Tk Source Code

Check-in Differences
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From trunk To tip-166

2024-05-06
07:33
Fix [ff5417505b]: xlib/X11/X.h not compilable on x64 Windows, using gcc Leaf check-in: cf6c186a user: jan.nijtmans tags: trunk, main
07:33
Fix [ff5417505b]: xlib/X11/X.h not compilable on x64 Windows, using gcc Leaf check-in: 5246e4ad user: jan.nijtmans tags: core-8-branch
2024-05-04
15:53
Update X11 header-files to the latest version check-in: 98095432 user: jan.nijtmans tags: trunk, main
2017-09-16
15:16
Fix order of tests in tkImgListFormat.c. This was discovered when analyzing [829925ffff]: image put errors on {} color check-in: ef510165 user: fvogel tags: trunk
15:16
Fix order of tests in tkImgListFormat.c. This was discovered when analyzing [829925ffff]: image put errors on {} color Closed-Leaf check-in: b36f05fa user: fvogel tags: tip-166
2017-08-06
15:27
merge trunk check-in: a3fc619c user: fvogel tags: tip-166

Changes to .fossil-settings/crlf-glob.


1
2


1


2
3
+
-
-
+
+
win/buildall.vc.bat
win/*.bat
win/*.vc
win/makefile.vc
win/rules.vc

Changes to .fossil-settings/crnl-glob.


1
2


1


2
3
+
-
-
+
+
win/buildall.vc.bat
win/*.bat
win/*.vc
win/makefile.vc
win/rules.vc

Changes to .fossil-settings/encoding-glob.

1
2
3
4
5
6
7
8
9
1
2

3







-

-
-
-
-
-
win/buildall.vc.bat
win/makefile.vc
win/rules-ext.vc
win/rules.vc
win/targets.vc
win/rc/*.bmp
win/rc/*.cur
win/rc/*.ico
win/rc/*.rc

Changes to .fossil-settings/ignore-glob.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32



33
34
35
36
37
38
39
1
2
3

4
5

6

7
8
9
10
11
12
13

14
15
16
17
18

19
20








21
22
23



24






-


-

-







-





-
+

-
-
-
-
-
-
-
-
+
+
+
-
-
-

-
-
-
*.a
*.dll
*.dylib
*.dylib.E
*.exe
*.exp
*.la
*.lib
*.lo
*.o
*.obj
*.pdb
*.res
*.sl
*.so
*/Makefile
*/autom4te.cache
*/config.cache
*/config.log
*/config.status
*/tkConfig.sh
*/wish*
*/tktest
*/tktest*
*/versions.vc
*/version.vc
*/libtk.vfs
*/libtk*.zip
*/tkUuid.h
html
macosx/configure
win/Debug*
win/Release*
doc/man.macros
win/Debug_VC*
win/Release_VC*
win/*.manifest
win/nmhlp-out.txt
win/nmakehlp.out
unix/tk.pc
unix/Tk-Info.plist
unix/Wish-Info.plist
unix/Credits.html

Deleted .fossil-settings/manifest.

1

-
u

Deleted .gitattributes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43











































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# Set the default behavior, in case people don't have core.autocrlf set.
* eol=lf
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.3 text
*.c text
*.css text
*.enc text
*.h text
*.htm text
*.html text
*.java text
*.js text
*.json text
*.n text
*.svg text
*.ts text
*.tcl text
*.test text

# Declare files that will always have CRLF line endings on checkout.
*.bat eol=crlf
*.rc eol=crlf
*.sln eol=crlf
*.vc eol=crlf

# Denote all files that are truly binary and should not be modified.
*.a binary
*.bmp binary
*.cur binary
*.dll binary
*.exe binary
*.gif binary
*.gz binary
*.ico binary
*.jpg binary
*.lib binary
*.pdf binary
*.png binary
*.xlsx binary
*.zip binary

Deleted .github/ISSUE_TEMPLATE.md.

1
2
3



-
-
-
Important Note
==========
Please do not file issues with Tk on Github. They are unlikely to be noticed in a timely fashion. Tk issues are hosted in the [tk fossil repository on core.tcl-lang.org](https://core.tcl-lang.org/tk/tktnew); please post them there.

Deleted .github/PULL_REQUEST_TEMPLATE.md.

1
2
3



-
-
-
Important Note
==========
Please do not file pull requests with Tk on Github. They are unlikely to be noticed in a timely fashion. Tk issues (including patches) are hosted in the [tk fossil repository on core.tcl-lang.org](https://core.tcl-lang.org/tk/tktnew); please post them there.

Deleted .github/workflows/linux-build.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197





































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: Linux
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
defaults:
  run:
    shell: bash
    working-directory: tk/unix
env:
  ERROR_ON_FAILURES: 1
jobs:
  build:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
          - "clang"
        config:
          - ""
          - "CFLAGS=-DTK_NO_DEPRECATED=1"
          - "--disable-shared"
          - "--disable-xft"
          - "--disable-xss"
          - "--enable-symbols"
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl 8.6
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
          echo "TOOL_DIR=$(cd tcl/tools;pwd)" >> $GITHUB_ENV
          echo "BUILD_CONFIG_ID=$OPTS" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.config }}
          COMPILER: ${{ matrix.compiler }}
          OPTS: ${{ matrix.compiler }}${{ matrix.config }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure (opts=${{ matrix.config }})
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Build Test Harness
        run: |
          make tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Test-Drive Installation
        run: |
          make install || {
            echo "::error::Failure during Install"
            exit 1
          }
      - name: Create Distribution Package
        run: |
          make dist || {
            echo "::error::Failure during Distribute"
            exit 1
          }
      - name: Convert Documentation to HTML
        run: |
          make html-tk TOOL_DIR=$TOOL_DIR || {
            echo "::error::Failure during Distribute"
            exit 1
          }
      - name: Discover Version ID
        if: ${{ env.BUILD_CONFIG_ID == 'gcc' }}
        run: |
          cd /tmp/dist
          echo "VERSION=`ls -d tk* | sed 's/tk//'`" >> $GITHUB_ENV
      - name: Upload Source Distribution
        if: ${{ env.BUILD_CONFIG_ID == 'gcc' }}
        uses: actions/upload-artifact@v4
        with:
          name: Tk ${{ env.VERSION }} Source distribution (snapshot)
          path: |
            /tmp/dist/tk*
            !/tmp/dist/tk*/html/**
      - name: Upload Documentation Distribution
        if: ${{ env.BUILD_CONFIG_ID == 'gcc' }}
        uses: actions/upload-artifact@v4
        with:
          name: Tk ${{ env.VERSION }} HTML documentation (snapshot)
          path: /tmp/dist/tk*/html
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
        config:
          - ""
          - "--disable-xft"
          - "--enable-symbols"
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev xvfb libicu-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.config }}
          COMPILER: ${{ matrix.compiler }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure ${{ matrix.config }}
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tests
        run: |
          xvfb-run --auto-servernum make test-classic | tee out-classic.txt
          xvfb-run --auto-servernum make test-ttk | tee out-ttk.txt
          grep -q "Failed	0" out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
        timeout-minutes: 10

Deleted .github/workflows/linux-with-tcl8-build.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178


















































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: Linux (with Tcl 8.7)
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
defaults:
  run:
    shell: bash
    working-directory: tk/unix
env:
  ERROR_ON_FAILURES: 1
jobs:
  build:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
          - "clang"
        cfgopt:
          - ""
          - "CFLAGS=-DTK_NO_DEPRECATED=1"
          - "--disable-shared"
          - "--disable-xft"
          - "--disable-xss"
          - "--enable-symbols"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: core-8-branch
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
          echo "TOOL_DIR=$(cd tcl/tools;pwd)" >> $GITHUB_ENV
          echo "BUILD_CONFIG_ID=$OPTS" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.cfgopt }}
          COMPILER: ${{ matrix.compiler }}
          OPTS: ${{ matrix.compiler }}${{ matrix.cfgopt }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure (opts=${{ matrix.cfgopt }})
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Build Test Harness
        run: |
          make tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Test-Drive Installation
        run: |
          make install || {
            echo "::error::Failure during Install"
            exit 1
          }
      - name: Create Distribution Package
        run: |
          make dist || {
            echo "::error::Failure during Distribute"
            exit 1
          }
      - name: Convert Documentation to HTML
        run: |
          make html-tk TOOL_DIR=$TOOL_DIR || {
            echo "::error::Failure during Distribute"
            exit 1
          }
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
        cfgopt:
          - ""
          - "--disable-xft"
          - "--enable-symbols"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: core-8-branch
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev xvfb libicu-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.cfgopt }}
          COMPILER: ${{ matrix.compiler }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure ${{ matrix.cfgopt }}
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tests
        run: |
          xvfb-run --auto-servernum make test-classic | tee out-classic.txt
          xvfb-run --auto-servernum make test-ttk | tee out-ttk.txt
          grep -q "Failed	0" out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
        timeout-minutes: 15

Deleted .github/workflows/linux-with-tcl91-build.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178


















































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: Linux (with Tcl 9.1)
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
defaults:
  run:
    shell: bash
    working-directory: tk/unix
env:
  ERROR_ON_FAILURES: 1
jobs:
  build:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
          - "clang"
        cfgopt:
          - ""
          - "CFLAGS=-DTK_NO_DEPRECATED=1"
          - "--disable-shared"
          - "--disable-xft"
          - "--disable-xss"
          - "--enable-symbols"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: tip-626
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
          echo "TOOL_DIR=$(cd tcl/tools;pwd)" >> $GITHUB_ENV
          echo "BUILD_CONFIG_ID=$OPTS" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.cfgopt }}
          COMPILER: ${{ matrix.compiler }}
          OPTS: ${{ matrix.compiler }}${{ matrix.cfgopt }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure (opts=${{ matrix.cfgopt }})
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Build Test Harness
        run: |
          make tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Test-Drive Installation
        run: |
          make install || {
            echo "::error::Failure during Install"
            exit 1
          }
      - name: Create Distribution Package
        run: |
          make dist || {
            echo "::error::Failure during Distribute"
            exit 1
          }
      - name: Convert Documentation to HTML
        run: |
          make html-tk TOOL_DIR=$TOOL_DIR || {
            echo "::error::Failure during Distribute"
            exit 1
          }
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        compiler:
          - "gcc"
        cfgopt:
          - ""
          - "--disable-xft"
          - "--enable-symbols"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: tip-626
          path: tcl
      - name: Setup Environment (compiler=${{ matrix.compiler }})
        run: |
          sudo apt-get install libxss-dev libxft-dev xvfb libicu-dev
          mkdir "$HOME/install dir"
          touch tk/doc/man.macros tk/generic/tkStubInit.c
          echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV
          echo "CC=$COMPILER" >> $GITHUB_ENV
        working-directory: "."
        env:
          CFGOPT: ${{ matrix.cfgopt }}
          COMPILER: ${{ matrix.compiler }}
      - name: Configure and Build Tcl
        run: |
          ./configure $CFGOPT "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        working-directory: tcl/unix
      - name: Configure ${{ matrix.cfgopt }}
        run: |
          ./configure $CFGOPT --with-tcl=$TCL_CONFIG_PATH "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
      - name: Build
        run: |
          make binaries libraries tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tests
        run: |
          xvfb-run --auto-servernum make test-classic | tee out-classic.txt
          xvfb-run --auto-servernum make test-ttk | tee out-ttk.txt
          grep -q "Failed	0" out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
        timeout-minutes: 15

Deleted .github/workflows/mac-build.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171











































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: macOS
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
env:
  ERROR_ON_FAILURES: 1
jobs:
  xcode:
    runs-on: macos-11
    defaults:
      run:
        shell: bash
        working-directory: tk/macosx
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Check out Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Prepare checked out repositories
        run: |
          touch tk/generic/tkStubInit.c
          mkdir build
          echo "BUILD_DIR=`cd build && pwd`" >> $GITHUB_ENV
          echo "DESTDIR=`cd build && pwd`" >> $GITHUB_ENV
        working-directory: .
      - name: Build Tcl
        run: |
          make all
        working-directory: tcl/macosx
      - name: Build
        run: |
          make all install || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tests
        run: |
          make test | tee out.txt
          nmatches=$( grep -c "Failed	0" out.txt )
          if [ $nmatches -lt 4 ]
          then
            echo "::error::Failure during Test"
            exit 1
          fi
        timeout-minutes: 30
  clang:
    runs-on: macos-11
    strategy:
      matrix:
        symbols:
          - 'no'
          - 'mem'
        options:
          - '--enable-aqua'
          - '--disable-aqua'
    defaults:
      run:
        shell: bash
        working-directory: tk/unix
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Check out Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Prepare checked out repositories
        env:
          SET_DISPLAY: ${{ contains(matrix.options, '--disable-aqua') }}
        run: |
          touch tkStubInit.c
          mkdir "$HOME/install dir"
          echo "USE_XVFB=$SET_DISPLAY" >> $GITHUB_ENV
        working-directory: tk/generic
      - name: Add X11 (if required)
        if: ${{ env.USE_XVFB == 'true' }}
        run: |
          brew install --cask xquartz
          sudo /opt/X11/libexec/privileged_startx || true
        working-directory: .
      - name: Build Tcl
        run: |
          ./configure $CFGOPT --disable-zipfs "--prefix=$HOME/install dir" || {
            cat config.log
            echo "::error::Failure during Tcl Configure"
            exit 1
          }
          make all || {
            echo "::error::Failure during Tcl Build"
            exit 1
          }
          make install || {
            echo "::error::Failure during Tcl Install"
            exit 1
          }
        working-directory: tcl/unix
        env:
          CFGOPT: --enable-symbols=${{ matrix.symbols }}
      - name: Configure (symbols=${{ matrix.symbols }} ${{matrix.options }})
        run: |
          ./configure $CFGOPT --disable-zipfs "--prefix=$HOME/install dir" --disable-xft || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
        env:
          CFGOPT: --enable-symbols=${{ matrix.symbols }} ${{matrix.options }}
      - name: Build
        run: |
          make all tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tests
        run: |
          if [ $USE_XVFB == true ]; then
            function runXvfb {
              PATH=$PATH:/opt/X11/bin
              Xvfb $1 &
              XVFB_PID=$!
              echo Launched Xvfb $1 as process $XVFB_PID >&2
              trap "echo killing process $XVFB_PID... >&2; kill $XVFB_PID" 0
              export DISPLAY=$1
              sleep 2
            }
          else
            function runXvfb {
              echo Xvfb not used, this is a --enable-aqua build
            }
          fi
          ( runXvfb :0; make test-classic; exit $? ) | tee out-classic.txt || {
            echo "::error::Failure during Test (classic)"
            exit 1
          }
          ( runXvfb :0; make test-ttk; exit $? ) | tee out-ttk.txt || {
            echo "::error::Failure during Test (ttk)"
            exit 1
          }
          cat out-classic.txt | grep -q "Failed	0" || {
            echo "::error::Failure in classic test results"
            exit 1
          }
          cat out-ttk.txt | grep -q "Failed	0" || {
            echo "::error::Failure in ttk test results"
            exit 1
          }
        timeout-minutes: 20
      - name: Carry out trial installation
        run: |
          make install || {
            cat config.log
            echo "::error::Failure during Install"
            exit 1
          }

Deleted .github/workflows/onefiledist.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222






























































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: Build Binaries
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
jobs:
  linux:
    name: Linux
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    env:
      CC: gcc
      CFGOPT: --disable-symbols --disable-shared
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Setup Environment
        run: |
          sudo apt-get install libxss-dev libxft-dev
          touch tcl/generic/tclStubInit.c tcl/generic/tclOOStubInit.c
          touch tk/generic/tkStubInit.c
          echo "INST_DIR=$(cd install;pwd)" >> $GITHUB_ENV
          echo "VER_PATH=$(cd tcl/tools; pwd)/addVerToFile.tcl" >> $GITHUB_ENV
        working-directory: "."
      - name: Configure Tcl
        run: |
          ./configure $CFGOPT --prefix=$INST_DIR
        working-directory: tcl/unix
      - name: Build & Install Tcl
        run: |
          make binaries libraries install
          make shell SCRIPT="$VER_PATH $GITHUB_ENV"
        working-directory: tcl/unix
      - name: Configure Tk
        run: |
          ./configure $CFGOPT --with-tcl=$INST_DIR/lib --prefix=$INST_DIR
        working-directory: tk/unix
      - name: Build & Install Tk
        run: |
          make binaries libraries install
        working-directory: tk/unix
        # TODO: need the Tk version separately for distro naming below
      - name: Package
        run: |
          cp bin/wish9.0 ${BUILD_NAME}
          chmod +x ${BUILD_NAME}
          tar -cf ${BUILD_NAME}.tar ${BUILD_NAME}
        working-directory: ${{ env.INST_DIR }}
        env:
          BUILD_NAME: wish${{ env.TCL_PATCHLEVEL }}_snapshot
      - name: Upload
        uses: actions/upload-artifact@v4
        with:
          name: Wish ${{ env.TCL_PATCHLEVEL }} Linux single-file build (snapshot)
          path: ${{ env.INST_DIR }}/*.tar
      - name: Describe Installation Zip Contents
        if: ${{ always() }}
        run: |
          unzip -l wish${{ env.TCL_PATCHLEVEL }}_snapshot || true
        working-directory: ${{ env.INST_DIR }}
  macos:
    name: macOS
    runs-on: macos-11
    defaults:
      run:
        shell: bash
    env:
      CC: gcc
      CFGOPT: --disable-symbols --disable-shared
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Checkout create-dmg
        uses: actions/checkout@v4
        with:
          repository: create-dmg/create-dmg
          ref: v1.0.8
          path: create-dmg
      - name: Setup Environment
        run: |
          mkdir -p install/contents
          touch tcl/generic/tclStubInit.c tcl/generic/tclOOStubInit.c
          touch tk/generic/tkStubInit.c
          echo "INST_DIR=$(cd install;pwd)" >> $GITHUB_ENV
          echo "VER_PATH=$(cd tcl/tools; pwd)/addVerToFile.tcl" >> $GITHUB_ENV
          echo "CREATE_DMG=$(cd create-dmg;pwd)/create-dmg" >> $GITHUB_ENV
          echo "CFLAGS=-arch x86_64 -arch arm64" >> $GITHUB_ENV
        working-directory: "."
      - name: Configure Tcl
        run: |
          ./configure $CFGOPT --prefix=$INST_DIR
        working-directory: tcl/unix
      - name: Build & Install Tcl
        run: |
          make binaries libraries install
          make shell SCRIPT="$VER_PATH $GITHUB_ENV"
        working-directory: tcl/unix
      - name: Configure Tk
        run: |
          ./configure $CFGOPT --with-tcl=$INST_DIR/lib --prefix=$INST_DIR \
              --enable-aqua
        working-directory: tk/unix
      - name: Build & Install Tk
        run: |
          make binaries libraries install
        working-directory: tk/unix
        # TODO: need the Tk version separately for distro naming below
      - name: Package
        run: |
          cp ../tk/unix/wish contents/${BUILD_NAME}
          chmod +x contents/${BUILD_NAME}
          cat > contents/README.txt <<EOF
          This is a single-file executable developer preview of Tcl/Tk $TCL_PATCHLEVEL

          It is not intended as an official release at all, so it is unsigned and unnotarized.
          Use strictly at your own risk.

          To run it, you need to copy the executable out and run:
              xattr -d com.apple.quarantine ${BUILD_NAME}
          to mark the executable as runnable on your machine.
          EOF
          $CREATE_DMG \
              --volname "TclTk $TCL_PATCHLEVEL (snapshot)" \
              --window-pos 200 120 \
              --window-size 800 400 \
              "TclTk-$TCL_PATCHLEVEL-(snapshot).dmg" \
              "contents/"
        working-directory: ${{ env.INST_DIR }}
        env:
          BUILD_NAME: wish${{ env.TCL_PATCHLEVEL }}_snapshot
      - name: Upload
        uses: actions/upload-artifact@v4
        with:
          name: Wish ${{ env.TCL_PATCHLEVEL }} macOS single-file build (snapshot)
          path: ${{ env.INST_DIR }}/*.dmg
  win:
    name: Windows
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    env:
      CC: gcc
      CFGOPT: --disable-symbols --disable-shared
    steps:
      - name: Install MSYS2
        uses: msys2/setup-msys2@v2
        with:
          msystem: MINGW64
          install: git mingw-w64-x86_64-toolchain make zip
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Setup Environment
        run: |
          mkdir -p install/combined
          touch tcl/generic/tclStubInit.c tcl/generic/tclOOStubInit.c
          touch tk/generic/tkStubInit.c
          echo "INST_DIR=$(cd install;pwd)" >> $GITHUB_ENV
          echo "VER_PATH=$(cd tcl/tools; pwd)/addVerToFile.tcl" >> $GITHUB_ENV
        working-directory: "."
      - name: Configure Tcl
        run: |
          ./configure $CFGOPT --prefix=$INST_DIR
        working-directory: tcl/win
      - name: Build & Install Tcl
        run: |
          make binaries libraries install
          $INST_DIR/bin/tclsh* $VER_PATH $GITHUB_ENV
        working-directory: tcl/win
      - name: Configure Tk
        run: |
          ./configure $CFGOPT --with-tcl=$INST_DIR/lib --prefix=$INST_DIR
        working-directory: tk/win
      - name: Build & Install Tk
        run: |
          make all install
          echo "TK_BIN=`pwd`/`echo wish*.exe`" >> $GITHUB_ENV
        working-directory: tk/win
        # TODO: need the Tk version separately for distro naming below
      - name: Package
        run: |
          cp ${TK_BIN} combined/${BUILD_NAME}.exe
        working-directory: install
        env:
          BUILD_NAME: wish${{ env.TCL_PATCHLEVEL }}_snapshot
      - name: Upload
        uses: actions/upload-artifact@v4
        with:
          name: Wish ${{ env.TCL_PATCHLEVEL }} Windows single-file build (snapshot)
          path: install/combined/wish${{ env.TCL_PATCHLEVEL }}_snapshot.exe

Deleted .github/workflows/win-build.yml.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178


















































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
name: Windows
on:
  push:
    branches:
    - "main"
    - "core-8-branch"
    - "core-8-6-branch"
    tags:
    - "core-**"
permissions:
  contents: read
env:
  ERROR_ON_FAILURES: 1
jobs:
  msvc:
    runs-on: windows-2022
    defaults:
      run:
        shell: powershell
        working-directory: tk/win
    # Using powershell means we need to explicitly stop on failure
    strategy:
      matrix:
        config:
          - ""
          - "OPTS=symbols"
          - "OPTS=static"
    steps:
      - name: Checkout Tk
        uses: actions/checkout@v4
        with:
          path: tk
      - name: Checkout Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Init MSVC
        uses: ilammy/msvc-dev-cmd@v1
      - name: Make Install Location
        working-directory: tcl
        run: |
          echo "TCLDIR=`pwd`" >> $GITHUB_ENV
          cd ..
          mkdir install
          cd install
          echo "INSTALLDIR=`pwd`" >> $GITHUB_ENV
      - name: Build Tcl (${{ matrix.config }})
        run: |
          &nmake -f makefile.vc release install ${{ matrix.config }}
          if ($lastexitcode -ne 0) {
             throw "nmake exit code: $lastexitcode"
          }
        working-directory: tcl/win
      - name: Build Tk (${{ matrix.config }})
        run: |
          &nmake -f makefile.vc all ${{ matrix.config }}
          if ($lastexitcode -ne 0) {
             throw "nmake exit code: $lastexitcode"
          }
      - name: Build Test Harness (${{ matrix.config }})
        run: |
          &nmake -f makefile.vc tktest ${{ matrix.config }}
          if ($lastexitcode -ne 0) {
             throw "nmake exit code: $lastexitcode"
          }
      - name: Run Tk Tests (${{ matrix.config }})
        run: |
          nmake -f makefile.vc test-classic ${{ matrix.config }} | tee out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          nmake -f makefile.vc test-ttk ${{ matrix.config }} | tee out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
        env:
          CI_BUILD_WITH_MSVC: 1
        shell: bash
        timeout-minutes: 10
      - name: Build Help (${{ matrix.config }})
        run: |
          &nmake -f makefile.vc htmlhelp ${{ matrix.config }}
          if ($lastexitcode -ne 0) {
             throw "nmake exit code: $lastexitcode"
          }
      - name: Install (${{ matrix.config }})
        run: |
          &nmake -f makefile.vc install ${{ matrix.config }}
          if ($lastexitcode -ne 0) {
             throw "nmake exit code: $lastexitcode"
          }
  gcc:
    runs-on: windows-2019
    defaults:
      run:
        shell: msys2 {0}
        working-directory: win
    strategy:
      matrix:
        config:
          - ""
          - "--enable-symbols=mem"
          - "--enable-symbols=all"
          - "--disable-shared"
    steps:
      - name: Install MSYS2
        uses: msys2/setup-msys2@v2
        with:
          msystem: MINGW64
          install: git mingw-w64-x86_64-toolchain make zip
      - name: Checkout Tk
        uses: actions/checkout@v4
      - name: Checkout Tcl 9.0
        uses: actions/checkout@v4
        with:
          repository: tcltk/tcl
          ref: main
          path: tcl
      - name: Prepare
        run: |
          touch tkStubInit.c
          touch "${HOME}/forWinDialog-5.12.7"
          mkdir "${HOME}/install_dir"
          echo "INSTALL_DIR=${HOME}/install_dir" >> $GITHUB_ENV
        working-directory: generic
      - name: Configure and Build Tcl (${{ matrix.config }})
        run: |
          ./configure $CFGOPT "--prefix=$INSTALL_DIR" || {
            cat config.log
            echo "::warning::Failure during Tcl Configure"
            exit 1
          }
          make all install  || {
            echo "::warning::Failure during Tcl Build"
            exit 1
          }
          echo "TCL_CONFIG_PATH=`pwd`" >> $GITHUB_ENV
        env:
          CFGOPT: --enable-64bit ${{ matrix.config }}
        working-directory: tcl/win
      - name: Configure Tk (${{ matrix.config }})
        run: |
          ./configure $CFGOPT "--prefix=$HOME/INSTALL_DIR" "--with-tcl=$TCL_CONFIG_PATH" || {
            cat config.log
            echo "::error::Failure during Configure"
            exit 1
          }
        env:
          CFGOPT: --enable-64bit ${{ matrix.config }}
      - name: Build Tk
        run: |
          make all tktest || {
            echo "::error::Failure during Build"
            exit 1
          }
      - name: Run Tk Tests
        run: |
          make test-classic | tee out-classic.txt
          make test-ttk | tee out-ttk.txt
          grep -q "Failed	0" out-classic.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
          grep -q "Failed	0" out-ttk.txt || {
            echo "::error::Failure during Test"
            exit 1
          }
        timeout-minutes: 10

Deleted .gitignore.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
*.a
*.bundle
*.dll
*.dylib
*.dylib.E
*.exe
*.exp
*.lib
*.o
*.obj
*.pdb
*.res
*.sl
*.so
.fslckout
Makefile
Tk-Info.plist
Wish-Info.plist
Credits.html
autom4te.cache
config.cache
config.log
config.status
config.status.lineno
html
manifest.uuid
_FOSSIL_
*/tkConfig.sh
*/wish*
*/tktest
*/versions.vc
*/version.vc
*/libtk.vfs
*/libtk*.zip
*/tkUuid.h
libtommath/bn.ilg
libtommath/bn.ind
libtommath/pretty.build
libtommath/tommath.src
libtommath/*.log
libtommath/*.pdf
libtommath/*.pl
libtommath/*.sh
libtommath/doc/*
libtommath/tombc/*
libtommath/pre_gen/*
libtommath/pics/*
libtommath/mtest/*
libtommath/logs/*
libtommath/etc/*
libtommath/demo/*
libtommath/*.out
libtommath/*.tex
macosx/configure
unix/autoMkindex.tcl
unix/dltest.marker
unix/tk.pc
unix/tclIndex
win/Debug*
win/Release*
win/*.manifest
win/nmakehlp.out
win/nmhlp-out.txt

Changes to .project.

1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>tk9.0</name>
	<name>tk8.7</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
	</buildSpec>
	<natures>
	</natures>

Added ChangeLog.







































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
A NOTE ON THE CHANGELOG:
Starting in early 2011, Tk source code has been under the management of
fossil, hosted at http://core.tcl.tk/tk/ .  Fossil presents a "Timeline"
view of changes made that is superior in every way to a hand edited log file.
Because of this, many Tk developers are now out of the habit of maintaining
this log file.  You may still find useful things in it, but the Timeline is
a better first place to look now.
============================================================================

2013-08-30  Don Porter  <[email protected]>

	*** 8.6.1 TAGGED FOR RELEASE ***

	* README:		Bump version number to 8.6.1
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2013-08-25   Kevin Walzer <[email protected]>

	* macosx/tkMacOSXButton.c:  Bug [3016181]: Crash after scrollbar
	* macosx/tkMacOSXMenu.c:	destroyed, Tk Cocoa.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

2012-08-15  Joe English  <[email protected]>

	* library/ttk/progress.tcl: Bug [c597acdab3]: Call [$pb step]
	in tail position in ttk::progressbar::Autoincrement, so that
	the widget is in a consistent state when any write traces on
	the linked -variable are fired.

2013-08-14  Jan Nijtmans  <[email protected]>

	* generic/tkConfig.c:  Bug [069c9e43c4]: FreeOptionInternalRep() breaks
	* tests/config.test:   Tk_CreateOptionTable()

2013-07-02  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:  Bug [32afa6e256]: dirent64 check is incorrect in tcl.m4
	* unix/configure: (thanks to Brian Griffin)

2012-06-28  Jan Nijtmans  <[email protected]>

	* library/ttk/scale.tcl: [Bug 2501278]: ttk::scale keyboard binding
	problem.

2013-06-05  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkScroll.c: [Bug 3613759]: ttk::entry and symbolic
	index names.
	* generic/ttk/ttkEntry.c: [Bug 2100430]: ttk::entry widget index
	must be integer
	* generic/tkEntry.c: Don't set interp result when it will be
	overwritten later.

2013-06-04  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4: Eliminate NO_VIZ macro as current
	zlib uses HAVE_HIDDEN in stead. One more last-moment
	fix for FreeBSD by Pietro Cerutti

2013-05-23  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:     [Bug 3613668]: XFilterEvent() hangs.
	* unix/configure:
	* unix/tkUnixEvent.c:

2013-05-19  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:     Fix for FreeBSD, and remove support for older
	* unix/configure:  FreeBSD versions. Patch by Pietro Cerutti.

2013-04-10  Jan Nijtmans  <[email protected]>

	* win/makefile.vc: [Bug 3568760]: Tk documentation fails to build

2013-04-01  Don Porter  <[email protected]>

	* tests/window.test: Bring back test window-2.9. No longer hangs.

	* generic/tkInt.h:	[Bug 3607830] Runtime checks that Xkb is
	* unix/tkUnixEvent.c:	available in the X server before trying to
	* unix/tkUnixKey.c:	use.  Adapted from patch from Brian Griffin.

2013-03-27  Jan Nijtmans  <[email protected]>

	* library/button.tcl:    [Bug 3608074]: Add <<Invoke>> bindings to
	* library/listbox.tcl:   Button's, Listbox and Menu.
	* library/menu.tcl:
	* doc/event.n:           Document <<Invoke>>, <<ThemeChanged>>,
	* doc/ttk_panedwindow.n: <<EnteredChild>> (ttk_pandedwindow only) and
	* doc/ttk_spinbox.n:     <<Increment/Decrement>> (ttk_spinbox only)

2013-03-13  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4: Patch by Andrew Shadura, providing better support for
	three architectures they have in Debian.

2013-03-11  Don Porter  <[email protected]>

	* generic/tkListbox.c:	[Bug 3607326] Stop segfault from
	* tests/listbox.test:	[listbox .l -listvariable $array].

2013-02-28  Donal K. Fellows  <[email protected]>

	* unix/tkUnixKey.c (TkpGetKeySym): [Bug 3599312]: Put the
	initialization of the key mapping before the input method handling so
	that Alt key handling is correct on non-OSX Unix. Thanks to Colin
	McDonald for developing the fix.

2013-02-18  Jan Nijtmans  <[email protected]>

	* unix/tkUnixEvent.c: Call XInitThreads once before the first Xlib
	call. Suggested by Brian Griffin.

2013-01-14  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:	 More flexible search for win32 tclConfig.sh,
	* win/configure: backported from TEA.

2013-01-13  Jan Nijtmans  <[email protected]>

	* library/tk.tcl: [Bug 3600390]: tk_strictMotif not tested for. Now
	* library/ttk/entry.tcl: all key-bindings for Control-a,b,e,f,n,p and
	their shift variants respect tk_strictMotif.

2013-01-10  Jan Nijtmans  <[email protected]>

	* library/text.tcl: [Bug 3600251]: Inappropriate replacement of Mac
	binding.
	* library/tk.tcl: [Bug 3600260]: Errors in new virtual event
	definitions

2012-12-11  Don Porter  <[email protected]>

	*** 8.6.0 TAGGED FOR RELEASE ***

	* README:		Bump version number to 8.6.0
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2012-12-04  François Vogel  <[email protected]>

	* generic/tkTextIndex.c: [Bug 3588824]: bug in image index handling
	* tests/textIndex.test:  for weird image names

2012-11-16  Joe Mistachkin  <[email protected]>

	* generic/tkBind.c: Add support for an 'M' binding substitution
	that is replaced with the number of script-based binding patterns
	matched so far for the event.

2012-11-14  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3500545]: tk_getOpenFile -multiple 1 wrong
	on windows.
	[Bug 3416492]: Crash in open/save file dialog in Windows 7 libraries.
	[Bug 3095112]: crash when selecting file from Win7 Library.

2012-11-11  Jan Nijtmans  <[email protected]>

	* win/tkWinTest.c: [Bug 3585396]: winDialog.test requires user
	* tests/winDialog.test: interaction.

2012-11-07  Donal K. Fellows  <[email protected]>

	* generic/tkFocus.c (TkSetFocusWin): [Bug 3574708]: Move window
	liveness into this function from caller sites to ensure that there are
	no paths where things can trip up on setting the focus to a partially
	dead window.

2012-10-24  Don Porter  <[email protected]>

	* macosx/tkMacOSXWm.c:	[Bug 3574893] Add overlooked toplevel ref
	count maintenance in the [wm manage|forget] operations that could
	cause segfaults due to premature free of structs.

2012-09-19  Jan Nijtmans  <[email protected]>

	* win/Makefile.in:    Compile win32 binaries with -DTCL_NO_DEPRECATED
	* win/tkiWinWm.c:     Fix gcc compiler warning.

2012-09-17  Don Porter  <[email protected]>

	*** 8.6b3 TAGGED FOR RELEASE ***

	* macosx/tkMacOSXWm.c: [Bug 3567786] Stop segfault in [wm forget].

2012-09-15  Don Porter  <[email protected]>

	* macosx/tkMacOSXFont.c: [Bug 3567778] Make Tk_MeasureChars() honor
	the TK_AT_LEAST_ONE flag properly.

2012-09-13  Donal K. Fellows  <[email protected]>

	* generic/ttk/ttkEntry.c (EntryDisplay): [Bug 3567453]: Clip regions
	* generic/ttk/ttkLabel.c (TextDraw): must be cleared with XSetClipMask
	* xlib/xgc.c (TkSetRegion): and not TkSetRegion, or crashes will ensue
	on X11-based builds, which can't handle None for a region argument.
	Added a clean panic to the non-X11 TkSetRegion to catch this case and
	stop such confusion from happening again.

2012-09-13  Donal K. Fellows  <[email protected]>

	* win/tkWinWm.c (WmTransientCmd): [Bug 3567283]: Added missing cast.

2012-09-11  Donal K. Fellows  <[email protected]>

	* generic/ttk/ttkEntry.c (EntryDisplay): [Bug 3566594]: Must manually
	* generic/ttk/ttkLabel.c (TextDraw):     reset the clip region of GCs
	when not using the Xft font renderer (well, especially on classic X11)
	because the GC sharing code doesn't take into account clip handling.
	Thanks to Christian Nassau for identifying the problem.

2012-09-07  Donal K. Fellows  <[email protected]>

	* generic/tkCanvPs.c (TkCanvPostscriptCmd): [Bug 3565533]: Purge use
	of variable that was only ever checked once immediately afterwards,
	except for one (buggy) case where it was checked without assignment.

2012-09-07  Don Porter  <[email protected]>

	* README:		Bump version number to 8.6b3
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2012-08-30  Andreas Kupries  <[email protected]>

	* generic/tkCanvWind.c (CanvasPsWindow): Unbreak AIX, replaced use
	of C99 comments in commit [961ae24a3f] (2012-08-27) with C89-style.
	* win/tkWinDialog.c: Unbreak windows problems with commit [961ae24a3f]
	* win/tkWinMenu.c: as well.
	* win/tkWinSend.c:

2012-08-28  Jan Nijtmans  <[email protected]>

	* generic/tkMenuDraw.c: [Bug 3562426]: Context menu goes out of edge of
	screen.

2012-08-27  Donal K. Fellows  <[email protected]>

	* (very many files): Reworked the generation of error messages and
	postscript so that they no longer made nearly as much use of the Tcl
	interpreter's string result code, in the process substantially
	reducing the amount of ad-hoc stack buffers used for message
	generation. There should be no observable changes from this except
	that Tk now causes the ::errorCode variable to be set meaningfully in
	virtually all places where errors are generated.

2012-08-24  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (GlobFiltered): [Bug 3558535]: Factor out the
	filtered-sorted globbing code into one procedure that knows how to
	avoid nasty problems when non-list filters are used. This allows the
	rest of the [tk_getOpenFile] implementation to be ignorant of the
	considerable complexities of globbing.

2012-08-23  Don Porter  <[email protected]>

	* unix/tkUnixWm.c: [Bugs 3554026,3561016]: Stop crash with tearoff
	menus.

2012-08-23  Jan Nijtmans  <[email protected]>

	* library/tk.tcl:        [Bug 3555644]: Better use of virtual events,
	* library/ttk/entry.tcl  Add <<ToggleSelection>> virtual event.
	* library/ttk/treeview.tcl

2012-08-22  Jan Nijtmans  <[email protected]>

	TIP #403 IMPLEMENTATION

	* xlib/xcolors.c:     Web Colors for Tk. New colors aqua, crimson,
	* xlib/rgb.txt:       fuchsia, indigo, lime, olive, silver and teal.
	* unix/tkUnixColor.c: Modified RGB values for gray/grey, green,
	* generic/tkInt.h:    maroon and purple.
	* generic/tkColor.c

2012-08-17  Jan Nijtmans  <[email protected]>

	* win/nmakehlp.c: Add "-V<num>" option, in order to be able to detect
	partial version numbers.

2012-08-15  Jan Nijtmans  <[email protected]>

	* win/buildall.vc.bat:	Only build the threaded builds by default
	* win/rules.vc:		For msvcrt static builds, allow to link
				against libraries where the 'x' is missing
				(generated by Makefile.in).
	* win/makefile.vc:	Always compile Tk with -DUSE_TCL_STUBS,
				formatting.
	* library/tk.tcl:	[FRQ 3555324]: On Windows, re-define Ctrl-A
				for Select-All., as most Windows applications
				do.

2012-08-11  Jan Nijtmans  <[email protected]>

	* library/*.tcl: [Bug 3555644]: Better use of virtual events.
	Pre-define 10 new Virtual events, and correct various bindings
	according to the Mac OSX documentation.
	*** POTENTIAL INCOMPATIBILITY *** for code that assumes that widget
	classes are bound to literal events or that was using one of the new
	virtual event names itself for other purposes.

	* win/rules.vc: Sync with tcl version of rules.vc

2012-08-11  François Vogel  <[email protected]>

	* generic/tkTextTag.c:  [Bug 3554273]: Test textDisp-32.2 failed

2012-08-09  Stuart Cassoff  <[email protected]>

	* generic/tkEvent.c:    Remove useless (void *) casts introduced in
	* unix/tkUnixEvent.c:   checkin [81e50c85ed]. The warnings were false
	* unix/tkUnixKey.c:     flags from a faulty OpenBSD C compiler.
	* unix/tkUnixRFont.c:

2012-07-31  Donal K. Fellows  <[email protected]>

	* unix/tkUnixKey.c (TkpSetKeycodeAndState, TkpInitKeymapInfo)
	(TkpGetKeySym): [Bug 3551802]: Convert from XKeycodeToKeysym to
	XkbKeycodeToKeysym to fix deprecation warning.

2012-07-31  Jan Nijtmans  <[email protected]>

	* win/nmakehlp.c: Backport from Tcl 8.6, but add -Q option from
	sampleextension.

2012-07-17  Jan Nijtmans  <[email protected]>

	* win/makefile.vc: [Bug 3544932]: Visual studio compiler check fails

2012-07-05  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c (GetFileNameW): [Bug 3540127]: Better solution,
	using Tcl_GetIndexFromObj in stead of Tcl_GetIndexFromObjStruct

2012-07-05  Donal K. Fellows  <[email protected]>

	* doc/wm.n (geometry): [Bug 3538401]: Better description of the key
	difference between [wm geometry] and [winfo geometry]; the former
	represents the window manager's understanding, not Tk's.

2012-07-04  Donal K. Fellows  <[email protected]>

	* win/tkWinDialog.c (GetFileNameW): [Bug 3540127]: Clean up the tables
	of options for the file dialogs so that options are listed in error
	messages in alphabetical order.

2012-07-02  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3540127]: filebox.test fails on win32

2012-06-26  Jan Nijtmans  <[email protected]>

	* unix/configure.in:  Link cygwin wish.exe with win32 tk.dll, only
	* unix/Makefile.in:   in combination with --enable-shared.
	* unix/tcl.m4:
	* unix/configure:     autoconf-2.59

2012-06-24  Jan Nijtmans  <[email protected]>

	* doc/SetOptions.3:   [FRQ-3536507]: clientData field in Tk_OptionSpec
	* generic/tk.h:       should be "const void *"
	* generic/tk*.c:      Eliminate many unnessessary type casts

2012-06-22  Jan Nijtmans  <[email protected]>

	* win/Makefile.in:    [Bug 1844430]: cygwin make fails in 8.4.14-8.5b3
	* unix/tcl.m4:        Sync with Tcl version.
	* unix/configure:     autoconf-2.59

2012-06-20  Jan Nijtmans  <[email protected]>

	* generic/tk.decls:    [FRQ 2636558] simplification. Restore forwards
	* generic/tkBitmap.c:  compatibility with Tk 8.5.
	* generic/tkdecls.h:
	* generic/tkStubInit.c:

2012-06-15  Donal K. Fellows  <[email protected]>

	* generic/ttk/ttkTreeview.c (unshareObj): [Bug 3535362]: Changed name
	of 'unshare' internal function to avoid clash with some libc versions.

2012-06-12  Donal K. Fellows  <[email protected]>

	* unix/tkUnixRFont.c (Tk_DrawChars, TkUnixSetXftClipRegion): Add some
	* generic/ttk/ttkEntry.c (EntryDisplay): special magic to make the
	* generic/ttk/ttkLabel.c (TextDraw): text clipping work right with the
	Xft-based renderer (which doesn't use the standard Tk GC except to
	supply the color).

2012-06-11  Donal K. Fellows  <[email protected]>

	* generic/ttk/ttkLabel.c (TextDraw): [Bug 3294450]: Get the clipping
	* generic/ttk/ttkEntry.c (EntryDisplay): of text in Ttk various text
	elements (e.g., buttons, entries, etc.) correct. Stops a whole range
	of visual problems, including loss of the second and subsequent lines
	of a label when the first line doesn't entirely fit, and failing to
	draw the last character of an entry at all if it doesn't all exactly
	fit in the space available (a problem I've noticed in tkchat, and been
	very frustrated with).

2012-06-10  Jan Nijtmans  <[email protected]>

	* library/*.tcl:      [Bug 3534137]: $tcl_platform(platform) !=
	[tk windowingsystem]

2012-06-08  Jan Nijtmans  <[email protected]>

	* generic/tkMain.c:   Implement TkCygwinMainEx for loading
	* generic/tkWindow.c: Cygwin's Tk_MainEx from the Tk dll.
	* generic/tkInt.decls:   Change XChangeWindowAttributes signature and
	* generic/tkIntXlibDeclsDecls.h: many others to match Xorg, needed for
	Cygwin.

2012-06-06  Jan Nijtmans  <[email protected]>

	* unix/Makefile.in:      [Bug 3532186] pkgIndex.tcl file complexity
	* win/Makefile.in:

2012-05-31  Jan Nijtmans  <[email protected]>

	* generic/tkWindow.c:	Simplify determination whether we are running
	* generic/tkStubInit.c:	on cygwin.  Export Tk_GetHINSTANCE,
	* generic/tkInt.decls:	TkSetPixmapColormap and TkpPrintWindowId from
				the Cygwin dll, sync stub table with Tk 8.6
				win32 version.
	* generic/tk*Decls.h:   re-generated
	* win/Makefile.in:      "make genstubs" when cross-compiling on UNIX

	* win/stubs.c:		Implement XFlush and various others for win32
	* win/tkWinPort.h:	as stubs, so win32 extensions using those can
				run under CYGWIN as well.
	* generic/tkMain.c:     Allow tk86.dll to cooperate with the cygwin
				console.

2012-05-29  Donal K. Fellows  <[email protected]>

	* generic/tkInt.decls (TkMacOSXDrawable): Added OSX-specific mechanism
	to allow retrieval of the drawing surface. Allows Canvas3d to be
	adapted to 8.6.

2012-05-28  François Vogel  <[email protected]>

	* doc/text.n:  [Bug 1630251]: Doc for -endline option was wrong

2012-05-28  François Vogel  <[email protected]>

	* generic/tkTextDisp.c: [Bug 1630254]: missing scrolling of text widget
	when from a -startline == -endline initial state it is configured to
	display a non-empty part of it

2012-05-24  Jan Nijtmans  <[email protected]>

	* win/stubs.c:          Change XSetCommand signature to match Xorg,
	* win/tkWinWm.c:        needed for Cygwin.
	* generic/tkInt.decls
	* generic/tk*Decls.h:   re-generated

2012-05-09  Jan Nijtmans  <[email protected]>

	* win/tkWinWm.c:           Change TkpWmSetState signature to match Xorg,
	* generic/tkInt.decls:     needed for Cygwin. (not needed for Mac)
	* generic/tkIntPlatDeclsDecls.h:
	* generic/tkWindow.c:      Don't check for cygwin in win32 static build.
	* unix/tkUnixPort.h:       Some more useful #defines for Cygwin

2012-05-05  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c:      Single "const" addition
	* generic/tkWindow.c:  If tk.dll loaded in cygwin, don't use the
	win32 file dialogs

2012-05-04  Jan Nijtmans  <[email protected]>

	* library/menu.tcl: [Bug 2768586]: Menu posting on dual monitors

2012-04-29  Jan Nijtmans  <[email protected]>

	* library/tk.tcl: [Bug 533519]: Window placement with multiple screens
	* generic/tkBind.c:
	* generic/tkFocus.c:
	* generic/tkMenuDraw.c:
	* generic/tkWinWm.c:

2012-04-26  Donal K. Fellows  <[email protected]>

	* generic/tkStubInit.c (Tk_GetHINSTANCE): Ensure that this is defined
	for OSX.

2012-04-26  Jan Nijtmans  <[email protected]>

	* generic/tk.decls:	[Bug 3508771]: Implement TkClipBox, Tk*Region
	* generic/tkInt.decls:	and Tk_GetHINSTANCE for Cygwin
	* generic/tkPlatDecls.h:
	* generic/tkintDecls.h:
	* generic/tkStubInit.c:

2012-04-22  Donal K. Fellows  <[email protected]>

	* generic/tkBind.c (ExpandPercents): [Bug 3520202]: Ensure that the
	%k, %K and %N substitutions use dummy tokens with <MouseWheel> events
	and that the %D subsitution is a dummy with <Key>/<KeyRelease>. This
	was causing significant indigestion (and a read of goodness knows what
	memory) to Tkinter/Python because of the way they map events between
	languages.

2012-04-20  Donal K. Fellows  <[email protected]>

	* generic/tkWindow.c (commands): Ensure that all descriptions of
	commands created by Tk are correct.

2012-04-20  Jan Nijtmans  <[email protected]>

	* generic/tk.tcl: Use vroot size in stead of screen size for clipping
	window coordinates in ::tk::PlaceWindow.
	* generic/dialog.tcl: Use ::tk::PlaceWindow in dialog.tcl, instead of
	dumplicating the code there. (harmless part of [Bug 533519])

2012-04-13  Jan Nijtmans  <[email protected]>

	* win/rules.vc: [Bug 3517448]: TclKit build fails (unresolved
	__strtoi64)

2012-04-07  Jan Nijtmans  <[email protected]>

	* generic/tkBind.c: [Bug 3176239]: control-MouseWheel causes segv

2012-03-30  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:        [Bug 3511806]: Compiler checks too early
	* unix/configure.in:  This change allows to build the cygwin
	* unix/configure      and mingw32 ports of Tcl/Tk to build
	* win/tcl.m4:         out-of-the-box using a native or cross-
	* win/configure.in:   compiler.
	* win/configure

2012-03-21  Jan Nijtmans  <[email protected]>

	* generic/tkColor.c:  [Bug 2809525]: Abort on overlong color name.
	* unix/tkUnixColor.c:

2012-03-18  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c:   [FRQ 3503317]: XParseColor speedup
	* xlib/rgb.txt:     List of all colors accepted by Tk in Xorg format
	* tests/color.test: Added test case for all colors in rgb.txt

2012-03-13  Donal K. Fellows  <[email protected]>

	* doc/*.3, doc/*.n: Minor spelling fixes.

2012-03-07  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (GetPixelsFromObjEx): [Bug 3497848]: Better rounding
	of pixel values to integers.

2012-03-04  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:    Patch from the cygwin folks
	* unix/configure: (re-generated)

2012-02-28  François Vogel  <[email protected]>

	* generic/tkText.c:      [Bug 1630262, Bug 1615425]: segfault
	* generic/tkTextBTree.c  when deleting lines or tagging outside of
	* generic/tkTextDisp.c   the -startline/-endline range with peer
	* generic/tkTextMark.c   text widgets.
	* tests/text.test        [Bug 3487407]: Weird text indices.
	* tests/textMark.test

2012-02-28  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: [Bug 3495198]: Corrected types of bitmap options.

2012-02-26  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: Provide fallback for _strtoi64
	* win/configure.in: Detect whether _strtoi64 is available
	* win/configure: (regenerated)

2012-02-25  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 1913750]: tk_chooseDirectory -initialdir
	internationalization problem.

2012-02-15  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: [Bug 3486474]: Inconsistent color scaling
	* generic/tkColor.c: new internal function TkParseColor
	* generic/tkInt.h:
	* generic/tk*.c:   Change XParseColor() to TkParseColor() everywhere.

2012-02-10  Donal K. Fellows  <[email protected]>

	* win/tkWinDialog.c (GetFileName): Ensure that we do not convert a
	result list to a string inadvertently, as this causes problems with
	Tkinter's handling of multiple filename results. Issue was reported
	via StackOverflow: http://stackoverflow.com/q/9227859/301832

2012-01-30  Joe English  <[email protected]>

	* library/ttk/combobox.tcl: [Bug 2925561] Don't take focus in
	disabled state.

2012-01-29  Jan Nijtmans  <[email protected]>

	* win/tkImgPhoto.c: [Bug 3480634]: PNG Images missing in menus on Mac

2012-01-27  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3480471]: tk_getOpenFile crashes on Win64

2012-01-26  François Vogel  <[email protected]>

	* generic/tkTextDisp.c: [Bug-1754043] and [Bug-2321450]: When
	-blockcursor is true, the cursor appears as a blinking bar which
	expands to the right edge of the widget.

2012-01-25  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c: [Bug 2433260]: non-critical error in
	Tk_PhotoPutBlock

2012-01-25  François Vogel  <[email protected]>

	* generic/tkText.c: Don't increase the epoch twice

2012-01-25  François Vogel  <[email protected]>

	* generic/tkText.c:      [Bug-1630271]: segfault/infinite loop
	* generic/tkTextMark.c:  when a mark is before -startline
	* tests/textMark.test:

2012-01-25  François Vogel  <[email protected]>

	* generic/tkText.c: [Bug-3475627]: Test text-31.11 fails

2012-01-22  François Vogel  <[email protected]>

	* generic/tkTextMark.c: [Bug-3288113,3288121]: Missing marks/endless
	* tests/textMark.test:  loop in text mark prev/next

2012-01-19  François Vogel  <[email protected]>

	* generic/tkText.c: [Bug-3021557]: Moving the cursor in
	* tests/text.test:  elided text freezes Tk

2011-12-22  Don Porter  <[email protected]>

	* win/tkWinMenu.c: [Bug 3235256] Keep menu entry IDs out of system
	values. Thanks Colin McDonald.

2011-12-13  Donal K. Fellows  <[email protected]>

	* doc/getOpenFile.n: Make example follow best practices. Issue spotted
	by Emiliano Gavilán.

2011-11-29  Donal K. Fellows  <[email protected]>

	* tests/safe.test: [Bug 1847925]: Update list of hidden commands.

2011-11-22  Jan Nijtmans  <[email protected]>

	* unix/Makefile.in: [Bug 1945073]: Demo square.tcl
	* win/Makefile.in: cannot run; need package tktest

2011-11-17  Jan Nijtmans  <[email protected]>

	* doc/menu.n: Fix the escaping of leading dots in lines that start with
	a widget name, so that nroff doesn't mistake it as a non-existing macro
	and skips the entire line.

2011-11-14  Alexandre Ferrieux  <[email protected]>

	* generic/tkCanvas.c: [Bug 3437816]: Missing TCL_ERROR return
	in [canvas lower].

2011-11-08  Reinhard Max  <[email protected]>

	* unix/Makefile.in: Add square to DEMOPROGS. It contains a shebang
	and hence should get installed with executable bits.

	* doc/label.n:         Fix the escaping of leading dots in lines that
	* doc/text.n:          start with a widget name, so that nroff
	* doc/ttk_notebook.n:  doesn't mistake it as a non-existing macro
	* doc/pack.n:          and skips the entire line.

2011-11-01  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (GetPixelsFromObjEx): [Bug 3431491]: Use a bit of
	type hackery to allow numbers to be interpreted as coordinates (most
	notably on a canvas) without reinterpreting via a string.

2011-10-27  Kevin B. Kenny  <[email protected]>

	* generic/tkInt.h:	[Bug 3410609]: Change the event mechanism
	* unix/tkUnixEvent.c:	for <KeyPress> events to use the keysym
	* unix/tkUnixKey.c:	returned by XLookupString in preference to
	the one that appears in the raw X event at any level. This change
	allows binding to ISO_Level3_Shift-ed characters, composed characters,
	and similar beasts. KeyRelease events still work as they did before,
	as does Tk with input methods disabled.

2011-10-13  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: Internationalization of all Windows font
	* win/tkWinFont.c:   handling.

2011-10-10  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3163893]: -initialdir option bug for
	tk_chooseDirectory under XP

2011-10-05  Jan Nijtmans  <[email protected]>

	* win/tkWinInt.h:   Remove tkWinProcs, as it is no longer
	* win/tkWinX.c:     being used.
	* win/tkWinTest.c:

2011-09-27  Donal K. Fellows  <[email protected]>

	* generic/tkImgPNG.c (WriteExtraChunks): [Bug 3405839]: Write the sDAT
	chunk with the correct length.

2011-09-08  Jan Nijtmans  <[email protected]>

	* generic/tkDecls.h: Don't let tkDecls.h depend on <tchar.h> on
	windows, not even in UNICODE mode.

2011-09-01  Donal K. Fellows  <[email protected]>

	* doc/photo.n: Correctly documented what the [$ph data] command
	produces without the -format option.

2011-08-16  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3388350]: mingw64 compiler warnings
	* win/tkWinEmbed.c
	* win/tkWinMenu.c
	* win/tkWinTest.c
	* win/tkWinWm.c
	* win/tkWinX.c

2011-08-13  Jan Nijtmans  <[email protected]>

	* generic/tkBitmap.c: [Bug 3388350]: mingw64 compiler warnings
	* generic/tkConsole.c
	* win/tkWinDialog.c
	* win/tkWinEmbed.c
	* win/tkWinSend.c
	* win/tkWinSendCom.c

2011-08-05  Don Porter  <[email protected]>

	*** 8.6b2 TAGGED FOR RELEASE ***

	* changes:	Updates for 8.6b2 release.

2011-08-03  Don Porter  <[email protected]>

	* win/tkWinWm.c: [Bug 2891541]: Merge of 8.5.8 fix from Pat Thoyts.
	Permit normal behaviour on Windows for a grabbed toplevel when it
	is the main window.

2011-08-03  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: [Bug 3314770]: regression - Windows file
	dialogs not resizable

2011-07-28  Don Porter  <[email protected]>

	* changes:	Updates for 8.6b2 release.

2011-07-28  Jan Nijtmans  <[email protected]>

	* xlib/X11/Xutil.h: [Bug 3380684]: XEmptyRegion prototype doesn't
	match usage

2011-07-19  Donal K. Fellows  <[email protected]>

	* doc/*.3, doc/*.n: Many small fixes to documentation as part of
	project to improve quality of generated HTML docs.

2011-07-18  Don Porter  <[email protected]>

	* README:		Bump version number to 8.6b2
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2011-06-29  Don Porter  <[email protected]>

	* generic/ttk/ttkTrace.c: [Bug 3341056]: Correct segfault due to flaw
	* tests/ttk/ttk.test:	in the 2011-06-17 commit.

2011-06-19  Donal K. Fellows  <[email protected]>

	* doc/wm.n: Added documentation of the -type attribute that was
	introduced in TIP#359, and moved documentation of -alpha to common
	section as it is supported on all platforms now.

2011-06-17  Don Porter  <[email protected]>

	* generic/ttk/ttkTrace.c:	Workaround Bug 3062331.
	* tests/ttk/ttk.test:
	* changes:	Updated

2011-06-16  Jan Nijtmans  <[email protected]>

	* win/tcl.m4: Sync with win/tcl.m4 from Tcl
	* win/configure: (regenerated)

2011-06-10  Don Porter  <[email protected]>

	* generic/tkEntry.c:	[Bug 3315731]: Fix [$entry -invcmd].

2011-06-10  Don Porter  <[email protected]>

	* README:	Correct some README bitrot.
	* macosx/README:

2011-06-07  Don Porter  <[email protected]>

	* generic/tkEntry.c:	[Bug 2358545]: Restore support for values "08"
	and "09" in a [spinbox] configured to use -from and -to values.

2011-06-06  Don Porter  <[email protected]>

	* generic/tkConsole.c:	[Bug 2546087]: Restore proper NUL output to
	* library/console.tcl:	the [console].

2011-04-22  Peter Spjuth  <[email protected]>

	* generic/tkCanvPoly.c: [Bug 3291543]: There was a crash if dchars
	* tests/canvas.test:    removed all coordinates of a polygon.

2011-04-21  Peter Spjuth  <[email protected]>

	* doc/checkbutton.n: Document all variable options as global.
	* doc/radiobutton.n:
	* doc/listbox.n:
	* doc/menu.n:
	* doc/options.n:
	* doc/ttk_combobox.n:
	* doc/ttk_entry.n:
	* doc/ttk_progressbar.n:
	* doc/ttk_widget.n:

2011-04-06  Jan Nijtmans  <[email protected]>

	* unix/tkAppInit.c:  Make symbols "main" and "Tcl_AppInit"
	MODULE_SCOPE: there is absolutely no reason for exporting them.
	* unix/tcl.m4:        Don't use -fvisibility=hidden with static
	* unix/configure      libraries (--disable-shared)

2011-04-04  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: [Bug 723765]: When a slave was removed from grid,
	the -in option was not remembered.

2011-04-04  Joe Mistachkin  <[email protected]>

	* win/tkWinDialog.c (FontchooserShowCmd): Change the CHOOSEFONT and
	LOGFONT used with sizeof to CHOOSEFONTA and LOGFONTA to match their
	local variable declarations (i.e. mismatch with -DUNICODE).  This code
	is not present in 8.4 or 8.5.

2011-04-04  Peter Spjuth  <[email protected]>

	* doc/labelframe.n:
	* doc/frame.n:
	* generic/tkFrame.c: [Bug 2997657]: Removed -container from labelframe
	documentation since it does not work as expected and does not make
	sense as a container. Added note to frame about restrictions when used
	as a container.

2011-03-28  Donal K. Fellows  <[email protected]>

	* library/tk.tcl (::tk::FindAltKeyTarget): Make this handle the
	traversal of the logical window manager hierarchy correctly. Based on
	comments by Emiliano Gavilan.

2011-03-28  Jan Nijtmans  <[email protected]>

	* generic/tkTextBTree.c: [Bug 3129527]: Fix buffer overflow w/ GCC 4.5
	and -D_FORTIFY_SOURCE=2. One more place where this problem could
	appear.

2011-03-24  Jan Nijtmans  <[email protected]>

	* win/tkWinMenu.c: [Bug #3239768]: tk8.4.19 (and later) WIN32
	menu font support.

2011-03-16  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:    Make SHLIB_LD_LIBS='${LIBS}' the default and
	* unix/configure: set to "" on per-platform necessary basis.
	Backported from TEA, but kept all original platform code which was
	removed from TEA.

2011-03-14  Jan Nijtmans  <[email protected]>

	* generic/tkBind.c:      Eliminate some more unneeded write-only
	* generic/tkCanvUtil.c:  variables (discovered by gcc-4.6)
	* generic/tkFocus.c:

2011-03-12  Donal K. Fellows  <[email protected]>

	Remove casts from uses of ckalloc/ckfree/... now that Tcl declares
	them to be using useful casts internally.

2011-03-12  Jan Nijtmans  <[email protected]>

	* win/tkWin32Dll.c: Eliminate unneeded _TkFinalize wrapper.

2011-03-11  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkDefaultTheme.c: Eliminate some unneeded write-only
	* generic/ttk/ttkManager.c:      variables (discovered by gcc-4.6)
	* generic/ttk/ttkSquare.c:

2011-03-09  Reinhard Max  <[email protected]>

	* unix/configure.in: Use a symbol from libXft itself for the link
	test rather than one from libfreetype, because the latter doesn't
	work when the linker is called with --as-needed.

2011-03-03  Alexandre Ferrieux  <[email protected]>

	* generic/tkCanvLine.c: [Bug 3175610]: Incomplete refresh of line items.

2011-03-02  Donal K. Fellows  <[email protected]>

	* doc/tk_mac.n (new file): Description of OSX-specific functionality
	in Tk, contributed by Kevin Walzer.
	* doc/button.n, doc/font.n, doc/menu.n: Noted which parts of these
	commands are intentionally not fully supported on OSX.

2011-01-24  Joe English  <[email protected]>

	* generic/tkSelect.c: Fix for [Bug #3164879]: (memory allocation
	bug introduced by [Patch #3129527])

2011-01-22  Joe English  <[email protected]>

	* generic/ttk/ttkEntry.c(ttk::combobox): Add missing
	'validate' command (reported by schelte).

2011-01-13  Jan Nijtmans  <[email protected]>

	* library/msgbox.tcl: [Patch #3154705]: Close button has no effect

2011-01-12  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:         handle --enable-64bit=ia64 for gcc
	* win/configure.in    typo
	* win/configure:      (autoconf-2.59)

2011-01-06   Kevin Walzer <[email protected]>

	* macosx/README:	Added info on textured background windows.
	* macosx/tkMacOSXFont.c: Fix for 2857300, improves rounding up on text
	width [submitted by treectrl]
	* macosx/tkMacOSXMenu.c: Fix for radiobuttons and checkbuttons not
	displaying in popup menus, and disabled menu entries.
	* macosx/tkMacOSXWindowEvent.c:	Fix for 3086887, speeds up scrolling;
	also textured background windows
	* macosx/tkMacOSXWm.c: Textured background windows.

2011-01-06  Stuart Cassoff  <[email protected]>

	* generic/tkEvent.c:	Cast some NULLs to (void *) in order to quash
	* unix/tkUnixEvent.c:	"missing sentinel in function call"
	* unix/tkUnixKey.c:	compiler warnings.
	* unix/tkUnixRFont.c:

2010-12-17  Stuart Cassoff  <[email protected]>

	* unix/Makefile.in:	Clean up '.PHONY:' targets: Arrange those
				common to Tcl and Tk as in Tcl's Makefile.in,
				add any missing ones and remove duplicates.

2010-12-17  Stuart Cassoff  <[email protected]>

	* unix/Makefile.in:  [Bug 2446711]: Remove 'allpatch' target.

2010-12-17  Stuart Cassoff  <[email protected]>

	* unix/Makefile.in:  [Bug 2537626]: Use 'rpmbuild', not 'rpm'.

2010-12-17  Jan Nijtmans  <[email protected]>

	* generic/tkMain.c:  refactor isatty() function for Windows.
	* win/tkWinImage.c:  better warning message.
	* win/tkWinInit.c:   Let TkpDisplayWarning() send the message
	directly to the debugger, if available, otherwise do as before.

2010-12-16  Jan Nijtmans  <[email protected]>

	* generic/tk.h:       [Patch 3124554]: Move WishPanic from Tk to Tcl
	* win/winMain.c:      Remove special MessageBox'es here, since every
	panic-related thing is now handled correctly by Tcl.

2010-12-15  Stuart Cassoff  <[email protected]>

	* unix/Makefile.in:	Installer Improvements.
	* unix/install-sh:	Similar to Tcl [Patch 3101127].

2010-12-15  Jan Nijtmans  <[email protected]>

	* generic/tkMain.c:	[Patch #3124683]: platform specific stuff
	in (tcl|tk)Main.c

2010-12-13  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:		[Bug 3135271]: Link error due to hidden
	* unix/configure:	symbols (CentOS 4.2)  (autoconf-2.59)
	* generic/tkMain.c:	Change "Application initialization failed" to
	* tests/main.test:	"application-specific initialization failed",
	for consistency with Tcl.
	* win/tkWin32Dll.c:	See also: [Patch 1910041] and [Patch 3059922].
	SEH emulation on Win64 was not correct here: it sometimes results in
	a crash. Contrary to the other places, the code here is not meant to
	protect from OS bugs, but to protect Finalizing Tk when the application
	went in an invalid state.

2010-12-12  Stuart Cassoff  <[email protected]>

	* unix/tcl.m4: Better building on OpenBSD.
	* unix/configure: (autoconf-2.59)

2010-12-10  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:	Fix manifest-generation for 64-bit gcc (mingw-w64)
	* win/configure: (autoconf-2.59)

2010-12-06  Jan Nijtmans  <[email protected]>

	* generic/tkSelect.c:	[Bug 3129527]: Fix buffer overflow w/ GCC 4.5
	* generic/tkTextDisp.c: and -D_FORTIFY_SOURCE=2
	* unix/tkUnixWm.c:
	* win/tkWinWm.c:

2010-12-05  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:      [Patch 3116490]: cross-compile support for unix
	* unix/configure    (autoconf-2.59)

2010-12-03  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:	[Patch 3116490]: cross-compile Tcl mingw32 on unix
	* win/configure: This makes it possible to cross-compile Tcl/Tk for
	Windows (either 32-bit or 64-bit) out-of-the-box on UNIX, using
	mingw-w64 build tools.

2010-12-02  Donal K. Fellows  <[email protected]>

	* generic/tkInt.decls (TkDrawAngledTextLayout,TkDrawAngledChars,...):
	Expose angled text API for Emiliano Gavilán. Still only in internal
	stub table.

2010-11-29  Jan Nijtmans  <[email protected]>

	* generic/tkAtom.c:    Fix various 64-bit gcc(-4.5.2) warnings: cast
	* generic/tkSelect.c:  from pointer to integer of different size.
	* win/stubs.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinPixmap.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWindow.c:
	* win/tkWinWm.c:
	* win/ttkWinMonitor.c:
	* win/tkWin32Dll.c:   Make assembler code compile in Win64 with gcc.

2010-11-24  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c:  [Bug 3071836]: Crash/Tcl_Panic on WinXP saving
	* win/tkWinInit.c:    file to C:\, and rewrite TkpDisplayWarning not
	to use any Tcl functions any more. This allows TkpDisplayWarning to be
	used as panic proc.
	* win/winMain.c:      Use TkpDisplayWarning as panic proc on Windows.
	* generic/tkMain.c:   Remove unused strrchr, combine outChannel and
	errChannel variables to a single variable.

2010-11-19  Jan Nijtmans  <[email protected]>

	* generic/tkCanv*.c:         Revise Tcl_Panic() calls ending with a
	* generic/tkGeomerty.c:      newline removing the newline, because
	* generic/tkImgPhInstance.c: Tcl_Panic() outputs a final newline
	* generic/tkMenu.c:	     already.
	* generic/tkRectOval.c:
	* generic/tkTextBTree.c:
	* generic/tkWindow.c:
	* unix/tkUnixRFont.c:
	* win/tkWinColor.c:
	* win/tkWinDraw.c:
	* win/tkWinMenu.c:

2010-11-18  Jan Nijtmans  <[email protected]>

	* win/winMain.c:   [FRQ 491789]: "setargv() doesn't support a unicode
	cmdline" now implemented for cygwin and mingw32 too.
	* win/configure.in:	Allow cross-compilation by default.
	* win/configure    (regenerated)

2010-11-17  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:      [FRQ 491789]: "setargv() doesn't support a unicode
	cmdline" now implemented for mingw-w64
	* win/configure    (regenerated)
	* win/winMain.c    Workaround for bug in some versions of mingw-w64

2010-11-16  Jan Nijtmans  <[email protected]>

	* win/winMain.c    Bring compilation under mingw-w64 a bit closer
	* win/tcl.m4       to reality. See for what's missing:
	    https://sourceforge.net/apps/trac/mingw-w64/wiki/Unicode%20apps
	* win/configure:   (re-generated)
	* win/tkWinPort.h: [Bug 3110161]: Extensions using TCHAR don't compile
	on VS2005 SP1

2010-11-10  Andreas Kupries  <[email protected]>

	* changes:	Updates for 8.6b2 release.

2010-11-06  Jan Nijtmans  <[email protected]>

	* library/msgs/*.msg:	Update NL catalog. For other languages,
	sorting and fix some locations of "&".

2010-11-05  Jan Nijtmans  <[email protected]>

	* library/demos/widget: Use unicode copyright sign, instead of
	* library/demos/en.msg: depending on translation.
	* library/demos/nl.msg:
	* generic/tkMain.c:    Sync TK_ASCII_MAIN usage with tclMain.c

2010-11-04  Don Porter  <[email protected]>

	* changes:	Updates for 8.6b2 release.

2010-11-03  Jan Nijtmans  <[email protected]>

	* win/tkWinClipboard.c: [FRQ 2965056]: Windows build with
	* win/tkWinDialog.c:     -DUNICODE
	* win/tkWinMenu.c:

2010-10-11  Jan Nijtmans  <[email protected]>

	* generic/tkDecls.h:  [FRQ 491789]: "setargv() doesn't support a
	* doc/Tk_Main.3:      unicode cmdline" implemented for Tk on MSVC++
	* win/Makefile.in:
	* win/makefile.vc:
	* win/winMain.c:
	* win/rules.vc:       Update for VS10

2010-10-11  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c: [Bug 3085489]: Fix crash in 'tag add' /
	'tag remove' commands when no -tags specified.

2010-10-11  Jan Nijtmans  <[email protected]>

	* win/tkWinMenu.c:    [FRQ 2965056]: Windows build with -DUNICODE
	* win/tkWinWm.c:
	* win/tcl.m4:         Add netapi32 to the link line, so we no longer
	* win/makefile.vc:    have to use LoadLibrary to access those
	* win/configure:      functions.

2010-10-06  Jan Nijtmans  <[email protected]>

	* win/tkWinClipboard.c: [FRQ 2965056]: Windows build with
	* win/tkWinColor.c:     -DUNICODE
	* win/tkWinCursor.c:
	* win/tkWinFont.c:
	* win/tkWinTest.c:
	* win/tkWinMenu.c:
	* win/tkWinPixmap.c:
	* win/tkWinX.c:         Eliminate isWinNT variable
	* win/Makefile.in (genstubs): Generate ttk files as well.

2010-10-06  Donal K. Fellows  <[email protected]>

	* win/Makefile.in (genstubs): [Tcl Bug 3082049]: Typo.

2010-10-05  Jan Nijtmans  <[email protected]>

	* generic/tkWinX.c: [Bug 3080953]: Malformed Unicode characters in %A
	substitution Problem was in the static function GetTranslatedKey().

2010-10-01  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock):
	[Bug 3078902]: Ensure that zero-dimensioned data blocks cause no
	changes at all instead of causing a hang.

2010-09-29  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:         Sync with Tcl version
	* unix/configure:      Re-generate with autoconf-2.59
	* win/configure:
	* generic/tkMain.c     Make compilable with -DUNICODE as well

2010-09-28  Jan Nijtmans  <[email protected]>

	* win/tkWinSend.c: [Bug 3076671]: CVS HEAD Tk build fails on win32
	with msys/mingw. Make it compile on older mingw as well.
	* generic/tk.decls:   Add explicit scspec "EXTERN", as in Tcl
	* generic/tkInt.decls:
	* generic/tkStubInit.c: Don't let Tk_MainEx macro disturb compilation

2010-09-23  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:            Add -Wdeclaration-after-statement
	* win/configure:         (regenerated)
	* win/tkWinX.c:          Make compilable with -DUNICODE.
	* win/winMain.c:
	* unix/tkAppInit.c:      Many clean-ups in comments, so all
	(tcl|tk)AppInit.c variants use the same style.
	* generic/ttk/ttkGenStubs.tcl: Dummy genStubs::export (from
	genStubs.tcl)

2010-09-20  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkGenStubs.tcl: Clean-up, port all genStubs.tcl changes
	* generic/ttk/ttk.decls:    from Tcl to ttkGenStubs.tcl as well (no
	* generic/tk.decls:         change in any output files). This brings
	* generic/tkInt.decls:      all *.decls in the same form as tcl.decls

2010-09-16  Jeff Hobbs  <[email protected]>

	* win/tkWinX.c (_WIN32_IE): update to IE5.5 base expectation

2010-09-14  Jan Nijtmans  <[email protected]>

	* win/rules.vc       [FRQ 2965056]: Windows build with -DUNICODE
	* win/Makefile.in

2010-09-13  Jan Nijtmans  <[email protected]>

	* win/tkWin.h          Move definitions of WINVER/_WIN32_WINNT
	* win/tkWinDialog.h    to one place, now that we only support
	* win/tkWinMenu.c      Win2000+
	* win/tkWinX.c

2010-09-10  Jan Nijtmans  <[email protected]>

	* win/tkWinEmbed.c:     Make compilable with -DUNICODE
	* win/tkWinClipboard.c: Mark those files as not compilable with
	* win/tkWinColor.c:     -DUNICODE, so add a TODO.
	* win/tkWinCursor.c:
	* win/tkWinDialog.c:
	* win/tkWinFont.c:
	* win/tkWinMenu.c:
	* win/tkWinPixmap.c:
	* win/tkWinTest.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
	* win/winMain.c:
	* win/tkWinPort.h:  mingw/cygwin fixes: <tchar.h> should always
	be included here.

2010-09-09  Jan Nijtmans  <[email protected]>

	* win/rules.vc:   (sync with tcl version)
	* win/makefile.vc: mingw should always link with -ladvapi32
	* win/tcl.m4:
	* win/configure:   (regenerated)
	* win/tkWinInt.h:  Remove ascii variant of tkWinPocs table,
	* win/tkWinX.c:    it is no longer necessary.
	* win/tkWinTest.c:

2010-09-08  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c (TreeviewSeeCommand): [Bug 2829363]:
	Schedule redisplay if [$tv see] opens any items.

2010-09-05  Donal K. Fellows  <[email protected]>

	* library/bgerror.tcl: [Bugs 3046742,3046750]: Improve keybindings for
	the background error dialog, and allow the use of the window manager
	controls for closing it (where supported). The Escape key now causes
	all remaining background error messages in the queue to be dropped.

2010-09-02  Joe English  <[email protected]>

        * library/ttk/winTheme.tcl, library/ttk/xpTheme.tcl,
	* library/ttk/vistaTheme.tcl: [Bug 3057573]: Specify disabled combobox
	text foreground color.

2010-08-31  Andreas Kupries  <[email protected]>

	* win/tcl.m4: Applied patch by Jeff fixing issues with the manifest
	handling on Win64.
	* win/configure: Regenerated.

2010-08-26  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in: Add valgrind target
	* unix/configure, unix/tcl.m4: [Bug 1230554]: SHLIB_LD_LIBS='${LIBS}'
	for OSF1-V*. Add /usr/lib64 to set of auto-search dirs.
	(SC_PATH_X): Correct syntax error when xincludes not found.

	* win/Makefile.in (VC_MANIFEST_EMBED_DLL VC_MANIFEST_EMBED_EXE):
	* win/configure, win/configure.in, win/tcl.m4: SC_EMBED_MANIFEST macro
	and --enable-embedded-manifest configure arg added to support manifest
	embedding where we know the magic. Help prevents DLL hell with MSVC8+.

	* generic/tkText.c (DumpLine): [Bug 3053347]: Replace segPtr->size
	with currentSize throughout, but particularly in if lineChanged block
	where segPtr may no longer be valid.

2010-08-21  Jan Nijtmans  <[email protected]>

	* generic/tk*Decls.h:   (regenerated with modified genStubs.tcl)
	* generic/tk*StubInit.c

2010-08-18  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkGenStubs.tcl: [Patch 3034251]: partly: remove some
	more unneeded ifdeffery, as in tcl/tools/genStubs.tcl.
	* generic/tk.h:     Move USE_OLD_IMAGE support after tkDecls.h
	* generic/*Decls.h  (regenerated)
	* generic/ttk/ttkDecls.h

2010-08-11  Jeff Hobbs  <[email protected]>

	* win/Makefile.in (%.${OBJEXT}): Better implicit rules support

	* unix/configure: regen with ac-2.59
	* unix/configure.in, unix/Makefile.in:
	* unix/tcl.m4 (AIX): Remove the need for ldAIX, replace with
	-bexpall/-brtl.  Remove TK_EXP_FILE (export file) and other baggage
	that went with it.  Remove pre-4 AIX build support.

2010-08-11  Don Porter  <[email protected]>

	* changes:	Updates for 8.6b2 release.

2010-08-04  Jeff Hobbs  <[email protected]>

	* license.terms: fix DFARs note for number-adjusted rights clause

2010-08-03  Jeff Hobbs  <[email protected]>

	* library/button.tcl (::tk::CheckEnter): [AS Bug#87409]: Use uplevel
	set instead of set :: to work with other var resolvers (itcl).

2010-07-19  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c (StringWriteGIF): Added ability to write a GIF to
	a string (as a byte array, of course) following comments on c.l.t by
	Aric Bills. Also improved readability of some of the function and
	field names in this file.

2010-07-16  Jan Nijtmans  <[email protected]>

	* generic/tkDecls.h: [Tcl Bug 3029891]: Functions that don't belong in
	the stub table (Tk part, not really removed from the stub table, just
	disabled)
	* generic/tkMain.c:  [Bug 3027438]: Tk_Main calls Tcl_CreateInterp
	* generic/tk.h:      before Tcl_FindExecutable

2010-07-06  Andreas Kupries  <[email protected]>

	* doc/text.n: Fixed minor typo in the description of 'text delete', as
	reported by <[email protected]> on the chat.

2010-07-01  Jan Nijtmans  <[email protected]>

	* win/rules.vc:  [Bug 3020677]: wish can't link reg1.2

2010-06-22  Anton Kovalenko  <[email protected]>

	* generic/tkPlace.c: [Patch 3019624]: modify "place" command, making
	it get main window through ClientData (like grid or pack do), instead
	of calling Tk_MainWindow(interp).
	* generic/tkWindow.c: modify "place" entry in commands[], turn on
	passMainWindow flag.

2010-06-22  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkGenStubs.tcl: [Bug 3019363]: "make genstubs" failure
	* generic/ttk/ttkDecls.h:      (regenerated)
	* generic/ttk/ttkTheme.c:      Unnecessary type cast

2010-06-21  Jan Nijtmans  <[email protected]>

	* generic/tkInt.decls: [Patch 2999889]: TkCopyAndGlobalEval obsolete
	* generic/tkIntDecls.h
	* generic/tkBind.c
	* generic/tkStubInit.c

2010-06-19  Joe English  <[email protected]>

	* win/tkWinScrlbr.c, carbon/tkMacOSXScrlbr.c: Replace binding
	procedures with ordinary event handlers [Patch 3009998].
	* generic/tkBind.c, generic/tk.h, generic/tkInt.h,
	* generic/tkInt.decls: Simplifications enabled by previous change:
	TkCreateBindingProcedure() and associated machinery no longer needed;
	TkBindDeadWindow() no longer needed; TK_DEFER_MODAL_LOOP and
	associated machinery no longer needed.
	* generic/tkTest.c, tests/bind.test: Tests related to C binding
	procedures no longer needed.
	* generic/tkWindow.c: TkBindDeadWindow() no longer needed.
	* generic/tkIntDecls.h, generic/tkStubInit.c: Regenerated.

2010-06-15  Joe English  <[email protected]>

	* library/ttk/ttk.tcl: Bump dummy [package ifneeded tile] version to
	0.8.6; see [Bug 3016598].

2010-06-15  Donal K. Fellows  <[email protected]>

	* library/text.tcl (TextCursorInSelection): [Patch 2585265]: Make it
	so that pressing delete or backspace when the primary selection does
	not include the insertion cursor does not cause the deletion of the
	inserted text.

2010-06-15  Jan Nijtmans  <[email protected]>

	* generic/tkCanvArc.c:	Eliminate many unnecessary (ClientData) type
	* generic/tkCanvas.c:	casts.
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvTest.c:
	* generic/tkCanvWind.c:
	* generic/tkRectOval.c:
	* generic/tkScrollbar.c:
	* generic/tkStyle.c:
	* generic/tkTest.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixEvent.c:
	* unix/tkUnixScale.c:
	* unix/tkUnixScrlbr.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixWm.c:
	* carbon/tkMacOSXDialog.c: Terminate TkEnsemble definition with NULL
	* macosx/tkMacOSXDialog.c:

2010-05-31  Joe English <[email protected]>

	* generic/tkBind.c (Tk_CreateBinding): [Bug 3006842]: Silently ignore
	empty scripts.

2010-05-27  Joe English <[email protected]>

	* generic/ttk/ttkTreeview.c, tests/ttk/treeview.test:
	[$tv tag bind $tag <...> {}] now removes binding completely.
	Fixes [Bug 3006842] (although there's still a problem somewhere
	in Tk_CreateBinding()).

2010-05-26  Jan Nijtmans  <[email protected]>

	* tests/wm.test: Fix 3 tests on Ubuntu 10.4, two of them timing
	dependent, one wm-dependent.
	* generic/tkText.c:	Fix some gcc strict-aliasing warnings,
	* unix/tkUnixFont.c:	discovered with "-Wstrict-aliasing=2"
	* unix/tkUnixSelect.c:

2010-05-20  Donal K. Fellows  <[email protected]>

	* win/tkWinX.c (HandleIMEComposition): [Bug 2992129]: Ensure that all
	places that generate key events zero them out first; Tk relies on that
	being true for the generic parts of the fix for Bug 1924761.

2010-05-17  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: Fix [Bug 3002230]: tk_chooseDirectory returns
	garbage on cancel

2010-05-17  Joe English  <[email protected]>

	* generic/tkBind.c: Revert [Patch 2999920], as it entails an
	incompatible change to the C API is and is the cause of [Bug 3002768].

2010-05-17  Jan Nijtmans  <[email protected]>

	* generic/tkBind.c: [Patch 2999920]: Optimize Internal Virtual event
	string operations.
	* win/tkWinDialog.c: [Bug 2987995]: Tk_getOpenFile returns garbage
	under described circumstances

2010-05-11  Jan Nijtmans  <[email protected]>

	* doc/RestrictEv.3:  Consistent use of variable names in RestrictEvent
	* generic/tkGrab.c:  API documentation and implementation: Use 'prev'
	* unix/tkUnixDraw.c: instead of 'old', and 'arg' instead of
	* unix/tkUnixSend.c: 'clientData' everywhere, just as in tkEvent.c.
	* unix/tkUnixWm.c

2010-05-10  Jan Nijtmans  <[email protected]>

	* doc/BindTable.3:     Bring in line with actual implementation.
	* generic/tk.decls:    Change Tk_CreateBinding param name, as in doc
	* generic/tkInt.decls: CONSTify TkCopyAndGlobalEval,
	* generic/tkBind.c:    TkpSetMainMenubar, TkpMenuNotifyToplevelCreate,
	* generic/tkMenu.c:    and TkSetWindowMenuBar
	* generic/tkDecls.h:    (regenerated)
	* generic/tkIntDecls.h: (regenerated)
	* carbon/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenu.c:
	* unix/tkUnixMenu.c:
	* win/tkWinMenu.c:

2010-05-03  Don Porter  <[email protected]>

	* generic/tk.h:		Bump patchlevel to 8.6b1.2 to distinguish
	* library/tk.tcl:	CVS snapshots from earlier snapshots as well
	* unix/configure.in:	as the 8.6b1 and 8.6b2 releases.
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2010-05-03  Donal K. Fellows  <[email protected]>

	* library/button.tcl (CheckInvoke, CheckEnter): [Patch 1530276 redux]:
	Apply a bit more care to ensure that things continue to work correctly
	even when there is no -selectcolor defined.

2010-04-29  Jan Nijtmans  <[email protected]>

	* win/tkWin.h:		Unnecessary TCL_STORAGE_CLASS re-definition
	* win/tkWinInt.h:	Make various functions MODULE_SCOPE
	* win/tkWinButton.c:	TCHAR-related fixes, making al those
	* win/tkWinFont.c:	files compile fine when TCHAR != char.
	* win/tkWinScrlbr.c:
	* win/tkWinWindow.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
	* win/ttkWinMonitor.c:
	* win/ttkWinXPTheme.c:

2010-04-25  Donal K. Fellows  <[email protected]>

	* generic/tkImgPNG.c (ReadIDAT, DecodePNG): Move the check for overall
	termination of the compressed stream until after the final IDAT has
	been read, so that multi-segment images will work right. Reported by
	Andy Goth on the Wiki.

2010-04-23  Jan Nijtmans  <[email protected]>

	* generic/tkImgGIF.c:  Formatting
	* generic/tkListbox.c: fix typo;
	* generic/tkTrig.c:    fix typo;
	* generic/tkInt.h:     fix typo; remove not existing tkDisplayList;
	* generic/*.h:         Useless re-definitions of TCL_STORAGE_CLASS

2010-04-20  Jan Nijtmans  <[email protected]>

	* generic/tkPort.h:         Make sure that tkWinPort.h is always
	* generic/tkIntXlibDecls.h: included before tcl.h, otherwise the
	* win/tkWinPort.h:          fallback for TCHAR might go off before the
				    inclusion of <tchar.h>
	* win/tkWinDialog.c:        Define OPENFILENAME_SIZE_VERSION_400 if
				    needed.
	* compat/stdlib.h:          Include <tcl.h> only when not already
	* compat/unistd.h:	    done.
	* generic/tkInt.h:          tkPort.h already includes tk.h, which
				    includes tcl.h.
	* generic/tk3d.h:           Always use #include "tkInt.h", not
	* generic/tkColor.h:	    <tkInt.h>
	* xlib/xcolors.c:
	* xlib/xgc.c:

2010-04-19  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: Fix [Bug 2987995]: Tk_GetOpenFile returns garbage
	under described circumstances.
	* win/tkWinDialog.c: [Patch 2898255]: Filenames limit with
	Tk_GetFileName().
	Assure modern style dialogs where available

2010-04-13  Jan Nijtmans  <[email protected]>

	* win/tkWinPort.h     Fix [Patch 2986105]: conditionally defining
	strcasecmp/strncasecmp

2010-04-12  Donal K. Fellows  <[email protected]>

	* generic/tkImgPNG.c (WriteIDAT): [Bug 2984787]: Use the correct
	flushing semantics when handling the last data from the image. Without
	this, many PNG readers (notably including Firefox) refuse to show the
	image and instead complain about errors.
	(ReadIDAT): Added sanity checks to ensure that when we've got bad data
	of the sorts of forms we were previously generating, we detect it and
	error out rather than silently failing.
	(WriteExtraChunks): New function to write in some basic metadata.

2010-04-09  Jan Nijtmans  <[email protected]>

	* doc/photo.n:    Follow-up to [Bug 2983824]: update doc.

2010-04-09  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoCmd): [Bug 2983824]: Use the file
	extension to guess the output format to use if one isn't specified.

2010-04-08  Jan Nijtmans  <[email protected]>

	* win/tkWinPort.h:    Add <wchar.h> to tkWinPort.h, and
	* win/tkWinSend.c:    remove some earlier CYGWIN-related
	* win/tkWinSendCom.c: hacks which are no longer necessary.

2010-04-06  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:         Sync with Tcl version
	* unix/tcl.m4:
	* win/configure:      (regenerate with autoconf-2.59)
	* unix/configure:     [Bug 2982540]: configure and install* script
			      files should always have LF

2010-03-29  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:            Only test for -visibility=hidden with gcc
	                          (Second remark in [Bug 2976508])
	* unix/configure:         regen

2010-03-29  Donal K. Fellows  <[email protected]>

	* unix/tkUnixRFont.c (GetFont): [Bug 2978410]: Do not use non-constant
	initializers for structures, since HP-UX cc doesn't like it.

2010-03-28  Joe English  <[email protected]>

	* generic/ttk/ttkTagSet.c, generic/ttk/ttkTheme.c,
	* generic/ttk/ttkTheme.h, generic/ttk/ttkTreeview.c,
	* generic/ttk/ttkWidget.h, doc/ttk_treeview.n,
	* tests/ttk/treetags.test: ttk::treeview widget: add 'tag names',
	'tag add', and 'tag remove' methods.

2010-03-23  Donal K. Fellows  <[email protected]>

	* unix/configure.in, unix/Makefile.in: [Bug 2965133]: Get rid of the
	spurious NONE and some pointless quotes that were causing problems
	with building Tk on OSX. Overall bug might not yet be solved.

2010-03-17  Donal K. Fellows  <[email protected]>

	* library/entry.tcl:	 [Bug 2971663]: Make the <Up> and <Down> keys
	* library/ttk/entry.tcl: explicitly do nothing, since Tk-on-Cocoa will
	generate (invisible zero-width) characters for them otherwise. The
	explicitly empty bindings are harmless on other platforms.

2010-03-16  Jan Nijtmans  <[email protected]>

	* unix/.cvsignore:	Ignore .a and .so

2010-03-12  Jan Nijtmans  <[email protected]>

	* win/rules.vc:		Fix [Tcl Bug 2967340]: Static build failure
	* win/makefile.vc:
	* win/.cvsignore:

2010-03-12  Donal K. Fellows  <[email protected]>

	* library/iconlist.tcl:		Factor out some of the machinery for
	* library/megawidget.tcl:	making a megawidget framework. Not a
					public API at the moment.

2010-03-11  Donal K. Fellows  <[email protected]>

	* generic/tkText.c (DumpLine): [Bug 2968379]: When peers are about,
	there can be unnamed marks present during a dump. Ignore them as they
	will just be for the peers' insert and current marks, which aren't
	very important.
	(DumpLine): Removed lame reliance on the leading letters of the names
	of segment types. Entailed expanding the scope of the declarations of
	the types of embedded images and windows.

2010-03-08  Don Porter  <[email protected]>

	* generic/tkPlatDecls.h: [Bug 2965600]: Correct broken 2886635 fix.

2010-03-06  Pat Thoyts  <[email protected]>

	* library/menu.tcl: [Bug 2949774]: When using the non-ClickToFocus
	menu mode cascade menus should popdown once the pointer moves to
	another entry to be compatible with current X desktop usage.

2010-03-04  Jan Nijtmans  <[email protected]>

	* unix/configure.in:    Don't use -fvisibility=hidden
	* unix/tcl.m4:          for cygwin.
	* win/tkWinTest.c:      Make tkTestWinProcs const

2010-03-04  Donal K. Fellows  <[email protected]>

	* doc/clipboard.n: Added note about STRING vs. UTF8_STRING types.

2010-03-02  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4: [Tcl FRQ 2959069]: Support for -fvisibility=hidden
	* unix/configure:  (regenerated with autoconf-2.59)

2010-02-23  Jan Nijtmans  <[email protected]>

	* unix/configure.in:    Use @EXEEXT@ in stead of @EXT_SUFFIX@
	* unix/tcl.m4:
	* unix/Makefile.in:     Use -DBUILD_tk
	* unix/configure:       (regenerated)
	* generic/tkConfig.c:   Make internal Tk_ObjCustomOption const
	* generic/tkPanedWindow.c:
	* generic/tkTest.c:
	* generic/tkText.c:

2010-02-21  Donal K. Fellows  <[email protected]>

	* generic/tkText.c (TextEditCmd): [Bug 1799782]: Refix this, so that
	<<Modified>> events are issued when things change.

2010-02-20  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c: Cache the result of the last call to
	EndPosition() to avoid quadratic-time behavior in the common cases
	where the treeview is populated in depth-first or breadth-first
	order.

2010-02-19  Jan Nijtmans  <[email protected]>

	* win/tkWinColor.c:	 remove unused "dataKey" variable

2010-02-19  Donal K. Fellows  <[email protected]>

	* unix/configure.in, unix/Makefile.in: [Bug 2415437]: Corrections to
	allow installation of Tcl and Tk to different directories, especially
	when neither is a system standard location. Also [Tcl Bug 2307398].

	* unix/installManPage: [Tcl Bug 2954638]: Correct behaviour of manual
	page installer. Also added armouring to check that assumptions about
	the initial state are actually valid (e.g., look for existing input
	file).

2010-02-19  Stuart Cassoff  <[email protected]>

	* tcl.m4: Correct compiler/linker flags for threaded builds on
	OpenBSD.
	* configure: (regenerated).

2010-02-18  Jan Nijtmans  <[email protected]>

	* generic/tkButton.h:	Put all Tk_OptionSpec for buttons and labels
	* generic/tkButton.c:	in const memory. With some changes to win32
	* win/tkWinButton.c:	and macosx, preventing direct writes to
	* unix/tkUnixPort.h:	read-only memory.
	* carbon/tkMacOSXPort.h:
	* macosx/tkMacOSXButton.c:

2010-02-17  Joe English  <[email protected]>

	* generic/tkMenu.c: [Bug 2952745]: Defer TkMenuOptionTables cleanup to
	CallWhenDeleted() time, to ensure that the record doesn't get freed
	until after all widget instance commands have been deleted.

2010-02-17  Jan Nijtmans  <[email protected]>

	* generic/tk.decls:	CONSTify everything related to Tk_ConfigSpec
	* generic/tk.h:
	* generic/tkCanvArc.c:	Many tables can now be put in const memory
	* generic/tkCanvas.c:
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvPs.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkOldConfig.c:
	* generic/tkRectOval.c:
	* generic/tkScrollbar.c:
	* generic/tkScrollbar.h:
	* generic/tkDecls.h:	(regenerated)
	* doc/CanvTkwin.3:
	* doc/ConfigWidg.3:
	* doc/CrtItemType.3:
	* win/tkWinScrlbr.c:
	* carbon/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXScrlbr.c:

2010-02-16  Jan Nijtmans  <[email protected]>

	* generic/tkWindow.c:	Reverted rename from tkStubs to tkConstStubs
	* generic/tkStubInit.c: (regenerated)
	* generic/tkArgv.c:	make defaultTable const
	* generic/tkScrollbar.c:Store default for "-with" in static non-const
				space
	* win/tkWinInt.h:	Make tkWinProcs const, and 5 procs
	* win/tkWinX.c:		MODULE_SCOPE.
	* win/tkWinColor.c:	Make sysColors const.
	* win/tkWinKey.c:	Make keymap const.
	* win/tkWinScrlbr.c:	Simplify copying of "-with" default value.
	* unix/tkUnixWm.c:	Make TkSetTransientFor static.
	* tests/textImage.test: textImage-1.13 depends on hash-order

2010-02-12  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:		Use -pipe for gcc on win32
	* win/configure:	(mingw/cygwin) (regenerated)
	* unix/tkUnixColor.c:	Make sure that TkpCmapStressed is exported
	* generic/tkImgPhoto.c:	Clean up unused Tk_CreatePhotoOption
	* generic/tkBind.c:	Make more internal arrays "const"
	* generic/tkBusy.c:
	* generic/tkButton.c:
	* generic/tkEvent.c:
	* generic/tkGrab.c:
	* generic/tkImgBmap.c:
	* generic/tkObj.c:
	* generic/tkOption.c:
	* generic/tkPanedWindow.c:
	* generic/tkPointer.c:
	* generic/tkWindow.c:
	* generic/tkImgPhoto.c:	Eliminate never used Tk_CreatePhotoOption()

2010-02-05  Jan Nijtmans  <[email protected]>

	* carbon/tkMacOSXDialog.c:  Make more internal tables "const"
	* macosx/tkMacOSXDialog.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixWm.c:
	* win/tkWinDialog.c:
	* generic/tkWindow.c:
	* generic/tk*Decls.h:       (regenerated with new
	* generic/tkStubInit.c:     genStubs.tcl from Tcl)

2010-02-05  Joe English  <[email protected]>

	* generic/ttk/*.[ch]: Revert contravariant const qualifiers added by
	the previous commit to keep codebase in sync with the Tile extension,
	which must remain 8.4 compatible.

2010-02-05  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkGenStubs.tcl: Follow-up to [2010-01-29] commit:
	        prevent space within stub table function parameters if the
	        parameter type is a pointer. Make the various stub tables and
	        hook pointers const, just as Tcl and Tk.
	* generic/ttk/ttkDecls.h: (regenerated)
	* generic/ttk/ttkStubInit.c: (regenerated)
	* generic/ttk/ttk.decls:	Minor formatting
	* generic/ttk/ttkButton.c:	Make more internal tables "const"
	* generic/ttk/ttkDefaultTheme.c:
	* generic/ttk/ttkEntry.c:
	* generic/ttk/ttkImage.c:
	* generic/ttk/ttkInit.c:
	* generic/ttk/ttkLayout.c:
	* generic/ttk/ttkNotebook.c:
	* generic/ttk/ttkPanedWindow.c:
	* generic/ttk/ttkProgress.c:
	* generic/ttk/ttkStubLib.c:
	* generic/ttk/ttkTheme.c:
	* generic/ttk/ttkTreeview.c:
	* generic/ttk/ttkWidget.c:
	* generic/ttk/ttkWidget.h:

2010-01-31  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.h, generic/ttk/ttkWidget.h, generic/ttk/*.c:
	Change signature of widget subcommand procedures to match
	Tcl_ObjCmdProc. Merge now-redundant ensemble dispatch code.

2010-01-29  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkGenStubs.tcl: No longer generate a space after "*"
	                        and immediately after a function name, so the
	                        format of function definitions in *Decls.h
	                        match all other *.h header files.
	* generic/ttk/ttkDecls.h: (re-generated)
	* generic/tk.decls:	Formatting
	* generic/tkDecls.h:	(re-generated)
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkBind.c:	Little simplification

2010-01-19  Jan Nijtmans  <[email protected]>

	* generic/tkInt.h:           Don't depend on <stdio.h> from tcl.h any
	* generic/tkOldConfig.c:     more.
	* generic/ttk/ttkClamTheme.c:	 Fix more gcc warnings: missing
	* generic/ttk/ttkClassicTheme.c: initializer.
	* generic/ttk/ttkDefaultTheme.c:
	* generic/ttk/ttkElements.c:
	* generic/ttk/ttkEntry.c:
	* generic/ttk/ttkInit.c:
	* generic/ttk/ttkLabel.c:
	* generic/ttk/ttkNotebook.c:
	* generic/ttk/ttkPanedwindow.c:
	* generic/ttk/ttkSquare.c:
	* generic/ttk/ttkTreeview.c:
	* win/ttkWinTheme.c:
	* win/tkWinMenu.c:     Add missing #include <string.h>
	* win/tkWinPort.h:     Fix include files for CYGWIN
	* win/tkWinSend.c:
	* win/tkWinSendCom.c:
	* win/tkWinTest.c:     Fix gcc warning
	* win/winMain.c:       Eliminate use of __argc and __argv for CYGWIN
	* win/tcl.m4:          Make cygwin configuration error into
	* win/configure.in:    a warning: CYGWIN compilation works
	* win/configure:       although there still are test failures.

2010-01-19  Donal K. Fellows  <[email protected]>

	* generic/tkCanvas.c (TagSearchScanExpr): [Bug 2931374]: Stop overflow
	of working buffer during construction of long tag expressions.

2010-01-19  Pat Thoyts  <[email protected]>

	TIP #359 IMPLEMENTATION

	* library/bgerror.tcl:  Extended Window Manager Hints following the
	* library/clrpick.tcl:  freedesktop.org specification are now
	* library/demos/widget: supported on X11 using a new [wm attribute]
	* library/dialog.tcl:   called '-type'. This feature is now used in
	* library/msgbox.tcl:   the Tk library functions where appropriate.
	* library/tkfbox.tcl:
	* library/ttk/combobox.tcl:
	* tests/unixWm.test:
	* tests/wm.test:
	* unix/tkUnixWm.c:

2010-01-18  Jan Nijtmans  <[email protected]>

	* generic/tkCanvArc.c:	Fix more gcc warnings: missing initializer
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvPs.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkCmds.c:
	* generic/tkImgBmap.c:
	* generic/tkImgGIF.c:
	* generic/tkImgPhoto.c:
	* generic/tkImgPNG.c:
	* generic/tkImgPPM.c:
	* generic/tkMenu.c:
	* generic/tkMenubutton.c:
	* generic/tkMessage.c:
	* generic/tkOldTest.c:
	* generic/tkPanedWindow.c:
	* generic/tkRectOval.c:
	* generic/tkScrollbar.c:
	* generic/tkSquare.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkTextImage.c:
	* generic/tkTextTag.c:
	* generic/tkTextWind.c:
	* generic/tkTrig.c:
	* generic/tkCanvas.c:      [Patch 2932808]: Canvas items not updating
				   on widget state change.

2010-01-13  Jan Nijtmans  <[email protected]>

	* generic/tkMenubutton.h:  Eliminate tkpMenubuttonClass
	* generic/tkButton.h       make tkpButtonProcs CONST
	* generic/tkBusy.c:        fix gcc warning: missing initializer
	* generic/tkButton.c
	* generic/tkCanvas.c
	* generic/tkConsole.c
	* generic/tkEntry.c
	* generic/tkFrame.c
	* generic/tkListbox.c
	* generic/tkMenu.c
	* generic/tkMenubutton.c
	* generic/tkMessage.c
	* generic/tkScale.c
	* generic/tkScrollbar.h
	* generic/tkText.c
	* generic/ttk/ttkWidget.c
	* carbon/tkMacOSXButton.c
	* carbon/tkMacOSXMenubutton.c
	* carbon/tkMacOSXScrlbr.c
	* macosx/tkMacOSXButton.c
	* macosx/tkMacOSXMenubutton.c
	* macosx/tkMacOSXScrlbr.c
	* unix/tkUnixButton.c
	* unix/tkUnixMenubu.c
	* unix/tkUnixScrolbr.c
	* win/tkWinButton.c
	* win/tkWinDialog.c
	* win/tkWinEmbed.c
	* win/tkWinFont.c
	* win/tkWinInit.c
	* win/tkWinKey.c
	* win/tkWinScrlbr.c
	* win/tkWinInt.h      Add SPI_SETKEYBOARDCUES definition, needed for
	                      original VC++ 6.0.

2010-01-10  Jan Nijtmans  <[email protected]>

	* doc/SetClassProcs.3:  CONSTify Tk_SetClassProcs
	* generic/tk.decls
	* generic/tkInt.h
	* generic/tkWindow.c
	* generic/tkDecls.h:    (regenerated)
	* unix/tcl.m4           Sync with Tcl version
	* unix/configure        (regenerated)

2010-01-09  Pat Thoyts  <[email protected]>

	TIP #360 IMPLEMENTATION

	* doc/menu.n:           Remove special handling of the .help menu on
	* library/obsolete.tcl: X11.
	* unix/tkUnixMenu.c:

	* library/menu.tcl:	Make Tk menu activation follow mouse
	* library/obsolete.tcl: movements.

2010-01-08  Pat Thoyts  <[email protected]>

	* doc/photo.n: [Bug 2927569]: Multiple edits have peverted the
	original meaning of the phrase 'image file data' to reference
	a filename option that does not exist.

2010-01-07  Donal K. Fellows  <[email protected]>

	* generic/tkTextDisp.c (AsyncUpdateLineMetrics): [Bug 2677890]: Fix
	odd text widget update problem that had scrollbars being unable to
	cover the whole widget. Fix is to reify the range to update sooner.

2010-01-06  Donal K. Fellows  <[email protected]>

	* library/tk.tcl:		Centralize the definition of keys that
	* library/entry.tcl:		do common movement in entry and text
	* library/spinbox.tcl:		widgets. This is because they are
	* library/text.tcl:		subtlely different on the different
	* library/ttk/entry.tcl:	platforms. Lets Tk code work more
	* doc/event.n (PREDEFINED VIRTUAL EVENTS): correctly with platform
					conventions "out of the box".

	* generic/tkBind.c (HandleEventGenerate, DoWarp): [Bug 2926819]:
	* generic/tkInt.h (TkDisplay):			Factor out the pointer
	* generic/tkWindow.c (GetScreen):		warping code a bit
	* carbon/tkMacOSXMouseEvent.c (TkpWarpPointer): better and extend it
	* macosx/tkMacOSXMouseEvent.c (TkpWarpPointer): to work on OSX too.
	* unix/tkUnixEvent.c (TkpWarpPointer):
	* win/tkWinPointer.c (TkpWarpPointer):

	* unix/tkUnixWm.c (TkWmMapWindow): [Bug 1163496]: Allow windows to be
	* tests/wm.test (wm-transient-8.1): set to be transients for withdrawn
	masters correctly.

2010-01-05  Pat Thoyts  <[email protected]>

	* win/tkWinDialog.c: [Patch 2898255]: Enable unlimited multiple file
	selection from the open files dialog. (pawlak,fellows,thoyts)

2010-01-05  Donal K. Fellows  <[email protected]>

	* generic/tkMenu.c (MenuWidgetObjCmd): [Bug 220950]: Do not delete
	menu entries if the first index to delete is explicitly after the last
	index of existing entries.

	* generic/tkFont.h (ROUND16): [Bug 2824916]: Use a correct rounding
	* unix/tkUnixFont.c (TkpDrawAngledChars):    macro for converting a
	* unix/tkUnixRFont.c (TkpDrawAngledChars):   double to a short. This
	* win/tkWinFont.c (GetScreenFont):	     stops a number of small
	visual artefacts from happening and reduces the effect of others. The
	ROUND16 macro is now shared across all the font code (though some
	platforms do not need it specially).

2010-01-04  Pat Thoyts  <[email protected]>

	* doc/TkInitStubs.3: [Bug 2192104]: Mention USE_TK_STUBS macro.
	* library/dialog.tcl: [Bug 2811266]: <Return> binding should invoke
	the button with the focus.
	* library/fontchooser.tcl: [Bug 2727476]: Fix default size of font
	chooser dialog and assigned minimum sizes for the lists.
	* library/console.tcl: [Bug 580361]: Fix console <<Cut>> binding.
	* library/console.tcl: Fix keyboard access to console menu.
	* library/demos/filebox.tcl: Make prettier using ttk.
	* library/demos/fontchoose.tcl: Fix display of demo code.
	* library/tk.tcl: Correctly handle quoted ampersands in AmpMenuArgs

2010-01-03  Donal K. Fellows  <[email protected]>

	* unix/tcl.m4 (SC_CONFIG_CFLAGS): [Bug 1636685]: Use the configuration
	for modern FreeBSD suggested by the FreeBSD porter.

2010-01-03  Pat Thoyts  <[email protected]>

	* generic/tkMenu.h: [Patch 2848897]: Support the system keyboard
	* win/tkWinMenu.c:  cues option on Windows. This system parameter
	hides the underlines on menu items unless the keyboard is used to
	open the menu. (kovalenko, thoyts)

2010-01-03  Donal K. Fellows  <[email protected]>

	* generic/tkFont.c (Tk_TextLayoutToPostscript):	Simplified the code to
	* generic/tkCanvPs.c (TkCanvPostscriptCmd):	generate the preamble
	* library/mkpsenc.tcl:				for PS generation and
	also simplify the code to output text following the observation that
	it effectively only produces ASCII anyway, even when it might have the
	option to do otherwise in theory.

2010-01-03  Pat Thoyts  <[email protected]>

	* library/tearoff.tcl: Tearoff menus should be transient and use the
	                       toolwindow style on Windows.
	* tests/menu.test: Menu tests using 'tkwait visibility' are unix only.

2010-01-02  Donal K. Fellows  <[email protected]>

	* unix/tkUnixEvent.c (TransferXEventsToTcl): [Bug 1924761]: Use the
	new cache mechanism to force the extraction of the string of a key
	event from XIM at the right time rather than after queueing when it
	can be quashed by a race condition centered on the limited amount of
	state in some XIM implementations.

	* unix/tkUnixKey.c (TkpGetString): [Bug 1373712]: Cache the value that
	* generic/tkInt.h (TkKeyEvent):		will be substituted via %A so
	* generic/tkEvent.c (CleanUpTkEvent):	that we do not need to make it
	* doc/HandleEvent.3 (ARGUMENTS):	fresh each time, which causes
	* doc/QWinEvent.3 (ARGUMENTS):		trouble with some input
	* carbon/tkMacOSXKeyEvent.c (InitKeyEvent): methods. Also includes the
	* macosx/tkMacOSXKeyEvent.c (tkProcessKeyEvent): factoring out of some
	* win/tkWinX.c (GenerateXEvent):	code and update of
	documentation to describe the slightly increased constraints on
	how Tk_HandleEvent can be used.

2010-01-01  Donal K. Fellows  <[email protected]>

	* unix/tkUnixEvent.c (TransferXEventsToTcl): [Bug 1924761]: Move the
	* generic/tkEvent.c (Tk_HandleEvent):	     passing of key events to
	XFilterEvent to the low level point where all other events are
	handled, where it should have been all along. This makes more input
	methods work, stops [event generate] from interfering with input
	methods, and allows the simplification of tkEvent.c by removing half
	of InvokeInputMethods and allowing the rest - which was not full input
	method handling - to be rolled back into Tk_HandleEvent. Introduces a
	small potential bug when a focus change and input method handling are
	too close together in the Tk event queue, but that should be less
	deadly to usability than the previous problems where input methods
	could fail completely or reorder key presses...

2009-12-30  Pat Thoyts  <[email protected]>

	* generic/tkMenu.c: [Patch 2879789]: Torn off menu items are only
	* tests/menu.tcl:   activated over a limited region of the window.
	Fixed to make the whole width of a menu item activate the entry.

2009-12-27  Pat Thoyts  <[email protected]>

	* win/tkWinMenu.c: [Bug 2879927]: Highlight for cascade items in
	torn-off menus is incorrect on Windows.

2009-12-25  Joe English  <[email protected]>

	* library/ttk/utils.tcl, library/notebook.tcl: [Bugs 2917688,2546779]:
	Reworked ActivateTab focus selection logic.

2009-12-25  Donal K. Fellows  <[email protected]>

	* doc/option.n: [Bug 2914943]: Correct the first example.
	Also define what the format of option patterns is; that's a much less
	commonly known fact than it used to be.

2009-12-22  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:		Sync with current Tcl version.
	* unix/Makefile.in:	Use EXE_SUFFIX for Cygwin, and install
				libtk8.6.dll in bin directory.
	* unix/configure:	(regenerated)

2009-12-22  Joe English  <[email protected]>

	* library/ttk/sizegrip.tcl: [Bug 2912356]: Patch to avoid bizarro
	behavior under compiz.

2009-12-20  Donal K. Fellows  <[email protected]>

	* unix/tkUnixSend.c (ServerSecure): [Patch 2917663]: Better support
	for server-interpreted access control addreses.

2009-12-16  Jan Nijtmans  <[email protected]>

	* generic/tkListbox.c:	Fix gcc warning: ignoring return value of
				"strtol", declared with attribute
				warn_unused_result.
	* unix/tkUnixEvent.c:   Fix gcc warning: dereferencing pointer
				"xgePtr" does break strict-aliasing rules.
	* generic/tkInt.decls:  CONSTify return values of TkKeysymToString,
	* generic/tkBind.c      TkFindStateString, TkpGetString, TkpGetChar,
	* generic/tkIntDecls.h  which are all not supposed to be modified by
	* generic/tkUtil.c      the caller. In tkUtil.c this gets rid of a
	* carbon/tkMacOSXKeyboard.c   dangerous type cast.
	* macosx/tkMacOSXKeyboard.c
	* unix/tkUnixKey.c
	* win/tkWinKey.c

2009-12-15  Don Porter  <[email protected]>

	* generic/tkConfig.c:	Added another dimension of refCounting to the
	* generic/tkInt.c:	"option" Tcl_ObjType to improve memory troubles
	* generic/tkObj.c:	detailed in [Bug 2492179].  Also removed
	registration of the "option" Tcl_ObjType.
	*** POTENTIAL INCOMPATIBILITY *** for callers of
	Tcl_GetObjType("option") which must now handle a NULL return.

2009-12-15  Donal K. Fellows  <[email protected]>

	* library/demos/unicodeout.tcl (usePresentationFormsFor): Split out
	the code to decide whether to use presentation forms for clarity, and
	add some more languages (though only in natural uncomposed form for
	Devanagari script).

2009-12-14  Kevin B. Kenny  <[email protected]>

	* library/demos/unicodeout.tcl: Added code to check for right-to-left
	support on Windows and adjust Hebrew and Arabic character strings
	accordingly. Changed the Hebrew string to 'ktb ebryt' (ktav Ivrit,
	"Hebrew writing") to be consistent with at least the Greek and Russian
	strings. Thanks to Rodrigo Readi for calling the inconsistency to our
	attention.

2009-12-02  Jan Nijtmans  <[email protected]>

	* win/tkInt.decls: [Bugs 220600, 220690]: Comment that TkWinChildProc
	is exported through the stubs table since 8.5.9

2009-12-11  Jan Nijtmans  <[email protected]>

	* win/makefile.vc:	Fix dependancies on ${TKSTUBLIB} when
				TCL_USE_STATIC_PACKAGES is defined
	* generic/tkWindow.c:	Fix gcc warning, using gcc-4.3.4 on cygwin
				warning: array subscript has type 'char'

2009-12-11  Donal K. Fellows  <[email protected]>

	* library/tk.tcl (::tk::ScreenChanged): [Bug 2912473]: Stop problems
	caused by display names with a double colon in.

2009-12-10  Donal K. Fellows  <[email protected]>

	* library/demos/ttkscale.tcl: Added demo of [ttk::scale] widget.

2009-12-09  Donal K. Fellows  <[email protected]>

	* generic/tkColor.c (Tk_GetColorByValue): [Bug 2911570]: Ensure that
	hash keys of color values are zeroed first, so that they hash properly
	on 64-bit systems (where X structures are not tightly packed).

	* unix/tkUnixWm.c (TkpMakeMenuWindow):	Improve the determining of what
	* generic/tkMenu.c (ConfigureMenu):	EWMH hint to use so that we
	distinguish between dropdown menus (children of menubars) and what are
	presumably popup menus.

2009-12-08  Pat Thoyts  <[email protected]>

	* unix/tkUnixWm.c: [Bug 2864685]: Apply suitable extended window
	manager hints to the menus so that modern unix window managers can use
	the correct animation modes.

2009-12-02  Jan Nijtmans  <[email protected]>

	* win/configure:	(regenerated)
	* win/Makefile.in:	Use tktest86.dll for all tests.
	* win/tkWinInt.h:	Mark various functions MODULE_SCOPE
	* generic/tkInt.decls:	[Bugs 220600, 220690]: Make TkWinChildProc
				available in private stub table.
	* generic/tkIntPlatDecls.h: (regenerated)
	* generic/tkStubInit.c:	(regenerated)

2009-11-30  Jan Nijtmans  <[email protected]>

	* win/Makefile.in: Better dependancies in case of static build.
	Generate tktest86.dll and tktest86.lib.

2009-11-29  Jan Nijtmans  <[email protected]>

	* generic/tkInt.h:      Make all internal initialization
	* generic/tkTest.c:     routines MODULE_SCOPE
	* generic/tkOldTest.c:
	* generic/tkSquare.c:
	* carbon/tkMaxOSXTest.c:
	* macosx/tkMaxOSXTest.c:
	* win/tkWinTest.c:
	* win/tcl.m4:           (copied from Tcl 8.6)
	* win/configure:        (regenerated)

2009-11-25  Stuart Cassoff  <[email protected]>

	* unix/tcl.m4:		[Patch 2892871]: Remove unneeded
				AC_STRUCT_TIMEZONE.
	* unix/configure:	Regenerated with autoconf-2.59.

2009-11-24  Donal K. Fellows  <[email protected]>

	* unix/tkUnixWm.c (WmIconphotoCmd): [Bug 2902814]: Use the correct
	type for the array of data passed into X. It's wrong, but "right"
	because of a mistake in the X11 specification.

2009-11-23  Andreas Kupries  <[email protected]>

	* library/safetk.tcl (::safe::loadTk): [Bug 2902573]: Fixed access
	to the cleanupHook of the safe base. The code used the old
	internal commands which have been removed since 2009-11-05/06. See
	Tcl's ChangeLog.

2009-11-23  Donal K. Fellows  <[email protected]>

	* unix/Makefile.in: Added .PHONY lines to stop make from getting
	confused when someone makes an error in a rule.

2009-11-22  Pat Thoyts  <[email protected]>

	* tests/winWm.test: [Bug 2899949]: Make sure the window is still
	* win/tkWinWm.c:    present when handling delayed activation.

	* win/Makefile.vc: Include tk stubs in the tktest link

2009-11-21  Donal K. Fellows  <[email protected]>

	* generic/tkUtil.c: Remove some anachronistic techniques (pointless
	casts, mixed assignments and tests, etc.)

	* generic/tk3d.c, generic/tkBitmap.c, generic/tkColor.c:
	* generic/tkCursor.c, generic/tkFont.c, generic/tkTextIndex.c:
	[Tcl Bug 2857044]: Corrections following audit of Tcl_ObjType freeing
	practises; the typePtr field is now cleared when an object ceases to
	be of the type.

2009-11-19  Alexandre Ferrieux  <[email protected]>

	* generic/tkCanvas.c: [Bug 2899685]: Fix the redraw logic of [imove]

2009-11-19  Jan Nijtmans  <[email protected]>

	* doc/GetHINSTANCE.3:	Fix mentioned header file
	* generic/tkTest.c:	Compile with Stubs
	* generic/tkOldTest.c
	* generic/tkSquare.c
	* win/tcl.m4:		Should have been checked in together with the
				2009-08-09 check in of "win/configure"
	* win/tkWinTest.c:	Don't access tkWinProcs from Tk dll any more
	* unix/tcl.m4:		[Patch 2883533]: tcl.m4 support for Haiku OS
	* unix/configure	(regenerated)
	* unix/Makefile.in:	Fix library order in X11_LIB_SWITCHES

2009-11-19  Donal K. Fellows  <[email protected]>

	* generic/tkCanvLine.c (LineDeleteCoords): [Bug 2900121]: Get sense of
	test for drawing optimization correct.

2009-11-15  Donal K. Fellows  <[email protected]>

	* doc/ttk_treeview.n (detach): Added note that the 'move' operation
	restores detached nodes.

2009-11-12  Joe English  <[email protected]>

	* library/ttk/button.tcl, library/ttk/combobox.tcl,
	* library/ttk/notebook.tcl, library/ttk/treeview.tcl:
	[update] hygiene.

	+ Where possible, replace [a; update; b] with [a ; after 0 b].
	+ Where not possible, use [update idletasks] instead of full [update].
	+ Use [after 0] in favor of [after idle] for delayed work, to reduce
	likelihood of reentrancy issues in [update idletasks].

2009-11-11  Don Porter  <[email protected]>

	* generic/tkPlatDecls.h:	[Bug 2886635]: Restore C++
	friendliness to the tkPlatDecls.h header file, which we insist
	extensions #include to gain access to the Tk_*HWND*() routines.

2009-11-10  Andreas Kupries  <[email protected]>

	* unix/Makefile.in: Partially reverted Don Porter's 2009-10-20 commit.
	The OSX Cocoa code branch still needs tclInt.h and the internal
	headers, thus the TCL_PLATFORM directory. See tclMacOSXNotify.c for
	example.

2009-11-09  Donal K. Fellows  <[email protected]>

	* generic/tkFileFilter.c (TkFreeFileFilters): Simplify the code in
	this file by consolidating the deletion code together into a single
	function rather than scattering it over four.

2009-11-01  Joe Mistachkin  <[email protected]>

	* win/tkWinButton.c: [Bug 1739613]: The default width being stored
	in TSD cannot be put into the process-wide options table.  This fix
	allocates storage for the default width from the heap and frees it
	using an exit handler.

2009-11-01  Joe Mistachkin  <[email protected]>

	* doc/loadTk.n: Minor fix for htmlhelp target.

2009-11-01  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c, doc/ttk_widget.n: Uniform, extensible
	syntax for [$w identify] methods: [$w identify $component $x $y].  All
	ttk::* widgets support [$w identify element $x $y]; widgets with other
	identifiable parts may have additional subcommands.
	* generic/ttk/ttkNotebook.c, doc/ttk_notebook.n: Notebook widgets
	support [$nb identify tab].
	* generic/ttk/ttkPanedwindow.c, doc/ttk_panedwindow.n: Panedwindow
	widgets support [$w identify sash].  Older 2-argument form [$w
	identify $x $y] still supported, though it does different things
	depending on the widget.

2009-10-29  Pat Thoyts  <[email protected]>

	* win/tkWinFont.c: [Bug 1825353]: This patch reverts a previous
	attempt to fix tiny fonts on Russian Windows. It fixes the issue by
	requesting a suitable fixed font instead of decoding the system stock
	font.

2009-10-26  Don Porter  <[email protected]>

	* unix/Makefile.in:	Remove $(PACKAGE).* and prototype from the
	`make distclean` target.  Completes 2009-10-20 commit.

2009-10-25  Donal K. Fellows  <[email protected]>

	* unix/tkUnixColor.c (TkpGetColor): [Bug 2809525]: Impose a maximum
	X11 color name length so that it becomes impossible to blow things up
	that way.

	* library/text.tcl: [Bug 1854913]: Stop <Delete> actions from ever
	deleting backwards, even when the insertion cursor is "at the end" of
	the text widget.

2009-10-24  Donal K. Fellows  <[email protected]>

	* library/button.tcl, unix/tkUnixButton.c (TkpDisplayButton):
	[Patch 1530276]: Make -selectcolor handling work better for both
	checkbuttons and radiobuttons when they don't have indicators.

2009-10-22  Donal K. Fellows  <[email protected]>

	* generic/tkText.c (CreateWidget, TextEditUndo, TextEditRedo)
	(TextEditCmd, UpdateDirtyFlag):
	* generic/tkText.h: [Patch 1469210]: Corrected handling of marking as
	dirty when inserting after an undo from a non-dirty state.

	* win/tkWinDialog.c (GetFileNameA): Make the handling of the filter
	index the same as in GetFileNameW.

	* library/tkfbox.tcl (::tk::dialog::file::, Done):
	* library/xmfbox.tcl (MotifFDialog_FileTypes)
	(MotifFDialog_ActivateSEnt):
	* macosx/tkMacOSXDialog.c (Tk_GetOpenFileObjCmd):
	* win/tkWinDialog.c (GetFileNameW, GetFileNameA):
	* doc/getOpenFile.n: [Patch 2168768]: Corrected handling of the
	-typevariable option to be consistently global; it's the only way it
	can work even close to the same on all platforms.

	* macosx/ttkMacOSXTheme.c (RangeToFactor): [Bug 2883712]: Factor out
	some common code and make sure that it is 64-bit correct.

2009-10-21  Jan Nijtmans  <[email protected]>

	* win/Makefile.in:	[Bug 2875562]: Make sure that winMain.c and
	* win/winMain.c:	tkAppInit.c are never compiled with stubs.
	* unix/tkAppInit.c:

2009-10-20  Don Porter  <[email protected]>

	* unix/Makefile.in:	Compiling Tk no longer requires header files
	* win/Makefile.in:	from the TCL_PLATFORM DIR.  Baby step in
	pursuit of [Bug 1712098].  Also removed the long outdated and broken
	targets package-* that were for building Solaris packages.  Appears
	that the pieces needed for these targets to function have never been
	present in the current era of Tcl development and belong completely
	to Tcl pre-history.

2009-10-20  Andreas Kupries  <[email protected]>

	* library/msgs/pl.msg: Applied patch to Polish message catalog created
	and submitted by Pawel Pawlak <[email protected]> (via JeffH).

2009-10-18  Donal K. Fellows  <[email protected]>

	* doc/menu.n: Reorganized for readability, and added a note describing
	some subtleties of the -variable entry configuration option following
	some discussion with Joe Mistachkin.

2009-10-10  Donal K. Fellows  <[email protected]>

	* unix/tkUnixRFont.c (InitFont, TkpGetFontFromAttributes)
	(Tk_DrawChars, TkpDrawAngledChars): [Bug 1961455]: Draw underlines and
	overstrikes when using Xft for font rendering.

	* generic/tkFont.c (TkDrawAngledTextLayout): Optimize the zero-angle
	case better.

2009-10-08  Donal K. Fellows  <[email protected]>

	* library/iconlist.tcl (Create): [Patch 2870648]: Corrected cursor
	used in file/directory dialogs.

2009-10-07  Pat Thoyts  <[email protected]>

	* library/ttk/vistaTheme.tcl: [Bug 2787164]: Fix size of dropdown
	arrow on combobox and menubutton for Windows 7.

2009-10-07  Donal K. Fellows  <[email protected]>

	* unix/tkUnixScrlbr.c (TkpComputeScrollbarGeometry): [Patch 2088597]:
	Stop scrollbars from getting too small at the end.

2009-10-05  Pat Thoyts  <[email protected]>

	* win/tkWinButton.c: [Bug 2860827]: Avoid 3D effects with
	user-specified backgrounds. The default disabled text is embossed on
	Windows. But this looks poor when a non-default background color is in
	use. This patch disables the embossed effect for buttons and labels
	when the background is non- standard.

2009-09-30  Pat Thoyts  <[email protected]>

	* tests/winWm.test: [Bug 2799589]: Grab on deleted window.

2009-09-25  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgGetPhoto): Correct generation of grayscale
	data from an image. Reported by Keith Vetter on comp.lang.tcl.

2009-09-19  Peter Spjuth  <[email protected]>

	* generic/tkGrid.c:	[Bug 2859912]: Bug fix in grid/pack collision
	* generic/tkPack.c:	detect. Faulty slave was not properly blocked
	* tests/packgrid.test:	from slave list.

2009-09-14  Jeff Hobbs  <[email protected]>

	* generic/tkMenuDraw.c (TkPostSubmenu): [Bug 873613]: Fix reposting of
	* win/tkWinMenu.c (TkWinHandleMenuEvent): submenu in torn off Windows
	menu.
	(DrawMenuEntryArrow): [Bug 873608]: Draw Win menu arrow after being
	torn off.

2009-09-09  Donal K. Fellows  <[email protected]>

	* unix/tkUnixRFont.c (InitFont): Move pattern disposal in error case
	to callers so they have more options when they come to recovering from
	the failure.
	(TkpGetFontFromAttributes): If the default attributes don't work, try
	adding a setting to turn off use of XRender. That seems to work for
	some people for unexplained reasons (possibly local misconfiguration).
	* generic/tkFont.c (Tk_AllocFontFromObj): Stop this function from
	keeling over in a heap when the low-level font allocation fails. An
	error beats a crash! (Issue reported on comp.lang.tcl by Denis
	Berezhnoy.)

2009-09-07  Daniel Steffen  <[email protected]>

	* generic/tkFocus.c:	Fix potential null dereference flagged by clang
	* generic/tkMenu.c:	static analyzer.
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextIndex.c:

	* generic/tkConsole.c:	Silence false positives from clang static
	* generic/tkTest.c:	analyzer about potential null dereference.
	* generic/tkText.c:
	* generic/tkTextBTree.c:
	* generic/tkTextTag.c:
	* generic/tkVisual.c:

2009-09-04  Donal K. Fellows  <[email protected]>

	* generic/tkInt.h (TkDisplay): Remove fields that are never read from.
	* generic/tkWindow.c (Tk_DestroyWindow): Remove code to write to
	write-only fields of TkDisplay. This follows on from [Bug 2039720].

2009-08-25  Donal K. Fellows  <[email protected]>

	* unix/tkUnixSend.c (ServerSecure): [Bug 1909931]: Added some support
	for server-interpreted access control addreses.

2009-08-24  Donal K. Fellows  <[email protected]>

	* library/msgbox.tcl (::tk::MessageBox): Correct bindings so that they
	work with ttk::buttons. Reported by Hans-Christoph Steiner.

2009-08-24  Daniel Steffen  <[email protected]>

	* generic/tkInt.h: Annotate Tcl_Panic as noreturn for clang static
	analyzer in PURIFY builds, replacing preprocessor/assert technique.

	* generic/tkBind.c (HandleEventGenerate): Don't generate events for
	windows that don't exist yet (fixes TkAqua testsuite crash).

	* macosx/tkMacOSXWindowEvent.c: [Bug 2821084]: Allow WM_DELETE_WINDOW
	handlers to prevent window closure by generating WM destroy event
	earlier (from window delegate's -windowShouldClose:).

	* macosx/tkMacOSXDraw.c (TkMacOSX{Setup,Restore}DrawingContext):
	Disable window flushing during Tk drawing to avoid immediate flush of
	NSView-based native widgets on draw. (fixes drawing performance issue
	reported by Youness Alaoui on tcl-mac)

	* macosx/tkMacOSXHLEvents.c (ScriptHandler):	Fix "do script" apple
	* carbon/tkMacOSXHLEvents.c (ScriptHandler):	event handler issues
	on recent OS X releases by using AE coercion to 'utf8' for text data
	and to 'fsrf' for alias data. (reported by Youness Alaoui on tcl-mac)

	* macosx/Wish.sdef (new file):		Install and enable sdef file
	* macosx/Wish-Info.plist.in:		into Wish application bundle,
	* macosx/Tk.xcode/project.pbxproj:	describing TkAqua apple event
	* macosx/Tk.xcodeproj/project.pbxproj:	support for use by AppleScript.
	* unix/Makefile.in:			(replaces functionality of
	* unix/configure.in:			'aete' resource removed with
						Cocoa port & fixes AppleScript
						issues reported on tcl-mac)
	* unix/configure: autoconf-2.59

	* carbon/Wish.xcode/project.pbxproj:	Remove references to obsolete
	* carbon/Wish.xcodeproj/project.pbxproj: prolog.ps file.

2009-08-19  Peter Spjuth  <[email protected]>

	* generic/tk.h
	* generic/tkGeometry.c
	* generic/tkGrid.c
	* generic/tkInt.h
	* generic/tkPack.c
	* generic/tkWindow.c
	* tests/grid.test
	* tests/packgrid.test
	* tests/textIndex.test:	[Patch 2475855]: Give an error if grid and
	pack are used in the same master.

2009-08-14  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c: Avoid exception in XCopyArea() when copying
	from toplevel that has never been mapped. (Reported by Youness Alaoui
	on tcl-mac)

	* macosx/tkMacOSXWm.c: Workaround for textured windows being draggable
	from opaque content areas. [Bug 2824538] (walzer)

2009-08-10  Jan Nijtmans  <[email protected]>

	* win/tkWinPixmap.c: Eliminate more gcc warnings
	* win/tkWinWm.c:
	* win/tkWinTest.c

2009-08-09  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkInit.c: Eliminate gcc warning
	* generic/tkBind.c
	* generic/tkText.c
	* generic/tkUtil.c
	* win/ttkWinXPTheme.c:	Include <vssym32.h> only when available
	* win/configure.in:	check for vssym32.h, available in newer SDK's
	* win/configure:	(regenerated)

2009-08-08  Donal K. Fellows  <[email protected]>

	* library/demos/pendulum.tcl: Make the display handle being resized
	more gracefully.

2009-08-04  Donal K. Fellows  <[email protected]>

	* generic/tkTextDisp.c (TkTextCharLayoutProc): Make the line breaking
	algorithm (in the word-wrap case) do the right thing with non-breaking
	spaces by restricting what we break on to ASCII spaces, which is good
	enough for most purposes.

2009-08-02  Jan Nijtmans  <[email protected]>

	* win/tkWinClipboard.c Correct check for winNT
	* win/tkWinDialog.c    Eliminate many gcc warnings
	* win/tkWinImage.c:
	* win/tkWinMenu.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
	* win/ttkWinXPTheme.c: Eliminate msvc warnings
	* win/tcl.m4:
	* win/configure
	* win/.cvsignore:      Prevent files from being checked in by accident

2009-08-01  Donal K. Fellows  <[email protected]>

	* unix/tkUnixWm.c (WmIconphotoCmd): [Bug 2830420]: Assemble the image
	for the window manager in a way that doesn't assume we're on a little-
	endian system.

2009-07-27  Donal K. Fellows  <[email protected]>

	* doc/GetScroll.3: Reworded and reordered so as to indicate that the
	Tcl_Obj forms are preferred.

2009-07-26  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: Corrected description of acceptable join styles.
	Spotted by Emiliano Gavilán.

2009-07-23  Donal K. Fellows  <[email protected]>

	* generic/tkSelect.c (HandleTclCommand): [Bug 2441988]: Stop losing
	reports of errors in selection handlers; that's what the background
	error handling code is for.
	*** POTENTIAL INCOMPATIBILITY *** if your code was relying on erroring
	selection scripts being silent.
	(LostSelection, Tk_SelectionObjCmd): Stop using the vastly inefficient
	TkCopyAndGlobalEval; better to use Tcl_Obj refcount management.

2009-07-22  Donal K. Fellows  <[email protected]>

	* generic/tkFocus.c (TkFocusDeadWindow): [Bug 2496114]: Ensure that
	focus desynchronization doesn't cause a crash.

2009-07-21  Donal K. Fellows  <[email protected]>

	* generic/tkFont.c (TkUnderlineAngledTextLayout): [Bug 2356057]:
	Corrected drawing of rotated underlines.

2009-07-21  Alexandre Ferrieux  <[email protected]>

	* generic/tkFont.c: [Bug 2328657]: Explicitly exclude hacky zero-char
	chunks from intersection computation. Might deserve generalization to
	other tests.

2009-07-20  Donal K. Fellows  <[email protected]>

	* tests/clipboard.test (clipboard-6.2): [Bug 2824378]: Corrected
	result of test in light of changes to binary selection retrieval.

2009-07-18  Donal K. Fellows  <[email protected]>

	* unix/tkUnixSelect.c (SelCvtFromX32, SelCvtFromX8): Make the
	incremental transfer of binary selections work get deserialized
	correctly. Thanks to Emiliano Gavilán for detecting.

2009-07-18  Daniel Steffen  <[email protected]>

	* unix/Makefile.in:		Define NDEBUG in optimized (non-
					symbols) build to disable assert()s.

	* macosx/tkMacOSXBitmap.c:	[Bug 2821318]: Fix tk::mac::iconBitmap
					crash due to off-by-one ckalloc error.

2009-07-15  Daniel Steffen  <[email protected]>

	* macosx/ttkMacOSXTheme.c:	[Patch 2819620]: Update notebook tab
	* library/ttk/aquaTheme.tcl:	appearance to modern L&F; adjust tab &
					notebook padding and tabmargins;
					correct appearance of selected tree
					header; add support for native tree
					header sort arrows via user1 state.

	* library/demos/mclist.tcl:	Use native sort arrows with aqua theme

2009-07-15  Donal K. Fellows  <[email protected]>

	* unix/tkUnixSelect.c (TkSelEventProc, SelRcvIncrProc, SelCvtFromX8):
	[Bug 2821962]: Make byte sequence selection transfers possible.

2009-07-14  Donal K. Fellows  <[email protected]>

	* doc/canvas.n (WINDOW ITEMS): [Bug 2326602]: Corrected definition of
	the -height and -width options for these items.

	* unix/configure.in: [Bug 2496018]: Allow the disabling of the use of
	XScreenSaver at configuration time, so as to permit better control of
	dependencies in the embedded case.

2009-07-11  Donal K. Fellows  <[email protected]>

	* doc/grid.n: [Bug 2818455]: Corrected example.

2009-07-02  Pat Thoyts  <[email protected]>

	* generic/tkInt.h: Avoid using C++ reserved word in header.

2009-06-30  Daniel Steffen  <[email protected]>

	* generic/tkInt.h:		Add assert macros for clang static
					analyzer and redefine Tcl_Panic to
					assert after panic in clang PURIFY
					builds.

	* generic/tkImgPhInstance.c:	Small fixes to make clang static
	* generic/tkTextDisp.c:		analyzer happier.

	* generic/tkConfig.c:		Add clang assert for false positives
	* generic/tkUndo.c:		from static analyzer.

2009-06-29  Daniel Steffen  <[email protected]>

	Merge of TkAqua Cocoa port <http://github.com/das/tcltk/tree/de-carbon>
	*** POTENTIAL INCOMPATIBILITY ***

	* macosx/tkMacOSX.h:		Large-scale rewrite of TkAqua migrating
	* macosx/tkMacOSXBitmap.c:	all use of deprecated Carbon API to
	* macosx/tkMacOSXButton.c:	Cocoa API; now supports 64bit
	* macosx/tkMacOSXClipboard.c:	architecture and requires Mac OS X 10.5
	* macosx/tkMacOSXColor.c:	or later; with TkAqua enabled, all Tk
	* macosx/tkMacOSXConfig.c:	sources are now built with the
	* macosx/tkMacOSXCursor.c:	Objective-C compiler and running in
	* macosx/tkMacOSXDebug.c:	Objective-C garbage collection mode as
	* macosx/tkMacOSXDebug.h:	well as in retain-release mode is
	* macosx/tkMacOSXDefault.h:	supported; detailed development history
	* macosx/tkMacOSXDialog.c:	is available in github repository.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:	There should be no script-visible
	* macosx/tkMacOSXEntry.c:	changes to existing Tk functionality,
	* macosx/tkMacOSXEvent.c:	but there are a few aqua-specific
	* macosx/tkMacOSXEvent.h:	additions, see macosx/README for
	* macosx/tkMacOSXFont.c:	details; extensions using only public
	* macosx/tkMacOSXFont.h:	Tk API should continue to work
	* macosx/tkMacOSXHLEvents.c:	unchanged but extensions that rely on
	* macosx/tkMacOSXInit.c:	platform-specific internal Tk API or
	* macosx/tkMacOSXInt.h:		make assumptions about the inner
	* macosx/tkMacOSXKeyEvent.c:	workings of TkAqua (in particular
	* macosx/tkMacOSXKeyboard.c:	presence of QuickDraw) will require
	* macosx/tkMacOSXMenu.c:	porting.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:	Configure Tk with --enable-aqua=carbon
	* macosx/tkMacOSXMouseEvent.c:	to fallback to now-deprecated previous
	* macosx/tkMacOSXNotify.c:	TkAqua implementation in tk/carbon.
	* macosx/tkMacOSXPort.h:
	* macosx/tkMacOSXPrivate.h:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:
	* macosx/ttkMacOSXTheme.c:
	* macosx/tkMacOSXCarbonEvents.c (removed):

	* macosx/tkMacOSXCursors.h (new):	Move cursor data from resources
	* macosx/tkMacOSXXCursors.h (new):	to compiled-in const array;
	* macosx/tkMacOSXCursors.r (removed):	remove obsolete Rez source
	* macosx/tkMacOSXXCursors.r (removed):	files for resource data.
	* macosx/tkAboutDlg.r (removed):
	* macosx/tkMacOSXAETE.r (removed):

	* macosx/Tk.tiff (new):		Rename and update icon to blue feather;
	* macosx/Tk.icns (new):		add tiff version for about dialog.
	* macosx/Wish.icns (removed):

	* macosx/Tk-Info.plist.in:	Update copyright; adjust minimum system
	* macosx/Wish-Info.plist.in:	version requirement.
	* generic/tkEntry.h:

	* license.terms:		Sync list of entities with those in the
					tcl license.terms, add Apple Inc.

	* generic/tk.h:			Update comment with list of source
					files containing tk version numbers.

	* generic/tkButton.c:		On aqua, recompute button geometry on
					secondary image change to enable cache
					of native img format in geom compute.

	* generic/tkGrab.c:		On aqua, make all grabs global, the
					Mac OS X windowserver forces all grabs
					to be application-local only anyway.

	* generic/tkSelect.c:		Enable utf8 atom on aqua.

	* generic/tk.decls:		Replace carbon types in public and
	* generic/tkInt.decls:		internal platform stubs interfaces with
					void* resp. generic Tk types.

	* xlib/xgc.c:			Add support for managing a platform-
					specific cache appended to a GC.

	* tests/dialog.test:		Change name of undefined bit to avoid
					match with OSType native bitmap name.

	* doc/cursors.n:		Update list of cursors mapped to native
					cursors and add new native cursors.

	* doc/menu.n:			Add documentation of new aqua-specific
					.window menu, document new constraints
					on .apple menu.

	* library/console.tcl:		Add aqua window and help menus.

	* unix/Makefile.in:		Add support for TkAqua-implementation-
					specific sources determined at
					configure-time. Update dist target for
					new/removed files.

	* unix/configure.in:		Add libraries & compiler flags for
					Cocoa and Objective-C; update build
					support for new/removed files; add
					support for configure-time choice of
					TkAqua implementation.

	* macosx/Tk-Common.xcconfig (new):	Rename Xcode projects and
	* macosx/Tk-Debug.xcconfig (new):	related files; update for Xcode
	* macosx/Tk-Release.xcconfig (new):	3.1 and 3.2; update for Cocoa,
	* macosx/Tk.xcode/* (new):		Objective-C & GC; update with
	* macosx/Tk.xcodeproj/* (new):		new/removed source files;
	* macosx/Wish.xcode/* (removed):	standardize on gcc 4.2; remove
	* macosx/Wish.xcodeproj/* (removed):	obsolete configurations and
	* macosx/Wish-Debug.xcconfig (removed):	pre-Xcode project.
	* macosx/Wish-Common.xcconfig (removed):
	* macosx/Wish-Release.xcconfig (removed):
	* macosx/Wish.pbproj/* (removed):

	* macosx/README:		Document new Cocoa-port features and
					constraints; update project docs;
					cleanup.

	* carbon/tkMacOSXInt.h:		Add dummy defines for empty GC cache.

	* carbon/tkMacOSXColor.c:	Update for type changes in platform
	* carbon/tkMacOSXDraw.c:	stubs interfaces.
	* carbon/tkMacOSXHLEvents.c:
	* carbon/tkMacOSXMouseEvent.c:
	* carbon/tkMacOSXSubwindows.c:
	* carbon/tkMacOSXWm.c:

	* carbon/tkMacOSXButton.c:	Fix warning.

	* generic/tkPlatDecls.h:	regen.
	* generic/tkIntPlatDecls.h:
	* unix/configure:		autoconf-2.59

2009-06-27  Jan Nijtmans  <[email protected]>

	* generic/tkInt.decls (added TkSmooth(Parse|Print)Proc,
	removed TkTile(Parse|Print)Proc which don't exist):
	Follow-up to [Bug 2804935]: Expose these functions through the
	internal stub table as they are useful to existing third-party code.

2009-06-26  Daniel Steffen  <[email protected]>

	* carbon/ (new directory):	Copy of current state of 'macosx'
	source directory, to preserve legacy TkAqua implementation based on
	Carbon API (with support for Mac OS X releases older than 10.5).

	* unix/Makefile.in:		Add support for --enable-aqua=carbon
	* unix/configure.in:		configure option (legacy fallback for
					pre-Mac OS X 10.5 releases).

	* unix/configure:		autoconf-2.59

2009-06-22  Jan Nijtmans  <[email protected]>

	* generic/tkCanvUtil.c: [Bug 220935]: canvas dash update problem

2009-06-12  Donal K. Fellows  <[email protected]>

	* generic/tkInt.decls (TkOrientParseProc, TkOrientPrintProc):
	[Bug 2804935]: Expose these functions through the internal stub table
	as they are useful to existing third-party code.

2009-06-02  Pat Thoyts  <[email protected]>

	* win/tkWinWm.c:    [Bug 2799589]: Avoid setting the focus on a
	* tests/winWm.test: deleted window during delayed activation.

2009-05-21  Pat Thoyts  <[email protected]>

	* win/tkWinMenu.c: [Bug 2794778]: Calls to CallWindowProc can lead to
	other functions overwriting the event strucure. Therefore preserve a
	local copy of the XKeyEvent while looping over the key events.

2009-05-17  Joe English  <[email protected]>

	* generic/ttkNotebook.c: [Bug 1470246]: More flexible tab placement.

2009-05-14  Pat Thoyts  <[email protected]>

	* generic/tkButton.c: [Bug 1923684]: If a checkbutton offvalue is the
	same as the tristate value we should use the off state in
	preference. (andrey gusev)

2009-05-13  Pat Thoyts  <[email protected]>

	* win/tkWinSend.c: FormatMessage should always use the ignore-inserts
	* win/tkWinTest.c: flag when processing system errors.

	* generic/tkFont.c: [Bug 2791352]: Handle parsing of type 5 font
	* tests/font.test: descriptions with hyphenated family name.

2009-05-06  Pat Thoyts  <[email protected]>

	* library/images/lamp.svg: Added an SVG version of the Tk lamp and
	* library/images/lamp.png: a pre-rendered PNG version.
	* win/rc/wish.ico: Wish gets a new icon using the SVG lamp and the tk
	* win/rc/tk.ico:   dll gets the tcl rendered feather. This provides
	improved icons for Vista/Windows 7.

2009-05-05  Donal K. Fellows  <[email protected]>

	* doc/MainWin.3 (Tk_GetNumMainWindows): [Bug 487220]: Clarified that
	this function works per-thread, not per-process.

	* doc/canvas.n (scale): [Bug 1832015]: Clarified that [$c scale] only
	affects item coordinates.

2009-05-04  Donal K. Fellows  <[email protected]>

	* doc/3DBorder.3, doc/BindTable.3, doc/CanvPsY.3, doc/Clipboard.3:
	* doc/ConfigWidg.3, doc/CrtWindow.3, doc/GetBitmap.3:
	* doc/GetCapStyl.3, doc/GetImage.3, doc/GetJoinStl.3, doc/GetScroll.3:
	* doc/GetSelect.3, doc/GetVisual.3, doc/MainWin.3, doc/Name.3:
	* doc/ParseArgv.3, doc/TextLayout.3, doc/Tk_Init.3: [Bug 2431507]:
	Purge all mention of the now-obsolete 'interp->result'.

2009-05-03  Donal K. Fellows  <[email protected]>

	* win/tkWinWm.c (UpdateWrapper): [Bug 2785744]: Manipulate flag bit
	correctly so that menubar updates can't smash other attributes.

2009-05-01  Donal K. Fellows  <[email protected]>

	* library/mkpsenc.tcl (DrawText): [Bug 2777019]: Corrected point of
	application of rotation transform so rotation is about the anchor
	point of the text.

	* generic/tkCanvPs.c (Tk_PostscriptPhoto):
	* library/mkpsenc.tcl: Factor out the postscript code for converting
	images into postscript so that the code bits are in the prolog and not
	emitted at runtime if a non-thread-safe static says to...

2009-04-30  Pat Thoyts  <[email protected]>

	* win/tkWinWm.c: [Patch 2504402]: Create icon bitmaps as device
	independent bitmaps. This ensures the icon can be drawn properly on
	various colour depth surfaces - in particular it fixes a problem with
	remote desktop and looks better in the vista task switching overlay.
	(cjmcdonald)

2009-04-30  Donal K. Fellows  <[email protected]>

	* win/tkWinPixmap.c (Tk_GetPixmap): [Bug 2080533]: Added patch that
	allows Tk to keep working even when the graphics card is stressed.

2009-04-28  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4, unix/configure (SC_CONFIG_CFLAGS): Harden the check
	to add _r to CC on AIX with threads.

2009-04-27  Donal K. Fellows  <[email protected]>

	* generic/tkInt.decls: [Bug 2768945]: Expose (as "private") a set of
	functions needed for easily building canvas items that work like
	existing standard ones.

2009-04-24  Jeff Hobbs  <[email protected]>

	* win/tkWinDialog.c (ChooseDirectoryValidateProc): No need to set cwd
	on selchange. Prevents delete of selected folder in dialog.

2009-04-24  Stuart Cassoff <[email protected]>

	* unix/Makefile.in: Assorted issues:
	[Bug 2764263]: Removed stray @ from Makefile.in test target.
	[Bug 1945073]: Don't chmod+x square demo.
	[Patch 2764272]: Adjustable demo install location.

2009-04-24  Stuart Cassoff <[email protected]>

	* unix/Makefile.in: [Patch 2769530]: Don't chmod/exec installManPage.

2009-04-23  Jeff Hobbs  <[email protected]>

	* win/tkWinDialog.c (Tk_ChooseDirectoryObjCmd): [Bug 2779910]: Enable
	the new style choosedir that has a "New Folder" button, with
	::tk::winChooseDirFlags override for new behavior.

2009-04-14  Donal K. Fellows  <[email protected]>

	* library/xmfbox.tcl (MotifFDialog_ActivateSEnt): Ensure that the
	* library/tkfbox.tcl (Done):			  dialogs have the
	correct levels for [upvar] for accessing the -typevariable var.

2009-04-13  Donal K. Fellows  <[email protected]>

	* library/tk.tcl: Corrected another problem; can't determine the exact
	type of OS - needed for figuring out how to guess the correct binding
	in some circumstances - in a safe interpreter.

	* library/tkfbox.tcl: [Bug 2759119]: Corrected level handling for the
	* library/xmfbox.tcl: -typevariable option following updates to tk.tcl
	[Patch 2739360]: Use more modern images from Tango set for the non-
	Motif file dialog. Thanks to Emiliano for bring this to my attention.

2008-04-10  Joe English  <[email protected]

	* library/palette.tcl (tk_setPalette): Don't set *selectColor:
	#b03060; this makes radio- and checkbuttons look wrong post-TIP#109.

2009-04-10  Daniel Steffen  <[email protected]>

	* unix/configure.in (Darwin):	Use Darwin SUSv3 extensions if
					available.
	* unix/configure:		autoconf-2.59
	* unix/tkConfig.h.in:		autoheader-2.59

	* library/demos/filebox.tcl: Only show "Motif Style Dialog"
	checkbutton on X11 windowingsystem.

	* library/demos/widget: GOOBE: use ttk::cursor

	* library/demos/knightstour.tcl: Fix knightstour demo not running from
	interactive wish.

	* library/console.tcl (::tk::ConsoleInit): Remove redundant TkAqua
	Quit menu item.

	* generic/tkPointer.c (Tk_UpdatePointer): Use all 5 buttons.

	* generic/tkMenu.c (PostProcessEntry): Delay call to
	TkpConfigureMenuEntry() until all menu entry attributes are setup.

	* library/menu.tcl (::tk::MbPost): Fix error thrown in y position
	computation with indicatoron.

	* generic/tkMenubutton.c: s/DEF_BUTTON_JUSTIFY/DEF_MENUBUTTON_JUSTIFY/

	* generic/tkUtil.c (TkBackgroundEvalObjv): Use Tcl_BackgroundException

	* generic/tkTextBTree.c (TkBTreeDeleteIndexRange): Add bounds check
	to startEnd array access (fixes testsuite crash).

	* tests/unixFont.test: Only use xlsfonts with X11 windowingsystem.

2009-04-10  Donal K. Fellows  <[email protected]>

	* library/tk.tcl: [Bug 2116837]: Add event definitions to handle the
	standard virtual events when Caps Lock is on.

2009-04-08  Donal K. Fellows  <[email protected]>

	* library/demos/widget (addFormattedText): Stop marking demonstrations
	as new for 8.6; that label is for wholly new demos.

2009-04-04  Donal K. Fellows  <[email protected]>

	* doc/messageBox.n: [Bug 1881896]: Reworded to be clearer on what the
	platform restrictions really are.

2009-04-03  Joe English  <[email protected]>

	* unix/tkUnixWm.c: [Bug 1789819]: Don't panic when the window manager
	does something unexpected with the stacking order.

2009-04-03  Donal K. Fellows  <[email protected]>

	* doc/TextLayout.3: [Bug 974421]: Clarified description of how result
	of lookup of a point after end of layout relates to the underlying
	string's length.

2009-04-02  Pat Thoyts  <[email protected]>

	* tests/textTag.test: Ensure the pointer begins outside the window for
	all the tests checking Enter/Leave motion events.

	* library/demos/pendulum.tcl: Use unicode labels
	* library/demos/knightstour.tcl: Use polygon knight on x11.

2009-03-31  Donal K. Fellows  <[email protected]>

	* library/demos/mclist.tcl: Added support for arrow indicators to show
	which way a column is being sorted. Corrected determination of which
	fonts to use for measurements.

2009-03-25  Jan Nijtmans  <[email protected]>

	* doc/wish.1:		Bring doc and demos in line with
	* library/demos/hello:	http://wiki.tcl.tk/812
	* library/demos/rmt
	* library/demos/square
	* library/demos/tcolor
	* library/demos/timer
	* library/demos/widget
	* win/tkWinMenu.c:	Eliminate a few compiler warnings on mingw
	* win/ttkWinXPTheme.c:	Spacing

2009-03-25  Donal K. Fellows  <[email protected]>

	* generic/ttk/ttkTheme.c (BuildOptionMap, NewElementClass):
	[Bug 2178820]: Ensure that zero-size allocations don't happen; some
	malloc implementations don't like it at all.

	* win/wish.exe.manifest.in: [Bug 1871101]: Add magic to make Tk not be
	blurred on Vista with large fonts.

2009-03-14  Donal K. Fellows  <[email protected]>

	* unix/tk.pc.in (new file):		[Patch 2243962] (hat0)
	* unix/configure.in, unix/Makefile.in: Added support for reporting
	Tk's public build configuration via the pkg-config system. TEA is
	still the official mechanism though, in part because pkg-config is not
	universally supported across all Tk's supported platforms.

2009-03-10  Donal K. Fellows  <[email protected]>

	* doc/event.n: Tidy up and improve examples.

2009-03-09  Benjamin Riefenstahl  <[email protected]>

	* tkMacOSXFont.c (GetFontFamilyName): [Bug 2548661]: Handle NULL
	return from CFStringCreate.

2009-02-27  Jan Nijtmans  <[email protected]>

	* doc/GetBitmap.3:    [FRQ 2636558]: Tk_DefineBitmap and
	* generic/tk.decls:   Tk_GetBitmapFromData signature problem
	* generic/tkInt.decls:
	* generic/tkBitmap.c:
	* generic/tkInt.h:
	* generic/tkStubInit.c:
	* generic/tkDecls.h:    (regenerated)
	* generic/tkIntDecls.h: (regenerated)
	* macosx/tkMacOSXBitmap.c:

2009-02-27  Pat Thoyts  <[email protected]>

	* generic/tkWindow.c: [Bug 2645457]: Check for dead windows after
	calling Tk_MakeWindowExist to avoid a crash when mapping dead windows.

2009-02-23  Pat Thoyts  <[email protected]>

	* win/rc/*.cur: [Patch 2513104]: Fix cursor hotspots (cjmcdonald)

	* win/tkWinMenu.c: Applied patch for menu image display bug.
	[Bug 1329198, 456299] [Patch 2507419] (cjmcdonald)

2009-02-22  Pat Thoyts  <[email protected]>

	* win/tkWinCursor.c: Applied patch to support stock Win32 help arrow
	cursor when question_arrow requested [Patch 2542828] (danckaert)

2009-02-21  Pat Thoyts  <[email protected]>

	* library/ttk/vistaTheme.tcl: Correct the ttk::treeview border on
	* win/ttkWinXpTheme.c:        XP and vista.

	* library/console.tcl: [Bug 2546087]: In 2004 a fix to Tcl channels
	prevented the exposure of the internal UTF-8 representation of the
	ASCII NUL character (\uc080). Since then strings in the console have
	been truncated at NUL. This restores the older behaviour.

2009-02-17  Jeff Hobbs  <[email protected]>

	* win/tcl.m4, win/configure: Check if cl groks _WIN64 already to avoid
	CC manipulation that can screw up later configure checks. Use 'd'ebug
	runtime in 64-bit builds.

2009-02-16  Jeff Hobbs  <[email protected]>

	* win/configure.in, win/configure: Align better with tcl version.
	Ensures finding correct CPP for Win64.

2009-02-16  Donal K. Fellows  <[email protected]>

	* doc/ttk_intro.n: [Bug 2604420]: Improve wording so that this page
	feels less obviously incomplete.

2009-02-12  Donal K. Fellows  <[email protected]>

	* library/iconlist.tcl: Split out the IconList megawidget from
	tkfbox.tcl into its own file so as to make it easier to maintain. Also
	cleans up the API for the megawidget, making it more like a
	conventional Tk widget.

2009-02-11  Donal K. Fellows  <[email protected]>

	* library/demos/items.tcl, .../label.tcl, .../twind.tcl:
	* library/demos/images/ouster.png: [Bug 2588919]: Demo GOOBE. Added
	new image of John Ousterhout that does not look quite so massively out
	of date, and also showed off a bit of how we can adjust PNG images
	when loading them. Also labeled JO as the creator; it's the TCT who
	are the proprietors now.

2009-02-10  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4: [Bug 2502365]: Building of head on HPUX was broken when
	using the native CC.
	* unix/configure (autoconf-2.59)

2009-02-08  Joe English  <[email protected]>

	* generic/ttk/*.[ch]: Renamed several internal data structures and
	functions: ElementImpl -> ElementClass, LayoutNode -> Element. Remove
	more unnecessary casts. Add function Ttk_ClientRegion, common factor
	of entry, scale, progress, and treeview widgets.
	* generic/ttk/ttkTrack.c: Fix [Bug 2431428].

2009-02-06  Daniel Steffen  <[email protected]>

	* generic/tkImgPhInstance.c:	Fix numerous leaks discovered with the
	* generic/tkMenu.c:		Mac OS X Instruments.app Leaks tool.
	* generic/tkText.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkUndo.c:
	* generic/tkUtil.c:
	* generic/ttk/ttkFrame.c:
	* macosx/tkMacOSXWm.c:

2009-01-29  Jan Nijtmans  <[email protected]>

	* generic/tkCanvArc.c   - eliminate some unnessary type casts
	* generic/tkCanvBmap.c  - some internal const decorations
	* generic/tkCanvImg.c   - spacing
	* generic/tkCanvWind.c
	* generic/tkCmds.c
	* generic/tkConfig.c
	* generic/tkEntry.c
	* generic/tkFocus.c
	* generic/tkFont.c
	* generic/tkFrame.c
	* generic/tkGrab.c
	* generic/tkGrid.c
	* generic/tkImage.c
	* generic/tkListbox.c
	* generic/tkObj.c
	* generic/tkOption.c
	* generic/tkPack.c
	* generic/tkPanedWindow.c
	* generic/tkRectOval.c
	* generic/tkSelect.c
	* generic/tkText.c
	* generic/tkTextMark.c
	* generic/tkTextTag.c

2009-01-28  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkCache.c:  - eliminate some unnessary type casts
	* generic/ttk/ttkLayout.c  - some internal const decorations
	* generic/ttk/ttkState.c   - spacing
	* generic/ttk/ttkTheme.c
	* macosx/tkMacOSXMenu.c
	* macosx/tkMacOSXPrivate.h
	* unix/tkUnixFont.c
	* unix/tkUnixMenu.c
	* unix/tkUnixWm.c
	* win/tkWinColor.c
	* win/tkWinDialog.c
	* win/tkWinFont.c
	* win/tkWinMenu.c
	* win/tkWinSend.c
	* win/tkWinWindow.c
	* win/tkWinWM.c

2009-01-22  Kevin B. Kenny  <[email protected]>

	* unix/tcl.m4: Corrected a typo ($(SHLIB_VERSION) should be
	${SHLIB_VERSION}).
	* unix/configure: Autoconf 2.59

2009-01-19  Kevin B. Kenny  <[email protected]>

	* unix/Makefile.in: Added a CONFIG_INSTALL_DIR parameter so that
	* unix/tcl.m4:      distributors can control where tclConfig.sh goes.
	Made the installation of 'ldAix' conditional upon actually being on an
	AIX system. Allowed for downstream packagers to customize
	SHLIB_VERSION on BSD-derived systems.
	Thanks to Stuart Cassoff for [Patch 907924].
	* unix/configure: Autoconf 2.59

2009-01-16  Don Porter  <[email protected]>

	* generic/tk.h:		Bump patchlevel to 8.6b1.1 to distinguish
	* library/tk.tcl:	CVS snapshots from the 8.6b1 and 8.6b2
	* unix/configure.in:	releases.
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2009-01-14  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c: [Bug 2507326]: Fix for aMSN compatibility
	* generic/tkMenu.h: CONSTify Tk(Create|Find)MenuReferences
	* generic/tkMenu.c: various internal "const" decorations.

2009-01-13  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4: [Bug 2502365]: Building of head on HPUX was broken when
	using the native CC
	* unix/configure (autoconf-2.59)

2009-01-13  Pat Thoyts  <[email protected]>

	* tests/constraints.tcl: Made the tests more independent of the
	* tests/*.test:          presence of images in the interpreter.

2009-01-11  Pat Thoyts  <[email protected]>

	* tests/bind.test: Fixed keysym bind tests for unix [Bug 2336454]

2009-01-11  George Peter Staplin <[email protected]>

	* generic/tkEvent.c: Fix a possible segv due to a NULL pointer
	dereference that occurs when XCreateIC fails.

2009-01-11  Pat Thoyts  <[email protected]>

	* library/bgerror.tcl: Pretty up the unix tk_messageBox icons with PNG
	* library/icons.tcl:   images and grouped all the stock icons in one
	* library/msgbox.tcl:  file.
	* library/tk.tcl:

2009-01-11  Joe English  <[email protected]>

	* generic/ttk/ttkNotebook.c (NotebookCleanup): [Bug 2496162]: Don't
	call Tk_DeleteOptionTable(), it's unnecessary and quite possibly
	harmful.

2009-01-08  Jan Nijtmans  <[email protected]>

	* generic/tk3d.c:     CONSTify TkDebugBorder
	* generic/tkBind.c:   CONSTify TkStringToKeysym
	* generic/tkBitmap.c: CONSTify TkDebugBitmap
	* generic/tkColor.c:  CONSTify TkDebugColor
	* generic/tkCursor.c: CONSTify TkDebugCursor
	* generic/tkFont.c:   CONSTify TkDebugFont
	* generic/tkInt.decls All those mods TIP #27 complient,
	                      no incompatibility risks.
	* generic/tkIntDecls.h (regenerated)

2009-01-08  Pat Thoyts  <[email protected]>

	* library/bgerror.tcl: Theme the bgerror dialog and make use of our
	PNG support to improve the icon.

2009-01-07  Pat Thoyts  <[email protected]>

	* library/tkfbox.tcl: [Bug 2473120]: Mis-ordered messagebox args.

	* win/tkWinWm.c: [Bug 1847002]: Prevent grabs being bypassed on
	Windows.

2009-01-06  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		A few const -> CONST86 modifications,
	* generic/tkCanvas.c:	improving backwards compatibility. Change
	* generic/tkCanvLine.c:	Tk_ItemIndexProc and Tk_ItemInsertProc
	* generic/tkCanvPoly.c:	signature to have a Tcl_Obj parameter instead
	* generic/tkCanvText.c:	of a string parameter. This is binary and
	* doc/CrtItemType.3:	source compatible with previous API, it just
	* doc/Clipboard.3:	prevents the need for a type cast in the
	* doc/ConfigWidg.3:	Tk_ItemType table construction. Bring doc in
	* doc/ParseArgv.3:	line with API.

2009-01-06  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock): Optimize a common case for
	photo image building. [Patch 1539990] (jepler)

2009-01-06  Pat Thoyts  <[email protected]>

	* win/tkWinDialog.c: Use task modal for messagebox instead of system
	modal. [Bug 2484771] (ferrieux,thoyts,mjanssen)

2009-01-03  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: [Bug 1836621]: Improve the documentation of the
	-offset and -outlineoffset item options.

2009-01-03  Jan Nijtmans  <[email protected]>

	* generic/tk.decls:       CONSTify Tk_ClipboardAppend
	* generic/tkClipboard.c:
	* generic/tkDecls.h: (regenerated)

2008-12-31  David Gravereaux <[email protected]>

	* win/rules.vc: Small bug not setting SYMBOLS macro fixed.

2008-12-31  Joe English  <[email protected]>

	* generic/ttk/ttkDefaultTheme.c: Fix color palette for radiobutton and
	checkbutton indicators. Fixes [Bug 2003310]; also makes "alt" theme
	check/radiobuttons look like Windows 98, as intended.
	* library/ttk/altTheme.tcl: Specify dark gray -bordercolor to soften
	edges.
	* tests/ttk/{checkbutton,radiobutton}.test: Split out of ttk.test.

2008-12-28  Donal K. Fellows  <[email protected]>

	TIP #171 IMPLEMENTATION

	* library/listbox.tcl, library/scrlbar.tcl, library/text.tcl: Adjust
	users of the <MouseWheel> event to do the right thing horizontally as
	well as vertically.
	* win/tkWinX.c (GenerateXEvent): Redirect <MouseWheel> to the window
	that contains the mouse.
	* generic/tkEvent.c (InvokeFocusHandlers): Do not direct <MouseWheel>
	through the focus mechanism.
	*** POTENTIAL INCOMPATIBILITY *** for anyone counting on shift-wheel
	to do something else (or nothing at all) or for the wheel events to be
	following the keyboard on Win.

	* generic/tkImgPNG.c (ReadIDAT): Corrected code to transfer blocks of
	compressed data into the Tcl_ZlibStream. Allows the reading of all
	images from PngSuite set. Thanks to Michael Kirkham for fix/testing.

	TIP #244 IMPLEMENTATION

	* generic/tkImgPNG.c, tests/imgPNG.test, doc/photo.n: Adaptation of
	tkpng to the Tk core, proving support for PNG image reading and
	writing, based on Tcl's zlib support.

2008-12-27  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c: [Bug 2381555]: Fix inconsistent use of
	treeArea / headingArea. ([$tv identify] didn't work when horizontally
	scrolled).

2008-12-21  Donal K. Fellows  <[email protected]>

	* doc/canvas.n (postscript): Regularized documentation of -channel
	option.

2008-12-19  Don Porter  <[email protected]>

	*** 8.6b1 TAGGED FOR RELEASE ***

	* changes:	Updates for 8.6b1 release.

	* tests/clrpick.test:	Eliminate duplicate test names.
	* tests/embed.test:
	* tests/text.test:
	* tests/textMark.test:

	* README:		Bump version number to 8.6b1
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2008-12-18  Don Porter  <[email protected]>

	* library/msgs/de.msg:	[Patch 2442309]: Updated German messages.
	Thanks to Ruediger Haertel.

2008-12-17  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		VOID --> void
	* unix/tkUnixPort.h:
	* macosx/tkMacOSXPort.h:

2008-12-17  Donal K. Fellows  <[email protected]>

	* doc/selection.n: [Bugs 2441817,2441884]: Assorted small fixes.

2008-12-16  Jan Nijtmans  <[email protected]>

	* win/tkWinDialog.c: Remove unused variables

2008-12-15  Don Porter  <[email protected]>

	TIP #338 IMPLEMENTATION

	* doc/Tk_Main.c:	Removed the last two '#include "tclInt.h"'.
	* generic/tkMain.c:	Tk is now limited to Tcl's public interface.
	* macosx/tkMacOSXInit.c:

2008-12-12  Pat Thoyts  <[email protected]>

	* library/demos/fontchoose.tcl: Simple fontchooser demo.
	* library/demos/widget:

2008-12-11  Jan Nijtmans  <[email protected]>

	* generic/tk3d.c:	Make error message from Tk_GetRelief the same
				as for Tk_GetReliefFromObj.
	* tests/canvas.test:	Adapt test cases for changed error message.
	* tests/scrollbar.test
	* tests/textTag.test

2008-12-11  Joe English  <[email protected]>

	* library/demos/*.tcl: Omit contraindicated [package require Ttk].
	Remove logic that switches [ttk::scrollbar]s to [tk::scrollbar]s
	based on [tk windowingsystem]; this is already handled in
	library/ttk/scrollbar.tcl.

2008-12-10  Daniel Steffen  <[email protected]>

	TIP #324 IMPLEMENTATION

	* generic/tkCmds.c:		Implementation of [tk fontchooser] as
	* generic/tkInt.h:		a Ttk dialog for X11 and as a native
	* win/tkWinDialog.c:		platform dialog on Mac OS X & Windows.
	* win/tkWinInt.h:		(thoyts, vetter, robert, steffen)
	* win/tkWinTest.c:		[Patch 1477426]
	* win/tkWinX.c:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXFont.h:
	* macosx/Wish.xcodeproj/project.pbxproj:
	* library/fontchooser.tcl (new):
	* library/tclIndex:
	* library/msgs/de.msg:
	* library/msgs/en.msg:
	* tests/fontchooser.test (new):
	* tests/winDialog.test:
	* doc/fontchooser.n (new):
	* doc/tk.n:

	* library/console.tcl:		Let user select console font via
					[tk fontchooser].
	* library/demos/text.tcl:	Add [tk fontchooser] demo.

	* generic/tkUtil.c:		Add TkBackgroundEvalObjv() and
					TkSendVirtualEvent() utility functions
					(used by TIP #324 code).

	* generic/tkInt.h:		Turn [tk] into an ensemble.
	* generic/tkBusy.c:		(thoyts, steffen)
	* generic/tkCmds.c:
	* generic/tkWindow.c:

	* macosx/tkMacOSXInit.c (TkpInit): Unconditionally show Tk console if
					   TK_CONSOLE env var is set.

2008-12-09  Don Porter  <[email protected]>

	TIP #337 IMPLEMENTATION

	* generic/tkBind.c:	Updated callers of Tcl_BackgroundError() to
	* generic/tkCanvas.c:	use the new routine
	* generic/tkEntry.c:	Tcl_BackgroundException() as appropriate.
	* generic/tkImgBmap.c:
	* generic/tkListbox.c:
	* generic/tkSelect.c:
	* generic/tkTextDisp.c:
	* generic/tkTextWind.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* unix/tkUnixScale.c:
	* unix/tkUnixWm.c:
	* win/tkWinButton.c:
	* win/tkWinMenu.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c:

2008-12-07  Joe English  <[email protected]>

	* macosx/ttkMacOSXTheme.c: [Bug 2219588]: Add native aqua elements for
	ttk::spinbox
	* generic/ttk/ttkEntry.c, library/ttk/spinbox.tcl,
	* tests/ttk/spinbox.test: Moved most spinbox "business logic" out of
	ttkEntry.c into Tcl bindings.
	* library/ttk/clamTheme.tcl: Minor spinbox appearance improvements.
	* library/ttk/combobox.tcl, library/ttk/utils.tcl:
	Factor out ttk::bindMouseWheel procedure.
	* library/ttk/spinbox.tcl: Add cross-platform MouseWheel bindings.

2008-12-06  Donal K. Fellows  <[email protected]>

	TIP #197 IMPLEMENTATION

	* generic/tkText.c (insertUnfocussedStrings, optionSpecs):
	* generic/tkText.h (TkText, TkTextInsertUnfocussed):
	* doc/text.n, tests/text.test:
	Added definitions/tests/docs for "-insertunfocussed" field.
	* generic/tkTextMark.c (TkTextInsertDisplayProc):
	* generic/tkText.c (TextBlinkProc):
	Added user-controlledrendering of insertion cursor when focus is not
	in the text widget.

2008-12-05  Pat Thoyts  <[email protected]>

	* library/ttk/ttk.tcl:	      Added vista theme to iron out the visual
	* library/ttk/vistaTheme.tcl: differences between vista and XP.
	* library/ttk/xpTheme.tcl:
	* win/ttkWinXPTheme.c:

2008-12-05  Donal K. Fellows  <[email protected]>

	* generic/tkCanvPs.c (Tk_PostscriptFont): [Bug 2107938]: Ensure that
	font sizes can ever be negative; it triggers a really strange case
	that is definitely not what is wanted.
	* library/mkpsenc.tcl: Corrected and improved generation of postscript
	* library/prolog.ps:  prolog. Removed prolog.ps, which wasn't used and
	was misleading.

2008-12-04  Jan Nijtmans  <[email protected]>

	* generic/tkInt.decls:	[FRQ 220906]: Move 10 functions from tkText.h
	* generic/tkText.h:     to stub table.
	* generic/tkStubInit.c (regenerated)
	* generic/tkIntDecls.h (regenerated)

2008-12-04  Donal K. Fellows  <[email protected]>

	* doc/ttk_button.n, doc/ttk_checkbutton.n, doc/ttk_menubutton.n:
	* doc/ttk_radiobutton.n: Added mention of the Toolbutton style to all
	widgets that can sensibly make use of it.

2008-12-03  Joe English  <[email protected]>

	* generic/ttk/ttkState.c, generic/ttk/ttkTheme.h,
	* generic/ttk/ttkWidget.c, doc/ttk_widget.n:
	Add new "hover" state (patch from Pat Thoyts; needed to support proper
	visual feedback on Vista).

2008-11-29  Pat Thoyts  <[email protected]>

	* library/ttk/altTheme.tcl:     Use a styled frame around the popdown
	* library/ttk/clamTheme.tcl:    listbox so we can adjust the border
	* library/ttk/classicTheme.tcl: for each theme as needed.
	* library/ttk/combobox.tcl:
	* library/ttk/defaults.tcl:
	* library/ttk/winTheme.tcl:
	* library/ttk/xpTheme.tcl:
	* tests/ttk/combobox.test:

2008-11-28  Alexandre Ferrieux  <[email protected]>

	* generic/tkCanvUtil.c:	[Bug 1813597,2218964]: Millimeter patch.
	* generic/tkInt.h:	Eliminates the functional redundancy and
	* generic/tkObj.c:	unnecessary loss of precision of the
	* generic/tkText.c:	{pixel,mm}ObjType tandem.

2008-11-27  Jan Nijtmans  <[email protected]>

	* generic/tkCanvLine.c:	Replace Tcl_SetResult(interp, NULL, ....)
	* generic/tkEntry.c:	calls with Tcl_ResetResult(interp)
	* generic/tkMenu.c
	* generic/tkOldConfig.c
	* win/tkWinTest.c:	Eliminate warning: unused variable 'tkwin'

2008-11-23  Pat Thoyts  <[email protected]>

	* generic/tkBind.c:  [Bug 1389270]: event generate silently ignored
	* generic/tkFocus.c: focus events. These can now be generated.
	* generic/tkGrab.c:
	* generic/tkInt.h:
	* tests/bind.test: Fixed some locale dependencies in various
	tests to reduce the noise on non-English windows systems.

2008-11-22  Donal K. Fellows  <[email protected]>

	* library/demos/ctext.tcl: Extended to show off what you can do with
	angled text; there is now a pie selector to change the orientation.

2008-11-22  Pat Thoyts  <[email protected]>

	* library/ttk/combobox.tcl: [Bug 1939129,1991930]: combobox dropdown
				    was drawn behind topmost toplevels.
	* generic/tkCanvText.c:  Fixed up complaints from MSVC engendered
	* generic/tkFont.c:      by the last commit. In particular replaced
	* win/tkWinDraw.c:       round() which is a C99 function.
	* win/tkWinFont.c:

2008-11-22  Donal K. Fellows  <[email protected]>

	TIP #119 IMPLEMENTATION

	* generic/tkCanvText.c:  Added -angle configuration option to canvas
	* generic/tkFont.c:	 text items. This required reengineering the
	* library/prolog.ps:	 whole text rendering engine to be able to
	* macosx/tkMacOSXFont.c: handle an angle! No change to any external
	* unix/tkUnixFont.c:	 API. Note, this feature was originally
	* unix/tkUnixRFont.c:	 approved for Tk 8.5, but it has proved much
	* win/tkWinFont.c:	 harder to implement than originally
	* generic/tkInt.h:	 estimated. [Patch 1611359]
	* tests/canvText.test:

2008-11-22  Pat Thoyts  <[email protected]>

	* test/winDialog.test: [Bug 2307837]: Avoid some locale-dependent
	* win/tkWinTest.c:     failures by using id's or an english constraint

2008-11-19  Joe English  <[email protected]>

	* doc/ttk_panedwindow.n: [Bug 1824996]: Remove inoperative text
	stating that slave windows must be direct children of the master.

2008-11-19  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c	 Minor simplification in fix for [Bug 2312027]
				 no need to malloc and copy photo type name
				 because it is a constant to begin with.
	* generic/tkOldConfig.c	 Convert Tcl_SetResult(......, TCL_DYNAMIC) to
	* mac/tkMacOSXWm.c	 Tcl_SetResult(......, TCL_VOLATILE), in
	* unix/tkUnixWm.c	 preparation for TIP #340
	* unix/tkUnixSend.c
	* win/tkWinWm.c

2008-11-16  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c: [Bug 2298720]: Widget self-destruction is
	not necessarily an error.

2008-11-16  Donal K. Fellows  <[email protected]>

	* doc/wm.n: Added note about [wm overrideredirect] so that users will
	avoid making unwarranted assumptions about how magical it is.
	Triggered by [Bug 2282861] discussion.

2008-11-14  Pat Thoyts  <[email protected]>

	* generic/tk.h:	       The TIP 125 implementation permits the
	* generic/tkFrame.c:   [wm manage] command to manage any widget but
	* macosx/tkMacOSXWm.c: only those with Frame instance data should be
	* unix/tkUnixWm.c:     permitted. We now check for the suitability and
	* win/tkWinWm.c:       raise an error for non-frame widgets. Updated
	* test/wm.test:	       the tests and documentation. See also [Bug
	* doc/wm.n:	       2239034]

2008-11-12  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c: Reworked widget construction and
	destruction sequence; fixes [Bug 2207435] and several other problems
	discovered during investigation of same.
	* generic/ttk/ttkButton.c (CheckbuttonInitialize): Account for
	initializeProc being called earlier in the construction sequence now.
	* tests/ttk/ttk.test: Updated test suite.

2008-11-12  Pat Thoyts  <[email protected]>

	* library/text.tcl: [Bug 1777362]: Handle windows with funky names by
	* test/text.test:   avoiding use of the window path for anchors.

2008-11-11  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c	  Fix [Bug 2265860] new test failures

2008-11-11  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c (BeginDrawing): [Bug 2264732]: Don't crash
	when application uses nondefault visual.

2008-11-11  Jan Nijtmans  <[email protected]>

	* win/tcl.m4:	    Reverted change from 2008-11-06 (was under the
			    impression that "-Wno-implicit-int" added an extra
			    warning)
	* win/configure	    (regenerated)
	* unix/tcl.m4:	    Use -O2 as gcc optimization compiler flag, and get
			    rid of -Wno-implicit-int for UNIX
	* unix/configure    (regenerated)

	* generic/tk.decls     Modify Tk_Create(Old)ImageType signature,
	* generic/tk.h	       relaxing the constraint that every Tk_ImageType
	* generic/tkImage.c    can only be passed to this function once. This
	* generic/tkImgBmap.c  lets tkImg be loaded in multiple interpreters
	* generic/tkImgPhoto.c in a thread-enabled build of Tk. [Bug 2312027]
	* generic/tkTest.c     This CONSTification complies with TIP #27. It
	* doc/CrtImgType.3     is binary compatible with the old interface,
			       but not fully source compatible (although tkImg
			       does not suffer).
	* generic/tkDecls.h (regenerated)

	*** POTENTIAL INCOMPATIBILITY ***

2008-11-09  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c: Remove unnecessary casts.

	* generic/ttk/ttkWidget.h, generic/ttk/ttkWidget.c: Ttk widget
	initializeProc()s now return void instead of a status code, and are no
	longer allowed to fail. (Fix for [Bug 2207435] in progress).

	* generic/ttk/ttkButton.c, generic/ttk/ttkEntry.c,
	* generic/ttk/ttkFrame.c, generic/ttk/ttkNotebook.c,
	* generic/ttk/ttkPanedwindow.c, generic/ttk/ttkProgress.c,
	* generic/ttk/ttkScale.c, generic/ttk/ttkScrollbar.c,
	* generic/ttk/ttkTreeview.c: Adjustments for the above.

2008-11-09  Jan Nijtmans  <[email protected]>

	* generic/tkCanvas.c:	 Make all Tk_CustomOption tables const and
	* generic/tkCanvBmap.c:	 remove unnecessary type cast.
	* generic/tkCanvImg.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkRectOval.c:
	* generic/tkScrollbar.c:
	* generic/tk.decls:	Two more (hopefully the last) signature
	* generic/tkInt.h:	changes in Tk_CreateSmoothMethod and
	* generic/tkCanvLine.c: Tk_CreatePhotoImageFormat
	* generic/tkCanvUtil.c:
	* generic/tkImgPhoto.c:
	* generic/tkDecls.h: (regenerated)
	* doc/CrtImgType.3:  doc updates
	* doc/CrtPhImgFmt.3:

2008-11-06  Jan Nijtmans  <[email protected]>

	* win/tcl.m4: Add "-Wno-implicit-int" flag for gcc, as on UNIX
	* win/configure: (regenerated)
	* generic/default.h: Use tkUnixDefault.h under CygWin. With this
			     change, at least the X11 version of Tk can be
			     built with cygwin.

2008-11-06  Donal K. Fellows  <[email protected]>

	* unix/configure.in: [Bug 2229999]: Work around the fact that the
	HP-UX system compiler cannot handle 'inline'.

2008-11-05  Jan Nijtmans  <[email protected]>

	* unix/tkUnixFont.c:   [Bug 2226093]: Const changes not all correct
	* unix/tkUnixButton.c: More internal -Wwrite-strings warning fixes
	* unix/tkUnixCursor.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixRFont.c:
	* generic/tkInt.h:     No need to use CONST in internal header files
	* generic/tkFont.h
	* generic/tkInt.decls: CONSTify string and fileName parameters of
	* generic/tkImgBmap.c: TkGetBitmapData
	* generic/tkBitmap.c:  Remove unneccessary type cast
	* generic/tkIntDecls.h: (regenerated)
	* doc/GetCursor.3:     Fix documentation about obsolete X10 bitmaps
	* doc/GetBitmap.3:     [Bug 1866774]: Remove X10 references from docs

2008-11-03  Jan Nijtmans  <[email protected]>

	* generic/ttk/ttkEntry.c: Fix warning: unused variable `currentValue'
	* generic/tkOldTest.c:	  Fix warning: assignment discards qualifiers
	* win/tkWinTest.c:	  from pointer target type

2008-11-03  Pat Thoyts  <[email protected]>

	* tests/winClipboard.test: testclipboard no longer returns strings
	with embedded \r but now returns Tcl strings
	* tests/winfo.test: Fixed embedding test broken during upgrade
	* tests/busy.test: Default wait cursor on windows is 'wait'
	* win/tkWinFont.c: const fixes for the windows code.

2008-11-02  Jan Nijtmans  <[email protected]>

	* generic/tkFont.h:	 More internal -Wwrite-strings warning fixes
	* generic/tkFont.c
	* generic/ttk/ttkTheme.h
	* generic/ttk/ttkDefaultTheme.c
	* generic/ttk/ttkState.c
	* macosx/tkMacOSXFont.c
	* unix/tkUnixFont.c
	* win/tkWinFont.c

2008-11-01  Donal K. Fellows  <[email protected]>

	TIP #97 IMPLEMENTATION

	* generic/tkCanvas.c (CanvasWidgetCmd): Implementation of the 'imove'
	and 'rchars' subcommands.
	* generic/tk.h (TK_MOVABLE_POINTS): New flag to allow items to state
	whether they support finding and moving individual coordinates.
	* doc/canvas.n, tests/canvas.test: Docs 'n' tests.

2008-11-01  Pat Thoyts  <[email protected]>

	* generic/ttk/ttkEntry.c:      Implemented the themed spinbox
	* library/ttk/altTheme.tcl:    widget.
	* library/ttk/clamTheme.tcl:
	* library/ttk/classicTheme.tcl:
	* library/ttk/defaults.tcl:
	* library/ttk/entry.tcl:
	* library/ttk/ttk.tcl:
	* library/ttk/winTheme.tcl:
	* library/ttk/xpTheme.tcl:
	* library/ttk/spinbox.tcl:
	* win/ttkWinTheme.c:
	* win/ttkWinXPTheme.c:
	* doc/ttk_spinbox.n:
	* tests/ttk/spinbox.test:

2008-10-31  Joe English  <[email protected]>

	* generic/widget.c: Temporary workaround for [Bug 2207435]

2008-10-30  Jan Nijtmans  <[email protected]>

	* generic/tkAtom.c:	 more internal -Wwrite-strings warning fixes
	* generic/tkBusy.c
	* generic/tkButton.c
	* generic/tkCanvPoly.c
	* generic/tkCanvText.c
	* generic/tkCmds.c
	* generic/tkListbox.c
	* generic/tkMenu.c
	* generic/tkOldConfig.c
	* generic/tkOption.c
	* generic/tkPanedWindow.c
	* generic/tkPlace.c
	* generic/tkScale.c
	* generic/tkTest.c
	* generic/tkText.c
	* generic/tkTextImage.c

2008-10-30  Don Porter  <[email protected]>

	* tests/unixSelect.test:	Revise the unixSelect-1.* tests so that
	they test the ability of Tk's selection mechanism to faithfully pass
	valid Tcl values without corruption, and stop testing details of
	Tcl's internal encoding scheme.	 With this change, the Tk test suite
	no longer uses the identity encoding or [string bytelength].

2008-10-30  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		      CONSTify return value of
	* generic/tkInt.h	      Tk_OptionPrintProc, and customPtr
	* generic/tk.decls	      field of Tk_ConfigSpec.
	* generic/tkCanvArc.c	      See [Bug 2190619]: Warnings due to
	* generic/tkCanvLine.c	      Tk_SmoothMethod name constness change
	* generic/tkCanvUtil.c
	* generic/tkUtil.c
	* generic/tkDecls.h:	      (regenerated)

2008-10-29  Joe English  <[email protected]>

	* generic/tkAtom.c(Tk_GetAtomName): Remove incorrect 'const' qualifier.
	Remove useless 'register' declarations too, while we're at it.

2008-10-28  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		Add "const" to a few struct member fields.
	* generic/tkInt.h:	CONSTify TkPrintPadAmount
	* generic/tkSelect.h:	Move TkSelGetSelection to tkInt.decls
	* generic/tk.decls:	CONSTify Tk_ParseArgv
	* generic/tkInt.decls:	CONSTify TkCreateFrame and TkCreateMainWindow
	* generic/tkDecls.h:	(regenerated)
	* generic/tkIntDecls.h:	(regenerated)
	* generic/tkArgv.c:
	* generic/tkAtom.c:
	* generic/tkEntry.c:
	* generic/tkFrame.c:
	* generic/tkImgPhoto.c:
	* generic/tkPack.c:
	* generic/tkSelect.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* win/tkWinTest.c:	Fix compilation under mingw32

2008-10-28  Joe English  <[email protected]>

	* library/ttk/cursors.tcl, library/ttk/combobox.tcl,
	library/ttk/entry.tcl, library/ttk/paned.tcl, library/ttk/sizegrip.tcl,
	library/treeview.tcl:
	[Bug 2054562]: Add correct platform-specific cursors for OSX
	[Bug 1534835]: Expanded set of symbolic cursors.  Use correct cursor
	for ttk::entry and ttk::combobox widgets

2008-10-28  Don Porter  <[email protected]>

	* win/tkWinTest.c:		[Bug 2191960]: Revise [testclipboard]
	* tests/winClipboard.test:	to form that handles encodings.
	* tests/constraints.tcl: [tcltest::bytestring] no longer used.

2008-10-24  Joe English  <[email protected]>

	* tests/ttk/ttk.test: [Bug 2175411]: Disable test ttk-6.3, it's not
	applicable.

	* generic/ttk/ttkTheme.c: Use different Tcl_AssocData key so the tile
	extension can be loaded into an 8.6 interp, in the off-chance that
	anyone wants to do this.

2008-10-24  Donal K. Fellows  <[email protected]>

	* generic/tkCanvUtil.c (TkSmoothPrintProc): [Bug 2190619]: Corrected
	'const'ness to quell warning.

2008-10-23  Don Porter  <[email protected]>

	* README:		Bump version number to 8.6a4
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2008-10-22  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		      CONST -> const and white-spacing
	* generic/tk.decls
	* generic/tkInt.decls
	* generic/tkDecls.h:	      (regenerated)
	* generic/tkIntDecls.h:	      (regenerated)
	* generic/tkIntPlatDecls.h:   (regenerated)
	* generic/tkIntXlibDecls.h:   (regenerated)
	* generic/tkPlatDecls.h:      (regenerated)
	* generic/ttk/tk.decls
	* generic/ttk/ttkDecls.h      (regenerated)
	* generic/ttk/ttkGenStubs.tcl

2008-10-20  Donal K. Fellows  <[email protected]>

	* generic/tkBusy.c, macosx/tkMacOSXEmbed.c, unix/tkUnixEmbed.c:
	* win/tkWinWindow.c: [Bug 2180919]: Factor out the platform-specific
	parts into the platform directories.

2008-10-18  Donal K. Fellows  <[email protected]>

	TIP #321 IMPLEMENTATION

	* generic/tkBusy.c, doc/busy.n, tests/busy.test: [Patch 1997907]:
	Implementation of the [tk busy] command.

2008-10-18  Pat Thoyts  <[email protected]>

	* win/tkWinFont.c: [Bug 1825353]: To fix a problem with tiny fonts on
	Russian versions of Windows we will avoid removing the internal
	leading for fixed width fonts.

2008-10-15  Jan Nijtmans  <[email protected]>

	* generic/tk.h:		 Add "const" to many internal const tables, so
	* generic/tkBind.c:	 those will be put by the C-compiler in the
	* generic/tkButton.c:	 TEXT segment instead of the DATA segment.
	* generic/tkCanvas.c:	 This makes those tables as being shareable in
	* generic/tkClipboard.c: shared libraries.
	* generic/tkCmds.c:
	* generic/tkConsole.c:
	* generic/tkEntry.c:
	* generic/tkFocus.c:
	* generic/tkFrame.c:
	* generic/tkGet.c:
	* generic/tkGrab.c:
	* generic/tkGrid.c:
	* generic/tkImage.c:
	* generic/tkImgBmap.c:
	* generic/tkImgGIF.c:
	* generic/tkImgPhoto.c:
	* generic/tkListbox.c:
	* generic/tkMenu.c:
	* generic/tkMenu.h:
	* generic/tkMenubutton.c:
	* generic/tkMessage.c:
	* generic/tkOption.c:
	* generic/tkPack.c:
	* generic/tkPanedWindow.c:
	* generic/tkPlace.c:
	* generic/tkScale.c:
	* generic/tkSelect.c:
	* generic/tkSquare.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkTextDisp.c:
	* generic/tkTextMark.c:
	* generic/tkTextTag.c:
	* generic/tkTextWind.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXWin.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixWm.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinDialog.c:
	* win/tkWinMenu.c:
	* win/tkWinSend.c:
	* win/tkWinWm.c:
	* xlib/xcolors.c:

2008-10-17  Pat Thoyts  <[email protected]>

	* library/ttk/scale.tcl: Implemented keyboard bindings for ttk::scale

2008-10-15  Jan Nijtmans  <[email protected]>

	* generic/tkInt.h:	 Add "const" to many internal const tables, so
	* generic/tk3d.c:	 those will be put by the C-compiler in the
	* generic/tkBitmap.c:	 TEXT segment instead of the DATA segment.
	* generic/tkColor.c:	 This makes those tables as being shareable in
	* generic/tkConfig.c:	 shared libraries.
	* generic/tkCursor.c:
	* generic/tkFont.c:
	* generic/tkObj.c:
	* generic/tkStyle.c:
	* generic/tkTextIndex.c:
	* generic/tkUtil.c:

2008-10-14  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (TkNewWindowObj): Added utility function for making
	a Tcl_Obj from a Tk_Window reference. Candidate for future exposure to
	third-party code I suppose, but useful internal to Tk for sure.

2008-10-11  Donal K. Fellows  <[email protected]>

	* generic/tkCanvas.c (CanvasWidgetCmd): Corrected result generation.

2008-10-10  Don Porter  <[email protected]>

	*** 8.6a3 TAGGED FOR RELEASE ***

	* changes:	Updates for 8.6a3 release.

2008-10-09  Don Porter  <[email protected]>

	* generic/tkListbox.c:	Make literal return values consistent with
	those generated by Tcl_PrintDouble().

	* tests/entry.test:	Restore test naming consistency with Tk 8.5.
	* tests/listbox.test:	Remove some more dependency on precision in
	* tests/spinbox.test:	test results.

2008-10-08  Jan Nijtmans  <[email protected]>

	* unix/tcl.m4:		[Bug 2073255]: fix
	* unix/configure:	regenerated

2008-10-08  Don Porter  <[email protected]>

	* tests/textDisp.test (textDisp-16.34): Update test that tested string
	equality of double values based on an assumption of tcl_precision==12.
	Test now does its own formatting.

	* tests/scrollbar.test: Revised testing of the cget subcommand so that
	it tests consistency with the configure subcommand and not agreement
	with a hardcoded value that will change as tastes in GUIs evolve.

	* tests/canvText.test (canvText-17.1): Update expected result to match
	revised PostScript output due to more predictable formatting of
	floating point values.

	* unix/tkUnixWm.c:	[Bug 2021443]: Restored consistency of error
	* macosx/tkMacOSXWm.c:	messages from [wm iconphoto] with the test
	* tests/unixWm.test:	suite and across all platforms.

2008-10-07  Pat Thoyts  <[email protected]>

	* tests/canvImg.test:  Removed dependency on precision in results
	* tests/canvRect.test:
	* tests/canvText.test:
	* tests/entry.test:
	* tests/listbox.test:
	* tests/scrollbar.test:
	* tests/spinbox.test:
	* tests/winWm.test: Fixed incorrect error strings
	* tests/wm.test:

2008-10-06  Pat Thoyts  <[email protected]>

	* tests/winDialog.test: Fixed tests for Vista+
	* win/tkWinWm.c: corrected some errors from the previous commit

2008-10-05  Donal K. Fellows  <[email protected]>

	* win/tkWinWm.c (WmAttributesCmd, WmOverrideredirectCmd)
	(WmStackorderCmd):
	* win/tkWinSendCom.c (Async):
	* win/tkWinSend.c (Tk_SendObjCmd):
	* win/tkWinFont.c (TkpGetFontFamilies, TkpGetSubFonts):
	* unix/tkUnixWm.c (WmOverrideredirectCmd, WmStackorderCmd):
	* unix/tkUnixFont.c (TkpGetFontFamilies, TkpGetSubFonts):
	* macosx/tkMacOSXWm.c (WmOverrideredirectCmd, WmStackorderCmd):
	* generic/tkTextIndex.c (SetTextIndexFromAny):
	* generic/tkTest.c (TrivialConfigObjCmd):
	* generic/tkSelect.c (HandleTclCommand):
	* generic/tkPanedWindow.c (Tk_PanedWindowObjCmd)
	(PanedWindowSashCommand, PanedWindowProxyCommand):
	* generic/tkMenubutton.c (Tk_MenubuttonObjCmd):
	* generic/tkMenu.c (MenuWidgetObjCmd):
	* generic/tkListbox.c (ListboxWidgetObjCmd):
	* generic/tkImgPhoto.c (ImgPhotoCmd): (mostly)
	* generic/tkImage.c (Tk_ImageObjCmd):
	* generic/tkFont.c (Tk_FontObjCmd, GetAttributeInfoObj):
	* generic/tkEntry.c (EntryWidgetObjCmd, SpinboxWidgetObjCmd):
	* generic/tkConfig.c (SetOptionFromAny, Tk_SetOptions):
	* generic/tkCmds.c (Tk_TkObjCmd, Tk_WinfoObjCmd, TkGetDisplayOf):
	* generic/tkButton.c (ButtonCreate): Get rid of code that insists on
	non-idiomatically writing to the object in the interpreter result.

2008-10-03  Donal K. Fellows  <[email protected]>

	* generic/tkArgv.c, generic/tkCanvText.c, generic/tkEntry.c:
	* generic/tkListbox.c, generic/tkScrollbar.c, macosx/tkMacOSXScrlbr.c:
	* win/tkWinScrlbr.c: [Bug 2112563]: Convert use of %g to
	Tcl_PrintDouble to create string versions of floats so as to avoid
	trouble with some locales.

2008-10-02  Joe Mistachkin  <[email protected]>

	* doc/canvas.n: Fix unmatched font change.
	* win/buildall.vc.bat: Prefer the HtmlHelp target over the WinHelp
	target.

2008-10-01  Donal K. Fellows  <[email protected]>

	TIP #236 IMPLEMENTATION

	* doc/canvas.n, generic/tkCanvas.c (CanvasWidgetCmd)
	* tests/canvMoveto.test: Added 'moveto' subcommand to canvases to
	allow items to be easily moved to a particular place.

2008-09-23  Donal K. Fellows  <[email protected]>

	* doc/listbox.n (SEE ALSO): [Bug 2123813]: Redirected this to
	ttk::treeview(n) which is far more useful (it does multicolumn listbox
	duties).

	* doc/*.n: [Bug 2118116]: Make sure that the initial line of the
	manpage includes nothing that chokes old versions of man.

2008-08-25  Todd M. Helfter  <[email protected]>

	* library/menu.tcl: [Bug 1023955]: Additional fix.

2008-09-08  Todd M. Helfter  <[email protected]>

	* doc/menu.n: [Bug 2098425]: Fix typo in docs.

2008-09-03  Don Porter  <[email protected]>

	* generic/tk.h:		Dropped use of _ANSI_ARGS_ macro to preserve
	* generic/tkSelect.h:	Tk's TCL_NO_DEPRECATED build.

2008-08-30  Ania Pawelczyk  <[email protected]>

	* tests/textWind.test: Update to tcltest2
	* tests/unixSelect.test:
	* tests/visual_bb.test:
	* tests/visual.test:
	* tests/window.test:
	* tests/winfo.test:
	* tests/xmfbox.test:
	* tests/winButton.test:
	* tests/winDialog.test:
	* tests/winFont.test:
	* tests/winMenu.test:
	* tests/winMsbox.test:
	* tests/winWm.test:

2008-08-28  Don Porter  <[email protected]>

	* unix/tkConfig.sh.in:	Added @XFT_LIBS@ to the definition of TK_LIBS
	to avoid link failures when a "big wish" program links against a
	--disable-shared build of libtk. (Discovered building expectTk.)

	* generic/tkImgPhoto.c:	Changed TclStack* calls to ck* calls so that
	we don't create new dependencies on Tcl internals.

	* unix/tkUnixPort.h:	Removed #include of tclInt.h that has been
	* win/tkWinPort.h:	disabled for three years. If we needed this
	we'd have noticed by now.

	* README:		Bump version number to 8.6a3
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2008-08-28  Donal K. Fellows  <[email protected]>

	* tests/imgPhoto.test: [Bug 2080587]: Fix failures.

2008-08-28  Ania Pawelczyk  <[email protected]>

	* tests/option.test: Update to tcltest2
	* tests/place.test:
	* tests/scale.test:
	* tests/select.test:
	* tests/textBTree.test:
	* tests/textImage.test:
	* tests/textMark.test:
	* tests/textTag.test:
	* tests/unixMenu.test:

2008-08-25  Todd M. Helfter  <[email protected]>

	* library/menu.tcl: [Bug 1023955]: Fix typo.

2008-08-27  Peter Spjuth  <[email protected]>

	* tests/grid.test: [Bug 2075285]: Added a "knownBug"-marked test to
	show a problem identified in the grid implementation.

2008-08-26  Donal K. Fellows  <[email protected]>

	* tests/imgPhoto.test: More style improvements.

2008-08-25  Todd M. Helfter  <[email protected]>

	* library/menu.tcl: [Bug 1023955]: Do not flip to the arrow cursor on
	menus. This was a Motif convention. Current behavior is maintained iff
	tk_strictMotif is enabled.

2008-08-25  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoConfigureMaster): Ensure that uses of
	TclStackAlloc and TclStackFree balance.

2008-08-25  Todd M. Helfter  <[email protected]>

	* library/tkfbox.tcl: [Bug 1936220]: Fix the multiple selection error
	for tk_getOpenFile -multiple 1 which fails on all unix platforms since
	the adoption of ttk widgets.

2008-08-25  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c:	     Split the implementation of the core of
	* generic/tkImgPhoto.h:	     photo images into two pieces, the photo
	* generic/tkImgPhInstance.c: master (which manages the data model and
	the interaction with the script level) and the photo instances (which
	handle display).

2008-08-22  Don Porter  <[email protected]>

	*** 8.6a2 TAGGED FOR RELEASE ***

	* changes:	Updates for 8.6a2 release.

2008-08-21  Ania Pawelczyk  <[email protected]>

	* tests/menuDraw.test: Update to tcltest2
	* tests/msgbox.test:
	* tests/oldpack.test:
	* tests/pack.test:
	* tests/panedwindow.test:

2008-08-21  Donal K. Fellows  <[email protected]>

	* generic/tkOption.c (ExtendArray): Rework so that the code uses
	ckrealloc (idiomatically) rather than its home-brewed version.

2008-08-19  George Peter Staplin  <[email protected]>

	[Bug 2039720]: After some discussion with Joe English and subsequently
	the X.org developers (Keith Packard in particular), it was discovered
	that Tk is doing management of XIDs that it shouldn't need to do. The
	very common XC-MISC extension which has come with every version of X
	for the last 15 years is used with Xlib now, to retrieve the
	information about the used/unused XIDs. The public Tk_FreeXId is now a
	no-op.

	* generic/tkError.c: Remove the usage of TkpWindowWasRecentlyDeleted.
	* generic/tkInt.decls: Update the declarations for the now unused
	internal stubs.
	* generic/tkIntDecls.h: Regenerated based on tkInt.decls.
	* generic/tkIntPlatDecls.h: Regenerated based on tkInt.decls.
	* generic/tkStubInit.c
	* generic/tkWindow.c: Remove the calls to TkInitXId, and
	TkFreeWindowId.
	* macosx/tkMaxOSXPort.h: Remove TkFreeWindowId and TkInitXId macro
	definitions.
	* macosx/tkMacOSXXStubs.c: Remove the no-op
	TkpWindowWasRecentlyDeleted.
	* unix/tkUnixEvent.c: Remove call to TkFreeXId.
	* unix/tkUnixXId.c: Remove a lot of unnecessary code (see above).
	* win/tkWinPort.h: Remove TkFreeWindowId and TkInitXId.
	* win/tkWinWindow.c: Remove TkpWindowWasRecentlyDeleted.
	* tests/id.test: Remove this unnecessary test.

2008-08-19  Joe English  <[email protected]>

	* generic/ttk/ttkScroll.c: Don't use sprintf "%g" to format floating
	point numbers in -[xy]scrollcommand callbacks or [xy]view methods.
	Minor incompatibility: 0 and 1 now formatted as "0.0" resp "1.0".
	* tests/ttk/entry.test, tests/ttk/treeview.test: Updated to account
	for above change.

2008-08-19  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXFont.c (SetFontFeatures): Disable antialiasing of
						   fixed-width fonts with
						   size <= 10.

2008-08-18  Ania Pawelczyk  <[email protected]>

	* tests/canvWind.test: Update to tcltest2
	* tests/menubut.test:
	* tests/raise.test:
	* tests/unixButton.test:
	* tests/unixEmbed.test:
	* tests/winClipboard.test:

2008-08-17  Ania Pawelczyk  <[email protected]>

	* tests/focus.test: Update to tcltest2
	* tests/focusTcl.test:
	* tests/geometry.test:
	* tests/grab.test:
	* tests/grid.test:
	* tests/imgBmap.test:
	* tests/imgPhoto.test:
	* tests/imgPPM.test:
	* tests/listbox.test:
	* tests/safe.test:
	* tests/tk.test:
	* tests/util.test:

2008-08-15  Ania Pawelczyk  <[email protected]>

	* tests/clrpick.test: Update to tcltest2
	* tests/frame.test:
	* tests/font.test:
	* tests/image.test:

2008-08-14  Ania Pawelczyk  <[email protected]>

	* tests/event.test: Update to tcltest2
	* tests/id.test:
	* tests/menu.test:

2008-08-14  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (SC_PATH_X):	Check for libX11.dylib in addition to
					libX11.so et al.

	* unix/configure:		autoconf-2.59

2008-08-12  Ania Pawelczyk  <[email protected]>

	* tests/choosedir.test: Update to tcltest2
	* tests/clipboard.test:
	* tests/embed.test:
	* tests/main.test:

2008-08-12  Don Porter  <[email protected]>

	* README:		Bump version number to 8.6a2
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

	* changes:	Updates for 8.6a2 release.

2008-08-11  Ania Pawelczyk  <[email protected]>

	* tests/canvImg.test: Update to tcltest2
	* tests/canvRect.test:
	* tests/canvText.test:
	* tests/obj.test:

2008-08-07  Ania Pawelczyk  <[email protected]>

	* tests/canvPs.test: Update to tcltest2
	* tests/config.test:
	* tests/canvas.test:

2008-08-05  Joe English  <[email protected]>

	* generic/tk.h, generic/tkEvent.c: Fix for [Bug 2010422] "no event
	type or button # or keysym while executing "bind Listbox
	<MouseWheel> [...]".

2008-08-03  Ania Pawelczyk  <[email protected]>

	* tests/cmds.test: Update to tcltest2
	* tests/dialog.test:
	* tests/get.test:
	* tests/text.test: Update to tcltest2; report: 33.11 fails

2008-08-01  Pat Thoyts  <[email protected]>

	* win/tkWinWm.c: [Bug 2028703]: Check wmPtr is valid in
	* tests/wm.test: TopLevelReqProc.

2008-07-31  Don Porter  <[email protected]>

	* generic/tk.h: Added missing EXTERN for the Tcl_PkgInitStubsCheck
	declaration to fix inability to embed non-stub-enabled Tk on Windows.

2008-07-29  Ania Pawelczyk  <[email protected]>

	* tests/constraints.tcl: -highlightthickness entry's option (fonts
	constraint)

2008-07-28  Ania Pawelczyk  <[email protected]>

	* tests/cursor.test: Update to tcltest2
	* tests/message.test:

2008-07-26  Pat Thoyts  <[email protected]>

	* doc/options.n: [Bug 1686012]: Direct to the font manual for -font.

	* tests/constraints.tcl: Add a nonwin contraint.
	* tests/listbox.test:	 [Bug 2024753]: Conform to testing policy.

	* win/tkWinWm.c: [Bug 2009788]: Check that the parent has been mapped
	* tests/wm.test: before calling RemapWindows.

	* win/tkWinWindow.c: [Bug 2026405]: Check for 0x prefix in sprintf %p.

2008-07-25  Ania Pawelczyk  <[email protected]>

	* tests/bind.test: Update to tcltest2

2008-07-24  Jan Nijtmans  <[email protected]>

	* generic/*.c: [Bug 2021443]: Fix inconsistant "wrong # args" messages
	* macosx/tkMacOSXSend.c
	* macosx/tkMacOSXWm.c
	* unix/tkUnixSend.c
	* unix/tkUnixWm.c
	* tests/*.test

2008-07-22  Ania Pawelczyk  <[email protected]>

	* tests/bell.test:   Update to tcltest2
	* tests/bgerror.test:
	* tests/bitmap.test:
	* tests/border.test:
	* tests/button.test:
	* tests/entry.test:
	* tests/spinbox.test:

2008-07-22  Daniel Steffen  <[email protected]>

	* library/ttk/aquaTheme.tcl: Use system color names and TIP145 named
	font instead of hardcoded color values and deprecated native font name

	* macosx/tkMacOSXHLEvents.c: Factor out common code; formatting.

2008-07-08  Pat Thoyts  <[email protected]>

	* doc/*.n: Fixed broken line endings from last doc commit.

2008-07-04  Joe English  <[email protected]>

	* generic/ttk/ttkDefaultTheme.c, generic/ttk/ttkClamTheme.c,
	* generic/ttk/ttkClassicTheme.c, generic/ttk/ttkElements.c:
	[Bug 2009213]: Audit: ensure that output arguments to Tk_Get*FromObj()
	are initialized, in case of erroneous style specifications.

2008-07-02  Donal K. Fellows  <[email protected]>

	* macosx/tkMacOSXHLEvents.c: Some tidying up of this file. Make sure
	that failing handling callbacks get reported as background errors.

2008-06-30  Donal K. Fellows  <[email protected]>

	* doc/*.1, doc/*.3, doc/*.n: Remove out of date changebars, make
	formatting of typedefs consistent, other small changes.

2008-06-25  Don Porter  <[email protected]>

	*** 8.6a1 TAGGED FOR RELEASE ***

	* changes:		Updates for 8.6a1 release.

2008-06-24  Pat Thoyts  <[email protected]>

	* library/demos/ttkpane.tcl: Work around missing timezones
	* doc/text.n: [Bug 1997293]: Fix documentation of text tag options.

2008-06-19  Don Porter  <[email protected]>

	* changes:		Updates for 8.6a1 release.

	* generic/tk.h:		TIP 285 additions make Tk 8.6 call the new
	* library/tk.tcl:	Tcl_Canceled() routine, available only in Tcl
	8.6, so bump our Tcl dependencies to version 8.6. Tk 8.6a1 will no
	longer [load] into a Tcl 8.5 interp.

	* README:		Bump version number to 8.6a1
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2008-06-18  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXCarbonEvents.c: Fix debug carbon event tracing.
	(InstallStandardApplicationEventHandler): Replace needless use of
	TkMacOSXInitNamedDebugSymbol() by standard TkMacOSXInitNamedSymbol().

	* macosx/tkMacOSXDebug.c:	Revert 2007-11-09 commit making
	* macosx/tkMacOSXDebug.h:	TkMacOSXInitNamedDebugSymbol()
					available outside of debug builds.

	* macosx/tkMacOSXEmbed.c (TkpMakeWindow):	Fix bug with missing
	* macosx/tkMacOSXSubwindows.c (XMapWindow):	focus on first map by
	only sending VisibilityNotify events once windows are mapped (rather
	than when they are created).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessWindowEvent): Fix
	return value.

	* macosx/tkMacOSXInit.c:	Add helper to efficiently convert from
	* macosx/tkMacOSXPrivate.h:	CFString to Tcl_Obj.

	* macosx/tkMacOSXFont.c (TkpGetFontFromAttributes, InitFont):	Fix
	incorrect conversion to points of font sizes already in points; factor
	out retrieval of font family name from font family ID.

2008-06-13  Jeff Hobbs  <[email protected]>

	* win/configure, win/configure.in (TK_WIN_VERSION): Fix handling of
	interim a/b versioning for manifest usage.

2008-06-13  Joe Mistachkin  <[email protected]>

	TIP #285 IMPLEMENTATION

	* generic/tkCmds.c: During [tkwait] and [update], always cooperatively
	check for script cancellation.
	* win/makefile.vc: Added 'pdbs' option for Windows build rules to
	* win/rules.vc: allow for non-debug builds with full symbols.

2008-06-12  Daniel Steffen  <[email protected]>

	* generic/tkPointer.c (Tk_UpdatePointer): [Bug 1991932]: Fix failure
	to restore a global grab capture and to release the restrict window
	capture when releasing a button grab. Fixes segfault due to dangling
	reference to restrict window inside TkpSetCapture() implementation.

	* generic/ttk/ttkTreeview.c:	Fix warning.

	* unix/tcl.m4 (SunOS-5.11): Fix 64bit amd64 support with gcc & Sun cc.
	* unix/configure: autoconf-2.59

	* macosx/tkMacOSXXStubs.c (Tk_ResetUserInactiveTime): Use UsrActivity
	instead of OverallAct (which may be ignored in some circumstances).

	* macosx/Wish.xcodeproj/project.pbxproj: Add tclIORTrans.c; add tclOO
	* macosx/Wish.xcodeproj/default.pbxuser: files to tktest-X11 target;
	add debug configs for 64bit and with corefoundation disabled; updates
	and cleanup for Xcode 3.1 and for Leopard; sync with Tcl.xcodeproj.
	* macosx/Wish.xcode/project.pbxproj:	Sync Wish.xcodeproj changes.
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/README:			Document new build configs.

2008-06-10  Joe English  <[email protected]>

	* unix/tkUnixKey.c: [Patch 1986818]: Use Xutf8LookupString if
	available. This should fix problems (like [Bug 1908443]) where Xlib's
	idea of the system encoding does not match Tcl's.

2008-06-01  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: Add new tclOO files; add
	* macosx/README:			 debug configs with gcov;
						 update to Xcode 3.1.

2008-05-27  Pat Thoyts  <[email protected]>

	* generic/ttk/ttkTheme.c: [ttk::style theme use] without an argument
	* doc/ttk_style.n: now returns the current theme.

2008-05-23  Joe English  <[email protected]>

	* doc/ttk_treeview.n, generic/ttk/ttkTreeview.c,
	* generic/ttk/ttkTagSet.c, generic/ttk/ttkLayout.c,
	* generic/ttk/ttkTheme.c, generic/ttk/ttkTheme.h,
	* generic/ttk/ttkThemeInt.h, generic/ttk/ttkWidget.h:
	Added [$tv identify region], [$tv identify element], and [$tv identify
	item] subcommands. Simplified bindings. Added [$tv tag has]
	subcommand. Tag-related display improvements; setting a tag
	-background or -foreground no longer overrides selection feedback.

	* library/ttk/altTheme.tcl, library/ttk/aquaTheme.tcl,
	* library/ttk/clamTheme.tcl, library/ttk/classicTheme.tcl,
	* library/ttk/defaults.tcl, library/ttk/treeview.tcl,
	* library/ttk/winTheme.tcl, library/ttk/xpTheme.tcl:
	Don't need separate 'Item', 'Cell', and 'Row' style settings anymore,
	only the base "Treeview" style is used.

2008-05-23  Joe English  <[email protected]>

	* generic/ttk/ttkLabel.c: [Bug 1967576]: Avoid passing width or height
	<= 0 to Tk_RedrawImage, as this leads to a panic on Windows.

2008-05-16  Pat Thoyts  <[email protected]>

	* library/ttk/xpTheme.tcl: Add correct border to combobox on Vista

2008-05-15  Pat Thoyts  <[email protected]>

	* win/makefile.vc: We should use the thread allocator for threaded
	* win/rules.vc: builds. Added 'tclalloc' option to disable.

2008-05-14  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (PanedWindowProxyCommand)
	(DisplayPanedWindow): [Bug 1639824]: Ensure that a zero width never
	gets fed to the underlying window system.

2008-05-13  Pat Thoyts  <[email protected]>

	* library/console.tcl: Support pixel sized font in +/- keybinding.
	* tests/listbox.test: -activestyle default is underline on windows.
	* tests/winDialog.test: Fixed hanging tk_chooseColor tests.

2008-05-11  Pat Thoyts  <[email protected]>

	* library/tk.tcl: Support for ttk widgets in AmpWidget
	* doc/button.n: [Patch 1883418]: Note negative widths for button.

2008-05-09  Pat Thoyts  <[email protected]>

	* doc/ttk_*: 'identify' widget command is on all ttk widgets.

2008-05-04  Joe English  <[email protected]>

	* macosx/ttkMacOSAquaTheme.c: [Bug 1942785]: "default" and "focus"
	adornments should not be disjoint.

2008-04-27  Donal K. Fellows  <[email protected]>

	* */*.c: A large tranche of getting rid of pre-C89-isms; if your
	compiler doesn't support things like proper function declarations,
	'void' and 'const', borrow a proper one when building Tcl. (The header
	files allow building things that link against Tcl with really ancient
	compilers still; the requirement is just when building Tcl itself.)

2008-04-25  Joe English  <[email protected]>

	* library/ttk/treeview.tcl: [Bug 1951733]: [$tv selection] takes a
	list of items, not a single item.

2008-04-20  Pat Thoyts  <[email protected]>

	* win/makefile.vc: [Bug 1900872]: Include ws2_32 in the link list.
	* doc/menu.n: [Bug 1887169]: Minor change regarding the system menu.
	* doc/button.n: [Bug 1926223]: Minor clarification of button flash.

2008-04-17  Donal K. Fellows  <[email protected]>

	* doc/text.n: Correct description of when -relief option is ignored on
	a tag. Thanks to emiliano for spotting.

2008-04-17  Don Porter  <[email protected]>

	* generic/tkCanvas.c: [Bug 1327482]: Fix logic that determines when
	canvas item <Enter> event should fire. Thanks to Sebastian Wangnick.

2008-04-16  Daniel Steffen  <[email protected]>

	* generic/tkStubInit.c:			[Patch 1938497]: Make stubs
	* generic/tkWindow.c (Initialize):	tables static const and export
	only a module-scope pointer to to the main stubs table (for package
	init).

2008-04-14  Pat Thoyts  <[email protected]>

	* win/tkWinDialog.c:	[Bug 1941740]: Fix [tk_chooseColor -title].
	* win/tkWinTest.c:	Added parent to testgetwininfo
	* tests/winDialog.test:	Created some tk_chooseColor win tests.

2008-04-09  Jan Nijtmans  <[email protected]>

	* generic/tkImgGIF.c:	Let the GIF writer use a real LZW compressor.

2008-04-08  Pat Thoyts  <[email protected]>

	* win/ttkWinXpTheme.c:	Provide a visual-styles API element engine
	* tests/ttk/vsapi.test: to permit scripts to create any available
	* doc/ttk_vsapi.n:    windows xp/vista element. Plus basic tests.

2008-04-08  Daniel Steffen  <[email protected]>

	* generic/tkDecls.h:		make genstubs (genStubs.tcl changes).
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:

2008-04-08  Kevin Kenny  <[email protected]>

	* tkWinEmbed.c:	 Removed #if 0 code. Trust the revision control
	system, if you need it again, you can find it.

	* tkWinSend.c:	 Added conditional compilation to silence several
	compiler warnings.

2008-04-07  Jeff Hobbs  <[email protected]>

	* generic/tkWindow.c (Initialize): [Bug 1937135]: Fix double-free on
	* tests/main.test (main-3.*):	   Tk_ParseArgv error.

	* generic/tkArgv.c: Fix -help mem explosion. [Bug 1936238] (kenny)

2008-04-04  Pat Thoyts  <[email protected]>

	* library/ttk/sizegrip.tcl: Don't resize if the toplevel is not
	resizable or the sizegrip has been disabled.

2008-04-03  Pat Thoyts  <[email protected]>

	* win/makefile.vc:    Fixed stubs usage
	* library/ttk/xpTheme.tcl: fix the colour of labelframe in xp

2008-04-02  Daniel Steffen  <[email protected]>

	* generic/tk.decls:	Remove 'export' declarations of symbols now
				only in libtkstub and no longer in libtk.

	* generic/tkStubLib.c:	[Bug 1819422]: Make symbols in libtkstub.a
				MODULE_SCOPE to avoid exporting them from
				libraries that link with -ltkstub; constify
				tk*StubsPtr and stub table hook pointers.

	* generic/tkStubLib.c:	    Undef USE_TCL_STUBS before defining it
	* generic/ttk/ttkStubLib.c: unconditionally; remove needless #ifdef

	* generic/tkDecls.h:		make genstubs
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c:

	* unix/configure.in (Darwin):	Remove now unnecessary unexporting of
					libtclstub symbols from libtk.

	* unix/configure:		autoconf-2.59

2008-04-01  Don Porter  <[email protected]>

	* generic/tkStubLib.c (Tk_InitStubs):		Added missing error
	* generic/tkWindow.c (Tk_PkgInitStubsCheck):	message and removed
	needless #ifdef complexity.

	* generic/tkWindow.c:	[Tcl Bug 1819422]: Revised package init so
	* unix/Makefile.in:	that "tkStubsPtr" is not present in libtk.so,
	* win/Makefile.in:	but is present only in libtkstub.a. This
	* win/makefile.bc:	tightens up the rules for users of the stubs
	* win/makefile.vc:	interfaces.

	* README:		Bump version number to 8.6a0
	* generic/tk.h:
	* library/tk.tcl:
	* macosx/Wish-Common.xcconfig:
	* unix/configure.in:
	* unix/tk.spec:
	* win/README:
	* win/configure.in:
	* win/tcl.m4:

	* unix/configure:	autoconf-2.59
	* win/configure:

	* generic/tkConsole.c:	Relax Tcl_InitStubs() calls so that a Tk 8.6
	* generic/tkMain.c:	might [load] into a Tcl 8.5 interp.
	* generic/tkWindow.c:

	* generic/tkDecls.h:		make genstubs
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:

2008-03-28  Don Porter  <[email protected]>

	*** 8.5.2 TAGGED FOR RELEASE ***

	* README:		Bump to 8.5.2 for release.
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

	* changes:	Updates for 8.5.2 release.

2008-03-27  Jeff Hobbs  <[email protected]>

	* library/safetk.tcl (::safe::tkInterpInit): Make sure tk_library and
	its subdirs (eg, ttk) are on the "safe" access path.

2008-03-27  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (SunOS-5.1x): [Bug 1921166]: Fix 64bit support for Sun
	cc.

	* unix/configure: autoconf-2.59

2008-03-27  Daniel Steffen  <[email protected]>

	* generic/ttk/ttkStubLib.c:	Ensure tcl stubs are used in libtkstub
					even in a static build of Tk.
	* generic/ttk/ttkDecls.h:	Fix incorrect number of arguments in
					Ttk_InitStubs macro definition.

2008-03-26  Don Porter  <[email protected]>

	* changes:	Updates for 8.5.2 release.

	* unix/tkUnixCursor.c:	[Bug 1922466]: Stop crash in [. configure
	-cursor] on X11. Thanks to Emiliano Gavilán.

2008-03-26  Joe English  <[email protected]>

	* generic/tkInt.h, generic/tkEvent.c, unix/tkUnixEvent.c,
	* unix/tkUnixKey.c: XIM reorganization and cleanup; see
	[Patch 1919791] for details.

2008-03-21  Joe English  <[email protected]>

	* generic/tk.decls, generic/ttk/ttkStubLib.c, unix/Makefile.in:
	[Bug 1920030]: Keep ttkStubLib.o in libtkstub instead of libtk.

2008-03-20  Donal K. Fellows  <[email protected]>

	* tests/wm.test: Rewrote so that tests clean up after themselves
	rather than leaving that to the following test. Makes it easier to
	catch problems where they originate. Inspired by [Bug 1852338]

2008-03-19  Donal K. Fellows  <[email protected]>

	* doc/GetClrmap.3: [Bug 220809]: Documented Tk_PreserveColormap.

2008-03-17  Joe English  <[email protected]>

	* unix/Makefile.in, win/Makefile.in, win/makefile.vc: [Bug 1863007]:
	Put ttkStubLib.o in libtkstub instead of libtk.

2008-03-16  Donal K. Fellows  <[email protected]>

	* library/demos/goldberg.tcl: [Bug 1899664]: Made work when run twice
	in the same session. Also made the control panel use Ttk widgets.

2008-03-13  Daniel Steffen  <[email protected]>

	* unix/configure.in: [Bug 1913622]: Use backslash-quoting instead of
	* unix/tcl.m4:	     double-quoting for lib paths in tkConfig.sh.
	* unix/configure:    autoconf-2.59

2008-03-13  Don Porter  <[email protected]>

	* changes:	Updates for 8.5.2 release.

2008-03-12  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: Add support for Xcode 3.1
	* macosx/Wish.xcodeproj/default.pbxuser: CODE_SIGN_IDENTITY and
	* macosx/Wish-Common.xcconfig:		 'xcodebuild install'.

2008-03-12  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Try a fallback font if XftFontOpenPattern()
	fails in GetFont (workaround for [Bug 1090382]).

2008-03-11  Daniel Steffen  <[email protected]>

	* library/demos/knightstour.tcl:	Aqua GOOBE.
	* library/demos/widget:

	* macosx/Wish.xcodeproj/project.pbxproj: Add support for Xcode 3.1 and
	* macosx/Wish.xcodeproj/default.pbxuser: configs for building with
	* macosx/Wish-Common.xcconfig:		 gcc-4.2 and llvm-gcc-4.2.

	* generic/tkCanvUtil.c:			Fix gcc-4.2 warnings.

	* macosx/GNUmakefile:			Fix quoting to allow paths to
	* macosx/Wish-Common.xcconfig:		${builddir}, ${INSTALL_ROOT}
	* unix/Makefile.in:			and ${TCL_BIN_DIR} to contain
	* unix/configure.in:			spaces.
	* unix/install-sh:
	* unix/tcl.m4:

	* unix/configure:			autoconf-2.59

	* unix/Makefile.in (install-strip):	Strip non-global symbols from
						dynamic library.

2008-03-10  Don Porter  <[email protected]>

	* changes:	Updates for 8.5.2 release.

2008-03-07  Donal K. Fellows  <[email protected]>

	* doc/colors.n: Reworked to produce nicer HTML output.

2008-03-06  Joe English  <[email protected]>

	* doc/ttk_notebook.n: [Bug 1882011]: Move "TAB IDENTIFIERS" section
	above "WIDGET COMMAND" section.

2008-02-29  Pat Thoyts  <[email protected]>

	* library/demos/widget:	 Added a Knight's tour canvas demo.
	* library/demos/knightstour.tcl:

2008-02-27  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c: Workaround leak in Carbon SetPortPenPixPat()
	API [Bug 1863346]; avoid repeated PixPat allocation/deallocation.

2008-02-23  Joe English  <[email protected]>

	* library/ttk/combobox.tcl, doc/ttk_combobox.n,
	* tests/ttk/combobox.test: Arrange to deliver <<ComboboxSelected>>
	event after listbox is unposted, as intended [Bug 1890211]. Clarified
	documentation.

2008-02-23  Joe English  <[email protected]>

	* generic/ttk/ttkPanedWindow.c: [FRQ 1898288]: Don't enforce minimum
	sash thickness of 5 pixels, just use 5 as a default.

2008-02-14  Donal K. Fellows  <[email protected]>

	* unix/README: Documented missing configure flags.

2008-02-06  Donal K. Fellows  <[email protected]>

	* doc/ttk_scale.n (new file): [Bug 1881925]: Added basic documentation

2008-02-04  Don Porter  <[email protected]>

	*** 8.5.1 TAGGED FOR RELEASE ***

	* generic/tk.h:		Bump to 8.5.1 for release.
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2008-02-04  Donal K. Fellows  <[email protected]>

	* doc/MeasureChar.3, doc/FontId.3: Minor improvements (formatting,
	keywords).

2008-02-02  Daniel Steffen  <[email protected]>

	* macosx/Wish-Info.plist.in:	Add CFBundleLocalizations key, listing
	* unix/configure.in (Darwin):	all library/msgs locales.

	* unix/configure.in (Darwin):	Correct Info.plist year substitution
					in non-framework builds.

	* unix/configure:		autoconf-2.59

2008-02-01  Don Porter  <[email protected]>

	* changes:	Updates for 8.5.1 release.

2008-02-01  Reinhard Max  <[email protected]>

	* generic/tkImgGIF.c: Fixed a buffer overflow (CVE-2008-0553).
	* tests/imgPhoto.test: Added a test for the above.

2008-01-31  Jeff Hobbs  <[email protected]>

	* library/msgbox.tcl (::tk::MessageBox): Don't use ttk::label in low
	depth/aqua fallback, as it doesn't support -bitmap.

	* win/tkWinDialog.c (Tk_MessageBoxObjCmd): [Bug 1881892]: Pass ""
	instead of NULL when -title isn't set.

2008-01-31  Donal K. Fellows  <[email protected]>

	* doc/panedwindow.n: Added proper description of -height and -width
	options, which aren't "standard". Last of fallout from [Bug 1882495].

2008-01-30  Donal K. Fellows  <[email protected]>

	* doc/canvas.n, doc/listbox.n, doc/message.n: [Bug 1882495]: Fix
	erroneous listing of "standard" options.

2008-01-29  Joe English  <[email protected]>

	* library/treeview.tcl: Fix bug in Shift-ButtonPress-1 binding (error
	if no current focus item; reported on c.l.t.)

2008-01-29  Donal K. Fellows  <[email protected]>

	* doc/ttk_*.n: [Bug 1876493]: Adjusted handling of the standard
	options part of the Ttk manual pages so that they are documented in
	the correct location.

2008-01-28  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Re-fix strict-aliasing warnings reintroduced by
	last patch.

2008-01-27  Joe English  <[email protected]>

	* generic/ttk/ttkNotebook.c: [Bug 1878298]: Make sure to schedule a
	redisplay when adding and/or hiding tabs.

2008-01-27  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Merged common code from InitFont() and
	TkpGetFontAttrsForChar(), factored into GetTkFontAttributes() and
	GetTkFontMetrics(). Removed write-only struct UnixFtFont member
	'drawable'. Removed unneeded double-pointer indirections. Ensure that
	TkFontAttributes.family member is a Tk_Uid, as specified. Use
	FcTypeDouble for XFT_SIZE attribute. Finally: fix [Bug 1835848]

2008-01-25  Don Porter  <[email protected]>

	* changes:	Updates for 8.5.1 release.

2008-01-08  Joe English  <[email protected]>

	* generic/ttk/ttkFrame.c: [Bug 1867122]: fix crash in
	[ttk::labelframe] when -style option specified.

2008-01-08  Joe English  <[email protected]>

	* win/ttkWinTheme.c: [Bug 1865898]: Add tristate support to
	checkbuttons and radiobuttons.
	[Bug 1679067]: Fix check and radio indicator size.

2008-01-06  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c, generic/ttk/ttkWidget.h: Call
	Tk_MakeWindowExist() in widget constructor. Removed now-unnecessary
	initial ConfigureNotify processing.

2008-01-06  Joe English  <[email protected]>

	* library/ttk/treeview.tcl, library/ttk/utils.tcl:
	[Bugs 1442006, 1821939, 1862692]: Fix MouseWheel bindings for
	ttk::treeview widget.

2008-01-02  Don Porter  <[email protected]>

	* generic/tk.h:		Bump version number to 8.5.1b1 to distinguish
	* library/tk.tcl:	CVS development snapshots from the 8.5.0 and
	* unix/configure.in:	8.5.1 releases.
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf (2.59)
	* win/configure:

	******************************************************************
	*** CHANGELOG ENTRIES FOR 2005 TO 2007 IN "ChangeLog.2007"     ***
	*** CHANGELOG ENTRIES FOR 2004 AND 2003 IN "ChangeLog.2004"    ***
	*** CHANGELOG ENTRIES FOR 2002 AND EARLIER IN "ChangeLog.2002" ***
	******************************************************************

Added ChangeLog.2002.






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2002-12-27  David Gravereaux <[email protected]>

	* generic/tkText.h: ANSI unfriendly typedef for TkTextBTree
	repaired for C++ compilers.

2002-12-27  Joe English  <[email protected]>

	* unix/tkUnixWm.c (WaitForEvent): process Map and Unmap events
	as well as Configure events during WaitFor{Configure|Map}Notify.
	Fixes [Bug 578569] (WaitForMapNotify could process Map and Unmap
	events out of order, making Tk think a window was unmapped when
	it really wasn't).

2002-12-18  Todd M. Helfter  <[email protected]>

	* doc/label.n: Fixed documentation of the -compound option to
	the label widget.  The option was simply missing from the
	man page [Bug 577540]

2002-12-17  Donal K. Fellows  <[email protected]>

	* doc/photo.n: Fixed documentation of the put subcommand to no
	longer talk about files and to mention that you can use colour
	names for working with solid colours.  [Bug 640026]

2002-12-13  Don Porter <[email protected]>

	* generic/tkMain.c (Tk_Main):  Call on Tcl*StartupScript*() routines
	to store the startup script, if any.  [Bug 616245].

2002-12-10  David Gravereaux  <[email protected]>

	* win/makefile.vc: tclThreadTest.obj not required to link
	tktest.exe [Bug 651396]

2002-12-08  Jeff Hobbs  <[email protected]>

	* generic/tkEntry.c (ConfigureEntry): keep a flag to indicate when
	a var is traced to prevent double-traces caused by configuring the
	widget in traces with validation on. (dejong)

2002-12-07  Jeff Hobbs  <[email protected]>

	* generic/tkInt.decls: add TkWinSetHINSTANCE decl
	* generic/tkIntPlatDecls.h: regen
	* generic/tkStubInit.c: regen
	* win/tkWinInit.c (TkpInit):  While init and cleanup aren't correct
	* win/tkWinX.c (TkWinXInit):  in DllMain, we had to specify the
	* win/tkWin32Dll.c (DllMain): true HINSTANCE or the resources of a
	dynamic Tk weren't being loaded correctly.  Created a new function
	TkWinSetHINSTANCE for this purpose.

2002-12-06  Jeff Hobbs  <[email protected]>

	* win/tkWinX.c (TkWinXInit):      Move cleanup into an exit handler
	* win/tkWin32Dll.c (DllMain):     to ensure that it will be called
	* win/tkWinWm.c (TkWinWmCleanup): without having to unload the dll.
	Also reset the static int initialized on cleanup to allow reinit.

2002-12-01  Mo DeJong  <[email protected]>

	* tests/event.test (_keypress, _text_ind_to_x_y): Force focus to
	widget in _keypress method to avoid problems with window managers
	that use focus follows mouse. [Bug 526209]

2002-12-01  Mo DeJong  <[email protected]>

	* tests/wm.test: Add wm-transient-6.3 to check that a transient
	remains withdrawn when it is first withdrawn and then turned into
	a transient.
	* unix/tkUnixWm.c:
	* win/tkWinWm.c: Replace WM_TRANSIENT_WITHDRAWN with WM_WITHDRAWN
	and set this flag whenever a window is explicitly withdrawn. This
	fixes the test case added above. [Bug 644356]

2002-11-22  Jeff Hobbs  <[email protected]>

	* tests/textDisp.test:
	* generic/tkTextDisp.c (TkTextSeeCmd): handle see for unmapped
	text displays. [Bug #641778]

2002-11-19  Jim Ingham <[email protected]>

	* macosx/tkMacOSXScrlbr.c (TkpDisplayScrollbar): If the
	scrollbar width is set to 12 or less (but 12 is what you
	should use) use the small metric scrollbar.

	(UpdateControlValues): Fix thinko in setting off AUTO_ADJUST for
	the place geometry manager.

2002-11-19  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in: add macosx/*.tcl (buildTkConfig.tcl in
	particular) to the dist target.

2002-11-14  Mo DeJong  <[email protected]>

	* generic/tkWindow.c (Tk_DestroyWindow, DeleteWindowsExitProc):
	Add TkHalfdeadWindow type and halfdeadWindowList to keep track of
	windows that were only partially deallocated before a call to
	exit. Finish cleaning up these windows in DeleteWindowsExitProc.
	Keep track of cleanup status in Tk_DestroyWindow so that a window
	with a Destroy binding which calls exit will get fully destroyed.
	* tests/window.test: Add Tk_DestroyWindow tests for an assortment
	of half dead window cases. [Bug 630533]

2002-11-10  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: fixed erroneous
	removal of libtkstub before Wish was built.

2002-11-07  Mo DeJong  <[email protected]>

	* tests/unixWm.test: Add short delay to test unixWm-51.7
	to account for raise/lower changes in TIP 107. This allows
	the test case to pass under Window Maker on Linux.

2002-11-07  Peter Spjuth  <[email protected]>

	* tests/place.test:
	* generic/tkPlace.c: place info did not return all settings,
	and didn't make sure the result was a proper list.
	Put '-in' first in result to be more consistent with how
	grid/pack info behaves. [Bug #635025][Bug #532022]

2002-11-07  Daniel Steffen  <[email protected]>

	* unix/Makefile.in: added macosx/README to dist target.
	* macosx/Wish.pbproj/project.pbxproj: fix to 'wish' script
	to allow it to work when not installed into '/'.

2002-11-06  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen.
	* win/configure.in: Check that AR, RANLIB, and RC
	are found on the path when building with gcc.

2002-11-04  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: added Wish linker flag
	-headerpad_max_install_names to allow use of 'install_name_tool'.
	fixed tkConfig.sh generation and redo_prebinding in the case where
	Tk is not installed alongside Tcl.

2002-11-03  David Gravereaux <[email protected]>

	* win/winMain.c (Tcl_AppInit): Calls Registry_Init() and
	Dde_Init() when STATIC_BUILD and TCL_USE_STATIC_PACKAGES macros
	are set.

	* win/makefile.vc:  linkexten option now sets the
	TCL_USE_STATIC_PACKAGES	macro which also adds the registry and
	dde static lib files to the link of the shell. [Patch 479697]

	* win/rules.vc: Matches the one from Tcl.

	* win/buildall.vc.bat: More useful commentary.

2002-11-01  Andreas Kupries  <[email protected]>

	* win/makefile.vc (TCLREGLIBNAME): Updated to registry 1.1.

2002-10-29  Daniel Steffen  <[email protected]>

	* macosx/README: added info on new package searching in
	Frameworks directories.

2002-10-22  Jeff Hobbs  <[email protected]>

	*** 8.4.1 TAGGED FOR RELEASE ***

	* changes: updated for 8.4.1 release

2002-10-21  Daniel Steffen  <[email protected]>

	* macosx/README: revised according to Jim's suggestions
	* macosx/tkMacOSXAppInit.c: use standard PATH_MAX from <limits.h>

2002-10-18  Jeff Hobbs  <[email protected]>

	* win/winMain.c (WinMain, main): remove obsolete SetMessageQueue call

	* win/configure: Regen.
	* win/tcl.m4 (SC_CONFIG_CFLAGS): Check for bug in Cygwin version
	of windres and work around that case by passing a POSIX path
	instead of a Windows native path. One can't always pass a POSIX
	path because the mingw native toolchain accepts only Windows
	native paths. (dejong)

	* win/tkWinPort.h: define OPEN_MAX only if not defined.
	[Patch #625472] (howell)

2002-10-18  Daniel Steffen  <[email protected]>

	* mac/tkMacAppInit.c: removed tcltest dependency.
	[Bug #592639] (porter)

2002-10-17  Jeff Hobbs  <[email protected]>

	* tests/imgPhoto.test:
	* generic/tkImgPhoto.c (ImgPhotoConfigureMaster): fix arg handling
	for missing -format or -data options. [Bug #624974]

	* tests/text.test:		      properly return the number of
	* unix/tkUnixFont.c (ControlUtfProc): bytes consumed. [Bug #624732]

2002-10-17  Daniel Steffen  <[email protected]>

	* macosx/README: info specific to building and running
	TclTk on Mac OS X, answers to tcl-mac list FAQs.
	* macosx/Makefile: permission fix after embedded install.
	* macosx/Wish.pbproj/project.pbxproj: after install, fix
	permissions of uninstalled products.

2002-10-17  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: added TEXT document
	type to plist so that files can be dragged onto Wish Shell.

	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXFont.c: added private proc
	TkMacOSXUseAntialiasedText() to enable/disable quickdraw
	text antialiasing where available, default is enabled.
	Added a linked boolean ::tk::mac::antialiasedtext with
	write trace to allow control of antialiasing from tcl.

2002-10-16  Vince Darley  <[email protected]>

	* macosx/tkMacOSXMenu.c: fix to accelerators shown in menus
	with non-alphanumeric keys.
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c: applied first patch from [Patch
	#622582] to fix some of [Bug #616988].  Further work is needed
	in this area, but this will let foreign keyboards at least work
	reasonably with Tk.

2002-10-15  Jeff Hobbs  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: add AIX-5 ppc build support. Remove unused
	SC_ENABLE_MEMDEBUG.

	* win/configure:
	* win/tcl.m4: Add --enable-shared=mem support.

2002-10-10  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: The grid size was not updated properly
	when removing a widget from a grid. [Bug #621241] (forssen)

2002-10-10  Jeff Hobbs  <[email protected]>

	* tests/canvPs.test: tests for canvas embedded window ps generation
	* generic/tkCanvWind.c (CanvasPsWindow): removed dead code loop.
	* generic/tkCanvas.h: moved TkColormapData struct to tkCanvPs.c
	* generic/tkCanvPs.c (TkImageGetColor): corrected bogus use of
	TkColormapData on Windows (Windows now requires RGB pixel data
	from image).
	* win/tkWinImage.c (XGetImage, XGetImageZPixmap): added support
	for generating ps for embedded widgets on canvases on Windows,
	tested for 8, 16, 24 and 32-bit depths (XGetImageZPixmap not used).

	* library/tk.tcl: simplified the adding of extra <ISO_Left_Tab>
	and <hpBackTab> events to <<PrevWindow>>.

2002-10-09  Jeff Hobbs  <[email protected]>

	* unix/README: doc'ed --enable-symbols options.
	* unix/Makefile.in: comment docs
	* unix/configure: regen
	* unix/tcl.m4: replaced SC_ENABLE_MEMDEBUG with a more intelligent
	SC_ENABLE_SYMBOLS that takes yes|no|mem|all as options now.

2002-10-09  Don Porter <[email protected]>

	* generic/tk.h:  Added reminder comment to edit
	macosx/Wish.pbproj/project.pbxproj when version number changes.

2002-10-09  Daniel Steffen  <[email protected]>

	* macosx/Makefile: don't remove tclsh after building embedded.

	* macosx/Wish.pbproj/project.pbxproj: bumped version to 8.4.1;
	added missing library/mkpsenc.tcl to framework.

2002-10-09  Daniel Steffen  <[email protected]>

	* generic/tkInt.decls(tkIntXlib): added XQueryTree declaration for
	mac & aqua, since it's now called from ParentXId via Tk_HandleEvent.
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c: regen.
	* mac/tkMacXStubs.c: added XQueryTree stub

	* mac/tkMacEmbed.c (TkpUseWindow): check that container window
	has -container option set (sync with other platforms).

	* mac/tkMacBitmap.c:
	* mac/tkMacFont.c:
	* mac/tkMacSend.c:
	* mac/tkMacTest.c:
	* mac/tkMacWm.c: CONSTification.

	* mac/tkMacProjects.sea.hqx: added tkStyle.c and tkUndo.c to
	tk library projects.

2002-10-09  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoSetSize): Only error-out if we
	fail to allocate a non-empty buffer; getting a NULL when we
	allocate an empty buffer is no problem since nothing will look at
	the value anyway. [Bug 619544]
	Also tidied up file to take into account the fact that we're using
	32 bits per pixel in the master to accommodate the alpha channel
	as well as RGB.

2002-10-08  Jeff Hobbs  <[email protected]>

	* tests/winButton.test: add option clear to top to prevent option
	leakage from other tests causing problems. [Bug #582382]

	* generic/tkPanedWindow.c (Tk_PanedWindowObjCmd): leave the
	DestroyPanedWindow proc to free the pwPtr, add a Preserve
	reference to the pwPtr->tkwin.
	(DestroyPanedWindow): Release the pwPtr->tkwin.

	* generic/tkFocus.c (TkFocusFilterEvent): Ignore event if we are
	focusing into a dead window. [Bug #588831] (griffin)

2002-10-02  Jim Ingham  <[email protected]>

	* macosx/tkMacOSXScrlbr.c (TkpDisplayScrollbar): Put the Tk scrollbar
	pointer into the control reference data for the Mac scrollbar, so we
	can get it out again in the ScrollbarActionProc.

2002-10-02  Jeff Hobbs  <[email protected]>

	* generic/tkText.c (TextBlinkProc): don't blink the cursor unless
	it is visible. [Bug #616791] [Patch #614474] (bonfield)

	* tests/entry.test: added entry-20.7
	* generic/tkEntry.c (EntryTextVarProc): check if the entry is
	being deleted before handling an associated textvariable.
	[Bug #607390 #617446]

2002-10-01  Donal K. Fellows  <[email protected]>

	* tests/unixSelect.test (unixSelect-1.1[89]): Altered these tests
	to work around [Bug #616923]
	* unix/tkUnixSelect.c (SelRcvIncrProc,TkSelPropProc): It turns out
	a much simpler and more robust solution is possible if we leverage
	Tcl's encoding engine by using the same code path as for the
	normal string selection.  It might be a bit slower, but it should
	be a lot more correct.  [Bug #614650]

2002-09-30  Jeff Hobbs  <[email protected]>

	* tests/panedwindow.test: added panedwindow-28.[12]
	* generic/tkPanedWindow.c (PanedWindowCmdDeletedProc):
	(Tk_PanedWindowObjCmd): when destroying the panedwindow, destroy
	the proxy before the parent to avoid dependency conflicts.
	[Bug #616589]

2002-09-30  Donal K. Fellows  <[email protected]>

	* tests/unixSelect.test: Test for various things that can fail to
	work in 8.4.0...
	* unix/tkUnixSelect.c (TkSelPropProc,SelRcvIncrProc): Incremental
	transfers of UTF8_STRING selections should now work; Tk will now
	tag them with the right size and only transfer complete UTF8
	characters.  Previously, things only worked when the transfer
	could only happen in one go, and even then not always. [Bug 614650]

	* doc/bind.n: Doc-fix to mention that %A substitutes UNICODE
	characters rather than ASCII ones.  Tk's done this ever since 8.1
	in any case; after all, it is the right thing to do.

2002-09-27  Don Porter <[email protected]>

	* README:		Bumped to version 8.4.1 to avoid confusion
	* generic/tk.h:		of CVS snapshots with release 8.4.0.
	* unix/README:
	* unix/configure.in:
	* unix/tk.spec
	* win/configure.in:

	* unix/configure:	autoconf
	* win/configure:

2002-09-26  Jeff Hobbs  <[email protected]>

	* unix/configure: regen.
	* unix/tcl.m4: improve AIX-4/5 64bit compilation support.

	* unix/Makefile.in: add macosx subdir to dist target.
	Do not generate .Z, only .gz and .zip in alldist target.

2002-09-18  Mumit Khan  <[email protected]>

	Added basic Cygwin support.

	* win/tcl.m4 (SC_PATH_TCLCONFIG): Support one-tree build.
	(SC_PATH_TKCONFIG): Likewise.
	(SC_PROG_TCLSH): Likewise.
	(SC_CONFIG_CFLAGS): Assume real Cygwin port and remove -mno-cygwin
	flags.  Add -mwin32 to extra_cflags and extra_ldflags.
	Remove ``-e _WinMain@16'' from LDFLAGS_WINDOW.
	* win/configure: Regenerate.

	* win/tkWinPort.h (tchar.h): Do not include on Cygwin.
	(_T): Define for Cygwin.
	* win/winMain.c (main): Conditionally define.

2002-09-26  Daniel Steffen  <[email protected]>

	* macosx/Makefile: preserve environment value of INSTALL_ROOT.
	When embedding only use deployment build. Force relink before
	embedded build to ensure new linker flags are picked up.

	* macosx/buildTkConfig.tcl (new):
	* macosx/Wish.pbproj/project.pbxproj: synthesize tkConfig.sh
	based on tclConfig.sh in Tcl.framework and tkConfig.sh.in.
	Add symbolic links to debug lib, stub libs and tkConfig.sh
	in framework toplevel. Made tkIntXlibDecls.h a public header
	since Headers/X11/Xlib.h includes it. Install wish8.4 script
	that runs "Wish Shell.app" and corresponding wish link.
	Use tcl headers from built Tcl.framework instead of from tcl
	source directory.

	* macosx/tkMacOSXPort.h: added missing standard unix includes
	and defines, similarly to tkUnixPort.h.
	* macosx/tkMacOSXNotify.c: removed dependency on internal tcl
	header "tclPort.h"

	* unix/Makefile.in:
	* unix/install-sh: copied support for 'install-strip' target
	over from tcl/unix/{Makefile.in,install-sh}

2002-09-22  Jim Ingham <[email protected]>

	* macosx/tkMacOSXScrlbr.c (UpdateControlValue): HiliteControl
	doesn't give the proper "nothing to scroll" look on Mac OS X.
	You have to set the min value greater than the max value to
	get this.

2002-09-15  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.
	* unix/tkUnixEvent.c (TkpCloseDisplay): Use PEEK_XCLOSEIM
	to examine the input context queue before invoking
	XCloseIM. Generate an assert if there is an input
	context that has not been freed.
	[Patch 570902]

2002-09-13  Andreas Kupries  <[email protected]>

	* generic/tk.h: Moved RC_INVOKED down so that tcl.h is still
	included when running the resource compiler. <tcl.h> excludes the
	unnecessary parts on its own. This reenables the Windows build. It
	failed because the non-inclusion of tcl.h caused the resource
	compiler to miss some vital macro definitions (TCL_FINAL_RELEASE,
	STRINGIFY, ...).

2002-09-12  Daniel Steffen  <[email protected]>

	* generic/tk.h:
	* mac/tkMacApplication.r:
	* mac/tkMacLibrary.r:
	* mac/tkMacResource.r:
	* macosx/tkAboutDlg.r:
	* macosx/tkMacOSXApplication.r:
	* macosx/tkMacOSXLibrary.r:
	* macosx/tkMacOSXResource.r: unified use of the two equivalent
	resource compiler header inclusion defines RC_INVOKED and
	RESOURCE_INCLUDED, now use RC_INVOKED throughout.

	* macosx/tkMacOSXAppInit.c: improved detection of Wish startup
	by the finder (by checking if stdin is /dev/null), in which
	case we want to bring up the Tk console window.

	* macosx/tkMacOSXHLEvents.c: added 'rapp' apple event handler.

2002-09-12  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: reference & install
	tk/generic/prolog.ps instead of tk/library/prolog.ps.

2002-09-10  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: added backwards
	compatibility for OSX 10.1 ProjectBuilder 2.0.

2002-09-10  Daniel Steffen  <[email protected]>

	* unix/Makefile.in: added DYLIB_INSTALL_DIR variable for Darwin
	and set it to default value ${LIB_RUNTIME_DIR}
	* unix/tcl.m4 (Darwin): use DYLIB_INSTALL_DIR instead of
	LIB_RUNTIME_DIR in the -install_name argument to ld.
	* unix/configure: regen.

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Makefile: added support for building Tcl as an embedded
	framework, i.e. using an dyld install_name containing
	@executable_path/../Frameworks via the new DYLIB_INSTALL_DIR
	unix/Makefile variable.

2002-09-10  Jeff Hobbs  <[email protected]>

	*** 8.4.0 TAGGED FOR RELEASE ***

2002-09-09  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXNotify.c (Tk_MacOSXSetupTkNotifier): corrected
	Mac Jaguar event loop issue.

	* library/tk.tcl: use command instead of control on Aqua bindings.
	Force dialogs to appear below fixed native Mac menubar.
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c: Keypress/release events for pure
	modifier keys were not being passed to Tk.
	Deadkey presses were inserting null characters into text windows.
	Now they do nothing. (Still not ideal, but better than before!)
	* macosx/tkMacOSXMenu.c: Allow more than 200 menus to exist -
	increased to 2000.
	* macosx/tkMacOSXMouseEvent.c: Bad interactions between floating
	windows and ordinary ones.  Ensure that local<->global coordinate
	transformations are wrt to the correct window.
	* macosx/tkMacOSXWm.c: Better error msg for 'wm attributes'.
	Remove crash in 'wm transient'.
	Add 'noActivates' and 'noUpdates' flags to unsupported command.
	[Patch #606658] (darley)

	* library/xmfbox.tcl (::tk::MotifFDialog_ActivateSEnt): corrected
	msgcat code with XPG specifier. [Patch #606719] (miller)

2002-09-06  Don Porter <[email protected]>

	* tests/unixWm.test (unixWm-50.3):  Constrained test that hangs
	on Windows.

2002-09-05  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: added overlooked missing
	TK_PATCH_LEVEL version bump to 8.4.0.

2002-09-04  Andreas Kupries  <[email protected]>

	* win/Makefile.in (install-libraries): Added code section to
	install the message catalogs. Copied same section from
	unix/Makefile.in and adapted it to the slightly different
	environment.

2002-09-03  Jeff Hobbs  <[email protected]>

	* library/button.tcl: further restrict buttons to not resetting
	the "original" relief if it has changed in the interim.  This
	prevents code that simulated overrelief buttons from not working
	in 8.4.  [Bug #604270]

2002-09-03  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: Bumped version number to
	8.4.0 and updated copyright info.

2002-09-03  Vince Darley  <[email protected]>

	* macosx/tkMacOSXWm.c: fix to 'wm attributes' error-handling bug.

2002-09-03  Don Porter <[email protected]>

	* changes: Updated for 8.4.0 release

2002-09-02  Jeff Hobbs  <[email protected]>

	* tests/cursor.test: reverted 2002-08-31 change for OS X to use
	'heart' cursor because 'arrow' on windows has a pre-skewed use
	count. [Bug #602667]

	* tests/button.test: added button-14.1
	* win/tkWinButton.c (TkpComputeButtonGeometry): correct Win button
	sizing to be equal for one-line buttons with -height of 0 or 1, as
	well as -height 0 buttons with empty text and no image, which
	should be the same as single-line text buttons. [Bug #565485]

	* library/button.tcl (::tk::ButtonLeave): correctly restore state
	of button to normal for unix bindings. [Bug #597920]

	* doc/tk.n: added tk windowingsystem docs.

	* tests/wm.test:
	* unix/tkUnixWm.c: remove possible 2-second delay in 'raise'.
	[Patch #601518] (english) TIP #107

	* unix/tcl.m4: add support for 64-bit builds on HP-11 with gcc.
	* unix/configure.in: make sure to substitute LD_LIBRARY_PATH_VAR.
	* unix/configure: regend

	* README:		Bumped version number to 8.4.0
	* generic/tk.h:
	* unix/configure:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure:
	* win/configure.in:

	* generic/tkCmds.c:
	* generic/tkWindow.c: made 'tk' available in safe interpreters,
	but only the caret and windowingsystem subcommands may be called.
	* tests/safe.test (safe-1.2): noted that tk is now available in
	safe interps, but not the appname/scaling subcommands.

	* tests/tk.test (tk-1.2): noted new tk windowingsystem subcommand

2002-08-31  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: update from Tcl

	* unix/Makefile.in: import of TK_SHLIB_LD_EXTRAS for Tk library
	specific linker settings. Added use of new LD_LIBRARY_PATH_VAR.

	* unix/configure: regen

2002-08-31  Daniel Steffen  <[email protected]>

	*** macosx-8-4-branch merged into the mainline [tcl patch #602770] ***

	* generic/tk.decls:
	* generic/tkInt.decls: added new "aqua" specific entries to the
	stubs tables. Changed all "unix" entries to "x11" to allow us to
	distinguish and build both "aqua" on MacOSX and "x11" on MacOSX.

	* generic/tk.h: added a #ifnded RESOURCE_INCLUDED so that tk.h can
	be passed to the resource compiler.

	* generic/tkCmds.c (Tk_TkObjCmd): added [tk windowingsystem]
	subcommand: returns "x11" when running on X11, "win32" on Windows,
	"classic" on MacOS9 and "aqua" on MacOSX Aqua (i.e. Carbon)

	* generic/tkFont.c (TkFontGetFirstTextLayout): new private function
	returning the first chunk of a Tk_TextLayout, i.e. until the first
	font change on the first line (or the whole first line if there is
	no such font change).

	* generic/tkMain.c: made Tcl_ThreadDataKey static

	* library/demos/puzzle.tcl: fixed button metrics for aqua

	* tests/cursor.test: check for presence of arrow cursor instead of
	heart cursor

	* xlib/xcolors.c: changed xColors static initialization to more
	standard C

	* macosx/Wish.pbproj/jingham.pbxuser (new):
	* macosx/Wish.pbproj/project.pbxproj (new): project for Apple's
	ProjectBuilder IDE.

	* macosx/Makefile (new): simple makefile for building the project
	from the command line via the ProjectBuilder tool 'pbxbuild'.

	* macosx/tkMacOSXAppInit.c (new): macosx specific AppInit looking
	for a AppMain.tcl file in its bundled Resources/Scripts folder. If
	present, argv[1] is set to that file and the Scripts folder is
	added to the auto_path. This allows tk apps to embed scripts within
	their bundle directory structure.

	* macosx/tkMacOSXInit.c (new): macosx adapted version of
	tkUnixInit.c: we initialize & cache the Carbon native encoding
	(e.g. 'macRoman') and try to find the tk script library files
	inside Tk packaged as a framework.

	* macosx/tkMacOSXNotify.c (new): new macosx specific merged
	Carbon/select-based notifier.

	* macosx/tkMacOSXEvent.c (new):
	* macosx/tkMacOSXEvent.h (new):
	* macosx/tkMacOSXKeyEvent.c (new):
	* macosx/tkMacOSXMouseEvent.c (new):
	* macosx/tkMacOSXWindowEvent.c (new): new macosx specific event
	handling functionality.

	* macosx/tkMacOSX.h (new):
	* macosx/tkMacOSXBitmap.c (new):
	* macosx/tkMacOSXButton.c (new):
	* macosx/tkMacOSXClipboard.c (new):
	* macosx/tkMacOSXColor.c (new):
	* macosx/tkMacOSXConfig.c (new):
	* macosx/tkMacOSXCursor.c (new):
	* macosx/tkMacOSXDefault.h (new):
	* macosx/tkMacOSXDialog.c (new):
	* macosx/tkMacOSXDraw.c (new):
	* macosx/tkMacOSXEmbed.c (new):
	* macosx/tkMacOSXFont.c (new):
	* macosx/tkMacOSXHLEvents.c (new):
	* macosx/tkMacOSXInt.h (new):
	* macosx/tkMacOSXKeyboard.c (new):
	* macosx/tkMacOSXMenu.c (new):
	* macosx/tkMacOSXMenubutton.c (new):
	* macosx/tkMacOSXMenus.c (new):
	* macosx/tkMacOSXPort.h (new):
	* macosx/tkMacOSXRegion.c (new):
	* macosx/tkMacOSXScale.c (new):
	* macosx/tkMacOSXScrlbr.c (new):
	* macosx/tkMacOSXSubwindows.c (new):
	* macosx/tkMacOSXTest.c (new):
	* macosx/tkMacOSXUtil.c (new):
	* macosx/tkMacOSXUtil.h (new):
	* macosx/tkMacOSXWm.c (new):
	* macosx/tkMacOSXWm.h (new):
	* macosx/tkMacOSXXStubs.c (new): macosx ports of classic mac Tk
	implementation in tk/mac.

	* macosx/tkMacOSXSend.c (new): only send to local interp
	implemented currently.

	* macosx/tkMacOSXDebug.h (new):
	* macosx/tkMacOSXDebug.c (new): new macosx specific functions for
	debugging MacOS events, regions, etc.

	* macosx/tkAboutDlg.r (new):
	* macosx/tkMacOSXApplication.r (new):
	* macosx/tkMacOSXCursors.r (new):
	* macosx/tkMacOSXLibrary.r (new):
	* macosx/tkMacOSXMenu.r (new):
	* macosx/tkMacOSXResource.r (new):
	* macosx/tkMacOSXXCursors.r (new):
	* macosx/tclets.r (new): sources for Rez resource compiler.

	* macosx/Wish.icns (new): Wish application icon.

	* generic/tk.h:
	* generic/default.h:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkGrab.c:
	* generic/tkPointer.c:
	* generic/tkPort.h:
	* generic/tkSelect.c:
	* generic/tkStubLib.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkWindow.c:
	* unix/tkUnix3d.c:
	* xlib/xgc.c:
	* xlib/X11/X.h:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h: added #includes and #ifdefs for macosx

	* library/bgerror.tcl:
	* library/button.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/widget: check [tk windowingsystem] instead of
	and/or in addition to $tcl_platform(platform).

	* generic/tkInt.h:
	* mac/tkMacBitmap.c:
	* mac/tkMacWm.c: added missing CONSTification

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: regen

2002-08-27  D. Richard Hipp <[email protected]>

	* doc/checkbutton.n:      [Bug 582457] Fix the -offrelief option so
	* doc/radiobutton.n:      that when -offrelief is flat and -relief is
	* mac/tkMacButton.c:      sunken and -overrelief is raised, buttons
	* unix/tkUnixButton.c:    work look toolbar buttons under Windows.
	* win/tkWinButton.c:      See also: TIP #82.

2002-08-26  Don Porter <[email protected]>

	* win/Makefile.in:	Removed dependence on the (parts of) the
	* win/winMain.c:	tcltest executable on Windows.  It was not
	used, and the dependency complicated the Makefile.  [Bug 592638].

2002-08-20  Don Porter <[email protected]>

	* README:		Bumped version number to 8.4b3 to distinguish
	* generic/tk.h:		HEAD from the 8.4b2 release.
	* unix/configure.in:
	* win/configure.in:
	* unix/tk.spec:

	* unix/configure:	autoconf
	* win/configure:

	* generic/tk.h:	Added compile-time check that the tcl.h header file
	#included by Tk 8.4 is one from Tcl 8.4.  This is needed to be sure
	that new #defines like CONST84 are available. [Bug 597432].

2002-08-16  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (install-binaries): simplified pkgIndex.tcl
	file created on installation.
	* win/Makefile.in (install-binaries): corrected and simplified
	creation of pkgIndex.tcl file on installation.

2002-08-14  Vince Darley  <[email protected]>

	* win/tkWinDialog.c:
	* win/makefile.vc: broken compilation and link from changes
	Hobbs-08-07 fixed.
	* win/tkWinTest.c: CONST problem resolved.

2002-08-13  Jeff Hobbs  <[email protected]>

	* library/button.tcl: change the bindings to use Priv($w,relief)
	instead of just Priv(relief).  This ensures that neighboring
	buttons don't confuse (over)relief settings.

2002-08-13  Reinhard Max  <[email protected]>

	* unix/tkUnixSend.c (Tk_SetAppName): Fixed a compiler warning.

2002-08-12  Donal K. Fellows  <[email protected]>

	* library/demos/image2.tcl: Tweaked the behaviour of the directory
	box on resize, as resizing of the overall window tends to be
	common given the sample images.

2002-08-08  Mo DeJong  <[email protected]>

	* unix/tkUnixWm.c (WmTransientCmd): Apply fix for
	wm transient assertion error that was applied
	to tkWinWm.c for Tk Bug #592201.

2002-08-08  Mo DeJong  <[email protected]>

	* tests/wm.test: Add deleteWindows at start of
	new transient tests so they do not fail if the
	toplevels already exist.
	* unix/tkUnixWm.c: Revert patch for Tk Bug #592201
	which incorrectly removed numTransients member.

2002-08-08  Joe English  <[email protected]>

	* unix/tkUnixWm.c:
	* win/tkWinWm.c:
	* tests/wm.test: Fix for Tk Bug #592201 "wm transient fails with
	two masters"; fixes panic after a transient window is reassigned
	to new master and either master is subsequently destroyed.

2002-08-08  Don Porter <[email protected]>

	* tests/unixWm.test:  Corrected packaging of unixWm-50.3 so that
	[setupbg] and [cleanupbg] always balance, no matter what tests
	are skipped.

2002-08-08  Reinhard Max  <[email protected]>

	* unix/Makefile.in: Fixed typos in DISTNAME, and ZIPNAME.

2002-08-08  Jeff Hobbs  <[email protected]>

	*** 8.4b2 TAGGED FOR RELEASE ***

	* generic/tkButton.c (TkButtonWorldChanged): added GCFont handling
	to the disabledGc of buttons when compound != none.  The drawing
	appears to be incorrect across platforms still.  [Bug #477740]

	* generic/tkImgGIF.c (FileReadGIF): fixed -from handling for gifs
	[Bug #467524] (obermeier)

2002-08-07  Jeff Hobbs  <[email protected]>

	* generic/tkCanvUtil.c (TkSmoothParseProc): recognize the built-in
	bezier method by name. [Bug #578654]
	* doc/canvas.n: update to note that -smooth really doesn't take
	or return just booleans.

	* win/tkWinMenu.c (TkpSetWindowMenuBar): fixed logic bug in when
	to idle call ReconfigureWindowsMenu.

	* doc/GetBitmap.3: removed doc refs to deprecated
	Tk_GetBitmapFromData. [Bug #590379]

	* generic/tkPanedWindow.c (Tk_PanedWindowObjCmd):
	* library/panedwindow.tcl: changed class from PanedWindow to
	Panedwindow to not conflict with existing bwidgets, but also to be
	more regular with other names used in the core.

	* tests/panedwindow.test: added -text foobar to some test buttons
	to enable correct testing of panedwindow across platforms.
	[Bug #582370]

	* win/tkWinDialog.c: enabled use of the updated native Windows
	directory browser (tk_chooseDirectory).  This does require
	shell32.dll v4.71 or greater. [Patch #468139]

	* win/configure:
	* win/tcl.m4: added shell32 to libs for updated native Windows
	tk_chooseDirectory dialog.

2002-08-06  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (RESIZE_PENDING): Separated out flag for
	indicating that a resize needs to be issued.
	(PanedWindowReqProc): Do the old behaviour when the panedwindow is
	not mapped; easiest way of making the test suite pass while still
	preserving improved behaviour in the face of children whose size
	is not known immediately.

2002-08-06  Don Porter <[email protected]>

	* tests/defs.tcl: removed file.  No longer needed now that Tk is
	using the tcltest package to do its testing.

2002-08-05  Don Porter <[email protected]>

	* win/tkWinFont.c:	Additional changes to fix CONST warnings on
	* win/tkWinWM.c:	Windows due to latest patch.  Tks Vince Darley.

	* doc/3DBorder.3:	Applied companion patch for Tcl Patch 585105,
	* doc/BindTable.3:	updating Tk to use Tcl 8.4's fully CONST-ified
	* doc/ConfigWidg.3:	interface, and fully CONSTifying Tk at the
	* doc/CrtImgType.3:	same time.
	* doc/CrtWindow.3:
	* doc/DeleteImg.3:	This patch includes purging Tk of its last
	* doc/FindPhoto.3:	direct access to interp->result.  [Bug 589853]
	* doc/GetAnchor.3:
	* doc/GetBitmap.3:	The substantial changes include copying
	* doc/GetCapStyl.3:	event sequence strings into Tcl_DStrings
	* doc/GetClrmap.3:	in tkBind.c, and copying [text] indices into
	* doc/GetColor.3:	Tcl_DStrings because parsing them involved
	* doc/GetCursor.3:	overwriting them.  If this causes performance
	* doc/GetFont.3:	trouble, that can be resolved by further
	* doc/GetImage.3:	converting them to Tcl_Obj's.
	* doc/GetJoinStl.3:
	* doc/GetJustify.3:	The #defines USE_NON_CONST and USE_COMPAT_CONST
	* doc/GetOption.3:	have the same effect for Tk as they do for Tcl.
	* doc/GetRelief.3:	(They actually change tcl.h)
	* doc/GetScroll.3:
	* doc/GetVisual.3:
	* doc/InternAtom.3:
	* doc/NameOfImg.3:
	* doc/SetAppName.3:
	* doc/WindowId.3:
	* generic/tk.decls:
	* generic/tk.h:
	* generic/tk3d.c:
	* generic/tkAtom.c:
	* generic/tkBind.c:
	* generic/tkBitmap.c:
	* generic/tkButton.c:
	* generic/tkCanvArc.c:
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvPs.c:
	* generic/tkCanvText.c:
	* generic/tkCanvUtil.c:
	* generic/tkCanvWind.c:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h:
	* generic/tkClipboard.c:
	* generic/tkCmds.c:
	* generic/tkColor.c:
	* generic/tkConfig.c:
	* generic/tkConsole.c:
	* generic/tkCursor.c:
	* generic/tkDecls.h:
	* generic/tkEntry.c:
	* generic/tkFont.c:
	* generic/tkFrame.c:
	* generic/tkGet.c:
	* generic/tkGrid.c:
	* generic/tkImage.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkInt.decls:
	* generic/tkInt.h:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkListbox.c:
	* generic/tkMenu.c:
	* generic/tkMenubutton.c:
	* generic/tkMessage.c:
	* generic/tkOldConfig.c:
	* generic/tkOption.c:
	* generic/tkRectOval.c:
	* generic/tkScale.c:
	* generic/tkScrollbar.c:
	* generic/tkSelect.c:
	* generic/tkStyle.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkText.h:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkTextMark.c:
	* generic/tkTextTag.c:
	* generic/tkTextWind.c:
	* generic/tkUtil.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* mac/tkMacConfig.c:
	* mac/tkMacCursor.c:
	* mac/tkMacEmbed.c:
	* mac/tkMacSend.c:
	* unix/tkUnixConfig.c:
	* unix/tkUnixCursor.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixWm.c:
	* win/tkWinConfig.c:
	* win/tkWinCursor.c:
	* win/tkWinEmbed.c:
	* win/tkWinMenu.c:
	* win/tkWinSend.c:

2002-08-02  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (DestroyPanedWindow): Idle calls need to
	be deleted on destruction of the window, or things can *really* go
	pear-shaped.

2002-07-31  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (PanedWindowReqProc): Postpone pane
	arrangement until idle, as is done in other window managers, to
	fix problems with size calculations when the children don't
	already know their sizes anyway.

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2002-07-29  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Remove code that was setting
	CC_SEARCH_FLAGS and LD_SEARCH_FLAGS to try to
	account for cc vs ld linking. Tcl now handles this.
	* unix/tcl.m4: Update from Tcl.

2002-07-27  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Add MAJOR_VERSION, MINOR_VERSION,
	PATCH_LEVEL, INSTALL_LIBRARY, STUB_LIB_FILE, and LIB_FILE
	to support changes in tcl.m4 related to library builds.
	Use MAKE_LIB macro to avoid dealing with RANLIB issues.
	Rename TK_CC_SEARCH_FLAGS to CC_SEARCH_FLAGS and
	rename TK_LD_SEARCH_FLAGS to LD_SEARCH_FLAGS.
	Use new INSTALL_LIB and INSTALL_STUB_LIB substs to
	deal with ranlib issues when install libraries.
	* unix/configure: Regen.
	* unix/configure.in: Remove AC_PROG_RANLIB since
	this is done by tcl.m4 now. Define CC_SEARCH_FLAGS
	instead of TK_CC_SEARCH_FLAGS and so on.
	Use MAKE_LIB and MAKE_STUB_LIB from tcl.m4.
	Remove AC_SUBST calls that are no done in tcl.m4.
	* unix/tcl.m4: Update from Tcl.
	* unix/tkConfig.sh.in: Subst CC_SEARCH_FLAGS and
	LD_SEARCH_FLAGS.

2002-07-25  Peter Spjuth  <[email protected]>

	* generic/tkInt.h:
	* generic/tkWindow.c:
	* mac/tkMacWm.c:
	* unix/tkUnixWm.c:
	* win/tkWinWm.c:
	* tests/wm.test:
	* tests/winWm.test:
	* tests/unixWm.test: Objectifed wm. [Patch #564521]
	Note: At this point the Mac file is completely untested
	and may not even compile.

2002-07-25  Jeff Hobbs  <[email protected]>

	* tests/spinbox.test: added spinbox-22.[1-3]
	* generic/tkEntry.c (ConfigureEntry): made the textvariable value
	take precedence over changed -from/-to values, unless it must be
	constrained.  [Bug #559078]

	* library/spinbox.tcl (MouseSelect): when not in the entry, just
	return instead of invoking - ButtonUp handles invoking already.
	[Bug #499168]

	* library/tk.tcl (RestoreFocusGrab): handle the case where the
	FocusGrab info is not set. [Bug #553283]

2002-07-24  Jeff Hobbs  <[email protected]>

	* tests/canvas.test: added canvas-14.[1-6]
	* generic/tkCanvas.c (CanvasWidgetCmd): corrected handling of
	'scan' subcommand args.  Also removed early return cases to goto
	done instead where the canvasPtr would be Tcl_Release'd.  This may
	solve other problems with unreleased canvasPtr's. [Bug #581560]

	* win/tkWinButton.c (TkpDisplayButton): corrected display of focus
	ring around the actual text when the button is a compound button.
	[Bug #583691]

	* unix/README: Corrected notes about running user interactive Tk
	tests. [Bug #462320]

	* generic/tkText.c (TextEditUndo): set isDirtyIncrement to -1 when
	reverting to note proper "dirtiness". [Bug #580362] (callewaert)

	* generic/tkEntry.c (DisplayEntry): correct cursor position before
	calling Tk_SetCaretPos. (yamamoto)

2002-07-23  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2002-07-22  Mo DeJong  <[email protected]>

	* library/choosedir.tcl (tk::dialog::file::chooseDir):
	* library/clrpick.tcl (tk::dialog::file::chooseDir):
	* library/msgbox.tcl (tk::MessageBox):
	* library/tkfbox.tcl (tk::dialog::file):
	* library/xmfbox.tcl (tk::MotifFDialog):
	Revert [Tk patch 568278]. The transient window workaround
	is no longer needed since the fix for [Tk bug 570764]
	solved the problem for withdrawn transients.

2002-07-19  Mo DeJong  <[email protected]>

	* unix/configure:
	* unix/configure.in:
	* win/configure:
	* win/configure.in: Add AC_PREREQ(2.13) in an attempt
	to make it more clear that the configure scripts
	must be generated with autoconf version 2.13.
	[Tcl Bug 583573]

2002-07-19  D. Richard Hipp  <[email protected]>

	* library/mkpsec.tcl: Fix a bug that was causing postscript generation
	to fail under Win2K.

2002-07-18  Reinhard Max  <[email protected]>

	* unix/tkUnixSend.c: Using Tcl_GetTime instead of TclpGetTime.

2002-07-17  Reinhard Max  <[email protected]>

	* library/unsupported.tcl: Extended ExposePrivateVariable, and
	ExposePrivateCommand to accept patterns as well.

2002-07-17  Don Porter <[email protected]>

	* generic/tkFont.c: Corrected reversed logic in assert -> panic
	conversion.  [Bug 582799]

2002-07-16  Mo DeJong  <[email protected]>

	* generic/tkFont.c (TkFontPkgFree): Call panic instead
	of assert since assert is not used in the rest of Tk.
	[Tk bug 579651]

2002-07-16  Mo DeJong  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in: Add a more descriptive warning
	in the event `make genstubs` needs to be rerun.

2002-07-16  Vince Darley  <[email protected]>

	* win/tkWinWm.c:
	* doc/wm.n: fix for part of [Bug 581627], and made iconbitmap
	code on Windows more flexible about reading in icons [Bug
	220800].

2002-07-15  David Gravereaux <[email protected]>

	* win/makefile.bc (new): re-add of the borland makefile.  Submitted
	by Helmut Giese <[email protected]>.  This needs testing, still.

2002-07-15  Don Porter <[email protected]>

	* Fixes for [Bug 581627, 581795].
	* generic/tkTest.c:		Test commands not supported on non-Unix
	platforms should not be defined there in the first place.
	* tests/constraints.tcl:	Fixed "secureserver" constraint.
	* tests/unixWm.test:		Some tests needed "unix" constraint.
	* win/tkWinWm.c:		Typo in error message.

2002-07-14  Don Porter <[email protected]>

	* tests/event.test:	Fixes to enable testing of only userInteraction
	* tests/visual_bb.test:	tests.

	* README:		Bumped HEAD to version 8.4b2 in order to
	* generic/tk.h:		distinguish it from the 8.4b1 release.
	* unix/configure*:	Also extended LOCALES to cover all message
	* unix/tk.spec:		catalogs.
	* win/configure*:

	* tests/focustTcl.test:	Conversion bug: Corrected backwards logic.
	* tests/imgPhoto.test:	Conversion bug: overwrote unix/README.

	* tests/all.tcl:		Completed conversion of Tk test suite
	* tests/constraints.tcl:	to use tcltest.
	* tests/[b-v]*.test:
	* unix/Makefile.in:

2002-07-12  Don Porter <[email protected]>

	* tests/constraints.tcl:	Converted more files to tcltest and
	* tests/[g-x]*.test:		factored out common code.

2002-07-11  Don Porter <[email protected]>

	* tests/canvPsImg.tcl:			Converted several files in the
	* tests/constraints.tcl (new file):	Tk test suite for testing by
	* tests/[r-x]*.test:			tcltest 2.1.
	* unix/Makefile.in:

2002-07-11  Jeff Hobbs  <[email protected]>

	* win/tkWinDialog.c (Tk_ChooseDirectoryObjCmd): initialize
	utfTitle to NULL, add a few more notes about limitations of
	possible new Tk_ChooseDirectoryObjCmd function.

2002-07-11  Donal K. Fellows  <[email protected]>

	* tests/imgPhoto.test (imgPhoto-15.1): Added test of mem-alloc
	failure, but this is non-portable.
	* generic/tkImgPhoto.c (ImgPhotoSetSize): Allowed this function to
	fail when it can't allocate enough memory.  Note that not all the
	places that call it can fail nicely without API changes; some
	still panic but at least some of the potential failures are now
	handled gracefully.

	* tests/visual_bb.test (lpr): Stopped this from relying on
	external files; direct piping is much more flexible for this
	application.

2002-07-09  Don Porter <[email protected]>

	* generic/tkTest.c:	Removed unused dependence on TclThread_Init()
	* tests/defs.tcl:	and [testthread].  [Bug 578165, Tcl Bug 531413]

2002-07-08  David Gravereaux <[email protected]>

	* unix/Makefile.in: Added missing win/lamp.bmp to the dist
	target.

2002-07-05  Jeff Hobbs  <[email protected]>

	*** 8.4b1 TAGGED FOR RELEASE ***

2002-07-04  Donal K. Fellows  <[email protected]>

	* library/bgerror.tcl (bgerror): Stopped the bgerror dialog from
	getting wider than the screen; in theory really long messages
	could make it become taller than the screen now, but that's much
	less likely to happen.  Also trimmed a little bit of internal
	space so that the icon-message gap is the same as the icon-frame
	and message-frame gaps.

2002-07-01  Don Porter <[email protected]>

	* unix/configure:
	* unix/tcl.m4: Updated to latest tcl.m4 from Tcl.

2002-06-28  Donal K. Fellows  <[email protected]>

	* library/msgbox.tcl (MessageBox): Force all non-button widgets to
	have the same background as the containing toplevel.  [Bug #552515]

2002-06-27  Andreas Kupries  <[email protected]>

	* win/Makefile.in (install-binaries): Fix of troubled Makefile
	quoting introduced by [Patch 521356] causing the installed to
	fail.

2002-06-25  Don Porter <[email protected]>

	* unix/tkUnixFont.c: (Tk_DrawChars) silence compiler warning.

2002-06-26  David Gravereaux <[email protected]>

	* generic/tkStyle.c: <eol> of the committing cvs client didn't
	match the <eol> of the file itself.  Windows users where getting
	\r\r\n.  Problem fixed.

2002-06-26  Anton Kovalenko <[email protected]>

	* generic/tkFont.c (TkTextLayoutToPostscript): fixed potential
	buffer overflow which could be intentionally triggered from
	within safe interpreter -- malicious applet could modify
	tk::psglyphs array.

2002-06-26  Anton Kovalenko <[email protected]>

	* tests/font.test (font-32.1): updated this test
	to expect the new behavior of canvas postscript.

2002-06-25  Don Porter <[email protected]>

	* unix/Makefile.in:	Expanded install-binaries target to create
	* win/Makefile.in:	and install a pkgIndex.tcl file to enable
	Tk as a loadable package [Patch 521356]

2002-06-25  Anton Kovalenko <[email protected]>

	* library/mkpsenc.tcl: (added) utilities to generate
	Postscript prolog for current system encoding.
	* generic/tkCanvPs.c (TkCanvPostscriptCmd): now
	uses mkpsenc.tcl to generate Postscript prolog.
	* generic/tkFont.c (TkTextLayoutToPostscript): modified
	according to patch #546910. Now outputs system-encoded
	characters (for unibyte) or Adobe glyph names (for
	multibyte or outside-locale).
	* tests/canvText.test (canvText-17.1): updated this test
	to expect the new behavior of canvas postscript.

2002-06-25  Reinhard Max  <[email protected]>

	* unix/tcl.m4:       New macro SC_CONFIG_MANPAGES.
	* unix/configure.in: Added support for symlinks and compression
	* unix/Makefile.in:  when installing the manpages. [Patch 518052]
	Default is still hardlinks and no compression.

	* unix/mkLinks:      generated
	* unix/configure:

	* unix/README:       Added documentation for the new features.

	* unix/configure:                  Replaced ${exec_prefix}/lib
	* unix/tcl.m4 (SC_PATH_TCLCONFIG): by ${libdir}.

2002-06-24  Mo DeJong  <[email protected]>

	* tests/winWm.test: Verify that both an unmapped
	and already mapped toplevel are raised and receive
	the focus when deiconified.
	* tests/wm.test: Add wm deiconify tests. Check that
	a toplevel that has never been mapped is not mapped
	by the deiconify command since it should be done
	at idle by MapFrame.
	* win/tkWinWm.c (Tk_WmCmd): Check the WM_NEVER_MAPPED
	flag while processing the wm deiconify command.
	The WM_UPDATE_PENDING flag should never be set when
	WM_NEVER_MAPPED is set, but double check so that
	the implementation is more explicit and matches
	the comment just above.
	Return without invoking TkWmRestackToplevel or
	TkSetFocusWin on a toplevel that has never been
	mapped. This fixes a bug where a toplevel is mapped
	with the wrong size and is then resized by the
	idle call to MapFrame. [Tk bug 233150]

2002-06-23  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (UpdateGeometryInfo): remove the check for a null
	wrapper introduced in r1.41 on 2002-06-15 because it prevented
	geometry setting from taking effect if the window was not on the
	screen.  Another check may go in it's place as IsIconic and
	IsZoomed should not be passed NULL.

2002-06-22  Mo DeJong  <[email protected]>

	* tests/wm.test: Remove invalid minsize test. Add update
	calls to wm transient tests so that idle handlers get
	run. This is needed to get the tests to pass under Win32.
	* unix/tkUnixWm.c (WmWaitMapProc): Move the special
	transient withdrawn check into the if body to
	make it easier to set a breakpoint on this test
	inside a debugger. No functional changes.
	* win/tkWinWm.c (WmWaitVisibilityOrMapProc): Ditto.

2002-06-22  Jeff Hobbs  <[email protected]>

	* doc/wm.n:                   TIP #95 Windows implementation and
	* mac/tkMacWm.c (Tk_WmCmd):   docs with mac and unix stubs.
	* unix/tkUnixWm.c (Tk_WmCmd):
	* win/tkWinWm.c (Tk_WmCmd):
	* tests/unixWm.test:
	* tests/winWm.test: more wm attr tests will be needed.

	* generic/tkGrid.c (GridReqProc): check that gridPtr is not NULL
	(may be when embedded). [Bug #548791] (halliday)

	* generic/tkFont.c (TkFontPkgFree): changed panic on freeing fonts
	to an assert, and wrapped panic in #ifdef PURIFY. [Bug #568701]

	* library/menu.tcl: corrected menus from being posted offscreen
	on Windows. [Bug #464451] (darley)

	* library/console.tcl: corrected the defaultPrompt substitution
	[Bug #553207] and made Tab a default expansion key (like Escape).

	* win/tkWinEmbed.c (EmbedWindowDeleted): added a check for a null
	containerPtr.  The core of this bug is likely elsewhere. [Bug #476176]

	* doc/text.n:                             TIP #93 implementation that
	* generic/tkText.c (TextWidgetCmd):       enhances the text get and
	* generic/tkTextIndex.c (TkTextGetIndex): delete methods to accept
	* tests/text.test:                        multiple range pairs.
	This handles the delete case in an atomic, fixed-index fashion.

2002-06-21  Mo DeJong  <[email protected]>

	* tests/wm.test: Add tests to make sure a withdrawn
	transient does not get remapped by state changes
	in the master.
	* unix/tkUnixWm.c (Tk_WmCmd, WmWaitMapProc):
	* win/tkWinWm.c (Tk_WmCmd, WmWaitVisibilityOrMapProc):
	Add a WM_TRANSIENT_WITHDRAWN flag that gets set by the
	withdraw, deiconify, or state wm subcommands. Check
	this flag before mapping a transient when processing
	a MapNotify event. [Tk bug 570764]

2002-06-21  Donal K. Fellows  <[email protected]>

	* unix/tk.spec (version), README, win/configure.in, unix/configure.in:
	* generic/tk.h (TK_RELEASE_*, TK_PATCH_LEVEL): Bumped to beta1.

2002-06-21  Jeff Hobbs  <[email protected]>

	* doc/text.n:          TIP #104 implementation which generalizes the
	* generic/tkText.c:    undo/redo stack to not be tied solely to the
	* generic/tkText.h:    text widget.  The APIs are still private.
	* generic/tkUndo.c:    This also adds a stack limiting ability and
	* generic/tkUndo.h:    a -maxundo option to the text widget (in
	* library/text.tcl:    addition to the options from TIP #26) should
	* mac/tkMacDefault.h:  users want to limit the undo/redo stack
	* tests/text.test:     (should not be necessary in most cases).
	* unix/Makefile.in:    [Patch #554763] (callewart)
	* unix/tkUnixDefault.h:
	* win/Makefile.in:
	* win/makefile.vc:
	* win/tkWinDefault.h:

2002-06-21  Don Porter <[email protected]>

	* unix/Makefile.in:	Removed unnecessary dependence of tktest
	* unix/tkAppInit.c:	executable on the tcltest executable on
	Unix.  If there are similar dependencies on other platforms, they
	can probably be removed as well.  [Bug 572134].

2002-06-20  Jeff Hobbs  <[email protected]>

	* doc/listbox.n:
	* generic/tkListbox.c (DisplayListbox):
	* mac/tkMacDefault.h:   TIP #94 implementation adding -activestyle
	* tests/listbox.test:   option to the listbox.  This adds the ability
	* unix/tkUnixDefault.h: to have listboxes look native on Windows, and
	* win/tkWinDefault.h:   "nicer" elsewhere using the 'dotbox' style.

2002-06-20  Peter Spjuth  <[email protected]>

	* generic/tkGrid.c: Corrected the test for grid propagate change.
	[Bug #571433]

2002-06-19  Jeff Hobbs  <[email protected]>

	* tests/panedwindow.test:
	* generic/tkPanedWindow.c: ensure that sash index is lower bounds
	checked. [Bug #548727]

2002-06-19  Mo DeJong  <[email protected]>

	* generic/tkClipboard.c (TkClipCleanup): Add code
	to set dispPtr->clipWindow to NULL, this was
	accidently removed by last commit. Fixes
	a crash while running the tests under win32.

2002-06-19  Mo DeJong  <[email protected]>

	* generic/tkBind.c (TkBindDeadWindow):
	Handle case where Tk_DestroyWindow is invoked
	on clipboard and send windows.
	* generic/tkClipboard.c (TkClipCleanup):
	Invoke Tk_DestroyWindow to cleanup the
	dispPtr->clipWindow. Call Tcl_Preserve
	and Tcl_Release on the window to avoid an
	invalid memory ref on shutdown.
	* generic/tkEvent.c (Tk_HandleEvent):
	Panic if XCreateIC is invoked twice for
	the same window. This should never happen,
	the check were just added to make sure it
	does not since this could lead to crashes
	in XCloseIM.
	* generic/tkFocus.c (TkFocusDeadWindow):
	Handle case where Tk_DestroyWindow is invoked
	on clipboard and send windows.
	* generic/tkOption.c (TkOptionDeadWindow): Ditto.
	* generic/tkWindow.c (TkCloseDisplay): Move
	deletion of dispPtr->winTable after TkpCloseDisplay
	call since Tk_DestroyWindow uses it and could
	be called by TkpCloseDisplay for clipboard/send windows.
	Also invoke ckfree for the dispPtr instead of
	doing it in TkpCloseDisplay.
	(Tk_DestroyWindow): Check for a null winPtr->mainPtr
	before doing certain cleanup tasks so the we can
	invoke Tk_DestroyWindow on clipboard and send windows.
	We need to do this so that XDestroyIC will get invoked
	for the input contexts of each window.
	* mac/tkMacXStubs.c (TkpCloseDisplay): Don't free
	the displayPtr since this is now done in TkCloseDisplay.
	* unix/tkUnixEvent.c (TkpCloseDisplay, OpenIM): Remove
	conditional compilation around calls to XCloseIM
	since I am confident that the crashes related to
	input contexts has been fixed. Don't free
	the displayPtr since this is now done in TkCloseDisplay.
	* unix/tkUnixSend.c (TkSendCleanup): Invoke the
	Tk_DestroyWindow method to cleanup the special
	send window. This will call XDestroyIC and thereby
	avoid a crash in XCloseIM. The send window needs
	to be Tcl_Preserve and Tcl_Release to avoid an
	invalid memory ref on shutdown.
	* win/tkWinX.c (TkpCloseDisplay): Don't free
	the displayPtr since this is now done in TkCloseDisplay.
	[Tk patch 570902]

2002-06-19  Donal K. Fellows  <[email protected]>

	* generic/tkStyle.c: TIP#48 style engine.
	See http://purl.org/tcl/tip/48.html for details.

	* generic/tkConfig.c (GetOptionFromObj): Split to allow for access
	to option tables via name as well as via object.
	(TkGetOptionSpec): Semi-public interface to GetOption functionality.
	(DoObjConfig, Tk_RestoreSavedOptions, FreeResources)
	(GetObjectForOption): Basic style support for configure.

	* generic/tkWindow.c (TkCreateMainWindow, Tk_DestroyWindow): Added
	calls to set up and tear down the style subsystem.

	* generic/tk.decls, generic/tk.h: Many declarations forming TIP#48
	public interface.

	* generic/tkInt.decls (TkStylePkgInit,TkStylePkgFree):
	* generic/tkInt.h (TkGetOptionSpec): Supporting declarations.

	* unix/Makefile.in, win/Makefile.in, win/makefile.vc: Added
	tkStyle.c to list of generic source files.

2002-06-18  Donal K. Fellows  <[email protected]>

	* tests/defs.tcl (makeFile): Defined the return value of this
	procedure to be the filename of the created file, as in the real
	tcltest package...

2002-06-17  Mo DeJong  <[email protected]>

	* generic/tkImage.c (Tk_ImageObjCmd, DeleteImage): Call
	Tcl_Preserve and Tcl_Release for the masterPtr->winPtr
	window to avoid accessing memory that had already
	been deallocated in DeleteImage.

2002-06-17  David Gravereaux <[email protected]>

	Trims to support the removal of RESOURCE_INCLUDED from rc
	scripts from Tcl's accepted FR #565088.

	* generic/tk.h: Changed RESOURCE_INCLUDED to be RC_INVOKED
	as the RC tool defines this already by default.

	* win/rc/tk.rc:
	* win/rc/wish.rc: removed the #define RESOURCE_INCLUDED lines.

2002-06-17  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (dist): correct installation of
	wish.exe.manifest to DISTDIR target directory.

	* generic/tkCmds.c (Tk_TkObjCmd):
	* generic/tkInt.h (struct TkCaret):
	* mac/tkMacXStubs.c (Tk_SetCaretPos):
	* unix/tkUnixKey.c (TkpGetString, Tk_SetCaretPos):
	* win/tkWinX.c (Tk_SetCaretPos):
	* tests/tk.test:        Added 'tk caret' implementation of TIP#96
	* doc/SetCaret.3 (new): which adds a TkCaret structure element to
	* doc/tk.n:             TkDisplay for maintaining state.

	* unix/tkUnixSend.c (TkSendCleanup): special cleanup of
	inputContext to avoid bug in XCloseIM. (dejong)

2002-06-17  Don Porter <[email protected]>

	* library/msgs/en_gb.msg:  Added catalog for UK English.
	Currently includes only Color -> Colour translation.

2002-06-17  D. Richard Hipp  <[email protected]>

	* doc/checkbutton.n:
	* doc/radiobutton.n:
	* generic/tkButton.c:
	* generic/tkButton.h:
	* mac/tkMacButton.c:
	* tests/button.test:
	* unix/tkUnixButton.c:
	* win/tkWinButton.c: Implementation of TIP#82 - Added the
	-offrelief option to checkbutton and radiobutton.

2002-06-14  Mo DeJong  <[email protected]>

	* generic/tkWindow.c (Tk_DestroyWindow): Set the pathName
	component of a window to NULL after its memory has been
	deallocated to avoid a possible illegal memory access
	as a result of a call to Tk_PathName() on a Tk_Window
	structure of a window that has already been destroyed.
	[Tk bug 521946]

2002-06-14  Mo DeJong  <[email protected]>

	* generic/tkOption.c (Tk_GetOption): Allocate
	memory with ckalloc not malloc. This keeps
	Tk from erroring out when built with
	TCL_MEM_DEBUG.

2002-06-14  Jeff Hobbs  <[email protected]>

	* generic/tkBind.c (HandleEventGenerate):
	* generic/tkInt.h: changed warpInProgress boolean from int to a
	bit in the flags variable (TK_DISPLAY_IN_WARP)

	* generic/tkCmds.c (Tk_TkObjCmd):
	* unix/tkUnixKey.c (TkpGetString):
	* generic/tkEvent.c (Tk_HandleEvent):
	* generic/tkInt.h: changed useInputMethods boolean from int to a
	bit in the flags variable (TK_DISPLAY_USE_IM)

	* generic/tkInt.h:
	* generic/tkCmds.c (Tk_WmObjCmd):
	* unix/tkUnixWm.c (Tk_WmCmd):
	* win/tkWinWm.c (Tk_WmCmd): changed wmTracing from being an int to
	just a bit in the flags variable (TK_DISPLAY_WM_TRACING)

	* generic/tkEvent.c (Tk_HandleEvent):
	* unix/tkUnixEvent.c (OpenIM):
	* unix/tkUnixKey.c (TkpGetString):
	* generic/tkInt.h: added TK_DISPLAY_XIM_SPOT flag bit for TkDisplay
	and used this to allow a runtime check to see if over-the-spot XIM
	is possible.  If not it will try and fallback to the old-style
	input context, which handles things like dead keys input.

	* generic/tk.decls:     added TIP #84 implementation that adds a
	* generic/tkDecls.h:    Tk_CollapseMotionEvents API which controls Tk's
	* generic/tkEvent.c:    collapsing of incoming motion events on its
	* generic/tkInt.h:      windows.  The default remains to do collapsing.
	* generic/tkStubInit.c: Added a flags parameter to the internal display
	* generic/tkWindow.c:   structure to support this and be used in the
	* doc/QWinEvent.3:      future for other bits. [Tk patch 564642]

	* unix/mkLinks: updated from current docs

2002-06-14  Mo DeJong  <[email protected]>

	* generic/tkEvent.c (TkXErrorHandler): Declare static
	function to avoid compiler error with VC++.
	* generic/tkBind.c (ExpandPercents): Cast argument to
	Tk_GetAtomName in order to avoid compiler warning.

2002-06-14  Joe English  <[email protected]>

	* doc/bind.n:
	* generic/tk.h:
	* generic/tkBind.c:
	* generic/tkCanvWind.c:
	* generic/tkCmds.c:
	* generic/tkEvent.c:
	* generic/tkFocus.c:
	* generic/tkGrab.c:
	* generic/tkGrid.c:
	* generic/tkImage.c:
	* generic/tkPack.c:
	* generic/tkPlace.c:
	* generic/tkPointer.c:
	* generic/tkTextWind.c:
	* generic/tkWindow.c:
	* mac/tkMacSubwindows.c:
	* mac/tkMacWindowMgr.c
	* mac/tkMacWm.c:
	* unix/Makefile.in:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixWm.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWindow.c:
	* win/tkWinWm.c: Implementation of TIP #47 by Neil McKay
	"Modifying Tk to Allow Writing X Window managers".
	Add CirculateRequest, Create, MapRequest, ResizeRequest,
	and ConfigureRequest event types;
	Split TK_TOPLEVEL flag into TK_TOPLEVEL, TK_HAS_WRAPPER,
	TK_WIN_MANAGED, and TK_TOP_HIERARCHY. [Tk patch 572978]

2002-06-14  Andreas Kupries  <[email protected]>

	* unix/tkAppInit.c: Removed now unneeded and erroneous reference
	to 'matherr'. See Tcl ChangeLog entry 2002-05-31 Don Porter.

2002-06-14  David Gravereaux <[email protected]>

	* win/rules.vc: The test for compiler optimizations was in error.
	Thanks goes to Roy Terry <[email protected]> for his
	assistance with this.

2002-06-14  Donal K. Fellows  <[email protected]>

	Implement TIP 98  [Tk patch 566765]

	* doc/FindPhoto.3, generic/tk.h, generic/tk.decls:
	* generic/tkImgPhoto.c: Changed *_Old to *_NoComposite and
	USE_OLD_PHOTO_PUT_BLOCK to USE_COMPOSITELESS_PHOTO_PUT_BLOCK
	following a suggestion from Don Porter.

	* tests/imgPhoto.test: Added tests of -compositingrule

	* doc/photo.n: Added documentation for "-compositingrule".
	* generic/tkImgPhoto.c (ImgPhotoCmd, ParseSubcommandOptions): New
	"-compositingrule" option for [$photo copy] subcommand, using
	OPT_COMPOSITE flag and compositingRule field in SubcommandOptions
	structure.

	* doc/FindPhoto.3: Documented the extra argument for the
	compositing rule and the action to take if anyone wants to
	maintain total backward-compatability.

	* generic/tk.h (TK_PHOTO_COMPOSITE_*): Defined values for use as
	compositing rules.
	(USE_OLD_PHOTO_PUT_BLOCK): Added a way for users to select the old
	interface to Tk_PhotoPutBlock to provide an easier upgrade path.

	* generic/tk.decls: Alter Tk_PhotoPut*Block to Tk_PhotoPut*Block_Old
	and introduce new slots for the old name of function with an extra
	argument at the end for the compositing rule.

	* generic/tkImgPhoto.c (ImgPhotoCmd): Updated "transparency set"
	subcommand to use TkSubtractRegion().

	* win/tkWinRegion.c (TkSubtractRegion):
	* mac/tkMacRegion.c (TkSubtractRegion):
	* generic/tkInt.decls (TkSubtractRegion):
	* unix/tkUnixPort.h (TkSubtractRegion): Added function to perform
	the set-difference operation on regions; it seems all platforms
	can support it, and it makes removing rectangular bits from
	regions much easier.

	* generic/tkImgPPM.c (FileReadPPM): Reading a PPM/PGM always uses
	the SET compositing rule because it is faster and the format does
	not have any transparency information.

	* generic/tkImgGIF.c (FileReadGIF): Reading a GIF always uses the
	SET compositing rule because GIF files model transparency as a
	single special colour.

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock):
	Added a compositing rule to allow better control over what happens
	to transparent pixels when inserting data into a photo image.

2002-06-13  Mo DeJong  <[email protected]>

	* tests/winfo.test: Add basic tests for winfo ismapped.

2002-06-13  Mo DeJong  <[email protected]>

	* tests/unixWm.test:
	* tests/wm.test: Move wm minsize and wm maxsize
	usage tests into the cross platform wm tests.

2002-06-13  Don Porter <[email protected]>

	* tests/cursor.test:  corrected error after cursor-2.2.
	* tests/defs.tcl: Added enhancements to Tk's fake version of
	tcltest required by recent cursor.test changes.

2002-06-13  Donal K. Fellows  <[email protected]>

	* tests/cursor.test (cursor-2.[34]): Tests added to ensure that
	cursor specs really are well-behaved lists.  Also some general
	clean-up...
	* win/tkWinCursor.c (TkGetCursorByName): Undone Jeff's back-off
	and fixed things so that they should work now.  Cursor specs are
	lists first and foremost.

2002-06-12  Mo DeJong  <[email protected]>

	* changes: Clearly label wm transient changes as
	a POTENTIAL INCOMPATIBILITY.
	* doc/wm.n: Remove "some window managers will" text
	and explicitly state what behavior a transient
	window will display. Also mention that it is an
	error to make a window a transient of itself.

2002-06-12  Mo DeJong  <[email protected]>

	* library/choosedir.tcl (tk::dialog::file::chooseDir):
	* library/clrpick.tcl (tk::dialog::file::chooseDir):
	* library/msgbox.tcl (tk::MessageBox):
	* library/tkfbox.tcl (tk::dialog::file):
	* library/xmfbox.tcl (tk::MotifFDialog): Remove the
	transient property on dialogs after they have been
	dismissed to insulate them from further state changes
	in the master. This keeps a withdrawn dialog from
	being mapped when the master is deiconified. [Tk patch 568278]

2002-06-12  Jeff Hobbs  <[email protected]>

	* win/tkWinCursor.c (TkGetCursorByName): reverted fix from
	2002-06-06 because it broke the ability to use built-in cursors
	like left_ptr.

2002-06-12  Mo DeJong  <[email protected]>

	* library/choosedir.tcl (tk::dialog::file::chooseDir):
	* library/clrpick.tcl (tk::dialog::color):
	* library/dialog.tcl (tk_dialog):
	* library/msgbox.tcl (tk::MessageBox):
	* library/tkfbox.tcl (tk::dialog::file):
	* library/xmfbox.tcl (tk::MotifFDialog_Create):
	Only make the dialog window a transient if
	the master is visible. This check already
	appeared in some of the dialogs. This patch
	just copies the check into those that were
	lacking. [Tk patch 568253]

2002-06-12  Mo DeJong  <[email protected]>

	* changes: Add note about new transient behavior.
	* tests/unixWm.test: Check that the WM_TRANSIENT_FOR
	property for a transient window is being cleared
	when the master is destroyed.
	* tests/wm.test: Source defs.tcl instead of using
	tcltest to match the rest of Tk's test files.
	Add new tests that ensure that a transient's state
	mirrors the state of the master.
	* unix/tkUnixWm.c (WmInfo, TkWmNewWindow, TkWmMapWindow)
	(TkWmDeadWindow, Tk_WmCmd, WmWaitMapProc): Add numTransients
	member to WmInfo structure. Keep state of master and
	transient in sync using a callback that tracks MapNotify
	and UnmapNotify events. When the master is mapped, map
	the transient. When the master is unmapped or iconified,
	withdraw the transient.
	* win/tkWinWm.c (TkWmMapWindow, TkpWmSetState)
	(TkWmDeadWindow, Tk_WmCmd, WmWaitVisibilityOrMapProc):
	Keep state of master and transient in sync using a
	callback that tracks MapNotify and UnmapNotify events.
	Move masterPtr check from TkpWmSetState into TkWmMapWindow
	to deal with WM_NEVER_MAPPED transients. Cleanup
	numTransients and the callback in TkWmDeadWindow.
	Cleanup numTransients and the callback only after
	deleting a master in wm transient command to avoid
	deleting the callback when an error is raised.
	Add support for MapNotify and UnmapNotify events
	to the master callback. [Tk patch 561708]

2002-06-11  Joe English  <[email protected]>

	* library/menu.tcl: fix for bug report #530212 "Bad Window Path
	Name in tkMenuFind"

2002-06-10  David Gravereaux <[email protected]>

	* win/makefile.vc: Fixed a win98 issue where the /exclude option
	for xcopy is unsupported.
	Reported by Roy Terry <[email protected]>.

2002-06-10  Anton Kovalenko <[email protected]>

	* library/tk.tcl: added utility functions to get "-underline" and
	"-text" for labels and buttons from translatable string containing
	"magic ampersand" [patch #566605]
	* library/clrpick.tcl:
	* library/msgbox.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl: some places where msgcat is used to get
	translated label are modified to handle labels with magic ampersand.
	* library/msgs/ru.msg: russian translations added
	* library/msgs/cs.msg:
	* library/msgs/de.msg:
	* library/msgs/el.msg:
	* library/msgs/es.msg:
	* library/msgs/fr.msg:
	* library/msgs/it.msg:
	* library/msgs/nl.msg: all translation files now have labels with
	'magic ampersand' where appropriate. In el.msg some ampersands are
	missing, as I don't know which underline positions seems natural
	to "el" users.

2002-06-09  Mo DeJong  <[email protected]>

	* library/bgerror.tcl (tk::dialog::error::bgerror):
	Don't set the bgerror dialog as a transient of
	itself since this operation is ill defined.

2002-06-06  Donal K. Fellows  <[email protected]>

	* win/tkWinCursor.c (TkGetCursorByName): Fixed so that the reading
	of cursors from a file with a cursor spec was built using [list]
	works when the file has a space in instead of requiring fiddling
	with backslashes.

2002-06-06  Anton Kovalenko <[email protected]>

	* library/msgbox.tcl (MessageBox): Add -default normal
	when creating non-default buttons for message box.
	They already get -default normal when they're
	unfocused, and dialog window size used to change suddenly
	in such cases.

2002-06-05  Anton Kovalenko <[email protected]>

	* unix/tkUnixFont.c (Tk_DrawChars): Don't assume that
	one char is always one byte, and that required
	subfont for the last character in any string is
	the same as for the previous character
	[Bug #559435] [Patch #559437]

2002-05-27  Mo DeJong  <[email protected]>

	* changes: Document [wm transient .t .t] error.
	* tests/wm.test: Check that setting a window
	as a transient of itself raises an error. Check
	that passing a non-toplevel window to the wm
	transient command uses the enclosing toplevel.
	* unix/tkUnixWm.c (Tk_WmCmd): Raise an error
	if the user tries to make a toplevel a
	transient of itself.
	* win/tkWinWm.c (Tk_WmCmd): Raise an error
	if the user tries to make a toplevel a
	transient of itself. Test for other error
	before checking for the transient self error.

2002-05-27  Mo DeJong  <[email protected]>

	* unix/tkUnixWm.c (WmInfo, TkWmCleanup, TkWmNewWindow)
	(TkWmMapWindow, TkWmDeadWindow, Tk_WmCmd): Replace
	WmInfo's master and masterWindowName members with
	a masterPtr member. This implementation is much
	simpler and mirrors the Win32 implementation. This
	change makes it easy to check the flags of the
	master window. No user visible changes.

2002-05-27  Mo DeJong  <[email protected]>

	* generic/tkInt.decls: Add unix decl for TkpWmSetState.
	* generic/tkIntPlatDecls.h: Regen.
	* generic/tkStubInit.c: Regen.
	* tests/wm.test: Test state changes between iconic,
	normal, and withdrawn both before and after initial
	mapping.
	* unix/tkUnixWm.c (Tk_WmCmd, TkpWmSetState): Move
	state change code into TkpWmSetState to more closely
	match the Win32 implementation. No user visible changes.

2002-05-27  Mo DeJong  <[email protected]>

	* tests/embed.test: Added cross platform embed tests.
	Check that window passed to -use has the -container
	option set.
	* tests/wm.test: Remove useless catch call. Deiconify
	. just in case, stackorder tests will not pass unless
	it is in the normal state. Add -container flag to
	embedded stackorder test.
	* unix/tkUnixEmbed.c (TkpUseWindow):
	* win/tkWinEmbed.c (TkpUseWindow): Lookup Tk window
	based on the id passed in as the value for -use.
	Generate an error if the Tk window did not have
	the -container option set.

2002-05-26  Peter Spjuth <[email protected]>

	* generic/tkButton.c (ConfigureButton): When creating
	a radiobutton with -value "" it was not drawn properly
	if the -variable was created by the radiobutton.
	[Bug #548765]

2002-05-26  Peter Spjuth <[email protected]>

	* generic/tkCanvText.c (ComputeTextBbox): Negative
	coordinates were rounded badly causing a 1 pixel
	displacement. [Bug #556526]

2002-05-24  Mo DeJong  <[email protected]>

	* mac/tkMacWm.c (Tk_WmCmd):
	* tests/unixWm.test: Move wm transient checks over
	to wm.test so they will be run on all systems.
	* tests/wm.test: Add tests to check for error when
	an iconwindow is passed to the wm transient command.
	* unix/tkUnixWm.c (Tk_WmCmd):
	* win/tkWinWm.c (Tk_WmCmd): Raise an error if one
	of the windows passed to the wm transient command
	is an iconwindow for another toplevel.

2002-05-23  Mo DeJong  <[email protected]>

	* mac/tkMacWm.c (TkWmStackorderToplevelWrapperMap):
	* tests/wm.test: Add embedded Window test case for
	the stackorder command.
	* unix/tkUnixWm.c (TkWmStackorderToplevelWrapperMap):
	* win/tkWinWm.c (TkWmStackorderToplevelWrapperMap):
	Ignore embedded windows during wm stackorder command.

2002-05-21  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Invoke SC_ENABLE_SHARED before
	calling SC_CONFIG_CFLAGS so that the SHARED_BUILD
	variable can be checked inside SC_CONFIG_CFLAGS.
	* unix/tcl.m4: Update from Tcl.

2002-05-20  Don Porter  <[email protected]>

	* library/tk.tcl:  A little namespace cleanup on Daniel Steffen's
	latest revisions to avoid defining new global commands.

2002-05-20  Daniel Steffen  <[email protected]>

	* mac/tkMacInit.c:
	* mac/tkMacTclCode.r: include msgcat package in resources
	as bgerror depends on it. Restores ability of mac static
	build to run standalone (except for encoding file issues).

	* mac/tkMacInit.c:
	* library/console.tcl:
	* library/tk.tcl: fix tk.tcl not sourcing library files
	that define bindings at startup on mac. (independent of
	tk library files being in resources or on auto_path)

2002-05-08  Don Porter  <[email protected]>

	* library/bgerror.tcl:
	* library/tclIndex:  Cleaned up namespace usage of the bgerror
	dialog.  Completes soft dependence on msgcat.  [FR 539309]

2002-05-07  David Gravereaux  <[email protected]>
	* win/makefile.vc: Problem with TCLDIR macro not accepting
	forward slash path seperators resolved.  Added the same logic
	to INSTALLDIR, too. [Bug #553208]

2002-04-26  Jeff Hobbs  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: change HP-11 SHLIB_LD_LIBS from "" to ${LIBS} so
	that the .sl knows its dependent libs.

2002-04-24  Daniel Steffen  <[email protected]>

	* mac/tkMacTclCode.r:
	* mac/tkMacResource.r: added check of
	TCLTK_NO_LIBRARY_TEXT_RESOURCES #define to allow disabling the
	inclusion of the tk library code in the resource fork of Tk
	executables and shared libraries.
	Moved tk library code inclusion to separate file like in tcl.
	Added 'panedwindow' resource.

2002-04-22  Jeff Hobbs  <[email protected]>

	* library/button.tcl (ButtonLeave): corrected the 3
	implementations of ButtonLeave to check for Priv(relief) existing
	before trying to use it. [Patch #541849]

	* generic/tkTextDisp.c (DisplayLineBackground):
	* unix/tkUnix3d.c (Tk_3DHorizontalBevel):
	* unix/tkUnixFont.c (Tk_DrawChars): applied fixes to not overrun
	the X window 16-bit size limit. [Patch #541999] (bonfield)

2002-04-22  Donal K. Fellows  <[email protected]>

	* generic/tkTextDisp.c (GetXView, GetYView): Comparison with
	previous values of scrollbar range are now done in a way that is
	sensitive to the bizarreness of floating-point on architectures
	where IEEE-FP is not used on the processor.  Also increased the
	size of the temporary buffer to take account of the fact that
	TCL_DOUBLE_SPACE is meant to only imply enough space to take a
	printed double and trailing '\0', and no more.  [Bug #223739]
	(FP_EQUAL_SCALE): New macro to help compare floating-point numbers
	for equality in a sane way, used in GetXView and GetYView.

2002-04-12  Jeff Hobbs  <[email protected]>

	* generic/tkWindow.c (TkCloseDisplay): Added to centralize where a
	display was closed.  This handles freeing memory associated with a
	display and closing it.
	(DeleteWindowsExitProc): actually close displays.  This would also
	ideally be done in Tk_DestroyWindow when the last window on the
	display has been closed, but that still has unresolved order of
	cleanup problems.
	(Tk_DestroyWindow): added TkFocusFree call.

	* generic/tkStubInit.c:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntDecls.h:
	* generic/tkInt.decls: added TkFocusFree, TkClipCleanup and
	TkGCCleanup generic private procs, and TkWmCleanup, TkSendCleanup
	and TkFreeXId unix private procs.

	* generic/tkInt.h:
	* unix/tkUnixXId.c (TkFreeXId): frees XID resources.
	Made idCleanupScheduled a Tcl_TimerToken (was int) in TkDisplay
	structure to allow us to delete the timer scheduled for it.

	* unix/tkUnixWm.c (TkWmStackorderToplevel): ensure children
	structure is freed.
	(ConfigureEvent, ComputeReparentGeometry): Add extra wm tracing info
	(TkWmRestackToplevel): initialize changes to 0 to prevent UMR.
	Use WaitForConfigureNotify on all windows.  This part still
	requires fixing as it is the root of the 2 second raise delay on
	some window managers (those that use extra wrapper windows of
	their own).

	* unix/tkUnixSend.c (TkSendCleanup): free send-related resources

	* unix/tkUnixEvent.c (TkpCloseDisplay): call TkSendCleanup and
	TkWmCleanup.

	* unix/tkUnixSelect.c (SelRcvIncrProc): added missing Tcl_Release
	of interp

	* generic/tkGet.c (FreeUidThreadExitProc): free thread-specific
	resources on thread exit

	* generic/tkFocus.c (TkFocusFree): frees TkMainInfo data
	* generic/tkClipboard.c (TkClipCleanup): frees TkDisplay data
	* generic/tkGC.c (TkGCCleanup): frees TkDisplay data

	* unix/tkUnixFont.c (FontPkgCleanup): cleanup thread specific font
	resources on thread exit.

	* mac/tkMacXStubs.c (TkpOpenDisplay): memset the initial display
	structures to 0.

	* generic/tkOption.c (OptionThreadExitProc): freed tsd option
	stacks on thread exit.
	(Tk_GetOption): free mem used to get Tk_Uid

	* generic/tkMenu.c (ConfigureMenu): freed saved options in all
	error cases.

	* win/tkWinInt.h: declaration for TkWinGetUnicodeEncoding
	* win/tkWinDialog.c (GetFileNameW): use TkWinGetUnicodeEncoding
	* win/tkWinInit.c (TkpDisplayWarning): use TkWinGetUnicodeEncoding
	* win/tkWinFont.c: use TkWinGetUnicodeEncoding instead of static
	unicodeEncoding.

	* win/tkWinX.c (Tk_SetCaretPos): remove WM_IME_STARTCOMPOSITION
	and place the IME position within Tk_SetCaretPos.  Cache results in
	Tk_SetCaretPos to reduce unnecessary repositioning.  Also call
	DestroyCaret if we receive WM_KILLFOCUS.
	(TkpOpenDisplay): ZeroMemory the initial display structures.
	(TkWinGetUnicodeEncoding): Added so that Windows only needs to
	cache this value one, and then free it in TkWinXCleanup.
	(HandleIMEComposition): add support for Win98 and ATOK13
	IME. (yamamoto)

	* generic/tkConsole.c (ConsoleCmd): correct return that should
	have just set result code.

	* generic/tkImgPhoto.c: Added PhotoFormatThreadExitProc to clean
	up on thread exit. (Tk_PhotoPutBlock) slight code updates

	* generic/tkPanedWindow.c (DestroyPanedWindow, ConfigureSlaves):
	fix mem leaks in not freeing slave info

	* win/configure:
	* win/tcl.m4: Enabled COFF as well as CV style debug info with
	--enable-symbols to allow Dr. Watson users to see function info.
	More info on debugging levels can be obtained at:
	http://msdn.microsoft.com/library/en-us/dnvc60/html/gendepdebug.asp

2002-04-10  Mo DeJong  <[email protected]>

	* doc/wm.n:
	* mac/tkMacWm.c:
	* tests/wm.test:
	* unix/tkUnixWm.c:
	* win/tkWinWm.c: Update wm stackorder usage message
	to make it clear that either 1 or 3 arguments are
	required. [Bug 540013]

2002-04-08  Daniel Steffen  <[email protected]>

	* mac/tkMacProjects.sea.hqx: added tkPanedWindow.c to projects
	* mac/tkMacAppInit.c: fixes to MSL stdin/stdout hookup to the
	TkConsole when using shared MSL libraries; fix for crashing
	bug on exit: writing to stdin/sterr when console has already
	been destroyed. (both fixes need support in MSL, see
	'CW Pro6 changes' in tcl/mac/tcltkMacBuildSupport.sea.hqx)
	* mac/tkMacDialog.c: fixes to Navigation Services Dialog filter.
	* mac/tkMacDraw.c: add panic for overwide TkImages that would
	crash Tk on mac otherwise.

2002-04-05  Jeff Hobbs  <[email protected]>

	* mac/tkMacXStubs.c: added Tk_SetCaretPos stub (does nothing).
	* win/tkWinX.c: added Tk_SetCaretPos code to position IME windows
	correctly when WM_IME_STARTCOMPOSITION is received.
	* unix/tkUnixKey.c: added Tk_SetCaretPos and code for setting
	XIM caret in TkpGetString.

	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tk.decls: added Tk_SetCaretPos declaration.  This command
	allows users to indicate the cursor position and is used by XIM
	(Unix) or IME (Windows) to place the caret box correctly.  It is
	also part of correct Accessibility style on Windows to make the
	magnifier jump to the focus point.

	* win/tkWinButton.c (TkpDisplayButton):
	* generic/tkTextMark.c (TkTextInsertDisplayProc):
	* generic/tkCanvText.c (DisplayCanvText):
	* generic/tkEntry.c (DisplayEntry): added Tk_SetCaretPos calls

	* generic/tkInt.h: added TK_XIM_SPOT #define (default 1).
	Added XFontSet attribute to TkDisplay when TK_XIM_SPOT is true.
	* generic/tkEvent.c (Tk_HandleEvent): made sure inputContexts are
	not getting created on DestroyNotify events (for dead windows).
	Added over-the-spot support if TK_XIM_SPOT is defined (default).
	The is the nicer XIM behavior, but uses a bit more memory.

	* unix/tkUnixEvent.c:
	* generic/tkWindow.c: moved OpenIM over to tkUnixEvent.c.
	Removed setting inputContext to null in Tk_MakeWindowExist as it
	was redundant.

	* unix/tkUnixWm.c (CreateWrapper): Removed redundat setting of
	inputContext to null.

	* win/Makefile.in: changed gdb and shell targets to properly build
	all binaries before running (otherwise an error often occured).

2002-03-28  David Gravereaux <[email protected]>

	* win/.cvsignore (new):
	* win/lamp.bmp (new):
	* win/makefile.vc:
	* win/nmakehlp.c (new):
	* win/rules.vc:  Brought the makefile up-to-date with Tcl's one.
	This now has support for Win9x issues and the winhelp target now
	exists.  Color scheme can be changed.  I'm just imparting a first
	suggestion using orange :)  I'll have to think about the install
	portion of the helpfile as I'll need to do some tricks to insert
	tk's contents file into Tcl's using some special winhlp32.exe
	switches.  [Bug 533862 527941]

	* win/makefile.vc:  Tk helpfile is now installing itself into Tcl's
	contents file as part of the install target and rebuilding the
	contents table as desired.  [Bug 527941]

	* doc/console.n:  Changed topic from "Tcl Built-In Commands" to
	"Tk Built-In Commands"

	* win/buildall.vc.bat:  Update to match Tcl.

2002-03-26  Andreas Kupries  <[email protected]>

	* unix/tkUnixFont.c: Added inclusion of <arpa/inet.h>. This fixes
	a GCC/HPUX problem with missing a "htons". See also
	"tclUnixPort.h" for equivalent code.

2002-03-21  David Gravereaux <[email protected]>

	* win/makefile.vc: Changed optimize flag to -0ti instead of -02.
	[Bug 528441]

2002-03-20  Don Porter  <[email protected]>

	* generic/tkButton.c (ButtonTextVarProc,ButtonVarProc):
	* generic/tkCmds.c (WaitVariableProc):
	* generic/tkEntry.c (EntryTextVarProc):
	* generic/tkListbox.c (ListboxListVarProc):
	* generic/tkMenu.c (MenuVarProc):
	* generic/tkMenubutton.c (MenuButtonTextVarProc):
	* generic/tkMessage.c (MessageTextVarProc):
	* generic/tkScale.c (ScaleVarProc): Updates to handle change in
	type of part2 argument of Tcl_VarTraceProc typedef. [TIP 27]
	[Patch 532644].

2002-03-19  Jeff Hobbs  <[email protected]>

	* generic/tkOldConfig.c (Tk_ConfigureValue): prevent leaving
	interp->result as NULL.

2002-03-07  Donal K. Fellows  <[email protected]>

	* library/text.tcl (TextPasteSelection): Renaming of TextPaste to
	prevent confusion with tk_textPaste.  Stopped code from inserting
	selections twice, which seems to have happened with TIP#26, and
	reorganized code to reduce amount of stuff protected by catch
	which is tricky to maintain.
	(tk_textPaste): Reduce amount of code protected by catch.

2002-03-06  Mo DeJong  <[email protected]>

	* win/tkWinX.c: Define _WIN32_IE as 0x0300
	before including commctrl.h so that we can
	access the InitCommonControlsEx API when
	building Tk with mingw.

2002-03-06  Donal K. Fellows  <[email protected]>

	* README, generic/tk.h, unix/configure.in, unix/tk.spec:
	* win/configure.in: Bumped patchlevel; this might need to change
	in the future, but it will help us distinguish between the CVS
	version and the most recent released version.

2002-03-05  Jeff Hobbs  <[email protected]>

	*** 8.4a4 TAGGED FOR RELEASE ***

	* unix/README: updated --* options docs.

	* unix/tk.spec: fixed URL refs to use www.tcl.tk or SF.

2002-03-04  Jeff Hobbs  <[email protected]>

	* README:
	* mac/README:
	* unix/README:
	* win/README: updated to use www.tcl.tk URL.

2002-03-03  Jeff Hobbs  <[email protected]>

	* library/entry.tcl: added catch around Triple-1 binding use of
	sel.last

2002-02-28  Don Porter  <[email protected]>

	* library/console.tcl (ConsoleBind): Corrected console <<Paste>>
	binding on Unix platforms.

2002-02-26  Jeff Hobbs  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

	* generic/tkWindow.c (Tk_MainWindow, Tk_GetNumMainWindows):
	protect against being called before Tcl stubs are init'ed.
	[Bug #220916] (porter)

2002-02-25  Jeff Hobbs  <[email protected]>

	* generic/tkText.c (ConfigureText): reenable the blinking cursor
	on state change where necessary. [Bug #503772]

	* tests/listbox.test:
	* generic/tkListbox.c: corrected error handling when setting to an
	invalid listvar value. [Bug #503613]

	* library/scale.tcl: mirror B2 bindings to B3 on Windows to better
	accomodate two button mice. [Patch #493145]

	* library/panedwindow.tcl: improved proxy sash handling. (boudaillier)

2002-02-25  Donal K. Fellows  <[email protected]>

	* tests/filebox.test: Reorganised and fixed so that tests are
	executed fewer times (!) and the automatic extension adding
	behaviour of tk_getSaveFile is tested.

2002-02-23  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2002-02-22  Jeff Hobbs  <[email protected]>

	* generic/tkPanedWindow.c (PanedWindowWidgetObjCmd): fixed returns
	that should have been breaks instead.  Corrected .pw configure
	handling for insufficient args.  [Patch #521436] (boudaillier)

	* mac/tkMacDefault.h:
	* unix/tkUnixDefault.h:
	* win/tkWinDefault.h: changed panedwindow default relief to flat,
	a more natural outer relief.

	* library/panedwindow.tcl (ReleaseSash): changed to not pass x and
	y args at all (they aren't used).
	Added proc comments.  Made configuring sash cursor more efficient.
	Added Cursor timer that restores the default cursor when pointer
	is no longer over the sash.  This is necessary because Leave
	events won't be seen when moving into a paned child.

2002-02-22  Donal K. Fellows  <[email protected]>

	* library/demos/widget: New section "Paned Windows"
	* library/demos/paned2.tcl, library/demos/paned1.tcl: New files.

	* library/panedwindow.tcl (ReleaseSash): Added missing arguments.
	* library/tk.tcl: Bindings for paned window were not being loaded
	by default.

	* unix/tkUnixMenu.c (GetMenuLabelGeometry,DrawMenuEntryLabel):
	Stop meaningless GCC warnings.

2002-02-21  Jeff Hobbs  <[email protected]>

	* doc/panedwindow.n (new):
	* generic/tkPanedWindow.c (new):
	* generic/tkInt.h:
	* generic/tkWindow.c:
	* library/panedwindow.tcl (new):
	* mac/tkMacDefault.h:
	* tests/panedwindow.test (new):
	* unix/Makefile.in:
	* unix/tkUnixDefault.h:
	* win/Makefile.in:
	* win/makefile.vc:
	* win/tkWinDefault.h: added implementation of TIP #41, panedwindow
	widget. [Patch #512503] (melski)

	* generic/tkOption.c (ReadOptionFile): fixed Tcl_Seek casting to
	remove warnings (we expect no option files with be > 2GB).

	* unix/configure: regenerated
	* unix/tcl.m4: updated to sync with Tcl's tcl.m4
	Added --enable-64bit support for AIX-4 using IBM's xlc (-q64 flag).

2002-02-19  Don Porter  <[email protected]>

	* changes: First draft of updated changes for 8.4a4 release.

2002-02-19  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (MatchFileFormat):  Tcl_Seek takes
	Tcl_WideInt offset (three places.)
	* generic/tkImgPPM.c (FileReadPPM): Tcl_Seek takes Tcl_WideInt offset.
	* generic/tkFrame.c (ConfigureFrame): Stop GCC warning.

	* generic/tkImgGIF.c: Made file meet the formatting rules from the
	Tcl Engineering Manual better; mostly differences in whitespace.

2002-02-18  Jeff Hobbs  <[email protected]>

	* unix/configure: regen'd
	* unix/tcl.m4:
	* unix/configure.in: added macros and calls to SC_TCL_EARLY_FLAGS
	and SC_TCL_64BIT_FLAGS, part of TIP #72.

2002-02-14  Mo DeJong  <[email protected]>

	* library/entry.tcl:
	* library/text.tcl: Adjust <Double-1> and <Triple-1> bindings
	so that no anchor point is set and the insertion cursor is
	set to the last character in the selection. [Bug 220943]
	* tests/event.test: Add test cases for double click and
	drag as well as triple click and drag in the text and
	entry widgets.

2002-02-14  Mo DeJong  <[email protected]>

	* tests/event.test (_text_ind_to_x_y, _get_selection): Fix
	incorrect use of results from bbox invocation so that
	y center point for a give index is calculated correctly.
	Add new method to return the selection and use it in
	test cases. Always lappend to the result list to avoid
	case where initial result includes a space.

2002-02-07  Don Porter  <[email protected]>

	* generic/tkMain.c:
	* mac/tkMacInit.c:
	* mac/tkMacKeyboard.c:
	* win/tkWinDialog.c:
	* win/tkWinTest.c: modified some callers of Tcl routines that
	were restored to return (char *) pointing into Tcl_DStrings.

2002-02-03  eric melski  <[email protected]>

	* generic/tkImage.c (Tk_ImageObjCmd): Clean up bogus for loop in
	[image inuse] subcommand [Bug #485803].

2002-02-01  Jeff Hobbs  <[email protected]>

	* generic/tkCmds.c (Tk_TkObjCmd): don't use 'bool' as an arg as it
	conflicts with the C99 spec. [Bug #511956] (ingham)

2002-02-01  David Gravereaux <[email protected]>

	* win/makefile.vc: unset macro located in the tktest target
	caused a failure to build.  [Bug 511652]

2002-01-30  Don Porter  <[email protected]>

	* win/stubs.c (XSetCommand):  Overlooked CONSTification.

2002-02-01  Donal K. Fellows  <[email protected]>

	* doc/photo.n: Documented transparency subcommand.
	* tests/imgPhoto.test (imgPhoto-4.40...imgPhoto-4.68): Tests for
	the transparency subcommand.
	* generic/tkImgPhoto.c (ImgPhotoCmd): Added transparency
	subcommand (see TIP #14.)

2002-01-31  Todd Helfter <[email protected]>
	* generic/tkMenu.c (ConfigureMenuCloneEntries)
	* tests/menu.test (menu3.68)
	Correct and test for logic error when cloning menus. [Bug #508988]

2002-01-30  Don Porter  <[email protected]>

	* generic/tk.decls:  The POTENTIAL INCOMPATIBILITY in the changing
	interface of Tk_ParseArgv can now be removed by the -DUSE_NON_CONST
	compiler flag.
	* generic/tkDecls.h: make genstubs

2002-01-29  Andreas Kupries  <[email protected]>

	* win/tkWinInit.c (TkpGetAppName): TIP 27 fixup. The code now does
	not write into the CONST path returned by "argv0" and
	Tcl_SplitPath anymore.

2002-01-28  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Don't set TCL_LIB_SPEC and
	TCL_STUB_LIB_SPEC variables since this breaks
	the AIX build. This was used in the past to
	support linking with Tcl from the build dir
	or the install dir, but it is no longer needed.

2002-01-28  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Remove commented out vars.
	* unix/configure: Regen.
	* unix/configure.in: Don't subst vars that are already
	taken care of in SC_LOAD_TCLCONFIG.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2001-01-27  Daniel Steffen  <[email protected]>

	* generic/tkFileFilter.c:
	* mac/tkMacInit.c:
	* mac/tkMacKeyboard.c:
	* mac/tkMacMenus.c: TIP 27 CONSTification induced changes

2002-01-25  Don Porter  <[email protected]>

	* All changes below are Patch 505159

	* doc/AddOption.3:
	* doc/CanvTkWin.3:
	* doc/GetPixels.3:
	* doc/Name.3:
	* doc/ParseArgv.3:
	* generic/tk.decls (Tk_AddOption,Tk_CanvasGetCoord,Tk_GetPixels)
	(Tk_GetScreenMM,Tk_NameToWindow,Tk_ParseArgv):
	* generic/tkArgv.c (Tk_ParseArgv):
	* generic/tkCanvLine.c (ParseArrowShape):
	* generic/tkCanvUtil.c (Tk_CanvasGetCoord,Tk_CanvasTagsParseProc)
	(Tk_CanvasTagsPrintProc,Tk_GetDash):
	* generic/tkCanvas.c (ConfigureCanvas):
	* generic/tkGet.c (Tk_GetPixels,Tk_GetScreenMM):
	* generic/tkImgPhoto.c (ImgPhotoCmd):
	* generic/tkMain.c (Tk_MainEx):
	* generic/tkOldConfig.c (FormatConfigInfo):
	* generic/tkOption.c (Tk_AddOption):
	* generic/tkText.c (TextWidgetCmd,TkTextGetTabs,DumpSegment):
	* generic/tkText.h (TkTextCreateTag):
	* generic/tkTextTag.c (TkTextCreateTag):
	* generic/tkWindow.c (Tk_NameToWindow,Initialize):
	* mac/tkMacCursor.c (FindCursorByName,TkGetCursorByName):
	* mac/tkMacWm.c (Tk_WmCmd):
	* unix/tkUnixCursor.c (TkGetCursorByName):
	* unix/tkUnixSend.c (ValidateName):
	* unix/tkUnixWm.c (Tk_WmCmd):
	* win/tkWinCursor.c (TkGetCursorByName):
	* win/tkWinWm.c (Tk_WmCmd): Updated callers of Tcl_SplitList and
	Tcl_Merge.
	* generic/tkDecls.h: make genstubs
	***POTENTIAL INCOMPATIBILITY***
	Includes a source incompatibility in the argv argument of Tcl_ParseArgv.

	* generic/tkBind.c (DeleteVirtualEvent):
	* generic/tkCanvas.c (ScrollFractions, CanvasWidgetCmd)
	(CanvasUpdateScrollbars):
	* generic/tkTestTag.c (TkTextTagCmd): Updated callers of
	Tcl_GetStringResult.  Rewrote PrintScrollFractions to
	ScrollFractions to stop scribbling directly on interp->result.

	* generic/tkInt.decls (TkGetDefaultScreenName, TkpDisplayWarning)
	(TkpOpenDisplay):
	* generic/tkCanvPs.c (Tk_PostscriptColor, Tk_PostscriptFont):
	* generic/tkEntry.c (EntrySetValue, EntryValidateChange)
	(ExpandPercents, EntryValueChanged, Tk_EntryObjCmd, DestroyEntry)
	(ConfigureEntry, EntryComputeGeometry, InsertChars, DeleteChars)
	(EntryFetchSelection, EntryTextVarProc, Tk_SpinBoxObjCmd)
	(SpinboxWidgetObjCmd):
	* generic/tkMain.c (Prompt):
	* generic/tkMenu.c (MenuVarProc):
	* generic/tkMenubutton.c (ConfigureMenuButton, MenuButtonTextVarProc):
	* generic/tkMessage.c (ConfigureMessage, MessageTextVarProc):
	* generic/tkWindow.c (GetScreen, Initialize):
	* mac/tkMacInit.c (TkpInit, TkpDisplayWarning):
	* mac/tkMacXStubs.c (TkGetDefaultScreenName, TkpOpenDisplay):
	* unix/tkUnix.c (TkGetDefaultScreenName):
	* unix/tkUnixEvent.c (TkpOpenDisplay):
	* unix/tkUnixInit.c (TkpGetAppName, TkpDisplayWarning):
	* unix/tkUnixSend.c (SendEventProc):
	* win/tkWinInit.c (TkpGetAppName, TkpDisplayWarning):
	* win/tkWinX.c (TkGetDefaultScreenName,TkpOpenDisplay): Updated
	callers of Tcl_GetVar, Tcl_GetVar2
	* generic/tkIntDecls.h: make genstubs

	* generic/tkCanvPs.c (TkCanvPostscriptCmd):
	* generic/tkImgBmap.c (TkGetBitmapData):
	* generic/tkOption.c (ReadOptionFile):
	* mac/tkMacInit.c (TkpInit, TkpGetAppName):
	* win/tkWinInit.c (TkpGetAppName): Updated callers of
	Tcl_SplitPath, Tcl_JoinPath, and Tcl_TranslateFileName.

2002-01-18  Mo DeJong  <[email protected]>

	* tests/wm.test: Rewrite stackorder tests that
	deal with toplevels that have the overrideredirect
	flag set. [Tk bug 492259]

2002-01-18  Don Porter  <[email protected]>

	* win/tkWinDialog.c: Overlooked Tcl_GetIndexFromObj callers.

2001-01-18  Daniel Steffen  <[email protected]>

	* mac/tkMacDialog.c:
	* mac/tkMacSend.c: TIP 27 CONSTification broke the mac
	build in a few places.

2002-01-16  Jeff Hobbs  <[email protected]>

	* generic/tkListbox.c (ChangeListboxOffset): improved tracking
	when scrolling on x axis with entry/text.  [Bug #225025] (voskuil)

2002-01-16  Don Porter  <[email protected]>

	* generic/tk3d.c (Tk_GetReliefFromObj):
	* generic/tkBind.c (Tk_EventObjCmd, HandleEventGenerate):
	* generic/tkButton.c (ButtonWidgetObjCmd):
	* generic/tkCanvas.c (CanvasWidgetCmd, FindItems):
	* generic/tkClipboard.c (Tk_ClipboardObjCmd):
	* generic/tkCmds.c (Tk_BellObjCmd, Tk_TkObjCmd, Tk_TkwaitObjCmd)
	(Tk_UpdateObjCmd, Tk_WinfoObjCmd, Tk_WmObjCmd):
	* generic/tkConfig.c (DoObjConfig):
	* generic/tkEntry.c (EntryWidgetObjCmd, SpinboxWidgetObjCmd):
	* generic/tkFocus.c (Tk_FocusObjCmd):
	* generic/tkFont.c (Tk_FocusObjCmd, ConfigAttributesObj):
	* generic/tkFrame.c (Tk_FrameObjCmd):
	* generic/tkGet.c (Tk_GetAnchorFromObj, Tk_GetJustifyFromObj):
	* generic/tkGrab.c (Tk_GrabObjCmd):
	* generic/tkGrid.c (Tk_GridObjCmd, GridRowColumnConfigureCommand)
	(GridSlavesCommand, ConfigureSlaves):
	* generic/tkImage.c (Tk_ImageObjCmd):
	* generic/tkImgBmap.c (ImgBmapCmd):
	* generic/tkImgGIF.c (FileReadGIF):
	* generic/tkImgPhoto.c (ImgPhotoCmd):
	* generic/tkListbox.c (ListboxWidgetObjCmd, ListboxSelectionSubCmd)
	(GetListboxIndex):
	* generic/tkMenu.c (MenuWidgetObjCmd, MenuAddOrInsert, MenuCmd)
	(ConfigureMenu, CloneMenu):
	* generic/tkMenubutton.c (MenuButtonWidgetObjCmd):
	* generic/tkMessage.c (MessageWidgetObjCmd):
	* generic/tkOption.c (Tk_OptionObjCmd):
	* generic/tkPack.c (Tk_PackObjCmd, ConfigureSlaves):
	* generic/tkPlace.c (Tk_PlaceObjCmd):
	* generic/tkScale.c (ScaleWidgetObjCmd):
	* generic/tkSelect.c (Tk_SelectionObjCmd):
	* generic/tkSquare.c (SquareWidgetObjCmd):
	* generic/tkTest.c (TestobjconfigObjCmd, TrivialConfigObjCmd)
	(TestfontObjCmd): Updates to handle change in type of tablePtr
	argument of Tcl_GetIndexFromObj(Struct) from (char **) to
	(CONST char **).  [TIP 27] [Patch 504705]

	* generic/tkCanvText.c (GetSelText):
	* generic/tkEntry.c (Entry{FetchSelection,Setvalue},ExpandPercents):
	* generic/tkSelect.c (HandleTclCommand):
	* generic/tkText.c (TextSearchCmd):
	* generic/tkTextIndex.c (TkTextMakeByteIndex, TkTextIndexBackChars):
	* mac/tkMacFont.c (Tk_MeasureChars, BreakLine):
	* unix/tkUnixMenu.c (DrawMenuUnderline):
	* win/tkWinMenu.c (GetEntryText, DrawMenuUnderline):  Updated
	callers of Tcl_Utf* and Tcl_Regexp* APIs to reflect TIP 27 API
	changes (see Tcl Patch 471509). [Patch 471513]

2002-01-16  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2002-01-04  Don Porter  <[email protected]>

	* generic/tkMain.c (Tk_MainEx):  Updated callers of CONSTified
	Tcl interfaces Tcl_EvalFile and TclGetStartupScriptFileName.

	* generic/tkConsole.c (ConsoleOutputProc, TkConsolePrint):
	* generic/tkInt.h (TkConsolePrint):
	* mac/tkMacAppInit.c (TkConsolePrint): Updated Tk's console to
	CONSTified channel driver interface.  [Tcl Patch 503565, Tk Patch
	503983]

2002-01-11  Mo DeJong  <[email protected]>

	Use ${libdir} instead of ${exec_prefix}/lib. [Tcl bug 489370]

	* unix/configure: Regen.
	* unix/configure.in: Define and use libdir.
	* win/configure: Regen.
	* win/configure.in: Define libdir.

2002-01-11  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Burn Tcl and Tk build
	directories into tktest executable to avoid crashes
	caused by ld loading a previously installed version
	of the tcl or tk shared libraries. Remove setting
	of LD_LIBRARY_PATH, LIBPATH, and SHLIB_PATH
	before running tktest since it should no
	longer be required.

2002-01-11  Mo DeJong  <[email protected]>

	Enable use of Tcl stubs when building Tk as
	a shared library. This should fix the build
	under AIX. [Bugs 220858, 220955, 220921]

	* unix/Makefile.in: Add TCL_STUB_LIB_SPEC and
	TCL_STUB_LIB_FLAG variables.
	* unix/configure: Regen.
	* unix/configure.in: Pass TCL_STUB_LIB_SPEC into
	Makefile and use it when linking the tk shared library.
	Define USE_TCL_STUBS when building shared. Subst
	TCL_STUB_LIB_SPEC and TCL_STUB_LIB_FLAG.

2002-01-08  D. Richard Hipp  <[email protected]>

	* win/tkWinMenu.c: Fix the following bug: If you select an entry
	on a cascade menu then the next time the parent menu is posted, the
	cascade entry was active.  Also, if you traverse to a disabled entry
	using keystrokes and press ENTER on the disabled entry, then that
	entry appears active the next time the menu is posted.  The same
	patch fixes both problems.

2002-01-04  Don Porter  <[email protected]>

	* generic/tkBind.c (TkBindFree):
	* generic/tkGrid.c (ResolveConstraints,CheckSlotData,DestroyGrid):
	* generic/tkSelect.c (Tk_DeleteSelHandler,TkSelDeadWindow): Replaced
	Tcl_Free calls with ckfree so that memory debugging is fully supported.

2001-12-28  Jeff Hobbs  <[email protected]>

	* test/winButton.test:
	* win/tkWinButton.c: added updated patch #463234 which returns the
	default sizing behavior (not so native), but enables native L&F
	with negative sizing (-11 for example).

	* library/text.tcl (tk::TextButton1): made text receive focus even
	in disabled state for Windows to show selection and allow
	mouse-wheel scrolling.

	* win/tkWinInit.c (TkpDisplayWarning): added Tcl_DStringFree's

	* win/tkWinInt.h:
	* win/tkWinX.c: added TkWinProcs that represent a function table
	to switch between unicode and ansi procs on Windows.  This is
	analogous to the TclWinProcs.  Using Tcl_WinUtfToTChar, we can
	easily take advantage of using unicode functions where available
	without having to switch on the platform id each time.

	* win/tkWinWm.c (InitWindowClass): corrected init routines to
	allow unicode in window titles on Windows (for Win2K/XP).
	(TkWmStackorderToplevel): Corrected casts to enable debug compile

	* win/configure: regen'ed
	* win/tcl.m4: added shell32.lib to link libs, as these are
	necessary for new directory chooser (when enabled).

	* win/tkWinDialog.c (Tk_MessageBoxObjCmd): use MessageBoxW for
	proper display of unicode errors.
	Added patch which uses new OLE based directory chooser.  This
	still has some issues, so is disabled by default. [Patch #468139]
	(ColorDlgHookProc) Corrected ability to use unicode chars in
	tk_chooseColor -title.

2001-12-27  Jeff Hobbs  <[email protected]>

	* win/tkWinInit.c (TkpDisplayWarning): Use MessageBoxW in case the
	error displayed has unicode chars. [Bug #485986]

2001-12-27  Daniel Steffen <[email protected]>

	* mac/tkMacInit.c:
	* mac/tkMacResource.r: synced up tkInit features to unix/win:
	use existing tkInit proc if defined. Added spinbox.tcl resource.
	Used TclGetEnv() instead of Tcl_GetVar2(interp, env)
	* mac/tkMacApplication.r:
	* mac/tkMacLibrary.r: minor version resources cleanup

2001-12-27  Jeff Hobbs  <[email protected]>

	* generic/tkButton.c (ButtonTextVarProc): guard against being
	called while the *button/label is being deleted. [Bug #490051]

	* library/entry.tcl:
	* library/spinbox.tcl:
	* library/text.tcl: added extra checks against bug #220269 and
	made spinbox reuse more of the entry procedure code.

2001-12-20  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2001-12-19  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2001-12-18  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Move EXP file changes over from
	Tcl configure script to fix AIX build with gcc. [Bug 220955]

2001-12-18  Mo DeJong  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in: Use $(MAKE) instead of make
	in the tcltest rule.

2001-12-18  Don Porter  <[email protected]>

	* tests/event.test (event-click-drag-1.2): Corrected test that
	failed on Solaris/CDE due to text scrolling.  [Bug 413735]

2001-12-18  Jeff Hobbs  <[email protected]>

	* library/spinbox.tcl (ButtonDown): added catch to ignore
	possible error in after cancel when Priv(afterId) isn't defined.

	* doc/spinbox.n: corrected spin(up|down) -> button(up|down)

2001-12-14  Donal K. Fellows  <[email protected]>

	* doc/getOpenFile.n: Documented change.
	* library/tkfbox.tcl (SetFilter): Added code to guess the correct
	default extension from whatever value was selected in the
	filetypes option menu.  Adapted from code by Chris Nelson
	submitted in Patch #492220.

2001-12-12  Jeff Hobbs  <[email protected]>

	* unix/tkUnixWm.c (TkWmStackorderToplevelWrapperMap): added static

2001-12-05  Jeff Hobbs  <[email protected]>

	* generic/tkText.c:
	* generic/tkText.h: changed TkTextEditType enums to be prefaced
	with TK_EDIT_ to prevent name collision.

2001-12-05  Daniel Steffen <[email protected]>

	* mac/tkMacWm.c: mac implementation of wm stackorder
	(patch 481148, TIP 74)

2001-12-03  Mo DeJong  <[email protected]>

	Add TK patch 481148 to implement TIP 74, the
	wm stackorder command.

	* doc/winfo.n: Update documentation for the winfo
	children command to indicate that top-level windows
	are not returned in stacking order.
	* doc/wm.n: Add documentation for wm stackorder.
	* generic/tkInt.decls (TkWmStackorderToplevel):
	Add decl for new function.
	* generic/tkIntDecls.h: Regen.
	* generic/tkStubInit.c: Regen.
	* tests/unixWm.test: Add stackorder command to test
	for wm command usage message.
	* tests/wm.test: Add new set of tests for generic
	window manager methods.
	* unix/tkUnixWm.c (Tk_WmCmd, TkWmStackorderToplevelWrapperMap)
	(TkWmStackorderToplevel): Add unix implementation of
	new wm stackorder command.
	* win/tkWinWm.c (Tk_WmCmd, TkWmStackorderToplevelEnumProc)
	(TkWmStackorderToplevelWrapperMap, TkWmStackorderToplevel): Add
	windows implementation of new wm stackorder command.

2001-12-03  David Gravereaux <[email protected]>

	* win/makefile.vc: install target changes by request from
	Ryan Casey <[email protected]>.

2001-11-30  Donal K. Fellows  <[email protected]>

	* library/demos/widget: Further overhauling; shrank fonts, made
	better use of fonts, added an icon, fixed the About box.  Prompted
	by Bug #487442 from Vincent Wartelle.

2001-11-29  Donal K. Fellows  <[email protected]>

	* library/palette.tcl (tk_setPalette): Added heuristic to guess
	from the background whether to use black or white for the
	foreground when not told specifically.  Suggested by Chris Nelson,
	this makes the command fit the documentation better!

2001-11-27  David Gravereaux <[email protected]>

	* win/makefile.vc: Fixed CAT32 target.  cat.c is located in the Tcl
	source, not the Tk source.

2001-11-27  D. Richard Hipp <[email protected]>

	* library/menu.tcl: Do not allow keyboard traversal of torn-off
	menus to visit the (invisible) tearoff bar.

2001-11-26  D. Richard Hipp <[email protected]>

	* win/tkWinMenu.c: disabled menu items show the activebackground
	color in their background.  This change makes menu behavior
	consistent with what native windows does.

2001-11-24  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Add comments to better describe
	TCL_EXE and when it should be available. Add
	rule that prints message about running `make genstubs`
	when tkStubInit.c is out of date.
	* win/Makefile.in: Add TCL_TOOL_DIR and TCL_EXE
	variables to better match the Tcl Makefile. Add
	genstubs rule so tkSTubInit.c can be regenerated.

2001-11-24  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Don't AC_SUBST CFLAGS_DEBUG, CFLAGS_OPTIMIZE,
	or CFLAGS_WARNING since it is now done in SC_CONFIG_CFLAGS.
	* win/tcl.m4 (SC_CONFIG_CFLAGS): AC_SUBST DL_LIBS, CFLAGS_DEBUG,
	CFLAGS_OPTIMIZE, and CFLAGS_WARNING.

2001-11-23  Daniel Steffen <[email protected]>

	Up-port to 8.4 of mac code changes for 8.3.3 & various new
	changes for 8.4, some already backported to 8.3.4 (patch #435660)

	* library/tk.tcl: added <Key-F1> binding for <<Undo>> on the mac (TIP26)

	* library/button.tcl: fixed undefined $Priv(repeated) error for button
	without -repeatdelay support

	* generic/tkConsole.c:
	* library/console.tcl:
	* mac/tkMacInit.c:
	* mac/tkMacResource.r: corrected how mac deals with tcl library
	files present both in resources and in $tk_library directory.

	* generic/tkConsole.c: crashing bug fix when printing to console
	at program exit after the console has already been closed.
	Now setting gStdoutInterp=NULL in ConsoleClose().

	* mac/tkMacInit.c: correct use of Tcl_JoinPath in tk_library
	initialization

	* mac/tkMacMenu.c: special MDEF_PROC_OFFSET only needed for
	exactly one specific version of the MWERKS 68k compiler .

	* mac/tkMacShLib.exp: removed file

	* unix/Makefile.in: removed reference to .exp files

	* mac/MWTkBuildLibHeader.h:
	* mac/MW_TkBuildLibHeader.pch:
	* mac/MW_TkHeaderCommon.h:
	* mac/MW_TkOldImgStaticHeader.h:
	* mac/MW_TkStaticHeader.h:
	* mac/MW_TkStaticHeader.pch: new precompiled header files

	* mac/MW_TkHeader.pch:
	* mac/MW_TkOldImgHeader.h:
	* mac/MW_TkTestHeader.pch: revised precompiled header handling: now
	include a common header file 'MW_TkHeaderCommon.h' from all .pch files,
	the .pch files themselves now only setup #defines (e.g. BUILD_tk,
	STATIC_BUILD, TCL_DEBUG, TCL_THREADS) like in makefiles on other
	platforms.

	* mac/tkMac.h:
	* mac/tkMacPort.h:
	* mac/tkMacInt.h: use of BUILD_tk and TCL_STORAGE_CLASS like on other
	platforms, standardize #include'd files to what's done on other
	platforms, removed use of #pragma export, changed extern to EXTERN
	where appropriate to enable DLL export via the TCL_STORAGE_CLASS
	mechanism.

	* mac/tkMacAppearanceStubs.c: removed use of #pragma export

	* mac/widget.r: new resource file for 'Widget Demos'

	* mac/tkMacProjects.sea.hqx: updated mac build project files:
	build support for CodeWarrior Pro6, UnivIntf 3.4 & shared runtime
	libraries (see Tcl ChangeLog for details).
	changed weak linking so that CFM68k binaries now work on all OS
	versions from the free 7.5.5 onwards, with or without AppearanceMgr
	and/or NavigationMgr installed.
	added target to automatically build 'Widget Demos'
	included XML versions of the projects for CW Pro5 or Pro7 users.
	use compat/strtod.c instead of MSL's strtod()

	* generic/tkInt.decls:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkStubInit.c:

	* mac/tkMacInt.h: MAC_TCL tk stub support was badly broken due to
	multiply defined (mac specific) names in tk.decls and tkInt.decls,
	removed the duplicates from the internal unsupported interfaces
	"interface tkInt" and "interface tkIntPlat"; moved declaration of
	TkpIsWindowFloating from tkMacInt.h to tkInt.decls: interface tkIntPlat.
	- these changes to the stub tables might require you to recompile your
	Tk extensions if they turn out to reference one of the removed routines
	in the wrong table (should be unlikely).

	* generic/tkMain.c: MAC_TCL: workaround for broken/non-standard isatty
	on MW Pro6, #include <unistd.h> instead of defining isatty

	* generic/tkPointer.c: MAC_TCL: #include tkMacInt.h

	* generic/tkStubLib.c: MAC_TCL: removed obsolete special casing of mac
	headers, standardize #include'd files to what's done on other platforms

	* mac/tclets.r:
	* mac/tkMacWindowMgr.c:
	* mac/tkMacScrlbr.c:
	* mac/tkMacMenu.c:
	* mac/tkMacMenus.c:
	* mac/tkMacFont.c:
	* mac/tkMacDialog.c:
	* mac/tkMacButton.c: renamed obsolete apple API names to modern
	equivalents; UH3.4 support: added #include <ControlDefinitions.h>;
	fixed munged non-ASCII chars in sources due to bungled latin1<->mac
	roman encoding in CVS repository.

	* mac/tkMacDialog.c: added support for -filetypes option (fix for bug
	tcl #221636); added update event handling for background windows while
	in a NavigationMgr dialog; fixed nasty bug when calling CustomGetFile
	(missing addr operator) (fix for bug tk #220911 & tcl #219367); renamed
	routines conflicting with standard MoreFiles headers (see Tcl ChangeLog
	for details)

	* mac/tkMacApplication.r:
	* mac/tkMacLibrary.r:
	* mac/tkMacResource.r: fixed obsolete copyrights/dates in version
	strings, updated version strings to standard usage, added support for
	'(Support Libraries)' subfolder for shared runtime libraries in
	unmerged binaries, commented out demo setting of "Tcl Environment
	Variables"; reorganized resources among these files to avoid
	multiple copies in applications and shared libraries, the script
	libraries/Xcursors etc are now no longer duplicated in Wish but are
	only included in the resources of Tk.shlb.

	* mac/tkMacMenu.c:
	* mac/tkMacMDEF.r: changes to support MW Pro 6 68k (vers 0x2400 only)
	compiler producing different offset to start of MDEF; fix to static 68k
	presence testing when calling the custom MDEF

	* mac/tkMacWm.c.c:
	* mac/tkMacWindowMgr.c: added/fixed AppearanceMgr checks; override
	AppearanceMgr version detection on static 68k to ensure static 68k Wish
	runs on PPCs with recent AppearanceMgr

	* mac/tkMacButton.c: fixed misplaced/missing variable initialization.

2001-11-20  Jeff Hobbs  <[email protected]>

	* generic/tkText.c (TextGetText): reworked to use DString for
	improved speed. (callewaert, darley)
	(DestroyText): plugged mem leak when not clearing stack (callewaert)
	(TextGetText): more efficient string size calculation (darley)

2001-11-19  Donal K. Fellows  <[email protected]>

	* library/demos/entry3.tcl: New demo showing off validation and
	password entry.

	* library/demos/widget: Some reorganization to make the code
	simpler, plus a new entry demo.

2001-11-17  Jeff Hobbs  <[email protected]>

	* win/tkWinButton.c (TkpComputeButtonGeometry): corrected the
	default size of Windows buttons to conform to the Windows style.
	This changes the default size of buttons on Windows.
	[Patch #463234] (nelson)
	**** POTENTIAL VISUAL INCOMPATABILITY ****

2001-11-16  Jeff Hobbs  <[email protected]>

	* library/menu.tcl: corrected menu traversal code on Unix to
	better handle entering cascades.  [Patch #481219] (oleinick)

2001-11-16  David Gravereaux <[email protected]>

	* win/makefile.vc:  Install target repaired.

2001-11-15  Donal K. Fellows  <[email protected]>

	* library/demos/image2.tcl: Many improvements to this
	image-viewing demo; now uses labelframes and tk_chooseDirectory

	* library/palette.tcl (::tk::RecolorTree): Made this work better
	with CDE, which does some extremely annoying things with the
	option database that interact badly with Tk's way of handling
	options.

	* doc/text.n: Overhauled the documentation of undo to make it
	easier to understand.
	* library/tk.tcl (::tk::EventMotifBindings): Added Emacs-like undo
	binding, but not behaviour (we separate undo and redo.)
	* library/demos/text.tcl: Show off our undo capability!

2001-11-12  David Gravereaux <[email protected]>

	* win/mkd.bat:
	* win/rmd.bat:  Removed -kb CVS attribute and added changes
	from Llyod Lim for better stability.  [Patch #456761]

	* win/rules.vc(new):
	* win/buildall.vc.bat(new):
	* win/makefile.vc:  large rewrite following Tcl's makefile.vc as
	a guide and Patch #456761.  Appears BugFree(tm).

2001-11-12  Jeff Hobbs  <[email protected]>

	* doc/text.n:
	* generic/tkText.c:
	* generic/tkText.h:
	* generic/tkTextTag.c:
	* library/text.tcl:
	* library/tk.tcl:
	* mac/tkMacDefault.h:
	* tests/text.test:
	* unix/tkUnixDefault.h:
	* win/tkWinDefault.h: added TIP #26 implementation of simple
	built-in undo/redo of text editing in the text widget.
	[Patch #458879] (callewaert)

2001-11-12  Donal K. Fellows  <[email protected]>

	* library/demos/menu.tcl: Show off -compound support in menus.

	* library/demos/radio.tcl: Added some code to both show off the
	extra capabilities of the buttons and also show what can be done
	with compound images on the sly.

2001-11-10  Mo DeJong  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in: Add "make gdb" target. This target
	can run wish inside either gdb or insight.

2001-11-09  Jeff Hobbs  <[email protected]>

	* library/clrpick.tcl: changed a few parameters so that the full
	0..255 range could be accessed via the mouse. [Bug #478498]

	* unix/configure:
	* unix/tcl.m4: added -lc to AIX libs, fixed path to ldAix

	* win/configure:
	* win/tcl.m4:
	* win/makefile.vc: add comctl32.lib to build libs.
	* win/tkWinX.c (TkWinXInit): added InitCommonControlsEx call.
	* win/rc/tk.rc:
	* win/rc/wish.rc:
	* win/rc/wish.exe.manifest: added resources that specify using v6
	of the MS Common Controls library when available (WinXP+).  This
	enables use of the themeable widgets (like scrollbars) to be used
	in Tk. [Patch #478933]

2001-11-09  Mo DeJong  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: Update from Tcl.

2001-11-08  Mo DeJong  <[email protected]>

	* unix/Makefile.in:
	Avoid adding libc to the LIBS and WISH_LIBS
	variables since it is not needed when linking with CC.
	If required when linking with LD it should be done
	on a case by case basis in tcl.m4.

2001-11-05  Donal K. Fellows  <[email protected]>

	* library/demos/dialog2.tcl: Typo-fix.
	* library/demos/browse, library/demos/ixset, library/demos/rolodex:
	Installation does version number fixup, so we shouldn't.  Thanks
	to [email protected] for pointing these (thankfully minor) problems
	out.

2001-10-30  Donal K. Fellows  <[email protected]>

	* library/demos/widget: Integrated labelframe item into the labels
	section and added a spinbox demo to the (retitled) entry section.

	* library/demos/labelframe.tcl: Adjusted so as to show off the
	labelframe widget to better effect and have a better description.

	* library/demos/spin.tcl: New demo to show off spinbox capabilities.

	* library/demos/rolodex: Changes up-ported from core-8-3-1-branch
	to make the script use more 8.*-isms, but not menus due to the way
	the context help system works.

	* library/demos/ixset: Changed to use the labelframe widget and
	the grid geometry manager.

2001-10-29  Donal K. Fellows  <[email protected]>

	* library/demos/browse: Changes up-ported from core-8-3-1-branch
	to make the script much more robust, particularly when neither the
	current version of wish or the script are on the path.

	* library/demos/hello: Added emacs trailing tag-line.

	* library/demos/tcolor: Changes up-ported from core-8-3-1-branch
	to make the script compliant with current good practise, as well
	as extensive use of the new labelframe widget.

	* library/demos/timer: Changes up-ported from core-8-3-1-branch to
	make the script look and work better.

	* library/demos/rmt: Changes up-ported from core-8-3-1-branch to
	use more 8.* features and make the demo script more generally
	useful to people.

2001-10-23  Donal K. Fellows  <[email protected]>

	* generic/tkCursor.c (Tk_GetCursorFromData): Fixed uninit nextPtr
	field.  [adapted from Patch 473875]
	(GetCursor): Removed double-assignment to nextPtr field.

2001-10-19  Jeff Hobbs  <[email protected]>

	* library/console.tcl: removed transpose ability until the console
	can get a proper rewrite of tag handling.

2001-10-18  Jeff Hobbs  <[email protected]>

	* tests/defs.tcl: removed threaded build warning under X.

	* library/console.tcl (ConsoleOutput): fixed undefined widget
	argument.

2001-10-16  Jeff Hobbs  <[email protected]>

	* library/xmfbox.tcl: fixed filtering in motif file dialog.
	[Patch #469670] (nelson)

	* generic/tkWindow.c (OpenIM): Added simple XIM patch to enable
	basic XIM input on Unix. [Patch #412727] (fabian)

2001-10-15  Jeff Hobbs  <[email protected]>

	* unix/configure:
	* unix/configure.in:
	* win/configure:
	* win/configure.in:
	* win/tkConfig.sh.in: reworked to be a little cleaner in
	comparison to each other, and to AC_SUBST even empty vars for
	win/tkConfig.sh

2001-10-12  Todd M. Helfter <[email protected]>

	* ChangeLog:
	* doc/menu.n:
	* generic/tkMenu.c:
	* generic/tkMenu.h:
	* generic/tkMenubutton.c:
	* generic/tkMenubutton.h:
	* mac/tkMacDefault.h:
	* mac/tkMacMenu.c:
	* mac/tkMacMenubutton.c:
	* tests/menu.test:
	* unix/tkUnixDefault.h:
	* unix/tkUnixMenu.c:
	* win/makefile.vc:
	* win/tkWinDefault.h:
	* win/tkWinMenu.c:
	* win/tkWinWm.c: Implementation of TIP #63, the addition of
	a -compound option to menu entries allowing text and an image to
	be displayed at the same time.

2001-10-09  Jeff Hobbs  <[email protected]>

	* library/console.tcl: added more smarts extracted from tkcon to
	the default console.

2001-10-01  Jeff Hobbs  <[email protected]>

	* win/tkWinTest.c: better error reporting from testclipboard

	* win/tkWinDialog.c: minor cast changes to support Win64

	* win/tkWinWindow.c: made use of standard Tk_GetHWND instead of
	older, private TkWinGetHWND.

	* win/configure: regen'ed
	* win/tcl.m4:
	* win/makefile.vc: updated for Win64 SDK RC1 compilation support

2001-09-30  Peter Spjuth <[email protected]>

	* doc/grid.n:
	* generic/tkGrid.c:
	* tests/grid.test: Added -uniform option to grid's row/column-
	configure. [TIP 37] [Patch 459343]

2001-09-26  Peter Spjuth <[email protected]>

	* win/tkWinFont.c (Tk_DrawChars): Added support for clipping text.

	* doc/frame.n:
	* doc/labelframe.n:
	* doc/toplevel.n:
	* generic/tkFrame.c:
	* generic/tkInt.h:
	* generic/tkWindow.c:
	* library/demos/radio.tcl:
	* library/demos/labelframe.tcl:
	* library/demos/widget:
	* mac/tkMacDefault.h:
	* tests/frame.test:
	* unix/tkUnixDefault.h:
	* win/tkWinDefault.h: Added labelframe widget. Added -padx/y
	options to frame and toplevel.

	* tests/grid.test:
	* tests/pack.test:
	* tests/place.test: Used labelframe to test geometry manager changes.
	[TIP 18] [Patch 429164]

2001-09-26  Peter Spjuth <[email protected]>

	* doc/GeomReq.3:
	* doc/WindowId.3:
	* generic/tk.decls:
	* generic/tk.h:
	* generic/tkDecls.h:
	* generic/tkGeometry.c:
	* generic/tkGrid.c (ArrangeGrid):
	* generic/tkInt.h:
	* generic/tkPack.c (ArrangePacking):
	* generic/tkPlace.c (RecomputePlacement):
	* generic/tkStubInit.c:
	* generic/tkUtil.c (TkComputeAnchor):
	* generic/tkWindow.c (TkAllocWindow):
	* unix/mkLinks: Geometry manager changes to support TIP#18.
	Allows a widget to set different internal border widths on
	different sides, and to set a minimum requested size.
	POTENTIAL INCOMPATIBILITY.  [Patch 429164]

2001-09-25  Don Porter  <[email protected]>

	* generic/tkBind.c:
	* generic/tkInt.decls (TkpScanWindowId):
	* unix/tkUnixPort.h (Tkp{Print,Scan}WindowId):
	* unix/tkUnixXId.c (TkpScanWindowId):
	* win/tkWinWindow.c (TkpScanWindowId): Corrected definition of
	TkpScanWindowId to handle situation where types Window and int
	do not have the same number of bits.  CONST-ified too.

	* generic/tkIntPlatDecls.h:
	* generic/tkStubInit.c: make genstubs

2001-09-24  Don Porter  <[email protected]>

	* generic/tkMain.c (StdinProc): Update to handle change in
	return type of Tcl_DStringAppend() from (char *) to (CONST char *).
	[TIP 27]

2001-09-23  Peter Spjuth  <[email protected]>
	* generic/tkPack.c (ConfigureSlaves):
	* tests/pack.test:
	* tests/grid.test:  Pack accepted asymmetric values for -ipadx/y.
	Only -padx/y supports asymmetry. [Bug #462348]

2001-09-21  Jeff Hobbs  <[email protected]>

	* win/tkWinWindow.c (TkpPrintWindowId, TkpScanWindowId): fixed to
	work on Win64 with 64bit XIDs.

	* generic/tkWindow.c (Tk_CreateAnonymousWindow):
	* generic/tkEntry.c (GetSpinboxElement): fixed unreachable returns.

	* win/tkWinX.c (TkGetServerInfo): added recognition of Win64.

	* xlib/X11/X.h: made XID __int64 type for Win64.

	* unix/tkUnixPort.h:
	* mac/tkMacPort.h: add (int*) cast to TkpScanWindowId.
	These may need to be changed to Window* (ulong).

	* generic/tkCmds.c (Tk_WinfoObjCmd):
	* generic/tkBind.c (NameToWindow):
	correct Window id's to be of type Window

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkInt.decls (TkpScanWindowId): changed decl to use
	Window* instead of int*.

	* xlib/xcolors.c:
	* generic/tkPack.c,tkWindow.c:
	* win/tkWinFont.c,tkWinMenu.c:
	* unix/tkUnixScale.c: minor cast fixes to prevent 64bit warnings.

	* tests/scrollbar.test (scrollbar-6.27): marked knownBug because
	it is skewed by bad dimensions returned by Windows.

	* tests/textDisp.test (textDisp-4.12): corrected test to work
	properly on Windows.

	* tests/id.test,macFont.test,macMenu.test,macscrollbar.test:
	* tests/send.test,winClipboard.test,winDialog.test,winFont.test:
	improved use of test constraints

	* win/tkWinWm.c (WinSetIcon): fixed SetClassLong for 64bit support.

2001-09-20  Jeff Hobbs  <[email protected]>

	* unix/configure: regen'ed
	* unix/tcl.m4: added --enable-64bit support for HP-11 with the
	64-bit kernel.

2001-09-17  Don Porter  <[email protected]>

	* generic/tkGrid.c (ConfigureSlaves):
	* generic/tkPack.c (PackAfter):  Corrected type definition of
	argument passed to Tcl_GetStringFromObj() from size_t to int.
	Incorrect type broke [pack] and [grid] on systems where
	sizeof(size_t) != sizeof(int).  [Bugs 462375, 462342, 462338]

2001-09-17  Donal K. Fellows  <[email protected]>

	* library/choosedir.tcl (DblClick):
	* library/tkfbox.tcl (OkCmd, ListInvoke): Rewrote so as to avoid
	the highly confusing string "text" and to be consistent about what
	is and what is not a list.  [Bug 459895, reported by fandom]

2001-09-14  Andreas Kupries  <[email protected]>

	* generic/tkImgGIF.c:
	* generic/tkImgPPM.c:
	* generic/tkImgPhoto.c:
	* generic/tkMenu.c: Applied patch [461578], provided by Vincent
	Darley. This fixes several memory leaks in the image code. They
	happen if there are errors during the initialization of the
	channel the image is supposed to be read from.

2001-09-12  Mo DeJong  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: Update from Tcl.

2001-09-12  D. Richard Hipp  <[email protected]>

	* library/tkfbox.tcl: fixed error that appeared when you would
	click on the canvas while viewing an empty directory.

2001-09-10  Mo DeJong  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: Update from Tcl.

2001-09-09  Mo DeJong  <[email protected]>

	* win/Makefile.in: Fix Windows Makefile so that
	tcltest will automatically be compiled if the
	user tries to build tktest.

2001-09-09  Mo DeJong  <[email protected]>

	* win/Makefile.in: Use TKTEST variable directly
	instead of depending on the tktest alias.

2001-09-08  Mo DeJong  <[email protected]>

	* win/mkd.bat:
	* win/rmd.bat:
	Apply binary property (cvs admin -kb) to files and convert
	to CRLF linefeed format to fix the VC++ build. [Tcl Bug #219409]

2001-08-29  Jeff Hobbs  <[email protected]>

	* tests/menu.test:
	* tests/send.test:
	* tests/select.test: corrected to use testConfig constraints in
	the TK_ALT_DISPLAY case

	* tests/unixSend.test: removed test file completely identical to
	send.test.  Removed platform specific named file in case somebody
	gets send working on Win/Mac in the future.

	* tests/config.test: added config-14.1 to test namespace import
	evaluation of widgets.
	* generic/tkButton.c (ButtonCreate):
	* generic/tkFrame.c (CreateFrame):
	* generic/tkMenubutton.c (Tk_MenubuttonObjCmd):
	* generic/tkPlace.c (Tk_PlaceObjCmd):
	* generic/tkScale.c (Tk_ScaleObjCmd):
	* generic/tkMessage.c (Tk_MessageObjCmd):
	* generic/tkEntry.c (Tk_EntryObjCmd, Tk_SpinboxObjCmd):
	* generic/tkSquare.c (SquareObjCmd): redid the handling of
	optionTables in widgets to allow them to be imported into other
	namespaces. [Bug #456632]

2001-08-28  Jeff Hobbs  <[email protected]>

	* win/tkWinDialog.c (ChooseDirectoryHookProc): work-around for MS
	bug that caused crashing in tk_chooseDirectory on Win95.
	[Bug #224936] (baker)

	* unix/tkUnixWm.c (TkWmRestackToplevel): reworked how
	ConfigureNotify requests were handled in relation to the parent to
	avoid the problem with potential 'raise' delays on some wms.
	[Bug #220260] (baker) wms that were affected should notice the
	difference in tests unixWm-51.* not failing that failed before.

2001-08-26  Don Porter  <[email protected]>

	* library/text.tcl (<Shift-Up> binding):  Corrected TIP 44 typo
	that broke binding.  Thanks to "Michal" for the fix.
	[Bug 455468]

2001-08-23  Jeff Hobbs  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: added QNX-6 build support. [Bug #219410] (loverso)

	* doc/CrtPhImgFmt.3: removed bogus note about including tkPhoto.h

2001-08-22  Peter Spjuth  <[email protected]>

	* generics/tkGrid.c (ConfigureSlaves):
	* tests/grid.test: Fixed a bug where adjacent 'x' and '^' where
	not handled properly. [Bug #452040]

2001-08-22  Jeff Hobbs  <[email protected]>

	* generic/tkPack.c (TkParsePadAmount): added lint init for sepChar.

	* tests/dialog.test (HitReturn): fixed failing dialog-2.1 test
	because it wasn't always getting focus properly.

2001-08-21  Jeff Hobbs  <[email protected]>

	* tests/unixFont.test (unixFont-2.[234]): fixed to be more
	sensitive on systems that have more installed fonts.

	* library/dialog.tcl (tk_dialog): changed dialog to show bar on
	Windows as well and added some y padding between the buttons and
	the bar. [Patch #442835] (harrismh)

2001-08-20  Peter Spjuth  <[email protected]>

	* generic/tkInt.h:
	* generic/tkWindow.c:
	* generic/tkGrid.c:
	* generic/tkPack.c:
	* tests/grid.test:
	* tests/oldpack.test:
	* tests/pack.test: Objectified grid and pack commands.

2001-08-20  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (TkGetWindowFromObj): Rewrote window code to
	reuse a previously worked-out set of window information exactly
	when the reference window is the same and no window deletions have
	occurred since the object was allocated (display has same epoch
	counter.)  Required changing the internal rep of the window quite
	a bit as now need to save three words-worth of information in the
	internal rep (this window, reference window, display epoch.)
	* generic/tkObj.c (SetWindowFromAny, DupWindowInternalRep)
	(FreeWindowInternalRep): Code to support new internal rep for
	window objects.
	* generic/tkInt.h: Added epoch counter to TkDisplay structure
	* generic/tkWindow.c (GetScreen, Tk_DestroyWindow): Epoch counter
	is incremented every time a window is deleted.

2001-08-18  Peter Spjuth <[email protected]>

	* doc/grid.n:
	* tests/grid.test:
	* generic/tkGrid.c: Grid configure rejected initial "x" and "^".
	[Bug #418664]

2001-08-17  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (TkGetWindowFromObj): Was failing to reuse
	cached window objects, forcing a call to Tcl_GetStringFromObj and
	Tk_NameToWindow every time.  This fault has been in there for
	nearly three years...

2001-08-15  Don Porter <[email protected]>

	* changes: Labelled the TIP 44 changes as "POTENTIAL INCOMPATIBILITY".
	Although technically internal changes are not incompatible, they'll
	be perceived as such by those who get bitten, and this will help
	them find the cause of their trouble.

2001-08-14  Donal K. Fellows  <[email protected]>

	* generic/tk{Util,Font,Cursor,Color,Bitmap,3d}.c: Modified
	objtype declarations so that they can be picked up in tkObj.c and
	the names are now prefixed with "tk" too.
	* generic/tkObj.c (TkRegisterObjTypes):
	* generic/tkWindow.c (Initialize):
	* generic/tkInt.h: Added code to register Tk's object types with
	the Tcl runtime.  [Tcl Bug 450545]

2001-08-12  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2001-08-10  Donal K. Fellows  <[email protected]>

	* library/demos/image2.tcl (loadDir): Converted non-portable
	[glob [file join $dirName *]] to [glob -directory $dirName *]
	which is both fully portable and more reliable when directory
	names contain glob-significant characters.  [Bug 223313]

2001-08-08  Don Porter <[email protected]>

	* tests/dialog.test:  New file testing [tk_dialog].

	* library/dialog.tcl:
	* library/tkfbox.tcl: Corrections to problems introduced by
	the TIP 44 changes.  [Bug 449261]

	* README:
	* generic/tk.h:
	* unix/configure:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure:
	* win/configure.in: Bumped up patchlevel to 8.4a4 to distinguish
	CVS snapshots from the 8.4a3 release.  This does not necessarily
	mean there will be an 8.4a4 release.  [Bug 448938].

2001-08-07  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (dist): added {unix,win}/tcl.m4 and
	library/msgs/*.msg to dist target.  [Bug: #448802]

2001-08-06  Jeff Hobbs  <[email protected]>

	8.4a3 RELEASE

	* changes:
	* README: updated for 8.4a3 release

	* unix/configure: regenerated
	* unix/tcl.m4: added GNU (HURD) configuration target. (brinkmann)
	[Patch: #442974]

2001-08-06  Don Porter  <[email protected]>

	* generic/tkConsole.c:
	* generic/tkWindow.c:
	* library/bgerror.tcl:
	* library/dialog.tcl:
	* library/msgbox.tcl:
	* library/unsupported.tcl:
	* mac/tclets.tcl:
	* mac/tkMacHLEvents.c:
	* mac/tkMacWm.c:  TIP 44 changes specific to the Mac and
	Windows platforms that were overlooked before: tkOpenDocument,
	tkConsoleExit, tkConsoleOutput, unsupported1 out of namespace :: .
	Thanks to Vince Darley for prompting another look.

2001-08-03  Jeff Hobbs  <[email protected]>

	* win/winMain.c (WishPanic): fixed CONST changes to go with
	CONST-ification in Tcl.

	* win/configure: regenerated
	* win/tcl.m4: fixed DLLSUFFIX definition to always be ${DBGX}.dll.
	This is necessary for TEA compliant builds that build shared
	against a static-built Tk.
	* win/Makefile.in ($(WISH)): added $(TK_STUB_LIB_FILE) to build
	target, otherwise it wouldn't get generated in a static build.

2001-08-01  Don Porter  <[email protected]>

	* doc/console.n:
	* doc/menu.n:
	* doc/text.n:
	* doc/tkvars.n:
	* generic/tkBind.c:
	* generic/tkMenu.c:
	* library/bgerror.tcl:
	* library/button.tcl:
	* library/choosedir.tcl:
	* library/clrpick.tcl:
	* library/comdlg.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/focus.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/optMenu.tcl:
	* library/palette.tcl:
	* library/scale.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/tclIndex:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/tkfbox.tcl:
	* library/unsupported.tcl:
	* library/xmfbox.tcl:
	* mac/tkMacMenu.c:
	* tests/clrpick.test:
	* tests/filebox.test:
	* tests/macMenu.test:
	* tests/menu.test:
	* tests/menuDraw.test:
	* tests/msgbox.test:
	* tests/text.test:
	* tests/unixMenu.test:
	* tests/winMenu.test:
	* tests/xmfbox.test:
	* unix/mkLinks:
	* unix/tkUnixDialog.c: Merged changes from feature branch
	dgp-privates-into-namespace, implementing TIP 44.  All
	Tk commands and variables matching tk[A-Z]* are now in the
	::tk namespace.  See "BRANCH: dgp-privates-into-namespace"
	entries below for details.  [FR 220936]

2001-07-24  Mo DeJong  <[email protected]>

	* generic/default.h: Include tkWinDefault.h
	when built with Cygwin or Mingw.

2001-07-18  Don Porter	<[email protected]>

	BRANCH dgp-privates-into-namespace:
	* doc/console.n:  Updated names of private console commands.

2001-07-16  Don Porter	<[email protected]>

	BRANCH dgp-privates-into-namespace:
	* library/console.tcl:
	* library/unsupported.tcl: Renamed tk::histNum to tk::HistNum
	as directed by the Tcl Style Guide.

2001-07-10  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Add AR and STLIB_LD variables.
	* unix/configure:
	* unix/configure.in: Use STLIB_LD when defining MAKE_LIB
	and MAKE_STUB_LIB. Subst STLIB_LD, RANLIB, and AR.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2001-07-06  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2001-07-05  Mo DeJong  <[email protected]>

	* win/Makefile.in: Subst DEPARG directly instead
	of relying on a variable. This will make Cygwin
	build faster since an extra exec will be avoided.
	* win/configure: Regen.
	* win/configure.in: Subst DEPARG.
	* win/tcl.m4: Update from Tcl.

2001-07-04  Jeff Hobbs  <[email protected]>

	* README:
	* mac/README:
	* unix/README:
	* win/README: updated READMEs with purls

2001-07-03  Jeff Hobbs  <[email protected]>

	* tests/canvas.test:
	* generic/tkCanvPoly.c (PolygonToArea): Added patch that respects
	the polygon difference of including points in the polygon even
	when fill is empty.  [Bug #226357]

2001-07-03  Mo DeJong  <[email protected]>

	* win/Makefile.in: Remove PATHTYPE variable.
	* win/configure: Regen.
	* win/configure.in: Don't subst PATHTYPE.
	* win/tcl.m4: Update from Tcl.

2001-07-03  Mo DeJong  <[email protected]>

	* win/Makefile.in: Don't use VPSEP, instead just use :
	in the VPATH.
	* win/configure: Regen.
	* win/configure.in: Don't subst VPSEP.

2001-07-03  Donal K. Fellows  <[email protected]>

	* library/xmfbox.tcl (tkMotifFDialog_ActivateSEnt): Added missing
	backslash [Bug #438247]

2001-07-02  Jeff Hobbs  <[email protected]>

	* generic/tkWindow.c (Tk_DestroyWindow): changed to use
	Tcl_EventuallyFree instead of ckfree so that widgets that have
	references to a tkwin can use them.

	* generic/tkCanvArc.c:
	* generic/tkCanvBmap.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkRectOval.c: corrected argument handling in
	Create<Item> functions that could lead to ABRs or FMRs and
	corrected names of argc/argv to objc/objv.

	* generic/tkImgGIF.c (Mgetc): corrected screwy use of ternary
	operator and possible FMR.

	* generic/tkEntry.c: corrected missing Tcl_Release that caused
	font not freed complaints when trying valid cleanup calls.
	* generic/tkListbox.c: made use of Tcl_Preserve/Tcl_Release to
	prevent FMR errors in Display functions.

	* unix/tkUnixScale.c (TkpDisplayScale): corrected FMR when scale
	was deleted while calling its command.

	* library/console.tcl:
	* library/entry.tcl:
	* library/spinbox.tcl:
	* library/text.tcl:
	* library/tk.tcl: added private ::tk::GetSelection command to
	handle requesting selection.  This is to support requesting
	UTF8_STRING before generic STRING on Unix.  Changed Text, Spinbox,
	Entry and Console to use this command.

	* tests/select.test:
	* generic/tkSelect.c (Tk_CreateSelHandler, Tk_DeleteSelHandler):
	on Unix, a UTF8_STRING handler will be created when the user
	requests a STRING handler (in addition to the STRING handler).
	This provides implicit support for the new UTF8_STRING selection
	target.
	* unix/tkUnixSelect.c (TkSelEventProc, ConvertSelection): Added
	support for UTF8_STRING target. [RFE #418653, Patch #433283]

	* generic/tkInt.h: added utf8Atom to TkDisplay structure.

	* tests/listbox.test: changed 'darkblue' to 'white' in a test
	because it isn't a portable color name.

	* generic/tkEntry.c (DestroyEntry): used Tcl_EventuallyFree
	instead of ckfree for entryPtr to prevent FMRs. [Bug #413904]

2001-06-26  Mo DeJong  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in: Add `make shell` target. This target
	will set the proper env vars before invoking wish
	from the build directory.

2001-06-26  Mo DeJong  <[email protected]>

	* win/configure:
	* win/configure.in: Revert cross compiling change
	accidently added during last checkin.

2001-06-26  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Fix last checkin by removing
	export since that only works in bash.
	* win/configure: Regen.
	* win/configure.in: Ditto.

2001-06-26  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Set CFLAGS to "" if the user
	did not set CFLAGS in the env. This keeps AC_PROG_CC
	from adding "-g -O2" to the CFLAGS by default.
	* win/configure: Regen.
	* win/configure.in: Ditto.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Use RC_DEFINE flag from tcl.m4.
	* win/tcl.m4: Update from Tcl.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4 (SC_CONFIG_CFLAGS): Link to the
	imm32 library when building with mingw gcc.
	* win/tkWinX.c: Include the imm.h header
	to fix compiling with mingw gcc.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Add resource compiler fix from
	8.3.3 to fix compiling with mingw.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4: Fix silly typo in last checkin.

2001-06-22  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Set CFLAGS to @CFLAGS@ and @CFLAGS_DEFAULT@.
	Set LDFLAGS to @LDFLAGS@ and @LDFLAGS_DEFAULT@. Add LDFLAGS_DEBUG
	and LDFLAGS_OPTIMIZE to match the way CFLAGS_DEFAULT works. Use
	new LDFLAGS variable in the Makefile instead of @LDFLAGS@.
	* unix/configure: Regen.
	* unix/configure.in: Don't set CFLAGS to CFLAGS_DEFAULT, instead
	subst CFLAGS_DEFAULT into the Makefile. Add AC_SUBST for CFLAGS_DEBUG,
	CFLAGS_OPTIMIZE, LDFLAGS_DEFAULT, LDFLAGS_DEBUG, and LDFLAGS_OPTIMIZE.
	Remove unused LD_FLAGS subst.
	* unix/tcl.m4: Update from Tcl.
	* win/Makefile.in: Set CFLAGS to @CFLAGS@ and @CFLAGS_DEFAULT@.
	Set LDFLAGS to @LDFLAGS@ and @LDFLAGS_DEFAULT@.
	* win/configure: Regen.
	* win/configure.in: Don't set CFLAGS or LDFLAGS, instead subst
	CFLAGS_DEFAULT and LDFLAGS_DEFAULT into the Makefile.
	* win/tcl.m4: Update from Tcl.

2001-06-22  Mo DeJong  <[email protected]>

	* win/configure:
	* win/tcl.m4: Update From Tcl.

2001-06-21  eric melski  <[email protected]>

	* doc/colors.n: Corrected bogus documentation with respect to
	several shades of blue, all of which were listed as RGB 0 0 0.
	[Bug #432104].

2001-06-14  Donal K. Fellows  <[email protected]>

	* library/demos/floor.tcl, library/demos/filebox.tcl,
	* library/demos/clrpick.tcl, library/demos/vscale.tcl,
	* library/demos/twind.tcl, library/demos/ruler.tcl,
	* library/demos/plot.tcl, library/demos/items.tcl,
	* library/demos/hscale.tcl, library/demos/ctext.tcl,
	* library/demos/cscroll.tcl, library/demos/arrow.tcl,
	* library/xmfbox.tcl, library/msgbox.tcl,
	* library/clrpick.tcl, library/bgerror.tcl: Braced expressions.

2001-06-06  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Handle the --prefix option correctly
	it should default to /usr/local like the unix version.

2001-06-03  Jeff Hobbs  <[email protected]>

	* doc/selection.n:
	* doc/clipboard.n: added SEE ALSOs to cross-reference selection
	and clipboard, with extra note for clipboard command in selection
	docs.  [Patch #422256]

	* unix/tkUnixFont.c: Corrected support for iso10646 (X11 Unicode)
	fonts on Unix. This adds a ucs-2be (UCS-2 Big Endian) encoding in
	Tk on Unix that is used for those fonts (X11 requires
	big-endianness). (welch) [Patch #406411; Bug #220890 #220899]
	This differs from the 8.3.3 patch by not adding ucs-2be in the
	preferred encodingList (seems works fine without).
	Added alias for jisx0201* fonts to jis0201 encoding. [Bug #414033]

2001-05-30  Jeff Hobbs  <[email protected]>

	* win/tkWinKey.c (TkpSetKeycodeAndState): removed old debug info

2001-05-29  Jeff Hobbs  <[email protected]>

	* win/tkWinX.c: moved the initialization of tkPlatformId from
	TkWinXInit to TkWinGetPlatformId because static builds could call
	it before it was initialized. [Bug #427278]

2001-05-28  Peter Spjuth  <[email protected]>

	* generic/tkFrame.c:
	* generic/tkWindow.c:
	* tests/frame.test: Upgraded frame to use the newer TK_OPTION
	style when processing configuration options. Some cleanup of
	bad comments and bad code. [part of patch #420861]

2001-05-23  Mo DeJong  <[email protected]>

	* unix/configure:
	* unix/tcl.m4:
	* win/configure:
	* win/tcl.m4: Sync from Tcl sources.

2001-05-21  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4: sync'ed up wih Tcl tcl.m4. [Bug #419812]

	* doc/TkInitStubs.3:
	* generic/tk.h:
	* generic/tkStubLib.c: CONST'ified Tk_InitStubs to match CONST
	changes to Tcl_PkgRequireEx.

2001-05-21  Todd M. Helfter  <[email protected]>

	* doc/menubutton.n:
	* generic/tkMenubutton.c:
	* generic/tkMenubutton.h:
	* mac/tkMacMenubutton.c:
	* tests/menubut.test:
	* unix/tkUnixMenubu.c: Implementation of TIP #11, the addition of
	a -compound option to the menubutton allowing text and an image to
	be displayed at the same time.  This behavior is identical to the
	behavior of the button widget.

2001-05-16  Donal K. Fellows  <[email protected]>

	* doc/console.n: Added - was erroneously placed in Tcl before...

2001-04-25  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl.

2001-04-25  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/configure.in: Use $@ in MAKE_LIB and MAKE_STUB_LIB
	commands instead of using a delayed subst variable. Replace
	instances of STUB_LIB_FILE with TK_STUB_LIB_FILE.

2001-04-25  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Use TCL_STUB_LIB_FILE instead of STUB_LIB_FILE.
	* unix/configure: Regen.
	* unix/configure.in: Don't subst STUB_LIB_FILE, use TCL_STUB_LIB_FILE
	instead.

2001-04-12  Donal K. Fellows  <[email protected]>

	* generic/tkImage.c (Tk_ImageObjCmd,DeleteImage): Better detection
	of deletion when world is falling apart. [Bug #220819]

2001-04-04  Jeff Hobbs  <[email protected]>

	* win/tkWinMenu.c (TkWinHandleMenuEvent): corrected reseting of
	service mode to only occur when it was set. [Bug #220948]

2001-04-03  Jeff Hobbs  <[email protected]>

	* tests/winClipboard.test: improved results for understanding when
	tests fail.

	* tests/winDialog.test: string totitle'd some results that
	expected [pwd] to return a capital drive letter.

	* tests/cursor.test: changed tests to use 'heart' cursor because
	'arrow' on windows has a pre-skewed use count.

	* win/tkWinDialog.c (GetFileNameA): initialize multi to 0.

2001-04-02  Jeff Hobbs  <[email protected]>

	* win/configure:
	* win/tcl.m4 (SHLIB_LD): added -incremental:no. [Bug #219381]

	* generic/tkMenu.c (TkInvokeMenu): checked for menu deletion
	before calling associated menu entry command.  [Bug #220821]

	* doc/image.n: added warning about names chosen for images.

	* generic/tkImgPhoto.c (ImgPhotoCmd): corrected the src and dest
	values for $imageName put when -format and -to are used.
	[Bug #232741]

	* tests/listbox.test: added test listbox-27.1, delete during
	scrollbar update
	* generic/tkListbox.c (DestroyListbox, ListboxEventProc):
	corrected listbox to make proper use of Tcl_EventuallyFree and
	protect against unusual listbox deletion.

	* tests/entry.test: added tests entry-20.*, delete during widget
	activity
	* generic/tkEntry.c (DestroyEntry, EntryEventProc): fixed the
	entry widget to survive deletion while processing scrollbar
	updates and validation.

	* tests/canvas.test: test of canvas delete during event
	* generic/tkCanvas.c (DestroyCanvas, CanvasEventProc): fixed the
	canvas to survive deletion during event processing. [Bug #228024]

2001-04-01  Jeff Hobbs  <[email protected]>

	* README:
	* mac/README: updated patchlevel to 8.4a3 and corrected links and
	notes.

	* generic/tk.h:
	* unix/configure.in (TK_PATCH_LEVEL):
	* unix/configure:
	* unix/tk.spec:
	* win/configure.in (TK_PATCH_LEVEL):
	* win/configure: updated patchlevel to 8.4a3

2001-03-30  Jeff Hobbs  <[email protected]>

	* tests/safe.test: added note about correcting failures in
	safe.test.
	* library/tk.tcl: moved package require msgcat inside if case to
	not be used in safe interps.

	* win/makefile.vc:
	* win/configure:
	* win/tcl.m4: added imm32.lib to LIBS_GUI for Tk IME support.
	* win/tkWinInt.h:
	* win/tkWinKey.c:
	* win/tkWinX.c: added support for changing IME on the fly in
	Windows (2000).  (lam) [Patch #402993]

	* tests/bind.test (bind-22.18):
	* generic/tkBind.c (NameToWindow): handled the error case where a
	valid-looking but invalid identifier could be passed in certain
	event generate options causing a crash. [Bug #411307]

	* win/tkWinWm.c (UpdateWrapper): ensured that the passed in winPtr
	had an existent window to operate on. [Bug #409172]

	* win/Makefile.in (install-*): improved install-* targets to use
	their base build dependency.

	* generic/tkImage.c (Tk_ImageObjCmd, EventuallyDeleteImage):
	added casts to allow compiling on Windows with debbuging.

2001-03-29  Jeff Hobbs  <[email protected]>

	* library/msgs/de.msg: fixed translations. [Patch #403525]

	* doc/canvas.n: Noted ability to specify coords as a list in the
	docs. (techentin) [Patch #403660]

	* tests/canvas.test: added test case to check obj conversion
	* generic/tkObj.c (UpdateStringOfMM, SetMMFromAny): better
	obj-aware screen distances.  (pgbaum, hobbs) [Patch #403327]

	* library/bgerror.tcl (bgerror): allow focus into details window
	for Windows C&P to work. [Bug #220929]

	* library/tk.tcl: put a catch around adding <hpBackTab> to the
	<<PrevWindow>> virtual event as it doesn't seem to work on all HP
	systems. [Bug #411669]

	* library/tkfbox.tcl: fixed selecting directories and single files
	with spaces using tk_getOpenFile -multiple 1. [Bug #411640]

	* win/tkWinDialog.c (GetFileNameA): added support for -multiple to
	ascii-based tk_getOpenFile (Win9*). (haneef) [Patch #403047]
	(GetFileNameW): increased number of files that could be returned
	by tk_getOpenFile -multiple. [Patch #412042]

2001-03-29  Mo DeJong  <[email protected]>

	* library/entry.tcl (tkEntryMouseSelect):
	* library/text.tcl (tkTextSelectTo): When
	the mouse is dragged with the button down,
	move the insertion cursor to the current
	mouse position.
	* tests/event.test: Add a series of tests
	for event generation. Add tests for selection,
	check the position of the insertion cursor.

2001-03-28  Jeff Hobbs  <[email protected]>

	* unix/configure:
	* unix/tcl.m4: corrected IRIX-5.x config to not use -n32.
	(english) [Patch 403626]

2001-03-28  Don Porter  <[email protected]>

	* tests/focus.test (focus-6.1):
	* tests/macEmbed.test (unixEmbed-5.1):
	* tests/macMenu.test (macMenu-21.3):
	* tests/menu.test (menu-27.1):
	* tests/unixEmbed.test (unixEmbed-8.2):
	* tests/unixWm.test (unixWm-50.4):  Replaced all [load {} tk]
	in Tk test suite with [load {} Tk].  [Bug 220940, Patch 411952]

2001-03-12  Don Porter  <[email protected]>

	BRANCH dgp-privates-into-namespace:
	* doc/menu.n:
	* unix/mkLinks: Added documentation for [tk_menuSetFocus].

2001-03-12  Don Porter  <[email protected]>

	BRANCH dgp-privates-into-namespace:
	* doc/text.n:
	* doc/tkvars.n:
	* unix/mkLinks: Added documentation for commands and variables
	matching tk_text*.

2001-03-08  Don Porter  <[email protected]>

	BRANCH dgp-privates-into-namespace:
	* generic/tkTextDisp.c:
	* library/unsupported.tcl:
	* tests/textDisp.test: Restored the global variables tk_textRedraw
	and tk_textRelayout.  Since they match tk_*, they should remain
	publicly available until at least Tk 9.

2001-03-01  Don Porter  <[email protected]>

	BRANCH dgp-privates-into-namespace:
	* library/unsupported.tcl: New file for Tk's unsupported
	interfaces.  Contains [tk::unsupported::ExposePrivateCommand]
	and [tk::unsupported::ExposePrivateVariable] that restore the
	availability of an old public name of one of Tk's private
	commands and variables, respectively, for those applications
	and extensions that depend on the old names against advice.

2001-02-28  Don Porter  <[email protected]>

	BRANCH dgp-privates-into-namespace:  Feature branch to move all
	of Tk's private commands and variable into the ::tk namespace
	and its children.

	* doc/tkvars.n:  Documented private variable tkPriv renamed tk::Priv.

	* generic/tkBind.c:
	* generic/tkMenu.c:
	* generic/tkTextDisp.c:
	* library/bgerror.tcl:
	* library/button.tcl:
	* library/choosedir.tcl:
	* library/clrpick.tcl:
	* library/comdlg.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/focus.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/optMenu.tcl:
	* library/palette.tcl:
	* library/scale.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/tclIndex:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl:
	* mac/tkMacMenu.c:
	* tests/clrpick.test:
	* tests/filebox.test:
	* tests/macMenu.test:
	* tests/menu.test:
	* tests/menuDraw.test:
	* tests/msgbox.test:
	* tests/text.test:
	* tests/textDisp.test:
	* tests/unixMenu.test:
	* tests/winMenu.test:
	* tests/xmfbox.test:
	* unix/tkUnixDialog.c:  All Tk commands matching ::tk[A-Z]* and
	all Tk private variables in the global namespace were renamed to
	live in the namespace ::tk or one of its children.

2001-02-13  Eric Melski  <[email protected]>

	* doc/photo.n: [Bug 132213] Added clarification on interpretation
	of ranges for "photoName data -from" subcommand.

2001-02-12  D. Richard Hipp  <[email protected]>

	TIP #21: Asymmetric padding in the pack and grid geometry managers.
	With this changes, you can now say "-padx {10 20}" to put 10 pixels
	of padding on the left and 20 on the right.  Similar rules apply
	for vertical padding.  See the revised documentation for details.

2001-01-02  Andreas Kupries  <[email protected]>

	Everything below belongs together and implements TIP#8 (SF patch#102833)

	* win/tkWinWm.c (line 56f): Added icon structures.
	* win/tkWinWm.c (struct WmInfo, line 242): Added reference to
	optional icon for titlebar.
	* win/tkWinWm.c (struct ThreadSpecificData, line 335): Added
	reference to optional default icon for toplevel windows.
	* win/tkWinWm.c (line 387 ... 1169): All the new functions required
	to deal with icon specifications, 'InitWm' changed.
	* win/tkWinWm.c (TkWmNewWindow, UpdateWrapper, TkWmDeadWindow, Tk_WmCmd):
	Added initialization and handling of the new fields.
	* doc/wm.n: Documentation updated to explain the newly available
	functionality.

2000-12-13  jeff hobbs  <[email protected]>

	* generic/tkObj.c (SetMMFromAny): Added ability to recognize
	double type object to speed up canvas coord calculations.
	[Patch 403327]

2000-12-12  Donal K. Fellows  <[email protected]>

	* doc/entry.n: Improved documentation of interplay between the
	-state and -textvariable options.

2000-11-29  Donal K. Fellows  <[email protected]>

	* tests/image.test (image-1.10): Improved this test, which
	previously only worked if the command failed to delete the root
	window, and caused *major* trouble otherwise...
	* generic/tkImage.c (EventuallyDeleteImage): Created this function
	so that images that get deleted during the creation of an image
	won't cause a nasty core dump.  Properly fixes bug #120819.

2000-11-28  Donal K. Fellows  <[email protected]>

	* doc/image.n:
	* generic/tkImage.c (Tk_ImageObjCmd): Backed out previous change.
	Bug #120819 is back again in force.  Left the test in there
	though.

2000-11-23  Donal K. Fellows  <[email protected]>

	* doc/image.n:
	* tests/image.test (image-1.10):
	* generic/tkImage.c (Tk_ImageObjCmd): Prohibited image names that
	start with "." since they can cause some really obscure crashes.
	Fixes Bug #120819.

2000-11-21  Eric Melski  <[email protected]>

	Overall change:  Implemented TIP 5, which exports
	TkClassProcs/TkSetClassProcs as Tk_ClassProcs/Tk_SetClassProcs,
	adding a size field to Tk_ClassProcs to allow for future
	expansion, and renaming the geometryProc to worldChangedProc,
	which is more in keeping with the actual use of the callback.

	* unix/mkLinks: Added link for Tk_SetClassProcs.

	* doc/SetClassProcs.3: Documentation for
	Tk_ClassProcs/Tk_SetClassProcs.

	* generic/tkCanvas.c:
	* generic/tkEntry.c:
	* generic/tkFrame.c:
	* generic/tkListbox.c:
	* generic/tkMenu.c:
	* generic/tkMessage.c:
	* generic/tkScale.c:
	* generic/tkText.c: Updated to use Tk_ClassProcs/Tk_SetClassProcs
	instead of TkClassProcs/TkSetClassProcs.

	* generic/tkMenubutton.c:
	* generic/tkScrollbar.c:
	* generic/tkButton.c: Updated to use Tk_SetClassProcs instead of
	TkSetClassProcs.

	* generic/tkMenubutton.h:
	* generic/tkScrollbar.h:
	* generic/tkButton.h:
	* win/tkWinButton.c:
	* win/tkWinScrlbr.c:
	* mac/tkMacButton.c:
	* mac/tkMacMenubutton.c:
	* mac/tkMacScrlbr.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixMenubu.c:
	* unix/tkUnixScrlbr.c: Updated to use Tk_ClassProcs instead of
	TkClassProcs.

	* generic/tkDecls.h:
	* generic/tkStubInit.c:
	* generic/tkIntDecls.h: Regenned from tk.decls, tkInt.decls.

	* generic/tk.h: Added declaration of Tk_ClassProcs, with size
	field.  Added typedef's for Tk_ClassCreateProc,
	Tk_ClassWorldChangedProc, Tk_ClassModalProc.  Added definition of
	Tk_GetClassProc macro, shorthand for extracting a member of the
	Tk_ClassProcs structure.

	* generic/tkInt.h: Removed declaration of TkClassProcs,
	TkClassGeometryProc, etc.

	* generic/tkBind.c (Tk_BindEvent): Updated to use Tk_GetClassProc
	macro to extract modalProc; added check that the modalProc is non-NULL.

	* generic/tkFont.c (RecomputeWidgets): Updated to use
	Tk_GetClassProc macro to extract worldChangedProc; added comment
	about the choice of a recursive versus iterative algorithm for
	propagating world changed messages.

	* generic/tkWindow.c (Tk_MakeWindowExist): Updated to use
	Tk_GetClassProc macro to extract createProc from Tk_ClassProcs.

	* generic/tk.decls: Added declaration for Tk_SetClassProcs.

	* generic/tkInt.decls: Commented out declaration for
	TkSetClassProcs, which is made public by this change.  The entry
	is left in place, but commented, so that future developers will
	know not to reuse it's stub number.

2000-11-21  Donal K. Fellows  <[email protected]>

	* doc/ConfigWidg.3: Added deprecation note from Bug #120944 - use
	Tk_SetOption() instead.

	* generic/tkImgPhoto.c (TkPhotoGetValidRegion): Applied patch to
	create this function and add it to tkInt stubs.  Should now be
	possible to write an extension that accesses the transparency data
	in a photo image.  Bug #120930

2000-11-03  Jeff Hobbs  <[email protected]>

	8.4a2 RELEASE

	* generic/tkWindow.c (Initialize): added call to Tcl_SetMainLoop.
	This only has effect when tclsh is run (not wish), and then Tk is
	loaded in interactively.

2000-11-02  Jeff Hobbs  <[email protected]>

	* win/tkWinButton.c:
	* win/tkWinDialog.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c: fixed up code for Win64 support.  This mostly
	remains in _WIN64 #ifdef's, until updated compilers are standard.

	* win/tcl.m4:
	* win/makefile.vc: updated for Win64 compile support

	* unix/configure:
	* win/configure: checked in configure scripts so people doing
	CVS checkouts aren't required to have autoconf.  Changes to
	configure.in in the future will require the corresponding
	configure script to also be re-autoconf'ed and checked in.

	* doc/event.n: added note that key events require window focus.

2000-11-01  Jeff Hobbs  <[email protected]>

	* win/tkWinDialog.c (GetFileNameW, GetFileNameA)
	(Tk_ChooseDirectoryObjCmd): created
	work-around for change in NT5.0/98 that caused no initialdir
	setting to open the browser up in the user's documents dir.

	* tests/color.test: marked color-2.6 nonPortable as we can't
	reliably assume what 'red' maps to.

2000-11-01  Eric Melski  <[email protected]>

	* tests/winDialog.test: Corrected expected results for bad option
	tests (5.2, 5.5) to include -multiple option.

	* win/tkWinDialog.c: Added branch for 0 return from
	CommDlgExtendedError() switches; this was formerly treated as an
	error, but it actually is not, since it just means the user hit
	cancel or closed the dialog.  (GetFileNameW): Added better smarts
	such that -multiple is not considered a valid option for
	tk_getSaveFile.
	Removed CommDlgExtendedError() checks for color and choosedir
	dialogs, and removed all except the explicit invalid filename
	checks for the file dialogs.

2000-10-30  David Gravereaux  <[email protected]>

	* win/configure.in:
	* win/Makefile.in:
	* win/makefile.vc:
	* win/rc/tk.rc:
	* win/rc/tk_base.rc (new):
	* win/rc/wish.rc: Added logic to derive filenames better in the
	resource scripts based on compile options along with better
	support for building a static wish shell with cursor resources.

2000-10-27  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4: added support for AIX-5.

	* tests/tk.test:
	* doc/tk.n: updated to reflect default on status of useinputmethods.
	* library/tk.tcl: tk useinputmethods is set to 1 by default.  This
	enables Kanji and dead-char input by default.  Intro'd in
	1999-12-16 with default off to avoid some problems with older X
	servers that would slow down widget creation over time.

	* win/Makefile.in (test, winhelp, tktest): corrected the
	TCL_LIBRARY path specification.

2000-10-18  Eric Melski  <[email protected]>

	* win/tkWinDraw.c (RenderObject): Applied patch from [Bug: 6368],
	which corrects rendering of 1-pixel wide stippled lines on Windows.

	* generic/tkCanvLine.c (DisplayLine): Applied patch from
	[Bug: 6368], corrects bugs relating to use of active- and
	disabledwidth values for displaying lines (disabledwidth was never
	used, and activewidth/disablewidths would only possibly be used
	when greater than default width, rather than when simply not equal
	to default width).

	* library/tkfbox.tcl (OkCmd): Applied patch from [Bug: 6365],
	which adds safety for directory names containing spaces or which
	are non-lists.

	* win/tkWinDialog.c (GetFileNameW, GetFileNameA)
	(Tk_ChooseColorObjCmd, Tk_ChooseDirectoryObjCmd): Added error
	checking for the return value from the common dialog functions, so
	that the commands will not silently fail if the common dialog
	returns an error. [Bug: 6369].

2000-10-10  Eric Melski  <[email protected]>

	* generic/tkConfig.c (Tk_InitOptions): Added
	Tcl_IncrRefCount/Tcl_DecrRefCount calls on valuePtr, to prevent
	memory leaks when the value object comes from the option
	database.  [Bug: 6275].

2000-10-06  Jeff Hobbs  <[email protected]>

	* win/Makefile.in (cat32.${OBJEXT}): add win/ subdirectory to
	cat32 target to correctly find the source file.

2000-10-05  Eric Melski  <[email protected]>

	* generic/tkCmds.c (Tk_WinfoObjCmd): Added check for
	TK_ANONYMOUS_WINDOW flag in the [winfo children] subcommand; if
	set, the window will not be printed in the list of children.

	* doc/CrtWindow.3: Added entry for Tk_CreateAnonymousWindow.

	* generic/tkWindow.c
	(Tk_CreateAnonymousWindow): New API for creating anonymous
	windows.  These windows are manipulable from C, but not from Tcl,
	because they have no pathname associated with them.  They are used
	initially by widgets that do rubber-band resizing (panedwindow,
	multi-column listbox, etc.), and may be useful for other widgets
	as well (dropbox, combobox).
	(Tk_DestroyWindow): Added check for TK_ANONYMOUS_WINDOW flag when
	determining whether to generate a DestroyNotify event.

	* generic/tkStubInit.c:
	* generic/tkDecls.h: Regen'd from tk.decls.

	* generic/tk.decls: Added Tk_CreateAnonymousWindow declaration.

	* generic/tk.h: Added TK_ANONYMOUS_WINDOW flag for Tk_Window's.

2000-10-04  Eric Melski  <[email protected]>

	* doc/MaintGeom.3: Noted that Tk_MaintainGeometry handles direct
	descendants properly.

	* generic/tkGeometry.c (Tk_MaintainGeometry): Added a check for
	the case in which the slave window is a direct descendant of the
	master window.  In this case, we need not set up the additional
	infrastructure normally provide by Tk_MaintainGeometry, because we
	can rely on the parent/child relationship to handle it for us
	implicitly.  In this case, Tk_MaintainGeometry just calls directly
	to Tk_MoveResizeWindow.  This allows geometry managers to simply
	always use Tk_MaintainGeometry to maintain geometry for slaves,
	and avoid doing the direct descendant check themselves.
	(Tk_UnmaintainGeometry): Added a matching check for the direct
	descendant case; in this case, Tk_UnmaintainGeometry simply
	returns immediately.

2000-10-01  Eric Melski  <[email protected]>

	* generic/tkButton.c (ConfigureButton): Added tests for -compound
	option, so that when there is a textvariable and an image, and
	-compound is not none, the button will display both the
	textvariable and the image.

	* doc/SetOptions.3: Added note that restoreProc and freeProc may
	be NULL.

	* generic/tkConfig.c (Tk_RestoreSavedOptions): For custom options,
	added test that the restoreProc is not NULL, to allow for custom
	options that don't care about supporting Tk_RestoreSavedOptions.

2000-09-29  D. Richard Hipp <[email protected]>

	* generic/tkBitmap.c: Changes to prevent a BadMatch error from the
	Xserver when the same bitmap is used on two or more screens of the
	same display.

	* tests/menu.test: Print a warning if the TK_ALT_DISPLAY environment
	variable is not configured so as to test for the bug fix above.

	* library/tk.tcl (::tk::SetGrabFocus): "Catch" the grab in case
	another application already holds the grab and the "grab" command
	fails.

2000-09-29  Jeff Hobbs  <[email protected]>

	* win/Makefile.in: commented use of TESTFLAGS
	* unix/Makefile.in: added TESTFLAGS to test and testlang targets to
	conform with Windows makefile and TEA style.

2000-09-29  Eric Melski  <[email protected]>

	* generic/tkTest.c: Fixed tests to use updated API.

	* doc/SetOptions.3:
	* generic/tk.h:
	* generic/tkConfig.c: Changed interface for Tk_CustomOptionSetProc
	and Tk_CustomOptionGetProc; these now take a pointer to the start
	of the widget record, and an integer offset to the slot for the
	option value, instead of just a pointer to the slot.  This allows
	more sophisticated options to do interesting things based on other
	data in the widget record.

2000-09-17  Eric Melski  <[email protected]>

	* generic/tk.h: Added declaration of Tk_ObjCustomOption structure,
	used for TK_OPTION_CUSTOM, and typedef's of the functions
	Tk_CustomOptionSetProc, Tk_CustomOptionGetProc,
	Tk_CustomOptionRestoreProc, and Tk_CustomOptionFreeProc, used for
	TK_OPTION_CUSTOM.

	* doc/SetOptions.3: Added documentation of TK_OPTION_CUSTOM, and
	section "CUSTOM OPTION TYPES" explaining how to create and use
	custom options.

	* tests/config.test: Added tests for custom option type.

	* generic/tkTest.c: Added test support for TK_OPTION_CUSTOM to
	TestobjconfigObjCmd.  Added CustomOption* functions to implement a
	test custom option.

	* generic/tkConfig.c: Added new option type TK_OPTION_CUSTOM,
	which allows the definition of custom option types by creating
	parsing, printing, freeing, and restoring procedures for a custom
	option.  This is needed by the text and canvas widgets if they are
	to be fully objectified.

2000-09-07  Jeff Hobbs  <[email protected]>

	* doc/Tk_Init.3:
	* doc/bell.n:
	* doc/loadTk.n: minor doc cleanup

2000-09-06  Eric Melski  <[email protected]>

	* doc/HWNDToWindow.3:
	* doc/GetHWND.3: Changed synopsis to indicate the tkPlatDecls.h
	should be included, not tk.h.

	* generic/tkPlatDecls.h: Removed #include <windows.h> for Windows,
	a better solution for now is to update the docs and have extension
	authors #include <tkPlatDecls.h>.

	* generic/tk.h: Removed '#include "tkPlatDecls.h"', as the
	incorrect inclusion order between windows.h/tkPlatDecls.h causes
	build conflicts on Windows.

	* generic/tkPlatDecls.h: Added #include <windows.h> for Windows,
	so that HWND, etc., are defined properly.

2000-09-06  Jeff Hobbs  <[email protected]>

	* doc/canvas.n: fixed doc bug (ellson). [Bug: 6218]

	* README:
	* generic/tk.h:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in: updated to patchlevel 8.4a2

	* generic/tkMessage.c (MessageWidgetObjCmd): initialized result to
	avoid pedantic warning.

	* generic/tkGrab.c (Tk_GrabObjCmd): changed len arg from size_t to
	int to fix pedantic warning.

2000-09-01  Eric Melski  <[email protected]>

	* win/makefile.vc (install-libraries):
	* win/Makefile.in (install-libraries):
	* unix/Makefile.in (install-libraries): Added tkPlatDecls.h to
	list of header files to install.

	* generic/tk.h: Added #include "tkPlatDecls.h", which declares the
	platform specific component of the public Tk stubs API's.

2000-08-29  Eric Melski  <[email protected]>

	* win/tkWinMenu.c (DrawWindowsSystemBitmap): Use scratchDC
	for determining the source's logical coordinates.  Patch from
	[Bug: 6134 (Markus Oberhumer)].

	* win/tkWinMenu.c (SetDefaults): Compute the indicatorDimensions[]
	under Windows NT/2000 in the same way as under Windows 95/98.
	Patch from [Bug: 6134 (Markus Oberhumer)].

	* win/tkWinFont.c (GetScreenFont): Added a memset() to
	pacify memory checkers.  Patch from [Bug: 6134 (Markus Oberhumer)].

	* library/tkfbox.tcl (::tk::dialog::file::Update): Corrected
	handling of multi-pattern filters (eg, "* *.*"), which was broken
	by the getOpenFile performance patches applied earlier.

2000-08-24  Eric Melski  <[email protected]>

	* doc/toplevel.n:
	* doc/spinbox.n:
	* doc/scrollbar.n:
	* doc/scale.n:
	* doc/menubutton.n:
	* doc/menu.n:
	* doc/listbox.n:
	* doc/entry.n:
	* doc/frame.n:
	* doc/message.n:
	* doc/checkbutton.n:
	* doc/radiobutton.n:
	* doc/button.n:
	* doc/label.n:
	* doc/canvas.n:
	* doc/text.n: Fixed Standard Options section to make best use of
	new tab settings in man.macros.

2000-08-24  Mo DeJong  <[email protected]>

	* unix/README: Update to account for removal of --enable-gcc.
	* unix/configure.in:
	* unix/tcl.m4 (SC_ENABLE_GCC): Remove --enable-gcc option.
	* win/configure.in:
	* win/tcl.m4 (SC_ENABLE_GCC): Remove --enable-gcc option.
	Remove quick hack that provided cross compile support for
	windows builds.

2000-08-23  Jeff Hobbs  <[email protected]>

	* generic/tkButton.c (ButtonTextVarProc): reversed change below,
	it was not correct.

2000-08-22  Jeff Hobbs  <[email protected]>

	* generic/tkButton.c (ButtonTextVarProc): changed order of
	incr/decr of new value object, in case they are equal.

2000-08-18  Eric Melski  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoGet): Removed redundant call to
	DitherInstance; this call was formerly being made from
	ImgPhotoGet->ImgPhotoConfigureInstance->DitherInstance, and
	ImgPhotoGet->DitherInstance.  The second call was removed.

2000-08-10  Jeff Hobbs  <[email protected]>

	* doc/SetOptions.3: added missing ')'.

2000-08-09  Eric Melski  <[email protected]>

	* doc/SetOptions.3: Updated documentation to reflect support for
	TK_OPTION_NULL_OK for TK_OPTION_DOUBLE and TK_OPTION_PIXELS.

	* generic/tkConfig.c: Added for TK_OPTION_NULL_OK support for
	TK_OPTION_DOUBLE and TK_OPTION_PIXELS.

	* doc/place.n: Updated, reformatted manual entry.

	* tests/place.test: Added many tests.

	* generic/tkPlace.c (Tk_PlaceObjCmd): Updated to use Tk
	widget-option management facilities to manage place options (-x,
	-y, etc.), which simplifies the placer code.  Added support for
	[place configure pathName] and [place configure pathName -option],
	similar to the behavior of the configure subcommand supported by
	widgets.

2000-08-08  Eric Melski  <[email protected]>

	* tests/place.test: Extended test suite to test error returns from
	[place].

	* generic/tkInt.h: Replaced Tk_PlaceCmd prototype with
	Tk_PlaceObjCmd prototype.

	* generic/tkWindow.c: Updated [place] command entry to use new
	Tcl_Obj interface.

	* generic/tkPlace.c (Tk_PlaceObjCmd): Tcl_Obj'ified [place] command.

2000-08-07  Eric Melski  <[email protected]>

	* generic/tkWindow.c: Updated [selection] command entry to use
	new Tcl_Obj interface.

	* generic/tkInt.h: Replaced Tk_SelectionCmd prototype with
	Tk_SelectionObjCmd prototype.

	* tests/select.test: Updated test suite to recognize standardized
	error messages.

	* generic/tkSelect.c (Tk_SelectionObjCmd): Tcl_Obj'ified
	[selection] command.

2000-08-07  Jeff Hobbs  <[email protected]>

	* doc/cursors.n: changed .SS to more compatible macros.

2000-08-05  Jeff Hobbs  <[email protected]>

	* library/safetk.tcl: rationalized the setting of tk_library when
	initialized Tk in a safe interpreter.

2000-08-03  Eric Melski  <[email protected]>

	* generic/tkWindow.c: Updated "grab" command entry to use
	Tcl_Obj'ified command.

	* generic/tkInt.h: Replaced Tk_GrabCmd prototype with
	Tk_GrabObjCmd prototype.

	* tests/grab.test: Initial suite of tests for [grab] command.

	* generic/tkGrab.c (Tk_GrabObjCmd): Tcl_Obj'ified [grab] command.

	* generic/tkInt.h: Removed Tk_AfterCmd function prototype; the
	function does not exist (since 4.0p3).  Cleaned up some line
	wrapping.

	* generic/tk.h: Removed "#define Tk_AfterCmd Tcl_AfterCmd";
	nothing in the core uses Tk_AfterCmd, and Tcl_AfterCmd doesn't exist
	anymore anyway.

	* generic/tkInt.h: Replace Tk_BindCmd prototype with
	Tk_BindObjCmd prototype.

	* generic/tkWindow.c: Updated "bind" command entry to use
	Tcl_Obj'ified command.

	* generic/tkCmds.c (Tk_BindObjCmd): Tcl_Obj'ified [bind] command.

	* tests/bind.test: Tweaked expected error messages for [bindtags]
	to comply with updated error messages.

	* generic/tkMenu.c (CloneMenu): Replaced calls to Tk_BindtagsCmd
	with equivalent calls to Tk_BindtagsObjCmd.

	* generic/tkInt.h: Replace Tk_BindtagsCmd prototype with
	Tk_BindtagsObjCmd prototype.

	* generic/tkWindow.c: Updated "bindtags" command entry to use
	Tcl_Obj'ified command.

	* generic/tkCmds.c (Tk_BindtagsObjCmd): Tcl_Obj'ified [bindtags]
	command.

2000-08-02  Eric Melski  <[email protected]>

	* generic/tkCmds.c (Tk_TkwaitObjCmd): Tcl_Obj'ified [tkwait] command.

	* generic/tkWindow.c: Updated "tkwait" command entry to use
	Tcl_Obj'ified command.

	* generic/tkInt.h: Replace Tk_TkwaitCmd prototype with
	Tk_TkwaitObjCmd prototype.

	* generic/tkGrid.c (Tk_GridCmd): Split [grid] subcommands into
	separate functions instead of inlining them all in Tk_GridCmd.

2000-08-01  Eric Melski  <[email protected]>

	* generic/tkInt.h: Replaced prototype for Tk_MessageCmd with
	prototype for Tk_MessageObjCmd.

	* generic/tkWindow.c: Marked message command as using the new
	MessageObjCmd instead of the old MessageCmd.

	* tests/message.test: Added tests for the message widget.

	* generic/tkMessage.c: Obj'ified the message widget.

	* generic/tkInt.h: Removed prototype for Tk_ClipboardCmd, added
	prototype for Tk_ClipboardObjCmd.

	* generic/tkWindow.c: Updated function pointers for clipboard
	command to use Tcl_Obj version.

	* tests/clipboard.test: Updated tests to expect standard error
	messages.

	* generic/tkClipboard.c (Tk_ClipboardObjCmd): Obj'ified
	Tk_ClipboardCmd -> Tk_ClipboardObjCmd.

2000-07-28  Eric Melski  <[email protected]>

	* unix/tkUnixButton.c (TkpDisplayButton): Added bits to change
	the indicator color when radio-/check-buttons are disabled.  This
	reduces the visual incongruity when a group of these controls are
	disabled together.

	* win/tkWinMenu.c (ReconfigureWindowsMenu): Added MF_GRAYED bit
	for disabled menu entries, to ensure that those which are drawn by
	the system are shown grayed (such as entries on menubars) [Bug: 4372].

	* doc/label.n: Added -disabledforeground to list of options [Bug:
	6053].

	* mac/tkMacDefault.h:
	* unix/tkUnixDefault.h: Added default values for listbox
	disabledforeground and state.

	* win/tkWinDefault.h: Changed default listbox background color to
	white and listbox selection borderwidth to 0, in keeping with the
	"Microsoft Windows User Experience"; added default values for
	listbox disabledforeground and listbox state.

	* doc/listbox.n: Added documentation for -state option.

	* generic/tkListbox.c: Added support for -state to listbox. [RFE:
	6052].

	* tests/listbox.test: Tests for listbox disabled state.

2000-07-27  Mo DeJong  <[email protected]>

	* win/configure.in: TCL_STUB_LIB_FLAG and
	TK_STUB_LIB_FLAG should not include ${TCL_DBGX}
	in win/tkConfig.sh, fix that.

2000-07-25  Joe English  <[email protected]>

	* doc: CanvPsY.3, ConfigWidg.3, CrtImgType.3, CrtItemType.3,
	FontId.3, GetFont.3, canvas.n, font.n, options.n, text.n:
	Documentation fix: Replaced references to XFontStruct *
	and Tk_FontStruct with Tk_Font.

2000-07-24  Eric Melski  <[email protected]>

	* tests/text.test: Added tests for -regexp -nocase searches with
	backslash character classes.

	* generic/tkText.c (TextSearchCmd): Text search did not work
	properly when -regexp and -nocase were used, in combination with
	backslash character classes represented by capital letters (ie,
	\W, \M); altered implementation of -regexp -nocase searches to use
	new regexp interfaces to fix this problem.  [Bug: 5988].

2000-07-21  Eric Melski  <[email protected]>

	* tests/text.test: Added tests for searching when text is elided.

	* generic/tkText.c (TextSearchCmd): Text search was not returning
	the correct index when the search covered (but did not search)
	elided characters; corrected this by adjusting the match index by
	the number of elided characters preceeding the start of the match,
	just as is done with embedded windows, etc. [Bug: 5470].

2000-07-21  Mo DeJong  <[email protected]>

	* win/configure.in: Add TK_STUB_LIB_FLAG and
	TK_BUILD_STUB_LIB_SPEC. These are needed to build a stub enabled
	extension.

2000-07-20  Eric Melski  <[email protected]>

	* unix/tkUnixDraw.c (TkScrollWindow): Replaced a use of a trinary
	operator with an if/else, to avoid build problems on some
	platforms [Bug: 5819].

	* win/makefile.vc: Applied patch from Don Porter to enhance nmake
	support on NT/Alpha [RFE: 5939].

2000-07-19  Eric Melski  <[email protected]>

	* library/text.tcl: Enhanced <Tab> binding to behave like normal
	<Tab> bindings when the text widget is disabled (ie, it advances
	focus to the next widget).

	* generic/tkText.c (TextSearchCmd): Added a test for a NULL
	segment pointer when doing backwards searches for "" on an empty
	text widget. [Bug: 6007].

2000-07-18  Mo DeJong  <[email protected]>

	* unix/aclocal.m4: Use tcl.m4.

	* unix/configure.in: Properly quote LOCALES variable. Properly quote
	argument to m4 macro.

	* unix/tcl.m4: Add updated file from tcl.

	* win/tcl.m4: Updated file from tcl.

2000-07-18  Eric Melski  <[email protected]>

	* library/tkfbox.tcl: Fixed keyboard navigation in the iconlist.

	* unix/configure.in (MAKE_LIB): Corrected definition of MAKE_LIB
	for shared builds, with patch from Mike Hopkirk.

2000-07-18  Mo DeJong  <[email protected]>

	* win/Makefile.in: Fix TCL_GENERIC_DIR variable
	so that it uses the TK_SRC_DIR in the same way
	as the unix version.

2000-07-17  David Gravereaux  <[email protected]>

	* generic/tkConsole.c: Added comments for a Win2K OS bug with
	GetStdHandle(STD_OUTPUT_HANDLE).  No change was done to the code
	as the resulting behaviour of ShouldUseConsoleChannel() was
	correct, anyways. [BUG: 5971]

2000-07-17  Eric Melski  <[email protected]>

	* generic/tkStubImg.c (Tk_InitImageArgs): Applied patch from [Bug:
	5990], from Anselm Lingnau, which correctly sets the value of
	useNewImage to 0 when the new image system is not to be used,
	instead of leaving it at -1, which causes the check to be
	performed more times than is really necessary.

	* library/bgerror.tcl: Fixed a typo in one of the bgerror dialog
	label.

	* library/msgs/it.msg: Italian message catalog, from Paolo
	Brutti. [RFE: 6012].

2000-07-07  Eric Melski  <[email protected]>

	* library/msgs/el.msg: Greek message catalog, from George Petasis.

2000-07-07  Mo DeJong  <[email protected]>

	* win/configure.in: Fix subst of TK_SHARED_BUILD
	variable in tkConfig.sh.in. Fix definition of
	TK_SRC_DIR variable so that it matches the
	unix version.

2000-07-05  Mo DeJong  <[email protected]>

	* generic/tkFileFilter.c (AddClause): Cast to match function prototype.
	* win/stubs.c (_XInitImageFuncPtrs): Add return value for function.
	* win/tkWinButton.c (buttonStyles, ButtonBindProc, ComputeStyle):
	Remove unused declarations.
	* win/tkWinColor.c (GetColorByName, GetColorByValue): Remove unused
	function declarations.
	* win/tkWinDialog.c (TrySetDirectory): Remove unused function
	declaration.
	* win/tkWinEmbed.c (TkWinEmbeddedEventProc): Cast to match function
	prototype.
	* win/tkWinMenu.c (winMenuMutex, MenuExitProc): Remove unused
	declaration.
	* win/tkWinWindow.c (StackWindow): Remove unused declaration.
	* win/tkWinWm.c (ConfigureEvent): Remove unused declaration.
	* win/tkWinX.c (winXMutex): Remove unused declaration.
	* xlib/ximage.c (XCreateBitmapFromData): Cast to match function
	prototype.

2000-07-05  Eric Melski  <[email protected]>

	* tests/imgPhoto.test: Added test for GIF writing code [Bug: 5823].

	* generic/tkImgGIF.c: Applied patch from Jan Nijtmans to fix a
	problem with the GIF writing code [Bug:	5823].

	* generic/tkCursor.c: Added initialization for nextPtr field of
	TkCursor, patch from Nijtmans/Howlett.

2000-07-05  Eric Melski  <[email protected]>

	* library/msgs/nl.msg: Dutch message catalog for dialogs, from Jan
	Nijtmans.

2000-06-30  Eric Melski  <[email protected]>

	* doc/keysyms.n:
	* doc/colors.n: Added extra .CE/.CS pairs to break up the large
	text block, so that the generated Windows help file could
	accomodate the manual entry. [Bug: 5862]

	* tests/filebox.test: Adjusted tests to accomodate -multiple.

	* library/xmfbox.tcl: Adjusted arguments list construction such
	that -multiple is not presented as an option for tk_getSaveFile.

	* library/tk.tcl: Added test for safe interpreter status before
	attempting to load message catalogs (which is impossible in a
	standard safe interpreter).  This means that SafeTk will not have
	localized dialogs, unless a means is found for loading the message
	catalog files.

2000-06-29  Eric Melski  <[email protected]>

	* library/msgs/de.msg: German message catalog.

	* library/msgs/en.msg: English message catalog.

	* library/msgs/es.msg: Spanish message catalog.

	* library/msgs/fr.msg: French message catalog.

	* unix/Makefile.in:
	* unix/configure.in:
	* library/tk.tcl:
	* library/clrpick.tcl:
	* library/choosedir.tcl:
	* library/console.tcl:
	* library/msgbox.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl:
	* library/bgerror.tcl: Applied patches from Laurent Duperval to
	provide localization of Tk dialogs. [RFE: 2671].

2000-06-27  Eric Melski  <[email protected]>

	* generic/tkMenu.c (DeleteMenuCloneEntries): Applied fix from
	[Bug: 5275], which corrected a segfault-causing indexing problem
	when deleting entries from torn-off menus.

2000-06-22  Eric Melski  <[email protected]>

	* doc/getOpenFile.n: Updated with information about -multiple.

	* library/choosedir.tcl: Tweaked to handle modified tkIconList API's.

	* library/tkfbox.tcl: Preliminary implementation of multiple
	selection; based on patch from [RFE: 604].  Some of the tkIconList
	functions changed to support this and to make the dialog faster.

	* library/xmfbox.tcl: Added support for multiple selection, from
	patch in [RFE: 4999].

2000-06-21  Eric Melski  <[email protected]>

	* library/text.tcl: Corrected behavior of text widget with respect
	to this sequence of events:  click, shift-click.  Previously, the
	shift-click just moved the cursor and anchor; now, the shift-click
	will select the text between the click and the shift-click, which
	is the behavior most users expect. [Bug: 5929].

2000-06-19  Eric Melski  <[email protected]>

	* library/bgerror.tcl: Added auto-truncation for long error
	messages (more than 30 characters wide, or more than 4 lines
	long), so that the dialog remains a manageable size. [RFE: 5782]

2000-06-15  Eric Melski  <[email protected]>

	* win/tkWinDialog.c: Patched to support tk_getOpenFile
	-multiple. [RFE: 604].

2000-06-13  Eric Melski  <[email protected]>

	* win/aclocal.m4:
	* win/configure.in:
	* win/Makefile.in: Applied patch from [RFE: 5844], to provide
	support for the mingw compile environment for Windows.

2000-06-06  Jeff Hobbs  <[email protected]>

	8.4a1 RELEASE

2000-06-03  Jeff Hobbs  <[email protected]>

	* doc/CrtCmHdlr.3: new doc for ClientMessage handler procs
	* generic/tk.h: added typdef for Tk_ClientMessageProc
	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tk.decls: Added Tk_CreateClientMessageHandler and
	Tk_DeleteClientMessageHandler declarations.
	* generic/tkEvent.c (Tk_HandleEvent): Added
	Tk_CreateClientMessageHandler and Tk_DeleteClientMessageHandler to
	allow adding event handlers that invoke for ClientMessage events.
	This is necessary to support unix dnd protocols.

2000-06-02  Jeff Hobbs  <[email protected]>

	* canvas.test: added test for 5783.
	* generic/tkCanvPoly.c (DisplayPolygon): added checks for the
	polygon fillGC not being empty to prevent segfault. [Bug: 5783]

2000-05-31  Eric Melski  <[email protected]>

	* library/bgerror.tcl: Improved bgerror based on work by Donal
	K. Fellows; no longer dependant on tk_dialog; features a
	Windows-esque "Details" button, and a customizable extra function
	button that allows the user to (for example) save the stack trace
	to a file.

2000-05-30  Eric Melski  <[email protected]>

	* generic/tkImgGIF.c: Changed defines for GIF87a/GIF89a to be
	static char arrays with integer initialization, to address EBCIDIC
	vs. ASCII encoding issues and to handle compilers that don't deal
	with "\xAB" syntax for specifying hex values in strings.

2000-05-28  Jeff Hobbs  <[email protected]>

	* doc/spinbox.n: (new file) docs for spinbox widget
	* generic/tkInt.h: added Tk_SpinboxObjCmd declaration
	* generic/tkEntry.c: added 'spinbox' widget - an extension of the
	entry widget type.
	* generic/tkWindow.c: added 'spinbox' to core Tk commands
	* library/spinbox.tcl: (new file) binding and helper procs for spinbox
	* library/tk.tcl: added spinbox.tcl to list of files to source
	* tests/entry.test: updated changed error messages
	* tests/spinbox.test: (new file) test suite for spinbox

	* generic/tkPlace.c (Tk_PlaceCmd): reworked place master/slave
	table init'n to prevent seg fault when using place on multiple
	displays.

	* generic/tk.h: added comments ot Tk_FakeWin structure

2000-05-26  Eric Melski  <[email protected]>

	* generic/tkOption.c (Tk_GetOption): Extended Tk_GetOption to
	support a new syntax for option names in option tables.  If the
	option name has an embedded ".", it indicates that the name field
	contains both an option name and an overriding widget class, in
	the form "class.option".  The lookup for the option value will be
	performed as though the widget class is that specified, rather
	than the actual widget class.
	(SetupStacks): Replaced several lines of array element copying
	with a for loop for conciseness.

2000-05-25  Eric Melski  <[email protected]>

	* library/button.tcl: Tweaks for -overrelief handling on Windows.

	* doc/radiobutton.n: Added documentation for -overrelief option.

	* doc/checkbutton.n: Added documentation for -overrelief option.

	* doc/label.n: Added documentation for -state option.

	* generic/tkButton.c: Added -overrelief option for checkbuttons,
	and radiobuttons.

	* library/button.tcl (tkButtonDown, macintosh version): Added
	protection against querying the -repeatdelay option from a widget
	that doesn't support it (ie, checkbuttons, radiobuttons, etc).
	Other platforms use a different binding script for checkbuttons
	and radiobuttons, so they don't have this issue.
	(tkCheckRadioEnter, windows version):  Added code to handle
	-overrelief for check/radiobuttons on windows.

2000-05-22  Eric Melski  <[email protected]>

	* generic/tkButton.c: Added -activeforeground, -activebackground
	for labels, for the -state option.

	* doc/label.n: Added documentation for -state option,
	-activeforeground, -activebackground.

2000-05-22  Jeff Hobbs  <[email protected]>

	* win/Makefile.in (install-libraries): corrected to install X
	headers [Bug: 5516]

	* doc/bind.n:
	* doc/canvas.n:
	* doc/entry.n:
	* doc/listbox.n:
	* doc/photo.n: doc fix-ups [Bug: 5396]

2000-05-17  Jeff Hobbs  <[email protected]>

	* doc/bell.n:
	* tests/bell.test:
	* generic/tkCmds.c (Tk_BellObjCmd): added -nice option to
	optionally avoid resetting screen saver [Bug: 4279]

2000-05-15  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (Tk_WmCmd): changed wm deiconify from using idle
	callback to calling restack and focus code immediately.

2000-05-17  Eric Melski  <[email protected]>

	Overall change:  Added "-readonlybackground" option for entries,
	to enable a visual change when state goes to readonly.

	* mac/tkMacDefault.h (DEF_ENTRY_READONLY_BG_COLOR)
	(DEF_ENTRY_READONLY_BG_COLOR):
	* win/tkWinDefault.h (DEF_ENTRY_READONLY_BG_COLOR)
	(DEF_ENTRY_READONLY_BG_COLOR):
	* unix/tkUnixDefault.h (DEF_ENTRY_READONLY_BG_COLOR)
	(DEF_ENTRY_READONLY_BG_COLOR): Added default values for entry
	-readonlybackground option.

	* generic/tkEntry.c: Added -readonlybackground option, cleaned up
	excessive use of graphics contexts.

	* tests/entry.test: Added configuration test for
	-readonlybackground option.

	* doc/entry.n: Added documentation for -readonlybackground option.

	Overall change:  changed implementation of "link" relief for
	buttons.  Instead of a new relief style (-relief link), there is a
	new option, -overrelief, which if set is used when the mouse is
	over the button.

	* doc/SetOptions.3: Added information about TK_OPTION_NULL_OK with
	TK_OPTION_RELIEF.

	* win/tkWinButton.c: Removed bits about TK_RELIEF_LINK.

	* tests/button.test: Added tests for -overrelief; removed tests
	for -relief link.

	* mac/tkMacButton.c: Removed bits about TK_RELIEF_LINK.

	* generic/tkOldConfig.c: Removed bits about TK_RELIEF_LINK.

	* generic/tkConfig.c: Removed bits about TK_RELIEF_LINK; added
	support for TK_OPTION_NULL_OK for TK_OPTION_RELIEF.

	* library/button.tcl: Added binding support for -overrelief.

	* generic/tk3d.c (Tk_GetRelief): Added branch for TK_RELIEF_NULL.

	* generic/tkButton.c: Added -overrelief option; removed
	Enter/Leave EventProc masks and handlers.

	* generic/tk.h: Added TK_RELIEF_NULL definition, removed
	TK_RELIEF_LINK.

	* mac/tkMacDefault.h (DEF_BUTTON_OVER_RELIEF):
	* win/tkWinDefault.h (DEF_BUTTON_OVER_RELIEF):
	* unix/tkUnixDefault.h (DEF_BUTTON_OVER_RELIEF): Added default
	value for the -overrelief option.

2000-05-16  Eric Melski  <[email protected]>

	* win/tkWinMenu.c (ReconfigureWindowsMenu): Added code to add the
	MF_SEPARATOR bit for SEPARATOR_ENTRY menu items.  This causes
	separator entries on the system menu to be drawn correctly [Bug: 5451].

2000-05-15  Eric Melski  <[email protected]>

	* doc/image.n: Added documentation for [image inuse] command.

	* tests/image.test: Added tests for [image inuse] command.

	* generic/tkImage.c (Tk_ImageObjCmd): Added [image inuse] command,
	which provides a means for programmers to determine if a given
	image is in use by any widgets. [RFE: 3327].

2000-05-14  Eric Melski  <[email protected]>

	* doc/clipboard.n: Added documentation for "clipboard get".

	* generic/tkClipboard.c (Tk_ClipboardCmd): Added "clipboard get"
	subcommand [RFE: 4628].

	* tests/clipboard.test: Updated to use "clipboard get" instead of
	"selection get -s CLIPBOARD".

	* library/entry.tcl: Adjusted Button-1 binding to set focus to the
	entry when it is readonly or normal.

	* doc/entry.n: Added documentation for readonly state,
	-disabledforeground, -disabledbackground.

	* tests/entry.test: Added tests for readonly state.

	* generic/tkEntry.c: Added support for "readonly" state, and
	redefined "disabled" state.  A disabled entry will display its
	text in a dimmed color and possibly with a different background,
	and will be completely unusable (no selection, no editing).  A
	readonly entry will look like a normal entry, but it will not be
	editable; selection is still allowed. [RFE: 4239].  To support the
	new disabled state properly, "-disabledforeground" and
	"-disabledbackground" options were added.
	*** THIS IS A BACKWARDS INCOMPATIBLE BEHAVIOR CHANGE ***

	* win/tkWinDefault.h:
	* mac/tkMacDefault.h:
	* unix/tkUnixDefault.h: Added DEF_ENTRY_DISABLED_FG,
	DEF_ENTRY_DISABLED_BG_COLOR, DEF_ENTRY_DISABLED_BG_MONO.

2000-05-12  Eric Melski  <[email protected]>

	* unix/tkUnixButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
	* mac/tkMacButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
	* win/tkWinButton.c (TkpDisplayButton, TkpComputeButtonGeometry):
	Added code for drawing compound buttons.

	* tests/button.test: Added configuration tests for -repeatdelay,
	-repeatinterval, -compound.

	* library/button.tcl: Added support for -repeatedelay,
	-repeatinterval options.

	* generic/tkOldConfig.c: Changed handling of link relief so that
	proper error messages are used.

	* generic/tkButton.h: Added -compound, -repeatdelay,
	-repeatinterval options.

	* generic/tkButton.c: Added event watchers for enter/leave events,
	for link relief support.

	* generic/tk3d.c: Changed handling of link relief so that proper
	error messages are used.

	* generic/tk.h: Changed values of
	TK_OPTION_LINK_OK/TK_CONFIG_LINK_OK for link relief support.

2000-05-12  Jeff Hobbs  <[email protected]>

	* win/tkWinFont.c (LoadFontRanges): improved support for all chars
	in 0-255 range for bitmap ANSI fonts.  May be improved to handle
	bitmap non-ANSI fonts in the future. [Bug: 2172]

	* win/tkWinWm.c (RaiseWinWhenIdle): added TK_DONT_DESTROY_WINDOW
	to flag check to prevent timing related core dump. [Bug: 5438]

2000-05-11  Jeff Hobbs  <[email protected]>

	* win/tkWinTest.c (TestclipboardObjCmd): ensured CloseClipboard
	would always get called for each OpenClipboard.

	* tests/focus.test (focusSetupAlt): removed wm withdraw from proc
	as it would cause a hang for tkwait visibility

	* tests/menu.test:
	* generic/tk3d.c:
	* generic/tkColor.c:
	* generic/tkCursor.c: corrected handling of 3DBorder, Cursor and
	Color objects on multiple screens. [Bug: 5454]

2000-05-09  Eric Melski  <[email protected]>

	* doc/button.n: Added documentation for link relief.

	* tests/button.test: Added tests for link relief for buttons.

	* generic/tk.h (TK_CONFIG_LINK_OK): Added definition of
	TK_RELIEF_LINK, TK_OPTION_LINK_OK and TK_CONFIG_LINK_OK. [RFE: 4348]

	* generic/tk3d.c: Added support for link relief. [RFE: 4348]

	* mac/tkMacButton.c (TkpDisplayButton):
	* unix/tkUnixButton.c (TkpDisplayButton): Added support for link
	relief. [RFE: 4348]

	* generic/tkOldConfig.c (Tk_ConfigureWidget):
	* generic/tkConfig.c (DoObjConfig): Added understanding of link
	relief, which is allowed only for widgets that have
	TK_OPTION_LINK_OK or TK_CONFIG_LINK_OK set for the "-relief"
	option. [RFE: 4348]

	* generic/tkButton.c: Added TK_OPTION_LINK_OK to "-relief" option
	for buttons. [RFE: 4348]

	* win/tkWinWm.c (EX_TRANSIENT_STYLE): Removed WS_EX_TOOLWINDOW
	style bit, so that transient windows have full-size titlebars
	(like the tk_getOpenFile dialog).

	* win/tkWinMenu.c (GetMenuSeparatorGeometry): Tweaked height
	requested for separator bars to be (linespace - (2*descent))
	instead of just (linespace); this makes the separator occupy a
	more correct amount of vertical space. [Bug: 5303].

2000-05-09  Jeff Hobbs  <[email protected]>

	* library/focus.tcl: fixed calling of takeFocus proc [Bug: 5372]

2000-05-02  Jeff Hobbs  <[email protected]>

	* README:
	* generic/tk.h:
	* library/tk.tcl:
	* mac/README:
	* unix/README:
	* unix/configure.in:
	* unix/tk.spec:
	* win/README:
	* win/aclocal.m4:
	* win/configure.in:
	* win/makefile.vc: updated patchlevel to 8.4a1

	* unix/Makefile.in: added tk.spec to dist target

2000-04-27  Eric Melski  <[email protected]>

	* doc/Tk_Init.3: Added Tk_SafeInit information [Bug: 1884].

	* doc/keysyms.n: Man page enumerating keysyms [RFE: 1645].

	* doc/colors.n: Man page enumerating valid color names [RFE: 1645].

	* doc/cursors.n: Man page enumerating valid cursor values [RFE: 1645].

	* library/msgbox.tcl: Corrected Unix tk_messageBox implementation
	to make the first button the default when no default is specified
	[Bug: 2218].

	* doc/messageBox.n: Updated documentation with regards to
	selection of default button when none is specified (now it will
	use the first button as the default in that case) [Bug: 2218].

2000-04-26  Jeff Hobbs  <[email protected]>

	8.3.1 RELEASE

	* README:
	* mac/README:
	* unix/README:
	* unix/tk.spec:
	* win/README: Updating URLs to reference dev.scriptics.com

2000-04-25  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in: makefile cleanup

2000-04-25  Eric Melski  <[email protected]>

	* generic/tkMain.c: Fixed function header comment for Tk_MainEx.

	* unix/mkLinks:
	* doc/GetScroll.3: Added information about Tk_GetScrollInfoObj
	[Bug: 1866].

2000-04-24  Eric Melski  <[email protected]>

	* unix/mkLinks:
	* doc/Grab.3: Man page for Tk_Grab and Tk_Ungrab [Bug: 1868, 1889]

	* unix/mkLinks:
	* doc/MainWin.3: Added entry for Tk_GetNumMainWindows [Bug: 1865].

	* unix/mkLinks:
	* doc/GetHINSTANCE.3: Man page for Tk_GetHINSTANCE [Bug: 1862].

2000-04-24  Jeff Hobbs  <[email protected]>

	* generic/tkImage.c (Tk_PostscriptImage): added check to create
	necessary prolog for photos
	* generic/tkCanvPs.c: added Tk_PostscriptPhoto that outputs PS for
	photo images
	* generic/tkImgPhoto.c: new func ImgPhotoPostscript and added that
	in as ps proc in tkPhotoImageType.
	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tk.decls: added Tk_PostscriptPhoto

	* generic/tkConfig.c (DoObjConfig): removed direct setting of
	interp->result.

	* mac/tkMacWm.c (Tk_WmCmd): initialized gotToplevel in
	colormapwindows case (bug found by Reasoning, Inc's automated code
	testing).

2000-04-24  Eric Melski  <[email protected]>

	* unix/mkLinks:
	* doc/GetHWND.3: Man page for Tk_GetHWND [Bug: 1863].

	* unix/mkLinks:
	* doc/HWNDToWindow.3: Man page for Tk_HWNDToWindow [Bug: 1869].

	* unix/mkLinks:
	* doc/AddOption.3: Man page for Tk_AddOption [Bug: 1854]

2000-04-22  Jim Ingham	<[email protected]>

	* mac/tkMacDialog.c (Tk_MacGetOpenFile): Add empty bodies for the
	"-initialfile" and "-defaultextension" options.

	* mac/tkMacDialog.c (NavServicesGetFile): Only cons the result up
	into a list if multiple is true.

	* mac/tkMacMenus.c (SourceDialog): Use the "tk_getOpenFile"
	instead of hand-coding the dialog with StandardGetFile.  This way
	we get the Navigation dialogs for free.

	* doc/getOpenFile.n: Document the -multiple and -message flags
	which are only implemented on the Mac.  Also note that the -title
	works on the Mac with Nav Services installed.

2000-04-19  Eric Melski  <[email protected]>

	* doc/WinViewable.3:
	* unix/mkLinks: Removed docs for Tk_IsViewable.

	* win/tkWinDialog.c: Removed calls to Tk_IsViewable.

	* generic/tkUtil.c:
	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tkCmds.c:
	* generic/tk.decls: Removed Tk_IsViewable function (it was not
	actually needed).

2000-04-19  Jeff Hobbs  <[email protected]>

	* win/aclocal.m4: made SC_PROG_TCLSH search specifically for
	tclsh*.exe type files to find an executable.

	* win/Makefile.in: fixed up cleanup, winhelp, cat32 targets

	* library/console.tcl: made console use systemfixed font on Win

	* generic/tkEntry.c: removed unnecessary ENTRY_VALIDATE #define

2000-04-19  Eric Melski  <[email protected]>

	* generic/tkRectOval.c (ConfigureRectOval): Added checks for valid
	outline settings before creating of outline GC; this means that it
	is really possible now to have an oval or rectangle with no
	outline.  [Bug: 5029].

2000-04-19  Jeff Hobbs  <[email protected]>

	* library/choosedir.tcl (::tk::dialog::file::chooseDir::Config):
	* library/tkfbox.tcl (::tk::dialog::file::Config): removed the
	extraneous glob on -initialdir after file isdir already returned 1
	and moved cd trick into this case as the else already uses [pwd].
	[Bug: 5181]

	* win/winMain.c: moved extern call out of WinMain func

	* README:
	* generic/tk.h:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in: bumped to version 8.3.1

	* library/msgbox.tcl (tkMessageBox): changed to use grid in some
	places, realign icon to anchor nw.

	* mac/tkMacScale.c: reverted tkMacScale.c to 1.5 equivalent (it
	was accidentally bumped forward).

2000-04-18  Eric Melski  <[email protected]>

	* win/tkWinPointer.c: Changed Mod2Mask in TkWinGetModifierState to
	ALT_MASK, to fix some event problems [Bugs: 1160, 5088].

	* win/tkWinX.c: Changed Mod2Mask in GetState to ALT_MASK, to fix
	some event problems [Bugs: 1160, 5088].

	* generic/tkInt.h: Moved definition of ALT_MASK and META_MASK here
	so that it would be accessible from other modules than tkBind.c.

	* generic/tkBind.c: Added code in BindEvent to check for ALT_MASK
	and META_MASK in the event state field, as this field may not be
	set up with the correct display modifier mask bits if the XEvent
	structure was created by [event generate] or by the Windows X
	emulation. [Bugs: 1160, 5088].

2000-04-18  Scott Redman  <redman@HILO>

	* win/tk.rc:
	* win/wish.rc:
	* win/wish.ico:  Modified copyright dates in Windows resource
	files.  Updated the icon for wish.exe.

2000-04-17  Eric Melski  <[email protected]>

	* win/tkWinDialog.c: Added checks for visibility of parent window
	before creating MessageBox and ChooseColor dialogs; this prevents
	the application from locking when the parent is withdrawn and the
	message box is created.  In these cases, the window will be
	created without a parent.

	* unix/mkLinks: Added WinViewable.3.

	* tests/msgbox.test: Added tests for patch from [Bug: 4997].

	* library/msgbox.tcl:
	* library/dialog.tcl: Applied patch from [Bug: 4997]; detaches
	dialog window from parent if parent is not viewable.

	* library/bgerror.tcl: Removed workaround from [Bug: 4370]; this
	is superceeded by patches to dialog.tcl.

	* generic/tkCmds.c: Changed WinfoObjCmd to use Tk_IsViewable
	function to determine visibility of windows instead of inlining
	the code.

	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tk.decls: Added Tk_IsViewable declaration.

2000-04-17  Eric Melski  <[email protected]>

	* library/text.tcl: Tweaked double-/triple-click selection;
	previously, anchor and insert marks were placed in unexpected
	locations following a double or triple click.  Now they are placed
	logically.  Also tweaked the extension of selection via
	shift-double-clicks so that it no longer selects the contiguous
	whitespace on the side of the selection opposite the
	double-click. [RFE: 4253].

	* doc/menu.n: Added note regarding rendering of
	checkbuttons/radiobuttons in menubars on different platforms --
	some systems do not draw indicators for check/radiobuttons in
	menubars.

	* library/menu.tcl: Corrected behavior of
	checkbuttons/commands/radiobuttons in menubars [Bug: 630].

	* tests/grid.test: Added test for [grid propagate . 0] to not toggle.

	* generic/tkGrid.c: Fixed bogus logic in [grid propagate] that
	caused [grid propagate . 0] to act as a toggle instead of an
	absolute set. [Bug: 2286].

2000-04-16  Jeff Hobbs  <[email protected]>

	* win/tkWinColor.c (FindSystemColor): correct calculation of
	colors when shifting value. [Bug: 4919]

2000-04-16  Jim Ingham  <[email protected]>

	* mac/tkMacPort.h: protect against strncasecmp already defined -
	it is in the Pro5 version of MSL.

	* mac/tkMacWindowMgr.c (GenerateKeyEvent): Check for a null tkWin.
	If the hidden window we use for double-buffering controls manages
	to percolate to the top (should never happen, but...) this will
	keep us from crashing.

	* mac/tkMacButton.c (InitSampleControls): Hide the
	double-buffering window BEHIND the first "." window you can find.
	This will keep it from ever being the front window, and thus a
	black hole for events.  * mac/tkMacButton.c (ButtonEventProc):
	Disable the controls when the window is in the background.  This
	is required by the MacOS HIG. This doesn't always get called when
	it should, it still needs more work.

	* mac/tkMacDialog.c: Pretty substantial rewrite to include
	Navigation Services support for systems which have it.

2000-04-14  Eric Melski  <[email protected]>

	* win/tkWinKey.c: Added check for ASCII delete character in
	KeycodeToKeysym, to fix [Bug: 5090].  See comment in code for more
	information.

	* generic/ks_names.h: Added Scroll_Lock and Sys_Req definitions.

	* win/tkWinKey.c: Changed implementation of KeycodeToKeysym,
	et. al., to use a keycode table for lookups; this will result in
	faster keycode -> keysym translations for non-ASCII keys like
	Control, Alt, etc.

2000-04-14  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (WmProc): added check in WM_MOUSEACTIVATE so we
	correctly activate native menus when clicking in when we didn't
	have focus [Bug: 2272]

	* generic/tkCanvas.c (CanvasEventProc:2451): corrected cast

	* generic/tkEntry.c (Tk_EntryObjCmd): adjusted finishing error
	cases and changed TK_CONFIG_NULL_OK to TK_OPTION_NULL_OK

	* tests/scale.test:
	* generic/tkScale.c:
	* generic/tkScale.h:
	* unix/tkUnixScale.c:
	* mac/tkMacScale.c: moved (PixelToValue|ValueToPixel|SetScaleValue)
	to tkScale.c.  Caused an associated variable to be immediately set
	[Bug: 4833]

	* library/scale.tcl (tkScaleActivate): reduced number of scale
	redisplays by checking current value of state before setting it
	again.  [Bug: 4191]

	* tests/winDialog.test: tk_chooseDirectory seems to get a noop
	from GetOpenFileName in the static build, hanging some tests.
	The tests were fixed to timeout (noop cause unknown).

	* unix/aclocal.m4 (SC_ENABLE_THREADS): enhanced the detection of
	pthread_mutex_init [Bug: 4359] and (SC_CONFIG_CFLAGS) added
	--enable-64bit-vis switch for Sparc VIS compilation [Bug: 4995]

2000-04-13  Eric Melski  <[email protected]>

	* win/tkWinKey.c: Added smarts to check whether the left or right
	Control, Shift, or Alt key was pressed.  [Bug: 870].

	* win/tkWinMenu.c: Corrected code that created separator items on
	menus; originally, it requested that the system be responsible for
	drawing those items, so it would ignore configuration items like
	the widget background.  Now, we draw the separators ourselves (as
	we do with every other kind of menu item already). [Bug: 1166].

	* win/tkWin3d.c:
	* unix/tkUnix3d.c: Applied patch from [RFE: 2501]: adds more
	sophisticated smarts to TkpGetShadows, so that the highlight of a
	very bright color is actually distinguishable from the color, and
	the shadow of a very dark color is similarly distinguishable from
	the color.

	* generic/tkCanvas.c: Applied patch from [Bug: 4202]; adds a check
	for NULL tkwin in Tk_CanvasEventuallyRedraw.

2000-04-12  Jeff Hobbs  <[email protected]>

	* test/winClipboard.test:
	* win/tkWinInt.h:
	* win/tkWinClipboard.c (UpdateClipboard):
	* win/tkWinX.c (GenerateXEvent): added updatingClipboard tsd and
	TkWinUpdatingClipboard accessor function to allow us to flag
	ourselves when we are the ones updating the clipboard.  This
	corrected inability to create our own clipboard types within a Tk
	application.  [Bug: 2338 4318]
	* win/tkWinTest.c (TestclipboardCmd): improved TestclipboardCmd
	with better error handling and obj'ification

2000-04-11  Eric Melski  <[email protected]>

	* msgcat.n: Added docs for new behavior from patch in [Bug: 4158].

	* msgcat.test: Added tests for new behavior from patch in [Bug:
	4158].

	* msgcat.tcl: Applied patch from [Bug: 4158], which enables
	msgcat::mc to search the entire namespace ancestry chain for
	message translations (ie, first it checks the current namespace,
	then the parent, then the parent's parent, etc).  Also allows the
	specification of additional args for msgcat::mc; if extra args are
	given, the [format] command is used to substitute the additional
	args in the translated message.

	* library/bgerror.tcl: Moved check for withdrawn state after check
	for tkerror; this was causing problems when tkerror was used.

2000-04-10  Eric Melski  <[email protected]>

	* library/bgerror.tcl: Added check for withdrawn state of . and
	unsetting of transient bit for .bgerrorDialog if . is not
	viewable; this protects against the application hanging on systems
	like Windows, where transient windows are withdrawn with their
	parents. [Bug: 4370].

	* tests/event.test: Added test for [event generate $widget
	<Alt-z>] [Bug: 4611].

	* tests/choosedir.test: Changed "namespace import ::tcltest" to
	"namespace import -force ::tcltest".

	* win/tkWinKey.c:
	* unix/tkUnixKey.c:
	* mac/tkMacKeyboard.c: Changed InitKeymapInfo to
	TkpInitKeymapInfo. [Bug: 4611].

	* generic/tkStubInit.c:
	* generic/tkIntDecls.h: Re-gen'd from tkInt.decls.

	* generic/tkInt.decls: Added TkpInitKeymapInfo to list of function
	decls.

	* generic/tkBind.c (HandleEventGenerate): Added code to initialize
	keymap info if necessary, and to correctly set modifier bits in
	XEvent structure create to handle [event generate] calls.
	Previously, the alt/meta bits were not set correctly, so [event
	generate $widget <Alt-z>] would always fail. [Bug: 4611]

2000-04-07  Jeff Hobbs  <[email protected]>

	* generic/tkGrid.c (InitMasterData): fixed uninit'd data in
	GridMaster struct [Bug: 4387]

	* library/safetk.tcl (disallowTk): made disallowTk work in the
	simple case.

	* library/comdlg.tcl (tkFocusGroup_In): fixed key navigation
	problems in dialogs under CDE [Bug: 2960]

	* tests/winDialog.test: removed knownBug constraint from 5.16

	* win/tkWinFont.c (GetScreenFont): corrected adjustment against
	LC_FACESIZE limitation for NT [Bug: 4931]

	* win/makefile.vc (TKTEST_OBJS):
	* win/Makefile.in (TKTEST_OBJS): moved tkWinTest.c from normal
	objs to TKTEST_OBJS where it belonged.

2000-04-03  Jeff Hobbs  <[email protected]>

	* generic/tkTest.c: fixed incorrect platform inclusion for
	TkplatformtestInit (it would never get called).

	* unix/Makefile.in (MAN_INSTALL_DIR): patch to accept --mandir
	correctly [Bug: 4085]

	* library/clrpick.tcl (tkColorDialog_Config): error now thrown
	when -initialcolor "" specified. [Bug: 4198]

2000-03-31  Jeff Hobbs  <[email protected]>

	* doc/DrawFocHlt.3: doc name correction

	* generic/tkEntry.c: set TK_OPTION_NULL_OK bit on -invcmd option
	and removed #ifdef ENTRY_VALIDATE expressions

	* library/menu.tcl (tkMenuInvoke): corrected naming of tearoffs
	[Bug: 4506]

	* library/tkfbox.tcl (tkIconList_Goto): caused browsecmd to be
	called in tkIconList_Select.  This causes the entry to be set
	properly when using the type-in-name-in-listbox bindings.

	* win/tkWinDialog.c: added unicode-aware open/save file dialogs

	* win/tkWinFont.c (TkpFontPkgInit): move private ref to platformId
	to TkWinGetPlatformId

	* win/tkWinMenu.c (SetDefaults): moved private use of versionInfo
	to TkWinGetPlatformId and removed all code for
	(versionInfo.dwMajorVersion < 4) (== Win32s)

	* win/tkWinX.c:
	* win/tkWin32Dll.c: moved TkWinGetPlatformId to tkWinX.c
	* win/tkWinInit.c: added TkWinXInit to TkpInit to ensure that its
	called for static Windows shells. [Bug: 3647]

	* win/tkWinInt.h:
	* win/tkWinX.c:
	* win/tkWinDraw.c (SetUpGraphicsPort):
	* win/tkWinScrlbr.c (UpdateScrollbar): removed use of tkpIsWin32s

	* win/tkWinInt.h (TkWinDCState struct): added bkmode value
	* win/tkWinDraw.c (TkWinGetDrawableDC, et al): added support for
	properly transparent dashed lines on Windows. [Bug: 4617]

2000-03-30  Eric Melski  <[email protected]>

	* generic/tkImgGIF.c: Fixed some ANSI specific bits to avoid
	compile problems with non-ANSI compilers (ie, replace const with
	CONST, etc).  [Bug: 4223].

	* unix/configure.in: Applied patch from [Bug: 4237]; ensures that
	srcdir is fully qualified.

	* unix/Makefile.in: Applied patch from [Bug: 4237]; if tcltest was
	not compiled, make test/tktest failed.  Now it has a rule to build
	tcltest if it has not been built.

2000-03-28  Eric Melski  <[email protected]>

	* library/tkfbox.tcl: Moved an overlooked tkFDialog* function in
	::tk::dialog::file namespace.

	* tests/unixWm.test: Added tests for memory leak conditions in
	tkUnixWm.c.

	* tests/canvas.test: Added test for bad configuration options on
	empty and non-empty canvas.

	* generic/tkCanvas.c: Removed bad code in CANV_CONFIGURE block of
	CanvasWidgetCmd; this was causing non-empty canvases to improperly
	handle bad configuration options [Bug: 4456].

2000-03-27  Eric Melski  <[email protected]>

	* unix/tkUnixWm.c: Applied patch from [Bug: 4405]; fixes memory
	leak in Unix wm command.

2000-03-24  Eric Melski  <[email protected]>

	* tests/filebox.test:
	* tests/choosedir.test: Updated tests.

	* library/xmfbox.tcl: Updated to stash data array in
	::tk::dialog::file namespace instead of in global namespace.

	* library/tkfbox.tcl: Extended some functions to support creation
	of a choosedir dialog, to allow greater code reuse between the two
	dialogs.  Moved tkFDialog* functions into a namespace
	(::tk::dialog::file).  Because these are private Tk functions (and
	should thus not be used directly by users), this should not impact
	anybody (the tk_getOpenFile and tk_getSaveFile commands still
	exist at the global scope).

	* library/tk.tcl:
	* library/tclIndex: Updated function names for tkFDialog*
	functions and choosedir functions.

	* library/choosedir.tcl: New and improved implementation of
	tk_chooseDirectory dialog.  Based on tk_getOpenFile dialog.

2000-03-23  Eric Melski  <[email protected]>

	* generic/tkWindow.c:
	* generic/tkInt.h: Updated Tcl_OptionCmd -> Tcl_OptionObjCmd

	* generic/tkOption.c: Tcl_Obj'ectified the "option" command.

2000-03-22  Eric Melski  <[email protected]>

	* library/listbox.tcl (tkListboxCancel): Added a check for empty
	string value for tkPriv(listboxPrev).  Without this check, it's
	possible to get a stack trace under certain conditions. [Bug: 4373].

2000-03-15  Sven Delmas  <[email protected]>

	* win/tkWinDialog.c: Changed the behavior for the
	tk_chooseDirectory dialog under Windows. Instead of trying to
	return the currently selected listbox entry (which didn't work in
	case the user selected the initial directory anyway), we now
	return the value shown in the entry. This seems to be in
	accordance with the expected behavior for this dialog.

2000-03-14  Eric Melski  <[email protected]>

	* tests/choosedir.test: Marked test 3.1 and 3.2 as bad until the
	issue with those tests on IRIX can be determined.

2000-03-10  Eric Melski  <[email protected]>

	* library/menu.tcl: Applied patch from [Bug: 4155]; protects
	against grabs on non-viewable windows.

2000-03-08  Eric Melski  <[email protected]>

	* tests/choosedir.test: Modified test 3.1 (-mustexist works) to be
	more careful about cleaning up its potentially troublesome after
	events.

2000-03-07  Eric Melski  <[email protected]>

	* tests/button.test:
	* generic/tkButton.c: Added -disabledforeground/-state to labels.

2000-03-07  Jeff Hobbs  <[email protected]>

	* tests/entry.test:
	* generic/tkEntry.c (EntrySetValue): malloc the value when
	validating because validation could cause the pointer to become
	invalid.  Also fixed configure to not trigger focus-based
	validation.  Improved use of Tcl_WrongNumArgs. [Bug: 4320]

2000-03-06  Eric Melski  <[email protected]>

	* library/menu.tcl: Added a check in tkMenuFirstEntry that changes
	menu behavior to only auto-post an immediate child cascade if we
	are currently on a menubar menu.  This prevents massive
	auto-cascading in cases where the first entry of the cascade is
	itself a cascade, and the first entry of that cascade is a
	cascade, and the first entry of that cascade is a cascade
	... [Bug: 676].

	* generic/tkOldConfig.c: Added check for NULL tkwin value in
	Tk_ConfigureWidget [Bug: 4079]

	* generic/tkWindow.c: Added check for NULL tkwin value in
	Tk_NameToWindow [Bug: 4079]

2000-03-02  Jeff Hobbs  <[email protected]>

	* tests/color.test:
	* xlib/xcolors.c (XParseColor FindColor):
	* win/tkWinColor.c (XAllocColor): Fixed bit fiddling for colors to
	return "correct" values for color mapping. [Bug: 4282]

	* unix/Makefile.in (SCRIPT_INSTALL_DIR): removed extraneous '/'
	* unix/aclocal.m4: corrected TCL_NEEDS_EXP_FILE to be 1 for AIX

	* win/tkWinInt.h: change extern to EXTERN for TkWinChildProc
	declaration with extra #defs. [Bug: 4240]

	* library/focus.tcl: fixed tkFocusOK to protect $w in
	uplevel with list. [Bug: 4208]

	* doc/CrtItemType.3: fixed docs for Tk_CreateItemType to reflect
	changes made in 8.3.0 (but old style would still work as well).
	[Bug: 4252]

	* tests/config.test: extra test to check object cleanup when
	destroying the widget
	* generic/tkListbox.c (DestroyListbox): fixed crash in
	DestroyListbox due to null tkwin.  [Bug: 4207]

	* tests/entry.test: added test suite for entry validation
	* doc/entry.n: improved docs discussing caveats and gotchas when
	mixing textvar with widget validation
	* generic/tkEntry.c (EntryValidateChange): improved handling of
	validation with relation to -textvariable.  Previously, it would
	turn off whenever the textvar was set.  Now it will it will turn
	off only when the textvar is set and validation returns 0.  Added
	%V (type of validation occuring) to %-subs to help work with
	trickier validation.

2000-03-01  Eric Melski  <[email protected]>

	* tests/clrpick.test:
	* library/clrpick.tcl: Added code to make color chooser dialog
	inherit screen setting from parent (bug #2334)

2000-02-25  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (RaiseWinWhenIdle): Checked for the possibility
	that the window could be destroyed (can occur with
	wm deiconify .toplevel; destroy .toplevel).

2000-02-25  Eric Melski  <[email protected]>

	* generic/tkImgGIF.c: Applied "spirit of" the patch in 1605 (the
	submitted patch was more complicated than necessary and did not
	extend to writing GIF's, only reading), to allow reading/writing
	of GIF files on EBCDIC and other non-ASCII based systems.

2000-02-14  Eric Melski  <[email protected]>

	* unix/tk.spec: RPM specification for producing a binary Tk RPM
	for Linux.

	* unix/Makefile.in: Added rpm target to generate Tk
	binary RPM.

2000-02-10  Jeff Hobbs  <[email protected]>

	8.3.0 RELEASE

	* changes: updated for 8.3.0 release

	* generic/tkImgGIF.c (FileReadGIF): added cast for trashBuffer

	* generic/tkIntXlibDecls.h:
	* generic/tkInt.decls: declared some Xlib emulation calls for
	the Mac

	* generic/tkFrame.c (TkInstallFrameMenu): added extra panic to
	inform user of bad call when framePtr is NULL [Bug: 2530]

	* generic/tkMenu.c (DestroyMenuInstance): Placed checks around
	menu name objects before trying to incr the ref.  [Bug: 3402]

	* generic/tkTest.c: removed USE_OLD_IMAGE def for Mac

	* library/listbox.tcl:
	* library/text.tcl: added support for <4> and <5> for mousewheel
	style scrolling on Unix for mice that map to these buttons.

	* tests/scrollbar.test: fixed check of testmetrics command to
	allow unix tests to run (testmetrics is mac/pc only)

	* unix/tkUnixWm.c (Tk_CoordsToWindow): qualified delete of error
	handler as the goto label is reached from above and below.

	* unix/configure.in:
	* unix/aclocal.m4: cleaned up macros to coincide with tcl.m4,
	added -export-dynamic to LDFLAGS for FreeBSD-3+ [Bug: 2998]

	* unix/README:
	* unix/Makefile.in (dist): removed porting.notes and porting.old
	from distribution and CVS.  The information was very outdated.  Now
	refer to http://dev.scriptics.com/services/support/platforms.html

	* xlib/xgc.c: #def'd out XDrawSegments for the Mac, and added
	some extra include info for the Mac

2000-02-09  Jim Ingham  <[email protected]>

	* mac/tkMacButton.c: Stop removing the appearance window from the
	Window List.  It is not clear why Ray did this, and it causes the
	Appearance manager to crash at random times.

	* mac/tkMacWM.c: Add support in unsupported1 style for the Appearance
	specification of window styles, including floating window support.
	* mac/tkMacWindowMgr.c: Operate on the front non-floating window,
	unless the mouse is directly over the floating window.  Also,
	keystrokes go to the front non-floating window.
	* mac/tkMacAppInit.c: Initialize floating window support.
	* mac/tkMacScrlbr.c:
	* mac/tkMacmenu.c: Fixes for floating windows - operate on the
	FrontNonFloatingWindow.
	* mac/tkMacLibrary.r: Fix typo in File info string.
	* mac/tkMacApplication.r: Fix typo in file info string.  Add
	Finder balloon help for no apparent reason.

	* mac/tkMacSubwindows.c: Change panic in tkMacGetDrawablePort to
	Debugger.  This is only a temporary fix.  The panic is only
	triggered when a safeTk interpreter is torn down, and ignoring it
	does no harm.  I haven't figured out how to avoid it yet, however.
	Also use the Appearance MoveWindowStructure call when available.

	New Files:
	* MW_TkOldImageHeader.h: Handle #defining USE_OLD_IMAGE for tkImgPPM.c.
	* MW_TkTestHeader.h:
	* MW_TkTestHeader.pch:
	* MW_TkHeader.h: Add separate prefix files for test & release
	versions of Tk, so we can just have separate targets w/o having to
	edit files.

	* tclets.r: The D&D Tclets icon in rez form so we can have a
	target for this.

	The above are curtesy of Daniel Steffen ([email protected])

	* tkMacAppearanceStubs.c: Stubs of the Mac Appearance calls I use
	so I can link the static 68K Shell without putting ifdef's all
	over the code.

2000-02-08  Jeff Hobbs  <[email protected]>

	* generic/tk.decls:
	* generic/tkBind.c:
	* generic/tkInt.decls:
	* generic/tkIntDecls.h:
	* generic/tkStubInit.c:
	* mac/tkMacKeyboard.c:
	* unix/tkUnixKey.c:
	* win/tkWinKey.c: Fix for keyboard handling of "dead" keys and
	caps lock from Peter Spjuth. [Bug: 4105 3359 2493]
	Split functions into platform specific files:
	Static functions GetKeySym(), SetKeycodeAndState() and InitKeymapInfo()
	from tkBind.c moved into platform files tkWinKey.c tkUnixKey.c and
	tkMacKeyboard.c.  GetKeySym() and SetKeycodeAndState() renamed to
	Tkp* and made public (as private functions) in tkInt.decls.

	Step 2, fixes in tkWinKey.c
	New static function: KeycodeToKeysym(), based on XKeycodeToKeysym()
	but with different arguments, and a lot of improvements.
	TkpGetString() changed to use KeycodeToKeysym() + other fixes.
	TkpGetKeySym() changed to use KeycodeToKeysym() + other fixes.
	InitKeymapInfo() changed to use KeycodeToKeysym().
	TkpSetKeycodeAndState() rewritten, mostly by copying code from
	XKeysymToKeycode().
	XKeycodeToKeysym() rewritten. Preferably it should be removed.

	EXPLANATION: The main problem is ToAscii() which has a lot of side
	effects, and also that XKeycodeToKeysym() is not provided enough
	input to do a proper job.  The changes' main goal is to avoid
	calling ToAscii() if not necessary, and to provide it with as
	correct information as possible when called.  Also some attempts
	to clean up what ToAscii() did are done.  See the code for details.

	BUGS FIXED: Typing shifted (and AltGr) dead keys did not work.
	Keyboard lock lamps did not work on Win98.
	Events regarding AltGr-keys behaved badly.
	Example: On a Swedish keyboard, $ is typed with AltGr-4.
	That keyboard event would get the keysym '4' not 'dollar'.
	Also, doing [event generete . <Key-dollar>] would send keysym '4'.
	Translation to ascii in TkpGetString did not handle return and
	tab correctly. I.e. [event generate . <Key-Return>] gave wrong %A

	* generic/tkDecls.h:
	* generic/tk.decls:
	* generic/tk.h: moved new public functions created in dash patch
	to the stubs interface [Bug: 4062]

	* generic/tk.h:
	* doc/CrtImgType.3:
	* doc/CrtPhImgFmt.3:
	* generic/tk.h:
	* generic/tkImgGIF.c:
	* generic/tkImgPhoto.c:
	* generic/tkStubImg.c (new file):
	* generic/tkTest.c:
	* unix/Makefile.in:
	* win/Makefile.in:
	* win/makefile.vc: improved support for moving from the old style
	image C API to the new obj'ified one with new Tk_InitImageArgs
	command and stub'ing of image code.  See docs for how to make the
	transition. [Bug: 4060]

	* library/tk.tcl: wrapped check for tcl_platform(os) around info
	exists because it won't in safe interpreters

	* win/tkWinFont.c: corrected symbol font use to only work on 8-bit
	characters [Bug: 2406]

	* unix/aclocal.m4: changed all -fpic to -fPIC

	* README:
	* unix/configure.in:
	* win/configure.in:
	* generic/tk.h (TK_RELEASE_SERIAL): Moved to 8.3.0 patchlevel

2000-02-07  Eric Melski  <[email protected]>

	* library/tkfbox.tcl: Applied patch from bug #4117,
	tk_getOpenFile/getSaveFile doesn't do the right thing when user
	types a directory name in the entry and a default extension is
	specified.

2000-02-05  Jeff Hobbs  <[email protected]>

	* unix/tkUnixScale.c (TkpDestroyScale): changed ckfree to
	Tcl_EventuallyFree to behave with Tcl_Preserve in TkpDisplayScale
	(prevents possible segfault).

2000-02-03  Eric Melski  <[email protected]>

	* tests/canvText.test: test for fix for bug #2525.

	* generic/tkFont.c (Tk_ComputeTextLayout): Was erroneously setting
	the width of newline-only text display chunks to some arbitrary
	huge number, instead of 0; this was interfering with things like
	the canvas find enclosed feature. (bug #2525).

	* tests/text.test:
	* generic/tkText.c (DumpLine/DumpSegment): Changed DumpSegment to
	take a TkTextIndex instead of two integer offsets, so that it
	could use TkTextPrintIndex to format the offsets into an index,
	which makes it UTF smart (bug #2582).

2000-02-01  Eric Melski  <[email protected]>

	* library/tk.tcl:
	* library/tclIndex:
	* library/choosedir.tcl: Moved choosedir functions into the
	::tk::dialog::chooseDir namespace instead of a toplevel
	::tkChooseDirectory namespace.  Additional cleanup on the
	chooseDir dialog.

2000-02-01  Jeff Hobbs  <[email protected]>

	* doc/text.n: clarified docs on what happens during a search with
	-count when images/windows are embedded

	* win/Makefile.in (install-*): reduced verbosity of install

	* win/tkWinPixmap.c (XGetGeometry): added support for windows in
	XGetGeometry [Bug: 4069]

	* win/tkWinFont.c (GetScreenFont): fixed possible mem overrun with
	long font names [Bug: 4108]

	* win/tkWinDialog.c: added EnableWindow calls to dialogs to
	correct for possible loss of control in parent Tk toplevel
	[Bug: 1212 et al]

	* generic/tkRectOval.c (ConfigureRectOval):
	* generic/tkCanvLine.c (ConfigureLine):
	* generic/tkCanvPoly.c (ConfigurePoly):
	* generic/tkCanvArc.c (Configure/DisplayArc): fixed handling for
	negative dash values [Bug: 4104]

	* generic/tkScale.c (TkRoundToResolution): fixed incorrect
	assumption that (N+1)*delta = N*delta + delta with floating point
	math [Bug: 3689, 4099]
	(DestroyScale) Fixed check for cancelling TkpDisplayScale (was
	REDRAW_ALL, is now REDRAW_PENDING)

	* tests/listbox.test: corrected test case for listbox itemconfigure

	* unix/aclocal.m4: added *BSD ELF recognition for
	SHARED_LIB_SUFFIX determination (from Tcl's tcl.m4)

2000-01-27  Eric Melski  <[email protected]>

	* generic/tkImgPhoto.c: Removed unneccesary object translation in
	MatchStringFormat (bug #4103).

2000-01-27  Eric Melski  <[email protected]>

	* generic/tkImgGIF.c: Additional code cleanup (now we only have
	one decoder!  neat!)

2000-01-26  Eric Melski  <[email protected]>

	* doc/getOpenFile.n:
	* doc/chooseDirectory.n: Man page/cross links for
	tk_chooseDirectory (bug #1786).

	* library/tk.tcl:
	* library/tclIndex: Added hooks for tk_chooseDirectory. (bug #1786)

	* library/choosedir.tcl: tk_chooseDirectory implementation for
	Unix/Mac (bug #1786).

	* generic/tkImgPhoto.c: Added some comments regarding slow
	processing of transparent images.

	* generic/tkImgGIF.c: Improved GIF decoder for ~60% speed
	increase.  Added some comments on how to further improve the
	implementation, time permitting.

	* doc/photo.n: Added a description of what the -data string can
	contain (base64 or binary data).

	* generic/tkImgPhoto.c: Fixed bug with use of binary data for
	"-data" option to "image create" command.

2000-01-21  Eric Melski  <[email protected]>

	* library/tkfbox.tcl: Fixed bug relating to incorrect parent
	values for error message boxes displayed by the file dialog (bug
	#3616).

	* tests/text.test:
	* generic/tkText.c: Fixed bug relating to regexp searching for
	empty lines; previously, the starting line was ignored. (bug #1643).

2000-01-20  Jeff Hobbs  <[email protected]>

	* library/text.tcl: fixed double-click selection behavior where
	there were embedded windows/widgets in the same line. [Bug: 3989]

	* win/tkWinWm.c (TkWmProtocolEventProc): cached atom name as the
	window could get destroyed during eval [Bug: 2513]

	* generic/tkCanvLine.c (LineCoords): fixed segfault when too few
	coords were passed to a line with certain options set (it should
	always have thrown an error anyway). [Bug: 4042]

	* tests/text.test:
	* generic/tkText.c: fixed missing " in error case and missing
	'dump' in subcommand listing [Bug: 4036]

	* generic/tkListbox.c: adjusted use of basic string concatenation
	in (non-K&R behavior) [Bug: 4027]
	Swapped bg/fg class for -select(bg|fg) for listbox and their
	items [Bug: 4039]

	* unix/mkLinks:
	* doc/WindowId.3: added docs for Tk_IsContainer and Tk_IsEmbedded

	* doc/text.n: clarified mark gravity definition and usage of
	``word'' in binding definitions.  [Bug: 2004 2277 1388]

	* generic/tkInt.h: moved new TkDisplay useInputMethods structure
	element to end to not disturb position of previous elements in
	the structure (as compared to Tk <=8.2).

2000-01-20  Eric Melski  <[email protected]>

	* tests/grid.test: Added a test for the consecutive ^ and multiple
	widget case (bug #1386).

	* generic/tkGrid.c: Fixed interpretation of consecutive ^
	characters in grid command.  Previously, ^ ^ was interpreted as
	meaning that there must be a 2-column widget above to extend,
	neglecting the case where there was actually 2 1-column widgets
	above.  Now, ^ ^ is interpreted as a possible width; the gridder
	will consume as many ^'s as there are columns in the widget, and
	leave the rest for the extension of other widgets.  (bug #1386).

2000-01-19  Eric Melski  <[email protected]>

	* library/tk.tcl: Created a virtual event <<PrevWindow>> for
	reverse tab traversals, with one default binding <Shift-Tab>, and
	OS specific bindings for Linux, HP-UX, and IRIX. (bug #3163)

2000-01-13  Jeff Hobbs  <[email protected]>

	* changes: updated changes file to reflect 8.3b2 mods
	* README:
	* generic/tk.h:
	* unix/configure.in:
	* win/configure.in: updated to patchlevel 8.3b2

	* win/tkWinWm.c: added visibility event handler to make sure
	that transient window wrappers would be updated when the master
	was initially mapped.

2000-01-12  Jeff Hobbs  <[email protected]>

	* tests/text.test: changed test to reflect change of -hidden
	to -elide in search options.

	* win/tkWinScrlbr.c: added check for valid hwnd in ModalLoopProc
	to avoid crash when building statically

	* doc/event.n:
	* generic/tkBind.c: prevented core with event -warp on Windows
	when window wasn't mapped [Bug: 4004] and added docs stating
	the requirement for mapped windows.

	* generic/tkCanvas.c: fixed mem leak with TagSearchExprInit
	[Bug: 3977]

	* generic/tkStubInit.c:
	* generic/tkDecls.h: remove non-existent
	Tk_(Get|Create)CanvasVisitor prototypes

	* generic/tkText.c:
	* generic/tkEntry.c: fixed cursor to not blink when widget was
	disabled [Bug: 1807]

	* generic/tkRectOval.c: added note about change to bloat for
	RectOval bounds calculation for WIN32 only

	* library/dialog.tcl: improved handling of $default arg to allow
	for name of given button, as well as bounds checking

	* doc/wm.n:
	* tests/winWm.test:
	* tests/unixWm.test:
	* mac/tkMacWm.c:
	* unix/tkUnixWm.c: fixed possible X error being raised [Bug: 3377]
	* win/tkWinWm.c: wm deiconify in zoom state [Bug: 2077],
	fixed possible flashing of unmapped toplevel in deiconify [Bug: 3338]
	and fixed mapping of transient window [Bug: 572]
	Also, for all wm's, extended 'wm state' command to allow setting
	of the state, and added official support of 'zoomed' state on Win.

	* unix/aclocal.m4: strtod bug on Tru64 [Bug: 3378]

	* unix/Makefile.in: added tests to prevent unnecessary chmod +x
	in source dirs while installing [Bug: 3367]

	* unix/configure.in: properly sub'ed in TK_SHARED_BUILD [Bug: 3385]

2000-01-05  Jeff Hobbs  <[email protected]>

	* doc/text.n:
	* generic/tkText.c:
	* generic/tkText.h:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextTag.c: removed the -state option for text tags,
	and reoriented it around -elide, as -state disabled was never
	implemented, and -state hidden is better as -elide.

	* mac/tkMacClipboard.c: fixed i18n problems with clipboard [Bug: 3544]

	* library/entry.tcl:
	* library/focus.tcl:
	* library/listbox.tcl:
	* library/scale.tcl:
	* library/scrlbar.tcl:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl: fixed unprotected arg parsing through eval/after
	[Bug: 3943]

	* unix/Makefile.in: added unix/aclocal.m4 to distribution [Bug: 3938]
	* unix/aclocal.m4: changed NetBSD SHLIB_CFLAGS from -fpic to -fPIC

	* win/tkWinImage.c: added static declaration to function

1999-12-22  Jeff Hobbs  <[email protected]>

	* changes: updated changes file

	* generic/tkScale.c:
	* generic/tkScale.h:
	* mac/tkMacScale.c:
	* unix/tkUnixScale.c: fixed potential segv from patch in 3897

	* tests/unixWm.test: nonPOrtable -> nonPortable

1999-12-21  Jeff Hobbs  <[email protected]>

	* generic/tk.h:
	* unix/configure.in:
	* win/configure.in:
	* win/aclocal.m4:
	* README: updated for patch level 8.3b1

	* unix/tkUnixWm.c: fixed panic in Tk_CoordsToWindow to print error
	and continue instead (for Tix) [Bug: 716 et al]

	* scale.test:
	* generic/tkScale.c:
	* generic/tkScale.h: fixed possible core when freeing options
	(cursor) associated with scale widget [Bug: 3897]

	* doc/MeasureChar.3: fixed docs for Tk_MeasureChars to reflect code
	* doc/listbox.n: fixed formatting problem

	* generic/tk3d.c: added extra calculations to ensure that thin
	frames get refreshed too [Bug: 3596]

	* unix/tkUnixMenu.c:
	* unix/tkUnixFont.c:
	* generic/tkCanvText.c:
	* generic/tkEntry.c:
	* generic/tkFont.c:
	* generic/tkImgPPM.c: removed extranneous vars that were set but
	never used.

	* mac/tclMacHLEvents.c: fixed applescript for I18N [Bug: 3644]

	* unix/aclocal.m4: removed -O flag for AIX when using the IBM
	compiler (several versions have a bug that crops up in the text
	widget). [Bug: 2316]

	* unix/Makefile.in: removed extra slash in SCRIPT_INSTALL_DIR
	[Bug: 3896]

	* library/listbox.tcl: added extra checks for existence of
	tkPriv(listboxSelection) before it was used. [Bug: 3892]

1999-12-16  Jeff Hobbs  <[email protected]>

	* doc/GetCursor.3:
	* win/tkWinCursor.c: added support for Windows cursors to
	TkGetCursorByName (.ani, .cur) using -cursor @<filename>
	(Ascher) [Bug: 1350]

	* win/tkWinWm.c: fixed 'wm deiconify' to update position of the
	toplevel if event is waiting before mapping. (Mao) [Bug: 3687]
	This removes the need for 'update idle' before 'wm deiconify' on
	Windows.

	* doc/listbox.n: added doc for <<ListboxSelect>> [Bug: 3500]

	* doc/getOpenFile.n: removed note that -initialfile didn't work
	for tk_getOpenFile
	* library/tkfbox.tcl: updated tk_get*File to better match the
	Windows file box it emulates, give proper support to -initialfile,
	and fixes lack of global tkPriv call.  [Bug: 3735 3882]

	* doc/tk.n: added doc for 'tk useinputmethods ...'
	* tests/tk.test:
	* unix/tkUnixKey.c:
	* generic/tkCmds.c:
	* generic/tkEvent.c:
	* generic/tkWindow.c:
	* generic/tkInt.h: add 'tk useinputmethods ?-display win? ?bool?'
	call to provide support for disabling/enabling the use of XIM on
	X.  This was previously all done at compile time, and always on.
	Now it is turned off by default, even when available, and the user
	must turn it on to use XIM (per display).

	* generic/tkCanvUtil.c: fixed bug in Tk_CanvasPsOutline that freed
	mem it shouldn't.

	* generic/tkFont.c: added "bitstream cyberbit" (popular Windows
	CJK font) to list of font fallbacks. (kenny) [Bug: 2407]

	* mac/tkMacMenu.c: finished bug 3075 by changing the char values of
	what was checked (verified correctness on Mac).

1999-12-13  Jeff Hobbs  <[email protected]>

	* doc/canvas.n: added docs for items added by dash patch (-*dash*,
	-state, -active*, -disabled*, -offset, essentially rewrote the
	man patch for completely updated 8.3 canvas widget.
	* doc/entry.n: added docs for entry widget validation
	* doc/event.n: added docs for -warp
	* doc/text.n: doc'ed new -state value 'hidden'
	* doc/GetDash.3: (new file) man page explaining Tk_GetDash
	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkInt.decls: added XSetDashes and XWarpPointer
	* generic/tk.decls: added Tk_CreateSmoothMethod, and reserved
	two spots
	* generic/tk.h: added Tk_SmoothMethod struct,
	state item to canvas record, #defines for item state,
	support for using old char*-based canvas item C creation
	procedures with -DUSE_OLD_CANVAS,
	Tk_Dash, Tk_TSOffset (-offsets) & Tk_Outline structs and #defs,
	decls for dash, outline and postscript routines
	* generic/tkBind.c: added support for Quadruple clicks, and added
	the -warp option to 'event' with pointer warping routines
	* xlib/xgc.c:
	* generic/tkRectOval.c:
	* generic/tkCanvArc.c:
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvPs.c:
	* generic/tkCanvText.c:
	* generic/tkCanvUtil.c:
	* generic/tkCanvWind.c:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h: Canvas and items received overhaul to with
	the addition of the dash patch (Nijtmans, et al)  This includes
	objectification of the 'canvas' command, as well as support for
	(where appropriate) dashes in items, extended stipple support,
	state for all items, and postscript generation of images and
	windows.  See the new canvas man page for related docs.
	* generic/tkEntry.c: added entry widget validation, see entry.n
	* generic/tkEvent.c: on simulated events, ButtonPress should
	be matched with ButtonRelease to be correct
	* generic/tkFont.c: corrected possible null reference
	* generic/tkFrame.c: made frame a Tcl_Obj based command
	* generic/tkGet.c: added TkGetDoublePixels
	* generic/tkImage.c: bug fixes from Img patch and new
	Tk_PostscriptImage and Tk_SetTSOrigin functions
	* generic/tkImgBmap.c: new ImgBmapPostscript function
	* generic/tkImgPhoto.c: new Tk_CreatePhotoOption, Tk_DitherPhoto
	* generic/tkInt.h: declarations for some new functions
	* generic/tkMessage.c: reworked relief drawing
	* generic/tkOldConfig.c: added TK_CONFIG_OBJS so old style
	ConfigureWidget calls can pass in Tcl_Obj arrays
	* generic/tkScrollbar.c:
	* generic/tkScrollbar.h: made -orient use an option table
	* generic/tkText.c:
	* generic/tkText.h: made -wrap and -state use option tables
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextMark.c:
	* generic/tkTextTag.c:
	* generic/tkTextWind.c: added support for -elide and -state hidden
	* generic/tkTrig.c: changed TkMakeBezierCurve to support returning
	the upper limit of points needed for spline
	* generic/tkUtil.c: new option table parsing routines
	* generic/tkWindow.c: init'ing of warp stuff, mouseButtonState

	related bug ids for the fixes:
	[Bug: 648 1541 1540 1779 2168 2311 2297 2340 2348 2578 3386]

	* tests/bind.test:
	* tests/canvImg.test:
	* tests/canvPsArc.tcl:
	* tests/canvPsImg.tcl: (new file)
	* tests/canvRect.test:
	* tests/canvText.test:
	* tests/canvas.test:
	* tests/defs.tcl:
	* tests/entry.test:
	* tests/event.test:
	* tests/font.test:
	* tests/frame.test:
	* tests/imgPhoto.test:
	* tests/safe.test:
	* tests/scale.test:
	* tests/scrollbar.test:
	* tests/select.test:
	* tests/text.test:
	* tests/textDisp.test:
	* tests/textTag.test:
	* tests/unixFont.test:
	* tests/unixWm.test:
	* tests/visual_bb.test:
	* tests/winClipboard.test: tests for the dash patch changes

	* unix/mkLinks: added GetDash.3 into the mkLink step

	* mac/tkMacDraw.c: mac still needs pointer warping routine
	* mac/tkMacXStubs.c:
	* win/tkWinDraw.c:
	* win/tkWinPointer.c: added support for pointer warping and
	platform specific support for dash patch items

1999-12-12  Jeff Hobbs  <[email protected]>

	* generic/tkText.c: fixed bug in TextSearchCmd for multibyte chars
	(Darley) [Bug: 3839]

	* unix/aclocal.m4: added warning when configuring with
	--enable-threads that Tk may have problems

1999-12-09  Jeff Hobbs  <[email protected]>

	* generic/tkImgGIF.c: updated casting

	* win/makefile.vc: removed 16bit stuff, simplified makefile.

1999-12-06  Scott Redman  <[email protected]>

	* generic/tkMain.c: need to include tclInt.h for new hook
	functions that are internal-use-only.

1999-12-06  Jeff Hobbs  <[email protected]>

	* library/comdlg.tcl: removed tclVerifyInteger and tclSortNoCase,
	they weren't used, and were not actually correct

	* mac/tkMacFont.c:
	* mac/tkMacMenu.c:
	* mac/tkMacWindowMgr.c: fixed greyed out menu items, handling of
	... elipsis, font mapping problem, and enabled generated menu
	posting [Bug: 3705]

1999-12-02  Jeff Hobbs  <[email protected]>

	* generic/tkInt.h:
	* generic/tkWindow.c:
	* generic/tkCmds.c: converted Tk_DestroyCmd, Tk_LowerCmd and
	Tk_RaiseCmd to their ObjCmd equivalent.

	* library/msgbox.tcl: added color icons for tk_messageBox on Unix
	and Mac when tk_strictMotif isn't set. (Hipp)
	* library/tk.tcl: added window bounds checking to ::tk::PlaceWindow

	* tests/imgPPM.test: fixed test 2.2 to use -format ppm (since
	we know have GIF write capability)

1999-12-01  Scott Redman <[email protected]>

	* generic/tkMain.c :
	* unix/tkAppInit.c:
	* win/winMain.c: Added added hooks into the main() code for
	supporting TclPro and other "big" shells more easily without
	requiring a copy of the main() code.

1999-11-29  Jeff Hobbs  <[email protected]>

	* generic/tkImgGIF.c: added GIF writing that uses miGIF RLE
	[Bug: 2039, new patch]

	* library/entry.tcl: fixed up tkEntrySeeInsert (Nemthi)

	* generic/tkListbox.c: fixed 'get' of listbox to return a string
	when only one item is requested.

	* tests/clrpick.test:
	* tests/filebox.test: minor whitespace cleanup

	* library/tk.tcl: fixed missing $w in ::tk::PlaceWindow

1999-11-24  Jeff Hobbs  <[email protected]>

	* library/clrpick.tcl:
	* library/msgbox.tcl:
	* library/tk.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl: fixed dialogs to center over -parent,
	added utility functions ::tk::PlaceWindow, ::tk::SetFocusGrab,
	::tk::RestoreFocusGrab to tk.tcl to help

1999-11-23  Eric Melski  <[email protected]>

	* tests/listbox.test: Added a test to check that the topIndex is
	update when items are removed from the listvar variable.

	* generic/tkListbox.c: Added a check the updates the topIndex when
	items are removed from the listvar variable.

	* tests/listbox.test: Added a test to check that the vertical
	scrollbar is updated when the listvar changes.

	* generic/tkListbox.c (ListboxListVarProc): added a check that
	sets the UPDATE_V_SCROLLBAR flag if the length of the listvar has
	changed.

1999-11-23  Jeff Hobbs  <[email protected]>

	* generic/tk.h:
	* generic/tkConfig.c: added support for TK_OPTION_DONT_SET_DEFAULT
	as equiv for TK_CONFIG_DONT_SET_DEFAULT
	* generic/tkListbox.c: added TK_OPTION_DONT_SET_DEFAULT to the
	item specs

1999-11-19  Jeff Hobbs  <[email protected]>

	* generic/tkColor.c:
	* generic/tkColor.h: fixed Tk_NameOfColor to work correctly,
	with minor change to TkColor struct.

	* generic/tkConsole.c: added static declaration to
	ConsoleDeleteProc function (proto already had it)

	* win/tkWinInt.h: removed TkFontAttributes typedef (was
	redundant with tkFont.h).
	* win/tkWinPort.h: put #ifndef __GNUC__ around redefinition
	of str[n]casecmp, as cygwin uses the originals.
	* win/tkWinX.c: changed GetCurrentTime to GetTickCount (the
	former is deprecated).  [Bug: 2053]

1999-11-19  Eric Melski  <[email protected]>

	* tests/listbox.test: Added tests for itemcget and itemconfigure.

	* doc/listbox.n: Added documentation for -listvar option and for
	itemconfigure and itemcget commands.

	* generic/tkListbox.c: Added support for itemconfigure/itemcget
	listbox subcommands (addresses rfe #936)

1999-11-17  Eric Melski  <[email protected]>

	* tests/listbox.test: Updated tests for new error messages.

	* generic/tkListbox.c: Improved error messages for bad -listvar's.

	* tests/listbox.test: Added tests for bad -listvar's.

	* generic/tkListbox.c: Added handlers for bad -listvar's (ie, bad
	lists)

	* tests/listbox.test: Added tests for ListboxUpdateHScrollbar.

	* generic/tkListbox.c: Changed some old static buffers to base
	size on TCL_DOUBLLE_SPACE instead of (completely) hardcoding the size.

	* tests/listbox.test: New tests for -listvar functionality, and an
	odd extra case that wasn't covered before.

	* generic/tkListbox.c: Tests exposed some bugs, now fixed.

1999-11-16  Eric Melski  <[email protected]>

	* tests/listbox.test: Fixed tests to comply with new objectified
	error messages.  No -listvar specific tests yet.

	* win/tkWinDefault.h:
	* unix/tkUnixDefault.h:
	* mac/tkMacDefault.h: Added default value for -listvar option.

	* generic/tkWindow.c: Changed "listbox" mapping from old-school to
	new-school objectified command.

	* generic/tkListbox.c: Objectified listbox; added support for
	-listvar option.  Converted internal structure to use a Tcl list
	object to store the data.

	* generic/tkInt.h: Changed reference to Tk_ListboxCmd to
	Tk_ListboxObjCmd.

1999-11-09  Jeff Hobbs  <[email protected]>

	* generic/tkGrid.c: changed Tcl_Alloc to ckalloc

	* generic/tkEntry.c: fixed C expr error in destroy of entry
	that could lead to 'malformed bucket chain' error

	* win/winMain.c: corrected winMain to not do a DebugBreak when
	returning an error message from the top level

1999-10-30  Jeff Hobbs  <[email protected]>

	* win/tkWinKey.c: fixed XKeysymToKeycode to handle mapping of
	symbolic keysyms (Left, Home, ...) with event generate

	* library/entry.tcl: change tkEntrySeeInsert to avoid the use
	of a while loop that could eat CPU tremendously.  Behavior of
	moving the cursor at the right edge changes slightly (previously
	it tried to keep the cursor at the right edge, now it moves the
	cursor to a "central right" location - better IMHO).

1999-10-28  Jeff Hobbs  <[email protected]>

	* doc/CrtImgType.3:
	* doc/CrtPhImgFmt.3:
	* doc/FindPhoto.3:
	* doc/photo.n:
	* generic/tk.h:
	* generic/tkCmds.c:
	* generic/tkImage.c:
	* generic/tkImgBmap.c:
	* generic/tkImgGIF.c:
	* generic/tkImgPPM.c:
	* generic/tkImgPhoto.c:
	* generic/tkInt.h:
	* generic/tkTest.c:
	* generic/tkWindow.c:
	* tests/imgPhoto.test: added Img patch (Nijtmans) with docs,
	headers #def'd with USE_OLD_IMAGE.  Upgrades image stuff to
	Tcl_Obj API, adds alpha channel (images are now 32 bpp)

	* makefile.vc: changed 'c:/program files' to c:/progra~1

1999-10-19  Jeff Hobbs  <[email protected]>

	* library/scrlbar.tcl: changed tkScrollButtonUp to check for
	existence of tkPriv(relief) in order to avoid spurious release
	events

	* unix/Makefile.in: added ChangeLog to dist archive

1999-09-24  Jeff Hobbs  <[email protected]>

	* */README:
	* win/makefile.vc:
	* */configure.in:
	* generic/tk.h:
	* library/tk.tcl: up'd to 8.3a1

	* unix/Makefile.in: changed 'mkdir' to 'mkdir -p'

	* library/dialog.tcl: changed {Times 18} to {Times 12} for
	dialog font.

1999-09-16  Jeff Hobbs  <[email protected]>

	* generic/tkFont.c: fixed processing of font options and error
	returned [Bug: 2075]

	* win/tkWinWm.c: fixed bug in 'wm deiconify' that raised the
	wrong toplevel, and changed it to not set focus on overridden
	toplevels

1999-09-15  Jeff Hobbs  <[email protected]>

	* unix/aclocal.m4: added fix for FreeBSD-[1-2] recognition [Bug: 2070]
	and fix to AIX-* to get ldAix right [Bug: 2624], fixed AIX
	version check (readjust from 8-21 fix) and several other config
	fixes for AIX
	* mac/tkMacMenubutton.c:
	* unix/tkUnixMenubu.c: fixed permanently stippled menubutton image
	* win/tkWinButton.c: fixed possible pointer smash [Bug: 2733]

1999-09-14  Jeff Hobbs  <[email protected]>

	* win/tkWinMenu.c: fix for stack overrun in GetTextFace [Bug: 909]

1999-09-01  Jeff Hobbs  <[email protected]>

	* win/tkWinDraw.c:
	* unix/tkUnixDraw.c: fixed header style for TkpDrawHighlightBorder
	* generic/tkCanvas.c: fixed GC error (bg <> fg) in tkCanvas.c
	(from code added to support TkpDrawHighlightBorder) [Bug: 2676]
	* unix/aclocal.m4: added -bnoentry to the AIX-* flags
	* library/msgbox.tcl: changed the behavior of tk_messageBox on
	Unix to be more Windows like in handling of <Return> and the
	default button
	* library/button.tcl:
	* library/clrpick.tcl:
	* library/comdlg.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/focus.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/palette.tcl:
	* library/safetk.tcl:
	* library/scale.tcl:
	* library/scrlbar.tcl:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl: updated commands to use [string] ops
	instead of expr equality operators

1999-08-21  Jeff Hobbs  <[email protected]>

	* unix/aclocal.m4: Changed AIX-4.[2-9] check to AIX-4.[1-9]
	[Bug: 1909]

1999-08-20  Jeff Hobbs  <[email protected]>

	* generic/tkCursor.c: fixed bug in GetCursorFromObj that caused
	panic [Bug: 2562]

	* TK 8.2.0 RELEASED

1999-08-13  Jim Ingham  <[email protected]>

	* mac/tkMacMenu.c: Tk_DrawChars ends up setting the menu background
	wrong.	There is no clean way to stop it, so I use lower level routines
	here to draw the text.
	* mac/tkMacProjects.sea.hqx: Rearrange the projects so that the build
	directory is separate from the sources.  Much more convenient!

1999-08-10  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c: changed "wm deiconify" on Windows to raise and
	force the focus on the deiconified window (behavioral change from
	8.1 to comply better with Windows style) [Bug: 1609]
	* doc/wm.n: clarified behavior of "wm deiconify".
	* generic/tkInt.decls: added TkSetFocusWin
	* generic/tkFocus.c: changed static SetFocus to TkSetFocusWin

	* library/clrpick.tcl:
	* library/console.tcl:
	* library/tk.tcl: fixed code where abbreviations where used
	in calling widget methods (confuses iWidgets) [Bug: 2422]

1999-08-09  Jeff Hobbs  <[email protected]>

	* library/button.tcl: cleaned up programming (config -> configure)
	and fixed Windows relief bug [Bug: 664]
	* library/entry.tcl: changed Entry C/C/P to not use global data
	(now uses tkPriv(data)) [Bug: 1475]
	* library/listbox.tcl: fixed extended mode script error [Bug: 866]
	* doc/options.n: clarified that -troughcolor doesn't work on Windows
	* doc/wm.n: fixed wm positionfrom docs [Bug: 2284]

1999-08-01  Jeff Hobbs  <[email protected]>

	* mac/tkMacPort.h: wrapped panic in #ifndef panic to avoid
	compiler errors when used with stubs-#defines, from Vince Darley.
	[Bug: 2389]

1999-07-31  Scott Redman  <[email protected]>

	* xlib/X11/Xlib.h: Remove XFillRectangle since it is now in the
	stub tables.

1999-07-30  Jeff Hobbs  <[email protected]>

	* generic/tkInt.decls: Added stub entry for XFillRectangle [Bug: 2446]

1999-07-30  Scott Redman  <[email protected]>

	* win/makefile.vc: Corrected building threaded tktest.exe on
	Windows.  Needed to link in .obj files from Tcl, needs to change
	later so that code is in Tk and doesn't require a Tcl build.
	Also added runtest target.

1999-07-29  Scott Redman  <[email protected]>

	* generic/tkConsole.c: Allow tcl to open CON and NUL, even for std
	channels.  Checking for bad/unusable std channels was moved to Tk
	since its only purpose was to check whether to use the Tk Console
	Window for the std channels.  [Bug: 2393 2392 2209 2458]

	* win/Makefile.in: Corrected building threaded tktest.exe on
	Windows.  Needed to link in .obj files from Tcl, needs to change
	later so that code is in Tk and doesn't require a Tcl build.

1999-07-22  Scott Redman  <[email protected]>

	* Changed version to 8.2b2

	* win/tkWinPort.h: Block out include of sys/stat.h in order to
	build extensions with MetroWerks compiler for Win32. [Bug: 2385]

	* unix/Makefile.in: Need to make install-sh executable before
	calling (with chmod +x).  [Bug: 2413]

	* library/menu.tcl: Applied patch from Jeff Hobbs to fix typo.
	[Bug: 2425]

1999-07-21  Scott Redman  <[email protected]>

	* unix/Makefile.in: Add Windows configure script to distribution.

1999-07-16  Scott Redman  <[email protected]>

	* unix/Makefile.in:
	* win/Makefile.in:  Copy the prolog.ps from the generic directory
	for install-libraries.

	* unix/aclocal.m4: Check for Alpha/Linux to set the IEEE flag to
	the compiler to be -mieee.  Patch from Don Porter.

1999-07-08  Scott Stanton  <[email protected]>

	* tests/unixSelect.test: Fixed broken test.

	* win/makefile.vc: Added special case target to ensure that
	tkStubLib.obj is built with -DSTATIC_BUILD.

	* win/tkWinX.c (TkWinChildProc): Changed to pass
	WM_WINDOWPOSCHANGED through to DefWindowProc to make OpenGL
	sub-windows happy.  This allows Windows to generate the WM_SIZE
	and WM_MOVE messages.

1999-07-08  Scott Redman  <[email protected]>

	* unix/configure.in: Fix Tk stub lib file names and flags.

1999-06-30  Scott Redman  <[email protected]>

	* generic/tkGrid.c: removed deprecated functions (applied patch
	from Jan Nijtmans). [Bug: 2080]

	* generic/tkImgGIF.c:
	* generic/tkImgPPM.c:
	* generic/tkImgPhoto.c: Applied patch to allow Img extension to
	work with 8.2, from Jan Nijtmans. [Bug: 2068]

	* win/tkWinWm.c: Applied patch from Don Porter to prevent the
	windows code from calling the Tcl functions when the stub table
	has not been initialized in TkWinWmCleanup.  [Bug: 2269]

1999-06-16  Michael Thomas  <[email protected]>

	* unix/configure.in:
	* unix/Makefile.in:
	* unix/aclocal.m4: Numerous build changes to make Tk conform to
	the proposed TEA spec

	* tkConsole.c: changed some variable types from (int) to (size_t)
	to prevent compiler warnings.  Cast return value from strlen()
	to (int) in one place for the same reason.

1999-06-03  Scott Stanton  <[email protected]>

	* unix/tkUnixSelect.c:
	* tests/unixSelect.test:
	* generic/tkSelect.c: Fixed selection code to handle Unicode data
	in COMPOUND_TEXT and STRING selections. [Bug: 1791]

1999-06-02  Scott Stanton  <[email protected]>

	* generic/tkIntXlibDecls.h:
	* xlib/X11/Xlib.h: Added Mac specific defines to help with
	compilation.

	* generic/tkFont.c: lint

1999-06-01  Scott Stanton  <[email protected]>

	* unix/tkUnixSelect.c: Improved I18N selection support.
	COMPOUND_TEXT is converted to/from iso2022, and STRING is
	converted to/from iso8859-1.  There are still a few loose ends to
	tie up before this is completely done.

	* unix/tkUnixFont.c: Eliminated redundant case folding code.

	* generic/tkFont.c: Eliminated use of isupper/tolower in favor of
	Unicode variants.

1999-05-24  Scott Stanton  <[email protected]>

	* generic/tkStubLib.c:
	* generic/tkStubInit.c:
	* generic/tkIntXlibDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntDecls.h:
	* generic/tkInt.decls:
	* generic/tkConsole.c: Various changes to try to get the Mac
	builds working.

1999-05-21  Scott Stanton  <[email protected]>

	* win/tkWinClipboard.c: Fixed clipboard code to handle lack of
	CF_LOCALE information (e.g. from command.com).

1999-05-20  Scott Redman  <[email protected]>

	* library/console.tcl: Changed copyright string to read 1999
	Scriptics Corp. in wish console about box.

1999-05-19  Scott Redman  <[email protected]>

	* generic/tk.h: Add extern "C" block around entire header file for
	C++ compilers to fix linkage issues.  Submitted by Don Porter and
	Paul Duffin.

1999-05-18  Scott Stanton  <[email protected]>

	* tests/winClipboard.test:
	* win/tkWinClipboard.c: Fixed clipboard code so it handles Unicode
	data properly on Windows NT and 95. [Bug: 1791]

1999-05-07  Scott Stanton  <[email protected]>

	* library/menu.tcl: Fixed bug where tk_popup fails when called too
	quickly. [Bug: 2009]

1999-04-30  Scott Stanton  <[email protected]>

	* Changed version number to 8.1.1.

1999-04-30  Scott Stanton  <[email protected]>

	* Merged changes from 8.1.0 branch:

	* generic/tkDecls.h:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: Changed to avoid the need for forward
	declarations in stub initializers.  Added extern "C" blocks around
	stub table pointer declarations so the stubs can be used from C++
	code. [Bug: 1934]

	* generic/tkInt.decls: Added TkClipBox, XDrawSegments, and
	XForceScreenSaver to stubs.

	* generic/tkStubLib.c: Reordered declarations to avoid
	circularities and forward references.

	* generic/tkStubInit.c: Added includes for Mac.

	* generic/tkMenubutton.c: lint

	* generic/tkEntry.c: Fixed bad option table entry.

	* generic/tkImgBmap.c:
	* generic/tkImgPPM.c:
	* generic/tkImgPhoto.c: Set the -translation and -encoding options
	to binary for image files. (reported by Marco Gazzetta)

1999-04-23  Scott Stanton  <[email protected]>

	* generic/tkInt.decls: Added TkClipBox, XDrawSegments, and
	XForceScreenSaver to stubs.

	* generic/tkStubLib.c: Reordered declarations to avoid
	circularities and forward references.

	* generic/tkStubInit.c: Added includes for Mac.

	* generic/tkMenubutton.c: lint

	* generic/tkEntry.c: Fixed bad option table entry.

1999-04-22  Scott Redman  <[email protected]>

	* generic/tkImgBmap.c:
	* generic/tkImgPPM.c:
	* generic/tkImgPhoto.c: Set the -translation and -encoding options
	to binary for image files. (reported by Marco Gazzetta)

1999-04-20  Scott Redman  <[email protected]>

	* xlib/X11/Xlib.h: changed definition of Status type to use a
	typedef instead of a #define to avoid conflicting with the cygwin
	win32 headers [Bug 1804]

1999-04-15  Scott Stanton  <[email protected]>

	* Merged 8.1 branch into the main trunk

1999-04-09  Scott Redman  <[email protected]>

	* generic/tkWindow.c: Fixed deadlock situation when the Initialize()
	function returns without releasing the mutex.  Found while testing
	Bug 1700, during safe.test (tk).

1999-04-06  Scott Stanton  <[email protected]>

	* generic/tkMain.c (Tk_MainEx): Changed to reset result before
	calling Tcl_EvalFile.  The ensures that error messages will be
	generated cleanly.

	* tests/winfo.test: Enabled tests that previously failed.

1999-04-05  Scott Stanton  <[email protected]>

	* library/bgerror.tcl:
	* library/button.tcl:
	* library/clrpick.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/focus.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/palette.tcl:
	* library/scale.tcl:
	* library/scrlbar.tcl:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tk.tcl: Lots of minor performance improvements
	contributed by Jeffrey Hobbs. [Bug: 1118]

	* win/tkWinWm.c (Tk_WmCmd): Fixed bad code in tracing
	suboption. [Bug: 1519]

	* library/tkfbox.tcl: Change to restore button text after an
	action to avoid the sticky "Open" button in a save dialog.
	[Bug: 1640]

	* library/entry.tcl: Fixed so selection is returned using the
	-show character during cut and paste operations. [Bug: 1687]

1999-04-5   Scott Redman  <[email protected]>

	* generic/tkInt.decls:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* xlib/xgc.c:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h: Added more X functions to the Win & Mac stubs
	tables.

1999-04-05  Scott Stanton  <[email protected]>

	* unix/configure.in:
	* generic/tkCanvPs.c: Added configure test for pw_gecos field in
	pwd to support OS/390. [Bug: 1724]

1999-04-02  Scott Stanton  <[email protected]>

	* tests/text.test:
	* generic/tkText.c: Fixed handling of Unicode in text searches.
	The -count option was returning byte counts instead of character
	counts. [Bug: 1056, 1148, 1666]

1999-04-01  Scott Redman  <[email protected]>

	* generic/tk.decls:
	* generic/tk.h:
	* generic/tkStubInit.c:
	* generic/tkWindow.c:
	* unix/Makefile.in:
	* win/makefile.vc: Tk now uses its own stub library to store
	pointers to its own stubs table.

	* doc/dde.n: (removed)
	* doc/send.n:
	* generic/tk.decls:
	* tests/winSend.test:
	* generic/tkPlatDecls.h:
	* win/tkWinSend.c:  Removed the DDE-based send and dde commands,
	they were causing Tk to lock up when any window on the system was
	not processing its message queue (more importantly, windows in Tcl
	and Tk).  The send command needs to be rewritten to prevent the
	deadlock situation (soon).  The dde command is being pushed into
	its own package and will provide almost all of the capabilities
	that send did before (using a "dde eval" command), not yet
	completed.

1999-03-31  Scott Redman  <[email protected]>

	* win/tkWinSend.c: Modified dde/send code to work properly on
	Win95/Win98. String lengths are not returned properly by DDE, so
	NULL terminate all strings going in and ignore the string length
	coming back out.  Do not destroy handles until all necessary work
	on those handles (and child handles) is done.

1999-03-30  Scott Stanton  <[email protected]>

	* generic/tkWindow.c (Tk_DestroyWindow): Image handlers are now
	finalized before the font subsystem since complex image handlers
	may contain references to fonts (e.g. Tix compound images).
	[Bug: 1603]

1999-03-29  Scott Stanton  <[email protected]>

	* doc/MeasureChar.3:
	* doc/TextLayout.3:
	* generic/tk.decls:
	* generic/tkCanvText.c:
	* generic/tkEntry.c:
	* generic/tkFont.c:
	* generic/tkListbox.c:
	* generic/tkMessage.c:
	* mac/tkMacFont.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixMenu.c:
	* win/tkWinFont.c:
	* win/tkWinMenu.c: Standardized text layout and font interfaces
	so they are consistent with respect to byte versus character
	oriented indices.  The layout functions all manipulate character
	oriented values while the lower level measurement functions all
	operate on byte oriented values.  This distinction was not clear
	and so the functions were being used improperly in a number of
	places.  [Bug: 1053, 747, 749, 1646]

	* generic/tk.decls: Eliminated uses of C++ STL types string and
	list from declarations.

	* generic/tkFont.c: Changes to named fonts were not being
	propagated in some cases. [Bug: 1144]

	* xlib/X11/Xlib.h:
	* generic/tkInt.decls: Added XParseColor to xlib stub
	tables. [Bug: 1574]

	* doc/GetBitmap.3:
	* generic/tkBitmap.c (BitmapInit): Eliminated use of Tk_Uid's in
	bitmaps.  Added a few CONST declarations.

1999-03-29  Scott Redman  <[email protected]>

	* unix/configure.in:
	* unix/Makefile.in:
	* win/makefile.vc:
	* generic/tkDecls.h:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkIntXlibDecls.h: Removed stub functions. Always use the
	Tcl stubs when building with --enable-shared.

1999-03-26  Scott Redman  <[email protected]>

	* generic/tkTextIndex.c:
	* tests/testIndex.test: Avoid looking past the beginning of the
	array storing data for the text widget (.t index end-2c).  Added
	test case to check for the bug.  [Bug 991]

	* generic/tkConsole.c: Copy static strings into a Tcl_DString
	before passing to Tcl_Eval, in case the compiler puts static
	strings into read-only memory.

1999-03-26  Suresh Ankolekar  <[email protected]>

	* unix/configure.in:
	--nameble-shared is now the default and builds Tk as a shared
	library; specify --disable-shared to build a static Tk library
	and shell.

1999-03-26  Bryan Surles  <[email protected]>

	* library/menu.tcl: Fixed bug reported by Bryan Oakley in the
	menubutton bindings.  There was a false assumption that there was
	always a menu attached to the button.  [Bug 1116]

1999-03-26  Scott Redman  <[email protected]>

	* unix/configure.in: Removed --enable-tcl-stub.  Linking Tk to Tcl
	stubs is causing too many problems when linking executables like wish.
	Until the Tk is a fully loadable extension, linking against the Tcl
	stubs is not supported in Tk.

1999-03-19  Scott Redman  <[email protected]>

	* generic/tkBitmap.c:
	* generic/tkCursor.c:
	* generic/tkGC.c: When creating hash tables that key off of XID
	handles, make sure to pass TCL_ONE_WORD_KEYS.  XIDs are guaranteed
	to be 32bit numbers, although on some 64bit systems (including 64bit
	Solaris 7) they are packed into a 64bit value where the upper 32bits
	are zero. The normal method of sizeof(XID)/sizeof(int) causes the
	hash table code to assume that the XID is a pointer to an array of
	two ints, which it is not.  Tk now supports 64bit Solaris 7.

1999-03-17  Scott Stanton  <[email protected]>

	* win/makefile.vc:
	* generic/tk.h: Changed to use TCL_BETA_RELEASE macro, and fixed
	so this works in rc files.

	* win/makefile.vc:
	* win/makefile.bc:
	* win/README:
	* unix/configure.in:
	* generic/tk.h:
	* README: Updated version to 8.1b3.

1999-03-14  Scott Stanton  <stanton@GASPODE>

	* unix/configure.in: Added missing stub related definitions.

	* unix/Makefile.in: Install tkDecls.h in addition to tk.h.

	* generic/tkStubLib.c: Added flags to ensure we are using Tcl
	stub macros.

1999-03-11  Scott Stanton  <stanton@GASPODE>

	* generic/tkInt.decls: Added reserved slot for XSetDashes for use
	by the dash patch.

1999-03-10  Scott Redman  <[email protected]>

	* xlib/xdraw.c:
	* xlib/X11/Xlib.h:
	* mac/tkMac.h:
	* mac/tkMacInt.h:
	* mac/tkMacPort.h:
	* mac/tkMacXStubs.c:
	* mac/tkMacAppInit.c:
	* mac/tkMacCursor.c:
	* win/makefile.vc:
	* win/tkWin.h:
	* win/tkWinInt.h:
	* win/tkWinPort.h:
	* win/winMain.c:
	* generic/tk.h:
	* generic/tkInt.h:
	* generic/tk.decls:
	* generic/tkInt.decls:
	* generic/tkDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubs.c:
	* generic/tkPlatStubs.c:
	* generic/tkIntStubs.c:
	* generic/tkIntPlatStubs.c:
	* generic/tkIntXlibStubs.c:
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkConfig.c:
	* generic/tkConsole.c:
	* generic/tkCursor.c:
	* generic/tkGrab.c:
	* generic/tkImgPhoto.c:
	* generic/tkMain.c:
	* generic/tkMenu.c:
	* generic/tkPointer.c:
	* generic/tkTextDisp.c:
	* generic/tkWindow.c:
	* unix/tkUnixInt.h:
	* unix/tkUnixPort.h:
	* unix/Makefile.in:
	* unix/configure.in:
	* unix/tkConfig.sh.in:
	* unix/tkUnix.c:
	* unix/tkUnix3d.c:
	* unix/tkUnixDraw.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixMenubu.c: Stubs implementation for 8.1.  Tk_Main() is
	replaced with a macro which calls Tk_MainEx(). Tk can link to the Tcl
	stubs library, wish links directly to Tcl and Tk. Use
	--enable-tcl-stubs to link Tk to the Tcl stubs library (Unix), on
	by default on Windows. Exported all public functions through the
	stubs mechanism (see the *.decls files) and many of the internal
	functions. Most of the changes dealt with shifting around the
	function declarations in the header files.  Mac code may not
	compile, but it shouldn't take much work to fix this.

	* mac/tkMacMenu.c: Added dummy TkpMenuThreadInit for Mac to be
	consistent with Unix and Windows versions.

1999-03-08  Lee Bernhard  <[email protected]>

	* win/tkWinWm.c: Toplevel class no longer shared between
	threads.

	* win/tkWinX.c: Multiple threads no longer share the same
	TkDisplay structure.  Required because TkDisplay stores much
	thread-specific data for a given thread.

	* win/tkWinSend.c: Moved application instance handle out
	out thread-local storage.  DDE was failing to initialize
	when the instance handles were different between threads.

	* win/makefile.vc: Added THREADDEFINES for building with
	threads enabled.

	* generic/tkMenu.c:
	* win/tkWinMenu.c:
	* unix/tkUnixMenu.c: Added TkpMenuThreadInit for initializing
	thread-specific Menu state.

1999-03-01  Scott Redman  <[email protected]>

	* win/tkWinWm.c:
	* win/tkWinPointer.c:
	* win/tkWinInt.h: Fix "focus -force" for Windows.  The Win32 API
	function SetForegroundWindow() does not work unless the window
	handle is a toplevel window (a Windows toplevel).  The handle
	being passed was a Tk toplevel, which is a child of the Windows
	toplevel.

1999-02-26  Scott Redman  <[email protected]>

	* win/cat.c: Remove this file, use the one in the Tcl source directory.

	* win/makefile.vc: Remove the wishc.exe from the default targets.  Add
	a separate console-wish target to build it.  The need for a
	console-wish will go away soon, so we don't want to encourage its
	use.

1999-02-25  Scott Redman  <[email protected]>

	* win/tkWinWm.c: Properly initialize the tsdPtr->firstWindow field.

	* win/cat.c: Code for cat32.exe, copied from the Tcl sources. Required
	in order to run the test suite from the makefile

	* win/winMain.c: Add main() for a console-based wishc.exe, which meant
	adding code to disable the call to Tk_ConsoleInit().

	* generic/tkConsole.c: Check the standard handles before creating the
	new standard channels.	This allows a windows app that has stdin,
	stdout, or stderr to correctly connect to them.

	* generic/tkMain.c: Add a proper check for the interactive mode, since
	the standard channels may actually be connected in windows mode or
	even in the console-based wish.

	* win/makefile.vc: Add targets for wishc.exe (console-based wish) and
	cat32.exe (for testing). Fix the test suite target so it can be run
	from the makefile (which can happen since the standard handles have
	been fixed).

1999-02-12  Lee Bernhard  <[email protected]>

	* generic/tkMenuButton.h:
	* generic/tkMenuButton.c:
	* mac/tkMacMenubutton.c:
	* mac/tkMacDefault.h
	* unix/tkUnixMenubu.c: Eliminated Tk_Uids used by -state option.
	* unix/tkUnixDefault.h
	* win/tkWinDefault.h

	* generic/tk.h:
	* generic/tkScale.h:
	* generic/tkScale.c:
	* generic/tkWindow.c:
	* unix/tkUnixScale.c:
	* unix/tkUnixDefault.h:
	* unix/tkWinDefault.h:
	* mac/tkMacDefault.h:  Objectified scale widget.

	* win/tkWinX.c: Removed Thread-specific data from process
	initialization code that was stopping the Tk Dll from
	loading.

1999-02-11  Scott Stanton  <stanton@GASPODE>

	* README:
	* generic/tk.h:
	* unix/configure.in:
	* win/README:
	* win/makefile.bc:
	* win/makefile.vc: Updated version to 8.1b2.

	* unix/tkUnixSend.c: Fixed one more Tcl_*ObjVar instance.

1999-02-04  Scott Stanton  <stanton@GASPODE>

	* Various cleanup related to the Tcl_Eval and Tcl_ObjSetVar
	changes in Tcl.

	INTEGRATED PATCHES FROM 8.0.5b2:

	* win/tkWinMenu.c (TkpDestroyMenu): Changed so modalMenuPtr is
	cleared when it is being destroyed.

	* generic/tkImgPhoto.c: Changed so color tables are freed
	immediately instead of being delayed.  This ensures that color
	tables are properly disposed at process exit.

	* library/prolog.ps: Changed string that determines font height to
	include European character with an umlaut.

	* generic/tkImgBmap.c (ImgBmapConfigureInstance): If an image
	mask changed but ended up with the same XID, the GC failed to be
	updated and so the new mask was not used. [Bug: 970]

	* generic/tkFocus.c (SetFocus): Changed so focus window is always
	set if -force is specified.  This fixes the problem on Windows
	where Tk does not activate the window if it already has focus.

	* generic/tkConsole.c: Fixed so errors in console eval are
	reported properly.  Eliminated duplicate result messages. [Bug: 973]

	* win/tkWinWm.c: Changed so windows that aren't resizable don't
	have resize handles and the zoom box is disabled.

	* win/tkWinInt.h:
	* win/tkWinPointer.c: Changed to cancel the mouse timer when a
	user initiated move/resize loop begins.

	* unix/configure.in: TK_LD_SEARCH_FLAGS was set incorrectly if
	SHLIB_LD_LIBS='${LIBS}', and shared linking is performed through
	the C compiler. Systems affected are Linux, MP-RAS and NEXTSTEP,
	but also with gcc on many more systems. [Bug: 908]

	* win/makefile.vc: First stab at install target.  Fixed quoting so
	paths with spaces work.

	* tests/main.test:
	* tests/unixWm.test: Better cleanup of temporary files.

	* mac/tkMacAppInit.c:
	* generic/tkTest.c:
	* generic/tkAppInit.c:
	* win/winMain.c: Changed some EXTERN declarations to extern
	since they are not defining exported interfaces.  This avoids
	generating useless declspec() attributes and makes the windows
	makefile simpler.

	* library/menu.tcl (tkMenuFind): Changed so keyboard shortcuts
	will only be found in the current toplevel.  Previously, they
	might be found in menus attached to other toplevels that might not
	even be mapped. [Bug: 924]

	* generic/tkCanvLine.c: Changed to treat zero width lines like
	they have width 1 for purposes of selection. [Bug: 925]

	* win/tkWinFont.c (Tk_MeasureChars): Added a workaround for a bug
	in GetTextExtentExPoint on Win NT 4.0/Japanese. [Bug: 1006]

	* unix/tkUnixSend.c (Tk_SetAppName): Fixed uninitialized memory
	access bug. [Bug: 919]

1999-1-28  Scott Stanton  <stanton@GASPODE>

	* generic/tkGrid.c: Fixed bug in "grid forget" that failed to cancel
	pending idle handlers, resulting in a crash in a few odd cases.

1999-01-06  Lee Bernhard  <lfb@JUSTICE>

	* generic/tk.h, generic/tkGet.c, generic/tkConfig.c,
	* generic/tkOldConfig.c, generic/tkEntry.c, generic/tkMenubutton.c,
	* generic/tkMenubutton.h, generic/tkScale.c, generic/tkScale.h,
	* generic/tkTextDisplay.c, generic/tkText.c, unix/tkUnixMenubu.c,
	* unix/tkUnixScale.c, mac/tkMacMenu.c, mac/tkMacMenubutton.c,

	Removed global Tk_Uids dealing with "-state" configuration option
	and added new TK_CONFIG_STATE configSpec that doesn't use
	Tk_Uids.

1998-12-11    === Tk 8.1b1 Release ===

1998-12-11  Scott Stanton  <stanton@GASPODE>

	* generic/tkMain.c (Tk_Main): Fixed improper command line encoding
	handling.

1998-12-08  Scott Stanton  <stanton@GASPODE>

	* win/tkWinClipboard.c (TkSelGetSelection, TkWinClipboardRender):
	Changed to handle multibyte characters properly. [Bug: 935]

1998-12-07  Scott Stanton  <stanton@GASPODE>

	* library/xmfbox.tcl (tkMotifFDialog_Create): In the cached case,
	the data array was not being initialized with the correct set of
	widgets.

1998-12-4  Brent Welch  <welch@SAGE>

	* Changed patchLevel to 8.1b1

	* generic/tkMenu.c (ConfigureMenuCloneEntries): The -menu configuration
	option was being incorrectly specified as just "menu".

1998-11-30  Scott Stanton  <stanton@GASPODE>

	* generic/tkButton.c (ConfigureButton): The error result was
	getting lost when restoring configuration options. [Bug: 619]

1998-11-25  Scott Stanton  <stanton@GASPODE>

	* unix/tkUnixFont.c (GetFontAttributes): Initialize an unspecified
	family to an empty string.
	(FontMapLoadPage): if the font included characters below 32, the
	index computation was incorrect because the range was shifted up
	to 32.
	(CreateClosestFont): check for empty locale as well as NULL.

	* generic/tkFont.c (TkFontParseXLFD): initialize charset to
	iso8859-1 if no charset is specified.

	* mac/tkMacHLEvents.c (OdocHandler): added conversion from
	external string to UTF [Bug: 869]

	* integrated tk8.0.4 changes.

	* generic/tkBind.c: fixed deletion order bug where a crash would
	result if a binding deleted "."

	* generic/tkMenu.c (MenuWidgetObjCmd): disabled menu entries were
	getting reenabled whenever the mouse passed over the entry [Bug: 860]

	* unix/tkUnixMenu.c (TkpComputeStandardMenuGeometry): hidemargin
	option was not honored properly in menus [Bug: 859]

1998-11-24  Scott Stanton  <stanton@GASPODE>

	* tkMacMenu.c, tkUnixMenu.c, tkWinMenu.c, tkMenuDraw.c, tkMenu.h,
	* tkMenu.c: Backed out the previous fix for bug 620 and
	eliminated a bunch of code that created unnecessary objects.
	Changed back to using internal types instead of objects for many
	configuration options.	There are many more fixes like this that
	could be made, but some require a little restructuring of the
	code. In any case the leaks are fixed and there is a lot less
	allocation happening. [Bug: 620]

1998-11-19  Scott Stanton  <stanton@GASPODE>

	* tkMenu.c (DestroyMenuEntry): fixed memory leaks [Bug: 620]

	* tkWinX.c (GetTranslatedKey): fixed bad code merge

	* tkWinWm.c, tkWinMenu.c: fixed titles and menus so they properly
	display Unicode [Bug: 819]

Added ChangeLog.2004.






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2004-12-29  Jeff Hobbs	<[email protected]>

	* win/tcl.m4, win/configure: update MSVC CFLAGS_OPT to -O2, remove -Gs
	(included in -O2) and -GD (outdated). Use "link -lib" instead of "lib"
	binary and remove -YX for MSVC7 portability. Add -fomit-frame-pointer
	for gcc OPT compiles. [Bug 1092952, 1091967]

2004-12-21  Donal K. Fellows  <[email protected]>

	* library/demos/*.tcl: Add [package require Tk] to all the widget demo
	scripts so they follow standard practice better. [FRQ 815118]

2004-12-20  Vince Darley  <[email protected]>

	* generic/tkFileFilter.c:
	* generic/tkFileFilter.h:
	* macosx/tkMacOSXDialog.c:
	* win/tkWinDialog.c:
	* tests/filebox.test:
	* tests/winDialog.test: Corrected handling of MacOS file types in
	tk_*file dialogs [Bug 1083878].

2004-12-20  Donal K. Fellows  <[email protected]>

	* doc/panedwindow.n: Fix silly typo. [Bug 1087842]

2004-12-19  Chengye Mao	 <[email protected]>

	* win/tkWin.h, win/tkWinEmbed.h: Make embedding work better on Windows.
	* win/tkWinWm.c, win/tkWinX.c:	 [Bugs 222677, 831627, 842945, 1024364]

2004-12-17  Chengye Mao	 <[email protected]>

	* generic/tkFrame.c:  Make container windows display their
	* generic/tkWindow.c: background when they don't have content.

2004-12-10  Donal K. Fellows  <[email protected]>

	* unix/tk.spec, macosx/Tk-Info.plist, macosx/Wish-Info.plist:
	* macosx/Wish.pbproj/project.pbxproj, README, win/configure.in:
	* unix/configure.in, generic/tk.h: Bump version to 8.5a3.

2004-12-09  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: synced with tcl/unix/tcl.m4
	* unix/configure: regen

2004-12-09  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock):
	Added guards so that rescanning for the complex-alpha check is not done
	in the common case of creating a simple image a bit at a time, or any
	other time where the image was simple before and the input data has no
	alpha channel. [Bug 1081966]

2004-12-07  Don Porter	<[email protected]>

	* tests/canvPs.test:	Cleaned up the matching of [makeFile] and
	* tests/choosedir.test: [removeFile] commands as indicated by the
	* tests/filebox.test:	results of a -debug 1 run of the test suite.
	* tests/imgPPM.test:	Tk test suite is now -debug 1 clean. This
	* tests/imgPhoto.test:	completes fixing [1078648].
	* tests/listbox.test:
	* tests/main.test:

2004-12-07  Donal K. Fellows  <[email protected]>

	* tests/bind.test, tests/button.test, tests/canvas.test:
	* tests/cursor.test, tests/scrollbar.test: Eliminate all duplicate test
	names. [Bug 1078648 again]

2004-12-06  Jeff Hobbs	<[email protected]>

	*** 8.5a2 TAGGED FOR RELEASE ***

2004-12-06  Don Porter	<[email protected]>

	* tests/safe.test:	Trim auto_path to improve performance [1080039]

2004-12-05  Jeff Hobbs	<[email protected]>

	* changes: updated for 8.5a2 release

2004-12-04  Donal K. Fellows  <[email protected]>

	* tests/*.test: Resolve duplicate test names. [Bug 1078648]

2004-12-03  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock): Make
	overlay compositing where the target is empty no longer set the target
	to magical gray, and also make sure that the complex-alpha flag is
	toggled when necessary. [Patch 848161]

2004-12-01  Jeff Hobbs	<[email protected]>

	* unix/tkUnixButton.c (TkpDisplayButton): constrain coords to
	Tk_RedrawImage to display only portion that is valid.
	* generic/tkImgPhoto.c (ImgPhotoDisplay): add X error suppression
	around XGetImage to prevent app abort. [Bug 979239]

2004-11-28  Joe English	 <[email protected]>

	* unix/tkUnixRFont.c(Tk_DrawChars): Check for short integer overflow in
	x,y coordinates [Fixes: Bug 942320 "Tk, Xft, text and long lines"]

2004-11-26  David Gravereaux  <[email protected]>

	* win/makefile.vc: Shell targets needed more stack space. [Bug 1066755]

2004-11-20  Vince Darley  <[email protected]>

	* tests/text.test: fix to test's platform sensitivities [Bug 1025871]
	* tests/textDisp.test: made test less timing sensitive [Bug 1034171],
	and fixed a platform-sensitive test [Bug 966845]

2004-11-19  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: reverted earlier changes for
	tclConfig.h changes to tcl, since those have been reverted for now.

	Note that newly added macosx/Wish.xcode will not work without
	tclConfig.h, this project has not been removed again.

2004-11-18  Reinhard Max  <[email protected]>

	* unix/tcl.m4 (SC_CONFIG_MANPAGES): Applied an improved version of
	* unix/configure.in:		    [Patch 996085], that introduces
	* unix/Makefile.in:		    --enable-man-suffix.

	* unix/installManPage:		    added
	* unix/mkLinks.tcl:		    removed
	* unix/mkLinks:			    removed
	* unix/configure:		    generated

2004-11-17  Jeff Hobbs	<[email protected]>

	* generic/tkCanvWind.c (ConfigureWinItem): unmap windows immediately
	when state hidden is requested. [Bug 982248]

	* generic/tkCanvImg.c (ImageToPostscript): don't try ps generation of
	canvas image item without image specified. [Bug 1032300]

	* library/console.tcl (::tk::console::ExpandVariable): correct array
	keyname expansion. [Bug 1004508] (bold)

	* generic/tkPanedWindow.c (Tk_PanedWindowObjCmd): set save_under X attr
	to prevent expose events when moving sash. [Bug 1036963]

2004-11-16  Vince Darley  <[email protected]>

	* doc/text.n: clarified documentation on use of -tabs option.

2004-11-16  Don Porter	<[email protected]>

	* library/msgs/it.msg: Updated Italian message catalog. Thanks to
	Roberto Ugoccioni [Bug 1063675].

2004-11-16  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/buildTkConfig.tcl: fixes for tclConfig.h changes.

	* macosx/Wish.pbproj/project.pbxproj: fixed references to renamed
	bitmap files.

	* macosx/Wish.xcode/project.pbxproj (new):
	* macosx/Wish.xcode/default.pbxuser (new):
	* macosx/Wish-Info.plist (new):
	* macosx/Tk-Info.plist (new): added new Xcode 1.5 project using native
	targets, made possible by tclConfig.h changes.

	* generic/tk.h: added version number change comments for new files.

2004-11-15  Vince Darley  <[email protected]>

	* generic/tkText.c: fix to multi-line search problem and removed
	* tests/text.test:  'knownBug' from one test.

2004-11-15  Donal K. Fellows  <[email protected]>

	* unix/tcl.m4, unix/configure.in: Expanded all AC_DEFINE calls to the
	three-argument form and ported recent changes to the tcl.m4 from the
	Tcl distribution. *No* call to AC_CONFIG_HEADERS has been added; this
	change should be virtually entirely cosmetic.

2004-11-12  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXXStubs.c: implemented XGetGeometry().

2004-11-12  Jeff Hobbs	<[email protected]>

	* generic/tkCmds.c (Tk_TkObjCmd): use correct screen data when
	-displayof arg is passed to [tk scaling]. [Bug 800178]

2004-11-12  Daniel Steffen  <[email protected]>

	* doc/SetOptions.3:
	* doc/text.n: fixed *roff errors uncovered by running 'make html'.

	* macosx/tkMacOSXFont.c (Tk_MeasureChars,Tk_DrawChars,etc): Make sure
	that the lastSubFontPtr remains valid even when the subfont array is
	reallocated. [Bug 618872]

2004-11-11  Reinhard Max  <[email protected]>

	* generic/tkEvent.c (InvokeInputMethods): Call XSetICFocus whenever the
	window receives focus. This fixes [Bug 905830] but avoids [Bug 1000051]

2004-11-11  Daniel Steffen  <[email protected]>

	* generic/tkMain.c:
	* macosx/tkMacOSXAppInit.c (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: changes to make TkAqua dynamically loadable,
	enabling [package require Tk] from tclsh. Startup code from
	tkMacOSXAppInit.c moved into tkMacOSXInit.c, added code that notifies
	the window server that an unbundled executable is a full GUI
	application after loading Tk. [Patch 1035348]

	* doc/wm.n: documented [wm attributes] on Mac OS X. [Bug 606665]
	* macosx/tkMacOSXWm.c: implemented TIP 222 [wm attributes -alpha] on
	Mac OS X. [Patch 892194]
	WmIconbitmapCmd: adopted FSRef changes from [wm atttrs -titlepath].

	* macosx/tkMacOSXSubwindows.c: synced spacing/formatting with
	core-8-4-branch.

	* generic/tkRectOval.c:
	* macosx/README:
	* macosx/tkMacOSXDefault.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXWm.c: forward port from core-8-4-branch of Jim's and
	my changes for CG drawing and [wm attributes] (corresponds to 8.4
	changes dating from 09-18, 07-27, 07-24).

	* macosx/tkMacOSXMouseEvent.c: endianness fixes.

	* macosx/Wish.pbproj/project.pbxproj: corrected path to html help
	inside framework.

	* macosx/Makefile: prevent parallel make from building several targets
	at the same time.

2004-11-09  Vince Darley  <[email protected]>

	* macosx/tkMacOSXButton.c: fix to dynamic reconfiguration of button
	'-compound' options (cosmetic problem), [Bug 1055023]

	* tests/text.test: added 'knownBug' 20.172.1 in text widget multiline
	search routines.

2004-11-08  Donal K. Fellows  <[email protected]>

	* library/demos/goldberg.tcl: Added slightly adapted version of Keith
	Vetter's tkGoldberg as the final animation demo. Many many thanks to
	Keith for giving his permission! [FRQ 627466]

2004-11-07  Peter Spjuth  <[email protected]>

	* doc/frame.n: Added some info for -width/-height options. [Bug
	1055423]

2004-11-07  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: Made handling of ^ a bit more consistent in corner
	cases. This makes ^ work without any widgets in the same command. [Bug
	962589]

2004-11-07  Donal K. Fellows  <[email protected]>

	* library/demos/pendulum.tcl:	Added demonstrations of how to do
	* library/demos/aniwave.tcl:	animations using Tcl/Tk to the widget
	* library/demos/anilabel.tcl:	demo.

2004-11-03  Don Porter	<[email protected]>

	* tests/button.test: Update expected results to account for more
	verbose errorinfo from errors in variable traces [Tcl Bug 572164]

2004-11-01  Don Porter	<[email protected]>

	* tests/dialog.test (dialog-1.1): Update expected result to changes in
	the error messages produced by procs.

2004-10-29  Mo DeJong  <[email protected]>

	* tests/wm.test: Add Win32 test cases for attributes subcommand.
	* win/tkWinWm.c (WmAttributesCmd): Fixup broken option processing logic
	for attributes subcommand.

2004-10-28  Mo DeJong  <[email protected]>

	* win/tkWin32Dll.c (DllMain, _except_dllmain_detach_handler): Rework
	pushing of exception handler function pointer so that compiling with
	gcc -O3 works. Remove empty function call to avoid compiler warning.
	Mark the DllMain function as noinline to avoid compiler error from
	duplicated asm labels in generated code.

2004-10-28  Pat Thoyts	<[email protected]>

	* unix/tkUnixScale.c (DisplayHorizontalValue): Fix for [Bug 220927] by
	Michael Schlenker to keep the labels within the window.

2004-10-28  Donal K. Fellows  <[email protected]>

	* doc/*.n: Assorted minor documentation fixes.

2004-10-26  David Gravereaux <[email protected]>

	* win/tkWinX.c:		     Signature for tkWinXCleanup needed to be
	* generic/tkInt.decls:	     changed so it matches the Tcl_ExitProc
	* generic/tkIntPlatDecls.h:  typedef to avoid a bad-style cast.

	* win/makefile.vc: Force TCL_LIBRARY envar when calling tclsh

2004-10-26  Pat Thoyts	<[email protected]>

	* win/tkWinRegion.c (TkpBuildRegionFromAlphaData): Fixed syntax error
	* generic/tkImgPhoto.c (Tk_PhotoPutBlock): Removed unreferences vars.

2004-10-26  Donal K. Fellows  <[email protected]>

	* macosx/tkMacOSXRegion.c (TkpBuildRegionFromAlphaData):
	* win/tkWinRegion.c (TkpBuildRegionFromAlphaData): Factor out the
	* unix/tkUnix.c (TkpBuildRegionFromAlphaData):	   building of region
	* generic/tkImgPhoto.c (Tk_PhotoPutBlock):	   data to permit
	better implementations on particular platforms. [Bug 919066]

2004-10-24  Donal K. Fellows  <[email protected]>

	TIP#177 AND TIP#179 IMPLEMENTATIONS

	* doc/panedwindow.n: Docs for -hide and -stretch options.
	* tests/panedwindow.test: Basic tests of -hide and -stretch options.
	* generic/tkPanedWindow.c (Slave,slaveOptionSpecs,ComputeGeometry):
	(DisplayPanedWindow,ArrangePanes,MoveSash,PanedWindowIdentifyCoords):
	Add hide flag and stretch setting to list of options supported on a
	panedwindow's slaves. [Patch 983886] Much thanks to Brian Griffin for
	these options.

2004-10-20  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (UpdateWrapper): pass SWP_NOOWNERZORDER to SetWindowPos
	when maintaining win Z order, to prevent parent from flashing (when
	adjusting Z order).

2004-10-19  Joe English	 <[email protected]>

	TIP#204 IMPLEMENTATION

	* library/tk.tcl, library/entry.tcl, library/spinbox.tcl:
	TIP #204 "Virtual Events for Keyboard Traversal" [Patch 976928]

2004-10-19  Donal K. Fellows  <[email protected]>

	* tests/canvPsImg.tcl, tests/canvPsBmap.tcl:
	* generic/tkBitmap.c, bitmaps/*.bmp:
	* library/demos/icon.tcl, library/demos/items.tcl:
	* library/demos/label.tcl, library/demos/menu.tcl:
	* library/demos/ruler.tcl, library/demos/twind.tcl:
	* library/demos/images/*.bmp: Renamed all X bitmap files files to have
	an .xbm extension so Windows users won't get confused when wandering
	around the Tcl source tree. [Bug 733835]

2004-10-11  Miguel Bañon <[email protected]>

	* library/msgs/sv.msg: Swedish message catalog from Mats Bengtsson.

2004-10-09  Donal K. Fellows  <[email protected]>

	* doc/wm.n: Recorded what attribute values are supported on OSX though
	I don't know what they do.

2004-10-08  Joe English	 <[email protected]>

	TIP#205 IMPLEMENTATION

	* unix/tkUnixRFont.c: TIP #205 "Use pkgconfig Database to Register Xft
	Support".

2004-10-05  Jeff Hobbs	<[email protected]>

	TIP#159 IMPLEMENTATION

	* doc/wm.n (iconphoto):		  Added support for Tk photo images as
	* generic/tkInt.h (TkDisplay):	  title-bar icons. TIP #159
	* win/tkWinWm.c (WmIconphotoCmd): "wm iconphoto ?-default? image1 ..."
	* macosx/tkMacOSXWm.c (WmIconphotoCmd): Implemented for Win/Unix,
	* unix/tkUnixWm.c (WmIconphotoCmd):	stubbed out for OS X.
	* tests/wm.test, tests/unixWm.test, tests/winWm.test: [Bug 815751]

2004-10-04  Jeff Hobbs	<[email protected]>

	* generic/tkTextWind.c (EmbWinDelayedUnmap): Fix init warnings
	* generic/tkTextTag.c (TkTextCreateTag):
	* generic/tkTextMark.c (TkTextSetMark):
	* generic/tkTextIndex.c (GetIndex):
	* generic/tkUndo.c (EvaluateActionList):

2004-09-24  Don Porter	<[email protected]>

	* generic/tkCursor.c: Add missing initialization in debug routine.

2004-09-24  Vince Darley  <[email protected]>

	* library/text.tcl: corrected mousewheel scrolling [Bug 960190]

	* tests/textDisp.test: made some tests more robust to slowness in
	asynchronous height calculation callbacks [Bug 1025781]

2004-09-24  Pat Thoyts	<[email protected]>

	* win/tkWinX.c: Added declaration for advapi32 now that this file uses
	the Reg* functions (req'd for nmake build system).

2004-09-23  Vince Darley  <[email protected]>

	* generic/tkTest.c
	* tests/text.test: fix and tests for [Bug 1026485] - negative text
	search ranges should not lead to any matches.

2004-09-22  Jeff Hobbs	<[email protected]>

	* win/tkWinInt.h (TkWinDisplayChanged): added decl
	* win/tkWinX.c (TkWinDisplayChanged, TkpOpenDisplay): Correctly handle
	* win/tkWinWm.c (InvalidateSubTreeDepth, WmProc):     color and screen
	resolution changes. Tested for 16/24/32 bpp changes on XP. May need
	more fixes for 8bpp switch, use of special colormaps, or other special
	palette handling cases. [Bug 223689]

2004-09-21  Mo DeJong  <[email protected]>

	* generic/tkInt.decls: Add decl for TkWinGetPlatformTheme. It is only
	defined under Win32.
	* generic/tkIntPlatDecls.h: Regen.
	* generic/tkStubInit.c: Regen.
	* win/tkWinInt.h: Define TK_THEME_WIN_CLASSIC and TK_THEME_WIN_XP.
	* win/tkWinMenu.c (DrawMenuEntryAccelerator, DrawMenuEntryLabel): Draw
	a disabled 3D text highlight for the accelerator only with the Win95/98
	look. Same goes for the menu entry text.
	* win/tkWinX.c (TkWinGetPlatformId, TkWinGetPlatformTheme):
	Automatically detect the Windows theme in use and return either
	TK_THEME_WIN_CLASSIC or TK_THEME_WIN_XP when the TkWinGetPlatformTheme
	function is invoked. [Patch 866194]

2004-09-21  Mo DeJong  <[email protected]>

	* win/tkWinWm.c: Rework WS_EX_LAYERED and LWA_ALPHA defines so that
	compiling with mingw works again.

2004-09-20  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (UpdateWrapper, WmAttributesCmd): handle attribute
	settings prior to window mapping and resort to more forceful wrapper
	update again for -toolwindow (to remove it from taskbar).

2004-09-19  Donal K. Fellows  <[email protected]>

	* doc/*: Standardize style of references to manual sections and public
	Tcl symbols along the lines of what I set out in [Tcl Patch 1022527].

2004-09-18  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (WmAttributesCmd): correct -alpha 0.0/1.0 setting and
	round the value.
	(UpdateWrapper): don't adjust Z order of TOPMOST window.
	(WmAttributesCmd): don't call UpdateWrapper for -disabled or
	-toolwindow attr changes.

2004-09-17  Jeff Hobbs	<[email protected]>

	TIP#222 IMPLEMENTATION

	* doc/wm.n:
	* tests/winWm.test: Add 'wm attributes -alpha' to control toplevel
	* win/tkWinInt.h:   alpha transparency on Win2K/XP+.
	* win/tkWinWm.c:    TIP #222 [Patch 892194]

	* win/tkWinWm.c (UpdateWrapper): Ensure that we maintain Z order and
	* tests/winWm.test:		 focus of preexisting window when
	replacing the wrapper window.

2004-09-16  David Gravereaux <[email protected]>

	* win/makefile.vc : added VC7-safe environment check as used in the Tcl
	makefile.vc [Bug 1029349]

2004-09-16  Jeff Hobbs	<[email protected]>

	* generic/tkMenu.c (MenuWorldChanged): ensure that we recompute the
	menu geometry on WorldChanged to handle font size changes. [Bug 607649]

2004-09-16  Peter Spjuth  <[email protected]>

	* tests/place.test:
	* generic/tkPlace.c: Fixed a memory leak when a placed widget was
	forgotten. [Bug 1028888]

2004-09-14  Mo DeJong  <[email protected]>

	* win/tkWinWm.c (WmIconwindowCmd): Replace bogus call to
	XWithdrawWindow with proper code. This avoids a "couldn't send withdraw
	message to window manager" error when the iconwindow is already mapped.
	The wm iconwindow command does not seem to do much under Win32, but at
	least this avoids an error message.

2004-09-13  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (ReadIconFromFile): fix mem alloc to get the right size
	for both icons ('?:' order of precedence mistake).

2004-09-10  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (::tk::dialog::file::): Make sure that the state
	is reset properly when starting to run the dialog. [Bug 845189]

	* library/demos/filebox.tcl: Stop the use of tk_strictMotif from
	poisoning the rest of the widget demo. [Bug 1013942]

2004-09-10  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (ActivateWindow): SetFocus to grab window when clicking
	outside the grab window hierarchy. [Bug 220908]
	(UpdateWrapper): update to 2004-06-12 Kovalenko to account for whether
	the override window has a transient parent, and apply WS_POPUP in the
	correct case. The makes splash screens pop up as well as making
	dropdowns not grab focus away from the parent.

2004-09-10  Vince Darley  <[email protected]>

	TIP#169 IMPLEMENTATION

	* doc/text.n, generic/tkTest.c, generic/tkText.c, generic/tkText.h:
	* generic/tkTextBTree.c, generic/tkTextDisp.c, generic/tkTextImage.c:
	* generic/tkTextIndex.c, generic/tkTextMark.c, generic/tkTextTag.c:
	* generic/tkTextWind.c, generic/tkUndo.c, generic/tkUndo.h:
	* library/text.tcl, library/demos/twind.tcl, library/demos/widget:
	* tests/text.test, tests/textImage.test, tests/textIndex.test:
	* tests/textWind.test: implementation of TIP#169, which provides the
	new '$text peer' widget subcommand. This includes new documentation,
	tests, and an extension to the text widget demos to illustrate some of
	the new features. Many thanks also to Brian Griffin for the initial
	implementation.

2004-09-09  Jeff Hobbs	<[email protected]>

	* tests/panedwindow.test: bulletproof 23.2 result [Bug 1019100]

	* win/tkWinWm.c (ReadIconFromFile): when using SHGetFileInfo to
	retrieve icon, get regular icon as well for correct Alt-Tab icon.

2004-09-09  Donal K. Fellows  <[email protected]>

	* doc/wish.1: Added note that the -use option is linked to the frame's
	-container option to help with [Bug 1024364]

2004-09-06  Jeff Hobbs	<[email protected]>

	* library/tkfbox.tcl (::tk::dialog::file::Create): use label instead of
	button for "File of type", as it properly handles -state disabled now.

2004-09-06  Pat Thoyts	<[email protected]>

	* win/makefile.vc: Set TK_LIBRARY when execing Tk apps (test, runtest,
	rundemo).

2004-09-03  Donal K. Fellows  <[email protected]>

	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent):
	* win/tkWinMenu.c (MenuSelectEvent): Make sure everywhere that needs to
	NULL-out the user_data field does actually do so. (Code that uses
	bzero() or memset() for the task just needs to be rebuilt to work).
	[Bug 1021812]

2004-09-01  Donal K. Fellows  <[email protected]>

	* tests/bind.test (bind-22.163): Fix inadvertent minor breakage from
	TIP#165. [Bug 1019085]

	* doc/toplevel.n, doc/loadTk.n: More spelling/abbreviation fixes from
	Mikhail Kolesnitchenko.

2004-08-29  Donal K. Fellows  <[email protected]>

	TIP#165 IMPLEMENTATION

	* generic/tk.h (XVirtualEvent): Added user_data field to structure.
	* generic/tkBind.c (ExpandPercents, HandleEventGenerate):
	* generic/tkEvent.c (Tk_HandleEvent): Handle putting data into the
	user_data field, passing it to scripts as %d substitution, and
	releasing the field's contents once the event has been processed.
	* doc/bind.n, doc/event.n, tests/bind.test: Docs + tests.

2004-08-26  Jeff Hobbs	<[email protected]>

	* library/text.tcl (::tk::TextTranspose): Ensure that Transpose is an
	atomic op to undo.

2004-08-25  Don Porter	<[email protected]>

	* macosx/tkMacOSXWm.c:	Made use of Tcl_WrongNumArgs in a few
	* win/tkWinMenu.c:	appropriate spots.

2004-08-22  Donal K. Fellows  <[email protected]>

	* doc/SetOptions.3, doc/SetClassProcs.3, doc/MeasureChar.3:
	* doc/GetVRoot.3, doc/GetHWND.3, doc/GetDash.3, doc/GetBitmap.3:
	* doc/FontId.3, doc/CrtItemType.3, doc/ConfigWidg.3, doc/GetCursor.3:
	More doc fixes from Mikhail Kolesnitchenko. [Patch 1013520]

2004-08-20  Donal K. Fellows  <[email protected]>

	* doc/TkInitStubs.3, doc/photo.n, doc/ParseArgv.3, doc/options.n:
	* doc/keysyms.n, doc/font.n: More doc fixes. [Patch 1012837]

	* doc/place.n, doc/pack.n, doc/grid.n, doc/getOpenFile.n:
	* doc/event.n, doc/chooseDirectory.n, doc/bind.n:
	Spelling and grammar fixes from Mikhail Kolesnitchenko. [Patch 1012083]

	* tests/canvas.test (canvas-17.1): Report the result of the test so
	that it can be compared. [Bug 1012331]

2004-08-19  Jeff Hobbs	<[email protected]>

	* win/tkWinDialog.c (Tk_MessageBoxObjCmd): Inherit the icon from the
	* win/tkWinInt.h:			   -parent window for the
	* win/tkWinWm.c (TkWinGetIcon):		   MessageBox.

2004-08-19  Joe English	 <[email protected]>

	* unix/tkUnixWm.c: Cast argument 7 of XChangeProperty to 'const
	unsigned char *' (from 'const char *') to satisfy Solaris 8 Forte C
	compiler [Bug 1012325]

2004-08-19  Don Porter	<[email protected]>

	* tests/safe.test (safe-1.3): Made test less sensitve to the full set
	of existing aliases in an interp, so the it only tests whether the
	tested ones are present.

	* unix/Makefile.in: Copied LD_LIBRARY_PATH machinery from `make shell`
	target to other similar targets so that just built libraries are
	tested, rather than previous installations.

2004-08-19  Donal K. Fellows  <[email protected]>

	TIP#168 IMPLEMENTATION

	* generic/tkTrig.c (TkMakeRawCurve, TkMakeRawCurvePostscript):
	* generic/tkInt.decls: New functions to handle the geometry for "raw"
	bezier curves.
	* generic/tkCanvUtil.c (tkRawSmoothMethod, InitSmoothMethods)
	(TkSmoothParseProc): Add new type of smoothing method, simplify the
	method initialization, and change the old smoothing method to be called
	"true" and just keep "bezier" as an alias.
	* tests/canvas.test (canvas-17.1): Basic test of built-in smoothing
	method support.
	* doc/canvas.n: Documentation updates.

2004-08-18  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (optionSpecs): Add missing GEOMETRY flag to
	-handlepad option. [Bug 1010938]

2004-08-17  Donal K. Fellows  <[email protected]>

	* doc/menu.n, doc/text.n: Assorted fixes, including spelling fixes from
	Mikhail Kolesnitschenko. [Patch 1010083]

	* doc/spinbox.n, doc/scrollbar.n, doc/scale.n, doc/panedwindow.n:
	* doc/message.n, doc/listbox.n, doc/entry.n, doc/button.n:
	More spelling fixes from Mikhail Kolesnitschenko. [Patch 1010607]

2004-08-16  Donal K. Fellows  <[email protected]>

	* doc/button.n, doc/checkbutton.n, doc/label.n, doc/menubutton.n:
	* doc/radiobutton.n: Added cross-reference to new standard option.
	* doc/options.n: Added standard documentation for the -compound
	option. [Bug 712588]

	* doc/canvas.n: Spelling and grammar fixes from Mikhail
	Kolesnitschenko. [Bug 1009636]

2004-08-11  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (ResolveFile): Added some environment variable
	handling; this isn't perfect, but should do what most people want most
	of the time. [FRQ 979101]
	* library/xmfbox.tcl (MotifFDialog_BuildUI): Fix [Bug 987169] in the
	Motif file dialogs as well.

2004-08-10  Joe English	 <[email protected]>

	* unix/tkUnixWm.c: Fix for [Bug 1006686] "wm resizable command not
	working on Solaris/CDE" (patch from Colin McDonald).

2004-08-09  Mo DeJong  <[email protected]>

	* tests/canvText.test:
	* win/tkWinFont.c (Tk_MeasureChars): Fix for text wrapping problem that
	appeared using canvas text under Win32. A long wrapping string that had
	leading spaces was being incorrectly wrapped. This change makes the
	Win32 implementation behave the same as the Unix implementation. [Patch
	1006286]

2004-08-05  Donal K. Fellows  <[email protected]>

	* library/clrpick.tcl (BuildDialog):
	* library/msgbox.tcl (MessageBox): Add scheme for cancelling dialog
	boxes with Escape and also handle what happens when the window gets
	nuked from outside. [Bug 987169]

2004-08-04  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoBlendComplexAlpha): Clean the code up a
	bit and add a few more comments.
	(Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock): Clarified the code,
	corrected the compositing rule now that I have looked up what the right
	thing to do is, and factorized out the compositing rule code into a few
	simpler macros.

2004-07-30  Daniel Steffen  <[email protected]>

	* unix/configure:
	* unix/tcl.m4 (SC_CONFIG_CFLAGS): Darwin: instead of setting PLAT_OBJS
	to explict object files in tcl.m4, refer to MAC_OSX_OBJS makefile var.

2004-07-29  George Peter Staplin <[email protected]>

	* generic/tkEvent.c (TkQueueEventForAllChildren): Code from the
	core-8-4-branch to not queue events for unmapped windows was added.

2004-07-27  Daniel Steffen  <[email protected]>

	* generic/tkImgGIF.c (FileReadGIF): fix crash reported by Reinhard
	Max: in case of premature end of image data, return error instead of
	passing nil buffer to Tk_PhotoPutBlock().

2004-07-22  Jeff Hobbs	<[email protected]>

	* library/tkfbox.tcl (::tk::dialog::file::Update): use -directory [pwd]
	(instead of .) to get around some VFS edge case bugs. Correct args
	passes to tk_messageBox when failing to cd. Add -force back to
	namespace import of msgcat.

2004-07-20  Jeff Hobbs	<[email protected]>

	* generic/tkEvent.c (InvokeInputMethods): ensure IC focus is set after
	creation. [Bug 905830]

2004-07-20  Daniel Steffen  <[email protected]>

	* macosx/Makefile: added support to tk framework build to optionally
	install tk manpages in addition to html help, similarly to
	tcl/macosx/Makefile.

	* macosx/Wish.pbproj/project.pbxproj: fixes for building with
	non-default SYMROOT/OBJROOT/SRCROOT, added support for using a
	Tcl.framework in DYLIB_INSTALL_PATH != /Library/Frameworks, added
	optional support for building html help without tcl sources present by
	giving explicit location of tcltk-man2html script.

	* macosx/tkMacOSXMenu.c: fixed #include case sensitivity bug.

	* unix/Makefile.in:
	* win/Makefile.in: added 'install-private-headers' makefile target to
	allow optionally installing private tk headers. [Tcl FR 922727]

2004-07-16  Jeff Hobbs	<[email protected]>

	* unix/Makefile.in, unix/tcl.m4:     move (C|LD)FLAGS after their
	* unix/configure.in, unix/configure: _DEFAULT to allow for env setting
	to override m4 switches.
	Consolidate header checks to limit redundancy in configure.
	(CFLAGS_WARNING): Remove -Wconversion
	(SC_ENABLE_THREADS): Set m4 to force threaded build when built against
	a threaded Tcl core.
	Reorder configure.in for better 64-bit build configuration, replacing
	EXTRA_CFLAGS with CFLAGS. [Bug 874058]

2004-07-14  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXCursor.c (TkpSetCursor): The code to not reset the
	cursor more often than necessary was getting fooled when the current
	cursor was nulled out when the current cursor gets freed. So in the
	case where the input cursor was NULL, we have to just always set it.
	[Bug 894550]

2004-07-13  Don Porter	<[email protected]>

	* library/tkfbox.tcl: Corrected coding errors in most recent change.
	Use [bind $w], not [$w configure] to modify bindings.

2004-07-11  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (::tk::dialog::file::Create): Watch out for users
	destroying the dialog indirectly. [Bug 987169]

2004-07-07  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: Add paragraph to make clearer what is going on with the
	default canvas origin. [Bug 956681]

2004-07-05  George Peter Staplin <[email protected]>

	* generic/tkEvent.c: TK_XIM_SPOT preprocessor usage was modified
	slightly to fix a bug that occured when TK_XIM_SPOT was defined as 0.
	Thanks to Joe Mistachkin for reporting this bug.

2004-07-05  Donal K. Fellows  <[email protected]>

	TIP#158 IMPLEMENTATION

	* tests/bind.test:		   Allow Win apps to distinguish keys
	* win/tkWinX.c (GetState):	   on the keypad using the Extended
	* generic/tkInt.h (EXTENDED_MASK): modifier. Thanks to Wolfgang
	* generic/tkBind.c:		   Grossbauer and Kevin Kenny for
	* doc/bind.n:			   developing this patch [Patch 797404]

2004-07-05  Joe English	 <[email protected]>

	* unix/tkUnixWm.c: Set _NET_WM_NAME and _NET_WM_ICON_NAME
	(freedesktop.org) in addition to WM_NAME and WM_ICON_NAME (ICCCM). This
	allows the full Unicode character set to be used in window manager
	strings (but only for newer WMs that support the EWMH spec). [Bug
	959973]

2004-07-02  George Peter Staplin <[email protected]>

	* generic/tkEvent.c: Tk_HandleEvent was refactored to be more readable,
	and during this process two bugs were found.
	1) Button 4 and 5 masks will now be synchronized with the TkDisplay.
	2) ClientMessage handlers will use the proper last pointer rather than
	writing to the last GenericHandler pointer.

	Thanks to Joe English for his help and encouragement, and DKF for
	review.

2004-07-01  Donal K. Fellows  <[email protected]>

	* doc/place.n, doc/pack.n: Doc fixes. [Tcl Bug 983146]

2004-06-30  Donal K. Fellows  <[email protected]>

	TIP#153 IMPLEMENTATION

	* generic/tkCmds.c (GetTopHierarchy): Modified from GetToplevel so
	* doc/winfo.n:			      that [winfo toplevel] does not
	assume that it is really working with toplevels. Occasionally this is
	important. Thanks to Neil McKay for this patch!

2004-06-29  Jeff Hobbs	<[email protected]>

	* generic/tkCmds.c (Tk_WinfoObjCmd): refetch interp result obj for
	'winfo id' as it can change when making the window exist.

2004-06-26  Joe Mistachkin  <[email protected]>

	* generic/tkConsole.c (ConsoleDeleteProc): Set tsdPtr->gStdoutInterp to
	NULL when the console command is deleted [Bug 756840]. Also, added
	Tcl_Preserve/Tcl_Release for consoleInterp in InterpreterCmd in case it
	gets deleted during the calls to Tcl_GlobalEval and Tcl_RecordAndEval.

2004-06-24  Donal K. Fellows  <[email protected]>

	* tests/canvPs.test, etc: Use standard tcltest constraint names.

2004-06-19  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: autoconf 2.5 fixes in Darwin section.
	* unix/configure: autoconf-2.57

2004-06-17  Donal K. Fellows  <[email protected]>

	* tests/constraints.tcl, tests/*.test: Systematization of test
	constraints so many common and basic constraints are defined once with
	a single name.

2004-06-16  Joe English	 <[email protected]>

	* unix/tkUnixWm.c, win/tkWinWm.c, macosx/tkMacOSXWm.c, tests/wm.test
	* tests/unixWm.test: Fix for [Bug 742882] "Potential division by zero
	in gridded wm geometry"

2004-06-15  Anton Kovalenko <[email protected]>

	* win/tkWinButton.c: Add a 3D highlight to disabled *buttons and
	labels, the same way as it's now done for disabled menu entries.

2004-06-15  Donal K. Fellows  <[email protected]>

	* doc/image.n: Enhanced the documentation to take into account the
	concerns raised in [RFE 803060]

	* tests/canvas.test: Updated tests affected by the change to
	ScrollFractions, which is now clean about result generation.

	* generic/tkCanvas.c: Make tag search subsystem use symbolic names for
	type flags for easier maintenance.
	(FIRST_CANVAS_ITEM_MATCHING,FOR_EVERY_CANVAS_ITEM_MATCHING): Factorize
	out searching idioms into macros to reduce the #ifdef count and make
	braces match.
	(ScrollFractions): Really create a list Tcl_Obj.

2004-06-12  Anton Kovalenko <[email protected]>

	* win/tkWinWm.c (UpdateWrapper): Let overrideredirect'ed window's
	wrapper be the child of desktop window, thus making it to behave more
	similarly to X11 Override Redirect. Esp. useful for combobox-like
	megawidgets.

2004-06-09  Vince Darley  <[email protected]>

	* generic/tkText.c:
	* tests/text.test: fix to multi-line regexp search bugs in text widget
	(reported against Alphatk editor, not on sf). Addded 3 new tests.

2004-06-09  Donal K. Fellows  <[email protected]>

	* generic/tkUndo.c (TkUndoSetDepth): Delete the unlinked element and
	not the next element. Stops a crash in some situations and a memory
	leak in others. Thanks to Jiang Wu for spotting this. [Bug 969358]

2004-06-08  Mo DeJong  <[email protected]>

	* generic/tkCanvText.c (DisplayCanvText): Fix text rendering problem
	with canvas text items that have a selected region. The previous
	implementation would render the whole line and then redraw the
	selected text if it was a different color. This caused problems when
	the selected text foreground differs from the normal text foreground,
	the anti-aliasing alpha pixels for the two text strings would blend
	together resulting in strange looking text. The fix is to draw the
	normal text and the selected text separately. This problem has only
	been observed under Windows, with anti-aliased text. [Patch 968725]

2004-06-07  Vince Darley  <[email protected]>

	* generic/tkTextDisp.c:
	* generic/tkTextBTree.c: fix to (Bug 965186) in which the text widget's
	record of partial-line-height calculations (for very long wrapped
	lines) was being incorrectly reused. This resulted in confusing
	scrollbar-text interactions.

2004-06-06  Pat Thoyts	<[email protected]>

	* tests/frame.test:	Fix frame-2.8 for ![info exists env(DISPLAY)]

2004-06-04  Don Porter	<[email protected]>

	* tests/filebox.test:	A few typo corrections in dkf's recent style
	* tests/frame.test:	upgrade for the test suite.
	* tests/select.test:
	* tests/visual.test:

2004-06-04  Vince Darley  <[email protected]>

	* generic/tkTextIndex.c:
	* generic/tkText.c:
	* generic/tkTextDisp.c:
	* doc/text.n: fix to shimmering infinite loop scrolling problem in text
	widget under some rare circumstances (Bug 965398). Improved comments
	and documentation.

	* tests/textDisp.test: corrected rounding from float to int in test,
	fixing occasional failures

	* library/text.tcl: corrected mousewheel bindings for TkAqua

2004-05-29  Joe English	 <[email protected]>

	* doc/messageBox.n: Fix minor markup errors (backslash is \e, not \b).

2004-05-24  Donal K. Fellows  <[email protected]>

	* doc/messageBox.n: Added documentation for the -detail option.
	* tests/msgbox.test: Updated test suite with correct list of options.
	* win/tkWinDialog.c (Tk_MessageBoxObjCmd): Added "support" for the
	-detail option by concatenating it onto the end of the message.

2004-05-24  Jim Ingham	<[email protected]>

	* tkMacOSXDialog.c (Tk_MessageBoxObjCmd): Turn on the -detail option
	for Mac OS X.

2004-05-23  Donal K. Fellows  <[email protected]>

	* ChangeLog.2002: Split older ChangeLog entries off into a separate
	file.
	* doc/bindtags.n: Added example.

	* tests/*.test: Many minor fixes aiming towards making the Tk test
	suite have better style. (A very large fraction of test files were
	modified.)

	* generic/tkVisual.c (Tk_GetVisual): Minor fix for error message.

2004-05-14  Donal K. Fellows  <[email protected]>

	TIP#152 IMPLEMENTATION (Unix only)

	* library/msgbox.tcl (MessageBox): Added TIP#152's -detail option for
	Unix/X11 platforms. Also shrank the size of the main -message text
	which was grossly large.

2004-05-12  Chengye Mao <[email protected]>

	* generic/tkBind.c <HandleEventGenerate>: Modified to fix wish crash
	due to incorrectly generate <Destroy> event. This bug was reported in
	comp.lang.tcl but not logged.

2004-05-07  Chengye Mao <[email protected]>

	* win/tkWinWm.c <UpdateWrapper>: handle and destroy old wrapper
	correctly and fix crash problem in wish exiting [Bug 767176].

2004-05-05  Jeff Hobbs	<[email protected]>

	* win/tkWinFont.c (FindSubFontForChar): corrections to dkf patch to
	handle subFontPtrPtr in EnumFontFamilies callback.

2004-05-05  Donal K. Fellows  <[email protected]>

	* win/tkWinFont.c (Tk_MeasureChars,Tk_DrawChars,etc): Make sure that
	the lastSubFontPtr remains valid even when the subfont array is
	reallocated. [Bug 618872]

2004-05-03  Jeff Hobbs	<[email protected]>

	* unix/tkUnixButton.c (TkpDrawCheckIndicator): allow radiobuttons to be
	drawn when disabledforeground and/or selectcolor are NULL.
	[Bug 826850] (griffin)

	* win/tkWinMenu.c, unix/tkUnixMenu.c (DrawMenuEntryLabel): place images
	of compound menu entries in indicator space if not a radio of
	checkbutton. [Bug 756952] (eserte)

	* win/tkWinX.c:		       fix drawing of unicode chars in menu
	* win/tkWinInt.h (TkWinProcs): titles. [Bug 904371] (riefenstahl)
	* win/tkWinMenu.c (ReconfigureWindowsMenu):

	* generic/tkClipboard.c:   Move TkClipCleanup from tkClipboard.c to
	* macosx/tkMacOSXXStubs.c: being implemented in a platform-specific
	* unix/tkUnixEvent.c:	   manner. The cleanup order was bad at least
	* win/tkWinX.c:		   on Windows, where we reset/cleared display
	info that was still needed for the clipboard to render. [Bug 939389,
	822002, 732662]

	* library/panedwindow.tcl (MarkSash): call DragSash to stop sash jump
	when B1 is pressed and released without moving. [Bug 932155]

	* tests/panedwindow.test: panedwindow-25.1
	* generic/tkPanedWindow.c (Unlink): clean up -before/-after refs to a
	slave when removing it. [Bug 928413] (griffin)

	* generic/tkImgPhoto.c (ImgPhotoConfigureMaster): force -data into
	ByteArray and -format into String to correctly handle them if they
	have been shimmered or created as some other object type.

2004-04-24  Daniel Steffen  <[email protected]>

	* generic/tkPort.h:
	* unix/Makefile.in:
	* win/makefile.bc:
	* win/Makefile.in: followup on tcl header reform [FR 922727]: removed
	use of relative #include paths in tkPort.h to allow installation of
	private headers outside of tk source tree; added tcl plaform source dir
	to compiler header search path.

2004-04-23  Donal K. Fellows  <[email protected]>

	* doc/bind.n: Added examples (in line with the parallel programme for
	adding examples to Tcl manual pages) and made assorted minor
	alterations to improve the overall look.

2004-04-21  Donal K. Fellows  <[email protected]>

	* tests/textDisp.test: Get rid of windows that are no longer needed so
	single-proc tests don't have extra windows hanging around unexpectedly.

2004-04-21  Benjamin Riefenstahl  <[email protected]>

	Mac OS X: Fix several problems with Icelandic (and Faroese) keyboards
	reported by Jérôme Gagnon-Voyer <gagnonje5000<at>mac<dot>com> on
	tcl-mac on 2004-03-22.

	* macosx/tkMacOSXKeyEvent.c (KLSInit): Add.
	(GetKeyboardLayout): Add calls to Keyboard Layout Services, if present.
	Rework classic handling. Use GetKCHREncoding(). Add parameter
	encodingPtr.
	(GetKCHREncoding): Add.

2004-04-16  Jeff Hobbs	<[email protected]>

	* library/bgerror.tcl (bgerror): rework to only set -topmost bit on
	Windows if necessary. Also use existing ::tk functions for placing
	dialog and managing focus/grab.

2004-04-04  Joe English	 <[email protected]>

	* unix/tkUnixWm.c: Fix for [Bug 915350] "Tk sets min, max size in
	WM_HINTS when it shouldn't" and [Bug 922336] "Tk apps have no maximize
	window button under KDE-3.2.1"

2004-03-31  Jim Ingham	<[email protected]>

	* tkMacOSXCarbonEvents.c (AppEventHandlerProc): Handle the
	kEventAppHidden and kEventAppShown events.
	(TkMacOSXInitCarbonEvents): Register for the above events.
	* tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): Steal the
	Command-H menu key event and allow the Application handler to have it.
	This is currently the only way to get the Hide behavior to work. [Bug
	917557]

	* tkMacOSMenus.c (TkMacOSXHandleMenuSelect): Remove the Quit menu
	handler - this was for the Quit item in the File menu, but it doesn't
	belong there.
	(TkMacOSXInitMenus): Remove the Quit menu item from the File menu.

	* tkMacOSXMenu.c (EventuallyInvokeMenu): Report errors from invoking
	menu commands as background errors. [Bug 220871]

2004-03-31  Don Porter	<[email protected]>

	* generic/tkImgPhoto.c:	Removed outdated #include's of the tclMath.h
	* generic/tkScale.c:	header file. All tk*Port.h files have long had
	a #include <math.h>, and other parts of Tk routinely make use of
	libm-supplied math routines.

2004-03-30  Daniel Steffen  <[email protected]>

	* macosx/tclets.r (removed): obsolete holdover from mac classic.

2004-03-26  Donal K. Fellows  <[email protected]>

	* generic/tkImgPPM.c (ReadPPMStringHeader): Code to read PPM/PGM data
	(StringReadPPM, StringMatchPPM): from strings/bytearrays. [FRQ 540375]

2004-03-26  Don Porter	<[email protected]>

	* unix/tcl.m4:	Replaced -Wno-strict-alias with more portable
	-fno-strict-alias alternative.

	* README:		Bump version to 8.5a2.
	* generic/tk.h:
	* macosx/Wish.pbproj/project.pbxproj:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.57
	* win/configure:

2004-03-26  Donal K. Fellows  <[email protected]>

	* generic/tkImgPPM.c (StringWritePPM): New function to support
	converting of images to PPM strings. Other direction not yet done. Rest
	of file converted to use new image API.
	* generic/tkImgPhoto.c (ImgPhotoCmd): Restored support for the
	stringWriteProc of old photo formats. [Bug 923555]

2004-03-25  Donal K. Fellows  <[email protected]>

	* doc/winfo.n: Clarified the range of colour intensities returned by
	[winfo rgb]. [Bug 922610]

2004-03-22  Donal K. Fellows  <[email protected]>

	* doc/ConfigWidg.3: Converted malloc/free to Tcl_Alloc/Tcl_Free to help
	avoid confusion and crashes on Windows. [Bug 920695]

2004-03-20  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXSubwindows.c (GenerateConfigureNotify): New function.
	(XMoveWindow): Generate configure notify events for child widgets on
	move.
	(XMoveResizeWindow): Ditto.

2004-03-18  Daniel Steffen  <[email protected]>

	Removed support for Mac OS Classic platform [Patch 918139]

	* doc/console.n:
	* doc/tk.n:
	* generic/README:
	* generic/default.h:
	* generic/tk.decls:
	* generic/tk.h:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkConsole.c:
	* generic/tkFileFilter.h:
	* generic/tkGrab.c:
	* generic/tkInitScript.h:
	* generic/tkInt.decls:
	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkMain.c:
	* generic/tkPlatDecls.h:
	* generic/tkPointer.c:
	* generic/tkPort.h:
	* generic/tkSelect.c:
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkWindow.c:
	* library/bgerror.tcl:
	* library/button.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/msgbox.tcl:
	* library/spinbox.tcl:
	* library/tearoff.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/demos/text.tcl:
	* library/demos/widget:
	* mac/MW_TkBuildLibHeader.h (removed):
	* mac/MW_TkBuildLibHeader.pch (removed):
	* mac/MW_TkHeader.h (removed):
	* mac/MW_TkHeader.pch (removed):
	* mac/MW_TkHeaderCommon.h (removed):
	* mac/MW_TkOldImgHeader.h (removed):
	* mac/MW_TkOldImgStaticHeader.h (removed):
	* mac/MW_TkStaticHeader.h (removed):
	* mac/MW_TkStaticHeader.pch (removed):
	* mac/MW_TkTestHeader.h (removed):
	* mac/MW_TkTestHeader.pch (removed):
	* mac/README (removed):
	* mac/bugs.doc (removed):
	* mac/tclets.r (removed):
	* mac/tclets.tcl (removed):
	* mac/tkMac.h (removed):
	* mac/tkMacAppInit.c (removed):
	* mac/tkMacAppearanceStubs.c (removed):
	* mac/tkMacApplication.r (removed):
	* mac/tkMacBitmap.c (removed):
	* mac/tkMacButton.c (removed):
	* mac/tkMacClipboard.c (removed):
	* mac/tkMacColor.c (removed):
	* mac/tkMacConfig.c (removed):
	* mac/tkMacCursor.c (removed):
	* mac/tkMacCursors.r (removed):
	* mac/tkMacDefault.h (removed):
	* mac/tkMacDialog.c (removed):
	* mac/tkMacDraw.c (removed):
	* mac/tkMacEmbed.c (removed):
	* mac/tkMacFont.c (removed):
	* mac/tkMacHLEvents.c (removed):
	* mac/tkMacInit.c (removed):
	* mac/tkMacInt.h (removed):
	* mac/tkMacKeyboard.c (removed):
	* mac/tkMacLibrary.r (removed):
	* mac/tkMacMDEF.c (removed):
	* mac/tkMacMDEF.r (removed):
	* mac/tkMacMenu.c (removed):
	* mac/tkMacMenu.r (removed):
	* mac/tkMacMenubutton.c (removed):
	* mac/tkMacMenus.c (removed):
	* mac/tkMacPort.h (removed):
	* mac/tkMacProjects.sea.hqx (removed):
	* mac/tkMacRegion.c (removed):
	* mac/tkMacResource.r (removed):
	* mac/tkMacScale.c (removed):
	* mac/tkMacScrlbr.c (removed):
	* mac/tkMacSend.c (removed):
	* mac/tkMacSubwindows.c (removed):
	* mac/tkMacTclCode.r (removed):
	* mac/tkMacTest.c (removed):
	* mac/tkMacWindowMgr.c (removed):
	* mac/tkMacWm.c (removed):
	* mac/tkMacXCursors.r (removed):
	* mac/tkMacXStubs.c (removed):
	* mac/widget.r (removed):
	* tests/clrpick.test:
	* tests/cursor.test:
	* tests/entry.test:
	* tests/font.test:
	* tests/macEmbed.test (removed):
	* tests/macFont.test (removed):
	* tests/macMenu.test (removed):
	* tests/macWinMenu.test (removed):
	* tests/macscrollbar.test (removed):
	* tests/menuDraw.test:
	* tests/safe.test:
	* tests/scrollbar.test:
	* tests/select.test:
	* tests/spinbox.test:
	* tests/text.test:
	* tests/tk.test:
	* tests/winfo.test:
	* tests/wm.test:
	* unix/Makefile.in:
	* unix/README:
	* unix/tk.spec:
	* unix/tkUnix3d.c:
	* unix/tkUnixDraw.c:
	* xlib/xgc.c:
	* xlib/xutil.c:
	* xlib/X11/X.h:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h:
	* xlib/X11/keysym.h:

2004-03-16  Jeff Hobbs	<[email protected]>

	* unix/tkUnixButton.c (TkpDrawCheckIndicator): correct crash condition
	for new radio/checkbuttons when colors are exhausted.
	[Bug 915330] (griffin)

	* generic/tkGrid.c (GridRowColumnConfigureCommand): fix lint warning

	* generic/tkCanvUtil.c: fix cast warnings

	* generic/tkTextImage.c (EmbImageConfigure): fix casts

	* unix/tkUnixSelect.c (ConvertSelection, TkSelPropProc): fix casts

	* unix/configure, unix/tcl.m4: add -Wno-strict-aliasing for GCC to
	suppress useless type puning warnings.

2004-03-08  David Gravereaux <[email protected]>

	* win/makefile.vc:
	* win/buildall.vc.bat:	Checks MSDevDir, not MSVCDir envar.

2004-03-04  Mo DeJong  <[email protected]>

	* win/tkWin32Dll.c: Add variables needed when compiling with mem debug
	under Mingw. This fixes the checking from 2003-12-25.

2004-03-03  Jeff Hobbs	<[email protected]>

	*** 8.5a1 TAGGED FOR RELEASE ***

	* unix/Makefile.in (dist): don't require win/lamp.bmp copy in dist
	target (it's already handled by win/rc/*.bmp copy)

	* changes: updated for 8.5a1

2004-03-01  Jeff Hobbs	<[email protected]>

	* README:	update to patchlevel 8.5a1
	* generic/tk.h:
	* macosx/Wish.pbproj/project.pbxproj:
	* unix/configure, unix/configure.in, unix/tk.spec:
	* win/configure, win/configure.in:

	* unix/tcl.m4: update HP-11 build libs setup

2004-03-01  Don Porter	<[email protected]>

	* unix/tcl.m4 (SC_CONFIG_CFLAGS):	Allow 64-bit enabling on
	IRIX64-6.5* systems. [Bug 218561]
	* unix/configure:	autoconf-2.57

2004-02-28  Vince Darley  <[email protected]>

	* generic/tkTextIndex.c: remove use of internal Tcl interface
	'TclUtfToUniChar'

2004-02-25  Benjamin Riefenstahl  <[email protected]>

	* library/demos/widget (addFormattedText): Correct off-by-one error.

2004-02-23  Daniel Steffen  <[email protected]>

	* macosx/Makefile: ensure that xcodebuild will use the Wish.pbproj
	project even if a .xcode project is also present.

	* macosx/tkMacOSXMouseEvent.c: fixed modifiers for MouseWheel events.

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkAboutDlg.r: changed year in copyright strings to 2004.

2004-02-23  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXXStubs.c:
	* xlib/ximage.c: fixed MacOSX XGetImage/XPutImage and related functions
	to deal properly with XImages copied from screen.
	* generic/tkCanvPs.c (TkImageGetColor): MacOSX fix. [Bug 809157]

2004-02-18  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: Fixed a bug in grid geometry calculations for a
	shrinking grid. [Bug 899246]

2004-02-17  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXKeyboard.c (TkpInitKeymapInfo): Don't make <Alt> and
	<Meta> synonyms for <Command> and <Option> for now.

2004-02-17  Jeff Hobbs	<[email protected]>

	* generic/tkBind.c (HandleEventGenerate): only modify root[xy] with
	[xy] when they haven't been otherwise set.

	TIP#110 IMPLEMENTATION

	* doc/checkbutton.n: Tristate Checkbutton and Radiobuttons
	* doc/radiobutton.n:
	* generic/tkButton.c:
	* generic/tkButton.h:
	* library/demos/check.tcl:
	* library/demos/radio.tcl:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDefault.h:
	* tests/button.test:
	* unix/tkUnixButton.c:
	* unix/tkUnixDefault.h:
	* win/tkWinButton.c:
	* win/tkWinDefault.h:

2004-02-17  Don Porter	<[email protected]>

	* tests/imgPhoto.test (imgPhoto-16.1): Corrected incorrect variable
	name [Bug 899010].

2004-02-15  Jim Ingham	<[email protected]>

	* tkMacOSXDialog.c (MatchOneType): If the Macintosh filetype is 0, then
	automatically pass the fileType check.

	* tkMacOSXCarbonEvents.c: New file - this doesn't do anything yet -
	just registers for a couple of App Events.

	* tkMacOSXInit.c (TkpInit.c): Call TkMacOSXInitCarbonEvents.c.

	* tkMacOSXAppInit.c: Formatting cleanups.
	* tkMacOSXButton.c: Ditto
	* tkMacOSXClipboard.c: Ditto
	* tkMacOSXDebug.c: Ditto
	* tkMacOSXDialog.c: Ditto
	* tkMacOSXDraw.c: Ditto
	* tkMacOSXEvent.c: Ditto
	* tkMacOSXFont.c: Ditto
	* tkMacOSXHLEvents.c: Ditto
	* tkMacOSXInit.c: Ditto
	* tkMacOSXInt.h
	* tkMacOSXKeyEvent.c: Ditto
	* tkMacOSXMenu.c: Ditto
	* tkMacOSXMenubutton.c: Ditto
	* tkMacOSXMouseEvent.c: Ditto
	* tkMacOSXNotify.c: Ditto
	* tkMacOSXScale.c: Ditto
	* tkMacOSXScrlbr.c: Ditto
	* tkMacOSXSubwindows.c: Ditto
	* tkMacOSXWindowEvent.c: Ditto
	* tkMacOSXWm.c: Ditto

2004-02-13  Jim Ingham	<[email protected]>

	* tkMacOSXDialog.c (Tk_GetOpenFileObjCmd): Use CFStringRef for title &
	message options, not pascal strings.
	(Tk_GetSaveFileObjCmd): Ditto
	(Tk_ChooseDirectoryObjCmd): Ditto
	(NavServicesGetFile): Now that we get CFStrings, we don't need to
	convert them here.

	* tkMacOSXMenu.c (TkMacOSXDispatchMenuEvent): Cleanup, we don't need to
	handle the Apple Menu picks any more, but the code didn't reflect that.

	* tkMacOSXWm.c (TkSetWMName): Use CFStrings for the Window Title name,
	not Pascal strings.

2004-02-12  Jeff Hobbs	<[email protected]>

	* win/tkWinDialog.c (ChooseDirectoryValidateProc): create a pidl for
	-initialdir if we have a UNC path because BFFM_SETSELECTION doesn't
	support UNC paths in strings.

2004-02-10  Donal K. Fellows  <[email protected]>

	* library/msgs/eo.msg:	Language support for Esperanto and Polish from
	* library/msgs/pl.msg:	Artur Trzewik <[email protected]> with thanks.

2004-02-09  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock):
	* tests/imgPhoto.test (imgPhoto-16.1): Better handling of the case when
	copying from one area of a photo to another triggers a resizing of the
	image. [Bug 877950]

2004-02-07  David Gravereaux <[email protected]>

	* win/makefile.vc:
	* win/rules.vc:
	* win/rc/tk.rc:
	* win/rc/wish.rc: Now supports the 'unchecked' option when building.

2004-02-03  Jeff Hobbs	<[email protected]>

	* doc/menubutton.n:
	* library/menu.tcl (::tk::MbPost): make menubuttons that post above or
	below reverse direction when not enough space is available.

2004-02-01  David Gravereaux <[email protected]>

	* win/lamp.bmp (deleted): using win/rc/lamp.bmp instead.

	* win/winMain.c: Removed our custom setargv() in favor of __argc and
	__argv exported by the C run-time.

	* win/makefile.vc:
	* win/rc/tk.rc:
	* win/rc/wish.rc: General clean-up.

	* win/rules.vc:
	* win/nmakehlp.c: sync'd to Tcl.

2004-01-31  Joe English	 <[email protected]>

	* unix/tkUnixWm.c, unix/tkUnixEvent.c: Replaced TclpGetTime() with
	Tcl_GetTime(), to remove dependency on tclInt.h [Bug 874745].

2004-01-27  Daniel Steffen  <[email protected]>

	* generic/tkTextIndex.c: added '#include <tclInt.h>' since the code
	uses the TclUtfToUniChar macro from that file. [Bug 874745]

	* macosx/Wish.pbproj/project.pbxproj: removed erroneous reference to
	mkpsenc.tcl in bundle resources phase (mkpsenc.tcl is already part of
	the copy files phase to Resources/Scripts).

	* macosx/Makefile: added support for 'xcodebuild' on Mac OS X 10.3.

2004-01-25  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXKeyboard.c: Fix regressions due to the last patches.

2004-01-25  Peter Spjuth  <[email protected]>

	* library/dialog.tcl:
	* library/msgbox.tcl: The dialogs were affected by the TIP#146
	implementation. Added grid anchor commands to restore original
	behaviour.

2004-01-15  David Gravereaux <[email protected]>

	* win/tkWinSendCom.c: Placed the requirement for the special COM
	libraries into the object file itself with #pragma comment (lib, ...)
	when built with VC++. This will simplify linking for users of the
	static library. uuid.lib is required for VC5.2, but is implicit with
	VC6.

	* win/makefile.vc: Removed 'ole32.lib oleaut32.lib uuid.lib' from
	$(baselibs).

2004-01-12  David Gravereaux <[email protected]>

	* generic/tk3d.c:	All uses of 'panic' (the macro) changed to
	* generic/tkBind.c:	'Tcl_Panic' (the function). The #define of
	* generic/tkBitmap.c:	panic in tcl.h clearly states it is deprecated
	* generic/tkCanvArc.c:	in the comments. [Tcl Patch 865264]
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkColor.c:
	* generic/tkConfig.c:
	* generic/tkCursor.c:
	* generic/tkError.c:
	* generic/tkEvent.c:
	* generic/tkFocus.c:
	* generic/tkFont.c:
	* generic/tkFrame.c:
	* generic/tkGC.c:
	* generic/tkGrid.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkImgUtil.c:
	* generic/tkMenu.c:
	* generic/tkObj.c:
	* generic/tkPack.c:
	* generic/tkPlace.c:
	* generic/tkRectOval.c:
	* generic/tkSelect.c:
	* generic/tkText.c:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkTextMark.c:
	* generic/tkTextWind.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* mac/tkMacAppInit.c:
	* mac/tkMacAppearanceStubs.c:
	* mac/tkMacButton.c:
	* mac/tkMacDraw.c:
	* mac/tkMacEmbed.c:
	* mac/tkMacFont.c:
	* mac/tkMacInit.c:
	* mac/tkMacMenus.c:
	* mac/tkMacPort.h:
	* mac/tkMacSubwindows.c:
	* mac/tkMacWm.c:
	* mac/tkMacXStubs.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXPort.h:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnix3d.c:
	* unix/tkUnixColor.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixEvent.c:
	* unix/tkUnixFocus.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixWm.c:
	* win/tkWin3d.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinDialog.c:
	* win/tkWinDraw.c:
	* win/tkWinEmbed.c:
	* win/tkWinFont.c:
	* win/tkWinPixmap.c:
	* win/tkWinPointer.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:

	* win/rc/tk.rc:
	* win/rc/tk_base.rc:
	* win/rc/wish.rc:
	* win/makefile.vc: Refreshed how the resource files are built. Should
	be a bit easier for people linking with a static Tk library.

	* win/lamp.bmp (deleted):
	* win/rc/lamp.bmp (new): Moved.

	* win/rules.vc:	 Sync'd to Tcl, respects the CHECKS=nodep command line
	macro and was used to verify the Tcl_Panic change above.

2004-01-09  Peter Spjuth  <[email protected]>

	TIP#146 IMPLEMENTATION

	* doc/grid.n:
	* tests/grid.test:
	* generic/tkGrid.c: Implementation of TIP#146, "Add Overall Anchoring
	to the Grid Geometry Manager", adding [grid anchor] subcommand.
	**** POTENTIAL VISUAL INCOMPATABILITY ****

2004-01-07  Vince Darley <[email protected]>

	* generic/tkTextDisp.c:
	* generic/tkTextBTree.c:
	* tests/text.test: fixed crashing [Bug 872299] in yview code, and added
	tests and better error checking in the B-tree.

2004-01-07  Vince Darley <[email protected]>

	* generic/tkTextIndex.c:
	* tests/textIndex.test: fixed bug in which 'wordstart' and 'wordend'
	were not utf-8 aware (they haven't been changed since Tk 8.0), and
	added tests.

2004-01-07  Vince Darley <[email protected]>

	* win/tkWinMenu.c: only provide a submenu handle when the MF_POPUP flag
	is given, fixing a recently-introduced crash when submenus are
	disabled. Also better error checking for this sort of situation in the
	future.

2003-12-31  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: added missing private headers to
	installed Tk.framework, so that tkInt.h can be included sucessfully
	from Tk.framework/PrivateHeaders.
	* generic/tkPort.h: corrected include of tkMacOSXPort.h

2003-12-28  Mo DeJong  <[email protected]>

	* win/tkWinMenu.c (ReconfigureWindowsMenu): Fix drawing of a disabled
	(TkWinHandleMenuEvent, DrawMenuEntryArrow): cascade menu arrow. Tk was
	displaying a disabled cascade menu arrow in black instead of gray. This
	was caused by a bug in the Win32 code for user drawn menu items. The
	fix is to avoid telling Windows that the menu item is a cascade type
	and then draw the gray arrow bitmap on our own. [Patch 865842]

2003-12-27  Mo DeJong  <[email protected]>

	* win/tkWinMenu.c (DrawWindowsSystemBitmap): Fix a strange Win32 bug
	where the logical coordinates returned by a call to DPtoLP are wrong
	the first time a menu is posted. This bug manifested itself by drawing
	the bitmap in the wrong place in a menu. The fix was to pass the newly
	created DC instead of the DC from the window.

2003-12-26  Mo DeJong  <[email protected]>

	* win/tkWinMenu.c (DrawMenuEntryAccelerator):
	(DrawMenuEntryLabel): When drawing the label text and accelerator text
	for a disabled menu entry be sure to draw a 3D highlight. The only
	exception to this is when a disabled menu entry is highlighted, in that
	case do not draw a 3D hightlight.

2003-12-26  Mo DeJong  <[email protected]>

	* win/tkWinMenu.c (DrawMenuEntryAccelerator, DrawMenuEntryArrow): Move
	the unused menu arrow drawing code in DrawMenuEntryAccelerator into a
	new function named DrawMenuEntryArrow. This makes no functional change
	but it will make it easier to fix things in the future.

2003-12-25  Mo DeJong  <[email protected]>

	* win/tkWin32Dll.c (DllMain): Add HAVE_NO_SEH blocks in place of __try
	and __except statements to support gcc builds. This is needed after
	David's changes on 2003-12-21. [Tcl patch 858493]

2003-12-22  David Gravereaux <[email protected]>

	* win/nmakehlp.c:
	* win/rules.vc: sync'd to Tcl.

	* win/makefile.vc: Uses new features of nmakehlp to get the version
	strings from header files without the use of hardcoded values.

	* generic/tk.h: removed the note about having to update makefile.vc
	when the version changes.

2003-12-22  Joe English	 <[email protected]>

	* doc/text.n: Fix markup errors (".t" at beginning of line).

2003-12-21  David Gravereaux <[email protected]>

	* generic/tkEvent.c:  Added three new functions: TkCreateExitHandler,
	* generic/tkInt.h:    TkDeleteExitHandler, and TkFinalize. This adds an
	* generic/tkMenu.c:   insertion point so Tk's exit handlers can be
	* generic/tkWindow.c: called on their own from tk85.dll's DllMain for
	* mac/tkMacButton.c:  DLL_PROCESS_DETACH. These are private to the
	* unix/tkUnixEvent.c: binary and not exported. It is possible the
	* win/tkWin32Dll.c:   Windows OS can unload Tk _prior_ to Tcl under
	* win/tkWinEmbed.c:   some conditions such as ExitProcess(). This
	* win/tkWinMenu.c:    avoids a dangling pointer problem when Tcl does
	* win/tkWinX.c:	      Tcl_Finalize after Tk has been unloaded.
	* win/winMain.c:      DllMain's DLL_PROCESS_DETACH now protected with
	SEH as DeleteWindowsExitProc is causing an exception of its own under
	some teardown conditions. AT&T assembly syntax has not been added for
	MinGW yet. [Tcl Patch 858493]

2003-12-20  Joe English	 <[email protected]>

	* library/bgerror.tcl: Truncate displayed error message if it's too
	long. [Bug 231251]

2003-12-16  Pat Thoyts	<[email protected]>

	* win/rc/wish.exe.manifest: It seems that Windows XP insists on a
	strict format for the version value. 8.5.a0 or 8.5.0 results in an
	unloadable executable -- must be 4 numbers.

	* win/tkWinSend.c: Removed some misleading comments [Bug 846134] and
	disabled the send package until [Bug 858822] is resolved.

2003-12-16  Anton Kovalenko <[email protected]>

	* win/tkWinWm.c (InstallColormaps): Check for TK_ALREADY_DEAD to avoid
	handling of dead windows.

2003-12-15  David Gravereaux <[email protected]>

	Some silent invalid handle issues discovered with NuMega's
	BoundsChecker [Patch 699022]

	* win/tkWinMenu.c (ReconfigureWindowsMenu): Only redraw the menubar
	when a menubar exists.

	* win/tkWinWm.c (UpdateGeometryInfo): wmPtr->wrapper might be NULL. No
	exception is thrown, but it isn't correct to ignore.

2003-12-15  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXKeyboard.c: General cleanup. Add support for [event
	generate]. [Bug 860454]

2003-12-15  Vince Darley <[email protected]>

	* generic/tkText.h:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextIndex.c: improved documentation in comments to explain
	how pixel heights are kept track of. Also ensured correct clean-up of
	elide-state calculation, even with very large numbers of tags. Also
	provided slightly better updating of cache for totally elided display
	lines.

2003-12-12  David Gravereaux <[email protected]>

	* win/tkWinEmbed.c (TkWinEmbeddedEventProc) : for loop dereferences
	containerPtr but can't get to the if (containerPtr == NULL) test due to
	the unhandled read memory exception for when it really is NULL.

	* win/tkWinX.c (TkWinXInit): Don't restrict InitCommonControlsEx. It's
	valid on all platforms given IE 3.0+ is installed. As tkWinX.c does set
	#define _WIN32_IE 0x0300, I guess we can accept IE3 as the lowest
	denominator and use the version 4.71 features of Comctl32.dll

	* win/rc/wish.exe.manifest: updated version string. This file isn't
	compiled.

2003-12-10  Vince Darley <[email protected]>

	* tests/textWind.test: fixed 2 tests so they run on Windows as well as
	unix, and so their results take account of -padx/-pady settings for the
	text widget.

2003-12-10  Donal K. Fellows  <[email protected]>

	* doc/CrtImgType.3: Fixed line-transposition error found by Eric
	Raymond. [Bug 857159]

2003-12-09  Jeff Hobbs	<[email protected]>

	* unix/configure:
	* unix/tcl.m4: updated OpenBSD build configuration based on [Patch
	775246] (cassoff)

2003-12-09  Vince Darley <[email protected]>

	* win/tkWinWm.c: fix to memory leak on certain error cases.

	* generic/tkTextTag.c: fix reading of freed tag memory, by removing all
	references to freed tags.

2003-12-08  Jeff Hobbs	<[email protected]>

	* doc/entry.n: clean up usage of 'edition' as a verb.

2003-12-05  Vince Darley <[email protected]>

	* tests/text.test:
	* generic/tkText.c: after debate on sf, allow decreasing tab-stops,
	hence removing any potential backwards incompatibility, even for buggy
	code. Added new test. [Bug 852949]

	* generic/tkText.h:
	* generic/tkTextDisp.c:
	* generic/tkTextTag.c: fix to performance problems in the text widget
	when inserting lines which wrap thousands of times [Bug 853003]. Note
	that the text widget must now perform additional calculations (pixel
	heights) compared to Tk <= 8.4, and so some actions will be slower, by
	necessity.

2003-12-05  Benjamin Riefenstahl  <[email protected]>

	* win/tkWinFont.c (Tk_MeasureChars): Fix indentation. Fix memory leak.
	Fix handling of TK_WHOLE_WORDS.

2003-12-04  Vince Darley <[email protected]>

	* generic/tkText.c: disallow negative or decreasing tab-stops, which
	fixes [Bug 852949], but is a

	*** POTENTIAL INCOMPATIBILITY ***

	with Tk 8.4.5 or earlier, but only for code which assumed (incorrectly)
	that tab stops are relative to each other instead of relative to the
	widget's left edge. Such code will now throw an error instead of doing
	the wrong thing.

	[[MAINTAINER NOTE: SEE TIP#256]]

	* generic/tkTextDisp.c: restore previous meaning of -[xy]scrollcommand
	[Bug 852954], and remove unused argument to 'MeasureChars'

	* generic/tkTextWind.c:
	* generic/tkTextImage.c: better border handling and fixed typos in
	comments.

	* tests/text.test: tests for negative and decreasing tab stops.

	* doc/text.n: documentation of '-tabs', to clarify Tk's longstanding
	interpretation of all distances as relative to the left edge of the
	widget.

	* library/demos/twind.tcl:
	* library/demos/widget: minor enhancements to text widget demo, showing
	embedded images, for example.

2003-12-04  Vince Darley <[email protected]>

	* win/tkWinFont.c: applied [Patch 852669] which fixes [Bug 478568] with
	certain bold or italic fonts on Windows.
	* tests/textDisp.test: added test for the font measurement problem.

2003-12-02  Jeff Hobbs	<[email protected]>

	* generic/tkMenu.c (MenuVarProc): prevent this from triggering while
	interp is being destroyed.

2003-11-25  Anton Kovalenko <[email protected]>

	* generic/tkPointer.c (Tk_UpdatePointer): corrected targetWinPtr check
	(line 369) so any pointer event with winPtr==0 is really redirected to
	the grab or restrict window (if any).

2003-11-21  Vince Darley <[email protected]>

	* generic/tkTextDisp.c:
	* generic/tkText.h:
	* generic/tkText.c:
	* tests/textDisp.test: ensure interpolated tabs are at the same
	location as the equivalent real tabs, by making use of fractional
	rather than integer pixel calculations.

2003-11-21  Vince Darley <[email protected]>

	* generic/tkTextDisp.c: prevent wrapped line height calculations until
	the widget has actually been given a geometry.

	* tests/textWind.test:
	* tests/textDisp.test: fix to [Bug 843752], allowing tests to complete
	cross-platform. Thanks to dgp for extensive testing.

2003-11-21  Donal K. Fellows  <[email protected]>

	* doc/FindPhoto.3: Removed reference to long-gone header file.

2003-11-20  Vince Darley <[email protected]>

	* win/tkWinSend.c:
	* win/tkWinSendCom.c: ensure object is not shared before lappend (fix
	for crash in Windows test suite), and clean up of files to bring them
	closer to Tcl standards.

2003-11-20  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXKeyboard.c: Add PowerBook keycode 0x34 as <Return>.

2003-11-18  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXScrlbr.c: Reworking Vince's fix to [Bug 842952]. This
	version is clearer, and works helps keep the mouse better pinned to the
	scrollbar. I also removed the glitch where the scrollbar would jump get
	its middle over the mouse when you first moved it.

2003-11-17  Don Porter	<[email protected]>

	* tests/constraints.tcl:When running the test suite in a process where
	* tests/image.test:	Tk has been [load]ed, there's no guarantee that
	* tests/select.test:	child processes created by [exec [interpreter]]
	* tests/unixWm.test:	will have Tk in them. Made modifications to
	* tests/window.test:	force a [load] of Tk in those situations.

2003-11-17  Jeff Hobbs	<[email protected]>

	* generic/tkMenubutton.h: fixed compound menubutton handling like
	* generic/tkMenubutton.c: *button corrections of 2003-04-25.
	* mac/tkMacMenubutton.c (TkpDisplayMenuButton):
	* unix/tkUnixMenubu.c (TkpDisplayMenuButton):

2003-11-16  Don Porter	<[email protected]>

	* win/makefile.vc: Restored consistency of pkgIndex.tcl file with that
	generated by Makefile.

2003-11-15  Vince Darley <[email protected]>

	* macosx/tkMacOSXScrlbr.c: [Bug 842952] correct scrollbar tracking with
	mouse. Also increased scrollbar resolution for better scrolling in very
	large text widgets.

	* generic/tkTextDisp.c: cleanup and clarify some comments
	* doc/text.n: cleanup some of the markup.

2003-11-15  David Gravereaux <[email protected]>

	* win/makefile.vc: Fixes pkgIndex.tcl generation so a symbols build is
	loaded when Tcl is symbols.

2003-11-15  Vince Darley <[email protected]>

	* generic/tkTextDisp.c:
	* tests/textDisp.test: fixes to one more old Tk [Bug 422411] this time
	concerning inconsistent tab interpretation. Also fixed an unreported
	new problem if a single logical line wraps to fill more than the
	entire display.

	* macosx/tkMacOSXScrlbr.c: fix to [Bug 840978] where the size of the
	proportional scrollbar was calculated wrongly.

2003-11-14  Joe English	 <[email protected]>

	* doc/text.n: Fix markup errors.

2003-11-15  Vince Darley <[email protected]>

	* generic/tkText.h:
	* generic/tkText.c:
	* generic/tkTextDisp.c:
	* generic/tkTextWind.c:
	* generic/tkTextTag.c:
	* tests/textDisp.test: fixes to another pair of old Tk bugs [Bug
	220816] (can't scroll horizontally to display all of last character),
	[Bug 842498] (xview confused on window creation), and more efficiency
	in tag creation. Added new tests.

2003-11-14  Donal K. Fellows  <[email protected]>

	* generic/tkTextDisp.c (TkTextRedrawTag): Get the correct number of
	lines in the region to be updated. This fix due to Vince Darley.
	(TkTextUpdateLineMetrics): Return the correct marker value when we know
	the update loop should terminate. [Bug 837300]

2003-11-13  Vince Darley <[email protected]>

	* tests/event.test:
	* library/text.tcl: fixed the text widget portion of [Bug 542199]

2003-11-13  Donal K. Fellows  <[email protected]>

	* generic/tkMenuDraw.c (TkPostSubmenu,AdjustMenuCoords): Rewrote to use
	Tcl_EvalObjv instead of Tcl_VarEval for greater robustness. A side
	benefit is that this should all be faster now too. [Bug 723856]

2003-11-12  Vince Darley <[email protected]>

	* generic/tkText.h:
	* generic/tkText.c:
	* generic/tkTextDisp.c:
	* generic/tkTextIndex.c:
	* generic/tkTextTag.c:
	* tests/textTag.test: fixes to two very old Tk bugs [Bug 583286]
	(focus handling with embedded windows), [Bug 220780] (tag bindings
	trigger on window borders), and made two more functions static in
	tkTextDisp.c.

	* library/text.tcl: fixed [Tcl Bug 699642] with double/triple-click
	insert positioning.

2003-11-11  Jeff Hobbs	<[email protected]>

	* unix/configure:
	* unix/configure.in: use xft-config instead of pkg-config to determine
	xft info.
	* unix/tcl.m4: improve AIX --enable-64bit handling remove
	-D__NO_STRING_INLINES -D__NO_MATH_INLINES from CFLAGS_OPTIMIZE on
	Linux. Make default opt -O2 (was -O).

	* generic/tkButton.c (ConfigureButton): abort option processing if the
	button was deleted. [Bug 824479]

	* generic/tkMenuDraw.c (TkPostSubmenu): add {} around menu name in case
	it has spaces when calling Tcl_VarEval. This is a hack until this is
	rewritten for proper Tcl_Obj handling. [Bug 723856]

	* library/tkfbox.tcl (::tk::dialog::file::Update): optimize the
	dir/files list separation by using the -tails, -directory and -type
	option of 'glob'. Also passes the glob the -filetypes filters instead
	of calling string match over each file. [Patch 833819]
	(::tk::dialog::file::ActivateEnt): allow typing filename into entry
	when tk_getOpenFile -multiple 1 is specified. [Bug 788069]

	* generic/tkListbox.c (ListboxDeleteSubCmd, ListboxListVarProc): free
	itemconfig data when removing it from table. [Bug 836483]

	* macosx/tkMacOSXClipboard.c (TkSuspendClipboard, TkSelGetSelection):
	add unicode clipboard support. [Patch 840107] (senn)

2003-11-10  Jeff Hobbs	<[email protected]>

	* win/configure:
	* win/tcl.m4: add necessary ole libs to VC LIBS_GUI line.

	* win/tkWinDraw.c (XFillRectangles): correctly handle the
	XGCValues.function parameter when filling rectangles. [Bug 820278]
	[Patch 820282]

	* win/configure:
	* win/configure.in: define TK_LIB_FLAG, TK_LIB_SPEC,
	TK_BUILD_LIB_SPEC, TK_STUB_LIB_SPEC, TK_STUB_LIB_PATH, and
	TK_BUILD_STUB_LIB_PATH for tkConfig.sh [Bug 826614]

	* unix/Makefile.in (SHLIB_LD_FLAGS): include in Makefile as it is used
	in MAKE_LIB sometimes (ie: AIX-64) [Bug 829686] (jimix)

2003-11-10  Vince Darley <[email protected]>

	* generic/tkTextDisp.c: correct yview handling of text widgets
	containing no vertical pixels at all.

2003-11-08  Pat Thoyts	<[email protected]>

	* win/tclWinSend.c: Fixed an error returning the registered name.

2003-11-08  Vince Darley <[email protected]>

	* tests/textDisp.test:
	* tests/text.test:
	* generic/tkText.h:
	* generic/tkTextIndex.c:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c: fix to another version of [Bug 833627] (crash
	in tkchat), adding more tests. I believe the handling of nested elide
	tags of all types is now correct!

2003-11-07  Vince Darley <[email protected]>

	* tests/textDisp.test:
	* generic/tkTextDisp.c: fix to another version of [Bug 833627] (crash
	in tkchat), adding two new tests.

	* generic/tkText.c
	* generic/tkTextIndex.c
	* generic/tkTextDisp.c
	* generic/tkTextWind.c
	* generic/tkTextImage.c
	* generic/tkTextTag.c
	* generic/tkTextMark.c
	* generic/tkTextBTree.c
	* generic/tkText.h
	* doc/text.n
	* tests/text.test
	* tests/textWind.test: better handling of 'elide' tags, especially
	during line layout, counting and forward/backward index movement. Added
	new tests to ensure correct behaviour with multiple tags of multiple
	priorities.

2003-11-05  Donal K. Fellows  <[email protected]>

	* library/demos/nl.msg: Dutch messages from Arjen Markus [Patch 836368]
	* library/demos/widget: Added mechanism to support some l10n of the
	actual hotkeys used.

2003-11-04  Vince Darley <[email protected]>

	* tests/textDisp.test:
	* tests/textWind.test: fix to rest of test suite problems reported in
	[Bug 833761]. This also has the nice effect that many more tests are
	now run on Windows.

2003-11-04  Donal K. Fellows  <[email protected]>

	* library/demos/widget (showCode,printCode): Added code to print the
	source code on Unix and Win, courtesy of Arjen Markus and the Wiki.
	[Patch 835644]

2003-11-03  Vince Darley <[email protected]>

	* generic/tkTextDisp.c
	* tests/textDisp.test: test and fix to a panic reported in [Bug
	833627], with tkchat, and an unused variable [Bug 835010]. Also fixes
	substantial parts of [Bug 833761]

2003-11-03  Donal K. Fellows  <[email protected]>

	* library/demos/widget, etc.: Made widget demos locate themselves
	independently of the main Tk library using the new global variable
	tk_demoDirectory. [Patch 832691, adapted]

	* generic/tkTextDisp.c (TextGetScrollInfoObj): Stop complaints about
	signed vs. unsigned for the length of strings.

2003-11-01  Donal K. Fellows  <[email protected]>

	* library/msgs/nl.msg: Updated messages from Arjen Markus and Pascal
	Scheffers. Thanks! [Patch 820519]

2003-10-31  Jeff Hobbs	<[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoBlendComplexAlpha): OS X uses 32bpp
	images internally always, so make use of the assumption.

2003-10-31  Vince Darley <[email protected]>

	TIP#155 IMPLEMENTATION

	* generic/tkText.c, generic/tkTextIndex.c, generic/tkTextDisp.c
	* generic/tkTextWind.c, generic/tkTextImage.c, generic/tkTextTag.c
	* generic/tkTextMark.c, generic/tkTextBTree.c, generic/tkText.h
	* doc/text.n, tests/text.test, tests/textDisp.test
	* tests/textImage.test, tests/textIndex.test, tests/textWind.test
	* library/text.tcl, generic/tkCanvas.c, unix/tkUnixDefault.h
	* win/tkWinDefault.h, mac/tkMacDefault.h, macosx/tkMacOSXDefault.h

	This adds the 'count' and 'replace' subcommands to the text widget, the
	'-blockcursor' option, and in particular provides correct, smooth
	pixel-based scrolling of the widget under all circumstances. See the
	text.n man page for the complete new documentation. This also fixes
	[Bugs 559450 778511 779174].

	* generic/tkTextDisp.c
	* tests/textDisp.test: tests and fix to the promptly reported [Bug
	833627]

2003-10-31  Vince Darley <[email protected]>

	* win/tkWinMenu.c: more correct placing of images in compound menu
	entries.

2003-10-30  Jeff Hobbs	<[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoBlendComplexAlpha): add alpha blending
	for images with partial transparency. Only operates for 15bpp+ display.
	[Bug 809157]

2003-10-29  Donal K. Fellows  <[email protected]>

	* unix/tkUnixRFont.c: Some cleaning up to get the file more in lines
	with the general style guidelines. [Bug 832091] Still many comments
	needed (from someone who knows the code!) for the style guide to be
	satisfied, so bug still open.

	* library/tkfbox.tcl (IconList_Create,IconList_Add): Added option
	munging to allow some control of foreground colours on Unix in the same
	way that you can influence the background. [Bug 795717]

2003-10-28  Jeff Hobbs	<[email protected]>

	* unix/tkUnixFont.c (GetFontAttributes): place extra check for NULL
	family against bad X servers.

	* win/tkWinImage.c (XGetImageZPixmap): add separate 16bpp XGetImage
	code to correctly handle 16bpp requests. This appears to never have
	worked correctly.

	* tests/focusTcl.test (setup1): expand frame size to allow for correct
	visibility of windows that use larger default fonts.

2003-10-28  Donal K. Fellows  <[email protected]>

	* library/tk.tcl (::tk::PlaceWindow): Added check for empty string
	first when determining placement strategy. [Bug 819284]

2003-10-23  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXDialog.c (NavServicesGetFile): Minor cleanups.
	(OpenFileFilterProc): Handle FSRef's as well as FSSpec's in the input
	file. Also convert the FSSpec filename to an C-string before passing to
	MatchOneFile. [Bug 517600]
	(MatchOneFile): Require the input filename to be a C-string, not a
	pascal string.

2003-10-22  Donal K. Fellows  <[email protected]>

	* library/dialog.tcl (tk_dialog): Constrain the dialog to be fairly
	sensibly sized and placed. [Bug 827535]

2003-10-15  Joe English	 <[email protected]>

	* unix/tkUnixWm.c, tests/unixWm.test: Delete WM_TRANSIENT_FOR property
	instead of setting it to None when making a window nontransient [Bug
	632816 "cannot remove transient"]

2003-10-14  Joe English	 <[email protected]>

	* unix/tkUnixPort.h(TkPutImage): changed macro argument names to match
	function argument names ('dest' and 'src' were swapped, which was
	confusing) [GPS]

2003-10-14  Pat Thoyts	<[email protected]>

	* win/makefile.vc:  Applied patches from tcl bug 801467 from
	* win/winMain.c:    Joe Mistachkin

2003-10-12  Jeff Hobbs	<[email protected]>

	* generic/tkInt.h:	move TkGetOptionSpec to stubs intDecls
	* generic/tkIntDecls.h:
	* generic/tkInt.decls:
	* generic/tkStubInit.c:
	* tkDecls.h:		updated with latest genstubs
	* tkIntPlatDecls.h:
	* tkIntXlibDecls.h:
	* tkPlatDecls.h:

	* tests/listbox.test (13.3): correct result size
	(4.7): correct test for possible window drift [Bug 701931] (dgp)

	* unix/mkLinks:
	* doc/GetHWND.3: add Tk_AttachHWND docs [Bug 220803]

2003-10-10  Jeff Hobbs	<[email protected]>

	* mac/tkMacButton.c (TkpDisplayButton):
	* macosx/tkMacOSXButton.c (TkpDisplayButton):
	* unix/tkUnixButton.c (TkpDisplayButton): correct imageYOffset for
	buttons with just images.

2003-10-10  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (TkRegisterObjTypes): Register the type of text
	indexes.

2003-10-09  Jeff Hobbs	<[email protected]>

	* win/tkWinButton.c (TkpDisplayButton): correct imageYOffset for
	buttons with just images.

2003-10-08  Pat Thoyts	<[email protected]>

	* win/tcl.m4:	      Add TIP #150 items to the TEA makefiles.
	* win/configure:
	* win/Makefile.in:

	* win/tkWinSend.c:    Clean up some warnings from gcc -Wall.
	* win/tkWinSendCom.c:

2003-10-06  Joe English	 <[email protected]>

	* library/text.tcl, doc/text.n: Text widget binding for Control-v is
	now Mac-only, since it conflicts with standard <<Paste>> binding on
	other platforms. [Bug 605277]

2003-10-06  Joe English	 <[email protected]>

	* generic/tkStyle.c: Fix double-free in style engine [Bug 798211]

2003-10-06  Jeff Hobbs	<[email protected]>

	* win/configure:
	* win/tcl.m4: removed incorrect checks for existence of optimization.
	TCL_CFG_OPTIMIZED is now defined whenever the user does not build with
	--enable-symbols.

2003-10-06  Don Porter	<[email protected]>

	* doc/ConfigWidg.3:	Removed reference to Tk_Offset from the NAME
	section to resolve mkLinks conflict with SetOptions.3 [Bug 404197]

	* unix/configure.in:	 Reconfigured to use $TCL_PREFIX as the default
	value of --prefix, and also added warning when a TK_PREFIX value
	different from TCL_PREFIX is selected, since [package require Tk] fails
	in that configuration. [Bugs 428627,765642]

	* unix/tcl.m4 (SC_PATH_TCLCONFIG):	Corrected search path so that
	alpha and beta releases of Tcl are not favored. [Bug 608698]

	* unix/configure.in:	Added check that version of Tcl header found by
	configure matches that of the Tk we wish to build. As long as the Tk
	sources insist on lockstep releases, Tk's configuration should verify
	that's what we have. [Bug 749088]

	* unix/configure:	autoconf (2.57)
	* unix/mkLinks:		make mklinks

2003-10-03  Pat Thoyts	<[email protected]>

	* library/scale.tcl: Clear bug with chording mouse buttons.

	* library/console.tcl: Avoid including the console in the list of
	interpreters exposed by [winfo interps].

2003-10-01  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Makefile: fixed redo prebinding bug when DESTDIR="". Added
	support for all applicable customizable makefile variables from
	tcl/macosx/Makefile.

	* macosx/README:
	* macosx/Wish.pbproj/project.pbxproj: ensure that the versioned wishX.X
	script works correctly when Tk.framework with multiple versions is
	present by referring to a copy of 'Wish Shell.app' located in
	Tk.framework/Versions/X.X/Resources.

2003-09-30  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXButton.c (TkpDisplayButton): Use the tk text drawing
	for checkbuttons & radiobuttons as well as for labels.
	* macosx/tkMacOSXEvent.c (XSync): New function, need to implement this
	so drawing will get flushed in "update idletasks".
	* tkMacOSXPort.h: convert #define of XSync to function def'n.

2003-09-30  Donal K. Fellows  <[email protected]>

	* library/demos/browse:		Added suitable [package require] lines
	* library/demos/hello:		to all the Tk demo scripts which are
	* library/demos/ixset:		not run as part of something larger.
	* library/demos/rmt:		[FRQ 815118]
	* library/demos/rolodex:
	* library/demos/square:
	* library/demos/tcolor:
	* library/demos/timer:
	* library/demos/widget:

2003-09-30  Pat Thoyts	<[email protected]>

	* tests/safe.test:    Accomodate TIP #150 in the results.
	* tests/textWind.test: Fix a dependancy on font size in 10.1

2003-09-30  Donal K. Fellows  <[email protected]>

	* generic/tkCanvas.c (TkGetStringsFromObjs):
	* generic/tkPanedWindow.c (PanedWindowWorldChanged): Private functions
	should be either static or prefixed with 'Tk' (thanks to George Staplin
	for spotting this.)

2003-09-27  Pat Thoyts	<[email protected]>

	TIP#150 IMPLEMENTATION

	* win/makefile.vc:    Implementation of TIP #150, "Provide 'send'
	* win/tkWinSend.c:    command for Windows"
	* win/tkWinSendCom.h:
	* win/tkWinSendCom.c:

2003-09-26  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXWm.c (TkWmStackorderToplevelWrapperMap): Add
	GetWindowFromPort() [Bug 812415]; make function static.

2003-09-25  Daniel Steffen  <[email protected]>

	* library/demos/widget: don't create iconwindow on aqua, but add about
	menu like on classic.
	* macosx/Makefile: pass MAKEOVERRIDES to pxbuild.
	* macosx/tkMacOSXButton.c: added -compound support for bevel buttons.

	* unix/configure:
	* unix/configure.in:
	* unix/tkConfig.sh.in: added TK_INCLUDE_SPEC to allow extensions to
	find installed Tk headers, parallel to TCL_INCLUDE_SPEC. [Bug 777203]

2003-09-18  Chengye Mao <[email protected]>

	* generic/tkConsole.c: Fixed memory leak [Bug 802435]

2003-09-18  Peter Spjuth  <[email protected]>

	TIP#147 IMPLEMENTATION

	* doc/grid.n:
	* tests/grid.test:
	* generic/tkGrid.c: Implementation of TIP#147, "Make Grid's Column/Row
	Configure Easier".

2003-09-17  Don Porter	<[email protected]>

	* generic/tkImage.c:	Stopped [image create] from generating an image
	* tests/image.test:	command name that would overwrite an existing
	command name. Thanks to Michael Schlenker. [Bug 808039].

2003-09-16  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: Reworked a part of grid's geometry computations to
	handle some tricky cases better. [Bug 792387]

2003-09-05  Joe English	 <[email protected]>

	* doc/bind.n: Describe %P and %s substitution for Property events.
	[Bug 577906 "%P substitution not documented"]

2003-09-05  Don Porter	<[email protected]>

	* doc/wish.1:			Implementation of TIPs 137/151.
	* generic/tkMain.c (Tk_MainEx):	Added recognition of the -encoding
	* tests/main.test:		command line option by Tk_MainEx() and
	thus by wish and any other program built on Tk_MainEx(). [Patch 800139]
	This is a ***POTENTIAL INCOMPATIBILITY*** only for those C programs
	that embed Tcl and Tk, build on Tk_MainEx(), and make use of
	Tk_MainEx's former ability to pass a leading "-encoding" option to
	interactive shell operations.

2003-08-27  Donal K. Fellows  <[email protected]>

	* generic/tkListbox.c (ListboxSelect): Remove unused variable
	'increment'. [Bug 664783]

2003-08-25  David Gravereaux  <[email protected]>

	* win/makefile.vc: Don't do a string compare on the $(DBGX) variable,
	use the $(DEBUG) boolean directly. Also, don't try to regen the stubs
	table if $(TCLSH) doesn't exist.

2003-08-22  Donal K. Fellows  <[email protected]>

	* library/demos/msgbox.tcl: Brought into line with the newer
	look-and-feel for the demos.
	* library/demos/widget (addSeeDismiss): Added support for an extra
	button defined by the caller.

2003-08-21  Pat Thoyts	<[email protected]>

	* win/tkWin3d.c: Applied Tk patch 791273 from Jeremy Collins which
	improves the 3d lines for sunken widgets under windows.

2003-08-20  Jeff Hobbs	<[email protected]>

	* library/demos/widget:	     Redo code view dialog, use named fonts,
	* library/demos/arrow.tcl:   add basic see/dismiss routine with images
	* library/demos/bind.tcl:    for better look & feel
	* library/demos/bitmap.tcl:
	* library/demos/button.tcl:
	* library/demos/check.tcl:
	* library/demos/clrpick.tcl:
	* library/demos/colors.tcl:
	* library/demos/cscroll.tcl:
	* library/demos/ctext.tcl:
	* library/demos/entry1.tcl:
	* library/demos/entry2.tcl:
	* library/demos/entry3.tcl:
	* library/demos/filebox.tcl:
	* library/demos/floor.tcl:
	* library/demos/form.tcl:
	* library/demos/hscale.tcl:
	* library/demos/icon.tcl:
	* library/demos/image1.tcl:
	* library/demos/image2.tcl:
	* library/demos/items.tcl:
	* library/demos/label.tcl:
	* library/demos/labelframe.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/paned1.tcl:
	* library/demos/paned2.tcl:
	* library/demos/plot.tcl:
	* library/demos/puzzle.tcl:
	* library/demos/radio.tcl:
	* library/demos/ruler.tcl:
	* library/demos/sayings.tcl:
	* library/demos/search.tcl:
	* library/demos/spin.tcl:
	* library/demos/states.tcl:
	* library/demos/style.tcl:
	* library/demos/text.tcl:
	* library/demos/twind.tcl:
	* library/demos/unicodeout.tcl:
	* library/demos/vscale.tcl:

2003-08-20  Donal K. Fellows  <[email protected]>

	* generic/tkCanvPs.c (Tk_PostscriptFont): Use Tcl_Obj-based interfaces
	for working with user-supplied font maps.

2003-08-19  Joe English	 <[email protected]>

	* generic/tkPanedWindow.c (PanedWindowWorldChanged): Set window
	background from the -background resource. Fixes [Bug 791500
	"PanedWindow refresh glitches on X"]

2003-08-19  Joe English	 <[email protected]>

	* doc/bind.n: Added more information on event types and details [FRQ
	523593 "bind(n) manpage needs more detail"]

2003-08-18  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl to fix Tcl bug 781109.

2003-08-15  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoCmd): Faster color data parsing code
	for the [$photo put] subcommand. Now doesn't do everything through the
	pre-8.0 list handling routines!

2003-08-14  Donal K. Fellows  <[email protected]>

	* unix/tkUnixButton.c (TkpDisplayButton): Stopped accesses to NULL
	* unix/tkUnixMenu.c (TkpDrawMenuEntry):	  pointers that crashed tests.

	TIP #109 IMPLEMENTATION FROM Brian Griffin <[email protected]>
	* unix/tkUnixButton.c (TkpDrawCheckIndicator, TkpDisplayButton):
	* unix/tkUnixMenu.c (DrawMenuEntryIndicator, TkpDrawMenuEntry):
	Much improved display of checkbuttons and radiobuttons on UNIX/X.

2003-08-13  Pat Thoyts	<[email protected]>

	* library/scale.tcl: Fix for [Bug 787065] for Button-2 press.
	* tests/scale.test:  Added test for this bug.

2003-08-12  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXMenu.c: fixed C99'ism that breaks gcc 2.95.

2003-07-28  Pat Thoyts	<[email protected]>

	* win/tkWinDialog.c: Applied patch from [Bug 611615] which fixes a
	problem with double clicks in file dialogs falling through to the
	window underneath in win32.

	* library/panedwindow.tcl: Apply patch from [Bug 778893] to make the
	panedwindow -opaqueresize option work as per the docs.

	* library/tk.tcl: Apply fix for [Bug 778840] for window placement when
	using multiple desktops on windows.

2003-07-24  Pat Thoyts	<[email protected]>

	* win/tkWinCursor.c: Fix for [Bug 776646] for a native hand2 and fleur
	(move) cursor under win.
	* tests/cursor.test: Check that documented cursors are available.

2003-07-20  Daniel Steffen  <[email protected]>

	* macosx/buildTkConfig.tcl: fix to TK_BUILD_* ref generation broken by
	changes to tcl buildsystem.

2003-07-19  Pat Thoyts	<[email protected]>

	* win/tkWinCursor.c (TkGetCursorByName): Fix bug 420510 to provide
	consistency between unix and windows -cursor option.

	* library/scale.tcl: Fix for bug 706765 to correctly handle the
	-sliderrelief option while moving the thumb.

2003-07-18  Jeff Hobbs	<[email protected]>

	* unix/tkUnixFont.c (Tk_DrawChars): do not make XGetGeometry call that
	prevents overwidth lines as it requires a roundtrip call to the X
	server for every string drawn. Hard-code max width to 32768 until a
	better solution to get max width is made.

	* library/panedwindow.tcl: use widget-specific Priv slots for pwAfterId
	and panecursor items to correctly handle cursor changes with adjacant
	panedwindows.

	* generic/tkEvent.c (Tk_HandleEvent): correct XCreateIC call for
	TK_XIM_SPOT usage. [Bug 742660] (takahashi)

	* win/tkWinDialog.c: doubled the TK_MULTI_MAX_PATH value to ~10K. This
	is a short-term solution until the -multiple option is extended. [Bug
	641261]

2003-07-18  Vince Darley <[email protected]>

	* generic/tkWindow.c:
	* macosx/tkMacOSXDialog.c: added native tk_messageBox command,
	(Tk_MessageBoxObjCmd) for MacOS X platform.

	* macosx/tkMacOSXMenu.c: corrected encoding conversion for torn-off
	menu entries (but many other display problems still exist with these)

	* macosx/tkMacOSXMouseEvent.c: improved handling of events in the
	presence of grabs, particularly activation events.

2003-07-18  Donal K. Fellows  <[email protected]>

	* tests/panedwindow.test (panedwindow-30.2):
	* generic/tkPanedWindow.c (Tk_PanedWindowObjCmd): Ensure that we can
	share GCs between a panedwindow and its sash proxy, even if the
	panedwindow is in a toplevel with a different visual. [Bug 702230]

2003-07-17  Daniel Steffen  <[email protected]>

	* macosx/Makefile: Changes for new tcl buildsystem.

	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj:
	Changes for new tcl buildsystem. Changed build to include tk specific
	html help in Tk.framework instead of Tcl.framework. Set default SYMROOT
	in target options to simplify setting up PB (manually setting common
	build folder for tcl & tk no longer needed).

	* macosx/README: Updated info for changes to buildsystem, html help
	location and PB setup.

2003-07-17  Donal K. Fellows  <[email protected]>

	* doc/photo.n: [$photo put] has been able to take rectangles of pixel
	colours, specified as lists of lists, for years. Now this is a
	documented feature. [Bug 728952]

	* doc/panedwindow.n: Removed warning invalidated by fix from Bug
	738143. [Bug 747814]

	* generic/tkImgPhoto.c (ImgPhotoCmd): Rewrote subcommand processing to
	never jump to the end of the switch. I find that confusing as I can't
	see whether there's processing still to be done from a quick glance at
	the code, unlike with a direct return. [Bug 771988]
	(ImgPhotoCmd, ImgPhotoSetSize, ImgPhotoInstanceSetSize): Try harder to
	avoid zero-length mallocs()... [Bug 404421]

2003-07-16  Don Porter	<[email protected]>

	* generic/tkPack.c (ConfigureSlaves): silence compiler warning
	[Bug 771982]

2003-07-16  Jeff Hobbs	<[email protected]>

	* win/tkWinImage.c (XGetImage): correct init of biSizeImage in bitmap
	header. [Bug 703697] (cap)

2003-07-17  Peter Spjuth  <[email protected]>

	* tests/frame.test:
	* generic/tkFrame.c (CreateFrame): Make sure all options can be set to
	their default value. [Bug 697652]

2003-07-16  Jeff Hobbs	<[email protected]>

	* generic/tkPanedWindow.c (ArrangePanes): Ensure that the last pane
	* tests/panedwindow.test: shrinks instead of being clipped when resized
	below the reqsize. [Bug 748277] (spjuth)

	* generic/tkWindow.c (Initialize): do not free uninit'ed dstring.
	[Bug 755906] (mistachkin)

2003-07-09  Donal K. Fellows  <[email protected]>

	* tests/send.test: Strengthened constraints to stop accidental smashing
	of Xserver access; some systems (*ahem* mine *ahem*) require
	xhost-style security for all use... :^/

2003-07-07  Jeff Hobbs	<[email protected]>

	* generic/tkTextDisp.c (DisplayText): correct use of textPtr data with
	respect to Tcl_Release time. [Bug 767009]

2003-07-07  Donal K. Fellows  <[email protected]>

	* generic/tkImage.c (TkDeleteAllImages,etc.): Stopped the deleting of
	hash entries from a table that has just been deleted by this function
	when some images are Tcl_Preserve()d... [Bug 749353]

2003-07-03  Jim Ingham <[email protected]>

	* macosx/tkMacOSXColor.c (GetControlPartColor): Use the ThemeBrushes to
	get the control text color for buttons.

2003-07-02  Mo DeJong  <[email protected]>

	* unix/tkUnixEvent.c (TkpCloseDisplay): Don't test for XCloseIM bug
	when the XFree86 version is newer than 4.0 since the layout of the XIM
	structure has changed. The check is not needed for newer XFree86
	releases since the bug we are checking for was fixed in the 4.2.99.2
	release. [Bug 755530]

2003-06-26  Vince Darley <[email protected]>

	* library/menu.tcl: workaround problem on some Windows systems by
	trying to avoid posting a menu offscreen.

2003-06-09  Joe English	 <[email protected]>

	* unix/tkUnixRFont.c: fix for [Bug 751553] "Xft: [font configure] does
	not update in-use fonts". Fixed TkpGetSubFonts() to return information
	about all subfonts, not just the first one.

2003-06-01  Joe English	 <[email protected]>

	* unix/configure.in: BUGFIX, --enable-xft test was broken.
	* unix/configure: regen

2003-05-31  Joe English	 <[email protected]>

	* unix/tkUnixRFont.c (InitFont): Fill in TkFontAttributes from pattern
	returned from GetFont (actual font) instead of the query pattern
	(requested font).

2003-05-31  Joe English	 <[email protected]>

	* unix/tkUnixRFont.c: New file
	* unix/tkUnixDefault.h: Use different default fonts if HAVE_XFT
	* unix/Makefile.in:
	* unix/configure.in: Add --enable-xft flag
	* unix/configure: regen
	Experimental support for antialiased text under X11 [Patch 535541]

2003-05-30  Vince Darley <[email protected]>

	* generic/tkMenu.c
	* generic/tkMenu.h
	* generic/tkMenuDraw.c:
	* tests/menu.test: fixed complex bug in menu clone cleanup [Bug 465324]
	and removed 'knownBug' from a test.

2003-05-29  Joe English	 <[email protected]>

	* doc/text.n: Fixed markup errors.

2003-05-28  Miguel Bañón <[email protected]>

	* library/msgs/cs.msg: Updated messages from [email protected]

2003-05-27  Vince Darley <[email protected]>

	* generic/tkText.c
	* generic/tkTextTag.c
	* generic/tkTextDisp.c
	* generic/tkText.h: refactoring of text widget cleanup code to ensure
	all resources are freed. [Bug 741179]

	* library/tearoff.tcl: ensure torn-off menus do not appear underneath
	the MacOS/MacOS X main menu bar.

2003-05-23  Mo DeJong  <[email protected]>

	* unix/mkLinks: Set the var S to "" at the top of the file to avoid
	error when user has set S to something. [Bug 739833]

2003-05-21  Donal K. Fellows  <[email protected]>

	* generic/tkPanedWindow.c (PanedWindowReqProc): Thanks very much to
	Eric Boudaillier for making panes resize correctly! [Bug 738143]

	* generic/tkText.c (TextSearchCmd): Forwards and backwards aren't the
	same. [Bug 740558] Also edited SearchCore to get it closer to the
	Engineering Manual style guidelines.

2003-05-19  Donal K. Fellows  <[email protected]>

	* tests/textImage.test:		Fixed faults in option parsing and made
	* tests/text.test:		tests conformant. [Bug 739965]
	* generic/tkText.c (TextSearchCmd):

	* library/demos/en.msg: Base catalog for the widget demo.
	* library/demos/widget: Added message-catalog support.
	* library/console.tcl: Reworked to use tk::AmpMenuArgs and be more "in
	style".
	* library/tk.tcl (tk::AmpMenuArgs): New procedure for doing
	tk::AmpWidget-like processing for menus.

	* generic/tkTextMark.c:		Removed complaints about signed vs.
	* generic/tkTextImage.c:	unsigned in arguments to strncmp() by
	* generic/tkText.c:		using Tcl_GetIndexFromObj() more.

2003-05-19  Vince Darley <[email protected]>

	TIP#113 IMPLEMENTATION

	* doc/text.n
	* generic/tkCanvas.c
	* generic/tkInt.h
	* generic/tkTest.c
	* generic/tkText.c
	* generic/tkText.h
	* generic/tkTextBTree.c
	* generic/tkTextDisp.c
	* generic/tkTextImage.c
	* generic/tkTextIndex.c
	* generic/tkTextMark.c
	* generic/tkTextTag.c
	* generic/tkTextWind.c
	* generic/tkUndo.c
	* generic/tkUndo.h
	* generic/tkWindow.c
	* library/text.tcl
	* tests/text.test
	* tests/textIndex.test
	* tests/textMark.test
	* tests/textTag.test
	* tests/textWind.test: This adds multi-line searching and '-all'
	searching to the text widget. In addition the changes contain a
	complete 'objectification' of the text widget. Includes documentation
	and new tests.

2003-05-19  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj: changed tkConfig.sh location in
	versioned framework subdirectories to be identical to location in
	framework toplevel; fixed stub library symbolic links to be tk version
	specific.

2003-05-15  Jeff Hobbs	<[email protected]>

	* unix/tkUnixFont.c: use gb2312-raw as the alias for gb2312* charset
	fonts. gb2312.enc was made to be euc-cn for Tcl because that is what
	is most often meant, but X really wants the original (-raw) gb2312
	encoding. [Bug 557030]

2003-05-14  Jeff Hobbs	<[email protected]>

	* library/msgs/fr.msg: updated msg catalog. [Bug 737790] (zolli)

2003-05-13  Vince Darley <[email protected]>

	* win/makefile.vc: fix to installation of winhelp into path containing
	a space (Bug 693512)

2003-05-13  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXInit.c (TkpInit): use new versioned bundle resource
	API to get tk runtime library for TK_VERSION. [Bug 736774]

2003-05-10  Jeff Hobbs	<[email protected]>

	* generic/tkCanvPoly.c (PolygonToPostscript):
	* tests/canvPs.test: correct crash when generating postscript for a
	single-line polygon (point) with no color. [Bug 734498] (wilm)

2003-05-10  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXClipboard.c (TkSelGetSelection): Convert '\r' to '\n'
	on the way into Tcl.

2003-05-08  Donal K. Fellows  <[email protected]>

	* tests/image.test (image-15.1): Test to ensure that widgets pick up
	image information even if the image is deleted and recreated.

	* generic/tkImage.c (Tk_ImageObjCmd): Use the ImageMaster's deleted
	flag to stop deleted images from showing up in the various [image *]
	operations. Can't delete directly from the table because that makes us
	lose the information about what widgets want to use the image. [Bug
	634864]

2003-04-30  Jeff Hobbs	<[email protected]>

	* macosx/tkMacOSXButton.c (TkpDisplayButton): correct typo for
	stippleGC [Bug 730124].

2003-04-25  Jeff Hobbs	<[email protected]>

	* generic/tkButton.h:			      Rewrote the handling of
	* generic/tkButton.c (TkButtonWorldChanged):  compound *buttons to
	* mac/tkMacButton.c (TkpDisplayButton):	      correctly display mixture
	* macosx/tkMacOSXButton.c (TkpDisplayButton): of disabledfg,
	* unix/tkUnixButton.c (TkpDisplayButton):     selectcolor, indicator,
	* win/tkWinButton.c (TkpDisplayButton):	      etc. *buttons will now
	only stipple the image, unless no disabledfg is given, in which case it
	will stipple the whole button.

	* library/bgerror.tcl: make bgerror dialog topmost on Windows to
	prevent it being covered by other windows.

	* unix/tkUnixButton.c (TkpDisplayButton): Use the normalTextGc when
	* win/tkWinButton.c (TkpDisplayButton):	  displaying disabled text that
	have images, as they get a gray50 stipple as well and the disabledGc is
	not set up correctly for font drawing. [Bug 477740]

2003-04-18  Jeff Hobbs	<[email protected]>

	* win/configure: regen
	* win/configure.in (SHELL): force it to /bin/sh as autoconf 2.5x uses
	/bin/bash, which can fail to find exes in the path (ie: lib).

	* generic/tkCanvBmap.c: s/CreateBitmap/TkcCreateBitmap as Windows has a
	CreateBitmap function already.

	* generic/tkCursor.c: s/GetCursor/TkcGetCursor as Windows has a
	GetCursor func already, which causes compiler warnings.

2003-04-14  Mo DeJong  <[email protected]>

	* win/tkWinMenu.c (TkpInitializeMenuBindings): Rename the private menu
	helper cmd from tk::tkWinMenuKey to tk::WinMenuKey. [Bug 721514]

2003-04-14  Mo DeJong  <[email protected]>

	* generic/tkBind.c (TkpGetBindingXEvent): Add helper method that can be
	used to query the XEvent* for the currently executing binding.
	* generic/tkInt.h: Declare TkpGetBindingXEvent.
	* win/tkWinMenu.c (MenuKeyBindProc, TkWinMenuKeyObjCmd)
	(TkpInitializeMenuBindings): Rename MenuKeyBindProc to
	TkWinMenuKeyObjCmd and convert it into a Tcl command named
	tk::tkWinMenuKey. Bind keyboard accelerator actions to this Tcl command
	instead of using a native C binding. This makes it possible to extend
	the existing binding with Tcl code and makes the Windows version work
	just like the unix version.

2003-04-04  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Subst TCL_LIBS instead of DL_LIBS and MATH_LIBS.
	* unix/configure: Regen.
	* unix/configure.in: Remove SC_ENABLE_THREADS invocation. Thread
	support in an extension should be automatic when Tcl is compiled with
	thread support. Add AC_DEFINE calls to set TCL_THREADS, _REENTRANT, and
	_THREAD_SAFE since this was done in SC_ENABLE_THREADS. Remove socket
	and math lib checks since these are already done in the Tcl configure
	script.
	* unix/tcl.m4: Update from Tcl to get TCL_LIBS fix. This fixes [Bug
	597847] which was caused by improper linking.
	* unix/tkConfig.sh.in: Subst TCL_LIBS instead of MATH_LIBS and DL_LIBS.
	[Bug 597847]

2003-04-02  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Set stub lib flag based on new LIBFLAGSUFFIX
	variable.
	* win/tcl.m4: Update from Tcl to get new LIBFLAGSUFFIX variable.

2003-04-02  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Don't set TCL_DLL_FILE, TCL_LIB_FILE,
	TCL_STUB_LIB_FILE, TCL_STUB_LIB_FLAG, and TCL_BUILD_STUB_LIB_SPEC.
	These variables are already set in tclConfig.sh. Don't subst vars that
	are either not used, or already covered by a subst in
	SC_LOAD_TCLCONFIG. [Bug 691908]

2003-04-01  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2003-04-01  Don Porter	<[email protected]>

	* tests/all.tcl:		Made better use of a common -loadfile
	* tests/constraints.tcl:	to hold definitions common to all test
	* tests/*.test:			files.

2003-03-27  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2003-03-26  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl to get BeOS changes.

2003-03-22  Kevin Kenny	 <[email protected]>

	* win/makefile.vc:
	* win/rules.vc: Corrected several problems that prevented OPTS=symbols
	from building properly. [Patch 707792] Thanks to Joe Mistachkin for the
	fixes.

2003-03-20  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXApplication.r (removed):
	* macosx/tkMacOSXLibrary.r (removed):
	* macosx/tkMacOSXResource.r (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkAboutDlg.r: updated copyrights, cleaned up about box,
	removed obsolete unused resource files.

	* macosx/buildTkConfig.tcl: TK_DEFS space fix.

2003-03-18  Mo DeJong  <[email protected]>

	* win/tkConfig.sh.in: Add TK_DLL_FILE entry to mirror the TCL_DLL_FILE
	entry in tclConfig.sh. [Patch 694271]

2003-03-18  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/configure.in: Don't run the AC_CYGWIN macro since it uses
	AC_CANONICAL_HOST under autoconf 2.5X. Just check to see if __CYGWIN__
	is defined by the compiler and set the ac_cv_cygwin variable based on
	that. [Tcl Bug 705912]

2003-03-18  Don Porter	<[email protected]>

	* tests/unixWm.test (unixWm-41.2): Corrected typo in 2003-03-13 commit.
	Thanks Larry Virden. [Bug 705567]

2003-03-18  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Makefile:
	* macosx/README: added support for giving 'make' the location of
	Tcl.framework and tclsh to build and link against.

	* macosx/tkMacOSXXStubs.c: fixed crash in [winfo server].

2003-03-13  Don Porter	<[email protected]>

	* tests/unixWm.test:  Constrained all tests older than revision 1.21 to
	run only on Unix. Alternative approach did not match maintainer habits.
	* tests/spinbox.test (spinbox-17.4): Avoid long failure message.

2003-03-13  Mo DeJong  <[email protected]>

	Require autoconf 2.57 or newer, see TIP 34 for a detailed explanation
	of why this is good. This will no doubt break the build on some
	platforms, let the flaming begin.

	* unix/configure: Regen with autoconf 2.57.
	* unix/configure.in: Require autoconf 2.57.
	* unix/tcl.m4: Update from Tcl.
	* win/configure: Regen with autoconf 2.57.
	* win/configure.in: Require autoconf 2.57.
	* win/tcl.m4: Update from Tcl.

2003-03-12  Donal K. Fellows  <[email protected]>

	* library/msgbox.tcl (tk::MessageBox): Stopped message box buttons from
	getting very wide, and added some compensatory space so that the
	smaller buttons still look nice (well, to me). [Bug 701812]

2003-03-11  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXMenu.c (EventuallyInvokeMenu): New function, used to
	invoke menu commands at idle time.
	(TkMacOSXDispatchMenuEvent): Don't immediately dispatch menu commands,
	wait till the idle loop to do so. This is more like what is done on
	Windows, and avoids the crash from destroying a menu in it's command.

	* macosx/tkMacOSXHLEvents.c (ReallyKillMe): Don't force the shell to
	exit. According to the OS X HI guidelines, it should be possible to
	cancel an attempt to quit, and if we force the kill, here, it would not
	be possible to implement this.

2003-03-11  Mo DeJong  <[email protected]>

	* tests/unixWm.test: Add the testwrapper constraint to tests that
	depend on the testwrapper command. These tests should not be run under
	Windows for example.

2003-03-11  Mo DeJong  <[email protected]>

	* doc/wm.n (minimize, maximize): Remove claim that the resizable
	command keeps scripts from changing the size of windows since it is not
	true. The resizable command only applies to user sizing via user
	interaction.
	* tests/unixWm.test: Replace broken tests with the nonPortable
	constraint with new tests for maxsize and minsize options. These tests
	verify that setting the minsize and maxsize will resize the window if
	needed, and that the wm hints will be updated with the new sizes.
	* tests/wm.test: Add an exhaustive set of tests for the wm maxsize and
	wm minsize commands. These tests verify that setting the minsize and
	maxsize will resize the window if needed. These tests have only been
	run under Win98 and Window Maker under Linux, so further tweaking may
	be needed for other systems.
	* unix/tkUnixWm.c (UpdateGeometryInfo, UpdateSizeHints): Fixup
	comments and initialization for the minWidth, minHeight, maxWidth,
	maxHeight, width, and height members of the WmInfo struct. Check to
	ensure that a new toplevel window size is not larger than the maxsize
	or smaller than the minsize when updating the geometry at idle time.
	Pass new width and height values to the UpdateSizeHints method so that
	it can properly set the window min and max sizes for a window that
	cannot be resized by the user. This fixes a bug where the window
	resizes back to the original size when the user clicks on the window
	border.
	* win/tkWinWm.c (UpdateGeometryInfo): Fixup comments and
	initialization for the minWidth, minHeight, maxWidth, maxHeight, width,
	and height members of the WmInfo struct. Check to ensure that a new
	toplevel window size is not larger than the maxsize or smaller than the
	minsize when updating the geometry at idle time. [Patch 568861]

2003-03-11  Mo DeJong  <[email protected]>

	* generic/tkGrid.c (GridStructureProc, ConfigureSlaves): Check for a
	NULL masterPtr and slavePtr in the GridStructureProc code to ensure
	that a Gridder created before some error condition is ignored when it
	comes to geometry calculations. This approach closely matches the pack
	implementation. Keep track of a -in argument to a grid command in order
	to detect the case of an already gridded widget that wants to change
	some options. The previous implementation could make repeated and
	unnecessary calls to Tk_ManageGeometry. Replace use of "parent" with
	"master" in comments throughout the file.
	* generic/tkPack.c (PackStructureProc): Check for a NULL masterPtr
	before other checks so that a slave created under certain error
	conditions is cleaned up properly. Replace use of "parent" with
	"master" in comments throughout the file.
	* generic/tkPlace.c (CreateSlave, ConfigureSlave, SlaveStructureProc):
	Don't call Tk_ManageGeometry in CreateSlave since this was causing
	incorrect results in some error cases. Rework the ConfigureSlave method
	so that slave setup is done in one place. The call to Tk_ManageGeometry
	was added to the one place where a slave is setup. When a slave is
	configured but the master is not changed, simply goto the
	scheduleLayout label. Check for a NULL master in SlaveStructureProc for
	the sake of readability.
	* tests/grid.test:
	* tests/pack.test:
	* tests/place.test: Add test to check that a winfo manager call does
	not return incorrect results after an error condition is hit. [Patch
	693063]

2003-03-11  Kevin Kenny	 <[email protected]>

	* win/makefile.vc: Backported the code that makes the makefile build
	pkgIndex.tcl as part of the install step.

2003-03-07  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXMenus.c (TkMacOSXInitMenus): No longer need to call
	TkMacOSXSetHelpMenuItemCount.
	* macosx/tkMacOSXMenu.c (TkMacOSXHelpMenuItemCount): Stub out since it
	is no longer need (but is in the stubs table...).
	(TkMacOSXDispatchMenuEvent): Get the number of system help menu items
	from HMGetHelpMenu.
	(ReconfigureMacintoshMenu): Ditto.
	(TkpDestroyMenu): Ditto.

2003-03-06  Donal K. Fellows  <[email protected]>

	TIP#116 IMPLEMENTATION

	* doc/FindPhoto.3: Documentation of the photo API changes due to
	TIP#116

	* generic/tkImgPhoto.c (Tk_PhotoExpand, Tk_PhotoPutBlock)
	(Tk_PhotoPutZoomedBlock, Tk_PhotoSetSize): Added interp argument to
	these functions and made them return a standard Tcl result, with error
	indicating memory allocation failure instead of panic()ing.
	[See TIP #116 at http://purl.org/tcl/tip/116.html for discussion.]
	Each of these functions has also acquired a backward-compatability
	variant as well, named with a _Panic suffix.
	* generic.tk.decls: New API in new slots, back-compat API in old ones.
	* generic/tk.h (USE_PANIC_ON_PHOTO_ALLOC_FAILURE): Allow users to
	define this symbol to get the old 8.4 photo image API, including
	panic() calls when things go wrong.

	* generic/tkImgPhoto.c (ImgPhotoCmd): Adjusted to use the new API
	* generic/tkImgGIF.c (FileReadGIF):   discussed above.
	* generic/tkImgPPM.c (FileReadPPM):

2003-03-05  David Gravereaux  <[email protected]>

	* win/rules.vc: updated default tcl version to 8.5.

2003-03-04  Don Porter <[email protected]>

	* README:				Bumped version number of Tk to
	* generic/tk.h:				8.5a0.
	* library/tk.tcl:
	* mac/README:
	* macosx/Wish.pbproj/project.pbxproj:
	* unix/README:
	* unix/configure.in:
	* unix/tk.spec:
	* win/README:
	* win/configure.in:
	* win/makefile.vc:
	* win/tcl.m4:

	* unix/configure:      autoconf
	* win/configure:

2003-03-03  Jeff Hobbs	<[email protected]>

	*** 8.4.2 TAGGED FOR RELEASE ***

2003-02-28  Donal K. Fellows  <[email protected]>

	* tests/bind.test (bind-16.44):
	* generic/tkBind.c (ExpandPercents): Only allow events to see those
	expansions that are actually valid for them, and force the substitution
	of the rest as "??". This stops some crashes on Windows and gets rid of
	bogus values everywhere. [Bug 612110]

2003-02-26  Jeff Hobbs	<[email protected]>

	* macosx/README: correct 8.4.3 refs to 8.4.2.

	* unix/README: replace version refs with version-agnostic wording.

2003-02-25  Jeff Hobbs	<[email protected]>

	* win/tkWinInt.h:
	* win/tkWinDraw.c:
	* win/tkWinFont.c (Tk_DrawChars): add support for simple XOR text
	drawing on Windows. [Patch 685388] (martin)

	* generic/tkMenu.c (TkMenuCleanup): make sure to reset static
	menusInitialized on finalize. [Bug 548729]

2003-02-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXHLEvents.c: fixed conversion of apple event parameters
	to posix style path names. [Bug 621672] (steffen, Benjamin Riefenstahl)

	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXWm.c:
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXUtil.c (removed):
	* macosx/tkMacOSXUtil.h (removed): removed all references to
	tkMacOSXUtil.{c,h}, made obsolete by the patch above. [Bug 621672]

2003-02-24  Jeff Hobbs	<[email protected]>

	* unix/tkUnixFont.c (CreateClosestFont, CanUseFallback): use the first
	best font match in user font path. [Bug 647497] (dal zotto)

	* generic/tkListbox.c (ListboxSelectionSubCmd):
	* tests/listbox.test: Allow 'selection includes' to respond when
	disabled (but only 'includes'). [Bug 632514]

	* unix/tkUnixButton.c (TkpDisplayButton): Correct visual display of
	disabled check/radiobutton to be more distinctive on unix.
	* tests/unixButton.test: [Bug 669595] (hintermayer)

	* doc/panedwindow.n: clarified the need to use 'update idle' when
	adding unmapped windows. Needs further examination. [Bug 605105]

	* generic/tkEntry.c (SpinboxWidgetObjCmd, EntryWidgetObjCmd):
	* tests/entry.test:   return 1 if selection is present even if
	* tests/spinbox.test: entry/spinbox is disabled, as selection get will
	still return the selection (although selection still ignore modify
	requests when entry/spinbox is disabled). [Bug 637828]

2003-02-24  Benjamin Riefenstahl  <[email protected]>

	* tkMacOSXDialog.c (NavServicesGetFile): Fix bug with
	kNavCtlSetSelection - control data should be a pointer not a handle.

2003-02-21  Donal K. Fellows  <[email protected]>

	* library/clrpick.tcl (color::BuildDialog):
	* library/msgbox.tcl (MessageBox): Yet more places that did complex
	and fragile width calculations instead of using grid, though with these
	it is the -uniform option that saves the day.

	* library/tkfbox.tcl (file::Create): This procedure was really very
	crufty in how it went about creating the GUI. It is far easier and more
	robust to use the grid geometry manager than it is to tune the results
	of pack with tweaks to -width. [Bug 673722]

	* library/comdlg.tcl (FDGetFileTypes): Set an upper limit on how long a
	file type item description string can get due to appending of types.
	[Bug 617392]

	* tests/panedwindow.test (panedwindow-30.1):
	* generic/tkPanedWindow.c (DisplayPanedWindow, DisplayProxyWindow):
	Use the window's depth, not the screen's default depth. [Bug 671122]

2003-02-20  Daniel Steffen  <[email protected]>

	* library/console.tcl: (aqua & macintosh) added missing <Cmd-q> binding
	for corresponding Quit menu item shortcut.

	* macosx/README: updated instructions for embedded build, added various
	improvements by Russell Owen.

	* unix/tcl.m4: update from Tcl.
	* unix/configure: regen.

2003-02-20  Jeff Hobbs	<[email protected]>

	* win/tkWinScrlbr.c (UpdateScrollbar): use SIF_DISABLENOSCROLL to
	"disable" scrollbar when on Windows when there is nothing to scroll.
	This is Windows style, and fixes [Bug 624116].

	* tests/panedwindow.test:
	* generic/tkPanedWindow.c (ValidSashIndex): corrected to note that 2
	panes must exist before any one sash does. [tcllib Bug 689258]

2003-02-20  Peter Spjuth  <[email protected]>

	* tests/panedwindow.test:
	* generic/tkPanedWindow.c: Fixed calculation of the last slave's size
	when increasing the size of the panedwindow. [Bug 689099]

2003-02-20  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c (GetDataBlock): Removed pointless static variable
	ZeroDataBlock [Bug 664788]

	* unix/tkUnixFont.c (CanUseFallback): Added argument, passed through
	from callers to FindSubFontForChar(), so that pointers into the old
	subfont table to be updated when that table is reallocated, avoiding a
	(sometimes fatal) FMR. [Bugs 618872, 689357]

2003-02-19  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXKeyEvent.c: fix for uninitialized var warning.

2003-02-19  Jim Ingham <[email protected]>

	* macosx/tkMacOSXMouseEvents.c (GeneratePollingEvents): In the case
	where there was a capture window, we were sending the events to the
	capture window. But the capture window (return value or
	TkMacOSXGetCapture) is always a toplevel. So this is wrong in the case
	that the Event's toplevel IS the capture window - in which case the
	event should go to the subwindow most closely containing the event.

2003-02-19  Benjamin Riefenstahl <[email protected]>
	and Jim Ingham <[email protected]>

	This patch changes the default Tk behavior so that events are by
	default routed to the standard event handlers after Tk has looked at
	them.

	* macosx/tkMacOSXEvent.h: Rename "handledByTk" into "stopProcessing".

	* macosx/tkMacOSXEvent.c: Update erroneous comments and remove unused
	includes.
	(TkMacOSXProcessAppleEvent): Don't declare events handled that we did
	not even look at.
	(TkMacOSXProcessEvent): Add a comment on policy for "stopProcessing".
	(TkMacOSXProcessEvent): Remove "handling" of events that are not our
	business.
	(TkMacOSXProcessEvent): Rename "handledByTk" into "stopProcessing".
	(ReceiveAndProcessEvent): Ditto.
	(ReceiveAndProcessEvent): Tune error production of message.

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): Rename
	"handledByTk" into "stopProcessing".

	* macosx/tkMacOSXWindowEvent.c: Ditto.

	* macosx/tkMacOSXMouseEvent.c: Remove setting of "handledByTk".
	(TkMacOSXProcessMouseEvent): Handle clicks in the "traffic lights" in
	the window title when the window (or app) is in the background.

	This patch changes the key event handling to use the MacOS translation
	mechanisms. It also improves dead key handling.

	* macosx/tkMacOSXKeyEvent.c (InitKeyData): Add.
	(InitKeyEvent): Add.
	(DecodeViaUnicodeResource): Rename KeycodeToUnicodeViaUnicodeResource.
	(DecodeViaKCHRResource): Rename KeycodeToUnicodeViaKCHRResource.
	(GetKeyboardLayout): Use a boolean flag instead of a special layout id.
	(KeycodeToUnicodeViaUnicodeResource): Change interface and
	implementation to return a Unicode string instead of directly filling
	an XEvent.
	(KeycodeToUnicodeViaKCHRResource): Ditto.
	(KeycodeToUnicodeViaUnicodeResource): Add handling for callers that
	don't want deadkey processing (i.e. XKeycodeToKeysym).
	(KeycodeToUnicodeViaKCHRResource): Ditto.
	(KeycodeToUnicodeViaUnicodeResource): Clear deadKeyState if a character
	was produced.
	(KeycodeToUnicodeViaKCHRResource): Use CFString and current keyboard
	encoding instead of Tcl Tcl_ExternalToUtf() and fixed
	TkMacOSXCarbonEncoding.
	(TkMacOSXKeycodeToUnicode): Add.

	(TkMacOSXProcessKeyboardEvent): Add some heuristics to improve keyup
	events.
	(deadKeyState): Split into deadKeyStateUp and deadKeyStateDown.
	(GenerateKeyEvent): Change interface and implementation to accept a
	Unicode string instead of individual characters.
	(GenerateKeyEvent): Don't generate string representations for special
	characters.

	* macosx/tkMacOSXEvent.h (TkMacOSXKeycodeToUnicode): Add prototype.

	* macosx/tkMacOSXKeyboard.c (KCHRPtr): Remove.
	(XKeycodeToKeysym): Use TkMacOSXKeycodeToUnicode instead of
	KeyTranslate.
	(XKeycodeToKeysym): Support latin-1 keysyms.

	This patch reverts the hack to put icons in menus that Vince put in
	yesterday (but preserves the bug fix in that submission.)

	* macosx/tkMacOSXMenu.c (SetMenuTitle): revert treating "<bullet>
	number" as a request to put icon number <number> in the menu.

2003-02-18  Mo DeJong  <[email protected]>

	* doc/entry.n:
	* doc/text.n: Update double and triple click docs to match
	implementation changes made on 2002-02-14.

2003-02-19  Daniel Steffen  <[email protected]>

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Makefile: reworked embedded build to no longer require
	relinking but to use install_name_tool instead to change the
	install_names for embedded frameworks. [Bug 644510]

2003-02-19  Donal K. Fellows  <[email protected]>

	* library/demos/widget:		New part for the widget demo showing
	* library/demos/unicodeout.tcl: Tk's UNICODE output. [Patch 627453]

2003-02-18  Andreas Kupries  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl (HP xnet [Bug 651811]).

2003-02-18  Mo DeJong  <[email protected]>

	* unix/configure: Regen.
	* unix/tcl.m4: Update from Tcl.

2003-02-18  Jeff Hobbs	<[email protected]>

	* generic/tkText.c (TextWidgetCmd): remove unused lastEnd var. [Bug
	664790]

	* generic/tkCanvPs.c (TkPostscriptImage): remove unused depth var. [Bug
	664787]

	* generic/tkEntry.c (EntrySetValue): removed unused code var. [Bug
	664781]

	* library/tk.tcl (::tk::TabToWindow): auto-highlight spinboxes as well
	as entries when tabbing in. [Patch 683813] (bron)

	* library/xmfbox.tcl (::tk::MotifFDialog_ActivateSEnt): correct sub on
	embedded newlines. [Patch 688572] (bonfield)

	* doc/colors.n: corrected B values [Bug 682714].

	* win/tkWinInit.c (TkpDisplayWarning): truncate MessageBox string to
	1024 chars to prevent possible oversized window errors. May be
	necessary in other MB uses (ie Tcl_AppInit). [Tcl Bug 608559]

2003-02-18  Vince Darley <[email protected]>

	* macosx/tkMacOSXMenu.c: (SetMenuTitle) fix to utf encoding problem
	when setting menu titles, and provisional support for icons. [Tcl Bug
	625080]

2003-02-18  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c (FileReadGIF): Ensure that the trashBuffer is
	always deallocated on function exit to stop a potential memory leak.

2003-02-17  Mo DeJong  <[email protected]>

	* generic/tkEvent.c (Tk_HandleEvent): Fixup button press state saving
	code, it was incorrectly converting normal motion events into button
	press and motion events in some cases.
	* generic/tkInt.h: Add mouseButtonWindow member to the TkDisplay
	structure.
	* tests/event.test: Add test case for faulty button motion logic.

2003-02-14  Jeff Hobbs	<[email protected]>

	* README:	      Bumped to 8.4.2.
	* generic/tk.h:
	* macosx/Wish.pbproj/project.pbxproj:
	* unix/configure:
	* unix/configure.in:
	* unix/tcl.m4:
	* unix/tk.spec:
	* win/configure:
	* win/configure.in:

	* unix/tcl.m4: correct HP-UX ia64 --enable-64bit build flags

2003-02-13  Kevin Kenny	 <[email protected]>

	* doc/wish.n: Added language to describe the handling of the
	end-of-file character \u001a in script files. [Bug 685505]

2003-02-10  Jim Ingham <[email protected]>

	* macosx/tkMacOSXCursor.c (TkMacOSXInstallCursor): Set all theme
	cursors using SetThemeCursor or SetAnimatedThemeCursors.
	(TkGetCursorByName): Use the theme cursors for arrow, ibeam, etc. Allow
	animatedCursor{NUM} form for an animated cursor with count.
	(TkpSetCursor): Don't reset the cursor if there is no change.
	* macosx/tkMacOSXMouseEvent.c (GeneratePollingEvents): Don't directly
	call TkMacOSXInstallCursor, it gets called by the call to
	Tk_UpdatePointer immediately above.

2003-02-05  Fred Fish  <[email protected]>

	* macosx/tkMacOSXWm.c (Tk_SetGrid): Fix precedence problem with
	* mac/tkMacWm.c (Tk_SetGrid):	    '==' and '|'.

2003-02-08  Jeff Hobbs	<[email protected]>

	* generic/tkCanvArc.c (CreateArc):	 Rework canvas create item type
	* generic/tkCanvBmap.c (CreateBitmap):	 coords handling to be
	* generic/tkCanvImg.c (CreateImage):	 consistent across types and
	* generic/tkCanvPoly.c (CreatePolygon):	 not pass empty coords to item
	* generic/tkCanvLine.c (CreateLine):	 creation procs.
	* generic/tkCanvText.c (CreateText):
	* generic/tkCanvWind.c (CreateWinItem):
	* generic/tkCanvas.c (CanvasWidgetCmd CANV_CREATE):
	* generic/tkRectOval.c (CreateRectOval):
	* tests/canvRect.test:
	* tests/canvText.test:
	* tests/canvas.test:

2003-01-28  Joe English	 <[email protected]>

	* generic/tkInt.h (TkDisplay,TkMainInfo):
	* generic/tkObj.c (windowObjType):
	* generic/tkWindow.c (Tk_DestroyWindow):
	* tests/wm.test (wm-deletion-epoch-1.1): Moved 'deletionEpoch' field
	from TkDisplay to TkMainInfo. Reworked windowObj type. Fixes [Bug
	671330] "segfault when e.g. deiconifying destroyed window"

2003-01-23  D. Richard Hipp  <[email protected]>

	* library/entry.tcl: Fix the KeyPress binding on the entry widget so
	that it enters text from left to right (not right to left) even if the
	mouse button is being held down. [Bug 673687]

2003-01-22  Donal K. Fellows  <[email protected]>

	* generic/tkFrame.c (TkToplevelWindowForCommand): Added way of mapping
	from command names to tkwins-for-toplevels.
	* generic/tkImage.c (Tk_ImageObjCmd): Added check to make sure that
	you're not creating an image named the same as .'s command, which
	refixes 220891, even when the name of the command has been changed with
	'rename'. The error message is better too.
	* tests/image.test (image-1.10,image-1.11): Updated to match new error
	message and added test for the rename case.

2003-01-19  Jeff Hobbs	<[email protected]>

	* generic/tkImage.c (DeleteImage): delete the image's entry in the
	image table correctly when there are no more instances. This reopens
	bug 220891. [Bug 669759]

2003-01-18  Jeff Hobbs	<[email protected]>

	* doc/loadTk.n: note that ::safe::loadTk has a prereq on
	::safe::interpCreate or ::safe::interpInit. [Bug 669159]

	* doc/photo.n: $image put only accepts -format and -to, and note
	extended use of -to.

2003-01-17  D. Richard Hipp <[email protected]>

	* generic/tkCanvUtil.c: The clipping algorithm introduced on 2003-01-08
	was unnecessarily aggressive in reducing the size of the clipping box.
	This did not cause a problem for normal display, but did create trouble
	for some extensions that attempt to render a canvas on a GDI printer
	under Windows. The patch here relaxes the constraints on the clipping
	box somewhat. [Bug 663981]

2003-01-14  Joe English	 <[email protected]>

	* generic/tkSelect.c (Tk_CreateSelHandler): Fix for [Bug 666346]
	"Selection handling crashes under KDE 3.0"
	* tests/unixSelect.test (unixSelect-1.20): Added test case.

2003-01-13  Mo DeJong  <[email protected]>

	* win/tkWinDialog.c (Tk_ChooseDirectoryObjCmd)
	(ChooseDirectoryValidateProc, Tk_MessageBoxObjCmd): Remove unused
	tsdPtr variable. Use TEXT macro instead of _T macro since _T does not
	work under Cygwin. Declare flags as UINT to avoid compiler warning when
	compiling with mingw.

2003-01-12  Mo DeJong  <[email protected]>

	* win/Makefile.in: Add TCL_DEFS to AC_FLAGS so that compiler flags
	defined by Tcl get passed to the compiler. Add empty rule for cat.c so
	that Tk compiles under msys.
	* win/configure: Regen.
	* win/tcl.m4: Update from Tcl, this pulls in a subst of TCL_DEFS, it
	also defines USE_THREAD_ALLOC when threads are used and it updates the
	SC_ENABLE_SYMBOLS and SC_PROG_TCLSH macros to match the ones used in
	Tcl.

2003-01-10  Joe English	 <[email protected]>

	* unix/tkUnixEvent.c (OpenIM): Remove unused variable (Fixes: [Bug
	664780] "SGI warning: OpenIM")

2003-01-08  D. Richard Hipp <[email protected]>

	* generic/tkCanvLine.c:
	* generic/tkCanvas.h:
	* generic/tkCanvUtil.c: Clip long lines so that they will display
	properly even on windowing systems where coordinates are expressed as
	16-bit numbers. [Bug 663981]

2003-01-03  Jeff Hobbs	<[email protected]>

	* generic/tkFrame.c (CreateFrame): throw a Tcl error instead of a panic
	when we cannot get a main window and appname is NULL. This can indicate
	that a user tried to create a frame/toplevel while Tk was dying. [Bug
	661792]

	******************************************************************
	*** CHANGELOG ENTRIES FOR 2002 AND EARLIER IN "ChangeLog.2002" ***
	******************************************************************

Added ChangeLog.2007.




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
2007-12-30  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: Documented exact behaviour of items with respect to
	when they are the current item. [Bug 1774593] Also documented the
	clipping behaviour of window items.

	* library/demos/nl.msg: Corrected following testing "in the field" by
	Arjen Markus. [Bug 1860802]

2007-12-17  Donal K. Fellows  <[email protected]>

	*** 8.5.0 TAGGED FOR RELEASE ***

	* doc/canvas.n: Documented -outlineoffset item option. [Bug 1836621]

2007-12-14  Don Porter  <[email protected]>

	* changes:	More updates for 8.5.0 release.

2007-12-14  Joe English  <[email protected]>

	* doc/ttk_treeview.n: Fix typo. [Bug 1850713]

2007-12-14  Pat Thoyts  <[email protected]>

	* win/tkWinInt.h:    Add in missing function definitions
	* win/tkWinButton.c:  to support plain MSVC6 and use INT_PTR
	* win/tkWinScrlBar.c: rather than LONG_PTR which isn'tr defined
	* win/tkWinWm.c:     in the msvc6 headers.

2007-12-14  Pat Thoyts <[email protected]>

	* win/nmakehlp.c:  Support compilation with MSVC9 for AMD64.
	* win/makefile.vc:

2007-12-13  Jeff Hobbs  <[email protected]>

	* generic/tkMenubutton.c (ConfigureMenuButton): trace the
	-textvariable even if an image exists as it may use -compound.

2007-12-12  Jeff Hobbs  <[email protected]>

	* generic/tkText.c (DeleteIndexRange, TextEditCmd, UpdateDirtyFlag):
	* tests/text.test (text-25.10.1,25.11.[12]):
	Don't require [update idle] to trigger Modified event [Bug 1809538]
	Modified virtual event should only fire on state change [Bug 1799782]
	Make sure we delete chars before triggering <<Modified>> [Bug 1737288]

2007-12-12  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Revert 2007-10-26
	change to window class of transient toplevels that are not also
	overrideredirect. [Bug 1845899]

	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Implement more
	* macosx/tkMacOSXMouseEvent.c (BringWindowForward): X11-like transient
	* macosx/tkMacOSXSubwindows.c (XDestroyWindow):  behaviour by
	adding transient windows to a window group owned by the master window,
	this ensures transients always remain in front of and are collapsed
	with the master; bring master to front when selecting transient
	windows; restore default window group of transients if master
	destroyed. [Bug 1845899]

2007-12-12  Joe English  <[email protected]>

	* doc/ttk_intro.n, doc/ttk_style.n, doc/ttk_widget.n:
	Various minor updates.

2007-12-12  Don Porter  <[email protected]>

	* changes:		Updated for 8.5.0 release.

2007-12-11  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.c (StyleElementOptionsCmd): Use
	Ttk_GetElement() to find element instead of direct hash table access.

2007-12-11  Donal K. Fellows  <[email protected]>

	* generic/tkText.c (TextReplaceCmd): Added code to rebuild the from
	index after the deletion phase so that the linePtr field is valid for
	the insertion phase. [Bug 1602537]

2007-12-10  Donal K. Fellows  <[email protected]>

	* doc/event.n: Clarify the fact that [event info] only returns the
	names of virtual events that are bound to physical event sequences.
	This follows on from comments on comp.lang.tcl.
	http://groups.google.com/group/comp.lang.tcl/msg/935d2d226ae8a770

2007-12-10  Joe English  <[email protected]>

	* doc/AddOption.3, doc/CrtImgType.3, doc/CrtPhImgFmt.3,
	* doc/InternAtom.3, doc/TextLayout.3, doc/chooseColor.n,
	* doc/chooseDirectory.n, doc/loadTk.n, doc/palette.n,
	* doc/ttk_combobox.n: Various markup fixes (mostly: missing quotes on
	.SH arguments, extraneous .PPs)

	* doc/ttk_entry.n, doc/ttk_scrollbar.n, doc/ttk_treeview.n: Remove
	extra .BEs that got added by mistake somewhere.

2007-12-10  Daniel Steffen  <[email protected]>

	* generic/tk.decls:		use new genstubs 'export' command to
	* generic/tkInt.decls:		mark exported symbols not in stubs
					table [FR 1716117]; cleanup formatting

	* generic/tkIntDecls.h:		regen with new genStubs.tcl.
	* generic/tkIntPlatDecls.h:	[Tcl Bug 1834288]
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c:

2007-12-10  Donal K. Fellows  <[email protected]>

	* tests/safe.test: Ensure list of hidden commands is correct. [Bug
	1847925]

2007-12-10  Pat Thoyts  <[email protected]>

	* win/tkWin.h: We must specify the lowest Windows version we intend to
	support. In particular the SystemParametersInfo API doesn't like to
	receive structures that are larger than it expects which affects the
	font assignements. Set to Win98 support.

	* win/tkWinFont.c: Handle failure to read the system parameters. This
	causes ttk/fonts.tcl to set any missing named fonts.

	* win/ttkWinMonitor.c:  Only tkWin.h should include windows.h unless
	* win/ttkWinTheme.c:    we have an explicit override of the WINVER
	* tin/ttkWinXPTheme.c:  macro.

	* win/rules.vc: Handle MSVC 9 (aka: Visual Studio 2008)

	* tests/safe.test: Update for 'unload' as a safe command (tcl 8.5b3+)

2007-12-09  Donal K. Fellows  <[email protected]>

	* win/configure.in: Adjusted code so that running configure does not
	generate an error message when the full current directory name
	contains a space.

	* win/tkWinWm.c: Added set of #defs to make this file build with my
	version of the SDK (i.e. with the msys suite we distribute).

2007-12-07  Joe English  <[email protected]>

	* library/ttk/altTheme.tcl, library/ttk/classicTheme.tcl:
	s/style/ttk::style/.

2007-12-07  Don Porter  <[email protected]>

	* unix/README:  Mention the stub library created by `make` and warn
	about the effect of embedded paths in the installed binaries. Thanks
	to Larry Virden. [Tcl Bug 1794084]

2007-12-05  Joe English  <[email protected]>

	* macosx/ttkMacOSXTheme.c: Fix TCombobox layout so as not to truncate
	long text when combobox is wider than requested. [Bug 1845164]

2007-12-05  Jeff Hobbs  <[email protected]>

	* library/demos/widget: reduce start size to 70% of screenheight from
	sh-200 for a more reasonable size.

	* win/tkWinButton.c, win/tkWinDialog.c: use SetWindowLongPtr and
	* win/tkWinScrlbr.c, win/tkWinWm.c:  GetWindowLongPtr only.
	* win/ttkWinMonitor.c:

	* win/tkWinInt.h: remove CS_CLASSDC (not recommended for any apps now)
	* win/tkWinX.c:   and simplify WNDCLASS to one style.
	* win/tkWinWm.c:  Reduce wrapper update for exStyle to toolwindow
	change only and set WS_EX_LAYERED as sticky (once set on a window, do
	not remove it) to reduce alpha transition flicker.

	* win/configure, win/tcl.m4 (LIBS_GUI): mingw needs -lole32 -loleaut32
	but not msvc for Tk's [send]. [Bug 1844749]

2007-12-04  Joe English  <[email protected]>

	* doc/ttk_style.n: Remove nonsense about "this manpage has not yet
	been written"; everything supported is documented.

2007-12-04  Donal K. Fellows  <[email protected]>

	* library/msgs/en.msg: Added missing messages. [Patch 1800744]

	* library/msgs/da.msg: Added Danish messages. [Patch 1844143]. Many
	thanks to Torsten Berg <[email protected]>.

2007-12-03  Jeff Hobbs  <[email protected]>

	* win/configure, win/tcl.m4 (LIBS_GUI): remove ole32.lib oleaut32.lib
	(LIBS): add ws2_32.lib for static builds with Tcl.

2007-12-01  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.h, generic/ttk/ttkThemeInt.h,
	* generic/ttk/ttkTheme.c, generic/ttk/ttkLayout.c,
	* generic/ttk/ttkClamTheme.c, generic/ttk/ttkClassicTheme.c,
	* generic/ttk/ttkTreeview.c, macosx/ttkMacOSXTheme.c,
	* win/ttkWinTheme.c, win/ttkWinXPTheme.c: Improved macrology for
	statically-initialized layout template tables.

2007-11-28  Don Porter  <[email protected]>

	* unix/tkUnixPort.h:	When unix/configure determines whether the
	intptr_t type is available, it has the <inttypes.h> header present.
	It's only fair that we let Tk have it too.

2007-11-26  Kevin Kenny  <[email protected]>

	* generic/tkImgPPM.c (StringReadPPM): Corrected a comparison whose
	sense was reversed that resulted in reading beyond the end of the
	input buffer on malformed PPM data. [Bug 1822391]
	* library/tkfbox.tcl (VerifyFileName): Corrected a couple of typos in
	handling of bad file names. [Bug 1822076] Thanks to Christoph Bauer
	([email protected]) for the patch.
	* tests/filebox.test (filebox-7.1, filebox-7.2): Added test cases that
	exercise. [Bug 1822076]
	* tests/imgPPM.test (imgPPM-4.1): Added test case that exercises. [Bug
	1822391]

2007-11-25  Joe English  <[email protected]>

	* generic/ttk/ttkManager.h, generic/ttk/ttkManager.c,
	* generic/ttk/ttkFrame.c, generic/ttk/ttkNotebook.c,
	* generic/ttk/ttkPanedwindow.c:  Internal Ttk_Manager API updates;
	Fixed [Bug 1343984]; Added [$nb hide] method; [$nb add] on
	already-managed windows no longer throws an error, can be used to
	re-add a hidden tab.

	* doc/ttk_notebook.n, tests/ttk/notebook.test,
	* tests/ttk/panedwindow.test:  Updated docs and test suite.

2007-11-23  Donal K. Fellows  <[email protected]>

	* unix/README: General improvements.

2007-11-21  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl: Better theming in the file list area.

2007-11-19  Don Porter  <[email protected]>

	*** 8.5b3 TAGGED FOR RELEASE ***

	* README:		Bump version number to 8.5b3.
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

	* changes:		Update changes for 8.5b3 release.

2007-11-19  Pat Thoyts  <[email protected]>

	* generic/ttk/ttkTheme.c:	Fix crash when 'style element create'
	* tests/ttk/ttk.test:		called w/ insufficient args; add tests.

2007-11-18  Joe English  <[email protected]>

	* generic/ttk/ttkElements.c, macosx/ttkMacOSXTheme.c: Add "fill"
	element: like "background" but only erases parcel.

	* generic/ttk/ttkFrame.c: Use fill element in Labelframe Label
	sublayout. Also improved default labelmargins for -labelanchor w*, e*.

	* generic/ttk/ttkLabel.c: no longer need Labelframe hack.

	* library/ttk/aquaTheme.tcl: ImageTextElement no longer needed.
	TextElement no longer needs '-background' option.

	* generic/ttk/ttkFrame.c: Use sublayout for ttk::labelframe labels
	instead of single element.

	* generic/ttk/ttkLabel.c: Default -anchor for text and label elements
	is now "w" instead of "center". [Bug 1614540]

	* library/ttk/defaults.tcl, library/ttk/*Theme.tcl: Button styles now
	need explicit "-anchor center".

	* generic/ttk/ttkLayout.c (TTKInitPadding): BUGFIX:
	Ttk_GetPaddingFromObj() and Ttk_GetBorderFromObj() returned garbage
	when passed an empty list.

	* macosx/ttkMacOSXTheme.c: Resynchronize with Tile codebase so that
	patches can flow back and forth.

	* library/ttk/aquaTheme.tcl: Extra TButton -padding no longer needed.

2007-11-18  Pat Thoyts  <[email protected]>

	* win/ttkWinXPTheme.c: Add support for size information flags for
	scrollbar and combobox buttons. This handles Tile [Patches 1596647 and
	1596657] but a bit more generically.

2007-11-17  Pat Thoyts  <[email protected]>

	* generic/(tkArgv.c, tkBind.c, tkCipboard.c, tkEntry.c, tkOption.c,
	tkScale.c, tkScrollbar.c, tkTextImage.c, tkVisual.c, tkWindow.c): Tidy
	up some variable types.

	* generic/tkFont.c:	Only check for -displayof if there are
	* test/font.test:	sufficient arguments. This permits checking
				strings like -d.

2007-11-17  Joe English  <[email protected]>

	* library/ttk/scrollbar.tcl: Swap in core scrollbars for
	[ttk::scrollbar]s on OSX.

2007-11-16  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXFont.c (TkpMeasureCharsInContext): Correct an
	oversight in the bug fix from 2007-11-11. [Bug 1824638]

2007-11-15  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: add new chanio.test.
	* macosx/Wish.xcode/project.pbxproj:

2007-11-14  Donal K. Fellows  <[email protected]>

	* library/msgs/sv.msg: Get the locale declared within the message
	catalog correct! [Bug 1831803]

2007-11-11  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXFont.c (TkpMeasureCharsInContext): Fix the case when
	TK_WHOLE_WORDS and TK_AT_LEAST_ONE are both set and maxLength is small.
	[Bug 1824638]

2007-11-09  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXCarbonEvents.c
	(InstallStandardApplicationEventHandler): on Mac OS X Leopard, replace
	the 2005-11-27 approach of installing the standard application handler
	by calling RAEL and immediately longjmping out of it from an event
	handler, as that now leads to crashes in -[NSView unlockFocus] whenever
	HIToolbox uses Cocoa in Leopard (Help menu, Nav Services, Color
	Picker). Instead call InstallStandardEventHandler() on the application
	and menubar event targets, as Leopard ISEH finally handles these
	correctly. Unfortunately need a HIToolbox-internal SPI to retrieve the
	menubar event target, no public API appears have that functionality.

	* macosx/tkMacOSXDebug.c:	make TkMacOSXInitNamedDebugSymbol()
	* macosx/tkMacOSXDebug.h:	available outside of debug builds as
					the new Leopard ISAEH needs it.

	* macosx/tkMacOSXButton.c:	replace HiliteControl() by modern API
	* macosx/tkMacOSXMenubutton.c:	for activation and enabling;
					distinguish inactive and disabled
					look&feel; correct activation handling
					to match that of container toplevel.

	* macosx/tkMacOSXMenubutton.c:	correct size computation of bevelbutton
					variant to match that of buttons;
					fix crash with bitmap due to NULL GC;
					delay picParams setup until needed;
					formatting cleanup. [Bug 1824521]

	* library/menu.tcl:		correct handling of menubutton "active"
					state on Aqua to match that of buttons.

	* macosx/tkMacOSXDefault.h:	correct button & menubutton active
					foreground and background colors and
					menubutton border width.

	* macosx/tkMacOSXWindowEvent.c:	handle kEventWindowExpanding carbon
	* macosx/tkMacOSXCarbonEvents.c: event instead of kEventWindowExpanded
					to ensure activate event arrives after
					window is remapped, also need to
					process all Tk events generated by
					remapping in the event handler to
					ensure children are remapped before
					activate event is processed.

	* macosx/tkMacOSXSubwindows.c:	add pixmap size field to MacDrawable
	* macosx/tkMacOSXInt.h:		struct; add flag for B&W pixmaps.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXPrivate.h:	correct Leopard HIToolboxVersionNumber.

	* macosx/ttkMacOSXTheme.c:	add error checking; cleanup formatting.

	* macosx/tkMacOSXFont.c (TkpGetFontAttrsForChar): panic on false return
					from TkMacOSXSetupDrawingContext().

	* macosx/tkMacOSXButton.c:	sync formatting, whitespace, copyright
	* macosx/tkMacOSXDialog.c:	with core-8-4-branch.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXWm.c:
	* xlib/xgc.c
	* library/bgerror.tcl:
	* library/console.tcl:
	* library/menu.tcl:

2007-11-07  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.c (Ttk_ElementSize): Fixed longstanding, subtle
	bug that caused element padding to sometimes be counted twice in size
	computations.

	* generic/ttk/ttkElements.c, generic/ttk/ttkClamTheme.c,
	* generic/ttk/ttkDefaultTheme.c, generic/ttk/ttkTreeview.c,
	* generic/ttk/ttkImage.c, macosx/ttkMacOSXTheme.c,
	* win/ttkWinTheme.c, win/ttkWinXPTheme.c:
	Fix ElementSizeProcs affected by previous change.

2007-11-06  Andreas Kupries  <[email protected]>

	* doc/CrtConsoleChan.3: Fixed markup typo and extended see also
	section per suggestions by Donal.

2007-11-05  Joe English  <[email protected]>

	* library/ttk/combobox.tcl: Set focus to listbox in <Map> binding
	instead of in Post command (see [Bug 1349811] for info).

2007-11-05  Andreas Kupries  <[email protected]>

	* doc/CrtConsoleChan.3: New file providing minimal documentation of
	'Tk_InitConsoleChannels()'. [Bug 432435]

2007-11-05  Joe English  <[email protected]>

	* macosx/ttkMacOSXTheme.c (TreeitemLayout): Remove focus ring
	from treeview items on OSX (problem reported by Kevin Walzer).

2007-11-04  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c: Use null "treearea" element for treeview
	owner-draw area instead of "client", to avoid nameclash with
	Notebook.client element (this was causing sizing anomalies in XP
	theme, and introduced extraneous padding).
	* generic/ttk/ttkDefaultTheme.c: Treeitem.indicator element needs left
	margin now.

2007-11-04  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXMenus.c: add "Run Widget Demo" menu item to the
	default Edit menu along with associated carbon event handler enabling
	the item only if demo files are installed; cleanup handling of "About"
	and "Source" menu items.

	* library/bgerror.tcl:		fix background of detail text on Aqua.

	* library/console.tcl:		add accelerators and fix Aqua bindings
					of the new font size menu items.

	* library/demos/mclist.tcl:	Aqua GOOBE.
	* library/demos/tree.tcl:
	* library/demos/ttknote.tcl:
	* library/demos/widget:

	* doc/chooseDirectory.n:	remove/correct obsolete Mac OS 9-era
	* doc/getOpenFile.n:		information.
	* doc/menu.n:

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent): fix boolean
	arg

	* macosx/Wish.xcodeproj/project.pbxproj: add new demo file.
	* macosx/Wish.xcode/project.pbxproj:

2007-11-03  Pat Thoyts  <[email protected]>

	* library/console.tcl: Add menu item and key binding to adjust font.

2007-11-02  Donal K. Fellows  <[email protected]>

	* library/demos/mclist.tcl: Added a demo of how to do a multi-column
	sortable listbox.

	* library/msgbox.tcl: Made message dialog use Ttk widgets for better
	L&F.

	* library/tkfbox.tcl (::tk::dialog::file::CompleteEnt): Added <Tab>
	completion. [FR 805091]
	* library/tkfbox.tcl: Made file dialog use Ttk widgets for better L&F.

	* library/demos/sayings.tcl: Better resizing. [Bug 1822410]

2007-11-01  Donal K. Fellows  <[email protected]>

	* library/demos/textpeer.tcl: Better resizing. [Bug 1822601]

	* doc/colors.n: Added list of Windows system colors. [Bug 945409]

2007-11-01  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXColor.c (GetThemeColor): improve translation of RGB
				pixel values into RGBColor.

	* library/demos/widget:	increase height of main window text widget to
				use more of the available vertical space.

	* doc/bind.n:		document the Option modifier, clarify meaning
				and availability of Command & Option.

	* doc/console.n:	clarify availability of [console] in TkAqua.

2007-11-01  Donal K. Fellows  <[email protected]>

	* unix/installManPage, doc/*.n: Make documentation use the name that
	scripts use as much as possible. [Bug 1640073]

	* doc/text.n: Fixed mistake in [$t tag remove] docs. [Bug 1792191]

	* doc/bind.n: Documented the Command modifier. [Bug 1232908]

	* doc/console.n, doc/wish.1: Made it clearer when and why the console
	command is present. [Bug 1386955]

2007-10-31  Donal K. Fellows  <[email protected]>

	* library/demos/entry3.tcl: Improved description/comments so that
	people better understand what is being validated, following suggestion
	from Don Porter.

	* library/demos/image2.tcl (loadImage): Mark non-loadable images as
	such instead of throwing a nasty dialog, following suggestion from Don
	Porter.

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock): More optimization, derived
	from [Patch 224066].

2007-10-30  Joe English  <[email protected]>

	* library/ttk/combobox.tcl (Unpost): BUGFIX: Unpost can be called with
	no preceding Post.

2007-10-31  Pat Thoyts  <[email protected]>

	* win/rules.vc:  Use -fp:strict with msvc8 as -fp:precise fails on
	* generic/tkObj.c:  amd64 builds. Fix the two places in Tk that
	* generic/tkTrig.c: generate errors with msvc8 when using this flag.

2007-10-30  Jeff Hobbs  <[email protected]>

	* library/choosedir.tcl: only enable OK button when valid in
	conjunction with -mustexist. [Bug 1550528]

	* library/listbox.tcl (::tk::ListboxBeginSelect): ignore -takefocus
	when considering focus on <1>, it is for tab focus.

2007-10-30  Don Porter  <[email protected]>

	* generic/tk.h:		Bump version number to 8.5b2.1 to distinguish
	* library/tk.tcl:	CVS development snapshots from the 8.5b2
	* unix/configure.in:	release.
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf (2.59)
	* win/configure:

2007-10-30  Jeff Hobbs  <[email protected]>

	* doc/text.n: fix spelling of -inactiveselectbackground [Bug 1626415]

	* library/entry.tcl: don't error with Clear event. [Bug 1509288]

	* library/ttk/fonts.tcl: use size -12 TkFixedFont (was -10) on X11

2007-10-30  Donal K. Fellows  <[email protected]>

	* library/demos/unicodeout.tcl: Fixed Arabic and Hebrew rendering on
	Windows. [Bug 1803723]

	* generic/tkImgPhoto.c (ImgPhotoCmd): Rename enumeration for somewhat
	simpler-to-read code. [Bug 1677613]

2007-10-30  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c: Split up RedisplayWidget() to factor out
	double-buffering related code.

	* macosx/ttkMacOSXAquaTheme.c: Use SetThemeBackGround/
	kThemeBrushModelessDialogBackground{Active|Inactive} instead of
	ApplyThemeBackground/kThemeBackgroundWindowHeader (advice from DAS).

	* library/ttk/aquaTheme.tcl: Use darker shade for inactive and
	disabled text, to match typical values of most
	kThemeXXXTextColorInactive values.

2007-10-30  Donal K. Fellows  <[email protected]>

	* doc/selection.n: Clarify UTF8_STRING handling. [Bug 1778563]

	* doc/text.n: Clarify search subccommand docs. [Bug 1622919]

2007-10-29  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXFont.c (InitSystemFonts):
	* library/ttk/fonts.tcl: use Monaco 11 (was 9) as Aqua TkFixedFont

	* tests/listbox.test, tests/panedwindow.test, tests/scrollbar.test:
	* library/bgerror.tcl, library/dialog.tcl, library/listbox.tcl:
	* library/msgbox.tcl, library/optMenu.tcl, library/tclIndex:
	* library/tkfbox.tcl, library/demos/floor.tcl, library/demos/rmt:
	* library/demos/tcolor, library/demos/text.tcl:
	* library/demos/twind.tcl, library/demos/widget: Buh-bye Motif look
	* library/ttk/fonts.tcl:    Update of Tk default look in 8.5
	* macosx/tkMacOSXDefault.h: Trims border sizes, cleaner X11 look
	* unix/tkUnixDefault.h:  with minor modifications for Win32/Aqua.
	* win/tkWinDefault.h:    Uses Tk*Font definitions throughout for
	* win/tkWinFont.c:     classic widgets. [Bug 1820344]
	* library/obsolete.tcl (::tk::classic::restore): This restores
	changes made to defaults in 8.5 using the 'option' command,
	segmented into logical groups.

	* tests/winfo.test: winfo-4.5 raise .t to above . for Windows

	* tests/unixWm.test: note TIP#142 results and remove unnecessary
	catches.

2007-10-29  Donal K. Fellows  <[email protected]>

	* doc/*.1, doc/*.n, doc/*.3: Lots more GOOBE work.

2007-10-28  Joe English  <[email protected]>

	* library/ttk/combobox.tcl: Make popdown window [wm resizable 0 0] on
	OSX, to prevent TkAqua from shrinking the scrollbar to make room for a
	grow box that isn't there.
	* macosx/ttkMacOSXTheme.c, library/ttk/aquaTheme.tcl: Reworked
	combobox layout.

2007-10-26  Don Porter  <[email protected]>

	*** 8.5b2 TAGGED FOR RELEASE ***

	* changes:		Update changes for 8.5b2 release.

	* doc/*.1:      Revert doc changes that broke
	* doc/*.3:      `make html` so we can get the release
	* doc/*.n:      out the door.

	* README:		Bump version number to 8.5b2.
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2007-10-26  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): fix window class
	of transient toplevels that are not also overrideredirect. [Bug
	1816252]

	* macosx/tkMacOSXDialog.c:	TIP#242 cleanup.
	* library/demos/filebox.tcl: 	demo TIP#242 -typevariable.

2007-10-25  Joe English  <[email protected]>

	* generic/ttk/ttkNotebook.c: [Bug 1817596]

2007-10-25  Jeff Hobbs  <[email protected]>

	* doc/getOpenFile.n:	TIP#242 implementation of -typevariable to
	* library/tkfbox.tcl:	return type of selected file in file dialogs.
	* library/xmfbox.tcl:	[Bug 1156388]
	* macosx/tkMacOSXDialog.c:
	* tests/filebox.test:
	* tests/winDialog.test:
	* win/tkWinDialog.c:

2007-10-25  Don Porter  <[email protected]>

	* generic/tkPlace.c:	Prevent segfault in place geometry manager.
	Thanks to Colin McDonald. [Bug 1818491]

2007-10-24  Joe English  <[email protected]>

	* generic/ttk/*.c, win/{ttkWinMonitor,ttkWinTheme,ttkWinXPTheme}.c,
	* macosx/ttkMacOSXTheme.c: Move widget layout registration from
	TtkElements_Init() to widget *_Init() routines. Renaming/consistency:
	s/...ElementGeometry()/...ElementSize()/

2007-10-24  Donal K. Fellows  <[email protected]>

	* doc/*.n, doc/*.3, doc/*.1: Lots of changes to take advantage of the
	new macros.

2007-10-24  Pat Thoyts  <[email protected]>

	* win/tkWinDraw.c: Applied [Patch 1723362] for transparent bitmaps.

	* generic/tkWindow.c: permit wm manage of any widget (esp: ttk::frame)

2007-10-23  Jeff Hobbs  <[email protected]>

	* library/ttk/combobox.tcl (ttk::combobox::PopdownWindow): redo wm
	transient on each drop to handle reparent-able frames. [Bug 1818441]

2007-10-23  Joe English  <[email protected]>

	* library/ttk/combobox.tcl: [namespace import ::ttk::scrollbar]
	doesn't work, since ttk::scrollbar isn't [namespace export]ed.

2007-10-23  Don Porter  <[email protected]>

	* tests/cursor.test:	Make tests robust against changes in Tcl's
	rules for accepting integers in octal format.

2007-10-23  Donal K. Fellows  <[email protected]>

	* doc/font.n: Added section on the TIP#145 fonts.

2007-10-23  Pat Thoyts  <[email protected]>

	* win/tkWinFont.c: Fixed leak in CreateNamedFont spotted by das.

2007-10-23  Daniel Steffen  <[email protected]>

	* library/demos/combo.tcl:	Aqua GOOBE.
	* library/demos/toolbar.tcl:
	* library/demos/tree.tcl:
	* library/demos/ttknote.tcl:
	* library/demos/ttkprogress.tcl:
	* library/demos/widget:

	* macosx/Wish.xcodeproj/project.pbxproj: add new demo files.
	* macosx/Wish.xcode/project.pbxproj:

2007-10-22  Donal K. Fellows  <[email protected]>

	* library/demos/widget: Added more demos, reorganized to make Tk and
	Ttk demos seem to be more coherent whole. Made localization a bit
	easier by reducing the amount of duplication.
	* library/demos/{combo,toolbar,tree,ttknote,ttkprogress}.tcl: New
	demos of new (mostly) Ttk widgets.
	* library/demos/ttkbut.tcl: Improvements.

2007-10-22  Joe English  <[email protected]>

	* library/ttk/combobox.tcl:	ttk::combobox overhaul; fixes [Bugs
					1814778, 1780286, 1609168, 1349586]
	* library/ttk/aquaTheme.tcl:	Factored out aqua-specific combobox
					-postposition adjustments.
	* generic/ttk/ttkTrack.c:	Detect [grab]s and unpress pressed
					element; combobox workaround no longer
					needed.

2007-10-22  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXFont.c: 	register named fonts for TIP #145 fonts
					and all theme font IDs.

	* generic/tkFont.c (Tk{Create,Delete}NamedFont): allow NULL interp.

	* library/ttk/fonts.tcl:	check for TIP #145 fonts on all
					platforms; correct aqua font sizes.

	* library/demos/ttkmenu.tcl:	Aqua GOOBE.
	* library/demos/ttkpane.tcl:
	* library/demos/widget:

	* macosx/Wish.xcodeproj/project.pbxproj: add new demo files.
	* macosx/Wish.xcode/project.pbxproj:

2007-10-18  Donal K. Fellows  <[email protected]>

	* library/demos/ttkmenu.tcl: Added more demos of Ttk widgets. These
	* library/demos/ttkpane.tcl: ones are of menubuttons, panedwindows and
	a progress bar (indirectly).

2007-10-18  Pat Thoyts  <[email protected]>

	* library/ttk/fonts.tcl: Create all the TIP #145 font names on all
	platforms (mac and unix get handled in script, windows in C)

2007-10-17  David Gravereaux <[email protected]>

	* bitmaps/*.xbm: Changed CVS storage mode from -kb to -kkv as these
	are really text files, not binaries.
	* win/makefile.vc: Added $(BITMAPDIR) to the search path for the
	depend target.

2007-10-18  Daniel Steffen  <[email protected]>

	* library/demos/widget:		Aqua GOOBE, cleanup icons.
	* library/demos/ttkbut.tcl:
	* library/demos/entry3.tcl:
	* library/demos/msgbox.tcl:

	* library/demos/button.tcl:	restore setting of button
					highlightbackground on Aqua.

	* macosx/ttkMacOSXTheme.c: 	adjust button and separator geometry.

	* macosx/tkMacOSXWm.c:		fix warnings.

	* macosx/Wish.xcodeproj/project.pbxproj: add new demo files.
	* macosx/Wish.xcode/project.pbxproj:

2007-10-17  Donal K. Fellows  <[email protected]>

	* library/demos/ttkbut.tcl: Added demo of the basic Ttk widgets.

2007-10-16  David Gravereaux <[email protected]>

	* win/makefile.vc: depend target now works and builds a generated
	dependency list with $(TCLTOOLSDIR)/mkdepend.tcl

2007-10-16  Donal K. Fellows  <[email protected]>

	* library/demos/widget: Made the code for generating the contents of
	the main widget more informative. Added 'new' flagging for wholly new
	demos.

	* doc/text.n: Made it clearer what things are text widget invokations
	and what are not. Also some other clarity improvements.

2007-10-15  Donal K. Fellows  <[email protected]>

	* library/demos/widget: Use Ttk widgets for the widget demo core, for
	vastly improved look-and-feel on at least one platform (Windows).
	* library/demos/{button,check,style,twind}.tcl: Various tweaks for
	GOOBE...
	* library/demos/textpeer.tcl: New demo script to show off peering as a
	specific feature.

2007-10-15  Jeff Hobbs  <[email protected]>

	* generic/tkFocus.c, generic/tkFrame.c, generic/tkInt.h:
	* macosx/tkMacOSXButton.c, macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c, unix/tkUnixWm.c, win/tkWinWm.c:
	* doc/wm.n, tests/wm.test: TIP #125 implementation. [Bug 998125]
	Adds [wm manage|forget] for dockable frames.
	Finished X11 and Windows code, needs OS X completion.

2007-10-15  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c: Store pointer to column table entry
	instead of column index in columnNames hash table. This avoids the
	need for the evil PTR2INT and INT2PTR macros, and simplifies things a
	bit.

2007-10-15  Daniel Steffen  <[email protected]>

	* generic/tkArgv.c:		Fix gcc warnings about 'cast to/from
	* generic/tkCanvUtil.c:		pointer from/to integer of different
	* generic/tkCanvas.c:		size' on 64-bit platforms by casting
	* generic/tkCursor.c:		to intermediate types
	* generic/tkInt.h:		intptr_t/uintptr_t via new PTR2INT(),
	* generic/tkListbox.c:		INT2PTR(), PTR2UINT() and UINT2PTR()
	* generic/tkObj.c:		macros.
	* generic/tkStyle.c:
	* generic/tkTextIndex.c:
	* generic/tkUtil.c:
	* generic/ttk/ttkTheme.h:
	* generic/ttk/ttkTreeview.c:
	* unix/tkUnixMenu.c:
	* unix/configure.in:

	* unix/configure:		autoconf-2.59
	* unix/tkConfig.h.in:		autoheader-2.59

	* macosx/Wish-Common.xcconfig:		add 'tktest-X11' target.
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/Wish.xcodeproj/default.pbxuser:
	* macosx/Wish.xcodeproj/project.pbxproj:

	* unix/configure.in (Darwin):	add support for 64-bit X11.
	* unix/configure:		autoconf-2.59

2007-10-14  Jeff Hobbs  <[email protected]>

	* win/configure, win/configure.in (TK_WIN_VERSION): Make sure the
	patchlevel doesn't contain extra dotted pairs (eg. interim release)

2007-10-12  Pat Thoyts  <[email protected]>

	* win/makefile.vc:  Mine all version information from headers.
	* win/rules.vc:  Sync tcl and tk and bring extension versions
	* win/nmakehlp.c:   closer together. Try and avoid using tclsh
	        to do substitutions as we may cross compile.

	* library/console.tcl:     Use TkFixedFont and ttk widgets

2007-10-12  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c:	replace all (internal) use of QD region
	* macosx/tkMacOSXSubwindows.c:	API by HIShape API, with conversion to
	* macosx/tkMacOSXWindowEvent.c:	QD regions only when required by legacy
	* macosx/tkMacOSXPrivate.h:	Carbon or Tk API.
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:

	* macosx/tkMacOSXInt.h:		replace MacDrawable's QD RgnHandles
	* macosx/tkMacOSXEmbed.c:	clipRgn, aboveClipRgn & drawRgn by
	* macosx/tkMacOSXMenu.c:	HIShapeRefs visRgn & aboveVisRgn and
	* macosx/tkMacOSXSubwindows.c:	CGRect drawRect.

	* macosx/tkMacOSXWindowEvent.c:	remove use of QD port vis rgn in
	* macosx/tkMacOSXSubwindows.c:	window update rgn calculation,
	* macosx/tkMacOSXWm.c:		manually excise growbox from toplevel
					clip rgn instead.

	* macosx/tkMacOSXDraw.c:	replace use of QD port clip rgn by new
	* macosx/tkMacOSXPrivate.h:	clipRgn fld in TkMacOSXDrawingContext;
					handle QD/CG drawing mismatches in
					XCopyArea, XCopyPlane and TkPutImage;
					cleanup/speedup CGContext setup in
					TkMacOSXSetupDrawingContext().

	* macosx/tkMacOSXDraw.c:	change TkMacOSXSetupDrawingContext()
	* macosx/tkMacOSXEntry.c:	to return boolean indicating whether
	* macosx/tkMacOSXFont.c:	drawing is allowed (and was setup) or
	* macosx/tkMacOSXMenu.c:	not (e.g. when clipRgn is empty).
	* macosx/ttkMacOSXTheme.c:

	* macosx/tkMacOSXSubwindows.c:	signal that drawable is a pixmap via
	* macosx/tkMacOSXInt.h:		new explicit TK_IS_PIXMAP flag instead
					of a NULL cligRgn field.

	* macosx/tkMacOSXRegion.c:	add wrappers for missing/buggy HIShape
	* macosx/tkMacOSXPrivate.h:	API, and private helpers to operate on
					HIShapeRefs & convert to/from TkRegion

	* macosx/tkMacOSXRegion.c:	add Tkp{Retain,Release}Region() API
	* macosx/tkMacOSXInt.h:		for TkRegion.

	* xlib/xgc.c:			factor out alloc/free of GC clip_mask;
	* macosx/tkMacOSXXStubs.c:	manage clip rgn lifetime with new
					Tkp{Retain,Release}Region().

	* macosx/tkMacOSXButton.c:	delay picParams setup until needed.

	* generic/tkTextDisp.c (CharUndisplayProc): fix textDisp.test crash.

2007-10-11  David Gravereaux <[email protected]>

	* win/winMain.c: Replaced incorrect comments in main() to descibe why
	the console widget does not need to be created for this application
	entry point (if used). Must have been a bad copy/paste of WinMain()
	from 10 years back.

2007-10-11  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (TkMacOSXGrowToplevel): manually constrain resize
	limitBounds to maxBounds, works around SectRect() mis-feature (return
	zero rect if input rect has zero height/width). [Bug 1810818]

2007-10-09  Pat Thoyts  <[email protected]>

	* generic/tkImage.c:    Make Ttk_GetImage safe if called with NULL
	* tests/ttk/image.test: interp. Added some tests that crash on Windows
				without this fix.

2007-10-02  Don Porter  <[email protected]>

	[core-stabilizer-branch]

	* README:        Bump version number to 8.5.0
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:	Updated LOCALES.
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf (2.59)
	* win/configure:

2007-09-30  Joe English  <[email protected]>

	* library/ttk/entry.tcl (WordBack, WordForward):
	Fix private routines accidentally defined in global namespace
	[Bug 1803836]

2007-09-26  Donal K. Fellows  <[email protected]>

	* library/msgs/hu.msg: Added Hungarian message set, from Pader Reszo.
	[Patch 1800742]

2007-09-20  Donal K. Fellows  <[email protected]>

	*** 8.5b1 TAGGED FOR RELEASE ***

	* generic/tkTextDisp.c (LayoutDLine):  Only call callbacks that are
	* tests/textDisp.test (textDisp-32.3): not NULL. [Bug 1791052]

2007-09-20  Don Porter  <[email protected]>

	* changes: updates for 8.5b1 release.

2007-09-19  Don Porter  <[email protected]>

	* README:		Bump version number to 8.5b1.
	* generic/tk.h:		Merge from core-stabilizer-branch.
	* library/tk.tcl:	Stabilizing toward 8.5b1 release now done
	* unix/configure.in:	on the HEAD. core-stabilizer-branch is
	* unix/tk.spec:		now suspended.
	* win/configure.in:

2007-09-19  Pat Thoyts  <[email protected]>

	* generic/tkStubLib.: Replaced isdigit with internal implementation.

2007-09-18  Don Porter  <[email protected]>

	* generic/tkStubLib.c:	Remove C library calls from Tk_InitStubs()
	* win/makefile.vc:	so that we don't need the C library linked
	in to libtkStub.

2007-09-18  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c (FileReadGIF, StringReadGIF): Rewrite for greater
	clarity (more comments, saner code arrangement, etc.)

2007-09-18  Pat Thoyts  <[email protected]>

	* tests/all.tcl:    Made ttk/all.tcl be the same as tk's all.tcl and
	* tests/ttk/all.tcl: make use of file normalize (bugs noted by
	mjanssen and GPS with msys)

2007-09-17  Pat Thoyts  <[email protected]>

	* win/makefile.vc: Add crt flags for tkStubLib now it uses C-library
	functions.

2007-09-17  Joe English  <[email protected]>

	* unix/tcl.m4: use '${CC} -shared' instead of 'ld -Bshareable' to
	build shared libraries on current NetBSDs. [Bug 1749251]
	* unix/configure: regenerated (autoconf-2.59).

2007-09-17  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Revised callers of Tcl_InitStubs() to account
	* generic/tkMain.c:	for restored compatible support for the call
	* generic/tkWindow.c:	Tcl_InitStubs(interp, TCL_VERSION, 1). Also
	revised Tcl_PkgRequire() call for Tcl so that, for example, a Tk
	library built against Tcl 8.5.1 headers will not refuse to [load] into
	a Tcl 8.5.0 interpreter. [Tcl Bug 1578344]

	* generic/tk.h:		Revised Tk_InitStubs() to restore Tk 8.4
	* generic/tkStubLib.c:	source compatibility with callers of
	* generic/tkWindow.c:	Tk_InitStubs(interp, TK_VERSION, 1).

2007-09-17  Joe English  <[email protected]>

	* library/ttk/combobox.tcl:  Try to improve combobox appearance on
	OSX + Tk 8.5. [Bug 1780286]

2007-09-15  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: 	replace all direct references to compiler by ${CC} to
			enable CC overriding at configure & make time; run
			check for visibility "hidden" with all compilers;
			quoting fixes from TEA tcl.m4.
	(SunOS-5.1x):	replace direct use of '/usr/ccs/bin/ld' in SHLIB_LD by
			'cc' compiler driver.
	* unix/configure: autoconf-2.59

2007-09-14  Daniel Steffen  <[email protected]>

	* macosx/Wish-Common.xcconfig:		  enable Tcl DTrace support.
	* macosx/Wish.xcodeproj/project.pbxproj:

2007-09-12  Andreas Kupries  <[email protected]>

	* win/Makefile.in (install-binaries): Fixed missing brace in the
	* win/makefile.vc (install-binaries): generated package index file.
	Note: unix/Makefile.in is good.

2007-09-11  Reinhard Max  <[email protected]>

	* generic/tkImgGIF.c: Fixed a buffer overrun that got triggered by
	multi-frame interlaced GIFs that contain subsequent frames that are
	smaller than the first one.

	* tests/imgPhoto.test: Added a test for the above.

2007-09-11  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Revised calls to Tcl_InitStubs() and
	* generic/tkMain.c:	[package require Tcl] so that Tk Says What It
	* generic/tkWindow.c:	Means using the new facilties of [package] in
	* library/tk.tcl:	Tcl 8.5 about what version(s) of Tcl it is
	* unix/Makefile.in:	willing to work with. [Bug 1578344]
	* win/Makefile.in:
	* win/makefile.vc:

2007-09-10  Jeff Hobbs  <[email protected]>

	* unix/README: typo corrections [Bug 1788682]

2007-09-10  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Revise all Tcl_InitStubs() calls to restore
	* generic/tkMain.c:	the traditional practice that a Tk shared
	* generic/tkWindow.c:	library may [load] into a Tcl 8.5 interp at
	any patchlevel.	 This practice also matches the compile time checks of
	TCL_MAJOR_VERSION and TCL_MINOR_VERSION in tk.h. [Bug 1723622]

2007-09-06  Don Porter  <[email protected]>

	* generic/tkWindow.c (Initialize):	Moved common Tk initialization
	* generic/tkInitScript.h (removed):	script out of tkInitScript.h
	* macosx/tkMacOSXInit.c:	and multiple TkpInit() routines and
	* unix/Makefile.in:	into the common Initialize() routine in
	* unix/tkUnixInit.c:	generic code. Also removed constraint on
	* win/tkWinInit.c:	ability to define a custom [tkInit] before
	calling Tk_Init(). Until now the custom [tkInit] had to be a proc. Now
	it can be any command. Removal of tkInitScript.h also fixes [Bug
	1656283].

2007-09-06  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcode/project.pbxproj: discontinue unmaintained support
	* macosx/Wish.xcode/default.pbxuser: for Xcode 1.5; replace by Xcode2
	project for use on Tiger (with Wish.xcodeproj to be used on Leopard).

	* macosx/Wish.xcodeproj/project.pbxproj: updates for Xcode 2.5 and 3.0.
	* macosx/Wish.xcodeproj/default.pbxuser:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/Wish-Common.xcconfig:

	* macosx/README: document project changes.

2007-09-04  Joe English  <[email protected]>

	* generic/tkTest.c: Fix for [Bug 1788019] "tkTest.c compiler warning".

2007-09-04  Don Porter  <[email protected]>

	* unix/Makefile.in:  It's unreliable to count on the release
	manager to remember to `make genstubs` before `make dist`. Let the
	Makefile remember the dependency for us.

	* unix/Makefile.in:  Corrections to `make dist` dependencies to be
	sure that macosx/configure gets generated whenever it does not exist.

2007-09-03  Daniel Steffen  <[email protected]>

	* generic/ttk/ttkInit.c  (Ttk_Init): register ttk in package database
	to enable extension access to the ttkStubs table.

	* generic/ttk/ttkDecls.h: correct capitalization of ttk package name.

2007-08-28  Donal K. Fellows  <[email protected]>

	Assorted documentation improvements.
	* doc/button.n: Added examples.
	* doc/checkbutton.n: Added example.
	* doc/console.n: Standardized section ordering.
	* doc/tk.n: Added "See also".
	* doc/ttk_combobox.n: Added keywords.

2007-08-27  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDialog.c (Tk_ChooseColorObjCmd): correct setting of
	interp result [Bug 1782105]; fix -initialcolor overwriting last color
	selection; style cleanup.

2007-08-21  Pat Thoyts  <[email protected]>

	* win/rules.vc: Synchronize with tcl rules.vc
	* tests/all.tcl: Fix the line-endings.

2007-08-07  Daniel Steffen  <[email protected]>

	* unix/Makefile.in:	Add support for compile flags specific to
				object files linked directly into executables.

	* unix/configure.in (Darwin): Only use -seg1addr flag when prebinding;
	use -mdynamic-no-pic flag for object files linked directly into exes.

	* unix/configure: autoconf-2.59

2007-08-01  Pat Thoyts  <[email protected]>

	* win/tkWinDialog.c:    Fix [Bug 1692927] (buffer length problems)
	* win/tkWinTest.c:    Added 'testfindwindow' and 'testgetwindowinfo'
	and extended 'testwinevent' for WM_COMMAND support to enable testing
	native messagebox dialogs.
	* tests/winMsgbox.test: New Windows native messagebox tests.

2007-07-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDialog.c (NavServicesGetFile): Reset interp result on
	nav dialog cancel. [Bug 1743786]

2007-07-09  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in: clarify what the headers installed are, and
	add ttkTheme.h and ttkDecls.h to private headers (later public).

2007-07-09  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWindowEvent.c (Tk_MacOSXIsAppInFront):	Use process mgr
	* macosx/tkMacOSXMouseEvent.c:				to determine if
	app is in front instead of relying on activate/deactivate events (which
	may arrive after this info is needed, e.g. during window drag/click
	activation); replace other process mgr use to get this info with calls
	to Tk_MacOSXIsAppInFront().

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): Correct
	window click activation, titlebar click handling and background window
	dragging/growing in the presence of grabs or window-/app-modal windows;
	fix window click activation bringing all other app windows to front.

	* macosx/tkMacOSXDraw.c (TkPutImage): Handle non-native XImage byte and
	bit orders; reverse bits via xBitReverseTable instead of InvertByte().

2007-07-06  Joe English  <[email protected]>

	* library/ttk/aquaTheme.tcl:	Set -anchor w for TMenubuttons.
					[Bug 1614540]

2007-07-04  Andreas Kupries  <[email protected]>

	* macosx/tkMacOSXXStubs.c (DestroyImage): Fixed seg.fault in release
	of image data for images coming from XGetImage. Change committed by me
	for Daniel Steffen. See 2007-06-23 for the change which introduced the
	problem.

2007-07-02  Daniel Steffen  <[email protected]>

	* xlib/xgc.c (XCreateGC): Correct black and white pixel values used to
	initialize GC foregrund and background fields.

	* macosx/tkMacOSXColor.c: Add debug messages for unknown pixel values.

	* macosx/tkMacOSXDraw.c (TkMacOSXRestoreDrawingContext): Don't restore
	port state if it wasn't altered by TkMacOSXSetupDrawingContext().

2007-06-29  Daniel Steffen  <[email protected]>

	* xlib/ximage.c:		Bitmaps created from the static .xbm
					arrays always have LSBFirst bit order.

	* unix/configure.in:		Fix flag used to weak-link libXss.
	* unix/configure:		autoconf-2.59

	* macosx/tkMacOSXScrlbr.c: Correct int <-> dobule conversion issues
	that could lead to Carbon getting confused about scrollbar thumb size.

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage): Use
	TkMacOSX{Setup,Restore}DrawingContext() to setup/restore clip & colors.
	(TkMacOSXSetupDrawingContext, TkMacOSXRestoreDrawingContext): Add save
	and restore of QD port clip region; factor out clip region code common
	to CG and QD branches; check for port and context validity; handle
	tkPictureIsOpen flag during QD port setup.
	(TkScrollWindow): Remove unnecessary scroll region manipulation

	* macosx/tkMacOSXDraw.c:	Remove second global QD temp region
	* macosx/tkMacOSXInt.h:		(no longer necessary) and rename
	* macosx/tkMacOSXRegion.c:	remaining global QD temp region.
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXDraw.c: 	Make useCGDrawing variable MODULE_SCOPE
	* macosx/tkMacOSXFont.c: 	and respect it for ATSUI font drawing.

	* macosx/tkMacOSXButton.c:	Reduce reliance on current QD port
	* macosx/tkMacOSXColor.c:	setting and remove unnecessary
	* macosx/tkMacOSXDebug.c:	references to a drawable's QD port,
	* macosx/tkMacOSXDebug.h:	notably replace GetWindowFromPort(
	* macosx/tkMacOSXDialog.c:	TkMacOSXGetDrawablePort()) idiom by new
	* macosx/tkMacOSXDraw.c:	TkMacOSXDrawableWindow() and change
	* macosx/tkMacOSXKeyEvent.c:	TkMacOSXSetColorInPort() to take a port
	* macosx/tkMacOSXMenu.c:	argument.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:		  	Factor out macros, declarations
	* macosx/tkMacOSXPrivate.h (new): 	and prototypes that are purely
	internal and private to the 'macosx' sources into a new internal header
	file that does _not_ get installed into Tk.framework/PrivateHeaders.

	* macosx/tkMacOSXButton.c: 		#include new tkMacOSXPrivate.h
	* macosx/tkMacOSXCarbonEvents.c:	instead of tkMacOSXInt.h.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* macosx/ttkMacOSXTheme.c:

	* macosx/Wish.xcodeproj/project.pbxproj: Improve support for renamed
	* macosx/Wish.xcodeproj/default.pbxuser: tcl and tk source dirs; add
	* macosx/Wish-Common.xcconfig:		 10.5 SDK build config; remove
						 tclMathOp.c.

	* macosx/README: Document Wish.xcodeproj changes.

2007-06-23  Daniel Steffen  <[email protected]>

	* generic/tkImgPhoto.c (ImgPhotoConfigureInstance, DisposeInstance):
	Use XDestroyImage instead of XFree to destroy XImage; replace runtime
	endianness determination by compile-time check for WORDS_BIGENDIAN.

	* xlib/ximage.c (XCreateBitmapFromData): Use XCreateImage and
	XDestroyImage instead of creating XImage structure manually.

	* macosx/tkMacOSXXStubs.c (XCreateImage, DestroyImage): Correct XImage
	bytes_per_line/bitmap_pad calculations and endianness setting; free
	image data and XImage structure at destruction; formatting cleanup.

	* macosx/tkMacOSXDialog.c (NavServicesGetFile): Disable app-modal
	sheet variant of nav dialog on OS versions where it causes problems.

2007-06-20  Jeff Hobbs  <[email protected]>

	* library/ttk/ttk.tcl: Should require Tk before pseudo-providing
	tile 0.8.0.

2007-06-09  Joe English  <[email protected]>

	* generic/ttk/ttkPanedwindow.c, doc/ttk_panedwindow.n,
	* tests/ttk/panedwindow.test: Added -width and -height options. Added
	'panes' method, return list of managed windows. 'sashpos' method is
	now documented as part of the public interface, and details clarified.
	Should be easier to set initial sash positions now. Alleviates [Bug
	1659067].

2007-06-09  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (WmIconphotoCmd): fix wm iconphoto RGBA issues.
	[Bug 1467997] (janssen)

	* win/tkWinMenu.c (TkWinHandleMenuEvent): Improve handling to allow
	for unicode char menu indices and not use CharUpper on Tcl utf
	strings. [Bug 1734223]

2007-06-09  Joe English  <[email protected]>

	* generic/ttk/ttkManager.h, generic/ttk/ttkManager.c,
	* generic/ttk/ttkNotebook.c, generic/ttk/ttkPanedwindow.c,
	* generic/ttk/ttkFrame.c: Ttk_Manager API overhaul:
	    + Ttk_Manager no longer responsible for managing slave records
	    + Ttk_Manager structure now opaque
	    + Ttk_Slave structure now private
	    + Pass Ttk_Manager* to Tk_GeomMgr hooks instead of Ttk_Slave*

	* generic/ttk/ttkFrame.c: Simplified -labelwidget management.

	* doc/ttk_panedwindow.n, library/ttk/panedwindow.tcl: Changed
	documentation of ttk::panedwindow 'identify' command to match
	implementation.

	* generic/ttk/ttkNotebook.c, tests/ttk/notebook.test:
	BUGFIX: ttk::noteboook 'insert' command didn't correctly maintain
	current tab.

2007-06-09  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXColor.c: Fix issues with TK_{IF,ELSE,ENDIF} macros;
	* macosx/tkMacOSXDraw.c:  implement Jaguar equivalent of unavailable
	* macosx/tkMacOSXEntry.c: kHIToolboxVersion global; panic at startup
	* macosx/tkMacOSXEvent.c: if MAC_OS_X_VERSION_MIN_REQUIRED constraint
	* macosx/tkMacOSXInit.c:  is not satisfied.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage)
	(TkMacOSXSetupDrawingContext): Factor out common code and standardize
	setup/restore of port, context and clipping; formatting cleanup.

	* macosx/tkMacOSXWindowEvent.c:	Add error checking.
	* macosx/tkMacOSXMenu.c:	Fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	Fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	Formatting cleanup.
	* macosx/tkMacOSXRegion.c:	Fix typos.
	* macosx/tkMacOSXScale.c:

	* macosx/tkMacOSXXStubs.c (Tk_GetUserInactiveTime): Remove superfluous
							    CFRetain/CFRelease.

	* macosx/Wish-Release.xcconfig: Disable tktest release build stripping.

	* macosx/Wish.xcodeproj/project.pbxproj: Add new Tclsh-Info.plist.in.

2007-06-06  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXInt.h: Use native debug message API when available.
	* macosx/Wish-Debug.xcconfig:

	* macosx/tkMacOSXMouseEvent.c (GenerateMouseWheelEvent): Enable
	processing of mousewheel events in background windows.

	* macosx/tkMacOSXScrlbr.c: Modernize checks for active/front window.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXColor.c: Factor out verbose #ifdef checks of
	* macosx/tkMacOSXDraw.c:  MAC_OS_X_VERSION_{MAX_ALLOWED,MIN_REQUIRED}
	* macosx/tkMacOSXEntry.c: and runtime checks of kHIToolboxVersion into
	* macosx/tkMacOSXEvent.c: new TK_{IF,ELSE,ENDIF}_MAC_OS_X macros.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c:  Factor out clip clearing in QD ports;
	* macosx/tkMacOSXEntry.c: Formatting cleanup.

	* macosx/Wish.xcodeproj/project.pbxproj: Add settings for Fix&Continue.

	* unix/configure.in (Darwin): Link the Tk and Wish plists into their
	binaries in all cases; fix 64bit arch removal in fat 32&64bit builds.

	* unix/tcl.m4 (Darwin): Fix CF checks in fat 32&64bit builds.
	* unix/configure: autoconf-2.59

2007-06-05  Donal K. Fellows  <[email protected]>

	* doc/photo.n: Clarified the fact that base64 support for the -data
	option is not universal. [Bug 1731348] (matzek)

2007-06-03  Daniel Steffen  <[email protected]>

	* unix/Makefile.in: Add datarootdir to silence autoconf-2.6x warning.

	* macosx/Wish.xcodeproj/default.pbxuser: Add ttk tests.

	* macosx/tkMacOSXMenu.c: Add error checking; whitespace cleanup.

	* macosx/tkMacOSXDraw.c:	Comment formatting fixes for Xcode 3.0
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

2007-06-02  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXMenu.c (TkpPostMenu): Ensure cascade menus display in
	posted menus that are not part of the menubar or attached to a
	menubutton (fixes bug reported on tcl-mac by Linus Nyberg).

2007-05-31  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): Complete all
	pending idle-time redraws before newly posted Expose events are
	processed; add bounds of redrawn windows to update region to ensure
	all child windows overdrawn by parents are redrawn.

	* macosx/tkMacOSXWindowEvent.c:	Centralize clip and window invalidation
	* macosx/tkMacOSXSubwindows.c: 	after location/size changes in the
	* macosx/tkMacOSXWm.c:		BoundsChanged carbon event handler;
	correct/add window invalidation after window attribute changes.

	* macosx/tkMacOSXSubwindows.c (XResizeWindow, XMoveResizeWindow)
	(XMoveWindow): Factor out common code dealing with embedded and
	non-toplevel windows; remove unnecessary clip and window invalidation.

	* macosx/tkMacOSXButton.c (TkpDisplayButton): Move clip setup closer
	to native button drawing calls.

	* macosx/tkMacOSXWm.c (TkMacOSXIsWindowZoomed, TkMacOSXZoomToplevel):
	Correct handling of gridded windows in max size calculations.

	* macosx/tkMacOSXEvent.c (TkMacOSXFlushWindows): Use HIWindowFlush API
	when available.

	* macosx/tkMacOSXColor.c:	Cleanup whitespace and formatting.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* generic/tkFont.c:	#ifdef out debug msg printing to stderr.
	* generic/tkTextDisp.c:

2007-05-30  Don Porter  <[email protected]>

	* generic/tk.h: Correct placement of #include <tcl.h>. [Bug 1723812]

2007-05-30  Daniel Steffen  <[email protected]>

	* library/bgerror.tcl:	Standardize dialog option & button size
	* library/dialog.tcl:	modifications done when running on on Aqua.
	* library/msgbox.tcl:

	* library/demos/button.tcl: Set button highlightbackground on Aqua.

	* macosx/tkMacOSXMenu.c (DrawMenuSeparator): Use DrawingContext API.

	* macosx/tkMacOSXWindowEvent.c (ClearPort): Clip to updateRgn.

	* macosx/tkMacOSXDebug.c:	Factor out debug region flashing.
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXEvent.c:	Cleanup whitespace and formatting.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* xlib/xgc.c:

	* macosx/Wish.xcodeproj/project.pbxproj: Delete references to removed
	* macosx/Wish.xcodeproj/default.pbxuser: ttk files.

2007-05-28  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXFont.c (TkpMeasureCharsInContext): Fix short measures
	with flags=TK_WHOLE_WORDS|TK_AT_LEAST_ONE [Bug 1716141]. Make some
	casts unnecessary by changing variable types.

2007-05-25  Joe English  <[email protected]>

	* library/ttk/ttk.tcl: Omit ttk::dialog and dependencies.
	* library/ttk/dialog.tcl, library/ttk/icons.tcl,
	* library/ttk/keynav.tcl: Removed.
	* tests/ttk/misc.test: Removed.
	* doc/ttk_dialog.tcl: Removed.

2007-05-25  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: Fixed documentation of default -joinstyle option
	values for line and polygon items. [Bug 1725782]

2007-05-22  Don Porter  <[email protected]>

	[core-stabilizer-branch]

	* unix/configure:    autoconf-2.59 (FC6 fork)
	* win/configure:

	* README:        Bump version number to 8.5b1
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

2007-05-18  Joe English  <[email protected]>

	* generic/ttk/ttkEntry.c(EntrySetValue):  Ensure that widget is in a
	consistent state before setting the linked -textvariable. Previously,
	it was possible for [$e index insert] to point past the end of the
	string, leading to heap corruption. [Bug 1721532]
	* tests/ttk/entry.test(entry-9.1): Add test case for the above.

2007-05-18  Don Porter  <[email protected]>

	* unix/configure:    autoconf-2.59 (FC6 fork)
	* win/configure:

	* README:        Bump version number to 8.5a7
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* tests/ttk/treetags.test:	Another bit of test suite
	SCIM-tolerance. [Bug 1609316]

2007-05-17  Daniel Steffen  <[email protected]>

	* generic/tk.decls: Workaround 'make checkstubs' failures from
	tkStubLib.c MODULE_SCOPE revert. [Bug 1716117]

	* macosx/Wish.xcodeproj/project.pbxproj: Add tkOldTest.c and remove
						 tkStubImg.c.

2007-05-16  Joe English  <[email protected]>

	* generic/tkStubLib.c:  Change Tk_InitStubs(), tkStubsPtr, and the
	auxilliary stubs table pointers back to public visibility. See [Bug
	1716117] for details.

	Removed TCL_STORAGE_CLASS monkey business, as it had no effect.

2007-05-16  Don Porter  <[email protected]>

	* library/choosedir.tcl:	Removed uses of obsolete {expand}
	* library/comdlg.tcl:		syntax; replaced with the now
	* library/tk.tcl:		approved {*}. [Bug 1710633]
	* tests/canvImg.test:
	* tests/imgPhoto.test:

	* tests/bind.test:  Make test suite more SCIM-tolerant. [Bug 1609316]

2007-05-16  Pat Thoyts  <[email protected]>

	* win/makefile.vc: Test ttk widgets.

2007-05-15  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Fix crash introduced by previous fix exposed
	under newer fontconfig libraries [Bug 1717830] again.

2007-05-15  Don Porter  <[email protected]>

	* generic/tkGrid.c: Stop crash due to list intrep shimmer [Bug 1677608]

2007-05-15  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Fix various memory leaks. [Bug 1717830], [Bug
	800149]

2007-05-14  Don Porter  <[email protected]>

	[Tk Bug 1712081]

	* unix/Makefile.in:	Updates to account for new and deleted files
	* win/Makefile.in:	tkStubImg.c and tkOldTest.c.
	* win/makefile.bc:
	* win/makefile.vc:

	* generic/tkOldTest.c (new):	New file used to create testing
	* generic/tkTest.c:		commands for testing various Tk
	* tests/constraints.tcl:	legacy interfaces where a separate
	* tests/image.test:		compilation unit is needed in order to
	#define suitable macros during compilation. Only the effect of
	USE_OLD_IMAGE on Tk_CreateImageType() is currently tested, but more
	similar testing commands can be added to this same file. New
	constraint defined to detect presence of the image type provided by
	the new testing code, and a few tests added to exercise it. Having
	USE_OLD_IMAGE support tested by the default test suite should reduce
	chance of a recurrence of this bug.

	* doc/CrtImgType.3:	Revised docs to better indicate the legacy
	* doc/CrtPhImgFmt.3:	nature of the interfaces supported by
	USE_OLD_IMAGE.

	* generic/tkDecls.h:	make genstubs
	* generic/tkStubInit.c:

	* generic/tk.decls:		Reworked USE_OLD_IMAGE support to use
	* generic/tk.h:			the same support mechanisms both with
	* generic/tkStubImg.c (deleted):and without a stub-enabled build. In
	each case, route the legacy calls to Tk_CreateImageType and
	Tk_CreatePhotoImageFormat through the Tk_CreateOldImageType and
	Tk_CreateOldPhotoImageFormat routines. Add those routines to the
	public stub table so they're available to a stub-enabled extension.
	Remove the definition of Tk_InitImageArgs() and use a macro to convert
	any calls to it in source code into a comment.

	* generic/tkImage.c:	Removed the MODULE_SCOPE declarations that
	* generic/tkImgPhoto.c:	broke USE_OLD_IMAGE support.

2007-05-11  Pat Thoyts  <[email protected]>

	* tests/winButton.test: Avoid font dependencies in results.

	* generic/tkFont.c: propagate error from TkDeleteNamedFont. [Bug
	1716613]

2007-05-09  Daniel Steffen  <[email protected]>

	* generic/tkFileFilter.c (AddClause): OSType endianness fixes.

	* library/palette.tcl (tk::RecolorTree): Handle color options with
	empty value, fixes error due to emtpy -selectforeground (reported on
	tcl-mac by Russel E. Owen).

	* macosx/tkMacOSXWindowEvent.c:	Ensure window is brought to the front
	* macosx/tkMacOSXMouseEvent.c:	at the start of a window drag (except
	* macosx/tkMacOSXInt.h:		when cmd key is down); formatting and
					whitespace fixes.

	* macosx/tkMacOSXDialog.c (Tk_GetSaveFileObjCmd): Add -filetypes option
	processing (fixes fileDialog-0.1, fileDialog-0.2 failures).

	* macosx/tkMacOSXEmbed.c (TkpMakeWindow, TkpUseWindow): Fix sending of
	Visibility event for embedded windows (fixes frame-3.9 hang).

	* macosx/tkMacOSXScrlbr.c (ScrollbarBindProc):		Fix testsuite
	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn):	crashes by
	adding sanity checks.

	* macosx/Wish.xcodeproj/project.pbxproj: Add 'DebugUnthreaded' &
	* macosx/Wish.xcodeproj/default.pbxuser: 'DebugLeaks' targets and env
	var settings needed to run the 'leaks' tool.

	* macosx/tkMacOSXButton.c: Fix debug msg typo.

	* tests/constraints.tcl: Ensure 'nonUnixUserInteraction' constraint is
	set for aqua.

	* tests/choosedir.test:	Add 'notAqua' constraints to X11-only tests;
	* tests/clrpick.test:	add 'nonUnixUserInteraction' to 'unix' tests
	* tests/menuDraw.test:	requiring interaction on aqua.
	* tests/unixMenu.test:
	* tests/unixWm.test:
	* tests/winMenu.test:

2007-05-07  Joe English  <[email protected]>

	* unix/tkUnixRFont.c: Properly cast sentinel arguments to variadic
	function (fixes "warning: missing sentinel in function call", [Bug
	1712001])

2007-05-04  Pat Thoyts  <[email protected]>

	* generic/tkFont.c:  TIP #145 implementation -
	* generic/tkFont.h:  Enhanced font handling.
	* win/tkWinDefault.h:
	* win/tkWinFont.c:
	* win/tkWinInt.h:
	* win/tkWinWm.c:
	* library/demos/widget:
	* library/ttk/fonts.tcl:

2007-05-04  Donal K. Fellows  <[email protected]>

	* doc/ttk_treeview.n, doc/ttk_panedwindow.n, doc/ttk_dialog.n:
	* doc/ttk_checkbutton.n, doc/tk.n, doc/menu.n, doc/font.n:
	* doc/canvas.n: Spelling fixes. [Bug 1686210]

2007-05-03  Donal K. Fellows  <[email protected]>

	* generic/tkStubLib.c (Tk_InitStubs):
	* generic/ttk/ttkLabel.c (LabelSetup):
	* unix/tkUnixSelect.c (ConvertSelection):
	* unix/tkUnixEvent.c (TkUnixDoOneXEvent):
	* generic/tkConfig.c (Tk_RestoreSavedOptions):
	* generic/tkCanvPs.c (TkCanvPostscriptCmd):
	* generic/tkOption.c (GetDefaultOptions):
	* unix/tkUnixRFont.c (TkpGetFontAttrsForChar, InitFont)
	(TkpGetFontFamilies, TkpGetSubFonts):
	* unix/tkUnixSend.c (TkpTestsendCmd, RegOpen): Squelch warnings from
	GCC type aliasing. [Bug 1711985 and others]

2007-04-29  Daniel Steffen  <[email protected]>

	* unix/configure.in: Fix for default case in tk debug build detection.
	* unix/configure: autoconf-2.59

2007-04-27  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c(TagOptionSpecs): Use TK_OPTION_STRING
	instead of TK_OPTION_FONT to avoid resource leak in tag management.

2007-04-26  Joe English  <[email protected]>

	* macosx/ttkMacOSXTheme.c: Merged OFFSET_RECT processing into
	BoxToRect(); factored out PatternOrigin; resynchronized with Tile
	codebase.

2007-04-26  Jeff Hobbs  <[email protected]>

	*** 8.5a6 TAGGED FOR RELEASE ***

	* unix/Makefile.in (dist): Correct tests/ttk glob inclusion

2007-04-25  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (dist): Add tests/ttk dir to src dist

	* unix/tkUnixMenubu.c (TkpDisplayMenuButton): Init width/height to 0

2007-04-25  Daniel Steffen  <[email protected]>

	* unix/Makefile.in (dist): Add macosx/*.xcconfig files to src dist;
	copy license.terms to dist macosx dir; fix autoheader bits.

2007-04-24  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (dist): Add ttk bits to src dist

	* tests/font.test (font-46.[12]): Correct listification of result

2007-04-23  Daniel Steffen  <[email protected]>

	* generic/tkCanvas.c:	Allow -selectforeground option to be None; add
	* generic/tkCanvText.c:	fallback to fgColor when selFgColor is None
	* generic/tkEntry.c:	(new default on aqua to match native L&F).
	* generic/tkListbox.c:
	* generic/tkText.c:

	* generic/tkCanvas.c:	   Add support for bypassing all of Tk's double
	* generic/tkEntry.c:	   buffered drawing into intermediate pixmaps
	* generic/tkFrame.c:	   (via TK_NO_DOUBLE_BUFFERING #define), it is
	* generic/tkListbox.c:	   unnecessary & wasteful on aqua where all
	* generic/tkPanedWindow.c: drawing is already double-buffered by the
	* generic/tkTextDisp.c:	   window server. (Use of this on other
	* generic/ttk/ttkWidget.c: platforms would only require implementation
	* unix/tkUnixScale.c:	   of TkpClipDrawableToRect()).
	* macosx/tkMacOSXPort.h:

	* library/bgerror.tcl:	On aqua, use moveable alert resp. modal dialog
	* library/dialog.tcl:	window class and corresponding system
				background pattern; fix button padding.

	* library/tearoff.tcl:	Correct aqua menu bar height; vertically offset
	* library/tk.tcl:	aqua tearoff floating window to match menu.

	* library/demos/goldberg.tcl: Fix overwriting of widget demo global.

	* library/demos/menu.tcl:   On aqua, use custom MDEF and tearoffs;
	* library/demos/menubu.tcl: correct menubutton toplevel name.

	* library/demos/puzzle.tcl: Fix button size & padding for aqua.
	* library/demos/radio.tcl:

	* macosx/tkMacOSXCarbonEvents.c: Add window event target carbon event
	* macosx/tkMacOSXEvent.c:	 handler for all kEventClassWindow and
	* macosx/tkMacOSXEvent.h:	 kEventClassMouse events; move all
	* macosx/tkMacOSXNotify.c:	 remaining events except for
	* macosx/tkMacOSXWindowEvent.c:	 kEventClassKeyboard from dispatcher to
	application event handler; pass event handler callRef downstream; fix
	debug event tracing; process all tcl event types in carbon event timer;
	delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark
	enter/exit of event tracking loop during which all tcl events but only
	carbon update events should be processed by the timer (replaces various
	calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent()
	to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to
	tkMacOSXCarbonEvents.c and modify it to dequeue only update events
	during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize
	the various ways in use to run the tcl event loop; add handling of
	kEventClassAppearance events (for ScrollBarVariantChanged event).

	* macosx/tkMacOSXDialog.c:	Use new TkMacOSXTrackingLoop() around
	* macosx/tkMacOSXEvent.c:	blocking API that puts up modal dialogs
	* macosx/tkMacOSXMenu.c:	or when entering/exiting menu/control
	* macosx/tkMacOSXMouseEvent.c:	tracking, window dragging and other
	* macosx/tkMacOSXScale.c:	mouse tracking loops.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:	Use new TkMacOSXRunTclEventLoop()
	* macosx/tkMacOSXScale.c:	instead of Tcl_DoOneEvent(),
	* macosx/tkMacOSXScrlbr.c:	Tcl_ServiceAll(), TclServiceIdle()
	* macosx/tkMacOSXWindowEvent.c:	and Tcl_GlobalEval("update idletasks").

	* macosx/tkMacOSXColor.c: Make available as Tk system colors all
	* macosx/tkMacOSXPort.h:  appearance manager brushes, text colors and
	backgrounds with new and legacy names, as well as the fully transparent
	color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to
	directly set an X pixel color value in the current QD port resp. the
	given CG context without requiring passage through rgb representation
	(lossy for most system colors); modernize/remove Classic-era code;
	replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct().

	* macosx/tkMacOSXButton.c:	Use new TkMacOSXSetColorInPort()
	* macosx/tkMacOSXDraw.c:	instead of setting rgb color directly
	* macosx/tkMacOSXMenubutton.c:	to allow for non-rgb system colors.

	* macosx/tkMacOSXCursor.c: Implement "none" cursor as on other
	platforms [Patch 1615427]; add all missing appearance manager cursors.

	* macosx/tkMacOSXDefault.h: Set SELECT_FG_COLORs to None to match aqua
	L&F; use standard system color names; use new 'menu' system font;
	correct default scrollbar width.

	* macosx/tkMacOSXDraw.c: 	Standardize initialization, use and
	* macosx/tkMacOSXInt.h: 	emptying of various static temp rgns
	* macosx/tkMacOSXRegion.c:	onto two global RgnHandles; in debug
	* macosx/tkMacOSXSubwindows.c:	builds, verify emptiness of these temp
	* macosx/tkMacOSXWindowEvent.c:	rgns before use.

	* macosx/tkMacOSXDraw.c: Add TkMacOSX{Setup,Restore}DrawingContext() to
	* macosx/tkMacOSXInt.h:  abstract common setup & teardown of drawing
	environment (for both CG and QD); save/restore QD theme drawing state;
	handle GC clip region; add TkpClipDrawableToRect() to allow clipped
	drawing into drawable regardless of GC used; use new system color
	"systemWindowHeaderBackground" to setup background in themed toplevels;
	correct implementation of TkMacOSXMakeStippleMap().

	* macosx/tkMacOSXEntry.c:  Use new TkMacOSXSetupDrawingContext() and
	* macosx/tkMacOSXFont.c:   TkMacOSXRestoreDrawingContext() instead of
	* macosx/ttkMacOSXTheme.c: various setup/teardown procs like
	TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(),
	TkMacOSXSetUpGraphicsPort() etc.

	* macosx/tkMacOSXEmbed.c: Add CG context and drawable clip rgn fields
	* macosx/tkMacOSXInt.h:   to MacDrawable struct.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXDialog.c: Make -parent option of tk_getOpenFile et al.
	use the sheet version of NavServices dialogs; ensure native parent win
	exists before using StandardSheet API for tk_messageBox [Bug 1677611];
	force sheets to behave like app-modal dialogs via WindowModality() API;
	use more modern ColorPicker API.

	* macosx/tkAboutDlg.r: Use themed movable modal dialog, fix (c) year.

	* macosx/tkMacOSXEntry.c:  Take xOff/yOff of MacDrawable into account
	* macosx/ttkMacOSXTheme.c: when computing locations/bounds to ensure
	correct posititioning when not drawing into intermediate pixmap.

	* macosx/tkMacOSXFont.c: Use appearance manager API to map system font
	* macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for
	menu item text drawing from MDEF; always draw with CG; remove QD
	dependent stippling algorithm; move most header declarations into the
	source file (as they were not used anywhere else).

	* macosx/tkMacOSXMenu.c:		 Large-scale rewrite of custom
	* macosx/tkMacOSXMenu.r (removed):	 MDEF and related code that
	* macosx/Wish.xcode/project.pbxproj:	 restores many longtime-MIA
	* macosx/Wish.xcodeproj/project.pbxproj: features to working order
	* unix/Makefile.in:			 (e.g. images, custom colors &
	fonts in menus etc); implement compound menu items; use Appearance Mgr
	and ThemeText APIs to mimic native MDEF as closely as possible when
	default "menu" system font is used; remove now obsolete SICN drawing
	code and resources.

	* macosx/tkMacOSXCarbonEvents.c: Handle additional menu carbon events
	* macosx/tkMacOSXEvent.c:	 in order to support <<MenuSelect>> in
	* macosx/tkMacOSXMenu.c:	 the menubar and in menus that are not
	* macosx/tkMacOSXMenus.c:	 using the custom MDEF [Bug 1620826];
	fix early and missing clearing of current Tk active menu entry; fix
	extraneous sending of <<MenuSelect>> during active menu entry clearing.

	* macosx/tkMacOSXMouseEvent.c: Add support for async window dragging by
	the window server; set the corresponding window attribute by default.

	* macosx/tkMacOSXMouseEvent.c: Rationalized handling order of
	non-mousedown events; add TkMacOSXModifierState() to retrieve the
	current key modifiers in carbon format.

	* macosx/tkMacOSXScrlbr.c: Use appearance manager API to retrieve
	scrollbar component metrics; add awareness of multiple possibilites for
	scrollbar arrow position in aqua and handle user changes to arrow
	position pref; handle difference in metrics of small & large scrollbar
	variants; handle aqua "jump to here" scrollbar behaviour; correct
	computation of scroll view size and position; enforce min scrollbar
	height to avoid scrollbar component overlap; erase scrollbar area
	outside of standard width; remove broken auto-adjust code; account for
	window class when leaving space for grow box; remove code to manually
	draw grow box; use modern API for thumb scroll proc; replace
	HiliteControl() by modern API; replace control mgr constants with
	appearance mgr equivalents.

	* macosx/tkMacOSXSubwindows.c: Use SetWindowBounds() API instead of
	SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix
	for [Bug 940117] made them dependent on mapping state; remove unneeded
	calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port;
	use native-endian pixmap on intel; remove obsolete pixmap pix locking.

	* macosx/tkMacOSXWindowEvent.c: Handle only the first of a batch of
	kEventAppAvailableWindowBoundsChanged events sent per transaction;
	handle kEventWindowBoundsChanged event to support live window resizing
	and centralized sending of location/size changed ConfigureNotify
	events; ensure HIGrowBox is redrawn after bounds change; constrain
	window after dragging to ensure titlebar is not inacessible
	offscreen or under dock/menubar; handle kEventWindowGetRegion and
	kEventWindowDrawContent for transparent windows to mark resp. paint
	content region as transparent; handle kEventWindowConstrain for
	fullscreen windows to ensure bounds match new screen size; enter/exit
	fullscreen UIMode upon activation/deactivation of fullscreen window.

	* macosx/tkMacOSXWm.c: Use live-resize and async-drag carbon window
	* macosx/tkMacOSXWm.h: attributes for toplevels by default; implement
	new [wm attributes] -topmost, -transparent and -fullscreen; refactor
	WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus
	factored proc to set proxy icon from [wm iconbitmap]; dynamically
	determine default values for toplevel min and max sizes (similar to
	tkWinWm.c impl): min sizes depend on window class & attributes to
	ensure visibility of all titlebar widgets and grow box, max sizes
	depend on maximal window bounds for all active displays; factor out
	code that puts into effect changes to master or override_redirect; use
	RepositionWindow() API to determine staggered initial window bounds;
	correct resize limit calculations, handle gridding and use modern
	resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify
	after resize or zoom (now handled by BoundsChanged handler); correct
	composite carbon window attribute handling, remove currently unusable
	attributes and add new attributes in [tk::unsupported::MacWindowStyle];
	ensure validity of window class and attributes before use; apply
	changes to window class when handling carbon window attribute changes
	(if HIWindowChangeClass() API available); add debug build warning
	message when deprecated window style is used instead of window class;
	use transparent HIGrowBox for resizable windows; avoid unnecessary
	calls to window structure width API; use tcl time API in TkpGetMS();
	add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and
	menubar hidden; restrict wmTracing output to debug builds; remove
	unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD
	port; workaround GetWindowStructureWidths() Carbon bug (bogus results
	for never-mapped floating windows).

	* macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): Add maximal window
	bounds field to Screen record (in ext_data), computed as the union of
	available window positioning bounds of all graphics devices (displays).

	* macosx/tkMacOSXBitmap.c: Fix macRoman encoding leak.
	* macosx/tkMacOSXCursor.c:

	* macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): Use static
	* macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes.

	* macosx/tkMacOSXBitmap.c: Use more efficient QDSwapPort() instead of
	* macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld().
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXColor.c: Use kHIToolboxVersionNumber for runtime OS
	* macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c: Remove obsolete and now incorrect
	* macosx/tkMacOSXInt.h:  tkMenuCascadeRgn clipping code.
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXHLEvents.c: Replace Tcl_GlobalEval() resp. Tcl_Eval()
	* macosx/tkMacOSXScrlbr.c:   by Tcl_EvalEx().
	* macosx/tkMacOSXInit.c:

	* macosx/tkMacOSXInit.c (TkpInit): Reorder initialization steps.

	* macosx/tkMacOSXKeyEvent.c: Remove pre-10.2 support.

	* macosx/tkMacOSXMenus.c: Remove now useless call to
	TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman
	literar chars to allow file to be edited as utf-8.

	* macosx/tkMacOSXScale.c: Replace TrackControl() by modern
	* macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new
	TkMacOSXModifierState()).

	* macosx/tkMacOSXInt.h:		Move all constant #defines needed to
	* macosx/tkMacOSXColor.c:	support building on older OS X releases
	* macosx/tkMacOSXEvent.h:	to a central location in tkMacOSXInt.h.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/ttkMacOSXTheme.c:

	* macosx/tkMacOSXInt.h:		 Add ChkErr() macro to factor out
	* macosx/tkMacOSXButton.c:	 Carbon OSStatus return value checking
	* macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour
	* macosx/tkMacOSXClipboard.c:	 out debug message output; use these
	* macosx/tkMacOSXColor.c:	 macros to replace #ifdef TK_MAC_DEBUG
	* macosx/tkMacOSXCursor.c:	 blocks & direct printing to stderr,
	* macosx/tkMacOSXDebug.c:	 and to do additional OSStatus return
	* macosx/tkMacOSXDialog.c:	 checking, and to standardize OSStatus
	* macosx/tkMacOSXDraw.c:	 usage.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXSend.c:	Remove duplicate/unused declarations.
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXDebug.c:	Const fixes.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/Wish-Info.plist.in: Add tcl document extensions/mime types and
	LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys.

	* macosx/Wish-Common.xcconfig: Add Wish's Info.plist as __info_plist
	section to tktest; enable more warnings.

	* macosx/Wish.xcodeproj/project.pbxproj: Add 'DebugMemCompile' build
	configuration that calls configure with --enable-symbols=all; disable
	configure check for __attribute__((__visibility__("hidden"))) in Debug
	configuration to restore availability of ZeroLink.

	* macosx/Wish-Common.xcconfig:	Fix whitespace.
	* macosx/Wish-Debug.xcconfig:
	* macosx/Wish-Release.xcconfig:
	* macosx/tkMacOSXAETE.r:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursors.r:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXSend.c:
	* macosx/ttkMacOSXTheme.c:
	* macosx/tkMacOSXXCursors.r:
	* macosx/README:

	* macosx/GNUmakefile:		Fix/add copyright and license refs.
	* macosx/Tk-Info.plist.in:
	* macosx/Wish-Info.plist.in:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/project.pbxproj:
	* macosx/tkMacOSX.h:

	* unix/configure.in: Install license.terms into Tk.framework; fix tk
	debug build detection.
	* unix/configure: autoconf-2.59

	* doc/colors.n:		Document new Mac OS X system colors.
	* doc/cursors.n:	Document new Mac OS X native cursors.
	* doc/font.n:		Document new Mac OS X 'menu' system font.
	* doc/wm.n:		Document new Mac OS X [wm attributes].
	* doc/ttk_image.n:	Fix 'make html' warning.
	* doc/canvas.n:		Fix nroff typo.

2007-04-21  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXBitmap.c, macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c, macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXCursor.c, macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c, macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c, macosx/tkMacOSXInit.c, macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c, macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c, macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c, macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c: Revert of commits from 2007-04-13 which broke
	the OS X build.

2007-04-17  Donal K. Fellows  <[email protected]>

	* generic/tkFont.c, generic/tkListbox.c, unix/tkUnixSelect.c:
	* win/ttkWinMonitor.c, win/ttkWinTheme.c, win/ttkWinXPTheme.c: Make
	the format of declarations much more standardized (removing K&R-isms
	and other things like that).

2007-04-13  Donal K. Fellows  <[email protected]>

	* macosx/tkMacOSXInt.h (LOG_MSG, LOG_ON_ERROR): Added macros to make
	the OSX code much less #ifdef-full.

2007-04-12  Jeff Hobbs  <[email protected]>

	* library/ttk/panedwindow.tcl (ttk::panedwindow::Press): handle Press
	triggering outside sash element boundaries.

2007-04-10  Joe English  <[email protected]>

	* win/ttkWinMonitor.c, win/ttkWinXPTheme.c: Re-sync with Tile codebase
	so patches can flow back and forth.

	* win/ttkWinXPTheme.c: Skip OS version test, should work on Vista/Aero
	now as well as XP. Fixes [Bug 1687299], thanks to George Petasis for
	tracking this down.

2007-03-21  Joe English  <[email protected]>

	* generic/ttk/ttkLayout.c(Ttk_BuildLayoutTemplate): BUGFIX: Nested
	TTK_GROUP nodes did not work unless they appeared at the end of the
	layout (and only by accident then).

2007-03-08  Joe English  <[email protected]>

	* tests/grid.test(grid-21.7): Reset wm geometry . and pack propagate .
	at end of test. 'pack propagate . 0' was causing cascading failures in
	subsequent tests. [Bug 1676770]

2007-03-07  Daniel Steffen  <[email protected]>

	* generic/tkMain.c (Tk_MainEx): Replicate macosx-specific code from
	TkpInit() that ensures the console window appears when wish is started
	from the OS X Finder (i.e. with stdin == /dev/null), jeffh's 2006-11-24
	change rendered the corresponding code in TkpInit() ineffective in wish
	because Tk_MainEx() sets tcl_interactive before calling TkpInit().

	* generic/ttk/ttkGenStubs.tcl (new): Add ttk-specific genstubs.tcl from
	* unix/Makefile.in (genstubs):  tile and run it from 'genstubs'
	target, restores ability to generate all of Tk's stub sources.

	* generic/ttk/ttkTreeview.c: #ifdef out unused declaration.

	* macosx/tkMacOSXDebug.c (TkMacOSXGetNamedDebugSymbol): Add fix for
	libraries loaded with a DYLD_IMAGE_SUFFIX.

	* macosx/Wish.xcodeproj/project.pbxproj: Ensure gcc version used by
	* macosx/Wish.xcodeproj/default.pbxuser: Xcode and configure/make are
	* macosx/Wish-Common.xcconfig:		 consistent and independent of
	gcc_select default and CC env var; fixes for Xcode 3.0.

	* unix/tcl.m4 (Darwin): s/CFLAGS/CPPFLAGS/ in macosx-version-min check.
	* unix/configure: autoconf-2.59

2007-02-25  Peter Spjuth  <[email protected]>

	* generic/tkUtil.c: Fixed grid anchor center problem in labelframes.
	* tests/grid.test:  [Bug 1545765]

2007-02-23  Jeff Hobbs  <[email protected]>

	* library/ttk/notebook.tcl (ttk::notebook::enableTraversal): OS X
	needs Option instead of Alt binding

2007-02-19  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4: use SHLIB_SUFFIX=".so" on HP-UX ia64 arch.
	* unix/configure: autoconf-2.59

	* library/tkfbox.tcl (::tk::IconList_Goto): avoid goto issues in empty
	dirs. [Bug 1662959]

2007-02-09  Joe Mistachkin  <[email protected]>

	* win/nmakehlp.c: Properly cleanup after nmakehlp, including the
	* win/makefile.vc: vcX0.pch file. Sync up fixed nmakehlp usage from
	Tcl.

2007-02-06  Joe English  <[email protected]>

	* library/ttk/ttk.tcl: Add no-op [package ifneeded] script for tile
	0.8.0, so that existing applications that use "package require tile"
	won't fail when run under Tk 8.5.

2007-02-04  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: Use gcc4's __attribute__((__visibility__("hidden"))) if
	available to define MODULE_SCOPE effective on all platforms.
	* unix/configure.in: add caching to -pipe check.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

2007-02-03  Joe Mistachkin  <[email protected]>

	* win/rules.vc: Fix platform specific file copy macros for downlevel
	Windows.
	* win/ttkWinMonitor.c: Windows portability support. Fix "noxp" build
	* win/ttkWinXPTheme.c: option handling and use GetWindowLongPtr and
	SetWindowLongPtr only when needed.

2007-02-02  Pat Thoyts  <[email protected]>

	* win/ttkWinXPTheme.c: Support IsAppThemed() call. This is what is
	used when theming is turned off just for an individual application.

2007-01-28  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj:   Extract build settings that
	* macosx/Wish.xcodeproj/default.pbxuser:   were common to multiple
	* macosx/Wish-Common.xcconfig (new file):  configurations into external
	* macosx/Wish-Debug.xcconfig (new file):   xcconfig files; add extra
	* macosx/Wish-Release.xcconfig (new file): configurations for building
	with SDKs; convert legacy jam-based 'Tk' target to native target with
	single script phase; correct syntax of build setting references to use
	$() throughout; remove unused tcltest sources from 'tktest' target.

	* macosx/README: Document new Wish.xcodeproj configurations; other
	minor updates/corrections.

	* generic/tk.h: Update location of version numbers in macosx files.

	* macosx/Wish.xcode/project.pbxproj: Restore 'tktest' target to working
	* macosx/Wish.xcode/default.pbxuser: order by replicating applicable
	changes to Wish.xcodeproj since 2006-07-20.

2007-01-25  Daniel Steffen  <[email protected]>

	* unix/tcl.m4: Integrate CPPFLAGS into CFLAGS as late as possible and
	move (rather than duplicate) -isysroot flags from CFLAGS to CPPFLAGS to
	avoid errors about multiple -isysroot flags from some older gcc builds.

	* unix/configure: autoconf-2.59

2007-01-19  Joe Mistachkin  <[email protected]>

	* win/makefile.vc: Properly build man2tcl.c for MSVC8.

2007-01-19  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: Remove libtommath defines.

	* unix/tcl.m4: Ensure CPPFLAGS env var is used when set. [Bug 1586861]
	(Darwin): add -isysroot and -mmacosx-version-min flags to CPPFLAGS when
	present in CFLAGS to avoid discrepancies between what headers configure
	sees during preprocessing tests and compiling tests.

	* unix/configure: autoconf-2.59

2007-01-11  Jeff Hobbs  <[email protected]>

	* unix/tkUnixEvent.c, library/msgs/es.msg: s/CRLF/LF/g

2007-01-11  Joe English  <[email protected]>

	* win/tcl.m4 (CFLAGS_WARNING): Remove "-Wconversion". This was removed
	from unix/tcl.m4 2004-07-16 but not from here.
	* win/configure: Regenerated.

2007-01-11  Joe English  <[email protected]>

	* generic/ttk/ttkManager.h, generic/ttk/ttk*.c: Revert addition of
	contravariant 'const' qualifiers, to keep in sync with Tile codebase
	(which must remain compatible with Tk 8.4).

2007-01-03  Jan Nijtmans  <[email protected]>

	* doc/ManageGeom.3,
	* generic/tk.decls,
	* generic/tk.h: Add const to 2nd parameter of Tk_ManageGeometry
	* generic/tkDecls.h: regenerated
	* generic/tkInt.h,
	* generic/tk*.c,
	* generic/ttk/ttk*.c: Added many "const" specifiers in implementation.

2007-01-02  Donal K. Fellows  <[email protected]>

	* xlib/*: Made the generic fake-X11 glue layer abide by the formatting
	rules of the core.

2006-12-31  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXFont.c: Fill-in TkpGetFontAttrsForChar (TIP #300).
	* macosx/ttkMacOSXTheme.c: Define a constant to make it compile on Mac
	OS X 10.3.

2006-12-28  Mo DeJong  <[email protected]>

	* tests/wm.test: Update wm attributes output so that tests pass after
	addition of -transparentcolor for Win32.

2006-12-26  Joe English  <[email protected]>

	* generic/ttk/ttkLabel.c: ImageElement clientData no longer needed.

2006-12-22  Donal K. Fellows  <[email protected]>

	* unix/tkUnixEvent.c (TkUnixDoOneXEvent): Made correct on AMD64 and
	other similar 64-bit systems where fd_mask is not 'unsigned int' in
	effect. [Bug 1522467]

	* library/msgs/es_ES.msg (removed):
	* library/msgs/es.msg: Fixed translation fault that was present in all
	Spanish-speaking locales. [Bug 1111213]

2006-12-19  Jeff Hobbs  <[email protected]>

	* win/tkWinButton.c (TkpDisplayButton): lint init. [Bug 1618604]

2006-12-19  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (Darwin): --enable-64bit: verify linking with 64bit -arch
	flag succeeds before enabling 64bit build.
	* unix/configure: autoconf-2.59

2006-12-18  Joe English  <[email protected]>

	* generic/ttk/ttkTreeview.c, library/ttk/treeview.tcl, doc/treeview.n:
	Added column '-stretch' and '-minwidth' options. Improved column drag
	and resize behavior. Added horizontal scrolling [Bug 1518650]. Row
	height and child indent specifiable on Treeview style. Decreased
	default row height, no default -padding. Use correct heading height
	[Bug 1163349]. Apply tag settings to tree item as well as to data
	columns [NOTE: 'tag configure' still buggy]. Fix off-by-one condition
	when moving nodes forward [Bug 1618142]
	* generic/ttk/ttkScroll.c (TtkScrollTo): Prevent overscroll [Bug
	1173434]
	* library/ttk/altTheme.tcl, library/ttk/aquaTheme.tcl,
	* library/ttk/clamTheme.tcl, library/ttk/classicTheme.tcl,
	* library/ttk/defaults.tcl, library/ttk/winTheme.tcl,
	* library/ttk/xpTheme.tcl: Per-theme treeview settings.
	* macosx/ttkMacOSXTheme.c: Added disclosure triangle element.

2006-12-17  Joe English  <[email protected]>

	* library/ttk/combobox.tcl, generic/ttk/ttkEntry.c,
	* doc/ttk_combobox.n: Add combobox -height option; only show scrollbar
	if the listbox needs to scroll. [Bug 1032869]

2006-12-16  Mo DeJong  <[email protected]>

	* doc/cursors.n: Mention "none" in supported cursor list. Fix comment
	that incorrectly claims that the Win32 "no" cursor hides the cursor.
	* tests/cursor.test: Test "none" cursor.
	* unix/tkUnixCursor.c (CreateCursorFromTableOrFile)
	(TkGetCursorByName): Define a table of Tk cursors that is searched in
	addition to the X cursor table. A Tk cursor is loaded from a data
	string and works with the same options as the built in X cursors. This
	code makes it possible to use "none" as a cursor name under Unix.
	* win/rc/cursor9a.cur: Added none Win32 cursor.
	* win/rc/tk_base.rc: Define a built-in Win32 cursor named "none".
	[Patch 1615427]

2006-12-14  Joe English  <[email protected]>

	* generic/ttk/ttkButton.c, generic/ttk/ttkElements.c,
	* generic/ttk/ttkEntry.c, generic/ttk/ttkFrame.c,
	* generic/ttk/ttkImage.c, generic/ttk/ttkInit.c,
	* generic/ttk/ttkLabel.c, generic/ttk/ttkNotebook.c,
	* generic/ttk/ttkPanedwindow.c, generic/ttk/ttkProgress.c,
	* generic/ttk/ttkScale.c, generic/ttk/ttkScrollbar.c,
	* generic/ttk/ttkSeparator.c, generic/ttk/ttkTheme.h,
	* generic/ttk/ttkTreeview.c, generic/ttk/ttkWidget.h:
	Global reduction: use per-file *_Init() routines to reduce the number
	of globally-visible initialization records.

2006-12-13  Jeff Hobbs  <[email protected]>

	* unix/Makefile.in (install-doc): intentionally skip ttk_dialog.n
	installation (not for public consumption)

	* doc/scrollbar.n, doc/button.n, doc/checkbutton.n:
	* doc/entry.n, doc/frame.n, doc/label.n, doc/labelframe.n:
	* doc/menu.n, doc/menubutton.n, doc/panedwindow.n:
	* doc/radiobutton.n, doc/scrollbar.n, doc/ttk_*: revamp ttk docs to
	use consist nroff format (not 100% consistent with classic widget
	docs). Add more man page cross-linking "SEE ALSO".

	* generic/ttk/ttkInit.c:
	* generic/ttk/ttkTreeview.c: make treeview exist by default
	* generic/ttk/ttkPanedwindow.c: s/TtkPaned_Init/TtkPanedwindow_Init/

	* win/Makefile.in, unix/Makefile.in (demo): add 'demo' target

2006-12-13  Joe English  <[email protected]>

	* library/ttk/ttk.tcl: Try to straighten out theme loading and
	selection logic.
	* generic/ttk/ttkElements.c, library/ttk/defaults.tcl,
	* generic/ttk/ttkClamTheme.c, library/ttk/clamTheme.tcl:
	Provide package in C part instead of Tcl part.

2006-12-12  Joe English  <[email protected]>

	* library/ttk/ttk.tcl, generic/ttkTheme.c: Remove nonfunctional code.

2006-12-12  Mo DeJong  <[email protected]>

	* win/tkWinButton.c (InitBoxes): Call Tcl_Panic() if loading of bitmap
	resources fails. This change generates an error if Tk is unable to
	find button widget resources instead of silently failing and then
	drawing widgets incorrectly.
	* win/rc/tk_base.rc: If the user defines BASE_NO_TK_ICON then compile
	the base resources file without a "tk" icon. This change makes it
	easier to replace the default tk icon with a custom icon. [Patch
	1614362]

2006-12-11  Donal K. Fellows  <[email protected]>

	* unix/tkUnixWm.c (TkWmMapWindow, WmClientCmd): Added support for
	_NET_WM_PID property from the EWMH spec. This is only installed when
	the client machine is set.
	(WmProtocolCmd, UpdateWmProtocols, TkWmProtocolEventProc): Added
	support for the _NET_WM_PING protocol from the EWMH spec. Note that
	the support for this is not exposed to the script level as that would
	prevent correct handling.

2006-12-10  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.h, generic/ttk/ttkThemeInt.h,
	* generic/ttk/ttk.decls, generic/ttk/ttkTheme.c,
	* generic/ttk/ttkLayout.c, generic/ttk/ttkDecls.h:
	Rename typedef Ttk_Element => Ttk_ElementImpl.

2006-12-09  Joe English  <[email protected]>

	* generic/ttk/ttkButton.c, generic/ttk/ttkImage.c,
	* generic/ttk/ttkLabel.c, generic/ttk/ttkWidget.h,
	* generic/ttk/ttkTheme.h, generic/ttk/ttkNotebook.c,
	* generic/ttk/ttkTreeview.c, doc/ttk_image.n:
	Merged duplicate functionality between image element factory, image
	element, and -image option processing. Image element factory now takes
	an imageSpec argument instead of a separate image name and -map option
	* tests/ttk/image.test(image-1.1): Can catch this error earlier now.

2006-12-06  Kevin Kenny  <[email protected]>

	* unix/configure.in: Further changes to avoid attempting to link
	* unix/configure:   against Xft libraries in a non-Xft build
	         [Bug 1609616] (dgp)

2006-12-04  Jeff Hobbs  <[email protected]>

	* generic/tkListbox.c (ConfigureListboxItem): ListboxWorldChanged not
	needed - just call EventuallyRedrawRange. [Bug 1608046] (rezic)

2006-12-04  Donal K. Fellows  <[email protected]>

	TIP #286 IMPLEMENTATION

	* generic/tkMenu.c (MenuWidgetObjCmd, MenuDoXPosition):
	* doc/menu.n, tests/menu.test: Added an [$menu xposition] subcommand
	which is useful in menubars and when menus use multiple columns. Many
	thanks to Schelte Bron for the implementation.

2006-12-01  Kevin Kenny  <[email protected]>

	TIP #300 IMPLEMENTATION

	* doc/font.n:			Added a [font actual $font $char]
	* generic/tkFont.c:		variant that introspects the font that
	* generic/tkFont.h:		is chosen to render a given character
	* macosx/tkMacOSXFont.c:	in a given nominal font. Added
	* tests/font.test:		documentation and test cases for the
	* unix/tkUnixFont.c:		new command syntax.
	* unix/tkUnixRFont.c:
	* win/tkWinFont.c:

2006-12-01  Jeff Hobbs  <[email protected]>

	* doc/wm.n, tests/winWm.test:
	* win/tkWinWm.c: add -transparentcolor attribute for Windows.

2006-12-01  Joe English  <[email protected]>

	* generic/ttk/ttkTheme.h, generic/ttk/ttkLayout.c: Dead code removal.

2006-11-30  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDialog.c (Tk_MessageBoxObjCmd): fix inability to use
	buttons with standard Escape key binding as -default button (reported
	on tcl-mac by Hans-Christoph Steiner).

	* macosx/tkMacOSXWm.c (WmAttributesCmd): fix getting [wm attr -alpha].
	[Bug 1581932]

2006-11-28  Joe English  <[email protected]>

	* library/ttk/fonts.tcl: Clean up temporary variables.

2006-11-27  Kevin Kenny  <[email protected]>

	* unix/configure.in: Corrected Xft configuration so that Xft actually
	does get turned on when available.
	* unix/configure: autoconf

2006-11-26  Joe English  <[email protected]>

	* generic/ttk/ttkWidget.c, generic/ttk/ttkPaned.c: Fix [Bug 1603506]
	* library/ttk/button.tcl, library/ttk/combobox.tcl,
	* library/ttk/utils.tcl: Rename ttk::CopyBindings to ttk::copyBindings
	* generic/ttk/ttkTreeview.c, doc/ttk_treeview.n:
	-displaycolumns {} now means "no columns" instead of "all columns".
	Use -displaycolumns #all for "all columns". [Bug 1547622]

2006-11-26  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (Linux): --enable-64bit support.	[Patch 1597389]
	* unix/configure: autoconf-2.59			[Bug 1230558]

2006-11-24  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXInit.c (TkpInit): only set tcl_interactive 1 if it
	isn't already defined. Allows embedders to set it to 0 to prevent the
	console appearing on OS X. [Bug 1487701]

	* unix/tkUnixMenu.c (DrawMenuUnderline): bound Tcl_UtfAtIndex usage
	* tests/menu.test (menu-36.1): [Bug 1599877]

2006-11-24  Joe English  <[email protected]>

	* library/ttk/altTheme.tcl, library/ttk/clamTheme.tcl,
	* library/ttk/defaults.tcl, library/ttk/winTheme.tcl,
	* library/ttk/xpTheme.tcl: explicitly specify -anchor w on TMenubutton
	* tests/ttk/entry.test: Fixed font dependency; test entry-3.2 should
	work on all platforms now.
	* library/classicTheme.tcl: Don't define or use TkClassicDefaultFont.
	* generic/ttk/ttkTreeview.c, generic/ttk/ttkPanedwindow.c: Handle
	missing layouts.

2006-11-23  Jeff Hobbs  <[email protected]>

	* win/tkWinMenu.c (TkWinHandleMenuEvent, DrawMenuUnderline): Handle
	unichar underlining correctly and safely. [Bug 1599877]

2006-11-20  Joe English  <[email protected]>

	* win/ttkWinXPTheme.c: Add support for alternate/indeterminate
	checkbutton state. Fix various spacing parameters [Bug 1596020, patch
	from Tim Baker]. Remove unused uxtheme hooks.

2006-11-16  Donal K. Fellows  <[email protected]>

	* doc/colors.n, doc/wm.n: Minor fixes, added See Also.

	* doc/labelframe.n: Added an example.

2006-11-15  Donal K. Fellows  <[email protected]>

	* doc/label.n: Added an example and some See Also refs.

	* doc/ConfigWidg.3, doc/bind.n, doc/grid.n, doc/panedwindow.n:
	* doc/text.n, doc/ttk_Geometry.3, doc/ttk_button.n:
	* doc/ttk_checkbutton.n, doc/ttk_combobox.n, doc/ttk_dialog.n:
	* doc/ttk_entry.n, doc/ttk_frame.n, doc/ttk_image.n, doc/ttk_intro.n:
	* doc/ttk_label.n, doc/ttk_labelframe.n, doc/ttk_menubutton.n:
	* doc/ttk_notebook.n, doc/ttk_panedwindow.n, doc/ttk_progressbar.n:
	* doc/ttk_radiobutton.n, doc/ttk_scrollbar.n, doc/ttk_separator.n:
	* doc/ttk_sizegrip.n, doc/ttk_style.n, doc/ttk_widget.n, doc/wm.n:
	Convert \fP to \fR so that man-page scrapers have an easier time.

2006-11-14  Joe English  <[email protected]>

	* generic/ttk/ttkDefaultTheme.c: Fix off-by-one bug in tree indicator
	size computation [Bug 1596021, patch from Tim Baker]. Increased
	default size from 7 to 9 pixels.

2006-11-12  Joe English  <[email protected]>

	* generic/ttkScroll.c: *correct* fix for [Bug 1588251].

2006-11-12  Joe English  <[email protected]>

	* tests/ttk/ttk.test(ttk-6.9): Workaround for [Bug 1583038]

2006-11-12  Joe English  <[email protected]>

	* generic/ttkScroll.c: Reworked cleanup procedure; "self-cancelling"
	idle call is not robust, call Tcl_CancelIdleCall() in
	TtkFreeScrollHandle instead. Fixes [Bug 1588251]

2006-11-10  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: remove tclParseExpr.c and
	bwidget.test.

	* unix/tcl.m4 (Darwin): suppress linker arch warnings when building
	universal for both 32 & 64 bit and no 64bit CoreFoundation is
	available; sync with tcl tcl.m4 change.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

2006-11-08  Kevin Kenny  <[email protected]>

	* unix/configure.in: Silenced warnings about missing Xft configuration
	unless --enable-xft is requested explicitly. Also added a few basic
	checks that we can actually compile and link against Xft headers and
	libraries. [Bug 1592667]
	* unix/configure: Regen.

2006-11-07  Kevin Kenny  <[email protected]>

	* unix/configure.in: Made --enable-xft the default.
	* unix/configure: Regen.

2006-11-06  Joe English  <[email protected]>

	* generic/ttk/ttkClassicTheme.c, generic/ttk/ttkPanedwindow.c,
	* generic/ttk/ttkTheme.c, generic/ttk/ttkTreeview.c,
	* win/ttkWinXPTheme.c, library/ttk/entry.tcl,
	* library/ttk/notebook.tcl, library/ttk/panedwindow.tcl,
	* library/ttk/utils.tcl, tests/ttk/entry.test, tests/ttk/bwidget.test:
	Miscellaneous minor changes to re-sync Ttk codebase with Tile CVS: fix
	comments damaged by overzealous search-and-destroy; removed obsolete
	[style default] synonym for [ttk::style configure]; removed other dead
	code.

2006-11-03  Pat Thoyts  <[email protected]>

	* library/safetk.tcl (::safe::tkTopLevel): Theme it.

	* generic/ttk/ttkLayout.c:   We do not want to require tkInt in all
	* generic/ttk/ttkMananager.h:  the ttk files so added the definition
	* generic/ttk/ttkTheme.h:   of MODULE_SCOPE to ttkTheme.h. Ensures
	* generic/ttk/ttkWinMonitor.c: everyone gets to see the definition
	from someplace.

	* library/ttk/fonts.tcl: In a safe interp there is no osVersion field
	in tcl_platform so work around it.

2006-11-02  Daniel Steffen  <[email protected]>

	* generic/ttk/ttkBlink.c, generic/ttk/ttkButton.c:
	* generic/ttk/ttkClamTheme.c, generic/ttk/ttkClassicTheme.c:
	* generic/ttk/ttkDecls.h, generic/ttk/ttkDefaultTheme.c:
	* generic/ttk/ttkElements.c, generic/ttk/ttkEntry.c:
	* generic/ttk/ttkFrame.c, generic/ttk/ttkImage.c:
	* generic/ttk/ttkInit.c, generic/ttk/ttkLabel.c:
	* generic/ttk/ttkLayout.c, generic/ttk/ttkManager.h:
	* generic/ttk/ttkNotebook.c, generic/ttk/ttkPanedwindow.c:
	* generic/ttk/ttkProgress.c, generic/ttk/ttkScale.c:
	* generic/ttk/ttkScroll.c, generic/ttk/ttkScrollbar.c:
	* generic/ttk/ttkSeparator.c, generic/ttk/ttkSquare.c:
	* generic/ttk/ttkStubInit.c, generic/ttk/ttkStubLib.c:
	* generic/ttk/ttkTheme.c, generic/ttk/ttkTheme.h:
	* generic/ttk/ttkThemeInt.h, generic/ttk/ttkTrack.c:
	* generic/ttk/ttkTreeview.c, generic/ttk/ttkWidget.c:
	* generic/ttk/ttkWidget.h, macosx/ttkMacOSXTheme.c:
	* win/ttkWinMonitor.c, win/ttkWinTheme.c, win/ttkWinXPTheme.c: ensure
	all global Ttk symbols have Ttk or ttk prefix; declare all externally
	visible Ttk symbols not contained in stubs table as MODULE_SCOPE (or as
	static when possible); so that 'make check{exports,stubs}' once again
	complete without errors.

	* macosx/tkMacOSXColor.c (TkMacOSXCompareColors): ifdef out when unused

	* macosx/Wish.xcodeproj/project.pbxproj: check autoconf/autoheader exit
	status and stop build if they fail.

	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): fix handling of
	Carbon Update events: the QuickDraw window update region was being
	ignored and all child TkWindows were sent an Expose XEvent even when
	they did not need to be redrawn. [Patch 1589226]

2006-11-01  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDebug.c: add TkMacOSX prefix to leftover
	* macosx/tkMacOSXDebug.h: macosx-private global symbols without Tk
	* macosx/tkMacOSXEmbed.c: prefix; ifdef out currently unused debug
	* macosx/tkMacOSXEvent.c: procs.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

2006-10-31  Pat Thoyts  <[email protected]>

	* win/makefile.vc: Added ttk files to msvc build and add manifest
	* win/rules.vc: files to binaries with MSVC8.

2006-10-31  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcodeproj/project.pbxproj: add new Ttk files.

	* macosx/ttkMacOSXTheme.c: standardize header #includes.

	* unix/Makefile (checkstubs, checkexports): check ttk.decls, allow
	export of Ttk prefixed symbols.

	* generic/ttk/tkDefaultTheme.c: fix warnings.

2006-10-30  Jeff Hobbs  <[email protected]>

	* doc/ttk_Geometry.3, doc/ttk_Theme.3, doc/ttk_button.n:
	* doc/ttk_checkbutton.n, doc/ttk_combobox.n, doc/ttk_dialog.n:
	* doc/ttk_entry.n, doc/ttk_frame.n, doc/ttk_image.n:
	* doc/ttk_intro.n, doc/ttk_label.n, doc/ttk_labelframe.n:
	* doc/ttk_menubutton.n, doc/ttk_notebook.n, doc/ttk_panedwindow.n:
	* doc/ttk_progressbar.n, doc/ttk_radiobutton.n, doc/ttk_scrollbar.n:
	* doc/ttk_separator.n, doc/ttk_sizegrip.n, doc/ttk_style.n:
	* doc/ttk_treeview.n, doc/ttk_widget.n,:
	* generic/ttk/ttk.decls, generic/ttk/ttkBlink.c:
	* generic/ttk/ttkButton.c, generic/ttk/ttkCache.c:
	* generic/ttk/ttkClamTheme.c, generic/ttk/ttkClassicTheme.c:
	* generic/ttk/ttkDecls.h, generic/ttk/ttkDefaultTheme.c:
	* generic/ttk/ttkElements.c, generic/ttk/ttkEntry.c:
	* generic/ttk/ttkFrame.c, generic/ttk/ttkImage.c:
	* generic/ttk/ttkInit.c, generic/ttk/ttkLabel.c:
	* generic/ttk/ttkLayout.c, generic/ttk/ttkManager.c:
	* generic/ttk/ttkManager.h, generic/ttk/ttkNotebook.c:
	* generic/ttk/ttkPanedwindow.c, generic/ttk/ttkProgress.c:
	* generic/ttk/ttkScale.c, generic/ttk/ttkScroll.c:
	* generic/ttk/ttkScrollbar.c, generic/ttk/ttkSeparator.c:
	* generic/ttk/ttkSquare.c, generic/ttk/ttkState.c:
	* generic/ttk/ttkStubInit.c, generic/ttk/ttkStubLib.c:
	* generic/ttk/ttkTagSet.c, generic/ttk/ttkTheme.c:
	* generic/ttk/ttkTheme.h, generic/ttk/ttkThemeInt.h:
	* generic/ttk/ttkTrace.c, generic/ttk/ttkTrack.c:
	* generic/ttk/ttkTreeview.c, generic/ttk/ttkWidget.c:
	* generic/ttk/ttkWidget.h:
	* library/demos/ttk_demo.tcl, library/demos/ttk_iconlib.tcl:
	* library/demos/ttk_repeater.tcl:
	* library/ttk/altTheme.tcl, library/ttk/aquaTheme.tcl:
	* library/ttk/button.tcl, library/ttk/clamTheme.tcl:
	* library/ttk/classicTheme.tcl, library/ttk/combobox.tcl:
	* library/ttk/cursors.tcl, library/ttk/defaults.tcl:
	* library/ttk/dialog.tcl, library/ttk/entry.tcl:
	* library/ttk/fonts.tcl, library/ttk/icons.tcl:
	* library/ttk/keynav.tcl, library/ttk/menubutton.tcl:
	* library/ttk/notebook.tcl, library/ttk/panedwindow.tcl:
	* library/ttk/progress.tcl, library/ttk/scale.tcl:
	* library/ttk/scrollbar.tcl, library/ttk/sizegrip.tcl:
	* library/ttk/treeview.tcl, library/ttk/ttk.tcl:
	* library/ttk/utils.tcl, library/ttk/winTheme.tcl:
	* library/ttk/xpTheme.tcl:
	* macosx/ttkMacOSXTheme.c:
	* tests/ttk/all.tcl, tests/ttk/bwidget.test, tests/ttk/combobox.test:
	* tests/ttk/entry.test, tests/ttk/image.test:
	* tests/ttk/labelframe.test, tests/ttk/layout.test:
	* tests/ttk/misc.test, tests/ttk/notebook.test:
	* tests/ttk/panedwindow.test, tests/ttk/progressbar.test:
	* tests/ttk/scrollbar.test, tests/ttk/treetags.test:
	* tests/ttk/treeview.test, tests/ttk/ttk.test, tests/ttk/validate.test:
	* win/ttkWinMonitor.c, win/ttkWinTheme.c, win/ttkWinXPTheme.c:
	First import of Ttk themed Tk widgets as branched from tile 0.7.8

	* generic/tkInt.h, generic/tkWindow.c: add Ttk_Init call, copy tk
	classic widgets to ::tk namespace.
	* library/tk.tcl: add source of ttk/ttk.tcl, define $::ttk::library.
	* unix/Makefile.in, win/Makefile.in: add Ttk build bits
	* win/configure, win/configure.in: check for uxtheme.h (XP theme).

2006-10-23  Don Porter  <[email protected]>

	* README:		Bump version number to 8.5a6
	* generic/tk.h:
	* library/tk.tcl:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2006-10-19  Pat Thoyts  <[email protected]>

	*** 8.5a5 TAGGED FOR RELEASE ***

	* generic/tkImgBmap.c: Fixed line endings.
	* win/makefile.vc:  Patched up build system to manage
	* win/rules.vc:  AMD64 with MSVC8
	* win/nmakehlp.c:   Ensure operation without Platform SDK.

2006-10-18  Don Porter  <[email protected]>

	* changes:		8.5a5 release date set.

2006-10-17  Jeff Hobbs  <[email protected]>

	* doc/text.n: fix docs to not correct -tabs usage case.

	* generic/tkTextDisp.c (SizeOfTab): fix -tabstyle wordprocessor tab
	alignment to correct tab edge case. [Bug 1578858]

2006-10-17  Pat Thoyts  <[email protected]>

	* generic/tkText.c: Applied suggested patch from [Bug 1536735]
	* tests/text.test:  Update test for above patch.
	* tests/textWind.test:  Corrected test to catch all messages
	* tests/safe.test: Silence spurious win32 failure awaiting TIP150
	* tests/winDialog.test: Updated test for file name length check.
	* test/winWm.test: Corrected test expectation for menu wrapping.

2006-10-16  Andreas Kupries  <[email protected]>

	* doc/WindowId.3: Pat's commit on 2006-10-08 broke the .SH NAME
	information across several lines, breaking the cross-linking of
	manpages during installation for this one. Put everything back on a
	single line, unbreaking it.

2006-10-16  Daniel Steffen  <[email protected]>

	* changes: updates for 8.5a5 release.

	* macosx/tkMacOSXDraw.c: fix numerous issues in CG and QD drawing
	procs so that they now match X11 drawing much more closely [Bug
	1558051]; use Tiger ellipse drawing API when available; fix comments &
	whitespace.

	* macosx/tkMacOSXInit.c: set default linewidth limit for CG
	antialiasing to 0 as thin horizontal/vertical lines look good now.
	* macosx/README: document CG antialiasing limit changes.

	* generic/tkCanvLine.c (ConfigureLine):  on TkAqua, pass outline
	* generic/tkCanvPoly.c (ConfigurePolygon):  linewidth in gc even for
	* generic/tkRectOval.c (ConfigureRectOval): fills (as it controls AA).

	* macosx/GNUmakefile: don't redo prebinding of non-prebound binaires.

	* library/demos/pendulum.tcl: fix incorrect setting of toplevel title.

2006-10-10  Don Porter  <[email protected]>

	* changes:	Updates for 8.5a5 release

2006-10-08  Pat Thoyts  <[email protected]>

	* generic/tkWindow.c:  Implemented TIP #264 - Tk_Interp function.
	* doc/WindowId.3:   Documented Tk_Interp.
	* generic/tk.decls: Added to the stubs interface and
	* generic/tkDecls.h:   regenerated.
	* generic/tkStubsInit.c:

2006-10-05  Jeff Hobbs  <[email protected]>

	* unix/tkUnixFont.c (Ucs2beToUtfProc, UtfToUcs2beProc):
	(TkpFontPkgInit, encodingAliases): Correct alignment issues in
	encoding conversion. Call ucs-2be "unicode" on big-endian systems.
	[Bug 1122671]

2006-09-27  Andreas Kupries  <[email protected]>

	* unix/Makefile.in (install-binaries): Added a second guard to the
	* win/Makefile.in: package index file to prevent older versions of Tcl
	* win/makefile.vc: from seeing version numbers which may contain a/b
	information, and then balking on them. This could otherwise happen
	when Tcl/Tk 8.4 and 8.5 are installed in the same directory, seeing
	each other. [Bug 1566418]

2006-09-22  Andreas Kupries  <[email protected]>

	* generic/tkConsole.c: TIP #268 update regarding registered package
	* generic/tkMain.c: version, now using full patchlevel instead of
	* generic/tkWindow.c:  major.minor
	* library/tk.tcl:
	* unix/configure:
	* unix/Makefile.in:
	* unix/tcl.m4:
	* win/configure:
	* win/Makefile.in:
	* win/makefile.vc:
	* win/rules.vc:
	* win/tcl.m4:

2006-09-20  Jeff Hobbs  <[email protected]>

	* win/tkWinMenu.c (TkpPostMenu): disable menu animation in menus with
	images to avoid clipping bug. [Bug 1329198]

2006-09-21  Donal K. Fellows  <[email protected]>

	* generic/tkImgBmap.c (ImgBmapPostscript): Change 0 to NULL, since
	they are not interchangable on all platforms in all circumstances.
	[Tcl Bug 1562528]

2006-09-11  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (TkMacOSXMakeRealWindowExist): revert part of
	2006-05-16 change that had set overrideredirect windows to not become
	activated by the window manager, as this prevented interaction with
	native widgets in such windows [Bug 1472624]; apply changes to carbon
	window attributes even if native window has already been created.

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): fix app
	* macosx/tkMacOSXMenu.c (DrawMenuBarWhenIdle): menu item key shortcuts
	* macosx/tkMacOSXInt.h: when custom ".apple" menu is installed.

	* library/demos/widget: on TkAqua, don't install file menu with single
	quit menu item, as the application menu already has a quit item.

	* macosx/tkMacOSXColor.c: fix building on Mac OS X 10.2.

2006-09-10  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXColor.c (TkSetMacColor,TkpGetColor): use AppearanceMgr
	* macosx/tkMacOSXDefault.h: to retrieve platform std colors for text
	* macosx/tkMacOSXPort.h:    selections, add "systemHighlightSecondary"
	color name for standard color of inactive selections, use this color as
	default for text widget -inactiveselectbackground to implement platform
	standard look for inactive text selections.

	* library/text.tcl (aqua): remove focus bindings to set selection color

	* generic/tkTextBTree.c (TkTextIsElided): on TkAqua, don't show
	* generic/tkTextDisp.c (GetStyle):   inactive text selection when
						  text widget is disabled.

	* generic/tkEntry.c (DisplayEntry): change default TkAqua selection
	* macosx/tkMacOSXDefault.h:     relief to "flat" (platform std).

	* generic/tkText.c (CreateWidget): fix bug leading to default text
	selection relief string DEF_TEXT_SELECT_RELIEF being ignored.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): allow mouse
	event delivery to background windows with kWindowNoActivatesAttribute
	(e.g. overrideredirect windows), as these never come to the foreground
	they would never receive any mouse events otherwise. [Bug 1472624]

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): do not
	send focus events to any windows with kWindowNoActivatesAttribute.

	* macosx/tkMacOSXXStubs.c (XQueryColor, XQueryColors): implement basic
	XColor computation from pixel values, enough to make tkImg's window.c
	happy, fixes img::window failures reported on tcl-mac.

	* macosx/tkMacOSXMenu.c (DrawMenuEntryLabel): fix leak. [Bug 1554672]

	* macosx/GNUmakefile: workaround bug in 'cp -pRH' on Darwin 6 and
	earlier, fixes 'make embedded' failure reported on tcl-mac; fix error
	from 'make deploy' with same build tree as previous 'make embedded'.

	* macosx/Wish.xcodeproj/project.pbxproj: add new tclUnixCompat.c file.

	* macosx/tkMacOSXEntry.c (TkpDrawEntryBorderAndFocus): fix typo.

	* unix/tcl.m4: sync with tcl/unix/tcl.m4.
	* unix/configure: autoconf-2.59

2006-09-06  Jeff Hobbs  <[email protected]>

	* generic/tkEntry.c:   move hard-coded ALWAYS_SHOW_SELECTION control
	* generic/tkInt.h:   of entry/text selection display based on focus
	* generic/tkText.c: to the Tcl level, controlled by
	* generic/tkWindow.c:  ::tk::AlwaysShowSelection (boolean, private).
	* library/tk.tcl:   [Bug 1553691]
	* macosx/tkMacOSXDefault.h:
	* unix/tkUnixDefault.h:
	* unix/tkUnixPort.h:
	* win/tkWinDefault.h:

2006-08-30  Jeff Hobbs  <[email protected]>

	* win/tkWinKey.c: Add WM_UNICHAR window message support (used by
	* win/tkWinX.c:   virtual keyboard apps). [Bug 1518677] (petasis)

2006-08-24  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXScrlbr.c (UpdateControlValues): set native scrollbar
	control bounds only once all size adjustments have been computed.
	Fixes issue with grow icon obscuring scrollbar reported on tcl-mac.

2006-08-21  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXCarbonEvents.c (CarbonTimerProc): avoid starving main
	event loop: limit the number of tcl events processed per invocation.
	Fixes bug reported on tcl-mac by Kevan Hashemi.

2006-08-18  Donal K. Fellows  <[email protected]>

	* tests/text.test (text-25.15): Added test suggested by Sam
	<[email protected]> on comp.lang.tcl

	* generic/tk.h, generic/tkInt.h: Stylistic improvements. No API change.

2006-08-18  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (Darwin): add support for --enable-64bit on x86_64, for
	universal builds including x86_64, for 64-bit CoreFoundation on Leopard
	and for use of -mmacosx-version-min instead of MACOSX_DEPLOYMENT_TARGET
	* unix/configure.in (Darwin): remove 64-bit arch flags from CFLAGS for
	combined 32-bit and 64-bit universal builds, as neither TkAqua nor
	TkX11 can be built for 64-bit at present.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/Wish.xcodeproj/project.pbxproj: switch native release targets
	to use DWARF with dSYM, Xcode 3.0 changes.
	* macosx/README: updates for x86_64 support in Tcl.

	* macosx/tkMacOSXInit.c (TkpInit): when available, use public
	TransformProcessType() API instead of CPSEnableForegroundOperation()
	SPI to notify the window server that we are a GUI application.

	* macosx/tkMacOSXWm.c (WmAttrGetTitlePath): use HIWindow API on >=Tiger

	* macosx/tkMacOSXMouseEvent.c (GenerateToolbarButtonEvent):
	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent): bzero() the XVirtualEvent
	structure before use to ensure all fields are initialized. [Bug
	1542205]

2006-08-16  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXWm.c (WmAttributesCmd): correct OS X result for [wm
	attributes $top].

2006-07-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): handle key
	shortcut for kHICommandQuit in the same way as other application menu
	item key shortcuts. [Bug 1516950]

2006-07-24  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (TkWmMapWindow): fix incorrect values of wmInfo
	parentWidth/Height for toplevels by recalculating them once the window
	is mapped (i.e once the window&structure sizes are known). [Bug
	1358663]
	(ParseGeometry): sync with ParseGeometry in tkUnixWm.c/tkWinWm.c.

2006-07-21  Daniel Steffen  <[email protected]>

	* generic/tkBind.c (TkBindInit): for REDO_KEYSYM_LOOKUP, change
	keysym-to-string mapping hash to use first name in ks_names.h instead
	of last (if there are multiple possibilities), e.g. "F11" instead of
	"L1".

	* macosx/tkMacOSXKeyboard.c (TkpGetKeySym): correct keysyms for pure
	modifier key presses [Bugs 700311, 1525905]; correct keysym for Enter
	key; add keysyms for new NumLock and Fn modifiers (added 2005-08-09).

2006-07-20  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (WmAttributesCmd, WmIconbitmapCmd): add support
	* unix/tkUnixSend.c (Tk_GetUserInactiveTime):       for weakly
	importing symbols not available on OSX 10.2 or 10.3, enables binaires
	built on later OSX versions to run on earlier ones.
	* macosx/Wish.xcodeproj/project.pbxproj: enable weak-linking; turn on
	                 extra warnings.
	* macosx/README: document how to enable weak-linking; cleanup.
	* unix/configure.in: add check on Darwin-X11 for ld support of -weak-l
	* unix/tcl.m4:  flag and weak-link libXss if possible as it is not
	available before OSX 10.4; enforce requirement of OSX 10.2 for TkAqua;
	move Darwin specific checks & defines that are only relevant to the tcl
	build out of tcl.m4; restrict framework option to Darwin; clean up
	quoting and help messages.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/GNUmakefile: enable xft for TkX11 build.
	* macosx/tkMacOSXFont.c (TkMacOSXQuarzStartDraw, TkMacOSXQuarzEndDraw):
	verify validity of context returned from QDBeginCGContext() before use.
	* macosx/tkMacOSXKeyEvent.c: ifdef out diagnostic messages to stderr.

	* macosx/tkMacOSXEvent.h:   standardize MAC_OS_X_VERSION_MAX_ALLOWED
	* macosx/tkMacOSXMenu.c:    checks per QA1316, ensure define can be
	* macosx/tkMacOSXMenubutton.c: overridden on command line (from default
	* macosx/tkMacOSXMenus.c:   of current OS version).
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:

	* generic/tkImgGIF.c (ReadImage):
	* macosx/tkMacOSXCursor.c (TkMacOSXCursor):
	* macosx/tkMacOSXDebug.c (TkMacOSXGetNamedDebugSymbol):
	* macosx/tkMacOSXFont.c (TkpMeasureCharsInContext):
	* macosx/tkMacOSXInit.c (Map):
	* xlib/xgc.c (XCreateGC): fix signed-with-unsigned comparison and other
	warnings from gcc4 -Wextra.

2006-07-14  Andreas Kupries  <[email protected]>

	* generic/tkWindow.c (Initialize): Modify change of 2006-05-25 (jeffh).
	Release mutex a bit earlier, to prevent lock when OS X creates its
	console windows (recursively enters Tk_Init). Patch by JeffH.

2006-07-06  Jeff Hobbs  <[email protected]>

	* library/tkfbox.tcl: catch scrollbar use of highlightthickness

2006-06-21  Jeff Hobbs  <[email protected]>

	* library/bgerror.tcl (::tk::dialog::error::bgerror): remove a couple
	of unnecessary hardcoded options

2006-06-14  Don Porter  <[email protected]>

	* generic/tkScale.c: Revised variable writing logic to account for
	[scale]'s design that it deals with its value as a formatted string,
	and not as a double. [Bug 891141]

2006-06-14  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXSubwindows.c (TkMacOSXInvalidateWindow): ensure
	invalid clip regions are recreated via TkMacOSXUpdateClipRgn() before
	they are used; correct call order of TkMacOSXInvalidateWindow() and
	TkMacOSXInvalClipRgns() throughout. [Bug 1501922]

	* macosx/tkMacOSXDraw.c (TkPutImage): implement drawing of very wide
	images in slices of less than 4096 pixels to workaround CopyBits
	limitation. [Bug 950121]

2006-06-09  Don Porter  <[email protected]>

	* generic/tkMain.c:	Added Tcl_Preserve() call on the master interp
	as crash protection against any Tcl_DeleteInterp() call that might
	happen.

2006-06-01  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Added Tcl_RegisterChannel() calls to bump the
	refcount of channels passed to Tcl_SetStdChannel(). This prevents early
	free-ing of the channels that leads to crashes. [Bug 912571]

2006-05-29  Jeff Hobbs  <[email protected]>

	* win/tkWinEmbed.c (TkpGetOtherWindow):   Do not panic if no window is
	* unix/tkUnixEmbed.c (TkpGetOtherWindow): found; caller handles. [Bug
	* unix/tkUnixWm.c (Tk_CoordsToWindow, UpdateGeometryInfo): 1212056]

	* tests/entry.test (entry-22.1):
	* tests/listbox.test (listbox-6.15):
	* generic/tkListbox.c (ListboxInsertSubCmd, ListboxDeleteSubCmd):
	Ignore Tcl_SetVar2Ex failure of listVarName, similar to entry widget
	handling. [Bug 1424513]

2006-05-26  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXButton.c (TkMacOSXDrawControl): correct redraw for
	direct transition from disabled to active state. [Bug 706446]

2006-05-25  Jeff Hobbs  <[email protected]>

	* win/tkWinMenu.c (TkWinMenuKeyObjCmd): get eventPtr after we know the
	window is still alive. [AS bug 45987] [Bug 1236306]

	* generic/tkMenu.c (DeleteMenuCloneEntries): Modify entry index
	changes to work around VC6 optimization bug. [Bug 1224330]

	* generic/tkMessage.c (MessageWidgetObjCmd): Correct msgPtr
	preserve/release pairing. [Bug 1485750] (afredd)

	* generic/tkWindow.c (Initialize): Correct mutex (un)lock pairing.
	[Bug 1479587] (loewis)

	* generic/tkBind.c (Tk_BindEvent, TkCopyAndGlobalEval): use Tcl_EvalEx
	instead of Tcl_GlobalEval.

2006-05-16  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): don't send
	focus events to windows of class help or to overrideredirect windows.
	[Bug 1472624]

	* macosx/tkMacOSXWm.c: set overrideredirect windows to not become
	activated by the window manager and to not receive OS activate events
	(should make them behave more like on other platforms); use modern
	window class API for overrideredirect and transient windows; set the
	default class of overrideredirect windows to 'simple' rather than
	'plain' (i.e. no window frame); add missing Panther and Tiger window
	attributes to [::tk::unsupported::MacWindowStyle].

2006-05-12  Jeff Hobbs  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock): Fix
	opt added 2006-03 that caused slowdown for some common cases. [Bug
	1409140]

2006-05-13  Daniel Steffen  <[email protected]>

	* generic/tkCanvWind.c (DisplayWinItem, WinItemRequestProc): ensure
	canvas window items are unmapped when canvas is unmapped. [Bug 940117]

	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn): empty clip
	region of unmapped windows to prevent any drawing into them or into
	their children from becoming visible. [Bug 940117]

	* macosx/tkMacOSXInt.h:     revert Jim's attempt of 2005-03-14 to
	* macosx/tkMacOSXSubwindows.c:  fix Bug 940117 as it disables Map/Unmap
	event propagation to children. [Bug 1480105]

	* macosx/tkMacOSXDraw.c (TkPutImage): handle tkPictureIsOpen flag,
	fixes incorrect positioning of images with complex alpha on native
	buttons; actual alpha blending is still broken in this situation. [Bug
	1155596]

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent):
	* macosx/tkMacOSXMenus.c (TkMacOSXInitMenus): workaround carbon bug
	with key shortcut for 'Preferences' app menu item. [Bug 1481503]

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only check
	for HICommand menu item shortcuts in the application menu.

	* macosx/tkMacOSXInt.h:    initialize keyboard layout setup in
	* macosx/tkMacOSXInit.c:     TkpInit() rather than during handling of
	* macosx/tkMacOSXKeyEvent.c:  first key down event.

	* macosx/tkMacOSXDraw.c:     add optional debug code to flash clip
	* macosx/tkMacOSXSubwindows.c:  regions during update or draw.

2006-05-04  Don Porter  <[email protected]>

	* README:		Bump version number to 8.5a5
	* generic/tk.h:
	* unix/configure.in:
	* unix/tk.spec:
	* win/configure.in:

	* unix/configure:	autoconf-2.59
	* win/configure:

2006-04-28  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (TkWmMapWindow, InitialWindowBounds): fix use of
	potentially stale window position in initial configure event on first
	map of a window. [Bug 1476443]
	(TkMacOSXWindowOffset): use modern GetWindowStructureWidths API.

	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMouseEvent.c (TkGenerateButtonEventForXPointer): new
	internal function to generate button events for current pointer
	directly, without requiring prior call to XQueryPointer().

	* macosx/tkMacOSXMouseEvent.c (XQueryPointer): implement return of
	window-local pointer position.

	* macosx/tkMacOSXInt.h:   use improvements above to avoid calls to
	* macosx/tkMacOSXKeyEvent.c: GlobalToLocal() when the current port
	* macosx/tkMacOSXMenu.c:    might not be set correctly. May fix [Bug
	* macosx/tkMacOSXMenus.c:   1243318]
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:

	* tkAboutDlg.r: update copyright.

	* macosx/tkMacOSXDebug.h: sync #includes with core-8-4-branch.
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:

2006-04-26  Don Porter  <[email protected]>

	*** 8.5a4 TAGGED FOR RELEASE ***

	* changes:	Updates for next RC

2006-04-25  Donal K. Fellows  <[email protected]>

	* unix/tkUnixFont.c (TkpGetFontFamilies): Fix crash caused when the
	XServer returns invalid font names. [Bug 1475865]

2006-04-23  Vince Darley  <[email protected]>

	* tests/scrollbar.test: fix to tkAqua test failures

2006-04-18  Vince Darley  <[email protected]>

	* macosx/tkMacOSXEmbed.c: fix to [Bug 1088814] test failures in
	embed.test

	* macosx/tkMacOSXWm.c:
	* tests/constraints.tcl:
	* tests/wm.test: fix to 'wm attributes' test for TkAqua

2006-04-11  Peter Spjuth  <[email protected]>

	* generic/tkWindow.c (Tk_NameToWindow): Allow NULL interp to
	Tk_NameToWindow. This fixes TkGetWindowFromObj which promises to handle
	NULL but didn't.

	* generic/tkGrid.c: Fixed handling of out of bounds row or column.
	* tests/grid.test:  [Bug 1432666]

2006-04-11  Don Porter  <[email protected]>

	* unix/Makefile.in:	Updated `make dist` target to be sure the
	message catalogs for the widget demo get packaged into the source code
	distribution. [Bug 1466509]

2006-04-11  Daniel Steffen  <[email protected]>

	* changes: added latest aqua bug fixes.

	* macosx/tkMacOSXDialog.c (Tk_MessageBoxObjCmd): added standard Escape
	key binding for msgbox cancel buttons [Patch 1193614], whitespace.

	* macosx/tkMacOSXCarbonEvents.c: handle kEventCommandUpdateStatus
	* macosx/tkMacOSXEvent.c:     carbon event to dynamically enable
	the 'Preferences' app menu item when proc [::tk::mac::ShowPreferences]
	is defined. [Bug 700316]

	* macosx/tkMacOSXHLEvents.c:    call ::tk::mac::* procs for all
	* macosx/tkMacOSXWindowEvent.c: registered appleevents [FR 1105284],
	implement print applevent handling, style/whitespace cleanup.

	* macosx/tkMacOSXDraw.c (TkMacOSXInitCGDrawing): prevent multiple init

	* macosx/tkMacOSXFont.c: remove #ifdef'd text measuring codepaths now
	* macosx/tkMacOSXInit.c: known to be incorrect, cleanup obsolete text
	* macosx/README:	 antialiasing control code, document ATSUI
				 text antialiasing changes.

	* macosx/tkMacOSXInt.h:     Implemented 'zoomed' window state
	* macosx/tkMacOSXWindowEvent.c: handling for TkAqua, via titlebar
	* macosx/tkMacOSXWm.c:     widget clicks as well as [wm state].
	* doc/wm.n:         [Bug 1073456]

2006-04-10  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (::tk::IconList_Goto): Fix prefix searching so
	that the start location is reasonable, and the prefix matching is
	using the correct Tcl command for this. [Bug 1467938]

2006-04-10  Benjamin Riefenstahl  <[email protected]>

	* macosx/tkMacOSXFont.c (MeasureStringWidth): Use implementation based
	on ATSUGetGlyphBounds (TK_MAC_USE_GETGLYPHBOUNDS), so we can use
	kATSUseFractionalOrigins. This in turn corrects [Bug 1461650].
	(InitFont): Use "." and "W" instead of "i" and "w" to determine the
	"-fixed" attribute. This prevents "Apple Chancery" from being
	classified as fixed.
	(InitFontFamilies): Only get the font families once.

2006-04-09  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (WmResizableCmd): propagate window attribute
	changes to Carbon window manager. [FR 1467004]
	(TkSetWMName, TkMacOSXMakeRealWindowExist): allow empty name for
	toplevels, remove bogus initial window name. [Bug 1450800]

2006-04-07  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): fix return
	values, implement window dragging & growing in background (with Command
	key down) and by fronting clicks [Bug 934524], use correct button &
	modifier state API when application is in background (also in
	TkMacOSXButtonKeyState).

	* macosx/tkMacOSXWm.c (TkMacOSXGrowToplevel): ensure QD port is set
	correctly before using API relying on it.

2006-04-06  Vince Darley  <[email protected]>

	* macosx/tkMacOSXMouseEvent.c: Now that [wm attributes -titlepath]
	works correctly, add OS support for dragging proxy icons and using the
	titlepath menu.

2006-04-06  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXWm.c (WmAttributesCmd, WmIconbitmapCmd): fix errors in
	setting/removing window proxy icons via [wm attributes -titlepath] and
	[wm iconbitmap], use HIWindow API on Tiger or later. [Bug 1455241]

	* unix/tcl.m4: remove TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
	define on Darwin. [Tcl Bug 1457515]
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

2006-04-05  Jeff Hobbs  <[email protected]>

	* generic/tkWindow.c (Initialize): remove impotent use of
	DeleteWindowsExitProc as a global exit handler.

	* generic/tkMenu.c (TkSetWindowMenuBar): remove extra TkMenuInit call
	that caused finalization panic. [Bug 1456851]
	* win/tkWinMenu.c (FreeID, TkpNewMenu, MenuExitHandler)
	(MenuThreadExitHandler, TkpMenuInit, TkpMenuThreadInit): rework Windows
	menu init/finalization to better respect per-process and per-thread
	boundaries. [Bug 1456851]
	(TkWinMenuKeyObjCmd): Do not error when unknown window is passed in.
	[Bug 1236306]

	* win/tkWinX.c (TkWinXInit): init default keyboard charset correctly.
	[Bug 1374119] (pajas)

	* win/tkWinWm.c (WmProc): pass WM_QUERYENDSESSION message to Tk as
	WM_SAVE_YOURSELF wm protocol callback.

	* tests/textWind.test (textWind-10.6.1): prevent infinite update loop
	in case of test failure.

	* tests/wm.test (wm-attributes-1.2.4): correct expected result.

	* tests/grid.test: fix segfault on empty or "all" index list
	* generic/tkGrid.c (GridRowColumnConfigureCommand): [Bug 1422430]

2006-04-05  Vince Darley  <[email protected]>

	* generic/tkText.c: fix to crash caused on some platforms by new tests
	introduced to check for [Bug 1414171], which destroy the text widget in
	the dump callback script.

2006-03-29  Jeff Hobbs  <[email protected]>

	* generic/tkOption.c (TkOptionDeadWindow): handle OptionThreadExitProc
	being called before DeleteWindowsExitProc.

	* win/Makefile.in: convert _NATIVE paths to use / to avoid ".\"
	path-as-escape issue.

2006-03-29  Don Porter  <[email protected]>

	* changes:	Updates for next RC

	* unix/tkUnixDefault.h: Changed "Black" to "#000000" and "White" to
	"#ffffff" to work around the (broken?) X servers that do not accept
	those color names. [Bug 917433]

2006-03-28  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4, win/tcl.m4: []-quote AC_DEFUN functions.

2006-03-26  Vince Darley  <[email protected]>

	* generic/tkText.c:
	* tests/text.test: Fix for elaborations of [Bug 1414171] for '$text
	dump -command <script>' where script deletes large portions of the
	text widget, or even destroys the widget.

2006-03-28  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcode/default.pbxuser:    add '-singleproc 1' cli arg to
	* macosx/Wish.xcodeproj/default.pbxuser: tktest to ease test debugging.

	* macosx/Wish.xcode/project.pbxproj:    removed $prefix/share from
	* macosx/Wish.xcodeproj/project.pbxproj: TCL_PACKAGE_PATH as per change
	to tcl/unix/configure.in of 2006-03-13.

	* macosx/tkMacOSXDraw.c:   sync whitespace & minor changes with
	* macosx/tkMacOSXEvent.h:  core-8-4-branch.
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXNotify.c:

2006-03-27  Don Porter  <[email protected]>

	* changes:	Updates for next RC

2006-03-27  Benjamin Riefenstahl  <[email protected]>

	* generic/tkTextDisp.c (MeasureChars): Fix calculations of start and
	end of string. [Bugs 1325998, 1456157]

2006-03-27  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c (FileReadGIF): Stop crashes when the first GIF
	frame does not define the overall size of the image. [Bug 1458234]

2006-03-26  Vince Darley  <[email protected]>

	* generic/tkText.c:
	* generic/tkText.h:
	* generic/tkTextBTree.c:
	* tests/text.test: Fix for [Bug 1414171] for '$text dump -command
	<script>' where 'script' actually modifies the widget during the
	process.

2006-03-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c (TkMacOSXSetUpCGContext):
	* macosx/tkMacOSXFont.c (TkMacOSXQuarzStartDraw, TkMacOSXQuarzEndDraw):
	performance improvements, sync similar code, formatting & whitespace.

2006-03-24  Daniel Steffen  <[email protected]>

	* generic/tkTextDisp.c:   Moved #ifdef MAC_OSX_TK code added by
	* macosx/tkMacOSXColor.c: [Patch 638966] into platform specific files.
	* macosx/tkMacOSXInt.h:

	* macosx/tkMacOSX.h:       Cleaned up & rationalized order of
	* macosx/tkMacOSXBitmap.c:  #includes of tk and carbon headers.
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:

2006-03-23  Reinhard Max  <[email protected]>

	* unix/tkUnixRFont.c (TkpMeasureCharsInContext): Copied over from
	tkUnixFont.c to fix compiling with --enable-xft .

	* unix/tk.spec: Cleaned up and completed. An RPM can now be built from
	the tk source distribution with "rpmbuild -tb <tarball>".

2006-03-23  Don Porter  <[email protected]>

	* tests/textDisp.test: Updated expected error messages to match the
	standardized formats established on 2005-11-17. [Bug 1370296]

2006-03-22  Don Porter  <[email protected]>

	* changes:	Updates for next RC

2006-03-21  Daniel Steffen  <[email protected]>

	* generic/tkFont.c:       implementation of ATSUI text rendering
	* generic/tkInt.h:      in TkAqua provided by Benjamin
	* generic/tkTextDisp.c:     Riefenstahl. [Patch 638966]
	* library/demos/unicodeout.tcl:
	* macosx/tkMacOSXFont.h (new file):
	* macosx/tkMacOSXFont.c:
	* tests/font.test:
	* unix/tkUnixFont.c:
	* win/tkWinFont.c:

	* generic/tkFont.c:       moved MODULE_SCOPE declarations of font
	* generic/tkFont.h:       helper procs into header files.
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXMenubutton.c:

	* macosx/Wish.xcode/project.pbxproj:    add new tkMacOSXFont.h file,
	* macosx/Wish.xcodeproj/project.pbxproj: turn off dead code stripping
	as it interferes with -sectcreate (rdar://4486223).

	* macosx/Wish.xcode/default.pbxuser:    add TCLLIBPATH=/Library/Tcl
	* macosx/Wish.xcodeproj/default.pbxuser: env var setting to tktest.

	* unix/configure.in: fix detection of symbols build when enabling
	TkAqua debug code; filter nm output of libtclstub better to avoid
	error on intel macs. [Bug 1415789]
	* unix/configure: autoconf-2.59

2006-03-20  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Added exit handler to clean up the interp where
	the console window lives. Also added code to handle multiple calls to
	Tk_CreateConsoleWindow so that the console channels connect to the last
	console window opened, in compatibility with the previous
	implementation.

2006-03-18  Vince Darley  <[email protected]>

	* generic/tkText.c: Fix for undo/modified status of text widgets when
	empty strings are inserted and undone.

2006-03-17  Pat Thoyts  <[email protected]>

	* library/clrpick.tcl:   Avoid using abbreviated sub-commands in core
	* library/palette.tcl:   scripts as this can cause problems with
	* library/scale.tcl:    mega-widget libraries like snit.
	* library/scrlbar.tcl:	 [Bug 1451587]
	* library/tkfbox.tcl:
	* library/xmfbox.tcl:

2006-03-16  Don Porter  <[email protected]>

	* generic/tkConsole.c:	Substantial rewrite of [console] support.
	* generic/tkInt.h:	Included Obj-ification of the [console] and
	[consoleinterp] commands, and reworking of all the supporting data
	structures for cleaner sharing and lifetime management especially in
	multi-threaded configurations.

2006-03-16  Donal K. Fellows  <[email protected]>

	* library/msgs/pt.msg: Messages for Portuguese (strictly just for
	Brazilian Portuguese, but they'll do until we get other Portuguese
	speakers localize) from Ricardo Jorge <[email protected]> and Silas
	Justiano <[email protected]>. Many thanks! [Bug 1405069]

	* generic/tkImgPhoto.c (ImgPhotoCmd, Tk_PhotoPutBlock)
	(Tk_PhotoPutZoomedBlock): Added hack to detect copying of a photo with
	a simple alpha channel and skip calling ToggleComplexAlphaIfNeeded.
	This should speed up many photo-to-photo copies, keeping the cost of
	the alpha channel down.

2006-03-15  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock): Try
	to squelch performance issue with code that writes to large images by
	single pixels. Masses of thanks to George Staplin for helping to trace
	this down to the COMPLEX_ALPHA flag handling code. [Bug 1409140]

2006-03-13  Don Porter  <[email protected]>

	* tests/scrollbar.test: Corrected several broken calls to [testmetrics]
	that were crashing the test suite.

	* tests/constraints.tcl:     Added notAqua constraint to canvPs-3.1
	* tests/canvPs.test:      to stop test suite crash on Mac OSX.
					[Bug 1088807]

	* generic/tkCmds.c:		Purged remaining references to errno,
	* macosx/tkMacOSXPort.h:	and errno.h. Standardized the logic
	* macosx/tkMacOSXWm.c:		for using header files from the compat
	* macosx/tkMacOSXWm.h:		directory. Thanks Joe English for the
	* unix/tkUnixPort.h:		patch. [Patch 1445404]

2006-03-08  Don Porter	<[email protected]>

	* unix/Makefile.in: Update `make dist` to copy the image files needed
	by the test suite into the source distro. This was overlooked in the
	2005-10-12 commit.

	* changes:	Update in prep. for 8.5a4 release.

2006-03-07  Joe English  <[email protected]>

	* unix/tcl.m4: Set SHLIB_LD_FLAGS='${LIBS}' on NetBSD, as per the other
	*BSD variants. [Bug 1334613]
	* unix/configure: Regenerated.

2006-03-07  Donal K. Fellows  <[email protected]>

	* doc/canvas.n: Added note that stipples are not well-supported on
	non-X11 platforms. [Bug 220787] It's not a great solution, but it does
	indicate the state of affairs that has existed for years anyway; not
	much modern software uses stipples anyway.

2006-03-02  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXDraw.c (TkPutImage): Fix endian issue on OS X x86
	displaying images. Bitmap images still have a black/white reversal
	issue, appears to be a general OS X issue (as seen in frogger demo).

2006-02-27  Donal K. Fellows  <[email protected]>

	* generic/tkBitmap.c (Tk_GetBitmapFromData): Improve thread-safety.
	[Bug 470322]

	* generic/tkImgBmap.c (ImgBmapConfigureInstance): Force creation of new
	Pixmaps before deletion of old ones to prevent stupid caching problems.
	[Bug 480862]

2006-02-09  Daniel Steffen  <[email protected]>

	* generic/tk.decls:       fix signature of TkMacOSXInvalClipRgns
	* generic/tkPlatDecls.h:     to use Tk_Window instead of internal
	* macosx/tkMacOSXSubwindows.c:  type TkWindow (which led to any include
	* macosx/tkMacOSXWindowEvent.c: of public header tkMacOSX.h requiring
	* macosx/tkMacOSXWm.c:     prior include of tkInt.h).

	* generic/tk.h:      move TkAqua specific REDO_KEYSYM_LOOKUP define
	* macosx/tkMacOSXPort.h: out of tk.h into platform header.

2006-01-31  Donal K. Fellows  <[email protected]>

	* library/bgerror.tcl (::tk::dialog::error::bgerror): Finish the
	internationalization of the error dialog. [Bug 1409264]

2006-01-25  Don Porter	<[email protected]>

	* library/bgerror.tcl: Updates to use Tcl 8.4 features. [Patch 1237759]
	* library/choosedir.tcl:
	* library/comdlg.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/focus.tcl:
	* library/msgbox.tcl:
	* library/palette.tcl:
	* library/tk.tcl:
	* library/tkfbox.tcl:
	* library/xmfbox.tcl:

2006-01-23  Daniel Steffen  <[email protected]>

	* unix/configure:   minor fix to Darwin specific code removing
	* unix/configure.in: 64bit flags from CFLAGS for Tk build.

2006-01-20  Joe English  <[email protected]>

	* generic/tkEvent.c, unix/tkUnixEvent.c: XIM fixes [See 905830, patch
	tk84-xim-fixes.patch], and revert 2005-12-05 patch disabling XIM when
	SCIM in use, and make sure all X events get passed to XFilterEvent,
	including those without a corresponding Tk window.

2006-01-13  Anton Kovalenko  <[email protected]>

	* generic/tkUndo.c (TkUndoSetDepth): Don't free TkUndoSubAtoms for
	separator entries that are deleted: there is some unpredictable garbage
	instead of subatoms.

	Free both 'apply' and 'revert' action chains for non-separator entries.

2006-01-12  Donal K. Fellows  <[email protected]>

	TIP #260 IMPLEMENTATION

	* generic/tkCanvText.c (TextItem, CreateText, DisplayCanvText):
	* doc/canvas.n:		Code, docs and tests to implement an -underline
	* tests/canvText.test:	option for canvases' text items.

2006-01-11  Peter Spjuth  <[email protected]>

	* generic/tkGrid.c: Removed a lingering error message from TIP#147
	implementation.

2006-01-10  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDebug.c: add TkMacOSXGetNamedDebugSymbol() function
	* macosx/tkMacOSXDebug.h: that finds unexported symbols in loaded
	libraries by manually walking their symbol table; only to be used for
	debugging purposes, may break unexpectedly in the future. Needed to get
	access to private_extern internal debugging functions in HIToolbox.

	* macosx/tkMacOSXCarbonEvents.c: fix debug event tracing on Tiger.
	* macosx/tkMacOSXMenu.c: add debug menu printing during reconfigure.
	* macosx/tkMacOSXInit.c: conditionalize 64bit-unsafe dyld code.
	* macosx/GNUmakefile: add 'wish8.x' symlink to SYMROOT.

	* macosx/Wish.xcode/project.pbxproj:    fix copy to tktest resource
	* macosx/Wish.xcodeproj/project.pbxproj: fork when zerolinked.

	* macosx/Wish.xcode/default.pbxuser:    add widget demo as argument to
	* macosx/Wish.xcodeproj/default.pbxuser: executables (on by default).

	* unix/configure:   add caching, use AC_CACHE_CHECK instead of
	* unix/configure.in: AC_CACHE_VAL where possible, consistent message
	* unix/tcl.m4:  quoting, sync relevant tclconfig/tcl.m4 changes
	and gratuitous formatting differences, fix SC_CONFIG_MANPAGES with
	default argument, Darwin improvements to SC_LOAD_*CONFIG.

2005-12-28  Donal K. Fellows  <[email protected]>

	* generic/tkUndo.c (TkUndoSetDepth): Apply [Patch 1391939] from Ludwig
	Callewaert to fix [Bug 1380427].

2005-12-14  Daniel Steffen  <[email protected]>

	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/project.pbxproj: add new tclTomMath* files.

2005-12-13  Daniel Steffen  <[email protected]>

	* library/demos/cscroll.tcl: add MouseWheel bindings for aqua.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent)
	(GenerateMouseWheelEvent): add support for kEventMouseScroll events
	(smooth mouse wheel scrolling from mighty mouse or scrolling trackpad)
	by handling kEventMouseWheelMoved on application target as well as on
	dispatcher, in order to pick up synthesized MouseWheel events from
	HIObject handler (c.f. QA1453); add support for horizontal scrolling
	events by generating MouseWheel XEvent with Shift modifier.

2005-12-12  Jeff Hobbs  <[email protected]>

	* unix/tcl.m4, unix/configure: Fix sh quoting error reported in
	bash-3.1+ [Bug 1377619] (schafer)

2005-12-09  Mo DeJong  <[email protected]>

	* win/tkWinWm.c (WinSetIcon): Don't check result of SetClassLong() or
	SetClassLongPtr() since it was generating an incorrect error and the
	MSDN docs indicate that the result need not be checked.

2005-12-09  Mo DeJong  <[email protected]>

	* win/configure: Regen.
	* win/tcl.m4 (SC_CONFIG_CFLAGS): Define MACHINE for gcc builds. The
	lack of a definition of this variable in the manifest file was causing
	a runtime error in wish built with gcc.

2005-12-09  Daniel Steffen  <[email protected]>

	* generic/tkInt.decls:  Move all platform test sources from tk lib into
	* generic/tkTest.c:  tktest directly, removes requirement to export
	* macosx/tkMacOSXTest.c:TkplatformtestInit from internal stubs table.
	* unix/Makefile.in:
	* win/Makefile.in:
	* win/makefile.vc:
	* win/tkWinTest.c:

	* generic/tkIntPlatDecls.h:
	* generic/tkStubInit.c: regen.

2005-12-08  Jeff Hobbs  <[email protected]>

	* win/tcl.m4:    Add build support for Windows-x64 builds.
	* win/configure:    --enable-64bit now accepts =amd64|ia64 for
	* win/Makefile.in:  Windows 64-bit build variants (default: amd64)
	* win/makefile.vc:  [Bug 1369597]
	(TKOBJS): add tkWinTest.obj to regular Tk obj for TkplatformtestInit

	* win/configure.in: Add CE build support (some C code fixes needed)
	* win/wish.exe.manifest.in (new):    manifest must map in MACHINE and
	* win/rc/wish.exe.manifest (removed): VERSION to be correct.
	* unix/Makefile.in: fix dist target for manifest dir change

	* generic/tkTextTag.c (TkTextTagCmd): use correct arraySize for peered
	text widgets in [$text tag names]. [Bugs 1375069, 1374935]

2005-12-08  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDraw.c:  Remove inclusion of tclInt.h and use of tcl
	* macosx/tkMacOSXFont.c:  internals wherever possible in tk/macosx, the
	* macosx/tkMacOSXInit.c:  only remaining tcl internals in TkAqua are
	* macosx/tkMacOSXNotify.c:TclServiceIdle() in tkMacOSXScrlbr.c and
	* macosx/tkMacOSXScrlbr.c:Tcl_Get/SetStartupScript() in tkMacOSXInit.c
				  [RFE 1336531]

	* macosx/tkMacOSXInt.h: sync comments with core-8-4-branch.

2005-12-07  Jeff Hobbs  <[email protected]>

	* unix/tkUnixEvent.c (OpenIM): remove extraneous const

2005-12-06  Donal K. Fellows  <[email protected]>

	* doc/ConfigWidg.3 (TK_CONFIG_OPTION_SPECIFIED): Mentioned that the
	flag is deprecated because it is not thread-safe.

2005-12-05  Reinhard Max  <[email protected]>

	* unix/tkUnixEvent.c (OpenIM): Added a workaround to allow at least
	ASCII and the Compose key when typing into text and entry widgets on a
	system that uses SCIM. This has to be taken out again once the SCIM
	problems have been fixed.

2005-12-01  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (Darwin): fixed error when MACOSX_DEPLOYMENT_TARGET unset
	* unix/configure: regen.

2005-11-30  Jeff Hobbs  <[email protected]>

	* win/tkWinWm.c (WmAttributesCmd): set (no)topmost window aspect before
	rewrapping. [Bug 1086049]

	* macosx/tkMacOSXXStubs.c (TkpOpenDisplay, TkMacOSXDisplayChanged):
	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXEvent.h: Trap kEventAppAvailableWindowBoundsChanged
	* macosx/tkMacOSXInt.h:   event to watch for change in display size and
	adjust internal state appropriately.

	* doc/checkbutton.n: fix -selectcolor docs. [Bug 1083838]

	* generic/tkImgGIF.c: cast calls to blockOut

	* win/Makefile.in: place TCL_BIN_DIR first in PATH for targets to get
	Tcl built dll first.
	Add tkWinTest.obj to tk84.dll to handle some needed test functions
	being defined in stubs (TkplatformtestInit).

	* tests/scrollbar.test (6.22): fix rounding-error sensitive test

2005-11-29  Jeff Hobbs  <[email protected]>

	* library/console.tcl (::tk::ConsoleInit): improve work-around to avoid
	'% ' from tclMain.c. [Bug 1252259]

2005-11-27  Daniel Steffen  <[email protected]>

	* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
	add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
	configure (flag can't be present twice, so can't be in both CFLAGS and
	LDFLAGS during configure), don't use -prebind when deploying on 10.4,
	define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
	(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
	autoconf macros. Sync with tcl/unix/tcl.m4.

	* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
	formatting/ordering differences with tcl/unix/configure.in.

	* unix/Makefile.in: add CFLAGS to wish/tktest link to make executable
	linking the same as during configure (needed to avoid loosing any
	linker relevant flags in CFLAGS, in particular flags that can't be in
	LDFLAGS). Avoid concurrent linking of wish and compiling of
	tkTestInit.o during parallel make, fix dependencies and flags for
	building tkMacOSXInit.o
	(checkstubs, checkexports): dependency and Darwin fixes
	(dist): add new macosx files.

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessEvent):
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	* macosx/tkMacOSXCarbonEvents.c: install standard application event
	handler, add & call functions to start and stop carbon even timer that
	runs the tcl event loop periodically during a nested carbon event loop
	in the toolbox (e.g. during menutracking) to ensure tcl timers etc.
	continue to fire, register app event handler for menu tracking and HI
	command carbon events, move menu event handling to new handlers for
	those carbon events, no longer register for/handle appleevent carbon
	event (now dealt with by standard application event handler), event
	debugging code dynamically acquires carbon event debugging functions to
	allow use on Tiger where they are no longer exported from HIToolbox.

	* macosx/tkMacOSXFont.c (TkMacOSXUseAntialiasedText):
	* macosx/tkMacOSXKeyEvent.c (GetKeyboardLayout):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: abstract common code to dynamically acquire
	address of a named symbol (from a loaded dynamic library) into new
	function TkMacOSXGetNamedSymbol() and macro TkMacOSXInitNamedSymbol.

	* macosx/tkMacOSXMenu.c (TkpNewMenu):
	* macosx/tkMacOSXMenubutton.c (MenuButtonInitControl):
	* macosx/tkMacOSXMenus.c (TkMacOSXHandleMenuSelect): switch to modern
	utf-8 aware menu manager API, remove obsolete code, add error handling.

	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c: define OSX 10.3 or later only constants
	if necessary to allow compilation on OSX 10.2

	* macosx/tkMacOSXWm.c (UpdateSizeHints): remove code that is never
	executed.

	* xlib/xgc.c (XCreateGC): sync with core-8-4-branch change.

	* generic/tk.h: add/correct location of version numbers in macosx files

	* generic/tkInt.h: clarify fat compile comment.

	* macosx/Wish.pbproj/default.pbxuser (new):
	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/default.pbxuser (new):
	* macosx/Wish.xcodeproj/project.pbxproj (new): new/updated projects for
	Xcode 2.2 on 10.4, Xcode 1.5 on 10.3 & ProjectBuilder on 10.2, with
	native tktest targets and support for universal (fat) compiles.

	* macosx/Tk-Info.plist (removed):
	* macosx/Wish-Info.plist (removed):
	* macosx/buildTkConfig.tcl (removed): remove obsolete build files.

	* macosx/README: clarification/cleanup, document new Xcode projects and
	universal (fat) builds via CFLAGS (i.e. ppc and i386 at the same time).

	* unix/Makefile.in:
	* unix/aclocal.m4:
	* unix/configure.in:
	* macosx/configure.ac (new): add support for inclusion of
	unix/configure.in by macosx/configure.ac, allows generation of a
	config headers enabled configure script in macosx (required by Xcode
	projects).

	* macosx/GNUmakefile: rename from Makefile to avoid overwriting by
	configure run in tk/macosx, add support for reusing configure cache,
	build target fixes.

	* generic/tk3d.h:
	* generic/tkButton.h:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h:
	* generic/tkColor.h:
	* generic/tkEntry.h:
	* generic/tkFileFilter.h:
	* generic/tkFont.c:
	* generic/tkFont.h:
	* generic/tkImage.c:
	* generic/tkImgPhoto.c:
	* generic/tkInt.h:
	* generic/tkMenu.c:
	* generic/tkMenu.h:
	* generic/tkMenubutton.h:
	* generic/tkScale.h:
	* generic/tkScrollbar.h:
	* generic/tkSelect.h:
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* generic/tkText.h:
	* generic/tkUndo.h:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixMenu.c:
	* xlib/xgc.c: ensure externally visible symbols not contained in stubs
	table are declared as MODULE_SCOPE (or as static if not used outside of
	own source file), #ifdef out a few Xlib and aqua functions that are
	never called. These changes allow 'make checkstubs' to complete without
	error on Darwin with gcc 4.

	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXPort.h:
	* win/tkWinTest.c:
	* generic/tkInt.decls: add functions needed by tktest to internal stubs
	table, correct signature of TkMacOSXHandleMenuSelect, add XSync to aqua
	Xlib stubs.

	* unix/tkUnixSend.c:
	* generic/tkText.c:
	* generic/tkTest.c: #ifdef unix only declarations.
	(TestmetricsCmd): unify win and mac implementation.
	(TestsendCmd): move to tkUnixSend.c to avoid access to global var.
	(TesttextCmd): move to tkText.c to avoid having to put all the internal
	text functions it uses into the stubs table.

	* generic/tkTextDisp.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXXStubs.c: fix gcc 4 warnings.

	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXScrlbr.c: sync with core-8-4-branch.

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure:
	* unix/tkConfig.h.in: regen.

2005-11-22  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl: Remove all references to data(curItem), as it is
	no longer used. [Bug 600313]
	(::tk::IconList_CurSelection): Renamed for clarity.

	* doc/GetFont.3: Revert previous fix; a NULL interp is now legal.
	* generic/tkFont.c (ParseFontNameObj, GetAttributeInfoObj): Allow these
	functions to work with a NULL interp by making them check when
	generating error messages. [Bug 1151523]

	* library/tkfbox.tcl (::tk::dialog::file::): Correct the quoting of the
	script used in variable traces so that widget names with spaces in will
	work. [Bug 1335485]

2005-11-16  Vince Darley  <[email protected]>

	* doc/text.n: clarify left to right interpretation of index modifiers,
	including the fact that validation occurs after each step. [Bug
	1357575]

2005-11-15  Joe English  <[email protected]>

	* unix/tkUnixWm.c, tests/unixWm.test, doc/wm.n: Support for [wm
	attributes] on X11. [TIP#231, Patch 1062022]

2005-11-14  Joe English  <[email protected]>

	* library/bgerror.tcl: Truncate error messages at 45 characters
	instead of 30. [Bug 1224235]

2005-11-14  Donal K. Fellows  <[email protected]>

	* generic/tkSelect.c (TkSelDefaultSelection): Test select-9.5
	highlighted further brokenness in this function.

2005-11-13  Donal K. Fellows  <[email protected]>

	* unix/tkUnixSelect.c (SelCvtToX): Arrange for the parsing code to use
	Tcl's list parsing code, another simplification that enables testing
	of the [Bug 1353414] fix.

	* unix/tkUnixSelect.c (SelCvtFromX): Generate string forms of the
	advanced selection types in a Tcl_DString. This makes fixing [Bug
	1353414] trivial, and simplifies the code at the same time.
	* tests/select.test (select-9.5): Added test for [Bug 1353414]

2005-11-10  Donal K. Fellows  <[email protected]>

	* generic/tkBind.c (ChangeScreen):		More DString fixes from
	* generic/tkTextWind.c (EmbWinLayoutProc):	[Bug 1353022]
	* win/tkWinMenu.c (SetDefaults):

	* win/tkWinDialog.c (ConvertExternalFilename): Factored out the
	encoding conversion and de-backslash-ing code that is used in many
	places in this file.
	(GetFileNameW, GetFileNameA, ChooseDirectoryValidateProc): Make sure
	that data is freed correctly and that certain (hopefully impossible)
	failure modes won't cause crashes. [Bug 1353022]

2005-11-06  Pat Thoyts  <[email protected]>

	* unix/tcl.m4:  Fix SHLIB_LD_LIBS for building tclkit on OpenBSD.
	* unix/configure: regenerated

2005-10-31  Vince Darley  <[email protected]>

	* generic/tkText.c
	* tests/textDisp.test: fix and test for [Bug 1333951] in '.text count
	-displaylines'.

2005-10-18  Don Porter	<[email protected]>

	* generic/tkMain.c: Rewrote code that sets the ::argv value to be sure
	conversion from the system encoding is complete before any processing
	sensitive to list-special characters is done. [Bug 1328926]

2005-10-17  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXScrlbr.c (UpdateControlValues): check geomMgrPtr is
	valid before checking type

2005-10-15  Jeff Hobbs  <[email protected]>

	* library/menu.tcl (::tk::MenuUnpost): remove leftover ] from string
	equal mods of 2005-07-25. (sowadsky)

2005-10-14  Pat Thoyts  <[email protected]>

	* win/tkWinSend.c:  Avoid using tcl internal headers and fix to
	* win/tkWinSendCom.h: correctly link on all types of build (was
	* win/tkWinSendCom.c: broken in static,msvcrt builds).

2005-10-12  Donal K. Fellows  <[email protected]>

	* tests/canvPs.test, tests/canvPsBmap.tcl, tests/canvPsImg.tcl:
	* tests/imgPhoto.test, tests/menu.test: Arrange for the test suite to
	only ever refer to images in the same directory as the tests. This
	makes it possible to package the test suite itself as a starkit. Thanks
	to David Zolli for suggesting this.

2005-10-10  Jeff Hobbs  <[email protected]>

	* generic/tkConfig.c (Tk_DeleteOptionTable, Tk_CreateOptionTable):
	properly alloc/delete one more option. [Bug 1319720] (melbardis)

	* macosx/tkMacOSXInt.h: Move MODULE_SCOPE defn to tkInt.h and add
	* generic/tkInt.h:    WORDS_BIGENDIAN checks that will work with OS X
	universal binary compiles. (steffen)

	* generic/tkMenu.c (TkSetWindowMenuBar): do not call TkMenuInit if the
	winPtr indicates TK_ALREADY_DEAD. This prevents reinit that creates a
	Tk exit handler after all exit handlers should be called. [Bug 749908,
	1322294]

2005-10-10  Vince Darley  <[email protected]>

	TIP #256 IMPLEMENTATION

	* doc/text.n
	* generic/tkText.c
	* generic/tkText.h
	* generic/tkTextBTree.c
	* generic/tkTextDisp.c
	* generic/tkTextImage.c
	* generic/tkTextIndex.c
	* generic/tkTextMark.c
	* generic/tkTextTag.c
	* generic/tkTextWind.c
	* macosx/tkMacOSXDefault.h
	* tests/text.test
	* tests/textDisp.test
	* unix/tkUnixDefault.h
	* win/tkWinDefault.h: Implementation of TIP#256, adding a new text
	widget configuration option '-tabstyle', with new tests and
	documentation.

	Also a fix for [Bug 1281228] (documentation and full implementation of
	-strictlimits), and [Bug 1288677] (corrected elide behaviour), again
	with more tests.

2005-10-04  Jeff Hobbs  <[email protected]>

	* library/dialog.tcl (::tk_dialog): add tkwait visibility before grab.
	[Bug 1216775]

	* win/tkWinDialog.c (ChooseDirectoryValidateProc): reset stored path to
	"" if it doesn't exist and -mustexist is true. [Bug 1309218] Remove
	old-style dir chooser (no longer used).

	* macosx/tkMacOSXInt.h: add MODULE_SCOPE definition check for extension
	writers that access private headers on OS X and don't define it in
	configure.

2005-09-28  Don Porter	<[email protected]>

	* unix/tkUnixPort.h:	Disabled inclusion of the private Tcl header
	* win/tkWinPort.h:	file tclInt.h. Tk ought to have a tiny and
	shrinking number of calls of private Tcl routines. Each Tk source file
	doing this should follow the convention in the macosx port and have its
	own #include "tclInt.h".

	* generic/tkEvent.c:	Disabled calls to private Tcl routine
	TclInExit(). See comment in TkCreateExitHandler() for full rationale.

2005-09-21  Donal K. Fellows  <[email protected]>

	* generic/tkEvent.c (TkCreateThreadExitHandler, TkFinalizeThread)
	(TkDeleteThreadExitHandler): New internal API (from Joe Mistachkin) to
	allow Tk to finalize itself correctly in a multi-threaded
	environment. [Bug 749908]

2005-09-14  Donal K. Fellows  <[email protected]>

	* generic/tkOldConfig.c (GetCachedSpecs): Split out the code to
	manipulate the cached writable specs so that it can be reused from all
	the public Tk_Configure* functions.
	(Tk_ConfigureInfo, Tk_ConfigureWidget, Tk_ConfigureValue): Use the
	factored out code everywhere, so we always manipulate the cache
	correctly. [Bug 1288128]

2005-09-13  Don Porter	<[email protected]>

	* win/winMain.c (WishPanic): Replaced TCL_VARARGS* macros with direct
	use of stdarg.h conventions.

2005-09-11  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): check if
	process is in front on MouseDown, otherwise request process activation
	from BringWindowForward() via new isFrontProcess param.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents): register
	our event handler on the dispatcher target for all carbon events of
	interest to TkAqua; this replaces event processing directly from the
	event queue and thus allows to capture events that are syntesized by
	Carbon and sent directly to the dispatcher and not to the event queue.

	* macosx/tkMacOSXEvent.c: remove TkMacOSXCountAndProcessMacEvents(),
	rename ReceiveAndProcessEvent() to TkMacOSXReceiveAndProcessEvent().
	(TkMacOSXReceiveAndProcessEvent): remove tk event processing before
	sending events to the dispatcher, all events of interest are now
	processed in our dispatcher target event handler.

	* macosx/tkMacOSXNotify.c (CarbonEventsCheckProc): dispatch events
	directly via TkMacOSXReceiveAndProcessEvent(), but dispatch no more
	than four carbon events at one time to avoid starving other event
	sources.

	* macosx/tkMacOSXEvent.c: formatting cleanup, move XSync() to XStubs,
	* macosx/tkMacOSXEvent.h: removed obsolete kEventClassWish handling.
	* macosx/tkMacOSXXStubs.c

	* macosx/tkMacOSXEvent.h: declare macosx internal procs as MODULE_SCOPE
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXButton.c: conditionalize all debug message printing to
	* macosx/tkMacOSXCursor.c: stderr via TK_MAC_DEBUG define.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* unix/configure.in: define TK_MAC_DEBUG on aqua when symbols enabled.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* library/listbox.tcl: synced aqua MouseWheel bindings with
	* library/scrlbar.tcl: core-8-4-branch.
	* library/text.tcl:

	* xlib/xcolors.c: fixed warning

2005-08-25  Daniel Steffen  <[email protected]>

	* unix/Makefile.in (html): reverted/amended changes of 2005-08-23 that
	broke TkAqua 'make install'; added BUILD_HTML_FLAGS optional var like
	in tcl/unix/Makefile.in.

2005-08-24  Donal K. Fellows  <[email protected]>

	* tests/text.test (text-8.18): Fix punctuation of error message to
	match good practice (actual message already fixed). [Bug 1267484]

2005-08-23  Jeff Hobbs  <[email protected]>

	* macosx/tkMacOSXDialog.c: make dialogs ignore -initialfile "" and
	-initialdir "" instead of error.

2005-08-23  Mo DeJong  <[email protected]>

	* win/tkWin32Dll.c (DllMain): Replace old asm SEH approach with Kenny's
	new SEH implementation. [Tcl Bug 1235544]

2005-08-23  Mo DeJong  <[email protected]>

	* unix/Makefile.in: Subst BUILD_TCLSH and TCL_EXE.
	* unix/configure: Regen.
	* unix/configure.in: Update minimum autoconf version to 2.59. Invoke
	SC_PROG_TCLSH and SC_BUILD_TCLSH.
	* unix/tcl.m4 (SC_PROG_TCLSH, SC_BUILD_TCLSH):
	* win/Makefile.in: Subst BUILD_TCLSH and TCL_EXE.
	* win/configure: Regen.
	* win/configure.in: Update minimum autoconf version to 2.59. Invoke
	SC_BUILD_TCLSH.
	* win/tcl.m4 (SC_PROG_TCLSH, SC_BUILD_TCLSH): Split confused search
	for tclsh on PATH and build and install locations into two macros.
	SC_PROG_TCLSH searches just the PATH. SC_BUILD_TCLSH determines the
	name of the tclsh executable in the Tcl build directory. [Tcl Bug
	1160114] [Tcl Patch 1244153]

2005-08-22  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c: fix warnings.

2005-08-20  Joe Mistachkin  <[email protected]>

	* win/tkWinX.c: Fixed bad cast. [Bug 1216006]

2005-08-18  Donal K. Fellows  <[email protected]>

	* doc/GetFont.3: Reworded to reflect the truth. [Bug 1151523]

2005-08-16 George Peter Staplin  <[email protected]>

	* doc/CrtItemType.3 prototypes were lacking [] after objv. Thus the man
	page was wrong about the actual prototypes. This was verified by
	studying tkCanvBmap.c.

2005-08-13 Chengye Mao  <[email protected]>

	* generic/tkOldConfig.c: Fixed [Bug 1258604]. This bug was introduced
	into the modfied Tk_ConfigureWidget. It failed to properly handle the
	specFlags' bit TK_CONFIG_OPTION_SPECIFIED.

2005-08-12  Donal K. Fellows  <[email protected]>

	* generic/tkOldConfig.c (Tk_ConfigureWidget): Stop storing per-thread
	data in global data structures. Store it in per-interpreter data (i.e.
	per-thread data) instead. [Bug 749908]

2005-08-10  Donal K. Fellows  <[email protected]>

	* generic/tkFrame.c (CreateFrame) and others: Don't use size_t when
	working with Tcl_GetStringFromObj because it is not 64-bit clean. [Bug
	1252702]

2005-08-04  Vince Darley  <[email protected]>

	* doc/text.n: Clarify behaviour of tab stops (as per [Bug 1247835])

2005-08-09  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon
	events sent directly to application event target via the general
	TkMacOSXProcessEvent() in the same way as events posted to the event
	loop. Moved existing app event handlers to tkMacOSXWindowEvent.c.
	(TkMacOSXInitCarbonEvents): register our application event handler for
	kEventWindowExpanded events to deal with uncollapsing from the dock.

	* macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added
	* macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for
				  use by app event handler.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve
	current window, partCode, modifiers and local cursor position from
	carbon mouse event if possible. Use new static GenerateButtonEvent()
	taking a MouseEventData struct instead of TkGenerateButtonEvent() to
	avoid recomputing already known values. Move process activation on
	MouseDown into BringWindowForward() to allow clicking on window
	titlebar widgets without activating process. Move code dealing with
	clicks in window titelbar into separate function
	HandleWindowTitlebarMouseDown() to avoid code duplication. Avoid
	repeated calls to TkMacOSXGetXWindow() by storing result in
	MouseEventData struct.
	(TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier
	state from currently processed carbon event (to avoid unnecessary IPC
	with the window server), otherwise use modern carbon API to get this
	info instead of Button() and GetKeys(); only retrieve info caller asks
	for (via non-NULL ptr passed to XQueryPointer).
	(ButtonModifiers2State): new static function converting carbon button
	and modifier state into tk state, allows detection of more than 3 mouse
	buttons (tk supports up to 5) and of NumLock and Fn modifier keys
	(NumLock is mapped to Mod3 and Fn to Mod4).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent):
	handle kEventWindowExpanded event to deal with window uncollapsing from
	the dock by generating tk Map event, handle kEventAppHidden and
	kEventAppShown events (moved here from tkMacOSXCarbonEvents.c).

	* macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when it
	is not iconified to avoid window flashing on collapse.

	* macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle().
	(TkMacOSXZoomToplevel): remove call to TrackBox(), now done in
	HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c.
	(TkpWmSetState): avoid window flashing on collapse by unmapping after
	calling CollapseWindow(); only uncollapse window if it is collapsed.

	* generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature.
	* generic/tkIntPlatDecls.h:

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call
	GetMenuItemCommandID() on KeyDown or KeyRepeat events.

	* macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to
	obsolete AppendResMenu() API.

	* macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive
	* macosx/tkMacOSXMenu.c:    GetMouse() and TkMacOSXButtonKeyState()
	* macosx/tkMacOSXMenus.c:   APIs by calls to XQueryPointer()
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:   replaced use of FrontNonFloatingWindow()
	* macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as
	* macosx/tkMacOSXMenu.c:    recommended by Carbon docs.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c: fixed warnings
	* macosx/tkMacOSXTest.c:

	* macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.h:

	* macosx/tkMacOSXInt.h: declare macosx internal procs as MODULE_SCOPE.
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXWindowEvent.c

	* library/bgerror.tcl: sync with core-8-4-branch changes of 2005-07-28.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXMouseEvent.c:

	* generic/tkFrame.c:   sync with core-8-4-branch changes of 2005-07-27.
	* generic/tkIntDecls.h:
	* generic/tkStubInit.c:
	* generic/tkFrame.c:
	* win/tkWinDraw.c:
	* unix/tkUnixDraw.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXButton.c: sync with core-8-4-branch.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXScale.c:

	* library/demos/menu.tcl: removed errant '}'.

2005-08-04  Donal K. Fellows  <[email protected]>

	* doc/clipboard.n: Add example demonstrating custom types of clipboard
	data.

2005-07-25  Donal K. Fellows  <[email protected]>

	* library/*.tcl: Updated to use more 8.4 and 8.5 features as part of
	resolving [Patch 1237759].

2005-07-22  Mo DeJong  <[email protected]>

	* win/tkWinX.c: Define _WIN32_WINNT with NT SP 3 data to fix compiler
	error because SendInput was not defined. The new msys_mingw7 release is
	now needed to compile the HEAD with mingw gcc. [Bug 1210712]

2005-07-21  Jeff Hobbs	<[email protected]>

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): corrected if
	expression error (use of = instead of ==).

2005-07-18  Vince Darley  <[email protected]>

	* generic/tkTextMark.c: fix to segfault in "mark prev"
	* tests/textIndex.test: [Bug 1240221]

	* tests/textWind.test: make test more robust to avoid infinite loop

2005-07-06  Jeff Hobbs	<[email protected]>

	* doc/getOpenFile.n: correct -multiple docs (takes boolean)

2005-07-05  Don Porter	<[email protected]>

	* unix/Makefile.in:	Purged use of TCLTESTARGS. [RFE 1161550]

2005-06-23  Daniel Steffen  <[email protected]>

	* generic/tkConsole.c (TkConsolePrint): prevent potential NULL deref.

	* macosx/tkMacOSXDefault.h: change ENTRY_BORDER defaults to from 5 to 2
	to make default entry widgets in TkAqua look like in other aqua apps
	(and have same border dimensions as other platforms). [Bug 1176610]

2005-06-21  Donal K. Fellows  <[email protected]>

	* doc/GetBitmap.3: Fix silly error in SYNOPSIS. [Bug 1224983]

2005-06-19  Donal K. Fellows  <[email protected]>

	* generic/tkImgGIF.c: Cleanse all static (i.e. non-thread-safe) data
	at a miniscule performance hit.

2005-06-18  Daniel Steffen  <[email protected]>

	* macosx/Makefile: for X11 build, add -X11 suffix to unversioned wish
	symbolic link.

	* unix/tcl.m4 (Darwin): add -headerpad_max_install_names to LDFLAGS to
	ensure we can always relocate binaries with install_name_tool.

	* unix/configure: autoconf-2.59

2005-06-07  Donal K. Fellows  <[email protected]>

	Bump patchlevel to a4 to distinguish from a3 release.

2005-06-04  Jeff Hobbs	<[email protected]>

	*** 8.5a3 TAGGED FOR RELEASE ***

2005-06-02  Jim Ingham	<[email protected]>

	* generic/tkEvent.c (InvokeFocusHandlers): On Mac OS X the scrollwheel
	events are sent to the window under the mouse, not to the focus window

	Another patch from M. Kirkham.

	* macosx/tkMacOSXScrlbr.c (ThumbActionProc, ScrollBarBindProc): Record
	the first mouse down point, and compute differences from that, rather
	than getting the mouse down each time through the loop. The old method
	would get fooled if you moved the mouse less than a text line height in
	the text widget. [Bug 1083728]

2005-06-03  Daniel Steffen  <[email protected]>

	* macosx/Makefile: fixed 'embedded' target.

2005-06-02  Reinhard Max  <[email protected]>

	* unix/tkUnix.c (Tk_GetUserInactiveTime): Improvements to get it
	working on Solaris, and panic if we run out of memory.
	* unix/configure.in: Rework the searching for Xss, to make it work on
	Solaris and provide more useful output. Use AC_HELP_STRING where
	appropriate.
	* unix/tcl.m4: synced from Tcl.
	* unix/configure: regenerated with autoconf 2.59.

2005-06-01  Jeff Hobbs	<[email protected]>

	* win/tkWinInt.h: added private decls of Tk_GetEmbeddedMenuHWND,
	Tk_GetMenuHWND, TkWinCleanupContainerList, and TkpWmGetState to that
	are used across source files.

	* win/tkWinX.c (Tk_ResetUserInactiveTime): cast to squelch compiler
	warning.

2005-05-31  Reinhard Max  <[email protected]>

	* doc/Inactive.3 (new file): C level API documentationn for
	TIP#245 (Tk_GetUserInactiveTime, Tk_ResetUserInactiveTime).
	* tests/tk.test: Added tests for the TIP#245 implementation.

2005-05-30  Jeff Hobbs	<[email protected]>

	* generic/tkPanedWindow.c, tests/panedwindow.test: batch of fixes to
	panedwindow from Daniel South. Improved auto-size to fit internal
	windows, fixed sash placement at edge of pane, fixed calculation of
	stretch amount for internal windows. [Bug 1124198, 1161543, 1054117,
	1010941, 795869, 690169, 1192323]

	* generic/tkMenu.c (MenuCmd): create event handler earlier to ensure
	proper destruction of menu through DestroyNotify. [Bug 1159367]

	* library/console.tcl (::tk::ConsoleInit): print out first prompt and
	swallow the extra "% " that comes once from Tcl on Windows.

2005-05-29  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXFont.c: use Tcl_Panic instead of panic.

	* unix/configure.in: added description of HAVE_XSS for autoheader.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Wish.xcode/project.pbxproj: added missing FRAMEWORK defines
	introduced with configure/make based build.

	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: fixed warnings.

	* generic/tkDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: ran missing 'make genstubs' for TIP245 changes
	to tk.decls

	* macosx/tkMacOSXXStubs.c (Tk_ResetUserInactiveTime): use symbolic
	constant argument in call to UpdateSystemActivity();

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Wish.xcode/project.pbxproj:
	* unix/configure.in: added/corrected linking to IOKit.framework for
	TIP245.

	* unix/configure.in: skip X11 configure checks when building tk_aqua.
	* unix/configure: autoconf-2.59

2005-05-28  Donal K. Fellows  <[email protected]>

	TIP #245 IMPLEMENTATION from Reinhard Max <[email protected]>

	* doc/tk.n: Documentation of [tk inactivity].
	* win/tkWinX.c (Tk_GetUserInactiveTime, Tk_ResetUserInactiveTime):
	* unix/tkUnix.c (Tk_GetUserInactiveTime, Tk_ResetUserInactiveTime):
	* macosx/tkMacOSXXStubs.c:	Implementations of the core API for
	(Tk_GetUserInactiveTime):	determining how long as user's left
	(Tk_ResetUserInactiveTime):	her machine alone.
	* unix/configure.in: Test for XScreenSaver support.
	* generic/tkCmds.c (Tk_TkObjCmd): Implementation of [tk inactivity].

2005-05-27  Todd Helfter  <[email protected]>

	* library/menu.tcl: correct the sticky behavior of menus posted by
	tk_popup so that they "stick" after the initial <ButtonRelease>
	following the post, that is not over an active menu entry.

2005-05-26  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXInit.c (TkpInit): fixed resource file extraction from
	__tk_rsrc section to work with non-prebound .dylib and .bundle.

	* macosx/Makefile: corrected EMBEDDED_BUILD check, use separate Tcl and
	Tk version vars to properly support tk/x11 framework version
	overriding, rewrite tkConfig.sh when overriding tk version, corrected
	Wish.app symlink in tk build dir.

	* unix/configure.in: corrected framework finalization to softlink stub
	library to Versions/8.x subdir instead of Versions/Current.
	* unix/configure: autoconf-2.59

2005-05-25  Jeff Hobbs	<[email protected]>

	* unix/Makefile.in (install-libraries): protect possible empty list in
	for with list= trick for older shells.

2005-05-23  Jeff Hobbs	<[email protected]>

	* generic/tkFileFilter.c (FreeGlobPatterns): s/null/NULL/

2005-05-24  Daniel Steffen  <[email protected]>

	* generic/tkTest.c: disable commands not available on TkAqua.

	* macosx/Makefile:
	* macosx/README:
	* macosx/Tk-Info.plist.in (new file):
	* macosx/Wish-Info.plist.in (new file):
	* unix/Makefile.in:
	* unix/configure.in:
	* unix/tcl.m4:
	* unix/tkUnixInit.c: moved all Darwin framework and TkAqua build
	support from macosx/Wish.pbproj and macosx/Makefile into the standard
	unix configure/make buildsystem, the project and macosx/Makefile are no
	longer required to build Tk.framework and/or TkAqua. TkAqua is now
	enabled by the --enable-aqua configure option, and static and
	non-framework builds of TkAqua are now available via the standard
	configure switches. Tk/X11 can also be built as a framework. The
	macosx/Makefile now wraps the unix buildsystem and no longer uses the
	projects, embedded builds are still only available via this Makefile,
	but for other builds it is not longer required (but its current
	functionality is still available for backwards compatibility). The
	projects currently do not call through to the Makefile to build (unlike
	Tcl.pbproj) so project builds may differ from makefile builds. Due to
	issues with spaces in pathnames, 'Wish Shell.app' has been renamed to
	'Wish.app', the macosx/Makefile installs backwards compatibility
	symlinks for the old name.
	* macosx/tkMacOSXInit.c (TkpInit): added support for Tk resource file
	in non-framework and static builds: the resource file is copied into a
	__tk_rsrc MachO section of the library or executable at link time and
	extracted into a temporary location at initialization.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in (new file): autoheader-2.59

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Tk-Info.plist:
	* macosx/Wish-Info.plist:
	* macosx/tkAboutDlg.r: updated copyright years to 2005.

2005-05-22  Donal K. Fellows  <[email protected]>

	* generic/tkFileFilter.c (TkGetFileFilters): Add all filters, not just
	the first one. [Bug 1206133]

2005-05-15  Jim Ingham	<[email protected]>

	Fixes from Michael Kirkham:

	* macosx/tkMacOSXMenu.c (TkpConfigureMenuEntry): Thinko in clearing the
	ENTRY_ACCEL_MASK before re-parsing it. [Bug 1012852]

	* macosx/tkMacOSXScrlbr.c (UpdateControlValues): Don't set the control
	value BEFORE setting the min and max or the control manager will reset
	it for you. [Bug 1202181]

	* macosx/tkMacOSXXStubs.c (TkMacOSXXGetPixel, TkMacOSXXPutPixel):
	Restore the port to what it was before putting we were called. [Bug
	1202223]

2005-05-14  Jim Ingham  <[email protected]>

	* macosx/tkMacOSXScrlbr.c (ThumbActionProc): Missing Tcl_Release.

2005-05-14  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: introduction of new tcl notifier based on
	CFRunLoop allows replacement of the custom TkAqua notifier by a
	standard tcl event source. Removes requirement of threaded tcl core
	for TkAqua, allows to stub-link TkAqua against Tcl by removing use of
	the unstubbed TclInitNotifier & TclFinalizeNotifier. [Tcl Patch
	1202052]

	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.pbproj/project.pbxproj: stub-link TkAqua: build with
	USE_TCL_STUBS and link against libtclstub instead of Tcl.framework,
	unexport libtclstub symbols from Tk to avoid duplicate symbol warnings
	when linking with both Tcl and Tk, fixes for gcc4.0 warnings.

	* macosx/Wish.xcode/project.pbxproj: sync with Wish.pbproj changes
	since 2004-11-19.
	NOTE: to use this project, need to uncomment the tclConfig.h settings
	at the top of tcl/unix/configure.in, autoconf and rebuild tcl !

	* macosx/tkMacOSXBitmap.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c: fixed gcc 4.0 warnings.

	* unix/tcl.m4: sync with tcl
	* unix/configure: autoconf-2.59

2005-05-10  Vince Darley  <[email protected]>

	* library/text.tcl: test and fix to TextPrevPara to avoid infinite loop
	* tests/textIndex.test: at start of widget. [Bug 1191895]

	* generic/tkTextDisp.c: better synchronisation between explicit and
	implicit pixel line-height calculations. [Bug 1186558]

2005-05-10  Don Porter	<[email protected]>

	* generic/tkTextDisp.c (GetXView): Improved numerical precision of
	calculation of [.t xview] return values.
	* tests/textDisp.test: Match greater precisions of [.t xview] and
	[.t yview] values in tests.

2005-05-06  Jeff Hobbs	<[email protected]>

	* unix/configure: regen
	* unix/configure.in: Add AC_C_BIGENDIAN check and pkg-config xft checks
	to extend xft search.
	* unix/tcl.m4: Correct Solaris 10 (5.10) check and add support for
	x86_64 Solaris cc builds.

2005-04-28  Donal K. Fellows  <[email protected]>

	* macosx/tkMacOSXNotify.c (TkMacOSXWaitForEvent): Fix for typo in
	waitTime computation. [Bug 1191097]
	(AlertNotifier): Factor out the core of the notifier alerting code.

2005-04-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXNotify.c: sync with tclUnixNotfy.c changes since
	2004-06-22, added compile time check for threaded tcl core, removed
	unthreaded code paths as they are never used anyway, fixed
	TkMacOSXAlertNotifier() implementation.

	* unix/Makefile.in: added TCL_STUB_LIB_FILE, needed for unexporting of
	symbols from libtclstub to avoid duplicate symbol warnings.

	* unix/tcl.m4 (Darwin): added configure checks for recently added
	linker flags -single_module and -search_paths_first to allow building
	with older tools (and on Mac OS X 10.1), use -single_module in SHLIB_LD
	and not just T{CL,K}_SHLIB_LD_EXTRAS, added unexporting from Tk of
	symbols from libtclstub to avoid duplicate symbol warnings, added
	PLAT_SRCS definition for Mac OS X, defined MODULE_SCOPE to
	__private_extern__.
	(SC_MISSING_POSIX_HEADERS): added caching of dirent.h check.

	* unix/configure: autoconf-2.59

2005-04-22  George Peter Staplin  <[email protected]>

	* doc/FontId.3: I fixed a typo. "linespace" was used instead of
	"ascent". I also added a .PP before the paragraph to make the
	formatting look better for the ascent paragraph.

2003-04-18  Joe English	 <[email protected]>

	* unix/tkUnixRFont.c(Tk_MeasureChars): Use Tcl_UtfToUnichar() for lax
	UTF-8 parsing instead of strict parsing with FcUtf8ToUcs4()
	[fix/workaround for Bug 1185640]

2003-04-18  Vince Darley  <[email protected]>

	* library/text.tcl
	* doc/text.n: corrected 'Home' and 'End' and Control-a/e handling to
	work with display lines. This was an ommission of the previous tip155
	patch. Clarified the documentation on this point.

2005-04-14  Jeff Hobbs	<[email protected]>

	* unix/tkUnixFont.c (FontMapLoadPage): reorder char[] decls to avoid
	possible segv. Minimal fix for [Bug 1122671]

2005-04-12  Jeff Hobbs	<[email protected]>

	* library/tkfbox.tcl (::tk::dialog::file::): fix typeMenuLab ref. Add
	undoc'd ::tk::dialog::file::showHiddenBtn var (default 0) that will add
	a "Show Hidden" checkbutton to tk_get*File and tk_chooseDirectory if
	set to true.
	* library/choosedir.tcl (::tk::dialog::file::chooseDir::): fix
	cancelBtn ref, add hiddenBtn ref for "Show Hidden" button.

2005-04-09  Daniel Steffen  <[email protected]>

	* macosx/README: updated requirements for OS & developer tool versions
	+ other small fixes/cleanup.

	* macosx/tkMacOSXEntry.c (ComputeIncDecParameters): manually define
	constants present only in 10.3 headers so that we can build on 10.2.

	* macosx/Wish.pbproj/project.pbxproj: fixed absolute path to tkEntry.h
	that confused 10.2 PBX.

	* unix/tcl.m4 (Darwin): added -single_module linker flag to
	TCL_SHLIB_LD_EXTRAS and TK_SHLIB_LD_EXTRAS.
	* unix/configure: autoconf-2.59

2005-04-07  Mo DeJong  <[email protected]>

	* macosx/tkMacOSXWm.c (TkWmStackorderToplevelWrapperMap,
	(TkWmStackorderToplevel):
	* unix/tkUnixWm.c (TkWmStackorderToplevelWrapperMap,
	(TkWmStackorderToplevel):
	* win/tkWinWm.c (TkWmStackorderToplevelWrapperMap,
	(TkWmStackorderToplevel):
	Fix panic in wm stackorder when a toplevel is created on another
	display. The code now ignores toplevels that have a display that does
	not match the display of the parent window. [Bug 1152809]

2005-04-06  Donal K. Fellows  <[email protected]>

	* doc/wm.n, doc/winfo.n, doc/tk.n, doc/send.n, doc/selection.n:
	* doc/radiobutton.n, doc/photo.n, doc/options.n, doc/menu.n:
	* doc/listbox.n, doc/getOpenFile.n, doc/font.n, doc/event.n:
	* doc/entry.n, doc/clipboard.n, doc/checkbutton.n, doc/canvas.n:
	* doc/button.n, doc/bind.n, doc/TextLayout.3, doc/MeasureChar.3:
	* doc/GetRelief.3, doc/GetPixels.3, doc/GetJustify.3, doc/GetFont.3:
	* doc/GetCursor.3, doc/GetColor.3, doc/GetBitmap.3, doc/GetAnchor.3:
	* doc/FontId.3, doc/CrtWindow.3, doc/CrtImgType.3, doc/ConfigWidg.3:
	* doc/3DBorder.3: Purge old .VS/.VE macro instances.

2005-04-04  Don Porter	<[email protected]>

	* library/comdlg.tcl: Added Macintosh file type validation to
	[::tk::FDGetFileTypes]. [Bug 1083878] (Thanks, Vince Darley)

2005-04-04  Vince Darley  <[email protected]>

	* generic/tkText.c:
	* tests/text.test: fix to elide searching problems [Bug 1174269] and
	disappearing cursor with insertofftime 0. [Bug 1169429]

2005-04-03  Peter Spjuth  <[email protected]>

	* tests/grid.test:
	* generic/tkGrid.c: Fixed bug in geometry calculations for widgets that
	span multiple columns/row. Bug was introduced in 8.5a1 when fixing
	792387. [Bug 1175092]

2005-03-29  Jeff Hobbs	<[email protected]>

	* win/tcl.m4, win/configure: do not require cygpath in macros to allow
	msys alone as an alternative.

2005-03-27  Vince Darley  <[email protected]>

	* tests/textDisp.test: added test for fix of 2005-03-15.

2005-03-24  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXEntry.c (TkpDrawEntryBorderAndFocus): Dopey bug - do
	not reset the width for entry widgets - we didn't change it for them.

2005-03-23  Jim Ingham	<[email protected]>

	These changes allow us to draw the Entry and Spinbox widget with a
	native look and feel on Mac OS X.

	* generic/tkEntry.h: New file, extracting the definitions of Entry and
	Spinbox.
	* generic/tkEntry.c (DisplayEntry): Call out to TkpDrawSpinboxButtons
	and TkpDrawEntryBorderAndFocus. Also provide default implementations
	for X11 & Win.
	* macosx/tkMacOSXEntry.c: New file, implements the entry & focus and
	spinbox button drawing.
	* tkMacOSXDefaults.h: Change the Mac OS X defaults so they fit the
	native widget shapes.

	This is cleanup thanks to Neil Madden <[email protected]>.

	* macosx/tkMacOSXWm.c (TkMacOSXWinStyle) New function.
	(TkUnsupported1ObjCmd): New function, replaces the un-objectified
	version of the command.
	* generic/tkInt.h: Swap TkUnsupported1Cmd for TkUnsupported1ObjCmd.
	* generic/tkWindow.c (): Ditto.

	This adds a "-notify" flag to "wm attributes" that will bounce the
	dock icon on Mac OS X.	This is from Revar Desmera <[email protected]>

	* macosx/tkMacOSXWm.c (WmAttrGetNotifyStatus, WmAttrSetNotifyStatus):
	New functions.
	(WmAttributesCmd): Add the -notify.
	* doc/wm.n: Document -notify.

2005-03-19  Donal K. Fellows  <[email protected]>

	* generic/tkConsole.c (Tk_CreateConsoleWindow,TkConsolePrint): Rewrite
	so that TkConsolePrint cannot become detached from the console when the
	[console] command is renamed. [Bug 1016385]

2005-03-15  Vince Darley  <[email protected]>

	* generic/tkTextDisp.c: fix for [Bug 1143776] in adjusting displayed
	lines when running into the bottom of the window.

2005-03-14  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXScrlbr.c (ThumbActionProc): No need to use "update
	idletasks" here, TclServiceIdle will do as well and it is simpler.

	These changes implement a change on the Mac OS X side. When we unmap a
	window we mark all its children as unmapped (not following toplevels.
	But we preserve whether they had been mapped before, and when the
	parent is remapped, we remap the children as well. [Bug 940117]

	* macosx/tkMacOSXInt.h: Added TK_MAPPED_IN_PARENT
	* macosx/tkMacOSXSubwindows.c (FixMappingFlags): New function.
	(XMapWindow): Call FixMappingFlags.
	(XUnMapWindow): Ditto.

	* macosx/tkMacOSXSubwindows.c (XMoveResizeWindow): Update the xOff &
	yOff data in the Macdrawable even if the native window hasn't been
	created yet. [Bug 700305]
	(XMoveWindow): Ditto.
	(XResizeWindow): Ditto.

2005-03-15  Pat Thoyts	<[email protected]>

	* unix/tcl.m4:	  Updated the OpenBSD configuration and regenerated the
	* unix/configure: configure script.

2005-03-14  Donal K. Fellows  <[email protected]>

	* generic/tkEvent.c (InvokeClientMessageHandlers): Ensure that client
	messages are handled correctly. Thanks to George Petasis for tracking
	this down. [Bug 1162356]

2005-03-11  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXButton.c (TkpDisplayButton): Set the port to the
	Button window's port BEFORE you set the clip, otherwise you are setting
	the clip on the wrong window!
	Also, a little cleanup - move x & y into the branches where they are
	used, and don't compute the TextAnchor if we are using the native
	button text, since we aren't going to use it.
	(TkMacOSXDrawControl): Call ShowControl & SetControlVisibility in a
	more logical order.

	* tkMacOSXInt.h: Add TkMacOSXGenerateFocusEvent.
	* tkMacOSXSubwindows.c (XDestroyWindow): We don't get Activate events
	for the remaining windows when a Floating window is destroyed. This can
	cause the focus to disappear. So catch this case when the window is
	being destroyed and move the focus here.

	* tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): Make this public
	(used to be GenerateFocusEvent) since we need it here and in
	tkMacOSXSubwindows.c. Then change the name everywhere it is used. [Bug
	1124237]

2005-03-10  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): In the
	inDrag section, set the GrafPort to the drag window's GrafPort before
	doing LocalToGlobal. [Bug 1160025]

2005-03-09  Jim Ingham	<[email protected]>

	* macosx/tkMacOSXInit.c (TkpInit): Check to see if the environment
	variable XCNOSTDIN is set, and if so, close stdin & stdout. This is
	necessary to make remote debugging under Xcode work properly.

2005-03-08  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (WinSetIcon): fix GCLP_ICONSM -> GCLP_HICONSM.

	* win/makefile.vc: clarify necessary defined vars that can come from
	MSVC or the Platform SDK.

2005-02-28  Jeff Hobbs	<[email protected]>

	* win/tkWinX.c (GenerateXEvent): correct %A translation on MouseWheel.
	[Bug 1118340]

2005-02-24  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSX.h: fixed incorrect inclusion of internal header.
	* macosx/tkMacOSXNotify.c: corrected included headers.

2005-02-22  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXDialog.c (Tk_GetSaveFileObjCmd, NavServicesGetFile):
	fixed encoding problems with -initialfile & -filetypes and corrected
	potential buffer overrun with -initialdir/-initialfile. [Bug 1146057]

2005-02-16  Mo DeJong  <[email protected]>

	TIP#223 IMPLEMENTATION

	* doc/wm.n: Add documentation for -fullscreen attribute.
	* tests/winWm.test: Add -fullscreen to wm attribute usage message.
	* tests/wm.test: Add -fullscreen to wm attribute usage message. Add
	-fullscreen attribute test cases for Windows.
	* win/tkWinWm.c (WmInfo, UpdateWrapper, TkpWmSetFullScreen)
	(WmAttributesCmd, UpdateGeometryInfo):
	Implement TIP 223 [wm attributes -fullscreen].

2005-02-14  Vince Darley  <[email protected]>

	* generic/tkText.c:
	* generic/tkText.h:
	* generic/tkTextDisp.c:
	* generic/tkTextIndex.c:
	* generic/tkTextBTree.c:
	* doc/text.n:
	* tests/textDisp.test:
	* tests/textIndex.test: fix of longstanding elide problem when eliding
	a newline without eliding the entire logical line. [Bug 443848]

2005-02-14  Jeff Hobbs	<[email protected]>

	* doc/options.n: note -cursor {} behavior. [Bug 965618]

2005-02-14  Donal K. Fellows  <[email protected]>

	* tests/all.tcl: Add a [package require Tk] so that a missing display
	causes an early failure and keeps the error trace short. Issue observed
	in [FRQ 11122147], even though that's unrelated.

2005-02-11  Jeff Hobbs	<[email protected]>

	* library/panedwindow.tcl (::tk::panedwindow::Cursor): check window
	existence on delayed call. [Bug 949792]

	* doc/text.n: note 'image' key in 'dump' command. [Bug 1115907]

	* win/tkWinWm.c (TkWinGetIcon): fix toplevel retrieval for determining
	icon ref (potential crash). [Bug 1105738]

	* generic/tkCanvBmap.c (ConfigureBitmap, ComputeBitmapBbox): Fixed
	possible crash with disabled bmap and bbox handling [Bug 1119460]
	(BitmapToPostscript): made aware of various bitmap types

	* unix/Makefile.in: remove SHLIB_LD_FLAGS (only for AIX, inlined into
	* unix/tcl.m4:	    SHLIB_LD). Combine AIX-* and AIX-5 branches in
	* unix/configure:   SC_CONFIG_CFLAGS. Correct gcc builds for AIX-4+ and
	HP-UX-11. autoconf-2.59 gen'd.

2005-02-09  Donal K. Fellows  <[email protected]>

	* tests/wm.test: Convert to use more tcltest2 features.

2005-02-07  Donal K. Fellows  <[email protected]>

	* generic/tkCanvas.c (CanvasWidgetCmd): Fix stupid mistake in variable
	names, reported by Andreas Leitgeb.

2005-02-03  Donal K. Fellows  <[email protected]>

	* generic/tkCanvas.c (GetStaticUids): New function to manage the
	thread-specific data detailing the list of all uids in a thread.
	(typeList): Protect this (the other piece of global data) with a mutex.
	[Bug 1114977]

2005-01-31  Jeff Hobbs	<[email protected]>

	* unix/tcl.m4, unix/configure: add solaris-64 gcc build support. [Bug
	1021871]

2005-01-31  Donal K. Fellows  <[email protected]>

	* generic/tkImgPhoto.c (PhotoFormatThreadExitProc): Made the comments
	in the code more relevant to the function they were documenting! [Bug
	1110553]

	* library/msgs/es_ES.msg: Added more localization for Spanish Spanish.
	[Bug 1111213]

2005-01-25  Daniel Steffen  <[email protected]>

	* macosx/tkMacOSXInit.c (TkpInit): set tcl_interactive to 1 to show
	console at startup instead of directly calling [console show].

	* unix/tcl.m4 (Darwin): fixed bug with static build linking to dynamic
	library in /usr/lib etc instead of linking to static library earlier in
	search path. [Tcl Bug 956908]
	Removed obsolete references to Rhapsody.
	* unix/configure: autoconf-2.57

2005-01-18  Donal K. Fellows  <[email protected]>

	* library/demos/menu.tcl: Reworked to make dialogs children of the
	demo widget so that they are properly visible. Issue reported by Keith
	Nash <[email protected]>

2005-01-13  Donal K. Fellows  <[email protected]>

	* library/tkfbox.tcl (IconList_Selection, IconList_Create):
	(IconList_Arrange): Assorted tk_getOpenFile fixes. [part of Bug 600313]
	(IconList_ShiftMotion1): Also fix shift-drag.

2005-01-12  Don Porter	<[email protected]>

	* unix/tcl.m4:		Sync'ed to Tcl's copy.
	* unix/configure:	autoconf-2.57

2005-01-12  Donal K. Fellows  <[email protected]>

	* doc/event.n: Added section on predefined virtual events. [Bug 608115]

2005-01-11  Vince Darley  <[email protected]>

	* generic/tkTextDisp.c: fix to scrollbar height calculations of text
	widgets containing a single very long (wrapped) line. This fixes at
	least part of [Bug 1093631].

2005-01-11  Donal K. Fellows  <[email protected]>

	* generic/tkObj.c (TkParsePadAmount):
	* generic/tkPack.c: Moved function to tkObj.c and rewrote so that it
	takes advantage of Tcl_Objs properly and cannot leave objects in an
	inconsistent state. [Bug 1098779]

2005-01-10  Joe English	 <[email protected]>

	* unix/Makefile.in, unix/configure.in, unix/tkConfig.sh.in:
	Remove ${DBGX}, ${TK_DBGX} from Tk build system. [Patch 1081595]
	* unix/tcl.m4: re-synced with tcl/unix/tcl.m4
	* unix/configure: Regenerated.

2005-01-07  Donal K. Fellows  <[email protected]>

	* generic/tkWindow.c (GetScreen): Make sure the result is reset on all
	error paths to stop strange errors. [Bug 697915]

2005-01-05  Donal K. Fellows  <[email protected]>

	* doc/loadTk.n, doc/toplevel.n: Convert to other form of emacs mode
	control comment to prevent problems with old versions of man. [Bug
	1085127]

2005-01-03  Jeff Hobbs	<[email protected]>

	* win/tkWinWm.c (TkWinWmCleanup): clean up layered window class. This
	caused crash in reinit of Tk (as seen in plugin).

	******************************************************************
	*** CHANGELOG ENTRIES FOR 2004 AND 2003 IN "ChangeLog.2004"    ***
	*** CHANGELOG ENTRIES FOR 2002 AND EARLIER IN "ChangeLog.2002" ***
	******************************************************************

Added README.










































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
README:  Tk
    This is the Tk 8.7a0 source distribution.
	http://sourceforge.net/projects/tcl/files/Tcl/
    You can get any source release of Tk from the URL above.

1. Introduction
---------------

This directory contains the sources and documentation for Tk, an X11
toolkit implemented with the Tcl scripting language.

For details on features, incompatibilities, and potential problems with
this release, see the Tcl/Tk 8.7 Web page at

	http://www.tcl.tk/software/tcltk/8.7.html

or refer to the "changes" file in this directory, which contains a
historical record of all changes to Tk.

Tk is maintained, enhanced, and distributed freely by the Tcl community.
Source code development and tracking of bug reports and feature requests
takes place at:

	http://core.tcl.tk/tk/

with the Tcl Developer Xchange at:

	http://www.tcl.tk/

Tk is a freely available open source package.  You can do virtually
anything you like with it, such as modifying it, redistributing it,
and selling it either in whole or in part.  See the file
"license.terms" for complete information.

2. See Tcl README
-----------------

Please see the README file that comes with the associated Tcl release
for more information.  There are pointers there to extensive
documentation.  In addition, there are additional README files
in the subdirectories of this distribution.

Deleted README.md.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# README:  Tk

This is the **Tk 9.0b2** source distribution.

You can get any source release of Tk from [our distribution
site](https://sourceforge.net/projects/tcl/files/Tcl/).

8.6 (production release, daily build)
[![Build Status](https://github.com/tcltk/tk/workflows/Linux/badge.svg?branch=core-8-6-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Linux%22+branch%3Acore-8-6-branch)
[![Build Status](https://github.com/tcltk/tk/workflows/Windows/badge.svg?branch=core-8-6-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Windows%22+branch%3Acore-8-6-branch)
[![Build Status](https://github.com/tcltk/tk/workflows/macOS/badge.svg?branch=core-8-6-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22macOS%22+branch%3Acore-8-6-branch)
<br>
8.7 (in development, daily build))
[![Build Status](https://github.com/tcltk/tk/workflows/Linux/badge.svg?branch=core-8-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Linux%22+branch%3Acore-8-branch)
[![Build Status](https://github.com/tcltk/tk/workflows/Windows/badge.svg?branch=core-8-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Windows%22+branch%3Acore-8-branch)
[![Build Status](https://github.com/tcltk/tk/workflows/macOS/badge.svg?branch=core-8-branch)](https://github.com/tcltk/tk/actions?query=workflow%3A%22macOS%22+branch%3Acore-8-branch)
9.0 (in development, daily build))
[![Build Status](https://github.com/tcltk/tk/workflows/Linux/badge.svg?branch=main)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Linux%22+branch%3Amain)
[![Build Status](https://github.com/tcltk/tk/workflows/Windows/badge.svg?branch=main)](https://github.com/tcltk/tk/actions?query=workflow%3A%22Windows%22+branch%3Amain)
[![Build Status](https://github.com/tcltk/tk/workflows/macOS/badge.svg?branch=main)](https://github.com/tcltk/tk/actions?query=workflow%3A%22macOS%22+branch%3Amain)

## <a id="intro">1.</a> Introduction

This directory contains the sources and documentation for Tk, a
cross-platform GUI toolkit implemented with the Tcl scripting language.

For details on features, incompatibilities, and potential problems with
this release, see [the Tcl/Tk 9.0 Web page](https://www.tcl-lang.org/software/tcltk/9.0.html)
or refer to the "changes" file in this directory, which contains a
historical record of all changes to Tk.

Tk is maintained, enhanced, and distributed freely by the Tcl community.
Source code development and tracking of bug reports and feature requests
take place at [core.tcl-lang.org](https://core.tcl-lang.org/).
Tcl/Tk release and mailing list services are [hosted by
SourceForge](https://sourceforge.net/projects/tcl/)
with the Tcl Developer Xchange hosted at
[www.tcl-lang.org](https://www.tcl-lang.org).

Tk is a freely available open-source package.  You can do virtually
anything you like with it, such as modifying it, redistributing it,
and selling it either in whole or in part.  See the file
`license.terms` for complete information.

## <a id="tcl">2.</a> See Tcl README.md

Please see the README.md file that comes with the associated Tcl release
for more information.  There are pointers there to extensive
documentation.  In addition, there are additional README files
in the subdirectories of this distribution.

Added changes.





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This file summarizes all changes made to Tk since version 1.0 was
released on March 13, 1991.  Changes that aren't backward compatible
are marked specially.

3/16/91 (bug fix) Modified tkWindow.c to remove Tk's Tcl commands from
the interpreter when the main window is deleted (otherwise there will
be dangling pointers to the non-existent window).

3/16/91 (bug fix) Modified tkColor.c not to free black or white colors:
some X servers get upset at this.

3/18/91 (bug fix) Modified tkShare.c to fix bug causing "DeleteGroup
couldn't find group on shareList" panic.

3/18/91 (bug fix) Several changes to tkListbox.c and tkScrollbar.c to
handle listboxes (and scrollbars) with zero total entries in them.

3/22/91 (bug fix) Fixed a few ='s in tkListbox.c that should be ==.

3/22/91 (bug fix) Fixed error in main.c that caused BadWindow errors
in some cases where wish scripts invoke "destroy .".

3/23/91 (new feature) Added Tk_CancelIdleCall to remove Tk_DoWhenIdle
handler.

3/23/91 (bug fix and new feature) Added -name option to main.c, made
it more clever about choosing name (was always using the name "wish"
on most Unix systems).

3/23/91 (new feature) Added TK_CONFIG_STRING option to Tk_ConfigureWidget,
used it to malloc strings for various widget options that used to be
Tk_Uid's (e.g. button text, message strings, etc.).  Eliminates core
leaks when values change in continuous non-repeating fashion.

3/29/91 (new feature) Added Tk_Preserve, Tk_Release, and
Tk_EventuallyFree procedures to help manage widget records and avoid
premature memory free-ing.

4/4/91 (bug fix) Fixed problem in tkWm.c where top-level window geometry
wasn't tracking correctly when wm-induced size change also changed window
position (e.g. menus wouldn't be displayed at the right places).

4/5/91 (new feature) Added "invoke" option to widget command for buttons,
check buttons, and radio buttons.

4/5/91 (new feature) Added "unpack" option to "pack" command.

4/5/91 (bug fix) Changed tkPack.c to use new Tk_Preserve code and be
more careful about window deletions that occur while repacking is in
progress.

4/6/91 (bug fix) Major overhaul of deletion code in all widgets to use
Tk_Preserve and Tk_Release.  Should fix many problems.

4/6/91 (bug fix) Changed "winfo children" to generate correct lists
when child names have embedded spaces.

4/6/91 (new feature) Added "screenheight" and "screenwidth" options to
"winfo".

4/18/91 (bug fix) Binding mechanism didn't correctly handle very long
%-substitutions in commands (e.g. long path names) and caused memory
to be overwritten.  Modified tkBind.c to fix.

---------------------- Release 1.1, 4/18/91 -------------------------

4/19/91 (bug fix) Inconsistent ICCCM handling of coordinates of reparented
windows causes windows to gradually walk south when moved or resized.
Fixed tkWm.c to patch around the problem.

---------------------- Release 1.2, 4/24/91 -------------------------

4/26/91 (new feature) Added -geometry and -display switches to wish.
Also wrote wish manual entry.

5/3/91 (bug fix) Fixed bug in tkListbox.c that caused garbage to appear
at right edge of window when strings were to large to fit in window.

5/3/91 (bug fix) Fixed bug in tkListbox.c where topIndex wasn't getting
updated when elements were deleted:  tended to cause errors in
communication with scrollbars.

5/16/91 (bug fix) Fixed bug in tk3d.c, which caused core dumps when
consecutive points in a polygon were the same (happened with some
configurations of radio buttons, for example).

5/16/91 (bug fix) Fixed main.c to allow stdin to be redirected.

6/1/91 (bug fix) Make sure that pointers are never used after being
freed.

6/15/91 (bug fix) Fixed bug in tkBind.c that caused current binding
values to not always be printed correctly.

6/15/91 (bug fix) Make sure that interpreters are always unregistered
when their main windows are deleted, and make wish delete the main
window before exiting.

8/21/91 (misfeature correction)  Automatically set source of window
position to "user" in "wm geometry" command, unless it has been
explicitly set to "program".

9/5/91 (bug fix) Modified option code to accept '#' as a comment
character in .Xdefaults files, in addition to '!'.

9/10/91 (misfeature correction) Changed binding mechanism so that
numeric %-sequences are output in decimal instead of hex.

9/19/91 (bug fix) Fixed bug in Tk_DoOneEvent(1) where it wasn't
checking files and X connections properly so it missed events.

10/6/91 (new feature) Reorganized tkBind.c to provide generic "binding
table" structure, which can be used to create bindings on items in
canvases as well as windows.

10/6/91 (new feature) Upgraded buttons and menus to use new tracing
code in Tcl 6.0.  Allows radio buttons and check buttons to both set
and clear themselves when associated variable changes.

10/17/91 (bug fix) Fixed 2 bugs in listboxes: accidentally advanced the
selection when new entries were inserted in the listbox after the location
of the selected item(s), and goofed up on redisplay if selected item
was deleted and then selection was immediately lost.

10/27/91 (bug fix) "pack unpack" wasn't telling Tk that it no longer
manages window;  this led to core dumps in some situations.

10/31/91 (reorganization) Renamed manual entries so that they are no
more than 14 characters in length.

10/31/91 (reorganization) Changed tk.h and tkInt.h so that tkInt.h
doesn't needed to be included by tk.h.

11/3/91 (portability improvement) Eliminated use of "class" as a variable
name, since it's a reserved word in C++.

11/7/91 (reorganization) Many changes to upgrade for Tcl 6.1 including
use of Tcl hash tables instead of separate "Hash_" module.  The "lib"
subdirectory is no longer needed in Tk.

---------------------- Release 1.3, 11/7/91 -------------------------

11/24/91 (bug fix) Fixed bug causing occasional errors if existing bindings
are modified (FindSequence in tkBind.c forget to set *maskPtr).

11/24/91 (bug fix) Used wrong hash table in Tk_GetColorByValue.  Could
cause new entries to get created unnecessarily.

12/2/91 (bug fix) Changed "bind" code to put backslashes in front of
special characters (e.g. [ or \) that appear in %-replacements, so that
they can be parsed cleanly.

12/10/91 (bug fix) Manual entries had first lines that caused "man" program
to try weird preprocessor.  Added blank comment lines to fix problem.

1/2/92 (documentation cleanup) Changed manual entries for Tk_GetBitmap
and the like to make it more clear that the argument must be a Tk_Uid
and not a string.

1/2/92 (bug fix) Fixed problem where scrollbars that were very short or
very narrow (too small to hold both arrows) could cause negative values
in calls to XClearArea, which crashed some servers.

1/2/92 (bug fix) Fixed bug in TkMeasureChars occurring when maxChars
is 0.  Occasionally affected things like message window geometry.

1/3/92 (new feature) Added procedures Tk_GetJustify, Tk_GetAnchor,
Tk_GetCapStyle, and Tk_GetJoinStyle, plus support for these things
in Tk_ConfigureWidget.

---------------------- Release 1.4, 1/10/92 -------------------------

1/12/92 (bug fix) TkMenubutton.c wasn't cleaning up mbPtr->varName
properly during menubutton cleanup if an error occurred during
menubutton creation.

1/19/92 (bug fix) Fixed off-by-one bug in tkListbox.c that caused
scrollbars to display a slider that was too large.

2/10/92 (bug fix) Tk_CreateFileHandler didn't correctly handle case
where new mask was specified for existing handler.

2/13/92 (bug fix) Tk_DeleteAllBindings wasn't correctly removing
bindings from the pattern table:  only did the removal for the
first pattern in a pattern list.

2/15/92 (new feature) Added procedures Tk_DefineBitmap and
Tk_SizeOfBitmap.  Tk_GetBitmapFromData is now considered obsolete
and probably shouldn't be used anymore.  Tk_GetBitmapFromData
is now implemented by calling Tk_DefineBitmap and Tk_GetBitmap.

2/15/92 (new feature) Added "curselection" and "select clear" options
to widget command for listboxes.

2/15/92 (new feature) Added Tk_3DBorderColor procedure.

2/17/92 (relaxed limitations) Changed scrollbars so they no longer limit
the slider position to lie within the object's range:  can scroll off the
end of an object, if the object permits it.  Changed listboxes and
entries to explicitly prevent viewing off the ends.  Also relaxed
listbox index checks so that out-of-range indices are automatically
adjust to fit within the listbox range.

2/19/92 (bug fix) tkWindow.c tended to leave half-created windows around
if a new window's name was found to be in use already.  Fixed to clean
them up.

2/22/92 (new feature) Added -anchor, -bitmap, -height, -textvariable,
-width options to labels, buttons, check buttons, menu buttons, and radio
buttons.  This means that (a) size can be controlled better, (b) bitmaps
can be displayed in any buttons, (c) the position of the text within the
button can be controlled, and (d) a button can be made to display the value
of a variable, continuously updating itself.  Also changed -selector option
so that if it's specified as an empty string then no selector is drawn
for the button.

2/22/92 (new feature) Changed menus to support bitmaps in menu entries:
added new -bitmap option for entries.

2/26/92 (bug fix) "after" command, when invoked with just one argument,
called Tk_Sleep rather than registering a timer handler and looping on
Tk_DoOneEvent.  As a result, it caused the application to become non-
responsive to X events during the sleep.  Changed to use a Tk_DoOneEvent
loop so that it is responsive.

2/26/92 (bug fix) Tk's main program didn't map the main window until
after the startup script returned.  Changed to map the window as a
do-when-idle handler, so that scripts can cause the window to be
mapped immediately with a call to "update" or "after".

2/28/92 (bug fix) "wm withdraw" wasn't working if invoked before window
was originally mapped:  window got mapped anyway.  Fixed so that the
window doesn't get mapped as long as it's withdrawn.

2/29/92 (new feature) Can use "focus none" to clear input focus.

2/29/92 (bug fix) Fixed tkEvent.c to generate SubstructureNotify events
properly.  These weren't being generated previously.

2/29/92 (bug fix) Fixed entries so that newline characters can be properly
displayed (as `\x0a').  Had to change interface to TkDisplayChars in order
to do this (added flags argument).

2/29/92 (bug fix) Change Tk not to update size and position of top-level
windows directly during calls like Tk_ResizeWindow.  Instead, wait until
actual event is received.  This makes updates happen at same time as
callbacks.

3/6/92 (bug fix) TkMenubutton.c was dumping core when a menubutton was
pressed at a time when there was no associated menu for the button.

3/6/92 (new feature) Added Tk script library directory with official
Tk initialization file "tk.tcl".  Other procedures used by Tk are in
other files.  Tk procedures and variables all have names starting
with "tk_".  Also added Wish startup script "wish.tcl", which sources
both the Tk and Tcl startup scripts.  This means that things like
auto-loading and abbreviation expansion are now available in wish.
Added new variables tk_library, tk_priv, and tk_version.

3/6/92 (new feature) It's now possible to set bindings for whole
classes by using the class name in the bind command.  For example,
"bind Button <Enter> {puts stdout Hi!}" will cause a message to be
printed whenever any mouse button is entered.  Can also use "all"
to set bindings for all widgets.  Widget-specific bindings override
class bindings which override "all" bindings.

3/6/92 (reorganization) Changed buttons (all flavors) and listboxes to
eliminate all hard-wired behavior.  Instead, default behavior is set
by class bindings in tk.tcl.  Also set up class bindings for menus,
menubuttons, and entries, which previously had no default behavior at
all.  Scrollbars and scales still have hard-wired behavior that can't
be overridden.

3/7/92 (look-and-feel change) Changed listboxes and entries and menus
to use button 2 for scanning instead of button 3.  This is more consistent
with the official Motif use of button 2 for dragging.

3/10/92 (new features) Added more options to "winfo" command:  screencells,
screendepth, screenmmheight, screenmmwidth, and screenvisual.

3/13/92 (bug fix) Event sharing mechanism (tkShare.c) wasn't checking
to see whether window was mapped before sharing events with it.

3/16/92 (bug fix) Tk_SetInternalBorderWidth was passing wrong window to
geometry-management procedures, causing core-dumps when menu buttons
had their border widths changed.

3/16/92 (bug fix) Menus were setting their geometry directory rather
than using Tk_GeometryRequest mechanism.

3/17/92 (new feature) Added -cursor option to all widgets to set the
active cursor for the widget.  Also added TK_CONFIG_ACTIVE_CURSOR
configure type.

3/18/92 (new feature) Implemented generalized screen coordinates to
allow resolution-independent specification in many cases (but pixel-
based coordinates are still OK).  Added Tk_GetScreenMM(),
Tk_GetPixels(), new configure types TK_CONFIG_SCREEN_MM and
TK_CONFIG_PIXELS.  Changed widgets to use this new configure types
wherever possible (a few of the more complex cases still haven't
been taken care of yet).  Added "pixels" and "fpixels" options to
"winfo" command.

3/18/92 (new feature) First cut at canvas widgets is done and part of
the official Tk now.  Canvases display text and structured graphics,
and allow you to bind commands to events related to the text and
graphics.

3/21/92 (new feature) Added new "place" command.  It implements a
new geometry manager that provides fixed placement, rubber-sheet
placement, and combinations of the two.  Eliminated the commands
"move", "resize", and "map" that were provided by main.c but never
officially supported;  the placer provides all of this functionality.

3/23/92 (bug fix) Fixed bug in tkWm.c where top-level windows were
occasionally not being given the right size.  The problem occurred
when a string of resizes happened all in a row (such as deleting all
the windows in an application and then recreating them).

3/23/92 (new feature) Added Tk_CoordsToWindow procedure and
"winfo containing" command.  These may be used to locate the window
containing a given point.

3/28/92 (new feature) Added "-exportselection" option to listboxes,
so that listbox selection need not necessarily be the X selection.

4/12/92 (bug fix) Changed menu buttons to store name of menubutton
in the associated variable, rather than the name of the menu.  This
is necessary in order to allow several menu buttons to share the
same menu.
*** POTENTIAL INCOMPATIBILITY ***

4/12/92 (bug fix) Fixed core dump that occurred in tkError.c when
removing the first error record from the error list.

4/15/92 (bug fix) Fixed bug in tkBind.c that prevented <KeyPress-1>
event specifications from being processed correctly:  the "1" was
treated as a button name rather than a keysym.

4/18/92 (new feature) Added Tk_DefineCursor and Tk_UndefineCursor
procedures.

4/18/92 (new feature) Major revision to listboxes.  Can now scroll and
scan in both x and y, plus -exportselection option allows selection not
to be exported.  The "view" widget command has been replaced by "xview"
and "yview", and the "scan" widget command has a new syntax.
*** POTENTIAL INCOMPATIBILITY ***

4/18/92 (new feature) Added -exportselection option to entries, so you
can select whether you want the entry selection to be the X selection
or not.

4/24/92 (new features) Added TK_CONFIG_CUSTOM type to Tk_ConfigureWidget,
plus added new flags TK_CONFIG_NULL_OK, TK_CONFIG_DONT_SET_DEFAULT,
and TK_CONFIG_OPTION_SPECIFIED.  Several other new types, such as
TK_CONFIG_CAP_STYLE, were also added as part of implementing canvases.

4/29/92 (bug fix) Changed "-selector" default for menus to have separate
values for mono and color.

4/30/92 (bug fix) Fixed bug in tkListbox.c where it occasionally generated
bogus scroll commands (last index less than first).

4/30/92 (reorganization) Moved demos directory to "library/demos".

---------------------- Release 2.0, 5/1/92 -------------------------

5/2/92 (bug fix) Fixed problem in tkListbox.c where it was doing too many
redisplays after repeated insertions.  Also reduced number of invocations
of scrollbar commands.

5/7/92 (portability improvement) Changed main.c not to use TK_EXCEPTION
flag;  it isn't needed and it causes problems on some systems.

5/9/92 (bug fix) Plugged core leaks in tkListbox.c and tkBind.c

5/9/92 (bug fix) TkBind.c was accidentally deleting bindings during
attempts to print non-existent bindings.

5/11/92 (bug fix) Maximum name length for applications (name used in
"send" commands) was too short (only 20);  increased to 1000.  Also
fixed bug related to over-long names that caused core dumps.

5/13/92 (bug fix) tkShare.c was using a dangling pointer if a share
group was deleted as a side-effect of a shared event.

5/13/92 (bug fix) Various initialization and core leak problems in
tkGC.c, tkSend.c, tkMenu.c, tkEvent.c, tkCanvas.c, tkCanvPoly.c,
tkCanvLine.c, tkListbox.c, tkEntry.c.

5/13/92 (bug fix) Empty entries could be scanned off the left edge,
displaying a garbage character.

5/13/92 (bug fix) Fixed a few problems with window manager interactions,
such as tendency for windows to spontaneously shrink in size.  By no
means are all of the problems fixed, though.

5/13/92 (performance optimization) Changed Tk_GeometryRequest not to
invoke geometry manager unless requested size has changed.

---------------------- Release 2.1, 5/14/92 -------------------------

5/1/92 (new features) Added flags like TK_IDLE_EVENTS to Tk_DoWhenIdle,
plus added "idletasks" option to "update" command.  Tk_DoWhenIdle arguments
look different now, but the change should be upward-compatible.

5/17/92 (new feature/bug fix) Added support for VisibilityNotify events
to the "bind" command.  For some reason they weren't supported previously.

5/17/92 (new feature) Added "tkwait" command.

5/17/92 (new feature) Added "grab" command.

5/17/92 (new feature) Added "-width" option to messages.  Also changed
messages to use the computed (i.e. desired) line length when displaying,
not the actual width of the window.

5/17/92 (bug fixes) Did some more fiddling with tkWm.c in the hopes
of improving window manager interactions.  Now there won't be more than
one configure request outstanding to the wm at a time.

5/17/92 (bug fix) Arrowheads on canvas lines weren't being translated
or scaled correctly.

5/20/92 (bug fix) Page-mode scrolling didn't work correctly for canvases
(wrong windowUnits was passed to scrollbars).

5/20/92 (bug fix) Changed scrollbars not to lose highlight when pointer
leaves window with button down.  Also changed redisplay to double-buffer
for smoother redraws.

5/21/92 (new feature) Added "gray50" and "gray25" as predefined bitmaps.

5/22/92 (new feature) Buttons can now be disabled using the "-state" and
"-disabledforeground configuration options.  The "activate" and "deactivate"
widget commands for buttons are now obsolete and will go away soon.
Please change Tcl scripts not to use them.

5/23/92 (new feature) Entries can now be disabled using the "-state"
config option.  Also improved class bindings for entries to keep the
cursor visible in the window when operations occur.  Also made slight
improvements in the way redisplay is done.

5/23/92 (new feature) Added "-textvariable" option to entries so that
the text in an entry can be tied to the value of a global variable in
a fashion similar to buttons.

5/27/92 (new feature) Added "-textvariable" and "-anchor" options to
messages.

5/28/92 (new feature) Added "-padx" and "-pady" and "-underline" options
to menubuttons.

5/28/92 (feature change) Changed "-width" and "-height" options on
all flavors of buttons and menubuttons so that they are orthogonal
to "-padx" and "-pady".  It used to be that -width overrode -padx
(no padding).  Now they accumulate.

5/29/92 (new feature) Added "-disabledforeground" option to menus and
all flavors of buttons (can specify color for disabled things rather
than just using stipple to gray out).

5/29/92 (new features) Added many new options to menu entries:
-activebackground, -background, -font, -state, -underline.  The
"disable" and "enable" widget commands for menus are now obsolete
and will go away soon.  Please change Tcl scripts not to use them.

5/29/92 (new features) Added "atom" and "atomname" options to "winfo"
command.

5/29/92 (new feature) Wrote tk_listboxSingleSelect procedure, which
can be used to change listbox behavior so that only a single item is
selected at once.

6/1/92 (new feature) Added new modifier names "Meta" and "Alt" for
"bind" command.

6/3/92 (new feature) Added "winfo toplevel" command.

6/3/92 (new feature) Made several changes for greater Motif compliance,
including:
    - menu retention if you click and release in the menu button,
    - keyboard traversal of menus (see traversal.man)
    - no widget flashing if you set $tk_strictMotif to 1

6/15/92 (bug fix) Fixed problem in tkBind.c where command string for a
binding could get reallocated while the command was being executed (e.g.
bindings that delete or change themselves).

6/15/92 (bug fix) Don't allow "tabWidth" field to become zero in tkFont.c:
can cause core dumps for fonts that don't enough information to compute
tab widths.

6/19/92 (bug fix) Fixed bug in binding mechanism that caused structure-
related events to be reported both to the correct window and its parent.

7/14/92 (bug fix) Changed tkColor.c not to free colors for visual types
StaticGray or StaticColor.

7/15/92 (new feature) Text widgets now exist.  They display any number of
lines of text with a variety of display formats, and include hypertext
facilities.  See the manual page for details.

7/20/92 (bug fix) If a top-level window was put in the iconic state to
begin with, it could be deiconified with "wm deiconify .foo" until it had
first been deiconified by hand from the window manager.  Tk was getting
confused and thought the window was mapped when it wasn't.

7/29/92 (bug fix) Don't permit rectangles or ovals to have zero-sized
dimensions.  Round up to at least one pixel.

7/29/92 (new features) Major upgrade to canvases:
    - new item types: arc, window, bitmap
    - added Bezier spline support for lines and polygons
    - rectangles and ovals now center their outlines on the shape,
      rather than drawing them entirely inside the shape
    - new "coords" and "bbox" widget commands
    - new "-tags" option for all item types.
    - new "-confine" option to prevent scrolling off edge of canvas.

8/6/92 (new feature) Added "-width" and "-height" options to frames.
The "-geometry" option is now obsolete and should be removed from Tcl
scripts:  it may go away in the future.

8/7/92 (bug fix) Error messages in Tk_ParseArgv were sometimes including
the option name where they should have included its value.

---------------------- Release 2.2, 8/7/92 -------------------------

8/7/92 (bug fix) Changed tkCanvas.c to be more conservative in the area
it passes to XCopyArea.

8/8/92 (bug fix) Fixed bug in tkTextDisp.c that sometimes caused core
dumps when text views changed (e.g. typing return on last line of screen).

8/8/92 (bug fix) Fixed bug in menu.tcl that caused errors when using
keyboard to traverse over separator menu entries.

8/10/92 (bug fix) Changed to use OPEN_MAX instead of MAX_FD to compute
maximum # of open files.

8/10/92 (bug fix) Canvases weren't updating scrollbars on window size
changes.  They also weren't recentering canvases on window size changes.

8/10/92 (bug fix) There were still a few places where commands were being
invoked at local level instead of global level (e.g. commands associated
with buttons and menu entries).

8/10/92 (bug fix) TkBind.c used to ignore explicit shift modifiers for
all keys (i.e. <Shift-Tab> was treated the same as <Tab>).  Modified to
allow explicit request for shift modifier, like <Shift-Tab>.

8/13/92 (feature change) Changed default fonts to request "Adobe" fonts
explicitly.

8/16/92 (bug fixes) Modified tkCanvArc.c and tkTrig.c to increase slightly
the bounding boxes for arcs, in order to make sure that proper redisplay
occurs when arcs are moved (little turds were getting left behind).

8/16/92 (bug fix) Modified tkCanvas.c not to redraw at all if the redisplay
area is off the screen.  Also, only do a background clear for the portion
of the redraw area that is on-screen.  Also, reduced size of off-screen
pixmaps used for redisplaying, which speeds up redisplay in some cases.

8/19/92 (bug fix) Canvases that were taller than wide were not being
redisplayed properly.

8/20/92 (new feature) Added Tk_CreateGenericHandler procedure for trapping
all X events (useful for tracing, watching non-Tk windows, etc.).

8/21/92 (bug fix) Widgets weren't always being notified when they got
the focus back again (the problem had to do with grabs and menus in
particular).

8/21/92 (new feature) Added "-state" option to scale widgets.

8/22/92 (new feature) Changed tkBitmap.c to allow tilde-substitution
to occur in bitmap file names.

---------------------- Release 2.3, 8/24/92 -------------------------

8/27/92 (bug fix) Changes to -activebackground and -activeforeground options
for menubuttons were being lost.

8/27/92 (bug fix) Entries were selecting last character when a B1-drag
occurred past the right edge of the text.

8/28/92 (bug fix) Fixed bug in canvases where a grab during a button
press caused the canvas state to lock up so that it didn't select a
new current item.

9/7/92 (bug fix) Changed tkMenu.c to accept numerical menu indices that
are out of range;  now it just rounds them off to the nearest existing
entry.

9/7/92 (bug fix) Fixed bug in tkTextDisp.c that caused core dumps when
invoking "yview -pickplace" widget command on texts that are too small
to hold any lines at all.

9/11/92 (bug fix) Fixed bug in tkTextDisp.c that caused core dumps
when adding tags to non-existent lines.

9/11/92 (bug fix) Line items in canvases didn't permit an empty fill
color (i.e. couldn't make them transparent).

9/14/92 (reorganization) Changed manual entries to use .1, .3, and .n
extensions.  Added "install" target to Makefile to suggest how Tk should
be installed.

9/16/92 (bug fix) Changed tkSend.c to always specify the root window of
screen 0 rather than using DefaultRootWindow.  DefaultRootWindow doesn't
always go to screen 0 on displays with multiple screens, which can result
in send's not being possible between the screens.

9/18/92 (new feature) Added three new options to "wm" command: "protocol",
"client", and "command".  These provide support for window manager protocols
such as WM_DELETE_WINDOW and WM_TAKE_FOCUS, plus support for the
WM_CLIENT_MACHINE and WM_COMMAND properties.

9/30/92 (new feature) Implemented color model support, including
"tk colormodel" command and Tk_GetColorModel and Tk_SetColorModel
procedures.  These allow you to force mono operation even on a color
display.  Also changed color allocation not to give errors when colors
run out, but just to switch to a mono color model.

10/1/92 (bug fixes) Fixed two bugs in tkTextBTree.c that caused core dumps
during text deletion.

10/5/92 (bug work-around) Changed tkColor.c to ignore errors when freeing
colors.  This is needed to work around improper reference count management
for colormap entries under X11/NeWS.

10/7/92 (new feature) Added support for different visual types, including
procedures Tk_SetWindowVisual and Tk_SetWindowColormap, plus macros
Tk_Visual, Tk_Depth, and Tk_Colormap.  The code for this was contributed
by Paul Mackerras.

10/7/92 (new feature) Added Tk_IsTopLevel macro.

10/12/92 (bug fix) Fixed bug in tk.tcl that caused torn-off menus with
cascaded children not to track mouse motion correctly (the cascade
switched in response to mouse motions within the cascaded child).

10/12/92 (new feature) Major changes to focus handling:
(a) Tk watches FocusIn and FocusOut events for focus changes, not Enter
    and Leave, so it will work better with explicit-focus-model window
    managers (e.g. mwm in default mode).
(b) Tk generates FocusIn and FocusOut events for the focus window now.
    The old procedural interface (via Tk_CreateFocusHandler) is obsolete
    and is no longer used inside Tk.  It is still supported for
    compatibility, but won't be for long.  You should change your code
    to use FocusIn and FocusOut events instead.
(c) The model for FocusIn and FocusOut events is different than the
    one described in Xlib documentation.  See the "focus" manual entry
    for details.
(d) If there is no input focus then keyboard events are discarded.  They
    used to be directed to the mouse pointer window, although this wasn't
    documented.  The focus now defaults to the root window.
*** POTENTIAL INCOMPATIBILITY ***

10/15/92 (bug fix) Fixed text items in canvases where they didn't
display the insertion cursor if the item had no characters in it.

10/26/92 (bug fix) Fixed bug in tkSelect.c that occasionally caused
BadWindow X protocol errors when retrieving the selection.  Tk wasn't
making sure that a window existed before using it to retrieve the
selection.

10/30/92 (feature change) Changed canvases so that if the scroll region
is smaller than the window and -confine is on, the scroll region isn't
forced to be centered in the window;  it can be anywhere that meets the
confinement restrictions.

11/2/92 (new feature) Added "winfo exists" command.

11/5/92 (new feature) Changed DoWhenIdle handlers so that if a new
when-idle handler is created as a side-effect of another when-idle
handler, the new handler isn't invoked until Tk has first checked
for other events to process.

11/6/92 (bug fixes, new features) Major overhaul of window manager
interface:
(a) Tk should now work with virtual-root window managers;
(b) windows will now place more accurately on the screen and stay where
    they're supposed to;
(c) size changes handled more reliably;
(d) code now works robustly in the face of withdrawals followed
    immediately by deiconifications.
(e) Added new procedure Tk_GetVRootInfo and new options to "winfo" command:
    vrootx, vrooty, vrootwidth, vrootheight.
(f) Added "overrideredirect" option to "wm".
(g) Fixed bug where change in width-only via "wm geom" didn't always work
   (min and max window sizes weren't being set properly for the wm).

11/6/92 (bug fixes) Modified menus so that they work correctly with
virtual root window managers.  Also fixed bug where menus didn't move
along with their associated windows, so that the menu popped up at
the old location of the window rather than its new location.

11/9/92 (new constraint) Made it illegal to give windows names that
start with upper-case letters, since such names will goof up the
option database by appearing to be classes rather than names.
*** POTENTIAL INCOMPATIBILITY ***

11/10/92 (new feature) Added Postscript output to canvases.

11/13/92 (bug fix) Changed default for maximum size passed to window
manager from 1000000 (which causes some wm's to make windows too large
when "maximized") to the size of the display.

11/14/92 (feature change) Major overhaul of menubuttons and pull-down
menus.  Removed event-sharing code, including Tk_ShareEvents and
Tk_UnshareEvents.  The -variable option for menubuttons has been
removed,and the "post" and "unpost" widget commands for menubuttons
no longer exist.  The "post" widget command for menus no longer
allows a group option.  The procedure tk_menus has been replaced
with a new procedure, tk_menuBar, which has a slightly different
interface.
*** POTENTIAL INCOMPATIBILITY ***

11/20/92 (new features, feature changes) Major overhaul of grab
mechanism to produce more correct event streams.  Also changed Tcl
commands to require explicit window for grab releases (makes it
possible for grabs to work on multiple displays simultaneously).
The old "grab none" command no longer exists, but new options
have been added: "current", "release", "set", and "status".
*** POTENTIAL INCOMPATIBILITY ***

11/20/92 (new feature) Use TK_LIBRARY environment variable to set library
directory location, if it is defined.  Otherwise fall back on usual
compiled-in value.

11/25/92 (bug fix) "wm grid" command was using wrong window.

11/29/92 (bug fix) Fixed core dump that occurred when trying to use
placer on top-level windows: return error instead.

11/29/92 (bug fix) Selection retrieval wasn't making sure that the window
on whose behalf selection is being retrieved actually exists.

12/3/92 (new feature) Added support for Mode_switch key to support the
full ISO character set.  Also added event handlers for MappingNotify
events so that Tk updates itself in response to keycode and modifier
changes.

12/6/92 (bug fix) Ignore recursive attempts to destroy window.

12/9/92 (new demos) Added "tcolor" and "rmt" demos.

12/10/92 (new features) Added "yposition" widget command for menus,
changed "delete" widget command to take an optional second index,
and changed -command option for cascade entries so that it is
invoked when the entry is activated rather than when it is invoked.
*** POTENTIAL INCOMPATIBILITY ***

12/12/92 (implementation change)  Changed the procedures Tk_FreeBitmap,
Tk_NameOfBitmap, Tk_SizeOfBitmap, Tk_FreeCursor, Tk_NameOfCursor, and
Tk_FreeGC to require an addition Display argument.  This is needed for
Tk to function correctly when an application has windows on multiple
displays.
*** POTENTIAL INCOMPATIBILITY ***

12/12/92 (new feature) Started creating a test suite.  Right now it
only has a few tests.

12/12/92 (new feature) Modified the packer so that a window can be
packed in descendants of its parent (used to be restricted to the
parent alone).  This makes it possible to hide extra windows used
for geometry management.  Also, can use generalized screen distances
in the "pack" command.

12/16/92 (feature change) Boolean options such as -exportselection now
print as 0/1 rather than true/false (both the default and current values
print this way).  This makes it easier to use these values in expressions.
*** POTENTIAL INCOMPATIBILITY ***

12/16/92 (name change) The classes "RadioButton" and "CheckButton" have
been renamed "Radiobutton" and "Checkbutton" for consistency.  From now
on widget class names will have exactly one capital letter.
*** POTENTIAL INCOMPATIBILITY ***

12/16/92 (new feature) Added -setgrid option to listboxes.

12/16/92 (new feature) The "destroy" command, and the "delete" widget
command for canvases, now accept any number of arguments, including
zero.

12/16/92 (new feature) Changed internal TkBindError procedure to
Tk_BackgroundError and exported it to Tk clients.

12/16/92 (option name change) Changed the place command's "dependents"
option to "slaves" for better consistency with documentation.
*** POTENTIAL INCOMPATIBILITY ***

12/16/92 (name changes) Renamed the "cursor*" options in entries and
canvases to "insert*".  Also renamed the "cursor" index to "insert" and
the "cursor" widget command to "icursor".  This was done to avoid
confusion between the mouse cursor and the insertion cursor.
*** POTENTIAL INCOMPATIBILITY ***

---------------------- Release 3.0, 12/17/92 -------------------------

12/17/92 (bug fix) Fixed dangling-pointer bug in canvases that occurred
if a <LeaveNotify> binding deleted the current item.

12/18/92 (bug fix) Core dump occurred if "wm" invoked with no arguments.
Also, tkWm.c wasn't properly setting WM_CLASS property on application
startup.

12/18/92 (incorrect documentation) Updated manual entries for Tk_FreeGC,
Tk_FreeCursor, and Tk_FreeBitmap to reflect new interface that requires
"display" argument.

12/18/92 (missing documentation) Added documentation for the canvas
"postscript" command, which was missing in the 3.0 release.

12/21/92 (bug fixes) There were lots of problems with the new installation
targets in the Makefiles, such as using "cp -f" and not installing
prolog.ps.  Made several other miscellaneous improvements to Makefile.

12/21/92 (bug fix) Arrowheads on canvas line items weren't moving properly
after coordinate changes made with the "coords" widget command.

12/21/92 (bug fix) If top-level window was initially withdrawn, couldn't
ever deiconify it again.

12/21/92 (bug fix) Double-button event sequences didn't always trigger
properly when grabs were in effect.

12/22/92 (bug fix) The packer didn't display any top or bottom windows
after a left or right expanded window, and vice versa.  Also made the
distribution of space among expanded windows more even.

12/28/92 (new features) Several improvements to selection:
(a) Added procedures Tk_ClearSelection and Tk_DeleteSelHandler.
(b) Added "clear" and "own" options to "selection" command, extended
    "handle" option to delete handlers.
(c) Error returns from "selection handle" scripts are now turned into
    selection retrieval errors ("no such selection") rather than an
    empty selection.
(d) Tk responds automatically for targets APPLICATION (name of application,
    so you can "send" to it) and WINDOW_NAME (name of window within
    application.
(e) Added test file "select.test" to test suite.

12/28/92 (bug fix) Fixed problem with flashing menus that occurred
because menu.tcl was willing to unpost and then immediately repost
the same menu.

1/6/93 (bug fix) Test for UnmapNotify events in tkPack.c used = instead
of ==.

1/21/93 (bug fix) Changed many widgets to eliminate use of
DefaultVisualofScreen, DefaultColormap, etc. and use the visuals
and colormaps for the actual windows instead.  Also changed to
inherit colormaps and windows from parent by default.

1/21/93 (new features) Added new winfo options "cells", "depth", and
"visual".

1/23/93 (bug fix) Fixed problem with text display that could result
in negative XCopyArea heights being sent to X server.  This causes some
servers (e.g. some versions of OpenWindows) to crash.

1/25/93 (new feature) Added -postcommand option to menus, so that menus
can be reconfigured before each posting.

1/29/93 (feature change) Changed %X and %Y in bindings so that they
refer to the virtual root rather than the true root.  Although
potentially incompatible, this change should almost always "do the
right thing".
*** POTENTIAL INCOMPATIBILITY ***

1/31/93 (bug fix) Changed "send" code to grab server while updating
the registry property (before this fix, two programs could allocate
the same interpreter name if they started up simultaneously).  In
order to make this fix I had to change the code for reclaiming
names of dead interpreters in a way that sometimes allows dead
interpreters to persist in the registry.

2/1/93 (feature change) Changed entries to allow leftmost "visible"
character to be the end of the text (i.e. no characters actually visible).
This is needed so that the cursor can be displayed even if the last
actual character is too wide to fit in the window.

2/3/93 (bug fix) Fixed two bugs in tkFocus.c:  (a) FocusIn events
were getting lost in some cases because the focus window hadn't been
created yet (e.g. new top-level window pops up underneath the mouse);
(b) Tk was accidentally triggering FocusOut events when the mouse
moved from a top-level window to one of its children.

2/4/93 (new feature) Added "visibility" option to "tkwait" command to make
it easier to wait for a new window to appear on the screen.

---------------------- Release 3.1, 2/5/93 -------------------------

2/10/93 (installation improvements) Makefile improvements:  added RANLIB
variable for easier Sys-V installation, changed to use INCLUDE_DIR
properly, and added SHELL variable for SGI systems.

---------------------- Release 3.2, 2/11/93 -------------------------

2/11/93 (new feature) Added "wm state" command, and improved wm so that
the right thing will happen if you invoke "wm iconify" when a window is
withdrawn.

2/14/93 (bug fix) When -colormap option was used in generating Postscript
for canvases, Tk didn't add an extra space after the color command.

2/14/93 (new feature) Changed "extern" declarations in tk.h to "EXTERN",
which will use the definition of EXTERN from tcl.h and work correctly
in C++ programs.

2/18/93 (bug fix) Item-specific bindings weren't getting deleted from
canvas items when the items were deleted.  As a result, they could
suddenly re-appear for new items if the new items were allocated a
record at the same addresses as the old ones.

2/18/93 (feature reversal) Changed "after" back again, so that it sleeps
*without* responding to events when it is invoked with just one argument;
can always use tkwait plus after with additional arguments to achieve
the effect of responding to events.
*** POTENTIAL INCOMPATIBILITY ***

2/20/93 (bug fix) Fixed bug in tkWindow.c where colormaps weren't being
set correctly for new top-level windows on different screens than their
parents (the bug results in X protocol errors: "invalid Colormap
parameter").

2/22/93 (bug fix) Changed "#!/usr/local/wish" in demo scripts to
"#!/usr/local/bin/wish" to reflect new location of binary.

2/22/93 (new feature) Added new reliefs "groove" and "ridge".

2/25/93 (new feature) Added new built-in bitmaps:  "error", "hourglass",
"info", "question", "questhead", and "warning".  Also added new demo in
"widget" to display all of these (under the Miscellaneous menu).

2/25/93 (improved implementation) Changed DrawText procedure in
prolog for outputting Postscript from canvases to use stringwidth
instead of charpath+pathbbox:  avoids limitcheck problems with long
strings, and also properly includes space characters in calculation.

2/25/93 (bug fix) Fixed several bugs in library/menu.tcl that caused
menu traversal to mis-behave when menu had no entries.

2/26/93 (new feature) Added "wm frame" command.

3/6/93 (bug fix) Mwm in click-to-focus mode was goofing up grabs so that
pull-down menus were sometimes unresponsive.  Modified tk.tcl to ignore
the spurious B1-Enter events generated by mwm, plus modified tkGrab.c to
release simulated button grabs correctly.

3/8/93 (bug fix) Tk had wrong interpretation of "lbearing" font metric,
which caused text to be displayed at the wrong horizontal position in
several places (labels/buttons, listboxes, canvas text, scales).  This
change will cause slight changes in the way certain widgets are
displayed.

3/12/93 (bug fix) Fixed core dumps that occurred in tkEntry.c because of
zero values in entryPtr->avgWidth.

3/12/93 (bug fix) Tk_CoordsToWindow was using root coordinates always.
Changed to use virtual-root coordinates when a virtual-root window
manager is being used.  Before this fix, "winfo containing" didn't
return the correct window under virtual-root window managers.

3/18/93 (bug fix) Modified tkWm.c so that Tk doesn't fight with window
manager over position of window;  it just takes what the window manager
gives it.

3/21/93 (new feature) Changed menus to display cascade entries with
standard Motif arrows at right side.a

3/22/93 (bug fix) Fixed bug in tkPack.c that was causing memory to
get trashed with the integer value 1.

3/22/93 (bug fix) Canvas text didn't print correctly if it contained
an open paren (or other special character) immediately followed by
an octal digit.

3/22/93 (bug fix) Text widgets didn't redisplay properly in cases
where two or more groups of lines both got taller at the same time
(e.g. from tag changes), causing two separate bit copies where the
first bit copy's target area overlapped the source area for
the second bit copy.

4/1/93 (bug fix) Changed canvases to use ISO Latin-1 font encoding
if that's supported by the Postscript interpreter.  Also added workaround
for bug in NeWSprint related to stipple fills.

4/1/93 (bug fixes) Made various changes to focusing and grabs to
eliminate extraneous focus events and generally improve behavior.

4/2/93 (bug fix) Modified tkWm.c not to wait indefinitely for the window
manager to map or reconfigure a window:  this led to deadlock in some
situations, such as creating a new top-level window with a grab held.

4/19/93 (bug fix) Fixed another bug in tkWm.c that caused windows to walk
across the screen in some situations.  Also fixed problem where rapid
posting and unposting of cascaded submenus (or menus?) could cause Tk
to become confused about whether or not a window is mapped (added
TkWmUnmapWindow procedure to make top-level unmaps synchronous).

4/24/93 (feature change) Changed the "after" command to allow times
less than or equal to 0, and to use 0 whenever they occur.

4/26/93 (new feature) Implemented security check for "send" as proposed
by Bennett Todd: incoming sends are now rejected unless (a) xhost-style
access control is enabled and (b) the list of authorized hosts is
empty.  In other words, you have to use xauth to use send.  This feature
can be disabled by setting the TK_NO_SECURITY flag at compile-time.

5/15/93 (improvement) Switched to use Tcl_PrintDouble whenever returning
real values as Tcl results.  This potentially allows higher precision.
Switched to use %.15g whenever printing reals in Postscript files.
However, the change Tcl_PrintDouble causes incompatibilities.  For
now, it's disabled with a macro in tclInt.h that redefines Tcl_PrintDouble.
Tk 4.0 will delete the macro, and you can also delete it now if you
want the better (but incompatible) behavior.

5/19/93 (bug fix) Fixed divide-by-zero problem that could occur in
closeness calculations for canvas oval items.

5/30/93 (bug fix) PROP and CONFIG were accidentally #defined to the same
value in tkBind.c, which could cause incorrect %-substitutions in event
bindings in a few exotic cases.

6/4/93 (improvement) Changed to use GNU autoconfig for configuration.
Makefile format changed, and Tcl is no longer automatically included
in Tk releases.

6/7/93 (bug fix) Fixed off-by-one error in rounding negative coordinates
during redisplay of canvases.

6/9/93 (feature improvement) Modified default bindings for entries to
keep one character visible to the left of the cursor during backspaces.

6/18/93 (feature improvement) Added patchlevel.h, for use in coordinating
future patch releases, and also added tk_patchLevel variable to make the
patch level available in scripts.

6/26/93 (bug fix) Fixed numeric problems in scales that occurred with
very large scale values.

6/26/93 (bug fix) Polygon items in canvases could cause core dumps if
the "coords" widget command was used to add one new coordinate.

6/26/93 (bug fix) Changed canvases to handle large stipple patterns
gracefully (stipples used to jump around during redisplay and lose
coherency).

7/1/93 (syntax change, new feature) Implemented the new packer syntax
as described in the book.  For now the old syntax will continue to be
supported too.  Converting over is straightforward except (a) use
"-anchor" instead of "frame", and (b) padding is different (separate
internal and external padding, plus pad amounts are *on each side*
instead of total).  Also added "pack propagate" command for keeping
the packer from setting the master's requested size.

7/1/93 Changed copyright notices.  The effect is the same as with the
old notices, but the new notices more clearly disclaim liability.

7/7/93 (new feature) Added support for window stacking order.  Windows
will now stack in the order created (most recent on top), plus "raise"
and "lower" commands may be used to restack (Tk_RestackWindow procedure
is available from C level).

7/7/93 (reorganization) Moved main.c to tkMain.c, reorganized it to
call Tcl_AppInit just like tclsh does, and added argv0 variable to contain
application name, and added default Tcl_AppInit procedure for wish.
Also added tkTest.c to hold C code for testing.

7/7/93 (new feature) Added new Tk-specific "exit" command, which cleans
up properly before exiting.  It replaces the Tcl "exit" command, and
can be used in place of "destroy .".

7/9/93 (new features) Added tk_dialog library procedure that creates
dialogs with a bitmap, message, and any number of buttons.  Also changed
default tkerror procedure to use tk_dialog plus offer the user a chance
to see a Tcl stack trace.

-------------------- Release 3.3 Beta 1, 7/9/93 -------------------------

7/12/93 (configuration changes) Eliminated leading blank line in
configure script;  provided separate targets in Makefile for installing
binary and non-binary information; fixed -lnsl and -lsocket handling
in configure; added autoconf support for fd_set type; check for various
typedefs like mode_t and size_t, and provide substitutes if they
don't exist; don't include tkAppInit.o in libtk.a; try to locate the
X includes and library in all of the standard places for various systems.

7/14/93 (new feature) Modified tkMain.c so that it stores the value
of the -display command-line option into the DISPLAY environment
variable, if it is specified.

7/15/93 (feature removal) Removed auto-initialization feature from
Tk_ConfigureWidget, so that you must once again initialize all fields
of a widget record before calling Tk_ConfigureWidget.  This restores
the behavior back to what it was in Tk 3.2.

7/16/93 (bug fix) Modified tkBind.c to ignore the Caps Lock modifier
unless it is explicitly requested in a binding.  Without this fix,
buttons and menus and other things didn't work if the Caps Lock key
was active.

-------------------- Release 3.3 Beta 2, 7/21/93 -------------------------

7/21/93 (new feature) Change "make install" so that it will modify the
#! lines on demo scripts to reflect the place where the wish binary
is installed.

7/23/93 (new feature) Added Tk_MainWindow procedure that returns the
main window associated with a Tcl interpreter.  This is intended for
use by Tcl_AppInit and other initialization procedures.

7/24/93 (configuration improvements) Changed configure script not to
omplain about "fd_set" missing if it's defined in <sys/select.h>.

7/28/93 (bug fix) "Bad Match - parameter mismatch" errors were
sometimes occurring when several top-level windows got created
at the same time, due to wrong choice of sibling when stacking
windows.

8/14/93 (new feature) Added support for tcl_prompt1 and tcl_prompt2
to wish main program:  makes prompts user-settable.

8/19/93 (bug fix) Bindings to event sequences like "aD" never matched
because the Shift key has to be pressed before D.  Modified Tk to
ignore extraneous keypresses if they are for modifier keys.

8/26/93 (configuration changes) Added Tk_Init, modified Tcl_AppInit
procedures to use it and Tcl_Init.  Added support for .wishrc file.

8/28/93 (new feature) The main window is now a legitimate toplevel
widget.

-------------------- Release 3.3 Beta 3, 8/30/93 -------------------------

9/2/93 (bug fix) The packer wasn't always relaying out a master after
changes to some of the configuration options of its slaves.

9/2/93 (bug fix) The binding mechanism made it impossible for patterns
like <Double-ButtonRelease-1> to ever match.

9/2/93 (bug fix) Fixed core dump that occurred for bitmap canvas items
if Postscript is generated but no -bitmap option has been specified.

9/4/93 (enhancement) Slight improvements to menu traversal:  set menu
traversal bindings for menubar window in tk_menuBar, plus trigger
traversal on <Any-Alt-Keypress> instead of <Alt-Keypress>.

9/9/93 (bug fix) Changed tkBind.c so that the Num_Lock key doesn't
prevent events from triggering bindings.

9/9/93 (bug fix) Changed tkOption.c to always fetch RESOURCE_MANAGER
property from root window of screen 0, rather than using default
screen.

9/9/93 (bug fix) Entry widgets weren't allocating quite enough width
for themselves.  Fixed this and changed the size computation to match
what's done for buttons and texts.

9/16/93 (bug fix) Changed tkMain.c not to call exit C procedure directly;
instead always invoke "exit" Tcl command so that application can redefine
the command to do additional cleanup.

-------------------- Release 3.3, 9/29/93 -------------------------

9/30/93 (bug fix) Packer wasn't unmapping slaves when master got deleted.

9/30/93 (bug fix) Binding event sequences such as <Right> were being
misprinted as ASCII characters such as "S".

10/6/93 (bug fix) Canvases weren't unmapping window items when the canvas
got unmapped, which caused problems for window items whose windows weren't
descendants of the canvas (they got left on the screen).

10/7/93 (feature change) NULL proc arguments to Tk_CreateFileHandler used
to have a special undocumented meaning (fd was display);  eliminated this
special interpretation.

10/7/93 (configuration change) Eliminated dependency of tkMain.c on
tkInt.h and tkConfig.h, so that it's easier for people to copy the file
out of the source directory to make modified versions.

10/8/93 (bug fix) 3.0 introduced a bug where the class of the application
wasn't being set properly, so options based on the application class
weren't triggering.  Fixed by adding new argument to Tk_CreateMainWindow.

10/11/93 (bug fix) Fixed bug in tkTextBTree.c where some deletions would
cause core dumps due to halfwayLinePtr not getting set correctly.

10/18/93 (bug fix) Fixed a couple of bugs that made it hard to actually
display N characters in an entry with "-width N" (tended to scroll the
entry so that only N-1 characters were visible at once).

10/22/93 (bug fix) During configuration, XINCLUDE_DIR and XLIBRARY_DIR
weren't overriding xmkmf like they were supposed to.

10/23/93 (new feature) Allow negative scale factors in canvas "scale"
widget command.

10/23/93 (bug fix) Grabs weren't being cleaned up right if the grab
window was deleted, causing core-dumps in some cases.

10/23/93 (bug fix) tk_TextSelectTo wasn't checking to be sure that
the "anchor" mark exists.

10/27/93 (bug fix) Fixed core dump that could occur in a text widget if
the scroll command modifies the text.

11/1/93 (bug fix) Change texts so that the -yscrollcommand option is
invoked at display time, not when the window is re-layed out.  This
eliminated various core dumps that could occur if -yscrollcommand modified
the text.

-------------------- Release 3.4, 11/04/93 -------------------------

Note: there is no 3.5 release.  It was flawed and was thus withdrawn
shortly after it was released.

11/12/93 (bug fix) TkMain.c didn't compile on some systems because of
R_OK in call to "access".  Changed to eliminate call to "access".

-------------------- Release 3.6, 11/26/93 -------------------------

11/10/93 (bug fix) Packer and placer didn't always reposition a window
correctly if it was managed inside a neice or lower descendant (using
"-in" option) and the neice's parent moved.

11/24/93 (bug fix) Fixed time problem in selection (retrievals could
fail if retriever hasn't received any X events since selection was
made, so that time of retrieval appears to be older than time of
selection).  Selection code is now much less picky about times, both
on retrieving and supplying sides.

12/2/93 (new feature) Changed arrow-head drawing code for canvas
lines to draw a 0-width outline in addition to filling the area:
this produces much nicer, more symmetrical displays.

12/2/93 (bug fix) When colors ran out, Tk was invoking "tkerror"
when its state was internally inconsistent, which could cause
core dumps in some situations (e.g. if tkerror used the same color
that caused colors to run out).  Changed notification to occur
as a when-idle handler.

12/3/93 (bug fix) During a global grab, Tk wasn't including PointerMotion
in the list of grabbed events, so pointer motion couldn't be tracked
outside the grabbing application.

12/3/93 (bug fix) Canvases didn't handle smoothed lines correctly
when they only contained two points.

12/3/93 (bug fix) Fixed bug in tkWindow.c where certain kinds of
errors during window creation could cause Destroy events to be generated
for a window that was never completely initialized.

12/13/93 (bug fix) Fixed bug in tkTextDisp.c that resulted in core
dumps at line 1467 under exmh.  The exact situation is that a text
widget was being redisplayed at a time when it had a -yscrollcommand
option but hadn't yet been mapped onto the screen.

12/17/93 (bug fix) Fixed bug in tkWindow.c whereby new top-level windows
with non-default visuals still inherited border pixmap from parent (root),
which could cause visual clash and X error.

12/17/93 (bug fix) Fixed bug in tkTextDisp.c that caused round-off
error in the information passed to scroll commands.

12/18/93 (bug fix) Fixed bug in tkPack.c that caused core dumps in
some situations if a master with siblings packed "-in" it was deleted.

12/18/93 (bug fix) Added "compat" directory to distribution, since it's
referenced by tkConfig.h on some systems.

12/18/93 (performance improvement) Improved performance of appending to
a listbox, so that inserting N items doesn't take N**2 time.

12/20/93 (bug fix) Fixed bug in canvas ovals that caused the fill color
for the oval to stick out past the outline.

1/2/94 (fixed Xlib bug) Added code to reuse X resource identifiers so
that they won't run out in long running applications.  There are three
new library procedures: Tk_FreeXId, Tk_GetPixmap, and Tk_FreePixmap.
Modified all Tk code to use these procedures, so wish applications should
now be able to run forever without running out of identifiers.

1/10/94 (bug fix) tkCursor wasn't freeing pixmaps used to create
cursors, which caused memory leaks in programs that changed cursors
frequently.

1/21/94 (bug fix) Fixed bug in scales that caused them to loop
infinitely drawing tick-marks when -from and -to were the same.

2/2/94 (bug fix) Fixed problem where messages that contained tabs
didn't always compute the correct size, so that text spilled off
the right edge.  The fix adds an extra "tabOrigin" parameter to
the internal procedures TkMeasureChars, TkDisplayChars, and
TkUnderlineChars.

2/4/94 (bug fix) Fixed off-by-one problem in tkBind.c that caused
it to read past the initialized part of dispPtr->modKeyCodes.

2/7/94 (bug fix) Text widgets didn't handle grabs correctly, such
that the "current" character got stuck if a grab occurred while a
mouse button was down.  It would get unstuck until after the
next button press and release.

2/19/94 (bug fix) Fixed prolog.ps (prolog for Postscript printing from
canvases) so that it correctly prints all of the characters in the
ISO Latin-1 character set.

2/19/94 (bug fix) Modified tkBind.c to save and restore the interpreter's
result across the execution of binding scripts.  Otherwise if an event
triggers in the middle of some other script (e.g. a destroy event during
window creation, because there was an error in the creation command),
the interpreter's result gets lost.

2/19/94 (bug fix) Fixed bug in dealing with results of sent command
that could cause them to get lost in some situations.

2/21/94 (bug fix) Don't let user close a dialog window created by
tk_dialog, since this would cause tk_dialog to hang:  force the user
to select one of the dialog's buttons.

2/21/94 (bug fix) Fixed bug in canvas polygons whereby they didn't
correctly handle changes in the number of points (via "coords"
widget command).

2/23/94 (bug fix) Large bitmaps in canvases didn't print correctly
because they overflowed the 64-KB limit on strings in Postscript.
Changed canvas printing to split up large bitmaps into mutliple
smaller ones for printing.

2/25/94 (bug fix) The "." window was being set up with -width
and -height options, which interfered with geometry management (any
configuration change on "." causes the window to change size to
200x200, then change back again).

2/26/94 (bug fix) Fixed several bugs that occurred when a Destroy
event handler for a window deleted the window's parent.

3/3/94 (new features) Changes to binding mechanism:
    - The modifiers for "Alt", "Meta", and "M" are now computed by
      examining the modifier map, rather than being hardwired to
      M2, M1, and M1.
    - When processing events, one script is invoked for each object
      in the list passed to Tk_BindEvent, rather than stopping as
      soon as a script is invoked for some object.  The "break" and
      "continue" commands can be used within a script to abort all
      scripts for the event or the current one.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added "bindtags" command so that new binding groups can be
      defined for widgets and the evaluation order can be changed.
    - When matching events to bindings, extra modifiers are now ignored,
      as if "Any" were specified for every event.  The "Any" modifier
      is still recognized, but it is ignored and is deprecated.
      *** POTENTIAL INCOMPATIBILITY ***
    - In % sequences that print window identifiers (e.g. %a and %S), print
      in hexadecimal rather than decimal, for consistence with "winfo id".
      *** POTENTIAL INCOMPATIBILITY ***
    - The "bind" command no longer supports the event types CirculateRequest,
      ConfigureRequest, MapRequest, or ResizeRequest.  These event types
      are somewhat dangerous, and they never worked anyway.

3/13/94 (bug fix) Fixed numerous problems with the "wm iconwindow" command.
It appears that this command never really worked at all, but it should
work OK now.

3/14/94 (feature changes) Removed several obsolete features:
    - Eliminated "enable" and "disable" widget commands for menus.
      *** POTENTIAL INCOMPATIBILITY ***
    - Eliminated "activate" and "deactivate" widget commands for buttons,
      checkbuttons, radiobuttons, and menubuttons.
      *** POTENTIAL INCOMPATIBILITY ***
    - Removed -geometry option for frames and toplevels:  it causes
      problems when .Xdefaults files contain entries like
      "*geometry: +0+0".  Must use -width and -height instead.
      *** POTENTIAL INCOMPATIBILITY ***
    - Desupported "tkVersion" variable: use "tk_version" instead.
      *** POTENTIAL INCOMPATIBILITY ***

3/16/94 (feature changes) Changes to listboxes:
    - Eliminated -geometry option (it causes problems when .Xdefaults
      files contain entries like "*geometry: +0+0").  Added -width
      and -height options to use instead.
      *** POTENTIAL INCOMPATIBILITY ***

3/21/94 (bug fix) Fixed bug in tkOption.c where the option cache wasn't
properly cleaned up after window deletion;  this could cause the wrong
value from the option database to be used under some conditions.

3/25/94 (new features) Changes to geometry management:
    - Added Tk_MaintainGeometry and Tk_UnmaintainGeometry procedures
      to solve problems with -in windows.  Modified the packer, the
      placer, and canvases to use them.
    - Changed 2nd argument to Tk_ManageGeometry from Tk_GeometryProc *
      to a pointer to a structure with additional information about
      the geometry manager, such as name and procedure to call when
      slaves are stolen.
      *** POTENTIAL INCOMPATIBILITY ***

3/28/94 (new feature) Overhauled event management:
    - Added "cancel" option to the "after" command so that you can
      cancel previously-scheduled commands.
    - Separated X-specific stuff from generic event management.  The
      file tkEvent.c can now be used stand-alone without the rest of Tk.
      See the manual entry for Tk_EventInit for information on which
      procedures are available this way.
    - Added Tk_CreateFileHandler2 procedure, which provides a lower-level
      and more powerful form of file event handler.
    - Fixed bug in Tk_DoOneEvent where an infinite loop could occur if
      the TK_FILE_EVENT and TK_DONT_WAIT flags were set simultaneously
      (there were bugs with several other combinations too;  all should
      be fixed now).

3/28/94 (new feature) Added "fileevent" command, which allows event-
driven I/O in the style of Mark Diekhans' "addinput" command.

4/11/94 (new feature) Better support for colormaps and visuals:
    - Added new -colormap and -visual options to toplevels and frames.
    - Added "winfo visualsavailable" command.
    - Added "wm colormapwindows" command, plus support for WM_COLORMAP_WINDOWS
      to Tk_SetWindowColormap.
    - Added new library procedures Tk_GetVisual, Tk_GetColormap,
      and Tk_FreeColormap.

4/11/94 (bug fix) Fixed core dump that used to occur when specifying
an iconwindow ("wm iconwindow") for a toplevel on a different screen
than the main window.

4/23/94 (new feature) Added support for images, including the following:
    - New "image" command for creating images.
    - Built-in image type: bitmap.
    - New "image" item type in canvases.
    - Labels, buttons, checkbuttons, radiobuttons, menubuttons, and
      menu entries now support a -image option for displaying images.
    - Tk_CreateImageType and Tk_ImageChanged procedures, for defining
      new types of images in C.
    - Tk_GetImage, Tk_FreeImage, Tk_RedrawImage, and Tk_SizeOfImage
      procedures, for using images in widgets.

5/1/94 (new features) Added new procedures Tk_3DVerticalBevel and
Tk_3DHorizontalBevel.

5/11/94 (new features) Major overhaul of text widgets:
    - Implemented embedded windows and "window" widget command.
    - Added new configuration options for tags: -justify, -lmargin1,
      -lmargin2, -rmargin, -offset, -spacing1, -spacing2, and -spacing3.
      See the "Display styles" widget demo for examples.
    - Added new configuration options for texts: -spacing1, -spacing2,
      and -spacing3.
    - Added "tagList" option to "insert" widget command to control
      tags on new text.  Made tagged regions so they aren't sticky on
      either side:  new characters get a tag only if the old chars. on
      both sides had it.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added gravity for marks, and "mark gravity" widget command.
    - Added horizontal scrolling, "xview" widget command, -xscrollcommand
      option.  Changed "scan" widget commands to support horizontal
      scrolling.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added "search" widget command for searching (either exact matches
      or regular expressions).
    - New widget commands: bbox, dlineinfo, and see.
    - Changed implementation of bindings so that Enter and Leave
      events are not generated unless the tag has just become present
      (or just ceased to be present) on the current character.  Also
      changed bindings to process separately for each tag, rather than
      having high-priority tags override low-priority ones.
    - The "end" index now refers to the character after the last newline
      rather than the newline itself.  You can now tag the final newline
      and set a mark after the final newline.
    - Deletions of the "sel" tag and the "insert" and "current" marks
      are now ignored silently, rather than generating errors.  This means
      you can do things like "eval .t tag delete [.t tag names]".

5/19/94 (bug fix) Canvases didn't generate proper Postscript for stippled
text.

5/20/94 (new feature) Added "bell" command to ring the display's bell.

5/20/94 (new feature) Incorporated "square" demonstration widget into
tktest application.

5/20/94 (new features) Changed wish application (tkMain.c):
    - wish no longer processes the -help option.
      *** POTENTIAL INCOMPATIBILITY ***
    - The wish main program is now called Tk_Main;  tkAppInit.c has a
      "main" procedure that calls Tk_Main.  This makes it easier to use
      Tk with C++ programs, which need their own main programs, and it
      also allows an application to prefilter the argument list before
      calling Tk_Main.
      *** POTENTIAL INCOMPATIBILITY ***
    - The application's class is now the same as its name (except the
      first letter is capitalized), instead of "Tk".
      *** POTENTIAL INCOMPATIBILITY ***
    - The -file keyword is no longer required:  the script file name can
      be provided as the first argument without being preceded by "-file",
      as in tclsh.  For backward compatibility the "-file" keyword is
      ignored if it is the first argument, but it is deprecated.

5/26/94 (feature removed) Removed support for "fill" justify mode from
Tk_GetJustify and from the TK_CONFIG_JUSTIFY configuration option.  None
of the built-in widgets ever supported this mode anyway.
*** POTENTIAL INCOMPATIBILITY ***

5/27/94 (feature change) Changed Tk to use Tk_PrintDouble everywhere
that it converts reals to strings.  This means that floating-point
values will be generated in some cases where integer-like values were
generated before.
*** POTENTIAL INCOMPATIBILITY ***

6/1/94 (feature change) Renamed "pack newinfo" command to "pack info".
The old "pack info" command is no longer available.
*** POTENTIAL INCOMPATIBILITY ***

6/20/94 (feature changes) Overhaul of entry widgets:
    - Added "-justify" option.
    - Added "-show" option to make entries easier to use for passwords.
    - Added "cget" widget command.
    - Added "selection range" and "selection present" widget commands.
    - Added "anchor" symbolic index.
    - Changed "-scrollcommand" option to "-xscrollcommand", "view"
      widget command to "xview", for compatibility with other widgets.
      *** POTENTIAL INCOMPATIBILITY ***
    - Changed sel.last to refer to character just *after* last one
      selected, again for compatibility with other widgets.
      *** POTENTIAL INCOMPATIBILITY ***
    - For "delete" widget command, second index now refers to character
      just *after* last one to delete.
      *** POTENTIAL INCOMPATIBILITY ***
    - Overhauled bindings to be more Motif-compatible and to include
      common Emacs bindings for editing.
    - Changed -width option:  if specified as 0, widget sizes to fit
      its current text.

6/11/94 (new features) Improved Motif compatibility:
    - Added "-highlightwidth" and "-highlightcolor" options to all widgets.

6/27/94 (bug fix) Postscript generation for text items in canvases was
not justifying the text properly when a -width was specified that was
longer than the longest line.

6/27/94 (bug fix) "winfo exists" used to report a window as existing
if it was in the process of being destroyed (i.e., a destroy handler
is in the middle of execution).  Changed to report it as non-existent
under these conditions.
*** POTENTIAL INCOMPATIBILITY ***

7/11/94 (bug fix) Selections claimed via "selection own" weren't always
being cleared properly when the selection was claimed away.  Also fixed
bug where Tk wasn't properly claiming the selection, if there haven't
been any recent X events at the time of the claim.

7/13/94 (feature changes) Overhaul of scrollbar widgets:
    - New widget commands: "activate", "cget", "fraction", and "identify".
    - New options: -activebackground, -activerelief, -highlightcolor,
      -jump, -highlightthickness, and -troughcolor.  What used to be
      -background is now -troughcolor, -foreground is now -background,
      and -activeforeground is now -activebackground.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added new syntax for "set" command, "get" result, and generated
      commands.  Changed other widgets to use the new syntax.
    - Moved the bindings out of C and into Tcl scripts, using the new
      options and widget commands.  Added support for all Motif
      bindings, plus jump scrolling and cancelling of slider drags.

7/16/94 (bug fix) Canvases assumed that the Leave event for one item
didn't modify or delete the next current item;  this could cause core
dumps under some conditions.

7/23/94 (feature change) Modified Tk_BackgroundError so that tkerror
is invoked as an idle handler.  If tkerror generates a break exception
then all other queued reports are aborted.

8/14/94 (bug fix) "cursorOffTime" and "cursorOnTime" were confused in
canvases, resulting in the same time being used for both.

8/16/94 (bug fix) "tkwait variable" command didn't detect errors in
variable name, such as trying to wait for an entire array.

9/2/94 (new features) Overhaul of scale widgets:
    - Floating-point values are supported now, following Paul Mackerras'
      "fscale" widget.  Added "-resolution" and "-digits" options.
    - Added "-variable" option to link scale to variable, following
      Henning Schulzrinne's implementation.
    - Added focus highlight (-highlightthickness and -highlightcolor
      options).
    - Added new widget commands "cget",  "coords", "identify", plus
      improved "get";  removed wired-in bindings, added complete set
      of Motif bindings via Tcl scripts.
    - Changed -sliderforeground option to -background, -background to
      -troughColor, -activeforeground to -activebackground.
      *** POTENTIAL INCOMPATIBILITY ***
    - Moved value label from below horizontal scales to above the scale,
      for Motif compliance.

9/9/94 (bug fix) Fixed bug in tkWm.c that caused long delays in "raise"
command under some conditions (window already at the top of the stack).

9/10/94 (new features) Overhaul of label/button/checkbutton/radiobutton
widgets:
    - Added focus highlight (-highlightthickness and -highlightcolor
      options).
    - Added new widget command "cget".
    - Changed -selector option to -selectcolor, and changed its meaning
      too: empty no longer means don't draw the indicator;  it means
      don't use a special color when selected.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added -indicatoron (controls whether indicator is displayed) and
      -selectimage (gives special image to display when selected) options.
    - Modified bindings to be more Motif-like, added binding for space
      key.
    - Changed padding defaults to give widgets correct Motif appearance
      by default.  Also, changed to ignore padding options when displaying
      an image or bitmap.
      *** POTENTIAL INCOMPATIBILITY ***
    - Can now display text on multiple lines:  newlines cause line breaks,
      and word wrapping can be requested with -wraplength option.  Also
      added -justify and -underline options.
    - The -value option for radiobuttons can now have an empty string as
      its value;  it no longer defaults to the name of the widget.
      *** POTENTIAL INCOMPATIBILITY ***

9/13/94 (new features) Modified both canvases and messages to support
-highlightthickness and -highlightcolor options plus "cget" widget
command.

9/19/94 (new features) Added Tk_UnsetGrid procedure, modified widgets
to use it.  Also changed Tk_SetGrid so that at most one window per
toplevel can have gridding enabled.

9/23/94 (new features) Major overhaul of listbox widgets:
    - Added focus highlight (-highlightthickness and -highlightcolor
      options).
    - Added new widget command "cget".
    - Revised selection commands to support single selections as well
      as multiple disjoint selections;  syntax of "selection" widget
      command has changed to support this.  Added new option -selectmode
      for specifying which mode to use.  Default is single selection;
      tk_listboxSingleSelect procedure no longer exists.  Selections
      now return as items separated by newlines instead of a list whose
      elements are the items.
      *** POTENTIAL INCOMPATIBILITY ***
    - Extended "get" widget command to allow many items to be retrieved
      at once.
    - Added "bbox" widget command for finding position of an element on
      screen.
    - Added "activate" command to mark element with traversal focus.
    - Extended index mechanism to support new types of indices:
      "active", "anchor", "@x,y".
    - Added "see" widget command.
    - Revised bindings to include all Motif features except for AddMode.
    - If -width or -height option is <= 0, the widget requests a size just
      large enough to hold all of its text.

10/6/94 (new features) Overhaul of menubuttons:
    - Added focus highlight (-highlightthickness and -highlightcolor
      options).
    - Added new widget command "cget".
    - Added -indicatoron option to display option menu indicator.
    - The -menu option must be a child of the menubutton.
      *** POTENTIAL INCOMPATIBILITY ***

10/6/94 (new features) Overhaul of menu widgets:
    - Added new widget commands "cget" and "entrycget".
    - Changed the implementation of tear-off menus to be more
      Motif-like;  added -tearoff option for specifying whether
      tearoff entry is displayed.
    - Changed interpretation of "@y" index:  it now returns the
      closest entry, rather than "none" if y is outside the menu's
      range.
      *** POTENTIAL INCOMPATIBILITY ***
    - The -menu option for a cascade entry must now be a child of
      the menu.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added "type" widget command, so that you can query the type of
      an entry.
    - Added -foreground, -activeforeground, -selectcolor, -indicatoron,
      -image, and -selectimage options to menu entries.
    - Changed "selector" menu option to "selectColor" for Motif compliance.
      *** POTENTIAL INCOMPATIBILITY ***
    - Added -relief option for menus, just for consistency with other
      widgets (it was implicitly "raised" before).

10/6/94 (feature change) Completely overhauled the bindings for menus
and menubuttons.  They now fit better with other Tk 4.0 facilities,
such as the new binding mechanism, and they provide better Motif
compliance (e.g. keyboard traversal of submenus).  Also, the bindings
now support option menus, popup menus, and proper Motif tear-off
menus.

10/6/94 (obsolete features) The procedures tk_menuBar and
tk_bindForTraversal are no longer needed in Tk 4.0.  They still exist
for compability, but they do nothing.

10/6/94 (new procedures) Added "tk_popup" procedure for posting a
popup menu, and "tk_optionMenu" for creating an option menubutton
and its associated menu.

10/6/94 (change in name) The variable "tk_priv" has been renamed
to "tkPriv" to reflect that fact that it is private to Tk now.
This shouldn't cause any problems, since no-one except Tk should
have been using it before anyway (right?).

10/6/94 (bug fix) Fixed bug in texts where sometimes the text would
stop tracking mouse motion (the "current" item wouldn't get updated)
because the text widget missed a ButtonRelease event.

10/20/94 (new features) Overhauled selection code to support multiple
selections (primary, secondary, etc.) and multiple displays:
    - Changed "selection" command to support new options such as
      "-displayof" and "-selection".  Old command formats are still
      supported for compatibility, but they are no longer documented
      and are deprecated.
    - Changed procedures Tk_GetSelection, Tk_CreateSelHandler, and
      Tk_ClearSelection to take additional "selection" argument.
      *** POTENTIAL INCOMPATIBILITY ***
    - Selection targets APPLICATION and WINDOW_NAME have been replaced
      by TK_APPLICATION and TK_WINDOW.
      *** POTENTIAL INCOMPATIBILITY ***

10/20/94 (new features) Added support for clipboard:
    - New "clipboard" command.
    - C procedures Tk_ClipboardClear and Tk_ClipboardAppend.
    - Bindings for "cut", "paste", and "copy" for text and entry widgets,
      plus "copy" binding for listboxes.

10/24/94 (bug fix) Button widgets weren't checking for errors when
setting the values of associated variables.

11/3/94 (bug fix) Fixed bug whereby Tk would hang if "exit" was invoked
from inside a <Destroy> binding.

11/15/94 (new features) Overhaul of focus mechanism:
    - Added support for multiple displays:  separate focus windows are
      kept for each display.
    - Added support for keyboard traversal.
    - Changed focus model so Tk keeps track of a focus window for each
      top-level window and automatically sets the focus on Enter to the
      top-level.  Tk no longer synthesizes FocusIn and FocusOut events,
      but just uses the standard X mechanisms.  There is no "default"
      focus window anymore; the focus reverts to top-levels by default.
      *** POTENTIAL INCOMPATIBILITY ***
    - Changed focus command:  eliminated "focus default" and "focus none",
      added "-displayof" and "-lastfor" options.  An empty string is now
      used to signify "no focus" instead of "none".
      *** POTENTIAL INCOMPATIBILITY ***
    - Added library procedures tk_focusNext, tk_focusPrev, and
      tk_focusFollowsMouse.
    - Removed obsolete Tk_CreateFocusHandler:  must use FocusIn and
      FocusOut events now.
      *** POTENTIAL INCOMPATIBILITY ***

11/23/94 (new features) Overhaul of "send" command:
    - Added support for multiple displays: -displayof option to "send".
    - Added asynchronous sends: -async option to "send".
    - Eliminated fixed timeouts on sends:  as long as the target
      application appears to exist, the send will wait for it.
    - Stale entries get removed from the application registry now,
      so "winfo interps" should never return non-existent applications.
    - Can change the name of an application with "tk appname" command.
      This is also the preferred way of querying the application name
      now.
    - The errorCode and errorInfo variables are now propagated back to
      the sender now, so a full stack trace is available.
    - Tk checks display security on each send now, instead of just during
      initialization, so changes in the security status are seen immediately
      by all applications.
    - The above changes required changes to the data formats used for
      communication between source and target applications, so Tk 4.0
      applications cannot send to, or be sent from, Tk 3.6 applications.
      *** POTENTIAL INCOMPATIBILITY ***
    - The procedure Tk_RegisterInterp has been replaced with Tk_SetAppName.
      *** POTENTIAL INCOMPATIBILITY ***

12/6/94 (cleanup) Eliminated "interp" argument to Tk_GetColorByValue,
since it is no longer needed.
*** POTENTIAL INCOMPATIBILITY ***

12/7/94 (feature change) Changed the "wm" command so that top-level
windows are now resizable by default.  You can no longer specify
empty arguments to "wm maxsize" and "wm minsize".
*** POTENTIAL INCOMPATIBILITY ***

12/8/94 (new feature) Added new "photo" image type using code provided
by Paul Mackerras:  currently supports only PPM "P6" format images.

12/14/94 (new features) Canvas modifications:
    - Modified the interfaces between generic canvas code and the item
      types so that it's easy for people to write new item types outside
      of Tk.
    - Added support for transparent bitmap items:  just specify an
      empty string as the background color.
    - Changed the "xview" and "yview" commands for canvases to use the
      new scrolling syntax.
    - Eliminated -scrollincrement option.
      *** POTENTIAL INCOMPATIBILITY ***

12/14/94 (bug fix) Fixed bug where the dimensions of canvas arrowheads
scaled during a "scale" widget command, but the scaling was only
temporary and got lost on the next re-configure of the item.  The
correct behavior is for the arrowheads not to scale.

-------------------- Release 4.0b1, 12/23/94 -------------------------

12/26/94 (bug fix) Removed obsolete demos from Makefile (color, dialog,
size), fixed "install" target.

1/3/95 (bug fix) Fixed all procedure calls to explicitly cast arguments:
implicit conversions from prototypes don't work when compiling under
non-ANSI compilers.  Tk is now clean under gcc -Wconversion.

1/4/95 (bug fix) Used "screenX" without ever setting it in DisplayText
in tkCanvText.c:  caused tabs in canvas text items to get messed up.

1/4/95 (bug fix) Canvases forgot to register the built-in types if
Tk_CreateItemType was called before a canvas widget was created.

1/4/95 (bug fixes) Fixed glitches in various text bindings:
    - Up used to do nothing if the cursor was at 2.0.
    - Right used to make the cursor invisible if it was just before
      the final newline of the text.
    - Control-t didn't conform to Emacs;  made it conform to GNU Emacs.
    - Deleted Control-x binding, since it doesn't conform to anything and
      is confusing for Emacs users.

1/4/95 (bug fixes) Changed Control-t for entries just as for texts (see
above) an deleted Control-x for entries (see above).

1/4/95 (bug fix) The packer didn't map slaves unless the master was mapped;
this could cause slaves to get "lost" so that they weren't mapped until the
master resized.

1/5/95 (bug fix) Scrollbars weren't executing the proper code the first time
the mouse entered the widget;  this caused problems if tk_strictMotif was
set.

1/6/95 (bug fix) Fixed label/button/checkbutton/radiobutton/menubutton
widgets to allow arbitrary screen distances when specifying -width and
-height for an image or bitmap (the manual pages already documented this
but the code didn't implement it).

1/6/95 (new feature) Added very primitive support for input methods,
as suggested by Martin Forssen.  This should be enough for European
character sets (Compose key) but it isn't near enough for Asian
character sets.

1/8/95 (bug fix) Fixed problem in canvas "xview" and "yview" commands
where divide-by-zero errors could sometimes occur.

1/8/95 (bug fix) New event handler didn't properly handle files for
which both TK_READABLE and TK_WRITABLE were specified.

1/11/95 (bug fix) Fixed bug with text selections:  was returning count
too high for data, causing bogus garbage to appear when selection was
copied.

-------------------- Release 4.0b2, 1/12/95 -------------------------

1/27/95 (feature removal) Removed %D substitution from binding scripts:
wasn't portable, shouldn't be used anyway.
*** POTENTIAL INCOMPATIBILITY ***

1/27/95 (new features) Added -displayof options to the commands
"winfo atom", "winfo atomname", "winfo containing", "winfo interps",
and "winfo pathname".

1/27/95 (new feature) Added "idle" option to "after" command to run
scripts as idle handlers.

1/28/95 (new feature) Modified placer to make -x and -relx additive
if you specify both.  Same for -y and -rely, -width and -relwidth,
and -height and -relheight.  This makes it easy to make request such
as "make .a 2 pixels larger than .b".
*** POTENTIAL INCOMPATIBILITY ***

1/28/95 (new feature) Improved auto-grab mechanism in canvases (which
prevents current item from changing while a button is down):  changed
to report Enter and Leave events for the current item while a button
is down.  However, as before, no Enter events are reported for other
items until the button goes up.

1/28/95 (new feature) Bitmap images are now transparent if the -background
is specified as an empty string (-maskdata and -maskfile are ignored in
this case).  This is also the default.

1/28/95 (bug fix) Tk didn't support manufacturer- or site-specific keysyms
such as SunAudioMute.  Modified tkBind.c so that it uses XStringToKeysym
in addition to its own hash table, so that all keysyms are now available.

1/30/95 (feature change) Modified "clipboard append" so that it reclaims
the clipboard selection if it had been previously lost, rather than just
generating an error.  This handles certain race conditions more cleanly,
and also allows the use of programs like "xclipboard".

1/30/95 (new feature) Added -xscrollincrement and -yscrollincrement
options to canvases.

1/31/95 (bug fix) Geometry management was broken if a particular geometry
manager claimed a slave away from itself.

1/31/95 (bug fix) Fixed bug in tkVisual.c where a visual with fewer bits
than requested was being selected in preference to one with just the right
number of bits.

1/31/95 (bug fix) Texts weren't redisplaying the padding region properly
after changes in -padx or -pady.

1/31/95 (new features) More text improvements:
    - Extended "insert" widget command for texts to allow multiple
      text-tagList pairs in the same command.
    - Added -nocase option to "search" widget command.
    - Added -overstrike option to tags.
    - Added tab stops, via -tabs option for widget and for tags.

2/10/95 (bug fix) Modified all widgets to allow renaming of widget
commands.  Deleting a widget command will delete the widget.

2/11/95 (new feature) Added -highlightbackground option to all widgets.

2/14/95 (new feature) Added "insert" widget command for menus.

2/15/95 (new feature) Modified text display code (for all widgets) to
display well-known control characters like newline and backspace as
\n or \b instead of \xa.

2/15/95 (bug fix) Modified bitmap and photo image managers to delete
the image command when the image is deleted.  Also modified them to
allow renaming of the image command, and to delete the image if the
image command is deleted.

2/15/95 (bug fix) Fixed text widgets to allow horizontal scrolling
even if wrapping was enabled, if a line isn't entirely visible due to
a large character or embedded window.

2/16/95 (feature change) Added "postcascade" widget command to menus,
changed "invoke" and "activate" not to post or unpost submenus.  Also
fixed bug in redisplay that tended to leave bits of garbage on menu
when submenu unposted.
*** POTENTIAL INCOMPATIBILITY ***

2/16/95 (feature removal) Removed "snap back" behavior (slider
snaps back to old position if you move the mouse outside the widet
before releasing the button) from scrollbars and scales.

2/16/95 (bug fix) The last line of a listbox wasn't being displayed if
it was only partially visible.

2/16/95 (new features) Added support for "-resolution 0" (no rounding
of values) to scale widgets, plus smarter computation of how many digits
to display.

2/17/95 (bug fix) Fixed bug in text bindings for things like Shift-Left:
didn't properly set the anchor position.

2/20/95 (bug fix) Changed management of COLORMAP_WINDOWS property to
add the toplevel implicitly to the end of the list if it wasn't already
on the list somewhere.  Without this, some window managers implicitly
put it at the front of the list, so that colormaps in internal windows
are never used.

2/20/95 (bug fix) Changed to use separate command procedures for
button, checkbutton, label, and radiobutton commands.  This allows the
class commands to be renamed without breaking their behavior.

2/20/95 (removed feature) The "bind" command no longer supports
"Keymap" events;  they never worked anyway.

2/20/95 (bug fix) The text "search" widget command looped infinitely
when searching an empty text.

2/20/95 (bug fix) Canvases weren't redrawing their borders after
configuration changes.

2/20/95 (upgrade) Changed to use autoconf version 2.2.

2/21/95 (bug fix) Fixed several bug fixes in menu bindings that occur
when menus have no entries.

2/21/95 (bug fix) Fixed bug in geometry management that caused windows
packed -in siblings to not always be mapped and unmapped properly
(particularly when the toplevel got unmapped and mapped).

2/22/95 (bug fix) Fixed resource leak problem in tkTextDisp.c that
caused embedded windows not to be unmapped when off-screen.

2/23/95 (bug fix) "After cancel" dumped core when the script for an
after event cancelled itself.

2/24/95 (bug fix) Text and entry widgets weren't properly ignoring
Alt-, Control-, and Meta- keystrokes, so a widget-specific binding
for one of these resulted in the character also being inserted.

2/24/95 (bug fix) Several widgets accidentally performed unsigned
division on negative numbers, thereby losing the sign bit.  This
mostly affected the display of images and bitmaps in buttons,
menubuttons, and messages.

2/24/95 (feature reversal) Restored old behavior of %A so that it
returns non-printing characters as well as printing ones now.
*** POTENTIAL INCOMPATIBILITY with Tk 4.0b2, but not with Tk 3.6 ***

2/24/95 (bug fix) Duplicate "leave" events could occur for canvas
items under some conditions, due to recursive calls to PickCurrentItem.
Added code to detect and skip the nested calls.

2/24/95 (bug fix) Fixed bug where an error could occur during the first
keystroke in an application if its binding invoked "break".

2/25/95 (new feature) Modified syntax of "search" widget command for
texts.  The -nowrap switch and the "variable" final argument are no
longer supported.  Instead, there is a -count switch to replace
the final argument;  if the final argument is specified, it is now
a stopping index for the search.  The features of -nowrap can be
achieved now with the stopping index.
*** POTENTIAL INCOMPATIBILITY with Tk 4.0b2, but not with Tk 3.6 ***

2/27/95 (bug fix) Fixed problem that appears to prevent keyboard
input for working under IRIX:  tkBind.c was ignoring XmbLookupString
calls that returned a status of XLookupBoth.

2/27/95 (new feature) Added Tk_GetItemTypes procedure to return
information about available canvas item types.

2/27/95 (feature change) Changed Makefile to always use install-sh
for installations:  there's just too much variation among "install"
system programs, which makes installation flakey.

2/27/95 (bug fix) Fixed bug in tkSend.c that caused core dumps if
the app's main window was destroyed by a destroy handler on a
child.

3/5/95 (feature change) Change separator character used in "bind +..."
bindings from semi-colon to newline (permits bindings that are
comments, for what that's worth).

3/7/95 (bug fix/feature change) Overhauled focus code, both in C
and in Tcl:
    - Tk won't move the X focus in response to the "focus" command
      unless either the application already has the focus or the
      -force switch is specified.
    - Tk no longer sets the X focus to anything other than top-levels;
      it synthesizes events for FocusIn and FocusOut to children.
    - A window no longer has to be viewable when focussed to;  Tk will
      set the X focus later, when the window becomes viewable.
    - Added -takefocus option to all widgets.
    - Rewrote tk_focusPrev and tk_focusNext to use the -takefocus option.
      These procedures no longer set the focus;  they just return the
      next window in focus order.
      *** POTENTIAL INCOMPATIBILITY with Tk 4.0b2, but not with Tk 3.6 ***
    - Eliminated tk_focusContinue.
      *** POTENTIAL INCOMPATIBILITY with Tk 4.0b2, but not with Tk 3.6 ***

3/8/95 (new feature, bug fix) Added support for tk_strictMotif variable
in C:  Tk_StrictMotif library procedure.  Modified buttons, menubuttons,
menus to use it.  This fixes the problem with menus not supporting
tk_strictMotif properly in Tk4.0b1 and b2.

3/16/95 (feature overhaul) Overhauled color management:
    - Changed Tk so it never denies a color request because a colormap
      filled up.  Instead, it allocates the closest available color.
    - Eliminated "color model" mechanism.  The "tk colormodel" command
      is gone, as are the procedures Tk_GetColorModel and Tk_SetColorModel.
      *** POTENTIAL INCOMPATIBILITY ***
    - Changed 3D border implementation to allocate colors for shadows
      lazily, so they're never allocated if they're never used.  Also
      added new feature whereby stippling is used for borders when
      the colormap has run out of entries.  Changed arguments to many
      of Tk_3D C procedures to take a Tk_Window as argument instead of
      a (Display *).  This is needed to do lazy color allocation.
      *** POTENTIAL INCOMPATIBILITY ***
    - Eliminated colormap argument to Tk_GetColor, Tk_GetColorByValue,
      and Tk_Get3DBorder.
      *** POTENTIAL INCOMPATIBILITY ***

3/16/95 (feature change) Event bindings created from Tcl will now ignore
Enter, Leave, FocusIn, and FocusOut events with detail NotifyInferior.
This is done in anticipation of mega-widgets, so that the user of a
mega-widget can create Enter/Leave bindings on the mega-widget without
seeing spurious events as the mouse moves among the windows in the
mega-widget.
*** POTENTIAL INCOMPATIBILITY ***

3/17/95 (feature change) Changed C interfaces throughout Tk to use ints
instead of unsigneds:  the unsigneds turn out to cause subtle problems
with arithmetic in some places, and using ints everywhere is just
simpler.
*** POTENTIAL INCOMPATIBILITY ***

3/23/95 (bug fix) Selections longer than 4000 bytes were being
truncated to 4000 bytes.

-------------------- Release 4.0b3, 3/24/95 -------------------------

3/25/95 (bug fix) Changed "install" to "./install" in Makefile so that
"make install" will work even when "." isn't in the search path.

3/25/95 (bug fix) Modified Tk's selection mechanism to prevent core
dumps in other applications during retrievals of large selections
(this is actually a bug in the other apps, but I've patched Tk to
keep it from getting triggered).

3/25/95 (bug fix) Fixed bug where X window for "." wasn't being
deleted.

3/27/95 (bug fix) Fixed many bugs associated with having more than
one application in a single process.

3/28/95 (bug fix) The "search" widget command for texts didn't
return the correct index and count if there were embedded widgets
on the same line as the returned range but before the end of
the range.

3/28/95 (bug fix) Changed pasting via button 2 in text and entries
so that it inserts at the pointer location, not the location of
the insertion cursor.

3/28/95 (bug fix) Fixed several bugs related to <Destroy> bindings
that delete ancestors in the window hierarchy.  Also eliminated
extraneous calls to XDestroyWindow, which speeds up window deletion
by about 3x.

3/28/95 (bug fix) Several widgets (buttons, menubuttons, menus) didn't
properly handle image deletions that occurred while the widget was
being deleted (caused core dumps).

3/29/95 (bug fix) When retrieving long selections from text widgets,
parts of lines were getting duplicated in the selection information.

4/1/95 (bug fix) Fixed bug that caused infinite loop in horizontal
scales with 0 range.

4/1/95 (bug fix) Fixed problem with -command option for scrollbars and
-takefocus option that caused commands to be evaluated in the wrong
context.

4/1/95 (bug fix) Fixed problem with option database that caused it to
sometimes use the wrong option (wasn't flushing the database properly
after a change in a window's class).

4/1/95 (bug fix) If a line in a text widget just barely fit in the window,
Tk was allocating a second screen line just for the newline character.

4/1/95 (new feature) When backspacing in an entry widget, when you reach
the left edge of the widget, the insertion cursor gets recentered.

4/1/95 (new features) Added "winfo pointerx" and "winfo pointery" commands
to fetch the current pointer position.

4/6/95 (bug fix) If the last line of a text widget was only partially
visible, it was counted as visible for purposes of the scrollbar.  Now
it is treated as if it were off-screen for scrolling purposes.

4/6/95 (new feature) Modified "bell" command to reset screen saver as well.

4/6/95 (feature change) Modified menu scanning (where menus pull down
as you drag across their menubuttons) so it only works among menus
in the same toplevel;  it used to work for any menubuttons in the
application.

4/6/95 (bug fix) Canvas text items weren't allowing real numbers in
"@x,y" notation for specifying indices.

4/7/95 (bug fix) Menus didn't display correctly when -activeborderwidth
was large.

4/7/95 (bug fix) Changed "clipboard append" command to support -- option
and to always treat the last argument as data, even if it starts with
"-".

4/17/95 (new feature) Added -wrap option to text tags.

4/18/95 (bug fix) Listboxes and texts weren't updating their grid information
when -width or -height changed.

4/18/95 (bug fix) "Down" didn't work right in text widgets if the last
line was only partially visible in the window.

4/19/95 (bug fix) Listboxes didn't handle partially visible last lines
right:  couldn't scroll it into full visibility, for example.

4/20/95 (bug fix) If a toplevel was positioned with a command like
"wm geometry . -0-0", the window didn't reposition itself to maintain
that geometry after a size change.

4/21/95 (feature change) Changed order of binding tags so widget bindings
fire before class bindings.  New order is: widget, class, toplevel, all.
*** POTENTIAL INCOMPATIBILITY with Tk 4.0b3, but not with Tk 3.6 ***

4/23/95 (new feature) Added "winfo colormapfull" command.

4/23/95 (new feature) Buttons and radiobuttons and checkbuttons now
treat Return the same as Space, unless tk_strictMotif is set.

4/23/95 (bug fix) Modified menu tear-off procedure to duplicate the
binding tags and bindings of the original in the copy.

4/25/95 (bug fix and feature change) Modified mechanism for choosing
"best" visual to fix a bug where depth wasn't really getting highest
priority in all situations.

4/28/95 (bug fix) Failed text searches starting at "end" could result
in an infinite loop in Tk.

4/30/95 (new feature) Added "wm resizable" command to enable and
disable interactive resizing.

4/30/95 (new feature) Added "window names" widget command to texts:
returns a list of all embedded windows.

5/2/95 (feature change) Changed text searches so that forward searches
start at the given index, rather than the character just after the
given index.
*** POTENTIAL INCOMPATIBILITY with Tk 4.0b3, but not with Tk 3.6 ***

5/4/95 (bug fix) Default bit gravity for windows was wrong (it was
ForgetGravity) causing unnecessary flashing when windows were resized.

5/4/95 (feature change) Modified Tk_DoOneEvent so that it doesn't
sleep if there's nothing that will wake it up again (e.g. no file
or timer handlers).  Returns 0 immediately.

5/5/95 (configuration change) Changed to use BSDgettimeofday instead
of gettimeofday on systems like IRIX where BSDgettimeofday is
available.  This avoids compilation problems due to the different
interface to gettimeofday provided by IRIX.

5/5/95 (feature change) Changed binding mechanism so that all bindings
are created immediately at initialization time, rather than waiting
until the first FocusIn or Enter event for a class.

5/6/95 (feature change) Changed default text for labels, buttons,
checkbuttons, radiobuttons, menubuttons, and messages from " " to
"".

5/6/95 (bug fix) If the application was destroyed in the middle of
an "update" command, Tk would dump core.

5/6/95 (bug fix) Changed manual entries to use the standard .TH
macro instead of a custom .HS macro;  the .HS macro confuses index
generators like makewhatis.

5/6/95 (bug fix) Change "wm iconwindow" command to disable button
presses for the icon window.  This is needed so that the window
manager can get those events (X only allows button presses to go
to one client for a given window).

5/9/95 (new feature) When specifying visuals, can now use "best"
with a depth, e.g. "-visual {best 8}" to get the best 8-bit visual.

5/18/95 (bug fix) Fixed bug with -spacing* options for text widget:
screen distances weren't allowed, only integers.

5/20/95 (bug fix) Eliminated memory leaks in tkTextDisp.c and elsewhere.

5/22/95 (color change) Changed the Tk color palette to a gray scheme.
Also added a library procedure tk_setPalette that makes it easy to
change colors on the fly, and a procedure tk_bisque that restores the
previous light brown scheme.

5/28/95 (bug fix) Modified canvases so that the -width and -height
options refer to the space inside the borders, not the total widget
space.  Also changed "xview" and "yview" commands and scroll-increment
rounding to use the pixel just inside the borders, rather than (0,0).

5/28/95 (bug fix) Several widgets (e.g. entries, buttons, and menus)
didn't properly handle unsets of variables they were tracing, if the
variables were reference through upvars in procedures.

6/4/95 (bug fix) The placer wasn't rounding window widths right when
both -relx and -relwidth were specified (or -rely and -relheight) so
that rounding errors accumulated.

6/4/95 (feature improvement) Change parsing of text indices to handle
weird mark and tag names better (e.g. any string ending with ".first"
will now be parsed as a tag name, even if it contains embedded spaces,
etc.).

6/4/95 (feature change) If a font defines glyphs for control characters,
they are now displayed, instead of translating the character to a
backslash sequence (however, tabs and newlines are still treated
specially;  glyphs are not displayed for these characters).

6/4/95 (bug fix) Modify the implementation of "raise" and "lower" for
toplevels so that it now works under olwm and olvwm.  It didn't use to
work, and the problem is really in the window manager, but Tk now
patches around it.  However, only "total" raises and lowers work:
raising and lowering relative to a sibling still don't work under
olvwm and olwm.

6/4/95 (feature change) Modified tab code in texts so that a tab always
occupies at least as much space as a space character.

6/4/95 (bug fix) The "%t" substitution wasn't being made properly in
Enter and Leave event bindings.

6/7/95 (new feature) Added support for GIF images.  Unfortunately it's
a bit fragile:  certain kinds of badly formed images can cause core
dumps;  I don't know enough about the GIF reader (taken from giftoppm)
to figure this out.

6/7/95 (bug fix and feature change) Fixed PPM image reader to be more
flexible about header formats, and added support for PGM images.

6/7/95 (feature change) Added -outlinestipple option to canvas arc
items, changed "-style arc" to use -outline as the color instead of
-fill (the old approach was pretty quirky).
*** POTENTIAL INCOMPATIBILITY ***

6/8/95 (feature change) Modified interface to Tk_Main to pass in the
address of the application-specific initialization procedure.
Tcl_AppInit is no longer hardwired into Tk_Main.  This is needed
in order to make Tcl a shared library.

6/8/95 (feature change) Modified Makefile so that the installed versions
of wish and libtk.a have version number in them (e.g. wish4.0 and
libtk4.0.a) and the library directory name also has an embedded version
number (e.g., /usr/local/lib/tk4.0).  This should make it easier for
Tk 4.0 to coexist with earlier versions.

6/9/95 (new feature) Added -outline and -width options to canvas polygon
items.

6/9/95 (feature changed) Renamed -decimate in photo widget to -subsample
(decimate wasn't technically correct).
*** POTENTIAL INCOMPATIBILITY with Tk 4.0b3, but not with Tk 3.6 ***

-------------------- Release 4.0b4, 6/16/95 -------------------------

6/19/95 (bug fix) Colors weren't being rounded correctly in canvas
Postscript generation: caused "white" to appear slightly gray when
the display of the canvas used only 8 bits per color.

6/20/95 (bug fix) "bbox" widget command for texts didn't return
proper width for tabs.

6/20/95 (bug fix) Scrollbars didn't always work right for texts:
couldn't scroll all the way to the bottom of the text in a single
drag of the slider.

6/20/95 (new feature) Added "delta" widget command for scrollbars
(needed for above bug fix).

6/23/95 (bug fix) Listboxes weren't properly redisplaying their
borders when the were configured to a smaller size.

6/23/95 (new feature) Added "winfo server" command.

6/23/95 (bug fix) If a menu was posted, couldn't switch to another
menu with an Alt- key.

6/24/95 (new feature) Added "winfo pointerxy" command.

6/25/95 (bug fix) Tk_ParseArgv referenced beyond the end of 0-length
option names.

6/25/95 (bug fix) Fixed problem in tkOption.c where "cachedWindow"
could get garbage in it if the main window's class was changed by
calling Tk_SetClass.

6/25/95 (bug fix) Fixed two bugs in menus, one where errors in
variable traces weren't propagated correctly and one where "invoke"
was invoked at the wrong stack level, with the result that variable
traces didn't have access to the right variables.

6/27/95 (bug fix) tk3d.c wasn't using all the right information
when deciding whether or not to stipple borders, so it stippled
borders even on 16-bit true-color displays.

6/28/95 (bug fix) Page up and down operations in texts could cause
insertion cursor to drift to the right.  Changed tkTextScrollPages
to use upper-left corner of current character, rather than center
of character.

6/28/95 (bug fix) Changed text widget so that you can't put the
insertion cursor after the last newline in the text.

6/28/95 (bug fix) Bitmap images didn't allow ~'s in file names.

6/28/95 (bug fix) Fixed problem that could cause core dumps in the
text widget when dealing with embedded windows (there were problems
if the act of redisplaying caused the window layout to change, which
can happen with embedded windows).

6/28/95 (bug fix) Texts didn't handle indices with double negatives,
such as ".t mark set insert {insert + -20 chars}".

6/28/95 (bug fix) Fixed problem where focus didn't always revert to
its prior window after a dialog box was dismissed.

6/28/95 (bug fix) Fixed problem with "search" widget command returning
incorrect length on some backwards regexp searches.

6/28/95 (bug fix) Successive "wm iconbitmap . {}" commands could cause
a core dump.

6/29/95 (new feature) Added -elementborderwidth option for scrollbars
so the -borderwidth can be set to 0 without flattening the arrows and
slider.

-------------------- Release 4.0, 7/1/95 -------------------------

7/18/95 (bug fix) %t in event bindings didn't work properly for some
events (e.g. PropertyNotify).

7/18/95 (bug fix) Changed "exec wish" lines in demo scripts to
"exec wish4.0" to avoid version conflicts.

7/18/95 (bug fix) Fixed round-off errors in scrolling for texts,
canvases, listboxes, and entries.  The error could cause the view
to shift up in a command like "$w yview moveto [lindex [$w yview] 0]".

7/19/95 (bug fix) Canvases weren't always redrawing borders correctly
when they became unobscured.  There were also some problems with
improper refresh after size changes.

7/19/95 (bug fix) Fixed bug in text index processing that causes
tests textIndex-11.1 and textIndex12.1 to fail on some platforms.

7/19/95 (bug fix) Fixed bug where 2-second delays were ocurring during
"raise" and "lower" commands for toplevel windows under some window
managers (such as fvwm).

7/20/95 (bug fix) Text searches were misbehaving when there were embedded
windows on the starting line of the search.  The most common symptom is
that Tk would fail to find a match at the starting position for the
search.

7/22/95 (bug fix) Fixed core dump that could occur in menus if a checkbutton
entry's -variable option referred to an array (or couldn't be read
by the menu C code for some other reason).

7/22/95 (bug fix) Text widgets didn't update their scrollbars when
changes were made to information that was off-screen.

7/25/95 (bug fix) Fixed core-dump in tkListbox.c that used to happen
in the command ".l bbox end" if the listbox was empty.

7/25/95 (bug fix) Page-up and page-down bindings for listboxes didn't
move active element to remain on the screen.

7/25/95 (bug fix) Patched around H-P compiler problem that results in
core-dumps in tkImgPhoto.c during image handling.

7/25/95 (bug fix) Fixed bug in tkImgPhoto.c that caused core dumps
(during Tk self-tests and other image uses) on AIX and other machines
where "schar" in tkImgPhoto.c was being defined as "short" instead of
"char".

7/26/95 (bug fix) The PPM image reader couldn't handle maximum intensity
values other than 255.

7/26/95 (bug fix) Canvases didn't redraw their borders when the relief
changed from raised to flat.

7/27/95 (bug fix) Canvases didn't set the scrolling values correctly
when no scroll region was specified.

7/28/95 (bug fix) Modified menu and tk_dialog scripts to restore any
old grab that might have been in effect before a menu or dialog was
posted.

----------------- Released patch 4.0p1, 7/29/95 ----------------------

8/4/95 (bug fix) Calls to toupper and tolower weren't using the UCHAR
macro, so they didn't always work in non-U.S. locales. (JO)

8/14/95 (new feature) Added -tearoffcommand option for menus.

8/16/95 (bug fix) Canvases didn't generate proper Enter and Leave
events if the Leave handler for an item reconfigured the canvas in
a way that made the old current item the new current item again. (JO)

8/21/95 (bug fix/feature change) When -takefocus was a script, Tk
was allowing window viewability to override it.  Changed so that
viewability is now ignored when -takefocus is a script. (JO)

8/21/95 (bug fixes) Fixed memory leaks in tkSend.c, tkSelect.c, and
tkUnixWm.c (JO).

8/21/95 (bug fix) Text widgets didn't handle commands like
".t search -backwards foo end 1.0" properly:  never found foo. (JO)

8/23/95 (new feature) Added Makefile and configure.in support for
dynamic loading. (JO)

8/25/95 (bug fix) The "frame" and "toplevel" commands couldn't safely
be renamed, due to a kludgy way that they shared a single command
procedure.  Split into separate procedures. (JO)

8/25/95 (bug fix) Fixed bug in libary/menu.tcl that caused "grab
window not visible" errors for popup menus (and perhaps elsewhere?). (JO)

8/25/95 (bug fix / new feature) The "gray25" bitmap was really only
12.5% on, not 25%.  Added new "gray12" bitmap that is the same as the
old "gray25".  "Gray25" is still supported for compatibility, but its
use is deprecated. (JO)

8/25/95 (bug fix) Scrollbar bindings didn't properly handle case where
B2 is clicked while B1 is already down. (JO)

8/26/95 (bug fix) Menus were ignoring -activebackground if tk_strictMotif
was set, but not -activeforeground.  Changed to ignore both. (JO)

8/26/95 (bug fix) Scales and scrollbars didn't properly handle a
-repeatdelay value of 0 (they shouldn't auto-repeat in this case). (JO)

8/28/95 (bug fix) Tcl errors were occurring for tkPriv(oldGrab) when
clicking on a disabled option menu. (JO)

8/28/95 (bug fix) Changed event-handling code to use FD_SETSIZE instead
of OPEN_MAX, since OPEN_MAX is incorrect on some systems (e.g., IRIX). (JO)

8/28/95 (bug fix) Fixed bug in photo images that caused garbling of
image data in the "put" and "copy" commands if the source data had
only one scan line but had a width less than the width of the target
image. (JO)

8/29/95 (bug fix) Tk used to refuse to post menus if they had no
entries.  This made it impossible for a menu to fill itself the first
time it is posted.  Changed to allow menus with no entries to be
posted. (JO)

8/30/95 (bug fix) If there was extra space at the bottom of a menu,
it wasn't being redisplayed properly.

8/30/95 (new feature) Added -transient option to menus.

8/30/95 (new features) Added proper button 2 support to both scrollbars
and scales (it sets the slider position from the mouse position). (JO)

8/30/95 (bug fix) Fixed potential core dump that could occur in
photo images (ReadPPMFileHeader could overflow buffer under some bad
inputs, such as certain GIF images). (JO)

8/30/95 (bug fix) Errors of the form `syntax error in expression "!"'
could occasionally happen in tkScaleDrag. (JO)

8/31/95 (new feature) Changed man page installation (with "mkLinks"
script) to create additional links for manual pages corresponding to
each of the procedure and command names described in the pages. (JO)

9/1/95 (new feature) Added "after info" command.  Also added checks
so that one interpreter can't cancel another's "after" events. (JO)

9/8/95 (bug fix) Fixed bug that could cause memory corruption and core
dumps if a "fileevent" handler was deleted while the handler was
active. (JO)

9/11/95 Reorganized Tk sources for Windows and Mac ports.  All sources
are now in subdirectories:  "generic" contains sources that work on all
platforms, "windows", "mac", and "unix" directories contain platform-
specific sources.  (SS)

9/11/95 (new feature) Added new  "notifier" mechanism to allow multiple
implementations of the mechanisms for finding out about events.  This
change was necessary to support Mac and PC platforms, but it may also
allow other goodies such as combining Xt and Tk widgets in a single
application.  See the new manual entry Notifier.3 for details. (SS)

9/11/95 (feature change) Changed interface to Tk_RestrictProc so that
(a) it takes a clientData argument instead of display and arg, and
(b) it returns a value that can ask for the event to be discarded as well
as deferred or processed. (SS)
*** POTENTIAL INCOMPATIBILITY ***

9/11/95 (new feature) Added TK_WINDOW_EVENTS #define, which is equivalent
to TK_X_EVENTS but is now preferred, since it applies to all platforms. (SS)

9/11/95 (feature change) Can't export variables anymore because this doesn't
work under Windows DLLs.  Eliminated tk_NumMainWindows variable and replaced
with procedure Tk_GetNumMainWindows. (SS)
*** POTENTIAL INCOMPATIBILITY ***

9/11/95 (new feature) Added procedure Tk_PreserveColormap to increment
the reference count on colormaps.  Used in photo widgets. (SS)

----------------- Released patch 4.0p2, 9/15/95 ----------------------

----------------- Released 4.1a1, 9/15/95 ----------------------

9/22/95 (renamed files) Changed the names of the bitmap images in the
$tk_library/demos/images directory to use the .bmap file extension.  (RJ)

9/22/95 (bug fix) Fixed bug where text widgets could occasionally
display the insertion cursor both at the end of one line and the
beginning of the next. (JO)

9/25/95 (bug fix) Fixed bug that could cause core dumps when an
application uses multiple screens and a binding destroys the main
window (bind code was using MainInfo structure after it had been
freed). (JO)

9/25/95 (bug fix) Text widgets sometimes scrolled backwards on
occasion if you dragged down past the bottom of the scrollbar. (JO)

9/25/95 (bug fix) Fixed bug in menus where a cascaded submenu posted
from a torn-off menu could be left posted if mouse was pulled off the
end of the cascade and released. (JO)

9/25/95 (new feature) Added "--" switch to wish, so that you can
pass arguments like -n through to a script without having wish
interpret them. (JO)

9/25/95 (bug fix) Fixed core dump that could occur for radiobuttons
and selectbuttons if -selectcolor was an empty string. (JO)

9/26/95 (bug fix) Entries didn't used to notice if a trace procedure
on the -textvariable overrode a new value set by the entry.  This
could cause the variable to get out of sync with the contents of the
entry. (JO)

9/26/95 (new feature) Added -sliderrelief option to scales, changed
default bindings to change the slider's relief to sunken while it's
being dragged with the mouse. (JO)

9/26/95 (bug fix) TkColor.c wasn't computing colormap size correctly;
could result in X Protocol error for QueryColors when colormaps run
out of colors. (JO)

9/26/95 (bug fix) Wish couldn't handle script files with spaces in
their names. (JO)

9/27/95 (cosmetic clean-up) Removed extraneous spaces to make error
messages consistent: ":  should be" is now ": should be". (JO)

9/27/95 (feature change)  Modified tk_dialog so that it uses the
option database for the -wraplength option on the message.  This
allows the option to be overridden by the caller. (JO)

9/28/95 (bug fix) Wish incorrectly parsed the command line under
Windows, causing backslashes to be substituted. (SS)

9/28/95 (bug fix) Wish now sources wishrc.tcl instead of .wishrc. (SS)

9/28/95 (bug fix) Tk_DoOneEvent returned 0 under some circumstances
when it was possible to find more work to do.  For example, if a
signal interrupted select(), but no event handlers were triggered, it
would return 0 even though it could still detect events by reentering
select().  (SS)

9/29/95 (bug fix) "winfo interps" caused a crash under Windows. (SS)

10/1/95 (feature change) Eliminated Tk_NotifyIdle interface in favor of
Tk_IdlePending. (SS)

10/1/95 (bug fix) Turned motion event collapsing into an idle handler
so it will be easier to move the event loop into Tcl. (SS)

10/1/95 (bug fix) Fixed several problems with negative coordinates
in canvases.  One example:  dragging a canvas rectangle with a wide
border and fractional coordinates could leave junk on the screen
if the rectangle was in negative coordinate space. (JO)

10/2/95 (bug fix) Tk was improperly handling Enter/Leave events
during a button grab. (SS)

10/2/95 (new feature) Added support for the Macintosh do script
('dosc') event.  Available only on the Macintosh.  (RJ)

10/4/95 (new feature) Added support for compiling with VC++.
Resulting binaries work under Win32s through NT.

----------------- Released 4.1a2, 10/6/95 ----------------------

10/10/95 (new feature) Macintosh Tk now supports the complete set
of X cursors that Unix Tk supports. (RJ)

10/11/95 (bug fix) Tk now supports all of the X11 cursors under
Windows.  (SS)

10/11/95 (bug fix) The "wm resizable" command was missing from the
Windows version of Tk. (SS)

10/12/95 (bug fix) Macintosh Tk had problems with clipping toplevel
windows that children of any frame other than another toplevel. (RJ)

10/13/95 (bug fix) Eliminated dependency on MKS toolkit for generating
the tk.def file from Borland object files. (SS)

10/16/95 (bug fix) Fixed clipping and update problems relating to
the raising and lowering of overlapping windows on Mac. (RJ)

10/30/95 (bug fix) When focus-follows-mode (invoked via tk_focusFollowsMouse),
was focussing on windows even in situations where keyboard traversal would
skip the window.  Changed to use the tkFocusOK procedure so that the
criteria for focussing are the same in both modes. (JO)

11/2/95 (bug fix) Changed listbox bindings to ignore double-clicks.
This avoids errors that used to occur if a user defined a binding
for double-click that deleted the listbox. (JO)

11/3/95 (feature change) Moved most of the Tk event loop to Tcl.  Many
Tk_ names have become Tcl names now:

TK_READABLE =>		TCL_READABLE
TK_WRITABLE =>		TCL_WRITABLE
TK_EXCEPTION =>		TCL_EXCEPTION
TK_DONT_WAIT =>		TCL_DONT_WAIT
TK_WINDOW_EVENTS =>	TCL_WINDOW_EVENTS
TK_FILE_EVENTS =>	TCL_FILE_EVENTS
TK_TIMER_EVENTS =>	TCL_TIMER_EVENTS
TK_IDLE_EVENTS =>	TCL_IDLE_EVENTS
TK_ALL_EVENTS =>	TCL_ALL_EVENTS
Tk_IdleProc =>		Tcl_IdleProc
Tk_FileProc =>		Tcl_FileProc
Tk_TimerProc =>		Tcl_TimerProc
Tk_TimerToken =>	Tcl_TimerToken
Tk_BackgroundError =>	Tcl_BackgroundError
Tk_CancelIdleCall =>	Tcl_CancelIdleCall
Tk_CreateFileHandler =>	Tcl_CreateFileHandler
Tk_CreateTimerHandler =>Tcl_CreateTimerHandler
Tk_DeleteFileHandler =>	Tcl_DeleteFileHandler
Tk_DeleteTimerHandler =>Tk_DeleteTimerHandler
Tk_DoOneEvent =>	Tcl_DoOneEvent
Tk_DoWhenIdle =>	Tcl_DoWhenIdle
Tk_Sleep =>		Tcl_Sleep
tkerror =>		bgerror

Other than the name changes, the functions are the same.  In addition,
there are #defines in tk.h so that the old Tk names will still work.
tkerror and bgerror are specially hacked as synonyms, so it should be
safe to use either one.  You should switch to the new Tcl names ASAP,
though, since the old Tk names will eventually be desupported. (JO)

11/7/95 (features removed) As part of moving the event loop to Tcl,
the following procedures were deleted:
    - Tk_EventInit (the presence of the event loop in Tcl should
      make this unneccessary).
    - Tk_CreatFileHandler2 (you can get the same effect by using event
      sources in Tcl, but you have to modify your code to use the new
      Tcl APIs).
    - All of the stuff in the manual entries Notifer.3 and QueueEvent.3;
      this has changed because the notifier got reworked when it was
      moved to Tcl.
*** POTENTIAL INCOMPATIBILITY ***

11/7/95 (feature change)  Changed to use exit handler to cleanup windows
in Tk, so Tk no longer needs to have a private copy of the "exit" command.
(JO)

11/7/95 (bug fix) If wish was invoked with a command-line geometry and
a script file (e.g. "wish foo.tcl -geometry 30x20"), and if one of
the windows created by the script used the -setgrid option, then the
width and height from the command line were lost. (JO)

11/8/95 (bug fix) The "see" command didn't work quite right for texts:
if the window was small and you try to "see" a line just offscreen,
Tk centered the line (actually, mis-centered it) when it should have
aligned it at the top or bottom. (JO)

11/9/95 (bug fix) The "send" command crashed if you tried to send to
a different display with "-displayof". (JO)

11/9/95 (bug fix) The Symbol font didn't print right in Postscript
output, because of changes made to re-encode fonts to get proper
ISO Latin1 behavior.  Changed the code not to re-encode the Symbol
font. (JO)

11/13/95 (bug fix) Fixed Makefile.in and configure.in for UNIX so that
configure can be run from a clean directory separate from the Tcl source
tree, and compilations can be performed there. (JO)

11/17/95 (bug fix) If a window was gridded, Tk still computed the
default maximum dimensions in pixel units, which resulted in windows
that could grow much larger than the screen. (JO)

11/17/95 (bug fix) If a menus entries were all disabled, posting
the menu and typing Up or Down caused an infinite loop, locking
up the screen (JO).

11/19/95 (bug fix) The focus wasn't being restored properly after a
menu selection in a cascaded menu. (JO)

11/19/95 (bug fix) Menubutton's didn't stipple display their images
differently when disabled.  Change to have the same behavior as buttons:
the image is stippled over in the background color when the menubutton
is disabled. (JO)

11/21/95 (bug fix) Changes in display attributes such as font could
cause core dumps in the text widget under some circumstances involving
line wrapping. (JO)

11/22/95 (bug fix/new feature)  Changed both the placer and the packer
to ensure that slaves are unmapped whenever the master is unmapped.
This saves time that slaves might otherwise spend trying to redisplay
themselves when they're unmapped. (JO)

11/22/95 (bug fix) Space and return keys didn't work for menus if
they were posted via Alt-x keystrokes. (JO)

11/24/95 (bug fix) tk_dialog procedure had binding for <Return> that
always activated default binding, even if input focus was in some
other binding.  Removed this feature, since existing focus support
will already "do the right thing".  (JO)

11/24/95 (bug fix) Both canvases and texts could dump core if a binding
(such as ButtonRelease on an internal item) deleted the widget. (JO)

11/24/95 (feature change) Replaced "configInfo" file with tkConfig.sh,
which is more complete and uses slightly different names.  Also
arranged for tkConfig.sh to be installed in the platform-specific
library directory. (JO)

11/24/95 (bug fix) It was possible for a slave to be placed or packed
-in itself, with unpleasant consequences.  It is now an error for the
slave to be its own master for geometry management. (JO)

11/25/95 (bug fix) The -command option of scales was sometimes being
invoked spuriously (e.g. when the mouse moved in the scale without a
button down).  This was because the scale wasn't rounding properly
when setting the scale value from its associated variable. (JO)

----------------- Released patch 4.0p3, 11/28/95 ----------------------

12/18/95 (feature change) Moved Tk_Preserve, Tk_Release, and
Tk_EventuallyFree to Tcl, renamed to Tcl_Preserve etc.  Added #defines
to tk.h so that the old names still work.  (JO)

12/23/95 (bug fix) If a single process had > 1 Tk application, Tk
didn't guarantee that the application names were unique, which could
cause all sorts of confusion with "send".  (JO)

12/23/95 (feature change) Eliminated Tk_CreateMainWindow and moved
all of its functionality to Tk_Init.  All that you need to do now
to get Tk in an application is to call Tk_Init.  Improved Tk_Init
so that -colormap and -visual command-line arguments are now passed
through to TkCreateFrame.  Tk_Main is much simpler now, since a lot
of its functionality has moved to Tk_Init. (JO)
*** POTENTIAL INCOMPATIBILITY ***

12/23/95 (new feature) Added support for Tcl_StaticPackage so
that Tk can now be loaded into slave interpreters with the "load"
command to create new applications. (JO)

12/23/95 (new features) Added support for -colormap and -visual command-
line options for wish. (JO)

1/4/95 (bug fix) Fixed keyboard code to properly handle alt-key
sequences for international keyboards and menu-accelerators. (SS)

1/5/96 (bug fix) Scrollbar code sometimes generated errors on accesses
to tkPriv(relief) during control-clicks. (JO)

1/9/96 (new feature) added the "grid" command to provide a table based
geometry manager. (SU)

1/12/96 (performance optimization) Changed the way tag information is kept
in the text's Btree so the cost of adding and removing tag ranges is no longer
proportional to the number of unique tags in the text.  In the old system
the cost of adding N unique tags was O(N-squared).  The new implementation is
optimized for tags that only cover a small amount of text, measuring from
their earliest tag range to the end of their last range.  In the best case the
cost of adding a tag range is unrelated to the number of unique tags, so the
cost of adding N tags is only O(N).  In the worst case, where all tags
cover all the text, the cost is still O(N-squared) to add N such tags.
Deleting tags still has an O(N) cost (so deleting N tags is O(N-squared),
but it is now a factor of 2 faster than the old system. (BW)

1/12/96 (new feature) added the text "dump" operation that returns information
about all elements in a text widget: text, tags, marks, and windows. (BW)

1/12/96 (new feature) added the text "mark next" and "mark previous" operations
to search forward and backwards for the next (previous) mark in the text. (BW)

1/12/96 (new feature) added the text "tag prevrange" operation to search
backwards for the current or previous range of a tag. (BW)

1/16/96 (new feature) Added support for relative widget placement on
the "grid" command. (SU)

1/17/96 (new feature) Modified the Makefile/configure setup to support
compiling Tk as a shared library.  Use the --enable-shared option to
the "configure" script. (JO)

----------------- Released 4.1b1, 1/26/96 -----------------------

2/2/96 (bug fix) Frames were getting a default size of 200x200, whereas
there should be no default. (JO)

2/2/96 (bug fix) Argc wasn't getting reset properly after Tk removed
the arguments it understood from those on the command line. (JO)

2/6/96 (bug fix) Fixed off by one error in argument parsing code under
Windows. (SS)

2/6/96 (bug fix) "wm transient" now works under Windows.  The resulting
toplevel is created with a modal dialog box frame and will not appear
in the taskbar under Windows '95. (SS)

2/9/96 (bug fix) Changed Makefile.in to use -L and -l for Tcl and Tk
libraries so that shared libraries are more likely to be found correctly
on more platforms. (JO)

2/14/96 (feature change) Eliminated tk_CanvasTagsOption variable because
it can't be exported safely across DLL boundaries.  Instead, exported
Tk_CanvasTagsParseProc and Tk_CanvasTagsPrintProc procedures for
use by canvas type managers in creating their own custom options. (JO)
*** POTENTIAL INCOMPATIBILITY ***

2/14/96 (bug fix) "winfo pointerxy" when applied to a non-toplevel window
crashed wish.  (SS)

2/14/96 (bug fix) "tkwait visibility" would hang under Windows. (SS)

2/14/96 (bug fix) Cursors were not being updated until an enter event.
In cases where the cursor left the toplevel and reentered before Tk
noticed, the cursor would get "stuck" until the next enter event.
Similarly, if the cursor attribute of a window was updated while the
mouse was in the window, the cursor would not change until the next
time the mouse entered the window. (SS)

2/15/96 (bug fix) If a top-level was resizable in one direction
(e.g. "wm resizable . 0 1"), once the user resized it any changes
in the internally requested size (by the widgets) were ignored,
even for the non-resizable dimension.  Fixed to handle the two
dimensions totally independently, so the widget's requests are
honored as long as that dimension hasn't been set by the user. (JO)

2/17/96 (bug fix) If a text widget had very long lines (e.g. more than
32K pixels), integer overflow could occur, resulting in parts of the
line not being visible. (JO)

2/20/96 (feature change) Changed the -minsize option of grid to take
screen units instead of pixels. (SU)

2/20/96 (bug fix) grid row and column weights are compared against
MINWEIGHT (0.001) instead of 0.0 to guard against divide by zero errors
during weight normalization. (SU)

2/20/96 (bug fix) Menu commands were not being invoked sometimes.
There was a race condition that caused events to be processed while a
menu was being unposted. (SS)

----------------- Released 4.1b2, 2/23/96 -----------------------

2/23/96 (bug fix) Alt-keys invoked in torn-off and popped up menus
caused menus to be posted in the parent toplevel. (JO)

2/23/96 (bug fix) Canvases weren't always updating their scrollbars
when they should. (JO)

2/23/96 (bug fix) Fixed core dump that could occur if a WM_DELETE_PROTOCOL
handler generated an error. (JO)

2/24/96 (bug fix) Removed dependencies on Makefile in the UNIX Makefile:
this caused problems on some platforms (like Linux?). (JO)

2/24/96 (feature change) Changed text and entry widgets so that they
set the insertion cursor before inserting during a button-2 click.
Also made optional bindings check for tk_strictMotif at the time of
the event, rather than at the time the bindings are created. (JO)

2/24/96 (bug fix) Tk tended to crash with an X error when unsetting
an icon window (e.g. "wm iconwindow . {}"). (JO)

2/25/96 (bug fix) Wasn't removing windows from the WM_COLORMAP_WINDOWS
property when they were deleted.  (JO)

3/1/96 (new feature) Added new "bbox" widget command for entries.
Also modified mouse bindings for entries and texts so that the
mouse position rounds to the nearest inter-character gap, rather
than the left edge of the character under the mouse.  This provides
more natural selection behavior. (JO)

3/1/96 (bug fix) Fixed core dump that could occur in image code if an
image was deleted while in use in a widet, then re-used in another
widget while "deleted". (JO)

3/1/96 (bug fix) Calling wish with a single argument caused a crash
under Windows due to an off-by-one error in the argument parsing code. (SS)

3/1/96 (bug fix) Palette management was broken and resulted in
incorrect palette realization and refresh behavior.  Also, images were
being drawn incorrectly if they were attached to widgets that had a
private colormap. (SS)

3/2/96 (bug fix) It was possible to press the mouse button over an
option menu, drag to a pulldown menu, and have the pulldown menu
popup in place of the option menu.  Fixed this so that option menus
are isolated from each other and from pulldowns. (JO)

3/2/96 (bug fix) Fixed yet another bug that caused long delays when
raising toplevel windows. (JO)

3/2/96 (bug fix) Fixed bug in canvases where zero-sized rectangles
and ovals didn't always redisplay right (could leave trailing
garbage on screen when moved). (JO)

3/2/96 (bug fix) Entry widgets reset their insertion cursor, selection,
and view whenever the text variable changed, plus whenever a "configure"
widget command was invoked and there was a text variable for the
widget.  Fixed to preserve this information as much as possible. (JO)

3/5/96 (new feature) Added version suffix to shared library names so that
Tk will compile under NetBSD and FreeBSD (I hope).  (JO)

3/6/96 (bug fix) Changed the way certain configure & motion events are
reported.  This fixes several bugs in menus & "winfo rootx". (RJ)

3/7/96 (bug fix) Fixed tag remove bug that showed up when draging out a
selection.  If you had dragged left, then tried to drag back right, the
left edge of the selection wasn't being updated because the tag remove
wasn't doing anything. (BW)

3/7/96 (bug fix) Fixed the boundary conditions of tag prevrange.  The second
index argument wasn't effecting in stopping the search if it fell within
a range.  The second index has to come at or before the start of a range
for the range to be found by tag prevrange. (BW)

3/7/96 (bug fix) "puts" to stdout or stderr when running from a script
caused wish41.exe to exit silently.  Now the output is silently
discarded without generating an error.  (SS)

3/7/96 (bug fix) Fixed bug where wish was treating empty lines in the input
as end of input, if the input came from stdin. This would cause it to
complain about missing closing braces etc. (JL)

----------------- Released 4.1b3, 3/8/96 -----------------------

3/9/96 (bug fix) Fixed bug in text.tcl that could cause errors in text
widgets of the form 'can't use non-numeric string as operand of "-"'. (JO)

3/12/96 (feature improvement) Modified startup script to look in several
different places for the Tcl library directory.  This should allow tk
to find the libraries under all but the weirdest conditions, even without
the TK_LIBRARY environment variable being set. (JO)

3/14/96 (bug fix) "wish bogus_file_name" didn't print an error message. (JO)

3/14/96 (bug fix) Button-2 wasn't claiming the focus during paste
operations. (JO)

3/14/96 (bug fix) "tkwait visibility" use to hang forever if its window
was deleted.  Now it detects this condition and returns an error. (JO)

3/16/96 (bug fix) Changed configuration stuff to get dynamic loading and
shared libraries working under AIX. (JO)

3/16/96 (bug fix) Fixed core dumps that could occur when a slave interpreter
was deleted in the middle of executin bindings. (JO)

3/18/96 (new feature) Added support for Activate/Deactivate events.
Currently, these new X events will generated only on the Macintosh. (RJ/CS)

3/21/96 (bug fix) The "tag prevrange" command would fail to return the current
range if it began at 1.0 and the starting point of the search was within
the range. (BW)

3/21/96 (configuration improvement) Changed configure script so it
doesn't use version numbers (as in -ltk4.1 and libtk4.1.so) under
SunOS 4.1, where they don't work anyway.  (JO)

3/22/96 (bug fix) Made Tk more robust against interpreter deletion. Now it
should be safe to delete an interpreter with a Tk application inside it,
without first deleting the Tk application. (JL)

3/26/96 (bug fix) Tk now returns results from a "send" to an interpreter
in which the Tk application is destroyed, if the interpreter continues
computing after the Tk application is destroyed. Previously any results
computed after '.' was destroyed in the target interpreter were discarded
by the "send". (JL)

3/26/96 (new feature) Tk now provides a static Tktest package which is
present only in test versions of Tk; this allows the testing commands to
be loaded into new interpreters besides the main one. (JL)

3/28/96 (bug fix) Changed the tk_dialog procedure *not* to make the
dialog a transient for its parent.  The old behavior meant that the
dialog did not get posted if the parent was iconified. (JO)

4/5/96 (bug fix) Tk would occasionally crash when destroying toplevels
under Windows. (SS)

4/5/96 (bug fix) Fonts were not being properly deallocated, causing
GDI resources to be consumed and never released under Windows. (SS)

4/11/96 (bug fix) Toplevel windows with no specified geometry were
always appearing in the upper left corner of the screen under
Windows. (SS)

4/11/96 (bug fix) "wm minsize" did not properly report the minimum
size imposed by the Windows window manager. (SS)

4/13/96 (bug fix) Text widgets could dump core in some cases where
text was inserted on the top visible line. (JO)

4/16/96 (bug fix) Changed menu code to ignore errors that occur when
restoring a grab:  the old grab window might not be visible anymore. (JO)

----------------- Released 4.1, 4/21/96 -----------------------

5/1/96 (bug fix) "option readfile" did not handle files with CRLF
line termination. (SS)

5/1/96 (bug fix) Changed to install tkConfig.sh under "make install-binaries",
not "make install-libraries". (JO)

5/7/96 (bug fix) Moved initScript in tkUnixInit.c to writable memory to
avoid potential core dumps. (JO)

5/7/96 (bug fix) Changed tk_dialog back so that the dialog box is a
transient window again.  This is needed to make sure that the dialog
box doesn't get obscured.  Also changed it to return -1 if the dialog
window is deleted before the user presses a button. (JO)

5/16/96 (bug fix) Fixed bug that caused core-dumps if a text widget
with -setgrid 1 was deleted by removing its command. (JO)

5/16/96 (bug fix) Fixed bug that caused Tk initialization to use improperly
initialized variables left over from previous invocation of Tk_Init on
another interpreter. (JL)

5/16/96 (new feature) Implemented application embedding on Windows
platforms (only Tk inside another application, not the other way yet). (JL)

5/16/96 (new feature) Added C API Tk_SafeInit that adds Tk to a safe
interpreter. (JL)

5/16/96 (bug fix) Fixed bug that caused Tk initialization to use improperly
initialized variables left over from previous invocation of Tk_Init on
another interpreter. (JL)

5/16/96 (new feature) Implemented application embedding on Windows
platforms (only Tk inside another application, not the other way yet). (JL)

5/16/96 (new feature) Added C API Tk_SafeInit that adds Tk to a safe
interpreter. (JL)

5/22/96 (bug fix) Listboxes weren't properly ignoring double clicks on
button 1. (JO)

6/12/96 (bug fix) Focus was automatically placed on new toplevels.
This caused the titlebar to flash during menubar traversal. (SS)

6/12/96 (bug fix) Iconification of a window with a specified geometry
by using the minimize button would leave the window in an inconsistent
state.  When the window was deiconified using "wm deiconify", the
window would continue to display as an icon with the deiconified
geometry. (SS)

6/12/96 (bug fix) Fixed a resource leak where the text widget was not
freeing all of the TkRegions it created.  This fix affects all
platforms, but is particularly important for Win32s. (SS)

6/21/96 (configuration change) Added --enable-gcc switch to configure
script to make Tk just like Tcl.  Now Tk will not use gcc unless you
request it explicitly. (JO)

7/18/96 (bug fix) Changed "configure" script to add an extra -R switch
(or whatever is appropriate to the platform) if the X library is in a
nonstandard place.  This guarantees that the shared library can be
found at runtime without having to set the LD_LIBRARY_PATH variable. (JO)

7/19/96 (bug fix) Fixed bug in tkImgGIF.c that cause core dumps if a
GIF file contained multiple images. (JO)

7/20/96 (bug fix) Deadlock could occur if a recursive series of send
operations involved multiple displays. (JO)

7/23/96 (bug fix) Fixed a resource leak where deallocated XIDs were
taking up memory on Windows and Macintosh platforms. (SS)

7/30/96 (bug fix) A core dump could occur if a <Destroy> handler for
a window tried to create a child in the half-dead window.  Fixed by
making the window's name disappear from the name table once it starts
to be deleted. (JO)

----------------- Released patch 4.1p1, 8/2/96 -----------------------

4/30/96 (new feature) Added support for named virtual events. New "event"
command to define/destroy named virtual events and to programmatically
send both real and virtual events to Tk. (CS)

8/6/96 (bug fix) Entry widgets were invoking scrollbar update functions
too often. (JO)

8/9/96 (bug fix) 7/30 change above for <Destroy> handlers broke many
things by making window available during Destroy handler.  Reworked
fix for core dump to simply disallow creating children of half-dead
parents. (JO)

8/12/96 (bug fix) Fixed bug where using the Copy menu item on the
Macintosh would append a NULL character at the end of the text. (RJ)

8/15/96 (bug fix) Fixed Mac code so garbage wouldn't be printed in
text and entry widgets when function & other non-printing keys were
pressed. (RJ)

8/15/96 (configuration improvement) Changed the file patchlevel.h
to be tkPatch.h.  This avoids conflict with the Tcl file and is now
in 8.3 format on the Windows platform. (RJ)

8/19/96 (bug fix) Fixed a bug under Windows where the initial window
position for a toplevel window was reported as +0+0, regardless of the
actual position. (SS)

8/21/96 (bug fix) If the last character on a line in a text widget was
a space character that didn't completely fit, the text widget would
sometimes add an extra wrap line. (JO)

8/22/96 (feature change) Complete rewrite of the grid geometry manager.
There is a new layout algorithm that produces better (but different)
layouts in many common cases. (SU)

8/22/96 (new feature) There are two new options for the grid geometry
manager, "grid update" which forces an immediate layout calculation,
and a "-pad" option to rowconfigure and columnconfigure that allows for
extra space around widgets. (SU)

8/22/96 (feature change) The order in which the grid geometry manager
reports slaves is now last-managed first. (SU)

8/22/96 (feature change) The column and row weights in the grid
geometry manager are kept internally as integers, instead of floating
point values.  Floating point values are still accepted on the command line,
but are truncated to integers. (SU)

8/22/96 (new feature) There are four new commands for opening common
dialog boxes: tk_chooseColor, tk_getOpenFile, tk_getSaveFile and
tk_messageBox. Native dialog boxes are used wherever available. (IL)

8/22/96 (new demos) Added "fsbox", "msgbox" and "clrpick" demos. (IL)

8/23/96 (feature change) Invoking the edit menu on the Macintosh now
generates the following virtual events <<Cut>>, <<Copy>>, <<Paste>>,
and <<Clear>> instead of faking key events. (RJ)
*** POTENTIAL INCOMPATIBILITY ***

8/25/96 (bug fix)  Fixed a bug that would cause "grid x" to dump core. (SU)

8/26/96 (new feature) Added the "unsupported1" command to the
Macintosh version of Tk.  This command will allow you to set the style
of a new toplevel Window (much like overrideredirect).  You can use
this to get access to all of the Native Mac window styles.  This is to
hold you over until we get a more general solution added to the
toplevel command. (RJ)

8/26/96 (new feature) Added support to handle the zoom box on a
Macintosh window.  (Currently, you can only get a Tk window with a
zoom box by using the "unsupported1" command. (RJ)

8/27/96 (documentation change) Removed old change bars (for changes in
Tk 4.1 and earlier releases) from manual entries. (JO)

----------------- Released 4.2b1, 8/30/96 -----------------------

9/5/96 (bug fixes) Fixed several bugs in file dialogs: individual files
could be listed twice, if a long list of files were shown, and the view
scrolled to the right, and then a different file file was shown, the
scrollregion on the canvas wasn't being reset, so the file dialog was
broken from then on, added an update idletasks so that the watch
cursor was shown when the dialog was thinking. For the motif file
dialog, fixed the weights for resizing.  On the clrpicker, fixed the
finalColor variable which caused problems when the OK button was
"clicked" before the dialog was mapped (in the test suite). Added Ioi's
last changes from before he left. For message boxes, if a single button
message box is shown (currently only 'ok'), it is set to be the default
even if not specified. (KC)

9/5/96 (bug fix) Fixed bug on Macintosh where menus would appear in a
seemingly random location.  (RJ)

9/5/96 (bug fix) Text widgets had rounding problems with the "yview"
command that caused them sometimes to round to the line before the
correct one. (JO)

9/5/96 (bug fix) Changed grab code to retry grabs after errors where
another application already has the grab.  This is needed to get
around race conditions with some window managers and will hopefully
solve the grab errors that people see occasionally. (JO)

9/6/96 (bug fix) Fixed x-y coordinate confusion problem with scaling
of window items in canvases. (JO)

9/11/96 (bug fix) The open and save file dialogs would change the
current working directory under Windows. (SS)

9/12/96 (bug fix) The Tk event system was delivering events to dead
windows, if the event handler got reentered during a Destroy event
handler.  This could cause core dumps and other problems. (JO)

9/20/96 (bug fix) In XFillRectangles under Windows, a brush was not
being deallocated. (SS)

9/20/96 (bug fix) The Mac window manager used to generate a mouseUp
event for a top level that was recently raised to the front/active
window which often caused a tk(priv) error.  The up event is no
longer generated with solves several problems. (RJ)

9/25/96 (bug fix) The font code under Windows was leaking memory
whenever a new font was referenced using the three part font names. (SS)

9/26/96 (bug fix) The tests for the common dialogs still used the 'testevent'
function.  I updated these calls in clrpick.test, msgbox.test, filebox.test
to use the new event gereating mechanism.

9/18/96 (bug fix) Long-standing bug in bind where <Button-1><Button-1> was
reported as <Double-Button-1>, but <Double-Key-a> was reported as "aa". (CS)

9/27/96 (bug fix) Bindings didn't work on 64-bit machines due to changes
made for virtual events. (CS)

9/30/96 (feature change) Binding for new virtual events included both
lower and upper-case, e.g., <<Copy>> was defined as <Control-c> and
<Control-C>.  Previously, widgets were directly bound to only lower-case
bindings.  The upper-case binding caused incompatibility with some existing
Tcl programs, so the upper case bindings for <<Cut>>, <<Copy>>, and <<Paste>>
were removed. (CS)

9/30/96 (bug fix) The postscript code in the canvas widget now uses
channels to get and write .ps files which fixed a bug on the Mac where
an output file would have mixed EOL characters.  In addition, I added
the ability for the prolog to come from the Tk shared library on the
Mac which makes it possible to have a standalone application. (RJ)

10/1/96 (feature change)  "grid forget" was renamed "grid remove".  A new
command "grid forget" was added whose semantics are the same as "pack forget"
(SAU)
*** POTENTIAL INCOMPATIBILITY ***

10/1/96 (feature change)  grid no longer accepts floating point values for
row or column weights, integers must be used.  (SAU)
*** POTENTIAL INCOMPATIBILITY ***

10/1/96 (feature change)  "grid {column,row}configure <master> <index>"
returns a list of option value pairs for all of the row or column
constraints. It used to return an error. (SAU)

10/1/96 (bug fix)  "The way grid handles '^' short-cuts was re-written
to eliminate core dumps. (SAU)

10/3/96 (feature change) A virtual event binding associated with a
given physical event is now considered less specific than a binding for
that same physical event, all other things being equal. (CS).

10/3/96 (bug fix) Under Windows text placed on the clipboard did not
undergo CRLF translation when delivered to other applications. (SS)

10/3/96 (bug fix) Copying an image onto itself with a zoom factor that
caused the image to grow was accessing freed memory. (SS)

10/3/96 (bug fix) Under Windows, the image blank subcommand did not
work. (SS)

10/10/96 (bug fix) Under Windows & Macintosh, XSetFont and XChangeGC
were not implemented, and XSetLineAttributes did not correctly update
the GC. (SS)

10/10/96 (bug fix) Under Windows, 8-bit non-palette displays were not
handled properly. (SS)

10/10/96 (bug fix) Under Windows, images of depth other than 8 or 24
bits were not being rendered properly. (SS)

10/10/96 (bug fix) Under Windows, bitmap subimages were not correctly
displayed. (SS)

10/14/96 (bug fix) Under Window, wm resizable would constrain both
programatic resizes as well as user resizes. (SS)

----------------- Released 4.2, 10/16/96 -----------------------

10/17/96 (bug fix) XCopyPlane was broken under Windows and would cause
a crash when used with a clipping bitmap. (SS)

10/21/96 (bug fix) Added missing resources needed by tk_getOpenDialog
on the Macintosh to the shared library for Tk. (RJ)

10/22/96 (bug fix) Invoking a menu with an Alt key sequence caused an
error due to a misplaced common in library/menu.tcl. (JO)

10/23/96 (bug fix) Errors in files sourced by the Macintosh
"Source..." menu are now correctly reported via the background
error mechanism. (RJ)

10/23/96 (bug fix) Fixed a bug in the Mac subwindow implementation
that caused refreshes to not occur for canvases with embedded
windows. (RJ)

10/24/96 (bug fix) Provided workaround for Apple bug that doesn't
handle zooming correctly for floating windows. (RJ)

10/24/96 (bug fix) Macintosh tearoff menus are now correctly
displayed as Mac floating windows. (RJ)

11/1/96 (bug fix) Restored manual page for procedures like
Tk_CreateWindowFromPath and Tk_DestroyWindow; was accidentally deleted
when Tk_CreateMainWindow procedure was decommissioned. (JO)

11/19/96 (bug fix) Fixed bugs in postscript code that would cause the
prefix to not be included and the output file to have the wrong
permissions. (RJ)

12/2/96 (bug fix) Fixed problem with canvas lines where it didn't
compute bounding boxes correctly for zero-width lines: this could
potentially leave garbage on the screen when items were deleted or
moved. (JO)

12/5/96 (bug fix) Fixed the Macintosh implementation of pointer x/y
which was returning garbage. (RJ)

12/6/96 (bug fix) Fixed grid bug where the positioning of slaves was
incorrect for non-zero values of ipadx and ipady (SU)

12/6/96 (bug fix) Fixed grid bug where slaves got "lost" when an
already managed slave is re-managed in a different master. (SAU)

----------------- Released 4.2p1, 12/8/96 (Mac only) --------------

1/17/97 (bug fix) Fixed bug where the Tk clipboard was not in sync
with the Macintosh clipboard on start-up.  (RJ)

----------------- Released 4.2p2, 1/31/97 --------------

----------------------------------------------------------
Changes for Tk 4.2 go above this line.
Changes for Tk 4.3 go below this line.
----------------------------------------------------------

9/19/96 (improvement) Implemented table driven mechanism for deciding
whether a command is safe. If it is added by Tk_Init and it appears in the
table then it is kept, otherwise it is removed in a safe interpreter. (JL)

10/18/96 (new feature) Added support for application embedding:
    - Frame and toplevel widgets now have a -container option, which
      turns the widget into a container.
    - Toplevel widgets have a -use option for requesting that the
      widget be embedded in another application.
    - Wish also supports a -use command-line option.
Embedding is fully supported under Unix, but the implementation is
not complete under Windows or the Macintosh (it works just well
enough to support the Tcl/Tk plugin). (JO)

10/22/96 (bug fix) The commands "winfo rootx" and "winfo rooty" didn't
work for non-toplevel windows in embedded applications: they returned
the coordinates of the nearest toplevel. (JO)

12/02/96 (new feature) Implemented Safe Tk. Tk can now be loaded into a
safe interpreter that has been created with tcl_safeCreateInterp, by
calling load {} Tk interpname. (JL)

12/02/96 (new feature) A safe Tk interpreter can no longer generate
postscript output from a canvas. (JL)

12/02/96 (new feature) Added -channel option to photo command to allow
image data to be read from a channel. This is useful in safe Tk
interpreters where the data cannot be read directly from a file. (JL)

----------------------------------------------------------
Changes for Tk 4.3 go above this line.
Changes for Tk 8.0 go below this line.
----------------------------------------------------------

9/1/96 (new features) The font mechanism in Tk has been completely
reworked:
    - Font names need not be nasty X LFDs: more intuitive names like
      {Times 12 Bold} can also be used.  See the manual entry font.n
      for details.
    - Font requests always succeed now.  If the requested font is not
      available, Tk finds the closest available font and uses that one.
    - Tk now supports named fonts whose precise attributes can be
      changed dynamically.  If a named font is changed, any widget
      using that font updates itself to reflect the change.
    - There is a new command "font" for creating named fonts and querying
      various information about fonts.
    - There are now officially supported C APIs for measuring and
      displaying text.  If you use these APIs now, your code will
      automatically handle international text when internationalization
      is added to Tk in a future release.  See the manual entries
      MeasureChar.3, TextLayout.3, and FontId.3.
    - The old C procedures Tk_GetFontStruct, Tk_NameOfFontStruct, and
      Tk_FreeFontStruct have been replaced with more portable procedures
      Tk_GetFont, Tk_NameOfFont, and Tk_FreeFont.
      *** POTENTIAL INCOMPATIBILITY ***
(CS)

9/24/96 (bug fix) Under Windows, transient windows would be destroyed
if their master was destroyed, even if the transient window was not a
child of the master. (SS)

10/18/96 (new features) A -menu option has been added to the toplevel
widget command, which allows a menu to operate as a menubar. On the
Macintosh, the menubar is displayed accross the top of the main monitor,
just like with other applications. Under Windows and Unix, the menu is
attached to the toplevel window. Also, changed some semantics.
Tearoff menus will now reflect changes to the menu it was
torn off from, and are deleted when the master menu is
deleted. Tearoffs also reflect more look-and-feel of the
platforms they are running on. (SRP)

10/31/96 (bug fix) Under Windows, missing system cursors would
generate an error instead of falling through to the Tk cursor of the
same name. (SS)

11/7/96 (feature change) Under Unix, default borderwidth is now 1 to
more closely approximate CDE.  (SS)
Note: this change was undone on 6/12/97, restoring the default border
width to 2 again.  (JO)

11/7/96 (new feature) The button widget now supports a -default option
that draws a platform specific default ring around the widget. (SS)

11/7/96 (feature change) Under Windows, buttons and scrollbars now
have native look and feel.  This affects the default class bindings
and the way the some configuration options are interpreted.  Refer to
the widget manual pages for more details. (SS)
*** POTENTIAL INCOMPATIBILITY ***

11/19/96 (bug fix) Under Windows, images were incorrectly drawn on
16-bit displays. (SS)

11/19/96 (bug fix) Under Windows, the class name for the main window
(.) was not properly generated from argv0. (SS)

11/20/96 (bug fix) Fixed a couple of bugs in the Canvas widget.  The
postscript file is now created with the correct permissions.  Also,
the prolog is now properly included in all cases. (RJ)

11/22/96 (bug fix) Under Windows, the initial directory and file names
were not properly translated before being passed to the system
open/save file dialogs.  So forward slashes were not converted to
backslashes, and tilde substitution was not performed.  (SS)

11/25/96 (feature change) Under Windows and Macintosh, the selection
highlight is now hidden whenever an entry or text widget loses focus.
Also, the previous selection information is not lost when a new
selection is made in a different widget. (SS)

11/26/96 (new feature) Added support for images as primitive types in
text widgets. (SU)

11/30/96 (configuration improvement) Modified configure.in to handle the
case where Tcl and Tk are installed in different places by including both
their library directories in the library search path for Tk. (JO)

12/3/96 (bug fixes) Fixed two bugs related to canvas lines that caused
the screen to be incorrectly refreshed, leaving garbage on the screen.
One bug was related to lines with width zero, and the other was
related to lines with very long miters. (JO)

12/4/96 (bug fix) The "update" command was only syncing the display
for its main window.  Changed to sync all displays. (JO)

12/5/96 (bug fix) Color deallocation would occasionally cause a panic
under Windows. (SS)

12/5/96 (bug fix) Errors during startup were silently discarded under
Windows. (SS)

12/5/96 (bug fix) Errors during startup were silently discarded under
Windows. (SS)

12/11/96 (bug fix) Text widgets weren't considering the -spacing1
and -spacing2 options when computing their desired geometry. (JO)

12/12/96 (feature change) Option menus using tk_optionMenu were
created with command entries that set the option menu's variable in a
command string. This has been changed so that the option menu's
entries are now radiobutton entries so that the entries that matches
the variable is now checked when the menu is posted. (SRP)

12/12/96 (feature change) The destroy command no longer returns an
error when a window does not exist. (SRP)

12/13/96 (new feature) grid row/column-configure accepts a list of
indices in addition to a single index. (SU)

12/17/96 (bug fix) Under Windows, command line was not being parsed
correctly if it contained the literal characters \" (CS)

12/17/96 (feature change) Native Windows labels do not get a focus-ring
border.  (CS)

12/17/96 (bug fix) Under Windows, colors specified as "#XXYYZZ" where XX, YY,
or ZZ were not valid hex digits were getting a random color value instead of
being an error. (CS)

----------------- Released 8.0a1, 12/17/96 -----------------------

12/23/96 (bug fix) Fixed two menu bugs:
    - Menus could get stacked below other windows so that they weren't
      visible when posted (especially under olvwm and fvwm).
    - Under olvwm if you pressed button 1 over an entry in a new-style
      menubar, the menu didn't appear until you moved the mouse slightly.
(JO)

1/6/97 (bug fix) Focus could accidentally get grabbed by an application
away from the rightful focus owner if the focus recently changed from one
application to another. (JO)

1/6/97 (bug fix) Under Windows, the console was appearing even for
non-interactive applications.  This was a side effect of a general
problem with the wm state of windows that were being mapped for the
first time. (SS)

1/6/97 (bug fix) Under Windows, the initialization code was not
looking in the right directory for the Tk libraries when the program
being run was not in the Tcl installation heirarchy. (SS)

1/8/97 (bug fix) Under Windows, the windows were not being unmapped
properly, which led to strange packer behavior. (SS)

1/8/97 (bug fix) The "winfo containing" command (and the Tk_CoordsToWindow
procedure) didn't work properly on Unix in the presence of embedding or
menubars. (JO)

1/15/97 (bug fix) Invoking "destroy ." as the command from a menu would
cause Tk to crash because TkMainInfo was freed before menu released its
resources.  This bug had already been fixed for scrollbars and buttons. (CS)

1/15/97 (bug fix) Tk is now working under Win32s again, including Win32
version 1.25.  Fixed separate problems in fonts and dialogs. (CS)

1/15/97 (feature change) Under Windows, font sizes are now specified in
points, not pixels.  The mapping between pointsize and pixels depends on
Windows having accurate metrics for the monitor (plug&play helps).  Font
metrics are still reported in pixels. (CS)

1/21/97 (bug fix)  Grid no longer reports rows or columns "out of range"
when requesting their constraints. (SAU)

1/21/97 (bug fix)  Fixed some window manager related bugs on the
Macintosh.  Now better support global grabs. (RJ)

1/21/97 (bug fix) For Windows: Fixed problems with canvas items that
used end caps.  Fixed arc implementation to more closely approximate
X.  Stippling now works properly on fat lines. (SS)

1/21/97 (bug fix) Small interlaced GIF images were not properly
decoded. (SS)

1/21/97 (bug fix) More changes to image code to try to handle 16-bit
displays properly under Windows. (SS)

1/21/97 (bug fix) Numerous display bugs on Unix and Macintosh are now
fixed. Numerous binding problems for menubars under Unix are now
fixed. Deletion of menu separators under Windows is now fixed. (SRP)

----------------- Released 8.0a2, 1/24/97 -----------------------

1/29/97 (feature change) The -transient field for menus is no longer
supported.  There is now a -type field which is used to achieve the
same purpose that the -transient field accomplished. When a menu is
created, the -type field controls whether the menu is a normal
pull-down menu, a floating tearoff menu or a menubar. This option is
normally only used by the library code and internally by the menubar
code. (SRP)
*** POTENTIAL INCOMPATIBILITY ***

2/5/97 (feature change) Changed the photo image mechanism to use
Tcl_Channels instead of FILE * as an argument to image matching
functions.  The change will make it much easier to write cross
platform image types in Tk.  Note: FILE * is no longer used anywhere
in Tk. (RJ)
*** POTENTIAL INCOMPATIBILITY ***

2/7/97 (enhancement) Were not allowed to bind to virtual events inside of
canvas or text widget (e.g., "$canvas bind all <<foo>> {script}" or
"$text tag bind sel <<foo>> {script}"); it would return an error
disallowing that binding.  Now _can_ bind to a virtual event, but that
binding inside of the canvas or text widget will only fire if the
underlying virtual event definition is of type key, button, motion,
enter, or leave; all other physical event types get filtered out by the
widget before the virtual event mapping is done. (CS)

2/22/97 (bug fix) Under Unix, "wm geometry +-20+-30" didn't work. (JO)

2/24/97 (bug fix) The photo image didn't always zero out enough of its
pixel and dither correction arrays. (JO)

2/25/97 (bug fix) Fixed focus problem that could cause "BadMatch (invalid
parameter attributes)" in X_SetInputFocus requests on Unix. (JO)

2/25/97 (bug fix and new feature) Added new "gray75" bitmap, fixed
"gray25" bitmap to really be 25% on (due to an ancient mistake, it
had been only 12% on). (JO)

2/28/97 (bug fix) Windows: made embedding work again on Win32 platform.
Prevent iconification, deiconinification on embedded windows. (JL)

3/4/97 (new feature) Added the ability to manipulate the Apple and
Help menus on the Macintosh; the system menu on Windows; and to have a
right justified Help menu on Unix. See the documentation for menu.n
for more details. (SRP)

3/4/97 (bug fix) Prevented core dump at exit if a <Destroy> binding on "."
gets invoked from destroying a nested widget and the binding causes the
interpreter to be deleted. The core dump was being caused by the
interpreter not being Tcl_Preserve'd during the destroy of ".". (JL)

3/4/97 (bug fix) Under Unix, when embedded Tk is running in a separate
process, correctly handle a race condition: ignore cross-over messages from
the X server for windows that Tk thinks it had already deleted, when the
containing process deletes its container window. Some other race conditions
still remain, e.g. with pixmaps, colormaps and images. (JL)

3/10/97 (bug fix) Prevented core dump in generic console code due to
following a NULL pointer when the console interpreter was already deleted.
This may happen due to different orders of deletion possible at exit. (JL)

3/10/97 (bug fix) Fixed bug on Mac and Windows that caused time to be
ignored when considering if a single click was actually a double
click. (RJ)

3/11/97 (feature change) A major oversight has been that although it was
documented that the Tk programmer was asking for a font in points (1/72 of an
inch), under Unix and Mac Tk was actually asking for a font in pixels, while
only under Windows was it using points.  This caused applications to appear
much larger when run under Windows.  Now, on all platforms the (purportedly)
correct size in points is used when asking for fonts.  However, for
compatibility with existing tk4.2 applications that depend on fonts being of
specified pixel size, XLFDs retain their incorrect behavior of getting a
font in pixels.  (CCS)
*** POTENTIAL INCOMPATIBILITY ***

3/13/97 (new feature) "tk scaling" command to setup the mapping between
pixels and points.  This scaling factor is used by all widgets that accept
ruler distances, not just fonts. (CCS)

3/24/97 (new feature) Added "-columnbreak" option to menu
entries. When this value is "1", the entry will appear at the top of a
new column in a non-menubar menu. Also added "-hideMargin". Together
with "-columnBreak", menus with palettes are now possible. (SRP)

3/26/97 (new features and bug fix) Titles for tearoff menus were
broken on the Mac and Windows. Added the ability to set the title of a
menu when it gets torn off and override Tk's automatic generation of
the title.  On the Macintosh, whenever a menu
label contains three dots in a row "...", the menu will instead
display the elipses character '…'.  (SRP)

3/27/97 (bug fixes) When a menu had an error executing a postcommand,
the error information was getting lost. On Windows, a set of
menubuttons was not highligting properly when clicking between
windows. On Windows, post commands were getting executed twice for
popup menus.  On Macintosh, fixed problem where menubars were not
always current. (SRP)

4/11/97 (new feature) Menubuttons now have a direction flag which
controls where the menu popups up relative to the button. (SRP)

4/24/97 (bug fix) Transient windows did not obey the resizable setting
under Windows. (SS)

4/24/97 (bug fix) wm geometry did not correctly parse negative
coordinates. (SS)

4/29/97 (bug fix) Changed the canvas polygon implementation to only
report the coordinates specified by the end user not the automatically
generated end point of a self closing polygon. (RJ)
*** POTENTIAL INCOMPATIBILITY ***

4/23/97 (feature change) Loosened the rules on parsing font names so that
unix-centric fonts in scripts don't break when run on Windows or Mac.
(1) Previously, an XLFD had to specify font name, weight, slant, and size;
now, a minimal XLFD (such as "*-times-*") will be accepted, and all
unspecified attributes will be given default values.  (2) Previously, in the
{name size style ...} format, only the style was optional; now both the size
and the style are optional; this solves the problem of old scripts that
contain specifications of the form "-font fixed" or "-font times". (CCS)

5/7/97 (new feature) Menus now send a virtual event <<MenuSelect>>
when an item is highlighted in a menu. Applications can use this to
implement context-sensitive help. (SRP)

5/14/97 (bug fix) Fixed a race condition in the focus code where focus
could be taken away from a window incorrectly.  Scenario is that the main
window creates a toplevel and assigns focus to it.  When the user moves the
mouse from the main window into the toplevel there was a race between
two different kinds of focus events. (BW)

5/20/97 (bug fix) Fixed bug where the clipboard was not rendered before
the application exited. (SS)

5/22/97 (feature change) When a Tk8.0 menu is configured, all menus
derived from it (menubars, tearoff) mirror the changes. This was not
true for the "-tearoff" flag. In Tk4.6, tearoff menus had the
"-tearoff" flag turned off. Now, the "-tearoff" flag is tracked just
as the other options are. Tearoff menus and menubars with the
"-tearoff" option set will not display the tearoff item. This means
that a given menu entry for a menu and a tearoff of that menu will
match now. (SRP)
*** POTENTIAL INCOMPATIBILITY ***

----------------- Released 8.0b1, 5/27/97 -----------------------

5/30/97 (bug fix) Made the options to the grid command shortcut-able.
Ie. You can now use -stick, in addition to -sticky. (RJ)

6/2/97 (bug fix) Fixed bug in startup code that caused a problem in
finding the library files when they are installed in a directory
containing a space in the name. (SS)

6/2/97 (bug fix) Virtual events associated with <Enter>/<Leave> in text
widget tag caused panic. (CCS)

6/6/97 (bug fix) On some systems, struct timeval.tv_sec is unsigned. (SS)

6/6/97 (feature change) Changed -default option on buttons to take
three states: normal, active, disabled.  This allows apps to have a
row of buttons where the default ring moves between buttons without
changing the geometry of the buttons.  See the button.n manual page
for more details. (SS)
*** POTENTIAL INCOMPATIBILITY with Tk 8.0b1, but not with Tk 4.2 ***

6/9/97 (bug fix) Canvas postscript printing now works for bitmaps
under Windows. (SS)

6/10/97 (bug fix) Fixed bug in bindings for listboxes where state wasn't
being properly initialized on Shift-1 button presses. (JO)

6/11/97 (bug fix) Text widget display code did not include internal
padding in the damage calculation for borders leading to unrefreshed
sections on Windows and Mac. (SS)

6/12/97 (feature reversal) Changed default border widths under Unix
back to 2 again.  This reverses the change made on 11/7/96. (JO)

6/13/97 (bug fixes) In canvas text item: the insertion cursor wasn't shown
if insertion point was at end of text item, it was impossible to click to
position the insertion point after the last character, and @x,y indices were
computed incorrectly if -scrollregion had been specified and canvas was
scrolled. (CCS)

6/13/97 (bug fix) Hitting up/down arrows in a text widget packed in a
toplevel window created with the "-screen" option would cause an error dialog
to pop up. (CCS)

6/12/97 (bug fix) Fixed bug in canvas text items where multi-line
selections were not highlighted properly.  This bug existed only in
earlier releases of Tk 8.0.  (JO)

6/16/97 (bug fix) In some obscure cases, canvas window items could
accidentally specified a 0x0 size for the window, which caused a
BadValue error under X. (JO)

6/17/97 (bug fix) Tk buttons on the Macintosh will now correctly
draw under MacOS 8.0. (RJ)

6/18/97 (feature change) Changed the way highlights are drawn in text
widgets so that the empty space to the left of a line is highlighted
whenever the leftmost character of the line is highlighted (the empty
space didn't used to be highlighted).  This produces a neater left
edge when several lines are selected.  (JO)

6/18/97 (bug fix) Tk was using the wrong system colors to draw various
widgets under Windows. (SS)

6/19/97 (bug fix) Under Windows, the "wm transient" and "wm overrideredirect"
subcommands can now be applied to a toplevel to change its window
style at any time during the life of the window. (SS)

6/19/97 (feature change) All GIF and XBM images needed for the "TK"
file dialog box are included in-line in tkfbox.tcl. (IL)

6/27/97 (bug fix) Revamped focus code to eliminate most XSetInputFocus
calls from the FilterEvent procedure.  This moves the implementation back
towards the Tk 4.2 implementation, but adds embedding support.  There is
still a known bug with twm's NoTitleFocus and embedded windows.  However,
the races in a2 and the funny focus stealing in b1 are gone. (BW)

6/25/97 (bug fix) Error message was not properly reported when using
button 'toggle'. (DL)

6/25/97 (bug fix) Removed one source of memory corruption in tkGrid.c code
(fixes what was exercised by "grid col . 0 -w 1; grid col . 0 -w 25") (DL)

----------------- Released 8.0b2, 6/30/97 -----------------------

7/1/97 (bug fix) Menu shortcut and tearoff reported problem fixed. (DL)

7/1/97 (new feature) TK_BUILD_SHARED flag set in tkConfig.sh
when Tk has been built with --enable-shared. TK_SRC_DIR added.
A new tkLibObjs make target, echoing the list of the .o's needed
to build a tk library, is now provided. (DL)

7/9/97 (bug fix) Fixed Tk_CreateFileHandler and Tk_DeleteFileHandler
macros to directly call the Tcl equivalents. (JL)

7/10/97 (bug fix) On the Mac, if the binding for <<MenuSelect>> was
drawing, the drawing could bleed over into the menus. This is now
fixed. (SRP)

7/10/97 (bug fixes) Removed duplicate code related to Tk_SafeInit,
made a single init script handling both cases. (DL)

7/10/97 (feature change) On Unix, to be able to load Tk into a safe
interp you need to set the env(DISPLAY) var. Some API should be
added to allow master crontrol over Tk instantiation. (DL)

7/11/97 (new feature) On the Mac, menus that are too big for the
screen will now scroll. This is part of the interface on the Mac,
impossible under Windows, and is not done for Unix. (SRP)

7/21/97 (bug fix) After fixing the bug that in canvas text item the insertion
cursor wasn't shown if insertion point was at end of text item, introduced a
different bug in where clicking in entry widget with 0 characters would
crash or display garbage. (CCS)

7/22/97 (bug fix) If there were a whole bunch of returns or tabs in a row in
a canvas text item, then the temporary buffer used when outputting
postscript could overflow and overwrite the stack. (CCS)

7/23/97 (feature change) Reenabled "tkwait" in the Safe Tk base. (JL)

7/24/97 (bug fix) Single init script for both Win and Unix.
new library/safetk.tcl using features from new tcl safe.tcl (DL)

7/30/97 (feature change) As a result of native menus, you can no
longer drag through a frame of menubuttons on Macintosh and Windows
and have the menus pop down. You can still click on individual
menubuttons and their menus will pop down.  Applications needing to
present a menubar should consider using the new "-menu" configuration
of the toplevel widget to set up menubar which behaves correctly on
Macintosh, Windows and X Windows. (SRP)

7/31/97 (bug fix) Tk widget commands can now safely be hidden commands.
Previously destroying the widget would potentially leave dangling pointers
and destroy an exposed command instead of a hidden one if an exposed
command by that name existed. (JL)

7/31/97 (bug fix) On Windows, popup menus were not tracking the right mouse
button correctly if it was used to invoke the menu. On Unix, tearoff
menus were stealing focus when the mouse moving over them even when
focus following was turned off. (SRP)

8/4/97 (bug fix) Fixed problem under USENIX where raising a toplevel
window could cause an X error if the window had just been withdrawn.  (JO)

8/4/97 (feature change) tkerror and bgerror are not anymore hard links
maintained by the Tcl core. The implementation of bgerror provided by
Tk tries, for backward compatibility only, to to call "tkerror" and
if that fails, falls back to the usual dialog and stack trace option
posting. You can thus still use either "bgerror" or "tkerror" as your
application error handling proc, but using "bgerror" is strongly
recommended as support for "tkerror" will eventually vanish in upcoming
releases. (DL)
*** POTENTIAL INCOMPATIBILITY with scripts that were using
    the actual hardlink implementation 'features' and with
    scripts (if any) that would be calling the default "tkerror" to
    simulate error messages (use "bgerror" instead)                  ***

8/7/97 (feature change/addition) Removed the gif files used for the
Open dialog box on UNIX (they were previously made inline).  Added a
new images directory that includes several images of the Tcl and Tcl
Powered logos. (RJ)

8/7/97 (bug fix) Fixed focus to deal with embedding when there is
no window manager. (BW)

8/8/97 (bug fix) Fixed bug in photo image code where photo images from
different interpreters could get confused if they had the same name. (JO)

8/8/97 (new feature) Added new procedure Tk_GetImageMasterData for
mapping image names to master data.  (JO)

8/8/97 (feature change) Modified Tk_FindPhoto procedure to require
extra "interp" argument (needed for bug fix above).  (JO)
*** POTENTIAL INCOMPATIBILITY ***

8/8/97 (bug fix) Fixed problems under Windows renaming toplevels with
menubars. Fixed problems on all platforms renaming menu widgets and
using new menus of the same name as an old one as cascades. Fixed a
cosmetic problem with tearoff menus. (SRP)

8/13/97 (bug fixes) Fixed "-from" option for the "image create" and
"imageName read" commands for GIF images, which didn't used to work
correctly.  Also made transparency work correctly for GIF images
without the TRANSPARENT_GIF_COLOR hack; TRANSPARENT_GIF_COLOR is
now ignored.  These fixes were provided by Jan Nijtmans. (JO)

8/13/97 (new feature) added safe::loadTk command to load Tk in a
safe slave interpreter. See the loadTk.n manual page for more
details. (DL)

----------------- Released 8.0, 8/18/97 -----------------------

8/22/97 - (bug fix) Fixed syntax error in tk_popup; option menus now
popup over their selected items like they did in tk4.2. Fixed problem
where cascades sometimes did not work on X. On X, menubars with
checkbuttons and radiobuttons in them would infinite loop when
mappped. (SRP)

8/27/97 (new feature) Added support for new X11R6 colors under Windows
and Mac platforms. (SS)

8/29/97 (bug fix) Wish crashed if stdin was closed. (SS)

9/10/97 (bug fix) "font actual {helvetica 10} -displayof ." wasn't taking
into account the "-displayof" option.  This problem also existed for the
"font metrics" and "font measure" commands. (CCS)

9/16/97 (new feature) Added "resource delete" and "resource files"
command to the Mac.  Also fixed "resource write" when the resource
was specified by id and already existed. (JI)

9/16/97 (bug fix) Added null bindings to <Command-KeyPress> for the
text and entry widget on the Macintosh.  This prevents unbound command
key sequences from having the character echoed to the widget. Also
fixed Cut & Copy bindings.  (JI) (RJ)

9/18/97 (bug fix) Revamped Macintosh focus code.  Cut, Copy & Paste
virtual events now go to the correct (focus) window. (RJ)

9/19/97 (bug fix) Made Macintosh tearoff menus non-resizable. (RJ)

10/9/97 (bug fix) Default font for new canvas text items was hardcoded to
"Helvetica 12" instead of using DEF_CANVTEXT_FONT defined in
tk{platform}Default.h like all the other widget settings.  (CCS)

10/9/97 (bug fix) Image code could cause crashes during "exit" under
some conditions (such as an image named "place").  (JO)

10/9/97 (bug fix) Fixed bug that sometimes prevented listboxes from
scrolling far enough horizontally to see the rightmost character.  (JO)

10/10/97 (bug fix) In canvas text items, if the text ended with a \n, it
was not counted in the bbox height, as it did in tk4.2.  This caused
"hello\n" to be the same height as "hello" and you couldn't see the
cursor positioned on the next line. (CCS)

10/10/97 (bug fix) The grid geometry manager didn't always properly
forget about windows after a "grid forget" or "grid remove" command:
the windows could reappear on the screen later.  (JO)

10/13/97 (bug fix) Selection could not be restored to a text widget
after "selection clear" on Windows. (SS)

10/14/97 (bug fix) If a canvas had contained windows that were off-screen,
the windows could sometimes reappear (in the wrong place) if the canvas was
enlarged.  (JO)

10/20/97 (bug fix) Omitting the arguments to the text widget "mark
gravity" option caused a crash. (SS)

10/21/97 (bug fix) Tk did not reset the result after native dialog
modal loops on Window so background events could perturb the dialog
result. (SS)

10/23/97 (bug fix) Memory leak in unix's TkpGetFontFamilies.  Thanks
to James Bonfield for the fix. (DL)

10/27/97 (bug fix) Fixed event reporting for the Mac during a grab
when the pointer was out of the toplevel window. (RJ)

10/28/97 (bug fix) Under Unix, override-redirect was getting set
incorrectly for menus, so that "wm overrideredirect" returned 0. (JO)

10/28/97 (bug fix) Under Unix, focus code could sometimes cause the
display to deadlock (it wasn't flushing the output buffer after issuing
an ungrab command). (JO)

10/28/97 (bug fix) If a PPM image file wasn't complete (e.g. it
consisted of nothing but space characters) Tk entered an infinite loop
reading the header. (JO)

10/28/97 (bug fixes) On the Mac, menubars assigned to toplevels would
disappear after a menu item was invoked from them. On Windows,
clicking a system menu with added items and then again with a
different set of added items would crash. On all platforms, a command
menu entry that caused the entry to be deleted, another one created in
its place, and the replacement deleted would cause a panic. On Unix,
<<MenuSelect>> event bindings were firing every time the mouse moved,
instead of everytime the active menu item changed. (SRP)

10/27/97 (bug fix) If a particular race condition occurred under Windows,
Tk would crash complaining about trying to free a color that wasn't
allocated. (SS)

10/28/97 (bug fix) Under Windows, button grabs did not report motion
events that occurred outside of Tk windows. (SS)

10/28/97 (bug fix) Fixed incorrect display of transparent images on
the Macintosh. (JI)

10/29/97 (bug fix) Reworked the handling of out-of-range indices in
the widget command for listboxes: there were all sorts of quirks
before (e.g., ".l delete -1" actually deleted the first element
of the listbox). (JO)

10/29/97 (bug fix) Fixed crash on the Macintosh that could occur if a
window is moved before it is mapped where the X window was created but
the Macintosh port was not. (RJ)

10/29/97 (bug fix) Fixed several errors in how wm state was maintained
on the Macintosh.  Tk now also will iconify a toplevel window on the
Mac if the new Appearance Manager is present. (RJ)

10/28/97 (bug fixes) In canvas' postscript command: User name
information was leaked in safe interpreters on Unix (security fix).
Errors while reading prolog.ps were not propagated and the error
message was mixed with partial data. Note: postscript output does
not work in safe interpreters on unix and windows. (DL)

10/28/97 (bug fix) Safe Tk interps on unix were leaking env(DISPLAY). (DL)

10/31/97 (bug fix) Fixed problems related to the input focus when one
application had windows open simultaneously on several displays. (JO)

10/31/97 (bug fix) Fixed several problems with traversal of menus via
the keyboard under Unix. (SRP)

11/4/97 (bug fix) Fixed various word-size related problems for 64-bit
architectures. (SS)

11/5/97 (bug fix) Embedding on Windows was using freed data (crashing
in safe.test with TCL_MEM_DEBUG). NB: Embedding is still not fully
implemented on Windows ! (It works mostly when Tk is embeded into it's
own Tk frame (safe::loadTk case), but not well with respect to resizing
with a toplevel container or with an external process). (DL)

----------------- Released 8.0p1, 11/7/97 -----------------------

11/20/97 (bug fix) Fixed bug on the Mac where the "package require"
command caused menus to stop working. (JI)

11/20/97 (bug fix) Fixed bug in rendering transparent gifs on Text
widgets. (JI)

11/20/97 (enhancement) Made the changes required to work with the new
Apple Universal Headers V. 3.0 so we can compile with CW Pro 2.0 (JI)

----------------- Released 8.0p2, 11/25/97 -----------------------

11/25/97 (security bug fix + added feature) Tk Safe Init now asks
the master's safe::TkInit for the 'argv' to use. This is transparently
dealt with by the safe::loadTk API. New optional "-display displayName"
argument to safe::loadTk, and the "-use" argument accepts both window
Ids and Tk window names: see loadTk(n). Made the ":0.0" default display
work on the Mac as it works on Windows and Unix. (DL)

12/3/97 (bug fix/optimization) Removed unneeded and potentially dangerous
instances of double evaluations if "if" and "expr" statements from
the library files. It is recommended that unless you need a double
evaluation you always use "expr {...}" instead of "expr ..." and
"if {...} ..." instead of "if ... ...". It will also be faster
thanks to the byte compiler. (DL)

12/3/97 (new feature) Added support for browser/plugin style embedding,
and made various other fixes to get the plugin working on the Mac. (JI)

12/8/97 (bug fix) on Windows, using "winfo pathname" before "." was mapped
was crashing. (DL)

---- Shipped as part of the plugin2.0b5 as 8.0p2Plugin1, Dec 8th 97 ----

12/97 (bug fix) more Macintosh embeding fixes needed for the plugin. (JI)

Jan/9/98 (improvement) Allow applications to have custom init script
without  having to patch the Tk core: Tk_Init will use an existing
"tkInit" proc if one exists in the interp where one tries to install Tk
instead of defining it's own (tkInit is the transient proc defined in
generic/tkInitScript.h that searches and sources tk.tcl and defines
the 'correct' tk_library). (DL)

---- Shipped as part of the plugin2.0 as 8.0p2Plugin2, Jan 15th 98 ----

6/3/98 (bug fix) Fixed bugs in the tk_getOpenFile under Unix.
 1) If the -initialdir option was "." the result would be "././foo.tcl"
    instead of an absolute path, like the Windows interface.
 2) There is a traceVar on the data(selectPath) where the script was
    assumes the window exists. (BS)

6/12/98 (feature change) Focus -force now sets the foreground window
on Windows platforms in addition to moving the focus. (SS)

6/12/98 (bug fix) Fixed bug in Windows font measurement that did not
take kerning into account. (BS)

6/24/98 (bug fix) On Unix, fixed -initialdir switch to tk_getOpenFile
and tk_getSaveFile to convert the specified directory to an absolute
path and to use the current working directory if the specified
directory does not exist. (SS)

6/25/98 (bug fix) On Unix, both the Tk and the Motif file dialogs
would fail if the -parent flag changed between two parent windows that
had been previously used as file dialog parents. (SS)

6/29/98 (compatibility patch)  Added reserved fields to several Tk
structures to match additions made by Jan Nijtmans dash patch.  This
means that extensions can be compiled against the dash patch
and still work with unpatched Tk, and vice versa.

7/6/98 (bug fix) Added keysym definitions for the new keys on the
Microsoft keyboards.  You can bind to <App>, <Win_L>, and <Win_R>,
but you cannot use the Win keys as modifiers. (SS, BW)

7/6/98 (new feature) Added support for the Macintosh Appearance Manager. (JI)

7/24/98 (feature change) Eliminated the static variable that sets
tk_library and simplified search order for tk.tcl.  The tk_library
variable can now be set before calling Tk_Init to avoid doing any
searches.  If it isn't set, then Tk checks env(TK_LIBRARY), relative
to tcl_library, an install directory relative to the executable, a
source directory relative to the executable, and a tk directory
relative to the source heirarchy containing the executable.  See the
comment at the top of generic/tkInitScript.h for more details. (SS)

7/27/98 (bug fix) The bbox for coords in the canvas were incorrectly
including the center of the coord as part of the bound area.  (RJ)

8/4/98 (bug fix) Fixed memory leak in Windows menu code. (SS)

8/4/98 (bug fix) Fixed bug where bgerror's were not being generated
from menu callbacks on Windows. (SS)

8/4/98 (bug fix) Alt-key bindings were not being handled properly
under Windows, resulting in annoying beeps. (SS)

8/4/98 (bug fix) Fixed bug in Windows menubar handling that allowed
a shared menubar to be deleted when any window using it was deleted. (SS)

8/4/98 (feature change) Introduced TkReadBitmapFile to replace
XReadBitmapFile so that all Tk file opens go through the Tcl channel
mechanism.  This lets us wrap applications that define their own
bitmaps and cursors. Note that XReadBitmapFile is no longer
emulated for non-unix platforms platforms (RJ, BW)

8/5/98 (bug fix) <Insert> binding in entries was masking the virtual
event <<Paste>> binding to Shift-Insert on Windows. (SS)

8/5/98 (bug fix) wm frame would crash if the window had not been
mapped yet on Windows. (SS)

8/5/98 (bug fix) Local grabs did not exclude menus or the caption bar
under Windows. (SS)

8/5/98 (bug fix) Reduced message traffic by setting
WS_EX_NOPARENTNOTIFY on TkChild windows. (SS)

8/6/98 (feature change) Changed tkInitScript.h to use the new
tcl_findLibrary procedure to locate its script library. (BW)

8/10/98 (bug fix) Added special case to font code to limit the
length of displayed strings to avoid wrap-around bugs in some
PC X servers when the pixel length of the string exceeds 0x7fff. (SS)

8/12/98 (bug fix) Macintosh, lock down some of the resources
associated with menus to try and stabilise the menu system
on memory limited machines. (JI)

8/12/98 (windows build change) Moved the tkConsole.obj into the tk80.dll
on windows.  If you build your own Tk main program, you no longer
need to compile and link this yourself. (SKS)

-------- Released 8.0.3 to the Tcl Consortium CD-ROM project, 8/13/98 ------

10/5/98 (new feature) Added the event "MouseWheel" that will fire on
Windows applications in response to mouse wheel movement.  You can
bind to the MouseWheel event and use the %D substitution to get the
delta the wheel moved.  The "event generate" command has also been
enhanced with the -delta flag so you can generate these events from
Tcl.  See the bind and event man pages for more details.  The listbox
and text widgets' default bindings have been updated to understand
MouseWheel events. (RJ)

10/12/98 (performance improvement) Added hash table to canvas widget
that holds numeric ids for items.  The hash table makes item lookup
almost constant time which improves certain canvas operations
(exspecially for canvases with large number items).  Thanks to Mark
Weissman <[email protected]> and Jan Nijtmans <[email protected]>
for submitting this improvement.  (RJ)

10/15/98 (bug fix) The -fill option to text items in the canvas did
not allow the empty string as an argument (meaning transparent) even
though every other item type did.  Thanks to Sebastian Wangnick
<[email protected]> for supplying this patch. (RJ)

10/20/98 (feature change) The Makefile and configure scripts have been
changed for IRIX to build n32 binaries instead of the old 32 abi
format.  If you have extensions built with the o32 abi's you will need
to update them to n32 for them to work with Tcl.  (RJ)
*** POTENTIAL INCOMPATIBILITY ***

11/10/98 (feature change) The Macintosh menus will use the Appearance
Theme backgrounds, separators and menu shape, if Appearance version
1.0.1 or greater is installed.  The version of Appearance that shipped
with MacOS 8.0 so it will not work with a straight 8.0, but it will
with MacOS 8.1 or later. (JI)

----------------- Released 8.0.4, 11/20/98 -----------------------

11/24/98 (bug fix) On some X servers, XQueryLoadFont will always
return a font, even if the name is meaningless.  This prevents Tk from
parsing the font name, so now we perform a quick sanity check on the
name before letting X have it. (stanton)

12/30/98 (bug fix) Fixed bug in "grid forget" that failed to cancel
pending idle handlers, resulting in a crash in a few odd cases. (stanton)

1/28/99 (configure change) Now support -pipe option on gcc.  (RJ)

2/4/99 (bug fix) Changed so color tables in photo images are freed
immediately instead of being delayed.  This ensures that color tables
are properly disposed at process exit. (stanton)

2/4/99 (bug fix) Changed postscript template to	include a European
character with an umlaut when determining font height. (stanton)

2/4/99 (bug fix) If an image bitmap mask changed but ended up with the
same XID, the GC failed to be updated and so the new mask was
not used. (stanton)

2/4/99 (bug fix) Changed so focus window is always set if -force is
specified.  This fixes the problem on Windows where Tk does not
activate the window if it already has focus. (stanton)

2/4/99 (bug fix) Fixed so errors in console eval are reported
properly.  Eliminated duplicate result messages. (stanton)

2/4/99 (bug fix) Under Windows, changed so toplevels that aren't
resizable don't have resize handles and the zoom box is disabled. (stanton)

2/4/99 (bug fix) Changed to cancel the mouse timer when a user
initiated move/resize loop begins on Windows. (stanton)

2/4/99 (configure change) TK_LD_SEARCH_FLAGS was set incorrectly if
SHLIB_LD_LIBS='${LIBS}', and shared linking is performed through the C
compiler. Systems affected are Linux, MP-RAS and NEXTSTEP, but also
with gcc on many more systems.

2/4/99 (bug fix) Changed some EXTERN declarations to extern since they
are not defining exported interfaces.  This avoids generating useless
declspec() attributes and makes the Windows makefile simpler. (stanton)

2/4/99 (bug fix) Changed so keyboard shortcuts will only be found in
the current toplevel.  Previously, they might be found in menus
attached to other toplevels that might not even be mapped. (stanton)
*** POTENTIAL INCOMPATIBILITY ***

2/4/99 (bug fix) Changed to treat zero width lines in the canvas like
they have width 1 for purposes of selection. (stanton)

2/4/99 (bug fix) Added a workaround for a bug in GetTextExtentExPoint
on Win NT 4.0/Japanese that cause a crash in some cases. (stanton)

2/4/99 (bug fix) Fixed uninitialized memory access bug in Unix send
code. (stanton)

----------------------------------------------------------
Changes for Tk 8.0 go above this line.
Changes for Tk 8.1 go below this line.
----------------------------------------------------------

1/16/98 (new feature) Tk now supports international characters sets:
    - Font display mechanism overhauled to display Unicode strings
      containing full set of international characters.  You do not need
      Unicode fonts on your system in order to use tk or see international
      characters.  For those familiar with the Japanese or Chinese patches,
      there is no "-kanjifont" option.  Characters from any available fonts
      will automatically be used if the widget's originally selected font is
      not capable of displaying a given character.
    - Textual widgets are international aware.  For instance, cursor
      positioning commands would now move the cursor forwards/back by 1
      international character, not by 1 byte.
    - Input Method Editors (IMEs) work on Mac and Windows.  Unix is still in
      progress.

7/7/97 (new feature) The send command now works for Microsoft
Windows. It is implemented using Dynamic Data Exchange, and a new
command, dde, allows Tk to send more generic DDE commands to other
applications. (SRP)

11/3/97 (new feature) Major overhaul of code that manages configuration
options to use Tcl_Obj structures instead of strings:
    - There is a new set of procedures including Tk_CreateOptionTable,
      Tk_InitOptions, and Tk_SetOptions, which replace Tk_ConfigureWidget
      and related procedures.  The old procedures are still available.
      The new procedures use a new format for configuration tables.
      See SetOptions.3 for more information.
    - There are new procedures Tk_AllocColorFromObj, Tk_GetColorFromObj,
      and Tk_FreeColorFromObj to manage colors using objects to hold the
      name of the color and cache the corresponding XColor pointer.
      There are similar procedures Tk_Alloc3DBorderFromObj,
      Tk_AllocBitmapFromObj, Tk_AllocCursorFromObj, Tk_AllocFontFromObj,
      and so on to manage borders, bitmaps, cursors, and fonts.
    - The old-style procedures such as Tk_GetColor and Tk_GetBitmap no
      longer take Tk_Uids for arguments; they just take strings.
    - Menus, labels, buttons, checkbuttons, and radiobuttons have been
      converted to use the new object-based configuration library.
      (SRP & JO)

11/7/97 (improvement) Changed code referring to "interp->result" to call
accessor functions like Tcl_SetResult().

12/23/97 (fix) Fixed transparency and web optimized the palette of
the images/ Tcl powered logos. (DL)

12/16/97 (bug fix) Canvas and text "bind" subcommands generated an
error with no message if called to fetch a binding that didn't exist.
They now silently return without an error like the "bind" command. (SS)

1/13/98 (bug fix) Keysyms for international characters were not being
reported properly under Windows. (SS)

----------------- Released 8.1a1, 1/22/98 -----------------------

2/4/98 (bug fix) Calling XFreeFontNames() twice if couldn't allocate
font. (CCS)

2/10/98 (bug fix) Inlined prolog.ps in tkCanvPs.c to make it accessible
from safe interpreters: canvas postscript now works in safe interps
(like in tk8.0plugin). (DL)

2/11/98 (bug fix) Windows "send" to a remote interp wasn't propagating
$errorInfo correctly from the remote interp to the local invoking interp.
(CCS)

2/11/98 (bug fix) Windows "send" should have accepted "--" to mean "no more
arguments". (CCS)

2/11/98 (bug fix) Windows "send" was concatenating its arguments
incorrectly (not consistent with "eval", "uplevel", or Unix "send"). (CCS)

2/18/98 (bug fix) Macintosh radiobuttons and checkbuttons now color
their backgrounds correctly under Appearance.  The controls gadgets themselves
however, remain the Theme colors. (JI)

2/18/98 (improvement) The corner pixels that peek through around the
rounded corners of the Mac button widget are now controlled by the
-highlightbackground, rather than the -background option. (JI)

2/18/98 (improvement) Implemented the intra-application Send on the
Mac (RJ)

2/18/98 (bug fix) Under X, a problem mapping from a fontStructPtr to an
XLFD (no XA_FONT attribute) would lead to dereferencing NULL. (CCS)

----------------- Released 8.1a2, Feb 20 1998 -----------------------

10/21/98 (bug fix) Tk_UnderlineChars did not handle UTF strings properly
so underline indices were in bytes instead of characters. (stanton)

11/19/98 (bug fix) Fixed menus and titles so they properly display
Unicode characters under Windows. [Bug: 819] (stanton)

11/24/98 (bug fix) Fixed a bunch of memory leaks in the Windows menu
code. [Bug: 620] (stanton)

11/25/98 (bug fix) Various small bug fixes: (stanton)
	- hidemargin option was not honored properly in menus [Bug: 859]
	- disabled menu entries were getting reenabled whenever the
	mouse passed over the entry [Bug: 860]
	- fixed deletion order bug where a crash would result if a
	binding deleted "."

11/30/98 (bug fix) The error result was getting lost when restoring
configuration options in buttons. [Bug: 619] (stanton)

12/8/98 (bug fix) The Windows clipboard was not correctly traslating
multibyte characters. [Bug: 935] (stanton)

----------------- Released 8.1b1, Dec 11 1998 -----------------------

1/29/99 (bug fix) Fixed bug in "grid forget" that failed to cancel
pending idle handlers, resulting in a crash in a few odd
cases. (stanton)

2/4/99 (bug fix): Fixed uninitialized memory access in
Tk_SetAppName. [Bug: 919] (stanton)

2/4/99 (bug fix): Added a workaround for a bug in GetTextExtentExPoint
on Win NT 4.0/Japanese. [Bug: 1006] (stanton)

2/4/99 (bug fix): Changed so keyboard shortcuts for menus will only be
found in the current toplevel.  Previously, they might be found in
menus attached to other toplevels that might not even be mapped.
[Bug: 924] (stanton)

2/4/99 (bug fix): Changed to treat zero width lines in the canvas like
they have width 1 for purposes of selection. [Bug: 925] (stanton)

2/4/99 (bug fix): TK_LD_SEARCH_FLAGS was set incorrectly if
SHLIB_LD_LIBS='${LIBS}', and shared linking is performed through the C
compiler. Systems affected are Linux, MP-RAS and NEXTSTEP, but also
with gcc on many more systems. [Bug: 908] (stanton)

2/4/99 (feature enhancement): Changed so windows that aren't resizable
don't have resize handles and the zoom box is disabled on
Windows. (stanton)

2/4/99 (bug fix): Fixed so errors in console eval are reported
properly.  Eliminated duplicate result messages. [Bug: 973] (stanton)

2/4/99 (bug fix): Changed so focus window is always set if -force is
specified.  This fixes the problem on Windows where Tk does not
activate the window if it already has focus. (stanton)

2/4/99 (bug fix): If an image mask changed but ended up with the same
XID, the GC failed to be updated and so the new mask was not
used. [Bug: 970] (stanton)

2/12/99 (new feature): Tk is now thread safe.  You enable this by
configuring with --enable-threads.  Tcl must also be compiled with
--enable-threads.  See Tcl for more information about the threading
interfaces. (lfb)

2/25/99 (bug fix) Under Windows, wish can now inherit pipe handles on
stdio so it is possible to use the wish executable in a command
pipeline to capture the output of puts or read from the pipe with
gets.  (redman)

3/1/99 (bug fix) Under Windows, Tk was not properly handling focus and
activation changes in some cases. (redman)

3/10/99 (new feature) Tk now uses the new stub library feature in Tcl.
The Tk library now contains no direct references to any symbols in
Tcl.  In addition, there is a new Tk_MainEx() function that takes an
interpreter as an argument.  See the Tcl documentation for more
information about the stubs mechanism. (redman)

3/14/99 (feature change) Test suite now uses "test" namespace to
define the test procedure and other auxiliary procedures as well as
global variables.
    - Global array testConfige is now called ::test::testConfig.
    - Global variable VERBOSE is now called ::test::verbose, and
      ::test::verbose no longer works with numerical values.  We've
      switched to a bitwise character string.  You can set
      ::test::verbose by using the -verbose option on the Tk command
      line.
    - Global variable TESTS is now called ::test::matchingTests, and
      can be set on the Tk command line via the -match option.
    - There is now a ::test::skipTests variable (works similarly to
      ::test::matchTests) that can be set on the Tk command line via
      the -match option.
    - The test suite can now be run in any working directory.  When
      you run "make test", the working directory is nolonger switched
      to ../tests.
(hirschl)
*** POTENTIAL INCOMPATIBILITY ***

----------------- Released 8.1b2, March 16, 1999 ---------------------

3/23/99 (feature change) Test suite now uses "tcltest" namespace to
define the test procedure and other auxiliary procedures as well as
global variables.  The previously chosen "test" namespace was thought
to be too generic and likely to create conflits.
(hirschl)
*** POTENTIAL INCOMPATIBILITY ***

3/26/99 [bug fix]  Fixed bug reported by Bryan Oakley in the
menubutton bindings.  There was a false assumption that there was
always a menu attached to the button.  [Bug 1116] (surles)

3/26/99 (feature change) Removed --enable-tcl-stub from the configure
script. Linking Tk to Tcl stubs is causing too many problems when
linking executables like wish.  Until the Tk is a fully loadable
extension, linking against the Tcl stubs is not supported in Tk.
(redman)

3/26/99 (feature change) --nameble-shared is now the default and builds
Tk as a shared library; specify --disable-shared to build a static Tk
library and shell.
*** POTENTIAL INCOMPATIBILITY ***

3/29/99 (api change) Standardized text layout and font interfaces
so they are consistent with respect to byte versus character
oriented indices.  The layout functions all manipulate character
oriented values while the lower level measurement functions all
operate on byte oriented values. (stanton)

4/1/99 (bug fix) Image handlers are finalized before the font subsystem
to fix crashes during finalization of complex widgets. (stanton)

4/1/99 (feature change) Removed the send command on Windows.  Moved
the DDE basis of that command out to its own extension.  The send
implementation on top of DDE was causing Tk to lock up in some cases.
(redman)

4/5/99 (bug fix) Fixed handling of Unicode in text searches.  The
-count option was returning byte counts instead of character counts.

4/5/99 (feature change) Cut and paste to an entry widget returns the
selection instead of the widget contents, which can be different if the
-show option is used to hide the display. (stanton)

--------------- Released 8.1b3, April 6, 1999 ----------------------

4/20/99 (compiler fix) changed definition of Status type to use a
typedef instead of a #define to avoid conflicting with the cygwin win32
headers. (redman)

4/22/99 (bug fix) Set the -translation and -encoding options to binary
for image files. (redman)

4/27/99 (bug fix) Changed to avoid the need for forward declarations in
stub initializers.  Added extern "C" blocks around stub table pointer
declarations so the stubs can be used from C++ code. (stanton)

--------------- Released 8.1 final, April 29, 1999 ----------------------

5/7/99 (bug fix) Fixed bug wheretk_popup fails when called too
quickly. [Bug: 2009] (stanton)

5/18/99 (bug fix) Fixed clipboard code so it handles Unicode data
properly on Windows NT and 95. [Bug: 1791] (stanton)

5/19/99 (bug fix) Add extern "C" block around entire header file for
C++ compilers to fix linkage issues.  Submitted by Don Porter and Paul
Duffin. (redman)

--------------- Released 8.1.1, May 25, 1999 ----------------------

5/21/99 (bug fix) Fixed clipboard code to handle lack of CF_LOCALE
information (from command.com).  (stanton)

6/1/99  (bug fix) Improved I18N selection support.  COMPOUND_TEXT
is converted to/from iso2022, and STRING is converted to/from
iso8859-1.  More work is needed.  (stanton)

6/3/99  (bug fix) Fixed selection code to handle Unicode data in
COMPOUND_TEXT and STRING selections.  [Bug: 1791] (stanton)

6/16/99 (new feature) Changes to makefiles and configure scripts to
support TEA specification.  (wart)

6/30/99 (bug fix) Removed deprecated functions, patch from Jan
Nijtmans. [Bug 2080] (redman)

6/30/99 (bug fix) Applied patch to allow Img extension to work with
8.2, patch from Jan Nijtmans.  [Bug 2068] (redman)

6/30/99 (bug fix) Applied patch from Don Porter to prevent the Windows
shutdown code from calling Tcl functions when the stub table has not
been initialized in TkWinWmCleanup. [Bug: 2269] (redman)

7/8/99  (bug fix) Changed TkWinChildProc to pass WM_WINDOWSPOSCHANGED
through to DefWindowProc to make OpenGL sub-windows happpy.  This
allows Windows to generate the WM_SIZE and WM_MOVE messages. (stanton)

--------------- Released 8.2b1, July 14, 1999 ----------------------

7/16/99 (bug fix) Copy prolog.ps from the generic directory for
install-libraries make target. (redman)

7/22/99 (bug fix) Applied patch from Jeff Hobbs to fix
library/menu.tcl. [Bug: 2425] (redman)

7/22/99 (bug fix) Make install-sh have executable permissions before
calling from the Makefile. [Bug: 2413] (redman)

7/22/99 (bug fix) Block out sys/stat.h include with #if to allow
extension writers to use the MetroWerks compiler on Windows.
[Bug: 2385] (redman)

7/29/99 (bug fix) Allow tcl to opn CON and NUL on Windows, moved check
to Tk Console code instead.  [Bug: 2393 2392 2209 2458] (redman)

7/30/99 (bug fix) corrected the Windows build of threaded Tk from both
sets of makefiles (nmake and gmake). (redman)

7/30/99 (bug fix) Added XFillRectangle to stub table, patch from Jan
Njitmans.  [Bug: 2446] (hobbs)

8/1/99  (bug fix) Wrapped #define of panic() inside #ifndef blocks to
avoid compiler errors on Macintosh.  Patch from Vince Darley.
[Bug: 2389] (hobbs)

--------------- Released 8.2b2, August 5, 1999 ----------------------

8/13/99 (Mac) Rearranged the projects in the tkMacProjects.sea.hqx so
that the build directory is separate from the sources.  Fixed bug in
Tk_DrawChars(). (Jim Ingham)

--------------- Released 8.2.0, August 17, 1999 ----------------------

9/21/99 (bug fix) fixed 'wm deiconify' quirks on Windows. (hobbs)

9/21/99 (bug fix) fix fg<>bg GC swap bug for canvas. [Bug: 2676] (hobbs)

9/21/99 (config fix) fixed AIX config issues for Tk. (hobbs)

9/24/99 (feature change) tk_dialog now uses {Times 12} by default. (hobbs)

--- Released 8.2.1, October 04, 1999 --- See ChangeLog for details ---

10/30/99 (bug fix) fixed XKeysymToKeycode to handle mapping of symbolic
keysyms (Left, Home, ...) with event generate (hobbs)

10/30/99 (bug fix) change tkEntrySeeInsert to avoid the use of a while loop
that could eat CPU tremendously.  Behavior of moving the cursor at the
right edge changes slightly. [Bug: 3195] (hobbs)

10/30/99 (bug fix) changed tkScrollButtonUp to check for existence of
tkPriv(relief) in order to avoid spurious release events (hobbs)

--- Released 8.2.2, November 04, 1999 --- See ChangeLog for details ---

11/19/99 (bug fix) fixed expression error that could cause
'malformed bucket chain' error in tkEntry.c. (hobbs)

11/19/99 (bug fix) fixed Tk_NameOfColor (hobbs)

--- Released 8.2.3, December 16, 1999 --- See ChangeLog for details ---

1999-09-01 (feature enhancement) rewrote runtime libraries to use new
Tcl functions where appropriate

1999-10-28 (feature enhancement) added Img patch from Jan Nijtmans that
makes the image command Tcl_Obj-based, adds support for binary -data args,
adds alpha channel to images, adds GIF write capability (RLE).  Binary
compatability is maintained, and source level compatibility is retained
with -DUSE_OLD_IMAGE. (nijtmans)

1999-11-16 (feature enhancement) made listbox Tcl_Obj based, added
-listvariable option and itemconfigure command to allow coloring
individual items. (melski)

1999-11-23 (feature enhancement) added TK_OPTION_DONT_SET_DEFAULT as an
equivalent to TK_CONFIG_DONT_SET_DEFAULT (hobbs)

1999-11-24 (feature enhancement) updated dialogs to use color icons on
Unix, center properly over -parent. (hipp, hobbs)

1999-12-01 (feature enhancement) added hooks into main() code to support
"big" shells more easily. (redman)

1999-12-02 (feature enhancement) converted Tk_DestroyCmd, Tk_LowerCmd and
Tk_RaiseCmd to their ObjCmd equivalent.

1999-12-12 (bug fix) fixed bug in TextSearchCmd for multibyte chars

1999-12-13 (feature enhancement) added support for pointer warping via the
event -warp option, added some items from Dash patch: canvas widget now
Tcl_Obj-based, added Tk_CreateSmoothMethod, added support for <Quadruple>
clicks, entry widget validation routines, new -state hidden in text
widgets, new -state -active* -disabled* -offset options to canvas items
(see man page for full docs).  New features include dashed line support on
the canvas, -elide support for TkMan, postscript printing of images and
windows from the canvas.  Binary compatibility is maintained with 8.2, and
source level compatibility is kept by using -DUSE_OLD_CANVAS.
(hobbs, nijtmans, et al)

1999-12-16 (feature enhancement) added "bitstream cyberbit" to list of
font fallbacks. (hobbs)

1999-12-16 (feature enhancement) added new 'tk useinputmethods ...' command
to provide support for disabling/enabling the use of XIM on X.  This was
previously all done at compile time, and always on.  Now it is turned off
by default, even when available, and the user must turn it on to use XIM
(per display).
	*** POTENTIAL INCOMPATIBILITY ***
user must add 'tk useinputmethods 1' to retain old style. (hobbs)

1999-12-16 (feature enhancement) added proper support for -initialfile
to tk_get*File, and made Unix version better match Windows file box
that it was emulating. (hobbs)

1999-12-16 (bug fix) removed necessity of 'update idle' before 'wm
deiconify' on Windows. (mao)

1999-12-16 (feature enhancement) added support for Windows system cursors
to TkGetCursorByName (use -cursor @filename)

1999-12-21 (bug fix) fixed lack of refresh for thin frames (darley)

1999-12-21 (bug fix) fixed panic in Tk_CoordsToWindow to print error
to stderr instead (for Tix) (hobbs)

1999-12-21 (bug fix) fixed segv with scale widget when using -cursor (hobbs)

--- Released 8.3b1, December 22, 1999 --- See ChangeLog for details ---

2000-01-05 (bug fix) Applied fixes for unprotected arg passing through eval
and after in Tk runtime code [Bug: 3943] (hobbs)

2000-01-05 (bug fix) Applied fix for i18n problems with Mac clipboard
[Bug: 3544] (hobbs)

2000-01-05 (feature change) removed the 8.3b1 introduced -state option
for text tags, and documented -elide (-state hidden == -elide true) (hobbs)

2000-01-12 (bug fix) fix Windows 'wm deiconify' to zoomed state [Bug: 2077]
and fixed possible flashing of unmapped toplevel in deiconify [Bug: 3338]
and fixed unwanted mapping of transient window [Bug: 572] (hobbs)

2000-01-12 (feature enhancement) extended 'wm state' to accept a state
to set for the toplevel, and added support for zoomed (maximized) state
on Windows (hobbs)

2000-01-12 (bug fix) Applied fix for cursor to not blink when entry or
text widget was disabled [Bug: 1807] (hobbs)

--- Released 8.3b2, January 13, 2000 --- See ChangeLog for details ---

2000-01-20 (bug fix) fixed interpretation of consecutive ^ characters in
grid command (melski)

2000-01-20 (bug fix) fixed -select(bg|fg) class names in listbox (hobbs)

2000-01-20 (bug fix) fixed handling of too few coords for line item type in
canvas (hobbs)

2000-01-20 (bug fix) fixed dialog's association with parent (melski)

2000-01-26 (bug fix) fixed handling of binary data for -data option to
image create (melski)

2000-01-26 (feature enhancement) improved GIF decoding speed by ~60%
(melski)

2000-01-26 (feature enhancement) added tk_chooseDirectory implementation
for Unix and Mac (nelson, melski)

2000-02-01 (bug fix) fixed resolution rounding problem in scale (porter)
and fixed potential Unix seg fault due to use of ckfree instead of
Tcl_EventuallyFree (hobbs)

2000-02-01 (bug fix) fixed handling of negative dash values for canvas
items (nijtmans)

2000-02-01 (bug fix) fixed dialog lockup on Windows where once the native
dialog disappeared, the parent window could end up locked up (hobbs)

2000-02-03 (bug fix) fixed text dump to use char indices instead of byte
indices (melski)

2000-02-07 (bug fix) fixed handling of default extension in unix file
dialogs (dejong)

2000-02-08 (bug fix) corrected windows symbol font use to restrict itself
to 8-bit chars (kenny)

2000-02-08 (feature enhancement) improved support for moving from the old
style image C API to the new obj'ified one with new Tk_InitImageArgs
command and stub'ing of image code.  See docs for how to make the
transition. (nijtmans)

2000-02-08 (bug fix) fixed incorrect handling of CapsLock on Win9* and the
use of dead keys on international keyboards (spjuth)

2000-02-10 (bug fix) brought Mac back to building state, added support
for Appearance Manager (ingham)

2000-02-10 (feature enhancement) added support for buttons 4 && 5 as
mousewheel style scrolling in listbox and text widget for Unix.

--- Released 8.3.0, February 10, 2000 --- See ChangeLog for details ---

2000-03-02 (bug fix) fixed crash in listbox when cursor was configure and
then widget was destroyed (hobbs)

2000-03-02 (feature enhancement) added %V substitution to entry widget
validation to clarify type of validation occuring (hobbs)

2000-03-07 (feature enhancement) added -disabledforeground/-state to labels
(melski)

2000-03-29 (config enhancement) improved build support for gcc/mingw on
Windows (nijtmans, hobbs) and added RPM target (melski)

2000-03-24 (bug fixes) numerous corrections for more correct Unix dialog
behaviors (melski)

2000-03-27 (bug fix) fixed mem leak in wm commands (hu)

2000-03-31 (bug fix) correct initialization of Windows static builds and
added Unicode aware open/save file dialogs on Windows (hobbs)

2000-03 (bug fix) canvas: corrected support for transparency in dashed
lines on Windows (nijtmans); added support for postscript generation of
images on Windows, also fixing transparency printing (biancardi); corrected
handling of configure options in non-empty canvas (melski)

2000-04-07 (bug fix) correct font name length restriction that prevented
the use of long named (>16 char) fonts on NT/2000 (hobbs)

2000-04-07 (bug fix) fixed safe Tk to work in base cases (hobbs)

2000-04-10 (bug fix) corrected Alt-Key event generation and handling of
Alt-sequence Windows special char generation and (Control|Shift|Alt)_L/_R
determination (melski)

2000-04-10 (bug fix) correctly check state of parent when popping up
bgerror dialog. (melski)

2000-04-11 (feature enhancement) msgcat now searches up the namespace chain
for a match instead of just in the local namespace (hershey)

2000-04-12 (bug fix) corrected handling of Windows clipboard to allow for
use of user-defined types within the Tk app (hobbs)

2000-04-13 (feature enhancement) improved handling of shadow determination
for 3D borders in very light/dark cases (hipp, melski)

2000-04-13 (bug fix) correctly color separator bg in menus on Windows
(melski)

2000-04-14 (bug fix) improved handling of scale widget, reduced number of
redraws (hobbs)

2000-04-17 (feature enhancement) made shift-selection more Windows-like
(intuitive) in text widget (melski)

2000-04-22 (bug fix) mac bug fixes, nav services handling (ingham)

2000-04 more docs for public APIs (melski)

--- Released 8.3.1, April 26, 2000 --- See ChangeLog for details ---
2000-04 (doc updates) extended, updated docs (melski)

2000-05-09 (feature change) removed WS_EX_TOOLWINDOW style bit for
transient windows on Windows platforms, so that transients have
full-size titlebars (melski)

2000-05-09 (bug fix) fixed calling of takeFocus proc (nemethi)

2000-05-11 (bug fix) corrected handling of 3DBorder, Cursor and Color
objects on multiple screens (hobbs)

2000-05-12 (feature enhancement) improved support for chars in 0-255
range for bitmap ANSI fonts (spjuth, hobbs)

2000-05-12 (widget enhancement) added support for -repeatdelay,
-repeatinterval for command buttons; and -compound (image and text
simultaneously) for labels, check-, radio-, and command buttons (melski)

2000-05-14 (widget change) added "readonly" state for entries and
changed behavior of "disabled" entries; added -readonlybackground
option for entries (melski)
*** THIS IS A BACKWARDS INCOMPATIBLE BEHAVIOR CHANGE ***

2000-05-15 (feature enhancement) added [image inuse] command (melski)

2000-05-15 (feature enhancement) added -nice option to [bell] command (duncan)

2000-05-17 (widget enhancement) added -overrelief option for
check/radio/buttons (melski)

2000-05-26 (feature change) added support for new syntax in
Tk_OptionSpec tables; if the database name for an option contains an
embedded "." it indicates that the name contains an overriding window
class specifier in addition to the database name, which allows widgets
to perform queries for certain options as if they were options for a
different widget class (melski)

2000-05-28 (new widget) added spinbox widget (hobbs)

2000-05-31 (feature change) replaced bgerror dialog with a new and
improved one (fellows, melski)

--- Released 8.4a1, June 6, 2000 --- See ChangeLog for details ---

2000-05-15 (bug fix) changed wm deiconify from using idle callback to
calling restack and focus code immediately. (hobbs)

2000-07 (build cleanup) cleanup of defines in tkConfig.sh, and cleanup
in make and configure files to better handle .rc files across
builds. (welch)

2000-07 (build improvements) cleanup of the makefiles and configure scripts
to correct support for building under gcc for Windows. (dejong)

2000-08 (feature enhancements) for Windows, corrected drawing of separator
menu entries, disable menu entries and the height for separator
bars. (melski)

2000-08 (bug fix) fixed calling of takeFocus proc with arg bearing
functions. (nemethi)

2000-08 (bug fix) For text widgets, added a test for a NULL segment pointer
when doing backwards searches for "", correct searching over elided chars,
and corrected search combining -regexp and -nocase. (melski)

2000-08 (bug fix) Corrected code for using 'place', cursors, colors and 3D
borders on multiple screens simultaneously. (hobbs, hipp)

--- Released 8.3.2, August 9, 2000 --- See ChangeLog for details ---

2000-06-15 (new feature) [tk_getOpenFile ... -multiple] (melski)

2000-06-29 (new feature) localization support in Tk dialogs (duperval,
melski, et al)

200-07-28 (new feature) -state option for listbox, better native color
defaults (melski)

2000-08 (feature rewrites) Tcl_Obj'ified clipboard, message, tkwait,
bindtags, grab. place, selection commands (melski)

2000-08-24 (new feature) More correct GNU configure support (no more
--enable-gcc) (dejong)
	*** POTENTIAL INCOMPATIBILITY ***

2000-08-29 (bug fix) Corrected Windows menu indicator drawing (oberhumer)

2000-09-01 (bug fix) Added tkPlatDecls.h to default install (melski)

2000-09-17 (new feature) Added TK_OPTION_CUSTOM type, similar to
TK_CONFIG_CUSTOM (melski)

2000-09-29 (bug fix) Several fixes for multi-display uses of Tk (hipp, hobbs)

2000-10-05 (new feature) Tk_CreateAnonymousWindow API to create anonymous
Tk windows controllable from C (melski)

2000-10-27 (new default behavior) [tk useinputmethods 1] is the default
in tk.tcl, for users of XIM and "dead" keys (hobbs)

2000-10-30 Improved support for static builds on Windows (gravereaux)

 * Added support for mingw (gcc on Windows), AIX-5 and Win64 builds
   (dejong, hobbs)

 * Improved error checking in Windows native dialogs (melski, hobbs)

--- Released 8.4a2, November 3, 2000 --- See ChangeLog for details ---

2001-04-04 (build improvements) redid Mac build structure (steffen)
Corrected IRIX-5* configure (english).  Added support for AIX-5 (hobbs).
Added support for Win64 (hobbs).

2001-04-04 (doc fixes) numerous doc corrections and clarifications.
Update of READMEs.

2001-04-04 (bug fix) corrected reseting of service mode to only occur when
it was set (hedin, hobbs)

2001-04-02 (bug fix) Improved tests on Windows for correctness.
Checked for menu deletion before calling associated menu entry command.
Fixed listbox, canvas and entry destruction to be more aware of current
widget activity. (hobbs)

2001-03-30 (feature enhancement) added support for changing IME on the fly
in Windows (2000) (lam)
(bug fix) handled the error case where a valid-looking but invalid
identifier could be passed in certain event generate options causing a
crash (hobbs)

2001-03-29 (bug fix) corrected handling of drag-selection (dejong)

2001-01-02 (feature enhancement) added Windows icon support in wm
iconbitmap (darley)

2000-10-27 (feature enhancement) made [tk useinputmethods 1] the default
for Tk (hobbs)

2000-10-18 (bug fix) Corrected rendering of 1-pixel wide stippled lines on
Windows.  Correct use of active- and disabledwidth values for displaying
lines.  Enhanced error handling in Windows native dialogs (melski)

2000-09-29 (bug fix) corrected BadMatch errors when using Tk on multiple
screens (hipp)

2000-08-18 (feature enhancement) Removed redundant call to DitherInstance
(melski)

--- Released 8.3.3, April 6, 2001 --- See ChangeLog for details ---

2000-11-21 (new feature)[TIP 5] Tk_ClassProcs, Tk_SetClassProcs API (melski)

2000-12-13 (performance enhancement)[403327] Tcl_Objs of type "double"
are recognized in SetMMFromAny to speed up canvas coord calculations (hobbs)

2001-01-02 (new feature)[TIP 8] [wn iconbitmap -default] on Windows (darley)

2001-02-12 (new feature)[TIP #21] asymmetric padding in the pack and grid
geometry managers (hipp)

2001-05-21 (new feature)[TIP #11], -compound for [menubutton] widget (helfter)

2001-06-03 (bug fix) corrected support for is10646 fonts on Unix, added a
ucs-2be encoding (welch)

2001-07-02 (bug fix) allowed tkwin to be Tcl_EventuallyFree'd in
Tk_DestroyWindow so other widgets could register their use of it.  Updated
entry and listbox widgets to use this, correcting potential crashes. (hobbs)

2001-08-01 (interface rewrite)[TIP 44] moved all private tk[A-Z]* commands and
variables into the ::tk:: namespace (porter)
	*** POTENTIAL INCOMPATIBILITY ***

 * overhaul of configure scripts for cleaner standard support and support
   of mingw gcc on Windows. (mdejong)

 * improved tests to better handle results on variant systems (hobbs)

 * correct several minor Purify complaints (hobbs)

--- Released 8.4a3, August 6, 2000 --- See ChangeLog for details ---

2001-08-06 (new feature) added GNU (HURD) build support. (brinkman)

2001-08-23 (new feature) added QNX-6 build support. (loverso)

2001-08-24 (bug fix) correct several possible free memory reads and array
bounds read errors reported by purify. (hobbs)

2001-08-27 (new feature) added call to Tcl_SetMainLoop which enables Tk to
be loaded interactively into tclsh and have the event loop kick in
correctly. (hobbs)

2001-08-28 (bug fix) fixed tk_chooseDirectory crash on Win95. (baker)

2001-08-28 (bug fix) removed 2 second 'raise' delay seen by some Unix
window managers. (hobbs, baker)

2001-09-14 (bug fix) fixed memory leaks that occured if errors were
thrown while initializing the channel for an image. (darley)

2001-09-20 (new feature) --enable-64bit support was added for HP 11 when
using the native compiler.

2001-10-03 (new feature) finalized Win64 support with latest RC1 release
and SDK. (hobbs, stacy)

2001-10-04 (new feature) added enhanced bgerror dialog from Hipp. (hobbs)

2001-10-09 (new feature) added brace/quote matching and file/path/var
expansion to the Win/Mac console. (hobbs)

2001-10-17 (bug fix) fixed file filtering in the motif file dialog (nelson)

2001-10-17 (bug fix) updated Mac build support. (steffen)

--- Released 8.3.4, October 19, 2001 --- See ChangeLog for details ---

2001-08-14 (bug fix)[450545] Tk's Tcl_ObjTypes now registered (fellows)

2001-08-20 (performance enhancement) internal use of a "window" Tcl_ObjType
(fellows)

2001-08-20 (performance enhancement) Obj-ified [grid] and [pack] (spjuth)

2001-09-26 (new feature)[TIP 18] add labels to frames, update geometry
managers (spjuth)

2001-09-30 (new feature)[TIP 37] [grid {row|column}configure -uniform] (spjuth)

2001-10-12 (new feature)[TIP 63] [$menu add ... -compound] (helfter)

2001-10-18 (build improvement) no more warnings about building with
thread-enabled Tcl (hobbs)

2001-11-10 (build improvement) new make target 'make gdb' (dejong)

2001-11-12 (new feature)[TIP 26] simple undo/redo in text widget (callewaert)

2001-11-12 (build improvement) revitalized makefile.vc (gravereaux)

2001-11-17 (visual change) default button size on Windows changed to
conform to Windows style (hobbs)
	**** POTENTIAL VISUAL INCOMPATABILITY ****

2001-12-03 (new feature)[TIP 74] [wm stackorder] (dejong, steffen)

2001-12 (new feature) more use of Unicode in native widgets on Windows (hobbs)

2001-12-18 (bug fix)[413735] event-click-drag-1.2 test failure (porter)

2001-12-28 (new feature) On Windows, buttons accept negative widths, meaning
minimum size, enabling native L&F (hobbs)

2002-01 (bug fix) updates for CONST-ification in Tcl API, notably
Tcl_ParseArgv.  Use -DUSE_NON_CONST to suppress source incompatibility
	**** POTENTIAL INCOMPATABILITY ****

2002-01-31 (bug fix)[508988] logic error in menu cloning (helfter)

2002-02-01 (new feature)[TIP 14] [$photo transparency] (fellows)

2002-02-01 (bug fix)[511956] C99 spec: avoid 'bool' as a variable name (hobbs)

2002-02-19 (bug fix) updates to image code calls of Tcl_Seek/Tcl_Tell to
address TIP 72 changes (64-bit) in Tcl (fellows)

2002-02-21 (new widget)[TIP 41] added [panedwindow] (hobbs)

2002-02-22 (new feature)  64-bit support for xlc compiler on AIX-4 (hobbs)

2002-02-25 (bug fix)[503772] blinking cursor fix in [text] (hobbs)

2002-02-25 (bug fix)[503613] [listbox] handling of invalid listvar (hobbs)

2002-02-25 (feature change)[493145] mirror B2 bindings to B3 on Windows (hobbs)

 * (updated demos) many updates to show new features (fellows)

--- Released 8.4a4, March 5, 2002 --- See ChangeLog for details ---

2002-03-20 (feature change)[TIP 27][532644] Constness changes (porter)

2002-03-21 (bug fix)[528441] Change in optimization flags for windows
(gravereaux)

2002-04-08 (bug fix) MSL stdin/out fixes prevent crash on exit  (steffen)

2002-04-12 (bug fix) Centralized closing of display, mem-leak fixes (hobbs)

2002-04-22 (bug fix)[223739] More robust FP comparisons for odd
architectures (fellows)

2002-04-22 (bug fix)[541999] Fixed posible overun of 16-bit size limit
of X windows in drawchars (hobbs,bonfield)

2002-04-22 (bug fix)[541849] ButtonLeave implementation corrected (hobbs)

2002-04-24 (new feature) TCLTK_NO_LIBRARY_TEXT_RESOURCES check added,
allowing disable of inclusion of tk lib into resources (steffen)

2002-05-07 (bug fix)[553208] Makefile/Win fix (TCLDIR, INSTALLDIR
forward slash trouble resolved) (gravereaux)

2002-05-20 (bug fix) msgcat added to resources, fixed setup of bindings
on startup (steffen, porter)

2002-05-21 (bug fix) Build system fix, SC_ENABLE_SHARED before
SC_CONFIG_CFLAGS for usage for SHARED_BUILD (dejong)

2002-05-26 (bug fix)[548765] Fixed -value "" redraw error for variable
created by radiobutton (spjuth)

2002-05-27 (feature change) [wm transient .t .t] now raises an error (dejong)
	*** POTENTIAL INCOMPATIBILITY ***

2002-06-10 (new feature)[566605] Utilities for -underline, ampersand magic
(kovalenko)

2002-06-12 (feature change) A transient toplevel now mirrors state changes
in the master. (dejong)
	*** POTENTIAL INCOMPATIBILITY ***

2002-06-13 (bug fix) Fixed handling of cursor specs across platforms to
be consistent. (fellows)

2002-06-14 (new feature) [TIP 98] Enhanced photo compositing (fellows)
	*** POTENTIAL INCOMPATIBILITY ***

2002-06-14 (bug fix) Removed references to matherr (kupries)

2002-06-14 (new feature) [TIP 47] Reorganized Tk to allow usage in writing
an X wm (english)

2002-06-14 (new feature) [TIP 84] Full motion events upon request (hobbs)

2002-06-17 (new feature) [TIP 82] -offrelief option for check/radiobutton
(hipp)

2002-06-17 (enhancement) Added msg catalog for UK English. (porter)

2002-06-17 (new feature) [TIP 96] Added caret handling (hobbs)

2002-06-19 (new feature) [TIP 48] Added style engine (bonnet)

2002-06-19 (bug fix)[570902] Reorganized Tk shutdown to work around bugs in
X (dejong)

2002-06-20 (new feature) [TIP 94] Added -activestyle for [listbox] (hobbs)

2002-06-21 (new feature) [TIP 104] generalized text undo/redo (callewart,
hobbs)

2002-06-22 (new feature) [TIP 95] Added [wm attributes] command (hobbs)

2002-06-22 (new feature) [TIP 93] enhanced get/delete to accept accept
multiple range pairs (hobbs)

--- Released 8.4b1, July 5, 2002 --- See ChangeLog for details ---

2002-07-11 (bug fix) some memory allocation failures now result in
	error messages rather than panic (fellows)

2002-07-15 (platform support) Borland makefile on Windows (gravereaux,giese)

2002-07-16 (bug fix)[220800,581627] icon reading (darley)

2002-07-19 (bug fix) Postscript generation on Win2K (hipp)

2002-07-22 (bug fix)[570764,568278] transient windows (dejong)

2002-07-24 (bug fix)[581560] canvas memory management (hobbs)

2002-07-24 (bug fix)[584691] focus ring on compound button (hobbs)

2002-07-25 (feature enhancement)[564521] Obj-ified [wm] (spjuth)

2002-08-04 (new feature)[589853][TIP 27] Tk interfaces are now fully
	CONST-ified.  Use the symbols USE_NON_CONST or USE_COMPAT_CONST
	to select interfaces with fewer changes.
        *** POTENTIAL INCOMPATIBILITY ***

2002-08-07 (bug fix)[578654] bezier curves on canvas (hobbs)

2002-08-07 (platform support)[468139] native directory browser on Win (hobbs)

2002-08-07 (bug fix)[467524] fixed -from handling for gifs (obermeier)

2002-08-08 (bug fix)[592201] wm transient panic (english,dejong)

Rewrote Tk test suite to use tcltest package.

--- Released 8.4b2, August 9, 2002 --- See ChangeLog for details ---

2002-08-20 (bug fix) tk.h checks for matching tcl.h version (porter)

2002-08-27 (bug fix)[582457] toolbar button bindings (hipp)

2002-08-31 (platform support)[602770] Mac OS X / Aqua port (steffen)

2002-09-02 (bug fix)[565485] button height on windows (hobbs)

2002-09-02 (new feature)[TIP 108] new comand [tk windowingsystem] (steffen)

2002-09-02 (new feature)[TIP 107][601518] [raise] is non-blocking (english)

2002-09-02 (platfrom support) 64-bit compile on HP-11 (martin)

--- Released 8.4.0, September 10, 2002 --- See ChangeLog for details ---

2002-09-15 (bug fix)[570902] Use PEEK_XCLOSEIM to examine the input context
queue before invoking XCloseIM. Generate an assert if there is an input
context that has not been freed. (dejong)

2002-09-18 (platform support) Updated support for compiling with Cygwin and
either mingw or gcc. (khan, howell, dejong)

2002-09-30 (bug fix)[614650] Correct incremental transfers of UTF8_STRING
selections (fellows)

2002-10-02 (bug fix)[616791, 614474] don't blink the cursor unless it is
visible. (bonfield)

2002-10-02 (bug fix)[607390, 617446] check if the entry is being deleted
before handling an associated textvariable. (hobbs)

2002-10-08 (bug fix)[616589] leave the DestroyPanedWindow proc to free the
pwPtr. (hobbs)

2002-10-08 (bug fix)[588831] Ignore event if we are focusing into a dead
window (griffin)

2002-10-09 (bug fix)[619544] Only error-out creating an image if we fail to
allocate a non-empty buffer (fellows)

2002-10-09 (build support) all --enable-symbols to take the enhanced
options yes|no|mem|all. (hobbs)

2002-10-10 (feature enhancement) added support for generating ps for
embedded widgets on canvases on Windows (hobbs)

2002-10-10 (bug fix)[621241] The grid size was not updated properly when
removing a widget from a grid (forssen)

2002-10-16 (bug fix)[616988] macosx fix to accelerators shown in menus
with non-alphanumeric keys. (darley)

2002-10-15 (platform support) Correct AIX-5 ppc and 4/5 64-bit build flags.
Correct HP 11 64-bit gcc building. (martin, hobbs)

2002-10-17 (bug fix)[624974] fix arg handling for missing image create
photo -format or -data options (hobbs)

2002-10-17 (bug fix)[624732] In ControlUtfProc, properly return the number
of bytes consumed (hobbs)

2002-10-22 (platform support)[624509] On macosx, add embedded framework
dirs to tcl_pkgPath: @executable_path/../Frameworks and
@executable_path/../PrivateFrameworks (if they exist), as well as the dirs
in DYLD_FRAMEWORK_PATH (if set).  Added 'rapp' apple event handler.  Added
TEXT document type to plist so that files can be dragged onto Wish Shell.
Added private proc TkMacOSXUseAntialiasedText() to enable/disable quickdraw
text antialiasing where available, default is enabled.  Added a linked
boolean ::tk::mac::antialiasedtext with write trace to allow control of
antialiasing from tcl.  (steffen)

--- Released 8.4.1, October 22, 2002 --- See ChangeLog for details ---

2002-11-07 (bug fix)[635025,532022] Make [place info] complete and bring into
line with other geometry managers. (spjuth)

2002-11-14 (bug fix)[630533] Handle half-dead windows better. (dejong)

2002-11-19 (bug fix) Better handling of narrow scrollbars on OSX. (ingham)

2002-11-22 (bug fix)[641778] Make the [text see] work when the widget is
unmapped. (hobbs)

2002-12-01 (bug fix) Stopped [wm withdraw] and [wm transient] from interfering
with each other. (dejong)

2002-12-06 (bug fix) Improved DLL cleanup on Windows. (hobbs)

2002-12-06 (new feature) New function TkWinSetHINSTANCE() as part of enabling
dynamic Tk to load resources correctly. (hobbs)

2002-12-13 (bug fix)[616245] Use Tcl*StartupScript*() routines in Tk_Main.
(porter)

2002-12-27 (bug fix)[578569] Made sure that Tk always knows whether its windows
are mapped or not. (english)

2003-01-03 (bug fix)[661792] Stopped crash when trying to create a toplevel
when Tk is dying. (hobbs)

2003-01-08 (bug fix)[663981] Clip long lines so they show correctly even when
they hit windowing-system limits. (hipp)

2003-01-14 (bug fix)[666346] Stopped selection handling crashes under KDE3.0.
(english)

2003-01-22 (bug fix)[220891] Image creation cannot trigger Tk's death.
(fellows)

2003-01-23 (bug fix)[673687] Entry typein works as expected even when the mouse
button is pressed. (hipp)

2003-01-28 (bug fix)[671330] Stopped segfaults from unsynchonized window
deletion epochs. (english)

2003-02-08 (bug fix) Make canvas item coordinate list handling consistent to
stop segfaults.  Cannot now create items without coordinates. (hobbs)
	*** POTENTIAL INCOMPATIBILITY ***

2003-02-10 (bug fix) Better support for themed and animated cursors on OSX.
(ingham)

2003-02-17 (bug fix) Stopped motion events from morphing into button press
and motion events. (dejong)

2003-02-18 (bug fix) Removed memory leak in GIF image loader. (fellows)

2003-02-18 (bug fix) Made OSX menus support UTF8 text and icons. (darley)

2003-02-18 (bug fix)[608559] Stop message boxes from getting extremely wide.
(hobbs)

2003-02-18 (bug fix)[683813] Make focus behaviour of spinboxes more like
entries. (bron)

2003-02-19 (new demo)[627453] New demo showing off Tk's Unicode font handling.
(fellows,suchenwirth)

2003-02-19 (bug fix) Bring event handling more into line with the OSX standard.
Also improves "dead key" handling. (riefenstahl,ingham)

2003-02-20 (bug fix)[618872,689357] Stopped read of freed memory when working
with large composite fonts. (fellows)

2003-02-20 (bug fix)[689099,tcllib 689258] Improvements to [panedwindow] pane
size and sash handling. (spjuth,hobbs)

2003-02-20 (bug fix)[624116] Stopped semi-crash in Windows scrollbar handling.
(hobbs)

2003-02-21 (bug fix)[671122] Stopped panedwindow from crashing when embedded
in a window with a different visual to the root window. (fellows)

2003-02-21 (bug fix)[617392] Limit the screen-size of [tk_get*File] file type
selection menu. (fellows)

2003-02-21 (bug fix)[673722] Rework standard dialogs to use [grid]. (fellows)

2003-02-24 (bug fix)[637828] Report that entries can provide the selection,
even if they're not displaying it. (hobbs)

2003-02-24 (bug fix)[669595] Improved display of indicators in disabled
checkbuttons and radiobuttons. (hintermayer)

2003-02-24 (bug fix)[632514] Allow listbox 'selection includes' to respond
positively when disabled.

2003-02-24 (bug fix)[647497] Make Tk pick the first best matching font on
the font path. (dal zotto)
	*** POTENTIAL VISUAL INCOMPATIBILITY ***

2003-02-25 (bug fix)[621672] Fixed conversion of apple event parameters
to posix path names. (steffen,riefenstahl)

2003-02-25 (feature enhancement)[patch 685388] Support simple XOR text drawing
on Windows. (martin)

2003-02-28 (bug fix)[612110] Make %-substitutions for events only read data out
of the event structure when that field is valid for that event type. (fellows)
	*** POTENTIAL INCOMPATIBILITY ***

--- Released 8.4.2, March 3, 2003 --- See ChangeLog for details ---

2003-03-14 (bug fix)[701812] Stop buttons from being very wide when a
tk_messageBox has a lot of content on Unix

2003-03-18 (bug fix) Fixed crash in [winfo server] on Mac OS X

2003-04-25 (bug fix)[477740] Correct compound button display in the
disabled state

2003-05-10 (bug fix)[734498] Correct crash when generating postscript for a
single-line polygon (point) with no color.

2003-05-13 (feature enhancement)[736774] Use new versioned bundle resource
API to get tk runtime library for TK_VERSION on Mac OS X

2003-05-14 (bug fix)[737790] Updated French message catalog

2003-05-15 (bug fix)[557030] Use gb2312-raw as the alias for gb2312*
charset fonts.  gb2312.enc was made to be euc-cn for Tcl because that is
what is most often meant, but X really wants the original (-raw) gb2312
encoding.

--- Released 8.4.3, May 20, 2003 --- See ChangeLog for details ---

2003-07-07 (bug fix)[749353] Improve deletion of images on exit.

2003-07-15 (bug fix)[465324] Fixed complex bug in menu clone cleanup.

2003-07-15 (bug fix)[755530] Don't test for XCloseIM bug when the XFree86
version is newer than 4.0 since the layout of the XIM structure has
changed.

2003-07-16 (bug fix)[748277, 702230, 738143] Numerous panedwindow fixes.
Ensure that the last pane shrinks instead of being clipped when resized
below the reqsize.  Ensure that we can share GCs between a panedwindow and
its sash proxy, even if the panedwindow is in a toplevel with a different
visual.  Ensure that panedwindows get their geometry right even when their
children don't know their initial size.  Use widget-specific Priv slots for
pwAfterId and panecursor items to correctly handle cursor changes with
adjacant panedwindows.

2003-07-17 (bug fix)[697652] Make sure all options of a frame can be set to
their default value.

2003-07-17 (bug fix)[404421] Try harder to avoid zero-length mallocs() when
creating images.

2003-07-17 (feature enhancement) MacOSX build system rewrite.

2003-07-18 (bug fix) Do not make XGetGeometry call that prevents overwidth
lines drawing on unix as it requires a roundtrip call to the X server for
every string drawn.  Hard-code max width to 32768 until a beter solution to
get max width is made.

2003-07-18 (bug fix)[742660] correct XCreateIC call for TK_XIM_SPOT usage
on unix.

2003-07-18 (bug fix)[420510] Provide consistency between unix and windows
-cursor option.

2003-07-19 (bug fix)[706765] Correctly handle the -sliderrelief option
while moving the thumb.

--- Released 8.4.4, July 22, 2003 --- See ChangeLog for details ---

2003-08-13 (bug fix)[787065] Fix Button-2 binding for scale widget.

2003-08-19 (bug fix)[791500] Fix panedwindow refresh glitches for bg.

2003-09-17 (bug fix)[808039] Prevent [image create] from generating an
image command name that overwrites an existing command.

2003-09-25 (enhancement) Added -compound support for OS X bevel buttons.

2003-10-10 (bug fix) Fix image offset stippling for disabled buttons.

2003-10-22 (enhancement)[827535] Constrain tk_dialog to be sensibly sized and
placed

2003-10-28 (bug fix) Add 16bpp XGetImage support on Windows

2003-10-29 (enhancement)[795717] Allow some control of foreground and
background colors on Tk's tk_getOpenFile/tk_chooseDirectory.

2003-11-01 (enhancement)[820519] Updated Dutch (nl) message catalog.

2003-11-10 (enhancement)[826614] Provide more Tk build info in tkConfig.sh.

2003-11-10 (enhancement)[809157] Add alpha blending for images with partial
transparency on Windows and Unix on 15bpp+ displays.

2003-11-10 (enhancement)[820282] Use the XGCValues.function parameter when
filling rectangles with XFillRectangles on Windows.

2003-11-11 (enhancement)[840107] Add OS X unicode clipboard support.

2003-11-11 (enhancement)[833819] Improve Tk's
tk_getOpenFile/tk_chooseDirectory directory glob'ing speed.

2003-11-11 (bug fix)[836483] Fix mem leak in '$listbox itemconfigure'.

2003-11-11 (bug fix)[723856] Correctly handle menu (un)posting on menus
with spaces in their names.

2003-11-11 (enhancement) Improve AIX-64 build configuration.

2003-11-17 (bug fix) Fix menubutton -compound state disabled drawing.

--- Released 8.4.5, November 20, 2003 --- See ChangeLog for details ---

2003-12-17 (platform support)[842952] Mac OS X: [scrollbar]

2004-02-13 (platform support)[776646] Win: native hand2/fleur cursors

2004-02-03 (enhancement) post menubuttons so they stay on screen.

2004-02-09 (bug fix)[877950] stop crash during intra-image copy/resize

2004-02-10 (enhancement) New msg catalogs for Esperanto and Polish (trzewik)

2004-02-13 (platform support)[478568] Win: bold/italic font handling

2004-02-15 (platform support)[860454] Mac OS X: [event generate]

2004-02-15 (platform support)[840107] Mac OS X: Unicode clipboard (senn)

2004-02-15 (platform support)[517600] Mac OS X: handle FSRef's

2004-02-15 (platform support) Mac OS X: native [tk_messageBox]

2004-02-15 (platform support) Mac OS X: PowerBook keycode 0x34 -> <Return>

2004-02-18 (platform support) Mac OS MouseWheel event handling

2004-02-18 (bug fix)[899246] fix shrinking grid geometry calculations

2003-02-23 (platform support)[809157] Mac OS X: Add alpha blending for
images with partial transparency.

2004-03-01 (platform support)[218561] Allow 64-bit configure on IRIX64-6.5*

--- Released 8.4.6, March 1, 2004 --- See ChangeLog for details ---

Changes to 8.5a1 include all changes to the 8.4 line through 8.4.6,
plus the following, which focuses on the high-level feature changes
in this changeset (new minor version) rather than bug fixes:

 * Tk is no longer guaranteed to work for Win95 (not tested 8.5+)

 * configure scripts now require autoconf 2.57 for regeneration

 * added support for anti-aliased test under X11 (already existed for
   Win/Mac) using --enable-xft

 * improved speed of 'photo put' handling

 * updated demos for consistency and improved look & feel

 * improve 3D line drawing for sunken widgets on Windows

 * [792387] reworked 'grid' to handle some tricky geometry computations
   better

 * [TIP #109] updated look of radiobuttons and checkbuttons on X11

 * [TIP #110] tristate value option for checkbuttons and radiobuttons

 * [TIP #113] add multi-line searching and -all searching to the text widget
   Full Tcl_Obj-ification of the text widget
 * [TIP #155] add 'count' and 'replace' subcommands and a '-blockcursor'
   option to text widgets and support smooth-scrolling of them
	*** POTENTIAL INCOMPATIBILITY ***
   Negative or decreasing tab-stops are explicitly disallowed

 * [TIP #116] more safety for large image creation through use of attempted
   allocation of large memory blocks

 * [TIP #137/151] add -encoding option to 'wish' executable (through
   Tk_MainEX())
	*** POTENTIAL INCOMPATIBILITY ***
   For Tk embedders that build on Tk_MainEx() and make use of Tk_MainEx's
   former ability to pass a leading "-encoding" option to interactive shell
   operations, this will now be consumed by Tk.

 * [TIP #146] added 'grid anchor' subcommand for overall grid anchoring

 * [TIP #147] recognize widget names and "all" as keywords in grid's
   'columnconfigure' and 'rowconfigure' subcommands

 * [TIP #150] make 'send' available on Windows

--- Released 8.5a1, March 3, 2004 --- See ChangeLog for details ---

2004-03-17 (platform support) Mac OS X: Grab the Command-H &
Command-Shift-H keys and use them for Hide and Hide Others before passing
keystrokes on to the generic keyboard event processing.
Stop putting a Quit menu item in the File menu. (ingham)

2004-03-26 (enhancement)[540375] Add code to read and write PPM/PGM data
from strings and/or bytearrays. (fellows)

2004-03-26 (bug fix)[923555] Restored support for the stringWriteProc of
old photo formats/ (fellows)

2004-03-31 (bug fix)[Bug 220871] Report errors from invoking menu commands
as background errors on OS X. (ingham)

2004-04-20 (bug fix)[915350, 922336] Do not set min, max size in WM_HINTS
when we shouldn't and correctly display maximize window button under
KDE-3.2.1. (english)

2004-05-03 (enhancement)[756952] Place images of compound menu entries in
indicator space if not a radio of checkbutton on Windows. (eserte)

2004-05-03 (bug fix)[904371] Fix drawing of unicode chars in menu titles.
(riefenstahl)

2004-05-03 (bug fix)[939389, 822002, 732662] Correctly post internal
clipboard data to the Windows clipboard on exit. (hobbs)

2004-05-03 (bug fix)[778893, 932155] Make the panedwindow -opaqueresize
option work as per the docs, and call DragSash to stop sash jump when B1 is
pressed and released without moving. (hobbs)

2004-05-05 (bug fix)[618872] Fix Tk_MeasureChars and Tk_DrawChars to handle
reallocation of subfonts when unicode chars require extra fonts.
(dkf, hobbs)

2004-05-14 (enhancement) reduce Tk tk_messageBox default font size to
14-point (was 18-point). (fellows)

2004-07-11 (enhancement)[987169] Handle users destroying the dialog
indirectly. (fellows)

2004-07-14 (bug fix)[894550] Correctly set the cursor to the platform
cursor on OS X when Tk asks for the "NULL" (empty) cursor.

2004-07-14 (bug fix)[969358] Prevent possible segfault in -maxundo. (jiangwu)

2004-07-19 (bug fix)[874058] improved build configuration on 64-bit systems.
Corrects Tcl_StatBuf definition issues.  (hobbs)

2004-07-23 (platform support) Mac OS X: Fix several problems with
Icelandic (and Faroese) keyboards (riefenstahl)

2004-07-24 (platform support) Mac OS X: Complete the implementation of
the CG version of the X drawing emulation layer. (tittle, ingham)

--- Released 8.4.7, July 26, 2004 --- See ChangeLog for details ---

2004-08-09 (bug fix)[1006286] test wrapping on canvas; Win (dejong)

2004-08-10 (bug fix)[1006686] [wm resizable] Solaris (mcdonald,english)

2004-08-17 (bug fix)[1010938] panedwindow -handlepad GEOMETRY (fellows)

2004-08-19 (bug fix)[611615] file dialog double clicks fell through (hobbs)

2004-09-10 (bug fix)[845189] file dialog state initialization (fellows)

2004-09-10 (bug fix)[1013942] widget demo robust against strict motif (fellows)

2004-09-16 (bug fix)[1028888] [place forget] memory leak (spjuth)

2004-09-16 (bug fix)[607649] font size change: recompute menu geometry (hobbs)

2004-09-17 (new feature)[TIP 222] [wm attributes -alpha] (hobbs)

2004-09-22 (bug fix)[865842] disabled cascade menu arrow draw (dejong)

2004-09-22 (bug fix)[866194] menu accelerator text highlights (dejong)

2004-09-22 (bug fix)[223689] handle color/screen resolution changes (hobbs)

2004-10-05 (new feature)[TIP 159] [wm iconphoto] (hobbs)

2004-10-26 (bug fix)[905830] set IC focus after creation (max)

2004-10-26 (bug fix) shutdown safety corrections for Win (gravereaux)

2004-10-28 (bug fix) HAVE_NO_SEH handler code, Win (dejong)

2004-10-29 (bug fix)[533519] multi-display window placement (thoyts)

2004-11-10 (bug fix)[1055023] compound buttons, MacOSX (kirkham,ingham)

2004-11-11 (bug fix)[1035348] [load]-able Tk on MacOSX/Aqua (steffen)

2004-11-12 (bug fix)[800178] use correct display for [tk scaling] (hobbs)

2004-11-16 (bug fix)[1063675] Italian msg catalog fixes (ugoccioni,welton)

2004-11-17 (bug fix)[1036963] panedwindow: set save_under X attr (hobbs)

2004-11-17 (bug fix)[1004508] console: array keyname expansion (bold,hobbs)

2004-11-17 (bug fix)[1032300] ps generation of unspecified canvas image (hobbs)

2004-11-17 (bug fix)[982248] immediate unmap of hidden canvas windows (hobbs)

2004-11-18 (new feature) configure options --enable-man-suffix (max)

--- Released 8.4.8, November 18, 2004 --- See ChangeLog for details ---

2004-12-01 (bug fix)[979239] Fix clipping of partially transparent images
on buttons on unix to avoid X error (hobbs, petasis)

2004-12-03 (bug fix)[848161] Fix Tk_PhotoPut(Zoomed)Block overlay
compositing of partially transparent areas.

--- Released 8.4.9, December 6, 2004 --- See ChangeLog for details ---

Changes to 8.5a2 include all changes to the 8.4 line through 8.4.9, plus
the following, which focuses on the 8.5-only changes since 8.5a1:

2004-03-16 (bug fix)[915330] correct crash condition for new
radio/checkbuttons when colors are exhausted (griffin)

2004-03-18 (platform removal)[918139] Removed support for Mac OS Classic
platform (steffen)
	*** POTENTIAL INCOMPATIBILITY ***

2004-03-26 (new feature)[FRQ 540375] support for
[image create photo -format PPM -data] (fellows)

2004-05-14 (bug fix)[TIP 152] -detail option for tk_messageBox (fellows)

2004-06-04 (bug fix)[965398] Fix to shimmering infinite loop scrolling in
text widget under rare circumstances (darley)

2004-06-04 (bug fix) Fixed mousewheel bindings for OS X/Aqua (darley)

2004-06-07 (bug fix)[965186] Fix text widget's record of
partial-line-height calculations for very long wrapped lines, correcting
scrollbar-text interactions (darley)

2004-06-08 (bug fix)[968725] Fix text rendering problem with canvas text
items that have a selected region. (dejong)

2004-06-09 (bug fix) Fix multi-line regexp search bugs in text widget
(darley)

2004-06-15 (feature enhancement) Add 3D highlight to disabled *buttons and
labels, as is done for disabled menu entries (kovalenko)

2004-06-16 (bug fix)[742882] Fix potential division by zero in gridded wm
geometry (english)

2004-06-26 (bug fix)[756840] Fix Tk console cleanup on exit/reinit
(mistachkin)

2004-06-30 (new feature)[TIP 153] enhanced 'winfo toplevel' to recognize
non-Tk windows (mckay)

2004-07-02 (bug fix) Button 4 and 5 masks synchronized with Tk display
(staplin)

2004-07-05 (bug fix)[959973] Set _NET_WM_NAME and _NET_WM_ICON_NAME
(freedesktop.org) in addition to WM_NAME and WM_ICON_NAME (ICCCM).  Allows
Unicode characters in wm titlebar on X11. (english)

2004-07-05 (new feature)[TIP 158][797404] Allow Win apps to distinguish
keys on the keypad using the Extended modifier (grossbauer, kenny)

2004-07-20 (feature enhancement)[922727] add install-private-headers target
(steffen)

2004-07-27 (bug fix) Fix segfault in case of premature end of GIF image
data (steffen)

2004-08-11 (feature)[979101] [tk_getOpenFile] consults env vars (fellows)

2004-08-19 (new feature)[TIP 168] Add -smooth method for alternative bezier
curve implementations on canvas items (hellstroem, fellows)

2004-08-29 (new feature)[TIP 165] Add %d binding substitution for
user-controlled data field (fellows)

2004-09-10 (new feature)[TIP 169] Allow for text peering with '$text peer'
widget subcommand (griffin, darley)

2004-10-08 (new feature)[TIP 205] Use pkgconfig Database to register Xft
support (english)

2004-10-11 (new language) Swedish message catalog from Mats Bengtsson

2004-10-19 (new feature)[TIP 204][976928] Virtual events for keyboard
traversal (english)

2004-10-24 (new feature)[TIP 177, 179][983886] Add -hide and -stretch
options to panedwindow widget (griffin)

2004-10-26 (bug fix)[919066] Improve region handling functions

2004-10-28 (bug fix)[220927] Fix scale labels to stay in window (schlenker,
thoyts)

2004-11-07 (bug fix)[962589] Made handling of ^ more consistent in grid
(spjuth)

2004-11-28 (bug fix)[942320] Fix short integer overflow in x,y coordinates
for long lines using unix AA fonts (english)

Updated test suite, documentation, and demos.

--- Released 8.5a2, December 7, 2004 --- See ChangeLog for details ---

2004-12-09 (performance)[1081966] BMP, JPG image load speed (fellows)

2004-12-17 (feature change) Modified DisplayFrame to draw a container's
background when the embedded window is NULL (chengyemao)

2004-12-17 (bug fix)[842945][831627] Fixed a bug in ContainerEventProc
to handle ConfigureNotify event properly; Changed CleanupContainList to
TkWinCleanupContainerList to be invoked in TkWinXCleanup; Changed Intialize
and CreateTopLevelWindow to create the DeleteWindowsExitProc after TkpInit
so that finalization will be done in a proper sequence (to avoid painics
and potential crashes in exit). (chengyemao)

2004-12-17 (platform support) Added TkWinClenupContainerList into stublib.
(chengyemao)

2004-12-18 (buf fix)[222677] Close the embedded window (of a different
process) when its container is destroyed. (chengyemao)

2004-12-19 (Windows feature implementation of embedded/embedding
Tk and bug fix) Implemented container identification, focus, raise, set
title of and move window so that an embedded widget is able to identify
a container, to get focus and to receive key press input. Fixed bugs include
[1024364][1096047] and an incorrect wm overrideredirect for an embedded
window. (chengyemao)

2004-12-20 (Windows feature implementation of embedded/embedding Tk)
Implemented overrideredirect for an embedded toplevel; correctly updated a
frame's upper left x and y of an embedded toplevel after its container
(of another process) moved. (chengyemao)

2004-12-28 (feature implementatoin of embedded/embedding Tk of Windows)
Implemented embedded/embedding toplevel menu. A menu may be embedded in
a container of either the same process or a different process. Working
fine with Windows 98. But having a problem when invoked with a mouse click
(Windows XP): if an embedded menu is in a different process, the menu items
may show as a blank window at the pull-down time and require the mouse
moves over the menu items to complete display. (chengyemao)

2004-12-29 (platform support)[1092952,1091967] MSVC7, gcc OPT compiles (hobbs)

2005-01-03 (feature implementation of embedded/embedding Tk of Windows) Added
a separated window handler for an embedded menu; solved the problem of
a blank menu display with a mouse click in XP. (chengyemao)

2005-01-07 (feature implementation of embedded/embedding Tk of Window) Added
TK_STATE message (Windows) to support {wm state} for embedded windows; forced
redraw of container after the embedded window detached; removed unnecessary
panic in using embedded window; embeded toplevel menu of an embedded window
automatically in wrapper updating.  Modified and added functions: WmStateCmd,
UpdateWrapper, TkpWmGetState (added) in tkWinWm.c; TkpUseWindow,
TkWinEmbeddedEventProc in tkWinEmbed.c; TkWinChildProc in tkWinX.c.
(chengyemao)

2005-01-08 (bug fix)[1098625] Wrong toplevel geometry when created with a menu;
[637653] Deleting a popup menu crashes wish (chengyemao)

2005-01-09 (feature implementation of embedded/embedding Tk of Windows)
Changed FrameWidgetObjCmd (tkFrame.c), TkpUseWindow (tkMacOSXEmbed.c,
tkUnixEmbed.c, tkWinEmbed.c) to make implementation ready for a
configurable toplevel -use option and completed the implementation for
Windows (tkWinWm.c, tkWinEmbed.c, tkWinInt.h). Embedding with a frame
container needs further debugging (chengyemao).

2005-01-10 (enhancement)[1081595] stopped use of TK_DBGX (english)

2005-01-11 (bug fix)[1098779] -pady accept all lists (fellows,kirkham)

2005-01-11 (bug fix)[1093631] [text] scroll long wrapped line (darley)

2005-01-18 (feature implementation of embedded/embedding Tk of Windows)
Simplified TkpUseWindow, added Tk_DetachEmbeddedWindow and got rid of code
for saving an embedded window object which is never used. Fixed a bug in
TkWinHandleMenuEvent for processing WM_MENUSELECT. Wish crashed due to an
invalid index in a case of MF_POPUP. The -use option of a toplevel can be
configured after the toplevel is created.

2005-01-18 (bug fix) dialog visibility in demos (nash,fellows)

2005-01-28 (platform support)[1021871] Solaris gcc 64-bit support (hobbs)

2005-01-31 (enhancement)[1111213] msg catalog for Spain's Spanish. (poser)

2005-02-03 (bug fix)[1114977] UID thread-safety in canvas (fellows)

2005-02-11 (bug fix)[949792] Fix error during panedwindow destroy (hobbs)

2005-02-11 (bug fix)[1105738] Fix [tk_messageBox -parent $nonToplevel]
segfault (hobbs)

2005-02-11 (bug fix)[1119460] Disabled canvas bmap/bbox segfault (hobbs)

2005-02-11 (platform support) Correct gcc builds for AIX-4+, HP-UX-11 (hobbs)

2005-02-14 (bug fix)[443848] [text] elide newline, but not line (darley)

2005-02-16 (new feature)[TIP 223] Windows: [wm attributes -fullscreen] (dejong)

2005-02-22 (bug fix)[1146057] Aqua: [tk_getOpenFile] encoding (steffen)

2005-02-28 (bug fix)[1118340] Fix Mousewheel %A translation (davis,hobbs)

2005-03-09 (bug fix) Mac OS X: remote debugging under Xcode (ingham)

2005-03-10 (bug fix)[1160025] Aqua: offset in mouse coords (davies,ingham)

2005-03-10 (bug fix)[1124237] Aqua: floating window focus (davies,ingham)

2005-03-14 (bug fix)[1162356] ClientMessageHandlers work now (petasis,fellows)

2005-03-14 (bug fix)[1124237] Aqua: (un)map of subwindows (ingham)

2005-03-14 (bug fix)[700305] Aqua: child window updates before creation
(ingham)

2005-03-15 (platform support) OpenBSD ports patch (thoyts)

2005-03-15 (bug fix)[1143776] [text] display panic (revar,darley)

2005-03-19 (bug fix)[1016385] allow [rename console] (fellows)

2005-03-23 (enhancment) Aqua: native L&F for entry and spinbox (ingham)

2005-03-23 (new feature) Aqua: [wm attributes -notify] (ingham)

2005-03-29 (platform support) Allow msys builds without cygwin (hobbs)

2005-04-03 (bug fix)[1175092] grid geometry calculations (spjuth)

2005-04-04 (bug fix)[1174269] [text] elide search (darley)

2005-04-04 (bug fix)[1169429] [text] invisible cursor (darley)

2005-04-04 (bug fix)[1083878] \0 char in [tk_getOpenFile -filetypes] (darley)

2005-04-07 (bug fix)[1152809] [wm stackorder] panic; multi-DISPLAY (dejong)

2005-04-14 (bug fix)[1122671] font encoding alignment issue (brubaker,hobbs)

2005-04-18 (bug fix) [text] <Home> and <End> bindings (darley)

2005-04-18 (bug fix)[1185640] [text] passed bogus utf-8 to Tk_MeasureChars
(petasis,english)

2005-04-25 (platform support) Fix builds on Mac OS X 10.1 (steffen)

2005-05-06 (platform support) Added x86_64 Solaris cc and Solaris 10 build
support (hobbs)

2005-05-10 (bug fix)[1191895] [text] hang on <Control-Key-Up> (vlasov,darley)

2005-05-14 (enhancement)[1202052] Aqua: CFRunLoop notifier allows
[load]able Tk (steffen)

2005-05-15 (bug fix)[1012852] Aqua: check/radiobutton accelerator (kirkham)

2005-05-15 (bug fix)[1202181] Aqua: scrollbar thumb position (kirkham)

2005-05-15 (bug fix)[1202223] Aqua: [text] window -> scroll lock (kirkham)

2005-05-22 (bug fix)[1206133] TkGetFileFilters: add all (dionizio,fellows)

2005-05-24 (platform support) Darwin/Aqua builds merged into unix (steffen)

2005-05-27 (behavior change) tk_popup menus now "sticky" (helfter)

2005-05-28 (new feature)[TIP 245] [tk inactive] (max,fellows)

2005-05-30 (bug fix)[1161543,1010941,795869,690169] panedwindow
display/resizing (south)

2005-05-30 (bug fix)[1159367] [menu] creation segfault (schofield,hobbs)

Documentation improvements [1087842,1081527,1115907,etc.]

--- Released 8.5a3, June 4, 2005 --- See ChangeLog for details ---

2005-06-23 (bug fix)[1176610] Aqua: default [entry] borderwidth (steffen)

2005-07-18 (bug fix)[1240221] [$text mark prev] crash (darley)

2005-07-22 (platform support) msys build now requires msys_mingw7.zip (dejong)

2005-08-09 (Aqua enhancement) Carbon events (steffen)

2005-08-10 (bug fix)[1252702] portable Tcl_GetStringFromObj() calls (fellows)

2005-08-12 (bug fix)[749908] per-thread Tk_ConfigSpec tables (fellows)

2005-08-23 (enhancement)[1244153] use SC_PROG_TCLSH, SC_BUILD_TCLSH (dejong)

2005-08-23 (bug fix)[1235544] adopt Tcl's SEH implementation (kenny,dejong)

2005-08-23 (Aqua bug fix) dialogs ignore -initial* options (hobbs)

2005-10-04 (bug fix)[1216775] [tk_dialog] failing [grab] (fontana,hobbs)

2005-10-04 (bug fix)[1309218] [tk_chooseDirectory -mustexist] (lemburg,hobbs)

2005-10-04 (bug fix)[1311734] Fixed the problems that an embedded windows failed
to respond to display changes (Windows platform) (chengyemao)

2005-10-10 (new feature)[TIP 256] [$text config -tabstyle] (darley)

2005-10-10 (bug fix)[1319720] Tk_DeleteOptionTable() mem leak (melbardis)

2005-10-12 (new feature) one directory test suite (starpackable) (zolli,fellows)

2005-10-18 (bug fix)[1328926] $argv encoding and list formatting (porter)

2005-11-06 (platform support) OpenBSD missing LIBS (thoyts)

2005-11-10 (bug fix)[1353022] minor potential memleaks (fellows)

2005-11-22 (bug fix)[1353414] [selection get] compat w/OpenOffice.org (fellows)

2005-11-14 (feature change) [bgerror] msg truncation at 45 chars (english)

2005-11-15 (new feature)[TIP 231] [wm attributes] on X11 (english)

2005-11-22 (bug fix)[1335485] dialog and space in widget name (taylor,fellows)

2005-11-27 (platform support) Darwin 64bit, Tiger copyfile(), and
Max OSX universal binaries support (steffen)

2005-11-29 (bug fix)[1252259] clear initial % from console (lawlor,hobbs)

2005-11-30 (bug fix)[1086049] [wm attributes -topmost] fix (courtney,hobbs)

2005-12-08 (enhancement)[1369597] Win 64: --enable-64bit=amd64|ia64 (hobbs)

2005-12-08 (bug fix)[1374935] [$text tag names] crash with peer (hobbs)

2005-12-12 (bug fix)[1377619] configure syntax error exposed in bash-3.1 (hobbs)

2005-12-13 (Aqua) MouseWheel bindings; kEventMouseScroll events (steffen)

2005-12-28 (bug fix)[1380427] text widget undo/redo crash (callewaert)

2006-01-12 (new feature)[TIP 260] canvas text item -underline option (fellows)

2006-01-20 (bug fix)[905830] all events to XFilterEvent (SCIM compat) (english)

2006-01-25 (feature enhance)[1237759] update script lib to 8.4 (fradin,porter)

2006-01-25 (feature enhance)[1409264] I10N of [bgerror] dialog (fellows)

2006-02-27 (bug fix)[480862] [$img configure -data] no display change (fellows)

2006-02-27 (bug fix)[470322] BitmapInit() thread safety (griffin,fellows)

2006-03-02 (Aqua bug fix) image endian issue on OS X/x86 (hobbs)

2006-03-15 (bug fix)[1409140] speed up photo image updates (fellows)

2006-03-16 (enhancement)[1405069] added Portuguese l10n. (ricardoj,silasj)

2006-03-17 (bug fix)[1451587] no abbreviations in script library (thoyts)

2006-03-21 (enhancement)[638966] Aqua: ATSUI text render (reifenstahl,steffen)

2006-03-23 (platform support) new tk.spec file (max)

2006-03-26 (bug fix)[1414171] crash in [$text dump -command] (macdonald,darley)

2006-03-27 (bug fix)[1458234] crash in animated GIFs (bron,fellows)

2006-03-29 (platform support)[917433] tolerate X servers that do not
accept the color names "Black" and "White" (porter)

2006-04-06 (bug fix)[1455241] Aqua: [wm attributes -titlepath] fix (steffen)

2006-04-07 (bug fix)[934524]  Aqua: background window dragging/growing (steffen)

2006-04-09 (bug fix)[1467004] Aqua: [wm resizable] fix (steffen)

2006-04-09 (bug fix)[1450800] Aqua: allow empty toplevel names (steffen)

2006-04-11 (bug fix)[1073456] Aqua: implement toplevel zoom (steffen)

2006-04-11 (bug fix)[700316]  Aqua: enable 'Preferences' app menu item (steffen)

2006-04-11 (bug fix)[1193614] Aqua: tk_messageBox escape key binding (steffen)

2006-04-11 (enhancement)[1105284] Aqua: call ::tk::mac::* procs for all
registered applevents (steffen)

2006-04-12 (bug fix)[1432666] grid row/col out of bounds crash (spjuth)

2006-04-25 (bug fix)[1475865] crash on invalid font name (fellows)

Documentation improvements [1224983,1247835,1151523,1357575,1083838]

--- Released 8.5a4, April 27, 2006 --- See ChangeLog for details ---

2006-04-28 (bug fix)[1243318] Aqua: incorrect cursor pos in bindings (steffen)

2006-04-28 (bug fix)[1476443] Aqua: incorrect toplevel pos on 1st map (steffen)

2006-05-12 (performance)[1409140] restore perf lost in 2006-03-15 change (hobbs)

2006-05-13 (bug fix)[1481503] Aqua: key shortcut for 'Preferences' (steffen)

2006-05-13 (bug fix)[1155596] Aqua: images with alpha on native btns (steffen)

2006-05-13 (bug fix)[1480105] Aqua: Map/Unmap propagation to children (steffen)

2006-05-13 (bug fix)[940117] Unmap canvas window items on canvas Unmap (steffen)

2006-05-16 (bug fix)[1472624] Aqua: balloon help don't steal focus (steffen)

2006-05-29 (bug fix)[706446] Aqua: active [button] highlight (hobbs)

2006-05-29 (bug fix)[1424513] [listbox] crash with namespace var (hobbs)

2006-06-01 (bug fix)[912571] [console] std chan refcount (mistachkin,hobbs)

2006-06-14 (bug fix)[950121] Aqua: crash in draw of very wide images (steffen)

2006-06-14 (bug fix)[1501922] Aqua: invalid clip regions on redraw (steffen)

2006-06-14 (bug fix)[891141] excess variable writes by [scale] (porter)

2006-07-20 (platform support) Mac OS X weak linking (steffen)

2006-07-21 (bug fix)[700311, 1525905] Aqua: pure modifier keysyms (steffen)

2006-07-24 (bug fix)[1358663] Aqua: [wm geometry -x-y] (steffen)

2006-07-25 (bug fix)[1516950] Aqua: cmd-Q app menu key shortcut (steffen)

2006-08-18 (bug fix)[1542205] Aqua: toplevel toolbar button crash (steffen)

2006-08-21 (bug fix) Aqua: recursively called event loop (steffen)

2006-08-24 (bug fix) Aqua: window grow icon obscuring scrollbar (steffen)

2006-08-30 (new feature)[1518677] WM_UNICHAR window message (hobbs,petasis)

2006-09-10 (bug fix) Aqua: active/inactive text selection color&relief (steffen)

2006-09-10 (bug fix)[1472624] Aqua: mouse events in overrideredir wins (steffen)

2006-09-11 (bug fix) Aqua: app menu shortcuts with custom .apple menu (steffen)

2006-09-22 (bug fix)[1562528] NULL terminates variadic calls (fellows,ryazanov)

2006-09-22 (new feature)[TIP 268] [package provide] full patchlevel (kupries)

2006-10-05 (bug fix)[1122671] alignment fixes in ucs-2be encoding routines
(hobbs,staplin)

2006-10-08 (new feature)[TIP 264] New public routine Tk_Interp() (thoyts)

2006-10-16 (bug fix)[1558051] Aqua: CG drawing matches X11 (steffen)

--- Released 8.5a5, October 20, 2006 --- See ChangeLog for details ---

2006-10-30 (new feature)[TIP 48] Addition of themed tk widgets to Tk as Ttk
(themed Tk).  Adds ttk::notebook, ttk::sizegrip, ttk::combobox,
ttk::panedwindow, ttk::progressbar, ttk::menubutton, ttk::button,
ttk::radiobutton, ttk::checkbutton, ttk::treeview, ttk::separator,
ttk::scrollbar, ttk::entry, ttk::frame and ttk::labelframe widgets.  Adds
ttk::style command.

2006-11-02 (enhancement) Improve OS X Carbon Update event handling (steffen)

2006-11-07 (configure change) Unix --enable-xft is enabled by default (kenny)

2006-11-23 (bug fix)[1599877] Fix unicode character underline in menus (hobbs)

2006-11-24 (bug fix)[1487701] Better handling of tcl_interactive on OS X to
control display of console (hobbs, steffen)

2006-11-26 (platform support)[1230558] --enable-64bit on more systems (steffen)

2006-11-30 (bug fix) Fix handling of Escape binding on OS X dialogs (steffen)

2006-12-01 (new feature) Add -transparentcolor wm attribute on Windows (hobbs)

2006-12-01 (new feature)[TIP 300] Added [font actual $font $char] (kenny)

2006-12-04 (new feature)[TIP 286] Added [$menu xposition] subcommand (bron)

2006-12-11 (enhancement) Improved EWMH support for _NET_WM_PID and
_NET_WM_PING (fellows)

2007-01-25 (configure change) ensure CPPFLAGS env var used when set (steffen)

2007-02-19 (configure change) Use SHLIB_SUFFIX=".so" on HP-UX IA64 (was
".sl") (hobbs)

2007-04-10 (platform support) Correctly handle theming on Vista/Aero (english)

2007-04-23 (enhancement) Allow empty value for -selectforeground opt (steffen)

2007-04-23 (platform support) Aqua: remove Tk-internal double buffering that is
wasteful on Aqua; allows direct-to-window CoreGraphics drawing (e.g. adding
support for colors with alpha) (steffen)

2007-04-23 (platform support) Aqua: add all OS theme colors/brushes (patterns)
as system colors (steffen)

2007-04-23 (platform support) Aqua: tk_dialog & bgerror use OS theme (steffen)

2007-04-23 (platform support) Aqua: add 'none' & missing theme cursors (steffen)

2007-04-23 (platform support) Aqua: [tk_getOpenFile -parent] et al use sheet
dialog (steffen)

2007-04-23 (bug fix) Aqua: fix custom MDEF and tearoff menu display (steffen)

2007-04-23 (bug fix)[1620826] Aqua: fix <<MenuSelect>> support (steffen)

2007-04-23 (platform support) Aqua: add support for live window resizing and
asynchronous window dragging; prevent window from becoming inacessible
offscreen or under Dock after dragging; use transparent grow box (steffen)

2007-04-23 (platform support) Aqua: improve event processing during nested
event loops (e.g. modal dialogs, menu tracking, window resizing etc) (steffen)

2007-04-23 (bug fix) Aqua: add support for all possible aqua scrollbar arrow
positions, scrollbar variants and for "jump to here" scrollbar behaviour;
correct scroll view size computation; enforce minimal scrollbar height (steffen)

2007-04-23 (platform support) Aqua: add [wm attributes] -topmost, -fullscreen
and -transparent (fully transparent win via -bg "systemTransparent") (steffen)

2007-04-23 (platform support) Aqua: determine win min/max sizes dynamically;
correct size handling of gridded windows; improve computation of initial
window bounds; correct window size handling on multi-headed systems (steffen)

2007-04-23 (platform support) Aqua: correct composite attribute handling in
[tk::unsupported::MacWindowStyle] and add new attributes; allow changing
window class of already existing windows (steffen)

2007-04-23 (platform support) Aqua: add tcl document extensions and mime type
to Wish.app's Info.plist (steffen)

--- Released 8.5a6, April 25, 2007 --- See ChangeLog for details ---

2007-05-04 (new feature)[TIP 145] Enhanced font handling (thoyts)

2007-05-14 (bug fix)[1712081] restored USE_OLD_IMAGE support (porter)

2007-05-15 (bug fix)[1717830,800149] memory leaks (jenglish)

2007-05-15 (bug fix)[1677608] [grid *configure] crash (porter)

2007-05-31 (platform support) Aqua: improve interaction of Expose events and
idle-time redraws (steffen)

2007-05-31 (bug fix) Aqua: gridded window max-size calculation (steffen)

2007-06-02 (bug fix)[1731734] Aqua: menu cascades outside menubar (steffen)

2007-06-06 (platform support) Aqua: enable MouseWheel events in background
windows (steffen)

2007-06-09 (bug fix)[1724223] Unicode menu entry crash (hobbs)

2007-06-09 (bug fix)[1467997] Blue/red reversal in icons (hobbs,janssen)

2007-06-23 (bug fix) Aqua: nav dialog sheet crash (steffen)

2007-06-29 (platform support) Aqua: remove private internal declarations from
installed tkMacOSXInt.h header (steffen)

2007-06-29 (bug fix) Aqua: scrollbar thumb size calculation (steffen)

2007-07-09 (bug fix) Aqua: app-is-frontmost detection (steffen)

2007-07-09 (bug fix) Aqua: window click activation & titlebar click handling
in presence of grabs or modal windows (steffen)

2007-07-25 (bug fix)[1743786] Aqua: [tk_getOpenFile] result (steffen)

2007-08-01 (bug fix)[1692927] [tk_messageBox -detail] buffer (davies,thoyts)

2007-08-27 (bug fix)[1782105] Aqua: tk_chooseColor result (steffen)

2007-09-06 (platform support) Aqua: drop support for Xcode 1.5 project, add
project for Xcode 3.0 (steffen)

2007-09-11 (bug fix) Animated GIF buffer overrun (max)

2007-09-15 (platform support) SunOS-5.1x link with cc, not ld (steffen)

2007-09-17 (enhancement)[1780286] Aqua: combobox appearance (english)

2007-09-17 (platform support)[1748251] Fix NetBSD link failures (english)

2007-09-20 (bug fix)[1791052] [text] DLine layout crash (khomoutov,fellows)

--- Released 8.5b1, September 26, 2007 --- See ChangeLog for details ---

2007-09-26 (enhancement)[1800742] msg catalog for Hungarian. (reszo)

2007-10-11 (bug fix)[1810818] Aqua: [wm resizeable] (steffen)

2007-10-12 (platform support) Aqua: replace RgnHandles by HIShapeRefs (steffen)
	*** POTENTIAL INCOMPATIBILITY for C code acessing MacDrawable Rgns ***

2007-10-15 (platform support) Mac OS X: 64-bit X11 support (steffen)

2007-10-15 (new feature)[TIP 125][998125] dockable frame support (hobbs)

2007-10-22 (bug fix)[1814778,1780286,1609168,1349586] combobox overhaul(english)

2007-10-22 (platform support) Aqua: TIP 145 and Aqua Theme fonts (steffen)

2007-10-23 (bug fix)[1818441] combobox & reparentable frames (hobbs)

2007-10-24 (bug fix)[1723362] Win: transparent bitmaps (mcdonald,thoyts)

2007-10-25 (bug fix)[1818491] crash in [place] manager (mcdonald)

2007-10-25 (new feature)[TIP 242][1156388] file dialog filter (hobbs)

2007-10-25 (bug fix)[1817596] ttk::notebook (english)

2007-10-26 (bug fix)[1816252] Aqua: [wm transient] (steffen)

Improvements to demo suite to make more use of Tk 8.5 features (fellows,steffen)

--- Released 8.5b2, October 26, 2007 --- See ChangeLog for details ---

2007-10-29 (appearance change) Default look and fonts on X11 (hobbs)
	*** POTENTIAL INCOMPATIBILITY; [::tk::classic::restore] to undo ***

2007-10-30 (bug fix)[1803723] Win: Arabic and Hebrew rendering (fellows)

2007-10-30 (bug fix)[1550528] [tk_chooseDirectory -mustexist true] disables
the "OK" until valid selection (hobbs)

2007-11-03 (new feature) adjustable [console] fonts (thoyts)

2007-11-04 (enhancement) Aqua: "Run Widget Demo" menu item (steffen)

2007-11-09 (bug fix) Aqua: activate event after window expansion (steffen)

2007-11-09 (bug fix)[1824521] Aqua: menubutton crash with -bitmap (steffen)

2007-11-09 (platform support) Aqua: (menu)button pressed/inactive/disabled
look&feel; menubutton size with -image/-bitmap (steffen)

2007-11-09 (bug fix) Aqua: [tk_getOpenFile] (et al.) and help menu crashes on
Mac OS X Leopard (steffen)

2007-11-11 (bug fix)[1824638] Aqua: small max-width text measuring (riefenstahl)

2007-11-14 (bug fix)[1831803] sv.msg catalog for "sv" locale (fellows)

Many significant improvements to the documentation and demos (fellows, hobbs,
steffen, kupries)

--- Released 8.5b3, Novemeber 19, 2007 --- See ChangeLog for details ---

2007-11-25 (bug fix)[1343984] ttk::notebook bugs (english,boudaillier)

2007-11-26 (bug fix)[1822391] [photo put] segfault w/ PPM data (kenny)

2007-11-26 (bug fix)[1822076] [tk_saveFile] and path w/spaces (bauer,kenny)

2007-12-04 (new feature)[1844143] Danish message catalog (berg)

2007-12-11 (bug fix)[1602537] crash in [$text replace] (goth,porter,fellows)

2007-12-12 (bug fix)[1845899] Aqua: [wm transient] (steffen)

2007-12-12 (bug fix)[1809538,1799782,1737288] fixes for the <<Modified>>
virtual event on [text] widgets (hobbs)

2007-12-13 (bug fix) correctly trace menubutton -textvariable for -compound
use (hobbs)

Several documentation and release notes improvements

--- Released 8.5.0, December 18, 2007 --- See ChangeLog for details ---

2007-12-30 (bug fix)[1860802] fixed Dutch message catalog (markus,fellows)

2008-01-06 (bug fix)[1442006,1821939,18862692] MouseWheel for treeview (english)

2008-01-08 (bug fix)[1865898,1679067] button size & state (english)

2008-01-08 (bug fix)[1867122] [labelframe -style] crash (english,rib)

2008-01-27 (bug fix)[1835848] size value returned by [font actual] (english)

2008-01-27 (bug fix)[1878298] [notebook] redraws on tab visibility (english)

2008-01-31 (bug fix)[1881892] messagebox default title (hobbs)

2008-02-01 (bug fix)[CVE-2008-0553] buffer overflow in GIF format (max)

--- Released 8.5.1, February 5, 2008 --- See ChangeLog for details ---

2008-02-27 (bug fix)[1863346] Aqua: memleak in QD drawing (steffen)

2008-02-29 (enhancement) Knight's tour demo (thoyts)

2008-03-12 (bug fix)[1090382] crash when GetFont() fails (jenglish)

2008-03-13 (enhancement) support space in INSTALL_ROOT or $builddir (steffen)

2008-03-21 (bug fix)[1863007,1920030] Export Ttk stubs table (english)

2008-03-26 (bug fix)[1922466] crash  in [. configure -cursor] (gavilán)

2008-03-27 (platform support)[1921166] Solaris 64bit build fixes (steffen)

2008-03-27 (bug fix) restored [::safe::loadTk] (hobbs)

--- Released 8.5.2, March 28, 2008 --- See ChangeLog for details ---

2008-04-01 (interface)[1819422] tkStubsPtr no longer in libtk (porter)
	*** POTENTIAL INCOMPATIBILITY ***

2008-04-02 (interface)[1819422] libtkstub symbols MODULE_SCOPE (steffen)

2008-04-07 (bug fix)[1937135] Tk_ParseArgv() double free crash (hobbs)

2008-04-07 (bug fix)[1936238] wish -h mem explosion (bachmann,kenny)

2008-04-08 (new feature) Win: visual-styles API element engine (thoyts)

2008-04-09 (enhancement) real LZW compression in GIF writer (nijtmans)

2008-04-14 (bug fix)[1941740] [tk_chooseColor -title] (thoyts)

2008-04-16 (interface)[1938497] make stubs tables 'static const' (steffen)

2008-04-17 (bug fix)[1327482] canvas item <Enter> events (wangnick)

2008-05-23 (bug fix)[1967576] ttk::label height or width 0 panic (lawlor)

2008-06-10 (enhancement)[1986818] Use Xutf8LookupString when possible (english)

2008-06-12 (bug fix)[1991932] global grab segfault (steffen)

2008-06-12 (platform support) Solaris/amd64 gcc 64bit support (steffen)

2008-06-13 (new feature)[TIP 285] [tkwait] and [update] are now
[interp cancel]able (mistachkin)

2008-06-18 (bug fix) Aqua: missing focus on first map (steffen)

--- Released 8.6a1, June 25, 2008 --- See ChangeLog for details ---

2008-07-04 (bug fix)[2009213] crash in [ttk::scale] (polo,english)

2008-07-24 (bug fix)[2021443] consistent "wrong # args" messages (nijtmans)

2008-07-26 (bug fix)[2026405] portability of [winfo id] (uchida,thoyts)

2008-07-31 (bug fix) export Tk_PkgInitStubsCheck; fixes Tk embed on Windows

2008-08-01 (bug fix)[2009788,2028703] unmapped toplevel crashes (thoyts)

2008-08-05 (bug fix)[2010422] Tk header files revised to accommodate
incompatible changes in recent X.org releases of X11 headers. (jenglish)

2008-08-19 (bug fix) revised number format in -[xy]scrollcommand callbacks
and [xy]view methods (jenglish)
        *** POTENTIAL INCOMPATIBILITY ***

2008-08-19 (enhancement) removed obsolete XID management code (staplin)

Test suite modernization by Ania Pawelczyk.

--- Released 8.6a2, August 25, 2008 --- See ChangeLog for details ---

2008-08-25 (bug fix)[1936220] fix [tk_getOpenFile -multiple 1] on unix (helfter)

2008-08-25 (bug fix)[1023955] default menu cursor: no more Motif (helfter)

2008-08-28 (bug fix) correct TK_LIBS value to include Xft (porter)

2008-09-03 (support) Dropped support for pre-ANSI compilers. (porter)

2008-10-01 (new feature)[TIP 236] [$canvas moveto] (mckay,fellows)

2008-10-05 (bug fix)[2112563] format double values explicitly in double
format, avoiding sensitivity to locale setting. (fellows)
        *** POTENTIAL INCOMPATIBILITY ***

--- Released 8.6a3, October 10, 2008 --- See ChangeLog for details ---

2008-10-17 (enhancement) keyboard bindings for ttk::scale (thoyts)

2008-10-18 (bug fix)[1825353] Russian Windows tiny fonts problem (thoyts)

2008-10-18 (new feature)[TIP 321] [tk busy] (decoster,fellows)

2008-10-28 (bug fix)[1534835,2054562] use of more correct cursors (english)

2008-11-01 (new feature) New [ttk::spinbox] widget (thoyts)

2008-11-01 (new feature)[TIP 97] [$canvas imove] [$canvas rchars] (fellows)

2008-11-09 (bug fix)[2207435] [ttk::entry .t -textvar ::noexist::x] (english)

2008-11-11 (bug fix)[2312027] Tk_Create*ImageType() thread safety (nijtmans)

2008-11-11 (bug fix)[2264732] crash using nondefault visual (english)

2008-11-12 (bug fix)[1777362] permit [text] names containing "-" (thoyts)

2008-11-14 (bug fix)[2239034] limit [wm manage] to Frames (thoyts)

2008-11-22 (new feature)[TIP 119] -angle option for canvas text items (fellows)

2008-11-22 (bug fix)[1939129,1991930] combobox behind other windows (thoyts)

2008-11-22 (new feature) Demo ctext.tcl now demos angled text (fellows)

2008-11-23 (bug fix)[1389270] made [event generate <Focus*>] work (thoyts)

2008-11-28 (bug fix)[1813597,2218964] eliminate unnecessary units conversion
in screen distances, reducing precision loss (ferrieux)

2008-12-03 (enhancement) new "hover" state for proper Vista visuals (thoyts)

2008-12-05 (bug fix)[2107938] no negative font size in PS (fellows)

2008-12-05 (enhancement) new "vista" theme (thoyts)

2008-12-06 (new feature)[TIP 197] [$text -insertunfocussed] (edwards,fellows)

2008-12-06 (new feature)[TIP 337] handle non-error bg exceptions (porter)

2008-12-10 (new feature)[TIP 324] [tk fontchooser](thoyts,vetter,robert,steffen)

2008-12-12 (new feature) Demo fontchoose.tcl demos [tk fontchooser] (thoyts)

2008-12-18 (enhancement)[24442309] Updated German messages (haertel)

--- Released 8.6b1, December 19, 2008 --- See ChangeLog for details ---

2008-12-27 (bug fix)[2381555] horiz. scroll [$treeview identify] (english)

2008-12-28 (new feature)[TIP 244] PNG photo format support (fellows)

2008-12-28 (new feature)[TIP 171] <MouseWheel> event handling (fellows)
	*** POTENTIAL INCOMPATIBILITY ***

2008-12-31 (bug fix)[2003310] radio|check button indicator color (english)

2009-01-06 (bug fix)[2484771] messagebox: system to task modal (ferrieux,thoyts,mjanssen)

2009-01-06 (enhancement)[1539990] optimize photo building (jepler)

2009-01-07 (bug fix)[2473120] chooseDir syntax error (bron)

2009-01-07 (bug fix)[1847002] Win: prevent grab bypass (thoyts)

2009-01-11 (bug fix)[2496162] crash calling Tk_DeleteOptionTable() (english)

2009-01-11 (bug fix) crash on XCreateIC failure (staplin)

2009-01-14 (bug fix)[2507326] Restore aMSN compat (nijtmans)

2009-01-19 (new feature) CONFIG_INSTALL_DIR - where tkConfig.sh goes (cassoff)

2009-01-19 (platform support) better tools for BSD ports (cassoff)

2009-02-08 (bug fix)[2431428] panic computing layout on active widget (english)

2009-02-17 (platform support) MSVC and _WIN64 (hobbs)

2009-02-21 (bug fix)[2546087] [console] display of true UTF-8 \0 (thoyts)

2009-02-23 (bug fix)[1329198,456299,2507419] menu image display (mcdonald)

2009-02-23 (bug fix)[2513104] fix cursor hotspots (mcdonald)

2009-02-23 (bug fix)[2542828] Win: standard question_arrow cursor (danckaert)

2009-02-27 (bug fix)[2645457] crash in Tk_MakeWindowExist() (thoyts)

2009-03-09 (bug fix)[2548661] crash in GetFontFamilyName (riefenstahl)

2009-03-25 (bug fix)[2178820] stop zero-size allocs in ttk (fellows)

2009-03-25 (bug fix)[1871101] blurry large fonts on Vista (garvey,fellows)

2009-04-03 (bug fix)[1789819] stop panic on unexpected wm stack order (english)

2009-04-10 (bug fix)[2116837] std virtual events with Caps Lock (fellows)

2009-04-10 (platform) sse Darwin SUSv3 extensions if available (steffen)

2009-04-10 (bug fix) Motif checkbutton on X11 only (steffen)

2009-04-10 (bug fix) remove TkAqua Quit menu item on [console] (steffen)

2009-04-10 (bug fix) crash deleting char range from [text] (steffen)

2009-04-23 (bug fix)[2779910] updated Win chooseDir (hobbs)

2009-04-24 (bug fix) prevent delete of selected folder in Win dialog (hobbs)

2009-04-30 (bug fix)[2080533] panedwindow sash draw crash (fellows)

2009-04-30 (bug fix)[2504402] iconphoto on non-32-bit displays (mcdonald,thoyts)

2009-05-01 (bug fix)[2777019] anchor for text rotation (gavilán,fellows)

2009-05-03 (bug fix)[2785744] broken flag twiddling (baker,fellows)

2009-05-13 (bug fix)[2791352] XLFD parsing error (thoyts)

2009-05-14 (new feature) Vista theme support (thoyts)

2009-05-14 (bug fix)[1923684] confused checkbutton state (thoyts)

2009-05-17 (new feature)[1470246] notebook tab orientation control (english)

2009-05-21 (bug fix)[2794778] Win menu keyboard traversal (thoyts)

2009-06-02 (bug fix)[2799589] crash on delayed window activation (thoyts)

2009-06-23 (bug fix)[220935] canvas dash update problem (nijtmans)

2009-06-23 (platform) new subdir 'carbon' preserved for OSX 10.4-
use --enable-aqua=carbon option to unix/configure to enable (steffen)

2009-06-29 (new feature) source in `macosx` now built on Cocoa (steffen)
	*** POTENTIAL INCOMPATIBILITY ***

2009-06-30 (platform support) clang static analyzer macros (steffen)

2009-07-15 (bug fix)[2821962] photo image copy/paste (rib,fellows)

2009-07-21 (bug fix)[2356057] rotated underlined text (fellows)

2009-07-22 (bug fix)[2496114] focus in dead window crash (griffin,fellows)

2009-07-23 (bug fix)[2441988] report errors in selection handlers (fellows)
	*** POTENTIAL INCOMPATIBILITY ***

2009-08-01 (bug fix)[2830420] X iconphoto for big endian (misch,fellows)

2009-08-04 (bug fix) [text] word-wrap of non-breaking space (fellows)

2009-08-14 (bug fix) copy from unmapped toplevel crash (alaoui,steffen)

2009-08-19 (bug fix)[2475855] prevent grid & pack on same master (spjuth)

2009-08-24 (bug fix)[2821084] Cocoa: let WM_DELETE_WINDOW handler stop window
deletion (walzer,steffen)

2009-08-24 (bug fix) tk::MessageBox bindings for ttk::buttons (steiner,fellows)

2009-08-25 (bug fix)[1909931] [send] update for Fedora 8 (fellows)

2009-09-10 (bug fix) font allocation crash (berezhnoy,fellows)

2009-09-14 (bug fix)[873608] win tearoff menu, no submenu arrows (traum,hobbs)

2009-09-14 (bug fix)[873613] win tearoff menu repeat select (traum,hobbs)

2009-09-25 (bug fix) grayscale from images (vetter,fellows)

2009-10-07 (bug fix)[2088597] min scrollbar slider size (danckaert,fellows)

2009-10-07 (bug fix)[2787164] combobox/menubutton arrow size (thoyts)

2009-10-08 (bug fix)[2870648] file dialog cursor (danckaert,fellows)

2009-10-10 (feature)[1961455] underline, overstrike Xft fonts (caffin,fellows)

2009-10-20 (enhancement) Updates to Polish messages (pawlak)

2009-10-22 (bug fix)[2168768] file dialog -typevariable scope (danckaert)

2009-10-22 (bug fix)[1469210] [text] modified error (danckaert)

2009-10-22 (bug fix)[2883712] 64-bit Aqua progress bar (haffner)

2009-10-24 (bug fix)[1530276] X checkbutton -selectcolor (danckaert)

2009-10-25 (bug fix)[1854913] [.t delete] before -startindex (danckaert)

2009-10-25 (bug fix)[2809525] prevent X crash on overlong color name (goth)

2009-10-29 (bug fix)[1825353] Russian Windows tiny fonts problem (thoyts)

2009-11-01 (new feature) Ttk: [$w identify] now an ensemble (jenglish)

2009-11-19 (bug fix)[2899685] fix [imove] redraw logic (schekin,ferrieux)

2009-11-22 (bug fix)[2899949] crash on widget destroy (meier,thoyts)

2009-11-23 (bug fix)[2902573] Update Safe Tk to new Safe Base (kurpies)

2009-11-24 (bug fix)[2902814] fix [wm iconphoto] on LP64 systems (fellows)

2009-12-08 (bug fix)[2864685] Compiz menu item animation (gavilán,thoyts)

2009-12-11 (bug fix)[2912473] accept :: in DISPLAY name (fellows)

2009-12-15 (bug fix)[2492179] Tcl_ObjType "option" no longer registered (porter)
	*** POTENTIAL INCOMPATIBILITY for Tcl_GetObjType("option") ***

2009-12-20 (bug fix)[2917663] [send] accept SI:* on auth list (fellows)

2009-12-22 (bug fix)[2912356] [ttk::sizegrip] accommodate Compiz (english)

2009-12-25 (bug fix)[2977688,2546779] tab selection focus (english)

2009-12-27 (bug fix)[2879927] Win: cascade menu highlight (pawlak,thoyts)

2010-01-01 (bug fix)[1924761] stop [event generate] / XIM conflict (fellows)

2010-01-03 (bug fix)[2848897] ODS_NOACCEL flag support (kovalenko,thoyts)

2010-01-04 (bug fix)[2811266] <Return> binding in [tk_dialog] (thoyts)

2010-01-04 (bug fix)[2727476] font dialog appearance (thoyts)

2010-01-05 (bug fix)[220950] [$menu delete] bounds check (fellows)

2010-01-05 [2898255] unlimited multi-file select (pawlak,fellows,thoyts)

2010-01-06 (bug fix)[1163496] X: [wm transient] fix (bateman,fellows)

2010-01-09 (new feature)[TIP 360] Modernize X11 Menus (thoyts)

2010-01-18 (bug fix)[2932808] canvas update on state change (mcdonald,nijtmans)

2010-01-19 (new feature)[TIP 359] Extended Window Manager Hint Support (thoyts)

2010-01-19 (bug fix)[2931374] overflow in complex tag search (schmitz)

2010-02-17 (bug fix)[2952745] crash in menu deletion (english)

2010-02-20 (performance) treeview stop quadratic common case (english)

2010-03-02 (enhancement) -fvisibility-hidden build support (nijtmans)

2010-03-06 (bug fix)[2949774] cascade menu unpost (thoyts)

2010-03-11 (bug fix)[2968379] crash in peer text dump (fellows)

2010-03-17 (bug fix)[2971663] Cocoa entry <Up>, <Down> (goddard,fellows)

2010-03-28 (new feature) [$treeview tag names|add|remove] (english)

2010-04-09 (new feature)[2983824] [$image write -file] use extension of file
name to select image format (fellows)

2010-04-19 [2898255] unlimited multi-file select (pawlak,fellows,thoyts)

2010-05-31 (bug fix)[3006842] crash on empty bind scripts (english)

2010-06-15 (bug fix)[2585265] text <Delete>,<Backspace> note selection (fellows)

2010-06-15 (new package)[3016598] Tk now provides "tile 0.8.6" (english)

2010-07-19 (new feature) [$photo data -format GIF] (fellows)

2010-08-03 (bug fix) entry validation compat with Itcl scope (hobbs)

2010-08-11 (platform) Drop pre-aix 4.2 support, ldAix (hobbs)

2010-08-21 (patch)[3034251] genStubs steal features of ttkGenStubs (nijtmans)

2010-08-26 (bug fix)[1230554] configure, OSF-1 problems, windows manifest issues (hobbs)

2010-08-31 fixed manifest handling on windows (hobbs, kupries)

2010-09-02 (bug fix)[3057573] specify combobox text fg color (english)

2010-09-05 (enhancement)[3046742,3046750] Improved error dialog UI (fellows)

2010-09-08 (bug fix)[2829363] [$tv see] open item -> sched display (english)

2010-09-13 (platform) limit support to Win2000+ (nijtmans)

2010-10-01 (bug fix)[3078902] no hang operating on zero-size subimages (fellows)

2010-10-05 (bug fix)[3080953] corrupt multibyte char in %A subst (nijtmans)

2010-10-11 (bug fix)[3085489] crash in [tag add/remove] (english)

2010-10-11 (enhancement)[491789] Unicode command line support on Win (nijtmans)

2010-11-03 windows build with -UNICODE (nijtmans)

2010-11-05 Message catalogs reworked to use unicode copyright char (nijtmans)

2010-11-06 Message catalogs resorted, updates to NL (nijtmans)

2010-11-16 (platform) VS 2005 SP1 MSVC compiler (nijtmans)

2010-11-24 (bug fix)[3071836] crash in tk_getSaveFile (twylite)

2010-12-03 (enhancement)[3116490] mingw x-compile improvements (nijtmans)

2010-12-12 (platform) OpenBSD build improvements (cassoff)

2010-12-17 (platform) Revisions to support rpm 4.4.2 (cassoff)

2011-01-06 (bug fix)[2857300] Cocoa: correct text width rounding (walzer)

2011-01-06 (bug fix)[3086887] Cocoa: textured bg windows (walzer)

2011-01-13 (bug fix)[3154705] tk_messageBox close button disabled (skylera)

2011-01-22 (enhancement) add [ttk::entry validate] (schelte,english)

2011-01-24 (bug fix)[2907388] OSX: composite character entry crash (berg,walzer)

2011-03-02 (new doc) tk_mac.n: OS X specific functions (walzer)

2011-03-03 (bug fix)[3175610] incomplete line item refresh (ferrieux)

2011-03-10 (bug fix)[3205260] crash in [wm manage] (boudaillier, thoyts)

2011-03-16 (bug fix)[3181181] tearoff submenu fix (menez, thoyts)

2011-03-19 (bug fix)[3205464] [wm forget] loses window (boudaillier,thoyts)

2011-03-19 (bug fix)[3223850] ttk button state disabled during click (thoyts)

2011-03-22 (bug fix)[3000002] ttk scrollbar size Appearance (garvey,thoyts)

2011-03-24 (bug fix)[3239768] Win menu font support (wehle)

2011-03-28 (bug fix)[3129527] stop buffer overflows (dirtyepic,nijtmans)

2011-04-04 (feature change)[2997657] No -container for [labelframe] (spjuth)

2011-04-04 (bug fix)[723765] [grid remove] lost -in value (saye,spjuth)

2011-04-22 (bug fix)[3291543] mem corrupt when [$canvas dchars] removes all
coords of a polygon (rogers,spjuth)

2011-04-29 (platform support) [wm forget|manage] on OS X (walzer)

2011-06-06 (bug fix)[2546087] [console] treatment of '\0' (porter)

2011-06-07 (bug fix)[2358545] Restore "08" in spinbox configured with -from
and -to (porter)

2011-06-10 (bug fix)[3315731] fix [$entry -invcmd] (porter)

2011-06-17 (bug fix)[3062331] crash in unset traces (macdonald,porter)

2011-08-03 (bug fix)[2891541] fix grab behaviour for main window (thoyts)

--- Released 8.6b2, August 8, 2011 --- See ChangeLog for details ---

2011-09-22 (bug fix)[3404541] -takefocus option (dzach,english)

2011-10-24 (new feature)[TIP 382] -confirmoverwrite on save dialog (porter)

2011-10-25 (bug fix)[3410609] AltGr keysyms on Swiss keyboard (tasser,kenny)

2011-11-17 (bug fix)[3437816] return code of [canvas lower] (hirner,ferrieux)

2011-12-22 (bug fix)[3235256] correct menu failure on Windows (mcdonald)

2012-01-19 (bug fix)[3021557] cursor freeze in elided text (vogel)

2012-01-22 (bug fix)[3476698] hang in [text mark prev/next] (vogel)

2012-01-25 (bug fix)[3475627] Stop text-31.11 failure (vogel)

2012-01-25 (bug fix)[1630271] hang/crash on mark before -startline (vogel)

2012-01-26 (bug fix)[1754043,2321450] -blockcursor appearance (vogel)

2012-01-27 (bug fix)[3480471] crash in [tk_getOpenFile] (nijtmans)

2012-01-29 (bug fix)[3480634] PNG image in menus (nijtmans)

2012-01-30 (bug fix)[2925561] disabled combobox don't take focus (english)

2012-02-10 (bug fix) win dialog avoid shimmer that confuses Python (fellows)

2012-02-15 (bug fix)[3486474] Correct color scaling (goth,nijtmans)

2012-02-28 (bug fix)[1630262,1615425] [text] crash tags & -*line (vogel)

2012-03-07 (bug fix)[3497848] consistent pixel rounding (fassel,fellows)

2012-03-18 (enhancement)[3503317] XParseColor speedup (nijtmans)

2012-04-07 (bug fix)[3176239] control-Mousewheel crash (couch,nijtmans)

2012-04-22 (bug fix)[3520202] <MouseWheel> %k,%K,%N for Python (deily,fellows)

2012-05-02 (bug fix)[533519] multiscreen window placement (nijtmans)

2012-05-04 (bug fix)[2768586] multiscreen menu posting (nijtmans)

2012-05-28 (bug fix)[1630254] text peer update on -startline reset (baker,vogel)

2012-06-11 (bug fix)[3294450] ttk text element clipping (oehlmann,fellows)

2012-07-02 (bug fix) Make sure all index tables are static (kirkham,english)

2012-07-23 (bug fix)[3546073] DisplayString() -> DefaultDisplay() (english)

2012-08-11 (bug fix)[3554273] text elide and tags (vogel)

2012-08-15 (enhancement)[3555324] Win:Ctrl-A now means Select-All (nijtmans)
	*** POTENTIAL INCOMPATIBILITY ***

2012-08-22 (new feature)[TIP 403] Use Web color definitions (nijtmans)
	*** POTENTIAL INCOMPATIBILITY ***

2012-08-23 (enhancement)[3555644] better use of virtual events (nijtmans)
	*** POTENTIAL INCOMPATIBILITY ***

2012-08-24 (bug fix)[3558535] file dialog filtering (fellows)

2012-08-25 (bug fix)[3554026,3561016] crash with tearoff menus (gavilán)

2012-09-11 (bug fix)[3566594] stop clip region leaks (fellows)

2012-09-15 (bug fix)[3567778] stop hang in wrapped label (porter)

2012-09-17 (bug fix)[3567786] stop segfault in [wm forget] (porter)

Many revisions to better support a Cygwin environment (nijtmans)

--- Released 8.6b3, September 18, 2012 --- See ChangeLog for details ---

2012-10-02 (bug fix)[3572016] menu enable after modal dialog (berg,walzer)

2012-10-08 Remove Carbon support

2012-10-24 (bug fix)[3574893] crash in [wm forget] (porter)

2012-11-07 (bug fix)[3574708] crash in focus handling (fellows)

2012-11-14 (bug fix)[3500545] fix [tk_getOpenFile -multiple] (bruederlin)

2012-12-04 (bug fix)[3588824] Support weird image names in [text] (vogel)

2012-12-06 (bug fix)[3592736] stop pink greys from buggy mingw builds (fellows)

--- Released 8.6.0, December 20, 2012 --- See ChangeLog for details ---

2013-01-04 (bug fix) Tk_InitStubs("8.6") rejected in 8.60 interp (nijtmans)

2013-01-10 (bug fix)[3600251] Mac <Control-v> binding (kjnash,nijtmans)

2013-01-10 (bug fix)[3600260] <<SelectNextPara>> binding (kjnash,nijtmans)

2013-01-13 (bug fix)[3600290] restore $tk_strictMotif respect (kjnash,nijtmans)

2013-01-22 (bug fix)[3601782] Tcl_InitStubs failure message (nijtmans)

2013-01-31 (bug fix)[3599928] use XKeycodeToKeysym on old systems (cassoff)

2013-02-04 (bug fix)[3603077] treeview update on tag add/remove (english)

2013-02-28 (bug fix)[3599312] First Alt key event is lost (mcdonald)

2013-03-11 (bug fix)[3607326] Crash [listbox .l -listvariable $array] (porter)

2013-03-13 (enhancement) better build support for Debian arch (shadura)

2013-03-27 (bug fix)[3608074] button, listbox, menu <<Invoke>> (nijtmans)

2013-04-01 (bug fix)[3607830] Xkb runtime checks (griffin)

2013-05-19 (platform support) FreeBSD updates (cerutti)

2013-06-05 (bug fix)[3613759] [ttk::entry .e; .e xview end] (nijtmans)

2013-06-05 (bug fix)[2100430] [ttk::entry .e; .e xview insert] (nijtmans)

2013-06-28 (bug fix)[2501278] reverse ttk::scale key bindings {mcdonald)

2013-07-02 (bug fix)[32afa6] corrected dirent64 check (griffin)

2013-08-14 (bug fix)[069c9e] "option" value refcount crash (tim,nijtmans)

2013-08-15 (bug fix)[c597acd] [$pb step] work with traces (english)

2013-08-25 (bug fix)[3016181] Cocoa: [destroy $scrollbar] => crash (goddard)

--- Released 8.6.1, September 19, 2013 --- http://core.tcl.tk/tk/ for details

2013-10-27 (bug fix) OSX drawing lags (deily,steffen,walzer)

2013-10-28 (bug fix)[3603436] png wrong component indices (nijtmans)

2013-10-31 (bug fix) C++ friendly stubs struct declarations (nijtmans)

2013-10-31 (bug fix)[c0cc9fd] PNG parser accept uppercase -format (nijtmans)

2013-10-31 (bug fix) double free of a TkFont (nijtmans)

2013-11-03 (bug fix)[1632447] support PPM maxval up to 65535 (fellows)

2013-11-05 (bug fix)[426679e] OpenBSD man page rendering (nijtmans)

2013-11-11 (bug fix)[f214b8a] multi-interp font teardown double free (porter)

2013-11-11 (bug fix)[0aa5e85] option file \n syntax support (nijtmans)

2013-11-20 (platforms) Support for Windows 8.1 (nijtmans)

2014-01-23 (bug fix)[3606644] X: correct fontconfig dependence (venable)

2014-01-23 (bug fix) FreeBSD build fixes (cerutti)

2014-02-06 (bug fix)[3279221] [menu] event race (danckaert,kupries)

2014-02-07 (bug fix)[6867cc1] creative writing in [tk fontchooser] (nijtmans)

2014-02-11 (bug fix)[52ca3e7] XkbOpenDisplay macro correction (nijtmans)

2014-03-16 (bug fix) Xcode 5.1 update; Retina displays (walzer)

2014-03-20 (bug fix)[2f7cbd0] FreeBSD 10.0 build failure (nijtmans)

2014-04-01 (bug fix)[5bcb502] @TK_LIBS@ in pkgconfig (badshah400,nijtmans)

2014-05-27 (bug fix)[a80f5d7] autoscroll initiation (crogers,english)

2014-07-07 (bug fix) OSX alpha channel rendering (culler,walzer)

2014-07-08 (workaround)[4955f5d] Ocaml trouble with tailcall splice (nijtmans)

2014-07-24 (bug fix) OSX [text] image display & scrolling (culler,walzer)

2014-08-01 (bug fix) OSX font config crash (rob@bitkeeper)

--- Released 8.6.2, August 27, 2014 --- http://core.tcl.tk/tk/ for details

2014-08-27 (bug) Cocoa: Crash after [$button destroy] (walzer)

2014-09-23 (bug) Cocoa: button and scroll display fixes (walzer)

2014-09-24 (bug) Cocoa: improved drawing performance (walzer)

2014-10-11 (bug)[9e487e] Phony button clicks from browsers to plugin (nijtmans)

2014-10-11 (bug)[810c43] [text] elide changes advance epoch (vogel)

2014-10-14 (bug)[fb35eb] fix PNG transparency appearance (walton,culler)

2014-10-18 (feature)[TIP 432] Win: updated file dialogs (nadkarni)

2014-10-26 Support for Windows 10 (nijtmans)

2014-10-28 (bug) OSX: Improved ttk notebook tab metrics for Yosemite (walzer)

2014-10-30 (bug)[3417012] [scale -digits $bigValue] segfault (vogel)

2014-11-07 (bug)[3529885] [scale] handling of negative resolution (vogel)

--- Released 8.6.3, November 12, 2014 --- http://core.tcl.tk/tk/ for details

2014-11-14 (bug)[d43a10] shimmer-related crash in [tk_getOpenFile] (nadkarni)

2014-11-23 (bug)[1c0d6e] Win build trouble with SIGDN (keene)

2014-12-03 (bug)[4a0451] [tk_getOpenFile] result (nadkarni)

2014-12-13 fix header files installation on OS X (houben)

2015-01-02 (bug) Stop bit loss in [winfo id] on 64-bit Cocoa (porter)

2015-02-06 (bug) several fixes to elided context in [text] (vogel)

2015-02-06 (new feature)[TIP 433] %M binding substitution (mistachkin)
        *** POTENTIAL INCOMPATIBILITY ***

2015-02-22 (bug)[ab6dab] corrupt dashed lines in postscript (porter)

Tk Cocoa 2.0: App Store enabled (walzer,culler,desmera,owen,nyberg,reincke)
        *** POTENTIAL INCOMPATIBILITY ***

--- Released 8.6.4, March 12, 2015 --- http://core.tcl.tk/tk/ for details

2015-03-10 (bug) Cocoa: premature image free crash (walzer)

2015-03-15 (bug) Cocoa: wish launches in front. [focus -force] works (culler)

2015-04-09 (bug)[e4ed00] [$text index "1.0 display wordstart"] crash (vogel)

2015-04-09 (bug)[562118] Unicode support of "wordstart" modifier (vogel)

2015-05-05 (bug)[06c3fc] PNG alpha error corrupted output file (gauthier,porter)

2015-05-20 (bug)[dece63] various mem corruptions in images (mic42,porter)

2015-05-24 (bug)[53f8fc] panedwindow geometry management (vogel)

2015-05-26 (bug)[1641721] tk_getOpenFile symlink display doubled (nijtmans)

2015-06-01 (bug)[d7bad5][2368195][3592454][1714535][1292219][3592454]
                panedwindow fixes (vogel)

2015-06-25 (bug)[805cff] Tk_ConfigureWidget() segfault (aspect,nijtmans)

2015-07-13 (bug)[3f179a] Text widget crash with elided text (vogel)

2015-07-16 (bug)[2886436] Stop [$text delete] acting before start index (vogel)

2015-07-28 (bug)[1236306] TraverseToMenu error bound to toplevel destroy (vogel)

2015-08-20 (bug)[00189c] MSVC 14: semi-static UCRT support (dower,nijtmans)

2015-09-13 (bug)[cc0ba3] PNG read buffer overflow (maxjarek,porter)

2015-09-29 (bug)[1501749] Crash embedded window delete bound to <Map> (vogel)

2015-10-04 (license) Replace icons that lacked clear free license (cowals)

2015-10-06 (bug)[46c83f] Win: tk_getOpenFile -initialdir (koend,nadkarni)

2015-10-08 (new feature)[TIP 437] New panedwindow options (vogel)

2015-10-09 (bug)[1669632] [text] autoseparator placement (nash,vogel)

2015-10-09 (bug)[2262711] [text] RE search Unicode+elided (kaitzschu,vogel)

2015-10-09 (bug)[1815161] [$text count -ypixels] needs management (vogel)

2015-10-22 (bug)[1520118] Document spinbox validate expectations (vogel)

2015-10-22 (bug)[1414025] $entry insertion cursor visibility (vogel)

2015-10-26 (bug) PNG rendering on El Capitan (meier,walzer)

2015-11-08 (bug)[2160206] menubutton panic (vogel)

2015-11-08 (bug)[220854] Display trailing TAB in entry (vogel)

2015-11-08 (bug)[542199] double click on lone char in entry (vogel)

2015-11-08 (bug)[297442d] strict motif binding on <Control-underscore> (vogel)

2015-11-08 (bug)[3601604] $listbox -takefocus (vogel)

2015-11-09 (bug)[5ee8af] X, Win: 64-bit enable embedded windows (vogel)

2015-11-29 (bug)[1997299] [text] tag borderwidth leak (vogel)

2015-12-12 (bug)[1739605] [text see] misbehavior (danckaert)

2015-12-13 (bug)[ff8a1e] Never-mapped [text] performance (danckaert)

2015-12-19 (bug)[1700065] Report errors from -textvariable write trace (vogel)

2015-12-19 (bug)[793909] -textvariable handle undefined namespace (vogel)

2015-12-26 (bug)[2f78c7] crash with [text] and [tablelist] (vogel)

2016-01-06 (bug)[1288433,3102228] <<ListboxSelect>> misfires (vogel)

2016-01-08 (bug)[1510538] initial scrollbar width (vogel,nijtmans)

2016-01-08 (bug)[1305128] event not received by scrollbar (vogel,nijtmans)

2016-01-09 (bug)[1927212] Mousewheel/scrollbar bindings (vogel)

2016-01-11 (bug)[63c354] Cocoa message boxes (culler)

2016-01-12 (bug)[2049429] get more $text options from database (vogel)

2016-01-22 (TIP 441) New option [listbox ... -justify] (vogel)

2016-01-25 (bug) OBOE in ttk::notebook options parsing (bromley,english)

2016-02-08 (enhance) [option readile] expects utf-8 file (oehlmann,nijtmans)

2016-02-08 (bug) crash in [$text delete] (griffin,vogel)

Tk Cocoa 2.0: More drawing internals refinements (culler,walzer)

--- Released 8.6.5, February 29, 2016 --- http://core.tcl.tk/tk/ for details

Deleted changes.md.

1

-
TODO

Deleted compat/stdbool.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37





































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*===---- stdbool.h - Standard header for booleans -------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
* Modified for use by pre-C99 compilers. (c) Jan Nijtmans.
*
*===-----------------------------------------------------------------------===
*/

#ifndef __STDBOOL_H
#define __STDBOOL_H

/* Don't define bool, true, and false in C++, except as a GNU extension. */
#ifndef __cplusplus
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define bool _Bool
#else
#define bool unsigned char
#endif
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool as a GNU extension. */
#define _Bool bool
#if __cplusplus < 201103L
/* For C++98, define bool, false, true as a GNU extension. */
#define bool  bool
#define false false
#define true  true
#endif
#endif

#define __bool_true_false_are_defined 1

#endif /* __STDBOOL_H */

Added compat/stdlib.h.









































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * stdlib.h --
 *
 *	Declares facilities exported by the "stdlib" portion of the C library.
 *	This file isn't complete in the ANSI-C sense; it only declares things
 *	that are needed by Tk. This file is needed even on many systems with
 *	their own stdlib.h (e.g. SunOS) because not all stdlib.h files declare
 *	all the procedures needed here (such as strtod).
 *
 * Copyright (c) 1991 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _STDLIB
#define _STDLIB

#ifndef _TCL
#   include <tcl.h>
#endif

extern void		abort(void);
extern double		atof(const char *string);
extern int		atoi(const char *string);
extern long		atol(const char *string);
extern char *		calloc(unsigned int numElements, unsigned int size);
extern void		exit(int status);
extern int		free(char *blockPtr);
extern char *		getenv(const char *name);
extern char *		malloc(unsigned int numBytes);
extern void		qsort(void *base, int n, int size, int (*compar)(
			    const void *element1, const void *element2));
extern char *		realloc(char *ptr, unsigned int numBytes);
extern double		strtod(const char *string, char **endPtr);
extern long		strtol(const char *string, char **endPtr, int base);
extern unsigned long	strtoul(const char *string, char **endPtr, int base);

#endif /* _STDLIB */

Added compat/unistd.h.

















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * unistd.h --
 *
 *      Macros, constants and prototypes for Posix conformance.
 *
 * Copyright 1989 Regents of the University of California Permission to use,
 * copy, modify, and distribute this software and its documentation for any
 * purpose and without fee is hereby granted, provided that the above
 * copyright notice appear in all copies. The University of California makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

#ifndef _UNISTD
#define _UNISTD

#include <sys/types.h>
#ifndef _TCL
#   include <tcl.h>
#endif

#ifndef NULL
#define NULL    0
#endif

/*
 * Strict POSIX stuff goes here. Extensions go down below, in the ifndef
 * _POSIX_SOURCE section.
 */

extern void		_exit(int status);
extern int		access(const char *path, int mode);
extern int		chdir(const char *path);
extern int		chown(const char *path, uid_t owner, gid_t group);
extern int		close(int fd);
extern int		dup(int oldfd);
extern int		dup2(int oldfd, int newfd);
extern int		execl(const char *path, ...);
extern int		execle(const char *path, ...);
extern int		execlp(const char *file, ...);
extern int		execv(const char *path, char **argv);
extern int		execve(const char *path, char **argv, char **envp);
extern int		execvp(const char *file, char **argv);
extern pid_t		fork(void);
extern char *		getcwd(char *buf, size_t size);
extern gid_t		getegid(void);
extern uid_t		geteuid(void);
extern gid_t		getgid(void);
extern int		getgroups(int bufSize, int *buffer);
extern pid_t		getpid(void);
extern uid_t		getuid(void);
extern int		isatty(int fd);
extern long		lseek(int fd, long offset, int whence);
extern int		pipe(int *fildes);
extern int		read(int fd, char *buf, size_t size);
extern int		setgid(gid_t group);
extern int		setuid(uid_t user);
extern unsigned		sleep(unsigned seconds);
extern char *		ttyname(int fd);
extern int		unlink(const char *path);
extern int		write(int fd, const char *buf, size_t size);

#ifndef	_POSIX_SOURCE
extern char *		crypt(const char *, const char *);
extern int		fchown(int fd, uid_t owner, gid_t group);
extern int		flock(int fd, int operation);
extern int		ftruncate(int fd, unsigned long length);
extern int		ioctl(int fd, int request, ...);
extern int		readlink(const char *path, char *buf, int bufsize);
extern int		setegid(gid_t group);
extern int		seteuid(uid_t user);
extern int		setreuid(int ruid, int euid);
extern int		symlink(const char *, const char *);
extern int		ttyslot(void);
extern int		truncate(const char *path, unsigned long length);
extern int		vfork(void);
#endif /* _POSIX_SOURCE */

#endif /* _UNISTD */

Changes to doc/3DBorder.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16

17
18

19
20
21
22
23
24
25

26
27
28
29
30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45
46
47

48
49
50

51
52
53

54
55

56
57

58
59
60
61
62
63
64
65
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15

16
17

18
19




20

21
22


23

24
25
26

27
28
29

30
31
32

33
34
35

36
37
38

39
40
41

42
43
44

45
46
47

48
49
50

51
52
53

54
55

56
57

58

59
60
61
62
63
64
65











-
+



-
+

-
+

-
-
-
-

-
+

-
-

-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+


-
+


-
+


-
+

-
+

-
+
-







'\"
'\" Copyright (c) 1990-1993 The Regents of the University of California.
'\" Copyright (c) 1994-1998 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH Tk_Alloc3DBorderFromObj 3 8.1 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_Alloc3DBorderFromObj, Tk_ClipDrawableToRect, Tk_DrawHighlightBorder, Tk_Get3DBorder, Tk_Get3DBorderColors, Tk_Get3DBorderFromObj, Tk_Draw3DRectangle, Tk_Fill3DRectangle, Tk_Draw3DPolygon, Tk_Fill3DPolygon, Tk_3DVerticalBevel, Tk_3DHorizontalBevel, Tk_SetBackgroundFromBorder, Tk_NameOf3DBorder, Tk_3DBorderColor, Tk_3DBorderGC, Tk_Free3DBorderFromObj, Tk_Free3DBorder \- draw borders with three-dimensional appearance
Tk_Alloc3DBorderFromObj, Tk_Get3DBorder, Tk_Get3DBorderFromObj, Tk_Draw3DRectangle, Tk_Fill3DRectangle, Tk_Draw3DPolygon, Tk_Fill3DPolygon, Tk_3DVerticalBevel, Tk_3DHorizontalBevel, Tk_SetBackgroundFromBorder, Tk_NameOf3DBorder, Tk_3DBorderColor, Tk_3DBorderGC, Tk_Free3DBorderFromObj, Tk_Free3DBorder \- draw borders with three-dimensional appearance
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR

.sp
Tk_3DBorder
\fBTk_Alloc3DBorderFromObj\fR(\fIinterp, tkwin, objPtr\fR)
\fBTk_Alloc3DBorderFromObj(\fIinterp, tkwin, objPtr\fB)\fR
.sp
\fBTk_ClipDrawableToRect\fR(\fIdisplay, drawable, x, y, width, height\fR)
.sp
\fBTk_DrawHighlightBorder\fR(\fItkwin, fgGC, bgGC, highlightWidth, drawable\fR)
.sp
Tk_3DBorder
\fBTk_Get3DBorder\fR(\fIinterp, tkwin, colorName\fR)
\fBTk_Get3DBorder(\fIinterp, tkwin, colorName\fB)\fR
.sp
\fBTk_Get3DBorderColors\fR(\fIborder, bgColorPtr, darkColorPtr, lightColorPtr\fR)
.sp
Tk_3DBorder
\fBTk_Get3DBorderFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_Get3DBorderFromObj(\fItkwin, objPtr\fB)\fR
.sp
void
\fBTk_Draw3DRectangle\fR(\fItkwin, drawable, border, x, y, width, height, borderWidth, relief\fR)
\fBTk_Draw3DRectangle(\fItkwin, drawable, border, x, y, width, height, borderWidth, relief\fB)\fR
.sp
void
\fBTk_Fill3DRectangle\fR(\fItkwin, drawable, border, x, y, width, height, borderWidth, relief\fR)
\fBTk_Fill3DRectangle(\fItkwin, drawable, border, x, y, width, height, borderWidth, relief\fB)\fR
.sp
void
\fBTk_Draw3DPolygon\fR(\fItkwin, drawable, border, pointPtr, numPoints, polyBorderWidth, leftRelief\fR)
\fBTk_Draw3DPolygon(\fItkwin, drawable, border, pointPtr, numPoints, polyBorderWidth, leftRelief\fB)\fR
.sp
void
\fBTk_Fill3DPolygon\fR(\fItkwin, drawable, border, pointPtr, numPoints, polyBorderWidth, leftRelief\fR)
\fBTk_Fill3DPolygon(\fItkwin, drawable, border, pointPtr, numPoints, polyBorderWidth, leftRelief\fB)\fR
.sp
void
\fBTk_3DVerticalBevel\fR(\fItkwin, drawable, border, x, y, width, height, leftBevel, relief\fR)
\fBTk_3DVerticalBevel\fR(\fItkwin, drawable, border, x, y, width, height, leftBevel, relief\fB)\fR
.sp
void
\fBTk_3DHorizontalBevel\fR(\fItkwin, drawable, border, x, y, width, height, leftIn, rightIn, topBevel, relief\fR)
\fBTk_3DHorizontalBevel\fR(\fItkwin, drawable, border, x, y, width, height, leftIn, rightIn, topBevel, relief\fB)\fR
.sp
void
\fBTk_SetBackgroundFromBorder\fR(\fItkwin, border\fR)
\fBTk_SetBackgroundFromBorder(\fItkwin, border\fB)\fR
.sp
const char *
\fBTk_NameOf3DBorder\fR(\fIborder\fR)
\fBTk_NameOf3DBorder(\fIborder\fB)\fR
.sp
XColor *
\fBTk_3DBorderColor\fR(\fIborder\fR)
\fBTk_3DBorderColor(\fIborder\fB)\fR
.sp
GC *
\fBTk_3DBorderGC\fR(\fItkwin, border, which\fR)
\fBTk_3DBorderGC(\fItkwin, border, which\fB)\fR
.sp
\fBTk_Free3DBorderFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_Free3DBorderFromObj(\fItkwin, objPtr\fB)\fR
.sp
\fBTk_Free3DBorder\fR(\fIborder\fR)
\fBTk_Free3DBorder(\fIborder\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tk_3DBorder" borderWidth
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Token for window (for all procedures except \fBTk_Get3DBorder\fR,
must be the window for which the border was allocated).
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
86
87
88
89
90
91
92



93
94
95
96
97
98
99







-
-
-







Width of rectangle describing border or bevel, in pixels.
.AP int height in
Height of rectangle describing border or bevel, in pixels.
.AP int borderWidth in
Width of border in pixels. Positive means border is inside rectangle
given by \fIx\fR, \fIy\fR, \fIwidth\fR, \fIheight\fR, negative means
border is outside rectangle.
.AP int highlightWidth in
Width of ring around the outside of the widget if the widget has received the
input focus.
.AP int relief in
Indicates 3-D position of interior of value relative to exterior;
should be \fBTK_RELIEF_RAISED\fR, \fBTK_RELIEF_SUNKEN\fR, \fBTK_RELIEF_GROOVE\fR,
\fBTK_RELIEF_SOLID\fR, or \fBTK_RELIEF_RIDGE\fR (may also be \fBTK_RELIEF_FLAT\fR
for \fBTk_Fill3DRectangle\fR).
.AP XPoint *pointPtr in
Pointer to array of points describing the set of vertices in a polygon.
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
129
130
131
132
133
134
135












136
137
138
139
140
141
142







-
-
-
-
-
-
-
-
-
-
-
-







right than the top.
.AP int topBevel in
Non-zero means this bevel forms the top side of the value;  zero means
it forms the bottom side.
.AP int which in
Specifies which of the border's graphics contexts is desired.
Must be \fBTK_3D_FLAT_GC\fR, \fBTK_3D_LIGHT_GC\fR, or \fBTK_3D_DARK_GC\fR.
.AP XColor *bgColorPtr out
Pointer to location in which to store the background color of the given border.
.AP XColor *darkColorPtr out
Pointer to location in which to store the color for darker areas of the
given border.
.AP XColor *lightColorPtr out
Pointer to location in which to store the color for lighter areas of the
given border.
.AP GC fgGC in
Foreground X graphics context.
.AP GC fgGC in
Background X graphics context.
.BE
.SH DESCRIPTION
.PP
These procedures provide facilities for drawing window borders in a
way that produces a three-dimensional appearance.
\fBTk_Alloc3DBorderFromObj\fR
allocates colors and Pixmaps needed to draw a border in the window
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
155
156
157
158
159
160
161














162
163
164
165
166


167
168
169
170
171
172
173







-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
-







then NULL is returned and an error message is left as the result of
interpreter \fIinterp\fR.
If it returns successfully, \fBTk_Alloc3DBorderFromObj\fR caches
information about the return value in \fIobjPtr\fR, which speeds up
future calls to \fBTk_Alloc3DBorderFromObj\fR with the same \fIobjPtr\fR
and \fItkwin\fR.
.PP
\fBTk_ClipDrawableToRect\fR will clip all drawing into the drawable \fId\fR
to the given rectangle. If \fIwidth\fR or \fIheight\fR are negative, reset
to no clipping.
Subsequent drawing into \fId\fR is offset and clipped as specified.
The function is only used when \fBTK_NO_DOUBLE_BUFFERING\fR is specified at
compile time.
.PP
\fBTk_DrawHighlightBorder\fR draws a rectangular ring around the outside of
a widget to indicate that it has received the input focus.
On the Macintosh, this puts a 1 pixel border in the bgGC color between
the widget and the focus ring, except in the case where highlightWidth
is 1, in which case the border is left out.
For proper Mac L&F, use highlightWidth of 3.
.PP
\fBTk_Get3DBorder\fR is identical to \fBTk_Alloc3DBorderFromObj\fR except
that the color is specified with a string instead of a value.  This
prevents \fBTk_Get3DBorder\fR from caching the return value, so
\fBTk_Get3DBorder\fR is less efficient than \fBTk_Alloc3DBorderFromObj\fR.
.PP
\fBTk_Get3DBorderColors\fR returns the used colors of the given border.
.PP
\fBTk_Get3DBorderFromObj\fR returns the token for an existing border, given
the window and color name used to create the border.
\fBTk_Get3DBorderFromObj\fR does not actually create the border; it must
already have been created with a previous call to
\fBTk_Alloc3DBorderFromObj\fR or \fBTk_Get3DBorder\fR.  The return
value is cached in \fIobjPtr\fR, which speeds up
future calls to \fBTk_Get3DBorderFromObj\fR with the same \fIobjPtr\fR
219
220
221
222
223
224
225
226
227


228
229
230
231
232
233
234
188
189
190
191
192
193
194


195
196
197
198
199
200
201
202
203







-
-
+
+







\fIwidth\fR and \fIheight\fR are the dimensions of the window), and
\fIborderWidth\fR specifies the number of pixels actually
occupied by the border.  The \fIrelief\fR argument indicates
which of several three-dimensional effects is desired:
\fBTK_RELIEF_RAISED\fR means that the interior of the rectangle should
appear raised relative to the exterior of the rectangle, and
\fBTK_RELIEF_SUNKEN\fR means that the interior should appear depressed.
\fBTK_RELIEF_GROOVE\fR and \fBTK_RELIEF_RIDGE\fR mean that there should
appear to be a groove or ridge around the exterior of the rectangle.
\fBTK_RELIEF_GROOVE\fR and \fBTK_RELIEF_RIDGE\fR mean that there should appear to be
a groove or ridge around the exterior of the rectangle.
.PP
\fBTk_Fill3DRectangle\fR is somewhat like \fBTk_Draw3DRectangle\fR except
that it first fills the rectangular area with the background color
(one corresponding
to the color used to create \fIborder\fR).  Then it calls
\fBTk_Draw3DRectangle\fR to draw a border just inside the outer edge of
the rectangular area.  The argument \fIrelief\fR indicates the desired
318
319
320
321
322
323
324
325

326
287
288
289
290
291
292
293

294








-
+
-
with the window and color name used to create the
border; for \fBTk_Free3DBorder\fR the border to release is specified
with the Tk_3DBorder token for the border.
There should be exactly one call to \fBTk_Free3DBorderFromObj\fR or
\fBTk_Free3DBorder\fR for each call to \fBTk_Alloc3DBorderFromObj\fR
or \fBTk_Get3DBorder\fR.
.SH KEYWORDS
3D, background, border, color, depressed, illumination, value, polygon,
3D, background, border, color, depressed, illumination, value, polygon, raised, shadow, three-dimensional effect
raised, shadow, three-dimensional effect

Changes to doc/AddOption.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46



47
48

49
50

51
52
53
54

55
56
57
58
59
60
61
62
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15




16
17
18
19
20
21
22




23
24
25
26
27

28
29
30
31
32
33
34
35



36
37
38
39

40
41

42
43
44
45

46
47
48




49
50

-
+













-
-
-
-







-
-
-
-





-
+







-
-
-
+
+
+

-
+

-
+



-
+


-
-
-
-


'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH Tk_AddOption 3 "" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_AddOption \- Add an option to the option database
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
void
\fBTk_AddOption\fR(\fItkwin, name, value, priority\fR)
.sp
Tcl_Obj *
\fBTk_GetSystemDefault\fR(\fItkwin, dbName, className\fR)
.fi
.SH ARGUMENTS
.AP Tk_Window tkwin in
Token for window.
.AP "const char" *name in
Multi-element name of option.
.AP "const char" *value in
Value of option.
.AP "const char" *dbName in
The option database name.
.AP "const char" *className in
The name of the option class.
.AP int priority in
Overall priority level to use for option.
.BE
.SH DESCRIPTION
.PP
\fBTk_AddOption\fR is invoked to add an option to the database
This procedure is invoked to add an option to the database
associated with \fItkwin\fR's main window.  \fIName\fR
contains the option being specified and consists of names and/or
classes separated by asterisks or dots, in the usual X format.
\fIValue\fR contains the text string to associate with \fIname\fR;
this value will be returned in calls to \fBTk_GetOption\fR.
\fIPriority\fR specifies the priority of the value; when options are
queried using \fBTk_GetOption\fR, the value with the highest priority
is returned.  \fIPriority\fR must be between 0 and \fBTK_MAX_PRIO\fR (100).
Some common priority values are:
.IP \fBTK_WIDGET_DEFAULT_PRIO\fR (20)
is returned.  \fIPriority\fR must be between 0 and \fBTK_MAX_PRIO\fR.  Some
common priority values are:
.IP 20
Used for default values hard-coded into widgets.
.IP \fBTK_STARTUP_FILE_PRIO\fR (40)
.IP 40
Used for options specified in application-specific startup files.
.IP \fBTK_USER_DEFAULT_PRIO\fR (60)
.IP 60
Used for options specified in user-specific defaults files, such as
\fB.Xdefaults\fR, resource databases loaded into the X server, or
user-specific startup files.
.IP \fBTK_INTERACTIVE_PRIO\fR (80)
.IP 80
Used for options specified interactively after the application starts
running.
.PP
\fBTk_GetSystemDefault\fR returns a Tcl_Obj* with the string identifying
a configuration option matching the given \fIdbname\fR and \fIclassName\fR.
Returns NULL if there are no system defaults that match this pair.
.SH KEYWORDS
class, name, option, add

Changes to doc/BindTable.3.

11
12
13
14
15
16
17
18

19
20

21
22
23

24
25
26

27
28
29

30
31

32
33

34
35

36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61

62
63
64
65
66
67
68
11
12
13
14
15
16
17

18
19

20
21
22

23
24
25

26
27
28

29
30

31
32

33
34

35

36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59

60
61
62
63
64
65
66
67







-
+

-
+


-
+


-
+


-
+

-
+

-
+

-
+
-








-
+













-
+

-
+







.SH NAME
Tk_CreateBindingTable, Tk_DeleteBindingTable, Tk_CreateBinding, Tk_DeleteBinding, Tk_GetBinding, Tk_GetAllBindings, Tk_DeleteAllBindings, Tk_BindEvent \- invoke scripts in response to X events
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_BindingTable
\fBTk_CreateBindingTable\fR(\fIinterp\fR)
\fBTk_CreateBindingTable(\fIinterp\fB)\fR
.sp
\fBTk_DeleteBindingTable\fR(\fIbindingTable\fR)
\fBTk_DeleteBindingTable(\fIbindingTable\fB)\fR
.sp
unsigned long
\fBTk_CreateBinding\fR(\fIinterp, bindingTable, object, eventString, script, append\fR)
\fBTk_CreateBinding(\fIinterp, bindingTable, object, eventString, script, append\fB)\fR
.sp
int
\fBTk_DeleteBinding\fR(\fIinterp, bindingTable, object, eventString\fR)
\fBTk_DeleteBinding(\fIinterp, bindingTable, object, eventString\fB)\fR
.sp
const char *
\fBTk_GetBinding\fR(\fIinterp, bindingTable, object, eventString\fR)
\fBTk_GetBinding(\fIinterp, bindingTable, object, eventString\fB)\fR
.sp
\fBTk_GetAllBindings\fR(\fIinterp, bindingTable, object\fR)
\fBTk_GetAllBindings(\fIinterp, bindingTable, object\fB)\fR
.sp
\fBTk_DeleteAllBindings\fR(\fIbindingTable, object\fR)
\fBTk_DeleteAllBindings(\fIbindingTable, object\fB)\fR
.sp
\fBTk_BindEvent\fR(\fIbindingTable, eventPtr, tkwin, numObjects, objectPtr\fR)
\fBTk_BindEvent(\fIbindingTable, eventPtr, tkwin, numObjects, objectPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS Tk_BindingTable bindingTable
.AP Tcl_Interp *interp in
Interpreter to use when invoking bindings in binding table.  Also
used for returning results and errors from binding procedures.
.AP Tk_BindingTable bindingTable in
Token for binding table;  must have been returned by some previous
call to \fBTk_CreateBindingTable\fR.
.AP "void *" object in
.AP ClientData object in
Identifies object with which binding is associated.
.AP "const char" *eventString in
String describing event sequence.
.AP "const char" *script in
Tcl script to invoke when binding triggers.
.AP int append in
Non-zero means append \fIscript\fR to existing script for binding,
if any; zero means replace existing script with new one.
.AP XEvent *eventPtr in
X event to match against bindings in \fIbindingTable\fR.
.AP Tk_Window tkwin in
Identifier for any window on the display where the event occurred.
Used to find display-related information such as key maps.
.AP Tcl_Size numObjects in
.AP int numObjects in
Number of object identifiers pointed to by \fIobjectPtr\fR.
.AP "void **" objectPtr in
.AP ClientData *objectPtr in
Points to an array of object identifiers:  bindings will be considered
for each of these objects in order from first to last.
.BE
.SH DESCRIPTION
.PP
These procedures provide a general-purpose mechanism for creating
and invoking bindings.

Changes to doc/CanvPsY.3.

25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
25
26
27
28
29
30
31

32

33
34
35
36
37
38
39
40







-

-
+







int
\fBTk_CanvasPsFont\fR(\fIinterp, canvas, tkFont\fR)
.sp
\fBTk_CanvasPsPath\fR(\fIinterp, canvas, coordPtr, numPoints\fR)
.sp
int
\fBTk_CanvasPsStipple\fR(\fIinterp, canvas, bitmap\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Size "numPoints"
.AS "unsigned int" "numPoints"
.AP Tk_Canvas canvas in
A token that identifies a canvas widget for which Postscript is
being generated.
.AP double canvasY in
Y-coordinate in the space of the canvas.
.AP Tcl_Interp *interp in/out
A Tcl interpreter;  Postscript is appended to its result, or the
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+







.AP Tk_Font tkFont in
Font for which Postscript is to be generated.
.AP double *coordPtr in
Pointer to an array of coordinates for one or more
points specified in canvas coordinates.
The order of values in \fIcoordPtr\fR is x1, y1, x2, y2, x3, y3,
and so on.
.AP Tcl_Size numPoints in
.AP int numPoints in
Number of points at \fIcoordPtr\fR.
.BE
.SH DESCRIPTION
.PP
These procedures are called by canvas type managers to carry out
common functions related to generating Postscript.
Most of the procedures take a \fIcanvas\fR argument, which

Changes to doc/CanvTkwin.3.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39







-







\fBTk_CanvasWindowCoords\fR(\fIcanvas, x, y, screenXPtr, screenYPtr\fR)
.sp
\fBTk_CanvasEventuallyRedraw\fR(\fIcanvas, x1, y1, x2, y2\fR)
.sp
Tk_OptionParseProc *\fBTk_CanvasTagsParseProc\fR;
.sp
Tk_OptionPrintProc *\fBTk_CanvasTagsPrintProc\fR;
.fi
.SH ARGUMENTS
.AS Tk_ItemType *drawableXPtr
.AP Tk_Canvas canvas in
A token that identifies a canvas widget.
.AP Tcl_Interp *interp in/out
Interpreter to use for error reporting.
.AP "const char" *string in
141
142
143
144
145
146
147
148

149
150
151
152
153

154
155
156
157
158
159
140
141
142
143
144
145
146

147
148
149
150
151

152
153
154
155
156
157
158







-
+




-
+






The code of a canvas type manager will not call these procedures
directly, but will use their addresses to create a \fBTk_CustomOption\fR
structure for the \fB\-tags\fR option.   The code typically looks
like this:
.PP
.CS
static const Tk_CustomOption tagsOption = {Tk_CanvasTagsParseProc,
    Tk_CanvasTagsPrintProc, NULL
    Tk_CanvasTagsPrintProc, (ClientData) NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    ...
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
    {TK_CONFIG_CUSTOM, "\-tags", NULL, NULL,
        NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    ...
};
.CE
.SH KEYWORDS
canvas, focus, item type, redisplay, selection, type manager

Changes to doc/CanvTxtInfo.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-
















-
+







Tk_CanvasTextInfo \- additional information for managing text items in canvases
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_CanvasTextInfo *
\fBTk_CanvasGetTextInfo\fR(\fIcanvas\fR)
.fi
.SH ARGUMENTS
.AS Tk_Canvas canvas
.AP Tk_Canvas canvas in
A token that identifies a particular canvas widget.
.BE
.SH DESCRIPTION
.PP
Textual canvas items are somewhat more complicated to manage than
other items, due to things like the selection and the input focus.
\fBTk_CanvasGetTextInfo\fR may be invoked by a type manager
to obtain additional information needed for items that display text.
The return value from \fBTk_CanvasGetTextInfo\fR is a pointer to
a structure that is shared between Tk and all the items that display
text.
The structure has the following form:
.CS
typedef struct {
typedef struct Tk_CanvasTextInfo {
    Tk_3DBorder \fIselBorder\fR;
    int \fIselBorderWidth\fR;
    XColor *\fIselFgColorPtr\fR;
    Tk_Item *\fIselItemPtr\fR;
    int \fIselectFirst\fR;
    int \fIselectLast\fR;
    Tk_Item *\fIanchorItemPtr\fR;

Changes to doc/Clipboard.3.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
15
16
17
18
19
20
21

22
23
24
25
26
27
28







-







\fB#include <tk.h>\fR
.sp
int
\fBTk_ClipboardClear\fR(\fIinterp, tkwin\fR)
.sp
int
\fBTk_ClipboardAppend\fR(\fIinterp, tkwin, target, format, buffer\fR)
.fi
.SH ARGUMENTS
.AS Tk_ClipboardClear tkwin
.AP Tcl_Interp *interp in
Interpreter to use for reporting errors.
.AP Tk_Window tkwin in
Window that determines which display's clipboard to manipulate.
.AP Atom target in

Changes to doc/ClrSelect.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







.SH NAME
Tk_ClearSelection \- Deselect a selection
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_ClearSelection\fR(\fItkwin, selection\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP Tk_Window tkwin in
The selection will be cleared from the display containing this
window.
.AP Atom selection in
The name of selection to be cleared.

Changes to doc/ConfigWidg.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26

27
28
29

30
31
32
33
34
35
36
37
38
39



40
41
42
43
44
45
46
11
12
13
14
15
16
17

18
19
20

21
22
23

24
25

26

27

28
29
30
31
32
33
34
35



36
37
38
39
40
41
42
43
44
45







-
+


-
+


-
+

-
+
-

-
+







-
-
-
+
+
+







.SH NAME
Tk_ConfigureWidget, Tk_ConfigureInfo, Tk_ConfigureValue, Tk_FreeOptions \- process configuration options for widgets
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_ConfigureWidget\fR(\fIinterp, tkwin, specs, objc, objv, widgRec, flags\fR)
\fBTk_ConfigureWidget(\fIinterp, tkwin, specs, argc, argv, widgRec, flags\fB)\fR
.sp
int
\fBTk_ConfigureInfo\fR(\fIinterp, tkwin, specs, widgRec, argvName, flags\fR)
\fBTk_ConfigureInfo(\fIinterp, tkwin, specs, widgRec, argvName, flags\fB)\fR
.sp
int
\fBTk_ConfigureValue\fR(\fIinterp, tkwin, specs, widgRec, argvName, flags\fR)
\fBTk_ConfigureValue(\fIinterp, tkwin, specs, widgRec, argvName, flags\fB)\fR
.sp
\fBTk_FreeOptions\fR(\fIspecs, widgRec, display, flags\fR)
\fBTk_FreeOptions(\fIspecs, widgRec, display, flags\fB)\fR
.fi
.SH ARGUMENTS
.AS void *widgRec in/out
.AS char *widgRec in/out
.AP Tcl_Interp *interp in
Interpreter to use for returning error messages.
.AP Tk_Window tkwin in
Window used to represent widget (needed to set up X resources).
.AP "const Tk_ConfigSpec" *specs in
Pointer to table specifying legal configuration options for this
widget.
.AP Tcl_Size objc in
Number of arguments in \fIobjv\fR.
.AP "Tcl_Obj *const *" objv in
.AP int argc in
Number of arguments in \fIargv\fR.
.AP "const char" **argv in
Command-line options for configuring widget.
.AP char *widgRec in/out
Points to widget record structure.  Fields in this structure get
modified by \fBTk_ConfigureWidget\fR to hold configuration information.
.AP int flags in
If non-zero, then it specifies an OR-ed combination of flags that
control the processing of configuration information.
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86


87
88

89
90
91
92
93
94
95
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83


84
85
86

87
88
89
90
91
92
93
94







-
-
+
+











-
+





-
-
+
+

-
+







options.
.AP Display *display in
Display containing widget whose record is being freed;  needed in
order to free up resources.
.BE
.SH DESCRIPTION
.PP
Note that \fBTk_ConfigureWidget\fR should be replaced with the new
\fBTcl_Obj\fR based API, \fBTk_SetOptions\fR.  The old interface is
Note: \fBTk_ConfigureWidget\fR should be replaced with the new
\fBTcl_Obj\fR based API \fBTk_SetOptions\fR.  The old interface is
retained for backward compatibility.
.PP
\fBTk_ConfigureWidget\fR is called to configure various aspects of a
widget, such as colors, fonts, border width, etc.
It is intended as a convenience procedure to reduce the amount
of code that must be written in individual widget managers to
handle configuration information.
It is typically
invoked when widgets are created, and again when the \fBconfigure\fR
command is invoked for a widget.
Although intended primarily for widgets, \fBTk_ConfigureWidget\fR
can be used in other situations where \fIobjc-objv\fR information
can be used in other situations where \fIargc-argv\fR information
is to be used to fill in a record structure, such as configuring
graphical elements for a canvas widget or entries of a menu.
.PP
\fBTk_ConfigureWidget\fR processes
a table specifying the configuration options that are supported
(\fIspecs\fR) and a collection of command-line arguments (\fIobjc\fR and
\fIobjv\fR) to fill in fields of a record (\fIwidgRec\fR).
(\fIspecs\fR) and a collection of command-line arguments (\fIargc\fR and
\fIargv\fR) to fill in fields of a record (\fIwidgRec\fR).
It uses the option database and defaults specified in \fIspecs\fR
to fill in fields of \fIwidgRec\fR that are not specified in \fIobjv\fR.
to fill in fields of \fIwidgRec\fR that are not specified in \fIargv\fR.
\fBTk_ConfigureWidget\fR normally returns the value \fBTCL_OK\fR; in this
case it does not modify \fIinterp\fR.
If an error
occurs then \fBTCL_ERROR\fR is returned and \fBTk_ConfigureWidget\fR will
leave an error message in interpreter \fIinterp\fR's result in the standard Tcl
fashion.
In the event of an error return, some of the fields of \fIwidgRec\fR
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129

130
131
132
133
134
135
136
137

138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345


346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362


363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127

128
129
130
131
132
133
134
135

136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163


164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251

252
253
254
255

256
257
258
259
260
261

262
263
264
265
266
267

268
269
270
271
272

273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300

301
302
303
304
305
306
307

308
309
310
311
312
313

314
315
316
317
318
319

320
321
322
323
324
325


326
327
328
329
330
331
332
333
334
335

336

337
338
339
340
341


342
343
344
345
346
347
348
349

350
351
352
353
354
355
356

357
358
359
360
361
362
363







-
+












-
+




-
+







-
+






-
+








-
+











-
-
+
+
+








-














-






-










-



















-










-








-










-




-






-






-





-










-










-








-







-






-






-






-
-
+
+








-

-
+




-
-
+
+






-







-







.CS
typedef struct {
    int \fItype\fR;
    const char *\fIargvName\fR;
    const char *\fIdbName\fR;
    const char *\fIdbClass\fR;
    const char *\fIdefValue\fR;
    size_t \fIoffset\fR;
    int \fIoffset\fR;
    int \fIspecFlags\fR;
    const Tk_CustomOption *\fIcustomPtr\fR;
} \fBTk_ConfigSpec\fR;
.CE
The \fItype\fR field indicates what type of configuration option this is
(e.g. \fBTK_CONFIG_COLOR\fR for a color value, or \fBTK_CONFIG_INT\fR for
an integer value).  The \fItype\fR field indicates how to use the
value of the option (more on this below).
The \fIargvName\fR field is a string such as
.QW \-font
or
.QW \-bg ,
which is compared with the values in \fIobjv\fR (if \fIargvName\fR is
which is compared with the values in \fIargv\fR (if \fIargvName\fR is
NULL it means this is a grouped entry;  see \fBGROUPED ENTRIES\fR below).  The
\fIdbName\fR and \fIdbClass\fR fields are used to look up a value
for this option in the option database.  The \fIdefValue\fR field
specifies a default value for this configuration option if no
value is specified in either \fIobjv\fR or the option database.
value is specified in either \fIargv\fR or the option database.
\fIOffset\fR indicates where in \fIwidgRec\fR to store information
about this option, and \fIspecFlags\fR contains additional information
to control the processing of this configuration option (see FLAGS
below).
The last field, \fIcustomPtr\fR, is only used if \fItype\fR is
\fBTK_CONFIG_CUSTOM\fR;  see CUSTOM OPTION TYPES below.
.PP
\fBTk_ConfigureWidget\fR first processes \fIobjv\fR to see which
\fBTk_ConfigureWidget\fR first processes \fIargv\fR to see which
(if any) configuration options are specified there.  \fIArgv\fR
must contain an even number of fields;  the first of each pair
of fields must match the \fIargvName\fR of some entry in \fIspecs\fR
(unique abbreviations are acceptable),
and the second field of the pair contains the value for that
configuration option.  If there are entries in \fIspec\fR for which
there were no matching entries in \fIobjv\fR,
there were no matching entries in \fIargv\fR,
\fBTk_ConfigureWidget\fR uses the \fIdbName\fR and \fIdbClass\fR
fields of the \fIspecs\fR entry to probe the option database;  if
a value is found, then it is used as the value for the option.
Finally, if no entry is found in the option database, the
\fIdefValue\fR field of the \fIspecs\fR entry is used as the
value for the configuration option.  If the \fIdefValue\fR is
NULL, or if the \fBTK_CONFIG_DONT_SET_DEFAULT\fR bit is set in
\fIflags\fR, then there is no default value and this \fIspecs\fR entry
will be ignored if no value is specified in \fIobjv\fR or the
will be ignored if no value is specified in \fIargv\fR or the
option database.
.PP
Once a string value has been determined for a configuration option,
\fBTk_ConfigureWidget\fR translates the string value into a more useful
form, such as a color if \fItype\fR is \fBTK_CONFIG_COLOR\fR or an integer
if \fItype\fR is \fBTK_CONFIG_INT\fR.  This value is then stored in the
record pointed to by \fIwidgRec\fR.  This record is assumed to
contain information relevant to the manager of the widget;  its exact
type is unknown to \fBTk_ConfigureWidget\fR.  The \fIoffset\fR field
of each \fIspecs\fR entry indicates where in \fIwidgRec\fR to store
the information about this configuration option.  You should use the
\fBoffsetof\fR macro to generate \fIoffset\fR values.  The location
indicated by \fIwidgRec\fR and \fIoffset\fR will be referred to as the
\fBTk_Offset\fR macro to generate \fIoffset\fR values (see below for
a description of \fBTk_Offset\fR).  The location indicated by
\fIwidgRec\fR and \fIoffset\fR will be referred to as the
.QW target
in the descriptions below.
.PP
The \fItype\fR field of each entry in \fIspecs\fR determines what
to do with the string value of that configuration option.  The
legal values for \fItype\fR, and the corresponding actions, are:
.TP
\fBTK_CONFIG_ACTIVE_CURSOR\fR
.
The value
must be an ASCII string identifying a cursor in a form
suitable for passing to \fBTk_GetCursor\fR.
The value is converted to a \fBTk_Cursor\fR by calling
\fBTk_GetCursor\fR and the result is stored in the target.
In addition, the resulting cursor is made the active cursor
for \fItkwin\fR by calling \fBXDefineCursor\fR.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target and \fItkwin\fR's
active cursor will be set to \fBNone\fR.
If the previous value of the target
was not \fBNone\fR, then it is freed by passing it to \fBTk_FreeCursor\fR.
.TP
\fBTK_CONFIG_ANCHOR\fR
.
The value must be an ASCII string identifying an anchor point in one of the ways
accepted by \fBTk_GetAnchor\fR.
The string is converted to a \fBTk_Anchor\fR by calling
\fBTk_GetAnchor\fR and the result is stored in the target.
.TP
\fBTK_CONFIG_BITMAP\fR
.
The value must be an ASCII string identifying a bitmap in a form
suitable for passing to \fBTk_GetBitmap\fR.  The value is converted
to a \fBPixmap\fR by calling \fBTk_GetBitmap\fR and the result
is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target is set to \fBNone\fR.
If the previous value of the target
was not \fBNone\fR, then it is freed by passing it to \fBTk_FreeBitmap\fR.
.TP
\fBTK_CONFIG_BOOLEAN\fR
.
The value must be an ASCII string specifying a boolean value.  Any
of the values
.QW true ,
.QW yes ,
.QW on ,
or
.QW 1 ,
or an abbreviation of one of these values, means true;
any of the values
.QW false ,
.QW no ,
.QW off ,
or
.QW 0 ,
or an abbreviation of one of these values, means false.
The target is expected to be an integer;  for true values it will
be set to 1 and for false values it will be set to 0.
.TP
\fBTK_CONFIG_BORDER\fR
.
The value must be an ASCII string identifying a border color in a form
suitable for passing to \fBTk_Get3DBorder\fR.  The value is converted
to a (\fBTk_3DBorder *\fR) by calling \fBTk_Get3DBorder\fR and the result
is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target will be set to NULL.
If the previous value of the target
was not NULL, then it is freed by passing it to \fBTk_Free3DBorder\fR.
.TP
\fBTK_CONFIG_CAP_STYLE\fR
.
The value must be
an ASCII string identifying a cap style in one of the ways
accepted by \fBTk_GetCapStyle\fR.
The string is converted to an integer value corresponding
to the cap style by calling
\fBTk_GetCapStyle\fR and the result is stored in the target.
.TP
\fBTK_CONFIG_COLOR\fR
.
The value must be an ASCII string identifying a color in a form
suitable for passing to \fBTk_GetColor\fR.  The value is converted
to an (\fBXColor *\fR) by calling \fBTk_GetColor\fR and the result
is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target will be set to \fBNone\fR.
If the previous value of the target
was not NULL, then it is freed by passing it to \fBTk_FreeColor\fR.
.TP
\fBTK_CONFIG_CURSOR\fR
.
This option is identical to \fBTK_CONFIG_ACTIVE_CURSOR\fR except
that the new cursor is not made the active one for \fItkwin\fR.
.TP
\fBTK_CONFIG_CUSTOM\fR
.
This option allows applications to define new option types.
The \fIcustomPtr\fR field of the entry points to a structure
defining the new option type.
See the section \fBCUSTOM OPTION TYPES\fR below for details.
.TP
\fBTK_CONFIG_DOUBLE\fR
.
The value must be an ASCII floating-point number in
the format accepted by \fBstrtol\fR.  The string is converted
to a \fBdouble\fR value, and the value is stored in the
target.
.TP
\fBTK_CONFIG_END\fR
.
Marks the end of the table.  The last entry in \fIspecs\fR
must have this type;  all of its other fields are ignored and it
will never match any arguments.
.TP
\fBTK_CONFIG_FONT\fR
.
The value must be an ASCII string identifying a font in a form
suitable for passing to \fBTk_GetFont\fR.  The value is converted
to a \fBTk_Font\fR by calling \fBTk_GetFont\fR and the result
is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target will be set to NULL.
If the previous value of the target
was not NULL, then it is freed by passing it to \fBTk_FreeFont\fR.
.TP
\fBTK_CONFIG_INT\fR
.
The value must be an ASCII integer string
in the format accepted by \fBstrtol\fR (e.g.
.QW 0
and
.QW 0x
prefixes may be used to specify octal or hexadecimal
numbers, respectively).  The string is converted to an integer
value and the integer is stored in the target.
.TP
\fBTK_CONFIG_JOIN_STYLE\fR
.
The value must be
an ASCII string identifying a join style in one of the ways
accepted by \fBTk_GetJoinStyle\fR.
The string is converted to an integer value corresponding
to the join style by calling
\fBTk_GetJoinStyle\fR and the result is stored in the target.
.TP
\fBTK_CONFIG_JUSTIFY\fR
.
The value must be
an ASCII string identifying a justification method in one of the
ways accepted by \fBTk_GetJustify\fR.
The string is converted to a \fBTk_Justify\fR by calling
\fBTk_GetJustify\fR and the result is stored in the target.
.TP
\fBTK_CONFIG_MM\fR
.
The value must specify a screen distance in one of the forms acceptable
to \fBTk_GetScreenMM\fR.
The string is converted to double-precision floating-point distance
in millimeters and the value is stored in the target.
.TP
\fBTK_CONFIG_PIXELS\fR
.
The value must specify screen units in one of the forms acceptable
to \fBTk_GetPixels\fR.
The string is converted to an integer distance in pixels and the
value is stored in the target.
.TP
\fBTK_CONFIG_RELIEF\fR
.
The value must be an ASCII string identifying a relief in a form
suitable for passing to \fBTk_GetRelief\fR.  The value is converted
to an integer relief value by calling \fBTk_GetRelief\fR and the result
is stored in the target.
.TP
\fBTK_CONFIG_STRING\fR
.
A copy of the value is made by allocating memory space with
A copy
of the value is made by allocating memory space with
\fBTcl_Alloc\fR and copying the value into the dynamically-allocated
space.  A pointer to the new string is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR then the value
may be an empty string, in which case the target will be set to NULL.
If the previous value of the target was not NULL, then it is
freed by passing it to \fBTcl_Free\fR.
.TP
\fBTK_CONFIG_SYNONYM\fR
.
This \fItype\fR value identifies special entries in \fIspecs\fR that
are synonyms for other entries.  If an \fIobjv\fR value matches the
are synonyms for other entries.  If an \fIargv\fR value matches the
\fIargvName\fR of a \fBTK_CONFIG_SYNONYM\fR entry, the entry is not used
directly. Instead, \fBTk_ConfigureWidget\fR searches \fIspecs\fR
for another entry whose \fIargvName\fR is the same as the \fIdbName\fR
field in the \fBTK_CONFIG_SYNONYM\fR entry;  this new entry is used just
as if its \fIargvName\fR had matched the \fIobjv\fR value.  The
synonym mechanism allows multiple \fIobjv\fR values to be used for
as if its \fIargvName\fR had matched the \fIargv\fR value.  The
synonym mechanism allows multiple \fIargv\fR values to be used for
a single configuration option, such as
.QW \-background
and
.QW \-bg .
.TP
\fBTK_CONFIG_UID\fR
.
The value is translated to a \fBTk_Uid\fR
(by passing it to \fBTk_GetUid\fR).  The resulting value
is stored in the target.
If \fBTK_CONFIG_NULL_OK\fR is specified in \fIspecFlags\fR and the value
is an empty string then the target will be set to NULL.
.TP
\fBTK_CONFIG_WINDOW\fR
.
The value must be a window path name.  It is translated to a
\fBTk_Window\fR token and the token is stored in the target.
.SH "GROUPED ENTRIES"
.PP
In some cases it is useful to generate multiple resources from
a single configuration value.  For example, a color name might
be used both to generate the background color for a widget (using
399
400
401
402
403
404
405
406

407
408
409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457








458
459
460
461
462
463
464
378
379
380
381
382
383
384

385

386
387

388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403

404
405
406
407
408

409
410
411
412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446







-
+
-


-
+










-





-





-













-










+
+
+
+
+
+
+
+







The \fIflags\fR argument passed to \fBTk_ConfigureWidget\fR is used
in conjunction with the \fIspecFlags\fR fields in the entries of \fIspecs\fR
to provide additional control over the processing of configuration
options.  These values are used in three different ways as
described below.
.PP
First, if the \fIflags\fR argument to \fBTk_ConfigureWidget\fR has
the \fBTK_CONFIG_ARGV_ONLY\fR bit set
the \fBTK_CONFIG_ARGV_ONLY\fR bit set (i.e., \fIflags\fR | \fBTK_CONFIG_ARGV_ONLY\fR != 0),
(i.e., \fIflags\fR | \fBTK_CONFIG_ARGV_ONLY\fR != 0),
then the option database and
\fIdefValue\fR fields are not used.  In this case, if an entry in
\fIspecs\fR does not match a field in \fIobjv\fR then nothing happens:
\fIspecs\fR does not match a field in \fIargv\fR then nothing happens:
the corresponding target is not modified.  This feature is useful
when the goal is to modify certain configuration options while
leaving others in their current state, such as when a \fBconfigure\fR
widget command is being processed.
.PP
Second, the \fIspecFlags\fR field of an entry in \fIspecs\fR may be used
to control the processing of that entry.  Each \fIspecFlags\fR
field may consists of an OR-ed combination of the following values:
.TP
\fBTK_CONFIG_COLOR_ONLY\fR
.
If this bit is set then the entry will only be considered if the
display for \fItkwin\fR has more than one bit plane.  If the display
is monochromatic then this \fIspecs\fR entry will be ignored.
.TP
\fBTK_CONFIG_MONO_ONLY\fR
.
If this bit is set then the entry will only be considered if the
display for \fItkwin\fR has exactly one bit plane.  If the display
is not monochromatic then this \fIspecs\fR entry will be ignored.
.TP
\fBTK_CONFIG_NULL_OK\fR
.
This bit is only relevant for some types of entries (see the
descriptions of the various entry types above).
If this bit is set, it indicates that an empty string value
for the field is acceptable and if it occurs then the
target should be set to NULL or \fBNone\fR, depending
on the type of the target.
This flag is typically used to allow a
feature to be turned off entirely, e.g. set a cursor value to
\fBNone\fR so that a window simply inherits its parent's cursor.
If this bit is not set then empty strings are processed as strings,
which generally results in an error.
.TP
\fBTK_CONFIG_DONT_SET_DEFAULT\fR
.
If this bit is one, it means that the \fIdefValue\fR field of the
entry should only be used for returning the default value in
\fBTk_ConfigureInfo\fR.
In calls to \fBTk_ConfigureWidget\fR no default will be supplied
for entries with this flag set;  it is assumed that the
caller has already supplied a default value in the target location.
This flag provides a performance optimization where it is expensive
to process the default string:  the client can compute the default
once, save the value, and provide it before calling
\fBTk_ConfigureWidget\fR.
.TP
\fBTK_CONFIG_OPTION_SPECIFIED\fR
This bit is
deprecated. It used to be set and cleared by \fBTk_ConfigureWidget\fR
so that callers could detect what entries were specified in
\fIargv\fR, but it was removed because it was inherently
thread-unsafe. Code that wishes to detect what options were specified
should use \fBTk_SetOptions\fR instead.
.PP
The \fBTK_CONFIG_MONO_ONLY\fR and \fBTK_CONFIG_COLOR_ONLY\fR flags are typically
used to specify different default values for
monochrome and color displays.  This is done by creating two
entries in \fIspecs\fR that are identical except for their
\fIdefValue\fR and \fIspecFlags\fR fields.  One entry should have
the value \fBTK_CONFIG_MONO_ONLY\fR in its \fIspecFlags\fR and the
483
484
485
486
487
488
489







490
491
492
493
494
495
496
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485







+
+
+
+
+
+
+







for N different widget types, then N of the high-order bits will
be used.  Each \fIspecs\fR entry will have one of more of those
bits set in its \fIspecFlags\fR field to indicate the widget types
for which this entry is valid.  When calling \fBTk_ConfigureWidget\fR,
\fIflags\fR will have a single one of these bits set to select the
entries for the desired widget type.  For a working example of
this feature, see the code in tkButton.c.
.SH TK_OFFSET
.PP
The \fBTk_Offset\fR macro is provided as a safe way of generating
the \fIoffset\fR values for entries in Tk_ConfigSpec structures.
It takes two arguments:  the name of a type of record, and the
name of a field in that record.  It returns the byte offset of
the named field in records of the given type.
.SH TK_CONFIGUREINFO
.PP
The \fBTk_ConfigureInfo\fR procedure may be used to obtain
information about one or all of the options for a given widget.
Given a token for a window (\fItkwin\fR), a table describing the
configuration options for a class of widgets (\fIspecs\fR), a
pointer to a widget record containing the current information for
548
549
550
551
552
553
554
555

556
557
558

559
560
561
562

563
564
565
566
567

568
569
570

571
572
573

574
575
576
577
578
579
580
537
538
539
540
541
542
543

544
545
546

547
548
549
550

551
552
553
554
555

556
557
558

559
560
561

562
563
564
565
566
567
568
569







-
+


-
+



-
+




-
+


-
+


-
+







corresponding field of the widget record to null.
.SH "CUSTOM OPTION TYPES"
.PP
Applications can extend the built-in configuration types with additional
configuration types by writing procedures to parse and print options
of the a type and creating a structure pointing to those procedures:
.CS
typedef struct {
typedef struct Tk_CustomOption {
    Tk_OptionParseProc *\fIparseProc\fR;
    Tk_OptionPrintProc *\fIprintProc\fR;
    void *\fIclientData\fR;
    ClientData \fIclientData\fR;
} \fBTk_CustomOption\fR;

typedef int \fBTk_OptionParseProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        Tcl_Interp *\fIinterp\fR,
        Tk_Window \fItkwin\fR,
        char *\fIvalue\fR,
        char *\fIwidgRec\fR,
        Tcl_Size \fIoffset\fR);
        int \fIoffset\fR);

typedef const char *\fBTk_OptionPrintProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        Tk_Window \fItkwin\fR,
        char *\fIwidgRec\fR,
        Tcl_Size \fIoffset\fR,
        int \fIoffset\fR,
        Tcl_FreeProc **\fIfreeProcPtr\fR);
.CE
The Tk_CustomOption structure contains three fields, which are pointers
to the two procedures and a \fIclientData\fR value to be passed to those
procedures when they are invoked.  The \fIclientData\fR value typically
points to a structure containing information that is needed by the
procedures when they are parsing and printing options.

Changes to doc/ConfigWind.3.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48







-







\fBTk_SetWindowBorderPixmap\fR(\fItkwin, pixmap\fR)
.sp
\fBTk_SetWindowColormap\fR(\fItkwin, colormap\fR)
.sp
\fBTk_DefineCursor\fR(\fItkwin, cursor\fR)
.sp
\fBTk_UndefineCursor\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS XSetWindowAttributes borderWidth
.AP Tk_Window tkwin in
Token for window.
.AP "unsigned int" valueMask in
OR-ed mask of values like \fBCWX\fR or \fBCWBorderPixel\fR,
indicating which fields of \fI*valuePtr\fR or \fI*attsPtr\fR to use.

Changes to doc/CoordToWin.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_CoordsToWindow \- Find window containing a point
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Window
\fBTk_CoordsToWindow\fR(\fIrootX, rootY, tkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP int rootX in
X-coordinate (in root window coordinates).
.AP int rootY in
Y-coordinate (in root window coordinates).
.AP Tk_Window tkwin in

Changes to doc/CrtCmHdlr.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-















-
+







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateClientMessageHandler\fR(\fIproc\fR)
.sp
\fBTk_DeleteClientMessageHandler\fR(\fIproc\fR)
.fi
.SH ARGUMENTS
.AP Tk_ClientMessageProc *proc in
Procedure to invoke whenever a ClientMessage X event occurs on any display.
.BE
.SH DESCRIPTION
.PP
\fBTk_CreateClientMessageHandler\fR arranges for \fIproc\fR to be invoked
in the future whenever a ClientMessage X event occurs that is not handled by
\fBWM_PROTOCOL\fR.  \fBTk_CreateClientMessageHandler\fR is intended for use
by applications which need to watch X ClientMessage events, such as drag and
drop applications.
.PP
The callback to \fIproc\fR will be made by \fBTk_HandleEvent\fR;
this mechanism only works in programs that dispatch events
through \fBTk_HandleEvent\fR (or through other Tk procedures that
call \fBTk_HandleEvent\fR, such as \fBTcl_DoOneEvent\fR or
call \fBTk_HandleEvent\fR, such as \fBTk_DoOneEvent\fR or
\fBTk_MainLoop\fR).
.PP
\fIProc\fR should have arguments and result that match the
type \fBTk_ClientMessageProc\fR:
.CS
typedef int \fBTk_ClientMessageProc\fR(
        Tk_Window \fItkwin\fR,

Changes to doc/CrtConsoleChan.3.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
10
11
12
13
14
15
16

17
18
19
20
21
22
23







-







.SH NAME
Tk_InitConsoleChannels \- Install the console channels as standard channels
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_InitConsoleChannels\fR(\fIinterp\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Interp *interp in
.AP Tcl_Interp *interp in
Interpreter in which the console channels are created.
.BE
.SH DESCRIPTION
.PP

Changes to doc/CrtErrHdlr.3.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45







-

















-
+







.nf
\fB#include <tk.h>\fR
.sp
Tk_ErrorHandler
\fBTk_CreateErrorHandler\fR(\fIdisplay, error, request, minor, proc, clientData\fR)
.sp
\fBTk_DeleteErrorHandler\fR(\fIhandler\fR)
.fi
.SH ARGUMENTS
.AS "Tk_ErrorHandler" clientData
.AP Display *display in
Display whose errors are to be handled.
.AP int error in
Match only error events with this value in the \fIerror_code\fR
field.  If \-1, then match any \fIerror_code\fR value.
.AP int request in
Match only error events with this value in the \fIrequest_code\fR
field.  If \-1, then match any \fIrequest_code\fR value.
.AP int minor in
Match only error events with this value in the \fIminor_code\fR
field.  If \-1, then match any \fIminor_code\fR value.
.AP Tk_ErrorProc *proc in
Procedure to invoke whenever an error event is received for
\fIdisplay\fR and matches \fIerror\fR, \fIrequest\fR, and \fIminor\fR.
NULL means ignore any matching errors.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.AP Tk_ErrorHandler handler in
Token for error handler to delete (return value from a previous
call to \fBTk_CreateErrorHandler\fR).
.BE
.SH DESCRIPTION
.PP
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+







The protocol request to which the error pertains must have been
made when the handler was active (see below for more information).
.PP
\fIProc\fR should have arguments and result that match the
following type:
.CS
typedef int \fBTk_ErrorProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        XErrorEvent *\fIerrEventPtr\fR);
.CE
The \fIclientData\fR parameter to \fIproc\fR is a copy of the \fIclientData\fR
argument given to \fBTcl_CreateErrorHandler\fR when the callback
was created.  Typically, \fIclientData\fR points to a data
structure containing application-specific information that is
needed to deal with the error.  \fIErrEventPtr\fR is

Changes to doc/CrtGenHdlr.3.

13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49

50
51
52
53
54
55
56
13
14
15
16
17
18
19

20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47

48
49
50
51
52
53
54
55







-




-
+
















-
+






-
+







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateGenericHandler\fR(\fIproc, clientData\fR)
.sp
\fBTk_DeleteGenericHandler\fR(\fIproc, clientData\fR)
.fi
.SH ARGUMENTS
.AS "Tk_GenericProc" clientData
.AP Tk_GenericProc *proc in
Procedure to invoke whenever any X event occurs on any display.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.BE
.SH DESCRIPTION
.PP
\fBTk_CreateGenericHandler\fR arranges for \fIproc\fR to be
invoked in the future whenever any X event occurs.  This mechanism is
\fInot\fR intended for dispatching X events on windows managed by Tk
(you should use \fBTk_CreateEventHandler\fR for this purpose).
\fBTk_CreateGenericHandler\fR is intended for other purposes, such
as tracing X events, monitoring events on windows not owned by Tk,
accessing X-related libraries that were not originally designed for
use with Tk, and so on.
.PP
The callback to \fIproc\fR will be made by \fBTk_HandleEvent\fR;
this mechanism only works in programs that dispatch events
through \fBTk_HandleEvent\fR (or through other Tk procedures that
call \fBTk_HandleEvent\fR, such as \fBTcl_DoOneEvent\fR or
call \fBTk_HandleEvent\fR, such as \fBTk_DoOneEvent\fR or
\fBTk_MainLoop\fR).
.PP
\fIProc\fR should have arguments and result that match the
type \fBTk_GenericProc\fR:
.CS
typedef int \fBTk_GenericProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        XEvent *\fIeventPtr\fR);
.CE
The \fIclientData\fR parameter to \fIproc\fR is a copy of the \fIclientData\fR
argument given to \fBTk_CreateGenericHandler\fR when the callback
was created.  Typically, \fIclientData\fR points to a data
structure containing application-specific information about
how to handle events.

Changes to doc/CrtImgType.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21




22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45











-
+






-
-
-
+
+
+
+














+
+







'\"
'\" Copyright (c) 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.
'\"
.TH Tk_CreateImageType 3 8.5 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_CreateImageType, Tk_GetImageModelData \- define new kind of image
Tk_CreateImageType, Tk_GetImageMasterData, Tk_InitImageArgs \- define new kind of image
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateImageType\fR(\fItypePtr\fR)
.sp
void *
\fBTk_GetImageModelData\fR(\fIinterp, name, typePtrPtr\fR)
.fi
ClientData
\fBTk_GetImageMasterData\fR(\fIinterp, name, typePtrPtr\fR)
.sp
\fBTk_InitImageArgs\fR(\fIinterp, argc, argvPtr\fR)
.SH ARGUMENTS
.AS "const Tk_ImageType" *typePtrPtr
.AP "const Tk_ImageType" *typePtr in
Structure that defines the new type of image.
For Tk 8.4 and earlier this must be static: a
pointer to this structure is retained by the image code.
In Tk 8.5, this limitation was relaxed.
.AP Tcl_Interp *interp in
Interpreter in which image was created.
.AP "const char" *name in
Name of existing image.
.AP Tk_ImageType **typePtrPtr out
Points to word in which to store a pointer to type information for
the given image, if it exists.
.AP int argc in
Number of arguments
.AP char ***argvPtr in/out
Pointer to argument list
.BE
.SH DESCRIPTION
.PP
\fBTk_CreateImageType\fR is invoked to define a new kind of image.
An image type corresponds to a particular value of the \fItype\fR
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+












-
+







\fIimage manager\fR.
It consists of a collection of procedures plus three different
kinds of data structures.
The first data structure is a Tk_ImageType structure, which contains
the name of the image type and pointers to five procedures provided
by the image manager to deal with images of this type:
.CS
typedef struct {
typedef struct Tk_ImageType {
    const char *\fIname\fR;
    Tk_ImageCreateProc *\fIcreateProc\fR;
    Tk_ImageGetProc *\fIgetProc\fR;
    Tk_ImageDisplayProc *\fIdisplayProc\fR;
    Tk_ImageFreeProc *\fIfreeProc\fR;
    Tk_ImageDeleteProc *\fIdeleteProc\fR;
} \fBTk_ImageType\fR;
.CE
The fields of this structure will be described in later subsections
of this entry.
.PP
The second major data structure manipulated by an image manager
is called an \fIimage model\fR;  it contains overall information
is called an \fIimage master\fR;  it contains overall information
about a particular image, such as the values of the configuration
options specified in an \fBimage create\fR command.
There will usually be one of these structures for each
invocation of the \fBimage create\fR command.
.PP
The third data structure related to images is an \fIimage instance\fR.
There will usually be one of these structures for each usage of an
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
122
123

124
125
126
127

128
129

130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148

149
150
151
152


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
109
110
111
112
113
114
115


116
117
118
119
120
121
122
123
124
125

126
127
128
129

130
131

132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150

151
152
153


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177







-
-
+
+








-
+



-
+

-
+

-
+














-
+

-
+


-
-
+
+














-
+







.CS
typedef int \fBTk_ImageCreateProc\fR(
        Tcl_Interp *\fIinterp\fR,
        const char *\fIname\fR,
        int \fIobjc\fR,
        Tcl_Obj *const \fIobjv\fR[],
        const Tk_ImageType *\fItypePtr\fR,
        Tk_ImageModel \fImodel\fR,
        void **\fImodelDataPtr\fR);
        Tk_ImageMaster \fImaster\fR,
        ClientData *\fImasterDataPtr\fR);
.CE
The \fIinterp\fR argument is the interpreter in which the \fBimage\fR
command was invoked, and \fIname\fR is the name for the new image,
which was either specified explicitly in the \fBimage\fR command
or generated automatically by the \fBimage\fR command.
The \fIobjc\fR and \fIobjv\fR arguments describe all the configuration
options for the new image (everything after the name argument to
\fBimage\fR).
The \fImodel\fR argument is a token that refers to Tk's information
The \fImaster\fR argument is a token that refers to Tk's information
about this image;  the image manager must return this token to
Tk when invoking the \fBTk_ImageChanged\fR procedure.
Typically \fIcreateProc\fR will parse \fIobjc\fR and \fIobjv\fR
and create an image model data structure for the new image.
and create an image master data structure for the new image.
\fIcreateProc\fR may store an arbitrary one-word value at
*\fImodelDataPtr\fR, which will be passed back to the
*\fImasterDataPtr\fR, which will be passed back to the
image manager when other callbacks are invoked.
Typically the value is a pointer to the model data
Typically the value is a pointer to the master data
structure for the image.
.PP
If \fIcreateProc\fR encounters an error, it should leave an error
message in the interpreter result and return \fBTCL_ERROR\fR;  otherwise
it should return \fBTCL_OK\fR.
.PP
\fIcreateProc\fR should call \fBTk_ImageChanged\fR in order to set the
size of the image and request an initial redisplay.
.SS GETPROC
.PP
\fItypePtr->getProc\fR is invoked by Tk whenever a widget
calls \fBTk_GetImage\fR to use a particular image.
This procedure must match the following prototype:
.CS
typedef void *\fBTk_ImageGetProc\fR(
typedef ClientData \fBTk_ImageGetProc\fR(
        Tk_Window \fItkwin\fR,
        void *\fImodelData\fR);
        ClientData \fImasterData\fR);
.CE
The \fItkwin\fR argument identifies the window in which the
image will be used and \fImodelData\fR is the value
returned by \fIcreateProc\fR when the image model was created.
image will be used and \fImasterData\fR is the value
returned by \fIcreateProc\fR when the image master was created.
\fIgetProc\fR will usually create a data structure for the new
instance, including such things as the resources needed to
display the image in the given window.
\fIgetProc\fR returns a one-word token for the instance, which
is typically the address of the instance data structure.
Tk will pass this value back to the image manager when invoking
its \fIdisplayProc\fR and \fIfreeProc\fR procedures.
.SS DISPLAYPROC
.PP
\fItypePtr->displayProc\fR is invoked by Tk whenever an image needs
to be displayed (i.e., whenever a widget calls \fBTk_RedrawImage\fR).
\fIdisplayProc\fR must match the following prototype:
.CS
typedef void \fBTk_ImageDisplayProc\fR(
        void *\fIinstanceData\fR,
        ClientData \fIinstanceData\fR,
        Display *\fIdisplay\fR,
        Drawable \fIdrawable\fR,
        int \fIimageX\fR,
        int \fIimageY\fR,
        int \fIwidth\fR,
        int \fIheight\fR,
        int \fIdrawableX\fR,
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224


225
226
227
228

229
230

231
232

233
234
235
236
237

238
239

240




































241
242
243
244

199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225


226
227
228
229
230

231
232

233
234

235
236
237
238
239

240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

283







-
+

















-
+

-
-
+
+



-
+

-
+

-
+




-
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+
\fBTk_FreeImage\fR is invoked).
This can happen, for example, when a widget is deleted or a image item
in a canvas is deleted, or when the image displayed in a widget or
canvas item is changed.
\fIfreeProc\fR must match the following prototype:
.CS
typedef void \fBTk_ImageFreeProc\fR(
        void *\fIinstanceData\fR,
        ClientData \fIinstanceData\fR,
        Display *\fIdisplay\fR);
.CE
The \fIinstanceData\fR will be the same as the value returned by
\fIgetProc\fR when the instance was created, and \fIdisplay\fR
is the display containing the window for the instance.
\fIfreeProc\fR should release any resources associated with the
image instance, since the instance will never be used again.
.SS DELETEPROC
.PP
\fItypePtr->deleteProc\fR is a procedure that Tk invokes when an
image is being deleted (i.e. when the \fBimage delete\fR command
is invoked).
Before invoking \fIdeleteProc\fR Tk will invoke \fIfreeProc\fR for
each of the image's instances.
\fIdeleteProc\fR must match the following prototype:
.CS
typedef void \fBTk_ImageDeleteProc\fR(
        void *\fImodelData\fR);
        ClientData \fImasterData\fR);
.CE
The \fImodelData\fR argument will be the same as the value
stored in \fI*modelDataPtr\fR by \fIcreateProc\fR when the
The \fImasterData\fR argument will be the same as the value
stored in \fI*masterDataPtr\fR by \fIcreateProc\fR when the
image was created.
\fIdeleteProc\fR should release any resources associated with
the image.
.SH TK_GETIMAGEMODELDATA
.SH TK_GETIMAGEMASTERDATA
.PP
The procedure \fBTk_GetImageModelData\fR may be invoked to retrieve
The procedure \fBTk_GetImageMasterData\fR may be invoked to retrieve
information about an image.  For example, an image manager can use this
procedure to locate its image model data for an image.
procedure to locate its image master data for an image.
If there exists an image named \fIname\fR
in the interpreter given by \fIinterp\fR, then \fI*typePtrPtr\fR is
filled in with type information for the image (the \fItypePtr\fR value
passed to \fBTk_CreateImageType\fR when the image type was registered)
and the return value is the clientData value returned by the
and the return value is the ClientData value returned by the
\fIcreateProc\fR when the image was created (this is typically a
pointer to the image model data structure).  If no such image exists
pointer to the image master data structure).  If no such image exists
then NULL is returned and NULL is stored at \fI*typePtrPtr\fR.
.SH "LEGACY INTERFACE SUPPORT"
.PP
In Tk 8.2 and earlier, the definition of \fBTk_ImageCreateProc\fR
was incompatibly different, with the following prototype:
.CS
typedef int \fBTk_ImageCreateProc\fR(
        Tcl_Interp *\fIinterp\fR,
        char *\fIname\fR,
        int \fIargc\fR,
        char **\fIargv\fR,
        Tk_ImageType *\fItypePtr\fR,
        Tk_ImageMaster \fImaster\fR,
        ClientData *\fImasterDataPtr\fR);
.CE
Legacy programs and libraries dating from those days may still
contain code that defines extended Tk image types using the old
interface.  The Tk header file will still support this legacy
interface if the code is compiled with the macro \fBUSE_OLD_IMAGE\fR
defined.
.PP
When the \fBUSE_OLD_IMAGE\fR legacy support is enabled, you may
see the routine \fBTk_InitImageArgs\fR in use.  This was a migration
tool used to create stub-enabled extensions that could be loaded
into interps containing all versions of Tk 8.1 and later.  Tk 8.5 no longer
provides this routine, but uses a macro to convert any attempted
calls of this routine into an empty comment.  Any stub-enabled
extension providing an extended image type via the legacy interface
that is compiled against Tk 8.5 headers and linked against the
Tk 8.5 stub library will produce a file that can be loaded only
into interps with Tk 8.5 or later; that is, the normal stub-compatibility
rules.  If a developer needs to generate from such code a file
that is loadable into interps with Tk 8.4 or earlier, they must
use Tk 8.4 headers and stub libraries to do so.
.PP
Any new code written today should not make use of the legacy
interfaces.  Expect their support to go away in Tk 9.
.SH "SEE ALSO"
Tk_ImageChanged, Tk_GetImage, Tk_FreeImage, Tk_RedrawImage, Tk_SizeOfImage
.SH KEYWORDS
image manager, image type, instance, model
image manager, image type, instance, master

Changes to doc/CrtItemType.3.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
13
14
15
16
17
18
19

20
21
22
23

24
25
26
27
28
29
30







-




-







.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateItemType\fR(\fItypePtr\fR)
.sp
Tk_ItemType *
\fBTk_GetItemTypes\fR()
.fi
.SH ARGUMENTS
.AS Tk_ItemType *typePtr
.AP Tk_ItemType *typePtr in
Structure that defines the new type of canvas item.
Note that this is not \fIconst\fR; Tk may write to these structures.
.BE
.SH INTRODUCTION
.PP
\fBTk_CreateItemType\fR is invoked to define a new kind of canvas item
described by the \fItypePtr\fR argument.
An item type corresponds to a particular value of the \fItype\fR
argument to the \fBcreate\fR widget command for canvases, and
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
60
61
62
63
64
65
66

67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84

85



86
87
88
89
90
91
92







-
+






-
+










-
+
-
-
-







The first data structure is a Tk_ItemType; it contains
information such as the name of the type and pointers to
the standard procedures implemented by the type manager:
.PP
.CS
typedef struct Tk_ItemType {
    const char *\fIname\fR;
    size_t \fIitemSize\fR;
    int \fIitemSize\fR;
    Tk_ItemCreateProc *\fIcreateProc\fR;
    const Tk_ConfigSpec *\fIconfigSpecs\fR;
    Tk_ItemConfigureProc *\fIconfigProc\fR;
    Tk_ItemCoordProc *\fIcoordProc\fR;
    Tk_ItemDeleteProc *\fIdeleteProc\fR;
    Tk_ItemDisplayProc *\fIdisplayProc\fR;
    int \fIflags\fR;
    int \fIalwaysRedraw\fR;
    Tk_ItemPointProc *\fIpointProc\fR;
    Tk_ItemAreaProc *\fIareaProc\fR;
    Tk_ItemPostscriptProc *\fIpostscriptProc\fR;
    Tk_ItemScaleProc *\fIscaleProc\fR;
    Tk_ItemTranslateProc *\fItranslateProc\fR;
    Tk_ItemIndexProc *\fIindexProc\fR;
    Tk_ItemCursorProc *\fIicursorProc\fR;
    Tk_ItemSelectionProc *\fIselectionProc\fR;
    Tk_ItemInsertProc *\fIinsertProc\fR;
    Tk_ItemDCharsProc *\fIdCharsProc\fR;
    struct Tk_ItemType *\fInextPtr\fR;
    Tk_ItemType *\fInextPtr\fR;
.VS "8.7, TIP164"
    Tk_ItemRotateProc *\fIrotateProc\fR;
.VE "8.7, TIP164"
} \fBTk_ItemType\fR;
.CE
.PP
The fields of a Tk_ItemType structure are described in more detail
later in this manual entry.
When \fBTk_CreateItemType\fR is called, its \fItypePtr\fR
argument must point to a structure with all of the fields initialized
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+







defined by Tk via the type Tk_Item; the rest of the item
record is defined by the type manager.
A type manager must define its item records with a Tk_Item as
the first field.
For example, the item record for bitmap items is defined as follows:
.PP
.CS
typedef struct {
typedef struct BitmapItem {
    Tk_Item \fIheader\fR;
    double \fIx\fR, \fIy\fR;
    Tk_Anchor \fIanchor\fR;
    Pixmap \fIbitmap\fR;
    XColor *\fIfgColor\fR;
    XColor *\fIbgColor\fR;
    GC \fIgc\fR;
167
168
169
170
171
172
173
174

175
176
177
178

179
180
181
182
183








184
185
186
187
188
189
190
162
163
164
165
166
167
168

169
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193







-
+



-
+





+
+
+
+
+
+
+
+







Once \fBTk_CreateImageType\fR returns, this name may be used
in \fBcreate\fR widget commands to create items of the new
type.
If there already existed an item type by this name then
the new item type replaces the old one.
.SS "FLAGS (IN ALWAYSREDRAW)"
.PP
The \fItypePtr\->flags\fR field
The \fItypePtr\->alwaysRedraw\fR field (so named for historic reasons)
contains a collection of flag bits that modify how the canvas core interacts
with the item. The following bits are defined:
.TP
\fBTK_ALWAYS_REDRAW\fR
\fB1\fR
.
Indicates that the item should always be redrawn when any part of the canvas
is redrawn, rather than only when the bounding box of the item overlaps the
area being redrawn. This is used by window items, for example, which need to
unmap subwindows that are not on the screen.
.TP
\fBTK_CONFIG_OBJS\fR
.
Indicates that operations which would otherwise take a string (or array of
strings) actually take a Tcl_Obj reference (or an array of such references).
The operations to which this applies are the \fIconfigProc\fR, the
\fIcoordProc\fR, the \fIcreateProc\fR, the \fIindexProc\fR and the
\fIinsertProc\fR.
.TP
\fBTK_MOVABLE_POINTS\fR
.VS 8.6
Indicates that the item supports the \fIdCharsProc\fR, \fIindexProc\fR and
\fIinsertProc\fR with the same semantics as Tk's built-in line and polygon
types, and that hence individual coordinate points can be moved. Must not be
set if any of the above methods is NULL.
219
220
221
222
223
224
225



226
227
228
229
230
231
232
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238







+
+
+







\fIitemPtr\fR is a pointer to a newly-allocated item of
size \fItypePtr\->itemSize\fR.
Tk has already initialized the item's header (the first
\fBsizeof(Tk_ItemType)\fR bytes).
The \fIobjc\fR and \fIobjv\fR arguments describe all of the
arguments to the \fBcreate\fR command after the \fItype\fR
argument.
Note that if \fBTK_CONFIG_OBJS\fR is not set in the
\fItypePtr\->alwaysRedraw\fR field, the \fIobjv\fR parameter will actually
contain a pointer to an array of constant strings.
For example, in the widget command:
.PP
.CS
\fB\&.c create rectangle 10 20 50 50 \-fill black\fR
.CE
.PP
\fIobjc\fR will be \fB6\fR and \fIobjv\fR[0] will contain the
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
254
255
256
257
258
259
260


261
262
263
264
265
266
267
268







-
-
+







\fBTk_ConfigureWidget\fR.
This table will normally be used by \fItypePtr\->createProc\fR
and \fItypePtr\->configProc\fR, but Tk also uses it directly
to retrieve option information in the \fBitemcget\fR and
\fBitemconfigure\fR widget commands.
\fItypePtr\->configSpecs\fR must point to the configuration table
for this type.
.PP
Note that Tk provides a custom option type \fBtk_CanvasTagsOption\fR
Note: Tk provides a custom option type \fBtk_CanvasTagsOption\fR
for implementing the \fB\-tags\fR option; see an existing type
manager for an example of how to use it in \fIconfigSpecs\fR.
.SS CONFIGPROC
.PP
\fItypePtr\->configProc\fR is called by Tk whenever the
\fBitemconfigure\fR widget command is invoked to change the
configuration options for a canvas item.
273
274
275
276
277
278
279



280
281
282
283
284
285
286
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294







+
+
+







        int \fIflags\fR);
.CE
.PP
The \fIinterp\fR argument identifies the interpreter in which the
widget command was invoked, \fIcanvas\fR is a handle for the canvas
widget, and \fIitemPtr\fR is a pointer to the item being configured.
\fIobjc\fR and \fIobjv\fR contain the configuration options.
Note that if \fBTK_CONFIG_OBJS\fR is not set in the
\fItypePtr\->alwaysRedraw\fR field, the \fIobjv\fR parameter will actually
contain a pointer to an array of constant strings.
For example, if the following command is invoked:
.PP
.CS
\fB\&.c itemconfigure 2 \-fill red \-outline black\fR
.CE
.PP
\fIobjc\fR is \fB4\fR and \fIobjv\fR contains the string objects \fB\-fill\fR
309
310
311
312
313
314
315



316
317
318
319
320
321
322
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333







+
+
+







        int \fIobjc\fR,
        Tcl_Obj *const \fIobjv\fR[]);
.CE
.PP
The arguments \fIinterp\fR, \fIcanvas\fR, and \fIitemPtr\fR
all have the standard meanings, and \fIobjc\fR and \fIobjv\fR
describe the coordinate arguments.
Note that if \fBTK_CONFIG_OBJS\fR is not set in the
\fItypePtr\->alwaysRedraw\fR field, the \fIobjv\fR parameter will actually
contain a pointer to an array of constant strings.
For example, if the following widget command is invoked:
.PP
.CS
\fB\&.c coords 2 30 90\fR
.CE
.PP
\fIobjc\fR will be \fB2\fR and \fBobjv\fR will contain the integer objects
383
384
385
386
387
388
389
390

391
392

393
394
395
396
397
398
399
394
395
396
397
398
399
400

401
402

403
404
405
406
407
408
409
410







-
+

-
+







will not necessarily be the same as those in the canvas.
\fIdisplayProc\fR should call \fBTk_CanvasDrawableCoords\fR
to transform coordinates from those of the canvas to those
of \fIdst\fR.
.PP
Normally an item's \fIdisplayProc\fR is only invoked if the item
overlaps the area being displayed.
However, if bit zero of \fItypePtr\->flags\fR is 1,
However, if bit zero of \fItypePtr\->alwaysRedraw\fR is 1,
(i.e.\|
.QW "\fItypePtr\->flags & 1 == 1\fR" )
.QW "\fItypePtr\->alwaysRedraw & 1 == 1\fR" )
then \fIdisplayProc\fR is invoked during every redisplay operation,
even if the item does not overlap the area of redisplay; this is useful for
cases such as window items, where the subwindow needs to be unmapped when it
is off the screen.
.SS POINTPROC
.PP
\fItypePtr\->pointProc\fR is invoked by Tk to find out how close
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
545
546
547
548
549
550
551








































552
553
554
555
556
557
558







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







.CE
.PP
The \fIcanvas\fR and \fIitemPtr\fR arguments have the usual meaning,
and \fIdeltaX\fR and \fIdeltaY\fR give the amounts that should be
added to each x and y coordinate within the item.
The type manager should adjust the item's coordinates and
update the bounding box in the item's header.
.SS ROTATEPROC
.VS "8.7, TIP164"
.PP
\fItypePtr\->rotateProc\fR is invoked by Tk to rotate a canvas item
during the \fBrotate\fR widget command.
The procedure must match the following prototype:
.PP
.CS
typedef void \fBTk_ItemRotateProc\fR(
        Tk_Canvas \fIcanvas\fR,
        Tk_Item *\fIitemPtr\fR,
        double \fIoriginX\fR,
        double \fIoriginY\fR,
        double \fIangleRad\fR);
.CE
.PP
The \fIcanvas\fR and \fIitemPtr\fR arguments have the usual meaning.
\fIoriginX\fR and \fIoriginY\fR specify an origin relative to which
the item is to be rotated, and \fIangleRad\fR gives the anticlockwise
rotation to be applied in radians.
The item should adjust the coordinates of its control points so that where
they used to have coordinates \fIx\fR and \fIy\fR, they will have new
coordinates \fIx\(fm\fR and \fIy\(fm\fR, where
.PP
.CS
\fIrelX\fR = \fIx\fR \(mi \fIoriginX\fR
\fIrelY\fR = \fIy\fR \(mi \fIoriginY\fR
\fIx\(fm\fR = \fIoriginX\fR + \fIrelX\fR \(mu cos(\fIangleRad\fR) + \fIrelY\fR \(mu sin(\fIangleRad\fR)
\fIy\(fm\fR = \fIoriginY\fR \(mi \fIrelX\fR \(mu sin(\fIangleRad\fR) + \fIrelY\fR \(mu cos(\fIangleRad\fR)
.CE
.PP
The control points for an item are not necessarily the coordinates provided to
the item when it is created (or via the \fItypePtr\->coordProc\fR), but could
instead be derived from them.
\fIrotateProc\fR must also update the bounding box in the item's header.
.PP
Item types do not need to provide a \fItypePtr\->rotateProc\fR. If the
\fItypePtr\->rotateProc\fR is NULL, the \fItypePtr\->coordProc\fR will be
used instead to retrieve and update the list of coordinates.
.VE "8.7, TIP164"
.SS INDEXPROC
.PP
\fItypePtr\->indexProc\fR is invoked by Tk to translate a string
index specification into a numerical index, for example during the
\fBindex\fR widget command.
It is only relevant for item types that support indexable text or coordinates;
\fItypePtr\->indexProc\fR may be specified as NULL for non-textual
598
599
600
601
602
603
604



605
606
607
608
609
610
611
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585







+
+
+







.CE
.PP
The \fIinterp\fR, \fIcanvas\fR, and \fIitemPtr\fR arguments all
have the usual meaning.
\fIindexObj\fR contains a textual description of an index,
and \fIindexPtr\fR points to an integer value that should be
filled in with a numerical index.
Note that if \fBTK_CONFIG_OBJS\fR is not set in the
\fItypePtr\->alwaysRedraw\fR field, the \fIindexObj\fR parameter will
actually contain a pointer to a constant string.
It is up to the type manager to decide what forms of index
are supported (e.g., numbers, \fBinsert\fR, \fBsel.first\fR,
\fBend\fR, etc.).
\fIindexProc\fR should return a Tcl completion code and set
the interpreter result in the event of an error.
.SS ICURSORPROC
.PP
681
682
683
684
685
686
687



688
689
690
691
692
693
694
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671







+
+
+







.CE
.PP
\fIcanvas\fR and \fIitemPtr\fR have the usual meanings.
\fIindex\fR is an index into the item's text, as returned by a
previous call to \fItypePtr\->insertProc\fR, and \fIobj\fR
contains new text to insert just before the character given
by \fIindex\fR.
Note that if \fBTK_CONFIG_OBJS\fR is not set in the
\fItypePtr\->alwaysRedraw\fR field, the \fIobj\fR parameter will
actually contain a pointer to a constant string to be inserted.
If the item supports modification of the coordinates list by this
.PP
The type manager should insert the text and recompute the bounding
box in the item's header.
.SS DCHARSPROC
.PP
\fItypePtr\->dCharsProc\fR is invoked by Tk during the \fBdchars\fR

Changes to doc/CrtPhImgFmt.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58




59
60
61

62
63
64
65
66
67
68
69







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125


126
127
128
129

130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184


185
186
187

188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244


245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277


278
279
280
281
282
283


284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311



312
313

314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343



344
345



346
347



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362



363
364
365


366
367
368
369
370
371

372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413


414
415

416
417
418
419
420


421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20




21
22

23




24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40





41




42
43
44
45

46

47
48







49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69


70
71

72
73
74
75
76
77

78
79
80
81
82
83
84

85

86
87
88

89
90

91
92
93
94
95
96


97
98
99
100
101
102


103
104
105
106
107

108

109
110

111
112

113
114
115
116
117


118
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133

134
135
136

137

138
139
140
141
142
143
144
145
146
147
148
149
150


151
152
153


154
155
156
157

158
159
160
161

162
163
164

165

166
167
168
169
170
171


172
173
174
175
176
177
178


179
180
181
182
183
184
185

186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203


204
205
206


207
208

209
210

211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227


228


229
230






231
232






233
234










235


















236
237
238


239


240



























241
242
243
244


245
246
247


248
249
250
251














252
253
254
255


256
257






258


259




























260












261
262


263
264




265
266








































267
268
269
270











-
+








-
-
-
-


-
+
-
-
-
-





-
+











-
-
-
-
-

-
-
-
-
+
+
+
+
-

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-













-
-
+
+
-






-







-
+
-



-


-
+





-
-






-
-
+
+



-
+
-


-


-
+




-
-











-
+




-



-
+
-













-
-



-
-
+
+


-
+



-



-
+
-






-
-
+
+





-
-







-
+



-














-
-



-
-
+
+
-


-
+


-














-
-

-
-
+

-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+
+
+
-
-
+
+
+
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+

-
-
+
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+

-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




'\"
'\" Copyright (c) 1994 The Australian National University
'\" 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.
'\"
'\" Author: Paul Mackerras ([email protected]),
'\"	    Department of Computer Science,
'\"	    Australian National University.
'\"
.TH Tk_CreatePhotoImageFormat 3 8.7 Tk "Tk Library Procedures"
.TH Tk_CreatePhotoImageFormat 3 8.5 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_CreatePhotoImageFormat \- define new file format for photo images
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
.VS 8.7
\fBTk_CreatePhotoImageFormatVersion3\fR(\fIformatVersion3Ptr\fR)
.VE 8.7
.sp
\fBTk_CreatePhotoImageFormat\fR(\fIformatPtr\fR)
.SH ARGUMENTS
.AS "const Tk_PhotoImageFormatVersion3" *formatVersion3Ptr
.AS "const Tk_PhotoImageFormat" *formatPtr
.VS 8.7
.AP "const Tk_PhotoImageFormatVersion3" *formatVersion3Ptr in
Structure that defines the new file format including metadata functionality.
.VE 8.7
.AP "const Tk_PhotoImageFormat" *formatPtr in
Structure that defines the new file format.
.BE
.SH DESCRIPTION
.PP
\fBTk_CreatePhotoImageFormatVersion3\fR is invoked to define a new file format
\fBTk_CreatePhotoImageFormat\fR is invoked to define a new file format
for image data for use with photo images.  The code that implements an
image file format is called an image file format handler, or
handler for short.  The photo image code
maintains a list of handlers that can be used to read and
write data to or from a file.  Some handlers may also
support reading image data from a string or converting image data to a
string format.
The user can specify which handler to use with the \fB\-format\fR
image configuration option or the \fB\-format\fR option to the
\fBread\fR and \fBwrite\fR photo image subcommands.
.PP
The alternate version 2 function \fBTk_CreatePhotoImageFormat\fR has
identical functionality, but does not allow the handler to get or return
the metadata dictionary of the image.
It is described in section \fBVERSION 2 INTERFACE\fR below.
.PP
An image file format handler consists of a collection of procedures
plus a \fBTk_PhotoImageFormatVersion3\fR structure, which contains the
name of the image file format and pointers to six procedures provided
by the handler to deal with files and strings in this format.  The
Tk_PhotoImageFormatVersion3 structure contains the following fields:
plus a Tk_PhotoImageFormat structure, which contains the name of the
image file format and pointers to six procedures provided by the
handler to deal with files and strings in this format.  The
Tk_PhotoImageFormat structure contains the following fields:
.VS 8.7
.CS
typedef struct {
typedef struct Tk_PhotoImageFormat {
    const char *\fIname\fR;
    Tk_ImageFileMatchProcVersion3 *\fIfileMatchProc\fR;
    Tk_ImageStringMatchProcVersion3 *\fIstringMatchProc\fR;
    Tk_ImageFileReadProcVersion3 *\fIfileReadProc\fR;
    Tk_ImageStringReadProcVersion3 *\fIstringReadProc\fR;
    Tk_ImageFileWriteProcVersion3 *\fIfileWriteProc\fR;
    Tk_ImageStringWriteProcVersion3 *\fIstringWriteProc\fR;
} \fBTk_PhotoImageFormatVersion3\fR;
    Tk_ImageFileMatchProc *\fIfileMatchProc\fR;
    Tk_ImageStringMatchProc *\fIstringMatchProc\fR;
    Tk_ImageFileReadProc *\fIfileReadProc\fR;
    Tk_ImageStringReadProc *\fIstringReadProc\fR;
    Tk_ImageFileWriteProc *\fIfileWriteProc\fR;
    Tk_ImageStringWriteProc *\fIstringWriteProc\fR;
} \fBTk_PhotoImageFormat\fR;
.CE
.VE 8.7
.PP
The handler need not provide implementations of all six procedures.
For example, the procedures that handle string data would not be
provided for a format in which the image data are stored in binary,
and could therefore contain null characters.  If any procedure is not
implemented, the corresponding pointer in the Tk_PhotoImageFormat
structure should be set to NULL.  The handler must provide the
\fIfileMatchProc\fR procedure if it provides the \fIfileReadProc\fR
procedure, and the \fIstringMatchProc\fR procedure if it provides the
\fIstringReadProc\fR procedure.
.SS NAME
.PP
\fIformatPtr->name\fR provides a name for the image type.
Once \fBTk_CreatePhotoImageFormatVersion3\fR returns, this name may be
used in the \fB\-format\fR photo image configuration and subcommand
Once \fBTk_CreatePhotoImageFormat\fR returns, this name may be used
in the \fB\-format\fR photo image configuration and subcommand option.
option.
The manual page for the photo image (photo(n)) describes how image
file formats are chosen based on their names and the value given to
the \fB\-format\fR option. The first character of \fIformatPtr->name\fR
must not be an uppercase character from the ASCII character set
(that is, one of the characters \fBA\fR-\fBZ\fR).  Such names are used
only for legacy interface support (see below).
.VS 8.7
.SS FILEMATCHPROC
.PP
\fIformatPtr->fileMatchProc\fR provides the address of a procedure for
Tk to call when it is searching for an image file format handler
suitable for reading data in a given file.
\fIformatPtr->fileMatchProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileMatchProcVersion3\fR(
typedef int \fBTk_ImageFileMatchProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Channel \fIchan\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        int *\fIwidthPtr\fR,
        int *\fIheightPtr\fR,
        Tcl_Obj *\fImetadataOut\fR);
        Tcl_Interp *\fIinterp\fR);
.CE
The \fIfileName\fR argument is the name of the file containing the
image data, which is open for reading as \fIchan\fR.  The
\fIformat\fR argument contains the value given for the
\fB\-format\fR option, or NULL if the option was not specified.
\fBmetadataIn\fR and \fBmetadataOut\fR inputs and returns a metadata
dictionary as described in section \fBMETADATA INTERFACE\fR below.
If the data in the file appears to be in the format supported by this
handler, the \fIformatPtr->fileMatchProc\fR procedure should store the
width and height of the image in *\fIwidthPtr\fR and *\fIheightPtr\fR
respectively, and return 1.  Otherwise it should return 0.
.SS STRINGMATCHPROC
.PP
\fIformatPtr->stringMatchProc\fR provides the address of a procedure
for Tk to call when it is searching for an image file format handler
\fIformatPtr->stringMatchProc\fR provides the address of a procedure for
Tk to call when it is searching for an image file format handler for
suitable for reading data from a given string.
\fIformatPtr->stringMatchProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringMatchProcVersion3\fR(
typedef int \fBTk_ImageStringMatchProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Obj *\fIdata\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        int *\fIwidthPtr\fR,
        int *\fIheightPtr\fR,
        Tcl_Obj *\fImetadataOut\fR);
        Tcl_Interp *\fIinterp\fR);
.CE
The \fIdata\fR argument points to the object containing the image
data.  The \fIformat\fR argument contains the value given for
the \fB\-format\fR option, or NULL if the option was not specified.
\fBmetadataIn\fR and \fBmetadataOut\fR inputs and returns a metadata
dictionary as described in section \fBMETADATA INTERFACE\fR below.
If the data in the string appears to be in the format supported by
this handler, the \fIformatPtr->stringMatchProc\fR procedure should
store the width and height of the image in *\fIwidthPtr\fR and
*\fIheightPtr\fR respectively, and return 1.  Otherwise it should
return 0.
.SS FILEREADPROC
.PP
\fIformatPtr->fileReadProc\fR provides the address of a procedure for
Tk to call to read data from an image file into a photo image.
\fIformatPtr->fileReadProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileReadProcVersion3\fR(
typedef int \fBTk_ImageFileReadProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Channel \fIchan\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        PhotoHandle \fIimageHandle\fR,
        int \fIdestX\fR, int \fIdestY\fR,
        int \fIwidth\fR, int \fIheight\fR,
        int \fIsrcX\fR, int \fIsrcY\fR,
        int \fIsrcX\fR, int \fIsrcY\fR);
        Tcl_Obj *\fImetadataOut\fR);
.CE
The \fIinterp\fR argument is the interpreter in which the command was
invoked to read the image; it should be used for reporting errors.
The image data is in the file named \fIfileName\fR, which is open for
reading as \fIchan\fR.  The \fIformat\fR argument contains the
value given for the \fB\-format\fR option, or NULL if the option was
not specified.  The image data in the file, or a subimage of it, is to
be read into the photo image identified by the handle
\fIimageHandle\fR.  The subimage of the data in the file is of
dimensions \fIwidth\fR x \fIheight\fR and has its top-left corner at
coordinates (\fIsrcX\fR,\fIsrcY\fR).  It is to be stored in the photo
image with its top-left corner at coordinates
(\fIdestX\fR,\fIdestY\fR) using the \fBTk_PhotoPutBlock\fR procedure.
\fBmetadataIn\fR and \fBmetadataOut\fR inputs and returns a metadata
dictionary as described in section \fBMETADATA INTERFACE\fR below.
The return value is a standard Tcl return value.
.SS STRINGREADPROC
.PP
\fIformatPtr->stringReadProc\fR provides the address of a procedure
for Tk to call to read data from a string into a photo image.
\fIformatPtr->stringReadProc\fR provides the address of a procedure for
Tk to call to read data from a string into a photo image.
\fIformatPtr->stringReadProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringReadProcVersion3\fR(
typedef int \fBTk_ImageStringReadProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Obj *\fIdata\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        PhotoHandle \fIimageHandle\fR,
        int \fIdestX\fR, int \fIdestY\fR,
        int \fIwidth\fR, int \fIheight\fR,
        int \fIsrcX\fR, int \fIsrcY\fR,
        int \fIsrcX\fR, int \fIsrcY\fR);
        Tcl_Obj *\fImetadataOut\fR);
.CE
The \fIinterp\fR argument is the interpreter in which the command was
invoked to read the image; it should be used for reporting errors.
The \fIdata\fR argument points to the image data in object form.
The \fIformat\fR argument contains the
value given for the \fB\-format\fR option, or NULL if the option was
not specified.  The image data in the string, or a subimage of it, is
to be read into the photo image identified by the handle
not specified.  The image data in the string, or a subimage of it, is to
be read into the photo image identified by the handle
\fIimageHandle\fR.  The subimage of the data in the string is of
dimensions \fIwidth\fR x \fIheight\fR and has its top-left corner at
coordinates (\fIsrcX\fR,\fIsrcY\fR).  It is to be stored in the photo
image with its top-left corner at coordinates
(\fIdestX\fR,\fIdestY\fR) using the \fBTk_PhotoPutBlock\fR procedure.
\fBmetadataIn\fR and \fBmetadataOut\fR inputs and returns a metadata
dictionary as described in section \fBMETADATA INTERFACE\fR below.
The return value is a standard Tcl return value.
.SS FILEWRITEPROC
.PP
\fIformatPtr->fileWriteProc\fR provides the address of a procedure for
Tk to call to write data from a photo image to a file.
\fIformatPtr->fileWriteProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileWriteProcVersion3\fR(
typedef int \fBTk_ImageFileWriteProc\fR(
        Tcl_Interp *\fIinterp\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        Tk_PhotoImageBlock *\fIblockPtr\fR);
.CE
The \fIinterp\fR argument is the interpreter in which the command was
invoked to write the image; it should be used for reporting errors.
The image data to be written are in memory and are described by the
Tk_PhotoImageBlock structure pointed to by \fIblockPtr\fR; see the
manual page FindPhoto(3) for details.  The \fIfileName\fR argument
points to the string giving the name of the file in which to write the
image data.  The \fIformat\fR argument contains the
value given for the \fB\-format\fR option, or NULL if the option was
not specified.  The format string can contain extra characters
after the name of the format.  If appropriate, the
\fIformatPtr->fileWriteProc\fR procedure may interpret these
characters to specify further details about the image file.
\fBmetadataIn\fR may contain metadata keys that a driver may include
into the output data.
The return value is a standard Tcl return value.
.SS STRINGWRITEPROC
.PP
\fIformatPtr->stringWriteProc\fR provides the address of a procedure
for Tk to call to translate image data from a photo image into a
\fIformatPtr->stringWriteProc\fR provides the address of a procedure for
Tk to call to translate image data from a photo image into a string.
string.
\fIformatPtr->stringWriteProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringWriteProcVersion3\fR(
typedef int \fBTk_ImageStringWriteProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Obj *\fIformat\fR,
        Tcl_Obj *\fImetadataIn\fR,
        Tk_PhotoImageBlock *\fIblockPtr\fR);
.CE
The \fIinterp\fR argument is the interpreter in which the command was
invoked to convert the image; it should be used for reporting errors.
The image data to be converted are in memory and are described by the
Tk_PhotoImageBlock structure pointed to by \fIblockPtr\fR; see the
manual page FindPhoto(3) for details.  The data for the string
should be put in the interpreter \fIinterp\fR result.
The \fIformat\fR argument contains the
value given for the \fB\-format\fR option, or NULL if the option was
not specified.  The format string can contain extra characters
after the name of the format.  If appropriate, the
\fIformatPtr->stringWriteProc\fR procedure may interpret these
characters to specify further details about the image file.
\fBmetadataIn\fR may contain metadata keys that a driver may include
into the output data.
The return value is a standard Tcl return value.
.PP
.SH "METADATA INTERFACE"
.SH "LEGACY INTERFACE SUPPORT"
.PP
Image formats contain a description of the image bitmap and may
contain additional information like image resolution or comments.
Image metadata may be read from image files and passed to the script
level by including dictionary keys into the metadata property of the
image. Image metadata may be written to image data on file write or
image data output.
In Tk 8.2 and earlier, the definition of all the function pointer
types stored in fields of a \fBTk_PhotoImageFormat\fR struct were
.PP
.SS "METADATA KEYS"
.PP
The metadata may contain any key.
A driver will handle only a set of dictionary keys documented in the
documentation. See the photo image manual page for currently defined
incompatibly different.  Legacy programs and libraries dating from
those days may still contain code that defines extended Tk photo image
keys for the system drivers.
.PP
The following rules may give guidance to name metadata keys:
.IP \(bu
Abbreviations are in upper case.
.IP \(bu
Words are in US English in small case (except proper nouns)
.IP \(bu
Vertical DPI is expressed as DPI/aspect. The reason is, that some
image formats may feature aspect and no resolution value.
formats using the old interface.  The Tk header file will still support
.SS "METADATA INPUT"
.PP
Each driver function gets a Tcl object pointer \fBmetadataIn\fR as
parameter. This parameter serves to input a metadata dict to the
driver function.
It may be NULL to flag that the metadata dict is empty.
.PP
A typical driver code snipped to check for a metadata key is:
.CS
if (NULL != metadataIn) {
    Tcl_Obj *itemData;
    Tcl_DictObjGet(interp, metadataIn, Tcl_NewStringObj("Comment",-1),
            &itemData));
    // use value reference in itemData
}
.CE
.PP
The \fB\-metadata\fR command option data of the following commands is passed
this legacy interface if the code is compiled with the
macro \fBUSE_OLD_IMAGE\fR defined.  Alternatively, the legacy interfaces
are used if the first character of \fIformatPtr->name\fR is an
to the driver: \fBimage create\fR, \fBconfigure\fR, \fBput\fR,
\fBread\fR, \fBdata\fR and \fBwrite\fR.
uppercase ASCII character (\fBA\fR-\fBZ\fR), and explicit casts
If no \fB\-metadata\fR command option available or not given, the metadata
property of the image is passed to the driver using the following
are used to forgive the type mismatch.  For example,
commands: \fBcget\fR, \fBconfigure\fR, \fBdata\fR and \fBwrite\fR.
.PP
Note that setting the \fB\-metadata\fR property of an image using
\fBconfigure\fR without any other option does not invoke any driver
function.
.PP
The metadata dictionary is not suited to pass options to the driver
related to the bitmap representation, as the image bitmap is not
recreated on a metadata change. The format string should be used for
this purpose.
.PP
.SS "METADATA OUTPUT"
.PP
The image match and read driver functions may set keys in a prepared
metadata dict to return them.
Those functions get a Tcl object pointer \fImetadataOut\fR as
parameter.
\fImetadataOut\fR may be NULL to indicate, that no metadata return is
required (\fBput\fR, \fBread\fR subcommands). The variable pointed to
by \fImetadataOut\fR is initialized to an empty unshared dict object if
metadata return is attended (\fBimage create\fR command, \fBconfigure\fR
subcommand). The driver may set dict keys in this object to return
metadata.
If a match function succeeds, the metadataOut pointer is passed to the
corresponding read function.
.PP
A sample driver code snippet is:
.CS
static Tk_PhotoImageFormat myFormat = {
    "MyFormat",
    (Tk_ImageFileMatchProc *) FileMatch,
if (NULL != metadataOut) {
    Tcl_DictObjPut(NULL, metadataOut, Tcl_NewStringObj("XMP",-1),
    NULL,
    (Tk_ImageFileReadProc *) FileRead,
    NULL,
            Tcl_NewStringObj(xmpMetadata));
}
    NULL,
    NULL
};
.CE
.PP
The metadata keys returned by the driver are merged into the present
metadata property of the image or into the metadata dict given by the
\fB\-metadata\fR command line option.
At the script level, the command \fBimage create\fR and the
\fBconfigure\fR method may return metadata from the driver.
.PP
Format string options or metadata keys may influence the creation of
metadata within the driver.
For example, the creation of an expensive metadata key may depend on a
format string option or on a metadata input key.
.PP
.VE 8.7
.SH "VERSION 2 INTERFACE"
would define a minimal \fBTk_PhotoImageFormat\fR that operates provide
only file reading capability, where \fBFileMatch\fR and \fBFileRead\fR
are written according to the legacy interfaces of Tk 8.2 or earlier.
.PP
Version 2 Interface does not include the possibility for the driver to
use the metadata dict for input or output.
Any stub-enabled extension providing an extended photo image format
via the legacy interface enabled by the \fBUSE_OLD_IMAGE\fR macro
.SS SYNOPSIS
\fB#include <tk.h>\fR
.sp
\fBTk_CreatePhotoImageFormat\fR(\fIformatPtr\fR)
.SS ARGUMENTS
.AS "const Tk_PhotoImageFormat" *formatPtr
that is compiled against Tk 8.5 headers and linked against the
.AP "const Tk_PhotoImageFormat" *formatPtr in
Structure that defines the new file format.
Tk 8.5 stub library will produce a file that can be loaded only
.BE
.SS DESCRIPTION
A driver using the version 2 interface invokes \fBTk_CreatePhotoImageFormat\fR
for driver registration. The Tk_PhotoImageFormat structure
contains the following fields:
.CS
typedef struct {
    const char *\fIname\fR;
    Tk_ImageFileMatchProc *\fIfileMatchProc\fR;
    Tk_ImageStringMatchProc *\fIstringMatchProc\fR;
    Tk_ImageFileReadProc *\fIfileReadProc\fR;
    Tk_ImageStringReadProc *\fIstringReadProc\fR;
    Tk_ImageFileWriteProc *\fIfileWriteProc\fR;
    Tk_ImageStringWriteProc *\fIstringWriteProc\fR;
} \fBTk_PhotoImageFormat\fR;
.CE
.PP
.SS FILEMATCHPROC
.PP
\fIformatPtr->fileMatchProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileMatchProc\fR(
        Tcl_Channel \fIchan\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        int *\fIwidthPtr\fR,
        int *\fIheightPtr\fR,
        Tcl_Interp *\fIinterp\fR);
into interps with Tk 8.5 or later; that is, the normal stub-compatibility
.CE
.PP
.SS STRINGMATCHPROC
.PP
\fIformatPtr->stringMatchProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringMatchProc\fR(
        Tcl_Obj *\fIdata\fR,
        Tcl_Obj *\fIformat\fR,
        int *\fIwidthPtr\fR,
        int *\fIheightPtr\fR,
        Tcl_Interp *\fIinterp\fR);
rules.  If a developer needs to generate from such code a file
that is loadable into interps with Tk 8.4 or earlier, they must
.CE
.SS FILEREADPROC
use Tk 8.4 headers and stub libraries to do so.
.PP
\fIformatPtr->fileReadProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileReadProc\fR(
        Tcl_Interp *\fIinterp\fR,
Any new code written today should not make use of the legacy
interfaces.  Expect their support to go away in Tk 9.
        Tcl_Channel \fIchan\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        PhotoHandle \fIimageHandle\fR,
        int \fIdestX\fR, int \fIdestY\fR,
        int \fIwidth\fR, int \fIheight\fR,
        int \fIsrcX\fR, int \fIsrcY\fR);
.CE
.SS STRINGREADPROC
.PP
\fIformatPtr->stringReadProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringReadProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Obj *\fIdata\fR,
        Tcl_Obj *\fIformat\fR,
        PhotoHandle \fIimageHandle\fR,
        int \fIdestX\fR, int \fIdestY\fR,
        int \fIwidth\fR, int \fIheight\fR,
        int \fIsrcX\fR, int \fIsrcY\fR);
.CE
.SS FILEWRITEPROC
.PP
\fIformatPtr->fileWriteProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageFileWriteProc\fR(
        Tcl_Interp *\fIinterp\fR,
        const char *\fIfileName\fR,
        Tcl_Obj *\fIformat\fR,
        Tk_PhotoImageBlock *\fIblockPtr\fR);
.CE
.SS STRINGWRITEPROC
.PP
\fIformatPtr->stringWriteProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageStringWriteProc\fR(
        Tcl_Interp *\fIinterp\fR,
        Tcl_Obj *\fIformat\fR,
        Tk_PhotoImageBlock *\fIblockPtr\fR);
.CE
.SH "SEE ALSO"
Tk_FindPhoto, Tk_PhotoPutBlock
.SH KEYWORDS
photo image, image file

Changes to doc/CrtSelHdlr.3.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-















-
+







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateSelHandler\fR(\fItkwin, selection, target, proc, clientData, format\fR)
.sp
\fBTk_DeleteSelHandler\fR(\fItkwin, selection, target\fR)
.fi
.SH ARGUMENTS
.AS Tk_SelectionProc clientData
.AP Tk_Window tkwin in
Window for which \fIproc\fR will provide selection information.
.AP Atom selection in
The name of the selection for which \fIproc\fR will provide
selection information.
.AP Atom target in
Form in which \fIproc\fR can provide the selection (e.g. STRING
or FILE_NAME).  Corresponds to \fItype\fR arguments in \fBselection\fR
commands.
.AP Tk_SelectionProc *proc in
Procedure to invoke whenever the selection is owned by \fItkwin\fR
and the selection contents are requested in the format given by
\fItarget\fR.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.AP Atom format in
If the selection requestor is not in this process, \fIformat\fR determines
the representation used to transmit the selection to its
requestor.
.BE
.SH DESCRIPTION
51
52
53
54
55
56
57
58
59
60



61
62

63
64
65
66
67
68
69
50
51
52
53
54
55
56



57
58
59
60

61
62
63
64
65
66
67
68







-
-
-
+
+
+

-
+







X Inter-Client Communication Conventions Manual (ICCCM) or
any other form in which an application is willing to present
the selection.  The most common form is STRING.
.PP
\fIProc\fR should have arguments and result that match the
type \fBTk_SelectionProc\fR:
.CS
typedef Tcl_Size \fBTk_SelectionProc\fR(
        void *\fIclientData\fR,
        Tcl_Size \fIoffset\fR,
typedef int \fBTk_SelectionProc\fR(
        ClientData \fIclientData\fR,
        int \fIoffset\fR,
        char *\fIbuffer\fR,
        Tcl_Size \fImaxBytes\fR);
        int \fImaxBytes\fR);
.CE
The \fIclientData\fR parameter to \fIproc\fR is a copy of the
\fIclientData\fR argument given to \fBTk_CreateSelHandler\fR.
Typically, \fIclientData\fR points to a data
structure containing application-specific information that is
needed to retrieve the selection.  \fIOffset\fR specifies an
offset position into the selection, \fIbuffer\fR specifies a

Changes to doc/CrtWindow.3.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35







-







.sp
Tk_Window
\fBTk_CreateWindowFromPath\fR(\fIinterp, tkwin, pathName, topLevScreen\fR)
.sp
\fBTk_DestroyWindow\fR(\fItkwin\fR)
.sp
\fBTk_MakeWindowExist\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Interp *topLevScreen
.AP Tcl_Interp *interp out
Tcl interpreter to use for error reporting.  If no error occurs,
then \fI*interp\fR is not modified.
.AP Tk_Window parent in
Token for the window that is to serve as the logical parent of

Changes to doc/DeleteImg.3.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
10
11
12
13
14
15
16

17
18
19
20
21
22
23







-







.SH NAME
Tk_DeleteImage \- Destroy an image.
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_DeleteImage\fR(\fIinterp, name\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Interp *interp
.AP Tcl_Interp *interp in
Interpreter for which the image was created.
.AP "const char" *name in
Name of the image.
.BE

Changes to doc/DrawFocHlt.3.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
9
10
11
12
13
14
15

16

17
18
19
20
21
22
23







-
+
-







.BS
.SH NAME
Tk_DrawFocusHighlight \- draw the traversal highlight ring for a widget
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_DrawFocusHighlight\fR(\fItkwin, gc, width, drawable\fR)
\fBTk_DrawFocusHighlight(\fItkwin, gc, width, drawable\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *joinPtr
.AP Tk_Window tkwin in
Window for which the highlight is being drawn.  Used to retrieve
the window's dimensions, among other things.
.AP GC gc in
Graphics context to use for drawing the highlight.

Changes to doc/EventHndlr.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59

60
61
62
63
64
65
66
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19





20
21






22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47

48
49
50
51
52
53
54
55











-
+







-
-
-
-
-


-
-
-
-
-
-








-
+










-
+






-
+







'\"
'\" Copyright (c) 1990 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH Tk_CreateEventHandler 3 "" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_CreateEventHandler, Tk_DeleteEventHandler, Tk_GetButtonMask, Tk_SendVirtualEvent \- associate procedure callback with an X event
Tk_CreateEventHandler, Tk_DeleteEventHandler \- associate procedure callback with an X event
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_CreateEventHandler\fR(\fItkwin, mask, proc, clientData\fR)
.sp
\fBTk_DeleteEventHandler\fR(\fItkwin, mask, proc, clientData\fR)
.sp
\fBTk_GetButtonMask\fR(\fIbutton\fR)
.sp
\fBTk_SendVirtualEvent\fR(\fItkwin, eventName, detail\fR)
.fi
.SH ARGUMENTS
.AS "unsigned long" clientData
.AP unsigned button in
Button number.
.AP "const char" *eventName in
The name of the virtual event.
.AP Tcl_Obj *detail in
Detail information for the virtual event.
.AP Tk_Window tkwin in
Token for window in which events may occur.
.AP "unsigned long" mask in
Bit-mask of events (such as \fBButtonPressMask\fR)
for which \fIproc\fR should be called.
.AP Tk_EventProc *proc in
Procedure to invoke whenever an event in \fImask\fR occurs
in the window given by \fItkwin\fR.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.BE
.SH DESCRIPTION
.PP
\fBTk_CreateEventHandler\fR arranges for \fIproc\fR to be
invoked in the future whenever one of the event types specified
by \fImask\fR occurs in the window specified by \fItkwin\fR.
The callback to \fIproc\fR will be made by \fBTk_HandleEvent\fR;
this mechanism only works in programs that dispatch events
through \fBTk_HandleEvent\fR (or through other Tk procedures that
call \fBTk_HandleEvent\fR, such as \fBTcl_DoOneEvent\fR or
call \fBTk_HandleEvent\fR, such as \fBTk_DoOneEvent\fR or
\fBTk_MainLoop\fR).
.PP
\fIProc\fR should have arguments and result that match the
type \fBTk_EventProc\fR:
.CS
typedef void \fBTk_EventProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        XEvent *\fIeventPtr\fR);
.CE
The \fIclientData\fR parameter to \fIproc\fR is a copy of the \fIclientData\fR
argument given to \fBTk_CreateEventHandler\fR when the callback
was created.  Typically, \fIclientData\fR points to a data
structure containing application-specific information about
the window in which the event occurred.  \fIEventPtr\fR is
78
79
80
81
82
83
84
85
86
87
88
89
90
91
67
68
69
70
71
72
73





74
75







-
-
-
-
-


When a window is deleted all of its handlers will be deleted
automatically;  in this case there is no need to call
\fBTk_DeleteEventHandler\fR.
.PP
If multiple handlers are declared for the same type of X event
on the same window, then the handlers will be invoked in the
order they were created.
.PP
\fBTk_GetButtonMask\fR returns the button mask corresponding to
the button. E.g it will return \fIButton1Mask\fR for button \fIButton1\fR.
.PP
\fBTk_SendVirtualEvent\fR sends a virtual event to Tk's event queue.
.SH KEYWORDS
bind, callback, event, handler

Changes to doc/FindPhoto.3.

28
29
30
31
32
33
34

35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52







+





+




-







int
\fBTk_PhotoPutZoomedBlock\fR(\fIinterp, handle, blockPtr, x, y, width, height,\
zoomX, zoomY, subsampleX, subsampleY, compRule\fR)
.sp
int
\fBTk_PhotoGetImage\fR(\fIhandle, blockPtr\fR)
.sp
void
\fBTk_PhotoBlank\fR(\fIhandle\fR)
.sp
int
\fBTk_PhotoExpand\fR(\fIinterp, handle, width, height\fR)
.sp
void
\fBTk_PhotoGetSize\fR(\fIhandle, widthPtr, heightPtr\fR)
.sp
int
\fBTk_PhotoSetSize\fR(\fIinterp. handle, width, height\fR)
.fi
.SH ARGUMENTS
.AS Tk_PhotoImageBlock window_path
.AP Tcl_Interp *interp in
Interpreter in which image was created and in which error reporting is
to be done.
.AP "const char" *imageName in
Name of the photo image.
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274







-
+







.SH BUGS
The \fBTk_PhotoImageBlock\fR structure used to provide image data to
\fBTk_PhotoPutBlock\fR promises great flexibility in the layout of the
data (e.g. separate planes for the red, green, blue and alpha
channels).  Unfortunately, the implementation fails to hold this
promise.  The problem is that the \fIpixelSize\fR field is
(incorrectly) used to determine whether the image has an alpha channel.
Currently, if the offset for the alpha channel is greater than or equal to
Currently, if the offset for the alpha channel is greater or equal than
\fIpixelSize\fR, \fBtk_PhotoPutblock\fR assumes no alpha data is
present and makes the image fully opaque.  This means that for layouts
where the channels are separate (or any other exotic layout where
\fIpixelSize\fR has to be smaller than the alpha offset), the alpha
channel will not be read correctly.  In order to be on the safe side
if this issue will be corrected in a future release, it is strongly
recommended you always provide alpha data - even if the image has no

Changes to doc/FontId.3.

11
12
13
14
15
16
17
18

19
20

21
22
23

24
25
26
27
28
29
30
31
11
12
13
14
15
16
17

18
19

20
21
22

23

24
25
26
27
28
29
30







-
+

-
+


-
+
-







Tk_FontId, Tk_GetFontMetrics, Tk_PostscriptFontName \- accessor functions for
fonts
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Font
\fBTk_FontId\fR(\fItkfont\fR)
\fBTk_FontId(\fItkfont\fB)\fR
.sp
\fBTk_GetFontMetrics\fR(\fItkfont, fmPtr\fR)
\fBTk_GetFontMetrics(\fItkfont, fmPtr\fB)\fR
.sp
int
\fBTk_PostscriptFontName\fR(\fItkfont, dsPtr\fR)
\fBTk_PostscriptFontName(\fItkfont, dsPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS Tk_FontMetrics *dsPtr
.AP Tk_Font tkfont in
Opaque font token being queried.  Must have been returned by a previous
call to \fBTk_GetFont\fR.
.AP Tk_FontMetrics *fmPtr out
Pointer to structure in which the font metrics for \fItkfont\fR will
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







Any other font families may not print correctly because the computed
Postscript font name may be incorrect or not exist on the printer.
.SH "DATA STRUCTURES"
.PP
The \fBTk_FontMetrics\fR data structure is used by \fBTk_GetFontMetrics\fR to
return information about a font and is defined as follows:
.CS
typedef struct {
typedef struct Tk_FontMetrics {
    int \fIascent\fR;
    int \fIdescent\fR;
    int \fIlinespace\fR;
} \fBTk_FontMetrics\fR;
.CE
.PP
The \fIascent\fR field is the amount in pixels that the tallest

Added doc/FreeXId.3.































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
'\"
'\" Copyright (c) 1990 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH Tk_FreeXId 3 4.0 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_FreeXId \- make X resource identifier available for reuse
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_FreeXId(\fIdisplay, id\fB)\fR
.SH ARGUMENTS
.AS Display *display out
.AP Display *display in
Display for which \fIid\fR was allocated.
.AP XID id in
Identifier of X resource (window, font, pixmap, cursor, graphics
context, or colormap) that is no longer in use.
.BE
.SH DESCRIPTION
.PP
This function is deprecated, it doesn't do anything since 2008-08-19.
.SH KEYWORDS
resource identifier

Changes to doc/GeomReq.3.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43

44
45
46

47
48
49

50
51
52
53
54
55
56
57
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39

40

41

42

43

44

45

46
47
48
49
50
51
52







-















-
+
-

-
+
-

-
+
-

-
+
-







\fBTk_GeometryRequest\fR(\fItkwin, reqWidth, reqHeight\fR)
.sp
\fBTk_SetMinimumRequestSize\fR(\fItkwin, minWidth, minHeight\fR)
.sp
\fBTk_SetInternalBorder\fR(\fItkwin, width\fR)
.sp
\fBTk_SetInternalBorderEx\fR(\fItkwin, left, right, top, bottom\fR)
.fi
.SH ARGUMENTS
.AS baseHeight clientData
.AP Tk_Window tkwin in
Window for which geometry is being requested.
.AP int reqWidth in
Desired width for \fItkwin\fR, in pixel units.
.AP int reqHeight in
Desired height for \fItkwin\fR, in pixel units.
.AP int minWidth in
Desired minimum requested width for \fItkwin\fR, in pixel units.
.AP int minHeight in
Desired minimum requested height for \fItkwin\fR, in pixel units.
.AP int width in
Space to leave for internal border for \fItkwin\fR, in pixel units.
.AP int left in
Space to leave for left side of internal border for \fItkwin\fR,
Space to leave for left side of internal border for \fItkwin\fR, in pixel units.
in pixel units.
.AP int right in
Space to leave for right side of internal border for \fItkwin\fR,
Space to leave for right side of internal border for \fItkwin\fR, in pixel units.
in pixel units.
.AP int top in
Space to leave for top side of internal border for \fItkwin\fR,
Space to leave for top side of internal border for \fItkwin\fR, in pixel units.
in pixel units.
.AP int bottom in
Space to leave for bottom side of internal border for \fItkwin\fR,
Space to leave for bottom side of internal border for \fItkwin\fR, in pixel units.
in pixel units.
.BE
.SH DESCRIPTION
.PP
\fBTk_GeometryRequest\fR is called by widget code to indicate its
preference for the dimensions of a particular window.  The arguments
to \fBTk_GeometryRequest\fR are made available to the geometry
manager for the window, which then decides on the actual geometry

Changes to doc/GetAnchor.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27
28
29
30
31
32
11
12
13
14
15
16
17

18
19
20

21
22
23

24

25
26
27
28
29
30
31







-
+


-
+


-
+
-







.SH NAME
Tk_GetAnchorFromObj, Tk_GetAnchor, Tk_NameOfAnchor \- translate between strings and anchor positions
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetAnchorFromObj\fR(\fIinterp, objPtr, anchorPtr\fR)
\fBTk_GetAnchorFromObj(\fIinterp, objPtr, anchorPtr\fB)\fR
.sp
int
\fBTk_GetAnchor\fR(\fIinterp, string, anchorPtr\fR)
\fBTk_GetAnchor(\fIinterp, string, anchorPtr\fB)\fR
.sp
const char *
\fBTk_NameOfAnchor\fR(\fIanchor\fR)
\fBTk_NameOfAnchor(\fIanchor\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tk_Anchor" *anchorPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting, or NULL.
.AP Tcl_Obj *objPtr in/out
String value contains name of anchor point:
.QW \fBn\fR  ,

Changes to doc/GetBitmap.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27

28
29
30

31
32

33
34

35
36

37
38
39
40
41
42
43
44
11
12
13
14
15
16
17

18
19
20

21
22
23

24
25
26

27
28
29

30
31

32
33

34
35

36

37
38
39
40
41
42
43







-
+


-
+


-
+


-
+


-
+

-
+

-
+

-
+
-







.SH NAME
Tk_AllocBitmapFromObj, Tk_GetBitmap, Tk_GetBitmapFromObj, Tk_DefineBitmap, Tk_NameOfBitmap, Tk_SizeOfBitmap, Tk_FreeBitmapFromObj, Tk_FreeBitmap \- maintain database of single-plane pixmaps
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Pixmap
\fBTk_AllocBitmapFromObj\fR(\fIinterp, tkwin, objPtr\fR)
\fBTk_AllocBitmapFromObj(\fIinterp, tkwin, objPtr\fB)\fR
.sp
Pixmap
\fBTk_GetBitmap\fR(\fIinterp, tkwin, info\fR)
\fBTk_GetBitmap(\fIinterp, tkwin, info\fB)\fR
.sp
Pixmap
\fBTk_GetBitmapFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_GetBitmapFromObj(\fItkwin, objPtr\fB)\fR
.sp
int
\fBTk_DefineBitmap\fR(\fIinterp, name, source, width, height\fR)
\fBTk_DefineBitmap(\fIinterp, name, source, width, height\fB)\fR
.sp
const char *
\fBTk_NameOfBitmap\fR(\fIdisplay, bitmap\fR)
\fBTk_NameOfBitmap(\fIdisplay, bitmap\fB)\fR
.sp
\fBTk_SizeOfBitmap\fR(\fIdisplay, bitmap, widthPtr, heightPtr\fR)
\fBTk_SizeOfBitmap(\fIdisplay, bitmap, widthPtr, heightPtr\fB)\fR
.sp
\fBTk_FreeBitmapFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_FreeBitmapFromObj(\fItkwin, objPtr\fB)\fR
.sp
\fBTk_FreeBitmap\fR(\fIdisplay, bitmap\fR)
\fBTk_FreeBitmap(\fIdisplay, bitmap\fB)\fR
.fi
.SH ARGUMENTS
.AS "unsigned long" *pixelPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting; if NULL then no error message
is left after errors.
.AP Tk_Window tkwin in
Token for window in which the bitmap will be used.
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94

95
96
97

98

99

100

101

102

103

104

105
106

107

108

109

110
111

112

113

114

115

116

117
118
119
120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152
153
154
155
156
157
158
76
77
78
79
80
81
82

83
84
85
86

87
88
89
90
91

92
93
94
95
96

97
98
99

100
101
102

103
104
105

106
107
108
109

110
111
112

113
114
115
116

117
118
119

120
121
122

123
124
125
126
127
128

129
130
131

132
133
134

135
136
137

138
139
140

141
142
143

144
145
146

147
148
149

150
151
152

153
154
155

156
157
158

159
160
161

162
163
164

165
166
167

168
169
170

171
172
173

174
175
176
177
178
179
180
181







-




-




+
-
+



+
-
+

+
-
+

+
-
+

+
-
+


+
-
+

+
-
+


+
-
+

+
-
+

+
-
+




+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+

+
-
+







\fBTk_AllocBitmapFromObj\fR returns a Pixmap identifier for a bitmap
that matches the description in \fIobjPtr\fR and is suitable for use
in \fItkwin\fR.  It re-uses an existing bitmap, if possible, and
creates a new one otherwise.  \fIObjPtr\fR's value must have one
of the following forms:
.TP 20
\fB@\fIfileName\fR
.
\fIFileName\fR must be the name of a file containing a bitmap
description in the standard X11 format.
.TP 20
\fIname\fR
.
\fIName\fR must be the name of a bitmap defined previously with
a call to \fBTk_DefineBitmap\fR.  The following names are pre-defined
by Tk:
.RS
.TP 12
.IP \fBerror\fR 12
\fBerror\fR
The international
.QW don't
symbol:  a circle with a diagonal line across it.
.TP 12
.IP \fBgray75\fR 12
\fBgray75\fR
75% gray: a checkerboard pattern where three out of four bits are on.
.TP 12
.IP \fBgray50\fR 12
\fBgray50\fR
50% gray: a checkerboard pattern where every other bit is on.
.TP 12
.IP \fBgray25\fR 12
\fBgray25\fR
25% gray: a checkerboard pattern where one out of every four bits is on.
.TP 12
.IP \fBgray12\fR 12
\fBgray12\fR
12.5% gray: a pattern where one-eighth of the bits are on, consisting of
every fourth pixel in every other row.
.TP 12
.IP \fBhourglass\fR 12
\fBhourglass\fR
An hourglass symbol.
.TP 12
.IP \fBinfo\fR 12
\fBinfo\fR
A large letter
.QW i .
.TP 12
.IP \fBquesthead\fR 12
\fBquesthead\fR
The silhouette of a human head, with a question mark in it.
.TP 12
.IP \fBquestion\fR 12
\fBquestion\fR
A large question-mark.
.TP 12
.IP \fBwarning\fR 12
\fBwarning\fR
A large exclamation point.
.PP
In addition, the following pre-defined names are available only on the
\fBMacintosh\fR platform:
.TP 12
.IP \fBdocument\fR 12
\fBdocument\fR
A generic document.
.TP 12
.IP \fBstationery\fR 12
\fBstationery\fR
Document stationery.
.TP 12
.IP \fBedition\fR 12
\fBedition\fR
The \fIedition\fR symbol.
.TP 12
.IP \fBapplication\fR 12
\fBapplication\fR
Generic application icon.
.TP 12
.IP \fBaccessory\fR 12
\fBaccessory\fR
A desk accessory.
.TP 12
.IP \fBfolder\fR 12
\fBfolder\fR
Generic folder icon.
.TP 12
.IP \fBpfolder\fR 12
\fBpfolder\fR
A locked folder.
.TP 12
.IP \fBtrash\fR 12
\fBtrash\fR
A trash can.
.TP 12
.IP \fBfloppy\fR 12
\fBfloppy\fR
A floppy disk.
.TP 12
.IP \fBramdisk\fR 12
\fBramdisk\fR
A floppy disk with chip.
.TP 12
.IP \fBcdrom\fR 12
\fBcdrom\fR
A cd disk icon.
.TP 12
.IP \fBpreferences\fR 12
\fBpreferences\fR
A folder with prefs symbol.
.TP 12
.IP \fBquerydoc\fR 12
\fBquerydoc\fR
A database document icon.
.TP 12
.IP \fBstop\fR 12
\fBstop\fR
A stop sign.
.TP 12
.IP \fBnote\fR 12
\fBnote\fR
A face with balloon words.
.TP 12
.IP \fBcaution\fR 12
\fBcaution\fR
A triangle with an exclamation point.
.RE
.LP
Under normal conditions, \fBTk_AllocBitmapFromObj\fR
returns an identifier for the requested bitmap.  If an error
occurs in creating the bitmap, such as when \fIobjPtr\fR refers
to a non-existent file, then \fBNone\fR is returned and an error
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220







-
+







have been used in a call to \fBTk_DefineBitmap\fR.
The arguments \fIsource\fR, \fIwidth\fR, and \fIheight\fR
describe the bitmap.
\fBTk_DefineBitmap\fR normally returns \fBTCL_OK\fR; if an error occurs
(e.g. a bitmap named \fInameId\fR has already been defined) then
\fBTCL_ERROR\fR is returned and an error message is left in
interpreter \fIinterp\fR's result.
Note that \fBTk_DefineBitmap\fR expects the memory pointed to by
Note:  \fBTk_DefineBitmap\fR expects the memory pointed to by
\fIsource\fR to be static:  \fBTk_DefineBitmap\fR does not make
a private copy of this memory, but uses the bytes pointed to
by \fIsource\fR later in calls to \fBTk_AllocBitmapFromObj\fR or
\fBTk_GetBitmap\fR.
.PP
Typically \fBTk_DefineBitmap\fR is used by \fB#include\fR-ing a
bitmap file directly into a C program and then referencing

Changes to doc/GetCapStyl.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24
25
26
27
28
29
11
12
13
14
15
16
17

18
19
20

21

22
23
24
25
26
27
28







-
+


-
+
-







.SH NAME
Tk_GetCapStyle, Tk_NameOfCapStyle \- translate between strings and cap styles
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetCapStyle\fR(\fIinterp, string, capPtr\fR)
\fBTk_GetCapStyle(\fIinterp, string, capPtr\fB)\fR
.sp
const char *
\fBTk_NameOfCapStyle\fR(\fIcap\fR)
\fBTk_NameOfCapStyle(\fIcap\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *capPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP "const char" *string in
String containing name of cap style \- one of
.QW \fBbutt\fR ,

Changes to doc/GetClrmap.3.

11
12
13
14
15
16
17
18

19
20

21
22

23
24
25
26
27
28
29
30
11
12
13
14
15
16
17

18
19

20
21

22

23
24
25
26
27
28
29







-
+

-
+

-
+
-







.SH NAME
Tk_GetColormap, Tk_PreserveColormap, Tk_FreeColormap \- allocate and free colormaps
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Colormap
\fBTk_GetColormap\fR(\fIinterp, tkwin, string\fR)
\fBTk_GetColormap(\fIinterp, tkwin, string\fB)\fR
.sp
\fBTk_PreserveColormap\fR(\fIdisplay, colormap\fR)
\fBTk_PreserveColormap(\fIdisplay, colormap\fB)\fR
.sp
\fBTk_FreeColormap\fR(\fIdisplay, colormap\fR)
\fBTk_FreeColormap(\fIdisplay, colormap\fB)\fR
.fi
.SH ARGUMENTS
.AS "Colormap" colormap
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Token for window in which colormap will be used.
.AP "const char" *string in

Changes to doc/GetColor.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27

28
29
30

31
32
33

34
35

36
37

38
39
40
41
42
43
44
45
11
12
13
14
15
16
17

18
19
20

21
22
23

24
25
26

27
28
29

30
31
32

33
34

35
36

37

38
39
40
41
42
43
44







-
+


-
+


-
+


-
+


-
+


-
+

-
+

-
+
-







.SH NAME
Tk_AllocColorFromObj, Tk_GetColor, Tk_GetColorFromObj, Tk_GetColorByValue, Tk_NameOfColor, Tk_FreeColorFromObj, Tk_FreeColor \- maintain database of colors
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
XColor *
\fBTk_AllocColorFromObj\fR(\fIinterp, tkwin, objPtr\fR)
\fBTk_AllocColorFromObj(\fIinterp, tkwin, objPtr\fB)\fR
.sp
XColor *
\fBTk_GetColor\fR(\fIinterp, tkwin, name\fR)
\fBTk_GetColor(\fIinterp, tkwin, name\fB)\fR
.sp
XColor *
\fBTk_GetColorFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_GetColorFromObj(\fItkwin, objPtr\fB)\fR
.sp
XColor *
\fBTk_GetColorByValue\fR(\fItkwin, prefPtr\fR)
\fBTk_GetColorByValue(\fItkwin, prefPtr\fB)\fR
.sp
const char *
\fBTk_NameOfColor\fR(\fIcolorPtr\fR)
\fBTk_NameOfColor(\fIcolorPtr\fB)\fR
.sp
GC
\fBTk_GCForColor\fR(\fIcolorPtr, drawable\fR)
\fBTk_GCForColor(\fIcolorPtr, drawable\fB)\fR
.sp
\fBTk_FreeColorFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_FreeColorFromObj(\fItkwin, objPtr\fB)\fR
.sp
\fBTk_FreeColor\fR(\fIcolorPtr\fR)
\fBTk_FreeColor(\fIcolorPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *colorPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Token for window in which color will be used.
.AP Tcl_Obj *objPtr in/out
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90







-










-







.PP
Given a textual description of a color, \fBTk_AllocColorFromObj\fR
locates a pixel value that may be used to render the color
in a particular window.  The desired color is specified with a
value whose string value must have one of the following forms:
.TP 20
\fIcolorname\fR
.
Any of the valid textual names for a color defined in the
server's color database file, such as \fBred\fR or \fBPeachPuff\fR.
.TP 20
\fB#\fIRGB\fR
.TP 20
\fB#\fIRRGGBB\fR
.TP 20
\fB#\fIRRRGGGBBB\fR
.TP 20
\fB#\fIRRRRGGGGBBBB\fR
.
A numeric specification of the red, green, and blue intensities
to use to display the color.  Each \fIR\fR, \fIG\fR, or \fIB\fR
represents a single hexadecimal digit.  The four forms permit
colors to be specified with 4-bit, 8-bit, 12-bit or 16-bit values.
When fewer than 16 bits are provided for each color, they represent
the most significant bits of the color, while the lower unfilled
bits will be repeatedly replicated from the available higher bits.

Changes to doc/GetCursor.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27

28
29
30

31
32

33
34

35
36
37
38
39
40
41
42
11
12
13
14
15
16
17

18
19
20

21
22
23

24
25
26

27
28
29

30
31

32
33

34

35
36
37
38
39
40
41







-
+


-
+


-
+


-
+


-
+

-
+

-
+
-







.SH NAME
Tk_AllocCursorFromObj, Tk_GetCursor, Tk_GetCursorFromObj, Tk_GetCursorFromData, Tk_NameOfCursor, Tk_FreeCursorFromObj, Tk_FreeCursor \- maintain database of cursors
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Cursor
\fBTk_AllocCursorFromObj\fR(\fIinterp, tkwin, objPtr\fR)
\fBTk_AllocCursorFromObj(\fIinterp, tkwin, objPtr\fB)\fR
.sp
Tk_Cursor
\fBTk_GetCursor\fR(\fIinterp, tkwin, name\fR)
\fBTk_GetCursor(\fIinterp, tkwin, name\fB)\fR
.sp
Tk_Cursor
\fBTk_GetCursorFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_GetCursorFromObj(\fItkwin, objPtr\fB)\fR
.sp
Tk_Cursor
\fBTk_GetCursorFromData\fR(\fIinterp, tkwin, source, mask, width, height, xHot, yHot, fg, bg\fR)
\fBTk_GetCursorFromData(\fIinterp, tkwin, source, mask, width, height, xHot, yHot, fg, bg\fB)\fR
.sp
const char *
\fBTk_NameOfCursor\fR(\fIdisplay, cursor\fR)
\fBTk_NameOfCursor(\fIdisplay, cursor\fB)\fR
.sp
\fBTk_FreeCursorFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_FreeCursorFromObj(\fItkwin, objPtr\fB)\fR
.sp
\fBTk_FreeCursor\fR(\fIdisplay, cursor\fR)
\fBTk_FreeCursor(\fIdisplay, cursor\fB)\fR
.fi
.SH ARGUMENTS
.AS "unsigned long" *pixelPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Token for window in which the cursor will be used.
.AP Tcl_Obj *objPtr in/out
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
83
84
85
86
87
88
89

90
91
92
93
94
95
96







-







\fBTk_GetCursorFromObj\fR. If an error occurs in creating the cursor,
such as when \fIobjPtr\fR refers to a non-existent file, then \fBNone\fR
is returned and an error message will be stored in \fIinterp\fR's result
if \fIinterp\fR is not NULL.  \fIObjPtr\fR must contain a standard Tcl
list with one of the following forms:
.TP
\fIname\fR\0[\fIfgColor\fR\0[\fIbgColor\fR]]
.
\fIName\fR is the name of a cursor in the standard X cursor cursor,
i.e., any of the names defined in \fBcursorcursor.h\fR, without
the \fBXC_\fR.  Some example values are \fBX_cursor\fR, \fBhand2\fR,
or \fBleft_ptr\fR.  Appendix B of
.QW "The X Window System"
by Scheifler & Gettys has illustrations showing what each of these
cursors looks like.  If \fIfgColor\fR and \fIbgColor\fR are both
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126

127
128
129
130
131
132

133
134
135
136
137
138
139







-









-






-







name of the resource.  The application and all its open
dynamic library's resource files will be searched for the named
cursor.  If there are conflicts color cursors will always be loaded
in preference to black and white cursors.
.RE
.TP
\fB@\fIsourceName\0maskName\0fgColor\0bgColor\fR
.
In this form, \fIsourceName\fR and \fImaskName\fR are the names of
files describing cursors for the cursor's source bits and mask.
Each file must be in standard X11 cursor format.
\fIFgColor\fR and \fIbgColor\fR
indicate the colors to use for the
cursor, in any of the forms acceptable to \fBTk_GetColor\fR.  This
form of the command will not work on Macintosh or Windows computers.
.TP
\fB@\fIsourceName\0fgColor\fR
.
This form is similar to the one above, except that the source is
used as mask also.  This means that the cursor's background is
transparent.  This form of the command will not work on Macintosh
or Windows computers.
.TP
\fB@\fIsourceName\fR
.
This form only works on Windows, and will load a Windows system
cursor (\fB.ani\fR or \fB.cur\fR) from the file specified in
\fIsourceName\fR.
.PP
\fBTk_GetCursor\fR is identical to \fBTk_AllocCursorFromObj\fR except
that the description of the cursor is specified with a string instead
of an object.  This prevents \fBTk_GetCursor\fR from caching the
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206







-
+







The procedure \fBTk_NameOfCursor\fR is roughly the inverse of
\fBTk_GetCursor\fR.  If its \fIcursor\fR argument was created
by \fBTk_GetCursor\fR, then the return value is the \fIname\fR
argument that was passed to \fBTk_GetCursor\fR to create the
cursor.  If \fIcursor\fR was created by a call to \fBTk_GetCursorFromData\fR,
or by any other mechanism, then the return value is a hexadecimal string
giving the X identifier for the cursor.
Note that the string returned by \fBTk_NameOfCursor\fR is
Note:  the string returned by \fBTk_NameOfCursor\fR is
only guaranteed to persist until the next call to
\fBTk_NameOfCursor\fR.  Also, this call is not portable except for
cursors returned by \fBTk_GetCursor\fR.
.PP
When a cursor returned by \fBTk_AllocCursorFromObj\fR, \fBTk_GetCursor\fR,
or \fBTk_GetCursorFromData\fR
is no longer needed, \fBTk_FreeCursorFromObj\fR or

Changes to doc/GetFont.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18

19
20
21

22
23
24

25
26
27
28
29
30

31
32
33

34

35

36
37
38
39
40
41
42
43
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17

18
19
20

21
22
23

24
25



26

27
28
29

30
31
32

33

34
35
36
37
38
39
40











-
+





-
+


-
+


-
+

-
-
-

-
+


-
+

+
-
+
-







'\"
'\" Copyright (c) 1990-1992 The Regents of the University of California.
'\" Copyright (c) 1994-1998 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH Tk_AllocFontFromObj 3 8.1 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_AllocFontFromObj, Tk_GetFont, Tk_GetFontFromObj, Tk_NameOfFont, Tk_FontGetDescription, Tk_FreeFontFromObj, Tk_FreeFont \- maintain database of fonts
Tk_AllocFontFromObj, Tk_GetFont, Tk_GetFontFromObj, Tk_NameOfFont, Tk_FreeFontFromObj, Tk_FreeFont \- maintain database of fonts
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Font
\fBTk_AllocFontFromObj\fR(\fIinterp, tkwin, objPtr\fR)
\fBTk_AllocFontFromObj(\fIinterp, tkwin, objPtr\fB)\fR
.sp
Tk_Font
\fBTk_GetFont\fR(\fIinterp, tkwin, string\fR)
\fBTk_GetFont(\fIinterp, tkwin, string\fB)\fR
.sp
Tk_Font
\fBTk_GetFontFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_GetFontFromObj(\fItkwin, objPtr\fB)\fR
.sp
Tcl_Obj *
\fBTk_FontGetDescription\fR(\fItkfont\fR)
.sp
const char *
\fBTk_NameOfFont\fR(\fItkfont\fR)
\fBTk_NameOfFont(\fItkfont\fB)\fR
.sp
Tk_Font
\fBTk_FreeFontFromObj\fR(\fItkwin, objPtr\fR)
\fBTk_FreeFontFromObj(\fItkwin, objPtr\fB)\fR
.sp
void
\fBTk_FreeFont\fR(\fItkfont\fR)
\fBTk_FreeFont(\fItkfont\fB)\fR
.fi
.SH ARGUMENTS
.AS "const char" *tkfont
.AP "Tcl_Interp" *interp in
Interpreter to use for error reporting.  If \fBNULL\fR, then no error
messages are left after errors.
.AP Tk_Window tkwin in
Token for window in which font will be used.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
84
85
86
87
88
89
90




91
92
93
94
95
96
97







-
-
-
-







\fBTk_AllocFontFromObj\fR and \fBTk_GetFont\fR maintain
a database of all fonts they have allocated.  If
the same font is requested multiple times (e.g. by different
windows or for different purposes), then a single Tk_Font will be
shared for all uses.  The underlying resources will be freed automatically
when no-one is using the font anymore.
.PP
The procedure \fBTk_FontGetDescription\fR returns information about the font
description as a Tcl list. One possible result is
.QW "{{DejaVu Sans} -16 bold underline}" .
.PP
The procedure \fBTk_NameOfFont\fR is roughly the inverse of
\fBTk_GetFont\fR.  Given a \fItkfont\fR that was created by
\fBTk_GetFont\fR (or \fBTk_AllocFontFromObj\fR), the return value is
the \fIstring\fR argument that was
passed to \fBTk_GetFont\fR to create the font.  The string returned by
\fBTk_NameOfFont\fR is only guaranteed to persist until the \fItkfont\fR
is deleted.  The caller must not modify this string.

Changes to doc/GetGC.3.

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
13
14
15
16
17
18
19

20

21
22
23
24
25
26
27







-
+
-







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
GC
\fBTk_GetGC\fR(\fItkwin, valueMask, valuePtr\fR)
.sp
\fBTk_FreeGC\fR(\fIdisplay, gc\fR)
\fBTk_FreeGC(\fIdisplay, gc\fR)
.fi
.SH ARGUMENTS
.AS "unsigned long" valueMask
.AP Tk_Window tkwin in
Token for window in which the graphics context will be used.
.AP "unsigned long" valueMask in
Mask of bits (such as \fBGCForeground\fR or \fBGCStipple\fR)
indicating which fields of \fI*valuePtr\fR are valid.

Changes to doc/GetHINSTANCE.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22

-
+













-







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH Tk_GetHISTANCE 3 "" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_GetHINSTANCE \- retrieve the global application instance handle
.SH SYNOPSIS
.nf
\fB#include <tkPlatDecls.h>\fR
.sp
HINSTANCE
\fBTk_GetHINSTANCE\fR()
.fi
.BE
.SH DESCRIPTION
.PP
\fBTk_GetHINSTANCE\fR returns the Windows application instance handle
for the Tk application.  This function is only available on Windows platforms.
.SH KEYWORDS
identifier, instance

Changes to doc/GetHWND.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25

-
+
















-







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH HWND 3 8.0 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_GetHWND, Tk_AttachHWND \- manage interactions between the Windows handle and an X window
.SH SYNOPSIS
.nf
\fB#include <tkPlatDecls.h>\fR
.sp
HWND
\fBTk_GetHWND\fR(\fIwindow\fR)
.sp
Window
\fBTk_AttachHWND\fR(\fItkwin, hwnd\fR)
.fi
.SH ARGUMENTS
.AP Window window in
X token for window.
.AP Tk_Window tkwin in
Tk window for window.
.AP HWND hwnd in
Windows HWND for window.

Changes to doc/GetImage.3.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-










-
+







\fBTk_GetImage\fR(\fIinterp, tkwin, name, changeProc, clientData\fR)
.sp
\fBTk_RedrawImage\fR(\fIimage, imageX, imageY, width, height, drawable, drawableX, drawableY\fR)
.sp
\fBTk_SizeOfImage\fR(\fIimage, widthPtr, heightPtr\fR)
.sp
\fBTk_FreeImage\fR(\fIimage\fR)
.fi
.SH ARGUMENTS
.AS Tk_ImageChangedProc *changeProc
.AP Tcl_Interp *interp in
Place to leave error message.
.AP Tk_Window tkwin in
Window in which image will be used.
.AP "const char" *name in
Name of image.
.AP Tk_ImageChangedProc *changeProc in
Procedure for Tk to invoke whenever image content or size changes.
.AP void *clientData in
.AP ClientData clientData in
One-word value for Tk to pass to \fIchangeProc\fR.
.AP Tk_Image image in
Token for image instance;  must have been returned by a previous
call to \fBTk_GetImage\fR.
.AP int imageX in
X-coordinate of upper-left corner of region of image to redisplay
(measured in pixels from the image's upper-left corner).
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
+







they can redisplay themselves.
The \fIchangeProc\fR and \fIclientData\fR arguments to
\fBTk_GetImage\fR are used for this purpose.
\fIchangeProc\fR will be called by Tk whenever a change occurs
in the image;  it must match the following prototype:
.CS
typedef void \fBTk_ImageChangedProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        int \fIx\fR,
        int \fIy\fR,
        int \fIwidth\fR,
        int \fIheight\fR,
        int \fIimageWidth\fR,
        int \fIimageHeight\fR);
.CE

Changes to doc/GetJoinStl.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24
25
26
27
28
29
11
12
13
14
15
16
17

18
19
20

21

22
23
24
25
26
27
28







-
+


-
+
-







.SH NAME
Tk_GetJoinStyle, Tk_NameOfJoinStyle \- translate between strings and join styles
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetJoinStyle\fR(\fIinterp, string, joinPtr\fR)
\fBTk_GetJoinStyle(\fIinterp, string, joinPtr\fB)\fR
.sp
const char *
\fBTk_NameOfJoinStyle\fR(\fIjoin\fR)
\fBTk_NameOfJoinStyle(\fIjoin\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *joinPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP "const char" *string in
String containing name of join style \- one of
.QW \fBbevel\fR ,

Changes to doc/GetJustify.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27
28
29
30
31
32
11
12
13
14
15
16
17

18
19
20

21
22
23

24

25
26
27
28
29
30
31







-
+


-
+


-
+
-







.SH NAME
Tk_GetJustifyFromObj, Tk_GetJustify, Tk_NameOfJustify \- translate between strings and justification styles
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetJustifyFromObj\fR(\fIinterp, objPtr, justifyPtr\fR)
\fBTk_GetJustifyFromObj(\fIinterp, objPtr, justifyPtr\fB)\fR
.sp
int
\fBTk_GetJustify\fR(\fIinterp, string, justifyPtr\fR)
\fBTk_GetJustify(\fIinterp, string, justifyPtr\fB)\fR
.sp
const char *
\fBTk_NameOfJustify\fR(\fIjustify\fR)
\fBTk_NameOfJustify(\fIjustify\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tk_Justify" *justifyPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting, or NULL.
.AP Tcl_Obj *objPtr in/out
String value contains name of justification style \- one of
.QW \fBleft\fR ,
45
46
47
48
49
50
51

52

53
54

55

56
57

58

59
60
61
62
63
64
65
44
45
46
47
48
49
50
51

52
53
54
55

56
57
58
59

60
61
62
63
64
65
66
67







+
-
+


+
-
+


+
-
+







Justification style (one of the values listed below).
.BE
.SH DESCRIPTION
.PP
\fBTk_GetJustifyFromObj\fR places in \fI*justifyPtr\fR the justify value
corresponding to \fIobjPtr\fR's value.
This value will be one of the following:
.TP
.IP \fBTK_JUSTIFY_LEFT\fR
\fBTK_JUSTIFY_LEFT\fR
Means that the text on each line should start at the left edge of
the line;  as a result, the right edges of lines may be ragged.
.TP
.IP \fBTK_JUSTIFY_RIGHT\fR
\fBTK_JUSTIFY_RIGHT\fR
Means that the text on each line should end at the right edge of
the line;  as a result, the left edges of lines may be ragged.
.TP
.IP \fBTK_JUSTIFY_CENTER\fR
\fBTK_JUSTIFY_CENTER\fR
Means that the text on each line should be centered;  as a result,
both the left and right edges of lines may be ragged.
.PP
Under normal circumstances the return value is \fBTCL_OK\fR and
\fIinterp\fR is unused.
If \fIobjPtr\fR does not contain a valid justification style
or an abbreviation of one of these names, \fBTCL_ERROR\fR is returned,

Changes to doc/GetOption.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_GetOption \- retrieve an option from the option database
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Uid
\fBTk_GetOption\fR(\fItkwin, name, class\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window *class
.AP Tk_Window tkwin in
Token for window.
.AP "const char" *name in
Name of desired option.
.AP "const char" *class in

Changes to doc/GetPixels.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18

19
20
21
22
23
24

25
26
27

28
29
30

31
32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17

18
19
20




21
22
23

24
25
26

27

28
29
30
31
32
33
34











-
+





-
+


-
-
-
-
+


-
+


-
+
-







'\"
'\" Copyright (c) 1990 The Regents of the University of California.
'\" Copyright (c) 1994-1998 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH Tk_GetPixelsFromObj 3 8.1 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_GetPixelsFromObj, Tk_GetPixels, Tk_GetMMFromObj, Tk_GetScreenMM, Tk_GetDoublePixelsFromObj \- translate between strings and screen units
Tk_GetPixelsFromObj, Tk_GetPixels, Tk_GetMMFromObj, Tk_GetScreenMM \- translate between strings and screen units
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetPixelsFromObj\fR(\fIinterp, tkwin, objPtr, intPtr\fR)
\fBTk_GetPixelsFromObj(\fIinterp, tkwin, objPtr, intPtr\fB)\fR
.sp
int
\fBTk_GetDoublePixelsFromObj\fR(\fIinterp, tkwin, objPtr, doublePtr\fR)
.sp
int
\fBTk_GetPixels\fR(\fIinterp, tkwin, string, intPtr\fR)
\fBTk_GetPixels(\fIinterp, tkwin, string, intPtr\fB)\fR
.sp
int
\fBTk_GetMMFromObj\fR(\fIinterp, tkwin, objPtr, doublePtr\fR)
\fBTk_GetMMFromObj(\fIinterp, tkwin, objPtr, doublePtr\fB)\fR
.sp
int
\fBTk_GetScreenMM\fR(\fIinterp, tkwin, string, doublePtr\fR)
\fBTk_GetScreenMM(\fIinterp, tkwin, string, doublePtr\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *joinPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Window whose screen geometry determines the conversion between absolute
units and pixels.
53
54
55
56
57
58
59

60

61

62

63

64

65

66

67

68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
49
50
51
52
53
54
55
56

57
58
59

60
61
62

63
64
65

66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83



84
85
86
87
88
89
90
91
92
93
94
95







+
-
+

+
-
+

+
-
+

+
-
+

+
-
+














-
-
-












the screen (\fIobjPtr\fR or \fIstring\fR) and compute the
corresponding distance either in integer pixels or floating-point millimeters.
In either case,
\fIobjPtr\fR or \fIstring\fR
specifies a screen distance as a
floating-point number followed by one of the following characters
that indicates units:
.TP
.IP <none>
<none>
The number specifies a distance in pixels.
.TP
.IP \fBc\fR
\fBc\fR
The number specifies a distance in centimeters on the screen.
.TP
.IP \fBi\fR
\fBi\fR
The number specifies a distance in inches on the screen.
.TP
.IP \fBm\fR
\fBm\fR
The number specifies a distance in millimeters on the screen.
.TP
.IP \fBp\fR
\fBp\fR
The number specifies a distance in printer's points (1/72 inch)
on the screen.
.PP
\fBTk_GetPixelsFromObj\fR converts the value of \fIobjPtr\fR to the
nearest even number of pixels and stores that value at \fI*intPtr\fR.
It returns \fBTCL_OK\fR under normal circumstances.
If an error occurs (e.g. \fIobjPtr\fR contains a number followed
by a character that is not one of the ones above) then
\fBTCL_ERROR\fR is returned and an error message is left
in \fIinterp\fR's result if \fIinterp\fR is not NULL.
\fBTk_GetPixelsFromObj\fR caches information about the return
value in \fIobjPtr\fR, which speeds up future calls to
\fBTk_GetPixelsFromObj\fR with the same \fIobjPtr\fR.
.PP
\fBTk_GetDoublePixelsFromObj\fR is identical to \fBTk_GetPixelsFromObj\fR
except it returns a double not rounded to the nearest integer.
.PP
\fBTk_GetPixels\fR is identical to \fBTk_GetPixelsFromObj\fR except
that the screen distance is specified with a string instead
of an object.  This prevents \fBTk_GetPixels\fR from caching the
return value, so \fBTk_GetPixels\fR is less efficient than
\fBTk_GetPixelsFromObj\fR.
.PP
\fBTk_GetMMFromObj\fR and \fBTk_GetScreenMM\fR are similar to
\fBTk_GetPixelsFromObj\fR and \fBTk_GetPixels\fR (respectively) except
that they convert the screen distance to millimeters and
store a double-precision floating-point result at \fI*doublePtr\fR.
.SH KEYWORDS
centimeters, convert, inches, millimeters, pixels, points, screen units

Changes to doc/GetPixmap.3.

11
12
13
14
15
16
17
18

19
20

21
22
23
24
25
26
27
28
11
12
13
14
15
16
17

18
19

20

21
22
23
24
25
26
27







-
+

-
+
-







.SH NAME
Tk_GetPixmap, Tk_FreePixmap \- allocate and free pixmaps
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Pixmap
\fBTk_GetPixmap\fR(\fIdisplay, d, width, height, depth\fR)
\fBTk_GetPixmap(\fIdisplay, d, width, height, depth\fB)\fR
.sp
\fBTk_FreePixmap\fR(\fIdisplay, pixmap\fR)
\fBTk_FreePixmap(\fIdisplay, pixmap\fB)\fR
.fi
.SH ARGUMENTS
.AS "Drawable" *pixelPtr
.AP Display *display in
X display for the pixmap.
.AP Drawable d in
Pixmap or window where the new pixmap will be used for drawing.
.AP "int" width in

Changes to doc/GetRelief.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24

25
26
27
28
29
30
31
32
11
12
13
14
15
16
17

18
19
20

21
22
23

24

25
26
27
28
29
30
31







-
+


-
+


-
+
-







.SH NAME
Tk_GetReliefFromObj, Tk_GetRelief, Tk_NameOfRelief \- translate between strings and relief values
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetReliefFromObj\fR(\fIinterp, objPtr, reliefPtr\fR)
\fBTk_GetReliefFromObj(\fIinterp, objPtr, reliefPtr\fB)\fR
.sp
int
\fBTk_GetRelief\fR(\fIinterp, name, reliefPtr\fR)
\fBTk_GetRelief(\fIinterp, name, reliefPtr\fB)\fR
.sp
const char *
\fBTk_NameOfRelief\fR(\fIrelief\fR)
\fBTk_NameOfRelief(\fIrelief\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *reliefPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tcl_Obj *objPtr in/out
String value contains name of relief, one of
.QW \fBflat\fR ,

Changes to doc/GetRootCrd.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







.SH NAME
Tk_GetRootCoords \- Compute root-window coordinates of window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_GetRootCoords\fR(\fItkwin, xPtr, yPtr\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP Tk_Window tkwin in
Token for window.
.AP int *xPtr out
Pointer to location in which to store root-window x-coordinate
corresponding to left edge of \fItkwin\fR's border.

Changes to doc/GetScroll.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24
25
26
27

28
29

30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57
58

59
60
61
62
63
64
65
66



67
68
69
70
71
72
73
74
75
76
77
11
12
13
14
15
16
17

18
19
20

21

22
23
24
25

26
27

28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56

57
58
59
60
61
62



63
64
65

66
67
68
69
70
71
72
73
74
75







-
+


-
+
-




-
+

-
+





-
+


















-
-
+
+


-
+





-
-
-
+
+
+
-










.SH NAME
Tk_GetScrollInfoObj, Tk_GetScrollInfo \- parse arguments for scrolling commands
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetScrollInfoObj\fR(\fIinterp, objc, objv, fractionPtr, stepsPtr\fR)
\fBTk_GetScrollInfoObj(\fIinterp, objc, objv, dblPtr, intPtr\fB)\fR
.sp
int
\fBTk_GetScrollInfo\fR(\fIinterp, argc, argv, fractionPtr, stepsPtr\fR)
\fBTk_GetScrollInfo(\fIinterp, argc, argv, dblPtr, intPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *fractionPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tcl_Size objc in
.AP int objc in
Number of Tcl_Obj's in \fIobjv\fR array.
.AP "Tcl_Obj *const *" objv in
.AP "Tcl_Obj *const" objv[] in
Argument objects.  These represent the entire widget command, of
which the first word is typically the widget name and the second
word is typically \fBxview\fR or \fByview\fR.
.AP int argc in
Number of strings in \fIargv\fR array.
.AP "const char **" argv in
.AP "const char" *argv[] in
Argument strings.  These represent the entire widget command, of
which the first word is typically the widget name and the second
word is typically \fBxview\fR or \fByview\fR.
.AP double *fractionPtr out
Filled in with fraction from \fBmoveto\fR option, if any.
.AP int *stepsPtr out
Filled in with line or page count from \fBscroll\fR option, if any.
The value may be negative.
.BE
.SH DESCRIPTION
.PP
\fBTk_GetScrollInfoObj\fR parses the arguments expected by widget
scrolling commands such as \fBxview\fR and \fByview\fR.
It receives the entire list of words that make up a widget command
and parses the words starting with \fIobjv\fR[2].
The words starting with \fIobjv\fR[2] must have one of the following forms:
.CS
\fBmoveto \fIfraction\fR
\fBscroll \fInumber\fB pages\fR
\fBscroll \fInumber\fB units\fR
\fBscroll \fInumber\fB units\fR
\fBscroll \fInumber\fB pages\fR
.CE
.LP
Any of the \fBmoveto\fR, \fBscroll\fR, \fBpages\fR, and \fBunits\fR
Any of the \fBmoveto\fR, \fBscroll\fR, \fBunits\fR, and \fBpages\fR
keywords may be abbreviated.
If \fIobjv\fR has the \fBmoveto\fR form, \fBTK_SCROLL_MOVETO\fR
is returned as result and \fI*fractionPtr\fR is filled in with the
\fIfraction\fR argument to the command, which must be a proper real
value.
If \fIobjv\fR has the \fBscroll\fR form, \fBTK_SCROLL_PAGES\fR
or \fBTK_SCROLL_UNITS\fR is returned and \fI*stepsPtr\fR is filled
in with the \fInumber\fR value, which must be a  integer or a float,
If \fIobjv\fR has the \fBscroll\fR form, \fBTK_SCROLL_UNITS\fR
or \fBTK_SCROLL_PAGES\fR is returned and \fI*stepsPtr\fR is filled
in with the \fInumber\fR value, which must be a proper integer.
but if it is a float then it is converted to an integer, rounded away from 0.
If an error occurs in parsing the arguments, \fBTK_SCROLL_ERROR\fR
is returned and an error message is left in interpreter
\fIinterp\fR's result.
.PP
\fBTk_GetScrollInfo\fR is identical in function to
\fBTk_GetScrollInfoObj\fR.  However, \fBTk_GetScrollInfo\fR accepts
string arguments, making it more appropriate for use with legacy
widgets.
.SH KEYWORDS
parse, scrollbar, scrolling command, xview, yview

Changes to doc/GetSelect.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54







-














-
+













-
+







Tk_GetSelection \- retrieve the contents of a selection
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_GetSelection\fR(\fIinterp, tkwin, selection, target, proc, clientData\fR)
.fi
.SH ARGUMENTS
.AS Tk_GetSelProc clientData
.AP Tcl_Interp *interp in
Interpreter to use for reporting errors.
.AP Tk_Window tkwin in
Window on whose behalf to retrieve the selection (determines
display from which to retrieve).
.AP Atom selection in
The name of the selection to be retrieved.
.AP Atom target in
Form in which to retrieve selection.
.AP Tk_GetSelProc *proc in
Procedure to invoke to process pieces of the selection as they
are retrieved.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.BE
.SH DESCRIPTION
.PP
\fBTk_GetSelection\fR retrieves the selection specified by the atom
\fIselection\fR in the format specified by \fItarget\fR.  The
selection may actually be retrieved in several pieces; as each piece
is retrieved, \fIproc\fR is called to process the piece.  \fIProc\fR
should have arguments and result that match the type
\fBTk_GetSelProc\fR:
.PP
.CS
typedef int \fBTk_GetSelProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        Tcl_Interp *\fIinterp\fR,
        char *\fIportion\fR);
.CE
.PP
The \fIclientData\fR and \fIinterp\fR parameters to \fIproc\fR
will be copies of the corresponding arguments to
\fBTk_GetSelection\fR.  \fIPortion\fR will be a pointer to

Changes to doc/GetUid.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_GetUid, Tk_Uid \- convert from string to unique identifier
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Uid
\fBTk_GetUid\fR(\fIstring\fR)
.fi
.SH ARGUMENTS
.AP char *string in
String for which the corresponding unique identifier is
desired.
.BE
.SH DESCRIPTION
.PP

Changes to doc/GetVRoot.3.

10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24







-
+
-







.BS
.SH NAME
Tk_GetVRootGeometry \- Get location and size of virtual root for window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_GetVRootGeometry\fR(\fItkwin, xPtr, yPtr, widthPtr, heightPtr\fR)
\fBTk_GetVRootGeometry(\fItkwin, xPtr, yPtr, widthPtr, heightPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS Tk_Window heightPtr
.AP Tk_Window tkwin in
Token for window whose virtual root is to be queried.
.AP int xPtr out
Points to word in which to store x-offset of virtual root.
.AP int yPtr out

Changes to doc/GetVisual.3.

11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
11
12
13
14
15
16
17

18

19
20
21
22
23
24
25







-
+
-







.SH NAME
Tk_GetVisual \- translate from string to visual
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Visual *
\fBTk_GetVisual\fR(\fIinterp, tkwin, string, depthPtr, colormapPtr\fR)
\fBTk_GetVisual(\fIinterp, tkwin, string, depthPtr, colormapPtr\fB)\fR
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" *colormapPtr
.AP Tcl_Interp *interp in
Interpreter to use for error reporting.
.AP Tk_Window tkwin in
Token for window in which the visual will be used.
.AP "const char" *string in
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67

68
69
70
71
72

73
74
75

76
77
78
79
80
81
82







-














-



-





-



-







also locates an appropriate colormap for use with the result visual
and stores its X identifier at \fI*colormapPtr\fR.
.PP
The \fIstring\fR argument specifies the desired visual in one
of the following ways:
.TP 15
\fIclass depth\fR
.
The string consists of a class name followed by an integer depth,
with any amount of white space (including none) in between.
\fIclass\fR selects what sort of visual is desired and must be one of
\fBdirectcolor\fR, \fBgrayscale\fR, \fBgreyscale\fR, \fBpseudocolor\fR,
\fBstaticcolor\fR, \fBstaticgray\fR, \fBstaticgrey\fR, or
\fBtruecolor\fR, or a unique abbreviation.
\fIdepth\fR specifies how many bits per pixel are needed for the
visual.
If possible, \fBTk_GetVisual\fR will return a visual with this depth;
if there is no visual of the desired depth then \fBTk_GetVisual\fR
looks first for a visual with greater depth, then one with less
depth.
.TP 15
\fBdefault\fR
.
Use the default visual for \fItkwin\fR's screen.
.TP 15
\fIpathName\fR
.
Use the visual for the window given by \fIpathName\fR.
\fIpathName\fR must be the name of a window on the same screen
as \fItkwin\fR.
.TP 15
\fInumber\fR
.
Use the visual whose X identifier is \fInumber\fR.
.TP 15
\fBbest\fR ?\fIdepth\fR?
.
Choose the
.QW "best possible"
visual, using the following rules, in decreasing order of priority:
.RS
.IP (a)
a visual that has exactly the desired depth is best, followed
by a visual with greater depth than requested (but as little extra

Changes to doc/Grab.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25

-
+














+

-







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH Tk_Grab 3 "" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_Grab, Tk_Ungrab \- manipulate grab state in an application
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_Grab\fR(\fIinterp, tkwin, grabGlobal\fR)
.sp
void
\fBTk_Ungrab\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AP Tcl_Interp *interp in
Interpreter to use for error reporting
.AP Tk_Window tkwin in
Window on whose behalf the pointer is to be grabbed or released
.AP int grabGlobal in
Boolean indicating whether the grab is global or application local

Changes to doc/HWNDToWindow.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22

-
+













-







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH Tk_HWNDToWindow 3 "" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_HWNDToWindow \- Find Tk's window information for a Windows window
.SH SYNOPSIS
.nf
\fB#include <tkPlatDecls.h>\fR
.sp
Tk_Window
\fBTk_HWNDToWindow\fR(\fIhwnd\fR)
.fi
.SH ARGUMENTS
.AP HWND hwnd in
Windows handle for the window.
.BE
.SH DESCRIPTION
.PP
Given a Windows HWND window identifier, this procedure returns the

Changes to doc/HandleEvent.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35







-










-
+







.SH NAME
Tk_HandleEvent \- invoke event handlers for window system events
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_HandleEvent\fR(\fIeventPtr\fR)
.fi
.SH ARGUMENTS
.AS XEvent *eventPtr
.AP XEvent *eventPtr in
Pointer to X event to dispatch to relevant handler(s). It is important
that all unused fields of the structure be set to zero.
.BE
.SH DESCRIPTION
.PP
\fBTk_HandleEvent\fR is a lower-level procedure that deals with window
events.  It is called by \fBTcl_ServiceEvent\fR (and indirectly by
\fBTcl_DoOneEvent\fR), and in a few other cases within Tk.
\fBTk_DoOneEvent\fR), and in a few other cases within Tk.
It makes callbacks to any window event
handlers (created by calls to \fBTk_CreateEventHandler\fR)
that match \fIeventPtr\fR and then returns.  In some cases
it may be useful for an application to bypass the Tk event
queue and call \fBTk_HandleEvent\fR directly instead of
calling \fBTcl_QueueEvent\fR followed by
\fBTcl_ServiceEvent\fR.

Changes to doc/IdToWindow.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







Tk_IdToWindow \- Find Tk's window information for an X window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Window
\fBTk_IdToWindow\fR(\fIdisplay, window\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window display
.AP Display *display in
X display containing the window.
.AP Window window in
X id for window.
.BE

Changes to doc/ImgChanged.3.

10
11
12
13
14
15
16
17

18
19
20
21


22
23
24
25
26
27
28
10
11
12
13
14
15
16

17

18


19
20
21
22
23
24
25
26
27







-
+
-

-
-
+
+







.BS
.SH NAME
Tk_ImageChanged \- notify widgets that image needs to be redrawn
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_ImageChanged\fR(\fImodel, x, y, width, height, imageWidth, imageHeight\fR)
\fBTk_ImageChanged\fR(\fIimageMaster, x, y, width, height, imageWidth, imageHeight\fR)
.fi
.SH ARGUMENTS
.AS Tk_ImageModel imageHeight
.AP Tk_ImageModel model in
.AS Tk_ImageMaster imageHeight
.AP Tk_ImageMaster imageMaster in
Token for image, which was passed to image's \fIcreateProc\fR when
the image was created.
.AP int x in
X-coordinate of upper-left corner of region that needs redisplay (measured
from upper-left corner of image).
.AP int y in
Y-coordinate of upper-left corner of region that needs redisplay (measured
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+







.SH DESCRIPTION
.PP
An image manager calls \fBTk_ImageChanged\fR for an image
whenever anything happens that requires the image to be redrawn.
As a result of calling \fBTk_ImageChanged\fR, any widgets using
the image are notified so that they can redisplay themselves
appropriately.
The \fImodel\fR argument identifies the image, and
The \fIimageMaster\fR argument identifies the image, and
\fIx\fR, \fIy\fR, \fIwidth\fR, and \fIheight\fR
specify a rectangular region within the image that needs to
be redrawn.
\fIimageWidth\fR and \fIimageHeight\fR specify the image's (new) size.
.PP
An image manager should call \fBTk_ImageChanged\fR during
its \fIcreateProc\fR to specify the image's initial size and to

Changes to doc/Inactive.3.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15

16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
1

2
3
4
5
6
7
8
9
10
11
12
13
14

15
16

17

18
19
20
21
22
23
24
25
26
27
28


29
30
31
32
33
34

-
+












-
+

-
+
-











-
-
+
+




'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH Tk_GetUserInactiveTime 3 8.5 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_GetUserInactiveTime, Tk_ResetUserInactiveTime \- discover user inactivity time
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
long
\fBTk_GetUserInactiveTime\fR(\fIdisplay\fR)
\fBTk_GetUserInactiveTime(\fIdisplay\fB)\fR
.sp
\fBTk_ResetUserInactiveTime\fR(\fIdisplay\fR)
\fBTk_GetUserInactiveTime(\fIdisplay\fB)\fR
.fi
.SH ARGUMENTS
.AS Display *display
.AP Display *display in
The display on which the user inactivity timer is to be queried or
reset.
.BE
.SH DESCRIPTION
.PP
\fBTk_GetUserInactiveTime\fR returns the number of milliseconds that
have passed since the last user interaction (usually via keyboard or
mouse) with the respective display. On systems and displays that do not
support querying the user inactivity time, \fB\-1\fR is returned.
\fBTk_ResetUserInactiveTime\fR resets the user inactivity timer of the
support querying the user inactiviy time, \fB\-1\fR is returned.
\fBTk_GetUserInactiveTime\fR resets the user inactivity timer of the
given display to zero.  On windowing systems that do not support
multiple displays \fIdisplay\fR can be passed as \fBNULL\fR.
.SH KEYWORDS
idle, inactive

Changes to doc/InternAtom.3.

11
12
13
14
15
16
17
18

19
20
21

22
23
24
25
26
27
28
29
11
12
13
14
15
16
17

18
19
20

21

22
23
24
25
26
27
28







-
+


-
+
-







.SH NAME
Tk_InternAtom, Tk_GetAtomName \- manage cache of X atoms
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Atom
\fBTk_InternAtom\fR(\fItkwin, name\fR)
\fBTk_InternAtom(\fItkwin, name\fR)
.sp
const char *
\fBTk_GetAtomName\fR(\fItkwin, atom\fR)
\fBTk_GetAtomName(\fItkwin, atom\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window parent
.AP Tk_Window tkwin in
Token for window.  Used to map atom or name relative to a particular display.
.AP "const char" *name in
String name for which atom is desired.
.AP Atom atom in

Changes to doc/MainLoop.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







.SH NAME
Tk_MainLoop \- loop for events until all windows are deleted
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_MainLoop\fR()
.fi
.BE
.SH DESCRIPTION
.PP
\fBTk_MainLoop\fR is a procedure that loops repeatedly calling
\fBTcl_DoOneEvent\fR.  It returns only when there are no applications
left in this process (i.e. no main windows exist anymore).  Most
windowing applications will call \fBTk_MainLoop\fR after

Changes to doc/MainWin.3.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
13
14
15
16
17
18
19




20
21

22
23
24
25








26
27
28
29
30
31
32
33
34
35
36
37
38







39
40







-
-
-
-


-




-
-
-
-
-
-
-
-













-
-
-
-
-
-
-


.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Window
\fBTk_MainWindow\fR(\fIinterp\fR)
.sp
\fBTk_SetMainMenubar\fR(\fIinterp, tkwin, menuName\fR)
.sp
\fBTk_SetWindowMenubar\fR(\fIinterp, tkwin, oldMenuName, menuName\fR)
.sp
int
\fBTk_GetNumMainWindows\fR()
.fi
.SH ARGUMENTS
.AS Tcl_Interp *pathName
.AP Tcl_Interp *interp in/out
Interpreter associated with the application.
.AP Tk_Window tkwin in
Token for main window.
.AP const char *menuName in
The name of the new menubar that the toplevel needs to be set to.
NULL means that their is no menu now.
.AP const char *oldMenuName in
The name of the menubar previously set in this toplevel.
NULL means no menu was set previously.
.BE
.SH DESCRIPTION
.PP
A main window is a special kind of toplevel window used as the
outermost window in an application.
.PP
If \fIinterp\fR is associated with a Tk application then \fBTk_MainWindow\fR
returns the application's main window. If there is no Tk application
associated with \fIinterp\fR then \fBTk_MainWindow\fR returns NULL and
leaves an error message in interpreter \fIinterp\fR's result.
.PP
\fBTk_GetNumMainWindows\fR returns a count of the number of main
windows currently open in the current thread.
\fBTk_SetMainMenubar\fR
Called when a toplevel widget is brought to front. On the Macintosh,
sets up the menubar that goes across the top of the main monitor. On
other platforms, nothing is necessary.
\fBTk_SetWindowMenubar\fR associates a menu with a window.
The old menu clones for the menubar are thrown away, and a handler is
set up to allocate the new ones.
.SH KEYWORDS
application, main window

Changes to doc/MaintGeom.3.

10
11
12
13
14
15
16
17

18
19

20
21
22
23


24
25
26


27
28
29
30



31
32
33
34



35
36

37
38

39
40
41
42
43

44
45

46
47
48
49



50
51
52


53
54

55
56
57


58
59
60
61



62
63
64
65
66



67
68
69


70
71
72


73
74
75


76
77
78


79
80
81
82
83
84
85
86
87

88
89
90
91

92
93
94
95

96
97

98
99
100

10
11
12
13
14
15
16

17
18

19

20


21
22
23


24
25
26



27
28
29
30



31
32
33
34

35
36

37
38
39
40
41

42
43

44
45



46
47
48
49


50
51
52

53
54


55
56
57



58
59
60
61
62



63
64
65
66


67
68
69


70
71
72


73
74
75


76
77
78
79
80
81
82
83
84
85

86
87
88
89

90
91
92
93

94
95

96
97
98

99







-
+

-
+
-

-
-
+
+

-
-
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
+

-
+




-
+

-
+

-
-
-
+
+
+

-
-
+
+

-
+

-
-
+
+

-
-
-
+
+
+


-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+








-
+



-
+



-
+

-
+


-
+
.BS
.SH NAME
Tk_MaintainGeometry, Tk_UnmaintainGeometry \- maintain geometry of one window relative to another
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_MaintainGeometry\fR(\fIwindow, container, x, y, width, height\fR)
\fBTk_MaintainGeometry\fR(\fIslave, master, x, y, width, height\fR)
.sp
\fBTk_UnmaintainGeometry\fR(\fIwindow, container\fR)
\fBTk_UnmaintainGeometry\fR(\fIslave, master\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window container
.AP Tk_Window window in
.AS Tk_Window master
.AP Tk_Window slave in
Window whose geometry is to be controlled.
.AP Tk_Window container in
Window relative to which \fIwindow\fR's geometry will be controlled.
.AP Tk_Window master in
Window relative to which \fIslave\fR's geometry will be controlled.
.AP int x in
Desired x-coordinate of \fIwindow\fR in \fIcontainer\fR, measured in pixels
from the inside of \fIcontainer\fR's left border to the outside of
\fIwindow\fR's left border.
Desired x-coordinate of \fIslave\fR in \fImaster\fR, measured in pixels
from the inside of \fImaster\fR's left border to the outside of
\fIslave\fR's left border.
.AP int y in
Desired y-coordinate of \fIwindow\fR in \fIcontainer\fR, measured in pixels
from the inside of \fIcontainer\fR's top border to the outside of
\fIwindow\fR's top border.
Desired y-coordinate of \fIslave\fR in \fImaster\fR, measured in pixels
from the inside of \fImaster\fR's top border to the outside of
\fIslave\fR's top border.
.AP int width in
Desired width for \fIwindow\fR, in pixels.
Desired width for \fIslave\fR, in pixels.
.AP int height in
Desired height for \fIwindow\fR, in pixels.
Desired height for \fIslave\fR, in pixels.
.BE
.SH DESCRIPTION
.PP
\fBTk_MaintainGeometry\fR and \fBTk_UnmaintainGeometry\fR make it
easier for geometry managers to deal with windows whose containers are not
easier for geometry managers to deal with slaves whose masters are not
their parents.
Three problems arise if the container for a window is not its parent:
Three problems arise if the master for a slave is not its parent:
.IP [1]
The x- and y-position of the window must be translated from the
coordinate system of the container to that of the parent before
positioning the window.
The x- and y-position of the slave must be translated from the
coordinate system of the master to that of the parent before
positioning the slave.
.IP [2]
If the container window, or any of its ancestors up to the window's
parent, is moved, then the window must be repositioned within its
If the master window, or any of its ancestors up to the slave's
parent, is moved, then the slave must be repositioned within its
parent in order to maintain the correct position relative to the
container.
master.
.IP [3]
If the container or one of its ancestors is mapped or unmapped, then
the window must be mapped or unmapped to correspond.
If the master or one of its ancestors is mapped or unmapped, then
the slave must be mapped or unmapped to correspond.
.LP
None of these problems is an issue if the parent and container are
the same.  For example, if the container or one of its ancestors
is unmapped, the window is automatically removed by the screen
None of these problems is an issue if the parent and master are
the same.  For example, if the master or one of its ancestors
is unmapped, the slave is automatically removed by the screen
by X.
.PP
\fBTk_MaintainGeometry\fR deals with these problems for windows
whose containers are not their parents, as well as handling the simpler
case of windows whose container are their parents.
\fBTk_MaintainGeometry\fR deals with these problems for slaves
whose masters are not their parents, as well as handling the simpler
case of slaves whose masters are their parents.
\fBTk_MaintainGeometry\fR is typically called by a window manager
once it has decided where a window should be positioned relative
to its container.
once it has decided where a slave should be positioned relative
to its master.
\fBTk_MaintainGeometry\fR translates the coordinates to the
coordinate system of \fIwindow\fR's parent and then moves and
resizes the window appropriately.
coordinate system of \fIslave\fR's parent and then moves and
resizes the slave appropriately.
Furthermore, it remembers the desired position and creates event
handlers to monitor the container and all of its ancestors up
to (but not including) the window's parent.
handlers to monitor the master and all of its ancestors up
to (but not including) the slave's parent.
If any of these windows is moved, mapped, or unmapped,
the window will be adjusted so that it is mapped only when the
container is mapped and its geometry relative to the container
the slave will be adjusted so that it is mapped only when the
master is mapped and its geometry relative to the master
remains as specified by \fIx\fR, \fIy\fR, \fIwidth\fR, and
\fIheight\fR.
.PP
When a window manager relinquishes control over a window, or
if it decides that it does not want the window to appear on the
screen under any conditions, it calls \fBTk_UnmaintainGeometry\fR.
\fBTk_UnmaintainGeometry\fR unmaps the window and cancels any
previous calls to \fBTk_MaintainGeometry\fR for the
\fIcontainer\fR\-\fIwindow\fR pair, so that the window's
\fImaster\fR\-\fIslave\fR pair, so that the slave's
geometry and mapped state are no longer maintained
automatically.
\fBTk_UnmaintainGeometry\fR need not be called by a geometry
manager if the window, the container, or any of the container's ancestors
manager if the slave, the master, or any of the master's ancestors
is destroyed:  Tk will call it automatically.
.PP
If \fBTk_MaintainGeometry\fR is called repeatedly for the same
\fIcontainer\fR\-\fIwindow\fR pair, the information from the most
\fImaster\fR\-\fIslave\fR pair, the information from the most
recent call supersedes any older information.
If \fBTk_UnmaintainGeometry\fR is called for a \fIcontainer\fR\-\fIwindow\fR
If \fBTk_UnmaintainGeometry\fR is called for a \fImaster\fR\-\fIslave\fR
pair that is is not currently managed, the call has no effect.
.SH KEYWORDS
geometry manager, map, container, parent, position, window, unmap
geometry manager, map, master, parent, position, slave, unmap

Changes to doc/ManageGeom.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57

58
59
60
61
62

63
64
65
66
67
68
69
70
71

72
73

74
75
76

77
78
79
80
81

82
83
84
85


86
87
88

89
90
91
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55

56
57
58
59
60

61
62
63
64
65
66
67
68
69

70
71

72
73
74

75
76
77
78
79

80
81
82


83
84
85
86

87
88
89
90







-










-
+






-
+











-
+








-
+




-
+








-
+

-
+


-
+




-
+


-
-
+
+


-
+



.SH NAME
Tk_ManageGeometry \- arrange to handle geometry requests for a window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_ManageGeometry\fR(\fItkwin, mgrPtr, clientData\fR)
.fi
.SH ARGUMENTS
.AS Tk_GeometryProc clientData
.AP Tk_Window tkwin in
Token for window to be managed.
.AP "const Tk_GeomMgr" *mgrPtr in
Pointer to data structure containing information about the
geometry manager, or NULL to indicate that \fItkwin\fR's geometry
should not be managed anymore.
The data structure pointed to by \fImgrPtr\fR must be static:
Tk keeps a reference to it as long as the window is managed.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to geometry manager callbacks.
.BE
.SH DESCRIPTION
.PP
\fBTk_ManageGeometry\fR arranges for a particular geometry manager,
described by the \fImgrPtr\fR argument, to control the geometry
of a particular content window, given by \fItkwin\fR.
of a particular slave window, given by \fItkwin\fR.
If \fItkwin\fR was previously managed by some other geometry manager,
the previous manager loses control in favor of the new one.
If \fImgrPtr\fR is NULL, geometry management is cancelled for
\fItkwin\fR.
.PP
The structure pointed to by \fImgrPtr\fR contains information about
the geometry manager:
.CS
typedef struct {
    const char *\fIname\fR;
    Tk_GeomRequestProc *\fIrequestProc\fR;
    Tk_GeomLostContentProc *\fIlostContentProc\fR;
    Tk_GeomLostSlaveProc *\fIlostSlaveProc\fR;
} \fBTk_GeomMgr\fR;
.CE
The \fIname\fR field is the textual name for the geometry manager,
such as \fBpack\fR or \fBplace\fR;  this value will be returned
by the command \fBwinfo manager\fR.
.PP
\fIrequestProc\fR is a procedure in the geometry manager that
will be invoked whenever \fBTk_GeometryRequest\fR is called by the
content window to change its desired geometry.
slave to change its desired geometry.
\fIrequestProc\fR should have arguments and results that match the
type \fBTk_GeomRequestProc\fR:
.CS
typedef void \fBTk_GeomRequestProc\fR(
        void *\fIclientData\fR,
        ClientData \fIclientData\fR,
        Tk_Window \fItkwin\fR);
.CE
The parameters to \fIrequestProc\fR will be identical to the
corresponding parameters passed to \fBTk_ManageGeometry\fR.
\fIclientData\fR usually points to a data
structure containing application-specific information about
how to manage \fItkwin\fR's geometry.
.PP
The \fIlostContentProc\fR field of \fImgrPtr\fR points to another
The \fIlostSlaveProc\fR field of \fImgrPtr\fR points to another
procedure in the geometry manager.
Tk will invoke \fIlostContentProc\fR if some other manager
Tk will invoke \fIlostSlaveProc\fR if some other manager
calls \fBTk_ManageGeometry\fR to claim
\fItkwin\fR away from the current geometry manager.
\fIlostContentProc\fR is not invoked if \fBTk_ManageGeometry\fR is
\fIlostSlaveProc\fR is not invoked if \fBTk_ManageGeometry\fR is
called with a NULL value for \fImgrPtr\fR (presumably the current
geometry manager has made this call, so it already knows that the
window is no longer managed), nor is it called if \fImgrPtr\fR
is the same as the window's current geometry manager.
\fIlostContentProc\fR should have
\fIlostSlaveProc\fR should have
arguments and results that match the following prototype:
.CS
typedef void \fBTk_GeomLostContentProc\fR(
        void *\fIclientData\fR,
typedef void \fBTk_GeomLostSlaveProc\fR(
        ClientData \fIclientData\fR,
        Tk_Window \fItkwin\fR);
.CE
The parameters to \fIlostContentProc\fR will be identical to the
The parameters to \fIlostSlaveProc\fR will be identical to the
corresponding parameters passed to \fBTk_ManageGeometry\fR.
.SH KEYWORDS
callback, geometry, managed, request, unmanaged

Changes to doc/MapWindow.3.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
14
15
16
17
18
19
20

21
22
23
24
25
26
27







-







.nf
\fB#include <tk.h>\fR
.sp
Tk_Window
\fBTk_MapWindow\fR(\fItkwin\fR)
.sp
\fBTk_UnmapWindow\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window parent
.AP Tk_Window tkwin in
Token for window.
.BE
.SH DESCRIPTION
.PP

Changes to doc/MeasureChar.3.

10
11
12
13
14
15
16
17

18
19
20

21
22

23
24
25


26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56
57
58
59
10
11
12
13
14
15
16

17
18
19

20
21

22
23


24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


51
52
53
54
55
56
57
58
59







-
+


-
+

-
+

-
-
+
+










-
+














-
-
+
+







.SH NAME
Tk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars \- routines to measure and display simple single-line strings.
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_MeasureChars\fR(\fItkfont, string, numBytes, maxPixels, flags, lengthPtr\fR)
\fBTk_MeasureChars(\fItkfont, string, numBytes, maxPixels, flags, lengthPtr\fB)\fR
.sp
int
\fBTk_TextWidth\fR(\fItkfont, string, numBytes\fR)
\fBTk_TextWidth(\fItkfont, string, numBytes\fB)\fR
.sp
\fBTk_DrawChars\fR(\fIdisplay, drawable, gc, tkfont, string, numBytes, x, y\fR)
\fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numBytes, x, y\fB)\fR
.sp
\fBTk_UnderlineChars\fR(\fIdisplay, drawable, gc, tkfont, string, x, y, firstByte, lastByte\fR)
.fi
\fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstByte, lastByte\fB)\fR
.sp
.SH ARGUMENTS
.AS "const char" firstChar
.AP Tk_Font tkfont in
Token for font in which text is to be drawn or measured.  Must have been
returned by a previous call to \fBTk_GetFont\fR.
.AP "const char" *string in
Text to be measured or displayed.  Need not be null terminated.  Any
non-printing meta-characters in the string (such as tabs, newlines, and
other control characters) will be measured or displayed in a
platform-dependent manner.
.AP Tcl_Size numBytes in
.AP int numBytes in
The maximum number of bytes to consider when measuring or drawing
\fIstring\fR.  Must be greater than or equal to 0.
.AP int maxPixels in
If \fImaxPixels\fR is >= 0, it specifies the longest permissible
line length in pixels.  Characters from \fIstring\fR are processed only
until this many pixels have been covered.  If \fImaxPixels\fR is < 0, then
the line length is unbounded and the \fIflags\fR argument is ignored.
.AP int flags in
Various flag bits OR-ed together: \fBTK_PARTIAL_OK\fR means include a character
as long as any part of it fits in the length given by \fImaxPixels\fR;
otherwise, a character must fit completely to be considered.
\fBTK_WHOLE_WORDS\fR means stop on a word boundary, if possible.  If
\fBTK_AT_LEAST_ONE\fR is set, it means return at least one character even if no
characters could fit in the length given by \fImaxPixels\fR.  If
\fBTK_AT_LEAST_ONE\fR is set and \fBTK_WHOLE_WORDS\fR is also set, it means
that if not even one word fits on the line, return the first few letters of the
\fBTK_AT_LEAST_ONE\fR is set and \fBTK_WHOLE_WORDS\fR is also set, it means that if
not even one word fits on the line, return the first few letters of the
word that did fit; if not even one letter of the word fit, then the first
letter will still be returned.
.AP int *lengthPtr out
Filled with the number of pixels occupied by the number of characters
returned as the result of \fBTk_MeasureChars\fR.
.AP Display *display in
Display on which to draw.

Changes to doc/MoveToplev.3.

10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24







-
+
-







.BS
.SH NAME
Tk_MoveToplevelWindow \- Adjust the position of a top-level window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_MoveToplevelWindow\fR(\fItkwin, x, y\fR)
\fBTk_MoveToplevelWindow(\fItkwin, x, y\fB)\fR
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP Tk_Window tkwin in
Token for top-level window to move.
.AP int x in
New x-coordinate for the top-left pixel of \fItkwin\fR's border, or the
top-left pixel of the decorative border supplied for \fItkwin\fR by the
43
44
45
46
47
48
49
50

51
52
42
43
44
45
46
47
48

49
50
51







-
+


similar in function to the \fBwm geometry\fR Tcl command except that
negative offsets cannot be specified.  It is invoked by widgets such as
menus that want to appear at a particular place on the screen.
.PP
When \fBTk_MoveToplevelWindow\fR is called it does not immediately
pass on the new desired location to the window manager;  it defers
this action until all other outstanding work has been completed,
using the \fBTcl_DoWhenIdle\fR mechanism.
using the \fBTk_DoWhenIdle\fR mechanism.
.SH KEYWORDS
position, top-level window, window manager

Changes to doc/Name.3.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
18
19
20
21
22
23
24

25
26
27
28
29
30
31







-







\fBTk_Name\fR(\fItkwin\fR)
.sp
char *
\fBTk_PathName\fR(\fItkwin\fR)
.sp
Tk_Window
\fBTk_NameToWindow\fR(\fIinterp, pathName, tkwin\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Interp *pathName
.AP Tk_Window tkwin in
Token for window.
.AP Tcl_Interp *interp out
Interpreter to use for error reporting.
.AP "const char" *pathName in

Changes to doc/NameOfImg.3.

10
11
12
13
14
15
16
17

18
19
20
21


22
23
24
25
26
27
28
10
11
12
13
14
15
16

17

18


19
20
21
22
23
24
25
26
27







-
+
-

-
-
+
+







.SH NAME
Tk_NameOfImage \- Return name of image.
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
const char *
\fBTk_NameOfImage\fR(\fIimageModel\fR)
\fBTk_NameOfImage\fR(\fItypePtr\fR)
.fi
.SH ARGUMENTS
.AS Tk_ImageModel imageModel
.AP Tk_ImageModel imageModel in
.AS Tk_ImageMaster *masterPtr
.AP Tk_ImageMaster *masterPtr in
Token for image, which was passed to image manager's \fIcreateProc\fR when
the image was created.
.BE
.SH DESCRIPTION
.PP
This procedure is invoked by image managers to find out the name
of an image.  Given the token for the image, it returns the

Changes to doc/OwnSelect.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-








-
+















-
+







.SH NAME
Tk_OwnSelection \- make a window the owner of the primary selection
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_OwnSelection\fR(\fItkwin, selection, proc, clientData\fR)
.fi
.SH ARGUMENTS
.AS Tk_LostSelProc clientData
.AP Tk_Window tkwin in
Window that is to become new selection owner.
.AP Atom selection in
The name of the selection to be owned, such as XA_PRIMARY.
.AP Tk_LostSelProc *proc in
Procedure to invoke when \fItkwin\fR loses selection ownership later.
.AP void *clientData in
.AP ClientData clientData in
Arbitrary one-word value to pass to \fIproc\fR.
.BE
.SH DESCRIPTION
.PP
\fBTk_OwnSelection\fR arranges for \fItkwin\fR to become the
new owner of the selection specified by the atom
\fIselection\fR.  After this call completes, future requests
for the selection will be directed to handlers created for
\fItkwin\fR using \fBTk_CreateSelHandler\fR.  When \fItkwin\fR
eventually loses the selection ownership, \fIproc\fR will be
invoked so that the window can clean itself up (e.g. by
unhighlighting the selection).  \fIProc\fR should have arguments and
result that match the type \fBTk_LostSelProc\fR:
.CS
typedef void \fBTk_LostSelProc\fR(
        void *\fIclientData\fR);
        ClientData \fIclientData\fR);
.CE
The \fIclientData\fR parameter to \fIproc\fR is a copy of the
\fIclientData\fR argument given to \fBTk_OwnSelection\fR, and is
usually a pointer to a data structure containing application-specific
information about \fItkwin\fR.
.SH KEYWORDS
own, selection owner

Changes to doc/ParseArgv.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_ParseArgv \- process command-line options
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_ParseArgv\fR(\fIinterp, tkwin, argcPtr, argv, argTable, flags\fR)
.fi
.SH ARGUMENTS
.AS Tk_ArgvInfo *argTable
.AP Tcl_Interp *interp in
Interpreter to use for returning error messages.
.AP Tk_Window tkwin in
Window to use when arguments specify Tk options.  If NULL, then
no Tk options will be processed.
69
70
71
72
73
74
75
76
77


78
79
80
81
82
83
84
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83







-
-
+
+







.PP
The \fIargTable\fR array specifies the kinds of arguments that are
expected;  each of its entries has the following structure:
.CS
typedef struct {
    const char *\fIkey\fR;
    int \fItype\fR;
    void *\fIsrc\fR;
    void *\fIdst\fR;
    char *\fIsrc\fR;
    char *\fIdst\fR;
    const char *\fIhelp\fR;
} \fBTk_ArgvInfo\fR;
.CE
The \fIkey\fR field is a string such as
.QW \-display
or
.QW \-bg
110
111
112
113
114
115
116

117

118
119
120

121

122
123
124

125

126
127
128
129
130
131
132
133
134
135

136

137
138
139
140
141
142

143

144
145
146
147

148

149
150
151
152
153
154
155

156

157
158
159
160
161
162

163

164
165
166
167
168
169

170

171
172
173
174
175
176

177

178
179
180
181
182
183
184
185
186
187

188

189
190
191
192
193
194
195
196
197
198
199

200

201
202
203
204
205
206
207
109
110
111
112
113
114
115
116

117
118
119
120
121

122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146

147
148
149
150
151
152

153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218







+
-
+



+
-
+



+
-
+










+
-
+






+
-
+




+
-
+







+
-
+






+
-
+






+
-
+






+
-
+










+
-
+











+
-
+







.QW "the matching argument"
in the descriptions below.  As part of the processing,
\fBTk_ParseArgv\fR may also use the next argument in \fIargv\fR
after the matching argument, which is called
.QW "the following argument" .
The legal values for \fItype\fR, and the processing
that they cause, are as follows:
.TP
.IP \fBTK_ARGV_END\fR
\fBTK_ARGV_END\fR
Marks the end of the table.  The last entry in \fIargTable\fR
must have this type;  all of its other fields are ignored and it
will never match any arguments.
.TP
.IP \fBTK_ARGV_CONSTANT\fR
\fBTK_ARGV_CONSTANT\fR
\fISrc\fR is treated as an integer and \fIdst\fR is treated
as a pointer to an integer.  \fISrc\fR is stored at \fI*dst\fR.
The matching argument is discarded.
.TP
.IP \fBTK_ARGV_INT\fR
\fBTK_ARGV_INT\fR
The following argument must contain an
integer string in the format accepted by \fBstrtol\fR (e.g.
.QW 0
and
.QW 0x
prefixes may be used to specify octal or hexadecimal
numbers, respectively).  \fIDst\fR is treated as a pointer to an
integer;  the following argument is converted to an integer value
and stored at \fI*dst\fR.  \fISrc\fR is ignored.  The matching
and following arguments are discarded from \fIargv\fR.
.TP
.IP \fBTK_ARGV_FLOAT\fR
\fBTK_ARGV_FLOAT\fR
The following argument must contain a floating-point number in
the format accepted by \fBstrtol\fR.
\fIDst\fR is treated as the address of a double-precision
floating point value;  the following argument is converted to a
double-precision value and stored at \fI*dst\fR.  The matching
and following arguments are discarded from \fIargv\fR.
.TP
.IP \fBTK_ARGV_STRING\fR
\fBTK_ARGV_STRING\fR
In this form, \fIdst\fR is treated as a pointer to a (char *);
\fBTk_ParseArgv\fR stores at \fI*dst\fR a pointer to the following
argument, and discards the matching and following arguments from
\fIargv\fR.  \fISrc\fR is ignored.
.TP
.IP \fBTK_ARGV_UID\fR
\fBTK_ARGV_UID\fR
This form is similar to \fBTK_ARGV_STRING\fR, except that the argument
is turned into a Tk_Uid by calling \fBTk_GetUid\fR.
\fIDst\fR is treated as a pointer to a
Tk_Uid; \fBTk_ParseArgv\fR stores at \fI*dst\fR the Tk_Uid
corresponding to the following
argument, and discards the matching and following arguments from
\fIargv\fR.  \fISrc\fR is ignored.
.TP
.IP \fBTK_ARGV_CONST_OPTION\fR
\fBTK_ARGV_CONST_OPTION\fR
This form causes a Tk option to be set (as if the \fBoption\fR
command had been invoked).  The \fIsrc\fR field is treated as a
pointer to a string giving the value of an option, and \fIdst\fR
is treated as a pointer to the name of the option.  The matching
argument is discarded.  If \fItkwin\fR is NULL, then argument
specifiers of this type are ignored (as if they did not exist).
.TP
.IP \fBTK_ARGV_OPTION_VALUE\fR
\fBTK_ARGV_OPTION_VALUE\fR
This form is similar to \fBTK_ARGV_CONST_OPTION\fR, except that the
value of the option is taken from the following argument instead
of from \fIsrc\fR.  \fIDst\fR is used as the name of the option.
\fISrc\fR is ignored.  The matching and following arguments
are discarded.  If \fItkwin\fR is NULL, then argument
specifiers of this type are ignored (as if they did not exist).
.TP
.IP \fBTK_ARGV_OPTION_NAME_VALUE\fR
\fBTK_ARGV_OPTION_NAME_VALUE\fR
In this case the following argument is taken as the name of a Tk
option and the argument after that is taken as the value for that
option.  Both \fIsrc\fR and \fIdst\fR are ignored.  All three
arguments are discarded from \fIargv\fR.  If \fItkwin\fR is NULL,
then argument
specifiers of this type are ignored (as if they did not exist).
.TP
.IP \fBTK_ARGV_HELP\fR
\fBTK_ARGV_HELP\fR
When this kind of option is encountered, \fBTk_ParseArgv\fR uses the
\fIhelp\fR fields of \fIargTable\fR to format a message describing
all the valid arguments.  The message is placed in interpreter
\fIinterp\fR's result
and \fBTk_ParseArgv\fR returns \fBTCL_ERROR\fR.  When this happens, the
caller normally prints the help message and aborts.  If the \fIkey\fR
field of a \fBTK_ARGV_HELP\fR specifier is NULL, then the specifier will
never match any arguments;  in this case the specifier simply provides
extra documentation, which will be included when some other
\fBTK_ARGV_HELP\fR entry causes help information to be returned.
.TP
.IP \fBTK_ARGV_REST\fR
\fBTK_ARGV_REST\fR
This option is used by programs or commands that allow the last
several of their options to be the name and/or options for some
other program.  If a \fBTK_ARGV_REST\fR argument is found, then
\fBTk_ParseArgv\fR does not process any
of the remaining arguments;  it returns them all at
the beginning of \fIargv\fR (along with any other unprocessed arguments).
In addition, \fBTk_ParseArgv\fR treats \fIdst\fR as the address of an
integer value, and stores at \fI*dst\fR the index of the first of the
\fBTK_ARGV_REST\fR options in the returned \fIargv\fR.  This allows the
program to distinguish the \fBTK_ARGV_REST\fR options from other
unprocessed options that preceded the \fBTK_ARGV_REST\fR.
.TP
.IP \fBTK_ARGV_FUNC\fR
\fBTK_ARGV_FUNC\fR
For this kind of argument, \fIsrc\fR is treated as the address of
a procedure, which is invoked to process the following argument.
The procedure should have the following structure:
.RS
.CS
int
\fIfunc\fR(\fIdst\fR, \fIkey\fR, \fInextArg\fR)
217
218
219
220
221
222
223

224

225
226
227
228
229
230
231
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







+
-
+







(or NULL if there are not any more arguments left in \fIargv\fR).
If \fIfunc\fR uses \fInextArg\fR (so that
\fBTk_ParseArgv\fR should discard it), then it should return 1.  Otherwise it
should return 0 and \fBTkParseArgv\fR will process the following
argument in the normal fashion.  In either event the matching argument
is discarded.
.RE
.TP
.IP \fBTK_ARGV_GENFUNC\fR
\fBTK_ARGV_GENFUNC\fR
This form provides a more general procedural escape.  It treats
\fIsrc\fR as the address of a procedure, and passes that procedure
all of the remaining arguments.  The procedure should have the following
form:
.RS
.CS
int
250
251
252
253
254
255
256

257

258
259
260
261

262

263
264
265

266

267
268
269
270
271
272

273

274
275
276
277
278
279
280
262
263
264
265
266
267
268
269

270
271
272
273
274
275

276
277
278
279
280

281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296







+
-
+




+
-
+



+
-
+






+
-
+







\fBTk_ParseArgv\fR will process them.  If \fIgenfunc\fR encounters
an error then it should leave an error message in interpreter
\fIinterp\fR's result,
in the usual Tcl fashion, and return \-1;  when this happens
\fBTk_ParseArgv\fR will abort its processing and return \fBTCL_ERROR\fR.
.RE
.SS "FLAGS"
.TP
.IP \fBTK_ARGV_DONT_SKIP_FIRST_ARG\fR
\fBTK_ARGV_DONT_SKIP_FIRST_ARG\fR
\fBTk_ParseArgv\fR normally treats \fIargv[0]\fR as a program
or command name, and returns it to the caller just as if it
had not matched \fIargTable\fR.  If this flag is given, then
\fIargv[0]\fR is not given special treatment.
.TP
.IP \fBTK_ARGV_NO_ABBREV\fR
\fBTK_ARGV_NO_ABBREV\fR
Normally, \fBTk_ParseArgv\fR accepts unique abbreviations for
\fIkey\fR values in \fIargTable\fR.  If this flag is given then
only exact matches will be acceptable.
.TP
.IP \fBTK_ARGV_NO_LEFTOVERS\fR
\fBTK_ARGV_NO_LEFTOVERS\fR
Normally, \fBTk_ParseArgv\fR returns unrecognized arguments to the
caller.  If this bit is set in \fIflags\fR then \fBTk_ParseArgv\fR
will return an error if it encounters any argument that does not
match \fIargTable\fR.  The only exception to this rule is \fIargv[0]\fR,
which will be returned to the caller with no errors as
long as \fBTK_ARGV_DONT_SKIP_FIRST_ARG\fR is not specified.
.TP
.IP \fBTK_ARGV_NO_DEFAULTS\fR
\fBTK_ARGV_NO_DEFAULTS\fR
Normally, \fBTk_ParseArgv\fR searches an internal table of
standard argument specifiers in addition to \fIargTable\fR.  If
this bit is set in \fIflags\fR, then \fBTk_ParseArgv\fR will
use only \fIargTable\fR and not its default table.
.SH EXAMPLE
.PP
Here is an example definition of an \fIargTable\fR and
292
293
294
295
296
297
298
299

300
301

302
303

304
305

306
307
308


309
310


311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333



334
335
336
337
338
339
340
341
342
308
309
310
311
312
313
314

315
316

317
318

319
320

321
322


323
324
325
326
327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348



349
350
351
352
353
354
355
356
357
358
359
360







-
+

-
+

-
+

-
+

-
-
+
+


+
+
-
+



















-
-
-
+
+
+









char *fileName = defaultFileName;
Boolean exec = FALSE;

/*
 * Define option descriptions.
 */
Tk_ArgvInfo argTable[] = {
    {"-X", TK_ARGV_CONSTANT, (char *) 1, &debugFlag,
    {"\-X", TK_ARGV_CONSTANT, (char *) 1, (char *) &debugFlag,
        "Turn on debugging printfs"},
    {"-N", TK_ARGV_INT, NULL, &numReps,
    {"\-N", TK_ARGV_INT, (char *) NULL, (char *) &numReps,
        "Number of repetitions"},
    {"-of", TK_ARGV_STRING, NULL, &fileName,
    {"\-of", TK_ARGV_STRING, (char *) NULL, (char *) &fileName,
        "Name of file for output"},
    {"x", TK_ARGV_REST, NULL, &exec,
    {"x", TK_ARGV_REST, (char *) NULL, (char *) &exec,
        "File to exec, followed by any arguments (must be last argument)."},
    {NULL, TK_ARGV_END, NULL, NULL,
        NULL}
    {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
        (char *) NULL}
};

main(argc, argv)
    int argc;
int main(int argc, char *argv[])
    char *argv[];
{
    \&...

    if (Tk_ParseArgv(interp, tkwin, &argc, argv, argTable, 0) != TCL_OK) {
        fprintf(stderr, "%s\en", Tcl_GetString(Tcl_GetObjResult(interp)));
        exit(1);
    }

    /*
     * Remainder of the program.
     */
}
.CE
.PP
Note that default values can be assigned to variables named in
\fIargTable\fR:  the variables will only be overwritten if the
particular arguments are present in \fIargv\fR.
Here are some example command lines and their effects.
.CS
prog -N 200 infile        # just sets the numReps variable to 200
prog -of out200 infile    # sets fileName to reference "out200"
prog -XN 10 infile        # sets the debug flag, also sets numReps
prog \-N 200 infile        # just sets the numReps variable to 200
prog \-of out200 infile    # sets fileName to reference "out200"
prog \-XN 10 infile        # sets the debug flag, also sets numReps
.CE
In all of the above examples, \fIargc\fR will be set by \fBTk_ParseArgv\fR to 2,
\fIargv\fR[0] will be
.QW prog ,
\fIargv\fR[1] will be
.QW infile ,
and \fIargv\fR[2] will be NULL.
.SH KEYWORDS
arguments, command line, options

Changes to doc/QWinEvent.3.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
13
14
15
16
17
18
19

20
21
22
23
24
25
26







-







.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_CollapseMotionEvents\fR(\fIdisplay, collapse\fR)
.sp
\fBTk_QueueWindowEvent\fR(\fIeventPtr, position\fR)
.fi
.SH ARGUMENTS
.AS Tcl_QueuePosition position
.AP Display *display  in
Display for which to control motion event collapsing.
.AP int collapse in
Indicates whether motion events should be collapsed or not.
.AP XEvent *eventPtr  in

Changes to doc/Restack.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_RestackWindow \- Change a window's position in the stacking order
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_RestackWindow\fR(\fItkwin, aboveBelow, other\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window aboveBelow
.AP Tk_Window tkwin in
Token for window to restack.
.AP int aboveBelow in
Indicates new position of \fItkwin\fR relative to \fIother\fR;
must be \fBAbove\fR or \fBBelow\fR.

Changes to doc/RestrictEv.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27

28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
12
13
14
15
16
17
18

19
20
21
22
23

24
25

26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-





-
+

-
+






-
+









-
+







-
+







Tk_RestrictEvents \- filter and selectively delay X events
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_RestrictProc *
\fBTk_RestrictEvents\fR(\fIproc, arg, prevArgPtr\fR)
.fi
.SH ARGUMENTS
.AS Tk_RestrictProc **prevArgPtr
.AP Tk_RestrictProc *proc in
Predicate procedure to call to filter incoming X events.
NULL means do not restrict events at all.
.AP void *arg in
.AP ClientData arg in
Arbitrary argument to pass to \fIproc\fR.
.AP void **prevArgPtr out
.AP ClientData *prevArgPtr out
Pointer to place to save argument to previous restrict procedure.
.BE
.SH DESCRIPTION
.PP
This procedure is useful in certain situations where applications
are only prepared to receive certain X events.  After
\fBTk_RestrictEvents\fR is called, \fBTcl_DoOneEvent\fR (and
\fBTk_RestrictEvents\fR is called, \fBTk_DoOneEvent\fR (and
hence \fBTk_MainLoop\fR) will filter X input events through
\fIproc\fR.  \fIProc\fR indicates whether a
given event is to be processed immediately, deferred until some
later time (e.g. when the event restriction is lifted), or discarded.
\fIProc\fR
is a procedure with arguments and result that match
the type \fBTk_RestrictProc\fR:
.CS
typedef Tk_RestrictAction \fBTk_RestrictProc\fR(
        void *\fIarg\fR,
        ClientData \fIarg\fR,
        XEvent *\fIeventPtr\fR);
.CE
The \fIarg\fR argument is a copy of the \fIarg\fR passed
to \fBTk_RestrictEvents\fR; it may be used to provide \fIproc\fR with
information it needs to filter events.  The \fIeventPtr\fR points to
an event under consideration.  \fIProc\fR returns a restrict action
(enumerated type \fBTk_RestrictAction\fR) that indicates what
\fBTcl_DoOneEvent\fR should do with the event.  If the return value is
\fBTk_DoOneEvent\fR should do with the event.  If the return value is
\fBTK_PROCESS_EVENT\fR, then the event will be handled immediately.
If the return value is \fBTK_DEFER_EVENT\fR, then the event will be
left on the event queue for later processing.  If the return value is
\fBTK_DISCARD_EVENT\fR, then the event will be removed from the event
queue and discarded without being processed.
.PP
\fBTk_RestrictEvents\fR uses its return value and \fIprevArgPtr\fR
71
72
73
74
75
76
77
78

79
80
70
71
72
73
74
75
76

77
78
79







-
+


for a particular event to occur on a particular window but you do not
want to invoke any handlers for any other events).  The
.QW obvious
solution in these situations is to call \fBXNextEvent\fR or
\fBXWindowEvent\fR, but these procedures cannot be used because
Tk keeps its own event queue that is separate from the X event
queue.  Instead, call \fBTk_RestrictEvents\fR to set up a filter,
then call \fBTcl_DoOneEvent\fR to retrieve the desired event(s).
then call \fBTk_DoOneEvent\fR to retrieve the desired event(s).
.SH KEYWORDS
delay, event, filter, restriction

Changes to doc/SetAppName.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_SetAppName \- Set the name of an application for 'send' commands
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
const char *
\fBTk_SetAppName\fR(\fItkwin, name\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window parent
.AP Tk_Window tkwin in
Token for window in application.  Used only to select a particular
application.
.AP "const char" *name in
Name under which to register the application.

Changes to doc/SetCaret.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







Tk_SetCaretPos \- set the display caret location
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_SetCaretPos\fR(\fItkwin, x, y, height\fR)
.fi
.SH ARGUMENTS
.AP Tk_Window tkwin in
Token for window.
.AP int x in
Window-relative x coordinate.
.AP int y in
Window-relative y coordinate.

Changes to doc/SetClass.3.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
14
15
16
17
18
19
20

21
22
23
24
25
26
27







-







.nf
\fB#include <tk.h>\fR
.sp
\fBTk_SetClass\fR(\fItkwin, class\fR)
.sp
Tk_Uid
\fBTk_Class\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window parent
.AP Tk_Window tkwin in
Token for window.
.AP char *class in
New class name for window.
.BE

Changes to doc/SetClassProcs.3.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60

61
62
63
64
65
66
67

68
69
70
71
72
73
74
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58

59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-








-
+









-
-
+
+
















-
+





-
+






-
+







.SH NAME
Tk_SetClassProcs \- register widget specific procedures
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_SetClassProcs\fR(\fItkwin, procs, instanceData\fR)
.fi
.SH ARGUMENTS
.AS Tk_ClassProc instanceData
.AP Tk_Window tkwin in
Token for window to modify.
.AP "const Tk_ClassProcs" *procs in
Pointer to data structure containing widget specific procedures.
The data structure pointed to by \fIprocs\fR must be static:
Tk keeps a reference to it as long as the window exists.
.AP void *instanceData in
.AP ClientData instanceData in
Arbitrary one-word value to pass to widget callbacks.
.BE
.SH DESCRIPTION
.PP
\fBTk_SetClassProcs\fR is called to register a set of procedures that
are used as callbacks in different places.
.PP
The structure pointed to by \fIprocs\fR contains the following:
.CS
typedef struct {
    size_t \fIsize\fR;
typedef struct Tk_ClassProcs {
    unsigned int \fIsize\fR;
    Tk_ClassWorldChangedProc *\fIworldChangedProc\fR;
    Tk_ClassCreateProc *\fIcreateProc\fR;
    Tk_ClassModalProc *\fImodalProc\fR;
} \fBTk_ClassProcs\fR;
.CE
The \fIsize\fR field is used to simplify future expansion of the
structure. It should always be set to (literally) \fBsizeof(Tk_ClassProcs)\fR.
.PP
\fIworldChangedProc\fR is invoked when the system has altered
in some way that requires some reaction from the widget.  For example,
when a font alias (see the \fBfont\fR manual entry) is reconfigured,
widgets configured to use that font alias must update their display
accordingly.  \fIworldChangedProc\fR should have arguments and results
that match the type \fBTk_ClassWorldChangedProc\fR:
.CS
typedef void \fBTk_ClassWorldChangedProc\fR(
        void *\fIinstanceData\fR);
        ClientData \fIinstanceData\fR);
.CE
The \fIinstanceData\fR parameter passed to the \fIworldChangedProc\fR
will be identical to the \fIinstanceData\fR parameter passed to
\fBTk_SetClassProcs\fR.
.PP
\fIcreateProc\fR is used to create platform-dependent windows.  It is
\fIcreateProc\fR is used to create platform-dependant windows.  It is
invoked by \fBTk_MakeWindowExist\fR.  \fIcreateProc\fR should have
arguments and results that match the type \fBTk_ClassCreateProc\fR:
.CS
typedef Window \fBTk_ClassCreateProc\fR(
        Tk_Window \fItkwin\fR,
        Window \fIparent\fR,
        void *\fIinstanceData\fR);
        ClientData \fIinstanceData\fR);
.CE
The \fItkwin\fR and \fIinstanceData\fR parameters will be identical to
the \fItkwin\fR and \fIinstanceData\fR parameters passed to
\fBTk_SetClassProcs\fR.  The \fIparent\fR parameter will be the parent
of the window to be created.  The \fIcreateProc\fR should return the
created window.
.PP

Changes to doc/SetGrid.3.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
13
14
15
16
17
18
19

20
21
22
23
24
25
26







-







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_SetGrid\fR(\fItkwin, reqWidth, reqHeight, widthInc, heightInc\fR)
.sp
\fBTk_UnsetGrid\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window heightInc
.AP Tk_Window tkwin in
Token for window.
.AP int reqWidth in
Width in grid units that corresponds to the pixel dimension \fItkwin\fR
has requested via \fBTk_GeometryRequest\fR.

Changes to doc/SetOptions.3.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17

18
19

20
21
22

23
24
25

26
27

28
29

30
31
32

33
34
35

36
37
38




39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62

63
64

65
66
67
68
69
70
71
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16

17
18

19
20
21

22
23
24

25
26

27
28

29
30
31

32
33
34

35
36


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63

64
65

66
67
68
69
70
71
72
73










-
+





-
+

-
+


-
+


-
+

-
+

-
+


-
+


-
+

-
-
+
+
+
+














-
+








-
+

-
+







'\"
'\" Copyright (c) 1998 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH Tk_SetOptions 3 8.1 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_CreateOptionTable, Tk_DeleteOptionTable, Tk_InitOptions, Tk_SetOptions, Tk_FreeSavedOptions, Tk_RestoreSavedOptions, Tk_GetOptionValue,  Tk_GetOptionInfo, Tk_FreeConfigOptions \- process configuration options
Tk_CreateOptionTable, Tk_DeleteOptionTable, Tk_InitOptions, Tk_SetOptions, Tk_FreeSavedOptions, Tk_RestoreSavedOptions, Tk_GetOptionValue,  Tk_GetOptionInfo, Tk_FreeConfigOptions, Tk_Offset \- process configuration options
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_OptionTable
\fBTk_CreateOptionTable\fR(\fIinterp, templatePtr\fR)
\fBTk_CreateOptionTable(\fIinterp, templatePtr\fB)\fR
.sp
\fBTk_DeleteOptionTable\fR(\fIoptionTable\fR)
\fBTk_DeleteOptionTable(\fIoptionTable\fB)\fR
.sp
int
\fBTk_InitOptions\fR(\fIinterp, recordPtr, optionTable, tkwin\fR)
\fBTk_InitOptions(\fIinterp, recordPtr, optionTable, tkwin\fB)\fR
.sp
int
\fBTk_SetOptions\fR(\fIinterp, recordPtr, optionTable, objc, objv, tkwin, savePtr, maskPtr\fR)
\fBTk_SetOptions(\fIinterp, recordPtr, optionTable, objc, objv, tkwin, savePtr, maskPtr\fB)\fR
.sp
\fBTk_FreeSavedOptions\fR(\fIsavedPtr\fR)
\fBTk_FreeSavedOptions(\fIsavedPtr\fB)\fR
.sp
\fBTk_RestoreSavedOptions\fR(\fIsavedPtr\fR)
\fBTk_RestoreSavedOptions(\fIsavedPtr\fB)\fR
.sp
Tcl_Obj *
\fBTk_GetOptionValue\fR(\fIinterp, recordPtr, optionTable, namePtr, tkwin\fR)
\fBTk_GetOptionValue(\fIinterp, recordPtr, optionTable, namePtr, tkwin\fB)\fR
.sp
Tcl_Obj *
\fBTk_GetOptionInfo\fR(\fIinterp, recordPtr, optionTable, namePtr, tkwin\fR)
\fBTk_GetOptionInfo(\fIinterp, recordPtr, optionTable, namePtr, tkwin\fB)\fR
.sp
\fBTk_FreeConfigOptions\fR(\fIrecordPtr, optionTable, tkwin\fR)
.fi
\fBTk_FreeConfigOptions(\fIrecordPtr, optionTable, tkwin\fB)\fR
.sp
int
\fBTk_Offset(\fItype, field\fB)\fR
.SH ARGUMENTS
.AS Tk_SavedOptions "*const objv[]" in/out
.AP Tcl_Interp *interp in
A Tcl interpreter.  Most procedures use this only for returning error
messages; if it is NULL then no error messages are returned.  For
\fBTk_CreateOptionTable\fR the value cannot be NULL; it gives the
interpreter in which the option table will be used.
.AP "const Tk_OptionSpec" *templatePtr in
Points to an array of static information that describes the configuration
options that are supported.  Used to build a Tk_OptionTable.  The information
pointed to by this argument must exist for the lifetime of the Tk_OptionTable.
.AP Tk_OptionTable optionTable in
Token for an option table.  Must have been returned by a previous call
to \fBTk_CreateOptionTable\fR.
.AP void *recordPtr in/out
.AP char *recordPtr in/out
Points to structure in which values of configuration options are stored;
fields of this record are modified by procedures such as \fBTk_SetOptions\fR
and read by procedures such as \fBTk_GetOptionValue\fR.
.AP Tk_Window tkwin in
For options such as \fBTK_OPTION_COLOR\fR, this argument indicates
the window in which the option will be used.  If \fIoptionTable\fR uses
no window-dependent options, then a NULL value may be supplied for
this argument.
.AP Tcl_Size objc in
.AP int objc in
Number of values in \fIobjv\fR.
.AP Tcl_Obj "*const *objv" in
.AP Tcl_Obj "*const objv[]" in
Command-line arguments for setting configuring options.
.AP Tk_SavedOptions *savePtr out
If not NULL, the structure pointed to by this argument is filled
in with the old values of any options that were modified and old
values are restored automatically if an error occurs in \fBTk_SetOptions\fR.
.AP int *maskPtr out
If not NULL, the word pointed to by \fImaskPtr\fR is filled in with the
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111







-
+







.QW widget
will be used to refer to the object whose options are being managed; in
practice the object may not actually be a widget.  The term
.QW "widget record"
is used to refer to the C-level structure in
which information about a particular widget or object is stored.
.PP
Note that the easiest way to learn how to use these procedures is to
Note: the easiest way to learn how to use these procedures is to
look at a working example.  In Tk, the simplest example is the code
that implements the button family of widgets, which is in \fBtkButton.c\fR.
Other examples are in \fBtkSquare.c\fR and \fBtkMenu.c\fR.
.PP
In order to use these procedures, the code that implements the widget
must contain a static array of Tk_OptionSpec structures. This is a
template that describes the various options supported by that class of
124
125
126
127
128
129
130
131


132
133
134
135
136


137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
126
127
128
129
130
131
132

133
134
135
136
137
138

139
140
141
142
143
144
145

146


147
148
149
150
151
152
153







-
+
+




-
+
+





-
+
-
-







class.  A Tk_OptionTable may be used only in a single interpreter, given
by the \fIinterp\fR argument to \fBTk_CreateOptionTable\fR.  When an
option table is no longer needed \fBTk_DeleteOptionTable\fR should be
called to free all of its resources.  All of the option tables
for a Tcl interpreter are freed automatically if the interpreter is deleted.
.PP
\fBTk_InitOptions\fR is invoked when a new widget is created to set the
default values.
default values for all of the widget's configuration options that do not
have \fBTK_OPTION_DONT_SET_DEFAULT\fR set in their \fIflags\fR field.
\fBTk_InitOptions\fR is passed a token for an option table
(\fIoptionTable\fR) and a pointer to a widget record (\fIrecordPtr\fR),
which is the C structure that holds information about this widget.
\fBTk_InitOptions\fR uses the information in the option table to choose an
appropriate default for each option, then it stores the default value
appropriate default for each option, except those having
\fBTK_OPTION_DONT_SET_DEFAULT\fR set, then it stores the default value
directly into the widget record, overwriting any information that was
already present in the widget record.  \fBTk_InitOptions\fR normally
returns \fBTCL_OK\fR.  If an error occurred while setting the default
values (e.g., because a default value was erroneous) then \fBTCL_ERROR\fR
is returned and an error message is left in \fIinterp\fR's result if
\fIinterp\fR is not NULL. For any widget's configuration option that
\fIinterp\fR is not NULL.
has \fBTK_OPTION_DONT_SET_DEFAULT\fR set in its \fIflags\fR field,
the above initialization is fully skipped, see below.
.PP
\fBTk_SetOptions\fR is invoked to modify configuration options based
on information specified in a Tcl command.  The command might be one that
creates a new widget, or a command that modifies options on an existing
widget.  The \fIobjc\fR and \fIobjv\fR arguments describe the
values of the arguments from the Tcl command.  \fIObjv\fR must contain
an even number of objects: the first object of each pair gives the name of
233
234
235
236
237
238
239






240
241
242
243
244
245
246
247
248
249
250
251
252
253
254


255
256
257
258
259
260
261
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260


261
262
263
264
265
266
267
268
269







+
+
+
+
+
+













-
-
+
+







(e.g., because \fInamePtr\fR contains an unknown option name) then NULL
is returned and an error message is left in \fIinterp\fR's result unless
\fIinterp\fR is NULL.
.PP
\fBTk_FreeConfigOptions\fR must be invoked when a widget is deleted.
It frees all of the resources associated with any of the configuration
options defined in \fIrecordPtr\fR by \fIoptionTable\fR.
.PP
The \fBTk_Offset\fR macro is provided as a safe way of generating the
\fIobjOffset\fR and \fIinternalOffset\fR values for entries in
Tk_OptionSpec structures.  It takes two arguments: the name of a type
of record, and the name of a field in that record. It returns the byte
offset of the named field in records of the given type.
.SH "TEMPLATES"
.PP
The array of Tk_OptionSpec structures passed to \fBTk_CreateOptionTable\fR
via its \fItemplatePtr\fR argument describes the configuration options
supported by a particular class of widgets.  Each structure specifies
one configuration option and has the following fields:
.CS
typedef struct {
    Tk_OptionType \fItype\fR;
    const char *\fIoptionName\fR;
    const char *\fIdbName\fR;
    const char *\fIdbClass\fR;
    const char *\fIdefValue\fR;
    size_t \fIobjOffset\fR;
    size_t \fIinternalOffset\fR;
    int \fIobjOffset\fR;
    int \fIinternalOffset\fR;
    int \fIflags\fR;
    const void *\fIclientData\fR;
    int \fItypeMask\fR;
} \fBTk_OptionSpec\fR;
.CE
The \fItype\fR field indicates what kind of configuration option this is
(e.g. \fBTK_OPTION_COLOR\fR for a color value, or \fBTK_OPTION_INT\fR for
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







-
+







\fIdbName\fR is NULL then the option database is not used by
\fBTk_InitOptions\fR for this option.  The \fIdefValue\fR field
specifies a default value for this configuration option if no
value is specified in the option database.  The \fIobjOffset\fR and
\fIinternalOffset\fR fields indicate where to store the value of this
option in widget records (more on this below); values for the \fIobjOffset\fR
and \fIinternalOffset\fR fields should always be generated with the
\fBoffsetof\fR macro.
\fBTk_Offset\fR macro.
The \fIflags\fR field contains additional information
to control the processing of this configuration option (see below
for details).
\fIClientData\fR provides additional type-specific data needed
by certain types.  For instance, for \fBTK_OPTION_COLOR\fR types,
\fIclientData\fR is a string giving the default value to use on
monochrome displays.  See the descriptions of the different types
298
299
300
301
302
303
304

305

306
307
308
309
310
311
312
313
314
315

316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345


346
347
348
349


350
351

352
353
354
355

356

357
358

359
360

361
362
363

364
365
366
367
368

369

370
371
372
373
374

375

376
377
378
379
380
381
382

383

384
385
386

387

388
389
390
391
392



393
394
395
396
397
398
399

400

401
402
403
404
405

406

407
408
409

410
411
412
413
414
415

416
417
418
419
420
421


422
423
424

425
426
427
428


429
430
431
432
433


434
435
436
437



438
439
440
441
442
443




444
445
446

447

448
449
450
451
452
453
454


455
456

457
458
459
460
461

462

463
464
465
466
467
468
469
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331













332
333
334
335
336
337
338
339
340


341
342
343
344


345
346


347
348
349
350
351
352

353
354

355


356



357
358
359
360
361
362
363

364
365
366
367
368
369
370

371
372
373
374
375
376
377
378
379

380
381
382
383
384

385
386
387
388


389
390
391
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406

407
408
409

410






411






412
413
414
415

416




417
418
419
420
421


422
423
424
425


426
427
428
429
430
431



432
433
434
435
436
437
438
439

440
441
442
443
444
445


446
447


448
449
450
451
452
453
454

455
456
457
458
459
460
461
462







+
-
+










+
-
+





-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
+
+


-
-
+
+
-
-
+




+
-
+

-
+
-
-
+
-
-
-
+





+
-
+





+
-
+







+
-
+



+
-
+



-
-
+
+
+







+
-
+





+
-
+


-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+


-
+
-
-
-
-
+
+



-
-
+
+


-
-
+
+
+



-
-
-
+
+
+
+



+
-
+





-
-
+
+
-
-
+





+
-
+







\fBTK_OPTION_INT\fR then the internal form is an integer.  If the
\fIobjOffset\fR or \fIinternalOffset\fR field is negative then the
value is not stored in that form.  At least one of the offsets must be
greater than or equal to zero.
.PP
The \fIflags\fR field consists of one or more bits ORed together. The
following flags are supported:
.TP
.IP \fBTK_OPTION_NULL_OK\fR
\fBTK_OPTION_NULL_OK\fR
If this bit is set for an option then an empty string will be accepted as
the value for the option and the resulting internal form will be a NULL
pointer, a zero value, or \fBNone\fR, depending on the type of the option.
If the flag is not set then empty strings will result in errors.
\fBTK_OPTION_NULL_OK\fR is typically used to allow a
feature to be turned off entirely, e.g. set a cursor value to
\fBNone\fR so that a window simply inherits its parent's cursor.
Not all option types support the \fBTK_OPTION_NULL_OK\fR
flag; for those that do, there is an explicit indication of that fact
in the descriptions below.
.TP
.IP \fBTK_OPTION_DONT_SET_DEFAULT\fR
\fBTK_OPTION_DONT_SET_DEFAULT\fR
If this bit is set for an option then no default value will be set in
\fBTk_InitOptions\fR for this option. Neither the option database, nor any
system default value, nor \fIoptionTable\fR are used to give a default
value to this option. Instead it is assumed that the caller has already
supplied a default value in the widget code.
.IP \fBTK_OPTION_ENUM_VAR\fR
If this value is set for an option, then it indicates the the
internalOffset points to an enum variable in stead of an int variable.
Only useful in combination with \fBTK_OPTION_STRING_TABLE\fR,
\fBTK_OPTION_BOOLEAN\fR, \fBTK_OPTION_ANCHOR\fR, \fBTK_OPTION_JUSTIFY\fR,
or \fBTK_OPTION_ANCHOR\fR.
.IP \fBTK_OPTION_VAR(\fItype\fB)\fR
If this value is set for an option, then it indicates the the
internalOffset points to a \fItype\fR variable in stead of an int variable.
Only useful in combination with \fBTK_OPTION_STRING_TABLE\fR or
\fBTK_OPTION_BOOLEAN\fR, or as \fBTK_OPTION_VAR(Tcl_Size)\fR
with \fBTK_OPTION_INT\fR
.RS
.PP
The \fItype\fR field of each Tk_OptionSpec structure determines
how to parse the value of that configuration option. The
legal value for \fItype\fR, and the corresponding actions, are
described below.  If the type requires a \fItkwin\fR value to be
passed into procedures like \fBTk_SetOptions\fR, or if it uses
the \fIclientData\fR field of the Tk_OptionSpec, then it is indicated
explicitly; if not mentioned, the type requires neither \fItkwin\fR
nor \fIclientData\fR.
.RE
.IP \fBTK_OPTION_ANCHOR\fR
.TP
\fBTK_OPTION_ANCHOR\fR
The value must be a standard anchor position such as \fBne\fR or
\fBcenter\fR.  The internal form is a Tk_Anchor value like the ones
returned by \fBTk_GetAnchorFromObj\fR.  This option type supports the
\fBTK_OPTION_NULL_OK\fR flag; if the empty string is specified as the
returned by \fBTk_GetAnchorFromObj\fR.
.TP
value for the option, the integer relief value is set to \fBTK_ANCHOR_NULL\fR.
.IP \fBTK_OPTION_BITMAP\fR
\fBTK_OPTION_BITMAP\fR
The value must be a standard Tk bitmap name. The internal form is a
Pixmap token like the ones returned by \fBTk_AllocBitmapFromObj\fR.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR, and it supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_BOOLEAN\fR
\fBTK_OPTION_BOOLEAN\fR
The value must be a standard boolean value such as \fBtrue\fR or
\fBno\fR.  The internal form is an integer with value 0 or 1.  Note that if
\fBno\fR.  The internal form is an integer with value 0 or 1.
the \fIobjOffset\fR field is not used, information about the original
value of this option will be lost.  This option type supports the
.TP
\fBTK_OPTION_NULL_OK\fR flag; if a NULL value is set, the internal
representation is set to -1.
.IP \fBTK_OPTION_BORDER\fR
\fBTK_OPTION_BORDER\fR
The value must be a standard color name such as \fBred\fR or \fB#ff8080\fR.
The internal form is a Tk_3DBorder token like the ones returned
by \fBTk_Alloc3DBorderFromObj\fR.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR, and it supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_COLOR\fR
\fBTK_OPTION_COLOR\fR
The value must be a standard color name such as \fBred\fR or \fB#ff8080\fR.
The internal form is an (XColor *) token like the ones returned by
\fBTk_AllocColorFromObj\fR.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR, and it supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_CURSOR\fR
\fBTK_OPTION_CURSOR\fR
The value must be a standard cursor name such as \fBcross\fR or \fB@foo\fR.
The internal form is a Tk_Cursor token like the ones returned by
\fBTk_AllocCursorFromObj\fR.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR, and when the option is set the cursor
for the window is changed by calling \fBXDefineCursor\fR.  This
option type also supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_CUSTOM\fR
\fBTK_OPTION_CUSTOM\fR
This option allows applications to define new option types.  The
clientData field of the entry points to a structure defining the new
option type.  See the section \fBCUSTOM OPTION TYPES\fR below for details.
.TP
.IP \fBTK_OPTION_DOUBLE\fR
\fBTK_OPTION_DOUBLE\fR
The string value must be a floating-point number in
the format accepted by \fBstrtol\fR.  The internal form is a C
\fBdouble\fR value.  This option type supports the \fBTK_OPTION_NULL_OK\fR
flag; if a NULL value is set, the internal representation is set to NaN.
.IP \fBTK_OPTION_END\fR
flag; if a NULL value is set, the internal representation is set to zero.
.TP
\fBTK_OPTION_END\fR
Marks the end of the template.  There must be a Tk_OptionSpec structure
with \fItype\fR \fBTK_OPTION_END\fR at the end of each template.  If the
\fIclientData\fR field of this structure is not NULL, then it points to
an additional array of Tk_OptionSpec's, which is itself terminated by
another \fBTK_OPTION_END\fR entry.  Templates may be chained arbitrarily
deeply.  This feature allows common options to be shared by several
widget classes.
.TP
.IP \fBTK_OPTION_FONT\fR
\fBTK_OPTION_FONT\fR
The value must be a standard font name such as \fBTimes 16\fR.
The internal form is a Tk_Font handle like the ones returned by
\fBTk_AllocFontFromObj\fR.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR, and it supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_INT\fR
\fBTK_OPTION_INT\fR
The string value must be an integer in the format accepted by
\fBstrtol\fR (e.g. \fB0\fR and \fB0x\fR prefixes may be used to
specify octal or hexadecimal numbers, respectively).  The internal form is
specify octal or hexadecimal numbers, respectively).  The internal
a C \fBint\fR value.  This option type supports the \fBTK_OPTION_NULL_OK\fR
flag; if a NULL value is set, the internal representation is set to INT_MIN.
.IP \fBTK_OPTION_INDEX\fR
The string value must be an index in the format accepted by
\fBTcl_GetIntForIndex()\fR
or the empty string.  The internal form is a C \fBint\fR value. If the string
form is a C \fBint\fR value.
starts with \fB\-\fR, the internal representation will be set to INT_MIN. If the
string has the form \fBend-???\fR, then the result will be a negative number:
\fB-1\fR stands for \fBend\fR, \fB-2\fR stands for \fBend-1\fR and so on.
This option type supports the \fBTK_OPTION_NULL_OK\fR flag;
if a NULL value is set, the internal representation is set to INT_MIN.
.IP \fBTK_OPTION_JUSTIFY\fR
.TP
\fBTK_OPTION_JUSTIFY\fR
The value must be a standard justification value such as \fBleft\fR.
The internal form is a Tk_Justify like the values returned by
\fBTk_GetJustifyFromObj\fR.  This option type supports the
\fBTk_GetJustifyFromObj\fR.
\fBTK_OPTION_NULL_OK\fR
flag; if the empty string is specified as the value for the option,
the integer relief value is set to \fBTK_JUSTIFY_NULL\fR.
.IP \fBTK_OPTION_PIXELS\fR
.TP
\fBTK_OPTION_PIXELS\fR
The value must specify a screen distance such as \fB2i\fR or \fB6.4\fR.
The internal form is an integer value giving a
distance in pixels, like the values returned by
\fBTk_GetPixelsFromObj\fR.  Note that if the \fIobjOffset\fR field is not
used, information about the original value of this option will be lost.
\fBTk_GetPixelsFromObj\fR.  Note: if the \fIobjOffset\fR field is not
used then information about the original value of this option will be lost.
See \fBOBJOFFSET VS. INTERNALOFFSET\fR below for details.  This option
type supports the \fBTK_OPTION_NULL_OK\fR flag; if a NULL value is set, the
internal representation is set to INT_MIN.
.IP \fBTK_OPTION_RELIEF\fR
internal representation is set to zero.
.TP
\fBTK_OPTION_RELIEF\fR
The value must be standard relief such as \fBraised\fR.
The internal form is an integer relief value such as
\fBTK_RELIEF_RAISED\fR.  This option type supports the \fBTK_OPTION_NULL_OK\fR
flag; if a NULL value is set, the internal representation is set to
\fBTK_RELIEF_NULL\fR.
.IP \fBTK_OPTION_STRING\fR
flag; if the empty string is specified as the value for the option,
the integer relief value is set to \fBTK_RELIEF_NULL\fR.
.TP
\fBTK_OPTION_STRING\fR
The value may be any string.  The internal form is a (char *) pointer
that points to a dynamically allocated copy of the value.
This option type supports the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fBTK_OPTION_STRING_TABLE\fR
\fBTK_OPTION_STRING_TABLE\fR
For this type, \fIclientData\fR is a pointer to an array of strings
suitable for passing to \fBTcl_GetIndexFromObj\fR.  The value must
be one of the strings in the table, or a unique abbreviation of
one of the strings.  The internal form is an integer giving the index
into the table of the matching string, like the return value
from \fBTcl_GetStringFromObj\fR.  This option type supports the
\fBTK_OPTION_NULL_OK\fR flag; if a NULL value is set, the internal
from \fBTcl_GetStringFromObj\fR.
.TP
representation is set to -1.
.IP \fBTK_OPTION_SYNONYM\fR
\fBTK_OPTION_SYNONYM\fR
This type is used to provide alternative names for an option (for
example, \fB\-bg\fR is often used as a synonym for \fB\-background\fR).
The \fBclientData\fR field is a string that gives the name of another
option in the same table.  Whenever the synonym option is used, the
information from the other option will be used instead.
.TP
.IP \fBTK_OPTION_WINDOW\fR
\fBTK_OPTION_WINDOW\fR
The value must be a window path name.  The internal form is a
\fBTk_Window\fR token for the window.
This option type requires \fItkwin\fR to be supplied to procedures
such as \fBTk_SetOptions\fR (in order to identify the application),
and it supports the \fBTK_OPTION_NULL_OK\fR flag.
.SH "STORAGE MANAGEMENT ISSUES"
.PP
505
506
507
508
509
510
511
512
513


514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532

533
534
535
536
537
538

539
540
541
542

543
544
545
546
547
548
549
550
551
552

553
554
555
556
557
558

559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581

582

583
584

585

586

587

588

589

590
591
592
593
594
595
596
597
598

599

600

601

602
603

604

605
606
607
608
609

610

611
612
613
614
615
616
617
498
499
500
501
502
503
504


505
506
507
508
509
510
511
512
513




514
515
516
517
518
519
520

521
522
523
524
525
526

527
528
529
530

531
532
533
534
535
536
537
538
539
540

541
542
543
544
545
546

547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575

576
577
578

579
580
581

582
583
584
585
586
587
588
589
590
591
592

593
594
595

596
597
598
599

600
601
602
603
604
605
606

607
608
609
610
611
612
613
614







-
-
+
+







-
-
-
-







-
+





-
+



-
+









-
+





-
+





-
+

















+
-
+


+
-
+

+
-
+

+
-
+









+
-
+

+
-
+


+
-
+





+
-
+







the original screen-independent value. Thus for \fBTK_OPTION_PIXELS\fR options
it is better to use the \fIobjOffset\fR field.  In this case the original
value of the option is retained in the object and can be returned when
the option is retrieved.  In most cases it is convenient to use the
\fIinternalOffset\fR field as well, so that the integer value is
immediately available for use in the widget code (alternatively,
\fBTk_GetPixelsFromObj\fR can be used to extract the integer value from
the object whenever it is needed).  Note that the problem of losing
information on retrievals exists only for \fBTK_OPTION_PIXELS\fR options.
the object whenever it is needed).  Note: the problem of losing information
on retrievals exists only for \fBTK_OPTION_PIXELS\fR options.
.PP
The second reason to use the \fIobjOffset\fR field is in order to
implement new types of options not supported by these procedures.
To implement a new type of option, you can use \fBTK_OPTION_STRING\fR as
the type in the Tk_OptionSpec structure and set the \fIobjOffset\fR field
but not the \fIinternalOffset\fR field.  Then, after calling
\fBTk_SetOptions\fR, convert the object to internal form yourself.
.PP
Ttk widgets do not support the \fIinternalOffset\fR machinery.
Option values of Ttk widgets are always stored as (Tcl_Obj *), meaning that
the \fIobjOffset\fR field must be used.
.SH "CUSTOM OPTION TYPES"
.PP
Applications can extend the built-in configuration types with
additional configuration types by writing procedures to parse, print,
free, and restore saved copies of the type and creating a structure
pointing to those procedures:
.CS
typedef struct {
typedef struct Tk_ObjCustomOption {
    char *name;
    Tk_CustomOptionSetProc *\fIsetProc\fR;
    Tk_CustomOptionGetProc *\fIgetProc\fR;
    Tk_CustomOptionRestoreProc *\fIrestoreProc\fR;
    Tk_CustomOptionFreeProc *\fIfreeProc\fR;
    void *\fIclientData\fR;
    ClientData \fIclientData\fR;
} \fBTk_ObjCustomOption\fR;

typedef int \fBTk_CustomOptionSetProc\fR(
    void *\fIclientData\fR,
    ClientData \fIclientData\fR,
    Tcl_Interp *\fIinterp\fR,
    Tk_Window \fItkwin\fR,
    Tcl_Obj **\fIvaluePtr\fR,
    char *\fIrecordPtr\fR,
    int \fIinternalOffset\fR,
    char *\fIsaveInternalPtr\fR,
    int \fIflags\fR);

typedef Tcl_Obj *\fBTk_CustomOptionGetProc\fR(
    void *\fIclientData\fR,
    ClientData \fIclientData\fR,
    Tk_Window \fItkwin\fR,
    char *\fIrecordPtr\fR,
    int \fIinternalOffset\fR);

typedef void \fBTk_CustomOptionRestoreProc\fR(
    void *\fIclientData\fR,
    ClientData \fIclientData\fR,
    Tk_Window \fItkwin\fR,
    char *\fIinternalPtr\fR,
    char *\fIsaveInternalPtr\fR);

typedef void \fBTk_CustomOptionFreeProc\fR(
    void *\fIclientData\fR,
    ClientData \fIclientData\fR,
    Tk_Window \fItkwin\fR,
    char *\fIinternalPtr\fR);
.CE
.PP
The Tk_ObjCustomOption structure contains six fields: a name
for the custom option type; pointers to the four procedures; and a
\fIclientData\fR value to be passed to those procedures when they are
invoked.  The \fIclientData\fR value typically points to a structure
containing information that is needed by the procedures when they are
parsing and printing options.  \fIRestoreProc\fR and \fIfreeProc\fR
may be NULL, indicating that no function should be called for those
operations.
.PP
The \fIsetProc\fR procedure is invoked by \fBTk_SetOptions\fR to
convert a Tcl_Obj into an internal representation and store the
resulting value in the widget record.  The arguments are:
.RS
.TP
.IP \fIclientData\fR
\fIclientData\fR
A copy of the \fIclientData\fR field in the Tk_ObjCustomOption
structure.
.TP
.IP \fIinterp\fR
\fIinterp\fR
A pointer to a Tcl interpreter, used for error reporting.
.TP
.IP \fITkwin\fR
\fITkwin\fR
A copy of the \fItkwin\fR argument to \fBTk_SetOptions\fR
.TP
.IP \fIvaluePtr\fR
\fIvaluePtr\fR
A pointer to a reference to a Tcl_Obj describing the new value for the
option; it could have been specified explicitly in the call to
\fBTk_SetOptions\fR or it could come from the option database or a
default.  If the objOffset for the option is non-negative (the option
value is stored as a (Tcl_Obj *) in the widget record), the Tcl_Obj
pointer referenced by \fIvaluePtr\fR is the pointer that will be
stored at the objOffset for the option.  \fISetProc\fR may modify the
value if necessary; for example, \fIsetProc\fR may change the value to
NULL to support the \fBTK_OPTION_NULL_OK\fR flag.
.TP
.IP \fIrecordPtr\fR
\fIrecordPtr\fR
A pointer to the start of the widget record to modify.
.TP
.IP \fIinternalOffset\fR
\fIinternalOffset\fR
Offset in bytes from the start of the widget record to the location
where the internal representation of the option value is to be placed.
.TP
.IP \fIsaveInternalPtr\fR
\fIsaveInternalPtr\fR
A pointer to storage allocated in a Tk_SavedOptions structure for the
internal representation of the original option value.  Before setting
the option to its new value, \fIsetProc\fR should set the value
referenced by \fIsaveInternalPtr\fR to the original value of the
option in order to support \fBTk_RestoreSavedOptions\fR.
.TP
.IP \fIflags\fR
\fIflags\fR
A copy of the \fIflags\fR field in the Tk_OptionSpec structure for the
option
.RE
.PP
\fISetProc\fR returns a standard Tcl result: \fBTCL_OK\fR to indicate successful
processing, or \fBTCL_ERROR\fR to indicate a failure of any kind.  An error
message may be left in the Tcl interpreter given by \fIinterp\fR in

Changes to doc/SetVisual.3.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







Tk_SetWindowVisual \- change visual characteristics of window
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_SetWindowVisual\fR(\fItkwin, visual, depth, colormap\fR)
.fi
.SH ARGUMENTS
.AS "Tk_Window int" colormap
.AP Tk_Window tkwin in
Token for window.
.AP Visual *visual in
New visual type to use for \fItkwin\fR.
.AP "int" depth in
40
41
42
43
44
45
46
47

48
49
50
51
39
40
41
42
43
44
45

46
47
48
49
50







-
+




The safest thing is to call \fBTk_SetWindowVisual\fR immediately
after calling \fBTk_CreateWindow\fR.
If \fItkwin\fR has already been created before \fBTk_SetWindowVisual\fR
is called then it returns 0 and does not make any changes;  otherwise
it returns 1 to signify that the operation
completed successfully.
.PP
Note that \fBTk_SetWindowVisual\fR should not be called if you just want
Note:  \fBTk_SetWindowVisual\fR should not be called if you just want
to change a window's colormap without changing its visual or depth;
call \fBTk_SetWindowColormap\fR instead.
.SH KEYWORDS
colormap, depth, visual

Changes to doc/StrictMotif.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







Tk_StrictMotif \- Return value of tk_strictMotif variable
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
int
\fBTk_StrictMotif\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP Tk_Window tkwin in
Token for window.
.BE
.SH DESCRIPTION
.PP

Changes to doc/TextLayout.3.

10
11
12
13
14
15
16
17

18

19

20

21

22

23

24
25
26

27
28
29

30
31
32

33
34
35

36

37

38
39
40
41
42
43
44
45
10
11
12
13
14
15
16

17
18
19

20
21
22

23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41

42
43
44
45
46
47
48







-
+

+
-
+

+
-
+

+
-
+


-
+


-
+


-
+


-
+

+
-
+
-







.SH NAME
Tk_ComputeTextLayout, Tk_FreeTextLayout, Tk_DrawTextLayout, Tk_UnderlineTextLayout, Tk_PointToChar, Tk_CharBbox, Tk_DistanceToTextLayout, Tk_IntersectTextLayout, Tk_TextLayoutToPostscript \- routines to measure and display single-font, multi-line, justified text.
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_TextLayout
\fBTk_ComputeTextLayout\fR(\fItkfont, string, numChars, wrapLength, justify, flags, widthPtr, heightPtr\fR)
\fBTk_ComputeTextLayout(\fItkfont, string, numChars, wrapLength, justify, flags, widthPtr, heightPtr\fB)\fR
.sp
void
\fBTk_FreeTextLayout\fR(\fIlayout\fR)
\fBTk_FreeTextLayout(\fIlayout\fB)\fR
.sp
void
\fBTk_DrawTextLayout\fR(\fIdisplay, drawable, gc, layout, x, y, firstChar, lastChar\fR)
\fBTk_DrawTextLayout(\fIdisplay, drawable, gc, layout, x, y, firstChar, lastChar\fB)\fR
.sp
void
\fBTk_UnderlineTextLayout\fR(\fIdisplay, drawable, gc, layout, x, y, underline\fR)
\fBTk_UnderlineTextLayout(\fIdisplay, drawable, gc, layout, x, y, underline\fB)\fR
.sp
int
\fBTk_PointToChar\fR(\fIlayout, x, y\fR)
\fBTk_PointToChar(\fIlayout, x, y\fB)\fR
.sp
int
\fBTk_CharBbox\fR(\fIlayout, index, xPtr, yPtr, widthPtr, heightPtr\fR)
\fBTk_CharBbox(\fIlayout, index, xPtr, yPtr, widthPtr, heightPtr\fB)\fR
.sp
int
\fBTk_DistanceToTextLayout\fR(\fIlayout, x, y\fR)
\fBTk_DistanceToTextLayout(\fIlayout, x, y\fB)\fR
.sp
int
\fBTk_IntersectTextLayout\fR(\fIlayout, x, y, width, height\fR)
\fBTk_IntersectTextLayout(\fIlayout, x, y, width, height\fB)\fR
.sp
void
\fBTk_TextLayoutToPostscript\fR(\fIinterp, layout\fR)
\fBTk_TextLayoutToPostscript(\fIinterp, layout\fB)\fR
.fi
.SH ARGUMENTS
.AS Tk_TextLayout "*xPtr, *yPtr"
.AP Tk_Font tkfont in
Font to use when constructing and displaying a text layout.  The
\fItkfont\fR must remain valid for the lifetime of the text layout.  Must
have been returned by a previous call to \fBTk_GetFont\fR.
.AP "const char" *string in
93
94
95
96
97
98
99
100

101
102
103

104
105
106
107
108

109
110
111


112
113
114
115
116
117
118
96
97
98
99
100
101
102

103
104
105

106
107
108
109
110

111



112
113
114
115
116
117
118
119
120







-
+


-
+




-
+
-
-
-
+
+







this GC must correspond to the \fItkfont\fR used when constructing the
text layout.
.AP int "x, y" in
Point, in pixels, at which to place the upper-left hand corner of the
text layout when it is being drawn, or the coordinates of a point (with
respect to the upper-left hand corner of the text layout) to check
against the text layout.
.AP Tcl_Size firstChar in
.AP int firstChar in
The index of the first character to draw from the given text layout.
The number 0 means to draw from the beginning.
.AP Tcl_Size lastChar in
.AP int lastChar in
The index of the last character up to which to draw.  The character
specified by \fIlastChar\fR itself will not be drawn.  A number less
than 0 means to draw all characters in the text layout.
.AP int underline in
Index of the single character to underline in the text layout, or a
Index of the single character to underline in the text layout, or a number
negative number counting backwards from the end of the string. Any
out-of-range number (e.g. INT_MIN) means no underline.
.AP Tcl_Size index in
less than 0 for no underline.
.AP int index in
The index of the character whose bounding box is desired.  The bounding
box is computed with respect to the upper-left hand corner of the text layout.
.AP int "*xPtr, *yPtr" out
Filled with the upper-left hand corner, in pixels, of the bounding box
for the character specified by \fIindex\fR.  Either or both \fIxPtr\fR
and \fIyPtr\fR may be NULL, in which case the corresponding value
is not calculated.

Changes to doc/TkInitStubs.3.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24







-







Tk_InitStubs \- initialize the Tk stubs mechanism
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
const char *
\fBTk_InitStubs\fR(\fIinterp, version, exact\fR)
.fi
.SH ARGUMENTS
.AS Tcl_Interp *interp in
.AP Tcl_Interp *interp in
Tcl interpreter handle.
.AP char *version in
A version string consisting of one or more decimal numbers
separated by dots.

Changes to doc/Tk_Init.3.

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
43
44
45
46
47
48
49

50
51
52

53
54
55
56
57
58

59
60
61

62
63
64
65

66
67
68

69
70
71

72
73
74

75
76
77

78
79
80
81

82
83
84
85







-



-






-



-




-



-



-



-



-




-




its command-line arguments).
.PP
\fBTk_SafeInit\fR is identical to \fBTk_Init\fR except that it removes
all Tk commands that are considered unsafe.  Those commands and the
reasons for their exclusion are:
.TP
\fBbell\fR
.
Continuous ringing of the bell is a nuisance.
.TP
\fBclipboard\fR
.
A malicious script could replace the contents of the clipboard with
the string
.QW "\fBrm \-r *\fR"
and lead to surprises when the contents of the clipboard are pasted.
.TP
\fBgrab\fR
.
Grab can be used to block the user from using any other applications.
.TP
\fBmenu\fR
.
Menus can be used to cover the entire screen and to steal input from
the user.
.TP
\fBselection\fR
.
See clipboard.
.TP
\fBsend\fR
.
Send can be used to cause unsafe interpreters to execute commands.
.TP
\fBtk\fR
.
The tk command recreates the send command, which is unsafe.
.TP
\fBtkwait\fR
.
Tkwait can block the containing process forever
.TP
\fBtoplevel\fR
.
Toplevels can be used to cover the entire screen and to steal input
from the user.
.TP
\fBwm\fR
.
If toplevels are ever allowed, wm can be used to remove decorations,
move windows around, etc.
.SH KEYWORDS
safe, application, initialization, load, main window

Changes to doc/Tk_Main.3.

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27







-
+







.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
\fBTk_Main\fR(\fIargc, argv, appInitProc\fR)
.SH ARGUMENTS
.AS Tcl_AppInitProc *appInitProc
.AP Tcl_Size argc in
.AP int argc in
Number of elements in \fIargv\fR.
.AP char *argv[] in
Array of strings containing command-line arguments. On Windows, when
using -DUNICODE, the parameter type changes to wchar_t *.
.AP Tcl_AppInitProc *appInitProc in
Address of an application-specific initialization procedure.
The value for this argument is usually \fBTcl_AppInit\fR.

Deleted doc/WinUtil.3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
'\"
'\" Copyright (c) 1990-1993 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH Tk_ConfigureWindow 3 4.0 Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_GetOtherWindow, Tk_MakeContainer, Tk_MakeWindow, Tk_UseWindow \- window utility functions
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Tk_Window
\fBTk_GetOtherWindow\fR(\fItkwin\fR)
.sp
\fBTk_MakeContainer\fR(\fItkwin\fR)
.sp
\fBTk_MakeWindow\fR(\fItkwin, parent\fR)
.sp
int
\fBTk_UseWindow\fR(\fIinterp, tkwin, string\fR)
.fi
.SH ARGUMENTS
.AS XSetWindowAttributes borderWidth
.AP Tcl_Interp * interp in
Interpreter associated with the application.
.AP Tk_Window tkwin in
Token for window.
.AP Window parent in
Parent window.
.AP "const char" *string in
String identifying an X window to use for \fItkwin\fR; must be an integer value.
.BE
.SH DESCRIPTION
.PP
If both the container and embedded window are in the same process,
\fBTk_GetOtherWindow\fR will return either one, given the other.
If winPtr is a container, the return value is the token for the
embedded window, and vice versa. If the "other" window isn't in this
process, NULL is returned.
.PP
\fBTk_MakeContainer\fR is called to indicate that a particular window will be a
container for an embedded application. This changes certain aspects of
the window's behavior, such as whether it will receive events anymore.
.PP
\fBTk_MakeWindow\fR creates an actual window system window object based on the
current attributes of the specified TkWindow. It returns the handle to the new
window, or None on failure.
.PP
\fBTk_UseWindow\fR causes a Tk window to use a given X window as its
parent window, rather than the root window for the screen. It is
invoked by an embedded application to specify the window in which it
is embedded.
.PP
The return value is normally TCL_OK. If an error occurs (such as
string not being a valid window spec), then the return value is
TCL_ERROR and an error message is left in the interp's result if
interp is non-NULL.
.PP
.SH KEYWORDS
parent, window

Changes to doc/WindowId.3.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



32
33
34
35
36
37
38











-
+



















-
-
-







'\"
'\" Copyright (c) 1990-1993 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.
'\"
.TH Tk_WindowId 3 "8.4" Tk "Tk Library Procedures"
.so man.macros
.BS
.SH NAME
Tk_WindowId, Tk_Parent, Tk_Display, Tk_DisplayName, Tk_ScreenNumber, Tk_AlwaysShowSelection, Tk_Screen, Tk_X, Tk_Y, Tk_Width, Tk_Height, Tk_Changes, Tk_Attributes, Tk_IsContainer, Tk_IsEmbedded, Tk_IsMapped, Tk_IsTopLevel, Tk_ReqWidth, Tk_ReqHeight, Tk_MinReqWidth, Tk_MinReqHeight, Tk_InternalBorderLeft, Tk_InternalBorderRight, Tk_InternalBorderTop, Tk_InternalBorderBottom, Tk_Visual, Tk_Depth, Tk_Colormap, Tk_Interp, Tk_NewWindowObj  \- retrieve information from Tk's local data structure
Tk_WindowId, Tk_Parent, Tk_Display, Tk_DisplayName, Tk_ScreenNumber, Tk_Screen, Tk_X, Tk_Y, Tk_Width, Tk_Height, Tk_Changes, Tk_Attributes, Tk_IsContainer, Tk_IsEmbedded, Tk_IsMapped, Tk_IsTopLevel, Tk_ReqWidth, Tk_ReqHeight, Tk_MinReqWidth, Tk_MinReqHeight, Tk_InternalBorderLeft, Tk_InternalBorderRight, Tk_InternalBorderTop, Tk_InternalBorderBottom, Tk_Visual, Tk_Depth, Tk_Colormap, Tk_Interp  \- retrieve information from Tk's local data structure
.SH SYNOPSIS
.nf
\fB#include <tk.h>\fR
.sp
Window
\fBTk_WindowId\fR(\fItkwin\fR)
.sp
Tk_Window
\fBTk_Parent\fR(\fItkwin\fR)
.sp
Display *
\fBTk_Display\fR(\fItkwin\fR)
.sp
const char *
\fBTk_DisplayName\fR(\fItkwin\fR)
.sp
int
\fBTk_ScreenNumber\fR(\fItkwin\fR)
.sp
int
\fBTk_AlwaysShowSelection\fR(\fItkwin\fR)
.sp
Screen *
\fBTk_Screen\fR(\fItkwin\fR)
.sp
int
\fBTk_X\fR(\fItkwin\fR)
.sp
int
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
93
94
95
96
97
98
99




100
101
102
103
104
105
106







-
-
-
-







\fBTk_Depth\fR(\fItkwin\fR)
.sp
Colormap
\fBTk_Colormap\fR(\fItkwin\fR)
.sp
Tcl_Interp *
\fBTk_Interp\fR(\fItkwin\fR)
.sp
Tcl_Obj *
\fBTk_NewWindowObj\fR(\fItkwin\fR)
.fi
.SH ARGUMENTS
.AS Tk_Window tkwin
.AP Tk_Window tkwin in
Token for window.
.BE
.SH DESCRIPTION
.PP
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
123
124
125
126
127
128
129


130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149







-
-












-
+







.PP
\fBTk_Display\fR returns a pointer to the Xlib display structure
corresponding to \fItkwin\fR.  \fBTk_DisplayName\fR returns an
ASCII string identifying \fItkwin\fR's display.  \fBTk_ScreenNumber\fR
returns the index of \fItkwin\fR's screen among all the screens
of \fItkwin\fR's display.  \fBTk_Screen\fR returns a pointer to
the Xlib structure corresponding to \fItkwin\fR's screen.
\fBTk_AlwaysShowSelection\fR indicates whether text/entry widgets
should always display their selection, regardless of window focus.
.PP
\fBTk_X\fR, \fBTk_Y\fR, \fBTk_Width\fR, and \fBTk_Height\fR
return information about \fItkwin's\fR location within its
parent and its size.  The location information refers to the
upper-left pixel in the window, or its border if there is one.
The width and height information refers to the interior size
of the window, not including any border.  \fBTk_Changes\fR
returns a pointer to a structure containing all of the above
information plus a few other fields.  \fBTk_Attributes\fR
returns a pointer to an XSetWindowAttributes structure describing
all of the attributes of the \fItkwin\fR's window, such as background
pixmap, event mask, and so on (Tk keeps track of all this information
as it is changed by the application).  Note that it is essential that
as it is changed by the application).  Note: it is essential that
applications use Tk procedures like \fBTk_ResizeWindow\fR instead
of X procedures like \fBXResizeWindow\fR, so that Tk can keep its
data structures up-to-date.
.PP
\fBTk_IsContainer\fR returns a non-zero value if \fItkwin\fR
is a container, and that some other application may be embedding
itself inside \fItkwin\fR.
187
188
189
190
191
192
193
194
195
196
197
198
199
178
179
180
181
182
183
184


185
186
187
188







-
-




information about the visual characteristics of a window.
\fBTk_Visual\fR returns the visual type for
the window, \fBTk_Depth\fR returns the number of bits per pixel,
and \fBTk_Colormap\fR returns the current
colormap for the window.  The visual characteristics are
normally set from the defaults for the window's screen, but
they may be overridden by calling \fBTk_SetWindowVisual\fR.
.PP
\fBTk_NewWindowObj\fR creates a new \fBTcl_Obj\fR from the window.
.SH KEYWORDS
attributes, colormap, depth, display, height, geometry manager,
identifier, mapped, requested size, screen, top-level,
visual, width, window, x, y

Changes to doc/bind.n.

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25


26
27
28
29
30
31
32
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22



23
24
25
26
27
28
29
30
31



-
+

















-
+
-
-
-
+
+







'\"
'\" Copyright (c) 1990 The Regents of the University of California.
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
'\" Copyright (c) 1998 Scriptics Corporation.
'\" Copyright (c) 1998 by Scriptics Corporation.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH bind n 8.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
bind \- Arrange for X events to invoke Tcl scripts
.SH SYNOPSIS
\fBbind\fI tag\fR ?\fIsequence\fR? ?\fB+\fR??\fIscript\fR?
.BE
.SH "INTRODUCTION"
.PP
The \fBbind\fR command associates Tcl scripts with X events.
If all three arguments are specified, \fBbind\fR will
arrange for \fIscript\fR (a Tcl script called the
arrange for \fIscript\fR (a Tcl script) to be evaluated whenever
.QW "binding script")
to be evaluated whenever the event(s) given by \fIsequence\fR
occur in the window(s) identified by \fItag\fR.
the event(s) given by \fIsequence\fR occur in the window(s)
identified by \fItag\fR.
If \fIscript\fR is prefixed with a
.QW + ,
then it is appended to
any existing binding for \fIsequence\fR;  otherwise \fIscript\fR replaces
any existing binding.
If \fIscript\fR is an empty string then the current binding for
\fIsequence\fR is destroyed, leaving \fIsequence\fR unbound.
50
51
52
53
54
55
56
57
58
59
60
61



62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
49
50
51
52
53
54
55



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
-
-


+
+
+











-
+







Although the \fBbindtags\fR command may be used to assign an
arbitrary set of binding tags to a window, the default binding
tags provide the following behavior:
.IP \(bu 3
If a tag is the name of an internal window the binding applies
to that window.
.IP \(bu 3
If the tag is the name of a class of widgets, such as \fBButton\fR,
the binding applies to all widgets in that class.
.IP \(bu 3
If the tag is the name of a toplevel window the binding applies
to the toplevel window and all its internal windows.
.IP \(bu 3
If the tag is the name of a class of widgets, such as \fBButton\fR,
the binding applies to all widgets in that class;
.IP \(bu 3
If \fItag\fR has the value \fBall\fR,
the binding applies to all windows in the application.
.SH "EVENT PATTERNS"
.PP
The \fIsequence\fR argument specifies a sequence of one or more
event patterns, with optional white space between the patterns.  Each
event pattern may
take one of three forms.  In the simplest case it is a single
printing ASCII character, such as \fBa\fR or \fB[\fR.  The character
may not be a space character or the character \fB<\fR.  This form of
pattern matches a \fBKey\fR event for the particular
pattern matches a \fBKeyPress\fR event for the particular
character.  The second form of pattern is longer but more general.
It has the following syntax:
.CS
\fB<\fImodifier\-modifier\-type\-detail\fB>\fR
.CE
The entire event pattern is surrounded by angle brackets.
Inside the angle brackets are zero or more modifiers, an event
102
103
104
105
106
107
108
109
110


111
112
113
114
115
116
117
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116







-
-
+
+







.SS "MODIFIERS"
.PP
Modifiers consist of any of the following values:
.DS
.ta 6c
\fBControl\fR	\fBMod1\fR, \fBM1\fR, \fBCommand\fR
\fBAlt\fR	\fBMod2\fR, \fBM2\fR, \fBOption\fR
\fBShift\fR	\fBMod3\fR, \fBM3\fR, \fBNum\fR
\fBLock\fR	\fBMod4\fR, \fBM4\fR, \fBFn\fR
\fBShift\fR	\fBMod3\fR, \fBM3\fR
\fBLock\fR	\fBMod4\fR, \fBM4\fR
\fBExtended\fR	\fBMod5\fR, \fBM5\fR
\fBButton1\fR, \fBB1\fR	\fBMeta\fR, \fBM\fR
\fBButton2\fR, \fBB2\fR	\fBDouble\fR
\fBButton3\fR, \fBB3\fR	\fBTriple\fR
\fBButton4\fR, \fBB4\fR	\fBQuadruple\fR
\fBButton5\fR, \fBB5\fR
.DE
145
146
147
148
149
150
151
152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174

175
176
177
178
179
180
181





182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206


207
208

209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244


245
246
247

248
249
250
251
252
253

254
255
256
257
258
259
260
144
145
146
147
148
149
150



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171

172
173
174





175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202


203
204
205

206
207

208
209
210























211
212
213



214


215
216
217
218

219
220
221
222
223
224

225
226
227
228
229
230
231
232







-
-
-
+
+

















-
+

-
+


-
-
-
-
-
+
+
+
+
+




















-
+


-
-
+
+

-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-

-
-
+
+


-
+





-
+







times, and also place a time and space requirement on the sequence: for a
sequence of events to match a \fBDouble\fR, \fBTriple\fR or \fBQuadruple\fR
pattern, all of the events must occur close together in time and without
substantial mouse motion in between.  For example, \fB<Double\-Button\-1>\fR
is equivalent to \fB<Button\-1><Button\-1>\fR with the extra time and space
requirement.
.PP
The \fBCommand\fR, \fBOption\fR, \fBNum\fR and \fBFn\fRmodifiers are
equivalents of \fBMod1\fR up to \fBMod4\fR; they correspond to
Macintosh-specific modifier keys.
The \fBCommand\fR and \fBOption\fR modifiers are equivalents of \fBMod1\fR
resp. \fBMod2\fR, they correspond to Macintosh-specific modifier keys.
.PP
The \fBExtended\fR modifier is, at present, specific to Windows.  It
appears on events that are associated with the keys on the
.QW "extended keyboard" .
On a US keyboard, the extended keys include the \fBAlt\fR
and \fBControl\fR keys at the right of the keyboard, the cursor keys
in the cluster to the left of the numeric pad, the \fBNumLock\fR key,
the \fBBreak\fR key, the \fBPrintScreen\fR key, and the \fB/\fR and
\fBEnter\fR keys in the numeric keypad.
.SS "EVENT TYPES"
.PP
The \fItype\fR field may be any of the standard X event types, with a
few extra abbreviations.  The \fItype\fR field will also accept a
couple non-standard X event types that were added to better support
the Macintosh and Windows platforms.  Below is a list of all the valid
types; where two names appear together, they are synonyms.
.DS
.ta \w'\fBButton, ButtonPress\0\0\0\fR'u +\w'\fBKey, KeyPress\0\0\0\fR'u
.ta \w'\fBButtonPress, Button\0\0\0\fR'u +\w'\fBKeyPress, Key\0\0\0\fR'u
\fBActivate\fR	\fBDestroy\fR	\fBMap\fR
\fBButton\fR, \fBButtonPress\fR	\fBEnter\fR	\fBMapRequest\fR
\fBButtonPress\fR, \fBButton\fR	\fBEnter\fR	\fBMapRequest\fR
\fBButtonRelease\fR	\fBExpose\fR	\fBMotion\fR
\fBCirculate\fR	\fBFocusIn\fR	\fBMouseWheel\fR
\fBTouchpadScroll\fR	\fBCirculateRequest\fR	\fBFocusOut\fR
\fBProperty\fR	\fBColormap\fR	\fBGravity\fR
\fBReparent\fR	\fBConfigure\fR	\fBKey\fR, \fBKeyPress\fR
\fBResizeRequest\fR	\fBConfigureRequest\fR	\fBKeyRelease\fR
\fBUnmap\fR   \fBCreate\fR	\fBLeave\fR	\fBVisibility\fR
\fBCirculateRequest\fR	\fBFocusOut\fR	\fBProperty\fR
\fBColormap\fR	\fBGravity\fR	\fBReparent\fR
\fBConfigure\fR	\fBKeyPress\fR, \fBKey\fR	\fBResizeRequest\fR
\fBConfigureRequest\fR	\fBKeyRelease\fR	\fBUnmap\fR
\fBCreate\fR	\fBLeave\fR	\fBVisibility\fR
\fBDeactivate\fR
.DE
Most of the above events have the same fields and behaviors as events
in the X Windowing system.  You can find more detailed descriptions of
these events in any X window programming book.  A couple of the events
are extensions to the X event system to support features unique to the
Macintosh and Windows platforms.  We provide a little more detail on
these events here.  These include:
.IP "\fBActivate\fR, \fBDeactivate\fR" 5
These two events are sent to every sub-window of a toplevel when they
change state.  In addition to the focus Window, the Macintosh platform
and Windows platforms have a notion of an active window (which often
has but is not required to have the focus).  On the Macintosh, widgets
in the active window have a different appearance than widgets in
deactive windows.  The \fBActivate\fR event is sent to all the
sub-windows in a toplevel when it changes from being deactive to
active.  Likewise, the \fBDeactive\fR event is sent when the window's
state changes from active to deactive.  There are no useful percent
substitutions you would make when binding to these events.
.IP \fBMouseWheel\fR 5
Many contemporary mice include a mouse wheel, which is used
Many contemporary mice support a mouse wheel, which is used
for scrolling documents without using the scrollbars.  By rolling the
wheel, the system will generate \fBMouseWheel\fR events that the
application can use to scroll.  The event is routed to the
window currently under the mouse pointer. When the event
application can use to scroll.  Like \fBKey\fR events the event is
always routed to the window that currently has focus. When the event
is received you can use the \fB%D\fR substitution to get the
\fIdelta\fR field for the event, which is an integer value describing how
\fIdelta\fR field for the event, which is a integer value describing how
the mouse wheel has moved.  The smallest value for which the
system will report is defined by the OS.  The sign of the
system will report is defined by the OS. The sign of the
value determines which direction your widget should scroll.  Positive
values should scroll up and negative values should scroll down.
.RS
.PP
Horizontal scrolling uses \fBShift-MouseWheel\fR events, with positive
\fB%D\fR \fIdelta\fR substitution indicating left scrolling and
negative right scrolling. Horizontal scrolling events are generated
tilt wheels on some mice.  Horizontal scrolling can also be emulated
by holding Shift and scrolling vertically.
.RE
.IP "\fBTouchpadScroll\fR" 5
On some platforms (currently Windows and macOS) there is support for
high-resolution scrolling devices, such as touchpads.  This is
provided via \fBTouchpadScroll\fR events.  These events store two
16 bit delta values in the integer provided by the \fB%D\fR
substitution.  The \fIX\fR delta is in the high order 16 bits and the
\fIY\fR delta is in the low order 16 bits.  These values can be
unpacked by using the tk::PreciseScrollDeltas utility procedure.  For
example:
.CS
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
.CE
The \fB$#\fR substitution is a counter for \fBTouchpadScroll\fR events
which can be used by widgets that only support scrolling by units to
ignore some portion of the events.
.IP "\fBKeyPress\fR, \fBKeyRelease\fR" 5
The \fBKeyPress\fR and \fBKeyRelease\fR events are generated
whenever a key is pressed or released.  \fBKeyPress\fR and \fBKeyRelease\fR
.IP "\fBKey\fR, \fBKeyRelease\fR" 5
The \fBKey\fR and \fBKeyRelease\fR events are generated
whenever a key is pressed or released.  \fBKey\fR and \fBKeyRelease\fR
events are sent to the window which currently has the keyboard focus.
.IP "\fBButton\fR, \fBButtonRelease\fR, \fBMotion\fR" 5
The \fBButton\fR and \fBButtonRelease\fR events
.IP "\fBButtonPress\fR, \fBButtonRelease\fR, \fBMotion\fR" 5
The \fBButtonPress\fR and \fBButtonRelease\fR events
are generated when the user presses or releases a mouse button.
\fBMotion\fR events are generated whenever the pointer is moved.
\fBButton\fR, \fBButtonRelease\fR, and \fBMotion\fR events are
\fBButtonPress\fR, \fBButtonRelease\fR, and \fBMotion\fR events are
normally sent to the window containing the pointer.
.RS
.PP
When a mouse button is pressed, the window containing the pointer
automatically obtains a temporary pointer grab.
Subsequent \fBButton\fR, \fBButtonRelease\fR, and \fBMotion\fR
Subsequent \fBButtonPress\fR, \fBButtonRelease\fR, and \fBMotion\fR
events will be sent to that window,
regardless of which window contains the pointer,
until all buttons have been released.
.RE
.IP \fBConfigure\fR 5
A \fBConfigure\fR event is sent to a window whenever its
size, position, or border width changes, and sometimes
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308
265
266
267
268
269
270
271

272

273
274
275
276
277
278
279







-
+
-







A \fBDestroy\fR event is delivered to a window when
it is destroyed.
.RS
.PP
When the \fBDestroy\fR event is delivered
to a widget, it is in a
.QW half-dead
state: the widget still exists, but operations that involve it
state: the widget still exists, but most operations on it will fail.
may return invalid results, or return an error.
.RE
.IP "\fBFocusIn\fR, \fBFocusOut\fR" 5
The \fBFocusIn\fR and \fBFocusOut\fR events are generated
whenever the keyboard focus changes.
A \fBFocusOut\fR event is sent to the old focus window,
and a \fBFocusIn\fR event is sent to the new one.
.RS
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392


393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

415
416

417
418
419

420
421
422
423
424
425
426
427
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361


362
363
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

385
386

387
388
389

390

391
392
393
394
395
396
397







-
+








-
-
+
+

-
+



















-
+

-
+


-
+
-







This event type is included only for completeness;
there is no reliable way to track changes to a window's
position in the stacking order.
.RE
.SS "EVENT DETAILS"
.PP
The last part of a long event specification is \fIdetail\fR.  In the
case of a \fBButton\fR or \fBButtonRelease\fR event, it is the
case of a \fBButtonPress\fR or \fBButtonRelease\fR event, it is the
number of a button (1\-9).  If a button number is given, then only an
event on that particular button will match;  if no button number is
given, then an event on any button will match.  Note:  giving a
specific button number is different than specifying a button modifier;
in the first case, it refers to a button being pressed or released,
while in the second it refers to some other button that is already
depressed when the matching event occurs.  If a button
number is given then \fItype\fR may be omitted:  if will default
to \fBButton\fR.  For example, the specifier \fB<1>\fR
is equivalent to \fB<Button\-1>\fR.
to \fBButtonPress\fR.  For example, the specifier \fB<1>\fR
is equivalent to \fB<ButtonPress\-1>\fR.
.PP
If the event type is \fBKey\fR or \fBKeyRelease\fR, then
If the event type is \fBKeyPress\fR or \fBKeyRelease\fR, then
\fIdetail\fR may be specified in the form of an X keysym.  Keysyms
are textual specifications for particular keys on the keyboard;
they include all the alphanumeric ASCII characters (e.g.
.QW a
is the keysym for the ASCII character
.QW a ),
plus descriptions for non-alphanumeric characters
.PQ comma "is the keysym for the comma character" ,
plus descriptions for all the non-ASCII keys on the keyboard (e.g.
.QW Shift_L
is the keysym for the left shift key, and
.QW F1
is the keysym for the F1 function key, if it exists).  The
complete list of keysyms is not presented here;  it is
available in other X documentation and may vary from system to
system.
If necessary, you can use the \fB%K\fR notation described below
to print out the keysym name for a particular key.
If a keysym \fIdetail\fR is given, then the
\fItype\fR field may be omitted;  it will default to \fBKey\fR.
\fItype\fR field may be omitted;  it will default to \fBKeyPress\fR.
For example, \fB<Control\-comma>\fR is equivalent to
\fB<Control\-Key\-comma>\fR.
\fB<Control\-KeyPress\-comma>\fR.
.SH "BINDING SCRIPTS AND SUBSTITUTIONS"
.PP
The \fIscript\fR argument to \fBbind\fR is a Tcl script, called the
The \fIscript\fR argument to \fBbind\fR is a Tcl script,
.QW "binding script",
which will be executed whenever the given event sequence occurs.
\fICommand\fR will be executed in the same interpreter that the
\fBbind\fR command was executed in, and it will run at global
level (only global variables will be accessible).
If \fIscript\fR contains
any \fB%\fR characters, then the script will not be
executed directly.  Instead, a new script will be
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429







-
+







formatted as a hexadecimal number.
Valid only for \fBConfigure\fR events.
Indicates the sibling window immediately below the receiving window
in the stacking order, or \fB0\fR if the receiving window is at the
bottom.
.IP \fB%b\fR 5
The number of the button that was pressed or released.  Valid only
for \fBButton\fR and \fBButtonRelease\fR events.
for \fBButtonPress\fR and \fBButtonRelease\fR events.
.IP \fB%c\fR 5
The \fIcount\fR field from the event.  Valid only for \fBExpose\fR events.
Indicates that there are \fIcount\fR pending \fBExpose\fR events which have not
yet been delivered to the window.
.IP \fB%d\fR 5
The \fIdetail\fR or \fIuser_data\fR
field from the event.  The \fB%d\fR is replaced by
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515


516
517
518
519
520
521
522
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483


484
485
486
487
488
489
490
491
492







-
+














-
-
+
+







\fBConfigureRequest\fR, \fBCreate\fR, \fBResizeRequest\fR, and
\fBExpose\fR events.
Indicates the new or requested height of the window.
.IP \fB%i\fR 5
The \fIwindow\fR field from the event, represented as a hexadecimal
integer.  Valid for all event types.
.IP \fB%k\fR 5
The \fIkeycode\fR field from the event.  Valid only for \fBKey\fR
The \fIkeycode\fR field from the event.  Valid only for \fBKeyPress\fR
and \fBKeyRelease\fR events.
.IP \fB%m\fR 5
The \fImode\fR field from the event.  The substituted string is one of
\fBNotifyNormal\fR, \fBNotifyGrab\fR, \fBNotifyUngrab\fR, or
\fBNotifyWhileGrabbed\fR.  Valid only for \fBEnter\fR,
\fBFocusIn\fR, \fBFocusOut\fR, and \fBLeave\fR events.
.IP \fB%o\fR 5
The \fIoverride_redirect\fR field from the event.  Valid only for
\fBMap\fR, \fBReparent\fR, and \fBConfigure\fR events.
.IP \fB%p\fR 5
The \fIplace\fR field from the event, substituted as one of the
strings \fBPlaceOnTop\fR or \fBPlaceOnBottom\fR.  Valid only
for \fBCirculate\fR and \fBCirculateRequest\fR events.
.IP \fB%s\fR 5
The \fIstate\fR field from the event.  For \fBButton\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBKey\fR, \fBKeyRelease\fR,
The \fIstate\fR field from the event.  For \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
\fBLeave\fR, and \fBMotion\fR events, a decimal string
is substituted.  For \fBVisibility\fR, one of the strings
\fBVisibilityUnobscured\fR, \fBVisibilityPartiallyObscured\fR,
and \fBVisibilityFullyObscured\fR is substituted.
For \fBProperty\fR events, substituted with
either the string \fBNewValue\fR (indicating that the property
has been created or modified) or \fBDelete\fR (indicating that
530
531
532
533
534
535
536
537
538


539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579

580
581
582
583
584
585
586
500
501
502
503
504
505
506


507
508
509
510



511
512
513
514
515
516
517

518
519
520


521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

539
540
541
542
543
544

545
546
547
548
549
550
551
552







-
-
+
+


-
-
-







-
+


-
-
+

















-
+





-
+







The \fIwidth\fR field from the event.
Indicates the new or requested width of the window.
Valid only for
\fBConfigure\fR, \fBConfigureRequest\fR, \fBCreate\fR,
\fBResizeRequest\fR, and \fBExpose\fR events.
.IP "\fB%x\fR, \fB%y\fR" 5
The \fIx\fR and \fIy\fR fields from the event.
For \fBButton\fR, \fBButtonRelease\fR, \fBMotion\fR,
\fBKey\fR, \fBKeyRelease\fR, and \fBMouseWheel\fR events,
For \fBButtonPress\fR, \fBButtonRelease\fR, \fBMotion\fR,
\fBKeyPress\fR, \fBKeyRelease\fR, and \fBMouseWheel\fR events,
\fB%x\fR and \fB%y\fR indicate the position of the mouse pointer
relative to the receiving window.
For key events on the Macintosh these are the coordinates of the
mouse at the moment when an X11 KeyEvent is sent to Tk, which could
be slightly later than the time of the physical press or release.
For \fBEnter\fR and \fBLeave\fR events, the position where the
mouse pointer crossed the window, relative to the receiving window.
For \fBConfigure\fR and \fBCreate\fR requests, the \fIx\fR and \fIy\fR
coordinates of the window relative to its parent window.
.IP \fB%A\fR 5
Substitutes the UNICODE character corresponding to the event, or
the empty string if the event does not correspond to a UNICODE character
(e.g. the shift key was pressed). On X11, \fBXmbLookupString\fR (or
(e.g. the shift key was pressed). \fBXmbLookupString\fR (or
\fBXLookupString\fR when input method support is turned off) does all
the work of translating from the event to a UNICODE character.
On X11, valid only for \fBKey\fR event. On Windows and macOS/aqua,
valid only for \fBKey\fR and \fBKeyRelease\fR events.
Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
.IP \fB%B\fR 5
The \fIborder_width\fR field from the event.  Valid only for
\fBConfigure\fR, \fBConfigureRequest\fR, and \fBCreate\fR events.
.IP \fB%D\fR 5
This reports the \fIdelta\fR value of a \fBMouseWheel\fR event.  The
\fIdelta\fR value represents the rotation units the mouse wheel has
been moved. The sign of the value represents the direction the mouse
wheel was scrolled.
.IP \fB%E\fR 5
The \fIsend_event\fR field from the event.  Valid for all event types.
\fB0\fR indicates that this is a
.QW normal
event, \fB1\fR indicates that it is a
.QW synthetic
event generated by \fBSendEvent\fR.
.IP \fB%K\fR 5
The keysym corresponding to the event, substituted as a textual
string.  Valid only for \fBKey\fR and \fBKeyRelease\fR events.
string.  Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
.IP \fB%M\fR 5
The number of script-based binding patterns matched so far for the
event.  Valid for all event types.
.IP \fB%N\fR 5
The keysym corresponding to the event, substituted as a decimal
number.  Valid only for \fBKey\fR and \fBKeyRelease\fR events.
number.  Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
.IP \fB%P\fR 5
The name of the property being updated or deleted (which
may be converted to an XAtom using \fBwinfo atom\fR.) Valid
only for \fBProperty\fR events.
.IP \fB%R\fR 5
The \fIroot\fR window identifier from the event.  Valid only for
events containing a \fIroot\fR field.
594
595
596
597
598
599
600
601
602


603
604
605
606
607
608
609
560
561
562
563
564
565
566


567
568
569
570
571
572
573
574
575







-
-
+
+







The path name of the window to which the event was reported (the
\fIwindow\fR field from the event).  Valid for all event types.
.IP "\fB%X\fR, \fB%Y\fR" 5
The \fIx_root\fR and  \fIy_root\fR fields from the event.
If a virtual-root window manager is being used then the substituted
values are the corresponding x-coordinate and y-coordinate in the virtual root.
Valid only for
\fBButton\fR, \fBButtonRelease\fR, \fBEnter\fR, \fBKey\fR,
\fBKeyRelease\fR, \fBLeave\fR and \fBMotion\fR events.
\fBButtonPress\fR, \fBButtonRelease\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
and \fBMotion\fR events.
Same meaning as \fB%x\fR and \fB%y\fR, except relative to the (virtual) root
window.
.LP
The replacement string for a %-replacement is formatted as a proper
Tcl list element.
This means that spaces or special characters such as \fB$\fR and
\fB{\fR may be preceded by backslashes.
636
637
638
639
640
641
642
643

644
645
646
647


648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669


670
671
672
673
674

675
676
677
678

679
680
681
682
683
684
685
602
603
604
605
606
607
608

609




610
611
612
613
614
615






616
617
618
619
620
621
622
623
624
625


626
627

628
629
630

631
632
633
634

635
636
637
638
639
640
641
642







-
+
-
-
-
-
+
+




-
-
-
-
-
-










-
-
+
+
-



-
+



-
+







an \fBall\fR binding.
The \fBbindtags\fR command may be used to change this order for
a particular window or to associate additional binding tags with
the window.
.PP
The \fBcontinue\fR and \fBbreak\fR commands may be used inside a
binding script to control the processing of matching scripts.
If \fBcontinue\fR is invoked within a binding script, then this
If \fBcontinue\fR is invoked, then the current binding script
binding script, including all other
.QW +
appended scripts, is terminated but Tk will continue processing
binding scripts associated with other \fItag\fR's.
is terminated but Tk will continue processing binding scripts
associated with other \fItag\fR's.
If the \fBbreak\fR command is invoked within a binding script,
then that script terminates and no other scripts will be invoked
for the event.
.PP
Within a script called from the binding script, \fBreturn\fR
\fB\-code ok\fR may be used to continue processing (including
.QW +
appended scripts), or \fBreturn\fR \fB\-code break\fR may be used to
stop processing all other binding scripts.
.PP
If more than one binding matches a particular event and they
have the same \fItag\fR, then the most specific binding
is chosen and its script is evaluated.
The following tests are applied, in order, to determine which of
several matching sequences is more specific:
.RS
.IP (a)
an event pattern that specifies a specific button or key is more specific
than one that does not;
.IP (b)
a sequence with the most highest-ordered patterns (in term of highest
repetition count) is more specific than a sequence with less
a longer sequence (in terms of number
of events matched) is more specific than a shorter sequence;
highest-ordered patterns;
.IP (c)
if the modifiers specified in one pattern are a subset of the
modifiers in another pattern, then the pattern with more modifiers
is more specific;
is more specific.
.IP (d)
a virtual event whose physical pattern matches the sequence is less
specific than the same physical pattern that is not associated with a
virtual event;
virtual event.
.IP (e)
given a sequence that matches two or more virtual events, one
of the virtual events will be chosen, but the order is undefined.
.RE
.PP
If the matching sequences contain more than one event, then tests
(c)\-(e) are applied in order from the most recent event to the least recent
707
708
709
710
711
712
713
714

715
716
717
718
719


720
721
722
723
724



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743

744
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760
761
762
763
664
665
666
667
668
669
670

671
672
673
674


675
676
677
678



679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707
708

709
710
711
712
713
714
715
716
717
718
719
720







-
+



-
-
+
+


-
-
-
+
+
+


















-
+








-
+











An unbound event is not considered to be an error.
.SH "MULTI-EVENT SEQUENCES AND IGNORED EVENTS"
.PP
When a \fIsequence\fR specified in a \fBbind\fR command contains
more than one event pattern, then its script is executed whenever
the recent events (leading up to and including the current event)
match the given sequence.  This means, for example, that if button 1 is
clicked repeatedly the sequence \fB<Double\-Button\-1>\fR will match
clicked repeatedly the sequence \fB<Double\-ButtonPress\-1>\fR will match
each button press but the first.
If extraneous events that would prevent a match occur in the middle
of an event sequence then the extraneous events are
ignored unless they are \fBKey\fR or \fBButton\fR events.
For example, \fB<Double\-Button\-1>\fR will match a sequence of
ignored unless they are \fBKeyPress\fR or \fBButtonPress\fR events.
For example, \fB<Double\-ButtonPress\-1>\fR will match a sequence of
presses of button 1, even though there will be \fBButtonRelease\fR
events (and possibly \fBMotion\fR events) between the
\fBButton\fR events.
Furthermore, a \fBKey\fR event may be preceded by any number
of other \fBKey\fR events for modifier keys without the
\fBButtonPress\fR events.
Furthermore, a \fBKeyPress\fR event may be preceded by any number
of other \fBKeyPress\fR events for modifier keys without the
modifier keys preventing a match.
For example, the event sequence \fBaB\fR will match a press of the
\fBa\fR key, a release of the \fBa\fR key, a press of the \fBShift\fR
key, and a press of the \fBb\fR key:  the press of \fBShift\fR is
ignored because it is a modifier key.
Finally, if several \fBMotion\fR events occur in a row, only
the last one is used for purposes of matching binding sequences.
.SH "ERRORS"
.PP
If an error occurs in executing the script for a binding then the
\fBbgerror\fR mechanism is used to report the error.
The \fBbgerror\fR command will be executed at global level
(outside the context of any Tcl procedure).
.SH "EXAMPLES"
.PP
Arrange for a string describing the motion of the mouse to be printed
out when the mouse is double-clicked:
.CS
\fBbind\fR . <Double-1> {
\fBbind\fR . <Double\-1> {
    puts "hi from (%x,%y)"
}
.CE
.PP
A little GUI that displays what the keysym name of the last key
pressed is:
.CS
set keysym "Press any key"
pack [label .l -textvariable keysym -padx 2m -pady 1m]
pack [label .l \-textvariable keysym \-padx 2m \-pady 1m]
\fBbind\fR . <Key> {
    set keysym "You pressed %K"
}
.CE
.SH "SEE ALSO"
bgerror(n), bindtags(n), event(n), focus(n), grab(n), keysyms(n)
.SH KEYWORDS
binding, event
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/bitmap.n.

11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25







-
+







'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
bitmap \- Images that display two colors
.SH SYNOPSIS
.nf
\fBimage create bitmap \fR?\fIname\fR? ?\fIoptions\fR?

\fIimageName \fBcget\fI option\fR
\fIimageName \fBcget\fR \fIoption\fR
\fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.fi
.BE
.SH DESCRIPTION
.PP
A bitmap is an image whose pixels can display either of two colors
or be transparent.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57

58
59
60
61
62
63
64

65
66
67
68
69

70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97

98

99
100
101
102
103
104

105
106
107
108
109
110
111







-








-








-







-





-








-















-
+




-

-
+





-







the source data is one and the background color if the source
data is zero.
.SH "CREATING BITMAPS"
.PP
Like all images, bitmaps are created using the \fBimage create\fR
command.
Bitmaps support the following \fIoptions\fR:
.\" OPTION: -background
.TP
\fB\-background \fIcolor\fR
.
Specifies a background color for the image in any of the standard
ways accepted by Tk.  If this option is set to an empty string
then the background pixels will be transparent.  This effect
is achieved by using the source bitmap as the mask bitmap, ignoring
any \fB\-maskdata\fR or \fB\-maskfile\fR options.
.\" OPTION: -data
.TP
\fB\-data \fIstring\fR
.
Specifies the contents of the source bitmap as a string.
The string must adhere to X11 bitmap format (e.g., as generated
by the \fBbitmap\fR program).
If both the \fB\-data\fR and \fB\-file\fR options are specified,
the \fB\-data\fR option takes precedence.
.\" OPTION: -file
.TP
\fB\-file \fIname\fR
.
\fIname\fR gives the name of a file whose contents define the
source bitmap.
The file must adhere to X11 bitmap format (e.g., as generated
by the \fBbitmap\fR program).
.\" OPTION: -foreground
.TP
\fB\-foreground \fIcolor\fR
.
Specifies a foreground color for the image in any of the standard
ways accepted by Tk.
.\" OPTION: -maskdata
.TP
\fB\-maskdata \fIstring\fR
.
Specifies the contents of the mask as a string.
The string must adhere to X11 bitmap format (e.g., as generated
by the \fBbitmap\fR program).
If both the \fB\-maskdata\fR and \fB\-maskfile\fR options are specified,
the \fB\-maskdata\fR option takes precedence.
.\" OPTION: -maskfile
.TP
\fB\-maskfile \fIname\fR
.
\fIname\fR gives the name of a file whose contents define the
mask.
The file must adhere to X11 bitmap format (e.g., as generated
by the \fBbitmap\fR program).
.SH "IMAGE COMMAND"
.PP
When a bitmap image is created, Tk also creates a new command
whose name is the same as the image.
This command may be used to invoke various operations
on the image.
It has the following general form:
.CS
\fIimageName option \fR?\fIarg ...\fR?
\fIimageName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for bitmap images:
.\" METHOD: cget
.TP
\fIimageName \fBcget\fI option\fR
\fIimageName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the
\fBimage create\fR \fBbitmap\fR command.
.\" METHOD: configure
.TP
\fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options for the image.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIimageName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified

Changes to doc/busy.n.

24
25
26
27
28
29
30
31

32
33
34

35
36



37

38


39

40
41
42
43
44
45
46


47
48

49
50
51
52
53
54
55
24
25
26
27
28
29
30

31
32


33


34
35
36
37
38

39
40
41
42
43

44
45
46


47
48


49
50
51
52
53
54
55
56







-
+

-
-
+
-
-
+
+
+

+
-
+
+

+

-



-
-
+
+
-
-
+







'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH busy n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
busy \- Make Tk widgets busy, temporarily blocking user interactions
busy \- confine pointer and keyboard events to a window sub-tree
.SH SYNOPSIS
.nf
\fBtk busy\fI window \fR?\fIoptions\fR?
\fBtk busy\fR \fIwindow \fR?\fIoptions\fR?
\fBtk busy busywindow \fIwindow\fR
\fBtk busy hold\fI window \fR?\fIoptions\fR?
.sp
\fBtk busy hold\fR \fIwindow \fR?\fIoptions\fR?
.sp
\fBtk busy configure \fIwindow\fR ?\fIoption value\fR?...
.sp
\fBtk busy forget\fI window \fR?\fIwindow \fR?...
\fBtk busy forget\fR \fIwindow \fR?\fIwindow \fR?...
.sp
\fBtk busy current\fR ?\fIpattern\fR?
.sp
\fBtk busy status \fIwindow\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBtk busy\fR command provides a simple means to block mouse pointer events
from Tk widgets, while overriding the widget's cursor with a configurable busy
The \fBtk busy\fR command provides a simple means to block keyboard, button,
and pointer events from Tk widgets, while overriding the widget's cursor with
cursor. Note this command does not prevent keyboard events from being sent to
the widgets made busy.
a configurable busy cursor.
.SH INTRODUCTION
.PP
There are many times in applications where you want to temporarily restrict
what actions the user can take. For example, an application could have a
.QW Run
button that when pressed causes some processing to occur. However, while the
application is busy processing, you probably don't want the user to be
63
64
65
66
67
68
69
70
71


72
73
74
75
76
77
78
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79







-
-
+
+







The \fBtk busy\fR command lets you make Tk widgets busy. This means that user
interactions such as button clicks, moving the mouse, typing at the keyboard,
etc.\0are ignored by the widget. You can set a special cursor (like a watch)
that overrides the widget's normal cursor, providing feedback that the
application (widget) is temporarily busy.
.PP
When a widget is made busy, the widget and all of its descendants will ignore
pointer events. It's easy to make an entire panel of widgets busy. You can
simply make the toplevel widget (such as
events. It's easy to make an entire panel of widgets busy. You can simply make
the toplevel widget (such as
.QW . )
busy. This is easier and far much more efficient than recursively traversing
the widget hierarchy, disabling each widget and re-configuring its cursor.
.PP
Often, the \fBtk busy\fR command can be used instead of Tk's \fBgrab\fR
command. Unlike \fBgrab\fR which restricts all user interactions to one
widget, with the \fBtk busy\fR command you can have more than one widget
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131


132
133
134
135














136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128

129

130
131
132
133




134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155

156
157
158
159
160
161
162







-
+












-

-
+

+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+






-







\fBtk busy\fR forget .top
.CE
.PP
The busy window has a configurable cursor. You can change the busy cursor
using the \fBconfigure\fR operation.
.PP
.CS
\fBtk busy\fR configure .top -cursor "watch"
\fBtk busy\fR configure .top \-cursor "watch"
.CE
.PP
Destroying the widget will also clean up any resources allocated by the \fBtk
busy\fR command.
.PP
.SH OPERATIONS
.PP
The following operations are available for the \fBtk busy\fR command:
.TP
\fBtk busy \fIwindow\fR ?\fIoption value\fR?...
.
Shortcut for \fBtk busy hold\fR command.
.\" METHOD: busywindow
.TP
\fBtk busy busywindow \fIwindow\fR
\fBtk busy hold \fIwindow\fR ?\fIoption value\fR?...
.
Makes the specified \fIwindow\fR (and its descendants in the Tk window
hierarchy) appear busy. \fIWindow\fR must be a valid path name of a Tk widget.
Returns the pathname of the busy window (i.e. the transparent window
shielding the window appearing busy) created by the \fBtk busy hold\fR
command for \fIwindow\fR, or the empty string if \fIwindow\fR is not busy.
.\" METHOD: cget
A transparent window is put in front of the specified window. This transparent
window is mapped the next time idle tasks are processed, and the specified
window and its descendants will be blocked from user interactions. Normally
\fBupdate\fR should be called immediately afterward to insure that the hold
operation is in effect before the application starts its processing. The
following configuration options are valid:
.RS
.TP
\fB\-cursor \fIcursorName\fR
.
Specifies the cursor to be displayed when the widget is made busy.
\fICursorName\fR can be in any form accepted by \fBTk_GetCursor\fR. The
default cursor is \fBwait\fR on Windows and \fBwatch\fR on other platforms.
.RE
.TP
\fBtk busy cget \fIwindow option\fR
\fBtk busy cget \fIwindow\fR \fIoption\fR
.
Queries the \fBtk busy\fR command configuration options for \fIwindow\fR.
\fIWindow\fR must be the path name of a widget previously made busy by the
\fBhold\fR operation. The command returns the present value of the specified
\fIoption\fR. \fIOption\fR may have any of the values accepted by the
\fBhold\fR operation.
.\" METHOD: configure
.TP
\fBtk busy configure \fIwindow\fR ?\fIoption value\fR?...
.
Queries or modifies the \fBtk busy\fR command configuration options for
\fIwindow\fR. \fIWindow\fR must be the path name of a widget previously made
busy by the \fBhold\fR operation.  If no options are specified, a list
describing all of the available options for \fIwindow\fR (see
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198

199
200


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224


225
226
227
228

229
230

231














232
233
234


235
236
237
238
239
240
241
242
243
244

245
246
247


248
249
250
251
252
253
254
255


256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
175
176
177
178
179
180
181








182
183
184
185
186
187
188
189

190

191
192








193


194
195










196
197
198
199
200
201
202
203
204
205
206
207


208
209
210
211
212

213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231


232
233
234
235
236
237
238
239
240
241
242

243



244
245

246
247


248


249
250


251
252
253
254
255

256

257
258
259
260
261
262
263
264
265
266
267







-
-
-
-
-
-
-
-








-

-
+

-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-












-
-
+
+



-
+


+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+









-
+
-
-
-
+
+
-


-
-

-
-
+
+
-
-





-
+
-











specified for it by either \fBoption\fR command:
.PP
.CS
option add *frame.busyCursor gumby
option add *Frame.BusyCursor gumby
.CE
.RE
.\" METHOD: current
.TP
\fBtk busy current \fR?\fIpattern\fR?
.
Returns the pathnames of all widgets that are currently busy. If a
\fIpattern\fR is given, only the path names of busy widgets matching
\fIpattern\fR are returned.
.\" METHOD: forget
.TP
\fBtk busy forget \fIwindow\fR ?\fIwindow\fR?...
.
Releases resources allocated by the \fBtk busy\fR command for \fIwindow\fR,
including the transparent window. User events will again be received by
\fIwindow\fR. Resources are also released when \fIwindow\fR is destroyed.
\fIWindow\fR must be the name of a widget specified in the \fBhold\fR
operation, otherwise an error is reported.
.\" METHOD: hold
.TP
\fBtk busy hold \fIwindow\fR ?\fIoption value\fR?...
\fBtk busy current \fR?\fIpattern\fR?
.
Makes the specified \fIwindow\fR (and its descendants in the Tk window
hierarchy) appear busy. \fIWindow\fR must be a valid path name of a Tk widget.
A transparent window is put in front of the specified window. This transparent
window is mapped the next time idle tasks are processed, and the specified
window and its descendants will be blocked from user interactions. Normally
\fBupdate\fR should be called immediately afterward to insure that the hold
operation is in effect before the application starts its processing. The
command returns the pathname of the busy window that was created (i.e. the
Returns the pathnames of all widgets that are currently busy. If a
transparent window shielding the window appearing busy). The following
configuration options are valid:
\fIpattern\fR is given, only the path names of busy widgets matching
\fIpattern\fR are returned.
.RS
.\" OPTION: -cursor
.TP
\fB\-cursor \fIcursorName\fR
.
Specifies the cursor to be displayed when the widget is made busy.
\fICursorName\fR can be in any form accepted by \fBTk_GetCursor\fR. The
default cursor is \fBwait\fR on Windows and \fBwatch\fR on other platforms.
.RE
.\" METHOD: status
.TP
\fBtk busy status \fIwindow\fR
.
Returns the status of a widget \fIwindow\fR. If \fIwindow\fR presently can not
receive user interactions, \fB1\fR is returned, otherwise \fB0\fR.
.SH "EVENT HANDLING"
.SS BINDINGS
.PP
The event blocking feature is implemented by creating and mapping a
transparent window that completely covers the widget. When the busy window is
mapped, it invisibly shields the widget and its hierarchy from all events that
may be sent. Like Tk widgets, busy windows have widget names in the Tk window
hierarchy. This means that you can use the \fBbind\fR command to handle
events in the busy window:
hierarchy. This means that you can use the \fBbind\fR command, to handle
events in the busy window.
.PP
.CS
\fBtk busy\fR hold .frame.canvas
bind [\fBtk busy\fR busywindow .frame.canvas] <Enter> { ... }
bind .frame.canvas_Busy <Enter> { ... }
.CE
.PP
Normally the busy window is a sibling of the widget. The name of the busy
or
window is
.QW \fIwidget\fB_Busy\fR
where \fIwidget\fR is the name of the widget to be made busy. In the previous
example, the pathname of the busy window is
.QW \fB.frame.canvas_Busy\fR .
The exception is when the widget is a toplevel widget (such as
.QW . )
where the busy window can't be made a sibling. The busy window is then a child
of the widget named
.QW \fIwidget\fB._Busy\fR
where \fIwidget\fR is the name of the toplevel widget. In the following
example, the pathname of the busy window is
.QW \fB._Busy\fR .
.PP
.CS
set busyWin [\fBtk busy\fR hold .frame.canvas]
bind $busyWin <Enter> { ... }
\fBtk busy\fR hold .
bind ._Busy <Enter> { ... }
.CE
.SS "ENTER/LEAVE EVENTS"
.PP
Mapping and unmapping busy windows generates Enter/Leave events for all
widgets they cover. Please note this if you are tracking Enter/Leave events in
widgets.
.SS "KEYBOARD EVENTS"
.PP
When a widget is made busy, the widget is prevented from gaining the keyboard
focus by a user clicking on it by the busy window. But if the widget already had
focus by the busy window. But if the widget already had focus, it still may
focus, it still may receive keyboard events. The widget can also still receive
focus through keyboard traversal. To prevent this, you must move
focus to another window and make sure the focus can not go back to the widgets
received keyboard events. To prevent this, you must move focus to another
window.
made busy (e.g. but restricting focus to a cancel button).
.PP
.CS
pack [frame .frame]
pack [text .frame.text]
\fBtk busy\fR hold .frame
pack [button .cancel -text "Cancel" -command exit]
focus .cancel
label .dummy
focus .dummy
bind .cancel <Tab> {break}
bind .cancel <Shift-Tab> {break}
update
.CE
.PP
The above example moves the focus from .frame immediately after invoking the
\fBhold\fR so that no keyboard events will be sent to \fB.frame\fR or any of
its descendants. It also makes sure it's not possible to leave button
its descendants.
\fB.cancel\fR using the keyboard.
.SH PORTABILITY
.PP
Note that the \fBtk busy\fR command does not currently have any effect on OSX
when Tk is built using Aqua support.
.SH "SEE ALSO"
grab(n)
.SH KEYWORDS
busy, keyboard events, pointer events, window
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/button.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH button n 4.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
button \- Create and manipulate 'button' action widgets
.SH SYNOPSIS
\fBbutton\fI pathName \fR?\fIoptions\fR?
\fBbutton\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-font	\-relief
\-activeforeground	\-foreground	\-repeatdelay
\-anchor	\-highlightbackground	\-repeatinterval
\-background	\-highlightcolor	\-takefocus
\-bitmap	\-highlightthickness	\-text
\-borderwidth	\-image	\-textvariable
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
105
106
107
108
109
110
111

112
113
114
115
116

117

118

119
120
121
122

123
124

125
126
127
128
129
130
131
132
133
134
135
136

137
138

139
140
141
142
143

144
145

146
147
148
149
150
151
152







-
+




-

-
+
-




-


-












-


-





-


-







.SH "WIDGET COMMAND"
.PP
The \fBbutton\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for button widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBbutton\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBbutton\fR
command.
.\" METHOD: flash
.TP
\fIpathName \fBflash\fR
.
Flash the button.  This is accomplished by redisplaying the button
several times, alternating between the configured activebackground
and background colors.  At the end of the flash the button is left
in the same normal/active state as when the command was invoked.
This command is ignored if the button's state is \fBdisabled\fR.
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke\fR
.
Invoke the Tcl command associated with the button, if there is one.
The return value is the return value from the Tcl command, or an
empty string if there is no command associated with the button.
This command is ignored if the button's state is \fBdisabled\fR.
.SH "DEFAULT BINDINGS"
.PP
Tk automatically creates class bindings for buttons that give them
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209




210
211
212
213
214
215
216
217
218
184
185
186
187
188
189
190

191
192
193
194
195
196
197




198
199
200
201
202
203
204
205
206
207
208
209
210







-
+






-
-
-
-
+
+
+
+









.SH EXAMPLES
.PP
This is the classic Tk
.QW "Hello, World!"
demonstration:
.PP
.CS
\fBbutton\fR .b -text "Hello, World!" -command exit
\fBbutton\fR .b \-text "Hello, World!" \-command exit
pack .b
.CE
.PP
This example demonstrates how to handle button accelerators:
.PP
.CS
\fBbutton\fR .b1 -text Hello -underline 0
\fBbutton\fR .b2 -text World -underline 0
bind . <Key-h> {.b1 flash; .b1 invoke}
bind . <Key-w> {.b2 flash; .b2 invoke}
\fBbutton\fR .b1 \-text Hello \-underline 0
\fBbutton\fR .b2 \-text World \-underline 0
bind . <Key\-h> {.b1 flash; .b1 invoke}
bind . <Key\-w> {.b2 flash; .b2 invoke}
pack .b1 .b2
.CE
.SH "SEE ALSO"
ttk::button(n)
.SH KEYWORDS
button, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/canvas.n.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23







-
+







.TH canvas n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
canvas \- Create and manipulate 'canvas' hypergraphics drawing surface widgets
.SH SYNOPSIS
\fBcanvas\fI pathName \fR?\fIoptions\fR?
\fBcanvas\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-background	\-borderwidth	\-cursor
\-highlightbackground	\-highlightcolor	\-highlightthickness
\-insertbackground	\-insertborderwidth	\-insertofftime
\-insertontime	\-insertwidth	\-relief
\-selectbackground	\-selectborderwidth	\-selectforeground
\-takefocus	\-xscrollcommand	\-yscrollcommand
216
217
218
219
220
221
222
223

224
225
226
227
228

229
230
231
232
233
234
235
216
217
218
219
220
221
222

223





224
225
226
227
228
229
230
231







-
+
-
-
-
-
-
+







It is possible to adjust the origin of the canvas
coordinate system relative to the origin of the window using the
\fBxview\fR and \fByview\fR widget commands; this is typically used
for scrolling.
Canvases do not support scaling or rotation of the canvas coordinate
system relative to the window coordinate system.
.PP
Individual items may be moved, scaled
Individual items may be moved or scaled using widget commands
.VS "8.7, TIP164"
or rotated
.VE "8.7, TIP164"
using widget commands
described below.
described below, but they may not be rotated.
.PP
Note that the default origin of the canvas's visible area is
coincident with the origin for the whole window as that makes bindings
using the mouse position easier to work with; you only need to use the
\fBcanvasx\fR and \fBcanvasy\fR widget commands if you adjust the
origin of the visible area. However, this also means that any focus
ring (as controlled by the \fB\-highlightthickness\fR option) and
252
253
254
255
256
257
258

259


260
261
262
263
264
265
266
267
268
269
270
271

272


273
274
275

276


277
278

279


280
281

282


283
284

285


286
287
288
289
290
291
292
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276

277
278
279
280
281

282
283
284
285
286

287
288
289
290
291

292
293
294
295
296
297
298
299
300







+
-
+
+












+
-
+
+



+
-
+
+


+
-
+
+


+
-
+
+


+
-
+
+







support as many of these forms as practical.
Note that it is possible to refer to the character just after
the last one in the text item; this is necessary for such
tasks as inserting new text at the end of the item.
Lines and Polygons do not support the insertion cursor
and the selection. Their indices are supposed to be even
always, because coordinates always appear in pairs.
.TP 10
.IP \fInumber\fR 10
\fInumber\fR
.
A decimal number giving the position of the desired character
within the text item.
0 refers to the first character, 1 to the next character, and
so on. If indexes are odd for lines and polygons, they will be
automatically decremented by one.
A number less than 0 is treated as if it were zero, and a
number greater than the length of the text item is treated
as if it were equal to the length of the text item. For
polygons, numbers less than 0 or greater than the length
of the coordinate list will be adjusted by adding or subtracting
the length until the result is between zero and the length,
inclusive.
.TP 10
.IP \fBend\fR 10
\fBend\fR
.
Refers to the character or coordinate just after the last one
in the item (same as the number of characters or coordinates
in the item).
.TP 10
.IP \fBinsert\fR 10
\fBinsert\fR
.
Refers to the character just before which the insertion cursor
is drawn in this item. Not valid for lines and polygons.
.TP 10
.IP \fBsel.first\fR 10
\fBsel.first\fR
.
Refers to the first selected character in the item.
If the selection is not in this item then this form is illegal.
.TP 10
.IP \fBsel.last\fR 10
\fBsel.last\fR
.
Refers to the last selected character in the item.
If the selection is not in this item then this form is illegal.
.TP 10
.IP \fB@\fIx,y\fR 10
\fB@\fIx,y\fR
.
Refers to the character or coordinate at the point given by \fIx\fR and
\fIy\fR, where \fIx\fR and \fIy\fR are specified in the coordinate
system of the canvas.
If \fIx\fR and \fIy\fR lie outside the coordinates covered by the
text item, then they refer to the first or last character in the
line that is closest to the given point.
.SH "DASH PATTERNS"
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
309
310
311
312
313
314
315

316
317
318
319
320
321
322







-







.PP
The second possible syntax is a character list containing only
5 possible characters
.QW "\fB.,-_ \fR" .
The space can be used
to enlarge the space between other line elements, and cannot
occur as the first position in the string. Some examples:
.PP
.CS
\-dash .     \(-> \-dash {2 4}
\-dash -     \(-> \-dash {6 4}
\-dash -.    \(-> \-dash {6 4 2 4}
\-dash -..   \(-> \-dash {6 4 2 4 2 4}
\-dash {. }  \(-> \-dash {2 8}
\-dash ,     \(-> \-dash {4 4}
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
358

359


360
361
362
363

364


365

366


367
368
369
370

371


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389


390
391
392
393

394


395
396
397
398
399

400


401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
339
340
341
342
343
344
345

346
347
348
349
350

351

352
353
354
355
356
357
358
359
360
361
362
363
364
365

366
367
368
369
370
371
372

373
374
375
376

377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410

411
412
413
414
415
416
417
418

419
420
421
422

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446







-
+




-

-
+












+
-
+
+




+
-
+
+

+
-
+
+




+
-
+
+

















+
-
+
+




+
-
+
+





+
-
+
+


-

















-







.SH "WIDGET COMMAND"
.PP
The \fBcanvas\fR command creates a new Tcl command whose
name is \fIpathName\fR. This
command may be used to invoke various
operations on the widget. It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.
The following widget commands are possible for canvas widgets:
.\" METHOD: addtag
.TP
\fIpathName \fBaddtag \fItag searchSpec \fR?\fIarg ...\fR?
\fIpathName \fBaddtag \fItag searchSpec \fR?\fIarg arg ...\fR?
.
For each item that meets the constraints specified by
\fIsearchSpec\fR and the \fIarg\fRs, add
\fItag\fR to the list of tags associated with the item if it
is not already present on that list.
It is possible that no items will satisfy the constraints
given by \fIsearchSpec\fR and \fIarg\fRs, in which case the
command has no effect.
This command returns an empty string as result.
\fISearchSpec\fR and \fIarg\fR's may take any of the following
forms:
.RS
.TP
.IP "\fBabove \fItagOrId\fR"
\fBabove \fItagOrId\fR
.
Selects the item just after (above) the one given by \fItagOrId\fR
in the display list.
If \fItagOrId\fR denotes more than one item, then the last (topmost)
of these items in the display list is used.
.TP
.IP \fBall\fR
\fBall\fR
.
Selects all the items in the canvas.
.TP
.IP "\fBbelow \fItagOrId\fR"
\fBbelow \fItagOrId\fR
.
Selects the item just before (below) the one given by \fItagOrId\fR
in the display list.
If \fItagOrId\fR denotes more than one item, then the first (lowest)
of these items in the display list is used.
.TP
.IP "\fBclosest \fIx y \fR?\fIhalo\fR? ?\fIstart\fR?"
\fBclosest \fIx y \fR?\fIhalo\fR? ?\fIstart\fR?
.
Selects the item closest to the point given by \fIx\fR and \fIy\fR.
If more than one item is at the same closest distance (e.g. two
items overlap the point), then the top-most of these items (the
last one in the display list) is used.
If \fIhalo\fR is specified, then it must be a non-negative
value.
Any item closer than \fIhalo\fR to the point is considered to
overlap it.
The \fIstart\fR argument may be used to step circularly through
all the closest items.
If \fIstart\fR is specified, it names an item using a tag or id
(if by tag, it selects the first item in the display list with
the given tag).
Instead of selecting the topmost closest item, this form will
select the topmost closest item that is below \fIstart\fR in
the display list; if no such item exists, then the selection
behaves as if the \fIstart\fR argument had not been specified.
.TP
.IP "\fBenclosed\fI x1 y1 x2 y2\fR"
\fBenclosed\fR \fIx1\fR \fIy1\fR \fIx2\fR \fIy2\fR
.
Selects all the items completely enclosed within the rectangular
region given by \fIx1\fR, \fIy1\fR, \fIx2\fR, and \fIy2\fR.
\fIX1\fR must be no greater than \fIx2\fR and \fIy1\fR must be
no greater than \fIy2\fR.
.TP
.IP "\fBoverlapping\fI x1 y1 x2 y2\fR"
\fBoverlapping\fR \fIx1\fR \fIy1\fR \fIx2\fR \fIy2\fR
.
Selects all the items that overlap or are enclosed within the
rectangular region given by \fIx1\fR, \fIy1\fR, \fIx2\fR,
and \fIy2\fR.
\fIX1\fR must be no greater than \fIx2\fR and \fIy1\fR must be
no greater than \fIy2\fR.
.TP
.IP "\fBwithtag \fItagOrId\fR"
\fBwithtag \fItagOrId\fR
.
Selects all the items given by \fItagOrId\fR.
.RE
.\" METHOD: bbox
.TP
\fIpathName \fBbbox \fItagOrId\fR ?\fItagOrId tagOrId ...\fR?
.
Returns a list with four elements giving an approximate bounding box
for all the items named by the \fItagOrId\fR arguments.
The list has the form
.QW "\fIx1 y1 x2 y2\fR"
such that the drawn
areas of all the named elements are within the region bounded by
\fIx1\fR on the left, \fIx2\fR on the right, \fIy1\fR on the top,
and \fIy2\fR on the bottom.
The return value may overestimate the actual bounding box by
a few pixels.
If no items match any of the \fItagOrId\fR arguments or if the
matching items have empty bounding boxes (i.e. they have nothing
to display)
then an empty string is returned.
.\" METHOD: bind
.TP
\fIpathName \fBbind \fItagOrId\fR ?\fIsequence\fR? ?\fIcommand\fR?
.
This command associates \fIcommand\fR with all the items given by
\fItagOrId\fR such that whenever the event sequence given by
\fIsequence\fR occurs for one of the items the command will
be invoked.
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457
461
462
463
464
465
466
467

468
469
470
471
472
473
474
475







-
+







If both \fIcommand\fR and \fIsequence\fR are omitted then the command
returns a list of all the sequences for which bindings have been
defined for \fItagOrId\fR.
.RS
.PP
The only events for which bindings may be specified are those related to
the mouse and keyboard (such as \fBEnter\fR, \fBLeave\fR,
\fBButton\fR, \fBMotion\fR, and \fBKey\fR) or virtual events.
\fBButtonPress\fR, \fBMotion\fR, and \fBKeyPress\fR) or virtual events.
The handling of events in canvases uses the current item defined in
\fBITEM IDS AND TAGS\fR above. \fBEnter\fR and \fBLeave\fR events
trigger for an
item when it becomes the current item or ceases to be the current item;
note that these events are different than \fBEnter\fR and \fBLeave\fR
events for windows. Mouse-related events are directed to the current
item, if any. Keyboard-related events are directed to the focus item, if
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
494
495
496
497
498
499
500

501
502
503
504
505
506
507

508
509
510
511
512
513
514

515

516
517
518
519
520
521

522
523
524
525
526
527
528
529
530
531
532
533
534
535
536

537

538
539

540
541
542
543
544
545
546
547
548
549










550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572
573
574

575
576
577
578
579

580
581
582
583
584
585
586
587
588
589

590

591
592
593
594
595
596
597
598

599
600
601
602
603
604
605







-







-







-

-
+





-















-

-
+

-
+









-
-
-
-
-
-
-
-
-
-













-












-





-










-

-
+







-







.PP
If bindings have been created for a canvas window using the \fBbind\fR
command, then they are invoked in addition to bindings created for
the canvas's items using the \fBbind\fR widget command.
The bindings for items will be invoked before any of the bindings
for the window as a whole.
.RE
.\" METHOD: canvasx
.TP
\fIpathName \fBcanvasx \fIscreenx\fR ?\fIgridspacing\fR?
.
Given a window x-coordinate in the canvas \fIscreenx\fR, this command returns
the canvas x-coordinate that is displayed at that location.
If \fIgridspacing\fR is specified, then the canvas coordinate is
rounded to the nearest multiple of \fIgridspacing\fR units.
.\" METHOD: canvasy
.TP
\fIpathName \fBcanvasy \fIscreeny\fR ?\fIgridspacing\fR?
.
Given a window y-coordinate in the canvas \fIscreeny\fR this command returns
the canvas y-coordinate that is displayed at that location.
If \fIgridspacing\fR is specified, then the canvas coordinate is
rounded to the nearest multiple of \fIgridspacing\fR units.
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBcanvas\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure ?\fIoption\fR? ?\fIvalue\fR? ?\fIoption value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list). If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified). If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s); in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBcanvas\fR
command.
.\" METHOD: coords
.TP
\fIpathName \fBcoords \fItagOrId \fR?\fIx0 y0 ...\fR?
\fIpathName\fR \fBcoords \fItagOrId \fR?\fIx0 y0 ...\fR?
.TP
\fIpathName \fBcoords \fItagOrId \fR?\fIcoordList\fR?
\fIpathName\fR \fBcoords \fItagOrId \fR?\fIcoordList\fR?
.
Query or modify the coordinates that define an item.
If no coordinates are specified, this command returns a list
whose elements are the coordinates of the item named by
\fItagOrId\fR.
If coordinates are specified, then they replace the current
coordinates for the named item.
If \fItagOrId\fR refers to multiple items, then
the first one in the display list is used.
.RS
.PP
Note that for rectangles, ovals and arcs the returned list of coordinates
has a fixed order, namely the left, top, right and bottom coordinates,
which may not be the order originally given. Also the coordinates are always
returned in screen units with no units (that is, in pixels). So if the
original coordinates were specified for instance in centimeters or inches,
the returned values will nevertheless be in pixels.
.RE
.\" METHOD: create
.TP
\fIpathName \fBcreate \fItype x y \fR?\fIx y ...\fR? ?\fIoption value ...\fR?
.TP
\fIpathName \fBcreate \fItype coordList \fR?\fIoption value ...\fR?
.
Create a new item in \fIpathName\fR of type \fItype\fR.
The exact format of the arguments after \fItype\fR depends
on \fItype\fR, but usually they consist of the coordinates for
one or more points, followed by specifications for zero or
more item options.
See the subsections on individual item types below for more
on the syntax of this command.
This command returns the id for the new item.
.\" METHOD: dchars
.TP
\fIpathName \fBdchars \fItagOrId first \fR?\fIlast\fR?
.
For each item given by \fItagOrId\fR, delete the characters, or coordinates,
in the range given by \fIfirst\fR and \fIlast\fR, inclusive.
If some of the items given by \fItagOrId\fR do not support
indexing operations then they ignore this operation.
Text items interpret \fIfirst\fR and \fIlast\fR as indices to a character,
line and polygon items interpret them as indices to a coordinate (an x,y pair).
Indices are described in \fBINDICES\fR above.
If \fIlast\fR is omitted, it defaults to \fIfirst\fR.
This command returns an empty string.
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fR?\fItagOrId tagOrId ...\fR?
.
Delete each of the items given by each \fItagOrId\fR, and return
an empty string.
.\" METHOD: dtag
.TP
\fIpathName \fBdtag \fItagOrId \fR?\fItagToDelete\fR?
.
For each of the items given by \fItagOrId\fR, delete the
tag given by \fItagToDelete\fR from the list of those
associated with the item.
If an item does not have the tag \fItagToDelete\fR then
the item is unaffected by the command.
If \fItagToDelete\fR is omitted then it defaults to \fItagOrId\fR.
This command returns an empty string.
.\" METHOD: find
.TP
\fIpathName \fBfind \fIsearchCommand \fR?\fIarg ...\fR?
\fIpathName \fBfind \fIsearchCommand \fR?\fIarg arg ...\fR?
.
This command returns a list consisting of all the items that
meet the constraints specified by \fIsearchCommand\fR and
\fIarg\fR's.
\fISearchCommand\fR and \fIargs\fR have any of the forms
accepted by the \fBaddtag\fR command.
The items are returned in stacking order, with the lowest item first.
.\" METHOD: focus
.TP
\fIpathName \fBfocus \fR?\fItagOrId\fR?
.
Set the keyboard focus for the canvas widget to the item given by
\fItagOrId\fR.
If \fItagOrId\fR refers to several items, then the focus is set
to the first such item in the display list that supports the
623
624
625
626
627
628
629
630
631
632

633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683

684
685
686
687
688
689

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
621
622
623
624
625
626
627

628

629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645



646
647
648
649

650


651





















652

653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681
682
683


684
685

686


687

688
689
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704







-

-
+







-









-
-
-
+



-

-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+





-
+














-










-
-


-

-
-

-
+









-







a given item does not actually have the input focus unless (a)
its canvas is the focus window and (b) the item is the focus item
within the canvas.
In most cases it is advisable to follow the \fBfocus\fR widget
command with the \fBfocus\fR command to set the focus window to
the canvas (if it was not there already).
.RE
.\" METHOD: gettags
.TP
\fIpathName \fBgettags\fI tagOrId\fR
\fIpathName \fBgettags\fR \fItagOrId\fR
.
Return a list whose elements are the tags associated with the
item given by \fItagOrId\fR.
If \fItagOrId\fR refers to more than one item, then the tags
are returned from the first such item in the display list.
If \fItagOrId\fR does not refer to any items, or if the item
contains no tags, then an empty string is returned.
.\" METHOD: icursor
.TP
\fIpathName \fBicursor \fItagOrId index\fR
.
Set the position of the insertion cursor for the item(s) given by \fItagOrId\fR
to just before the character whose position is given by \fIindex\fR.
If some or all of the items given by \fItagOrId\fR do not support
an insertion cursor then this command has no effect on them.
See \fBINDICES\fR above for a description of the
legal forms for \fIindex\fR.
.RS
.PP
Note that the insertion cursor is only displayed in an item if
Note: the insertion cursor is only displayed in an item if
that item currently has the keyboard focus (see the \fBfocus\fR widget
command, above), but the cursor position may
be set even when the item does not have the focus.
.PP
This command returns an empty string.
.RE
.\" METHOD: image
.TP
\fIpathName \fBimage \fIimagename\fR ?\fIsubsample\fR? ?\fIzoom\fR?
.
Draw the canvas into the Tk photo image named \fIimagename\fR.
If a \fB\-scrollregion\fR has been defined then this will be the boundaries
of the canvas region drawn and the final size of the photo image. Otherwise
the widget width and height with an origin of 0,0 will be the size of the
canvas region drawn and the final size of the photo image. Optionally an
integer \fIsubsample\fR factor may be given and the photo image
will be reduced in size.
.RS
.PP
In addition to the \fIsubsample\fR an integer \fIzoom\fR factor can also
be given and the photo image will be enlarged. The image background will
be filled with the canvas background colour. The canvas widget does not
need to be mapped for this widget command to work, but at least one of
it's ancestors must be mapped.
.PP
This command returns an empty string.
.RE
.\" METHOD: imove
.TP
\fIpathName \fBimove \fItagOrId index x y\fR
.
.VS 8.6
This command causes the \fIindex\fR'th coordinate of each of the items
indicated by \fItagOrId\fR to be relocated to the location (\fIx\fR,\fIy\fR).
Each item interprets \fIindex\fR independently according to the rules
described in \fBINDICES\fR above. Out of the standard set of items, only line
and polygon items may have their coordinates relocated this way.
.\" METHOD: index
.VE 8.6
.TP
\fIpathName \fBindex \fItagOrId index\fR
.
This command returns a decimal string giving the numerical index
within \fItagOrId\fR corresponding to \fIindex\fR.
\fIIndex\fR gives a textual description of the desired position
as described in \fBINDICES\fR above.
Text items interpret \fIindex\fR as an index to a character,
line and polygon items interpret it as an index to a coordinate (an x,y pair).
The return value is guaranteed to lie between 0 and the number
of characters, or coordinates, within the item, inclusive.
If \fItagOrId\fR refers to multiple items, then the index
is processed in the first of these items that supports indexing
operations (in display list order).
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fItagOrId beforeThis string\fR
.
For each of the items given by \fItagOrId\fR, if the item supports
text or coordinate, insertion then \fIstring\fR is inserted into the item's
text just before the character, or coordinate, whose index is \fIbeforeThis\fR.
Text items interpret \fIbeforeThis\fR as an index to a character,
line and polygon items interpret it as an index to a coordinate (an x,y pair).
For lines and polygons the \fIstring\fR must be a valid coordinate
sequence.
.RS
.PP
See \fBINDICES\fR above for information about the forms allowed
for \fIbeforeThis\fR.
.PP
This command returns an empty string.
.RE
.\" METHOD: itemcget
.TP
\fIpathName \fBitemcget\fI tagOrId option\fR
\fIpathName \fBitemcget\fR \fItagOrId\fR \fIoption\fR
.
Returns the current value of the configuration option for the
item given by \fItagOrId\fR whose name is \fIoption\fR.
This command is similar to the \fBcget\fR widget command except that
it applies to a particular item rather than the widget as a whole.
\fIOption\fR may have any of the values accepted by the \fBcreate\fR
widget command when the item was created.
If \fItagOrId\fR is a tag that refers to more than one item,
the first (lowest) such item is used.
.\" METHOD: itemconfigure
.TP
\fIpathName \fBitemconfigure \fItagOrId\fR ?\fIoption\fR? ?\fIvalue\fR? ?\fIoption value ...\fR?
.
This command is similar to the \fBconfigure\fR widget command except
that it modifies item-specific options for the items given by
\fItagOrId\fR instead of modifying options for the overall
canvas widget.
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

786
787

788
789
790
791
792
793
794
795

796
797
798
799
800
801
802
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
728
729

730
731
732
733
734

735
736
737
738
739
740
741
742

743
744

745
746

747

748
749
750
751
752
753

754
755
756
757
758
759
760
761







-










-
+




-








-


-
+

-
+
-






-
+







modifies the given widget option(s) to have the given value(s) in
each of the items given by \fItagOrId\fR; in
this case the command returns an empty string.
The \fIoption\fRs and \fIvalue\fRs are the same as those permissible
in the \fBcreate\fR widget command when the item(s) were created;
see the sections describing individual item types below for details
on the legal options.
.\" METHOD: lower
.TP
\fIpathName \fBlower \fItagOrId \fR?\fIbelowThis\fR?
.
Move all of the items given by \fItagOrId\fR to a new position
in the display list just before the item given by \fIbelowThis\fR.
If \fItagOrId\fR refers to more than one item then all are moved
but the relative order of the moved items will not be changed.
\fIBelowThis\fR is a tag or id; if it refers to more than one
item then the first (lowest) of these items in the display list is used
as the destination location for the moved items.
Note that this command has no effect on window items. Window items always
Note: this command has no effect on window items. Window items always
obscure other item types, and the stacking order of window items is
determined by the \fBraise\fR command and \fBlower\fR command, not the
\fBraise\fR widget command and \fBlower\fR widget command for canvases.
This command returns an empty string.
.\" METHOD: move
.TP
\fIpathName \fBmove \fItagOrId xAmount yAmount\fR
.
Move each of the items given by \fItagOrId\fR in the canvas coordinate
space by adding \fIxAmount\fR to the x-coordinate of each point
associated with the item and \fIyAmount\fR to the y-coordinate of
each point associated with the item.
This command returns an empty string.
.\" METHOD: moveto
.TP
\fIpathName \fBmoveto \fItagOrId xPos yPos\fR
.
.VS 8.6
Move the items given by \fItagOrId\fR in the canvas coordinate
space so that the first coordinate pair (the upper-left corner of the
space so that the first coordinate pair of the bottommost item with
bounding box) of the first item (the lowest in the display list) with
tag \fItagOrId\fR is located at
position (\fIxPos\fR,\fIyPos\fR). \fIxPos\fR and \fIyPos\fR may be
the empty string, in which case the corresponding coordinate
will be unchanged. All items matching
\fItagOrId\fR remain in the same positions relative to each other.
This command returns an empty string.
.\" METHOD: postscript
.VE 8.6
.TP
\fIpathName \fBpostscript \fR?\fIoption value option value ...\fR?
.
Generate a Postscript representation for part or all of the canvas.
If the \fB\-file\fR option is specified then the Postscript is written
to a file and an empty string is returned; otherwise the Postscript
is returned as the result of the command.
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
1045
774
775
776
777
778
779
780

781
782
783
784
785
786
787

788
789
790
791
792
793
794
795
796
797
798
799
800


801
802
803


804
805
806
807
808
809
810

811
812
813
814
815
816
817

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833


834
835
836


837
838
839
840
841

842
843
844
845
846
847


848
849
850


851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899

900
901
902
903
904

905
906
907
908
909
910
911

912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
927
928
929
930
931
932

933
934
935
936
937

938
939

940
941
942
943
944
945
946
947
948






















949

950
951
952
953
954
955
956







-







-













-
-



-
-







-







-
















-
-



-
-





-






-
-



-
-












-










-








-








-











-





-







-








-













-
+




-


-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-







either invoke the \fBupdate\fR command to wait for the canvas window
to reach its final size, or else use the \fB\-width\fR and \fB\-height\fR
options to specify the area of the canvas to print.
The \fIoption\fR\-\fIvalue\fR argument pairs provide additional
information to control the generation of Postscript. The following
options are supported:
.RS
.\" OPTION: -channel
.TP
\fB\-channel \fIchannelName\fR
.
Specifies the name of the channel to which to write the Postscript.
If this option and the \fB\-file\fR option are
not specified then the Postscript is returned as the
result of the command.
.\" OPTION: -colormap
.TP
\fB\-colormap \fIvarName\fR
.
\fIVarName\fR must be the name of an array variable
that specifies a color mapping to use in the Postscript.
Each element of \fIvarName\fR must consist of Postscript
code to set a particular color value (e.g.
.QW "\fB1.0 1.0 0.0 setrgbcolor\fR" ).
When outputting color information in the Postscript, Tk checks
to see if there is an element of \fIvarName\fR with the same
name as the color.
If so, Tk uses the value of the element as the Postscript command
to set the color.
.RS
.PP
If this option has not been specified, or if there is no entry
in \fIvarName\fR for a given color, then Tk uses the red, green,
and blue intensities from the X color.
.RE
.\" OPTION: -colormode
.TP
\fB\-colormode \fImode\fR
.
Specifies how to output color information. \fIMode\fR must be either
\fBcolor\fR (for full color output), \fBgray\fR (convert all colors
to their gray-scale equivalents) or \fBmono\fR (convert all colors
to black or white).
.\" OPTION: -file
.TP
\fB\-file \fIfileName\fR
.
Specifies the name of the file in which to write the Postscript.
If this option and the \fB\-channel\fR option are
not specified then the Postscript is returned as the
result of the command.
.\" OPTION: -fontmap
.TP
\fB\-fontmap \fIvarName\fR
.
\fIVarName\fR must be the name of an array variable
that specifies a font mapping to use in the Postscript.
Each element of \fIvarName\fR must consist of a Tcl list with
two elements, which are the name and point size of a Postscript font.
When outputting Postscript commands for a particular font, Tk
checks to see if \fIvarName\fR contains an element with the same
name as the font.
If there is such an element, then the font information contained in
that element is used in the Postscript.
Otherwise Tk attempts to guess what Postscript font to use.
Tk's guesses generally only work for well-known fonts such as
Times and Helvetica and Courier, and only if the X font name does not
omit any dashes up through the point size.
.RS
.PP
For example, \fB\-*\-Courier\-Bold\-R\-Normal\-\-*\-120\-*\fR will work but
\fB*Courier\-Bold\-R\-Normal*120*\fR will not; Tk needs the dashes to
parse the font name).
.RE
.\" OPTION: -height
.TP
\fB\-height \fIsize\fR
.
Specifies the height of the area of the canvas to print.
Defaults to the height of the canvas window.
.\" OPTION: -pageanchor
.TP
\fB\-pageanchor \fIanchor\fR
.
Specifies which point of the printed area of the canvas should appear over
the positioning point on the page (which is given by the \fB\-pagex\fR
and \fB\-pagey\fR options).
.RS
.PP
For example, \fB\-pageanchor n\fR means that the top center of the
area of the canvas being printed (as it appears in the canvas window)
should be over the positioning point. Defaults to \fBcenter\fR.
.RE
.\" OPTION: -pageheight
.TP
\fB\-pageheight \fIsize\fR
.
Specifies that the Postscript should be scaled in both x and y so
that the printed area is \fIsize\fR high on the Postscript page.
\fISize\fR consists of a floating-point number followed by
\fBc\fR for centimeters, \fBi\fR for inches, \fBm\fR for millimeters,
or \fBp\fR or nothing for printer's points (1/72 inch).
Defaults to the height of the printed area on the screen.
If both \fB\-pageheight\fR and \fB\-pagewidth\fR are specified then
the scale factor from \fB\-pagewidth\fR is used (non-uniform scaling
is not implemented).
.\" OPTION: -pagewidth
.TP
\fB\-pagewidth \fIsize\fR
.
Specifies that the Postscript should be scaled in both x and y so
that the printed area is \fIsize\fR wide on the Postscript page.
\fISize\fR has the same form as for \fB\-pageheight\fR.
Defaults to the width of the printed area on the screen.
If both \fB\-pageheight\fR and \fB\-pagewidth\fR are specified then
the scale factor from \fB\-pagewidth\fR is used (non-uniform scaling
is not implemented).
.\" OPTION: -pagex
.TP
\fB\-pagex \fIposition\fR
.
\fIPosition\fR gives the x-coordinate of the positioning point on
the Postscript page, using any of the forms allowed for \fB\-pageheight\fR.
Used in conjunction with the \fB\-pagey\fR and \fB\-pageanchor\fR options
to determine where the printed area appears on the Postscript page.
Defaults to the center of the page.
.\" OPTION: -pagey
.TP
\fB\-pagey \fIposition\fR
.
\fIPosition\fR gives the y-coordinate of the positioning point on
the Postscript page, using any of the forms allowed for \fB\-pageheight\fR.
Used in conjunction with the \fB\-pagex\fR and \fB\-pageanchor\fR options
to determine where the printed area appears on the Postscript page.
Defaults to the center of the page.
.\" OPTION: -rotate
.TP
\fB\-rotate \fIboolean\fR
.
\fIBoolean\fR specifies whether the printed area is to be rotated 90
degrees.
In non-rotated output the x-axis of the printed area runs along
the short dimension of the page
.PQ portrait " orientation" ;
in rotated output the x-axis runs along the long dimension of the page
.PQ landscape " orientation" .
Defaults to non-rotated.
.\" OPTION: -width
.TP
\fB\-width \fIsize\fR
.
Specifies the width of the area of the canvas to print.
Defaults to the width of the canvas window.
.\" OPTION: -x
.TP
\fB\-x \fIposition\fR
.
Specifies the x-coordinate of the left edge of the area of the
canvas that is to be printed, in canvas coordinates, not window
coordinates.
Defaults to the coordinate of the left edge of the window.
.\" OPTION: -y
.TP
\fB\-y \fIposition\fR
.
Specifies the y-coordinate of the top edge of the area of the
canvas that is to be printed, in canvas coordinates, not window
coordinates.
Defaults to the coordinate of the top edge of the window.
.RE
.\" METHOD: raise
.TP
\fIpathName \fBraise \fItagOrId \fR?\fIaboveThis\fR?
.
Move all of the items given by \fItagOrId\fR to a new position
in the display list just after the item given by \fIaboveThis\fR.
If \fItagOrId\fR refers to more than one item then all are moved
but the relative order of the moved items will not be changed.
\fIAboveThis\fR is a tag or id; if it refers to more than one
item then the last (topmost) of these items in the display list is used
as the destination location for the moved items.
This command returns an empty string.
.RS
.PP
Note this this command has no effect on window items. Window items always
Note: this command has no effect on window items. Window items always
obscure other item types, and the stacking order of window items is
determined by the \fBraise\fR command and \fBlower\fR command, not the
\fBraise\fR widget command and \fBlower\fR widget command for canvases.
.RE
.\" METHOD: rchars
.TP
\fIpathName \fBrchars \fItagOrId first last string\fR
.
.VS 8.6
This command causes the text or coordinates between \fIfirst\fR and \fIlast\fR
for each of the items indicated by \fItagOrId\fR to be replaced by
\fIstring\fR. Each item interprets \fIfirst\fR and \fIlast\fR independently
according to the rules described in \fBINDICES\fR above. Out of the standard
set of items, text items support this operation by altering their text as
directed, and line and polygon items support this operation by altering their
coordinate list (in which case \fIstring\fR should be a list of coordinates to
use as a replacement). The other items ignore this operation.
.\" METHOD: rotate
.TP
\fIpathName \fBrotate \fItagOrId xOrigin yOrigin angle\fR
.VS "8.7, TIP164"
Rotate the coordinates of all of the items given by \fItagOrId\fR in canvas
coordinate space.
\fIXOrigin\fR and \fIyOrigin\fR identify the origin for the rotation
operation and \fIangle\fR identifies the amount to rotate the coordinates
anticlockwise, in degrees. (Negative values rotate clockwise.)
This command returns an empty string.
.RS
.PP
Implementation note: not all item types work the same with rotations. In
particular,\fB bitmap\fR,\fB image\fR,\fB text\fR and\fB window\fR items only
rotate their anchor points and do not rotate the items themselves about those
points, and the \fBarc\fR, \fBoval\fR and \fBrectangle\fR types rotate about a
computed center point instead of moving the bounding box coordinates directly.
.PP
Some items (currently \fBarc\fR and\fB text\fR) have angles in their options;
this command \fIdoes not\fR affect those options.
.RE
.VE "8.7, TIP164"
.VE 8.6
.\" METHOD: scale
.TP
\fIpathName \fBscale \fItagOrId xOrigin yOrigin xScale yScale\fR
.
Rescale the coordinates of all of the items given by \fItagOrId\fR in canvas
coordinate space.
\fIXOrigin\fR and \fIyOrigin\fR identify the origin for the scaling
operation and \fIxScale\fR and \fIyScale\fR identify the scale
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
964
965
966
967
968
969
970

971

972
973
974
975
976
977
978
979







-

-
+







This command returns an empty string.
.RS
.PP
Note that some items have only a single pair of coordinates (e.g., text,
images and windows) and so scaling of them by this command can only move them
around.
.RE
.\" METHOD: scan
.TP
\fIpathName \fBscan\fI option args\fR
\fIpathName \fBscan\fR \fIoption args\fR
.
This command is used to implement scanning on canvases. It has
two forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBscan mark \fIx y\fR
.
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004







-







It then adjusts the view by \fIgain\fR times the
difference in coordinates, where \fIgain\fR defaults to 10.
This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the canvas at high speed through its window. The return
value is an empty string.
.RE
.\" METHOD: select
.TP
\fIpathName \fBselect \fIoption\fR ?\fItagOrId arg\fR?
.
Manipulates the selection in one of several ways, depending on
\fIoption\fR.
The command may take any of the forms described below.
In all of the descriptions below, \fItagOrId\fR must refer to
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072

1073
1074
1075
1076
1077
1078
1079







-









-







The anchor point is determined by the most recent \fBselect adjust\fR
or \fBselect from\fR command for this widget.
If the selection anchor point for the widget is not currently in
\fItagOrId\fR, then it is set to the same character given
by \fIindex\fR.
Returns an empty string.
.RE
.\" METHOD: type
.TP
\fIpathName \fBtype\fI tagOrId\fR
.
Returns the type of the item given by \fItagOrId\fR, such as
\fBrectangle\fR or \fBtext\fR.
If \fItagOrId\fR refers to more than one item, then the type
of the first item in the display list is returned.
If \fItagOrId\fR does not refer to any items at all then
an empty string is returned.
.\" METHOD: xview
.TP
\fIpathName \fBxview \fR?\fIargs\fR?
.
This command is used to query and change the horizontal position of the
information displayed in the canvas's window.
It can take any of the following forms:
.RS
1189
1190
1191
1192
1193
1194
1195
1196

1197
1198

1199



1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1096
1097
1098
1099
1100
1101
1102

1103


1104
1105
1106
1107
1108
1109
1110
1111
1112
1113



1114

1115

1116
1117
1118
1119
1120
1121
1122
1123







-
+
-
-
+

+
+
+





-
-
-

-

-
+







total width of the canvas is off-screen to the left.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right in units
of the \fBxScrollIncrement\fR option, if it is greater than zero,
or in units of one-tenth the window's width otherwise.
If \fIwhat is \fBpages\fR then the view
adjusts in units of nine-tenths the window's width.
If \fInumber\fR is negative then information farther to the left
becomes visible; if it is positive then information farther to the right
becomes visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right in units
of the \fBxScrollIncrement\fR option, if it is greater than zero,
or in units of one-tenth the window's width otherwise.
.RE
.\" METHOD: yview
.TP
\fIpathName \fByview ?\fIargs\fR?
\fIpathName \fByview \fI?args\fR?
.
This command is used to query and change the vertical position of the
information displayed in the canvas's window.
It can take any of the following forms:
.RS
.TP
\fIpathName \fByview\fR
1232
1233
1234
1235
1236
1237
1238
1239

1240
1241




1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315


1316
1317


1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336


1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362

1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439


1440
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457
1137
1138
1139
1140
1141
1142
1143

1144


1145
1146
1147
1148
1149
1150
1151
1152
1153



1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181
1182
1183

1184
1185

1186
1187

1188
1189
1190

1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202

1203
1204

1205
1206

1207
1208
1209


1210
1211

1212
1213
1214
1215
1216



1217
1218

1219
1220

1221
1222
1223

1224
1225
1226


1227
1228

1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244

1245
1246

1247
1248
1249

1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265
1266

1267
1268

1269
1270

1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290

1291
1292
1293
1294
1295
1296

1297
1298

1299
1300

1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316


1317
1318

1319
1320
1321
1322
1323
1324
1325

1326


1327
1328
1329
1330
1331
1332
1333







-
+
-
-
+
+
+
+





-
-
-




















-










-


-


-



-
+




-







-


-


-



-
-
+
+
-

+
+


-
-
-


-


-



-
+


-
-
+
+
-














-


-


-



-
+










-






-


-


-



-
+










-






-






-


-


-



-
+












-
-
+
+
-







-
+
-
-







area is off-screen to the top.
\fIFraction\fR is a fraction between 0 and 1.
.TP
\fIpathName \fByview scroll \fInumber what\fR
.
This command adjusts the view in the window up or down according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR.
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR.
If \fIwhat\fR is \fBunits\fR, the view adjusts up or down in units
of the \fByScrollIncrement\fR option, if it is greater than zero,
or in units of one-tenth the window's height otherwise.
If \fIwhat\fR is \fBpages\fR then
the view adjusts in units of nine-tenths the window's height.
If \fInumber\fR is negative then higher information becomes
visible; if it is positive then lower information
becomes visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts up or down in units
of the \fByScrollIncrement\fR option, if it is greater than zero,
or in units of one-tenth the window's height otherwise.
.RE
.SH "OVERVIEW OF ITEM TYPES"
.PP
The sections below describe the various types of items supported
by canvas widgets. Each item type is characterized by two things:
first, the form of the \fBcreate\fR command used to create
instances of the type; and second, a set of configuration options
for items of that type, which may be used in the
\fBcreate\fR and \fBitemconfigure\fR widget commands.
Most items do not support indexing or selection or the commands
related to them, such as \fBindex\fR and \fBinsert\fR.
Where items do support these facilities, it is noted explicitly
in the descriptions below.
At present, text, line and polygon items provide this support.
For lines and polygons the indexing facility is used to manipulate
the coordinates of the item.
.SS "COMMON ITEM OPTIONS"
.PP
Many items share a common set of options. These options are
explained here, and then referred to be each widget type for brevity.
.\" OPTION: -anchor
.TP
\fB\-anchor \fIanchorPos\fR
.
\fIAnchorPos\fR tells how to position the item relative to the
positioning point for the item; it may have any of the forms
accepted by \fBTk_GetAnchor\fR. For example, if \fIanchorPos\fR
is \fBcenter\fR then the item is centered on the point; if
\fIanchorPos\fR is \fBn\fR then the item will be drawn so that
its top center point is at the positioning point.
This option defaults to \fBcenter\fR.
.\" OPTION: -dash
.TP
\fB\-dash \fIpattern\fR
.\" OPTION: -activedash
.TP
\fB\-activedash \fIpattern\fR
.\" OPTION: -disableddash
.TP
\fB\-disableddash \fIpattern\fR
.
These options specify dash patterns for the normal, active
This option specifies dash patterns for the normal, active
state, and disabled state of an item.
\fIpattern\fR may have any of the forms accepted by \fBTk_GetDash\fR.
If the dash options are omitted then the default is a solid outline.
See \fBDASH PATTERNS\fR for more information.
.\" OPTION: -dashoffset
.TP
\fB\-dashoffset \fIoffset\fR
.
The starting \fIoffset\fR in pixels into the pattern provided by the
\fB\-dash\fR option. \fB\-dashoffset\fR is ignored if there is no
\fB\-dash\fR pattern. The \fIoffset\fR may have any of the forms described
in the \fBCOORDINATES\fR section above.
.\" OPTION: -fill
.TP
\fB\-fill \fIcolor\fR
.\" OPTION: -activefill
.TP
\fB\-activefill \fIcolor\fR
.\" OPTION: -disabledfill
.TP
\fB\-disabledfill \fIcolor\fR
.
These options specify the color to be used to fill item's area.
in its normal, active, and disabled states.
Specifies the color to be used to fill item's area.
in its normal, active, and disabled states,
The even-odd fill rule is used.
\fIColor\fR may have any of the forms accepted by \fBTk_GetColor\fR.
If \fIcolor\fR is an empty string (the default),
then the item will not be filled.
For the line item, it specifies the color of the line drawn.
For the text item, it specifies the foreground color of the text.
If \fIcolor\fR is an empty string (the default for all canvas items
except line and text), then the item will not be filled.
.\" OPTION: -outline
.TP
\fB\-outline \fIcolor\fR
.\" OPTION: -activeoutline
.TP
\fB\-activeoutline \fIcolor\fR
.\" OPTION: -disabledoutline
.TP
\fB\-disabledoutline \fIcolor\fR
.
These options specify the color that should be used to draw the
This option specifies the color that should be used to draw the
outline of the item in its normal, active and disabled states.
\fIColor\fR may have any of the forms accepted by \fBTk_GetColor\fR.
If \fIcolor\fR is specified as an empty string then no outline is drawn
for the item.
This option defaults to \fBblack\fR. If \fIcolor\fR is specified
as an empty string then no outline is drawn for the item.
.\" OPTION: -offset
.TP
\fB\-offset \fIoffset\fR
.
Specifies the offset of stipples. The offset value can be of the form
\fBx,y\fR or \fIside\fR, where side can be \fBn\fR, \fBne\fR, \fBe\fR,
\fBse\fR, \fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, or \fBcenter\fR. In the
first case the origin is the origin of the toplevel of the current window.
For the canvas itself and canvas objects the origin is the canvas origin,
but putting \fB#\fR in front of the coordinate pair indicates using the
toplevel origin instead. For canvas objects, the \fB\-offset\fR option is
used for stippling as well. For the line and polygon canvas items you can
also specify an index as argument, which connects the stipple origin to one
of the coordinate points of the line/polygon. Note that stipple offsets are
\fIonly supported on X11\fR; they are silently ignored on other platforms.
.\" OPTION: -outlinestipple
.TP
\fB\-outlinestipple \fIbitmap\fR
.\" OPTION: -activeoutlinestipple
.TP
\fB\-activeoutlinestipple \fIbitmap\fR
.\" OPTION: -disabledoutlinestipple
.TP
\fB\-disabledoutlinestipple \fIbitmap\fR
.
These options specify stipple patterns that should be used to draw the
This option specifies stipple patterns that should be used to draw the
outline of the item in its normal, active and disabled states.
Indicates that the outline for the item should be drawn with a stipple pattern;
\fIbitmap\fR specifies the stipple pattern to use, in any of the
forms accepted by \fBTk_GetBitmap\fR.
If the \fB\-outline\fR option has not been specified then this option
has no effect.
If \fIbitmap\fR is an empty string (the default), then the outline is drawn
in a solid fashion.
\fINote that stipples are not well supported on platforms that do not
use X11 as their drawing API.\fR
.\" OPTION: -outlineoffset
.TP
\fB\-outlineoffset \fIoffset\fR
.
Specifies the offset of the stipple pattern used for outlines, in the same way
that the \fB\-outline\fR option controls fill stipples. (See the
\fB\-outline\fR option for a description of the syntax of \fIoffset\fR.)
.\" OPTION: -stipple
.TP
\fB\-stipple \fIbitmap\fR
.\" OPTION: -activestipple
.TP
\fB\-activestipple \fIbitmap\fR
.\" OPTION: -disabledstipple
.TP
\fB\-disabledstipple \fIbitmap\fR
.
These options specify stipple patterns that should be used to fill
This option specifies stipple patterns that should be used to fill
the item in its normal, active and disabled states.
\fIbitmap\fR specifies the stipple pattern to use, in any of the
forms accepted by \fBTk_GetBitmap\fR.
If the \fB\-fill\fR option has not been specified then this option
has no effect.
If \fIbitmap\fR is an empty string (the default), then filling is done
in a solid fashion.
For the text item, it affects the actual text.
\fINote that stipples are not well supported on platforms that do not
use X11 as their drawing API.\fR
.\" OPTION: -state
.TP
\fB\-state \fIstate\fR
.
This allows an item to override the canvas widget's global \fIstate\fR
option. It takes the same values:
\fInormal\fR, \fIdisabled\fR or \fIhidden\fR.
.\" OPTION: -tags
.TP
\fB\-tags \fItagList\fR
.
Specifies a set of tags to apply to the item.
\fITagList\fR consists of a list of tag names, which replace any
existing tags for the item. \fITagList\fR may be an empty list.
.\" OPTION: -width
.TP
\fB\-width \fIoutlineWidth\fR
.\" OPTION: -activewidth
.TP
\fB\-activewidth \fIoutlineWidth\fR
.\" OPTION: -disabledwidth
.TP
\fB\-disabledwidth \fIoutlineWidth\fR
.
These options specify the width of the outline to be drawn around
Specifies the width of the outline to be drawn around
the item's region, in its normal, active and disabled states.
\fIoutlineWidth\fR may be in any of the forms described in the
\fBCOORDINATES\fR section above.
If the \fB\-outline\fR option has been specified as an empty string then
this option has no effect. This option defaults to 1.0.
For arcs, wide outlines will be drawn centered on the edges of the
arc's region.
.SH "STANDARD ITEM TYPES"
.SS "ARC ITEMS"
.PP
Items of type \fBarc\fR appear on the display as arc-shaped regions.
An arc is a section of an oval delimited by two angles (specified
by either the \fB\-start\fR and \fB\-extent\fR options or the \fB\-height\fR
option) and displayed in one of several ways (specified by the \fB\-style\fR
by the \fB\-start\fR and \fB\-extent\fR options) and displayed in
one of several ways (specified by the \fB\-style\fR option).
option).
Arcs are created with widget commands of the following form:
.CS
\fIpathName \fBcreate arc \fIx1 y1 x2 y2 \fR?\fIoption value ...\fR?
\fIpathName \fBcreate arc \fIcoordList\fR ?\fIoption value ...\fR?
.CE
The arguments \fIx1\fR, \fIy1\fR, \fIx2\fR, and \fIy2\fR or \fIcoordList\fR give
the coordinates of two diagonally opposite corners of a
rectangular region enclosing the oval that defines the arc (except when
rectangular region enclosing the oval that defines the arc.
\fB\-height\fR is specified - see below).
.
After the coordinates there may be any number of \fIoption\fR\-\fIvalue\fR
pairs, each of which sets one of the configuration options
for the item. These same \fIoption\fR\-\fIvalue\fR pairs may be
used in \fBitemconfigure\fR widget commands to change the item's
configuration. An arc item becomes the current item when the mouse pointer is
over any part that is painted or (when fully transparent) that would be
painted if both the \fB\-fill\fR and \fB\-outline\fR options were non-empty.
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1345
1346
1347
1348
1349
1350
1351

1352
1353

1354
1355
1356
1357
1358
1359

1360
1361

1362
1363
1364
1365

1366






























1367

1368
1369
1370
1371
1372
1373
1374







-


-






-


-




-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-







\fB\-disabledoutlinestipple\fR	\fB\-stipple\fR
\fB\-activestipple\fR	\fB\-disabledstipple\fR
\fB\-state\fR	\fB\-tags\fR
\fB\-width\fR	\fB\-activewidth\fR
\fB\-disabledwidth\fR
.DE
The following extra options are supported for arcs:
.\" OPTION: -extent
.TP
\fB\-extent \fIdegrees\fR
.
Specifies the size of the angular range occupied by the arc.
The arc's range extends for \fIdegrees\fR degrees counter-clockwise
from the starting angle given by the \fB\-start\fR option.
\fIDegrees\fR may be negative.
If it is greater than 360 or less than \-360, then \fIdegrees\fR
modulo 360 is used as the extent.
.\" OPTION: -start
.TP
\fB\-start \fIdegrees\fR
.
Specifies the beginning of the angular range occupied by the
arc.
\fIDegrees\fR is given in units of degrees measured counter-clockwise
from the 3-o'clock position; it may be either positive or negative.
.\" OPTION: -height
.TP
\fB\-height \fIdistance\fR
.
Provides a shortcut for creating a circular arc segment by defining the
distance of the mid-point of the arc from its chord. When this option
is used the coordinates are interpreted as the start and end coordinates
of the chord, and the options \fB\-start\fR and \fB\-extent\fR are ignored.
The value of \fIdistance\fR has the following meaning:
.RS
.PP
.RS
\fIdistance\fR > 0 creates a clockwise arc
.br
\fIdistance\fR < 0 creates an counter-clockwise arc
.br
\fIdistance\fR = 0 creates an arc as if this option had not been specified
.RE
.PP
If you want the arc to have a specific radius, \fIr\fR, use the formula:
.PP
.RS
\fIdistance\fR = \fIr\fR \(+- sqrt(\fIr\fR**2 - (chordLength / 2)**2)
.RE
.PP
choosing the minus sign for the minor arc and the plus sign for the major arc.
.PP
Note that \fBitemcget \-height\fR always returns 0 so that introspection code
can be kept simple.
.RE
.\" OPTION: -style
.TP
\fB\-style \fItype\fR
.
Specifies how to draw the arc. If \fItype\fR is \fBpieslice\fR
(the default) then the arc's region is defined by a section
of the oval's perimeter plus two line segments, one between the center
of the oval and each end of the perimeter section.
If \fItype\fR is \fBchord\fR then the arc's region is defined
by a section of the oval's perimeter plus a single line segment
connecting the two end points of the perimeter section.
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593


1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605

1606
1607
1608


1609
1610
1611
1612
1613
1614
1615
1398
1399
1400
1401
1402
1403
1404

1405
1406

1407
1408

1409
1410

1411
1412
1413
1414
1415
1416
1417

1418
1419

1420
1421

1422
1423



1424
1425
1426

1427
1428

1429
1430

1431
1432


1433
1434
1435

1436
1437
1438
1439
1440
1441
1442
1443
1444







-


-


-


-







-


-


-


-
-
-
+
+

-


-


-


-
-
+


-
+
+







The following standard options are supported by bitmaps:
.DS
.ta 3i
\fB\-anchor\fR	\fB\-state\fR
\fB\-tags\fR
.DE
The following extra options are supported for bitmaps:
.\" OPTION: -background
.TP
\fB\-background \fIcolor\fR
.\" OPTION: -activebackground
.TP
\fB\-activebackground \fIcolor\fR
.\" OPTION: -disabledbackground
.TP
\fB\-disabledbackground \fIcolor\fR
.
Specifies the color to use for each of the bitmap's
.QW 0
valued pixels in its normal, active and disabled states.
\fIColor\fR may have any of the forms accepted by \fBTk_GetColor\fR.
If this option is not specified, or if it is specified as an empty
string, then nothing is displayed where the bitmap pixels are 0; this
produces a transparent effect.
.\" OPTION: -bitmap
.TP
\fB\-bitmap \fIbitmap\fR
.\" OPTION: -activebitmap
.TP
\fB\-activebitmap \fIbitmap\fR
.\" OPTION: -disabledbitmap
.TP
\fB\-disabledbitmap \fIbitmap\fR
.
These options specify the bitmaps to display in the item in its normal,
active and disabled states.
Specifies the bitmaps to display in the item in its normal, active and
disabled states.
\fIBitmap\fR may have any of the forms accepted by \fBTk_GetBitmap\fR.
.\" OPTION: -foreground
.TP
\fB\-foreground \fIcolor\fR
.\" OPTION: -activeforeground
.TP
\fB\-activeforeground \fIcolor\fR
.\" OPTION: -disabledforeground
.TP
\fB\-disabledforeground \fIcolor\fR
.
These options specify the color to use for each of the bitmap's
Specifies the color to use for each of the bitmap's
.QW 1
valued pixels in its normal, active and disabled states.
\fIColor\fR may have any of the forms accepted by \fBTk_GetColor\fR.
\fIColor\fR may have any of the forms accepted by \fBTk_GetColor\fR and
defaults to \fBblack\fR.
.SS "IMAGE ITEMS"
.PP
Items of type \fBimage\fR are used to display images on a
canvas.
Images are created with widget commands of the following form:
.CS
\fIpathName \fBcreate image \fIx y \fR?\fIoption value ...\fR?
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1457
1458
1459
1460
1461
1462
1463

1464
1465

1466
1467

1468
1469

1470
1471
1472
1473
1474
1475
1476







-


-


-


-







The following standard options are supported by images:
.DS
.ta 3i
\fB\-anchor\fR	\fB\-state\fR
\fB\-tags\fR
.DE
The following extra options are supported for images:
.\" OPTION: -image
.TP
\fB\-image \fIname\fR
.\" OPTION: -activeimage
.TP
\fB\-activeimage \fIname\fR
.\" OPTION: -disabledimage
.TP
\fB\-disabledimage \fIname\fR
.
Specifies the name of the images to display in the item in is normal,
active and disabled states.
This image must have been created previously with the
\fBimage create\fR command.
.SS "LINE ITEMS"
.PP
Items of type \fBline\fR appear on the display as one or more connected
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
1502
1503
1504
1505
1506
1507
1508

1509
1510

1511
1512
1513
1514
1515
1516
1517







1518
1519

1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534

1535
1536
1537
1538
1539
1540

1541
1542

1543
1544
1545
1546
1547
1548
1549

1550
1551

1552
1553
1554

1555

1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573

1574
1575
1576
1577
1578
1579
1580







-


-







-
-
-
-
-
-
-


-













-


-






-


-







-


-



-
+
-
















-


-







\fB\-disabledfill\fR	\fB\-stipple\fR
\fB\-activestipple\fR	\fB\-disabledstipple\fR
\fB\-state\fR	\fB\-tags\fR
\fB\-width\fR	\fB\-activewidth\fR
\fB\-disabledwidth\fR
.DE
The following extra options are supported for lines:
.\" OPTION: -arrow
.TP
\fB\-arrow \fIwhere\fR
.
Indicates whether or not arrowheads are to be drawn at one or both
ends of the line.
\fIWhere\fR must have one of the values \fBnone\fR (for no arrowheads),
\fBfirst\fR (for an arrowhead at the first point of the line),
\fBlast\fR (for an arrowhead at the last point of the line), or
\fBboth\fR (for arrowheads at both ends).
This option defaults to \fBnone\fR.
When requested to draw an arrowhead, Tk internally adjusts the corresponding
line end point so that the rendered line ends at the neck of the arrowhead
rather than at its tip so that the line doesn't extend past the edge of the
arrowhead. This may trigger a \fBLeave\fR event if the mouse is hovering this
line end. Conversely, when removing an arrowhead Tk adjusts the corresponding
line point the other way round, which may trigger an \fBEnter\fR event.
.\" OPTION: -arrowshape
.TP
\fB\-arrowshape \fIshape\fR
.
This option indicates how to draw arrowheads.
The \fIshape\fR argument must be a list with three elements, each
specifying a distance in any of the forms described in
the \fBCOORDINATES\fR section above.
The first element of the list gives the distance along the line
from the neck of the arrowhead to its tip.
The second element gives the distance along the line from the
trailing points of the arrowhead to the tip, and the third
element gives the distance from the outside edge of the line to the
trailing points.
If this option is not specified then Tk picks a
.QW reasonable
shape.
.\" OPTION: -capstyle
.TP
\fB\-capstyle \fIstyle\fR
.
Specifies the ways in which caps are to be drawn at the endpoints
of the line.
\fIStyle\fR may have any of the forms accepted by \fBTk_GetCapStyle\fR
(\fBbutt\fR, \fBprojecting\fR, or \fBround\fR).
If this option is not specified then it defaults to \fBbutt\fR.
Where arrowheads are drawn the cap style is ignored.
.\" OPTION: -joinstyle
.TP
\fB\-joinstyle \fIstyle\fR
.
Specifies the ways in which joints are to be drawn at the vertices
of the line.
\fIStyle\fR may have any of the forms accepted by \fBTk_GetJoinStyle\fR
(\fBbevel\fR, \fBmiter\fR, or \fBround\fR).
If this option is not specified then it defaults to \fBround\fR.
If the line only contains two points then this option is
irrelevant.
.\" OPTION: -smooth
.TP
\fB\-smooth \fIsmoothMethod\fR
.
\fIsmoothMethod\fR must have one of the forms accepted by
\fBTcl_GetBoolean\fR or a line smoothing method.
Only \fBtrue\fR and \fBraw\fR are
supported in the core (with \fBbezier\fR being an alias for \fBtrue\fR),
supported in the core (with \fBbezier\fR being an alias for \fBtrue\fR), but more can be added at runtime. If a boolean
but more can be added at runtime. If a boolean
false value or empty string is given, no smoothing is applied. A boolean
truth value assumes \fBtrue\fR smoothing.
If the smoothing method is \fBtrue\fR, this indicates that the line
should be drawn as a curve, rendered as a set of quadratic splines: one spline
is drawn for the first and second line segments, one for the second
and third, and so on. Straight-line segments can be generated within
a curve by duplicating the end-points of the desired line segment.
If the smoothing method is \fBraw\fR, this indicates that the line
should also be drawn as a curve but where the list of coordinates is
such that the first coordinate pair (and every third coordinate pair
thereafter) is a knot point on a cubic Bezier curve, and the other
coordinates are control points on the cubic Bezier curve. Straight
line segments can be generated within a curve by making control points
equal to their neighbouring knot points. If the last point is a
control point and not a knot point, the point is repeated (one or two
times) so that it also becomes a knot point.
.\" OPTION: -splinesteps
.TP
\fB\-splinesteps \fInumber\fR
.
Specifies the degree of smoothness desired for curves: each spline
will be approximated with \fInumber\fR line segments. This
option is ignored unless the \fB\-smooth\fR option is true or \fBraw\fR.
.SS "OVAL ITEMS"
.PP
Items of type \fBoval\fR appear as circular or oval regions on
the display. Each oval may have an outline, a fill, or
1817
1818
1819
1820
1821
1822
1823
1824
1825


1826
1827
1828
1829
1830
1831
1832
1623
1624
1625
1626
1627
1628
1629


1630
1631
1632
1633
1634
1635
1636
1637
1638







-
-
+
+







Polygon items support coordinate indexing operations using the \fBdchars\fR,
\fBindex\fR and \fBinsert\fR widget commands.
Polygons are created with widget commands of the following form:
.CS
\fIpathName \fBcreate polygon \fIx1 y1 ... xn yn \fR?\fIoption value ...\fR?
\fIpathName \fBcreate polygon \fIcoordList\fR ?\fIoption value ...\fR?
.CE
The arguments \fIx1\fR through \fIyn\fR or \fIcoordList\fR specify the
coordinates for three or more points that define a polygon.
The arguments \fIx1\fR through \fIyn\fR or \fIcoordList\fR specify the coordinates for
three or more points that define a polygon.
The first point should not be repeated as the last to
close the shape; Tk will automatically close the periphery between
the first and last points.
After the coordinates there may be any number of \fIoption\fR\-\fIvalue\fR
pairs, each of which sets one of the configuration options
for the item. These same \fIoption\fR\-\fIvalue\fR pairs may be
used in \fBitemconfigure\fR widget commands to change the item's
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
1653
1654
1655
1656
1657
1658
1659

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







-


-





-


-


-
+
-












-
+




-


-







\fB\-disabledoutlinestipple\fR	\fB\-stipple\fR
\fB\-activestipple\fR	\fB\-disabledstipple\fR
\fB\-state\fR	\fB\-tags\fR
\fB\-width\fR	\fB\-activewidth\fR
\fB\-disabledwidth\fR
.DE
The following extra options are supported for polygons:
.\" OPTION: -joinstyle
.TP
\fB\-joinstyle \fIstyle\fR
.
Specifies the ways in which joints are to be drawn at the vertices
of the outline.
\fIStyle\fR may have any of the forms accepted by \fBTk_GetJoinStyle\fR
(\fBbevel\fR, \fBmiter\fR, or \fBround\fR).
If this option is not specified then it defaults to \fBround\fR.
.\" OPTION: -smooth
.TP
\fB\-smooth \fIboolean\fR
.
\fIBoolean\fR must have one of the forms accepted by \fBTcl_GetBoolean\fR
or a line smoothing method. Only \fBtrue\fR and \fBraw\fR are
supported in the core (with \fBbezier\fR being an alias for \fBtrue\fR),
supported in the core (with \fBbezier\fR being an alias for \fBtrue\fR), but more can be added at runtime. If a boolean
but more can be added at runtime. If a boolean
false value or empty string is given, no smoothing is applied. A boolean
truth value assumes \fBtrue\fR smoothing.
If the smoothing method is \fBtrue\fR, this indicates that the polygon
should be drawn as a curve, rendered as a set of quadratic splines: one spline
is drawn for the first and second line segments, one for the second
and third, and so on. Straight-line segments can be generated within
a curve by duplicating the end-points of the desired line segment.
If the smoothing method is \fBraw\fR, this indicates that the polygon
should also be drawn as a curve but where the list of coordinates is
such that the first coordinate pair (and every third coordinate pair
thereafter) is a knot point on a cubic Bezier curve, and the other
coordinates are control points on the cubic Bezier curve. Straight
line segments can be generated within a curve by making control points
line segments can be venerated within a curve by making control points
equal to their neighbouring knot points. If the last point is not the
second point of a pair of control points, the point is repeated (one or two
times) so that it also becomes the second point of a pair of control
points (the associated knot point will be the first control point).
.\" OPTION: -splinesteps
.TP
\fB\-splinesteps \fInumber\fR
.
Specifies the degree of smoothness desired for curves: each spline
will be approximated with \fInumber\fR line segments. This
option is ignored unless the \fB\-smooth\fR option is true or \fBraw\fR.
.PP
Polygon items are different from other items such as rectangles, ovals
and arcs in that interior points are considered to be
.QW inside
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
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







-


-
+





-
+


-




-


-






-


-





-

-
+
-





-


-







\fB\-anchor\fR	\fB\-fill\fR
\fB\-activefill\fR	\fB\-disabledfill\fR
\fB\-stipple\fR	\fB\-activestipple\fR
\fB\-disabledstipple\fR	\fB\-state\fR
\fB\-tags\fR
.DE
The following extra options are supported for text items:
.\" OPTION: -angle
.TP
\fB\-angle \fIrotationDegrees\fR
.
.VS 8.6
\fIRotationDegrees\fR tells how many degrees to rotate the text anticlockwise
about the positioning point for the text; it may have any floating-point value
from 0.0 to 360.0. For example, if \fIrotationDegrees\fR is \fB90\fR, then the
text will be drawn vertically from bottom to top.
This option defaults to \fB0.0\fR.
.\" OPTION: -font
.VE 8.6
.TP
\fB\-font \fIfontName\fR
.
Specifies the font to use for the text item.
\fIFontName\fR may be any string acceptable to \fBTk_GetFont\fR.
If this option is not specified, it defaults to a system-dependent
font.
.\" OPTION: -justify
.TP
\fB\-justify \fIhow\fR
.
Specifies how to justify the text within its bounding region.
\fIHow\fR must be one of the values \fBleft\fR, \fBright\fR,
or \fBcenter\fR.
This option will only matter if the text is displayed as multiple
lines.
If the option is omitted, it defaults to \fBleft\fR.
.\" OPTION: -text
.TP
\fB\-text \fIstring\fR
.
\fIString\fR specifies the characters to be displayed in the text item.
Newline characters cause line breaks.
The characters in the item may also be changed with the
\fBinsert\fR and \fBdelete\fR widget commands.
This option defaults to an empty string.
.\" OPTION: -underline
.TP
\fB\-underline \fInumber\fR
\fB\-underline \fI\fR
.
Specifies the integer index of a character within the text to be
underlined. 0 corresponds to the first character of the text
displayed, 1 to the next character, and so on. \-1 means that no
underline should be drawn (if the whole text item is to be underlined,
the appropriate font should be used instead).
.\" OPTION: -width
.TP
\fB\-width \fIlineLength\fR
.
Specifies a maximum line length for the text, in any of the forms
described in the \fBCOORDINATES\fR section above.
If this option is zero (the default) the text is broken into
lines only at newline characters.
However, if this option is non-zero then any line that would
be longer than \fIlineLength\fR is broken just before a space
character to make the line shorter than \fIlineLength\fR; the
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
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







-








-








-








-
+







The following standard options are supported by window items:
.DS
.ta 3i
\fB\-anchor\fR	\fB\-state\fR
\fB\-tags\fR
.DE
The following extra options are supported for window items:
.\" OPTION: -height
.TP
\fB\-height \fIpixels\fR
.
Specifies the height to assign to the item's window.
\fIPixels\fR may have any of the
forms described in the \fBCOORDINATES\fR section above.
If this option is not specified, or if it is specified as zero,
then the window is given whatever height it requests internally.
.\" OPTION: -width
.TP
\fB\-width \fIpixels\fR
.
Specifies the width to assign to the item's window.
\fIPixels\fR may have any of the
forms described in the \fBCOORDINATES\fR section above.
If this option is not specified, or if it is specified as zero,
then the window is given whatever width it requests internally.
.\" OPTION: -window
.TP
\fB\-window \fIpathName\fR
.
Specifies the window to associate with this item.
The window specified by \fIpathName\fR must either be a child of
the canvas widget or a child of some ancestor of the canvas widget.
\fIPathName\fR may not refer to a top-level window.
.PP
Note that, due to restrictions in the ways that windows are managed, it is not
Note: due to restrictions in the ways that windows are managed, it is not
possible to draw other graphical items (such as lines and images) on top
of window items. A window item always obscures any graphics that
overlap it, regardless of their order in the display list. Also note that
window items, unlike other canvas items, are not clipped for display by their
containing canvas's border, and are instead clipped by the parent widget of
the window specified by the \fB\-window\fR option; when the parent widget is
the canvas, this means that the window item can overlap the canvas's border.

Changes to doc/checkbutton.n.

188
189
190
191
192
193
194
195

196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
188
189
190
191
192
193
194

195
196
197
198
199

200

201

202
203
204
205

206
207

208
209
210
211
212
213
214
215
216
217
218
219

220
221

222
223
224

225
226

227
228
229
230
231

232
233

234
235
236
237
238
239

240
241

242
243
244

245
246

247
248
249
250
251
252
253







-
+




-

-
+
-




-


-












-


-



-


-





-


-






-


-



-


-







.SH "WIDGET COMMAND"
.PP
The \fBcheckbutton\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for checkbutton widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBcheckbutton\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBcheckbutton\fR
command.
.\" METHOD: deselect
.TP
\fIpathName \fBdeselect\fR
.
Deselects the checkbutton and sets the associated variable to its
.QW off
value.
.\" METHOD: flash
.TP
\fIpathName \fBflash\fR
.
Flashes the checkbutton.  This is accomplished by redisplaying the checkbutton
several times, alternating between active and normal colors.  At
the end of the flash the checkbutton is left in the same normal/active
state as when the command was invoked.
This command is ignored if the checkbutton's state is \fBdisabled\fR.
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke\fR
.
Does just what would have happened if the user invoked the checkbutton
with the mouse: toggle the selection state of the button and invoke
the Tcl command associated with the checkbutton, if there is one.
The return value is the return value from the Tcl command, or an
empty string if there is no command associated with the checkbutton.
This command is ignored if the checkbutton's state is \fBdisabled\fR.
.\" METHOD: select
.TP
\fIpathName \fBselect\fR
.
Selects the checkbutton and sets the associated variable to its
.QW on
value.
.\" METHOD: toggle
.TP
\fIpathName \fBtoggle\fR
.
Toggles the selection state of the button, redisplaying it and
modifying its associated variable to reflect the new state.
.SH BINDINGS
.PP
Tk automatically creates class bindings for checkbuttons that give them
the following default behavior:
.IP [1]
287
288
289
290
291
292
293
294
295
296
297
298





299
300
301
302
303
304
305
306
307
273
274
275
276
277
278
279





280
281
282
283
284
285
286
287
288
289
290
291
292
293







-
-
-
-
-
+
+
+
+
+









The behavior of checkbuttons can be changed by defining new bindings for
individual widgets or by redefining the class bindings.
.SH EXAMPLE
.PP
This example shows a group of uncoupled checkbuttons.
.PP
.CS
labelframe .lbl -text "Steps:"
\fBcheckbutton\fR .c1 -text Lights  -variable lights
\fBcheckbutton\fR .c2 -text Cameras -variable cameras
\fBcheckbutton\fR .c3 -text Action! -variable action
pack .c1 .c2 .c3 -in .lbl
labelframe .lbl \-text "Steps:"
\fBcheckbutton\fR .c1 \-text Lights  \-variable lights
\fBcheckbutton\fR .c2 \-text Cameras \-variable cameras
\fBcheckbutton\fR .c3 \-text Action! \-variable action
pack .c1 .c2 .c3 \-in .lbl
pack .lbl
.CE
.SH "SEE ALSO"
button(n), options(n), radiobutton(n), ttk::checkbutton(n)
.SH KEYWORDS
checkbutton, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/chooseColor.n.

14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30

31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
14
15
16
17
18
19
20

21

22

23
24
25

26

27

28
29

30

31

32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48







-

-
+
-



-

-
+
-


-

-
+
-










-
+






\fBtk_chooseColor \fR?\fIoption value ...\fR?
.BE
.SH DESCRIPTION
.PP
The procedure \fBtk_chooseColor\fR pops up a dialog box for the
user to select a color. The following \fIoption\-value\fR pairs are
possible as command line arguments:
.\" OPTION: -initialcolor
.TP
\fB\-initialcolor\fI color\fR
\fB\-initialcolor\fR \fIcolor\fR
.
Specifies the color to display in the color dialog when it pops
up. \fIcolor\fR must be in a form acceptable to the \fBTk_GetColor\fR
function.
.\" OPTION: -parent
.TP
\fB\-parent\fI window\fR
\fB\-parent\fR \fIwindow\fR
.
Makes \fIwindow\fR the logical parent of the color dialog. The color
dialog is displayed on top of its parent window.
.\" OPTION: -title
.TP
\fB\-title\fI titleString\fR
\fB\-title\fR \fItitleString\fR
.
Specifies a string to display as the title of the dialog box. If this
option is not specified, then a default title will be displayed.
.LP
If the user selects a color, \fBtk_chooseColor\fR will return the
name of the color in a form acceptable to \fBTk_GetColor\fR.  If the
user cancels the operation, both commands will return the empty
string.
.SH EXAMPLE
.PP
.CS
button .b -bg [tk_chooseColor -initialcolor gray -title "Choose color"]
button .b \-bg [tk_chooseColor \-initialcolor gray \-title "Choose color"]
.CE
.SH KEYWORDS
color, color selection, dialog
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/chooseDirectory.n.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55

56
57
58
59
60
61
62

63
64
65
66
67
68
69
70

71
72

73
74

75
76
77
78
79
80
81
82
83
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19










20

21
22
23
24
25
26
27
28

29







30

31
32
33

34

35

36
37
38

39

40

41
42
43
44
45
46

47
48

49
50

51
52
53
54
55
56
57
58
59
60

-
+
















-

-
-
-
-
-
-
-
-
-
-
+
-








-

-
-
-
-
-
-
-
+
-



-

-
+
-



-

-
+
-






-
+

-
+

-
+









'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH tk_chooseDirectory n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk_chooseDirectory \- pops up a dialog box for the user to select a directory.
.SH SYNOPSIS
\fBtk_chooseDirectory \fR?\fIoption value ...\fR?
.BE
.SH DESCRIPTION
.PP
The procedure \fBtk_chooseDirectory\fR pops up a dialog box for the
user to select a directory. The following \fIoption\-value\fR pairs are
possible as command line arguments:
.\" OPTION: -command
.TP
\fB\-command\fI string\fR
.
Specifies the prefix of a Tcl command to invoke when the user closes the
dialog after having selected an item. This callback is not called if the
user cancelled the dialog. The actual command consists of \fIstring\fR
followed by a space and the value selected by the user in the dialog. This
is only available on Mac OS X.
.\" OPTION: -initialdir
.TP
\fB\-initialdir\fI dirname\fR
\fB\-initialdir\fR \fIdirname\fR
.
Specifies that the directories in \fIdirectory\fR should be displayed
when the dialog pops up. If this parameter is not specified,
the initial directory defaults to the current working directory
on non-Windows systems and on Windows systems prior to Vista.
On Vista and later systems, the initial directory defaults to the last
user-selected directory for the application. If the
parameter specifies a relative path, the return value will convert the
relative path to an absolute path.
.\" OPTION: -message
.TP
\fB\-message\fI string\fR
.
Specifies a message to include in the client area of the dialog.
This is only available on Mac OS X.
.\" OPTION: -mustexist
.TP
\fB\-mustexist\fI boolean\fR
\fB\-mustexist\fR \fIboolean\fR
.
Specifies whether the user may specify non-existent directories.  If
this parameter is true, then the user may only select directories that
already exist.  The default value is \fIfalse\fR.
.\" OPTION: -parent
.TP
\fB\-parent\fI window\fR
\fB\-parent\fR \fIwindow\fR
.
Makes \fIwindow\fR the logical parent of the dialog. The dialog
is displayed on top of its parent window. On Mac OS X, this
turns the file dialog into a sheet attached to the parent window.
.\" OPTION: -title
.TP
\fB\-title\fI titleString\fR
\fB\-title\fR \fItitleString\fR
.
Specifies a string to display as the title of the dialog box. If this
option is not specified, then a default title will be displayed.
.SH EXAMPLE
.PP
.CS
set dir [\fBtk_chooseDirectory\fR \e
        -initialdir ~ -title "Choose a directory"]
        \-initialdir ~ \-title "Choose a directory"]
if {$dir eq ""} {
   label .l -text "No directory selected"
   label .l \-text "No directory selected"
} else {
   label .l -text "Selected $dir"
   label .l \-text "Selected $dir"
}
.CE
.SH "SEE ALSO"
tk_getOpenFile(n), tk_getSaveFile(n)
.SH KEYWORDS
directory, selection, dialog, platform-specific
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/clipboard.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30

31
32
33
34
35
36
37
38







-
+














-

-
+







.TH clipboard n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
clipboard \- Manipulate Tk clipboard
.SH SYNOPSIS
\fBclipboard \fIoption\fR ?\fIarg ...\fR?
\fBclipboard \fIoption\fR ?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
This command provides a Tcl interface to the Tk clipboard,
which stores data for later retrieval using the selection mechanism
(via the \fB\-selection CLIPBOARD\fR option).
In order to copy data into the clipboard, \fBclipboard clear\fR must
be called, followed by a sequence of one or more calls to \fBclipboard
append\fR.  To ensure that the clipboard is updated atomically, all
appends should be completed before returning to the event loop.
.PP
The first argument to \fBclipboard\fR determines the format of the
rest of the arguments and the behavior of the command.  The following
forms are currently supported:
.\" METHOD: append
.TP
\fBclipboard append\fR ?\fB\-displayof\fI window\fR? ?\fB\-format\fI format\fR? ?\fB\-type\fI type\fR? ?\fB\-\|\-\fR? \fIdata\fR
\fBclipboard append\fR ?\fB\-displayof\fR \fIwindow\fR? ?\fB\-format\fR \fIformat\fR? ?\fB\-type\fR \fItype\fR? ?\fB\-\|\-\fR? \fIdata\fR
.
Appends \fIdata\fR to the clipboard on \fIwindow\fR's
display in the form given by \fItype\fR with the representation given
by \fIformat\fR and claims ownership of the clipboard on \fIwindow\fR's
display.
.RS
.PP
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
67
68
69
70
71
72
73

74

75
76
77
78
79
80

81

82
83
84
85
86
87
88
89







-

-
+





-

-
+







irrelevant.
.PP
A \fB\-\|\-\fR argument may be specified to mark the end of options:  the
next argument will always be used as \fIdata\fR.
This feature may be convenient if, for example, \fIdata\fR starts
with a \fB\-\fR.
.RE
.\" METHOD: clear
.TP
\fBclipboard clear\fR ?\fB\-displayof\fI window\fR?
\fBclipboard clear\fR ?\fB\-displayof\fR \fIwindow\fR?
.
Claims ownership of the clipboard on \fIwindow\fR's display and removes
any previous contents.  \fIWindow\fR defaults to
.QW . .
Returns an empty string.
.\" METHOD: get
.TP
\fBclipboard get\fR ?\fB\-displayof\fI window\fR? ?\fB\-type\fI type\fR?
\fBclipboard get\fR ?\fB\-displayof\fR \fIwindow\fR? ?\fB\-type\fR \fItype\fR?
.
Retrieve data from the clipboard on \fIwindow\fR's display.
\fIWindow\fR defaults to
.QW . .
\fIType\fR specifies the form in which
the data is to be returned and should be an atom name such as \fBSTRING\fR
or \fBFILE_NAME\fR.  \fIType\fR defaults to \fBSTRING\fR.  This command is
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139

140
141
142

143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135

136
137
138

139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157







-
+










-
+


-
+







-
+










# it produces a script that recreates the item(s) when executed
proc getItemConfig {canvas tag} {
   set script {}
   foreach item [$canvas find withtag $tag] {
      append script {$canvas create } [$canvas type $item]
      append script { } [$canvas coords $item] { }
      foreach config [$canvas itemconf $item] {
         lassign $config name - - - value
         lassign $config name \- \- \- value
         append script [list $name $value] { }
      }
      append script \en
   }
   return [string trim $script]
}

# Set up a binding on a canvas to cut and paste an item
set c [canvas .c]
pack $c
$c create text 150 30 -text "cut and paste me"
$c create text 150 30 \-text "cut and paste me"
bind $c <<Cut>> {
   \fBclipboard clear\fR
   \fBclipboard append -type\fR TkCanvasItem \e
   \fBclipboard append \-type\fR TkCanvasItem \e
         [getItemConfig %W current]
   # Delete because this is cut, not copy.
   %W delete current
}
bind $c <<Paste>> {
   catch {
      set canvas %W
      eval [\fBclipboard get -type\fR TkCanvasItem]
      eval [\fBclipboard get \-type\fR TkCanvasItem]
   }
}
.CE
.SH "SEE ALSO"
interp(n), selection(n)
.SH KEYWORDS
clear, format, clipboard, append, selection, type
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/colors.n.

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" Copyright (c) 2003 ActiveState Corporation.
'\" Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
'\" Copyright (c) 2008 Donal K. Fellows
'\"
.TH colors n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
780
781
782
783
784
785
786
787

788
789

790
791

792
793
794

795
796

797
798
799
800





801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

823

824
825

826


827
828
829
830
831
832
833

834
835


836
837
838
839
840
841


842
843

844
845







846
847

848



849




850
851
852







853






854
855

856
857
858
859
860
861







862
863
864
865
866
867


868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887


888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906




907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929









930
931
932
933
934
935
936
937
938
939
940
941
942
943
780
781
782
783
784
785
786

787


788


789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917


918
919




















920
921



















922
923
924
925




926
927
928
929
930
931
932
933
934
935









936
937
938
939
940
941
942
943
944
945
946
947
948

949
950
951
952
953
954
955
956
957







-
+
-
-
+
-
-
+



+


+




+
+
+
+
+



+



















+

+


+

+
+







+


+
+






+
+


+


+
+
+
+
+
+
+


+

+
+
+

+
+
+
+



+
+
+
+
+
+
+

+
+
+
+
+
+


+

-




+
+
+
+
+
+
+




-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-










-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-









yellow4	139	139 	0
YellowGreen	154	205 	50
.DE
.SH "PORTABILITY ISSUES"
.TP
\fBMac OS X\fR
.
On macOS, the following additional system colors are available.  This
On Mac OS X, the following additional system colors are available
first group contains all of the HIBrush colors available in the
HIToolbox library. Note that on macOS 10.14 (Mojave) and later these
(note that the actual color values depend on the currently active OS theme,
colors are unlikely to match the color actually used for the purpose
suggested by the color name.
and typically many of these will in fact be patterns rather than pure colors):
.RS
.DS
systemActiveAreaFill
systemAlertActiveText
systemAlertBackgroundActive
systemAlertBackgroundInactive
systemAlertInactiveText
systemAlternatePrimaryHighlightColor
systemAppleGuideCoachmark
systemBevelActiveDark
systemBevelActiveLight
systemBevelButtonActiveText
systemBevelButtonInactiveText
systemBevelButtonPressedText
systemBevelButtonStickyActiveText
systemBevelButtonStickyInactiveText
systemBevelInactiveDark
systemBevelInactiveLight
systemBlack
systemBlackText
systemButtonActiveDarkHighlight
systemButtonActiveDarkShadow
systemButtonActiveLightHighlight
systemButtonActiveLightShadow
systemButtonFace
systemButtonFaceActive
systemButtonFaceInactive
systemButtonFacePressed
systemButtonFrame
systemButtonFrameActive
systemButtonFrameInactive
systemButtonInactiveDarkHighlight
systemButtonInactiveDarkShadow
systemButtonInactiveLightHighlight
systemButtonInactiveLightShadow
systemButtonPressedDarkHighlight
systemButtonPressedDarkShadow
systemButtonPressedLightHighlight
systemButtonPressedLightShadow
systemButtonText
systemChasingArrows
systemDialogActiveText
systemDialogBackgroundActive
systemDialogBackgroundInactive
systemDialogInactiveText
systemDocumentWindowBackground
systemDocumentWindowTitleActiveText
systemDocumentWindowTitleInactiveText
systemDragHilite
systemDrawerBackground
systemFinderWindowBackground
systemFocusHighlight
systemHighlight
systemHighlightAlternate
systemHighlightSecondary
systemHighlightText
systemIconLabelBackground
systemIconLabelBackgroundSelected
systemIconLabelSelectedText
systemIconLabelText
systemListViewBackground
systemListViewColumnDivider
systemListViewEvenRowBackground
systemListViewOddRowBackground
systemListViewSeparator
systemListViewSortColumnBackground
systemListViewText
systemListViewWindowHeaderBackground
systemMenu
systemMenuActive
systemMenuActiveText
systemMenuBackground
systemMenuBackgroundSelected
systemMenuDisabled
systemMenuItemActiveText
systemMenuItemDisabledText
systemMenuItemSelectedText
systemMenuText
systemMetalBackground
systemModelessDialogActiveText
systemModelessDialogBackgroundActive
systemModelessDialogBackgroundInactive
systemModelessDialogInactiveText
systemMovableModalBackground
systemMovableModalWindowTitleActiveText
systemMovableModalWindowTitleInactiveText
systemNotificationText
systemNotificationWindowBackground
systemPlacardActiveText
systemPlacardBackground
systemPlacardInactiveText
systemPlacardPressedText
systemPopupArrowActive
systemPopupArrowInactive
systemPopupArrowPressed
systemPopupButtonActiveText
systemPopupButtonInactiveText
systemPopupButtonPressedText
systemPopupLabelActiveText
systemPopupLabelInactiveText
systemPopupWindowTitleActiveText
systemPopupWindowTitleInactiveText
systemPrimaryHighlightColor
systemPushButtonActiveText
systemPushButtonInactiveText
systemPushButtonPressedText
systemRootMenuActiveText
systemRootMenuDisabledText
systemRootMenuSelectedText
systemScrollBarDelimiterActive
systemScrollBarDelimiterInactive
systemSecondaryGroupBoxBackground
systemSecondaryHighlightColor
systemSelectedTabTextColor
systemSheetBackground
systemSheetBackgroundOpaque
systemSheetBackgroundTransparent
systemStaticAreaFill
systemSystemDetailText
systemTabFrontActiveText
systemTabFrontInactiveText
systemTabNonFrontActiveText
systemTabNonFrontInactiveText
systemTabNonFrontPressedText
systemTabPaneBackground
systemToolbarBackground
systemTransparent
systemUtilityWindowBackgroundActive
systemUtilityWindowBackgroundInactive
systemWhite
systemWindowBody
systemUtilityWindowTitleActiveText
systemUtilityWindowTitleInactiveText
.DE
.RE
.
Tk supports all of the NSColors in the macOS System ColorList.  The
convention for naming these colors is that the Tk name is generated by
capitalizing the macOS name and adding the prefix "system".  On OSX
10.14 (Mojave) and later many of these "semantic" colors will appear
differently depending on whether the NSWindow in which they are used has
the Aqua or DarkAqua appearance.  The System ColorList differs between
releases of macOS and some colors, such as systemLinkColor and
systemControlAccentColor, are simulated on older systems which did not
provide them.  All of the colors below are available on all supported
macOS releases, but newer systems will support additional colors.
.RS
.DS
systemControlAccentColor
systemControlTextColor
systemDisabledControlTextColor
systemLabelColor
systemLinkColor
systemWhite
systemWhiteText
systemPlaceholderTextColor
systemSelectedTextBackgroundColor
systemSelectedTextColor
systemSeparatorColor
systemTextBackgroundColor
systemTextColor
.DE
.RE
.
The numbered systemWindowBackgroundColors below
are used in the \fBttk::notebook\fR and \fBttk::labelframe\fR widgets
to provide a contrasting background.  Each numbered color contrasts
with its predecessor.
.RS
.DS
systemWindowBackgroundColor
systemWindowBackgroundColor1
systemWindowBackgroundColor2
systemWindowBackgroundColor3
systemWindowBody
systemWindowHeaderActiveText
systemWindowHeaderBackground
systemWindowHeaderInactiveText
systemWindowBackgroundColor4
systemWindowBackgroundColor5
systemWindowBackgroundColor6
systemWindowBackgroundColor7
.DE
.RE
.TP
\fBWindows\fR
.
On Windows, the following additional system colors are available
(note that the actual color values depend on the currently active OS theme):
.RS
.DS
.ta 6c
system3dDarkShadow	systemHighlightText
system3dLight	systemInactiveBorder
systemActiveBorder	systemInactiveCaption
systemActiveCaption	systemInactiveCaptionText
systemAppWorkspace	systemInfoBackground
systemBackground	systemInfoText
systemButtonFace	systemMenu
systemButtonHighlight	systemMenuText
systemButtonShadow	systemPlaceholderText
system3dDarkShadow	systemHighlight
system3dLight	systemHighlightText
systemActiveBorder	systemInactiveBorder
systemActiveCaption	systemInactiveCaption
systemAppWorkspace	systemInactiveCaptionText
systemBackground	systemInfoBackground
systemButtonFace	systemInfoText
systemButtonHighlight	systemMenu
systemButtonShadow	systemMenuText
systemButtonText	systemScrollbar
systemCaptionText	systemWindow
systemDisabledText	systemWindowFrame
systemGrayText	systemWindowText
systemHighlight
.DE
.RE
.SH "SEE ALSO"
options(n), Tk_GetColor(3)
.SH KEYWORDS
color, option
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/console.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29



30


31

32
33

34
35
36

37
38

39
40

41
42

43
44

45
46

47
48
49
50
51
52
53
54
55
56
57

58
59

60
61

62
63

64
65
66
67
68
69
70













-
+













-
-
+
+
-
-
-
+
-
-

-


-



-


-


-


-


-


-











-


-


-


-







'\"
'\" Copyright (c) 2001 Donal K. Fellows
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH console n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
console \- Control the console on systems without a real console
.SH SYNOPSIS
\fBconsole\fI subcommand\fR ?\fIarg ...\fR?
\fBconsole\fR \fIsubcommand\fR ?\fIarg ...\fR?
.BE
.SH DESCRIPTION
.PP
The console window is a replacement for a real console to allow input
and output on the standard I/O channels on platforms that do not have
a real console.  It is implemented as a separate interpreter with the
Tk toolkit loaded, and control over this interpreter is given through
the \fBconsole\fR command.  The behaviour of the console window is
defined mainly through the contents of the \fIconsole.tcl\fR file in
the Tk library. Except for TkAqua, this command is not available when
Tk is loaded into a tclsh interpreter with
.QW "\fBpackage require Tk\fR" ,
as a conventional terminal is expected to be present in that case.
In TkAqua, this command is disabled when there is a startup script
and stdin is \fB/dev/null\fR (as is the case e.g. when a bundled application
In TkAqua, this command is only available when stdin is \fB/dev/null\fR
(as is the case e.g. when the application embedding Tk is started
embedding Tk is started by the macOS Launcher).  To enable the command
in that case, define the environment variable \fBTK_CONSOLE\fR.  This can be
done by modifying the Info.plist file by adding the LSEnvironment key
from the Mac OS X Finder).
to the main dict and setting its value to be a dict with the key
\fBTK_CONSOLE\fR.
.PP
.\" METHOD: eval
.TP
\fBconsole eval \fIscript\fR
.
Evaluate the \fIscript\fR argument as a Tcl script in the console
interpreter.  The normal interpreter is accessed through the
\fBconsoleinterp\fR command in the console interpreter.
.\" METHOD: hide
.TP
\fBconsole hide\fR
.
Hide the console window from view.  Precisely equivalent to
withdrawing the \fB.\fR window in the console interpreter.
.\" METHOD: show
.TP
\fBconsole show\fR
.
Display the console window.  Precisely equivalent to deiconifying the
\fB.\fR window in the console interpreter.
.\" METHOD: title
.TP
\fBconsole title \fR?\fIstring\fR?
.
Query or modify the title of the console window.  If \fIstring\fR is
not specified, queries the title of the console window, and sets the
title of the console window to \fIstring\fR otherwise.  Precisely
equivalent to using the \fBwm title\fR command in the console
interpreter.
.SH "ACCESS TO THE MAIN INTERPRETER"
.PP
The \fBconsoleinterp\fR command in the console interpreter allows
scripts to be evaluated in the main interpreter.  It supports two
subcommands: \fBeval\fR and \fBrecord\fR.
.PP
.\" METHOD: eval
.TP
\fBconsoleinterp eval \fIscript\fR
.
Evaluates \fIscript\fR as a Tcl script at the global level in the main
interpreter.
.\" METHOD: record
.TP
\fBconsoleinterp record \fIscript\fR
.
Records and evaluates \fIscript\fR as a Tcl script at the global level
in the main interpreter as if \fIscript\fR had been typed in at the
console.
.SH "ADDITIONAL TRAP CALLS"
.PP
There are several additional commands in the console interpreter that
are called in response to activity in the main interpreter.

Changes to doc/cursors.n.

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
'\" Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
'\"
.TH cursors n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
97
98
99
100
101
102
103

104
105
106
107
108
109
110







-







xterm
.CE
.PP
The \fBnone\fR cursor can be specified to eliminate the cursor.
.SH "PORTABILITY ISSUES"
.TP
\fBWindows\fR
.
On Windows systems, the following cursors are mapped to native cursors:
.RS
.CS
arrow
center_ptr
crosshair
fleur
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
127
128
129
130
131
132
133

134
135
136
137
138
139
140







-







size_we
uparrow
wait
.CE
.RE
.TP
\fBMac OS X\fR
.
On Mac OS X systems, the following cursors are mapped to native cursors:
.RS
.CS
arrow
top_left_arrow
left_ptr
cross

Changes to doc/dialog.n.

15
16
17
18
19
20
21

22

23
24

25

26

27

28

29

30
31
32
33

34

35
36
37
38
39

40

41
42
43
44
45
46
47
15
16
17
18
19
20
21
22

23
24
25
26

27
28
29

30
31
32

33
34
35
36
37
38

39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







+
-
+


+
-
+

+
-
+

+
-
+




+
-
+





+
-
+







\fBtk_dialog \fIwindow title text bitmap default string string ...\fR
.BE
.SH DESCRIPTION
.PP
This procedure is part of the Tk script library.
It is largely \fIdeprecated\fR by the \fBtk_messageBox\fR.
Its arguments describe a dialog box:
.TP
.IP \fIwindow\fR
\fIwindow\fR
Name of top-level window to use for dialog.  Any existing window
by this name is destroyed.
.TP
.IP \fItitle\fR
\fItitle\fR
Text to appear in the window manager's title bar for the dialog.
.TP
.IP \fItext\fR
\fItext\fR
Message to appear in the top portion of the dialog box.
.TP
.IP \fIbitmap\fR
\fIbitmap\fR
If non-empty, specifies a bitmap (in a form suitable for Tk_GetBitmap)
to display in the top portion of
the dialog, to the left of the text.
If this is an empty string then no bitmap is displayed in the dialog.
.TP
.IP \fIdefault\fR
\fIdefault\fR
If this is an integer greater than or equal to zero, then it gives
the index of the button that is to be the default button for the dialog
(0 for the leftmost button, and so on).
If less than zero or an empty string then there will not be any default
button.
.TP
.IP \fIstring\fR
\fIstring\fR
There will be one button for each of these arguments.
Each \fIstring\fR specifies text to display in a button,
in order from left to right.
.PP
After creating a dialog box, \fBtk_dialog\fR waits for the user to
select one of the buttons either by clicking on the button with the
mouse or by typing return to invoke the default button (if any).

Changes to doc/entry.n.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32







-
+









-







.TH entry n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
entry \- Create and manipulate 'entry' one-line text entry widgets
.SH SYNOPSIS
\fBentry\fI pathName \fR?\fIoptions\fR?
\fBentry\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-background	\-highlightthickness	\-selectbackground
\-borderwidth	\-insertbackground	\-selectborderwidth
\-cursor	\-insertborderwidth	\-selectforeground
\-exportselection	\-insertofftime	\-takefocus
\-font	\-insertontime	\-textvariable
\-foreground	\-insertwidth	\-xscrollcommand
\-highlightbackground	\-justify
\-highlightcolor	\-relief
\-placeholder	\-placeholderforeground
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-disabledbackground disabledBackground DisabledBackground
Specifies the background color to use when the entry is disabled.  If
this option is the empty string, the normal background color is used.
.OP \-disabledforeground disabledForeground DisabledForeground
Specifies the foreground color to use when the entry is disabled.  If
172
173
174
175
176
177
178
179

180
181

182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

453
454

455


456
457
458



459
460
461
462
463
464
465
466
467
468
171
172
173
174
175
176
177

178
179

180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
199
200
201
202

203
204
205
206

207
208
209
210

211
212
213
214
215

216
217
218
219

220
221
222
223

224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240



241
242
243

244
245

246
247
248
249
250
251
252
253

254

255

256
257
258
259

260
261

262
263
264
265
266
267
268
269
270
271
272
273

274
275

276
277
278
279
280
281
282

283
284

285

286
287

288
289

290
291

292

293
294

295
296

297

298

299
300
301
302
303

304
305
306
307
308
309

310
311
312
313
314
315
316
317

318
319

320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340

341
342
343
344
345

346
347
348

349

350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369

370
371

372
373
374
375

376
377

378
379
380
381
382
383

384
385
386
387
388
389
390
391
392

393

394
395
396
397

398
399
400
401
402

403
404

405


406
407
408
409



410
411
412
413


414
415
416
417
418
419
420







-
+

-
+











-
+










-




-




-





-




-




-





-












-
-
-



-


-








-

-
+
-




-


-












-


-







-


-

-


-


-


-

-


-


-

-
+
-





-






-








-


-





-











-





-





-



-
+
-







-













-


-




-


-






-









-
+
-




-





-


-
+
-
-
+

+
+
-
-
-
+
+
+

-
-







\fB\-invalidcommand\fR encounters an error in its script while evaluating or
\fB\-validatecommand\fR does not return a valid Tcl boolean value.  The
\fB\-validate\fR option will also set itself to \fBnone\fR when you edit the
entry widget from within either the \fB\-validatecommand\fR or the
\fB\-invalidcommand\fR.  Such editions will override the one that was being
validated.  If you wish to edit the entry widget (for example set it to {})
during validation and still have the \fB\-validate\fR option set, you should
include the command:
include the command
.CS
after idle {%W config -validate %v}
after idle {%W config \-validate %v}
.CE
in the \fB\-validatecommand\fR or \fB\-invalidcommand\fR (whichever one you
were editing the entry widget from).  It is also recommended to not set an
associated \fB\-textvariable\fR during validation, as that can cause the
entry widget to become out of sync with the \fB\-textvariable\fR.
.SH "WIDGET COMMAND"
.PP
The \fBentry\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName subcommand \fR?\fIarg ...\fR?
\fIpathName subcommand \fR?\fIarg arg ...\fR?
.CE
\fISubcommand\fR and the \fIarg\fRs
determine the exact behavior of the command.
.SS INDICES
.PP
Many of the widget commands for entries take one or more indices as
arguments.  An index specifies a particular character in the entry's
string, in any of the following ways:
.TP 12
\fInumber\fR
.
Specifies the character as a numerical index, where 0 corresponds
to the first character in the string.
.TP 12
\fBanchor\fR
.
Indicates the anchor point for the selection, which is set with the
\fBselect from\fR and \fBselect adjust\fR widget commands.
.TP 12
\fBend\fR
.
Indicates the character just after the last one in the entry's string.
This is equivalent to specifying a numerical index equal to the length
of the entry's string.
.TP 12
\fBinsert\fR
.
Indicates the character adjacent to and immediately following the
insertion cursor.
.TP 12
\fBsel.first\fR
.
Indicates the first character in the selection.  It is an error to
use this form if the selection is not in the entry window.
.TP 12
\fBsel.last\fR
.
Indicates the character just after the last one in the selection.
It is an error to use this form if the selection is not in the
entry window.
.TP 12
\fB@\fInumber\fR
.
In this form, \fInumber\fR is treated as an x-coordinate in the
entry's window;  the character spanning that x-coordinate is used.
For example,
.QW \fB@0\fR
indicates the left-most character in the window.
.LP
Abbreviations may be used for any of the forms above, e.g.
.QW \fBe\fR
or
.QW \fBsel.f\fR .
In general, out-of-range indices are automatically rounded to the
nearest legal value.
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.SS SUBCOMMANDS
.PP
The following commands are possible for entry widgets:
.\" METHOD: bbox
.TP
\fIpathName \fBbbox \fIindex\fR
.
Returns a list of four numbers describing the bounding box of the
character given by \fIindex\fR.
The first two elements of the list give the x and y coordinates of
the upper-left corner of the screen area covered by the character
(in pixels relative to the widget) and the last two elements give
the width and height of the character, in pixels.
The bounding box may refer to a region outside the visible area
of the window.
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBentry\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBentry\fR
command.
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fIfirst \fR?\fIlast\fR?
.
Delete one or more elements of the entry.
\fIFirst\fR is the index of the first character to delete, and
\fIlast\fR is the index of the character just after the last
one to delete.
If \fIlast\fR is not specified it defaults to \fIfirst\fR+1,
i.e. a single character is deleted.
This command returns an empty string.
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the entry's string.
.\" METHOD: icursor
.TP
\fIpathName \fBicursor \fIindex\fR
.
Arrange for the insertion cursor to be displayed just before the character
given by \fIindex\fR.  Returns an empty string.
.\" METHOD: index
.TP
\fIpathName \fBindex\fI index\fR
.
Returns the numerical index corresponding to \fIindex\fR.
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex string\fR
.
Insert the characters of \fIstring\fR just before the character
indicated by \fIindex\fR.  Returns an empty string.
.\" METHOD: scan
.TP
\fIpathName \fBscan\fI option args\fR
\fIpathName \fBscan\fR \fIoption args\fR
.
This command is used to implement scanning on entries.  It has
two forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBscan mark \fIx\fR
.
Records \fIx\fR and the current view in the entry window;  used in
conjunction with later \fBscan dragto\fR commands.  Typically this
command is associated with a mouse button press in the widget.  It
returns an empty string.
.TP
\fIpathName \fBscan dragto \fIx\fR
.
This command computes the difference between its \fIx\fR argument
and the \fIx\fR argument to the last \fBscan mark\fR command for
the widget.  It then adjusts the view left or right by 10 times the
difference in x-coordinates.  This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the entry at high speed through the window.  The return
value is an empty string.
.RE
.\" METHOD: selection
.TP
\fIpathName \fBselection \fIoption arg\fR
.
This command is used to adjust the selection within an entry.  It
has several forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBselection adjust \fIindex\fR
.
Locate the end of the selection nearest to the character given by
\fIindex\fR, and adjust that end of the selection to be at \fIindex\fR
(i.e. including but not going beyond \fIindex\fR).  The other
end of the selection is made the anchor point for future
\fBselect to\fR commands.  If the selection
is not currently in the entry, then a new selection is created to
include the characters between \fIindex\fR and the most recent
selection anchor point, inclusive.
Returns an empty string.
.TP
\fIpathName \fBselection clear\fR
.
Clear the selection if it is currently in this widget.  If the
selection is not in this widget then the command has no effect.
Returns an empty string.
.TP
\fIpathName \fBselection from \fIindex\fR
.
Set the selection anchor point to just before the character
given by \fIindex\fR.  Does not change the selection.
Returns an empty string.
.TP
\fIpathName \fBselection present\fR
.
Returns 1 if there is are characters selected in the entry,
0 if nothing is selected.
.TP
\fIpathName \fBselection range \fIstart end\fR
\fIpathName \fBselection range \fIstart\fR \fIend\fR
.
Sets the selection to include the characters starting with
the one indexed by \fIstart\fR and ending with the one just
before \fIend\fR.
If \fIend\fR refers to the same character as \fIstart\fR or an
earlier one, then the entry's selection is cleared.
.TP
\fIpathName \fBselection to \fIindex\fR
.
If \fIindex\fR is before the anchor point, set the selection
to the characters from \fIindex\fR up to but not including
the anchor point.
If \fIindex\fR is the same as the anchor point, do nothing.
If \fIindex\fR is after the anchor point, set the selection
to the characters from the anchor point up to but not including
\fIindex\fR.
The anchor point is determined by the most recent \fBselect from\fR
or \fBselect adjust\fR command in this widget.
If the selection is not in this widget then a new selection is
created using the most recent anchor point specified for the widget.
Returns an empty string.
.RE
.\" METHOD: validate
.TP
\fIpathName \fBvalidate\fR
.
This command is used to force an evaluation of the \fB\-validatecommand\fR
independent of the conditions specified by the \fB\-validate\fR option.
This is done by temporarily setting the \fB\-validate\fR option to \fBall\fR.
It returns 0 or 1.
.\" METHOD: xview
.TP
\fIpathName \fBxview \fIargs\fR
.
This command is used to query and change the horizontal position of the
text in the widget's window.  It can take any of the following
forms:
.RS
.TP
\fIpathName \fBxview\fR
.
Returns a list containing two elements.
Each element is a real fraction between 0 and 1;  together they describe
the horizontal span that is visible in the window.
For example, if the first element is .2 and the second element is .6,
20% of the entry's text is off-screen to the left, the middle 40% is visible
in the window, and 40% of the text is off-screen to the right.
These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
option.
.TP
\fIpathName \fBxview\fI index\fR
\fIpathName \fBxview\fR \fIindex\fR
.
Adjusts the view in the window so that the character given by \fIindex\fR
is displayed at the left edge of the window.
.TP
\fIpathName \fBxview moveto\fI fraction\fR
.
Adjusts the view in the window so that the character \fIfraction\fR of the
way through the text appears at the left edge of the window.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display;  if it is
If \fIwhat\fR is \fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left become
visible;  if it is positive then characters farther to the right
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left
become visible;  if it is positive then characters farther to the right
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display.
.RE
.SH "DEFAULT BINDINGS"
.PP
Tk automatically creates class bindings for entries that give them
the following default behavior. In the descriptions below,
.QW word
refers to a contiguous group of letters, digits, or
492
493
494
495
496
497
498
499

500
501
502


503
504
505
506
507
508
509
444
445
446
447
448
449
450

451



452
453
454
455
456
457
458
459
460







-
+
-
-
-
+
+







.IP [5]
Clicking mouse button 1 with the Control key down will position the
insertion cursor in the entry without affecting the selection.
.IP [6]
If any normal printing characters are typed in an entry, they are
inserted at the point of the insertion cursor.
.IP [7]
The view in the entry can be adjusted by dragging with the middle
The view in the entry can be adjusted by dragging with mouse button 2.
mouse button (button 2, or button 3 in TkAqua). If the middle mouse
button is clicked without moving the mouse, the selection is copied
into the entry at the position of the mouse cursor.
If mouse button 2 is clicked without moving the mouse, the selection
is copied into the entry at the position of the mouse cursor.
.IP [8]
If the mouse is dragged out of the entry on the left or right sides
while button 1 is pressed, the entry will automatically scroll to
make more text visible (if there is more text off-screen on the side
where the mouse left the window).
.IP [9]
The Left and Right keys move the insertion cursor one character to the

Changes to doc/event.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294

295
296

297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
32
33

34

35

36
37
38
39
40
41
42
43
44
45

46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89

90
91
92
93

94
95

96
97
98
99

100
101

102

103
104
105

106
107

108
109
110

111
112

113
114
115

116
117

118
119
120
121
122
123
124
125
126

127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144

145
146
147
148

149
150

151
152
153

154
155

156
157

158
159

160
161

162
163
164
165

166
167

168
169

170
171
172
173
174
175

176
177

178
179
180
181

182
183

184
185
186
187

188
189

190
191

192
193
194
195

196
197

198
199

200
201
202

203
204

205
206

207
208
209
210

211
212

213
214
215

216
217

218
219
220

221
222

223

224
225
226
227
228
229
230
231

232
233

234
235

236
237
238

239
240

241

242


243
244
245
246

247
248

249
250

251
252
253

254
255

256
257
258
259

260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

280
281

282
283

284
285
286
287
288
289
290
291

292
293

294
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320

321
322
323
324

325
326
327
328

329
330
331
332

333
334
335
336

337
338
339
340


341


342









343

344
345
346
347
348
349

350
351
352
353
354
355

356
357
358
359

360
361
362
363
364
365
366
367
368
369

370
371
372

373
374
375

376
377
378
379
380
381
382







-
+







-


-









-

-
+
-










-


-




















-


-


















-


-




-


-




-


-

-
+


-


-



-


-



-


-









-


-














-


-




-


-



-


-


-
+

-


-




-
+

-


-






-


-




-


-




-


-


-
+



-


-


-
+


-


-


-
+



-


-



-


-



-


-

-
+







-


-


-
+


-


-

-
+
-
-
+



-


-


-
+


-


-




-


-


















-


-


-
+







-


-


-
+

















-







-




-




-




-




-




-
-
+
-
-

-
-
-
-
-
-
-
-
-

-






-






-




-










-



-



-







.TH event n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
event \- Miscellaneous event facilities: define virtual events and generate events
.SH SYNOPSIS
\fBevent\fI option \fR?\fIarg ...\fR?
\fBevent\fI option \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBevent\fR command provides several facilities for dealing with
window system events, such as defining virtual events and synthesizing
events.  The command has several different forms, determined by the
first argument.  The following forms are currently supported:
.\" METHOD: add
.TP
\fBevent add <<\fIvirtual\fB>>\fI sequence \fR?\fIsequence ...\fR?
.
Associates the virtual event \fIvirtual\fR with the physical
event sequence(s) given by the \fIsequence\fR arguments, so that
the virtual event will trigger whenever any one of the \fIsequence\fRs
occurs.
\fIVirtual\fR may be any string value and \fIsequence\fR may have
any of the values allowed for the \fIsequence\fR argument to the
\fBbind\fR command.
If \fIvirtual\fR is already defined, the new physical event sequences
add to the existing sequences for the event.
.\" METHOD: delete
.TP
\fBevent delete <<\fIvirtual\fB>> \fR?\fIsequence sequence ...\fR?
\fBevent delete <<\fIvirtual\fB>> \fR?\fIsequence\fR \fIsequence ...\fR?
.
Deletes each of the \fIsequence\fRs from those associated with
the virtual event given by \fIvirtual\fR.
\fIVirtual\fR may be any string value and \fIsequence\fR may have
any of the values allowed for the \fIsequence\fR argument to the
\fBbind\fR command.
Any \fIsequence\fRs not currently associated with \fIvirtual\fR
are ignored.
If no \fIsequence\fR argument is provided, all physical event sequences
are removed for \fIvirtual\fR, so that the virtual event will not
trigger anymore.
.\" METHOD: generate
.TP
\fBevent generate \fIwindow event \fR?\fIoption value option value ...\fR?
.
Generates a window event and arranges for it to be processed just as if
it had come from the window system.
\fIWindow\fR gives the path name of the window for which the event
will be generated; it may also be an identifier (such as returned by
\fBwinfo id\fR) as long as it is for a window in the current application.
\fIEvent\fR provides a basic description of
the event, such as \fB<Shift-Button-2>\fR or \fB<<Paste>>\fR.
If \fIWindow\fR is empty the whole screen is meant, and coordinates
are relative to the screen.
\fIEvent\fR may have any of the forms allowed for the \fIsequence\fR
argument of the \fBbind\fR command except that it must consist
of a single event pattern, not a sequence.
\fIOption-value\fR pairs may be used to specify additional
attributes of the event, such as the x and y mouse position;  see
\fBEVENT FIELDS\fR below.  If the \fB\-when\fR option is not specified, the
event is processed immediately:  all of the handlers for the event
will complete before the \fBevent generate\fR command returns.
If the \fB\-when\fR option is specified then it determines when the
event is processed.  Certain events, such as key events, require
that the window has focus to receive the event properly.
.\" METHOD: info
.TP
\fBevent info \fR?\fB<<\fIvirtual\fB>>\fR?
.
Returns information about virtual events.
If the \fB<<\fIvirtual\fB>>\fR argument is omitted, the return value
is a list of all the virtual events that are currently defined.
If \fB<<\fIvirtual\fB>>\fR is specified then the return value is
a list whose elements are the physical event sequences currently
defined for the given virtual event;  if the virtual event is
not defined then an empty string is returned.
.RS
.PP
Note that virtual events that are not bound to physical event
sequences are \fInot\fR returned by \fBevent info\fR.
.RE
.SH "EVENT FIELDS"
.PP
The following options are supported for the \fBevent generate\fR
command.  These correspond to the
.QW %
expansions allowed in binding scripts for the \fBbind\fR command.
.\" OPTION: -above
.TP
\fB\-above\fI window\fR
.
\fIWindow\fR specifies the \fIabove\fR field for the event,
either as a window path name or as an integer window id.
Valid for \fBConfigure\fR events.
Corresponds to the \fB%a\fR substitution for binding scripts.
.\" OPTION: -borderwidth
.TP
\fB\-borderwidth\fI size\fR
.
\fISize\fR must be a screen distance;  it specifies the
\fIborder_width\fR field for the event.
Valid for \fBConfigure\fR events.
Corresponds to the \fB%B\fR substitution for binding scripts.
.\" OPTION: -button
.TP
\fB\-button\fI number\fR
.
\fINumber\fR must be an integer;  it specifies the \fIdetail\fR field
for a \fBButton\fR or \fBButtonRelease\fR event, overriding
for a \fBButtonPress\fR or \fBButtonRelease\fR event, overriding
any button  number provided in the base \fIevent\fR argument.
Corresponds to the \fB%b\fR substitution for binding scripts.
.\" OPTION: -count
.TP
\fB\-count\fI number\fR
.
\fINumber\fR must be an integer;  it specifies the \fIcount\fR field
for the event.  Valid for \fBExpose\fR events.
Corresponds to the \fB%c\fR substitution for binding scripts.
.\" OPTION: -data
.TP
\fB\-data\fI string\fR
.
\fIString\fR may be any value; it specifies the \fIuser_data\fR field
for the event.  Only valid for virtual events.  Corresponds to the
\fB%d\fR substitution for virtual events in binding scripts.
.\" OPTION: -delta
.TP
\fB\-delta\fI number\fR
.
\fINumber\fR must be an integer;  it specifies the \fIdelta\fR field
for the \fBMouseWheel\fR event.  The \fIdelta\fR refers to the
direction and magnitude the mouse wheel was rotated.  Note the value
is not a screen distance but are units of motion in the mouse wheel.
Typically these values are multiples of 120.  For example, 120 should
scroll the text widget up 4 lines and \-240 would scroll the text
widget down 8 lines.  Of course, other widgets may define different
behaviors for mouse wheel motion.  This field corresponds to the
\fB%D\fR substitution for binding scripts.
.\" OPTION: -detail
.TP
\fB\-detail\fI detail\fR
.
\fIDetail\fR specifies the \fIdetail\fR field for the event
and must be one of the following:
.RS
.DS
.ta 6c
\fBNotifyAncestor\fR	\fBNotifyNonlinearVirtual\fR
\fBNotifyDetailNone\fR	\fBNotifyPointer\fR
\fBNotifyInferior\fR	\fBNotifyPointerRoot\fR
\fBNotifyNonlinear\fR	\fBNotifyVirtual\fR
.DE
Valid for \fBEnter\fR, \fBLeave\fR, \fBFocusIn\fR and
\fBFocusOut\fR events.
Corresponds to the \fB%d\fR substitution for binding scripts.
.RE
.\" OPTION: -focus
.TP
\fB\-focus\fI boolean\fR
.
\fIBoolean\fR must be a boolean value;  it specifies the \fIfocus\fR
field for the event.
Valid for \fBEnter\fR and \fBLeave\fR events.
Corresponds to the \fB%f\fR substitution for binding scripts.
.\" OPTION: -height
.TP
\fB\-height\fI size\fR
.
\fISize\fR must be a screen distance;  it specifies the \fIheight\fR
field for the event.  Valid for \fBConfigure\fR events.
Corresponds to the \fB%h\fR substitution for binding scripts.
.\" OPTION: -keycode
.TP
\fB\-keycode\fI number\fR
.
\fINumber\fR  must be an integer;  it specifies the \fIkeycode\fR
field for the event.
Valid for \fBKey\fR and \fBKeyRelease\fR events.
Valid for \fBKeyPress\fR and \fBKeyRelease\fR events.
Corresponds to the \fB%k\fR substitution for binding scripts.
.\" OPTION: -keysym
.TP
\fB\-keysym\fI name\fR
.
\fIName\fR must be the name of a valid keysym, such as \fBg\fR,
\fBspace\fR, or \fBReturn\fR;  its corresponding
keycode value is used as the \fIkeycode\fR field for event, overriding
any detail specified in the base \fIevent\fR argument.
Valid for \fBKey\fR and \fBKeyRelease\fR events.
Valid for \fBKeyPress\fR and \fBKeyRelease\fR events.
Corresponds to the \fB%K\fR substitution for binding scripts.
.\" OPTION: -mode
.TP
\fB\-mode\fI notify\fR
.
\fINotify\fR specifies the \fImode\fR field for the event and must be
one of \fBNotifyNormal\fR, \fBNotifyGrab\fR, \fBNotifyUngrab\fR, or
\fBNotifyWhileGrabbed\fR.
Valid for \fBEnter\fR, \fBLeave\fR, \fBFocusIn\fR, and
\fBFocusOut\fR events.
Corresponds to the \fB%m\fR substitution for binding scripts.
.\" OPTION: -override
.TP
\fB\-override\fI boolean\fR
.
\fIBoolean\fR must be a boolean value;  it specifies the
\fIoverride_redirect\fR field for the event.
Valid for \fBMap\fR, \fBReparent\fR, and \fBConfigure\fR events.
Corresponds to the \fB%o\fR substitution for binding scripts.
.\" OPTION: -place
.TP
\fB\-place\fI where\fR
.
\fIWhere\fR specifies the \fIplace\fR field for the event;  it must be
either \fBPlaceOnTop\fR or \fBPlaceOnBottom\fR.
Valid for \fBCirculate\fR events.
Corresponds to the \fB%p\fR substitution for binding scripts.
.\" OPTION: -root
.TP
\fB\-root\fI window\fR
.
\fIWindow\fR must be either a window path name or an integer window
identifier;  it specifies the \fIroot\fR field for the event.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR
events.
Corresponds to the \fB%R\fR substitution for binding scripts.
.\" OPTION: -rootx
.TP
\fB\-rootx\fI coord\fR
.
\fICoord\fR must be a screen distance;  it specifies the \fIx_root\fR
field for the event.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR
events.  Corresponds to the \fB%X\fR substitution for binding scripts.
.\" OPTION: -rooty
.TP
\fB\-rooty\fI coord\fR
.
\fICoord\fR must be a screen distance;  it specifies the \fIy_root\fR
field for the event.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR
events.
Corresponds to the \fB%Y\fR substitution for binding scripts.
.\" OPTION: -sendevent
.TP
\fB\-sendevent\fI boolean\fR
.
\fIBoolean\fR must be a boolean value;  it specifies the \fIsend_event\fR
field for the event.  Valid for all events.  Corresponds to the
\fB%E\fR substitution for binding scripts.
.\" OPTION: -serial
.TP
\fB\-serial\fI number\fR
.
\fINumber\fR must be an integer;  it specifies the \fIserial\fR field
for the event.  Valid for all events.
Corresponds to the \fB%#\fR substitution for binding scripts.
.\" OPTION: -state
.TP
\fB\-state\fI state\fR
.
\fIState\fR specifies the \fIstate\fR field for the event.
For \fBKey\fR, \fBKeyRelease\fR, \fBButtons\fR,
For \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR events
it must be an integer value.
For \fBVisibility\fR events it must be one of \fBVisibilityUnobscured\fR,
\fBVisibilityPartiallyObscured\fR, or \fBVisibilityFullyObscured\fR.
This option overrides any modifiers such as \fBMeta\fR or \fBControl\fR
specified in the base \fIevent\fR.
Corresponds to the \fB%s\fR substitution for binding scripts.
.\" OPTION: -subwindow
.TP
\fB\-subwindow\fI window\fR
.
\fIWindow\fR specifies the \fIsubwindow\fR field for the event, either
as a path name for a Tk widget or as an integer window identifier.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR events.
Similar to \fB%S\fR substitution for binding scripts.
.\" OPTION: -time
.TP
\fB\-time\fI integer\fR
.
\fIInteger\fR must be an integer value;  it specifies the \fItime\fR field
for the event. Additionally, the special value \fBcurrent\fR is allowed;
for the event.
this value will be substituted by the current event time.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, \fBMotion\fR,
and \fBProperty\fR events.
Corresponds to the \fB%t\fR substitution for binding scripts.
.\" OPTION: -warp
.TP
\fB\-warp\fI boolean\fR
.
\fIboolean\fR must be a boolean value;  it specifies whether
the screen pointer should be warped as well.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, and \fBMotion\fR events.  The pointer will
only warp to a window if it is mapped.
.\" OPTION: -width
.TP
\fB\-width\fI size\fR
.
\fISize\fR must be a screen distance;  it specifies the \fIwidth\fR field
for the event.
Valid for \fBConfigure\fR events.
Corresponds to the \fB%w\fR substitution for binding scripts.
.\" OPTION: -when
.TP
\fB\-when\fI when\fR
.
\fIWhen\fR determines when the event will be processed;  it must have one
of the following values:
.RS
.IP \fBnow\fR 10
Process the event immediately, before the command returns.
This also happens if the \fB\-when\fR option is omitted.
.IP \fBtail\fR 10
Place the event on Tcl's event queue behind any events already
queued for this application.
.IP \fBhead\fR 10
Place the event at the front of Tcl's event queue, so that it
will be handled before any other events already queued.
.IP \fBmark\fR 10
Place the event at the front of Tcl's event queue but behind any
other events already queued with \fB\-when mark\fR.
This option is useful when generating a series of events that should
be processed in order but at the front of the queue.
.RE
.\" OPTION: -x
.TP
\fB\-x\fI coord\fR
.
\fICoord\fR must be a screen distance;  it specifies the \fIx\fR field
for the event.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBMotion\fR, \fBEnter\fR, \fBLeave\fR,
\fBExpose\fR, \fBConfigure\fR, \fBGravity\fR, and \fBReparent\fR
events.
Corresponds to the \fB%x\fR substitution for binding scripts.
If \fIWindow\fR is empty the coordinate is relative to the
screen, and this option corresponds to the \fB%X\fR substitution
for binding scripts.
.\" OPTION: -y
.TP
\fB\-y\fI coord\fR
.
\fICoord\fR must be a screen distance;  it specifies the \fIy\fR
field for the event.
Valid for \fBKey\fR, \fBKeyRelease\fR, \fBButton\fR,
Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,
\fBButtonRelease\fR, \fBMotion\fR, \fBEnter\fR, \fBLeave\fR,
\fBExpose\fR, \fBConfigure\fR, \fBGravity\fR, and \fBReparent\fR
events.
Corresponds to the \fB%y\fR substitution for binding scripts.
If \fIWindow\fR is empty the coordinate is relative to the
screen, and this option corresponds to the \fB%Y\fR substitution
for binding scripts.
.PP
Any options that are not specified when generating an event are filled
with the value 0, except for \fIserial\fR, which is filled with the
next X event serial number.
.SH "PREDEFINED VIRTUAL EVENTS"
.PP
Tk defines the following virtual events for the purposes of
notification:
.TP
\fB<<AltUnderlined>>\fR
.
This is sent to widget to notify it that the letter it has underlined
(as an accelerator indicator) with the \fB\-underline\fR option has
been pressed in combination with the Alt key. The usual response to
this is to either focus into the widget (or some related widget) or to
invoke the widget.
.TP
\fB<<Invoke>>\fR
.
This can be sent to some widgets (e.g. button, listbox, menu) as an
alternative to <space>.
.TP
\fB<<ListboxSelect>>\fR
.
This is sent to a listbox when the set of selected item(s) in the
listbox is updated.
.TP
\fB<<MenuSelect>>\fR
.
This is sent to a menu when the currently selected item in the menu
changes. It is intended for use with context-sensitive help systems.
.TP
\fB<<Modified>>\fR
.
This is sent to a text widget when the contents of the widget are
changed.
.TP
\fB<<Selection>>\fR
.
This is sent to a text widget when the selection in the widget is
changed.
.TP
\fB<<ThemeChanged>>\fR
.
This is sent to all widgets when the ttk theme changed. The ttk
This is sent to a text widget when the ttk (Tile) theme changed.
widgets listen to this event and redisplay themselves when it fires.
The legacy widgets ignore this event.
.TP
\fB<<TkWorldChanged>>\fR
.
This event is sent to all widgets when a font is changed, for example,
by the use of [font configure].  The user_data field (%d) will have the
value "FontChanged".  For other system wide changes, this event will
be sent to all widgets, and the user_data field will indicate the
cause of the change.  NOTE: all tk and ttk widgets already handle this
event internally.
.TP
\fB<<TraverseIn>>\fR
.
This is sent to a widget when the focus enters the widget because of a
user-driven
.QW "tab to widget"
action.
.TP
\fB<<TraverseOut>>\fR
.
This is sent to a widget when the focus leaves the widget because of a
user-driven
.QW "tab to widget"
action.
.TP
\fB<<UndoStack>>\fR
.
This is sent to a text widget when its undo stack or redo stack becomes
empty or unempty.
.TP
\fB<<WidgetViewSync>>\fR
.
This is sent to a text widget when its internal data become obsolete,
and again when these internal data are back in sync with the widget
view. The detail field (%d substitution) is either true (when the
widget is in sync) or false (when it is not).
.PP
Tk defines the following virtual events for the purposes of unifying
bindings across multiple platforms. Users expect them to behave in the
following way:
.TP
\fB<<Clear>>\fR
.
Delete the currently selected widget contents.
.TP
\fB<<Copy>>\fR
.
Copy the currently selected widget contents to the clipboard.
.TP
\fB<<Cut>>\fR
.
Move the currently selected widget contents to the clipboard.
.TP
\fB<<LineEnd>>\fR
.
Move to the end of the line in the current widget while deselecting any
selected contents.
.TP
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
402
403
404
405
406
407
408

409
410
411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

432
433
434
435
436
437
438
439

440
441
442
443
444
445
446







-




-



















-








-







.TP
\fB<<NextWord>>\fR
.
Move to the next group of items (i.e., visible word) in the current widget
while deselecting any selected contents.
.TP
\fB<<Paste>>\fR
.
Replace the currently selected widget contents with the contents of
the clipboard.
.TP
\fB<<PasteSelection>>\fR
.
Insert the contents of the selection at the mouse location. (This
event has meaningful \fB%x\fR and \fB%y\fR substitutions).
.TP
\fB<<PrevChar>>\fR
.
Move to the previous item (i.e., visible character) in the current widget
while deselecting any selected contents.
.TP
\fB<<PrevLine>>\fR
.
Move to the previous line in the current widget while deselecting any selected
contents.
.TP
\fB<<PrevPara>>\fR
.
Move to the previous paragraph in the current widget while deselecting any
selected contents.
.TP
\fB<<PrevWindow>>\fR
.
Traverse to the previous window.
.TP
\fB<<PrevWord>>\fR
.
Move to the previous group of items (i.e., visible word) in the current widget
while deselecting any selected contents.
.TP
\fB<<Redo>>\fR
.
Redo one undone action.
.TP
\fB<<SelectAll>>\fR
.
Set the range of selected contents to the complete widget.
.TP
\fB<<SelectLineEnd>>\fR
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
561
562
563
564
565
566
567

568
569
570
571
572
573
574
575







-
+







.PP
When a definition of a virtual event changes at run time, all windows
will respond immediately to the new definition.
Starting from the preceding example, if the following code is executed:
.PP
.CS
bind Entry <Control-y> {}
\fBevent add\fR <<Paste>> <F6>
\fBevent add\fR <<Paste>> <Key-F6>
.CE
.PP
the behavior will change such in two ways.  First, the shadowed
\fB<<Paste>>\fR binding will emerge.
Typing Control-y will no longer invoke the \fB<Control-y>\fR binding,
but instead invoke the virtual event \fB<<Paste>>\fR.  Second,
pressing the F6 key will now also invoke the \fB<<Paste>>\fR binding.

Changes to doc/focus.n.

11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25







-
+







'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
focus \- Manage the input focus
.SH SYNOPSIS
.nf
\fBfocus\fR
\fBfocus \fIwindow\fR
\fBfocus \fIoption\fR ?\fIarg ...\fR?
\fBfocus \fIoption\fR ?\fIarg arg ...\fR?
.fi
.BE
.SH DESCRIPTION
.PP
The \fBfocus\fR command is used to manage the Tk input focus.
At any given time, one window on each display is designated as
the \fIfocus window\fR;  any key press or key release events for the
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74

75

76
77
78
79
80

81
82
83
84
85
86
87
88

89

90
91
92
93
94
95
96







-








-









-
+
-





-








-
+
-







implement a focus order among the windows of a top-level;  they
are used in the default bindings for Tab and Shift-Tab, among other
things.
.PP
The \fBfocus\fR command can take any of the following forms:
.TP
\fBfocus\fR
.
Returns the path name of the focus window on the display containing
the application's main window,  or an empty string if no window in
this application has the focus on that display.   Note:  it is
better to specify the display explicitly using \fB\-displayof\fR
(see below) so that the code will work in applications using multiple
displays.
.TP
\fBfocus \fIwindow\fR
.
If the application currently has the input focus on \fIwindow\fR's
display, this command resets the input focus for \fIwindow\fR's display
to \fIwindow\fR and returns an empty string.
If the application does not currently have the input focus on
\fIwindow\fR's display, \fIwindow\fR will be remembered as the focus
for its top-level;  the next time the focus arrives at the top-level,
Tk will redirect it to \fIwindow\fR.
If \fIwindow\fR is an empty string then the command does nothing.
.TP
\fBfocus \-displayof \fIwindow\fR
\fBfocus \-displayof\fR \fIwindow\fR
.
Returns the name of the focus window on the display containing \fIwindow\fR.
If the focus window for \fIwindow\fR's display is not in this
application, the return value is an empty string.
.TP
\fBfocus \-force \fIwindow\fR
.
Sets the focus of \fIwindow\fR's display to \fIwindow\fR, even if
the application does not currently have the input focus for the display.
This command should be used sparingly, if at all.
In normal usage, an application should not claim the focus for
itself;  instead, it should wait for the window manager to give it
the focus.
If \fIwindow\fR is an empty string then the command does nothing.
.TP
\fBfocus \-lastfor \fIwindow\fR
\fBfocus \-lastfor\fR \fIwindow\fR
.
Returns the name of the most recent window to have the input focus
among all the windows in the same top-level as \fIwindow\fR.
If no window in that top-level has ever had the input focus, or
if the most recent focus window has been deleted, then the name
of the top-level is returned.  The return value is the window that
will receive the input focus the next time the window manager gives
the focus to the top-level.
110
111
112
113
114
115
116
117
118
119
120
121
122
123





124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
105
106
107
108
109
110
111

112





113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137







-

-
-
-
-
-
+
+
+
+
+







-
+












the fact that the X focus is on the top-level is invisible unless
you use C code to query the X server directly.
.SH "EXAMPLE"
.PP
To make a window that only participates in the focus traversal ring
when a variable is set, add the following bindings to the widgets
\fIbefore\fR and \fIafter\fR it in that focus ring:
.PP
.CS
button .before -text "Before"
button .middle -text "Middle"
button .after  -text "After"
checkbutton .flag -variable traverseToMiddle -takefocus 0
pack .flag -side left
button .before \-text "Before"
button .middle \-text "Middle"
button .after  \-text "After"
checkbutton .flag \-variable traverseToMiddle \-takefocus 0
pack .flag \-side left
pack .before .middle .after
bind .before <Tab> {
   if {!$traverseToMiddle} {
      \fBfocus\fR .after
      break
   }
}
bind .after <Shift-Tab> {
bind .after <Shift\-Tab> {
   if {!$traverseToMiddle} {
      \fBfocus\fR .before
      break
   }
}
\fBfocus\fR .before
.CE
.SH KEYWORDS
events, focus, keyboard, top-level, window manager
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/focusNext.n.

8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24
25
26
8
9
10
11
12
13
14

15
16
17
18
19

20
21
22
23
24
25
26







-

+

+

-







.TH tk_focusNext n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk_focusNext, tk_focusPrev, tk_focusFollowsMouse \- Utility procedures for managing the input focus.
.SH SYNOPSIS
.nf
\fBtk_focusNext \fIwindow\fR
.sp
\fBtk_focusPrev \fIwindow\fR
.sp
\fBtk_focusFollowsMouse\fR
.fi
.BE
.SH DESCRIPTION
.PP
\fBtk_focusNext\fR is a utility procedure used for keyboard traversal.
It returns the
.QW next
window after \fIwindow\fR in focus order. The focus order is determined by
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
45
46
47
48
49
50
51


52
53
54
55
56
57
58
59
60







-
-
+








\fBtk_focusFollowsMouse\fR changes the focus model for the application
to an implicit one where the window under the mouse gets the focus.
After this procedure is called, whenever the mouse enters a window
Tk will automatically give it the input focus.
The \fBfocus\fR command may be used to move the focus to a window
other than the one under the mouse, but as soon as the mouse moves
into a new window the focus will jump to that window.
.PP
Note that at present there is no built-in support for returning the
Note: at present there is no built-in support for returning the
application to an explicit focus model;  to do this you will have
to write a script that deletes the bindings created by
\fBtk_focusFollowsMouse\fR.
.SH KEYWORDS
focus, keyboard traversal, top-level
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/font.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69

70

71
72
73
74
75
76
77
78

79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109

110
111

112
113
114
115
116
117
118







-
+







-


















-




















-









-

-
+







-






-














-











-


-







.TH font n 8.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
font \- Create and inspect fonts.
.SH SYNOPSIS
\fBfont\fI option \fR?\fIarg ...\fR?
\fBfont\fI option \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBfont\fR command provides several facilities for dealing with
fonts, such as defining named fonts and inspecting the actual attributes of
a font.  The command has several different forms, determined by the
first argument.  The following forms are currently supported:
.\" METHOD: actual
.TP
\fBfont actual \fIfont\fR ?\fB\-displayof \fIwindow\fR? ?\fIoption\fR? ?\fB\-\|\-\fR? ?\fIchar\fR?
.
Returns information about the actual attributes that are obtained when
\fIfont\fR is used on \fIwindow\fR's display; the actual attributes obtained
may differ from the attributes requested due to platform-dependent
limitations, such as the availability of font families and point sizes.
\fIfont\fR is a font description; see \fBFONT DESCRIPTIONS\fR below.  If the
\fIwindow\fR argument is omitted, it defaults to the main window.  If
\fIoption\fR is specified, returns the value of that attribute; if it is
omitted, the return value is a list of all the attributes and their values.
See \fBFONT OPTIONS\fR below for a list of the possible attributes.  If the
\fIchar\fR argument is supplied, it must be a single character. The font
attributes returned will be those of the specific font used to render
that character, which will be different from the base font if the base
font does not contain the given character.  If \fIchar\fR may be a hyphen, it
should be preceded by \fB\-\|\-\fR to distinguish it from a misspelled
\fIoption\fR.
.\" METHOD: configure
.TP
\fBfont configure \fIfontname\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the desired attributes for the named font called
\fIfontname\fR.  If no \fIoption\fR is specified, returns a list describing
all the options and their values for \fIfontname\fR.  If a single \fIoption\fR
is specified with no \fIvalue\fR, then returns the current value of that
attribute.  If one or more \fIoption\fR\-\fIvalue\fR pairs are specified,
then the command modifies the given named font to have the given values; in
this case, all widgets using that font will redisplay themselves using the
new attributes for the font.  See \fBFONT OPTIONS\fR below for a list of the
possible attributes.
.RS
.PP
Note that on Aqua/Mac OS X, the system fonts (see
\fBPLATFORM SPECIFIC FONTS\fR below) may not be actually altered because they
are implemented by the system theme. To achieve the effect of modification,
use \fBfont actual\fR to get their configuration and \fBfont create\fR to
synthesize a copy of the font which can be modified.
.RE
.\" METHOD: create
.TP
\fBfont create\fR ?\fIfontname\fR? ?\fIoption value ...\fR?
.
Creates a new named font and returns its name.  \fIfontname\fR specifies the
name for the font; if it is omitted, then Tk generates a new name of the
form \fBfont\fIx\fR, where \fIx\fR is an integer.  There may be any number
of \fIoption\fR\-\fIvalue\fR pairs, which provide the desired attributes for
the new named font.  See \fBFONT OPTIONS\fR below for a list of the possible
attributes.
.\" METHOD: delete
.TP
\fBfont delete\fI fontname\fR ?\fIfontname ...\fR?
\fBfont delete\fR \fIfontname\fR ?\fIfontname ...\fR?
.
Delete the specified named fonts.  If there are widgets using the named font,
the named font will not actually be deleted until all the instances are
released.  Those widgets will continue to display using the last known values
for the named font.  If a deleted named font is subsequently recreated with
another call to \fBfont create\fR, the widgets will use the new named font
and redisplay themselves using the new attributes of that font.
.\" METHOD: families
.TP
\fBfont families\fR ?\fB\-displayof \fIwindow\fR?
.
The return value is a list of the case-insensitive names of all font families
that exist on \fIwindow\fR's display.  If the \fIwindow\fR argument is
omitted, it defaults to the main window.
.\" METHOD: measure
.TP
\fBfont measure \fIfont\fR ?\fB\-displayof \fIwindow\fR? \fItext\fR
.
Measures the amount of space the string \fItext\fR would use in the given
\fIfont\fR when displayed in \fIwindow\fR.  \fIfont\fR is a font description;
see \fBFONT DESCRIPTIONS\fR below.  If the \fIwindow\fR argument is
omitted, it
defaults to the main window.  The return value is the total width in pixels
of \fItext\fR, not including the extra pixels used by highly exaggerated
characters such as cursive
.QW f .
If the string contains newlines or tabs,
those characters are not expanded or treated specially when measuring the
string.
.\" METHOD: metrics
.TP
\fBfont metrics \fIfont\fR ?\fB\-displayof \fIwindow\fR? ?\fIoption\fR?
.
Returns information about the metrics (the font-specific data), for
\fIfont\fR when it is used on \fIwindow\fR's display.  \fIfont\fR is a font
description; see \fBFONT DESCRIPTIONS\fR below.  If the \fIwindow\fR
argument is
omitted, it defaults to the main window.  If \fIoption\fR is specified,
returns the value of that metric; if it is omitted, the return value is a
list of all the metrics and their values.  See \fBFONT METRICS\fR
below for a list of the possible metrics.
.\" METHOD: names
.TP
\fBfont names\fR
.
The return value is a list of all the named fonts that are currently defined.
.SH "FONT DESCRIPTIONS"
.PP
The following formats are accepted as a font description anywhere
\fIfont\fR is specified as an argument above; these same forms are also
permitted when specifying the \fB\-font\fR option for widgets.
.TP
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

323


324

325


326

327


328

329


330

331


332

333


334

335


336

337


338

339


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
196
197
198
199
200
201
202

203

204
205
206
207

208

209
210
211
212

213
214
215
216
217
218
219

220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279

280
281

282
283
284
285
286
287

288
289

290
291

292
293

294
295
296
297
298
299
300
301

302
303
304
305

306
307
308
309

310
311
312
313

314
315
316
317

318
319
320
321

322
323
324
325

326
327
328
329

330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345

346
347
348

349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366







-

-
+



-

-
+



-







-

-
+
















-
















-



















-







-


-






-


-


-


-







+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+










-



-











-







font.  In the following definitions, the
.QW baseline
of a font is the
horizontal line where the bottom of most letters line up; certain letters,
such as lower-case
.QW g
stick below the baseline.
.\" OPTION: -ascent
.TP
\fB\-ascent\fR
\fB\-ascent        \0\fR
.
The amount in pixels that the tallest letter sticks up above the baseline of
the font, plus any extra blank space added by the designer of the font.
.\" OPTION: -descent
.TP
\fB\-descent\fR
\fB\-descent       \0\fR
.
The largest amount in pixels that any letter sticks down below the baseline
of the font, plus any extra blank space added by the designer of the font.
.\" OPTION: -linespace
.TP
\fB\-linespace\fR
.
Returns how far apart vertically in pixels two lines of text using the same
font should be placed so that none of the characters in one line overlap any
of the characters in the other line.  This is generally the sum of the ascent
above the baseline line plus the descent below the baseline.
.\" OPTION: -fixed
.TP
\fB\-fixed\fR
\fB\-fixed          \0\fR
.
Returns a boolean flag that is
.QW \fB1\fR
if this is a fixed-width font,
where each normal character is the same width as all the other
characters, or is
.QW \fB0\fR
if this is a proportionally-spaced font, where
individual characters have different widths.  The widths of control
characters, tab characters, and other non-printing characters are not
included when calculating this value.
.SH "FONT OPTIONS"
.PP
The following options are supported on all platforms, and are used when
constructing a named font or when specifying a font using style [5] as
above:
.\" OPTION: -family
.TP
\fB\-family \fIname\fR
.
The case-insensitive font family name.  Tk guarantees to support the font
families named \fBCourier\fR (a monospaced
.QW typewriter
font), \fBTimes\fR (a serifed
.QW newspaper
font), and \fBHelvetica\fR (a sans-serif
.QW European
font).  The most closely matching native font family will
automatically be substituted when one of the above font families is used.
The \fIname\fR may also be the name of a native, platform-specific font
family; in that case it will work as desired on one platform but may not
display correctly on other platforms.  If the family is unspecified or
unrecognized, a platform-specific default font will be chosen.
.\" OPTION: -size
.TP
\fB\-size \fIsize\fR
.
The desired size of the font.  If the \fIsize\fR argument is a positive
number, it is interpreted as a size in points.  If \fIsize\fR is a negative
number, its absolute value is interpreted as a size in pixels.  If a
font cannot be displayed at the specified size, a nearby size will be
chosen.  If \fIsize\fR is unspecified or zero, a platform-dependent default
size will be chosen.
.RS
.PP
Sizes should normally be specified in points so the application will remain
the same ruler size on the screen, even when changing screen resolutions or
moving scripts across platforms.  However, specifying pixels is useful in
certain circumstances such as when a piece of text must line up with respect
to a fixed-size bitmap.  The mapping between points and pixels is set when
the application starts, based on properties of the installed monitor, but it
can be overridden by calling the \fBtk scaling\fR command.
.RE
.\" OPTION: -weight
.TP
\fB\-weight \fIweight\fR
.
The nominal thickness of the characters in the font.  The value
\fBnormal\fR specifies a normal weight font, while \fBbold\fR specifies a
bold font.  The closest available weight to the one specified will
be chosen.  The default weight is \fBnormal\fR.
.\" OPTION: -slant
.TP
\fB\-slant \fIslant\fR
.
The amount the characters in the font are slanted away from the
vertical.  Valid values for slant are \fBroman\fR and \fBitalic\fR.
A roman font is the normal, upright appearance of a font, while
an italic font is one that is tilted some number of degrees from upright.
The closest available slant to the one specified will be chosen.
The default slant is \fBroman\fR.
.\" OPTION: -underline
.TP
\fB\-underline \fIboolean\fR
.
The value is a boolean flag that specifies whether characters in this
font should be underlined.  The default value for underline is \fBfalse\fR.
.\" OPTION: -overstrike
.TP
\fB\-overstrike \fIboolean\fR
.
The value is a boolean flag that specifies whether a horizontal line should
be drawn through the middle of characters in this font.  The default value
for overstrike is \fBfalse\fR.
.SH "STANDARD FONTS"
.PP
The following named fonts are supported on all systems, and default to values
that match appropriate system defaults.
.TP
.IP \fBTkDefaultFont\fR
\fBTkDefaultFont\fR
.
This font is the default for all GUI items not otherwise specified.
.TP
.IP \fBTkTextFont\fR
\fBTkTextFont\fR
.
This font should be used for user text in entry widgets, listboxes etc.
.TP
.IP \fBTkFixedFont\fR
\fBTkFixedFont\fR
.
This font is the standard fixed-width font.
.TP
.IP \fBTkMenuFont\fR
\fBTkMenuFont\fR
.
This font is used for menu items.
.TP
.IP \fBTkHeadingFont\fR
\fBTkHeadingFont\fR
.
This font should be used for column headings in lists and tables.
.TP
.IP \fBTkCaptionFont\fR
\fBTkCaptionFont\fR
.
This font should be used for window and dialog caption bars.
.TP
.IP \fBTkSmallCaptionFont\fR
\fBTkSmallCaptionFont\fR
.
This font should be used for captions on contained windows or tool dialogs.
.TP
.IP \fBTkIconFont\fR
\fBTkIconFont\fR
.
This font should be used for icon captions.
.TP
.IP \fBTkTooltipFont\fR
\fBTkTooltipFont\fR
.
This font should be used for tooltip windows (transient information windows).
.LP
It is \fInot\fR advised to change these fonts, as they may be modified by Tk
itself in response to system changes. Instead, make a copy of the font and
modify that.
.SH "PLATFORM SPECIFIC FONTS"
.PP
The following system fonts are supported:
.TP
\fBX Windows\fR
.
All valid X font names, including those listed by xlsfonts(1), are available.
.TP
\fBMS Windows\fR
.
The following fonts are supported, and are mapped to the user's
style defaults.
.RS
.DS
.ta 3c 6c
\fBsystem\fR	\fBansi\fR	\fBdevice\fR
\fBsystemfixed\fR	\fBansifixed\fR	\fBoemfixed\fR
.DE
.RE
.TP
\fBMac OS X\fR
.
The following fonts are supported, and are mapped to the user's
style defaults.
.RS
.DS
.ta 3c 6c
\fBsystem\fR	\fBapplication\fR	\fBmenu\fR
.DE
389
390
391
392
393
394
395
396

397
398
399
400
401



402
403
404
405
406




407
408
409
410
411
412
413
414
415
416
382
383
384
385
386
387
388

389
390
391



392
393
394
395




396
397
398
399
400
401
402
403
404
405
406
407
408
409







-
+


-
-
-
+
+
+

-
-
-
-
+
+
+
+










.DE
.RE
.SH EXAMPLE
.PP
Fill a text widget with lots of font demonstrators, one for every font
family installed on your system:
.CS
pack [text .t -wrap none] -fill both -expand 1
pack [text .t \-wrap none] \-fill both \-expand 1
set count 0
set tabwidth 0
foreach family [lsort -dictionary [\fBfont families\fR]] {
    .t tag configure f[incr count] -font [list $family 10]
    .t insert end ${family}:\et {} \e
foreach family [lsort \-dictionary [\fBfont families\fR]] {
    .t tag configure f[incr count] \-font [list $family 10]
    .t insert end ${family}:\\t {} \e
            "This is a simple sampler\en" f$count
    set w [\fBfont measure\fR [.t cget -font] ${family}:]
    if {$w + 5 > $tabwidth} {
        set tabwidth [expr {$w + 5}]
        .t configure -tabs $tabwidth
    set w [\fBfont measure\fR [.t cget \-font] ${family}:]
    if {$w+5 > $tabwidth} {
        set tabwidth [expr {$w+5}]
        .t configure \-tabs $tabwidth
    }
}
.CE
.SH "SEE ALSO"
options(n)
.SH KEYWORDS
font
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/fontchooser.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32

33

34
35
36
37

38
39
40
41
42

43
44
45
46
47
48
49

50
51

52
53
54

55
56

57
58

59
60

61
62
63
64
65

66
67

68
69
70
71
72
73
74
75
76

77
78

79
80
81
82
83
84
85

86
87
88
89
90
91
92
93

94
95
96
97
98
99
100













-
-
+
+

+

-














-

-
+



-





-







-


-



-


-


-


-





-


-









-


-







-








-







'\"
'\" Copyright (c) 2008 Daniel A. Steffen <[email protected]>
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH fontchooser n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
fontchooser \- control font selection dialog
.SH SYNOPSIS
.nf
\fBtk fontchooser\fR \fBconfigure\fR ?\fI\-option value ...\fR?
\fBtk fontchooser\fR \fBconfigure\fR ?\fI\-option value \-option value ...\fR?
.sp
\fBtk fontchooser\fR \fBshow\fR
.sp
\fBtk fontchooser\fR \fBhide\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBtk fontchooser\fR command controls the Tk font selection dialog. It uses
the native platform font selection dialog where available, or a dialog
implemented in Tcl otherwise.
.PP
Unlike most of the other Tk dialog commands, \fBtk fontchooser\fR does not
return an immediate result, as on some platforms (Mac OS X) the standard font
dialog is modeless while on others (Windows) it is modal. To accommodate this
difference, all user interaction with the dialog will be communicated to the
caller via callbacks or virtual events.
.PP
The \fBtk fontchooser\fR command can have one of the following forms:
.\" METHOD: configure
.TP
\fBtk fontchooser\fR \fBconfigure \fR?\fI\-option value ...\fR?
\fBtk fontchooser\fR \fBconfigure \fR?\fI\-option value \-option value ...\fR?
.
Set or query one or more of the configurations options below (analogous to Tk
widget configuration).
.\" METHOD: show
.TP
\fBtk fontchooser\fR \fBshow\fR
.
Show the font selection dialog. Depending on the platform, may return
immediately or only once the dialog has been withdrawn.
.\" METHOD: hide
.TP
\fBtk fontchooser\fR \fBhide\fR
.
Hide the font selection dialog if it is visible and cause any pending
\fBtk fontchooser\fR \fBshow\fR command to return.
.PP
.SH "CONFIGURATION OPTIONS"
.\" OPTION: -parent
.TP
\fB\-parent\fR
.
Specifies/returns the logical parent window of the font selection dialog
(similar to the \fB\-parent\fR option to other dialogs). The font selection
dialog is hidden if it is visible when the parent window is destroyed.
.\" OPTION: -title
.TP
\fB\-title\fR
.
Specifies/returns the title of the dialog. Has no effect on platforms where the
font selection dialog does not support titles.
.\" OPTION: -font
.TP
\fB\-font\fR
.
Specifies/returns the font that is currently selected in the dialog if it is
visible, or that will be initially selected when the dialog is shown (if
supported by the platform). Can be set to the empty string to indicate that no
font should be selected. Fonts can be specified in any form given by the "FONT
DESCRIPTION" section in the \fBfont\fR manual page.
.\" OPTION: -command
.TP
\fB\-command\fR
.
Specifies/returns the command prefix to be called when a font selection has
been made by the user. The command prefix is evaluated at the global level
after having the specification of the selected font appended. On platforms
where the font selection dialog offers the user control of further font
attributes (such as color), additional key/value pairs may be appended before
evaluation. Can be set to the empty string to indicate that no callback should
be invoked. Fonts are specified by a list of form [3] of the "FONT DESCRIPTION"
section in the \fBfont\fR manual page (i.e. a list of the form
\fI{family size style ?style ...?}\fR).
.\" OPTION: -visible
.TP
\fB\-visible\fR
.
Read-only option that returns a boolean indicating whether the font selection
dialog is currently visible. Attempting to set this option results in an error.

.PP
.SH "VIRTUAL EVENTS"
.TP
\fB<<TkFontchooserVisibility>>\fR
.
Sent to the dialog parent whenever the visibility of the font selection dialog
changes, both as a result of user action (e.g. disposing of the dialog via
OK/Cancel button or close box) and of the \fBtk fontchooser\fR
\fBshow\fR/\fBhide\fR commands being called. Binding scripts can determine the
current visibility of the dialog by querying the \fB\-visible\fR configuration
option.
.TP
\fB<<TkFontchooserFontChanged>>\fR
.
Sent to the dialog parent whenever the font selection dialog is visible and the
selected font changes, both as a result of user action and of the \fB\-font\fR
configuration option being set. Binding scripts can determine the currently
selected font by querying the \fB\-font\fR configuration option.
.PP
.SH NOTES
.PP
150
151
152
153
154
155
156
157
158


159
160

161
162
163

164
165
166
167
168


169
170
171
172
173

174
175
176
177
178


179
180
181
182
183


184
185
186

187
188
189
190
191
192
193
194
195
196
135
136
137
138
139
140
141


142
143
144

145
146
147

148
149
150
151


152
153
154
155
156
157

158
159
160
161


162
163
164
165
166


167
168
169
170

171
172
173
174
175
176
177
178
179
180
181







-
-
+
+

-
+


-
+



-
-
+
+




-
+



-
-
+
+



-
-
+
+


-
+










to ensure its selected font matches the new value of the named font.
.PP
.SH EXAMPLE
.PP
.CS
proc fontchooserDemo {} {
    wm title . "Font Chooser Demo"
    \fBtk fontchooser\fR \fBconfigure\fR -parent .
    button .b -command fontchooserToggle -takefocus 0
    \fBtk fontchooser\fR \fBconfigure\fR \-parent .
    button .b \-command fontchooserToggle \-takefocus 0
    fontchooserVisibility .b
    bind . \fB<<TkFontchooserVisibility>>\fR \e
    bind . \fB<<TkFontchooserVisibility>>\fR \\
            [list fontchooserVisibility .b]
    foreach w {.t1 .t2} {
        text $w -width 20 -height 4 -borderwidth 1 -relief solid
        text $w \-width 20 \-height 4 \-borderwidth 1 \-relief solid
        bind $w <FocusIn> [list fontchooserFocus $w]
        $w insert end "Text Widget $w"
    }
    .t1 configure -font {Courier 14}
    .t2 configure -font {Times 16}
    .t1 configure \-font {Courier 14}
    .t2 configure \-font {Times 16}
    pack .b .t1 .t2; focus .t1
}
proc fontchooserToggle {} {
    \fBtk fontchooser\fR [expr {
            [\fBtk fontchooser\fR \fBconfigure\fR -visible] ?
            [\fBtk fontchooser\fR \fBconfigure\fR \-visible] ?
            "\fBhide\fR" : "\fBshow\fR"}]
}
proc fontchooserVisibility {w} {
    $w configure -text [expr {
            [\fBtk fontchooser\fR \fBconfigure\fR -visible] ?
    $w configure \-text [expr {
            [\fBtk fontchooser\fR \fBconfigure\fR \-visible] ?
            "Hide Font Dialog" : "Show Font Dialog"}]
}
proc fontchooserFocus {w} {
    \fBtk fontchooser\fR \fBconfigure\fR -font [$w cget -font] \e
            -command [list fontchooserFontSelection $w]
    \fBtk fontchooser\fR \fBconfigure\fR \-font [$w cget \-font] \\
            \-command [list fontchooserFontSelection $w]
}
proc fontchooserFontSelection {w font args} {
    $w configure -font [font actual $font]
    $w configure \-font [font actual $font]
}
fontchooserDemo
.CE
.SH "SEE ALSO"
font(n), tk(n)
.SH KEYWORDS
dialog, font, font selection, font chooser, font panel
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/frame.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27










28
29
30
31
32
33
34







-
+












-
-
-
-
-
-
-
-
-
-







.TH frame n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
frame \- Create and manipulate 'frame' simple container widgets
.SH SYNOPSIS
\fBframe\fI pathName\fR ?\fIoptions\fR?
\fBframe\fR \fIpathName\fR ?\fIoptions\fR?
.SO
\-borderwidth	\-highlightcolor	\-pady
\-cursor	\-highlightthickness	\-relief
\-highlightbackground	\-padx	\-takefocus
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-background background Background
This option is the same as the standard \fB\-background\fR option
except that its value may also be specified as an empty string.
In this case, the widget will display no background or border, and
no colors will be consumed from its colormap for its background
and border.
.VS "8.7, TIP262"
An empty background will disable drawing the background image.
.OP \-backgroundimage backgroundImage BackgroundImage
This specifies an image to display on the frame's background within
the border of the frame (i.e., the image will be clipped by the
frame's highlight ring and border, if either are present); subwidgets
of the frame will be drawn on top. The image must have been created
with the \fBimage create\fR command. If specified as the empty string,
no image will be displayed.
.VE "8.7, TIP262"
.OP \-class class Class
Specifies a class for the window.
This class will be used when querying the option database for
the window's other options, and it will also be used later for
other purposes such as bindings.
The \fB\-class\fR option may not be changed with the \fBconfigure\fR
widget command.
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
58
59
60
61
62
63
64









65
66
67
68
69
70
71







-
-
-
-
-
-
-
-
-







Specifies the desired height for the window in any of the forms
acceptable to \fBTk_GetPixels\fR.  If this option is less than or equal
to zero then the window will not request any size at all.  Note that this
sets the total height of the frame, any \fB\-borderwidth\fR or similar is
not added.  Normally \fB\-height\fR should not be used if a propagating
geometry manager, such as \fBgrid\fR or \fBpack\fR, is used within the
frame since the geometry manager will override the height of the frame.
.OP \-tile tile Tile
.VS "8.7, TIP262"
This specifies how to draw the background image (see
\fB\-backgroundimage\fR) on the frame.
If true (according to \fBTcl_GetBoolean\fR), the image will be tiled
to fill the whole frame, with the origin of the first copy of the
image being the top left of the interior of the frame.
If false (the default), the image will be centered within the frame.
.VE "8.7, TIP262"
.OP \-visual visual Visual
Specifies visual information for the new window in any of the
forms accepted by \fBTk_GetVisual\fR.
If this option is not specified, the new window will use the same
visual as its parent.
The \fB\-visual\fR option may not be modified with the \fBconfigure\fR
widget command.
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101

102

103
104

105
106
107
108

109

110

111
112
113
114

115

116

117
118
119
120
121
122
123







-
+







-

-
+

-




-

-
+
-




-

-
+
-







or in the option database
to configure aspects of the frame such as its background color
and relief.  The \fBframe\fR command returns the
path name of the new window.
.PP
A frame is a simple widget.  Its primary purpose is to act as a
spacer or container for complex window layouts.  The only features
of a frame are its background and an optional 3-D border to make the
of a frame are its background color and an optional 3-D border to make the
frame appear raised or sunken.
.SH "WIDGET COMMAND"
.PP
The \fBframe\fR command creates a new Tcl command whose
name is the same as the path name of the frame's window.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.PP
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
.PP
\fIPathName\fR is the name of the command, which is the same as
the frame widget's path name.  \fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for frame widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBframe\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
\fIpathName \fBconfigure\fR ?\fIoption\fR? \fI?value option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If

Changes to doc/getOpenFile.n.

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96

97
98
99
100
101
102

103
104
105
106
107

108
109
110
111
112
113
114

115
116
117
118
119
120

121
122
123
124
125
126
127
30
31
32
33
34
35
36

37










38

39
40
41
42

43

44
45
46
47
48
49
50
51
52

53

54
55
56
57
58
59
60
61
62
63

64

65
66
67
68
69
70
71
72
73
74

75

76
77
78

79

80
81
82
83

84

85
86
87

88

89
90
91
92
93

94

95
96
97
98

99

100
101
102
103
104
105
106
107







-

-
-
-
-
-
-
-
-
-
-
+
-




-

-
+








-

-
+









-

-
+









-

-
+


-

-
+



-

-
+


-

-
+




-

-
+



-

-
+







The \fBtk_getSaveFile\fR command is usually associated with the \fBSave
as\fR command in the \fBFile\fR menu. If the user enters a file that
already exists, the dialog box prompts the user for confirmation
whether the existing file should be overwritten or not.
.PP
The following \fIoption\-value\fR pairs are possible as command line
arguments to these two commands:
.\" OPTION: -command
.TP
\fB\-command\fI string\fR
.
Specifies the prefix of a Tcl command to invoke when the user closes the
dialog after having selected an item. This callback is not called if the
user cancelled the dialog. The actual command consists of \fIstring\fR
followed by a space and the value selected by the user in the dialog. This
is only available on Mac OS X.
.\" OPTION: -confirmoverwrite
.TP
\fB\-confirmoverwrite\fI boolean\fR
\fB\-confirmoverwrite\fR \fIboolean\fR
.
Configures how the Save dialog reacts when the selected file already
exists, and saving would overwrite it.  A true value requests a
confirmation dialog be presented to the user.  A false value requests
that the overwrite take place without confirmation.  Default value is true.
.\" OPTION: -defaultextension
.TP
\fB\-defaultextension\fI extension\fR
\fB\-defaultextension\fR \fIextension\fR
.
Specifies a string that will be appended to the filename if the user
enters a filename without an extension. The default value is the empty
string, which means no extension will be appended to the filename in
any case. This option is ignored on Mac OS X, which
does not require extensions to filenames,
and the UNIX implementation guesses reasonable values for this from
the \fB\-filetypes\fR option when this is not supplied.
.\" OPTION: -filetypes
.TP
\fB\-filetypes\fI filePatternList\fR
\fB\-filetypes\fR \fIfilePatternList\fR
.
If a \fBFile types\fR listbox exists in the file dialog on the particular
platform, this option gives the \fIfiletype\fRs in this listbox. When
the user choose a filetype in the listbox, only the files of that type
are listed. If this option is unspecified, or if it is set to the
empty list, or if the \fBFile types\fR listbox is not supported by the
particular platform then all files are listed regardless of their
types. See the section \fBSPECIFYING FILE PATTERNS\fR below for a
discussion on the contents of \fIfilePatternList\fR.
.\" OPTION: -initialdir
.TP
\fB\-initialdir\fI directory\fR
\fB\-initialdir\fR \fIdirectory\fR
.
Specifies that the files in \fIdirectory\fR should be displayed
when the dialog pops up. If this parameter is not specified,
the initial directory defaults to the current working directory
on non-Windows systems and on Windows systems prior to Vista.
On Vista and later systems, the initial directory defaults to the last
user-selected directory for the application. If the
parameter specifies a relative path, the return value will convert the
relative path to an absolute path.
.\" OPTION: -initialfile
.TP
\fB\-initialfile\fI filename\fR
\fB\-initialfile\fR \fIfilename\fR
.
Specifies a filename to be displayed in the dialog when it pops up.
.\" OPTION: -message
.TP
\fB\-message\fI string\fR
\fB\-message\fR \fIstring\fR
.
Specifies a message to include in the client area of the dialog.
This is only available on Mac OS X.
.\" OPTION: -multiple
.TP
\fB\-multiple\fI boolean\fR
\fB\-multiple\fR \fIboolean\fR
.
Allows the user to choose multiple files from the Open dialog.
.\" OPTION: -parent
.TP
\fB\-parent\fI window\fR
\fB\-parent\fR \fIwindow\fR
.
Makes \fIwindow\fR the logical parent of the file dialog. The file
dialog is displayed on top of its parent window. On Mac OS X, this
turns the file dialog into a sheet attached to the parent window.
.\" OPTION: -title
.TP
\fB\-title\fI titleString\fR
\fB\-title\fR \fItitleString\fR
.
Specifies a string to display as the title of the dialog box. If this
option is not specified, then a default title is displayed.
.\" OPTION: -typevariable
.TP
\fB\-typevariable\fI variableName\fR
\fB\-typevariable\fR \fIvariableName\fR
.
The global variable \fIvariableName\fR is used to preselect which filter is
used from \fIfilterList\fR when the dialog box is opened and is
updated when the dialog box is closed, to the last selected
filter. The variable is read once at the beginning to select the
appropriate filter. If the variable does not exist, or its value does
not match any filter typename, or is empty (\fB{}\fR), the dialog box
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200







-
+












    {{Text Files}       {.txt}        }
    {{TCL Scripts}      {.tcl}        }
    {{C Source Files}   {.c}      TEXT}
    {{GIF Files}        {.gif}        }
    {{GIF Files}        {}        GIFF}
    {{All Files}        *             }
}
set filename [\fBtk_getOpenFile\fR -filetypes $types]
set filename [\fBtk_getOpenFile\fR \-filetypes $types]

if {$filename ne ""} {
    # Open the file ...
}
.CE
.SH "SEE ALSO"
tk_chooseDirectory
.SH KEYWORDS
file selection dialog
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/grab.n.

8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24
25
8
9
10
11
12
13
14

15
16

17

18
19
20
21
22
23
24







-

+
-
+
-







.TH grab n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
grab \- Confine pointer and keyboard events to a window sub-tree
.SH SYNOPSIS
.nf
\fBgrab \fR?\fB\-global\fR? \fIwindow\fR
.sp
\fBgrab \fIoption \fR?\fIarg \fR...?
\fBgrab \fIoption \fR?\fIarg arg \fR...?
.fi
.BE
.SH DESCRIPTION
.PP
This command implements simple pointer and keyboard grabs for Tk.
Tk's grabs are different than the grabs
described in the Xlib documentation.
When a grab is set for a particular window, Tk restricts all pointer
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
57
58
59
60
61
62
63










64
65
66
67
68
69
70
71
72
73
74
75

76

77
78

79
80
81
82
83
84

85
86

87
88

89
90

91
92
93
94
95
96
97

98
99

100
101
102
103
104
105
106







-
-
-
-
-
-
-
-
-
-












-

-


-






-


-


-


-







-


-







redirected to the focus window.
During a global grab Tk grabs the keyboard so that all keyboard events
are always sent to the grabbing application.
The \fBfocus\fR command is still used to determine which window in the
application receives the keyboard events.
The keyboard grab is released when the grab is released.
.PP
On macOS a global grab affects all windows created by one Tk process.
No window in that process other than the grab window can even be
focused, hence no other window receives key or mouse events.  A local
grab on macOS affects all windows created by one Tcl interpreter.  It
is possible to focus any window belonging to the Tk process during a
local grab but the grab window is the only window created by its
interpreter which receives key or mouse events.  Windows belonging to the
same process but created by different interpreters continue to receive
key and mouse events normally.
.PP
Grabs apply to particular displays.  If an application has windows
on multiple displays then it can establish a separate grab on each
display.
The grab on a particular display affects only the windows on
that display.
It is possible for different applications on a single display to have
simultaneous local grabs, but only one application can have a global
grab on a given display at once.
.PP
The \fBgrab\fR command can take any of the following forms:
.TP
\fBgrab \fR?\fB\-global\fR? \fIwindow\fR
.
Same as \fBgrab set\fR, described below.
.\" METHOD: current
.TP
\fBgrab current \fR?\fIwindow\fR?
.
If \fIwindow\fR is specified, returns the name of the current grab
window in this application for \fIwindow\fR's display, or an empty
string if there is no such window.
If \fIwindow\fR is omitted, the command returns a list whose elements
are all of the windows grabbed by this application for all displays,
or an empty string if the application has no grabs.
.\" METHOD: release
.TP
\fBgrab release \fIwindow\fR
.
Releases the grab on \fIwindow\fR if there is one, otherwise does
nothing.  Returns an empty string.
.\" METHOD: set
.TP
\fBgrab set \fR?\fB\-global\fR? \fIwindow\fR
.
Sets a grab on \fIwindow\fR.  If \fB\-global\fR is specified then the
grab is global, otherwise it is local.
If a grab was already in effect for this application on
\fIwindow\fR's display then it is automatically released.
If there is already a grab on \fIwindow\fR and it has the same
global/local form as the requested grab, then the command
does nothing.  Returns an empty string.
.\" METHOD: status
.TP
\fBgrab status \fIwindow\fR
.
Returns \fBnone\fR if no grab is currently set on \fIwindow\fR,
\fBlocal\fR if a local grab is set on \fIwindow\fR, and
\fBglobal\fR if a global grab is set.
.SH WARNING
.PP
It is very easy to use global grabs to render a display completely
unusable (e.g. by setting a grab on a widget which does not respond to
142
143
144
145
146
147
148
149
150
151



152
153
154
155
156
157
158
159
160
122
123
124
125
126
127
128



129
130
131
132
133
134
135
136
137
138
139
140







-
-
-
+
+
+









processes, this restriction does not exist.
.SH EXAMPLE
.PP
Set a grab so that only one button may be clicked out of a group.  The
other buttons are unresponsive to the mouse until the middle button is
clicked.
.CS
pack [button .b1 -text "Click me! #1" -command {destroy .b1}]
pack [button .b2 -text "Click me! #2" -command {destroy .b2}]
pack [button .b3 -text "Click me! #3" -command {destroy .b3}]
pack [button .b1 \-text "Click me! #1" \-command {destroy .b1}]
pack [button .b2 \-text "Click me! #2" \-command {destroy .b2}]
pack [button .b3 \-text "Click me! #3" \-command {destroy .b3}]
\fBgrab\fR .b2
.CE
.SH "SEE ALSO"
busy(n)
.SH KEYWORDS
grab, keyboard events, pointer events, window
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/grid.n.

13
14
15
16
17
18
19
20

21
22
23
24

25
26

27
28
29
30
31
32
33

34
35

36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
53
54

55
56
57

58
59
60
61
62
63
64
65



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88

89
90
91
92

93
94

95
96

97
98
99

100
101
102
103
104
105
106
107

108
109

110
111
112
113


114
115
116
117
118
119
120

121
122
123
124
125
126

127
128
129


130
131
132
133
134
135
136
137


138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153

154
155
156
157

158
159
160
161
162
163

164
165
166
167

168
169
170
171
172

173
174

175
176

177
178
179
180
181

182
183
184


185
186
187
188
189
190
191


192
193
194

195
196

197
198
199

200
201
202
203
204

205
206

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225



226
227

228
229
230
231
232
233
234
235
236
237
238
239

240
241
242

243
244
245
246


247
248
249

250
251
252
253
254




255
256
257

258
259
260

261
262
263

264
265
266
267

268
269
270
271
272
273
274

275
276
277

278
279
280
281
282
283
284
285



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312

313
314
315
316



317
318
319



320
321
322
323
324
325
326
327
328
329
330

331
332
333


334
335
336
337
338

339
340





341
342
343
344
345

346
347
348

349
350
351
352
353



354
355

356

357
358
359
360
361
362
363
364
365
366















367
368

369
370
371
372
373


374
375

376
377

378
379

380
381
382
383


384
385
386

387
388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413

414
415

416
417
418
419
420
421
422
423
424
425



426
427
428
429
430

431
432
433


434
435

436
437
438


439
440
441
442



443
444
445
446
447
448
449
450






451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466



467
468
469
470


471
472
473
474


475
476
477
478
479
480
481
482
483
484



485
486
487


488
489
490
491
492
493
494
495
13
14
15
16
17
18
19

20
21
22
23

24
25

26
27
28
29
30

31

32
33

34
35
36

37

38
39
40
41
42

43
44
45
46
47
48
49

50

51
52
53

54
55
56
57
58
59



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84

85
86

87

88
89

90
91

92
93
94

95
96
97
98

99
100
101

102
103

104
105
106


107
108
109
110

111
112
113

114
115
116
117

118

119
120


121
122
123

124
125
126
127


128
129
130
131

132
133
134
135


136
137
138

139
140
141
142

143
144
145
146

147

148
149
150
151

152
153
154
155

156

157
158
159

160
161

162


163

164
165
166

167
168


169
170
171

172
173
174


175
176
177
178

179
180

181
182
183

184
185
186
187
188

189
190

191
192
193
194

195










196
197



198
199
200
201

202
203









204

205
206
207

208
209
210


211
212

213

214
215




216
217
218
219

220

221
222
223

224
225
226

227
228
229
230

231


232


233

234
235
236

237
238
239
240
241
242



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268
269

270

271
272



273
274
275
276


277
278
279









280

281
282


283
284
285
286

287

288
289

290
291
292
293
294
295
296
297
298

299
300
301

302
303
304



305
306
307
308

309
310
311










312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331


332
333
334

335
336

337
338

339
340
341


342
343
344
345

346
347

348
349

350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

371
372

373
374

375
376
377
378
379
380
381
382



383
384
385
386
387
388
389

390
391


392
393
394

395
396


397
398
399



400
401
402
403
404






405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423



424
425
426
427
428


429
430
431
432


433
434
435
436
437
438
439
440
441



442
443
444
445


446
447
448
449
450
451
452
453
454
455







-
+



-
+

-
+




-

-
+

-
+


-

-
+




-
+






-

-
+


-
+





-
-
-
+
+
+




















-
+

-
+

-

-
+

-
+

-
+


-
+



-



-
+

-
+


-
-
+
+


-



-
+



-

-
+

-
-
+
+

-




-
-
+
+


-




-
-
+
+

-




-
+



-
+
-




-
+



-
+
-



-
+

-
+
-
-
+
-



-
+

-
-
+
+

-



-
-
+
+


-
+

-
+


-
+




-
+

-
+



-

-
-
-
-
-
-
-
-
-
-
+

-
-
-
+
+
+

-
+

-
-
-
-
-
-
-
-
-

-
+


-
+


-
-
+
+
-

-
+

-
-
-
-
+
+
+
+
-

-
+


-
+


-
+



-
+
-
-

-
-

-
+


-
+





-
-
-
+
+
+




















-
+



-

-
+

-
-
-
+
+
+

-
-
+
+
+
-
-
-
-
-
-
-
-
-

-
+

-
-
+
+


-

-
+

-
+
+
+
+
+




-
+


-
+


-
-
-
+
+
+

-
+

+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
-
+
+

-
+

-
+

-
+


-
-
+
+


-
+

-
+

-
+




















-
+

-
+

-
+







-
-
-
+
+
+




-
+

-
-
+
+

-
+

-
-
+
+

-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+













-
-
-
+
+
+


-
-
+
+


-
-
+
+







-
-
-
+
+
+

-
-
+
+








.SH SYNOPSIS
\fBgrid \fIoption arg \fR?\fIarg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBgrid\fR command is used to communicate with the grid
geometry manager that arranges widgets in rows and columns inside
of another window, called the geometry container (or container window).
of another window, called the geometry master (or master window).
The \fBgrid\fR command can have any of several forms, depending
on the \fIoption\fR argument:
.TP
\fBgrid \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
\fBgrid \fIslave \fR?\fIslave ...\fR? ?\fIoptions\fR?
.
If the first argument to \fBgrid\fR is suitable as the first window
If the first argument to \fBgrid\fR is suitable as the first slave
argument to \fBgrid configure\fR, either a window name (any value
starting with \fB.\fR) or one of the characters \fBx\fR or \fB^\fR
(see the \fBRELATIVE PLACEMENT\fR section below), then the command is
processed in the same way as \fBgrid configure\fR.
.\" METHOD: anchor
.TP
\fBgrid anchor \fIwindow\fR ?\fIanchor\fR?
\fBgrid anchor \fImaster\fR ?\fIanchor\fR?
.
The anchor value controls how to place the grid within the container window
The anchor value controls how to place the grid within the master
when no row/column has any weight.  See \fBTHE GRID ALGORITHM\fR below
for further details.  The default \fIanchor\fR is \fInw\fR.
.\" METHOD: bbox
.TP
\fBgrid bbox \fIwindow\fR ?\fIcolumn row\fR? ?\fIcolumn2 row2\fR?
\fBgrid bbox \fImaster\fR ?\fIcolumn row\fR? ?\fIcolumn2 row2\fR?
.
With no arguments,
the bounding box (in pixels) of the grid is returned.
The return value consists of 4 integers.  The first two are the pixel
offset from the container window (x then y) of the top-left corner of the
offset from the master window (x then y) of the top-left corner of the
grid, and the second two integers are the width and height of the grid,
also in pixels.  If a single \fIcolumn\fR and \fIrow\fR is specified on
the command line, then the bounding box for that cell is returned, where the
top left cell is numbered from zero.  If both \fIcolumn\fR and \fIrow\fR
arguments are specified, then the bounding box spanning the rows and columns
indicated is returned.
.\" METHOD: columnconfigure
.TP
\fBgrid columnconfigure \fIwindow index \fR?\fI\-option value...\fR?
\fBgrid columnconfigure \fImaster index \fR?\fI\-option value...\fR?
.
Query or set the column properties of the \fIindex\fR column of the
geometry container, \fIwindow\fR.
geometry master, \fImaster\fR.
The valid options are \fB\-minsize\fR, \fB\-weight\fR, \fB\-uniform\fR
and \fB\-pad\fR.
If one or more options are provided, then \fIindex\fR may be given as
a list of column indices to which the configuration options will operate on.
Indices may be integers, window names or the keyword \fIall\fR. For \fIall\fR
the options apply to all columns currently occupied be content windows. For
a window name, that window must be a content of this container and the options
apply to all columns currently occupied be the content.
the options apply to all columns currently occupied be slave windows. For
a window name, that window must be a slave of this master and the options
apply to all columns currently occupied be the slave.
The \fB\-minsize\fR option sets the minimum size, in screen units,
that will be permitted for this column.
The \fB\-weight\fR option (an integer value)
sets the relative weight for apportioning
any extra spaces among
columns.
A weight of zero (0) indicates the column will not deviate from its requested
size.  A column whose weight is two will grow at twice the rate as a column
of weight one when extra space is allocated to the layout.
The \fB\-uniform\fR option, when a non-empty value is supplied, places
the column in a \fIuniform group\fR with other columns that have the
same value for \fB\-uniform\fR.  The space for columns belonging to a
uniform group is allocated so that their sizes are always in strict
proportion to their \fB\-weight\fR values.  See
\fBTHE GRID ALGORITHM\fR below for further details.
The \fB\-pad\fR option specifies the number of screen units that will be
added to the largest window contained completely in that column when the
grid geometry manager requests a size from the containing window.
If only an option is specified, with no value,
the current value of that option is returned.
If only the container window and index is specified, all the current settings
If only the master window and index is specified, all the current settings
are returned in a list of
.QW "\fI\-option value\fR"
.QW "\-option value"
pairs.
.\" METHOD: configure
.TP
\fBgrid configure \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
\fBgrid configure \fIslave \fR?\fIslave ...\fR? ?\fIoptions\fR?
.
The arguments consist of the names of one or more content windows
The arguments consist of the names of one or more slave windows
followed by pairs of arguments that specify how
to manage the content.
to manage the slaves.
The characters \fB\-\fR,  \fBx\fR and \fB^\fR,
can be specified instead of a window name to alter the default
location of a \fIwindow\fR, as described in the \fBRELATIVE PLACEMENT\fR
location of a \fIslave\fR, as described in the \fBRELATIVE PLACEMENT\fR
section, below.
The following options are supported:
.RS
.\" OPTION: -column
.TP
\fB\-column \fIn\fR
.
Insert the window so that it occupies the \fIn\fRth column in the grid.
Insert the slave so that it occupies the \fIn\fRth column in the grid.
Column numbers start with 0.  If this option is not supplied, then the
window is arranged just to the right of previous window specified on this
slave is arranged just to the right of previous slave specified on this
call to \fBgrid\fR, or column
.QW 0
if it is the first window.  For each
\fBx\fR that immediately precedes the \fIwindow\fR, the column position
if it is the first slave.  For each
\fBx\fR that immediately precedes the \fIslave\fR, the column position
is incremented by one.  Thus the \fBx\fR represents a blank column
for this row in the grid.
.\" OPTION: -columnspan
.TP
\fB\-columnspan \fIn\fR
.
Insert the window so that it occupies \fIn\fR columns in the grid.
Insert the slave so that it occupies \fIn\fR columns in the grid.
The default is one column, unless the window name is followed by a
\fB\-\fR, in which case the columnspan is incremented once for each immediately
following \fB\-\fR.
.\" OPTION: -in
.TP
\fB\-in \fIcontainer\fR
\fB\-in \fIother\fR
.
Insert the window(s) in the container
window given by \fIcontainer\fR.  The default is the first window's
Insert the slave(s) in the master
window given by \fIother\fR.  The default is the first slave's
parent window.
.\" OPTION: -ipadx
.TP
\fB\-ipadx \fIamount\fR
.
The \fIamount\fR specifies how much horizontal internal padding to
leave on each side of the content.  This is space is added
inside the content border.
leave on each side of the slave(s).  This is space is added
inside the slave(s) border.
The \fIamount\fR must be a valid screen distance, such as \fB2\fR or \fB.5c\fR.
It defaults to 0.
.\" OPTION: -ipady
.TP
\fB\-ipady \fIamount\fR
.
The \fIamount\fR specifies how much vertical internal padding to
leave on the top and bottom of the content.
This space is added inside the content border.
leave on the top and bottom of the slave(s).
This space is added inside the slave(s) border.
The \fIamount\fR  defaults to 0.
.\" OPTION: -padx
.TP
\fB\-padx \fIamount\fR
.
The \fIamount\fR specifies how much horizontal external padding to
leave on each side of the content, in screen units.
leave on each side of the slave(s), in screen units.
\fIAmount\fR may be a list
of two values to specify padding for left and right separately.
The \fIamount\fR defaults to 0.
This space is added outside the content border.
This space is added outside the slave(s) border.
.\" OPTION: -pady
.TP
\fB\-pady \fIamount\fR
.
The \fIamount\fR specifies how much vertical external padding to
leave on the top and bottom of the content, in screen units.
leave on the top and bottom of the slave(s), in screen units.
\fIAmount\fR may be a list
of two values to specify padding for top and bottom separately.
The \fIamount\fR defaults to 0.
This space is added outside the content border.
This space is added outside the slave(s) border.
.\" OPTION: -row
.TP
\fB\-row \fIn\fR
.
Insert the content so that it occupies the \fIn\fRth row in the grid.
Insert the slave so that it occupies the \fIn\fRth row in the grid.
Row numbers start with 0.  If this option is not supplied, then the
content is arranged on the same row as the previous content specified on this
slave is arranged on the same row as the previous slave specified on this
call to \fBgrid\fR, or the next row after the highest occupied row
if this is the first content.
call to \fBgrid\fR, or the first unoccupied row if this is the first slave.
.\" OPTION: -rowspan
.TP
\fB\-rowspan \fIn\fR
.
Insert the content so that it occupies \fIn\fR rows in the grid.
Insert the slave so that it occupies \fIn\fR rows in the grid.
The default is one row.  If the next \fBgrid\fR command contains
\fB^\fR characters instead of \fIcontent\fR that line up with the columns
of this \fIcontent\fR, then the \fBrowspan\fR of this \fIcontent\fR is
\fB^\fR characters instead of \fIslaves\fR that line up with the columns
of this \fIslave\fR, then the \fBrowspan\fR of this \fIslave\fR is
extended by one.
.\" OPTION: -sticky
.TP
\fB\-sticky \fIstyle\fR
.
If a content's cell is larger than its requested dimensions, this
option may be used to position (or stretch) the content within its cell.
If a slave's cell is larger than its requested dimensions, this
option may be used to position (or stretch) the slave within its cell.
\fIStyle\fR  is a string that contains zero or more of the characters
\fBn\fR, \fBs\fR, \fBe\fR or \fBw\fR.
The string can optionally contain spaces or
The string can optionally contains spaces or
commas, but they are ignored.  Each letter refers to a side (north, south,
east, or west) that the content will
east, or west) that the slave will
.QW stick
to.  If both \fBn\fR and \fBs\fR (or \fBe\fR and \fBw\fR) are
specified, the content will be stretched to fill the entire
specified, the slave will be stretched to fill the entire
height (or width) of its cavity.  The \fB\-sticky\fR option subsumes the
combination of \fB\-anchor\fR and \fB\-fill\fR that is used by \fBpack\fR.
The default is
.QW "" ,
which causes the content to be centered in its cavity, at its requested size.
which causes the slave to be centered in its cavity, at its requested size.
.LP
If any of the content is already managed by the geometry manager
If any of the slaves are already managed by the geometry manager
then any unspecified options for them retain their previous values rather
than receiving default values.
.RE
.\" METHOD: content
.TP
\fBgrid content \fIwindow\fR ?\fI\-option value\fR?
.
If no options are supplied, a list of all of the content in \fIwindow\fR
is returned, most recently managed first.
\fIOption\fR can be either \fB\-row\fR or \fB\-column\fR which
causes only the content in the row (or column) specified by \fIvalue\fR
to be returned.
.\" METHOD: forget
.TP
\fBgrid forget \fIwindow \fR?\fIwindow ...\fR?
\fBgrid forget \fIslave \fR?\fIslave ...\fR?
.
Removes each of the \fIwindow\fRs from grid for its
container and unmaps their windows.
The content will no longer be managed by the grid geometry manager.
Removes each of the \fIslave\fRs from grid for its
master and unmaps their windows.
The slaves will no longer be managed by the grid geometry manager.
The configuration options for that window are forgotten, so that if the
window is managed once more by the grid geometry manager, the initial
slave is managed once more by the grid geometry manager, the initial
default settings are used.
.RS
.PP
.VS "TIP 518"
If the last content window of the container becomes unmanaged, this will also
send the virtual event \fB<<NoManagedChild>>\fR to the container; the container
may choose to resize itself (or otherwise respond) to such a change.
.VE "TIP 518"
.RE
.\" METHOD: info
.TP
\fBgrid info \fIwindow\fR
\fBgrid info \fIslave\fR
.
Returns a list whose elements are the current configuration state of
the content given by \fIwindow\fR in the same option-value form that
the slave given by \fIslave\fR in the same option-value form that
might be specified to \fBgrid configure\fR.
The first two elements of the list are
.QW "\fB\-in \fIcontainer\fR"
where \fIcontainer\fR is the windows's container window.
.QW "\fB\-in \fImaster\fR"
where \fImaster\fR is the slave's master.
.\" METHOD: location
.TP
\fBgrid location \fIwindow x y\fR
\fBgrid location \fImaster x y\fR
.
Given  \fIx\fR and \fIy\fR values in screen units relative to the container
window, the column and row number at that \fIx\fR and \fIy\fR location is
returned. For locations that are above or to the left of the grid, \fB\-1\fR
is returned.
Given  \fIx\fR and \fIy\fR values in screen units relative to the master window,
the column and row number at that \fIx\fR and \fIy\fR location is returned.
For locations that are above or to the left of the grid, \fB\-1\fR is
returned.
.\" METHOD: propagate
.TP
\fBgrid propagate \fIwindow\fR ?\fIboolean\fR?
\fBgrid propagate \fImaster\fR ?\fIboolean\fR?
.
If \fIboolean\fR has a true boolean value such as \fB1\fR or \fBon\fR
then propagation is enabled for \fIwindow\fR, which must be a window
then propagation is enabled for \fImaster\fR, which must be a window
name (see \fBGEOMETRY PROPAGATION\fR below).
If \fIboolean\fR has a false boolean value then propagation is
disabled for \fIwindow\fR.
disabled for \fImaster\fR.
In either of these cases an empty string is returned.
If \fIboolean\fR is omitted then the command returns \fB0\fR or
\fB1\fR to indicate whether propagation is currently enabled
for \fIwindow\fR.
for \fImaster\fR.
.RS
.PP
Propagation is enabled by default.
.RE
.\" METHOD: rowconfigure
.TP
\fBgrid rowconfigure \fIwindow index \fR?\fI\-option value...\fR?
\fBgrid rowconfigure \fImaster index \fR?\fI\-option value...\fR?
.
Query or set the row properties of the \fIindex\fR row of the
geometry container, \fIwindow\fR.
geometry master, \fImaster\fR.
The valid options are \fB\-minsize\fR, \fB\-weight\fR, \fB\-uniform\fR
and \fB\-pad\fR.
If one or more options are provided, then \fIindex\fR may be given as
a list of row indices to which the configuration options will operate on.
Indices may be integers, window names or the keyword \fIall\fR. For \fIall\fR
the options apply to all rows currently occupied by content windows. For a
window name, that window must be a content window of this container and the
options apply to all rows currently occupied by the container window.
the options apply to all rows currently occupied be slave windows. For
a window name, that window must be a slave of this master and the options
apply to all rows currently occupied be the slave.
The \fB\-minsize\fR option sets the minimum size, in screen units,
that will be permitted for this row.
The \fB\-weight\fR option (an integer value)
sets the relative weight for apportioning
any extra spaces among
rows.
A weight of zero (0) indicates the row will not deviate from its requested
size.  A row whose weight is two will grow at twice the rate as a row
of weight one when extra space is allocated to the layout.
The \fB\-uniform\fR option, when a non-empty value is supplied, places
the row in a \fIuniform group\fR with other rows that have the
same value for \fB\-uniform\fR.  The space for rows belonging to a
uniform group is allocated so that their sizes are always in strict
proportion to their \fB\-weight\fR values.  See
\fBTHE GRID ALGORITHM\fR below for further details.
The \fB\-pad\fR option specifies the number of screen units that will be
added to the largest window contained completely in that row when the
grid geometry manager requests a size from the containing window.
If only an option is specified, with no value,
the current value of that option is returned.
If only the container window and index is specified, all the current settings
If only the master window and index is specified, all the current settings
are returned in a list of
.QW "-option value"
pairs.
.\" METHOD: remove
.TP
\fBgrid remove \fIwindow \fR?\fIwindow ...\fR?
\fBgrid remove \fIslave \fR?\fIslave ...\fR?
.
Removes each of the \fIwindow\fRs from grid for its
container and unmaps their windows.
The content will no longer be managed by the grid geometry manager.
Removes each of the \fIslave\fRs from grid for its
master and unmaps their windows.
The slaves will no longer be managed by the grid geometry manager.
However, the configuration options for that window are remembered,
so that if the content window is managed once more by the grid
geometry manager, the previous values are retained.
so that if the
slave is managed once more by the grid geometry manager, the previous
values are retained.
.RS
.PP
.VS "TIP 518"
If the last content window of the container becomes unmanaged, this will also
send the virtual event \fB<<NoManagedChild>>\fR to the container; the
container may choose to resize itself (or otherwise respond) to such a change.
.VE "TIP 518"
.RE
.\" METHOD: size
.TP
\fBgrid size \fIcontainer\fR
\fBgrid size \fImaster\fR
.
Returns the size of the grid (in columns then rows) for \fIcontainer\fR.
The size is determined either by the \fIcontent\fR occupying the largest
Returns the size of the grid (in columns then rows) for \fImaster\fR.
The size is determined either by the \fIslave\fR occupying the largest
row or column, or the largest column or row with a \fB\-minsize\fR,
\fB\-weight\fR, or \fB\-pad\fR that is non-zero.
.\" METHOD: slaves
.TP
\fBgrid slaves \fIwindow\fR ?\fI\-option value\fR?
\fBgrid slaves \fImaster\fR ?\fI\-option value\fR?
.
Synonym for \fBgrid content \fIwindow\fR ?\fI\-option value\fR?.
If no options are supplied, a list of all of the slaves in \fImaster\fR
are returned, most recently manages first.
\fIOption\fR can be either \fB\-row\fR or \fB\-column\fR which
causes only the slaves in the row (or column) specified by \fIvalue\fR
to be returned.
.SH "RELATIVE PLACEMENT"
.PP
The \fBgrid\fR command contains a limited set of capabilities that
permit layouts to be created without specifying the row and column
information for each content.  This permits content to be rearranged,
information for each slave.  This permits slaves to be rearranged,
added, or removed without the need to explicitly specify row and
column information.
When no column or row information is specified for a \fIcontent\fR,
When no column or row information is specified for a \fIslave\fR,
default values are chosen for
\fB\-column\fR, \fB\-row\fR, \fB\-columnspan\fR and \fB\-rowspan\fR
at the time the \fIcontent\fR is managed. The values are chosen
based upon the current layout of the grid, the position of the \fIcontent\fR
relative to other \fIcontent\fRs in the same grid command, and the presence
at the time the \fIslave\fR is managed. The values are chosen
based upon the current layout of the grid, the position of the \fIslave\fR
relative to other \fIslave\fRs in the same grid command, and the presence
of the characters \fB\-\fR, \fBx\fR, and \fB^\fR in \fBgrid\fR
command where \fIcontent\fR names are normally expected.
command where \fIslave\fR names are normally expected.
.RS
.TP
.IP \fB\-\fR
This increases the \fB\-columnspan\fR of the \fIcontent\fR to the left.  Several
\fB\-\fR's in a row will successively increase the number of columns spanned.
A \fB\-\fR may not follow a \fB^\fR or a \fBx\fR, nor may it be the first
\fIcontent\fR argument to \fBgrid configure\fR.
.IP \fBx\fR
This leaves an empty column between the \fIcontent\fR on the left and
the \fIcontent\fR on the right.
.IP \fB^\fR
This extends the \fB\-rowspan\fR of the \fIcontent\fR above the \fB^\fR's
\fB\-\fR
.
This increases the \fB\-columnspan\fR of the \fIslave\fR to the left.  Several
\fB\-\fR's in a row will successively increase the number of columns spanned. A \fB\-\fR
may not follow a \fB^\fR or a \fBx\fR, nor may it be the first \fIslave\fR
argument to \fBgrid configure\fR.
.TP
\fBx\fR
.
This leaves an empty column between the \fIslave\fR on the left and
the \fIslave\fR on the right.
.TP
\fB^\fR
.
This extends the \fB\-rowspan\fR of the \fIslave\fR above the \fB^\fR's
in the grid.  The number of \fB^\fR's in a row must match the number of
columns spanned by the \fIcontent\fR above it.
columns spanned by the \fIslave\fR above it.
.RE
.SH "THE GRID ALGORITHM"
.PP
The grid geometry manager lays out its content in three steps.
In the first step, the minimum size needed to fit all of the content
The grid geometry manager lays out its slaves in three steps.
In the first step, the minimum size needed to fit all of the slaves
is computed, then (if propagation is turned on), a request is made
of the container window to become that size.
of the master window to become that size.
In the second step, the requested size is compared against the actual size
of the container.  If the sizes are different, then spaces is added to or taken
of the master.  If the sizes are different, then spaces is added to or taken
away from the layout as needed.
For the final step, each content is positioned in its row(s) and column(s)
For the final step, each slave is positioned in its row(s) and column(s)
based on the setting of its \fIsticky\fR flag.
.PP
To compute the minimum size of a layout, the grid geometry manager first looks
at all content whose \fB\-columnspan\fR and \fB\-rowspan\fR values are one,
To compute the minimum size of a layout, the grid geometry manager
first looks at all slaves whose \fB\-columnspan\fR and \fB\-rowspan\fR values are one,
and computes the nominal size of each row or column to be either the
\fIminsize\fR for that row or column, or the sum of the \fIpad\fRding
plus the size of the largest content, whichever is greater.  After that
plus the size of the largest slave, whichever is greater.  After that
the rows or columns in each uniform group adapt to each other.  Then
the content whose row-spans or column-spans are greater than one are
the slaves whose row-spans or column-spans are greater than one are
examined.  If a group of rows or columns need to be increased in size
in order to accommodate these content, then extra space is added to each
in order to accommodate these slaves, then extra space is added to each
row or column in the group according to its \fIweight\fR.  For each
group whose weights are all zero, the additional space is apportioned
equally.
.PP
When multiple rows or columns belong to a uniform group, the space
allocated to them is always in proportion to their weights. (A weight
of zero is considered to be 1.)  In other words, a row or column
configured with \fB\-weight 1 \-uniform a\fR will have exactly the same
size as any other row or column configured with \fB\-weight 1 \-uniform
a\fR.  A row or column configured with \fB\-weight 2 \-uniform b\fR will
be exactly twice as large as one that is configured with \fB\-weight 1
\-uniform b\fR.
.PP
More technically, each row or column in the group will have a size
equal to \fIk*weight\fR for some constant \fIk\fR.  The constant
\fIk\fR is chosen so that no row or column becomes smaller than its
minimum size.  For example, if all rows or columns in a group have the
same weight, then each row or column will have the same size as the
largest row or column in the group.
.PP
For containers whose size is larger than the requested layout, the additional
For masters whose size is larger than the requested layout, the additional
space is apportioned according to the row and column weights.  If all of
the weights are zero, the layout is placed within its container according to
the weights are zero, the layout is placed within its master according to
the \fIanchor\fR value.
For containers whose size is smaller than the requested layout, space is taken
For masters whose size is smaller than the requested layout, space is taken
away from columns and rows according to their weights.  However, once a
column or row shrinks to its minsize, its weight is taken to be zero.
If more space needs to be removed from a layout than would be permitted, as
when all the rows or columns are at their minimum sizes, the layout is
placed and clipped according to the \fIanchor\fR value.
.SH "GEOMETRY PROPAGATION"
.PP
The grid geometry manager normally computes how large a container must be to
just exactly meet the needs of its content, and it sets the
requested width and height of the container to these dimensions.
The grid geometry manager normally computes how large a master must be to
just exactly meet the needs of its slaves, and it sets the
requested width and height of the master to these dimensions.
This causes geometry information to propagate up through a
window hierarchy to a top-level window so that the entire
sub-tree sizes itself to fit the needs of the leaf windows.
However, the \fBgrid propagate\fR command may be used to
turn off propagation for one or more containers.
turn off propagation for one or more masters.
If propagation is disabled then grid will not set
the requested width and height of the container window.
This may be useful if, for example, you wish for a container
the requested width and height of the master window.
This may be useful if, for example, you wish for a master
window to have a fixed size that you specify.
.SH "RESTRICTIONS ON CONTAINER WINDOWS"
.SH "RESTRICTIONS ON MASTER WINDOWS"
.PP
The container for each content must either be the content's parent
(the default) or a descendant of the content's parent.
The master for each slave must either be the slave's parent
(the default) or a descendant of the slave's parent.
This restriction is necessary to guarantee that the
content can be placed over any part of its container that is
visible without danger of the content being clipped by its parent.
In addition, all content in one call to \fBgrid\fR must have the same container.
slave can be placed over any part of its master that is
visible without danger of the slave being clipped by its parent.
In addition, all slaves in one call to \fBgrid\fR must have the same master.
.SH "STACKING ORDER"
.PP
If the container for a content is not its parent then you must make sure
that the content is higher in the stacking order than the container.
Otherwise the container will obscure the content and it will appear as
if the content has not been managed correctly.
The easiest way to make sure the content is higher than the container is
to create the container window first:  the most recently created window
If the master for a slave is not its parent then you must make sure
that the slave is higher in the stacking order than the master.
Otherwise the master will obscure the slave and it will appear as
if the slave has not been managed correctly.
The easiest way to make sure the slave is higher than the master is
to create the master window first:  the most recently created window
will be highest in the stacking order.
.SH CREDITS
.PP
The \fBgrid\fR command is based on ideas taken from the \fIGridBag\fR
geometry manager written by Doug. Stein, and the \fBblt_table\fR geometry
manager, written by George Howlett.
.SH EXAMPLES
.PP
A toplevel window containing a text widget and two scrollbars:
.PP
.CS
# Make the widgets
toplevel .t
text .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}
scrollbar .t.v -orient vertical   -command {.t.txt yview}
scrollbar .t.h -orient horizontal -command {.t.txt xview}
text .t.txt \-wrap none \-xscroll {.t.h set} \-yscroll {.t.v set}
scrollbar .t.v \-orient vertical   \-command {.t.txt yview}
scrollbar .t.h \-orient horizontal \-command {.t.txt xview}

# Lay them out
\fBgrid\fR .t.txt .t.v -sticky nsew
\fBgrid\fR .t.h        -sticky nsew
\fBgrid\fR .t.txt .t.v \-sticky nsew
\fBgrid\fR .t.h        \-sticky nsew

# Tell the text widget to take all the extra room
\fBgrid rowconfigure\fR    .t .t.txt -weight 1
\fBgrid columnconfigure\fR .t .t.txt -weight 1
\fBgrid rowconfigure\fR    .t .t.txt \-weight 1
\fBgrid columnconfigure\fR .t .t.txt \-weight 1
.CE
.PP
Three widgets of equal width, despite their different
.QW natural
widths:
.PP
.CS
button .b -text "Foo"
entry .e -textvariable foo ; set foo "Hello World!"
label .l -text "This is a fairly long piece of text"
button .b \-text "Foo"
entry .e \-variable foo
label .l \-text "This is a fairly long piece of text"

\fBgrid\fR .b .e .l -sticky ew
\fBgrid columnconfigure\fR . "all" -uniform allTheSame
\fBgrid\fR .b .e .l \-sticky ew
\fBgrid columnconfigure\fR . "all" \-uniform allTheSame
.CE
.SH "SEE ALSO"
pack(n), place(n)
.SH KEYWORDS
geometry manager, location, grid, cell, propagation, size, pack
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/image.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102

103
104
105

106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
8
9
10
11
12
13
14

15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42

43
44
45
46
47
48
49
50
51
52

53
54

55
56

57
58

59
60

61
62

63

64
65

66
67

68
69

70
71
72

73
74

75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91

92
93
94
95











96

97
98
99
100
101
102







-
+






-


-

















-


-










-


-


-


-


-


-

-


-


-


-



-


-











+
-
+



+
-
+



-
-
-
-
-
-
-
-
-
-
-

-
+





.TH image n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
image \- Create and manipulate images
.SH SYNOPSIS
\fBimage\fI option \fR?\fIarg ...\fR?
\fBimage\fR \fIoption \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBimage\fR command is used to create, delete, and query images.
It can take several different forms, depending on the
\fIoption\fR argument.  The legal forms are:
.\" METHOD: create
.TP
\fBimage create \fItype \fR?\fIname\fR? ?\fIoption value ...\fR?
.
Creates a new image and a command with the same name and returns its name.
\fItype\fR specifies the type of the image, which must be one of
the types currently defined (e.g., \fBbitmap\fR).
\fIname\fR specifies the name for the image;  if it is omitted then
Tk picks a name of the form \fBimage\fIx\fR, where \fIx\fR is
an integer.
There may be any number of \fIoption\fR\-\fIvalue\fR pairs,
which provide configuration options for the new image.
The legal set of options is defined separately for each image
type;  see below for details on the options for built-in image types.
If an image already exists by the given name then it is replaced
with the new image and any instances of that image will redisplay
with the new contents.
It is important to note that the image command will silently overwrite any
procedure that may currently be defined by the given name, so choose the
name wisely.  It is recommended to use a separate namespace for image names
(e.g., \fB::img::logo\fR, \fB::img::large\fR).
.\" METHOD: delete
.TP
\fBimage delete \fR?\fIname name\fR ...?
.
Deletes each of the named images and returns an empty string.
If there are instances of the images displayed in widgets,
the images will not actually be deleted until all of the instances
are released.
However, the association between the instances and the image
manager will be dropped.
Existing instances will retain their sizes but redisplay as
empty areas.
If a deleted image is recreated with another call to \fBimage create\fR,
the existing instances will use the new image.
.\" METHOD: height
.TP
\fBimage height \fIname\fR
.
Returns a decimal string giving the height of image \fIname\fR
in pixels.
.\" METHOD: inuse
.TP
\fBimage inuse \fIname\fR
.
Returns a boolean value indicating whether or not the image given by
\fIname\fR is in use by any widgets.
.\" METHOD: names
.TP
\fBimage names\fR
.
Returns a list containing the names of all existing images.
.\" METHOD: type
.TP
\fBimage type \fIname\fR
.
Returns the type of image \fIname\fR (the value of the \fItype\fR
argument to \fBimage create\fR when the image was created).
.\" METHOD: types
.TP
\fBimage types\fR
.
Returns a list whose elements are all of the valid image types
(i.e., all of the values that may be supplied for the \fItype\fR
argument to \fBimage create\fR).
.\" METHOD: width
.TP
\fBimage width \fIname\fR
.
Returns a decimal string giving the width of image \fIname\fR
in pixels.
.PP
Additional operations (e.g. writing the image to a file) may be
available as subcommands of the image instance command. See the manual
page for the particular image type for details.
.SH "BUILT-IN IMAGE TYPES"
.PP
The following image types are defined by Tk so they will be available
in any Tk application.
Individual applications or extensions may define additional types.
.TP
.IP \fBbitmap\fR
\fBbitmap\fR
Each pixel in the image displays a foreground color, a background
color, or nothing.
See the \fBbitmap\fR manual entry for more information.
.TP
.IP \fBphoto\fR
\fBphoto\fR
Displays a variety of full-color images, using dithering to
approximate colors on displays with limited color capabilities.
See the \fBphoto\fR manual entry for more information.
.IP \fBnsimage\fR
This type is only available in the Aqua platform.  It is a full-color
image which may be created from a named system image.  It has options
designed to facilitate the use of these images in buttons.  An
\fBnsimage\fR can be based on an a \fItemplate image\fR, which is an
anti-aliased 2-color image format that automatically interchanges
black and white in response to changes between the light and dark
modes on macOS.  An \fBnsimage\fR can also generate an alternate
\fIpressed\fR variant which is lighter in dark mode and darker in
light mode.  These are for use in image buttons. See the \fBnsimage\fR
manual entry for more information.
.SH "SEE ALSO"
bitmap(n), options(n), photo(n), nsimage(n)
bitmap(n), options(n), photo(n)
.SH KEYWORDS
height, image, types of images, width
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/keysyms.n.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

























51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84














85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108















109
110
111
112
113
114
115
116
117
118
119
120
121





122
123
124
125
126




127
128

129
130
131
132
133
134


135
136
137


138
139
140
141
142
143



144
145

146
147
148
149
150


151
152
153
154


155
156

157
158
159
160
161
162





163
164
165
166


167
168
169
170
171
172




173
174

175
176
177
178
179



180
181
182
183
184
185
186





187
188

189
190
191
192
193
194





195
196
197
198


199
200
201
202
203
204





205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
















235
236
237
238
239

240
241
242
243
244
245
246
247





248
249
250
251
252
253
254






255
256
257
258
259
260
261
262
263




264
265
266
267
268
269





270
271
272


273
274

275
276

277
278
279

280
281
282
283
284




285
286

287
288

289
290

291
292
293


294
295
296
297
298



299
300
301
302
303
304
305
306







307
308
309
310
311
312
313






314
315
316
317
318
319
320
321
322


323
324
325
326



327
328

329
330
331
332
333




334
335
336
337
338
339
340
341
342
343
344






345
346
347

348
349
350
351
352
353
354
355
356
357
358
359
360













361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384















385
386
387
388
389
390
391
392
393
394
395
396




397
398
399
400


401
402

403
404
405
406
407
408
409


410
411
412
413
414
415
416






417
418
419
420



421
422
423
424
425
426





427
428
429
430
431



432
433
434
435
436


437
438
439
440
441
442
443
444



445
446
447


448
449
450


451
452
453
454
455
456
457
458







459
460
461
462
463


464
465
466


467
468
469
470



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487










488
489
490
491
492
493





494
495
496
497



498
499

500
501

502
503
504
505
506

507
508
509
510
511
512



513
514
515
516



517
518
519


520
521
522


523
524
525
526
527
528




529
530
531
532
533
534
535
536
537
538
539
540
541
542












543
544
545


546
547
548
549
550
551
552
553
554

555
556
557
558


559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579














580
581
582
583
584




585
586
587
588
589




590
591

592
593
594
595
596


597
598
599
600
601
602
603




604
605
606
607



608
609

610
611
612
613
614




615
616
617

618
619
620

621
622
623

624
625
626
627
628
629
630




631
632
633
634


635
636
637
638


639
640
641
642
643
644





645
646
647
648
649
650
651
652
653
654
655
656
657












658
659
660
661
662


663
664
665
666
667
668
669
670
671
672
673
674






675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690








691
692
693
694



695
696
697
698
699
700
701




702
703
704
705
706
707
708
709







710
711
712
713
714
715
716
717
718
719
720
721
722







723
724
725
726

727
728
729
730
731
732
733
734
735
736
737






738
739
740
741
742


743
744
745
746


747
748

749
750

751
752
753
754
755
756
757
758
759
760
761
762
763
764












765
766
767

768
769
770

771
772
773
774
775
776
777
778
779
780
781









782
783
784
785
786
787
788
789
790
791






792
793
794
795
796
797
798
799
800
801
802
803






804
805
806
807
808
809
810
811
812





813
814

815
816
817
818
819
820





821
822
823
824


825
826
827
828
829
830
831



832
833
834
835
836
837
838






839
840
841
842
843



844
845
846
847
848
849
850




851
852
853


854
855
856
857
858
859
860
861
862
863
864
865











866
867
868
869
870
871

872
873
874
875
876
877
878
879
880






881
882
883
884
885
886
887
888
889








890
891
892
893
894
895

896
897
898
899
900
901
902
903
904
905
906
907










908
909
910

911
912
913

914
915

916
917
918
919
920
921
922
923
924


925
926
927

928
929
930


931
932
933


934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957





















958
959
960
961
962
963
964
965
966
967
968
969
970


971
972
973
974
975
976




977
978
979
980
981
982
983
984







985
986
987
988

989
990
991
992
993
994



995
996
997
998
999
1000




1001
1002
1003
1004
1005
1006



1007
1008
1009
1010
1011




1012
1013

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025













1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044



1045
1046
1047
1048
1049
1050
1051






1052
1053
1054
1055
1056




1057
1058
1059
1060
1061
1062
1063





1064
1065
1066
1067



1068
1069
1070


1071
1072
1073
1074
1075



1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094









1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108






1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121









1122
1123
1124
1125
1126
1127





1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138




1139
1140
1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1151






1152
1153
1154
1155
1156
1157
1158
1159
1160
1161









1162
1163
1164
1165
1166
1167
1168
1169







1170
1171
1172
1173
1174
1175
1176



1177
1178
1179
1180
1181




1182
1183
1184
1185
1186
1187
1188


1189
1190
1191


1192
1193
1194
1195



1196
1197
1198
1199



1200
1201
1202
1203
1204
1205
1206


1207
1208

1209
1210
1211
1212
1213
1214
1215





1216
1217
1218
1219
1220
1221
1222





1223
1224
1225
1226
1227
1228
1229
1230






1231
1232
1233
1234
1235
1236




1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
















1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279














1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303













1304
1305
1306

1307
1308

1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320









1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331


1332
1333
1334
1335



1336
1337

1338
1339
1340


1341
1342
1343
1344
1345



1346
1347
1348
1349





1350
1351
1352

1353
1354
1355
1356
1357


1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368










1369
1370
1371
1372
1373
1374




1375
1376
1377
1378
1379
1380
1381
1382
1383
1384




1385
1386
1387


1388
1389
1390
1391
1392
1393
1394
1395
1396
1397









1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410





1411
1412
1413
1414
1415




1416
1417

1418
1419
1420


1421
1422
1423

1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448














1449
1450
1451
1452
1453
1454
1455
1456







1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468






1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479







1480
1481
1482
1483
1484
1485




1486
1487
1488


1489
1490
1491
1492
1493
1494
1495

1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1

2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20

21
22
23
24
25

























26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


































51
52
53
54
55
56
57
58
59
60
61
62
63
64







65

















66
67
68
69
70
71
72
73
74
75
76
77
78
79
80













81
82
83
84
85





86
87
88
89


90






91
92



93
94






95
96
97


98





99
100




101
102


103






104
105
106
107
108




109
110






111
112
113
114


115





116
117
118







119
120
121
122
123


124






125
126
127
128
129




130
131






132
133
134
135
136






























137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152





153








154
155
156
157
158







159
160
161
162
163
164









165
166
167
168






169
170
171
172
173



174
175


176


177



178





179
180
181
182


183


184


185



186
187





188
189
190








191
192
193
194
195
196
197







198
199
200
201
202
203









204
205




206
207
208


209





210
211
212
213











214
215
216
217
218
219



220













221
222
223
224
225
226
227
228
229
230
231
232
233
























234
235
236
237
238
239
240
241
242
243
244
245
246
247
248












249
250
251
252




253
254


255







256
257







258
259
260
261
262
263




264
265
266






267
268
269
270
271





272
273
274





275
276








277
278
279



280
281



282
283








284
285
286
287
288
289
290





291
292



293
294




295
296
297

















298
299
300
301
302
303
304
305
306
307






308
309
310
311
312




313
314
315


316


317





318






319
320
321




322
323
324



325
326



327
328






329
330
331
332














333
334
335
336
337
338
339
340
341
342
343
344



345
346









347




348
349





















350
351
352
353
354
355
356
357
358
359
360
361
362
363





364
365
366
367





368
369
370
371


372





373
374







375
376
377
378




379
380
381


382





383
384
385
386



387



388



389







390
391
392
393




394
395




396
397






398
399
400
401
402













403
404
405
406
407
408
409
410
411
412
413
414





415
416












417
418
419
420
421
422
















423
424
425
426
427
428
429
430




431
432
433







434
435
436
437








438
439
440
441
442
443
444













445
446
447
448
449
450
451




452











453
454
455
456
457
458





459
460




461
462


463


464














465
466
467
468
469
470
471
472
473
474
475
476



477



478











479
480
481
482
483
484
485
486
487










488
489
490
491
492
493












494
495
496
497
498
499









500
501
502
503
504


505






506
507
508
509
510




511
512







513
514
515







516
517
518
519
520
521





522
523
524







525
526
527
528



529
530












531
532
533
534
535
536
537
538
539
540
541






542









543
544
545
546
547
548









549
550
551
552
553
554
555
556






557












558
559
560
561
562
563
564
565
566
567



568



569


570









571
572



573



574
575



576
577
























578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598













599
600






601
602
603
604








605
606
607
608
609
610
611




612






613
614
615






616
617
618
619






620
621
622





623
624
625
626


627












628
629
630
631
632
633
634
635
636
637
638
639
640















641




642
643
644







645
646
647
648
649
650





651
652
653
654







655
656
657
658
659




660
661
662



663
664





665
666
667



668
















669
670
671
672
673
674
675
676
677














678
679
680
681
682
683













684
685
686
687
688
689
690
691
692






693
694
695
696
697











698
699
700
701





702








703
704
705
706
707
708










709
710
711
712
713
714
715
716
717








718
719
720
721
722
723
724







725
726
727





728
729
730
731







732
733



734
735




736
737
738




739
740
741







742
743


744







745
746
747
748
749







750
751
752
753
754








755
756
757
758
759
760






761
762
763
764






















765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780





















781
782
783
784
785
786
787
788
789
790
791
792
793
794
























795
796
797
798
799
800
801
802
803
804
805
806
807



808


809












810
811
812
813
814
815
816
817
818



819








820
821




822
823
824


825



826
827





828
829
830




831
832
833
834
835



836





837
838











839
840
841
842
843
844
845
846
847
848






849
850
851
852










853
854
855
856



857
858










859
860
861
862
863
864
865
866
867













868
869
870
871
872





873
874
875
876


877



878
879



880

























881
882
883
884
885
886
887
888
889
890
891
892
893
894








895
896
897
898
899
900
901




902








903
904
905
906
907
908











909
910
911
912
913
914
915






916
917
918
919



920
921







922
923
924
925
926
927
928
929























































































































































930
931
932
933
934
935
936

-
+












-
+





-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
+
+
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
+
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+
-
-
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 1998-2000 Scriptics Corporation.
'\" Copyright (c) 1998-2000 by Scriptics Corporation.
'\" All rights reserved.
'\"
.TH keysyms n 8.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
keysyms \- keysyms recognized by Tk
.BE
.SH DESCRIPTION
.PP
Tk recognizes many keysyms when specifying key bindings (e.g.,
.QW "\fBbind\fR \fB. <\fR\fIkeysym\fR\fB>\fR" ).
.QW "\fBbind\fR \fB. <Key-\fR\fIkeysym\fR\fB>\fR" ).
The following list enumerates the
keysyms that will be recognized by Tk.  Note that not all keysyms will
be valid on all platforms, and some keysyms are also available on
platforms that have a different native name for that key.
For example, on Unix systems, the presence
of a particular keysym is dependent on the configuration of the
of a particular keysym is dependant on the configuration of the
keyboard modifier map.  This list shows keysyms along with their
decimal and hexadecimal values.
.PP
.CS
space                               32     0x20
! (exclam)                          33     0x21
quotedbl                            34     0x22
numbersign                          35     0x23
dollar                              36     0x24
% (percent)                         37     0x25
& (ampersand)                       38     0x26
' (apostrophe)                      39     0x27
( (parenleft)                       40     0x28
) (parenright)                      41     0x29
* (asterisk)                        42     0x2A
+ (plus)                            43     0x2B
, (comma)                           44     0x2C
minus                               45     0x2D
. (period)                          46     0x2E
/ (slash)                           47     0x2F
0                                   48     0x30
1                                   49     0x31
2                                   50     0x32
3                                   51     0x33
4                                   52     0x34
5                                   53     0x35
6                                   54     0x36
7                                   55     0x37
8                                   56     0x38
space                               32     0x0020
exclam                              33     0x0021
quotedbl                            34     0x0022
numbersign                          35     0x0023
dollar                              36     0x0024
percent                             37     0x0025
ampersand                           38     0x0026
quoteright                          39     0x0027
parenleft                           40     0x0028
parenright                          41     0x0029
asterisk                            42     0x002a
plus                                43     0x002b
comma                               44     0x002c
minus                               45     0x002d
period                              46     0x002e
slash                               47     0x002f
0                                   48     0x0030
1                                   49     0x0031
2                                   50     0x0032
3                                   51     0x0033
4                                   52     0x0034
5                                   53     0x0035
6                                   54     0x0036
7                                   55     0x0037
8                                   56     0x0038
9                                   57     0x39
: (colon)                           58     0x3A
semicolon                           59     0x3B
less                                60     0x3C
= (equal)                           61     0x3D
greater                             62     0x3E
? (question)                        63     0x3F
@ (at)                              64     0x40
A                                   65     0x41
B                                   66     0x42
C                                   67     0x43
D                                   68     0x44
E                                   69     0x45
F                                   70     0x46
G                                   71     0x47
H                                   72     0x48
I                                   73     0x49
J                                   74     0x4A
K                                   75     0x4B
L                                   76     0x4C
M                                   77     0x4D
N                                   78     0x4E
O                                   79     0x4F
P                                   80     0x50
Q                                   81     0x51
R                                   82     0x52
S                                   83     0x53
T                                   84     0x54
U                                   85     0x55
V                                   86     0x56
W                                   87     0x57
X                                   88     0x58
Y                                   89     0x59
Z                                   90     0x5A
9                                   57     0x0039
colon                               58     0x003a
semicolon                           59     0x003b
less                                60     0x003c
equal                               61     0x003d
greater                             62     0x003e
question                            63     0x003f
at                                  64     0x0040
A                                   65     0x0041
B                                   66     0x0042
C                                   67     0x0043
D                                   68     0x0044
E                                   69     0x0045
F                                   70     0x0046
bracketleft                         91     0x5B
backslash                           92     0x5C
bracketright                        93     0x5D
^ (asciicircum)                     94     0x5E
_ (underscore)                      95     0x5F
` (grave)                           96     0x60
a                                   97     0x61
G                                   71     0x0047
b                                   98     0x62
c                                   99     0x63
d                                  100     0x64
e                                  101     0x65
f                                  102     0x66
g                                  103     0x67
h                                  104     0x68
i                                  105     0x69
j                                  106     0x6A
k                                  107     0x6B
l                                  108     0x6C
m                                  109     0x6D
n                                  110     0x6E
o                                  111     0x6F
p                                  112     0x70
q                                  113     0x71
r                                  114     0x72
H                                   72     0x0048
I                                   73     0x0049
J                                   74     0x004a
K                                   75     0x004b
L                                   76     0x004c
M                                   77     0x004d
N                                   78     0x004e
O                                   79     0x004f
P                                   80     0x0050
Q                                   81     0x0051
R                                   82     0x0052
S                                   83     0x0053
T                                   84     0x0054
U                                   85     0x0055
V                                   86     0x0056
s                                  115     0x73
t                                  116     0x74
u                                  117     0x75
v                                  118     0x76
w                                  119     0x77
x                                  120     0x78
y                                  121     0x79
z                                  122     0x7A
braceleft                          123     0x7B
| (bar)                            124     0x7C
braceright                         125     0x7D
~ (asciitilde)                     126     0x7E
nobreakspace                       160     0xA0
W                                   87     0x0057
X                                   88     0x0058
Y                                   89     0x0059
Z                                   90     0x005a
bracketleft                         91     0x005b
\(r! (exclamdown)                     161     0xA1
\(ct (cent)                           162     0xA2
\(Po (sterling)                       163     0xA3
\(Cs (currency)                       164     0xA4
\(Ye (yen)                            165     0xA5
backslash                           92     0x005c
bracketright                        93     0x005d
asciicircum                         94     0x005e
underscore                          95     0x005f
\(bb (brokenbar)                      166     0xA6
\(sc (section)                        167     0xA7
quoteleft                           96     0x0060
\(ad (diaeresis)                      168     0xA8
\(co (copyright)                      169     0xA9
\(Of (ordfeminine)                    170     0xAA
\(Fo (guillemetleft)                  171     0xAB
\(no (notsign)                        172     0xAC
hyphen                             173     0xAD
a                                   97     0x0061
b                                   98     0x0062
\(rg (registered)                     174     0xAE
\(a- (macron)                         175     0xAF
\(de (degree)                         176     0xB0
c                                   99     0x0063
d                                  100     0x0064
\(+- (plusminus)                      177     0xB1
\(S2 (twosuperior)                    178     0xB2
\(S3 (threesuperior)                  179     0xB3
\(aa (acute)                          180     0xB4
\(mc (mu)                             181     0xB5
\(ps (paragraph)                      182     0xB6
e                                  101     0x0065
f                                  102     0x0066
g                                  103     0x0067
\(pc (periodcentered)                 183     0xB7
\(ac (cedilla)                        184     0xB8
h                                  104     0x0068
\(S1 (onesuperior)                    185     0xB9
\(Om (ordmasculine)                   186     0xBA
\(Fc (guillemetright)                 187     0xBB
\(14 (onequarter)                     188     0xBC
\(12 (onehalf)                        189     0xBD
i                                  105     0x0069
j                                  106     0x006a
\(34 (threequarters)                  190     0xBE
\(r? (questiondown)                   191     0xBF
\(`A (Agrave)                         192     0xC0
\('A (Aacute)                         193     0xC1
k                                  107     0x006b
l                                  108     0x006c
\(^A (Acircumflex)                    194     0xC2
\(~A (Atilde)                         195     0xC3
m                                  109     0x006d
\(:A (Adiaeresis)                     196     0xC4
\(oA (Aring)                          197     0xC5
\(AE (AE)                             198     0xC6
\(,C (Ccedilla)                       199     0xC7
\(`E (Egrave)                         200     0xC8
\('E (Eacute)                         201     0xC9
n                                  110     0x006e
o                                  111     0x006f
p                                  112     0x0070
q                                  113     0x0071
r                                  114     0x0072
\(^E (Ecircumflex)                    202     0xCA
\(:E (Ediaeresis)                     203     0xCB
\(`I (Igrave)                         204     0xCC
\('I (Iacute)                         205     0xCD
s                                  115     0x0073
t                                  116     0x0074
\(^I (Icircumflex)                    206     0xCE
\(:I (Idiaeresis)                     207     0xCF
\(-D (ETH)                            208     0xD0
\(~N (Ntilde)                         209     0xD1
\(`O (Ograve)                         210     0xD2
\('O (Oacute)                         211     0xD3
u                                  117     0x0075
v                                  118     0x0076
w                                  119     0x0077
x                                  120     0x0078
\(^O (Ocircumflex)                    212     0xD4
\(~O (Otilde)                         213     0xD5
y                                  121     0x0079
\(:O (Odiaeresis)                     214     0xD6
\(mu (multiply)                       215     0xD7
\(/O (Oslash)                         216     0xD8
\(`U (Ugrave)                         217     0xD9
\('U (Uacute)                         218     0xDA
z                                  122     0x007a
braceleft                          123     0x007b
bar                                124     0x007c
\(^U (Ucircumflex)                    219     0xDB
\(:U (Udiaeresis)                     220     0xDC
\('Y (Yacute)                         221     0xDD
\(TP (THORN)                          222     0xDE
\(ss (ssharp)                         223     0xDF
\(`a (agrave)                         224     0xE0
\('a (aacute)                         225     0xE1
braceright                         125     0x007d
asciitilde                         126     0x007e
nobreakspace                       160     0x00a0
exclamdown                         161     0x00a1
cent                               162     0x00a2
\(^a (acircumflex)                    226     0xE2
\(~a (atilde)                         227     0xE3
sterling                           163     0x00a3
\(:a (adiaeresis)                     228     0xE4
\(oa (aring)                          229     0xE5
\(ae (ae)                             230     0xE6
\(,c (ccedilla)                       231     0xE7
\(`e (egrave)                         232     0xE8
\('e (eacute)                         233     0xE9
currency                           164     0x00a4
yen                                165     0x00a5
brokenbar                          166     0x00a6
section                            167     0x00a7
diaeresis                          168     0x00a8
\(^e (ecircumflex)                    234     0xEA
\(:e (ediaeresis)                     235     0xEB
\(`i (igrave)                         236     0xEC
\('i (iacute)                         237     0xED
copyright                          169     0x00a9
ordfeminine                        170     0x00aa
\(^i (icircumflex)                    238     0xEE
\(:i (idiaeresis)                     239     0xEF
\(Sd (eth)                            240     0xF0
\(~n (ntilde)                         241     0xF1
\(`o (ograve)                         242     0xF2
\('o (oacute)                         243     0xF3
guillemotleft                      171     0x00ab
notsign                            172     0x00ac
hyphen                             173     0x00ad
registered                         174     0x00ae
macron                             175     0x00af
\(^o (ocircumflex)                    244     0xF4
\(~o (otilde)                         245     0xF5
\(:o (odiaeresis)                     246     0xF6
\(di (division)                       247     0xF7
\(/o (oslash)                         248     0xF8
\(`u (ugrave)                         249     0xF9
\('u (uacute)                         250     0xFA
\(^u (ucircumflex)                    251     0xFB
\(:u (udiaeresis)                     252     0xFC
\('y (yacute)                         253     0xFD
\(Tp (thorn)                          254     0xFE
\(:y (ydiaeresis)                     255     0xFF
.CE
.CS
Aogonek                            417     0x1A1
breve                              418     0x1A2
Lstroke                            419     0x1A3
Lcaron                             421     0x1A5
Sacute                             422     0x1A6
Scaron                             425     0x1A9
Scedilla                           426     0x1AA
Tcaron                             427     0x1AB
Zacute                             428     0x1AC
Zcaron                             430     0x1AE
Zabovedot                          431     0x1AF
aogonek                            433     0x1B1
ogonek                             434     0x1B2
lstroke                            435     0x1B3
lcaron                             437     0x1B5
sacute                             438     0x1B6
degree                             176     0x00b0
plusminus                          177     0x00b1
twosuperior                        178     0x00b2
threesuperior                      179     0x00b3
acute                              180     0x00b4
mu                                 181     0x00b5
paragraph                          182     0x00b6
periodcentered                     183     0x00b7
cedilla                            184     0x00b8
onesuperior                        185     0x00b9
masculine                          186     0x00ba
guillemotright                     187     0x00bb
onequarter                         188     0x00bc
onehalf                            189     0x00bd
threequarters                      190     0x00be
questiondown                       191     0x00bf
caron                              439     0x1B7
scaron                             441     0x1B9
scedilla                           442     0x1BA
tcaron                             443     0x1BB
zacute                             444     0x1BC
Agrave                             192     0x00c0
doubleacute                        445     0x1BD
zcaron                             446     0x1BE
zabovedot                          447     0x1BF
Racute                             448     0x1C0
Abreve                             451     0x1C3
Lacute                             453     0x1C5
Cacute                             454     0x1C6
Ccaron                             456     0x1C8
Aacute                             193     0x00c1
Acircumflex                        194     0x00c2
Atilde                             195     0x00c3
Adiaeresis                         196     0x00c4
Aring                              197     0x00c5
Eogonek                            458     0x1CA
Ecaron                             460     0x1CC
Dcaron                             463     0x1CF
Dstroke                            464     0x1D0
Nacute                             465     0x1D1
Ncaron                             466     0x1D2
Odoubleacute                       469     0x1D5
AE                                 198     0x00c6
Ccedilla                           199     0x00c7
Egrave                             200     0x00c8
Eacute                             201     0x00c9
Ecircumflex                        202     0x00ca
Ediaeresis                         203     0x00cb
Rcaron                             472     0x1D8
Uring                              473     0x1D9
Udoubleacute                       475     0x1DB
Tcedilla                           478     0x1DE
racute                             480     0x1E0
abreve                             483     0x1E3
lacute                             485     0x1E5
cacute                             486     0x1E6
ccaron                             488     0x1E8
Igrave                             204     0x00cc
Iacute                             205     0x00cd
Icircumflex                        206     0x00ce
Idiaeresis                         207     0x00cf
eogonek                            490     0x1EA
ecaron                             492     0x1EC
dcaron                             495     0x1EF
dstroke                            496     0x1F0
nacute                             497     0x1F1
ncaron                             498     0x1F2
Eth                                208     0x00d0
Ntilde                             209     0x00d1
Ograve                             210     0x00d2
Oacute                             211     0x00d3
Ocircumflex                        212     0x00d4
odoubleacute                       501     0x1F5
rcaron                             504     0x1F8
uring                              505     0x1F9
Otilde                             213     0x00d5
Odiaeresis                         214     0x00d6
udoubleacute                       507     0x1FB
tcedilla                           510     0x1FE
multiply                           215     0x00d7
abovedot                           511     0x1FF
Hstroke                            673     0x2A1
Ooblique                           216     0x00d8
Hcircumflex                        678     0x2A6
Iabovedot                          681     0x2A9
Gbreve                             683     0x2AB
Ugrave                             217     0x00d9
Jcircumflex                        684     0x2AC
hstroke                            689     0x2B1
hcircumflex                        694     0x2B6
idotless                           697     0x2B9
gbreve                             699     0x2BB
Uacute                             218     0x00da
Ucircumflex                        219     0x00db
Udiaeresis                         220     0x00dc
Yacute                             221     0x00dd
jcircumflex                        700     0x2BC
Cabovedot                          709     0x2C5
Thorn                              222     0x00de
Ccircumflex                        710     0x2C6
Gabovedot                          725     0x2D5
ssharp                             223     0x00df
Gcircumflex                        728     0x2D8
Ubreve                             733     0x2DD
agrave                             224     0x00e0
Scircumflex                        734     0x2DE
cabovedot                          741     0x2E5
ccircumflex                        742     0x2E6
aacute                             225     0x00e1
acircumflex                        226     0x00e2
gabovedot                          757     0x2F5
gcircumflex                        760     0x2F8
ubreve                             765     0x2FD
scircumflex                        766     0x2FE
kra                                930     0x3A2
atilde                             227     0x00e3
adiaeresis                         228     0x00e4
aring                              229     0x00e5
Rcedilla                           931     0x3A3
Itilde                             933     0x3A5
Lcedilla                           934     0x3A6
Emacron                            938     0x3AA
Gcedilla                           939     0x3AB
Tslash                             940     0x3AC
rcedilla                           947     0x3B3
itilde                             949     0x3B5
ae                                 230     0x00e6
ccedilla                           231     0x00e7
egrave                             232     0x00e8
eacute                             233     0x00e9
ecircumflex                        234     0x00ea
ediaeresis                         235     0x00eb
igrave                             236     0x00ec
lcedilla                           950     0x3B6
emacron                            954     0x3BA
gcedilla                           955     0x3BB
tslash                             956     0x3BC
ENG                                957     0x3BD
eng                                959     0x3BF
Amacron                            960     0x3C0
iacute                             237     0x00ed
icircumflex                        238     0x00ee
idiaeresis                         239     0x00ef
eth                                240     0x00f0
ntilde                             241     0x00f1
ograve                             242     0x00f2
Iogonek                            967     0x3C7
Eabovedot                          972     0x3CC
Imacron                            975     0x3CF
Ncedilla                           977     0x3D1
Omacron                            978     0x3D2
Kcedilla                           979     0x3D3
Uogonek                            985     0x3D9
Utilde                             989     0x3DD
Umacron                            990     0x3DE
oacute                             243     0x00f3
ocircumflex                        244     0x00f4
amacron                            992     0x3E0
iogonek                            999     0x3E7
eabovedot                         1004     0x3EC
imacron                           1007     0x3EF
otilde                             245     0x00f5
odiaeresis                         246     0x00f6
division                           247     0x00f7
ncedilla                          1009     0x3F1
omacron                           1010     0x3F2
oslash                             248     0x00f8
kcedilla                          1011     0x3F3
uogonek                           1017     0x3F9
utilde                            1021     0x3FD
umacron                           1022     0x3FE
overline                          1150     0x47E
ugrave                             249     0x00f9
uacute                             250     0x00fa
ucircumflex                        251     0x00fb
udiaeresis                         252     0x00fc
kana_fullstop                     1185     0x4A1
kana_openingbracket               1186     0x4A2
kana_closingbracket               1187     0x4A3
kana_comma                        1188     0x4A4
kana_conjunctive                  1189     0x4A5
kana_WO                           1190     0x4A6
kana_a                            1191     0x4A7
kana_i                            1192     0x4A8
kana_u                            1193     0x4A9
kana_e                            1194     0x4AA
kana_o                            1195     0x4AB
yacute                             253     0x00fd
thorn                              254     0x00fe
ydiaeresis                         255     0x00ff
Aogonek                            417     0x01a1
breve                              418     0x01a2
Lstroke                            419     0x01a3
kana_ya                           1196     0x4AC
kana_yu                           1197     0x4AD
kana_yo                           1198     0x4AE
Lcaron                             421     0x01a5
kana_tsu                          1199     0x4AF
prolongedsound                    1200     0x4B0
kana_A                            1201     0x4B1
kana_I                            1202     0x4B2
kana_U                            1203     0x4B3
kana_E                            1204     0x4B4
kana_O                            1205     0x4B5
kana_KA                           1206     0x4B6
kana_KI                           1207     0x4B7
kana_KU                           1208     0x4B8
kana_KE                           1209     0x4B9
kana_KO                           1210     0x4BA
kana_SA                           1211     0x4BB
Sacute                             422     0x01a6
Scaron                             425     0x01a9
Scedilla                           426     0x01aa
Tcaron                             427     0x01ab
Zacute                             428     0x01ac
.CE
.CS
Zcaron                             430     0x01ae
Zabovedot                          431     0x01af
aogonek                            433     0x01b1
ogonek                             434     0x01b2
lstroke                            435     0x01b3
lcaron                             437     0x01b5
kana_SHI                          1212     0x4BC
kana_SU                           1213     0x4BD
kana_SE                           1214     0x4BE
kana_SO                           1215     0x4BF
kana_TA                           1216     0x4C0
kana_CHI                          1217     0x4C1
kana_TSU                          1218     0x4C2
kana_TE                           1219     0x4C3
kana_TO                           1220     0x4C4
kana_NA                           1221     0x4C5
kana_NI                           1222     0x4C6
kana_NU                           1223     0x4C7
kana_NE                           1224     0x4C8
kana_NO                           1225     0x4C9
kana_HA                           1226     0x4CA
kana_HI                           1227     0x4CB
kana_FU                           1228     0x4CC
kana_HE                           1229     0x4CD
kana_HO                           1230     0x4CE
kana_MA                           1231     0x4CF
kana_MI                           1232     0x4D0
kana_MU                           1233     0x4D1
kana_ME                           1234     0x4D2
kana_MO                           1235     0x4D3
sacute                             438     0x01b6
caron                              439     0x01b7
scaron                             441     0x01b9
scedilla                           442     0x01ba
tcaron                             443     0x01bb
zacute                             444     0x01bc
doubleacute                        445     0x01bd
zcaron                             446     0x01be
zabovedot                          447     0x01bf
Racute                             448     0x01c0
Abreve                             451     0x01c3
Cacute                             454     0x01c6
Ccaron                             456     0x01c8
Eogonek                            458     0x01ca
Ecaron                             460     0x01cc
kana_YA                           1236     0x4D4
kana_YU                           1237     0x4D5
kana_YO                           1238     0x4D6
kana_RA                           1239     0x4D7
kana_RI                           1240     0x4D8
kana_RU                           1241     0x4D9
kana_RE                           1242     0x4DA
kana_RO                           1243     0x4DB
kana_WA                           1244     0x4DC
kana_N                            1245     0x4DD
voicedsound                       1246     0x4DE
semivoicedsound                   1247     0x4DF
Dcaron                             463     0x01cf
Nacute                             465     0x01d1
Ncaron                             466     0x01d2
Odoubleacute                       469     0x01d5
.CE
.CS
Arabic_comma                      1452     0x5AC
Arabic_semicolon                  1467     0x5BB
Rcaron                             472     0x01d8
Uring                              473     0x01d9
Arabic_question_mark              1471     0x5BF
Arabic_hamza                      1473     0x5C1
Udoubleacute                       475     0x01db
Arabic_maddaonalef                1474     0x5C2
Arabic_hamzaonalef                1475     0x5C3
Arabic_hamzaonwaw                 1476     0x5C4
Arabic_hamzaunderalef             1477     0x5C5
Arabic_hamzaonyeh                 1478     0x5C6
Arabic_alef                       1479     0x5C7
Arabic_beh                        1480     0x5C8
Tcedilla                           478     0x01de
racute                             480     0x01e0
Arabic_tehmarbuta                 1481     0x5C9
Arabic_teh                        1482     0x5CA
Arabic_theh                       1483     0x5CB
Arabic_jeem                       1484     0x5CC
Arabic_hah                        1485     0x5CD
Arabic_khah                       1486     0x5CE
Arabic_dal                        1487     0x5CF
abreve                             483     0x01e3
cacute                             486     0x01e6
ccaron                             488     0x01e8
eogonek                            490     0x01ea
ecaron                             492     0x01ec
dcaron                             495     0x01ef
Arabic_thal                       1488     0x5D0
Arabic_ra                         1489     0x5D1
Arabic_zain                       1490     0x5D2
Arabic_seen                       1491     0x5D3
nacute                             497     0x01f1
ncaron                             498     0x01f2
odoubleacute                       501     0x01f5
Arabic_sheen                      1492     0x5D4
Arabic_sad                        1493     0x5D5
Arabic_dad                        1494     0x5D6
Arabic_tah                        1495     0x5D7
Arabic_zah                        1496     0x5D8
Arabic_ain                        1497     0x5D9
rcaron                             504     0x01f8
uring                              505     0x01f9
udoubleacute                       507     0x01fb
tcedilla                           510     0x01fe
abovedot                           511     0x01ff
Arabic_ghain                      1498     0x5DA
Arabic_tatweel                    1504     0x5E0
Arabic_feh                        1505     0x5E1
Arabic_qaf                        1506     0x5E2
Arabic_kaf                        1507     0x5E3
Hstroke                            673     0x02a1
Hcircumflex                        678     0x02a6
Iabovedot                          681     0x02a9
Arabic_lam                        1508     0x5E4
Arabic_meem                       1509     0x5E5
Arabic_noon                       1510     0x5E6
Arabic_ha                         1511     0x5E7
Arabic_waw                        1512     0x5E8
Gbreve                             683     0x02ab
Jcircumflex                        684     0x02ac
Arabic_alefmaksura                1513     0x5E9
Arabic_yeh                        1514     0x5EA
Arabic_fathatan                   1515     0x5EB
Arabic_dammatan                   1516     0x5EC
Arabic_kasratan                   1517     0x5ED
Arabic_fatha                      1518     0x5EE
Arabic_damma                      1519     0x5EF
Arabic_kasra                      1520     0x5F0
hstroke                            689     0x02b1
hcircumflex                        694     0x02b6
idotless                           697     0x02b9
Arabic_shadda                     1521     0x5F1
Arabic_sukun                      1522     0x5F2
Serbian_dje                       1697     0x6A1
gbreve                             699     0x02bb
jcircumflex                        700     0x02bc
Macedonia_gje                     1698     0x6A2
Cyrillic_io                       1699     0x6A3
Ukrainian_ie                      1700     0x6A4
Cabovedot                          709     0x02c5
Ccircumflex                        710     0x02c6
Macedonia_dse                     1701     0x6A5
Ukrainian_i                       1702     0x6A6
Ukrainian_yi                      1703     0x6A7
Cyrillic_je                       1704     0x6A8
Cyrillic_lje                      1705     0x6A9
Cyrillic_nje                      1706     0x6AA
Serbian_tshe                      1707     0x6AB
Macedonia_kje                     1708     0x6AC
Gabovedot                          725     0x02d5
Gcircumflex                        728     0x02d8
Ubreve                             733     0x02dd
Scircumflex                        734     0x02de
cabovedot                          741     0x02e5
ccircumflex                        742     0x02e6
gabovedot                          757     0x02f5
Ukrainian_ghe_with_upturn         1709     0x6AD
Byelorussian_shortu               1710     0x6AE
Cyrillic_dzhe                     1711     0x6AF
numerosign                        1712     0x6B0
Serbian_DJE                       1713     0x6B1
gcircumflex                        760     0x02f8
ubreve                             765     0x02fd
Macedonia_GJE                     1714     0x6B2
Cyrillic_IO                       1715     0x6B3
Ukrainian_IE                      1716     0x6B4
scircumflex                        766     0x02fe
kappa                              930     0x03a2
Macedonia_DSE                     1717     0x6B5
Ukrainian_I                       1718     0x6B6
Ukrainian_YI                      1719     0x6B7
Cyrillic_JE                       1720     0x6B8
Rcedilla                           931     0x03a3
Itilde                             933     0x03a5
Lcedilla                           934     0x03a6
Cyrillic_LJE                      1721     0x6B9
Cyrillic_NJE                      1722     0x6BA
Serbian_TSHE                      1723     0x6BB
Macedonia_KJE                     1724     0x6BC
Ukrainian_GHE_WITH_UPTURN         1725     0x6BD
Byelorussian_SHORTU               1726     0x6BE
Cyrillic_DZHE                     1727     0x6BF
Cyrillic_yu                       1728     0x6C0
Cyrillic_a                        1729     0x6C1
Cyrillic_be                       1730     0x6C2
Cyrillic_tse                      1731     0x6C3
Cyrillic_de                       1732     0x6C4
Cyrillic_ie                       1733     0x6C5
Cyrillic_ef                       1734     0x6C6
Cyrillic_ghe                      1735     0x6C7
Cyrillic_ha                       1736     0x6C8
Cyrillic_i                        1737     0x6C9
Emacron                            938     0x03aa
Gcedilla                           939     0x03ab
Tslash                             940     0x03ac
rcedilla                           947     0x03b3
itilde                             949     0x03b5
lcedilla                           950     0x03b6
emacron                            954     0x03ba
gacute                             955     0x03bb
tslash                             956     0x03bc
ENG                                957     0x03bd
Cyrillic_shorti                   1738     0x6CA
Cyrillic_ka                       1739     0x6CB
Cyrillic_el                       1740     0x6CC
Cyrillic_em                       1741     0x6CD
Cyrillic_en                       1742     0x6CE
Cyrillic_o                        1743     0x6CF
eng                                959     0x03bf
Amacron                            960     0x03c0
Iogonek                            967     0x03c7
Eabovedot                          972     0x03cc
Imacron                            975     0x03cf
Cyrillic_pe                       1744     0x6D0
Cyrillic_ya                       1745     0x6D1
Cyrillic_er                       1746     0x6D2
Cyrillic_es                       1747     0x6D3
Ncedilla                           977     0x03d1
Omacron                            978     0x03d2
Kcedilla                           979     0x03d3
Cyrillic_te                       1748     0x6D4
Cyrillic_u                        1749     0x6D5
Uogonek                            985     0x03d9
Cyrillic_zhe                      1750     0x6D6
Cyrillic_ve                       1751     0x6D7
Utilde                             989     0x03dd
Cyrillic_softsign                 1752     0x6D8
Cyrillic_yeru                     1753     0x6D9
Cyrillic_ze                       1754     0x6DA
Cyrillic_sha                      1755     0x6DB
Cyrillic_e                        1756     0x6DC
Umacron                            990     0x03de
Cyrillic_shcha                    1757     0x6DD
Cyrillic_che                      1758     0x6DE
Cyrillic_hardsign                 1759     0x6DF
Cyrillic_YU                       1760     0x6E0
Cyrillic_A                        1761     0x6E1
Cyrillic_BE                       1762     0x6E2
amacron                            992     0x03e0
iogonek                            999     0x03e7
eabovedot                         1004     0x03ec
Cyrillic_TSE                      1763     0x6E3
Cyrillic_DE                       1764     0x6E4
Cyrillic_IE                       1765     0x6E5
Cyrillic_EF                       1766     0x6E6
imacron                           1007     0x03ef
ncedilla                          1009     0x03f1
omacron                           1010     0x03f2
Cyrillic_GHE                      1767     0x6E7
Cyrillic_HA                       1768     0x6E8
Cyrillic_I                        1769     0x6E9
kcedilla                          1011     0x03f3
uogonek                           1017     0x03f9
Cyrillic_SHORTI                   1770     0x6EA
Cyrillic_KA                       1771     0x6EB
Cyrillic_EL                       1772     0x6EC
utilde                            1021     0x03fd
umacron                           1022     0x03fe
Cyrillic_EM                       1773     0x6ED
Cyrillic_EN                       1774     0x6EE
Cyrillic_O                        1775     0x6EF
Cyrillic_PE                       1776     0x6F0
Cyrillic_YA                       1777     0x6F1
Cyrillic_ER                       1778     0x6F2
overline                          1150     0x047e
kana_fullstop                     1185     0x04a1
kana_openingbracket               1186     0x04a2
kana_closingbracket               1187     0x04a3
Cyrillic_ES                       1779     0x6F3
Cyrillic_TE                       1780     0x6F4
Cyrillic_U                        1781     0x6F5
Cyrillic_ZHE                      1782     0x6F6
Cyrillic_VE                       1783     0x6F7
Cyrillic_SOFTSIGN                 1784     0x6F8
Cyrillic_YERU                     1785     0x6F9
Cyrillic_ZE                       1786     0x6FA
Cyrillic_SHA                      1787     0x6FB
Cyrillic_E                        1788     0x6FC
Cyrillic_SHCHA                    1789     0x6FD
Cyrillic_CHE                      1790     0x6FE
Cyrillic_HARDSIGN                 1791     0x6FF
Greek_ALPHAaccent                 1953     0x7A1
kana_comma                        1188     0x04a4
kana_middledot                    1189     0x04a5
kana_WO                           1190     0x04a6
kana_a                            1191     0x04a7
kana_i                            1192     0x04a8
kana_u                            1193     0x04a9
kana_e                            1194     0x04aa
kana_o                            1195     0x04ab
kana_ya                           1196     0x04ac
kana_yu                           1197     0x04ad
kana_yo                           1198     0x04ae
kana_tu                           1199     0x04af
Greek_EPSILONaccent               1954     0x7A2
Greek_ETAaccent                   1955     0x7A3
Greek_IOTAaccent                  1956     0x7A4
prolongedsound                    1200     0x04b0
kana_A                            1201     0x04b1
Greek_IOTAdieresis                1957     0x7A5
Greek_IOTAaccentdiaeresis         1958     0x7A6
Greek_OMICRONaccent               1959     0x7A7
Greek_UPSILONaccent               1960     0x7A8
Greek_UPSILONdieresis             1961     0x7A9
Greek_UPSILONaccentdieresis       1962     0x7AA
Greek_OMEGAaccent                 1963     0x7AB
Greek_accentdieresis              1966     0x7AE
Greek_horizbar                    1967     0x7AF
kana_I                            1202     0x04b2
Greek_alphaaccent                 1969     0x7B1
Greek_epsilonaccent               1970     0x7B2
Greek_etaaccent                   1971     0x7B3
Greek_iotaaccent                  1972     0x7B4
kana_U                            1203     0x04b3
kana_E                            1204     0x04b4
Greek_iotadieresis                1973     0x7B5
Greek_iotaaccentdieresis          1974     0x7B6
Greek_omicronaccent               1975     0x7B7
Greek_upsilonaccent               1976     0x7B8
Greek_upsilondieresis             1977     0x7B9
Greek_upsilonaccentdieresis       1978     0x7BA
Greek_omegaaccent                 1979     0x7BB
Greek_ALPHA                       1985     0x7C1
Greek_BETA                        1986     0x7C2
Greek_GAMMA                       1987     0x7C3
Greek_DELTA                       1988     0x7C4
Greek_EPSILON                     1989     0x7C5
Greek_ZETA                        1990     0x7C6
Greek_ETA                         1991     0x7C7
Greek_THETA                       1992     0x7C8
Greek_IOTA                        1993     0x7C9
Greek_KAPPA                       1994     0x7CA
Greek_LAMDA                       1995     0x7CB
Greek_MU                          1996     0x7CC
Greek_NU                          1997     0x7CD
Greek_XI                          1998     0x7CE
kana_O                            1205     0x04b5
kana_KA                           1206     0x04b6
kana_KI                           1207     0x04b7
kana_KU                           1208     0x04b8
kana_KE                           1209     0x04b9
kana_KO                           1210     0x04ba
kana_SA                           1211     0x04bb
kana_SHI                          1212     0x04bc
kana_SU                           1213     0x04bd
kana_SE                           1214     0x04be
kana_SO                           1215     0x04bf
kana_TA                           1216     0x04c0
kana_TI                           1217     0x04c1
kana_TU                           1218     0x04c2
Greek_OMICRON                     1999     0x7CF
Greek_PI                          2000     0x7D0
Greek_RHO                         2001     0x7D1
Greek_SIGMA                       2002     0x7D2
Greek_TAU                         2004     0x7D4
kana_TE                           1219     0x04c3
kana_TO                           1220     0x04c4
kana_NA                           1221     0x04c5
kana_NI                           1222     0x04c6
Greek_UPSILON                     2005     0x7D5
Greek_PHI                         2006     0x7D6
Greek_CHI                         2007     0x7D7
Greek_PSI                         2008     0x7D8
Greek_OMEGA                       2009     0x7D9
kana_NU                           1223     0x04c7
kana_NE                           1224     0x04c8
kana_NO                           1225     0x04c9
kana_HA                           1226     0x04ca
Greek_alpha                       2017     0x7E1
Greek_beta                        2018     0x7E2
kana_HI                           1227     0x04cb
Greek_gamma                       2019     0x7E3
Greek_delta                       2020     0x7E4
Greek_epsilon                     2021     0x7E5
Greek_zeta                        2022     0x7E6
Greek_eta                         2023     0x7E7
kana_HU                           1228     0x04cc
kana_HE                           1229     0x04cd
Greek_theta                       2024     0x7E8
Greek_iota                        2025     0x7E9
Greek_kappa                       2026     0x7EA
Greek_lamda                       2027     0x7EB
Greek_mu                          2028     0x7EC
Greek_nu                          2029     0x7ED
Greek_xi                          2030     0x7EE
kana_HO                           1230     0x04ce
kana_MA                           1231     0x04cf
kana_MI                           1232     0x04d0
kana_MU                           1233     0x04d1
Greek_omicron                     2031     0x7EF
Greek_pi                          2032     0x7F0
Greek_rho                         2033     0x7F1
Greek_sigma                       2034     0x7F2
kana_ME                           1234     0x04d2
kana_MO                           1235     0x04d3
kana_YA                           1236     0x04d4
Greek_finalsmallsigma             2035     0x7F3
Greek_tau                         2036     0x7F4
kana_YU                           1237     0x04d5
Greek_upsilon                     2037     0x7F5
Greek_phi                         2038     0x7F6
Greek_chi                         2039     0x7F7
Greek_psi                         2040     0x7F8
Greek_omega                       2041     0x7F9
kana_YO                           1238     0x04d6
kana_RA                           1239     0x04d7
kana_RI                           1240     0x04d8
kana_RU                           1241     0x04d9
.CE
.CS
leftradical                       2209     0x8A1
kana_RE                           1242     0x04da
topleftradical                    2210     0x8A2
horizconnector                    2211     0x8A3
topintegral                       2212     0x8A4
kana_RO                           1243     0x04db
botintegral                       2213     0x8A5
vertconnector                     2214     0x8A6
topleftsqbracket                  2215     0x8A7
kana_WA                           1244     0x04dc
botleftsqbracket                  2216     0x8A8
toprightsqbracket                 2217     0x8A9
botrightsqbracket                 2218     0x8AA
topleftparens                     2219     0x8AB
botleftparens                     2220     0x8AC
toprightparens                    2221     0x8AD
botrightparens                    2222     0x8AE
kana_N                            1245     0x04dd
voicedsound                       1246     0x04de
semivoicedsound                   1247     0x04df
Arabic_comma                      1452     0x05ac
leftmiddlecurlybrace              2223     0x8AF
rightmiddlecurlybrace             2224     0x8B0
topleftsummation                  2225     0x8B1
botleftsummation                  2226     0x8B2
Arabic_semicolon                  1467     0x05bb
Arabic_question_mark              1471     0x05bf
topvertsummationconnector         2227     0x8B3
botvertsummationconnector         2228     0x8B4
toprightsummation                 2229     0x8B5
botrightsummation                 2230     0x8B6
Arabic_hamza                      1473     0x05c1
Arabic_maddaonalef                1474     0x05c2
rightmiddlesummation              2231     0x8B7
lessthanequal                     2236     0x8BC
notequal                          2237     0x8BD
greaterthanequal                  2238     0x8BE
integral                          2239     0x8BF
therefore                         2240     0x8C0
Arabic_hamzaonalef                1475     0x05c3
Arabic_hamzaonwaw                 1476     0x05c4
Arabic_hamzaunderalef             1477     0x05c5
Arabic_hamzaonyeh                 1478     0x05c6
Arabic_alef                       1479     0x05c7
variation                         2241     0x8C1
infinity                          2242     0x8C2
nabla                             2245     0x8C5
approximate                       2248     0x8C8
similarequal                      2249     0x8C9
ifonlyif                          2253     0x8CD
implies                           2254     0x8CE
identical                         2255     0x8CF
radical                           2262     0x8D6
includedin                        2266     0x8DA
includes                          2267     0x8DB
intersection                      2268     0x8DC
union                             2269     0x8DD
Arabic_beh                        1480     0x05c8
Arabic_tehmarbuta                 1481     0x05c9
Arabic_teh                        1482     0x05ca
Arabic_theh                       1483     0x05cb
Arabic_jeem                       1484     0x05cc
Arabic_hah                        1485     0x05cd
Arabic_khah                       1486     0x05ce
Arabic_dal                        1487     0x05cf
Arabic_thal                       1488     0x05d0
Arabic_ra                         1489     0x05d1
Arabic_zain                       1490     0x05d2
Arabic_seen                       1491     0x05d3
logicaland                        2270     0x8DE
logicalor                         2271     0x8DF
partialderivative                 2287     0x8EF
function                          2294     0x8F6
leftarrow                         2299     0x8FB
Arabic_sheen                      1492     0x05d4
Arabic_sad                        1493     0x05d5
uparrow                           2300     0x8FC
rightarrow                        2301     0x8FD
downarrow                         2302     0x8FE
blank                             2527     0x9DF
soliddiamond                      2528     0x9E0
checkerboard                      2529     0x9E1
ht                                2530     0x9E2
ff                                2531     0x9E3
cr                                2532     0x9E4
lf                                2533     0x9E5
nl                                2536     0x9E8
vt                                2537     0x9E9
Arabic_dad                        1494     0x05d6
Arabic_tah                        1495     0x05d7
Arabic_zah                        1496     0x05d8
Arabic_ain                        1497     0x05d9
Arabic_ghain                      1498     0x05da
Arabic_tatweel                    1504     0x05e0
lowrightcorner                    2538     0x9EA
uprightcorner                     2539     0x9EB
upleftcorner                      2540     0x9EC
lowleftcorner                     2541     0x9ED
crossinglines                     2542     0x9EE
horizlinescan1                    2543     0x9EF
horizlinescan3                    2544     0x9F0
horizlinescan5                    2545     0x9F1
horizlinescan7                    2546     0x9F2
horizlinescan9                    2547     0x9F3
leftt                             2548     0x9F4
rightt                            2549     0x9F5
bott                              2550     0x9F6
topt                              2551     0x9F7
vertbar                           2552     0x9F8
emspace                           2721     0xAA1
Arabic_feh                        1505     0x05e1
Arabic_qaf                        1506     0x05e2
Arabic_kaf                        1507     0x05e3
Arabic_lam                        1508     0x05e4
Arabic_meem                       1509     0x05e5
.CE
.CS
Arabic_noon                       1510     0x05e6
enspace                           2722     0xAA2
em3space                          2723     0xAA3
em4space                          2724     0xAA4
digitspace                        2725     0xAA5
Arabic_heh                        1511     0x05e7
Arabic_waw                        1512     0x05e8
Arabic_alefmaksura                1513     0x05e9
punctspace                        2726     0xAA6
thinspace                         2727     0xAA7
hairspace                         2728     0xAA8
emdash                            2729     0xAA9
endash                            2730     0xAAA
signifblank                       2732     0xAAC
ellipsis                          2734     0xAAE
Arabic_yeh                        1514     0x05ea
Arabic_fathatan                   1515     0x05eb
Arabic_dammatan                   1516     0x05ec
Arabic_kasratan                   1517     0x05ed
doubbaselinedot                   2735     0xAAF
onethird                          2736     0xAB0
twothirds                         2737     0xAB1
onefifth                          2738     0xAB2
twofifths                         2739     0xAB3
threefifths                       2740     0xAB4
fourfifths                        2741     0xAB5
onesixth                          2742     0xAB6
Arabic_fatha                      1518     0x05ee
Arabic_damma                      1519     0x05ef
Arabic_kasra                      1520     0x05f0
Arabic_shadda                     1521     0x05f1
Arabic_sukun                      1522     0x05f2
Serbian_dje                       1697     0x06a1
Macedonia_gje                     1698     0x06a2
fivesixths                        2743     0xAB7
careof                            2744     0xAB8
figdash                           2747     0xABB
leftanglebracket                  2748     0xABC
decimalpoint                      2749     0xABD
rightanglebracket                 2750     0xABE
marker                            2751     0xABF
oneeighth                         2755     0xAC3
threeeighths                      2756     0xAC4
fiveeighths                       2757     0xAC5
seveneighths                      2758     0xAC6
trademark                         2761     0xAC9
signaturemark                     2762     0xACA
Cyrillic_io                       1699     0x06a3
Ukranian_je                       1700     0x06a4
Macedonia_dse                     1701     0x06a5
Ukranian_i                        1702     0x06a6
Ukranian_yi                       1703     0x06a7
Serbian_je                        1704     0x06a8
Serbian_lje                       1705     0x06a9
trademarkincircle                 2763     0xACB
leftopentriangle                  2764     0xACC
rightopentriangle                 2765     0xACD
emopencircle                      2766     0xACE
Serbian_nje                       1706     0x06aa
emopenrectangle                   2767     0xACF
leftsinglequotemark               2768     0xAD0
rightsinglequotemark              2769     0xAD1
leftdoublequotemark               2770     0xAD2
rightdoublequotemark              2771     0xAD3
prescription                      2772     0xAD4
permille                          2773     0xAD5
minutes                           2774     0xAD6
seconds                           2775     0xAD7
latincross                        2777     0xAD9
hexagram                          2778     0xADA
Serbian_tshe                      1707     0x06ab
Macedonia_kje                     1708     0x06ac
Byelorussian_shortu               1710     0x06ae
Serbian_dze                       1711     0x06af
numerosign                        1712     0x06b0
Serbian_DJE                       1713     0x06b1
filledrectbullet                  2779     0xADB
filledlefttribullet               2780     0xADC
filledrighttribullet              2781     0xADD
emfilledcircle                    2782     0xADE
emfilledrect                      2783     0xADF
Macedonia_GJE                     1714     0x06b2
Cyrillic_IO                       1715     0x06b3
enopencircbullet                  2784     0xAE0
enopensquarebullet                2785     0xAE1
openrectbullet                    2786     0xAE2
opentribulletup                   2787     0xAE3
Ukranian_JE                       1716     0x06b4
Macedonia_DSE                     1717     0x06b5
opentribulletdown                 2788     0xAE4
openstar                          2789     0xAE5
Ukranian_I                        1718     0x06b6
enfilledcircbullet                2790     0xAE6
enfilledsqbullet                  2791     0xAE7
Ukranian_YI                       1719     0x06b7
filledtribulletup                 2792     0xAE8
filledtribulletdown               2793     0xAE9
leftpointer                       2794     0xAEA
rightpointer                      2795     0xAEB
club                              2796     0xAEC
diamond                           2797     0xAED
heart                             2798     0xAEE
maltesecross                      2800     0xAF0
dagger                            2801     0xAF1
doubledagger                      2802     0xAF2
checkmark                         2803     0xAF3
ballotcross                       2804     0xAF4
musicalsharp                      2805     0xAF5
musicalflat                       2806     0xAF6
Serbian_JE                        1720     0x06b8
Serbian_LJE                       1721     0x06b9
Serbian_NJE                       1722     0x06ba
Serbian_TSHE                      1723     0x06bb
Macedonia_KJE                     1724     0x06bc
Byelorussian_SHORTU               1726     0x06be
Serbian_DZE                       1727     0x06bf
Cyrillic_yu                       1728     0x06c0
Cyrillic_a                        1729     0x06c1
Cyrillic_be                       1730     0x06c2
Cyrillic_tse                      1731     0x06c3
Cyrillic_de                       1732     0x06c4
malesymbol                        2807     0xAF7
femalesymbol                      2808     0xAF8
telephone                         2809     0xAF9
Cyrillic_ie                       1733     0x06c5
telephonerecorder                 2810     0xAFA
phonographcopyright               2811     0xAFB
caret                             2812     0xAFC
Cyrillic_ef                       1734     0x06c6
singlelowquotemark                2813     0xAFD
doublelowquotemark                2814     0xAFE
cursor                            2815     0xAFF
leftcaret                         2979     0xBA3
rightcaret                        2982     0xBA6
downcaret                         2984     0xBA8
upcaret                           2985     0xBA9
overbar                           3008     0xBC0
downtack                          3010     0xBC2
upshoe                            3011     0xBC3
downstile                         3012     0xBC4
Cyrillic_ghe                      1735     0x06c7
Cyrillic_ha                       1736     0x06c8
Cyrillic_i                        1737     0x06c9
Cyrillic_shorti                   1738     0x06ca
Cyrillic_ka                       1739     0x06cb
Cyrillic_el                       1740     0x06cc
Cyrillic_em                       1741     0x06cd
Cyrillic_en                       1742     0x06ce
Cyrillic_o                        1743     0x06cf
underbar                          3014     0xBC6
jot                               3018     0xBCA
quad                              3020     0xBCC
uptack                            3022     0xBCE
circle                            3023     0xBCF
upstile                           3027     0xBD3
downshoe                          3030     0xBD6
rightshoe                         3032     0xBD8
leftshoe                          3034     0xBDA
lefttack                          3036     0xBDC
Cyrillic_pe                       1744     0x06d0
Cyrillic_ya                       1745     0x06d1
Cyrillic_er                       1746     0x06d2
Cyrillic_es                       1747     0x06d3
Cyrillic_te                       1748     0x06d4
Cyrillic_u                        1749     0x06d5
righttack                         3068     0xBFC
hebrew_doublelowline              3295     0xCDF
hebrew_aleph                      3296     0xCE0
hebrew_bet                        3297     0xCE1
hebrew_gimel                      3298     0xCE2
hebrew_dalet                      3299     0xCE3
hebrew_he                         3300     0xCE4
hebrew_waw                        3301     0xCE5
hebrew_zain                       3302     0xCE6
hebrew_chet                       3303     0xCE7
hebrew_tet                        3304     0xCE8
hebrew_yod                        3305     0xCE9
Cyrillic_zhe                      1750     0x06d6
Cyrillic_ve                       1751     0x06d7
Cyrillic_softsign                 1752     0x06d8
Cyrillic_yeru                     1753     0x06d9
Cyrillic_ze                       1754     0x06da
Cyrillic_sha                      1755     0x06db
hebrew_finalkaph                  3306     0xCEA
hebrew_kaph                       3307     0xCEB
hebrew_lamed                      3308     0xCEC
hebrew_finalmem                   3309     0xCED
hebrew_mem                        3310     0xCEE
hebrew_finalnun                   3311     0xCEF
hebrew_nun                        3312     0xCF0
hebrew_samech                     3313     0xCF1
hebrew_ayin                       3314     0xCF2
Cyrillic_e                        1756     0x06dc
Cyrillic_shcha                    1757     0x06dd
Cyrillic_che                      1758     0x06de
Cyrillic_hardsign                 1759     0x06df
Cyrillic_YU                       1760     0x06e0
hebrew_finalpe                    3315     0xCF3
hebrew_pe                         3316     0xCF4
Cyrillic_A                        1761     0x06e1
hebrew_finalzade                  3317     0xCF5
hebrew_zade                       3318     0xCF6
hebrew_qoph                       3319     0xCF7
hebrew_resh                       3320     0xCF8
hebrew_shin                       3321     0xCF9
hebrew_taw                        3322     0xCFA
Cyrillic_BE                       1762     0x06e2
Cyrillic_TSE                      1763     0x06e3
Cyrillic_DE                       1764     0x06e4
Cyrillic_IE                       1765     0x06e5
Cyrillic_EF                       1766     0x06e6
.CE
.CS
Thai_kokai                        3489     0xDA1
Thai_khokhai                      3490     0xDA2
Cyrillic_GHE                      1767     0x06e7
Cyrillic_HA                       1768     0x06e8
Thai_khokhuat                     3491     0xDA3
Thai_khokhwai                     3492     0xDA4
Thai_khokhon                      3493     0xDA5
Thai_khorakhang                   3494     0xDA6
Thai_ngongu                       3495     0xDA7
Thai_chochan                      3496     0xDA8
Thai_choching                     3497     0xDA9
Cyrillic_I                        1769     0x06e9
Cyrillic_SHORTI                   1770     0x06ea
Cyrillic_KA                       1771     0x06eb
Thai_chochang                     3498     0xDAA
Thai_soso                         3499     0xDAB
Thai_chochoe                      3500     0xDAC
Thai_yoying                       3501     0xDAD
Thai_dochada                      3502     0xDAE
Thai_topatak                      3503     0xDAF
Thai_thothan                      3504     0xDB0
Cyrillic_EL                       1772     0x06ec
Cyrillic_EM                       1773     0x06ed
Cyrillic_EN                       1774     0x06ee
Cyrillic_O                        1775     0x06ef
Cyrillic_PE                       1776     0x06f0
Cyrillic_YA                       1777     0x06f1
Thai_thonangmontho                3505     0xDB1
Thai_thophuthao                   3506     0xDB2
Thai_nonen                        3507     0xDB3
Thai_dodek                        3508     0xDB4
Thai_totao                        3509     0xDB5
Cyrillic_ER                       1778     0x06f2
Cyrillic_ES                       1779     0x06f3
Cyrillic_TE                       1780     0x06f4
Thai_thothung                     3510     0xDB6
Thai_thothahan                    3511     0xDB7
Thai_thothong                     3512     0xDB8
Thai_nonu                         3513     0xDB9
Thai_bobaimai                     3514     0xDBA
Thai_popla                        3515     0xDBB
Thai_phophung                     3516     0xDBC
Cyrillic_U                        1781     0x06f5
Cyrillic_ZHE                      1782     0x06f6
Cyrillic_VE                       1783     0x06f7
Cyrillic_SOFTSIGN                 1784     0x06f8
Thai_fofa                         3517     0xDBD
Thai_phophan                      3518     0xDBE
Thai_fofan                        3519     0xDBF
Cyrillic_YERU                     1785     0x06f9
Cyrillic_ZE                       1786     0x06fa
Thai_phosamphao                   3520     0xDC0
Thai_moma                         3521     0xDC1
Thai_yoyak                        3522     0xDC2
Thai_rorua                        3523     0xDC3
Thai_ru                           3524     0xDC4
Thai_loling                       3525     0xDC5
Thai_lu                           3526     0xDC6
Thai_wowaen                       3527     0xDC7
Thai_sosala                       3528     0xDC8
Thai_sorusi                       3529     0xDC9
Thai_sosua                        3530     0xDCA
Thai_hohip                        3531     0xDCB
Cyrillic_SHA                      1787     0x06fb
Cyrillic_E                        1788     0x06fc
Cyrillic_SHCHA                    1789     0x06fd
Cyrillic_CHE                      1790     0x06fe
Cyrillic_HARDSIGN                 1791     0x06ff
Greek_ALPHAaccent                 1953     0x07a1
Greek_EPSILONaccent               1954     0x07a2
Greek_ETAaccent                   1955     0x07a3
Greek_IOTAaccent                  1956     0x07a4
Greek_IOTAdiaeresis               1957     0x07a5
Greek_IOTAaccentdiaeresis         1958     0x07a6
Thai_lochula                      3532     0xDCC
Thai_oang                         3533     0xDCD
Thai_honokhuk                     3534     0xDCE
Thai_paiyannoi                    3535     0xDCF
Thai_saraa                        3536     0xDD0
Thai_maihanakat                   3537     0xDD1
Greek_OMICRONaccent               1959     0x07a7
Thai_saraaa                       3538     0xDD2
Thai_saraam                       3539     0xDD3
Thai_sarai                        3540     0xDD4
Thai_saraii                       3541     0xDD5
Thai_saraue                       3542     0xDD6
Thai_sarauee                      3543     0xDD7
Thai_sarau                        3544     0xDD8
Thai_sarauu                       3545     0xDD9
Thai_phinthu                      3546     0xDDA
Greek_UPSILONaccent               1960     0x07a8
Greek_UPSILONdieresis             1961     0x07a9
Greek_UPSILONaccentdieresis       1962     0x07aa
Greek_OMEGAaccent                 1963     0x07ab
Greek_alphaaccent                 1969     0x07b1
Greek_epsilonaccent               1970     0x07b2
Thai_maihanakat_maitho            3550     0xDDE
Thai_baht                         3551     0xDDF
Thai_sarae                        3552     0xDE0
Thai_saraae                       3553     0xDE1
Thai_sarao                        3554     0xDE2
Thai_saraaimaimuan                3555     0xDE3
Thai_saraaimaimalai               3556     0xDE4
Thai_lakkhangyao                  3557     0xDE5
Thai_maiyamok                     3558     0xDE6
Greek_etaaccent                   1971     0x07b3
Greek_iotaaccent                  1972     0x07b4
Greek_iotadieresis                1973     0x07b5
Greek_iotaaccentdieresis          1974     0x07b6
Greek_omicronaccent               1975     0x07b7
Greek_upsilonaccent               1976     0x07b8
Greek_upsilondieresis             1977     0x07b9
Greek_upsilonaccentdieresis       1978     0x07ba
Thai_maitaikhu                    3559     0xDE7
Thai_maiek                        3560     0xDE8
Thai_maitho                       3561     0xDE9
Thai_maitri                       3562     0xDEA
Thai_maichattawa                  3563     0xDEB
Thai_thanthakhat                  3564     0xDEC
Greek_omegaaccent                 1979     0x07bb
Thai_nikhahit                     3565     0xDED
Thai_leksun                       3568     0xDF0
Thai_leknung                      3569     0xDF1
Thai_leksong                      3570     0xDF2
Thai_leksam                       3571     0xDF3
Thai_leksi                        3572     0xDF4
Thai_lekha                        3573     0xDF5
Thai_lekhok                       3574     0xDF6
Thai_lekchet                      3575     0xDF7
Thai_lekpaet                      3576     0xDF8
Thai_lekkao                       3577     0xDF9
Hangul_Kiyeog                     3745     0xEA1
Greek_ALPHA                       1985     0x07c1
Greek_BETA                        1986     0x07c2
Greek_GAMMA                       1987     0x07c3
Greek_DELTA                       1988     0x07c4
Greek_EPSILON                     1989     0x07c5
Greek_ZETA                        1990     0x07c6
Greek_ETA                         1991     0x07c7
Greek_THETA                       1992     0x07c8
Greek_IOTA                        1993     0x07c9
Greek_KAPPA                       1994     0x07ca
Hangul_SsangKiyeog                3746     0xEA2
Hangul_KiyeogSios                 3747     0xEA3
Hangul_Nieun                      3748     0xEA4
Greek_LAMBDA                      1995     0x07cb
Hangul_NieunJieuj                 3749     0xEA5
Hangul_NieunHieuh                 3750     0xEA6
Hangul_Dikeud                     3751     0xEA7
Greek_MU                          1996     0x07cc
Hangul_SsangDikeud                3752     0xEA8
Hangul_Rieul                      3753     0xEA9
Greek_NU                          1997     0x07cd
Hangul_RieulKiyeog                3754     0xEAA
Hangul_RieulMieum                 3755     0xEAB
Hangul_RieulPieub                 3756     0xEAC
Hangul_RieulSios                  3757     0xEAD
Hangul_RieulTieut                 3758     0xEAE
Hangul_RieulPhieuf                3759     0xEAF
Hangul_RieulHieuh                 3760     0xEB0
Hangul_Mieum                      3761     0xEB1
Hangul_Pieub                      3762     0xEB2
Greek_XI                          1998     0x07ce
Greek_OMICRON                     1999     0x07cf
Hangul_SsangPieub                 3763     0xEB3
Hangul_PieubSios                  3764     0xEB4
Hangul_Sios                       3765     0xEB5
Greek_PI                          2000     0x07d0
Hangul_SsangSios                  3766     0xEB6
Hangul_Ieung                      3767     0xEB7
Hangul_Jieuj                      3768     0xEB8
Greek_RHO                         2001     0x07d1
Greek_SIGMA                       2002     0x07d2
Hangul_SsangJieuj                 3769     0xEB9
Hangul_Cieuc                      3770     0xEBA
Hangul_Khieuq                     3771     0xEBB
Greek_TAU                         2004     0x07d4
Greek_UPSILON                     2005     0x07d5
Hangul_Tieut                      3772     0xEBC
Hangul_Phieuf                     3773     0xEBD
Hangul_Hieuh                      3774     0xEBE
Hangul_A                          3775     0xEBF
Hangul_AE                         3776     0xEC0
Hangul_YA                         3777     0xEC1
Hangul_YAE                        3778     0xEC2
Hangul_EO                         3779     0xEC3
Hangul_E                          3780     0xEC4
Hangul_YEO                        3781     0xEC5
Hangul_YE                         3782     0xEC6
Hangul_O                          3783     0xEC7
Hangul_WA                         3784     0xEC8
Hangul_WAE                        3785     0xEC9
Hangul_OE                         3786     0xECA
Hangul_YO                         3787     0xECB
Hangul_U                          3788     0xECC
Hangul_WEO                        3789     0xECD
Hangul_WE                         3790     0xECE
Hangul_WI                         3791     0xECF
Hangul_YU                         3792     0xED0
Hangul_EU                         3793     0xED1
Hangul_YI                         3794     0xED2
Hangul_I                          3795     0xED3
Greek_PHI                         2006     0x07d6
Greek_CHI                         2007     0x07d7
Greek_PSI                         2008     0x07d8
Greek_OMEGA                       2009     0x07d9
Greek_alpha                       2017     0x07e1
Greek_beta                        2018     0x07e2
Greek_gamma                       2019     0x07e3
Greek_delta                       2020     0x07e4
Greek_epsilon                     2021     0x07e5
Greek_zeta                        2022     0x07e6
Greek_eta                         2023     0x07e7
Greek_theta                       2024     0x07e8
Greek_iota                        2025     0x07e9
Greek_kappa                       2026     0x07ea
Greek_lambda                      2027     0x07eb
Greek_mu                          2028     0x07ec
Greek_nu                          2029     0x07ed
Greek_xi                          2030     0x07ee
Greek_omicron                     2031     0x07ef
Greek_pi                          2032     0x07f0
Greek_rho                         2033     0x07f1
Hangul_J_Kiyeog                   3796     0xED4
Hangul_J_SsangKiyeog              3797     0xED5
Hangul_J_KiyeogSios               3798     0xED6
Hangul_J_Nieun                    3799     0xED7
Hangul_J_NieunJieuj               3800     0xED8
Hangul_J_NieunHieuh               3801     0xED9
Hangul_J_Dikeud                   3802     0xEDA
Hangul_J_Rieul                    3803     0xEDB
Hangul_J_RieulKiyeog              3804     0xEDC
Hangul_J_RieulMieum               3805     0xEDD
Hangul_J_RieulPieub               3806     0xEDE
Hangul_J_RieulSios                3807     0xEDF
Hangul_J_RieulTieut               3808     0xEE0
Greek_sigma                       2034     0x07f2
Greek_finalsmallsigma             2035     0x07f3
Hangul_J_RieulPhieuf              3809     0xEE1
Hangul_J_RieulHieuh               3810     0xEE2
Hangul_J_Mieum                    3811     0xEE3
Hangul_J_Pieub                    3812     0xEE4
Hangul_J_PieubSios                3813     0xEE5
Hangul_J_Sios                     3814     0xEE6
Greek_tau                         2036     0x07f4
Greek_upsilon                     2037     0x07f5
Greek_phi                         2038     0x07f6
Greek_chi                         2039     0x07f7
Hangul_J_SsangSios                3815     0xEE7
Hangul_J_Ieung                    3816     0xEE8
Hangul_J_Jieuj                    3817     0xEE9
Hangul_J_Cieuc                    3818     0xEEA
Hangul_J_Khieuq                   3819     0xEEB
Hangul_J_Tieut                    3820     0xEEC
Hangul_J_Phieuf                   3821     0xEED
Hangul_J_Hieuh                    3822     0xEEE
Greek_psi                         2040     0x07f8
Greek_omega                       2041     0x07f9
leftradical                       2209     0x08a1
topleftradical                    2210     0x08a2
horizconnector                    2211     0x08a3
topintegral                       2212     0x08a4
botintegral                       2213     0x08a5
Hangul_RieulYeorinHieuh           3823     0xEEF
Hangul_SunkyeongeumMieum          3824     0xEF0
Hangul_SunkyeongeumPieub          3825     0xEF1
Hangul_PanSios                    3826     0xEF2
vertconnector                     2214     0x08a6
Hangul_KkogjiDalrinIeung          3827     0xEF3
Hangul_SunkyeongeumPhieuf         3828     0xEF4
Hangul_YeorinHieuh                3829     0xEF5
Hangul_AraeA                      3830     0xEF6
Hangul_AraeAE                     3831     0xEF7
Hangul_J_PanSios                  3832     0xEF8
topleftsqbracket                  2215     0x08a7
botleftsqbracket                  2216     0x08a8
toprightsqbracket                 2217     0x08a9
Hangul_J_KkogjiDalrinIeung        3833     0xEF9
Hangul_J_YeorinHieuh              3834     0xEFA
Korean_Won                        3839     0xEFF
OE                                5052     0x13BC
oe                                5053     0x13BD
Ydiaeresis                        5054     0x13BE
botrightsqbracket                 2218     0x08aa
topleftparens                     2219     0x08ab
botleftparens                     2220     0x08ac
toprightparens                    2221     0x08ad
\(eu (EuroSign)                      8364     0x20AC
.CE
.CS
ISO_Lock                         65025     0xFE01
ISO_Level2_Latch                 65026     0xFE02
ISO_Level3_Shift                 65027     0xFE03
botrightparens                    2222     0x08ae
leftmiddlecurlybrace              2223     0x08af
rightmiddlecurlybrace             2224     0x08b0
ISO_Level3_Latch                 65028     0xFE04
ISO_Level3_Lock                  65029     0xFE05
ISO_Group_Latch                  65030     0xFE06
ISO_Group_Lock                   65031     0xFE07
ISO_Next_Group                   65032     0xFE08
topleftsummation                  2225     0x08b1
botleftsummation                  2226     0x08b2
topvertsummationconnector         2227     0x08b3
botvertsummationconnector         2228     0x08b4
ISO_Next_Group_Lock              65033     0xFE09
ISO_Prev_Group                   65034     0xFE0A
toprightsummation                 2229     0x08b5
ISO_Prev_Group_Lock              65035     0xFE0B
ISO_First_Group                  65036     0xFE0C
ISO_First_Group_Lock             65037     0xFE0D
ISO_Last_Group                   65038     0xFE0E
ISO_Last_Group_Lock              65039     0xFE0F
ISO_Level5_Shift                 65041     0xFE11
ISO_Level5_Latch                 65042     0xFE12
ISO_Level5_Lock                  65043     0xFE13
ISO_Left_Tab                     65056     0xFE20
ISO_Move_Line_Up                 65057     0xFE21
ISO_Move_Line_Down               65058     0xFE22
ISO_Partial_Line_Up              65059     0xFE23
botrightsummation                 2230     0x08b6
rightmiddlesummation              2231     0x08b7
.CE
.CS
lessthanequal                     2236     0x08bc
notequal                          2237     0x08bd
greaterthanequal                  2238     0x08be
integral                          2239     0x08bf
therefore                         2240     0x08c0
variation                         2241     0x08c1
infinity                          2242     0x08c2
nabla                             2245     0x08c5
approximate                       2248     0x08c8
ISO_Partial_Line_Down            65060     0xFE24
ISO_Partial_Space_Left           65061     0xFE25
ISO_Partial_Space_Right          65062     0xFE26
ISO_Set_Margin_Left              65063     0xFE27
ISO_Set_Margin_Right             65064     0xFE28
ISO_Release_Margin_Left          65065     0xFE29
ISO_Release_Margin_Right         65066     0xFE2A
ISO_Release_Both_Margins         65067     0xFE2B
ISO_Fast_Cursor_Left             65068     0xFE2C
ISO_Fast_Cursor_Right            65069     0xFE2D
ISO_Fast_Cursor_Up               65070     0xFE2E
ISO_Fast_Cursor_Down             65071     0xFE2F
ISO_Continuous_Underline         65072     0xFE30
ISO_Discontinuous_Underline      65073     0xFE31
ISO_Emphasize                    65074     0xFE32
similarequal                      2249     0x08c9
ISO_Center_Object                65075     0xFE33
ISO_Enter                        65076     0xFE34
dead_grave                       65104     0xFE50
dead_acute                       65105     0xFE51
ifonlyif                          2253     0x08cd
implies                           2254     0x08ce
identical                         2255     0x08cf
dead_circumflex                  65106     0xFE52
dead_tilde                       65107     0xFE53
dead_macron                      65108     0xFE54
dead_breve                       65109     0xFE55
dead_abovedot                    65110     0xFE56
dead_diaeresis                   65111     0xFE57
dead_abovering                   65112     0xFE58
radical                           2262     0x08d6
includedin                        2266     0x08da
includes                          2267     0x08db
intersection                      2268     0x08dc
union                             2269     0x08dd
logicaland                        2270     0x08de
dead_doubleacute                 65113     0xFE59
dead_caron                       65114     0xFE5A
dead_cedilla                     65115     0xFE5B
dead_ogonek                      65116     0xFE5C
dead_iota                        65117     0xFE5D
logicalor                         2271     0x08df
partialderivative                 2287     0x08ef
function                          2294     0x08f6
leftarrow                         2299     0x08fb
dead_voiced_sound                65118     0xFE5E
dead_semivoiced_sound            65119     0xFE5F
dead_belowdot                    65120     0xFE60
dead_hook                        65121     0xFE61
dead_horn                        65122     0xFE62
dead_stroke                      65123     0xFE63
dead_abovecomma                  65124     0xFE64
uparrow                           2300     0x08fc
rightarrow                        2301     0x08fd
downarrow                         2302     0x08fe
blank                             2527     0x09df
soliddiamond                      2528     0x09e0
dead_abovereversedcomma          65125     0xFE65
dead_doublegrave                 65126     0xFE66
dead_belowring                   65127     0xFE67
dead_belowmacron                 65128     0xFE68
checkerboard                      2529     0x09e1
ht                                2530     0x09e2
ff                                2531     0x09e3
dead_belowcircumflex             65129     0xFE69
dead_belowtilde                  65130     0xFE6A
dead_belowbreve                  65131     0xFE6B
cr                                2532     0x09e4
lf                                2533     0x09e5
dead_belowdiaeresis              65132     0xFE6C
dead_invertedbreve               65133     0xFE6D
dead_belowcomma                  65134     0xFE6E
dead_currency                    65135     0xFE6F
AccessX_Enable                   65136     0xFE70
nl                                2536     0x09e8
vt                                2537     0x09e9
lowrightcorner                    2538     0x09ea
AccessX_Feedback_Enable          65137     0xFE71
RepeatKeys_Enable                65138     0xFE72
SlowKeys_Enable                  65139     0xFE73
uprightcorner                     2539     0x09eb
BounceKeys_Enable                65140     0xFE74
StickyKeys_Enable                65141     0xFE75
MouseKeys_Enable                 65142     0xFE76
MouseKeys_Accel_Enable           65143     0xFE77
Overlay1_Enable                  65144     0xFE78
Overlay2_Enable                  65145     0xFE79
AudibleBell_Enable               65146     0xFE7A
dead_a                           65152     0xFE80
dead_A                           65153     0xFE81
dead_e                           65154     0xFE82
dead_E                           65155     0xFE83
dead_i                           65156     0xFE84
dead_I                           65157     0xFE85
dead_o                           65158     0xFE86
dead_O                           65159     0xFE87
dead_u                           65160     0xFE88
upleftcorner                      2540     0x09ec
lowleftcorner                     2541     0x09ed
crossinglines                     2542     0x09ee
horizlinescan1                    2543     0x09ef
horizlinescan3                    2544     0x09f0
horizlinescan5                    2545     0x09f1
horizlinescan7                    2546     0x09f2
horizlinescan9                    2547     0x09f3
leftt                             2548     0x09f4
dead_U                           65161     0xFE89
dead_schwa                       65162     0xFE8A
dead_SCHWA                       65163     0xFE8B
dead_greek                       65164     0xFE8C
dead_lowline                     65168     0xFE90
dead_aboveverticalline           65169     0xFE91
dead_belowverticalline           65170     0xFE92
dead_longsolidusoverlay          65171     0xFE93
ch                               65184     0xFEA0
Ch                               65185     0xFEA1
CH                               65186     0xFEA2
c_h                              65187     0xFEA3
C_h                              65188     0xFEA4
C_H                              65189     0xFEA5
rightt                            2549     0x09f5
bott                              2550     0x09f6
topt                              2551     0x09f7
vertbar                           2552     0x09f8
emspace                           2721     0x0aa1
enspace                           2722     0x0aa2
First_Virtual_Screen             65232     0xFED0
Prev_Virtual_Screen              65233     0xFED1
Next_Virtual_Screen              65234     0xFED2
Last_Virtual_Screen              65236     0xFED4
Terminate_Server                 65237     0xFED5
Pointer_Left                     65248     0xFEE0
Pointer_Right                    65249     0xFEE1
Pointer_Up                       65250     0xFEE2
Pointer_Down                     65251     0xFEE3
Pointer_UpLeft                   65252     0xFEE4
Pointer_UpRight                  65253     0xFEE5
Pointer_DownLeft                 65254     0xFEE6
Pointer_DownRight                65255     0xFEE7
em3space                          2723     0x0aa3
em4space                          2724     0x0aa4
digitspace                        2725     0x0aa5
punctspace                        2726     0x0aa6
thinspace                         2727     0x0aa7
hairspace                         2728     0x0aa8
emdash                            2729     0x0aa9
endash                            2730     0x0aaa
signifblank                       2732     0x0aac
Pointer_Button_Dflt              65256     0xFEE8
Pointer_Button1                  65257     0xFEE9
Pointer_Button2                  65258     0xFEEA
Pointer_Button3                  65259     0xFEEB
Pointer_Button4                  65260     0xFEEC
Pointer_Button5                  65261     0xFEED
ellipsis                          2734     0x0aae
doubbaselinedot                   2735     0x0aaf
onethird                          2736     0x0ab0
twothirds                         2737     0x0ab1
onefifth                          2738     0x0ab2
Pointer_DblClick_Dflt            65262     0xFEEE
Pointer_DblClick1                65263     0xFEEF
Pointer_DblClick2                65264     0xFEF0
Pointer_DblClick3                65265     0xFEF1
Pointer_DblClick4                65266     0xFEF2
Pointer_DblClick5                65267     0xFEF3
Pointer_Drag_Dflt                65268     0xFEF4
Pointer_Drag1                    65269     0xFEF5
Pointer_Drag2                    65270     0xFEF6
Pointer_Drag3                    65271     0xFEF7
Pointer_Drag4                    65272     0xFEF8
twofifths                         2739     0x0ab3
threefifths                       2740     0x0ab4
fourfifths                        2741     0x0ab5
onesixth                          2742     0x0ab6
Pointer_EnableKeys               65273     0xFEF9
Pointer_Accelerate               65274     0xFEFA
Pointer_DfltBtnNext              65275     0xFEFB
Pointer_DfltBtnPrev              65276     0xFEFC
Pointer_Drag5                    65277     0xFEFD
fivesixths                        2743     0x0ab7
.CE
.CS
BackSpace                        65288     0xFF08
Tab                              65289     0xFF09
Linefeed                         65290     0xFF0A
Clear                            65291     0xFF0B
Return                           65293     0xFF0D
Pause                            65299     0xFF13
careof                            2744     0x0ab8
figdash                           2747     0x0abb
leftanglebracket                  2748     0x0abc
decimalpoint                      2749     0x0abd
rightanglebracket                 2750     0x0abe
marker                            2751     0x0abf
Scroll_Lock                      65300     0xFF14
Sys_Req                          65301     0xFF15
Escape                           65307     0xFF1B
Multi_key                        65312     0xFF20
Kanji                            65313     0xFF21
Muhenkan                         65314     0xFF22
Henkan_Mode                      65315     0xFF23
Romaji                           65316     0xFF24
Hiragana                         65317     0xFF25
Katakana                         65318     0xFF26
oneeighth                         2755     0x0ac3
threeeighths                      2756     0x0ac4
fiveeighths                       2757     0x0ac5
seveneighths                      2758     0x0ac6
trademark                         2761     0x0ac9
signaturemark                     2762     0x0aca
trademarkincircle                 2763     0x0acb
leftopentriangle                  2764     0x0acc
rightopentriangle                 2765     0x0acd
Hiragana_Katakana                65319     0xFF27
Zenkaku                          65320     0xFF28
Hankaku                          65321     0xFF29
Zenkaku_Hankaku                  65322     0xFF2A
Touroku                          65323     0xFF2B
Massyo                           65324     0xFF2C
Kana_Lock                        65325     0xFF2D
Kana_Shift                       65326     0xFF2E
emopencircle                      2766     0x0ace
emopenrectangle                   2767     0x0acf
leftsinglequotemark               2768     0x0ad0
rightsinglequotemark              2769     0x0ad1
leftdoublequotemark               2770     0x0ad2
rightdoublequotemark              2771     0x0ad3
prescription                      2772     0x0ad4
Eisu_Shift                       65327     0xFF2F
Eisu_toggle                      65328     0xFF30
Hangul                           65329     0xFF31
Hangul_Start                     65330     0xFF32
Hangul_End                       65331     0xFF33
Hangul_Hanja                     65332     0xFF34
Hangul_Jamo                      65333     0xFF35
minutes                           2774     0x0ad6
seconds                           2775     0x0ad7
latincross                        2777     0x0ad9
Hangul_Romaja                    65334     0xFF36
Codeinput                        65335     0xFF37
Hangul_Jeonja                    65336     0xFF38
Hangul_Banja                     65337     0xFF39
Hangul_PreHanja                  65338     0xFF3A
hexagram                          2778     0x0ada
filledrectbullet                  2779     0x0adb
filledlefttribullet               2780     0x0adc
filledrighttribullet              2781     0x0add
Hangul_PostHanja                 65339     0xFF3B
SingleCandidate                  65340     0xFF3C
MultipleCandidate                65341     0xFF3D
PreviousCandidate                65342     0xFF3E
Hangul_Special                   65343     0xFF3F
Home                             65360     0xFF50
Left                             65361     0xFF51
emfilledcircle                    2782     0x0ade
emfilledrect                      2783     0x0adf
Up                               65362     0xFF52
Right                            65363     0xFF53
Down                             65364     0xFF54
enopencircbullet                  2784     0x0ae0
enopensquarebullet                2785     0x0ae1
Prior                            65365     0xFF55
Next                             65366     0xFF56
End                              65367     0xFF57
Begin                            65368     0xFF58
openrectbullet                    2786     0x0ae2
opentribulletup                   2787     0x0ae3
opentribulletdown                 2788     0x0ae4
Select                           65376     0xFF60
Print                            65377     0xFF61
Execute                          65378     0xFF62
Insert                           65379     0xFF63
openstar                          2789     0x0ae5
enfilledcircbullet                2790     0x0ae6
enfilledsqbullet                  2791     0x0ae7
Undo                             65381     0xFF65
Redo                             65382     0xFF66
Menu (App)                       65383     0xFF67
Find                             65384     0xFF68
Cancel                           65385     0xFF69
Help                             65386     0xFF6A
Break                            65387     0xFF6B
filledtribulletup                 2792     0x0ae8
filledtribulletdown               2793     0x0ae9
Mode_switch                      65406     0xFF7E
Num_Lock                         65407     0xFF7F
leftpointer                       2794     0x0aea
KP_Space                         65408     0xFF80
KP_Tab                           65417     0xFF89
KP_Enter                         65421     0xFF8D
KP_F1                            65425     0xFF91
KP_F2                            65426     0xFF92
KP_F3                            65427     0xFF93
KP_F4                            65428     0xFF94
rightpointer                      2795     0x0aeb
club                              2796     0x0aec
diamond                           2797     0x0aed
heart                             2798     0x0aee
maltesecross                      2800     0x0af0
KP_Home                          65429     0xFF95
KP_Left                          65430     0xFF96
KP_Up                            65431     0xFF97
KP_Right                         65432     0xFF98
KP_Down                          65433     0xFF99
KP_Prior                         65434     0xFF9A
KP_Next                          65435     0xFF9B
dagger                            2801     0x0af1
doubledagger                      2802     0x0af2
checkmark                         2803     0x0af3
ballotcross                       2804     0x0af4
musicalsharp                      2805     0x0af5
KP_End                           65436     0xFF9C
KP_Begin                         65437     0xFF9D
KP_Insert                        65438     0xFF9E
KP_Delete                        65439     0xFF9F
KP_Multiply                      65450     0xFFAA
KP_Add                           65451     0xFFAB
KP_Separator                     65452     0xFFAC
KP_Subtract                      65453     0xFFAD
musicalflat                       2806     0x0af6
malesymbol                        2807     0x0af7
femalesymbol                      2808     0x0af8
telephone                         2809     0x0af9
telephonerecorder                 2810     0x0afa
phonographcopyright               2811     0x0afb
KP_Decimal                       65454     0xFFAE
KP_Divide                        65455     0xFFAF
KP_0                             65456     0xFFB0
KP_1                             65457     0xFFB1
KP_2                             65458     0xFFB2
KP_3                             65459     0xFFB3
caret                             2812     0x0afc
singlelowquotemark                2813     0x0afd
doublelowquotemark                2814     0x0afe
cursor                            2815     0x0aff
KP_4                             65460     0xFFB4
KP_5                             65461     0xFFB5
KP_6                             65462     0xFFB6
KP_7                             65463     0xFFB7
KP_8                             65464     0xFFB8
KP_9                             65465     0xFFB9
KP_Equal                         65469     0xFFBD
F1                               65470     0xFFBE
F2                               65471     0xFFBF
F3                               65472     0xFFC0
F4                               65473     0xFFC1
F5                               65474     0xFFC2
F6                               65475     0xFFC3
F7                               65476     0xFFC4
F8                               65477     0xFFC5
F9                               65478     0xFFC6
F10                              65479     0xFFC7
F11                              65480     0xFFC8
F12                              65481     0xFFC9
F13                              65482     0xFFCA
F14                              65483     0xFFCB
F15                              65484     0xFFCC
leftcaret                         2979     0x0ba3
rightcaret                        2982     0x0ba6
downcaret                         2984     0x0ba8
upcaret                           2985     0x0ba9
overbar                           3008     0x0bc0
downtack                          3010     0x0bc2
upshoe                            3011     0x0bc3
downstile                         3012     0x0bc4
underbar                          3014     0x0bc6
jot                               3018     0x0bca
quad                              3020     0x0bcc
uptack                            3022     0x0bce
circle                            3023     0x0bcf
upstile                           3027     0x0bd3
downshoe                          3030     0x0bd6
rightshoe                         3032     0x0bd8
F16                              65485     0xFFCD
F17                              65486     0xFFCE
F18                              65487     0xFFCF
F19                              65488     0xFFD0
F20                              65489     0xFFD1
F21                              65490     0xFFD2
F22                              65491     0xFFD3
F23                              65492     0xFFD4
F24                              65493     0xFFD5
F25                              65494     0xFFD6
F26                              65495     0xFFD7
F27                              65496     0xFFD8
F28                              65497     0xFFD9
F29                              65498     0xFFDA
F30                              65499     0xFFDB
F31                              65500     0xFFDC
F32                              65501     0xFFDD
F33                              65502     0xFFDE
F34                              65503     0xFFDF
F35                              65504     0xFFE0
Shift_L                          65505     0xFFE1
leftshoe                          3034     0x0bda
lefttack                          3036     0x0bdc
righttack                         3068     0x0bfc
hebrew_aleph                      3296     0x0ce0
hebrew_beth                       3297     0x0ce1
hebrew_gimmel                     3298     0x0ce2
hebrew_daleth                     3299     0x0ce3
hebrew_he                         3300     0x0ce4
hebrew_waw                        3301     0x0ce5
hebrew_zayin                      3302     0x0ce6
hebrew_het                        3303     0x0ce7
hebrew_teth                       3304     0x0ce8
hebrew_yod                        3305     0x0ce9
hebrew_finalkaph                  3306     0x0cea
Shift_R                          65506     0xFFE2
Control_L                        65507     0xFFE3
Control_R                        65508     0xFFE4
Caps_Lock                        65509     0xFFE5
Shift_Lock                       65510     0xFFE6
Meta_L                           65511     0xFFE7
Meta_R                           65512     0xFFE8
Alt_L                            65513     0xFFE9
Alt_R                            65514     0xFFEA
Super_L (Win_L)                  65515     0xFFEB
Super_R (Win_R)                  65516     0xFFEC
Hyper_L                          65517     0xFFED
Hyper_R                          65518     0xFFEE
braille_dot_1                    65521     0xFFF1
braille_dot_2                    65522     0xFFF2
braille_dot_3                    65523     0xFFF3
braille_dot_4                    65524     0xFFF4
braille_dot_5                    65525     0xFFF5
braille_dot_6                    65526     0xFFF6
braille_dot_7                    65527     0xFFF7
braille_dot_8                    65528     0xFFF8
braille_dot_9                    65529     0xFFF9
braille_dot_10                   65530     0xFFFA
Delete                           65535     0xFFFF
hebrew_kaph                       3307     0x0ceb
hebrew_lamed                      3308     0x0cec
hebrew_finalmem                   3309     0x0ced
hebrew_mem                        3310     0x0cee
hebrew_finalnun                   3311     0x0cef
hebrew_nun                        3312     0x0cf0
hebrew_samekh                     3313     0x0cf1
hebrew_ayin                       3314     0x0cf2
hebrew_finalpe                    3315     0x0cf3
hebrew_pe                         3316     0x0cf4
hebrew_finalzadi                  3317     0x0cf5
hebrew_zadi                       3318     0x0cf6
hebrew_kuf                        3319     0x0cf7
.CE
.CS
SunFA_Grave                  268828416     0x1005FF00
hebrew_resh                       3320     0x0cf8
SunFA_Circum                 268828417     0x1005FF01
SunFA_Tilde                  268828418     0x1005FF02
hebrew_shin                       3321     0x0cf9
SunFA_Acute                  268828419     0x1005FF03
SunFA_Diaeresis              268828420     0x1005FF04
SunFA_Cedilla                268828421     0x1005FF05
SunF36                       268828432     0x1005FF10
SunF37                       268828433     0x1005FF11
SunSys_Req                   268828512     0x1005FF60
SunProps                     268828528     0x1005FF70
SunFront                     268828529     0x1005FF71
SunCopy                      268828530     0x1005FF72
SunOpen                      268828531     0x1005FF73
SunPaste                     268828532     0x1005FF74
SunCut                       268828533     0x1005FF75
hebrew_taf                        3322     0x0cfa
BackSpace                        65288     0xff08
Tab                              65289     0xff09
Linefeed                         65290     0xff0a
Clear                            65291     0xff0b
Return                           65293     0xff0d
Pause                            65299     0xff13
Scroll_Lock                      65300     0xff14
Sys_Req                          65301     0xff15
SunPowerSwitch               268828534     0x1005FF76
SunAudioLowerVolume          268828535     0x1005FF77
SunAudioMute                 268828536     0x1005FF78
Escape                           65307     0xff1b
SunAudioRaiseVolume          268828537     0x1005FF79
SunVideoDegauss              268828538     0x1005FF7A
SunVideoLowerBrightness      268828539     0x1005FF7B
SunVideoRaiseBrightness      268828540     0x1005FF7C
SunPowerSwitchShift          268828541     0x1005FF7D
XF86BrightnessAuto           268964084     0x100810F4
XF86DisplayOff               268964085     0x100810F5
XF86Info                     268964198     0x10081166
Multi_key                        65312     0xff20
Kanji                            65313     0xff21
XF86AspectRatio              268964215     0x10081177
XF86DVD                      268964229     0x10081185
XF86Audio                    268964232     0x10081188
XF86ChannelUp                268964242     0x10081192
Home                             65360     0xff50
Left                             65361     0xff51
Up                               65362     0xff52
XF86ChannelDown              268964243     0x10081193
XF86Break                    268964251     0x1008119B
Right                            65363     0xff53
XF86VideoPhone               268964256     0x100811A0
XF86ZoomReset                268964260     0x100811A4
XF86Editor                   268964262     0x100811A6
Down                             65364     0xff54
Prior                            65365     0xff55
XF86GraphicsEditor           268964264     0x100811A8
XF86Presentation             268964265     0x100811A9
XF86Database                 268964266     0x100811AA
XF86Voicemail                268964268     0x100811AC
XF86Addressbook              268964269     0x100811AD
Next                             65366     0xff56
End                              65367     0xff57
Begin                            65368     0xff58
XF86DisplayToggle            268964271     0x100811AF
XF86SpellCheck               268964272     0x100811B0
XF86ContextMenu              268964278     0x100811B6
XF86MediaRepeat              268964279     0x100811B7
Win_L                            65371     0xff5b
Win_R                            65372     0xff5c
.CE
.CS
App                              65373     0xff5d
XF8610ChannelsUp             268964280     0x100811B8
XF8610ChannelsDown           268964281     0x100811B9
XF86Images                   268964282     0x100811BA
Select                           65376     0xff60
XF86NotificationCenter       268964284     0x100811BC
XF86PickupPhone              268964285     0x100811BD
XF86HangupPhone              268964286     0x100811BE
XF86Fn                       268964304     0x100811D0
XF86Fn_Esc                   268964305     0x100811D1
Print                            65377     0xff61
Execute                          65378     0xff62
XF86FnRightShift             268964325     0x100811E5
XF86Numeric0                 268964352     0x10081200
XF86Numeric1                 268964353     0x10081201
XF86Numeric2                 268964354     0x10081202
XF86Numeric3                 268964355     0x10081203
XF86Numeric4                 268964356     0x10081204
XF86Numeric5                 268964357     0x10081205
XF86Numeric6                 268964358     0x10081206
XF86Numeric7                 268964359     0x10081207
XF86Numeric8                 268964360     0x10081208
XF86Numeric9                 268964361     0x10081209
Insert                           65379     0xff63
Undo                             65381     0xff65
Redo                             65382     0xff66
Menu                             65383     0xff67
Find                             65384     0xff68
Cancel                           65385     0xff69
Help                             65386     0xff6a
Break                            65387     0xff6b
Hebrew_switch                    65406     0xff7e
Num_Lock                         65407     0xff7f
XF86NumericStar              268964362     0x1008120A
XF86NumericPound             268964363     0x1008120B
XF86NumericA                 268964364     0x1008120C
XF86NumericB                 268964365     0x1008120D
XF86NumericC                 268964366     0x1008120E
XF86NumericD                 268964367     0x1008120F
KP_Space                         65408     0xff80
KP_Tab                           65417     0xff89
KP_Enter                         65421     0xff8d
KP_F1                            65425     0xff91
XF86CameraFocus              268964368     0x10081210
XF86WPSButton                268964369     0x10081211
XF86CameraZoomIn             268964373     0x10081215
XF86CameraZoomOut            268964374     0x10081216
XF86CameraUp                 268964375     0x10081217
XF86CameraDown               268964376     0x10081218
XF86CameraLeft               268964377     0x10081219
XF86CameraRight              268964378     0x1008121A
XF86AttendantOn              268964379     0x1008121B
XF86AttendantOff             268964380     0x1008121C
KP_F2                            65426     0xff92
KP_F3                            65427     0xff93
KP_F4                            65428     0xff94
KP_Multiply                      65450     0xffaa
XF86AttendantToggle          268964381     0x1008121D
XF86LightsToggle             268964382     0x1008121E
XF86ALSToggle                268964400     0x10081230
KP_Add                           65451     0xffab
KP_Separator                     65452     0xffac
XF86Buttonconfig             268964416     0x10081240
XF86Taskmanager              268964417     0x10081241
XF86Journal                  268964418     0x10081242
XF86ControlPanel             268964419     0x10081243
XF86AppSelect                268964420     0x10081244
XF86Screensaver              268964421     0x10081245
XF86VoiceCommand             268964422     0x10081246
XF86Assistant                268964423     0x10081247
XF86EmojiPicker              268964425     0x10081249
XF86Dictate                  268964426     0x1008124A
KP_Subtract                      65453     0xffad
KP_Decimal                       65454     0xffae
KP_Divide                        65455     0xffaf
KP_0                             65456     0xffb0
KP_1                             65457     0xffb1
KP_2                             65458     0xffb2
KP_3                             65459     0xffb3
KP_4                             65460     0xffb4
KP_5                             65461     0xffb5
XF86BrightnessMin            268964432     0x10081250
XF86BrightnessMax            268964433     0x10081251
XF86KbdInputAssistPrev       268964448     0x10081260
XF86KbdInputAssistNext       268964449     0x10081261
XF86KbdInputAssistPrevgroup  268964450     0x10081262
XF86KbdInputAssistNextgroup  268964451     0x10081263
XF86KbdInputAssistAccept     268964452     0x10081264
XF86KbdInputAssistCancel     268964453     0x10081265
XF86RightUp                  268964454     0x10081266
XF86RightDown                268964455     0x10081267
XF86LeftUp                   268964456     0x10081268
XF86LeftDown                 268964457     0x10081269
XF86RootMenu                 268964458     0x1008126A
KP_6                             65462     0xffb6
KP_7                             65463     0xffb7
KP_8                             65464     0xffb8
KP_9                             65465     0xffb9
KP_Equal                         65469     0xffbd
XF86MediaTopMenu             268964459     0x1008126B
XF86Numeric11                268964460     0x1008126C
XF86Numeric12                268964461     0x1008126D
XF86AudioDesc                268964462     0x1008126E
XF863DMode                   268964463     0x1008126F
F1                               65470     0xffbe
F2                               65471     0xffbf
F3                               65472     0xffc0
F4                               65473     0xffc1
XF86NextFavorite             268964464     0x10081270
XF86StopRecord               268964465     0x10081271
F5                               65474     0xffc2
XF86PauseRecord              268964466     0x10081272
XF86VOD                      268964467     0x10081273
XF86Unmute                   268964468     0x10081274
F6                               65475     0xffc3
F7                               65476     0xffc4
XF86FastReverse              268964469     0x10081275
XF86SlowReverse              268964470     0x10081276
XF86Data                     268964471     0x10081277
F8                               65477     0xffc5
XF86OnScreenKeyboard         268964472     0x10081278
XF86PrivacyScreenToggle      268964473     0x10081279
XF86SelectiveScreenshot      268964474     0x1008127A
XF86Macro1                   268964496     0x10081290
XF86Macro2                   268964497     0x10081291
XF86Macro3                   268964498     0x10081292
XF86Macro4                   268964499     0x10081293
XF86Macro5                   268964500     0x10081294
XF86Macro6                   268964501     0x10081295
XF86Macro7                   268964502     0x10081296
XF86Macro8                   268964503     0x10081297
XF86Macro9                   268964504     0x10081298
XF86Macro10                  268964505     0x10081299
XF86Macro11                  268964506     0x1008129A
XF86Macro12                  268964507     0x1008129B
XF86Macro13                  268964508     0x1008129C
XF86Macro14                  268964509     0x1008129D
XF86Macro15                  268964510     0x1008129E
XF86Macro16                  268964511     0x1008129F
XF86Macro17                  268964512     0x100812A0
XF86Macro18                  268964513     0x100812A1
XF86Macro19                  268964514     0x100812A2
XF86Macro20                  268964515     0x100812A3
XF86Macro21                  268964516     0x100812A4
XF86Macro22                  268964517     0x100812A5
F9                               65478     0xffc6
F10                              65479     0xffc7
L1                               65480     0xffc8
L2                               65481     0xffc9
L3                               65482     0xffca
L4                               65483     0xffcb
L5                               65484     0xffcc
L6                               65485     0xffcd
L7                               65486     0xffce
L8                               65487     0xffcf
L9                               65488     0xffd0
L10                              65489     0xffd1
R1                               65490     0xffd2
R2                               65491     0xffd3
XF86Macro23                  268964518     0x100812A6
XF86Macro24                  268964519     0x100812A7
XF86Macro25                  268964520     0x100812A8
XF86Macro26                  268964521     0x100812A9
XF86Macro27                  268964522     0x100812AA
XF86Macro28                  268964523     0x100812AB
XF86Macro29                  268964524     0x100812AC
XF86Macro30                  268964525     0x100812AD
R3                               65492     0xffd4
R4                               65493     0xffd5
R5                               65494     0xffd6
R6                               65495     0xffd7
R7                               65496     0xffd8
R8                               65497     0xffd9
R9                               65498     0xffda
XF86MacroRecordStart         268964528     0x100812B0
XF86MacroRecordStop          268964529     0x100812B1
XF86MacroPresetCycle         268964530     0x100812B2
XF86MacroPreset1             268964531     0x100812B3
R10                              65499     0xffdb
XF86MacroPreset2             268964532     0x100812B4
XF86MacroPreset3             268964533     0x100812B5
XF86KbdLcdMenu1              268964536     0x100812B8
XF86KbdLcdMenu2              268964537     0x100812B9
XF86KbdLcdMenu3              268964538     0x100812BA
XF86KbdLcdMenu4              268964539     0x100812BB
XF86KbdLcdMenu5              268964540     0x100812BC
XF86Switch_VT_1              269024769     0x1008FE01
R11                              65500     0xffdc
R12                              65501     0xffdd
F33                              65502     0xffde
R14                              65503     0xffdf
R15                              65504     0xffe0
Shift_L                          65505     0xffe1
XF86Switch_VT_2              269024770     0x1008FE02
XF86Switch_VT_3              269024771     0x1008FE03
XF86Switch_VT_4              269024772     0x1008FE04
XF86Switch_VT_5              269024773     0x1008FE05
XF86Switch_VT_6              269024774     0x1008FE06
XF86Switch_VT_7              269024775     0x1008FE07
XF86Switch_VT_8              269024776     0x1008FE08
XF86Switch_VT_9              269024777     0x1008FE09
XF86Switch_VT_10             269024778     0x1008FE0A
XF86Switch_VT_11             269024779     0x1008FE0B
XF86Switch_VT_12             269024780     0x1008FE0C
Shift_R                          65506     0xffe2
Control_L                        65507     0xffe3
Control_R                        65508     0xffe4
Caps_Lock                        65509     0xffe5
Shift_Lock                       65510     0xffe6
Meta_L                           65511     0xffe7
Meta_R                           65512     0xffe8
.CE
.CS
XF86Ungrab                   269024800     0x1008FE20
XF86ClearGrab                269024801     0x1008FE21
XF86Next_VMode               269024802     0x1008FE22
XF86Prev_VMode               269024803     0x1008FE23
Alt_L                            65513     0xffe9
Alt_R                            65514     0xffea
Super_L                          65515     0xffeb
Super_R                          65516     0xffec
XF86LogWindowTree            269024804     0x1008FE24
XF86LogGrabInfo              269024805     0x1008FE25
XF86ModeLock                 269025025     0x1008FF01
Hyper_L                          65517     0xffed
Hyper_R                          65518     0xffee
XF86MonBrightnessUp          269025026     0x1008FF02
XF86MonBrightnessDown        269025027     0x1008FF03
XF86KbdLightOnOff            269025028     0x1008FF04
XF86KbdBrightnessUp          269025029     0x1008FF05
XF86KbdBrightnessDown        269025030     0x1008FF06
XF86MonBrightnessCycle       269025031     0x1008FF07
XF86Standby                  269025040     0x1008FF10
Delete                           65535     0xffff
XF86AudioLowerVolume         269025041     0x1008FF11
XF86AudioMute                269025042     0x1008FF12
XF86AudioRaiseVolume         269025043     0x1008FF13
XF86AudioPlay                269025044     0x1008FF14
XF86AudioStop                269025045     0x1008FF15
XF86AudioPrev                269025046     0x1008FF16
XF86AudioNext                269025047     0x1008FF17
XF86HomePage                 269025048     0x1008FF18
XF86Mail                     269025049     0x1008FF19
XF86Start                    269025050     0x1008FF1A
XF86Search                   269025051     0x1008FF1B
XF86AudioRecord              269025052     0x1008FF1C
XF86Calculator               269025053     0x1008FF1D
XF86Memo                     269025054     0x1008FF1E
XF86ToDoList                 269025055     0x1008FF1F
XF86Calendar                 269025056     0x1008FF20
XF86PowerDown                269025057     0x1008FF21
XF86ContrastAdjust           269025058     0x1008FF22
XF86RockerUp                 269025059     0x1008FF23
XF86RockerDown               269025060     0x1008FF24
XF86RockerEnter              269025061     0x1008FF25
XF86Back                     269025062     0x1008FF26
XF86Forward                  269025063     0x1008FF27
XF86Stop                     269025064     0x1008FF28
XF86Refresh                  269025065     0x1008FF29
XF86PowerOff                 269025066     0x1008FF2A
XF86WakeUp                   269025067     0x1008FF2B
XF86Eject                    269025068     0x1008FF2C
XF86ScreenSaver              269025069     0x1008FF2D
XF86WWW                      269025070     0x1008FF2E
XF86Sleep                    269025071     0x1008FF2F
XF86Favorites                269025072     0x1008FF30
XF86AudioPause               269025073     0x1008FF31
XF86AudioMedia               269025074     0x1008FF32
XF86MyComputer               269025075     0x1008FF33
XF86VendorHome               269025076     0x1008FF34
XF86LightBulb                269025077     0x1008FF35
XF86Shop                     269025078     0x1008FF36
XF86History                  269025079     0x1008FF37
XF86OpenURL                  269025080     0x1008FF38
XF86AddFavorite              269025081     0x1008FF39
XF86HotLinks                 269025082     0x1008FF3A
XF86BrightnessAdjust         269025083     0x1008FF3B
XF86Finance                  269025084     0x1008FF3C
XF86Community                269025085     0x1008FF3D
XF86AudioRewind              269025086     0x1008FF3E
XF86BackForward              269025087     0x1008FF3F
XF86Launch0                  269025088     0x1008FF40
XF86Launch1                  269025089     0x1008FF41
XF86Launch2                  269025090     0x1008FF42
XF86Launch3                  269025091     0x1008FF43
XF86Launch4                  269025092     0x1008FF44
XF86Launch5                  269025093     0x1008FF45
XF86Launch6                  269025094     0x1008FF46
XF86Launch7                  269025095     0x1008FF47
XF86Launch8                  269025096     0x1008FF48
XF86Launch9                  269025097     0x1008FF49
XF86LaunchA                  269025098     0x1008FF4A
XF86LaunchB                  269025099     0x1008FF4B
XF86LaunchC                  269025100     0x1008FF4C
XF86LaunchD                  269025101     0x1008FF4D
XF86LaunchE                  269025102     0x1008FF4E
XF86LaunchF                  269025103     0x1008FF4F
XF86ApplicationLeft          269025104     0x1008FF50
XF86ApplicationRight         269025105     0x1008FF51
XF86Book                     269025106     0x1008FF52
XF86CD                       269025107     0x1008FF53
XF86Calculater               269025108     0x1008FF54
XF86Clear                    269025109     0x1008FF55
XF86Close                    269025110     0x1008FF56
XF86Copy                     269025111     0x1008FF57
XF86Cut                      269025112     0x1008FF58
XF86Display                  269025113     0x1008FF59
XF86DOS                      269025114     0x1008FF5A
XF86Documents                269025115     0x1008FF5B
XF86Excel                    269025116     0x1008FF5C
XF86Explorer                 269025117     0x1008FF5D
XF86Game                     269025118     0x1008FF5E
XF86Go                       269025119     0x1008FF5F
XF86iTouch                   269025120     0x1008FF60
XF86LogOff                   269025121     0x1008FF61
XF86Market                   269025122     0x1008FF62
XF86Meeting                  269025123     0x1008FF63
XF86MenuKB                   269025125     0x1008FF65
XF86MenuPB                   269025126     0x1008FF66
XF86MySites                  269025127     0x1008FF67
XF86New                      269025128     0x1008FF68
XF86News                     269025129     0x1008FF69
XF86OfficeHome               269025130     0x1008FF6A
XF86Open                     269025131     0x1008FF6B
XF86Option                   269025132     0x1008FF6C
XF86Paste                    269025133     0x1008FF6D
XF86Phone                    269025134     0x1008FF6E
XF86Q                        269025136     0x1008FF70
XF86Reply                    269025138     0x1008FF72
XF86Reload                   269025139     0x1008FF73
XF86RotateWindows            269025140     0x1008FF74
XF86RotationPB               269025141     0x1008FF75
XF86RotationKB               269025142     0x1008FF76
XF86Save                     269025143     0x1008FF77
XF86ScrollUp                 269025144     0x1008FF78
XF86ScrollDown               269025145     0x1008FF79
XF86ScrollClick              269025146     0x1008FF7A
XF86Send                     269025147     0x1008FF7B
XF86Spell                    269025148     0x1008FF7C
XF86SplitScreen              269025149     0x1008FF7D
XF86Support                  269025150     0x1008FF7E
XF86TaskPane                 269025151     0x1008FF7F
XF86Terminal                 269025152     0x1008FF80
XF86Tools                    269025153     0x1008FF81
XF86Travel                   269025154     0x1008FF82
XF86UserPB                   269025156     0x1008FF84
XF86User1KB                  269025157     0x1008FF85
XF86User2KB                  269025158     0x1008FF86
XF86Video                    269025159     0x1008FF87
XF86WheelButton              269025160     0x1008FF88
XF86Word                     269025161     0x1008FF89
XF86Xfer                     269025162     0x1008FF8A
XF86ZoomIn                   269025163     0x1008FF8B
XF86ZoomOut                  269025164     0x1008FF8C
XF86Away                     269025165     0x1008FF8D
XF86Messenger                269025166     0x1008FF8E
XF86WebCam                   269025167     0x1008FF8F
XF86MailForward              269025168     0x1008FF90
XF86Pictures                 269025169     0x1008FF91
XF86Music                    269025170     0x1008FF92
XF86Battery                  269025171     0x1008FF93
XF86Bluetooth                269025172     0x1008FF94
XF86WLAN                     269025173     0x1008FF95
XF86UWB                      269025174     0x1008FF96
XF86AudioForward             269025175     0x1008FF97
XF86AudioRepeat              269025176     0x1008FF98
XF86AudioRandomPlay          269025177     0x1008FF99
XF86Subtitle                 269025178     0x1008FF9A
XF86AudioCycleTrack          269025179     0x1008FF9B
XF86CycleAngle               269025180     0x1008FF9C
XF86FrameBack                269025181     0x1008FF9D
XF86FrameForward             269025182     0x1008FF9E
XF86Time                     269025183     0x1008FF9F
XF86Select                   269025184     0x1008FFA0
XF86View                     269025185     0x1008FFA1
XF86TopMenu                  269025186     0x1008FFA2
XF86Red                      269025187     0x1008FFA3
XF86Green                    269025188     0x1008FFA4
XF86Yellow                   269025189     0x1008FFA5
XF86Blue                     269025190     0x1008FFA6
XF86Suspend                  269025191     0x1008FFA7
XF86Hibernate                269025192     0x1008FFA8
XF86TouchpadToggle           269025193     0x1008FFA9
XF86TouchpadOn               269025200     0x1008FFB0
XF86TouchpadOff              269025201     0x1008FFB1
XF86AudioMicMute             269025202     0x1008FFB2
XF86Keyboard                 269025203     0x1008FFB3
XF86WWAN                     269025204     0x1008FFB4
XF86RFKill                   269025205     0x1008FFB5
XF86AudioPreset              269025206     0x1008FFB6
XF86RotationLockToggle       269025207     0x1008FFB7
XF86FullScreen               269025208     0x1008FFB8
.CE
.SH "SEE ALSO"
bind(n), event(n)
.SH KEYWORDS
bind, binding, event, keysym
'\" Local Variables:
'\" mode: nroff

Changes to doc/label.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH label n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
label \- Create and manipulate 'label' non-interactive text or image widgets
.SH SYNOPSIS
\fBlabel\fI pathName \fR?\fIoptions\fR?
\fBlabel\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-disabledforeground	\-padx
\-activeforeground	\-font	\-pady
\-anchor	\-foreground	\-relief
\-background	\-highlightbackground	\-takefocus
\-bitmap	\-highlightcolor	\-text
\-borderwidth	\-highlightthickness	\-textvariable
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118




119
120
121
122
123
124
125
126





127
128
129
130
131
132
133
134
71
72
73
74
75
76
77

78
79
80
81
82

83

84

85
86
87
88

89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110




111
112
113
114
115
116
117





118
119
120
121
122
123
124
125
126
127
128
129
130







-
+




-

-
+
-




-


-




















-
-
-
-
+
+
+
+



-
-
-
-
-
+
+
+
+
+








.SH "WIDGET COMMAND"
.PP
The \fBlabel\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for label widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBlabel\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBlabel\fR
command.
.SH BINDINGS
.PP
When a new label is created, it has no default event bindings:
labels are not intended to be interactive.
.SH EXAMPLE
.PP
.CS
# Make the widgets
\fBlabel\fR .t -text "This widget is at the top"    -bg red
\fBlabel\fR .b -text "This widget is at the bottom" -bg green
\fBlabel\fR .l -text "Left\enHand\enSide"
\fBlabel\fR .r -text "Right\enHand\enSide"
\fBlabel\fR .t \-text "This widget is at the top"    \-bg red
\fBlabel\fR .b \-text "This widget is at the bottom" \-bg green
\fBlabel\fR .l \-text "Left\enHand\enSide"
\fBlabel\fR .r \-text "Right\enHand\enSide"
text .mid
\&.mid insert end "This layout is like Java's BorderLayout"
# Lay them out
pack .t   -side top    -fill x
pack .b   -side bottom -fill x
pack .l   -side left   -fill y
pack .r   -side right  -fill y
pack .mid -expand 1    -fill both
pack .t   \-side top    \-fill x
pack .b   \-side bottom \-fill x
pack .l   \-side left   \-fill y
pack .r   \-side right  \-fill y
pack .mid \-expand 1    \-fill both
.CE
.SH "SEE ALSO"
labelframe(n), button(n), ttk::label(n)
.SH KEYWORDS
label, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/labelframe.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH labelframe n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
labelframe \- Create and manipulate 'labelframe' labelled container widgets
.SH SYNOPSIS
\fBlabelframe\fI pathName\fR ?\fIoptions\fR?
\fBlabelframe\fR \fIpathName\fR ?\fIoptions\fR?
.SO
\-borderwidth	\-highlightbackground	\-pady
\-cursor	\-highlightcolor	\-relief
\-font	\-highlightthickness	\-takefocus
\-foreground	\-padx	\-text
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
91
92
93
94
95
96
97

98
99
100
101
102
103

104

105

106
107
108
109

110

111

112
113
114
115
116
117
118







-
+





-

-
+
-




-

-
+
-







.SH "WIDGET COMMAND"
.PP
The \fBlabelframe\fR command creates a new Tcl command whose
name is the same as the path name of the labelframe's window.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIPathName\fR is the name of the command, which is the same as
the labelframe widget's path name.  \fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for frame widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBlabelframe\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
\fIpathName \fBconfigure\fR ?\fIoption\fR? \fI?value option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
132
133
134
135
136
137
138
139
140
141
142




143
144
145
146
147
148
149
128
129
130
131
132
133
134




135
136
137
138
139
140
141
142
143
144
145







-
-
-
-
+
+
+
+







.SH EXAMPLE
.PP
This shows how to build part of a GUI for a hamburger vendor. The
\fBlabelframe\fR widgets are used to organize the available choices by
the kinds of things that the choices are being made over.
.PP
.CS
grid [\fBlabelframe\fR .burger -text "Burger"] \e
     [\fBlabelframe\fR .bun    -text "Bun"] -sticky news
grid [\fBlabelframe\fR .cheese -text "Cheese Option"] \e
     [\fBlabelframe\fR .pickle -text "Pickle Option"] -sticky news
grid [\fBlabelframe\fR .burger \-text "Burger"] \e
     [\fBlabelframe\fR .bun    \-text "Bun"] \-sticky news
grid [\fBlabelframe\fR .cheese \-text "Cheese Option"] \e
     [\fBlabelframe\fR .pickle \-text "Pickle Option"] \-sticky news
foreach {type name val} {
    burger Beef    beef
    burger Lamb    lamb
    burger Vegetarian beans

    bun    Plain   white
    bun    Sesame  seeds
157
158
159
160
161
162
163
164
165
166



167
168
169
170
171
172
173
174
175
176
177
178
179
153
154
155
156
157
158
159



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175







-
-
-
+
+
+













    cheese "Monterey Jack" jack

    pickle None    none
    pickle Gherkins gherkins
    pickle Onions  onion
    pickle Chili   chili
} {
    set w [radiobutton .$type.$val -text $name -anchor w \e
            -variable $type -value $val]
    pack $w -side top -fill x
    set w [radiobutton .$type.$val \-text $name \-anchor w \e
            \-variable $type \-value $val]
    pack $w \-side top \-fill x
}
set burger beef
set bun    white
set cheese none
set pickle none
.CE
.SH "SEE ALSO"
frame(n), label(n), ttk::labelframe(n)
.SH KEYWORDS
labelframe, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/listbox.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH listbox n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
listbox \- Create and manipulate 'listbox' item list widgets
.SH SYNOPSIS
\fBlistbox\fI pathName \fR?\fIoptions\fR?
\fBlistbox\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-background	\-borderwidth	\-cursor
\-disabledforeground	\-exportselection	\-font
\-foreground	\-highlightbackground	\-highlightcolor
\-highlightthickness	\-justify	\-relief
\-selectbackground	\-selectborderwidth	\-selectforeground
\-setgrid	\-takefocus	\-xscrollcommand
91
92
93
94
95
96
97

98


99
100

101


102
103
104
105

106


107
108

109


110
111
112
113

114

115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
91
92
93
94
95
96
97
98

99
100
101
102
103

104
105
106
107
108
109
110

111
112
113
114
115

116
117
118
119
120
121
122

123
124
125
126
127

128



129
130
131
132
133
134
135
136
137
138

139
140
141
142
143

144

145
146
147
148
149
150
151
152

153

154
155
156
157
158
159
160
161
162
163
164
165
166
167

168

169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196

197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220

221
222
223
224
225
226
227

228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253

254
255
256
257
258

259
260
261
262
263
264

265
266
267
268
269
270
271

272
273
274
275
276

277

278
279
280
281
282
283
284
285







+
-
+
+


+
-
+
+




+
-
+
+


+
-
+
+




+
-
+




-
+
-
-
-










-
+




-

-
+







-

-
+













-

-
+





-















-







-







-











-






-







-






-















-





-





-






-







-





-

-
+







They also support scanning, as described below.
.SH "INDICES"
.PP
Many of the widget commands for listboxes take one or more indices
as arguments.
An index specifies a particular element of the listbox, in any of
the following ways:
.TP 12
.IP \fInumber\fR 12
\fInumber\fR
.
Specifies the element as a numerical index, where 0 corresponds
to the first element in the listbox.
.TP 12
.IP \fBactive\fR 12
\fBactive\fR
.
Indicates the element that has the location cursor.  This element
will be displayed as specified by \fB\-activestyle\fR when the listbox
has the keyboard focus, and it is specified with the \fBactivate\fR
widget command.
.TP 12
.IP \fBanchor\fR 12
\fBanchor\fR
.
Indicates the anchor point for the selection, which is set with the
\fBselection anchor\fR widget command.
.TP 12
.IP \fBend\fR 12
\fBend\fR
.
Indicates the end of the listbox.
For most commands this refers to the last element in the listbox,
but for a few commands such as \fBindex\fR and \fBinsert\fR
it refers to the element just after the last one.
.TP 12
.IP \fB@\fIx\fB,\fIy\fR 12
\fB@\fIx\fB,\fIy\fR
Indicates the element that covers the point in the listbox window
specified by \fIx\fR and \fIy\fR (in pixel coordinates).  If no
element covers that point, then the closest element to that
point is used.
.PP
.LP
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
In the widget command descriptions below, arguments named \fIindex\fR,
\fIfirst\fR, and \fIlast\fR always contain text indices in one of
the above forms.
.SH "WIDGET COMMAND"
.PP
The \fBlistbox\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for listbox widgets:
.\" METHOD: activate
.TP
\fIpathName \fBactivate\fI index\fR
\fIpathName \fBactivate\fR \fIindex\fR
.
Sets the active element to the one indicated by \fIindex\fR.
If \fIindex\fR is outside the range of elements in the listbox
then the closest element is activated.
The active element is drawn as specified by \fB\-activestyle\fR when the
widget has the input focus, and its index may be retrieved with the
index \fBactive\fR.
.\" METHOD: bbox
.TP
\fIpathName \fBbbox\fI index\fR
\fIpathName \fBbbox\fR \fIindex\fR
.
Returns a list of four numbers describing the bounding box of
the text in the element given by \fIindex\fR.
The first two elements of the list give the x and y coordinates
of the upper-left corner of the screen area covered by the text
(specified in pixels relative to the widget) and the last two
elements give the width and height of the area, in pixels.
If no part of the element given by \fIindex\fR is visible on the
screen,
or if \fIindex\fR refers to a non-existent element,
then the result is an empty string;  if the element is
partially visible, the result gives the full area of the element,
including any parts that are not visible.
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBlistbox\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBlistbox\fR
command.
.\" METHOD: curselection
.TP
\fIpathName \fBcurselection\fR
.
Returns a list containing the numerical indices of
all of the elements in the listbox that are currently selected.
If there are no elements selected in the listbox then an empty
string is returned.
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fIfirst \fR?\fIlast\fR?
.
Deletes one or more elements of the listbox.  \fIFirst\fR and \fIlast\fR
are indices specifying the first and last elements in the range
to delete.  If \fIlast\fR is not specified it defaults to
\fIfirst\fR, i.e. a single element is deleted.
.\" METHOD: get
.TP
\fIpathName \fBget \fIfirst\fR ?\fIlast\fR?
.
If \fIlast\fR is omitted, returns the contents of the listbox
element indicated by \fIfirst\fR,
or an empty string if \fIfirst\fR refers to a non-existent element.
If \fIlast\fR is specified, the command returns a list whose elements
are all of the listbox elements between \fIfirst\fR and \fIlast\fR,
inclusive.
Both \fIfirst\fR and \fIlast\fR may have any of the standard
forms for indices.
.\" METHOD: index
.TP
\fIpathName \fBindex \fIindex\fR
.
Returns the integer index value that corresponds to \fIindex\fR.
If \fIindex\fR is \fBend\fR the return value is a count of the number
of elements in the listbox (not the index of the last element).
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex \fR?\fIelement element ...\fR?
.
Inserts zero or more new elements in the list just before the
element given by \fIindex\fR.  If \fIindex\fR is specified as
\fBend\fR then the new elements are added to the end of the
list.  Returns an empty string.
.\" METHOD: itemcget
.TP
\fIpathName \fBitemcget \fIindex option\fR
.
Returns the current value of the item configuration option given
by \fIoption\fR. \fIOption\fR may have any of the values accepted
by the \fBitemconfigure\fR command.
.\" METHOD: itemconfigure
.TP
\fIpathName \fBitemconfigure \fIindex\fR ?\fIoption\fR? ?\fIvalue\fR? ?\fIoption value ...\fR?
.
Query or modify the configuration options of an item in the listbox.
If no \fIoption\fR is specified, returns a list describing all of
the available options for the item (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string. The following options
are currently supported for items:
.RS
.\" OPTION: -background
.TP
\fB\-background \fIcolor\fR
.
\fIColor\fR specifies the background color to use when displaying the
item. It may have any of the forms accepted by \fBTk_GetColor\fR.
.\" OPTION: -foreground
.TP
\fB\-foreground \fIcolor\fR
.
\fIColor\fR specifies the foreground color to use when displaying the
item. It may have any of the forms accepted by \fBTk_GetColor\fR.
.\" OPTION: -selectbackground
.TP
\fB\-selectbackground \fIcolor\fR
.
\fIcolor\fR specifies the background color to use when displaying the
item while it is selected. It may have any of the forms accepted by
\fBTk_GetColor\fR.
.\" OPTION: -selectforeground
.TP
\fB\-selectforeground \fIcolor\fR
.
\fIcolor\fR specifies the foreground color to use when displaying the
item while it is selected. It may have any of the forms accepted by
\fBTk_GetColor\fR.
.RE
.\" METHOD: nearest
.TP
\fIpathName \fBnearest \fIy\fR
.
Given a y-coordinate within the listbox window, this command returns
the index of the (visible) listbox element nearest to that y-coordinate.
.\" METHOD: scan
.TP
\fIpathName \fBscan\fI option args\fR
\fIpathName \fBscan\fR \fIoption args\fR
.
This command is used to implement scanning on listboxes.  It has
two forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBscan mark \fIx y\fR
.
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317







-









-







\fBscan mark\fR command for the widget.
It then adjusts the view by 10 times the
difference in coordinates.  This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the list at high speed through the window.  The return
value is an empty string.
.RE
.\" METHOD: see
.TP
\fIpathName \fBsee \fIindex\fR
.
Adjust the view in the listbox so that the element given by \fIindex\fR
is visible.
If the element is already visible then the command has no effect;
if the element is near one edge of the window then the listbox
scrolls to bring the element into view at the edge;  otherwise
the listbox scrolls to center the element.
.\" METHOD: selection
.TP
\fIpathName \fBselection \fIoption arg\fR
.
This command is used to adjust the selection within a listbox.  It
has several forms, depending on \fIoption\fR:
.RS
.TP
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
339
340
341
342
343
344
345

346
347
348
349
350

351
352
353
354
355
356
357







-





-







.TP
\fIpathName \fBselection set \fIfirst \fR?\fIlast\fR?
.
Selects all of the elements in the range between
\fIfirst\fR and \fIlast\fR, inclusive, without affecting
the selection state of elements outside that range.
.RE
.\" METHOD: size
.TP
\fIpathName \fBsize\fR
.
Returns a decimal string indicating the total number of elements
in the listbox.
.\" METHOD: xview
.TP
\fIpathName \fBxview \fR?\fIargs\fR
.
This command is used to query and change the horizontal position of the
information in the widget's window.  It can take any of the following
forms:
.RS
394
395
396
397
398
399
400
401

402
403

404


405

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
379
380
381
382
383
384
385

386


387
388
389
390

391
392
393
394
395



396

397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412







-
+
-
-
+

+
+
-
+




-
-
-

-









-







total width of the listbox text is off-screen to the left.
\fIfraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR character units (the width of the \fB0\fR character)
If \fIwhat\fR is \fBpages\fR then the view adjusts by
on the display;  if it is \fBpages\fR then the view adjusts by
\fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left
become visible;  if it is positive then characters farther to the right
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR character units (the width of the \fB0\fR character)
on the display.
.RE
.\" METHOD: yview
.TP
\fIpathName \fByview \fR?\fIargs\fR?
.
This command is used to query and change the vertical position of the
text in the widget's window.
It can take any of the following forms:
.RS
.TP
\fIpathName \fByview\fR
.
Returns a list containing two elements, both of which are real fractions
between 0 and 1.
The first element gives the position of the listbox element at the
top of the window, relative to the listbox as a whole (0.5 means
it is halfway through the listbox, for example).
The second element gives the position of the listbox element just after
the last one in the window, relative to the listbox as a whole.
445
446
447
448
449
450
451
452

453
454
455



456
457
458
459
460
461
462
463
464
465
466
467
468
426
427
428
429
430
431
432

433



434
435
436
437
438
439
440


441
442
443
444
445
446
447







-
+
-
-
-
+
+
+




-
-







element in the listbox, 0.33 indicates the element one-third the
way through the listbox, and so on.
.TP
\fIpathName \fByview scroll \fInumber what\fR
.
This command adjusts the view in the window up or down according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR.
If \fIwhat\fR is \fBpages\fR then
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR.
If \fIwhat\fR is \fBunits\fR, the view adjusts up or down by
\fInumber\fR lines;  if it is \fBpages\fR then
the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then earlier elements
become visible;  if it is positive then later elements
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts up or down by
\fInumber\fR lines.
.RE
.SH "DEFAULT BINDINGS"
.PP
Tk automatically creates class bindings for listboxes that give them
Motif-like behavior.  Much of the behavior of a listbox is determined
by its \fB\-selectmode\fR option, which selects one of four ways
of dealing with the selection.
577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570







-
+







extend the selection to the active element just as if button 1
had been pressed with the Shift key down.
.IP [16]
In \fBextended\fR mode, the Escape key cancels the most recent
selection and restores all the elements in the selected range
to their previous selection state.
.IP [17]
Control-/ selects everything in the widget, except in
Control-slash selects everything in the widget, except in
\fBsingle\fR and \fBbrowse\fR modes, in which case it selects
the active element and deselects everything else.
.IP [18]
Control-backslash deselects everything in the widget, except in
\fBbrowse\fR mode where it has no effect.
.IP [19]
The F16 key (labelled Copy on many Sun workstations) or Meta-w

Changes to doc/loadTk.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52



53
54

55
56
57
58
59
60
61
62
63
64
65
66


67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45

46
47
48
49



50
51
52
53

54
55
56
57
58
59
60
61
62
63
64


65
66
67
68
69













-
+




















-
+










-
+



-
-
-
+
+
+

-
+










-
-
+
+



'\"
'\" 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.
'\"
.TH "Safe Tk" n 8.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
safe::loadTk \- Load Tk into a safe interpreter.
.SH SYNOPSIS
\fBsafe::loadTk \fIchild\fR ?\fB\-use\fI windowId\fR? ?\fB\-display\fI displayName\fR?
\fBsafe::loadTk \fIslave\fR ?\fB\-use\fR \fIwindowId\fR? ?\fB\-display\fR \fIdisplayName\fR?
.BE
.SH DESCRIPTION
.PP
Safe Tk is based on Safe Tcl, which provides a mechanism that allows
restricted and mediated access to auto-loading and packages for safe
interpreters.  Safe Tk adds the ability to configure the interpreter for safe
Tk operations and load Tk into safe interpreters.
.PP
The \fBsafe::loadTk\fR command initializes the required data structures in
the named safe interpreter and then loads Tk into it.  The interpreter must
have been created with \fBsafe::interpCreate\fR or have been initialized
with \fBsafe::interpInit\fR.  The command returns the name of the safe
interpreter.  If \fB\-use\fR is specified, the window identified by the
specified system dependent identifier \fIwindowId\fR is used to contain the
.QW .
window of the safe interpreter; it can be any valid id, eventually referencing
a window belonging to another application. As a convenience, if the window you
plan to use is a Tk Window of the application you can use the window name
(e.g.,
.QW \fB.x.y\fR )
instead of its window Id (e.g., from \fBwinfo id\fI .x.y\fR).
instead of its window Id (e.g., from \fBwinfo id\fR \fB.x.y\fR).
When \fB\-use\fR is not specified, a new toplevel window is created for the
.QW .
window of the safe interpreter. On X11 if you want the embedded window to use
another display than the default one, specify it with \fB\-display\fR.  See
the \fBSECURITY ISSUES\fR section below for implementation details.
.SH "SECURITY ISSUES"
.PP
Please read the \fBsafe\fR manual page for Tcl to learn about the basic
security considerations for Safe Tcl.
.PP
\fBsafe::loadTk\fR adds the value of \fBtk_library\fR taken from the parent
\fBsafe::loadTk\fR adds the value of \fBtk_library\fR taken from the master
interpreter to the virtual access path of the safe interpreter so that
auto-loading will work in the safe interpreter.
.PP
Tk initialization is now safe with respect to not trusting the child's state
for startup. \fBsafe::loadTk\fR registers the child's name so when the Tk
initialization (\fBTk_SafeInit\fR) is called and in turn calls the parent's
Tk initialization is now safe with respect to not trusting the slave's state
for startup. \fBsafe::loadTk\fR registers the slave's name so when the Tk
initialization (\fBTk_SafeInit\fR) is called and in turn calls the master's
\fBsafe::InitTk\fR it will return the desired \fBargv\fR equivalent
(\fB\-use\fI windowId\fR, correct \fB\-display\fR, etc.)
(\fB\-use\fR \fIwindowId\fR, correct \fB\-display\fR, etc.)
.PP
When \fB\-use\fR is not used, the new toplevel created is specially decorated
so the user is always aware that the user interface presented comes from a
potentially unsafe code and can easily delete the corresponding interpreter.
.PP
On X11, conflicting \fB\-use\fR and \fB\-display\fR are likely to generate a
fatal X error.
.SH "SEE ALSO"
safe(n), interp(n), library(n), load(n), package(n), source(n), unknown(n)
.SH KEYWORDS
alias, auto-loading, auto_mkindex, load, parent interpreter, safe
interpreter, child interpreter, source
alias, auto-loading, auto_mkindex, load, master interpreter, safe
interpreter, slave interpreter, source
'\" Local Variables:
'\" mode: nroff
'\" End:

Deleted doc/man.macros.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267











































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
.\"	and indent is equivalent to second arg of .IP (shouldn't ever be
.\"	needed;  use .AS below instead)
.\"
.\" .AS ?type? ?name?
.\"	Give maximum sizes of arguments for setting tab stops.  Type and
.\"	name are examples of largest possible arguments that will be passed
.\"	to .AP later.  If args are omitted, default tab stops are used.
.\"
.\" .BS
.\"	Start box enclosure.  From here until next .BE, everything will be
.\"	enclosed in one large box.
.\"
.\" .BE
.\"	End of box enclosure.
.\"
.\" .CS
.\"	Begin code excerpt.
.\"
.\" .CE
.\"	End code excerpt.
.\"
.\" .VS ?version? ?br?
.\"	Begin vertical sidebar, for use in marking newly-changed parts
.\"	of man pages.  The first argument is ignored and used for recording
.\"	the version when the .VS was added, so that the sidebars can be
.\"	found and removed when they reach a certain age.  If another argument
.\"	is present, then a line break is forced before starting the sidebar.
.\"
.\" .VE
.\"	End of vertical sidebar.
.\"
.\" .DS
.\"	Begin an indented unfilled display.
.\"
.\" .DE
.\"	End of indented unfilled display.
.\"
.\" .SO ?manpage?
.\"	Start of list of standard options for a Tk widget. The manpage
.\"	argument defines where to look up the standard options; if
.\"	omitted, defaults to "options". The options follow on successive
.\"	lines, in three columns separated by tabs.
.\"
.\" .SE
.\"	End of list of standard options for a Tk widget.
.\"
.\" .OP cmdName dbName dbClass
.\"	Start of description of a specific option.  cmdName gives the
.\"	option's name as specified in the class command, dbName gives
.\"	the option's name in the option database, and dbClass gives
.\"	the option's class in the option database.
.\"
.\" .UL arg1 arg2
.\"	Print arg1 underlined, then print arg2 normally.
.\"
.\" .QW arg1 ?arg2?
.\"	Print arg1 in quotes, then arg2 normally (for trailing punctuation).
.\"
.\" .PQ arg1 ?arg2?
.\"	Print an open parenthesis, arg1 in quotes, then arg2 normally
.\"	(for trailing punctuation) and then a closing parenthesis.
.\"
.\"	# Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
.\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1 \\fI\\$2\\fP (\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
.\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
.\"	# BS - start boxed text
.\"	# ^y = starting y location
.\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
.\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
.\"	# VS - start vertical sidebar
.\"	# ^Y = starting y location
.\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
.\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
.\"	# Special macro to handle page bottom:  finish off current
.\"	# box/sidebar if in box/sidebar mode, then invoked standard
.\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
.\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
.\"	# DE - end display
.de DE
.fi
.RE
.sp
..
.\"	# SO - start of list of standard options
.de SO
'ie '\\$1'' .ds So \\fBoptions\\fR
'el .ds So \\fB\\$1\\fR
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 5.5c 11c
.ft B
..
.\"	# SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\*(So manual entry for details on the standard options.
..
.\"	# OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name:	\\fB\\$1\\fR
Database Name:	\\fB\\$2\\fR
Database Class:	\\fB\\$3\\fR
.fi
.IP
..
.\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
.\"	# CE - end code excerpt
.de CE
.fi
.RE
..
.\"	# UL - underline word
.de UL
\\$1\l'|0\(ul'\\$2
..
.\"	# QW - apply quotation marks to word
.de QW
.ie '\\*(lq'"' ``\\$1''\\$2
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\$2
..
.\"	# PQ - apply parens and quotation marks to word
.de PQ
.ie '\\*(lq'"' (``\\$1''\\$2)\\$3
.\"" fix emacs highlighting
.el (\\*(lq\\$1\\*(rq\\$2)\\$3
..
.\"	# QR - quoted range
.de QR
.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
..
.\"	# MT - "empty" string
.de MT
.QW ""
..

Changes to doc/menu.n.

9
10
11
12
13
14
15
16
17


18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
9
10
11
12
13
14
15


16
17

18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
-
+
+
-




-
+














-
-
-
-
-
-
-
+
+
+
+
+
+
+













-
+







.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
menu, tk_menuSetFocus \- Create and manipulate 'menu' widgets and menubars
.SH SYNOPSIS
.nf
\fBmenu\fI pathName \fR?\fIoptions\fR?
\fBtk_menuSetFocus\fI pathName\fR
\fBmenu\fR \fIpathName \fR?\fIoptions\fR?
\fBtk_menuSetFocus\fR \fIpathName\fR
.fi
.SO
\-activebackground	\-borderwidth	\-foreground
\-activeborderwidth	\-cursor	\-relief
\-activeforeground	\-disabledforeground	\-takefocus
\-background	\-font	\-activerelief
\-background	\-font
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-postcommand postCommand Command
If this option is specified then it provides a Tcl command to execute
each time the menu is posted.  The command is invoked by the \fBpost\fR
widget command before posting the menu. Note that in Tk 8.0 on Macintosh
and Windows, all post-commands in a system of menus are executed before any
of those menus are posted.
This is due to the limitations in the individual platforms' menu managers.
.OP \-selectcolor selectColor Background
For menu entries that are check buttons or radio buttons, this option
specifies the color to display in the indicator when the check button
or radio button is selected.
.OP \-tearoff tearOff TearOff
This option must have a proper boolean value (default is false),
which specifies whether or not the menu should include a tear-off
entry at the top.  If so, it will exist as entry 0 of the menu and
the other entries will number starting at 1.  The default menu
bindings arrange for the menu to be torn off when the tear-off entry
is invoked.
This option is ignored under Aqua/MacOS, where menus cannot
This option must have a proper boolean value, which specifies
whether or not the menu should include a tear-off entry at the
top.  If so, it will exist as entry 0 of the menu and the other
entries will number starting at 1.  The default
menu bindings arrange for the menu to be torn off when the tear-off
entry is invoked.
This option is ignored under Aqua/Mac OS X, where menus cannot
be torn off.
.OP \-tearoffcommand tearOffCommand TearOffCommand
If this option has a non-empty value, then it specifies a Tcl command
to invoke whenever the menu is torn off.  The actual command will
consist of the value of this option, followed by a space, followed
by the name of the menu window, followed by a space, followed by
the name of the name of the torn off menu window.  For example, if
the option's value is
.QW "\fBa b\fR"
and menu \fB.x.y\fR is torn off to
create a new menu \fB.x.tearoff1\fR, then the command
.QW "\fBa b .x.y .x.tearoff1\fR"
will be invoked.
This option is ignored under Aqua/MacOS, where menus cannot
This option is ignored under Aqua/Mac OS X, where menus cannot
be torn off.
.OP \-title title Title
The string will be used to title the window created when this menu is
torn off. If the title is NULL, then the window will have the title
of the menubutton or the text of the cascade item from which this menu
was invoked.
.OP \-type type Type
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277
278
260
261
262
263
264
265
266

267



268
269
270
271
272
273
274







-
+
-
-
-







becoming the Application menu.
.PP
When Tk sees a .menubar.window menu on the Macintosh, the menu's
contents are inserted into the standard Window menu of the user's
menubar whenever the window's menubar is in front. The first items in
the menu are provided by Mac OS X, and the names of the current
toplevels are automatically appended after all the Tk-defined items and
a separator. The Window menu on the Mac also allows toggling the
a separator.
window into a fullscreen state, and managing a tabbed window interface
(multiple windows grouped into a single window) if supported by that
version of the operating system.
.PP
When Tk sees a .menubar.help menu on the Macintosh, the menu's contents
are appended to the standard Help menu of the user's menubar whenever
the window's menubar is in front. The first items in the menu
are provided by Mac OS X.
.PP
When Tk sees a System menu on Windows, its items are appended to the
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315

316


317
318

319

320


321
322

323

324


325

326


327
328
329
330
331

332


333
334
335
336







337
338



339
340
341

342
343



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369
370
371

372
373
374
375
376

377
378
379
380
381
382



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

463
464
465

466
467
468
469
470
471



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492

493
494
495
496
497
498
499
500
501








502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549


550
551
552
553
554
555
556
557
558
559
560

561
562
563

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310
311
312

313
314
315

316
317
318

319
320
321

322
323
324

325
326
327
328

329
330
331
332
333
334

335
336
337
338




339
340
341
342
343
344
345


346
347
348
349
350
351
352


353
354
355



356
357
358
359
360
361
362



363
364

365
366
367
368
369
370

371
372
373

374

375
376
377
378
379

380






381
382
383

384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422

423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442










443
444
445
446

447

448

449
450
451
452



453
454
455
456


457
458
459
460
461
462
463
464
465
466
467
468

469

470
471
472

473









474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497

498
499
500
501
502
503
504

505
506
507
508
509

510
511
512
513
514
515
516
517

518
519
520
521


522
523
524
525
526
527
528

529
530
531
532

533
534
535

536
537
538
539
540
541
542
543
544
545

546
547
548
549
550


551
552
553

554
555
556
557
558
559
560
561
562
563
564
565

566
567
568
569
570
571

572
573

574
575
576
577
578

579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596

597
598
599
600
601


602
603
604

605
606
607
608
609
610
611

612
613
614
615
616
617
618
619
620
621
622
623

624
625
626
627
628
629

630
631
632
633
634

635
636
637
638
639
640

641
642
643
644
645
646

647
648
649
650
651

652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686

687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703

704
705
706
707
708
709
710







-
+








+
-
+
+

-
+

+
-
+
+

-
+

+
-
+
+

+
-
+
+




-
+

+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+



+
-
-
+
+
+
-
-
-







-
-
-


-






-
+


-

-
+




-
+
-
-
-
-
-
-
+
+
+
-







-









-















-








-







-













-
-
-
-
-
-
-
-
-
-




-
+
-

-
+



-
-
-
+
+
+

-
-












-

-
+


-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-









-







-







-





-








-




-
-
+
+





-




-
+


-
+









-





-
-
+


-












-






-
+

-





-










-








-





-
-
+


-







-












-






-





-






-






-





-








-










-

















-










-







-







.SH "WIDGET COMMAND"
.PP
The \fBmenu\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.
.PP
Many of the widget commands for a menu take as one argument an
indicator of which entry of the menu to operate on. These
indicators are called \fIindex\fRes and may be specified in
any of the following forms:
.TP 12
.IP \fBactive\fR 12
\fBactive\fR
.
Indicates the entry that is currently active.  If no entry is
active then this form is equivalent to \fB{}\fR.  This form may
active then this form is equivalent to \fBnone\fR.  This form may
not be abbreviated.
.TP 12
.IP \fBend\fR 12
\fBend\fR
.
Indicates the bottommost entry in the menu.  If there are no
entries in the menu then this form is equivalent to \fB{}\fR.
entries in the menu then this form is equivalent to \fBnone\fR.
This form may not be abbreviated.
.TP 12
.IP \fBlast\fR 12
\fBlast\fR
.
Same as \fBend\fR.
.TP 12
.IP \fB{}\fR 12
\fBnone\fR
.
Indicates
.QW "no entry at all" ;
this is used most commonly with
the \fBactivate\fR option to deactivate all the entries in the
menu.  In most cases the specification of \fB{}\fR causes
menu.  In most cases the specification of \fBnone\fR causes
nothing to happen in the widget command.
This form may not be abbreviated.
.TP 12
.IP \fB@\fIx\fB,\fIy\fR 12
Indicates the entry that covers the point in the menu's window specified
by \fIx\fR and \fIy\fR (in pixel coordinates).
If no entry covers that point, then this form is equivalent to \fB{}\fR.
\fB@\fInumber\fR
.
In this form, \fInumber\fR is treated as a y-coordinate in the
menu's window;  the entry closest to that y-coordinate is used.
For example,
.QW \fB@0\fR
indicates the top-most entry in the window.
If only a single number is specified, it is treated as the y-coordinate.
.IP \fInumber\fR 12
.TP 12
\fInumber\fR
.
Specifies the entry numerically, where 0 corresponds
to the top-most entry of the menu, 1 to the entry below it, and
so on.
.TP 12
.IP \fIid\fR 12
If the index does not satisfy one of the above forms then the menu is
\fIpattern\fR
.
If the index does not satisfy one of the above forms then this
searched for an entry with the specified id.
.IP \fIpattern\fR 12
If all of the above methods for finding an entry fail, this
form is used.  \fIPattern\fR is pattern-matched against the label of
each entry in the menu, in order from the top down, until a
matching entry is found.  The rules of \fBstring match\fR
are used.
.PP
If the index could match more than one of the above forms, then
the form earlier in the above list takes precedence.
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.PP
The following widget commands are possible for menu widgets:
.\" METHOD: activate
.TP
\fIpathName \fBactivate \fIindex\fR
.
Change the state of the entry indicated by \fIindex\fR to \fBactive\fR
and redisplay it using its active colors.
Any previously-active entry is deactivated.  If \fIindex\fR
is specified as \fB{}\fR, or if the specified entry is
is specified as \fBnone\fR, or if the specified entry is
disabled, then the menu ends up with no active entry.
Returns an empty string.
.\" METHOD: add
.TP
\fIpathName \fBadd \fItype \fR?\fIid\fR? ?\fIoption value option value ...\fR?
\fIpathName \fBadd \fItype \fR?\fIoption value option value ...\fR?
.
Add a new entry to the bottom of the menu.  The new entry's type
is given by \fItype\fR and must be one of \fBcascade\fR,
\fBcheckbutton\fR, \fBcommand\fR, \fBradiobutton\fR, or \fBseparator\fR,
or a unique abbreviation of one of the above.
or a unique abbreviation of one of the above.  If additional arguments
If the \fIid\fR argument is specified, it is used as the entry identifier;
\fIid\fR must not already exist in the menu. Otherwise, a new unique
identifier is generated.
If additional arguments are present, they specify the options listed in the
\fBMENU ENTRY OPTIONS\fR section below.
The \fBadd\fR widget command returns the id of the new entry.
are present, they specify the options listed in the \fBMENU ENTRY OPTIONS\fR
section below.
The \fBadd\fR widget command returns an empty string.
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBmenu\fR
command.
.\" METHOD: clone
.TP
\fIpathName \fBclone \fInewPathname\fR ?\fIcloneType\fR?
.
Makes a clone of the current menu named \fInewPathName\fR. This clone
is a menu in its own right, but any changes to the clone are
propagated to the original menu and vice versa. \fIcloneType\fR can be
\fBnormal\fR, \fBmenubar\fR, or \fBtearoff\fR. Should not normally be
called outside of the Tk library. See the \fBCLONES\fR section for
more information.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBmenu\fR
command.
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fIindex1\fR ?\fIindex2\fR?
.
Delete all of the menu entries between \fIindex1\fR and
\fIindex2\fR inclusive.
If \fIindex2\fR is omitted then it defaults to \fIindex1\fR.
Attempts to delete a tear-off menu entry are ignored (instead, you
should change the \fB\-tearoff\fR option to remove the tear-off entry).
.\" METHOD: entrycget
.TP
\fIpathName \fBentrycget \fIindex option\fR
.
Returns the current value of a configuration option for
the entry given by \fIindex\fR.
\fIOption\fR may have any of the names described in the
\fBMENU ENTRY OPTIONS\fR section below.
.\" METHOD: entryconfigure
.TP
\fIpathName \fBentryconfigure \fIindex \fR?\fIoptions...\fR?
.
This command is similar to the \fBconfigure\fR command, except that
it applies to the options for an individual entry, whereas \fBconfigure\fR
applies to the options for the menu as a whole.
\fIOptions\fR may have any of the values described in the
\fBMENU ENTRY OPTIONS\fR
section below.  If \fIoptions\fR are specified, options are
modified as indicated in the command and the command returns an empty string.
If no \fIoptions\fR are specified, returns a list describing
the current options for entry \fIindex\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).
.\" METHOD: id
.TP
\fIpathName \fBid \fIindex\fR
.
Returns the id of the menu entry given by \fIindex\fR.
This is the identifier that was assigned to the entry when it was created
using the \fBadd\fR or \fBinsert\fR widget command.
Returns an empty string for the tear-off entry, or if \fIindex\fR is
equivalent to \fB{}\fR.
.\" METHOD: index
.TP
\fIpathName \fBindex \fIindex\fR
.
Returns the numerical index corresponding to \fIindex\fR, or
\fB{}\fR if \fIindex\fR was specified as \fB{}\fR.
\fBnone\fR if \fIindex\fR was specified as \fBnone\fR.
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex type \fR?\fIid\fR? ?\fIoption value option value ...\fR?
\fIpathName \fBinsert \fIindex type \fR?\fIoption value option value ...\fR?
.
Same as the \fBadd\fR widget command except that it inserts the new
entry just before the entry given by \fIindex\fR, instead of appending
to the end of the menu.  The \fItype\fR, \fIid\fR, \fIoption\fR, and
\fIvalue\fR arguments have the same interpretation as for the \fBadd\fR
widget command.  It is not possible to insert new menu entries before the
to the end of the menu.  The \fItype\fR, \fIoption\fR, and \fIvalue\fR
arguments have the same interpretation as for the \fBadd\fR widget
command.  It is not possible to insert new menu entries before the
tear-off entry, if the menu has one.
The \fBinsert\fR widget command returns the id of the new entry.
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke \fIindex\fR
.
Invoke the action of the menu entry.  See the sections on the
individual entries above for details on what happens.  If the
menu entry is disabled then nothing happens.  If the
entry has a command associated with it then the result of that
command is returned as the result of the \fBinvoke\fR widget
command.  Otherwise the result is an empty string.  Note:  invoking
a menu entry does not automatically unpost the menu;  the default
bindings normally take care of this before invoking the \fBinvoke\fR
widget command.
.\" METHOD: post
.TP
\fIpathName \fBpost \fIx y\fR ?\fIindex\fR?
\fIpathName \fBpost \fIx y\fR
.
Arrange for the menu to be displayed on the screen at the root-window
coordinates given by \fIx\fR and \fIy\fR.  If an index is specified
coordinates given by \fIx\fR and \fIy\fR.  These coordinates are
the menu will be located so that the entry with that index is
displayed at the point.  These coordinates are adjusted if necessary to
guarantee that the entire menu is visible on the screen.  This command
normally returns an empty string.  If the \fB\-postcommand\fR option
has been specified, then its value is executed as a Tcl script before
posting the menu and the result of that script is returned as the
result of the \fBpost\fR widget command.  If an error returns while
executing the command, then the error is returned without posting the
menu.
adjusted if necessary to guarantee that the entire menu is visible on
the screen.  This command normally returns an empty string.
If the \fB\-postcommand\fR option has been specified, then its value is
executed as a Tcl script before posting the menu and the result of
that script is returned as the result of the \fBpost\fR widget
command.
If an error returns while executing the command, then the error is
returned without posting the menu.
.\" METHOD: postcascade
.TP
\fIpathName \fBpostcascade \fIindex\fR
.
Posts the submenu associated with the cascade entry given by
\fIindex\fR, and unposts any previously posted submenu.
If \fIindex\fR does not correspond to a cascade entry,
or if \fIpathName\fR is not posted,
the command has no effect except to unpost any currently posted
submenu.
.\" METHOD: type
.TP
\fIpathName \fBtype \fIindex\fR
.
Returns the type of the menu entry given by \fIindex\fR.
This is the \fItype\fR argument passed to the \fBadd\fR or \fBinsert\fR widget
command when the entry was created, such as \fBcommand\fR
or \fBseparator\fR, or \fBtearoff\fR for a tear-off entry.
.\" METHOD: unpost
.TP
\fIpathName \fBunpost\fR
.
Unmap the window so that it is no longer displayed.  If a
lower-level cascaded menu is posted, unpost that menu.  Returns an
empty string. This subcommand does not work on Windows and the
Macintosh, as those platforms have their own way of unposting menus.
.\" METHOD: xposition
.TP
\fIpathName \fBxposition \fIindex\fR
.
Returns a decimal string giving the x-coordinate within the menu
window of the leftmost pixel in the entry specified by \fIindex\fR.
.\" METHOD: yposition
.TP
\fIpathName \fByposition \fIindex\fR
.
Returns a decimal string giving the y-coordinate within the menu
window of the topmost pixel in the entry specified by \fIindex\fR.
.SH "MENU ENTRY OPTIONS"
The following options are allowed on menu entries. Most options are not
supported by all entry types.
.\" OPTION: -activebackground
.TP
\fB\-activebackground \fIvalue\fR
.
Specifies a background color to use for displaying this entry when it
is active. This option is ignored on Aqua/MacOS.
If it is specified as an empty string (the default), then the
is active.
If this option is specified as an empty string (the default), then the
\fB\-activebackground\fR option for the overall menu is used.
If the \fBtk_strictMotif\fR variable has been set to request strict
Motif compliance, then this option is ignored and the \fB\-background\fR
option is used in its place.
This option is not available for separator or tear-off entries.
.\" OPTION: -activeforeground
.TP
\fB\-activeforeground \fIvalue\fR
.
Specifies a foreground color to use for displaying this entry when it
is active.   This option is ignored on Aqua/macOS.
is active.
If this option is specified as an empty string (the default), then the
\fB\-activeforeground\fR option for the overall menu is used.
.\" OPTION: -accelerator
This option is not available for separator or tear-off entries.
.TP
\fB\-accelerator \fIvalue\fR
.
Specifies a string to display at the right side of the menu entry.
Normally describes an accelerator keystroke sequence that may be
used to invoke the same function as the menu entry. This is a display
option, it does not actually set the corresponding binding (which can
be achieved using the \fBbind\fR command). This option is not available
for separator or tear-off entries.
.\" OPTION: -background
.TP
\fB\-background \fIvalue\fR
.
Specifies a background color to use for displaying this entry when it
is in the normal state (neither active nor disabled).
This option is ignored on Aqua/macOS.
If it is specified as an empty string (the default), then the
If this option is specified as an empty string (the default), then the
\fB\-background\fR option for the overall menu is used.
This option is not available for separator or tear-off entries.
.\" OPTION: -bitmap
.TP
\fB\-bitmap \fIvalue\fR
.
Specifies a bitmap to display in the menu instead of a textual
label, in any of the forms accepted by \fBTk_GetBitmap\fR.
This option overrides the \fB\-label\fR option
(as controlled by the \fB\-compound\fR option)
but may be reset
to an empty string to enable a textual label to be displayed.
If a \fB\-image\fR option has been specified, it overrides
\fB\-bitmap\fR.
This option is not available for separator or tear-off entries.
.\" OPTION: -columnbreak
.TP
\fB\-columnbreak \fIvalue\fR
.
When this option is zero, the entry appears below the previous entry. When
this option is one, the entry appears at the top of a new column in the
menu.
This option is ignored on Aqua/macOS, where menus are always a single
This option is ignored on Aqua/Mac OS X, where menus are always a single
column.
.\" OPTION: -command
.TP
\fB\-command \fIvalue\fR
.
Specifies a Tcl command to execute when the menu entry is invoked.
Not available for separator or tear-off entries.
.\" OPTION: -compound
.TP
\fB\-compound \fIvalue\fR
.
Specifies whether the menu entry should display both an image and text,
and if so, where the image should be placed relative to the text.
Valid values for this option are \fBbottom\fR, \fBcenter\fR,
\fBleft\fR, \fBnone\fR, \fBright\fR and \fBtop\fR.  The default value
is \fBnone\fR, meaning that the button will display either an image or
text, depending on the values of the \fB\-image\fR and \fB\-bitmap\fR
options.
.\" OPTION: -font
.TP
\fB\-font \fIvalue\fR
.
Specifies the font to use when drawing the label or accelerator
string in this entry.
If this option is specified as an empty string (the default) then
the \fB\-font\fR option for the overall menu is used.
This option is not available for separator or tear-off entries.
.\" OPTION: -foreground
.TP
\fB\-foreground \fIvalue\fR
.
Specifies a foreground color to use for displaying this entry when it
is in the normal state (neither active nor disabled).
This option is ignored on Aqua/macOS.
If it is specified as an empty string (the default), then the
If this option is specified as an empty string (the default), then the
\fB\-foreground\fR option for the overall menu is used.
This option is not available for separator or tear-off entries.
.\" OPTION: -hidemargin
.TP
\fB\-hidemargin \fIvalue\fR
.
Specifies whether the standard margins should be drawn for this menu
entry. This is useful when creating palette with images in them, i.e.,
color palettes, pattern palettes, etc. 1 indicates that the margin for
the entry is hidden; 0 means that the margin is used.
.\" OPTION: -image
.TP
\fB\-image \fIvalue\fR
.
Specifies an image to display in the menu instead of a text string
or bitmap.
The image must have been created by some previous invocation of
\fBimage create\fR.
This option overrides the \fB\-label\fR and \fB\-bitmap\fR options
(as controlled by the \fB\-compound\fR option)
but may be reset to an empty string to enable a textual or
bitmap label to be displayed.
This option is not available for separator or tear-off entries.
.\" OPTION: -indicatoron
.TP
\fB\-indicatoron \fIvalue\fR
.
Available only for checkbutton and radiobutton entries.
\fIValue\fR is a boolean that determines whether or not the
indicator should be displayed.
.\" OPTION: -label
.TP
\fB\-label \fIvalue\fR
.
Specifies a string to display as an identifying label in the menu
entry.  Not available for separator or tear-off entries.
.\" OPTION: -menu
.TP
\fB\-menu \fIvalue\fR
.
Available only for cascade entries.  Specifies the path name of
the submenu associated with this entry.
The submenu must be a child of the menu.
.\" OPTION: -offvalue
.TP
\fB\-offvalue \fIvalue\fR
.
Available only for checkbutton entries.  Specifies the value to
store in the entry's associated variable when the entry is
deselected.
.\" OPTION: -onvalue
.TP
\fB\-onvalue \fIvalue\fR
.
Available only for checkbutton entries.  Specifies the value to
store in the entry's associated variable when the entry is selected.
.\" OPTION: -selectcolor
.TP
\fB\-selectcolor \fIvalue\fR
.
Available only for checkbutton and radiobutton entries.
Specifies the color to display in the indicator when the entry is
selected.
If the value is an empty string (the default) then the \fB\-selectcolor\fR
option for the menu determines the indicator color.
.\" OPTION: -selectimage
.TP
\fB\-selectimage \fIvalue\fR
.
Available only for checkbutton and radiobutton entries.
Specifies an image to display in the entry (in place of
the \fB\-image\fR option) when it is selected.
\fIValue\fR is the name of an image, which must have been created
by some previous invocation of \fBimage create\fR.
This option is ignored unless the \fB\-image\fR option has
been specified.
.\" OPTION: -state
.TP
\fB\-state \fIvalue\fR
.
Specifies one of three states for the entry:  \fBnormal\fR, \fBactive\fR,
or \fBdisabled\fR.  In normal state the entry is displayed using the
\fB\-foreground\fR option for the menu and the \fB\-background\fR
option from the entry or the menu.
The active state is typically used when the pointer is over the entry.
In active state the entry is displayed using the \fB\-activeforeground\fR
option for the menu along with the \fB\-activebackground\fR option from
the entry.  Disabled state means that the entry
should be insensitive:  the default bindings will refuse to activate
or invoke the entry.
In this state the entry is displayed according to the
\fB\-disabledforeground\fR option for the menu and the
\fB\-background\fR option from the entry.
This option is not available for separator entries.
.\" OPTION: -underline
.TP
\fB\-underline \fIvalue\fR
.
Specifies the integer index of a character to underline in the entry.
This option is also queried by the default bindings and used to
implement keyboard traversal.
0 corresponds to the first character of the text displayed in the entry,
1 to the next character, and so on.
If a bitmap or image is displayed in the entry then this option is ignored.
This option is not available for separator or tear-off entries.
.\" OPTION: -value
.TP
\fB\-value \fIvalue\fR
.
Available only for radiobutton entries.  Specifies the value to
store in the entry's associated variable when the entry is selected.
If an empty string is specified, then the \fB\-label\fR option
for the entry as the value to store in the variable.
.\" OPTION: -variable
.TP
\fB\-variable \fIvalue\fR
.
Available only for checkbutton and radiobutton entries.  Specifies
the name of a global variable to set when the entry is selected.
For checkbutton entries the variable is also set when the entry
is deselected.  For radiobutton entries, changing the variable

Added doc/menubar.n.







































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
'\"
'\" Copyright (c) 1992 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH tk_menuBar n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk_menuBar, tk_bindForTraversal \- Obsolete support for menu bars
.SH SYNOPSIS
\fBtk_menuBar \fIframe \fR?\fImenu menu ...\fR?
.sp
\fBtk_bindForTraversal \fIarg arg ... \fR
.BE
.SH DESCRIPTION
.PP
These procedures were used in Tk 3.6 and earlier releases to help
manage pulldown menus and to implement keyboard traversal of menus.
In Tk 4.0 and later releases they are no
longer needed.  Stubs for these procedures have been retained for
backward compatibility, but they have no effect.  You should remove
calls to these procedures from your code, since eventually the
procedures will go away.
.PP
From Tk 8.0 onwards, you should instead construct your menubar as a
normal \fBmenu\fR and then attach it to the \fBtoplevel\fR of your
choice using the \fB\-menu\fR option of that widget.
.SH "SEE ALSO"
menu(n), toplevel(n)
.SH KEYWORDS
keyboard traversal, menu, menu bar, post
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/menubutton.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
+











-
+







.TH menubutton n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
menubutton \- Create and manipulate 'menubutton' pop-up menu indicator widgets
.SH SYNOPSIS
\fBmenubutton\fI pathName \fR?\fIoptions\fR?
\fBmenubutton\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-disabledforeground	\-padx
\-activeforeground	\-font	\-pady
\-anchor	\-foreground	\-relief
\-background	\-highlightbackground	\-takefocus
\-bitmap	\-highlightcolor	\-text
\-borderwidth	\-highlightthickness	\-textvariable
\-cursor	\-image	\-underline
\-compound	\-justify	\-wraplength
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-direction direction Direction
.OP \-direction direction Height
Specifies where the menu is going to be popup up. \fBabove\fR tries to
pop the menu above the menubutton. \fBbelow\fR tries to pop the menu
below the menubutton. \fBleft\fR tries to pop the menu to the left of
the menubutton. \fBright\fR tries to pop the menu to the right of the
menu button. \fBflush\fR pops the menu directly over the menubutton.
In the case of \fBabove\fR or \fBbelow\fR, the direction will be
reversed if the menu would show offscreen.
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
113
114
115
116
117
118
119

120
121
122
123
124

125
126
127
128
129
130
131

132
133
134
135
136
137
138







-
+




-







-







.SH "WIDGET COMMAND"
.PP
The \fBmenubutton\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for menubutton widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBmenubutton\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified

Changes to doc/message.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH message n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
message \- Create and manipulate 'message' non-interactive text widgets
.SH SYNOPSIS
\fBmessage\fI pathName \fR?\fIoptions\fR?
\fBmessage\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-anchor	\-background	\-borderwidth
\-cursor	\-font	\-foreground
\-highlightbackground	\-highlightcolor	\-highlightthickness
\-padx	\-pady	\-relief
\-takefocus	\-text	\-textvariable
.SE
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
102
103
104
105
106
107
108

109
110
111
112
113

114
115
116
117
118
119
120

121
122
123
124
125
126
127







-
+




-







-







.SH "WIDGET COMMAND"
.PP
The \fBmessage\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for message widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBmessage\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified

Changes to doc/messageBox.n.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63

64
65
66
67
68
69

70
71
72
73
74
75

76
77
78



79
80
81

82
83
84
85

86


87
88

89


90

91


92

93


94

95


96

97


98
99
100
101
102
103
104
105
106
107
108




109
110
111


112
113
114
115
116
117
118
19
20
21
22
23
24
25

26









27
28
29
30
31
32
33
34
35

36

37
38
39
40
41
42

43

44
45
46
47
48
49

50

51
52
53
54

55

56
57
58
59

60

61
62


63
64
65

66

67
68
69
70
71
72

73
74
75
76
77

78
79
80
81

82
83
84
85

86
87
88
89

90
91
92
93

94
95
96
97
98
99
100
101
102




103
104
105
106
107


108
109
110
111
112
113
114
115
116







-

-
-
-
-
-
-
-
-
-
+








-

-
+





-

-
+





-

-
+



-

-
+



-

-
+

-
-
+
+
+
-

-
+




+
-
+
+


+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+







-
-
-
-
+
+
+
+

-
-
+
+







application-specified message, an icon and a set of buttons.  Each of
the buttons in the message window is identified by a unique symbolic
name (see the \fB\-type\fR options).  After the message window is
popped up, \fBtk_messageBox\fR waits for the user to select one of the
buttons. Then it returns the symbolic name of the selected button.
.PP
The following option-value pairs are supported:
.\" OPTION: -command
.TP
\fB\-command\fI string\fR
.
Specifies the prefix of a Tcl command to invoke when the user closes the
dialog. The actual command consists of \fIstring\fR followed by a space
and the name of the button clicked by the user to close the dialog. This
is only available on Mac OS X.
.\" OPTION: -default
.TP
\fB\-default\fI name\fR
\fB\-default\fR \fIname\fR
.
\fIName\fR gives the symbolic name of the default button for
this message window (
.QW ok ,
.QW cancel ,
and so on). See \fB\-type\fR
for a list of the symbolic names.  If this option is not specified,
the first button in the dialog will be made the default.
.\" OPTION: -detail
.TP
\fB\-detail\fI string\fR
\fB\-detail\fR \fIstring\fR
.
Specifies an auxiliary message to the main message given by the
\fB\-message\fR option. The message detail will be presented beneath the main
message and, where supported by the OS, in a less emphasized font than the
main message.
.\" OPTION: -icon
.TP
\fB\-icon\fI iconImage\fR
\fB\-icon\fR \fIiconImage\fR
.
Specifies an icon to display. \fIIconImage\fR must be one of the
following: \fBerror\fR, \fBinfo\fR, \fBquestion\fR or
\fBwarning\fR. If this option is not specified, then the info icon will be
displayed.
.\" OPTION: -message
.TP
\fB\-message\fI string\fR
\fB\-message\fR \fIstring\fR
.
Specifies the message to display in this message box. The
default value is an empty string.
.\" OPTION: -parent
.TP
\fB\-parent\fI window\fR
\fB\-parent\fR \fIwindow\fR
.
Makes \fIwindow\fR the logical parent of the message box. The message
box is displayed on top of its parent window.
.\" OPTION: -title
.TP
\fB\-title\fI titleString\fR
\fB\-title\fR \fItitleString\fR
.
Specifies a string to display as the title of the message box. The
default value is an empty string.
Specifies a string to display as the title of the message box. This option
is ignored on Mac OS X, where platform guidelines forbid the use of a title
on this kind of dialog.
.\" OPTION: -type
.TP
\fB\-type\fI predefinedType\fR
\fB\-type\fR \fIpredefinedType\fR
.
Arranges for a predefined set of buttons to be displayed. The
following values are possible for \fIpredefinedType\fR:
.RS
.TP 18
.IP \fBabortretryignore\fR 18
\fBabortretryignore\fR
.
Displays three buttons whose symbolic names are \fBabort\fR,
\fBretry\fR and \fBignore\fR.
.TP 18
.IP \fBok\fR 18
\fBok\fR
.
Displays one button whose symbolic name is \fBok\fR.
.TP 18
.IP \fBokcancel\fR 18
\fBokcancel\fR
.
Displays two buttons whose symbolic names are \fBok\fR and \fBcancel\fR.
.TP 18
.IP \fBretrycancel\fR 18
\fBretrycancel\fR
.
Displays two buttons whose symbolic names are \fBretry\fR and \fBcancel\fR.
.TP 18
.IP \fByesno\fR 18
\fByesno\fR
.
Displays two buttons whose symbolic names are \fByes\fR and \fBno\fR.
.TP 18
.IP \fByesnocancel\fR 18
\fByesnocancel\fR
.
Displays three buttons whose symbolic names are \fByes\fR, \fBno\fR
and \fBcancel\fR.
.RE
.PP
.SH EXAMPLE
.PP
.CS
set answer [\fBtk_messageBox\fR -message "Really quit?" \e
        -icon question -type yesno \e
        -detail "Select \e"Yes\e" to make the application exit"]
switch -- $answer {
set answer [\fBtk_messageBox\fR \-message "Really quit?" \e
        \-icon question \-type yesno \e
        \-detail "Select \e"Yes\e" to make the application exit"]
switch \-\- $answer {
    yes exit
    no {\fBtk_messageBox\fR -message "I know you like this application!" \e
            -type ok}
    no {\fBtk_messageBox\fR \-message "I know you like this application!" \e
            \-type ok}
}
.CE
.SH KEYWORDS
message box
'\" Local Variables:
'\" mode: nroff
'\" End:

Deleted doc/nsimage.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133





































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
'\"
'\" Copyright (c) 2022 Marc Culler
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH nsimage n 8.7 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
nsimage \- A Tk image type for macOS based on the NSImage class.
.BE
.SH DESCRIPTION
The nsimage is implemented as a Tk image type.  The \fBimage\fR
command is used to create, delete, and query all images, including
images of type \fBnsimage\fR.  The options that are available are
specific to the nsimage type and are described below.
.PP
The command to create an \fBnsimage\fR:
.TP
\fBimage create nsimage \fR?\fIname\fR? ?\fIoption value ...\fR?
.PP
creates a new nsimage and a command with the same name and returns its
name.
.SH OPTIONS
.PP
Valid \fIoptions\fR are:
.\" OPTION: -source
.TP
\fB\-source\fI string\fR
.PP
The value of the \fB\-source\fR option is a string describing an
NSimage.  There are several ways to interpret this string, and the
interpretation is determined by the value of the \fB\-as\fR option.
This option is required.
.PP
.\" OPTION: -as
.TP
\fB\-as\fI type\fR
.PP
There are four possible values for the \fB\-as\fR option which specify
how the source string should be interpreted.  The allowed values and
their meanings are:
.RS
.IP \fBname\fR
The source should be interpreted as the name of a named NSImage
provided by the system.
This is the default if the \fB\-as\fR option is not specified.
.IP \fBfile\fR
The source should be interpreted as a path to an image
file in one of the formats understood by the NSImage class.
.IP \fBpath\fR
The source should be interpreted as a path to an arbitrary
file. The type of the file will be examined and the resulting image
will be the system icon for files of that type.
.IP \fBfiletype\fR
The source is interpreted as a string identifying a
particular file type.  It may be a filename extension, an Apple Uniform Type
Identifier or a 4-character OSType value as used in the HFS filesystem.
.RE
.\" OPTION: -width
.TP
\fB\-width\fI pixels\fR
.PP
The value of the \fIwidth\fR option is an integer specifying the width
in pixels of the nsimage.  If the width is not specified it will be
computed from the height so as to preserve the aspect ration.  If
neither width nor height are specified then the width and height of
the underlying NSImage will be used.
.\" OPTION: -height
.TP
\fB\-height\fI pixels\fR
.PP
The value of the \fIheight\fR option is an integer specifying the
height in pixels of the nsimage. If the height is not specified it
will be computed from the height so as to preserve the aspect ration.
If neither width nor height are specified then the width and height of
the underlying NSImage will be used.
.\" OPTION: -radius
.TP
\fB\-radius\fI pixels\fR
.PP
The value of the \fIradius\fR option is an integer.  If non-zero the
image will be clipped to a rounded rectangle with the same width and
height as the image, but with circular arcs of the specified radius
cutting off the corners of the rectangle.
.\" OPTION: -ring
.TP
\fB\-ring\fI pixels\fR
.PP
The value of the \fIring\fR option is an integer.  If non-zero then it
specifies the thickness of a focus ring which will be drawn around the
image using the control accent color specified in the System
Preferences.  The image is resized to reduce its width and height by
twice the thickness of the ring.  Note that this may create a small
amount of distortion.  The aspect ration of a non-square image will
change slightly.
.\" OPTION: -alpha
.TP
\fB\-alpha\fI float\fR
.PP
The value of the \fIalpha\fR option should be a floating point number
between 0.0 and 1.0.  This alpha value will be applied to each pixel
of the nsimage, producing a partially transparent image.  The default value
is 1.0, which makes the image opaque.
.\" OPTION: -pressed
.TP
\fB\-pressed\fI boolean\fR
.PP
The \fIpressed\fR option takes a boolean value.  If the value is true
or 1 then the image will be algorithmically modified to become darker
in light mode or lighter in dark mode.  The default is false.  For an
image button, the primary image should use the value false while the
pressed image should be the same image but with the \fIpressed\fR
option set to true.
.\" OPTION: -template
.TP
\fB\-template\fI boolean\fR
.PP
The \fItemplate\fR option takes a boolean value.  If the value is true
or 1 then the image will be marked as being a template image.  This
means that the system will algorithmically convert the image to a
light colored image when in dark mode.  For the algorithm to work
correctly the image must consist only of black pixels with alpha
values.
.SH "SEE ALSO"
image(n), options(n), photo(n)
.SH KEYWORDS
height, image, types of images, width
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/option.n.

18
19
20
21
22
23
24
25

26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

74

75

76

77
78

79

80
81
82

83

84
85
86
87
88
89
90
18
19
20
21
22
23
24

25


26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73

74
75
76
77

78
79
80
81
82

83
84
85
86
87
88
89
90







-
+
-
-
+











-







-










-















+
-
+

+
-
+


+
-
+



+
-
+







\fBoption get \fIwindow name class\fR
\fBoption readfile \fIfileName \fR?\fIpriority\fR?
.fi
.BE
.SH DESCRIPTION
.PP
The \fBoption\fR command allows you to add entries to the Tk option
database or to retrieve options from the database.
database or to retrieve options from the database.  The \fBadd\fR
.\" METHOD: add
The \fBadd\fR form of the command adds a new option to the database.
form of the command adds a new option to the database.
\fIPattern\fR contains
the option being specified, and consists of names and/or classes
separated by asterisks or dots, in the usual X format (see
\fBPATTERN FORMAT\fR).  \fIValue\fR
contains a text string to associate with \fIpattern\fR;  this is the
value that will be returned in calls to \fBTk_GetOption\fR or by
invocations of the \fBoption get\fR command.  If \fIpriority\fR
is specified, it indicates the priority level for this option (see
below for legal values);  it defaults to \fBinteractive\fR.
This command always returns an empty string.
.PP
.\" METHOD: clear
The \fBoption clear\fR command clears the option database.  Default
options (from the
\fBRESOURCE_MANAGER\fR property or the \fB.Xdefaults\fR
file) will be reloaded automatically the next time an
option is added to the database or removed from it.  This command
always returns an empty string.
.PP
.\" METHOD: get
The \fBoption get\fR command returns the value of the option
specified for \fIwindow\fR
under \fIname\fR and \fIclass\fR.  If several entries in the option
database match \fIwindow\fR, \fIname\fR, and \fIclass\fR, then
the command returns whichever was created with highest
\fIpriority\fR level.  If there are several matching
entries at the same priority level, then it returns whichever entry
was most recently entered into the option database.  If there are
no matching entries, then the empty string is returned.
.PP
.\" METHOD: readfile
The \fBreadfile\fR form of the command reads \fIfileName\fR,
which should have the standard format for an
X resource database such as \fB.Xdefaults\fR, and adds all the
options specified in that file to the option database.  If \fIpriority\fR
is specified, it indicates the priority level at which to enter the
options;  \fIpriority\fR defaults to \fBinteractive\fR.
.PP
The file is read through a channel which is in "utf-8" encoding,
invalid byte sequences are automatically converted to valid ones.
This means that encodings like ISO 8859-1 or cp1252 with high
probability will work as well, but this cannot be guaranteed.
This cannot be changed, setting the [encoding system] has no effect.
.PP
The \fIpriority\fR arguments to the \fBoption\fR command are
normally specified symbolically using one of the following values:
.TP
.IP \fBwidgetDefault\fR3
\fBwidgetDefault\fR
Level 20.  Used for default values hard-coded into widgets.
.TP
.IP \fBstartupFile\fR
\fBstartupFile\fR
Level 40.  Used for options specified in application-specific
startup files.
.TP
.IP \fBuserDefault\fR
\fBuserDefault\fR
Level 60.  Used for options specified in user-specific defaults
files, such as \fB.Xdefaults\fR, resource databases loaded into
the X server, or user-specific startup files.
.TP
.IP \fBinteractive\fR
\fBinteractive\fR
Level 80.  Used for options specified interactively after the application
starts running.  If \fIpriority\fR is not specified, it defaults to
this level.
.PP
Any of the above keywords may be abbreviated.  In addition, priorities
may be specified numerically using integers between 0 and 100,
inclusive.  The numeric form is probably a bad idea except for new priority

Changes to doc/options.n.

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
54
55
56
57
58
59
60



61
62
63
64
65
66
67







-
-
-







definition of active elements.
The value may have any of the forms acceptable to \fBTk_GetPixels\fR.
This option is typically only available in widgets displaying more
than one element at a time (e.g. menus but not buttons).
.OP \-activeforeground activeForeground Background
Specifies foreground color to use when drawing active elements.
See above for definition of active elements.
.OP \-activerelief activeRelief Relief
Specifies the 3-D effect desired for the active item of the widget.
See the \fB\-relief\fR option for details.
.OP \-anchor anchor Anchor
Specifies how the information in a widget (e.g. text or a bitmap)
is to be displayed in the widget.
Must be one of the values \fBn\fR, \fBne\fR, \fBe\fR, \fBse\fR,
\fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, or \fBcenter\fR.
For example, \fBnw\fR means display the information such that its
top-left corner is at the top-left corner of the widget.
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
217
218
219
220
221
222
223







224
225
226
227
228
229
230







-
-
-
-
-
-
-







this amount to the height it would normally need (as determined by
the height of the things displayed in the widget);  if the geometry
manager can satisfy this request, the widget will end up with extra
internal space above and/or below what it displays inside.
Most widgets only use this option for padding text:  if they are
displaying a bitmap or image, then they usually ignore padding
options.
.OP \-placeholder placeHolder PlaceHolder
Specifies a help text string to display if no text is otherwise displayed,
that is when the widget is empty. The placeholder text is displayed using
the values of the \fB\-font\fR and \fB\-justify\fR options.
.OP \-placeholderforeground placeholderForeground PlaceholderForeground
Specifies the foreground color to use when the placeholder text is
displayed. The default color is platform-specific.
.OP \-relief relief Relief
Specifies the 3-D effect desired for the widget.  Acceptable
values are \fBraised\fR, \fBsunken\fR, \fBflat\fR, \fBridge\fR,
\fBsolid\fR, and \fBgroove\fR.
The value
indicates how the interior of the widget should appear relative
to its exterior;  for example, \fBraised\fR means the interior of
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292







-
+







If the value has any other form, then the traversal scripts take
the value, append the name of the window to it (with a separator space),
and evaluate the resulting string as a Tcl script.
The script must return \fB0\fR, \fB1\fR, or an empty string:  a
\fB0\fR or \fB1\fR value specifies whether the window will receive
the input focus, and an empty string results in the default decision
described above.
Note that this interpretation of the option is defined entirely by
Note: this interpretation of the option is defined entirely by
the Tcl scripts that implement traversal:  the widget implementations
ignore the option entirely, so you can change its meaning if you
redefine the keyboard traversal scripts.
.OP \-text text Text
Specifies a string to be displayed inside the widget.  The way in which
the string is displayed depends on the particular widget and may be
determined by other options, such as \fB\-anchor\fR or \fB\-justify\fR.
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
302
303
304
305
306
307
308

309

310
311
312
313
314
315
316







-
+
-







in widgets such as scrollbars and scales.  This option is ignored for
scrollbars on Windows (native widget does not recognize this option).
.OP \-underline underline Underline
Specifies the integer index of a character to underline in the widget.
This option is used by the default bindings to implement keyboard
traversal for menu buttons and menu entries.
0 corresponds to the first character of the text displayed in the
widget, 1 to the next character, and so on. \fBend\fR corresponds to the
widget, 1 to the next character, and so on.
last character, \fBend\fR-1 to the before last character, and so on.
.OP \-wraplength wrapLength WrapLength
For widgets that can perform word-wrapping, this option specifies
the maximum line length.
Lines that would exceed this length are wrapped onto the next line,
so that no line is longer than the specified length.
The value may be specified in any of the standard forms for
screen distances.

Added doc/pack-old.n.




































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
'\"
'\" Copyright (c) 1990-1994 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH pack-old n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
pack-old \- Obsolete syntax for packer geometry manager
.SH SYNOPSIS
\fBpack after \fIsibling \fIwindow options\fR ?\fIwindow options \fR...?
.sp
\fBpack append \fIparent \fIwindow options\fR ?\fIwindow options \fR...?
.sp
\fBpack before \fIsibling \fIwindow options\fR ?\fIwindow options \fR...?
.sp
\fBpack unpack \fIwindow\fR
.BE
.SH DESCRIPTION
.PP
\fINote: this manual entry describes the syntax for the \fBpack\fI
command as it existed before Tk version 3.3.
Although this syntax continues to be supported for backward
compatibility, it is obsolete and should not be used anymore.
At some point in the future it may cease to be supported.\fR
.PP
The packer is a geometry manager that arranges the
children of a parent by packing them in order around the edges of
the parent.  The first child is placed against one side of
the window, occupying the entire span of the window along that
side.  This reduces the space remaining for other children as
if the side had been moved in by the size of the first child.
Then the next child is placed against one side of the remaining
cavity, and so on until all children have been placed or there
is no space left in the cavity.
.PP
The \fBbefore\fR, \fBafter\fR, and \fBappend\fR forms of the \fBpack\fR
command are used to insert one or more children into the packing order
for their parent.  The \fBbefore\fR form inserts the children before
window \fIsibling\fR in the order;  all of the other windows must be
siblings of \fIsibling\fR.  The \fBafter\fR form inserts the windows
after \fIsibling\fR, and the \fBappend\fR form appends one or more
windows to the end of the packing order for \fIparent\fR.  If a
\fIwindow\fR named in any of these commands is already packed in
its parent, it is removed from its current position in the packing
order and repositioned as indicated by the command.  All of these
commands return an empty string as result.
.PP
The \fBunpack\fR form of the \fBpack\fR command removes \fIwindow\fR
from the packing order of its parent and unmaps it.  After the
execution of this command the packer will no longer manage
\fIwindow\fR's geometry.
.PP
The placement of each child is actually a four-step process;
the \fIoptions\fR argument following each \fIwindow\fR consists of
a list of one or more fields that govern the placement of that
window.  In the discussion below, the term \fIcavity\fR refers
to the space left in a parent when a particular child is placed
(i.e. all the space that was not claimed by earlier children in
the packing order).  The term \fIparcel\fR refers to the space
allocated to a particular child;  this is not necessarily the
same as the child window's final geometry.
.PP
The first step in placing a child is to determine which side of
the cavity it will lie against.  Any one of the following options
may be used to specify a side:
.TP
\fBtop\fR
Position the child's parcel against the top of the cavity,
occupying the full width of the cavity.
.TP
\fBbottom\fR
Position the child's parcel against the bottom of the cavity,
occupying the full width of the cavity.
.TP
\fBleft\fR
Position the child's parcel against the left side of the cavity,
occupying the full height of the cavity.
.TP
\fBright\fR
Position the child's parcel against the right side of the cavity,
occupying the full height of the cavity.
.LP
At most one of these options should be specified for any given window.
If no side is specified, then the default is \fBtop\fR.
.PP
The second step is to decide on a parcel for the child.  For \fBtop\fR
and \fBbottom\fR windows, the desired parcel width is normally the cavity
width and the desired parcel height is the window's requested height,
as passed to \fBTk_GeometryRequest\fR. For \fBleft\fR and \fBright\fR
windows, the desired parcel height is normally the cavity height and the
desired width is the window's requested width.  However, extra
space may be requested for the window using any of the following
options:
.TP 12
\fBpadx \fInum\fR
Add \fInum\fR pixels to the window's requested width before computing
the parcel size as described above.
.TP 12
\fBpady \fInum\fR
Add \fInum\fR pixels to the window's requested height before computing
the parcel size as described above.
.TP 12
\fBexpand\fR
This option requests that the window's parcel absorb any extra space left over
in the parent's cavity after packing all the children.
The amount of space left over depends on the sizes requested by the
other children, and may be zero.  If several windows have all specified
\fBexpand\fR then the extra width will be divided equally among all the
\fBleft\fR and \fBright\fR windows that specified \fBexpand\fR and
the extra height will be divided equally among all the \fBtop\fR and
\fBbottom\fR windows that specified \fBexpand\fR.
.LP
If the desired width or height for a parcel is larger than the corresponding
dimension of the cavity, then the cavity's dimension is used instead.
.PP
The third step in placing the window is to decide on the window's
width and height.  The default is for the window to receive either
its requested width and height or the those of the parcel, whichever
is smaller.  If the parcel is larger than the window's requested
size, then the following options may be used to expand the
window to partially or completely fill the parcel:
.TP
\fBfill\fR
Set the window's size to equal the parcel size.
.TP
\fBfillx\fR
Increase the window's width to equal the parcel's width, but retain
the window's requested height.
.TP
\fBfilly\fR
Increase the window's height to equal the parcel's height, but retain
the window's requested width.
.PP
The last step is to decide the window's location within its parcel.
If the window's size equals the parcel's size, then the window simply
fills the entire parcel.  If the parcel is larger than the window,
then one of
the following options may be used to specify where the window should
be positioned within its parcel:
.TP 15
\fBframe center\fR
Center the window in its parcel.  This is the default if no framing
option is specified.
.TP 15
\fBframe n\fR
Position the window with its top edge centered on the top edge of
the parcel.
.TP 15
\fBframe ne\fR
Position the window with its upper-right corner at the upper-right corner
of the parcel.
.TP 15
\fBframe e\fR
Position the window with its right edge centered on the right edge of
the parcel.
.TP 15
\fBframe se\fR
Position the window with its lower-right corner at the lower-right corner
of the parcel.
.TP 15
\fBframe s\fR
Position the window with its bottom edge centered on the bottom edge of
the parcel.
.TP 15
\fBframe sw\fR
Position the window with its lower-left corner at the lower-left corner
of the parcel.
.TP 15
\fBframe w\fR
Position the window with its left edge centered on the left edge of
the parcel.
.TP 15
\fBframe nw\fR
Position the window with its upper-left corner at the upper-left corner
of the parcel.
.PP
The packer manages the mapped/unmapped state of all the packed
children windows.  It automatically maps the windows when it packs
them, and it unmaps any windows for which there was no space left
in the cavity.
.PP
The packer makes geometry requests on behalf of the parent windows
it manages.  For each parent window it requests a size large enough
to accommodate all the options specified by all the packed children,
such that zero space would be leftover for \fBexpand\fR options.
.SH KEYWORDS
geometry manager, location, packer, parcel, size
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/pack.n.

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33

34
35

36
37

38
39
40
41
42
43
44
45
46
47
48


49
50
51
52
53
54

55
56
57
58
59
60
61
62
63


64
65
66
67
68
69


70
71
72
73
74
75
76
77
78


79
80

81
82


83

84
85


86

87
88


89

90
91


92
93
94
95

96
97
98


99
100
101
102
103
104

105
106
107
108
109
110
111
112

113
114
115
116
117
118
119

120
121
122
123
124
125
126
127

128
129
130
131
132
133
134

135
136
137
138
139

140
141
142

143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162



163
164
165
166
167
168
169
170
171
172
173

174
175
176

177
178
179
180


181
182
183

184
185
186

187
188
189

190
191
192
193

194
195
196
197

198
199




200
201
202
203


204
205

206
207

208
209
210

211
212
213
214
215




216
217

218
219
220


221
222
223

224
225
226

227
228
229
230
231


232
233

234
235
236

237
238
239

240
241
242
243
244



245
246
247

248
249

250
251
252
253



254
255

256
257

258
259

260
261
262
263
264



265
266
267

268
269

270
271
272
273
274



275
276
277
278
279

280
281
282

283
284

285
286
287


288
289
290


291
292
293
294
295
296
297
298






299
300
301

302
303
304
305
306
307
308
309




310
311
312
313
314
315
316
317





318
319
320
321
322
323
324
18
19
20
21
22
23
24

25

26
27
28
29

30

31


32
33

34
35
36
37
38

39
40

41


42
43

44
45

46

47
48
49

50
51

52


53
54

55
56



57
58
59
60
61

62
63



64
65
66
67
68


69
70
71
72


73
74
75
76


77
78
79
80


81
82
83

84

85



86
87

88
89

90

91
92
93

94
95

96

97
98

99
100

101

102
103
104

105
106

107

108
109
110

111
112


113
114
115
116
117

118
119
120

121
122

123
124
125
126

127









128




129
130
131









132

133

134

135
136
137


138
139

140

141

142

143
144
145

146
147
148
149

150
151

152

153


154
155
156
157
158
159


160
161
162

163
164

165
166
167

168
169




170
171
172
173
174

175
176


177
178
179
180

181
182
183

184
185
186
187


188
189
190

191
192
193

194
195
196

197
198
199



200
201
202
203
204

205
206

207
208



209
210
211
212

213
214

215
216

217
218
219



220
221
222
223
224

225
226

227
228
229



230
231
232
233
234
235
236

237
238
239

240
241

242
243


244
245
246


247
248
249
250






251
252
253
254
255
256
257
258

259
260
261
262
263




264
265
266
267
268
269
270





271
272
273
274
275
276
277
278
279
280
281
282







-
+
-




-

-
+
-
-
+

-
+




-


-

-
-
+
+
-


-

-
+


-


-

-
-
+
+
-


-
-
-
+
+



-


-
-
-
+
+


+
-
-
+
+

+
-
-
+
+

+
-
-
+
+

+
-
-
+
+

-

-
+
-
-
-
+
+
-


-

-
+


-


-

-
+

-


-

-
+


-


-

-
+


-


-
-
+




-
+


-
+

-
+



-

-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-

-
+
-

-
+


-
-
+
+
-

-
+
-

-
+


-
+



-
+

-

-
+
-
-
+
+
+
+


-
-
+
+

-
+

-
+


-
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+


-
+


-
+



-
-
+
+

-
+


-
+


-
+


-
-
-
+
+
+


-
+

-
+

-
-
-
+
+
+

-
+

-
+

-
+


-
-
-
+
+
+


-
+

-
+


-
-
-
+
+
+




-
+


-
+

-
+

-
-
+
+

-
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+


-
+




-
-
-
-
+
+
+
+



-
-
-
-
-
+
+
+
+
+







.PP
The \fBpack\fR command is used to communicate with the packer,
a geometry manager that arranges the children of a parent by
packing them in order around the edges of the parent.
The \fBpack\fR command can have any of several forms, depending
on the \fIoption\fR argument:
.TP
\fBpack \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
\fBpack \fIslave \fR?\fIslave ...\fR? ?\fIoptions\fR?
.
If the first argument to \fBpack\fR is a window name (any value
starting with
.QW . ),
then the command is processed in the same way as \fBpack configure\fR.
.\" METHOD: configure
.TP
\fBpack configure \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
\fBpack configure \fIslave \fR?\fIslave ...\fR? ?\fIoptions\fR?
.
The arguments consist of the names of one or more content windows
The arguments consist of the names of one or more slave windows
followed by pairs of arguments that specify how
to manage the content.
to manage the slaves.
See \fBTHE PACKER ALGORITHM\fR below for details on how the options
are used by the packer.
The following options are supported:
.RS
.\" OPTION: -after
.TP
\fB\-after \fIother\fR
.
\fIOther\fR must the name of another window.
Use its container as the container for the content, and insert
the content just after \fIother\fR in the packing order.
Use its master as the master for the slaves, and insert
the slaves just after \fIother\fR in the packing order.
.\" OPTION: -anchor
.TP
\fB\-anchor \fIanchor\fR
.
\fIAnchor\fR must be a valid anchor position such as \fBn\fR
or \fBsw\fR; it specifies where to position each content in its
or \fBsw\fR; it specifies where to position each slave in its
parcel.
Defaults to \fBcenter\fR.
.\" OPTION: -before
.TP
\fB\-before \fIother\fR
.
\fIOther\fR must the name of another window.
Use its container as the container for the content, and insert
the content just before \fIother\fR in the packing order.
Use its master as the master for the slaves, and insert
the slaves just before \fIother\fR in the packing order.
.\" OPTION: -expand
.TP
\fB\-expand \fIboolean\fR
.
Specifies whether the content should be expanded to consume
extra space in their container.
Specifies whether the slaves should be expanded to consume
extra space in their master.
\fIBoolean\fR may have any proper boolean value, such as \fB1\fR
or \fBno\fR.
Defaults to 0.
.\" OPTION: -fill
.TP
\fB\-fill \fIstyle\fR
.
If a content's parcel is larger than its requested dimensions, this
option may be used to stretch the content.
If a slave's parcel is larger than its requested dimensions, this
option may be used to stretch the slave.
\fIStyle\fR must have one of the following values:
.RS
.TP
.IP \fBnone\fR
Give the content its requested dimensions plus any internal padding
\fBnone\fR
Give the slave its requested dimensions plus any internal padding
requested with \fB\-ipadx\fR or \fB\-ipady\fR.  This is the default.
.TP
.IP \fBx\fR
Stretch the content horizontally to fill the entire width of its
\fBx\fR
Stretch the slave horizontally to fill the entire width of its
parcel (except leave external padding as specified by \fB\-padx\fR).
.TP
.IP \fBy\fR
Stretch the content vertically to fill the entire height of its
\fBy\fR
Stretch the slave vertically to fill the entire height of its
parcel (except leave external padding as specified by \fB\-pady\fR).
.TP
.IP \fBboth\fR
Stretch the content both horizontally and vertically.
\fBboth\fR
Stretch the slave both horizontally and vertically.
.RE
.\" OPTION: -in
.TP
\fB\-in \fIcontainer\fR
\fB\-in \fIother\fR
.
Insert the window at the end of the packing order for the container
window given by \fIcontainer\fR.
Insert the slave(s) at the end of the packing order for the master
window given by \fIother\fR.
.\" OPTION: -ipadx
.TP
\fB\-ipadx \fIamount\fR
.
\fIAmount\fR specifies how much horizontal internal padding to
leave on each side of the content.
leave on each side of the slave(s).
\fIAmount\fR must be a valid screen distance, such as \fB2\fR or \fB.5c\fR.
It defaults to 0.
.\" OPTION: -ipady
.TP
\fB\-ipady \fIamount\fR
.
\fIAmount\fR specifies how much vertical internal padding to
leave on each side of the content.
leave on each side of the slave(s).
\fIAmount\fR  defaults to 0.
.\" OPTION: -padx
.TP
\fB\-padx \fIamount\fR
.
\fIAmount\fR specifies how much horizontal external padding to
leave on each side of the content.  \fIAmount\fR may be a list
leave on each side of the slave(s).  \fIAmount\fR may be a list
of two values to specify padding for left and right separately.
\fIAmount\fR defaults to 0.
.\" OPTION: -pady
.TP
\fB\-pady \fIamount\fR
.
\fIAmount\fR specifies how much vertical external padding to
leave on each side of the content.  \fIAmount\fR may be a list
leave on each side of the slave(s).  \fIAmount\fR may be a list
of two values to specify padding for top and bottom separately.
\fIAmount\fR defaults to 0.
.\" OPTION: -side
.TP
\fB\-side \fIside\fR
.
Specifies which side of the container the content will be packed against.
Specifies which side of the master the slave(s) will be packed against.
Must be \fBleft\fR, \fBright\fR, \fBtop\fR, or \fBbottom\fR.
Defaults to \fBtop\fR.
.LP
If no \fB\-in\fR, \fB\-after\fR or \fB\-before\fR option is specified
then each of the content will be inserted at the end of the packing list
then each of the slaves will be inserted at the end of the packing list
for its parent unless it is already managed by the packer (in which
case it will be left where it is).
If one of these options is specified then all the content will be
If one of these options is specified then all the slaves will be
inserted at the specified point.
If any of the content are already managed by the geometry manager
If any of the slaves are already managed by the geometry manager
then any unspecified options for them retain their previous values rather
than receiving default values.
.RE
.\" METHOD: content
.TP
\fBpack content \fIwindow\fR
.
Returns a list of all of the content windows in the packing order for
\fIwindow\fR. The order of the content windows in the list is the same as
their order in the packing order.
If \fIwindow\fR has no content then an empty string is returned.
.\" METHOD: forget
.TP
\fBpack forget \fIwindow \fR?\fIwindow ...\fR?
\fBpack forget \fIslave \fR?\fIslave ...\fR?
.
Removes each of the \fIwindow\fRs from the packing order for its
container and unmaps their windows.
The content will no longer be managed by the packer.
Removes each of the \fIslave\fRs from the packing order for its
master and unmaps their windows.
The slaves will no longer be managed by the packer.
.RS
.PP
.VS "TIP 518"
If the last content window of the container becomes unmanaged, this will
also send the virtual event \fB<<NoManagedChild>>\fR to the container; the
container may choose to resize itself (or otherwise respond) to such a change.
.VE "TIP 518"
.RE
.\" METHOD: info
.TP
\fBpack info \fIwindow\fR
\fBpack info \fIslave\fR
.
Returns a list whose elements are the current configuration state of
the window given by \fIwindow\fR in the same option-value form that
the slave given by \fIslave\fR in the same option-value form that
might be specified to \fBpack configure\fR.
The first two elements of the list are
.QW "\fB\-in \fIcontainer\fR"
where \fIcontainer\fR is the window's container.
.QW "\fB\-in \fImaster\fR"
where \fImaster\fR is the slave's master.
.\" METHOD: propagate
.TP
\fBpack propagate \fIcontainer\fR ?\fIboolean\fR?
\fBpack propagate \fImaster\fR ?\fIboolean\fR?
.
If \fIboolean\fR has a true boolean value such as \fB1\fR or \fBon\fR
then propagation is enabled for \fIcontainer\fR, which must be a window
then propagation is enabled for \fImaster\fR, which must be a window
name (see \fBGEOMETRY PROPAGATION\fR below).
If \fIboolean\fR has a false boolean value then propagation is
disabled for \fIcontainer\fR.
disabled for \fImaster\fR.
In either of these cases an empty string is returned.
If \fIboolean\fR is omitted then the command returns \fB0\fR or
\fB1\fR to indicate whether propagation is currently enabled
for \fIcontainer\fR.
for \fImaster\fR.
Propagation is enabled by default.
.\" METHOD: slaves
.TP
\fBpack slaves \fIwindow\fR
\fBpack slaves \fImaster\fR
.
Synonym for \fBpack content \fIwindow\fR.
Returns a list of all of the slaves in the packing order for \fImaster\fR.
The order of the slaves in the list is the same as their order in
the packing order.
If \fImaster\fR has no slaves then an empty string is returned.
.SH "THE PACKER ALGORITHM"
.PP
For each container the packer maintains an ordered list of content
windows called the \fIpacking list\fR.
For each master the packer maintains an ordered list of slaves
called the \fIpacking list\fR.
The \fB\-in\fR, \fB\-after\fR, and \fB\-before\fR configuration
options are used to specify the container for each content and the content's
options are used to specify the master for each slave and the slave's
position in the packing list.
If none of these options is given for a content then the content
If none of these options is given for a slave then the slave
is added to the end of the packing list for its parent.
.PP
The packer arranges the content windows for a container by scanning the
The packer arranges the slaves for a master by scanning the
packing list in order.
At the time it processes each content, a rectangular area within
the container is still unallocated.
This area is called the \fIcavity\fR;  for the first content it
is the entire area of the container.
At the time it processes each slave, a rectangular area within
the master is still unallocated.
This area is called the \fIcavity\fR;  for the first slave it
is the entire area of the master.
.PP
For each content the packer carries out the following steps:
For each slave the packer carries out the following steps:
.IP [1]
The packer allocates a rectangular \fIparcel\fR for the content
along the side of the cavity given by the content's \fB\-side\fR option.
The packer allocates a rectangular \fIparcel\fR for the slave
along the side of the cavity given by the slave's \fB\-side\fR option.
If the side is top or bottom then the width of the parcel is
the width of the cavity and its height is the requested height
of the content plus the \fB\-ipady\fR and \fB\-pady\fR options.
of the slave plus the \fB\-ipady\fR and \fB\-pady\fR options.
For the left or right side the height of the parcel is
the height of the cavity and the width is the requested width
of the content plus the \fB\-ipadx\fR and \fB\-padx\fR options.
of the slave plus the \fB\-ipadx\fR and \fB\-padx\fR options.
The parcel may be enlarged further because of the \fB\-expand\fR
option (see \fBEXPANSION\fR below)
.IP [2]
The packer chooses the dimensions of the content.
The width will normally be the content's requested width plus
The packer chooses the dimensions of the slave.
The width will normally be the slave's requested width plus
twice its \fB\-ipadx\fR option and the height will normally be
the content's requested height plus twice its \fB\-ipady\fR
the slave's requested height plus twice its \fB\-ipady\fR
option.
However, if the \fB\-fill\fR option is \fBx\fR or \fBboth\fR
then the width of the content is expanded to fill the width of the parcel,
then the width of the slave is expanded to fill the width of the parcel,
minus twice the \fB\-padx\fR option.
If the \fB\-fill\fR option is \fBy\fR or \fBboth\fR
then the height of the content is expanded to fill the width of the parcel,
then the height of the slave is expanded to fill the width of the parcel,
minus twice the \fB\-pady\fR option.
.IP [3]
The packer positions the content over its parcel.
If the content is smaller than the parcel then the \fB\-anchor\fR
option determines where in the parcel the content will be placed.
The packer positions the slave over its parcel.
If the slave is smaller than the parcel then the \fB\-anchor\fR
option determines where in the parcel the slave will be placed.
If \fB\-padx\fR or \fB\-pady\fR is non-zero, then the given
amount of external padding will always be left between the
content and the edges of the parcel.
slave and the edges of the parcel.
.PP
Once a given content has been packed, the area of its parcel
Once a given slave has been packed, the area of its parcel
is subtracted from the cavity, leaving a smaller rectangular
cavity for the next content.
If a content does not use all of its parcel, the unused space
in the parcel will not be used by subsequent content.
cavity for the next slave.
If a slave does not use all of its parcel, the unused space
in the parcel will not be used by subsequent slaves.
If the cavity should become too small to meet the needs of
a content then the content will be given whatever space is
a slave then the slave will be given whatever space is
left in the cavity.
If the cavity shrinks to zero size, then all remaining content
If the cavity shrinks to zero size, then all remaining slaves
on the packing list will be unmapped from the screen until
the container window becomes large enough to hold them again.
the master window becomes large enough to hold them again.
.SS "EXPANSION"
.PP
If a container window is so large that there will be extra space
left over after all of its content have been packed, then the
extra space is distributed uniformly among all of the content
If a master window is so large that there will be extra space
left over after all of its slaves have been packed, then the
extra space is distributed uniformly among all of the slaves
for which the \fB\-expand\fR option is set.
Extra horizontal space is distributed among the expandable
content whose \fB\-side\fR is \fBleft\fR or \fBright\fR,
slaves whose \fB\-side\fR is \fBleft\fR or \fBright\fR,
and extra vertical space is distributed among the expandable
content whose \fB\-side\fR is \fBtop\fR or \fBbottom\fR.
slaves whose \fB\-side\fR is \fBtop\fR or \fBbottom\fR.
.SS "GEOMETRY PROPAGATION"
.PP
The packer normally computes how large a container must be to
just exactly meet the needs of its content, and it sets the
requested width and height of the container to these dimensions.
The packer normally computes how large a master must be to
just exactly meet the needs of its slaves, and it sets the
requested width and height of the master to these dimensions.
This causes geometry information to propagate up through a
window hierarchy to a top-level window so that the entire
sub-tree sizes itself to fit the needs of the leaf windows.
However, the \fBpack propagate\fR command may be used to
turn off propagation for one or more containers.
turn off propagation for one or more masters.
If propagation is disabled then the packer will not set
the requested width and height of the packer.
This may be useful if, for example, you wish for a container
This may be useful if, for example, you wish for a master
window to have a fixed size that you specify.
.SH "RESTRICTIONS ON CONTAINER WINDOWS"
.SH "RESTRICTIONS ON MASTER WINDOWS"
.PP
The container for each content must either be the content's parent
(the default) or a descendant of the content's parent.
The master for each slave must either be the slave's parent
(the default) or a descendant of the slave's parent.
This restriction is necessary to guarantee that the
content can be placed over any part of its container that is
visible without danger of the content being clipped by its parent.
slave can be placed over any part of its master that is
visible without danger of the slave being clipped by its parent.
.SH "PACKING ORDER"
.PP
If the container for a content is not its parent then you must make sure
that the content is higher in the stacking order than the container.
Otherwise the container will obscure the content and it will appear as
if the content has not been packed correctly.
The easiest way to make sure the content is higher than the container is
to create the container window first:  the most recently created window
If the master for a slave is not its parent then you must make sure
that the slave is higher in the stacking order than the master.
Otherwise the master will obscure the slave and it will appear as
if the slave has not been packed correctly.
The easiest way to make sure the slave is higher than the master is
to create the master window first:  the most recently created window
will be highest in the stacking order.
Or, you can use the \fBraise\fR and \fBlower\fR commands to change
the stacking order of either the container or the content.
the stacking order of either the master or the slave.
.SH EXAMPLE
.PP
.CS
# Make the widgets
label .t -text "This widget is at the top"    -bg red
label .b -text "This widget is at the bottom" -bg green
label .l -text "Left\enHand\enSide"
label .r -text "Right\enHand\enSide"
label .t \-text "This widget is at the top"    \-bg red
label .b \-text "This widget is at the bottom" \-bg green
label .l \-text "Left\enHand\enSide"
label .r \-text "Right\enHand\enSide"
text .mid
\&.mid insert end "This layout is like Java's BorderLayout"
# Lay them out
\fBpack\fR .t   -side top    -fill x
\fBpack\fR .b   -side bottom -fill x
\fBpack\fR .l   -side left   -fill y
\fBpack\fR .r   -side right  -fill y
\fBpack\fR .mid -expand 1    -fill both
\fBpack\fR .t   \-side top    \-fill x
\fBpack\fR .b   \-side bottom \-fill x
\fBpack\fR .l   \-side left   \-fill y
\fBpack\fR .r   \-side right  \-fill y
\fBpack\fR .mid \-expand 1    \-fill both
.CE
.SH "SEE ALSO"
grid(n), place(n)
.SH KEYWORDS
geometry manager, location, packer, parcel, propagation, size
'\" Local Variables:
'\" mode: nroff

Changes to doc/palette.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16

17
18
19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18

19
20
21
22
23
24
25













-

+

+

-







'\"
'\" 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.
'\"
.TH tk_setPalette n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk_setPalette, tk_bisque \- Modify the Tk color palette
.SH SYNOPSIS
.nf
\fBtk_setPalette \fIbackground\fR
.sp
\fBtk_setPalette \fIname value \fR?\fIname value ...\fR?
.sp
\fBtk_bisque\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBtk_setPalette\fR procedure changes the color scheme for Tk.
It does this by modifying the colors of existing widgets and by changing
the option database so that future widgets will use the new color scheme.
If \fBtk_setPalette\fR is invoked with a single argument, the

Changes to doc/panedwindow.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51

52



53
54
55
56
57
58
59
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31











32
33

34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51







-
+
















-
-
-
-
-
-
-
-
-
-
-


-
+





-
+

+
+
+







.TH panedwindow n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
panedwindow \- Create and manipulate 'panedwindow' split container widgets
.SH SYNOPSIS
\fBpanedwindow\fI pathName \fR?\fIoptions\fR?
\fBpanedwindow\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-background	\-borderwidth	\-cursor
\-orient	\-relief
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-handlepad handlePad HandlePad
When sash handles are drawn, specifies the distance from the top or
left end of the sash (depending on the orientation of the widget) at
which to draw the handle.  May be any value accepted by \fBTk_GetPixels\fR.
.OP \-handlesize handleSize HandleSize
Specifies the side length of a sash handle.  Handles are always
drawn as squares.  May be any value accepted by \fBTk_GetPixels\fR.
.OP \-height height Height
Specifies a desired height for the overall panedwindow widget. May be any
value accepted by \fBTk_GetPixels\fR. If an empty string, the widget will be
made high enough to allow all contained widgets to have their natural height.
.OP \-opaqueresize opaqueResize OpaqueResize
Specifies whether panes should be resized as a sash is moved (true),
or if resizing should be deferred until the sash is placed (false).
In the latter case, a
.QW ghost
version of the sash is displayed during the resizing to show where the
panes will be resized to when releasing the mouse button. This
.QW ghost
version of the sash is the proxy. It's rendering can be configured
using the \fB\-proxybackground\fR, \fB\-proxyborderwidth\fR and
\fB\-proxyrelief\fR options.
.OP \-proxybackground proxyBackground ProxyBackground
Background color to use when drawing the proxy. If an empty string, the
value of the \fB\-background\fR option will be used.
value of the \fB-background\fR option will be used.
.OP \-proxyborderwidth proxyBorderWidth ProxyBorderWidth
Specifies the borderwidth of the proxy. May be any value accepted by
\fBTk_GetPixels\fR.
.OP \-proxyrelief proxyRelief ProxyRelief
Relief to use when drawing the proxy. May be any of the standard Tk
relief values. If an empty string, the value of the \fB\-sashrelief\fR
relief values. If an empty string, the value of the \fB-sashrelief\fR
option will be used.
.OP \-opaqueresize opaqueResize OpaqueResize
Specifies whether panes should be resized as a sash is moved (true),
or if resizing should be deferred until the sash is placed (false).
.OP \-sashcursor sashCursor SashCursor
Mouse cursor to use when over a sash.  If null,
\fBsb_h_double_arrow\fR will be used for horizontal panedwindows, and
\fBsb_v_double_arrow\fR will be used for vertical panedwindows.
.OP \-sashpad sashPad SashPad
Specifies the amount of padding to leave of each side of a sash.  May
be any value accepted by \fBTk_GetPixels\fR.
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
80
81
82
83
84
85
86

87
88
89
90
91
92

93
94
95
96
97
98
99
100

101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125

126
127
128
129
130
131
132
133
134




































































































































135
136
137
138
139
140
141







-
+





-








-






-














-





-









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







.SH "WIDGET COMMAND"
.PP
The \fBpanedwindow\fR command creates a new Tcl command whose name is
the same as the path name of the panedwindow's window.  This command
may be used to invoke various operations on the widget.  It has the
following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIPathName\fR is the name of the command, which is the same as
the panedwindow widget's path name.  \fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for panedwindow widgets:
.\" METHOD: add
.TP
\fIpathName \fBadd \fIwindow \fR?\fIwindow ...\fR? ?\fIoption value ...\fR?
.
Add one or more windows to the panedwindow, each in a separate pane.
The arguments consist of the names of one or more windows
followed by pairs of arguments that specify how to manage the windows.
\fIOption\fR may have any of the values accepted by the
\fBconfigure\fR subcommand.
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given by
\fIoption\fR.  \fIOption\fR may have any of the values accepted by the
\fBpanedwindow\fR command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.  If no
\fIoption\fR is specified, returns a list describing all of the
available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string. \fIOption\fR may have
any of the values accepted by the \fBpanedwindow\fR command.
.\" METHOD: forget
.TP
\fIpathName \fBforget \fIwindow \fR?\fIwindow ...\fR?
.
Remove the pane containing \fIwindow\fR from the panedwindow.  All
geometry management options for \fIwindow\fR will be forgotten.
.\" METHOD: identify
.TP
\fIpathName \fBidentify \fIx y\fR
.
Identify the panedwindow component underneath the point given by
\fIx\fR and \fIy\fR, in window coordinates.  If the point is over a
sash or a sash handle, the result is a two element list containing the
index of the sash or handle, and a word indicating whether it is over
a sash or a handle, such as {0 sash} or {2 handle}.  If the point is
over any other part of the panedwindow, the result is an empty list.
.\" METHOD: panecget
.TP
\fIpathName \fBpanecget \fIwindow option\fR
.
Query a management option for \fIwindow\fR.  \fIOption\fR may be any
value allowed by the \fBpaneconfigure\fR subcommand.
.\" METHOD: paneconfigure
.TP
\fIpathName \fBpaneconfigure \fIwindow \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the management options for \fIwindow\fR.  If no
\fIoption\fR is specified, returns a list describing all of the
available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.  The following options
are supported:
.RS
.\" OPTION: -after
.TP
\fB\-after \fIwindow\fR
.
Insert the window after the window specified.  \fIwindow\fR should be the
name of a window already managed by \fIpathName\fR.
.\" OPTION: -before
.TP
\fB\-before \fIwindow\fR
.
Insert the window before the window specified.  \fIwindow\fR should be
the name of a window already managed by \fIpathName\fR.
.\" OPTION: -height
.TP
\fB\-height \fIsize\fR
.
Specify a height for the window.  The height will be the outer
dimension of the window including its border, if any.  If \fIsize\fR
is an empty string, or if \fB\-height\fR is not specified, then the
height requested internally by the window will be used initially; the
height may later be adjusted by the movement of sashes in the
panedwindow.  \fISize\fR may be any value accepted by \fBTk_GetPixels\fR.
.\" OPTION: -hide
.TP
\fB\-hide \fIboolean\fR
.
Controls the visibility of a pane.  When the \fIboolean\fR is true
(according to \fBTcl_GetBoolean\fR) the pane will not be visible, but
it will still be maintained in the list of panes.
.\" OPTION: -minsize
.TP
\fB\-minsize \fIn\fR
.
Specifies that the size of the window cannot be made less than
\fIn\fR.  This constraint only affects the size of the widget in the
paned dimension \(em the x dimension for horizontal panedwindows, the y
dimension for vertical panedwindows.  May be any value accepted by
\fBTk_GetPixels\fR.
.\" OPTION: -padx
.TP
\fB\-padx \fIn\fR
.
Specifies a non-negative value indicating how much extra space to
leave on each side of the window in the X-direction.  The value may
have any of the forms accepted by \fBTk_GetPixels\fR.
.\" OPTION: -pady
.TP
\fB\-pady \fIn\fR
.
Specifies a non-negative value indicating how much extra space to
leave on each side of the window in the Y-direction.  The value may
have any of the forms accepted by \fBTk_GetPixels\fR.
.\" OPTION: -sticky
.TP
\fB\-sticky \fIstyle\fR
.
If a window's pane is larger than the requested dimensions of the
window, this option may be used to position (or stretch) the window
within its pane.  \fIStyle\fR  is a string that contains zero or more
of the characters \fBn\fR, \fBs\fR, \fBe\fR or \fBw\fR.  The string
can optionally contains spaces or commas, but they are ignored.  Each
letter refers to a side (north, south, east, or west) that the window
will
.QW stick
to.  If both \fBn\fR and \fBs\fR (or \fBe\fR and \fBw\fR)
are specified, the window will be stretched to fill the entire height
(or width) of its cavity.
.\" OPTION: -stretch
.TP
\fB\-stretch \fIwhen\fR
.
Controls how extra space is allocated to each of the panes.
\fIWhen\fR is one of \fBalways\fR, \fBfirst\fR, \fBlast\fR,
\fBmiddle\fR, and \fBnever\fR.
The panedwindow will calculate the required size of all its panes. Any
remaining (or deficit) space will be distributed to those panes marked
for stretching. The space will be distributed based on each panes
current ratio of the whole.  The \fIwhen\fR values have the following
definition:
.RS
.IP \fBalways\fR
This pane will always stretch.
.IP \fBfirst\fR
Only if this pane is the first pane (left-most or top-most) will it
stretch.
.IP \fBlast\fR
Only if this pane is the last pane (right-most or bottom-most) will it
stretch.  This is the default value.
.IP \fBmiddle\fR
Only if this pane is not the first or last pane will it stretch.
.IP \fBnever\fR
This pane will never stretch.
.RE
.\" OPTION: -width
.TP
\fB\-width \fIsize\fR
.
Specify a width for the window.  The width will be the outer
dimension of the window including its border, if any.  If \fIsize\fR
is an empty string, or if \fB\-width\fR is not specified, then the
width requested internally by the window will be used initially; the
width may later be adjusted by the movement of sashes in the
panedwindow.  \fISize\fR may be any value accepted by \fBTk_GetPixels\fR.
.RE
.\" METHOD: panes
.TP
\fIpathName \fBpanes\fR
.
Returns an ordered list of the widgets managed by \fIpathName\fR.
.\" METHOD: proxy
.TP
\fIpathName \fBproxy \fR?\fIargs\fR?
.
This command is used to query and change the position of the sash
proxy, used for rubberband-style pane resizing. It can take any of
the following forms:
.RS
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
149
150
151
152
153
154
155

156
157

158
159
160
161
162
163
164







-


-







.
Remove the proxy from the display.
.TP
\fIpathName \fBproxy place \fIx y\fR
.
Place the proxy at the given \fIx\fR and \fIy\fR coordinates.
.RE
.\" METHOD: sash
.TP
\fIpathName \fBsash \fR?\fIargs\fR?
.
This command is used to query and change the position of sashes in the
panedwindow.  It can take any of the following forms:
.RS
.TP
\fIpathName \fBsash coord \fIindex\fR
.
Return the current x and y coordinate pair for the sash given by
325
326
327
328
329
330
331
































































































































332
333
334
335
336
337
338
339
340
341
342
343
344
345


346
347
348
349
350
351
352
353
354
355
356
357
358
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












-
-
+
+













Records \fIx\fR and \fIy\fR for the sash given by \fIindex\fR; used in
conjunction with later \fBsash dragto\fR commands to move the sash.
.TP
\fIpathName \fBsash place \fIindex x y\fR
.
Place the sash given by \fIindex\fR at the given coordinates.
.RE
.TP
\fIpathName \fBpanecget \fIwindow option\fR
.
Query a management option for \fIwindow\fR.  \fIOption\fR may be any
value allowed by the \fBpaneconfigure\fR subcommand.
.TP
\fIpathName \fBpaneconfigure \fIwindow \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the management options for \fIwindow\fR.  If no
\fIoption\fR is specified, returns a list describing all of the
available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.  The following options
are supported:
.RS
.TP
\fB\-after \fIwindow\fR
.
Insert the window after the window specified.  \fIwindow\fR should be the
name of a window already managed by \fIpathName\fR.
.TP
\fB\-before \fIwindow\fR
.
Insert the window before the window specified.  \fIwindow\fR should be
the name of a window already managed by \fIpathName\fR.
.TP
\fB\-height \fIsize\fR
.
Specify a height for the window.  The height will be the outer
dimension of the window including its border, if any.  If \fIsize\fR
is an empty string, or if \fB\-height\fR is not specified, then the
height requested internally by the window will be used initially; the
height may later be adjusted by the movement of sashes in the
panedwindow.  \fISize\fR may be any value accepted by \fBTk_GetPixels\fR.
.TP
\fB\-hide \fIboolean\fR
.
Controls the visibility of a pane.  When the \fIboolean\fR is true
(according to \fBTcl_GetBoolean\fR) the pane will not be visible, but
it will still be maintained in the list of panes.
.TP
\fB\-minsize \fIn\fR
.
Specifies that the size of the window cannot be made less than
\fIn\fR.  This constraint only affects the size of the widget in the
paned dimension \(em the x dimension for horizontal panedwindows, the y
dimension for vertical panedwindows.  May be any value accepted by
\fBTk_GetPixels\fR.
.TP
\fB\-padx \fIn\fR
.
Specifies a non-negative value indicating how much extra space to
leave on each side of the window in the X-direction.  The value may
have any of the forms accepted by \fBTk_GetPixels\fR.
.TP
\fB\-pady \fIn\fR
.
Specifies a non-negative value indicating how much extra space to
leave on each side of the window in the Y-direction.  The value may
have any of the forms accepted by \fBTk_GetPixels\fR.
.TP
\fB\-sticky \fIstyle\fR
.
If a window's pane is larger than the requested dimensions of the
window, this option may be used to position (or stretch) the window
within its pane.  \fIStyle\fR  is a string that contains zero or more
of the characters \fBn\fR, \fBs\fR, \fBe\fR or \fBw\fR.  The string
can optionally contains spaces or commas, but they are ignored.  Each
letter refers to a side (north, south, east, or west) that the window
will
.QW stick
to.  If both \fBn\fR and \fBs\fR (or \fBe\fR and \fBw\fR)
are specified, the window will be stretched to fill the entire height
(or width) of its cavity.
.TP
\fB\-stretch \fIwhen\fR
.
Controls how extra space is allocated to each of the panes.
\fIWhen\fR is one of \fBalways\fR, \fBfirst\fR, \fBlast\fR,
\fBmiddle\fR, and \fBnever\fR.
The panedwindow will calculate the required size of all its panes. Any
remaining (or deficit) space will be distributed to those panes marked
for stretching. The space will be distributed based on each panes
current ratio of the whole.  The \fIwhen\fR values have the following
definition:
.RS
.TP
\fBalways\fR
.
This pane will always stretch.
.TP
\fBfirst\fR
.
Only if this pane is the first pane (left-most or top-most) will it
stretch.
.TP
\fBlast\fR
.
Only if this pane is the last pane (right-most or bottom-most) will it
stretch.  This is the default value.
.TP
\fBmiddle\fR
.
Only if this pane is not the first or last pane will it stretch.
.TP
\fBnever\fR
.
This pane will never stretch.
.RE
.TP
\fB\-width \fIsize\fR
.
Specify a width for the window.  The width will be the outer
dimension of the window including its border, if any.  If \fIsize\fR
is an empty string, or if \fB\-width\fR is not specified, then the
width requested internally by the window will be used initially; the
width may later be adjusted by the movement of sashes in the
panedwindow.  \fISize\fR may be any value accepted by \fBTk_GetPixels\fR.
.RE
.TP
\fIpathName \fBpanes\fR
.
Returns an ordered list of the widgets managed by \fIpathName\fR.
.SH "RESIZING PANES"
.PP
A pane is resized by grabbing the sash (or sash handle if present) and
dragging with the mouse.  This is accomplished via mouse motion
bindings on the widget.  When a sash is moved, the sizes of the panes
on each side of the sash, and thus the widgets in those panes, are
adjusted.
.PP
When a pane is resized from outside (e.g. it is packed to expand and
fill, and the containing toplevel is resized), space is added to the final
(rightmost or bottommost) pane in the window.
.PP
Unlike child windows managed by e.g. pack or grid, the panes managed by a
panedwindow do not change width or height to accommodate changes in the
Unlike slave windows managed by e.g. pack or grid, the panes managed by a
panedwindow do not change width or height to accomodate changes in the
requested widths or heights of the panes, once these have become mapped.
Therefore it may be advisable, particularly when creating layouts
interactively, to not add a pane to the panedwindow widget until after the
geometry requests of that pane has been finalized (i.e., all components of
the pane inserted, all options affecting geometry set to their proper
values, etc.).
.SH "SEE ALSO"
ttk::panedwindow(n)
.SH KEYWORDS
panedwindow, widget, geometry management
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/photo.n.

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53

54
55
56
57
58
59
60
61
62
63
64
65

66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343

344
345
346
347

348
349
350
351

352
353
354
355

356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480

481
482
483
484

485
486

487

488
489

490
491


492
493

494

495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567


568
569
570

571
572
573
574
575
576
577
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45





46
47
48

49
50
51
52
53
54
55
56

57
58
59

60
61
62

63
64
65
66
67
68
69
70

71
72
73
74
75

76
77
78

79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103












104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148

149


150

151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171





172

173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237
238

239
240
241

242
243
244
245

246
247
248
249
250

251
252
253
254
255
256

257
258
259
260
261
262
263

264
265
266
267
268
269
270
271

272
273
274

275
276
277
278
279
280
281
282
283
284

285
286
287
288
289





290







291


292

293
294
295
296

297
298
299
300

301
302

303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321

322
323
324











325
326
327
328
329
330
331
332

333
334
335
336
337
338

339

340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356

357
358
359

360
361
362
363
364
365
366
367
368
369











370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385

386
387
388
389
390
391
392
393
394
395

396

397
398
399
400
401
402
403

404

405
406

407
408
409
410
411
412

413

414
415
416
417

418
419
420
421
422

423
424
425
426
427
428

429
430
431
432
433
434

435
436
437
438
439
440
441
442
443
444
445

446
447
448

449
450
451
452
453
454
455
456
457

458
459
460
461
462











463
464
465
466
467
468
469


470
471
472
473

474
475
476
477
478
479
480
481







-
+














-
-
-
-
-
+


-
+







-



-
+


-
+







-





-
+


-






-












-







-
-
-
-
-
-
-
-
-
-
-
-












-















-
+












-





-
+
-
-

-
+





-















-
-
-
-
-

-
+








-










-










-








-









-








-












-



-
+



-
+




-






-







-
+







-
+


-










-





-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-

-
+



-
+



-
+

-
+










-








-
+


-
-
-
-
-
-
-
-
-
-
-








-
+





-

-
+








-








-
+


-










-
-
-
-
-
-
-
-
-
-
-









-







-










-

-
+




+

-
+
-
+

-
+


+
+

-
+
-
+



-
+




-






-






-











-
+


-









-





-
-
-
-
-
-
-
-
-
-
-







-
-
+
+


-
+







\fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
\fIimageName \fBcopy \fIsourceImage\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBdata\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBget \fIx y\fR ?\fIoption\fR?
\fIimageName \fBput \fIdata\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBread \fIfilename\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBredither\fR
\fIimageName \fBtransparency \fIsubcommand \fR?\fIarg ...\fR?
\fIimageName \fBtransparency \fIsubcommand \fR?\fIarg arg ...\fR?
\fIimageName \fBwrite \fIfilename\fR ?\fIoption value(s) ...\fR?
.fi
.BE
.SH DESCRIPTION
.PP
A photo is an image whose pixels can display any color with a varying
degree of transparency (the alpha channel). A photo image is stored
internally in full color (32 bits per pixel), and is displayed using
dithering if necessary.  Image data for a photo image can be obtained
from a file or a string, or it can be supplied from C code through a
procedural interface.  At present, only
.VS 8.6
PNG,
.VE 8.6
GIF, PPM/PGM,
.VS 8.7
and (read-only) SVG
.VE 8.7
formats are supported, but an interface exists to
GIF and PPM/PGM formats are supported, but an interface exists to
allow additional image file formats to be added easily.  A photo image
is (semi)transparent if the image data it was obtained from had
transparency information. In regions where no image data has been
transparency informaton. In regions where no image data has been
supplied, it is fully transparent. Transparency may also be modified
with the \fBtransparency set\fR subcommand.
.SH "CREATING PHOTOS"
.PP
Like all images, photos are created using the \fBimage create\fR
command.
Photos support the following \fIoptions\fR:
.\" OPTION: -data
.TP
\fB\-data \fIstring\fR
.
Specifies the contents of the image as a string.
Specifies the contents of the image as a string.  
.VS 8.7
The string should
contain data in the default list-of-lists form,
contain data in the default list-of-lists form, 
.VE 8.7
binary data or, for some formats, base64-encoded data (this is
currently guaranteed to be supported for PNG and GIF images). The
format of the string must be one of those for which there is an image
file format handler that will accept string data.  If both the
\fB\-data\fR and \fB\-file\fR options are specified, the \fB\-file\fR
option takes precedence.
.\" OPTION: -format
.TP
\fB\-format\fR {\fIformat-name\fR ?\fIoption value ...\fR?}
.
Specifies the name of the file format for the data specified with the
\fB\-data\fR or \fB\-file\fR option and optional arguments passed to
the format handler. Note that the value of this option must be a Tcl list.
the format handler. Note: the value of this option must be a Tcl list.
This means that the braces may be omitted if the argument has only one
word. Also, instead of braces, double quotes may be used for quoting.
.\" OPTION: -file
.TP
\fB\-file \fIname\fR
.
\fIname\fR gives the name of a file that is to be read to supply data
for the photo image.  The file format must be one of those for which
there is an image file format handler that can read data.
.\" OPTION: -gamma
.TP
\fB\-gamma \fIvalue\fR
.
Specifies that the colors allocated for displaying this image in a
window should be corrected for a non-linear display with the specified
gamma exponent value.  (The intensity produced by most
CRT displays is a power function of the input value, to a good
approximation; gamma is the exponent and is typically around 2).
The value specified must be greater than zero.  The default
value is one (no correction).  In general, values greater than one
will make the image lighter, and values less than one will make it
darker.
.\" OPTION: -height
.TP
\fB\-height \fInumber\fR
.
Specifies the height of the image, in pixels.  This option is useful
primarily in situations where the user wishes to build up the contents
of the image piece by piece.  A value of zero (the default) allows the
image to expand or shrink vertically to fit the data stored in it.
.VS 8.7
.\" OPTION: -metadata
.TP
\fB\-metadata \fImetadata\fR
.
Set the metadata dictionary of the image.
Additional keys may be set within the metadata dictionary of the image,
if image data is processed due to a \fB\-file\fR or \fB\-data\fR options
and the driver outputs any metadata keys.
See section \fBMETADATA DICTIONARY\fR below.
.VE 8.7
.\" OPTION: -palette
.TP
\fB\-palette \fIpalette-spec\fR
.
Specifies the resolution of the color cube to be allocated for
displaying this image, and thus the number of colors used from the
colormaps of the windows where it is displayed.  The
\fIpalette-spec\fR string may be either a single decimal number,
specifying the number of shades of gray to use, or three decimal
numbers separated by slashes (/), specifying the number of shades of
red, green and blue to use, respectively.  If the first form (a single
number) is used, the image will be displayed in monochrome (i.e.,
grayscale).
.\" OPTION: -width
.TP
\fB\-width \fInumber\fR
.
Specifies the width of the image, in pixels.    This option is useful
primarily in situations where the user wishes to build up the contents
of the image piece by piece.  A value of zero (the default) allows the
image to expand or shrink horizontally to fit the data stored in it.
.SH "IMAGE COMMAND"
.PP
When a photo image is created, Tk also creates a new command
whose name is the same as the image.
This command may be used to invoke various operations
on the image.
It has the following general form:
.CS
\fIimageName option \fR?\fIarg ...\fR?
\fIimageName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.
.PP
Those options that write data to the image generally expand the size
of the image, if necessary, to accommodate the data written to the
image, unless the user has specified non-zero values for the
\fB\-width\fR and/or \fB\-height\fR configuration options, in which
case the width and/or height, respectively, of the image will not be
changed.
.PP
The following commands are possible for photo images:
.\" METHOD: blank
.TP
\fIimageName \fBblank\fR
.
Blank the image; that is, set the entire image to have no data, so it
will be displayed as transparent, and the background of whatever
window it is displayed in will show through. The metadata dict of the
window it is displayed in will show through.
image is not changed.
.\" METHOD: cget
.TP
\fIimageName \fBcget\fI option\fR
\fIimageName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the
\fBimage create\fR \fBphoto\fR command.
.\" METHOD: configure
.TP
\fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options for the image.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIimageName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the
\fBimage create\fR \fBphoto\fR command.
.VS 8.7
Note that setting the \fB\-metadata\fR option without any other option
will not invoke the image format driver to recreate the bitmap.
.VE 8.7
.\" METHOD: copy
.TP
\fIimageName \fBcopy\fI sourceImage\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBcopy\fR \fIsourceImage\fR ?\fIoption value(s) ...\fR?
.
Copies a region from the image called \fIsourceImage\fR (which must
be a photo image) to the image called \fIimageName\fR, possibly with
pixel zooming and/or subsampling.  If no options are specified, this
command copies the whole of \fIsourceImage\fR into \fIimageName\fR,
starting at coordinates (0,0) in \fIimageName\fR.  The following
options may be specified:
.RS
.\" OPTION: -from
.TP
\fB\-from \fIx1 y1 x2 y2\fR
.
Specifies a rectangular sub-region of the source image to be copied.
(\fIx1,y1\fR) and (\fIx2,y2\fR) specify diagonally opposite corners of
the rectangle.  If \fIx2\fR and \fIy2\fR are not specified, the
default value is the bottom-right corner of the source image.  The
pixels copied will include the left and top edges of the specified
rectangle but not the bottom or right edges.  If the \fB\-from\fR
option is not given, the default is the whole source image.
.\" OPTION: -to
.TP
\fB\-to \fIx1 y1 x2 y2\fR
.
Specifies a rectangular sub-region of the destination image to be
affected.  (\fIx1,y1\fR) and (\fIx2,y2\fR) specify diagonally opposite
corners of the rectangle.  If \fIx2\fR and \fIy2\fR are not specified,
the default value is (\fIx1,y1\fR) plus the size of the source
region (after subsampling and zooming, if specified).  If \fIx2\fR and
\fIy2\fR are specified, the source region will be replicated if
necessary to fill the destination region in a tiled fashion.
.\" OPTION: -shrink
.TP
\fB\-shrink\fR
.
Specifies that the size of the destination image should be reduced, if
necessary, so that the region being copied into is at the bottom-right
corner of the image.  This option will not affect the width or height
of the image if the user has specified a non-zero value for the
\fB\-width\fR or \fB\-height\fR configuration option, respectively.
.\" OPTION: -zoom
.TP
\fB\-zoom \fIx y\fR
.
Specifies that the source region should be magnified by a factor of
\fIx\fR in the X direction and \fIy\fR in the Y direction.  If \fIy\fR
is not given, the default value is the same as \fIx\fR.  With this
option, each pixel in the source image will be expanded into a block
of \fIx\fR x \fIy\fR pixels in the destination image, all the same
color.  \fIx\fR and \fIy\fR must be greater than 0.
.\" OPTION: -subsample
.TP
\fB\-subsample \fIx y\fR
.
Specifies that the source image should be reduced in size by using
only every \fIx\fRth pixel in the X direction and \fIy\fRth pixel in
the Y direction.  Negative values will cause the image to be flipped
about the Y or X axes, respectively.  If \fIy\fR is not given, the
default value is the same as \fIx\fR.
.\" OPTION: -compositingrule
.TP
\fB\-compositingrule \fIrule\fR
.
Specifies how transparent pixels in the source image are combined with
the destination image.  When a compositing rule of \fIoverlay\fR is
set, the old contents of the destination image are visible, as if the
source image were printed on a piece of transparent film and placed
over the top of the destination.  When a compositing rule of \fIset\fR
is set, the old contents of the destination image are discarded and
the source image is used as-is.  The default compositing rule is
\fIoverlay\fR.
.RE
.\" METHOD: data
.TP
\fIimageName \fBdata\fR ?\fIoption value(s) ...\fR?
.
Returns image data in the form of a string.
Returns image data in the form of a string. 
.VS 8.7
The format of the string depends on the format handler. By default, a
human readable format as a list of lists of pixel data is used, other
formats can be chosen with the \fB\-format\fR option.
formats can be chosen with the \fB-format\fR option.
See \fBIMAGE FORMATS\fR below for details.
.VE 8.7
The following options may be specified:
.RS
.\" OPTION: -background
.TP
\fB\-background\fI color\fR
.
If the color is specified, the data will not contain any transparency
information. In all transparent pixels the color will be replaced by
the specified color.
.\" OPTION: -format
.TP
\fB\-format\fR {\fIformat-name\fR ?\fIoption value ...\fR?}
.
Specifies the name of the image file format handler to use and,
optionally, arguments to the format handler.  Specifically, this
subcommand searches for the first handler whose name matches an
initial substring of \fIformat-name\fR and which has the capability to
write a string containing this image data.
write a string containing this image data.  
.VS 8.7
If this option is not given, this subcommand uses the default format
that consists of a list (one element per row) of lists (one element
per pixel/column) of colors in
.QW \fB#\fIrrggbb\fR
format (see \fBIMAGE FORMATS\fR below).
.VE 8.7
Note that the value of this option must be a Tcl list.
Note: the value of this option must be a Tcl list.
This means that the braces may be omitted if the argument has only one
word. Also, instead of braces, double quotes may be used for quoting.
.\" OPTION: -from
.TP
\fB\-from \fIx1 y1 x2 y2\fR
.
Specifies a rectangular region of \fIimageName\fR to be returned.
If only \fIx1\fR and \fIy1\fR are specified, the region
extends from \fI(x1,y1)\fR to the bottom-right corner of
\fIimageName\fR.  If all four coordinates are given, they specify
diagonally opposite corners of the rectangular region, including x1,y1
and excluding x2,y2.  The default, if this option is not given, is the
whole image.
.\" OPTION: -grayscale
.TP
\fB\-grayscale\fR
.
If this options is specified, the data will not contain color
information. All pixel data will be transformed into grayscale.
.VS 8.7
.\" OPTION: -metadata
.TP
\fB\-metadata\fI metadata\fR
.
.RE
Image format handler may use metadata to be included in the returned
data string.
The specified \fImetadata\fR is passed to the driver for inclusion in the
data.
If no \fB\-metadata\fR option is given, the current metadata of the
image is used.
.VE 8.7
.VS 8.7
.RE
.\" METHOD: get
.TP
\fIimageName \fBget\fI x y\fR ?\fB\-withalpha\fR?
\fIimageName \fBget\fR \fIx y\fR ?\fB-withalpha\fR?
.
Returns the color of the pixel at coordinates (\fIx\fR,\fIy\fR) in the
image as a list of three integers between 0 and 255, representing the
red, green and blue components respectively. If the \fB\-withalpha\fR
red, green and blue components respectively. If the \fB-withalpha\fR
option is specified, the returned list will have a fourth element
representing the alpha value of the pixel as an integer between 0 and
255.
.\" METHOD: put
.VE 8.7
.TP
\fIimageName \fBput\fI data\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBput\fR \fIdata\fR ?\fIoption value(s) ...\fR?
.
Sets pixels in \fI imageName\fR to the data specified in \fIdata\fR.
.VS 8.7
This command searches the list of image file format handlers for
a handler that can interpret the data in \fIdata\fR, and then reads
the image encoded within into \fIimageName\fR (the destination image).
See \fBIMAGE FORMATS\fR below for details on formats for image data.
.VE 8.7
The following options may be specified:
.RS
.\" OPTION: -format
.TP
\fB\-format\fR {\fIformat-name\fR ?\fIoption value ..\fR?}
.
Specifies the format of the image data in \fIdata\fR and, optionally,
arguments to be passed to the format handler.
Specifically, only image file format handlers whose names begin with
\fIformat-name\fR will be used while searching for an image data
format handler to read the data.
Note that the value of this option must be a Tcl list.
Note: the value of this option must be a Tcl list.
This means that the braces may be omitted if the argument has only one
word. Also, instead of braces, double quotes may be used for quoting.
.VS 8.7
.\" OPTION: -metadata
.TP
\fB\-metadata\fI metadata\fR
.
A specified \fImetadata\fR is passed to the image format driver when interpreting
the data.
Note that the current metadata of the image is not passed to the format driver
and is not changed by the command.
.VE 8.7
.\" OPTION: -to
.TP
\fB\-to \fIx1 y1\fR ?\fIx2 y2\fR?
.
Specifies the coordinates of the top-left corner (\fIx1\fR,\fIy1\fR)
of the region of \fIimageName\fR into which the image data will be
copied.  The default position is (0,0).  If \fIx2\fR,\fIy2\fR is given
and \fIdata\fR is not large enough to cover the rectangle specified by
this option, the image data extracted will be tiled so it covers the
entire destination rectangle. If the region specified with this option
entire destination rectangle. If the region specified with this opion
is smaller than the supplied \fIdata\fR, the exceeding data is silently
discarded. Note that if \fIdata\fR specifies a
single color value, then a region extending to the bottom-right corner
represented by (\fIx2\fR,\fIy2\fR) will be filled with that color.
.RE
.\" METHOD: read
.TP
\fIimageName \fBread\fI filename\fR ?\fIoption value(s) ...\fR?
\fIimageName \fBread\fR \fIfilename\fR ?\fIoption value(s) ...\fR?
.
Reads image data from the file named \fIfilename\fR into the image.
This command first searches the list of
image file format handlers for a handler that can interpret the data
in \fIfilename\fR, and then reads the image in \fIfilename\fR into
\fIimageName\fR (the destination image).  The following options may be
specified:
.RS
.\" OPTION: -format
.TP
\fB\-format {\fIformat-name\fR ?\fIoption value ..\fR?}
.
Specifies the format of the image data in \fIfilename\fR and,
optionally, additional options to the format handler.
Specifically, only image file format handlers whose names begin with
\fIformat-name\fR will be used while searching for an image data
format handler to read the data.
Note that the value of this option must be a Tcl list.
Note: the value of this option must be a Tcl list.
This means that the braces may be omitted if the argument has only one
word. Also, instead of braces, double quotes may be used for quoting.
.\" OPTION: -from
.TP
\fB\-from \fIx1 y1 x2 y2\fR
.
Specifies a rectangular sub-region of the image file data to be copied
to the destination image.  If only \fIx1\fR and \fIy1\fR are
specified, the region extends from (\fIx1,y1\fR) to the bottom-right
corner of the image in the image file.  If all four coordinates are
specified, they specify diagonally opposite corners or the region.
The default, if this option is not specified, is the whole of the
image in the image file.
.VS 8.7
.\" OPTION: -metadata
.TP
\fB\-metadata\fI metadata\fR
.
A specified \fImetadata\fR is passed to the image format driver when interpreting
the data.
Note that the current metadata of the image is not passed to the format driver
and is not changed by the command.
.VE 8.7
.\" OPTION: -shrink
.TP
\fB\-shrink\fR
.
If this option, the size of \fIimageName\fR will be reduced, if
necessary, so that the region into which the image file data are read
is at the bottom-right corner of the \fIimageName\fR.  This option
will not affect the width or height of the image if the user has
specified a non-zero value for the \fB\-width\fR or \fB\-height\fR
configuration option, respectively.
.\" OPTION: -to
.TP
\fB\-to \fIx y\fR
.
Specifies the coordinates of the top-left corner of the region of
\fIimageName\fR into which data from \fIfilename\fR are to be read.
The default is (0,0).
.RE
.\" METHOD: redither
.TP
\fIimageName \fBredither\fR
.
The dithering algorithm used in displaying photo images propagates
quantization errors from one pixel to its neighbors.
If the image data for \fIimageName\fR is supplied in pieces, the
dithered image may not be exactly correct.  Normally the difference is
not noticeable, but if it is a problem, this command can be used to
recalculate the dithered image in each window where the image is
displayed.
.\" METHOD: transparency
.TP
\fIimageName \fBtransparency \fIsubcommand \fR?\fIarg ...\fR?
\fIimageName \fBtransparency \fIsubcommand \fR?\fIarg arg ...\fR?
.
Allows examination and manipulation of the transparency information in
the photo image.  Several subcommands are available:
.RS
.VS 8.7
.TP
\fIimageName \fBtransparency get \fIx y\fR ?\fB\-alpha\fR?
\fIimageName \fBtransparency get \fIx y\fR ?\fB-alpha\fR?
.VS 8.7
.
Returns true if the pixel at (\fIx\fR,\fIy\fR) is fully transparent,
false otherwise.  If the option \fB\-alpha\fR is passed, returns the
false otherwise.  If the option \fB-alpha\fR is passed, returns the
alpha value of the pixel instead, as an integer in the range 0 to 255.
.VE 8.7

.VS 8.7
.TP
\fIimageName \fBtransparency set \fIx y newVal\fR ?\fB\-alpha\fR?
\fIimageName \fBtransparency set \fIx y\fR \fInewVal\fR ?\fB-alpha\fR?
.VS 8.7
.
Change the transparency of the pixel at (\fIx\fR,\fIy\fR) to
\fInewVal.\fR If no additional option is passed, \fInewVal\fR is
interpreted as a boolean and the pixel is made fully transparent if
that value is true, fully opaque otherwise.  If the \fB\-alpha\fR
that value is true, fully opaque otherwise.  If the \fB-alpha\fR
option is passed, \fInewVal\fR is interpreted as an integral alpha
value for the pixel, which must be in the range 0 to 255.
.VE 8.7
.RE
.\" METHOD: write
.TP
\fIimageName \fBwrite \fIfilename\fR ?\fIoption value(s) ...\fR?
.
Writes image data from \fIimageName\fR to a file named \fIfilename\fR.
The following options may be specified:
.RS
.\" OPTION: -background
.TP
\fB\-background\fI color\fR
.
If the color is specified, the data will not contain any transparency
information. In all transparent pixels the color will be replaced by
the specified color.
.\" OPTION: -format
.TP
\fB\-format\fR {\fIformat-name\fR ?\fIoption value ...\fR?}
.
Specifies the name of the image file format handler to be used to
write the data to the file and, optionally, options to pass to the
format handler.  Specifically, this subcommand searches for the first
handler whose name matches an initial substring of \fIformat-name\fR
and which has the capability to write an image file.  If this option
is not given, the format is guessed from the file extension. If that
cannot be determined, this subcommand uses the first handler that has
the capability to write an image file.
Note that the value of this option must be a Tcl list.
Note: the value of this option must be a Tcl list.
This means that the braces may be omitted if the argument has only one
word. Also, instead of braces, double quotes may be used for quoting.
.\" OPTION: -from
.TP
\fB\-from \fIx1 y1 x2 y2\fR
.
Specifies a rectangular region of \fIimageName\fR to be written to the
image file.  If only \fIx1\fR and \fIy1\fR are specified, the region
extends from \fI(x1,y1)\fR to the bottom-right corner of
\fIimageName\fR.  If all four coordinates are given, they specify
diagonally opposite corners of the rectangular region.  The default,
if this option is not given, is the whole image.
.\" OPTION: -grayscale
.TP
\fB\-grayscale\fR
.
If this options is specified, the data will not contain color
information. All pixel data will be transformed into grayscale.
.VS 8.7
.\" OPTION: -metadata
.TP
\fB\-metadata\fI metadata\fR
.
Image format handler may use metadata to be included in the written file.
The specified \fImetadata\fR is passed to the driver for inclusion in the
file.
If no \fB\-metadata\fR option is given, the current metadata of the
image is used.
.VE 8.7
.RE
.SH "IMAGE FORMATS"
.PP
The photo image code is structured to allow handlers for additional
image file formats to be added easily.  The photo image code maintains
a list of these handlers.  Handlers are added to the list by
registering them with a call to \fBTk_CreatePhotoImageFormat\fR.  The
standard Tk distribution comes with handlers for PPM/PGM, PNG, GIF and
(read-only) SVG formats,
standard Tk distribution comes with handlers for PPM/PGM, PNG and GIF
formats, 
.VS 8.7
as well as the \fBdefault\fR handler to encode/decode image
data in a human readable form.
data in a human readable form. 
.VE 8.7
These handlers are automatically registered on initialization.
.PP
When reading an image file or processing string data specified with
the \fB\-data\fR configuration option, the photo image code invokes
each handler in turn until one is found that claims to be able to read
the data in the file or string.  Usually this will find the correct
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759


760
761
762
763
764
765
766



767
768
769
770


771
772
773
774
775

776
777
778
779
780
781
782
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519

520
521
522
523
524
525

526
527
528
529
530

531
532
533
534
535
536
537

538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553

















































































554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577


578
579
580
581
582
583



584
585
586
587
588


589
590
591
592
593
594

595
596
597
598
599
600
601
602







-
+












-
+





-





-
+






-








-








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-
+





-
-
+
+




-
-
-
+
+
+


-
-
+
+




-
+







.SS "THE DEFAULT IMAGE HANDLER"
.PP
The \fBdefault\fR image handler cannot be used to read or write data
from/to a file. Its sole purpose is to encode and decode image data in
string form in a clear text, human readable, form. The \fIimageName\fR
\fBdata\fR subcommand uses this handler when no other format is
specified. When reading image data from a string with \fIimageName\fR
\fBput\fR or the \fB\-data\fR option, the default handler is treated
\fBput\fR or the \fB-data\fR option, the default handler is treated
as the other handlers.
.PP
Image data in the \fBdefault\fR string format is a (top-to-bottom)
list of scan-lines, with each scan-line being a (left-to-right) list
of pixel data. Every scan-line has the same length. The color
and, optionally, alpha value of each pixel is specified in any of
the forms described in the \fBCOLOR FORMATS\fR section below.
.VE 8.7

.SS "FORMAT SUBOPTIONS"
.PP
.VS 8.6
Image formats may support sub-options, which are specified using
Image formats may support sub-options, wich ahre specified using
additional words in the value to the \fB\-format\fR option. These
suboptions can affect how image data is read or written to file or
string. The nature and values of these options is up to the format
handler.
The built-in handlers support these suboptions:
.\" OPTION -colorformat
.VS 8.7
.TP
\fBdefault \-colorformat\fI formatType\fR
.
The option is allowed when writing image data to a string with
\fIimageName \fBdata\fR. Specifies the format to use for the color
\fIimageName\fR \fBdata\fR. Specifies the format to use for the color
string of each pixel. \fIformatType\fR may be one of: \fBrgb\fR to
encode pixel data in the form \fB#\fIRRGGBB\fR, \fBrgba\fR to encode
pixel data in the form \fB#\fIRRGGBBAA\fR or \fBlist\fR to encode
pixel data as a list with four elements. See \fBCOLOR FORMATS\fR
below for details. The default is \fBrgb\fR.
.VE 8.7
.\" OPTION -index
.TP
\fBgif \-index\fI indexValue\fR
.
The option has effect when reading image data from a file. When
parsing a multi-part GIF image, Tk normally only accesses the first
image. By giving the \fB\-index\fR sub-option, the \fIindexValue\fR'th
value may be used instead. The \fIindexValue\fR must be an integer
from 0 up to the number of image parts in the GIF data.
.\" OPTION -alpha
.TP
\fBpng \-alpha\fI alphaValue\fR
.
The option has effect when reading image data from a file. Specifies
an additional alpha filtering for the overall image, which allows the
background on which the image is displayed to show through.  This
usually also has the effect of desaturating the image.  The
\fIalphaValue\fR must be between 0.0 and 1.0.
.\" OPTION -dpi
.\" OPTION -scale
.\" OPTION -scaletowidth
.\" OPTION -scaletoheight
.TP
\fBsvg \-dpi\fI dpiValue \fB\-scale\fI scaleValue \fB\-scaletowidth\fI width \fB\-scaletoheight\fI height\fR
.
\fIdpiValue\fR is used in conversion between given coordinates and
screen resolution. The value must be greater than 0 and the default
value is 96.
.PP
.RS
\fIscaleValue\fR is used to scale the resulting image. The value must
be greater than 0 and the default value is 1.
\fIwidth\fR and \fIheight\fR are the width or height that the image
will be adjusted to. Only one parameter among \fB\-scale\fR,
\fB\-scaletowidth\fR and \fB\-scaletoheight\fR can be given at a time
and the aspect ratio of the original image is always preserved.
The \fBsvg\fR format supports a wide range of SVG features, but the
full SVG standard is not available, for instance the 'text' feature
is missing and silently ignored when reading the SVG data.
The supported SVG features are:
.TP
\fBelements:\fR
.
g, path, rect, circle, ellipse, line, polyline, polygon,
linearGradient, radialGradient, stop, defs, svg, style
.TP
\fBattributes:\fR
.
width, height, viewBox,
preserveAspectRatio with none, xMin, xMid, xMax, yMin, yMid, yMax, slice
.TP
\fBgradient attributes:\fR
.
gradientUnits with objectBoundingBox,
gradientTransform, cx, cy, r fx, fy x1, y1, x2, y2
spreadMethod with pad, reflect or repeat,
xlink:href
.TP
\fBpoly attributes:\fR
.
points
.TP
\fBline attributes:\fR
.
x1, y1, x2, y2
.TP
\fBellipse attributes:\fR
.
cx, cy, rx, ry
.TP
\fBcircle attributes:\fR
.
cx, cy, r
.TP
\fBrectangle attributes:\fR
.
x, y, width, height, rx, ry
.TP
\fBpath attributes:\fR
.
d with m, M, l, L, h, H, v, V, c, C, s, S, q, Q, t, T, a, A, z, Z
.TP
\fBstyle attributes:\fR
.
display with none, visibility, hidden, visible,
fill with nonzero and evenodd, opacity, fill-opacity,
stroke, stroke-width, stroke-dasharray, stroke-dashoffset, stroke-opacity,
stroke-linecap with butt, round and square,
stroke-linejoin with miter, round and  bevel, stroke-miterlimit
fill-rule, font-size,
transform with matrix, translate, scale, rotate, skewX and  skewY,
stop-color, stop-opacity, offset, id, class
.RE
.PP
.RS
Currently only SVG images reading and conversion into (pixel-based
format) photos is supported: Tk does not (yet) support bundling photo
images in SVG vector graphics.
.RE
.VE 8.6
.VS 8.7
.SH "COLOR FORMATS"
.PP
The default image handler can represent/parse color and alpha values
of a pixel in one of the formats listed below. If a color format does
not contain transparency information, full opacity is assumed.  The
available color formats are:
.IP \(bu 3
The empty string - interpreted as full transparency, the color value
is undefined.
.IP \(bu 3
Any value accepted by \fBTk_GetColor\fR, optionally followed by an
alpha suffix. The alpha suffix may be one of:
.RS
.TP
\fB@\fR\fIA\fR
.
The alpha value \fIA\fR must be a fractional value in the range  0.0
The alpha value \fIA\fR must be a fractional value in the range  0.0 
(fully transparent) to 1.0 (fully opaque).
.TP
\fB#\fR\fIX\fR
.
The alpha value \fIX\fR is a hexadecimal digit that specifies an integer
alpha value in the range 0 (fully transparent) to 255 (fully opaque).
This is expanded in range from 4 bits wide to 8 bits wide by
alpha value in the range 0 (fully transparent) to 255 (fully opaque). 
This is expanded in range from 4 bits wide to 8 bits wide by 
multiplication by 0x11.
.TP
\fB#\fR\fIXX\fR
.
The alpha value \fIXX\fR is passed as two hexadecimal digits that
specify an integer alpha value in the range 0 (fully transparent) to 255
(fully opaque).
The alpha value \fIXX\fR is passed as two hexadecimal digits that 
specify an integer alpha value in the range 0 (fully transparent) to 255 
(fully opaque). 
.RE
.IP \(bu 3
A Tcl list with three or four integers in the range 0 to 255,
specifying the values for the red, green, blue and (optionally)
A Tcl list with three or four integers in the range 0 to 255, 
specifying the values for the red, green, blue and (optionally) 
alpha channels respectively.
.IP \(bu 3
\fB#\fR\fIRGBA\fR format: a \fB#\fR followed by four hexadecimal digits,
where each digit is the value for the red, green, blue and alpha
channels respectively. Each digit will be expanded internally to
channels respectively. Each digit will be expanded internally to 
8 bits by multiplication by 0x11.
.IP \(bu 3
\fB#\fR\fIRRGGBBAA\fR format: \fB#\fR followed by eight hexadecimal digits,
where each pair of  subsequent digits represents the value for the red,
green, blue and alpha channels respectively.
.VE 8.7
.SH "COLOR ALLOCATION"
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877

878
879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896




897
898
899
900
901
902
903
624
625
626
627
628
629
630






















































631
632
633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
658




659
660
661
662
663
664
665
666
667
668
669







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+






-
+








-
-
-
-
+
+
+
+







The user can exercise some control over the number of colors that a
photo image uses with the \fB\-palette\fR configuration option.  If
this option is used, it specifies the maximum number of shades of
each primary color to try to allocate.  It can also be used to force
the image to be displayed in shades of gray, even on a color display,
by giving a single number rather than three numbers separated by
slashes.
.VS 8.7
.SH "METADATA DICTIONARY"
.PP
Each image has a metadata dictionary property.
This dictionary is not relevant to the bitmap representation of the
image, but may contain additional information like resolution or
comments.
Image format drivers may output metadata when image data is
parsed, or may use metadata to be included in image files or formats.
.SS "METADATA KEYS (MULTIPLE FORMATS)"
.PP
Each image format driver supports an individual set of metadata dictionary
keys. Predefined keys are:
.IP \fBDPI\fR
Horizontal image resolution in DPI as a double value.
Supported by format \fBpng\fR.
.IP \fBaspect\fR
Aspect ratio horizontal divided by vertical as double value.
Supported by formats \fBgif\fR and \fBpng\fR.
.IP \fBcomment\fR
Image text comment.
Supported by formats \fBgif\fR and \fBpng\fR.
.PP
It is valid to set any key in the metadata dict.
A format driver will ignore keys that it does not handle.
.SS "METADATA KEYS FOR ANIMATED GIF INFORMATION"
.PP
The following metadata keys are reported when reading a \fBgif\fR format file.
They are typically used in conjunction with the \fB\-index\fR option of an
animated \fBgif\fR file to properly display the subimage sequence.
The options are linked to each subimage selected by \fB\-index\fR.
.TP
\fBdelay time\fI time\fR
.
Update delay time in 10ms units.
This key is only present if the delay time is not 0.
.TP
\fBdisposal method\fI method\fR
.
Disposal method of the preceeding image, if given for the current image.
Possible values are: \fBdo not dispose\fR, \fBrestore to background color\fR,
\fBrestore to previous\fR.
.TP
\fBuser interaction\fI bool\fR
.
The key is present with a value of 1, if user interaction is specified.
Otherwise, the key is not present.
.TP
\fBupdate region\fI X0\fR, \fIY0\fR, \fIwidth\fR, \fIheight\fR
.
Update region of the current subimage, if subimage has not the same size as
the full image. The pixel outside of this box are all fully transparent.
.PP
.VE 8.7
.SH CREDITS
.PP
The photo image type was designed and implemented by Paul Mackerras,
based on his earlier photo widget and some suggestions from
John Ousterhout.
.SH EXAMPLE
.PP
Load an image from a file and tile it to the size of a window, which
is useful for producing a tiled background:
.PP
.CS
# These lines should be called once
\fBimage create photo\fR untiled -file "theFile.ppm"
\fBimage create photo\fR untiled \-file "theFile.ppm"
\fBimage create photo\fR tiled

# These lines should be called whenever .someWidget changes
# size; a <Configure> binding is useful here
set width  [winfo width .someWidget]
set height [winfo height .someWidget]
tiled \fBcopy\fR untiled -to 0 0 $width $height -shrink
tiled \fBcopy\fR untiled \-to 0 0 $width $height \-shrink
.CE
.PP
.VS 8.6
The PNG image loader allows the application of an additional alpha factor
during loading, which is useful for generating images suitable for disabled
buttons:
.PP
.CS
\fBimage create photo\fR icon -file "icon.png"
\fBimage create photo\fR iconDisabled -file "icon.png" \e
        -format "png -alpha 0.5"
button .b -image icon -disabledimage iconDisabled
\fBimage create photo\fR icon \-file "icon.png"
\fBimage create photo\fR iconDisabled \-file "icon.png" \e
        \-format "png \-alpha 0.5"
button .b \-image icon \-disabledimage iconDisabled
.CE
.VE 8.6
.PP
.VS 8.7
Create a green box with a simple shadow effect
.PP
.CS

Changes to doc/place.n.

14
15
16
17
18
19
20
21
22


23
24
25
26



27
28
29


30
31
32
33
34

35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74

75
76
77


78
79
80

81
82
83
84
85

86
87

88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109

110
111

112
113

114
115
116
117


118
119
120
121
122
123
124
125
126
127
128




129
130

131
132
133
134
135
136
137
138
139
140




141
142

143
144
145
146
147

148
149
150
151

152
153

154
155
156


157
158
159
160
161

162
163
164
165

166
167

168
169
170


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186








187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233


234
235
236
237
238
239
240
241
242
243


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269

270
271
272
273
274

275
276
277
278
279
280
281
282
283
284


285
286
287
288
289

290
291
292
293
14
15
16
17
18
19
20


21
22
23



24
25
26
27


28
29
30
31
32


33
34
35
36
37

38
39


40
41
42
43
44
45
46
47
48
49
50
51
52

53
54

55
56
57
58
59
60
61

62
63

64
65

66

67
68


69
70
71
72

73
74
75
76
77

78
79

80
81

82
83
84
85
86

87
88

89
90
91
92
93
94
95

96

97


98
99

100
101

102
103
104


105
106
107

108
109

110
111




112
113
114
115
116

117

118
119

120
121




122
123
124
125
126

127

128
129


130
131
132
133

134
135

136
137


138
139

140
141


142
143
144
145

146
147

148
149


150
151

152
153

154
155
156
157
158
159
160

161
162


163
164
165
166
167
168
169
170
171
172
173

174









175
176
177
178
179

180







181

182
183
184
185
186

187
188

189
190
191
192

193
194


195
196
197
198
199
200
201
202
203
204


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231

232
233
234
235
236

237
238
239
240
241
242
243
244
245


246
247
248
249
250
251

252

253
254
255







-
-
+
+

-
-
-
+
+
+

-
-
+
+



-
-
+




-


-
-
+












-


-







-
+

-


-

-
+

-
-
+
+


-
+




-
+

-
+

-
+




-


-







-

-
+
-
-
+

-
+

-
+


-
-
+
+

-


-


-
-
-
-
+
+
+
+

-
+
-


-


-
-
-
-
+
+
+
+

-
+
-


-
-
+



-
+

-
+

-
-
+
+
-


-
-
+



-
+

-
+

-
-
+
+
-


-







-


-
-
+
+
+
+
+
+
+
+



-
+
-
-
-
-
-
-
-
-
-





-

-
-
-
-
-
-
-

-





-


-




-


-
-
+
+








-
-
+
+

















-
+







-
+




-
+








-
-
+
+




-
+
-



.SH SYNOPSIS
\fBplace \fIoption arg \fR?\fIarg ...\fR?
.BE
.SH DESCRIPTION
.PP
The placer is a geometry manager for Tk.
It provides simple fixed placement of windows, where you specify
the exact size and location of one window, called the \fIcontent\fR,
within another window, called the \fIcontainer\fR.
the exact size and location of one window, called the \fIslave\fR,
within another window, called the \fImaster\fR.
The placer also provides rubber-sheet placement, where you specify the
size and location of the content in terms of the dimensions of
the container, so that the content changes size and location
in response to changes in the size of the container.
size and location of the slave in terms of the dimensions of
the master, so that the slave changes size and location
in response to changes in the size of the master.
Lastly, the placer allows you to mix these styles of placement so
that, for example, the content has a fixed width and height but is
centered inside the container.
that, for example, the slave has a fixed width and height but is
centered inside the master.
.PP
.TP
\fBplace \fIwindow option value \fR?\fIoption value ...\fR?
.
Arrange for the placer to manage the geometry of a content whose
Arrange for the placer to manage the geometry of a slave whose
pathName is \fIwindow\fR.  The remaining arguments consist of one or
more \fIoption\-value\fR pairs that specify the way in which
\fIwindow\fR's geometry is managed.  \fIOption\fR may have any of the
values accepted by the \fBplace configure\fR command.
.\" METHOD: configure
.TP
\fBplace configure \fIwindow \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the geometry options of the content given by
Query or modify the geometry options of the slave given by
\fIwindow\fR.  If no \fIoption\fR is specified, this command returns a
list describing the available options (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given option(s) to have the given value(s); in this case
the command returns an empty string.
.RS
.PP
The following \fIoption\-value\fR pairs are supported:
.\" OPTION: -anchor
.TP
\fB\-anchor \fIwhere\fR
.
\fIWhere\fR specifies which point of \fIwindow\fR is to be positioned
at the (x,y) location selected by the \fB\-x\fR, \fB\-y\fR,
\fB\-relx\fR, and \fB\-rely\fR options.
The anchor point is in terms of the outer area of \fIwindow\fR
including its border, if any.
Thus if \fIwhere\fR is \fBse\fR then the lower-right corner of
\fIwindow\fR's border will appear at the given (x,y) location
in the container.
in the master.
The anchor position defaults to \fBnw\fR.
.\" OPTION: -bordermode
.TP
\fB\-bordermode \fImode\fR
.
\fIMode\fR determines the degree to which borders within the
container are used in determining the placement of the content.
master are used in determining the placement of the slave.
The default and most common value is \fBinside\fR.
In this case the placer considers the area of the container to
be the innermost area of the container, inside any border:
In this case the placer considers the area of the master to
be the innermost area of the master, inside any border:
an option of \fB\-x 0\fR corresponds to an x-coordinate just
inside the border and an option of \fB\-relwidth 1.0\fR
means \fIwindow\fR will fill the area inside the container's
means \fIwindow\fR will fill the area inside the master's
border.
.RS
.PP
If \fImode\fR is \fBoutside\fR then the placer considers
the area of the container to include its border;
the area of the master to include its border;
this mode is typically used when placing \fIwindow\fR
outside its container, as with the options \fB\-x 0 \-y 0 \-anchor ne\fR.
outside its master, as with the options \fB\-x 0 \-y 0 \-anchor ne\fR.
Lastly, \fImode\fR may be specified as \fBignore\fR, in which
case borders are ignored:  the area of the container is considered
case borders are ignored:  the area of the master is considered
to be its official X area, which includes any internal border but
no external border.  A bordermode of \fBignore\fR is probably
not very useful.
.RE
.\" OPTION: -height
.TP
\fB\-height \fIsize\fR
.
\fISize\fR specifies the height for \fIwindow\fR in screen units
(i.e. any of the forms accepted by \fBTk_GetPixels\fR).
The height will be the outer dimension of \fIwindow\fR including its
border, if any.
If \fIsize\fR is an empty string, or if no \fB\-height\fR or
\fB\-relheight\fR option is specified, then the height requested
internally by the window will be used.
.\" OPTION: -in
.TP
\fB\-in \fIcontainer\fR
\fB\-in \fImaster\fR
.
\fIContainer\fR specifies the path name of the window relative
\fIMaster\fR specifies the path name of the window relative
to which \fIwindow\fR is to be placed.
\fIContainer\fR must either be \fIwindow\fR's parent or a descendant
\fIMaster\fR must either be \fIwindow\fR's parent or a descendant
of \fIwindow\fR's parent.
In addition, \fIcontainer\fR and \fIwindow\fR must both be descendants
In addition, \fImaster\fR and \fIwindow\fR must both be descendants
of the same top-level window.
These restrictions are necessary to guarantee
that \fIwindow\fR is visible whenever \fIcontainer\fR is visible.
If this option is not specified then the other window defaults to
that \fIwindow\fR is visible whenever \fImaster\fR is visible.
If this option is not specified then the master defaults to
\fIwindow\fR's parent.
.\" OPTION: -relheight
.TP
\fB\-relheight \fIsize\fR
.
\fISize\fR specifies the height for \fIwindow\fR.
In this case the height is specified as a floating-point number
relative to the height of the container: 0.5 means \fIwindow\fR will
be half as high as the container, 1.0 means \fIwindow\fR will have
the same height as the container, and so on.
If both \fB\-height\fR and \fB\-relheight\fR are specified for a content,
relative to the height of the master: 0.5 means \fIwindow\fR will
be half as high as the master, 1.0 means \fIwindow\fR will have
the same height as the master, and so on.
If both \fB\-height\fR and \fB\-relheight\fR are specified for a slave,
their values are summed.  For example, \fB\-relheight 1.0 \-height \-2\fR
makes the content 2 pixels shorter than the container.
makes the slave 2 pixels shorter than the master.
.\" OPTION: -relwidth
.TP
\fB\-relwidth \fIsize\fR
.
\fISize\fR specifies the width for \fIwindow\fR.
In this case the width is specified as a floating-point number
relative to the width of the container: 0.5 means \fIwindow\fR will
be half as wide as the container, 1.0 means \fIwindow\fR will have
the same width as the container, and so on.
If both \fB\-width\fR and \fB\-relwidth\fR are specified for a content,
relative to the width of the master: 0.5 means \fIwindow\fR will
be half as wide as the master, 1.0 means \fIwindow\fR will have
the same width as the master, and so on.
If both \fB\-width\fR and \fB\-relwidth\fR are specified for a slave,
their values are summed.  For example, \fB\-relwidth 1.0 \-width 5\fR
makes the content 5 pixels wider than the container.
makes the slave 5 pixels wider than the master.
.\" OPTION: -relx
.TP
\fB\-relx \fIlocation\fR
.
\fILocation\fR specifies the x-coordinate within the container window
\fILocation\fR specifies the x-coordinate within the master window
of the anchor point for \fIwindow\fR.
In this case the location is specified in a relative fashion
as a floating-point number:  0.0 corresponds to the left edge
of the container and 1.0 corresponds to the right edge of the container.
of the master and 1.0 corresponds to the right edge of the master.
\fILocation\fR need not be in the range 0.0\-1.0.
If both \fB\-x\fR and \fB\-relx\fR are specified for a content
If both \fB\-x\fR and \fB\-relx\fR are specified for a slave
then their values are summed.  For example, \fB\-relx 0.5 \-x \-2\fR
positions the left edge of the content 2 pixels to the left of the
center of its container.
positions the left edge of the slave 2 pixels to the left of the
center of its master.
.\" OPTION: -rely
.TP
\fB\-rely \fIlocation\fR
.
\fILocation\fR specifies the y-coordinate within the container window
\fILocation\fR specifies the y-coordinate within the master window
of the anchor point for \fIwindow\fR.
In this case the value is specified in a relative fashion
as a floating-point number:  0.0 corresponds to the top edge
of the container and 1.0 corresponds to the bottom edge of the container.
of the master and 1.0 corresponds to the bottom edge of the master.
\fILocation\fR need not be in the range 0.0\-1.0.
If both \fB\-y\fR and \fB\-rely\fR are specified for a content
If both \fB\-y\fR and \fB\-rely\fR are specified for a slave
then their values are summed.  For example, \fB\-rely 0.5 \-x 3\fR
positions the top edge of the content 3 pixels below the
center of its container.
positions the top edge of the slave 3 pixels below the
center of its master.
.\" OPTION: -width
.TP
\fB\-width \fIsize\fR
.
\fISize\fR specifies the width for \fIwindow\fR in screen units
(i.e. any of the forms accepted by \fBTk_GetPixels\fR).
The width will be the outer width of \fIwindow\fR including its
border, if any.
If \fIsize\fR is an empty string, or if no \fB\-width\fR
or \fB\-relwidth\fR option is specified, then the width requested
internally by the window will be used.
.\" OPTION: -x
.TP
\fB\-x \fIlocation\fR
.
\fILocation\fR specifies the x-coordinate within the container window
\fILocation\fR specifies the x-coordinate within the master window
of the anchor point for \fIwindow\fR.
The location is specified in screen units (i.e. any of the forms
accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
of the master window.
.TP
\fB\-y \fIlocation\fR
\fILocation\fR specifies the y-coordinate within the master window
of the anchor point for \fIwindow\fR.
The location is specified in screen units (i.e. any of the forms
accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
of the container window.
of the master window.
.\" OPTION: -y
.TP
\fB\-y \fIlocation\fR
.
\fILocation\fR specifies the y-coordinate within the container window
of the anchor point for \fIwindow\fR.
The location is specified in screen units (i.e. any of the forms
accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
of the container window.
.PP
If the same value is specified separately with
two different options, such as \fB\-x\fR and \fB\-relx\fR, then
the most recent option is used and the older one is ignored.
.RE
.\" METHOD: content
.TP
\fBplace content \fIwindow\fR
.
Returns a list of all the content windows for which \fIwindow\fR is the
container. If there is no content for \fIwindow\fR then an empty string
is returned.
.\" METHOD: forget
.TP
\fBplace forget \fIwindow\fR
.
Causes the placer to stop managing the geometry of \fIwindow\fR.  As a
side effect of this command \fIwindow\fR will be unmapped so that it
does not appear on the screen.  If \fIwindow\fR is not currently managed
by the placer then the command has no effect.  This command returns an
empty string.
.\" METHOD: info
.TP
\fBplace info \fIwindow\fR
.
Returns a list giving the current configuration of \fIwindow\fR.
The list consists of \fIoption\-value\fR pairs in exactly the
same form as might be specified to the \fBplace configure\fR
command.
.\" METHOD: slaves
.TP
\fBplace slaves \fIwindow\fR
.
Synonym for \fBplace content \fIwindow\fR.
Returns a list of all the slave windows for which \fIwindow\fR is the master.
If there are no slaves for \fIwindow\fR then an empty string is returned.
.PP
If the configuration of a window has been retrieved with
\fBplace info\fR, that configuration can be restored later by
first using \fBplace forget\fR to erase any existing information
for the window and then invoking \fBplace configure\fR with
the saved information.
.SH "FINE POINTS"
.PP
It is not necessary for the container window to be the parent
of the content window.
It is not necessary for the master window to be the parent
of the slave window.
This feature is useful in at least two situations.
First, for complex window layouts it means you can create a
hierarchy of subwindows whose only purpose
is to assist in the layout of the parent.
The
.QW "real children"
of the parent (i.e. the windows that
are significant for the application's user interface) can be
children of the parent yet be placed inside the windows
of the geometry-management hierarchy.
This means that the path names of the
.QW "real children"
do not reflect the geometry-management hierarchy and users
can specify options for the real children
without being aware of the structure of the geometry-management
hierarchy.
.PP
A second reason for having a container different than the content's
A second reason for having a master different than the slave's
parent is to tie two siblings together.
For example, the placer can be used to force a window always to
be positioned centered just below one of its
siblings by specifying the configuration
.CS
\fB\-in \fIsibling\fB \-relx 0.5 \-rely 1.0 \-anchor n \-bordermode outside\fR
.CE
Whenever the sibling is repositioned in the future, the content
Whenever the sibling is repositioned in the future, the slave
will be repositioned as well.
.PP
Unlike many other geometry managers (such as the packer)
the placer does not make any attempt to manipulate the geometry of
the container windows or the parents of content windows (i.e. it does not
the master windows or the parents of slave windows (i.e. it does not
set their requested sizes).
To control the sizes of these windows, make them windows like
frames and canvases that provide configuration options for this purpose.
.SH EXAMPLE
.PP
Make the label occupy the middle bit of the toplevel, no matter how it
is resized:
.CS
label .l -text "In the\enMiddle!" -bg black -fg white
\fBplace\fR .l -relwidth .3 -relx .35 -relheight .3 -rely .35
label .l \-text "In the\enMiddle!" \-bg black \-fg white
\fBplace\fR .l \-relwidth .3 \-relx .35 \-relheight .3 \-rely .35
.CE
.SH "SEE ALSO"
grid(n), pack(n)
.SH KEYWORDS
geometry manager, height, location, container, place, rubber sheet,
geometry manager, height, location, master, place, rubber sheet, slave, width
content, width
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/popup.n.

27
28
29
30
31
32
33
34
35


36
37
38

39
40
41

42
43
44
45
46
47
48
27
28
29
30
31
32
33


34
35
36
37

38
39
40

41
42
43
44
45
46
47
48







-
-
+
+


-
+


-
+







the given point.
.SH EXAMPLE
.PP
How to attach a simple popup menu to a widget.
.CS
# Create a menu
set m [menu .popupMenu]
$m add command -label "Example 1" -command bell
$m add command -label "Example 2" -command bell
$m add command \-label "Example 1" \-command bell
$m add command \-label "Example 2" \-command bell

# Create something to attach it to
pack [label .l -text "Click me!"]
pack [label .l \-text "Click me!"]

# Arrange for the menu to pop up when the label is clicked
bind .l <Button-1> {\fBtk_popup\fR .popupMenu %X %Y}
bind .l <1> {\fBtk_popup\fR .popupMenu %X %Y}
.CE
.SH "SEE ALSO"
bind(n), menu(n), tk_optionMenu(n)
.SH KEYWORDS
menu, popup
'\" Local Variables:
'\" mode: nroff

Deleted doc/print.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62






























































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
.\" Text automatically generated by txt2man
'\"
'\" Copyright (c) 2021 Kevin Walzer/WordTech Communications LLC.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.

.TH tk print n "" Tk "Tk Built-in Commands"
.so man.macros
.SH NAME
print \- Print canvas and text widgets using native dialogs and APIs.
.SH SYNOPSIS
\fBtk print \fIwindow\fR
.
.SH DESCRIPTION
.PP
The \fBtk print\fR command posts a dialog that allows users to print output
from the \fBcanvas\fR and \fBtext\fR widgets. The printing will be done using
platform-native APIs and dialogs where available.
.PP
The \fBcanvas\fR widget has long supported PostScript export and both
PostScript and text files can be sent directly to a printer on Unix-like
systems using the
.QW "lp"
and
.QW "lpr"
Unix commands, and the \fBtk print\fR command does not supersede that
functionality; it builds on it. The \fBtk print\fR command is a fuller
implementation that uses native dialogs on macOS and Windows, and a Tk-based
dialog that provides parallel functionality on X11.
.SH PLATFORM NOTES
.TP
\fBmacOS\fR
.
The Mac implementation uses native print dialogs and relies on the underlying
Common Unix Printing System (CUPS) to render text output from the text widget
and PDF conversion of the canvas data to the printer or to a PDF file.
.TP
\fBWindows\fR
.
The Windows implementation is based on the GDI (Graphics Device Interface)
API. Because there are slight differences in how GDI and Tk's \fBcanvas\fR
widget display graphics, printed output from the \fBcanvas\fR on Windows may
not be identical to screen rendering.
.TP
\fBX11\fR
.
The X11 implementation uses a Tk GUI to configure print jobs for sending to a
printer via the
.QW "lpr"
or
.QW "lp"
commands. While these commands have a large number of parameters for
configuring print jobs, printers vary widely in how they support these
parameters. As a result, only printer selection and number of copies are
configured as arguments to the print command; many aspects of print rendering,
such as grayscale or color for the canvas, are instead configured when
PostScript is generated.
.SH "SEE ALSO"
canvas(n), text(n), tk(n)
.SH KEYWORDS
print, output, graphics, text, canvas

Changes to doc/radiobutton.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH radiobutton n 4.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
radiobutton \- Create and manipulate 'radiobutton' pick-one widgets
.SH SYNOPSIS
\fBradiobutton\fI pathName \fR?\fIoptions\fR?
\fBradiobutton\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-disabledforeground	\-padx
\-activeforeground	\-font	\-pady
\-anchor	\-foreground	\-relief
\-background	\-highlightbackground	\-takefocus
\-bitmap	\-highlightcolor	\-text
\-borderwidth	\-highlightthickness	\-textvariable
37
38
39
40
41
42
43










44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73









74
75
76
77
78
79
80







+
+
+
+
+
+
+
+
+
+




















-
-
-
-
-
-
-
-
-







If this option is not specified, the button's desired height is computed
from the size of the image or bitmap or text being displayed in it.
.OP \-indicatoron indicatorOn IndicatorOn
Specifies whether or not the indicator should be drawn.  Must be a
proper boolean value.  If false, the \fB\-relief\fR option is
ignored and the widget's relief is always sunken if the widget is
selected and raised otherwise.
.OP \-selectcolor selectColor Background
Specifies a background color to use when the button is selected.
If \fB\-indicatoron\fR is true then the color applies to the indicator.
Under Windows, this color is used as the background for the indicator
regardless of the select state.
If \fB\-indicatoron\fR is false, this color is used as the background
for the entire widget, in place of \fB\-background\fR or \fB\-activeBackground\fR,
whenever the widget is selected.
If specified as an empty string then no special color is used for
displaying when the widget is selected.
.OP \-offrelief offRelief OffRelief
Specifies the relief for the checkbutton when the indicator is not drawn and
the checkbutton is off.  The default value is
.QW raised .
By setting this option to
.QW flat
and setting \fB\-indicatoron\fR to false and \fB\-overrelief\fR to
.QW raised ,
the effect is achieved
of having a flat button that raises on mouse-over and which is
depressed when activated.  This is the behavior typically exhibited by
the Align-Left, Align-Right, and Center radiobuttons on the toolbar of a
word-processor, for example.
.OP \-overrelief overRelief OverRelief
Specifies an alternative relief for the radiobutton, to be used when the
mouse cursor is over the widget.  This option can be used to make
toolbar buttons, by configuring \fB\-relief flat \-overrelief
raised\fR.  If the value of this option is the empty string, then no
alternative relief is used when the mouse cursor is over the radiobutton.
The empty string is the default value.
.OP \-selectcolor selectColor Background
Specifies a background color to use when the button is selected.
If \fBindicatorOn\fR is true then the color is used as the background for
the indicator regardless of the select state.
If \fB\-indicatoron\fR is false, this color is used as the background for the
entire widget, in place of \fB\-background\fR or \fB\-activeBackground\fR,
whenever the widget is selected.
If specified as an empty string then no special color is used for
displaying when the widget is selected.
.OP \-selectimage selectImage SelectImage
Specifies an image to display (in place of the \fB\-image\fR option)
when the radiobutton is selected.
This option is ignored unless the \fB\-image\fR option has been
specified.
.OP \-state state State
Specifies one of three states for the radiobutton:  \fBnormal\fR, \fBactive\fR,
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
173
174
175
176
177
178
179

180
181
182
183
184

185

186
187
188
189
190
191

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213

214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237







-
+




-

-
+





-















-







-








-









-







.SH "WIDGET COMMAND"
.PP
The \fBradiobutton\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for radiobutton widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBradiobutton\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBradiobutton\fR
command.
.\" METHOD: deselect
.TP
\fIpathName \fBdeselect\fR
.
Deselects the radiobutton and sets the associated variable to an
empty string.
If this radiobutton was not currently selected, the command has
no effect.
.\" METHOD: flash
.TP
\fIpathName \fBflash\fR
.
Flashes the radiobutton.  This is accomplished by redisplaying the radiobutton
several times, alternating between active and normal colors.  At
the end of the flash the radiobutton is left in the same normal/active
state as when the command was invoked.
This command is ignored if the radiobutton's state is \fBdisabled\fR.
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke\fR
.
Does just what would have happened if the user invoked the radiobutton
with the mouse: selects the button and invokes
its associated Tcl command, if there is one.
The return value is the return value from the Tcl command, or an
empty string if there is no command associated with the radiobutton.
This command is ignored if the radiobutton's state is \fBdisabled\fR.
.\" METHOD: select
.TP
\fIpathName \fBselect\fR
.
Selects the radiobutton and sets the associated variable to the
value corresponding to this widget.
.SH BINDINGS
.PP
259
260
261
262
263
264
265
266

267
268
269
270
271
272
254
255
256
257
258
259
260

261

262
263
264
265
266







-
+
-





.PP
If the radiobutton's state is \fBdisabled\fR then none of the above
actions occur:  the radiobutton is completely non-responsive.
.PP
The behavior of radiobuttons can be changed by defining new bindings for
individual widgets or by redefining the class bindings.
.SH "SEE ALSO"
checkbutton(n), labelframe(n), listbox(n), options(n), scale(n),
checkbutton(n), labelframe(n), listbox(n), options(n), scale(n), ttk::radiobutton(n)
ttk::radiobutton(n)
.SH KEYWORDS
radiobutton, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/raise.n.

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48





49
50
51
52
53
54
55
27
28
29
30
31
32
33



34
35
36
37
38
39
40





41
42
43
44
45
46
47
48
49
50
51
52







-
-
-







-
-
-
-
-
+
+
+
+
+







\fIwindow\fR into the stacking order just above \fIaboveThis\fR
(or the ancestor of \fIaboveThis\fR that is a sibling of \fIwindow\fR);
this could end up either raising or lowering \fIwindow\fR.
.PP
All \fBtoplevel\fR windows may be restacked with respect to each
other, whatever their relative path names, but the window manager is
not obligated to strictly honor requests to restack.
.PP
On macOS raising an iconified \fBtoplevel\fR window causes it to be
deiconified.
.SH EXAMPLE
.PP
Make a button appear to be in a sibling frame that was created after
it. This is is often necessary when building GUIs in the style where
you create your activity widgets first before laying them out on the
display:
.CS
button .b -text "Hi there!"
pack [frame .f -background blue]
pack [label .f.l1 -text "This is above"]
pack .b -in .f
pack [label .f.l2 -text "This is below"]
button .b \-text "Hi there!"
pack [frame .f \-background blue]
pack [label .f.l1 \-text "This is above"]
pack .b \-in .f
pack [label .f.l2 \-text "This is below"]
\fBraise\fR .b
.CE
.SH "SEE ALSO"
lower(n)
.SH KEYWORDS
obscure, raise, stacking order
'\" Local Variables:

Changes to doc/scale.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH scale n 4.1 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
scale \- Create and manipulate 'scale' value-controlled slider widgets
.SH SYNOPSIS
\fBscale\fI pathName \fR?\fIoptions\fR?
\fBscale\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-foreground	\-relief
\-background	\-highlightbackground	\-repeatdelay
\-borderwidth	\-highlightcolor	\-repeatinterval
\-cursor	\-highlightthickness	\-takefocus
\-font	\-orient	\-troughcolor
.SE
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







-
+







Specifies the desired long dimension of the scale in screen units
(i.e. any of the forms acceptable to \fBTk_GetPixels\fR).
For vertical scales this is the scale's height;  for horizontal scales
it is the scale's width.
.OP \-resolution resolution Resolution
A real value specifying the resolution for the scale.
If this value is greater than zero then the scale's value will always be
rounded to an even multiple of this value, as will
rounded to an even multiple of this value, as will tick marks and
the endpoints of the scale.  If the value is less than zero then no
rounding occurs.  Defaults to 1 (i.e., the value will be integral).
.OP \-showvalue showValue ShowValue
Specifies a boolean value indicating whether or not the current
value of the scale is to be displayed.
.OP \-sliderlength sliderLength SliderLength
Specifies the size of the slider, measured in screen units along the slider's
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99


100
101
102
103
104
105
106
74
75
76
77
78
79
80

81


82
83
84
85
86
87
88
89
90
91
92
93

94
95


96
97
98
99
100
101
102
103
104







-
+
-
-












-
+

-
-
+
+







If the scale is disabled then the value may not be changed and the scale
will not activate.
If the scale is active, the slider is displayed using the color
specified by the \fB\-activebackground\fR option.
.OP \-tickinterval tickInterval TickInterval
Must be a real value.
Determines the spacing between numerical
tick marks displayed below or to the left of the slider. The values will all
tick marks displayed below or to the left of the slider.
be displayed with the same number of decimal places, which will be enough to
ensure they are all accurate to within 20% of a tick interval.
If 0, no tick marks will be displayed.
.OP \-to to To
Specifies a real value corresponding
to the right or bottom end of the scale.
This value may be either less than or greater than the \fB\-from\fR option.
.OP \-variable variable Variable
Specifies the name of a global variable to link to the scale.  Whenever the
value of the variable changes, the scale will update to reflect this
value.
Whenever the scale is manipulated interactively, the variable
will be modified to reflect the scale's new value.
.OP \-width width Width
Specifies the desired narrow dimension of the scale in screen units
Specifies the desired narrow dimension of the trough in screen units
(i.e. any of the forms acceptable to \fBTk_GetPixels\fR).
For vertical scales this is the scale's width;  for horizontal scales
this is the scale's height.
For vertical scales this is the trough's width;  for horizontal scales
this is the trough's height.
.BE
.SH DESCRIPTION
.PP
The \fBscale\fR command creates a new window (given by the
\fIpathName\fR argument) and makes it into a scale widget.
Additional
options, described above, may be specified on the command line
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
134
135
136
137
138
139
140

141
142
143
144
145

146

147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202







-
+




-

-
+





-















-







-









-












-







.SH "WIDGET COMMAND"
.PP
The \fBscale\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for scale widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBscale\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBscale\fR
command.
.\" METHOD: coords
.TP
\fIpathName \fBcoords \fR?\fIvalue\fR?
.
Returns a list whose elements are the x and y coordinates of
the point along the centerline of the trough that corresponds
to \fIvalue\fR.
If \fIvalue\fR is omitted then the scale's current value is used.
.\" METHOD: get
.TP
\fIpathName \fBget\fR ?\fIx y\fR?
.
If \fIx\fR and \fIy\fR are omitted, returns the current value
of the scale.  If \fIx\fR and \fIy\fR are specified, they give
pixel coordinates within the widget;  the command returns
the scale value corresponding to the given pixel.
Only one of \fIx\fR or \fIy\fR is used:  for horizontal scales
\fIy\fR is ignored, and for vertical scales \fIx\fR is ignored.
.\" METHOD: identify
.TP
\fIpathName \fBidentify \fIx y\fR
.
Returns a string indicating what part of the scale lies under
the coordinates given by \fIx\fR and \fIy\fR.
A return value of \fBslider\fR means that the point is over
the slider;  \fBtrough1\fR means that the point is over the
portion of the slider above  or to the left of the slider;
and \fBtrough2\fR means that the point is over the portion
of the slider below or to the right of the slider.
If the point is not over one of these elements, an empty string
is returned.
.\" METHOD: set
.TP
\fIpathName \fBset \fIvalue\fR
.
This command is invoked to change the current value of the scale,
and hence the position at which the slider is displayed.  \fIValue\fR
gives the new value for the scale.
The command has no effect if the scale is disabled.

Changes to doc/scrollbar.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22







-
+







.TH scrollbar n 4.1 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
scrollbar \- Create and manipulate 'scrollbar' scrolling control and indicator widgets
.SH SYNOPSIS
\fBscrollbar\fI pathName \fR?\fIoptions\fR?
\fBscrollbar\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-highlightcolor	\-repeatdelay
\-background	\-highlightthickness	\-repeatinterval
\-borderwidth	\-jump	\-takefocus
\-cursor	\-orient	\-troughcolor
\-highlightbackground	\-relief
.SE
77
78
79
80
81
82
83

84

85

86

87

88

89

90

91

92

93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
77
78
79
80
81
82
83
84

85
86
87

88
89
90

91
92
93

94
95
96

97
98
99
100
101
102
103
104
105

106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174

175
176
177
178
179
180
181
182

183
184
185
186
187
188
189







+
-
+

+
-
+

+
-
+

+
-
+

+
-
+








-
+




-













-







-















-












-












-





-








-







Scrollbars can be used to adjust the view in the associated window
by clicking or dragging with the mouse.  See the \fBBINDINGS\fR section
below for details.
.SH "ELEMENTS"
.PP
A scrollbar displays five elements, which are referred to in the
widget commands for the scrollbar:
.TP 10
.IP \fBarrow1\fR 10
\fBarrow1\fR
The top or left arrow in the scrollbar.
.TP 10
.IP \fBtrough1\fR 10
\fBtrough1\fR
The region between the slider and \fBarrow1\fR.
.TP 10
.IP \fBslider\fR 10
\fBslider\fR
The rectangle that indicates what is visible in the associated widget.
.TP 10
.IP \fBtrough2\fR 10
\fBtrough2\fR
The region between the slider and \fBarrow2\fR.
.TP 10
.IP \fBarrow2\fR 10
\fBarrow2\fR
The bottom or right arrow in the scrollbar.
.SH "WIDGET COMMAND"
.PP
The \fBscrollbar\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for scrollbar widgets:
.\" METHOD: activate
.TP
\fIpathName \fBactivate \fR?\fIelement\fR?
.
Marks the element indicated by \fIelement\fR as active, which
causes it to be displayed as specified by the \fB\-activebackground\fR
and \fB\-activerelief\fR options.
The only element values understood by this command are \fBarrow1\fR,
\fBslider\fR, or \fBarrow2\fR.
If any other value is specified then no element of the scrollbar
will be active.
If \fIelement\fR is not specified, the command returns
the name of the element that is currently active, or an empty string
if no element is active.
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBscrollbar\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBscrollbar\fR
command.
.\" METHOD: delta
.TP
\fIpathName \fBdelta \fIdeltaX deltaY\fR
.
Returns a real number indicating the fractional change in
the scrollbar setting that corresponds to a given change
in slider position.  For example, if the scrollbar is horizontal,
the result indicates how much the scrollbar setting must change
to move the slider \fIdeltaX\fR pixels to the right (\fIdeltaY\fR is
ignored in this case).
If the scrollbar is vertical, the result indicates how much the
scrollbar setting must change to move the slider \fIdeltaY\fR pixels
down.  The arguments and the result may be zero or negative.
.\" METHOD: fraction
.TP
\fIpathName \fBfraction \fIx y\fR
.
Returns a real number between 0 and 1 indicating where the point
given by \fIx\fR and \fIy\fR lies in the trough area of the scrollbar.
The value 0 corresponds to the top or left of the trough, the
value 1 corresponds to the bottom or right, 0.5 corresponds to
the middle, and so on.
\fIX\fR and \fIy\fR must be pixel coordinates relative to the scrollbar
widget.
If \fIx\fR and \fIy\fR refer to a point outside the trough, the closest
point in the trough is used.
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the scrollbar settings in the form of a list whose
elements are the arguments to the most recent \fBset\fR widget command.
.\" METHOD: identify
.TP
\fIpathName \fBidentify \fIx y\fR
.
Returns the name of the element under the point given by \fIx\fR and
\fIy\fR (such as \fBarrow1\fR), or an empty string if the point does
not lie in any element of the scrollbar.
\fIX\fR and \fIy\fR must be pixel coordinates relative to the scrollbar
widget.
.\" METHOD: set
.TP
\fIpathName \fBset \fIfirst last\fR
.
This command is invoked by the scrollbar's associated widget to
tell the scrollbar about the current view in the widget.
The command takes two arguments, each of which is a real fraction
between 0 and 1.
202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218
219
220

221








222
223
224
225
226
227
228
229
230
231
232









233


234
235
236











237
238



239
240
241









242
243






244
245
246
247
248
249
250
199
200
201
202
203
204
205

206

207
208
209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
242
243
244
245
246



247
248
249
250
251
252
253
254
255
256
257


258
259
260



261
262
263
264
265
266
267
268
269


270
271
272
273
274
275
276
277
278
279
280
281
282







-
+
-










+
-
+
+
+
+
+
+
+
+









-
-
+
+
+
+
+
+
+
+
+

+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+







the slider, the scrollbar notifies the associated widget that it
must change its view.
The scrollbar makes the notification by evaluating a Tcl command
generated from the scrollbar's \fB\-command\fR option.
The command may take any of the following forms.
In each case, \fIprefix\fR is the contents of the
\fB\-command\fR option, which usually has a form like
.QW "\fB.t yview\fR" .
.QW \fB.t yview\fR .
.\" METHOD: moveto
.TP
\fIprefix \fBmoveto \fIfraction\fR
.
\fIFraction\fR is a real number between 0 and 1.
The widget should adjust its view so that the point given
by \fIfraction\fR appears at the beginning of the widget.
If \fIfraction\fR is 0 it refers to the beginning of the
document.  1.0 refers to the end of the document, 0.333
refers to a point one-third of the way through the document,
and so on.
.TP
.\" METHOD: scroll
\fIprefix \fBscroll \fInumber \fBunits\fR
.
The widget should adjust its view by \fInumber\fR units.
The units are defined in whatever way makes sense for the widget,
such as characters or lines in a text widget.
\fINumber\fR is either 1, which means one unit should scroll off
the top or left of the window, or \-1, which means that one unit
should scroll off the bottom or right of the window.
.TP
\fIprefix \fBscroll \fInumber \fBpages\fR
.
The widget should adjust its view by \fInumber\fR pages.
It is up to the widget to define the meaning of a page;  typically
it is slightly less than what fits in the window, so that there
is a slight overlap between the old and new views.
\fINumber\fR is either 1, which means the next page should
become visible, or \-1, which means that the previous page should
become visible. Fractional numbers are rounded away from 0, so
scrolling 0.001 pages has the same effect as scrolling 1 page.
become visible.
.SH "OLD COMMAND SYNTAX"
.PP
In versions of Tk before 4.0, the \fBset\fR and \fBget\fR widget
commands used a different form.
This form is still supported for backward compatibility, but it
is deprecated.
In the old command syntax, the \fBset\fR widget command has the
following form:
.TP
\fIpathName \fBset \fItotalUnits windowUnits firstUnit lastUnit\fR
In this form the arguments are all integers.
\fIprefix \fBscroll \fInumber \fBunits\fR
.
The widget should adjust its view by \fInumber\fR units.
\fITotalUnits\fR gives the total size of the object being displayed in the
associated widget.  The meaning of one unit depends on the associated
widget;  for example, in a text editor widget units might
correspond to lines of
text.  \fIWindowUnits\fR indicates the total number of units that
can fit in the associated window at one time.  \fIFirstUnit\fR
and \fIlastUnit\fR give the indices of the first and last units
currently visible in the associated window (zero corresponds to the
first unit of the object).
.LP
Under the old syntax the \fBget\fR widget command returns a list
The units are defined in whatever way makes sense for the widget,
such as characters or lines in a text widget.
of four integers, consisting of the \fItotalUnits\fR, \fIwindowUnits\fR,
\fIfirstUnit\fR, and \fIlastUnit\fR values from the last \fBset\fR
widget command.
\fINumber\fR is either 1, which means one unit should scroll off
the top or left of the window, or \-1, which means that one unit
should scroll off the bottom or right of the window. Fractional
.PP
The commands generated by scrollbars also have a different form
when the old syntax is being used:
.TP
\fIprefix\fR \fIunit\fR
\fIUnit\fR is an integer that indicates what should appear at
the top or left of the associated widget's window.
It has the same meaning as the \fIfirstUnit\fR and \fIlastUnit\fR
arguments to the \fBset\fR widget command.
numbers are rounded away from 0, so scrolling 0.001 units has
the same effect as scrolling 1 unit.
.LP
The most recent \fBset\fR widget command determines whether or not
to use the old syntax.
If it is given two real arguments then the new syntax will be
used in the future, and if it is given four integer arguments then
the old syntax will be used.
.SH BINDINGS
.PP
Tk automatically creates class bindings for scrollbars that give them
the following default behavior.
If the behavior is different for vertical and horizontal scrollbars,
the horizontal behavior is described in parentheses.
.IP [1]
309
310
311
312
313
314
315
316
317
318
319
320





321
322
323
324
325
326
327
328
341
342
343
344
345
346
347





348
349
350
351
352
353
354
355
356
357
358
359
360







-
-
-
-
-
+
+
+
+
+








.IP [14]
The End key adjusts the view to the bottom (right edge) of the document.
.SH EXAMPLE
.PP
Create a window with a scrollable \fBtext\fR widget:
.CS
toplevel .tl
text .tl.t -yscrollcommand {.tl.s set}
\fBscrollbar\fR .tl.s -command {.tl.t yview}
grid .tl.t .tl.s -sticky nsew
grid columnconfigure .tl 0 -weight 1
grid rowconfigure .tl 0 -weight 1
text .tl.t \-yscrollcommand {.tl.s set}
\fBscrollbar\fR .tl.s \-command {.tl.t yview}
grid .tl.t .tl.s \-sticky nsew
grid columnconfigure .tl 0 \-weight 1
grid rowconfigure .tl 0 \-weight 1
.CE
.SH "SEE ALSO"
ttk:scrollbar(n)
.SH KEYWORDS
scrollbar, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/selection.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28

29

30
31
32
33
34
35
36
37
38
39

40

41
42
43
44
45
46
47
48







-
+













-

-
+









-

-
+







.TH selection n 8.1 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
selection \- Manipulate the X selection
.SH SYNOPSIS
\fBselection \fIoption\fR ?\fIarg ...\fR?
\fBselection \fIoption\fR ?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
This command provides a Tcl interface to the X selection mechanism and
implements the full selection functionality described in the
X Inter-Client Communication Conventions Manual (ICCCM).
.PP
Note that for management of the \fBCLIPBOARD\fR selection (see below), the
\fBclipboard\fR command may also be used.
.PP
The first argument to \fBselection\fR determines the format of the
rest of the arguments and the behavior of the command.  The following
forms are currently supported:
.\" METHOD: clear
.TP
\fBselection clear\fR ?\fB\-displayof\fI window\fR? ?\fB\-selection\fI selection\fR?
\fBselection clear\fR ?\fB\-displayof\fR \fIwindow\fR? ?\fB\-selection\fR \fIselection\fR?
.
If \fIselection\fR exists anywhere on \fIwindow\fR's display, clear it
so that no window owns the selection anymore.  \fISelection\fR
specifies the X selection that should be cleared, and should be an
atom name such as \fBPRIMARY\fR or \fBCLIPBOARD\fR; see the Inter-Client
Communication Conventions Manual for complete details.
\fISelection\fR defaults to \fBPRIMARY\fR and \fIwindow\fR defaults to
.QW . .
Returns an empty string.
.\" METHOD: get
.TP
\fBselection get\fR ?\fB\-displayof\fI window\fR? ?\fB\-selection\fI selection\fR? ?\fB\-type\fI type\fR?
\fBselection get\fR ?\fB\-displayof\fR \fIwindow\fR? ?\fB\-selection\fR \fIselection\fR? ?\fB\-type\fR \fItype\fR?
.
Retrieves the value of \fIselection\fR from \fIwindow\fR's display and
returns it as a result.  \fISelection\fR defaults to \fBPRIMARY\fR and
\fIwindow\fR defaults to
.QW . .
\fIType\fR specifies the form in which the selection is to be returned
(the desired
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
57
58
59
60
61
62
63

64

65
66
67
68
69
70
71
72







-

-
+







than the selection type; see the ICCCM for all the confusing details).
If the selection is returned in a non-string format, such as \fBINTEGER\fR
or \fBATOM\fR, the \fBselection\fR command converts it to string format as a
collection of fields separated by spaces: atoms are converted to their
textual names, and anything else is converted to hexadecimal integers.
Note that \fBselection get\fR does not retrieve the selection in the
\fBUTF8_STRING\fR format unless told to.
.\" METHOD: handle
.TP
\fBselection handle\fR ?\fB\-selection\fI s\fR? ?\fB\-type\fI t\fR? ?\fB\-format\fI f\fR? \fIwindow command\fR
\fBselection handle\fR ?\fB\-selection\fR \fIs\fR? ?\fB\-type\fR \fIt\fR? ?\fB\-format\fR \fIf\fR? \fIwindow command\fR
.
Creates a handler for selection requests, such that \fIcommand\fR will
be executed whenever selection \fIs\fR is owned by \fIwindow\fR and
someone attempts to retrieve it in the form given by type \fIt\fR
(e.g. \fIt\fR is specified in the \fBselection get\fR command).
\fIS\fR defaults to \fBPRIMARY\fR, \fIt\fR defaults to \fBSTRING\fR, and
\fIf\fR defaults to \fBSTRING\fR.  If \fIcommand\fR is an empty string
118
119
120
121
122
123
124
125
126
127

128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
115
116
117
118
119
120
121

122

123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142







































143
144
145
146
147
148
149

150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186







-

-
+

-
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+






-
+









-
+







-
+











.PP
The \fIformat\fR argument is needed only for compatibility with
selection requesters that do not use Tk.  If Tk is being
used to retrieve the selection then the value is converted back to
a string at the requesting end, so \fIformat\fR is
irrelevant.
.RE
.\" METHOD: own
.TP
\fBselection own\fR ?\fB\-displayof\fI window\fR? ?\fB\-selection\fI selection\fR?
\fBselection own\fR ?\fB\-displayof\fR \fIwindow\fR? ?\fB\-selection\fR \fIselection\fR?
.TP
\fBselection own\fR ?\fB\-command\fI command\fR? ?\fB\-selection\fI selection\fR? \fIwindow\fR
\fBselection own\fR ?\fB\-command\fR \fIcommand\fR? ?\fB\-selection\fR \fIselection\fR? \fIwindow\fR
.
The first form of \fBselection own\fR returns the path name of the
window in this application that owns \fIselection\fR on the display
containing \fIwindow\fR, or an empty string if no window in this
application owns the selection.  \fISelection\fR defaults to \fBPRIMARY\fR and
\fIwindow\fR defaults to
.QW . .
.RS
.PP
The second form of \fBselection own\fR causes \fIwindow\fR to become
the new owner of \fIselection\fR on \fIwindow\fR's display, returning
an empty string as result. The existing owner, if any, is notified
that it has lost the selection.
If \fIcommand\fR is specified, it is a Tcl script to execute when
some other window claims ownership of the selection away from
\fIwindow\fR.  \fISelection\fR defaults to PRIMARY.
.RE
.SH WIDGET FACILITIES
.PP
The \fBtext\fR, \fBentry\fR, \fBttk::entry\fR, \fBlistbox\fR, \fBspinbox\fR
and \fBttk::spinbox\fR widgets have the option \fB\-exportselection\fR.  If a
widget has this option set to boolean \fBtrue\fR, then (in an unsafe
interpreter) a selection made in the widget is automatically written to the
\fBPRIMARY\fR selection.
.PP
A GUI event, for example \fB<<PasteSelection>>\fR, can copy the \fBPRIMARY\fR
selection to certain widgets.  This copy is implemented by a widget binding to
the event.  The binding script makes appropriate calls to the \fBselection\fR
command.
.PP
.SH PORTABILITY ISSUES
.PP
On X11, the \fBPRIMARY\fR selection is a system-wide feature of the X server,
allowing communication between different processes that are X11 clients.
.PP
On Windows, the \fBPRIMARY\fR selection is not provided by the system, but
only by Tk, and so it is shared only between windows of a parent interpreter
and its child interpreters.  It is not shared between interpreters in
different processes or different threads.  Each parent interpreter has a
separate \fBPRIMARY\fR selection that is shared only with its child
interpreters which are not safe interpreters.
.PP
.SH SECURITY
.PP
A safe interpreter cannot read from the \fBPRIMARY\fR selection because its
\fBselection\fR command is hidden.  For this reason the \fBPRIMARY\fR
selection cannot be written to the Tk widgets of a safe interpreter.
.PP
A Tk widget can have its option \fB\-exportselection\fR set to boolean
\fBtrue\fR, but in a safe interpreter this option has no effect: writing
from the widget to the \fBPRIMARY\fR selection is disabled.
.PP
These are security features.  A safe interpreter may run untrusted code, and
it is a security risk if this untrusted code can read or write the
\fBPRIMARY\fR selection used by other interpreters.
.PP
.SH EXAMPLES
.PP
On X11 platforms, one of the standard selections available is the
\fBSECONDARY\fR selection. Hardly anything uses it, but here is how to read
it using Tk:
.PP
.CS
set selContents [\fBselection get\fR -selection SECONDARY]
set selContents [\fBselection get\fR \-selection SECONDARY]
.CE
.PP
Many different types of data may be available for a selection; the
special type \fBTARGETS\fR allows you to get a list of available types:
.PP
.CS
foreach type [\fBselection get\fR -type TARGETS] {
foreach type [\fBselection get\fR \-type TARGETS] {
   puts "Selection PRIMARY supports type $type"
}
.CE
.PP
To claim the selection, you must first set up a handler to supply the
data for the selection. Then you have to claim the selection...
.CS
# Set up the data handler ready for incoming requests
set foo "This is a string with some data in it... blah blah"
\fBselection handle\fR -selection SECONDARY . getData
\fBselection handle\fR \-selection SECONDARY . getData
proc getData {offset maxChars} {
   puts "Retrieving selection starting at $offset"
   return [string range $::foo $offset [expr {$offset+$maxChars-1}]]
}

# Now we grab the selection itself
puts "Claiming selection"
\fBselection own\fR -command lost -selection SECONDARY .
\fBselection own\fR \-command lost \-selection SECONDARY .
proc lost {} {
   puts "Lost selection"
}
.CE
.SH "SEE ALSO"
clipboard(n)
.SH KEYWORDS
clear, format, handler, ICCCM, own, selection, target, type
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/send.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34

35
36
37
38
39
40

41

42

43
44
45

46
47

48
49
50
51
52
53
54







-
+

















-


-






-

-
+
-



-


-







.TH send n 4.0 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
send \- Execute a command in a different application
.SH SYNOPSIS
\fBsend ?\fIoptions\fR? \fIapp cmd \fR?\fIarg ...\fR?
\fBsend ?\fIoptions\fR? \fIapp cmd \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
This command arranges for \fIcmd\fR (and \fIarg\fRs) to be executed in the
application named by \fIapp\fR.  It returns the result or
error from that command execution.
\fIApp\fR may be the name of any application whose main window is
on the display containing the sender's main window;  it need not
be within the same process.
If no \fIarg\fR arguments are present, then the command to be executed is
contained entirely within the \fIcmd\fR argument.  If one or
more \fIarg\fRs are present, they are concatenated to form the
command to be executed, just as for the \fBeval\fR command.
.PP
If the initial arguments of the command begin with
.QW \-
they are treated as options.  The following options are currently defined:
.\" OPTION: -async
.TP
\fB\-async\fR
.
Requests asynchronous invocation.  In this case the \fBsend\fR
command will complete immediately without waiting for \fIcmd\fR
to complete in the target application;  no result will be available
and errors in the sent command will be ignored.
If the target application is in the same process as the sending
application then the \fB\-async\fR option is ignored.
.\" OPTION: -displayof
.TP
\fB\-displayof\fI pathName\fR
\fB\-displayof\fR \fIpathName\fR
.
Specifies that the target application's main window is on the display
of the window given by \fIpathName\fR, instead of the display containing
the application's main window.
.\" OPTION: --
.TP
\fB\-\|\-\fR
.
Serves no purpose except to terminate the list of options.  This
option is needed only if \fIapp\fR could contain a leading
.QW \-
character.
.SH "APPLICATION NAMES"
.PP
The name of an application is set initially from the name of the
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100







-
+







functionality is provided by the \fBdde\fR command instead.
.SH EXAMPLE
.PP
This script fragment can be used to make an application that only runs
once on a particular display.
.CS
if {[tk appname FoobarApp] ne "FoobarApp"} {
    \fBsend\fR -async FoobarApp RemoteStart $argv
    \fBsend\fR \-async FoobarApp RemoteStart $argv
    exit
}
# The command that will be called remotely, which raises
# the application main window and opens the requested files
proc RemoteStart args {
    raise .
    foreach filename $args {

Changes to doc/spinbox.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32







-
+










-







.TH spinbox n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
spinbox \- Create and manipulate 'spinbox' value spinner widgets
.SH SYNOPSIS
\fBspinbox\fI pathName \fR?\fIoptions\fR?
\fBspinbox\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-activebackground	\-highlightthickness	\-repeatinterval
\-background	\-insertbackground	\-selectbackground
\-borderwidth	\-insertborderwidth	\-selectborderwidth
\-cursor	\-insertontime	\-selectforeground
\-exportselection	\-insertwidth	\-takefocus
\-font	\-insertofftime	\-textvariable
\-foreground	\-justify	\-xscrollcommand
\-highlightbackground	\-relief
\-highlightcolor	\-repeatdelay
\-placeholder	\-placeholderforeground
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-buttonbackground buttonBackground Background
The background color to be used for the spin buttons.
.OP \-buttoncursor buttonCursor Cursor
The cursor to be used when over the spin buttons.  If this is empty
(the default), a default cursor will be used.
164
165
166
167
168
169
170
171
172


173
174
175
176
177
178
179
163
164
165
166
167
168
169


170
171
172
173
174
175
176
177
178







-
-
+
+







The \fB\-validatecommand\fR will be called when the spinbox loses focus.
.IP \fBkey\fR 10
The \fB\-validatecommand\fR will be called when the spinbox is edited.
.IP \fBall\fR 10
The \fB\-validatecommand\fR will be called for all above conditions.
.PP
It is possible to perform percent substitutions on the \fB\-validatecommand\fR
and \fB\-invalidcommand\fR scripts, just as you would in a \fBbind\fR script.
The following substitutions are recognized:
and \fB\-invalidcommand\fR scripts, just as you would in a \fBbind\fR script.  The
following substitutions are recognized:
.PP
.IP \fB%d\fR 5
Type of action: 1 for \fBinsert\fR, 0 for \fBdelete\fR,
or \-1 for focus, forced or textvariable validation.
.IP \fB%i\fR 5
Index of char string to be inserted/deleted, if any, otherwise \-1.
.IP \fB%P\fR 5
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225



226
227

228
229
230


231
232
233
234
235

236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526

527
528

529


530
531


532
533
534
535
536
537
538
539
540
541
542
208
209
210
211
212
213
214

215
216
217
218
219
220
221



222
223
224
225

226
227


228
229
230
231
232
233

234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251

252
253
254
255

256
257
258
259

260
261
262
263
264

265
266
267
268

269
270
271
272

273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289



290
291
292

293
294

295
296
297
298
299
300
301
302

303

304

305
306
307
308

309
310

311
312
313
314
315
316
317
318
319
320
321
322

323
324

325
326
327
328
329
330
331

332
333

334

335
336

337
338

339
340

341
342
343

344
345

346

347
348

349
350

351
352

353
354

355

356

357
358
359
360
361

362
363
364
365
366
367

368
369
370
371
372
373
374
375

376
377

378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398

399
400
401
402

403
404
405
406
407

408
409
410
411

412
413
414
415
416
417
418

419
420
421
422
423
424
425
426
427
428
429
430
431

432
433

434
435
436

437
438

439
440
441
442

443
444

445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460

461
462
463
464

465
466
467
468
469

470
471

472


473
474
475
476


477
478
479
480


481
482
483
484
485
486
487







-
+






-
-
-
+
+
+

-
+

-
-
+
+




-
+






-
+










-




-




-





-




-




-





-












-
-
-



-


-








-

-
+
-




-


-












-


-







-


-

-


-


-


-



-


-

-


-


-


-


-

-
+
-





-






-








-


-





-











-





-




-





-




-







-













-


-



-


-




-


-






-










-




-





-


-
+
-
-
+

+
+
-
-
+
+


-
-







\fB\-validate\fR option will also set itself to \fBnone\fR when you edit the
spinbox widget from within either the \fB\-validatecommand\fR or the
\fB\-invalidcommand\fR.  Such editions will override the one that was being
validated.  If you wish to edit the value of the widget
during validation and still have the \fB\-validate\fR option set, you should
include the command
.CS
     \fI%W config -validate %v\fR
     \fI%W config \-validate %v\fR
.CE
in the \fB\-validatecommand\fR or \fB\-invalidcommand\fR (whichever one you
were editing the spinbox widget from).  It is also recommended to not set an
associated \fB\-textvariable\fR during validation, as that can cause the
spinbox widget to become out of sync with the \fB\-textvariable\fR.
.PP
Also, the \fB\-validate\fR option will set itself to \fBnone\fR when the
spinbox value gets changed because of adjustment of \fB\-from\fR or \fB\-to\fR
and the \fB\-validatecommand\fR returns false. For instance
Also, the \fB-validate\fR option will set itself to \fBnone\fR when the
spinbox value gets changed because of adjustment of \fB-from\fR or \fB-to\fR
and the \fB-validatecommand\fR returns false. For instance
.CS
     \fIspinbox pathName -from 1 -to 10 -validate all -validatecommand {return 0}\fR
     \fIspinbox pathName \-from 1 \-to 10 \-validate all \-vcmd {return 0}\fR
.CE
will in fact set the \fB\-validate\fR option to \fBnone\fR because the default
value for the spinbox gets changed (due to the \fB\-from\fR and \fB\-to\fR
will in fact set the \fB-validate\fR option to \fBnone\fR because the default
value for the spinbox gets changed (due to the \fB-from\fR and \fB-to\fR
options) to a value not accepted by the validation script.
.PP
Moreover, forced validation is performed when invoking any spinbutton of
the spinbox. If the validation script returns false in this situation,
then the \fB\-validate\fR option will be automatically set to \fBnone\fR.
then the \fB-validate\fR option will be automatically set to \fBnone\fR.
.SH "WIDGET COMMAND"
.PP
The \fBspinbox\fR command creates a new Tcl command whose
name is \fIpathName\fR.  This command may be used to invoke various
operations on the widget.  It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.
.SS INDICES
.PP
Many of the widget commands for spinboxes take one or more indices as
arguments.  An index specifies a particular character in the spinbox's
string, in any of the following ways:
.TP 12
\fInumber\fR
.
Specifies the character as a numerical index, where 0 corresponds
to the first character in the string.
.TP 12
\fBanchor\fR
.
Indicates the anchor point for the selection, which is set with the
\fBselect from\fR and \fBselect adjust\fR widget commands.
.TP 12
\fBend\fR
.
Indicates the character just after the last one in the spinbox's string.
This is equivalent to specifying a numerical index equal to the length
of the spinbox's string.
.TP 12
\fBinsert\fR
.
Indicates the character adjacent to and immediately following the
insertion cursor.
.TP 12
\fBsel.first\fR
.
Indicates the first character in the selection.  It is an error to
use this form if the selection is not in the spinbox window.
.TP 12
\fBsel.last\fR
.
Indicates the character just after the last one in the selection.
It is an error to use this form if the selection is not in the
spinbox window.
.TP 12
\fB@\fInumber\fR
.
In this form, \fInumber\fR is treated as an x-coordinate in the
spinbox's window;  the character spanning that x-coordinate is used.
For example,
.QW \fB@0\fR
indicates the left-most character in the window.
.LP
Abbreviations may be used for any of the forms above, e.g.
.QW \fBe\fR
or
.QW \fBsel.f\fR .
In general, out-of-range indices are automatically rounded to the
nearest legal value.
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.SS SUBCOMMANDS
.PP
The following commands are possible for spinbox widgets:
.\" METHOD: bbox
.TP
\fIpathName \fBbbox \fIindex\fR
.
Returns a list of four numbers describing the bounding box of the
character given by \fIindex\fR.
The first two elements of the list give the x and y coordinates of
the upper-left corner of the screen area covered by the character
(in pixels relative to the widget) and the last two elements give
the width and height of the character, in pixels.
The bounding box may refer to a region outside the visible area
of the window.
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBspinbox\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBspinbox\fR
command.
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fIfirst \fR?\fIlast\fR?
.
Delete one or more elements of the spinbox.
\fIFirst\fR is the index of the first character to delete, and
\fIlast\fR is the index of the character just after the last
one to delete.
If \fIlast\fR is not specified it defaults to \fIfirst\fR+1,
i.e. a single character is deleted.
This command returns an empty string.
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the spinbox's string.
.\" METHOD: icursor
.TP
\fIpathName \fBicursor \fIindex\fR
.
Arrange for the insertion cursor to be displayed just before the character
given by \fIindex\fR.  Returns an empty string.
.\" METHOD: identify
.TP
\fIpathName \fBidentify\fI x y\fR
.
Returns the name of the window element corresponding to coordinates
\fIx\fR and \fIy\fR in the spinbox.  Return value is one of:
\fBnone\fR, \fBbuttondown\fR, \fBbuttonup\fR, \fBentry\fR.
.\" METHOD: index
.TP
\fIpathName \fBindex\fI index\fR
.
Returns the numerical index corresponding to \fIindex\fR.
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex string\fR
.
Insert the characters of \fIstring\fR just before the character
indicated by \fIindex\fR.  Returns an empty string.
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke\fI element\fR
.
Causes the specified element, either \fBbuttondown\fR or \fBbuttonup\fR,
to be invoked, triggering the action associated with it.
.\" METHOD: scan
.TP
\fIpathName \fBscan\fI option args\fR
\fIpathName \fBscan\fR \fIoption args\fR
.
This command is used to implement scanning on spinboxes.  It has
two forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBscan mark \fIx\fR
.
Records \fIx\fR and the current view in the spinbox window;  used in
conjunction with later \fBscan dragto\fR commands.  Typically this
command is associated with a mouse button press in the widget.  It
returns an empty string.
.TP
\fIpathName \fBscan dragto \fIx\fR
.
This command computes the difference between its \fIx\fR argument
and the \fIx\fR argument to the last \fBscan mark\fR command for
the widget.  It then adjusts the view left or right by 10 times the
difference in x-coordinates.  This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the spinbox at high speed through the window.  The return
value is an empty string.
.RE
.\" METHOD: selection
.TP
\fIpathName \fBselection \fIoption arg\fR
.
This command is used to adjust the selection within a spinbox.  It
has several forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBselection adjust \fIindex\fR
.
Locate the end of the selection nearest to the character given by
\fIindex\fR, and adjust that end of the selection to be at \fIindex\fR
(i.e. including but not going beyond \fIindex\fR).  The other
end of the selection is made the anchor point for future
\fBselect to\fR commands.  If the selection
is not currently in the spinbox, then a new selection is created to
include the characters between \fIindex\fR and the most recent
selection anchor point, inclusive.
Returns an empty string.
.TP
\fIpathName \fBselection clear\fR
.
Clear the selection if it is currently in this widget.  If the
selection is not in this widget then the command has no effect.
Returns an empty string.
.TP
\fIpathName \fBselection element\fR ?\fIelement\fR?
.
Sets or gets the currently selected element.  If a spinbutton element
is specified, it will be displayed depressed.
.TP
\fIpathName \fBselection from \fIindex\fR
.
Set the selection anchor point to just before the character
given by \fIindex\fR.  Does not change the selection.
Returns an empty string.
.TP
\fIpathName \fBselection present\fR
.
Returns 1 if there is are characters selected in the spinbox,
0 if nothing is selected.
.TP
\fIpathName \fBselection range \fIstart end\fR
.
Sets the selection to include the characters starting with
the one indexed by \fIstart\fR and ending with the one just
before \fIend\fR.
If \fIend\fR refers to the same character as \fIstart\fR or an
earlier one, then the spinbox's selection is cleared.
.TP
\fIpathName \fBselection to \fIindex\fR
.
If \fIindex\fR is before the anchor point, set the selection
to the characters from \fIindex\fR up to but not including
the anchor point.
If \fIindex\fR is the same as the anchor point, do nothing.
If \fIindex\fR is after the anchor point, set the selection
to the characters from the anchor point up to but not including
\fIindex\fR.
The anchor point is determined by the most recent \fBselect from\fR
or \fBselect adjust\fR command in this widget.
If the selection is not in this widget then a new selection is
created using the most recent anchor point specified for the widget.
Returns an empty string.
.RE
.\" METHOD: set
.TP
\fIpathName \fBset\fR ?\fIstring\fR?
.
If \fIstring\fR is specified, the spinbox will try and set it to this
value, otherwise it just returns the spinbox's string.
If validation is on, it will occur when setting the string.
.\" METHOD: validate
.TP
\fIpathName \fBvalidate\fR
.
This command is used to force an evaluation of the \fB\-validatecommand\fR
independent of the conditions specified by the \fB\-validate\fR option.
This is done by temporarily setting the \fB\-validate\fR option to \fBall\fR.
It returns 0 or 1.
.\" METHOD: xview
.TP
\fIpathName \fBxview \fIargs\fR
.
This command is used to query and change the horizontal position of the
text in the widget's window.  It can take any of the following
forms:
.RS
.TP
\fIpathName \fBxview\fR
.
Returns a list containing two elements.
Each element is a real fraction between 0 and 1;  together they describe
the horizontal span that is visible in the window.
For example, if the first element is .2 and the second element is .6,
20% of the spinbox's text is off-screen to the left, the middle 40% is visible
in the window, and 40% of the text is off-screen to the right.
These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
option.
.TP
\fIpathName \fBxview \fIindex\fR
.
Adjusts the view in the window so that the character given by \fIindex\fR
is displayed at the left edge of the window.
.TP
\fIpathName \fBxview moveto\fI fraction\fR
.
Adjusts the view in the window so that the character \fIfraction\fR of the
way through the text appears at the left edge of the window.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
\fINumber\fR must be an integer.
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display;  if it is
If \fIwhat\fR is \fBpages\fR then the view adjusts by \fInumber\fR
screenfuls. If \fInumber\fR is negative then characters farther to the left
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left
become visible;  if it is positive then characters farther to the right
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display.
.RE
.SH "DEFAULT BINDINGS"
.PP
Tk automatically creates class bindings for spinboxes that give them
the following default behavior.
In the descriptions below,
.QW word
567
568
569
570
571
572
573
574

575
576
577


578
579
580
581
582
583
584
512
513
514
515
516
517
518

519



520
521
522
523
524
525
526
527
528







-
+
-
-
-
+
+







.IP [5]
Clicking mouse button 1 with the Control key down will position the
insertion cursor in the spinbox without affecting the selection.
.IP [6]
If any normal printing characters are typed in a spinbox, they are
inserted at the point of the insertion cursor.
.IP [7]
The view in the spinbox can be adjusted by dragging with the middle
The view in the spinbox can be adjusted by dragging with mouse button 2.
mouse button (button 2, or button 3 in TkAqua). If the middle mouse
button is clicked without moving the mouse, the selection is copied
into the spinbox at the position of the mouse cursor.
If mouse button 2 is clicked without moving the mouse, the selection
is copied into the spinbox at the position of the mouse cursor.
.IP [8]
If the mouse is dragged out of the spinbox on the left or right sides
while button 1 is pressed, the spinbox will automatically scroll to
make more text visible (if there is more text off-screen on the side
where the mouse left the window).
.IP [9]
The Left and Right keys move the insertion cursor one character to the

Deleted doc/sysnotify.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59



























































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
.\" Text automatically generated by txt2man
'\"
'\" Copyright (c) 2020 Kevin Walzer/WordTech Communications LLC.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH tk sysnotify n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
.SH NAME
sysnotify \- Creates a notification window with a title and message.
.SH SYNOPSIS
\fBtk sysnotify\fI title message\fR
.BE
.SH DESCRIPTION
.PP
The \fBtk sysnotify\fR command creates a platform-specific system notification
alert. Its intent is to provide a brief, unobtrusive notification to the user
by popping up a window that briefly appears in a corner of the screen.
.SH EXAMPLE
.PP
Here is an example of the \fBtk sysnotify\fR code:
.PP
.CS
tk sysnotify "Alert" \e
      "This is just a test of the Tk System Notification Code."
.CE
.SH PLATFORM NOTES
.PP
The macOS and Windows versions are native implementations using system
API's. The X11 version has a conditional dependency on libnotify, and
falls back to a Tcl-only implementation if libnotify is not installed. On
each platform the notification includes a platform-specific default image to
accompany the text.
.TP
\fBmacOS\fR
.
The macOS version will request permission from the user to authorize
notifications. This must be activated in Apple's System Preferences
Notifications section.
.RS
.PP
If deploying an application using the standalone version of Wish.app,
setting the bundle ID in the applications Info.plist file to begin with
.QW \fBcom\fR
seems necessary for notifications to work. Using a different prefix
for the bundle ID, such as something like
.QW \fBtk.tcl.tkchat\fR ,
will cause notifications to silently fail.
.RE
.TP
\fBWindows\fR
.
The image is taken from the system tray, i.e., \fBsysnotify\fR can only be
called when a \fBsystray\fR was installed.
.
.SH KEYWORDS
notify, alert

Deleted doc/systray.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79















































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
.\" Text automatically generated by txt2man
'\"
'\" Copyright (c) 2020 Kevin Walzer/WordTech Communications LLC.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH tk systray n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
.SH NAME
systray \- Creates an icon display in the platform-specific system tray.
.SH SYNOPSIS
.nf
\fBtk systray create \-image \fIimage\fR ?\fB\-text \fItext\fR? ?\fB\-button1 \fIcallback\fR? ?\fB\-button3 \fIcallback\fR?
\fBtk systray configure \fI?option? ?value option value ...?\fR
\fBtk systray exists\fR
\fBtk systray destroy\fR
.fi
.BE
.SH DESCRIPTION
.PP
.\" METHOD: create
The \fBtk systray create\fR command creates an icon in the platform-specific
tray. The widget is configured with a Tk image for the icon display, an
optional string for display in a tooltip, and optional callbacks that are
bound to <Button-1> and <Button-3>.
.PP
.\" METHOD: configure
The \fBtk systray configure\fR command sets one or more options of the systray
icon. Configurable options are the same as for the \fBcreate\fR subcommand. When
a single option name is given, the command returns the current value of this
option. When no option is given this command returns the list of all options and
their current value.
.PP
.\" METHOD: exists
The \fBtk systray exists\fR command checks whether a systray icon was created.
It returns a boolean.
.PP
.\" METHOD: destroy
The \fBtk systray destroy\fR command removes the icon from display and
deallocates it.
.PP
From a user-interface standpoint, only one icon per interpreter is
supported; attempts to create additional icons will return an error. The
existing tray icon can be modified with different images and
strings to indicate app state. Loading additional interpreters into a
running instance of Wish will allow additional icons to be displayed.
.SH EXAMPLE
.PP
Here is an example of the \fBtk systray\fR code:
.CS
image create photo book -data \e
        R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
tk systray create -image book -text "tk systray sample" \e
        -button1 {puts "Here is the tk systray output"} \e
        -button3 {puts "here is alternate output"}
.CE
.PP
Here is an example of modifying the \fBtk systray\fR icon:
.CS
image create photo book_page -data \e
        R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7
tk systray configure -image book_page -text "Updated sample" \e
        -button1 {puts "Different output from the tk systray"} \e
        -button3 {puts "and more different output from the tk systray"}
.CE
.SH PLATFORM NOTES
.PP
The X11 implementation is supported on a "best efforts" basis because it is
dependent on the window manager. The "text" flag, which is implemented as
a tooltip, does not always display if the WM does not support such features;
the systray icon itself may not even display with some window managers.
.PP
On Windows, the Tk image provided in the \fB\-image\fR option must be a
photo image. On other platforms either a bitmap image or a photo image
may be provided.
.SH KEYWORDS
image, callback

Changes to doc/text.n.

9
10
11
12
13
14
15
16
17
18
19




20
21
22
23
24
25
26
27
9
10
11
12
13
14
15




16
17
18
19

20
21
22
23
24
25
26







-
-
-
-
+
+
+
+
-







.so man.macros
.BS
'\" Note: do not modify the .SH NAME line immediately below!
.SH NAME
text, tk_textCopy, tk_textCut, tk_textPaste \- Create and manipulate 'text' hypertext editing widgets
.SH SYNOPSIS
.nf
\fBtext\fI pathName \fR?\fIoptions\fR?
\fBtk_textCopy\fI pathName\fR
\fBtk_textCut\fI pathName\fR
\fBtk_textPaste\fI pathName\fR
\fBtext\fR \fIpathName \fR?\fIoptions\fR?
\fBtk_textCopy\fR \fIpathName\fR
\fBtk_textCut\fR \fIpathName\fR
\fBtk_textPaste\fR \fIpathName\fR
.fi
.SO
\-background	\-highlightthickness	\-relief
\-borderwidth	\-insertbackground	\-selectbackground
\-cursor	\-insertborderwidth	\-selectborderwidth
\-exportselection	\-insertofftime	\-selectforeground
\-font	\-insertontime	\-setgrid
\-foreground	\-insertwidth	\-takefocus
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
225
226
227
228
229
230
231

232

233
234
235
236
237
238
239







-
+
-







.TP 12
\fBend\fR
.
Indicates the end of the text (the character just after the last newline).
.TP 12
\fImark\fR
.
Indicates the character just after the mark whose name is \fImark\fR (see
Indicates the character just after the mark whose name is \fImark\fR.
\fBMARKS\fR for details).
.TP 12
\fItag\fB.first\fR
.
Indicates the first character in the text that has been tagged with \fItag\fR.
This form generates an error if no characters are currently tagged with
\fItag\fR.
.TP 12
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510


511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563


564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
411
412
413
414
415
416
417

418
419
420
421
422

423
424
425
426
427
428
429

430
431
432
433
434
435

436
437
438
439
440
441

442
443
444
445
446
447
448
449

450
451
452
453
454

455
456
457
458
459
460

461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495


496
497

498
499
500
501
502
503
504
505

506
507
508
509
510
511

512
513
514
515
516
517
518

519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535

536
537
538
539

540
541
542


543
544

545
546

547
548
549
550
551

552
553

554
555
556
557
558

559
560
561
562
563
564

565
566
567
568
569
570

571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595

596
597
598
599
600

601
602
603
604
605
606
607

608
609
610
611
612
613
614







-





-







-






-






-








-





-






-








-









-










-








-
-
+
+
-








-






-







-







-










-




-
+


-
-
+
+
-


-





-


-





-






-






-






-











-








-





-







-







as determined by the \fB\-background\fR, \fB\-font\fR, and \fB\-foreground\fR
options for the text widget. However, display options may be associated with
individual tags using the
.QW "\fIpathName \fBtag configure\fR"
widget command. If a character has been tagged, then the display options
associated with the tag override the default display style. The following
options are currently supported for tags:
.\" OPTION: -background
.TP
\fB\-background \fIcolor\fR
.
\fIColor\fR specifies the background color to use for characters associated
with the tag. It may have any of the forms accepted by \fBTk_GetColor\fR.
.\" OPTION: -bgstipple
.TP
\fB\-bgstipple \fIbitmap\fR
.
\fIBitmap\fR specifies a bitmap that is used as a stipple pattern for the
background. It may have any of the forms accepted by \fBTk_GetBitmap\fR. If
\fIbitmap\fR has not been specified, or if it is specified as an empty string,
then a solid fill will be used for the background.
.\" OPTION: -borderwidth
.TP
\fB\-borderwidth \fIpixels\fR
.
\fIPixels\fR specifies the width of a border to draw around the tag using any
of the forms accepted by \fBTk_GetPixels\fR. This option should be used in
conjunction with the \fB\-relief\fR option to provide the desired border.
.\" OPTION: -elide
.TP
\fB\-elide \fIboolean\fR
.
\fIElide\fR specifies whether the data should be elided. Elided data
(characters, images, embedded windows, etc.) is not displayed and takes no
space on screen, but further on behaves just as normal data.
.\" OPTION: -fgstipple
.TP
\fB\-fgstipple \fIbitmap\fR
.
\fIBitmap\fR specifies a bitmap that is used as a stipple pattern when drawing
text and other foreground information such as underlines. It may have any of
the forms accepted by \fBTk_GetBitmap\fR. If \fIbitmap\fR has not been
specified, or if it is specified as an empty string, then a solid fill will be
used.
.\" OPTION: -font
.TP
\fB\-font \fIfontName\fR
.
\fIFontName\fR is the name of a font to use for drawing characters. It may
have any of the forms accepted by \fBTk_GetFont\fR.
.\" OPTION: -foreground
.TP
\fB\-foreground \fIcolor\fR
.
\fIColor\fR specifies the color to use when drawing text and other foreground
information such as underlines. It may have any of the forms accepted by
\fBTk_GetColor\fR.
.\" OPTION: -justify
.TP
\fB\-justify \fIjustify\fR
.
If the first non-elided character of a display line has a tag for which this
option has been specified, then \fIjustify\fR determines how to justify the
line. It must be one of \fBleft\fR, \fBright\fR, or \fBcenter\fR. If a line
wraps, then the justification for each line on the display is determined by
the first non-elided character of that display line.
.\" OPTION: -lmargin1
.TP
\fB\-lmargin1 \fIpixels\fR
.
If the first non-elided character of a text line has a tag for which this
option has been specified, then \fIpixels\fR specifies how much the line
should be indented from the left edge of the window. \fIPixels\fR may have any
of the standard forms for screen distances. If a line of text wraps, this
option only applies to the first line on the display; the \fB\-lmargin2\fR
option controls the indentation for subsequent lines.
.\" OPTION: -lmargin2
.TP
\fB\-lmargin2 \fIpixels\fR
.
If the first non-elided character of a display line has a tag for which this
option has been specified, and if the display line is not the first for its
text line (i.e., the text line has wrapped), then \fIpixels\fR specifies how
much the line should be indented from the left edge of the window.
\fIPixels\fR may have any of the standard forms for screen distances. This
option is only used when wrapping is enabled, and it only applies to the
second and later display lines for a text line.
.\" OPTION: -lmargincolor
.TP
\fB\-lmargincolor \fIcolor\fR
.
\fIColor\fR specifies the background color to use in regions that do not
contain characters because they are indented by \fB\-lmargin1\fR or
\fB\-lmargin2\fR. It may have any of the forms accepted by
\fBTk_GetColor\fR. If \fIcolor\fR has not been specified, or if it is
specified as an empty string, then the color used is specified by the
\fB\-background\fR tag option (or, if this is also unspecified, by the
\fB\-background\fR widget option).
\fB-background\fR tag option (or, if this is also unspecified, by the
\fB-background\fR widget option).
.\" OPTION: -offset
.TP
\fB\-offset \fIpixels\fR
.
\fIPixels\fR specifies an amount by which the text's baseline should be offset
vertically from the baseline of the overall line, in pixels. For example, a
positive offset can be used for superscripts and a negative offset can be used
for subscripts. \fIPixels\fR may have any of the standard forms for screen
distances.
.\" OPTION: -overstrike
.TP
\fB\-overstrike \fIboolean\fR
.
Specifies whether or not to draw a horizontal rule through the middle of
characters. \fIBoolean\fR may have any of the forms accepted by
\fBTcl_GetBoolean\fR.
.\" OPTION: -overstrikefg
.TP
\fB\-overstrikefg \fIcolor\fR
.
\fIColor\fR specifies the color to use when displaying the overstrike. It may
have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
been specified, or if it is specified as an empty string, then the color
specified by the \fB\-foreground\fR tag option is used.
.\" OPTION: -relief
.TP
\fB\-relief \fIrelief\fR
.
\fIRelief\fR specifies the relief style to use for drawing the border, in any
of the forms accepted by \fBTk_GetRelief\fR. This option is used in
conjunction with the \fB\-borderwidth\fR option to enable to the desired
border appearance.
.\" OPTION: -rmargin
.TP
\fB\-rmargin \fIpixels\fR
.
If the first non-elided character of a display line has a tag for which this
option has been specified, then \fIpixels\fR specifies how wide a margin to
leave between the end of the line and the right edge of the window.
\fIPixels\fR may have any of the standard forms for screen distances. This
option is only used when wrapping is enabled. If a text line wraps, the right
margin for each line on the display is determined by the first non-elided
character of that display line.
.\" OPTION: -rmargincolor
.TP
\fB\-rmargincolor \fIcolor\fR
.
\fIColor\fR specifies the background color to use in regions that do not
contain characters because they are indented by \fB\-rmargin\fR. It may
contain characters because they are indented by \fB\-rmargin1\fR. It may
have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
been specified, or if it is specified as an empty string, then the color
used is specified by the \fB\-background\fR tag option (or, if this is also
unspecified, by the \fB\-background\fR widget option).
used is specified by the \fB-background\fR tag option (or, if this is also
unspecified, by the \fB-background\fR widget option).
.\" OPTION: -selectbackground
.TP
\fB\-selectbackground \fIcolor\fR
.
\fIColor\fR specifies the background color to use when displaying selected
items. It may have any of the forms accepted by \fBTk_GetColor\fR. If
\fIcolor\fR has not been specified, or if it is specified as an empty
string, then the color specified by the \fB\-background\fR tag option is
used.
.\" OPTION: -selectforeground
.TP
\fB\-selectforeground \fIcolor\fR
.
\fIColor\fR specifies the foreground color to use when displaying selected
items. It may have any of the forms accepted by \fBTk_GetColor\fR. If
\fIcolor\fR has not been specified, or if it is specified as an empty
string, then the color specified by the \fB\-foreground\fR tag option is
used.
.\" OPTION: -spacing1
.TP
\fB\-spacing1 \fIpixels\fR
.
\fIPixels\fR specifies how much additional space should be left above each
text line, using any of the standard forms for screen distances. If a line
wraps, this option only applies to the first line on the display.
.\" OPTION: -spacing2
.TP
\fB\-spacing2 \fIpixels\fR
.
For lines that wrap, this option specifies how much additional space to leave
between the display lines for a single text line. \fIPixels\fR may have any of
the standard forms for screen distances.
.\" OPTION: -spacing3
.TP
\fB\-spacing3 \fIpixels\fR
.
\fIPixels\fR specifies how much additional space should be left below each
text line, using any of the standard forms for screen distances. If a line
wraps, this option only applies to the last line on the display.
.\" OPTION: -tabs
.TP
\fB\-tabs \fItabList\fR
.
\fITabList\fR specifies a set of tab stops in the same form as for the
\fB\-tabs\fR option for the text widget. This option only applies to a display
line if it applies to the first non-elided character on that display line. If
this option is specified as an empty string, it cancels the option, leaving it
unspecified for the tag (the default). If the option is specified as a
non-empty string that is an empty list, such as \fB\-tags\0{\0}\fR, then it
requests default 8-character tabs as described for the \fB\-tags\fR widget
option.
.\" OPTION: -tabstyle
.TP
\fB\-tabstyle \fIstyle\fR
.
\fIStyle\fR specifies either the \fItabular\fR or \fIwordprocessor\fR style of
tabbing to use for the text widget. This option only applies to a display line
if it applies to the first non-elided character on that display line. If this
option is specified as an empty string, it cancels the option, leaving it
unspecified for the tag (the default).
.\" OPTION: -underline
.TP
\fB\-underline \fIboolean\fR
.
\fIBoolean\fR specifies whether or not to draw an underline underneath
characters. It may have any of the forms accepted by \fBTcl_GetBoolean\fR.
.\" OPTION: -underlinefg
.TP
\fB\-underlinefg \fIcolor\fR
.
\fIColor\fR specifies the color to use when displaying the underline. It may
have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not
been specified, or if it is specified as an empty string, then the color
specified by the \fB\-foreground\fR tag option is used.
.\" OPTION: -wrap
.TP
\fB\-wrap \fImode\fR
.
\fIMode\fR specifies how to handle lines that are wider than the text's
window. This option only applies to a display line if it applies to the
first non-elided character on that display line. It has the same legal
values as the \fB\-wrap\fR option for the text widget: \fBnone\fR,
722
723
724
725
726
727
728
729

730
731

732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
691
692
693
694
695
696
697

698
699

700
701
702
703
704
705
706
707
708

709
710
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736

737
738
739
740
741
742

743
744
745
746
747
748
749
750

751
752
753
754
755
756
757







-
+

-
+








-










-












-






-






-








-







unit's worth of index space in the text widget, and it may be referred to
either by the name of its embedded window or by its position in the widget's
index space. If the range of text containing the embedded window is deleted
then the window is destroyed. Similarly if the text widget as a whole is
deleted, then the window is destroyed.
.PP
Eliding an embedded window immediately after scheduling it for creation via
\fIpathName \fBwindow create \fIindex \fB\-create\fR will prevent it from being
\fIpathName \fBwindow create \fIindex \fB-create\fR will prevent it from being
effectively created. Uneliding an elided embedded window scheduled for creation
via \fIpathName \fBwindow create \fIindex \fB\-create\fR will automatically
via \fIpathName \fBwindow create \fIindex \fB-create\fR will automatically
trigger the associated creation script. After destroying an elided embedded
window, the latter won't get automatically recreated.
.PP
When an embedded window is added to a text widget with the \fIpathName
\fBwindow create\fR widget command, several configuration options may be
associated with it. These options may be modified later with the \fIpathName
\fBwindow configure\fR widget command. The following options are currently
supported:
.\" OPTION: -align
.TP
\fB\-align \fIwhere\fR
.
If the window is not as tall as the line in which it is displayed, this option
determines where the window is displayed in the line. \fIWhere\fR must have
one of the values \fBtop\fR (align the top of the window with the top of the
line), \fBcenter\fR (center the window within the range of the line),
\fBbottom\fR (align the bottom of the window with the bottom of the line's
area), or \fBbaseline\fR (align the bottom of the window with the baseline of
the line).
.\" OPTION: -create
.TP
\fB\-create \fIscript\fR
.
Specifies a Tcl script that may be evaluated to create the window for the
annotation. If no \fB\-window\fR option has been specified for the annotation
this script will be evaluated when the annotation is about to be displayed on
the screen. \fIScript\fR must create a window for the annotation and return
the name of that window as its result. Two substitutions will be performed in
\fIscript\fR before evaluation. \fI%W\fR will be substituted by the name of
the parent text widget, and \fI%%\fR will be substituted by a single \fI%\fR.
If the annotation's window should ever be deleted, \fIscript\fR will be
evaluated again the next time the annotation is displayed.
.\" OPTION: -padx
.TP
\fB\-padx \fIpixels\fR
.
\fIPixels\fR specifies the amount of extra space to leave on each side of the
embedded window. It may have any of the usual forms defined for a screen
distance.
.\" OPTION: -pady
.TP
\fB\-pady \fIpixels\fR
.
\fIPixels\fR specifies the amount of extra space to leave on the top and on
the bottom of the embedded window. It may have any of the usual forms defined
for a screen distance.
.\" OPTION: -stretch
.TP
\fB\-stretch \fIboolean\fR
.
If the requested height of the embedded window is less than the height of the
line in which it is displayed, this option can be used to specify whether the
window should be stretched vertically to fill its line. If the \fB\-pady\fR
option has been specified as well, then the requested padding will be retained
even if the window is stretched.
.\" OPTION: -window
.TP
\fB\-window \fIpathName\fR
.
Specifies the name of a window to display in the annotation. Note that if a
\fIpathName\fR has been set, then later configuring a window to the empty
string will not delete the widget corresponding to the old \fIpathName\fR.
Rather it will remove the association between the old \fIpathName\fR and the
807
808
809
810
811
812
813
814

815
816

817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
770
771
772
773
774
775
776

777
778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798

799
800
801
802
803
804
805
806
807

808
809
810
811
812

813
814
815
816
817
818
819

820
821
822
823
824
825

826
827
828
829
830
831
832







-
+

-
+



















-









-





-







-






-







space in the text widget, and it may be referred to either by its position in
the widget's index space, or the name it is assigned when the image is inserted
into the text widget with \fIpathName \fBimage create\fR. If the range of text
containing the embedded image is deleted then that copy of the image is removed
from the screen.
.PP
Eliding an embedded image immediately after scheduling it for creation via
\fIpathName \fBimage create \fIindex \fB\-create\fR will prevent it from being
\fIpathName \fBimage create \fIindex \fB-create\fR will prevent it from being
effectively created. Uneliding an elided embedded image scheduled for creation
via \fIpathName \fBimage create \fIindex \fB\-create\fR will automatically
via \fIpathName \fBimage create \fIindex \fB-create\fR will automatically
trigger the associated creation script. After destroying an elided embedded
image, the latter won't get automatically recreated.
.PP
When an embedded image is added to a text widget with the \fIpathName \fBimage
create\fR widget command, a name unique to this instance of the image is
returned. This name may then be used to refer to this image instance. The name
is taken to be the value of the \fB\-name\fR option (described below). If the
\fB\-name\fR option is not provided, the \fB\-image\fR name is used instead.
If the \fIimageName\fR is already in use in the text widget, then \fB#\fInn\fR
is added to the end of the \fIimageName\fR, where \fInn\fR is an arbitrary
integer. This insures the \fIimageName\fR is unique. Once this name is
assigned to this instance of the image, it does not change, even though the
\fB\-image\fR or \fB\-name\fR values can be changed with \fIpathName \fBimage
configure\fR.
.PP
When an embedded image is added to a text widget with the \fIpathName \fBimage
create\fR widget command, several configuration options may be associated with
it. These options may be modified later with the \fIpathName \fBimage
configure\fR widget command. The following options are currently supported:
.\" OPTION: -align
.TP
\fB\-align \fIwhere\fR
.
If the image is not as tall as the line in which it is displayed, this option
determines where the image is displayed in the line. \fIWhere\fR must have one
of the values \fBtop\fR (align the top of the image with the top of the line),
\fBcenter\fR (center the image within the range of the line), \fBbottom\fR
(align the bottom of the image with the bottom of the line's area), or
\fBbaseline\fR (align the bottom of the image with the baseline of the line).
.\" OPTION: -image
.TP
\fB\-image \fIimage\fR
.
Specifies the name of the Tk image to display in the annotation. If
\fIimage\fR is not a valid Tk image, then an error is returned.
.\" OPTION: -name
.TP
\fB\-name \fIImageName\fR
.
Specifies the name by which this image instance may be referenced in the text
widget. If \fIImageName\fR is not supplied, then the name of the Tk image is
used instead. If the \fIimageName\fR is already in use, \fI#nn\fR is appended
to the end of the name as described above.
.\" OPTION: -padx
.TP
\fB\-padx \fIpixels\fR
.
\fIPixels\fR specifies the amount of extra space to leave on each side of the
embedded image. It may have any of the usual forms defined for a screen
distance.
.\" OPTION: -pady
.TP
\fB\-pady \fIpixels\fR
.
\fIPixels\fR specifies the amount of extra space to leave on the top and on
the bottom of the embedded image. It may have any of the usual forms defined
for a screen distance.
.SH "THE SELECTION"
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
843
844
845
846
847
848
849



850
851
852
853
854
855
856







-
-
-







.IP [3]
If the selection is claimed away by another application or by another window
within this application, then the \fBsel\fR tag will be removed from all
characters in the text.
.IP [4]
Whenever the \fBsel\fR tag range changes a virtual event \fB<<Selection>>\fR
is generated.
It might also be generated when selection is affected but not actually changed.
Further, multiple selection changes could happen before events can be processed
leading to multiple events with the same visible selection.
.PP
The \fBsel\fR tag is automatically defined when a text widget is created, and
it may not be deleted with the
.QW "\fIpathName \fBtag delete\fR"
widget command. Furthermore, the \fB\-selectbackground\fR,
\fB\-selectborderwidth\fR, and \fB\-selectforeground\fR options for the text
widget are tied to the \fB\-background\fR, \fB\-borderwidth\fR, and
1016
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
971
972
973
974
975
976
977

978
979
980
981
982
983
984
985







-
+







creation of peer widgets.
.SH "ASYNCHRONOUS UPDATE OF LINE HEIGHTS"
.PP
In order to maintain a responsive user-experience, the text widget calculates
lines metrics (line heights in pixels) asynchronously. Because of this, some
commands of the text widget may return wrong results if the asynchronous
calculations are not finished at the time of calling. This applies to
\fIpathName \fBcount \-ypixels\fR and \fIpathName \fByview\fR.
\fIpathName \fBcount -ypixels\fR and \fIpathName \fByview\fR.
.PP
Again for performance reasons, it would not be appropriate to let these
commands always wait for the end of the update calculation each time they are
called. In most use cases of these commands a more or less inaccurate result
does not really matter compared to execution speed.
.PP
In case accurate result is needed (and if the text widget is managed by a
1093
1094
1095
1096
1097
1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070

1071
1072
1073
1074

1075

1076
1077
1078
1079
1080
1081
1082
1083

1084

1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096

1097

1098
1099
1100
1101
1102
1103
1104
1105







-
+




-










-

-
+



-

-
+







-

-
+











-

-
+







.CE
.SH "WIDGET COMMAND"
.PP
The \fBtext\fR command creates a new Tcl command whose name is the same as the
path name of the text's window. This command may be used to invoke various
operations on the widget. It has the following general form:
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
\fIPathName\fR is the name of the command, which is the same as the text
widget's path name. \fIOption\fR and the \fIarg\fRs determine the exact
behavior of the command. The following commands are possible for text widgets:
.\" METHOD: bbox
.TP
\fIpathName \fBbbox \fIindex\fR
.
Returns a list of four elements describing the screen area of the character
given by \fIindex\fR. The first two elements of the list give the x and y
coordinates of the upper-left corner of the area occupied by the character,
and the last two elements give the width and height of the area. If the
character is only partially visible on the screen, then the return value
reflects just the visible part. If the character is not visible on the screen
then the return value is an empty list.
.\" METHOD: cget
.TP
\fIpathName \fBcget\fI option\fR
\fIpathName \fBcget\fR \fIoption\fR
.
Returns the current value of the configuration option given by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBtext\fR command.
.\" METHOD: compare
.TP
\fIpathName \fBcompare\fI index1 op index2\fR
\fIpathName \fBcompare\fR \fIindex1 op index2\fR
.
Compares the indices given by \fIindex1\fR and \fIindex2\fR according to the
relational operator given by \fIop\fR, and returns 1 if the relationship is
satisfied and 0 if it is not. \fIOp\fR must be one of the operators <, <=, ==,
>=, >, or !=. If \fIop\fR is == then 1 is returned if the two indices refer to
the same character, if \fIop\fR is < then 1 is returned if \fIindex1\fR refers
to an earlier character in the text than \fIindex2\fR, and so on.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
\fIpathName \fBconfigure\fR ?\fIoption\fR? \fI?value option value ...\fR?
.
Query or modify the configuration options of the widget. If no \fIoption\fR is
specified, returns a list describing all of the available options for
\fIpathName\fR (see \fBTk_ConfigureInfo\fR for information on the format of
this list). If \fIoption\fR is specified with no \fIvalue\fR, then the command
returns a list describing the one named option (this list will be identical to
the corresponding sublist of the value returned if no \fIoption\fR is
specified). If one or more \fIoption\-value\fR pairs are specified, then the
command modifies the given widget option(s) to have the given value(s); in
this case the command returns an empty string. \fIOption\fR may have any of
the values accepted by the \fBtext\fR command.
.\" METHOD: count
.TP
\fIpathName \fBcount\fR ?\fIoptions\fR? \fIindex1 index2\fR
\fIpathName \fBcount\fR \fI?options\fR? \fIindex1 index2\fR
.
Counts the number of relevant things between the two indices. If \fIindex1\fR
is after \fIindex2\fR, the result will be a negative number (and this holds
for each of the possible options). The actual items which are counted depend
on the options given. The result is a list of integers, one for the result of
each counting option given. Valid counting options are \fB\-chars\fR,
\fB\-displaychars\fR, \fB\-displayindices\fR, \fB\-displaylines\fR,
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186







-




















-







The command returns a positive or negative integer corresponding to the number
of items counted between the two indices. One such integer is returned for
each counting option given, so a list is returned if more than one option was
supplied. For example
.QW ".text count \-xpixels \-ypixels 1.3 4.5"
is perfectly valid and will return a list of two elements.
.RE
.\" METHOD: debug
.TP
\fIpathName \fBdebug \fR?\fIboolean\fR?
.
If \fIboolean\fR is specified, then it must have one of the true or false
values accepted by Tcl_GetBoolean. If the value is a true one then internal
consistency checks will be turned on in the B-tree code associated with text
widgets. If \fIboolean\fR has a false value then the debugging checks will be
turned off. In either case the command returns an empty string. If
\fIboolean\fR is not specified then the command returns \fBon\fR or \fBoff\fR
to indicate whether or not debugging is turned on. There is a single debugging
switch shared by all text widgets: turning debugging on or off in any widget
turns it on or off for all widgets. For widgets with large amounts of text,
the consistency checks may cause a noticeable slow-down.
.RS
.PP
When debugging is turned on, the drawing routines of the text widget set the
global variables \fBtk_textRedraw\fR and \fBtk_textRelayout\fR to the lists of
indices that are redrawn. The values of these variables are tested by Tk's
test suite.
.RE
.\" METHOD: delete
.TP
\fIpathName \fBdelete \fIindex1 \fR?\fIindex2 ...\fR?
.
Delete a range of characters from the text.
If both \fIindex1\fR and \fIindex2\fR are specified, then delete
all the characters starting with the one given by \fIindex1\fR
and stopping just before \fIindex2\fR (i.e. the character at
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256

1257
1258
1259
1260

1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
1282

1283

1284
1285
1286
1287
1288
1289
1290
1291







-
















-


















-





-







-




-




-






-








-








-

-
+







All indices are first checked for validity before any deletions are made.
They are sorted and the text is removed from the last range to the
first range so deleted text does not cause an undesired index shifting
side-effects.  If multiple ranges with the same start index are given,
then the longest range is used.  If overlapping ranges are given, then
they will be merged into spans that do not cause deletion of text
outside the given ranges due to text shifted during deletion.
.\" METHOD: dlineinfo
.TP
\fIpathName \fBdlineinfo \fIindex\fR
.
Returns a list with five elements describing the area occupied by the display
line containing \fIindex\fR. The first two elements of the list give the x and
y coordinates of the upper-left corner of the area occupied by the line, the
third and fourth elements give the width and height of the area, and the fifth
element gives the position of the baseline for the line, measured down from
the top of the area. All of this information is measured in pixels. If the
current wrap mode is \fBnone\fR and the line extends beyond the boundaries of
the window, the area returned reflects the entire area of the line, including
the portions that are out of the window. If the line is shorter than the full
width of the window then the area returned reflects just the portion of the
line that is occupied by characters and embedded windows. If the display line
containing \fIindex\fR is not visible on the screen then the return value is
an empty list.
.\" METHOD: dump
.TP
\fIpathName \fBdump \fR?\fIswitches\fR? \fIindex1 \fR?\fIindex2\fR?
.
Return the contents of the text widget from \fIindex1\fR up to, but not
including \fIindex2\fR, including the text and information about marks, tags,
and embedded windows. If \fIindex2\fR is not specified, then it defaults to
one character past \fIindex1\fR. The information is returned in the following
format:
.RS
.LP
\fIkey1 value1 index1 key2 value2 index2\fR ...
.LP
The possible \fIkey\fR values are \fBtext\fR, \fBmark\fR, \fBtagon\fR,
\fBtagoff\fR, \fBimage\fR, and \fBwindow\fR. The corresponding \fIvalue\fR is
the text, mark name, tag name, image name, or window name. The \fIindex\fR
information is the index of the start of the text, mark, tag transition, image
or window. One or more of the following switches (or abbreviations thereof)
may be specified to control the dump:
.\" OPTION: -all
.TP
\fB\-all\fR
.
Return information about all elements: text, marks, tags, images and windows.
This is the default.
.\" OPTION: -command
.TP
\fB\-command \fIcommand\fR
.
Instead of returning the information as the result of the dump operation,
invoke the \fIcommand\fR on each element of the text widget within the range.
The command has three arguments appended to it before it is evaluated: the
\fIkey\fR, \fIvalue\fR, and \fIindex\fR.
.\" OPTION: -image
.TP
\fB\-image\fR
.
Include information about images in the dump results.
.\" OPTION: -mark
.TP
\fB\-mark\fR
.
Include information about marks in the dump results.
.\" OPTION: -tag
.TP
\fB\-tag\fR
.
Include information about tag transitions in the dump results. Tag information
is returned as \fBtagon\fR and \fBtagoff\fR elements that indicate the begin
and end of each range of each tag, respectively.
.\" OPTION: -text
.TP
\fB\-text\fR
.
Include information about text in the dump results. The value is the text up
to the next element or the end of range indicated by \fIindex2\fR. A text
element does not span newlines. A multi-line block of text that contains no
marks or tag transitions will still be dumped as a set of text segments that
each end with a newline. The newline is part of the value.
.\" OPTION: -window
.TP
\fB\-window\fR
.
Include information about embedded windows in the dump results. The value of a
window is its Tk pathname, unless the window has not been created yet. (It
must have a create script.) In this case an empty string is returned, and you
must query the window by its index position to get more information.
.RE
.\" METHOD: edit
.TP
\fIpathName \fBedit \fIoption \fR?\fIarg ...\fR?
\fIpathName \fBedit \fIoption \fR?\fIarg arg ...\fR?
.
This command controls the undo mechanism and the modified flag. The exact
behavior of the command depends on the \fIoption\fR argument that follows the
\fBedit\fR argument. The following forms of the command are currently
supported:
.RS
.TP
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416

1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350

1351

1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362







-


















-

-
+


-
+







.
Undoes the last edit action when the \fB\-undo\fR option is true, and returns a
list of indices indicating what ranges were changed by the undo operation. An
edit action is defined as all the insert and delete commands that are recorded
on the undo stack in between two separators. Generates an error when the undo
stack is empty. Does nothing when the \fB\-undo\fR option is false.
.RE
.\" METHOD: get
.TP
\fIpathName \fBget\fR ?\fB\-displaychars\fR? ?\fB\-\-\fR? \fIindex1\fR ?\fIindex2 ...\fR?
.
Return a range of characters from the text. The return value will be all the
characters in the text starting with the one whose index is \fIindex1\fR and
ending just before the one whose index is \fIindex2\fR (the character at
\fIindex2\fR will not be returned). If \fIindex2\fR is omitted then the single
character at \fIindex1\fR is returned. If there are no characters in the
specified range (e.g. \fIindex1\fR is past the end of the file or \fIindex2\fR
is less than or equal to \fIindex1\fR) then an empty string is returned. If
the specified range contains embedded windows, no information about them is
included in the returned string. If multiple index pairs are given, multiple
ranges of text will be returned in a list. Invalid ranges will not be
represented with empty strings in the list. The ranges are returned in the
order passed to \fIpathName \fBget\fR. If the \fB\-displaychars\fR option is
given, then, within each range, only those characters which are not elided
will be returned. This may have the effect that some of the returned ranges
are empty strings.
.\" METHOD: image
.TP
\fIpathName \fBimage \fIoption \fR?\fIarg ...\fR?
\fIpathName \fBimage \fIoption \fR?\fIarg arg ...\fR?
.
This command is used to manipulate embedded images. The behavior of the
command depends on the \fIoption\fR argument that follows the \fBimage\fR
command depends on the \fIoption\fR argument that follows the \fBtag\fR
argument. The following forms of the command are currently supported:
.RS
.TP
\fIpathName \fBimage cget \fIindex option\fR
.
Returns the value of a configuration option for an embedded image. \fIIndex\fR
identifies the embedded image, and \fIoption\fR specifies a particular
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415

1416

1417
1418
1419
1420
1421
1422
1423
1424







-






-

















-

-
+







identifier returned.
.TP
\fIpathName \fBimage names\fR
.
Returns a list whose elements are the names of all image instances currently
embedded in \fIwindow\fR.
.RE
.\" METHOD: index
.TP
\fIpathName \fBindex \fIindex\fR
.
Returns the position corresponding to \fIindex\fR in the form \fIline.char\fR
where \fIline\fR is the line number and \fIchar\fR is the character number.
\fIIndex\fR may have any of the forms described under \fBINDICES\fR above.
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex chars \fR?\fItagList chars tagList ...\fR?
.
Inserts all of the \fIchars\fR arguments just before the character at
\fIindex\fR. If \fIindex\fR refers to the end of the text (the character after
the last newline) then the new text is inserted just before the last newline
instead. If there is a single \fIchars\fR argument and no \fItagList\fR, then
the new text will receive any tags that are present on both the character
before and the character after the insertion point; if a tag is present on
only one of these characters then it will not be applied to the new text. If
\fItagList\fR is specified then it consists of a list of tag names; the new
characters will receive all of the tags in this list and no others, regardless
of the tags present around the insertion point. If multiple
\fIchars\fR\-\fItagList\fR argument pairs are present, they produce the same
effect as if a separate \fIpathName \fBinsert\fR widget command had been
issued for each pair, in order. The last \fItagList\fR argument may be
omitted.
.\" METHOD: mark
.TP
\fIpathName \fBmark \fIoption \fR?\fIarg ...\fR?
\fIpathName \fBmark \fIoption \fR?\fIarg arg ...\fR?
.
This command is used to manipulate marks. The exact behavior of the command
depends on the \fIoption\fR argument that follows the \fBmark\fR argument. The
following forms of the command are currently supported:
.RS
.TP
\fIpathName \fBmark gravity \fImarkName\fR ?\fIdirection\fR?
1506
1507
1508
1509
1510
1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453







-
+







specified in numerical form, then the search for the next mark begins at that
index. If \fIindex\fR is the name of a mark, then the search for the next mark
begins immediately after that mark. This can still return a mark at the same
position if there are multiple marks at the same index. These semantics mean
that the \fBmark next\fR operation can be used to step through all the marks
in a text widget in the same order as the mark information returned by the
\fIpathName \fBdump\fR operation. If a mark has been set to the special
\fBend\fR index, then it appears to be \fIafter \fBend\fR with respect to
\fBend\fR index, then it appears to be \fIafter\fR \fBend\fR with respect to
the \fIpathName \fBmark next\fR operation. An empty string is returned if
there are no marks after \fIindex\fR.
.TP
\fIpathName \fBmark previous \fIindex\fR
.
Returns the name of the mark at or before \fIindex\fR. If \fIindex\fR is
specified in numerical form, then the search for the previous mark begins with
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498

1499

1500

1501

1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515

1516
1517
1518
1519
1520
1521
1522







-



















-


-

-

-
+
-














-







.
Remove the mark corresponding to each of the \fImarkName\fR arguments. The
removed marks will not be usable in indices and will not be returned by future
calls to
.QW "\fIpathName \fBmark names\fR" .
This command returns an empty string.
.RE
.\" METHOD: peer
.TP
\fIpathName \fBpeer \fIoption args\fR
.
This command is used to create and query widget peers. It has two forms,
depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBpeer create \fInewPathName\fR ?\fIoptions\fR?
.
Creates a peer text widget with the given \fInewPathName\fR, and any optional
standard configuration options (as for the \fItext\fR command). By default the
peer will have the same start and end line as the parent widget, but these can
be overridden with the standard configuration options.
.TP
\fIpathName \fBpeer names\fR
.
Returns a list of peers of this widget (this does not include the widget
itself). The order within this list is undefined.
.RE
.\" METHOD: pendingsync
.TP
\fIpathName \fBpendingsync\fR
.
Returns 1 if the line heights calculations are not up-to-date, 0 otherwise.
.\" METHOD: replace
.TP
\fIpathName \fBreplace\fI index1 index2 chars\fR ?\fItagList chars tagList ...\fR?
\fIpathName \fBreplace\fR \fIindex1 index2 chars\fR ?\fItagList chars tagList ...\fR?
.
Replaces the range of characters between \fIindex1\fR and \fIindex2\fR
with the given characters and tags.  See the section on \fIpathName
\fBinsert\fR for an explanation of the handling of the \fItagList...\fR
arguments, and the section on \fIpathName
\fBdelete\fR for an explanation of the handling of the indices.  If
\fIindex2\fR corresponds to an index earlier in the text than
\fIindex1\fR, an error will be generated.
.RS
.PP
The deletion and insertion are arranged so that no unnecessary scrolling of
the window or movement of insertion cursor occurs. In addition the undo/redo
stack are correctly modified, if undo operations are active in the text
widget. The command returns an empty string.
.RE
.\" METHOD: scan
.TP
\fIpathName \fBscan \fIoption args\fR
.
This command is used to implement scanning on texts. It has two forms,
depending on \fIoption\fR:
.RS
.TP
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542
1543
1544
1545
1546
1547

1548
1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561
1562

1563
1564
1565
1566
1567

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586

1587
1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619

1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636

1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647

1648
1649
1650
1651
1652
1653
1654







-









-






-









-





-











-








-




-










-



















-

















-







-




-







This command computes the difference between its \fIx\fR and \fIy\fR arguments
and the \fIx\fR and \fIy\fR arguments to the last \fIpathName \fBscan mark\fR
command for the widget. It then adjusts the view by 10 times the difference in
coordinates. This command is typically associated with mouse motion events in
the widget, to produce the effect of dragging the text at high speed through
the window. The return value is an empty string.
.RE
.\" METHOD: search
.TP
\fIpathName \fBsearch \fR?\fIswitches\fR? \fIpattern index \fR?\fIstopIndex\fR?
.
Searches the text in \fIpathName\fR starting at \fIindex\fR for a range of
characters that matches \fIpattern\fR. If a match is found, the index of the
first character in the match is returned as result; otherwise an empty string
is returned. One or more of the following switches (or abbreviations thereof)
may be specified to control the search:
.RS
.\" OPTION: -forwards
.TP
\fB\-forwards\fR
.
The search will proceed forward through the text, finding the first matching
range starting at or after the position given by \fIindex\fR. This is the
default.
.\" OPTION: -backwards
.TP
\fB\-backwards\fR
.
The search will proceed backward through the text, finding the matching range
closest to \fIindex\fR whose first character is before \fIindex\fR (it is not
allowed to be at \fIindex\fR). Note that, for a variety of reasons, backwards
searches can be substantially slower than forwards searches (particularly when
using \fB\-regexp\fR), so it is recommended that performance-critical code use
forward searches.
.\" OPTION: -exact
.TP
\fB\-exact\fR
.
Use exact matching: the characters in the matching range must be identical to
those in \fIpattern\fR. This is the default.
.\" OPTION: -regexp
.TP
\fB\-regexp\fR
.
Treat \fIpattern\fR as a regular expression and match it against the text
using the rules for regular expressions (see the \fBregexp\fR command
and the \fBre_syntax\fR page for
details). The default matching automatically passes both the
\fB\-lineanchor\fR and \fB\-linestop\fR options to the regexp engine (unless
\fB\-nolinestop\fR is used), so that \fI^$\fR match beginning and end of line,
and \fI.\fR, \fI[^\fR sequences will never match the newline character
\fI\en\fR.
.\" OPTION: -nolinestop
.TP
\fB\-nolinestop\fR
.
This allows \fI.\fR and \fI[^\fR sequences to match the newline character
\fI\en\fR, which they will otherwise not do (see the \fBregexp\fR command for
details). This option is only meaningful if \fB\-regexp\fR is also given, and
an error will be thrown otherwise. For example, to match the entire text, use
.QW "\fIpathName \fBsearch \-nolinestop \-regexp\fR \N'34'.*\N'34' 1.0" .
.\" OPTION: -nocase
.TP
\fB\-nocase\fR
.
Ignore case differences between the pattern and the text.
.\" OPTION: -count
.TP
\fB\-count\fI varName\fR
.
The argument following \fB\-count\fR gives the name of a variable; if a match
is found, the number of index positions between beginning and end of the
matching range will be stored in the variable. If there are no embedded images
or windows in the matching range (and there are no elided characters if
\fB\-elide\fR is not given), this is equivalent to the number of characters
matched. In either case, the range \fImatchIdx\fR to \fImatchIdx + $count
chars\fR will return the entire matched text.
.\" OPTION: -all
.TP
\fB\-all\fR
.
Find all matches in the given range and return a list of the indices of the
first character of each match. If a \fB\-count\fI varName\fR switch is given,
then \fIvarName\fR is also set to a list containing one element for each
successful match. Note that, even for exact searches, the elements of this
list may be different, if there are embedded images, windows or hidden text.
Searches with \fB\-all\fR behave very similarly to the Tcl command \fBregexp
\-all\fR, in that overlapping matches are not normally returned. For example,
applying an \fB\-all\fR search of the pattern
.QW \ew+
against
.QW "hello there"
will just match twice, once for each word, and matching
.QW "Z[a\-z]+Z"
against
.QW ZooZooZoo
will just match once.
.\" OPTION: -overlap
.TP
\fB\-overlap\fR
.
When performing \fB\-all\fR searches, the normal behaviour is that matches
which overlap an already-found match will not be returned. This switch changes
that behaviour so that all matches which are not totally enclosed within
another match are returned. For example, applying an \fB\-overlap\fR search of
the pattern
.QW \ew+
against
.QW "hello there"
will just match twice (i.e. no different to just \fB\-all\fR), but matching
.QW Z[a\-z]+Z
against
.QW ZooZooZoo
will now match twice. An error will be thrown if this switch is used without
\fB\-all\fR.
.\" OPTION: -strictlimits
.TP
\fB\-strictlimits\fR
.
When performing any search, the normal behaviour is that the start and stop
limits are checked with respect to the start of the matching text. With the
\fB\-strictlimits\fR flag, the entire matching range must lie inside the start
and stop limits specified for the match to be valid.
.\" OPTION: -elide
.TP
\fB\-elide\fR
.
Find elided (hidden) text as well. By default only displayed text is searched.
.\" OPTION: --
.TP
\fB\-\|\-\fR
.
This switch has no effect except to terminate the list of switches: the next
argument will be treated as \fIpattern\fR even if it starts with \fB\-\fR.
.PP
The matching range may be within a single line of text, or run across multiple
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
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







-









-

-
+
-




-





-
+
-





-

-
+







beginning or end of the text is reached, the search continues at the other end
until the starting location is reached again; if \fIstopIndex\fR is specified,
no wrap-around will occur. This means that, for example, if the search is
\fB\-forwards\fR but \fIstopIndex\fR is earlier in the text than
\fIstartIndex\fR, nothing will ever be found. See \fBKNOWN BUGS\fR below for a
number of minor limitations of the \fIpathName \fBsearch\fR command.
.RE
.\" METHOD: see
.TP
\fIpathName \fBsee \fIindex\fR
.
Adjusts the view in the window so that the character given by \fIindex\fR is
completely visible. If \fIindex\fR is already visible then the command does
nothing. If \fIindex\fR is a short distance out of view, the command adjusts
the view just enough to make \fIindex\fR visible at the edge of the window.
If \fIindex\fR is far out of view, then the command centers \fIindex\fR in the
window.
.\" METHOD: sync
.TP
\fIpathName \fBsync\fR ?\fB\-command \fIcommand\fR?
\fIpathName \fBsync\fR ?\fB-command \fIcommand\fR?
.
Controls the synchronization of the view of the text widget.
.RS
.TP
\fIpathName \fBsync\fR
.
Immediately brings the line metrics up-to-date by forcing computation of any
outdated line heights. The command returns immediately if there is no such
outdated line heights, otherwise it returns only at the end of the computation.
The command returns an empty string.
.TP
\fIpathName \fBsync \-command \fIcommand\fR
\fIpathName \fBsync -command \fIcommand\fR
.
Schedules \fIcommand\fR to be executed (by the event loop) exactly once as soon
as all line heights are up-to-date. If there are no pending line metrics
calculations, the scheduling is immediate. The command returns the empty
string. \fBbgerror\fR is called on \fIcommand\fR failure.
.RE
.\" METHOD: tag
.TP
\fIpathName \fBtag \fIoption \fR?\fIarg ...\fR?
\fIpathName \fBtag \fIoption \fR?\fIarg arg ...\fR?
.
This command is used to manipulate tags. The exact behavior of the command
depends on the \fIoption\fR argument that follows the \fBtag\fR argument. The
following forms of the command are currently supported:
.RS
.TP
\fIpathName \fBtag add \fItagName index1 \fR?\fIindex2 index1 index2 ...\fR?
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
1729
1730
1731
1732
1733
1734
1735


1736
1737


1738
1739
1740
1741
1742
1743

1744


1745
1746
1747
1748
1749
1750
1751
1752







-
-
+
+
-
-
+





-
+
-
-
+







the command returns the \fIscript\fR associated with \fItagName\fR and
\fIsequence\fR (an error occurs if there is no such binding). If both
\fIscript\fR and \fIsequence\fR are omitted then the command returns a list of
all the sequences for which bindings have been defined for \fItagName\fR.
.RS
.PP
The only events for which bindings may be specified are those related to the
mouse and keyboard (such as \fBEnter\fR, \fBLeave\fR, \fBButton\fR,
\fBMotion\fR, and \fBKey\fR) or virtual events. Mouse and keyboard event
mouse and keyboard (such as \fBEnter\fR, \fBLeave\fR, \fBButtonPress\fR,
\fBMotion\fR, and \fBKeyPress\fR) or virtual events. Event bindings for a text
bindings for a text widget respectively use the \fBcurrent\fR and \fBinsert\fR
marks described under \fBMARKS\fR above. An
widget use the \fBcurrent\fR mark described under \fBMARKS\fR above. An
\fBEnter\fR event triggers for a tag when the tag first becomes present on the
current character, and a \fBLeave\fR event triggers for a tag when it ceases
to be present on the current character. \fBEnter\fR and \fBLeave\fR events can
happen either because the \fBcurrent\fR mark moved or because the character at
that position changed. Note that these events are different than \fBEnter\fR
and \fBLeave\fR events for windows. Mouse events are directed to the current
and \fBLeave\fR events for windows. Mouse and keyboard events are directed to
character, while keyboard events are directed to the insert character.
If a virtual event is used in a binding, that binding
the current character. If a virtual event is used in a binding, that binding
can trigger only if the virtual event is defined by an underlying
mouse-related or keyboard-related event.
.PP
It is possible for the current character to have multiple tags, and for each
of them to have a binding for a particular event sequence. When this occurs,
one binding is invoked for each tag, in order from lowest-priority to highest
priority. If there are multiple matching bindings for a single tag, then the
1922
1923
1924
1925
1926
1927
1928
1929

1930
1931
1932
1933
1934
1935
1936
1828
1829
1830
1831
1832
1833
1834

1835
1836
1837
1838
1839
1840
1841
1842







-
+







starting at \fIindex2\fR will be considered). If several matching ranges
exist, the one closest to \fIindex1\fR is chosen. The command's return value
is a list containing two elements, which are the index of the first character
of the range and the index of the character just after the last one in the
range. If no matching range is found then the return value is an empty string.
If \fIindex2\fR is not given then it defaults to the beginning of the text.
.TP
\fIpathName \fBtag raise \fItagName \fR?\fIaboveThis\fR?
\fIpathName\fB tag raise \fItagName \fR?\fIaboveThis\fR?
.
Changes the priority of tag \fItagName\fR so that it is just higher in
priority than the tag whose name is \fIaboveThis\fR. If \fIaboveThis\fR is
omitted, then \fItagName\fR's priority is changed to make it highest priority
of all tags.
.TP
\fIpathName \fBtag ranges \fItagName\fR
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959

1960
1961
1962
1963
1964
1965
1966
1856
1857
1858
1859
1860
1861
1862

1863

1864
1865
1866
1867
1868
1869
1870
1871







-

-
+







\fIindex2\fR is not affected). A single command may contain any number of
\fIindex1\fR\-\fIindex2\fR pairs. If the last \fIindex2\fR is omitted then the
tag is removed from the single character at \fIindex1\fR. If there are no
characters in the specified range (e.g. \fIindex1\fR is past the end of the
file or \fIindex2\fR is less than or equal to \fIindex1\fR) then the command
has no effect. This command returns an empty string.
.RE
.\" METHOD: window
.TP
\fIpathName \fBwindow \fIoption \fR?\fIarg ...\fR?
\fIpathName \fBwindow \fIoption \fR?\fIarg arg ...\fR?
.
This command is used to manipulate embedded windows. The behavior of the
command depends on the \fIoption\fR argument that follows the \fBwindow\fR
argument. The following forms of the command are currently supported:
.RS
.TP
\fIpathName \fBwindow cget \fIindex option\fR
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
1896
1897
1898
1899
1900
1901
1902

1903
1904
1905
1906
1907
1908
1909







-







information on the options that are supported. Returns an empty string.
.TP
\fIpathName \fBwindow names\fR
.
Returns a list whose elements are the names of all windows currently embedded
in \fIwindow\fR.
.RE
.\" METHOD: xview
.TP
\fIpathName \fBxview \fIoption args\fR
.
This command is used to query and change the horizontal position of the text
in the widget's window. It can take any of the following forms:
.RS
.TP
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
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







-
-
-
-
+
+
+
+




-
+
-
-
-
+
+
+



-







Adjusts the view in the window so that \fIfraction\fR of the horizontal span
of the text is off-screen to the left. \fIFraction\fR is a fraction between 0
and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBpages\fR,
\fBpixels\fR, or \fBunits\fR. If \fIwhat\fR is \fBpages\fR or
\fBunits\fR then \fInumber\fR must be an integer, otherwise number may be
specified in any of the forms acceptable to \fBTk_GetPixels\fR, such as
\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBunits\fR, \fBpages\fR or
\fBpixels\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then \fInumber\fR
must be an integer, otherwise number may be specified in any of the forms
acceptable to \fBTk_GetPixels\fR, such as
.QW 2.0c
or
.QW 1i
(the result is rounded to the nearest integer value. If no units are given,
pixels are assumed). If \fIwhat\fR is \fBpages\fR then the view adjusts by
pixels are assumed). If \fIwhat\fR is \fBunits\fR, the view adjusts left or
\fInumber\fR screenfuls; if it is \fBpixels\fR then the view adjusts by
\fInumber\fR pixels; if it is \fBunits\fR, the view adjusts left or
right by \fInumber\fR average-width characters on the display. If \fInumber\fR is
right by \fInumber\fR average-width characters on the display; if it is
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls; if it is
\fBpixels\fR then the view adjusts by \fInumber\fR pixels. If \fInumber\fR is
negative then characters farther to the left become visible; if it is positive
then characters farther to the right become visible.
.RE
.\" METHOD: yview
.TP
\fIpathName \fByview \fR?\fIargs\fR?
.
This command is used to query and change the vertical position of the text in
the widget's window. It can take any of the following forms:
.RS
.TP
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081




2082
2083
2084
2085
2086
2087
2088
1974
1975
1976
1977
1978
1979
1980




1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991







-
-
-
-
+
+
+
+







the widget will never scroll beyond the last pixel, and so a value of 1 will
effectively be rounded back to whatever fraction ensures the last pixel is at
the bottom of the window, and some other pixel is at the top.
.TP
\fIpathName \fByview scroll \fInumber what\fR
.
This command adjust the view in the window up or down according to
\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBpages\fR,
\fBpixels\fR, or \fBunits\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then
\fInumber\fR must be an integer, otherwise number may be specified in any of
the forms acceptable to \fBTk_GetPixels\fR, such as
\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBunits\fR, \fBpages\fR or
\fBpixels\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then \fInumber\fR
must be an integer, otherwise number may be specified in any of the forms
acceptable to \fBTk_GetPixels\fR, such as
.QW 2.0c
or
.QW 1i
(the result is rounded to the nearest integer value. If no units are given,
pixels are assumed). If \fIwhat\fR is \fBunits\fR, the view adjusts up or down
by \fInumber\fR lines on the display; if it is \fBpages\fR then the view
adjusts by \fInumber\fR screenfuls; if it is \fBpixels\fR then the view
2120
2121
2122
2123
2124
2125
2126
2127

2128
2129
2130
2131


2132
2133

2134
2135
2136
2137
2138
2139
2140
2023
2024
2025
2026
2027
2028
2029

2030

2031


2032
2033
2034

2035
2036
2037
2038
2039
2040
2041
2042







-
+
-

-
-
+
+

-
+







This command makes the first character on the line after the one given by
\fInumber\fR visible at the top of the window. \fINumber\fR must be an
integer. This command used to be used for scrolling, but now it is obsolete.
.RE
.SH BINDINGS
.PP
Tk automatically creates class bindings for texts that give them the following
default behavior.
default behavior. In the descriptions below,
In the descriptions below,
.QW word
is dependent on the value of
the \fBtcl_wordchars\fR variable.  See \fBtclvars\fR(n).
is dependent on the value of the \fBtcl_wordchars\fR variable. See
\fBtclvars\fR(n).
.IP [1]
Clicking mouse button 1 positions the insertion cursor at the closest edge of the
Clicking mouse button 1 positions the insertion cursor just before the
character underneath the mouse cursor, sets the input focus to this widget,
and clears any selection in the widget. Dragging with mouse button 1 strokes
out a selection between the insertion cursor and the character under the
mouse.
.IP [2]
Double-clicking with mouse button 1 selects the word under the mouse and
positions the insertion cursor at the start of the word. Dragging after a
2153
2154
2155
2156
2157
2158
2159
2160

2161
2162
2163
2164



2165
2166
2167
2168
2169
2170
2171
2055
2056
2057
2058
2059
2060
2061

2062




2063
2064
2065
2066
2067
2068
2069
2070
2071
2072







-
+
-
-
-
-
+
+
+







.IP [5]
Clicking mouse button 1 with the Control key down will reposition the
insertion cursor without affecting the selection.
.IP [6]
If any normal printing characters are typed, they are inserted at the point of
the insertion cursor.
.IP [7]
The view in the widget can be adjusted by dragging with the middle mouse
The view in the widget can be adjusted by dragging with mouse button 2. If
button (button 2, or button 3 in TkAqua). If the middle mouse button is
clicked without moving the mouse, the selection is copied into the text at the
position of the mouse cursor. The Insert key also inserts the selection,
but at the position of the insertion cursor.
mouse button 2 is clicked without moving the mouse, the selection is copied
into the text at the position of the mouse cursor. The Insert key also inserts
the selection, but at the position of the insertion cursor.
.IP [8]
If the mouse is dragged out of the widget while button 1 is pressed, the entry
will automatically scroll to make more text visible (if there is more text
off-screen on the side where the mouse left the window).
.IP [9]
The Left and Right keys move the insertion cursor one character to the left or
right; they also clear any selection in the text. If Left or Right is typed
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263



2264
2265
2266
2267
2268
2269
2270
2153
2154
2155
2156
2157
2158
2159



2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171







-
-
-


+
+
+







.IP [28]
Control-o opens a new line by inserting a newline character in front of the
insertion cursor without moving the insertion cursor.
.IP [29]
Meta-backspace and Meta-Delete delete the word to the left of the insertion
cursor.
.IP [30]
Control-t reverses the order of the two characters to the right of the
insertion cursor.
.IP [31]
Control-x deletes whatever is selected in the text widget after copying it to
the clipboard.
.IP [31]
Control-t reverses the order of the two characters to the right of the
insertion cursor.
.IP [32]
Control-z undoes the last edit action if the \fB\-undo\fR option is true.
Does nothing otherwise.
.IP [33]
Control-Z (or Control-y on Windows) reapplies the last undone edit action if
the \fB\-undo\fR option is true. Does nothing otherwise.
.PP
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
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







-
+















-
+







means in the case where the first extra line added results in no match and
Tcl's regexp system returns the incorrect code and adding a second extra line
would actually match, the text widget will return the wrong result. In
practice this is a rare problem, but it can occur, for example:
.CS
pack [\fBtext\fR .t]
\&.t insert 1.0 "aaaa\enbbbb\encccc\enbbbb\enaaaa\en"
\&.t search -regexp -- {(a+|b+\enc+\enb+)+\ena+} 1.0
\&.t search \-regexp \-\- {(a+|b+\enc+\enb+)+\ena+} 1.0
.CE
will not find a match when one exists of 19 characters starting from the first
.QW b .
.PP
Whenever one possible match is fully enclosed in another, the search command
will attempt to ensure only the larger match is returned. When performing
backwards regexp searches it is possible that Tcl will not always achieve
this, in the case where a match is preceded by one or more short,
non-overlapping matches, all of which are preceded by a large match which
actually encompasses all of them. The search algorithm used by the widget does
not look back arbitrarily far for a possible match which might cover large
portions of the widget. For example:
.CS
pack [\fBtext\fR .t]
\&.t insert 1.0 "aaaa\enbbbb\enbbbb\enbbbb\enbbbb\\n"
\&.t search -regexp -backward -- {b+\en|a+\en(b+\en)+} end
\&.t search \-regexp \-backward \-\- {b+\en|a+\en(b+\en)+} end
.CE
matches at
.QW 5.0
when a true greedy match would match at
.QW 1.0 .
Similarly if we add \fB\-all\fR to this case, it matches at all of
.QW 5.0 ,

Changes to doc/tk.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32







-
+










-







.TH tk n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk \- Manipulate Tk internal state
.SH SYNOPSIS
\fBtk\fI option \fR?\fIarg ...\fR?
\fBtk\fR \fIoption \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBtk\fR command provides access to miscellaneous
elements of Tk's internal state.
Most of the information manipulated by this command pertains to the
application as a whole, or to a screen or display, rather than to a
particular window.
The command can take any of a number of different forms
depending on the \fIoption\fR argument.  The legal forms are:
.\" METHOD: appname
.TP
\fBtk appname \fR?\fInewName\fR?
.
If \fInewName\fR is not specified, this command returns the name
of the application (the name that may be used in \fBsend\fR
commands to communicate with the application).
If \fInewName\fR is specified, then the name of the application
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
40
41
42
43
44
45
46

47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85

86
87









88
89
90
91
92
93
94







-







-












-


















-


-


-
-
-
-
-
-
-
-
-







\fInewName\fR should not start with a capital letter.
This will interfere with option processing, since names starting with
capitals are assumed to be classes;  as a result, Tk may not
be able to find some options for the application.
If sends have been disabled by deleting the \fBsend\fR command,
this command will reenable them and recreate the \fBsend\fR
command.
.\" METHOD: busy
.TP
\fBtk busy \fIsubcommand\fR ...
.
This command controls the marking of window hierarchies as
.QW busy ,
rendering them non-interactive while some other operation is proceeding. For
more details see the \fBbusy\fR manual page.
.\" METHOD: caret
.TP
\fBtk caret \fIwindow \fR?\fB\-x \fIx\fR? ?\fB\-y \fIy\fR? ?\fB\-height \fIheight\fR?
.
Sets and queries the caret location for the display of the specified
Tk window \fIwindow\fR.  The caret is the per-display cursor location
used for indicating global focus (e.g. to comply with Microsoft
Accessibility guidelines), as well as for location of the over-the-spot
XIM (X Input Methods) or Windows IME windows.  If no options are specified,
the last values used for setting the caret are return in option-value pair
format.  \fB\-x\fR and \fB\-y\fR represent window-relative coordinates, and
\fB\-height\fR is the height of the current cursor location, or the height
of the specified \fIwindow\fR if none is given.
.\" METHOD: inactive
.TP
\fBtk inactive \fR?\fB\-displayof \fIwindow\fR? ?\fBreset\fR?
.
Returns a positive integer, the number of milliseconds since the last
time the user interacted with the system. If the \fB\-displayof\fR
option is given then the return value refers to the display of
\fIwindow\fR; otherwise it refers to the display of the application's
main window.
.RS
.PP
\fBtk inactive\fR will return \-1, if querying the user inactive time
is not supported by the system, and in safe interpreters.
.PP
If the literal string \fBreset\fR is given as an additional argument,
the timer is reset and an empty string is returned. Resetting the
inactivity time is forbidden in safe interpreters and will throw an
error if tried.
.RE
.\" METHOD: fontchooser
.TP
\fBtk fontchooser \fIsubcommand\fR ...
.
Controls the Tk font selection dialog. For more details see the
\fBfontchooser\fR manual page.
.\" METHOD: print
.TP
\fBtk print \fIwindow\fR
.
The \fBtk print\fR command posts a dialog that allows users to print output
from the \fBcanvas\fR and \fBtext\fR widgets. The printing will be done using
platform-native APIs and dialogs where available. For more details see the
\fBprint\fR manual page.
.\" METHOD: scaling
.TP
\fBtk scaling \fR?\fB\-displayof \fIwindow\fR? ?\fInumber\fR?
.
Sets and queries the current scaling factor used by Tk to convert between
physical units (for example, points, inches, or millimeters) and pixels.  The
\fInumber\fR argument is a floating point number that specifies the number of
pixels per point on \fIwindow\fR's display.  If the \fIwindow\fR argument is
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163

164
165
166
106
107
108
109
110
111
112















113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129

130
131

132
133
134
135







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-







-
+

-
+



displayed 1.25 times as large as normal.  The initial value for the scaling
factor is set when the application starts, based on properties of the
installed monitor, but it can be changed at any time.  Measurements made
after the scaling factor is changed will use the new scaling factor, but it
is undefined whether existing widgets will resize themselves dynamically to
accommodate the new scaling factor.
.RE
.\" METHOD: sysnotify
.TP
\fBtk sysnotify \fP \fItitle\fP? \fImessage\fP?
.
The \fBtk sysnotify\fP  command creates a platform-specific system
notification alert. Its intent is to provide a brief, unobtrusive
notification to the user by popping up a window that briefly appears in a
corner of the screen. For more details see the \fBsysnotify\fR manual page.
.\" METHOD: systray
.TP
\fBtk systray create\fP \fIsubcommand...\fP
.
The \fBtk systray\fP command creates an icon in the platform-specific
tray. For more details see the \fBsystray\fR manual page.
.\" METHOD: useinputmethods
.TP
\fBtk useinputmethods \fR?\fB\-displayof \fIwindow\fR? ?\fIboolean\fR?
.
Sets and queries the state of whether Tk should use XIM (X Input Methods)
for filtering events.  The resulting state is returned.  XIM is used in
some locales (i.e., Japanese, Korean), to handle special input devices. This
feature is only significant on X.  If XIM support is not available, this
will always return 0.  If the \fIwindow\fR argument is omitted, it defaults
to the main window.  If the \fIboolean\fR argument is omitted, the current
state is returned.  This is turned on by default for the main display.
.\" METHOD: windowingsystem
.TP
\fBtk windowingsystem\fR
.
Returns the current Tk windowing system, one of
\fBx11\fR (X11-based), \fBwin32\fR (MS Windows),
or \fBaqua\fR (Mac OS X Aqua).
.SH "SEE ALSO"
busy(n), fontchooser(n), print(n), send(n), sysnotify(n), systray(n), winfo(n)
busy(n), fontchooser(n), send(n), winfo(n)
.SH KEYWORDS
application name, print, send, sysnotify, systray
application name, send
'\" Local Variables:
'\" mode: nroff
'\" End:

Added doc/tk4.0.ps.



























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
%!
%%BoundingBox: (atend)
%%Pages: (atend)
%%DocumentFonts: (atend)
%%EndComments
%%BeginProlog
%
% FrameMaker postscript_prolog 3.0, for use with FrameMaker 3.0
% This postscript_prolog file is Copyright (c) 1986-1991 Frame Technology
% Corporation.  All rights reserved.  This postscript_prolog file may be
% freely copied and distributed in conjunction with documents created using
% FrameMaker.
% NOTE
% This file fixes the problem with NeWS printers dithering color output.
% Any questions should be sent to [email protected]
%
% Known Problems:
%	Due to bugs in Transcript, the 'PS-Adobe-' is omitted from line 1
/FMversion (3.0) def
% Set up Color vs. Black-and-White

/FMPrintInColor { % once-thru loop gimmick
    % See if we're a NeWSprint printer
     /currentcanvas where {
        pop systemdict /separationdict known
	exit
     } if
% originally had the following, which should always be false:
%    /currentcanvas where {
%        pop currentcanvas /Color known {
%	    currentcanvas /Color get
%	    exit
%        } if
%    } if
    systemdict /colorimage known
    systemdict /currentcolortransfer known and
exit } loop def

% Uncomment the following line to force b&w on color printer
%   /FMPrintInColor false def
/FrameDict 195 dict def
systemdict /errordict known not {/errordict 10 dict def
		errordict /rangecheck {stop} put} if
% The readline in 23.0 doesn't recognize cr's as nl's on AppleTalk
FrameDict /tmprangecheck errordict /rangecheck get put
errordict /rangecheck {FrameDict /bug true put} put
FrameDict /bug false put
mark
% Some PS machines read past the CR, so keep the following 3 lines together!
currentfile 5 string readline
00
0000000000
cleartomark
errordict /rangecheck FrameDict /tmprangecheck get put
FrameDict /bug get {
	/readline {
		/gstring exch def
		/gfile exch def
		/gindex 0 def
		{
			gfile read pop
			dup 10 eq {exit} if
			dup 13 eq {exit} if
			gstring exch gindex exch put
			/gindex gindex 1 add def
		} loop
		pop
		gstring 0 gindex getinterval true
		} def
	} if
/FMVERSION {
	FMversion ne {
		/Times-Roman findfont 18 scalefont setfont
		100 100 moveto
		(FrameMaker version does not match postscript_prolog!)
		dup =
		show showpage
		} if
	} def
/FMLOCAL {
	FrameDict begin
	0 def
	end
	} def
	/gstring FMLOCAL
	/gfile FMLOCAL
	/gindex FMLOCAL
	/orgxfer FMLOCAL
	/orgproc FMLOCAL
	/organgle FMLOCAL
	/orgfreq FMLOCAL
	/yscale FMLOCAL
	/xscale FMLOCAL
	/manualfeed FMLOCAL
	/paperheight FMLOCAL
	/paperwidth FMLOCAL
/FMDOCUMENT {
	array /FMfonts exch def
	/#copies exch def
	FrameDict begin
	0 ne dup {setmanualfeed} if
	/manualfeed exch def
	/paperheight exch def
	/paperwidth exch def
	/yscale exch def
	/xscale exch def
	currenttransfer cvlit /orgxfer exch def
	currentscreen cvlit /orgproc exch def
	/organgle exch def /orgfreq exch def
	setpapername
	manualfeed {true} {papersize} ifelse
	{manualpapersize} {false} ifelse
	{desperatepapersize} if
	end
	} def
	/pagesave FMLOCAL
	/orgmatrix FMLOCAL
	/landscape FMLOCAL
/FMBEGINPAGE {
	FrameDict begin
	/pagesave save def
	3.86 setmiterlimit
	/landscape exch 0 ne def
	landscape {
		90 rotate 0 exch neg translate pop
		}
		{pop pop}
		ifelse
	xscale yscale scale
	/orgmatrix matrix def
	gsave
	} def
/FMENDPAGE {
	grestore
	pagesave restore
	end
	showpage
	} def
/FMFONTDEFINE {
	FrameDict begin
	findfont
	ReEncode
	1 index exch
	definefont
	FMfonts 3 1 roll
	put
	end
	} def
/FMFILLS {
	FrameDict begin
	array /fillvals exch def
	end
	} def
/FMFILL {
	FrameDict begin
	 fillvals 3 1 roll put
	end
	} def
/FMNORMALIZEGRAPHICS {
	newpath
	0.0 0.0 moveto
	1 setlinewidth
	0 setlinecap
	0 0 0 sethsbcolor
	0 setgray
	} bind def
	/fx FMLOCAL
	/fy FMLOCAL
	/fh FMLOCAL
	/fw FMLOCAL
	/llx FMLOCAL
	/lly FMLOCAL
	/urx FMLOCAL
	/ury FMLOCAL
/FMBEGINEPSF {
	end
	/FMEPSF save def
	/showpage {} def
	FMNORMALIZEGRAPHICS
	[/fy /fx /fh /fw /ury /urx /lly /llx] {exch def} forall
	fx fy translate
	rotate
	fw urx llx sub div fh ury lly sub div scale
	llx neg lly neg translate
	} bind def
/FMENDEPSF {
	FMEPSF restore
	FrameDict begin
	} bind def
FrameDict begin
/setmanualfeed {
%%BeginFeature *ManualFeed True
	 statusdict /manualfeed true put
%%EndFeature
	} def
/max {2 copy lt {exch} if pop} bind def
/min {2 copy gt {exch} if pop} bind def
/inch {72 mul} def
/pagedimen {
	paperheight sub abs 16 lt exch
	paperwidth sub abs 16 lt and
	{/papername exch def} {pop} ifelse
	} def
	/papersizedict FMLOCAL
/setpapername {
	/papersizedict 14 dict def
	papersizedict begin
	/papername /unknown def
		/Letter 8.5 inch 11.0 inch pagedimen
		/LetterSmall 7.68 inch 10.16 inch pagedimen
		/Tabloid 11.0 inch 17.0 inch pagedimen
		/Ledger 17.0 inch 11.0 inch pagedimen
		/Legal 8.5 inch 14.0 inch pagedimen
		/Statement 5.5 inch 8.5 inch pagedimen
		/Executive 7.5 inch 10.0 inch pagedimen
		/A3 11.69 inch 16.5 inch pagedimen
		/A4 8.26 inch 11.69 inch pagedimen
		/A4Small 7.47 inch 10.85 inch pagedimen
		/B4 10.125 inch 14.33 inch pagedimen
		/B5 7.16 inch 10.125 inch pagedimen
	end
	} def
/papersize {
	papersizedict begin
		/Letter {lettertray letter} def
		/LetterSmall {lettertray lettersmall} def
		/Tabloid {11x17tray 11x17} def
		/Ledger {ledgertray ledger} def
		/Legal {legaltray legal} def
		/Statement {statementtray statement} def
		/Executive {executivetray executive} def
		/A3 {a3tray a3} def
		/A4 {a4tray a4} def
		/A4Small {a4tray a4small} def
		/B4 {b4tray b4} def
		/B5 {b5tray b5} def
		/unknown {unknown} def
	papersizedict dup papername known {papername} {/unknown} ifelse get
	end
	/FMdicttop countdictstack 1 add def
	statusdict begin stopped end
	countdictstack -1 FMdicttop {pop end} for
	} def
/manualpapersize {
	papersizedict begin
		/Letter {letter} def
		/LetterSmall {lettersmall} def
		/Tabloid {11x17} def
		/Ledger {ledger} def
		/Legal {legal} def
		/Statement {statement} def
		/Executive {executive} def
		/A3 {a3} def
		/A4 {a4} def
		/A4Small {a4small} def
		/B4 {b4} def
		/B5 {b5} def
		/unknown {unknown} def
	papersizedict dup papername known {papername} {/unknown} ifelse get
	end
	stopped
	} def
/desperatepapersize {
	statusdict /setpageparams known
		{
		paperwidth paperheight 0 1
		statusdict begin
		{setpageparams} stopped pop
		end
		} if
	} def
/savematrix {
	orgmatrix currentmatrix pop
	} bind def
/restorematrix {
	orgmatrix setmatrix
	} bind def
/dmatrix matrix def
/dpi    72 0 dmatrix defaultmatrix dtransform
    dup mul exch   dup mul add   sqrt def
/freq dpi 18.75 div 8 div round dup 0 eq {pop 1} if 8 mul dpi exch div def
/sangle 1 0 dmatrix defaultmatrix dtransform exch atan def
/DiacriticEncoding [
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /space /exclam /quotedbl
/numbersign /dollar /percent /ampersand /quotesingle /parenleft
/parenright /asterisk /plus /comma /hyphen /period /slash /zero /one
/two /three /four /five /six /seven /eight /nine /colon /semicolon
/less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K
/L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash
/bracketright /asciicircum /underscore /grave /a /b /c /d /e /f /g /h
/i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar
/braceright /asciitilde /.notdef /Adieresis /Aring /Ccedilla /Eacute
/Ntilde /Odieresis /Udieresis /aacute /agrave /acircumflex /adieresis
/atilde /aring /ccedilla /eacute /egrave /ecircumflex /edieresis
/iacute /igrave /icircumflex /idieresis /ntilde /oacute /ograve
/ocircumflex /odieresis /otilde /uacute /ugrave /ucircumflex
/udieresis /dagger /.notdef /cent /sterling /section /bullet
/paragraph /germandbls /registered /copyright /trademark /acute
/dieresis /.notdef /AE /Oslash /.notdef /.notdef /.notdef /.notdef
/yen /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/ordfeminine /ordmasculine /.notdef /ae /oslash /questiondown
/exclamdown /logicalnot /.notdef /florin /.notdef /.notdef
/guillemotleft /guillemotright /ellipsis /.notdef /Agrave /Atilde
/Otilde /OE /oe /endash /emdash /quotedblleft /quotedblright
/quoteleft /quoteright /.notdef /.notdef /ydieresis /Ydieresis
/fraction /currency /guilsinglleft /guilsinglright /fi /fl /daggerdbl
/periodcentered /quotesinglbase /quotedblbase /perthousand
/Acircumflex /Ecircumflex /Aacute /Edieresis /Egrave /Iacute
/Icircumflex /Idieresis /Igrave /Oacute /Ocircumflex /.notdef /Ograve
/Uacute /Ucircumflex /Ugrave /dotlessi /circumflex /tilde /macron
/breve /dotaccent /ring /cedilla /hungarumlaut /ogonek /caron
] def
/ReEncode {
	dup
	length
	dict begin
	{
	1 index /FID ne
		{def}
		{pop pop} ifelse
	} forall
	0 eq {/Encoding DiacriticEncoding def} if
	currentdict
	end
	} bind def
/graymode true def
	/bwidth FMLOCAL
	/bpside FMLOCAL
	/bstring FMLOCAL
	/onbits FMLOCAL
	/offbits FMLOCAL
	/xindex FMLOCAL
	/yindex FMLOCAL
	/x FMLOCAL
	/y FMLOCAL
/setpattern {
	 /bwidth  exch def
	 /bpside  exch def
	 /bstring exch def
	 /onbits 0 def  /offbits 0 def
	 freq sangle landscape {90 add} if
		{/y exch def
		 /x exch def
		 /xindex x 1 add 2 div bpside mul cvi def
		 /yindex y 1 add 2 div bpside mul cvi def
		 bstring yindex bwidth mul xindex 8 idiv add get
		 1 7 xindex 8 mod sub bitshift and 0 ne
		 {/onbits  onbits  1 add def 1}
		 {/offbits offbits 1 add def 0}
		 ifelse
		}
		setscreen
	 {} settransfer
	 offbits offbits onbits add div FMsetgray
	/graymode false def
	} bind def
/grayness {
	FMsetgray
	graymode not {
		/graymode true def
		orgxfer cvx settransfer
		orgfreq organgle orgproc cvx setscreen
		} if
	} bind def
	/HUE FMLOCAL
	/SAT FMLOCAL
	/BRIGHT FMLOCAL
	/Colors FMLOCAL
FMPrintInColor

	{
	/HUE 0 def
	/SAT 0 def
	/BRIGHT 0 def
	% array of arrays Hue and Sat values for the separations [HUE BRIGHT]
	/Colors
	[[0    0  ]    % black
	 [0    0  ]    % white
	 [0.00 1.0]    % red
	 [0.37 1.0]    % green
	 [0.60 1.0]    % blue
	 [0.50 1.0]    % cyan
	 [0.83 1.0]    % magenta
	 [0.16 1.0]    % comment / yellow
	 ] def

	/BEGINBITMAPCOLOR {
		BITMAPCOLOR} def
	/BEGINBITMAPCOLORc {
		BITMAPCOLORc} def
	/BEGINBITMAPTRUECOLOR {
		BITMAPTRUECOLOR } def
	/BEGINBITMAPTRUECOLORc {
		BITMAPTRUECOLORc } def
	/K {
		Colors exch get dup
		0 get /HUE exch store
		1 get /BRIGHT exch store
		  HUE 0 eq BRIGHT 0 eq and
			{1.0 SAT sub setgray}
			{HUE SAT BRIGHT sethsbcolor}
		  ifelse
		} def
	/FMsetgray {
		/SAT exch 1.0 exch sub store
		  HUE 0 eq BRIGHT 0 eq and
			{1.0 SAT sub setgray}
			{HUE SAT BRIGHT sethsbcolor}
		  ifelse
		} bind def
	}

	{
	/BEGINBITMAPCOLOR {
		BITMAPGRAY} def
	/BEGINBITMAPCOLORc {
		BITMAPGRAYc} def
	/BEGINBITMAPTRUECOLOR {
		BITMAPTRUEGRAY } def
	/BEGINBITMAPTRUECOLORc {
		BITMAPTRUEGRAYc } def
	/FMsetgray {setgray} bind def
	/K {
		pop
		} def
	}
ifelse
/normalize {
	transform round exch round exch itransform
	} bind def
/dnormalize {
	dtransform round exch round exch idtransform
	} bind def
/lnormalize {
	0 dtransform exch cvi 2 idiv 2 mul 1 add exch idtransform pop
	} bind def
/H {
	lnormalize setlinewidth
	} bind def
/Z {
	setlinecap
	} bind def
	/fillvals FMLOCAL
/X {
	fillvals exch get
	dup type /stringtype eq
	{8 1 setpattern}
	{grayness}
	ifelse
	} bind def
/V {
	gsave eofill grestore
	} bind def
/N {
	stroke
	} bind def
/M {newpath moveto} bind def
/E {lineto} bind def
/D {curveto} bind def
/O {closepath} bind def
	/n FMLOCAL
/L {
 	/n exch def
	newpath
	normalize
	moveto
	2 1 n {pop normalize lineto} for
	} bind def
/Y {
	L
	closepath
	} bind def
	/x1 FMLOCAL
	/x2 FMLOCAL
	/y1 FMLOCAL
	/y2 FMLOCAL
	/rad FMLOCAL
/R {
	/y2 exch def
	/x2 exch def
	/y1 exch def
	/x1 exch def
	x1 y1
	x2 y1
	x2 y2
	x1 y2
	4 Y
	} bind def
/RR {
	/rad exch def
	normalize
	/y2 exch def
	/x2 exch def
	normalize
	/y1 exch def
	/x1 exch def
	newpath
	x1 y1 rad add moveto
	x1 y2 x2 y2 rad arcto
	x2 y2 x2 y1 rad arcto
	x2 y1 x1 y1 rad arcto
	x1 y1 x1 y2 rad arcto
	closepath
	16 {pop} repeat
	} bind def
/C {
	grestore
	gsave
	R
	clip
	} bind def
	/FMpointsize FMLOCAL
/F {
	FMfonts exch get
	FMpointsize scalefont
	setfont
	} bind def
/Q {
	/FMpointsize exch def
	F
	} bind def
/T {
	moveto show
	} bind def
/RF {
	rotate
	0 ne {-1 1 scale} if
	} bind def
/TF {
	gsave
	moveto
	RF
	show
	grestore
	} bind def
/P {
	moveto
	0 32 3 2 roll widthshow
	} bind def
/PF {
	gsave
	moveto
	RF
	0 32 3 2 roll widthshow
	grestore
	} bind def
/S {
	moveto
	0 exch ashow
	} bind def
/SF {
	gsave
	moveto
	RF
	0 exch ashow
	grestore
	} bind def
/B {
	moveto
	0 32 4 2 roll 0 exch awidthshow
	} bind def
/BF {
	gsave
	moveto
	RF
	0 32 4 2 roll 0 exch awidthshow
	grestore
	} bind def
/G {
	gsave
	newpath
	normalize translate 0.0 0.0 moveto
	dnormalize scale
	0.0 0.0 1.0 5 3 roll arc
	closepath fill
	grestore
	} bind def
/A {
	gsave
	savematrix
	newpath
	2 index 2 div add exch 3 index 2 div sub exch
	normalize 2 index 2 div sub exch 3 index 2 div add exch
	translate
	scale
	0.0 0.0 1.0 5 3 roll arc
	restorematrix
	stroke
	grestore
	} bind def
	/x FMLOCAL
	/y FMLOCAL
	/w FMLOCAL
	/h FMLOCAL
	/xx FMLOCAL
	/yy FMLOCAL
	/ww FMLOCAL
	/hh FMLOCAL
	/FMsaveobject FMLOCAL
	/FMoptop FMLOCAL
	/FMdicttop FMLOCAL
/BEGINPRINTCODE {
	/FMdicttop countdictstack 1 add def
	/FMoptop count 4 sub def
	/FMsaveobject save def
	userdict begin
	/showpage {} def
	FMNORMALIZEGRAPHICS
	3 index neg 3 index neg translate
	} bind def
/ENDPRINTCODE {
	count -1 FMoptop {pop pop} for
	countdictstack -1 FMdicttop {pop end} for
	FMsaveobject restore
	} bind def
/gn {
	0
	{	46 mul
		cf read pop
		32 sub
		dup 46 lt {exit} if
		46 sub add
		} loop
	add
	} bind def
	/str FMLOCAL
/cfs {
	/str sl string def
	0 1 sl 1 sub {str exch val put} for
	str def
	} bind def
/ic [
	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0223
	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0223
	0
	{0 hx} {1 hx} {2 hx} {3 hx} {4 hx} {5 hx} {6 hx} {7 hx} {8 hx} {9 hx}
	{10 hx} {11 hx} {12 hx} {13 hx} {14 hx} {15 hx} {16 hx} {17 hx} {18 hx}
	{19 hx} {gn hx} {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}
	{13} {14} {15} {16} {17} {18} {19} {gn} {0 wh} {1 wh} {2 wh} {3 wh}
	{4 wh} {5 wh} {6 wh} {7 wh} {8 wh} {9 wh} {10 wh} {11 wh} {12 wh}
	{13 wh} {14 wh} {gn wh} {0 bl} {1 bl} {2 bl} {3 bl} {4 bl} {5 bl} {6 bl}
	{7 bl} {8 bl} {9 bl} {10 bl} {11 bl} {12 bl} {13 bl} {14 bl} {gn bl}
	{0 fl} {1 fl} {2 fl} {3 fl} {4 fl} {5 fl} {6 fl} {7 fl} {8 fl} {9 fl}
	{10 fl} {11 fl} {12 fl} {13 fl} {14 fl} {gn fl}
	] def
	/sl FMLOCAL
	/val FMLOCAL
	/ws FMLOCAL
	/im FMLOCAL
	/bs FMLOCAL
	/cs FMLOCAL
	/len FMLOCAL
	/pos FMLOCAL
/ms {
	/sl exch def
	/val 255 def
	/ws cfs
	/im cfs
	/val 0 def
	/bs cfs
	/cs cfs
	} bind def
400 ms
/ip {
	is
	0
	cf cs readline pop
	{	ic exch get exec
		add
		} forall
	pop

	} bind def
/wh {
	/len exch def
	/pos exch def
	ws 0 len getinterval im pos len getinterval copy pop
	pos len
	} bind def
/bl {
	/len exch def
	/pos exch def
	bs 0 len getinterval im pos len getinterval copy pop
	pos len
	} bind def
/s1 1 string def
/fl {
	/len exch def
	/pos exch def
	/val cf s1 readhexstring pop 0 get def
	pos 1 pos len add 1 sub {im exch val put} for
	pos len
	} bind def
/hx {
	3 copy getinterval
	cf exch readhexstring pop pop
	} bind def
	/h FMLOCAL
	/w FMLOCAL
	/d FMLOCAL
	/lb FMLOCAL
	/bitmapsave FMLOCAL
	/is FMLOCAL
	/cf FMLOCAL
/wbytes {
	dup
	8 eq {pop} {1 eq {7 add 8 idiv} {3 add 4 idiv} ifelse} ifelse
	} bind def
/BEGINBITMAPBWc {
	1 {} COMMONBITMAPc
	} bind def
/BEGINBITMAPGRAYc {
	8 {} COMMONBITMAPc
	} bind def
/BEGINBITMAP2BITc {
	2 {} COMMONBITMAPc
	} bind def
/COMMONBITMAPc {
	/r exch def
	/d exch def
	gsave
	translate rotate scale /h exch def /w exch def
	/lb w d wbytes def
	sl lb lt {lb ms} if
	/bitmapsave save def
	r
	/is im 0 lb getinterval def
	ws 0 lb getinterval is copy pop
	/cf currentfile def
	w h d [w 0 0 h neg 0 h]
	{ip} image
	bitmapsave restore
	grestore
	} bind def
/BEGINBITMAPBW {
	1 {} COMMONBITMAP
	} bind def
/BEGINBITMAPGRAY {
	8 {} COMMONBITMAP
	} bind def
/BEGINBITMAP2BIT {
	2 {} COMMONBITMAP
	} bind def
/COMMONBITMAP {
	/r exch def
	/d exch def
	gsave
	translate rotate scale /h exch def /w exch def
	/bitmapsave save def
	r
	/is w d wbytes string def
	/cf currentfile def
	w h d [w 0 0 h neg 0 h]
	{cf is readhexstring pop} image
	bitmapsave restore
	grestore
	} bind def
	/proc1 FMLOCAL
	/proc2 FMLOCAL
	/newproc FMLOCAL
/Fmcc {
    /proc2 exch cvlit def
    /proc1 exch cvlit def
    /newproc proc1 length proc2 length add array def
    newproc 0 proc1 putinterval
    newproc proc1 length proc2 putinterval
    newproc cvx
} bind def
/ngrayt 256 array def
/nredt 256 array def
/nbluet 256 array def
/ngreent 256 array def
	/gryt FMLOCAL
	/blut FMLOCAL
	/grnt FMLOCAL
	/redt FMLOCAL
	/indx FMLOCAL
	/cynu FMLOCAL
	/magu FMLOCAL
	/yelu FMLOCAL
	/k FMLOCAL
	/u FMLOCAL
/colorsetup {
	currentcolortransfer
	/gryt exch def
	/blut exch def
	/grnt exch def
	/redt exch def
	0 1 255 {
		/indx exch def
		/cynu 1 red indx get 255 div sub def
		/magu 1 green indx get 255 div sub def
		/yelu 1 blue indx get 255 div sub def
		/k cynu magu min yelu min def
		/u k currentundercolorremoval exec def
		nredt indx 1 0 cynu u sub max sub redt exec put
		ngreent indx 1 0 magu u sub max sub grnt exec put
		nbluet indx 1 0 yelu u sub max sub blut exec put
		ngrayt indx 1 k currentblackgeneration exec sub gryt exec put
	} for
	{255 mul cvi nredt exch get}
	{255 mul cvi ngreent exch get}
	{255 mul cvi nbluet exch get}
	{255 mul cvi ngrayt exch get}
	setcolortransfer
	{pop 0} setundercolorremoval
	{} setblackgeneration
	} bind def
	/tran FMLOCAL
/fakecolorsetup {
	/tran 256 string def
	0 1 255 {/indx exch def
		tran indx
		red indx get 77 mul
		green indx get 151 mul
		blue indx get 28 mul
		add add 256 idiv put} for
	currenttransfer
	{255 mul cvi tran exch get 255.0 div}
	exch Fmcc settransfer
} bind def
/BITMAPCOLOR {
	/d 8 def
	gsave
	translate rotate scale /h exch def /w exch def
	/bitmapsave save def
	colorsetup
	/is w d wbytes string def
	/cf currentfile def
	w h d [w 0 0 h neg 0 h]
	{cf is readhexstring pop} {is} {is} true 3 colorimage
	bitmapsave restore
	grestore
	} bind def
/BITMAPCOLORc {
	/d 8 def
	gsave
	translate rotate scale /h exch def /w exch def
	/lb w d wbytes def
	sl lb lt {lb ms} if
	/bitmapsave save def
	colorsetup
	/is im 0 lb getinterval def
	ws 0 lb getinterval is copy pop
	/cf currentfile def
	w h d [w 0 0 h neg 0 h]
	{ip} {is} {is} true 3 colorimage
	bitmapsave restore
	grestore
	} bind def
/BITMAPTRUECOLORc {
        gsave
        translate rotate scale /h exch def /w exch def
        /bitmapsave save def

        /is w string def

        ws 0 w getinterval is copy pop
        /cf currentfile def
        w h 8 [w 0 0 h neg 0 h]
        {ip} {gip} {bip} true 3 colorimage
        bitmapsave restore
        grestore
        } bind def
/BITMAPTRUECOLOR {
        gsave
        translate rotate scale /h exch def /w exch def
        /bitmapsave save def
        /is w string def
        /gis w string def
        /bis w string def
        /cf currentfile def
        w h 8 [w 0 0 h neg 0 h]
        { cf is readhexstring pop }
        { cf gis readhexstring pop }
        { cf bis readhexstring pop }
        true 3 colorimage
        bitmapsave restore
        grestore
        } bind def
/BITMAPTRUEGRAYc {
        gsave
        translate rotate scale /h exch def /w exch def
        /bitmapsave save def

        /is w string def

        ws 0 w getinterval is copy pop
        /cf currentfile def
        w h 8 [w 0 0 h neg 0 h]
        {ip gip bip w gray} image
        bitmapsave restore
        grestore
        } bind def
/ww FMLOCAL
/r FMLOCAL
/g FMLOCAL
/b FMLOCAL
/i FMLOCAL
/gray {
        /ww exch def
        /b exch def
        /g exch def
        /r exch def
        0 1 ww 1 sub { /i exch def r i get .299 mul g i get .587 mul
			b i get .114 mul add add r i 3 -1 roll floor cvi put } for
        r
        } bind def
/BITMAPTRUEGRAY {
        gsave
        translate rotate scale /h exch def /w exch def
        /bitmapsave save def
        /is w string def
        /gis w string def
        /bis w string def
        /cf currentfile def
        w h 8 [w 0 0 h neg 0 h]
        { cf is readhexstring pop
          cf gis readhexstring pop
          cf bis readhexstring pop w gray}  image
        bitmapsave restore
        grestore
        } bind def
/BITMAPGRAY {
	8 {fakecolorsetup} COMMONBITMAP
	} bind def
/BITMAPGRAYc {
	8 {fakecolorsetup} COMMONBITMAPc
	} bind def
/ENDBITMAP {
	} bind def
end
	/ALDsave FMLOCAL
	/ALDmatrix matrix def ALDmatrix currentmatrix pop
/StartALD {
	/ALDsave save def
	 savematrix
	 ALDmatrix setmatrix
	} bind def
/InALD {
	 restorematrix
	} bind def
/DoneALD {
	 ALDsave restore
	} bind def
%%EndProlog
%%BeginSetup
(3.0) FMVERSION
1 1 612 792 0 1 13 FMDOCUMENT
0 0 /Helvetica-Bold FMFONTDEFINE
1 0 /Times-Bold FMFONTDEFINE
2 0 /Times-Italic FMFONTDEFINE
3 0 /Times-Roman FMFONTDEFINE
4 0 /Helvetica FMFONTDEFINE
5 0 /Courier FMFONTDEFINE
6 0 /Courier-Oblique FMFONTDEFINE
32 FMFILLS
0 0 FMFILL
1 0.1 FMFILL
2 0.3 FMFILL
3 0.5 FMFILL
4 0.7 FMFILL
5 0.9 FMFILL
6 0.97 FMFILL
7 1 FMFILL
8 <0f1e3c78f0e1c387> FMFILL
9 <0f87c3e1f0783c1e> FMFILL
10 <cccccccccccccccc> FMFILL
11 <ffff0000ffff0000> FMFILL
12 <8142241818244281> FMFILL
13 <03060c183060c081> FMFILL
14 <8040201008040201> FMFILL
16 1 FMFILL
17 0.9 FMFILL
18 0.7 FMFILL
19 0.5 FMFILL
20 0.3 FMFILL
21 0.1 FMFILL
22 0.03 FMFILL
23 0 FMFILL
24 <f0e1c3870f1e3c78> FMFILL
25 <f0783c1e0f87c3e1> FMFILL
26 <3333333333333333> FMFILL
27 <0000ffff0000ffff> FMFILL
28 <7ebddbe7e7dbbd7e> FMFILL
29 <fcf9f3e7cf9f3f7e> FMFILL
30 <7fbfdfeff7fbfdfe> FMFILL
%%EndSetup
%%Page: "1" 1
%%BeginPaperSize: Letter
%%EndPaperSize
612 792 0 FMBEGINPAGE
98.1 675 512.1 675 2 L
7 X
0 K
V
2 H
0 Z
0 X
N
98.1 450 512.1 450 2 L
7 X
V
2 Z
0 X
N
98.1 108 512.1 126 R
7 X
V
0 10 Q
0 X
(1) 506.54 119.33 T
1 24 Q
-0.48 (Tk4.0 Overview and Porting Guide) 152.1 605 S
2 12 Q
(John Ouster) 152.1 563 T
(hout) 210.84 563 T
98.1 135 512.1 423 R
7 X
V
3 10 Q
0 X
(Tk version 4.0 is a major new release with many improvements, new features, and bug) 152.1 416.33 T
(\336xes. This document provides an introduction to the new features and describes the most) 152.1 404.33 T
-0.18 (common problems you are likely to encounter when porting scripts from Tk 3.6, the previ-) 152.1 392.33 P
(ous release. This is) 152.1 380.33 T
2 F
(not) 230.66 380.33 T
3 F
( an introduction to Tk: I assume that you are already familiar with) 243.43 380.33 T
(Tk 3.6 as described in the book) 152.1 368.33 T
2 F
(T) 279.79 368.33 T
(cl and the Tk T) 284.43 368.33 T
(oolkit) 343.48 368.33 T
3 F
(.) 366.24 368.33 T
-0.26 (The good news about Tk 4.0 is that it has many improvements over Tk 3.6. Here are a) 170.1 356.33 P
(few of the most important new features:) 152.1 344.33 T
3 12 Q
(\245) 152.1 329.33 T
3 10 Q
(Tk 4.0 includes a general-purpose mechanism for manipulating color images \050Tk 3.6) 162.9 329.33 T
(supports only monochrome images\051.) 162.9 317.33 T
3 12 Q
(\245) 152.1 302.33 T
3 10 Q
-0.17 (The text widget in Tk 4.0 includes many new features such as tab stops, embedded win-) 162.9 302.33 P
(dows, horizontal scrolling, and many new formatting options.) 162.9 290.33 T
3 12 Q
(\245) 152.1 275.33 T
3 10 Q
(The binding mechanism in Tk 4.0 is much more powerful in Tk 3.6.) 162.9 275.33 T
3 12 Q
(\245) 152.1 260.33 T
3 10 Q
(Motif compliance is much better) 162.9 260.33 T
(. For example, there is now support for keyboard tra-) 292.82 260.33 T
(versal and focus highlights.) 162.9 248.33 T
3 12 Q
(\245) 152.1 233.33 T
3 10 Q
(Many widgets have been improved. For example, buttons and labels can display multi-) 162.9 233.33 T
(line justi\336ed text, and scales can handle real values.) 162.9 221.33 T
(The bad news about Tk 4.0 is that it contains several incompatibilities with Tk 3.6.) 170.1 206.33 T
(Ever since the \336rst release of Tk I have assumed that there would eventually be a major) 152.1 194.33 T
(new release of Tk with substantial incompatibilities. I knew that I wouldn\325) 152.1 182.33 T
(t be able to get) 450.06 182.33 T
(all of the features of Tk right the \336rst time; rather than live forever with all of my early) 152.1 170.33 T
(mistakes, I wanted to have a chance to correct them. Tk 4.0 is that correction. I apologize) 152.1 158.33 T
-0.05 (for the incompatibilities, but I hope they improve Tk enough to justify the dif) 152.1 146.33 P
-0.05 (\336culties you) 460.55 146.33 P
44.1 351 98.1 423 C
35.1 360 197.1 414 R
7 X
0 K
V
1 9 Q
0 X
(FIGURE  1) 35.1 408 T
(T) 35.1 387 T
(ABLE  1) 40.43 387 T
26.1 351 125.1 423 R
7 X
V
40.5 63 571.5 729 C
FMENDPAGE
%%EndPage: "1" 2
%%Page: "2" 2
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(2) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
(encounter during porting. Tk 4.0 is a one-time correction: we will try very hard to avoid) 152.1 632.33 T
(substantial incompatibilities \050especially in Tk\325) 152.1 620.3 T
(s T) 337 620.3 T
(cl-level interfaces\051 in future releases.) 348.79 620.3 T
-0.4 (Sections 1-1) 170.1 608.3 P
-0.4 (1 cover the major areas of change in Tk 4.0: bindings, focus, text widgets,) 219.02 608.3 P
-0 (Motif compliance, other widget changes, images, color management, event handling, sup-) 152.1 596.26 P
(port for multiple displays, the) 152.1 584.23 T
5 F
(send) 273.14 584.23 T
3 F
( command, and the selection. Section 12 summarizes) 297.13 584.23 T
(several smaller changes. Section 13 lists all of the incompatibilities that af) 152.1 572.19 T
(fect T) 448.4 572.19 T
(cl scripts,) 471.29 572.19 T
-0.02 (along with suggestions for how to deal with them. The explanations here are not intended) 152.1 560.16 P
(to be comprehensive, but rather to introduce you to the issues; for complete information) 152.1 548.12 T
(on new or modi\336ed commands, refer to the reference documentation that comes with the) 152.1 536.09 T
(distribution.) 152.1 524.05 T
98.1 480.7 512.1 483.72 C
152.1 481.92 512.1 481.92 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 482.21 143.1 482.21 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(1) 134.63 487.72 T
(Bindings) 152.1 487.72 T
3 10 Q
-0.35 (The changes for Tk 4.0 that are most likely to af) 152.1 464.03 P
-0.35 (fect existing T) 341.31 464.03 P
-0.35 (cl scripts are those related to) 397.64 464.03 P
(bindings. The new binding mechanism in Tk 4.0 is much more powerful than that of Tk) 152.1 452 T
(3.6, particularly in the way it allows behaviors to be combined, but several incompatible) 152.1 439.96 T
(changes were required to implement the new features. These changes are likely to break) 152.1 427.93 T
(most Tk 3.6 scripts. Fortunately) 152.1 415.89 T
(, it is relatively easy to upgrade your bindings to work) 279.16 415.89 T
(under Tk 4.0.) 152.1 403.86 T
-0.27 (The basic mechanism for bindings is the same as in Tk 3.6. A binding associates a T) 170.1 391.86 P
-0.27 (cl) 502.65 391.86 P
(script with a particular event \050or sequence of events\051 occurring in one or more windows;) 152.1 379.82 T
-0.11 (the script will be invoked automatically whenever the event sequence occurs in any of the) 152.1 367.79 P
-0.13 (speci\336ed windows. The Tk 4.0 binding mechanism has three major feature changes. First,) 152.1 355.75 P
(there is a more general mechanism for specifying the relationship between windows and) 152.1 343.72 T
(bindings, called) 152.1 331.68 T
2 F
(binding tags) 217.89 331.68 T
3 F
(. Second, the con\337ict resolution mechanism \050which is) 267.6 331.68 T
(invoked when more than one binding matches an event\051 has been changed to allow more) 152.1 319.65 T
(than one binding script to execute for a single event. Third, the) 152.1 307.61 T
5 F
(Any) 405.81 307.61 T
3 F
( modi\336er is now) 423.8 307.61 T
(implicit in all binding patterns. These changes are discussed separately in the subsections) 152.1 295.58 T
(that follow) 152.1 283.54 T
(.) 195.04 283.54 T
-0.16 (Overall, the main ef) 170.1 271.54 P
-0.16 (fect of Tk 4.0\325) 249.37 271.54 P
-0.16 (s binding changes is that it allows more bindings to) 306.06 271.54 P
(trigger than Tk 3.6 does. Feedback from the T) 152.1 259.51 T
(cl/Tk community about the Tk 3.6 binding) 335.71 259.51 T
(mechanism indicated that it was too conservative about triggering bindings. This caused) 152.1 247.47 T
(the system to lose behaviors relatively easily and made the binding structure fragile. It) 152.1 235.44 T
-0.35 (appears to be easier to deal with too many binding invocations than too few) 152.1 223.4 P
-0.35 (, so Tk 4.0 tries) 449.17 223.4 P
(to err in this direction.) 152.1 211.37 T
0 F
(1.1) 127.41 181.37 T
(Binding tags) 152.1 181.37 T
3 F
(In Tk 3.6 you specify the window\050s\051 for a binding in one of three ways:) 152.1 165.37 T
3 12 Q
(\245) 152.1 150.37 T
3 10 Q
(Y) 162.9 150.37 T
(ou give the name of a window) 169.12 150.37 T
(, such as) 289.49 150.37 T
5 F
(.a.b.c) 326.13 150.37 T
3 F
(, in which case the binding applies) 362.11 150.37 T
(only to that window) 162.9 138.33 T
(.) 242.49 138.33 T
FMENDPAGE
%%EndPage: "2" 3
%%Page: "3" 3
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(1 Bindings) 98.1 668.33 T
0 F
(3) 506.54 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 12 Q
0 X
(\245) 152.1 632.33 T
3 10 Q
-0.06 (Y) 162.9 632.33 P
-0.06 (ou give the name of a class, such as) 169.12 632.33 P
5 F
-0.15 (Button) 313.45 632.33 P
3 F
-0.06 (, in which case the binding applies to all) 349.43 632.33 P
(the windows of that class.) 162.9 620.33 T
3 12 Q
(\245) 152.1 605.33 T
3 10 Q
(Y) 162.9 605.33 T
(ou specify) 169.12 605.33 T
5 F
(all) 212.97 605.33 T
3 F
(, in which case the binding applies to all windows.) 230.96 605.33 T
-0.3 (In Tk4.0 you specify the window\050s\051 using a more general mechanism called a) 170.1 590.33 P
2 F
-0.3 (binding) 479.35 590.33 P
(tag) 152.1 578.33 T
3 F
(. A binding tag may be an arbitrary string, but if it starts with a \322.\323 then it must be the) 164.87 578.33 T
(name of a window) 152.1 566.33 T
(. If you specify a class name or) 225.56 566.33 T
5 F
(all) 352.4 566.33 T
3 F
( as a binding tag, it will usually) 370.39 566.33 T
-0.1 (have the same ef) 152.1 554.33 P
-0.1 (fect as in Tk 3.6, but you may also specify other strings that were not per-) 218.51 554.33 P
(mitted in Tk 3.6.) 152.1 542.33 T
-0.07 (Each window in Tk 4.0 has a list of binding tags. When an event occurs in a window) 170.1 530.33 P
-0.07 (,) 507.17 530.33 P
-0.19 (Tk fetches the window\325) 152.1 518.33 P
-0.19 (s binding tags and matches the event against all of the bindings for) 245.62 518.33 P
-0.09 (any of the tags. By default, the binding tags for a window consist of the window name, its) 152.1 506.33 P
-0.14 (class name, the name of its nearest toplevel ancestor) 152.1 494.33 P
-0.14 (, and) 359.61 494.33 P
5 F
-0.33 (all) 381.26 494.33 P
3 F
-0.14 (. For example, a button win-) 399.25 494.33 P
(dow named) 152.1 482.33 T
5 F
(.b) 200.95 482.33 T
3 F
( will have the tags) 212.95 482.33 T
5 9 Q
(.b Button . all) 179.1 468 T
3 10 Q
(by default and all of the following bindings will apply to the window:) 152.1 454.33 T
5 9 Q
(bind .b <Enter> {identify "press here to exit"}) 179.1 440 T
(bind Button <Button-Release-1> {%W invoke}) 179.1 430 T
(bind all <Help> {help %W}) 179.1 420 T
3 10 Q
(So far) 152.1 406.33 T
(, this mechanism produces the same behavior as in Tk 3.6 except that bindings cre-) 175.85 406.33 T
(ated for a toplevel also apply to its descendants \050see Section 1.5 for more on this issue\051.) 152.1 394.33 T
(Y) 170.1 382.33 T
(ou can use the) 176.32 382.33 T
5 F
(bindtags) 235.71 382.33 T
3 F
( command to change the binding tags for a window or) 283.69 382.33 T
(their order) 152.1 370.33 T
(. For example, the command) 193.46 370.33 T
5 9 Q
(bindtags .b {.b MyButton all}) 179.1 356 T
3 10 Q
(will change the binding tags for) 152.1 342.33 T
5 F
(.b) 281.46 342.33 T
3 F
( to the three values in the list. This provides a simple) 293.45 342.33 T
(way to make radical changes the behavior of a window) 152.1 330.33 T
(. After the above command is) 371.55 330.33 T
(invoked none of the) 152.1 318.33 T
5 F
(Button) 234.26 318.33 T
3 F
( class bindings will apply to) 270.24 318.33 T
5 F
(.b) 384.63 318.33 T
3 F
(. Instead, bindings for) 396.63 318.33 T
5 F
-0.81 (MyButton) 152.1 306.33 P
3 F
-0.34 ( will apply; this might give the button a totally dif) 200.07 306.33 P
-0.34 (ferent set of behaviors than a) 395.88 306.33 P
(normal button. In addition, the) 152.1 294.33 T
5 F
(bindtags) 276.75 294.33 T
3 F
( command removes the \322.\323 tag, so bindings on) 324.72 294.33 T
(\322.\323 will not apply to) 152.1 282.33 T
5 F
(.b) 234.27 282.33 T
3 F
(.) 246.27 282.33 T
(Y) 170.1 270.33 T
(ou can also place additional tags on a window with the) 176.32 270.33 T
5 F
(bindtags) 397.55 270.33 T
3 F
( command to) 445.53 270.33 T
(combine a number of behaviors. For example,) 152.1 258.33 T
5 9 Q
(bindtags .b {.b MyButton Button . all}) 179.1 244 T
3 10 Q
(gives) 152.1 230.33 T
5 F
(.b) 175.7 230.33 T
3 F
( the behaviors of) 187.69 230.33 T
5 F
(MyButton) 257.08 230.33 T
3 F
( bindings as well as those speci\336ed by) 305.06 230.33 T
5 F
(Button) 459.96 230.33 T
3 F
(bindings.) 152.1 218.33 T
(Overall, binding tags are similar to the tag mechanisms already used internally by) 170.1 206.33 T
(canvas and text widgets in Tk 3.6, except that binding tags apply to windows instead of) 152.1 194.33 T
(graphical objects or textual characters.) 152.1 182.33 T
FMENDPAGE
%%EndPage: "3" 4
%%Page: "4" 4
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(4) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
0 F
0 X
(1.2) 127.41 632.33 T
(Con\337ict resolution) 152.1 632.33 T
3 F
(It is possible for several bindings to match a particular event. In Tk 3.6 at most one event) 152.1 616.33 T
(is actually allowed to trigger: a set of con\337ict resolution rules determines the winner) 152.1 604.22 T
(. In) 488.27 604.22 T
(general, a more speci\336c binding takes precedence over a less speci\336c binding. For exam-) 152.1 592.11 T
-0.27 (ple, any binding for a speci\336c widget takes precedence over any class or) 152.1 580 P
5 F
-0.66 (all) 439.96 580 P
3 F
-0.27 ( binding, and) 457.95 580 P
(a binding on) 152.1 567.89 T
5 F
(<Control-a>) 204.57 567.89 T
3 F
( takes precedence over a binding on) 270.54 567.89 T
5 F
(<KeyPress>.) 416.24 567.89 T
3 F
-0.26 (The mechanism for con\337ict resolution is similar in Tk 4.0 except that one binding can) 170.1 555.89 P
-0.35 (trigger for) 152.1 543.78 P
2 F
-0.35 (each) 194.7 543.78 P
3 F
-0.35 ( binding tag on the window where the event occurs. The bindings trigger in) 213.57 543.78 P
(the order of the tags. Thus if button) 152.1 531.67 T
5 F
(.b) 296.17 531.67 T
3 F
( has the default binding tags, one binding for) 308.16 531.67 T
5 F
(.b) 489.71 531.67 T
3 F
(can trigger) 152.1 519.56 T
(, followed by one for) 194.72 519.56 T
5 F
(Button) 281.32 519.56 T
3 F
(, followed by one for \322) 317.3 519.56 T
5 F
(.) 408.34 519.56 T
3 F
(\323, followed by one for) 414.34 519.56 T
5 F
(all) 152.1 507.44 T
3 F
(. If there are no matching bindings for a given tag then none will trigger) 170.09 507.44 T
(, and if there) 456.98 507.44 T
(are several matching bindings for a given tag then a single one is chosen using the same) 152.1 495.33 T
(rules as in Tk 3.6.) 152.1 483.22 T
(The philosophy behind binding tags in Tk 4.0 is that each binding tag corresponds to) 170.1 471.22 T
(an independent behavior) 152.1 459.11 T
(, so bindings with dif) 249.96 459.11 T
(ferent tags should usually be additive. Sup-) 334.46 459.11 T
(pose you de\336ned the following binding:) 152.1 447 T
5 9 Q
(bind .b <Enter> {puts "press here to exit"}) 179.1 432.67 T
3 10 Q
(This binding will add to the behavior de\336ned by the Button class binding for) 152.1 419 T
5 F
(<Enter>) 460.81 419 T
3 F
(.) 502.79 419 T
(In Tk 3.6, the widget-speci\336c binding will replace the class binding, which will break the) 152.1 406.89 T
(behavior of the button so that it no longer has normal button behavior) 152.1 394.78 T
(.) 429.71 394.78 T
(Sometimes there need to be interactions between binding tags. For example, you) 170.1 382.78 T
(might wish to keep most of the default button behavior for) 152.1 370.67 T
5 F
(.b) 388.34 370.67 T
3 F
( but replace the default) 400.33 370.67 T
(behavior for) 152.1 358.56 T
5 F
(<ButtonRelease>) 203.72 358.56 T
3 F
( with some other behavior) 293.67 358.56 T
(. T) 397.49 358.56 T
(o allow bindings to be) 407.9 358.56 T
-0.17 (overridden, Tk 4.0 allows the) 152.1 346.44 P
5 F
-0.41 (break) 271.44 346.44 P
3 F
-0.17 ( command to be invoked from inside a binding. This) 301.43 346.44 P
(causes all remaining binding tags for that binding to be skipped. Consider the following) 152.1 334.33 T
(binding:) 152.1 322.22 T
5 9 Q
(bind .b <ButtonRelease-1> {myRelease .b; break}) 179.1 307.89 T
3 10 Q
-0.21 (This will cause the) 152.1 294.22 P
5 F
-0.5 (myRelease) 228.99 294.22 P
3 F
-0.21 ( procedure to be invoked, then the) 282.96 294.22 P
5 F
-0.5 (break) 420.28 294.22 P
3 F
-0.21 ( command will) 450.26 294.22 P
-0.37 (cause the class binding for the event to be skipped \050assuming that the widget name appears) 152.1 282.11 P
(before its class in the binding tags for) 152.1 270 T
5 F
(.b) 304.78 270 T
3 F
(\051, along with any bindings for other tags.) 316.77 270 T
2 F
(Note:) 119.09 254 T
-0.07 (Y) 152.1 254 P
-0.07 (ou cannot invoke) 156.74 254 P
6 F
-0.17 (break) 227.31 254 P
2 F
-0.07 ( fr) 257.29 254 P
-0.07 (om within the) 266.02 254 P
6 F
-0.17 (myRelease) 322.73 254 P
2 F
-0.07 ( pr) 376.7 254 P
-0.07 (ocedur) 387.64 254 P
-0.07 (e in the above example:) 415.03 254 P
-0.02 (this will generate a T) 152.1 242.89 P
-0.02 (cl err) 236.05 242.89 P
-0.02 (or) 257.59 242.89 P
-0.02 (. However) 265.37 242.89 P
-0.02 (, you can invoke the command \322) 305.31 242.89 P
6 F
-0.05 (return -code) 434.25 242.89 P
(break) 152.1 231.78 T
2 F
(\323 in the pr) 182.08 231.78 T
(ocedur) 223.64 231.78 T
(e to achieve the same effect as the) 251.03 231.78 T
6 F
(break) 389.25 231.78 T
2 F
( in the binding script.) 419.23 231.78 T
0 F
(1.3) 127.41 202.78 T
(Implicit Any) 152.1 202.78 T
3 F
-0.13 (In Tk 3.6 extraneous modi\336ers prevent a binding from matching an event. For example, if) 152.1 186.78 P
(a binding is de\336ned for) 152.1 174.67 T
5 F
(<Button-1>) 247.32 174.67 T
3 F
( and the mouse button is pressed with the) 307.29 174.67 T
5 F
(Num-) 474.68 174.67 T
(Lock) 152.1 162.56 T
3 F
( key down, then the binding will not match. If you want a binding to trigger even) 176.09 162.56 T
(when extraneous modi\336ers are present, you must specify the) 152.1 150.45 T
5 F
(Any) 396.37 150.45 T
3 F
( modi\336er) 414.36 150.45 T
(, as in) 450.33 150.45 T
5 F
(<Any-) 476.42 150.45 T
(Button-1>) 152.1 138.33 T
3 F
(.) 206.07 138.33 T
FMENDPAGE
%%EndPage: "4" 5
%%Page: "5" 5
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(1 Bindings) 98.1 668.33 T
0 F
(5) 506.54 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
-0.06 (In Tk 4.0, all bindings have the) 170.1 632.33 P
5 F
-0.15 (Any) 297.08 632.33 P
3 F
-0.06 ( modi\336er present implicitly) 315.08 632.33 P
-0.06 (. The) 423.35 632.33 P
5 F
-0.15 (Any) 446.26 632.33 P
3 F
-0.06 ( modi\336er is) 464.25 632.33 P
(still allowed for compatibility) 152.1 620.33 T
(, but it has no meaning. Thus a binding for) 270.55 620.33 T
5 F
(<Button-1>) 443.23 620.33 T
3 F
(will match a button press event even if) 152.1 608.33 T
5 F
(NumLock) 309.21 608.33 T
3 F
(,) 351.19 608.33 T
5 F
(Shift) 356.19 608.33 T
3 F
(,) 386.17 608.33 T
5 F
(Control) 391.17 608.33 T
3 F
(, or any combina-) 433.15 608.33 T
(tion of them. If you wish for a binding not to trigger when a modi\336er is present, you can) 152.1 596.33 T
(just de\336ne an empty binding for that modi\336er combination. For example,) 152.1 584.33 T
5 9 Q
(bind .b <Control-ButtonPress-1> {# this script is a no-op}) 179.1 570 T
3 10 Q
(creates a binding that will trigger on mouse button presses when the) 152.1 556.33 T
5 F
(Control) 426.36 556.33 T
3 F
( key is) 468.34 556.33 T
-0.22 (down. If there is also a) 152.1 544.33 P
5 F
-0.52 (<ButtonPress-1>) 244.35 544.33 P
3 F
-0.22 ( binding for) 334.3 544.33 P
5 F
-0.52 (.b) 383.35 544.33 P
3 F
-0.22 (, it will no longer be invoked) 395.34 544.33 P
-0.02 (if the) 152.1 532.33 P
5 F
-0.05 (Control) 175.37 532.33 P
3 F
-0.02 ( key is down, due to the con\337ict resolution rules. The script for the above) 217.35 532.33 P
(binding is just a T) 152.1 520.33 T
(cl comment, so it has no ef) 223.59 520.33 T
(fect when it is invoked. Alternatively) 330.84 520.33 T
(, you) 478.98 520.33 T
(could use) 152.1 508.33 T
5 F
(%s) 192.63 508.33 T
3 F
( in the binding script to extract the modi\336er state, then test to see that only) 204.62 508.33 T
(desired modi\336ers are present.) 152.1 496.33 T
0 F
(1.4) 127.41 466.33 T
(Porting problems: widget bindings vs. class bindings) 152.1 466.33 T
3 F
-0.38 (Y) 152.1 450.33 P
-0.38 (ou are likely to encounter two problems with bindings when you port Tk 3.6 scripts to Tk) 158.32 450.33 P
-0.18 (4.0: widget bindings vs. class bindings, and events on top-level windows. This section dis-) 152.1 438.33 P
(cusses the \336rst problem and the following section discusses the second problem.) 152.1 426.33 T
(In Tk 3.6, if a widget-speci\336c binding matches an event then no class binding will) 170.1 414.33 T
-0.15 (trigger for the event; in Tk 4.0 both bindings will trigger) 152.1 402.33 P
-0.15 (. Because of this change, you will) 375.75 402.33 P
-0.09 (need to modify most of your widget-speci\336c bindings in one of two ways. If a widget-spe-) 152.1 390.33 P
(ci\336c binding in Tk 3.6 was intended to supplement the class binding, this could only be) 152.1 378.33 T
(done by duplicating the code of the class binding in the widget binding script. This dupli-) 152.1 366.33 T
-0.02 (cated code is no longer necessary in Tk 4.0 and will probably interfere with the new class) 152.1 354.33 P
(bindings in Tk 4.0; you should remove the duplicated class code, leaving only the widget-) 152.1 342.33 T
(speci\336c code in the binding script. If a widget-speci\336c binding in Tk 3.6 was intended to) 152.1 330.33 T
-0.17 (override the class binding, this will no longer occur by default in Tk 4.0; you should add a) 152.1 318.33 P
5 F
-0.54 (break) 152.1 306.33 P
3 F
-0.22 ( command at the end of the binding script to prevent the class binding from trigger-) 182.08 306.33 P
(ing. If a widget binding in Tk 3.6 didn\325) 152.1 294.33 T
(t con\337ict with a class binding, then you will not) 308.49 294.33 T
(need to modify it for Tk 4.0. For example, a widget binding for) 152.1 282.33 T
5 F
(<Help>) 407.49 282.33 T
3 F
( in a text widget) 443.47 282.33 T
(would not need to be modi\336ed, since it doesn\325) 152.1 270.33 T
(t con\337ict with a class binding.) 336.53 270.33 T
0 F
(1.5) 127.41 240.33 T
(Porting problems: events on top-levels) 152.1 240.33 T
3 F
-0.26 (The second binding problem you are likely to encounter in porting Tk 3.6 scripts to Tk 4.0) 152.1 224.33 P
(is that in Tk 4.0 a binding on a toplevel will match events on any of the internal windows) 152.1 212.33 T
(within that top-level. For example, suppose you have a binding created as follows:) 152.1 200.33 T
5 9 Q
(toplevel .t) 179.1 186 T
(button .t.b1 ...) 179.1 176 T
(button .t.b2 ...) 179.1 166 T
(bind .t <Enter> action) 179.1 156 T
FMENDPAGE
%%EndPage: "5" 6
%%Page: "6" 6
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(6) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
-0.27 (This binding will trigger not only when the mouse enters) 152.1 632.33 P
5 F
-0.64 (.t) 379.29 632.33 P
3 F
-0.27 (, but also when it enters either) 391.28 632.33 P
5 F
(.t.b1) 152.1 620.33 T
3 F
( or) 182.08 620.33 T
5 F
(.t.b2) 195.41 620.33 T
3 F
(. This is because the binding tags for a window include its nearest) 225.39 620.33 T
(ancestor toplevel by default. The toplevel is present in the binding tags to make it easy to) 152.1 608.33 T
(set up accelerator keys that apply in all the windows of a panel. For example,) 152.1 596.33 T
5 9 Q
(bind .t <Control-a> {controlAProc %W}) 179.1 582 T
3 10 Q
(will cause) 152.1 568.33 T
5 F
(controlAProc) 194.85 568.33 T
3 F
( to be invoked whenever) 266.81 568.33 T
5 F
(Control-a) 367.56 568.33 T
3 F
( is typed in any of the) 421.53 568.33 T
-0.12 (windows in) 152.1 556.33 P
5 F
-0.29 (.t) 200.72 556.33 P
3 F
-0.12 (. The procedure will receive the name of the focus window as its ar) 212.71 556.33 P
-0.12 (gument.) 479.62 556.33 P
(Unfortunately) 170.1 544.33 T
(, if you have created bindings on toplevel windows in your Tk 3.6) 225.52 544.33 T
-0.16 (scripts, they probably expect to trigger only for events in the toplevel, so the bindings will) 152.1 532.33 P
(misbehave under Tk 4.0. Fortunately you can reproduce the behavior of Tk 3.6 by using) 152.1 520.33 T
(the) 152.1 508.33 T
5 F
(%W) 166.81 508.33 T
3 F
( substitution in the binding script. For example, to ensure that) 178.8 508.33 T
5 F
(action) 427.28 508.33 T
3 F
( is invoked) 463.26 508.33 T
(only for) 152.1 496.33 T
5 F
(Enter) 186.52 496.33 T
3 F
( events in a toplevel window itself, create the following binding in place) 216.51 496.33 T
(of the one above:) 152.1 484.33 T
5 9 Q
(bind .t <Enter> {) 179.1 470 T
(if {"%W" == ".t"} {) 200.63 460 T
(action) 222.23 450 T
(}) 200.63 440 T
(}) 179.1 430 T
3 10 Q
-0.01 (When an) 152.1 416.33 P
5 F
-0.03 (Enter) 190.38 416.33 P
3 F
-0.01 ( event occurs in a descendant of) 220.36 416.33 P
5 F
-0.03 (.t) 350.45 416.33 P
3 F
-0.01 ( such as) 362.45 416.33 P
5 F
-0.03 (.t.x) 396.56 416.33 P
3 F
-0.01 (, a binding for) 420.54 416.33 P
5 F
-0.03 (Enter) 479.63 416.33 P
3 F
(in) 152.1 404.33 T
5 F
(.t.x) 162.37 404.33 T
3 F
( will trigger \336rst, if there is one. Then the above binding will trigger) 186.36 404.33 T
(. Since) 457.58 404.33 T
5 F
(%W) 487.29 404.33 T
3 F
(will be substituted with) 152.1 392.33 T
5 F
(.t.x) 248.17 392.33 T
3 F
(, the) 272.15 392.33 T
5 F
(if) 291.86 392.33 T
3 F
( condition will not be satis\336ed and the binding will) 303.86 392.33 T
(not do anything.) 152.1 380.33 T
-0.14 ( An alternative solution is to remove the toplevel window from the binding tags of all) 170.1 368.33 P
-0.12 (its internal windows. However) 152.1 356.33 P
-0.12 (, this means that you won\325) 274.03 356.33 P
-0.12 (t be able to take advantage of the) 378.73 356.33 P
(tag to create key bindings that apply everywhere within the toplevel.) 152.1 344.33 T
0 F
(1.6) 127.41 314.33 T
(Internal bindings in canvases and texts) 152.1 314.33 T
3 F
(The same changes in con\337ict resolution described in Section 1.2 also apply to bindings) 152.1 298.33 T
-0.05 (created internally for the items of a canvas or the tags of a text widget. If a canvas item or) 152.1 286.33 P
-0.29 (character of text has multiple tags, then one binding can trigger for each tag on each event.) 152.1 274.33 P
-0.32 (The bindings trigger in the priority order of the tags. Similar porting problems are likely to) 152.1 262.33 P
-0.19 (occur as described in Section 1.4; if a binding for one tag needs to override that of another) 152.1 250.33 P
(tag, you\325ll need to add a) 152.1 238.33 T
5 F
(break) 251.2 238.33 T
3 F
( command under Tk 4.0; if a binding for one tag dupli-) 281.18 238.33 T
-0.28 (cated the code from another tag\325) 152.1 226.33 P
-0.28 (s binding, so that they will compose in Tk 3.6, you\325ll have) 279.76 226.33 P
(to remove the duplicated code in Tk 4.0.) 152.1 214.33 T
FMENDPAGE
%%EndPage: "6" 7
%%Page: "7" 7
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(2 Focus management) 98.1 668.33 T
0 F
(7) 506.54 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
98.1 623.98 512.1 627 C
152.1 625.2 512.1 625.2 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 625.49 143.1 625.49 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(2) 134.63 631 T
(Focus management) 152.1 631 T
3 10 Q
(The input focus is another area where Tk 4.0 contains major changes. Fortunately) 152.1 607.31 T
(, the) 477.87 607.31 T
-0.09 (focus changes should not require as many modi\336cations to your Tk 3.6 scripts as the bind-) 152.1 595.31 P
(ing changes.) 152.1 583.31 T
0 F
(2.1) 127.41 553.31 T
(One focus window per toplevel) 152.1 553.31 T
3 F
(Tk 3.6 only keeps track of a single focus window for each application, and this results in) 152.1 537.31 T
(two problems. First, it doesn\325) 152.1 525.31 T
(t allow an application to use multiple displays since this) 269.64 525.31 T
-0.16 (could result in multiple simultaneous focus windows, one on each display) 152.1 513.31 P
-0.16 (. Second, the Tk) 444.99 513.31 P
(3.6 model doesn\325) 152.1 501.31 T
(t work very well for applications that have multiple toplevels: when the) 221.04 501.31 T
(mouse moves from one toplevel to another) 152.1 489.31 T
(, the focus window should switch to whatever) 322.7 489.31 T
-0.24 (window had the focus the last time the mouse was in the new toplevel, but Tk 3.6 does not) 152.1 477.31 P
(remember this information.) 152.1 465.31 T
(Tk 4.0 corrects both of these problems. It remembers one focus window for each) 170.1 453.31 T
(toplevel, which can be queried with the) 152.1 441.31 T
5 F
(focus -lastfor) 311.98 441.31 T
3 F
( command. When the win-) 395.94 441.31 T
(dow manager gives the focus to a toplevel window \050because the mouse entered the win-) 152.1 429.31 T
(dow or because you clicked on the window) 152.1 417.31 T
(, depending on the focus model being used by) 324.38 417.31 T
(the window manager\051, Tk passes the focus on to the remembered window) 152.1 405.31 T
(. Several win-) 446.23 405.31 T
(dows in an application can have the focus at the same time, one on each display the appli-) 152.1 393.31 T
(cation is using. When asking for the current focus window in the) 152.1 381.31 T
5 F
(focus) 413.31 381.31 T
3 F
( command, you) 443.29 381.31 T
(can use the) 152.1 369.31 T
5 F
(-displayof) 199 369.31 T
3 F
( switch to specify a particular display) 258.97 369.31 T
(.) 407.66 369.31 T
(When you set the focus to a window with the) 170.1 357.31 T
5 F
(focus) 353.31 357.31 T
3 F
( command, Tk remembers that) 383.29 357.31 T
(window as the most recent focus window for its toplevel. In addition, if the application) 152.1 345.31 T
(currently has the focus for the window\325) 152.1 333.31 T
(s display) 309.2 333.31 T
(, Tk moves the focus to the speci\336ed win-) 343.82 333.31 T
-0.35 (dow; this can be used, for example to move the focus to a dialog when the dialog is posted,) 152.1 321.31 P
(or to perform keyboard traversal among the toplevels of an application. If the application) 152.1 309.31 T
(doesn\325) 152.1 297.31 T
(t currently have the focus for the display) 178.57 297.31 T
(, then Tk will not normally take the focus) 339.74 297.31 T
(from its current owner) 152.1 285.31 T
(. However) 241.2 285.31 T
(, you can specify the) 282.43 285.31 T
5 F
(-force) 367.36 285.31 T
3 F
( ar) 403.34 285.31 T
(gument to) 413.43 285.31 T
5 F
(focus) 456.18 285.31 T
3 F
( to) 486.17 285.31 T
(insist that Tk grab the focus for this application \050in general this is probably not a good) 152.1 273.31 T
(idea, since it may clash with the window manager) 152.1 261.31 T
(\325) 352.05 261.31 T
(s focus policy\051.) 354.83 261.31 T
0 F
(2.2) 127.41 231.31 T
(Keyboard traversal) 152.1 231.31 T
3 F
-0.38 (Tk 4.0 has a much more complete implementation of keyboard traversal than Tk 3.6. In Tk) 152.1 215.31 P
(3.6 there is built-in support only for keyboard traversal of menus. In Tk 4.0 keyboard tra-) 152.1 203.31 T
(versal is implemented for all widgets. Y) 152.1 191.31 T
(ou can type) 311.27 191.31 T
5 F
(Tab) 359.85 191.31 T
3 F
( to move the focus among the) 377.84 191.31 T
-0.4 (windows within a toplevel and) 152.1 179.31 P
5 F
-0.95 (Shift+Tab) 275.31 179.31 P
3 F
-0.4 ( to move in the reverse direction. The order of) 329.28 179.31 P
-0.11 (traversal is de\336ned by the stacking order of widgets, with the lowest widget \336rst in the tra-) 152.1 167.31 P
(versal order) 152.1 155.31 T
(. All Tk widgets now provide a) 199 155.31 T
5 F
(-takefocus) 326.14 155.31 T
3 F
( option, which determines) 386.11 155.31 T
FMENDPAGE
%%EndPage: "7" 8
%%Page: "8" 8
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(8) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
(whether the window should accept the focus during traversal or be skipped. This option) 152.1 632.33 T
(has several features; see the) 152.1 620.33 T
5 F
(options.n) 265.61 620.33 T
3 F
( manual entry for details.) 319.58 620.33 T
(All of the Tk widgets provide a traversal highlight ring as required by Motif. The) 170.1 608.33 T
(highlight ring turns dark when the widget has the input focus. Its size and colors are con-) 152.1 596.33 T
(trolled by the) 152.1 584.33 T
5 F
(-highlightthickness) 207.9 584.33 T
3 F
(,) 321.84 584.33 T
5 F
(-highlightbackground) 326.83 584.33 T
3 F
(, and) 446.77 584.33 T
5 F
(-) 152.1 572.33 T
(highlightcolor) 158.1 572.33 T
3 F
( options. Y) 242.05 572.33 T
(ou may notice that widgets appear to have extra space) 285.2 572.33 T
(around them in Tk 4.0; this is due to the traversal highlight ring, which is normally the) 152.1 560.33 T
(same color as the background for widgets.) 152.1 548.33 T
0 F
(2.3) 127.41 518.33 T
(Support for focus-follows-mouse) 152.1 518.33 T
3 F
(Both Tk 3.6 and Tk 4.0 use an) 152.1 502.33 T
2 F
(explicit focus model) 275.91 502.33 T
3 F
( within a toplevel. This means that) 355.86 502.33 T
(moving the mouse among the windows of a toplevel does not normally move the focus;) 152.1 490.33 T
-0.06 (you have to click or perform some other action \050such as pressing) 152.1 478.33 P
5 F
-0.15 (Tab) 412.26 478.33 P
3 F
-0.06 (\051 to move the focus.) 430.25 478.33 P
(Tk 3.6 has no support for an) 152.1 466.33 T
2 F
(implicit focus model) 267.58 466.33 T
3 F
( where the window under the mouse) 348.64 466.33 T
(always has the focus. In Tk 4.0 you can invoke the library procedure) 152.1 454.33 T
5 F
(tk_focusFol-) 428.83 454.33 T
(lowsMouse) 152.1 442.33 T
3 F
( to switch to an implicit focus model; in this mode whenever the mouse) 206.07 442.33 T
(enters a new window the focus will switch to that window) 152.1 430.33 T
(.) 384.07 430.33 T
0 F
(2.4) 127.41 400.33 T
(No default focus window) 152.1 400.33 T
(, no \322none\323 focus.) 269.45 400.33 T
3 F
-0.16 (Tk 3.6 has the notion of a default focus window) 152.1 384.33 P
-0.16 (, which receives the focus if the focus win-) 341.56 384.33 P
(dow is deleted. It is also possible for an application to abandon the input focus by setting) 152.1 372.33 T
(the focus to) 152.1 360.33 T
5 F
(none) 201.23 360.33 T
3 F
(. In Tk 4.0 both of these features have been eliminated. There is no) 225.22 360.33 T
(default focus window) 152.1 348.33 T
(, and the focus can never be explicitly abandoned. If the focus win-) 238.05 348.33 T
(dow is destroyed, Tk resets the input focus to the toplevel containing the old focus win-) 152.1 336.33 T
(dow) 152.1 324.33 T
(. If the toplevel is destroyed, the window manager will reclaim the focus and move it) 168.66 324.33 T
(elsewhere.) 152.1 312.33 T
-0.18 (If you really want to abandon the focus in Tk 4.0 so that keyboard events are ignored,) 170.1 300.33 P
(you can create a dummy window with no key bindings \050set its binding tags to an empty) 152.1 288.33 T
(string to be sure\051, make sure that is never mapped, and give it the input focus.) 152.1 276.33 T
0 F
(2.5) 127.41 246.33 T
(Better focus events) 152.1 246.33 T
3 F
-0.13 (Tk 3.6 has a quirky event model for) 152.1 230.33 P
5 F
-0.32 (FocusIn) 296.77 230.33 P
3 F
-0.13 ( and) 338.75 230.33 P
5 F
-0.32 (FocusOut) 357.92 230.33 P
3 F
-0.13 ( events: when the window) 405.89 230.33 P
-0.23 (manager gives the focus to a toplevel, Tk generates a) 152.1 218.33 P
5 F
-0.55 (FocusIn) 364.36 218.33 P
3 F
-0.23 ( event for the toplevel and) 406.33 218.33 P
(another) 152.1 206.33 T
5 F
(FocusIn) 184.57 206.33 T
3 F
( event for the focus window) 226.55 206.33 T
(, but no events for any other windows.) 337.76 206.33 T
(When the window manager moves the focus somewhere else,) 152.1 194.33 T
5 F
(FocusOut) 400.79 194.33 T
3 F
( events are gen-) 448.77 194.33 T
-0 (erated for these same two windows. In Tk 4.0,) 152.1 182.33 P
5 F
-0 (FocusIn) 339.73 182.33 P
3 F
-0 ( and) 381.71 182.33 P
5 F
-0 (FocusOut) 401.13 182.33 P
3 F
-0 ( events are gen-) 449.11 182.33 P
-0.26 (erated in the same way as) 152.1 170.33 P
5 F
-0.63 (Enter) 255.43 170.33 P
3 F
-0.26 ( and) 285.41 170.33 P
5 F
-0.63 (Leave) 304.31 170.33 P
3 F
-0.26 ( events: when the focus arrives, a) 334.29 170.33 P
5 F
-0.63 (FocusIn) 467.89 170.33 P
3 F
-0.05 (event is generated for each window from the toplevel down to the focus window) 152.1 158.33 P
-0.05 (, with dif-) 472.5 158.33 P
FMENDPAGE
%%EndPage: "8" 9
%%Page: "9" 9
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(3 T) 98.1 668.33 T
(ext widgets) 111.43 668.33 T
0 F
(9) 506.54 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
-0.33 (ferent detail \336elds for dif) 152.1 632.33 P
-0.33 (ferent windows \050see Xlib documentation for information on these) 250.53 632.33 P
(values\051. The reverse happens when the focus leaves a window) 152.1 620.33 T
(.) 399.57 620.33 T
0 F
(2.6) 127.41 590.33 T
(Porting issues) 152.1 590.33 T
3 F
(If you didn\325) 152.1 574.33 T
(t have any special focus-related code in Tk 3.6, then you shouldn\325) 199.66 574.33 T
(t need to) 462.9 574.33 T
(make any changes for 4.0; things will just work better) 152.1 562.33 T
(. If you wrote code in Tk 3.6 to get) 366.96 562.33 T
(around the weaknesses with its focus mechanism, then you should remove most or all of) 152.1 550.33 T
(that code. For example, if you implemented keyboard traversal yourself, or if you built) 152.1 538.33 T
(your own mechanism to remember a separate focus window for each toplevel and give it) 152.1 526.33 T
(the input focus whenever the toplevel gets the focus, you can simply remove this code,) 152.1 514.33 T
-0.33 (since Tk 4.0 performs these functions for you. If you wrote code that depends on the weird) 152.1 502.33 P
-0.03 (event model in Tk 3.6, that code will need to be rewritten for Tk 4.0. The Tk 4.0 model is) 152.1 490.33 P
(general enough to duplicate any ef) 152.1 478.33 T
(fects that were possible in Tk 3.6.) 289.86 478.33 T
98.1 434.98 512.1 438 C
152.1 436.2 512.1 436.2 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 436.49 143.1 436.49 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(3) 134.63 442 T
(T) 152.1 442 T
(ext widgets) 158.54 442 T
3 10 Q
(T) 152.1 418.31 T
(ext widgets have under) 157.51 418.31 T
(gone a major overhaul for Tk 4.0 and they have improved in) 249.76 418.31 T
(many ways. The changes to text widgets are almost entirely upward-compatible from Tk) 152.1 406.31 T
(3.6.) 152.1 394.31 T
0 F
(3.1) 127.41 364.31 T
(Embedded windows.) 152.1 364.31 T
3 F
(Tk 3.6 supported two kinds of annotations in texts: marks and tags. In Tk 4.0 a third kind) 152.1 348.31 T
-0.04 (of annotation is available: an embedded window) 152.1 336.31 P
-0.04 (. This allows you to embed other widgets) 344.99 336.31 P
(inside a text widget, mixed in with the text. The text widget acts as a geometry manager) 152.1 324.31 T
(for these windows, laying them out and wrapping them just as if each embedded window) 152.1 312.31 T
(were a single character in the text. Y) 152.1 300.31 T
(ou can even have texts with nothing in them but) 297.64 300.31 T
(embedded windows. The) 152.1 288.31 T
5 F
(window) 254.8 288.31 T
3 F
( widget command for text widgets provides several) 290.78 288.31 T
(options to manage embedded windows.) 152.1 276.31 T
0 F
(3.2) 127.41 246.31 T
(More options for tags.) 152.1 246.31 T
3 F
(In Tk 4.0 tags support many new options providing additional control over how informa-) 152.1 230.31 T
(tion is displayed. Here is a summary of the new options:) 152.1 218.31 T
3 12 Q
(\245) 152.1 203.31 T
3 10 Q
(Y) 162.9 203.31 T
(ou can now specify tab stops with the) 169.12 203.31 T
5 F
(-tabs) 321.79 203.31 T
3 F
( option. Each tab stop can use left, cen-) 351.78 203.31 T
(ter) 162.9 191.31 T
(, right, or numeric justi\336cation. T) 173.04 191.31 T
(ab stops can also be speci\336ed for the widget as a) 305.6 191.31 T
(whole.) 162.9 179.31 T
3 12 Q
(\245) 152.1 164.31 T
3 10 Q
(Y) 162.9 164.31 T
(ou can specify justi\336cation \050left, center or right\051 with the) 169.12 164.31 T
5 F
(-justify) 398.12 164.31 T
3 F
( option.) 446.09 164.31 T
FMENDPAGE
%%EndPage: "9" 10
%%Page: "10" 10
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(10) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 12 Q
0 X
(\245) 152.1 632.33 T
3 10 Q
(Y) 162.9 632.33 T
(ou can now specify line spacing with three options,) 169.12 632.33 T
5 F
(-spacing1) 376.75 632.33 T
3 F
(,) 430.72 632.33 T
5 F
(-spacing2) 435.72 632.33 T
3 F
(, and) 489.69 632.33 T
5 F
(-) 162.9 620.2 T
(spacing3) 168.9 620.2 T
3 F
(, which control the spacing above a line, between wrapped lines, and) 216.87 620.2 T
(below a line.) 162.9 608.06 T
3 12 Q
(\245) 152.1 593.06 T
3 10 Q
(Y) 162.9 593.06 T
(ou can now specify mar) 169.12 593.06 T
(gins with the) 264.41 593.06 T
5 F
(-lmargin1) 318.55 593.06 T
3 F
(,) 372.52 593.06 T
5 F
(-lmargin2) 377.52 593.06 T
3 F
(, and) 431.49 593.06 T
5 F
(-rmargin) 453.42 593.06 T
3 F
(options.) 162.9 580.92 T
3 12 Q
(\245) 152.1 565.92 T
3 10 Q
-0.25 (Y) 162.9 565.92 P
-0.25 (ou can now adjust the vertical position of text \050e.g. for superscripts or subscripts\051 with) 169.12 565.92 P
(the) 162.9 553.79 T
5 F
(-offset) 177.61 553.79 T
3 F
( option.) 219.59 553.79 T
3 12 Q
(\245) 152.1 538.79 T
3 10 Q
-0.03 (Y) 162.9 538.79 P
-0.03 (ou can now specify the wrapping style \050word wrapping, character wrapping, or none\051) 169.12 538.79 P
(with the) 162.9 526.65 T
5 F
(-wrap) 197.88 526.65 T
3 F
( option.) 227.86 526.65 T
3 12 Q
(\245) 152.1 511.65 T
3 10 Q
(Y) 162.9 511.65 T
(ou can now request overstriking with the) 169.12 511.65 T
5 F
(-overstrike) 334.83 511.65 T
3 F
( option.) 400.8 511.65 T
0 F
(3.3) 127.41 481.65 T
(Bindings) 152.1 481.65 T
3 F
-0.19 (The default bindings for text widgets have been completely rewritten in Tk 4.0. They now) 152.1 465.65 P
(support almost all of the Motif behavior \050everything except add mode and secondary) 152.1 453.52 T
-0.36 (selections\051. They also include a substantial subset of the Emacs bindings for cursor motion) 152.1 441.38 P
(and basic editing. The) 152.1 429.24 T
5 F
(tk_strictMotif) 242.87 429.24 T
3 F
( variable disables the Emacs bindings.) 326.82 429.24 T
0 F
(3.4) 127.41 399.24 T
(Miscellaneous new features) 152.1 399.24 T
3 F
(In addition to the major changes described above, text widgets also include the following) 152.1 383.24 T
(new features:) 152.1 371.11 T
1 F
(Horizontal scr) 162.9 356.11 T
(olling) 224.07 356.11 T
3 F
(. T) 247.95 356.11 T
(ext widgets can now be scrolled horizontally as well as verti-) 258.36 356.11 T
(cally) 162.9 343.97 T
(, using the) 181.68 343.97 T
5 F
(-) 225.55 343.97 T
(xscrollcommand) 231.54 343.97 T
3 F
( option and the) 315.5 343.97 T
5 F
(xview) 377.68 343.97 T
3 F
( widget command.) 407.67 343.97 T
1 F
(Sear) 162.9 328.97 T
(ching) 182.15 328.97 T
3 F
(. T) 205.48 328.97 T
(ext widgets have a new) 215.88 328.97 T
5 F
(search) 311.64 328.97 T
3 F
( widget command, which provides ef) 347.62 328.97 T
(\336-) 495.67 328.97 T
-0.19 (cient searching of text widgets using either exact matching, glob-style matching, or reg-) 162.9 316.83 P
(ular expressions. Y) 162.9 304.7 T
(ou can search forwards or backwards.) 238.79 304.7 T
1 F
(Mark gravity) 162.9 289.7 T
3 F
(. In Tk 3.6 marks always had \322right gravity\323, which means they stick to) 219.71 289.7 T
(the character on the right side of the mark; if you insert at the position of a mark, the) 162.9 277.56 T
-0.1 (new character goes before the mark. In Tk 4.0 you can specify whether marks have left) 162.9 265.42 P
(or right gravity) 162.9 253.29 T
(.) 222.77 253.29 T
1 F
(Scr) 162.9 238.29 T
(een information) 177.15 238.29 T
3 F
(. In Tk 4.0 there are two new widget commands for text widgets) 245.16 238.29 T
(that return information about the screen layout. The) 162.9 226.15 T
5 F
(dlineinfo) 371.92 226.15 T
3 F
( widget command) 425.89 226.15 T
(returns the bounding box of a display line \050all the information displayed on one line of) 162.9 214.02 T
(the window) 162.9 201.88 T
(, which may be either a whole line of text or a partial line if wrapping has) 209.16 201.88 T
(occurred\051. The) 162.9 189.74 T
5 F
(bbox) 224.23 189.74 T
3 F
( widget command returns the screen area occupied by a single) 248.21 189.74 T
(character) 162.9 177.61 T
(.) 198.97 177.61 T
1 F
(Extended insert command) 162.9 162.61 T
3 F
(. The) 275.06 162.61 T
5 F
(insert) 298.1 162.61 T
3 F
( widget command now supports an addi-) 334.08 162.61 T
-0.32 (tional ar) 162.9 150.47 P
-0.32 (gument giving a list of tags to apply to the new characters. Y) 195.43 150.47 P
-0.32 (ou can also include) 434 150.47 P
(several text and tag ar) 162.9 138.33 T
(guments in a single) 250.42 138.33 T
5 F
(insert) 330.38 138.33 T
3 F
( command.) 366.36 138.33 T
FMENDPAGE
%%EndPage: "10" 11
%%Page: "11" 11
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(4 Better Motif compliance) 98.1 668.33 T
0 F
(1) 501.54 668.33 T
(1) 506.54 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
1 F
0 X
(See command) 162.9 632.33 T
3 F
(. There is a new) 222.03 632.33 T
5 F
(see) 288.08 632.33 T
3 F
( widget command, which adjusts the view in the) 306.07 632.33 T
(widget if needed to ensure that a particular character is visible in the window) 162.9 620.29 T
(.) 470.07 620.29 T
0 F
(3.5) 127.41 590.29 T
(Porting issues: tag stickiness, change in end) 152.1 590.29 T
3 F
(There are two changes in text widgets that may require modi\336cations to Tk 3.6 scripts.) 152.1 574.29 T
-0.06 (The \336rst change has to do with tag stickiness. In Tk 3.6, tags are sticky to the right: if you) 152.1 562.24 P
(insert new text just after a tagged range, the new text acquires the tags of the preceding) 152.1 550.19 T
(character) 152.1 538.14 T
(. If you insert text before a tagged range in Tk 3.6, the new characters do not) 188.17 538.14 T
-0.34 (acquire the tags of the range. In Tk 4.0, tags are not sticky on either side: new text acquires) 152.1 526.09 P
(a tag from surrounding characters only if the tag is present on both sides of the insertion) 152.1 514.05 T
(position. The sticky behavior in Tk 3.6 was rarely useful and special code was often) 152.1 502 T
(needed to work around it. Y) 152.1 489.95 T
(ou should be able to eliminate this code in Tk 4.0.) 263.24 489.95 T
(The second incompatible change in text widgets is that the index) 170.1 477.95 T
5 F
(end) 431.32 477.95 T
3 F
( now refers to) 449.31 477.95 T
-0.14 (the position just after the \336nal newline in the text, whereas in Tk 3.6 it referred to the posi-) 152.1 465.9 P
-0.1 (tion just before the \336nal newline. This makes it possible to apply tags to the \336nal newline,) 152.1 453.86 P
(which was not possible in Tk 3.6, but you may need to modify your scripts if you depend) 152.1 441.81 T
(on the old position of) 152.1 429.76 T
5 F
(end) 240.11 429.76 T
3 F
(.) 258.1 429.76 T
98.1 386.4 512.1 389.43 C
152.1 387.63 512.1 387.63 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 387.92 143.1 387.92 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(4) 134.63 393.43 T
(Better Motif compliance) 152.1 393.43 T
3 10 Q
(All of the widgets have been modi\336ed in Tk 4.0 to improve their Motif compliance. This) 152.1 369.74 T
-0.3 (was done by adding features that were missing and reworking the bindings to comply with) 152.1 357.69 P
(Motif conventions. I believe that the widgets are now completely Motif compliant except) 152.1 345.64 T
(for the following missing features:) 152.1 333.6 T
3 12 Q
(\245) 152.1 318.6 T
3 10 Q
(There is no support for secondary selections.) 162.9 318.6 T
3 12 Q
(\245) 152.1 303.6 T
3 10 Q
(There is no support for \322add mode\323 in widgets such as texts and listboxes.) 162.9 303.6 T
3 12 Q
(\245) 152.1 288.6 T
3 10 Q
(There is no support for drag and drop.) 162.9 288.6 T
-0.02 (Please let me know if you \336nd any other discrepancies between the Tk widgets and Motif) 152.1 273.59 P
(widgets. W) 152.1 261.55 T
(e plan to eliminate the remaining incompatibilities over the next year or two.) 196.82 261.55 T
98.1 218.19 512.1 221.21 C
152.1 219.41 512.1 219.41 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 219.7 143.1 219.7 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(5) 134.63 225.21 T
(W) 152.1 225.21 T
(idget changes) 163.31 225.21 T
3 10 Q
-0.07 (All of the Tk 4.0 widgets have been improved over their 3.6 counterparts, mostly in small) 152.1 201.52 P
-0.23 (and backwards compatible ways. Here is a summary of the widget improvements; see Sec-) 152.1 189.48 P
(tion 13 for information about incompatible changes.) 152.1 177.43 T
3 12 Q
(\245) 152.1 162.43 T
3 10 Q
(All widgets now have a) 162.9 162.43 T
5 F
(cget) 259.78 162.43 T
3 F
( command, which provides an easier way to retrieve the) 283.76 162.43 T
(value of a con\336guration option. In other situations where con\336guration options are) 162.9 150.38 T
(used, such as for menu entries or text tags, a) 162.9 138.33 T
5 F
(cget) 342.21 138.33 T
3 F
( command is also available.) 366.2 138.33 T
FMENDPAGE
%%EndPage: "11" 12
%%Page: "12" 12
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(12) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 12 Q
0 X
(\245) 152.1 632.33 T
3 10 Q
-0.22 (All widgets now have) 162.9 632.33 P
5 F
-0.53 (-highlightthickness) 251.96 632.33 P
3 F
-0.22 (,) 365.9 632.33 P
5 F
-0.53 (-highlightbackground) 370.68 632.33 P
3 F
-0.22 (, and) 490.61 632.33 P
5 F
(-) 162.9 620.33 T
(highlightcolor) 168.9 620.33 T
3 F
( options for displaying a highlight ring when the widget \050or one) 252.85 620.33 T
(of its descendants\051 has the input focus.) 162.9 608.33 T
3 12 Q
(\245) 152.1 593.33 T
3 10 Q
(Entry widgets now support justi\336cation and provide a) 162.9 593.33 T
5 F
(-show) 379.99 593.33 T
3 F
( option for \050not\051 display-) 409.97 593.33 T
(ing passwords. They will autosize to \336t their text if) 162.9 581.33 T
5 F
(-width 0) 369.17 581.33 T
3 F
( is speci\336ed.) 417.14 581.33 T
3 12 Q
(\245) 152.1 566.33 T
3 10 Q
-0.16 (The label/button family of widgets now supports multiline text and justi\336cation, includ-) 162.9 566.33 P
(ing new options) 162.9 554.33 T
5 F
(-wraplength) 229.25 554.33 T
3 F
( and) 295.22 554.33 T
5 F
(-justify) 314.65 554.33 T
3 F
(.  These features make the message) 361.97 554.33 T
-0.04 (widget obsolete. There is also a new) 162.9 542.33 P
5 F
-0.1 (-underline) 310.27 542.33 P
3 F
-0.04 ( option for highlighting a character) 370.23 542.33 P
(for keyboard traversal.) 162.9 530.33 T
3 12 Q
(\245) 152.1 515.33 T
3 10 Q
-0.23 (Listboxes now support all of the Motif selection modes, including single selection, mul-) 162.9 515.33 P
(tiple selection, and multiple disjoint selections, via the) 162.9 503.33 T
5 F
(-selectmode) 382.78 503.33 T
3 F
( option. They) 448.74 503.33 T
(will autosize to \336t their contents if) 162.9 491.33 T
5 F
(-width 0) 302.54 491.33 T
3 F
( or) 350.52 491.33 T
5 F
(-height 0) 363.84 491.33 T
3 F
( is speci\336ed. There are) 417.81 491.33 T
(new) 162.9 479.33 T
5 F
(see) 182.05 479.33 T
3 F
(,) 200.04 479.33 T
5 F
(bbox) 205.04 479.33 T
3 F
(, and) 229.02 479.33 T
5 F
(activate) 250.95 479.33 T
3 F
( widget commands.) 298.92 479.33 T
3 12 Q
(\245) 152.1 464.33 T
3 10 Q
(Canvas polygons now support) 162.9 464.33 T
5 F
(-outline) 286.16 464.33 T
3 F
( and) 334.14 464.33 T
5 F
(-width) 353.57 464.33 T
3 F
( options for drawing outlines.) 389.55 464.33 T
3 12 Q
(\245) 152.1 449.33 T
3 10 Q
-0.03 (Scale widgets now support real values as well as integers \050see the) 162.9 449.33 P
5 F
-0.08 (-resolution) 426.77 449.33 P
3 F
-0.03 ( and) 492.73 449.33 P
5 F
-0.54 (-digits) 162.9 437.33 P
3 F
-0.22 ( options\051, and they have a) 204.88 437.33 P
5 F
-0.54 (-variable) 308.73 437.33 P
3 F
-0.22 ( option to link to a T) 362.7 437.33 P
-0.22 (cl variable. They) 442.83 437.33 P
-0.28 (have two new widget commands,) 162.9 425.33 P
5 F
-0.67 (coords) 297.52 425.33 P
3 F
-0.28 ( and) 333.5 425.33 P
5 F
-0.67 (identify) 352.37 425.33 P
3 F
-0.28 (, and their bindings are now) 399.69 425.33 P
(de\336ned in T) 162.9 413.33 T
(cl rather than being hardwired in C code as in Tk 3.6.) 210.5 413.33 T
3 12 Q
(\245) 152.1 398.33 T
3 10 Q
(Scrollbar widgets now have a new interface to the controlling widget, which provides) 162.9 398.33 T
-0.04 (more \337exibility than the old style \050but the old style is still supported for compatibility\051.) 162.9 386.33 P
(There is a new option) 162.9 374.33 T
5 F
(-jump) 252 374.33 T
3 F
( to prevent continuous updates while dragging the slider) 281.98 374.33 T
(,) 505.88 374.33 T
-0.24 (and a new option) 162.9 362.33 P
5 F
-0.59 (-elementborderwidth) 232.98 362.33 P
3 F
-0.24 ( to control the border width of the arrows) 346.92 362.33 P
(and slider separately from the widget\325) 162.9 350.33 T
(s outer border) 314.18 350.33 T
(. There are four new widget com-) 369.14 350.33 T
(mands,) 162.9 338.33 T
5 F
(activate) 193.99 338.33 T
3 F
(,) 241.97 338.33 T
5 F
(delta) 246.96 338.33 T
3 F
(,) 276.95 338.33 T
5 F
(fraction) 281.95 338.33 T
3 F
(, and) 329.92 338.33 T
5 F
(identify) 351.85 338.33 T
3 F
(, and the default bindings) 399.17 338.33 T
(are now de\336ned in T) 162.9 326.33 T
(cl rather than being hardwired in C code as in Tk 3.6.) 244.91 326.33 T
3 12 Q
(\245) 152.1 311.33 T
3 10 Q
-0.13 (Menu entries now have several new con\336guration options such as) 162.9 311.33 P
5 F
-0.31 (-foreground) 426.97 311.33 P
3 F
-0.13 ( and) 492.93 311.33 P
5 F
-0.41 (-) 162.9 299.33 P
-0.41 (indicatoron) 168.9 299.33 P
3 F
-0.17 (, and tear) 234.86 299.33 P
-0.17 (-of) 271.23 299.33 P
-0.17 (f menus have been reimplemented to be more Motif-like.) 282.7 299.33 P
(New menu entries can be created in the middle of a menu using the) 162.9 287.33 T
5 F
(insert) 434.36 287.33 T
3 F
( widget) 470.34 287.33 T
(command, and there is a) 162.9 275.33 T
5 F
(type) 262.83 275.33 T
3 F
( widget command that returns the type of a menu entry) 286.81 275.33 T
(.) 505.45 275.33 T
3 12 Q
(\245) 152.1 260.33 T
3 10 Q
(Menubuttons now have a) 162.9 260.33 T
5 F
(-indicatoron) 266.16 260.33 T
3 F
( option for displaying an option menu indi-) 338.12 260.33 T
-0.38 (cator) 162.9 248.33 P
-0.38 (. There is now support for option menus via the) 182.33 248.33 P
5 F
-0.91 (tk_optionMenu) 370.9 248.33 P
3 F
-0.38 ( procedure, and) 448.86 248.33 P
(popups are simpli\336ed with the) 162.9 236.33 T
5 F
(tk_popup) 286.44 236.33 T
3 F
( procedure.) 334.42 236.33 T
3 12 Q
(\245) 152.1 221.33 T
3 10 Q
-0.03 (The variable) 162.9 221.33 P
5 F
-0.07 (tk_strictMotif) 215.57 221.33 P
3 F
-0.03 ( is used in more places to enforce even stricter Motif) 299.53 221.33 P
(compliance.) 162.9 209.33 T
FMENDPAGE
%%EndPage: "12" 13
%%Page: "13" 13
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(6 Images) 98.1 668.33 T
0 F
(13) 500.99 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
98.1 623.98 512.1 627 C
152.1 625.2 512.1 625.2 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 625.49 143.1 625.49 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(6) 134.63 631 T
(Images) 152.1 631 T
3 10 Q
(Tk 4.0 contains a general-purpose image mechanism for displaying color pictures and) 152.1 607.31 T
(other complex objects. There is a new command,) 152.1 595.26 T
5 F
(image) 350.84 595.26 T
3 F
(, which may be used to create) 380.82 595.26 T
(image objects. For example, the command) 152.1 583.21 T
5 9 Q
(image create photo myFace -f) 179.1 568.88 T
(ile picture.ppm) 330.09 568.88 T
3 10 Q
(creates a new image named) 152.1 555.21 T
5 F
(myFace) 264.5 555.21 T
3 F
(. The image is of type) 300.48 555.21 T
5 F
(photo) 390.14 555.21 T
3 F
( \050a full-color represen-) 420.12 555.21 T
(tation that dithers on monochrome or color) 152.1 543.17 T
(-mapped displays\051 and the source data for the) 323.46 543.17 T
(image is in the \336le named) 152.1 531.12 T
5 F
(picture.ppm) 257.59 531.12 T
3 F
(. Once an image has been created, it can be) 323.56 531.12 T
-0.15 (used in many dif) 152.1 519.07 P
-0.15 (ferent places by specifying a) 218.37 519.07 P
5 F
-0.36 (-image) 334.46 519.07 P
3 F
-0.15 ( option. For example, the command) 370.44 519.07 P
5 9 Q
(label .l -image myFace) 179.1 504.74 T
3 10 Q
(will create a label widget that displays the image, and if) 152.1 491.07 T
5 F
(.c) 377.5 491.07 T
3 F
( is a canvas widget the com-) 389.49 491.07 T
(mand) 152.1 479.02 T
5 9 Q
(.c create image 400 200 -image myFace) 179.1 464.69 T
3 10 Q
(will create an image item in the canvas that displays) 152.1 451.02 T
5 F
(myFace) 363.06 451.02 T
3 F
(.) 399.04 451.02 T
(The image mechanism provides a great deal of \337exibility:) 170.1 439.02 T
3 12 Q
(\245) 152.1 424.02 T
3 10 Q
-0.18 (Once an image has been de\336ned, it can be used in many dif) 162.9 424.02 P
-0.18 (ferent places, even on dif) 397.84 424.02 P
-0.18 (fer-) 497.68 424.02 P
(ent displays.) 162.9 411.98 T
3 12 Q
(\245) 152.1 396.98 T
3 10 Q
(Images provide image commands, analogous to widget commands, that can be used to) 162.9 396.98 T
(manipulate the image; any changes in an image are automatically re\337ected in all of its) 162.9 384.93 T
(instances.) 162.9 372.88 T
3 12 Q
(\245) 152.1 357.88 T
3 10 Q
-0.21 (There can be many dif) 162.9 357.88 P
-0.21 (ferent types of images. Tk 4.0 has two built-in types,) 251.78 357.88 P
5 F
-0.51 (photo) 463.11 357.88 P
3 F
-0.21 ( and) 493.1 357.88 P
5 F
(bitmap) 162.9 345.83 T
3 F
(. Other image types can be de\336ned in C as extensions \050see the documentation) 198.88 345.83 T
-0.16 (for the) 162.9 333.79 P
5 F
-0.39 (Tk_CreateImageType) 191.44 333.79 P
3 F
-0.16 ( library procedure\051. The photo image type was imple-) 299.38 333.79 P
(mented by Paul Mackerras, based on his earlier photo widget.) 162.9 321.74 T
3 12 Q
(\245) 152.1 306.74 T
3 10 Q
(W) 162.9 306.74 T
(ithin the photo image type, there can be many dif) 171.93 306.74 T
(ferent \336le formats. In Tk 4.0, only) 368.29 306.74 T
-0.11 (PPM, PGM, and GIF formats are built-in, but other formats can be added as extensions) 162.9 294.69 P
(\050see the documentation for the) 162.9 282.64 T
5 F
(Tk_CreatePhotoImageFormat) 286.97 282.64 T
3 F
( library proce-) 436.89 282.64 T
(dure\051. Readers for XPM, TIFF) 162.9 270.59 T
(, and others are available from the T) 284.23 270.59 T
(cl community) 428.41 270.59 T
(.) 483.01 270.59 T
98.1 227.24 512.1 230.26 C
152.1 228.46 512.1 228.46 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 228.75 143.1 228.75 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(7) 134.63 234.26 T
(Color management) 152.1 234.26 T
3 10 Q
(Tk 3.6 suf) 152.1 210.57 T
(fers from a relatively weak mechanism for managing colors. It uses only the) 192.73 210.57 T
(default colormap for a screen, and if all the entries in that colormap \336ll up then Tk) 152.1 198.52 T
(switches to monochrome mode and \322rounds\323 all future colors to black or white. This) 152.1 186.48 T
(approach is becoming increasingly unpleasant because of applications such as Frame and) 152.1 174.43 T
(W) 152.1 162.38 T
(eb browsers that use up all the entries in the default colormap.) 160.74 162.38 T
(Tk 4.0 has a much more powerful color management mechanism. If a colormap \336lls) 170.1 150.38 T
(up, Tk allocates future colors by picking the closest match from the available colors, so) 152.1 138.33 T
FMENDPAGE
%%EndPage: "13" 14
%%Page: "14" 14
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(14) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
(that it need not revert to monochrome mode. Tk also manages colors better by delaying) 152.1 632.33 T
-0.3 (color allocation until colors are actually needed; in many cases, such as 3D borders, colors) 152.1 620.33 P
(are never needed. When colors are scarce Tk changes the way it displays beveled borders) 152.1 608.33 T
-0.38 (so that it uses stippling instead of additional colors for the light and dark shadows. Y) 152.1 596.33 P
-0.38 (ou can) 484.01 596.33 P
(\336nd out whether a colormap has \336lled up using the new command) 152.1 584.33 T
5 F
(winfo colormap-) 418.59 584.33 T
(full) 152.1 572.33 T
3 F
(.) 176.09 572.33 T
-0.26 (Tk 4.0 also allows you to allocate new colormaps for toplevel and frame widgets with) 170.1 560.33 P
(the) 152.1 548.33 T
5 F
(-colormap) 166.81 548.33 T
3 F
( option, and you change the visual type in these widgets \050with the) 220.78 548.33 T
5 F
(-) 152.1 536.33 T
(visual) 158.1 536.33 T
3 F
( option\051 to take advantage of visuals other than the default visual for a screen.) 194.08 536.33 T
(New commands) 152.1 524.33 T
5 F
(winfo visualsavailable) 219.27 524.33 T
3 F
( and) 351.2 524.33 T
5 F
(wm colormapwindows) 370.63 524.33 T
3 F
( have) 478.57 524.33 T
(been added to help manage colormaps and visuals.) 152.1 512.33 T
(The default color scheme in Tk 4.0 has changed from a tan palette \050\322bisque\323\051 to a) 170.1 500.33 T
(gray palette, which seems to becoming standard for Motif. There is a new T) 152.1 488.33 T
(cl procedure) 454.78 488.33 T
5 F
-0.36 (tk_setPalette) 152.1 476.33 P
3 F
-0.15 ( that changes the palette of an application on the \337y) 230.06 476.33 P
-0.15 (, and there is also a) 433.89 476.33 P
(procedure) 152.1 464.33 T
5 F
(tk_bisque) 194.56 464.33 T
3 F
( to restore the palette to the old bisque colors.) 248.53 464.33 T
(The Tk 3.6 color model mechanism is no longer necessary so it has been removed in) 170.1 452.33 T
(Tk 4.0. If you want to \336nd out whether a screen is monochrome or color) 152.1 440.33 T
(, you cannot use) 440.38 440.33 T
(the) 152.1 428.33 T
5 F
(tk colormodel) 166.81 428.33 T
3 F
( command anymore; use) 244.77 428.33 T
5 F
(winfo depth) 345.25 428.33 T
3 F
( instead.) 411.22 428.33 T
98.1 384.98 512.1 388 C
152.1 386.2 512.1 386.2 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 386.49 143.1 386.49 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(8) 134.63 392 T
(Event handling: \336leevent and after) 152.1 392 T
3 10 Q
(Tk 4.0 contains several improvements in the area of event handling besides those already) 152.1 368.31 T
(mentioned for bindings:) 152.1 356.31 T
3 12 Q
(\245) 152.1 341.31 T
3 10 Q
(There is a new command) 162.9 341.31 T
5 F
(f) 265.87 341.31 T
(ileevent) 271.87 341.31 T
3 F
( for performing event-driven I/O to and from) 319.84 341.31 T
-0.12 (\336les. The) 162.9 329.31 P
5 F
-0.29 (f) 202.35 329.31 P
-0.29 (ileevent) 208.35 329.31 P
3 F
-0.12 ( command is modelled very closely after Mark Diekhans\325) 256.33 329.31 P
5 F
-0.29 (add-) 488.11 329.31 P
(input) 162.9 317.31 T
3 F
( extension, which has been used widely with Tk 3.6.) 192.88 317.31 T
3 12 Q
(\245) 152.1 302.31 T
3 10 Q
-0.34 (The) 162.9 302.31 P
5 F
-0.82 (after) 180.6 302.31 P
3 F
-0.34 ( command has two new options,) 210.58 302.31 P
5 F
-0.82 (idle) 339.82 302.31 P
3 F
-0.34 ( and) 363.81 302.31 P
5 F
-0.82 (cancel) 382.55 302.31 P
3 F
-0.34 (.) 418.53 302.31 P
5 F
-0.82 (After idle) 423.19 302.31 P
3 F
-0.34 ( can be) 482.33 302.31 P
-0.2 (used to schedule a script as an \322idle handler\323, which means it runs the next time that Tk) 162.9 290.31 P
(enters the event loop and \336nds no work to do.) 162.9 278.31 T
5 F
(After cancel) 348.06 278.31 T
3 F
( may be used to delete) 420.02 278.31 T
(a previously-scheduled) 162.9 266.31 T
5 F
(after) 257.83 266.31 T
3 F
( script, so that it will no longer be invoked.) 287.81 266.31 T
98.1 222.95 512.1 225.98 C
152.1 224.18 512.1 224.18 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 224.46 143.1 224.46 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(9) 134.63 229.98 T
(Multiple displays) 152.1 229.98 T
3 10 Q
(Although Tk has always allowed a single application to open windows on several dis-) 152.1 206.29 T
(plays, the support for multiple displays is weak in Tk 3.6. For example, many of the bind-) 152.1 194.29 T
(ings break if users work simultaneously in windows on dif) 152.1 182.29 T
(ferent displays, and) 385.94 182.29 T
(mechanisms like the selection and the input focus have insuf) 152.1 170.29 T
(\336cient support for multiple) 394.26 170.29 T
(displays.) 152.1 158.29 T
FMENDPAGE
%%EndPage: "14" 15
%%Page: "15" 15
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(10 The send command) 98.1 668.33 T
0 F
(15) 500.99 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
-0.33 (Tk 4.0 contains numerous modi\336cations to improve the handling of multiple displays.) 170.1 632.33 P
-0.18 (Several commands, such as) 152.1 620.24 P
5 F
-0.44 (selection) 263.78 620.24 P
3 F
-0.18 (,) 317.76 620.24 P
5 F
-0.44 (send) 322.57 620.24 P
3 F
-0.18 (, and) 346.55 620.24 P
5 F
-0.44 (focus) 368.12 620.24 P
3 F
-0.18 (, have a new) 398.1 620.24 P
5 F
-0.44 (-displayof) 449.82 620.24 P
3 F
(ar) 152.1 608.15 T
(gument so that you can select a particular display) 159.69 608.15 T
(. In addition, the bindings have been) 356.12 608.15 T
(reworked to handle interactions occurring simultaneously on dif) 152.1 596.05 T
(ferent displays. W) 408.13 596.05 T
(ith Tk) 480.73 596.05 T
(4.0 it should be possible to create applications that really use multiple displays gracefully) 152.1 583.96 T
(.) 508.44 583.96 T
98.1 540.6 512.1 543.63 C
152.1 541.83 512.1 541.83 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 542.12 143.1 542.12 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(10) 127.96 547.63 T
(The send command) 152.1 547.63 T
3 10 Q
-0.2 (The) 152.1 523.94 P
5 F
-0.48 (send) 169.94 523.94 P
3 F
-0.2 ( command has been completely overhauled for Tk 4.0 to eliminate several prob-) 193.93 523.94 P
(lems in Tk 3.6 and add a number of new features:) 152.1 511.85 T
3 12 Q
(\245) 152.1 496.85 T
3 10 Q
(Tk 3.6 aborts a) 162.9 496.85 T
5 F
(send) 225.36 496.85 T
3 F
( command if no response is received within 5 seconds; this made) 249.34 496.85 T
(it very dif) 162.9 484.75 T
(\336cult to invoke long-running commands. Tk 4.0 eliminates the timeout  and) 202.14 484.75 T
(uses a dif) 162.9 472.66 T
(ferent mechanism to tell if the tar) 200.47 472.66 T
(get application has crashed.) 333.53 472.66 T
3 12 Q
(\245) 152.1 457.66 T
3 10 Q
-0.36 (The) 162.9 457.66 P
5 F
-0.87 (winfo interps) 180.58 457.66 P
3 F
-0.36 ( command no longer returns the names of applications that have) 257.66 457.66 P
(exited or crashed.) 162.9 445.57 T
3 12 Q
(\245) 152.1 430.57 T
3 10 Q
(Asynchronous sends are possible using the) 162.9 430.57 T
5 F
(-async) 336.67 430.57 T
3 F
( switch.) 372.65 430.57 T
3 12 Q
(\245) 152.1 415.57 T
3 10 Q
(Commands can be sent to displays other than that of the root window) 162.9 415.57 T
(, using the) 439.3 415.57 T
5 F
(-) 162.9 403.47 T
(displayof) 168.9 403.47 T
3 F
( switch.) 222.87 403.47 T
3 12 Q
(\245) 152.1 388.47 T
3 10 Q
(W) 162.9 388.47 T
(indow server security is now checked on each) 171.93 388.47 T
5 F
(send) 357.89 388.47 T
3 F
(, so Tk 4.0 deals better with) 381.88 388.47 T
(changes in the security of the server) 162.9 376.38 T
(.) 306.12 376.38 T
3 12 Q
(\245) 152.1 361.38 T
3 10 Q
(More complete error information \050including the) 162.9 361.38 T
5 F
(errorCode) 356.09 361.38 T
3 F
( and) 410.06 361.38 T
5 F
(errorInfo) 429.49 361.38 T
3 F
( vari-) 483.46 361.38 T
(ables\051 is propagated back to the sender after errors.) 162.9 349.29 T
3 12 Q
(\245) 152.1 334.29 T
3 10 Q
(Y) 162.9 334.29 T
(ou can query and change the name of an application with the) 169.12 334.29 T
5 F
(tk appname) 414.48 334.29 T
3 F
( com-) 474.45 334.29 T
(mand.) 162.9 322.19 T
(Unfortunately the improvements to the Tk 4.0) 152.1 307.19 T
5 F
(send) 338.65 307.19 T
3 F
( mechanism required substantial) 362.63 307.19 T
(changes to the transport protocol for sends; this makes it impossible for Tk 4.0 applica-) 152.1 295.1 T
(tions to communicate with Tk 3.6 applications via) 152.1 283.01 T
5 F
(send) 355.04 283.01 T
3 F
(. The new transport protocol is) 379.02 283.01 T
(more \337exible than the old protocol, so it should be possible to make protocol improve-) 152.1 270.91 T
(ments in an upward-compatible way) 152.1 258.82 T
(.) 296.9 258.82 T
98.1 215.47 512.1 218.49 C
152.1 216.69 512.1 216.69 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 216.98 143.1 216.98 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(1) 128.62 222.49 T
(1) 134.63 222.49 T
(The selection and clipboard) 152.1 222.49 T
3 10 Q
(In Tk 3.6 the selection mechanism can deal only with the display of the root window and) 152.1 198.8 T
-0.13 (with the primary selection; there is no support for multiple displays, secondary selections,) 152.1 186.71 P
(or the clipboard. Tk 4.0 eliminates all of these shortcomings. The) 152.1 174.61 T
5 F
(-displayof) 415.82 174.61 T
3 F
( option) 475.78 174.61 T
-0.12 (can be used to specify a particular display in the selection command, and there is now full) 152.1 162.52 P
(access to all of the X selection types. Tk 4.0 also includes a new) 152.1 150.43 T
5 F
(clipboard) 411.36 150.43 T
3 F
( command) 465.33 150.43 T
(for manipulating the clipboard.) 152.1 138.33 T
FMENDPAGE
%%EndPage: "15" 16
%%Page: "16" 16
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(16) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
98.1 623.98 512.1 627 C
152.1 625.2 512.1 625.2 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 625.49 143.1 625.49 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(12) 127.96 631 T
(Miscellaneous changes) 152.1 631 T
3 10 Q
(Here is a quick summary of the remaining changes in Tk 4.0:) 152.1 607.31 T
3 12 Q
(\245) 152.1 592.31 T
3 10 Q
-0.17 (The) 162.9 592.31 P
5 F
-0.42 (wish) 180.76 592.31 P
3 F
-0.17 ( application has been modi\336ed so that the) 204.75 592.31 P
5 F
-0.42 (-f) 371.58 592.31 P
-0.42 (ile) 383.57 592.31 P
3 F
-0.17 ( switch is no longer needed) 401.56 592.31 P
(or recommended. This makes) 162.9 580.31 T
5 F
(wish) 283.64 580.31 T
3 F
( just like) 307.63 580.31 T
5 F
(tclsh) 344.56 580.31 T
3 F
(, where you specify the script \336le) 374.54 580.31 T
(as the \336rst ar) 162.9 568.31 T
(gument to the program, e.g.) 214.07 568.31 T
5 F
(wish foo.tcl) 327.33 568.31 T
3 F
(. The) 399.29 568.31 T
5 F
(-f) 422.33 568.31 T
(ile) 434.32 568.31 T
3 F
( switch is still) 452.31 568.31 T
(permitted for backward compatibility) 162.9 556.31 T
(, but its use is deprecated.) 311.87 556.31 T
3 12 Q
(\245) 152.1 541.31 T
5 10 Q
(Wish) 162.9 541.31 T
3 F
( now sets the application\325) 186.89 541.31 T
(s class from the application name \050what appears in the) 288.49 541.31 T
-0.37 (title bar of the window by default\051, rather than always using) 162.9 529.31 P
5 F
-0.88 (Tk) 400.9 529.31 P
3 F
-0.37 ( as the class as in Tk 3.6.) 412.89 529.31 P
(This makes application-speci\336c options easier to use.) 162.9 517.31 T
3 12 Q
(\245) 152.1 502.31 T
3 10 Q
(T) 162.9 502.31 T
(oplevel windows are now resizable by default, whereas in Tk 3.6 they were not. Y) 168.31 502.31 T
(ou) 496.22 502.31 T
(can use the) 162.9 490.31 T
5 F
(wm resizable) 209.8 490.31 T
3 F
( command to make windows non-reiszable.) 281.77 490.31 T
3 12 Q
(\245) 152.1 475.31 T
3 10 Q
(Tk 4.0 patches around an Xlib bug whereby long-running applications tended to reach) 162.9 475.31 T
(the end of the space of X resource ids, wrap around to 0 again, and then crash. Tk now) 162.9 463.31 T
(reuses resource identi\336ers so that wrap-around should never occur) 162.9 451.31 T
(.) 427.14 451.31 T
3 12 Q
(\245) 152.1 436.31 T
3 10 Q
-0.13 (There is a new) 162.9 436.31 P
5 F
-0.31 (winfo manager) 223.43 436.31 P
3 F
-0.13 ( command that tells which geometry manager is con-) 301.08 436.31 P
(trolling a particular widget.) 162.9 424.31 T
3 12 Q
(\245) 152.1 409.31 T
3 10 Q
(There is a new) 162.9 409.31 T
5 F
(bell) 223.96 409.31 T
3 F
( command that does what its name suggests.) 247.94 409.31 T
3 12 Q
(\245) 152.1 394.31 T
3 10 Q
(There are new) 162.9 394.31 T
5 F
(winfo pointerx) 222.56 394.31 T
3 F
(,) 306.51 394.31 T
5 F
(winfo pointery) 311.51 394.31 T
3 F
(, and) 394.81 394.31 T
5 F
(winfo pointerxy) 416.74 394.31 T
3 F
(commands that can be used to query the position of the mouse pointer) 162.9 382.31 T
(.) 442.17 382.31 T
98.1 338.95 512.1 341.98 C
152.1 340.18 512.1 340.18 2 L
0.5 H
2 Z
0 X
0 K
N
98.1 340.46 143.1 340.46 2 L
0 Z
N
40.5 63 571.5 729 C
0 12 Q
0 X
0 K
(13) 127.96 345.98 T
(Summary of Incompatibilites) 152.1 345.98 T
3 10 Q
-0.24 (This section lists all of the incompatible changes in Tk 4.0 that may require changes in T) 152.1 322.29 P
-0.24 (cl) 502.62 322.29 P
-0.22 (scripts written for T) 152.1 310.29 P
-0.22 (cl 3.6. Each incompatibility is described in terms of the problem it pro-) 230.42 310.29 P
(duces when you run your Tk 3.6 script under Tk 4.0 and a possible work-around. Only) 152.1 298.29 T
(T) 152.1 286.29 T
(cl-level incompatibilities are covered here. For incompatible changes at the C level, see) 157.51 286.29 T
(the) 152.1 274.29 T
5 F
(README) 166.81 274.29 T
3 F
( and) 202.79 274.29 T
5 F
(changes) 222.22 274.29 T
3 F
( \336les in the distribution. The problems and solutions are) 264.2 274.29 T
(roughly in order of importance, with the most important problems \336rst.) 152.1 262.29 T
1 F
(Pr) 152.1 247.29 T
(oblem #1:) 162.46 247.29 T
3 F
(When you change the background color of a widget, a small ring in the) 206.88 247.29 T
(default background color remains around the edge of the widget.) 152.1 235.29 T
2 F
(Solution:) 170.1 223.29 T
3 F
(This is the focus traversal highlight, whose color is speci\336ed separately) 209.25 223.29 T
(from) 170.1 211.29 T
5 F
(-background) 192.03 211.29 T
3 F
(; use the) 257.99 211.29 T
5 F
(-highlightbackground) 293.8 211.29 T
3 F
( option to change the) 413.74 211.29 T
(color of the highlight. Or) 170.1 199.29 T
(, you can set) 269.92 199.29 T
5 F
(-highlightthickness) 322.38 199.29 T
3 F
( to 0 to eliminate) 436.31 199.29 T
(the traversal highlight altogether) 170.1 187.29 T
(.) 299.74 187.29 T
1 F
(Pr) 152.1 172.29 T
(oblem #2:) 162.46 172.29 T
3 F
(Bindings de\336ned for a widget no longer replace the corresponding class) 206.88 172.29 T
(bindings, so unwanted class bindings get invoked in addition to the widget bindings.) 152.1 160.29 T
FMENDPAGE
%%EndPage: "16" 17
%%Page: "17" 17
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(13 Summary of Incompatibilites) 98.1 668.33 T
0 F
(17) 500.99 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
2 F
0 X
(Solution:) 170.1 632.33 T
3 F
(Add a) 209.25 632.33 T
5 F
(break) 235.89 632.33 T
3 F
( command at the end of the widget binding, or rework the) 265.88 632.33 T
(widget binding so that it\325) 170.1 620.33 T
(s OK for the class binding to execute.) 270.05 620.33 T
1 F
(Pr) 152.1 605.33 T
(oblem #3:) 162.46 605.33 T
3 F
(Bindings on toplevel windows are invoked when events occur for internal) 206.88 605.33 T
(windows inside the toplevels.) 152.1 593.33 T
2 F
(Solution:) 170.1 581.33 T
3 F
(Use the) 209.25 581.33 T
5 F
(%W) 242 581.33 T
3 F
( substitution to extract the name of the window where the event) 253.99 581.33 T
(actually occurred, and only execute the rest of the binding script if this matches the) 170.1 569.33 T
(name of the toplevel.) 170.1 557.33 T
1 F
-0.15 (Pr) 152.1 542.33 P
-0.15 (oblem #4:) 162.46 542.33 P
3 F
-0.15 (The) 206.58 542.33 P
5 F
-0.37 (-command) 224.46 542.33 P
3 F
-0.15 ( option for a cascade menu entry is no longer invoked when) 272.44 542.33 P
(the submenu is posted.) 152.1 530.33 T
2 F
(Solution:) 170.1 518.33 T
3 F
(Use the) 209.25 518.33 T
5 F
(-postcommand) 242 518.33 T
3 F
( option for the submenu instead.) 313.96 518.33 T
1 F
(Pr) 152.1 503.33 T
(oblem #5:) 162.46 503.33 T
3 F
(The) 206.88 503.33 T
5 F
(-geometry) 224.92 503.33 T
3 F
( option is no longer supported by listboxes, frames, and) 278.89 503.33 T
(toplevels.) 152.1 491.33 T
2 F
(Solution:) 170.1 479.33 T
3 F
(Use the) 209.25 479.33 T
5 F
(-width) 242 479.33 T
3 F
( and) 277.98 479.33 T
5 F
(-height) 297.41 479.33 T
3 F
( options instead.) 339.39 479.33 T
1 F
(Pr) 152.1 464.33 T
(oblem #6:) 162.46 464.33 T
3 F
(The procedure) 206.88 464.33 T
5 F
(tk_listboxSingleSelect) 267.38 464.33 T
3 F
( no longer exists.) 399.3 464.33 T
2 F
(Solution:) 170.1 452.33 T
3 F
(Use the) 209.25 452.33 T
5 F
(-selectmode) 242 452.33 T
3 F
( option on the listbox instead.) 307.96 452.33 T
1 F
(Pr) 152.1 437.33 T
(oblem #7:) 162.46 437.33 T
3 F
(Canvases no longer have a) 206.88 437.33 T
5 F
(-scrollincrement) 315.96 437.33 T
3 F
( option.) 411.91 437.33 T
2 F
(Solution:) 170.1 425.33 T
3 F
(Use the new) 209.25 425.33 T
5 F
(-xscrollincrement) 261.15 425.33 T
3 F
( and) 363.09 425.33 T
5 F
(-yscrollincrement) 382.52 425.33 T
3 F
(options instead.) 170.1 413.33 T
1 F
(Pr) 152.1 398.33 T
(oblem #8:) 162.46 398.33 T
3 F
(The) 206.88 398.33 T
5 F
(tk colormodel) 224.92 398.33 T
3 F
( command no longer exists.) 302.88 398.33 T
2 F
-0.28 (Solution:) 170.1 386.33 P
3 F
-0.28 (T) 208.97 386.33 P
-0.28 (o \336nd out whether a window is monochrome or color) 214.37 386.33 P
-0.28 (, use) 424.34 386.33 P
5 F
-0.68 (winfo depth) 444.6 386.33 P
3 F
(to extract the window\325) 170.1 374.33 T
(s depth; a depth of 1 means monochrome.) 259.76 374.33 T
1 F
-0.08 (Pr) 152.1 359.33 P
-0.08 (oblem #9:) 162.46 359.33 P
3 F
-0.08 (The class of Tk applications is no longer) 206.72 359.33 P
5 F
-0.19 (Tk) 370.97 359.33 P
3 F
-0.08 (, so options speci\336ed for the) 382.96 359.33 P
5 F
-0.19 (Tk) 497.69 359.33 P
3 F
(class in your) 152.1 347.33 T
5 F
(.Xdefaults) 205.12 347.33 T
3 F
( \336le are no longer used.) 265.09 347.33 T
2 F
(Solution:) 170.1 335.33 T
3 F
(Modify your) 209.25 335.33 T
5 F
(.Xdefaults) 262.55 335.33 T
3 F
( \336le \050and any T) 322.52 335.33 T
(cl code that sets options\051 to) 382.88 335.33 T
(specify the name of the application \050with the \336rst letter capitalized\051 as the class) 170.1 323.33 T
(instead of) 170.1 311.33 T
5 F
(Tk) 211.74 311.33 T
3 F
(.) 223.73 311.33 T
1 F
-0.15 (Pr) 152.1 296.33 P
-0.15 (oblem #10:) 162.46 296.33 P
3 F
-0.15 (When text is added to a text widget just after a tagged area, the new text no) 211.57 296.33 P
(longer receives the tag.) 152.1 284.33 T
2 F
-0.1 (Solution:) 170.1 272.33 P
3 F
-0.1 (Explicitly tag the new text with the desired tags. If you want the tags on the) 209.15 272.33 P
-0.08 (new text to be the same as those at some other point in the text, you can use the) 170.1 260.33 P
5 F
-0.2 (tag) 488.31 260.33 P
(names) 170.1 248.33 T
3 F
( widget command to query existing tags.) 200.08 248.33 T
1 F
(Pr) 152.1 233.33 T
(oblem #1) 162.46 233.33 T
(1:) 200.5 233.33 T
3 F
(W) 211.33 233.33 T
(idgets appear lar) 220.36 233.33 T
(ger than they did in Tk 3.6.) 286.24 233.33 T
2 F
(Solution:) 170.1 221.33 T
3 F
(There are two issues here. The \336rst is that all widgets now have a focus tra-) 209.25 221.33 T
-0.24 (versal highlight ring that turns dark when the widget has the focus; this is required for) 170.1 209.33 P
(Motif compliance but you can eliminate it by specifying a 0 value for the) 170.1 197.33 T
5 F
( -high-) 462.4 197.33 T
(lightthickness) 170.1 185.33 T
3 F
( option. The second issue is that the default padding for buttons) 254.05 185.33 T
-0.17 (and menubuttons has been increased to match the sizes of Motif widgets. If you don\325) 170.1 173.33 P
-0.17 (t) 506.99 173.33 P
(mind being dif) 170.1 161.33 T
(ferent from Motif, you can set the) 228.78 161.33 T
5 F
(-padx) 366.45 161.33 T
3 F
( and) 396.44 161.33 T
5 F
(-) 415.86 161.33 T
(pady) 421.86 161.33 T
3 F
( options back to) 445.85 161.33 T
FMENDPAGE
%%EndPage: "17" 18
%%Page: "18" 18
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(18) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
3 F
0 X
(their Tk 3.6 values \050use the) 170.1 632.33 T
5 F
(conf) 281.41 632.33 T
(igure) 305.4 632.33 T
3 F
( widget command in Tk 3.6 to see what the) 335.38 632.33 T
(old values were\051.) 170.1 620.33 T
1 F
(Pr) 152.1 605.33 T
(oblem #12:) 162.46 605.33 T
3 F
(Listboxes now return the selection as a string with newlines separating the) 211.88 605.33 T
(values, rather than a T) 152.1 593.33 T
(cl, list.) 240.49 593.33 T
2 F
(Solution:) 170.1 581.33 T
3 F
(Modify your code to handle the new format. Y) 209.25 581.33 T
(ou can convert the selection) 395.06 581.33 T
(back into the old list format with a script like the following:) 170.1 569.33 T
5 9 Q
(split [selection get] \134n) 179.1 555 T
1 10 Q
(Pr) 152.1 541.33 T
(oblem #13:) 162.46 541.33 T
3 F
(Tk 4.0 applications cannot) 211.88 541.33 T
5 F
(send) 320.42 541.33 T
3 F
( to or be sent from Tk 3.6 applications.) 344.4 541.33 T
2 F
(Solution:) 170.1 529.33 T
3 F
(The only solution is to upgrade all your applications to Tk 4.0.) 209.25 529.33 T
1 F
-0.17 (Pr) 152.1 514.33 P
-0.17 (oblem #14:) 162.46 514.33 P
3 F
-0.17 (In texts,) 211.54 514.33 P
5 F
-0.4 (end) 245.91 514.33 P
3 F
-0.17 ( now refers to a position just after the \336nal newline, instead of) 263.9 514.33 P
(the \336nal newline.) 152.1 502.33 T
2 F
-0.08 (Solution:) 170.1 490.33 P
3 F
-0.08 (If you wish to refer to the \336nal newline, use the index) 209.17 490.33 P
5 F
-0.19 (end-1char) 424.98 490.33 P
3 F
-0.08 ( instead) 478.95 490.33 P
(of) 170.1 478.33 T
5 F
(end) 180.92 478.33 T
3 F
(.) 198.91 478.33 T
1 F
(Pr) 152.1 463.33 T
(oblem #15:) 162.46 463.33 T
3 F
(In entry widgets,) 211.88 463.33 T
5 F
(sel.last) 281.83 463.33 T
3 F
( now refers to the character just after the last) 329.8 463.33 T
(selected one, rather than the last selected one. The second index for the) 152.1 451.33 T
5 F
(delete) 438.81 451.33 T
3 F
( widget) 474.79 451.33 T
(command has changed in the same way) 152.1 439.33 T
(.) 309.66 439.33 T
2 F
(Solution:) 170.1 427.33 T
3 F
(Add one to the values used in your scripts.) 209.25 427.33 T
1 F
(Pr) 152.1 412.33 T
(oblem #16:) 162.46 412.33 T
3 F
(Because) 211.88 412.33 T
5 F
(Any) 247.68 412.33 T
3 F
( is implicit in all bindings, bindings trigger when extra modi-) 265.67 412.33 T
(\336ers are present, whereas they didn\325) 152.1 400.33 T
(t trigger in Tk 3.6.) 296.24 400.33 T
2 F
(Solution:) 170.1 388.33 T
3 F
(In most cases it\325) 209.25 388.33 T
(s probably \336ne to ignore the extra modi\336ers. If you really) 273.93 388.33 T
-0.12 (don\325) 170.1 376.33 P
-0.12 (t want any actions to be taken when extra modi\336ers are present, create additional) 188.24 376.33 P
(bindings for the cases with extra modi\336ers, and specify a single blank character \050or) 170.1 364.33 T
(any script that does nothing\051 as the script for those bindings. Alternatively) 170.1 352.33 T
(, you can) 465.93 352.33 T
(use the) 170.1 340.33 T
5 F
(%s) 200.63 340.33 T
3 F
( substitution to extract the mouse and modi\336er state in the event binding,) 212.63 340.33 T
(then you can test this value for modi\336ers you do or don\325) 170.1 328.33 T
(t want.) 394.5 328.33 T
1 F
(Pr) 152.1 313.33 T
(oblem #17:) 162.46 313.33 T
3 F
(In scrollbars there is no longer a) 211.88 313.33 T
5 F
(-foreground) 343.17 313.33 T
3 F
( or) 409.13 313.33 T
5 F
(-activefore-) 422.45 313.33 T
(ground) 152.1 301.33 T
3 F
( option, and) 188.08 301.33 T
5 F
(-background) 238.05 301.33 T
3 F
( has a dif) 304.02 301.33 T
(ferent meaning.) 340.2 301.33 T
2 F
-0.4 (Solution:) 170.1 289.33 P
3 F
-0.4 (Use) 208.85 289.33 P
5 F
-0.96 (-troughcolor) 226.49 289.33 P
3 F
-0.4 ( everywhere that you used) 298.45 289.33 P
5 F
-0.96 (-background) 403.87 289.33 P
3 F
-0.4 ( in Tk 3.6,) 469.83 289.33 P
5 F
(-background) 170.1 277.33 T
3 F
( everywhere you used to use) 236.06 277.33 T
5 F
(-foreground) 352.08 277.33 T
3 F
(, and) 418.04 277.33 T
5 F
(-activeback-) 439.97 277.33 T
(ground) 170.1 265.33 T
3 F
( everywhere you used to use) 206.08 265.33 T
5 F
(-activeforeground) 322.1 265.33 T
3 F
(.) 424.04 265.33 T
1 F
(Pr) 152.1 250.33 T
(oblem #18:) 162.46 250.33 T
3 F
(Options for colors seem to have changed in scale widgets.) 211.88 250.33 T
2 F
(Solution:) 170.1 238.33 T
3 F
(Use) 209.25 238.33 T
5 F
(-background) 227.29 238.33 T
3 F
( where you used to use) 293.25 238.33 T
5 F
(-sliderforeground) 387.07 238.33 T
3 F
(,) 489.02 238.33 T
5 F
(-) 170.1 226.33 T
(troughcolor) 176.1 226.33 T
3 F
( where you used to use) 242.06 226.33 T
5 F
(-background) 335.88 226.33 T
3 F
(, and) 401.84 226.33 T
5 F
( -activeback-) 421.27 226.33 T
(ground) 170.1 214.33 T
3 F
( everywhere you used to use) 206.08 214.33 T
5 F
(-activeforeground) 322.1 214.33 T
3 F
(.) 424.04 214.33 T
1 F
(Pr) 152.1 199.33 T
(oblem #19:) 162.46 199.33 T
3 F
(Scale widgets no longer accept hexadecimal or octal numbers in the) 211.88 199.33 T
5 F
(set) 485.84 199.33 T
3 F
(command or the) 152.1 187.33 T
5 F
(-from) 219.55 187.33 T
3 F
( and) 249.54 187.33 T
5 F
(-to) 268.97 187.33 T
3 F
( options.) 286.96 187.33 T
2 F
(Solution:) 170.1 175.33 T
3 F
(Use) 209.25 175.33 T
5 F
(format) 227.29 175.33 T
3 F
( or) 263.27 175.33 T
5 F
(expr) 276.59 175.33 T
3 F
( to convert the values to decimal.) 300.58 175.33 T
1 F
(Pr) 152.1 160.33 T
(oblem #20:) 162.46 160.33 T
3 F
(In checkbuttons, radiobuttons, and menu entries, the) 211.88 160.33 T
5 F
(-selector) 423.4 160.33 T
3 F
( option) 477.37 160.33 T
(no longer exists.) 152.1 148.33 T
FMENDPAGE
%%EndPage: "18" 19
%%Page: "19" 19
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(13 Summary of Incompatibilites) 98.1 668.33 T
0 F
(19) 500.99 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
2 F
0 X
(Solution:) 170.1 632.33 T
3 F
(Use) 209.25 632.33 T
5 F
(-selectcolor) 227.29 632.33 T
3 F
( instead of) 299.25 632.33 T
5 F
(-select) 343.39 632.33 T
3 F
(. T) 385.36 632.33 T
(o specify that no indicator) 395.77 632.33 T
(should be drawn at all, use the) 170.1 620.33 T
5 F
(-indicatoron) 293.9 620.33 T
3 F
( option instead of setting) 365.86 620.33 T
5 F
(-select) 467.2 620.33 T
3 F
(to an empty string.) 170.1 608.33 T
1 F
-0.12 (Pr) 152.1 593.33 P
-0.12 (oblem #21:) 162.46 593.33 P
3 F
-0.12 (The indices of menu entries have changed, and operations on menu entry 0) 211.64 593.33 P
(no longer work.) 152.1 581.33 T
2 F
(Solution:) 170.1 569.33 T
3 F
(This is because menus now have a tearof) 209.25 569.33 T
(f entry at the top by default, and) 372.55 569.33 T
(this occupies entry 0, so your \336rst entry is now entry 1. Y) 170.1 557.33 T
(ou can either set the) 398.95 557.33 T
5 F
(-) 170.1 545.33 T
(tearoff) 176.1 545.33 T
3 F
( option to 0 to eliminate the tearof) 218.07 545.33 T
(f entry or add 1 to all the indices you) 354.2 545.33 T
(use in your scripts.) 170.1 533.33 T
1 F
-0.22 (Pr) 152.1 518.33 P
-0.22 (oblem #22:) 162.46 518.33 P
3 F
-0.22 (The) 211.44 518.33 P
5 F
-0.53 (enable) 229.26 518.33 P
3 F
-0.22 ( and) 265.24 518.33 P
5 F
-0.53 (disable) 284.23 518.33 P
3 F
-0.22 ( widget commands are no longer supported by) 326.21 518.33 P
(menus.) 152.1 506.33 T
2 F
(Solution:) 170.1 494.33 T
3 F
(Use the) 209.25 494.33 T
5 F
(-state) 242 494.33 T
3 F
( con\336guration option instead.) 277.98 494.33 T
1 F
(Pr) 152.1 479.33 T
(oblem #23:) 162.46 479.33 T
3 F
(The) 211.88 479.33 T
5 F
(activate) 229.92 479.33 T
3 F
( and) 277.89 479.33 T
5 F
(deactivate) 297.32 479.33 T
3 F
( widget commands are no longer sup-) 357.29 479.33 T
(ported by buttons, checkbuttons, radiobuttons, and menus.) 152.1 467.33 T
2 F
(Solution:) 170.1 455.33 T
3 F
(Use the) 209.25 455.33 T
5 F
(-state) 242 455.33 T
3 F
( con\336guration option instead.) 277.98 455.33 T
1 F
(Pr) 152.1 440.33 T
(oblem #24:) 162.46 440.33 T
3 F
(Canvas arc items no longer use the) 211.88 440.33 T
5 F
(-f) 353.72 440.33 T
(ill) 365.71 440.33 T
3 F
( and) 383.7 440.33 T
5 F
(-stipple) 403.13 440.33 T
3 F
( options for) 451.11 440.33 T
(drawing when the) 152.1 428.33 T
5 F
(-style) 226.21 428.33 T
3 F
( option is) 262.19 428.33 T
5 F
(arc) 301.9 428.33 T
3 F
(.) 319.89 428.33 T
2 F
(Solution:) 170.1 416.33 T
3 F
(Use the) 209.25 416.33 T
5 F
(-outline) 242 416.33 T
3 F
( and) 289.97 416.33 T
5 F
(-outlinestipple) 309.4 416.33 T
3 F
( options instead.) 399.35 416.33 T
1 F
-0.29 (Pr) 152.1 401.33 P
-0.29 (oblem #25:) 162.46 401.33 P
3 F
-0.29 (The variable) 211.29 401.33 P
5 F
-0.7 (tkVersion) 263.43 401.33 P
3 F
-0.29 ( no longer exists \050it has been obsolete for several) 317.4 401.33 P
(releases\051.) 152.1 389.33 T
2 F
(Solution:) 170.1 377.33 T
3 F
(Use) 209.25 377.33 T
5 F
(tk_version) 227.29 377.33 T
3 F
( instead.) 287.26 377.33 T
1 F
(Pr) 152.1 362.33 T
(oblem #26:) 162.46 362.33 T
3 F
(The syntax of the) 211.88 362.33 T
5 F
(scan) 284.05 362.33 T
3 F
( widget commands for texts has changed.) 308.03 362.33 T
2 F
(Solution:) 170.1 350.33 T
3 F
(Modify your code to use the new syntax.) 209.25 350.33 T
1 F
(Pr) 152.1 335.33 T
(oblem #27:) 162.46 335.33 T
5 F
(wish) 211.88 335.33 T
3 F
( no longer recognizes the) 235.86 335.33 T
5 F
(-help) 338.84 335.33 T
3 F
( option.) 368.82 335.33 T
2 F
(Solution:) 170.1 323.33 T
3 F
(Implement this option yourself in your) 209.25 323.33 T
5 F
(wish) 366.38 323.33 T
3 F
( scripts.) 390.37 323.33 T
1 F
(Pr) 152.1 308.33 T
(oblem #28:) 162.46 308.33 T
3 F
(Tk 4.0 always prints real numbers such as canvas coordinates with a deci-) 211.88 308.33 T
(mal point. This can cause syntax errors if you later use them in situations where integers) 152.1 296.33 T
(are expected.) 152.1 284.33 T
2 F
(Solution:) 170.1 272.33 T
3 F
(Change your code so that real numbers work OK, or use the) 209.25 272.33 T
5 F
(expr) 451.57 272.33 T
3 F
( com-) 475.55 272.33 T
(mand \050with the) 170.1 260.33 T
5 F
(round) 233.12 260.33 T
3 F
( function\051 to convert the numbers to integers.) 263.1 260.33 T
1 F
(Pr) 152.1 245.33 T
(oblem #29:) 162.46 245.33 T
3 F
(The) 211.88 245.33 T
5 F
(pack info) 229.92 245.33 T
3 F
( command returns dif) 283.89 245.33 T
(ferent information, and) 369.48 245.33 T
5 F
(pack) 464.41 245.33 T
(newinfo) 152.1 233.33 T
3 F
( no longer exists.) 194.08 233.33 T
2 F
(Solution:) 170.1 221.33 T
3 F
(Use) 209.25 221.33 T
5 F
(pack info) 227.29 221.33 T
3 F
( where you used to use) 281.26 221.33 T
5 F
(pack newinfo) 375.08 221.33 T
3 F
(.) 447.04 221.33 T
5 F
(Pack info) 452.04 221.33 T
3 F
(was obsolete, so it has been eliminated.) 170.1 209.33 T
1 F
(Pr) 152.1 194.33 T
(oblem #30:) 162.46 194.33 T
3 F
(The) 211.88 194.33 T
5 F
(view) 229.92 194.33 T
3 F
( widget command for entries no longer exists, nor does the) 253.9 194.33 T
5 F
(-) 152.1 182.33 T
(scrollcommand) 158.1 182.33 T
3 F
( option.) 236.05 182.33 T
2 F
-0.29 (Solution:) 170.1 170.33 P
3 F
-0.29 (Use) 208.96 170.33 P
5 F
-0.69 (xview) 226.71 170.33 P
3 F
-0.29 ( where you used to use) 256.7 170.33 P
5 F
-0.69 (view) 348.8 170.33 P
3 F
-0.29 (; use) 372.78 170.33 P
5 F
-0.69 (-xscrollcommand) 393.31 170.33 P
3 F
-0.29 ( where) 483.26 170.33 P
(you used to use) 170.1 158.33 T
5 F
(-scrollcommand) 234.51 158.33 T
3 F
(.) 318.46 158.33 T
FMENDPAGE
%%EndPage: "19" 20
%%Page: "20" 20
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(20) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
1 F
0 X
(Pr) 152.1 632.33 T
(oblem #31:) 162.46 632.33 T
3 F
(The) 211.88 632.33 T
5 F
(-padx) 229.92 632.33 T
3 F
( and) 259.9 632.33 T
5 F
(-pady) 279.33 632.33 T
3 F
( options are ignored for the button family of wid-) 309.31 632.33 T
(gets if a bitmap or image is being displayed: the padding is always 0.) 152.1 620.02 T
2 F
-0.27 (Solution:) 170.1 608.02 P
3 F
-0.27 (Pack the button inside a frame, with extra padding in the frame. Or) 208.98 608.02 P
-0.27 (, redo the) 472.94 608.02 P
(image or bitmap to incorporate padding into it.) 170.1 595.71 T
1 F
(Pr) 152.1 580.71 T
(oblem #32:) 162.46 580.71 T
3 F
(In radiobuttons, the) 211.88 580.71 T
5 F
(-value) 292.38 580.71 T
3 F
( option no longer defaults to the name of the) 328.36 580.71 T
(widget; it defaults to an empty string.) 152.1 568.4 T
2 F
(Solution:) 170.1 556.4 T
3 F
(Specify the widget\325) 209.25 556.4 T
(s name explicitly as the value of the option.) 286.98 556.4 T
1 F
(Pr) 152.1 541.4 T
(oblem #33:) 162.46 541.4 T
3 F
(The) 211.88 541.4 T
5 F
(-menu) 229.92 541.4 T
3 F
( option for menubuttons and cascade menu entries may refer) 259.9 541.4 T
(only to a child of the menubutton or menu.) 152.1 529.08 T
2 F
(Solution:) 170.1 517.08 T
3 F
(Rename menus to meet this requirement.) 209.25 517.08 T
1 F
(Pr) 152.1 502.08 T
(oblem #34:) 162.46 502.08 T
3 F
(The interpretation of) 211.88 502.08 T
5 F
(@y) 297.09 502.08 T
3 F
( in menus has changed: it never returns) 309.08 502.08 T
5 F
(none) 467.86 502.08 T
3 F
(,) 491.84 502.08 T
(even if the y-coordinate is outside the menu \050it returns the index of the closest entry\051.) 152.1 489.77 T
2 F
(Solution:) 170.1 477.77 T
3 F
(If you care about this distinction, check the y-coordinate explicitly to see if) 209.25 477.77 T
-0.17 (it is less than 0 or greater than or equal to the window\325) 170.1 465.46 P
-0.17 (s height \050use) 385.7 465.46 P
5 F
-0.41 (winfo height) 438.21 465.46 P
3 F
(to get the height\051.) 170.1 453.15 T
1 F
-0.13 (Pr) 152.1 438.15 P
-0.13 (oblem #35:) 162.46 438.15 P
3 F
-0.13 (The) 211.62 438.15 P
5 F
-0.3 (invoke) 229.54 438.15 P
3 F
-0.13 ( and) 265.52 438.15 P
5 F
-0.3 (activate) 284.7 438.15 P
3 F
-0.13 ( widget commands for menus no longer post) 332.67 438.15 P
(cascaded submenus.) 152.1 425.83 T
2 F
(Solution:) 170.1 413.83 T
3 F
(Use the) 209.25 413.83 T
5 F
(postcascade) 242 413.83 T
3 F
( widget command to post submenus.) 307.96 413.83 T
1 F
(Pr) 152.1 398.83 T
(oblem #36:) 162.46 398.83 T
3 F
(The selection tar) 211.88 398.83 T
(gets) 278.31 398.83 T
5 F
(APPLICATION) 296.91 398.83 T
3 F
( and) 362.87 398.83 T
5 F
(WINDOW_NAME) 382.3 398.83 T
3 F
( are no longer) 448.27 398.83 T
(supported.) 152.1 386.52 T
2 F
(Solution:) 170.1 374.52 T
3 F
(Use tar) 209.25 374.52 T
(gets) 237.65 374.52 T
5 F
(TK_APPLICATION) 256.25 374.52 T
3 F
( and) 340.21 374.52 T
5 F
(TK_WINDOW) 359.64 374.52 T
3 F
( instead.) 413.61 374.52 T
1 F
(Pr) 152.1 359.52 T
(oblem #37:) 162.46 359.52 T
3 F
(There is no longer a default focus.) 211.88 359.52 T
2 F
(Solution:) 170.1 347.52 T
3 F
(None: modify your code not to depend on this feature.) 209.25 347.52 T
1 F
(Pr) 152.1 332.52 T
(oblem #38:) 162.46 332.52 T
3 F
(The) 211.88 332.52 T
5 F
(focus) 229.92 332.52 T
3 F
( command now returns an empty string to indicate that the) 259.9 332.52 T
(application doesn\325) 152.1 320.21 T
(t have the input focus, instead of) 225.48 320.21 T
5 F
(none) 358.17 320.21 T
3 F
(.) 382.15 320.21 T
2 F
(Solution:) 170.1 308.21 T
3 F
(Modify your code to check for an empty string instead of) 209.25 308.21 T
5 F
(none) 440.47 308.21 T
3 F
(.) 464.46 308.21 T
1 F
(Pr) 152.1 293.21 T
(oblem #39:) 162.46 293.21 T
5 F
(FocusIn) 211.88 293.21 T
3 F
( and) 253.85 293.21 T
5 F
(FocusOut) 273.28 293.21 T
3 F
( events are delivered to more windows than) 321.26 293.21 T
(they used to be.) 152.1 280.9 T
2 F
-0.02 (Solution:) 170.1 268.9 P
3 F
-0.02 (Modify your code to use the new set of events. The old event set was some-) 209.23 268.9 P
(what bizarre, and the new set matches more closely what happens elsewhere, such as) 170.1 256.58 T
(with) 170.1 244.27 T
5 F
(Enter) 190.37 244.27 T
3 F
( and) 220.35 244.27 T
5 F
(Leave) 239.78 244.27 T
3 F
( events.) 269.77 244.27 T
1 F
-0.28 (Pr) 152.1 229.27 P
-0.28 (oblem #40:) 162.46 229.27 P
5 F
-0.67 (wm maxsize) 211.32 229.27 P
3 F
-0.28 ( and) 270.62 229.27 P
5 F
-0.67 (wm minsize) 289.49 229.27 P
3 F
-0.28 ( no longer accept empty ar) 348.79 229.27 P
-0.28 (guments. This) 453.52 229.27 P
(means that you cannot use these commands to make windows non-resizable.) 152.1 216.96 T
2 F
(Solution:) 170.1 204.96 T
3 F
(Use the) 209.25 204.96 T
5 F
(wm resizable) 242 204.96 T
3 F
( command to make windows resizable.) 313.96 204.96 T
1 F
(Pr) 152.1 189.96 T
(oblem #41:) 162.46 189.96 T
3 F
(In the placer) 211.88 189.96 T
(, if you specify both) 261.43 189.96 T
5 F
(-x) 344.15 189.96 T
3 F
( and) 356.15 189.96 T
5 F
(-relx) 375.58 189.96 T
3 F
( then they add, instead of) 405.56 189.96 T
(the most recent speci\336cation replacing the earlier one. Ditto for) 152.1 177.65 T
5 F
(-y) 407.74 177.65 T
3 F
( and) 419.73 177.65 T
5 F
(-rely) 439.16 177.65 T
3 F
(,) 468.5 177.65 T
5 F
(-width) 473.49 177.65 T
3 F
(and) 152.1 165.33 T
5 F
(-relwidth) 169.03 165.33 T
3 F
(, and) 223 165.33 T
5 F
(-height) 244.93 165.33 T
3 F
( and) 286.91 165.33 T
5 F
(-relheight) 306.33 165.33 T
3 F
(.) 366.3 165.33 T
2 F
(Solution:) 170.1 153.33 T
3 F
(If you no longer want one of these options to be used, set it to 0 explicitly) 209.25 153.33 T
(.) 503.14 153.33 T
1 F
(Pr) 152.1 138.33 T
(oblem #42:) 162.46 138.33 T
3 F
(The command \322) 211.88 138.33 T
5 F
(focus none) 276.27 138.33 T
3 F
(\323 doesn\325) 336.24 138.33 T
(t work in Tk 4.0.) 369.64 138.33 T
FMENDPAGE
%%EndPage: "20" 21
%%Page: "21" 21
612 792 0 FMBEGINPAGE
4 10 Q
0 X
0 K
(13 Summary of Incompatibilites) 98.1 668.33 T
0 F
(21) 500.99 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
2 F
0 X
(Solution:) 170.1 632.33 T
3 F
(Create a dummy widget that is never mapped and set the focus to that wid-) 209.25 632.33 T
(get.) 170.1 620.33 T
1 F
(Pr) 152.1 605.33 T
(oblem #43:) 162.46 605.33 T
5 F
(%D) 211.88 605.33 T
3 F
( substitutions are no longer supported in bindings, nor are the event) 223.87 605.33 T
(types) 152.1 593.33 T
5 F
(CirculateRequest) 175.7 593.33 T
3 F
(,) 271.64 593.33 T
5 F
(Conf) 276.64 593.33 T
(igureRequest) 300.63 593.33 T
3 F
(,) 372.59 593.33 T
5 F
(MapRequest) 377.59 593.33 T
3 F
(, and) 437.55 593.33 T
5 F
(Resiz-) 459.48 593.33 T
(eRequest) 152.1 581.33 T
3 F
(.) 200.07 581.33 T
2 F
-0.25 (Solution:) 170.1 569.33 P
3 F
-0.25 (Use the name of the display instead of %D to identify a display; you can get) 209 569.33 P
(the display name with the) 170.1 557.33 T
5 F
(winfo screen) 275.31 557.33 T
3 F
( command. The desupported event types) 347.27 557.33 T
(never really worked anyway) 170.1 545.33 T
(, so there should be no code that depends on them.) 282.96 545.33 T
1 F
(Pr) 152.1 530.33 T
(oblem #44:) 162.46 530.33 T
5 F
(%) 211.88 530.33 T
3 F
( binding substitutions that return window identi\336ers, such as) 217.87 530.33 T
5 F
(%a) 461.63 530.33 T
3 F
( and) 473.62 530.33 T
5 F
(%S) 493.05 530.33 T
3 F
(,) 505.05 530.33 T
(now produce hexadecimal results instead of decimal.) 152.1 518.33 T
2 F
(Solution:) 170.1 506.33 T
3 F
(Use the) 209.25 506.33 T
5 F
(format) 242 506.33 T
3 F
( command to turn them back to decimal.) 277.98 506.33 T
1 F
(Pr) 152.1 491.33 T
(oblem #45:) 162.46 491.33 T
5 F
(Enter) 211.88 491.33 T
3 F
(,) 241.46 491.33 T
5 F
(Leave) 246.46 491.33 T
3 F
(,) 276.44 491.33 T
5 F
(FocusIn) 281.44 491.33 T
3 F
(, and) 323.42 491.33 T
5 F
(FocusOut) 345.34 491.33 T
3 F
( events with detail) 393.32 491.33 T
5 F
(Notify-) 468.83 491.33 T
(Inferior) 152.1 479.33 T
3 F
( are now ignored by the binding mechanism, so they\325re not visible to T) 200.07 479.33 T
(cl) 483.08 479.33 T
(scripts.) 152.1 467.33 T
2 F
-0.13 (Solution:) 170.1 455.33 P
3 F
-0.13 (In most cases, T) 209.12 455.33 P
-0.13 (cl scripts work better if these bindings are ignored. Y) 273 455.33 P
-0.13 (ou can) 483.49 455.33 P
(still use C code to access these events if you really need them. Or) 170.1 443.33 T
(, create bindings on) 431.18 443.33 T
-0.33 (the inferior windows and use) 170.1 431.33 P
5 F
-0.8 (NotifyAncestor) 286.96 431.33 P
3 F
-0.33 ( bindings on the children instead of) 370.91 431.33 P
5 F
(NotifyInferior) 170.1 419.33 T
3 F
( bindings on the parent.) 254.05 419.33 T
FMENDPAGE
%%EndPage: "21" 22
%%Page: "22" 22
612 792 0 FMBEGINPAGE
0 10 Q
0 X
0 K
(22) 98.1 668.33 T
4 F
(Tk4.0 Overview and Porting Guide) 359.34 668.33 T
98.1 660.6 512.1 660.6 2 L
0.25 H
0 Z
N
98.1 135 512.1 639 R
7 X
V
FMENDPAGE
%%EndPage: "22" 23
%%Trailer
%%BoundingBox: 0 0 612 792
%%Pages: 22 1
%%DocumentFonts: Helvetica-Bold
%%+ Times-Bold
%%+ Times-Italic
%%+ Times-Roman
%%+ Helvetica
%%+ Courier
%%+ Courier-Oblique

Changes to doc/tk_mac.n.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

















42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63

64
65
66

67
68
69
70
71
72
73







-
-









-
-
-

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-




-
+


-







.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tk::mac \- Access Mac-Specific Functionality on OS X from Tk
.SH SYNOPSIS
.nf
\fB::tk::mac::DoScriptFile\fR
\fB::tk::mac::DoScriptText\fR
\fB::tk::mac::ShowPreferences\fR
\fB::tk::mac::OpenApplication\fR
\fB::tk::mac::ReopenApplication\fR
\fB::tk::mac::OpenDocument \fIfile...\fR
\fB::tk::mac::PrintDocument \fIfile...\fR
\fB::tk::mac::Quit\fR
\fB::tk::mac::OnHide\fR
\fB::tk::mac::OnShow\fR
\fB::tk::mac::ShowHelp\fR
\fB::tk::mac::PerformService\fR
\fB::tk::mac::LaunchURL \fIURL...\fR
\fB::tk::mac::GetAppPath\fR

\fB::tk::mac::standardAboutPanel\fR

\fB::tk::mac::useCompatibilityMetrics \fIboolean\fR
\fB::tk::mac::CGAntialiasLimit \fIlimit\fR
\fB::tk::mac::antialiasedtext \fInumber\fR
\fB::tk::mac::useThemedToplevel \fIboolean\fR

\fB::tk::mac::iconBitmap \fIname width height \-kind value\fR
.fi
.BE
.SH "EVENT HANDLER CALLBACKS"
.PP
The Aqua/Mac OS X application environment defines a number of additional
events that applications should respond to. These events are mapped by Tk to
calls to commands in the \fB::tk::mac\fR namespace; unless otherwise noted, if
the command is absent, no action will be taken.
.\" COMMAND: DoScriptFile
.TP
\fB::tk::mac::DoScriptFile\fR
.
The default Apple Event handler for AEDoScriptHandler. This command
executes a Tcl file when an AppleScript sends a
.QW "do script"
command to Wish with a file path as a parameter.
.\" COMMAND: DoScriptText
.TP
\fB::tk::mac::DoScriptText\fR
.
The default Apple Event handler for AEDoScriptHandler. This command
executes Tcl code when an AppleScript sends a
.QW "do script"
command to Wish with Tcl code or a Tcl procedure as a parameter.
.\" COMMAND: ShowPreferences
.TP
\fB::tk::mac::ShowPreferences\fR
.
The default Apple Event handler for kAEShowPreferences,
.QW pref .
The application menu
.QW "Preferences"
menu item is only enabled when this proc is defined. Typically this command is
used to wrap a specific own preferences command, which pops up a preferences
window. Something like:
.RS
.PP
.CS
proc ::tk::mac::ShowPreferences {} {
    setPref
}
.CE
.RE
.\" COMMAND: OpenApplication
.TP
\fB::tk::mac::OpenApplication\fR
.
If a proc of this name is defined, this proc fill fire when your application
is initially opened. It is the default Apple Event handler for
is intially opened. It is the default Apple Event handler for
kAEOpenApplication,
.QW oapp .
.\" COMMAND: ReopenApplication
.TP
\fB::tk::mac::ReopenApplication\fR
.
If a proc of this name is defined it is the default Apple Event handler for
kAEReopenApplication,
.QW rapp ,
the Apple Event sent when your application is opened when it is already
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234



235
236
237
238
239

240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112



113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130

131
132
133
134
135
136

137
138
139
140
141
142
143

144


















































145
146
147
148

149
150
151



152
153
154





155



156
157
158
159
160

161
162
163
164
165

166
167
168
169
170

171
172
173
174
175
176

177
178
179
180
181
182
183
184

185
186
187
188
189
190
191







-


















-






-
-
-
+
+
+










-





-






-







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-



-
-
-
+
+
+
-
-
-
-
-
+
-
-
-
+




-





-





-






-








-







    } else {
        wm deiconify .
    }
    raise .
}
.CE
.RE
.\" COMMAND: OpenDocument
.TP
\fB::tk::mac::OpenDocument \fIfile...\fR
.
If a proc of this name is defined it is the default Apple Event handler for
kAEOpenDocuments,
.QW odoc ,
the Apple Event sent when your application is asked to open one or more
documents (e.g., by drag & drop onto the app or by opening a document of a
type associated to the app). The proc should take as arguments paths to the
files to be opened, like so:
.RS
.PP
.CS
proc ::tk::mac::OpenDocument {args} {
    foreach f $args {my_open_document $f}
}
.CE
.RE
.\" COMMAND: PrintDocument
.TP
\fB::tk::mac::PrintDocument \fIfile...\fR
.
If a proc of this name is defined it is the default Apple Event handler for
kAEPrintDocuments,
.QW pdoc ,
the Apple Event sent when your application is asked to print a
document.  It takes a single absolute file path as an argument.
.\" COMMAND: Quit
the Apple Event sent when your application is asked to print one or more
documents (e.g., via the Print menu item in the Finder).  It works the same
way as \fBtk::mac::OpenDocument\fR in terms of arguments.
.TP
\fB::tk::mac::Quit\fR
.
If a proc of this name is defined it is the default Apple Event handler for
kAEQuitApplication,
.QW quit ,
the Apple Event sent when your application is asked to be quit, e.g. via the
quit menu item in the application menu, the quit menu item in the Dock menu,
or during a logout/restart/shutdown etc. If this is not defined, \fBexit\fR is
called instead.
.\" COMMAND: OnHide
.TP
\fB::tk::mac::OnHide\fR
.
If defined, this is called when your application receives a kEventAppHidden
event, e.g. via the hide menu item in the application or Dock menus.
.\" COMMAND: OnShow
.TP
\fB::tk::mac::OnShow\fR
.
If defined, this is called when your application receives a kEventAppShown
event, e.g. via the show all menu item in the application menu, or by clicking
the Dock icon of a hidden application.
.\" COMMAND: ShowHelp
.TP
\fB::tk::mac::ShowHelp\fR
.
Customizes behavior of Apple Help menu; if this procedure is not defined, the
platform-specific standard Help menu item
.QW "YourApp Help"
performs the default Cocoa action of showing the Help Book configured in the
application's Info.plist (or displaying an alert if no Help Book is
application's Info.plist (or displaying an alert if no Help Book is set).
set).
.\" COMMAND: PerformService
.TP
\fB::tk::mac::PerformService\fR
.
Executes a Tcl procedure called from the macOS
.QW Services
menu in the Application menu item. The
.QW Services
menu item allows for inter-application communication; data from one
application, such as selected text, can be sent to another application
for processing, for example to Safari as a search item for Google, or
to TextEdit to be appended to a file. An example of the proc is below,
and should be rewritten in an application script for customization:
.RS
.PP
.CS
proc ::tk::mac::PerformService {} {
    set data [clipboard get]
    $w insert end $data
}
.CE
.RE
Note that the mechanism for retrieving the data is from the clipboard;
there is no other supported way to obtain the data.  If the Services
process is not desired, the NSServices keys can be deleted from
the application's Info.plist file. The underlying code supporting this
command also allows the text, entry and ttk::entry widgets to access
services from other applications via the Services menu. The NSPortName
key in Wish's Info.plist file is currently set as
.QW "Wish"
; if a developer changes the name of the Wish executable to something
  else, this key should be modified with the same name.
.\" COMMAND: LaunchURL
.TP
\fB::tk::mac::LaunchURL \fIURL...\fR
.
If defined, launches a URL within Tk. This would be used if a Tk
application wants to handle a URL itself, such as displaying data from
an RSS feed, rather than launching a default application to handle the
URL, although it can defined as such. Wish includes a stub URL scheme
of
.QW foo://
in the CFBundleURLSchemes key of its Info.plist file; this should be
customized for the specific URL scheme the developer wants to support.
.TP
\fB::tk::mac::GetAppPath\fR
.
Returns the current applications's file path.
.PP
.SH "ADDITIONAL DIALOGS"
.PP
The Aqua/Mac OS X defines additional dialogs that applications should
support.
.\" COMMAND: standardAboutPanel
.TP
\fB::tk::mac::standardAboutPanel\fR
.
Brings the standard Cocoa about panel to the front with information filled in
from the application bundle files. The panel displays the application icon and
the values associated to the info.plist keys named CFBundleName,
Brings the standard Cocoa about panel to the front, with all its information
filled in from your application bundle files (standard about panel with no
options specified). See Apple Technote TN2179 and the AppKit documentation for
CFBundleShortVersionString, NSAboutPanelOptionVersion and
NSHumanReadableCopyright.  If a file named \fICredits.html\fR or
\fICredits.rtf\fR exists in the bundle's Resources directory then its contents
will be displayed in a scrolling text box at the bottom of the dialog. See the
documentation for -[NSApplication orderFrontStandardAboutPanelWithOptions:]
-[NSApplication orderFrontStandardAboutPanelWithOptions:] for details on the
for more details. A hook is also provided for a custom About dialog.  If a Tcl
proc named tkAboutDialog is defined in the main interpreter then that
procedure will be called instead of opening the standardAboutPanel.
Info.plist keys and app bundle files used by the about panel.
.SH "SYSTEM CONFIGURATION"
.PP
There are a number of additional global configuration options that control the
details of how Tk renders by default.
.\" COMMAND: useCompatibilityMetrics
.TP
\fB::tk::mac::useCompatibilityMetrics \fIboolean\fR
.
Preserves compatibility with older Tk/Aqua metrics; set to \fBfalse\fR for
more native spacing.
.\" COMMAND: CGAntialiasLimit
.TP
\fB::tk::mac::CGAntialiasLimit \fIlimit\fR
.
Sets the antialiasing limit; lines thinner that \fIlimit\fR pixels will not be
antialiased. Integer, set to 0 by default, making all lines be antialiased.
.\" COMMAND: antialiasedtext
.TP
\fB::tk::mac::antialiasedtext \fInumber\fR
.
Sets anti-aliased text.  Controls text antialiasing, possible values for
\fInumber\fR are -1 (default, use system default for text AA), 0 (no text AA),
1 (use text AA).
.\" COMMAND: useThemedToplevel
.TP
\fB::tk::mac::useThemedToplevel \fIboolean\fR
.
Sets toplevel windows to draw with the modern grayish/ pinstripe Mac
background. Equivalent to configuring the toplevel with
.QW "\fB\-background systemWindowHeaderBackground\fR" ,
or to using a \fBttk::frame\fR.
.SH "SUPPORT COMMANDS"
.\" COMMAND: iconBitmap
.TP
\fB::tk::mac::iconBitmap \fIname width height \-kind value\fR
.
Renders native icons and bitmaps in Tk applications (including any image file
readable by NSImage). A native bitmap name is interpreted as follows (in
order):
.RS
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
199
200
201
202
203
204
205

206
207
208
209

210
211
212
213

214
215
216
217

218
219
220
221

222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237







-




-




-




-




-




-












.IP \(bu 3
NSImage url string
.IP \(bu 3
4-char OSType of IconServices icon
.PP
The \fIwidth\fR and \fIheight\fR arguments to \fBtk::mac::iconBitmap\fR define
the dimensions of the image to create, and \fI\-kind\fR must be one of:
.\" OPTION: -file
.TP
\fB\-file\fR
.
icon of file at given path
.\" OPTION: -fileType
.TP
\fB\-fileType\fR
.
icon of given file type
.\" OPTION: -osType
.TP
\fB\-osType\fR
.
icon of given 4-char OSType file type
.\" OPTION: -systemType
.TP
\fB\-systemType\fR
.
icon for given IconServices 4-char OSType
.\" OPTION: -namedImage
.TP
\fB\-namedImage\fR
.
named NSImage for given name
.\" OPTION: -imageFile
.TP
\fB\-imageFile\fR
.
image at given path
.RE
.SH "SEE ALSO"
bind(n), wm(n)
.SH KEYWORDS
about dialog, antialiasing, Apple event, icon, NSImage
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/tkerror.n.

14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29

30
31
32
33
34
35
36
14
15
16
17
18
19
20



21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
-
-
+





-
+







.SH SYNOPSIS
\fBtkerror \fImessage\fR
.BE
.SH DESCRIPTION
.PP
Note: as of Tk 4.1 the \fBtkerror\fR command has been renamed to
\fBbgerror\fR because the event loop (which is what usually invokes
it) is now part of Tcl.  Using the \fBtkerror\fR name is deprecated.
.PP
For backward compatibility
it) is now part of Tcl.  For backward compatibility
the \fBbgerror\fR provided by the current Tk version still
tries to call \fBtkerror\fR if there is one (or an auto loadable one),
so old script defining that error handler should still work, but you
should anyhow modify your scripts to use \fBbgerror\fR instead
of \fBtkerror\fR because that support for the old name might vanish
in the future. If that call fails, \fBbgerror\fR
in the near future. If that call fails, \fBbgerror\fR
posts a dialog showing the error and offering to see the stack trace
to the user. If you want your own error management you should
directly override \fBbgerror\fR instead of \fBtkerror\fR.
Documentation for \fBbgerror\fR is available as part of Tcl's
documentation.
.SH KEYWORDS
background error, reporting

Changes to doc/tkvars.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52

53
54





































55
56
57
58
59
60
61
62
63


64
























65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94
95
96
97
98


99
100
101
102
103
104
105
106
107
108
109
110












-
+





-










-
+













-










-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-







-
-













-
-
+











'\"
'\" Copyright (c) 1990-1994 The Regents of the University of California.
'\" Copyright (c) 1994-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.
'\"
.TH tkvars n 4.1 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
geometry, tk_library, tk_patchLevel, tk::scalingPct, tk_strictMotif, tk::svgFmt, tk_version \- Variables used or set by Tk
geometry, tk_library, tk_patchLevel, tk_strictMotif, tk_version \- Variables used or set by Tk
.BE
.SH DESCRIPTION
.PP
The following Tcl variables are either set or used by Tk at various times
in its execution:
.\" VARIABLE: tk_library
.TP 15
\fBtk_library\fR
.
This variable holds the file name for a directory containing a library
of Tcl scripts related to Tk.  These scripts include an initialization
file that is normally processed whenever a Tk application starts up,
plus other files containing procedures that implement default behaviors
for widgets.
.RS
.PP
The initial value of \fBtk_library\fR is set when Tk is added to
The initial value of \fBtcl_library\fR is set when Tk is added to
an interpreter;  this is done by searching several different directories
until one is found that contains an appropriate Tk startup script.
If the \fBTK_LIBRARY\fR environment variable exists, then
the directory it names is checked first.
If \fBTK_LIBRARY\fR is not set or does not refer to an appropriate
directory, then Tk checks several other directories based on a
compiled-in default location, the location of the Tcl library directory,
the location of the binary containing the application, and the current
working directory.
.PP
The variable can be modified by an application to switch to a different
library.
.RE
.\" VARIABLE: tk_patchLevel
.TP
\fBtk_patchLevel\fR
.
Contains a dot-separated sequence of decimal integers giving the
current patch level for Tk.
The patch level is incremented for each new release or patch, and
it uniquely identifies an official version of Tk.
.RS
.PP
This value is normally the same as the result of
.QW "\fBpackage require\fR \fBtk\fR" .
.QW "\fBpackage require\fR \fBTk\fR" .
.RE
.\" VARIABLE: scalingPct
.TP
\fBtk::scalingPct\fR
.
Tk sets this variable at initialization time to the scaling percentage
corresponding to the display's DPI scaling level.  This value is at least
100 and is restricted to multiples of 25 (100, 125, 150, 175, 200,
225, ...).  The sizes and various attributes of the Tk core and Ttk
widgets and their components, as well as the sizes of the images used by
Tk are chosen according to the scaling percentage, and this is
recommended for applications and library packages, too.
.RS
.PP
Note that any access to this variable is supposed to be strictly
read-only!  Note also that whenever the scaling factor used to convert
between physical units and pixels is changed via \fBtk scaling\fR, the
value of the variable \fBtk::scalingPct\fR is automatically updated.
.PP
On the windowing systems \fBwin32\fR and \fBaqua\fR the scaling
percentage is computed by rounding [\fBtk scaling\fR] * 75 to the
nearest multiple of 25 that is at least 100.  (On \fBaqua\fR the result
is always 100, and the desktop engine automatically scales everything as
needed.)  On \fBx11\fR, deriving the scaling percentage from
[\fBtk scaling\fR] is done as fallback method only, because the
implementation of display scaling is highly dependent on the desktop
environment and it mostly manipulates system resources that are resident
outside of Xlib, which Tk is based on.  Moreover, for technical reasons,
the value assigned to the variable \fBtk::scalingPct\fR can be different
from the one selected in the system settings (e.g., 200 rather than 125,
150, or 175 when running GNOME on Xorg or the Cinnamon desktop).  On
\fBx11\fR the scaling percentage is computed mostly (but not
exclusively) from the value of the X resource Xft.dpi, and, as an
additional step, Tk synchronizes the scaling factor used to convert
between physical units and pixels with the scaling percentage, with the
aid of the \fBtk scaling\fR command.
.RE
.\" VARIABLE: tk_strictMotif
.TP
\fBtk_strictMotif\fR
.
This variable is set to zero by default.
If an application sets it to one, then Tk attempts to adhere as
closely as possible to Motif look-and-feel standards.
For example, active elements such as buttons and scrollbar
sliders will not change color when the pointer passes over them.
Modern applications should not normally set this variable.
.\" VARIABLE: svgFmt
.TP
.TP 15
\fBtk::svgFmt\fR
.
This variable is set at Tk initialization time to
.RS
.RS 4
.PP
[\fBlist svg \-scale\fR [\fBexpr\fR {$\fBtk::scalingPct\fR / 100.0}]]
.RE
.PP
Typical values are {\fBsvg \-scale\fR 1.0}, {\fBsvg \-scale\fR 1.25},
{\fBsvg \-scale\fR 2.0}, etc.  It is recommended to pass the value of
this variable to the commands \fBimage create photo\fR, \fIimageName\fB
configure\fR, \fIimageName\fB put\fR, and \fIimageName\fB read\fR as the
value of their \fB\-format\fR option when creating or manipulating SVG
images, to make sure that their sizes will correspond to the display's
DPI scaling level.
.PP
Note that any access to this variable is supposed to be strictly
read-only!  Note also that whenever the scaling factor used to convert
between physical units and pixels is changed via \fBtk scaling\fR, the
value of the variable \fBtk::svgFmt\fR is automatically updated.
.RE
.\" VARIABLE: tk_version
.TP
\fBtk_version\fR
.
Tk sets this variable in the interpreter for each application.
The variable holds the current version number of the Tk
library in the form \fImajor\fR.\fIminor\fR.  \fIMajor\fR and
\fIminor\fR are integers.  The major version number increases in
any Tk release that includes changes that are not backward compatible
(i.e. whenever existing Tk applications and scripts may have to change to
work with the new release).  The minor version number increases with
each new release of Tk, except that it resets to zero whenever the
major version number changes.
.SS "INTERNAL AND DEBUGGING VARIABLES"
.PP
These variables should not normally be set by user code.
.\" VARIABLE: Priv
.TP
\fBtk::Priv\fR
.
This variable is an array containing several pieces of information
that are private to Tk.  The elements of \fBtk::Priv\fR are used by
Tk library procedures and default bindings.
They should not be accessed by any code outside Tk.
.\" VARIABLE: tk_textRedraw
.\" VARIABLE: tk_textRelayout
.TP
\fBtk_textRedraw\fR
.TP
\fBtk_textRelayout\fR
.
These variables are set by text widgets when they have debugging
turned on.  The values written to these variables can be used to
test or debug text widget operations.  These variables are mostly
used by Tk's test suite.
.SH "OTHER GLOBAL VARIABLES"
The following variables are only guaranteed to exist in \fBwish\fR
executables; the Tk library does not define them itself but many Tk
environments do.
.\" VARIABLE: geometry
.TP
.TP 6
\fBgeometry\fR
.
If set, contains the user-supplied geometry specification to use for
the main Tk window.
.SH "SEE ALSO"
package(n), tclvars(n), wish(1)
.SH KEYWORDS
environment, text, variables, version
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/tkwait.n.

8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
8
9
10
11
12
13
14

15
16
17
18
19

20
21
22
23
24
25

26
27
28

29
30
31
32
33
34

35
36
37
38
39
40
41







-

+

+

-






-



-






-







.TH tkwait n "" Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
tkwait \- Wait for variable to change or window to be destroyed
.SH SYNOPSIS
.nf
\fBtkwait variable \fIname\fR
.sp
\fBtkwait visibility \fIname\fR
.sp
\fBtkwait window \fIname\fR
.fi
.BE
.SH DESCRIPTION
.PP
The \fBtkwait\fR command waits for one of several things to happen,
then it returns without taking any other actions.
The return value is always an empty string.
.\" METHOD: variable
If the first argument is \fBvariable\fR (or any abbreviation of
it) then the second argument is the name of a global variable and the
command waits for that variable to be modified.
.\" METHOD: visibility
If the first argument is \fBvisibility\fR (or any abbreviation
of it) then the second argument is the name of a window and the
\fBtkwait\fR command waits for a change in its
visibility state (as indicated by the arrival of a VisibilityNotify
event).  This form is typically used to wait for a newly-created
window to appear on the screen before taking some action.
.\" METHOD: window
If the first argument is \fBwindow\fR (or any abbreviation
of it) then the second argument is the name of a window and the
\fBtkwait\fR command waits for that window to be destroyed.
This form is typically used to wait for a user to finish interacting
with a dialog box before using the result of that interaction.
.PP
While the \fBtkwait\fR command is waiting it processes events in

Changes to doc/toplevel.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27











28
29
30
31

32


33
34
35
36
37
38
39







-
+












-
-
-
-
-
-
-
-
-
-
-




-
+
-
-







.TH toplevel n 8.4 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
toplevel \- Create and manipulate 'toplevel' main and popup window widgets
.SH SYNOPSIS
\fBtoplevel\fI pathName \fR?\fIoptions\fR?
\fBtoplevel\fR \fIpathName \fR?\fIoptions\fR?
.SO
\-borderwidth	\-highlightcolor	\-pady
\-cursor	\-highlightthickness	\-relief
\-highlightbackground	\-padx	\-takefocus
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-background background Background
This option is the same as the standard \fB\-background\fR option
except that its value may also be specified as an empty string.
In this case, the widget will display no background or border, and
no colors will be consumed from its colormap for its background
and border.
.VS "8.7, TIP262"
An empty background will disable drawing the background image.
.OP \-backgroundimage backgroundImage BackgroundImage
This specifies an image to display on the toplevel's background within
the border of the toplevel (i.e., the image will be clipped by the
toplevel's highlight ring and border, if either are present) on top of
the background;
subwidgets of the toplevel will be drawn on top. The image must have
been created with the \fBimage create\fR command. If specified as the
empty string, no image will be displayed.
.VE "8.7, TIP262"
.OP \-class class Class
Specifies a class for the window.
This class will be used when querying the option database for
the window's other options, and it will also be used later for
other purposes such as bindings. Some window managers display the
other purposes such as bindings.
class name for windows in their dock while some others display the
window title.
The \fB\-class\fR option may not be changed with the \fBconfigure\fR
widget command.
.OP \-colormap colormap Colormap
Specifies a colormap to use for the window.
The value may be either \fBnew\fR, in which case a new colormap is
created for the window and its children, or the name of another
window (which must be on the same screen and have the same visual
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
67
68
69
70
71
72
73









74
75
76
77
78
79
80







-
-
-
-
-
-
-
-
-







Specifies the screen on which to place the new window.
Any valid screen name may be used, even one associated with a
different display.
Defaults to the same screen as its parent.
This option is special in that it may not be specified via the option
database, and it may not be modified with the \fBconfigure\fR
widget command.
.OP \-tile tile Tile
.VS "8.7, TIP262"
This specifies how to draw the background image (see
\fB\-backgroundimage\fR) on the toplevel.
If true (according to \fBTcl_GetBoolean\fR), the image will be tiled
to fill the whole toplevel, with the origin of the first copy of the
image being the top left of the interior of the toplevel.
If false (the default), the image will be centered within the toplevel.
.VE "8.7, TIP262"
.OP \-use use Use
This option is used for embedding. If the value is not an empty string,
it must be the window identifier of a container window, specified as
a hexadecimal string like the ones returned by the \fBwinfo id\fR
command. The toplevel widget will be created as a child of the given
container instead of the root window for the screen.  If the container
window is in a Tk application, it must be a frame or toplevel widget for
122
123
124
125
126
127
128
129

130
131

132
133
134

135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
100
101
102
103
104
105
106

107
108

109
110
111

112
113
114
115
116
117
118
119

120

121
122

123
124
125
126

127
128

129
130
131
132

133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150


151

152
153
154
155
156
157







-
+

-
+


-
+







-

-
+

-




-


-




-


-
















-
-

-
+





by the \fIpathName\fR argument).  Additional
options, described above, may be specified on the command line
or in the option database
to configure aspects of the toplevel such as its background color
and relief.  The \fBtoplevel\fR command returns the
path name of the new window.
.PP
A toplevel is similar to a \fBframe\fR except that it is created as a
A toplevel is similar to a frame except that it is created as a
top-level window:  its X parent is the root window of a screen
rather than the logical parent from its Tk path name.  The primary
rather than the logical parent from its path name.  The primary
purpose of a toplevel is to serve as a container for dialog boxes
and other collections of widgets.  The only visible features
of a toplevel are its background and an optional 3-D border
of a toplevel are its background color and an optional 3-D border
to make the toplevel appear raised or sunken.
.SH "WIDGET COMMAND"
.PP
The \fBtoplevel\fR command creates a new Tcl command whose
name is the same as the path name of the toplevel's window.  This
command may be used to invoke various
operations on the widget.  It has the following general form:
.PP
.CS
\fIpathName option \fR?\fIarg ...\fR?
\fIpathName option \fR?\fIarg arg ...\fR?
.CE
.PP
\fIPathName\fR is the name of the command, which is the same as
the toplevel widget's path name.  \fIOption\fR and the \fIarg\fRs
determine the exact behavior of the command.  The following
commands are possible for toplevel widgets:
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
\fIOption\fR may have any of the values accepted by the \fBtoplevel\fR
command.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
information on the format of this list).  If \fIoption\fR is specified
with no \fIvalue\fR, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no \fIoption\fR is specified).  If
one or more \fIoption\-value\fR pairs are specified, then the command
modifies the given widget option(s) to have the given value(s);  in
this case the command returns an empty string.
\fIOption\fR may have any of the values accepted by the \fBtoplevel\fR
command.
.SH BINDINGS
.PP
When a new toplevel is created, it has no default event bindings:
toplevels are not intended to be interactive.
.PP
Be aware that bindings on toplevels may receive events from subwidgets.
.SH "SEE ALSO"
bind(n), bindtags(n), frame(n), wm(n)
frame(n)
.SH KEYWORDS
toplevel, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_Geometry.3.

62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90

91
92
93
94
95
96
97
98
99
100

101
102
103

104
105
106
107



108
109
110
111
112
113
114
62
63
64
65
66
67
68

69

70
71
72
73
74
75
76
77
78
79
80
81

82

83
84
85
86
87

88
89
90
91
92
93
94
95
96
97

98
99
100

101




102
103
104
105
106
107
108
109
110
111







-

-
+











-

-
+




-
+









-
+


-
+
-
-
-
-
+
+
+







.AP "Ttk_Box *" cavity in/out
A rectangular region from which a parcel is allocated.
.AP short border in
Extra padding (in pixels) to add uniformly to each side of a region.
.AP short bottom in
Extra padding (in pixels) to add to the bottom of a region.
.AP Ttk_Box box in
Specifies a rectangular region.
.AP "Ttk_Box *" box_rtn out
A rectangular region.
Specifies a rectangular region.
.AP int height in
The height in pixels of a region.
.AP "Tcl_Interp *" interp in
Used to store error messages.
.AP int left in
Extra padding (in pixels) to add to the left side of a region.
.AP "Tcl_Obj *" objPtr in
String value contains a symbolic name
to be converted to an enumerated value or bitmask.
Internal rep may be be modified to cache corresponding value.
.AP Ttk_Padding padding in
Extra padding to add on the inside of a region.
.AP "Ttk_Padding *" padding_rtn out
Padding present in the inside of a region.
Extra padding to add on the inside of a region.
.AP Ttk_Box parcel in
A rectangular region, allocated from a cavity.
.AP int relief in
One of the standard Tk relief options
(\fBTK_RELIEF_RAISED\fR, \fBTK_RELIEF_SUNKEN\fR, etc.).
(TK_RELIEF_RAISED, TK_RELIEF_SUNKEN, etc.).
See \fBTk_GetReliefFromObj\fR.
.AP short right in
Extra padding (in pixels) to add to the right side of a region.
.AP Ttk_Side side in
One of \fBTTK_SIDE_LEFT\fR, \fBTTK_SIDE_TOP\fR,
\fBTTK_SIDE_RIGHT\fR, or \fBTTK_SIDE_BOTTOM\fR.
.AP unsigned sticky in
A bitmask containing one or more of the bits
\fBTTK_STICK_W\fR (west, or left),
\fBTTK_STICK_E\fR (east, or right),
\fBTTK_STICK_E\fR (east, or right,
\fBTTK_STICK_N\fR (north, or top), and
\fBTTK_STICK_S\fR (south, or bottom).
\fBTTK_FILL_X\fR is defined as a synonym for
\fBTTK_FILL_X\fR is defined as a synonym for (TTK_STICK_W|TTK_STICK_E),
(\fBTTK_STICK_W\fR|\fBTTK_STICK_E\fR),
\fBTTK_FILL_Y\fR is a synonym for (\fBTTK_STICK_N\fR|\fBTTK_STICK_S\fR),
and  \fBTTK_FILL_BOTH\fR
is a synonym for (\fBTTK_FILL_X\fR|\fBTTK_FILL_Y\fR).
\fBTTK_FILL_Y\fR is a synonym for (TTK_STICK_N|TTK_STICK_S),
and  \fBTTK_FILL_BOTH\fR and \fBTTK_STICK_ALL\fR
are synonyms for (TTK_FILL_X|TTK_FILL_Y).
See also: \fIgrid(n)\fR.
.AP Tk_Window tkwin in
Window whose screen geometry determines
the conversion between absolute units and pixels.
.AP short top in
Extra padding at the top of a region.
.AP int width in
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223







-
+








\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
See \fBTk_GetPixelsFromObj(3)\fR for the syntax of length specifications.
.PP
\fBTtk_GetBorderFromObj\fR is the same as \fBTtk_GetPaddingFromObj\fR
except that the lengths are specified as integers
(i.e., resolution-dependent values like \fI3m\fR are not allowed).
(i.e., resolution-dependant values like \fI3m\fR are not allowed).
.PP
\fBTtk_GetStickyFromObj\fR converts the string in \fIobjPtr\fR
to a \fIsticky\fR bitmask.  The string contains zero or more
of the characters \fBn\fR, \fBs\fR, \fBe\fR, or \fBw\fR.
.SH "SEE ALSO"
Tk_GetReliefFromObj(3), Tk_GetPixelsFromObj(3), Tk_GetAnchorFromObj(3)
.SH "KEYWORDS"
geometry, padding, margins, box, region, sticky, relief

Changes to doc/ttk_button.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::button n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::button \- Widget that issues a command when pressed
.SH SYNOPSIS
\fBttk::button\fI pathName \fR?\fIoptions\fR?
\fBttk::button\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
A \fBttk::button\fR widget displays a textual label and/or image,
and evaluates a command when pressed.
.SO ttk_widget
\-class	\-compound	\-cursor
\-image	\-justify	\-state	\-style
44
45
46
47
48
49
50
51

52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109

110
111
112

113
114
115

116
117
118
119
120
121
122
44
45
46
47
48
49
50

51



52

53
54

55
56
57
58
59








60




61
62
































63


64



65



66
67
68
69
70
71
72
73







-
+
-
-
-
+
-


-





-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
-
+







.\" .OP \-foreground foreground Foreground
.\" .OP \-font font Font
.\" .OP \-anchor anchor Anchor
.\" .OP \-relief relief Relief
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
button widgets support the following additional commands:
commands, buttons support the following additional widget commands:
.\" METHOD: invoke
.TP
\fIpathName \fBinvoke\fR
.
Invokes the command associated with the button.
.SH "STANDARD STYLES"
.PP
\fBTtk::button\fR widgets support the \fBToolbutton\fR style in all standard
themes, which is useful for creating widgets for toolbars.
.PP
In the Aqua theme there are several other styles which can be used to
produce replicas of many of the different button types that are
discussed in Apple's Human Interface Guidelines.  These include
\fBDisclosureButton\fR, \fBDisclosureTriangle\fR, \fBHelpButton\fR,
\fBImageButton\fR, \fBInlineButton\fR, \fBGradientButton\fR,
\fBRoundedRectButton\fR, and \fBRecessedButton\fR.
.SH "STYLING OPTIONS"
.SH "COMPATIBILITY OPTIONS"
.PP
The class name for a \fBttk::button\fP is \fBTButton\fP.
.PP
Dynamic states: \fBactive\fP, \fBdisabled\fP, \fBpressed\fP, \fBreadonly\fP.
.OP \-state state State
May be set to \fBnormal\fR or \fBdisabled\fR to control the
.PP
\fBTButton\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-anchor\fP \fIanchor\fP
.br
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.br
\fB\-highlightcolor\fP \fIcolor\fP
.br
\fB\-highlightthickness\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-relief\fP \fIrelief\fP
.br
\fB\-shiftrelief\fP \fIamount\fP
.RS
\fB\-shiftrelief\fP specifies how far the button contents are
shifted down and right in the \fIpressed\fP state.
\fBdisabled\fR state bit. This is a
This action provides additional skeuomorphic feedback.
.RE
.QW write-only
\fB\-width\fP \fIamount\fP
.PP
Some options are only available for specific themes.
option: setting it changes the widget state, but the \fBstate\fR
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
widget command does not affect the state option.
.SH "SEE ALSO"
ttk::widget(n), button(n)
.SH "KEYWORDS"
widget, button, default, command
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_checkbutton.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::checkbutton n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::checkbutton \- On/off widget
.SH SYNOPSIS
\fBttk::checkbutton\fI pathName \fR?\fIoptions\fR?
\fBttk::checkbutton\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
A \fBttk::checkbutton\fR widget is used to show or change a setting.
It has two states, selected and deselected.
The state of the checkbutton may be linked to a Tcl variable.
.SO ttk_widget
\-class	\-compound	\-cursor
33
34
35
36
37
38
39
40

41
42
43

44

45
46
47
48
49
50
51
52
53
54
33
34
35
36
37
38
39

40



41

42
43
44

45
46
47
48
49
50
51







-
+
-
-
-
+
-
+


-







when the widget is selected.  Defaults to \fB1\fR.
.OP \-variable variable Variable
The name of a global variable whose value is linked to the widget.
Defaults to the widget pathname if not specified.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
checkbutton widgets support the following additional commands:
commands, checkbuttons support the following additional
.\" METHOD: invoke
widget commands:
.TP
\fIpathname\fB invoke\fR
.
Toggles between the selected and deselected states
and evaluates the associated \fB\-command\fR.
If the widget is currently selected, sets the \fB\-variable\fR
to the \fB\-offvalue\fR and deselects the widget;
otherwise, sets the \fB\-variable\fR to the \fB\-onvalue\fR
Returns the result of the \fB\-command\fR.
.\" Missing: select, deselect, toggle
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
64
65
66
67
68
69
70






























71
72
73
74
75
76
77







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







or
.QW indeterminate
selection.)
.SH "STANDARD STYLES"
.PP
\fBTtk::checkbutton\fR widgets support the \fBToolbutton\fR style in all
standard themes, which is useful for creating widgets for toolbars.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::checkbutton\fP is \fBTCheckbutton\fP.
.PP
Dynamic states: \fBactive\fP, \fBalternate\fP, \fBdisabled\fP,
\fBpressed\fP, \fBselected\fP, \fBreadonly\fP.
.PP
\fBTCheckbutton\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-indicatorbackground\fP \fIcolor\fP
.br
\fB\-indicatorcolor\fP \fIcolor\fP
.br
\fB\-indicatormargin\fP \fIpadding\fP
.br
\fB\-indicatorrelief\fP \fIrelief\fP
.br
\fB\-padding\fP \fIpadding\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::radiobutton(n), checkbutton(n)
.SH "KEYWORDS"
widget, button, toggle, check, option
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_combobox.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29












-
+








-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::combobox n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::combobox \- text field with popdown selection list
.SH SYNOPSIS
\fBttk::combobox\fI pathName \fR?\fIoptions\fR?
\fBttk::combobox\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::combobox\fR combines a text field with a pop-down list of values;
the user may select the value of the text field from among the
values in the list.
.SO ttk_widget
\-class	\-cursor	\-takefocus
\-style	\-placeholder	\-placeholderforeground
\-style
.SE
.\" ALSO: Other entry widget options
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-exportselection exportSelection ExportSelection
Boolean value.
If set, the widget selection is linked to the X selection.
.OP \-justify justify Justify
51
52
53
54
55
56
57
58
59



60
61


62
63




64
65
66
67
68

69
70
71
72
73
74

75
76
77
78
79
80








81
82

83
84




85
86
87

88
89
90
91
92







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
51
52
53
54
55
56
57


58
59
60


61
62


63
64
65
66
67
68

69

70




71

72

73
74

75

76
77
78
79
80
81
82
83
84

85

86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112



















































































113
114
115
116
117
118
119







-
-
+
+
+
-
-
+
+
-
-
+
+
+
+


-

-
+
-
-
-
-

-
+
-


-

-
+
+
+
+
+
+
+
+

-
+
-

+
+
+
+


-
+





+
+
+
+
+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







.OP \-values values Values
Specifies the list of values to display in the drop-down listbox.
.OP \-width width Width
Specifies an integer value indicating the desired width of the entry window,
in average-size characters of the widget's font.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
The following subcommands are possible for combobox widgets:
'\".TP
'\"\fIpathName \fBcget\fR \fIoption\fR
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
'\"Returns the current value of the specified \fIoption\fR.
'\"See \fIttk::widget(n)\fR.
combobox widgets support the following additional commands:
.\" METHOD: current
'\".TP
'\"\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
'\"Modify or query widget options.
'\"See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBcurrent\fR ?\fInewIndex\fR?
.
If \fInewIndex\fR is supplied, sets the combobox value
to the element at position \fInewIndex\fR in the list of \fB\-values\fR
to the element at position \fInewIndex\fR in the list of \fB\-values\fR.
(in addition to integers, the \fBend\fR index is supported and indicates
the last element of the list, moreover the same simple interpretation as
for the command \fBstring index\fR is supported, with simple integer index
arithmetic and indexing relative to \fBend\fR).
Otherwise, returns the index of the current value in the list of
\fB\-values\fR or \fB{}\fR if the current value does not appear in the list.
\fB\-values\fR or \fB\-1\fR if the current value does not appear in the list.
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the current value of the combobox.
.\" METHOD: set
'\".TP
'\"\fIpathName \fBidentify \fIx y\fR
'\"Returns the name of the element at position \fIx\fR, \fIy\fR.
'\"See \fIttk::widget(n)\fR.
'\".TP
'\"\fIpathName \fBinstate \fIstateSpec\fR ?\fIscript\fR?
'\"Test the widget state.
'\"See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBset\fI value\fR
\fIpathName \fBset\fR \fIvalue\fR
.
Sets the value of the combobox to \fIvalue\fR.
'\".TP
'\"\fIpathName \fBstate\fR ?\fIstateSpec\fR?
'\"Modify or query the widget state.
'\"See \fIttk::widget(n)\fR.
.PP
The combobox widget also supports the following \fBttk::entry\fR
widget commands:
widget subcommands (see \fIttk::entry(n)\fR for details):
.DS
.ta 5.5c 11c
\fBbbox\fR	\fBdelete\fR	\fBicursor\fR
\fBindex\fR	\fBinsert\fR	\fBselection\fR
\fBxview\fR
.DE
The combobox widget also supports the following generic \fBttk::widget\fR
widget subcommands (see \fIttk::widget(n)\fR for details):
.DS
.ta 5.5c 11c
\fBcget\fR	\fBconfigure\fR	\fBidentify\fR
\fBinstate\fR	\fBstate\fR
.DE
.SH "VIRTUAL EVENTS"
.PP
The combobox widget generates a \fB<<ComboboxSelected>>\fR virtual event
when the user selects an element from the list of values.
If the selection action unposts the listbox,
this event is delivered after the listbox is unposted.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::combobox\fP is \fBTCombobox\fP.
The \fBttk::combobox\fP uses the \fBentry\fP and
\fBlistbox\fP widgets internally.
The listbox frame has a class name of \fBComboboxPopdownFrame\fP.
.PP
Dynamic states: \fBdisabled\fP, \fBfocus\fP, \fBpressed\fP, \fBreadonly\fP.
.PP
\fBTCombobox\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-arrowcolor\fP \fIcolor\fP
.br
\fB\-arrowsize\fP \fIamount\fP
.br
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-focusfill\fP \fIcolor\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-fieldbackground\fP \fIcolor\fP
.RS
Can only be changed when using non-native and non-graphical themes.
.RE
\fB\-insertcolor\fP \fIcolor\fP
.br
\fB\-insertwidth\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-placeholderforeground\fP \fIcolor\fP
.br
\fB\-postoffset\fP \fIpadding\fP
.br
\fB\-selectbackground\fP \fIcolor\fP
.RS
Text entry select background.
.RE
\fB\-selectforeground\fP \fIcolor\fP
.RS
Text entry select foreground.
.RE
.PP
The \fBttk::combobox\fP popdown listbox cannot be configured using
\fBttk::style\fP nor via the widget \fBconfigure\fP command.  The listbox
can be configured using the option database.
.PP
option add *TCombobox*Listbox.background \fIcolor\fP
.br
option add *TCombobox*Listbox.font \fIfont\fP
.br
option add *TCombobox*Listbox.foreground \fIcolor\fP
.br
option add *TCombobox*Listbox.selectBackground \fIcolor\fP
.br
option add *TCombobox*Listbox.selectForeground \fIcolor\fP
.PP
To configure a specific listbox (subject to future change):
.CS
set popdown [ttk::combobox::PopdownWindow .mycombobox]
$popdown.f.l configure \-font \fIfont\fP
.CE
.PP
\fBComboboxPopdownFrame\fP
styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-borderwidth\fP \fIamount\fP
.br
\fB\-relief\fP \fIrelief\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::entry(n)
.SH KEYWORDS
choice, entry, list box, text box, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_entry.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36







-
+













-
+







'\"
.TH ttk::entry n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::entry \- Editable text field widget
.SH SYNOPSIS
\fBttk::entry\fI pathName \fR?\fIoptions\fR?
\fBttk::entry\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
An \fBttk::entry\fR widget displays a one-line text string and
allows that string to be edited by the user.
The value of the string may be linked to a Tcl variable
with the \fB\-textvariable\fR option.
Entry widgets support horizontal scrolling with the
standard \fB\-xscrollcommand\fR option and \fBxview\fR widget command.
.SO ttk_widget
\-class	\-cursor
\-font	\-foreground
\-style
\-takefocus	\-xscrollcommand	\-placeholder	\-placeholderforeground
\-takefocus	\-xscrollcommand
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-exportselection exportSelection ExportSelection
A boolean value specifying whether or not
a selection in the widget should be linked to the X selection.
If the selection is exported, then selecting in the widget deselects
the current X selection, selecting outside the widget deselects any
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162








163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184




185
186
187
188
189
190
191
192
193
194
195




196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222




223
224
225
226
227
228
229
230















































231
232
233
234
235
236
237
133
134
135
136
137
138
139



140
141





142

143
144

145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169

170
171

172

173
174

175
176

177
178
179
180
181
182

183

184
185

186
187

188
189
190
191
192
193

194
195
196
197
198

199
200
201
202
203

204
205
206

207

208
209
210
211
212
213

214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278







-
-
-


-
-
-
-
-
+
-


-








-
+
+
+
+
+
+
+
+


-







-


-

-


-


-
+
+
+
+


-

-


-


-
+
+
+
+


-





-





-



-
+
-






-
+
+
+
+


-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







.LP
Abbreviations may be used for any of the forms above, e.g.\|
.QW \fBe\fR
or
.QW \fBsel.l\fR .
In general, out-of-range indices are automatically rounded to the
nearest legal value.
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBstate\fR, \fBstyle\fR and \fBxview\fR
commands (see \fBttk::widget\fR),
entry widgets support the following additional commands:
The following subcommands are possible for entry widgets:
.\" METHOD: bbox
.TP
\fIpathName \fBbbox \fIindex\fR
.
Returns a list of four numbers describing the bounding box of the
character given by \fIindex\fR.
The first two elements of the list give the x and y coordinates of
the upper-left corner of the screen area covered by the character
(in pixels relative to the widget) and the last two elements give
the width and height of the character, in pixels.
The bounding box may refer to a region outside the visible area
of the window.
.\" METHOD: delete
'\".TP
'\"\fIpathName \fBcget\fR \fIoption\fR
'\"Returns the current value of the specified \fIoption\fR.
'\"See \fIttk::widget(n)\fR.
'\".TP
'\"\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
'\"Modify or query widget options.
'\"See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBdelete \fIfirst \fR?\fIlast\fR?
.
Delete one or more elements of the entry.
\fIFirst\fR is the index of the first character to delete, and
\fIlast\fR is the index of the character just after the last
one to delete.
If \fIlast\fR is not specified it defaults to \fIfirst\fR+1,
i.e. a single character is deleted.
This command returns the empty string.
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the entry's string.
.\" METHOD: icursor
.TP
\fIpathName \fBicursor \fIindex\fR
.
Arrange for the insert cursor to be displayed just before the character
given by \fIindex\fR.  Returns the empty string.
.\" METHOD: index
'\".TP
'\"\fIpathName \fBidentify \fIx y\fR
'\"Returns the name of the element at position \fIx\fR, \fIy\fR,
'\"or the empty string if the coordinates are outside the window.
.TP
\fIpathName \fBindex\fI index\fR
.
Returns the numerical index corresponding to \fIindex\fR.
.\" METHOD: insert
.TP
\fIpathName \fBinsert \fIindex string\fR
.
Insert \fIstring\fR just before the character
indicated by \fIindex\fR.  Returns the empty string.
.\" METHOD: selection
'\".TP
'\"\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR?
'\"Test the widget state.
'\"See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBselection \fIoption arg\fR
.
This command is used to adjust the selection within an entry.  It
has several forms, depending on \fIoption\fR:
.RS
.TP
\fIpathName \fBselection clear\fR
.
Clear the selection if it is currently in this widget.
If the selection is not in this widget then the command has no effect.
Returns the empty string.
.TP
\fIpathName \fBselection present\fR
.
Returns 1 if there is are characters selected in the entry,
0 if nothing is selected.
.TP
\fIpathName \fBselection range \fIstart end\fR
\fIpathName \fBselection range \fIstart\fR \fIend\fR
.
Sets the selection to include the characters starting with
the one indexed by \fIstart\fR and ending with the one just
before \fIend\fR.
If \fIend\fR refers to the same character as \fIstart\fR or an
earlier one, then the entry's selection is cleared.
.RE
.\" METHOD: validate
'\".TP
'\"\fIpathName \fBstate\fR ?\fIstateSpec\fR?
'\"Modify or query the widget state.
'\"See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBvalidate\fR
.
Force revalidation, independent of the conditions specified
by the \fB\-validate\fR option.
Returns 0 if validation fails, 1 if it succeeds.
Sets or clears the \fBinvalid\fR state accordingly.
See \fBVALIDATION\fR below for more details.
.TP
\fIpathName \fBxview \fIargs\fR
This command is used to query and change the horizontal position of the
text in the widget's window.  It can take any of the following
forms:
.RS
.TP
\fIpathName \fBxview\fR
Returns a list containing two elements.
Each element is a real fraction between 0 and 1; together they describe
the horizontal span that is visible in the window.
For example, if the first element is .2 and the second element is .6,
20% of the entry's text is off-screen to the left, the middle 40% is visible
in the window, and 40% of the text is off-screen to the right.
These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
option.
.TP
\fIpathName \fBxview\fR \fIindex\fR
Adjusts the view in the window so that the character given by \fIindex\fR
is displayed at the left edge of the window.
.TP
\fIpathName \fBxview moveto\fI fraction\fR
Adjusts the view in the window so that the character \fIfraction\fR of the
way through the text appears at the left edge of the window.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer.
\fIWhat\fR must be either \fBunits\fR or \fBpages\fR.
'\" or an abbreviation of one of these, but we don't document that.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display;  if it is
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left
become visible;  if it is positive then characters farther to the right
become visible.
.RE
.PP
The entry widget also supports the following generic \fBttk::widget\fR
widget subcommands (see \fIttk::widget(n)\fR for details):
.DS
.ta 5.5c 11c
\fBcget\fR	\fBconfigure\fR	\fBidentify\fR
\fBinstate\fR	\fBstate\fR
.DE
.SH VALIDATION
.PP
The \fB\-validate\fR, \fB\-validatecommand\fR, and \fB\-invalidcommand\fR
options are used to enable entry widget validation.
.SS "VALIDATION MODES"
.PP
There are two main validation modes: \fIprevalidation\fR,
347
348
349
350
351
352
353
354

355
356
357


358
359
360
361
362
363
364
388
389
390
391
392
393
394

395



396
397
398
399
400
401
402
403
404







-
+
-
-
-
+
+







.IP \0\(bu 4
Clicking mouse button 1 with the Control key down will position the
insert cursor in the entry without affecting the selection.
.IP \0\(bu 4
If any normal printing characters are typed in an entry, they are
inserted at the point of the insert cursor.
.IP \0\(bu 4
The view in the entry can be adjusted by dragging with the middle
The view in the entry can be adjusted by dragging with mouse button 2.
mouse button (button 2, or button 3 in TkAqua). If the middle mouse
button is clicked without moving the mouse, the selection is copied
into the entry at the position of the mouse cursor.
If mouse button 2 is clicked without moving the mouse, the selection
is copied into the entry at the position of the mouse cursor.
.IP \0\(bu 4
If the mouse is dragged out of the entry on the left or right sides
while button 1 is pressed, the entry will automatically scroll to
make more text visible (if there is more text off-screen on the side
where the mouse left the window).
.IP \0\(bu 4
The Left and Right keys move the insert cursor one character to the
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
457
458
459
460
461
462
463














































464
465
466
467
468
469
470







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







Typically, the text is
.QW grayed-out
in the \fBdisabled\fR state,
and a different background is used in the \fBreadonly\fR state.
.PP
The entry widget sets the \fBinvalid\fR state if revalidation fails,
and clears it whenever validation succeeds.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::entry\fP is \fBTEntry\fP.
.PP
Dynamic states: \fBdisabled\fP, \fBfocus\fP, \fBreadonly\fP.
.PP
\fBTEntry\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.RS
For backwards compatibility, when using the aqua theme (for macOS), this
option behaves as an alias for the \fB\-fieldbackground\fP provided that no
value is specified for \fB\-fieldbackground\fP. Otherwise it is ignored.
.RE
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-fieldbackground\fP \fIcolor\fP
.RS
Some themes use a graphical background and their field background colors
cannot be changed.
.RE
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-insertcolor\fP \fIcolor\fP
.br
\fB\-insertwidth\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-placeholderforeground\fP \fIcolor\fP
.br
\fB\-relief\fP \fIrelief\fP
.br
\fB\-selectbackground\fP \fIcolor\fP
.br
\fB\-selectborderwidth\fP \fIamount\fP
.br
\fB\-selectforeground\fP \fIcolor\fP
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), entry(n)
.SH KEYWORDS
entry, widget, text field
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_frame.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19


20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36


37
38


39
40
41
42
43
44
45
46
47



















48
49
50
51
52
53
54












-
+






-
-
+
+




-











-
-
+
+
-
-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2005 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::frame n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::frame \- Simple container widget
.SH SYNOPSIS
\fBttk::frame\fI pathName \fR?\fIoptions\fR?
\fBttk::frame\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::frame\fR widget is a container, used to group other widgets
together.
.SO ttk_widget
\-class	\-cursor	\-padding
\-style	\-takefocus
\-class	\-cursor	\-padding	\-style
\-takefocus
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-borderwidth borderWidth BorderWidth
The desired width of the widget border.  Defaults to 0.
May be ignored depending on the theme used.
.OP \-relief relief Relief
One of the standard Tk border styles:
\fBflat\fR, \fBgroove\fR, \fBraised\fR, \fBridge\fR,
\fBsolid\fR, or \fBsunken\fR.
Defaults to \fBflat\fR.
.OP \-width width Width
If specified, the widget's requested width in pixels.
.OP \-height height Height
If specified, the widget's requested height in pixels.
.SH "WIDGET COMMAND"
.PP
Frame widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Supports the standard widget commands
\fBconfigure\fR, \fBcget\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR;
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
see \fIttk::widget(n)\fR.
.SH "NOTES"
.PP
Note that if the \fBpack\fR, \fBgrid\fR, or other geometry managers
are used to manage the children of the \fBframe\fR,
by the GM's requested size will normally take precedence
over the \fBframe\fR widget's \fB\-width\fR and \fB\-height\fR options.
\fBpack propagate\fR and \fBgrid propagate\fR can be used
to change this.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::frame\fP is \fBTFrame\fP.
.PP
\fBTFrame\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-relief\fP \fIrelief\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH BINDINGS
.PP
When a new \fBttk::frame\fR is created, it has no default event bindings;
\fBttk::frame\fRs are not intended to be interactive.
.SH "SEE ALSO"
ttk::widget(n), ttk::labelframe(n), frame(n)
.SH "KEYWORDS"
widget, frame, container
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_image.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39


40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60


61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101




102
103

104
105
106
107
108
109
110
111
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28

29

30
31
32
33
34
35


36
37
38
39

40
41

42
43

44

45

46
47
48
49
50
51
52


53
54
55
56

57

58

59
60
61
62
63
64
65

66
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81



82
83
84




85
86
87
88
89

90
91
92
93
94
95
96
97
98












-
+














-

-
+
-






-
-
+
+


-


-


-

-
+
-







-
-
+
+


-

-
+
-







-


-














-
-
-



-
-
-
-
+
+
+
+

-
+








'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk_image n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk_image \- Define an element based on an image
.SH SYNOPSIS
\fBttk::style element create \fIname \fBimage\fI imageSpec\fR ?\fIoptions\fR?
\fBttk::style element create \fIname\fR \fBimage\fR \fIimageSpec\fR ?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
The \fIimage\fR element factory creates a new element
in the current theme whose visual appearance is determined
by Tk images.
\fIimageSpec\fP is a list of one or more elements.
The first element is the default image name.
The rest of the list is a sequence of \fIstatespec / value\fR
pairs specifying other images to use when the element is
in a particular state or combination of states.
.SH OPTIONS
.PP
Valid \fIoptions\fR are:
.\" OPTION: -border
.TP
\fB\-border\fI padding\fR
\fB\-border\fR \fIpadding\fR
.
\fIpadding\fR is a list of up to four integers, specifying
the left, top, right, and bottom borders, respectively.
If fewer than four elements are specified,
\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
In other words, a list of three numbers specify the left, vertical, and right
border; a list of two numbers specify the horizontal and the vertical border;
In other words, a list of three numbers specify the left, vertical, and right border;
a list of two numbers specify the horizontal and the vertical border;
a single number specifies the same border all the way around the element.
See \fBIMAGE STRETCHING\fR, below.
.\" OPTION: -height
.TP
\fB\-height \fIheight\fR
.
Specifies a minimum height for the element.
If less than zero, the base image's height is used as a default.
.\" OPTION: -padding
.TP
\fB\-padding\fI padding\fR
\fB\-padding\fR \fIpadding\fR
.
Specifies the element's interior padding.
The padding is a list of up to four length specifications
\fIleft top right bottom\fR.
If fewer than four elements are specified,
\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
In other words, a list of three numbers specify the left, vertical, and right
padding; a list of two numbers specify the horizontal and the vertical padding;
In other words, a list of three numbers specify the left, vertical, and right padding;
a list of two numbers specify the horizontal and the vertical padding;
a single number specifies the same padding all the way around the widget.
Defaults to \fB\-border\fR if not specified.
.\" OPTION: -sticky
.TP
\fB\-sticky\fI spec\fR
\fB\-sticky\fR \fIspec\fR
.
Specifies how the image is placed within the final parcel.
\fIspec\fR contains zero or more characters
.QW n ,
.QW s ,
.QW w ,
or
.QW e .
.\" OPTION: -width
.TP
\fB\-width \fIwidth\fR
.
Specifies a minimum width for the element.
If less than zero, the base image's width is used as a default.
.SH "IMAGE STRETCHING"
.PP
If the element's allocated parcel is larger than the image,
the image will be placed in the parcel based on the \fB\-sticky\fR option.
If the image needs to stretch horizontally (i.e., \fB\-sticky ew\fR)
or vertically (\fB\-sticky ns\fR),
subregions of the image are replicated to fill the parcel
based on the \fB\-border\fR option.
The \fB\-border\fR divides the image into 9 regions:
four fixed corners, top and left edges (which may be tiled horizontally),
left and right edges (which may be tiled vertically),
and the central area (which may be tiled in both directions).
.PP
An image element that is not meant to claim any space (for example when used
as a background image) should use \fB\-width 0\fR and \fB\-height 0\fR.
.SH "EXAMPLE"
.PP
.CS
set img1 [image create photo -file button.png]
set img2 [image create photo -file button-pressed.png]
set img3 [image create photo -file button-active.png]
ttk::style element create Button.button image \e
set img1 [image create photo \-file button.png]
set img2 [image create photo \-file button-pressed.png]
set img3 [image create photo \-file button-active.png]
style element create Button.button image \e
    [list $img1  pressed $img2  active $img3] \e
    -border {2 4} -sticky we
    \-border {2 4} \-sticky we
.CE
.SH "SEE ALSO"
ttk::intro(n), ttk::style(n), ttk_vsapi(n), image(n), photo(n)
.SH KEYWORDS
style, theme, appearance, pixmap theme, image
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_intro.n.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23







-
+







.BS
.SH NAME
ttk::intro \- Introduction to the Tk theme engine
.BE
.SH "OVERVIEW"
.PP
The Tk themed widget set is based on a revised and enhanced version
of TIP #48 (https://tip.tcl-lang.org/48) specified style engine.
of TIP #48 (http://tip.tcl.tk/48) specified style engine.
The main concepts are described below.
The basic idea is to separate, to the extent possible,
the code implementing a widget's behavior from
the code implementing its appearance.
Widget class bindings are primarily responsible for
maintaining the widget state and invoking callbacks;
all aspects of the widget's appearance are controlled by the style of
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70







-
+







.PP
Like widgets, elements have \fIoptions\fR which
specify what to display and how to display it.
For example, the \fBtext\fR element
(which displays a text string) has
\fB\-text\fR, \fB\-font\fR, \fB\-foreground\fR, \fB\-background\fR,
\fB\-underline\fR, and \fB\-width\fR options.
The value of an element option is taken from (in precedence order):
The value of an element option is taken from:
.IP \(bu
an option of the same name and type in the widget containing the element;
.IP \(bu
a dynamic setting specified by \fBstyle map\fR and the current state;
.IP \(bu
the default setting specified by \fBstyle configure\fR; or
.IP \(bu
79
80
81
82
83
84
85
86
87
88
89




90
91
92
93
94
95
96
79
80
81
82
83
84
85




86
87
88
89
90
91
92
93
94
95
96







-
-
-
-
+
+
+
+







the side specified by the \fB\-side\fR option,
and placed within the parcel according to the \fB\-sticky\fR
option.
For example, the layout for a horizontal scrollbar is:
.PP
.CS
ttk::\fBstyle layout\fR Horizontal.TScrollbar {
    Scrollbar.trough -children {
	Scrollbar.leftarrow  -side left  -sticky w
	Scrollbar.rightarrow -side right -sticky e
	Scrollbar.thumb -sticky ew
    Scrollbar.trough \-children {
	Scrollbar.leftarrow \-side left \-sticky w
	Scrollbar.rightarrow \-side right \-sticky e
	Scrollbar.thumb \-side left \-expand true \-sticky ew
    }
}
.CE
.PP
By default, the layout for a widget is the same as its class name.
Some widgets may override this (for example, the \fBttk::scrollbar\fR
widget chooses different layouts based on the \fB\-orient\fR option).
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131







-
+







.PP
For example, the class bindings for the \fBttk::button\fR
widget are:
.PP
.CS
bind TButton <Enter>		{ %W state active }
bind TButton <Leave>		{ %W state !active }
bind TButton <Button-1>		{ %W state pressed }
bind TButton <ButtonPress-1>	{ %W state pressed }
bind TButton <Button1-Leave>	{ %W state !pressed }
bind TButton <Button1-Enter>	{ %W state pressed }
bind TButton <ButtonRelease-1>	\e
    { %W instate {pressed} { %W state !pressed ; %W invoke } }
.CE
.PP
This specifies that the widget becomes \fBactive\fR when
147
148
149
150
151
152
153
154
155
156



157
158
159
160
161
162
163
164
165
166
167
168
169
170



171
172
173
174
175
176
177
147
148
149
150
151
152
153



154
155
156
157
158
159
160
161
162
163
164
165
166
167



168
169
170
171
172
173
174
175
176
177







-
-
-
+
+
+











-
-
-
+
+
+







which specifies values for element options.
Style names use a recursive dotted notation like layouts and elements;
by default, widgets use the class name to look up a style in the current theme.
For example:
.PP
.CS
ttk::\fBstyle configure\fR TButton \e
	-background #d9d9d9 \e
	-foreground black \e
	-relief raised \e
	\-background #d9d9d9 \e
	\-foreground black \e
	\-relief raised \e
	;
.CE
.PP
Many elements are displayed differently depending on the widget state.
For example, buttons have a different background when they are active,
a different foreground when disabled, and a different relief when pressed.
The \fBstyle map\fR command specifies dynamic option settings
for a particular style:
.PP
.CS
ttk::\fBstyle map\fR TButton \e
	-background [list disabled #d9d9d9  active #ececec] \e
	-foreground [list disabled #a3a3a3] \e
	-relief [list {pressed !disabled} sunken] \e
	\-background [list disabled #d9d9d9  active #ececec] \e
	\-foreground [list disabled #a3a3a3] \e
	\-relief [list {pressed !disabled} sunken] \e
	;
.CE
.SH "SEE ALSO"
ttk::widget(n), ttk::style(n)
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_label.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


48
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20



21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36






37
38


39
40


41





















42
43
44
45
46












-
+







-
-
-
+
+
+
-













-
-
-
-
-
-


-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::label n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::label \- Display a text string and/or image
.SH SYNOPSIS
\fBttk::label\fI pathName \fR?\fIoptions\fR?
\fBttk::label\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::label\fR widget displays a textual label and/or image.
The label may be linked to a Tcl variable
to automatically change the displayed text.
.SO ttk_widget
\-anchor	\-class	\-compound
\-cursor	\-font	\-foreground
\-image	\-justify	\-padding
\-anchor	\-class	\-compound	\-cursor
\-font	\-foreground
\-image	\-justify	\-padding	\-style	\-takefocus
\-state	\-style	\-takefocus
\-text	\-textvariable	\-underline
\-width	\-wraplength
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-background frameColor FrameColor
The widget's background color.
If unspecified, the theme default is used.
.OP \-relief relief Relief
.\" Rewrite this:
Specifies the 3-D effect desired for the widget border.
Valid values are
\fBflat\fR, \fBgroove\fR, \fBraised\fR, \fBridge\fR, \fBsolid\fR,
and \fBsunken\fR.
.OP \-wraplength wrapLength WrapLength
Specifies the maximum line length (in pixels).
If this option is less than or equal to zero,
then automatic wrapping is not performed; otherwise
the text is split into lines such that no line is longer
than the specified value.
.SH "WIDGET COMMAND"
.PP
Label widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Supports the standard widget commands
\fBconfigure\fR, \fBcget\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR;
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
see \fIttk::widget(n)\fR.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::label\fP is \fBTLabel\fP.
.PP
Dynamic states: \fBdisabled\fP, \fBreadonly\fP.
.PP
\fBTLabel\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), label(n)
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_labelframe.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60






61
62




63
64
65
66


67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
31
32




33
34
35
36
37
38
39
40
41
42






43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64


65
66


67








































68
69
70
71
72
73
74












-
+







-
-
+
+










-
-
-
-










-
-
-
-
-
-








+
+
+
+
+
+


+
+
+
+


-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2005 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::labelframe n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::labelframe \- Container widget with optional label
.SH SYNOPSIS
\fBttk::labelframe\fI pathName \fR?\fIoptions\fR?
\fBttk::labelframe\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::labelframe\fR widget is a container used to group other widgets
together.  It has an optional label, which may be a plain text string or
another widget.
.SO ttk_widget
\-class	\-cursor	\-padding
\-style	\-takefocus
\-class	\-cursor	\-padding	\-style
\-takefocus
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.\" XXX: Currently included, but may go away:
.\" XXX: .OP -borderwidth borderWidth BorderWidth
.\" XXX: The desired width of the widget border.  Default is theme-dependent.
.\" XXX: .OP -relief relief Relief
.\" XXX: One of the standard Tk border styles:
.\" XXX: \fBflat\fR, \fBgroove\fR, \fBraised\fR, \fBridge\fR,
.\" XXX: \fBsolid\fR, or \fBsunken\fR.
.\" XXX: Default is theme-dependent.
.OP \-height height Height
If specified, the widget's requested height in pixels.
(See \fIttk::frame(n)\fR for further notes on \fB\-width\fR and
\fB\-height\fR).
.OP \-labelanchor labelAnchor LabelAnchor
Specifies where to place the label.
Allowed values are (clockwise from the top upper left corner):
\fBnw\fR, \fBn\fR, \fBne\fR, \fBen\fR, \fBe\fR, \fBes\fR,
\fBse\fR, \fBs\fR,\fBsw\fR, \fBws\fR, \fBw\fR and \fBwn\fR.
The default value is theme-dependent.
.\" Alternate explanation: The first character must be one of n, s, e, or w
.\" and specifies which side the label should be placed on;
.\" the remaining characters specify how the label is aligned on that side.
.\" NOTE: Now allows other values as well; leave this undocumented for now
.OP \-labelwidget labelWidget LabelWidget
The name of a widget to use for the label.
If set, overrides the \fB\-text\fR option.
The \fB\-labelwidget\fR must be a child of the \fBlabelframe\fR widget
or one of the \fBlabelframe\fR's ancestors, and must belong to the
same top-level widget as the \fBlabelframe\fR.
.OP \-text text Text
Specifies the text of the label.
.OP \-underline underline Underline
If set, specifies the integer index (0-based) of a character to
underline in the text string.
The underlined character is used for mnemonic activation.
Mnemonic activation for a \fBttk::labelframe\fR
sets the keyboard focus to the first child of the \fBttk::labelframe\fR widget.
.OP \-labelwidget labelWidget LabelWidget
The name of a widget to use for the label.
If set, overrides the \fB\-text\fR option.
The \fB\-labelwidget\fR must be a child of the \fBlabelframe\fR widget
or one of the \fBlabelframe\fR's ancestors, and must belong to the
same top-level widget as the \fBlabelframe\fR.
.OP \-width width Width
If specified, the widget's requested width in pixels.
.OP \-height height Height
If specified, the widget's requested height in pixels.
(See \fIttk::frame(n)\fR for further notes on \fB\-width\fR and
\fB\-height\fR).
.SH "WIDGET COMMAND"
.PP
Labelframe widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Supports the standard widget commands
\fBconfigure\fR, \fBcget\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR;
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
see \fIttk::widget(n)\fR.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::labelframe\fP is \fBTLabelframe\fP.
The text label
has a class of \fBTLabelframe.Label\fP.
.PP
Dynamic states: \fBdisabled\fP, \fBreadonly\fP.
.PP
\fBTLabelframe\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-borderwidth\fP \fIamount\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-labelmargins\fP \fIamount\fP
.br
\fB\-labeloutside\fP \fIboolean\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-relief\fP \fIrelief\fP
.PP
\fBTLabelframe.Label\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.br
\fB\-foreground\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::frame(n), labelframe(n)
.SH "KEYWORDS"
widget, frame, container, label, groupbox
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_menubutton.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::menubutton n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::menubutton \- Widget that pops down a menu when pressed
.SH SYNOPSIS
\fBttk::menubutton\fI pathName \fR?\fIoptions\fR?
\fBttk::menubutton\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::menubutton\fR widget displays a textual label and/or image,
and displays a menu when pressed.
.SO ttk_widget
\-class	\-compound	\-cursor
34
35
36
37
38
39
40
41
42


43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
34
35
36
37
38
39
40


41
42


43
44
45
46
47





























48
49
50
51
52
53
54







-
-
+
+
-
-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







To be on the safe side, the menu ought to be a direct child of the
menubutton.
.\" not documented: may go away:
.\" .OP \-anchor anchor Anchor
.\" .OP \-padding padding Pad
.SH "WIDGET COMMAND"
.PP
Menubutton widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Menubutton widgets support the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
methods.  No other widget methods are used.
.SH "STANDARD STYLES"
.PP
\fBTtk::menubutton\fR widgets support the \fBToolbutton\fR style in all
standard themes, which is useful for creating widgets for toolbars.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::menubutton\fP is \fBTMenubutton\fP.
.PP
Dynamic states: \fBactive\fP, \fBdisabled\fP, \fBreadonly\fP.
.PP
\fBTMenubutton\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-arrowsize\fP \fIamount\fP
.br
\fB\-background\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-relief\fP \fIrelief\fP
.br
\fB\-width\fP \fIamount\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), menu(n), menubutton(n)
.SH "KEYWORDS"
widget, button, menu
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_notebook.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17


18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45


46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63

64
65
66
67
68
69
70
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15


16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62

63
64
65
66
67
68
69
70













-
+

-
-
+
+





-
+




















-
-
+
+













-
+



-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::notebook n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::notebook \- Multi-paned container widget
.SH SYNOPSIS
.nf
\fBttk::notebook\fI pathname \fR?\fIoptions...\fR?
\fBttk::notebook\fR \fIpathname \fR?\fIoptions...\fR?
.br
\fIpathname \fBadd\fI window\fR ?\fIoptions...\fR?
\fIpathname \fBinsert\fI index window\fR ?\fIoptions...\fR?
\fIpathname \fBadd\fR \fIwindow\fR ?\fIoptions...\fR?
\fIpathname \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR?
.fi
.BE
.SH DESCRIPTION
A \fBttk::notebook\fR widget manages a collection of windows
and displays a single one at a time.
Each content window is associated with a \fItab\fR,
Each slave window is associated with a \fItab\fR,
which the user may select to change the currently-displayed window.
.SO ttk_widget
\-class	\-cursor	\-takefocus
\-style
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-height height Height
If present and greater than zero,
specifies the desired height of the pane area
(not including internal padding or tabs).
Otherwise, the maximum height of all panes is used.
.OP \-padding padding Padding
Specifies the amount of extra space to add around the outside
of the notebook.
The padding is a list of up to four length specifications
\fIleft top right bottom\fR.
If fewer than four elements are specified,
\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
In other words, a list of three numbers specify the left, vertical, and right
padding; a list of two numbers specify the horizontal and the vertical padding;
In other words, a list of three numbers specify the left, vertical, and right padding;
a list of two numbers specify the horizontal and the vertical padding;
a single number specifies the same padding all the way around the widget.
.OP \-width width Width
If present and greater than zero,
specifies the desired width of the pane area
(not including internal padding).
Otherwise, the maximum width of all panes is used.
.SH "TAB OPTIONS"
The following options may be specified for individual notebook panes:
.OP \-state state State
Either \fBnormal\fR, \fBdisabled\fR or \fBhidden\fR.
If \fBdisabled\fR, then the tab is not selectable.
If \fBhidden\fR, then the tab is not shown.
.OP \-sticky sticky Sticky
Specifies how the content window is positioned within the pane area.
Specifies how the slave window is positioned within the pane area.
Value is a string containing zero or more of the characters
\fBn, s, e,\fR or \fBw\fR.
Each letter refers to a side (north, south, east, or west)
that the content window will
that the slave window will
.QW stick
to, as per the \fBgrid\fR geometry manager.
.OP \-padding padding Padding
Specifies the amount of extra space to add between the notebook and this pane.
Syntax is the same as for the widget \fB\-padding\fR option.
.OP \-text text Text
Specifies a string to be displayed in the tab.
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122


123

124



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171



172
173
174
175
176

177
178
179
180



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103




104







105
106

107
108
109
110
111
112

113
114
115
116
117
118

119
120

121
122

123
124
125
126

127
128

129
130
131
132
133

134

135
136

137

138
139

140
141

142
143
144

145
146

147
148
149
150
151
152

153
154
155
156
157

158

159
160
161
162

163
164
165
166
167

168
169
170
171
172
173
174

175
176

177
178
179
180
181
182
183







-
+














-
-
-
-

-
-
-
-
-
-
-


-




+
+
-
+

+
+
+

-


-


-




-


-





-
+
-


-
+
-


-


-



-


-






-
+
+
+


-

-
+



-
+
+
+


-







-


-







if \fBttk::notebook::enableTraversal\fR is called.
.SH "TAB IDENTIFIERS"
The \fItabid\fR argument to the following commands may take
any of the following forms:
.IP \(bu
An integer between zero and the number of tabs;
.IP \(bu
The name of a content window;
The name of a slave window;
.IP \(bu
A positional specification of the form
.QW @\fIx\fR,\fIy\fR ,
which identifies the tab
.IP \(bu
The literal string
.QW \fBcurrent\fR ,
which identifies the currently-selected tab; or:
.IP \(bu
The literal string
.QW \fBend\fR ,
which returns the number of tabs
(only valid for
.QW "\fIpathname \fBindex\fR" ).
.PP
Indexes support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBinstate\fR,
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
notebook widgets support the following additional commands:
.\" METHOD: add
.TP
\fIpathname \fBadd \fIwindow\fR ?\fIoptions...\fR?
.
Adds a new tab to the notebook.
See \fBTAB OPTIONS\fR for the list of available \fIoptions\fR.
If \fIwindow\fR is currently managed by the notebook but hidden,
it is restored to its previous position.
.TP
\fIpathname \fBconfigure\fR ?\fIoptions\fR?
.\" METHOD: forget
See \fIttk::widget(n)\fR.
.TP
\fIpathname \fBcget \fIoption\fR
See \fIttk::widget(n)\fR.
.TP
\fIpathname \fBforget \fItabid\fR
.
Removes the tab specified by \fItabid\fR,
unmaps and unmanages the associated window.
.\" METHOD: hide
.TP
\fIpathname \fBhide \fItabid\fR
.
Hides the tab specified by \fItabid\fR.
The tab will not be displayed, but the associated window
remains managed by the notebook and its configuration remembered.
Hidden tabs may be restored with the \fBadd\fR command.
.\" METHOD: identify
.TP
\fIpathname \fBidentify\fI component x y\fR
.
Returns the name of the element under the point given by \fIx\fR and \fIy\fR,
or the empty string if no component is present at that location.
The following subcommands are supported:
.RS
.TP
\fIpathname \fBidentify element\fI x y\fR
\fIpathname \fBidentify element\fR \fIx y\fR
.
Returns the name of the element at the specified location.
.TP
\fIpathname \fBidentify tab\fI x y\fR
\fIpathname \fBidentify tab\fR \fIx y\fR
.
Returns the index of the tab at the specified location.
.RE
.\" METHOD: index
.TP
\fIpathname \fBindex \fItabid\fR
.
Returns the numeric index of the tab specified by \fItabid\fR,
or the total number of tabs if \fItabid\fR is the string
.QW \fBend\fR .
.\" METHOD: insert
.TP
\fIpathname \fBinsert \fIpos subwindow options...\fR
.
Inserts a pane at the specified position.
\fIpos\fR is either the string \fBend\fR, an integer index,
or the name of a managed subwindow.
If \fIsubwindow\fR is already managed by the notebook,
moves it to the specified position.
See \fBTAB OPTIONS\fR for the list of available options.
.\" METHOD: select
.TP
\fIpathname \fBinstate \fIstatespec \fR?\fIscript...\fR?
See \fIttk::widget(n)\fR.
.TP
\fIpathname \fBselect\fR ?\fItabid\fR?
.
Selects the specified tab.
The associated content window will be displayed,
The associated slave window will be displayed,
and the previously-selected window (if different) is unmapped.
If \fItabid\fR is omitted, returns the widget name of the
currently selected pane.
.\" METHOD: tab
.TP
\fIpathname \fBstate\fR ?\fIstatespec\fR?
See \fIttk::widget(n)\fR.
.TP
\fIpathname \fBtab \fItabid\fR ?\fI\-option \fR?\fIvalue ...\fR
.
Query or modify the options of the specific tab.
If no \fI\-option\fR is specified,
returns a dictionary of the tab option values.
If one \fI\-option\fR is specified,
returns the value of that \fIoption\fR.
Otherwise, sets the \fI\-option\fRs to the corresponding \fIvalue\fRs.
See \fBTAB OPTIONS\fR for the available options.
.\" METHOD: tabs
.TP
\fIpathname \fBtabs\fR
.
Returns the list of windows managed by the notebook, in the index order of
their associated tabs.
.SH "KEYBOARD TRAVERSAL"
To enable keyboard traversal for a toplevel window
containing a notebook widget \fI$nb\fR, call:
.CS
ttk::notebook::enableTraversal $nb
217
218
219
220
221
222
223
224
225


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
199
200
201
202
203
204
205


206
207
208
209
210



























































































211
212
213
214
215
216
217







-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







are direct children of the notebook.
.SH "VIRTUAL EVENTS"
The notebook widget generates a \fB<<NotebookTabChanged>>\fR
virtual event after a new tab is selected.
.SH "EXAMPLE"
.CS
pack [\fBttk::notebook\fR .nb]
\&.nb add [frame .nb.f1] -text "First tab"
\&.nb add [frame .nb.f2] -text "Second tab"
\&.nb add [frame .nb.f1] \-text "First tab"
\&.nb add [frame .nb.f2] \-text "Second tab"
\&.nb select .nb.f2
ttk::notebook::enableTraversal .nb
.CE
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::notebook\fP is \fBTNotebook\fP.  The tab has
a class name of \fBTNotebook.Tab\fP
.PP
Dynamic states: \fBactive\fP, \fBdisabled\fP, \fBselected\fP.
.PP
\fBTNotebook\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-tabmargins\fP \fIpadding\fP
.br
\fB\-tabposition\fP \fIposition\fP
.RS
Specifies the position of the tab row or column as a string of length
1 or 2.  The first character indicates the side as \fBn\fP, \fBs\fP,
\fBw\fP, or \fBe\fP, while the second character (if present) is the
sticky bit (specified as \fBw\fP, \fBe\fP, \fBn\fP, or \fBs\fP) within
the tab position.  The default position is \fBn\fP for the \fBaqua\fP
theme and \fBnw\fP for all the other built-in themes.
.RE
.br
.PP
\fBTNotebook.Tab\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-expand\fP \fIpadding\fP
.RS
Defines how much the tab grows in size.  Usually used with the
\fBselected\fP dynamic state.  \fB\-tabmargins\fP should be
set appropriately so that there is room for the tab growth.
For example, the Ttk library file \fBvistaTheme.tcl\fP contains
the lines
.CS
ttk::style configure TNotebook -tabmargins {2 2 2 0}
ttk::style map TNotebook.Tab -expand {selected {2 2 2 2}}
.CE
which are valid for the default value \fBnw\fP of the \fB\-tabposition\fP
style option.  For a \fBttk::notebook\fP style \fBnbStyle\fP defined by
.CS
set nbStyle SW.TNotebook
ttk::style configure $nbStyle -tabposition sw
.CE
you will have to adapt the above settings as follows:
.CS
ttk::style configure $nbStyle -tabmargins {2 0 2 2}
ttk::style map $nbStyle.Tab -expand {selected {2 2 2 2}}
.CE
.RE
\fB\-font\fP \fIfont\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.RS
Some themes (e.g., \fBclam\fP) use a different \fIpadding\fP for the
selected tab.  For example, the Ttk library file \fBclamTheme.tcl\fP
contains the lines
.CS
ttk::style configure TNotebook.Tab \\
    -padding {4.5p 1.5p 4.5p 1.5p}
ttk::style map TNotebook.Tab \\
    -padding {selected {4.5p 3p 4.5p 1.5p}}
.CE
which are valid for the default value \fBnw\fP of the \fB\-tabposition\fP
style option.  Again, for a different tab position you will have to adapt
the above settings accordingly.
.RE
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), grid(n)
.SH "KEYWORDS"
pane, tab
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_panedwindow.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17


18
19
20
21
22
23
24
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15


16
17
18
19
20
21
22
23
24













-
+

-
-
+
+







'\"
'\" Copyright (c) 2005 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::panedwindow n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::panedwindow \- Multi-pane container window
.SH SYNOPSIS
.nf
\fBttk::panedwindow\fI pathname \fR?\fIoptions\fR?
\fBttk::panedwindow\fR \fIpathname \fR?\fIoptions\fR?
.br
\fIpathname \fBadd\fI window\fR ?\fIoptions...\fR?
\fIpathname \fBinsert\fI index window\fR ?\fIoptions...\fR?
\fIpathname \fBadd\fR \fIwindow\fR ?\fIoptions...\fR?
\fIpathname \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR?
.fi
.BE
.SH DESCRIPTION
A \fBttk::panedwindow\fR widget displays a number of subwindows,
stacked either vertically or horizontally.
The user may adjust the relative sizes of the subwindows
by dragging the sash between panes.
44
45
46
47
48
49
50
51
52
53
54


55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132


133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
44
45
46
47
48
49
50




51
52


53

54
55

56
57

58
59

60
61

62
63

64
65
66
67
68
69
70

71
72
73

74
75

76
77

78
79
80
81
82
83

84
85

86
87
88
89
90
91

92
93

94
95

96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111


112
113


114
































115
116
117
118
119







-
-
-
-
+
+
-
-
+
-


-


-


-


-


-







-



-


-


-






-


-






-


-


-


-














-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





.SH "PANE OPTIONS"
The following options may be specified for each pane:
.OP \-weight weight Weight
An integer specifying the relative stretchability of the pane.
When the paned window is resized, the extra space is added
or subtracted to each pane proportionally to its \fB\-weight\fR.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBinstate\fR,
\fBstate\fR and \fBstyle\fR
Supports the standard \fBconfigure\fR, \fBcget\fR, \fBstate\fR,
and \fBinstate\fR commands; see \fIttk::widget(n)\fR for details.
commands (see \fBttk::widget\fR),
panedwindow widgets support the following additional commands:
Additional commands:
.\" METHOD: add
.TP
\fIpathname \fBadd \fIsubwindow options...\fR
.
Adds a new pane to the window.
See \fBPANE OPTIONS\fR for the list of available options.
.\" METHOD: forget
.TP
\fIpathname \fBforget \fIpane\fR
.
Removes the specified subpane from the widget.
\fIpane\fR is either an integer index or the name of a managed subwindow.
.\" METHOD: identify
.TP
\fIpathname \fBidentify \fIcomponent x y\fR
.
Returns the name of the element under the point given by \fIx\fR and \fIy\fR,
or the empty string if no component is present at that location.
If \fIcomponent\fR is omitted, it defaults to \fBsash\fR.
The following subcommands are supported:
.RS
.TP
\fIpathname \fBidentify element \fIx y\fR
.
Returns the name of the element at the specified location.
.TP
\fIpathname \fBidentify sash \fIx y\fR
.
Returns the index of the sash at the specified location.
.RE
.\" METHOD: insert
.TP
\fIpathname \fBinsert \fIpos subwindow options...\fR
.
Inserts a pane at the specified position.
\fIpos\fR is either the string \fBend\fR, an integer index,
or the name of a managed subwindow.
If \fIsubwindow\fR is already managed by the paned window,
moves it to the specified position.
See \fBPANE OPTIONS\fR for the list of available options.
.\" METHOD: pane
.TP
\fIpathname \fBpane \fIpane \-option \fR?\fIvalue \fR?\fI\-option value...\fR
.
Query or modify the options of the specified \fIpane\fR,
where \fIpane\fR is either an integer index or the name of a managed subwindow.
If no \fI\-option\fR is specified, returns a dictionary of the pane
option values.
If one \fI\-option\fR is specified, returns the value of that \fIoption\fR.
Otherwise, sets the \fI\-option\fRs to the corresponding \fIvalue\fRs.
.\" METHOD: panes
.TP
\fIpathname \fBpanes\fR
.
Returns the list of all windows managed by the widget, in the index order of
their associated panes.
.\" METHOD: sashpos
.TP
\fIpathname \fBsashpos \fIindex\fR ?\fInewpos\fR?
.
If \fInewpos\fR is specified, sets the position
of sash number \fIindex\fR.
May adjust the positions of adjacent sashes
to ensure that positions are monotonically increasing.
Sash positions are further constrained to be between 0
and the total size of the widget.
.\" Full story: "total size" is either the -height (resp -width),
.\" or the actual window height (resp actual window width),
.\" depending on which changed most recently.
Returns the new position of sash number \fIindex\fR.
.\" Full story: new position may be different than the requested position.
.SH "VIRTUAL EVENTS"
.PP
The panedwindow widget generates an \fB<<EnteredChild>>\fR virtual event on
LeaveNotify/NotifyInferior events.
.SH "STYLING OPTIONS"
LeaveNotify/NotifyInferior events, because Tk does not execute binding scripts
for <Leave> events when the pointer crosses from a parent to a child. The
.PP
The class name for a \fBttk::panedwindow\fP is \fBTPanedwindow\fP.  The
panedwindow widget needs to know when that happens.
sash has a class name of \fBSash\fP.
.PP
\fBTPanedwindow\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.PP
\fBSash\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-gripsize\fP \fIsize\fP (number of screen units)
.br
\fB\-handlepad\fP \fIamount\fP
.br
\fB\-handlesize\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-sashpad\fP \fIamount\fP
.br
\fB\-sashrelief\fP \fIrelief\fP
.br
\fB\-sashthickness\fP \fIamount\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::notebook(n), panedwindow(n)
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_progressbar.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23

24
25
26


27
28
29
30
31
32
33
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22

23
24


25
26
27
28
29
30
31
32
33












-
+









-
+

-
-
+
+







'\"
'\" Copyright (c) 2005 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::progressbar n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::progressbar \- Provide progress feedback
.SH SYNOPSIS
\fBttk::progressbar\fI pathName \fR?\fIoptions\fR?
\fBttk::progressbar\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::progressbar\fR widget shows the status of a long-running
operation.  They can operate in two modes: \fIdeterminate\fR mode shows the
amount completed relative to the total amount of work to be done, and
\fIindeterminate\fR mode provides an animated display to let the user know
that something is happening.
.PP
If the value of \fB\-orient\fR is \fBhorizontal\fR a text string can be
If the value of \fB-orient\fR is \fBhorizontal\fR a text string can be
displayed inside the progressbar. This string can be configured using
the \fB\-anchor\fR, \fB\-font\fR, \fB\-foreground\fR, \fB\-justify\fR,
\fB\-text\fR and \fB\-wraplength\fR options. If the value of \fB\-orient\fR
the \fB-anchor\fR, \fB-font\fR, \fB-foreground\fR, \fB-justify\fR,
\fB-text\fR and \fB-wraplength\fR options. If the value of \fB-orient\fR
is \fBvertical\fR then these options are ignored.
.SO ttk_widget
\-anchor	\-class	\-cursor
\-font	\-foreground	\-justify	\-style
\-takefocus	\-text	\-wraplength
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68

69
70
71
72









73
74



75
76
77
78
79
80
81
82



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
53
54
55
56
57
58
59


60
61

62
63
64
65
66
67




68
69
70
71
72
73
74
75
76


77
78
79
80
81

82
83
84
85

86
87
88
89
90

91
92

93
94

95
96





























97
98
99
100
101







-
-


-
+




+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+


-




-
+
+
+


-


-


-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





.OP \-value value Value
The current value of the progress bar.
In \fIdeterminate\fR mode, this represents the amount of work completed.
In \fIindeterminate\fR mode, it is interpreted modulo \fB\-maximum\fR;
that is, the progress bar completes one
.QW cycle
when the \fB\-value\fR increases by \fB\-maximum\fR.
If \fB\-variable\fR is set to an existing variable, specifying \fB\-value\fR
has no effect (the variable value takes precedence).
.OP \-variable variable Variable
The name of a global Tcl variable which is linked to the \fB\-value\fR.
If specified to an existing variable, the \fB\-value\fR of the progress bar is
If specified, the \fB\-value\fR of the progress bar is
automatically set to the value of the variable whenever
the latter is modified.
.SH "WIDGET COMMAND"
.PP
.TP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
\fIpathName \fBcget \fIoption\fR
Returns the current value of the specified \fIoption\fR; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
Modify or query widget options; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBidentify \fIx y\fR
Returns the name of the element at position \fIx\fR, \fIy\fR.
See \fIttk::widget(n)\fR.
progressbar widgets support the following additional commands:
.\" METHOD: start
.TP
\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR?
Test the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBstart\fR ?\fIinterval\fR?
.
Begin autoincrement mode:
schedules a recurring timer event that calls \fBstep\fR
every \fIinterval\fR milliseconds.
If omitted, \fIinterval\fR defaults to 50 milliseconds (20 steps/second).
.\" METHOD: step
.TP
\fIpathName \fBstate\fR ?\fIstateSpec\fR?
Modify or query the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBstep\fR ?\fIamount\fR?
.
Increments the \fB\-value\fR by \fIamount\fR.
\fIamount\fR defaults to 1.0 if omitted.
.\" METHOD: stop
.TP
\fIpathName \fBstop\fR
.
Stop autoincrement mode:
cancels any recurring timer event initiated by \fIpathName \fBstart\fR.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::progressbar\fP is \fBTProgressbar\fP.
.PP
\fBTProgressbar\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-maxphase\fP
.RS
For the aqua theme.
.RE
\fB\-period\fP
.RS
For the aqua theme.
.RE
\fB\-troughcolor\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n)
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_radiobutton.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::radiobutton n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::radiobutton \- Mutually exclusive option widget
.SH SYNOPSIS
\fBttk::radiobutton\fI pathName \fR?\fIoptions\fR?
\fBttk::radiobutton\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
\fBttk::radiobutton\fR widgets are used in groups to show or change
a set of mutually-exclusive options.
Radiobuttons are linked to a Tcl variable,
and have an associated value; when a radiobutton is clicked,
33
34
35
36
37
38
39
40

41
42
43

44

45
46
47
48
49
50
51
52
53
54
33
34
35
36
37
38
39

40



41

42
43
44

45
46
47
48
49
50
51







-
+
-
-
-
+
-
+


-







when the widget is selected.
.OP \-variable variable Variable
The name of a global variable whose value is linked to the widget.
Default value is \fB::selectedButton\fR.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
radiobutton widgets support the following additional commands:
commands, radiobuttons support the following additional
.\" METHOD: invoke
widget commands:
.TP
\fIpathname\fB invoke\fR
.
Sets the \fB\-variable\fR to the \fB\-value\fR, selects the widget,
and evaluates the associated \fB\-command\fR.
Returns the result of the \fB\-command\fR, or the empty
string if no \fB\-command\fR is specified.
.\" Missing: select, deselect.  Useful?
.\" Missing: flash.  This is definitely not useful.
.SH "WIDGET STATES"
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
61
62
63
64
65
66
67






























68
69
70
71
72
73
74







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







or
.QW indeterminate
selection.)
.SH "STANDARD STYLES"
.PP
\fBTtk::radiobutton\fR widgets support the \fBToolbutton\fR style in all
standard themes, which is useful for creating widgets for toolbars.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::radiobutton\fP is \fBTRadiobutton\fP.
.PP
Dynamic states: \fBactive\fP, \fBalternate\fP, \fBdisabled\fP,
\fBpressed\fP, \fBreadonly\fP, \fBselected\fP.
.PP
\fBTRadiobutton\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-compound\fP \fIcompound\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-indicatorbackground\fP \fIcolor\fP
.br
\fB\-indicatorcolor\fP \fIcolor\fP
.br
\fB\-indicatormargin\fP \fIpadding\fP
.br
\fB\-indicatorrelief\fP \fIrelief\fP
.br
\fB\-padding\fP \fIpadding\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::checkbutton(n), radiobutton(n)
.SH "KEYWORDS"
widget, button, option
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_scale.n.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54

55
56
57



58
59




60
61
62
63
64
65







66

67
68
69
70
71
72
73




74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52

53



54
55
56


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93





























94
95
96
97
98
99
100







-
-







+
-
+
-
-
-
+
+
+
-
-
+
+
+
+






+
+
+
+
+
+
+
-
+







+
+
+
+


-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







or vertically. Must be either \fBhorizontal\fR or \fBvertical\fR or an
abbreviation of one of these.
.OP \-to to To
Specifies a real value corresponding to the right or bottom end of the scale.
This value may be either less than or greater than the \fB\-from\fR option.
.OP \-value value Value
Specifies the current floating-point value of the variable.
If \fB\-variable\fR is set to an existing variable, specifying \fB\-value\fR
has no effect (the variable value takes precedence).
.OP \-variable variable Variable
Specifies the name of a global variable to link to the scale. Whenever the
value of the variable changes, the scale will update to reflect this value.
Whenever the scale is manipulated interactively, the variable will be modified
to reflect the scale's new value.
.SH "WIDGET COMMAND"
.PP
.TP
In addition to the standard
\fIpathName \fBcget \fIoption\fR
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
.
Returns the current value of the specified \fIoption\fR; see
\fIttk::widget(n)\fR.
scale widgets support the following additional commands:
.\" METHOD: get
.TP
\fIpathName \fBconfigure \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Modify or query widget options; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBget \fR?\fIx y\fR?
.
Get the current value of the \fB\-value\fR option, or the value corresponding
to the coordinates \fIx,y\fR if they are specified. \fIX\fR and \fIy\fR are
pixel coordinates relative to the scale widget origin.
.TP
\fIpathName \fBidentify \fIx y\fR
Returns the name of the element at position \fIx\fR, \fIy\fR.
See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR?
.
.\" METHOD: see
Test the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBset \fIvalue\fR
.
Set the value of the widget (i.e. the \fB\-value\fR option) to \fIvalue\fR.
The value will be clipped to the range given by the \fB\-from\fR and
\fB\-to\fR options. Note that setting the linked variable (i.e. the variable
named in the \fB\-variable\fR option) does not cause such clipping.
.TP
\fIpathName \fBstate\fR ?\fIstateSpec\fR?
.
Modify or query the widget state; see \fIttk::widget(n)\fR.
.SH "INTERNAL COMMANDS"
.PP
.\" METHOD: coords
.TP
\fIpathName \fBcoords \fR?\fIvalue\fR?
.
Get the coordinates corresponding to \fIvalue\fR, or the coordinates
corresponding to the current value of the \fB\-value\fR option if \fIvalue\fR
is omitted.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::scale\fP is \fBTScale\fP.
.PP
Dynamic states: \fBactive\fP.
.PP
\fBTScale\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-borderwidth\fP \fIamount\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-groovewidth\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-sliderwidth\fP \fIamount\fP
.br
\fB\-troughcolor\fP \fIcolor\fP
.br
\fB\-troughrelief\fP \fIrelief\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), scale(n)
.SH KEYWORDS
scale, slider, trough, widget
.\" Local Variables:
.\" mode: nroff
.\" fill-column: 78

Changes to doc/ttk_scrollbar.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







'\"
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::scrollbar n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::scrollbar \- Control the viewport of a scrollable widget
.SH SYNOPSIS
\fBttk::scrollbar\fI pathName \fR?\fIoptions...\fR?
\fBttk::scrollbar\fR \fIpathName \fR?\fIoptions...\fR?
.BE
.SH DESCRIPTION
.PP
\fBttk::scrollbar\fR widgets are typically linked to an associated window
that displays a document of some sort, such as a file being edited or a
drawing.
A scrollbar displays a \fIthumb\fR in the middle portion of the scrollbar,
43
44
45
46
47
48
49

50
51




52
53

54
55
56
57
58
59
60
61




62



63
64
65
66
67
68



69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120









121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155








156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
43
44
45
46
47
48
49
50


51
52
53
54


55


56
57

58
59

60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78

79

80
81

82
83
84
85
86
87
88
89
90

91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136









137
138
139
140
141
142
143
144
145
146
147








148
149
150
151
152
153
154
155

156
































157
158
159
160
161
162
163







+
-
-
+
+
+
+
-
-
+
-
-


-


-
+
+
+
+

+
+
+

-




+
+
+



-
+
-


-









-


-




















-








-
-
+
+
+
+
+
+
+
+
+







-
-
-
-
-
-
-
-
-











-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







or \fByview\fR (for vertical scrollbars).
.RE
.OP \-orient orient Orient
One of \fBhorizontal\fR or \fBvertical\fR.
Specifies the orientation of the scrollbar.
.SH "WIDGET COMMAND"
.PP
.TP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
\fIpathName \fBcget \fIoption\fR
Returns the current value of the specified \fIoption\fR; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
\fBstate\fR and \fBstyle\fR
commands (see \fBttk::widget\fR),
Modify or query widget options; see \fIttk::widget(n)\fR.
scrollbar widgets support the following additional commands:
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
Returns the scrollbar settings in the form of a list whose
elements are the arguments to the most recent \fBset\fR widget command.
.\" METHOD: set
.TP
\fIpathName \fBidentify \fIx y\fR
Returns the name of the element at position \fIx\fR, \fIy\fR.
See \fIttk::widget(n)\fR.
.TP
\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR?
Test the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBset \fIfirst last\fR
.
This command is normally invoked by the scrollbar's associated widget
from an \fB\-xscrollcommand\fR or \fB\-yscrollcommand\fR callback.
Specifies the visible range to be displayed.
\fIfirst\fR and \fIlast\fR are real fractions between 0 and 1.
.TP
\fIpathName \fBstate\fR ?\fIstateSpec\fR?
Modify or query the widget state; see \fIttk::widget(n)\fR.
.SH "INTERNAL COMMANDS"
.PP
The following widget commands are used internally
by the \fBTScrollbar\fP widget class bindings.
by the TScrollbar widget class bindings.
.\" METHOD: delta
.TP
\fIpathName \fBdelta \fIdeltaX deltaY\fR
.
Returns a real number indicating the fractional change in
the scrollbar setting that corresponds to a given change
in thumb position.  For example, if the scrollbar is horizontal,
the result indicates how much the scrollbar setting must change
to move the thumb \fIdeltaX\fR pixels to the right (\fIdeltaY\fR is
ignored in this case).
If the scrollbar is vertical, the result indicates how much the
scrollbar setting must change to move the thumb \fIdeltaY\fR pixels
down.  The arguments and the result may be zero or negative.
.\" METHOD: fraction
.TP
\fIpathName \fBfraction \fIx y\fR
.
Returns a real number between 0 and 1 indicating where the point
given by \fIx\fR and \fIy\fR lies in the trough area of the scrollbar,
where 0.0 corresponds to the top or left of the trough
and 1.0 corresponds to the bottom or right.
\fIX\fR and \fIy\fR are pixel coordinates relative to the scrollbar
widget.
If \fIx\fR and \fIy\fR refer to a point outside the trough, the closest
point in the trough is used.
.SH "SCROLLING COMMANDS"
.PP
When the user interacts with the scrollbar, for example by dragging
the thumb, the scrollbar notifies the associated widget that it
must change its view.
The scrollbar makes the notification by evaluating a Tcl command
generated from the scrollbar's \fB\-command\fR option.
The command may take any of the following forms.
In each case, \fIprefix\fR is the contents of the
\fB\-command\fR option, which usually has a form like \fB.t yview\fR
.TP
\fIprefix \fBmoveto \fIfraction\fR
.
\fIFraction\fR is a real number between 0 and 1.
The widget should adjust its view so that the point given
by \fIfraction\fR appears at the beginning of the widget.
If \fIfraction\fR is 0 it refers to the beginning of the
document.  1.0 refers to the end of the document, 0.333
refers to a point one-third of the way through the document,
and so on.
.TP
\fIprefix \fBscroll \fInumber \fBpages\fR
.
\fIprefix \fBscroll \fInumber \fBunits\fR
The widget should adjust its view by \fInumber\fR units.
The units are defined in whatever way makes sense for the widget,
such as characters or lines in a text widget.
\fINumber\fR is either 1, which means one unit should scroll off
the top or left of the window, or \-1, which means that one unit
should scroll off the bottom or right of the window.
.TP
\fIprefix \fBscroll \fInumber \fBpages\fR
The widget should adjust its view by \fInumber\fR pages.
It is up to the widget to define the meaning of a page;  typically
it is slightly less than what fits in the window, so that there
is a slight overlap between the old and new views.
\fINumber\fR is either 1, which means the next page should
become visible, or \-1, which means that the previous page should
become visible.
.TP
\fIprefix \fBscroll \fInumber \fBunits\fR
.
The widget should adjust its view by \fInumber\fR units.
The units are defined in whatever way makes sense for the widget,
such as characters or lines in a text widget.
\fINumber\fR is either 1, which means one unit should scroll off
the top or left of the window, or \-1, which means that one unit
should scroll off the bottom or right of the window.
.SH "WIDGET STATES"
.PP
The scrollbar automatically sets the \fBdisabled\fR state bit.
when the entire range is visible (range is 0.0 to 1.0),
and clears it otherwise.
It also sets the \fBactive\fR and \fBpressed\fR state flags
of individual elements, based on the position and state of the mouse pointer.
.SH EXAMPLE
.PP
.CS
set f [frame .f]
\fBttk::scrollbar\fR $f.hsb -orient horizontal -command [list $f.t xview]
\fBttk::scrollbar\fR $f.vsb -orient vertical -command [list $f.t yview]
text $f.t -xscrollcommand [list $f.hsb set] -yscrollcommand [list $f.vsb set]
grid $f.t -row 0 -column 0 -sticky nsew
grid $f.vsb -row 0 -column 1 -sticky nsew
grid $f.hsb -row 1 -column 0 -sticky nsew
grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1
ttk::scrollbar $f.hsb \-orient horizontal \-command [list $f.t xview]
ttk::scrollbar $f.vsb \-orient vertical \-command [list $f.t yview]
text $f.t \-xscrollcommand [list $f.hsb set] \-yscrollcommand [list $f.vsb set]
grid $f.t \-row 0 \-column 0 \-sticky nsew
grid $f.vsb \-row 0 \-column 1 \-sticky nsew
grid $f.hsb \-row 1 \-column 0 \-sticky nsew
grid columnconfigure $f 0 \-weight 1
grid rowconfigure $f 0 \-weight 1
pack $f
.CE
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::scrollbar\fP is \fBTScrollbar\fP.
.PP
Dynamic states: \fBactive\fP, \fBdisabled\fP.
.PP
\fBTScrollbar\fP (or more specifically \fBVertical.TScrollbar\fP and
\fBHorizontal.TScrollbar\fP) styling options that are configurable with
\fBttk::style\fP are:
.PP
\fB\-arrowcolor\fP \fIcolor\fP
.br
\fB\-arrowsize\fP \fIamount\fP
.br
\fB\-background\fP \fIcolor\fP
.br
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP (color of the dark part of the 3D relief)
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-gripsize\fP \fIsize\fP (number of screen units)
.br
\fB\-lightcolor\fP \fIcolor\fP (color of the light part of the 3D relief)
.br
\fB\-troughcolor\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), scrollbar(n)
.SH KEYWORDS
scrollbar, widget
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_separator.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30


31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28


29
30


31














32
33
34
35
36
37
38












-
+






-
+








-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::separator n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::separator \- Separator bar
.SH SYNOPSIS
\fBttk::separator\fI pathName \fR?\fIoptions\fR?
\fBttk::separator\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::separator\fR widget displays a horizontal or vertical separator
bar.
.SO ttk_widget
\-class	\-cursor
\-class	\-cursor	\-state
\-style	\-takefocus
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-orient orient Orient
One of \fBhorizontal\fR or \fBvertical\fR.
Specifies the orientation of the separator.
.SH "WIDGET COMMAND"
.PP
Separator widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Separator widgets support the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
methods.  No other widget methods are used.
.PP
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::separator\fP is \fBTSeparator\fP.
.PP
\fBTSeparator\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n)
.SH "KEYWORDS"
widget, separator
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_sizegrip.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21

22
23
24
25
26
27


28
29

30
31
32
33
34
35
36
37
38
39
40
41


42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20

21
22
23
24
25


26
27


28
29
30
31
32
33
34
35
36
37
38


39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62













63
64
65
66
67
68
69












-
+







-
+




-
-
+
+
-
-
+










-
-
+
+





-
+
















-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2006 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::sizegrip n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::sizegrip \- Bottom-right corner resize widget
.SH SYNOPSIS
\fBttk::sizegrip\fI pathName \fR?\fIoptions\fR?
\fBttk::sizegrip\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::sizegrip\fR widget (also known as a \fIgrow box\fR)
allows the user to resize the containing toplevel window
by pressing and dragging the grip.
.SO ttk_widget
\-class	\-cursor
\-class	\-cursor	\-state
\-style	\-takefocus
.SE
.SH "WIDGET COMMAND"
.PP
Sizegrip widgets support the standard commands
\fBcget\fR, \fBconfigure\fR, \fBidentify element\fR, \fBinstate\fR,
Sizegrip widgets support the standard
\fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR
\fBstate\fR and \fBstyle\fR
(see \fBttk::widget\fR).
methods.  No other widget methods are used.
.SH "PLATFORM-SPECIFIC NOTES"
.PP
On Mac OSX, toplevel windows automatically include a built-in
size grip by default.
Adding a \fBttk::sizegrip\fR there is harmless, since
the built-in grip will just mask the widget.
.SH EXAMPLES
.PP
Using pack:
.CS
pack [ttk::frame $top.statusbar] -side bottom -fill x
pack [\fBttk::sizegrip\fR $top.statusbar.grip] -side right -anchor se
pack [ttk::frame $top.statusbar] \-side bottom \-fill x
pack [\fBttk::sizegrip\fR $top.statusbar.grip] \-side right \-anchor se
.CE
.PP
Using grid:
.CS
grid [\fBttk::sizegrip\fR $top.statusbar.grip] \e
    -row $lastRow -column $lastColumn -sticky se
    \-row $lastRow \-column $lastColumn \-sticky se
# ... optional: add vertical scrollbar in $lastColumn,
# ... optional: add horizontal scrollbar in $lastRow
.CE
.SH "BUGS"
.PP
If the containing toplevel's position was specified
relative to the right or bottom of the screen
(e.g.,
.QW "\fBwm geometry ... \fIw\fBx\fIh\fB\-\fIx\fB\-\fIy\fR"
instead of
.QW "\fBwm geometry ... \fIw\fBx\fIh\fB+\fIx\fB+\fIy\fR" ),
the sizegrip widget will not resize the window.
.PP
\fBttk::sizegrip\fR widgets only support
.QW southeast
resizing.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::sizegrip\fP is \fBTSizegrip\fP.
.PP
\fBTSizegrip\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n)
.SH "KEYWORDS"
widget, sizegrip, grow box
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_spinbox.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48

49
50




51
52
53
54
55
56
57
58







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23


24
25

26
27
28
29
30







31

32
33
34




35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

69


70
71
72
73

74
75

76
77
78
79
80
81
82
83
84













































85
86
87
88
89
90
91












-
+










-
-
+
+
-





-
-
-
-
-
-
-

-
+


-
-
-
-

-
+


+
+
+
+








+
+
+
+
+
+
+











-

-
-
+
+
+

-


-









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2008 Pat Thoyts
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::spinbox n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::spinbox \- Selecting text field widget
.SH SYNOPSIS
\fBttk::spinbox\fI pathName \fR?\fIoptions\fR?
\fBttk::spinbox\fR \fIpathName \fR?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
A \fBttk::spinbox\fR widget is a \fBttk::entry\fR widget with built-in
up and down buttons that are used to either modify a numeric value or
to select among a set of values. The widget implements all the features
of the \fBttk::entry\fR widget including support of the
\fB\-textvariable\fR option to link the value displayed by the widget
to a Tcl variable.
.SO ttk_widget
\-class	\-cursor	\-state
\-style	\-takefocus	\-xscrollcommand
\-class	\-cursor	\-style
\-takefocus	\-xscrollcommand
\-placeholder	\-placeholderforeground
.SE
.SO ttk_entry
\-validate	\-validatecommand
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.OP \-command command Command
Specifies a Tcl command to be invoked whenever a spinbutton is invoked.
.OP \-format format Format
Specifies an alternate format to use when setting the string value
when using the \fB\-from\fR and \fB\-to\fR range.
This must be a format specifier of the form \fB%<pad>.<pad>f\fR,
as it will format a floating-point number.
.OP \-from from From
A floating-point value specifying the lowest value for the spinbox. This is
A floating\-point value specifying the lowest value for the spinbox. This is
used in conjunction with \fB\-to\fR and \fB\-increment\fR to set a numerical
range.
.OP \-increment increment Increment
A floating-point value specifying the change in value to be applied each
time one of the widget spin buttons is pressed. The up button applies a
positive increment, the down button applies a negative increment.
.OP \-to to To
A floating-point value specifying the highest permissible value for the
A floating\-point value specifying the highest permissible value for the
widget. See also \fB\-from\fR and \fB\-increment\fR.
range.
.OP \-increment increment Increment
A floating\-point value specifying the change in value to be applied each
time one of the widget spin buttons is pressed. The up button applies a
positive increment, the down button applies a negative increment.
.OP \-values values Values
This must be a Tcl list of values. If this option is set then this will
override any range set using the \fB\-from\fR, \fB\-to\fR and
\fB\-increment\fR options. The widget will instead use the values
specified beginning with the first value.
.OP \-wrap wrap Wrap
Must be a proper boolean value.  If on, the spinbox will wrap around the
values of data in the widget.
.OP \-format format Format
Specifies an alternate format to use when setting the string value
when using the \fB\-from\fR and \fB\-to\fR range.
This must be a format specifier of the form \fB%<pad>.<pad>f\fR,
as it will format a floating-point number.
.OP \-command command Command
Specifies a Tcl command to be invoked whenever a spinbutton is invoked.
.SH "INDICES"
.PP
See the \fBttk::entry\fR manual for information about indexing characters.
.SH "VALIDATION"
.PP
See the \fBttk::entry\fR manual for information about using the
\fB\-validate\fR and \fB\-validatecommand\fR options.
.SH "WIDGET COMMAND"
.PP
The following subcommands are possible for spinbox widgets in addition to
the commands described for the \fBttk::entry\fR widget:
.\" METHOD: get
.TP
\fIpathName \fBget\fR
.
\fIpathName \fBcurrent \fIindex\fR
.TP
\fIpathName \fBget\fR
Returns the spinbox's current value.
.\" METHOD: set
.TP
\fIpathName \fBset \fIvalue\fR
.
Set the spinbox string to \fIvalue\fR. If a \fB\-format\fR option has
been configured then this format will be applied. If formatting fails
or is not set or the \fB\-values\fR option has been used then the value
is set directly.
.SH "VIRTUAL EVENTS"
.PP
The spinbox widget generates a \fB<<Increment>>\fR virtual event when
the user presses <Up>, and a \fB<<Decrement>>\fR virtual event when the
user presses <Down>.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::spinbox\fP is \fBTSpinbox\fP.
.PP
Dynamic states: \fBactive\fP, \fBdisabled\fP, \fBfocus\fP, \fBreadonly\fP.
.PP
\fBTSpinbox\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-arrowcolor\fP \fIcolor\fP
.br
\fB\-arrowsize\fP \fIamount\fP
.br
\fB\-background\fP \fIcolor\fP
.RS
For backwards compatibility, when using the aqua theme (for macOS), this
option behaves as an alias for the \fB\-fieldbackground\fP provided that no
value is specified for \fB\-fieldbackground\fP. Otherwise it is ignored.
.RE
\fB\-bordercolor\fP \fIcolor\fP
.br
\fB\-darkcolor\fP \fIcolor\fP
.br
\fB\-fieldbackground\fP \fIcolor\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-insertcolor\fP \fIcolor\fP
.br
\fB\-insertwidth\fP \fIamount\fP
.br
\fB\-lightcolor\fP \fIcolor\fP
.br
\fB\-padding\fP \fIpadding\fP
.br
\fB\-placeholderforeground\fP \fIcolor\fP
.br
\fB\-selectbackground\fP \fIcolor\fP
.br
\fB\-selectforeground\fP \fIcolor\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), ttk::entry(n), spinbox(n)
.SH KEYWORDS
entry, spinbox, widget, text field
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_style.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72

73
74
75

76

77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100

101
102
103











104
105
106





107
108

109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127

128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182

183
184
185


186
187
188


189
190
191
192
193
194
195
196




197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29



30
31
32

33
34

35






36

37






















38


39



40

41
42

43

44
45
46
47
48
49
50
51
52


53







54


55



56
57
58
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73

74

75
76
77
78
79
80





81

82
83
84
85
86

87


88

89
90

91
92
93

94
95
96
97
98
99
100


101






102












103

104
105




106


107
108




109



110
111



112
113
114
115
116
117




118
119
120
121
122
123
124



























125
126
127
128
129
130
131












-
+




-
+











-
-
-



-


-

-
-
-
-
-
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
-
+

-
+
-









-
-

-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+

-
+
-






-
-
-
-
-
+
-





-
+
-
-
+
-


-



-







-
-

-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-

-


-
-
-
-
+
-
-


-
-
-
-
+
-
-
-
+
+
-
-
-
+
+




-
-
-
-
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







'\"
'\" Copyright (c) 2004 Joe English
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk::style n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk::style \- Manipulate style database
.SH SYNOPSIS
\fBttk::style\fI option\fR ?\fIargs\fR?
\fBttk::style\fR \fIoption\fR ?\fIargs\fR?
.BE
.SH NOTES
.PP
See also the Tcl'2004 conference presentation,
available at https://tktable.sourceforge.net/tile/tile-tcl2004.pdf
available at http://tktable.sourceforge.net/tile/tile-tcl2004.pdf
.SH DEFINITIONS
.PP
Each widget is assigned a \fIstyle\fR,
which specifies the set of elements making up the widget
and how they are arranged, along with dynamic and default
settings for element options.
By default, the style name is the same as the widget's class;
this may be overridden by the \fB\-style\fR option.
.PP
A \fItheme\fR is a collection of elements and styles
which controls the overall look and feel of an application.
The
.QW .
style is the theme root style on which derived styles are based.
.SH DESCRIPTION
.PP
The \fBttk::style\fR command takes the following arguments:
.\" METHOD: configure
.TP
\fBttk::style configure \fIstyle\fR ?\fI\-option\fR ?\fIvalue option value...\fR? ?
.
Sets the default value of the specified option(s) in \fIstyle\fR.
If \fIstyle\fR does not exist, it is created.
If only \fIstyle\fR and \fI\-option\fR are specified, get the default value
for option \fI\-option\fR of style \fIstyle\fR.
If only \fIstyle\fR is specified, get the default value for all options
of style \fIstyle\fR.
.\" METHOD: element
.TP
\fBttk::style element\fI args\fR
\fBttk::style map \fIstyle\fR ?\fI\-option\fB { \fIstatespec value...\fB }\fR?
.RS
.TP
\fBttk::style element create\fI elementName type\fR ?\fIargs...\fR?
.
Creates a new element in the current theme of type \fItype\fR.
The only cross-platform built-in element type is \fIimage\fR
(see \fBttk_image\fR(n)) but themes may define other element types
(see \fBTtk_RegisterElementFactory\fR). On suitable versions of Windows
an element factory is registered to create Windows theme elements
(see \fBttk_vsapi\fR(n)).
.TP
\fBttk::style element names\fR
.
Returns the list of elements defined in the current theme.
.TP
\fBttk::style element options \fIelement\fR
.
Returns the list of \fIelement\fR's options.
.RE
.\" METHOD: layout
.TP
\fBttk::style layout \fIstyle\fR ?\fIlayoutSpec\fR?
Sets dynamic values of the specified option(s) in \fIstyle\fR.
.
Define the widget layout for style \fIstyle\fR.
Each \fIstatespec / value\fR pair is examined in order;
See \fBLAYOUTS\fR below for the format of \fIlayoutSpec\fR.
If \fIlayoutSpec\fR is omitted, return the layout specification
for style \fIstyle\fR.
the value corresponding to the first matching \fIstatespec\fR
.\" METHOD: lookup
is used.
.TP
\fBttk::style lookup \fIstyle \-option \fR?\fIstate \fR?\fIdefault\fR??
\fBttk::style lookup \fIstyle\fR \fI\-option \fR?\fIstate \fR?\fIdefault\fR??
.
Returns the value specified for \fI\-option\fR in style \fIstyle\fR
in state \fIstate\fR, using the standard lookup rules for element options.
\fIstate\fR is a list of state names; if omitted,
it defaults to all bits off (the
.QW normal
state).
If the \fIdefault\fR argument is present, it is used as a fallback
value in case no specification for \fI\-option\fR is found.
.\" Otherwise -- signal error? return empty string? Leave unspecified for now.
If \fIstyle\fR does not exist, it is created.
.\" METHOD: map
.TP
\fBttk::style map \fIstyle\fR ?\fI\-option\fB { \fIstatespec value...\fB }\fR?
.
Sets dynamic (state dependent) values of the specified option(s) in \fIstyle\fR.
Each \fIstatespec / value\fR pair is examined in order;
the value corresponding to the first matching \fIstatespec\fR
is used.
If \fIstyle\fR does not exist, it is created.
\fBttk::style layout \fIstyle\fR ?\fIlayoutSpec\fR?
If only \fIstyle\fR and \fI\-option\fR are specified, get the dynamic values
for option \fI\-option\fR of style \fIstyle\fR.
Define the widget layout for style \fIstyle\fR.
If only \fIstyle\fR is specified, get the dynamic values for all options
of style \fIstyle\fR.
.\" METHOD: theme
See \fBLAYOUTS\fR below for the format of \fIlayoutSpec\fR.
If \fIlayoutSpec\fR is omitted, return the layout specification
for style \fIstyle\fR.
.TP
\fBttk::style element create\fR \fIelementName\fR \fItype\fR ?\fIargs...\fR?
Creates a new element in the current theme of type \fItype\fR.
The only cross-platform built-in element type is \fIimage\fR
(see \fBttk_image\fR(n)) but themes may define other element types
(see \fBTtk_RegisterElementFactory\fR). On suitable versions of Windows
an element factory is registered to create Windows theme elements
(see \fBttk_vsapi\fR(n)).
.TP
\fBttk::style theme\fI args\fR
.RS
\fBttk::style element names\fR
Returns the list of elements defined in the current theme.
.TP
\fBttk::style element options \fIelement\fR
Returns the list of \fIelement\fR's options.
.TP
\fBttk::style theme create\fI themeName\fR ?\fB\-parent \fIbasedon\fR? ?\fB\-settings \fIscript...\fR ?
\fBttk::style theme create\fR \fIthemeName\fR ?\fB\-parent \fIbasedon\fR? ?\fB\-settings \fIscript...\fR ?
.
Creates a new theme.  It is an error if \fIthemeName\fR already exists.
If \fB\-parent\fR is specified, the new theme will inherit
styles, elements, and layouts from the parent theme \fIbasedon\fR.
If \fB\-settings\fR is present, \fIscript\fR is evaluated in the
context of the new theme as per \fBttk::style theme settings\fR.
.TP
\fBttk::style theme names\fR
.
Returns a list of all known themes.
.TP
\fBttk::style theme settings \fIthemeName script\fR
\fBttk::style theme settings \fIthemeName\fR \fIscript\fR
.
Temporarily sets the current theme to \fIthemeName\fR,
evaluate \fIscript\fR, then restore the previous theme.
Typically \fIscript\fR simply defines styles and elements,
though arbitrary Tcl code may appear.
.TP
\fBttk::style theme styles\fR ?\fIthemeName\fR?
\fBttk::style theme names\fR
.
Returns a list of all styles in \fIthemeName\fR. If \fIthemeName\fR
Returns a list of all known themes.
is omitted, the current theme is used.
.TP
\fBttk::style theme use\fR ?\fIthemeName\fR?
.
Without an argument the result is the name of the current theme.
Otherwise this command sets the current theme to \fIthemeName\fR,
and refreshes all widgets.
.RE
.SH LAYOUTS
.PP
A \fIlayout\fR specifies a list of elements, each followed
by one or more options specifying how to arrange the element.
The layout mechanism uses a simplified version of the \fBpack\fR
geometry manager: given an initial cavity,
each element is allocated a parcel.
Then the parcel actually used by the element is adjusted within
the allocated parcel.
Valid options are:
.\" -border should remain undocumented for now (dubious usefulness)
.\" .TP
.\" \fB\-border\fI boolean\fR
.\" .
.\" Specifies whether the element is drawn after its children. Defaults to 0.
.\" OPTION: -children
.TP
\fB\-children { \fIsublayout...\fB }\fR
.
Specifies a list of elements to place inside the element.
.\" OPTION: -expand
.TP
\fB\-expand\fI boolean\fR
.
Specifies whether the allocated parcel is the entire cavity. If so,
simultaneous specification of \fB\-side\fR is ignored.
Defaults to 0.
.\" OPTION: -side
.TP
\fB\-side \fIside\fR
.
Specifies which side of the cavity to place the element;
one of \fBleft\fR, \fBright\fR, \fBtop\fR, or \fBbottom\fR.
For instance, \fB\-side top\fR allocates the parcel along the top of
the cavity having width and height respectively the width of the cavity
and the height of the element.
If omitted, the allocated parcel is the entire cavity (same effect
If omitted, the element occupies the entire cavity.
as \fB\-expand\fR 1).
.\" OPTION: -sticky
.TP
\fB\-sticky\fR \fB[\fInswe\fB]\fR
.
Specifies the actual parcel position and size inside the allocated parcel.
If specified as an empty string then the actual parcel is centered in
the allocated parcel. Default is \fBnswe\fR.
Specifies where the element is placed inside its allocated parcel.
.\" -unit should remain undocumented for now (dubious usefulness)
.\" .TP
.\" \fB\-unit\fI boolean\fR
.TP
\fB\-children { \fIsublayout... \fB}\fR
.\" .
.\" Specifies whether the element propagates its state to its children.
.\" Defaults to 0.
Specifies a list of elements to place inside the element.
.\" Also: -border, -unit, -expand: may go away.
.PP
For example:
.CS
ttk::style layout Horizontal.TScrollbar {
    Scrollbar.trough -children {
        Scrollbar.leftarrow -side left
        Scrollbar.rightarrow -side right
        Horizontal.Scrollbar.thumb -side left -sticky ew
    Scrollbar.trough \-children {
        Scrollbar.leftarrow \-side left
        Scrollbar.rightarrow \-side right
        Horizontal.Scrollbar.thumb \-side left \-sticky ew
    }
}
.CE
.SH ROOT STYLE
.PP
The
.QW .
theme root style can be configured like any other style, providing defaults
for its derived styles. In addition to the usual options,
.QW .
styling options configurable with \fBttk::style\fP are:
.PP
\fB\-insertofftime\fP \fIamount\fP
.RS
Specifies a non-negative integer value indicating the number of milliseconds
the insertion cursor should remain
.QW off
in each blink cycle. If this option is zero then the cursor does not blink:
it is on all the time. Defaults to 300 ms, unless overriden with a
\fBRESOURCE_MANAGER\fR property or \fB.Xdefaults\fR file.
.RE
.PP
\fB\-insertontime\fP \fIamount\fP
.RS
Specifies a non-negative integer value indicating the number of milliseconds
the insertion cursor should remain
.QW on
in each blink cycle. Defaults to 600 ms, unless overriden with a
\fBRESOURCE_MANAGER\fR property or \fB.Xdefaults\fR file.
.RE
.SH "SEE ALSO"
ttk::intro(n), ttk::widget(n), photo(n), ttk_image(n)
.SH KEYWORDS
style, theme, appearance
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_treeview.n.

58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119



120
121
122


123
124
125
126
127
128

129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209

210
211
212

213
214
215
216
217

218
219
220
221
222

223
224
225
226
227
228
229
230
231

232
233
234


235
236
237
238
239

240
241

242
243
244

245
246

247
248



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78



79
80
81
82
83
84
85
86
87

88
89
90
91
92











93
94






95
96

97

98
99
100
101


102
103




104

105








106




































107
108

109
110
111
112
113
114
115
116
117
118
119

120
121

122
123
124
125
126
127
128
129

130
131

132
133

134


135

136

137

138
139
140

141

142

143
144
145

146

147







148



149
150



151

152


153



154
155

156
157

158
159
160
161
162

163
164
165

166
167

168
169
170
171
172
173
174

175








176

177
178

179
180

181
182
183


184
185

186
187
188

189
190

191

192
193

194

195
196

197
198

199
200

201
202
203
204

205
206

207
208
209
210
211
212
213







-
+













-
-
-









-
+




-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-


-

-
+
+
+

-
-
+
+
-
-
-
-

-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-











-


-








-


-


-
+
-
-

-
+
-

-
+


-

-
+
-



-
+
-

-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-

-
+
-
-
+
-
-
-
+

-
+

-
+
+
+


-



-


-







-

-
-
-
-
-
-
-
-

-


-


-



-
-


-



-


-

-


-

-


-


-


-




-


-







specifying which data columns are displayed
and the order in which they appear,
or the string \fB#all\fP.
If set to \fB#all\fP (the default),
all columns are shown in the order given.
.OP \-height height Height
Specifies the number of rows which should be visible.
Note that
Note:
the requested width is determined from the sum of the column widths.
.OP \-selectmode selectMode SelectMode
Controls how the built-in class bindings manage the selection.
One of \fBextended\fR, \fBbrowse\fR, or \fBnone\fR.
.RS
.PP
If set to \fBextended\fR (the default), multiple items may be selected.
If \fBbrowse\fR, only a single item will be selected at a time.
If \fBnone\fR, the selection will not be changed.
.PP
Note that application code and tag bindings can set the selection
however they wish, regardless of the value of \fB\-selectmode\fR.
.RE
.OP \-selecttype selectType SelectType
Controls how the built-in class bindings manage the selection.
One of \fBitem\fR or \fBcell\fR.
.OP \-show show Show
A list containing zero or more of the following values, specifying
which elements of the tree to display.
.RS
.IP \fBtree\fR
Display tree labels in column #0.
.IP \fBheadings\fR
Display the heading row.
.PP
The default is \fBtree headings\fR.
The default is \fBtree headings\fR, i.e., show all elements.
.PP
\fBNOTE:\fR Column #0 always refers to the tree column,
even if \fB\-show tree\fR is not specified.
.RE
.OP \-striped striped Striped
Boolean specifying zebra striped item coloring.
Note that
striped items uses the \fB\-stripedbackground\fR option if set by the theme or
a tag. If not supported by the current theme, it will not show.
.OP \-titlecolumns titleColumns TitleColumns
Number of display columns at the left that should not be scrolled. The tree
column counts, even if \fB\-show tree\fR is not specified. Thus for value N of
this option, column #N is the first one that is scrollable. Default is 0.
.OP \-titleitems titleItems TitleItems
Number of items at the top that should not be vertically scrolled. Default is 0.
.SH "WIDGET COMMAND"
.PP
In addition to the standard
\fBcget\fR, \fBconfigure\fR, \fBinstate\fR,
\fBstate\fR, \fBstyle\fR, \fBxview\fR and \fByview\fR
commands (see \fBttk::widget\fR),
treeview widgets support the following additional commands:
.\" METHOD: bbox
.TP
\fIpathname \fBbbox \fIitem\fR ?\fIcolumn\fR?
.
Returns the bounding box (relative to the treeview widget's window)
of the specified \fIitem\fR in the form \fIx y width height\fR.
of the specified \fIitem\fR
in the form \fIx y width height\fR.
If \fIcolumn\fR is specified, returns the bounding box of that cell.
If the \fIitem\fR is not visible
(i.e., if it is a descendant of a closed item or is vertically scrolled
offscreen), returns the empty list.
(i.e., if it is a descendant of a closed item or is scrolled offscreen),
returns the empty list.
If \fIcolumn\fR is specified and is not hidden (by the \fB\-displaycolumns\fR
option), returns the bounding box of that cell within \fIitem\fR
(even if the cell is horizontally scrolled offscreen).
.\" METHOD: cellselection
.TP
\fIpathname \fBcellselection\fR ?\fIselop arg ...\fR?
\fIpathname \fBcget \fIoption\fR
.
Manages cell selection. Cell selection is independent from item selection
handled by the \fBselection\fR command. A cell is given by a list of two
elements, item and column.
For the rectangle versions of commands, the cells must be in displayed columns.
Any change to \fB\-columns\fR clears the cell selection.
A \fIcellList\fR argument may be a single cell or a list of cells.
If \fIselop\fR is not specified, returns the list of selected cells.
Returns the current value of the specified \fIoption\fR; see \fIttk::widget(n)\fR.
Otherwise, \fIselop\fR is one of the following:
.RS
.TP
\fIpathname \fBcellselection set \fIcellList\fR
.
\fIcellList\fR becomes the new cell selection.
.TP
\fIpathname \fBcellselection set \fIfirstCell lastCell\fR
.
The rectangle defined becomes the new cell selection.
.TP
\fIpathname \fBcellselection add \fIcellList\fR
.
Add \fIcellList\fR to the cell selection.
.TP
\fIpathname \fBcellselection add \fIfirstCell lastCell\fR
.
The rectangle defined is added to the cell selection.
.TP
\fIpathname \fBcellselection remove \fIcellList\fR
.
Remove \fIcellList\fR from the cell selection.
.TP
\fIpathname \fBcellselection remove \fIfirstCell lastCell\fR
.
The rectangle defined is removed from the cell selection.
.TP
\fIpathname \fBcellselection toggle \fIcellList\fR
.
Toggle the cell selection state of each cell in \fIcellList\fR.
.TP
\fIpathname \fBcellselection toggle \fIfirstCell lastCell\fR
.
Toggle the cell selection state of each cell in the rectangle defined.
.RE
.\" METHOD: children
.TP
\fIpathname \fBchildren \fIitem\fR ?\fInewchildren\fR?
.
If \fInewchildren\fR is not specified,
returns the list of children belonging to \fIitem\fR.
.RS
.PP
If \fInewchildren\fR is specified, replaces \fIitem\fR's child list
with \fInewchildren\fR.
Items in the old child list not present in the new child list
are detached from the tree.
None of the items in \fInewchildren\fR may be an ancestor
of \fIitem\fR.
.RE
.\" METHOD: column
.TP
\fIpathname \fBcolumn \fIcolumn\fR ?\fI\-option \fR?\fIvalue \-option value...\fR?
.
Query or modify the options for the specified \fIcolumn\fR.
If no \fI\-option\fR is specified,
returns a dictionary of option/value pairs.
If a single \fI\-option\fR is specified,
returns the value of that option.
Otherwise, the options are updated with the specified values.
The following options may be set on each column:
.RS
.\" OPTION: -id
.TP
\fB\-id \fIname\fR
.
The column name.  This is a read-only option.
For example, [\fI$pathname \fBcolumn #\fIn \fB\-id\fR]
returns the data column associated with display column \fIn\fR.
returns the data column associated with display column #\fIn\fR.
The tree column has \fB\-id #0\fR.
.\" OPTION: -anchor
.TP
\fB\-anchor \fIanchor\fR
\fB\-anchor\fR
.
Specifies how the text in this column should be aligned
with respect to the cell. \fIAnchor\fR is one of
with respect to the cell. One of
\fBn\fR, \fBne\fR, \fBe\fR, \fBse\fR,
\fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, or \fBcenter\fR.
.\" OPTION: -minwidth
.TP
\fB\-minwidth \fIminwidth\fR
\fB\-minwidth\fR
.
The minimum width of the column in pixels.
The treeview widget will not make the column any smaller than
\fB\-minwidth\fR when the widget is resized or the user drags a
heading column separator.  Default is 20 pixels.
column separator.
.\" OPTION: -separator
.TP
\fB\-separator \fIboolean\fR
.
Specifies whether or not a column separator should be drawn to the right
of the column.  Default is false.
.\" OPTION: -stretch
.TP
\fB\-stretch \fIboolean\fR
\fB\-stretch\fR
.
Specifies whether or not the column width should be adjusted
when the widget is resized or the user drags a heading column separator.
Specifies whether or not the column's width should be adjusted
when the widget is resized.
\fIBoolean\fR may have any of the forms accepted by \fBTcl_GetBoolean\fR.
By default columns are stretchable.
.\" OPTION: -width
.TP
\fB\-width \fIwidth\fR
\fB\-width \fIw\fR
.
The width of the column in pixels.  Default is 200 pixels. The specified
The width of the column in pixels.  Default is something reasonable,
column width may be changed by Tk in order to honor \fB\-stretch\fR
and/or \fB\-minwidth\fR, or when the widget is resized or the user drags a
heading column separator.
probably 200 or so.
.PP
Use \fIpathname fBcolumn #0\fR to configure the tree column.
Use \fIpathname column #0\fR to configure the tree column.
.RE
.\" METHOD: delete
.TP
\fIpathname \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
Modify or query widget options; see \fIttk::widget(n)\fR.
.TP
\fIpathname \fBdelete \fIitemList\fR
.
Deletes each of the items in \fIitemList\fR and all of their descendants.
The root item may not be deleted.
See also: \fBdetach\fR.
.\" METHOD: detach
.TP
\fIpathname \fBdetach \fIitemList\fR
.
Unlinks all of the specified items in \fIitemList\fR from the tree.
The items and all of their descendants are still present
and may be reinserted at another point in the tree
with the \fBmove\fR operation,
but will not be displayed until that is done.
The root item may not be detached.
See also: \fBdelete\fR.
.\" METHOD: detached
.TP
\fIpathname \fBdetached \fR?\fIitem\fR?
.
If \fIitem\fR is provided, returns a boolean value indicating whether it is
the name of a detached item (see \fBdetach\fR). Otherwise, returns a list of
all the detached items (in an arbitrary order). The root item is never
detached.
.\" METHOD: exists
.TP
\fIpathname \fBexists \fIitem\fR
.
Returns 1 if the specified \fIitem\fR is present in the tree,
0 otherwise.
.\" METHOD: focus
.TP
\fIpathname \fBfocus \fR?\fIitem\fR?
.
If \fIitem\fR is specified, sets the focus item to \fIitem\fR.
Otherwise, returns the current focus item, or \fB{}\fR if there is none.
.\" Need: way to clear the focus item.  {} works for this...
.\"
.\" METHOD: heading
.TP
\fIpathname \fBheading \fIcolumn\fR ?\fI\-option \fR?\fIvalue \-option value...\fR?
.
Query or modify the heading options for the specified \fIcolumn\fR.
Valid options are:
.RS
.\" OPTION: -text
.TP
\fB\-text \fItext\fR
.
The text to display in the column heading.
.\" OPTION: -image
.TP
\fB\-image \fIimageName\fR
.
Specifies an image to display to the right of the column heading.
.\" OPTION: -anchor
.TP
\fB\-anchor \fIanchor\fR
.
Specifies how the heading text should be aligned.
One of the standard Tk anchor values.
.\" OPTION: -command
.TP
\fB\-command \fIscript\fR
.
A script to evaluate when the heading label is pressed.
.PP
Use \fIpathname heading #0\fR to configure the tree column heading.
.RE
.\" METHOD: identify
.TP
\fIpathname \fBidentify \fIcomponent x y\fR
.
Returns a description of the specified \fIcomponent\fR
under the point given by \fIx\fR and \fIy\fR,
or the empty string if no such \fIcomponent\fR is present at that position.
The following subcommands are supported:
.RS
.TP
\fIpathname \fBidentify region \fIx y\fR
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495

496
497
498


499
500
501
502
503
504
505
506
507
508
509
510
511
512
513

514
515

516
517
518
519
520

521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577





578
579
580
581
582
583
584






585
586
587
588
589
590


591
592
593
594


595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617

618
619
620
621
622
623
624
625
626
627
628

629
630

631
632

633
634
635


636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
223
224
225
226
227
228
229

230

231
232
233


234
235
236





237

238
239
240

241
242
243
244
245

246
247

248

249
250

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274

275
276
277
278
279
280
281

282
283

284
285
286
287
288
289
290
291

292
293

294
295

296
297

298
299

300
301

302
303

304
305

306
307
308
309

310
311



312
313
314
315
316

317
318
319


320
321
322


323
324
325

326
327

328
329

330
331
332
333
334
335

336

337








338
339


340
341



342
343

344
345
346
347


348
349

350
351

352
353
354
355
356

357
358
359

























360

361
362
363
364
365
366
367
368
369
370







371

372
373
374
375
376
377

378
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400


401
402




403
404





405
406
407
408
409
410
411
412
413
414
415





416
417
418

419
420
421
422
423
424
425
426
427
428
429

430


431


432



433
434


435
436









437
438
439
440
441
442
443
444
445
446
447




448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466



467
468
469
470
471
472
473
474
475
476













































































477
478
479
480
481







-

-



-
-
+


-
-
-
-
-

-



-





-


-

-


-



















-
+
+
+


-







-


-








-


-


-


-


-


-


-


-




-


-
-
-





-



-
-
+


-
-
+


-


-


-






-

-
+
-
-
-
-
-
-
-
-
+

-
-
+
+
-
-
-


-




-
-


-
+

-
+




-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-










-
-
-
-
-
-
-

-






-


+
+
+
+
+

-





+
+
+
+
+
+




-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
+










-
-
-
-
-
+


-
+










-
+
-
-
+
-
-
+
-
-
-
+
+
-
-


-
-
-
-
-
-
-
-
-











-
-
-
-


















-
+
-
-
-










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





will return the display column identifier
of the heading to left of the separator.
.IP tree
The tree area.
.IP cell
A data cell.
.RE
.TP
\fIpathname \fBidentify item \fIx y\fR
.
Returns the item ID of the item at position \fIy\fR.
.TP
\fIpathname \fBidentify column \fIx y\fR
.
Returns the display column identifier of the cell at position \fIx\fR.
Returns the data column identifier of the cell at position \fIx\fR.
The tree column has ID \fB#0\fR.
.TP
\fIpathname \fBidentify cell \fIx y\fR
.
Returns the cell identifier of the cell at position \fIx y\fR.
A cell identifier is a list of item ID and column ID.
.TP
\fIpathname \fBidentify element \fIx y\fR
.
The element at position \fIx,y\fR.
.TP
\fIpathname \fBidentify row \fIx y\fR
.
Obsolescent synonym for \fIpathname \fBidentify item\fR.
.PP
See \fBCOLUMN IDENTIFIERS\fR for a discussion of display columns
and data columns.
.RE
.\" METHOD: index
.TP
\fIpathname \fBindex \fIitem\fR
.
Returns the integer index of \fIitem\fR within its parent's list of children.
.\" METHOD: insert
.TP
\fIpathname \fBinsert \fIparent index\fR ?\fB\-id \fIid\fR? \fIoptions...\fR
.
Creates a new item.
\fIparent\fR is the item ID of the parent item,
or the empty string \fB{}\fR
to create a new top-level item.
\fIindex\fR is an integer, or the value \fBend\fR, specifying where in the
list of \fIparent\fR's children to insert the new item.
If \fIindex\fR is less than or equal to zero,
the new node is inserted at the beginning;
if \fIindex\fR is greater than or equal to the current number of children,
it is inserted at the end.
If \fB\-id\fR is specified, it is used as the item identifier;
\fIid\fR must not already exist in the tree.
Otherwise, a new unique identifier is generated.
.RS
.PP
\fIpathname \fBinsert\fR returns the item identifier of the
newly created item.
See \fBITEM OPTIONS\fR for the list of available options.
.RE
.\" METHOD: item
.TP
\fIpathname \fBinstate \fIstatespec\fR ?\fIscript\fR?
Test the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathname \fBitem \fIitem\fR ?\fI\-option \fR?\fIvalue \-option value...\fR?
.
Query or modify the options for the specified \fIitem\fR.
If no \fI\-option\fR is specified,
returns a dictionary of option/value pairs.
If a single \fI\-option\fR is specified,
returns the value of that option.
Otherwise, the item's options are updated with the specified values.
See \fBITEM OPTIONS\fR for the list of available options.
.\" METHOD: move
.TP
\fIpathname \fBmove \fIitem parent index\fR
.
Moves \fIitem\fR to position \fIindex\fR in \fIparent\fR's list of children.
It is illegal to move an item under one of its descendants.
.RS
.PP
If \fIindex\fR is less than or equal to zero, \fIitem\fR is moved
to the beginning; if greater than or equal to the number of children,
it is moved to the end.
.RE
.\" METHOD: next
.TP
\fIpathname \fBnext \fIitem\fR
.
Returns the identifier of \fIitem\fR's next sibling,
or \fB{}\fR if \fIitem\fR is the last child of its parent.
.\" METHOD: parent
.TP
\fIpathname \fBparent \fIitem\fR
.
Returns the ID of the parent of \fIitem\fR,
or \fB{}\fR if \fIitem\fR is at the top level of the hierarchy.
.\" METHOD: prev
.TP
\fIpathname \fBprev \fIitem\fR
.
Returns the identifier of \fIitem\fR's previous sibling,
or \fB{}\fR if \fIitem\fR is the first child of its parent.
.\" METHOD: see
.TP
\fIpathname \fBsee \fIitem\fR
.
Ensure that \fIitem\fR is visible:
sets all of \fIitem\fR's ancestors to \fB\-open true\fR,
and scrolls the widget if necessary so that \fIitem\fR is
within the visible portion of the tree.
.\" METHOD: selection
.TP
\fIpathname \fBselection\fR ?\fIselop itemList\fR?
.
Manages item selection. Item selection is independent from cell selection
handled by the \fBcellselection\fR command.
If \fIselop\fR is not specified, returns the list of selected items.
Otherwise, \fIselop\fR is one of the following:
.RS
.TP
\fIpathname \fBselection set \fIitemList\fR
.
\fIitemList\fR becomes the new selection.
.TP
\fIpathname \fBselection add \fIitemList\fR
.
Add \fIitemList\fR to the selection.
Add \fIitemList\fR to the selection
.TP
\fIpathname \fBselection remove \fIitemList\fR
.
Remove \fIitemList\fR from the selection.
Remove \fIitemList\fR from the selection
.TP
\fIpathname \fBselection toggle \fIitemList\fR
.
Toggle the selection state of each item in \fIitemList\fR.
.RE
.\" METHOD: set
.TP
\fIpathname \fBset \fIitem\fR ?\fIcolumn\fR? ?\fIvalue\fR?
.
With one argument, returns a dictionary of column/value pairs
for the specified \fIitem\fR.
With two arguments, returns the current value of the specified \fIcolumn\fR.
With three arguments, sets the value of column \fIcolumn\fR
in item \fIitem\fR to the specified \fIvalue\fR.
See also \fBCOLUMN IDENTIFIERS\fR.
.\" METHOD: tag
.TP
\fIpathName \fBtag \fIargs...\fR
\fIpathname \fBstate\fR ?\fIstateSpec\fR?
.
Manages tags. Tags can be set on items as well as on cells.
The set of tags is shared between items and cells. However item tagging is
independent from cell tagging (for instance adding a tag on an item does
not also add this tag on the cells in that item). Cell tags take precedence
over item tags when drawing.
The following subcommands are supported:
.RS
Modify or query the widget state; see \fIttk::widget(n)\fR.
.TP
\fIpathName \fBtag add \fItag items\fR
.
\fIpathName \fBtag \fIargs...\fR
.RS
Adds the specified \fItag\fR to each of the listed \fIitems\fR.
If \fItag\fR is already present for a particular item,
then the \fB\-tags\fR for that item are unchanged.
.TP
\fIpathName \fBtag bind \fItagName \fR?\fIsequence\fR? ?\fIscript\fR?
.
Add a Tk binding script for the event sequence \fIsequence\fR
to the tag \fItagName\fR.  When an X event is delivered to an item,
binding scripts for each of the item's \fB\-tags\fR are evaluated
in order as per \fIbindtags(n)\fR.
If the event can be associated with a cell (i.e. mouse events) any
bindings for the cell's \fB\-tags\fR are evaluated as well.
.RS
.PP
\fB<Key>\fR, \fB<KeyRelease>\fR, and virtual events
\fB<KeyPress>\fR, \fB<KeyRelease>\fR, and virtual events
are sent to the focus item.
\fB<Button>\fR, \fB<ButtonRelease>\fR, and \fB<Motion>\fR events
\fB<ButtonPress>\fR, \fB<ButtonRelease>\fR, and \fB<Motion>\fR events
are sent to the item under the mouse pointer.
No other event types are supported.
.PP
The binding \fIscript\fR undergoes \fB%\fR-substitutions before
evaluation; see \fBbind\fR(n) for details.
evaluation; see \fBbind(n)\fR for details.
.RE
.TP
\fIpathName \fBtag cell \fIsubcommand...\fR
.
Manages tags on individual cells.
A \fIcellList\fR argument may be a single cell or a list of cells.
.RS
.TP
\fIpathName \fBtag cell add \fItag cellList\fR
.
Adds the specified \fItag\fR to each of the listed \fIcellList\fR.
If \fItag\fR is already present for a particular cell,
then the tag list for that cell is unchanged.
.TP
\fIpathName \fBtag cell has \fItagName\fR ?\fIcell\fR?
.
If \fIcell\fR is specified, returns 1 or 0
depending on whether the specified cell has the named tag.
Otherwise, returns a list of all cells which have
the specified tag.
.TP
\fIpathName \fBtag cell remove \fItag\fR ?\fIcellList\fR?
.
Removes the specified \fItag\fR from each of the listed \fIcellList\fR.
If \fIcellList\fR is omitted, removes \fItag\fR from each cell in the tree.
.RE
.TP
\fIpathName \fBtag configure \fItagName\fR ?\fIoption\fR? ?\fIvalue option value...\fR?
.
Query or modify the options for the specified \fItagName\fR.
If one or more \fIoption/value\fR pairs are specified,
sets the value of those options for the specified tag.
If a single \fIoption\fR is specified,
returns the value of that option
(or the empty string if the option has not been specified for \fItagName\fR).
With no additional arguments,
returns a dictionary of the option settings for \fItagName\fR.
See \fBTAG OPTIONS\fR for the list of available options.
.TP
\fIpathName \fBtag delete \fItagName\fR
.
Deletes all tag information for the \fItagName\fR argument. The command
removes the tag from all items and cells in the widget and also deletes any
other information associated with the tag, such as bindings and display
information. The command returns an empty string.
.TP
\fIpathName \fBtag has \fItagName\fR ?\fIitem\fR?
.
If \fIitem\fR is specified, returns 1 or 0
depending on whether the specified item has the named tag.
Otherwise, returns a list of all items which have
the specified tag.
.TP
\fIpathName \fBtag names\fR
.
Returns a list of all tags used by the widget.
.TP
\fIpathName \fBtag add \fItag items\fR
Adds the specified \fItag\fR to each of the listed \fIitems\fR.
If \fItag\fR is already present for a particular item,
then the \fB\-tags\fR for that item are unchanged.
.TP
\fIpathName \fBtag remove \fItag\fR ?\fIitems\fR?
.
Removes the specified \fItag\fR from each of the listed \fIitems\fR.
If \fIitems\fR is omitted, removes \fItag\fR from each item in the tree.
If \fItag\fR is not present for a particular item,
then the \fB\-tags\fR for that item are unchanged.
.RE
.TP
\fIpathName \fBxview \fIargs\fR
Standard command for horizontal scrolling; see \fIwidget(n)\fR.
.TP
\fIpathName \fByview \fIargs\fR
Standard command for vertical scrolling; see \fIttk::widget(n)\fR.
.SH "ITEM OPTIONS"
.PP
The following item options may be specified for items
in the \fBinsert\fR and \fBitem\fR widget commands.
.IP \fB\-text\fR
The textual label to display for the item in the tree column.
.OP \-text text Text
The textual label to display for the item.
.IP \fB\-height\fR
The height for the item, in integer multiples of \fB\-rowheight\fP. Default is 1.
.IP \fB\-image\fR
A Tk image, displayed next to the label in the tree column, placed according
.OP \-image image Image
A Tk image, displayed to the left of the label.
to \fB\-imageanchor\fR.
.IP \fB\-imageanchor\fR
Specifies how the \fB\-image\fR is displayed relative to the text.
Default is \fBw\fR. One of the standard Tk anchor values.
.IP \fB\-values\fR
.OP \-values values Values
The list of values associated with the item.
.RS
.PP
Each item should have the same number of values as
the \fB\-columns\fR widget option.
If there are fewer values than columns,
the remaining values are assumed empty.
If there are more values than columns,
the extra values are ignored.
.RE
.IP \fB\-hidden\fR
A boolean value indicating whether this item
should be displayed (\fB\-hidden false\fR) or hidden (\fB\-hidden true\fR).
If a parent is hidden, all its decendants are hidden too.
.IP \fB\-open\fR
.OP \-open open Open
A boolean value indicating whether the item's children
should be displayed (\fB\-open true\fR) or hidden (\fB\-open false\fR).
.IP \fB\-tags\fR
.OP \-tags tags Tags
A list of tags associated with this item.
.SH "TAG OPTIONS"
.PP
The following options may be specified on tags:
.IP \fB\-foreground\fR
Specifies the text foreground color.
.IP \fB\-background\fR
Specifies the cell or item background color.
.IP \fB\-font\fR
Specifies the font to use when drawing text.
.IP \fB\-image\fR
.\" ??? Maybe: .IP \-anchor
Specifies the cell or item image.
.IP \fB\-imageanchor\fR
.\" ??? Maybe: .IP \-padding
Specifies the cell or item image anchor.
.IP \fB\-padding\fR
.\" ??? Maybe: .IP \-text
Specifies the cell padding. A data cell will have a default padding of {4 0}
.IP \fB\-stripedbackground\fR
Specifies the cell or item background color for alternate lines,
.IP \fB\-image\fR
Specifies the item image, in case the item's \fB\-image\fR option is empty.
if \fB\-striped\fR is true.
.PP
.\" .PP
.\" \fI(@@@ TODO: sort out order of precedence for options)\fR
.PP
Tags on cells have precedence over tags on items. Then, tag priority is
decided by the creation order: tags created first receive higher priority.
An item's options, like \fB\-image\fR and \fB\-imageanchor\fR, have priority
over tags.
.SH "IMAGES"
The -image option on an item, and on an item tag, controls the image next to
the label in the tree column.
Other cells can have images through the cell tag -image option.
.SH "COLUMN IDENTIFIERS"
.PP
Column identifiers take any of the following forms:
.IP \(bu
A symbolic name from the list of \fB\-columns\fR.
.IP \(bu
An integer \fIn\fR, specifying the \fIn\fRth data column.
.IP \(bu
A string of the form \fB#\fIn\fR, where \fIn\fR is an integer,
specifying the \fIn\fRth display column.
.PP
Column identifiers support the same simple interpretation as
for the command \fBstring index\fR, with simple integer index
arithmetic and indexing relative to \fBend\fR.
.PP
\fBNOTE:\fR
Item \fB\-values\fR may be displayed in a different order than
the order in which they are stored.
.PP
\fBNOTE:\fR Column #0 always refers to the tree column,
even if \fB\-show tree\fR is not specified.
.PP
A \fIdata column number\fR is an index into an item's \fB\-values\fR list;
a \fIdisplay column number\fR is the column number in the tree
where the values are displayed.
Tree labels are displayed in column #0.
If \fB\-displaycolumns\fR is not set,
then data column \fIn\fR is displayed in display column \fB#\fIn+1\fR.
Again, \fBcolumn #0 always refers to the tree column\fR.
.SH "VIRTUAL EVENTS"
.PP
The treeview widget generates the following virtual events.
.IP <<TreeviewSelect>>
Generated whenever the selection or cellselection changes.
Generated whenever the selection changes.
It might also be generated when selection is affected but not actually changed.
Further, multiple selection changes could happen before events can be processed
leading to multiple events with the same visible selection.
.IP <<TreeviewOpen>>
Generated just before setting the focus item to \fB\-open true\fR.
.IP <<TreeviewClose>>
Generated just after setting the focus item to \fB\-open false\fR.
.PP
The \fBfocus\fR and \fBselection\fR widget commands can be used
to determine the affected item or items.
'\" Not yet:
'\" In Tk 8.5, the affected item is also passed as the \fB\-detail\fR field
'\" of the virtual event.
.SH "STYLING OPTIONS"
.PP
The class name for a \fBttk::treeview\fP is \fBTreeview\fP.
The treeview header class name is \fBHeading\fP.
The treeview item class name is \fBItem\fP.
The treeview cell class name is \fBCell\fP.
.PP
Dynamic states: \fBdisabled\fP, \fBselected\fP.
.PP
\fBTreeview\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-fieldbackground\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.br
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-indent\fP \fIamount\fP
.RS
Specifies how many pixels items are indented from their parents. Defaults to 20.
.RE
.br
\fB\-columnseparatorwidth\fP \fIpixels\fP
.br
\fB\-rowheight\fP \fIpixels\fP
.RS
This is the standard height for an item.
If \fB\-rowheight\fP is not set by the style, it is set by measuring an
item and a cell layout with the style's settings.
This thus picks up the font and
any focus ring or padding from the theme's layout.
The \fB\-rowheight\fP may need to be set to make sure that a row
is large enough to contain any images.
.PP
Example of how to set \fB\-rowheight\fP, adapting to a font in a similar
way to how the default value is set:
.RE
.PP
.CS
ttk::style configure Treeview \\
     -rowheight [expr {[font metrics \fIfont\fP -linespace] + 2}]
.CE
.br
\fB\-stripedbackground\fP \fIcolor\fP
.PP
\fBHeading\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-background\fP \fIcolor\fP
.br
\fB\-font\fP \fIfont\fP
.br
\fB\-relief\fP \fIrelief\fP
.PP
\fBItem\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-foreground\fP \fIcolor\fP
.br
\fB\-indicatormargins\fP \fIpadding\fP
.br
\fB\-indicatorsize\fP \fIamount\fP
.br
\fB\-padding\fP \fIpadding\fP
.PP
\fBCell\fP styling options configurable with \fBttk::style\fP
are:
.PP
\fB\-padding\fP \fIpadding\fP
.PP
Some options are only available for specific themes.
.PP
See the \fBttk::style\fP manual page for information on how to configure
ttk styles.
.SH "SEE ALSO"
ttk::widget(n), listbox(n), image(n), bind(n)
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to doc/ttk_vsapi.n.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40


41
42
43
44

45
46
47
48
49
50
51

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66












-
+










-
+






-










-
-
+
+


-







-








-







'\"
'\" Copyright (c) 2008 Pat Thoyts
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ttk_vsapi n 8.5 Tk "Tk Themed Widget"
.so man.macros
.BS
.SH NAME
ttk_vsapi \- Define a Microsoft Visual Styles element
.SH SYNOPSIS
\fBttk::style element create \fIname \fBvsapi\fI className partId\fR ?\fIstateMap\fR? ?\fIoptions\fR?
\fBttk::style element create \fIname\fR \fBvsapi\fR \fIclassName\fR \fIpartId\fR ?\fIstateMap\fR? ?\fIoptions\fR?
.BE
.SH DESCRIPTION
.PP
The \fBvsapi\fR element factory creates a new element
in the current theme whose visual appearance is drawn using the
Microsoft Visual Styles API which is responsible for the themed styles
on Windows XP and Vista. This factory permits any of the Visual
Styles parts to be declared as Ttk elements that can then be
included in a style layout to modify the appearance of Ttk widgets.
.PP
The \fIclassName\fR and \fIpartId\fR are required parameters and specify
\fIclassName\fR and \fIpartId\fR are required parameters and specify
the Visual Styles class and part as given in the Microsoft
documentation. The \fIstateMap\fR may be provided to map Ttk states to
Visual Styles API states (see \fBSTATE MAP\fR).
.SH "OPTIONS"
.PP
Valid \fIoptions\fR are:
.\" OPTION: -padding
.TP
\fB\-padding \fIpadding\fR
.
Specify the element's interior padding.
\fIpadding\fR is a list of up to four integers specifying
the left, top, right and bottom padding quantities respectively.
If fewer than four elements are specified,
\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
In other words, a list of three numbers specify the left, vertical, and right
padding; a list of two numbers specify the horizontal and the vertical padding;
In other words, a list of three numbers specify the left, vertical, and right padding;
a list of two numbers specify the horizontal and the vertical padding;
a single number specifies the same padding all the way around the widget.
This option may not be mixed with any other options.
.\" OPTION: -margins
.TP
\fB\-margins \fIpadding\fR
.
Specifies the elements exterior padding.
\fIpadding\fR is a list of up to four integers specifying
the left, top, right and bottom padding quantities respectively.
This option may not be mixed with any other options.
.\" OPTION: -width
.TP
\fB\-width \fIwidth\fR
.
Specifies the height for the element. If this option is set then
the Visual Styles API will not be queried for the recommended
size or the part. If this option is set then \fB\-height\fR should
also be set. The \fB\-width\fR and \fB\-height\fR options cannot
be mixed with the \fB\-padding\fR or \fB\-margins\fR options.
.\" OPTION: -height
.TP
\fB\-height \fIheight\fR
.
Specifies the height of the element. See the comments for \fB\-width\fR.
.SH "STATE MAP"
.PP
The \fIstateMap\fR parameter is a list of ttk states and the

Changes to doc/ttk_widget.n.

76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
76
77
78
79
80
81
82




83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
-
-
-
+













-
+







relative to the inner margins.  Legal values are
\fBn\fR, \fBne\fR, \fBe\fR, \fBse\fR,
\fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, and \fBcenter\fR.
See also \fB\-justify\fR (for widgets supporting this option).
.OP \-compound compound Compound
Specifies how to display the image relative to the text,
in the case both \fB\-text\fR and \fB\-image\fR are present.
If set to the empty string (the default), the rules described in the
"Elements" section of \fIttk::intro(n)\fR explain which value is actually
used.
The other valid values are:
Valid values are:
.RS
.IP text
Display text only.
.IP image
Display image only.
.IP center
Display text centered on top of image.
.IP top
.IP bottom
.IP left
.IP right
Display image above, below, left of, or right of the text, respectively.
.IP none
Display the image if present, otherwise the text.
The default; display the image if present, otherwise the text.
.RE
.OP \-font font Font
Font to use for the text displayed by the widget.
.OP \-foreground textColor TextColor
The widget's foreground color.
If unspecified, the theme default is used.
.OP \-image image Image
121
122
123
124
125
126
127
128
129


130
131
132
133


134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340


341
342
343
344
345
346
347

348


349
350
351

352


353

354


355
356
357

358


359
360
361
362
363

364


365
366
367
368
369

370


371

372


373
374
375
376
377
378

379


380
381
382

383


384
385
386
387
388
389
390
118
119
120
121
122
123
124


125
126
127
128


129
130
131
132
133
134
135

136

137
138
139
140
141
142
143
144
145
146
147
148
149
150









151



152
153
154
155
156
157
158
159

160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187

188


189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215



































































































216
217
218
219

220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235

236
237
238
239

240
241
242
243
244
245

246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261

262
263
264
265

266
267
268
269
270
271
272
273
274

275
276
277
278
279
280

281
282
283
284
285
286
287
288
289







-
-
+
+


-
-
+
+





-
+
-














-
-
-
-
-
-
-
-
-

-
-
-








-





-
















-







-
+
-
-










-

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



+
-
+
+







+
-
+
+



+
-
+
+

+
-
+
+



+
-
+
+





+
-
+
+





+
-
+
+

+
-
+
+






+
-
+
+



+
-
+
+







Specifies the internal padding for the widget.
The padding is a list of up to four length specifications
\fIleft top right bottom\fR.
If fewer than four elements are specified,
\fIbottom\fR defaults to \fItop\fR,
\fIright\fR defaults to \fIleft\fR, and
\fItop\fR defaults to \fIleft\fR.
In other words, a list of three numbers specify the left, vertical, and right
padding; a list of two numbers specify the horizontal and the vertical padding;
In other words, a list of three numbers specify the left, vertical, and right padding;
a list of two numbers specify the horizontal and the vertical padding;
a single number specifies the same padding all the way around the widget.
.OP \-text text Text
Specifies a text string to be displayed inside the widget (unless overridden
by \fB\-textvariable\fR for the widgets supporting this option).
Specifies a text string to be displayed inside the widget
(unless overridden by \fB\-textvariable\fR for the widgets supporting this option).
.OP \-textvariable textVariable Variable
Specifies the name of a global variable whose value will be used
in place of the \fB\-text\fR resource.
.OP \-underline underline Underline
If set, specifies the integer index (0-based) of a character to underline
in the text string. \fBend\fR corresponds to the last character,
in the text string.
\fBend\fR-1 to the before last character, and so on.
The underlined character is used for mnemonic activation.
.OP \-width width Width
If greater than zero, specifies how much space, in character widths,
to allocate for the text label.
If less than zero, specifies a minimum width.
If zero or unspecified, the natural width of the text label is used.
Note that some themes may specify a non-zero \fB\-width\fR
in the style.
.OP \-wraplength wrapLength WrapLength
Specifies the maximum line length. The value may have any of the forms
acceptable to \fBTk_GetPixels\fR. If this option is less than or equal
to zero, then automatic wrapping is not performed; otherwise
the text is split into lines such that no line is longer
than the specified value.
.SH "ENTRY OPTIONS"
The following options are supported by entry, spinbox and combobox:
.OP \-placeholder placeHolder PlaceHolder
Specifies a help text string to display if no text is otherwise displayed,
that is when the widget is empty. The placeholder text is displayed using
the values of the \fB\-font\fR, \fB\-justify\fR and
\fB\-placeholderforeground\fR options.
.OP \-placeholderforeground placeHolderForeground PlaceHolderForeground
Specifies the foreground color of the placeholder text.
.SH "COMPATIBILITY OPTIONS"
This option is only available for themed widgets that have
.QW corresponding
traditional Tk widgets.
.OP \-state state State
May be set to \fBnormal\fR or \fBdisabled\fR
to control the \fBdisabled\fR state bit.
This is a write-only option:
setting it changes the widget state,
but the \fBstate\fR widget command
does not affect the \fB\-state\fR option.
.SH COMMANDS
.\" METHOD: cget
.TP
\fIpathName \fBcget \fIoption\fR
.
Returns the current value of the configuration option given
by \fIoption\fR.
.\" METHOD: configure
.TP
\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
.
Query or modify the configuration options of the widget.
If one or more \fIoption\-value\fR pairs are specified,
then the command modifies the given widget option(s)
to have the given value(s);
in this case the command returns an empty string.
If \fIoption\fR is specified with no \fIvalue\fR,
then the command returns a list describing the named option:
the elements of the list are the
option name, database name, database class, default value,
and current value.
.\" Note: Ttk widgets don't use TK_OPTION_SYNONYM.
If no \fIoption\fR is specified, returns a list describing all of
the available options for \fIpathName\fR.
.\" METHOD: identify
.TP
\fIpathName \fBidentify element \fIx y\fR
.
Returns the name of the element under the point given
by \fIx\fR and \fIy\fR, or an empty string if the point does
not lie within any element.
\fIx\fR and \fIy\fR are pixel coordinates relative to the widget.
Some widgets accept other \fBidentify\fR subcommands described
Some widgets accept other \fBidentify\fR subcommands.
in these widgets documentation.
.\" METHOD: instate
.TP
\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR?
.
Test the widget's state.
If \fIscript\fR is not specified, returns 1 if
the widget state matches \fIstatespec\fR and 0 otherwise.
If \fIscript\fR is specified, equivalent to
.CS
if {[\fIpathName\fR instate \fIstateSpec\fR]} \fIscript\fR
.CE
.\" METHOD: state
.TP
\fIpathName \fBstate\fR ?\fIstateSpec\fR?
.
Modify or inquire widget state.
If \fIstateSpec\fR is present, sets the widget state:
for each flag in \fIstateSpec\fR, sets the corresponding flag
or clears it if prefixed by an exclamation point.
.RS
Returns a new state spec indicating which flags were changed:
.CS
set changes [\fIpathName \fRstate \fIspec\fR]
\fIpathName \fRstate $changes
.CE
will restore \fIpathName\fR to the original state.
If \fIstateSpec\fR is not specified,
returns a list of the currently-enabled state flags.
.RE
.\" METHOD: style
.TP
\fIpathName \fBstyle\fR
.
Return the style used by the widget.
.\" METHOD: xview
.TP
\fIpathName \fBxview \fIargs\fR
.
This command is used to query and change the horizontal position of the
content in the widget's window.  It can take any of the following
forms:
.RS
.TP
\fIpathName \fBxview\fR
.
Returns a list containing two elements.
Each element is a real fraction between 0 and 1; together they describe
the horizontal span that is visible in the window.
For example, if the first element is .2 and the second element is .6,
20% of the widget's content is off-screen to the left, the middle 40% is visible
in the window, and 40% of the content is off-screen to the right.
These are the same values passed to scrollbars via the \fB\-xscrollcommand\fR
option.
.TP
\fIpathName \fBxview\fI index\fR
.
Adjusts the view in the window so that the content given by \fIindex\fR
is displayed at the left edge of the window.
.TP
\fIpathName \fBxview moveto\fI fraction\fR
.
Adjusts the view in the window so that the character \fIfraction\fR of the
way through the content appears at the left edge of the window.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR.
'\" or an abbreviation of one of these, but we don't document that.
If \fIwhat\fR is
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then characters farther to the left
become visible;  if it is positive then characters farther to the right
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts left or right by
\fInumber\fR average-width characters on the display.
.RE
.\" METHOD: yview
.TP
\fIpathName \fByview \fIargs\fR
.
This command is used to query and change the vertical position of the
content in the widget's window.  It can take any of the following
forms:
.RS
.TP
\fIpathName \fByview\fR
.
Returns a list containing two elements.
Each element is a real fraction between 0 and 1; together they describe
the vertical span that is visible in the window.
For example, if the first element is .2 and the second element is .6,
20% of the widget's content is off-screen to the top, the middle 40% is visible
in the window, and 40% of the content is off-screen to the bottom.
These are the same values passed to scrollbars via the \fB\-yscrollcommand\fR
option.
.TP
\fIpathName \fByview\fI index\fR
.
Adjusts the view in the window so that the content given by \fIindex\fR
is displayed at the top edge of the window.
.TP
\fIpathName \fByview moveto\fI fraction\fR
.
Adjusts the view in the window so that the item \fIfraction\fR of the
way through the content appears at the top edge of the window.
\fIFraction\fR must be a fraction between 0 and 1.
.TP
\fIpathName \fByview scroll \fInumber what\fR
.
This command shifts the view in the window up or down according to
\fInumber\fR and \fIwhat\fR.
\fINumber\fR must be an integer or a float, but if it is a float then
it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR.
'\" or an abbreviation of one of these, but we don't document that.
If \fIwhat\fR is
\fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
If \fInumber\fR is negative then items farther to the top
become visible;  if it is positive then items farther to the bottom
become visible.
If \fIwhat\fR is \fBunits\fR, the view adjusts up or down by
\fInumber\fR average-width characters on the display.
.RE
.SH "WIDGET STATES"
The widget state is a bitmap of independent state flags.
Widget state flags include:
.TP
.IP \fBactive\fR
\fBactive\fR
.
The mouse cursor is over the widget
and pressing a mouse button will cause some action to occur. (aka
.QW prelight
(Gnome),
.QW hot
(Windows),
.QW hover ).
.TP
.IP \fBdisabled\fR
\fBdisabled\fR
.
Widget is disabled under program control (aka
.QW unavailable ,
.QW inactive ).
.TP
.IP \fBfocus\fR
\fBfocus\fR
.
Widget has keyboard focus.
.TP
.IP \fBpressed\fR
\fBpressed\fR
.
Widget is being pressed (aka
.QW armed
in Motif).
.TP
.IP \fBselected\fR
\fBselected\fR
.
.QW On ,
.QW true ,
or
.QW current
for things like checkbuttons and radiobuttons.
.TP
.IP \fBbackground\fR
\fBbackground\fR
.
Windows and the Mac have a notion of an
.QW active
or foreground window.
The \fBbackground\fR state is set for widgets in a background window,
and cleared for those in the foreground window.
.TP
.IP \fBreadonly\fR
\fBreadonly\fR
.
Widget should not allow user modification.
.TP
.IP \fBalternate\fR
\fBalternate\fR
.
A widget-specific alternate display format.
For example, used for checkbuttons and radiobuttons in the
.QW tristate
or
.QW mixed
state, and for buttons with \fB\-default active\fR.
.TP
.IP \fBinvalid\fR
\fBinvalid\fR
.
The widget's value is invalid.
(Potential uses: scale widget value out of bounds,
entry widget value failed validation.)
.TP
.IP \fBhover\fR
\fBhover\fR
.
The mouse cursor is within the widget.
This is similar to the \fBactive\fP state;
it is used in some themes for widgets that
provide distinct visual feedback for
the active widget in addition to the active element
within the widget.
.PP

Changes to doc/winfo.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
8
9
10
11
12
13
14

15
16
17
18
19
20
21

22
23

24
25
26
27
28
29

30
31

32
33
34
35
36
37
38

39
40

41
42

43
44

45
46
47
48
49
50

51
52

53

54
55

56
57
58
59
60
61
62

63
64

65
66
67
68
69
70
71
72
73
74
75



76
77
78

79
80

81
82

83
84

85
86

87

88

89
90
91
92
93
94
95
96
97

98
99

100
101
102

103
104

105
106
107
108
109
110
111
112

113
114

115
116
117
118

119
120

121
122
123
124
125

126
127

128

129
130

131
132
133
134
135
136
137

138
139

140
141
142

143
144

145
146

147
148

149
150
151
152
153
154

155

156

157
158
159
160
161
162
163
164
165

166
167

168
169
170
171
172
173

174
175

176
177
178
179
180
181
182

183
184

185
186
187
188
189
190

191
192

193
194
195

196
197

198
199
200

201
202

203
204
205
206
207
208

209
210

211
212
213
214

215
216

217
218
219
220

221
222

223
224

225
226

227
228

229
230

231
232

233
234

235
236

237
238

239
240

241
242

243
244

245
246

247
248
249
250

251
252

253
254

255
256

257
258
259
260
261
262
263
264
265

266
267

268
269
270

271
272

273
274
275

276
277

278
279
280
281

282
283

284

285
286

287
288
289
290
291
292
293

294
295

296
297

298
299

300
301

302
303

304
305
306
307

308
309

310
311
312
313

314
315

316
317
318
319
320
321
322
323

324
325

326
327
328
329

330
331

332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+






-


-






-


-







-


-


-


-






-


-

-


-







-


-











-
-
-



-


-


-


-


-

-
+
-









-


-



-


-








-


-




-


-





-


-

-


-







-


-



-


-


-


-






-

-
+
-









-


-






-


-







-


-






-


-



-


-



-


-






-


-




-


-




-


-


-


-


-


-


-


-


-


-


-


-


-


-




-


-


-


-









-


-



-


-



-


-




-


-

-


-







-


-


-


-


-


-




-


-




-


-








-


-




-


-









-
+







.TH winfo n 4.3 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
winfo \- Return window-related information
.SH SYNOPSIS
\fBwinfo\fI option \fR?\fIarg ...\fR?
\fBwinfo\fR \fIoption \fR?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The \fBwinfo\fR command is used to retrieve information about windows
managed by Tk.  It can take any of a number of different forms,
depending on the \fIoption\fR argument.  The legal forms are:
.\" METHOD: atom
.TP
\fBwinfo atom \fR?\fB\-displayof \fIwindow\fR? \fIname\fR
.
Returns a decimal string giving the integer identifier for the
atom whose name is \fIname\fR.  If no atom exists with the name
\fIname\fR then a new one is created.
If the \fB\-displayof\fR option is given then the atom is looked
up on the display of \fIwindow\fR;  otherwise it is looked up on
the display of the application's main window.
.\" METHOD: atomname
.TP
\fBwinfo atomname \fR?\fB\-displayof \fIwindow\fR? \fIid\fR
.
Returns the textual name for the atom whose integer identifier is
\fIid\fR.
If the \fB\-displayof\fR option is given then the identifier is looked
up on the display of \fIwindow\fR;  otherwise it is looked up on
the display of the application's main window.
This command is the inverse of the \fBwinfo atom\fR command.
It generates an error if no such atom exists.
.\" METHOD: cells
.TP
\fBwinfo cells \fIwindow\fR
.
Returns a decimal string giving the number of cells in the
color map for \fIwindow\fR.
.\" METHOD: children
.TP
\fBwinfo children \fIwindow\fR
.
Returns a list containing the path names of all the children
of \fIwindow\fR. Top-level windows are returned as children
of their logical parents. The list is in stacking order, with
the lowest window first, except for Top-level windows which
are not returned in stacking order. Use the \fBwm stackorder\fR
command to query the stacking order of Top-level windows.
.\" METHOD: class
.TP
\fBwinfo class \fIwindow\fR
.
Returns the class name for \fIwindow\fR.
.\" METHOD: colormapfull
.TP
\fBwinfo colormapfull \fIwindow\fR
.
Returns 1 if the colormap for \fIwindow\fR is known to be full, 0
otherwise.  The colormap for a window is
.QW known
to be full if the last
attempt to allocate a new color on that window failed and this
application has not freed any colors in the colormap since the
failed allocation.
.\" METHOD: containing
.TP
\fBwinfo containing \fR?\fB\-displayof \fIwindow\fR? \fIrootX rootY\fR
.
Returns the path name for the window containing the point given
by \fIrootX\fR and \fIrootY\fR.
\fIRootX\fR and \fIrootY\fR are specified in screen units (i.e.
any form acceptable to \fBTk_GetPixels\fR) in the coordinate
system of the root window (if a virtual-root window manager is in
use then the coordinate system of the virtual root window is used).
If the \fB\-displayof\fR option is given then the coordinates refer
to the screen containing \fIwindow\fR;  otherwise they refer to the
screen of the application's main window.
If no window in this application contains the point then an empty
string is returned.
An empty string is also returned if the point lies in the title bar
or border of its highest containing toplevel in this application.
(Note that with some window managers the borders may be invisible.)
In selecting the containing window, children are given higher priority
than parents and among siblings the highest one in the stacking order is
chosen.
.\" METHOD: depth
.TP
\fBwinfo depth \fIwindow\fR
.
Returns a decimal string giving the depth of \fIwindow\fR (number
of bits per pixel).
.\" METHOD: exists
.TP
\fBwinfo exists \fIwindow\fR
.
Returns 1 if there exists a window named \fIwindow\fR, 0 if no such
window exists.
.\" METHOD: fpixels
.TP
\fBwinfo fpixels \fIwindow number\fR
\fBwinfo fpixels \fIwindow\fR \fInumber\fR
.
Returns a floating-point value giving the number of pixels
in \fIwindow\fR corresponding to the distance given by \fInumber\fR.
\fINumber\fR may be specified in any of the forms acceptable
to \fBTk_GetScreenMM\fR, such as
.QW 2.0c
or
.QW 1i .
The return value may be fractional;  for an integer value, use
\fBwinfo pixels\fR.
.\" METHOD: geometry
.TP
\fBwinfo geometry \fIwindow\fR
.
Returns the geometry for \fIwindow\fR, in the form
\fIwidth\fBx\fIheight\fB+\fIx\fB+\fIy\fR.  All dimensions are
in pixels.
.\" METHOD: height
.TP
\fBwinfo height \fIwindow\fR
.
Returns a decimal string giving \fIwindow\fR's height in pixels.
When a window is first created its height will be 1 pixel;  the
height will eventually be changed by a geometry manager to fulfil
the window's needs.
If you need the true height immediately after creating a widget,
invoke \fBupdate\fR to force the geometry manager to arrange it,
or use \fBwinfo reqheight\fR to get the window's requested height
instead of its actual height.
.\" METHOD: id
.TP
\fBwinfo id \fIwindow\fR
.
Returns a hexadecimal string giving a low-level platform-specific
identifier for \fIwindow\fR.  On Unix platforms, this is the X
window identifier.  Under Windows, this is the Windows
HWND.  On the Macintosh the value has no meaning outside Tk.
.\" METHOD: interps
.TP
\fBwinfo interps \fR?\fB\-displayof \fIwindow\fR?
.
Returns a list whose members are the names of all Tcl interpreters
(e.g. all Tk-based applications) currently registered for a particular display.
If the \fB\-displayof\fR option is given then the return value refers
to the display of \fIwindow\fR;  otherwise it refers to
the display of the application's main window.
.\" METHOD: ismapped
.TP
\fBwinfo ismapped \fIwindow\fR
.
Returns \fB1\fR if \fIwindow\fR is currently mapped, \fB0\fR otherwise.
.\" METHOD: manager
.TP
\fBwinfo manager \fIwindow\fR
.
Returns the name of the geometry manager currently
responsible for \fIwindow\fR, or an empty string if \fIwindow\fR
is not managed by any geometry manager.
The name is usually the name of the Tcl command for the geometry
manager, such as \fBpack\fR or \fBplace\fR.
If the geometry manager is a widget, such as canvases or text, the
name is the widget's class command, such as \fBcanvas\fR.
.\" METHOD: name
.TP
\fBwinfo name \fIwindow\fR
.
Returns \fIwindow\fR's name (i.e. its name within its parent, as opposed
to its full path name).
The command \fBwinfo name .\fR will return the name of the application.
.\" METHOD: parent
.TP
\fBwinfo parent \fIwindow\fR
.
Returns the path name of \fIwindow\fR's parent, or an empty string
if \fIwindow\fR is the main window of the application.
.\" METHOD: pathname
.TP
\fBwinfo pathname \fR?\fB\-displayof \fIwindow\fR? \fIid\fR
.
Returns the path name of the window whose X identifier is \fIid\fR.
\fIId\fR must be a decimal, hexadecimal, or octal integer and must
correspond to a window in the invoking application.
If the \fB\-displayof\fR option is given then the identifier is looked
up on the display of \fIwindow\fR;  otherwise it is looked up on
the display of the application's main window.
.\" METHOD: pixels
.TP
\fBwinfo pixels \fIwindow number\fR
\fBwinfo pixels \fIwindow\fR \fInumber\fR
.
Returns the number of pixels in \fIwindow\fR corresponding
to the distance given by \fInumber\fR.
\fINumber\fR may be specified in any of the forms acceptable
to \fBTk_GetPixels\fR, such as
.QW 2.0c
or
.QW 1i .
The result is rounded to the nearest integer value;  for a
fractional result, use \fBwinfo fpixels\fR.
.\" METHOD: pointerx
.TP
\fBwinfo pointerx \fIwindow\fR
.
If the mouse pointer is on the same screen as \fIwindow\fR, returns the
pointer's x coordinate, measured in pixels in the screen's root window.
If a virtual root window is in use on the screen, the position is
measured in the virtual root.
If the mouse pointer is not on the same screen as \fIwindow\fR then
-1 is returned.
.\" METHOD: pointerxy
.TP
\fBwinfo pointerxy \fIwindow\fR
.
If the mouse pointer is on the same screen as \fIwindow\fR, returns a list
with two elements, which are the pointer's x and y coordinates measured
in pixels in the screen's root window.
If a virtual root window is in use on the screen, the position
is computed in the virtual root.
If the mouse pointer is not on the same screen as \fIwindow\fR then
both of the returned coordinates are \-1.
.\" METHOD: pointery
.TP
\fBwinfo pointery \fIwindow\fR
.
If the mouse pointer is on the same screen as \fIwindow\fR, returns the
pointer's y coordinate, measured in pixels in the screen's root window.
If a virtual root window is in use on the screen, the position
is computed in the virtual root.
If the mouse pointer is not on the same screen as \fIwindow\fR then
-1 is returned.
.\" METHOD: reqheight
.TP
\fBwinfo reqheight \fIwindow\fR
.
Returns a decimal string giving \fIwindow\fR's requested height,
in pixels.  This is the value used by \fIwindow\fR's geometry
manager to compute its geometry.
.\" METHOD: reqwidth
.TP
\fBwinfo reqwidth \fIwindow\fR
.
Returns a decimal string giving \fIwindow\fR's requested width,
in pixels.  This is the value used by \fIwindow\fR's geometry
manager to compute its geometry.
.\" METHOD: rgb
.TP
\fBwinfo rgb \fIwindow color\fR
.
Returns a list containing three decimal values in the range 0 to
65535, which are the
red, green, and blue intensities that correspond to \fIcolor\fR in
the window given by \fIwindow\fR.  \fIColor\fR
may be specified in any of the forms acceptable for a color
option.
.\" METHOD: rootx
.TP
\fBwinfo rootx \fIwindow\fR
.
Returns a decimal string giving the x-coordinate, in the root
window of the screen, of the
upper-left corner of \fIwindow\fR's border (or \fIwindow\fR if it
has no border).
.\" METHOD: rooty
.TP
\fBwinfo rooty \fIwindow\fR
.
Returns a decimal string giving the y-coordinate, in the root
window of the screen, of the
upper-left corner of \fIwindow\fR's border (or \fIwindow\fR if it
has no border).
.\" METHOD: screen
.TP
\fBwinfo screen \fIwindow\fR
.
Returns the name of the screen associated with \fIwindow\fR, in
the form \fIdisplayName\fR.\fIscreenIndex\fR.
.\" METHOD: screencells
.TP
\fBwinfo screencells \fIwindow\fR
.
Returns a decimal string giving the number of cells in the default
color map for \fIwindow\fR's screen.
.\" METHOD: screendepth
.TP
\fBwinfo screendepth \fIwindow\fR
.
Returns a decimal string giving the depth of the root window
of \fIwindow\fR's screen (number of bits per pixel).
.\" METHOD: screenheight
.TP
\fBwinfo screenheight \fIwindow\fR
.
Returns a decimal string giving the height of \fIwindow\fR's screen,
in pixels.
.\" METHOD: screenmmheight
.TP
\fBwinfo screenmmheight \fIwindow\fR
.
Returns a decimal string giving the height of \fIwindow\fR's screen,
in millimeters.
.\" METHOD: screenmmwidth
.TP
\fBwinfo screenmmwidth \fIwindow\fR
.
Returns a decimal string giving the width of \fIwindow\fR's screen,
in millimeters.
.\" METHOD: screenvisual
.TP
\fBwinfo screenvisual \fIwindow\fR
.
Returns one of the following strings to indicate the default visual
class for \fIwindow\fR's screen: \fBdirectcolor\fR, \fBgrayscale\fR,
\fBpseudocolor\fR, \fBstaticcolor\fR, \fBstaticgray\fR, or
\fBtruecolor\fR.
.\" METHOD: screenwidth
.TP
\fBwinfo screenwidth \fIwindow\fR
.
Returns a decimal string giving the width of \fIwindow\fR's screen,
in pixels.
.\" METHOD: server
.TP
\fBwinfo server \fIwindow\fR
.
Returns a string containing information about the server for
\fIwindow\fR's display.  The exact format of this string may vary
from platform to platform.  For X servers the string
has the form
.QW "\fBX\fImajor\fBR\fIminor vendor vendorVersion\fR"
where \fImajor\fR and \fIminor\fR are the version and revision
numbers provided by the server (e.g., \fBX11R5\fR), \fIvendor\fR
is the name of the vendor for the server, and \fIvendorRelease\fR
is an integer release number provided by the server.
.\" METHOD: toplevel
.TP
\fBwinfo toplevel \fIwindow\fR
.
Returns the path name of the top-of-hierarchy window containing \fIwindow\fR.
In standard Tk this will always be a \fBtoplevel\fR widget, but extensions may
create other kinds of top-of-hierarchy widgets.
.\" METHOD: viewable
.TP
\fBwinfo viewable \fIwindow\fR
.
Returns 1 if \fIwindow\fR and all of its ancestors up through the
nearest toplevel window are mapped.  Returns 0 if any of these
windows are not mapped.
.\" METHOD: visual
.TP
\fBwinfo visual \fIwindow\fR
.
Returns one of the following strings to indicate the visual
class for \fIwindow\fR: \fBdirectcolor\fR, \fBgrayscale\fR,
\fBpseudocolor\fR, \fBstaticcolor\fR, \fBstaticgray\fR, or
\fBtruecolor\fR.
.\" METHOD: visualid
.TP
\fBwinfo visualid \fIwindow\fR
.
Returns the X identifier for the visual for \fIwindow\fR.
.\" METHOD: visualsavailable
.TP
\fBwinfo visualsavailable \fIwindow\fR ?\fBincludeids\fR?
.
Returns a list whose elements describe the visuals available for
\fIwindow\fR's screen.
Each element consists of a visual class followed by an integer depth.
The class has the same form as returned by \fBwinfo visual\fR.
The depth gives the number of bits per pixel in the visual.
In addition, if the \fBincludeids\fR argument is provided, then the
depth is followed by the X identifier for the visual.
.\" METHOD: vrootheight
.TP
\fBwinfo vrootheight \fIwindow\fR
.
Returns the height of the virtual root window associated with \fIwindow\fR
if there is one;  otherwise returns the height of \fIwindow\fR's screen.
.\" METHOD: vrootwidth
.TP
\fBwinfo vrootwidth \fIwindow\fR
.
Returns the width of the virtual root window associated with \fIwindow\fR
if there is one;  otherwise returns the width of \fIwindow\fR's screen.
.\" METHOD: vrootx
.TP
\fBwinfo vrootx \fIwindow\fR
.
Returns the x-offset of the virtual root window associated with \fIwindow\fR,
relative to the root window of its screen.
This is normally either zero or negative.
Returns 0 if there is no virtual root window for \fIwindow\fR.
.\" METHOD: vrooty
.TP
\fBwinfo vrooty \fIwindow\fR
.
Returns the y-offset of the virtual root window associated with \fIwindow\fR,
relative to the root window of its screen.
This is normally either zero or negative.
Returns 0 if there is no virtual root window for \fIwindow\fR.
.\" METHOD: width
.TP
\fBwinfo width \fIwindow\fR
.
Returns a decimal string giving \fIwindow\fR's width in pixels.
When a window is first created its width will be 1 pixel;  the
width will eventually be changed by a geometry manager to fulfil
the window's needs.
If you need the true width immediately after creating a widget,
invoke \fBupdate\fR to force the geometry manager to arrange it,
or use \fBwinfo reqwidth\fR to get the window's requested width
instead of its actual width.
.\" METHOD: x
.TP
\fBwinfo x \fIwindow\fR
.
Returns a decimal string giving the x-coordinate, in \fIwindow\fR's
parent, of the
upper-left corner of \fIwindow\fR's border (or \fIwindow\fR if it
has no border).
.\" METHOD: y
.TP
\fBwinfo y \fIwindow\fR
.
Returns a decimal string giving the y-coordinate, in \fIwindow\fR's
parent, of the
upper-left corner of \fIwindow\fR's border (or \fIwindow\fR if it
has no border).
.SH EXAMPLE
.PP
Print where the mouse pointer is and what window it is currently over:
.CS
lassign [\fBwinfo pointerxy\fR .] x y
puts -nonewline "Mouse pointer at ($x,$y) which is "
puts \-nonewline "Mouse pointer at ($x,$y) which is "
set win [\fBwinfo containing\fR $x $y]
if {$win eq ""} {
    puts "over no window"
} else {
    puts "over $win"
}
.CE

Changes to doc/wish.1.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
8
9
10
11
12
13
14

15
16

17
18
19

20
21
22

23
24

25
26
27
28

29
30
31

32
33
34
35

36
37
38
39
40
41
42
43
44
45
46

47
48
49
50

51
52
53
54
55
56
57







-
+

-



-



-


-




-



-




-











-




-







.TH wish 1 8.0 Tk "Tk Applications"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
wish \- Simple windowing shell
.SH SYNOPSIS
\fBwish\fR ?\fB\-encoding \fIname\fR? ?\fIfileName arg ...\fR?
\fBwish\fR ?\fB\-encoding \fIname\fR? ?\fIfileName arg arg ...\fR?
.SH OPTIONS
.\" OPTION: -encoding
.IP "\fB\-encoding \fIname\fR" 20
Specifies the encoding of the text stored in \fIfileName\fR.
This option is only recognized prior to the \fIfileName\fR argument.
.\" OPTION: -colormap
.IP "\fB\-colormap \fInew\fR" 20
Specifies that the window should have a new private colormap instead of
using the default colormap for the screen.
.\" OPTION: -display
.IP "\fB\-display \fIdisplay\fR" 20
Display (and screen) on which to display window.
.\" OPTION: -geometry
.IP "\fB\-geometry \fIgeometry\fR" 20
Initial geometry to use for window.  If this option is specified, its
value is stored in the \fBgeometry\fR global variable of the application's
Tcl interpreter.
.\" OPTION: -name
.IP "\fB\-name \fIname\fR" 20
Use \fIname\fR as the title to be displayed in the window, and
as the name of the interpreter for \fBsend\fR commands.
.\" OPTION: -sync
.IP "\fB\-sync\fR" 20
Execute all X server commands synchronously, so that errors
are reported immediately.  This will result in much slower
execution, but it is useful for debugging.
.\" OPTION: -use
.IP "\fB\-use\fR \fIid\fR" 20
Specifies that the main window for the application is to be embedded in
the window whose identifier is \fIid\fR, instead of being created as an
independent toplevel window.  \fIId\fR must be specified in the same
way as the value for the \fB\-use\fR option for toplevel widgets (i.e.
it has a form like that returned by the \fBwinfo id\fR command).
.RS
Note that on some platforms this will only work correctly if \fIid\fR
refers to a Tk \fBframe\fR or \fBtoplevel\fR that has its
\fB\-container\fR option enabled.
.RE
.\" OPTION: -visual
.IP "\fB\-visual \fIvisual\fR" 20
Specifies the visual to use for the window.
\fIVisual\fR may have any of the forms supported by the \fBTk_GetVisual\fR
procedure.
.\" OPTION: --
.IP "\fB\-\|\-\fR" 20
Pass all remaining arguments through to the script's \fBargv\fR
variable without interpreting them.
This provides a mechanism for passing arguments such as \fB\-name\fR
to a script instead of having \fBwish\fR interpret them.
.BE
.SH DESCRIPTION
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
113
114
115
116
117
118
119

120

121
122

123
124

125
126

127
128
129
130

131
132

133
134

135
136

137
138
139
140
141

142
143

144
145
146
147
148
149
150







-
+
-


-


-


-




-


-


-


-





-


-







.PP
The class of the application, which is used for purposes such as
specifying options with a \fBRESOURCE_MANAGER\fR property or .Xdefaults
file, is the same as its name except that the first letter is
capitalized.
.SH "VARIABLES"
.PP
\fBWish\fR sets the following global Tcl variables:
\fBWish\fR sets the following Tcl variables:
.\" VARIABLE: argc
.TP 15
\fBargc\fR
.
Contains a count of the number of \fIarg\fR arguments (0 if none),
not including the options described above.
.\" VARIABLE: argv
.TP 15
\fBargv\fR
.
Contains a Tcl list whose elements are the \fIarg\fR arguments
that follow a \fB\-\|\-\fR option or do not match any of the
options described in \fBOPTIONS\fR above, in order, or an empty string
if there are no such arguments.
.\" VARIABLE: argv0
.TP 15
\fBargv0\fR
.
Contains \fIfileName\fR if it was specified.
Otherwise, contains the name by which \fBwish\fR was invoked.
.\" VARIABLE: geometry
.TP 15
\fBgeometry\fR
.
If the \fB\-geometry\fR option is specified, \fBwish\fR copies its
value into this variable.  If the variable still exists after
\fIfileName\fR has been evaluated, \fBwish\fR uses the value of
the variable in a \fBwm geometry\fR command to set the main
window's geometry.
.\" VARIABLE: tcl_interactive
.TP 15
\fBtcl_interactive\fR
.
Contains 1 if \fBwish\fR is reading commands interactively (\fIfileName\fR
was not specified and standard input is a terminal-like
device), 0 otherwise.
.SH "SCRIPT FILES"
.PP
If you create a Tcl script in a file whose first line is
.CS

Changes to doc/wm.n.

8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216

217


218

219


220

221


222
223

224


225
226

227


228
229

230


231

232


233
234

235


236
237

238


239
240

241


242
243

244


245
246
247

248


249
250

251


252
253
254

255


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67

68
69
70
71
72
73

74
75
76
77
78
79

80
81
82
83

84
85
86
87

88
89
90
91
92
93
94
95
96

97





























98
99
100
101
102
103

104
105
106
107

108










































109
110


111
112

113
114
115
116
117
118
119
120
121
122

123

124
125
126
127
128
129
130
131
132
133
134

135
136
137
138

139
140
141
142

143
144
145
146
147

148
149
150
151
152

153
154
155
156
157

158
159
160
161

162
163
164
165
166

167
168
169
170
171

172
173
174
175
176

177
178
179
180
181

182
183
184
185
186
187

188
189
190
191
192

193
194
195
196
197
198

199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234







-
+












-

















-
















-







-






-






-




-




-









-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-




-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+
-










-
+
-










+
-
+
+

+
-
+
+

+
-
+
+


+
-
+
+


+
-
+
+


+
-
+
+

+
-
+
+


+
-
+
+


+
-
+
+


+
-
+
+


+
-
+
+



+
-
+
+


+
-
+
+



+
-
+
+



-











-













-







.TH wm n 8.5 Tk "Tk Built-In Commands"
.so man.macros
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
wm \- Communicate with window manager
.SH SYNOPSIS
\fBwm\fI option window \fR?\fIargs\fR?
\fBwm\fR \fIoption window \fR?\fIargs\fR?
.BE
.SH DESCRIPTION
.PP
The \fBwm\fR command is used to interact with window managers in
order to control such things as the title for a window, its geometry,
or the increments in terms of which it may be resized.  The \fBwm\fR
command can take any of a number of different forms, depending on
the \fIoption\fR argument.  All of the forms expect at least one
additional argument, \fIwindow\fR, which must be the path name of a
top-level window.
.PP
The legal forms for the \fBwm\fR command are:
.\" METHOD: aspect
.TP
\fBwm aspect \fIwindow\fR ?\fIminNumer minDenom maxNumer maxDenom\fR?
.
If \fIminNumer\fR, \fIminDenom\fR, \fImaxNumer\fR, and \fImaxDenom\fR
are all specified, then they will be passed to the window manager
and the window manager should use them to enforce a range of
acceptable aspect ratios for \fIwindow\fR.  The aspect ratio of
\fIwindow\fR (width/length) will be constrained to lie
between \fIminNumer\fR/\fIminDenom\fR and \fImaxNumer\fR/\fImaxDenom\fR.
If \fIminNumer\fR etc. are all specified as empty strings, then
any existing aspect ratio restrictions are removed.
If \fIminNumer\fR etc. are specified, then the command returns an
empty string.  Otherwise, it returns
a Tcl list containing four elements, which are the current values
of \fIminNumer\fR, \fIminDenom\fR, \fImaxNumer\fR, and \fImaxDenom\fR
(if no aspect restrictions are in effect, then an empty string is
returned).
.\" METHOD: attributes
.TP
\fBwm attributes \fIwindow\fR
.TP
\fBwm attributes \fIwindow\fR ?\fBoption\fR?
.TP
\fBwm attributes \fIwindow\fR ?\fBoption value option value...\fR?
.
This subcommand returns or sets platform specific attributes associated
with a window. The first form returns a list of the platform specific
flags and their values. The second form returns the value for the
specific option. The third form sets one or more of the values. The
values are as follows:
.RS
.PP
All platforms support the following attributes (though X11 users
should see the notes below):
.\" OPTION: -alpha
.TP
\fB\-alpha\fR
.
Specifies the alpha transparency level of the toplevel. It accepts a value
from \fB0.0\fR (fully transparent) to \fB1.0\fR (opaque).  Values outside that
range will be constrained.  Where not supported, the \fB\-alpha\fR value
remains at \fB1.0\fR.
.\" OPTION: -fullscreen
.TP
\fB\-fullscreen\fR
.
Places the window in a mode that takes up the entire screen, has no
borders, and covers the general use area (i.e. Start menu and taskbar on
Windows, dock and menubar on OSX, general window decorations on X11).
.\" OPTION: -topmost
.TP
\fB\-topmost\fR
.
Specifies whether this is a topmost window (displays above all other windows).
.PP
On Windows, the following attributes may be set.
.\" OPTION: -disabled
.TP
\fB\-disabled\fR
.
Specifies whether the window is in a disabled state.
.\" OPTION: -toolwindow
.TP
\fB\-toolwindow\fR
.
Specifies a toolwindow style window (as defined in the MSDN).
.\" OPTION: -transparentcolor
.TP
\fB\-transparentcolor\fR
.
Specifies the transparent color index of the toplevel.  It takes any color
value accepted by \fBTk_GetColor\fR.  If the empty string is specified
(default), no transparent color is used.  This is supported on Windows
2000/XP+.  Where not supported, the \fB\-transparentcolor\fR value remains
at \fB{}\fR.
.PP
On MacOS, the following attributes may be set.
On Mac OS X, the following attributes may be set.
.\" OPTION: -appearance
.TP
\fB\-appearance\fR
.
Specifies whether the window is rendered in "dark mode".  Allowed
values are \fBauto\fR, \fBaqua\fR and \fBdarkaqua\fR.  If the setting
is auto then the appearance of the window is controlled by the
System Settings.
.\" OPTION: -class
.TP
\fB\-class\fR
.
Specifies whether the underlying Aqua window for a toplevel is an
object of the NSWindow class or the NSPanel class.  The two allowed
values for this option are \fBnswindow\fR and \fBnspanel\fR.  It is
not possible to change the class of the underlying Aqua window once
that window has been instantiated, and attempting to do that is an
error.  However it is allowed to set this option for a pathname that
does not correspond to an existing window.  Doing that causes the
class name to be cached for later use.  When a toplevel with that
pathname is eventually created, the cached class name will determine which
class is used for the underlying Aqua window.
.\" OPTION: -isdark
.TP
\fB\-isdark\fR
.
Returns a boolean value which is true if the window is currently in
dark mode.
.\" OPTION: -modified
.TP
\fB\-modified\fR
.
Specifies the modification state of the window (determines whether the
window close widget contains the modification indicator and whether the
proxy icon is draggable).
.\" OPTION: -notify
.TP
\fB\-notify\fR
.
Specifies process notification state (bouncing of the application dock icon).
.\" OPTION: -stylemask
.TP
\fB\-stylemask\fR
.
Specifies an integer to be assigned as the styleMask of the underlying
Aqua window.  (See the Apple documentation for styleMask property of
the NSWindow class.) The value of this option should be a list of
bitnames.  Each bit named in the list will be set to 1, and all other
bits will be set to 0.  The allowed bitnames are: \fBtitled\fR,
\fBclosable\fR, \fBminiaturizable\fR, \fBresizable\fR,
\fBfullsizecontentview\fR, \fBdocmodal\fR, \fButility\fR,
\fBnonactivatingpanel\fR, and \fBHUDwindow\fR.  Note that a side
effect of setting the fullsizecontentview bit is that the window title
bar becomes transparent.
.\" OPTION: -tabbingid
.TP
\fB\-tabbingid\fR
.
Controls how tabbed toplevel windows are grouped together.  Two tabs
in the same group must correspond to toplevels with the same
tabbingid, which can be an arbitrary UTF8 string.  In the Tk
implementation, changing the tabbingid of a toplevel in a tab group
will cause it to be moved into a different group, in which all tabs
have the new tabbingid or, if the new tabbingid is unique, to become
a normal non-tabbed toplevel.   It is allowed to set the tabbingid before the
toplevel is created.  If the pathname provided in the command does not
correspond to a toplevel, the value will be cached and used later when
the toplevel is actually created.
.\" OPTION: -tabbingmode
.TP
\fB\-tabbingmode\fR
.
Controls whether a toplevel can be opened as a tab within a tab group.
The allowed values are \fBauto\fR, \fBpreferred\fR or
\fBdisallowed\fR.  A toplevel can be opened as a tab in exactly two
situations: if its tabbingmode is \fBpreferred\fR; or if its
tabbingmode is \fBauto\fR and the user has selected "prefer tabs when
opening documents" in the Desktop and Dock panel of the System
Settings application.  It is allowed to set the tabbingmode before the
toplevel is created.  If the pathname provided in the command does not
correspond to a toplevel, the value will be cached and used later when
the toplevel is actually created.
.\" OPTION: -titlepath
.TP
\fB\-titlepath\fR
.
Specifies the path of the file referenced as the window proxy icon
(which can be dragged and dropped in lieu of the file's finder icon).
Specifies the path of the file referenced as the window proxy icon (which
can be dragged and dropped in lieu of the file's finder icon).
.\" OPTION: -transparent
.TP
\fB\-transparent\fR
.
Makes the window content area transparent and turns off the window shadow. For
the transparency to be effective, the toplevel background needs to be set to a
color with some alpha, e.g.
.QW systemTransparent .
.PP
On X11, the following attributes may be set. These are not supported by all
window managers, and will have no effect under older WMs.
.\" See https://www.freedesktop.org/wiki/Specifications/wm-spec/
.\" See http://www.freedesktop.org/Standards/wm-spec
.\" OPTION: -type
.TP
\fB\-type\fR
.VS 8.6
Requests that the window should be interpreted by the window manager as being
of the specified type(s). This may cause the window to be decorated in a
different way or otherwise managed differently, though exactly what happens is
entirely up to the window manager. A list of types may be used, in order of
preference. The following values are mapped to constants defined in the EWMH
specification (using others is possible, but not advised):
.RS
.TP
.IP \fBdesktop\fR
\fBdesktop\fR
.
indicates a desktop feature,
.TP
.IP \fBdock\fR
\fBdock\fR
.
indicates a dock/panel feature,
.TP
.IP \fBtoolbar\fR
\fBtoolbar\fR
.
indicates a toolbar window that should be acting on behalf of another window,
as indicated with \fBwm transient\fR,
.TP
.IP \fBmenu\fR
\fBmenu\fR
.
indicates a torn-off menu that should be acting on behalf of another window,
as indicated with \fBwm transient\fR,
.TP
.IP \fButility\fR
\fButility\fR
.
indicates a utility window (e.g., palette or toolbox) that should be acting on
behalf of another window, as indicated with \fBwm transient\fR,
.TP
.IP \fBsplash\fR
\fBsplash\fR
.
indicates a splash screen, displayed during application start up,
.TP
.IP \fBdialog\fR
\fBdialog\fR
.
indicates a general dialog window, that should be acting on behalf of another
window, as indicated with \fBwm transient\fR,
.TP
.IP \fBdropdown_menu\fR
\fBdropdown_menu\fR
.
indicates a menu summoned from a menu bar, which should usually also be set to
be override-redirected (with \fBwm overrideredirect\fR),
.TP
.IP \fBpopup_menu\fR
\fBpopup_menu\fR
.
indicates a popup menu, which should usually also be set to be
override-redirected (with \fBwm overrideredirect\fR),
.TP
.IP \fBtooltip\fR
\fBtooltip\fR
.
indicates a tooltip window, which should usually also be set to be
override-redirected (with \fBwm overrideredirect\fR),
.TP
.IP \fBnotification\fR
\fBnotification\fR
.
indicates a window that provides a background notification of some event,
which should usually also be set to be override-redirected (with \fBwm
overrideredirect\fR),
.TP
.IP \fBcombo\fR
\fBcombo\fR
.
indicates the drop-down list of a combobox widget, which should usually also
be set to be override-redirected (with \fBwm overrideredirect\fR),
.TP
.IP \fBdnd\fR
\fBdnd\fR
.
indicates a window that represents something being dragged, which should
usually also be set to be override-redirected (with
\fBwm overrideredirect\fR),
.TP
.IP \fBnormal\fR
\fBnormal\fR
.
indicates a window that has no special interpretation.
.RE
.VE 8.6
.\" OPTION: -zoomed
.TP
\fB\-zoomed\fR
.
Requests that the window should be maximized. This is the same as \fBwm state
zoomed\fR on Windows and Mac OS X.
.PP
On X11, changes to window attributes are performed asynchronously. Querying
the value of an attribute returns the current state, which will not be the
same as the value most recently set if the window manager has not yet
processed the request or if it does not support the attribute.
.RE
.\" METHOD: client
.TP
\fBwm client \fIwindow\fR ?\fIname\fR?
.
If \fIname\fR is specified, this command stores \fIname\fR (which
should be the name of
the host on which the application is executing) in \fIwindow\fR's
\fBWM_CLIENT_MACHINE\fR property for use by the window manager or
session manager.
The command returns an empty string in this case.
If \fIname\fR is not specified, the command returns the last name
set in a \fBwm client\fR command for \fIwindow\fR.
If \fIname\fR is specified as an empty string, the command deletes the
\fBWM_CLIENT_MACHINE\fR property from \fIwindow\fR.
.\" METHOD: colormapwindows
.TP
\fBwm colormapwindows \fIwindow\fR ?\fIwindowList\fR?
.
This command is used to manipulate the \fBWM_COLORMAP_WINDOWS\fR
property, which provides information to the window managers about
windows that have private colormaps.
.RS
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324







-












-










-




















-








-









-







If \fBwm colormapwindows\fR is not invoked, Tk will automatically set
the property for each top-level window to all the internal windows
whose colormaps differ from their parents, followed by the top-level
itself;  the order of the internal windows is undefined.
See the ICCCM documentation for more information on the
\fBWM_COLORMAP_WINDOWS\fR property.
.RE
.\" METHOD: command
.TP
\fBwm command \fIwindow\fR ?\fIvalue\fR?
.
If \fIvalue\fR is specified, this command stores \fIvalue\fR in \fIwindow\fR's
\fBWM_COMMAND\fR property for use by the window manager or
session manager and returns an empty string.
\fIValue\fR must have proper list structure;  the elements should
contain the words of the command used to invoke the application.
If \fIvalue\fR is not specified then the command returns the last value
set in a \fBwm command\fR command for \fIwindow\fR.
If \fIvalue\fR is specified as an empty string, the command
deletes the \fBWM_COMMAND\fR property from \fIwindow\fR.
.\" METHOD: deiconify
.TP
\fBwm deiconify \fIwindow\fR
.
Arrange for \fIwindow\fR to be displayed in normal (non-iconified) form.
This is done by mapping the window.  If the window has never been
mapped then this command will not map the window, but it will ensure
that when the window is first mapped it will be displayed
in de-iconified form.  On Windows, a deiconified window will also be
raised and be given the focus (made the active window).
Returns an empty string.
.\" METHOD: focusmodel
.TP
\fBwm focusmodel \fIwindow\fR ?\fBactive\fR|\fBpassive\fR?
.
If \fBactive\fR or \fBpassive\fR is supplied as an optional argument
to the command, then it specifies the focus model for \fIwindow\fR.
In this case the command returns an empty string.  If no additional
argument is supplied, then the command returns the current focus
model for \fIwindow\fR.
.RS
.PP
An \fBactive\fR focus model means that \fIwindow\fR will claim the
input focus for itself or its descendants, even at times when
the focus is currently in some other application.  \fBPassive\fR means that
\fIwindow\fR will never claim the focus for itself:  the window manager
should give the focus to \fIwindow\fR at appropriate times.  However,
once the focus has been given to \fIwindow\fR or one of its descendants,
the application may re-assign the focus among \fIwindow\fR's descendants.
The focus model defaults to \fBpassive\fR, and Tk's \fBfocus\fR command
assumes a passive model of focusing.
.RE
.\" METHOD: forget
.TP
\fBwm forget \fIwindow\fR
.
The \fIwindow\fR will be unmapped from the screen and will no longer
be managed by \fBwm\fR.  Windows created with the \fBtoplevel\fR
command will be treated like \fBframe\fR windows once they are no
longer managed by \fBwm\fR, however, the \fB\-menu\fR configuration will be
remembered and the menus will return once the widget is managed again.
.\" METHOD: frame
.TP
\fBwm frame \fIwindow\fR
.
If \fIwindow\fR has been reparented by the window manager into a
decorative frame, the command returns the platform specific window
identifier for the outermost frame that contains \fIwindow\fR (the
window whose parent is the root or virtual root).  If \fIwindow\fR
has not been reparented by the window manager then the command returns
the platform specific window identifier for \fIwindow\fR.
.\" METHOD: geometry
.TP
\fBwm geometry \fIwindow\fR ?\fInewGeometry\fR?
.
If \fInewGeometry\fR is specified, then the geometry of \fIwindow\fR
is changed and an empty string is returned.  Otherwise the current
geometry for \fIwindow\fR is returned (this is the most recent
geometry specified either by manual resizing or
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
355
356
357
358
359
360
361

362
363
364
365
366
367
368







-







actual size and location of \fIwindow\fR, whereas \fBwm geometry\fR allows
both setting and querying of the \fIwindow manager\fR's understanding of the
size and location of the window. This can vary significantly, for example to
reflect the addition of decorative elements to \fIwindow\fR such as title
bars, and window managers are not required to precisely follow the requests
made through this command.
.RE
.\" METHOD: grid
.TP
\fBwm grid \fIwindow\fR ?\fIbaseWidth baseHeight widthInc heightInc\fR?
.
This command indicates that \fIwindow\fR is to be managed as a
gridded window.
It also specifies the relationship between grid units and pixel units.
\fIBaseWidth\fR and \fIbaseHeight\fR specify the number of grid
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
387
388
389
390
391
392
393

394
395
396
397

398
399
400
401
402
403
404
405
406
407
408

































409
410
411
412
413
414
415







-
+



-











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







.PP
Otherwise the return value is a Tcl list containing
four elements corresponding to the current \fIbaseWidth\fR,
\fIbaseHeight\fR, \fIwidthInc\fR, and \fIheightInc\fR;  if
\fIwindow\fR is not currently gridded, then an empty string
is returned.
.PP
Note that this command should not be needed very often, since the
Note: this command should not be needed very often, since the
\fBTk_SetGrid\fR library procedure and the \fBsetGrid\fR option
provide easier access to the same functionality.
.RE
.\" METHOD: group
.TP
\fBwm group \fIwindow\fR ?\fIpathName\fR?
.
If \fIpathName\fR is specified, it gives the path name for the leader of
a group of related windows.  The window manager may use this information,
for example, to unmap all of the windows in a group when the group's
leader is iconified.  \fIPathName\fR may be specified as an empty string to
remove \fIwindow\fR from any group association.  If \fIpathName\fR is
specified then the command returns an empty string;  otherwise it
returns the path name of \fIwindow\fR's current group leader, or an empty
string if \fIwindow\fR is not part of any group.
.\" METHOD: iconbadge
.TP
\fBwm iconbadge \fIwindow badge\fR
.
Sets a badge for the icon of the \fIwindow\fR. The badge can be a positive
integer number, for instance the number of new or unread messages, or
an exclamation point denoting attention needed. If the badge is an empty
string, the badge image is removed from the application icon. Managing
these changes through bindings, such as <FocusIn>, is the responsibility
of the developer.
.RS
.PP
On X11, for this command to work,
the variable \fB::tk::icons::base_icon($window)\fR must be set to the image
that is being used for the window icon of $window. On Windows and X11, the
iconphoto images work best at 32x32 or a similar dimension, as
the badge images are provided by Tk and drawn to overlay the icon images
using native (Windows) API's or Tk rendering. On macOS, the icon badge is
rendered by a system API and is not provided by Tk. The icon image itself
should be higher-resolution, preferably 512 pixels, to avoid being blurry.
.PP
The icon badge is intended for display in the Dock (macOS), taskbar
(Windows) or app panel (X11). On macOS, the last badge called will be
displayed in the Dock, regardless of how many different icon badges may be
assigned to different windows. On Windows, the taskbar display depends on
whether the taskbar buttons are combined or not (this is an OS setting
available to the user): if combined, the behavior is the same as on macOS,
otherwise each button in the taskbar shows the badge it was assigned.
Badge display on macOS is configured in the system preferences. App
panel display behavior on X11 will depend on the window manager and/or
desktop environment.
.RE
.\" METHOD: iconbitmap
.TP
\fBwm iconbitmap \fIwindow\fR ?\fIbitmap\fR?
.
If \fIbitmap\fR is specified, then it names a bitmap in the standard
forms accepted by Tk (see the \fBTk_GetBitmap\fR manual entry for details).
This bitmap is passed to the window manager to be displayed in
\fIwindow\fR's icon, and the command returns an empty string.  If
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590
591
592

593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632

633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
431
432
433
434
435
436
437

438
439
440
441
442
443

444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488

489

490

491






492

493
494
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519

520


521
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579

580
581
582
583
584
585
586







-






-















-











-














-
+




-
+
-

-
+
-
-
-
-
-
-

-










-

















-
+
-
-









-















-















-




















-







any file which contains a valid
Windows icon is also accepted (usually .ico or .icr files), or any
file for which the shell has assigned an icon.  Tcl will
first test if the file contains an icon, then if it has an assigned
icon, and finally, if that fails, test for
a bitmap.
.RE
.\" METHOD: iconify
.TP
\fBwm iconify \fIwindow\fR
.
Arrange for \fIwindow\fR to be iconified.  It \fIwindow\fR has not
yet been mapped for the first time, this command will arrange for
it to appear in the iconified state when it is eventually mapped.
.\" METHOD: iconmask
.TP
\fBwm iconmask \fIwindow\fR ?\fIbitmap\fR?
.
If \fIbitmap\fR is specified, then it names a bitmap in the standard
forms accepted by Tk (see the \fBTk_GetBitmap\fR manual entry for details).
This bitmap is passed to the window manager to be used as a mask
in conjunction with the \fBiconbitmap\fR option:  where the mask
has zeroes no icon will be displayed;  where it has ones, the bits
from the icon bitmap will be displayed.  If
an empty string is specified for \fIbitmap\fR then any current icon
mask is cancelled for \fIwindow\fR (this is equivalent to specifying
a bitmap of all ones).  If \fIbitmap\fR is specified
then the command returns an empty string.  Otherwise it
returns the name of the current icon mask associated with
\fIwindow\fR, or an empty string if no mask is in effect.
.\" METHOD: iconname
.TP
\fBwm iconname \fIwindow\fR ?\fInewName\fR?
.
If \fInewName\fR is specified, then it is passed to the window
manager;  the window manager should display \fInewName\fR inside
the icon associated with \fIwindow\fR.  In this case an empty
string is returned as result.  If \fInewName\fR is not specified
then the command returns the current icon name for \fIwindow\fR,
or an empty string if no icon name has been specified (in this
case the window manager will normally display the window's title,
as specified with the \fBwm title\fR command).
.\" METHOD: iconphoto
.TP
\fBwm iconphoto \fIwindow\fR ?\fB\-default\fR? \fIimage1\fR ?\fIimage2 ...\fR?
.
Sets the titlebar icon for \fIwindow\fR based on the named photo images.
If \fB\-default\fR is specified, this is applied to all future created
toplevels as well.  The data in the images is taken as a snapshot at the
time of invocation.  If the images are later changed, this is not
reflected to the titlebar icons.  Multiple images are accepted to allow
different images sizes (e.g., 16x16 and 32x32) to be provided. The window
manager may scale provided icons to an appropriate size.
.RS
.PP
On Windows, the images are packed into a Windows icon structure.
This will override an ico specified to \fBwm iconbitmap\fR, and
vice versa. This command sets the taskbar icon for the window.
vice versa.
.PP
On X, the images are arranged into the _NET_WM_ICON X property, which
most modern window managers support.  A \fBwm iconbitmap\fR may exist
simultaneously.  It is recommended to use not more than 2 icons, placing
the larger icon first. This command also sets the panel icon for the
the larger icon first.
application if the window manager or desktop environment supports it.
.PP
On Macintosh, the first image called is loaded into an OSX-native icon
On Macintosh, this currently does nothing.
format, and becomes the application icon in dialogs, the Dock, and
other contexts. At the
script level the command will accept only the first image passed in the
parameters as support for multiple sizes/resolutions on macOS is outside Tk's
scope. Developers should use the largest icon they can support
(preferably 512 pixels) to ensure smooth rendering on the Mac.
.RE
.\" METHOD: iconposition
.TP
\fBwm iconposition \fIwindow\fR ?\fIx y\fR?
.
If \fIx\fR and \fIy\fR are specified, they are passed to the window
manager as a hint about where to position the icon for \fIwindow\fR.
In this case an empty string is returned.  If \fIx\fR and \fIy\fR are
specified as empty strings then any existing icon position hint is cancelled.
If neither \fIx\fR nor \fIy\fR is specified, then the command returns
a Tcl list containing two values, which are the current icon position
hints (if no hints are in effect then an empty string is returned).
.\" METHOD: iconwindow
.TP
\fBwm iconwindow \fIwindow\fR ?\fIpathName\fR?
.
If \fIpathName\fR is specified, it is the path name for a window to
use as icon for \fIwindow\fR: when \fIwindow\fR is iconified then
\fIpathName\fR will be mapped to serve as icon, and when \fIwindow\fR
is de-iconified then \fIpathName\fR will be unmapped again.  If
\fIpathName\fR is specified as an empty string then any existing
icon window association for \fIwindow\fR will be cancelled.  If
the \fIpathName\fR argument is specified then an empty string is
returned.  Otherwise the command returns the path name of the
current icon window for \fIwindow\fR, or an empty string if there
is no icon window currently specified for \fIwindow\fR.
Button press events are disabled for \fIwindow\fR as long as it is
an icon window;  this is needed in order to allow window managers to
.QW own
those events.
Note that not all window managers support the notion of an icon window, and
Note: not all window managers support the notion of an icon window.
the concept is entirely meaningless on non-X11 platforms.
.\" METHOD: manage
.TP
\fBwm manage \fIwidget\fR
.
The \fIwidget\fR specified will become a stand alone top-level window.  The
window will be decorated with the window managers title bar, etc. Only
\fIframe\fR, \fIlabelframe\fR and \fItoplevel\fR widgets can be used
with this command. Attempting to pass any other widget type will raise
an error. Attempting to manage a \fItoplevel\fR widget is benign and
achieves nothing. See also \fBGEOMETRY MANAGEMENT\fR.
.\" METHOD: maxsize
.TP
\fBwm maxsize \fIwindow\fR ?\fIwidth height\fR?
.
If \fIwidth\fR and \fIheight\fR are specified, they give
the maximum permissible dimensions for \fIwindow\fR.
For gridded windows the dimensions are specified in
grid units;  otherwise they are specified in pixel units.
The window manager will restrict the window's dimensions to be
less than or equal to \fIwidth\fR and \fIheight\fR.
If \fIwidth\fR and \fIheight\fR are
specified, then the command returns an empty string.  Otherwise
it returns a Tcl list with two elements, which are the
maximum width and height currently in effect.
The maximum size defaults to the size of the screen.
See the sections on geometry management below for more information.
.\" METHOD: minsize
.TP
\fBwm minsize \fIwindow\fR ?\fIwidth height\fR?
.
If \fIwidth\fR and \fIheight\fR are specified, they give the
minimum permissible dimensions for \fIwindow\fR.
For gridded windows the dimensions are specified in
grid units;  otherwise they are specified in pixel units.
The window manager will restrict the window's dimensions to be
greater than or equal to \fIwidth\fR and \fIheight\fR.
If \fIwidth\fR and \fIheight\fR are
specified, then the command returns an empty string.  Otherwise
it returns a Tcl list with two elements, which are the
minimum width and height currently in effect.
The minimum size defaults to one pixel in each dimension.
See the sections on geometry management below for more information.
.\" METHOD: overrideredirect
.TP
\fBwm overrideredirect \fIwindow\fR ?\fIboolean\fR?
.
If \fIboolean\fR is specified, it must have a proper boolean form and
the override-redirect flag for \fIwindow\fR is set to that value.
If \fIboolean\fR is not specified then \fB1\fR or \fB0\fR is
returned to indicate whether or not the override-redirect flag
is currently set for \fIwindow\fR.
Setting the override-redirect flag for a window causes
it to be ignored by the window manager;  among other things, this means
that the window will not be reparented from the root window into a
decorative frame and the user will not be able to manipulate the
window using the normal window manager mechanisms.
.RS
.PP
Note that the override-redirect flag is only guaranteed to be taken notice of
when the window is first mapped or when mapped after the state is changed from
withdrawn to normal. Some, but not all, platforms will take notice at
additional times.
.RE
.\" METHOD: positionfrom
.TP
\fBwm positionfrom \fIwindow\fR ?\fIwho\fR?
.
If \fIwho\fR is specified, it must be either \fBprogram\fR or
\fBuser\fR, or an abbreviation of one of these two.  It indicates
whether \fIwindow\fR's current position was requested by the
program or by the user.  Many window managers ignore program-requested
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726





727
728
729
730



731
732
733

734
735
736
737

738
739
740
741
742
743
744
745


746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762








763
764
765









766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853










854
855
856


857
858
859


860
861
862
863
864
865
866
867
868
869
870
871

872
873
874
875
876
877
878
594
595
596
597
598
599
600

601
602
603




604
605
606
607
608




609
610
611



612




613








614
615

















616
617
618
619
620
621
622
623
624


625
626
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702
703

704

705
706









707
708
709
710
711
712
713
714
715
716



717
718



719
720

721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738







-



-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+

-
















-


















-














-












-









-

-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-










-
+







source of the window's current position, or an empty string if
no source has been specified yet.  Most window managers interpret
.QW "no source"
as equivalent to \fBprogram\fR.
Tk will automatically set the position source to \fBuser\fR
when a \fBwm geometry\fR command is invoked, unless the source has
been set explicitly to \fBprogram\fR.
.\" METHOD: protocol
.TP
\fBwm protocol \fIwindow\fR ?\fIname\fR? ?\fIcommand\fR?
.
This command is used to manage window manager protocols. The \fIname\fR
argument in the \fBwm protocol\fR command is the name of an atom corresponding
to a window manager protocol.  Examples include \fBWM_DELETE_WINDOW\fR or
\fBWM_SAVE_YOURSELF\fR or \fBWM_TAKE_FOCUS\fR.
This command is used to manage window manager protocols such as
\fBWM_DELETE_WINDOW\fR.
\fIName\fR is the name of an atom corresponding to a window manager
protocol, such as \fBWM_DELETE_WINDOW\fR or \fBWM_SAVE_YOURSELF\fR
or \fBWM_TAKE_FOCUS\fR.
.RS
.PP
A \fIwindow manager protocol\fR is a class of messages sent from a window
manager to a Tk application outside of the normal event processing system. The
If both \fIname\fR and \fIcommand\fR are specified, then \fIcommand\fR
is associated with the protocol specified by \fIname\fR.
\fIName\fR will be added to \fIwindow\fR's \fBWM_PROTOCOLS\fR
main example is the \fBWM_DELETE_WINDOW\fR protocol; these messages are sent
when the user clicks the close widget in the title bar of a window.  Handlers
for window manager protocols are installed with the \fBwm protocol\fR
property to tell the window manager that the application has a
command. As a rule, if no handler has been installed for a protocol by the
\fBwm protocol\fR command then all messages of that protocol are ignored. The
\fBWM_DELETE_WINDOW\fR protocol is an exception to this rule. At start-up Tk
installs a handler for this protocol, which responds by destroying the
protocol handler for \fIname\fR, and \fIcommand\fR will
window. The \fBwm protocol\fR command can be used to replace this default
handler by one which responds differently.
.RE
.RS
.PP
The list of available window manager protocols depends on the window manager,
but all window managers supported by Tk provide \fBWM_DELETE_WINDOW\fR. On the
Windows platform, a \fBWM_SAVE_YOURSELF\fR message is sent on user logout
be invoked in the future whenever the window manager sends a
message to the client for that protocol.
or system restart.
.RE
.RS
.PP
If both \fIname\fR and \fIcommand\fR are specified, then \fIcommand\fR becomes
the handler for the protocol specified by \fIname\fR. The atom for \fIname\fR
will be added to \fIwindow\fR's \fBWM_PROTOCOLS\fR property to tell the window
manager that the application has a handler for the protocol specified by
\fIname\fR, and \fIcommand\fR will be invoked in the future whenever the
window manager sends a message of that protocol to the Tk application.  In
this case the \fBwm protocol\fR command returns an empty string.  If
\fIname\fR is specified but \fIcommand\fR is not, then the current handler for
\fIname\fR is returned, or an empty string if there is no handler defined for
\fIname\fR (as a special case, the default handler for \fBWM_DELETE_WINDOW\fR
is not returned).  If \fIcommand\fR is specified as an empty string then the
atom for \fIname\fR is removed from the \fBWM_PROTOCOLS\fR property of
\fIwindow\fR and the handler is destroyed; an empty string is returned.
In this case the command returns an empty string.
If \fIname\fR is specified but \fIcommand\fR is not, then the current
command for \fIname\fR is returned, or an empty string if there
is no handler defined for \fIname\fR.
If \fIcommand\fR is specified as an empty string then the current
handler for \fIname\fR is deleted and it is removed from the
\fBWM_PROTOCOLS\fR property on \fIwindow\fR;  an empty string is
returned.
Lastly, if neither \fIname\fR nor \fIcommand\fR is specified, the
\fBwm protocol\fR command returns a list of all of the protocols for which
handlers are currently defined for \fIwindow\fR.
command returns a list of all the protocols for which handlers
are currently defined for \fIwindow\fR.
.RS
.PP
Tk always defines a protocol handler for \fBWM_DELETE_WINDOW\fR, even if
you have not asked for one with \fBwm protocol\fR.
If a \fBWM_DELETE_WINDOW\fR message arrives when you have not defined
a handler, then Tk handles the message by destroying the window for
which it was received.
.RE
.\" METHOD: resizable
.TP
\fBwm resizable \fIwindow\fR ?\fIwidth height\fR?
.
This command controls whether or not the user may interactively
resize a top-level window.  If \fIwidth\fR and \fIheight\fR are
specified, they are boolean values that determine whether the
width and height of \fIwindow\fR may be modified by the user.
In this case the command returns an empty string.
If \fIwidth\fR and \fIheight\fR are omitted then the command
returns a list with two 0/1 elements that indicate whether the
width and height of \fIwindow\fR are currently resizable.
By default, windows are resizable in both dimensions.
If resizing is disabled, then the window's size will be the size
from the most recent interactive resize or \fBwm geometry\fR
command.  If there has been no such operation then
the window's natural size will be used.
.\" METHOD: sizefrom
.TP
\fBwm sizefrom \fIwindow\fR ?\fIwho\fR?
.
If \fIwho\fR is specified, it must be either \fBprogram\fR or
\fBuser\fR, or an abbreviation of one of these two.  It indicates
whether \fIwindow\fR's current size was requested by the
program or by the user.  Some window managers ignore program-requested
sizes and ask the user to manually size the window;  if
\fBuser\fR is specified then the window manager should give the
window its specified size without asking the user for assistance.
If \fIwho\fR is specified as an empty string, then the current size
source is cancelled.
If \fIwho\fR is specified, then the command returns an empty string.
Otherwise it returns \fBuser\fR or \fBwindow\fR to indicate the
source of the window's current size, or an empty string if
no source has been specified yet.  Most window managers interpret
.QW "no source"
as equivalent to \fBprogram\fR.
.\" METHOD: stackorder
.TP
\fBwm stackorder \fIwindow\fR ?\fBisabove\fR|\fBisbelow \fIwindow\fR?
.
The \fBstackorder\fR command returns a list of toplevel windows
in stacking order, from lowest to highest. When a single toplevel
window is passed, the returned list recursively includes all of the
window's children that are toplevels. Only those toplevels
that are currently mapped to the screen are returned.
The \fBstackorder\fR command can also be used to determine if one
toplevel is positioned above or below a second toplevel.
When two window arguments separated by either \fBisabove\fR or
\fBisbelow\fR are passed, a boolean result indicates whether
or not the first window is currently above or below the second
window in the stacking order.
.\" METHOD: state
.TP
\fBwm state \fIwindow\fR ?newstate?
.
If \fInewstate\fR is specified, the window will be set to the new state,
otherwise it returns the current state of \fIwindow\fR: either
\fBnormal\fR, \fBiconic\fR, \fBwithdrawn\fR, \fBicon\fR, or (Windows and Mac
OS X only) \fBzoomed\fR.
The difference between \fBiconic\fR and \fBicon\fR is that
\fBiconic\fR refers to a window that has been iconified (e.g., with the
\fBwm iconify\fR command) while \fBicon\fR refers to a window whose only
purpose is to serve as the icon for some other window (via the \fBwm
iconwindow\fR command).  The \fBicon\fR state cannot be set.
.\" METHOD: title
.TP
\fBwm title \fIwindow\fR ?\fIstring\fR?
.
If \fIstring\fR is specified, then it will be passed to the window
manager for use as the title for \fIwindow\fR (the window manager
should display this string in \fIwindow\fR's title bar).  In this
case the command returns an empty string.  If \fIstring\fR is not
specified then the command returns the current title for the
\fIwindow\fR.  The title for a window defaults to its name.
.\" METHOD: transient
.TP
\fBwm transient \fIwindow\fR ?\fIcontainer\fR?
\fBwm transient \fIwindow\fR ?\fImaster\fR?
.
If \fIcontainer\fR is specified, then the window manager is informed that
\fIwindow\fR is a transient window (e.g. pull-down menu) working on
behalf of \fIcontainer\fR (where \fIcontainer\fR is the path name for a
top-level window).  If \fIcontainer\fR is specified as an empty string
then \fIwindow\fR is marked as not being a transient window any more.
Otherwise the command returns the path name of \fIwindow\fR's current
container, or an empty string if \fIwindow\fR is not currently a
transient window.  A transient window will mirror state changes in the
container and inherit the state of the container when initially mapped. The
If \fImaster\fR is specified, then the window manager is informed
that \fIwindow\fR is a transient window (e.g. pull-down menu) working
on behalf of \fImaster\fR (where \fImaster\fR is the
path name for a top-level window).  If \fImaster\fR
is specified as an empty string then \fIwindow\fR is marked as not
being a transient window any more.  Otherwise the command
returns the path name of \fIwindow\fR's current master, or an
empty string if \fIwindow\fR is not currently a transient window.
A transient window will mirror state changes in the master and
inherit the state of the master when initially mapped. It is an
directed graph with an edge from each transient to its container must be
acyclic.  In particular, it is an error to attempt to make a window a
transient of itself.  The window manager may also decorate a transient
error to attempt to make a window a transient of itself.
The window manager may also decorate a transient window differently, removing
window differently, removing some features normally present (e.g.,
minimize and maximize buttons) though this is entirely at the
discretion of the window manager.
some features normally present (e.g., minimize and maximize buttons) though
this is entirely at the discretion of the window manager.
.\" METHOD: widthdraw
.TP
\fBwm withdraw \fIwindow\fR
.
Arranges for \fIwindow\fR to be withdrawn from the screen.  This
causes the window to be unmapped and forgotten about by the window
manager.  If the window
has never been mapped, then this command
causes the window to be mapped in the withdrawn state.  Not all
window managers appear to know how to handle windows that are
mapped in the withdrawn state.
Note that it sometimes seems to be necessary to withdraw a
Note: it sometimes seems to be necessary to withdraw a
window and then re-map it (e.g. with \fBwm deiconify\fR) to get some
window managers to pay attention to changes in window attributes
such as group.
.SH "GEOMETRY MANAGEMENT"
.PP
By default a top-level window appears on the screen in its
\fInatural size\fR, which is the one determined internally by its
891
892
893
894
895
896
897
898

899
900
901
902
903
904
905
906
751
752
753
754
755
756
757

758

759
760
761
762
763
764
765







-
+
-







.PP
Normally a top-level window can have any size from one pixel in each
dimension up to the size of its screen.
However, you can use the \fBwm minsize\fR and \fBwm maxsize\fR commands
to limit the range of allowable sizes.
The range set by \fBwm minsize\fR and \fBwm maxsize\fR applies to
all forms of resizing, including the window's natural size as
well as manual resizes and the \fBwm geometry\fR command.  You
well as manual resizes and the \fBwm geometry\fR command.
can use any value accepted by \fBTk_GetPixels\fR.
You can also use the command \fBwm resizable\fR to completely
disable interactive resizing in one or both dimensions.
.PP
The \fBwm manage\fR and \fBwm forget\fR commands may be used to
perform undocking and docking of windows.  After a widget is managed
by \fBwm manage\fR command, all other \fBwm\fR subcommands may be used
with the widget.  Only widgets created using the toplevel command may
962
963
964
965
966
967
968
969
970
971
972




973
974
975
976
977
978
979
980
981
982


983
984
985
986
987
988
989
990
991

992
993
994
995
821
822
823
824
825
826
827




828
829
830
831
832
833
834
835
836
837
838
839


840
841
842
843
844
845
846
847
848
849

850

851
852
853







-
-
-
-
+
+
+
+








-
-
+
+








-
+
-



\fBwm resizable\fR .fixed 0 0
.CE
.PP
A simple dialog-like window, centred on the screen:
.CS
# Create and arrange the dialog contents.
toplevel .msg
label  .msg.l  -text "This is a very simple dialog demo."
button .msg.ok -text OK -default active -command {destroy .msg}
pack .msg.ok -side bottom -fill x
pack .msg.l  -expand 1    -fill both
label  .msg.l  \-text "This is a very simple dialog demo."
button .msg.ok \-text OK \-default active \-command {destroy .msg}
pack .msg.ok \-side bottom \-fill x
pack .msg.l  \-expand 1    \-fill both

# Now set the widget up as a centred dialog.

# But first, we need the geometry managers to finish setting
# up the interior of the dialog, for which we need to run the
# event loop with the widget hidden completely...
\fBwm withdraw\fR .msg
update
set x [expr {([winfo screenwidth .] - [winfo width .msg]) / 2}]
set y [expr {([winfo screenheight .] - [winfo height .msg]) / 2}]
set x [expr {([winfo screenwidth .]\-[winfo width .msg])/2}]
set y [expr {([winfo screenheight .]\-[winfo height .msg])/2}]
\fBwm geometry\fR  .msg +$x+$y
\fBwm transient\fR .msg .
\fBwm title\fR     .msg "Dialog demo"
\fBwm deiconify\fR .msg
.CE
.SH "SEE ALSO"
toplevel(n), winfo(n)
.SH KEYWORDS
aspect ratio, deiconify, focus model, geometry, grid, group, icon, iconify,
aspect ratio, deiconify, focus model, geometry, grid, group, icon, iconify, increments, position, size, title, top-level window, units, window manager
increments, position, size, title, top-level window, units, window manager
'\" Local Variables:
'\" mode: nroff
'\" End:

Changes to generic/ks_names.h.

1
2
3
4
5
6
7
8


9
10
11


12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261



262
263
264
265
266
267
268
269
270


271
272
273
274
275
276
277
278







279
280

281
282

283
284

285
286
287
288
289
290
291
292
293
294
295
296
297











298
299
300
301

302
303
304

305
306
307
308
309



310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
















333
334
335
336
337




338
339
340


341
342
343
344
345



346
347
348
349
350
351





352
353
354
355
356
357
358
359
360
361
362
363
364
365













366
367
368
369
370
371
372
373
374
375
376



377
378
379
380
381
382
383
384
385
386
387








388
389
390
391
392
393
394
395
396







397
398

399
400
401
402



403
404
405
406
407



408
409
410
411
412
413
414
415




416
417
418

419
420
421

422
423

424
425
426
427


428
429
430
431
432
433
434
435
436
437








438
439

440
441

442
443
444
445
446
447
448
449
450
451
452
453











454
455
456
457
458
459
460
461
462
463
464
465



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489






















490
491
492


493
494
495
496
497



498
499
500


501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519

















520
521
522

523
524
525
526
527
528
529
530
531
532
533
534



535
536
537
538
539
540
541
542
543
544









545
546
547
548
549


550
551

552
553
554
555
556
557


558
559
560
561
562
563
564
565
566
567








568
569

570
571

572
573
574
575
576
577
578
579





580
581
582
583

584
585
586
587
588
589
590





591
592

593
594
595


596
597
598
599
600


601
602
603
604
605

606
607
608

609
610

611
612
613
614



615
616

617
618
619
620


621
622
623
624
625
626





627
628
629
630

631
632
633
634
635
636

637
638
639

640
641
642
643
644
645
646
647


648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676




































677
678
679
680

681
682
683

684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700





701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722

723
724

725
726
727
728
729
730
731







732
733
734
735



736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762




763
764
765
766
767
768
769
770





771
772
773

774
775
776
777
778
779
780
781
782
783









784
785
786

787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

















805
806
807

808
809
810
811

812
813
814
815
816
817
818
819
820
821









822
823
824

825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
























































881
882
883

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898















899
900
901

902
903

904
905
906

907
908
909
910

911
912
913
914

915
916
917
918

919
920
921
922

923
924
925


926
927

928
929
930

931
932
933
934
935




936
937
938

939
940

941
942
943

944
945
946
947

948
949
950
951

952
953
954
955

956
957
958
959

960
961
962


963
964

965
966
967

968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036




































































1037
1038
1039

1040
1041
1042
1043
1044
1045
1046






1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069





















1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103











1104
1105
1106
1107
1108
1109
1110






1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141



1142
1143
1144
1145
1146
1147




1148
1149

1150
1151

1152
1153

1154
1155

1156
1157

1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168






1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179







1180
1181

1182
1183
1184
1185



1186
1187
1188
1189
1190
1191
1192
1193


1194
1195

1196
1197
1198

1199
1200
1201


1202
1203
1204
1205
1206
1207

1208
1209
1210


1211
1212
1213
1214
1215
1216
1217





1218
1219
1220
1221
1222




1223
1224
1225
1226



1227
1228
1229


1230
1231
1232
1233
1234
1235
1236


1237
1238
1239

1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253





1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264




1265
1266
1267
1268
1269
1270




1271
1272
1273
1274
1275



1276
1277
1278
1279
1280
1281
1282
1283







1284
1285
1286

1287
1288
1289


1290
1291

1292
1293

1294
1295

1296
1297

1298
1299

1300
1301
1302
1303



1304
1305

1306
1307

1308
1309

1310
1311

1312
1313

1314
1315

1316
1317
1318
1319
1320




1321
1322
1323


1324
1325

1326
1327

1328
1329
1330


1331
1332
1333
1334

1335
1336

1337
1338

1339
1340
1341
1342
1343
1344





1345
1346

1347
1348
1349
1350
1351




1352
1353
1354
1355


1356
1357
1358
1359
1360



1361
1362

1363
1364
1365
1366
1367
1368
1369
1370
1371
1372






1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383



1384
1385
1386
1387
1388
1389
1390
1391
1392
1393









1394
1395
1396
1397
1398
1399
1400






1401
1402
1403
1404


1405
1406
1407
1408


1409
1410
1411


1412
1413

1414
1415
1416
1417
1418



1419
1420
1421
1422
1423



1424
1425
1426
1427
1428
1429
1430
1431
1432








1433
1434
1435

1436
1437
1438
1439
1440

1441
1442
1443
1444
1445

1446
1447
1448
1449



1450
1451
1452

1453
1454

1455
1456
1457
1458
1459

1460
1461
1462
1463
1464



1465
1466
1467


1468
1469
1470
1471



1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482










1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493




1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509















1510
1511
1512
1513

1514
1515

1516
1517

1518
1519
1520
1521
1522

1523
1524
1525
1526

1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1
2
3
4
5
6


7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25































26
27
28
29
30
31



32



33
34
35
36
37
38
39
40
41
42
43
44



45
46
47
48
49
50




51
52
53
54
55
56
57
58










59



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136
137
138
139
140
141
142
143
144
145
146



147



148
149



150
151
152









153
154








155
156
157
158
159
160
161


162


163


164













165
166
167
168
169
170
171
172
173
174
175




176



177





178
179
180






181

















182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197





198
199
200
201



202
203





204
205
206






207
208
209
210
211














212
213
214
215
216
217
218
219
220
221
222
223
224











225
226
227











228
229
230
231
232
233
234
235









236
237
238
239
240
241
242


243




244
245
246





247
248
249








250
251
252
253



254



255


256




257
258










259
260
261
262
263
264
265
266


267


268












269
270
271
272
273
274
275
276
277
278
279












280
281
282
























283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304



305
306





307
308
309



310
311



















312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328



329












330
331
332










333
334
335
336
337
338
339
340
341





342
343


344






345
346










347
348
349
350
351
352
353
354


355


356








357
358
359
360
361




362







363
364
365
366
367


368



369
370





371
372





373



374


375




376
377
378


379




380
381






382
383
384
385
386




387






388



389








390
391





























392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427




428



429

















430
431
432
433
434






















435


436







437
438
439
440
441
442
443




444
445
446



























447
448
449
450








451
452
453
454
455



456










457
458
459
460
461
462
463
464
465



466


















467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483



484




485










486
487
488
489
490
491
492
493
494



495
























































496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551



552















553
554
555
556
557
558
559
560
561
562
563
564
565
566
567



568


569



570




571




572




573




574



575
576


577



578





579
580
581
582



583


584



585




586




587




588




589



590
591


592



593





































































594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661



662







663
664
665
666
667
668























669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689


690
































691
692
693
694
695
696
697
698
699
700
701







702
703
704
705
706
707































708
709
710






711
712
713
714


715


716


717


718


719



720








721
722
723
724
725
726











727
728
729
730
731
732
733


734




735
736
737








738
739


740



741



742
743






744



745
746







747
748
749
750
751





752
753
754
755




756
757
758



759
760







761
762



763



764











765
766
767
768
769


770









771
772
773
774






775
776
777
778





779
780
781








782
783
784
785
786
787
788



789



790
791


792


793


794


795


796




797
798
799


800


801


802


803


804


805





806
807
808
809



810
811


812


813



814
815




816


817


818






819
820
821
822
823


824





825
826
827
828




829
830





831
832
833


834










835
836
837
838
839
840











841
842
843










844
845
846
847
848
849
850
851
852







853
854
855
856
857
858




859
860




861
862



863
864


865





866
867
868





869
870
871









872
873
874
875
876
877
878
879



880





881





882




883
884
885



886


887





888





889
890
891



892
893




894
895
896











897
898
899
900
901
902
903
904
905
906




907







908
909
910
911
















912
913
914
915
916
917
918
919
920
921
922
923
924
925
926




927


928


929





930




931




932
933
934
935
936
937
938
939

















































































































































































































































































































































-
-
+
+

-
-
+
+











+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
-

-
-
-


+
+
+







-
-
-






-
-
-
-








-
-
-
-
-
-
-
-
-
-
+
-
-
-
















-











-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-











-
-
-

-
-
-


-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
+
+
-
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
+
-
-
+
-
-
-
+
+
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * This file should be maintained in sync with xlib/X11/keysymdefs.h
 *
 * Note that this should be done manually only, because in some cases
 * keysymdefs.h defines the same integer for multiple keysyms, e.g.:
 *
 *    #define XK_Greek_LAMDA                         0x7CB
 *    #define XK_Greek_LAMBDA                        0x7CB
 *    #define XK_Greek_LAMDA                         0x7cb
 *    #define XK_Greek_LAMBDA                        0x7cb
 *
 *    #define XK_Cyrillic_DZHE                       0x6BF
 *    #define XK_Serbian_DZE                         0x6BF  (deprecated)
 *    #define XK_Cyrillic_DZHE                       0x6bf
 *    #define XK_Serbian_DZE                         0x6bf  (deprecated)
 *
 */
{ "BackSpace", 0xFF08 },
{ "Tab", 0xFF09 },
{ "Linefeed", 0xFF0A },
{ "Clear", 0xFF0B },
{ "Return", 0xFF0D },
{ "Pause", 0xFF13 },
{ "Scroll_Lock", 0xFF14 },
{ "Sys_Req", 0xFF15 },
{ "Escape", 0xFF1B },
{ "Delete", 0xFFFF },
{ "Multi_key", 0xFF20 },
{ "Kanji", 0xFF21 },
{ "Muhenkan", 0xFF22 },
{ "Henkan_Mode", 0xFF23 },
{ "Henkan", 0xFF23 },
{ "Romaji", 0xFF24 },
{ "Hiragana", 0xFF25 },
{ "Katakana", 0xFF26 },
{ "Hiragana_Katakana", 0xFF27 },
{ "Zenkaku", 0xFF28 },
{ "Hankaku", 0xFF29 },
{ "Zenkaku_Hankaku", 0xFF2A },
{ "Touroku", 0xFF2B },
{ "Massyo", 0xFF2C },
{ "Kana_Lock", 0xFF2D },
{ "Kana_Shift", 0xFF2E },
{ "Eisu_Shift", 0xFF2F },
{ "Eisu_toggle", 0xFF30 },
{ "Hangul", 0xFF31 },
{ "Hangul_Start", 0xFF32 },
{ "Hangul_End", 0xFF33 },
{ "Hangul_Hanja", 0xFF34 },
{ "Hangul_Jamo", 0xFF35 },
{ "Hangul_Romaja", 0xFF36 },
{ "Codeinput", 0xFF37 },
{ "Hangul_Jeonja", 0xFF38 },
{ "Hangul_Banja", 0xFF39 },
{ "Hangul_PreHanja", 0xFF3A },
{ "Hangul_PostHanja", 0xFF3B },
{ "SingleCandidate", 0xFF3C },
{ "MultipleCandidate", 0xFF3D },
{ "PreviousCandidate", 0xFF3E },
{ "Hangul_Special", 0xFF3F },
{ "Home", 0xFF50 },
{ "Left", 0xFF51 },
{ "Up", 0xFF52 },
{ "Right", 0xFF53 },
{ "Down", 0xFF54 },
{ "Prior", 0xFF55 },
#ifndef TK_NO_DEPRECATED
{ "Page_Up", 0xFF55 },
#endif
{ "Next", 0xFF56 },
#ifndef TK_NO_DEPRECATED
{ "Page_Down", 0xFF56 },
#endif
{ "End", 0xFF57 },
{ "Begin", 0xFF58 },
{ "Win_L", 0xFF5B },
{ "Win_R", 0xFF5C },
{ "App", 0xFF5D },
{ "Select", 0xFF60 },
{ "Print", 0xFF61 },
{ "Execute", 0xFF62 },
{ "Insert", 0xFF63 },
{ "Undo", 0xFF65 },
{ "Redo", 0xFF66 },
{ "Menu", 0xFF67 },
#ifndef TK_NO_DEPRECATED
{ "App", 0xFF67 },
#endif
{ "Find", 0xFF68 },
{ "Cancel", 0xFF69 },
{ "Help", 0xFF6A },
{ "Break", 0xFF6B },
{ "Mode_switch", 0xFF7E },
{ "script_switch", 0xFF7E },
{ "kana_switch", 0xFF7E },
{ "Arabic_switch", 0xFF7E },
{ "Greek_switch", 0xFF7E },
{ "Hebrew_switch", 0xFF7E },
{ "Num_Lock", 0xFF7F },
{ "KP_Space", 0xFF80 },
{ "KP_Tab", 0xFF89 },
{ "KP_Enter", 0xFF8D },
{ "KP_F1", 0xFF91 },
{ "KP_F2", 0xFF92 },
{ "KP_F3", 0xFF93 },
{ "KP_F4", 0xFF94 },
{ "KP_Home", 0xFF95 },
{ "KP_Left", 0xFF96 },
{ "KP_Up", 0xFF97 },
{ "KP_Right", 0xFF98 },
{ "KP_Down", 0xFF99 },
{ "KP_Prior", 0xFF9A },
{ "KP_Page_Up", 0xFF9A },
{ "KP_Next", 0xFF9B },
{ "KP_Page_Down", 0xFF9B },
{ "KP_End", 0xFF9C },
{ "KP_Equal", 0xFFBD },
{ "KP_Begin", 0xFF9D },
{ "KP_Insert", 0xFF9E },
{ "KP_Delete", 0xFF9F },
{ "KP_Multiply", 0xFFAA },
{ "KP_Add", 0xFFAB },
{ "KP_Separator", 0xFFAC },
{ "KP_Subtract", 0xFFAD },
{ "KP_Decimal", 0xFFAE },
{ "KP_Divide", 0xFFAF },
{ "KP_0", 0xFFB0 },
{ "KP_1", 0xFFB1 },
{ "KP_2", 0xFFB2 },
{ "KP_3", 0xFFB3 },
{ "KP_4", 0xFFB4 },
{ "KP_5", 0xFFB5 },
{ "KP_6", 0xFFB6 },
{ "KP_7", 0xFFB7 },
{ "KP_8", 0xFFB8 },
{ "KP_9", 0xFFB9 },
{ "KP_Equal", 0xFFBD },
{ "F1", 0xFFBE },
{ "F2", 0xFFBF },
{ "F3", 0xFFC0 },
{ "F4", 0xFFC1 },
{ "F5", 0xFFC2 },
{ "F6", 0xFFC3 },
{ "F7", 0xFFC4 },
{ "F8", 0xFFC5 },
{ "F9", 0xFFC6 },
{ "F10", 0xFFC7 },
{ "F11", 0xFFC8 },
#ifndef TK_NO_DEPRECATED
{ "L1", 0xFFC8 },
#endif
{ "F12", 0xFFC9 },
#ifndef TK_NO_DEPRECATED
{ "L2", 0xFFC9 },
#endif
{ "F13", 0xFFCA },
#ifndef TK_NO_DEPRECATED
{ "L3", 0xFFCA },
#endif
{ "F14", 0xFFCB },
#ifndef TK_NO_DEPRECATED
{ "L4", 0xFFCB },
#endif
{ "F15", 0xFFCC },
#ifndef TK_NO_DEPRECATED
{ "L5", 0xFFCC },
#endif
{ "F16", 0xFFCD },
#ifndef TK_NO_DEPRECATED
{ "L6", 0xFFCD },
#endif
{ "F17", 0xFFCE },
#ifndef TK_NO_DEPRECATED
{ "L7", 0xFFCE },
#endif
{ "F18", 0xFFCF },
#ifndef TK_NO_DEPRECATED
{ "L8", 0xFFCF },
#endif
{ "F19", 0xFFD0 },
#ifndef TK_NO_DEPRECATED
{ "L9", 0xFFD0 },
#endif
{ "F20", 0xFFD1 },
#ifndef TK_NO_DEPRECATED
{ "L10", 0xFFD1 },
#endif
{ "F21", 0xFFD2 },
#ifndef TK_NO_DEPRECATED
{ "R1", 0xFFD2 },
#endif
{ "F22", 0xFFD3 },
#ifndef TK_NO_DEPRECATED
{ "R2", 0xFFD3 },
#endif
{ "F23", 0xFFD4 },
#ifndef TK_NO_DEPRECATED
{ "R3", 0xFFD4 },
#endif
{ "F24", 0xFFD5 },
#ifndef TK_NO_DEPRECATED
{ "R4", 0xFFD5 },
#endif
{ "F25", 0xFFD6 },
#ifndef TK_NO_DEPRECATED
{ "R5", 0xFFD6 },
#endif
{ "F26", 0xFFD7 },
#ifndef TK_NO_DEPRECATED
{ "R6", 0xFFD7 },
#endif
{ "F27", 0xFFD8 },
#ifndef TK_NO_DEPRECATED
{ "R7", 0xFFD8 },
#endif
{ "F28", 0xFFD9 },
#ifndef TK_NO_DEPRECATED
{ "R8", 0xFFD9 },
#endif
{ "F29", 0xFFDA },
#ifndef TK_NO_DEPRECATED
{ "R9", 0xFFDA },
#endif
{ "F30", 0xFFDB },
#ifndef TK_NO_DEPRECATED
{ "R10", 0xFFDB },
#endif
{ "F31", 0xFFDC },
#ifndef TK_NO_DEPRECATED
{ "R11", 0xFFDC },
#endif
{ "F32", 0xFFDD },
#ifndef TK_NO_DEPRECATED
{ "R12", 0xFFDD },
#endif
{ "F33", 0xFFDE },
#ifndef TK_NO_DEPRECATED
{ "R13", 0xFFDE },
#endif
{ "F34", 0xFFDF },
#ifndef TK_NO_DEPRECATED
{ "R14", 0xFFDF },
#endif
{ "F35", 0xFFE0 },
#ifndef TK_NO_DEPRECATED
{ "R15", 0xFFE0 },
#endif
{ "Shift_L", 0xFFE1 },
{ "Shift_R", 0xFFE2 },
{ "Control_L", 0xFFE3 },
{ "Control_R", 0xFFE4 },
{ "Caps_Lock", 0xFFE5 },
{ "Shift_Lock", 0xFFE6 },
{ "Meta_L", 0xFFE7 },
{ "Meta_R", 0xFFE8 },
{ "Alt_L", 0xFFE9 },
{ "Alt_R", 0xFFEA },
{ "Super_L", 0xFFEB },
#ifndef TK_NO_DEPRECATED
{ "Win_L", 0xFFEB },
#endif
{ "Super_R", 0xFFEC },
#ifndef TK_NO_DEPRECATED
{ "Win_R", 0xFFEC },
#endif
{ "Hyper_L", 0xFFED },
{ "Hyper_R", 0xFFEE },
{ "braille_dot_1", 0xFFF1 },
{ "braille_dot_2", 0xFFF2 },
{ "braille_dot_3", 0xFFF3 },
{ "space", 0x020 },
{ "exclam", 0x021 },
{ "quotedbl", 0x022 },
{ "braille_dot_4", 0xFFF4 },
{ "braille_dot_5", 0xFFF5 },
{ "braille_dot_6", 0xFFF6 },
{ "braille_dot_7", 0xFFF7 },
{ "braille_dot_8", 0xFFF8 },
{ "braille_dot_9", 0xFFF9 },
{ "braille_dot_10", 0xFFFA },
{ "Delete", 0xFFFF },
{ "ISO_Lock", 0xFE01 },
{ "numbersign", 0x023 },
{ "dollar", 0x024 },
{ "ISO_Level2_Latch", 0xFE02 },
{ "ISO_Level3_Shift", 0xFE03 },
{ "ISO_Level3_Latch", 0xFE04 },
{ "ISO_Level3_Lock", 0xFE05 },
{ "ISO_Group_Shift", 0xFF7E },
{ "ISO_Group_Latch", 0xFE06 },
{ "ISO_Group_Lock", 0xFE07 },
{ "ISO_Next_Group", 0xFE08 },
{ "percent", 0x025 },
{ "ampersand", 0x026 },
{ "quoteright", 0x027 },
{ "parenleft", 0x028 },
{ "parenright", 0x029 },
{ "asterisk", 0x02a },
{ "plus", 0x02b },
{ "ISO_Next_Group_Lock", 0xFE09 },
{ "ISO_Prev_Group", 0xFE0A },
{ "comma", 0x02c },
{ "ISO_Prev_Group_Lock", 0xFE0B },
{ "ISO_First_Group", 0xFE0C },
{ "minus", 0x02d },
{ "ISO_First_Group_Lock", 0xFE0D },
{ "ISO_Last_Group", 0xFE0E },
{ "period", 0x02e },
{ "ISO_Last_Group_Lock", 0xFE0F },
{ "ISO_Level5_Shift", 0xFE11 },
{ "ISO_Level5_Latch", 0xFE12 },
{ "ISO_Level5_Lock", 0xFE13 },
{ "ISO_Left_Tab", 0xFE20 },
{ "ISO_Move_Line_Up", 0xFE21 },
{ "ISO_Move_Line_Down", 0xFE22 },
{ "ISO_Partial_Line_Up", 0xFE23 },
{ "ISO_Partial_Line_Down", 0xFE24 },
{ "ISO_Partial_Space_Left", 0xFE25 },
{ "ISO_Partial_Space_Right", 0xFE26 },
{ "ISO_Set_Margin_Left", 0xFE27 },
{ "ISO_Set_Margin_Right", 0xFE28 },
{ "slash", 0x02f },
{ "0", 0x030 },
{ "1", 0x031 },
{ "2", 0x032 },
{ "3", 0x033 },
{ "4", 0x034 },
{ "5", 0x035 },
{ "6", 0x036 },
{ "7", 0x037 },
{ "8", 0x038 },
{ "9", 0x039 },
{ "ISO_Release_Margin_Left", 0xFE29 },
{ "ISO_Release_Margin_Right", 0xFE2A },
{ "ISO_Release_Both_Margins", 0xFE2B },
{ "ISO_Fast_Cursor_Left", 0xFE2C },
{ "colon", 0x03a },
{ "ISO_Fast_Cursor_Right", 0xFE2D },
{ "ISO_Fast_Cursor_Up", 0xFE2E },
{ "ISO_Fast_Cursor_Down", 0xFE2F },
{ "semicolon", 0x03b },
{ "ISO_Continuous_Underline", 0xFE30 },
{ "ISO_Discontinuous_Underline", 0xFE31 },
{ "ISO_Emphasize", 0xFE32 },
{ "ISO_Center_Object", 0xFE33 },
{ "ISO_Enter", 0xFE34 },
{ "less", 0x03c },
{ "equal", 0x03d },
{ "greater", 0x03e },
{ "dead_grave", 0xFE50 },
{ "dead_acute", 0xFE51 },
{ "dead_circumflex", 0xFE52 },
{ "dead_tilde", 0xFE53 },
{ "dead_perispomeni", 0xFE53 },
{ "dead_macron", 0xFE54 },
{ "question", 0x03f },
{ "dead_breve", 0xFE55 },
{ "dead_abovedot", 0xFE56 },
{ "dead_diaeresis", 0xFE57 },
{ "dead_abovering", 0xFE58 },
{ "dead_doubleacute", 0xFE59 },
{ "dead_caron", 0xFE5A },
{ "dead_cedilla", 0xFE5B },
{ "dead_ogonek", 0xFE5C },
{ "dead_iota", 0xFE5D },
{ "dead_voiced_sound", 0xFE5E },
{ "dead_semivoiced_sound", 0xFE5F },
{ "dead_belowdot", 0xFE60 },
{ "dead_hook", 0xFE61 },
{ "dead_horn", 0xFE62 },
{ "dead_stroke", 0xFE63 },
{ "dead_abovecomma", 0xFE64 },
{ "dead_psili", 0xFE64 },
{ "at", 0x040 },
{ "A", 0x041 },
{ "B", 0x042 },
{ "C", 0x043 },
{ "D", 0x044 },
{ "E", 0x045 },
{ "F", 0x046 },
{ "G", 0x047 },
{ "H", 0x048 },
{ "I", 0x049 },
{ "J", 0x04a },
{ "K", 0x04b },
{ "L", 0x04c },
{ "M", 0x04d },
{ "N", 0x04e },
{ "O", 0x04f },
{ "dead_abovereversedcomma", 0xFE65 },
{ "dead_dasia", 0xFE65 },
{ "dead_doublegrave", 0xFE66 },
{ "dead_belowring", 0xFE67 },
{ "dead_belowmacron", 0xFE68 },
{ "P", 0x050 },
{ "Q", 0x051 },
{ "R", 0x052 },
{ "S", 0x053 },
{ "dead_belowcircumflex", 0xFE69 },
{ "dead_belowtilde", 0xFE6A },
{ "dead_belowbreve", 0xFE6B },
{ "T", 0x054 },
{ "U", 0x055 },
{ "dead_belowdiaeresis", 0xFE6C },
{ "dead_invertedbreve", 0xFE6D },
{ "dead_belowcomma", 0xFE6E },
{ "dead_currency", 0xFE6F },
{ "AccessX_Enable", 0xFE70 },
{ "V", 0x056 },
{ "W", 0x057 },
{ "X", 0x058 },
{ "AccessX_Feedback_Enable", 0xFE71 },
{ "RepeatKeys_Enable", 0xFE72 },
{ "SlowKeys_Enable", 0xFE73 },
{ "BounceKeys_Enable", 0xFE74 },
{ "StickyKeys_Enable", 0xFE75 },
{ "MouseKeys_Enable", 0xFE76 },
{ "Y", 0x059 },
{ "Z", 0x05a },
{ "bracketleft", 0x05b },
{ "backslash", 0x05c },
{ "bracketright", 0x05d },
{ "MouseKeys_Accel_Enable", 0xFE77 },
{ "Overlay1_Enable", 0xFE78 },
{ "Overlay2_Enable", 0xFE79 },
{ "AudibleBell_Enable", 0xFE7A },
{ "dead_a", 0xFE80 },
{ "dead_A", 0xFE81 },
{ "dead_e", 0xFE82 },
{ "dead_E", 0xFE83 },
{ "dead_i", 0xFE84 },
{ "dead_I", 0xFE85 },
{ "dead_o", 0xFE86 },
{ "dead_O", 0xFE87 },
{ "dead_u", 0xFE88 },
{ "dead_U", 0xFE89 },
{ "asciicircum", 0x05e },
{ "underscore", 0x05f },
{ "quoteleft", 0x060 },
{ "a", 0x061 },
{ "b", 0x062 },
{ "c", 0x063 },
{ "d", 0x064 },
{ "e", 0x065 },
{ "f", 0x066 },
{ "g", 0x067 },
{ "h", 0x068 },
{ "i", 0x069 },
{ "j", 0x06a },
{ "dead_schwa", 0xFE8A },
#ifndef TK_NO_DEPRECATED
{ "dead_small_schwa", 0xFE8A },
#endif
{ "dead_SCHWA", 0xFE8B },
#ifndef TK_NO_DEPRECATED
{ "dead_capital_schwa", 0xFE8B },
#endif
{ "dead_greek", 0xFE8C },
{ "dead_hamza", 0xFE8D },
{ "dead_lowline", 0xFE90 },
{ "k", 0x06b },
{ "l", 0x06c },
{ "m", 0x06d },
{ "dead_aboveverticalline", 0xFE91 },
{ "dead_belowverticalline", 0xFE92 },
{ "dead_longsolidusoverlay", 0xFE93 },
{ "ch", 0xFEA0 },
{ "Ch", 0xFEA1 },
{ "CH", 0xFEA2 },
{ "c_h", 0xFEA3 },
{ "C_h", 0xFEA4 },
{ "C_H", 0xFEA5 },
{ "First_Virtual_Screen", 0xFED0 },
{ "Prev_Virtual_Screen", 0xFED1 },
{ "n", 0x06e },
{ "o", 0x06f },
{ "p", 0x070 },
{ "q", 0x071 },
{ "r", 0x072 },
{ "s", 0x073 },
{ "t", 0x074 },
{ "u", 0x075 },
{ "Next_Virtual_Screen", 0xFED2 },
{ "Last_Virtual_Screen", 0xFED4 },
{ "Terminate_Server", 0xFED5 },
{ "Pointer_Left", 0xFEE0 },
{ "Pointer_Right", 0xFEE1 },
{ "Pointer_Up", 0xFEE2 },
{ "Pointer_Down", 0xFEE3 },
{ "Pointer_UpLeft", 0xFEE4 },
{ "Pointer_UpRight", 0xFEE5 },
{ "v", 0x076 },
{ "w", 0x077 },
{ "x", 0x078 },
{ "y", 0x079 },
{ "z", 0x07a },
{ "braceleft", 0x07b },
{ "bar", 0x07c },
{ "Pointer_DownLeft", 0xFEE6 },
{ "Pointer_DownRight", 0xFEE7 },
{ "braceright", 0x07d },
{ "Pointer_Button_Dflt", 0xFEE8 },
{ "Pointer_Button1", 0xFEE9 },
{ "Pointer_Button2", 0xFEEA },
{ "Pointer_Button3", 0xFEEB },
{ "asciitilde", 0x07e },
{ "nobreakspace", 0x0a0 },
{ "exclamdown", 0x0a1 },
{ "Pointer_Button4", 0xFEEC },
{ "Pointer_Button5", 0xFEED },
{ "Pointer_DblClick_Dflt", 0xFEEE },
{ "Pointer_DblClick1", 0xFEEF },
{ "Pointer_DblClick2", 0xFEF0 },
{ "cent", 0x0a2 },
{ "sterling", 0x0a3 },
{ "currency", 0x0a4 },
{ "Pointer_DblClick3", 0xFEF1 },
{ "Pointer_DblClick4", 0xFEF2 },
{ "Pointer_DblClick5", 0xFEF3 },
{ "Pointer_Drag_Dflt", 0xFEF4 },
{ "Pointer_Drag1", 0xFEF5 },
{ "Pointer_Drag2", 0xFEF6 },
{ "Pointer_Drag3", 0xFEF7 },
{ "Pointer_Drag4", 0xFEF8 },
{ "yen", 0x0a5 },
{ "brokenbar", 0x0a6 },
{ "section", 0x0a7 },
{ "diaeresis", 0x0a8 },
{ "Pointer_EnableKeys", 0xFEF9 },
{ "Pointer_Accelerate", 0xFEFA },
{ "Pointer_DfltBtnNext", 0xFEFB },
{ "copyright", 0x0a9 },
{ "Pointer_DfltBtnPrev", 0xFEFC },
{ "Pointer_Drag5", 0xFEFD },
{ "space", 0x20 },
{ "ordfeminine", 0x0aa },
#ifndef TK_NO_DEPRECATED
{ "exclam", 0x21 },
{ "guillemotleft", 0x0ab },
#endif
{ "quotedbl", 0x22 },
{ "numbersign", 0x23 },
{ "dollar", 0x24 },
{ "notsign", 0x0ac },
{ "hyphen", 0x0ad },
#ifndef TK_NO_DEPRECATED
{ "percent", 0x25 },
{ "ampersand", 0x26 },
{ "apostrophe", 0x27 },
{ "quoteright", 0x27 },
{ "parenleft", 0x28 },
{ "parenright", 0x29 },
{ "asterisk", 0x2A },
{ "plus", 0x2B },
{ "comma", 0x2C },
{ "registered", 0x0ae },
{ "macron", 0x0af },
{ "degree", 0x0b0 },
{ "plusminus", 0x0b1 },
{ "twosuperior", 0x0b2 },
{ "threesuperior", 0x0b3 },
{ "acute", 0x0b4 },
{ "mu", 0x0b5 },
#endif
{ "minus", 0x2D },
{ "paragraph", 0x0b6 },
#ifndef TK_NO_DEPRECATED
{ "period", 0x2E },
{ "periodcentered", 0x0b7 },
{ "slash", 0x2F },
{ "0", 0x30 },
{ "1", 0x31 },
{ "2", 0x32 },
{ "3", 0x33 },
{ "4", 0x34 },
{ "5", 0x35 },
{ "6", 0x36 },
{ "7", 0x37 },
{ "8", 0x38 },
{ "9", 0x39 },
{ "colon", 0x3A },
{ "cedilla", 0x0b8 },
{ "onesuperior", 0x0b9 },
{ "masculine", 0x0ba },
{ "guillemotright", 0x0bb },
{ "onequarter", 0x0bc },
{ "onehalf", 0x0bd },
{ "threequarters", 0x0be },
{ "questiondown", 0x0bf },
{ "Agrave", 0x0c0 },
{ "Aacute", 0x0c1 },
{ "Acircumflex", 0x0c2 },
#endif
{ "semicolon", 0x3B },
{ "less", 0x3C },
#ifndef TK_NO_DEPRECATED
{ "equal", 0x3D },
#endif
{ "greater", 0x3E },
#ifndef TK_NO_DEPRECATED
{ "question", 0x3F },
{ "at", 0x40 },
{ "A", 0x41 },
{ "B", 0x42 },
{ "Atilde", 0x0c3 },
{ "Adiaeresis", 0x0c4 },
{ "Aring", 0x0c5 },
{ "C", 0x43 },
{ "D", 0x44 },
{ "E", 0x45 },
{ "F", 0x46 },
{ "G", 0x47 },
{ "H", 0x48 },
{ "I", 0x49 },
{ "J", 0x4A },
{ "K", 0x4B },
{ "L", 0x4C },
{ "M", 0x4D },
{ "N", 0x4E },
{ "O", 0x4F },
{ "P", 0x50 },
{ "Q", 0x51 },
{ "R", 0x52 },
{ "S", 0x53 },
{ "T", 0x54 },
{ "U", 0x55 },
{ "V", 0x56 },
{ "W", 0x57 },
{ "X", 0x58 },
{ "Y", 0x59 },
{ "Z", 0x5A },
{ "AE", 0x0c6 },
{ "Ccedilla", 0x0c7 },
{ "Egrave", 0x0c8 },
{ "Eacute", 0x0c9 },
{ "Ecircumflex", 0x0ca },
{ "Ediaeresis", 0x0cb },
{ "Igrave", 0x0cc },
{ "Iacute", 0x0cd },
{ "Icircumflex", 0x0ce },
{ "Idiaeresis", 0x0cf },
{ "Eth", 0x0d0 },
{ "Ntilde", 0x0d1 },
{ "Ograve", 0x0d2 },
{ "Oacute", 0x0d3 },
{ "Ocircumflex", 0x0d4 },
{ "Otilde", 0x0d5 },
{ "Odiaeresis", 0x0d6 },
{ "multiply", 0x0d7 },
{ "Ooblique", 0x0d8 },
{ "Ugrave", 0x0d9 },
{ "Uacute", 0x0da },
{ "Ucircumflex", 0x0db },
#endif
{ "bracketleft", 0x5B },
{ "backslash", 0x5C },
{ "Udiaeresis", 0x0dc },
{ "Yacute", 0x0dd },
{ "bracketright", 0x5D },
#ifndef TK_NO_DEPRECATED
{ "asciicircum", 0x5E },
{ "underscore", 0x5F },
{ "grave", 0x60 },
{ "Thorn", 0x0de },
{ "ssharp", 0x0df },
{ "agrave", 0x0e0 },
{ "quoteleft", 0x60 },
{ "a", 0x61 },
{ "b", 0x62 },
{ "aacute", 0x0e1 },
{ "acircumflex", 0x0e2 },
{ "c", 0x63 },
{ "d", 0x64 },
{ "e", 0x65 },
{ "f", 0x66 },
{ "g", 0x67 },
{ "h", 0x68 },
{ "i", 0x69 },
{ "j", 0x6A },
{ "k", 0x6B },
{ "l", 0x6C },
{ "m", 0x6D },
{ "n", 0x6E },
{ "o", 0x6F },
{ "p", 0x70 },
{ "q", 0x71 },
{ "r", 0x72 },
{ "s", 0x73 },
{ "t", 0x74 },
{ "u", 0x75 },
{ "atilde", 0x0e3 },
{ "adiaeresis", 0x0e4 },
{ "aring", 0x0e5 },
{ "ae", 0x0e6 },
{ "ccedilla", 0x0e7 },
{ "egrave", 0x0e8 },
{ "eacute", 0x0e9 },
{ "ecircumflex", 0x0ea },
{ "ediaeresis", 0x0eb },
{ "igrave", 0x0ec },
{ "iacute", 0x0ed },
{ "icircumflex", 0x0ee },
{ "idiaeresis", 0x0ef },
{ "eth", 0x0f0 },
{ "ntilde", 0x0f1 },
{ "ograve", 0x0f2 },
{ "oacute", 0x0f3 },
{ "v", 0x76 },
{ "w", 0x77 },
{ "x", 0x78 },
{ "ocircumflex", 0x0f4 },
{ "y", 0x79 },
{ "z", 0x7A },
#endif
{ "braceleft", 0x7B },
#ifndef TK_NO_DEPRECATED
{ "bar", 0x7C },
#endif
{ "braceright", 0x7D },
#ifndef TK_NO_DEPRECATED
{ "asciitilde", 0x7E },
#endif
{ "nobreakspace", 0xA0 },
{ "otilde", 0x0f5 },
{ "odiaeresis", 0x0f6 },
{ "division", 0x0f7 },
#ifndef TK_NO_DEPRECATED
{ "exclamdown", 0xA1 },
{ "cent", 0xA2 },
{ "sterling", 0xA3 },
{ "currency", 0xA4 },
{ "yen", 0xA5 },
{ "brokenbar", 0xA6 },
{ "section", 0xA7 },
{ "diaeresis", 0xA8 },
{ "copyright", 0xA9 },
{ "oslash", 0x0f8 },
{ "ugrave", 0x0f9 },
{ "uacute", 0x0fa },
{ "ucircumflex", 0x0fb },
{ "udiaeresis", 0x0fc },
{ "yacute", 0x0fd },
{ "thorn", 0x0fe },
{ "ydiaeresis", 0x0ff },
{ "Aogonek", 0x1a1 },
{ "ordfeminine", 0xAA },
{ "guillemetleft", 0xAB },
{ "guillemotleft", 0xAB },
{ "notsign", 0xAC },
{ "hyphen", 0xAD },
{ "breve", 0x1a2 },
{ "Lstroke", 0x1a3 },
{ "registered", 0xAE },
{ "macron", 0xAF },
{ "Lcaron", 0x1a5 },
{ "degree", 0xB0 },
{ "plusminus", 0xB1 },
{ "twosuperior", 0xB2 },
{ "threesuperior", 0xB3 },
{ "acute", 0xB4 },
{ "mu", 0xB5 },
{ "Sacute", 0x1a6 },
{ "Scaron", 0x1a9 },
{ "paragraph", 0xB6 },
{ "periodcentered", 0xB7 },
{ "cedilla", 0xB8 },
{ "onesuperior", 0xB9 },
{ "ordmasculine", 0xBA },
{ "masculine", 0xBA },
{ "guillemetright", 0xBB },
{ "guillemotright", 0xBB },
{ "onequarter", 0xBC },
{ "onehalf", 0xBD },
{ "Scedilla", 0x1aa },
{ "Tcaron", 0x1ab },
{ "Zacute", 0x1ac },
{ "Zcaron", 0x1ae },
{ "Zabovedot", 0x1af },
{ "aogonek", 0x1b1 },
{ "ogonek", 0x1b2 },
{ "lstroke", 0x1b3 },
{ "threequarters", 0xBE },
{ "questiondown", 0xBF },
{ "lcaron", 0x1b5 },
{ "Agrave", 0xC0 },
{ "Aacute", 0xC1 },
{ "sacute", 0x1b6 },
{ "Acircumflex", 0xC2 },
{ "Atilde", 0xC3 },
{ "Adiaeresis", 0xC4 },
{ "Aring", 0xC5 },
{ "AE", 0xC6 },
{ "Ccedilla", 0xC7 },
{ "Egrave", 0xC8 },
{ "Eacute", 0xC9 },
{ "caron", 0x1b7 },
{ "scaron", 0x1b9 },
{ "scedilla", 0x1ba },
{ "tcaron", 0x1bb },
{ "zacute", 0x1bc },
{ "Ecircumflex", 0xCA },
{ "Ediaeresis", 0xCB },
{ "Igrave", 0xCC },
{ "Iacute", 0xCD },
{ "doubleacute", 0x1bd },
{ "Icircumflex", 0xCE },
{ "Idiaeresis", 0xCF },
{ "ETH", 0xD0 },
{ "Eth", 0xD0 },
{ "Ntilde", 0xD1 },
{ "Ograve", 0xD2 },
{ "Oacute", 0xD3 },
{ "zcaron", 0x1be },
{ "zabovedot", 0x1bf },
{ "Racute", 0x1c0 },
{ "Abreve", 0x1c3 },
{ "Cacute", 0x1c6 },
{ "Ocircumflex", 0xD4 },
{ "Otilde", 0xD5 },
{ "Ccaron", 0x1c8 },
{ "Odiaeresis", 0xD6 },
{ "multiply", 0xD7 },
{ "Oslash", 0xD8 },
{ "Eogonek", 0x1ca },
{ "Ecaron", 0x1cc },
#ifndef TK_NO_DEPRECATED
{ "Ooblique", 0xD8 },
#endif
{ "Ugrave", 0xD9 },
{ "Uacute", 0xDA },
{ "Dcaron", 0x1cf },
{ "Nacute", 0x1d1 },
{ "Ucircumflex", 0xDB },
{ "Udiaeresis", 0xDC },
{ "Yacute", 0xDD },
{ "THORN", 0xDE },
{ "Thorn", 0xDE },
{ "Ncaron", 0x1d2 },
{ "ssharp", 0xDF },
{ "agrave", 0xE0 },
{ "aacute", 0xE1 },
{ "Odoubleacute", 0x1d5 },
{ "acircumflex", 0xE2 },
{ "atilde", 0xE3 },
{ "Rcaron", 0x1d8 },
{ "adiaeresis", 0xE4 },
{ "aring", 0xE5 },
{ "ae", 0xE6 },
{ "ccedilla", 0xE7 },
{ "Uring", 0x1d9 },
{ "Udoubleacute", 0x1db },
{ "Tcedilla", 0x1de },
{ "egrave", 0xE8 },
{ "eacute", 0xE9 },
{ "racute", 0x1e0 },
{ "ecircumflex", 0xEA },
{ "ediaeresis", 0xEB },
{ "igrave", 0xEC },
{ "iacute", 0xED },
{ "abreve", 0x1e3 },
{ "cacute", 0x1e6 },
{ "icircumflex", 0xEE },
{ "idiaeresis", 0xEF },
{ "eth", 0xF0 },
{ "ntilde", 0xF1 },
{ "ograve", 0xF2 },
{ "oacute", 0xF3 },
{ "ccaron", 0x1e8 },
{ "eogonek", 0x1ea },
{ "ecaron", 0x1ec },
{ "dcaron", 0x1ef },
{ "nacute", 0x1f1 },
{ "ocircumflex", 0xF4 },
{ "otilde", 0xF5 },
{ "odiaeresis", 0xF6 },
{ "division", 0xF7 },
{ "ncaron", 0x1f2 },
{ "oslash", 0xF8 },
#ifndef TK_NO_DEPRECATED
{ "ooblique", 0xF8 },
#endif
{ "ugrave", 0xF9 },
{ "uacute", 0xFA },
{ "odoubleacute", 0x1f5 },
{ "ucircumflex", 0xFB },
{ "udiaeresis", 0xFC },
{ "yacute", 0xFD },
{ "udoubleacute", 0x1fb },
{ "thorn", 0xFE },
{ "ydiaeresis", 0xFF },
#endif
{ "Aogonek", 0x1A1 },
{ "breve", 0x1A2 },
{ "Lstroke", 0x1A3 },
{ "Lcaron", 0x1A5 },
{ "Sacute", 0x1A6 },
{ "rcaron", 0x1f8 },
{ "uring", 0x1f9 },
{ "Scaron", 0x1A9 },
{ "Scedilla", 0x1AA },
{ "Tcaron", 0x1AB },
{ "Zacute", 0x1AC },
{ "Zcaron", 0x1AE },
{ "Zabovedot", 0x1AF },
{ "aogonek", 0x1B1 },
{ "ogonek", 0x1B2 },
{ "lstroke", 0x1B3 },
{ "lcaron", 0x1B5 },
{ "sacute", 0x1B6 },
{ "caron", 0x1B7 },
{ "scaron", 0x1B9 },
{ "scedilla", 0x1BA },
{ "tcaron", 0x1BB },
{ "zacute", 0x1BC },
{ "doubleacute", 0x1BD },
{ "zcaron", 0x1BE },
{ "zabovedot", 0x1BF },
{ "Racute", 0x1C0 },
{ "Abreve", 0x1C3 },
{ "Lacute", 0x1C5 },
{ "Cacute", 0x1C6 },
{ "Ccaron", 0x1C8 },
{ "Eogonek", 0x1CA },
{ "Ecaron", 0x1CC },
{ "Dcaron", 0x1CF },
{ "Dstroke", 0x1D0 },
{ "Nacute", 0x1D1 },
{ "tcedilla", 0x1fe },
{ "abovedot", 0x1ff },
{ "Hstroke", 0x2a1 },
{ "Hcircumflex", 0x2a6 },
{ "Iabovedot", 0x2a9 },
{ "Gbreve", 0x2ab },
{ "Jcircumflex", 0x2ac },
{ "hstroke", 0x2b1 },
{ "hcircumflex", 0x2b6 },
{ "idotless", 0x2b9 },
{ "gbreve", 0x2bb },
{ "jcircumflex", 0x2bc },
{ "Cabovedot", 0x2c5 },
{ "Ccircumflex", 0x2c6 },
{ "Gabovedot", 0x2d5 },
{ "Gcircumflex", 0x2d8 },
{ "Ubreve", 0x2dd },
{ "Scircumflex", 0x2de },
{ "cabovedot", 0x2e5 },
{ "ccircumflex", 0x2e6 },
{ "gabovedot", 0x2f5 },
{ "gcircumflex", 0x2f8 },
{ "ubreve", 0x2fd },
{ "scircumflex", 0x2fe },
{ "kappa", 0x3a2 },
{ "Rcedilla", 0x3a3 },
{ "Itilde", 0x3a5 },
{ "Lcedilla", 0x3a6 },
{ "Emacron", 0x3aa },
{ "Gcedilla", 0x3ab },
{ "Tslash", 0x3ac },
{ "rcedilla", 0x3b3 },
{ "itilde", 0x3b5 },
{ "lcedilla", 0x3b6 },
{ "emacron", 0x3ba },
{ "gacute", 0x3bb },
{ "Ncaron", 0x1D2 },
{ "Odoubleacute", 0x1D5 },
{ "Rcaron", 0x1D8 },
{ "Uring", 0x1D9 },
{ "tslash", 0x3bc },
{ "Udoubleacute", 0x1DB },
{ "Tcedilla", 0x1DE },
{ "racute", 0x1E0 },
{ "ENG", 0x3bd },
{ "abreve", 0x1E3 },
{ "lacute", 0x1E5 },
{ "cacute", 0x1E6 },
{ "ccaron", 0x1E8 },
{ "eogonek", 0x1EA },
{ "ecaron", 0x1EC },
{ "dcaron", 0x1EF },
{ "dstroke", 0x1F0 },
{ "nacute", 0x1F1 },
{ "ncaron", 0x1F2 },
{ "odoubleacute", 0x1F5 },
{ "rcaron", 0x1F8 },
{ "uring", 0x1F9 },
{ "udoubleacute", 0x1FB },
{ "tcedilla", 0x1FE },
{ "abovedot", 0x1FF },
{ "Hstroke", 0x2A1 },
{ "eng", 0x3bf },
{ "Amacron", 0x3c0 },
{ "Iogonek", 0x3c7 },
{ "Eabovedot", 0x3cc },
{ "Imacron", 0x3cf },
{ "Hcircumflex", 0x2A6 },
{ "Iabovedot", 0x2A9 },
{ "Gbreve", 0x2AB },
{ "Jcircumflex", 0x2AC },
{ "hstroke", 0x2B1 },
{ "hcircumflex", 0x2B6 },
{ "idotless", 0x2B9 },
{ "gbreve", 0x2BB },
{ "jcircumflex", 0x2BC },
{ "Cabovedot", 0x2C5 },
{ "Ccircumflex", 0x2C6 },
{ "Gabovedot", 0x2D5 },
{ "Gcircumflex", 0x2D8 },
{ "Ubreve", 0x2DD },
{ "Scircumflex", 0x2DE },
{ "cabovedot", 0x2E5 },
{ "ccircumflex", 0x2E6 },
{ "gabovedot", 0x2F5 },
{ "gcircumflex", 0x2F8 },
{ "ubreve", 0x2FD },
{ "scircumflex", 0x2FE },
{ "kra", 0x3A2 },
{ "Ncedilla", 0x3d1 },
#ifndef TK_NO_DEPRECATED
{ "kappa", 0x3A2 },
{ "Omacron", 0x3d2 },
#endif
{ "Rcedilla", 0x3A3 },
{ "Itilde", 0x3A5 },
{ "Lcedilla", 0x3A6 },
{ "Emacron", 0x3AA },
{ "Gcedilla", 0x3AB },
{ "Tslash", 0x3AC },
{ "Kcedilla", 0x3d3 },
{ "Uogonek", 0x3d9 },
{ "Utilde", 0x3dd },
{ "Umacron", 0x3de },
{ "amacron", 0x3e0 },
{ "iogonek", 0x3e7 },
{ "eabovedot", 0x3ec },
{ "rcedilla", 0x3B3 },
{ "itilde", 0x3B5 },
{ "lcedilla", 0x3B6 },
{ "emacron", 0x3BA },
{ "imacron", 0x3ef },
{ "ncedilla", 0x3f1 },
{ "omacron", 0x3f2 },
{ "gcedilla", 0x3BB },
#ifndef TK_NO_DEPRECATED
{ "gacute", 0x3BB },
#endif
{ "tslash", 0x3BC },
{ "ENG", 0x3BD },
{ "eng", 0x3BF },
{ "Amacron", 0x3C0 },
{ "Iogonek", 0x3C7 },
{ "Eabovedot", 0x3CC },
{ "Imacron", 0x3CF },
{ "Ncedilla", 0x3D1 },
{ "Omacron", 0x3D2 },
{ "Kcedilla", 0x3D3 },
{ "Uogonek", 0x3D9 },
{ "Utilde", 0x3DD },
{ "Umacron", 0x3DE },
{ "amacron", 0x3E0 },
{ "iogonek", 0x3E7 },
{ "eabovedot", 0x3EC },
{ "imacron", 0x3EF },
{ "ncedilla", 0x3F1 },
{ "omacron", 0x3F2 },
{ "kcedilla", 0x3F3 },
{ "uogonek", 0x3F9 },
{ "utilde", 0x3FD },
{ "umacron", 0x3FE },
{ "kcedilla", 0x3f3 },
{ "uogonek", 0x3f9 },
{ "utilde", 0x3fd },
{ "umacron", 0x3fe },
{ "OE", 0x13BC },
{ "oe", 0x13BD },
{ "Ydiaeresis", 0x13BE },
{ "overline", 0x47E },
{ "kana_fullstop", 0x4A1 },
{ "kana_openingbracket", 0x4A2 },
{ "kana_closingbracket", 0x4A3 },
{ "kana_comma", 0x4A4 },
{ "overline", 0x47e },
{ "kana_fullstop", 0x4a1 },
{ "kana_openingbracket", 0x4a2 },
{ "kana_closingbracket", 0x4a3 },
{ "kana_comma", 0x4a4 },
{ "kana_conjunctive", 0x4A5 },
#ifndef TK_NO_DEPRECATED
{ "kana_middledot", 0x4A5 },
{ "kana_middledot", 0x4a5 },
#endif
{ "kana_WO", 0x4A6 },
{ "kana_a", 0x4A7 },
{ "kana_i", 0x4A8 },
{ "kana_u", 0x4A9 },
{ "kana_e", 0x4AA },
{ "kana_o", 0x4AB },
{ "kana_ya", 0x4AC },
{ "kana_yu", 0x4AD },
{ "kana_yo", 0x4AE },
{ "kana_WO", 0x4a6 },
{ "kana_a", 0x4a7 },
{ "kana_i", 0x4a8 },
{ "kana_u", 0x4a9 },
{ "kana_e", 0x4aa },
{ "kana_o", 0x4ab },
{ "kana_ya", 0x4ac },
{ "kana_yu", 0x4ad },
{ "kana_yo", 0x4ae },
{ "kana_tsu", 0x4AF },
#ifndef TK_NO_DEPRECATED
{ "kana_tu", 0x4AF },
{ "kana_tu", 0x4af },
#endif
{ "prolongedsound", 0x4B0 },
{ "kana_A", 0x4B1 },
{ "kana_I", 0x4B2 },
{ "kana_U", 0x4B3 },
{ "kana_E", 0x4B4 },
{ "kana_O", 0x4B5 },
{ "kana_KA", 0x4B6 },
{ "kana_KI", 0x4B7 },
{ "kana_KU", 0x4B8 },
{ "kana_KE", 0x4B9 },
{ "kana_KO", 0x4BA },
{ "kana_SA", 0x4BB },
{ "kana_SHI", 0x4BC },
{ "kana_SU", 0x4BD },
{ "kana_SE", 0x4BE },
{ "kana_SO", 0x4BF },
{ "kana_TA", 0x4C0 },
{ "prolongedsound", 0x4b0 },
{ "kana_A", 0x4b1 },
{ "kana_I", 0x4b2 },
{ "kana_U", 0x4b3 },
{ "kana_E", 0x4b4 },
{ "kana_O", 0x4b5 },
{ "kana_KA", 0x4b6 },
{ "kana_KI", 0x4b7 },
{ "kana_KU", 0x4b8 },
{ "kana_KE", 0x4b9 },
{ "kana_KO", 0x4ba },
{ "kana_SA", 0x4bb },
{ "kana_SHI", 0x4bc },
{ "kana_SU", 0x4bd },
{ "kana_SE", 0x4be },
{ "kana_SO", 0x4bf },
{ "kana_TA", 0x4c0 },
{ "kana_CHI", 0x4C1 },
#ifndef TK_NO_DEPRECATED
{ "kana_TI", 0x4C1 },
{ "kana_TI", 0x4c1 },
#endif
{ "kana_TSU", 0x4C2 },
#ifndef TK_NO_DEPRECATED
{ "kana_TU", 0x4C2 },
{ "kana_TU", 0x4c2 },
#endif
{ "kana_TE", 0x4C3 },
{ "kana_TO", 0x4C4 },
{ "kana_NA", 0x4C5 },
{ "kana_NI", 0x4C6 },
{ "kana_NU", 0x4C7 },
{ "kana_NE", 0x4C8 },
{ "kana_NO", 0x4C9 },
{ "kana_HA", 0x4CA },
{ "kana_HI", 0x4CB },
{ "kana_TE", 0x4c3 },
{ "kana_TO", 0x4c4 },
{ "kana_NA", 0x4c5 },
{ "kana_NI", 0x4c6 },
{ "kana_NU", 0x4c7 },
{ "kana_NE", 0x4c8 },
{ "kana_NO", 0x4c9 },
{ "kana_HA", 0x4ca },
{ "kana_HI", 0x4cb },
{ "kana_FU", 0x4CC },
#ifndef TK_NO_DEPRECATED
{ "kana_HU", 0x4CC },
{ "kana_HU", 0x4cc },
#endif
{ "kana_HE", 0x4CD },
{ "kana_HO", 0x4CE },
{ "kana_MA", 0x4CF },
{ "kana_MI", 0x4D0 },
{ "kana_MU", 0x4D1 },
{ "kana_ME", 0x4D2 },
{ "kana_MO", 0x4D3 },
{ "kana_YA", 0x4D4 },
{ "kana_YU", 0x4D5 },
{ "kana_YO", 0x4D6 },
{ "kana_RA", 0x4D7 },
{ "kana_RI", 0x4D8 },
{ "kana_RU", 0x4D9 },
{ "kana_RE", 0x4DA },
{ "kana_RO", 0x4DB },
{ "kana_WA", 0x4DC },
{ "kana_N", 0x4DD },
{ "voicedsound", 0x4DE },
{ "semivoicedsound", 0x4DF },
{ "Arabic_comma", 0x5AC },
{ "Arabic_semicolon", 0x5BB },
{ "Arabic_question_mark", 0x5BF },
{ "Arabic_hamza", 0x5C1 },
{ "Arabic_maddaonalef", 0x5C2 },
{ "Arabic_hamzaonalef", 0x5C3 },
{ "Arabic_hamzaonwaw", 0x5C4 },
{ "Arabic_hamzaunderalef", 0x5C5 },
{ "Arabic_hamzaonyeh", 0x5C6 },
{ "Arabic_alef", 0x5C7 },
{ "Arabic_beh", 0x5C8 },
{ "Arabic_tehmarbuta", 0x5C9 },
{ "Arabic_teh", 0x5CA },
{ "Arabic_theh", 0x5CB },
{ "Arabic_jeem", 0x5CC },
{ "Arabic_hah", 0x5CD },
{ "Arabic_khah", 0x5CE },
{ "Arabic_dal", 0x5CF },
{ "Arabic_thal", 0x5D0 },
{ "Arabic_ra", 0x5D1 },
{ "Arabic_zain", 0x5D2 },
{ "Arabic_seen", 0x5D3 },
{ "Arabic_sheen", 0x5D4 },
{ "Arabic_sad", 0x5D5 },
{ "Arabic_dad", 0x5D6 },
{ "Arabic_tah", 0x5D7 },
{ "Arabic_zah", 0x5D8 },
{ "Arabic_ain", 0x5D9 },
{ "Arabic_ghain", 0x5DA },
{ "Arabic_tatweel", 0x5E0 },
{ "Arabic_feh", 0x5E1 },
{ "Arabic_qaf", 0x5E2 },
{ "Arabic_kaf", 0x5E3 },
{ "Arabic_lam", 0x5E4 },
{ "Arabic_meem", 0x5E5 },
{ "Arabic_noon", 0x5E6 },
{ "kana_HE", 0x4cd },
{ "kana_HO", 0x4ce },
{ "kana_MA", 0x4cf },
{ "kana_MI", 0x4d0 },
{ "kana_MU", 0x4d1 },
{ "kana_ME", 0x4d2 },
{ "kana_MO", 0x4d3 },
{ "kana_YA", 0x4d4 },
{ "kana_YU", 0x4d5 },
{ "kana_YO", 0x4d6 },
{ "kana_RA", 0x4d7 },
{ "kana_RI", 0x4d8 },
{ "kana_RU", 0x4d9 },
{ "kana_RE", 0x4da },
{ "kana_RO", 0x4db },
{ "kana_WA", 0x4dc },
{ "kana_N", 0x4dd },
{ "voicedsound", 0x4de },
{ "semivoicedsound", 0x4df },
{ "kana_switch", 0xFF7E },
{ "Arabic_comma", 0x5ac },
{ "Arabic_semicolon", 0x5bb },
{ "Arabic_question_mark", 0x5bf },
{ "Arabic_hamza", 0x5c1 },
{ "Arabic_maddaonalef", 0x5c2 },
{ "Arabic_hamzaonalef", 0x5c3 },
{ "Arabic_hamzaonwaw", 0x5c4 },
{ "Arabic_hamzaunderalef", 0x5c5 },
{ "Arabic_hamzaonyeh", 0x5c6 },
{ "Arabic_alef", 0x5c7 },
{ "Arabic_beh", 0x5c8 },
{ "Arabic_tehmarbuta", 0x5c9 },
{ "Arabic_teh", 0x5ca },
{ "Arabic_theh", 0x5cb },
{ "Arabic_jeem", 0x5cc },
{ "Arabic_hah", 0x5cd },
{ "Arabic_khah", 0x5ce },
{ "Arabic_dal", 0x5cf },
{ "Arabic_thal", 0x5d0 },
{ "Arabic_ra", 0x5d1 },
{ "Arabic_zain", 0x5d2 },
{ "Arabic_seen", 0x5d3 },
{ "Arabic_sheen", 0x5d4 },
{ "Arabic_sad", 0x5d5 },
{ "Arabic_dad", 0x5d6 },
{ "Arabic_tah", 0x5d7 },
{ "Arabic_zah", 0x5d8 },
{ "Arabic_ain", 0x5d9 },
{ "Arabic_ghain", 0x5da },
{ "Arabic_tatweel", 0x5e0 },
{ "Arabic_feh", 0x5e1 },
{ "Arabic_qaf", 0x5e2 },
{ "Arabic_kaf", 0x5e3 },
{ "Arabic_lam", 0x5e4 },
{ "Arabic_meem", 0x5e5 },
{ "Arabic_noon", 0x5e6 },
{ "Arabic_ha", 0x5E7 },
#ifndef TK_NO_DEPRECATED
{ "Arabic_heh", 0x5E7 },
{ "Arabic_heh", 0x5e7 },
#endif
{ "Arabic_waw", 0x5E8 },
{ "Arabic_alefmaksura", 0x5E9 },
{ "Arabic_yeh", 0x5EA },
{ "Arabic_fathatan", 0x5EB },
{ "Arabic_dammatan", 0x5EC },
{ "Arabic_kasratan", 0x5ED },
{ "Arabic_fatha", 0x5EE },
{ "Arabic_damma", 0x5EF },
{ "Arabic_kasra", 0x5F0 },
{ "Arabic_shadda", 0x5F1 },
{ "Arabic_sukun", 0x5F2 },
{ "Serbian_dje", 0x6A1 },
{ "Macedonia_gje", 0x6A2 },
{ "Cyrillic_io", 0x6A3 },
{ "Arabic_waw", 0x5e8 },
{ "Arabic_alefmaksura", 0x5e9 },
{ "Arabic_yeh", 0x5ea },
{ "Arabic_fathatan", 0x5eb },
{ "Arabic_dammatan", 0x5ec },
{ "Arabic_kasratan", 0x5ed },
{ "Arabic_fatha", 0x5ee },
{ "Arabic_damma", 0x5ef },
{ "Arabic_kasra", 0x5f0 },
{ "Arabic_shadda", 0x5f1 },
{ "Arabic_sukun", 0x5f2 },
{ "Arabic_switch", 0xFF7E },
{ "Serbian_dje", 0x6a1 },
{ "Macedonia_gje", 0x6a2 },
{ "Cyrillic_io", 0x6a3 },
{ "Ukrainian_ie", 0x6A4 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_je", 0x6A4 },
{ "Ukranian_je", 0x6a4 },
#endif
{ "Macedonia_dse", 0x6A5 },
{ "Macedonia_dse", 0x6a5 },
{ "Ukrainian_i", 0x6A6 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_i", 0x6A6 },
{ "Ukranian_i", 0x6a6 },
#endif
{ "Ukrainian_yi", 0x6A7 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_yi", 0x6A7 },
{ "Ukranian_yi", 0x6a7 },
#endif
{ "Cyrillic_je", 0x6A8 },
#ifndef TK_NO_DEPRECATED
{ "Serbian_je", 0x6A8 },
{ "Serbian_je", 0x6a8 },
#endif
{ "Cyrillic_lje", 0x6A9 },
#ifndef TK_NO_DEPRECATED
{ "Serbian_lje", 0x6A9 },
{ "Serbian_lje", 0x6a9 },
#endif
{ "Cyrillic_nje", 0x6AA },
#ifndef TK_NO_DEPRECATED
{ "Serbian_nje", 0x6AA },
{ "Serbian_nje", 0x6aa },
#endif
{ "Serbian_tshe", 0x6AB },
{ "Macedonia_kje", 0x6AC },
{ "Serbian_tshe", 0x6ab },
{ "Macedonia_kje", 0x6ac },
{ "Ukrainian_ghe_with_upturn", 0x6AD },
{ "Byelorussian_shortu", 0x6AE },
{ "Byelorussian_shortu", 0x6ae },
{ "Cyrillic_dzhe", 0x6AF },
#ifndef TK_NO_DEPRECATED
{ "Serbian_dze", 0x6AF },
{ "Serbian_dze", 0x6af },
#endif
{ "numerosign", 0x6B0 },
{ "Serbian_DJE", 0x6B1 },
{ "Macedonia_GJE", 0x6B2 },
{ "Cyrillic_IO", 0x6B3 },
{ "numerosign", 0x6b0 },
{ "Serbian_DJE", 0x6b1 },
{ "Macedonia_GJE", 0x6b2 },
{ "Cyrillic_IO", 0x6b3 },
{ "Ukrainian_IE", 0x6B4 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_JE", 0x6B4 },
{ "Ukranian_JE", 0x6b4 },
#endif
{ "Macedonia_DSE", 0x6B5 },
{ "Macedonia_DSE", 0x6b5 },
{ "Ukrainian_I", 0x6B6 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_I", 0x6B6 },
{ "Ukranian_I", 0x6b6 },
#endif
{ "Ukrainian_YI", 0x6B7 },
#ifndef TK_NO_DEPRECATED
{ "Ukranian_YI", 0x6B7 },
{ "Ukranian_YI", 0x6b7 },
#endif
{ "Cyrillic_JE", 0x6B8 },
#ifndef TK_NO_DEPRECATED
{ "Serbian_JE", 0x6B8 },
{ "Serbian_JE", 0x6b8 },
#endif
{ "Cyrillic_LJE", 0x6B9 },
#ifndef TK_NO_DEPRECATED
{ "Serbian_LJE", 0x6B9 },
{ "Serbian_LJE", 0x6b9 },
#endif
{ "Cyrillic_NJE", 0x6BA },
#ifndef TK_NO_DEPRECATED
{ "Serbian_NJE", 0x6BA },
{ "Serbian_NJE", 0x6ba },
#endif
{ "Serbian_TSHE", 0x6BB },
{ "Macedonia_KJE", 0x6BC },
{ "Serbian_TSHE", 0x6bb },
{ "Macedonia_KJE", 0x6bc },
{ "Ukrainian_GHE_WITH_UPTURN", 0x6BD },
{ "Byelorussian_SHORTU", 0x6BE },
{ "Byelorussian_SHORTU", 0x6be },
{ "Cyrillic_DZHE", 0x6BF },
#ifndef TK_NO_DEPRECATED
{ "Serbian_DZE", 0x6BF },
{ "Serbian_DZE", 0x6bf },
#endif
{ "Cyrillic_yu", 0x6C0 },
{ "Cyrillic_a", 0x6C1 },
{ "Cyrillic_be", 0x6C2 },
{ "Cyrillic_tse", 0x6C3 },
{ "Cyrillic_de", 0x6C4 },
{ "Cyrillic_ie", 0x6C5 },
{ "Cyrillic_ef", 0x6C6 },
{ "Cyrillic_ghe", 0x6C7 },
{ "Cyrillic_ha", 0x6C8 },
{ "Cyrillic_i", 0x6C9 },
{ "Cyrillic_shorti", 0x6CA },
{ "Cyrillic_ka", 0x6CB },
{ "Cyrillic_el", 0x6CC },
{ "Cyrillic_em", 0x6CD },
{ "Cyrillic_en", 0x6CE },
{ "Cyrillic_o", 0x6CF },
{ "Cyrillic_pe", 0x6D0 },
{ "Cyrillic_ya", 0x6D1 },
{ "Cyrillic_er", 0x6D2 },
{ "Cyrillic_es", 0x6D3 },
{ "Cyrillic_te", 0x6D4 },
{ "Cyrillic_u", 0x6D5 },
{ "Cyrillic_zhe", 0x6D6 },
{ "Cyrillic_ve", 0x6D7 },
{ "Cyrillic_softsign", 0x6D8 },
{ "Cyrillic_yeru", 0x6D9 },
{ "Cyrillic_ze", 0x6DA },
{ "Cyrillic_sha", 0x6DB },
{ "Cyrillic_e", 0x6DC },
{ "Cyrillic_shcha", 0x6DD },
{ "Cyrillic_che", 0x6DE },
{ "Cyrillic_hardsign", 0x6DF },
{ "Cyrillic_YU", 0x6E0 },
{ "Cyrillic_A", 0x6E1 },
{ "Cyrillic_BE", 0x6E2 },
{ "Cyrillic_TSE", 0x6E3 },
{ "Cyrillic_DE", 0x6E4 },
{ "Cyrillic_IE", 0x6E5 },
{ "Cyrillic_EF", 0x6E6 },
{ "Cyrillic_GHE", 0x6E7 },
{ "Cyrillic_HA", 0x6E8 },
{ "Cyrillic_I", 0x6E9 },
{ "Cyrillic_SHORTI", 0x6EA },
{ "Cyrillic_KA", 0x6EB },
{ "Cyrillic_EL", 0x6EC },
{ "Cyrillic_EM", 0x6ED },
{ "Cyrillic_EN", 0x6EE },
{ "Cyrillic_O", 0x6EF },
{ "Cyrillic_PE", 0x6F0 },
{ "Cyrillic_YA", 0x6F1 },
{ "Cyrillic_ER", 0x6F2 },
{ "Cyrillic_ES", 0x6F3 },
{ "Cyrillic_TE", 0x6F4 },
{ "Cyrillic_U", 0x6F5 },
{ "Cyrillic_ZHE", 0x6F6 },
{ "Cyrillic_VE", 0x6F7 },
{ "Cyrillic_SOFTSIGN", 0x6F8 },
{ "Cyrillic_YERU", 0x6F9 },
{ "Cyrillic_ZE", 0x6FA },
{ "Cyrillic_SHA", 0x6FB },
{ "Cyrillic_E", 0x6FC },
{ "Cyrillic_SHCHA", 0x6FD },
{ "Cyrillic_CHE", 0x6FE },
{ "Cyrillic_HARDSIGN", 0x6FF },
{ "Greek_ALPHAaccent", 0x7A1 },
{ "Greek_EPSILONaccent", 0x7A2 },
{ "Greek_ETAaccent", 0x7A3 },
{ "Greek_IOTAaccent", 0x7A4 },
{ "Cyrillic_yu", 0x6c0 },
{ "Cyrillic_a", 0x6c1 },
{ "Cyrillic_be", 0x6c2 },
{ "Cyrillic_tse", 0x6c3 },
{ "Cyrillic_de", 0x6c4 },
{ "Cyrillic_ie", 0x6c5 },
{ "Cyrillic_ef", 0x6c6 },
{ "Cyrillic_ghe", 0x6c7 },
{ "Cyrillic_ha", 0x6c8 },
{ "Cyrillic_i", 0x6c9 },
{ "Cyrillic_shorti", 0x6ca },
{ "Cyrillic_ka", 0x6cb },
{ "Cyrillic_el", 0x6cc },
{ "Cyrillic_em", 0x6cd },
{ "Cyrillic_en", 0x6ce },
{ "Cyrillic_o", 0x6cf },
{ "Cyrillic_pe", 0x6d0 },
{ "Cyrillic_ya", 0x6d1 },
{ "Cyrillic_er", 0x6d2 },
{ "Cyrillic_es", 0x6d3 },
{ "Cyrillic_te", 0x6d4 },
{ "Cyrillic_u", 0x6d5 },
{ "Cyrillic_zhe", 0x6d6 },
{ "Cyrillic_ve", 0x6d7 },
{ "Cyrillic_softsign", 0x6d8 },
{ "Cyrillic_yeru", 0x6d9 },
{ "Cyrillic_ze", 0x6da },
{ "Cyrillic_sha", 0x6db },
{ "Cyrillic_e", 0x6dc },
{ "Cyrillic_shcha", 0x6dd },
{ "Cyrillic_che", 0x6de },
{ "Cyrillic_hardsign", 0x6df },
{ "Cyrillic_YU", 0x6e0 },
{ "Cyrillic_A", 0x6e1 },
{ "Cyrillic_BE", 0x6e2 },
{ "Cyrillic_TSE", 0x6e3 },
{ "Cyrillic_DE", 0x6e4 },
{ "Cyrillic_IE", 0x6e5 },
{ "Cyrillic_EF", 0x6e6 },
{ "Cyrillic_GHE", 0x6e7 },
{ "Cyrillic_HA", 0x6e8 },
{ "Cyrillic_I", 0x6e9 },
{ "Cyrillic_SHORTI", 0x6ea },
{ "Cyrillic_KA", 0x6eb },
{ "Cyrillic_EL", 0x6ec },
{ "Cyrillic_EM", 0x6ed },
{ "Cyrillic_EN", 0x6ee },
{ "Cyrillic_O", 0x6ef },
{ "Cyrillic_PE", 0x6f0 },
{ "Cyrillic_YA", 0x6f1 },
{ "Cyrillic_ER", 0x6f2 },
{ "Cyrillic_ES", 0x6f3 },
{ "Cyrillic_TE", 0x6f4 },
{ "Cyrillic_U", 0x6f5 },
{ "Cyrillic_ZHE", 0x6f6 },
{ "Cyrillic_VE", 0x6f7 },
{ "Cyrillic_SOFTSIGN", 0x6f8 },
{ "Cyrillic_YERU", 0x6f9 },
{ "Cyrillic_ZE", 0x6fa },
{ "Cyrillic_SHA", 0x6fb },
{ "Cyrillic_E", 0x6fc },
{ "Cyrillic_SHCHA", 0x6fd },
{ "Cyrillic_CHE", 0x6fe },
{ "Cyrillic_HARDSIGN", 0x6ff },
{ "Greek_ALPHAaccent", 0x7a1 },
{ "Greek_EPSILONaccent", 0x7a2 },
{ "Greek_ETAaccent", 0x7a3 },
{ "Greek_IOTAaccent", 0x7a4 },
{ "Greek_IOTAdieresis", 0x7A5 },
#ifndef TK_NO_DEPRECATED
{ "Greek_IOTAdiaeresis", 0x7A5 },
{ "Greek_IOTAdiaeresis", 0x7a5 },
#endif
{ "Greek_IOTAaccentdiaeresis", 0x7A6 },
{ "Greek_OMICRONaccent", 0x7A7 },
{ "Greek_UPSILONaccent", 0x7A8 },
{ "Greek_UPSILONdieresis", 0x7A9 },
{ "Greek_UPSILONaccentdieresis", 0x7AA },
{ "Greek_OMEGAaccent", 0x7AB },
{ "Greek_IOTAaccentdiaeresis", 0x7a6 },
{ "Greek_OMICRONaccent", 0x7a7 },
{ "Greek_UPSILONaccent", 0x7a8 },
{ "Greek_UPSILONdieresis", 0x7a9 },
{ "Greek_UPSILONaccentdieresis", 0x7aa },
{ "Greek_OMEGAaccent", 0x7ab },
{ "Greek_accentdieresis", 0x7AE },
{ "Greek_horizbar", 0x7AF },
{ "Greek_alphaaccent", 0x7B1 },
{ "Greek_epsilonaccent", 0x7B2 },
{ "Greek_etaaccent", 0x7B3 },
{ "Greek_iotaaccent", 0x7B4 },
{ "Greek_iotadieresis", 0x7B5 },
{ "Greek_iotaaccentdieresis", 0x7B6 },
{ "Greek_omicronaccent", 0x7B7 },
{ "Greek_upsilonaccent", 0x7B8 },
{ "Greek_upsilondieresis", 0x7B9 },
{ "Greek_upsilonaccentdieresis", 0x7BA },
{ "Greek_omegaaccent", 0x7BB },
{ "Greek_ALPHA", 0x7C1 },
{ "Greek_BETA", 0x7C2 },
{ "Greek_GAMMA", 0x7C3 },
{ "Greek_DELTA", 0x7C4 },
{ "Greek_EPSILON", 0x7C5 },
{ "Greek_ZETA", 0x7C6 },
{ "Greek_ETA", 0x7C7 },
{ "Greek_THETA", 0x7C8 },
{ "Greek_IOTA", 0x7C9 },
{ "Greek_KAPPA", 0x7CA },
{ "Greek_alphaaccent", 0x7b1 },
{ "Greek_epsilonaccent", 0x7b2 },
{ "Greek_etaaccent", 0x7b3 },
{ "Greek_iotaaccent", 0x7b4 },
{ "Greek_iotadieresis", 0x7b5 },
{ "Greek_iotaaccentdieresis", 0x7b6 },
{ "Greek_omicronaccent", 0x7b7 },
{ "Greek_upsilonaccent", 0x7b8 },
{ "Greek_upsilondieresis", 0x7b9 },
{ "Greek_upsilonaccentdieresis", 0x7ba },
{ "Greek_omegaaccent", 0x7bb },
{ "Greek_ALPHA", 0x7c1 },
{ "Greek_BETA", 0x7c2 },
{ "Greek_GAMMA", 0x7c3 },
{ "Greek_DELTA", 0x7c4 },
{ "Greek_EPSILON", 0x7c5 },
{ "Greek_ZETA", 0x7c6 },
{ "Greek_ETA", 0x7c7 },
{ "Greek_THETA", 0x7c8 },
{ "Greek_IOTA", 0x7c9 },
{ "Greek_KAPPA", 0x7ca },
{ "Greek_LAMDA", 0x7CB },
{ "Greek_LAMBDA", 0x7CB },
{ "Greek_LAMBDA", 0x7cb },
{ "Greek_MU", 0x7CC },
{ "Greek_NU", 0x7CD },
{ "Greek_XI", 0x7CE },
{ "Greek_OMICRON", 0x7CF },
{ "Greek_PI", 0x7D0 },
{ "Greek_RHO", 0x7D1 },
{ "Greek_SIGMA", 0x7D2 },
{ "Greek_TAU", 0x7D4 },
{ "Greek_UPSILON", 0x7D5 },
{ "Greek_PHI", 0x7D6 },
{ "Greek_CHI", 0x7D7 },
{ "Greek_PSI", 0x7D8 },
{ "Greek_OMEGA", 0x7D9 },
{ "Greek_alpha", 0x7E1 },
{ "Greek_beta", 0x7E2 },
{ "Greek_gamma", 0x7E3 },
{ "Greek_delta", 0x7E4 },
{ "Greek_epsilon", 0x7E5 },
{ "Greek_zeta", 0x7E6 },
{ "Greek_eta", 0x7E7 },
{ "Greek_theta", 0x7E8 },
{ "Greek_iota", 0x7E9 },
{ "Greek_kappa", 0x7EA },
{ "Greek_lamda", 0x7EB },
{ "Greek_lambda", 0x7EB },
{ "Greek_mu", 0x7EC },
{ "Greek_nu", 0x7ED },
{ "Greek_xi", 0x7EE },
{ "Greek_omicron", 0x7EF },
{ "Greek_pi", 0x7F0 },
{ "Greek_rho", 0x7F1 },
{ "Greek_sigma", 0x7F2 },
{ "Greek_MU", 0x7cc },
{ "Greek_NU", 0x7cd },
{ "Greek_XI", 0x7ce },
{ "Greek_OMICRON", 0x7cf },
{ "Greek_PI", 0x7d0 },
{ "Greek_RHO", 0x7d1 },
{ "Greek_SIGMA", 0x7d2 },
{ "Greek_TAU", 0x7d4 },
{ "Greek_UPSILON", 0x7d5 },
{ "Greek_PHI", 0x7d6 },
{ "Greek_CHI", 0x7d7 },
{ "Greek_finalsmallsigma", 0x7F3 },
{ "Greek_tau", 0x7F4 },
{ "Greek_upsilon", 0x7F5 },
{ "Greek_phi", 0x7F6 },
{ "Greek_chi", 0x7F7 },
{ "Greek_psi", 0x7F8 },
{ "Greek_omega", 0x7F9 },
{ "Greek_PSI", 0x7d8 },
{ "Greek_OMEGA", 0x7d9 },
{ "Greek_alpha", 0x7e1 },
{ "Greek_beta", 0x7e2 },
{ "Greek_gamma", 0x7e3 },
{ "Greek_delta", 0x7e4 },
{ "leftradical", 0x8A1 },
{ "topleftradical", 0x8A2 },
{ "horizconnector", 0x8A3 },
{ "topintegral", 0x8A4 },
{ "botintegral", 0x8A5 },
{ "vertconnector", 0x8A6 },
{ "topleftsqbracket", 0x8A7 },
{ "botleftsqbracket", 0x8A8 },
{ "toprightsqbracket", 0x8A9 },
{ "botrightsqbracket", 0x8AA },
{ "topleftparens", 0x8AB },
{ "botleftparens", 0x8AC },
{ "toprightparens", 0x8AD },
{ "botrightparens", 0x8AE },
{ "leftmiddlecurlybrace", 0x8AF },
{ "rightmiddlecurlybrace", 0x8B0 },
{ "topleftsummation", 0x8B1 },
{ "botleftsummation", 0x8B2 },
{ "topvertsummationconnector", 0x8B3 },
{ "botvertsummationconnector", 0x8B4 },
{ "toprightsummation", 0x8B5 },
{ "botrightsummation", 0x8B6 },
{ "rightmiddlesummation", 0x8B7 },
{ "lessthanequal", 0x8BC },
{ "notequal", 0x8BD },
{ "greaterthanequal", 0x8BE },
{ "integral", 0x8BF },
{ "therefore", 0x8C0 },
{ "variation", 0x8C1 },
{ "infinity", 0x8C2 },
{ "nabla", 0x8C5 },
{ "Greek_epsilon", 0x7e5 },
{ "Greek_zeta", 0x7e6 },
{ "Greek_eta", 0x7e7 },
{ "approximate", 0x8C8 },
{ "similarequal", 0x8C9 },
{ "ifonlyif", 0x8CD },
{ "implies", 0x8CE },
{ "identical", 0x8CF },
{ "radical", 0x8D6 },
{ "Greek_theta", 0x7e8 },
{ "Greek_iota", 0x7e9 },
{ "Greek_kappa", 0x7ea },
{ "Greek_lambda", 0x7eb },
{ "includedin", 0x8DA },
{ "includes", 0x8DB },
{ "Greek_mu", 0x7ec },
{ "intersection", 0x8DC },
{ "union", 0x8DD },
{ "Greek_nu", 0x7ed },
{ "logicaland", 0x8DE },
{ "logicalor", 0x8DF },
{ "Greek_xi", 0x7ee },
{ "partialderivative", 0x8EF },
{ "function", 0x8F6 },
{ "Greek_omicron", 0x7ef },
{ "leftarrow", 0x8FB },
{ "uparrow", 0x8FC },
{ "Greek_pi", 0x7f0 },
{ "rightarrow", 0x8FD },
{ "downarrow", 0x8FE },
{ "blank", 0x9DF },
{ "Greek_rho", 0x7f1 },
{ "soliddiamond", 0x9E0 },
{ "checkerboard", 0x9E1 },
{ "ht", 0x9E2 },
{ "ff", 0x9E3 },
{ "cr", 0x9E4 },
{ "lf", 0x9E5 },
{ "nl", 0x9E8 },
{ "vt", 0x9E9 },
{ "Greek_sigma", 0x7f2 },
{ "Greek_finalsmallsigma", 0x7f3 },
{ "Greek_tau", 0x7f4 },
{ "Greek_upsilon", 0x7f5 },
{ "Greek_phi", 0x7f6 },
{ "Greek_chi", 0x7f7 },
{ "lowrightcorner", 0x9EA },
{ "uprightcorner", 0x9EB },
{ "upleftcorner", 0x9EC },
{ "lowleftcorner", 0x9ED },
{ "crossinglines", 0x9EE },
{ "horizlinescan1", 0x9EF },
{ "horizlinescan3", 0x9F0 },
{ "horizlinescan5", 0x9F1 },
{ "horizlinescan7", 0x9F2 },
{ "horizlinescan9", 0x9F3 },
{ "leftt", 0x9F4 },
{ "Greek_psi", 0x7f8 },
{ "Greek_omega", 0x7f9 },
{ "Greek_switch", 0xFF7E },
{ "leftradical", 0x8a1 },
{ "topleftradical", 0x8a2 },
{ "horizconnector", 0x8a3 },
{ "topintegral", 0x8a4 },
{ "rightt", 0x9F5 },
{ "bott", 0x9F6 },
{ "botintegral", 0x8a5 },
{ "topt", 0x9F7 },
{ "vertbar", 0x9F8 },
{ "emspace", 0xAA1 },
{ "enspace", 0xAA2 },
{ "vertconnector", 0x8a6 },
{ "topleftsqbracket", 0x8a7 },
{ "botleftsqbracket", 0x8a8 },
{ "em3space", 0xAA3 },
{ "em4space", 0xAA4 },
{ "digitspace", 0xAA5 },
{ "punctspace", 0xAA6 },
{ "thinspace", 0xAA7 },
{ "hairspace", 0xAA8 },
{ "emdash", 0xAA9 },
{ "endash", 0xAAA },
{ "toprightsqbracket", 0x8a9 },
{ "botrightsqbracket", 0x8aa },
{ "signifblank", 0xAAC },
{ "ellipsis", 0xAAE },
{ "topleftparens", 0x8ab },
{ "doubbaselinedot", 0xAAF },
{ "onethird", 0xAB0 },
{ "twothirds", 0xAB1 },
{ "botleftparens", 0x8ac },
{ "onefifth", 0xAB2 },
{ "twofifths", 0xAB3 },
{ "threefifths", 0xAB4 },
{ "toprightparens", 0x8ad },
{ "botrightparens", 0x8ae },
{ "fourfifths", 0xAB5 },
{ "onesixth", 0xAB6 },
{ "fivesixths", 0xAB7 },
{ "careof", 0xAB8 },
{ "figdash", 0xABB },
{ "leftanglebracket", 0xABC },
{ "leftmiddlecurlybrace", 0x8af },
{ "decimalpoint", 0xABD },
{ "rightanglebracket", 0xABE },
{ "marker", 0xABF },
{ "rightmiddlecurlybrace", 0x8b0 },
{ "topleftsummation", 0x8b1 },
{ "oneeighth", 0xAC3 },
{ "threeeighths", 0xAC4 },
{ "fiveeighths", 0xAC5 },
{ "seveneighths", 0xAC6 },
{ "trademark", 0xAC9 },
{ "signaturemark", 0xACA },
{ "trademarkincircle", 0xACB },
{ "botleftsummation", 0x8b2 },
{ "topvertsummationconnector", 0x8b3 },
{ "botvertsummationconnector", 0x8b4 },
{ "toprightsummation", 0x8b5 },
{ "botrightsummation", 0x8b6 },
{ "leftopentriangle", 0xACC },
{ "rightopentriangle", 0xACD },
{ "emopencircle", 0xACE },
{ "emopenrectangle", 0xACF },
{ "leftsinglequotemark", 0xAD0 },
{ "rightmiddlesummation", 0x8b7 },
{ "lessthanequal", 0x8bc },
{ "notequal", 0x8bd },
{ "greaterthanequal", 0x8be },
{ "rightsinglequotemark", 0xAD1 },
{ "leftdoublequotemark", 0xAD2 },
{ "rightdoublequotemark", 0xAD3 },
{ "prescription", 0xAD4 },
{ "integral", 0x8bf },
{ "therefore", 0x8c0 },
{ "variation", 0x8c1 },
{ "permille", 0xAD5 },
{ "minutes", 0xAD6 },
{ "seconds", 0xAD7 },
{ "infinity", 0x8c2 },
{ "nabla", 0x8c5 },
{ "latincross", 0xAD9 },
{ "hexagram", 0xADA },
{ "filledrectbullet", 0xADB },
{ "filledlefttribullet", 0xADC },
{ "filledrighttribullet", 0xADD },
{ "emfilledcircle", 0xADE },
{ "emfilledrect", 0xADF },
{ "approximate", 0x8c8 },
{ "similarequal", 0x8c9 },
{ "enopencircbullet", 0xAE0 },
{ "enopensquarebullet", 0xAE1 },
{ "openrectbullet", 0xAE2 },
{ "ifonlyif", 0x8cd },
{ "opentribulletup", 0xAE3 },
{ "opentribulletdown", 0xAE4 },
{ "openstar", 0xAE5 },
{ "implies", 0x8ce },
{ "enfilledcircbullet", 0xAE6 },
{ "enfilledsqbullet", 0xAE7 },
{ "filledtribulletup", 0xAE8 },
{ "filledtribulletdown", 0xAE9 },
{ "leftpointer", 0xAEA },
{ "rightpointer", 0xAEB },
{ "club", 0xAEC },
{ "diamond", 0xAED },
{ "heart", 0xAEE },
{ "maltesecross", 0xAF0 },
{ "dagger", 0xAF1 },
{ "identical", 0x8cf },
{ "radical", 0x8d6 },
{ "includedin", 0x8da },
{ "includes", 0x8db },
{ "intersection", 0x8dc },
{ "doubledagger", 0xAF2 },
{ "checkmark", 0xAF3 },
{ "union", 0x8dd },
{ "ballotcross", 0xAF4 },
{ "musicalsharp", 0xAF5 },
{ "musicalflat", 0xAF6 },
{ "malesymbol", 0xAF7 },
{ "femalesymbol", 0xAF8 },
{ "telephone", 0xAF9 },
{ "telephonerecorder", 0xAFA },
{ "phonographcopyright", 0xAFB },
{ "caret", 0xAFC },
{ "logicaland", 0x8de },
{ "logicalor", 0x8df },
{ "partialderivative", 0x8ef },
{ "function", 0x8f6 },
{ "singlelowquotemark", 0xAFD },
{ "doublelowquotemark", 0xAFE },
{ "cursor", 0xAFF },
{ "leftcaret", 0xBA3 },
{ "rightcaret", 0xBA6 },
{ "downcaret", 0xBA8 },
{ "leftarrow", 0x8fb },
{ "uparrow", 0x8fc },
{ "rightarrow", 0x8fd },
{ "downarrow", 0x8fe },
{ "upcaret", 0xBA9 },
{ "overbar", 0xBC0 },
{ "downtack", 0xBC2 },
{ "upshoe", 0xBC3 },
{ "downstile", 0xBC4 },
{ "blank", 0x9df },
{ "soliddiamond", 0x9e0 },
{ "checkerboard", 0x9e1 },
{ "underbar", 0xBC6 },
{ "jot", 0xBCA },
{ "quad", 0xBCC },
{ "uptack", 0xBCE },
{ "circle", 0xBCF },
{ "upstile", 0xBD3 },
{ "downshoe", 0xBD6 },
{ "rightshoe", 0xBD8 },
{ "ht", 0x9e2 },
{ "ff", 0x9e3 },
{ "cr", 0x9e4 },
{ "lf", 0x9e5 },
{ "nl", 0x9e8 },
{ "vt", 0x9e9 },
{ "lowrightcorner", 0x9ea },
{ "leftshoe", 0xBDA },
{ "lefttack", 0xBDC },
{ "righttack", 0xBFC },
{ "uprightcorner", 0x9eb },
{ "hebrew_doublelowline", 0xCDF },
{ "hebrew_aleph", 0xCE0 },
{ "hebrew_bet", 0xCE1 },
{ "upleftcorner", 0x9ec },
{ "lowleftcorner", 0x9ed },
#ifndef TK_NO_DEPRECATED
{ "hebrew_beth", 0xCE1 },
{ "crossinglines", 0x9ee },
#endif
{ "hebrew_gimel", 0xCE2 },
{ "horizlinescan1", 0x9ef },
#ifndef TK_NO_DEPRECATED
{ "hebrew_gimmel", 0xCE2 },
{ "horizlinescan3", 0x9f0 },
#endif
{ "hebrew_dalet", 0xCE3 },
{ "horizlinescan5", 0x9f1 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_daleth", 0xCE3 },
{ "horizlinescan7", 0x9f2 },
#endif
{ "hebrew_he", 0xCE4 },
{ "hebrew_waw", 0xCE5 },
{ "hebrew_zain", 0xCE6 },
{ "horizlinescan9", 0x9f3 },
{ "leftt", 0x9f4 },
{ "rightt", 0x9f5 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_zayin", 0xCE6 },
{ "bott", 0x9f6 },
#endif
{ "hebrew_chet", 0xCE7 },
{ "topt", 0x9f7 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_het", 0xCE7 },
{ "vertbar", 0x9f8 },
#endif
{ "hebrew_tet", 0xCE8 },
{ "emspace", 0xaa1 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_teth", 0xCE8 },
{ "enspace", 0xaa2 },
#endif
{ "hebrew_yod", 0xCE9 },
{ "em3space", 0xaa3 },
{ "hebrew_finalkaph", 0xCEA },
{ "hebrew_kaph", 0xCEB },
{ "hebrew_lamed", 0xCEC },
{ "hebrew_finalmem", 0xCED },
{ "hebrew_mem", 0xCEE },
{ "em4space", 0xaa4 },
{ "digitspace", 0xaa5 },
{ "punctspace", 0xaa6 },
{ "thinspace", 0xaa7 },
{ "hebrew_finalnun", 0xCEF },
{ "hebrew_nun", 0xCF0 },
{ "hebrew_samech", 0xCF1 },
{ "hairspace", 0xaa8 },
{ "emdash", 0xaa9 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_samekh", 0xCF1 },
{ "endash", 0xaaa },
#endif
{ "hebrew_ayin", 0xCF2 },
{ "signifblank", 0xaac },
{ "hebrew_finalpe", 0xCF3 },
{ "hebrew_pe", 0xCF4 },
{ "hebrew_finalzade", 0xCF5 },
{ "ellipsis", 0xaae },
{ "doubbaselinedot", 0xaaf },
#ifndef TK_NO_DEPRECATED
{ "hebrew_finalzadi", 0xCF5 },
#endif
{ "hebrew_zade", 0xCF6 },
{ "onethird", 0xab0 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_zadi", 0xCF6 },
{ "twothirds", 0xab1 },
#endif
{ "hebrew_qoph", 0xCF7 },
{ "onefifth", 0xab2 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_kuf", 0xCF7 },
#endif
{ "hebrew_resh", 0xCF8 },
{ "hebrew_shin", 0xCF9 },
{ "hebrew_taw", 0xCFA },
{ "twofifths", 0xab3 },
{ "threefifths", 0xab4 },
{ "fourfifths", 0xab5 },
{ "onesixth", 0xab6 },
{ "fivesixths", 0xab7 },
#ifndef TK_NO_DEPRECATED
{ "hebrew_taf", 0xCFA },
{ "careof", 0xab8 },
#endif
{ "Thai_kokai", 0xDA1 },
{ "Thai_khokhai", 0xDA2 },
{ "Thai_khokhuat", 0xDA3 },
{ "Thai_khokhwai", 0xDA4 },
{ "figdash", 0xabb },
{ "leftanglebracket", 0xabc },
{ "decimalpoint", 0xabd },
{ "rightanglebracket", 0xabe },
{ "Thai_khokhon", 0xDA5 },
{ "Thai_khorakhang", 0xDA6 },
{ "Thai_ngongu", 0xDA7 },
{ "Thai_chochan", 0xDA8 },
{ "marker", 0xabf },
{ "oneeighth", 0xac3 },
{ "Thai_choching", 0xDA9 },
{ "Thai_chochang", 0xDAA },
{ "Thai_soso", 0xDAB },
{ "Thai_chochoe", 0xDAC },
{ "Thai_yoying", 0xDAD },
{ "threeeighths", 0xac4 },
{ "fiveeighths", 0xac5 },
{ "seveneighths", 0xac6 },
{ "Thai_dochada", 0xDAE },
{ "Thai_topatak", 0xDAF },
{ "trademark", 0xac9 },
{ "Thai_thothan", 0xDB0 },
{ "Thai_thonangmontho", 0xDB1 },
{ "Thai_thophuthao", 0xDB2 },
{ "Thai_nonen", 0xDB3 },
{ "Thai_dodek", 0xDB4 },
{ "Thai_totao", 0xDB5 },
{ "Thai_thothung", 0xDB6 },
{ "Thai_thothahan", 0xDB7 },
{ "Thai_thothong", 0xDB8 },
{ "Thai_nonu", 0xDB9 },
{ "signaturemark", 0xaca },
{ "trademarkincircle", 0xacb },
{ "leftopentriangle", 0xacc },
{ "rightopentriangle", 0xacd },
{ "emopencircle", 0xace },
{ "emopenrectangle", 0xacf },
{ "Thai_bobaimai", 0xDBA },
{ "Thai_popla", 0xDBB },
{ "Thai_phophung", 0xDBC },
{ "Thai_fofa", 0xDBD },
{ "Thai_phophan", 0xDBE },
{ "Thai_fofan", 0xDBF },
{ "Thai_phosamphao", 0xDC0 },
{ "Thai_moma", 0xDC1 },
{ "Thai_yoyak", 0xDC2 },
{ "Thai_rorua", 0xDC3 },
{ "Thai_ru", 0xDC4 },
{ "leftsinglequotemark", 0xad0 },
{ "rightsinglequotemark", 0xad1 },
{ "leftdoublequotemark", 0xad2 },
{ "Thai_loling", 0xDC5 },
{ "Thai_lu", 0xDC6 },
{ "Thai_wowaen", 0xDC7 },
{ "Thai_sosala", 0xDC8 },
{ "Thai_sorusi", 0xDC9 },
{ "Thai_sosua", 0xDCA },
{ "Thai_hohip", 0xDCB },
{ "Thai_lochula", 0xDCC },
{ "Thai_oang", 0xDCD },
{ "Thai_honokhuk", 0xDCE },
{ "rightdoublequotemark", 0xad3 },
{ "prescription", 0xad4 },
{ "minutes", 0xad6 },
{ "seconds", 0xad7 },
{ "latincross", 0xad9 },
{ "hexagram", 0xada },
{ "filledrectbullet", 0xadb },
{ "filledlefttribullet", 0xadc },
{ "filledrighttribullet", 0xadd },
{ "Thai_paiyannoi", 0xDCF },
{ "Thai_saraa", 0xDD0 },
{ "Thai_maihanakat", 0xDD1 },
{ "Thai_saraaa", 0xDD2 },
{ "Thai_saraam", 0xDD3 },
{ "Thai_sarai", 0xDD4 },
{ "Thai_saraii", 0xDD5 },
{ "emfilledcircle", 0xade },
{ "emfilledrect", 0xadf },
{ "enopencircbullet", 0xae0 },
{ "enopensquarebullet", 0xae1 },
{ "openrectbullet", 0xae2 },
{ "opentribulletup", 0xae3 },
{ "Thai_saraue", 0xDD6 },
{ "Thai_sarauee", 0xDD7 },
{ "Thai_sarau", 0xDD8 },
{ "Thai_sarauu", 0xDD9 },
{ "opentribulletdown", 0xae4 },
{ "openstar", 0xae5 },
{ "Thai_phinthu", 0xDDA },
{ "Thai_maihanakat_maitho", 0xDDE },
{ "Thai_baht", 0xDDF },
{ "Thai_sarae", 0xDE0 },
{ "enfilledcircbullet", 0xae6 },
{ "enfilledsqbullet", 0xae7 },
{ "Thai_saraae", 0xDE1 },
{ "Thai_sarao", 0xDE2 },
{ "Thai_saraaimaimuan", 0xDE3 },
{ "filledtribulletup", 0xae8 },
{ "filledtribulletdown", 0xae9 },
{ "Thai_saraaimaimalai", 0xDE4 },
{ "Thai_lakkhangyao", 0xDE5 },
{ "leftpointer", 0xaea },
{ "Thai_maiyamok", 0xDE6 },
{ "Thai_maitaikhu", 0xDE7 },
{ "Thai_maiek", 0xDE8 },
{ "Thai_maitho", 0xDE9 },
{ "Thai_maitri", 0xDEA },
{ "rightpointer", 0xaeb },
{ "club", 0xaec },
{ "diamond", 0xaed },
{ "Thai_maichattawa", 0xDEB },
{ "Thai_thanthakhat", 0xDEC },
{ "Thai_nikhahit", 0xDED },
{ "Thai_leksun", 0xDF0 },
{ "Thai_leknung", 0xDF1 },
{ "heart", 0xaee },
{ "maltesecross", 0xaf0 },
{ "dagger", 0xaf1 },
{ "Thai_leksong", 0xDF2 },
{ "Thai_leksam", 0xDF3 },
{ "Thai_leksi", 0xDF4 },
{ "Thai_lekha", 0xDF5 },
{ "Thai_lekhok", 0xDF6 },
{ "Thai_lekchet", 0xDF7 },
{ "Thai_lekpaet", 0xDF8 },
{ "Thai_lekkao", 0xDF9 },
{ "Hangul_Kiyeog", 0xEA1 },
{ "doubledagger", 0xaf2 },
{ "checkmark", 0xaf3 },
{ "ballotcross", 0xaf4 },
{ "musicalsharp", 0xaf5 },
{ "musicalflat", 0xaf6 },
{ "malesymbol", 0xaf7 },
{ "femalesymbol", 0xaf8 },
{ "telephone", 0xaf9 },
{ "Hangul_SsangKiyeog", 0xEA2 },
{ "Hangul_KiyeogSios", 0xEA3 },
{ "Hangul_Nieun", 0xEA4 },
{ "telephonerecorder", 0xafa },
{ "Hangul_NieunJieuj", 0xEA5 },
{ "Hangul_NieunHieuh", 0xEA6 },
{ "Hangul_Dikeud", 0xEA7 },
{ "Hangul_SsangDikeud", 0xEA8 },
{ "Hangul_Rieul", 0xEA9 },
{ "phonographcopyright", 0xafb },
{ "Hangul_RieulKiyeog", 0xEAA },
{ "Hangul_RieulMieum", 0xEAB },
{ "Hangul_RieulPieub", 0xEAC },
{ "Hangul_RieulSios", 0xEAD },
{ "Hangul_RieulTieut", 0xEAE },
{ "caret", 0xafc },
{ "Hangul_RieulPhieuf", 0xEAF },
{ "Hangul_RieulHieuh", 0xEB0 },
{ "Hangul_Mieum", 0xEB1 },
{ "Hangul_Pieub", 0xEB2 },
{ "singlelowquotemark", 0xafd },
{ "doublelowquotemark", 0xafe },
{ "cursor", 0xaff },
{ "Hangul_SsangPieub", 0xEB3 },
{ "Hangul_PieubSios", 0xEB4 },
{ "Hangul_Sios", 0xEB5 },
{ "leftcaret", 0xba3 },
{ "Hangul_SsangSios", 0xEB6 },
{ "Hangul_Ieung", 0xEB7 },
{ "rightcaret", 0xba6 },
{ "Hangul_Jieuj", 0xEB8 },
{ "Hangul_SsangJieuj", 0xEB9 },
{ "Hangul_Cieuc", 0xEBA },
{ "Hangul_Khieuq", 0xEBB },
{ "Hangul_Tieut", 0xEBC },
{ "downcaret", 0xba8 },
{ "Hangul_Phieuf", 0xEBD },
{ "Hangul_Hieuh", 0xEBE },
{ "Hangul_A", 0xEBF },
{ "Hangul_AE", 0xEC0 },
{ "Hangul_YA", 0xEC1 },
{ "upcaret", 0xba9 },
{ "overbar", 0xbc0 },
{ "downtack", 0xbc2 },
{ "Hangul_YAE", 0xEC2 },
{ "Hangul_EO", 0xEC3 },
{ "Hangul_E", 0xEC4 },
{ "upshoe", 0xbc3 },
{ "downstile", 0xbc4 },
{ "Hangul_YEO", 0xEC5 },
{ "Hangul_YE", 0xEC6 },
{ "Hangul_O", 0xEC7 },
{ "Hangul_WA", 0xEC8 },
{ "underbar", 0xbc6 },
{ "jot", 0xbca },
{ "quad", 0xbcc },
{ "Hangul_WAE", 0xEC9 },
{ "Hangul_OE", 0xECA },
{ "Hangul_YO", 0xECB },
{ "Hangul_U", 0xECC },
{ "Hangul_WEO", 0xECD },
{ "Hangul_WE", 0xECE },
{ "Hangul_WI", 0xECF },
{ "Hangul_YU", 0xED0 },
{ "Hangul_EU", 0xED1 },
{ "Hangul_YI", 0xED2 },
{ "Hangul_I", 0xED3 },
{ "uptack", 0xbce },
{ "circle", 0xbcf },
{ "upstile", 0xbd3 },
{ "downshoe", 0xbd6 },
{ "rightshoe", 0xbd8 },
{ "leftshoe", 0xbda },
{ "lefttack", 0xbdc },
{ "righttack", 0xbfc },
{ "hebrew_aleph", 0xce0 },
{ "hebrew_beth", 0xce1 },
{ "Hangul_J_Kiyeog", 0xED4 },
{ "Hangul_J_SsangKiyeog", 0xED5 },
{ "Hangul_J_KiyeogSios", 0xED6 },
{ "Hangul_J_Nieun", 0xED7 },
{ "hebrew_gimmel", 0xce2 },
{ "Hangul_J_NieunJieuj", 0xED8 },
{ "Hangul_J_NieunHieuh", 0xED9 },
{ "Hangul_J_Dikeud", 0xEDA },
{ "Hangul_J_Rieul", 0xEDB },
{ "Hangul_J_RieulKiyeog", 0xEDC },
{ "Hangul_J_RieulMieum", 0xEDD },
{ "Hangul_J_RieulPieub", 0xEDE },
{ "hebrew_daleth", 0xce3 },
{ "hebrew_he", 0xce4 },
{ "hebrew_waw", 0xce5 },
{ "hebrew_zayin", 0xce6 },
{ "Hangul_J_RieulSios", 0xEDF },
{ "Hangul_J_RieulTieut", 0xEE0 },
{ "Hangul_J_RieulPhieuf", 0xEE1 },
{ "Hangul_J_RieulHieuh", 0xEE2 },
{ "Hangul_J_Mieum", 0xEE3 },
{ "Hangul_J_Pieub", 0xEE4 },
{ "Hangul_J_PieubSios", 0xEE5 },
{ "Hangul_J_Sios", 0xEE6 },
{ "Hangul_J_SsangSios", 0xEE7 },
{ "Hangul_J_Ieung", 0xEE8 },
{ "Hangul_J_Jieuj", 0xEE9 },
{ "Hangul_J_Cieuc", 0xEEA },
{ "Hangul_J_Khieuq", 0xEEB },
{ "Hangul_J_Tieut", 0xEEC },
{ "Hangul_J_Phieuf", 0xEED },
{ "Hangul_J_Hieuh", 0xEEE },
{ "hebrew_het", 0xce7 },
{ "hebrew_teth", 0xce8 },
{ "hebrew_yod", 0xce9 },
{ "hebrew_finalkaph", 0xcea },
{ "hebrew_kaph", 0xceb },
{ "hebrew_lamed", 0xcec },
{ "hebrew_finalmem", 0xced },
{ "hebrew_mem", 0xcee },
{ "hebrew_finalnun", 0xcef },
{ "hebrew_nun", 0xcf0 },
{ "hebrew_samekh", 0xcf1 },
{ "hebrew_ayin", 0xcf2 },
{ "hebrew_finalpe", 0xcf3 },
{ "hebrew_pe", 0xcf4 },
{ "hebrew_finalzadi", 0xcf5 },
{ "Hangul_RieulYeorinHieuh", 0xEEF },
{ "Hangul_SunkyeongeumMieum", 0xEF0 },
{ "Hangul_SunkyeongeumPieub", 0xEF1 },
{ "Hangul_PanSios", 0xEF2 },
{ "hebrew_zadi", 0xcf6 },
{ "Hangul_KkogjiDalrinIeung", 0xEF3 },
{ "Hangul_SunkyeongeumPhieuf", 0xEF4 },
{ "hebrew_kuf", 0xcf7 },
{ "Hangul_YeorinHieuh", 0xEF5 },
{ "Hangul_AraeA", 0xEF6 },
{ "hebrew_resh", 0xcf8 },
{ "Hangul_AraeAE", 0xEF7 },
{ "Hangul_J_PanSios", 0xEF8 },
{ "Hangul_J_KkogjiDalrinIeung", 0xEF9 },
{ "Hangul_J_YeorinHieuh", 0xEFA },
{ "Korean_Won", 0xEFF },
{ "hebrew_shin", 0xcf9 },
{ "XF86ModeLock", 0x1008FF01 },
{ "XF86MonBrightnessUp", 0x1008FF02 },
{ "XF86MonBrightnessDown", 0x1008FF03 },
{ "XF86KbdLightOnOff", 0x1008FF04 },
{ "hebrew_taf", 0xcfa },
{ "XF86KbdBrightnessUp", 0x1008FF05 },
{ "XF86KbdBrightnessDown", 0x1008FF06 },
{ "XF86MonBrightnessCycle", 0x1008FF07 },
{ "XF86Standby", 0x1008FF10 },
{ "Hebrew_switch", 0xFF7E },
{ "XF86AudioLowerVolume", 0x1008FF11 },
{ "XF86AudioMute", 0x1008FF12 },
{ "XF86AudioRaiseVolume", 0x1008FF13 },
{ "XF86AudioPlay", 0x1008FF14 },
{ "XF86AudioStop", 0x1008FF15 },
{ "XF86AudioPrev", 0x1008FF16 },
{ "XF86AudioNext", 0x1008FF17 },
{ "XF86HomePage", 0x1008FF18 },
{ "XF86Mail", 0x1008FF19 },
{ "XF86Start", 0x1008FF1A },
{ "XF86Search", 0x1008FF1B },
{ "XF86AudioRecord", 0x1008FF1C },
{ "XF86Calculator", 0x1008FF1D },
{ "XF86Memo", 0x1008FF1E },
{ "XF86ToDoList", 0x1008FF1F },
{ "XF86Calendar", 0x1008FF20 },
{ "XF86PowerDown", 0x1008FF21 },
{ "XF86ContrastAdjust", 0x1008FF22 },
{ "XF86RockerUp", 0x1008FF23 },
{ "XF86RockerDown", 0x1008FF24 },
{ "XF86RockerEnter", 0x1008FF25 },
{ "XF86Back", 0x1008FF26 },
{ "XF86Forward", 0x1008FF27 },
{ "XF86Stop", 0x1008FF28 },
{ "XF86Refresh", 0x1008FF29 },
{ "XF86PowerOff", 0x1008FF2A },
{ "XF86WakeUp", 0x1008FF2B },
{ "XF86Eject", 0x1008FF2C },
{ "XF86ScreenSaver", 0x1008FF2D },
{ "XF86WWW", 0x1008FF2E },
{ "XF86Sleep", 0x1008FF2F },
{ "XF86Favorites", 0x1008FF30 },
{ "XF86AudioPause", 0x1008FF31 },
{ "XF86AudioMedia", 0x1008FF32 },
{ "XF86MyComputer", 0x1008FF33 },
{ "XF86VendorHome", 0x1008FF34 },
{ "XF86LightBulb", 0x1008FF35 },
{ "XF86Shop", 0x1008FF36 },
{ "XF86History", 0x1008FF37 },
{ "XF86OpenURL", 0x1008FF38 },
{ "XF86AddFavorite", 0x1008FF39 },
{ "XF86HotLinks", 0x1008FF3A },
{ "XF86BrightnessAdjust", 0x1008FF3B },
{ "XF86Finance", 0x1008FF3C },
{ "XF86Community", 0x1008FF3D },
{ "XF86AudioRewind", 0x1008FF3E },
{ "XF86BackForward", 0x1008FF3F },
{ "XF86Launch0", 0x1008FF40 },
{ "XF86Launch1", 0x1008FF41 },
{ "XF86Launch2", 0x1008FF42 },
{ "XF86Launch3", 0x1008FF43 },
{ "XF86Launch4", 0x1008FF44 },
{ "XF86Launch5", 0x1008FF45 },
{ "XF86Launch6", 0x1008FF46 },
{ "XF86Launch7", 0x1008FF47 },
{ "XF86Launch8", 0x1008FF48 },
{ "XF86Launch9", 0x1008FF49 },
{ "XF86LaunchA", 0x1008FF4A },
{ "XF86LaunchB", 0x1008FF4B },
{ "XF86LaunchC", 0x1008FF4C },
{ "XF86LaunchD", 0x1008FF4D },
{ "XF86LaunchE", 0x1008FF4E },
{ "XF86LaunchF", 0x1008FF4F },
{ "XF86ApplicationLeft", 0x1008FF50 },
{ "XF86ApplicationRight", 0x1008FF51 },
{ "XF86Book", 0x1008FF52 },
{ "XF86CD", 0x1008FF53 },
{ "XF86Calculater", 0x1008FF54 },
{ "XF86Clear", 0x1008FF55 },
{ "XF86Close", 0x1008FF56 },
{ "XF86Copy", 0x1008FF57 },
{ "XF86Cut", 0x1008FF58 },
{ "XF86Display", 0x1008FF59 },
{ "XF86DOS", 0x1008FF5A },
{ "XF86Documents", 0x1008FF5B },
{ "XF86Excel", 0x1008FF5C },
{ "XF86Explorer", 0x1008FF5D },
{ "XF86Game", 0x1008FF5E },
{ "XF86Go", 0x1008FF5F },
{ "XF86iTouch", 0x1008FF60 },
{ "XF86LogOff", 0x1008FF61 },
{ "XF86Market", 0x1008FF62 },
{ "XF86Meeting", 0x1008FF63 },
{ "XF86MenuKB", 0x1008FF65 },
{ "XF86MenuPB", 0x1008FF66 },
{ "XF86MySites", 0x1008FF67 },
{ "XF86New", 0x1008FF68 },
{ "XF86News", 0x1008FF69 },
{ "XF86OfficeHome", 0x1008FF6A },
{ "XF86Open", 0x1008FF6B },
{ "XF86Option", 0x1008FF6C },
{ "XF86Paste", 0x1008FF6D },
{ "XF86Phone", 0x1008FF6E },
{ "XF86Q", 0x1008FF70 },
{ "XF86Reply", 0x1008FF72 },
{ "XF86Reload", 0x1008FF73 },
{ "XF86RotateWindows", 0x1008FF74 },
{ "XF86RotationPB", 0x1008FF75 },
{ "XF86RotationKB", 0x1008FF76 },
{ "XF86Save", 0x1008FF77 },
{ "XF86ScrollUp", 0x1008FF78 },
{ "XF86ScrollDown", 0x1008FF79 },
{ "XF86ScrollClick", 0x1008FF7A },
{ "XF86Send", 0x1008FF7B },
{ "XF86Spell", 0x1008FF7C },
{ "XF86SplitScreen", 0x1008FF7D },
{ "XF86Support", 0x1008FF7E },
{ "XF86TaskPane", 0x1008FF7F },
{ "XF86Terminal", 0x1008FF80 },
{ "XF86Tools", 0x1008FF81 },
{ "XF86Travel", 0x1008FF82 },
{ "XF86UserPB", 0x1008FF84 },
{ "XF86User1KB", 0x1008FF85 },
{ "XF86User2KB", 0x1008FF86 },
{ "XF86Video", 0x1008FF87 },
{ "XF86WheelButton", 0x1008FF88 },
{ "XF86Word", 0x1008FF89 },
{ "XF86Xfer", 0x1008FF8A },
{ "XF86ZoomIn", 0x1008FF8B },
{ "XF86ZoomOut", 0x1008FF8C },
{ "XF86Away", 0x1008FF8D },
{ "XF86Messenger", 0x1008FF8E },
{ "XF86WebCam", 0x1008FF8F },
{ "XF86MailForward", 0x1008FF90 },
{ "XF86Pictures", 0x1008FF91 },
{ "XF86Music", 0x1008FF92 },
{ "XF86Battery", 0x1008FF93 },
{ "XF86Bluetooth", 0x1008FF94 },
{ "XF86WLAN", 0x1008FF95 },
{ "XF86UWB", 0x1008FF96 },
{ "XF86AudioForward", 0x1008FF97 },
{ "XF86AudioRepeat", 0x1008FF98 },
{ "XF86AudioRandomPlay", 0x1008FF99 },
{ "XF86Subtitle", 0x1008FF9A },
{ "XF86AudioCycleTrack", 0x1008FF9B },
{ "XF86CycleAngle", 0x1008FF9C },
{ "XF86FrameBack", 0x1008FF9D },
{ "XF86FrameForward", 0x1008FF9E },
{ "XF86Time", 0x1008FF9F },
{ "XF86Select", 0x1008FFA0 },
{ "XF86View", 0x1008FFA1 },
{ "XF86TopMenu", 0x1008FFA2 },
{ "XF86Red", 0x1008FFA3 },
{ "XF86Green", 0x1008FFA4 },
{ "XF86Yellow", 0x1008FFA5 },
{ "XF86Blue", 0x1008FFA6 },
{ "XF86Suspend", 0x1008FFA7 },
{ "XF86Hibernate", 0x1008FFA8 },
{ "XF86TouchpadToggle", 0x1008FFA9 },
{ "XF86TouchpadOn", 0x1008FFB0 },
{ "XF86TouchpadOff", 0x1008FFB1 },
{ "XF86AudioMicMute", 0x1008FFB2 },
{ "XF86Keyboard", 0x1008FFB3 },
{ "XF86WWAN", 0x1008FFB4 },
{ "XF86RFKill", 0x1008FFB5 },
{ "XF86AudioPreset", 0x1008FFB6 },
{ "XF86RotationLockToggle", 0x1008FFB7 },
{ "XF86FullScreen", 0x1008FFB8 },
{ "XF86Switch_VT_1", 0x1008FE01 },
{ "XF86Switch_VT_2", 0x1008FE02 },
{ "XF86Switch_VT_3", 0x1008FE03 },
{ "XF86Switch_VT_4", 0x1008FE04 },
{ "XF86Switch_VT_5", 0x1008FE05 },
{ "XF86Switch_VT_6", 0x1008FE06 },
{ "XF86Switch_VT_7", 0x1008FE07 },
{ "XF86Switch_VT_8", 0x1008FE08 },
{ "XF86Switch_VT_9", 0x1008FE09 },
{ "XF86Switch_VT_10", 0x1008FE0A },
{ "XF86Switch_VT_11", 0x1008FE0B },
{ "XF86Switch_VT_12", 0x1008FE0C },
{ "XF86Ungrab", 0x1008FE20 },
{ "XF86ClearGrab", 0x1008FE21 },
{ "XF86Next_VMode", 0x1008FE22 },
{ "XF86Prev_VMode", 0x1008FE23 },
{ "XF86LogWindowTree", 0x1008FE24 },
{ "XF86LogGrabInfo", 0x1008FE25 },
{ "XF86BrightnessAuto", 0x100810F4 },
{ "XF86DisplayOff", 0x100810F5 },
{ "XF86Info", 0x10081166 },
{ "XF86AspectRatio", 0x10081177 },
{ "XF86DVD", 0x10081185 },
{ "XF86Audio", 0x10081188 },
{ "XF86ChannelUp", 0x10081192 },
{ "XF86ChannelDown", 0x10081193 },
{ "XF86Break", 0x1008119B },
{ "XF86VideoPhone", 0x100811A0 },
{ "XF86ZoomReset", 0x100811A4 },
{ "XF86Editor", 0x100811A6 },
{ "XF86GraphicsEditor", 0x100811A8 },
{ "XF86Presentation", 0x100811A9 },
{ "XF86Database", 0x100811AA },
{ "XF86Voicemail", 0x100811AC },
{ "XF86Addressbook", 0x100811AD },
{ "XF86DisplayToggle", 0x100811AF },
{ "XF86SpellCheck", 0x100811B0 },
{ "XF86ContextMenu", 0x100811B6 },
{ "XF86MediaRepeat", 0x100811B7 },
{ "XF8610ChannelsUp", 0x100811B8 },
{ "XF8610ChannelsDown", 0x100811B9 },
{ "XF86Images", 0x100811BA },
{ "XF86NotificationCenter", 0x100811BC },
{ "XF86PickupPhone", 0x100811BD },
{ "XF86HangupPhone", 0x100811BE },
{ "XF86Fn", 0x100811D0 },
{ "XF86Fn_Esc", 0x100811D1 },
{ "XF86FnRightShift", 0x100811E5 },
{ "XF86Numeric0", 0x10081200 },
{ "XF86Numeric1", 0x10081201 },
{ "XF86Numeric2", 0x10081202 },
{ "XF86Numeric3", 0x10081203 },
{ "XF86Numeric4", 0x10081204 },
{ "XF86Numeric5", 0x10081205 },
{ "XF86Numeric6", 0x10081206 },
{ "XF86Numeric7", 0x10081207 },
{ "XF86Numeric8", 0x10081208 },
{ "XF86Numeric9", 0x10081209 },
{ "XF86NumericStar", 0x1008120A },
{ "XF86NumericPound", 0x1008120B },
{ "XF86NumericA", 0x1008120C },
{ "XF86NumericB", 0x1008120D },
{ "XF86NumericC", 0x1008120E },
{ "XF86NumericD", 0x1008120F },
{ "XF86CameraFocus", 0x10081210 },
{ "XF86WPSButton", 0x10081211 },
{ "XF86CameraZoomIn", 0x10081215 },
{ "XF86CameraZoomOut", 0x10081216 },
{ "XF86CameraUp", 0x10081217 },
{ "XF86CameraDown", 0x10081218 },
{ "XF86CameraLeft", 0x10081219 },
{ "XF86CameraRight", 0x1008121A },
{ "XF86AttendantOn", 0x1008121B },
{ "XF86AttendantOff", 0x1008121C },
{ "XF86AttendantToggle", 0x1008121D },
{ "XF86LightsToggle", 0x1008121E },
{ "XF86ALSToggle", 0x10081230 },
{ "XF86Buttonconfig", 0x10081240 },
{ "XF86Taskmanager", 0x10081241 },
{ "XF86Journal", 0x10081242 },
{ "XF86ControlPanel", 0x10081243 },
{ "XF86AppSelect", 0x10081244 },
{ "XF86Screensaver", 0x10081245 },
{ "XF86VoiceCommand", 0x10081246 },
{ "XF86Assistant", 0x10081247 },
{ "XF86EmojiPicker", 0x10081249 },
{ "XF86Dictate", 0x1008124A },
{ "XF86BrightnessMin", 0x10081250 },
{ "XF86BrightnessMax", 0x10081251 },
{ "XF86KbdInputAssistPrev", 0x10081260 },
{ "XF86KbdInputAssistNext", 0x10081261 },
{ "XF86KbdInputAssistPrevgroup", 0x10081262 },
{ "XF86KbdInputAssistNextgroup", 0x10081263 },
{ "XF86KbdInputAssistAccept", 0x10081264 },
{ "XF86KbdInputAssistCancel", 0x10081265 },
{ "XF86RightUp", 0x10081266 },
{ "XF86RightDown", 0x10081267 },
{ "XF86LeftUp", 0x10081268 },
{ "XF86LeftDown", 0x10081269 },
{ "XF86RootMenu", 0x1008126A },
{ "XF86MediaTopMenu", 0x1008126B },
{ "XF86Numeric11", 0x1008126C },
{ "XF86Numeric12", 0x1008126D },
{ "XF86AudioDesc", 0x1008126E },
{ "XF863DMode", 0x1008126F },
{ "XF86NextFavorite", 0x10081270 },
{ "XF86StopRecord", 0x10081271 },
{ "XF86PauseRecord", 0x10081272 },
{ "XF86VOD", 0x10081273 },
{ "XF86Unmute", 0x10081274 },
{ "XF86FastReverse", 0x10081275 },
{ "XF86SlowReverse", 0x10081276 },
{ "XF86Data", 0x10081277 },
{ "XF86OnScreenKeyboard", 0x10081278 },
{ "XF86PrivacyScreenToggle", 0x10081279 },
{ "XF86SelectiveScreenshot", 0x1008127A },
{ "XF86Macro1", 0x10081290 },
{ "XF86Macro2", 0x10081291 },
{ "XF86Macro3", 0x10081292 },
{ "XF86Macro4", 0x10081293 },
{ "XF86Macro5", 0x10081294 },
{ "XF86Macro6", 0x10081295 },
{ "XF86Macro7", 0x10081296 },
{ "XF86Macro8", 0x10081297 },
{ "XF86Macro9", 0x10081298 },
{ "XF86Macro10", 0x10081299 },
{ "XF86Macro11", 0x1008129A },
{ "XF86Macro12", 0x1008129B },
{ "XF86Macro13", 0x1008129C },
{ "XF86Macro14", 0x1008129D },
{ "XF86Macro15", 0x1008129E },
{ "XF86Macro16", 0x1008129F },
{ "XF86Macro17", 0x100812A0 },
{ "XF86Macro18", 0x100812A1 },
{ "XF86Macro19", 0x100812A2 },
{ "XF86Macro20", 0x100812A3 },
{ "XF86Macro21", 0x100812A4 },
{ "XF86Macro22", 0x100812A5 },
{ "XF86Macro23", 0x100812A6 },
{ "XF86Macro24", 0x100812A7 },
{ "XF86Macro25", 0x100812A8 },
{ "XF86Macro26", 0x100812A9 },
{ "XF86Macro27", 0x100812AA },
{ "XF86Macro28", 0x100812AB },
{ "XF86Macro29", 0x100812AC },
{ "XF86Macro30", 0x100812AD },
{ "XF86MacroRecordStart", 0x100812B0 },
{ "XF86MacroRecordStop", 0x100812B1 },
{ "XF86MacroPresetCycle", 0x100812B2 },
{ "XF86MacroPreset1", 0x100812B3 },
{ "XF86MacroPreset2", 0x100812B4 },
{ "XF86MacroPreset3", 0x100812B5 },
{ "XF86KbdLcdMenu1", 0x100812B8 },
{ "XF86KbdLcdMenu2", 0x100812B9 },
{ "XF86KbdLcdMenu3", 0x100812BA },
{ "XF86KbdLcdMenu4", 0x100812BB },
{ "XF86KbdLcdMenu5", 0x100812BC },
{ "SunFA_Grave", 0x1005FF00 },
{ "SunFA_Circum", 0x1005FF01 },
{ "SunFA_Tilde", 0x1005FF02 },
{ "SunFA_Acute", 0x1005FF03 },
{ "SunFA_Diaeresis", 0x1005FF04 },
{ "SunFA_Cedilla", 0x1005FF05 },
{ "SunF36", 0x1005FF10 },
{ "SunF37", 0x1005FF11 },
{ "SunSys_Req", 0x1005FF60 },
{ "SunProps", 0x1005FF70 },
{ "SunFront", 0x1005FF71 },
{ "SunCopy", 0x1005FF72 },
{ "SunOpen", 0x1005FF73 },
{ "SunPaste", 0x1005FF74 },
{ "SunCut", 0x1005FF75 },
{ "SunPowerSwitch", 0x1005FF76 },
{ "SunAudioLowerVolume", 0x1005FF77 },
{ "SunAudioMute", 0x1005FF78 },
{ "SunAudioRaiseVolume", 0x1005FF79 },
{ "SunVideoDegauss", 0x1005FF7A },
{ "SunVideoLowerBrightness", 0x1005FF7B },
{ "SunVideoRaiseBrightness", 0x1005FF7C },
{ "SunPowerSwitchShift", 0x1005FF7D },

Deleted generic/nanosvg.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2013-14 Mikko Mononen [email protected]
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 *
 * The SVG parser is based on Anti-Grain Geometry 2.4 SVG example
 * Copyright (C) 2002-2004 Maxim Shemanarev (McSeem) (http://www.antigrain.com/)
 *
 * Arc calculation code based on canvg (https://code.google.com/p/canvg/)
 *
 * Bounding box calculation based on http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
 *
 */

#ifndef NANOSVG_H
#define NANOSVG_H

#ifdef __cplusplus
extern "C" {
#endif

/* NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.
 *
 * The library suits well for anything from rendering scalable icons in your editor application to prototyping a game.
 *
 * NanoSVG supports a wide range of SVG features, but something may be missing, feel free to create a pull request!
 *
 * The shapes in the SVG images are transformed by the viewBox and converted to specified units.
 * That is, you should get the same looking data as your designed in your favorite app.
 *
 * NanoSVG can return the paths in few different units. For example if you want to render an image, you may choose
 * to get the paths in pixels, or if you are feeding the data into a CNC-cutter, you may want to use millimeters.
 *
 * The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or 'in'.
 * DPI (dots-per-inch) controls how the unit conversion is done.
 *
 * If you don't know or care about the units stuff, "px" and 96 should get you going.
 */


/* Example Usage:
	// Load SVG
	NSVGimage* image;
	image = nsvgParseFromFile("test.svg", "px", 96);
	printf("size: %f x %f\n", image->width, image->height);
	// Use...
	for (NSVGshape *shape = image->shapes; shape != NULL; shape = shape->next) {
		for (NSVGpath *path = shape->paths; path != NULL; path = path->next) {
			for (int i = 0; i < path->npts-1; i += 3) {
				float* p = &path->pts[i*2];
				drawCubicBez(p[0],p[1], p[2],p[3], p[4],p[5], p[6],p[7]);
			}
		}
	}
	// Delete
	nsvgDelete(image);
*/

#ifndef NANOSVG_SCOPE
#define NANOSVG_SCOPE
#endif

#ifndef NANOSVG_malloc
#define NANOSVG_malloc malloc
#endif

#ifndef NANOSVG_realloc
#define NANOSVG_realloc realloc
#endif

#ifndef NANOSVG_free
#define NANOSVG_free free
#endif

/* float emulation for MS VC6++ compiler */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
#define tanf(a) (float)tan(a)
#define cosf(a) (float)cos(a)
#define sinf(a) (float)sin(a)
#define sqrtf(a) (float)sqrt(a)
#define fabsf(a) (float)fabs(a)
#define acosf(a) (float)acos(a)
#define atan2f(a,b) (float)atan2(a,b)
#define ceilf(a) (float)ceil(a)
#define fmodf(a,b) (float)fmod(a,b)
#define floorf(a) (float)floor(a)
#endif
/* float emulation for MS VC8++ compiler */
#if defined(_MSC_VER) && (_MSC_VER == 1400)
#define fabsf(a) (float)fabs(a)
#endif

enum NSVGpaintType {
	NSVG_PAINT_UNDEF = -1,
	NSVG_PAINT_NONE = 0,
	NSVG_PAINT_COLOR = 1,
	NSVG_PAINT_LINEAR_GRADIENT = 2,
	NSVG_PAINT_RADIAL_GRADIENT = 3
};

enum NSVGspreadType {
	NSVG_SPREAD_PAD = 0,
	NSVG_SPREAD_REFLECT = 1,
	NSVG_SPREAD_REPEAT = 2
};

enum NSVGlineJoin {
	NSVG_JOIN_MITER = 0,
	NSVG_JOIN_ROUND = 1,
	NSVG_JOIN_BEVEL = 2
};

enum NSVGlineCap {
	NSVG_CAP_BUTT = 0,
	NSVG_CAP_ROUND = 1,
	NSVG_CAP_SQUARE = 2
};

enum NSVGfillRule {
	NSVG_FILLRULE_NONZERO = 0,
	NSVG_FILLRULE_EVENODD = 1
};

enum NSVGflags {
	NSVG_FLAGS_VISIBLE = 0x01
};

typedef struct NSVGgradientStop {
	unsigned int color;
	float offset;
} NSVGgradientStop;

typedef struct NSVGgradient {
	float xform[6];
	char spread;
	float fx, fy;
	int nstops;
	NSVGgradientStop stops[1];
} NSVGgradient;

typedef struct NSVGpaint {
	signed char type;
	union {
		unsigned int color;
		NSVGgradient* gradient;
	};
} NSVGpaint;

typedef struct NSVGpath
{
	float* pts;					/* Cubic bezier points: x0,y0, [cpx1,cpx1,cpx2,cpy2,x1,y1], ... */
	int npts;					/* Total number of bezier points. */
	char closed;				/* Flag indicating if shapes should be treated as closed. */
	float bounds[4];			/* Tight bounding box of the shape [minx,miny,maxx,maxy]. */
	struct NSVGpath* next;		/* Pointer to next path, or NULL if last element. */
} NSVGpath;

typedef struct NSVGshape
{
	char id[64];				/* Optional 'id' attr of the shape or its group */
	NSVGpaint fill;				/* Fill paint */
	NSVGpaint stroke;			/* Stroke paint */
	float opacity;				/* Opacity of the shape. */
	float strokeWidth;			/* Stroke width (scaled). */
	float strokeDashOffset;		/* Stroke dash offset (scaled). */
	float strokeDashArray[8];	/* Stroke dash array (scaled). */
	char strokeDashCount;		/* Number of dash values in dash array. */
	char strokeLineJoin;		/* Stroke join type. */
	char strokeLineCap;			/* Stroke cap type. */
	float miterLimit;			/* Miter limit */
	char fillRule;				/* Fill rule, see NSVGfillRule. */
	unsigned char flags;		/* Logical or of NSVG_FLAGS_* flags */
	float bounds[4];			/* Tight bounding box of the shape [minx,miny,maxx,maxy]. */
	char fillGradient[64];		// Optional 'id' of fill gradient
	char strokeGradient[64];	// Optional 'id' of stroke gradient
	float xform[6];				// Root transformation for fill/stroke gradient
	NSVGpath* paths;			/* Linked list of paths in the image. */
	struct NSVGshape* next;		/* Pointer to next shape, or NULL if last element. */
} NSVGshape;

typedef struct NSVGimage
{
	float width;				/* Width of the image. */
	float height;				/* Height of the image. */
	NSVGshape* shapes;			/* Linked list of shapes in the image. */
} NSVGimage;

/* Parses SVG file from a file, returns SVG image as paths. */
NANOSVG_SCOPE NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);

/* Parses SVG file from a null terminated string, returns SVG image as paths. */
/* Important note: changes the string. */
NANOSVG_SCOPE NSVGimage* nsvgParse(char* input, const char* units, float dpi);

/* Deletes list of paths. */
NANOSVG_SCOPE void nsvgDelete(NSVGimage* image);

#ifdef __cplusplus
}
#endif

#ifdef NANOSVG_IMPLEMENTATION

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#define NSVG_PI (3.14159265358979323846264338327f)
#define NSVG_KAPPA90 (0.5522847493f)	/* Length proportional to radius of a cubic bezier handle for 90deg arcs. */

#define NSVG_ALIGN_MIN 0
#define NSVG_ALIGN_MID 1
#define NSVG_ALIGN_MAX 2
#define NSVG_ALIGN_NONE 0
#define NSVG_ALIGN_MEET 1
#define NSVG_ALIGN_SLICE 2

#define NSVG_NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0)
#define NSVG_RGB(r, g, b) (((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16))

#ifdef _MSC_VER
	#pragma warning (disable: 4996) /* Switch off security warnings */
	#pragma warning (disable: 4100) /* Switch off unreferenced formal parameter warnings */
	#ifdef __cplusplus
	#define NSVG_INLINE inline
	#else
	#define NSVG_INLINE
	#endif
	#if !defined(strtoll)           /* old MSVC versions do not have strtoll() */
		#define strtoll _strtoi64
	#endif
#else
	#define NSVG_INLINE inline
#endif


static int nsvg__isspace(char c)
{
	return strchr(" \t\n\v\f\r", c) != 0;
}

static int nsvg__isdigit(char c)
{
	return c >= '0' && c <= '9';
}

static NSVG_INLINE float nsvg__minf(float a, float b) { return a < b ? a : b; }
static NSVG_INLINE float nsvg__maxf(float a, float b) { return a > b ? a : b; }


/* Simple XML parser */

#define NSVG_XML_TAG 1
#define NSVG_XML_CONTENT 2
#define NSVG_XML_MAX_ATTRIBS 256

static void nsvg__parseContent(char* s,
							   void (*contentCb)(void* ud, const char* s),
							   void* ud)
{
	/* Trim start white spaces */
	while (*s && nsvg__isspace(*s)) s++;
	if (!*s) return;

	if (contentCb)
		(*contentCb)(ud, s);
}

static void nsvg__parseElement(char* s,
							   void (*startelCb)(void* ud, const char* el, const char** attr),
							   void (*endelCb)(void* ud, const char* el),
							   void* ud)
{
	const char* attr[NSVG_XML_MAX_ATTRIBS];
	int nattr = 0;
	char* cbname;
	int start = 0;
	int end = 0;
	char quote;

	/* Skip white space after the '<' */
	while (*s && nsvg__isspace(*s)) s++;

	/* Check if the tag is end tag */
	if (*s == '/') {
		s++;
		end = 1;
	} else {
		start = 1;
	}

	/* Skip comments, data and preprocessor stuff. */
	if (!*s || *s == '?' || *s == '!')
		return;

	/* Get tag name */
	cbname = s;
	while (*s && !nsvg__isspace(*s)) s++;
	if (*s) { *s++ = '\0'; }

	/* Get attribs */
	while (!end && *s && nattr < NSVG_XML_MAX_ATTRIBS-3) {
		char* name = NULL;
		char* value = NULL;

		/* Skip white space before the attrib name */
		while (*s && nsvg__isspace(*s)) s++;
		if (!*s) break;
		if (*s == '/') {
			end = 1;
			break;
		}
		name = s;
		/* Find end of the attrib name. */
		while (*s && !nsvg__isspace(*s) && *s != '=') s++;
		if (*s) { *s++ = '\0'; }
		/* Skip until the beginning of the value. */
		while (*s && *s != '\"' && *s != '\'') s++;
		if (!*s) break;
		quote = *s;
		s++;
		/* Store value and find the end of it. */
		value = s;
		while (*s && *s != quote) s++;
		if (*s) { *s++ = '\0'; }

		/* Store only well formed attributes */
		if (name && value) {
			attr[nattr++] = name;
			attr[nattr++] = value;
		}
	}

	/* List terminator */
	attr[nattr++] = 0;
	attr[nattr++] = 0;

	/* Call callbacks. */
	if (start && startelCb)
		(*startelCb)(ud, cbname, attr);
	if (end && endelCb)
		(*endelCb)(ud, cbname);
}

NANOSVG_SCOPE
int nsvg__parseXML(char* input,
				   void (*startelCb)(void* ud, const char* el, const char** attr),
				   void (*endelCb)(void* ud, const char* el),
				   void (*contentCb)(void* ud, const char* s),
				   void* ud)
{
	char* s = input;
	char* mark = s;
	int state = NSVG_XML_CONTENT;
	while (*s) {
		if (*s == '<' && state == NSVG_XML_CONTENT) {
			/* Start of a tag */
			*s++ = '\0';
			nsvg__parseContent(mark, contentCb, ud);
			mark = s;
			state = NSVG_XML_TAG;
		} else if (*s == '>' && state == NSVG_XML_TAG) {
			/* Start of a content or new tag. */
			*s++ = '\0';
			nsvg__parseContent(mark, contentCb, ud);
			nsvg__parseElement(mark, startelCb, endelCb, ud);
			mark = s;
			state = NSVG_XML_CONTENT;
		} else {
			s++;
		}
	}

	return 1;
}


/* Simple SVG parser. */

#define NSVG_MAX_ATTR 128

enum NSVGgradientUnits {
	NSVG_USER_SPACE = 0,
	NSVG_OBJECT_SPACE = 1
};

#define NSVG_MAX_DASHES 8

enum NSVGunits {
	NSVG_UNITS_USER,
	NSVG_UNITS_PX,
	NSVG_UNITS_PT,
	NSVG_UNITS_PC,
	NSVG_UNITS_MM,
	NSVG_UNITS_CM,
	NSVG_UNITS_IN,
	NSVG_UNITS_PERCENT,
	NSVG_UNITS_EM,
	NSVG_UNITS_EX
};

enum NSVGvisible {
	NSVG_VIS_DISPLAY = 1,
	NSVG_VIS_VISIBLE = 2
};

typedef struct NSVGcoordinate {
	float value;
	int units;
} NSVGcoordinate;

typedef struct NSVGlinearData {
	NSVGcoordinate x1, y1, x2, y2;
} NSVGlinearData;

typedef struct NSVGradialData {
	NSVGcoordinate cx, cy, r, fx, fy;
} NSVGradialData;

typedef struct NSVGgradientData
{
	char id[64];
	char ref[64];
	signed char type;
	union {
		NSVGlinearData linear;
		NSVGradialData radial;
	};
	char spread;
	char units;
	float xform[6];
	int nstops;
	NSVGgradientStop* stops;
	struct NSVGgradientData* next;
} NSVGgradientData;

typedef struct NSVGattrib
{
	char id[64];
	float xform[6];
	unsigned int fillColor;
	unsigned int strokeColor;
	float opacity;
	float fillOpacity;
	float strokeOpacity;
	char fillGradient[64];
	char strokeGradient[64];
	float strokeWidth;
	float strokeDashOffset;
	float strokeDashArray[NSVG_MAX_DASHES];
	int strokeDashCount;
	char strokeLineJoin;
	char strokeLineCap;
	float miterLimit;
	char fillRule;
	float fontSize;
	unsigned int stopColor;
	float stopOpacity;
	float stopOffset;
	char hasFill;
	char hasStroke;
	char visible;
} NSVGattrib;

typedef struct NSVGstyles
{
	char*	name;
	char* description;
	struct NSVGstyles* next;
} NSVGstyles;

typedef struct NSVGparser
{
	NSVGattrib attr[NSVG_MAX_ATTR];
	int attrHead;
	float* pts;
	int npts;
	int cpts;
	NSVGpath* plist;
	NSVGimage* image;
	NSVGstyles* styles;
	NSVGgradientData* gradients;
	NSVGshape* shapesTail;
	float viewMinx, viewMiny, viewWidth, viewHeight;
	int alignX, alignY, alignType;
	float dpi;
	char pathFlag;
	char defsFlag;
	char styleFlag;
} NSVGparser;

static void nsvg__xformIdentity(float* t)
{
	t[0] = 1.0f; t[1] = 0.0f;
	t[2] = 0.0f; t[3] = 1.0f;
	t[4] = 0.0f; t[5] = 0.0f;
}

static void nsvg__xformSetTranslation(float* t, float tx, float ty)
{
	t[0] = 1.0f; t[1] = 0.0f;
	t[2] = 0.0f; t[3] = 1.0f;
	t[4] = tx; t[5] = ty;
}

static void nsvg__xformSetScale(float* t, float sx, float sy)
{
	t[0] = sx; t[1] = 0.0f;
	t[2] = 0.0f; t[3] = sy;
	t[4] = 0.0f; t[5] = 0.0f;
}

static void nsvg__xformSetSkewX(float* t, float a)
{
	t[0] = 1.0f; t[1] = 0.0f;
	t[2] = tanf(a); t[3] = 1.0f;
	t[4] = 0.0f; t[5] = 0.0f;
}

static void nsvg__xformSetSkewY(float* t, float a)
{
	t[0] = 1.0f; t[1] = tanf(a);
	t[2] = 0.0f; t[3] = 1.0f;
	t[4] = 0.0f; t[5] = 0.0f;
}

static void nsvg__xformSetRotation(float* t, float a)
{
	float cs = cosf(a), sn = sinf(a);
	t[0] = cs; t[1] = sn;
	t[2] = -sn; t[3] = cs;
	t[4] = 0.0f; t[5] = 0.0f;
}

static void nsvg__xformMultiply(float* t, float* s)
{
	float t0 = t[0] * s[0] + t[1] * s[2];
	float t2 = t[2] * s[0] + t[3] * s[2];
	float t4 = t[4] * s[0] + t[5] * s[2] + s[4];
	t[1] = t[0] * s[1] + t[1] * s[3];
	t[3] = t[2] * s[1] + t[3] * s[3];
	t[5] = t[4] * s[1] + t[5] * s[3] + s[5];
	t[0] = t0;
	t[2] = t2;
	t[4] = t4;
}

static void nsvg__xformInverse(float* inv, float* t)
{
	double invdet, det = (double)t[0] * t[3] - (double)t[2] * t[1];
	if (det > -1e-6 && det < 1e-6) {
		nsvg__xformIdentity(t);
		return;
	}
	invdet = 1.0 / det;
	inv[0] = (float)(t[3] * invdet);
	inv[2] = (float)(-t[2] * invdet);
	inv[4] = (float)(((double)t[2] * t[5] - (double)t[3] * t[4]) * invdet);
	inv[1] = (float)(-t[1] * invdet);
	inv[3] = (float)(t[0] * invdet);
	inv[5] = (float)(((double)t[1] * t[4] - (double)t[0] * t[5]) * invdet);
}

static void nsvg__xformPremultiply(float* t, float* s)
{
	float s2[6];
	memcpy(s2, s, sizeof(float)*6);
	nsvg__xformMultiply(s2, t);
	memcpy(t, s2, sizeof(float)*6);
}

static void nsvg__xformPoint(float* dx, float* dy, float x, float y, float* t)
{
	*dx = x*t[0] + y*t[2] + t[4];
	*dy = x*t[1] + y*t[3] + t[5];
}

static void nsvg__xformVec(float* dx, float* dy, float x, float y, float* t)
{
	*dx = x*t[0] + y*t[2];
	*dy = x*t[1] + y*t[3];
}

#define NSVG_EPSILON (1e-12)

static int nsvg__ptInBounds(float* pt, float* bounds)
{
	return pt[0] >= bounds[0] && pt[0] <= bounds[2] && pt[1] >= bounds[1] && pt[1] <= bounds[3];
}


static double nsvg__evalBezier(double t, double p0, double p1, double p2, double p3)
{
	double it = 1.0-t;
	return it*it*it*p0 + 3.0*it*it*t*p1 + 3.0*it*t*t*p2 + t*t*t*p3;
}

static void nsvg__curveBounds(float* bounds, float* curve)
{
	int i, j, count;
	double roots[2], a, b, c, b2ac, t, v;
	float* v0 = &curve[0];
	float* v1 = &curve[2];
	float* v2 = &curve[4];
	float* v3 = &curve[6];

	/* Start the bounding box by end points */
	bounds[0] = nsvg__minf(v0[0], v3[0]);
	bounds[1] = nsvg__minf(v0[1], v3[1]);
	bounds[2] = nsvg__maxf(v0[0], v3[0]);
	bounds[3] = nsvg__maxf(v0[1], v3[1]);

	/* Bezier curve fits inside the convex hull of it's control points. */
	/* If control points are inside the bounds, we're done. */
	if (nsvg__ptInBounds(v1, bounds) && nsvg__ptInBounds(v2, bounds))
		return;

	/* Add bezier curve inflection points in X and Y. */
	for (i = 0; i < 2; i++) {
		a = -3.0 * v0[i] + 9.0 * v1[i] - 9.0 * v2[i] + 3.0 * v3[i];
		b = 6.0 * v0[i] - 12.0 * v1[i] + 6.0 * v2[i];
		c = 3.0 * v1[i] - 3.0 * v0[i];
		count = 0;
		if (fabs(a) < NSVG_EPSILON) {
			if (fabs(b) > NSVG_EPSILON) {
				t = -c / b;
				if (t > NSVG_EPSILON && t < 1.0-NSVG_EPSILON)
					roots[count++] = t;
			}
		} else {
			b2ac = b*b - 4.0*c*a;
			if (b2ac > NSVG_EPSILON) {
				t = (-b + sqrt(b2ac)) / (2.0 * a);
				if (t > NSVG_EPSILON && t < 1.0-NSVG_EPSILON)
					roots[count++] = t;
				t = (-b - sqrt(b2ac)) / (2.0 * a);
				if (t > NSVG_EPSILON && t < 1.0-NSVG_EPSILON)
					roots[count++] = t;
			}
		}
		for (j = 0; j < count; j++) {
			v = nsvg__evalBezier(roots[j], v0[i], v1[i], v2[i], v3[i]);
			bounds[0+i] = nsvg__minf(bounds[0+i], (float)v);
			bounds[2+i] = nsvg__maxf(bounds[2+i], (float)v);
		}
	}
}

static NSVGparser* nsvg__createParser(void)
{
	NSVGparser* p;
	p = (NSVGparser*)NANOSVG_malloc(sizeof(NSVGparser));
	if (p == NULL) goto error;
	memset(p, 0, sizeof(NSVGparser));

	p->image = (NSVGimage*)NANOSVG_malloc(sizeof(NSVGimage));
	if (p->image == NULL) goto error;
	memset(p->image, 0, sizeof(NSVGimage));

	/* Init style */
	nsvg__xformIdentity(p->attr[0].xform);
	memset(p->attr[0].id, 0, sizeof p->attr[0].id);
	p->attr[0].fillColor = NSVG_RGB(0,0,0);
	p->attr[0].strokeColor = NSVG_RGB(0,0,0);
	p->attr[0].opacity = 1;
	p->attr[0].fillOpacity = 1;
	p->attr[0].strokeOpacity = 1;
	p->attr[0].stopOpacity = 1;
	p->attr[0].strokeWidth = 1;
	p->attr[0].strokeLineJoin = NSVG_JOIN_MITER;
	p->attr[0].strokeLineCap = NSVG_CAP_BUTT;
	p->attr[0].miterLimit = 4;
	p->attr[0].fillRule = NSVG_FILLRULE_NONZERO;
	p->attr[0].hasFill = 1;
	p->attr[0].visible = NSVG_VIS_DISPLAY | NSVG_VIS_VISIBLE;

	return p;

error:
	if (p) {
		if (p->image) NANOSVG_free(p->image);
		NANOSVG_free(p);
	}
	return NULL;
}

static void nsvg__deleteStyles(NSVGstyles* style) {
	while (style) {
		NSVGstyles *next = style->next;
		if (style->name!= NULL)
			NANOSVG_free(style->name);
		if (style->description != NULL)
			NANOSVG_free(style->description);
		NANOSVG_free(style);
		style = next;
	}
}

static void nsvg__deletePaths(NSVGpath* path)
{
	while (path) {
		NSVGpath *next = path->next;
		if (path->pts != NULL)
			NANOSVG_free(path->pts);
		NANOSVG_free(path);
		path = next;
	}
}

static void nsvg__deletePaint(NSVGpaint* paint)
{
	if (paint->type == NSVG_PAINT_LINEAR_GRADIENT || paint->type == NSVG_PAINT_RADIAL_GRADIENT)
		NANOSVG_free(paint->gradient);
}

static void nsvg__deleteGradientData(NSVGgradientData* grad)
{
	NSVGgradientData* next;
	while (grad != NULL) {
		next = grad->next;
		NANOSVG_free(grad->stops);
		NANOSVG_free(grad);
		grad = next;
	}
}

static void nsvg__deleteParser(NSVGparser* p)
{
	if (p != NULL) {
		nsvg__deleteStyles(p->styles);
		nsvg__deletePaths(p->plist);
		nsvg__deleteGradientData(p->gradients);
		nsvgDelete(p->image);
		NANOSVG_free(p->pts);
		NANOSVG_free(p);
	}
}

static void nsvg__resetPath(NSVGparser* p)
{
	p->npts = 0;
}

static void nsvg__addPoint(NSVGparser* p, float x, float y)
{
	if (p->npts+1 > p->cpts) {
		p->cpts = p->cpts ? p->cpts*2 : 8;
		p->pts = (float*)NANOSVG_realloc(p->pts, p->cpts*2*sizeof(float));
		if (!p->pts) return;
	}
	p->pts[p->npts*2+0] = x;
	p->pts[p->npts*2+1] = y;
	p->npts++;
}

static void nsvg__moveTo(NSVGparser* p, float x, float y)
{
	if (p->npts > 0) {
		p->pts[(p->npts-1)*2+0] = x;
		p->pts[(p->npts-1)*2+1] = y;
	} else {
		nsvg__addPoint(p, x, y);
	}
}

static void nsvg__lineTo(NSVGparser* p, float x, float y)
{
	float px,py, dx,dy;
	if (p->npts > 0) {
		px = p->pts[(p->npts-1)*2+0];
		py = p->pts[(p->npts-1)*2+1];
		dx = x - px;
		dy = y - py;
		nsvg__addPoint(p, px + dx/3.0f, py + dy/3.0f);
		nsvg__addPoint(p, x - dx/3.0f, y - dy/3.0f);
		nsvg__addPoint(p, x, y);
	}
}

static void nsvg__cubicBezTo(NSVGparser* p, float cpx1, float cpy1, float cpx2, float cpy2, float x, float y)
{
	if (p->npts > 0) {
		nsvg__addPoint(p, cpx1, cpy1);
		nsvg__addPoint(p, cpx2, cpy2);
		nsvg__addPoint(p, x, y);
	}
}

static NSVGattrib* nsvg__getAttr(NSVGparser* p)
{
	return &p->attr[p->attrHead];
}

static void nsvg__pushAttr(NSVGparser* p)
{
	if (p->attrHead < NSVG_MAX_ATTR-1) {
		p->attrHead++;
		memcpy(&p->attr[p->attrHead], &p->attr[p->attrHead-1], sizeof(NSVGattrib));
	}
}

static void nsvg__popAttr(NSVGparser* p)
{
	if (p->attrHead > 0)
		p->attrHead--;
}

static float nsvg__actualOrigX(NSVGparser* p)
{
	return p->viewMinx;
}

static float nsvg__actualOrigY(NSVGparser* p)
{
	return p->viewMiny;
}

static float nsvg__actualWidth(NSVGparser* p)
{
	return p->viewWidth;
}

static float nsvg__actualHeight(NSVGparser* p)
{
	return p->viewHeight;
}

static float nsvg__actualLength(NSVGparser* p)
{
	float w = nsvg__actualWidth(p), h = nsvg__actualHeight(p);
	return sqrtf(w*w + h*h) / sqrtf(2.0f);
}

static float nsvg__convertToPixels(NSVGparser* p, NSVGcoordinate c, float orig, float length)
{
	NSVGattrib* attr = nsvg__getAttr(p);
	switch (c.units) {
		case NSVG_UNITS_USER:		return c.value;
		case NSVG_UNITS_PX:			return c.value;
		case NSVG_UNITS_PT:			return c.value / 72.0f * p->dpi;
		case NSVG_UNITS_PC:			return c.value / 6.0f * p->dpi;
		case NSVG_UNITS_MM:			return c.value / 25.4f * p->dpi;
		case NSVG_UNITS_CM:			return c.value / 2.54f * p->dpi;
		case NSVG_UNITS_IN:			return c.value * p->dpi;
		case NSVG_UNITS_EM:			return c.value * attr->fontSize;
		case NSVG_UNITS_EX:			return c.value * attr->fontSize * 0.52f; /* x-height of Helvetica. */
		case NSVG_UNITS_PERCENT:	return orig + c.value / 100.0f * length;
		default:					return c.value;
	}
	return c.value;
}

static NSVGgradientData* nsvg__findGradientData(NSVGparser* p, const char* id)
{
	NSVGgradientData* grad = p->gradients;
	if (id == NULL || *id == '\0')
		return NULL;
	while (grad != NULL) {
		if (strcmp(grad->id, id) == 0)
			return grad;
		grad = grad->next;
	}
	return NULL;
}

static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const float* localBounds, float *xform, signed char* paintType)
{
	NSVGgradientData* data = NULL;
	NSVGgradientData* ref = NULL;
	NSVGgradientStop* stops = NULL;
	NSVGgradient* grad;
	float ox, oy, sw, sh, sl;
	int nstops = 0;
	int refIter;

	data = nsvg__findGradientData(p, id);
	if (data == NULL) return NULL;

	/* TODO: use ref to fill in all unset values too. */
	ref = data;
	refIter = 0;
	while (ref != NULL) {
		NSVGgradientData* nextRef = NULL;
		if (stops == NULL && ref->stops != NULL) {
			stops = ref->stops;
			nstops = ref->nstops;
			break;
		}
		nextRef = nsvg__findGradientData(p, ref->ref);
		if (nextRef == ref) break; /* prevent infite loops on malformed data */
		ref = nextRef;
		refIter++;
		if (refIter > 32) break; /* prevent infite loops on malformed data */
	}
	if (stops == NULL) return NULL;

	grad = (NSVGgradient*)NANOSVG_malloc(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops-1));
	if (grad == NULL) return NULL;

	/* The shape width and height. */
	if (data->units == NSVG_OBJECT_SPACE) {
		ox = localBounds[0];
		oy = localBounds[1];
		sw = localBounds[2] - localBounds[0];
		sh = localBounds[3] - localBounds[1];
	} else {
		ox = nsvg__actualOrigX(p);
		oy = nsvg__actualOrigY(p);
		sw = nsvg__actualWidth(p);
		sh = nsvg__actualHeight(p);
	}
	sl = sqrtf(sw*sw + sh*sh) / sqrtf(2.0f);

	if (data->type == NSVG_PAINT_LINEAR_GRADIENT) {
		float x1, y1, x2, y2, dx, dy;
		x1 = nsvg__convertToPixels(p, data->linear.x1, ox, sw);
		y1 = nsvg__convertToPixels(p, data->linear.y1, oy, sh);
		x2 = nsvg__convertToPixels(p, data->linear.x2, ox, sw);
		y2 = nsvg__convertToPixels(p, data->linear.y2, oy, sh);
		/* Calculate transform aligned to the line */
		dx = x2 - x1;
		dy = y2 - y1;
		grad->xform[0] = dy; grad->xform[1] = -dx;
		grad->xform[2] = dx; grad->xform[3] = dy;
		grad->xform[4] = x1; grad->xform[5] = y1;
	} else {
		float cx, cy, fx, fy, r;
		cx = nsvg__convertToPixels(p, data->radial.cx, ox, sw);
		cy = nsvg__convertToPixels(p, data->radial.cy, oy, sh);
		fx = nsvg__convertToPixels(p, data->radial.fx, ox, sw);
		fy = nsvg__convertToPixels(p, data->radial.fy, oy, sh);
		r = nsvg__convertToPixels(p, data->radial.r, 0, sl);
		/* Calculate transform aligned to the circle */
		grad->xform[0] = r; grad->xform[1] = 0;
		grad->xform[2] = 0; grad->xform[3] = r;
		grad->xform[4] = cx; grad->xform[5] = cy;
		grad->fx = fx / r;
		grad->fy = fy / r;
	}

	nsvg__xformMultiply(grad->xform, data->xform);
	nsvg__xformMultiply(grad->xform, xform);

	grad->spread = data->spread;
	memcpy(grad->stops, stops, nstops*sizeof(NSVGgradientStop));
	grad->nstops = nstops;

	*paintType = data->type;

	return grad;
}

static float nsvg__getAverageScale(float* t)
{
	float sx = sqrtf(t[0]*t[0] + t[2]*t[2]);
	float sy = sqrtf(t[1]*t[1] + t[3]*t[3]);
	return (sx + sy) * 0.5f;
}

static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape, float* xform)
{
	NSVGpath* path;
	float curve[4*2], curveBounds[4];
	int i, first = 1;
	for (path = shape->paths; path != NULL; path = path->next) {
		nsvg__xformPoint(&curve[0], &curve[1], path->pts[0], path->pts[1], xform);
		for (i = 0; i < path->npts-1; i += 3) {
			nsvg__xformPoint(&curve[2], &curve[3], path->pts[(i+1)*2], path->pts[(i+1)*2+1], xform);
			nsvg__xformPoint(&curve[4], &curve[5], path->pts[(i+2)*2], path->pts[(i+2)*2+1], xform);
			nsvg__xformPoint(&curve[6], &curve[7], path->pts[(i+3)*2], path->pts[(i+3)*2+1], xform);
			nsvg__curveBounds(curveBounds, curve);
			if (first) {
				bounds[0] = curveBounds[0];
				bounds[1] = curveBounds[1];
				bounds[2] = curveBounds[2];
				bounds[3] = curveBounds[3];
				first = 0;
			} else {
				bounds[0] = nsvg__minf(bounds[0], curveBounds[0]);
				bounds[1] = nsvg__minf(bounds[1], curveBounds[1]);
				bounds[2] = nsvg__maxf(bounds[2], curveBounds[2]);
				bounds[3] = nsvg__maxf(bounds[3], curveBounds[3]);
			}
			curve[0] = curve[6];
			curve[1] = curve[7];
		}
	}
}

static void nsvg__addShape(NSVGparser* p)
{
	NSVGattrib* attr = nsvg__getAttr(p);
	float scale = 1.0f;
	NSVGshape* shape;
	NSVGpath* path;
	int i;

	if (p->plist == NULL)
		return;

	shape = (NSVGshape*)NANOSVG_malloc(sizeof(NSVGshape));
	if (shape == NULL) goto error;
	memset(shape, 0, sizeof(NSVGshape));

	memcpy(shape->id, attr->id, sizeof shape->id);
	memcpy(shape->fillGradient, attr->fillGradient, sizeof shape->fillGradient);
	memcpy(shape->strokeGradient, attr->strokeGradient, sizeof shape->strokeGradient);
	memcpy(shape->xform, attr->xform, sizeof shape->xform);
	scale = nsvg__getAverageScale(attr->xform);
	shape->strokeWidth = attr->strokeWidth * scale;
	shape->strokeDashOffset = attr->strokeDashOffset * scale;
	shape->strokeDashCount = (char)attr->strokeDashCount;
	for (i = 0; i < attr->strokeDashCount; i++)
		shape->strokeDashArray[i] = attr->strokeDashArray[i] * scale;
	shape->strokeLineJoin = attr->strokeLineJoin;
	shape->strokeLineCap = attr->strokeLineCap;
	shape->miterLimit = attr->miterLimit;
	shape->fillRule = attr->fillRule;
	shape->opacity = attr->opacity;

	shape->paths = p->plist;
	p->plist = NULL;

	/* Calculate shape bounds */
	shape->bounds[0] = shape->paths->bounds[0];
	shape->bounds[1] = shape->paths->bounds[1];
	shape->bounds[2] = shape->paths->bounds[2];
	shape->bounds[3] = shape->paths->bounds[3];
	for (path = shape->paths->next; path != NULL; path = path->next) {
		shape->bounds[0] = nsvg__minf(shape->bounds[0], path->bounds[0]);
		shape->bounds[1] = nsvg__minf(shape->bounds[1], path->bounds[1]);
		shape->bounds[2] = nsvg__maxf(shape->bounds[2], path->bounds[2]);
		shape->bounds[3] = nsvg__maxf(shape->bounds[3], path->bounds[3]);
	}

	/* Set fill */
	if (attr->hasFill == 0) {
		shape->fill.type = NSVG_PAINT_NONE;
	} else if (attr->hasFill == 1) {
		shape->fill.type = NSVG_PAINT_COLOR;
		shape->fill.color = attr->fillColor;
		shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24;
	} else if (attr->hasFill == 2) {
		shape->fill.type = NSVG_PAINT_UNDEF;
	}

	/* Set stroke */
	if (attr->hasStroke == 0) {
		shape->stroke.type = NSVG_PAINT_NONE;
	} else if (attr->hasStroke == 1) {
		shape->stroke.type = NSVG_PAINT_COLOR;
		shape->stroke.color = attr->strokeColor;
		shape->stroke.color |= (unsigned int)(attr->strokeOpacity*255) << 24;
	} else if (attr->hasStroke == 2) {
		shape->stroke.type = NSVG_PAINT_UNDEF;
	}

	/* Set flags */
	shape->flags = ((attr->visible & NSVG_VIS_DISPLAY) && (attr->visible & NSVG_VIS_VISIBLE) ? NSVG_FLAGS_VISIBLE : 0x00);

	/* Add to tail */
	if (p->image->shapes == NULL)
		p->image->shapes = shape;
	else
		p->shapesTail->next = shape;
	p->shapesTail = shape;

	return;

error:
	if (shape) NANOSVG_free(shape);
}

static void nsvg__addPath(NSVGparser* p, char closed)
{
	NSVGattrib* attr = nsvg__getAttr(p);
	NSVGpath* path = NULL;
	float bounds[4];
	float* curve;
	int i;

	if (p->npts < 4)
		return;

	if (closed)
		nsvg__lineTo(p, p->pts[0], p->pts[1]);

	/* Expect 1 + N*3 points (N = number of cubic bezier segments). */
	if ((p->npts % 3) != 1)
		return;

	path = (NSVGpath*)NANOSVG_malloc(sizeof(NSVGpath));
	if (path == NULL) goto error;
	memset(path, 0, sizeof(NSVGpath));

	path->pts = (float*)NANOSVG_malloc(p->npts*2*sizeof(float));
	if (path->pts == NULL) goto error;
	path->closed = closed;
	path->npts = p->npts;

	/* Transform path. */
	for (i = 0; i < p->npts; ++i)
		nsvg__xformPoint(&path->pts[i*2], &path->pts[i*2+1], p->pts[i*2], p->pts[i*2+1], attr->xform);

	/* Find bounds */
	for (i = 0; i < path->npts-1; i += 3) {
		curve = &path->pts[i*2];
		nsvg__curveBounds(bounds, curve);
		if (i == 0) {
			path->bounds[0] = bounds[0];
			path->bounds[1] = bounds[1];
			path->bounds[2] = bounds[2];
			path->bounds[3] = bounds[3];
		} else {
			path->bounds[0] = nsvg__minf(path->bounds[0], bounds[0]);
			path->bounds[1] = nsvg__minf(path->bounds[1], bounds[1]);
			path->bounds[2] = nsvg__maxf(path->bounds[2], bounds[2]);
			path->bounds[3] = nsvg__maxf(path->bounds[3], bounds[3]);
		}
	}

	path->next = p->plist;
	p->plist = path;

	return;

error:
	if (path != NULL) {
		if (path->pts != NULL) NANOSVG_free(path->pts);
		NANOSVG_free(path);
	}
}

/* We roll our own string to float because the std library one uses locale and messes things up. */
static double nsvg__atof(const char* s)
{
	char* cur = (char*)s;
	char* end = NULL;
	double res = 0.0, sign = 1.0;
#if defined(_MSC_VER) && (_MSC_VER == 1200)
	__int64 intPart = 0, fracPart = 0;
#else
	long long intPart = 0, fracPart = 0;
#endif
	char hasIntPart = 0, hasFracPart = 0;

	/* Parse optional sign */
	if (*cur == '+') {
		cur++;
	} else if (*cur == '-') {
		sign = -1;
		cur++;
	}

	/* Parse integer part */
	if (nsvg__isdigit(*cur)) {
		/* Parse digit sequence */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
		intPart = strtol(cur, &end, 10);
#else
		intPart = strtoll(cur, &end, 10);
#endif
		if (cur != end) {
			res = (double)intPart;
			hasIntPart = 1;
			cur = end;
		}
	}

	/* Parse fractional part. */
	if (*cur == '.') {
		cur++; /* Skip '.' */
		if (nsvg__isdigit(*cur)) {
			/* Parse digit sequence */
#if defined(_MSC_VER) && (_MSC_VER == 1200)
			fracPart = strtol(cur, &end, 10);
#else
			fracPart = strtoll(cur, &end, 10);
#endif
			if (cur != end) {
				res += (double)fracPart / pow(10.0, (double)(end - cur));
				hasFracPart = 1;
				cur = end;
			}
		}
	}

	/* A valid number should have integer or fractional part. */
	if (!hasIntPart && !hasFracPart)
		return 0.0;

	/* Parse optional exponent */
	if (*cur == 'e' || *cur == 'E') {
		int expPart = 0;
		cur++; /* skip 'E' */
		expPart = strtol(cur, &end, 10); /* Parse digit sequence with sign */
		if (cur != end) {
			res *= pow(10.0, (double)expPart);
		}
	}

	return res * sign;
}


static const char* nsvg__parseNumber(const char* s, char* it, const int size)
{
	const int last = size-1;
	int i = 0;

	/* sign */
	if (*s == '-' || *s == '+') {
		if (i < last) it[i++] = *s;
		s++;
	}
	/* integer part */
	while (*s && nsvg__isdigit(*s)) {
		if (i < last) it[i++] = *s;
		s++;
	}
	if (*s == '.') {
		/* decimal point */
		if (i < last) it[i++] = *s;
		s++;
		/* fraction part */
		while (*s && nsvg__isdigit(*s)) {
			if (i < last) it[i++] = *s;
			s++;
		}
	}
	/* exponent */
	if (*s == 'e' || *s == 'E') {
		if (i < last) it[i++] = *s;
		s++;
		if (*s == '-' || *s == '+') {
			if (i < last) it[i++] = *s;
			s++;
		}
		while (*s && nsvg__isdigit(*s)) {
			if (i < last) it[i++] = *s;
			s++;
		}
	}
	it[i] = '\0';

	return s;
}

static const char* nsvg__getNextPathItemWhenArcFlag(const char* s, char* it)
{
	it[0] = '\0';
	while (*s && (nsvg__isspace(*s) || *s == ',')) s++;
	if (!*s) return s;
	if (*s == '0' || *s == '1') {
		it[0] = *s++;
		it[1] = '\0';
		return s;
	}
	return s;
}

static const char* nsvg__getNextPathItem(const char* s, char* it)
{
	it[0] = '\0';
	/* Skip white spaces and commas */
	while (*s && (nsvg__isspace(*s) || *s == ',')) s++;
	if (!*s) return s;
	if (*s == '-' || *s == '+' || *s == '.' || nsvg__isdigit(*s)) {
		s = nsvg__parseNumber(s, it, 64);
	} else {
		/* Parse command */
		it[0] = *s++;
		it[1] = '\0';
		return s;
	}

	return s;
}

static unsigned int nsvg__parseColorHex(const char* str)
{
	unsigned int r=0, g=0, b=0;
	if (sscanf(str, "#%2x%2x%2x", &r, &g, &b) == 3 )		/* 2 digit hex */
		return NSVG_RGB(r, g, b);
	if (sscanf(str, "#%1x%1x%1x", &r, &g, &b) == 3 )		/* 1 digit hex, e.g. #abc -> 0xccbbaa */
		return NSVG_RGB(r*17, g*17, b*17);			/* same effect as (r<<4|r), (g<<4|g), .. */
	return NSVG_RGB(128, 128, 128);
}

/*
 * Parse rgb color. The pointer 'str' must point at "rgb(" (4+ characters).
 * This function returns gray (rgb(128, 128, 128) == '#808080') on parse errors
 * for backwards compatibility. Note: other image viewers return black instead.
 */

static unsigned int nsvg__parseColorRGB(const char* str)
{
	int i;
	unsigned int rgbi[3];
	float rgbf[3];
	/* try decimal integers first */
	if (sscanf(str, "rgb(%u, %u, %u)", &rgbi[0], &rgbi[1], &rgbi[2]) != 3) {
		/* integers failed, try percent values (float, locale independent) */
		const char delimiter[3] = {',', ',', ')'};
		str += 4; /* skip "rgb(" */
		for (i = 0; i < 3; i++) {
			while (*str && (nsvg__isspace(*str))) str++; 	/* skip leading spaces */
			if (*str == '+') str++;				/* skip '+' (don't allow '-') */
			if (!*str) break;
			rgbf[i] = nsvg__atof(str);

			/*
			 * Note 1: it would be great if nsvg__atof() returned how many
			 * bytes it consumed but it doesn't. We need to skip the number,
			 * the '%' character, spaces, and the delimiter ',' or ')'.
			 *
			 * Note 2: The following code does not allow values like "33.%",
			 * i.e. a decimal point w/o fractional part, but this is consistent
			 * with other image viewers, e.g. firefox, chrome, eog, gimp.
			 */

			while (*str && nsvg__isdigit(*str)) str++;		/* skip integer part */
			if (*str == '.') {
				str++;
				if (!nsvg__isdigit(*str)) break;		/* error: no digit after '.' */
				while (*str && nsvg__isdigit(*str)) str++;	/* skip fractional part */
			}
			if (*str == '%') str++; else break;
			while (nsvg__isspace(*str)) str++;
			if (*str == delimiter[i]) str++;
			else break;
		}
		if (i == 3) {
			rgbi[0] = roundf(rgbf[0] * 2.55f);
			rgbi[1] = roundf(rgbf[1] * 2.55f);
			rgbi[2] = roundf(rgbf[2] * 2.55f);
		} else {
			rgbi[0] = rgbi[1] = rgbi[2] = 128;
		}
	}
	/* clip values as the CSS spec requires */
	for (i = 0; i < 3; i++) {
		if (rgbi[i] > 255) rgbi[i] = 255;
	}
	return NSVG_RGB(rgbi[0], rgbi[1], rgbi[2]);
}

typedef struct NSVGNamedColor {
	const char* name;
	unsigned int color;
} NSVGNamedColor;

NSVGNamedColor nsvg__colors[] = {

	{ "red", NSVG_RGB(255, 0, 0) },
	{ "green", NSVG_RGB( 0, 128, 0) },
	{ "blue", NSVG_RGB( 0, 0, 255) },
	{ "yellow", NSVG_RGB(255, 255, 0) },
	{ "cyan", NSVG_RGB( 0, 255, 255) },
	{ "magenta", NSVG_RGB(255, 0, 255) },
	{ "black", NSVG_RGB( 0, 0, 0) },
	{ "grey", NSVG_RGB(128, 128, 128) },
	{ "gray", NSVG_RGB(128, 128, 128) },
	{ "white", NSVG_RGB(255, 255, 255) },

#ifdef NANOSVG_ALL_COLOR_KEYWORDS
	{ "aliceblue", NSVG_RGB(240, 248, 255) },
	{ "antiquewhite", NSVG_RGB(250, 235, 215) },
	{ "aqua", NSVG_RGB( 0, 255, 255) },
	{ "aquamarine", NSVG_RGB(127, 255, 212) },
	{ "azure", NSVG_RGB(240, 255, 255) },
	{ "beige", NSVG_RGB(245, 245, 220) },
	{ "bisque", NSVG_RGB(255, 228, 196) },
	{ "blanchedalmond", NSVG_RGB(255, 235, 205) },
	{ "blueviolet", NSVG_RGB(138, 43, 226) },
	{ "brown", NSVG_RGB(165, 42, 42) },
	{ "burlywood", NSVG_RGB(222, 184, 135) },
	{ "cadetblue", NSVG_RGB( 95, 158, 160) },
	{ "chartreuse", NSVG_RGB(127, 255, 0) },
	{ "chocolate", NSVG_RGB(210, 105, 30) },
	{ "coral", NSVG_RGB(255, 127, 80) },
	{ "cornflowerblue", NSVG_RGB(100, 149, 237) },
	{ "cornsilk", NSVG_RGB(255, 248, 220) },
	{ "crimson", NSVG_RGB(220, 20, 60) },
	{ "darkblue", NSVG_RGB( 0, 0, 139) },
	{ "darkcyan", NSVG_RGB( 0, 139, 139) },
	{ "darkgoldenrod", NSVG_RGB(184, 134, 11) },
	{ "darkgray", NSVG_RGB(169, 169, 169) },
	{ "darkgreen", NSVG_RGB( 0, 100, 0) },
	{ "darkgrey", NSVG_RGB(169, 169, 169) },
	{ "darkkhaki", NSVG_RGB(189, 183, 107) },
	{ "darkmagenta", NSVG_RGB(139, 0, 139) },
	{ "darkolivegreen", NSVG_RGB( 85, 107, 47) },
	{ "darkorange", NSVG_RGB(255, 140, 0) },
	{ "darkorchid", NSVG_RGB(153, 50, 204) },
	{ "darkred", NSVG_RGB(139, 0, 0) },
	{ "darksalmon", NSVG_RGB(233, 150, 122) },
	{ "darkseagreen", NSVG_RGB(143, 188, 143) },
	{ "darkslateblue", NSVG_RGB( 72, 61, 139) },
	{ "darkslategray", NSVG_RGB( 47, 79, 79) },
	{ "darkslategrey", NSVG_RGB( 47, 79, 79) },
	{ "darkturquoise", NSVG_RGB( 0, 206, 209) },
	{ "darkviolet", NSVG_RGB(148, 0, 211) },
	{ "deeppink", NSVG_RGB(255, 20, 147) },
	{ "deepskyblue", NSVG_RGB( 0, 191, 255) },
	{ "dimgray", NSVG_RGB(105, 105, 105) },
	{ "dimgrey", NSVG_RGB(105, 105, 105) },
	{ "dodgerblue", NSVG_RGB( 30, 144, 255) },
	{ "firebrick", NSVG_RGB(178, 34, 34) },
	{ "floralwhite", NSVG_RGB(255, 250, 240) },
	{ "forestgreen", NSVG_RGB( 34, 139, 34) },
	{ "fuchsia", NSVG_RGB(255, 0, 255) },
	{ "gainsboro", NSVG_RGB(220, 220, 220) },
	{ "ghostwhite", NSVG_RGB(248, 248, 255) },
	{ "gold", NSVG_RGB(255, 215, 0) },
	{ "goldenrod", NSVG_RGB(218, 165, 32) },
	{ "greenyellow", NSVG_RGB(173, 255, 47) },
	{ "honeydew", NSVG_RGB(240, 255, 240) },
	{ "hotpink", NSVG_RGB(255, 105, 180) },
	{ "indianred", NSVG_RGB(205, 92, 92) },
	{ "indigo", NSVG_RGB( 75, 0, 130) },
	{ "ivory", NSVG_RGB(255, 255, 240) },
	{ "khaki", NSVG_RGB(240, 230, 140) },
	{ "lavender", NSVG_RGB(230, 230, 250) },
	{ "lavenderblush", NSVG_RGB(255, 240, 245) },
	{ "lawngreen", NSVG_RGB(124, 252, 0) },
	{ "lemonchiffon", NSVG_RGB(255, 250, 205) },
	{ "lightblue", NSVG_RGB(173, 216, 230) },
	{ "lightcoral", NSVG_RGB(240, 128, 128) },
	{ "lightcyan", NSVG_RGB(224, 255, 255) },
	{ "lightgoldenrodyellow", NSVG_RGB(250, 250, 210) },
	{ "lightgray", NSVG_RGB(211, 211, 211) },
	{ "lightgreen", NSVG_RGB(144, 238, 144) },
	{ "lightgrey", NSVG_RGB(211, 211, 211) },
	{ "lightpink", NSVG_RGB(255, 182, 193) },
	{ "lightsalmon", NSVG_RGB(255, 160, 122) },
	{ "lightseagreen", NSVG_RGB( 32, 178, 170) },
	{ "lightskyblue", NSVG_RGB(135, 206, 250) },
	{ "lightslategray", NSVG_RGB(119, 136, 153) },
	{ "lightslategrey", NSVG_RGB(119, 136, 153) },
	{ "lightsteelblue", NSVG_RGB(176, 196, 222) },
	{ "lightyellow", NSVG_RGB(255, 255, 224) },
	{ "lime", NSVG_RGB( 0, 255, 0) },
	{ "limegreen", NSVG_RGB( 50, 205, 50) },
	{ "linen", NSVG_RGB(250, 240, 230) },
	{ "maroon", NSVG_RGB(128, 0, 0) },
	{ "mediumaquamarine", NSVG_RGB(102, 205, 170) },
	{ "mediumblue", NSVG_RGB( 0, 0, 205) },
	{ "mediumorchid", NSVG_RGB(186, 85, 211) },
	{ "mediumpurple", NSVG_RGB(147, 112, 219) },
	{ "mediumseagreen", NSVG_RGB( 60, 179, 113) },
	{ "mediumslateblue", NSVG_RGB(123, 104, 238) },
	{ "mediumspringgreen", NSVG_RGB( 0, 250, 154) },
	{ "mediumturquoise", NSVG_RGB( 72, 209, 204) },
	{ "mediumvioletred", NSVG_RGB(199, 21, 133) },
	{ "midnightblue", NSVG_RGB( 25, 25, 112) },
	{ "mintcream", NSVG_RGB(245, 255, 250) },
	{ "mistyrose", NSVG_RGB(255, 228, 225) },
	{ "moccasin", NSVG_RGB(255, 228, 181) },
	{ "navajowhite", NSVG_RGB(255, 222, 173) },
	{ "navy", NSVG_RGB( 0, 0, 128) },
	{ "oldlace", NSVG_RGB(253, 245, 230) },
	{ "olive", NSVG_RGB(128, 128, 0) },
	{ "olivedrab", NSVG_RGB(107, 142, 35) },
	{ "orange", NSVG_RGB(255, 165, 0) },
	{ "orangered", NSVG_RGB(255, 69, 0) },
	{ "orchid", NSVG_RGB(218, 112, 214) },
	{ "palegoldenrod", NSVG_RGB(238, 232, 170) },
	{ "palegreen", NSVG_RGB(152, 251, 152) },
	{ "paleturquoise", NSVG_RGB(175, 238, 238) },
	{ "palevioletred", NSVG_RGB(219, 112, 147) },
	{ "papayawhip", NSVG_RGB(255, 239, 213) },
	{ "peachpuff", NSVG_RGB(255, 218, 185) },
	{ "peru", NSVG_RGB(205, 133, 63) },
	{ "pink", NSVG_RGB(255, 192, 203) },
	{ "plum", NSVG_RGB(221, 160, 221) },
	{ "powderblue", NSVG_RGB(176, 224, 230) },
	{ "purple", NSVG_RGB(128, 0, 128) },
	{ "rosybrown", NSVG_RGB(188, 143, 143) },
	{ "royalblue", NSVG_RGB( 65, 105, 225) },
	{ "saddlebrown", NSVG_RGB(139, 69, 19) },
	{ "salmon", NSVG_RGB(250, 128, 114) },
	{ "sandybrown", NSVG_RGB(244, 164, 96) },
	{ "seagreen", NSVG_RGB( 46, 139, 87) },
	{ "seashell", NSVG_RGB(255, 245, 238) },
	{ "sienna", NSVG_RGB(160, 82, 45) },
	{ "silver", NSVG_RGB(192, 192, 192) },
	{ "skyblue", NSVG_RGB(135, 206, 235) },
	{ "slateblue", NSVG_RGB(106, 90, 205) },
	{ "slategray", NSVG_RGB(112, 128, 144) },
	{ "slategrey", NSVG_RGB(112, 128, 144) },
	{ "snow", NSVG_RGB(255, 250, 250) },
	{ "springgreen", NSVG_RGB( 0, 255, 127) },
	{ "steelblue", NSVG_RGB( 70, 130, 180) },
	{ "tan", NSVG_RGB(210, 180, 140) },
	{ "teal", NSVG_RGB( 0, 128, 128) },
	{ "thistle", NSVG_RGB(216, 191, 216) },
	{ "tomato", NSVG_RGB(255, 99, 71) },
	{ "turquoise", NSVG_RGB( 64, 224, 208) },
	{ "violet", NSVG_RGB(238, 130, 238) },
	{ "wheat", NSVG_RGB(245, 222, 179) },
	{ "whitesmoke", NSVG_RGB(245, 245, 245) },
	{ "yellowgreen", NSVG_RGB(154, 205, 50) },
#endif
};

static unsigned int nsvg__parseColorName(const char* str)
{
	int i, ncolors = sizeof(nsvg__colors) / sizeof(NSVGNamedColor);

	for (i = 0; i < ncolors; i++) {
		if (strcmp(nsvg__colors[i].name, str) == 0) {
			return nsvg__colors[i].color;
		}
	}

	return NSVG_RGB(128, 128, 128);
}

static unsigned int nsvg__parseColor(const char* str)
{
	size_t len = 0;
	while(*str == ' ') ++str;
	len = strlen(str);
	if (len >= 1 && *str == '#')
		return nsvg__parseColorHex(str);
	else if (len >= 4 && str[0] == 'r' && str[1] == 'g' && str[2] == 'b' && str[3] == '(')
		return nsvg__parseColorRGB(str);
	return nsvg__parseColorName(str);
}

static float nsvg__parseOpacity(const char* str)
{
	float val = 0;
	sscanf(str, "%f", &val);
	if (val < 0.0f) val = 0.0f;
	if (val > 1.0f) val = 1.0f;
	return val;
}

static float nsvg__parseMiterLimit(const char* str)
{
	float val = 0;
	sscanf(str, "%f", &val);
	if (val < 0.0f) val = 0.0f;
	return val;
}

static int nsvg__parseUnits(const char* units)
{
	if (units[0] == 'p' && units[1] == 'x')
		return NSVG_UNITS_PX;
	else if (units[0] == 'p' && units[1] == 't')
		return NSVG_UNITS_PT;
	else if (units[0] == 'p' && units[1] == 'c')
		return NSVG_UNITS_PC;
	else if (units[0] == 'm' && units[1] == 'm')
		return NSVG_UNITS_MM;
	else if (units[0] == 'c' && units[1] == 'm')
		return NSVG_UNITS_CM;
	else if (units[0] == 'i' && units[1] == 'n')
		return NSVG_UNITS_IN;
	else if (units[0] == '%')
		return NSVG_UNITS_PERCENT;
	else if (units[0] == 'e' && units[1] == 'm')
		return NSVG_UNITS_EM;
	else if (units[0] == 'e' && units[1] == 'x')
		return NSVG_UNITS_EX;
	return NSVG_UNITS_USER;
}

static int nsvg__isCoordinate(const char* s)
{
	/* optional sign */
	if (*s == '-' || *s == '+')
		s++;
	/* must have at least one digit, or start by a dot */
	return (nsvg__isdigit(*s) || *s == '.');
}

static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str)
{
	NSVGcoordinate coord = {0, NSVG_UNITS_USER};
	char units[32]="";
	sscanf(str, "%f%s", &coord.value, units);
	coord.units = nsvg__parseUnits(units);
	return coord;
}

static NSVGcoordinate nsvg__coord(float v, int units)
{
	NSVGcoordinate coord = {v, units};
	return coord;
}

static float nsvg__parseCoordinate(NSVGparser* p, const char* str, float orig, float length)
{
	NSVGcoordinate coord = nsvg__parseCoordinateRaw(str);
	return nsvg__convertToPixels(p, coord, orig, length);
}

static int nsvg__parseTransformArgs(const char* str, float* args, int maxNa, int* na)
{
	const char* end;
	const char* ptr;
	char it[64];

	*na = 0;
	ptr = str;
	while (*ptr && *ptr != '(') ++ptr;
	if (*ptr == 0)
		return 1;
	end = ptr;
	while (*end && *end != ')') ++end;
	if (*end == 0)
		return 1;

	while (ptr < end) {
		if (*ptr == '-' || *ptr == '+' || *ptr == '.' || nsvg__isdigit(*ptr)) {
			if (*na >= maxNa) return 0;
			ptr = nsvg__parseNumber(ptr, it, 64);
			args[(*na)++] = (float)nsvg__atof(it);
		} else {
			++ptr;
		}
	}
	return (int)(end - str);
}


static int nsvg__parseMatrix(float* xform, const char* str)
{
	float t[6];
	int na = 0;
	int len = nsvg__parseTransformArgs(str, t, 6, &na);
	if (na != 6) return len;
	memcpy(xform, t, sizeof(float)*6);
	return len;
}

static int nsvg__parseTranslate(float* xform, const char* str)
{
	float args[2];
	float t[6];
	int na = 0;
	int len = nsvg__parseTransformArgs(str, args, 2, &na);
	if (na == 1) args[1] = 0.0;

	nsvg__xformSetTranslation(t, args[0], args[1]);
	memcpy(xform, t, sizeof(float)*6);
	return len;
}

static int nsvg__parseScale(float* xform, const char* str)
{
	float args[2];
	int na = 0;
	float t[6];
	int len = nsvg__parseTransformArgs(str, args, 2, &na);
	if (na == 1) args[1] = args[0];
	nsvg__xformSetScale(t, args[0], args[1]);
	memcpy(xform, t, sizeof(float)*6);
	return len;
}

static int nsvg__parseSkewX(float* xform, const char* str)
{
	float args[1];
	int na = 0;
	float t[6];
	int len = nsvg__parseTransformArgs(str, args, 1, &na);
	nsvg__xformSetSkewX(t, args[0]/180.0f*NSVG_PI);
	memcpy(xform, t, sizeof(float)*6);
	return len;
}

static int nsvg__parseSkewY(float* xform, const char* str)
{
	float args[1];
	int na = 0;
	float t[6];
	int len = nsvg__parseTransformArgs(str, args, 1, &na);
	nsvg__xformSetSkewY(t, args[0]/180.0f*NSVG_PI);
	memcpy(xform, t, sizeof(float)*6);
	return len;
}

static int nsvg__parseRotate(float* xform, const char* str)
{
	float args[3];
	int na = 0;
	float m[6];
	float t[6];
	int len = nsvg__parseTransformArgs(str, args, 3, &na);
	if (na == 1)
		args[1] = args[2] = 0.0f;
	nsvg__xformIdentity(m);

	if (na > 1) {
		nsvg__xformSetTranslation(t, -args[1], -args[2]);
		nsvg__xformMultiply(m, t);
	}

	nsvg__xformSetRotation(t, args[0]/180.0f*NSVG_PI);
	nsvg__xformMultiply(m, t);

	if (na > 1) {
		nsvg__xformSetTranslation(t, args[1], args[2]);
		nsvg__xformMultiply(m, t);
	}

	memcpy(xform, m, sizeof(float)*6);

	return len;
}

static void nsvg__parseTransform(float* xform, const char* str)
{
	float t[6];
        int len;
	nsvg__xformIdentity(xform);
	while (*str)
	{
		if (strncmp(str, "matrix", 6) == 0)
			len = nsvg__parseMatrix(t, str);
		else if (strncmp(str, "translate", 9) == 0)
			len = nsvg__parseTranslate(t, str);
		else if (strncmp(str, "scale", 5) == 0)
			len = nsvg__parseScale(t, str);
		else if (strncmp(str, "rotate", 6) == 0)
			len = nsvg__parseRotate(t, str);
		else if (strncmp(str, "skewX", 5) == 0)
			len = nsvg__parseSkewX(t, str);
		else if (strncmp(str, "skewY", 5) == 0)
			len = nsvg__parseSkewY(t, str);
		else{
			++str;
			continue;
		}
                if (len != 0) {
			str += len;
                } else {
			++str;
			continue;
                }

		nsvg__xformPremultiply(xform, t);
	}
}

static void nsvg__parseUrl(char* id, const char* str)
{
	int i = 0;
	str += 4; /* "url("; */
	if (*str && *str == '#')
		str++;
	while (i < 63 && *str && *str != ')') {
		id[i] = *str++;
		i++;
	}
	id[i] = '\0';
}

static char nsvg__parseLineCap(const char* str)
{
	if (strcmp(str, "butt") == 0)
		return NSVG_CAP_BUTT;
	else if (strcmp(str, "round") == 0)
		return NSVG_CAP_ROUND;
	else if (strcmp(str, "square") == 0)
		return NSVG_CAP_SQUARE;
	/* TODO: handle inherit. */
	return NSVG_CAP_BUTT;
}

static char nsvg__parseLineJoin(const char* str)
{
	if (strcmp(str, "miter") == 0)
		return NSVG_JOIN_MITER;
	else if (strcmp(str, "round") == 0)
		return NSVG_JOIN_ROUND;
	else if (strcmp(str, "bevel") == 0)
		return NSVG_JOIN_BEVEL;
	/* TODO: handle inherit. */
	return NSVG_JOIN_MITER;
}

static char nsvg__parseFillRule(const char* str)
{
	if (strcmp(str, "nonzero") == 0)
		return NSVG_FILLRULE_NONZERO;
	else if (strcmp(str, "evenodd") == 0)
		return NSVG_FILLRULE_EVENODD;
	/* TODO: handle inherit. */
	return NSVG_FILLRULE_NONZERO;
}

static const char* nsvg__getNextDashItem(const char* s, char* it)
{
	int n = 0;
	it[0] = '\0';
	/* Skip white spaces and commas */
	while (*s && (nsvg__isspace(*s) || *s == ',')) s++;
	/* Advance until whitespace, comma or end. */
	while (*s && (!nsvg__isspace(*s) && *s != ',')) {
		if (n < 63)
			it[n++] = *s;
		s++;
	}
	it[n++] = '\0';
	return s;
}

static int nsvg__parseStrokeDashArray(NSVGparser* p, const char* str, float* strokeDashArray)
{
	char item[64];
	int count = 0, i;
	float sum = 0.0f;

	/* Handle "none" */
	if (str[0] == 'n')
		return 0;

	/* Parse dashes */
	while (*str) {
		str = nsvg__getNextDashItem(str, item);
		if (!*item) break;
		if (count < NSVG_MAX_DASHES)
			strokeDashArray[count++] = fabsf(nsvg__parseCoordinate(p, item, 0.0f, nsvg__actualLength(p)));
	}

	for (i = 0; i < count; i++)
		sum += strokeDashArray[i];
	if (sum <= 1e-6f)
		count = 0;

	return count;
}

static void nsvg__parseStyle(NSVGparser* p, const char* str);

static int nsvg__parseAttr(NSVGparser* p, const char* name, const char* value)
{
	float xform[6];
	NSVGattrib* attr = nsvg__getAttr(p);
	if (!attr) return 0;

	if (strcmp(name, "style") == 0) {
		nsvg__parseStyle(p, value);
	} else if (strcmp(name, "display") == 0) {
		if (strcmp(value, "none") == 0)
			attr->visible &= ~NSVG_VIS_DISPLAY;
		/* Don't reset ->visible on display:inline, one display:none hides the whole subtree */

	} else if (strcmp(name, "visibility") == 0) {
		if (strcmp(value, "hidden") == 0) {
			attr->visible &= ~NSVG_VIS_VISIBLE;
		} else if (strcmp(value, "visible") == 0) {
			attr->visible |= NSVG_VIS_VISIBLE;
		}
	} else if (strcmp(name, "fill") == 0) {
		if (strcmp(value, "none") == 0) {
			attr->hasFill = 0;
		} else if (strncmp(value, "url(", 4) == 0) {
			attr->hasFill = 2;
			nsvg__parseUrl(attr->fillGradient, value);
		} else {
			attr->hasFill = 1;
			attr->fillColor = nsvg__parseColor(value);
		}
	} else if (strcmp(name, "opacity") == 0) {
		attr->opacity = nsvg__parseOpacity(value);
	} else if (strcmp(name, "fill-opacity") == 0) {
		attr->fillOpacity = nsvg__parseOpacity(value);
	} else if (strcmp(name, "stroke") == 0) {
		if (strcmp(value, "none") == 0) {
			attr->hasStroke = 0;
		} else if (strncmp(value, "url(", 4) == 0) {
			attr->hasStroke = 2;
			nsvg__parseUrl(attr->strokeGradient, value);
		} else {
			attr->hasStroke = 1;
			attr->strokeColor = nsvg__parseColor(value);
		}
	} else if (strcmp(name, "stroke-width") == 0) {
		attr->strokeWidth = nsvg__parseCoordinate(p, value, 0.0f, nsvg__actualLength(p));
	} else if (strcmp(name, "stroke-dasharray") == 0) {
		attr->strokeDashCount = nsvg__parseStrokeDashArray(p, value, attr->strokeDashArray);
	} else if (strcmp(name, "stroke-dashoffset") == 0) {
		attr->strokeDashOffset = nsvg__parseCoordinate(p, value, 0.0f, nsvg__actualLength(p));
	} else if (strcmp(name, "stroke-opacity") == 0) {
		attr->strokeOpacity = nsvg__parseOpacity(value);
	} else if (strcmp(name, "stroke-linecap") == 0) {
		attr->strokeLineCap = nsvg__parseLineCap(value);
	} else if (strcmp(name, "stroke-linejoin") == 0) {
		attr->strokeLineJoin = nsvg__parseLineJoin(value);
	} else if (strcmp(name, "stroke-miterlimit") == 0) {
		attr->miterLimit = nsvg__parseMiterLimit(value);
	} else if (strcmp(name, "fill-rule") == 0) {
		attr->fillRule = nsvg__parseFillRule(value);
	} else if (strcmp(name, "font-size") == 0) {
		attr->fontSize = nsvg__parseCoordinate(p, value, 0.0f, nsvg__actualLength(p));
	} else if (strcmp(name, "transform") == 0) {
		nsvg__parseTransform(xform, value);
		nsvg__xformPremultiply(attr->xform, xform);
	} else if (strcmp(name, "stop-color") == 0) {
		attr->stopColor = nsvg__parseColor(value);
	} else if (strcmp(name, "stop-opacity") == 0) {
		attr->stopOpacity = nsvg__parseOpacity(value);
	} else if (strcmp(name, "offset") == 0) {
		attr->stopOffset = nsvg__parseCoordinate(p, value, 0.0f, 1.0f);
	} else if (strcmp(name, "id") == 0) {
		strncpy(attr->id, value, 63);
		attr->id[63] = '\0';
	} else if (strcmp(name, "class") == 0) {
		NSVGstyles* style = p->styles;
		while (style) {
			if (strcmp(style->name + 1, value) == 0) {
				break;
			}
			style = style->next;
		}
		if (style) {
			nsvg__parseStyle(p, style->description);
		}
	} else {
		return 0;
	}
	return 1;
}

static int nsvg__parseNameValue(NSVGparser* p, const char* start, const char* end)
{
	const char* str;
	const char* val;
	char name[512];
	char value[512];
	int n;

	str = start;
	while (str < end && *str != ':') ++str;

	val = str;

	/* Right Trim */
	while (str > start &&  (*str == ':' || nsvg__isspace(*str))) --str;
	++str;

	n = (int)(str - start);
	if (n > 511) n = 511;
	if (n) memcpy(name, start, n);
	name[n] = 0;

	while (val < end && (*val == ':' || nsvg__isspace(*val))) ++val;

	n = (int)(end - val);
	if (n > 511) n = 511;
	if (n) memcpy(value, val, n);
	value[n] = 0;

	return nsvg__parseAttr(p, name, value);
}

static void nsvg__parseStyle(NSVGparser* p, const char* str)
{
	const char* start;
	const char* end;

	while (*str) {
		/* Left Trim */
		while(*str && nsvg__isspace(*str)) ++str;
		start = str;
		while(*str && *str != ';') ++str;
		end = str;

		/* Right Trim */
		while (end > start &&  (*end == ';' || nsvg__isspace(*end))) --end;
		++end;

		nsvg__parseNameValue(p, start, end);
		if (*str) ++str;
	}
}

static void nsvg__parseAttribs(NSVGparser* p, const char** attr)
{
	int i;
	for (i = 0; attr[i]; i += 2)
	{
		if (strcmp(attr[i], "style") == 0)
			nsvg__parseStyle(p, attr[i + 1]);
		else
			nsvg__parseAttr(p, attr[i], attr[i + 1]);
	}
}

static int nsvg__getArgsPerElement(char cmd)
{
	switch (cmd) {
		case 'v':
		case 'V':
		case 'h':
		case 'H':
			return 1;
		case 'm':
		case 'M':
		case 'l':
		case 'L':
		case 't':
		case 'T':
			return 2;
		case 'q':
		case 'Q':
		case 's':
		case 'S':
			return 4;
		case 'c':
		case 'C':
			return 6;
		case 'a':
		case 'A':
			return 7;
		case 'z':
		case 'Z':
			return 0;
	}
	return -1;
}

static void nsvg__pathMoveTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
	if (rel) {
		*cpx += args[0];
		*cpy += args[1];
	} else {
		*cpx = args[0];
		*cpy = args[1];
	}
	nsvg__moveTo(p, *cpx, *cpy);
}

static void nsvg__pathLineTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
	if (rel) {
		*cpx += args[0];
		*cpy += args[1];
	} else {
		*cpx = args[0];
		*cpy = args[1];
	}
	nsvg__lineTo(p, *cpx, *cpy);
}

static void nsvg__pathHLineTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
	if (rel)
		*cpx += args[0];
	else
		*cpx = args[0];
	nsvg__lineTo(p, *cpx, *cpy);
}

static void nsvg__pathVLineTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
	if (rel)
		*cpy += args[0];
	else
		*cpy = args[0];
	nsvg__lineTo(p, *cpx, *cpy);
}

static void nsvg__pathCubicBezTo(NSVGparser* p, float* cpx, float* cpy,
								 float* cpx2, float* cpy2, float* args, int rel)
{
	float x2, y2, cx1, cy1, cx2, cy2;

	if (rel) {
		cx1 = *cpx + args[0];
		cy1 = *cpy + args[1];
		cx2 = *cpx + args[2];
		cy2 = *cpy + args[3];
		x2 = *cpx + args[4];
		y2 = *cpy + args[5];
	} else {
		cx1 = args[0];
		cy1 = args[1];
		cx2 = args[2];
		cy2 = args[3];
		x2 = args[4];
		y2 = args[5];
	}

	nsvg__cubicBezTo(p, cx1,cy1, cx2,cy2, x2,y2);

	*cpx2 = cx2;
	*cpy2 = cy2;
	*cpx = x2;
	*cpy = y2;
}

static void nsvg__pathCubicBezShortTo(NSVGparser* p, float* cpx, float* cpy,
									  float* cpx2, float* cpy2, float* args, int rel)
{
	float x1, y1, x2, y2, cx1, cy1, cx2, cy2;

	x1 = *cpx;
	y1 = *cpy;
	if (rel) {
		cx2 = *cpx + args[0];
		cy2 = *cpy + args[1];
		x2 = *cpx + args[2];
		y2 = *cpy + args[3];
	} else {
		cx2 = args[0];
		cy2 = args[1];
		x2 = args[2];
		y2 = args[3];
	}

	cx1 = 2*x1 - *cpx2;
	cy1 = 2*y1 - *cpy2;

	nsvg__cubicBezTo(p, cx1,cy1, cx2,cy2, x2,y2);

	*cpx2 = cx2;
	*cpy2 = cy2;
	*cpx = x2;
	*cpy = y2;
}

static void nsvg__pathQuadBezTo(NSVGparser* p, float* cpx, float* cpy,
								float* cpx2, float* cpy2, float* args, int rel)
{
	float x1, y1, x2, y2, cx, cy;
	float cx1, cy1, cx2, cy2;

	x1 = *cpx;
	y1 = *cpy;
	if (rel) {
		cx = *cpx + args[0];
		cy = *cpy + args[1];
		x2 = *cpx + args[2];
		y2 = *cpy + args[3];
	} else {
		cx = args[0];
		cy = args[1];
		x2 = args[2];
		y2 = args[3];
	}

	/* Convert to cubic bezier */
	cx1 = x1 + 2.0f/3.0f*(cx - x1);
	cy1 = y1 + 2.0f/3.0f*(cy - y1);
	cx2 = x2 + 2.0f/3.0f*(cx - x2);
	cy2 = y2 + 2.0f/3.0f*(cy - y2);

	nsvg__cubicBezTo(p, cx1,cy1, cx2,cy2, x2,y2);

	*cpx2 = cx;
	*cpy2 = cy;
	*cpx = x2;
	*cpy = y2;
}

static void nsvg__pathQuadBezShortTo(NSVGparser* p, float* cpx, float* cpy,
									 float* cpx2, float* cpy2, float* args, int rel)
{
	float x1, y1, x2, y2, cx, cy;
	float cx1, cy1, cx2, cy2;

	x1 = *cpx;
	y1 = *cpy;
	if (rel) {
		x2 = *cpx + args[0];
		y2 = *cpy + args[1];
	} else {
		x2 = args[0];
		y2 = args[1];
	}

	cx = 2*x1 - *cpx2;
	cy = 2*y1 - *cpy2;

	/* Convert to cubix bezier */
	cx1 = x1 + 2.0f/3.0f*(cx - x1);
	cy1 = y1 + 2.0f/3.0f*(cy - y1);
	cx2 = x2 + 2.0f/3.0f*(cx - x2);
	cy2 = y2 + 2.0f/3.0f*(cy - y2);

	nsvg__cubicBezTo(p, cx1,cy1, cx2,cy2, x2,y2);

	*cpx2 = cx;
	*cpy2 = cy;
	*cpx = x2;
	*cpy = y2;
}

static float nsvg__sqr(float x) { return x*x; }
static float nsvg__vmag(float x, float y) { return sqrtf(x*x + y*y); }

static float nsvg__vecrat(float ux, float uy, float vx, float vy)
{
	return (ux*vx + uy*vy) / (nsvg__vmag(ux,uy) * nsvg__vmag(vx,vy));
}

static float nsvg__vecang(float ux, float uy, float vx, float vy)
{
	float r = nsvg__vecrat(ux,uy, vx,vy);
	if (r < -1.0f) r = -1.0f;
	if (r > 1.0f) r = 1.0f;
	return ((ux*vy < uy*vx) ? -1.0f : 1.0f) * acosf(r);
}

static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args, int rel)
{
	/* Ported from canvg (https://code.google.com/p/canvg/) */
	float rx, ry, rotx;
	float x1, y1, x2, y2, cx, cy, dx, dy, d;
	float x1p, y1p, cxp, cyp, s, sa, sb;
	float ux, uy, vx, vy, a1, da;
	float x, y, tanx, tany, a, px = 0, py = 0, ptanx = 0, ptany = 0, t[6];
	float sinrx, cosrx;
	int fa, fs;
	int i, ndivs;
	float hda, kappa;

	rx = fabsf(args[0]);				/* y radius */
	ry = fabsf(args[1]);				/* x radius */
	rotx = args[2] / 180.0f * NSVG_PI;		/* x rotation angle */
	fa = fabsf(args[3]) > 1e-6 ? 1 : 0;	/* Large arc */
	fs = fabsf(args[4]) > 1e-6 ? 1 : 0;	/* Sweep direction */
	x1 = *cpx;							/* start point */
	y1 = *cpy;
	if (rel) {							/* end point */
		x2 = *cpx + args[5];
		y2 = *cpy + args[6];
	} else {
		x2 = args[5];
		y2 = args[6];
	}

	dx = x1 - x2;
	dy = y1 - y2;
	d = sqrtf(dx*dx + dy*dy);
	if (d < 1e-6f || rx < 1e-6f || ry < 1e-6f) {
		/* The arc degenerates to a line */
		nsvg__lineTo(p, x2, y2);
		*cpx = x2;
		*cpy = y2;
		return;
	}

	sinrx = sinf(rotx);
	cosrx = cosf(rotx);

	/* Convert to center point parameterization. */
	/* http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes */
	/* 1) Compute x1', y1' */
	x1p = cosrx * dx / 2.0f + sinrx * dy / 2.0f;
	y1p = -sinrx * dx / 2.0f + cosrx * dy / 2.0f;
	d = nsvg__sqr(x1p)/nsvg__sqr(rx) + nsvg__sqr(y1p)/nsvg__sqr(ry);
	if (d > 1) {
		d = sqrtf(d);
		rx *= d;
		ry *= d;
	}
	/* 2) Compute cx', cy' */
	s = 0.0f;
	sa = nsvg__sqr(rx)*nsvg__sqr(ry) - nsvg__sqr(rx)*nsvg__sqr(y1p) - nsvg__sqr(ry)*nsvg__sqr(x1p);
	sb = nsvg__sqr(rx)*nsvg__sqr(y1p) + nsvg__sqr(ry)*nsvg__sqr(x1p);
	if (sa < 0.0f) sa = 0.0f;
	if (sb > 0.0f)
		s = sqrtf(sa / sb);
	if (fa == fs)
		s = -s;
	cxp = s * rx * y1p / ry;
	cyp = s * -ry * x1p / rx;

	/* 3) Compute cx,cy from cx',cy' */
	cx = (x1 + x2)/2.0f + cosrx*cxp - sinrx*cyp;
	cy = (y1 + y2)/2.0f + sinrx*cxp + cosrx*cyp;

	/* 4) Calculate theta1, and delta theta. */
	ux = (x1p - cxp) / rx;
	uy = (y1p - cyp) / ry;
	vx = (-x1p - cxp) / rx;
	vy = (-y1p - cyp) / ry;
	a1 = nsvg__vecang(1.0f,0.0f, ux,uy);	/* Initial angle */
	da = nsvg__vecang(ux,uy, vx,vy);		/* Delta angle */

/*	if (vecrat(ux,uy,vx,vy) <= -1.0f) da = NSVG_PI; */
/*	if (vecrat(ux,uy,vx,vy) >= 1.0f) da = 0; */

	if (fs == 0 && da > 0)
		da -= 2 * NSVG_PI;
	else if (fs == 1 && da < 0)
		da += 2 * NSVG_PI;

	/* Approximate the arc using cubic spline segments. */
	t[0] = cosrx; t[1] = sinrx;
	t[2] = -sinrx; t[3] = cosrx;
	t[4] = cx; t[5] = cy;

	/* Split arc into max 90 degree segments. */
	/* The loop assumes an iteration per end point (including start and end), this +1. */
	ndivs = (int)(fabsf(da) / (NSVG_PI*0.5f) + 1.0f);
	hda = (da / (float)ndivs) / 2.0f;
	/* Fix for ticket #179: division by 0: avoid cotangens around 0 (infinite) */
	if ((hda < 1e-3f) && (hda > -1e-3f))
		hda *= 0.5f;
	else
		hda = (1.0f - cosf(hda)) / sinf(hda);
	kappa = fabsf(4.0f / 3.0f * hda);
	if (da < 0.0f)
		kappa = -kappa;

	for (i = 0; i <= ndivs; i++) {
		a = a1 + da * ((float)i/(float)ndivs);
		dx = cosf(a);
		dy = sinf(a);
		nsvg__xformPoint(&x, &y, dx*rx, dy*ry, t); /* position */
		nsvg__xformVec(&tanx, &tany, -dy*rx * kappa, dx*ry * kappa, t); /* tangent */
		if (i > 0)
			nsvg__cubicBezTo(p, px+ptanx,py+ptany, x-tanx, y-tany, x, y);
		px = x;
		py = y;
		ptanx = tanx;
		ptany = tany;
	}

	*cpx = x2;
	*cpy = y2;
}

static void nsvg__parsePath(NSVGparser* p, const char** attr)
{
	const char* s = NULL;
	char cmd = '\0';
	float args[10];
	int nargs;
	int rargs = 0;
	char initPoint;
	float cpx, cpy, cpx2, cpy2;
	const char* tmp[4];
	char closedFlag;
	int i;
	char item[64];

	for (i = 0; attr[i]; i += 2) {
		if (strcmp(attr[i], "d") == 0) {
			s = attr[i + 1];
		} else {
			tmp[0] = attr[i];
			tmp[1] = attr[i + 1];
			tmp[2] = 0;
			tmp[3] = 0;
			nsvg__parseAttribs(p, tmp);
		}
	}

	if (s) {
		nsvg__resetPath(p);
		cpx = 0; cpy = 0;
		cpx2 = 0; cpy2 = 0;
		initPoint = 0;
		closedFlag = 0;
		nargs = 0;

		while (*s) {
			item[0] = '\0';
			if ((cmd == 'A' || cmd == 'a') && (nargs == 3 || nargs == 4))
				s = nsvg__getNextPathItemWhenArcFlag(s, item);
			if (!*item)
				s = nsvg__getNextPathItem(s, item);
			if (!*item) break;
			if (cmd != '\0' && nsvg__isCoordinate(item)) {
				if (nargs < 10)
					args[nargs++] = (float)nsvg__atof(item);
				if (nargs >= rargs) {
					switch (cmd) {
						case 'm':
						case 'M':
							nsvg__pathMoveTo(p, &cpx, &cpy, args, cmd == 'm' ? 1 : 0);
							/* Moveto can be followed by multiple coordinate pairs, */
							/* which should be treated as linetos. */
							cmd = (cmd == 'm') ? 'l' : 'L';
							rargs = nsvg__getArgsPerElement(cmd);
							cpx2 = cpx; cpy2 = cpy;
							initPoint = 1;
							break;
						case 'l':
						case 'L':
							nsvg__pathLineTo(p, &cpx, &cpy, args, cmd == 'l' ? 1 : 0);
							cpx2 = cpx; cpy2 = cpy;
							break;
						case 'H':
						case 'h':
							nsvg__pathHLineTo(p, &cpx, &cpy, args, cmd == 'h' ? 1 : 0);
							cpx2 = cpx; cpy2 = cpy;
							break;
						case 'V':
						case 'v':
							nsvg__pathVLineTo(p, &cpx, &cpy, args, cmd == 'v' ? 1 : 0);
							cpx2 = cpx; cpy2 = cpy;
							break;
						case 'C':
						case 'c':
							nsvg__pathCubicBezTo(p, &cpx, &cpy, &cpx2, &cpy2, args, cmd == 'c' ? 1 : 0);
							break;
						case 'S':
						case 's':
							nsvg__pathCubicBezShortTo(p, &cpx, &cpy, &cpx2, &cpy2, args, cmd == 's' ? 1 : 0);
							break;
						case 'Q':
						case 'q':
							nsvg__pathQuadBezTo(p, &cpx, &cpy, &cpx2, &cpy2, args, cmd == 'q' ? 1 : 0);
							break;
						case 'T':
						case 't':
							nsvg__pathQuadBezShortTo(p, &cpx, &cpy, &cpx2, &cpy2, args, cmd == 't' ? 1 : 0);
							break;
						case 'A':
						case 'a':
							nsvg__pathArcTo(p, &cpx, &cpy, args, cmd == 'a' ? 1 : 0);
							cpx2 = cpx; cpy2 = cpy;
							break;
						default:
							if (nargs >= 2) {
								cpx = args[nargs-2];
								cpy = args[nargs-1];
								cpx2 = cpx; cpy2 = cpy;
							}
							break;
					}
					nargs = 0;
				}
			} else {
				cmd = item[0];
				if (cmd == 'M' || cmd == 'm') {
					/* Commit path. */
					if (p->npts > 0)
						nsvg__addPath(p, closedFlag);
					/* Start new subpath. */
					nsvg__resetPath(p);
					closedFlag = 0;
					nargs = 0;
				} else if (initPoint == 0) {
					/* Do not allow other commands until initial point has been set (moveTo called once). */
					cmd = '\0';
				}
				if (cmd == 'Z' || cmd == 'z') {
					closedFlag = 1;
					/* Commit path. */
					if (p->npts > 0) {
						/* Move current point to first point */
						cpx = p->pts[0];
						cpy = p->pts[1];
						cpx2 = cpx; cpy2 = cpy;
						nsvg__addPath(p, closedFlag);
					}
					/* Start new subpath. */
					nsvg__resetPath(p);
					nsvg__moveTo(p, cpx, cpy);
					closedFlag = 0;
					nargs = 0;
				}
				rargs = nsvg__getArgsPerElement(cmd);
				if (rargs == -1) {
					/* Command not recognized */
					cmd = '\0';
					rargs = 0;
				}
			}
		}
		/* Commit path. */
		if (p->npts)
			nsvg__addPath(p, closedFlag);
	}

	nsvg__addShape(p);
}

static void nsvg__parseRect(NSVGparser* p, const char** attr)
{
	float x = 0.0f;
	float y = 0.0f;
	float w = 0.0f;
	float h = 0.0f;
	float rx = -1.0f; /* marks not set */
	float ry = -1.0f;
	int i;

	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "x") == 0) x = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigX(p), nsvg__actualWidth(p));
			if (strcmp(attr[i], "y") == 0) y = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigY(p), nsvg__actualHeight(p));
			if (strcmp(attr[i], "width") == 0) w = nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualWidth(p));
			if (strcmp(attr[i], "height") == 0) h = nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualHeight(p));
			if (strcmp(attr[i], "rx") == 0) rx = fabsf(nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualWidth(p)));
			if (strcmp(attr[i], "ry") == 0) ry = fabsf(nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualHeight(p)));
		}
	}

	if (rx < 0.0f && ry > 0.0f) rx = ry;
	if (ry < 0.0f && rx > 0.0f) ry = rx;
	if (rx < 0.0f) rx = 0.0f;
	if (ry < 0.0f) ry = 0.0f;
	if (rx > w/2.0f) rx = w/2.0f;
	if (ry > h/2.0f) ry = h/2.0f;

	if (w != 0.0f && h != 0.0f) {
		nsvg__resetPath(p);

		if (rx < 0.00001f || ry < 0.0001f) {
			nsvg__moveTo(p, x, y);
			nsvg__lineTo(p, x+w, y);
			nsvg__lineTo(p, x+w, y+h);
			nsvg__lineTo(p, x, y+h);
		} else {
			/* Rounded rectangle */
			nsvg__moveTo(p, x+rx, y);
			nsvg__lineTo(p, x+w-rx, y);
			nsvg__cubicBezTo(p, x+w-rx*(1-NSVG_KAPPA90), y, x+w, y+ry*(1-NSVG_KAPPA90), x+w, y+ry);
			nsvg__lineTo(p, x+w, y+h-ry);
			nsvg__cubicBezTo(p, x+w, y+h-ry*(1-NSVG_KAPPA90), x+w-rx*(1-NSVG_KAPPA90), y+h, x+w-rx, y+h);
			nsvg__lineTo(p, x+rx, y+h);
			nsvg__cubicBezTo(p, x+rx*(1-NSVG_KAPPA90), y+h, x, y+h-ry*(1-NSVG_KAPPA90), x, y+h-ry);
			nsvg__lineTo(p, x, y+ry);
			nsvg__cubicBezTo(p, x, y+ry*(1-NSVG_KAPPA90), x+rx*(1-NSVG_KAPPA90), y, x+rx, y);
		}

		nsvg__addPath(p, 1);

		nsvg__addShape(p);
	}
}

static void nsvg__parseCircle(NSVGparser* p, const char** attr)
{
	float cx = 0.0f;
	float cy = 0.0f;
	float r = 0.0f;
	int i;

	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "cx") == 0) cx = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigX(p), nsvg__actualWidth(p));
			if (strcmp(attr[i], "cy") == 0) cy = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigY(p), nsvg__actualHeight(p));
			if (strcmp(attr[i], "r") == 0) r = fabsf(nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualLength(p)));
		}
	}

	if (r > 0.0f) {
		nsvg__resetPath(p);

		nsvg__moveTo(p, cx+r, cy);
		nsvg__cubicBezTo(p, cx+r, cy+r*NSVG_KAPPA90, cx+r*NSVG_KAPPA90, cy+r, cx, cy+r);
		nsvg__cubicBezTo(p, cx-r*NSVG_KAPPA90, cy+r, cx-r, cy+r*NSVG_KAPPA90, cx-r, cy);
		nsvg__cubicBezTo(p, cx-r, cy-r*NSVG_KAPPA90, cx-r*NSVG_KAPPA90, cy-r, cx, cy-r);
		nsvg__cubicBezTo(p, cx+r*NSVG_KAPPA90, cy-r, cx+r, cy-r*NSVG_KAPPA90, cx+r, cy);

		nsvg__addPath(p, 1);

		nsvg__addShape(p);
	}
}

static void nsvg__parseEllipse(NSVGparser* p, const char** attr)
{
	float cx = 0.0f;
	float cy = 0.0f;
	float rx = 0.0f;
	float ry = 0.0f;
	int i;

	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "cx") == 0) cx = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigX(p), nsvg__actualWidth(p));
			if (strcmp(attr[i], "cy") == 0) cy = nsvg__parseCoordinate(p, attr[i+1], nsvg__actualOrigY(p), nsvg__actualHeight(p));
			if (strcmp(attr[i], "rx") == 0) rx = fabsf(nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualWidth(p)));
			if (strcmp(attr[i], "ry") == 0) ry = fabsf(nsvg__parseCoordinate(p, attr[i+1], 0.0f, nsvg__actualHeight(p)));
		}
	}

	if (rx > 0.0f && ry > 0.0f) {

		nsvg__resetPath(p);

		nsvg__moveTo(p, cx+rx, cy);
		nsvg__cubicBezTo(p, cx+rx, cy+ry*NSVG_KAPPA90, cx+rx*NSVG_KAPPA90, cy+ry, cx, cy+ry);
		nsvg__cubicBezTo(p, cx-rx*NSVG_KAPPA90, cy+ry, cx-rx, cy+ry*NSVG_KAPPA90, cx-rx, cy);
		nsvg__cubicBezTo(p, cx-rx, cy-ry*NSVG_KAPPA90, cx-rx*NSVG_KAPPA90, cy-ry, cx, cy-ry);
		nsvg__cubicBezTo(p, cx+rx*NSVG_KAPPA90, cy-ry, cx+rx, cy-ry*NSVG_KAPPA90, cx+rx, cy);

		nsvg__addPath(p, 1);

		nsvg__addShape(p);
	}
}

static void nsvg__parseLine(NSVGparser* p, const char** attr)
{
	float x1 = 0.0;
	float y1 = 0.0;
	float x2 = 0.0;
	float y2 = 0.0;
	int i;

	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "x1") == 0) x1 = nsvg__parseCoordinate(p, attr[i + 1], nsvg__actualOrigX(p), nsvg__actualWidth(p));
			if (strcmp(attr[i], "y1") == 0) y1 = nsvg__parseCoordinate(p, attr[i + 1], nsvg__actualOrigY(p), nsvg__actualHeight(p));
			if (strcmp(attr[i], "x2") == 0) x2 = nsvg__parseCoordinate(p, attr[i + 1], nsvg__actualOrigX(p), nsvg__actualWidth(p));
			if (strcmp(attr[i], "y2") == 0) y2 = nsvg__parseCoordinate(p, attr[i + 1], nsvg__actualOrigY(p), nsvg__actualHeight(p));
		}
	}

	nsvg__resetPath(p);

	nsvg__moveTo(p, x1, y1);
	nsvg__lineTo(p, x2, y2);

	nsvg__addPath(p, 0);

	nsvg__addShape(p);
}

static void nsvg__parsePoly(NSVGparser* p, const char** attr, int closeFlag)
{
	int i;
	const char* s;
	float args[2];
	int nargs, npts = 0;
	char item[64];

	nsvg__resetPath(p);

	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "points") == 0) {
				s = attr[i + 1];
				nargs = 0;
				while (*s) {
					s = nsvg__getNextPathItem(s, item);
					args[nargs++] = (float)nsvg__atof(item);
					if (nargs >= 2) {
						if (npts == 0)
							nsvg__moveTo(p, args[0], args[1]);
						else
							nsvg__lineTo(p, args[0], args[1]);
						nargs = 0;
						npts++;
					}
				}
			}
		}
	}

	nsvg__addPath(p, (char)closeFlag);

	nsvg__addShape(p);
}

static void nsvg__parseSVG(NSVGparser* p, const char** attr)
{
	int i;
	for (i = 0; attr[i]; i += 2) {
		if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "width") == 0) {
				p->image->width = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
			} else if (strcmp(attr[i], "height") == 0) {
				p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
			} else if (strcmp(attr[i], "viewBox") == 0) {
				sscanf(attr[i + 1], "%f%*[%%, \t]%f%*[%%, \t]%f%*[%%, \t]%f", &p->viewMinx, &p->viewMiny, &p->viewWidth, &p->viewHeight);
			} else if (strcmp(attr[i], "preserveAspectRatio") == 0) {
				if (strstr(attr[i + 1], "none") != 0) {
					/* No uniform scaling */
					p->alignType = NSVG_ALIGN_NONE;
				} else {
					/* Parse X align */
					if (strstr(attr[i + 1], "xMin") != 0)
						p->alignX = NSVG_ALIGN_MIN;
					else if (strstr(attr[i + 1], "xMid") != 0)
						p->alignX = NSVG_ALIGN_MID;
					else if (strstr(attr[i + 1], "xMax") != 0)
						p->alignX = NSVG_ALIGN_MAX;
					/* Parse X align */
					if (strstr(attr[i + 1], "yMin") != 0)
						p->alignY = NSVG_ALIGN_MIN;
					else if (strstr(attr[i + 1], "yMid") != 0)
						p->alignY = NSVG_ALIGN_MID;
					else if (strstr(attr[i + 1], "yMax") != 0)
						p->alignY = NSVG_ALIGN_MAX;
					/* Parse meet/slice */
					p->alignType = NSVG_ALIGN_MEET;
					if (strstr(attr[i + 1], "slice") != 0)
						p->alignType = NSVG_ALIGN_SLICE;
				}
			}
		}
	}
}

static void nsvg__parseGradient(NSVGparser* p, const char** attr, signed char type)
{
	int i;
	NSVGgradientData* grad = (NSVGgradientData*)NANOSVG_malloc(sizeof(NSVGgradientData));
	if (grad == NULL) return;
	memset(grad, 0, sizeof(NSVGgradientData));
	grad->units = NSVG_OBJECT_SPACE;
	grad->type = type;
	if (grad->type == NSVG_PAINT_LINEAR_GRADIENT) {
		grad->linear.x1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT);
		grad->linear.y1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT);
		grad->linear.x2 = nsvg__coord(100.0f, NSVG_UNITS_PERCENT);
		grad->linear.y2 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT);
	} else if (grad->type == NSVG_PAINT_RADIAL_GRADIENT) {
		grad->radial.cx = nsvg__coord(50.0f, NSVG_UNITS_PERCENT);
		grad->radial.cy = nsvg__coord(50.0f, NSVG_UNITS_PERCENT);
		grad->radial.r = nsvg__coord(50.0f, NSVG_UNITS_PERCENT);
	}

	nsvg__xformIdentity(grad->xform);

	for (i = 0; attr[i]; i += 2) {
		if (strcmp(attr[i], "id") == 0) {
			strncpy(grad->id, attr[i+1], 63);
			grad->id[63] = '\0';
		} else if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
			if (strcmp(attr[i], "gradientUnits") == 0) {
				if (strcmp(attr[i+1], "objectBoundingBox") == 0)
					grad->units = NSVG_OBJECT_SPACE;
				else
					grad->units = NSVG_USER_SPACE;
			} else if (strcmp(attr[i], "gradientTransform") == 0) {
				nsvg__parseTransform(grad->xform, attr[i + 1]);
			} else if (strcmp(attr[i], "cx") == 0) {
				grad->radial.cx = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "cy") == 0) {
				grad->radial.cy = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "r") == 0) {
				grad->radial.r = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "fx") == 0) {
				grad->radial.fx = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "fy") == 0) {
				grad->radial.fy = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "x1") == 0) {
				grad->linear.x1 = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "y1") == 0) {
				grad->linear.y1 = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "x2") == 0) {
				grad->linear.x2 = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "y2") == 0) {
				grad->linear.y2 = nsvg__parseCoordinateRaw(attr[i + 1]);
			} else if (strcmp(attr[i], "spreadMethod") == 0) {
				if (strcmp(attr[i+1], "pad") == 0)
					grad->spread = NSVG_SPREAD_PAD;
				else if (strcmp(attr[i+1], "reflect") == 0)
					grad->spread = NSVG_SPREAD_REFLECT;
				else if (strcmp(attr[i+1], "repeat") == 0)
					grad->spread = NSVG_SPREAD_REPEAT;
			} else if (strcmp(attr[i], "xlink:href") == 0) {
				const char *href = attr[i+1];
				strncpy(grad->ref, href+1, 62);
				grad->ref[62] = '\0';
			}
		}
	}

	grad->next = p->gradients;
	p->gradients = grad;
}

static void nsvg__parseGradientStop(NSVGparser* p, const char** attr)
{
	NSVGattrib* curAttr = nsvg__getAttr(p);
	NSVGgradientData* grad;
	NSVGgradientStop* stop;
	int i, idx;

	curAttr->stopOffset = 0;
	curAttr->stopColor = 0;
	curAttr->stopOpacity = 1.0f;

	for (i = 0; attr[i]; i += 2) {
		nsvg__parseAttr(p, attr[i], attr[i + 1]);
	}

	/* Add stop to the last gradient. */
	grad = p->gradients;
	if (grad == NULL) return;

	grad->nstops++;
	grad->stops = (NSVGgradientStop*)NANOSVG_realloc(grad->stops, sizeof(NSVGgradientStop)*grad->nstops);
	if (grad->stops == NULL) return;

	/* Insert */
	idx = grad->nstops-1;
	for (i = 0; i < grad->nstops-1; i++) {
		if (curAttr->stopOffset < grad->stops[i].offset) {
			idx = i;
			break;
		}
	}
	if (idx != grad->nstops-1) {
		for (i = grad->nstops-1; i > idx; i--)
			grad->stops[i] = grad->stops[i-1];
	}

	stop = &grad->stops[idx];
	stop->color = curAttr->stopColor;
	stop->color |= (unsigned int)(curAttr->stopOpacity*255) << 24;
	stop->offset = curAttr->stopOffset;
}

static void nsvg__startElement(void* ud, const char* el, const char** attr)
{
	NSVGparser* p = (NSVGparser*)ud;

	if (p->defsFlag) {
		/* Skip everything but gradients in defs */
		if (strcmp(el, "linearGradient") == 0) {
			nsvg__parseGradient(p, attr, NSVG_PAINT_LINEAR_GRADIENT);
		} else if (strcmp(el, "radialGradient") == 0) {
			nsvg__parseGradient(p, attr, NSVG_PAINT_RADIAL_GRADIENT);
		} else if (strcmp(el, "stop") == 0) {
			nsvg__parseGradientStop(p, attr);
		}
		return;
	}

	if (strcmp(el, "g") == 0) {
		nsvg__pushAttr(p);
		nsvg__parseAttribs(p, attr);
	} else if (strcmp(el, "path") == 0) {
		if (p->pathFlag)	/* Do not allow nested paths. */
			return;
		nsvg__pushAttr(p);
		nsvg__parsePath(p, attr);
		nsvg__popAttr(p);
	} else if (strcmp(el, "rect") == 0) {
		nsvg__pushAttr(p);
		nsvg__parseRect(p, attr);
		nsvg__popAttr(p);
	} else if (strcmp(el, "circle") == 0) {
		nsvg__pushAttr(p);
		nsvg__parseCircle(p, attr);
		nsvg__popAttr(p);
	} else if (strcmp(el, "ellipse") == 0) {
		nsvg__pushAttr(p);
		nsvg__parseEllipse(p, attr);
		nsvg__popAttr(p);
	} else if (strcmp(el, "line") == 0)  {
		nsvg__pushAttr(p);
		nsvg__parseLine(p, attr);
		nsvg__popAttr(p);
	} else if (strcmp(el, "polyline") == 0)  {
		nsvg__pushAttr(p);
		nsvg__parsePoly(p, attr, 0);
		nsvg__popAttr(p);
	} else if (strcmp(el, "polygon") == 0)  {
		nsvg__pushAttr(p);
		nsvg__parsePoly(p, attr, 1);
		nsvg__popAttr(p);
	} else  if (strcmp(el, "linearGradient") == 0) {
		nsvg__parseGradient(p, attr, NSVG_PAINT_LINEAR_GRADIENT);
	} else if (strcmp(el, "radialGradient") == 0) {
		nsvg__parseGradient(p, attr, NSVG_PAINT_RADIAL_GRADIENT);
	} else if (strcmp(el, "stop") == 0) {
		nsvg__parseGradientStop(p, attr);
	} else if (strcmp(el, "defs") == 0) {
		p->defsFlag = 1;
	} else if (strcmp(el, "svg") == 0) {
		nsvg__parseSVG(p, attr);
	} else if (strcmp(el, "style") == 0) {
		p->styleFlag = 1;
	}
}

static void nsvg__endElement(void* ud, const char* el)
{
	NSVGparser* p = (NSVGparser*)ud;

	if (strcmp(el, "g") == 0) {
		nsvg__popAttr(p);
	} else if (strcmp(el, "path") == 0) {
		p->pathFlag = 0;
	} else if (strcmp(el, "defs") == 0) {
		p->defsFlag = 0;
	} else if (strcmp(el, "style") == 0) {
		p->styleFlag = 0;
	}
}

static char *nsvg__strndup(const char *s, size_t n)
{
	char *result;
	size_t len = strlen(s);

	if (n < len)
		len = n;

	result = (char*)NANOSVG_malloc(len+1);
	if (!result)
		return 0;

	result[len] = '\0';
	return (char *)memcpy(result, s, len);
}

static void nsvg__content(void* ud, const char* s)
{
	NSVGparser* p = (NSVGparser*)ud;
	if (p->styleFlag) {

		int state = 0;
		const char* start = NULL;
		while (*s) {
			char c = *s;
			if (nsvg__isspace(c) || c == '{') {
				if (state == 1) {
					NSVGstyles* next = p->styles;

					p->styles = (NSVGstyles*)NANOSVG_malloc(sizeof(NSVGstyles));
					p->styles->next = next;
					p->styles->name = nsvg__strndup(start, (size_t)(s - start));
					start = s + 1;
					state = 2;
				}
			} else if (state == 2 && c == '}') {
				p->styles->description = nsvg__strndup(start, (size_t)(s - start));
				state = 0;
			}
			else if (state == 0) {
				start = s;
				state = 1;
			}
			s++;
		/*
			if (*s == '{' && state == NSVG_XML_CONTENT) {
				// Start of a tag
				*s++ = '\0';
				nsvg__parseContent(mark, contentCb, ud);
				mark = s;
				state = NSVG_XML_TAG;
			}
			else if (*s == '>' && state == NSVG_XML_TAG) {
				// Start of a content or new tag.
				*s++ = '\0';
				nsvg__parseElement(mark, startelCb, endelCb, ud);
				mark = s;
				state = NSVG_XML_CONTENT;
			}
			else {
				s++;
			}
		*/
		}

	}
}

static void nsvg__imageBounds(NSVGparser* p, float* bounds)
{
	NSVGshape* shape;
	shape = p->image->shapes;
	if (shape == NULL) {
		bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0.0;
		return;
	}
	bounds[0] = shape->bounds[0];
	bounds[1] = shape->bounds[1];
	bounds[2] = shape->bounds[2];
	bounds[3] = shape->bounds[3];
	for (shape = shape->next; shape != NULL; shape = shape->next) {
		bounds[0] = nsvg__minf(bounds[0], shape->bounds[0]);
		bounds[1] = nsvg__minf(bounds[1], shape->bounds[1]);
		bounds[2] = nsvg__maxf(bounds[2], shape->bounds[2]);
		bounds[3] = nsvg__maxf(bounds[3], shape->bounds[3]);
	}
}

static float nsvg__viewAlign(float content, float container, int type)
{
	if (type == NSVG_ALIGN_MIN)
		return 0;
	else if (type == NSVG_ALIGN_MAX)
		return container - content;
	/* mid */
	return (container - content) * 0.5f;
}

static void nsvg__scaleGradient(NSVGgradient* grad, float tx, float ty, float sx, float sy)
{
	float t[6];
	nsvg__xformSetTranslation(t, tx, ty);
	nsvg__xformMultiply (grad->xform, t);

	nsvg__xformSetScale(t, sx, sy);
	nsvg__xformMultiply (grad->xform, t);
}

static void nsvg__scaleToViewbox(NSVGparser* p, const char* units)
{
	NSVGshape* shape;
	NSVGpath* path;
	float tx, ty, sx, sy, us, bounds[4], t[6], avgs;
	int i;
	float* pt;

	/* Guess image size if not set completely. */
	nsvg__imageBounds(p, bounds);

	if (p->viewWidth == 0) {
		if (p->image->width > 0) {
			p->viewWidth = p->image->width;
		} else {
			p->viewMinx = bounds[0];
			p->viewWidth = bounds[2] - bounds[0];
		}
	}
	if (p->viewHeight == 0) {
		if (p->image->height > 0) {
			p->viewHeight = p->image->height;
		} else {
			p->viewMiny = bounds[1];
			p->viewHeight = bounds[3] - bounds[1];
		}
	}
	if (p->image->width == 0)
		p->image->width = p->viewWidth;
	if (p->image->height == 0)
		p->image->height = p->viewHeight;

	tx = -p->viewMinx;
	ty = -p->viewMiny;
	sx = p->viewWidth > 0 ? p->image->width / p->viewWidth : 0;
	sy = p->viewHeight > 0 ? p->image->height / p->viewHeight : 0;
	/* Unit scaling */
	us = 1.0f / nsvg__convertToPixels(p, nsvg__coord(1.0f, nsvg__parseUnits(units)), 0.0f, 1.0f);

	/* Fix aspect ratio */
	if (p->alignType == NSVG_ALIGN_MEET) {
		/* fit whole image into viewbox */
		sx = sy = nsvg__minf(sx, sy);
		tx += nsvg__viewAlign(p->viewWidth*sx, p->image->width, p->alignX) / sx;
		ty += nsvg__viewAlign(p->viewHeight*sy, p->image->height, p->alignY) / sy;
	} else if (p->alignType == NSVG_ALIGN_SLICE) {
		/* fill whole viewbox with image */
		sx = sy = nsvg__maxf(sx, sy);
		tx += nsvg__viewAlign(p->viewWidth*sx, p->image->width, p->alignX) / sx;
		ty += nsvg__viewAlign(p->viewHeight*sy, p->image->height, p->alignY) / sy;
	}

	/* Transform */
	sx *= us;
	sy *= us;
	avgs = (sx+sy) / 2.0f;
	for (shape = p->image->shapes; shape != NULL; shape = shape->next) {
		shape->bounds[0] = (shape->bounds[0] + tx) * sx;
		shape->bounds[1] = (shape->bounds[1] + ty) * sy;
		shape->bounds[2] = (shape->bounds[2] + tx) * sx;
		shape->bounds[3] = (shape->bounds[3] + ty) * sy;
		for (path = shape->paths; path != NULL; path = path->next) {
			path->bounds[0] = (path->bounds[0] + tx) * sx;
			path->bounds[1] = (path->bounds[1] + ty) * sy;
			path->bounds[2] = (path->bounds[2] + tx) * sx;
			path->bounds[3] = (path->bounds[3] + ty) * sy;
			for (i =0; i < path->npts; i++) {
				pt = &path->pts[i*2];
				pt[0] = (pt[0] + tx) * sx;
				pt[1] = (pt[1] + ty) * sy;
			}
		}

		if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT || shape->fill.type == NSVG_PAINT_RADIAL_GRADIENT) {
			nsvg__scaleGradient(shape->fill.gradient, tx,ty, sx,sy);
			memcpy(t, shape->fill.gradient->xform, sizeof(float)*6);
			nsvg__xformInverse(shape->fill.gradient->xform, t);
		}
		if (shape->stroke.type == NSVG_PAINT_LINEAR_GRADIENT || shape->stroke.type == NSVG_PAINT_RADIAL_GRADIENT) {
			nsvg__scaleGradient(shape->stroke.gradient, tx,ty, sx,sy);
			memcpy(t, shape->stroke.gradient->xform, sizeof(float)*6);
			nsvg__xformInverse(shape->stroke.gradient->xform, t);
		}

		shape->strokeWidth *= avgs;
		shape->strokeDashOffset *= avgs;
		for (i = 0; i < shape->strokeDashCount; i++)
			shape->strokeDashArray[i] *= avgs;
	}
}

static void nsvg__createGradients(NSVGparser* p)
{
	NSVGshape* shape;

	for (shape = p->image->shapes; shape != NULL; shape = shape->next) {
		if (shape->fill.type == NSVG_PAINT_UNDEF) {
			if (shape->fillGradient[0] != '\0') {
				float inv[6], localBounds[4];
				nsvg__xformInverse(inv, shape->xform);
				nsvg__getLocalBounds(localBounds, shape, inv);
				shape->fill.gradient = nsvg__createGradient(p, shape->fillGradient, localBounds, shape->xform, &shape->fill.type);
			}
			if (shape->fill.type == NSVG_PAINT_UNDEF) {
				shape->fill.type = NSVG_PAINT_NONE;
			}
		}
		if (shape->stroke.type == NSVG_PAINT_UNDEF) {
			if (shape->strokeGradient[0] != '\0') {
				float inv[6], localBounds[4];
				nsvg__xformInverse(inv, shape->xform);
				nsvg__getLocalBounds(localBounds, shape, inv);
				shape->stroke.gradient = nsvg__createGradient(p, shape->strokeGradient, localBounds, shape->xform, &shape->stroke.type);
			}
			if (shape->stroke.type == NSVG_PAINT_UNDEF) {
				shape->stroke.type = NSVG_PAINT_NONE;
			}
		}
	}
}

NANOSVG_SCOPE
NSVGimage* nsvgParse(char* input, const char* units, float dpi)
{
	NSVGparser* p;
	NSVGimage* ret = 0;

	p = nsvg__createParser();
	if (p == NULL) {
		return NULL;
	}
	p->dpi = dpi;

	nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);

	// Create gradients after all definitions have been parsed
	nsvg__createGradients(p);

	/* Scale to viewBox */
	nsvg__scaleToViewbox(p, units);

	ret = p->image;
	p->image = NULL;

	nsvg__deleteParser(p);

	return ret;
}

NANOSVG_SCOPE
NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
{
	FILE* fp = NULL;
	size_t size;
	char* data = NULL;
	NSVGimage* image = NULL;

	fp = fopen(filename, "rb");
	if (!fp) goto error;
	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	data = (char*)NANOSVG_malloc(size+1);
	if (data == NULL) goto error;
	if (fread(data, 1, size, fp) != size) goto error;
	data[size] = '\0';	/* Must be null terminated. */
	fclose(fp);
	image = nsvgParse(data, units, dpi);
	NANOSVG_free(data);

	return image;

error:
	if (fp) fclose(fp);
	if (data) NANOSVG_free(data);
	if (image) nsvgDelete(image);
	return NULL;
}

NANOSVG_SCOPE
void nsvgDelete(NSVGimage* image)
{
	NSVGshape *snext, *shape;
	if (image == NULL) return;
	shape = image->shapes;
	while (shape != NULL) {
		snext = shape->next;
		nsvg__deletePaths(shape->paths);
		nsvg__deletePaint(&shape->fill);
		nsvg__deletePaint(&shape->stroke);
		NANOSVG_free(shape);
		shape = snext;
	}
	NANOSVG_free(image);
}

#endif

#endif /* NANOSVG_H */

Deleted generic/nanosvgrast.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2013-14 Mikko Mononen [email protected]
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 *
 * The polygon rasterization is heavily based on stb_truetype rasterizer
 * by Sean Barrett - http://nothings.org/
 *
 */

#ifndef NANOSVGRAST_H
#define NANOSVGRAST_H

#include "nanosvg.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef NANOSVG_SCOPE
#define NANOSVG_SCOPE
#endif

#ifndef NANOSVG_malloc
#define NANOSVG_malloc malloc
#endif

#ifndef NANOSVG_realloc
#define NANOSVG_realloc realloc
#endif

#ifndef NANOSVG_free
#define NANOSVG_free free
#endif

typedef struct NSVGrasterizer NSVGrasterizer;

/* Example Usage:
	// Load SVG
	struct SNVGImage* image = nsvgParseFromFile("test.svg.");

	// Create rasterizer (can be used to render multiple images).
	struct NSVGrasterizer* rast = nsvgCreateRasterizer();
	// Allocate memory for image
	unsigned char* img = malloc(w*h*4);
	// Rasterize
	nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4);
*/

/* Allocated rasterizer context. */
NANOSVG_SCOPE NSVGrasterizer* nsvgCreateRasterizer(void);

/* Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
 *   r - pointer to rasterizer context
 *   image - pointer to image to rasterize
 *   tx,ty - image offset (applied after scaling)
 *   scale - image scale
 *   dst - pointer to destination image data, 4 bytes per pixel (RGBA)
 *   w - width of the image to render
 *   h - height of the image to render
 *   stride - number of bytes per scaleline in the destination buffer
 */
NANOSVG_SCOPE void nsvgRasterize(NSVGrasterizer* r,
				   NSVGimage* image, float tx, float ty, float scale,
				   unsigned char* dst, int w, int h, int stride);

/* Deletes rasterizer context. */
NANOSVG_SCOPE void nsvgDeleteRasterizer(NSVGrasterizer*);


#ifdef __cplusplus
}
#endif

#ifdef NANOSVGRAST_IMPLEMENTATION

#include <math.h>
#include <stdlib.h>
#include <string.h>

#define NSVG__SUBSAMPLES	5
#define NSVG__FIXSHIFT		10
#define NSVG__FIX			(1 << NSVG__FIXSHIFT)
#define NSVG__FIXMASK		(NSVG__FIX-1)
#define NSVG__MEMPAGE_SIZE	1024

typedef struct NSVGedge {
	float x0,y0, x1,y1;
	int dir;
	struct NSVGedge* next;
} NSVGedge;

typedef struct NSVGpoint {
	float x, y;
	float dx, dy;
	float len;
	float dmx, dmy;
	unsigned char flags;
} NSVGpoint;

typedef struct NSVGactiveEdge {
	int x,dx;
	float ey;
	int dir;
	struct NSVGactiveEdge *next;
} NSVGactiveEdge;

typedef struct NSVGmemPage {
	unsigned char mem[NSVG__MEMPAGE_SIZE];
	int size;
	struct NSVGmemPage* next;
} NSVGmemPage;

typedef struct NSVGcachedPaint {
	signed char type;
	char spread;
	float xform[6];
	unsigned int colors[256];
} NSVGcachedPaint;

struct NSVGrasterizer
{
	float px, py;

	float tessTol;
	float distTol;

	NSVGedge* edges;
	int nedges;
	int cedges;

	NSVGpoint* points;
	int npoints;
	int cpoints;

	NSVGpoint* points2;
	int npoints2;
	int cpoints2;

	NSVGactiveEdge* freelist;
	NSVGmemPage* pages;
	NSVGmemPage* curpage;

	unsigned char* scanline;
	int cscanline;

	unsigned char* bitmap;
	int width, height, stride;
};

NANOSVG_SCOPE
NSVGrasterizer* nsvgCreateRasterizer(void)
{
	NSVGrasterizer* r = (NSVGrasterizer*)NANOSVG_malloc(sizeof(NSVGrasterizer));
	if (r == NULL) goto error;
	memset(r, 0, sizeof(NSVGrasterizer));

	r->tessTol = 0.25f;
	r->distTol = 0.01f;

	return r;

error:
	nsvgDeleteRasterizer(r);
	return NULL;
}

NANOSVG_SCOPE
void nsvgDeleteRasterizer(NSVGrasterizer* r)
{
	NSVGmemPage* p;

	if (r == NULL) return;

	p = r->pages;
	while (p != NULL) {
		NSVGmemPage* next = p->next;
		NANOSVG_free(p);
		p = next;
	}

	if (r->edges) NANOSVG_free(r->edges);
	if (r->points) NANOSVG_free(r->points);
	if (r->points2) NANOSVG_free(r->points2);
	if (r->scanline) NANOSVG_free(r->scanline);

	NANOSVG_free(r);
}

static NSVGmemPage* nsvg__nextPage(NSVGrasterizer* r, NSVGmemPage* cur)
{
	NSVGmemPage *newp;

	/* If using existing chain, return the next page in chain */
	if (cur != NULL && cur->next != NULL) {
		return cur->next;
	}

	/* Alloc new page */
	newp = (NSVGmemPage*)NANOSVG_malloc(sizeof(NSVGmemPage));
	if (newp == NULL) return NULL;
	memset(newp, 0, sizeof(NSVGmemPage));

	/* Add to linked list */
	if (cur != NULL)
		cur->next = newp;
	else
		r->pages = newp;

	return newp;
}

static void nsvg__resetPool(NSVGrasterizer* r)
{
	NSVGmemPage* p = r->pages;
	while (p != NULL) {
		p->size = 0;
		p = p->next;
	}
	r->curpage = r->pages;
}

static unsigned char* nsvg__alloc(NSVGrasterizer* r, int size)
{
	unsigned char* buf;
	if (size > NSVG__MEMPAGE_SIZE) return NULL;
	if (r->curpage == NULL || r->curpage->size+size > NSVG__MEMPAGE_SIZE) {
		r->curpage = nsvg__nextPage(r, r->curpage);
	}
	buf = &r->curpage->mem[r->curpage->size];
	r->curpage->size += size;
	return buf;
}

static int nsvg__ptEquals(float x1, float y1, float x2, float y2, float tol)
{
	float dx = x2 - x1;
	float dy = y2 - y1;
	return dx*dx + dy*dy < tol*tol;
}

static void nsvg__addPathPoint(NSVGrasterizer* r, float x, float y, int flags)
{
	NSVGpoint* pt;

	if (r->npoints > 0) {
		pt = &r->points[r->npoints-1];
		if (nsvg__ptEquals(pt->x,pt->y, x,y, r->distTol)) {
			pt->flags = (unsigned char)(pt->flags | flags);
			return;
		}
	}

	if (r->npoints+1 > r->cpoints) {
		r->cpoints = r->cpoints > 0 ? r->cpoints * 2 : 64;
		r->points = (NSVGpoint*)NANOSVG_realloc(r->points, sizeof(NSVGpoint) * r->cpoints);
		if (r->points == NULL) return;
	}

	pt = &r->points[r->npoints];
	pt->x = x;
	pt->y = y;
	pt->flags = (unsigned char)flags;
	r->npoints++;
}

static void nsvg__appendPathPoint(NSVGrasterizer* r, NSVGpoint pt)
{
	if (r->npoints+1 > r->cpoints) {
		r->cpoints = r->cpoints > 0 ? r->cpoints * 2 : 64;
		r->points = (NSVGpoint*)NANOSVG_realloc(r->points, sizeof(NSVGpoint) * r->cpoints);
		if (r->points == NULL) return;
	}
	r->points[r->npoints] = pt;
	r->npoints++;
}

static void nsvg__duplicatePoints(NSVGrasterizer* r)
{
	if (r->npoints > r->cpoints2) {
		r->cpoints2 = r->npoints;
		r->points2 = (NSVGpoint*)NANOSVG_realloc(r->points2, sizeof(NSVGpoint) * r->cpoints2);
		if (r->points2 == NULL) return;
	}

	memcpy(r->points2, r->points, sizeof(NSVGpoint) * r->npoints);
	r->npoints2 = r->npoints;
}

static void nsvg__addEdge(NSVGrasterizer* r, float x0, float y0, float x1, float y1)
{
	NSVGedge* e;

	/* Skip horizontal edges */
	if (y0 == y1)
		return;

	if (r->nedges+1 > r->cedges) {
		r->cedges = r->cedges > 0 ? r->cedges * 2 : 64;
		r->edges = (NSVGedge*)NANOSVG_realloc(r->edges, sizeof(NSVGedge) * r->cedges);
		if (r->edges == NULL) return;
	}

	e = &r->edges[r->nedges];
	r->nedges++;

	if (y0 < y1) {
		e->x0 = x0;
		e->y0 = y0;
		e->x1 = x1;
		e->y1 = y1;
		e->dir = 1;
	} else {
		e->x0 = x1;
		e->y0 = y1;
		e->x1 = x0;
		e->y1 = y0;
		e->dir = -1;
	}
}

static float nsvg__normalize(float *x, float* y)
{
	float d = sqrtf((*x)*(*x) + (*y)*(*y));
	if (d > 1e-6f) {
		float id = 1.0f / d;
		*x *= id;
		*y *= id;
	}
	return d;
}

static float nsvg__absf(float x) { return x < 0 ? -x : x; }
static float nsvg__roundf(float x) { return (x >= 0) ? floorf(x + 0.5) : ceilf(x - 0.5); }

static void nsvg__flattenCubicBez(NSVGrasterizer* r,
								  float x1, float y1, float x2, float y2,
								  float x3, float y3, float x4, float y4,
								  int level, int type)
{
	float x12,y12,x23,y23,x34,y34,x123,y123,x234,y234,x1234,y1234;
	float dx,dy,d2,d3;

	if (level > 10) return;

	x12 = (x1+x2)*0.5f;
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x34 = (x3+x4)*0.5f;
	y34 = (y3+y4)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;

	dx = x4 - x1;
	dy = y4 - y1;
	d2 = nsvg__absf((x2 - x4) * dy - (y2 - y4) * dx);
	d3 = nsvg__absf((x3 - x4) * dy - (y3 - y4) * dx);

	if ((d2 + d3)*(d2 + d3) < r->tessTol * (dx*dx + dy*dy)) {
		nsvg__addPathPoint(r, x4, y4, type);
		return;
	}

	x234 = (x23+x34)*0.5f;
	y234 = (y23+y34)*0.5f;
	x1234 = (x123+x234)*0.5f;
	y1234 = (y123+y234)*0.5f;

	nsvg__flattenCubicBez(r, x1,y1, x12,y12, x123,y123, x1234,y1234, level+1, 0);
	nsvg__flattenCubicBez(r, x1234,y1234, x234,y234, x34,y34, x4,y4, level+1, type);
}

static void nsvg__flattenShape(NSVGrasterizer* r, NSVGshape* shape, float scale)
{
	int i, j;
	NSVGpath* path;

	for (path = shape->paths; path != NULL; path = path->next) {
		r->npoints = 0;
		/* Flatten path */
		nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, 0);
		for (i = 0; i < path->npts-1; i += 3) {
			float* p = &path->pts[i*2];
			nsvg__flattenCubicBez(r, p[0]*scale,p[1]*scale, p[2]*scale,p[3]*scale, p[4]*scale,p[5]*scale, p[6]*scale,p[7]*scale, 0, 0);
		}
		/* Close path */
		nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, 0);
		/* Build edges */
		for (i = 0, j = r->npoints-1; i < r->npoints; j = i++)
			nsvg__addEdge(r, r->points[j].x, r->points[j].y, r->points[i].x, r->points[i].y);
	}
}

enum NSVGpointFlags
{
	NSVG_PT_CORNER = 0x01,
	NSVG_PT_BEVEL = 0x02,
	NSVG_PT_LEFT = 0x04
};

static void nsvg__initClosed(NSVGpoint* left, NSVGpoint* right, NSVGpoint* p0, NSVGpoint* p1, float lineWidth)
{
	float w = lineWidth * 0.5f;
	float dx = p1->x - p0->x;
	float dy = p1->y - p0->y;
	float len = nsvg__normalize(&dx, &dy);
	float px = p0->x + dx*len*0.5f, py = p0->y + dy*len*0.5f;
	float dlx = dy, dly = -dx;
	float lx = px - dlx*w, ly = py - dly*w;
	float rx = px + dlx*w, ry = py + dly*w;
	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

static void nsvg__buttCap(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p, float dx, float dy, float lineWidth, int connect)
{
	float w = lineWidth * 0.5f;
	float px = p->x, py = p->y;
	float dlx = dy, dly = -dx;
	float lx = px - dlx*w, ly = py - dly*w;
	float rx = px + dlx*w, ry = py + dly*w;

	nsvg__addEdge(r, lx, ly, rx, ry);

	if (connect) {
		nsvg__addEdge(r, left->x, left->y, lx, ly);
		nsvg__addEdge(r, rx, ry, right->x, right->y);
	}
	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

static void nsvg__squareCap(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p, float dx, float dy, float lineWidth, int connect)
{
	float w = lineWidth * 0.5f;
	float px = p->x - dx*w, py = p->y - dy*w;
	float dlx = dy, dly = -dx;
	float lx = px - dlx*w, ly = py - dly*w;
	float rx = px + dlx*w, ry = py + dly*w;

	nsvg__addEdge(r, lx, ly, rx, ry);

	if (connect) {
		nsvg__addEdge(r, left->x, left->y, lx, ly);
		nsvg__addEdge(r, rx, ry, right->x, right->y);
	}
	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

#ifndef NSVG_PI
#define NSVG_PI (3.14159265358979323846264338327f)
#endif

static void nsvg__roundCap(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p, float dx, float dy, float lineWidth, int ncap, int connect)
{
	int i;
	float w = lineWidth * 0.5f;
	float px = p->x, py = p->y;
	float dlx = dy, dly = -dx;
	float lx = 0, ly = 0, rx = 0, ry = 0, prevx = 0, prevy = 0;

	for (i = 0; i < ncap; i++) {
		float a = (float)i/(float)(ncap-1)*NSVG_PI;
		float ax = cosf(a) * w, ay = sinf(a) * w;
		float x = px - dlx*ax - dx*ay;
		float y = py - dly*ax - dy*ay;

		if (i > 0)
			nsvg__addEdge(r, prevx, prevy, x, y);

		prevx = x;
		prevy = y;

		if (i == 0) {
			lx = x; ly = y;
		} else if (i == ncap-1) {
			rx = x; ry = y;
		}
	}

	if (connect) {
		nsvg__addEdge(r, left->x, left->y, lx, ly);
		nsvg__addEdge(r, rx, ry, right->x, right->y);
	}

	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

static void nsvg__bevelJoin(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p0, NSVGpoint* p1, float lineWidth)
{
	float w = lineWidth * 0.5f;
	float dlx0 = p0->dy, dly0 = -p0->dx;
	float dlx1 = p1->dy, dly1 = -p1->dx;
	float lx0 = p1->x - (dlx0 * w), ly0 = p1->y - (dly0 * w);
	float rx0 = p1->x + (dlx0 * w), ry0 = p1->y + (dly0 * w);
	float lx1 = p1->x - (dlx1 * w), ly1 = p1->y - (dly1 * w);
	float rx1 = p1->x + (dlx1 * w), ry1 = p1->y + (dly1 * w);

	nsvg__addEdge(r, lx0, ly0, left->x, left->y);
	nsvg__addEdge(r, lx1, ly1, lx0, ly0);

	nsvg__addEdge(r, right->x, right->y, rx0, ry0);
	nsvg__addEdge(r, rx0, ry0, rx1, ry1);

	left->x = lx1; left->y = ly1;
	right->x = rx1; right->y = ry1;
}

static void nsvg__miterJoin(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p0, NSVGpoint* p1, float lineWidth)
{
	float w = lineWidth * 0.5f;
	float dlx0 = p0->dy, dly0 = -p0->dx;
	float dlx1 = p1->dy, dly1 = -p1->dx;
	float lx0, rx0, lx1, rx1;
	float ly0, ry0, ly1, ry1;

	if (p1->flags & NSVG_PT_LEFT) {
		lx0 = lx1 = p1->x - p1->dmx * w;
		ly0 = ly1 = p1->y - p1->dmy * w;
		nsvg__addEdge(r, lx1, ly1, left->x, left->y);

		rx0 = p1->x + (dlx0 * w);
		ry0 = p1->y + (dly0 * w);
		rx1 = p1->x + (dlx1 * w);
		ry1 = p1->y + (dly1 * w);
		nsvg__addEdge(r, right->x, right->y, rx0, ry0);
		nsvg__addEdge(r, rx0, ry0, rx1, ry1);
	} else {
		lx0 = p1->x - (dlx0 * w);
		ly0 = p1->y - (dly0 * w);
		lx1 = p1->x - (dlx1 * w);
		ly1 = p1->y - (dly1 * w);
		nsvg__addEdge(r, lx0, ly0, left->x, left->y);
		nsvg__addEdge(r, lx1, ly1, lx0, ly0);

		rx0 = rx1 = p1->x + p1->dmx * w;
		ry0 = ry1 = p1->y + p1->dmy * w;
		nsvg__addEdge(r, right->x, right->y, rx1, ry1);
	}

	left->x = lx1; left->y = ly1;
	right->x = rx1; right->y = ry1;
}

static void nsvg__roundJoin(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p0, NSVGpoint* p1, float lineWidth, int ncap)
{
	int i, n;
	float w = lineWidth * 0.5f;
	float dlx0 = p0->dy, dly0 = -p0->dx;
	float dlx1 = p1->dy, dly1 = -p1->dx;
	float a0 = atan2f(dly0, dlx0);
	float a1 = atan2f(dly1, dlx1);
	float da = a1 - a0;
	float lx, ly, rx, ry;

	if (da < NSVG_PI) da += NSVG_PI*2;
	if (da > NSVG_PI) da -= NSVG_PI*2;

	n = (int)ceilf((nsvg__absf(da) / NSVG_PI) * (float)ncap);
	if (n < 2) n = 2;
	if (n > ncap) n = ncap;

	lx = left->x;
	ly = left->y;
	rx = right->x;
	ry = right->y;

	for (i = 0; i < n; i++) {
		float u = (float)i/(float)(n-1);
		float a = a0 + u*da;
		float ax = cosf(a) * w, ay = sinf(a) * w;
		float lx1 = p1->x - ax, ly1 = p1->y - ay;
		float rx1 = p1->x + ax, ry1 = p1->y + ay;

		nsvg__addEdge(r, lx1, ly1, lx, ly);
		nsvg__addEdge(r, rx, ry, rx1, ry1);

		lx = lx1; ly = ly1;
		rx = rx1; ry = ry1;
	}

	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

static void nsvg__straightJoin(NSVGrasterizer* r, NSVGpoint* left, NSVGpoint* right, NSVGpoint* p1, float lineWidth)
{
	float w = lineWidth * 0.5f;
	float lx = p1->x - (p1->dmx * w), ly = p1->y - (p1->dmy * w);
	float rx = p1->x + (p1->dmx * w), ry = p1->y + (p1->dmy * w);

	nsvg__addEdge(r, lx, ly, left->x, left->y);
	nsvg__addEdge(r, right->x, right->y, rx, ry);

	left->x = lx; left->y = ly;
	right->x = rx; right->y = ry;
}

static int nsvg__curveDivs(float r, float arc, float tol)
{
	float da = acosf(r / (r + tol)) * 2.0f;
	int divs = (int)ceilf(arc / da);
	if (divs < 2) divs = 2;
	return divs;
}

static void nsvg__expandStroke(NSVGrasterizer* r, NSVGpoint* points, int npoints, int closed, int lineJoin, int lineCap, float lineWidth)
{
	int ncap = nsvg__curveDivs(lineWidth*0.5f, NSVG_PI, r->tessTol);	/* Calculate divisions per half circle. */
	NSVGpoint left = {0,0,0,0,0,0,0,0}, right = {0,0,0,0,0,0,0,0}, firstLeft = {0,0,0,0,0,0,0,0}, firstRight = {0,0,0,0,0,0,0,0};
	NSVGpoint* p0, *p1;
	int j, s, e;

	/* Build stroke edges */
	if (closed) {
		/* Looping */
		p0 = &points[npoints-1];
		p1 = &points[0];
		s = 0;
		e = npoints;
	} else {
		/* Add cap */
		p0 = &points[0];
		p1 = &points[1];
		s = 1;
		e = npoints-1;
	}

	if (closed) {
		nsvg__initClosed(&left, &right, p0, p1, lineWidth);
		firstLeft = left;
		firstRight = right;
	} else {
		/* Add cap */
		float dx = p1->x - p0->x;
		float dy = p1->y - p0->y;
		nsvg__normalize(&dx, &dy);
		if (lineCap == NSVG_CAP_BUTT)
			nsvg__buttCap(r, &left, &right, p0, dx, dy, lineWidth, 0);
		else if (lineCap == NSVG_CAP_SQUARE)
			nsvg__squareCap(r, &left, &right, p0, dx, dy, lineWidth, 0);
		else if (lineCap == NSVG_CAP_ROUND)
			nsvg__roundCap(r, &left, &right, p0, dx, dy, lineWidth, ncap, 0);
	}

	for (j = s; j < e; ++j) {
		if (p1->flags & NSVG_PT_CORNER) {
			if (lineJoin == NSVG_JOIN_ROUND)
				nsvg__roundJoin(r, &left, &right, p0, p1, lineWidth, ncap);
			else if (lineJoin == NSVG_JOIN_BEVEL || (p1->flags & NSVG_PT_BEVEL))
				nsvg__bevelJoin(r, &left, &right, p0, p1, lineWidth);
			else
				nsvg__miterJoin(r, &left, &right, p0, p1, lineWidth);
		} else {
			nsvg__straightJoin(r, &left, &right, p1, lineWidth);
		}
		p0 = p1++;
	}

	if (closed) {
		/* Loop it */
		nsvg__addEdge(r, firstLeft.x, firstLeft.y, left.x, left.y);
		nsvg__addEdge(r, right.x, right.y, firstRight.x, firstRight.y);
	} else {
		/* Add cap */
		float dx = p1->x - p0->x;
		float dy = p1->y - p0->y;
		nsvg__normalize(&dx, &dy);
		if (lineCap == NSVG_CAP_BUTT)
			nsvg__buttCap(r, &right, &left, p1, -dx, -dy, lineWidth, 1);
		else if (lineCap == NSVG_CAP_SQUARE)
			nsvg__squareCap(r, &right, &left, p1, -dx, -dy, lineWidth, 1);
		else if (lineCap == NSVG_CAP_ROUND)
			nsvg__roundCap(r, &right, &left, p1, -dx, -dy, lineWidth, ncap, 1);
	}
}

static void nsvg__prepareStroke(NSVGrasterizer* r, float miterLimit, int lineJoin)
{
	int i, j;
	NSVGpoint* p0, *p1;

	p0 = &r->points[r->npoints-1];
	p1 = &r->points[0];
	for (i = 0; i < r->npoints; i++) {
		/* Calculate segment direction and length */
		p0->dx = p1->x - p0->x;
		p0->dy = p1->y - p0->y;
		p0->len = nsvg__normalize(&p0->dx, &p0->dy);
		/* Advance */
		p0 = p1++;
	}

	/* calculate joins */
	p0 = &r->points[r->npoints-1];
	p1 = &r->points[0];
	for (j = 0; j < r->npoints; j++) {
		float dlx0, dly0, dlx1, dly1, dmr2, cross;
		dlx0 = p0->dy;
		dly0 = -p0->dx;
		dlx1 = p1->dy;
		dly1 = -p1->dx;
		/* Calculate extrusions */
		p1->dmx = (dlx0 + dlx1) * 0.5f;
		p1->dmy = (dly0 + dly1) * 0.5f;
		dmr2 = p1->dmx*p1->dmx + p1->dmy*p1->dmy;
		if (dmr2 > 0.000001f) {
			float s2 = 1.0f / dmr2;
			if (s2 > 600.0f) {
				s2 = 600.0f;
			}
			p1->dmx *= s2;
			p1->dmy *= s2;
		}

		/* Clear flags, but keep the corner. */
		p1->flags = (p1->flags & NSVG_PT_CORNER) ? NSVG_PT_CORNER : 0;

		/* Keep track of left turns. */
		cross = p1->dx * p0->dy - p0->dx * p1->dy;
		if (cross > 0.0f)
			p1->flags |= NSVG_PT_LEFT;

		/* Check to see if the corner needs to be beveled. */
		if (p1->flags & NSVG_PT_CORNER) {
			if ((dmr2 * miterLimit*miterLimit) < 1.0f || lineJoin == NSVG_JOIN_BEVEL || lineJoin == NSVG_JOIN_ROUND) {
				p1->flags |= NSVG_PT_BEVEL;
			}
		}

		p0 = p1++;
	}
}

static void nsvg__flattenShapeStroke(NSVGrasterizer* r, NSVGshape* shape, float scale)
{
	int i, j, closed;
	NSVGpath* path;
	NSVGpoint* p0, *p1;
	float miterLimit = shape->miterLimit;
	int lineJoin = shape->strokeLineJoin;
	int lineCap = shape->strokeLineCap;
	float lineWidth = shape->strokeWidth * scale;

	for (path = shape->paths; path != NULL; path = path->next) {
		/* Flatten path */
		r->npoints = 0;
		nsvg__addPathPoint(r, path->pts[0]*scale, path->pts[1]*scale, NSVG_PT_CORNER);
		for (i = 0; i < path->npts-1; i += 3) {
			float* p = &path->pts[i*2];
			nsvg__flattenCubicBez(r, p[0]*scale,p[1]*scale, p[2]*scale,p[3]*scale, p[4]*scale,p[5]*scale, p[6]*scale,p[7]*scale, 0, NSVG_PT_CORNER);
		}
		if (r->npoints < 2)
			continue;

		closed = path->closed;

		/* If the first and last points are the same, remove the last, mark as closed path. */
		p0 = &r->points[r->npoints-1];
		p1 = &r->points[0];
		if (nsvg__ptEquals(p0->x,p0->y, p1->x,p1->y, r->distTol)) {
			r->npoints--;
			p0 = &r->points[r->npoints-1];
			closed = 1;
		}

		if (shape->strokeDashCount > 0) {
			int idash = 0, dashState = 1;
			float totalDist = 0, dashLen, allDashLen, dashOffset;
			NSVGpoint cur;

			if (closed)
				nsvg__appendPathPoint(r, r->points[0]);

			/* Duplicate points -> points2. */
			nsvg__duplicatePoints(r);

			r->npoints = 0;
 			cur = r->points2[0];
			nsvg__appendPathPoint(r, cur);

			/* Figure out dash offset. */
			allDashLen = 0;
			for (j = 0; j < shape->strokeDashCount; j++)
				allDashLen += shape->strokeDashArray[j];
			if (shape->strokeDashCount & 1)
				allDashLen *= 2.0f;
			/* Find location inside pattern */
			dashOffset = fmodf(shape->strokeDashOffset, allDashLen);
			if (dashOffset < 0.0f)
				dashOffset += allDashLen;

			while (dashOffset > shape->strokeDashArray[idash]) {
				dashOffset -= shape->strokeDashArray[idash];
				idash = (idash + 1) % shape->strokeDashCount;
			}
			dashLen = (shape->strokeDashArray[idash] - dashOffset) * scale;

			for (j = 1; j < r->npoints2; ) {
				float dx = r->points2[j].x - cur.x;
				float dy = r->points2[j].y - cur.y;
				float dist = sqrtf(dx*dx + dy*dy);

				if ((totalDist + dist) > dashLen) {
					/* Calculate intermediate point */
					float d = (dashLen - totalDist) / dist;
					float x = cur.x + dx * d;
					float y = cur.y + dy * d;
					nsvg__addPathPoint(r, x, y, NSVG_PT_CORNER);

					/* Stroke */
					if (r->npoints > 1 && dashState) {
						nsvg__prepareStroke(r, miterLimit, lineJoin);
						nsvg__expandStroke(r, r->points, r->npoints, 0, lineJoin, lineCap, lineWidth);
					}
					/* Advance dash pattern */
					dashState = !dashState;
					idash = (idash+1) % shape->strokeDashCount;
					dashLen = shape->strokeDashArray[idash] * scale;
					/* Restart */
					cur.x = x;
					cur.y = y;
					cur.flags = NSVG_PT_CORNER;
					totalDist = 0.0f;
					r->npoints = 0;
					nsvg__appendPathPoint(r, cur);
				} else {
					totalDist += dist;
					cur = r->points2[j];
					nsvg__appendPathPoint(r, cur);
					j++;
				}
			}
			/* Stroke any leftover path */
			if (r->npoints > 1 && dashState)
				nsvg__expandStroke(r, r->points, r->npoints, 0, lineJoin, lineCap, lineWidth);
		} else {
			nsvg__prepareStroke(r, miterLimit, lineJoin);
			nsvg__expandStroke(r, r->points, r->npoints, closed, lineJoin, lineCap, lineWidth);
		}
	}
}

static int nsvg__cmpEdge(const void *p, const void *q)
{
	const NSVGedge* a = (const NSVGedge*)p;
	const NSVGedge* b = (const NSVGedge*)q;

	if (a->y0 < b->y0) return -1;
	if (a->y0 > b->y0) return  1;
	return 0;
}


static NSVGactiveEdge* nsvg__addActive(NSVGrasterizer* r, NSVGedge* e, float startPoint)
{
	 NSVGactiveEdge* z;
	float dxdy;

	if (r->freelist != NULL) {
		/* Restore from freelist. */
		z = r->freelist;
		r->freelist = z->next;
	} else {
		/* Alloc new edge. */
		z = (NSVGactiveEdge*)nsvg__alloc(r, sizeof(NSVGactiveEdge));
		if (z == NULL) return NULL;
	}

	dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
/*	STBTT_assert(e->y0 <= start_point); */
	/* round dx down to avoid going too far */
	if (dxdy < 0)
		z->dx = (int)(-nsvg__roundf(NSVG__FIX * -dxdy));
	else
		z->dx = (int)nsvg__roundf(NSVG__FIX * dxdy);
	z->x = (int)nsvg__roundf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
/*	z->x -= off_x * FIX; */
	z->ey = e->y1;
	z->next = 0;
	z->dir = e->dir;

	return z;
}

static void nsvg__freeActive(NSVGrasterizer* r, NSVGactiveEdge* z)
{
	z->next = r->freelist;
	r->freelist = z;
}

static void nsvg__fillScanline(unsigned char* scanline, int len, int x0, int x1, int maxWeight, int* xmin, int* xmax)
{
	int i = x0 >> NSVG__FIXSHIFT;
	int j = x1 >> NSVG__FIXSHIFT;
	if (i < *xmin) *xmin = i;
	if (j > *xmax) *xmax = j;
	if (i < len && j >= 0) {
		if (i == j) {
			/* x0,x1 are the same pixel, so compute combined coverage */
			scanline[i] = (unsigned char)(scanline[i] + ((x1 - x0) * maxWeight >> NSVG__FIXSHIFT));
		} else {
			if (i >= 0) /* add antialiasing for x0 */
				scanline[i] = (unsigned char)(scanline[i] + (((NSVG__FIX - (x0 & NSVG__FIXMASK)) * maxWeight) >> NSVG__FIXSHIFT));
			else
				i = -1; /* clip */

			if (j < len) /* add antialiasing for x1 */
				scanline[j] = (unsigned char)(scanline[j] + (((x1 & NSVG__FIXMASK) * maxWeight) >> NSVG__FIXSHIFT));
			else
				j = len; /* clip */

			for (++i; i < j; ++i) /* fill pixels between x0 and x1 */
				scanline[i] = (unsigned char)(scanline[i] + maxWeight);
		}
	}
}

/* note: this routine clips fills that extend off the edges... ideally this
 * wouldn't happen, but it could happen if the truetype glyph bounding boxes
 * are wrong, or if the user supplies a too-small bitmap
 */
static void nsvg__fillActiveEdges(unsigned char* scanline, int len, NSVGactiveEdge* e, int maxWeight, int* xmin, int* xmax, char fillRule)
{
	/* non-zero winding fill */
	int x0 = 0, w = 0;

	if (fillRule == NSVG_FILLRULE_NONZERO) {
		/* Non-zero */
		while (e != NULL) {
			if (w == 0) {
				/* if we're currently at zero, we need to record the edge start point */
				x0 = e->x; w += e->dir;
			} else {
				int x1 = e->x; w += e->dir;
				/* if we went to zero, we need to draw */
				if (w == 0)
					nsvg__fillScanline(scanline, len, x0, x1, maxWeight, xmin, xmax);
			}
			e = e->next;
		}
	} else if (fillRule == NSVG_FILLRULE_EVENODD) {
		/* Even-odd */
		while (e != NULL) {
			if (w == 0) {
				/* if we're currently at zero, we need to record the edge start point */
				x0 = e->x; w = 1;
			} else {
				int x1 = e->x; w = 0;
				nsvg__fillScanline(scanline, len, x0, x1, maxWeight, xmin, xmax);
			}
			e = e->next;
		}
	}
}

static float nsvg__clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); }

static unsigned int nsvg__RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
	return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24);
}

static unsigned int nsvg__lerpRGBA(unsigned int c0, unsigned int c1, float u)
{
	int iu = (int)(nsvg__clampf(u, 0.0f, 1.0f) * 256.0f);
	int r = (((c0) & 0xff)*(256-iu) + (((c1) & 0xff)*iu)) >> 8;
	int g = (((c0>>8) & 0xff)*(256-iu) + (((c1>>8) & 0xff)*iu)) >> 8;
	int b = (((c0>>16) & 0xff)*(256-iu) + (((c1>>16) & 0xff)*iu)) >> 8;
	int a = (((c0>>24) & 0xff)*(256-iu) + (((c1>>24) & 0xff)*iu)) >> 8;
	return nsvg__RGBA((unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a);
}

static unsigned int nsvg__applyOpacity(unsigned int c, float u)
{
	int iu = (int)(nsvg__clampf(u, 0.0f, 1.0f) * 256.0f);
	int r = (c) & 0xff;
	int g = (c>>8) & 0xff;
	int b = (c>>16) & 0xff;
	int a = (((c>>24) & 0xff)*iu) >> 8;
	return nsvg__RGBA((unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a);
}

static inline int nsvg__div255(int x)
{
    return ((x+1) * 257) >> 16;
}

static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* cover, int x, int y,
								float tx, float ty, float scale, NSVGcachedPaint* cache)
{

	if (cache->type == NSVG_PAINT_COLOR) {
		int i, cr, cg, cb, ca;
		cr = cache->colors[0] & 0xff;
		cg = (cache->colors[0] >> 8) & 0xff;
		cb = (cache->colors[0] >> 16) & 0xff;
		ca = (cache->colors[0] >> 24) & 0xff;

		for (i = 0; i < count; i++) {
			int r,g,b;
			int a = nsvg__div255((int)cover[0] * ca);
			int ia = 255 - a;
			/* Premultiply */
			r = nsvg__div255(cr * a);
			g = nsvg__div255(cg * a);
			b = nsvg__div255(cb * a);

			/* Blend over */
			r += nsvg__div255(ia * (int)dst[0]);
			g += nsvg__div255(ia * (int)dst[1]);
			b += nsvg__div255(ia * (int)dst[2]);
			a += nsvg__div255(ia * (int)dst[3]);

			dst[0] = (unsigned char)r;
			dst[1] = (unsigned char)g;
			dst[2] = (unsigned char)b;
			dst[3] = (unsigned char)a;

			cover++;
			dst += 4;
		}
	} else if (cache->type == NSVG_PAINT_LINEAR_GRADIENT) {
		/* TODO: spread modes. */
		/* TODO: plenty of opportunities to optimize. */
		float fx, fy, dx, gy;
		float* t = cache->xform;
		int i, cr, cg, cb, ca;
		unsigned int c;

		fx = ((float)x - tx) / scale;
		fy = ((float)y - ty) / scale;
		dx = 1.0f / scale;

		for (i = 0; i < count; i++) {
			int r,g,b,a,ia;
			gy = fx*t[1] + fy*t[3] + t[5];
			c = cache->colors[(int)nsvg__clampf(gy*255.0f, 0, 255.0f)];
			cr = (c) & 0xff;
			cg = (c >> 8) & 0xff;
			cb = (c >> 16) & 0xff;
			ca = (c >> 24) & 0xff;

			a = nsvg__div255((int)cover[0] * ca);
			ia = 255 - a;

			/* Premultiply */
			r = nsvg__div255(cr * a);
			g = nsvg__div255(cg * a);
			b = nsvg__div255(cb * a);

			/* Blend over */
			r += nsvg__div255(ia * (int)dst[0]);
			g += nsvg__div255(ia * (int)dst[1]);
			b += nsvg__div255(ia * (int)dst[2]);
			a += nsvg__div255(ia * (int)dst[3]);

			dst[0] = (unsigned char)r;
			dst[1] = (unsigned char)g;
			dst[2] = (unsigned char)b;
			dst[3] = (unsigned char)a;

			cover++;
			dst += 4;
			fx += dx;
		}
	} else if (cache->type == NSVG_PAINT_RADIAL_GRADIENT) {
		/* TODO: spread modes. */
		/* TODO: plenty of opportunities to optimize. */
		/* TODO: focus (fx,fy) */
		float fx, fy, dx, gx, gy, gd;
		float* t = cache->xform;
		int i, cr, cg, cb, ca;
		unsigned int c;

		fx = ((float)x - tx) / scale;
		fy = ((float)y - ty) / scale;
		dx = 1.0f / scale;

		for (i = 0; i < count; i++) {
			int r,g,b,a,ia;
			gx = fx*t[0] + fy*t[2] + t[4];
			gy = fx*t[1] + fy*t[3] + t[5];
			gd = sqrtf(gx*gx + gy*gy);
			c = cache->colors[(int)nsvg__clampf(gd*255.0f, 0, 255.0f)];
			cr = (c) & 0xff;
			cg = (c >> 8) & 0xff;
			cb = (c >> 16) & 0xff;
			ca = (c >> 24) & 0xff;

			a = nsvg__div255((int)cover[0] * ca);
			ia = 255 - a;

			/* Premultiply */
			r = nsvg__div255(cr * a);
			g = nsvg__div255(cg * a);
			b = nsvg__div255(cb * a);

			/* Blend over */
			r += nsvg__div255(ia * (int)dst[0]);
			g += nsvg__div255(ia * (int)dst[1]);
			b += nsvg__div255(ia * (int)dst[2]);
			a += nsvg__div255(ia * (int)dst[3]);

			dst[0] = (unsigned char)r;
			dst[1] = (unsigned char)g;
			dst[2] = (unsigned char)b;
			dst[3] = (unsigned char)a;

			cover++;
			dst += 4;
			fx += dx;
		}
	}
}

static void nsvg__rasterizeSortedEdges(NSVGrasterizer *r, float tx, float ty, float scale, NSVGcachedPaint* cache, char fillRule)
{
	NSVGactiveEdge *active = NULL;
	int y, s;
	int e = 0;
	int maxWeight = (255 / NSVG__SUBSAMPLES);  /* weight per vertical scanline */
	int xmin, xmax;

	for (y = 0; y < r->height; y++) {
		memset(r->scanline, 0, r->width);
		xmin = r->width;
		xmax = 0;
		for (s = 0; s < NSVG__SUBSAMPLES; ++s) {
			/* find center of pixel for this scanline */
			float scany = (float)(y*NSVG__SUBSAMPLES + s) + 0.5f;
			NSVGactiveEdge **step = &active;

			/* update all active edges; */
			/* remove all active edges that terminate before the center of this scanline */
			while (*step) {
				NSVGactiveEdge *z = *step;
				if (z->ey <= scany) {
					*step = z->next; /* delete from list */
/*					NSVG__assert(z->valid); */
					nsvg__freeActive(r, z);
				} else {
					z->x += z->dx; /* advance to position for current scanline */
					step = &((*step)->next); /* advance through list */
				}
			}

			/* resort the list if needed */
			for (;;) {
				int changed = 0;
				step = &active;
				while (*step && (*step)->next) {
					if ((*step)->x > (*step)->next->x) {
						NSVGactiveEdge* t = *step;
						NSVGactiveEdge* q = t->next;
						t->next = q->next;
						q->next = t;
						*step = q;
						changed = 1;
					}
					step = &(*step)->next;
				}
				if (!changed) break;
			}

			/* insert all edges that start before the center of this scanline -- omit ones that also end on this scanline */
			while (e < r->nedges && r->edges[e].y0 <= scany) {
				if (r->edges[e].y1 > scany) {
					NSVGactiveEdge* z = nsvg__addActive(r, &r->edges[e], scany);
					if (z == NULL) break;
					/* find insertion point */
					if (active == NULL) {
						active = z;
					} else if (z->x < active->x) {
						/* insert at front */
						z->next = active;
						active = z;
					} else {
						/* find thing to insert AFTER */
						NSVGactiveEdge* p = active;
						while (p->next && p->next->x < z->x)
							p = p->next;
						/* at this point, p->next->x is NOT < z->x */
						z->next = p->next;
						p->next = z;
					}
				}
				e++;
			}

			/* now process all active edges in non-zero fashion */
			if (active != NULL)
				nsvg__fillActiveEdges(r->scanline, r->width, active, maxWeight, &xmin, &xmax, fillRule);
		}
		/* Blit */
		if (xmin < 0) xmin = 0;
		if (xmax > r->width-1) xmax = r->width-1;
		if (xmin <= xmax) {
			nsvg__scanlineSolid(&r->bitmap[y * r->stride] + xmin*4, xmax-xmin+1, &r->scanline[xmin], xmin, y, tx,ty, scale, cache);
		}
	}

}

static void nsvg__unpremultiplyAlpha(unsigned char* image, int w, int h, int stride)
{
	int x,y;

	/* Unpremultiply */
	for (y = 0; y < h; y++) {
		unsigned char *row = &image[y*stride];
		for (x = 0; x < w; x++) {
			int r = row[0], g = row[1], b = row[2], a = row[3];
			if (a != 0) {
				row[0] = (unsigned char)(r*255/a);
				row[1] = (unsigned char)(g*255/a);
				row[2] = (unsigned char)(b*255/a);
			}
			row += 4;
		}
	}

	/* Defringe */
	for (y = 0; y < h; y++) {
		unsigned char *row = &image[y*stride];
		for (x = 0; x < w; x++) {
			int r = 0, g = 0, b = 0, a = row[3], n = 0;
			if (a == 0) {
				if (x-1 > 0 && row[-1] != 0) {
					r += row[-4];
					g += row[-3];
					b += row[-2];
					n++;
				}
				if (x+1 < w && row[7] != 0) {
					r += row[4];
					g += row[5];
					b += row[6];
					n++;
				}
				if (y-1 > 0 && row[-stride+3] != 0) {
					r += row[-stride];
					g += row[-stride+1];
					b += row[-stride+2];
					n++;
				}
				if (y+1 < h && row[stride+3] != 0) {
					r += row[stride];
					g += row[stride+1];
					b += row[stride+2];
					n++;
				}
				if (n > 0) {
					row[0] = (unsigned char)(r/n);
					row[1] = (unsigned char)(g/n);
					row[2] = (unsigned char)(b/n);
				}
			}
			row += 4;
		}
	}
}


static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opacity)
{
	int i, j;
	NSVGgradient* grad;

	cache->type = paint->type;

	if (paint->type == NSVG_PAINT_COLOR) {
		cache->colors[0] = nsvg__applyOpacity(paint->color, opacity);
		return;
	}

	grad = paint->gradient;

	cache->spread = grad->spread;
	memcpy(cache->xform, grad->xform, sizeof(float)*6);

	if (grad->nstops == 0) {
		for (i = 0; i < 256; i++)
			cache->colors[i] = 0;
	} else if (grad->nstops == 1) {
		unsigned int color = nsvg__applyOpacity(grad->stops[0].color, opacity);
		for (i = 0; i < 256; i++)
			cache->colors[i] = color;
	} else {
		unsigned int ca, cb = 0;
		float ua, ub, du, u;
		int ia, ib, count;

		ca = nsvg__applyOpacity(grad->stops[0].color, opacity);
		ua = nsvg__clampf(grad->stops[0].offset, 0, 1);
		ub = nsvg__clampf(grad->stops[grad->nstops-1].offset, ua, 1);
		ia = (int)(ua * 255.0f);
		ib = (int)(ub * 255.0f);
		for (i = 0; i < ia; i++) {
			cache->colors[i] = ca;
		}

		for (i = 0; i < grad->nstops-1; i++) {
			ca = nsvg__applyOpacity(grad->stops[i].color, opacity);
			cb = nsvg__applyOpacity(grad->stops[i+1].color, opacity);
			ua = nsvg__clampf(grad->stops[i].offset, 0, 1);
			ub = nsvg__clampf(grad->stops[i+1].offset, 0, 1);
			ia = (int)(ua * 255.0f);
			ib = (int)(ub * 255.0f);
			count = ib - ia;
			if (count <= 0) continue;
			u = 0;
			du = 1.0f / (float)count;
			for (j = 0; j < count; j++) {
				cache->colors[ia+j] = nsvg__lerpRGBA(ca,cb,u);
				u += du;
			}
		}

		for (i = ib; i < 256; i++)
			cache->colors[i] = cb;
	}

}

/*
static void dumpEdges(NSVGrasterizer* r, const char* name)
{
	float xmin = 0, xmax = 0, ymin = 0, ymax = 0;
	NSVGedge *e = NULL;
	int i;
	if (r->nedges == 0) return;
	FILE* fp = fopen(name, "w");
	if (fp == NULL) return;

	xmin = xmax = r->edges[0].x0;
	ymin = ymax = r->edges[0].y0;
	for (i = 0; i < r->nedges; i++) {
		e = &r->edges[i];
		xmin = nsvg__minf(xmin, e->x0);
		xmin = nsvg__minf(xmin, e->x1);
		xmax = nsvg__maxf(xmax, e->x0);
		xmax = nsvg__maxf(xmax, e->x1);
		ymin = nsvg__minf(ymin, e->y0);
		ymin = nsvg__minf(ymin, e->y1);
		ymax = nsvg__maxf(ymax, e->y0);
		ymax = nsvg__maxf(ymax, e->y1);
	}

	fprintf(fp, "<svg viewBox=\"%f %f %f %f\" xmlns=\"http://www.w3.org/2000/svg\">", xmin, ymin, (xmax - xmin), (ymax - ymin));

	for (i = 0; i < r->nedges; i++) {
		e = &r->edges[i];
		fprintf(fp ,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:#000;\" />", e->x0,e->y0, e->x1,e->y1);
	}

	for (i = 0; i < r->npoints; i++) {
		if (i+1 < r->npoints)
			fprintf(fp ,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:#f00;\" />", r->points[i].x, r->points[i].y, r->points[i+1].x, r->points[i+1].y);
		fprintf(fp ,"<circle cx=\"%f\" cy=\"%f\" r=\"1\" style=\"fill:%s;\" />", r->points[i].x, r->points[i].y, r->points[i].flags == 0 ? "#f00" : "#0f0");
	}

	fprintf(fp, "</svg>");
	fclose(fp);
}
*/

NANOSVG_SCOPE
void nsvgRasterize(NSVGrasterizer* r,
				   NSVGimage* image, float tx, float ty, float scale,
				   unsigned char* dst, int w, int h, int stride)
{
	NSVGshape *shape = NULL;
	NSVGedge *e = NULL;
	NSVGcachedPaint cache;
	int i;

	r->bitmap = dst;
	r->width = w;
	r->height = h;
	r->stride = stride;

	if (w > r->cscanline) {
		r->cscanline = w;
		r->scanline = (unsigned char*)NANOSVG_realloc(r->scanline, w);
		if (r->scanline == NULL) return;
	}

	for (i = 0; i < h; i++)
		memset(&dst[i*stride], 0, w*4);

	for (shape = image->shapes; shape != NULL; shape = shape->next) {
		if (!(shape->flags & NSVG_FLAGS_VISIBLE))
			continue;

		if (shape->fill.type != NSVG_PAINT_NONE) {
			nsvg__resetPool(r);
			r->freelist = NULL;
			r->nedges = 0;

			nsvg__flattenShape(r, shape, scale);

			/* Scale and translate edges */
			for (i = 0; i < r->nedges; i++) {
				e = &r->edges[i];
				e->x0 = tx + e->x0;
				e->y0 = (ty + e->y0) * NSVG__SUBSAMPLES;
				e->x1 = tx + e->x1;
				e->y1 = (ty + e->y1) * NSVG__SUBSAMPLES;
			}

			/* Rasterize edges */
			if (r->nedges != 0)
				qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);

			/* now, traverse the scanlines and find the intersections on each scanline, use non-zero rule */
			nsvg__initPaint(&cache, &shape->fill, shape->opacity);

			nsvg__rasterizeSortedEdges(r, tx,ty,scale, &cache, shape->fillRule);
		}
		if (shape->stroke.type != NSVG_PAINT_NONE && (shape->strokeWidth * scale) > 0.01f) {
			nsvg__resetPool(r);
			r->freelist = NULL;
			r->nedges = 0;

			nsvg__flattenShapeStroke(r, shape, scale);

/*			dumpEdges(r, "edge.svg"); */

			/* Scale and translate edges */
			for (i = 0; i < r->nedges; i++) {
				e = &r->edges[i];
				e->x0 = tx + e->x0;
				e->y0 = (ty + e->y0) * NSVG__SUBSAMPLES;
				e->x1 = tx + e->x1;
				e->y1 = (ty + e->y1) * NSVG__SUBSAMPLES;
			}

			/* Rasterize edges */
			if (r->nedges != 0)
				qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);

			/* now, traverse the scanlines and find the intersections on each scanline, use non-zero rule */
			nsvg__initPaint(&cache, &shape->stroke, shape->opacity);

			nsvg__rasterizeSortedEdges(r, tx,ty,scale, &cache, NSVG_FILLRULE_NONZERO);
		}
	}

	nsvg__unpremultiplyAlpha(dst, w, h, stride);

	r->bitmap = NULL;
	r->width = 0;
	r->height = 0;
	r->stride = 0;
}

#endif

#endif /* NANOSVGRAST_H */

Changes to generic/tk.decls.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







# tk.decls --
#
#	This file contains the declarations for all supported public
#	functions that are exported by the Tk library via the stubs table.
#	This file is used to generate the tkDecls.h, tkPlatDecls.h,
#	tkStub.c, and tkPlatStub.c files.
#
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2007 Daniel A. Steffen <[email protected]>
# Copyright (c) 1998-2000 Ajuba Solutions.
# Copyright (c) 2007 Daniel A. Steffen <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

library tk

# Define the tk interface with 3 sub interfaces:
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65







-
-
+
+







}
declare 5 {
    void Tk_AddOption(Tk_Window tkwin, const char *name,
	    const char *value, int priority)
}
declare 6 {
    void Tk_BindEvent(Tk_BindingTable bindingTable,
	    XEvent *eventPtr, Tk_Window tkwin, Tcl_Size numObjects,
	    void **objectPtr)
	    XEvent *eventPtr, Tk_Window tkwin, int numObjects,
	    ClientData *objectPtr)
}
declare 7 {
    void Tk_CanvasDrawableCoords(Tk_Canvas canvas,
	    double x, double y, short *drawableXPtr,
	    short *drawableYPtr)
}
declare 8 {
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105


106
107
108
109


110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144

145
146
147
148
149

150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176

177
178
179
180
181

182
183
184

185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233

234
235
236

237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275

276
277
278
279
280

281
282
283
284
285
286
287
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103


104
105
106
107


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143

144
145
146
147
148

149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175

176
177
178
179
180

181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232

233
234
235

236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274

275
276
277
278
279

280
281
282
283
284
285
286
287







-
+












-
-
+
+


-
-
+
+













-
+















-
+




-
+




-
+








-
+








-
+








-
+




-
+


-
+













-
+


















-
+



-
+











-
+


-
+











-
+







-
+









-
+








-
+




-
+







}
declare 13 {
    int Tk_CanvasPsFont(Tcl_Interp *interp,
	    Tk_Canvas canvas, Tk_Font font)
}
declare 14 {
    void Tk_CanvasPsPath(Tcl_Interp *interp,
	    Tk_Canvas canvas, double *coordPtr, Tcl_Size numPoints)
	    Tk_Canvas canvas, double *coordPtr, int numPoints)
}
declare 15 {
    int Tk_CanvasPsStipple(Tcl_Interp *interp,
	    Tk_Canvas canvas, Pixmap bitmap)
}
declare 16 {
    double Tk_CanvasPsY(Tk_Canvas canvas, double y)
}
declare 17 {
    void Tk_CanvasSetStippleOrigin(Tk_Canvas canvas, GC gc)
}
declare 18 {
    int Tk_CanvasTagsParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int Tk_CanvasTagsParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 19 {
    const char *Tk_CanvasTagsPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *Tk_CanvasTagsPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 20 {
    Tk_Window	Tk_CanvasTkwin(Tk_Canvas canvas)
}
declare 21 {
    void Tk_CanvasWindowCoords(Tk_Canvas canvas, double x, double y,
	    short *screenXPtr, short *screenYPtr)
}
declare 22 {
    void Tk_ChangeWindowAttributes(Tk_Window tkwin, unsigned long valueMask,
	    XSetWindowAttributes *attsPtr)
}
declare 23 {
    int Tk_CharBbox(Tk_TextLayout layout, Tcl_Size index, int *xPtr,
    int Tk_CharBbox(Tk_TextLayout layout, int index, int *xPtr,
	    int *yPtr, int *widthPtr, int *heightPtr)
}
declare 24 {
    void Tk_ClearSelection(Tk_Window tkwin, Atom selection)
}
declare 25 {
    int Tk_ClipboardAppend(Tcl_Interp *interp, Tk_Window tkwin,
	    Atom target, Atom format, const char *buffer)
}
declare 26 {
    int Tk_ClipboardClear(Tcl_Interp *interp, Tk_Window tkwin)
}
declare 27 {
    int Tk_ConfigureInfo(Tcl_Interp *interp,
	    Tk_Window tkwin, const Tk_ConfigSpec *specs,
	    void *widgRec, const char *argvName, int flags)
	    char *widgRec, const char *argvName, int flags)
}
declare 28 {
    int Tk_ConfigureValue(Tcl_Interp *interp,
	    Tk_Window tkwin, const Tk_ConfigSpec *specs,
	    void *widgRec, const char *argvName, int flags)
	    char *widgRec, const char *argvName, int flags)
}
declare 29 {
    int Tk_ConfigureWidget(Tcl_Interp *interp,
	    Tk_Window tkwin, const Tk_ConfigSpec *specs,
	    Tcl_Size objc, Tcl_Obj *const *objv, void *widgRec,
	    int argc, CONST84 char **argv, char *widgRec,
	    int flags)
}
declare 30 {
    void Tk_ConfigureWindow(Tk_Window tkwin,
	    unsigned int valueMask, XWindowChanges *valuePtr)
}
declare 31 {
    Tk_TextLayout Tk_ComputeTextLayout(Tk_Font font,
	    const char *str, Tcl_Size numChars, int wrapLength,
	    const char *str, int numChars, int wrapLength,
	    Tk_Justify justify, int flags, int *widthPtr,
	    int *heightPtr)
}
declare 32 {
    Tk_Window Tk_CoordsToWindow(int rootX, int rootY, Tk_Window tkwin)
}
declare 33 {
    unsigned long Tk_CreateBinding(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable, void *object,
	    Tk_BindingTable bindingTable, ClientData object,
	    const char *eventStr, const char *script, int append)
}
declare 34 {
    Tk_BindingTable Tk_CreateBindingTable(Tcl_Interp *interp)
}
declare 35 {
    Tk_ErrorHandler Tk_CreateErrorHandler(Display *display,
	    int errNum, int request, int minorCode,
	    Tk_ErrorProc *errorProc, void *clientData)
	    Tk_ErrorProc *errorProc, ClientData clientData)
}
declare 36 {
    void Tk_CreateEventHandler(Tk_Window token,
	    unsigned long mask, Tk_EventProc *proc,
	    void *clientData)
	    ClientData clientData)
}
declare 37 {
    void Tk_CreateGenericHandler(Tk_GenericProc *proc, void *clientData)
    void Tk_CreateGenericHandler(Tk_GenericProc *proc, ClientData clientData)
}
declare 38 {
    void Tk_CreateImageType(const Tk_ImageType *typePtr)
}
declare 39 {
    void Tk_CreateItemType(Tk_ItemType *typePtr)
}
declare 40 {
    void Tk_CreatePhotoImageFormat(const Tk_PhotoImageFormat *formatPtr)
}
declare 41 {
    void Tk_CreateSelHandler(Tk_Window tkwin,
	    Atom selection, Atom target,
	    Tk_SelectionProc *proc, void *clientData,
	    Tk_SelectionProc *proc, ClientData clientData,
	    Atom format)
}
declare 42 {
    Tk_Window Tk_CreateWindow(Tcl_Interp *interp,
	    Tk_Window parent, const char *name, const char *screenName)
}
declare 43 {
    Tk_Window Tk_CreateWindowFromPath(Tcl_Interp *interp, Tk_Window tkwin,
	    const char *pathName, const char *screenName)
}
declare 44 {
    int Tk_DefineBitmap(Tcl_Interp *interp, const char *name,
	    const void *source, int width, int height)
}
declare 45 {
    void Tk_DefineCursor(Tk_Window window, Tk_Cursor cursor)
}
declare 46 {
    void Tk_DeleteAllBindings(Tk_BindingTable bindingTable, void *object)
    void Tk_DeleteAllBindings(Tk_BindingTable bindingTable, ClientData object)
}
declare 47 {
    int Tk_DeleteBinding(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable, void *object,
	    Tk_BindingTable bindingTable, ClientData object,
	    const char *eventStr)
}
declare 48 {
    void Tk_DeleteBindingTable(Tk_BindingTable bindingTable)
}
declare 49 {
    void Tk_DeleteErrorHandler(Tk_ErrorHandler handler)
}
declare 50 {
    void Tk_DeleteEventHandler(Tk_Window token,
	    unsigned long mask, Tk_EventProc *proc,
	    void *clientData)
	    ClientData clientData)
}
declare 51 {
    void Tk_DeleteGenericHandler(Tk_GenericProc *proc, void *clientData)
    void Tk_DeleteGenericHandler(Tk_GenericProc *proc, ClientData clientData)
}
declare 52 {
    void Tk_DeleteImage(Tcl_Interp *interp, const char *name)
}
declare 53 {
    void Tk_DeleteSelHandler(Tk_Window tkwin, Atom selection, Atom target)
}
declare 54 {
    void Tk_DestroyWindow(Tk_Window tkwin)
}
declare 55 {
    const char *Tk_DisplayName(Tk_Window tkwin)
    CONST84_RETURN char *Tk_DisplayName(Tk_Window tkwin)
}
declare 56 {
    int Tk_DistanceToTextLayout(Tk_TextLayout layout, int x, int y)
}
declare 57 {
    void Tk_Draw3DPolygon(Tk_Window tkwin,
	    Drawable drawable, Tk_3DBorder border,
	    XPoint *pointPtr, Tcl_Size numPoints, int borderWidth,
	    XPoint *pointPtr, int numPoints, int borderWidth,
	    int leftRelief)
}
declare 58 {
    void Tk_Draw3DRectangle(Tk_Window tkwin, Drawable drawable,
	    Tk_3DBorder border, int x, int y, int width, int height,
	    int borderWidth, int relief)
}
declare 59 {
    void Tk_DrawChars(Display *display, Drawable drawable, GC gc,
	    Tk_Font tkfont, const char *source, Tcl_Size numBytes, int x, int y)
	    Tk_Font tkfont, const char *source, int numBytes, int x, int y)
}
declare 60 {
    void Tk_DrawFocusHighlight(Tk_Window tkwin, GC gc, int width,
	    Drawable drawable)
}
declare 61 {
    void Tk_DrawTextLayout(Display *display,
	    Drawable drawable, GC gc, Tk_TextLayout layout,
	    int x, int y, Tcl_Size firstChar, Tcl_Size lastChar)
	    int x, int y, int firstChar, int lastChar)
}
declare 62 {
    void Tk_Fill3DPolygon(Tk_Window tkwin,
	    Drawable drawable, Tk_3DBorder border,
	    XPoint *pointPtr, Tcl_Size numPoints, int borderWidth,
	    XPoint *pointPtr, int numPoints, int borderWidth,
	    int leftRelief)
}
declare 63 {
    void Tk_Fill3DRectangle(Tk_Window tkwin,
	    Drawable drawable, Tk_3DBorder border, int x,
	    int y, int width, int height, int borderWidth,
	    int relief)
314
315
316
317
318
319
320
321

322
323
324
325
326
327



328
329
330
331
332
333
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348

349
350
351
352


353
354
355
356
357
358
359
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350

351
352
353


354
355
356
357
358
359
360
361
362







-
+






+
+
+













-
+






-
+


-
-
+
+







    void Tk_FreeGC(Display *display, GC gc)
}
declare 73 {
    void Tk_FreeImage(Tk_Image image)
}
declare 74 {
    void Tk_FreeOptions(const Tk_ConfigSpec *specs,
	    void *widgRec, Display *display, int needFlags)
	    char *widgRec, Display *display, int needFlags)
}
declare 75 {
    void Tk_FreePixmap(Display *display, Pixmap pixmap)
}
declare 76 {
    void Tk_FreeTextLayout(Tk_TextLayout textLayout)
}
declare 77 {deprecated {function does nothing, call can be removed}} {
    void Tk_FreeXId(Display *display, XID xid)
}
declare 78 {
    GC Tk_GCForColor(XColor *colorPtr, Drawable drawable)
}
declare 79 {
    void Tk_GeometryRequest(Tk_Window tkwin, int reqWidth,  int reqHeight)
}
declare 80 {
    Tk_3DBorder	Tk_Get3DBorder(Tcl_Interp *interp, Tk_Window tkwin,
	    Tk_Uid colorName)
}
declare 81 {
    void Tk_GetAllBindings(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable, void *object)
	    Tk_BindingTable bindingTable, ClientData object)
}
declare 82 {
    int Tk_GetAnchor(Tcl_Interp *interp,
	    const char *str, Tk_Anchor *anchorPtr)
}
declare 83 {
    const char *Tk_GetAtomName(Tk_Window tkwin, Atom atom)
    CONST84_RETURN char *Tk_GetAtomName(Tk_Window tkwin, Atom atom)
}
declare 84 {
    const char *Tk_GetBinding(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable, void *object,
    CONST84_RETURN char *Tk_GetBinding(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable, ClientData object,
	    const char *eventStr)
}
declare 85 {
    Pixmap Tk_GetBitmap(Tcl_Interp *interp, Tk_Window tkwin, const char *str)
}
declare 86 {
    Pixmap Tk_GetBitmapFromData(Tcl_Interp *interp,
393
394
395
396
397
398
399
400

401
402
403
404


405
406
407
408
409
410
411
396
397
398
399
400
401
402

403
404
405


406
407
408
409
410
411
412
413
414







-
+


-
-
+
+







    void Tk_GetFontMetrics(Tk_Font font, Tk_FontMetrics *fmPtr)
}
declare 96 {
    GC Tk_GetGC(Tk_Window tkwin, unsigned long valueMask, XGCValues *valuePtr)
}
declare 97 {
    Tk_Image Tk_GetImage(Tcl_Interp *interp, Tk_Window tkwin, const char *name,
	    Tk_ImageChangedProc *changeProc, void *clientData)
	    Tk_ImageChangedProc *changeProc, ClientData clientData)
}
declare 98 {
    void *Tk_GetImageModelData(Tcl_Interp *interp,
	    const char *name, const Tk_ImageType **typePtrPtr)
    ClientData Tk_GetImageMasterData(Tcl_Interp *interp,
	    const char *name, CONST86 Tk_ImageType **typePtrPtr)
}
declare 99 {
    Tk_ItemType *Tk_GetItemTypes(void)
}
declare 100 {
    int Tk_GetJoinStyle(Tcl_Interp *interp, const char *str, int *joinPtr)
}
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458







-
+








-
+







    int Tk_GetRelief(Tcl_Interp *interp, const char *name, int *reliefPtr)
}
declare 107 {
    void Tk_GetRootCoords(Tk_Window tkwin, int *xPtr, int *yPtr)
}
declare 108 {
    int Tk_GetScrollInfo(Tcl_Interp *interp,
	    Tcl_Size argc, const char **argv, double *dblPtr, int *intPtr)
	    int argc, CONST84 char **argv, double *dblPtr, int *intPtr)
}
declare 109 {
    int Tk_GetScreenMM(Tcl_Interp *interp,
	    Tk_Window tkwin, const char *str, double *doublePtr)
}
declare 110 {
    int Tk_GetSelection(Tcl_Interp *interp,
	    Tk_Window tkwin, Atom selection, Atom target,
	    Tk_GetSelProc *proc, void *clientData)
	    Tk_GetSelProc *proc, ClientData clientData)
}
declare 111 {
    Tk_Uid Tk_GetUid(const char *str)
}
declare 112 {
    Visual *Tk_GetVisual(Tcl_Interp *interp,
	    Tk_Window tkwin, const char *str, int *depthPtr,
465
466
467
468
469
470
471
472

473
474



475
476
477
478
479
480
481
482
483
484


485
486
487
488
489
490
491
492
493
494

495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511
512
513
514
515

516
517
518

519
520
521

522
523
524

525
526
527

528
529
530

531
532
533

534
535
536

537
538
539

540
541
542

543
544
545

546
547
548
549
550
551
552
553
554

555
556
557
558

559











560
561
562
563
564
565
566



567
568
569



570
571
572
573
574
575
576
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483
484
485
486
487
488


489
490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523

524
525
526

527
528
529

530
531
532

533
534
535

536
537
538

539
540
541

542
543
544

545
546
547

548
549
550

551
552
553
554
555
556
557
558
559

560
561
562
563

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599







-
+


+
+
+








-
-
+
+









-
+






-
+













-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+








-
+



-
+

+
+
+
+
+
+
+
+
+
+
+







+
+
+



+
+
+







declare 115 {
    void Tk_HandleEvent(XEvent *eventPtr)
}
declare 116 {
    Tk_Window Tk_IdToWindow(Display *display, Window window)
}
declare 117 {
    void Tk_ImageChanged(Tk_ImageModel model, int x, int y,
    void Tk_ImageChanged(Tk_ImageMaster master, int x, int y,
	    int width, int height, int imageWidth, int imageHeight)
}
declare 118 {
    int Tk_Init(Tcl_Interp *interp)
}
declare 119 {
    Atom Tk_InternAtom(Tk_Window tkwin, const char *name)
}
declare 120 {
    int Tk_IntersectTextLayout(Tk_TextLayout layout, int x, int y,
	    int width, int height)
}
declare 121 {
    void Tk_MaintainGeometry(Tk_Window window,
	    Tk_Window container, int x, int y, int width, int height)
    void Tk_MaintainGeometry(Tk_Window slave,
	    Tk_Window master, int x, int y, int width, int height)
}
declare 122 {
    Tk_Window Tk_MainWindow(Tcl_Interp *interp)
}
declare 123 {
    void Tk_MakeWindowExist(Tk_Window tkwin)
}
declare 124 {
    void Tk_ManageGeometry(Tk_Window tkwin,
	    const Tk_GeomMgr *mgrPtr, void *clientData)
	    const Tk_GeomMgr *mgrPtr, ClientData clientData)
}
declare 125 {
    void Tk_MapWindow(Tk_Window tkwin)
}
declare 126 {
    int Tk_MeasureChars(Tk_Font tkfont,
	    const char *source, Tcl_Size numBytes, int maxPixels,
	    const char *source, int numBytes, int maxPixels,
	    int flags, int *lengthPtr)
}
declare 127 {
    void Tk_MoveResizeWindow(Tk_Window tkwin,
	    int x, int y, int width, int height)
}
declare 128 {
    void Tk_MoveWindow(Tk_Window tkwin, int x, int y)
}
declare 129 {
    void Tk_MoveToplevelWindow(Tk_Window tkwin, int x, int y)
}
declare 130 {
    const char *Tk_NameOf3DBorder(Tk_3DBorder border)
    CONST84_RETURN char *Tk_NameOf3DBorder(Tk_3DBorder border)
}
declare 131 {
    const char *Tk_NameOfAnchor(Tk_Anchor anchor)
    CONST84_RETURN char *Tk_NameOfAnchor(Tk_Anchor anchor)
}
declare 132 {
    const char *Tk_NameOfBitmap(Display *display, Pixmap bitmap)
    CONST84_RETURN char *Tk_NameOfBitmap(Display *display, Pixmap bitmap)
}
declare 133 {
    const char *Tk_NameOfCapStyle(int cap)
    CONST84_RETURN char *Tk_NameOfCapStyle(int cap)
}
declare 134 {
    const char *Tk_NameOfColor(XColor *colorPtr)
    CONST84_RETURN char *Tk_NameOfColor(XColor *colorPtr)
}
declare 135 {
    const char *Tk_NameOfCursor(Display *display, Tk_Cursor cursor)
    CONST84_RETURN char *Tk_NameOfCursor(Display *display, Tk_Cursor cursor)
}
declare 136 {
    const char *Tk_NameOfFont(Tk_Font font)
    CONST84_RETURN char *Tk_NameOfFont(Tk_Font font)
}
declare 137 {
    const char *Tk_NameOfImage(Tk_ImageModel model)
    CONST84_RETURN char *Tk_NameOfImage(Tk_ImageMaster imageMaster)
}
declare 138 {
    const char *Tk_NameOfJoinStyle(int join)
    CONST84_RETURN char *Tk_NameOfJoinStyle(int join)
}
declare 139 {
    const char *Tk_NameOfJustify(Tk_Justify justify)
    CONST84_RETURN char *Tk_NameOfJustify(Tk_Justify justify)
}
declare 140 {
    const char *Tk_NameOfRelief(int relief)
    CONST84_RETURN char *Tk_NameOfRelief(int relief)
}
declare 141 {
    Tk_Window Tk_NameToWindow(Tcl_Interp *interp,
	    const char *pathName, Tk_Window tkwin)
}
declare 142 {
    void Tk_OwnSelection(Tk_Window tkwin,
	    Atom selection, Tk_LostSelProc *proc,
	    void *clientData)
	    ClientData clientData)
}
declare 143 {
    int Tk_ParseArgv(Tcl_Interp *interp,
	    Tk_Window tkwin, int *argcPtr, const char **argv,
	    Tk_Window tkwin, int *argcPtr, CONST84 char **argv,
	    const Tk_ArgvInfo *argTable, int flags)
}
declare 144 {deprecated {function signature changed}} {
    void Tk_PhotoPutBlock_NoComposite(Tk_PhotoHandle handle,
	    Tk_PhotoImageBlock *blockPtr, int x, int y,
	    int width, int height)
}
declare 145 {deprecated {function signature changed}} {
    void Tk_PhotoPutZoomedBlock_NoComposite(Tk_PhotoHandle handle,
	    Tk_PhotoImageBlock *blockPtr, int x, int y,
	    int width, int height, int zoomX, int zoomY,
	    int subsampleX, int subsampleY)
}
declare 146 {
    int Tk_PhotoGetImage(Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr)
}
declare 147 {
    void Tk_PhotoBlank(Tk_PhotoHandle handle)
}
declare 148 {deprecated {function signature changed}} {
    void Tk_PhotoExpand_Panic(Tk_PhotoHandle handle, int width, int height )
}
declare 149 {
    void Tk_PhotoGetSize(Tk_PhotoHandle handle, int *widthPtr, int *heightPtr)
}
declare 150 {deprecated {function signature changed}} {
    void Tk_PhotoSetSize_Panic(Tk_PhotoHandle handle, int width, int height)
}
declare 151 {
    int Tk_PointToChar(Tk_TextLayout layout, int x, int y)
}
declare 152 {
    int Tk_PostscriptFontName(Tk_Font tkfont, Tcl_DString *dsPtr)
}
declare 153 {
588
589
590
591
592
593
594
595




596
597
598
599
600
601
602
611
612
613
614
615
616
617

618
619
620
621
622
623
624
625
626
627
628







-
+
+
+
+







    void Tk_ResizeWindow(Tk_Window tkwin, int width, int height)
}
declare 157 {
    int Tk_RestackWindow(Tk_Window tkwin, int aboveBelow, Tk_Window other)
}
declare 158 {
    Tk_RestrictProc *Tk_RestrictEvents(Tk_RestrictProc *proc,
	    void *arg, void **prevArgPtr)
	    ClientData arg, ClientData *prevArgPtr)
}
declare 159 {
    int Tk_SafeInit(Tcl_Interp *interp)
}
declare 160 {
    const char *Tk_SetAppName(Tk_Window tkwin, const char *name)
}
declare 161 {
    void Tk_SetBackgroundFromBorder(Tk_Window tkwin, Tk_3DBorder border)
}
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
658


659
660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682


683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702







-
+







-
-
+
+










-
+







declare 174 {
    int Tk_StrictMotif(Tk_Window tkwin)
}
declare 175 {
    void Tk_TextLayoutToPostscript(Tcl_Interp *interp, Tk_TextLayout layout)
}
declare 176 {
    int Tk_TextWidth(Tk_Font font, const char *str, Tcl_Size numBytes)
    int Tk_TextWidth(Tk_Font font, const char *str, int numBytes)
}
declare 177 {
    void Tk_UndefineCursor(Tk_Window window)
}
declare 178 {
    void Tk_UnderlineChars(Display *display,
	    Drawable drawable, GC gc, Tk_Font tkfont,
	    const char *source, int x, int y, Tcl_Size firstByte,
	    Tcl_Size lastByte)
	    const char *source, int x, int y, int firstByte,
	    int lastByte)
}
declare 179 {
    void Tk_UnderlineTextLayout(Display *display, Drawable drawable, GC gc,
	    Tk_TextLayout layout, int x, int y,
	    int underline)
}
declare 180 {
    void Tk_Ungrab(Tk_Window tkwin)
}
declare 181 {
    void Tk_UnmaintainGeometry(Tk_Window window, Tk_Window container)
    void Tk_UnmaintainGeometry(Tk_Window slave, Tk_Window master)
}
declare 182 {
    void Tk_UnmapWindow(Tk_Window tkwin)
}
declare 183 {
    void Tk_UnsetGrid(Tk_Window tkwin)
}
714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
740
741
742
743
744
745
746

747
748
749
750
751
752
753
754







-
+







declare 193 {
    void  Tk_FreeBitmapFromObj(Tk_Window tkwin, Tcl_Obj *objPtr)
}
declare 194 {
    void  Tk_FreeColorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr)
}
declare 195 {
    void  Tk_FreeConfigOptions(void *recordPtr, Tk_OptionTable optionToken,
    void  Tk_FreeConfigOptions(char *recordPtr, Tk_OptionTable optionToken,
	    Tk_Window tkwin)
}
declare 196 {
    void  Tk_FreeSavedOptions(Tk_SavedOptions *savePtr)
}
declare 197 {
    void  Tk_FreeCursorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr)
744
745
746
747
748
749
750
751

752
753
754
755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776

777
778
779

780
781




782
783
784
785
786
787


788
789
790
791
792
793



794
795
796
797
798
799
800
770
771
772
773
774
775
776

777
778
779
780

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801

802
803
804

805
806
807
808
809
810
811
812
813
814
815


816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833







-
+



-
+




















-
+


-
+


+
+
+
+




-
-
+
+






+
+
+







    XColor *Tk_GetColorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr)
}
declare 203 {
    Tk_Cursor Tk_GetCursorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr)
}
declare 204 {
    Tcl_Obj *Tk_GetOptionInfo(Tcl_Interp *interp,
	    void *recordPtr, Tk_OptionTable optionTable,
	    char *recordPtr, Tk_OptionTable optionTable,
	    Tcl_Obj *namePtr, Tk_Window tkwin)
}
declare 205 {
    Tcl_Obj *Tk_GetOptionValue(Tcl_Interp *interp, void *recordPtr,
    Tcl_Obj *Tk_GetOptionValue(Tcl_Interp *interp, char *recordPtr,
	    Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin)
}
declare 206 {
    int	 Tk_GetJustifyFromObj(Tcl_Interp *interp,
	    Tcl_Obj *objPtr, Tk_Justify *justifyPtr)
}
declare 207 {
    int	 Tk_GetMMFromObj(Tcl_Interp *interp,
	    Tk_Window tkwin, Tcl_Obj *objPtr, double *doublePtr)
}
declare 208 {
    int	 Tk_GetPixelsFromObj(Tcl_Interp *interp,
	    Tk_Window tkwin, Tcl_Obj *objPtr, int *intPtr)
}
declare 209 {
    int	 Tk_GetReliefFromObj(Tcl_Interp *interp,
	    Tcl_Obj *objPtr, int *resultPtr)
}
declare 210 {
    int	 Tk_GetScrollInfoObj(Tcl_Interp *interp,
	    Tcl_Size objc, Tcl_Obj *const objv[], double *dblPtr, int *intPtr)
	    int objc, Tcl_Obj *const objv[], double *dblPtr, int *intPtr)
}
declare 211 {
    int	 Tk_InitOptions(Tcl_Interp *interp, void *recordPtr,
    int	 Tk_InitOptions(Tcl_Interp *interp, char *recordPtr,
	    Tk_OptionTable optionToken, Tk_Window tkwin)
}
declare 212 {
    void  Tk_MainEx(int argc, char **argv, Tcl_AppInitProc *appInitProc,
	    Tcl_Interp *interp)
}
declare 213 {
    void  Tk_RestoreSavedOptions(Tk_SavedOptions *savePtr)
}
declare 214 {
    int	 Tk_SetOptions(Tcl_Interp *interp, void *recordPtr,
	    Tk_OptionTable optionTable, Tcl_Size objc,
    int	 Tk_SetOptions(Tcl_Interp *interp, char *recordPtr,
	    Tk_OptionTable optionTable, int objc,
	    Tcl_Obj *const objv[], Tk_Window tkwin,
	    Tk_SavedOptions *savePtr, int *maskPtr)
}
declare 215 {
    void Tk_InitConsoleChannels(Tcl_Interp *interp)
}
declare 216 {
    int Tk_CreateConsoleWindow(Tcl_Interp *interp)
}
declare 217 {
    void Tk_CreateSmoothMethod(Tcl_Interp *interp, const Tk_SmoothMethod *method)
}
#declare 218 {
#    void Tk_CreateCanvasVisitor(Tcl_Interp *interp, void *typePtr)
#}
#declare 219 {
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902







-
+







declare 234 {
    int Tk_PostscriptImage(Tk_Image image, Tcl_Interp *interp,
	    Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y,
	    int width, int height, int prepass)
}
declare 235 {
    void Tk_PostscriptPath(Tcl_Interp *interp, Tk_PostscriptInfo psInfo,
	    double *coordPtr, Tcl_Size numPoints)
	    double *coordPtr, int numPoints)
}
declare 236 {
    int Tk_PostscriptStipple(Tcl_Interp *interp, Tk_Window tkwin,
	    Tk_PostscriptInfo psInfo, Pixmap bitmap)
}
declare 237 {
    double Tk_PostscriptY(double y, Tk_PostscriptInfo psInfo)
887
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911











912
913
914
915
916
917
918
920
921
922
923
924
925
926

927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962







-
+

















+
+
+
+
+
+
+
+
+
+
+







#
declare 241 {
    Tk_Window Tk_CreateAnonymousWindow(Tcl_Interp *interp,
	    Tk_Window parent, const char *screenName)
}
declare 242 {
    void Tk_SetClassProcs(Tk_Window tkwin,
	    const Tk_ClassProcs *procs, void *instanceData)
	    const Tk_ClassProcs *procs, ClientData instanceData)
}

# New in 8.4a4
#
declare 243 {
    void Tk_SetInternalBorderEx(Tk_Window tkwin, int left, int right,
	    int top, int bottom)
}
declare 244 {
    void Tk_SetMinimumRequestSize(Tk_Window tkwin,
	    int minWidth, int minHeight)
}

# New in 8.4a5
#
declare 245 {
    void Tk_SetCaretPos(Tk_Window tkwin, int x, int y, int height)
}
declare 246 {deprecated {function signature changed}} {
    void Tk_PhotoPutBlock_Panic(Tk_PhotoHandle handle,
	    Tk_PhotoImageBlock *blockPtr, int x, int y,
	    int width, int height, int compRule)
}
declare 247 {deprecated {function signature changed}} {
    void Tk_PhotoPutZoomedBlock_Panic(Tk_PhotoHandle handle,
	    Tk_PhotoImageBlock *blockPtr, int x, int y,
	    int width, int height, int zoomX, int zoomY,
	    int subsampleX, int subsampleY, int compRule)
}
declare 248 {
    int Tk_CollapseMotionEvents(Display *display, int collapse)
}

# Style engine
declare 249 {
927
928
929
930
931
932
933
934

935
936
937
938
939
940
941
942
943
944
945
946
947






948
949

950
951
952
953
954

955
956
957
958
959

960
961
962
963
964
965

966
967
968
969

970
971
972
973
974
975
976
971
972
973
974
975
976
977

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003

1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014

1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







-
+













+
+
+
+
+
+

-
+




-
+




-
+





-
+



-
+







	    Tk_ElementSpec *templatePtr)
}
declare 252 {
    int Tk_GetElementId(const char *name)
}
declare 253 {
    Tk_Style Tk_CreateStyle(const char *name, Tk_StyleEngine engine,
	    void *clientData)
	    ClientData clientData)
}
declare 254 {
    Tk_Style Tk_GetStyle(Tcl_Interp *interp, const char *name)
}
declare 255 {
    void Tk_FreeStyle(Tk_Style style)
}
declare 256 {
    const char *Tk_NameOfStyle(Tk_Style style)
}
declare 257 {
    Tk_Style  Tk_AllocStyleFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr)
}
declare 258 {
    Tk_Style Tk_GetStyleFromObj(Tcl_Obj *objPtr)
}
declare 259 {
    void  Tk_FreeStyleFromObj(Tcl_Obj *objPtr)
}
declare 260 {
    Tk_StyledElement Tk_GetStyledElement(Tk_Style style, Tcl_Size elementId,
    Tk_StyledElement Tk_GetStyledElement(Tk_Style style, int elementId,
	Tk_OptionTable optionTable)
}
declare 261 {
    void Tk_GetElementSize(Tk_Style style, Tk_StyledElement element,
	    void *recordPtr, Tk_Window tkwin, int width, int height,
	    char *recordPtr, Tk_Window tkwin, int width, int height,
	    int inner, int *widthPtr, int *heightPtr)
}
declare 262 {
    void Tk_GetElementBox(Tk_Style style, Tk_StyledElement element,
	    void *recordPtr, Tk_Window tkwin, int x, int y, int width,
	    char *recordPtr, Tk_Window tkwin, int x, int y, int width,
	    int height, int inner, int *xPtr, int *yPtr, int *widthPtr,
	    int *heightPtr)
}
declare 263 {
    int Tk_GetElementBorderWidth(Tk_Style style, Tk_StyledElement element,
	    void *recordPtr, Tk_Window tkwin)
	    char *recordPtr, Tk_Window tkwin)
}
declare 264 {
    void Tk_DrawElement(Tk_Style style, Tk_StyledElement element,
	    void *recordPtr, Tk_Window tkwin, Drawable d, int x, int y,
	    char *recordPtr, Tk_Window tkwin, Drawable d, int x, int y,
	    int width, int height, int state)
}

# TIP#116
declare 265 {
    int Tk_PhotoExpand(Tcl_Interp *interp, Tk_PhotoHandle handle,
	    int width, int height)
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029

1030
1031
1032
1033
1034








1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049

1050
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1048
1049
1050
1051
1052
1053
1054

1055





















1056



1057





1058
1059
1060
1061
1062
1063
1064
1065












1066

1067

1068








1069
1070











1071
1072
1073
1074
1075
1076
1077







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-

-
+
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-







}

# TIP #264
declare 271 {
    Tcl_Interp *Tk_Interp(Tk_Window tkwin)
}

# TIP#580
# Now that the Tk 8.2 -> 8.3 transition is long past, use more conventional
declare 274 {
    int Tk_AlwaysShowSelection(Tk_Window tkwin)
}
declare 275 {
    unsigned Tk_GetButtonMask(unsigned button)
}
declare 276 {
    int Tk_GetDoublePixelsFromObj(Tcl_Interp *interp, Tk_Window tkwin,
	    Tcl_Obj *objPtr, double *doublePtr)
}
declare 277 {
    Tcl_Obj *Tk_NewWindowObj(Tk_Window tkwin)
}
declare 278 {
    void Tk_SendVirtualEvent(Tk_Window tkwin, const char *eventName,
	    Tcl_Obj *detail)
}
declare 279 {
    Tcl_Obj *Tk_FontGetDescription(Tk_Font tkfont)
}

# means to continue support for extensions using the USE_OLD_IMAGE to
# TIP#529
declare 280 {
    void Tk_CreatePhotoImageFormatVersion3(
# continue use of their string-based Tcl_ImageTypes and Tcl_PhotoImageFormats.
	    const Tk_PhotoImageFormatVersion3 *formatPtr)
}

# TIP#606
declare 281 {
#
# Note that this restores the usual rules for stub compatibility.  Stub-enabled
# extensions compiled against 8.5 headers and linked to the 8.5 stub library
# will produce a file [load]able into an interp with Tk 8.X, for X >= 5.
# It will *not* be [load]able into interps with Tk 8.4 (or Tk 8.2!).
# Developers who need to produce a file [load]able into legacy interps must
# build against legacy sources.
declare 272 {
    void Tk_DrawHighlightBorder(Tk_Window tkwin, GC fgGC, GC bgGC,
	    int highlightWidth, Drawable drawable)
}
declare 282 {
    void Tk_SetMainMenubar(Tcl_Interp *interp, Tk_Window tkwin, const char *menuName)
}
declare 283 {
    void Tk_SetWindowMenubar(Tcl_Interp *interp, Tk_Window tkwin,
	    const char *oldMenuName, const char *menuName)
}
declare 284 {
    void Tk_ClipDrawableToRect(Display *display, Drawable d, int x,
    void Tk_CreateOldImageType(const Tk_ImageType *typePtr)
	    int y, int width, int height)
}
declare 285 {
declare 273 {
    Tcl_Obj *Tk_GetSystemDefault(Tk_Window tkwin,
	    const char *dbName, const char *className)
}
declare 286 {
    int Tk_UseWindow(Tcl_Interp *interp, Tk_Window tkwin, const char *string)
}
declare 287 {
    void Tk_MakeContainer(Tk_Window tkwin)
    void Tk_CreateOldPhotoImageFormat(const Tk_PhotoImageFormat *formatPtr)
}
declare 288 {
    Tk_Window Tk_GetOtherWindow(Tk_Window tkwin)
}
declare 289 {
    void Tk_Get3DBorderColors(Tk_3DBorder border, XColor *bgColorPtr, XColor *darkColorPtr,
	    XColor *lightColorPtr)
}
declare 290 {
    Window Tk_MakeWindow(Tk_Window tkwin, Window parent)
}


# Define the platform specific public Tk interface.  These functions are
# only available on the designated platform.

interface tkPlat

################################
1084
1085
1086
1087
1088
1089
1090


1091






1092
1093


















1094
1095
1096




1097
1098
1099
1100
1101
1102


1103

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129



1130
1131

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141














1142
1143
1144
1145
1146
1147
1148
1149
1150








1151
1152
1153
1154







+
+
-
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+
+
+
+



-
-
-
+
+
-
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
-
-
-
-
-
-




}
declare 2 win {
    HWND Tk_GetHWND(Window window)
}
declare 3 win {
    Tk_Window Tk_HWNDToWindow(HWND hwnd)
}
declare 4 win {
    void Tk_PointerEvent(HWND hwnd, int x, int y)

}
declare 5 win {
    int Tk_TranslateWinEvent(HWND hwnd,
	    UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result)
}

################################
# Aqua specific functions

declare 0 aqua {
    void Tk_MacOSXSetEmbedHandler(
	    Tk_MacOSXEmbedRegisterWinProc *registerWinProcPtr,
	    Tk_MacOSXEmbedGetGrafPortProc *getPortProcPtr,
	    Tk_MacOSXEmbedMakeContainerExistProc *containerExistProcPtr,
	    Tk_MacOSXEmbedGetClipProc *getClipProc,
	    Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc)
}
declare 1 aqua {
    void Tk_MacOSXTurnOffMenus(void)
}
declare 2 aqua {
    void Tk_MacOSXTkOwnsCursor(int tkOwnsIt)
}
declare 3 aqua {
    void TkMacOSXInitMenus(Tcl_Interp *interp)
}
declare 4 aqua {
    void TkMacOSXInitAppleEvents(Tcl_Interp *interp)
}
declare 5 aqua {
    void TkGenWMConfigureEvent(Tk_Window tkwin, int x, int y, int width,
	    int height, int flags)
}
declare 6 aqua {
    void TkMacOSXInvalClipRgns(Tk_Window tkwin)
}
# Stub removed because it just returned NULL.
#declare 7 aqua {
#    void *TkMacOSXGetDrawablePort(Drawable drawable)
declare 7 aqua {
    void *TkMacOSXGetDrawablePort(Drawable drawable)
#}
}
declare 8 aqua {
    void *TkMacOSXGetRootControl(Drawable drawable)
}
declare 9 aqua {
    void Tk_MacOSXSetupTkNotifier(void)
}
declare 10 aqua {
    int Tk_MacOSXIsAppInFront(void)
}
declare 11 aqua {
    Tk_Window Tk_MacOSXGetTkWindow(void *w)
}
declare 12 aqua {
    void *Tk_MacOSXGetCGContextForDrawable(Drawable drawable)
}
# Replaces TkMacOSXDrawable
declare 13 aqua {
    void *Tk_MacOSXGetNSWindowForDrawable(Drawable drawable)
}
declare 16 aqua {
    void TkGenWMConfigureEvent(Tk_Window tkwin, int x, int y, int width,
	    int height, int flags)
}

##############################################################################

# Public functions that are not accessible via the stubs table.

export {
    const char *Tk_PkgInitStubsCheck(Tcl_Interp *interp, const char *version,
	    int exact)
}
export {
    void Tk_MainEx(Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc,
	    Tcl_Interp *interp)
}
export {
    void Tk_MainExW(Tcl_Size argc, wchar_t **argv,
	    Tcl_AppInitProc *appInitProc, Tcl_Interp *interp);
}

# Local Variables:
# mode: tcl
# End:

Changes to generic/tk.h.

13
14
15
16
17
18
19
20
21


22
23







24
25
26
27
28
29
30
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37







-
-
+
+


+
+
+
+
+
+
+







 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TK
#define _TK

#include <tcl.h>
#if (TCL_MAJOR_VERSION < 8) || (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 7)
#	error Tk 9.0 must be compiled with tcl.h from Tcl 8.7 or better
#if (TCL_MAJOR_VERSION < 8) || (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 6)
#	error Tk 8.7 must be compiled with tcl.h from Tcl 8.6 or better
#endif

#ifndef CONST84
#   define CONST84 const
#   define CONST84_RETURN const
#endif
#ifndef CONST86
#   define CONST86 CONST84
#endif
#ifndef EXTERN
#   define EXTERN extern TCL_STORAGE_CLASS
#endif

/*
 * Utility macros: STRINGIFY takes an argument and wraps it in "" (double
 * quotation marks), JOIN joins two arguments.
61
62
63
64
65
66
67
68
69

70
71
72
73
74



75
76
77


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100

101


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
68
69
70
71
72
73
74


75





76
77
78
79


80
81

82
83
84
85
86
87
88
89
90
91
92
93
94

95



96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127

128
129
130
131
132
133

134
135
136
137
138
139
140
141







-
-
+
-
-
-
-
-
+
+
+

-
-
+
+
-













-
+
-
-
-





+
-
+
+
















-
+







-






-
+







 * unix/tk.spec		(1 LOC patch)
 * win/tcl.m4		(not patchlevel)
 *
 * You may also need to update some of these files when the numbers change for
 * the version of Tcl that this release of Tk is compiled against.
 */

#ifndef TK_MAJOR_VERSION
#   define TK_MAJOR_VERSION 9
#define TK_MAJOR_VERSION	8
#endif
#if TK_MAJOR_VERSION == 9
#   define TK_MINOR_VERSION	0
#   define TK_RELEASE_LEVEL	TCL_BETA_RELEASE
#   define TK_RELEASE_SERIAL	2
#define TK_MINOR_VERSION	7
#define TK_RELEASE_LEVEL	TCL_ALPHA_RELEASE
#define TK_RELEASE_SERIAL	0

#   define TK_VERSION		"9.0"
#   define TK_PATCH_LEVEL		"9.0b2"
#define TK_VERSION		"8.7"
#define TK_PATCH_LEVEL		"8.7a0"
#endif /* TK_MAJOR_VERSION */

/*
 * A special definition used to allow this header file to be included from
 * windows or mac resource files so that they can obtain version information.
 * RC_INVOKED is defined by default by the windows RC tool and manually set
 * for macintosh.
 *
 * Resource compilers don't like all the C stuff, like typedefs and procedure
 * declarations, that occur below, so block them out.
 */

#ifndef RC_INVOKED

#if !defined(_XLIB_H) && !defined(_X11_XLIB_H_)
#ifndef _XLIB_H
#if defined(__GNUC__) && !defined(__cplusplus)
#   pragma GCC diagnostic ignored "-Wc++-compat"
#endif
#   include <X11/Xlib.h>
#   ifdef MAC_OSX_TK
#	include <X11/X.h>
#   endif
#endif
#ifdef __STDC__
#include <stddef.h>
#   include <stddef.h>
#endif

#ifdef BUILD_tk
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS	DLLEXPORT
#else
# ifndef TCL_STORAGE_CLASS
#   define TCL_STORAGE_CLASS DLLIMPORT
# endif
#endif

/*
 *----------------------------------------------------------------------
 *
 * Decide whether or not to use input methods.
 */

#if defined(XNQueryInputStyle) && !defined(_WIN32) && !defined(MAC_OSX_TK)
#ifdef XNQueryInputStyle
#define TK_USE_INPUT_METHODS
#endif

/*
 * Dummy types that are used by clients:
 */

#define Tk_ImageMaster Tk_ImageModel
typedef struct Tk_BindingTable_ *Tk_BindingTable;
typedef struct Tk_Canvas_ *Tk_Canvas;
typedef struct Tk_Cursor_ *Tk_Cursor;
typedef struct Tk_ErrorHandler_ *Tk_ErrorHandler;
typedef struct Tk_Font_ *Tk_Font;
typedef struct Tk_Image__ *Tk_Image;
typedef struct Tk_ImageModel_ *Tk_ImageModel;
typedef struct Tk_ImageMaster_ *Tk_ImageMaster;
typedef struct Tk_OptionTable_ *Tk_OptionTable;
typedef struct Tk_PostscriptInfo_ *Tk_PostscriptInfo;
typedef struct Tk_TextLayout_ *Tk_TextLayout;
typedef struct Tk_Window_ *Tk_Window;
typedef struct Tk_3DBorder_ *Tk_3DBorder;
typedef struct Tk_Style_ *Tk_Style;
typedef struct Tk_StyleEngine_ *Tk_StyleEngine;
168
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203




204
205
206
207
208
209
210




211
212
213
214
215
216
217
169
170
171
172
173
174
175

176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

197
198
199




200
201
202
203
204
205
206




207
208
209
210
211
212
213
214
215
216
217







-
+
-




















-
+


-
-
-
-
+
+
+
+



-
-
-
-
+
+
+
+







    TK_OPTION_JUSTIFY,
    TK_OPTION_ANCHOR,
    TK_OPTION_SYNONYM,
    TK_OPTION_PIXELS,
    TK_OPTION_WINDOW,
    TK_OPTION_END,
    TK_OPTION_CUSTOM,
    TK_OPTION_STYLE,
    TK_OPTION_STYLE
    TK_OPTION_INDEX
} Tk_OptionType;

/*
 * Structures of the following type are used by widgets to specify their
 * configuration options. Typically each widget has a static array of these
 * structures, where each element of the array describes a single
 * configuration option. The array is passed to Tk_CreateOptionTable.
 */

typedef struct Tk_OptionSpec {
    Tk_OptionType type;		/* Type of option, such as TK_OPTION_COLOR;
				 * see definitions above. Last option in table
				 * must have type TK_OPTION_END. */
    const char *optionName;	/* Name used to specify option in Tcl
				 * commands. */
    const char *dbName;		/* Name for option in option database. */
    const char *dbClass;	/* Class for option in database. */
    const char *defValue;	/* Default value for option if not specified
				 * in command line, the option database, or
				 * the system. */
    Tcl_Size objOffset;		/* Where in record to store a Tcl_Obj * that
    int objOffset;		/* Where in record to store a Tcl_Obj * that
				 * holds the value of this option, specified
				 * as an offset in bytes from the start of the
				 * record. Use the offsetof macro to generate
				 * values for this. TCL_INDEX_NONE means don't
				 * store the Tcl_Obj in the record. */
    Tcl_Size internalOffset;		/* Where in record to store the internal
				 * record. Use the Tk_Offset macro to generate
				 * values for this. -1 means don't store the
				 * Tcl_Obj in the record. */
    int internalOffset;		/* Where in record to store the internal
				 * representation of the value of this option,
				 * such as an int or XColor *. This field is
				 * specified as an offset in bytes from the
				 * start of the record. Use the offsetof
				 * macro to generate values for it.
				 * TCL_INDEX_NONE means don't store the
				 * internal representation in the record. */
				 * start of the record. Use the Tk_Offset
				 * macro to generate values for it. -1 means
				 * don't store the internal representation in
				 * the record. */
    int flags;			/* Any combination of the values defined
				 * below. */
    const void *clientData;	/* An alternate place to put option-specific
				 * data. Used for the monochrome default value
				 * for colors, etc. */
    int typeMask;		/* An arbitrary bit mask defined by the class
				 * manager; typically bits correspond to
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246




247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268
269











270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
289

290
291
292
293
294
295





296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312

313
314
315
316
317
318
319
225
226
227
228
229
230
231


232
233
234
235
236
237
238

239
240




241
242
243
244
245

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293


294
295
296

297
298





299
300
301
302
303



304
305
306
307
308
309
310
311
312

313
314
315
316

317
318
319
320
321
322
323
324







-
-







-
+

-
-
-
-
+
+
+
+

-
+

















-
+



+
+
+
+
+
+
+
+
+
+
+















-
-
+


-
+

-
-
-
-
-
+
+
+
+
+
-
-
-









-
+



-
+







/*
 * Flag values for Tk_OptionSpec structures. These flags are shared by
 * Tk_ConfigSpec structures, so be sure to coordinate any changes carefully.
 */

#define TK_OPTION_NULL_OK		(1 << 0)
#define TK_OPTION_DONT_SET_DEFAULT	(1 << 3)
#define TK_OPTION_VAR(type)		((sizeof(type) < 2 * sizeof(int)) ? ((int)(sizeof(type)&(sizeof(int)-1))<<6) : (3<<6))
#define TK_OPTION_ENUM_VAR		TK_OPTION_VAR(Tk_OptionType)

/*
 * The following structure and function types are used by TK_OPTION_CUSTOM
 * options; the structure holds pointers to the functions needed by the Tk
 * option config code to handle a custom option.
 */

typedef int (Tk_CustomOptionSetProc) (void *clientData,
typedef int (Tk_CustomOptionSetProc) (ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj **value, char *widgRec,
	Tcl_Size offset, char *saveInternalPtr, int flags);
typedef Tcl_Obj *(Tk_CustomOptionGetProc) (void *clientData,
	Tk_Window tkwin, char *widgRec, Tcl_Size offset);
typedef void (Tk_CustomOptionRestoreProc) (void *clientData,
	int offset, char *saveInternalPtr, int flags);
typedef Tcl_Obj *(Tk_CustomOptionGetProc) (ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset);
typedef void (Tk_CustomOptionRestoreProc) (ClientData clientData,
	Tk_Window tkwin, char *internalPtr, char *saveInternalPtr);
typedef void (Tk_CustomOptionFreeProc) (void *clientData, Tk_Window tkwin,
typedef void (Tk_CustomOptionFreeProc) (ClientData clientData, Tk_Window tkwin,
	char *internalPtr);

typedef struct Tk_ObjCustomOption {
    const char *name;		/* Name of the custom option. */
    Tk_CustomOptionSetProc *setProc;
				/* Function to use to set a record's option
				 * value from a Tcl_Obj */
    Tk_CustomOptionGetProc *getProc;
				/* Function to use to get a Tcl_Obj
				 * representation from an internal
				 * representation of an option. */
    Tk_CustomOptionRestoreProc *restoreProc;
				/* Function to use to restore a saved value
				 * for the internal representation. */
    Tk_CustomOptionFreeProc *freeProc;
				/* Function to use to free the internal
				 * representation of an option. */
    void *clientData;	/* Arbitrary one-word value passed to the
    ClientData clientData;	/* Arbitrary one-word value passed to the
				 * handling procs. */
} Tk_ObjCustomOption;

/*
 * Macro to use to fill in "offset" fields of the Tk_OptionSpec structure.
 * Computes number of bytes from beginning of structure to a given field.
 */

#ifdef offsetof
#define Tk_Offset(type, field) ((int) offsetof(type, field))
#else
#define Tk_Offset(type, field) ((int) ((char *) &((type *) 0)->field))
#endif

/*
 * The following two structures are used for error handling. When config
 * options are being modified, the old values are saved in a Tk_SavedOptions
 * structure. If an error occurs, then the contents of the structure can be
 * used to restore all of the old values. The contents of this structure are
 * for the private use Tk. No-one outside Tk should ever read or write any of
 * the fields of these structures.
 */

typedef struct Tk_SavedOption {
    struct TkOption *optionPtr;	/* Points to information that describes the
				 * option. */
    Tcl_Obj *valuePtr;		/* The old value of the option, in the form of
				 * a Tcl object; may be NULL if the value was
				 * not saved as an object. */
#if TCL_MAJOR_VERSION > 8
    long double internalForm;	/* The old value of the option, in some
    double internalForm;	/* The old value of the option, in some
				 * internal representation such as an int or
				 * (XColor *). Valid only if the field
				 * optionPtr->specPtr->objOffset is -1. The
				 * optionPtr->specPtr->objOffset is < 0. The
				 * space must be large enough to accommodate a
				 * long double, a double, a long, or a pointer;
				 * right now it looks like a long double (i.e., 16
				 * bytes) is big enough. Also, using a long double
				 * guarantees that the field is properly aligned
				 * for storing large values. */
				 * double, a long, or a pointer; right now it
				 * looks like a double (i.e., 8 bytes) is big
				 * enough. Also, using a double guarantees
				 * that the field is properly aligned for
				 * storing large values. */
#else
    double internalForm;
#endif
} Tk_SavedOption;

#ifdef TCL_MEM_DEBUG
#   define TK_NUM_SAVED_OPTIONS 2
#else
#   define TK_NUM_SAVED_OPTIONS 20
#endif

typedef struct Tk_SavedOptions {
    void *recordPtr;		/* The data structure in which to restore
    char *recordPtr;		/* The data structure in which to restore
				 * configuration options. */
    Tk_Window tkwin;		/* Window associated with recordPtr; needed to
				 * restore certain options. */
    Tcl_Size numItems;		/* The number of valid items in items field. */
    int numItems;		/* The number of valid items in items field. */
    Tk_SavedOption items[TK_NUM_SAVED_OPTIONS];
				/* Items used to hold old values. */
    struct Tk_SavedOptions *nextPtr;
				/* Points to next structure in list; needed if
				 * too many options changed to hold all the
				 * old values in a single structure. NULL
				 * means no more structures. */
329
330
331
332
333
334
335
336
337
338
339




340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371


372
373
374
375
376

377
378
379
380
381
382
383
334
335
336
337
338
339
340




341
342
343
344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373
374


375
376
377
378
379
380

381
382
383
384
385
386
387
388







-
-
-
-
+
+
+
+








-
+















-
+





-
-
+
+




-
+







/*
 * This is a temporary flag used while tkObjConfig and new widgets are in
 * development.
 */

#ifndef __NO_OLD_CONFIG

typedef int (Tk_OptionParseProc) (void *clientData, Tcl_Interp *interp,
	Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset);
typedef const char *(Tk_OptionPrintProc) (void *clientData,
	Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr);
typedef int (Tk_OptionParseProc) (ClientData clientData, Tcl_Interp *interp,
	Tk_Window tkwin, CONST84 char *value, char *widgRec, int offset);
typedef CONST86 char *(Tk_OptionPrintProc) (ClientData clientData,
	Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr);

typedef struct Tk_CustomOption {
    Tk_OptionParseProc *parseProc;
				/* Procedure to call to parse an option and
				 * store it in converted form. */
    Tk_OptionPrintProc *printProc;
				/* Procedure to return a printable string
				 * describing an existing option. */
    void *clientData;	/* Arbitrary one-word value used by option
    ClientData clientData;	/* Arbitrary one-word value used by option
				 * parser: passed to parseProc and
				 * printProc. */
} Tk_CustomOption;

/*
 * Structure used to specify information for Tk_ConfigureWidget. Each
 * structure gives complete information for one option, including how the
 * option is specified on the command line, where it appears in the option
 * database, etc.
 */

typedef struct Tk_ConfigSpec {
    int type;			/* Type of option, such as TK_CONFIG_COLOR;
				 * see definitions below. Last option in table
				 * must have type TK_CONFIG_END. */
    const char *argvName;	/* Switch used to specify option in argv. NULL
    CONST86 char *argvName;	/* Switch used to specify option in argv. NULL
				 * means this spec is part of a group. */
    Tk_Uid dbName;		/* Name for option in option database. */
    Tk_Uid dbClass;		/* Class for option in database. */
    Tk_Uid defValue;		/* Default value for option if not specified
				 * in command line or database. */
    Tcl_Size offset;			/* Where in widget record to store value; use
				 * offsetof macro to generate values for
    int offset;			/* Where in widget record to store value; use
				 * Tk_Offset macro to generate values for
				 * this. */
    int specFlags;		/* Any combination of the values defined
				 * below; other bits are used internally by
				 * tkConfig.c. */
    const Tk_CustomOption *customPtr;
    CONST86 Tk_CustomOption *customPtr;
				/* If type is TK_CONFIG_CUSTOM then this is a
				 * pointer to info about how to parse and
				 * print the option. Otherwise it is
				 * irrelevant. */
} Tk_ConfigSpec;

/*
409
410
411
412
413
414
415



416
417
418
419
420
421
422
423
424

425
426
427

428
429

430
431

432
433
434
435
436
437
438
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

432
433
434

435
436

437
438

439
440
441
442
443
444
445
446







+
+
+








-
+


-
+

-
+

-
+







 * (internal-use-only flags are defined there).
 */

#define TK_CONFIG_NULL_OK		(1 << 0)
#define TK_CONFIG_COLOR_ONLY		(1 << 1)
#define TK_CONFIG_MONO_ONLY		(1 << 2)
#define TK_CONFIG_DONT_SET_DEFAULT	(1 << 3)
#if !defined(TK_NO_DEPRECATED) || defined(BUILD_tk)
#  define TK_CONFIG_OPTION_SPECIFIED      (1 << 4)
#endif
#define TK_CONFIG_USER_BIT		0x100
#endif /* __NO_OLD_CONFIG */

/*
 * Structure used to specify how to handle argv options.
 */

typedef struct {
    const char *key;		/* The key string that flags the option in the
    CONST86 char *key;		/* The key string that flags the option in the
				 * argv array. */
    int type;			/* Indicates option type; see below. */
    void *src;			/* Value to be used in setting dst; usage
    char *src;			/* Value to be used in setting dst; usage
				 * depends on type. */
    void *dst;			/* Address of value to be modified; usage
    char *dst;			/* Address of value to be modified; usage
				 * depends on type. */
    const char *help;		/* Documentation message describing this
    CONST86 char *help;		/* Documentation message describing this
				 * option. */
} Tk_ArgvInfo;

/*
 * Legal values for the type field of a Tk_ArgvInfo: see the user
 * documentation for details.
 */
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
517
518
519
520
521
522
523

524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540







-










-







#define TK_NOTIFY_SHARE		20

/*
 * Enumerated type for describing a point by which to anchor something:
 */

typedef enum {
    TK_ANCHOR_NULL = -1,
    TK_ANCHOR_N, TK_ANCHOR_NE, TK_ANCHOR_E, TK_ANCHOR_SE,
    TK_ANCHOR_S, TK_ANCHOR_SW, TK_ANCHOR_W, TK_ANCHOR_NW,
    TK_ANCHOR_CENTER
} Tk_Anchor;

/*
 * Enumerated type for describing a style of justification:
 */

typedef enum {
    TK_JUSTIFY_NULL = -1,
    TK_JUSTIFY_LEFT, TK_JUSTIFY_RIGHT, TK_JUSTIFY_CENTER
} Tk_Justify;

/*
 * The following structure is used by Tk_GetFontMetrics() to return
 * information about the properties of a Tk_Font.
 */
566
567
568
569
570
571
572
573
574


575
576
577
578

579
580
581
582
583
584
585
572
573
574
575
576
577
578


579
580
581
582
583

584
585
586
587
588
589
590
591







-
-
+
+



-
+








/*
 * Widget class procedures used to implement platform specific widget
 * behavior.
 */

typedef Window (Tk_ClassCreateProc) (Tk_Window tkwin, Window parent,
	void *instanceData);
typedef void (Tk_ClassWorldChangedProc) (void *instanceData);
	ClientData instanceData);
typedef void (Tk_ClassWorldChangedProc) (ClientData instanceData);
typedef void (Tk_ClassModalProc) (Tk_Window tkwin, XEvent *eventPtr);

typedef struct Tk_ClassProcs {
    Tcl_Size size;
    unsigned int size;
    Tk_ClassWorldChangedProc *worldChangedProc;
				/* Procedure to invoke when the widget needs
				 * to respond in some way to a change in the
				 * world (font changes, etc.) */
    Tk_ClassCreateProc *createProc;
				/* Procedure to invoke when the platform-
				 * dependent window needs to be created. */
596
597
598
599
600
601
602
603

604
605
606
607
608

609
610
611
612
613
614
615
616
617
618


619
620
621
622
623
624
625

626
627
628


629
630
631

632
633
634
635
636
637
638
602
603
604
605
606
607
608

609
610
611
612
613

614
615
616
617
618
619
620
621



622
623
624
625
626
627
628
629

630
631


632
633
634
635

636
637
638
639
640
641
642
643







-
+




-
+







-
-
-
+
+






-
+

-
-
+
+


-
+







 * (or NULL if the structure is NULL).
 *
 * A more general version of this function may be useful if other
 * size-versioned structure pop up in the future:
 *
 *	#define Tk_GetField(name, who, which) \
 *	    (((who) == NULL) ? NULL :
 *	    (((size_t)(who)->size <= offsetof(name, which)) ? NULL :(name)->which))
 *	    (((who)->size <= Tk_Offset(name, which)) ? NULL :(name)->which))
 */

#define Tk_GetClassProc(procs, which) \
    (((procs) == NULL) ? NULL : \
    (((size_t)(procs)->size <= offsetof(Tk_ClassProcs, which)) ? NULL:(procs)->which))
    (((procs)->size <= Tk_Offset(Tk_ClassProcs, which)) ? NULL:(procs)->which))

/*
 * Each geometry manager (the packer, the placer, etc.) is represented by a
 * structure of the following form, which indicates procedures to invoke in
 * the geometry manager to carry out certain functions.
 */

#define Tk_GeomLostSlaveProc Tk_GeomLostContentProc
typedef void (Tk_GeomRequestProc) (void *clientData, Tk_Window tkwin);
typedef void (Tk_GeomLostContentProc) (void *clientData, Tk_Window tkwin);
typedef void (Tk_GeomRequestProc) (ClientData clientData, Tk_Window tkwin);
typedef void (Tk_GeomLostSlaveProc) (ClientData clientData, Tk_Window tkwin);

typedef struct Tk_GeomMgr {
    const char *name;		/* Name of the geometry manager (command used
				 * to invoke it, or name of widget class that
				 * allows embedded widgets). */
    Tk_GeomRequestProc *requestProc;
				/* Procedure to invoke when a content's
				/* Procedure to invoke when a slave's
				 * requested geometry changes. */
    Tk_GeomLostContentProc *lostContentProc;
				/* Procedure to invoke when content is taken
    Tk_GeomLostSlaveProc *lostSlaveProc;
				/* Procedure to invoke when a slave is taken
				 * away from one geometry manager by another.
				 * NULL means geometry manager doesn't care
				 * when content lost. */
				 * when slaves are lost. */
} Tk_GeomMgr;

/*
 * Result values returned by Tk_GetScrollInfo:
 */

#define TK_SCROLL_MOVETO	1
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664
665
653
654
655
656
657
658
659


660
661

662
663
664
665
666
667
668







-
-
+

-







 *----------------------------------------------------------------------
 */

#define VirtualEvent	    (MappingNotify + 1)
#define ActivateNotify	    (MappingNotify + 2)
#define DeactivateNotify    (MappingNotify + 3)
#define MouseWheelEvent     (MappingNotify + 4)
#define TouchpadScroll      (MappingNotify + 5)
#define TK_LASTEVENT	    (MappingNotify + 6)
#define TK_LASTEVENT	    (MappingNotify + 5)

#define TouchpadScrollMask  (1L << 27)
#define MouseWheelMask	    (1L << 28)
#define ActivateMask	    (1L << 29)
#define VirtualEventMask    (1L << 30)

/*
 * A virtual event shares most of its fields with the XKeyEvent and
 * XButtonEvent structures. 99% of the time a virtual event will be an
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692







-
+







typedef struct {
    int type;
    unsigned long serial;	/* # of last request processed by server. */
    Bool send_event;		/* True if this came from a SendEvent
				 * request. */
    Display *display;		/* Display the event was read from. */
    Window event;		/* Window on which event was requested. */
    Window root;		/* Root window that the event occurred on. */
    Window root;		/* Root window that the event occured on. */
    Window subwindow;		/* Child window. */
    Time time;			/* Milliseconds. */
    int x, y;			/* Pointer x, y coordinates in event
				 * window. */
    int x_root, y_root;		/* Coordinates relative to root. */
    unsigned int state;		/* Key or button mask */
    Tk_Uid name;		/* Name of virtual event. */
745
746
747
748
749
750
751




752
753
754
755
756
757
758
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765







+
+
+
+







    (((Tk_FakeWin *) (tkwin))->flags & TK_WIN_MANAGED)
#define Tk_TopWinHierarchy(tkwin) \
    (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY)
#define Tk_IsManageable(tkwin) \
    (((Tk_FakeWin *) (tkwin))->flags & TK_WM_MANAGEABLE)
#define Tk_ReqWidth(tkwin)	(((Tk_FakeWin *) (tkwin))->reqWidth)
#define Tk_ReqHeight(tkwin)	(((Tk_FakeWin *) (tkwin))->reqHeight)
#ifndef TK_NO_DEPRECATED
#define Tk_InternalBorderWidth(tkwin) \
    (((Tk_FakeWin *) (tkwin))->internalBorderLeft)
#endif /* !TK_NO_DEPRECATED */
#define Tk_InternalBorderLeft(tkwin) \
    (((Tk_FakeWin *) (tkwin))->internalBorderLeft)
#define Tk_InternalBorderRight(tkwin) \
    (((Tk_FakeWin *) (tkwin))->internalBorderRight)
#define Tk_InternalBorderTop(tkwin) \
    (((Tk_FakeWin *) (tkwin))->internalBorderTop)
#define Tk_InternalBorderBottom(tkwin) \
789
790
791
792
793
794
795
796

797
798
799
800
801



802
803
804

805
806
807
808
809

810
811
812
813
814
815
816
817
818


819
820
821
822
823

824
825
826
827
828
829
830
796
797
798
799
800
801
802

803
804
805



806
807
808
809
810

811
812
813
814
815

816
817
818
819
820
821
822



823
824





825
826
827
828
829
830
831
832







-
+


-
-
-
+
+
+


-
+




-
+






-
-
-
+
+
-
-
-
-
-
+







    Tk_Uid classUid;
    XWindowChanges changes;
    unsigned int dummy6;	/* dirtyChanges */
    XSetWindowAttributes atts;
    unsigned long dummy7;	/* dirtyAtts */
    unsigned int flags;
    char *dummy8;		/* handlerList */
#if defined(TK_USE_INPUT_METHODS) || (TCL_MAJOR_VERSION > 8)
#ifdef TK_USE_INPUT_METHODS
    XIC dummy9;			/* inputContext */
#endif /* TK_USE_INPUT_METHODS */
    void **dummy10;	/* tagPtr */
    Tcl_Size dummy11;		/* numTags */
    Tcl_Size dummy12;		/* optionLevel */
    ClientData *dummy10;	/* tagPtr */
    int dummy11;		/* numTags */
    int dummy12;		/* optionLevel */
    char *dummy13;		/* selHandlerList */
    char *dummy14;		/* geomMgrPtr */
    void *dummy15;		/* geomData */
    ClientData dummy15;		/* geomData */
    int reqWidth, reqHeight;
    int internalBorderLeft;
    char *dummy16;		/* wmInfoPtr */
    char *dummy17;		/* classProcPtr */
    void *dummy18;		/* instanceData */
    ClientData dummy18;		/* instanceData */
    char *dummy19;		/* privatePtr */
    int internalBorderRight;
    int internalBorderTop;
    int internalBorderBottom;
    int minReqWidth;
    int minReqHeight;
#if defined(TK_USE_INPUT_METHODS) || (TCL_MAJOR_VERSION > 8)
    int dummy20;
#endif /* TK_USE_INPUT_METHODS */
    char *dummy20;		/* geometryMaster */
#ifdef TK_USE_INPUT_METHODS
    char *dummy21;		/* geomMgrName */
    Tk_Window dummy22;		/* maintainerPtr */
#if !defined(TK_USE_INPUT_METHODS) && (TCL_MAJOR_VERSION < 9)
    XIC dummy9;			/* inputContext */
    int dummy20;
    int dummy21;
#endif /* TK_USE_INPUT_METHODS */
} Tk_FakeWin;

/*
 * Flag values for TkWindow (and Tk_FakeWin) structures are:
 *
 * TK_MAPPED:			1 means window is currently mapped,
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932

933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948

949
950
951
952
953
954
955
956
957
958

959
960

961
962
963
964
965
966
967
885
886
887
888
889
890
891




892
893
894
895
896
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
912

913
914
915
916
917
918
919
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951
952
953

954
955

956
957
958
959
960
961
962
963







-
-
-
-













-








-















-
+















-
+









-
+

-
+







 *				window's parent either doesn't exist or is not
 *				owned by this Tk application.
 * TK_PROP_PROPCHANGE		1 means that PropertyNotify events in the
 *				window's children should propagate up to this
 *				window.
 * TK_WM_MANAGEABLE		1 marks a window as capable of being converted
 *				into a toplevel using [wm manage].
 * TK_CAN_INPUT_TEXT            1 means that this window accepts text input.
 *                              Used on macOS to indicate that key events can be
 *                              processed with the NSTextInputClient protocol.
 *                              Not currently accessible through the public API.
 */

#define TK_MAPPED		1
#define TK_TOP_LEVEL		2
#define TK_ALREADY_DEAD		4
#define TK_NEED_CONFIG_NOTIFY	8
#define TK_GRAB_FLAG		0x10
#define TK_CHECKED_IC		0x20
#define TK_DONT_DESTROY_WINDOW	0x40
#define TK_WM_COLORMAP_WINDOW	0x80
#define TK_EMBEDDED		0x100
#define TK_CONTAINER		0x200
#define TK_BOTH_HALVES		0x400

#define TK_WRAPPER		0x1000
#define TK_REPARENTED		0x2000
#define TK_ANONYMOUS_WINDOW	0x4000
#define TK_HAS_WRAPPER		0x8000
#define TK_WIN_MANAGED		0x10000
#define TK_TOP_HIERARCHY	0x20000
#define TK_PROP_PROPCHANGE	0x40000
#define TK_WM_MANAGEABLE	0x80000
#define TK_CAN_INPUT_TEXT       0x100000

/*
 *----------------------------------------------------------------------
 *
 * Procedure prototypes and structures used for defining new canvas items:
 *
 *----------------------------------------------------------------------
 */

typedef enum {
    TK_STATE_NULL = -1, TK_STATE_ACTIVE, TK_STATE_DISABLED,
    TK_STATE_NORMAL, TK_STATE_HIDDEN
} Tk_State;

typedef struct Tk_SmoothMethod {
    const char *name;
    CONST86 char *name;
    int (*coordProc) (Tk_Canvas canvas, double *pointPtr, int numPoints,
	    int numSteps, XPoint xPoints[], double dblPoints[]);
    void (*postscriptProc) (Tcl_Interp *interp, Tk_Canvas canvas,
	    double *coordPtr, int numPoints, int numSteps);
} Tk_SmoothMethod;

/*
 * For each item in a canvas widget there exists one record with the following
 * structure. Each actual item is represented by a record with the following
 * stuff at its beginning, plus additional type-specific stuff after that.
 */

#define TK_TAG_SPACE 3

typedef struct Tk_Item {
    Tcl_Size id;		/* Unique identifier for this item (also
    int id;			/* Unique identifier for this item (also
				 * serves as first tag for item). */
    struct Tk_Item *nextPtr;	/* Next in display list of all items in this
				 * canvas. Later items in list are drawn on
				 * top of earlier ones. */
    Tk_Uid staticTagSpace[TK_TAG_SPACE];
				/* Built-in space for limited # of tags. */
    Tk_Uid *tagPtr;		/* Pointer to array of tags. Usually points to
				 * staticTagSpace, but may point to malloc-ed
				 * space if there are lots of tags. */
    Tcl_Size tagSpace;		/* Total amount of tag space available at
    int tagSpace;		/* Total amount of tag space available at
				 * tagPtr. */
    Tcl_Size numTags;		/* Number of tag slots actually used at
    int numTags;		/* Number of tag slots actually used at
				 * *tagPtr. */
    struct Tk_ItemType *typePtr;/* Table of procedures that implement this
				 * type of item. */
    int x1, y1, x2, y2;		/* Bounding box for item, in integer canvas
				 * units. Set by item-specific code and
				 * guaranteed to contain every pixel drawn in
				 * item. Item area includes x1 and y1 but not
997
998
999
1000
1001
1002
1003

1004
1005

1006
1007
1008

1009



1010
1011
1012
1013
1014







1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032







1033
1034
1035
1036










1037
1038

1039
1040
1041
1042
1043

1044
1045

1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063



1064
1065
1066
1067
1068
1069
1070
993
994
995
996
997
998
999
1000
1001

1002
1003


1004
1005
1006
1007
1008





1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026


1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055

1056
1057

1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075

1076
1077
1078
1079
1080
1081
1082
1083
1084
1085







+

-
+

-
-
+

+
+
+
-
-
-
-
-
+
+
+
+
+
+
+











-
-





+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+

-
+




-
+

-
+




-
+












-
+
+
+







#define TK_ITEM_DONT_REDRAW		2

/*
 * Records of the following type are used to describe a type of item (e.g.
 * lines, circles, etc.) that can form part of a canvas widget.
 */

#ifdef USE_OLD_CANVAS
typedef int	(Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
		    Tk_Item *itemPtr, int argc, char **argv);
typedef int	(Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[],
		    int flags);
		    Tk_Item *itemPtr, int argc, char **argv, int flags);
typedef int	(Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, int argc, char **argv);
#else
typedef int	(Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
typedef void	(Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Tcl_Size beforeThis, Tcl_Obj *string);
typedef int	(Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, Tcl_Obj *indexString, Tcl_Size *indexPtr);
		    Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[]);
typedef int	(Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[],
		    int flags);
typedef int	(Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, int argc, Tcl_Obj *const argv[]);
#endif /* USE_OLD_CANVAS */
typedef void	(Tk_ItemDeleteProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Display *display);
typedef void	(Tk_ItemDisplayProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Display *display, Drawable dst, int x, int y, int width,
		    int height);
typedef double	(Tk_ItemPointProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    double *pointPtr);
typedef int	(Tk_ItemAreaProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    double *rectPtr);
typedef int	(Tk_ItemPostscriptProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, int prepass);
typedef void	(Tk_ItemRotateProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    double originX, double originY, double angleRadians);
typedef void	(Tk_ItemScaleProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    double originX, double originY, double scaleX,
		    double scaleY);
typedef void	(Tk_ItemTranslateProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    double deltaX, double deltaY);
#ifdef USE_OLD_CANVAS
typedef int	(Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, char *indexString, int *indexPtr);
#else
typedef int	(Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas,
		    Tk_Item *itemPtr, Tcl_Obj *indexString, int *indexPtr);
#endif /* USE_OLD_CANVAS */
typedef void	(Tk_ItemCursorProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Tcl_Size index);
typedef Tcl_Size (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
		    int index);
typedef int	(Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    int offset, char *buffer, int maxBytes);
#ifdef USE_OLD_CANVAS
typedef void	(Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    int beforeThis, char *string);
#else
typedef void	(Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    int beforeThis, Tcl_Obj *string);
#endif /* USE_OLD_CANVAS */
typedef void	(Tk_ItemDCharsProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
		    Tcl_Size first, Tcl_Size last);
		    int first, int last);

#ifndef __NO_OLD_CONFIG

typedef struct Tk_ItemType {
    const char *name;		/* The name of this type of item, such as
    CONST86 char *name;		/* The name of this type of item, such as
				 * "line". */
    Tcl_Size itemSize;		/* Total amount of space needed for item's
    int itemSize;		/* Total amount of space needed for item's
				 * record. */
    Tk_ItemCreateProc *createProc;
				/* Procedure to create a new item of this
				 * type. */
    const Tk_ConfigSpec *configSpecs; /* Pointer to array of configuration specs for
    CONST86 Tk_ConfigSpec *configSpecs; /* Pointer to array of configuration specs for
				 * this type. Used for returning configuration
				 * info. */
    Tk_ItemConfigureProc *configProc;
				/* Procedure to call to change configuration
				 * options. */
    Tk_ItemCoordProc *coordProc;/* Procedure to call to get and set the item's
				 * coordinates. */
    Tk_ItemDeleteProc *deleteProc;
				/* Procedure to delete existing item of this
				 * type. */
    Tk_ItemDisplayProc *displayProc;
				/* Procedure to display items of this type. */
    int flags;		/* Combination of TK_ALWAYS_REDRAW/TK_MOVABLE_POINTS */
    int alwaysRedraw;		/* Non-zero means displayProc should be called
				 * even when the item has been moved
				 * off-screen. */
    Tk_ItemPointProc *pointProc;/* Computes distance from item to a given
				 * point. */
    Tk_ItemAreaProc *areaProc;	/* Computes whether item is inside, outside,
				 * or overlapping an area. */
    Tk_ItemPostscriptProc *postscriptProc;
				/* Procedure to write a Postscript description
				 * for items of this type. */
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100


1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1099
1100
1101
1102
1103
1104
1105



1106
1107
1108
1109
1110
1111
1112

1113
1114
1115
1116


1117
1118
1119
1120
1121
1122
1123
1124







-
-
-
+






-
+
+


-
-
+







    Tk_ItemInsertProc *insertProc;
				/* Procedure to insert something into an
				 * item. */
    Tk_ItemDCharsProc *dCharsProc;
				/* Procedure to delete characters from an
				 * item. */
    struct Tk_ItemType *nextPtr;/* Used to link types together into a list. */
    Tk_ItemRotateProc *rotateProc;
				/* Procedure to rotate an item's coordinates
				 * about a point. */
    char *reserved1;		/* Reserved for future extension. */
    int reserved2;		/* Carefully compatible with */
    char *reserved3;		/* Jan Nijtmans dash patch */
    char *reserved4;
} Tk_ItemType;

/*
 * Possible flags for 'flags' field.
 * Flag (used in the alwaysRedraw field) to say whether an item supports
 * point-level manipulation like the line and polygon items.
 */

#define TK_ALWAYS_REDRAW	1	/* item should be redrawn always*/
#define TK_MOVABLE_POINTS	2	/* item supports point-level manipulation */
#define TK_MOVABLE_POINTS	2

#endif /* __NO_OLD_CONFIG */

/*
 * The following structure provides information about the selection and the
 * insertion cursor. It is needed by only a few items, such as those that
 * display text. It is shared by the generic canvas code and the item-specific
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128

1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1132
1133
1134
1135
1136
1137
1138

1139
1140

1141
1142
1143
1144
1145

1146
1147
1148
1149
1150
1151
1152
1153







-
+

-
+




-
+







    int selBorderWidth;		/* Width of border around selection. Read-only
				 * to items. */
    XColor *selFgColorPtr;	/* Foreground color for selected text.
				 * Read-only to items. */
    Tk_Item *selItemPtr;	/* Pointer to selected item. NULL means
				 * selection isn't in this canvas. Writable by
				 * items. */
    Tcl_Size selectFirst;		/* Character index of first selected
    int selectFirst;		/* Character index of first selected
				 * character. Writable by items. */
    Tcl_Size selectLast;		/* Character index of last selected character.
    int selectLast;		/* Character index of last selected character.
				 * Writable by items. */
    Tk_Item *anchorItemPtr;	/* Item corresponding to "selectAnchor": not
				 * necessarily selItemPtr. Read-only to
				 * items. */
    Tcl_Size selectAnchor;		/* Character index of fixed end of selection
    int selectAnchor;		/* Character index of fixed end of selection
				 * (i.e. "select to" operation will use this
				 * as one end of the selection). Writable by
				 * items. */
    Tk_3DBorder insertBorder;	/* Used to draw vertical bar for insertion
				 * cursor. Read-only to items. */
    int insertWidth;		/* Total width of insertion cursor. Read-only
				 * to items. */
1164
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191







-
+







typedef struct Tk_TSOffset {
    int flags;			/* Flags; see below for possible values */
    int xoffset;		/* x offset */
    int yoffset;		/* y offset */
} Tk_TSOffset;

/*
 * Bit fields in Tk_TSOffset->flags:
 * Bit fields in Tk_Offset->flags:
 */

#define TK_OFFSET_INDEX		1
#define TK_OFFSET_RELATIVE	2
#define TK_OFFSET_LEFT		4
#define TK_OFFSET_CENTER	8
#define TK_OFFSET_RIGHT		16
1208
1209
1210
1211
1212
1213
1214

1215
1216
1217
1218
1219










1220
1221
1222
1223
1224



1225
1226

1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1221
1222
1223
1224
1225
1226
1227
1228





1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240



1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257

1258
1259
1260
1261
1262
1263
1264
1265







+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+

-
+












-
+







 *
 * Procedure prototypes and structures used for managing images:
 *
 *----------------------------------------------------------------------
 */

typedef struct Tk_ImageType Tk_ImageType;
#ifdef USE_OLD_IMAGE
typedef int (Tk_ImageCreateProc) (Tcl_Interp *interp, const char *name, Tcl_Size objc,
	Tcl_Obj *const objv[], const Tk_ImageType *typePtr, Tk_ImageModel model,
	void **clientDataPtr);
typedef void *(Tk_ImageGetProc) (Tk_Window tkwin, void *clientData);
typedef void (Tk_ImageDisplayProc) (void *clientData, Display *display,
typedef int (Tk_ImageCreateProc) (Tcl_Interp *interp, char *name, int argc,
	char **argv, Tk_ImageType *typePtr, Tk_ImageMaster master,
	ClientData *masterDataPtr);
#else
typedef int (Tk_ImageCreateProc) (Tcl_Interp *interp, CONST86 char *name, int objc,
	Tcl_Obj *const objv[], CONST86 Tk_ImageType *typePtr, Tk_ImageMaster master,
	ClientData *masterDataPtr);
#endif /* USE_OLD_IMAGE */
typedef ClientData (Tk_ImageGetProc) (Tk_Window tkwin, ClientData masterData);
typedef void (Tk_ImageDisplayProc) (ClientData instanceData, Display *display,
	Drawable drawable, int imageX, int imageY, int width, int height,
	int drawableX, int drawableY);
typedef void (Tk_ImageFreeProc) (void *clientData, Display *display);
typedef void (Tk_ImageDeleteProc) (void *clientData);
typedef void (Tk_ImageChangedProc) (void *clientData, int x, int y,
typedef void (Tk_ImageFreeProc) (ClientData instanceData, Display *display);
typedef void (Tk_ImageDeleteProc) (ClientData masterData);
typedef void (Tk_ImageChangedProc) (ClientData clientData, int x, int y,
	int width, int height, int imageWidth, int imageHeight);
typedef int (Tk_ImagePostscriptProc) (void *clientData,
typedef int (Tk_ImagePostscriptProc) (ClientData clientData,
	Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo,
	int x, int y, int width, int height, int prepass);

/*
 * The following structure represents a particular type of image (bitmap, xpm
 * image, etc.). It provides information common to all images of that type,
 * such as the type name and a collection of procedures in the image manager
 * that respond to various events. Each image manager is represented by one of
 * these structures.
 */

struct Tk_ImageType {
    const char *name;		/* Name of image type. */
    CONST86 char *name;		/* Name of image type. */
    Tk_ImageCreateProc *createProc;
				/* Procedure to call to create a new image of
				 * this type. */
    Tk_ImageGetProc *getProc;	/* Procedure to call the first time
				 * Tk_GetImage is called in a new way (new
				 * visual or screen). */
    Tk_ImageDisplayProc *displayProc;
1305
1306
1307
1308
1309
1310
1311
















1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360

1361





























1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1377







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
+








/*
 * Procedure prototypes and structures used in reading and writing photo
 * images:
 */

typedef struct Tk_PhotoImageFormat Tk_PhotoImageFormat;
#ifdef USE_OLD_IMAGE
typedef int (Tk_ImageFileMatchProc) (Tcl_Channel chan, char *fileName,
	char *formatString, int *widthPtr, int *heightPtr);
typedef int (Tk_ImageStringMatchProc) (char *string, char *formatString,
	int *widthPtr, int *heightPtr);
typedef int (Tk_ImageFileReadProc) (Tcl_Interp *interp, Tcl_Channel chan,
	char *fileName, char *formatString, Tk_PhotoHandle imageHandle,
	int destX, int destY, int width, int height, int srcX, int srcY);
typedef int (Tk_ImageStringReadProc) (Tcl_Interp *interp, char *string,
	char *formatString, Tk_PhotoHandle imageHandle, int destX, int destY,
	int width, int height, int srcX, int srcY);
typedef int (Tk_ImageFileWriteProc) (Tcl_Interp *interp, char *fileName,
	char *formatString, Tk_PhotoImageBlock *blockPtr);
typedef int (Tk_ImageStringWriteProc) (Tcl_Interp *interp,
	Tcl_DString *dataPtr, char *formatString, Tk_PhotoImageBlock *blockPtr);
#else
typedef int (Tk_ImageFileMatchProc) (Tcl_Channel chan, const char *fileName,
	Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp);
typedef int (Tk_ImageStringMatchProc) (Tcl_Obj *dataObj, Tcl_Obj *format,
	int *widthPtr, int *heightPtr, Tcl_Interp *interp);
typedef int (Tk_ImageFileReadProc) (Tcl_Interp *interp, Tcl_Channel chan,
	const char *fileName, Tcl_Obj *format, Tk_PhotoHandle imageHandle,
	int destX, int destY, int width, int height, int srcX, int srcY);
typedef int (Tk_ImageStringReadProc) (Tcl_Interp *interp, Tcl_Obj *dataObj,
	Tcl_Obj *format, Tk_PhotoHandle imageHandle, int destX, int destY,
	int width, int height, int srcX, int srcY);
typedef int (Tk_ImageFileWriteProc) (Tcl_Interp *interp, const char *fileName,
	Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
typedef int (Tk_ImageStringWriteProc) (Tcl_Interp *interp, Tcl_Obj *format,
	Tk_PhotoImageBlock *blockPtr);

#endif /* USE_OLD_IMAGE */
/*
 * The following alternate definitions are used with the Tk8.7 file format
 * supporting a metadata dict, internal dstring and close file flag
 */

typedef struct Tk_PhotoImageFormatVersion3 Tk_PhotoImageFormatVersion3;
typedef int (Tk_ImageFileMatchProcVersion3) (Tcl_Interp *interp,
	Tcl_Channel chan, const char *fileName, Tcl_Obj *format,
	Tcl_Obj *metadataIn, int *widthPtr, int *heightPtr,
	Tcl_Obj *metadataOut);
typedef int (Tk_ImageStringMatchProcVersion3) (Tcl_Interp *interp,
	Tcl_Obj *dataObj, Tcl_Obj *format, Tcl_Obj *metadataIn, int *widthPtr,
	int *heightPtr, Tcl_Obj *metadataOut);
typedef int (Tk_ImageFileReadProcVersion3) (Tcl_Interp *interp,
	Tcl_Channel chan,
	const char *fileName, Tcl_Obj *format, Tcl_Obj *metadataIn,
	Tk_PhotoHandle imageHandle,
	int destX, int destY, int width, int height, int srcX, int srcY,
	Tcl_Obj *metadataOut);
typedef int (Tk_ImageStringReadProcVersion3) (Tcl_Interp *interp,
	Tcl_Obj *dataObj, Tcl_Obj *format, Tcl_Obj *metadataIn,
	Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height,
	int srcX, int srcY, Tcl_Obj *metadataOut);
typedef int (Tk_ImageFileWriteProcVersion3) (Tcl_Interp *interp,
	const char *fileName, Tcl_Obj *format, Tcl_Obj *metadataIn,
	Tk_PhotoImageBlock *blockPtr);
typedef int (Tk_ImageStringWriteProcVersion3) (Tcl_Interp *interp,
	Tcl_Obj *format, Tcl_Obj *metadataIn, Tk_PhotoImageBlock *blockPtr);


/*
 * The following structure represents a particular file format for storing
 * images (e.g., PPM, GIF, JPEG, etc.). It provides information to allow image
 * files of that format to be recognized and read into a photo image.
 */

struct Tk_PhotoImageFormat {
    const char *name;		/* Name of image file format */
    CONST86 char *name;		/* Name of image file format */
    Tk_ImageFileMatchProc *fileMatchProc;
				/* Procedure to call to determine whether an
				 * image file matches this format. */
    Tk_ImageStringMatchProc *stringMatchProc;
				/* Procedure to call to determine whether the
				 * data in a string matches this format. */
    Tk_ImageFileReadProc *fileReadProc;
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1385
1386
1387
1388
1389
1390
1391
































1392
1393
1394
1395
1396
1397
1398







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







				 * photo image to a file. */
    Tk_ImageStringWriteProc *stringWriteProc;
				/* Procedure to call to obtain a string
				 * representation of the data in a photo
				 * image.*/
    struct Tk_PhotoImageFormat *nextPtr;
				/* Next in list of all photo image formats
				 * currently known. Filled in by Tk, not by
				 * image format handler. */
};

/*
 * The following structure is the same plus added support for the metadata
 * structure.
 */

struct Tk_PhotoImageFormatVersion3 {
    const char *name;		/* Name of image file format */
    Tk_ImageFileMatchProcVersion3 *fileMatchProc;
				/* Procedure to call to determine whether an
				 * image file matches this format. */
    Tk_ImageStringMatchProcVersion3 *stringMatchProc;
				/* Procedure to call to determine whether the
				 * data in a string matches this format. */
    Tk_ImageFileReadProcVersion3 *fileReadProc;
				/* Procedure to call to read data from an
				 * image file into a photo image. */
    Tk_ImageStringReadProcVersion3 *stringReadProc;
				/* Procedure to call to read data from a
				 * string into a photo image. */
    Tk_ImageFileWriteProcVersion3 *fileWriteProc;
				/* Procedure to call to write data from a
				 * photo image to a file. */
    Tk_ImageStringWriteProcVersion3 *stringWriteProc;
				/* Procedure to call to obtain a string
				 * representation of the data in a photo
				 * image.*/
    struct Tk_PhotoImageFormatVersion3 *nextPtr;
				/* Next in list of all photo image formats
				 * currently known. Filled in by Tk, not by
				 * image format handler. */
};

/*
 *----------------------------------------------------------------------
 *
1435
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445

1446
1447
1448
1449

1450
1451

1452
1453
1454
1455
1456
1457
1458
1409
1410
1411
1412
1413
1414
1415

1416
1417
1418

1419
1420
1421
1422

1423
1424

1425
1426
1427
1428
1429
1430
1431
1432







-
+


-
+



-
+

-
+







#define TK_STYLE_VERSION        TK_STYLE_VERSION_1

/*
 * The following structures and prototypes are used as static templates to
 * declare widget elements.
 */

typedef void (Tk_GetElementSizeProc) (void *clientData, char *recordPtr,
typedef void (Tk_GetElementSizeProc) (ClientData clientData, char *recordPtr,
	const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, int width,
	int height, int inner, int *widthPtr, int *heightPtr);
typedef void (Tk_GetElementBoxProc) (void *clientData, char *recordPtr,
typedef void (Tk_GetElementBoxProc) (ClientData clientData, char *recordPtr,
	const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, int x, int y,
	int width, int height, int inner, int *xPtr, int *yPtr, int *widthPtr,
	int *heightPtr);
typedef int (Tk_GetElementBorderWidthProc) (void *clientData,
typedef int (Tk_GetElementBorderWidthProc) (ClientData clientData,
	char *recordPtr, const Tk_OptionSpec **optionsPtr, Tk_Window tkwin);
typedef void (Tk_DrawElementProc) (void *clientData, char *recordPtr,
typedef void (Tk_DrawElementProc) (ClientData clientData, char *recordPtr,
	const Tk_OptionSpec **optionsPtr, Tk_Window tkwin, Drawable d, int x,
	int y, int width, int height, int state);

typedef struct Tk_ElementOptionSpec {
    char *name;			/* Name of the required option. */
    Tk_OptionType type;		/* Accepted option type. TK_OPTION_END means
				 * any. */
1487
1488
1489
1490
1491
1492
1493
1494


1495
1496
1497


































1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515


1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527



1528
1529
1530
1531
1532




1533
1534
1535


1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546


















































1547
1548
1549
1550
1551
1552
1553
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535



1536
1537
1538
1539




1540
1541
1542
1543
1544


1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614







-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















+
+









-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+











+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#define TK_ELEMENT_STATE_FOCUS          1<<2
#define TK_ELEMENT_STATE_PRESSED        1<<3

/*
 *----------------------------------------------------------------------
 *
 * The definitions below provide backward compatibility for functions and
 * types that used to be in Tk but have moved to Tcl.
 * types related to event handling that used to be in Tk but have moved to
 * Tcl.
 *
 *----------------------------------------------------------------------
 */

#define TK_READABLE		TCL_READABLE
#define TK_WRITABLE		TCL_WRITABLE
#define TK_EXCEPTION		TCL_EXCEPTION

#define TK_DONT_WAIT		TCL_DONT_WAIT
#define TK_X_EVENTS		TCL_WINDOW_EVENTS
#define TK_WINDOW_EVENTS	TCL_WINDOW_EVENTS
#define TK_FILE_EVENTS		TCL_FILE_EVENTS
#define TK_TIMER_EVENTS		TCL_TIMER_EVENTS
#define TK_IDLE_EVENTS		TCL_IDLE_EVENTS
#define TK_ALL_EVENTS		TCL_ALL_EVENTS

#define Tk_IdleProc		Tcl_IdleProc
#define Tk_FileProc		Tcl_FileProc
#define Tk_TimerProc		Tcl_TimerProc
#define Tk_TimerToken		Tcl_TimerToken

#define Tk_BackgroundError	Tcl_BackgroundError
#define Tk_CancelIdleCall	Tcl_CancelIdleCall
#define Tk_CreateFileHandler	Tcl_CreateFileHandler
#define Tk_CreateTimerHandler	Tcl_CreateTimerHandler
#define Tk_DeleteFileHandler	Tcl_DeleteFileHandler
#define Tk_DeleteTimerHandler	Tcl_DeleteTimerHandler
#define Tk_DoOneEvent		Tcl_DoOneEvent
#define Tk_DoWhenIdle		Tcl_DoWhenIdle
#define Tk_Sleep		Tcl_Sleep

/* Additional stuff that has moved to Tcl: */

#define Tk_EventuallyFree	Tcl_EventuallyFree
#define Tk_FreeProc		Tcl_FreeProc
#define Tk_Preserve		Tcl_Preserve
#define Tk_Release		Tcl_Release

/* Removed Tk_Main, use macro instead */
#if defined(_WIN32) || defined(__CYGWIN__)
#define Tk_Main(argc, argv, proc) Tk_MainEx(argc, argv, proc, \
	(Tcl_FindExecutable(0), (Tcl_CreateInterp)()))
#else
#define Tk_Main(argc, argv, proc) Tk_MainEx(argc, argv, proc, \
	(Tcl_FindExecutable(argv[0]), (Tcl_CreateInterp)()))
#endif
const char *		Tk_InitStubs(Tcl_Interp *interp, const char *version,
				int exact);
EXTERN const char *	Tk_PkgInitStubsCheck(Tcl_Interp *interp,
				const char *version, int exact);

#ifndef USE_TK_STUBS
#define Tk_InitStubs(interp, version, exact) \
    Tk_PkgInitStubsCheck(interp, version, exact)
#endif /* USE_TK_STUBS */

#define Tk_InitImageArgs(interp, argc, argv) /**/

/*
 *----------------------------------------------------------------------
 *
 * Additional procedure types defined by Tk.
 *
 *----------------------------------------------------------------------
 */

typedef int (Tk_ErrorProc) (void *clientData, XErrorEvent *errEventPtr);
typedef void (Tk_EventProc) (void *clientData, XEvent *eventPtr);
typedef int (Tk_GenericProc) (void *clientData, XEvent *eventPtr);
typedef int (Tk_ErrorProc) (ClientData clientData, XErrorEvent *errEventPtr);
typedef void (Tk_EventProc) (ClientData clientData, XEvent *eventPtr);
typedef int (Tk_GenericProc) (ClientData clientData, XEvent *eventPtr);
typedef int (Tk_ClientMessageProc) (Tk_Window tkwin, XEvent *eventPtr);
typedef int (Tk_GetSelProc) (void *clientData, Tcl_Interp *interp,
	const char *portion);
typedef void (Tk_LostSelProc) (void *clientData);
typedef Tk_RestrictAction (Tk_RestrictProc) (void *clientData,
typedef int (Tk_GetSelProc) (ClientData clientData, Tcl_Interp *interp,
	CONST86 char *portion);
typedef void (Tk_LostSelProc) (ClientData clientData);
typedef Tk_RestrictAction (Tk_RestrictProc) (ClientData clientData,
	XEvent *eventPtr);
typedef Tcl_Size (Tk_SelectionProc) (void *clientData, Tcl_Size offset,
	char *buffer, Tcl_Size maxBytes);
typedef int (Tk_SelectionProc) (ClientData clientData, int offset,
	char *buffer, int maxBytes);

/*
 *----------------------------------------------------------------------
 *
 * Platform independent exported procedures and variables.
 *
 *----------------------------------------------------------------------
 */

#include "tkDecls.h"

#ifdef USE_OLD_IMAGE
#undef Tk_CreateImageType
#define Tk_CreateImageType		Tk_CreateOldImageType
#undef Tk_CreatePhotoImageFormat
#define Tk_CreatePhotoImageFormat	Tk_CreateOldPhotoImageFormat
#endif /* USE_OLD_IMAGE */

/*
 *----------------------------------------------------------------------
 *
 * Allow users to say that they don't want to alter their source to add extra
 * arguments to Tk_PhotoPutBlock() et al; DO NOT DEFINE THIS WHEN BUILDING TK.
 *
 * This goes after the inclusion of the stubbed-decls so that the declarations
 * of what is actually there can be correct.
 */

#ifdef USE_COMPOSITELESS_PHOTO_PUT_BLOCK
#   ifdef Tk_PhotoPutBlock
#	undef Tk_PhotoPutBlock
#   endif
#   define Tk_PhotoPutBlock		Tk_PhotoPutBlock_NoComposite
#   ifdef Tk_PhotoPutZoomedBlock
#	undef Tk_PhotoPutZoomedBlock
#   endif
#   define Tk_PhotoPutZoomedBlock	Tk_PhotoPutZoomedBlock_NoComposite
#   define USE_PANIC_ON_PHOTO_ALLOC_FAILURE
#else /* !USE_COMPOSITELESS_PHOTO_PUT_BLOCK */
#   ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
#	ifdef Tk_PhotoPutBlock
#	    undef Tk_PhotoPutBlock
#	endif
#	define Tk_PhotoPutBlock		Tk_PhotoPutBlock_Panic
#	ifdef Tk_PhotoPutZoomedBlock
#	    undef Tk_PhotoPutZoomedBlock
#	endif
#	define Tk_PhotoPutZoomedBlock	Tk_PhotoPutZoomedBlock_Panic
#   endif /* USE_PANIC_ON_PHOTO_ALLOC_FAILURE */
#endif /* USE_COMPOSITELESS_PHOTO_PUT_BLOCK */
#ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
#   ifdef Tk_PhotoExpand
#	undef Tk_PhotoExpand
#   endif
#   define Tk_PhotoExpand		Tk_PhotoExpand_Panic
#   ifdef Tk_PhotoSetSize
#	undef Tk_PhotoSetSize
#   endif
#   define Tk_PhotoSetSize		Tk_PhotoSetSize_Panic
#endif /* USE_PANIC_ON_PHOTO_ALLOC_FAILURE */

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

#endif /* RC_INVOKED */

/*
 * end block for C++

Changes to generic/tk3d.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29






-
-
+
+













-
+







/*
 * tk3d.c --
 *
 *	This module provides procedures to draw borders in the
 *	three-dimensional Motif style.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "tk3d.h"

/*
 * The following table defines the string values for reliefs, which are used
 * by Tk_GetReliefFromObj.
 */

const char *const tkReliefStrings[] = {
static const char *const reliefStrings[] = {
    "flat", "groove", "raised", "ridge", "solid", "sunken", NULL
};

/*
 * Forward declarations for functions defined in this file:
 */

42
43
44
45
46
47
48
49
50


51
52
53
54

55
56
57
58
59
60
61
62
63
42
43
44
45
46
47
48


49
50
51
52
53

54


55
56
57
58
59
60
61







-
-
+
+



-
+
-
-







 * The following structure defines the implementation of the "border" Tcl
 * object, used for drawing. The border object remembers the hash table entry
 * associated with a border. The actual allocation and deallocation of the
 * border should be done by the configuration package when the border option
 * is set.
 */

const TkObjType tkBorderObjType = {
    {"border",			/* name */
const Tcl_ObjType tkBorderObjType = {
    "border",			/* name */
    FreeBorderObjProc,		/* freeIntRepProc */
    DupBorderObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_Alloc3DBorderFromObj --
 *
85
86
87
88
89
90
91
92

93
94
95

96
97
98
99
100
101
102
83
84
85
86
87
88
89

90
91
92

93
94
95
96
97
98
99
100







-
+


-
+







    Tcl_Interp *interp,		/* Interp for error results. */
    Tk_Window tkwin,		/* Need the screen the border is used on.*/
    Tcl_Obj *objPtr)		/* Object giving name of color for window
				 * background. */
{
    TkBorder *borderPtr;

    if (objPtr->typePtr != &tkBorderObjType.objType) {
    if (objPtr->typePtr != &tkBorderObjType) {
	InitBorderObj(objPtr);
    }
    borderPtr = (TkBorder *)objPtr->internalRep.twoPtrValue.ptr1;
    borderPtr = objPtr->internalRep.twoPtrValue.ptr1;

    /*
     * If the object currently points to a TkBorder, see if it's the one we
     * want. If so, increment its reference count and return.
     */

    if (borderPtr != NULL) {
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







     *
     * If the value is not NULL, the internal rep is the value of the color
     * the last time this object was accessed. Check the screen and colormap
     * of the last access, and if they match, we are done.
     */

    if (borderPtr != NULL) {
	TkBorder *firstBorderPtr = (TkBorder *)Tcl_GetHashValue(borderPtr->hashPtr);
	TkBorder *firstBorderPtr = Tcl_GetHashValue(borderPtr->hashPtr);

	FreeBorderObj(objPtr);
	for (borderPtr = firstBorderPtr ; borderPtr != NULL;
		borderPtr = borderPtr->nextPtr) {
	    if ((Tk_Screen(tkwin) == borderPtr->screen)
		    && (Tk_Colormap(tkwin) == borderPtr->colormap)) {
		borderPtr->resourceRefCount++;
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+








    if (!dispPtr->borderInit) {
	BorderInit(dispPtr);
    }

    hashPtr = Tcl_CreateHashEntry(&dispPtr->borderTable, colorName, &isNew);
    if (!isNew) {
	existingBorderPtr = (TkBorder *)Tcl_GetHashValue(hashPtr);
	existingBorderPtr = Tcl_GetHashValue(hashPtr);
	for (borderPtr = existingBorderPtr; borderPtr != NULL;
		borderPtr = borderPtr->nextPtr) {
	    if ((Tk_Screen(tkwin) == borderPtr->screen)
		    && (Tk_Colormap(tkwin) == borderPtr->colormap)) {
		borderPtr->resourceRefCount++;
		return (Tk_3DBorder) borderPtr;
	    }
234
235
236
237
238
239
240
241
242
243



244
245
246
247
248
249
250
232
233
234
235
236
237
238



239
240
241
242
243
244
245
246
247
248







-
-
-
+
+
+







    borderPtr->colormap = Tk_Colormap(tkwin);
    borderPtr->resourceRefCount = 1;
    borderPtr->objRefCount = 0;
    borderPtr->bgColorPtr = bgColorPtr;
    borderPtr->darkColorPtr = NULL;
    borderPtr->lightColorPtr = NULL;
    borderPtr->shadow = None;
    borderPtr->bgGC = NULL;
    borderPtr->darkGC = NULL;
    borderPtr->lightGC = NULL;
    borderPtr->bgGC = None;
    borderPtr->darkGC = None;
    borderPtr->lightGC = None;
    borderPtr->hashPtr = hashPtr;
    borderPtr->nextPtr = existingBorderPtr;
    Tcl_SetHashValue(hashPtr, borderPtr);

    /*
     * Create the information for displaying the background color, but delay
     * the allocation of shadows until they are actually needed for drawing.
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401







-
+
















-
+







    Tk_3DBorder border,		/* Border whose GC is wanted. */
    int which)			/* Selects one of the border's 3 GC's:
				 * TK_3D_FLAT_GC, TK_3D_LIGHT_GC, or
				 * TK_3D_DARK_GC. */
{
    TkBorder * borderPtr = (TkBorder *) border;

    if ((borderPtr->lightGC == NULL) && (which != TK_3D_FLAT_GC)) {
    if ((borderPtr->lightGC == None) && (which != TK_3D_FLAT_GC)) {
	TkpGetShadows(borderPtr, tkwin);
    }
    if (which == TK_3D_FLAT_GC) {
	return borderPtr->bgGC;
    } else if (which == TK_3D_LIGHT_GC) {
	return borderPtr->lightGC;
    } else if (which == TK_3D_DARK_GC){
	return borderPtr->darkGC;
    }
    Tcl_Panic("bogus \"which\" value in Tk_3DBorderGC");

    /*
     * The code below will never be executed, but it's needed to keep
     * compilers happy.
     */

    return NULL;
    return (GC) None;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_Free3DBorder --
 *
418
419
420
421
422
423
424

425

426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446

447
448
449

450
451
452
453
454
455
456
416
417
418
419
420
421
422
423

424
425
426
427

428
429
430
431
432
433
434
435
436
437
438
439
440
441

442
443
444

445
446
447

448
449
450
451
452
453
454
455







+
-
+



-
+













-
+


-
+


-
+







Tk_Free3DBorder(
    Tk_3DBorder border)		/* Token for border to be released. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    Display *display = DisplayOfScreen(borderPtr->screen);
    TkBorder *prevPtr;

    borderPtr->resourceRefCount--;
    if (borderPtr->resourceRefCount-- > 1) {
    if (borderPtr->resourceRefCount > 0) {
	return;
    }

    prevPtr = (TkBorder *)Tcl_GetHashValue(borderPtr->hashPtr);
    prevPtr = Tcl_GetHashValue(borderPtr->hashPtr);
    TkpFreeBorder(borderPtr);
    if (borderPtr->bgColorPtr != NULL) {
	Tk_FreeColor(borderPtr->bgColorPtr);
    }
    if (borderPtr->darkColorPtr != NULL) {
	Tk_FreeColor(borderPtr->darkColorPtr);
    }
    if (borderPtr->lightColorPtr != NULL) {
	Tk_FreeColor(borderPtr->lightColorPtr);
    }
    if (borderPtr->shadow != None) {
	Tk_FreeBitmap(display, borderPtr->shadow);
    }
    if (borderPtr->bgGC != NULL) {
    if (borderPtr->bgGC != None) {
	Tk_FreeGC(display, borderPtr->bgGC);
    }
    if (borderPtr->darkGC != NULL) {
    if (borderPtr->darkGC != None) {
	Tk_FreeGC(display, borderPtr->darkGC);
    }
    if (borderPtr->lightGC != NULL) {
    if (borderPtr->lightGC != None) {
	Tk_FreeGC(display, borderPtr->lightGC);
    }
    if (prevPtr == borderPtr) {
	if (borderPtr->nextPtr == NULL) {
	    Tcl_DeleteHashEntry(borderPtr->hashPtr);
	} else {
	    Tcl_SetHashValue(borderPtr->hashPtr, borderPtr->nextPtr);
524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537







-
+







    objPtr->typePtr = NULL;
}

static void
FreeBorderObj(
    Tcl_Obj *objPtr)		/* The object we are releasing. */
{
    TkBorder *borderPtr = (TkBorder *)objPtr->internalRep.twoPtrValue.ptr1;
    TkBorder *borderPtr = objPtr->internalRep.twoPtrValue.ptr1;

    if (borderPtr != NULL) {
	borderPtr->objRefCount--;
	if ((borderPtr->objRefCount == 0)
		&& (borderPtr->resourceRefCount == 0)) {
	    ckfree(borderPtr);
	}
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572







-
+







 */

static void
DupBorderObjProc(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    TkBorder *borderPtr = (TkBorder *)srcObjPtr->internalRep.twoPtrValue.ptr1;
    TkBorder *borderPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;

    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep.twoPtrValue.ptr1 = borderPtr;

    if (borderPtr != NULL) {
	borderPtr->objRefCount++;
    }
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604







-
+







 */

void
Tk_SetBackgroundFromBorder(
    Tk_Window tkwin,		/* Window whose background is to be set. */
    Tk_3DBorder border)		/* Token for border. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    register TkBorder *borderPtr = (TkBorder *) border;

    Tk_SetWindowBackground(tkwin, borderPtr->bgColorPtr->pixel);
}

/*
 *----------------------------------------------------------------------
 *
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636
637
638
639
640
641
642


643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665




666
667
668
669


670
671
672


673
674
675


676
677

678
679
680
681
682
683




684
685
686
687
688
689
690
691
692
693
694
695
696
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

658
659
660
661



662
663
664
665
666
667


668
669



670
671



672
673


674
675





676
677
678
679

680
681



682
683
684
685
686
687
688







-
+













-
+
+















-




-
-
-
+
+
+
+


-
-
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+

-
-
-
-
-
+
+
+
+
-


-
-
-







int
Tk_GetReliefFromObj(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tcl_Obj *objPtr,		/* The object we are trying to get the value
				 * from. */
    int *resultPtr)		/* Where to place the answer. */
{
    return Tcl_GetIndexFromObjStruct(interp, objPtr, tkReliefStrings,
    return Tcl_GetIndexFromObjStruct(interp, objPtr, reliefStrings,
	    sizeof(char *), "relief", 0, resultPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetRelief --
 *
 *	Parse a relief description and return the corresponding relief value,
 *	or an error.
 *
 * Results:
 *	A standard Tcl return value. If all goes well then *reliefPtr is
 *	filled in with one of the values TK_RELIEF_*
 *	filled in with one of the values TK_RELIEF_RAISED, TK_RELIEF_FLAT, or
 *	TK_RELIEF_SUNKEN.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetRelief(
    Tcl_Interp *interp,		/* For error messages. */
    const char *name,		/* Name of a relief type. */
    int *reliefPtr)		/* Where to store converted relief. */
{
    char c;
    size_t length;
    int relief;

    c = name[0];
    length = strlen(name);
    if ((c == 'f') && (strncmp(name, "flat", length) == 0)) {
	relief = TK_RELIEF_FLAT;
    } else if ((c == 'g') && (strncmp(name, "groove", length) == 0)) {
	relief = TK_RELIEF_GROOVE;
	*reliefPtr = TK_RELIEF_FLAT;
    } else if ((c == 'g') && (strncmp(name, "groove", length) == 0)
	    && (length >= 2)) {
	*reliefPtr = TK_RELIEF_GROOVE;
    } else if ((c == 'r') && (strncmp(name, "raised", length) == 0)
	    && (length >= 2)) {
	relief = TK_RELIEF_RAISED;
    } else if ((c == 'r') && (strncmp(name, "ridge", length) == 0)
	*reliefPtr = TK_RELIEF_RAISED;
    } else if ((c == 'r') && (strncmp(name, "ridge", length) == 0)) {
	    && (length >= 2)) {
	relief = TK_RELIEF_RIDGE;
    } else if ((c == 's') && (strncmp(name, "solid", length) == 0)
	*reliefPtr = TK_RELIEF_RIDGE;
    } else if ((c == 's') && (strncmp(name, "solid", length) == 0)) {
	    && (length >= 2)) {
	relief = TK_RELIEF_SOLID;
    } else if ((c == 's') && (strncmp(name, "sunken", length) == 0)
	*reliefPtr = TK_RELIEF_SOLID;
    } else if ((c == 's') && (strncmp(name, "sunken", length) == 0)) {
	    && (length >= 2)) {
	relief = TK_RELIEF_SUNKEN;
	*reliefPtr = TK_RELIEF_SUNKEN;
    } else {
	if (interp) {
	    Tcl_SetObjResult(interp,
		    Tcl_ObjPrintf("bad relief \"%.50s\": must be %s",
		    name, "flat, groove, raised, ridge, solid, or sunken"));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "RELIEF", NULL);
	Tcl_SetObjResult(interp,
		Tcl_ObjPrintf("bad relief \"%.50s\": must be %s",
		name, "flat, groove, raised, ridge, solid, or sunken"));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "RELIEF", NULL);
	}
	return TCL_ERROR;
    }
    if (reliefPtr) {
	*reliefPtr = relief;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_NameOfRelief --
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770

771
772
773
774

775
776
777

778
779
780
781
782
783
784
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761

762
763
764


765
766
767

768
769
770
771
772
773
774
775







-
+









-
+


-
-
+


-
+







Tk_Draw3DPolygon(
    Tk_Window tkwin,		/* Window for which border was allocated. */
    Drawable drawable,		/* X window or pixmap in which to draw. */
    Tk_3DBorder border,		/* Token for border to draw. */
    XPoint *pointPtr,		/* Array of points describing polygon. All
				 * points must be absolute
				 * (CoordModeOrigin). */
    Tcl_Size numPoints,		/* Number of points at *pointPtr. */
    int numPoints,		/* Number of points at *pointPtr. */
    int borderWidth,		/* Width of border, measured in pixels to the
				 * left of the polygon's trajectory. May be
				 * negative. */
    int leftRelief)		/* TK_RELIEF_RAISED or TK_RELIEF_SUNKEN:
				 * indicates how stuff to left of trajectory
				 * looks relative to stuff on right. */
{
    XPoint poly[4], b1, b2, newB1, newB2;
    XPoint perp, c, shift1, shift2;	/* Used for handling parallel lines. */
    XPoint *p1Ptr, *p2Ptr;
    register XPoint *p1Ptr, *p2Ptr;
    TkBorder *borderPtr = (TkBorder *) border;
    GC gc;
    Tcl_Size i;
    int lightOnLeft, dx, dy, parallel, pointsSeen;
    int i, lightOnLeft, dx, dy, parallel, pointsSeen;
    Display *display = Tk_Display(tkwin);

    if (borderPtr->lightGC == NULL) {
    if (borderPtr->lightGC == None) {
	TkpGetShadows(borderPtr, tkwin);
    }

    /*
     * Handle grooves and ridges with recursive calls.
     */

840
841
842
843
844
845
846
847
848
849



850
851
852
853
854
855
856
831
832
833
834
835
836
837



838
839
840
841
842
843
844
845
846
847







-
-
-
+
+
+







     * so some parts of the processing are ommitted for these points. The
     * variable "pointsSeen" keeps track of the priming process; it has to be
     * separate from i in order to be able to ignore duplicate points in the
     * polygon.
     */

    pointsSeen = 0;
    for (i = 0, p1Ptr = &pointPtr[numPoints-2], p2Ptr = p1Ptr+1;
	    i < numPoints + 2; i++, p1Ptr = p2Ptr, p2Ptr++) {
	if ((i == 1) || (i == numPoints + 1)) {
    for (i = -2, p1Ptr = &pointPtr[numPoints-2], p2Ptr = p1Ptr+1;
	    i < numPoints; i++, p1Ptr = p2Ptr, p2Ptr++) {
	if ((i == -1) || (i == numPoints-1)) {
	    p2Ptr = pointPtr;
	}
	if ((p2Ptr->x == p1Ptr->x) && (p2Ptr->y == p1Ptr->y)) {
	    /*
	     * Ignore duplicate points (they'd cause core dumps in ShiftLine
	     * calls below).
	     */
961
962
963
964
965
966
967
968

969
970
971
972
973
974
975
952
953
954
955
956
957
958

959
960
961
962
963
964
965
966







-
+







    int x, int y, int width, int height,
				/* Outside area of rectangular region. */
    int borderWidth,		/* Desired width for border, in pixels. Border
				 * will be *inside* region. */
    int relief)			/* Indicates 3D effect: TK_RELIEF_FLAT,
				 * TK_RELIEF_RAISED, or TK_RELIEF_SUNKEN. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    register TkBorder *borderPtr = (TkBorder *) border;
    int doubleBorder;

    /*
     * This code is slightly tricky because it only draws the background in
     * areas not covered by the 3D border. This avoids flashing effects on the
     * screen for the border region.
     */
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
1040







-
+








-
+


-
+







Tk_Fill3DPolygon(
    Tk_Window tkwin,		/* Window for which border was allocated. */
    Drawable drawable,		/* X window or pixmap in which to draw. */
    Tk_3DBorder border,		/* Token for border to draw. */
    XPoint *pointPtr,		/* Array of points describing polygon. All
				 * points must be absolute
				 * (CoordModeOrigin). */
    Tcl_Size numPoints,		/* Number of points at *pointPtr. */
    int numPoints,		/* Number of points at *pointPtr. */
    int borderWidth,		/* Width of border, measured in pixels to the
				 * left of the polygon's trajectory. May be
				 * negative. */
    int leftRelief)		/* Indicates 3D effect of left side of
				 * trajectory relative to right:
				 * TK_RELIEF_FLAT, TK_RELIEF_RAISED, or
				 * TK_RELIEF_SUNKEN. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    register TkBorder *borderPtr = (TkBorder *) border;

    XFillPolygon(Tk_Display(tkwin), drawable, borderPtr->bgGC,
	    pointPtr, (int)numPoints, Complex, CoordModeOrigin);
	    pointPtr, numPoints, Complex, CoordModeOrigin);
    if (leftRelief != TK_RELIEF_FLAT) {
	Tk_Draw3DPolygon(tkwin, drawable, border, pointPtr, numPoints,
		borderWidth, leftRelief);
    }
}

/*
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263







-
+









-
+







    Tcl_Obj *objPtr)		/* The object whose string value selects a
				 * border. */
{
    TkBorder *borderPtr = NULL;
    Tcl_HashEntry *hashPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (objPtr->typePtr != &tkBorderObjType.objType) {
    if (objPtr->typePtr != &tkBorderObjType) {
	InitBorderObj(objPtr);
    }

    /*
     * If we are lucky (and the user doesn't use too many different displays,
     * screens, or colormaps...) then the TkBorder structure we need will be
     * cached in the internal representation of the Tcl_Obj. Check it out...
     */

    borderPtr = (TkBorder *)objPtr->internalRep.twoPtrValue.ptr1;
    borderPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if ((borderPtr != NULL)
	    && (borderPtr->resourceRefCount > 0)
	    && (Tk_Screen(tkwin) == borderPtr->screen)
	    && (Tk_Colormap(tkwin) == borderPtr->colormap)) {
	/*
	 * The object already points to the right border structure. Just
	 * return it.
1286
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300
1277
1278
1279
1280
1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1291







-
+







     * find the right TkBorder structure.
     */

    hashPtr = Tcl_FindHashEntry(&dispPtr->borderTable, Tcl_GetString(objPtr));
    if (hashPtr == NULL) {
	goto error;
    }
    for (borderPtr = (TkBorder *)Tcl_GetHashValue(hashPtr); borderPtr != NULL;
    for (borderPtr = Tcl_GetHashValue(hashPtr); borderPtr != NULL;
	    borderPtr = borderPtr->nextPtr) {
	if ((Tk_Screen(tkwin) == borderPtr->screen)
		&& (Tk_Colormap(tkwin) == borderPtr->colormap)) {
	    FreeBorderObj(objPtr);
	    objPtr->internalRep.twoPtrValue.ptr1 = borderPtr;
	    borderPtr->objRefCount++;
	    return (Tk_3DBorder) borderPtr;
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352
1353
1354
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1345







-
+



















-
+







 * Results:
 *	The return value is a standard Tcl result. If an error occurs during
 *	conversion, an error message is left in the interpreter's result
 *	unless "interp" is NULL.
 *
 * Side effects:
 *	If no error occurs, a blank internal format for a border value is
 *	initialized. The final form cannot be done without a Tk_Window.
 *	intialized. The final form cannot be done without a Tk_Window.
 *
 *----------------------------------------------------------------------
 */

static void
InitBorderObj(
    Tcl_Obj *objPtr)		/* The object to convert. */
{
    const Tcl_ObjType *typePtr;

    /*
     * Free the old internalRep before setting the new one.
     */

    Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }
    objPtr->typePtr = &tkBorderObjType.objType;
    objPtr->typePtr = &tkBorderObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkDebugBorder --
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391
1392

1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381
1382

1383
1384

1385
1386
1387
1388
1389
1390


































1391
1392
1393
1394
1395
1396
1397
1398







-
+








-
+

-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    Tcl_HashEntry *hashPtr;
    Tcl_Obj *resultPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    resultPtr = Tcl_NewObj();
    hashPtr = Tcl_FindHashEntry(&dispPtr->borderTable, name);
    if (hashPtr != NULL) {
	TkBorder *borderPtr = (TkBorder *)Tcl_GetHashValue(hashPtr);
	TkBorder *borderPtr = Tcl_GetHashValue(hashPtr);

	if (borderPtr == NULL) {
	    Tcl_Panic("TkDebugBorder found empty hash table entry");
	}
	for ( ; (borderPtr != NULL); borderPtr = borderPtr->nextPtr) {
	    Tcl_Obj *objPtr = Tcl_NewObj();

	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(borderPtr->resourceRefCount));
		    Tcl_NewIntObj(borderPtr->resourceRefCount));
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(borderPtr->objRefCount));
		    Tcl_NewIntObj(borderPtr->objRefCount));
	    Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
	}
    }
    return resultPtr;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_Get3BorderColors --
 *
 *	Given a Tk_3DBorder determine its 3 colors.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

void
Tk_Get3DBorderColors(
    Tk_3DBorder border,
    XColor *bgColorPtr,
    XColor *darkColorPtr,
    XColor *lightColorPtr)
{
    if (bgColorPtr) {
	*bgColorPtr = *((TkBorder *)border)->bgColorPtr;
    }
    if (darkColorPtr) {
	*darkColorPtr = *((TkBorder *) border)->darkColorPtr;
    }
    if (lightColorPtr) {
	*lightColorPtr = *((TkBorder *) border)->lightColorPtr;
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tk3d.h.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tk3d.h --
 *
 *	Declarations of types and functions shared by the 3d border module.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TK3D
#define _TK3D
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60

61
62
63
64
65
66
67
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59

60
61
62
63
64
65
66
67







-
+








-
+
















-
+


-
+







    Screen *screen;		/* Screen on which the border will be used. */
    Visual *visual;		/* Visual for all windows and pixmaps using
				 * the border. */
    int depth;			/* Number of bits per pixel of drawables where
				 * the border will be used. */
    Colormap colormap;		/* Colormap out of which pixels are
				 * allocated. */
    Tcl_Size resourceRefCount;	/* Number of active uses of this color (each
    int resourceRefCount;	/* Number of active uses of this color (each
				 * active use corresponds to a call to
				 * Tk_Alloc3DBorderFromObj or Tk_Get3DBorder).
				 * If this count is 0, then this structure is
				 * no longer valid and it isn't present in
				 * borderTable: it is being kept around only
				 * because there are objects referring to it.
				 * The structure is freed when objRefCount and
				 * resourceRefCount are both 0. */
    Tcl_Size objRefCount;		/* The number of Tcl objects that reference
    int objRefCount;		/* The number of Tcl objects that reference
				 * this structure. */
    XColor *bgColorPtr;		/* Background color (intensity between
				 * lightColorPtr and darkColorPtr). */
    XColor *darkColorPtr;	/* Color for darker areas (must free when
				 * deleting structure). NULL means shadows
				 * haven't been allocated yet.*/
    XColor *lightColorPtr;	/* Color used for lighter areas of border
				 * (must free this when deleting structure).
				 * NULL means shadows haven't been allocated
				 * yet. */
    Pixmap shadow;		/* Stipple pattern to use for drawing shadows
				 * areas. Used for displays with <= 64 colors
				 * or where colormap has filled up. */
    GC bgGC;			/* Used (if necessary) to draw areas in the
				 * background color. */
    GC darkGC;			/* Used to draw darker parts of the border.
				 * NULL means the shadow colors haven't been
				 * None means the shadow colors haven't been
				 * allocated yet.*/
    GC lightGC;			/* Used to draw lighter parts of the border.
				 * NULL means the shadow colors haven't been
				 * None means the shadow colors haven't been
				 * allocated yet. */
    Tcl_HashEntry *hashPtr;	/* Entry in borderTable (needed in order to
				 * delete structure). */
    struct TkBorder *nextPtr;	/* Points to the next TkBorder structure with
				 * the same color name. Borders with the same
				 * name but different screens or colormaps are
				 * chained together off a single entry in

Changes to generic/tkArgv.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkArgv.c --
 *
 *	This file contains a function that handles table-based argv-argc
 *	parsing.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

63
64
65
66
67
68
69
70

71
72
73
74
75

76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
63
64
65
66
67
68
69

70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







-
+




-
+










+







				 * hold # args left in argv at end. */
    const char **argv,		/* Array of arguments. Modified to hold those
				 * that couldn't be processed here. */
    const Tk_ArgvInfo *argTable,	/* Array of option descriptions */
    int flags)			/* Or'ed combination of various flag bits,
				 * such as TK_ARGV_NO_DEFAULTS. */
{
    const Tk_ArgvInfo *infoPtr;
    register const Tk_ArgvInfo *infoPtr;
				/* Pointer to the current entry in the table
				 * of argument descriptions. */
    const Tk_ArgvInfo *matchPtr;/* Descriptor that matches current argument. */
    const char *curArg;		/* Current argument */
    char c;		/* Second character of current arg (used for
    register char c;		/* Second character of current arg (used for
				 * quick check for matching; use 2nd char.
				 * because first char. will almost always be
				 * '-'). */
    int srcIndex;		/* Location from which to read next argument
				 * from argv. */
    int dstIndex;		/* Index into argv to which next unused
				 * argument should be copied (never greater
				 * than srcIndex). */
    int argc;			/* # arguments in argv still to process. */
    size_t length;		/* Number of characters in current argument. */
    char *endPtr;		/* Used for identifying junk in arguments. */
    int i;

    if (flags & TK_ARGV_DONT_SKIP_FIRST_ARG) {
	srcIndex = dstIndex = 0;
	argc = *argcPtr;
    } else {
	srcIndex = dstIndex = 1;
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
+







	if (length > 0) {
	    c = curArg[1];
	} else {
	    c = 0;
	}

	/*
	 * Loop through the argument descriptors searching for one with the
	 * Loop throught the argument descriptors searching for one with the
	 * matching key string. If found, leave a pointer to it in matchPtr.
	 */

	matchPtr = NULL;
	for (i = 0; i < 2; i++) {
	    if (i == 0) {
		infoPtr = argTable;
170
171
172
173
174
175
176
177

178
179
180
181
182
183






184
185
186
187
188
189
190
171
172
173
174
175
176
177

178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196







-
+





-
+
+
+
+
+
+







	 * Take the appropriate action based on the option type
	 */

    gotMatch:
	infoPtr = matchPtr;
	switch (infoPtr->type) {
	case TK_ARGV_CONSTANT:
	    *((int *) infoPtr->dst) = (int)PTR2INT(infoPtr->src);
	    *((int *) infoPtr->dst) = PTR2INT(infoPtr->src);
	    break;
	case TK_ARGV_INT:
	    if (argc == 0) {
		goto missingArg;
	    }
	    if (Tcl_GetInt(interp, argv[srcIndex], (int *) infoPtr->dst) != TCL_OK) {
	    *((int *) infoPtr->dst) = strtol(argv[srcIndex], &endPtr, 0);
	    if ((endPtr == argv[srcIndex]) || (*endPtr != 0)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"expected %s argument for \"%s\" but got \"%s\"",
			"integer", infoPtr->key, argv[srcIndex]));
		Tcl_SetErrorCode(interp, "TK", "ARG", "INTEGER", curArg,NULL);
		return TCL_ERROR;
	    }
	    srcIndex++;
	    argc--;
	    break;
	case TK_ARGV_STRING:
	    if (argc == 0) {
205
206
207
208
209
210
211
212






213
214
215
216
217
218
219
220

221
222

223
224
225
226
227
228
229
230
231

232
233

234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252

253
254
255
256
257
258
259
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230

231
232

233
234
235
236
237
238
239
240
241

242
243

244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262

263
264
265
266
267
268
269
270







-
+
+
+
+
+
+







-
+

-
+








-
+

-
+











-
+






-
+







	case TK_ARGV_REST:
	    *((int *) infoPtr->dst) = dstIndex;
	    goto argsDone;
	case TK_ARGV_FLOAT:
	    if (argc == 0) {
		goto missingArg;
	    }
	    if (Tcl_GetDouble(interp, argv[srcIndex], ((double *) infoPtr->dst)) != TCL_OK) {
	    *((double *) infoPtr->dst) = strtod(argv[srcIndex], &endPtr);
	    if ((endPtr == argv[srcIndex]) || (*endPtr != 0)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"expected %s argument for \"%s\" but got \"%s\"",
			"floating-point", infoPtr->key, argv[srcIndex]));
		Tcl_SetErrorCode(interp, "TK", "ARG", "FLOAT", curArg, NULL);
		return TCL_ERROR;
	    }
	    srcIndex++;
	    argc--;
	    break;
	case TK_ARGV_FUNC: {
	    typedef int (ArgvFunc)(char *, const char *, const char *);
	    ArgvFunc *handlerProc = (ArgvFunc *)infoPtr->src;
	    ArgvFunc *handlerProc = (ArgvFunc *) infoPtr->src;

	    if (handlerProc((char *)infoPtr->dst, infoPtr->key, argv[srcIndex])) {
	    if (handlerProc(infoPtr->dst, infoPtr->key, argv[srcIndex])) {
		srcIndex++;
		argc--;
	    }
	    break;
	}
	case TK_ARGV_GENFUNC: {
	    typedef int (ArgvGenFunc)(char *, Tcl_Interp *, const char *, int,
		    const char **);
	    ArgvGenFunc *handlerProc = (ArgvGenFunc *)infoPtr->src;
	    ArgvGenFunc *handlerProc = (ArgvGenFunc *) infoPtr->src;

	    argc = handlerProc((char *)infoPtr->dst, interp, infoPtr->key, argc,
	    argc = handlerProc(infoPtr->dst, interp, infoPtr->key, argc,
		    argv+srcIndex);
	    if (argc < 0) {
		return TCL_ERROR;
	    }
	    break;
	}
	case TK_ARGV_HELP:
	    PrintUsage(interp, argTable, flags);
	    Tcl_SetErrorCode(interp, "TK", "ARG", "HELP", NULL);
	    return TCL_ERROR;
	case TK_ARGV_CONST_OPTION:
	    Tk_AddOption(tkwin, (char *)infoPtr->dst, (char *)infoPtr->src,
	    Tk_AddOption(tkwin, infoPtr->dst, infoPtr->src,
		    TK_INTERACTIVE_PRIO);
	    break;
	case TK_ARGV_OPTION_VALUE:
	    if (argc < 1) {
		goto missingArg;
	    }
	    Tk_AddOption(tkwin, (char *)infoPtr->dst, argv[srcIndex],
	    Tk_AddOption(tkwin, infoPtr->dst, argv[srcIndex],
		    TK_INTERACTIVE_PRIO);
	    srcIndex++;
	    argc--;
	    break;
	case TK_ARGV_OPTION_NAME_VALUE:
	    if (argc < 2) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







				 * area. */
    const Tk_ArgvInfo *argTable,/* Array of command-specific argument
				 * descriptions. */
    int flags)			/* If the TK_ARGV_NO_DEFAULTS bit is set in
				 * this word, then don't generate information
				 * for default options. */
{
    const Tk_ArgvInfo *infoPtr;
    register const Tk_ArgvInfo *infoPtr;
    size_t width, i, numSpaces;
    Tcl_Obj *message;

    /*
     * First, compute the width of the widest option key, so that we can make
     * everything line up.
     */
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
359
360
361
362
363
364
365

366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+












-
+







	    length = strlen(infoPtr->key);
	    if (length > width) {
		width = length;
	    }
	}
    }

    message = Tcl_NewStringObj("Command-specific options:", TCL_INDEX_NONE);
    message = Tcl_NewStringObj("Command-specific options:", -1);
    for (i = 0; ; i++) {
	for (infoPtr = i ? defaultTable : argTable;
		infoPtr->type != TK_ARGV_END; infoPtr++) {
	    if ((infoPtr->type == TK_ARGV_HELP) && (infoPtr->key == NULL)) {
		Tcl_AppendPrintfToObj(message, "\n%s", infoPtr->help);
		continue;
	    }
	    Tcl_AppendPrintfToObj(message, "\n %s:", infoPtr->key);
	    numSpaces = width + 1 - strlen(infoPtr->key);
	    while (numSpaces-- > 0) {
		Tcl_AppendToObj(message, " ", 1);
	    }
	    Tcl_AppendToObj(message, infoPtr->help, TCL_INDEX_NONE);
	    Tcl_AppendToObj(message, infoPtr->help, -1);
	    switch (infoPtr->type) {
	    case TK_ARGV_INT:
		Tcl_AppendPrintfToObj(message, "\n\t\tDefault value: %d",
			*((int *) infoPtr->dst));
		break;
	    case TK_ARGV_FLOAT:
		Tcl_AppendPrintfToObj(message, "\n\t\tDefault value: %f",
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414
415
416
417







-
+











		break;
	    }
	}

	if ((flags & TK_ARGV_NO_DEFAULTS) || (i > 0)) {
	    break;
	}
	Tcl_AppendToObj(message, "\nGeneric options for all commands:", TCL_INDEX_NONE);
	Tcl_AppendToObj(message, "\nGeneric options for all commands:", -1);
    }
    Tcl_SetObjResult(interp, message);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted generic/tkArray.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610


































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkArray.h --
 *
 * An array is a sequence of items, stored in a contiguous memory region.
 * Random access to any item is very fast. New items can be either appended
 * or prepended. An array may be traversed in the forward or backward direction.
 *
 * Copyright © 2018-2019 Gregor Cramer.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Note that this file will not be included in header files, it is the purpose
 * of this file to be included in source files only. Thus we are not using the
 * prefix "Tk_" here for functions, because all the functions have private scope.
 */

/*
 * -------------------------------------------------------------------------------
 * Use the array in the following way:
 * -------------------------------------------------------------------------------
 * typedef struct { int key, value; } Pair;
 * TK_PTR_ARRAY_DEFINE(MyArray, Pair);
 * MyArray *arr = NULL;
 * if (MyArray_IsEmpty(arr)) {
 *     MyArray_Append(&arr, MakePair(1, 2));
 *     MyArray_Append(&arr, MakePair(2, 3));
 *     for (i = 0; i < MyArray_Size(arr); ++i) {
 *         Pair *p = MyArray_Get(arr, i);
 *         printf("%d -> %d\n", p->key, p->value);
 *         ckfree(p);
 *     }
 *     MyArray_Free(&arr);
 *     assert(arr == NULL);
 * }
 * -------------------------------------------------------------------------------
 * Or with aggregated elements:
 * -------------------------------------------------------------------------------
 * typedef struct { int key, value; } Pair;
 * TK_ARRAY_DEFINE(MyArray, Pair);
 * Pair p1 = { 1, 2 };
 * Pair p2 = { 2, 3 };
 * MyArray *arr = NULL;
 * if (MyArray_IsEmpty(arr)) {
 *     MyArray_Append(&arr, p1);
 *     MyArray_Append(&arr, p2);
 *     for (i = 0; i < MyArray_Size(arr); ++i) {
 *         const Pair *p = MyArray_Get(arr, i);
 *         printf("%d -> %d\n", p->key, p->value);
 *     }
 *     MyArray_Free(&arr);
 *     assert(arr == NULL);
 * }
 * -------------------------------------------------------------------------------
 */

/*************************************************************************/
/*
 * Two array types will be provided:
 * Use TK_ARRAY_DEFINE if your array is aggregating the elements. Use
 * TK_PTR_ARRAY_DEFINE if your array contains pointers to elements. But
 * in latter case the array is not responsible for the lifetime of the
 * elements.
 */
/*************************************************************************/
/*
 * Array_ElemSize: Returns the memory size for one array element.
 */
/*************************************************************************/
/*
 * Array_BufferSize: Returns the memory size for given number of elements.
 */
/*************************************************************************/
/*
 * Array_IsEmpty: Array is empty?
 */
/*************************************************************************/
/*
 * Array_Size: Number of elements in array.
 */
/*************************************************************************/
/*
 * Array_Capacity: Capacity of given array. This is the maximal number of
 * elements fitting into current array memory without resizing the buffer.
 */
/*************************************************************************/
/*
 * Array_SetSize: Set array size, new size must not exceed the capacity of
 * the array. This function has to be used with care when increasing the
 * array size.
 */
/*************************************************************************/
/*
 * Array_First: Returns position of first element in array. Given array
 * may be NULL.
 */
/*************************************************************************/
/*
 * Array_Last: Returns position after last element in array. Given array
 * may be empty.
 */
/*************************************************************************/
/*
 * Array_Front: Returns first element in array. Given array must not be
 * empty.
 */
/*************************************************************************/
/*
 * Array_Back: Returns last element in array. Given array must not be
 * empty.
 */
/*************************************************************************/
/*
 * Array_Resize: Resize buffer of array for given number of elements. The
 * array may grow or shrink. Note that this function is not initializing
 * the increased buffer.
 */
/*************************************************************************/
/*
 * Array_ResizeAndClear: Resize buffer of array for given number of
 * elements. The array may grow or shrink. The increased memory will be
 * filled with zeroes.
 */
/*************************************************************************/
/*
 * Array_Clear: Fill specified range with zeroes.
 */
/*************************************************************************/
/*
 * Array_Free: Resize array to size zero. This function will release the
 * array buffer.
 */
/*************************************************************************/
/*
 * Array_Append: Insert given element after end of array.
 */
/*************************************************************************/
/*
 * Array_PopBack: Shrink array by one element. Given array must not be
 * empty.
 */
/*************************************************************************/
/*
 * Array_Get: Random access to array element at given position. The given
 * index must not exceed current array size.
 */
/*************************************************************************/
/*
 * Array_Set: Replace array element at given position with new value. The
 * given index must not exceed current array size.
 */
/*************************************************************************/
/*
 * Array_Find: Return index position of element which matches given
 * argument. If not found then -1 will be returned.
 */
/*************************************************************************/

#ifndef TK_ARRAY_DEFINED
#define TK_ARRAY_DEFINED

#include "tkInt.h"

#if defined(__GNUC__) || defined(__clang__)
# define __TK_ARRAY_UNUSED __attribute__((unused))
#else
# define __TK_ARRAY_UNUSED
#endif

#define TK_ARRAY_DEFINE(AT, ElemType) /* AT = type of array */			\
/* ------------------------------------------------------------------------- */	\
typedef struct AT {								\
    size_t size;								\
    size_t capacity;								\
    ElemType buf[1];								\
} AT;										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Init(AT *arr)								\
{										\
    assert(arr);								\
    arr->size = 0;								\
    arr->capacity = 0;								\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_ElemSize(void)									\
{										\
    return sizeof(ElemType);							\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_BufferSize(size_t numElems)						\
{										\
    return numElems*sizeof(ElemType);						\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_IsEmpty(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return !arr || arr->size == 0u;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_Size(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->size : 0u;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_Capacity(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->capacity : 0u;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_First(AT *arr)								\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->buf : NULL;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Last(AT *arr)								\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->buf + arr->size : NULL;					\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Front(AT *arr)								\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(!AT##_IsEmpty(arr));							\
    return &arr->buf[0];							\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Back(AT *arr)								\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(!AT##_IsEmpty(arr));							\
    return &arr->buf[arr->size - 1];						\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Resize(AT **arrp, size_t newSize)						\
{										\
    assert(arrp);								\
    assert(!*arrp || (*arrp)->size != 0xdeadbeef);				\
    if (newSize == 0) {								\
	assert(!*arrp || ((*arrp)->size = 0xdeadbeef));				\
	ckfree(*arrp);								\
	*arrp = NULL;								\
    } else {									\
	int init = *arrp == NULL;						\
	size_t memSize = AT##_BufferSize(newSize - 1) + sizeof(AT);		\
	*arrp = (AT *)ckrealloc(*arrp, memSize);					\
	if (init) {								\
	    (*arrp)->size = 0;							\
	} else if (newSize < (*arrp)->size) {					\
	    (*arrp)->size = newSize;						\
	}									\
	(*arrp)->capacity = newSize;						\
    }										\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Clear(AT *arr, size_t from, size_t to)					\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(to <= AT##_Capacity(arr));						\
    assert(from <= to);								\
    memset(arr->buf + from, 0, AT##_BufferSize(to - from));			\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_ResizeAndClear(AT **arrp, size_t newSize)					\
{										\
    size_t oldCapacity;								\
    assert(arrp);								\
    oldCapacity = *arrp ? (*arrp)->capacity : 0;				\
    AT##_Resize(arrp, newSize);							\
    if (newSize > oldCapacity) {						\
	AT##_Clear(*arrp, oldCapacity, newSize);				\
    }										\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_SetSize(AT *arr, size_t newSize)						\
{										\
    assert(newSize <= AT##_Capacity(arr));					\
    assert(!arr || arr->size != 0xdeadbeef);					\
    if (arr) {									\
	arr->size = newSize;							\
    }										\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Append(AT **arrp, ElemType *elem)						\
{										\
    assert(arrp);								\
    if (!*arrp) {								\
	AT##_Resize(arrp, 1);							\
    } else if ((*arrp)->size == (*arrp)->capacity) {				\
	AT##_Resize(arrp, (*arrp)->capacity + ((*arrp)->capacity + 1)/2);	\
    }										\
    (*arrp)->buf[(*arrp)->size++] = *elem;					\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_PopBack(AT *arr)								\
{										\
    assert(!AT##_IsEmpty(arr));							\
    return arr->size -= 1;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Get(const AT *arr, size_t at)						\
{										\
    assert(arr);								\
    assert(at < AT##_Size(arr));						\
    return (ElemType *) &arr->buf[at];						\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Set(AT *arr, size_t at, ElemType *elem)					\
{										\
    assert(arr);								\
    assert(at < AT##_Size(arr));						\
    arr->buf[at] = *elem;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Free(AT **arrp)								\
{										\
    AT##_Resize(arrp, 0);							\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_Find(const AT *arr, const ElemType *elem)					\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    if (arr) {									\
	const ElemType *buf = arr->buf;						\
	size_t i;								\
	for (i = 0; i < arr->size; ++i) {					\
	    if (memcmp(&buf[i], elem, sizeof(ElemType)) == 0) {			\
		return (int) i;							\
	    }									\
	}									\
    }										\
    return -1;									\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_Contains(const AT *arr, const ElemType *elem)				\
{										\
    return AT##_Find(arr, elem) != -1;						\
}										\
/* ------------------------------------------------------------------------- */

#define TK_PTR_ARRAY_DEFINE(AT, ElemType) /* AT = type of array */		\
/* ------------------------------------------------------------------------- */	\
typedef struct AT {								\
    size_t size;								\
    size_t capacity;								\
    ElemType *buf[1];								\
} AT;										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_ElemSize(void)									\
{										\
    return sizeof(ElemType);							\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_BufferSize(size_t numElems)						\
{										\
    return numElems*sizeof(ElemType *);						\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_IsEmpty(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return !arr || arr->size == 0;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType **								\
AT##_First(AT *arr)								\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->buf : NULL;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType **								\
AT##_Last(AT *arr)								\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->buf + arr->size : NULL;					\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Front(AT *arr)								\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(!AT##_IsEmpty(arr));							\
    return arr->buf[0];								\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Back(AT *arr)								\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(!AT##_IsEmpty(arr));							\
    return arr->buf[arr->size - 1];						\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_Size(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->size : 0;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_Capacity(const AT *arr)							\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    return arr ? arr->capacity : 0;						\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Resize(AT **arrp, size_t newCapacity)					\
{										\
    assert(arrp);								\
    assert(!*arrp || (*arrp)->size != 0xdeadbeef);				\
    if (newCapacity == 0) {							\
	assert(!*arrp || ((*arrp)->size = 0xdeadbeef));				\
	ckfree(*arrp);								\
	*arrp = NULL;								\
    } else {									\
	int init = *arrp == NULL;						\
	size_t memSize = AT##_BufferSize(newCapacity - 1) + sizeof(AT);		\
	*arrp = (AT *)ckrealloc(*arrp, memSize);					\
	if (init) {								\
	    (*arrp)->size = 0;							\
	} else if (newCapacity < (*arrp)->size) {				\
	    (*arrp)->size = newCapacity;					\
	}									\
	(*arrp)->capacity = newCapacity;					\
    }										\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Clear(AT *arr, size_t from, size_t to)					\
{										\
    assert(arr);								\
    assert(arr->size != 0xdeadbeef);						\
    assert(to <= AT##_Capacity(arr));						\
    assert(from <= to);								\
    memset(arr->buf + from, 0, AT##_BufferSize(to - from));			\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_ResizeAndClear(AT **arrp, size_t newCapacity)				\
{										\
    size_t oldCapacity;								\
    assert(arrp);								\
    oldCapacity = *arrp ? (*arrp)->capacity : 0;				\
    AT##_Resize(arrp, newCapacity);						\
    if (newCapacity > oldCapacity) {						\
	AT##_Clear(*arrp, oldCapacity, newCapacity);				\
    }										\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_SetSize(AT *arr, size_t newSize)						\
{										\
    assert(arr);								\
    assert(newSize <= AT##_Capacity(arr));					\
    arr->size = newSize;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Append(AT **arrp, ElemType *elem)						\
{										\
    assert(arrp);								\
    if (!*arrp) {								\
	AT##_Resize(arrp, 1);							\
    } else if ((*arrp)->size == (*arrp)->capacity) {				\
	AT##_Resize(arrp, (*arrp)->capacity + ((*arrp)->capacity + 1)/2);	\
    }										\
    (*arrp)->buf[(*arrp)->size++] = elem;					\
}										\
										\
__TK_ARRAY_UNUSED								\
static size_t									\
AT##_PopBack(AT *arr)								\
{										\
    assert(!AT##_IsEmpty(arr));							\
    return arr->size -= 1;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static ElemType *								\
AT##_Get(const AT *arr, size_t at)						\
{										\
    assert(arr);								\
    assert(at < AT##_Size(arr));						\
    return arr->buf[at];							\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Set(AT *arr, size_t at, ElemType *elem)					\
{										\
    assert(arr);								\
    assert(at < AT##_Size(arr));						\
    arr->buf[at] = elem;							\
}										\
										\
__TK_ARRAY_UNUSED								\
static void									\
AT##_Free(AT **arrp)								\
{										\
    AT##_Resize(arrp, 0);							\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_Find(const AT *arr, const ElemType *elem)					\
{										\
    assert(!arr || arr->size != 0xdeadbeef);					\
    if (arr) {									\
	ElemType *const *buf = arr->buf;					\
	size_t i;								\
	for (i = 0; i < arr->size; ++i) {					\
	    if (buf[i] == elem) {						\
		return (int) i;							\
	    }									\
	}									\
    }										\
    return -1;									\
}										\
										\
__TK_ARRAY_UNUSED								\
static int									\
AT##_Contains(const AT *arr, const ElemType *elem)				\
{										\
    return AT##_Find(arr, elem) != -1;						\
}										\
/* ------------------------------------------------------------------------- */

#endif /* TK_ARRAY_DEFINED */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 105
 * End:
 * vi:set ts=8 sw=4:
 */

Changes to generic/tkAtom.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17








-
-
+
+







/*
 * tkAtom.c --
 *
 *	This file manages a cache of X Atoms in order to avoid interactions
 *	with the X server. It's much like the Xmu routines, except it has a
 *	cleaner interface (caller doesn't have to provide permanent storage
 *	for atom names, for example).
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

150
151
152
153
154
155
156
157

158
159

160
161

162
163
164
165
166
167
168
150
151
152
153
154
155
156

157
158

159
160

161
162
163
164
165
166
167
168







-
+

-
+

-
+







	}
	Tk_DeleteErrorHandler(handler);
	hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew);
	Tcl_SetHashValue(hPtr, INT2PTR(atom));
	if (mustFree) {
	    XFree(mustFree);
	}
	name = (const char *)Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
	name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
	hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew);
	Tcl_SetHashValue(hPtr, (char *)name);
	Tcl_SetHashValue(hPtr, name);
    }
    return (const char *)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *--------------------------------------------------------------
 *
 * AtomInit --
 *
196
197
198
199
200
201
202
203

204
205

206
207
208
209
210
211
212
213
214
215
196
197
198
199
200
201
202

203
204

205
206
207
208
209
210
211
212
213
214
215







-
+

-
+










	if (hPtr != NULL) {
	    continue;
	}

	name = atomNameArray[atom - 1];
	hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew);
	Tcl_SetHashValue(hPtr, INT2PTR(atom));
	name = (const char *)Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
	name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
	hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew);
	Tcl_SetHashValue(hPtr, (char *)name);
	Tcl_SetHashValue(hPtr, name);
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkBind.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20

21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115






116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180








181
182
183
184
185

186
187
188
189
190
191













192
193
194
195





196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215








216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239








240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261












262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294
295

296
297
298
299

300
301
302
303
304
305









306
307
308
309
310
311
312








313
314
315
316







317
318
319
320

321





322
323


324
325
326
327

328
329
330
331















332
333
334
335
336
337
338
339






340
341
342
343
344
345
346
347
348
349


350
351


352
353
354
355
356
357
358
359
360
361
362
363
364
365







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392


393
394








395
396
397
398
399
400
401
402
403
404
405





406
407
408
409
410
411
412
413
414







415
416
417
418
419
420




421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512




513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569



















570
571
572
573
574




575
576
577
578
579
580
581
582


583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
1
2
3
4
5
6



7
8
9

10
11
12
13
14
15


16

17
18
19
20

21
22
23
24








25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42





















































43
44
45
46


47

48


49
50
51
52
53
54
55
56




















































57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77



78
79





80
81
82
83
84
85
86
87
88
89
90
91
92




93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114




115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140






141
142
143
144
145
146
147
148
149
150
151
152
153



154
155
156

157










158
159
160
161
162
163
164
165
166
167
168
169
170
171








172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191




192




193






194
195
196
197
198
199
200
201
202







203
204
205
206
207
208
209
210




211
212
213
214
215
216
217
218
219
220

221

222
223
224
225
226
227

228
229
230
231
232

233
234
235


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256


257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274

275
276
277
278
279
280
281
282
283
284
285





286
287
288
289
290
291
292


293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335



336
337
338
339
340
341
342
343
344
345




346
347
348
349
350
351
352
353
354




355
356
357
358
359
360
361
362
363
364

365

366
367
368
369
370
371
372
373
374
375
376
377








378
379

380





381
382

383



384
385

386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405


406
407
408
409
410
411
412
413
414
415
416
417
418
419

420

421
422

423



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454


455
456
457
458
459
460
461
462



















463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481





482
483
484
485
486







487
488













489
490
491
492
493
494
495






-
-
-
+
+
+
-






-
-

-
+



-
+



-
-
-
-
-
-
-
-







-
+
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-

-
+
-
-
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











+
+
+
+
+
+
+
+


-
-
-
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
















+
-
-
-
-
+
+
+
+
+
+
+
+


















-
-
-
-
-
-
+
+
+
+
+
+
+
+





-
-
-



-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-



















-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+



-
+
-
+
+
+
+
+

-
+
+



-
+


-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
-
+
+
+
+
+
+









-
+
+

-
+
+









-
-
-
-
-
+
+
+
+
+
+
+
-
-














-
+








-
-
+
+


+
+
+
+
+
+
+
+








-
-
-
+
+
+
+
+





-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+






-

-












-
-
-
-
-
-
-
-


-

-
-
-
-
-


-

-
-
-


-

-



















-
-
+
+
+











-

-


-

-
-
-
+
+
+
+


















-









-
-








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * tkBind.c --
 *
 *	This file provides functions that associate Tcl commands with X events
 *	or sequences of X events.
 *
 * Copyright © 1989-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998 Scriptics Corporation.
 * Copyright (c) 1989-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998 by Scriptics Corporation.
 * Copyright © 2018-2019 Gregor Cramer.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkDList.h"
#include "tkArray.h"

#if defined(_WIN32)
#ifdef _WIN32
#include "tkWinInt.h"
#elif defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#else /* if defined(__unix__) */
#else
#include "tkUnixInt.h"
#endif

#ifdef NDEBUG
# define DEBUG(expr)
#else
# define DEBUG(expr) expr
#endif

#define SIZE_OF_ARRAY(arr) (sizeof(arr)/sizeof(arr[0]))

/*
 * File structure:
 *
 * Structure definitions and static variables.
 *
 * Init/Free this package.
 *
 * Tcl "bind" command (actually located in tkCmds.c) core implementation, plus helpers.
 * Tcl "bind" command (actually located in tkCmds.c) core implementation, plus
 * helpers.
 *
 * Tcl "event" command implementation, plus helpers.
 *
 * Package-specific common helpers.
 *
 * Non-package-specific helpers.
 */

/*
 * In old implementation (the one that used an event ring), <Double-1> and <1><1> were
 * equivalent sequences. However it is logical to give <Double-1> higher precedence
 * since it is more specific. Indeed <Double-1> includes time and space requirements,
 * which is not the case for <1><1>.
 * This is achieved by setting PREFER_MOST_SPECIALIZED_EVENT to 1.
 */

#ifndef PREFER_MOST_SPECIALIZED_EVENT
# define PREFER_MOST_SPECIALIZED_EVENT 1
#endif

/*
 * Traditionally motion events can be combined with buttons in this way: <B1-B2-Motion>.
 * However it should be allowed to express this as <Motion-1-2> in addition. This is achieved
 * by setting SUPPORT_ADDITIONAL_MOTION_SYNTAX to 1.
 */

#ifndef SUPPORT_ADDITIONAL_MOTION_SYNTAX
# define SUPPORT_ADDITIONAL_MOTION_SYNTAX 1
#endif

/*
 * The output for motion events is of the type <B1-Motion>. This can be changed to become
 * <Motion-1> instead by setting PRINT_SHORT_MOTION_SYNTAX to 1, however this would be a
 * backwards incompatibility.
 */

#ifndef PRINT_SHORT_MOTION_SYNTAX
# define PRINT_SHORT_MOTION_SYNTAX 0 /* set to 1 if wanted */
#endif

#if !SUPPORT_ADDITIONAL_MOTION_SYNTAX
# undef PRINT_SHORT_MOTION_SYNTAX
# define PRINT_SHORT_MOTION_SYNTAX 0
#endif

/*
 * For debugging only, normally set to zero.
 */

#ifdef SUPPORT_DEBUGGING
# undef SUPPORT_DEBUGGING
#endif
#define SUPPORT_DEBUGGING 0

/*
 * Test validity of PSEntry items.
 */

# define TEST_PSENTRY(psPtr) psPtr->number != 0xdeadbeef
# define MARK_PSENTRY(psPtr) psPtr->number = 0xdeadbeef

/*
 * The following union is used to hold the detail information from an XEvent
 * (including Tk's XVirtualEvent extension).
 */

typedef KeySym Info;

typedef union {
    Info info;		/* This either corresponds to xkey.keycode, or to xbutton.button,
    KeySym keySym;		/* KeySym that corresponds to xkey.keycode. */
    			 * or is meaningless, depending on event type. */
    Tk_Uid name;	/* Tk_Uid of virtual event. */
    int button;			/* Button that was pressed (xbutton.button). */
    Tk_Uid name;		/* Tk_Uid of virtual event. */
    ClientData clientData;	/* Used when type of Detail is unknown, and to
				 * ensure that all bytes of Detail are
				 * initialized when this structure is used in
				 * a hash key. */
} Detail;

/*
 * We need an extended event definition.
 */

typedef struct {
    XEvent xev;		/* The original event from server. */
    Detail detail;	/* Additional information (for hashing). */
    unsigned countAny;	/* Count of multi-events, like multi-clicks, or repeated key pressing,
    			 * this count does not depend on detail (keySym or button). */
    unsigned countDetailed;
    			/* Count of multi-events, like multi-clicks, or repeated key pressing,
    			 * this count considers the detail (keySym or button). */
} Event;

struct PatSeq; /* forward declaration */

/* We need this array for bookkeeping the last matching modifier mask per pattern. */
TK_ARRAY_DEFINE(PSModMaskArr, unsigned);

typedef struct PSEntry {
    TK_DLIST_LINKS(PSEntry);	/* Makes this struct a doubly linked list; must be first entry. */
    Window window;		/* Window of last match. */
    struct PatSeq* psPtr;	/* Pointer to pattern sequence. */
    PSModMaskArr *lastModMaskArr;
    				/* Last matching modifier mask per pattern (except last pattern).
    				 * Only needed if pattern sequence is not single (more than one
				 * pattern), and if one of these patterns contains a non-zero
				 * modifier mask. */
    unsigned count;		/* Only promote to next level if this count has reached count of
    				 * pattern. */
    unsigned expired:1;		/* Whether this entry is expired, this means it has to be removed
    				 * from promotion list. */
    unsigned keepIt:1;		/* Whether to keep this entry, even if expired. */
} PSEntry;

/* Defining the whole PSList_* stuff (list of PSEntry items). */
TK_DLIST_DEFINE(PSList, PSEntry);

/* Don't keep larger arrays of modifier masks inside PSEntry. */
#define MAX_MOD_MASK_ARR_SIZE 8

/*
 * Maps and lookup tables from an event to a list of patterns that match that event.
 */

typedef struct {
    Tcl_HashTable patternTable;	/* Keys are PatternTableKey structs, values are (PatSeq *). */
    Tcl_HashTable listTable;	/* Keys are PatternTableKey structs, values are (PSList *). */
    PSList entryPool;		/* Contains free (unused) list items. */
    unsigned number;		/* Needed for enumeration of pattern sequences. */
} LookupTables;

/*
 * The structure below represents a binding table. A binding table represents
 * a domain in which event bindings may occur. It includes a space of objects
 * relative to which events occur (usually windows, but not always), a history
 * of recent events in the domain, and a set of mappings that associate
 * particular Tcl commands with sequences of events in the domain. Multiple
 * binding tables may exist at once, either because there are multiple
 * applications open, or because there are multiple domains within an
 * application with separate event bindings for each (for example, each canvas
 * widget has a separate binding table for associating events with the items
 * in the canvas).
 *
 * Note: it is probably a bad idea to reduce EVENT_BUFFER_SIZE much below 30.
 * To see this, consider a triple mouse button click while the Shift key is
 * down (and auto-repeating). There may be as many as 3 auto-repeat events
 * after each mouse button press or release (see the first large comment block
 * within Tk_BindEvent for more on this), for a total of 20 events to cover
 * the three button presses and two intervening releases. If you reduce
 * EVENT_BUFFER_SIZE too much, shift multi-clicks will be lost.
 */

/* Defining the whole PromArr_* stuff (array of PSList entries) */
TK_ARRAY_DEFINE(PromArr, PSList);

#define EVENT_BUFFER_SIZE 30
typedef struct Tk_BindingTable_ {
    Event eventInfo[TK_LASTEVENT];
    				/* Containing the most recent event for every event type. */
    PromArr *promArr;		/* Contains the promoted pattern sequences. */
    Event *curEvent;		/* Pointing to most recent event. */
    unsigned curModMask;		/* Containing the current modifier mask. */
    XEvent eventRing[EVENT_BUFFER_SIZE];
				/* Circular queue of recent events (higher
				 * indices are for more recent events). */
    Detail detailRing[EVENT_BUFFER_SIZE];
				/* "Detail" information (keySym, button,
				 * Tk_Uid, or 0) for each entry in
				 * eventRing. */
    int curEvent;		/* Index in eventRing of most recent event.
				 * Newer events have higher indices. */
    Tcl_HashTable patternTable;	/* Used to map from an event to a list of
				 * patterns that may match that event. Keys
				 * are PatternTableKey structs, values are
				 * (PatSeq *). */
    LookupTables lookupTables;	/* Containing hash tables for fast lookup. */
    Tcl_HashTable objectTable;	/* Used to map from an object to a list of patterns associated with
    				 * that object. Keys are ClientData, values are (PatSeq *). */
    Tcl_Interp *interp;		/* Interpreter in which commands are executed. */
    Tcl_HashTable objectTable;	/* Used to map from an object to a list of
				 * patterns associated with that object. Keys
				 * are ClientData, values are (PatSeq *). */
    Tcl_Interp *interp;		/* Interpreter in which commands are
				 * executed. */
} BindingTable;

/*
 * The following structure represents virtual event table. A virtual event
 * table provides a way to map from platform-specific physical events such as
 * button clicks or key presses to virtual events such as <<Paste>>,
 * <<Close>>, or <<ScrollWindow>>.
 *
 * A virtual event is usually never part of the event stream, but instead is
 * synthesized inline by matching low-level events. However, a virtual event
 * may be generated by platform-specific code or by Tcl commands. In that case,
 * no lookup of the virtual event will need to be done using this table,
 * because the virtual event is actually in the event stream.
 */

typedef struct {
    Tcl_HashTable patternTable;	/* Used to map from a physical event to a list
    LookupTables lookupTables;	/* Providing fast lookup tables to lists of pattern sequences. */
    Tcl_HashTable nameTable;	/* Used to map a virtual event name to the array of physical events
    				 * that can trigger it. Keys are the Tk_Uid names of the virtual
				 * events, values are PhysOwned structs. */
				 * of patterns that may match that event. Keys
				 * are PatternTableKey structs, values are
				 * (PatSeq *). */
    Tcl_HashTable nameTable;	/* Used to map a virtual event name to the
				 * array of physical events that can trigger
				 * it. Keys are the Tk_Uid names of the
				 * virtual events, values are PhysicalsOwned
				 * structs. */
} VirtualEventTable;

/*
 * The following structure is used as a key in a patternTable for both binding
 * tables and a virtual event tables.
 *
 * In a binding table, the object field corresponds to the binding tag for the
 * widget whose bindings are being accessed.
 *
 * In a virtual event table, the object field is always NULL. Virtual events
 * are a global definiton and are not tied to a particular binding tag.
 *
 * The same key is used for both types of pattern tables so that the helper
 * functions that traverse and match patterns will work for both binding
 * tables and virtual event tables.
 */

typedef struct {
    void *object;		/* For binding table, identifies the binding tag of the object
    				 * (or class of objects) relative to which the event occurred.
				 * For virtual event table, always NULL. */
    unsigned type;		/* Type of event (from X). */
    Detail detail;		/* Additional information, such as keysym, button, Tk_Uid, or zero
    				 * if nothing additional. */
    ClientData object;		/* For binding table, identifies the binding
				 * tag of the object (or class of objects)
				 * relative to which the event occurred. For
				 * virtual event table, always NULL. */
    int type;			/* Type of event (from X). */
    Detail detail;		/* Additional information, such as keysym,
				 * button, Tk_Uid, or 0 if nothing
				 * additional. */
} PatternTableKey;

/*
 * The following structure defines a pattern, which is matched against X
 * events as part of the process of converting X events into Tcl commands.
 *
 * For technical reasons we do not use 'union Detail', although this would
 * be possible, instead 'info' and 'name' are both included.
 */

typedef struct {
    unsigned eventType;		/* Type of X event, e.g. ButtonPress. */
    int eventType;		/* Type of X event, e.g. ButtonPress. */
    unsigned count;		/* Multi-event count, e.g. double-clicks, triple-clicks, etc. */
    unsigned modMask;		/* Mask of modifiers that must be present (zero means no modifiers
    				 * are required). */
    Info info;			/* Additional information that must match event. Normally this is zero,
    				 * meaning no additional information must match. For KeyPress and
				 * KeyRelease events, it may be specified to select a particular
				 * keystroke (zero means any keystrokes). For button events, specifies
				 * a particular button (zero means any buttons are OK). */
    Tk_Uid name;		/* Specifies the Tk_Uid of the virtual event name. NULL if not a
    				 * virtual event. */
    int needMods;		/* Mask of modifiers that must be present (0
				 * means no modifiers are required). */
    Detail detail;		/* Additional information that must match
				 * event. Normally this is 0, meaning no
				 * additional information must match. For
				 * KeyPress and KeyRelease events, a keySym
				 * may be specified to select a particular
				 * keystroke (0 means any keystrokes). For
				 * button events, specifies a particular
				 * button (0 means any buttons are OK). For
				 * virtual events, specifies the Tk_Uid of the
				 * virtual event name (never 0). */
} TkPattern;

/*
 * The following structure keeps track of all the virtual events that are
 * associated with a particular physical event. It is pointed to by the 'owners'
 * field in a PatSeq in the patternTable of a virtual event table.
 */

TK_PTR_ARRAY_DEFINE(VirtOwners, Tcl_HashEntry); /* define array of hash entries */

/*
 * The following structure defines a pattern sequence, which consists of one
 * or more patterns. In order to trigger, a pattern sequence must match the
 * most recent X events (first pattern to most recent event, next pattern to
 * next event, and so on). It is used as the hash value in a patternTable for
 * both binding tables and virtual event tables.
 *
 * In a binding table, it is the sequence of physical events that make up a
 * binding for an object.
 *
 * In a virtual event table, it is the sequence of physical events that define
 * a virtual event.
 *
 * The same structure is used for both types of pattern tables so that the
 * helper functions that traverse and match patterns will work for both
 * binding tables and virtual event tables.
 */

typedef struct PatSeq {
    unsigned numPats;		/* Number of patterns in sequence (usually 1). */
    int numPats;		/* Number of patterns in sequence (usually
    unsigned count;		/* Total number of repetition counts, summed over count in TkPattern. */
    unsigned number;		/* Needed for the decision whether a binding is less recently defined
    				 * than another, it is guaranteed that the most recently bound event
				 * has the highest number. */
				 * 1). */
    unsigned added:1;		/* Is this pattern sequence already added to lookup table? */
    unsigned modMaskUsed:1;	/* Does at least one pattern contain a non-zero modifier mask? */
    DEBUG(unsigned owned:1;)	/* For debugging purposes. */
    char *script;		/* Binding script to evaluate when sequence matches (ckalloc()ed) */
    char *script;		/* Binding script to evaluate when sequence
    Tcl_Obj* object;		/* Token for object with which binding is associated. For virtual
    				 * event table this is NULL. */
    struct PatSeq *nextSeqPtr;	/* Next in list of all pattern sequences that have the same initial
    				 * pattern. NULL means end of list. */
    Tcl_HashEntry *hPtr;	/* Pointer to hash table entry for the initial pattern. This is the
    				 * head of the list of which nextSeqPtr forms a part. */
				 * matches (ckalloc()ed) */
    int flags;			/* Miscellaneous flag values; see below for
				 * definitions. */
    struct PatSeq *nextSeqPtr;	/* Next in list of all pattern sequences that
				 * have the same initial pattern. NULL means
				 * end of list. */
    Tcl_HashEntry *hPtr;	/* Pointer to hash table entry for the initial
				 * pattern. This is the head of the list of
				 * which nextSeqPtr forms a part. */
    union {
	VirtOwners *owners;	/* In a binding table it has no meaning. In a virtual event table,
				 * identifies the array of virtual events that can be triggered
				 * by this event. */
	struct PatSeq *nextObj;	/* In a binding table, next in list of all pattern sequences for
				 * the same object (NULL for end of list). Needed to implement
				 * Tk_DeleteAllBindings. In a virtual event table it has no meaning. */
    struct VirtualOwners *voPtr;/* In a binding table, always NULL. In a
				 * virtual event table, identifies the array
				 * of virtual events that can be triggered by
				 * this event. */
    struct PatSeq *nextObjPtr;	/* In a binding table, next in list of all
				 * pattern sequences for the same object (NULL
				 * for end of list). Needed to implement
				 * Tk_DeleteAllBindings. In a virtual event
    } ptr;
    TkPattern pats[1];		/* Array of "numPats" patterns. Only one element is declared here
    				 * but in actuality enough space will be allocated for "numPats"
				 * patterns (but usually 1). */
				 * table, always NULL. */
    TkPattern pats[1];		/* Array of "numPats" patterns. Only one
				 * element is declared here but in actuality
				 * enough space will be allocated for
				 * "numPats" patterns. To match, pats[0] must
				 * match event n, pats[1] must match event
				 * n-1, etc. */
} PatSeq;

/*
 * Compute memory size of struct PatSeq with given pattern size.
 * Flag values for PatSeq structures:
 * The caller must be sure that pattern size is greater than zero.
 *
 * PAT_NEARBY		1 means that all of the events matching this sequence
 *			must occur with nearby X and Y mouse coordinates and
 *			close in time. This is typically used to restrict
 *			multiple button presses.
 */
#define PATSEQ_MEMSIZE(numPats) (sizeof(PatSeq) + (numPats - 1)*sizeof(TkPattern))

#define PAT_NEARBY		0x1

/*
 * Constants that define how close together two events must be in milliseconds
 * or pixels to be considered close in space or time.
 * or pixels to meet the PAT_NEARBY constraint:
 */

#define NEARBY_PIXELS	5
#define NEARBY_MS	500
#define NEARBY_PIXELS		5
#define NEARBY_MS		500

/*
 * The following structure keeps track of all the virtual events that are
 * associated with a particular physical event. It is pointed to by the voPtr
 * field in a PatSeq in the patternTable of a virtual event table.
 */

typedef struct VirtualOwners {
    int numOwners;		/* Number of virtual events to trigger. */
    Tcl_HashEntry *owners[1];	/* Array of pointers to entries in nameTable.
				 * Enough space will actually be allocated for
				 * numOwners hash entries. */
} VirtualOwners;

/*
 * The following structure is used in the nameTable of a virtual event table
 * to associate a virtual event with all the physical events that can trigger
 * it.
 */

TK_PTR_ARRAY_DEFINE(PhysOwned, PatSeq); /* define array of pattern seqs */
typedef struct {
    int numOwned;		/* Number of physical events owned. */
    PatSeq *patSeqs[1];		/* Array of pointers to physical event
				 * patterns. Enough space will actually be
				 * allocated to hold numOwned. */
} PhysicalsOwned;

/*
 * One of the following structures exists for each interpreter. This structure
 * keeps track of the current display and screen in the interpreter, so that a
 * command can be invoked whenever the display/screen changes (the command does
 * things like point tk::Priv at a display-specific structure).
 */

typedef struct {
    TkDisplay *curDispPtr;	/* Display for last binding command invoked in this application. */
    TkDisplay *curDispPtr;	/* Display for last binding command invoked in
				 * this application. */
    int curScreenIndex;		/* Index of screen for last binding command */
    unsigned bindingDepth;	/* Number of active instances of Tk_BindEvent in this application. */
    int bindingDepth;		/* Number of active instances of Tk_BindEvent
				 * in this application. */
} ScreenInfo;

/*
 * The following structure keeps track of all the information local to the
 * binding package on a per interpreter basis.
 */

typedef struct TkBindInfo_ {
    VirtualEventTable virtualEventTable;
				/* The virtual events that exist in this interpreter. */
    ScreenInfo screenInfo;	/* Keeps track of the current display and screen, so it can be
    				 * restored after a binding has executed. */
    int deleted;		/* 1 if the application has been deleted but the structure has been
    				 * preserved. */
				/* The virtual events that exist in this
				 * interpreter. */
    ScreenInfo screenInfo;	/* Keeps track of the current display and
				 * screen, so it can be restored after a
				 * binding has executed. */
    int deleted;		/* 1 the application has been deleted but the
				 * structure has been preserved. */
    Time lastEventTime;		/* Needed for time measurement. */
    Time lastCurrentTime;	/* Needed for time measurement. */
} BindInfo;

/*
 * In X11R4 and earlier versions, XStringToKeysym is ridiculously slow. The
 * data structure and hash table below, along with the code that uses them,
 * implement a fast mapping from strings to keysyms. In X11R5 and later
 * releases XStringToKeysym is plenty fast so this stuff isn't needed. The
 * #define REDO_KEYSYM_LOOKUP is normally undefined, so that XStringToKeysym
 * gets used. It can be set in the Makefile to enable the use of the hash
 * table below.
 */

#ifdef REDO_KEYSYM_LOOKUP
typedef struct {
    const char *name;		/* Name of keysym. */
    const char *name;			/* Name of keysym. */
    KeySym value;		/* Numeric identifier for keysym. */
} KeySymInfo;
static const KeySymInfo keyArray[] = {
#ifndef lint
#include "ks_names.h"
#endif
    {NULL, 0}
};
static Tcl_HashTable keySymTable;	/* keyArray hashed by keysym value. */
static Tcl_HashTable nameTable;		/* keyArray hashed by keysym name. */
static Tcl_HashTable keySymTable; /* keyArray hashed by keysym value. */
static Tcl_HashTable nameTable;	/* keyArray hashed by keysym name. */
#endif /* REDO_KEYSYM_LOOKUP */

/*
 * Set to non-zero when the package-wide static variables have been
 * initialized.
 */

static int initialized = 0;
TCL_DECLARE_MUTEX(bindMutex)

/*
 * A hash table is kept to map from the string names of event modifiers to
 * information about those modifiers. The structure for storing this
 * information, and the hash table built at initialization time, are defined
 * below.
 */

typedef struct {
    const char *name;	/* Name of modifier. */
    unsigned mask;	/* Button/modifier mask value, such as Button1Mask. */
    unsigned flags;	/* Various flags; see below for definitions. */
    const char *name; /* Name of modifier. */
    int mask;			/* Button/modifier mask value, such as
				 * Button1Mask. */
    int flags;			/* Various flags; see below for
				 * definitions. */
} ModInfo;

/*
 * Flags for ModInfo structures:
 *
 * DOUBLE -		Non-zero means duplicate this event, e.g. for double-clicks.
 * TRIPLE -		Non-zero means triplicate this event, e.g. for triple-clicks.
 * QUADRUPLE -		Non-zero means quadruple this event, e.g. for 4-fold-clicks.
 * MULT_CLICKS -	Combination of all the above.
 * DOUBLE -		Non-zero means duplicate this event,
 *			e.g. for double-clicks.
 * TRIPLE -		Non-zero means triplicate this event,
 *			e.g. for triple-clicks.
 * QUADRUPLE -		Non-zero means quadruple this event,
 *			e.g. for 4-fold-clicks.
 * MULT_CLICKS -	Combination of all of above.
 */

#define DOUBLE		(1<<0)
#define TRIPLE		(1<<1)
#define QUADRUPLE	(1<<2)
#define MULT_CLICKS	(DOUBLE|TRIPLE|QUADRUPLE)
#define DOUBLE		1
#define TRIPLE		2
#define QUADRUPLE	4
#define MULT_CLICKS	7

static const ModInfo modArray[] = {
    {"Control",		ControlMask,	0},
    {"Shift",		ShiftMask,	0},
    {"Lock",		LockMask,	0},
    {"Meta",		META_MASK,	0},
#ifndef TK_NO_DEPRECATED
    {"M",		META_MASK,	0},
#endif
    {"Alt",		ALT_MASK,	0},
    {"Extended",	EXTENDED_MASK,	0},
    {"B1",		Button1Mask,	0},
    {"Button1",		Button1Mask,	0},
    {"B2",		Button2Mask,	0},
    {"Button2",		Button2Mask,	0},
    {"B3",		Button3Mask,	0},
    {"Button3",		Button3Mask,	0},
    {"B4",		Button4Mask,	0},
    {"Button4",		Button4Mask,	0},
    {"B5",		Button5Mask,	0},
    {"Button5",		Button5Mask,	0},
    {"B6",		Button6Mask,	0},
    {"Button6",		Button6Mask,	0},
    {"B7",		Button7Mask,	0},
    {"Button7",		Button7Mask,	0},
    {"B8",		Button8Mask,	0},
    {"Button8",		Button8Mask,	0},
    {"B9",		Button9Mask,	0},
    {"Button9",		Button9Mask,	0},
    {"Mod1",		Mod1Mask,	0},
    {"M1",		Mod1Mask,	0},
#ifdef MAC_OSX_TK
    {"Command",		Mod1Mask,	0},
#elif defined (_WIN32)
    {"Command",		ControlMask,	0},
#else
    {"Command",		META_MASK,	0},
#endif
    {"Mod2",		Mod2Mask,	0},
    {"M2",		Mod2Mask,	0},
#ifdef MAC_OSX_TK
    {"Option",		Mod2Mask,	0},
#else
    {"Option",		ALT_MASK,	0},
#endif
    {"Mod3",		Mod3Mask,	0},
    {"M3",		Mod3Mask,	0},
    {"Num",		Mod3Mask,	0},
    {"Mod4",		Mod4Mask,	0},
    {"Fn",		Mod4Mask,	0},
    {"M4",		Mod4Mask,	0},
    {"Mod5",		Mod5Mask,	0},
    {"M5",		Mod5Mask,	0},
    {"Double",		0,		DOUBLE},
    {"Triple",		0,		TRIPLE},
    {"Quadruple",	0,		QUADRUPLE},
    {"Any",		0,		0},	/* Ignored: historical relic */
    {NULL,		0,		0}
};
static Tcl_HashTable modTable;

/*
 * This module also keeps a hash table mapping from event names to information
 * about those events. The structure, an array to use to initialize the hash
 * table, and the hash table are all defined below.
 */

typedef struct {
    const char *name;	/* Name of event. */
    unsigned type;	/* Event type for X, such as ButtonPress. */
    unsigned eventMask;	/* Mask bits (for XSelectInput) for this event type. */
    int type;			/* Event type for X, such as ButtonPress. */
    int eventMask;		/* Mask bits (for XSelectInput) for this event
				 * type. */
} EventInfo;

/*
 * Note: some of the masks below are an OR-ed combination of several masks.
 * This is necessary because X doesn't report up events unless you also ask
 * for down events. Also, X doesn't report button state in motion events
 * unless you've asked about button events.
 */

static const EventInfo eventArray[] = {
    {"Key",		KeyPress,		KeyPressMask},
#ifndef TK_NO_DEPRECATED
    {"KeyPress",	KeyPress,		KeyPressMask},
#endif
    {"KeyRelease",	KeyRelease,		KeyPressMask|KeyReleaseMask},
    {"Button",		ButtonPress,		ButtonPressMask},
#ifndef TK_NO_DEPRECATED
    {"ButtonPress",	ButtonPress,		ButtonPressMask},
#endif
    {"ButtonRelease",	ButtonRelease,		ButtonPressMask|ButtonReleaseMask},
    {"Motion",		MotionNotify,		ButtonPressMask|PointerMotionMask},
    {"ButtonRelease",	ButtonRelease,
	    ButtonPressMask|ButtonReleaseMask},
    {"Motion",		MotionNotify,
	    ButtonPressMask|PointerMotionMask},
    {"Enter",		EnterNotify,		EnterWindowMask},
    {"Leave",		LeaveNotify,		LeaveWindowMask},
    {"FocusIn",		FocusIn,		FocusChangeMask},
    {"FocusOut",	FocusOut,		FocusChangeMask},
    {"Expose",		Expose,			ExposureMask},
    {"Visibility",	VisibilityNotify,	VisibilityChangeMask},
    {"Destroy",		DestroyNotify,		StructureNotifyMask},
    {"Unmap",		UnmapNotify,		StructureNotifyMask},
    {"Map",		MapNotify,		StructureNotifyMask},
    {"Reparent",	ReparentNotify,		StructureNotifyMask},
    {"Configure",	ConfigureNotify,	StructureNotifyMask},
    {"Gravity",		GravityNotify,		StructureNotifyMask},
    {"Circulate",	CirculateNotify,	StructureNotifyMask},
    {"Property",	PropertyNotify,		PropertyChangeMask},
    {"Colormap",	ColormapNotify,		ColormapChangeMask},
    {"Activate",	ActivateNotify,		ActivateMask},
    {"Deactivate",	DeactivateNotify,	ActivateMask},
    {"MouseWheel",	MouseWheelEvent,	MouseWheelMask},
    {"TouchpadScroll",  TouchpadScroll,         TouchpadScrollMask},
    {"CirculateRequest", CirculateRequest,	SubstructureRedirectMask},
    {"ConfigureRequest", ConfigureRequest,	SubstructureRedirectMask},
    {"Create",		CreateNotify,		SubstructureNotifyMask},
    {"MapRequest",	MapRequest,		SubstructureRedirectMask},
    {"ResizeRequest",	ResizeRequest,		ResizeRedirectMask},
    {NULL,		0,			0}
};
static Tcl_HashTable eventTable;

static int eventArrayIndex[TK_LASTEVENT];

/*
 * The defines and table below are used to classify events into various
 * groups. The reason for this is that logically identical fields (e.g.
 * "state") appear at different places in different types of events. The
 * classification masks can be used to figure out quickly where to extract
 * information from events.
 */

#define KEY			(1<<0)
#define BUTTON			(1<<1)
#define MOTION			(1<<2)
#define CROSSING		(1<<3)
#define FOCUS			(1<<4)
#define EXPOSE			(1<<5)
#define VISIBILITY		(1<<6)
#define CREATE			(1<<7)
#define DESTROY			(1<<8)
#define UNMAP			(1<<9)
#define MAP			(1<<10)
#define REPARENT		(1<<11)
#define CONFIG			(1<<12)
#define GRAVITY			(1<<13)
#define CIRC			(1<<14)
#define PROP			(1<<15)
#define COLORMAP		(1<<16)
#define VIRTUAL			(1<<17)
#define ACTIVATE		(1<<18)
#define KEY			0x1
#define BUTTON			0x2
#define MOTION			0x4
#define CROSSING		0x8
#define FOCUS			0x10
#define EXPOSE			0x20
#define VISIBILITY		0x40
#define CREATE			0x80
#define DESTROY			0x100
#define UNMAP			0x200
#define MAP			0x400
#define REPARENT		0x800
#define CONFIG			0x1000
#define GRAVITY			0x2000
#define CIRC			0x4000
#define PROP			0x8000
#define COLORMAP		0x10000
#define VIRTUAL			0x20000
#define ACTIVATE		0x40000
#define WHEEL			(1<<19)
#define	MAPREQ			(1<<20)
#define	CONFIGREQ		(1<<21)
#define	RESIZEREQ		(1<<22)
#define CIRCREQ			(1<<23)
#define	MAPREQ			0x80000
#define	CONFIGREQ		0x100000
#define	RESIZEREQ		0x200000
#define CIRCREQ			0x400000

/*
 * These structs agree with xkey for the fields type, serial, send_event, display,
 * window, root, subwindow, time, x, y, x_root, and y_root. So when accessing
 * these fields we may pretend that we are using a struct xkey.
 */

#define HAS_XKEY_HEAD (KEY|BUTTON|MOTION|VIRTUAL|CROSSING|WHEEL)
#define KEY_BUTTON_MOTION_VIRTUAL	(KEY|BUTTON|MOTION|VIRTUAL)
#define KEY_BUTTON_MOTION_CROSSING	(KEY|BUTTON|MOTION|VIRTUAL|CROSSING)

/*
 * The xcrossing struct puts the state field in a different location, but the other
 * events above agree on where state is located.
 */

#define HAS_XKEY_HEAD_AND_STATE (KEY|BUTTON|MOTION|VIRTUAL|WHEEL)

/*
 * Event types which support -warp.
 */

#define CAN_WARP (KEY|BUTTON|MOTION|WHEEL)

static const int flagArray[TK_LASTEVENT] = {
   /* Not used */		0,
   /* Not used */		0,
   /* KeyPress */		KEY,
   /* KeyRelease */		KEY,
   /* ButtonPress */		BUTTON,
629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645
646
647
648
649
650





651
652
653
654
655
656
657
522
523
524
525
526
527
528

529

530
531
532
533
534
535
536
537





538
539
540
541
542
543
544
545
546
547
548
549







-
+
-








-
-
-
-
-
+
+
+
+
+







   /* SelectionNotify */	0,
   /* ColormapNotify */		COLORMAP,
   /* ClientMessage */		0,
   /* MappingNotify */		0,
   /* VirtualEvent */		VIRTUAL,
   /* Activate */		ACTIVATE,
   /* Deactivate */		ACTIVATE,
   /* MouseWheel */		WHEEL,
   /* MouseWheel */		KEY
   /* TouchpadScroll */		WHEEL
};

/*
 * The following table is used to map between the location where an generated
 * event should be queued and the string used to specify the location.
 */

static const TkStateMap queuePosition[] = {
    {-1,		"now"},
    {TCL_QUEUE_HEAD,	"head"},
    {TCL_QUEUE_MARK,	"mark"},
    {TCL_QUEUE_TAIL,	"tail"},
    {-2,		NULL}
    {-1,			"now"},
    {TCL_QUEUE_HEAD,		"head"},
    {TCL_QUEUE_MARK,		"mark"},
    {TCL_QUEUE_TAIL,		"tail"},
    {-2,			NULL}
};

/*
 * The following tables are used as a two-way map between X's internal numeric
 * values for fields in an XEvent and the strings used in Tcl. The tables are
 * used both when constructing an XEvent from user input and when providing
 * data from an XEvent to the user.
674
675
676
677
678
679
680
681
682


683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699






700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723








724
725
726
727
728
729
730
731
732
733
734
735















736
737

738
739

740
741



742
743
744

745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273


1274
1275

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363

1364
1365
1366


1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386

1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404

1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
566
567
568
569
570
571
572


573
574
575
576
577
578
579
580
581
582
583
584
585






586
587
588
589
590
591
592
593
594
595
596
597
598
599
600






601
602
603
604





605
606
607
608
609
610
611
612
613











614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629

630
631

632


633
634
635
636
637

638





























































639





































































































































































































640














641






























































































































































































































642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660







661
662
663
664
665
666



667
668


669




































































670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687

688
689
690

691
692
693
694
695
696
697
698












699

700
701
702
703
704
705

706
707
708
709

710
711
712
713
714
715
716

717
718
719
720
721
722


723

724
725
726
727
728
729
730







-
-
+
+











-
-
-
-
-
-
+
+
+
+
+
+









-
-
-
-
-
-




-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
+
-
-
+
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
-
-
-
-
-
-






-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-





-
+


-
+
+






-
-
-
-
-
-
-
-
-
-
-
-

-
+





-
+



-







-
+





-
-

-







    {NotifyPointer,		"NotifyPointer"},
    {NotifyPointerRoot,		"NotifyPointerRoot"},
    {NotifyDetailNone,		"NotifyDetailNone"},
    {-1, NULL}
};

static const TkStateMap circPlace[] = {
    {PlaceOnTop,	"PlaceOnTop"},
    {PlaceOnBottom,	"PlaceOnBottom"},
    {PlaceOnTop,		"PlaceOnTop"},
    {PlaceOnBottom,		"PlaceOnBottom"},
    {-1, NULL}
};

static const TkStateMap visNotify[] = {
    {VisibilityUnobscured,	  "VisibilityUnobscured"},
    {VisibilityPartiallyObscured, "VisibilityPartiallyObscured"},
    {VisibilityFullyObscured,	  "VisibilityFullyObscured"},
    {-1, NULL}
};

static const TkStateMap configureRequestDetail[] = {
    {None,	"None"},
    {Above,	"Above"},
    {Below,	"Below"},
    {BottomIf,	"BottomIf"},
    {TopIf,	"TopIf"},
    {Opposite,	"Opposite"},
    {None,		"None"},
    {Above,		"Above"},
    {Below,		"Below"},
    {BottomIf,		"BottomIf"},
    {TopIf,		"TopIf"},
    {Opposite,		"Opposite"},
    {-1, NULL}
};

static const TkStateMap propNotify[] = {
    {PropertyNewValue,	"NewValue"},
    {PropertyDelete,	"Delete"},
    {-1, NULL}
};

DEBUG(static int countTableItems = 0;)
DEBUG(static int countEntryItems = 0;)
DEBUG(static int countListItems = 0;)
DEBUG(static int countBindItems = 0;)
DEBUG(static int countSeqItems = 0;)

/*
 * Prototypes for local functions defined in this file:
 */

static void		ChangeScreen(Tcl_Interp *interp, char *dispName, int screenIndex);
static int		CreateVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr,
			    char *virtString, const char *eventString);
static int		DeleteVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr,
			    char *virtString, const char *eventString);
static void		ChangeScreen(Tcl_Interp *interp, char *dispName,
			    int screenIndex);
static int		CreateVirtualEvent(Tcl_Interp *interp,
			    VirtualEventTable *vetPtr, char *virtString,
			    const char *eventString);
static int		DeleteVirtualEvent(Tcl_Interp *interp,
			    VirtualEventTable *vetPtr, char *virtString,
			    const char *eventString);
static void		DeleteVirtualEventTable(VirtualEventTable *vetPtr);
static void		ExpandPercents(TkWindow *winPtr, const char *before, Event *eventPtr,
			    unsigned scriptCount, Tcl_DString *dsPtr);
static PatSeq *		FindSequence(Tcl_Interp *interp, LookupTables *lookupTables,
			    void *object, const char *eventString, int create,
			    int allowVirtual, unsigned *maskPtr);
static void		GetAllVirtualEvents(Tcl_Interp *interp, VirtualEventTable *vetPtr);
static const char *	GetField(const char *p, char *copy, unsigned size);
static Tcl_Obj *	GetPatternObj(const PatSeq *psPtr);
static int		GetVirtualEvent(Tcl_Interp *interp, VirtualEventTable *vetPtr,
			    Tcl_Obj *virtName);
static Tk_Uid		GetVirtualEventUid(Tcl_Interp *interp, char *virtString);
static void		ExpandPercents(TkWindow *winPtr, const char *before,
			    XEvent *eventPtr,KeySym keySym,
			    unsigned int scriptCount, Tcl_DString *dsPtr);
static PatSeq *		FindSequence(Tcl_Interp *interp,
			    Tcl_HashTable *patternTablePtr, ClientData object,
			    const char *eventString, int create,
			    int allowVirtual, unsigned long *maskPtr);
static void		GetAllVirtualEvents(Tcl_Interp *interp,
			    VirtualEventTable *vetPtr);
static char *		GetField(char *p, char *copy, int size);
static Tcl_Obj *	GetPatternObj(PatSeq *psPtr);
static int		GetVirtualEvent(Tcl_Interp *interp,
			    VirtualEventTable *vetPtr, Tcl_Obj *virtName);
static Tk_Uid		GetVirtualEventUid(Tcl_Interp *interp,
			    char *virtString);
static int		HandleEventGenerate(Tcl_Interp *interp, Tk_Window main,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		InitVirtualEventTable(VirtualEventTable *vetPtr);
static PatSeq *		MatchPatterns(TkDisplay *dispPtr, Tk_BindingTable bindPtr, PSList *psList,
static PatSeq *		MatchPatterns(TkDisplay *dispPtr,
			    PSList *psSuccList, unsigned patIndex, const Event *eventPtr,
			    void *object, PatSeq **physPtrPtr);
			    BindingTable *bindPtr, PatSeq *psPtr,
			    PatSeq *bestPtr, ClientData *objectPtr,
			    PatSeq **sourcePtrPtr);
static int		NameToWindow(Tcl_Interp *interp, Tk_Window main,
			    Tcl_Obj *objPtr, Tk_Window *tkwinPtr);
static unsigned		ParseEventDescription(Tcl_Interp *interp, const char **eventStringPtr,
static int		ParseEventDescription(Tcl_Interp *interp,
			    TkPattern *patPtr, unsigned *eventMaskPtr);
static PSList *		GetLookupForEvent(LookupTables* lookupPtr, const Event *eventPtr,
			    Tcl_Obj *object, int onlyConsiderDetailedEvents);
static void		ClearLookupTable(LookupTables *lookupTables, void *object);
static void		ClearPromotionLists(Tk_BindingTable bindPtr, void *object);
static PSEntry *	MakeListEntry(PSList *pool, PatSeq *psPtr, int needModMasks);
static void		RemovePatSeqFromLookup(LookupTables *lookupTables, PatSeq *psPtr);
static void		RemovePatSeqFromPromotionLists(Tk_BindingTable bindPtr, PatSeq *psPtr);
static PatSeq *		DeletePatSeq(PatSeq *psPtr);
static void		InsertPatSeq(LookupTables *lookupTables, PatSeq *psPtr);
#if SUPPORT_DEBUGGING
void			TkpDumpPS(const PatSeq *psPtr);
void			TkpDumpPSList(const PSList *psList);
#endif

/*
 * Some useful helper functions.
 */
#if SUPPORT_DEBUGGING
static int BindCount = 0;  /* Can be set or queried from Tcl through 'event debug' subcommand. Otherwise not used. */
#endif

static Tcl_Size Max(Tcl_Size a, Tcl_Size b) { return a < b ? b : a; }
static int Abs(int n) { return n < 0 ? -n : n; }
static int IsOdd(int n) { return n & 1; }

static int TestNearbyTime(int lhs, int rhs) { return Abs(lhs - rhs) <= NEARBY_MS; }
static int TestNearbyCoords(int lhs, int rhs) { return Abs(lhs - rhs) <= NEARBY_PIXELS; }

static int
IsSubsetOf(
    unsigned lhsMask,	/* Is this a subset... */
    unsigned rhsMask)	/* ...of this bit field? */
{
    return (lhsMask & rhsMask) == lhsMask;
}

static const char*
SkipSpaces(
    const char* s)
{
    assert(s);
    while (isspace(UCHAR(*s)))
	++s;
    return s;
}

static const char*
SkipFieldDelims(
    const char* s)
{
    assert(s);
    while (*s == '-' || isspace(UCHAR(*s))) {
	++s;
    }
    return s;
}

static unsigned
GetButtonNumber(
    const char *field)
			    const char **eventStringPtr, TkPattern *patPtr,
{
    unsigned button;
    assert(field);
    button = (field[0] >= '1' && field[0] <= '9' && field[1] == '\0') ? (unsigned)(field[0] - '0') : 0;
    return (button > 3) ? (button + 4) : button;
}

static Time
CurrentTimeInMilliSecs(void)
{
    Tcl_Time now;

    Tcl_GetTime(&now);
    return ((Time) now.sec)*1000 + ((Time) now.usec)/1000;
}

static Info
GetInfo(
    const PatSeq *psPtr,
    unsigned index)
{
    assert(psPtr);
    assert(index < psPtr->numPats);

    return psPtr->pats[index].info;
}

static unsigned
GetCount(
    const PatSeq *psPtr,
    unsigned index)
{
    assert(psPtr);
    assert(index < psPtr->numPats);

    return psPtr->pats[index].count;
}

static int
CountSpecialized(
    const PatSeq *fstMatchPtr,
    const PatSeq *sndMatchPtr)
{
    int fstCount = 0;
    int sndCount = 0;
    unsigned i;

    assert(fstMatchPtr);
    assert(sndMatchPtr);

    for (i = 0; i < fstMatchPtr->numPats; ++i) {
	if (GetInfo(fstMatchPtr, i)) { fstCount += GetCount(fstMatchPtr, i); }
    }
    for (i = 0; i < sndMatchPtr->numPats; ++i) {
	if (GetInfo(sndMatchPtr, i)) { sndCount += GetCount(sndMatchPtr, i); }
    }

    return sndCount - fstCount;
}

static int
IsKeyEventType(
    int eventType)
{
    return eventType == KeyPress || eventType == KeyRelease;
}

static int
IsButtonEventType(
    unsigned eventType)
{
    return eventType == ButtonPress || eventType == ButtonRelease;
}

static int
MatchEventNearby(
    const XEvent *lhs,	/* Previous button event */
    const XEvent *rhs)	/* Current button event */
{
    assert(lhs);
    assert(rhs);
    assert(IsButtonEventType(lhs->type));
    assert(lhs->type == rhs->type);

    /* assert: lhs->xbutton.time <= rhs->xbutton.time */

    return TestNearbyTime(rhs->xbutton.time, lhs->xbutton.time)
	    && TestNearbyCoords(rhs->xbutton.x_root, lhs->xbutton.x_root)
	    && TestNearbyCoords(rhs->xbutton.y_root, lhs->xbutton.y_root);
}

static int
MatchEventRepeat(
    const XKeyEvent *lhs,	/* Previous key event */
    const XKeyEvent *rhs)	/* Current key event */
{
    assert(lhs);
    assert(rhs);
    assert(IsKeyEventType(lhs->type));
    assert(lhs->type == rhs->type);

    /* assert: lhs->time <= rhs->time */
    return lhs->keycode == rhs->keycode && TestNearbyTime(lhs->time, rhs->time);
}

static void
FreePatSeq(
    PatSeq *psPtr)
{
    assert(psPtr);
    assert(!psPtr->owned);
    DEBUG(MARK_PSENTRY(psPtr);)
    ckfree(psPtr->script);
    if (!psPtr->object) {
	VirtOwners_Free(&psPtr->ptr.owners);
    }
    ckfree(psPtr);
    DEBUG(countSeqItems -= 1;)
}

static void
RemoveListEntry(
    PSList *pool,
    PSEntry *psEntry)
{
    assert(pool);
    assert(psEntry);

    if (PSModMaskArr_Capacity(psEntry->lastModMaskArr) > MAX_MOD_MASK_ARR_SIZE) {
	PSModMaskArr_Free(&psEntry->lastModMaskArr);
    }
    PSList_Remove(psEntry);
    PSList_Append(pool, psEntry);
}

static void
ClearList(
    PSList *psList,
    PSList *pool,
    void *object)
{
    assert(psList);
    assert(pool);

    if (object) {
	PSEntry *psEntry;
	PSEntry *psNext;

	for (psEntry = PSList_First(psList); psEntry; psEntry = psNext) {
	    psNext = PSList_Next(psEntry);
	    if (psEntry->psPtr->object == object) {
		RemoveListEntry(pool, psEntry);
	    }
	}
    } else {
	PSList_Move(pool, psList);
    }
}

static PSEntry *
FreePatSeqEntry(
    TCL_UNUSED(PSList *),
    PSEntry *entry)
{
    PSEntry *next = PSList_Next(entry);

    PSModMaskArr_Free(&entry->lastModMaskArr);
    ckfree(entry);
    return next;
}

static unsigned
ResolveModifiers(
    TkDisplay *dispPtr,
    unsigned modMask)
{
    assert(dispPtr);

    if (dispPtr->metaModMask) {
	if (modMask & META_MASK) {
	    modMask &= ~META_MASK;
	    modMask |= dispPtr->metaModMask;
	}
    }
    if (dispPtr->altModMask) {
	if (modMask & ALT_MASK) {
	    modMask &= ~ALT_MASK;
	    modMask |= dispPtr->altModMask;
	}
    }

    return modMask;
}

static int
ButtonNumberFromState(
    unsigned state)
			    unsigned long *eventMaskPtr);
{
    if (!(state & ALL_BUTTONS)) { return 0; }
    if (state & Button1Mask) { return 1; }
    if (state & Button2Mask) { return 2; }
    if (state & Button3Mask) { return 3; }
    if (state & Button4Mask) { return 4; }
    if (state & Button5Mask) { return 5; }
    if (state & Button6Mask) { return 6; }
    if (state & Button7Mask) { return 7; }
    if (state & Button8Mask) { return 8; }
    return 9;
}

static void
static void		DoWarp(ClientData clientData);
SetupPatternKey(
    PatternTableKey *key,
    const PatSeq *psPtr)
{
    const TkPattern *patPtr;

    assert(key);
    assert(psPtr);

    /* otherwise on some systems the key contains uninitialized bytes */
    memset(key, 0, sizeof(PatternTableKey));

    patPtr = psPtr->pats;
    assert(!patPtr->info || !patPtr->name);

    key->object = psPtr->object;
    key->type = patPtr->eventType;
    if (patPtr->info) {
	key->detail.info = patPtr->info;
    } else {
	key->detail.name = patPtr->name;
    }
}

/*
 *--------------------------------------------------------------
 *
 * MakeListEntry --
 *
 *	Makes new entry item for lookup table. We are using a
 *	pool of items, this avoids superfluous memory allocation/
 *	deallocation.
 *
 * Results:
 *	New entry item.
 *
 * Side effects:
 *	Memory allocated.
 *
 *--------------------------------------------------------------
 */

static PSEntry *
MakeListEntry(
    PSList *pool,
    PatSeq *psPtr,
    int needModMasks)
{
    PSEntry *newEntry = NULL;

    assert(pool);
    assert(psPtr);
    assert(psPtr->numPats > 0);
    assert(TEST_PSENTRY(psPtr));

    if (PSList_IsEmpty(pool)) {
	newEntry = (PSEntry *)ckalloc(sizeof(PSEntry));
	newEntry->lastModMaskArr = NULL;
	DEBUG(countEntryItems += 1;)
    } else {
	newEntry = PSList_First(pool);
	PSList_RemoveHead(pool);
    }

    if (!needModMasks) {
	PSModMaskArr_SetSize(newEntry->lastModMaskArr, 0);
    } else {
	if (PSModMaskArr_Capacity(newEntry->lastModMaskArr) < psPtr->numPats - 1) {
	    PSModMaskArr_Resize(&newEntry->lastModMaskArr, psPtr->numPats - 1);
	}
	PSModMaskArr_SetSize(newEntry->lastModMaskArr, psPtr->numPats - 1);
    }

    newEntry->psPtr = psPtr;
    newEntry->window = None;
    newEntry->expired = 0;
    newEntry->keepIt = 1;
    newEntry->count = 1;
    DEBUG(psPtr->owned = 0;)

    return newEntry;
}

/*
 *--------------------------------------------------------------
 *
 * GetLookupForEvent --
 *
 *	Get specific pattern sequence table for given event.
 *
 * Results:
 *	Specific pattern sequence table for given event.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static PSList *
GetLookupForEvent(
    LookupTables* lookupTables,
    const Event *eventPtr,
    Tcl_Obj *object,
    int onlyConsiderDetailedEvents)
{
    PatternTableKey key;
    Tcl_HashEntry *hPtr;

    assert(lookupTables);
    assert(eventPtr);

    /* Otherwise on some systems the key contains uninitialized bytes. */
    memset(&key, 0, sizeof(PatternTableKey));

    if (onlyConsiderDetailedEvents) {
	switch (eventPtr->xev.type) {
	case ButtonPress:   /* fallthru */
	case ButtonRelease: key.detail.info = eventPtr->xev.xbutton.button; break;
	case MotionNotify:  key.detail.info = ButtonNumberFromState(eventPtr->xev.xmotion.state); break;
	case KeyPress:      /* fallthru */
	case KeyRelease:    key.detail.info = eventPtr->detail.info; break;
	case VirtualEvent:  key.detail.name = eventPtr->detail.name; break;
	}
	if (!key.detail.name) {
	    assert(!key.detail.info);
	    return NULL;
	}
    }

    key.object = object;
    key.type = eventPtr->xev.type;
    hPtr = Tcl_FindHashEntry(&lookupTables->listTable, (char *) &key);
    return hPtr ? (PSList *)Tcl_GetHashValue(hPtr) : NULL;
}

/*
 *--------------------------------------------------------------
 *
 * ClearLookupTable --
 *
 *	Clear lookup table in given binding table, but only those
 *	bindings associated to given object. If object is NULL
 *	then remove all entries.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */
static void
ClearLookupTable(
    LookupTables *lookupTables,
    void *object)
{
    Tcl_HashSearch search;
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *nextPtr;
    PSList *pool = &lookupTables->entryPool;

    assert(lookupTables);

    for (hPtr = Tcl_FirstHashEntry(&lookupTables->listTable, &search); hPtr; hPtr = nextPtr) {
	PSList *psList;

	nextPtr = Tcl_NextHashEntry(&search);

	if (object) {
	    const PatternTableKey *key = (const PatternTableKey *)Tcl_GetHashKey(&lookupTables->listTable, hPtr);
	    if (key->object != object) {
		continue;
	    }
	}

	psList = (PSList *)Tcl_GetHashValue(hPtr);
	PSList_Move(pool, psList);
	ckfree(psList);
	DEBUG(countListItems -= 1;)
	Tcl_DeleteHashEntry(hPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * ClearPromotionLists --
 *
 *	Clear all the lists holding the promoted pattern
 *	sequences, which belongs to given object. If object
 *	is NULL then remove all patterns.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static void
ClearPromotionLists(
    Tk_BindingTable bindPtr,
    void *object)
{
    size_t i, newArraySize = 0;

    assert(bindPtr);

    for (i = 0; i < PromArr_Size(bindPtr->promArr); ++i) {
	PSList *psList = PromArr_Get(bindPtr->promArr, i);
	ClearList(psList, &bindPtr->lookupTables.entryPool, object);
	if (!PSList_IsEmpty(psList)) {
	    newArraySize = i + 1;
	}
    }

    PromArr_SetSize(bindPtr->promArr, newArraySize);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkBindInit --
 *
 *	This function is called when an application is created. It initializes
 *	all the structures used by bindings and virtual events. It must be
 *	called before any other functions in this file are called.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory allocated.
 *
 *---------------------------------------------------------------------------
 */

/*
 * Windows compiler does not allow the definition of these static variables inside a function,
 * otherwise this should belong to function TkBindInit().
 */
TCL_DECLARE_MUTEX(bindMutex);
static int initialized = 0;

void
TkBindInit(
    TkMainInfo *mainPtr)	/* The newly created application. */
{
    BindInfo *bindInfoPtr;

    assert(mainPtr);

    /* Otherwise virtual events can't be supported. */
    if (sizeof(XEvent) < sizeof(XVirtualEvent)) {
	Tcl_Panic("TkBindInit: virtual events can't be supported");
    assert(sizeof(XEvent) >= sizeof(XVirtualEvent));

    }
    /* Is type of TkPattern.info well defined? */
    assert(sizeof(Info) >= sizeof(KeySym));
    assert(sizeof(Info) >= sizeof(unsigned));

    /* Ensure that our matching algorithm is working (when testing detail). */
    assert(sizeof(Detail) == sizeof(Tk_Uid));

    /* Test expected indices of Button1..Button5, otherwise our button handling is not working. */
    assert(Button1 == 1 && Button2 == 2 && Button3 == 3 && Button4 == 4 && Button5 == 5);
    assert(Button2Mask == (Button1Mask << 1));
    assert(Button3Mask == (Button1Mask << 2));
    assert(Button4Mask == (Button1Mask << 3));
    assert(Button5Mask == (Button1Mask << 4));

    /* Test expected values of button motion masks, otherwise our button handling is not working. */
    assert(Button1MotionMask == Button1Mask);
    assert(Button2MotionMask == Button2Mask);
    assert(Button3MotionMask == Button3Mask);
    assert(Button4MotionMask == Button4Mask);
    assert(Button5MotionMask == Button5Mask);

    /* Because we expect zero if keySym is empty. */
    assert(NoSymbol == 0L);

    /* This must be a union, not a struct, otherwise comparison with NULL will not work. */
    assert(offsetof(Detail, name) == offsetof(Detail, info));

    /* We use some constraints about X*Event. */
    assert(offsetof(XButtonEvent, time) == offsetof(XMotionEvent, time));
    assert(offsetof(XButtonEvent, x_root) == offsetof(XMotionEvent, x_root));
    assert(offsetof(XButtonEvent, y_root) == offsetof(XMotionEvent, y_root));
    assert(offsetof(XCreateWindowEvent, border_width) == offsetof(XConfigureEvent, border_width));
    assert(offsetof(XCreateWindowEvent, width) == offsetof(XConfigureEvent, width));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XCirculateRequestEvent, window));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XConfigureEvent, window));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XGravityEvent, window));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XMapEvent, window));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XReparentEvent, window));
    assert(offsetof(XCreateWindowEvent, window) == offsetof(XUnmapEvent, window));
    assert(offsetof(XCreateWindowEvent, x) == offsetof(XConfigureEvent, x));
    assert(offsetof(XCreateWindowEvent, x) == offsetof(XGravityEvent, x));
    assert(offsetof(XCreateWindowEvent, y) == offsetof(XConfigureEvent, y));
    assert(offsetof(XCreateWindowEvent, y) == offsetof(XGravityEvent, y));
    assert(offsetof(XCrossingEvent, time) == offsetof(XEnterWindowEvent, time));
    assert(offsetof(XCrossingEvent, time) == offsetof(XLeaveWindowEvent, time));
    assert(offsetof(XCrossingEvent, time) == offsetof(XKeyEvent, time));
    assert(offsetof(XKeyEvent, root) == offsetof(XButtonEvent, root));
    assert(offsetof(XKeyEvent, root) == offsetof(XCrossingEvent, root));
    assert(offsetof(XKeyEvent, root) == offsetof(XMotionEvent, root));
    assert(offsetof(XKeyEvent, state) == offsetof(XButtonEvent, state));
    assert(offsetof(XKeyEvent, state) == offsetof(XMotionEvent, state));
    assert(offsetof(XKeyEvent, subwindow) == offsetof(XButtonEvent, subwindow));
    assert(offsetof(XKeyEvent, subwindow) == offsetof(XCrossingEvent, subwindow));
    assert(offsetof(XKeyEvent, subwindow) == offsetof(XMotionEvent, subwindow));
    assert(offsetof(XKeyEvent, time) == offsetof(XButtonEvent, time));
    assert(offsetof(XKeyEvent, time) == offsetof(XMotionEvent, time));
    assert(offsetof(XKeyEvent, x) == offsetof(XButtonEvent, x));
    assert(offsetof(XKeyEvent, x) == offsetof(XCrossingEvent, x));
    assert(offsetof(XKeyEvent, x) == offsetof(XMotionEvent, x));
    assert(offsetof(XKeyEvent, x_root) == offsetof(XButtonEvent, x_root));
    assert(offsetof(XKeyEvent, x_root) == offsetof(XCrossingEvent, x_root));
    assert(offsetof(XKeyEvent, x_root) == offsetof(XMotionEvent, x_root));
    assert(offsetof(XKeyEvent, y) == offsetof(XButtonEvent, y));
    assert(offsetof(XKeyEvent, y) == offsetof(XCrossingEvent, y));
    assert(offsetof(XKeyEvent, y) == offsetof(XMotionEvent, y));
    assert(offsetof(XKeyEvent, y_root) == offsetof(XButtonEvent, y_root));
    assert(offsetof(XKeyEvent, y_root) == offsetof(XCrossingEvent, y_root));
    assert(offsetof(XKeyEvent, y_root) == offsetof(XMotionEvent, y_root));

    /*
     * Initialize the static data structures used by the binding package. They
     * are only initialized once, no matter how many interps are created.
     */

    if (!initialized) {
	Tcl_MutexLock(&bindMutex);
	if (!initialized) {
	    Tcl_HashEntry *hPtr;
	    const ModInfo *modPtr;
	    const EventInfo *eiPtr;
	    int newEntry;
	    unsigned i;
#ifdef REDO_KEYSYM_LOOKUP
	    const KeySymInfo *kPtr;

	    Tcl_InitHashTable(&keySymTable, TCL_STRING_KEYS);
	    Tcl_InitHashTable(&nameTable, TCL_ONE_WORD_KEYS);
	    for (kPtr = keyArray; kPtr->name; ++kPtr) {
	    for (kPtr = keyArray; kPtr->name != NULL; kPtr++) {
		hPtr = Tcl_CreateHashEntry(&keySymTable, kPtr->name, &newEntry);
		Tcl_SetHashValue(hPtr, kPtr->value);
		hPtr = Tcl_CreateHashEntry(&nameTable, (char *) kPtr->value, &newEntry);
		hPtr = Tcl_CreateHashEntry(&nameTable, (char *) kPtr->value,
			&newEntry);
		if (newEntry) {
		    Tcl_SetHashValue(hPtr, kPtr->name);
		}
	    }
#endif /* REDO_KEYSYM_LOOKUP */

	    for (i = 0; i < SIZE_OF_ARRAY(eventArrayIndex); ++i) {
		eventArrayIndex[i] = -1;
	    }
	    for (i = 0; i < SIZE_OF_ARRAY(eventArray); ++i) {
		unsigned type = eventArray[i].type;
		assert(type < TK_LASTEVENT);
		assert(type > 0 || i == SIZE_OF_ARRAY(eventArray) - 1);
		if (type > 0 && eventArrayIndex[type] == -1) {
		    eventArrayIndex[type] = i;
		}
	    }

	    Tcl_InitHashTable(&modTable, TCL_STRING_KEYS);
	    for (modPtr = modArray; modPtr->name; ++modPtr) {
	    for (modPtr = modArray; modPtr->name != NULL; modPtr++) {
		hPtr = Tcl_CreateHashEntry(&modTable, modPtr->name, &newEntry);
		Tcl_SetHashValue(hPtr, modPtr);
	    }

	    Tcl_InitHashTable(&eventTable, TCL_STRING_KEYS);
	    for (eiPtr = eventArray; eiPtr->name; ++eiPtr) {
	    for (eiPtr = eventArray; eiPtr->name != NULL; eiPtr++) {
		hPtr = Tcl_CreateHashEntry(&eventTable, eiPtr->name, &newEntry);
		Tcl_SetHashValue(hPtr, eiPtr);
	    }

	    initialized = 1;
	}
	Tcl_MutexUnlock(&bindMutex);
    }

    mainPtr->bindingTable = Tk_CreateBindingTable(mainPtr->interp);

    bindInfoPtr = (BindInfo *)ckalloc(sizeof(BindInfo));
    bindInfoPtr = ckalloc(sizeof(BindInfo));
    InitVirtualEventTable(&bindInfoPtr->virtualEventTable);
    bindInfoPtr->screenInfo.curDispPtr = NULL;
    bindInfoPtr->screenInfo.curScreenIndex = -1;
    bindInfoPtr->screenInfo.bindingDepth = 0;
    bindInfoPtr->deleted = 0;
    bindInfoPtr->lastCurrentTime = CurrentTimeInMilliSecs();
    bindInfoPtr->lastEventTime = 0;
    mainPtr->bindInfo = bindInfoPtr;
    DEBUG(countBindItems += 1;)

    TkpInitializeMenuBindings(mainPtr->interp, mainPtr->bindingTable);
}

/*
 *---------------------------------------------------------------------------
 *
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
744
745
746
747
748
749
750


751
752
753
754
755
756
757
758






759
760
761
762
763
764
765







-
-


+





-
-
-
-
-
-








void
TkBindFree(
    TkMainInfo *mainPtr)	/* The newly created application. */
{
    BindInfo *bindInfoPtr;

    assert(mainPtr);

    Tk_DeleteBindingTable(mainPtr->bindingTable);
    mainPtr->bindingTable = NULL;

    bindInfoPtr = mainPtr->bindInfo;
    DeleteVirtualEventTable(&bindInfoPtr->virtualEventTable);
    bindInfoPtr->deleted = 1;
    Tcl_EventuallyFree(bindInfoPtr, TCL_DYNAMIC);
    mainPtr->bindInfo = NULL;

    DEBUG(countBindItems -= 1;)
    assert(countBindItems > 0 || countTableItems == 0);
    assert(countBindItems > 0 || countEntryItems == 0);
    assert(countBindItems > 0 || countListItems == 0);
    assert(countBindItems > 0 || countSeqItems == 0);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_CreateBindingTable --
 *
1470
1471
1472
1473
1474
1475
1476
1477
1478



1479
1480
1481


1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492


1493
1494

1495
1496
1497
1498


1499
1500
1501
1502
1503
1504
1505
773
774
775
776
777
778
779


780
781
782
783


784
785



786
787
788
789
790



791
792
793

794




795
796
797
798
799
800
801
802
803







-
-
+
+
+

-
-
+
+
-
-
-





-
-
-
+
+

-
+
-
-
-
-
+
+







 *	Memory is allocated for the new table.
 *
 *--------------------------------------------------------------
 */

Tk_BindingTable
Tk_CreateBindingTable(
    Tcl_Interp *interp)		/* Interpreter to associate with the binding table: commands are
    				 * executed in this interpreter. */
    Tcl_Interp *interp)		/* Interpreter to associate with the binding
				 * table: commands are executed in this
				 * interpreter. */
{
    BindingTable *bindPtr = (BindingTable *)ckalloc(sizeof(BindingTable));
    unsigned i;
    BindingTable *bindPtr = ckalloc(sizeof(BindingTable));
    int i;

    assert(interp);
    DEBUG(countTableItems += 1;)

    /*
     * Create and initialize a new binding table.
     */

    memset(bindPtr, 0, sizeof(BindingTable));
    for (i = 0; i < SIZE_OF_ARRAY(bindPtr->eventInfo); ++i) {
	bindPtr->eventInfo[i].xev.type = -1;
    for (i = 0; i < EVENT_BUFFER_SIZE; i++) {
	bindPtr->eventRing[i].type = -1;
    }
    bindPtr->curEvent = bindPtr->eventInfo; /* do not assign NULL */
    bindPtr->curEvent = 0;
    bindPtr->lookupTables.number = 0;
    PromArr_ResizeAndClear(&bindPtr->promArr, 2);
    Tcl_InitHashTable(&bindPtr->lookupTables.listTable, sizeof(PatternTableKey)/sizeof(int));
    Tcl_InitHashTable(&bindPtr->lookupTables.patternTable, sizeof(PatternTableKey)/sizeof(int));
    Tcl_InitHashTable(&bindPtr->patternTable,
	    sizeof(PatternTableKey)/sizeof(int));
    Tcl_InitHashTable(&bindPtr->objectTable, TCL_ONE_WORD_KEYS);
    bindPtr->interp = interp;
    return bindPtr;
}

/*
 *--------------------------------------------------------------
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535


1536
1537
1538
1539

1540
1541

1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
816
817
818
819
820
821
822
823
824
825
826


827
828
829
830


831
832




833

834
835

836
837
838
839










840
841
842
843


844
845

846

847
848



















































849
850
851
852
853
854
855







+



-
-




-
-
+
+
-
-
-
-
+
-

+
-
+



-
-
-
-
-
-
-
-
-
-




-
-
+

-

-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *--------------------------------------------------------------
 */

void
Tk_DeleteBindingTable(
    Tk_BindingTable bindPtr)	/* Token for the binding table to destroy. */
{
    PatSeq *psPtr, *nextPtr;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    assert(bindPtr);

    /*
     * Find and delete all of the patterns associated with the binding table.
     */

    hPtr = Tcl_FirstHashEntry(&bindPtr->lookupTables.patternTable, &search);
    for ( ; hPtr; hPtr = Tcl_NextHashEntry(&search)) {
    for (hPtr = Tcl_FirstHashEntry(&bindPtr->patternTable, &search);
	    hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	PatSeq *nextPtr;
	PatSeq *psPtr;

	for (psPtr = (PatSeq *)Tcl_GetHashValue(hPtr); psPtr; psPtr = nextPtr) {
	for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL; psPtr = nextPtr) {
	    assert(TEST_PSENTRY(psPtr));
	    nextPtr = psPtr->nextSeqPtr;
	    ckfree(psPtr->script);
	    FreePatSeq(psPtr);
	    ckfree(psPtr);
	}
    }

    /*
     * Don't forget to release lookup elements.
     */

    ClearLookupTable(&bindPtr->lookupTables, NULL);
    ClearPromotionLists(bindPtr, NULL);
    PromArr_Free(&bindPtr->promArr);
    DEBUG(countEntryItems -= PSList_Size(&bindPtr->lookupTables.entryPool);)
    PSList_Traverse(&bindPtr->lookupTables.entryPool, FreePatSeqEntry);

    /*
     * Clean up the rest of the information associated with the binding table.
     */

    Tcl_DeleteHashTable(&bindPtr->lookupTables.patternTable);
    Tcl_DeleteHashTable(&bindPtr->lookupTables.listTable);
    Tcl_DeleteHashTable(&bindPtr->patternTable);
    Tcl_DeleteHashTable(&bindPtr->objectTable);

    ckfree(bindPtr);
    DEBUG(countTableItems -= 1;)
}

/*
 *--------------------------------------------------------------
 *
 * InsertPatSeq --
 *
 *	Insert given pattern sequence into lookup table for fast
 *	access.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory allocated.
 *
 *--------------------------------------------------------------
 */

static void
InsertPatSeq(
    LookupTables *lookupTables,
    PatSeq *psPtr)
{
    assert(lookupTables);
    assert(psPtr);
    assert(TEST_PSENTRY(psPtr));
    assert(psPtr->numPats >= 1u);

    if (!(psPtr->added)) {
	PatternTableKey key;
	Tcl_HashEntry *hPtr;
	int isNew;
	PSList *psList;
	PSEntry *psEntry;

	SetupPatternKey(&key, psPtr);
	hPtr = Tcl_CreateHashEntry(&lookupTables->listTable, (char *) &key, &isNew);

	if (isNew) {
	    psList = (PSList *)ckalloc(sizeof(PSList));
	    PSList_Init(psList);
	    Tcl_SetHashValue(hPtr, psList);
	    DEBUG(countListItems += 1;)
	} else {
	    psList = (PSList *)Tcl_GetHashValue(hPtr);
	}

	psEntry = MakeListEntry(&lookupTables->entryPool, psPtr, 0);
	PSList_Append(psList, psEntry);
	psPtr->added = 1;
    }
}
/*
 *--------------------------------------------------------------
 *
 * Tk_CreateBinding --
 *
 *	Add a binding to a binding table, so that future calls to Tk_BindEvent
 *	may execute the command in the binding.
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653












1654
1655
1656

1657
1658

1659
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
870
871
872
873
874
875
876







877
878
879
880
881
882
883
884
885
886
887
888
889
890

891


892
893








894

895

896
897
898
899

900
901
902













903

904
905
906
907
908
909
910
911
912


913
914
915
916
917
918
919
920

921
922
923


924
925

926

927
928
929

930
931
932
933


934
935
936
937

938
939
940
941
942
943
944
945
946







-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
+

-
-
-
-
-
-
-
-

-

-
+

+
+
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
-

+







-
-
+
+
+
+
+
+
+

-



-
-
+
+
-

-
+


-
+



-
-
+
+

+
-
+
+







 *--------------------------------------------------------------
 */

unsigned long
Tk_CreateBinding(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_BindingTable bindPtr,	/* Table in which to create binding. */
    void *object,		/* Token for object with which binding is associated. */
    const char *eventString,	/* String describing event sequence that triggers binding. */
    const char *script,		/* Contains Tcl script to execute when binding triggers. */
    int append)			/* 0 means replace any existing binding for eventString;
    				 * 1 means append to that binding. If the existing binding is
				 * for a callback function and not a Tcl command string, the
				 * existing binding will always be replaced. */
    ClientData object,		/* Token for object with which binding is
				 * associated. */
    const char *eventString,	/* String describing event sequence that
				 * triggers binding. */
    const char *script,		/* Contains Tcl script to execute when
				 * binding triggers. */
    int append)			/* 0 means replace any existing binding for
				 * eventString; 1 means append to that
				 * binding. If the existing binding is for a
				 * callback function and not a Tcl command
				 * string, the existing binding will always be
				 * replaced. */
{
    PatSeq *psPtr;
    unsigned eventMask;
    unsigned long eventMask;
    char *oldStr;
    char *newStr;
    char *newStr, *oldStr;

    assert(bindPtr);
    assert(object);
    assert(eventString);
    assert(script);

    psPtr = FindSequence(interp, &bindPtr->lookupTables, object, eventString,
	    !!*script, 1, &eventMask);

    if (!*script) {
	assert(!psPtr || psPtr->added);
	/* Silently ignore empty scripts -- see SF#3006842 */
	return eventMask;
	return 1;
    }
    psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString,
	    1, 1, &eventMask);
    if (!psPtr) {
    if (psPtr == NULL) {
	return 0;
    }
    assert(TEST_PSENTRY(psPtr));

    if (psPtr->numPats > PromArr_Capacity(bindPtr->promArr)) {
	/*
	 * We have to increase the size of array containing the lists of promoted sequences.
	 * Normally the maximal size is 1, only in very seldom cases a bigger size is needed.
	 * Note that for technical reasons the capacity should be one higher than the expected
	 * maximal size.
	 */
	PromArr_ResizeAndClear(&bindPtr->promArr, psPtr->numPats);
    }

    if (!psPtr->script) {
    if (psPtr->script == NULL) {
	Tcl_HashEntry *hPtr;
	int isNew;
	Tcl_HashEntry *hPtr;

	/*
	 * This pattern sequence was just created. Link the pattern into the
	 * list associated with the object, so that if the object goes away,
	 * these bindings will all automatically be deleted.
	 */

	hPtr = Tcl_CreateHashEntry(&bindPtr->objectTable, (char *) object, &isNew);
	psPtr->ptr.nextObj = isNew ? NULL : (PatSeq *)Tcl_GetHashValue(hPtr);
	hPtr = Tcl_CreateHashEntry(&bindPtr->objectTable, (char *) object,
		&isNew);
	if (isNew) {
	    psPtr->nextObjPtr = NULL;
	} else {
	    psPtr->nextObjPtr = Tcl_GetHashValue(hPtr);
	}
	Tcl_SetHashValue(hPtr, psPtr);
	InsertPatSeq(&bindPtr->lookupTables, psPtr);
    }

    oldStr = psPtr->script;
    if (append && oldStr) {
	size_t length1 = strlen(oldStr);
    if ((append != 0) && (oldStr != NULL)) {
	size_t length1 = strlen(oldStr), length2 = strlen(script);
	size_t length2 = strlen(script);

	newStr = (char *)ckalloc(length1 + length2 + 2);
	newStr = ckalloc(length1 + length2 + 2);
	memcpy(newStr, oldStr, length1);
	newStr[length1] = '\n';
	memcpy(newStr + length1 + 1, script, length2 + 1);
	memcpy(newStr+length1+1, script, length2+1);
    } else {
	size_t length = strlen(script);

	newStr = (char *)ckalloc(length + 1);
	memcpy(newStr, script, length + 1);
	newStr = ckalloc(length + 1);
	memcpy(newStr, script, length+1);
    }
    if (oldStr != NULL) {
    ckfree(oldStr);
	ckfree(oldStr);
    }
    psPtr->script = newStr;
    return eventMask;
}

/*
 *--------------------------------------------------------------
 *
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
959
960
961
962
963
964
965


966
967
968
969
970



971
972
973


974


975
976
977
978




979
980

981



982
983
984
985
986

















987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023



1024


1025
1026
1027
1028
1029
1030
1031
1032







-
-
+
+
+
+

-
-
-
+
+
+
-
-

-
-
+
+
+

-
-
-
-
+
+
-

-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
-
-
+







 *--------------------------------------------------------------
 */

int
Tk_DeleteBinding(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_BindingTable bindPtr,	/* Table in which to delete binding. */
    void *object,		/* Token for object with which binding is associated. */
    const char *eventString)	/* String describing event sequence that triggers binding. */
    ClientData object,		/* Token for object with which binding is
				 * associated. */
    const char *eventString)	/* String describing event sequence that
				 * triggers binding. */
{
    PatSeq *psPtr;

    assert(bindPtr);
    PatSeq *psPtr, *prevPtr;
    unsigned long eventMask;
    Tcl_HashEntry *hPtr;
    assert(object);
    assert(eventString);

    psPtr = FindSequence(interp, &bindPtr->lookupTables, object, eventString, 0, 1, NULL);
    if (!psPtr) {
    psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString,
	    0, 1, &eventMask);
    if (psPtr == NULL) {
	Tcl_ResetResult(interp);
    } else {
	Tcl_HashEntry *hPtr;
	PatSeq *prevPtr;

	return TCL_OK;
    }
	assert(TEST_PSENTRY(psPtr));

	/*
	 * Unlink the binding from the list for its object.
	 */
    /*
     * Unlink the binding from the list for its object, then from the list for
     * its pattern.
     */

	if (!(hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object))) {
	    Tcl_Panic("Tk_DeleteBinding couldn't find object table entry");
	}
	prevPtr = (PatSeq *)Tcl_GetHashValue(hPtr);
	if (prevPtr == psPtr) {
	    Tcl_SetHashValue(hPtr, psPtr->ptr.nextObj);
	} else {
	    for ( ; ; prevPtr = prevPtr->ptr.nextObj) {
		if (!prevPtr) {
		    Tcl_Panic("Tk_DeleteBinding couldn't find on object list");
		}
		if (prevPtr->ptr.nextObj == psPtr) {
		    prevPtr->ptr.nextObj = psPtr->ptr.nextObj;
		    break;
		}
	    }
	}
    hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object);
    if (hPtr == NULL) {
	Tcl_Panic("Tk_DeleteBinding couldn't find object table entry");
    }
    prevPtr = Tcl_GetHashValue(hPtr);
    if (prevPtr == psPtr) {
	Tcl_SetHashValue(hPtr, psPtr->nextObjPtr);
    } else {
	for ( ; ; prevPtr = prevPtr->nextObjPtr) {
	    if (prevPtr == NULL) {
		Tcl_Panic("Tk_DeleteBinding couldn't find on object list");
	    }
	    if (prevPtr->nextObjPtr == psPtr) {
		prevPtr->nextObjPtr = psPtr->nextObjPtr;
		break;
	    }
	}
    }
    prevPtr = Tcl_GetHashValue(psPtr->hPtr);
    if (prevPtr == psPtr) {
	if (psPtr->nextSeqPtr == NULL) {
	    Tcl_DeleteHashEntry(psPtr->hPtr);
	} else {
	    Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr);
	}
    } else {
	for ( ; ; prevPtr = prevPtr->nextSeqPtr) {
	    if (prevPtr == NULL) {
		Tcl_Panic("Tk_DeleteBinding couldn't find on hash chain");
	    }
	    if (prevPtr->nextSeqPtr == psPtr) {
		prevPtr->nextSeqPtr = psPtr->nextSeqPtr;
		break;
	    }
	}
    }

	RemovePatSeqFromLookup(&bindPtr->lookupTables, psPtr);
	RemovePatSeqFromPromotionLists(bindPtr, psPtr);
	DeletePatSeq(psPtr);
    ckfree(psPtr->script);
    }

    ckfree(psPtr);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_GetBinding --
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
1047
1048
1049
1050
1051
1052
1053


1054
1055
1056
1057
1058

1059
1060
1061

1062



1063
1064
1065
1066



1067
1068
1069
1070
1071
1072
1073
1074







-
-
+
+
+
+

-
+
+

-
+
-
-
-
+
+
+
+
-
-
-
+







 *--------------------------------------------------------------
 */

const char *
Tk_GetBinding(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_BindingTable bindPtr,	/* Table in which to look for binding. */
    void *object,		/* Token for object with which binding is associated. */
    const char *eventString)	/* String describing event sequence that triggers binding. */
    ClientData object,		/* Token for object with which binding is
				 * associated. */
    const char *eventString)	/* String describing event sequence that
				 * triggers binding. */
{
    const PatSeq *psPtr;
    PatSeq *psPtr;
    unsigned long eventMask;

    assert(bindPtr);
    psPtr = FindSequence(interp, &bindPtr->patternTable, object, eventString,
    assert(object);
    assert(eventString);

	    0, 1, &eventMask);
    if (psPtr == NULL) {
	return NULL;
    }
    psPtr = FindSequence(interp, &bindPtr->lookupTables, object, eventString, 0, 1, NULL);
    assert(!psPtr || TEST_PSENTRY(psPtr));
    return psPtr ? psPtr->script : NULL;
    return psPtr->script;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_GetAllBindings --
 *
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
1087
1088
1089
1090
1091
1092
1093

1094
1095







1096





































1097

1098


1099



1100



1101






1102
1103






















1104







1105



1106




1107










1108

















1109







1110












1111
1112


1113




1114












1115


1116
1117
1118
1119
1120
1121
1122







-
+

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-

-
-
-
+
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-







 *--------------------------------------------------------------
 */

void
Tk_GetAllBindings(
    Tcl_Interp *interp,		/* Interpreter returning result or error. */
    Tk_BindingTable bindPtr,	/* Table in which to look for bindings. */
    void *object)		/* Token for object. */
    ClientData object)		/* Token for object. */
{
    Tcl_HashEntry *hPtr;

    assert(bindPtr);
    assert(object);

    if ((hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object))) {
	const PatSeq *psPtr;
    PatSeq *psPtr;
	Tcl_Obj *resultObj = Tcl_NewObj();

	/*
	 * For each binding, output information about each of the patterns in its sequence.
	 */

	for (psPtr = (const PatSeq *)Tcl_GetHashValue(hPtr); psPtr; psPtr = psPtr->ptr.nextObj) {
	    assert(TEST_PSENTRY(psPtr));
	    Tcl_ListObjAppendElement(NULL, resultObj, GetPatternObj(psPtr));
	}
	Tcl_SetObjResult(interp, resultObj);
    }
}

/*
 *--------------------------------------------------------------
 *
 * RemovePatSeqFromLookup --
 *
 *	Remove given pattern sequence from lookup tables. This
 *	can be required before deleting the pattern sequence.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static void
RemovePatSeqFromLookup(
    LookupTables *lookupTables,	/* Remove from this lookup tables. */
    PatSeq *psPtr)		/* Remove this pattern sequence. */
{
    PatternTableKey key;
    Tcl_HashEntry *hPtr;

    Tcl_Obj *resultObj;
    assert(lookupTables);
    assert(psPtr);

    SetupPatternKey(&key, psPtr);

    if ((hPtr = Tcl_FindHashEntry(&lookupTables->listTable, (char *) &key))) {
    hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object);
	PSList *psList = (PSList *)Tcl_GetHashValue(hPtr);
	PSEntry *psEntry;

    if (hPtr == NULL) {
	TK_DLIST_FOREACH(psEntry, psList) {
	    if (psEntry->psPtr == psPtr) {
		psPtr->added = 0;
		RemoveListEntry(&lookupTables->entryPool, psEntry);
		return;
	    }
	return;
    }
	}
    }

    assert(!"couldn't find pattern sequence in lookup");
}

/*
 *--------------------------------------------------------------
 *
 * RemovePatSeqFromPromotionLists --
 *
 *	Remove given pattern sequence from promotion lists. This
 *	can be required before deleting the pattern sequence.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static void
RemovePatSeqFromPromotionLists(
    Tk_BindingTable bindPtr,	/* Table in which to look for bindings. */
    PatSeq *psPtr)		/* Remove this pattern sequence. */
{
    size_t i;

    resultObj = Tcl_NewObj();
    assert(bindPtr);
    assert(psPtr);

    for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL;
    for (i = 0; i < PromArr_Size(bindPtr->promArr); ++i) {
	PSList *psList = PromArr_Get(bindPtr->promArr, i);
	PSEntry *psEntry;

	    psPtr = psPtr->nextObjPtr) {
	TK_DLIST_FOREACH(psEntry, psList) {
	    if (psEntry->psPtr == psPtr) {
		RemoveListEntry(&bindPtr->lookupTables.entryPool, psEntry);
		break;
	    }
	}
    }
}

/*
	/*
 *--------------------------------------------------------------
 *
 * DeletePatSeq --
 *
 *	Delete given pattern sequence. Possibly it is required
 *	to invoke RemovePatSeqFromLookup(), and RemovePatSeqFromPromotionLists()
 *	before.
 *
 * Results:
 *	Pointer to succeeding pattern sequence.
 *
 * Side effects:
 *	Deallocation of memory.
 *
 *--------------------------------------------------------------
 */

	 * For each binding, output information about each of the patterns in
static PatSeq *
DeletePatSeq(
    PatSeq *psPtr)		/* Delete this pattern sequence. */
{
    PatSeq *prevPtr;
    PatSeq *nextPtr;

	 * its sequence.
    assert(psPtr);
    assert(!psPtr->added);
    assert(!psPtr->owned);

    prevPtr = (PatSeq *)Tcl_GetHashValue(psPtr->hPtr);
    nextPtr = psPtr->ptr.nextObj;

    /*
     * Be sure to remove each binding from its hash chain in the pattern
     * table. If this is the last pattern in the chain, then delete the
     * hash entry too.
     */
	 */

    if (prevPtr == psPtr) {
	if (!psPtr->nextSeqPtr) {
	Tcl_ListObjAppendElement(NULL, resultObj, GetPatternObj(psPtr));
	    Tcl_DeleteHashEntry(psPtr->hPtr);
	} else {
	    Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr);
	}
    }
    } else {
	for ( ; ; prevPtr = prevPtr->nextSeqPtr) {
	    if (!prevPtr) {
		Tcl_Panic("DeletePatSeq couldn't find on hash chain");
	    }
	    if (prevPtr->nextSeqPtr == psPtr) {
		prevPtr->nextSeqPtr = psPtr->nextSeqPtr;
		break;
	    }
	}
    }

    Tcl_SetObjResult(interp, resultObj);
    FreePatSeq(psPtr);
    return nextPtr;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_DeleteAllBindings --
 *
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
1131
1132
1133
1134
1135
1136
1137

1138
1139

1140
1141
1142
1143




1144
1145
1146
1147
1148
1149
1150
1151



1152
1153
1154
1155
1156
1157
1158
1159









1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185







-
+

-
+



-
-
-
-
+
+


+
+
+

-
-
-
+
+
+
+
+

+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *
 *--------------------------------------------------------------
 */

void
Tk_DeleteAllBindings(
    Tk_BindingTable bindPtr,	/* Table in which to delete bindings. */
    void *object)		/* Token for object. */
    ClientData object)		/* Token for object. */
{
    PatSeq *psPtr;
    PatSeq *psPtr, *prevPtr;
    PatSeq *nextPtr;
    Tcl_HashEntry *hPtr;

    assert(bindPtr);
    assert(object);

    if (!(hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object))) {
    hPtr = Tcl_FindHashEntry(&bindPtr->objectTable, (char *) object);
    if (hPtr == NULL) {
	return;
    }
    for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL;
	    psPtr = nextPtr) {
	nextPtr = psPtr->nextObjPtr;

    /*
     * Don't forget to clear lookup tables.
     */
	/*
	 * Be sure to remove each binding from its hash chain in the pattern
	 * table. If this is the last pattern in the chain, then delete the
	 * hash entry too.
	 */

	prevPtr = Tcl_GetHashValue(psPtr->hPtr);
	if (prevPtr == psPtr) {
    ClearLookupTable(&bindPtr->lookupTables, object);
    ClearPromotionLists(bindPtr, object);

    for (psPtr = (PatSeq *)Tcl_GetHashValue(hPtr); psPtr; psPtr = nextPtr) {
	assert(TEST_PSENTRY(psPtr));
	DEBUG(psPtr->added = 0;)
	nextPtr = DeletePatSeq(psPtr);
    }

	    if (psPtr->nextSeqPtr == NULL) {
		Tcl_DeleteHashEntry(psPtr->hPtr);
	    } else {
		Tcl_SetHashValue(psPtr->hPtr, psPtr->nextSeqPtr);
	    }
	} else {
	    for ( ; ; prevPtr = prevPtr->nextSeqPtr) {
		if (prevPtr == NULL) {
		    Tcl_Panic("Tk_DeleteAllBindings couldn't find on hash chain");
		}
		if (prevPtr->nextSeqPtr == psPtr) {
		    prevPtr->nextSeqPtr = psPtr->nextSeqPtr;
		    break;
		}
	    }
	}
	ckfree(psPtr->script);
	ckfree(psPtr);
    }
    Tcl_DeleteHashEntry(hPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_BindEvent --
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
1200
1201
1202
1203
1204
1205
1206



































































1207
1208
1209
1210




1211
1212
1213
1214
1215
1216
1217


1218

1219


1220





1221
1222
1223








1224
1225
1226






1227
1228
1229
1230
1231
1232

1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268

1269
1270
1271
1272






1273
1274

1275
1276
1277
1278
1279
1280
1281


1282
1283
1284
1285
1286
1287
1288
1289
1290
1291


1292
1293


1294
1295
1296
1297







1298
1299




1300
1301
1302
1303


1304












1305
1306












1307





1308
1309
1310
1311
1312



1313






1314
1315
1316




1317




1318
1319




1320
1321




1322
1323














1324
1325


1326


1327



1328


1329





1330



1331





1332


1333


1334


1335


1336

1337

1338
1339
1340
1341
1342






1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369


1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387

1388
1389

1390





1391
1392




1393


1394
1395
1396





1397
1398
1399
1400












1401




1402



1403
1404


1405




1406
1407
1408
1409


1410



1411
1412


1413
1414




1415








1416




1417
1418
1419
1420







1421




1422
1423
1424
1425
1426
1427




1428




1429






1430




1431
1432






1433
1434
1435
1436
1437
1438
1439



1440
1441
1442
1443
1444
1445
1446








































































1447

1448
1449
1450
1451
1452
1453
1454
1455







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
+
+
+
+
+
+

-
-

-
+
-
-

-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-






-
+



+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+



+
+


-
+



-
-
-
-
-
-


-


+
+
+
+
+
-
-
+
+
+
+
+
+
+
+


-
-
+
+
-
-
+
+
+
+
-
-
-
-
-
-
-
+

-
-
-
-
+
+
+
+
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
+
+
+

-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-

-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-


-
+
-
-
-
-
-
+
+
-
-
-
-

-
-
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
+
-
-
-
-
+
+
+
+
-
-

-
-
-
+
+
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
+
+
+
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







 *	first binding is evaluated. If the action of a Tcl binding is to
 *	change or delete a binding, or delete the window associated with the
 *	binding, all the original Tcl binding scripts will still fire.
 *
 *---------------------------------------------------------------------------
 */

/* helper function */
static void
ResetCounters(
    Event *eventInfo,
    unsigned eventType,
    Window window)
{
    Event *curEvent;

    assert(eventInfo);
    curEvent = eventInfo + eventType;

    if (curEvent->xev.xany.window == window) {
	curEvent->xev.xany.window = None;
	eventInfo[eventType].countAny = 0;
	eventInfo[eventType].countDetailed = 0;
    }
}

/* helper function */
static int
IsBetterMatch(
    const PatSeq *fstMatchPtr,
    const PatSeq *sndMatchPtr)	/* this is a better match? */
{
    int diff;

    if (!sndMatchPtr) { return 0; }
    if (!fstMatchPtr) { return 1; }

    diff = CountSpecialized(fstMatchPtr, sndMatchPtr);
    if (diff > 0) { return 1; }
    if (diff < 0) { return 0; }

#if PREFER_MOST_SPECIALIZED_EVENT
    {	/* local scope */
#define M (Tcl_WideUInt)1000000
	static const Tcl_WideUInt weight[5] = { 0, 1, M, M*M, M*M*M };
#undef M
	Tcl_WideUInt fstCount = 0;
	Tcl_WideUInt sndCount = 0;
	unsigned i;

	/*
	 * Count the most high-ordered patterns.
	 *
	 * (This computation assumes that a sequence does not contain more than
	 * 1,000,000 single patterns. It can be precluded that in practice this
	 * assumption will not be violated.)
	 */

	for (i = 0; i < fstMatchPtr->numPats; ++i) {
	    assert(GetCount(fstMatchPtr, i) < SIZE_OF_ARRAY(weight));
	    fstCount += weight[GetCount(fstMatchPtr, i)];
	}
	for (i = 0; i < sndMatchPtr->numPats; ++i) {
	    assert(GetCount(sndMatchPtr, i) < SIZE_OF_ARRAY(weight));
	    sndCount += weight[GetCount(sndMatchPtr, i)];
	}
	if (sndCount > fstCount) { return 1; }
	if (sndCount < fstCount) { return 0; }
    }
#endif

    return sndMatchPtr->number > fstMatchPtr->number;
}

void
Tk_BindEvent(
    Tk_BindingTable bindPtr,	/* Table in which to look for bindings. */
    XEvent *eventPtr,		/* What actually happened. */
    Tk_Window tkwin,		/* Window on display where event occurred (needed in order to
    				 * locate display information). */
    Tcl_Size numObjects,		/* Number of objects at *objArr. */
    void **objArr)		/* Array of one or more objects to check for a matching binding. */
    Tk_Window tkwin,		/* Window on display where event occurred
				 * (needed in order to locate display
				 * information). */
    int numObjects,		/* Number of objects at *objectPtr. */
    ClientData *objectPtr)	/* Array of one or more objects to check for a
				 * matching binding. */
{
    Tcl_Interp *interp;
    ScreenInfo *screenPtr;
    TkDisplay *dispPtr;
    TkDisplay *oldDispPtr;
    ScreenInfo *screenPtr;
    Event *curEvent;
    TkWindow *winPtr = (TkWindow *)tkwin;
    BindInfo *bindInfoPtr;
    Tcl_InterpState interpState;
    LookupTables *physTables;
    PatSeq *psPtr[2];
    PatSeq *matchPtrBuf[32];
    PatSeq **matchPtrArr = matchPtrBuf;
    TkDisplay *oldDispPtr;
    XEvent *ringPtr;
    PatSeq *vMatchDetailList, *vMatchNoDetailList;
    PSList *psl[2];
    Tcl_DString scripts;
    const char *p;
    const char *end;
    unsigned scriptCount;
    int oldScreen;
    unsigned flags;
    Tcl_Size arraySize;
    int flags, oldScreen;
    unsigned int scriptCount;
    Tcl_Interp *interp;
    unsigned newArraySize;
    Tcl_Size i, k;

    assert(bindPtr);
    assert(eventPtr);
    assert(tkwin);
    Tcl_DString scripts;
    Tcl_InterpState interpState;
    Detail detail;
    char *p, *end;
    TkWindow *winPtr = (TkWindow *) tkwin;
    PatternTableKey key;
    assert(numObjects >= 0);

    /*
     * Ignore events on windows that don't have names: these are windows like
     * wrapper windows that shouldn't be visible to the application.
     */

    if (!winPtr->pathName) {
    if (winPtr->pathName == NULL) {
	return;
    }

    /*
     * Ignore the event completely if it is an Enter, Leave, FocusIn, or
     * FocusOut event with detail NotifyInferior. The reason for ignoring
     * these events is that we don't want transitions between a window and its
     * children to visible to bindings on the parent: this would cause
     * problems for mega-widgets, since the internal structure of a
     * mega-widget isn't supposed to be visible to people watching the parent.
     */
    flags = flagArray[eventPtr->type];

    if ((eventPtr->type == EnterNotify) || (eventPtr->type == LeaveNotify)) {
	if (eventPtr->xcrossing.detail == NotifyInferior) {
	    return;
	}
    }
    if ((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) {
	if (eventPtr->xfocus.detail == NotifyInferior) {
	    return;
	}
    }

    /*
     * Ignore event types which are not in flagArray and all zeroes there.
     * Most notably, NoExpose events can fill the ring buffer and disturb
     * (thus masking out) event sequences of interest.
     */

    if (eventPtr->type >= TK_LASTEVENT || !flags) {
    if ((eventPtr->type >= TK_LASTEVENT) || !flagArray[eventPtr->type]) {
	return;
    }

    if (flags & HAS_XKEY_HEAD_AND_STATE) {
	bindPtr->curModMask = eventPtr->xkey.state;
    } else if (flags & CROSSING) {
	bindPtr->curModMask = eventPtr->xcrossing.state;
    }

    dispPtr = ((TkWindow *) tkwin)->dispPtr;
    bindInfoPtr = winPtr->mainPtr->bindInfo;
    curEvent = bindPtr->eventInfo + eventPtr->type;

    /*
     * Add the new event to the ring of saved events for the binding table.
     * Two tricky points:
     *
     * 1. Combine consecutive MotionNotify events. Do this by putting the new
     *    event *on top* of the previous event.
     * Compute current time needed for "event generate",
     * and reset counters for Key and Button events.
     * 2. If a modifier key is held down, it auto-repeats to generate
     *    continuous KeyPress and KeyRelease events. These can flush the event
     *    ring so that valuable information is lost (such as repeated button
     *    clicks). To handle this, check for the special case of a modifier
     *    KeyPress arriving when the previous two events are a KeyRelease and
     *    KeyPress of the same key. If this happens, mark the most recent
     *    event (the KeyRelease) invalid and put the new event on top of the
     *    event before that (the KeyPress).
     */

    switch (eventPtr->type) {
    case EnterNotify:
    if ((eventPtr->type == MotionNotify)
	    && (bindPtr->eventRing[bindPtr->curEvent].type == MotionNotify)) {
    case LeaveNotify:
	if (eventPtr->xcrossing.time) {
	/*
	 * Don't advance the ring pointer.
	 */
    } else if (eventPtr->type == KeyPress) {
	    bindInfoPtr->lastCurrentTime = CurrentTimeInMilliSecs();
	    bindInfoPtr->lastEventTime = eventPtr->xcrossing.time;
	}
	break;
    case KeyPress:
    case KeyRelease: {
	int reset = 1;
	int i;

	if (eventPtr->xkey.time) {
	    bindInfoPtr->lastCurrentTime = CurrentTimeInMilliSecs();
	    bindInfoPtr->lastEventTime = eventPtr->xkey.time;
	}
	for (i = 0; ; i++) {
	    if (i >= dispPtr->numModKeyCodes) {
		goto advanceRingPointer;
	    }
	/* Modifier keys should not influence button events. */
	for (i = 0; i < dispPtr->numModKeyCodes; ++i) {
	    if (dispPtr->modKeyCodes[i] == eventPtr->xkey.keycode) {
		reset = 0;
	    }
	}
	if (reset) {
	    /* Reset repetition count for button events. */
	    bindPtr->eventInfo[ButtonPress].countAny = 0;
	    bindPtr->eventInfo[ButtonPress].countDetailed = 0;
	    bindPtr->eventInfo[ButtonRelease].countAny = 0;
	    bindPtr->eventInfo[ButtonRelease].countDetailed = 0;
	}
	break;
    }
		break;
	    }
    case ButtonPress:
    case ButtonRelease:
	/* Reset repetition count for key events. */
	bindPtr->eventInfo[KeyPress].countAny = 0;
	bindPtr->eventInfo[KeyPress].countDetailed = 0;
	bindPtr->eventInfo[KeyRelease].countAny = 0;
	bindPtr->eventInfo[KeyRelease].countDetailed = 0;
	/* fallthru */
    case MotionNotify:
	if (eventPtr->xmotion.time) {
	    bindInfoPtr->lastCurrentTime = CurrentTimeInMilliSecs();
	    bindInfoPtr->lastEventTime = eventPtr->xmotion.time;
	}
	break;
    case PropertyNotify:
	if (eventPtr->xproperty.time) {
	    bindInfoPtr->lastCurrentTime = CurrentTimeInMilliSecs();
	    bindInfoPtr->lastEventTime = eventPtr->xproperty.time;
	ringPtr = &bindPtr->eventRing[bindPtr->curEvent];
	if ((ringPtr->type != KeyRelease)
		|| (ringPtr->xkey.keycode != eventPtr->xkey.keycode)) {
	    goto advanceRingPointer;
	}
	break;
    case DestroyNotify:
	ResetCounters(bindPtr->eventInfo, KeyPress, eventPtr->xany.window);
	if (bindPtr->curEvent <= 0) {
	ResetCounters(bindPtr->eventInfo, KeyRelease, eventPtr->xany.window);
	ResetCounters(bindPtr->eventInfo, ButtonPress, eventPtr->xany.window);
	ResetCounters(bindPtr->eventInfo, ButtonRelease, eventPtr->xany.window);
	break;
    }

	    i = EVENT_BUFFER_SIZE - 1;
	} else {
	    i = bindPtr->curEvent - 1;
    /*
     * Now check whether this is a repeating event (multi-click, repeated key press, and so on).
     */

	}
    /* NOTE: if curEvent is not yet set, then the following cannot match: */
    if (curEvent->xev.xany.window == eventPtr->xany.window) {
	switch (eventPtr->type) {
	case KeyPress:
	ringPtr = &bindPtr->eventRing[i];
	if ((ringPtr->type != KeyPress)
	case KeyRelease:
	    if (MatchEventRepeat(&curEvent->xev.xkey, &eventPtr->xkey)) {
		if (curEvent->xev.xkey.keycode == eventPtr->xkey.keycode) {
		    ++curEvent->countDetailed;
		|| (ringPtr->xkey.keycode != eventPtr->xkey.keycode)) {
	    goto advanceRingPointer;
		} else {
		    curEvent->countDetailed = 1;
		}
		++curEvent->countAny;
	}
	bindPtr->eventRing[bindPtr->curEvent].type = -1;
	    } else {
		curEvent->countAny = curEvent->countDetailed = 1;
	    }
	    break;
	case ButtonPress:
	case ButtonRelease:
	    if (MatchEventNearby(&curEvent->xev, eventPtr)) {
		if (curEvent->xev.xbutton.button == eventPtr->xbutton.button) {
		    ++curEvent->countDetailed;
		} else {
		    curEvent->countDetailed = 1;
		}
		++curEvent->countAny;
	    } else {
	bindPtr->curEvent = i;
    } else {
		curEvent->countAny = curEvent->countDetailed = 1;
	    }

	    break;
	case EnterNotify:
    advanceRingPointer:
	case LeaveNotify:
	    if (TestNearbyTime(eventPtr->xcrossing.time, curEvent->xev.xcrossing.time)) {
		++curEvent->countAny;
	bindPtr->curEvent++;
	    } else {
		curEvent->countAny = 1;
	if (bindPtr->curEvent >= EVENT_BUFFER_SIZE) {
	    }
	    break;
	case PropertyNotify:
	    if (TestNearbyTime(eventPtr->xproperty.time, curEvent->xev.xproperty.time)) {
		++curEvent->countAny;
	    bindPtr->curEvent = 0;
	    } else {
		curEvent->countAny = 1;
	    }
	}
	    break;
	default:
	    ++curEvent->countAny;
	    break;
	}
    }
    } else {
	curEvent->countAny = curEvent->countDetailed = 1;
    ringPtr = &bindPtr->eventRing[bindPtr->curEvent];
    }

    memcpy(ringPtr, eventPtr, sizeof(XEvent));
    /*
     * Now update the details.
    detail.clientData = 0;
     */

    flags = flagArray[ringPtr->type];
    curEvent->xev = *eventPtr;
    if (flags & KEY) {
	curEvent->detail.info = TkpGetKeySym(dispPtr, eventPtr);
	detail.keySym = TkpGetKeySym(dispPtr, ringPtr);
	if (detail.keySym == NoSymbol) {
	    detail.keySym = 0;
	}
    } else if (flags & BUTTON) {
	curEvent->detail.info = eventPtr->xbutton.button;
    } else if (flags & MOTION) {
	curEvent->detail.info = ButtonNumberFromState(eventPtr->xmotion.state);
    } else if (flags & VIRTUAL) {
	curEvent->detail.name = ((XVirtualEvent *) eventPtr)->name;
    }
	detail.button = ringPtr->xbutton.button;
    } else if (flags & VIRTUAL) {
	detail.name = ((XVirtualEvent *) ringPtr)->name;
    }
    bindPtr->detailRing[bindPtr->curEvent] = detail;

    /*
     * Find out if there are any virtual events that correspond to this
     * physical event (or sequence of physical events).
     */

    vMatchDetailList = NULL;
    vMatchNoDetailList = NULL;
    memset(&key, 0, sizeof(key));

    if (ringPtr->type != VirtualEvent) {
	Tcl_HashTable *veptPtr = &bindInfoPtr->virtualEventTable.patternTable;
	Tcl_HashEntry *hPtr;

	key.object = NULL;
	key.type = ringPtr->type;
	key.detail = detail;

	hPtr = Tcl_FindHashEntry(veptPtr, (char *) &key);
	if (hPtr != NULL) {
	    vMatchDetailList = Tcl_GetHashValue(hPtr);
	}
    bindPtr->curEvent = curEvent;
    physTables = &bindPtr->lookupTables;

	if (key.detail.clientData != 0) {
	    key.detail.clientData = 0;
	    hPtr = Tcl_FindHashEntry(veptPtr, (char *) &key);
	    if (hPtr != NULL) {
		vMatchNoDetailList = Tcl_GetHashValue(hPtr);
	    }
	}
    }

    /*
     * Loop over all the binding tags, finding the binding script or callback
     * for each one. Append all of the binding scripts, with %-sequences
     * expanded, to "scripts", with null characters separating the scripts for
     * each object.
     */

    scriptCount = 0;
    arraySize = 0;
    Tcl_DStringInit(&scripts);

    if ((size_t) numObjects > SIZE_OF_ARRAY(matchPtrBuf)) {
    for ( ; numObjects > 0; numObjects--, objectPtr++) {
	/* It's unrealistic that the buffer size is too small, but who knows? */
	matchPtrArr = (PatSeq **)ckalloc(numObjects*sizeof(matchPtrArr[0]));
    }
    memset(matchPtrArr, 0, numObjects*sizeof(matchPtrArr[0]));

	PatSeq *matchPtr = NULL, *sourcePtr = NULL;
	Tcl_HashEntry *hPtr;
    if (!PromArr_IsEmpty(bindPtr->promArr)) {
	for (k = 0; k < numObjects; ++k) {
	    psl[1] = PromArr_Last(bindPtr->promArr);
	    psl[0] = psl[1] - 1;

	    /*
	     * Loop over all promoted bindings, finding the longest matching one.
	/*
	 * Match the new event against those recorded in the pattern table,
	 * saving the longest matching pattern. For events with details
	     *
	     * Note that we must process all lists, because all matching patterns
	     * have to be promoted. Normally at most one list will be processed, and
	     * usually this list only contains one or two patterns.
	     */
	 * (button and key events), look for a binding for the specific key or
	 * button. First see if the event matches a physical event that the
	 * object is interested in, then look for a virtual event.
	 */

	    for (i = PromArr_Size(bindPtr->promArr); i > 0; --i, --psl[0], --psl[1]) {
		psPtr[0] = MatchPatterns(dispPtr, bindPtr, psl[0], psl[1], i, curEvent, objArr[k], NULL);

		if (IsBetterMatch(matchPtrArr[k], psPtr[0])) {
		    /* We will process it later, because we still may find a pattern with better match. */
		    matchPtrArr[k] = psPtr[0];
		}
		if (!PSList_IsEmpty(psl[1])) {
		    /* We have promoted sequences, adjust array size. */
		    arraySize = Max(i + 1, arraySize);
		}

	    }
	}
    }

	key.object = *objectPtr;
    /*
     * 1. Look for bindings for the specific detail (button and key events).
     * 2. Look for bindings without detail.
	key.type = ringPtr->type;
	key.detail = detail;
     */

	hPtr = Tcl_FindHashEntry(&bindPtr->patternTable, (char *) &key);
    for (k = 0; k < numObjects; ++k) {
	PSList *psSuccList = PromArr_First(bindPtr->promArr);
	PatSeq *bestPtr;

	if (hPtr != NULL) {
	    matchPtr = MatchPatterns(dispPtr, bindPtr, Tcl_GetHashValue(hPtr),
		    matchPtr, NULL, &sourcePtr);
	}
	psl[0] = GetLookupForEvent(physTables, curEvent, (Tcl_Obj *)objArr[k], 1);
	psl[1] = GetLookupForEvent(physTables, curEvent, (Tcl_Obj *)objArr[k], 0);

	assert(psl[0] == NULL || psl[0] != psl[1]);

	psPtr[0] = MatchPatterns(dispPtr, bindPtr, psl[0], psSuccList, 0, curEvent, objArr[k], NULL);
	if (vMatchDetailList != NULL) {
	    matchPtr = MatchPatterns(dispPtr, bindPtr, vMatchDetailList,
	psPtr[1] = MatchPatterns(dispPtr, bindPtr, psl[1], psSuccList, 0, curEvent, objArr[k], NULL);

		    matchPtr, objectPtr, &sourcePtr);
	}
	if (!PSList_IsEmpty(psSuccList)) {
	    /* We have promoted sequences, adjust array size. */
	    arraySize = Max(1, arraySize);
	}


	bestPtr = psPtr[0] ? psPtr[0] : psPtr[1];

	if (matchPtrArr[k]) {
	    if (IsBetterMatch(matchPtrArr[k], bestPtr)) {
		matchPtrArr[k] = bestPtr;
	    } else {
		/*
	/*
		 * We've already found a higher level match, nevertheless it was required to
		 * process the level zero patterns because of possible promotions.
		 */
	    }
	 * If no match was found, look for a binding for all keys or buttons
	 * (detail of 0). Again, first match on a virtual event.
	 */

	    /*
	     * Now we have to catch up the processing of the script.
	     */
	} else {
	    /*
	     * We have to look whether we can find a better match in virtual table, provided that we
	     * don't have a higher level match.
	if ((detail.clientData != 0) && (matchPtr == NULL)) {
	     */

	    matchPtrArr[k] = bestPtr;

	    key.detail.clientData = 0;
	    hPtr = Tcl_FindHashEntry(&bindPtr->patternTable, (char *) &key);
	    if (hPtr != NULL) {
		matchPtr = MatchPatterns(dispPtr, bindPtr,
			Tcl_GetHashValue(hPtr), matchPtr, NULL, &sourcePtr);
	    }
	    if (eventPtr->type != VirtualEvent) {
		LookupTables *virtTables = &bindInfoPtr->virtualEventTable.lookupTables;
		PatSeq *matchPtr = matchPtrArr[k];
		PatSeq *mPtr;

		/*
		 * Note that virtual events cannot promote.
		 */

	    if (vMatchNoDetailList != NULL) {
		psl[0] = GetLookupForEvent(virtTables, curEvent, NULL, 1);
		psl[1] = GetLookupForEvent(virtTables, curEvent, NULL, 0);

		assert(psl[0] == NULL || psl[0] != psl[1]);

		mPtr = MatchPatterns(dispPtr, bindPtr, psl[0], NULL, 0, curEvent, objArr[k], &matchPtr);
		matchPtr = MatchPatterns(dispPtr, bindPtr, vMatchNoDetailList,
		if (mPtr) {
		    matchPtrArr[k] = matchPtr;
		    matchPtr = mPtr;
		}
			matchPtr, objectPtr, &sourcePtr);
	    }
		if (MatchPatterns(dispPtr, bindPtr, psl[1], NULL, 0, curEvent, objArr[k], &matchPtr)) {
		    matchPtrArr[k] = matchPtr;
		}
	    }
	}

	}

	if (matchPtr != NULL) {
	    ExpandPercents(winPtr, sourcePtr->script, eventPtr,
		    detail.keySym, scriptCount++, &scripts);

	    /*
	if (matchPtrArr[k]) {
	    ExpandPercents(winPtr, matchPtrArr[k]->script, curEvent, scriptCount++, &scripts);
	    /* Null is added to the scripts string to separate the various scripts. */
	     * A "" is added to the scripts string to separate the various
	     * scripts that should be invoked.
	     */

	    Tcl_DStringAppend(&scripts, "", 1);
	}
    }

    PromArr_SetSize(bindPtr->promArr, arraySize);

    /*
     * Remove expired pattern sequences.
     */

    for (i = 0, newArraySize = 0; i < arraySize; ++i) {
	PSList *psList = PromArr_Get(bindPtr->promArr, i);
	PSEntry *psEntry;
	PSEntry *psNext;

	for (psEntry = PSList_First(psList); psEntry; psEntry = psNext) {
	    const TkPattern *patPtr;

	    assert(i + 1 < (Tcl_Size)psEntry->psPtr->numPats);

	    psNext = PSList_Next(psEntry);
	    patPtr = &psEntry->psPtr->pats[i + 1];

	    /*
	     * We have to remove the following entries from promotion list (but
	     * only if we don't want to keep it):
	     * ------------------------------------------------------------------
	     * 1) It is marked as expired (see MatchPatterns()).
	     * 2) If we have a Key event, and current entry is matching a Button.
	     * 3) If we have a Button event, and current entry is matching a Key.
	     * 4) If we have a detailed event, current entry it is also detailed,
	     *    we have matching event types, but the details are different.
	     * 5) Current entry has been matched with a different window.
	     */

	    if (psEntry->keepIt) {
		assert(!psEntry->expired);
		psEntry->keepIt = 0;
	    } else if (psEntry->expired
		    || psEntry->window != curEvent->xev.xany.window
		    || (patPtr->info
			&& curEvent->detail.info
			&& patPtr->eventType == (unsigned) curEvent->xev.type
			&& patPtr->info != curEvent->detail.info)) {
		RemoveListEntry(&bindPtr->lookupTables.entryPool, psEntry);
	    } else {
		switch (patPtr->eventType) {
		case ButtonPress:
		case ButtonRelease:
		    if (IsKeyEventType(curEvent->xev.type)) {
			RemoveListEntry(&bindPtr->lookupTables.entryPool, psEntry);
		    }
		    break;
		case KeyPress:
		case KeyRelease:
		    if (IsButtonEventType(curEvent->xev.type)) {
			RemoveListEntry(&bindPtr->lookupTables.entryPool, psEntry);
		    }
		    break;
		}
	    }
	}

	if (!PSList_IsEmpty(psList)) {
	    /* We still have promoted sequences, adjust array size. */
	    newArraySize = Max(i + 1, newArraySize);
	}
    }

    PromArr_SetSize(bindPtr->promArr, newArraySize);

    if (matchPtrArr != matchPtrBuf) {
	ckfree(matchPtrArr);
    }

    if (Tcl_DStringLength(&scripts) == 0) {
	return; /* Nothing to do. */
	return;
    }

    /*
     * Now go back through and evaluate the binding for each object, in order,
     * dealing with "break" and "continue" exceptions appropriately.
     *
     * There are two tricks here:
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
1472
1473
1474
1475
1476
1477
1478


1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495

1496


1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508

1509
1510


1511
1512
1513
1514
1515
1516
1517
1518
1519
1520


1521
1522
1523
1524
1525



1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548


1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566




1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580





























































































































1581
1582
1583










1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606

1607







1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625








1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656







1657
1658
1659
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







-
-
+
+





+
+
+







-
+
-
-
+



-
+







-
+

-
-
+
+
+
+
+
+
+
+


-
-
+
+



-
-
-
+
+
+




+




-
+

+








-
-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+
+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
+
+
+

-
+
+
+
+
+

-
+
-
-
-
+
+
+
+
+

-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
-
-
+
+
+
+
-
-
-
-
+
+







     * screen has changed.
     */

    interpState = Tcl_SaveInterpState(interp, TCL_OK);
    screenPtr = &bindInfoPtr->screenInfo;
    oldDispPtr = screenPtr->curDispPtr;
    oldScreen = screenPtr->curScreenIndex;

    if (dispPtr != screenPtr->curDispPtr || Tk_ScreenNumber(tkwin) != screenPtr->curScreenIndex) {
    if ((dispPtr != screenPtr->curDispPtr)
	    || (Tk_ScreenNumber(tkwin) != screenPtr->curScreenIndex)) {
	screenPtr->curDispPtr = dispPtr;
	screenPtr->curScreenIndex = Tk_ScreenNumber(tkwin);
	ChangeScreen(interp, dispPtr->name, screenPtr->curScreenIndex);
    }

    p = Tcl_DStringValue(&scripts);
    end = p + Tcl_DStringLength(&scripts);

    /*
     * Be careful when dereferencing screenPtr or bindInfoPtr. If we evaluate
     * something that destroys ".", bindInfoPtr would have been freed, but we
     * can tell that by first checking to see if winPtr->mainPtr == NULL.
     */

    Tcl_Preserve(bindInfoPtr);

    while (p < end) {
    for (p = Tcl_DStringValue(&scripts), end = p + Tcl_DStringLength(&scripts); p < end; ) {
	Tcl_Size len = strlen(p);
	int len = (int) strlen(p);
	int code;

	if (!bindInfoPtr->deleted) {
	    ++screenPtr->bindingDepth;
	    screenPtr->bindingDepth++;
	}
	Tcl_AllowExceptions(interp);

	code = Tcl_EvalEx(interp, p, len, TCL_EVAL_GLOBAL);
	p += len + 1;

	if (!bindInfoPtr->deleted) {
	    --screenPtr->bindingDepth;
	    screenPtr->bindingDepth--;
	}
	if (code != TCL_OK && code != TCL_CONTINUE) {
	    if (code != TCL_BREAK) {
	if (code != TCL_OK) {
	    if (code == TCL_CONTINUE) {
		/*
		 * Do nothing: just go on to the next command.
		 */
	    } else if (code == TCL_BREAK) {
		break;
	    } else {
		Tcl_AddErrorInfo(interp, "\n    (command bound to event)");
		Tcl_BackgroundException(interp, code);
	    }
	    break;
		break;
	    }
	}
    }

    if (!bindInfoPtr->deleted
	    && screenPtr->bindingDepth > 0
	    && (oldDispPtr != screenPtr->curDispPtr || oldScreen != screenPtr->curScreenIndex)) {
    if (!bindInfoPtr->deleted && (screenPtr->bindingDepth != 0)
	    && ((oldDispPtr != screenPtr->curDispPtr)
		    || (oldScreen != screenPtr->curScreenIndex))) {
	/*
	 * Some other binding script is currently executing, but its screen is
	 * no longer current. Change the current display back again.
	 */

	screenPtr->curDispPtr = oldDispPtr;
	screenPtr->curScreenIndex = oldScreen;
	ChangeScreen(interp, oldDispPtr->name, oldScreen);
    }
    Tcl_RestoreInterpState(interp, interpState);
    (void) Tcl_RestoreInterpState(interp, interpState);
    Tcl_DStringFree(&scripts);

    Tcl_Release(bindInfoPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * MatchPatterns --
 *
 *	Given a list of pattern sequences and the recent event, return
 *	the pattern sequence that best matches this event, if there is
 *	Given a list of pattern sequences and a list of recent events, return
 *	the pattern sequence that best matches the event list, if there is
 *	one.
 *
 *	This function is used in two different ways. In the simplest use,
 *	"object" is NULL and psPtr is a list of pattern sequences, each of
 *	which corresponds to a binding. In this case, the function finds the
 *	pattern sequences that match the event list and returns the most
 *	specific of those, if there is more than one.
 *
 *	In the second case, psPtr is a list of pattern sequences, each of
 *	which corresponds to a definition for a virtual binding. In order for
 *	one of these sequences to "match", it must match the events (as above)
 *	but in addition there must be a binding for its associated virtual
 *	event on the current object. The "object" argument indicates which
 *	object the binding must be for.
 *
 * Results:
 *
 *	The return value is NULL if no match is found. Otherwise the
 *	return value is the most specific pattern sequence among all
 *	those that match the event table.

 *	The return value is NULL if bestPtr is NULL and no pattern matches the
 *	recent events from bindPtr. Otherwise the return value is the most
 *	specific pattern sequence among bestPtr and all those at psPtr that
 *	match the event list and object. If a pattern sequence other than
 *	bestPtr is returned, then *bestCommandPtr is filled in with a pointer
 *	to the command from the best sequence.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

/* helper function */
static int
VirtPatIsBound(
    Tk_BindingTable bindPtr,	/* Table in which to look for bindings. */
    PatSeq *psPtr,		/* Test this pattern. */
    void *object,		/* Check for this binding tag. */
    PatSeq **physPtrPtr)	/* Input: the best physical event.
    				 * Output: the physical event associated with matching virtual event. */
{
    PatternTableKey key;
    const struct VirtOwners *owners;
    unsigned i;

    assert(bindPtr);
    assert(psPtr);
    assert(!psPtr->object);
    assert(physPtrPtr);

    if (*physPtrPtr) {
	const TkPattern *physPatPtr = (*physPtrPtr)->pats;
	const TkPattern *virtPatPtr = psPtr->pats;

	if (physPatPtr->info || !virtPatPtr->info) {
	    if (IsSubsetOf(virtPatPtr->modMask, physPatPtr->modMask)) {
		return 0; /* We cannot surpass this match. */
	    }
	}
    }

    /* Otherwise on some systems the key contains uninitialized bytes. */
    memset(&key, 0, sizeof(key));

    key.object = object;
    key.type = VirtualEvent;
    owners = psPtr->ptr.owners;

    for (i = 0; i < VirtOwners_Size(owners); ++i) {
	Tcl_HashEntry *hPtr = VirtOwners_Get(owners, i);

	key.detail.name = (Tk_Uid) Tcl_GetHashKey(hPtr->tablePtr, hPtr);

	if ((hPtr = Tcl_FindHashEntry(&bindPtr->lookupTables.patternTable, (char *) &key))) {
	    /* The physical event matches this virtual event's definition. */
	    *physPtrPtr = (PatSeq *) Tcl_GetHashValue(hPtr);
	    return 1;
	}
    }

    return 0;
}

/* helper function */
static int
Compare(
    const PatSeq *fstMatchPtr,
    const PatSeq *sndMatchPtr) /* Most recent match. */
{
    int diff;

    if (!fstMatchPtr) { return +1; }
    assert(sndMatchPtr);
    diff = CountSpecialized(fstMatchPtr, sndMatchPtr);
    return diff ? diff : (int) sndMatchPtr->count - (int) fstMatchPtr->count;
}

/* helper function */
static int
CompareModMasks(
    const PSModMaskArr *fstModMaskArr,
    const PSModMaskArr *sndModMaskArr,
    unsigned fstModMask,
    unsigned sndModMask)
{
    int fstCount = 0;
    int sndCount = 0;
    int i;

    if (PSModMaskArr_IsEmpty(fstModMaskArr)) {
	if (!PSModMaskArr_IsEmpty(sndModMaskArr)) {
	    for (i = PSModMaskArr_Size(sndModMaskArr) - 1; i >= 0; --i) {
		if (*PSModMaskArr_Get(sndModMaskArr, i)) {
		    ++sndCount;
		}
	    }
	}
    } else if (PSModMaskArr_IsEmpty(sndModMaskArr)) {
	for (i = PSModMaskArr_Size(fstModMaskArr) - 1; i >= 0; --i) {
	    if (*PSModMaskArr_Get(fstModMaskArr, i)) {
		++fstCount;
	    }
	}
    } else {
	assert(PSModMaskArr_Size(fstModMaskArr) == PSModMaskArr_Size(sndModMaskArr));

	for (i = PSModMaskArr_Size(fstModMaskArr) - 1; i >= 0; --i) {
	    unsigned fstiModMask = *PSModMaskArr_Get(fstModMaskArr, i);
	    unsigned sndiModMask = *PSModMaskArr_Get(sndModMaskArr, i);

	    if (IsSubsetOf(fstiModMask, sndiModMask)) { ++sndCount; }
	    if (IsSubsetOf(sndiModMask, fstiModMask)) { ++fstCount; }
	}
    }

    /* Finally compare modifier masks of last pattern. */

    if (IsSubsetOf(fstModMask, sndModMask)) { ++sndCount; }
    if (IsSubsetOf(sndModMask, fstModMask)) { ++fstCount; }

    return fstCount - sndCount;
}

/* helper function */
static int
IsPSInPSList(
    const PatSeq *psPtr,   /* Is this pattern sequence... */
    const PSList *psList)  /* ...an element of this list of patterns sequence? */
{
    PSEntry *psEntry;

    TK_DLIST_FOREACH(psEntry, psList) {
        if (psEntry->psPtr == psPtr) { return 1; }
    }
    return 0;
}

static PatSeq *
MatchPatterns(
    TkDisplay *dispPtr,		/* Display from which the event came. */
    Tk_BindingTable bindPtr,	/* Table in which to look for bindings. */
    PSList *psList,		/* List of potentially matching patterns, can be NULL. */
    PSList *psSuccList,		/* Add all matching higher-level pattern sequences to this list.
    				 * Can be NULL. */
    unsigned patIndex,		/* Match only this tag in sequence. */
    const Event *curEvent,	/* Match this event. */
    void *object,		/* Check for this binding tag. */
    PatSeq **physPtrPtr)	/* Input: the best physical event; NULL if we test physical events.
    				 * Output: the associated physical event for the best matching virtual
				 * event; NULL when we match physical events. */
    BindingTable *bindPtr,	/* Information about binding table, such as
				 * ring of recent events. */
    PatSeq *psPtr,		/* List of pattern sequences. */
    PatSeq *bestPtr,		/* The best match seen so far, from a previous
				 * call to this function. NULL means no prior
				 * best match. */
    ClientData *objectPtr,	/* If NULL, the sequences at psPtr correspond
				 * to "normal" bindings. If non-NULL, the
				 * sequences at psPtr correspond to virtual
				 * bindings; in order to match each sequence
				 * must correspond to a virtual binding for
				 * which a binding exists for object in
				 * bindPtr. */
    PatSeq **sourcePtrPtr)	/* Filled with the pattern sequence that
				 * contains the eventProc and clientData
				 * associated with the best match. If this
				 * differs from the return value, it is the
				 * virtual event that most closely matched the
				 * return value (a physical event). Not
				 * modified unless a result other than bestPtr
				 * is returned. */
{
    PatSeq *matchPtr, *bestSourcePtr, *sourcePtr;
    Window window;

    PSEntry *psEntry;
    PatSeq *bestPtr;
    PatSeq *bestPhysPtr;
    unsigned bestModMask;
    const PSModMaskArr *bestModMaskArr = NULL;
    int isModKeyOnly = 0;
    Tcl_Size i;
    bestSourcePtr = *sourcePtrPtr;

    /*
     * Iterate over all the pattern sequences.
     */

    for ( ; psPtr != NULL; psPtr = psPtr->nextSeqPtr) {
	XEvent *eventPtr = &bindPtr->eventRing[bindPtr->curEvent];
	Detail *detailPtr = &bindPtr->detailRing[bindPtr->curEvent];
	TkPattern *patPtr = psPtr->pats;
	Window window = eventPtr->xany.window;
	int patCount, ringCount, flags, state, modMask, i;

	/*
	 * Iterate over all the patterns in a sequence to be sure that they
	 * all match.
	 */

    assert(dispPtr);
    assert(bindPtr);
    assert(curEvent);

    if (!psList) {
	return NULL;
    }

	patCount = psPtr->numPats;
	ringCount = EVENT_BUFFER_SIZE;
	while (patCount > 0) {
	    if (ringCount <= 0) {
		goto nextSequence;
	    }
	    if (eventPtr->xany.type != patPtr->eventType) {
		/*
		 * Most of the event types are considered superfluous in that
		 * they are ignored if they occur in the middle of a pattern
		 * sequence and have mismatching types. The only ones that
		 * cannot be ignored are ButtonPress and ButtonRelease events
		 * (if the next event in the pattern is a KeyPress or
		 * KeyRelease) and KeyPress and KeyRelease events (if the next
		 * pattern event is a ButtonPress or ButtonRelease). Here are
		 * some tricky cases to consider:
		 * 1. Double-Button or Double-Key events.
		 * 2. Double-ButtonRelease or Double-KeyRelease events.
		 * 3. The arrival of various events like Enter and Leave and
		 *    FocusIn and GraphicsExpose between two button presses or
		 *    key presses.
		 * 4. Modifier keys like Shift and Control shouldn't generate
		 *    conflicts with button events.
		 */

		if ((patPtr->eventType == KeyPress)
			|| (patPtr->eventType == KeyRelease)) {
		    if ((eventPtr->xany.type == ButtonPress)
			    || (eventPtr->xany.type == ButtonRelease)) {
			goto nextSequence;
		    }
    bestModMask = 0;
    bestPtr = NULL;
    bestPhysPtr = NULL;
    window = curEvent->xev.xany.window;

    /*
     * Modifier key events interlaced between patterns parts of a
		} else if ((patPtr->eventType == ButtonPress)
			|| (patPtr->eventType == ButtonRelease)) {
		    if ((eventPtr->xany.type == KeyPress)
			    || (eventPtr->xany.type == KeyRelease)) {
			/*
			 * Ignore key events if they are modifier keys.
     * sequence shall not prevent a sequence from ultimately
     * matching. Example: when trying to trigger <a><Control-c>
     * from the keyboard, the sequence of events actually seen is
     * <a> then <Control_L> (possibly repeating if the key is hold
     * down), and finally <Control-c>. At the time <Control_L> is
     * seen, we shall keep the <a><Control-c> pattern sequence in
     * the promotion list, otherwise it is impossible to trigger
     * it from the keyboard. See bug [16ef161925].
     */
    if (IsKeyEventType(curEvent->xev.type)) {
        for (i = 0; i < dispPtr->numModKeyCodes; ++i) {
            if (dispPtr->modKeyCodes[i] == curEvent->xev.xkey.keycode) {
                isModKeyOnly = 1;
                break;
            }
        }
    }

    for (psEntry = PSList_First(psList); psEntry; psEntry = PSList_Next(psEntry)) {
	if (patIndex == 0 || psEntry->window == window) {
	    PatSeq* psPtr = psEntry->psPtr;
			 */

			for (i = 0; i < dispPtr->numModKeyCodes; i++) {
			    if (dispPtr->modKeyCodes[i]
				    == eventPtr->xkey.keycode) {
				/*
				 * This key is a modifier key, so ignore it.
				 */

				goto nextEvent;
			    }
			}
			goto nextSequence;
		    }
		}
		goto nextEvent;
	    }
	    if (eventPtr->xany.type == CreateNotify
		    && eventPtr->xcreatewindow.parent != window) {
		goto nextSequence;
	    } else if (eventPtr->xany.window != window) {
		goto nextSequence;
	    }

	    /*
	     * Note: it's important for the keysym check to go before the
	     * modifier check, so we can ignore unwanted modifier keys before
	     * choking on the modifier check.
	     */

	    if ((patPtr->detail.clientData != 0)
		    && (patPtr->detail.clientData != detailPtr->clientData)) {
		/*
		 * The detail appears not to match. However, if the event is a
		 * KeyPress for a modifier key then just ignore the event.
		 * Otherwise event sequences like "aD" never match because the
		 * shift key goes down between the "a" and the "D".
		 */

	    assert(TEST_PSENTRY(psPtr));
	    assert((psPtr->object == NULL) == (physPtrPtr != NULL));
	    assert(psPtr->object || patIndex == 0);
	    assert(psPtr->numPats > patIndex);

		if (eventPtr->xany.type == KeyPress) {
		    for (i = 0; i < dispPtr->numModKeyCodes; i++) {
			if (dispPtr->modKeyCodes[i] == eventPtr->xkey.keycode) {
			    goto nextEvent;
			}
	    if (psPtr->object
		    ? psPtr->object == object
		    : VirtPatIsBound(bindPtr, psPtr, object, physPtrPtr)) {
		TkPattern *patPtr = psPtr->pats + patIndex;

                /* Ignore modifier key events, and KeyRelease events if the current event
                 * is of a different type (e.g. a Button event)
		    }
		}
		goto nextSequence;
	    }
	    flags = flagArray[eventPtr->type];
                 */
                psEntry->keepIt = isModKeyOnly || \
	    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		state = eventPtr->xkey.state;
	    } else if (flags & CROSSING) {
		state = eventPtr->xcrossing.state;
	    } else {
		state = 0;
                        ((patPtr->eventType != (unsigned) curEvent->xev.type) && curEvent->xev.type == KeyRelease);

		if (patPtr->eventType == (unsigned) curEvent->xev.type
	    }
	    if (patPtr->needMods != 0) {
			&& (curEvent->xev.type != CreateNotify
				|| curEvent->xev.xcreatewindow.parent == window)
			&& (!patPtr->name || patPtr->name == curEvent->detail.name)
		modMask = patPtr->needMods;
			&& (!patPtr->info || patPtr->info == curEvent->detail.info)) {
		    /*
		     * Resolve the modifier mask for Alt and Mod keys. Unfortunately this
		     * cannot be done in ParseEventDescription, otherwise this function would
		     * be the better place.
		     */
		    unsigned modMask = ResolveModifiers(dispPtr, patPtr->modMask);
		if ((modMask & META_MASK) && (dispPtr->metaModMask != 0)) {
		    modMask = (modMask & ~META_MASK) | dispPtr->metaModMask;
		}
		if ((modMask & ALT_MASK) && (dispPtr->altModMask != 0)) {
		    modMask = (modMask & ~ALT_MASK) | dispPtr->altModMask;
		}

		if ((state & META_MASK) && (dispPtr->metaModMask != 0)) {
		    state = (state & ~META_MASK) | dispPtr->metaModMask;
		}
		if ((state & ALT_MASK) && (dispPtr->altModMask != 0)) {
		    state = (state & ~ALT_MASK) | dispPtr->altModMask;
		}

		if ((state & modMask) != modMask) {
		    unsigned curModMask = ResolveModifiers(dispPtr, bindPtr->curModMask);

		    goto nextSequence;
		}
		    psEntry->expired = 1; /* Remove it from promotion list. */
                    psEntry->keepIt = 0;  /* Don't keep matching patterns. */

		    if (IsSubsetOf(modMask, curModMask)) {
			unsigned count = patPtr->info ? curEvent->countDetailed : curEvent->countAny;
	    }
	    if (psPtr->flags & PAT_NEARBY) {
		XEvent *firstPtr = &bindPtr->eventRing[bindPtr->curEvent];
		int timeDiff;

			if (patIndex < PSModMaskArr_Size(psEntry->lastModMaskArr)) {
			    PSModMaskArr_Set(psEntry->lastModMaskArr, patIndex, &modMask);
			}

		timeDiff = (Time) firstPtr->xkey.time - eventPtr->xkey.time;
		if ((firstPtr->xkey.x_root
			    < (eventPtr->xkey.x_root - NEARBY_PIXELS))
			|| (firstPtr->xkey.x_root
			    > (eventPtr->xkey.x_root + NEARBY_PIXELS))
			|| (firstPtr->xkey.y_root
			    < (eventPtr->xkey.y_root - NEARBY_PIXELS))
			|| (firstPtr->xkey.y_root
			    > (eventPtr->xkey.y_root + NEARBY_PIXELS))
			|| (timeDiff > NEARBY_MS)) {
		    goto nextSequence;
		}
	    }
			/*
			 * This pattern is finally matching.
	    patPtr++;
			 */

	    patCount--;
	nextEvent:
	    if (eventPtr == bindPtr->eventRing) {
		eventPtr = &bindPtr->eventRing[EVENT_BUFFER_SIZE-1];
		detailPtr = &bindPtr->detailRing[EVENT_BUFFER_SIZE-1];
	    } else {
		eventPtr--;
		detailPtr--;
	    }
			if (psPtr->numPats == patIndex + 1) {
			    if (patPtr->count <= count) {
				/*
	    ringCount--;
	}

				 * This is also a final pattern (i.e. the pattern sequence is complete).
				 * We always prefer the pattern with better match.
				 * If completely equal than prefer most recently defined pattern.
	matchPtr = psPtr;
	sourcePtr = psPtr;

				 */
	if (objectPtr != NULL) {
	    int iVirt;
	    VirtualOwners *voPtr;
	    PatternTableKey key;

				int cmp = Compare(bestPtr, psPtr);
	    /*
	     * The sequence matches the physical constraints. Is this object
	     * interested in any of the virtual events that correspond to this
	     * sequence?
	     */

				if (cmp == 0) {
	    voPtr = psPtr->voPtr;
				    cmp = CompareModMasks(psEntry->lastModMaskArr, bestModMaskArr,
					    modMask, bestModMask);
				}

	    memset(&key, 0, sizeof(key));
	    key.object = *objectPtr;
	    key.type = VirtualEvent;
	    key.detail.clientData = 0;

				if (cmp > 0 || (cmp == 0 && bestPtr->number < psPtr->number)) {
				    bestPtr = psPtr;
				    bestModMask = modMask;
	    for (iVirt = 0; iVirt < voPtr->numOwners; iVirt++) {
		Tcl_HashEntry *hPtr = voPtr->owners[iVirt];

				    bestModMaskArr = psEntry->lastModMaskArr;
				    if (physPtrPtr) {
					bestPhysPtr = *physPtrPtr;
				    }
				}
		key.detail.name = (Tk_Uid) Tcl_GetHashKey(hPtr->tablePtr,
			hPtr);
		hPtr = Tcl_FindHashEntry(&bindPtr->patternTable,
			(char *) &key);
		if (hPtr != NULL) {
		    /*
		     * This tag is interested in this virtual event and its
		     * corresponding physical event is a good match with the
		     * virtual event's definition.
		     */

		    PatSeq *virtMatchPtr = Tcl_GetHashValue(hPtr);

		    if ((virtMatchPtr->numPats != 1)
			    || (virtMatchPtr->nextSeqPtr != NULL)) {
			Tcl_Panic("MatchPattern: badly constructed virtual event");
		    }
			    } else {
				DEBUG(psEntry->expired = 0;)
		    sourcePtr = virtMatchPtr;
				psEntry->keepIt = 1; /* Don't remove it from promotion list. */
			    }
			} else if (psSuccList) {
			    /*
		    goto match;
		}
	    }

	    /*
			     * Not a final pattern, but matching (i.e. successive patterns match the pattern sequence so far),
			     * so promote the pattern sequence to next level if not already promoted in the success list.
			     * But do not promote if count of current pattern is not yet reached.
			     */
			    if (!IsPSInPSList(psPtr, psSuccList)) {
				if (patPtr->count == psEntry->count) {
	     * The physical event matches a virtual event's definition, but
	     * the tag isn't interested in it.
	     */

	    goto nextSequence;
				    PSEntry *psNewEntry;

				    assert(!patPtr->name);
				    psNewEntry = MakeListEntry(
					&bindPtr->lookupTables.entryPool, psPtr, psPtr->modMaskUsed);
				    if (!PSModMaskArr_IsEmpty(psNewEntry->lastModMaskArr)) {
					PSModMaskArr_Set(psNewEntry->lastModMaskArr, patIndex, &modMask);
				    }
	}
    match:

	/*
	 * This sequence matches. If we've already got another match, pick
	 * whichever is most specific. Detail is most important, then
	 * needMods.
	 */

				    assert(psNewEntry->keepIt);
				    assert(psNewEntry->count == 1u);
				    PSList_Append(psSuccList, psNewEntry);
				    psNewEntry->window = window; /* Bind to current window. */
				} else {
	if (bestPtr != NULL) {
	    TkPattern *patPtr2;

	    if (matchPtr->numPats != bestPtr->numPats) {
		if (bestPtr->numPats > matchPtr->numPats) {
		    goto nextSequence;
		} else {
				    assert(psEntry->count < patPtr->count);
				    DEBUG(psEntry->expired = 0;)
				    psEntry->count += 1;
				    psEntry->keepIt = 1; /* Don't remove it from promotion list. */
				}
			    } else {
		    goto newBest;
		}
	    }
	    for (i = 0, patPtr = matchPtr->pats, patPtr2 = bestPtr->pats;
		    i < matchPtr->numPats; i++, patPtr++, patPtr2++) {
		if (patPtr->detail.clientData != patPtr2->detail.clientData) {
		    if (patPtr->detail.clientData == 0) {
			goto nextSequence;
		    } else {
			        /*
				 * Pattern sequence is already present in the success list.
				 */

				DEBUG(psEntry->expired = 0;)
				psEntry->keepIt = 1; /* Don't remove it from promotion list. */
			    }
			}
		    }
		}
	    }
			goto newBest;
		    }
		}
		if (patPtr->needMods != patPtr2->needMods) {
		    if ((patPtr->needMods & patPtr2->needMods)
			    == patPtr->needMods) {
			goto nextSequence;
		    } else if ((patPtr->needMods & patPtr2->needMods)
			    == patPtr2->needMods) {
			goto newBest;
		    }
		}
	    }

	    /*
	     * Tie goes to current best pattern.
	     *
	     * (1) For virtual vs. virtual, the least recently defined virtual
	     * wins, because virtuals are examined in order of definition.
	     * This order is _not_ guaranteed in the documentation.
	     *
	     * (2) For virtual vs. physical, the physical wins because all the
	     * physicals are examined before the virtuals. This order is
	     * guaranteed in the documentation.
	     *
	     * (3) For physical vs. physical pattern, the most recently
	     * defined physical wins, because physicals are examined in
	     * reverse order of definition. This order is guaranteed in the
	     * documentation.
	     */

	    goto nextSequence;
	}
    newBest:
	bestPtr = matchPtr;
	bestSourcePtr = sourcePtr;
    }


    nextSequence:
	continue;
    }
    if (bestPhysPtr) {
	assert(physPtrPtr);
	*physPtrPtr = bestPhysPtr;
    }

    *sourcePtrPtr = bestSourcePtr;
    return bestPtr;
}

/*
 *--------------------------------------------------------------
 *
 * ExpandPercents --
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

3171
3172
3173




3174
3175

3176
3177

3178
3179



3180
3181



3182
3183

3184
3185
3186


3187
3188

3189
3190

3191
3192





3193
3194



3195
3196

3197
3198

3199
3200

3201
3202

3203
3204
3205

3206
3207

3208
3209



3210
3211

3212



3213
3214




3215
3216

3217
3218
3219


3220
3221
3222
3223




3224
3225
3226
3227

3228
3229
3230


3231
3232
3233



3234
3235

3236
3237
3238


3239
3240

3241
3242
3243


3244
3245
3246

3247
3248
3249
3250
3251











3252
3253
3254

3255
3256
3257
3258


3259


3260
3261

3262
3263
3264
3265






3266
3267

3268
3269
3270






3271
3272

3273
3274
3275
3276
3277

3278
3279
3280
3281
3282








3283
3284
3285
3286
3287
3288
3289







3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
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







-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
+
+
+

-
-
+
-
-
-
-


-
-
-
+
+
+
-
-
-
-
-
+
+
-
-
-



-
-
-
-
-





-
+
-
+
+

-
+


-
+







+



-
-
+
+


-
+


-
+


-
+
+

-
+


-
+
+

-
+


+
+
+
-
-
+
+
+

-
-
+
+
+




-
-
-
-
+
+
+
+
+
+
+
+
+


-
+
+

-
+


-
+

-
+

-
+

-
+

-
+
+
+

-
+


-
+

-
+
+

-
+

-
+


-
+

-
-
+
+
+

-
+


+
-
+

+
-
+

-
+


-
+

-
+

-
+

-
+
+
+

-
+


-
+
+

-
+
+

-
+

-
-
+
+
+

-
+
+

-
+
+

-
+
+

-
+

-
-
+
+
+
+

-
+
+
+

-
+

-
-
+
+


-
+

-
+

-
+

-
+

-
+
+
+

-
+

-
-
+
+
+
+

-
+

-
+

-
+
+
+

-
+
+
+

-
+

-
-
+
+

-
+

-
+

-
+
+
+
+
+

-
+
+
+

-
+

-
+

-
+

-
+


-
+

-
+

-
+
+
+

-
+

+
+
+
-
-
+
+
+
+

-
+

-
-
+
+

-
-
-
+
+
+
+



-
+

-
-
+
+

-
-
+
+
+

-
+


-
+
+

-
+

-
-
+
+


-
+

-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
+
+

+
+

-
+


-
-
+
+
+
+
+
+

-
+

-
-
+
+
+
+
+
+

-
+




-
+

-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-







 *	None.
 *
 *--------------------------------------------------------------
 */

static void
ExpandPercents(
    TkWindow *winPtr,		/* Window where event occurred: needed to get input context. */
    const char *before,		/* Command containing percent expressions to be replaced. */
    Event *eventPtr,		/* Event containing information to be used in % replacements. */
    unsigned scriptCount,	/* The number of script-based binding patterns matched so far for
    				 * this event. */
    Tcl_DString *dsPtr)		/* Dynamic string in which to append new command. */
    TkWindow *winPtr,		/* Window where event occurred: needed to get
				 * input context. */
    const char *before,		/* Command containing percent expressions to
				 * be replaced. */
    XEvent *eventPtr,		/* X event containing information to be used
				 * in % replacements. */
    KeySym keySym,		/* KeySym: only relevant for KeyPress and
				 * KeyRelease events). */
    unsigned int scriptCount,	/* The number of script-based binding patterns
				 * matched so far for this event. */
    Tcl_DString *dsPtr)		/* Dynamic string in which to append new
				 * command. */
{
    int spaceNeeded, cvtFlags;	/* Used to substitute string as proper Tcl
				 * list element. */
    unsigned flags;
    int number, flags, length;
#define NUM_SIZE 40
    const char *string;
    Tcl_DString buf;
    XEvent *evPtr;

    char numStorage[NUM_SIZE+1];
    assert(winPtr);
    assert(before);
    assert(eventPtr);
    assert(dsPtr);

    Tcl_DStringInit(&buf);
    evPtr = &eventPtr->xev;
    flags = (evPtr->type < TK_LASTEVENT) ? flagArray[evPtr->type] : 0;


    if (eventPtr->type < TK_LASTEVENT) {
	flags = flagArray[eventPtr->type];
#define SET_NUMBER(value)   { number = (value);			     \
    snprintf(numStorage, sizeof(numStorage), "%" TCL_LL_MODIFIER "d", number);	     \
    string = numStorage;					     \
    }

    } else {
	flags = 0;
#define SET_UNUMBER(value)  { unumber = (value);				\
	snprintf(numStorage, sizeof(numStorage), "%" TCL_LL_MODIFIER "u", unumber);	\
	string = numStorage;						\
    }

    while (1) {
	char numStorage[TCL_INTEGER_SPACE];
	const char *string;
	long long number;     /* signed */
	unsigned long long unumber;   /* unsigned */

	/*
	 * Find everything up to the next % character and append it to the
	 * result string.
	 */

	for (string = before; *string && *string != '%'; ++string)
	for (string = before; (*string != 0) && (*string != '%'); string++) {
	    ;
	    /* Empty loop body. */
	}
	if (string != before) {
	    Tcl_DStringAppend(dsPtr, before, (Tcl_Size)(string - before));
	    Tcl_DStringAppend(dsPtr, before, (int) (string-before));
	    before = string;
	}
	if (!*before) {
	if (*before == 0) {
	    break;
	}

	/*
	 * There's a percent sequence here. Process it.
	 */

	number = 0;
	string = "??";
	switch (before[1]) {
	case '#':
	    SET_UNUMBER(evPtr->xany.serial);
	    break;
	    number = eventPtr->xany.serial;
	    goto doNumber;
	case 'a':
	    if (flags & CONFIG) {
		TkpPrintWindowId(numStorage, evPtr->xconfigure.above);
		TkpPrintWindowId(numStorage, eventPtr->xconfigure.above);
		string = numStorage;
	    }
	    break;
	    goto doString;
	case 'b':
	    if (flags & BUTTON) {
		SET_UNUMBER(evPtr->xbutton.button);
		number = eventPtr->xbutton.button;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'c':
	    if (flags & EXPOSE) {
		SET_NUMBER(evPtr->xexpose.count);
		number = eventPtr->xexpose.count;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'd':
	    if (flags & (CROSSING|FOCUS)) {
		if (flags & FOCUS) {
		    number = eventPtr->xfocus.detail;
		} else {
		int detail = (flags & FOCUS) ? evPtr->xfocus.detail : evPtr->xcrossing.detail;
		string = TkFindStateString(notifyDetail, detail);
		    number = eventPtr->xcrossing.detail;
		}
		string = TkFindStateString(notifyDetail, number);
	    } else if (flags & CONFIGREQ) {
		if (evPtr->xconfigurerequest.value_mask & CWStackMode) {
		    string = TkFindStateString(configureRequestDetail, evPtr->xconfigurerequest.detail);
		if (eventPtr->xconfigurerequest.value_mask & CWStackMode) {
		    string = TkFindStateString(configureRequestDetail,
			    eventPtr->xconfigurerequest.detail);
		} else {
		    string = "";
		}
	    } else if (flags & VIRTUAL) {
		XVirtualEvent *vePtr = (XVirtualEvent *) evPtr;
		string = vePtr->user_data ? Tcl_GetString(vePtr->user_data) : "";
	    }
	    break;
		XVirtualEvent *vePtr = (XVirtualEvent *) eventPtr;

		if (vePtr->user_data != NULL) {
		    string = Tcl_GetString(vePtr->user_data);
		} else {
		    string = "";
		}
	    }
	    goto doString;
	case 'f':
	    if (flags & CROSSING) {
		SET_NUMBER(evPtr->xcrossing.focus != 0);
		number = eventPtr->xcrossing.focus;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'h':
	    if (flags & EXPOSE) {
		SET_NUMBER(evPtr->xexpose.height);
		number = eventPtr->xexpose.height;
	    } else if (flags & CONFIG) {
		SET_NUMBER(evPtr->xconfigure.height);
		number = eventPtr->xconfigure.height;
	    } else if (flags & CREATE) {
		SET_NUMBER(evPtr->xcreatewindow.height);
		number = eventPtr->xcreatewindow.height;
	    } else if (flags & CONFIGREQ) {
		SET_NUMBER(evPtr->xconfigurerequest.height);
		number = eventPtr->xconfigurerequest.height;
	    } else if (flags & RESIZEREQ) {
		SET_NUMBER(evPtr->xresizerequest.height);
		number = eventPtr->xresizerequest.height;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'i':
	    if (flags & CREATE) {
		TkpPrintWindowId(numStorage, evPtr->xcreatewindow.window);
		TkpPrintWindowId(numStorage, eventPtr->xcreatewindow.window);
	    } else if (flags & CONFIGREQ) {
		TkpPrintWindowId(numStorage, evPtr->xconfigurerequest.window);
		TkpPrintWindowId(numStorage,
			eventPtr->xconfigurerequest.window);
	    } else if (flags & MAPREQ) {
		TkpPrintWindowId(numStorage, evPtr->xmaprequest.window);
		TkpPrintWindowId(numStorage, eventPtr->xmaprequest.window);
	    } else {
		TkpPrintWindowId(numStorage, evPtr->xany.window);
		TkpPrintWindowId(numStorage, eventPtr->xany.window);
	    }
	    string = numStorage;
	    break;
	    goto doString;
	case 'k':
	    if (flags & KEY) {
		SET_UNUMBER(evPtr->xkey.keycode);
	    if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) {
		number = eventPtr->xkey.keycode;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'm':
	    if (flags & CROSSING) {
		number = eventPtr->xcrossing.mode;
		string = TkFindStateString(notifyMode, evPtr->xcrossing.mode);
		string = TkFindStateString(notifyMode, number);
	    } else if (flags & FOCUS) {
		number = eventPtr->xfocus.mode;
		string = TkFindStateString(notifyMode, evPtr->xfocus.mode);
		string = TkFindStateString(notifyMode, number);
	    }
	    break;
	    goto doString;
	case 'o':
	    if (flags & CREATE) {
		SET_NUMBER(evPtr->xcreatewindow.override_redirect != 0);
		number = eventPtr->xcreatewindow.override_redirect;
	    } else if (flags & MAP) {
		SET_NUMBER(evPtr->xmap.override_redirect != 0);
		number = eventPtr->xmap.override_redirect;
	    } else if (flags & REPARENT) {
		SET_NUMBER(evPtr->xreparent.override_redirect != 0);
		number = eventPtr->xreparent.override_redirect;
	    } else if (flags & CONFIG) {
		SET_NUMBER(evPtr->xconfigure.override_redirect != 0);
		number = eventPtr->xconfigure.override_redirect;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'p':
	    if (flags & CIRC) {
		string = TkFindStateString(circPlace, evPtr->xcirculate.place);
		string = TkFindStateString(circPlace,
			eventPtr->xcirculate.place);
	    } else if (flags & CIRCREQ) {
		string = TkFindStateString(circPlace, evPtr->xcirculaterequest.place);
		string = TkFindStateString(circPlace,
			eventPtr->xcirculaterequest.place);
	    }
	    break;
	    goto doString;
	case 's':
	    if (flags & HAS_XKEY_HEAD_AND_STATE) {
		SET_UNUMBER(evPtr->xkey.state);
	    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		number = eventPtr->xkey.state;
		goto doNumber;
	    } else if (flags & CROSSING) {
		SET_UNUMBER(evPtr->xcrossing.state);
		number = eventPtr->xcrossing.state;
		goto doNumber;
	    } else if (flags & PROP) {
		string = TkFindStateString(propNotify, evPtr->xproperty.state);
		string = TkFindStateString(propNotify,
			eventPtr->xproperty.state);
	    } else if (flags & VISIBILITY) {
		string = TkFindStateString(visNotify, evPtr->xvisibility.state);
		string = TkFindStateString(visNotify,
			eventPtr->xvisibility.state);
	    }
	    break;
	    goto doString;
	case 't':
	    if (flags & HAS_XKEY_HEAD) {
		SET_UNUMBER(evPtr->xkey.time);
	    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		number = (int) eventPtr->xkey.time;
	    } else if (flags & CROSSING) {
		number = (int) eventPtr->xcrossing.time;
	    } else if (flags & PROP) {
		SET_UNUMBER(evPtr->xproperty.time);
		number = (int) eventPtr->xproperty.time;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'v':
	    SET_UNUMBER(evPtr->xconfigurerequest.value_mask);
	    break;
	    number = eventPtr->xconfigurerequest.value_mask;
	    goto doNumber;
	case 'w':
	    if (flags & EXPOSE) {
		SET_NUMBER(evPtr->xexpose.width);
		number = eventPtr->xexpose.width;
	    } else if (flags & CONFIG) {
		SET_NUMBER(evPtr->xconfigure.width);
		number = eventPtr->xconfigure.width;
	    } else if (flags & CREATE) {
		SET_NUMBER(evPtr->xcreatewindow.width);
		number = eventPtr->xcreatewindow.width;
	    } else if (flags & CONFIGREQ) {
		SET_NUMBER(evPtr->xconfigurerequest.width);
		number = eventPtr->xconfigurerequest.width;
	    } else if (flags & RESIZEREQ) {
		SET_NUMBER(evPtr->xresizerequest.width);
		number = eventPtr->xresizerequest.width;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'x':
	    if (flags & HAS_XKEY_HEAD) {
		SET_NUMBER(evPtr->xkey.x);
	    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		number = eventPtr->xkey.x;
	    } else if (flags & CROSSING) {
		number = eventPtr->xcrossing.x;
	    } else if (flags & EXPOSE) {
		SET_NUMBER(evPtr->xexpose.x);
		number = eventPtr->xexpose.x;
	    } else if (flags & (CREATE|CONFIG|GRAVITY)) {
		SET_NUMBER(evPtr->xcreatewindow.x);
		number = eventPtr->xcreatewindow.x;
	    } else if (flags & REPARENT) {
		SET_NUMBER(evPtr->xreparent.x);
		number = eventPtr->xreparent.x;
	    } else if (flags & CREATE) {
		number = eventPtr->xcreatewindow.x;
	    } else if (flags & CONFIGREQ) {
		SET_NUMBER(evPtr->xconfigurerequest.x);
		number = eventPtr->xconfigurerequest.x;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'y':
	    if (flags & HAS_XKEY_HEAD) {
		SET_NUMBER(evPtr->xkey.y);
	    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		number = eventPtr->xkey.y;
	    } else if (flags & EXPOSE) {
		SET_NUMBER(evPtr->xexpose.y);
		number = eventPtr->xexpose.y;
	    } else if (flags & (CREATE|CONFIG|GRAVITY)) {
		SET_NUMBER(evPtr->xcreatewindow.y);
		number = eventPtr->xcreatewindow.y;
	    } else if (flags & REPARENT) {
		SET_NUMBER(evPtr->xreparent.y);
		number = eventPtr->xreparent.y;
	    } else if (flags & CROSSING) {
		number = eventPtr->xcrossing.y;
	    } else if (flags & CREATE) {
		number = eventPtr->xcreatewindow.y;
	    } else if (flags & CONFIGREQ) {
		SET_NUMBER(evPtr->xconfigurerequest.y);
		number = eventPtr->xconfigurerequest.y;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'A':
	    if (flags & KEY) {
	    if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) {
		Tcl_DStringFree(&buf);
		string = TkpGetString(winPtr, evPtr, &buf);
		string = TkpGetString(winPtr, eventPtr, &buf);
	    }
	    break;
	    goto doString;
	case 'B':
	    if (flags & CREATE) {
		SET_NUMBER(evPtr->xcreatewindow.border_width);
		number = eventPtr->xcreatewindow.border_width;
	    } else if (flags & CONFIGREQ) {
		SET_NUMBER(evPtr->xconfigurerequest.border_width);
		number = eventPtr->xconfigurerequest.border_width;
	    } else if (flags & CONFIG) {
		SET_NUMBER(evPtr->xconfigure.border_width);
		number = eventPtr->xconfigure.border_width;
	    } else {
		goto doString;
	    }
	    break;
	    goto doNumber;
	case 'D':
	    /*
	     * This is used only by the MouseWheel event.
	     */
	    if (flags & WHEEL) {
		SET_NUMBER((int)evPtr->xbutton.button); /* mis-use button field for this */

	    if ((flags & KEY) && (eventPtr->type == MouseWheelEvent)) {
		number = eventPtr->xkey.keycode;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'E':
	    SET_NUMBER(evPtr->xany.send_event != 0);
	    break;
	    number = (int) eventPtr->xany.send_event;
	    goto doNumber;
	case 'K':
	    if (flags & KEY) {
		const char *name = TkKeysymToString(eventPtr->detail.info);
		if (name) {
	    if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) {
		const char *name = TkKeysymToString(keySym);

		if (name != NULL) {
		    string = name;
		}
	    }
	    break;
	    goto doString;
	case 'M':
	    SET_UNUMBER(scriptCount);
	    break;
	    number = scriptCount;
	    goto doNumber;
	case 'N':
	    if (flags & KEY) {
		SET_UNUMBER(eventPtr->detail.info);
	    if ((flags & KEY) && (eventPtr->type != MouseWheelEvent)) {
		number = (int) keySym;
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'P':
	    if (flags & PROP) {
		string = Tk_GetAtomName((Tk_Window) winPtr, evPtr->xproperty.atom);
		string = Tk_GetAtomName((Tk_Window) winPtr,
			eventPtr->xproperty.atom);
	    }
	    break;
	    goto doString;
	case 'R':
	    if (flags & HAS_XKEY_HEAD) {
		TkpPrintWindowId(numStorage, evPtr->xkey.root);
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		TkpPrintWindowId(numStorage, eventPtr->xkey.root);
		string = numStorage;
	    }
	    break;
	    goto doString;
	case 'S':
	    if (flags & HAS_XKEY_HEAD) {
		TkpPrintWindowId(numStorage, evPtr->xkey.subwindow);
		string = numStorage;
	    }
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		TkpPrintWindowId(numStorage, eventPtr->xkey.subwindow);
		string = numStorage;
	    }
	    goto doString;
	case 'T':
	    number = eventPtr->type;
	    goto doNumber;
	case 'W': {
	    Tk_Window tkwin;

	    break;
	case 'T':
	    SET_NUMBER(evPtr->type);
	    tkwin = Tk_IdToWindow(eventPtr->xany.display,
	    break;
	case 'W': {
	    Tk_Window tkwin = Tk_IdToWindow(evPtr->xany.display, evPtr->xany.window);
	    if (tkwin) {
		    eventPtr->xany.window);
	    if (tkwin != NULL) {
		string = Tk_PathName(tkwin);
	    } else {
		string = "??";
	    }
	    break;
	    goto doString;
	}
	case 'X':
	    if (flags & HAS_XKEY_HEAD) {
		SET_NUMBER(evPtr->xkey.x_root);
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {

		number = eventPtr->xkey.x_root;
		Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);
		goto doNumber;
	    }
	    break;
	    goto doString;
	case 'Y':
	    if (flags & HAS_XKEY_HEAD) {
		SET_NUMBER(evPtr->xkey.y_root);
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {

		number = eventPtr->xkey.y_root;
		Tk_IdToWindow(eventPtr->xany.display,
			eventPtr->xany.window);
		goto doNumber;
	    }
	    break;
	    goto doString;
	default:
	    numStorage[0] = before[1];
	    numStorage[1] = '\0';
	    string = numStorage;
	    break;
	    goto doString;
	}
	{   /* local scope */
	    int cvtFlags;
	    Tcl_Size spaceNeeded = Tcl_ScanElement(string, &cvtFlags);
	    Tcl_Size length = Tcl_DStringLength(dsPtr);

    doNumber:
	sprintf(numStorage, "%d", number);
	string = numStorage;

    doString:
	spaceNeeded = Tcl_ScanElement(string, &cvtFlags);
	length = Tcl_DStringLength(dsPtr);

	    Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
	    spaceNeeded = Tcl_ConvertElement(
		    string, Tcl_DStringValue(dsPtr) + length, cvtFlags | TCL_DONT_USE_BRACES);
	    Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
	    before += 2;
	}
	Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
	spaceNeeded = Tcl_ConvertElement(string,
		Tcl_DStringValue(dsPtr) + length,
		cvtFlags | TCL_DONT_USE_BRACES);
	Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
	before += 2;
    }
    }

#undef SET_NUMBER
#undef SET_UNUMBER

    Tcl_DStringFree(&buf);
}

/*
 *----------------------------------------------------------------------
 *
 * ChangeScreen --
3318
3319
3320
3321
3322
3323
3324
3325


3326
3327
3328
3329
3330
3331


3332
3333
3334
3335
3336
3337
3338
2306
2307
2308
2309
2310
2311
2312

2313
2314
2315
2316
2317
2318
2319

2320
2321
2322
2323
2324
2325
2326
2327
2328







-
+
+





-
+
+








static void
ChangeScreen(
    Tcl_Interp *interp,		/* Interpreter in which to invoke command. */
    char *dispName,		/* Name of new display. */
    int screenIndex)		/* Index of new screen. */
{
    Tcl_Obj *cmdObj = Tcl_ObjPrintf("::tk::ScreenChanged %s.%d", dispName, screenIndex);
    Tcl_Obj *cmdObj = Tcl_ObjPrintf("::tk::ScreenChanged %s.%d",
	    dispName, screenIndex);
    int code;

    Tcl_IncrRefCount(cmdObj);
    code = Tcl_EvalObjEx(interp, cmdObj, TCL_EVAL_GLOBAL);
    if (code != TCL_OK) {
	Tcl_AddErrorInfo(interp, "\n    (changing screen in event binding)");
	Tcl_AddErrorInfo(interp,
		"\n    (changing screen in event binding)");
	Tcl_BackgroundException(interp, code);
    }
    Tcl_DecrRefCount(cmdObj);
}

/*
 *----------------------------------------------------------------------
3349
3350
3351
3352
3353
3354
3355
3356

3357
3358
3359
3360
3361
3362
3363
3364
3365
3366



3367
3368

3369
3370

3371
3372

3373
3374

3375
3376

3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388


3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399


3400
3401
3402
3403

3404
3405

3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435

3436
3437
3438
3439
3440
3441
3442
3443
3444


3445
3446
3447
3448
3449
3450
3451
3452
3453

3454
3455
3456
3457




3458
3459
3460
3461
3462
3463
3464
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







-
+







-
-
-
+
+
+
-
-
+
-
-
+
-
-
+

-
+
-
-
+
-
-


-





-
-
+
+



-
-
-
-



-
+
+



-
+

-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+








-
+
+







-
-
+

-
-
-
+
+
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_EventObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int index, i;
    char *name;
    const char *event;
    Tk_Window tkwin;
    TkBindInfo bindInfo;
    VirtualEventTable *vetPtr;
    Tk_Window tkwin = clientData;
    TkBindInfo bindInfo = ((TkWindow *) tkwin)->mainPtr->bindInfo;
    VirtualEventTable *vetPtr = &bindInfo->virtualEventTable;

    static const char *const optionStrings[] = { "add",
    static const char *const optionStrings[] = {
#if SUPPORT_DEBUGGING
	"debug",
	"add",		"delete",	"generate",	"info",
#endif
	"delete", "generate", "info", NULL
	NULL
    };
    enum options { EVENT_ADD,
    enum options {
#if SUPPORT_DEBUGGING
	EVENT_DEBUG,
	EVENT_ADD,	EVENT_DELETE,	EVENT_GENERATE,	EVENT_INFO
#endif
	EVENT_DELETE, EVENT_GENERATE, EVENT_INFO
    };

    assert(clientData);

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(
	    interp, objv[1], optionStrings, sizeof(char *), "option", 0, &index) != TCL_OK) {
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    tkwin = (Tk_Window) clientData;
    bindInfo = ((TkWindow *) tkwin)->mainPtr->bindInfo;
    vetPtr = &bindInfo->virtualEventTable;

    switch ((enum options) index) {
    case EVENT_ADD:
	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "virtual sequence ?sequence ...?");
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "virtual sequence ?sequence ...?");
	    return TCL_ERROR;
	}
	name = Tcl_GetString(objv[2]);
	for (i = 3; i < objc; ++i) {
	for (i = 3; i < objc; i++) {
	    event = Tcl_GetString(objv[i]);
	    if (!CreateVirtualEvent(interp, vetPtr, name, event)) {
	    if (CreateVirtualEvent(interp, vetPtr, name, event) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	break;
#if SUPPORT_DEBUGGING
    case EVENT_DEBUG:
	if (objc > 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "debug number");
	    return TCL_ERROR;
	}
	if (objc < 3) {
	    Tcl_SetObjResult(interp,
		Tcl_NewIntObj(BindCount));
	    return TCL_OK;
	}
	if (Tcl_GetIntFromObj(interp, objv[2], &BindCount) != TCL_OK) {
	    return TCL_ERROR;
	}
	return TCL_OK;
#endif
    case EVENT_DELETE:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "virtual ?sequence ...?");
	    return TCL_ERROR;
	}
	name = Tcl_GetString(objv[2]);
	if (objc == 3) {
	    return DeleteVirtualEvent(interp, vetPtr, name, NULL);
	}
	for (i = 3; i < objc; ++i) {
	for (i = 3; i < objc; i++) {
	    event = Tcl_GetString(objv[i]);
	    if (DeleteVirtualEvent(interp, vetPtr, name, event) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	break;
    case EVENT_GENERATE:
	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window event ?-option value ...?");
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "window event ?-option value ...?");
	    return TCL_ERROR;
	}
	return HandleEventGenerate(interp, tkwin, objc - 2, objv + 2);
    case EVENT_INFO:
	if (objc == 2) {
	    GetAllVirtualEvents(interp, vetPtr);
	    return TCL_OK;
	}
	if (objc == 3) {
	} else if (objc == 3) {
	    return GetVirtualEvent(interp, vetPtr, objv[2]);
	}
	Tcl_WrongNumArgs(interp, 2, objv, "?virtual?");
	return TCL_ERROR;
	} else {
	    Tcl_WrongNumArgs(interp, 2, objv, "?virtual?");
	    return TCL_ERROR;
	}
    }
    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------
 *
3474
3475
3476
3477
3478
3479
3480
3481


3482
3483
3484
3485
3486


3487
3488
3489
3490
3491
3492
3493
3494
3495
2439
2440
2441
2442
2443
2444
2445

2446
2447
2448




2449
2450
2451

2452
2453
2454
2455
2456
2457
2458







-
+
+

-
-
-
-
+
+

-







 *	*vetPtr is now initialized.
 *
 *---------------------------------------------------------------------------
 */

static void
InitVirtualEventTable(
    VirtualEventTable *vetPtr)	/* Pointer to virtual event table. Memory is supplied by the caller. */
    VirtualEventTable *vetPtr)	/* Pointer to virtual event table. Memory is
				 * supplied by the caller. */
{
    assert(vetPtr);
    memset(vetPtr, 0, sizeof(*vetPtr));
    Tcl_InitHashTable(&vetPtr->lookupTables.patternTable, sizeof(PatternTableKey)/sizeof(int));
    Tcl_InitHashTable(&vetPtr->lookupTables.listTable, sizeof(PatternTableKey)/sizeof(int));
    Tcl_InitHashTable(&vetPtr->patternTable,
	    sizeof(PatternTableKey) / sizeof(int));
    Tcl_InitHashTable(&vetPtr->nameTable, TCL_ONE_WORD_KEYS);
    PSList_Init(&vetPtr->lookupTables.entryPool);
}

/*
 *---------------------------------------------------------------------------
 *
 * DeleteVirtualEventTable --
 *
3507
3508
3509
3510
3511
3512
3513
3514

3515
3516
3517
3518


3519
3520
3521
3522


3523
3524
3525
3526


3527
3528
3529

3530
3531
3532

3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553

3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569


3570
3571
3572
3573

3574


3575
3576
3577
3578
3579
3580
3581
3582



3583
3584
3585
3586

3587
3588
3589
3590




3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604









3605

3606
3607
3608
3609
3610
3611
3612
























3613



3614
3615

3616
3617
3618
3619
3620
3621
3622
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







-
+
-

-
-
+
+
-
-
-
-
+
+
-

-
-
+
+


-
+


-
+



-
-
-
-
-
-











-
+















-
+
+




+
-
+
+


-
-
-
-
-
-
+
+
+



-
+


-
-
+
+
+
+

-











-
+
+
+
+
+
+
+
+
+

+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+

-
+








static void
DeleteVirtualEventTable(
    VirtualEventTable *vetPtr)	/* The virtual event table to delete. */
{
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    PatSeq *psPtr, *nextPtr;
    assert(vetPtr);

    hPtr = Tcl_FirstHashEntry(&vetPtr->lookupTables.patternTable, &search);
    for ( ; hPtr; hPtr = Tcl_NextHashEntry(&search)) {
    hPtr = Tcl_FirstHashEntry(&vetPtr->patternTable, &search);
    for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	PatSeq *nextPtr;
	PatSeq *psPtr;

	for (psPtr = (PatSeq *)Tcl_GetHashValue(hPtr); psPtr; psPtr = nextPtr) {
	psPtr = Tcl_GetHashValue(hPtr);
	for ( ; psPtr != NULL; psPtr = nextPtr) {
	    assert(TEST_PSENTRY(psPtr));
	    nextPtr = psPtr->nextSeqPtr;
	    DEBUG(psPtr->owned = 0;)
	    FreePatSeq(psPtr);
	    ckfree(psPtr->voPtr);
	    ckfree(psPtr);
	}
    }
    Tcl_DeleteHashTable(&vetPtr->lookupTables.patternTable);
    Tcl_DeleteHashTable(&vetPtr->patternTable);

    hPtr = Tcl_FirstHashEntry(&vetPtr->nameTable, &search);
    for ( ; hPtr; hPtr = Tcl_NextHashEntry(&search)) {
    for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	ckfree(Tcl_GetHashValue(hPtr));
    }
    Tcl_DeleteHashTable(&vetPtr->nameTable);

    ClearLookupTable(&vetPtr->lookupTables, NULL);
    Tcl_DeleteHashTable(&vetPtr->lookupTables.listTable);

    DEBUG(countEntryItems -= PSList_Size(&vetPtr->lookupTables.entryPool);)
    PSList_Traverse(&vetPtr->lookupTables.entryPool, FreePatSeqEntry);
}

/*
 *----------------------------------------------------------------------
 *
 * CreateVirtualEvent --
 *
 *	Add a new definition for a virtual event. If the virtual event is
 *	already defined, the new definition augments those that already exist.
 *
 * Results:
 *	The return value is TCL_ERROR if an error occurred while creating the
 *	The return value is TCL_ERROR if an error occured while creating the
 *	virtual binding. In this case, an error message will be left in the
 *	interp's result. If all went well then the return value is TCL_OK.
 *
 * Side effects:
 *	The virtual event may cause future calls to Tk_BindEvent to behave
 *	differently than they did previously.
 *
 *----------------------------------------------------------------------
 */

static int
CreateVirtualEvent(
    Tcl_Interp *interp,		/* Used for error reporting. */
    VirtualEventTable *vetPtr,	/* Table in which to augment virtual event. */
    char *virtString,		/* Name of new virtual event. */
    const char *eventString)	/* String describing physical event that triggers virtual event. */
    const char *eventString)		/* String describing physical event that
				 * triggers virtual event. */
{
    PatSeq *psPtr;
    int dummy;
    Tcl_HashEntry *vhPtr;
    unsigned long eventMask;
    PhysOwned *owned;
    PhysicalsOwned *poPtr;
    VirtualOwners *voPtr;
    Tk_Uid virtUid;

    assert(vetPtr);
    assert(virtString);
    assert(eventString);

    if (!(virtUid = GetVirtualEventUid(interp, virtString))) {
	return 0;
    virtUid = GetVirtualEventUid(interp, virtString);
    if (virtUid == NULL) {
	return TCL_ERROR;
    }

    /*
     * Find/create physical event.
     * Find/create physical event
     */

    if (!(psPtr = FindSequence(interp, &vetPtr->lookupTables, NULL, eventString, 1, 0, NULL))) {
	return 0;
    psPtr = FindSequence(interp, &vetPtr->patternTable, NULL, eventString,
	    1, 0, &eventMask);
    if (psPtr == NULL) {
	return TCL_ERROR;
    }
    assert(TEST_PSENTRY(psPtr));

    /*
     * Find/create virtual event.
     */

    vhPtr = Tcl_CreateHashEntry(&vetPtr->nameTable, virtUid, &dummy);

    /*
     * Make virtual event own the physical event.
     */

    owned = (PhysOwned *)Tcl_GetHashValue(vhPtr);
    poPtr = Tcl_GetHashValue(vhPtr);
    if (poPtr == NULL) {
	poPtr = ckalloc(sizeof(PhysicalsOwned));
	poPtr->numOwned = 0;
    } else {
	/*
	 * See if this virtual event is already defined for this physical
	 * event and just return if it is.
	 */

	int i;
    if (!PhysOwned_Contains(owned, psPtr)) {
	PhysOwned_Append(&owned, psPtr);
	Tcl_SetHashValue(vhPtr, owned);
	DEBUG(psPtr->owned = 1;)
	InsertPatSeq(&vetPtr->lookupTables, psPtr);
	/* Make physical event so it can trigger the virtual event. */
	VirtOwners_Append(&psPtr->ptr.owners, vhPtr);

	for (i = 0; i < poPtr->numOwned; i++) {
	    if (poPtr->patSeqs[i] == psPtr) {
		return TCL_OK;
	    }
	}
	poPtr = ckrealloc(poPtr, sizeof(PhysicalsOwned)
		+ poPtr->numOwned * sizeof(PatSeq *));
    }
    Tcl_SetHashValue(vhPtr, poPtr);
    poPtr->patSeqs[poPtr->numOwned] = psPtr;
    poPtr->numOwned++;

    /*
     * Make physical event so it can trigger the virtual event.
     */

    voPtr = psPtr->voPtr;
    if (voPtr == NULL) {
	voPtr = ckalloc(sizeof(VirtualOwners));
	voPtr->numOwners = 0;
    } else {
	voPtr = ckrealloc(voPtr, sizeof(VirtualOwners)
		+ voPtr->numOwners * sizeof(Tcl_HashEntry *));
    }
    psPtr->voPtr = voPtr;
    voPtr->owners[voPtr->numOwners] = vhPtr;
    voPtr->numOwners++;

    return 1;
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * DeleteVirtualEvent --
 *
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647





3648
3649
3650
3651
3652
3653


3654
3655
3656
3657
3658
3659


3660
3661
3662
3663


3664
3665
3666

3667
3668
3669

3670

3671
3672
3673
3674
3675
3676
3677
3678
3679



3680

3681

3682
3683
3684
3685
3686


3687
3688



3689




3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
















3700

3701






















3702
3703
3704
3705
3706
3707
3708

3709
3710
3711
3712
3713
3714
3715

3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726


3727
3728
3729
3730
3731
3732
3733


3734
3735
3736
3737
3738
3739

3740
3741
3742
3743
3744
3745
3746


3747
3748
3749
3750
3751
3752
3753
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







-
-
-
+
+
+
+
+




-
-
+
+
-

-
-
-
-
+
+



-
+
+


-
+


-
+
-
+







-
-
+
+
+

+
-
+



-
-
+
+

-
+
+
+

+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+
-
-
-
-
-
-
-
+
-
-






-
-
-
+
+




-
-
-
+
+





-
+






-
+
+







 *--------------------------------------------------------------
 */

static int
DeleteVirtualEvent(
    Tcl_Interp *interp,		/* Used for error reporting. */
    VirtualEventTable *vetPtr,	/* Table in which to delete event. */
    char *virtString,		/* String describing event sequence that triggers binding. */
    const char *eventString)	/* The event sequence that should be deleted, or NULL to delete
    				 * all event sequences for the entire virtual event. */
    char *virtString,		/* String describing event sequence that
				 * triggers binding. */
    const char *eventString)		/* The event sequence that should be deleted,
				 * or NULL to delete all event sequences for
				 * the entire virtual event. */
{
    int iPhys;
    Tk_Uid virtUid;
    Tcl_HashEntry *vhPtr;
    PhysOwned *owned;
    const PatSeq *eventPSPtr;
    PhysicalsOwned *poPtr;
    PatSeq *eventPSPtr;
    PatSeq *lastElemPtr;

    assert(vetPtr);
    assert(virtString);

    if (!(virtUid = GetVirtualEventUid(interp, virtString))) {
    virtUid = GetVirtualEventUid(interp, virtString);
    if (virtUid == NULL) {
	return TCL_ERROR;
    }

    if (!(vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid))) {
    vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid);
    if (vhPtr == NULL) {
	return TCL_OK;
    }
    owned = (PhysOwned *)Tcl_GetHashValue(vhPtr);
    poPtr = Tcl_GetHashValue(vhPtr);

    eventPSPtr = NULL;
    if (eventString) {
    if (eventString != NULL) {
	LookupTables *lookupTables = &vetPtr->lookupTables;
	unsigned long eventMask;

	/*
	 * Delete only the specific physical event associated with the virtual
	 * event. If the physical event doesn't already exist, or the virtual
	 * event doesn't own that physical event, return w/o doing anything.
	 */

	eventPSPtr = FindSequence(interp, lookupTables, NULL, eventString, 0, 0, NULL);
	if (!eventPSPtr) {
	eventPSPtr = FindSequence(interp, &vetPtr->patternTable, NULL,
		eventString, 0, 0, &eventMask);
	if (eventPSPtr == NULL) {
	    const char *string = Tcl_GetString(Tcl_GetObjResult(interp));

	    return string[0] ? TCL_ERROR : TCL_OK;
	    return (string[0] != '\0') ? TCL_ERROR : TCL_OK;
	}
    }

    for (iPhys = PhysOwned_Size(owned); --iPhys >= 0; ) {
	PatSeq *psPtr = PhysOwned_Get(owned, iPhys);
    for (iPhys = poPtr->numOwned; --iPhys >= 0; ) {
	PatSeq *psPtr = poPtr->patSeqs[iPhys];

	assert(TEST_PSENTRY(psPtr));
	if ((eventPSPtr == NULL) || (psPtr == eventPSPtr)) {
	    int iVirt;
	    VirtualOwners *voPtr;

	    /*
	     * Remove association between this physical event and the given
	     * virtual event that it triggers.
	     */
	if (!eventPSPtr || psPtr == eventPSPtr) {
	    VirtOwners *owners = psPtr->ptr.owners;
	    int iVirt = VirtOwners_Find(owners, vhPtr);

	    assert(iVirt != -1); /* Otherwise we couldn't find owner, and this should not happen. */

	    /*
	     * Remove association between this physical event and the given
	     * virtual event that it triggers.
	     */

	    voPtr = psPtr->voPtr;
	    for (iVirt = 0; iVirt < voPtr->numOwners; iVirt++) {
		if (voPtr->owners[iVirt] == vhPtr) {
		    break;
		}
	    }
	    if (iVirt == voPtr->numOwners) {
		Tcl_Panic("DeleteVirtualEvent: couldn't find owner");
	    }
	    voPtr->numOwners--;
	    if (voPtr->numOwners == 0) {
		/*
		 * Removed last reference to this physical event, so remove it
		 * from physical->virtual map.
		 */

		PatSeq *prevPtr = Tcl_GetHashValue(psPtr->hPtr);
	    if (VirtOwners_Size(owners) > 1) {

		if (prevPtr == psPtr) {
		    if (psPtr->nextSeqPtr == NULL) {
			Tcl_DeleteHashEntry(psPtr->hPtr);
		    } else {
			Tcl_SetHashValue(psPtr->hPtr,
				psPtr->nextSeqPtr);
		    }
		} else {
		    for ( ; ; prevPtr = prevPtr->nextSeqPtr) {
			if (prevPtr == NULL) {
			    Tcl_Panic("DeleteVirtualEvent couldn't find on hash chain");
			}
			if (prevPtr->nextSeqPtr == psPtr) {
			    prevPtr->nextSeqPtr = psPtr->nextSeqPtr;
			    break;
			}
		    }
		}
		ckfree(psPtr->voPtr);
		ckfree(psPtr);
	    } else {
		/*
		 * This physical event still triggers some other virtual
		 * event(s). Consolidate the list of virtual owners for this
		 * physical event so it no longer triggers the given virtual
		 * event.
		 */
		VirtOwners_Set(owners, iVirt, VirtOwners_Back(owners));

		VirtOwners_PopBack(owners);
	    } else {
		/*
		 * Removed last reference to this physical event, so remove it
		 * from lookup table.
		 */
		DEBUG(psPtr->owned = 0;)
		voPtr->owners[iVirt] = voPtr->owners[voPtr->numOwners];
		RemovePatSeqFromLookup(&vetPtr->lookupTables, psPtr);
		DeletePatSeq(psPtr);
	    }

	    /*
	     * Now delete the virtual event's reference to the physical event.
	     */

	    lastElemPtr = PhysOwned_Back(owned);

	    if (PhysOwned_PopBack(owned) > 0 && eventPSPtr) {
	    poPtr->numOwned--;
	    if (eventPSPtr != NULL && poPtr->numOwned != 0) {
		/*
		 * Just deleting this one physical event. Consolidate list of
		 * owned physical events and return.
		 */
		if ((size_t) iPhys < PhysOwned_Size(owned)) {
		    PhysOwned_Set(owned, iPhys, lastElemPtr);
		}

		poPtr->patSeqs[iPhys] = poPtr->patSeqs[poPtr->numOwned];
		return TCL_OK;
	    }
	}
    }

    if (PhysOwned_IsEmpty(owned)) {
    if (poPtr->numOwned == 0) {
	/*
	 * All the physical events for this virtual event were deleted, either
	 * because there was only one associated physical event or because the
	 * caller was deleting the entire virtual event. Now the virtual event
	 * itself should be deleted.
	 */
	PhysOwned_Free(&owned);

	ckfree(poPtr);
	Tcl_DeleteHashEntry(vhPtr);
    }
    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------
3774
3775
3776
3777
3778
3779
3780
3781
3782


3783
3784
3785
3786
3787
3788
3789


3790
3791
3792
3793


3794
3795
3796
3797
3798
3799
3800




3801
3802
3803
3804
3805
3806
3807
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







-
-
+
+



-
-
-
-
+
+



-
+
+




-
-
-
+
+
+
+







static int
GetVirtualEvent(
    Tcl_Interp *interp,		/* Interpreter for reporting. */
    VirtualEventTable *vetPtr,	/* Table in which to look for event. */
    Tcl_Obj *virtName)		/* String describing virtual event. */
{
    Tcl_HashEntry *vhPtr;
    unsigned iPhys;
    const PhysOwned *owned;
    int iPhys;
    PhysicalsOwned *poPtr;
    Tk_Uid virtUid;
    Tcl_Obj *resultObj;

    assert(vetPtr);
    assert(virtName);

    if (!(virtUid = GetVirtualEventUid(interp, Tcl_GetString(virtName)))) {
    virtUid = GetVirtualEventUid(interp, Tcl_GetString(virtName));
    if (virtUid == NULL) {
	return TCL_ERROR;
    }

    if (!(vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid))) {
    vhPtr = Tcl_FindHashEntry(&vetPtr->nameTable, virtUid);
    if (vhPtr == NULL) {
	return TCL_OK;
    }

    resultObj = Tcl_NewObj();
    owned = (const PhysOwned *)Tcl_GetHashValue(vhPtr);
    for (iPhys = 0; iPhys < PhysOwned_Size(owned); ++iPhys) {
	Tcl_ListObjAppendElement(NULL, resultObj, GetPatternObj(PhysOwned_Get(owned, iPhys)));
    poPtr = Tcl_GetHashValue(vhPtr);
    for (iPhys = 0; iPhys < poPtr->numOwned; iPhys++) {
	Tcl_ListObjAppendElement(NULL, resultObj,
		GetPatternObj(poPtr->patSeqs[iPhys]));
    }
    Tcl_SetObjResult(interp, resultObj);

    return TCL_OK;
}

/*
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838

3839
3840


3841
3842
3843
3844
3845
3846
3847
2837
2838
2839
2840
2841
2842
2843


2844
2845

2846


2847
2848
2849
2850
2851
2852
2853
2854
2855







-
-


-
+
-
-
+
+







    Tcl_Interp *interp,		/* Interpreter returning result. */
    VirtualEventTable *vetPtr)	/* Table containing events. */
{
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    Tcl_Obj *resultObj;

    assert(vetPtr);

    resultObj = Tcl_NewObj();
    hPtr = Tcl_FirstHashEntry(&vetPtr->nameTable, &search);
    for ( ; hPtr; hPtr = Tcl_NextHashEntry(&search)) {
    for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	Tcl_Obj* msg = Tcl_ObjPrintf("<<%s>>", (char *) Tcl_GetHashKey(hPtr->tablePtr, hPtr));
	Tcl_ListObjAppendElement(NULL, resultObj, msg);
	Tcl_ListObjAppendElement(NULL, resultObj, Tcl_ObjPrintf(
		"<<%s>>", (char *) Tcl_GetHashKey(hPtr->tablePtr, hPtr)));
    }
    Tcl_SetObjResult(interp, resultObj);
}

/*
 *---------------------------------------------------------------------------
 *
3877
3878
3879
3880
3881
3882
3883
3884

3885
3886
3887

3888
3889
3890

3891

3892
3893
3894

3895
3896
3897

3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914

3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932

3933
3934
3935
3936

3937

3938
3939
3940
3941


3942
3943
3944
3945

3946
3947
3948
3949


3950
3951
3952
3953
3954



3955
3956
3957
3958
3959



3960
3961
3962
3963
3964
3965
3966
3967

3968
3969
3970

3971

3972
3973
3974
3975
3976
3977
3978
3979

3980
3981
3982
3983
3984
3985
3986




3987
3988

3989
3990

3991
3992
3993
3994
3995
3996
3997

3998
3999
4000
4001
4002


4003
4004
4005
4006
4007


4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031

4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051


4052
4053
4054
4055


4056
4057
4058

4059



4060
4061
4062

4063
4064
4065
4066
4067
4068

4069
4070
4071
4072

4073
4074
4075
4076
4077
4078

4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091

4092
4093
4094
4095
4096
4097
4098
4099
4100
4101

4102
4103
4104
4105
4106
4107
4108
4109
4110

4111
4112
4113

4114
4115
4116
4117
4118
4119
4120
4121


4122
4123

4124
4125
4126
4127


4128
4129
4130
4131
4132
4133
4134
4135
4136

4137
4138
4139
4140
4141
4142
4143
4144
4145
4146

4147
4148
4149
4150


4151
4152
4153
4154
4155
4156
4157
4158

4159
4160
4161
4162
4163
4164
4165

4166
4167
4168

4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179




4180
4181
4182
4183
4184
4185
4186




4187
4188
4189
4190



4191
4192
4193
4194
4195


4196
4197
4198
4199
4200
4201
4202
4203

4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219

4220
4221
4222
4223


4224
4225
4226
4227
4228
4229

4230
4231
4232
4233

4234
4235
4236

4237
4238
4239

4240
4241
4242
4243

4244
4245
4246

4247
4248
4249

4250
4251
4252
4253

4254
4255
4256

4257
4258
4259

4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270

4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285






4286
4287
4288
4289
4290
4291
4292
4293
4294
4295

4296
4297
4298
4299

4300
4301
4302
4303
4304
4305



4306
4307
4308
4309
4310

4311
4312
4313
4314

4315
4316
4317

4318
4319
4320

4321
4322
4323

4324
4325
4326
4327
4328

4329
4330
4331
4332


4333
4334

4335
4336

4337
4338
4339
4340
4341

4342
4343
4344
4345
4346
4347
4348
4349

4350
4351
4352
4353

4354
4355
4356
4357
4358
4359

4360
4361
4362
4363

4364
4365
4366

4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386

4387
4388
4389
4390

4391
4392
4393

4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413

4414
4415
4416

4417
4418
4419
4420
4421
4422






4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
















4441
4442
4443
4444














4445
4446
4447


4448
4449







4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463













4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478

4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518

4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529



4530
4531
4532
4533
4534
4535
4536
4537

4538
4539
4540
4541
4542






4543
4544
4545


4546
4547
4548
4549


4550
4551
4552



4553
4554


4555
4556
4557
4558
4559
4560

4561
4562

4563
4564
4565
4566
4567
4568

4569
4570
4571
4572
4573
4574


4575
4576
4577
4578

4579
4580
4581
4582
4583
4584


4585
4586
4587


4588
4589
4590


4591
4592



4593


4594
4595
4596
4597
4598
4599








4600

4601
4602
4603
4604
4605
4606
4607
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
3171

3172
3173
3174
3175
3176
3177
3178
3179
3180
3181


3182
3183
3184
3185
3186
3187
3188
3189
3190


3191
3192
3193
3194
3195
3196


3197
3198
3199
3200
3201
3202
3203

3204
3205
3206
3207
3208
3209
3210
3211
3212

3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228

3229
3230
3231
3232

3233
3234
3235
3236
3237
3238
3239

3240
3241
3242
3243

3244
3245
3246

3247
3248
3249

3250
3251
3252
3253

3254
3255
3256

3257
3258
3259

3260
3261
3262
3263

3264
3265
3266

3267
3268
3269

3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285












3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300

3301
3302
3303
3304

3305
3306
3307
3308
3309
3310

3311
3312
3313
3314
3315
3316
3317

3318
3319
3320
3321

3322
3323
3324

3325
3326
3327

3328
3329
3330

3331





3332
3333
3334


3335
3336
3337

3338
3339

3340
3341
3342

3343

3344
3345
3346
3347
3348
3349
3350
3351

3352
3353
3354
3355

3356
3357
3358
3359
3360
3361

3362
3363
3364
3365

3366
3367
3368

3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388

3389
3390
3391
3392

3393
3394
3395

3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415

3416
3417
3418
3419
3420
3421





3422
3423
3424
3425
3426
3427

3428
3429
3430
3431
3432
3433











3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450



3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465


3466
3467
3468

3469
3470
3471
3472
3473
3474
3475
3476













3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489








3490






3491












3492
3493
3494
















3495
3496
3497
3498
3499
3500
3501
3502

3503
3504
3505






3506


3507
3508
3509
3510
3511
3512
3513


3514

3515
3516
3517
3518


3519
3520
3521
3522
3523
3524
3525


3526
3527




3528
3529



3530
3531
3532


3533
3534
3535
3536
3537
3538
3539

3540
3541

3542
3543
3544
3545
3546
3547

3548
3549
3550
3551
3552


3553
3554




3555






3556
3557
3558


3559
3560



3561
3562


3563
3564
3565
3566
3567
3568






3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585







-
+


-
+
-

-
+
-
+


-
+
-

-
+

-
-
-
-
-
-









-
+












-
-



-
+




+
-
+



-
+
+




+



-
+
+


-
-
-
+
+
+



-
-
+
+
+







-
+



+
-
+








+



-
-
-
-
+
+
+
+

-
+

-
+






-
+




-
+
+




-
+
+





-


-
-
-
-
-
-









-
+


















-
-
+
+



-
+
+



+
-
+
+
+


-
+





-
+



-
+





-
+







-
-
-


-
+









-
+









+


-
+






-
-
+
+

-
+



-
+
+








-
+









-
+



-
+
+







-
+






-
+


-
+









-
-
+
+
+
+





-
-
+
+
+
+


-
-
+
+
+




-
+
+







-
+















-
+



-
+
+





-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+











+



-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+









-
+



-
+





-
+
+
+




-
+



-
+


-
+


-
+


-
+
-
-
-
-
-
+


-
-
+
+

-
+

-
+


-

-
+







-
+



-
+





-
+



-
+


-
+



















-
+



-
+


-
+



















-
+



+

-
-
-
-
-
+
+
+
+
+
+
-






-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
+


-
-
-
-
-
-

-
-
+
+
+




-
-

-
+



-
-
+
+
+
+
+
+

-
-
+
+
-
-
-
-
+
+
-
-
-
+
+
+
-
-
+
+





-
+

-
+





-
+




-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
+
+

-
-
+
+
-
-
-
+
+
-
-
+
+
+

+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+

+







 *---------------------------------------------------------------------------
 */

static int
HandleEventGenerate(
    Tcl_Interp *interp,		/* Interp for errors return and name lookup. */
    Tk_Window mainWin,		/* Main window associated with interp. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    union { XEvent general; XVirtualEvent virt; } event;
    union {XEvent general; XVirtualEvent virtual;} event;

    const char *p;
    const char *name;
    const char *name, *windowName;
    const char *windowName;
    int count, flags, synch, i, number, warp;
    Tcl_QueuePosition pos;
    TkPattern pat;
    Tk_Window tkwin;
    Tk_Window tkwin, tkwin2;
    Tk_Window tkwin2;
    TkWindow *mainPtr;
    unsigned eventMask;
    unsigned long eventMask;
    Tcl_Obj *userDataObj;
    int synch;
    int warp;
    unsigned count;
    unsigned flags;
    int number;
    Tcl_Size i;

    static const char *const fieldStrings[] = {
	"-when",	"-above",	"-borderwidth",	"-button",
	"-count",	"-data",	"-delta",	"-detail",
	"-focus",	"-height",
	"-keycode",	"-keysym",	"-mode",	"-override",
	"-place",	"-root",	"-rootx",	"-rooty",
	"-sendevent",	"-serial",	"-state",	"-subwindow",
	"-time",	"-warp",	"-width",	"-window",
	"-x",		"-y",		NULL
	"-x",		"-y",	NULL
    };
    enum field {
	EVENT_WHEN,	EVENT_ABOVE,	EVENT_BORDER,	EVENT_BUTTON,
	EVENT_COUNT,	EVENT_DATA,	EVENT_DELTA,	EVENT_DETAIL,
	EVENT_FOCUS,	EVENT_HEIGHT,
	EVENT_KEYCODE,	EVENT_KEYSYM,	EVENT_MODE,	EVENT_OVERRIDE,
	EVENT_PLACE,	EVENT_ROOT,	EVENT_ROOTX,	EVENT_ROOTY,
	EVENT_SEND,	EVENT_SERIAL,	EVENT_STATE,	EVENT_SUBWINDOW,
	EVENT_TIME,	EVENT_WARP,	EVENT_WIDTH,	EVENT_WINDOW,
	EVENT_X,	EVENT_Y
    };

    assert(mainWin);

    windowName = Tcl_GetString(objv[0]);
    if (!windowName[0]) {
	tkwin = mainWin;
    } else if (!NameToWindow(interp, mainWin, objv[0], &tkwin)) {
    } else if (NameToWindow(interp, mainWin, objv[0], &tkwin) != TCL_OK) {
	return TCL_ERROR;
    }

    mainPtr = (TkWindow *) mainWin;
    if ((tkwin == NULL)
    if (!tkwin || mainPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr) {
	    || (mainPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window id \"%s\" doesn't exist in this application",
		Tcl_GetString(objv[0])));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW", Tcl_GetString(objv[0]), NULL);
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW",
		Tcl_GetString(objv[0]), NULL);
	return TCL_ERROR;
    }

    name = Tcl_GetString(objv[1]);

    p = name;
    eventMask = 0;
    userDataObj = NULL;
    if ((count = ParseEventDescription(interp, &p, &pat, &eventMask)) == 0) {
    count = ParseEventDescription(interp, &p, &pat, &eventMask);
    if (count == 0) {
	return TCL_ERROR;
    }
    if (count != 1u) {
	Tcl_SetObjResult(interp,
		Tcl_NewStringObj("Double, Triple, or Quadruple modifier not allowed", TCL_INDEX_NONE));
    if (count != 1) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Double or Triple modifier not allowed", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_MODIFIER", NULL);
	return TCL_ERROR;
    }
    if (*p) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("only one event specification allowed", TCL_INDEX_NONE));
    if (*p != '\0') {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"only one event specification allowed", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "MULTIPLE", NULL);
	return TCL_ERROR;
    }

    memset(&event, 0, sizeof(event));
    event.general.xany.type = pat.eventType;
    event.general.xany.serial = NextRequest(Tk_Display(tkwin));
    event.general.xany.send_event = 0;
    event.general.xany.send_event = False;
    if (windowName[0]) {
	event.general.xany.window = Tk_WindowId(tkwin);
    } else {
	event.general.xany.window =
	event.general.xany.window = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
		RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
    }
    event.general.xany.display = Tk_Display(tkwin);

    flags = flagArray[event.general.xany.type];
    if (flags & DESTROY) {
	/*
	 * Event DestroyNotify should be generated by destroying the window.
	 */

	Tk_DestroyWindow(tkwin);
	return TCL_OK;
    }
    if (flags & HAS_XKEY_HEAD_AND_STATE) {
	event.general.xkey.state = pat.modMask;
	if (flags & KEY) {
	    TkpSetKeycodeAndState(tkwin, pat.info, &event.general);
    if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
	event.general.xkey.state = pat.needMods;
	if ((flags & KEY) && (event.general.xany.type != MouseWheelEvent)) {
	    TkpSetKeycodeAndState(tkwin, pat.detail.keySym, &event.general);
	} else if (flags & BUTTON) {
	    event.general.xbutton.button = pat.info;
	    event.general.xbutton.button = pat.detail.button;
	} else if (flags & VIRTUAL) {
	    event.virt.name = pat.name;
	    event.virtual.name = pat.detail.name;
	}
    }
    if (flags & (CREATE|UNMAP|MAP|REPARENT|CONFIG|GRAVITY|CIRC)) {
	event.general.xcreatewindow.window = event.general.xany.window;
    }

    if (flags & HAS_XKEY_HEAD) {
    if (flags & KEY_BUTTON_MOTION_CROSSING) {
	event.general.xkey.x_root = -1;
	event.general.xkey.y_root = -1;
    }

    if (event.general.xany.type == FocusIn || event.general.xany.type == FocusOut) {
    if (event.general.xany.type == FocusIn
	    || event.general.xany.type == FocusOut) {
	event.general.xany.send_event = GENERATED_FOCUS_EVENT_MAGIC;
    }

    /*
     * Process the remaining arguments to fill in additional fields of the event.
     * Process the remaining arguments to fill in additional fields of the
     * event.
     */

    synch = 1;
    warp = 0;
    pos = TCL_QUEUE_TAIL;

    for (i = 2; i < objc; i += 2) {
	Tcl_Obj *optionPtr, *valuePtr;
#if defined(_MSC_VER)
        /* Work around MSVC compiler optimization bug, see [d93c8175fd]. */
	volatile int badOpt = 0;
#else
	int badOpt = 0;
#endif
	int index;

	optionPtr = objv[i];
	valuePtr = objv[i + 1];

	if (Tcl_GetIndexFromObjStruct(interp, optionPtr, fieldStrings,
		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (IsOdd(objc)) {
	if (objc & 1) {
	    /*
	     * This test occurs after Tcl_GetIndexFromObj() so that "event
	     * generate <Button> -xyz" will return the error message that
	     * "-xyz" is a bad option, rather than that the value for "-xyz"
	     * is missing.
	     */

	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "value for \"%s\" missing", Tcl_GetString(optionPtr)));
	    Tcl_SetErrorCode(interp, "TK", "EVENT", "MISSING_VALUE", NULL);
	    return TCL_ERROR;
	}

	switch ((enum field) index) {
	case EVENT_WARP:
	    if (Tcl_GetBooleanFromObj(interp, valuePtr, &warp) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (!(flags & CAN_WARP)) {
		badOpt = 1;
	    if (!(flags & KEY_BUTTON_MOTION_VIRTUAL)) {
		goto badopt;
	    }
	    break;
	case EVENT_WHEN:
	    pos = (Tcl_QueuePosition) TkFindStateNumObj(interp, optionPtr, queuePosition, valuePtr);
	    pos = (Tcl_QueuePosition) TkFindStateNumObj(interp, optionPtr,
		    queuePosition, valuePtr);
	    if ((int) pos < -1) {
		return TCL_ERROR;
	    }
	    synch = 0;
	    synch = ((int) pos == -1);
	    if ((int) pos == -1) {
		synch = 1;
	    }
	    break;
	case EVENT_ABOVE:
	    if (!NameToWindow(interp, tkwin, valuePtr, &tkwin2)) {
	    if (NameToWindow(interp, tkwin, valuePtr, &tkwin2) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & CONFIG) {
		event.general.xconfigure.above = Tk_WindowId(tkwin2);
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_BORDER:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & (CREATE|CONFIG)) {
		event.general.xcreatewindow.border_width = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_BUTTON:
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & BUTTON) {
		if (number >= Button4) {
		    number += (Button8 - Button4);
		}
		event.general.xbutton.button = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_COUNT:
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & EXPOSE) {
		event.general.xexpose.count = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_DATA:
	    if (flags & VIRTUAL) {
		/*
		 * Do not increment reference count until after parsing
		 * completes and we know that the event generation is really
		 * going to happen.
		 */

		userDataObj = valuePtr;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_DELTA:
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & WHEEL) {
		event.general.xbutton.button = (unsigned)number; /* mis-use button field for this */
	    if ((flags & KEY) && (event.general.xkey.type == MouseWheelEvent)) {
		event.general.xkey.keycode = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_DETAIL:
	    number = TkFindStateNumObj(interp, optionPtr, notifyDetail, valuePtr);
	    number = TkFindStateNumObj(interp, optionPtr, notifyDetail,
		    valuePtr);
	    if (number < 0) {
		return TCL_ERROR;
	    }
	    if (flags & FOCUS) {
		event.general.xfocus.detail = number;
	    } else if (flags & CROSSING) {
		event.general.xcrossing.detail = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_FOCUS:
	    if (Tcl_GetBooleanFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & CROSSING) {
		event.general.xcrossing.focus = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_HEIGHT:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr,
		    &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & EXPOSE) {
		event.general.xexpose.height = number;
	    } else if (flags & CONFIG) {
		event.general.xconfigure.height = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_KEYCODE:
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & KEY) {
	    if ((flags & KEY) && (event.general.xkey.type != MouseWheelEvent)) {
		event.general.xkey.keycode = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_KEYSYM: {
	    KeySym keysym;
	    const char *value;

	    value = Tcl_GetString(valuePtr);
	    keysym = TkStringToKeysym(value);
	    if (keysym == NoSymbol) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf("unknown keysym \"%s\"", value));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "KEYSYM", value, NULL);
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"unknown keysym \"%s\"", value));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "KEYSYM", value,
			NULL);
		return TCL_ERROR;
	    }

	    TkpSetKeycodeAndState(tkwin, keysym, &event.general);
	    if (event.general.xkey.keycode == 0) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf("no keycode for keysym \"%s\"", value));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "KEYCODE", value, NULL);
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"no keycode for keysym \"%s\"", value));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "KEYCODE", value,
			NULL);
		return TCL_ERROR;
	    }
	    if (!(flags & KEY)) {
		badOpt = 1;
	    if (!(flags & KEY)
		    || (event.general.xkey.type == MouseWheelEvent)) {
		goto badopt;
	    }
	    break;
	}
	case EVENT_MODE:
	    if ((number = TkFindStateNumObj(interp, optionPtr, notifyMode, valuePtr)) < 0) {
	    number = TkFindStateNumObj(interp,optionPtr,notifyMode,valuePtr);
	    if (number < 0) {
		return TCL_ERROR;
	    }
	    if (flags & CROSSING) {
		event.general.xcrossing.mode = number;
	    } else if (flags & FOCUS) {
		event.general.xfocus.mode = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_OVERRIDE:
	    if (Tcl_GetBooleanFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & CREATE) {
		event.general.xcreatewindow.override_redirect = number;
	    } else if (flags & MAP) {
		event.general.xmap.override_redirect = number;
	    } else if (flags & REPARENT) {
		event.general.xreparent.override_redirect = number;
	    } else if (flags & CONFIG) {
		event.general.xconfigure.override_redirect = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_PLACE:
	    if ((number = TkFindStateNumObj(interp, optionPtr, circPlace, valuePtr)) < 0) {
	    number = TkFindStateNumObj(interp, optionPtr, circPlace, valuePtr);
	    if (number < 0) {
		return TCL_ERROR;
	    }
	    if (flags & CIRC) {
		event.general.xcirculate.place = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_ROOT:
	    if (!NameToWindow(interp, tkwin, valuePtr, &tkwin2)) {
	    if (NameToWindow(interp, tkwin, valuePtr, &tkwin2) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.root = Tk_WindowId(tkwin2);
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_ROOTX:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.x_root = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_ROOTY:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.y_root = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_SEND: {
	    const char *value;

	    value = Tcl_GetString(valuePtr);
	    if (isdigit(UCHAR(value[0]))) {
		/*
		 * Allow arbitrary integer values for the field; they are
		 * needed by a few of the tests in the Tk test suite.
		 */

		if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (number) {
		    /*
		     * send_event only expects 1 or 0. We cannot allow arbitrary non-zero
		     * values, otherwise the thing with GENERATED_FOCUS_EVENT_MAGIC will not
		     * work.
		     */
		    number = 1;
		}
	    } else if (Tcl_GetBooleanFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    event.general.xany.send_event |= number;
	    } else {
		if (Tcl_GetBooleanFromObj(interp,valuePtr,&number) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    event.general.xany.send_event = number;
	    break;
	}
	case EVENT_SERIAL:
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    event.general.xany.serial = number;
	    break;
	case EVENT_STATE:
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (flags & HAS_XKEY_HEAD_AND_STATE) {
		if (flags & KEY_BUTTON_MOTION_VIRTUAL) {
		    event.general.xkey.state = number;
		} else {
		    event.general.xcrossing.state = number;
		}
	    } else if (flags & VISIBILITY) {
		if ((number = TkFindStateNumObj(interp, optionPtr, visNotify, valuePtr)) < 0) {
		number = TkFindStateNumObj(interp, optionPtr, visNotify,
			valuePtr);
		if (number < 0) {
		    return TCL_ERROR;
		}
		event.general.xvisibility.state = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_SUBWINDOW:
	    if (!NameToWindow(interp, tkwin, valuePtr, &tkwin2)) {
	    if (NameToWindow(interp, tkwin, valuePtr, &tkwin2) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.subwindow = Tk_WindowId(tkwin2);
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_TIME: {
	case EVENT_TIME:
	    if (strcmp(Tcl_GetString(valuePtr), "current") == 0) {
		TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
		BindInfo *biPtr = mainPtr->mainPtr->bindInfo;
		number = dispPtr->lastEventTime + (CurrentTimeInMilliSecs() - biPtr->lastCurrentTime);
	    } else if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
	    if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
		event.general.xkey.time = number;
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.time = (Time) number;
	    } else if (flags & PROP) {
		event.general.xproperty.time = number;
		event.general.xproperty.time = (Time) number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	}
	case EVENT_WIDTH:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & EXPOSE) {
		event.general.xexpose.width = number;
	    } else if (flags & (CREATE|CONFIG)) {
		event.general.xcreatewindow.width = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_WINDOW:
	    if (!NameToWindow(interp, tkwin, valuePtr, &tkwin2)) {
	    if (NameToWindow(interp, tkwin, valuePtr, &tkwin2) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & (CREATE|UNMAP|MAP|REPARENT|CONFIG|GRAVITY|CIRC)) {
		event.general.xcreatewindow.window = Tk_WindowId(tkwin2);
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_X:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.x = number;

		/*
		 * Only modify rootx as well if it hasn't been changed.
		 */

		if (event.general.xkey.x_root == -1) {
		    int rootX, rootY;

		    Tk_GetRootCoords(tkwin, &rootX, &rootY);
		    event.general.xkey.x_root = rootX + number;
		}
	    } else if (flags & EXPOSE) {
		event.general.xexpose.x = number;
	    } else if (flags & (CREATE|CONFIG|GRAVITY)) {
		event.general.xcreatewindow.x = number;
	    } else if (flags & REPARENT) {
		event.general.xreparent.x = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	case EVENT_Y:
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr, &number) != TCL_OK) {
	    if (Tk_GetPixelsFromObj(interp,tkwin,valuePtr,&number) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (flags & HAS_XKEY_HEAD) {
	    if (flags & KEY_BUTTON_MOTION_CROSSING) {
		event.general.xkey.y = number;

		/*
		 * Only modify rooty as well if it hasn't been changed.
		 */

		if (event.general.xkey.y_root == -1) {
		    int rootX, rootY;

		    Tk_GetRootCoords(tkwin, &rootX, &rootY);
		    event.general.xkey.y_root = rootY + number;
		}
	    } else if (flags & EXPOSE) {
		event.general.xexpose.y = number;
	    } else if (flags & (CREATE|CONFIG|GRAVITY)) {
		event.general.xcreatewindow.y = number;
	    } else if (flags & REPARENT) {
		event.general.xreparent.y = number;
	    } else {
		badOpt = 1;
		goto badopt;
	    }
	    break;
	}
	continue;

    	if (badOpt) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "%s event doesn't accept \"%s\" option", name, Tcl_GetString(optionPtr)));
	    Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_OPTION", NULL);
	    return TCL_ERROR;
    badopt:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"%s event doesn't accept \"%s\" option",
		name, Tcl_GetString(optionPtr)));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_OPTION", NULL);
	return TCL_ERROR;
	}
    }

    /*
     * Don't generate events for windows that don't exist yet.
     */

    if (event.general.xany.window) {
	if (userDataObj) {
	    /*
	     * Must be virtual event to set that variable to non-NULL. Now we want
	     * to install the object into the event. Note that we must incr the
	     * refcount before firing it into the low-level event subsystem; the
	     * refcount will be decremented once the event has been processed.
	     */
	    event.virt.user_data = userDataObj;
	    Tcl_IncrRefCount(userDataObj);
	}
    if (!event.general.xany.window) {
	goto done;
    }

    if (userDataObj != NULL) {

	/*
	 * Must be virtual event to set that variable to non-NULL. Now we want
	 * to install the object into the event. Note that we must incr the
	 * refcount before firing it into the low-level event subsystem; the
	 * refcount will be decremented once the event has been processed.
	 */

	event.virtual.user_data = userDataObj;
	Tcl_IncrRefCount(userDataObj);
    }

	/*
	 * We only allow warping if the window is mapped.
	 */
    /*
     * Now we have constructed the event, inject it into the event handling
     * code.
     */

    if (synch != 0) {
	Tk_HandleEvent(&event.general);
    } else {
	Tk_QueueWindowEvent(&event.general, pos);
    }

    /*
     * We only allow warping if the window is mapped.
     */

	if (warp && Tk_IsMapped(tkwin)) {
	    TkDisplay *dispPtr = TkGetDisplay(event.general.xmotion.display);
    if ((warp != 0) && Tk_IsMapped(tkwin)) {
	TkDisplay *dispPtr = TkGetDisplay(event.general.xmotion.display);

	    Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display, event.general.xmotion.window);
Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display,
		event.general.xmotion.window);

	if (!(dispPtr->flags & TK_DISPLAY_IN_WARP)) {
	    Tcl_DoWhenIdle(DoWarp, dispPtr);
	    dispPtr->flags |= TK_DISPLAY_IN_WARP;
	}

	    if (warpWindow != dispPtr->warpWindow) {
		if (warpWindow) {
		    Tcl_Preserve(warpWindow);
		}
		if (dispPtr->warpWindow) {
		    Tcl_Release(dispPtr->warpWindow);
		}
		dispPtr->warpWindow = warpWindow;
	    }
	    dispPtr->warpMainwin = mainWin;
	    dispPtr->warpX = event.general.xmotion.x;
	    dispPtr->warpY = event.general.xmotion.y;

	if (warpWindow != dispPtr->warpWindow) {
	    if (warpWindow) {
		Tcl_Preserve(warpWindow);
	    }
	    if (dispPtr->warpWindow) {
		Tcl_Release(dispPtr->warpWindow);
	    }
	    dispPtr->warpWindow = warpWindow;
	}
	dispPtr->warpMainwin = mainWin;
	dispPtr->warpX = event.general.xmotion.x;
	dispPtr->warpY = event.general.xmotion.y;
    }
            /*
             * Warping with respect to a window will be done when Tk_handleEvent
             * below will run the event handlers and in particular TkPointerEvent.
             * This allows to make grabs and warping work together robustly, that
             * is without depending on a precise sequence of events.
             * Warping with respect to the whole screen (i.e. dispPtr->warpWindow
             * is NULL) is run directly here.
             */

            if (!dispPtr->warpWindow) {
                TkpWarpPointer(dispPtr);
                XForceScreenSaver(dispPtr->display, ScreenSaverReset);
            }
	}

  done:
	/*
	 * Now we have constructed the event, inject it into the event handling
	 * code.
	 */

	if (synch) {
	    Tk_HandleEvent(&event.general);
	} else {
	    Tk_QueueWindowEvent(&event.general, pos);
	}
    }

    Tcl_ResetResult(interp);
    return TCL_OK;
}
/*
 *---------------------------------------------------------------------------
 *
 * NameToWindow --
 *
 *	Helper function for lookup of a window given its path name. Our
 *	version is able to handle window id's.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

static int
NameToWindow(
    Tcl_Interp *interp,		/* Interp for error return and name lookup. */
    Tk_Window mainWin,		/* Main window of application. */
    Tcl_Obj *objPtr,		/* Contains name or id string of window. */
    Tk_Window *tkwinPtr)	/* Filled with token for window. */
{
    const char *name;
    const char *name = Tcl_GetString(objPtr);
    Tk_Window tkwin;

    assert(mainWin);
    assert(objPtr);
    assert(tkwinPtr);

    name = Tcl_GetString(objPtr);

    if (name[0] == '.') {
	if (!(tkwin = Tk_NameToWindow(interp, name, mainWin))) {
	    return 0;
	tkwin = Tk_NameToWindow(interp, name, mainWin);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
    } else {
	Window id;

	tkwin = NULL;

	/*
	 * Check for the winPtr being valid, even if it looks okay to
	 * Check for the winPtr being valid, even if it looks ok to
	 * TkpScanWindowId. [Bug #411307]
	 */

	if (TkpScanWindowId(NULL, name, &id) == TCL_OK) {
	    tkwin = Tk_IdToWindow(Tk_Display(mainWin), id);
	if (TkpScanWindowId(NULL, name, &id) != TCL_OK) {
	    goto badWindow;
	}
	tkwin = Tk_IdToWindow(Tk_Display(mainWin), id);
	if (tkwin == NULL) {
	    goto badWindow;
	}

	if (!tkwin) {
    }
    *tkwinPtr = tkwin;
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad window name/identifier \"%s\"", name));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW_ID", name, NULL);
	    return 0;
	}
    return TCL_OK;

    }

    assert(tkwin);
  badWindow:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad window name/identifier \"%s\"", name));
    *tkwinPtr = tkwin;
    return 1;
    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW_ID", name, NULL);
    return TCL_ERROR;
}

/*
 *-------------------------------------------------------------------------
 *
 * TkDoWarpWrtWin --
 * DoWarp --
 *
 *	Perform warping of mouse pointer with respect to a window.
 *	Perform Warping of X pointer. Executed as an idle handler only.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	Mouse pointer moves to a new location.
 *	X Pointer will move to a new location.
 *
 *-------------------------------------------------------------------------
 */

void
TkDoWarpWrtWin(
static void
DoWarp(
    TkDisplay *dispPtr)
{
    assert(dispPtr);

    ClientData clientData)
    /*
     * A NULL warpWindow means warping with respect to the whole screen.
     * We want to warp here only if we're warping with respect to a window.
     */

    if (dispPtr->warpWindow) {
{
    TkDisplay *dispPtr = clientData;

        /*
         * Warping with respect to a window can only be done if the window is
    /*
     * DoWarp was scheduled only if the window was mapped. It needs to be
         * mapped. This was checked in HandleEvent. The window needs to be
         * still mapped at the time the present code is executed. Also
         * one needs to guard against window destruction in the meantime,
     * still mapped at the time the present idle callback is executed. Also
     * one needs to guard against window destruction in the meantime.
         * which could have happened as a side effect of an event handler.
         */
     * Finally, the case warpWindow == NULL is special in that it means
     * the whole screen.
     */

    if ((dispPtr->warpWindow == NULL) ||
            (Tk_IsMapped(dispPtr->warpWindow)
        if (Tk_IsMapped(dispPtr->warpWindow) && Tk_WindowId(dispPtr->warpWindow) != None) {
            TkpWarpPointer(dispPtr);
            XForceScreenSaver(dispPtr->display, ScreenSaverReset);
        }
        Tcl_Release(dispPtr->warpWindow);
        dispPtr->warpWindow = NULL;
            && (Tk_WindowId(dispPtr->warpWindow) != None))) {
        TkpWarpPointer(dispPtr);
        XForceScreenSaver(dispPtr->display, ScreenSaverReset);
    }

    if (dispPtr->warpWindow) {
	Tcl_Release(dispPtr->warpWindow);
	dispPtr->warpWindow = None;
    }
    dispPtr->flags &= ~TK_DISPLAY_IN_WARP;
}

/*
 *-------------------------------------------------------------------------
 *
 * GetVirtualEventUid --
 *
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635

4636
4637
4638
4639
4640



4641
4642
4643
4644
4645
4646
4647
3602
3603
3604
3605
3606
3607
3608


3609
3610

3611





3612
3613
3614
3615
3616
3617
3618
3619
3620
3621







-
-


-
+
-
-
-
-
-
+
+
+







GetVirtualEventUid(
    Tcl_Interp *interp,
    char *virtString)
{
    Tk_Uid uid;
    size_t length;

    assert(virtString);

    length = strlen(virtString);

    if (length < 5
    if (length < 5 || virtString[0] != '<' || virtString[1] != '<' ||
	    || virtString[0] != '<'
	    || virtString[1] != '<'
	    || virtString[length - 2] != '>'
	    || virtString[length - 1] != '>') {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("virtual event \"%s\" is badly formed", virtString));
	    virtString[length - 2] != '>' || virtString[length - 1] != '>') {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"virtual event \"%s\" is badly formed", virtString));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "MALFORMED", NULL);
	return NULL;
    }
    virtString[length - 2] = '\0';
    uid = Tk_GetUid(virtString + 2);
    virtString[length - 2] = '>';

4671
4672
4673
4674
4675
4676
4677

4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688













4689
4690

4691
4692
4693
4694


4695
4696
4697
4698
4699



4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713





4714
4715
4716
4717
4718
4719
4720
4721









4722


4723
4724
4725




4726
4727
4728
4729
4730
4731

4732
4733
4734
4735




4736
4737
4738
4739
4740
4741
4742
4743
4744










4745
4746
4747
4748
4749
4750
4751
4752
4753




4754
4755
4756
4757


4758
4759
4760
4761
4762
4763
4764
4765





4766
4767
4768
4769
4770
4771


4772
4773
4774
4775





4776
4777

4778
4779
4780
4781
4782
4783





4784
4785
4786
4787


4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807

4808
4809
4810
4811
4812
4813
4814
4815

4816

4817
4818

4819
4820

4821
4822

4823
4824



4825
4826
4827
4828
4829
4830
4831
4832
3645
3646
3647
3648
3649
3650
3651
3652











3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666

3667




3668
3669
3670
3671
3672


3673
3674
3675



3676
3677





3678



3679
3680
3681
3682
3683
3684
3685






3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697



3698
3699
3700
3701

3702
3703
3704
3705

3706
3707



3708
3709
3710
3711
3712
3713
3714
3715
3716




3717
3718
3719
3720
3721
3722
3723
3724
3725
3726


3727
3728
3729




3730
3731
3732
3733
3734
3735
3736

3737
3738
3739

3740
3741




3742
3743
3744
3745
3746
3747
3748




3749
3750




3751
3752
3753
3754
3755


3756






3757
3758
3759
3760
3761




3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779

3780
3781

3782


3783




3784
3785

3786
3787

3788


3789
3790
3791
3792


3793
3794
3795

3796
3797
3798
3799
3800
3801
3802







+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
+
+



-
-
+
+
+
-
-
-


-
-
-
-
-

-
-
-
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

+
+
-
-
-
+
+
+
+
-




-
+

-
-
-
+
+
+
+





-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-



-
-
-
-
+
+
+
+



-
+
+

-


-
-
-
-
+
+
+
+
+


-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
















-


-
+
-
-

-
-
-
-

+
-
+

-
+
-
-
+


+
-
-
+
+
+
-







 *
 *----------------------------------------------------------------------
 */

static PatSeq *
FindSequence(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tcl_HashTable *patternTablePtr,
    LookupTables *lookupTables,	/* Tables used for lookup. */
    void *object,		/* For binding table, token for object with which binding is
    				 * associated. For virtual event table, NULL. */
    const char *eventString,	/* String description of pattern to match on. See user
    				 * documentation for details. */
    int create,			/* 0 means don't create the entry if it doesn't already exist.
    				 * 1 means create. */
    int allowVirtual,		/* 0 means that virtual events are not allowed in the sequence.
    				 * 1 otherwise. */
    unsigned *maskPtr)		/* *maskPtr is filled in with the event types on which this
    				 * pattern sequence depends. */
				/* Table to use for lookup. */
    ClientData object,		/* For binding table, token for object with
				 * which binding is associated. For virtual
				 * event table, NULL. */
    const char *eventString,	/* String description of pattern to match on.
				 * See user documentation for details. */
    int create,			/* 0 means don't create the entry if it
				 * doesn't already exist. Non-zero means
				 * create. */
    int allowVirtual,		/* 0 means that virtual events are not allowed
				 * in the sequence. Non-zero otherwise. */
    unsigned long *maskPtr)	/* *maskPtr is filled in with the event types
				 * on which this pattern sequence depends. */
{
    unsigned patsBufSize = 1;
    TkPattern pats[EVENT_BUFFER_SIZE];
    unsigned numPats;
    unsigned totalCount = 0;
    int virtualFound = 0;
    const char *p = eventString;
    int numPats, virtualFound;
    const char *p;
    TkPattern *patPtr;
    PatSeq *psPtr;
    Tcl_HashEntry *hPtr;
    int isNew;
    unsigned count;
    int flags, count, isNew;
    size_t sequenceSize;
    unsigned long eventMask;
    unsigned maxCount = 0;
    unsigned eventMask = 0;
    unsigned modMask = 0;
    PatternTableKey key;

    assert(lookupTables);
    assert(eventString);

    psPtr = (PatSeq *)ckalloc(PATSEQ_MEMSIZE(patsBufSize));

    /*
     *------------------------------------------------------------------
     * Step 1: parse the pattern string to produce an array of Patterns.
     *------------------------------------------------------------------
     *-------------------------------------------------------------
     * Step 1: parse the pattern string to produce an array of Patterns. The
     * array is generated backwards, so that the lowest-indexed pattern
     * corresponds to the last event that must occur.
     *-------------------------------------------------------------
     */

    for (patPtr = psPtr->pats, numPats = 0; *(p = SkipSpaces(p)); ++patPtr, ++numPats) {
	if (numPats >= patsBufSize) {
	    unsigned pos = patPtr - psPtr->pats;
	    patsBufSize += patsBufSize;
	    psPtr = (PatSeq *)ckrealloc(psPtr, PATSEQ_MEMSIZE(patsBufSize));
	    patPtr = psPtr->pats + pos;
    p = eventString;
    flags = 0;
    eventMask = 0;
    virtualFound = 0;

    patPtr = &pats[EVENT_BUFFER_SIZE-1];
    for (numPats = 0; numPats < EVENT_BUFFER_SIZE; numPats++, patPtr--) {
	while (isspace(UCHAR(*p))) {
	    p++;
	}
	if (*p == '\0') {
	    break;

	if ((count = ParseEventDescription(interp, &p, patPtr, &eventMask)) == 0) {
	    /* error encountered */
	}

	count = ParseEventDescription(interp, &p, patPtr, &eventMask);
	if (count == 0) {
	    ckfree(psPtr);
	    return NULL;
	}

	if (eventMask & VirtualEventMask) {
	    if (!allowVirtual) {
	    if (allowVirtual == 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"virtual event not allowed in definition of another virtual event", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "INNER", NULL);
		ckfree(psPtr);
			"virtual event not allowed in definition of another virtual event",
			-1));
		Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "INNER",
			NULL);
		return NULL;
	    }
	    virtualFound = 1;
	}

	if (count > 1u) {
	    maxCount = Max(count, maxCount);
	}

	/*
	 * Replicate events for DOUBLE, TRIPLE, QUADRUPLE.
	 */

	while ((count-- > 1) && (numPats < EVENT_BUFFER_SIZE-1)) {
	    flags |= PAT_NEARBY;
	    patPtr[-1] = patPtr[0];
	    patPtr--;
	    numPats++;
	}
	totalCount += count;
	modMask |= patPtr->modMask;
    }

    /*
     *------------------------------------------------------------------
     * Step 2: find the sequence in the binding table if it exists, and
     * add a new sequence to the table if it doesn't.
     *------------------------------------------------------------------
     *-------------------------------------------------------------
     * Step 2: find the sequence in the binding table if it exists, and add a
     * new sequence to the table if it doesn't.
     *-------------------------------------------------------------
     */

    if (numPats == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("no events specified in binding", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"no events specified in binding", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "NO_EVENTS", NULL);
	ckfree(psPtr);
	return NULL;
    }
    if (numPats > 1u && virtualFound) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("virtual events may not be composed", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "COMPOSITION", NULL);
	ckfree(psPtr);
    if ((numPats > 1) && (virtualFound != 0)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"virtual events may not be composed", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "COMPOSITION",
		NULL);
	return NULL;
    }
    if (patsBufSize > numPats) {
	psPtr = (PatSeq *)ckrealloc(psPtr, PATSEQ_MEMSIZE(numPats));
    }


    patPtr = &pats[EVENT_BUFFER_SIZE-numPats];
    patPtr = psPtr->pats;
    psPtr->object = (Tcl_Obj *)object;
    SetupPatternKey(&key, psPtr);
    hPtr = Tcl_CreateHashEntry(&lookupTables->patternTable, (char *) &key, &isNew);
    memset(&key, 0, sizeof(key));
    key.object = object;
    key.type = patPtr->eventType;
    key.detail = patPtr->detail;
    hPtr = Tcl_CreateHashEntry(patternTablePtr, (char *) &key, &isNew);
    if (!isNew) {
	unsigned sequenceSize = numPats*sizeof(TkPattern);
    sequenceSize = numPats*sizeof(TkPattern);
	PatSeq *psPtr2;

	for (psPtr2 = (PatSeq *)Tcl_GetHashValue(hPtr); psPtr2; psPtr2 = psPtr2->nextSeqPtr) {
	    assert(TEST_PSENTRY(psPtr2));
	    if (numPats == psPtr2->numPats && memcmp(patPtr, psPtr2->pats, sequenceSize) == 0) {
		ckfree(psPtr);
    if (!isNew) {
	for (psPtr = Tcl_GetHashValue(hPtr); psPtr != NULL;
		psPtr = psPtr->nextSeqPtr) {
	    if ((numPats == psPtr->numPats)
		    && ((flags & PAT_NEARBY) == (psPtr->flags & PAT_NEARBY))
		if (maskPtr) {
		    *maskPtr = eventMask;
		}
		return psPtr2;
		    && (memcmp(patPtr, psPtr->pats, sequenceSize) == 0)) {
		goto done;
	    }
	}
    }
    if (!create) {
	if (isNew) {
	    Tcl_DeleteHashEntry(hPtr);
	}

	/*
	 * No binding exists for the sequence, so return an empty error. This
	 * is a special error that the caller will check for in order to
	 * silently ignore this case. This is a hack that maintains backward
	 * compatibility for Tk_GetBinding but the various "bind" commands
	 * silently ignore missing bindings.
	 */

	ckfree(psPtr);
	return NULL;
    }

    psPtr = ckalloc(sizeof(PatSeq) + (numPats-1)*sizeof(TkPattern));
    DEBUG(countSeqItems += 1;)

    psPtr->numPats = numPats;
    psPtr->count = totalCount;
    psPtr->number = lookupTables->number++;
    psPtr->added = 0;
    psPtr->modMaskUsed = (modMask != 0);
    psPtr->script = NULL;
    psPtr->flags = flags;
    psPtr->nextSeqPtr = (PatSeq *)Tcl_GetHashValue(hPtr);
    psPtr->nextSeqPtr = Tcl_GetHashValue(hPtr);
    psPtr->hPtr = hPtr;
    psPtr->ptr.nextObj = NULL;
    psPtr->voPtr = NULL;
    assert(psPtr->ptr.owners == NULL);
    DEBUG(psPtr->owned = 0;)
    psPtr->nextObjPtr = NULL;
    Tcl_SetHashValue(hPtr, psPtr);

    memcpy(psPtr->pats, patPtr, sequenceSize);
    if (maskPtr) {
	*maskPtr = eventMask;

  done:
    *maskPtr = eventMask;
    }
    return psPtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * ParseEventDescription --
4843
4844
4845
4846
4847
4848
4849
4850
4851

4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876






4877
4878
4879
4880







4881

4882
4883
4884





4885
4886

4887

4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902




4903
4904
4905
4906







4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
























4930
4931
4932
4933
4934
4935






4936
4937

4938
4939
4940
4941
4942
4943


4944
4945

4946
4947
4948
4949







4950
4951
4952









4953
4954
4955
4956
4957
4958
4959
4960
4961
4962

4963
4964
4965


4966
4967
4968
4969



4970
4971
4972
4973
4974
4975




4976
4977
4978
4979
4980
4981
4982
4983







4984
4985
4986
4987
4988
4989
4990
4991
4992
4993










4994
4995
4996
4997
4998
4999





5000
5001
5002
5003
5004
5005
5006
5007
5008













5009
5010



5011
5012
5013

5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032






















5033
5034

5035
5036
5037
5038







5039
5040
5041
5042
5043
5044
5045
5046
5047




5048
5049
5050
5051
5052
5053
5054

5055
5056
5057
5058


5059
5060


5061
5062

5063
5064
5065
5066
5067
5068





5069
5070
5071


5072
5073
5074
5075
5076
5077
5078
5079

5080
5081
5082
5083
5084
5085







5086
5087

5088
5089
5090
5091
5092






5093
5094

5095
5096
5097
5098
5099







5100
5101
5102


5103


5104

5105
5106
5107
5108
5109
5110
5111
3813
3814
3815
3816
3817
3818
3819


3820



















3821
3822




3823
3824
3825
3826
3827
3828
3829



3830
3831
3832
3833
3834
3835
3836
3837
3838



3839
3840
3841
3842
3843
3844

3845

3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857




3858
3859
3860
3861




3862
3863
3864
3865
3866
3867
3868
3869

3870




















3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895





3896
3897
3898
3899
3900
3901
3902

3903



3904


3905
3906


3907




3908
3909
3910
3911
3912
3913
3914



3915
3916
3917
3918
3919
3920
3921
3922
3923










3924



3925
3926




3927
3928
3929






3930
3931
3932
3933
3934







3935
3936
3937
3938
3939
3940
3941
3942









3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953





3954
3955
3956
3957
3958









3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971


3972
3973
3974



3975



















3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997


3998




3999
4000
4001
4002
4003
4004
4005









4006
4007
4008
4009







4010




4011
4012


4013
4014


4015






4016
4017
4018
4019
4020



4021
4022








4023






4024
4025
4026
4027
4028
4029
4030


4031





4032
4033
4034
4035
4036
4037


4038





4039
4040
4041
4042
4043
4044
4045



4046
4047
4048
4049
4050

4051
4052
4053
4054
4055
4056
4057
4058







-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+

+
-
-
-
+
+
+
+
+

-
+
-
+











-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+

-
+
-
-
-

-
-
+
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+

+
+
-
+







 *	On exit, eventStringPtr points to rest of event string (after the
 *	closing '>', so that this function can be called repeatedly to parse
 *	all the events in the entire sequence.
 *
 *---------------------------------------------------------------------------
 */

/* helper function */
static unsigned
static int
FinalizeParseEventDescription(
    Tcl_Interp *interp,
    TkPattern *patPtr,
    unsigned count,
    Tcl_Obj* errorObj,
    const char* errCode)
{
    assert(patPtr);
    assert(!errorObj == (count > 0));

    if (errorObj) {
	Tcl_SetObjResult(interp, errorObj);
	Tcl_SetErrorCode(interp, "TK", "EVENT", errCode, NULL);
    }
    patPtr->count = count;
    return count;
}

static unsigned
ParseEventDescription(
    Tcl_Interp *interp,		/* For error messages. */
    const char **eventStringPtr,/* On input, holds a pointer to start of event string. On exit,
    				 * gets pointer to rest of string after parsed event. */
    TkPattern *patPtr,		/* Filled with the pattern parsed from the event string. */
    unsigned *eventMaskPtr)	/* Filled with event mask of matched event. */
    const char **eventStringPtr,/* On input, holds a pointer to start of event
				 * string. On exit, gets pointer to rest of
				 * string after parsed event. */
    TkPattern *patPtr,		/* Filled with the pattern parsed from the
				 * event string. */
    unsigned long *eventMaskPtr)/* Filled with event mask of matched event. */
{
    const char *p;
    unsigned eventMask = 0;
    unsigned count = 1;
    char *p;
    unsigned long eventMask;
    int count, eventFlags;
#define FIELD_SIZE 48
    char field[FIELD_SIZE];
    Tcl_HashEntry *hPtr;
    Tcl_DString copy;

    Tcl_DStringInit(&copy);
    assert(eventStringPtr);
    assert(patPtr);
    assert(eventMaskPtr);
    p = Tcl_DStringAppend(&copy, *eventStringPtr, -1);

    patPtr->eventType = -1;
    patPtr->needMods = 0;
    patPtr->detail.clientData = 0;

    p = *eventStringPtr;
    eventMask = 0;
    memset(patPtr, 0, sizeof(TkPattern)); /* Otherwise memcmp doesn't work. */
    count = 1;

    /*
     * Handle simple ASCII characters.
     */

    if (*p != '<') {
	char string[2];

	patPtr->eventType = KeyPress;
	eventMask = KeyPressMask;
	string[0] = *p;
	string[1] = '\0';
	patPtr->info = TkStringToKeysym(string);
	if (patPtr->info == NoSymbol) {
	    if (!isprint(UCHAR(*p))) {
	string[1] = 0;
	patPtr->detail.keySym = TkStringToKeysym(string);
	if (patPtr->detail.keySym == NoSymbol) {
	    if (isprint(UCHAR(*p))) {
		return FinalizeParseEventDescription(
			interp,
			patPtr, 0,
			Tcl_ObjPrintf("bad ASCII character 0x%x", UCHAR(*p)), "BAD_CHAR");
		patPtr->detail.keySym = *p;
	    } else {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad ASCII character 0x%x", UCHAR(*p)));
		Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_CHAR", NULL);
		count = 0;
		goto done;
	    }
	    patPtr->info = *p;
	}
	++p;
    } else {
	/*
	 * A fancier event description. This can be either a virtual event or a physical event.
	 *
	 * A virtual event description consists of:
	 *
	 * 1. double open angle brackets.
	 * 2. virtual event name.
	 * 3. double close angle brackets.
	 *
	 * A physical event description consists of:
	 *
	 * 1. open angle bracket.
	 * 2. any number of modifiers, each followed by spaces or dashes.
	 * 3. an optional event name.
	 * 4. an option button or keysym name. Either this or item 3 *must* be present; if both
	 *    are present then they are separated by spaces or dashes.
	 * 5. a close angle bracket.
	 */
	p++;
	goto end;
    }

    /*
     * A fancier event description. This can be either a virtual event or a
     * physical event.
     *
     * A virtual event description consists of:
     *
     * 1. double open angle brackets.
     * 2. virtual event name.
     * 3. double close angle brackets.
     *
     * A physical event description consists of:
     *
     * 1. open angle bracket.
     * 2. any number of modifiers, each followed by spaces or dashes.
     * 3. an optional event name.
     * 4. an option button or keysym name. Either this or item 3 *must* be
     *	  present; if both are present then they are separated by spaces or
     *	  dashes.
     * 5. a close angle bracket.
     */

	++p;
	if (*p == '<') {
	    /*
	     * This is a virtual event: soak up all the characters up to the next '>'.
	     */
    p++;
    if (*p == '<') {
	/*
	 * This is a virtual event: soak up all the characters up to the next
	 * '>'.
	 */

	    const char *field = p + 1;
	char *field = p + 1;
	    char buf[256];
	    char* bufPtr = buf;
	    unsigned size;

	    p = strchr(field, '>');
	    if (p == field) {
	p = strchr(field, '>');
	if (p == field) {
		return FinalizeParseEventDescription(
			interp,
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			patPtr, 0,
			Tcl_NewStringObj("virtual event \"<<>>\" is badly formed", TCL_INDEX_NONE), "MALFORMED");
	    }
	    if (!p || p[1] != '>') {
		    "virtual event \"<<>>\" is badly formed", -1));
	    Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "MALFORMED",
		    NULL);
	    count = 0;
	    goto done;
	}
	if ((p == NULL) || (p[1] != '>')) {
		return FinalizeParseEventDescription(
			interp,
			patPtr, 0,
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "missing \">\" in virtual binding", -1));
	    Tcl_SetErrorCode(interp, "TK", "EVENT", "VIRTUAL", "MALFORMED",
		    NULL);
	    count = 0;
	    goto done;
	}
	*p = '\0';
	patPtr->eventType = VirtualEvent;
			Tcl_NewStringObj("missing \">\" in virtual binding", TCL_INDEX_NONE), "MALFORMED");
	    }

	    size = p - field;
	    if (size >= sizeof(buf)) {
		bufPtr = (char *)ckalloc(size + 1);
	    }
	    strncpy(bufPtr, field, size);
	    bufPtr[size] = '\0';
	    eventMask = VirtualEventMask;
	eventMask = VirtualEventMask;
	    patPtr->eventType = VirtualEvent;
	    patPtr->name = Tk_GetUid(bufPtr);
	    if (bufPtr != buf) {
	patPtr->detail.name = Tk_GetUid(field);
	*p = '>';
		ckfree(bufPtr);
	    }
	    p += 2;
	} else {

	p += 2;
	goto end;
	    unsigned eventFlags;
	    char field[512];
	    Tcl_HashEntry *hPtr;

	    while (1) {
		ModInfo *modPtr;
    }

    while (1) {
	ModInfo *modPtr;

		p = GetField(p, field, sizeof(field));
		if (*p == '>') {
		    /*
		     * This solves the problem of, e.g., <Control-M> being
		     * misinterpreted as Control + Meta + missing keysym instead of
		     * Control + KeyPress + M.
		     */
	p = GetField(p, field, FIELD_SIZE);
	if (*p == '>') {
	    /*
	     * This solves the problem of, e.g., <Control-M> being
	     * misinterpreted as Control + Meta + missing keysym instead of
	     * Control + KeyPress + M.
	     */

		     break;
		}
		if (!(hPtr = Tcl_FindHashEntry(&modTable, field))) {
		    break;
		}
		modPtr = (ModInfo *)Tcl_GetHashValue(hPtr);
		patPtr->modMask |= modPtr->mask;
		if (modPtr->flags & MULT_CLICKS) {
		    unsigned i = modPtr->flags & MULT_CLICKS;
	     break;
	}
	hPtr = Tcl_FindHashEntry(&modTable, field);
	if (hPtr == NULL) {
	    break;
	}
	modPtr = Tcl_GetHashValue(hPtr);
	patPtr->needMods |= modPtr->mask;
	if (modPtr->flags & MULT_CLICKS) {
	    int i = modPtr->flags & MULT_CLICKS;

		    count = 2;
		    while (i >>= 1) {
			++count;
		    }
		}
	    count = 2;
	    while (i >>= 1) {
		count++;
	    }
	}
		p = SkipFieldDelims(p);
	    }

	    eventFlags = 0;
	    if ((hPtr = Tcl_FindHashEntry(&eventTable, field))) {
		const EventInfo *eiPtr = (const EventInfo *)Tcl_GetHashValue(hPtr);
		patPtr->eventType = eiPtr->type;
		eventFlags = flagArray[eiPtr->type];
		eventMask = eiPtr->eventMask;
	while ((*p == '-') || isspace(UCHAR(*p))) {
	    p++;
	}
    }

    eventFlags = 0;
    hPtr = Tcl_FindHashEntry(&eventTable, field);
    if (hPtr != NULL) {
	const EventInfo *eiPtr = Tcl_GetHashValue(hPtr);

	patPtr->eventType = eiPtr->type;
	eventFlags = flagArray[eiPtr->type];
	eventMask = eiPtr->eventMask;
		p = GetField(SkipFieldDelims(p), field, sizeof(field));
	    }
	while ((*p == '-') || isspace(UCHAR(*p))) {
	    p++;
	}
	    if (*field) {
		unsigned button = GetButtonNumber(field);

	p = GetField(p, field, FIELD_SIZE);
		if ((eventFlags & BUTTON)
			|| (button && eventFlags == 0)
			|| (SUPPORT_ADDITIONAL_MOTION_SYNTAX && (eventFlags & MOTION) && button == 0)) {
		    /* This must be a button (or bad motion) event. */
		    if (button == 0) {
			return FinalizeParseEventDescription(
				interp,
				patPtr, 0,
				Tcl_ObjPrintf("bad button number \"%s\"", field), "BUTTON");
		    }
		    patPtr->info = button;
		    if (!(eventFlags & BUTTON)) {
			patPtr->eventType = ButtonPress;
			eventMask = ButtonPressMask;
		    }
		} else if ((eventFlags & KEY) || eventFlags == 0) {
		    /* This must be a key event */
		    patPtr->info = TkStringToKeysym(field);
		    if (patPtr->info == NoSymbol) {
    }
    if (*field != '\0') {
	if ((*field >= '1') && (*field <= '9') && (field[1] == '\0')) {
	    if (eventFlags == 0) {
		patPtr->eventType = ButtonPress;
		eventMask = ButtonPressMask;
	    } else if (eventFlags & KEY) {
		goto getKeysym;
	    } else if (!(eventFlags & BUTTON)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"specified button \"%s\" for non-button event",
			field));
		Tcl_SetErrorCode(interp, "TK", "EVENT", "NON_BUTTON", NULL);
		count = 0;
		goto done;
	    }
	    patPtr->detail.button = (*field - '0');
	} else {

	getKeysym:
	    patPtr->detail.keySym = TkStringToKeysym(field);
	    if (patPtr->detail.keySym == NoSymbol) {
			return FinalizeParseEventDescription(
				interp,
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
				patPtr, 0,
				Tcl_ObjPrintf("bad event type or keysym \"%s\"", field), "KEYSYM");
		    }
		    if (!(eventFlags & KEY)) {
			"bad event type or keysym \"%s\"", field));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "KEYSYM", field,
			NULL);
		count = 0;
		goto done;
	    }
	    if (eventFlags == 0) {
			patPtr->eventType = KeyPress;
			eventMask = KeyPressMask;
		    }
		} else if (button) {
		    if (!SUPPORT_ADDITIONAL_MOTION_SYNTAX || patPtr->eventType != MotionNotify) {
			return FinalizeParseEventDescription(
				interp,
				patPtr, 0,
				Tcl_ObjPrintf("specified button \"%s\" for non-button event", field),
		patPtr->eventType = KeyPress;
		eventMask = KeyPressMask;
	    } else if (!(eventFlags & KEY)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
				"NON_BUTTON");
		    }
#if SUPPORT_ADDITIONAL_MOTION_SYNTAX
		    patPtr->modMask |= Tk_GetButtonMask(button);
		    p = SkipFieldDelims(p);
		    while (*p && *p != '>') {
			p = SkipFieldDelims(GetField(p, field, sizeof(field)));
			"specified keysym \"%s\" for non-key event", field));
			if ((button = GetButtonNumber(field)) == 0) {
			    return FinalizeParseEventDescription(
				    interp,
				    patPtr, 0,
		Tcl_SetErrorCode(interp, "TK", "EVENT", "NON_KEY", NULL);
		count = 0;
				    Tcl_ObjPrintf("bad button number \"%s\"", field), "BUTTON");
			}
		goto done;
	    }
			patPtr->modMask |= Tk_GetButtonMask(button);
		    }
	}
		    patPtr->info = ButtonNumberFromState(patPtr->modMask);
#endif
		} else {
		    return FinalizeParseEventDescription(
			    interp,
			    patPtr, 0,
    } else if (eventFlags == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"no event type or button # or keysym", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "UNMODIFIABLE", NULL);
	count = 0;
			    Tcl_ObjPrintf("specified keysym \"%s\" for non-key event", field),
			    "NON_KEY");
		}
	goto done;
    }
	    } else if (eventFlags == 0) {
		return FinalizeParseEventDescription(
			interp,
			patPtr, 0,
			Tcl_NewStringObj("no event type or button # or keysym", TCL_INDEX_NONE), "UNMODIFIABLE");
	    } else if (patPtr->eventType == MotionNotify) {
		patPtr->info = ButtonNumberFromState(patPtr->modMask);
	    }

	    p = SkipFieldDelims(p);

	    if (*p != '>') {
		while (*p) {
		    ++p;
		    if (*p == '>') {
    while ((*p == '-') || isspace(UCHAR(*p))) {
	p++;
    }
    if (*p != '>') {
	while (*p != '\0') {
	    p++;
	    if (*p == '>') {
			return FinalizeParseEventDescription(
				interp,
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
				patPtr, 0,
				Tcl_NewStringObj("extra characters after detail in binding", TCL_INDEX_NONE),
				"PAST_DETAIL");
		    }
		}
			"extra characters after detail in binding", -1));
		Tcl_SetErrorCode(interp, "TK", "EVENT", "PAST_DETAIL", NULL);
		count = 0;
		goto done;
	    }
	}
		return FinalizeParseEventDescription(
			interp,
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
			patPtr, 0,
			Tcl_NewStringObj("missing \">\" in binding", TCL_INDEX_NONE), "MALFORMED");
	    }
	    ++p;
	}
		"missing \">\" in binding", -1));
	Tcl_SetErrorCode(interp, "TK", "EVENT", "MALFORMED", NULL);
	count = 0;
	goto done;
    }
    p++;

    }

    *eventStringPtr = p;
  end:
    *eventStringPtr += (p - Tcl_DStringValue(&copy));
    *eventMaskPtr |= eventMask;
  done:
    Tcl_DStringFree(&copy);
    return FinalizeParseEventDescription(interp, patPtr, count, NULL, NULL);
    return count;
}

/*
 *----------------------------------------------------------------------
 *
 * GetField --
 *
5121
5122
5123
5124
5125
5126
5127
5128

5129
5130
5131
5132



5133
5134
5135
5136




5137
5138


5139
5140
5141
5142
5143
5144
5145
4068
4069
4070
4071
4072
4073
4074

4075
4076



4077
4078
4079
4080



4081
4082
4083
4084


4085
4086
4087
4088
4089
4090
4091
4092
4093







-
+

-
-
-
+
+
+

-
-
-
+
+
+
+
-
-
+
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static const char *
static char *
GetField(
    const char *p,	/* Pointer to part of pattern. */
    char *copy,		/* Place to copy field. */
    unsigned size)	/* Maximum number of characters to copy. */
    char *p,			/* Pointer to part of pattern. */
    char *copy,			/* Place to copy field. */
    int size)			/* Maximum number of characters to copy. */
{
    assert(p);
    assert(copy);

    while ((*p != '\0') && !isspace(UCHAR(*p)) && (*p != '>')
	    && (*p != '-') && (size > 1)) {
	*copy = *p;
	p++;
    for ( ; *p && !isspace(UCHAR(*p)) && *p != '>' && *p != '-' && size > 1u; --size) {
	*copy++ = *p++;
	copy++;
	size--;
    }
    *copy = '\0';
    return p;
}

/*
 *---------------------------------------------------------------------------
5157
5158
5159
5160
5161
5162
5163
5164

5165




5166
5167
5168
5169




5170
5171

5172
5173

5174
5175
5176

5177
5178
5179
5180
5181
5182
5183
5184









5185







5186

5187
5188

5189
5190
5191


5192
5193
5194
5195
5196
5197





5198
5199

5200



5201
5202
5203












5204
5205
5206




5207
5208
5209
5210
5211

5212
5213
5214
5215
5216
5217
5218
5219







5220

5221
5222
5223
5224
5225
5226











5227
5228
5229
5230




5231
5232
5233


5234
5235

5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246

5247
5248

5249
5250

5251
5252

5253
5254
5255

5256
5257
5258
5259
5260
5261
5262
5263
4105
4106
4107
4108
4109
4110
4111

4112
4113
4114
4115
4116
4117
4118

4119

4120
4121
4122
4123
4124

4125


4126
4127
4128
4129
4130








4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147

4148


4149



4150
4151
4152





4153
4154
4155
4156
4157
4158

4159
4160
4161
4162
4163



4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175



4176
4177
4178
4179





4180

4181






4182
4183
4184
4185
4186
4187
4188
4189
4190






4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201




4202
4203
4204
4205



4206
4207


4208











4209


4210


4211


4212



4213

4214
4215
4216
4217
4218
4219
4220







-
+

+
+
+
+

-

-
+
+
+
+

-
+
-
-
+



+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
-
+
-
-
+
-
-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
+

+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
-
-
+
-

-
-
-
-
-
-
+
+
+
+
+
+
+

+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
+
-







 *	released; it starts with a refCount of zero.
 *
 *---------------------------------------------------------------------------
 */

static Tcl_Obj *
GetPatternObj(
    const PatSeq *psPtr)
    PatSeq *psPtr)
{
    TkPattern *patPtr;
    int patsLeft, needMods;
    const ModInfo *modPtr;
    const EventInfo *eiPtr;
    Tcl_Obj *patternObj = Tcl_NewObj();
    unsigned i;

    assert(psPtr);
    /*
     * The order of the patterns in the sequence is backwards from the order
     * in which they must be output.
     */

    for (i = 0; i < psPtr->numPats; ++i) {
    for (patsLeft = psPtr->numPats, patPtr = &psPtr->pats[psPtr->numPats - 1];
	const TkPattern *patPtr = psPtr->pats + i;

	    patsLeft > 0; patsLeft--, patPtr--) {
	/*
	 * Check for simple case of an ASCII character.
	 */

	if (patPtr->eventType == KeyPress
		&& patPtr->count == 1
		&& patPtr->modMask == 0
		&& patPtr->info < 128
		&& isprint(UCHAR(patPtr->info))
		&& patPtr->info != '<'
		&& patPtr->info != ' ') {
	    char c = (char) patPtr->info;
	if ((patPtr->eventType == KeyPress)
		&& !(psPtr->flags & PAT_NEARBY)
		&& (patPtr->needMods == 0)
		&& (patPtr->detail.keySym < 128)
		&& isprint(UCHAR(patPtr->detail.keySym))
		&& (patPtr->detail.keySym != '<')
		&& (patPtr->detail.keySym != ' ')) {
	    char c = (char) patPtr->detail.keySym;

	    Tcl_AppendToObj(patternObj, &c, 1);
	    continue;
	}

	/*
	 * Check for virtual event.
	 */

	} else if (patPtr->eventType == VirtualEvent) {
	if (patPtr->eventType == VirtualEvent) {
	    assert(patPtr->name);
	    Tcl_AppendPrintfToObj(patternObj, "<<%s>>", patPtr->name);
	    Tcl_AppendPrintfToObj(patternObj, "<<%s>>", patPtr->detail.name);
	} else {
	    unsigned modMask;
	    const ModInfo *modPtr;
	    continue;
	}

	    /*
	     * It's a more general event specification. First check for "Double",
	     * "Triple", "Quadruple", then modifiers, then event type, then keysym
	     * or button detail.
	     */
	/*
	 * It's a more general event specification. First check for "Double",
	 * "Triple", "Quadruple", then modifiers, then event type, then keysym
	 * or button detail.
	 */

	    Tcl_AppendToObj(patternObj, "<", 1);
	Tcl_AppendToObj(patternObj, "<", 1);

	if ((psPtr->flags & PAT_NEARBY) && (patsLeft > 1)
		&& (memcmp(patPtr, patPtr-1, sizeof(TkPattern)) == 0)) {
	    patsLeft--;
	    switch (patPtr->count) {
	    case 2: Tcl_AppendToObj(patternObj, "Double-", 7); break;
	    case 3: Tcl_AppendToObj(patternObj, "Triple-", 7); break;
	    patPtr--;
	    if ((patsLeft > 1) &&
		    (memcmp(patPtr, patPtr-1, sizeof(TkPattern)) == 0)) {
		patsLeft--;
		patPtr--;
		if ((patsLeft > 1) &&
			(memcmp(patPtr, patPtr-1, sizeof(TkPattern)) == 0)) {
		    patsLeft--;
		    patPtr--;
		    Tcl_AppendToObj(patternObj, "Quadruple-", 10);
		} else {
		    Tcl_AppendToObj(patternObj, "Triple-", 7);
	    case 4: Tcl_AppendToObj(patternObj, "Quadruple-", 10); break;
	    }

		}
	    } else {
		Tcl_AppendToObj(patternObj, "Double-", 7);
	    }
	    modMask = patPtr->modMask;
#if PRINT_SHORT_MOTION_SYNTAX
	    if (patPtr->eventType == MotionNotify) {
		modMask &= ~(ModMask)ALL_BUTTONS;
	    }
	}
#endif

	    for (modPtr = modArray; modMask; ++modPtr) {
		if (modPtr->mask & modMask) {
		    modMask &= ~modPtr->mask;
		    Tcl_AppendPrintfToObj(patternObj, "%s-", modPtr->name);
		}
	    }
	for (needMods = patPtr->needMods, modPtr = modArray;
		needMods != 0; modPtr++) {
	    if (modPtr->mask & needMods) {
		needMods &= ~modPtr->mask;
		Tcl_AppendPrintfToObj(patternObj, "%s-", modPtr->name);
	    }
	}

	for (eiPtr = eventArray; eiPtr->name != NULL; eiPtr++) {
	    assert(patPtr->eventType < TK_LASTEVENT);
	    assert(((size_t) eventArrayIndex[patPtr->eventType]) < SIZE_OF_ARRAY(eventArray));
	    Tcl_AppendToObj(patternObj, eventArray[eventArrayIndex[patPtr->eventType]].name, TCL_INDEX_NONE);

	    if (patPtr->info) {
		switch (patPtr->eventType) {
	    if (eiPtr->type == patPtr->eventType) {
		Tcl_AppendToObj(patternObj, eiPtr->name, -1);
		if (patPtr->detail.clientData != 0) {
		    Tcl_AppendToObj(patternObj, "-", 1);
		}
		break;
	    }
	}

	if (patPtr->detail.clientData != 0) {
	    if ((patPtr->eventType == KeyPress)
		case KeyPress:
		case KeyRelease: {
		    const char *string = TkKeysymToString(patPtr->info);
		    if (string) {
		    || (patPtr->eventType == KeyRelease)) {
		const char *string = TkKeysymToString(patPtr->detail.keySym);

		if (string != NULL) {
			Tcl_AppendToObj(patternObj, "-", 1);
			Tcl_AppendToObj(patternObj, string, TCL_INDEX_NONE);
		    }
		    Tcl_AppendToObj(patternObj, string, -1);
		}
		    break;
		}
	    } else {
		case ButtonPress:
		case ButtonRelease:
		    assert(patPtr->info <= 13);
		    Tcl_AppendPrintfToObj(patternObj, "-%u", (unsigned) ((patPtr->info > 7) ? (patPtr->info - 4) : patPtr->info));
		    break;
#if PRINT_SHORT_MOTION_SYNTAX
		case MotionNotify: {
		    unsigned mask = patPtr->modMask;
		    while (mask & ALL_BUTTONS) {
			unsigned button = ButtonNumberFromState(mask);
			Tcl_AppendPrintfToObj(patternObj, "-%u", (button > 7) ? (button - 4) : button);
		Tcl_AppendPrintfToObj(patternObj, "%d", patPtr->detail.button);
			mask &= ~Tk_GetButtonMask(button);
		    }
	    }
		    break;
		}
	}
#endif
		}

	    }

	    Tcl_AppendToObj(patternObj, ">", 1);
	Tcl_AppendToObj(patternObj, ">", 1);
	}
    }

    return patternObj;
}

/*
 *----------------------------------------------------------------------
5277
5278
5279
5280
5281
5282
5283
5284

5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321

5322
5323
5324
5325


5326
5327

5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
4234
4235
4236
4237
4238
4239
4240

4241


4242


































4243
4244
4245


4246
4247
4248

4249
4250
4251
4252
4253

4254
4255
4256
4257
4258
4259
4260







-
+
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
-
+
+

-
+




-







 */

KeySym
TkStringToKeysym(
    const char *name)		/* Name of a keysym. */
{
#ifdef REDO_KEYSYM_LOOKUP
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&keySymTable, name);
#endif /* REDO_KEYSYM_LOOKUP */
    int keysym;

    size_t len = Tcl_UtfToUniChar(name, &keysym);
    if (name[len] == '\0') {
        if (!Tcl_UniCharIsPrint(keysym)) {
    	/* This form not supported */
        } else if ((unsigned)(keysym - 0x21) <= 0x5D) {
		return (KeySym)keysym;
	    } else if ((unsigned)(keysym - 0xA1) <= 0x5E) {
		return (KeySym)keysym;
	    } else if (keysym == 0x20AC) {
		return 0x20AC;
	    } else {
		return (KeySym)keysym + 0x1000000;
	    }
    }
#ifdef REDO_KEYSYM_LOOKUP
    if ((name[0] == 'U') && ((unsigned)(name[1] - '0') <= 9)) {
	char *p = (char *)name + 1;
	keysym = strtol(p, &p, 16);
	if ((p >= name + 5) && (p <= name + 9) && !*p && (keysym >= 0x20)
		&& ((unsigned)(keysym - 0x7F) > 0x20)) {
	    if ((unsigned)(keysym - 0x21) <= 0x5D) {
		return keysym;
	    } else if ((unsigned)(keysym - 0xA1) <= 0x5E) {
		return keysym;
	    } else if (keysym == 0x20AC) {
		return keysym;
	    }
	    return keysym + 0x1000000;
	}
    }
#endif
#ifdef REDO_KEYSYM_LOOKUP
    hPtr = Tcl_FindHashEntry(&keySymTable, name);
    if (hPtr) {
    if (hPtr != NULL) {
	return (KeySym) Tcl_GetHashValue(hPtr);
    }
    if (((unsigned)(name[0]-1) < 0x7F) && !name[1]) {
	keysym = (unsigned char) name[0];
    if (strlen(name) == 1) {
	KeySym keysym = (KeySym) (unsigned char) name[0];

	if (TkKeysymToString(keysym)) {
	if (TkKeysymToString(keysym) != NULL) {
	    return keysym;
	}
    }
#endif /* REDO_KEYSYM_LOOKUP */
    assert(name);
    return XStringToKeysym(name);
}

/*
 *----------------------------------------------------------------------
 *
 * TkKeysymToString --
5351
5352
5353
5354
5355
5356
5357
5358

5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385


5386
5387
5388
5389
5390
5391
5392
4272
4273
4274
4275
4276
4277
4278

4279

4280

























4281
4282
4283
4284
4285
4286
4287
4288
4289







-
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+







 */

const char *
TkKeysymToString(
    KeySym keysym)
{
#ifdef REDO_KEYSYM_LOOKUP
    Tcl_HashEntry *hPtr;
    Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&nameTable, (char *)keysym);
#endif

    if ((unsigned)(keysym - 0x21) <= 0x5D) {
	keysym += 0x1000000;
    } else if ((unsigned)(keysym - 0xA1) <= 0x5E) {
	keysym += 0x1000000;
    } else if (keysym == 0x20AC) {
	keysym += 0x1000000;
    }
    if ((keysym >= 0x1000020) && (keysym <= 0x110FFFF)
	    && ((unsigned)(keysym - 0x100007F) > 0x20)) {
	char buf[10];
	if (Tcl_UniCharIsPrint(keysym-0x1000000)) {
	    buf[Tcl_UniCharToUtf(keysym - 0x1000000, buf)] = '\0';
	} else if (keysym >= 0x1010000) {
	    snprintf(buf, sizeof(buf), "U%08X", (int)(keysym - 0x1000000));
	} else {
	    snprintf(buf, sizeof(buf), "U%04X", (int)(keysym - 0x1000000));
	}
	return Tk_GetUid(buf);
    }

#ifdef REDO_KEYSYM_LOOKUP
    hPtr = Tcl_FindHashEntry(&nameTable, INT2PTR(keysym));

    if (hPtr) {
	return (const char *)Tcl_GetHashValue(hPtr);
    if (hPtr != NULL) {
	return Tcl_GetHashValue(hPtr);
    }
#endif /* REDO_KEYSYM_LOOKUP */

    return XKeysymToString(keysym);
}

/*
5408
5409
5410
5411
5412
5413
5414
5415
5416


5417
5418

5419
5420
5421
5422
5423
5424

5425
5426


5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440


5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456

5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472

5473
5474
5475
5476
5477
5478
5479
5480
5481
5482

5483
5484
5485
5486

5487
5488
5489


5490
5491
5492
5493
5494
5495
5496

5497
5498
5499
4305
4306
4307
4308
4309
4310
4311


4312
4313
4314

4315
4316
4317
4318
4319
4320

4321
4322

4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334

4335


4336
4337
4338















4339
















4340










4341




4342



4343
4344


4345
4346
4347
4348

4349
4350

4351







-
-
+
+

-
+





-
+

-
+
+










-

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-




-
+

-

 *----------------------------------------------------------------------
 */

XEvent *
TkpGetBindingXEvent(
    Tcl_Interp *interp)		/* Interpreter. */
{
    TkWindow *winPtr = (TkWindow *) Tk_MainWindow(interp);
    BindingTable *bindPtr = winPtr->mainPtr->bindingTable;
   TkWindow *winPtr = (TkWindow *) Tk_MainWindow(interp);
   BindingTable *bindPtr = winPtr->mainPtr->bindingTable;

    return &bindPtr->curEvent->xev;
   return &(bindPtr->eventRing[bindPtr->curEvent]);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDumpPS --
 * TkpCancelWarp --
 *
 *	Dump given pattern sequence to stdout.
 *	This function cancels an outstanding pointer warp and
 *	is called during tear down of the display.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#if SUPPORT_DEBUGGING
void
TkpDumpPS(
    const PatSeq *psPtr)
TkpCancelWarp(
    TkDisplay *dispPtr)
{
    if (!psPtr) {
	fprintf(stdout, "<null>\n");
    } else {
	Tcl_Obj* result = GetPatternObj(psPtr);
	Tcl_IncrRefCount(result);
	fprintf(stdout, "%s", Tcl_GetString(result));
	if (psPtr->object) {
	    fprintf(stdout, " (%s)", (char *) psPtr->object);
	}
	fprintf(stdout, "\n");
	Tcl_DecrRefCount(result);
    }
}
#endif

    if (dispPtr->flags & TK_DISPLAY_IN_WARP) {
/*
 *----------------------------------------------------------------------
 *
 * TkpDumpPSList --
 *
 *	Dump given pattern sequence list to stdout.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	Tcl_CancelIdleCall(DoWarp, dispPtr);
#if SUPPORT_DEBUGGING
void
TkpDumpPSList(
    const PSList *psList)
{
    if (!psList) {
	fprintf(stdout, "<null>\n");
    } else {
	const PSEntry *psEntry;

	dispPtr->flags &= ~TK_DISPLAY_IN_WARP;
	fprintf(stdout, "Dump PSList ========================================\n");
	TK_DLIST_FOREACH(psEntry, psList) {
	    TkpDumpPS(psEntry->psPtr);
	}
    }
	fprintf(stdout, "====================================================\n");
    }
}
}

#endif

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 105
 * fill-column: 78
 * End:
 * vi:set ts=8 sw=4:
 */

Changes to generic/tkBitmap.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23







-
-
+
+







-
-
-
-







/*
 * tkBitmap.c --
 *
 *	This file maintains a database of read-only bitmaps for the Tk
 *	toolkit. This allows bitmaps to be shared between widgets and also
 *	avoids interactions with the X server.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The includes below are for pre-defined bitmaps.
 *
 * Platform-specific issue: Windows complains when the bitmaps are included,
 * because an array of characters is being initialized with integers as
 * elements. For lint purposes, the following pragmas temporarily turn off
 * that warning message.
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98







-
+







 */

typedef struct {
    const char *source;		/* Bitmap bits. */
    int width, height;		/* Dimensions of bitmap. */
} DataKey;

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;		/* 0 means table below needs initializing. */
    Tcl_HashTable predefBitmapTable;
				/* Hash table created by Tk_DefineBitmap to
				 * map from a name to a collection of in-core
				 * data about a bitmap. The table is indexed
				 * by the address of the data for the bitmap,
				 * and the entries contain pointers to
121
122
123
124
125
126
127
128
129


130
131
132
133

134
135
136
137
138
139
140
141
142
117
118
119
120
121
122
123


124
125
126
127
128

129


130
131
132
133
134
135
136







-
-
+
+



-
+
-
-








/*
 * The following structure defines the implementation of the "bitmap" Tcl
 * object, which maps a string bitmap name to a TkBitmap object. The ptr1
 * field of the Tcl_Obj points to a TkBitmap object.
 */

const TkObjType tkBitmapObjType = {
    {"bitmap",			/* name */
const Tcl_ObjType tkBitmapObjType = {
    "bitmap",			/* name */
    FreeBitmapObjProc,		/* freeIntRepProc */
    DupBitmapObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_AllocBitmapFromObj --
 *
166
167
168
169
170
171
172
173

174
175
176

177
178
179
180
181
182
183
160
161
162
163
164
165
166

167
168
169

170
171
172
173
174
175
176
177







-
+


-
+







				 * NULL. */
    Tk_Window tkwin,		/* Need the screen the bitmap is used on.*/
    Tcl_Obj *objPtr)		/* Object describing bitmap; see manual entry
				 * for legal syntax of string value. */
{
    TkBitmap *bitmapPtr;

    if (objPtr->typePtr != &tkBitmapObjType.objType) {
    if (objPtr->typePtr != &tkBitmapObjType) {
	InitBitmapObj(objPtr);
    }
    bitmapPtr = (TkBitmap *)objPtr->internalRep.twoPtrValue.ptr1;
    bitmapPtr = objPtr->internalRep.twoPtrValue.ptr1;

    /*
     * If the object currently points to a TkBitmap, see if it's the one we
     * want. If so, increment its reference count and return.
     */

    if (bitmapPtr != NULL) {
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207







-
+







    /*
     * The object didn't point to the TkBitmap that we wanted. Search the list
     * of TkBitmaps with the same name to see if one of the others is the
     * right one.
     */

    if (bitmapPtr != NULL) {
	TkBitmap *firstBitmapPtr = (TkBitmap *)Tcl_GetHashValue(bitmapPtr->nameHashPtr);
	TkBitmap *firstBitmapPtr = Tcl_GetHashValue(bitmapPtr->nameHashPtr);

	FreeBitmapObj(objPtr);
	for (bitmapPtr = firstBitmapPtr; bitmapPtr != NULL;
		bitmapPtr = bitmapPtr->nextPtr) {
	    if ((Tk_Display(tkwin) == bitmapPtr->display) &&
		    (Tk_ScreenNumber(tkwin) == bitmapPtr->screenNum)) {
		bitmapPtr->resourceRefCount++;
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327







-
+









-
+







{
    Tcl_HashEntry *nameHashPtr, *predefHashPtr;
    TkBitmap *bitmapPtr, *existingBitmapPtr;
    TkPredefBitmap *predefPtr;
    Pixmap bitmap;
    int isNew, width = 0, height = 0, dummy2;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!dispPtr->bitmapInit) {
	BitmapInit(dispPtr);
    }

    nameHashPtr = Tcl_CreateHashEntry(&dispPtr->bitmapNameTable, string,
	    &isNew);
    if (!isNew) {
	existingBitmapPtr = (TkBitmap *)Tcl_GetHashValue(nameHashPtr);
	existingBitmapPtr = Tcl_GetHashValue(nameHashPtr);
	for (bitmapPtr = existingBitmapPtr; bitmapPtr != NULL;
		bitmapPtr = bitmapPtr->nextPtr) {
	    if ((Tk_Display(tkwin) == bitmapPtr->display) &&
		    (Tk_ScreenNumber(tkwin) == bitmapPtr->screenNum)) {
		bitmapPtr->resourceRefCount++;
		return bitmapPtr;
	    }
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







-
+







    if (*string == '@') {	/* INTL: ISO char */
	Tcl_DString buffer;
	int result;

	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't specify bitmap with '@' in a safe interpreter",
		    TCL_INDEX_NONE));
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "BITMAP_FILE", NULL);
	    goto error;
	}

	/*
	 * Note that we need to cast away the const from the string because
	 * Tcl_TranslateFileName is non-const, even though it doesn't modify
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
426







-
+











-
+








-
+







			    "bitmap \"%s\" not defined", string));
		    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "BITMAP", string,
			    NULL);
		}
		goto error;
	    }
	} else {
	    predefPtr = (TkPredefBitmap *)Tcl_GetHashValue(predefHashPtr);
	    predefPtr = Tcl_GetHashValue(predefHashPtr);
	    width = predefPtr->width;
	    height = predefPtr->height;
	    if (predefPtr->native) {
		bitmap = TkpCreateNativeBitmap(Tk_Display(tkwin),
		    predefPtr->source);
		if (bitmap == None) {
		    Tcl_Panic("native bitmap creation failed");
		}
	    } else {
		bitmap = XCreateBitmapFromData(Tk_Display(tkwin),
			RootWindowOfScreen(Tk_Screen(tkwin)),
			(const char *)predefPtr->source, (unsigned)width, (unsigned)height);
			predefPtr->source, (unsigned)width, (unsigned)height);
	    }
	}
    }

    /*
     * Add information about this bitmap to our database.
     */

    bitmapPtr = (TkBitmap *)ckalloc(sizeof(TkBitmap));
    bitmapPtr = ckalloc(sizeof(TkBitmap));
    bitmapPtr->bitmap = bitmap;
    bitmapPtr->width = width;
    bitmapPtr->height = height;
    bitmapPtr->display = Tk_Display(tkwin);
    bitmapPtr->screenNum = Tk_ScreenNumber(tkwin);
    bitmapPtr->resourceRefCount = 1;
    bitmapPtr->objRefCount = 0;
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
470
471
472
473
474
475
476

477
478
479
480
481
482
483
484







-
+







    const void *source,		/* Address of bits for bitmap. */
    int width,			/* Width of bitmap. */
    int height)			/* Height of bitmap. */
{
    int isNew;
    Tcl_HashEntry *predefHashPtr;
    TkPredefBitmap *predefPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Initialize the Bitmap module if not initialized already for this
     * thread. Since the current TkDisplay structure cannot be introspected
     * from here, pass a NULL pointer to BitmapInit, which will know to
     * initialize only the data in the ThreadSpecificData structure for the
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507







-
+







	    name, &isNew);
    if (!isNew) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bitmap \"%s\" is already defined", name));
	Tcl_SetErrorCode(interp, "TK", "BITMAP", "EXISTS", NULL);
	return TCL_ERROR;
    }
    predefPtr = (TkPredefBitmap *)ckalloc(sizeof(TkPredefBitmap));
    predefPtr = ckalloc(sizeof(TkPredefBitmap));
    predefPtr->source = source;
    predefPtr->width = width;
    predefPtr->height = height;
    predefPtr->native = 0;
    Tcl_SetHashValue(predefHashPtr, predefPtr);
    return TCL_OK;
}
538
539
540
541
542
543
544
545

546
547
548
549

550
551
552
553
554
555
556
532
533
534
535
536
537
538

539
540
541
542

543
544
545
546
547
548
549
550







-
+



-
+







    TkDisplay *dispPtr = TkGetDisplay(display);

    if (dispPtr == NULL || !dispPtr->bitmapInit) {
    unknown:
	Tcl_Panic("Tk_NameOfBitmap received unknown bitmap argument");
    }

    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, bitmap);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, (char *) bitmap);
    if (idHashPtr == NULL) {
	goto unknown;
    }
    bitmapPtr = (TkBitmap *)Tcl_GetHashValue(idHashPtr);
    bitmapPtr = Tcl_GetHashValue(idHashPtr);
    return bitmapPtr->nameHashPtr->key.string;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_SizeOfBitmap --
580
581
582
583
584
585
586
587

588
589
590
591

592
593
594
595
596
597
598
574
575
576
577
578
579
580

581
582
583
584

585
586
587
588
589
590
591
592







-
+



-
+







    TkDisplay *dispPtr = TkGetDisplay(display);

    if (!dispPtr->bitmapInit) {
    unknownBitmap:
	Tcl_Panic("Tk_SizeOfBitmap received unknown bitmap argument");
    }

    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, bitmap);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, (char *) bitmap);
    if (idHashPtr == NULL) {
	goto unknownBitmap;
    }
    bitmapPtr = (TkBitmap *)Tcl_GetHashValue(idHashPtr);
    bitmapPtr = Tcl_GetHashValue(idHashPtr);
    *widthPtr = bitmapPtr->width;
    *heightPtr = bitmapPtr->height;
}

/*
 *----------------------------------------------------------------------
 *
614
615
616
617
618
619
620

621

622
623
624
625
626
627

628
629
630
631
632
633
634
608
609
610
611
612
613
614
615

616
617
618
619
620
621

622
623
624
625
626
627
628
629







+
-
+





-
+








static void
FreeBitmap(
    TkBitmap *bitmapPtr)	/* Bitmap to be released. */
{
    TkBitmap *prevPtr;

    bitmapPtr->resourceRefCount--;
    if (bitmapPtr->resourceRefCount-- > 1) {
    if (bitmapPtr->resourceRefCount > 0) {
	return;
    }

    Tk_FreePixmap(bitmapPtr->display, bitmapPtr->bitmap);
    Tcl_DeleteHashEntry(bitmapPtr->idHashPtr);
    prevPtr = (TkBitmap *)Tcl_GetHashValue(bitmapPtr->nameHashPtr);
    prevPtr = Tcl_GetHashValue(bitmapPtr->nameHashPtr);
    if (prevPtr == bitmapPtr) {
	if (bitmapPtr->nextPtr == NULL) {
	    Tcl_DeleteHashEntry(bitmapPtr->nameHashPtr);
	} else {
	    Tcl_SetHashValue(bitmapPtr->nameHashPtr, bitmapPtr->nextPtr);
	}
    } else {
668
669
670
671
672
673
674
675

676
677
678
679

680
681
682
683
684
685
686
663
664
665
666
667
668
669

670
671
672
673

674
675
676
677
678
679
680
681







-
+



-
+







    Tcl_HashEntry *idHashPtr;
    TkDisplay *dispPtr = TkGetDisplay(display);

    if (!dispPtr->bitmapInit) {
	Tcl_Panic("Tk_FreeBitmap called before Tk_GetBitmap");
    }

    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, bitmap);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->bitmapIdTable, (char *) bitmap);
    if (idHashPtr == NULL) {
	Tcl_Panic("Tk_FreeBitmap received unknown bitmap argument");
    }
    FreeBitmap((TkBitmap *)Tcl_GetHashValue(idHashPtr));
    FreeBitmap(Tcl_GetHashValue(idHashPtr));
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_FreeBitmapFromObj --
 *
736
737
738
739
740
741
742
743

744
745
746
747
748
749
750
731
732
733
734
735
736
737

738
739
740
741
742
743
744
745







-
+







    objPtr->typePtr = NULL;
}

static void
FreeBitmapObj(
    Tcl_Obj *objPtr)		/* The object we are releasing. */
{
    TkBitmap *bitmapPtr = (TkBitmap *)objPtr->internalRep.twoPtrValue.ptr1;
    TkBitmap *bitmapPtr = objPtr->internalRep.twoPtrValue.ptr1;

    if (bitmapPtr != NULL) {
	bitmapPtr->objRefCount--;
	if ((bitmapPtr->objRefCount == 0)
		&& (bitmapPtr->resourceRefCount == 0)) {
	    ckfree(bitmapPtr);
	}
771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
766
767
768
769
770
771
772

773
774
775
776
777
778
779
780







-
+







 */

static void
DupBitmapObjProc(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    TkBitmap *bitmapPtr = (TkBitmap *)srcObjPtr->internalRep.twoPtrValue.ptr1;
    TkBitmap *bitmapPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;

    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep.twoPtrValue.ptr1 = bitmapPtr;

    if (bitmapPtr != NULL) {
	bitmapPtr->objRefCount++;
    }
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827

828
829
830
831
832
833
834

835
836
837
838
839
840

841
842
843

844
845
846
847
848
849
850
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829

830
831
832
833
834
835

836
837
838

839
840
841
842
843
844
845
846







+













-
+






-
+





-
+


-
+







 *	For each call to this function, there should eventually be a call to
 *	Tk_FreeBitmap, so that the database can be cleaned up when bitmaps
 *	aren't needed anymore.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
Pixmap
Tk_GetBitmapFromData(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tk_Window tkwin,		/* Window in which bitmap will be used. */
    const void *source,		/* Bitmap data for bitmap shape. */
    int width, int height)	/* Dimensions of bitmap. */
{
    DataKey nameKey;
    Tcl_HashEntry *dataHashPtr;
    int isNew;
    char string[16 + TCL_INTEGER_SPACE];
    char *name;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	BitmapInit(dispPtr);
    }

    nameKey.source = (const char *)source;
    nameKey.source = source;
    nameKey.width = width;
    nameKey.height = height;
    dataHashPtr = Tcl_CreateHashEntry(&dispPtr->bitmapDataTable,
	    (char *) &nameKey, &isNew);
    if (!isNew) {
	name = (char *)Tcl_GetHashValue(dataHashPtr);
	name = Tcl_GetHashValue(dataHashPtr);
    } else {
	dispPtr->bitmapAutoNumber++;
	snprintf(string, sizeof(string), "_tk%d", dispPtr->bitmapAutoNumber);
	sprintf(string, "_tk%d", dispPtr->bitmapAutoNumber);
	name = string;
	Tcl_SetHashValue(dataHashPtr, name);
	if (Tk_DefineBitmap(interp, name, source, width, height) != TCL_OK) {
	    Tcl_DeleteHashEntry(dataHashPtr);
	    return TCL_ERROR;
	}
    }
907
908
909
910
911
912
913
914

915
916
917
918

919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939

940
941
942
943
944
945
946
903
904
905
906
907
908
909

910
911
912
913

914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934

935
936
937
938
939
940
941
942







-
+



-
+




















-
+







    Tcl_Obj *objPtr)		/* The object that describes the desired
				 * bitmap. */
{
    TkBitmap *bitmapPtr;
    Tcl_HashEntry *hashPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (objPtr->typePtr != &tkBitmapObjType.objType) {
    if (objPtr->typePtr != &tkBitmapObjType) {
	InitBitmapObj(objPtr);
    }

    bitmapPtr = (TkBitmap *)objPtr->internalRep.twoPtrValue.ptr1;
    bitmapPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if (bitmapPtr != NULL) {
	if ((bitmapPtr->resourceRefCount > 0)
		&& (Tk_Display(tkwin) == bitmapPtr->display)) {
	    return bitmapPtr;
	}
	hashPtr = bitmapPtr->nameHashPtr;
	FreeBitmapObj(objPtr);
    } else {
	hashPtr = Tcl_FindHashEntry(&dispPtr->bitmapNameTable,
		Tcl_GetString(objPtr));
	if (hashPtr == NULL) {
	    goto error;
	}
    }

    /*
     * At this point we've got a hash table entry, off of which hang one or
     * more TkBitmap structures. See if any of them will work.
     */

    for (bitmapPtr = (TkBitmap *)Tcl_GetHashValue(hashPtr); bitmapPtr != NULL;
    for (bitmapPtr = Tcl_GetHashValue(hashPtr); bitmapPtr != NULL;
	    bitmapPtr = bitmapPtr->nextPtr) {
	if (Tk_Display(tkwin) == bitmapPtr->display) {
	    objPtr->internalRep.twoPtrValue.ptr1 = bitmapPtr;
	    bitmapPtr->objRefCount++;
	    return bitmapPtr;
	}
    }
982
983
984
985
986
987
988
989

990
991
992
993
994
995
996
978
979
980
981
982
983
984

985
986
987
988
989
990
991
992







-
+







     */

    Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }
    objPtr->typePtr = &tkBitmapObjType.objType;
    objPtr->typePtr = &tkBitmapObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * BitmapInit --
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







-
+



-
+







static void
BitmapInit(
    TkDisplay *dispPtr)		/* TkDisplay structure encapsulating
				 * thread-specific data used by this module,
				 * or NULL if unavailable. */
{
    Tcl_Interp *dummy;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * First initialize the data in the ThreadSpecificData structure, if
     * First initialize the data in the ThreadSpecificData strucuture, if
     * needed.
     */

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	dummy = Tcl_CreateInterp();
	Tcl_InitHashTable(&tsdPtr->predefBitmapTable, TCL_STRING_KEYS);
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
1090







-
+








/*
 *----------------------------------------------------------------------
 *
 * TkReadBitmapFile --
 *
 *	Loads a bitmap image in X bitmap format into the specified drawable.
 *	This is equivalent to the XReadBitmapFile in X.
 *	This is equivelent to the XReadBitmapFile in X.
 *
 * Results:
 *	Sets the size, hotspot, and bitmap on success.
 *
 * Side effects:
 *	Creates a new bitmap from the file data.
 *
1150
1151
1152
1153
1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164

1165
1166

1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159

1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205







-
+






-
+

-
+











-
+


















-
+












    Tcl_HashEntry *hashPtr;
    Tcl_Obj *resultPtr, *objPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    resultPtr = Tcl_NewObj();
    hashPtr = Tcl_FindHashEntry(&dispPtr->bitmapNameTable, name);
    if (hashPtr != NULL) {
	bitmapPtr = (TkBitmap *)Tcl_GetHashValue(hashPtr);
	bitmapPtr = Tcl_GetHashValue(hashPtr);
	if (bitmapPtr == NULL) {
	    Tcl_Panic("TkDebugBitmap found empty hash table entry");
	}
	for ( ; (bitmapPtr != NULL); bitmapPtr = bitmapPtr->nextPtr) {
	    objPtr = Tcl_NewObj();
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(bitmapPtr->resourceRefCount));
		    Tcl_NewIntObj(bitmapPtr->resourceRefCount));
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(bitmapPtr->objRefCount));
		    Tcl_NewIntObj(bitmapPtr->objRefCount));
	    Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
	}
    }
    return resultPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetBitmapPredefTable --
 *
 *	This function is used by tkMacOSXBitmap.c to access the thread-specific
 *	This function is used by tkMacBitmap.c to access the thread-specific
 *	predefBitmap table that maps from the names of the predefined bitmaps
 *	to data associated with those bitmaps. It is required because the
 *	table is allocated in thread-local storage and is not visible outside
 *	this file.

 * Results:
 *	Returns a pointer to the predefined bitmap hash table for the current
 *	thread.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_HashTable *
TkGetBitmapPredefTable(void)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    return &tsdPtr->predefBitmapTable;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkBusy.c.

12
13
14
15
16
17
18
19
20
21
22
23
24

25

26
27
28

29
30

31

32
33
34
35
36
37
38
39

40
41

42
43

44
45
46

47
48

49
50
51
52
53
54
55
56

57
58
59
60
61


62
63

64
65
66
67
68
69
70
12
13
14
15
16
17
18




19

20

21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36

37
38

39
40

41
42
43

44
45

46
47
48
49
50
51
52
53

54
55
56
57


58
59
60

61
62
63
64
65
66
67
68







-
-
-
-

-
+
-
+



+

-
+

+







-
+

-
+

-
+


-
+

-
+







-
+



-
-
+
+

-
+







 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkBusy.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Things about the busy system that may be configured. Note that on some
 * Things about the busy system that may be configured. Note that currently on
 * platforms this may or may not have an effect.
 * OSX/Aqua, that's nothing at all.
 */

static const Tk_OptionSpec busyOptionSpecs[] = {
#ifndef MAC_OSX_TK
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_BUSY_CURSOR, TCL_INDEX_NONE, offsetof(Busy, cursor),
	DEF_BUSY_CURSOR, -1, Tk_Offset(Busy, cursor),
	TK_OPTION_NULL_OK, 0, 0},
#endif
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 * Forward declarations of functions defined in this file.
 */

static void		BusyEventProc(void *clientData,
static void		BusyEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		BusyGeometryProc(void *clientData,
static void		BusyGeometryProc(ClientData clientData,
			    Tk_Window tkwin);
static void		BusyCustodyProc(void *clientData,
static void		BusyCustodyProc(ClientData clientData,
			    Tk_Window tkwin);
static int		ConfigureBusy(Tcl_Interp *interp, Busy *busyPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static Busy *		CreateBusy(Tcl_Interp *interp, Tk_Window tkRef);
static Tcl_FreeProc	DestroyBusy;
static void		DestroyBusy(void *dataPtr);
static void		DoConfigureNotify(Tk_FakeWin *winPtr);
static inline Tk_Window	FirstChild(Tk_Window parent);
static Busy *		GetBusy(Tcl_Interp *interp,
			    Tcl_HashTable *busyTablePtr,
			    Tcl_Obj *const windowObj);
static int		HoldBusy(Tcl_HashTable *busyTablePtr,
			    Tcl_Interp *interp, Tcl_Obj *const windowObj,
			    Tcl_Size configObjc, Tcl_Obj *const configObjv[]);
			    int configObjc, Tcl_Obj *const configObjv[]);
static void		MakeTransparentWindowExist(Tk_Window tkwin,
			    Window parent);
static inline Tk_Window	NextChild(Tk_Window tkwin);
static void		RefWinEventProc(void *clientData,
			    XEvent *eventPtr);
static void		RefWinEventProc(ClientData clientData,
			    register XEvent *eventPtr);
static inline void	SetWindowInstanceData(Tk_Window tkwin,
			    void *instanceData);
			    ClientData instanceData);

/*
 * The "busy" geometry manager definition.
 */

static Tk_GeomMgr busyMgrInfo = {
    "busy",			/* Name of geometry manager used by winfo */
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







-
+







    }
    return (Tk_Window) winPtr->nextPtr;
}

static inline void
SetWindowInstanceData(
    Tk_Window tkwin,
    void *instanceData)
    ClientData instanceData)
{
    struct TkWindow *winPtr = (struct TkWindow *) tkwin;

    winPtr->instanceData = instanceData;
}

/*
122
123
124
125
126
127
128

129
130
131
132


133
134

135
136
137
138
139
140

141
142
143
144
145
146
147
120
121
122
123
124
125
126
127
128
129


130
131
132

133
134
135
136
137
138

139
140
141
142
143
144
145
146







+


-
-
+
+

-
+





-
+







 *
 * Side effects:
 *	The Busy structure is freed at the next idle point.
 *
 *----------------------------------------------------------------------
 */

/* ARGSUSED */
static void
BusyCustodyProc(
    void *clientData,	/* Information about the busy window. */
    TCL_UNUSED(Tk_Window))		/* Not used. */
    ClientData clientData,	/* Information about the busy window. */
    Tk_Window tkwin)		/* Not used. */
{
    Busy *busyPtr = (Busy *)clientData;
    Busy *busyPtr = clientData;

    Tk_DeleteEventHandler(busyPtr->tkBusy, StructureNotifyMask, BusyEventProc,
	    busyPtr);
    TkpHideBusyWindow(busyPtr);
    busyPtr->tkBusy = NULL;
    Tcl_EventuallyFree(busyPtr, DestroyBusy);
    Tcl_EventuallyFree(busyPtr, (Tcl_FreeProc *)DestroyBusy);
}

/*
 *----------------------------------------------------------------------
 *
 * BusyGeometryProc --
 *
155
156
157
158
159
160
161

162
163
164

165
166

167
168
169
170
171
172
173
154
155
156
157
158
159
160
161
162
163

164
165

166
167
168
169
170
171
172
173







+


-
+

-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

/* ARGSUSED */
static void
BusyGeometryProc(
    TCL_UNUSED(void *),	/* Information about window that got new
    ClientData clientData,	/* Information about window that got new
				 * preferred geometry. */
    TCL_UNUSED(Tk_Window))		/* Other Tk-related information about the
    Tk_Window tkwin)		/* Other Tk-related information about the
				 * window. */
{
    /* Should never get here */
}

/*
 *----------------------------------------------------------------------
246
247
248
249
250
251
252
253
254


255
256

257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
246
247
248
249
250
251
252


253
254
255

256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272







-
-
+
+

-
+








-
+







 *	it's hidden, the busy window is unmapped.
 *
 *----------------------------------------------------------------------
 */

static void
RefWinEventProc(
    void *clientData,	/* Busy window record */
    XEvent *eventPtr)	/* Event which triggered call to routine */
    ClientData clientData,	/* Busy window record */
    register XEvent *eventPtr)	/* Event which triggered call to routine */
{
    Busy *busyPtr = (Busy *)clientData;
    register Busy *busyPtr = clientData;

    switch (eventPtr->type) {
    case ReparentNotify:
    case DestroyNotify:
	/*
	 * Arrange for the busy structure to be removed at a proper time.
	 */

	Tcl_EventuallyFree(busyPtr, DestroyBusy);
	Tcl_EventuallyFree(busyPtr, (Tcl_FreeProc *)DestroyBusy);
	break;

    case ConfigureNotify:
	if ((busyPtr->width != Tk_Width(busyPtr->tkRef)) ||
		(busyPtr->height != Tk_Height(busyPtr->tkRef)) ||
		(busyPtr->x != Tk_X(busyPtr->tkRef)) ||
		(busyPtr->y != Tk_Y(busyPtr->tkRef))) {
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
329
330
331
332
333
334
335

336



337

338
339
340
341
342
343
344
345







-

-
-
-

-
+







 *	Memory and resources are released and the Tk event handler is removed.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyBusy(
#if TCL_MAJOR_VERSION > 8
    void *data)			/* Busy window structure record */
#else
    char *data)
#endif
{
    Busy *busyPtr = (Busy *)data;
    register Busy *busyPtr = data;

    if (busyPtr->hashPtr != NULL) {
	Tcl_DeleteHashEntry(busyPtr->hashPtr);
    }
    Tk_DeleteEventHandler(busyPtr->tkRef, StructureNotifyMask,
	    RefWinEventProc, busyPtr);

376
377
378
379
380
381
382
383

384
385
386

387
388
389
390

391
392
393
394
395
396
397
372
373
374
375
376
377
378

379
380
381

382
383
384
385

386
387
388
389
390
391
392
393







-
+


-
+



-
+







 *	with it released at the next idle point.
 *
 *----------------------------------------------------------------------
 */

static void
BusyEventProc(
    void *clientData,	/* Busy window record */
    ClientData clientData,	/* Busy window record */
    XEvent *eventPtr)		/* Event which triggered call to routine */
{
    Busy *busyPtr = (Busy *)clientData;
    Busy *busyPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	busyPtr->tkBusy = NULL;
	Tcl_EventuallyFree(busyPtr, DestroyBusy);
	Tcl_EventuallyFree(busyPtr, (Tcl_FreeProc *)DestroyBusy);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MakeTransparentWindowExist --
521
522
523
524
525
526
527
528

529
530
531
532
533
534
535
536

537
538
539

540
541
542
543
544
545
546
517
518
519
520
521
522
523

524

525
526
527
528
529
530

531
532
533

534
535
536
537
538
539
540
541







-
+
-






-
+


-
+








static Busy *
CreateBusy(
    Tcl_Interp *interp,		/* Interpreter to report error to */
    Tk_Window tkRef)		/* Window hosting the busy window */
{
    Busy *busyPtr;
    size_t length;
    int length, x, y;
    int x, y;
    const char *fmt;
    char *name;
    Tk_Window tkBusy, tkChild, tkParent;
    Window parent;
    Tk_FakeWin *winPtr;

    busyPtr = (Busy *)ckalloc(sizeof(Busy));
    busyPtr = ckalloc(sizeof(Busy));
    x = y = 0;
    length = strlen(Tk_Name(tkRef));
    name = (char *)ckalloc(length + 6);
    name = ckalloc(length + 6);
    if (Tk_IsTopLevel(tkRef)) {
	fmt = "_Busy";		/* Child */
	tkParent = tkRef;
    } else {
	Tk_Window tkwin;

	fmt = "%s_Busy";	/* Sibling */
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

579
580
581

582
583
584
585
586
587
588
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572

573
574
575

576
577
578
579
580
581
582
583







-
+
















-
+


-
+







	    y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
	}
    }
    for (tkChild = FirstChild(tkParent); tkChild != NULL;
	    tkChild = NextChild(tkChild)) {
	Tk_MakeWindowExist(tkChild);
    }
    snprintf(name, length + 6, fmt, Tk_Name(tkRef));
    sprintf(name, fmt, Tk_Name(tkRef));
    tkBusy = Tk_CreateWindow(interp, tkParent, name, NULL);
    ckfree(name);

    if (tkBusy == NULL) {
	return NULL;
    }
    Tk_MakeWindowExist(tkRef);
    busyPtr->display = Tk_Display(tkRef);
    busyPtr->interp = interp;
    busyPtr->tkRef = tkRef;
    busyPtr->tkParent = tkParent;
    busyPtr->tkBusy = tkBusy;
    busyPtr->width = Tk_Width(tkRef);
    busyPtr->height = Tk_Height(tkRef);
    busyPtr->x = Tk_X(tkRef);
    busyPtr->y = Tk_Y(tkRef);
    busyPtr->cursor = NULL;
    busyPtr->cursor = None;
    Tk_SetClass(tkBusy, "Busy");
    busyPtr->optionTable = Tk_CreateOptionTable(interp, busyOptionSpecs);
    if (Tk_InitOptions(interp, busyPtr, busyPtr->optionTable,
    if (Tk_InitOptions(interp, (char *) busyPtr, busyPtr->optionTable,
	    tkBusy) != TCL_OK) {
	Tk_DestroyWindow(tkBusy);
	return NULL;
    }
    SetWindowInstanceData(tkBusy, busyPtr);
    winPtr = (Tk_FakeWin *) tkRef;

601
602
603
604
605
606
607
608

609
610
611
612
613
614
615
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610







-
+








    /*
     * Indicate that the busy window's geometry is being managed. This will
     * also notify us if the busy window is ever packed.
     */

    Tk_ManageGeometry(tkBusy, &busyMgrInfo, busyPtr);
    if (busyPtr->cursor != NULL) {
    if (busyPtr->cursor != None) {
	Tk_DefineCursor(tkBusy, busyPtr->cursor);
    }

    /*
     * Track the reference window to see if it is resized or destroyed.
     */

636
637
638
639
640
641
642
643

644
645
646
647
648

649
650
651
652
653

654
655
656
657
658
659
660
631
632
633
634
635
636
637

638
639
640
641
642

643
644
645
646
647

648
649
650
651
652
653
654
655







-
+




-
+




-
+







 *----------------------------------------------------------------------
 */

static int
ConfigureBusy(
    Tcl_Interp *interp,
    Busy *busyPtr,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tk_Cursor oldCursor = busyPtr->cursor;

    if (Tk_SetOptions(interp, busyPtr, busyPtr->optionTable, objc,
    if (Tk_SetOptions(interp, (char *) busyPtr, busyPtr->optionTable, objc,
	    objv, busyPtr->tkBusy, NULL, NULL) != TCL_OK) {
	return TCL_ERROR;
    }
    if (busyPtr->cursor != oldCursor) {
	if (busyPtr->cursor == NULL) {
	if (busyPtr->cursor == None) {
	    Tk_UndefineCursor(busyPtr->tkBusy);
	} else {
	    Tk_DefineCursor(busyPtr->tkBusy, busyPtr->cursor);
	}
    }

    return TCL_OK;
686
687
688
689
690
691
692
693
694


695
696
697

698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
681
682
683
684
685
686
687


688
689
690
691

692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707







-
-
+
+


-
+







-
+







    Tcl_Interp *interp,		/* Interpreter to look up main window of. */
    Tcl_HashTable *busyTablePtr,/* Busy hash table */
    Tcl_Obj *const windowObj)	/* Path name of parent window */
{
    Tcl_HashEntry *hPtr;
    Tk_Window tkwin;

    tkwin = Tk_MainWindow(interp);
    if (!tkwin || (TkGetWindowFromObj(interp, tkwin, windowObj, &tkwin) != TCL_OK)) {
    if (TkGetWindowFromObj(interp, Tk_MainWindow(interp), windowObj,
	    &tkwin) != TCL_OK) {
	return NULL;
    }
    hPtr = Tcl_FindHashEntry(busyTablePtr, tkwin);
    hPtr = Tcl_FindHashEntry(busyTablePtr, (char *) tkwin);
    if (hPtr == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't find busy window \"%s\"", Tcl_GetString(windowObj)));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "BUSY",
		Tcl_GetString(windowObj), NULL);
	return NULL;
    }
    return (Busy *)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * HoldBusy --
 *
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
722
723
724
725
726
727
728

729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744

745
746
747
748
749

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765



766
767
768
769
770
771
772







-
+















-





-
+















-
-
-







 */

static int
HoldBusy(
    Tcl_HashTable *busyTablePtr,/* Busy hash table. */
    Tcl_Interp *interp,		/* Interpreter to report errors to. */
    Tcl_Obj *const windowObj,	/* Window name. */
    Tcl_Size configObjc,		/* Option pairs. */
    int configObjc,		/* Option pairs. */
    Tcl_Obj *const configObjv[])
{
    Tk_Window tkwin;
    Tcl_HashEntry *hPtr;
    Busy *busyPtr;
    int isNew, result;

    if (TkGetWindowFromObj(interp, Tk_MainWindow(interp), windowObj,
	    &tkwin) != TCL_OK) {
	return TCL_ERROR;
    }
    hPtr = Tcl_CreateHashEntry(busyTablePtr, (char *) tkwin, &isNew);
    if (isNew) {
	busyPtr = CreateBusy(interp, tkwin);
	if (busyPtr == NULL) {
	    Tcl_DeleteHashEntry(hPtr);
	    return TCL_ERROR;
	}
	Tcl_SetHashValue(hPtr, busyPtr);
	busyPtr->hashPtr = hPtr;
    } else {
	busyPtr = (Busy *)Tcl_GetHashValue(hPtr);
	busyPtr = Tcl_GetHashValue(hPtr);
    }

    busyPtr->tablePtr = busyTablePtr;
    result = ConfigureBusy(interp, busyPtr, configObjc, configObjv);

    /*
     * Don't map the busy window unless the reference window is also currently
     * displayed.
     */

    if (Tk_IsMapped(busyPtr->tkRef)) {
	TkpShowBusyWindow(busyPtr);
    } else {
	TkpHideBusyWindow(busyPtr);
    }
    if (result == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(busyPtr->tkBusy), TCL_INDEX_NONE));
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_BusyObjCmd --
790
791
792
793
794
795
796
797

798
799

800
801
802

803
804
805
806
807
808

809
810
811
812
813


814
815
816
817

818
819
820
821
822
823
824
825
826
827

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861

862
863
864
865
866
867
868
869
870
871
872
873

874
875
876
877
878
879
880
881
882

883
884
885
886
887
888
889
781
782
783
784
785
786
787

788
789

790
791
792

793
794
795
796
797
798

799

800
801


802
803
804
805
806

807
808
809
810
811
812
813
814
815
816

817
818
819
820
821
822
823
824
825
826
827













828
829
830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845
846
847
848
849

850
851
852
853
854
855
856
857
858

859
860
861
862
863
864
865
866







-
+

-
+


-
+





-
+
-


-
-
+
+



-
+









-
+










-
-
-
-
-
-
-
-
-
-
-
-
-










-
+











-
+








-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_BusyObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    Tcl_HashTable *busyTablePtr = &((TkWindow *) tkwin)->mainPtr->busyTable;
    Busy *busyPtr;
    Tcl_Obj *objPtr;
    int index, result = TCL_OK;
    static const char *const optionStrings[] = {
	"busywindow", "cget", "configure", "current", "forget", "hold",
	"cget", "configure", "current", "forget", "hold", "status", NULL
        "status", NULL
    };
    enum options {
	BUSY_BUSYWINDOW, BUSY_CGET, BUSY_CONFIGURE, BUSY_CURRENT, BUSY_FORGET,
	BUSY_HOLD, BUSY_STATUS
	BUSY_CGET, BUSY_CONFIGURE, BUSY_CURRENT, BUSY_FORGET, BUSY_HOLD,
	BUSY_STATUS
    };

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "options ?arg ...?");
	Tcl_WrongNumArgs(interp, 1, objv, "options ?arg arg ...?");
	return TCL_ERROR;
    }

    /*
     * [tk busy <window>] command shortcut.
     */

    if (Tcl_GetString(objv[1])[0] == '.') {
	if (objc%2 == 1) {
	    Tcl_WrongNumArgs(interp, 1, objv, "window ?-option value ...?");
	    Tcl_WrongNumArgs(interp, 1, objv, "window ?option value ...?");
	    return TCL_ERROR;
	}
	return HoldBusy(busyTablePtr, interp, objv[1], objc-2, objv+2);
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    switch ((enum options) index) {
    case BUSY_BUSYWINDOW:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	busyPtr = GetBusy(interp, busyTablePtr, objv[2]);
	if (busyPtr == NULL) {
	    Tcl_ResetResult(interp);
            return TCL_OK;
	}
        Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(busyPtr->tkBusy), TCL_INDEX_NONE));
        return TCL_OK;

    case BUSY_CGET:
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window option");
	    return TCL_ERROR;
	}
	busyPtr = GetBusy(interp, busyTablePtr, objv[2]);
	if (busyPtr == NULL) {
	    return TCL_ERROR;
	}
	Tcl_Preserve(busyPtr);
	objPtr = Tk_GetOptionValue(interp, busyPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) busyPtr,
		busyPtr->optionTable, objv[3], busyPtr->tkBusy);
	if (objPtr == NULL) {
	    result = TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, objPtr);
	}
	Tcl_Release(busyPtr);
	return result;

    case BUSY_CONFIGURE:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?-option value ...?");
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?option? ?value ...?");
	    return TCL_ERROR;
	}
	busyPtr = GetBusy(interp, busyTablePtr, objv[2]);
	if (busyPtr == NULL) {
	    return TCL_ERROR;
	}
	Tcl_Preserve(busyPtr);
	if (objc <= 4) {
	    objPtr = Tk_GetOptionInfo(interp, busyPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) busyPtr,
		    busyPtr->optionTable, (objc == 4) ? objv[3] : NULL,
		    busyPtr->tkBusy);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, objPtr);
	    }
897
898
899
900
901
902
903
904

905
906

907
908

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925

926
927
928
929
930

931
932
933
934
935
936
937
874
875
876
877
878
879
880

881
882

883
884

885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901

902
903
904
905
906

907
908
909
910
911
912
913
914







-
+

-
+

-
+
















-
+




-
+







	Tcl_HashEntry *hPtr;
	Tcl_HashSearch cursor;
	const char *pattern = (objc == 3 ? Tcl_GetString(objv[2]) : NULL);

	objPtr = Tcl_NewObj();
	for (hPtr = Tcl_FirstHashEntry(busyTablePtr, &cursor); hPtr != NULL;
		hPtr = Tcl_NextHashEntry(&cursor)) {
	    busyPtr = (Busy *)Tcl_GetHashValue(hPtr);
	    busyPtr = Tcl_GetHashValue(hPtr);
	    if (pattern == NULL ||
		    Tcl_StringCaseMatch(Tk_PathName(busyPtr->tkRef), pattern, 0)) {
		    Tcl_StringMatch(Tk_PathName(busyPtr->tkRef), pattern)) {
		Tcl_ListObjAppendElement(interp, objPtr,
			Tk_NewWindowObj(busyPtr->tkRef));
			TkNewWindowObj(busyPtr->tkRef));
	    }
	}
	Tcl_SetObjResult(interp, objPtr);
	return TCL_OK;
    }

    case BUSY_FORGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	busyPtr = GetBusy(interp, busyTablePtr, objv[2]);
	if (busyPtr == NULL) {
	    return TCL_ERROR;
	}
	TkpHideBusyWindow(busyPtr);
	Tcl_EventuallyFree(busyPtr, DestroyBusy);
	Tcl_EventuallyFree(busyPtr, (Tcl_FreeProc *)DestroyBusy);
	return TCL_OK;

    case BUSY_HOLD:
	if (objc < 3 || objc%2 != 1) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?-option value ...?");
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?option value ...?");
	    return TCL_ERROR;
	}
	return HoldBusy(busyTablePtr, interp, objv[2], objc-3, objv+3);

    case BUSY_STATUS:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");

Changes to generic/tkButton.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33











34
35
36

37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67

68
69
70

71
72

73
74
75

76
77

78
79

80
81
82
83


84
85
86


87
88

89
90
91
92
93


94
95

96
97

98
99

100
101

102
103
104
105


106
107

108
109
110
111
112


113
114

115
116
117

118
119
120


121
122
123


124
125

126
127
128


129
130

131
132
133

134
135

136
137
138


139
140

141
142
143


144
145
146
147
148
149

150
151
152

153
154
155

156
157

158
159
160

161
162

163
164

165
166
167
168


169
170

171
172
173
174


175
176

177
178
179
180


181
182
183
184


185
186

187
188

189
190

191
192

193
194
195
196


197
198

199
200
201
202
203


204
205

206
207
208

209
210

211
212
213
214


215
216
217


218
219

220
221
222

223
224
225

226
227
228
229


230
231

232
233
234

235
236

237
238
239


240
241

242
243
244
245



246
247
248
249
250

251
252
253

254
255
256

257
258

259
260
261

262
263

264
265

266
267
268
269


270
271

272
273
274
275


276
277

278
279
280
281
282


283
284

285
286

287
288

289
290

291
292
293
294


295
296

297
298
299
300
301


302
303

304
305
306

307
308

309
310

311
312

313
314

315
316
317


318
319
320


321
322
323


324
325

326
327

328
329
330

331
332
333
334


335
336

337
338
339

340
341

342
343
344

345
346
347
348
349



350
351

352
353
354

355
356
357
358



359
360
361
362
363

364
365
366

367
368
369

370
371

372
373
374

375
376

377
378

379
380
381
382


383
384

385
386
387
388


389
390

391
392
393
394
395


396
397

398
399

400
401

402
403

404
405
406
407


408
409

410
411
412
413
414


415
416

417
418
419

420
421
422

423
424

425
426

427
428
429
430


431
432
433


434
435

436
437

438
439
440

441
442
443
444


445
446

447
448
449

450
451

452
453
454

455
456
457
458
459



460
461

462
463

464
465
466

467
468
469
470



471
472
473
474
475
476
477
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75

76
77
78

79
80

81
82
83

84
85

86
87

88
89
90


91
92
93


94
95
96

97
98
99
100


101
102
103

104
105

106
107

108
109

110
111
112


113
114
115

116
117
118
119


120
121
122

123
124
125

126
127


128
129
130


131
132
133

134
135


136
137
138

139
140
141

142
143

144
145


146
147
148

149
150


151
152
153
154
155
156
157

158
159
160

161
162
163

164
165

166
167
168

169
170

171
172

173
174
175


176
177
178

179
180
181


182
183
184

185
186
187


188
189
190
191


192
193
194

195
196

197
198

199
200

201
202
203


204
205
206

207
208
209
210


211
212
213

214
215
216

217
218

219
220
221


222
223
224


225
226
227

228
229
230

231
232
233

234
235
236


237
238
239

240
241
242

243
244

245
246


247
248
249

250
251



252
253
254
255
256
257
258

259
260
261

262
263
264

265
266

267
268
269

270
271

272
273

274
275
276


277
278
279

280
281
282


283
284
285

286
287
288
289


290
291
292

293
294

295
296

297
298

299
300
301


302
303
304

305
306
307
308


309
310
311

312
313
314

315
316

317
318

319
320

321
322

323
324


325
326
327


328
329
330


331
332
333

334
335

336
337
338

339
340
341


342
343
344

345
346
347

348
349

350
351
352

353
354
355



356
357
358
359

360
361
362

363
364



365
366
367
368
369
370
371

372
373
374

375
376
377

378
379

380
381
382

383
384

385
386

387
388
389


390
391
392

393
394
395


396
397
398

399
400
401
402


403
404
405

406
407

408
409

410
411

412
413
414


415
416
417

418
419
420
421


422
423
424

425
426
427

428
429
430

431
432

433
434

435
436
437


438
439
440


441
442
443

444
445

446
447
448

449
450
451


452
453
454

455
456
457

458
459

460
461
462

463
464
465



466
467
468
469

470
471

472
473
474

475
476



477
478
479
480
481
482
483
484
485
486







-
-
+
+









-
+












-
-
+
+
+
+
+
+
+
+
+
+
+


-
+








-
+


















-
+


-
+


-
+

-
+


-
+

-
+

-
+


-
-
+
+

-
-
+
+

-
+



-
-
+
+

-
+

-
+

-
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+


-
+

-
-
+
+

-
-
+
+

-
+

-
-
+
+

-
+


-
+

-
+

-
-
+
+

-
+

-
-
+
+





-
+


-
+


-
+

-
+


-
+

-
+

-
+


-
-
+
+

-
+


-
-
+
+

-
+


-
-
+
+


-
-
+
+

-
+

-
+

-
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+


-
+

-
+


-
-
+
+

-
-
+
+

-
+


-
+


-
+


-
-
+
+

-
+


-
+

-
+

-
-
+
+

-
+

-
-
-
+
+
+




-
+


-
+


-
+

-
+


-
+

-
+

-
+


-
-
+
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+

-
+

-
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+


-
+

-
+

-
+

-
+

-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
+

-
+


-
+


-
-
+
+

-
+


-
+

-
+


-
+


-
-
-
+
+
+

-
+


-
+

-
-
-
+
+
+




-
+


-
+


-
+

-
+


-
+

-
+

-
+


-
-
+
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+

-
+

-
+

-
+


-
-
+
+

-
+



-
-
+
+

-
+


-
+


-
+

-
+

-
+


-
-
+
+

-
-
+
+

-
+

-
+


-
+


-
-
+
+

-
+


-
+

-
+


-
+


-
-
-
+
+
+

-
+

-
+


-
+

-
-
-
+
+
+







/*
 * tkButton.c --
 *
 *	This module implements a collection of button-like widgets for the Tk
 *	toolkit. The widgets implemented include buttons, checkbuttons,
 *	radiobuttons, and labels.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkButton.h"
#include "default.h"

typedef struct {
typedef struct ThreadSpecificData {
    int defaultsInitialized;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Class names for buttons, indexed by one of the type values defined in
 * tkButton.h.
 */

static const char *const classNames[] = {"Label", "Button", "Checkbutton", "Radiobutton"};

/*
 * The following table defines the legal values for the -default/-state options.
 * It is used together with the "enum defaultValue/state" declarations in tkButton.h.
 * The following table defines the legal values for the -default option. It is
 * used together with the "enum defaultValue" declaration in tkButton.h.
 */

static const char *const defaultStrings[] = {
    "active", "disabled", "normal", NULL
};

/*
 * The following table defines the legal values for the -state option.
 * It is used together with the "enum state" declaration in tkButton.h.
 */

const char *const tkStateStrings[] = {
static const char *const stateStrings[] = {
    "active", "disabled", "normal", NULL
};

/*
 * The following table defines the legal values for the -compound option.
 * It is used with the "enum compound" declaration in tkButton.h
 */

const char *const tkCompoundStrings[] = {
static const char *const compoundStrings[] = {
    "bottom", "center", "left", "none", "right", "top", NULL
};

char tkDefButtonHighlightWidth[TCL_INTEGER_SPACE] = DEF_BUTTON_HIGHLIGHT_WIDTH;
char tkDefButtonPadx[TCL_INTEGER_SPACE] = DEF_BUTTON_PADX;
char tkDefButtonPady[TCL_INTEGER_SPACE] = DEF_BUTTON_PADY;
char tkDefButtonBorderWidth[TCL_INTEGER_SPACE] = DEF_BUTTON_BORDER_WIDTH;
char tkDefLabelHighlightWidth[TCL_INTEGER_SPACE] = DEF_LABEL_HIGHLIGHT_WIDTH;
char tkDefLabelPadx[TCL_INTEGER_SPACE] = DEF_LABCHKRAD_PADX;
char tkDefLabelPady[TCL_INTEGER_SPACE] = DEF_LABCHKRAD_PADY;

/*
 * Information used for parsing configuration options.  There is a
 * separate table for each of the four widget classes.
 */

static const Tk_OptionSpec labelOptionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_BUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeBorder),
	DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(TkButton, activeBorder),
	0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
	DEF_BUTTON_ACTIVE_FG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeFg),
	DEF_BUTTON_ACTIVE_FG_COLOR, -1, Tk_Offset(TkButton, activeFg),
	TK_OPTION_NULL_OK, DEF_BUTTON_ACTIVE_FG_MONO, 0},
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	DEF_BUTTON_ANCHOR, TCL_INDEX_NONE, offsetof(TkButton, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_ANCHOR, -1, Tk_Offset(TkButton, anchor), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, normalBorder),
	DEF_BUTTON_BG_COLOR, -1, Tk_Offset(TkButton, normalBorder),
	0, DEF_BUTTON_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
	DEF_BUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkButton, bitmap),
	DEF_BUTTON_BITMAP, -1, Tk_Offset(TkButton, bitmap),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	tkDefButtonBorderWidth, offsetof(TkButton, borderWidthPtr),
	offsetof(TkButton, borderWidth), 0, 0, 0},
	tkDefButtonBorderWidth, Tk_Offset(TkButton, borderWidthPtr),
	Tk_Offset(TkButton, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_BUTTON_COMPOUND, TCL_INDEX_NONE, offsetof(TkButton, compound),
	0, tkCompoundStrings, 0},
	 DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkButton, compound), 0,
	 compoundStrings, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_BUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkButton, cursor),
	DEF_BUTTON_CURSOR, -1, Tk_Offset(TkButton, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_BUTTON_DISABLED_FG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, disabledFg), TK_OPTION_NULL_OK,
	DEF_BUTTON_DISABLED_FG_MONO, 0},
	-1, Tk_Offset(TkButton, disabledFg), TK_OPTION_NULL_OK,
	(ClientData) DEF_BUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_BUTTON_FONT, TCL_INDEX_NONE, offsetof(TkButton, tkfont), 0, 0, 0},
	DEF_BUTTON_FONT, -1, Tk_Offset(TkButton, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_LABEL_FG, TCL_INDEX_NONE, offsetof(TkButton, normalFg), 0, 0, 0},
	DEF_BUTTON_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
    {TK_OPTION_STRING, "-height", "height", "Height",
	DEF_BUTTON_HEIGHT, offsetof(TkButton, heightPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightPtr), -1, 0, 0, 0},
    {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, highlightBorder), 0,
	DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
	-1, Tk_Offset(TkButton, highlightBorder), 0,
	(ClientData) DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_BUTTON_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkButton, highlightColorPtr),
	DEF_BUTTON_HIGHLIGHT, -1, Tk_Offset(TkButton, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", tkDefLabelHighlightWidth,
	offsetof(TkButton, highlightWidthPtr),
	offsetof(TkButton, highlightWidth), 0, 0, 0},
	Tk_Offset(TkButton, highlightWidthPtr),
	Tk_Offset(TkButton, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-image", "image", "Image",
	DEF_BUTTON_IMAGE, offsetof(TkButton, imagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, imagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_BUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkButton, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_JUSTIFY, -1, Tk_Offset(TkButton, justify), 0, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	tkDefLabelPadx, offsetof(TkButton, padXPtr),
	offsetof(TkButton, padX), 0, 0, 0},
	tkDefLabelPadx, Tk_Offset(TkButton, padXPtr),
	Tk_Offset(TkButton, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	tkDefLabelPady, offsetof(TkButton, padYPtr),
	offsetof(TkButton, padY), 0, 0, 0},
	tkDefLabelPady, Tk_Offset(TkButton, padYPtr),
	Tk_Offset(TkButton, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_LABCHKRAD_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, relief), 0, 0, 0},
	DEF_LABCHKRAD_RELIEF, -1, Tk_Offset(TkButton, relief), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_BUTTON_STATE, TCL_INDEX_NONE, offsetof(TkButton, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_BUTTON_STATE, -1, Tk_Offset(TkButton, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_LABEL_TAKE_FOCUS, offsetof(TkButton, takeFocusPtr), TCL_INDEX_NONE,
	DEF_LABEL_TAKE_FOCUS, Tk_Offset(TkButton, takeFocusPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_BUTTON_TEXT, offsetof(TkButton, textPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_TEXT, Tk_Offset(TkButton, textPtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_BUTTON_TEXT_VARIABLE, offsetof(TkButton, textVarNamePtr), TCL_INDEX_NONE,
	DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(TkButton, textVarNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TK_OPTION_UNDERLINE_DEF(TkButton, underline), 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	DEF_BUTTON_UNDERLINE, -1, Tk_Offset(TkButton, underline), 0, 0, 0},
    {TK_OPTION_STRING, "-width", "width", "Width",
	DEF_BUTTON_WIDTH, offsetof(TkButton, widthPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_WIDTH, Tk_Offset(TkButton, widthPtr), -1, 0, 0, 0},
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	DEF_BUTTON_WRAP_LENGTH, offsetof(TkButton, wrapLengthPtr),
	offsetof(TkButton, wrapLength), 0, 0, 0},
	DEF_BUTTON_WRAP_LENGTH, Tk_Offset(TkButton, wrapLengthPtr),
	Tk_Offset(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

static const Tk_OptionSpec buttonOptionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_BUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeBorder),
	DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(TkButton, activeBorder),
	0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
	DEF_BUTTON_ACTIVE_FG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeFg),
	DEF_BUTTON_ACTIVE_FG_COLOR, -1, Tk_Offset(TkButton, activeFg),
	TK_OPTION_NULL_OK, DEF_BUTTON_ACTIVE_FG_MONO, 0},
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	DEF_BUTTON_ANCHOR, TCL_INDEX_NONE, offsetof(TkButton, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_ANCHOR, -1, Tk_Offset(TkButton, anchor), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, normalBorder),
	DEF_BUTTON_BG_COLOR, -1, Tk_Offset(TkButton, normalBorder),
	0, DEF_BUTTON_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
	DEF_BUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkButton, bitmap),
	DEF_BUTTON_BITMAP, -1, Tk_Offset(TkButton, bitmap),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	tkDefButtonBorderWidth, offsetof(TkButton, borderWidthPtr),
	offsetof(TkButton, borderWidth), 0, 0, 0},
	tkDefButtonBorderWidth, Tk_Offset(TkButton, borderWidthPtr),
	Tk_Offset(TkButton, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	DEF_BUTTON_COMMAND, offsetof(TkButton, commandPtr), TCL_INDEX_NONE,
	DEF_BUTTON_COMMAND, Tk_Offset(TkButton, commandPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_BUTTON_COMPOUND, TCL_INDEX_NONE, offsetof(TkButton, compound),
	0, tkCompoundStrings, 0},
	 DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkButton, compound), 0,
	 compoundStrings, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_BUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkButton, cursor),
	DEF_BUTTON_CURSOR, -1, Tk_Offset(TkButton, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-default", "default", "Default",
	DEF_BUTTON_DEFAULT, TCL_INDEX_NONE, offsetof(TkButton, defaultState),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
        DEF_BUTTON_DEFAULT, -1, Tk_Offset(TkButton, defaultState),
	0, defaultStrings, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_BUTTON_DISABLED_FG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, disabledFg), TK_OPTION_NULL_OK,
	DEF_BUTTON_DISABLED_FG_MONO, 0},
	-1, Tk_Offset(TkButton, disabledFg), TK_OPTION_NULL_OK,
	(ClientData) DEF_BUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_BUTTON_FONT, TCL_INDEX_NONE, offsetof(TkButton, tkfont), 0, 0, 0},
	DEF_BUTTON_FONT, -1, Tk_Offset(TkButton, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_BUTTON_FG, TCL_INDEX_NONE, offsetof(TkButton, normalFg), 0, 0, 0},
	DEF_BUTTON_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
    {TK_OPTION_STRING, "-height", "height", "Height",
	DEF_BUTTON_HEIGHT, offsetof(TkButton, heightPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightPtr), -1, 0, 0, 0},
    {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, highlightBorder), 0,
	DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
	-1, Tk_Offset(TkButton, highlightBorder), 0,
	(ClientData) DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_BUTTON_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkButton, highlightColorPtr),
	DEF_BUTTON_HIGHLIGHT, -1, Tk_Offset(TkButton, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", tkDefButtonHighlightWidth,
	offsetof(TkButton, highlightWidthPtr),
	offsetof(TkButton, highlightWidth), 0, 0, 0},
	Tk_Offset(TkButton, highlightWidthPtr),
	Tk_Offset(TkButton, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-image", "image", "Image",
	DEF_BUTTON_IMAGE, offsetof(TkButton, imagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, imagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_BUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkButton, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_JUSTIFY, -1, Tk_Offset(TkButton, justify), 0, 0, 0},
    {TK_OPTION_RELIEF, "-overrelief", "overRelief", "OverRelief",
	 DEF_BUTTON_OVER_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, overRelief),
	 DEF_BUTTON_OVER_RELIEF, -1, Tk_Offset(TkButton, overRelief),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	tkDefButtonPadx, offsetof(TkButton, padXPtr),
	offsetof(TkButton, padX), 0, 0, 0},
	tkDefButtonPadx, Tk_Offset(TkButton, padXPtr),
	Tk_Offset(TkButton, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	tkDefButtonPady, offsetof(TkButton, padYPtr),
	offsetof(TkButton, padY), 0, 0, 0},
	tkDefButtonPady, Tk_Offset(TkButton, padYPtr),
	Tk_Offset(TkButton, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_BUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, relief),
	DEF_BUTTON_RELIEF, -1, Tk_Offset(TkButton, relief),
	 0, 0, 0},
    {TK_OPTION_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
	 DEF_BUTTON_REPEAT_DELAY, TCL_INDEX_NONE, offsetof(TkButton, repeatDelay),
	 DEF_BUTTON_REPEAT_DELAY, -1, Tk_Offset(TkButton, repeatDelay),
	 0, 0, 0},
    {TK_OPTION_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
	 DEF_BUTTON_REPEAT_INTERVAL, TCL_INDEX_NONE, offsetof(TkButton, repeatInterval),
	 DEF_BUTTON_REPEAT_INTERVAL, -1, Tk_Offset(TkButton, repeatInterval),
	 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_BUTTON_STATE, TCL_INDEX_NONE, offsetof(TkButton, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_BUTTON_STATE, -1, Tk_Offset(TkButton, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_BUTTON_TAKE_FOCUS, offsetof(TkButton, takeFocusPtr), TCL_INDEX_NONE,
	DEF_BUTTON_TAKE_FOCUS, Tk_Offset(TkButton, takeFocusPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_BUTTON_TEXT, offsetof(TkButton, textPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_TEXT, Tk_Offset(TkButton, textPtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_BUTTON_TEXT_VARIABLE, offsetof(TkButton, textVarNamePtr), TCL_INDEX_NONE,
	DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(TkButton, textVarNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TK_OPTION_UNDERLINE_DEF(TkButton, underline), 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	DEF_BUTTON_UNDERLINE, -1, Tk_Offset(TkButton, underline), 0, 0, 0},
    {TK_OPTION_STRING, "-width", "width", "Width",
	DEF_BUTTON_WIDTH, offsetof(TkButton, widthPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_WIDTH, Tk_Offset(TkButton, widthPtr), -1, 0, 0, 0},
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	DEF_BUTTON_WRAP_LENGTH, offsetof(TkButton, wrapLengthPtr),
	offsetof(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
	DEF_BUTTON_WRAP_LENGTH, Tk_Offset(TkButton, wrapLengthPtr),
	Tk_Offset(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

static const Tk_OptionSpec checkbuttonOptionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_BUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeBorder),
	DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(TkButton, activeBorder),
	0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
	DEF_CHKRAD_ACTIVE_FG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeFg),
	DEF_CHKRAD_ACTIVE_FG_COLOR, -1, Tk_Offset(TkButton, activeFg),
	TK_OPTION_NULL_OK, DEF_BUTTON_ACTIVE_FG_MONO, 0},
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	DEF_BUTTON_ANCHOR, TCL_INDEX_NONE, offsetof(TkButton, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_ANCHOR, -1, Tk_Offset(TkButton, anchor), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, normalBorder),
	DEF_BUTTON_BG_COLOR, -1, Tk_Offset(TkButton, normalBorder),
	0, DEF_BUTTON_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
	DEF_BUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkButton, bitmap),
	DEF_BUTTON_BITMAP, -1, Tk_Offset(TkButton, bitmap),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	tkDefButtonBorderWidth, offsetof(TkButton, borderWidthPtr),
	offsetof(TkButton, borderWidth), 0, 0, 0},
	tkDefButtonBorderWidth, Tk_Offset(TkButton, borderWidthPtr),
	Tk_Offset(TkButton, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	DEF_BUTTON_COMMAND, offsetof(TkButton, commandPtr), TCL_INDEX_NONE,
	DEF_BUTTON_COMMAND, Tk_Offset(TkButton, commandPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_BUTTON_COMPOUND, TCL_INDEX_NONE, offsetof(TkButton, compound),
	0, tkCompoundStrings, 0},
	 DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkButton, compound), 0,
	 compoundStrings, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_BUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkButton, cursor),
	DEF_BUTTON_CURSOR, -1, Tk_Offset(TkButton, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_BUTTON_DISABLED_FG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, disabledFg), TK_OPTION_NULL_OK,
	DEF_BUTTON_DISABLED_FG_MONO, 0},
	-1, Tk_Offset(TkButton, disabledFg), TK_OPTION_NULL_OK,
	(ClientData) DEF_BUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_BUTTON_FONT, TCL_INDEX_NONE, offsetof(TkButton, tkfont), 0, 0, 0},
	DEF_BUTTON_FONT, -1, Tk_Offset(TkButton, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_CHKRAD_FG, TCL_INDEX_NONE, offsetof(TkButton, normalFg), 0, 0, 0},
	DEF_CHKRAD_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
    {TK_OPTION_STRING, "-height", "height", "Height",
	DEF_BUTTON_HEIGHT, offsetof(TkButton, heightPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightPtr), -1, 0, 0, 0},
    {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, highlightBorder), 0,
	DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
	-1, Tk_Offset(TkButton, highlightBorder), 0,
	(ClientData) DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_BUTTON_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkButton, highlightColorPtr),
	DEF_BUTTON_HIGHLIGHT, -1, Tk_Offset(TkButton, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", tkDefButtonHighlightWidth,
	offsetof(TkButton, highlightWidthPtr),
	offsetof(TkButton, highlightWidth), 0, 0, 0},
	Tk_Offset(TkButton, highlightWidthPtr),
	Tk_Offset(TkButton, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-image", "image", "Image",
	DEF_BUTTON_IMAGE, offsetof(TkButton, imagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, imagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn",
	DEF_BUTTON_INDICATOR, TCL_INDEX_NONE, offsetof(TkButton, indicatorOn), 0, 0, 0},
	DEF_BUTTON_INDICATOR, -1, Tk_Offset(TkButton, indicatorOn), 0, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_BUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkButton, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_JUSTIFY, -1, Tk_Offset(TkButton, justify), 0, 0, 0},
    {TK_OPTION_RELIEF, "-offrelief", "offRelief", "OffRelief",
	DEF_BUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, offRelief), 0, 0, 0},
	 DEF_BUTTON_RELIEF, -1, Tk_Offset(TkButton, offRelief), 0, 0, 0},
    {TK_OPTION_STRING, "-offvalue", "offValue", "Value",
	DEF_BUTTON_OFF_VALUE, offsetof(TkButton, offValuePtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_OFF_VALUE, Tk_Offset(TkButton, offValuePtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-onvalue", "onValue", "Value",
	DEF_BUTTON_ON_VALUE, offsetof(TkButton, onValuePtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_ON_VALUE, Tk_Offset(TkButton, onValuePtr), -1, 0, 0, 0},
    {TK_OPTION_RELIEF, "-overrelief", "overRelief", "OverRelief",
	DEF_BUTTON_OVER_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, overRelief),
	TK_OPTION_NULL_OK, 0, 0},
	 DEF_BUTTON_OVER_RELIEF, -1, Tk_Offset(TkButton, overRelief),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	tkDefLabelPadx, offsetof(TkButton, padXPtr),
	offsetof(TkButton, padX), 0, 0, 0},
	tkDefLabelPadx, Tk_Offset(TkButton, padXPtr),
	Tk_Offset(TkButton, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	tkDefLabelPady, offsetof(TkButton, padYPtr),
	offsetof(TkButton, padY), 0, 0, 0},
	tkDefLabelPady, Tk_Offset(TkButton, padYPtr),
	Tk_Offset(TkButton, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_LABCHKRAD_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, relief), 0, 0, 0},
	DEF_LABCHKRAD_RELIEF, -1, Tk_Offset(TkButton, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-selectcolor", "selectColor", "Background",
	DEF_BUTTON_SELECT_COLOR, TCL_INDEX_NONE, offsetof(TkButton, selectBorder),
	DEF_BUTTON_SELECT_COLOR, -1, Tk_Offset(TkButton, selectBorder),
	TK_OPTION_NULL_OK, DEF_BUTTON_SELECT_MONO, 0},
    {TK_OPTION_STRING, "-selectimage", "selectImage", "SelectImage",
	DEF_BUTTON_SELECT_IMAGE, offsetof(TkButton, selectImagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_SELECT_IMAGE, Tk_Offset(TkButton, selectImagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_BUTTON_STATE, TCL_INDEX_NONE, offsetof(TkButton, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_BUTTON_STATE, -1, Tk_Offset(TkButton, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_BUTTON_TAKE_FOCUS, offsetof(TkButton, takeFocusPtr), TCL_INDEX_NONE,
	DEF_BUTTON_TAKE_FOCUS, Tk_Offset(TkButton, takeFocusPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_BUTTON_TEXT, offsetof(TkButton, textPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_TEXT, Tk_Offset(TkButton, textPtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_BUTTON_TEXT_VARIABLE, offsetof(TkButton, textVarNamePtr), TCL_INDEX_NONE,
	DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(TkButton, textVarNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-tristateimage", "tristateImage", "TristateImage",
	DEF_BUTTON_IMAGE, offsetof(TkButton, tristateImagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, tristateImagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-tristatevalue", "tristateValue", "TristateValue",
	DEF_BUTTON_TRISTATE_VALUE, offsetof(TkButton, tristateValuePtr), TCL_INDEX_NONE, 0, 0, 0},
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TK_OPTION_UNDERLINE_DEF(TkButton, underline), 0},
	DEF_BUTTON_TRISTATE_VALUE, Tk_Offset(TkButton, tristateValuePtr), -1, 0, 0, 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	DEF_BUTTON_UNDERLINE, -1, Tk_Offset(TkButton, underline), 0, 0, 0},
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	DEF_CHECKBUTTON_VARIABLE, offsetof(TkButton, selVarNamePtr), TCL_INDEX_NONE,
	DEF_CHECKBUTTON_VARIABLE, Tk_Offset(TkButton, selVarNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-width", "width", "Width",
	DEF_BUTTON_WIDTH, offsetof(TkButton, widthPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_WIDTH, Tk_Offset(TkButton, widthPtr), -1, 0, 0, 0},
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	DEF_BUTTON_WRAP_LENGTH, offsetof(TkButton, wrapLengthPtr),
	offsetof(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
	DEF_BUTTON_WRAP_LENGTH, Tk_Offset(TkButton, wrapLengthPtr),
	Tk_Offset(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

static const Tk_OptionSpec radiobuttonOptionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_BUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeBorder),
	DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(TkButton, activeBorder),
	0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
	DEF_CHKRAD_ACTIVE_FG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, activeFg),
	DEF_CHKRAD_ACTIVE_FG_COLOR, -1, Tk_Offset(TkButton, activeFg),
	TK_OPTION_NULL_OK, DEF_BUTTON_ACTIVE_FG_MONO, 0},
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	DEF_BUTTON_ANCHOR, TCL_INDEX_NONE, offsetof(TkButton, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_ANCHOR, -1, Tk_Offset(TkButton, anchor), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(TkButton, normalBorder),
	DEF_BUTTON_BG_COLOR, -1, Tk_Offset(TkButton, normalBorder),
	0, DEF_BUTTON_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
	DEF_BUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkButton, bitmap),
	DEF_BUTTON_BITMAP, -1, Tk_Offset(TkButton, bitmap),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	tkDefButtonBorderWidth, offsetof(TkButton, borderWidthPtr),
	offsetof(TkButton, borderWidth), 0, 0, 0},
	tkDefButtonBorderWidth, Tk_Offset(TkButton, borderWidthPtr),
	Tk_Offset(TkButton, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	DEF_BUTTON_COMMAND, offsetof(TkButton, commandPtr), TCL_INDEX_NONE,
	DEF_BUTTON_COMMAND, Tk_Offset(TkButton, commandPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_BUTTON_COMPOUND, TCL_INDEX_NONE, offsetof(TkButton, compound),
	0, tkCompoundStrings, 0},
	 DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkButton, compound), 0,
	 compoundStrings, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_BUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkButton, cursor),
	DEF_BUTTON_CURSOR, -1, Tk_Offset(TkButton, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_BUTTON_DISABLED_FG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, disabledFg), TK_OPTION_NULL_OK,
	DEF_BUTTON_DISABLED_FG_MONO, 0},
	-1, Tk_Offset(TkButton, disabledFg), TK_OPTION_NULL_OK,
	(ClientData) DEF_BUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_BUTTON_FONT, TCL_INDEX_NONE, offsetof(TkButton, tkfont), 0, 0, 0},
	DEF_BUTTON_FONT, -1, Tk_Offset(TkButton, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_CHKRAD_FG, TCL_INDEX_NONE, offsetof(TkButton, normalFg), 0, 0, 0},
	DEF_CHKRAD_FG, -1, Tk_Offset(TkButton, normalFg), 0, 0, 0},
    {TK_OPTION_STRING, "-height", "height", "Height",
	DEF_BUTTON_HEIGHT, offsetof(TkButton, heightPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_HEIGHT, Tk_Offset(TkButton, heightPtr), -1, 0, 0, 0},
    {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_BUTTON_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkButton, highlightBorder), 0,
	DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
	-1, Tk_Offset(TkButton, highlightBorder), 0,
	(ClientData) DEF_BUTTON_HIGHLIGHT_BG_MONO, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_BUTTON_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkButton, highlightColorPtr),
	DEF_BUTTON_HIGHLIGHT, -1, Tk_Offset(TkButton, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", tkDefButtonHighlightWidth,
	offsetof(TkButton, highlightWidthPtr),
	offsetof(TkButton, highlightWidth), 0, 0, 0},
	Tk_Offset(TkButton, highlightWidthPtr),
	Tk_Offset(TkButton, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-image", "image", "Image",
	DEF_BUTTON_IMAGE, offsetof(TkButton, imagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, imagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn",
	DEF_BUTTON_INDICATOR, TCL_INDEX_NONE, offsetof(TkButton, indicatorOn),
	DEF_BUTTON_INDICATOR, -1, Tk_Offset(TkButton, indicatorOn),
	0, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_BUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkButton, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_BUTTON_JUSTIFY, -1, Tk_Offset(TkButton, justify), 0, 0, 0},
    {TK_OPTION_RELIEF, "-offrelief", "offRelief", "OffRelief",
	 DEF_BUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, offRelief), 0, 0, 0},
	 DEF_BUTTON_RELIEF, -1, Tk_Offset(TkButton, offRelief), 0, 0, 0},
    {TK_OPTION_RELIEF, "-overrelief", "overRelief", "OverRelief",
	 DEF_BUTTON_OVER_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, overRelief),
	 DEF_BUTTON_OVER_RELIEF, -1, Tk_Offset(TkButton, overRelief),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	tkDefLabelPadx, offsetof(TkButton, padXPtr),
	offsetof(TkButton, padX), 0, 0, 0},
	tkDefLabelPadx, Tk_Offset(TkButton, padXPtr),
	Tk_Offset(TkButton, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	tkDefLabelPady, offsetof(TkButton, padYPtr),
	offsetof(TkButton, padY), 0, 0, 0},
	tkDefLabelPady, Tk_Offset(TkButton, padYPtr),
	Tk_Offset(TkButton, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_LABCHKRAD_RELIEF, TCL_INDEX_NONE, offsetof(TkButton, relief), 0, 0, 0},
	DEF_LABCHKRAD_RELIEF, -1, Tk_Offset(TkButton, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-selectcolor", "selectColor", "Background",
	DEF_BUTTON_SELECT_COLOR, TCL_INDEX_NONE, offsetof(TkButton, selectBorder),
	DEF_BUTTON_SELECT_COLOR, -1, Tk_Offset(TkButton, selectBorder),
	TK_OPTION_NULL_OK, DEF_BUTTON_SELECT_MONO, 0},
    {TK_OPTION_STRING, "-selectimage", "selectImage", "SelectImage",
	DEF_BUTTON_SELECT_IMAGE, offsetof(TkButton, selectImagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_SELECT_IMAGE, Tk_Offset(TkButton, selectImagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_BUTTON_STATE, TCL_INDEX_NONE, offsetof(TkButton, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_BUTTON_STATE, -1, Tk_Offset(TkButton, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_BUTTON_TAKE_FOCUS, offsetof(TkButton, takeFocusPtr), TCL_INDEX_NONE,
	DEF_BUTTON_TAKE_FOCUS, Tk_Offset(TkButton, takeFocusPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_BUTTON_TEXT, offsetof(TkButton, textPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_TEXT, Tk_Offset(TkButton, textPtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_BUTTON_TEXT_VARIABLE, offsetof(TkButton, textVarNamePtr), TCL_INDEX_NONE,
	DEF_BUTTON_TEXT_VARIABLE, Tk_Offset(TkButton, textVarNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-tristateimage", "tristateImage", "TristateImage",
	DEF_BUTTON_IMAGE, offsetof(TkButton, tristateImagePtr), TCL_INDEX_NONE,
	DEF_BUTTON_IMAGE, Tk_Offset(TkButton, tristateImagePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-tristatevalue", "tristateValue", "TristateValue",
	DEF_BUTTON_TRISTATE_VALUE, offsetof(TkButton, tristateValuePtr), TCL_INDEX_NONE, 0, 0, 0},
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TK_OPTION_UNDERLINE_DEF(TkButton, underline), 0},
	DEF_BUTTON_TRISTATE_VALUE, Tk_Offset(TkButton, tristateValuePtr), -1, 0, 0, 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	DEF_BUTTON_UNDERLINE, -1, Tk_Offset(TkButton, underline), 0, 0, 0},
    {TK_OPTION_STRING, "-value", "value", "Value",
	DEF_BUTTON_VALUE, offsetof(TkButton, onValuePtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_VALUE, Tk_Offset(TkButton, onValuePtr), -1, 0, 0, 0},
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	DEF_RADIOBUTTON_VARIABLE, offsetof(TkButton, selVarNamePtr), TCL_INDEX_NONE,
	DEF_RADIOBUTTON_VARIABLE, Tk_Offset(TkButton, selVarNamePtr), -1,
	0, 0, 0},
    {TK_OPTION_STRING, "-width", "width", "Width",
	DEF_BUTTON_WIDTH, offsetof(TkButton, widthPtr), TCL_INDEX_NONE, 0, 0, 0},
	DEF_BUTTON_WIDTH, Tk_Offset(TkButton, widthPtr), -1, 0, 0, 0},
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	DEF_BUTTON_WRAP_LENGTH, offsetof(TkButton, wrapLengthPtr),
	offsetof(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
	DEF_BUTTON_WRAP_LENGTH, Tk_Offset(TkButton, wrapLengthPtr),
	Tk_Offset(TkButton, wrapLength), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * The following table maps from one of the type values defined in tkButton.h,
 * such as TYPE_LABEL, to the option template for that class of widgets.
 */

508
509
510
511
512
513
514
515
516
517



518
519

520
521

522
523
524

525
526
527

528
529
530

531
532
533

534
535
536



537
538

539
540
541
542
543
544
545
517
518
519
520
521
522
523



524
525
526
527

528
529

530
531
532

533
534
535

536
537
538

539
540
541

542
543
544

545
546
547
548

549
550
551
552
553
554
555
556







-
-
-
+
+
+

-
+

-
+


-
+


-
+


-
+


-
+


-
+
+
+

-
+







	    COMMAND_INVOKE, COMMAND_SELECT}
};

/*
 * Forward declarations for functions defined later in this file:
 */

static void		ButtonCmdDeletedProc(void *clientData);
static int		ButtonCreate(void *clientData,
			    Tcl_Interp *interp, Tcl_Size objc,
static void		ButtonCmdDeletedProc(ClientData clientData);
static int		ButtonCreate(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[], int type);
static void		ButtonEventProc(void *clientData,
static void		ButtonEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		ButtonImageProc(void *clientData,
static void		ButtonImageProc(ClientData clientData,
			    int x, int y, int width, int height,
			    int imgWidth, int imgHeight);
static void		ButtonSelectImageProc(void *clientData,
static void		ButtonSelectImageProc(ClientData clientData,
			    int x, int y, int width, int height,
			    int imgWidth, int imgHeight);
static void		ButtonTristateImageProc(void *clientData,
static void		ButtonTristateImageProc(ClientData clientData,
			    int x, int y, int width, int height,
			    int imgWidth, int imgHeight);
static char *		ButtonTextVarProc(void *clientData,
static char *		ButtonTextVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static char *		ButtonVarProc(void *clientData,
static char *		ButtonVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static Tcl_ObjCmdProc ButtonWidgetObjCmd;
static int		ButtonWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		ConfigureButton(Tcl_Interp *interp, TkButton *butPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DestroyButton(TkButton *butPtr);

/*
 *--------------------------------------------------------------
 *
 * Tk_ButtonCmd, Tk_CheckbuttonCmd, Tk_LabelCmd, Tk_RadiobuttonCmd --
 *
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610







-
+









-
+









-
+









-
+







 *	call ButtonCreate to do all of the real work.
 *
 *--------------------------------------------------------------
 */

int
Tk_ButtonObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    return ButtonCreate(clientData, interp, objc, objv, TYPE_BUTTON);
}

int
Tk_CheckbuttonObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    return ButtonCreate(clientData, interp, objc, objv, TYPE_CHECK_BUTTON);
}

int
Tk_LabelObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    return ButtonCreate(clientData, interp, objc, objv, TYPE_LABEL);
}

int
Tk_RadiobuttonObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    return ButtonCreate(clientData, interp, objc, objv, TYPE_RADIO_BUTTON);
}

613
614
615
616
617
618
619
620

621
622

623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
624
625
626
627
628
629
630

631
632

633
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649







-
+

-
+








-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
ButtonCreate(
    TCL_UNUSED(void *),	/* NULL. */
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument values. */
    int type)			/* Type of button to create: TYPE_LABEL,
				 * TYPE_BUTTON, TYPE_CHECK_BUTTON, or
				 * TYPE_RADIO_BUTTON. */
{
    TkButton *butPtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->defaultsInitialized) {
	TkpButtonSetDefaults();
	tsdPtr->defaultsInitialized = 1;
    }

671
672
673
674
675
676
677
678

679
680
681
682
683
684
685
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696







-
+







    butPtr->display = Tk_Display(tkwin);
    butPtr->interp = interp;
    butPtr->widgetCmd = Tcl_CreateObjCommand(interp, Tk_PathName(tkwin),
	    ButtonWidgetObjCmd, butPtr, ButtonCmdDeletedProc);
    butPtr->type = type;
    butPtr->optionTable = optionTable;
    butPtr->textPtr = NULL;
    butPtr->underline = INT_MIN;
    butPtr->underline = -1;
    butPtr->textVarNamePtr = NULL;
    butPtr->bitmap = None;
    butPtr->imagePtr = NULL;
    butPtr->image = NULL;
    butPtr->selectImagePtr = NULL;
    butPtr->selectImage = NULL;
    butPtr->tristateImagePtr = NULL;
695
696
697
698
699
700
701
702
703
704
705




706
707

708
709
710
711
712
713
714
706
707
708
709
710
711
712




713
714
715
716
717

718
719
720
721
722
723
724
725







-
-
-
-
+
+
+
+

-
+







    butPtr->highlightBorder = NULL;
    butPtr->highlightColorPtr = NULL;
    butPtr->inset = 0;
    butPtr->tkfont = NULL;
    butPtr->normalFg = NULL;
    butPtr->activeFg = NULL;
    butPtr->disabledFg = NULL;
    butPtr->normalTextGC = NULL;
    butPtr->activeTextGC = NULL;
    butPtr->disabledGC = NULL;
    butPtr->stippleGC = NULL;
    butPtr->normalTextGC = None;
    butPtr->activeTextGC = None;
    butPtr->disabledGC = None;
    butPtr->stippleGC = None;
    butPtr->gray = None;
    butPtr->copyGC = NULL;
    butPtr->copyGC = None;
    butPtr->widthPtr = NULL;
    butPtr->width = 0;
    butPtr->heightPtr = NULL;
    butPtr->height = 0;
    butPtr->wrapLengthPtr = NULL;
    butPtr->wrapLength = 0;
    butPtr->padXPtr = NULL;
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
736
737
738
739
740
741
742

743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769







-
+








-
+









-
+







    butPtr->indicatorSpace = 0;
    butPtr->indicatorDiameter = 0;
    butPtr->defaultState = DEFAULT_DISABLED;
    butPtr->selVarNamePtr = NULL;
    butPtr->onValuePtr = NULL;
    butPtr->offValuePtr = NULL;
    butPtr->tristateValuePtr = NULL;
    butPtr->cursor = NULL;
    butPtr->cursor = None;
    butPtr->takeFocusPtr = NULL;
    butPtr->commandPtr = NULL;
    butPtr->flags = 0;

    Tk_CreateEventHandler(butPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    ButtonEventProc, butPtr);

    if (Tk_InitOptions(interp, butPtr, optionTable, tkwin)
    if (Tk_InitOptions(interp, (char *) butPtr, optionTable, tkwin)
	    != TCL_OK) {
	Tk_DestroyWindow(butPtr->tkwin);
	return TCL_ERROR;
    }
    if (ConfigureButton(interp, butPtr, objc - 2, objv + 2) != TCL_OK) {
	Tk_DestroyWindow(butPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(butPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(butPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * ButtonWidgetCmd --
768
769
770
771
772
773
774
775

776
777
778
779
780

781
782
783
784
785
786
787
779
780
781
782
783
784
785

786
787
788
789
790

791
792
793
794
795
796
797
798







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
ButtonWidgetObjCmd(
    void *clientData,	/* Information about button widget. */
    ClientData clientData,	/* Information about button widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    TkButton *butPtr = (TkButton *)clientData;
    TkButton *butPtr = clientData;
    int index;
    int result;
    Tcl_Obj *objPtr;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
795
796
797
798
799
800
801
802

803
804
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
806
807
808
809
810
811
812

813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830







-
+









-
+








    switch (map[butPtr->type][index]) {
    case COMMAND_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "cget option");
	    goto error;
	}
	objPtr = Tk_GetOptionValue(interp, butPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) butPtr,
		butPtr->optionTable, objv[2], butPtr->tkwin);
	if (objPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;

    case COMMAND_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, butPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) butPtr,
		    butPtr->optionTable, (objc == 3) ? objv[2] : NULL,
		    butPtr->tkwin);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
863
864
865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880
881
882
883
884
874
875
876
877
878
879
880

881





882

883
884
885
886
887
888
889







-
+
-
-
-
-
-

-







		/*
		 * Special note: must cancel any existing idle handler for
		 * TkpDisplayButton; it's no longer needed, and
		 * TkpDisplayButton cleared the REDRAW_PENDING flag.
		 */

		Tcl_CancelIdleCall(TkpDisplayButton, butPtr);
		(void)XFlush(butPtr->display);
		XFlush(butPtr->display);
		#ifndef MAC_OSX_TK
		/*
		 * On the mac you can not sleep in a display proc, and the
		 * flash command doesn't do anything anyway.
		 */
		Tcl_Sleep(50);
		#endif
	    }
	}
	break;

    case COMMAND_INVOKE:
	if (objc > 2) {
	    Tcl_WrongNumArgs(interp, 1, objv, "invoke");
966
967
968
969
970
971
972
973

974
975
976

977
978
979

980
981
982

983
984
985
986
987
988

989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
971
972
973
974
975
976
977

978
979
980

981
982
983

984
985
986

987
988
989
990
991
992

993
994
995
996
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
1011







-
+


-
+


-
+


-
+





-
+










-
+







    }
    if (butPtr->selectImage != NULL) {
	Tk_FreeImage(butPtr->selectImage);
    }
    if (butPtr->tristateImage != NULL) {
	Tk_FreeImage(butPtr->tristateImage);
    }
    if (butPtr->normalTextGC != NULL) {
    if (butPtr->normalTextGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->normalTextGC);
    }
    if (butPtr->activeTextGC != NULL) {
    if (butPtr->activeTextGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->activeTextGC);
    }
    if (butPtr->disabledGC != NULL) {
    if (butPtr->disabledGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->disabledGC);
    }
    if (butPtr->stippleGC != NULL) {
    if (butPtr->stippleGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->stippleGC);
    }
    if (butPtr->gray != None) {
	Tk_FreeBitmap(butPtr->display, butPtr->gray);
    }
    if (butPtr->copyGC != NULL) {
    if (butPtr->copyGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->copyGC);
    }
    if (butPtr->textLayout != NULL) {
	Tk_FreeTextLayout(butPtr->textLayout);
    }
    if (butPtr->selVarNamePtr != NULL) {
	Tcl_UntraceVar2(butPtr->interp, Tcl_GetString(butPtr->selVarNamePtr),
		NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		ButtonVarProc, butPtr);
    }
    Tk_FreeConfigOptions(butPtr, butPtr->optionTable,
    Tk_FreeConfigOptions((char *) butPtr, butPtr->optionTable,
	    butPtr->tkwin);
    butPtr->tkwin = NULL;
    Tcl_EventuallyFree(butPtr, TCL_DYNAMIC);
}

/*
 *----------------------------------------------------------------------
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030

1031
1032
1033
1034
1035
1036
1037
1026
1027
1028
1029
1030
1031
1032

1033
1034

1035
1036
1037
1038
1039
1040
1041
1042







-
+

-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureButton(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkButton *butPtr,	/* Information about widget;  may or may
    register TkButton *butPtr,	/* Information about widget;  may or may
				 * not already have values for some fields. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    Tk_SavedOptions savedOptions;
    Tcl_Obj *errorResult = NULL;
    int error, haveImage;
    Tk_Image image;

1059
1060
1061
1062
1063
1064
1065
1066

1067
1068
1069
1070
1071
1072
1073
1064
1065
1066
1067
1068
1069
1070

1071
1072
1073
1074
1075
1076
1077
1078







-
+








    for (error = 0; error <= 1; error++) {
	if (!error) {
	    /*
	     * First pass: set options to new values.
	     */

	    if (Tk_SetOptions(interp, butPtr,
	    if (Tk_SetOptions(interp, (char *) butPtr,
		    butPtr->optionTable, objc, objv,
		    butPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
		continue;
	    }
	} else {
	    /*
	     * Second pass: restore options to old values.
1111
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130







-
+







	}

	if (butPtr->type >= TYPE_CHECK_BUTTON) {
	    Tcl_Obj *valuePtr, *namePtr;

	    if (butPtr->selVarNamePtr == NULL) {
		butPtr->selVarNamePtr = Tcl_NewStringObj(
			Tk_Name(butPtr->tkwin), TCL_INDEX_NONE);
			Tk_Name(butPtr->tkwin), -1);
		Tcl_IncrRefCount(butPtr->selVarNamePtr);
	    }
	    namePtr = butPtr->selVarNamePtr;

	    /*
	     * Select the button if the associated variable has the
	     * appropriate value, initialize the variable if it doesn't exist,
1160
1161
1162
1163
1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179







-
+








		/*
		 * If a radiobutton has the empty string as value it should be
		 * selected.
		 */

 		if ((butPtr->type == TYPE_RADIO_BUTTON) &&
			(*Tcl_GetString(butPtr->onValuePtr) == '\0')) {
			(*Tcl_GetString(butPtr->onValuePtr) == 0)) {
		    butPtr->flags |= SELECTED;
		}
	    }
	}

	/*
	 * Get the images for the widget, if there are any. Allocate the new
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359

1360
1361
1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388
1333
1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363

1364
1365
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392
1393







-
+




-
+


















-
+









-
+











-
+







 *      Button will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

void
TkButtonWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC newGC;
    unsigned long mask;
    TkButton *butPtr = (TkButton *)instanceData;
    TkButton *butPtr = instanceData;

    /*
     * Recompute GCs.
     */

    gcValues.font = Tk_FontId(butPtr->tkfont);
    gcValues.foreground = butPtr->normalFg->pixel;
    gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel;

    /*
     * Note: GraphicsExpose events are disabled in normalTextGC because it's
     * used to copy stuff from an off-screen pixmap onto the screen (we know
     * that there's no problem with obscured areas).
     */

    gcValues.graphics_exposures = False;
    mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
    newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);
    if (butPtr->normalTextGC != NULL) {
    if (butPtr->normalTextGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->normalTextGC);
    }
    butPtr->normalTextGC = newGC;

    if (butPtr->activeFg != NULL) {
	gcValues.foreground = butPtr->activeFg->pixel;
	gcValues.background = Tk_3DBorderColor(butPtr->activeBorder)->pixel;
	mask = GCForeground | GCBackground | GCFont;
	newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);
	if (butPtr->activeTextGC != NULL) {
	if (butPtr->activeTextGC != None) {
	    Tk_FreeGC(butPtr->display, butPtr->activeTextGC);
	}
	butPtr->activeTextGC = newGC;
    }

    gcValues.background = Tk_3DBorderColor(butPtr->normalBorder)->pixel;

    /*
     * Create the GC that can be used for stippling
     */

    if (butPtr->stippleGC == NULL) {
    if (butPtr->stippleGC == None) {
	gcValues.foreground = gcValues.background;
	mask = GCForeground;
	if (butPtr->gray == None) {
	    butPtr->gray = Tk_GetBitmap(NULL, butPtr->tkwin, "gray50");
	}
	if (butPtr->gray != None) {
	    gcValues.fill_style = FillStippled;
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416

1417
1418
1419
1420
1421
1422
1423
1424







-
+




-
+







    mask = GCForeground | GCBackground | GCFont;
    if (butPtr->disabledFg != NULL) {
	gcValues.foreground = butPtr->disabledFg->pixel;
    } else {
	gcValues.foreground = gcValues.background;
    }
    newGC = Tk_GetGC(butPtr->tkwin, mask, &gcValues);
    if (butPtr->disabledGC != NULL) {
    if (butPtr->disabledGC != None) {
	Tk_FreeGC(butPtr->display, butPtr->disabledGC);
    }
    butPtr->disabledGC = newGC;

    if (butPtr->copyGC == NULL) {
    if (butPtr->copyGC == None) {
	butPtr->copyGC = Tk_GetGC(butPtr->tkwin, 0, &gcValues);
    }

    TkpComputeButtonGeometry(butPtr);

    /*
     * Lastly, arrange for the button to be redisplayed.
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463







-
+


-
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ButtonEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkButton *butPtr = (TkButton *)clientData;
    TkButton *butPtr = clientData;
    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	goto redraw;
    } else if (eventPtr->type == ConfigureNotify) {
	/*
	 * Must redraw after size changes, since layout could have changed and
	 * borders will need to be redrawn.
	 */
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509

1510
1511
1512
1513
1514
1515
1516
1505
1506
1507
1508
1509
1510
1511

1512
1513

1514
1515
1516
1517
1518
1519
1520
1521







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
ButtonCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkButton *butPtr = (TkButton *)clientData;
    TkButton *butPtr = clientData;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted or because the command was deleted,
     * and then this function destroys the widget. The BUTTON_DELETED flag
     * distinguishes these cases.
     */
1588
1589
1590
1591
1592
1593
1594

1595
1596
1597

1598
1599
1600


1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602

1603
1604


1605
1606
1607
1608

1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619



1620


















1621
1622
1623
1624
1625
1626
1627







+


-
+

-
-
+
+


-
+










-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *
 * Side effects:
 *	The button may become selected or deselected.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static char *
ButtonVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),	/* Name of variable. */
    TCL_UNUSED(const char *),	/* Second part of variable name. */
    const char *name1,		/* Name of variable. */
    const char *name2,		/* Second part of variable name. */
    int flags)			/* Information about what happened. */
{
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = clientData;
    const char *value;
    Tcl_Obj *valuePtr;

    /*
     * If the variable is being unset, then just re-establish the trace unless
     * the whole interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
	butPtr->flags &= ~(SELECTED | TRISTATED);
	if (!Tcl_InterpDeleted(interp)) {
	    void *probe = NULL;

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
	    do {
		probe = Tcl_VarTraceInfo(interp,
			Tcl_GetString(butPtr->selVarNamePtr),
			TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
			ButtonVarProc, probe);
		if (probe == (void *)butPtr) {
		    break;
		}
	    } while (probe);
	    if (probe) {
		/*
		 * We were able to fetch the unset trace for our
		 * selVarNamePtr, which means it is not unset and not
		 * the cause of this unset trace. Instead some outdated
		 * former variable must be, and we should ignore it.
		 */
		goto redisplay;
	    }
	    Tcl_TraceVar2(interp, Tcl_GetString(butPtr->selVarNamePtr),
		    NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    ButtonVarProc, clientData);
	}
	goto redisplay;
    }

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
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







+


-
+





-
+

-
-











-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *
 * Side effects:
 *	The text displayed in the button will change to match the variable.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static char *
ButtonTextVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    const char *name1,		/* Not used. */
    const char *name2,		/* Not used. */
    int flags)			/* Information about what happened. */
{
    TkButton *butPtr = (TkButton *)clientData;
    TkButton *butPtr = clientData;
    Tcl_Obj *valuePtr;
    (void)name1;
    (void)name2;

    if (butPtr->flags & BUTTON_DELETED) {
	return NULL;
    }

    /*
     * If the variable is unset, then immediately recreate it unless the whole
     * interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
	if (!Tcl_InterpDeleted(interp) && butPtr->textVarNamePtr != NULL) {

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
	    /*
	     * An unset trace on some variable brought us here, but is it
	     * the variable we have stored in butPtr->textVarNamePtr ?
	     */

	    void *probe = NULL;

	    do {
		probe = Tcl_VarTraceInfo(interp,
			Tcl_GetString(butPtr->textVarNamePtr),
			TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
			ButtonTextVarProc, probe);
		if (probe == (void *)butPtr) {
		    break;
		}
	    } while (probe);
	    if (probe) {
		/*
		 * We were able to fetch the unset trace for our
		 * textVarNamePtr, which means it is not unset and not
		 * the cause of this unset trace. Instead some outdated
		 * former textvariable must be, and we should ignore it.
		 */
		return NULL;
	    }

	    Tcl_ObjSetVar2(interp, butPtr->textVarNamePtr, NULL,
		    butPtr->textPtr, TCL_GLOBAL_ONLY);
	    Tcl_TraceVar2(interp, Tcl_GetString(butPtr->textVarNamePtr),
		    NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    ButtonTextVarProc, clientData);
	}
	return NULL;
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
1753
1754
1755
1756
1757
1758
1759

1760
1761
1762
1763
1764
1765
1766

1767






1768
1769
1770
1771
1772
1773
1774







-
+






-
+
-
-
-
-
-
-







 *	Arranges for the button to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
ButtonImageProc(
    void *clientData,	/* Pointer to widget record. */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (might be
				 * <= 0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = clientData;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
    (void)imgWidth;
    (void)imgHeight;

    if (butPtr->tkwin != NULL) {
	TkpComputeButtonGeometry(butPtr);
	if (Tk_IsMapped(butPtr->tkwin) && !(butPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(TkpDisplayButton, butPtr);
	    butPtr->flags |= REDRAW_PENDING;
	}
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
1791
1792
1793
1794
1795
1796
1797

1798
1799
1800
1801
1802
1803
1804

1805






1806
1807
1808
1809
1810
1811
1812







-
+






-
+
-
-
-
-
-
-







 *	May arrange for the button to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
ButtonSelectImageProc(
    void *clientData,	/* Pointer to widget record. */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (might be
				 * <= 0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = clientData;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
    (void)imgWidth;
    (void)imgHeight;

#ifdef MAC_OSX_TK
    if (butPtr->tkwin != NULL) {
	TkpComputeButtonGeometry(butPtr);
    }
#else
    /*
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
1838
1839
1840
1841
1842
1843
1844

1845
1846
1847
1848
1849
1850
1851

1852






1853
1854
1855
1856
1857
1858
1859







-
+






-
+
-
-
-
-
-
-







 *	May arrange for the button to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
ButtonTristateImageProc(
    void *clientData,	/* Pointer to widget record. */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (might be
				 * <= 0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = clientData;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
    (void)imgWidth;
    (void)imgHeight;

#ifdef MAC_OSX_TK
    if (butPtr->tkwin != NULL) {
	TkpComputeButtonGeometry(butPtr);
    }
#else
    /*

Changes to generic/tkButton.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkButton.h --
 *
 *	Declarations of types and functions used to implement button-like
 *	widgets.
 *
 * Copyright © 1996-1998 Sun Microsystems, Inc.
 * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKBUTTON
#define _TKBUTTON
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







    /*
     * Information about what's in the button.
     */

    Tcl_Obj *textPtr;		/* Value of -text option: specifies text to
				 * display in button. */
    int underline;		/* Value of -underline option: specifies index
				 * of character to underline. INT_MIN means don't
				 * of character to underline. < 0 means don't
				 * underline anything. */
    Tcl_Obj *textVarNamePtr;	/* Value of -textvariable option: specifies
				 * name of variable or NULL. If non-NULL,
				 * button displays the contents of this
				 * variable. */
    Pixmap bitmap;		/* Value of -bitmap option. If not None,
				 * specifies bitmap to display and text and
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245







-
+







				 * mode when variable matches this value.
				 * Used by check- buttons. */

    /*
     * Miscellaneous information:
     */

    Tk_Cursor cursor;		/* Value of -cursor option: if not NULL,
    Tk_Cursor cursor;		/* Value of -cursor option: if not None,
				 * specifies current cursor for window. */
    Tcl_Obj *takeFocusPtr;	/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. */
    Tcl_Obj *commandPtr;	/* Value of -command option: specifies script
				 * to execute when button is invoked. If
				 * widget is label or has no command, this is
302
303
304
305
306
307
308
309

310
311

312
313
314
315
316
317
318

319
320
321
322
302
303
304
305
306
307
308

309
310

311
312
313
314
315
316
317

318
319
320
321
322







-
+

-
+






-
+




MODULE_SCOPE char tkDefLabelPady[TCL_INTEGER_SPACE];

/*
 * Declaration of functions used in the implementation of the button widget.
 */

#ifndef TkpButtonSetDefaults
MODULE_SCOPE void	TkpButtonSetDefaults(void);
MODULE_SCOPE void	TkpButtonSetDefaults();
#endif
MODULE_SCOPE void	TkButtonWorldChanged(void *instanceData);
MODULE_SCOPE void	TkButtonWorldChanged(ClientData instanceData);
MODULE_SCOPE void	TkpComputeButtonGeometry(TkButton *butPtr);
MODULE_SCOPE TkButton	*TkpCreateButton(Tk_Window tkwin);
#ifndef TkpDestroyButton
MODULE_SCOPE void 	TkpDestroyButton(TkButton *butPtr);
#endif
#ifndef TkpDisplayButton
MODULE_SCOPE void	TkpDisplayButton(void *clientData);
MODULE_SCOPE void	TkpDisplayButton(ClientData clientData);
#endif
MODULE_SCOPE int	TkInvokeButton(TkButton *butPtr);

#endif /* _TKBUTTON */

Changes to generic/tkCanvArc.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3
4
5


6
7
8
9
10
11
12
13
14



15
16
17
18
19
20
21





-
-
+
+







-
-
-







/*
 * tkCanvArc.c --
 *
 *	This file implements arc items for canvas widgets.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

#include "float.h"

/*
 * The structure below defines the record for each arc item.
 */

typedef enum {
    PIESLICE_STYLE, CHORD_STYLE, ARC_STYLE
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93



94
95
96
97
98
99
100
58
59
60
61
62
63
64






65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81



82
83
84
85
86
87
88
89
90
91







-
-
-
-
-
-















-
+

-
-
-
+
+
+







    Style style;		/* How to draw arc: arc, chord, or
				 * pieslice. */
    GC fillGC;			/* Graphics context for filling item. */
    double center1[2];		/* Coordinates of center of arc outline at
				 * start (see ComputeArcOutline). */
    double center2[2];		/* Coordinates of center of arc outline at
				 * start+extent (see ComputeArcOutline). */
    double height;              /* Distance from the arc's chord to its
				 * mid-point. */
    double startPoint[2];       /* Start point of arc used when specifying
				 * height. */
    double endPoint[2];         /* End point of arc used when specifying
				 * height. */
} ArcItem;

/*
 * The definitions below define the sizes of the polygons used to display
 * outline information for various styles of arcs:
 */

#define CHORD_OUTLINE_PTS	7
#define PIE_OUTLINE1_PTS	6
#define PIE_OUTLINE2_PTS	7

/*
 * Information used for parsing configuration specs:
 */

static int	StyleParseProc(void *clientData, Tcl_Interp *interp,
static int	StyleParseProc(ClientData clientData, Tcl_Interp *interp,
		    Tk_Window tkwin, const char *value,
		    char *widgRec, Tcl_Size offset);
static const char * StylePrintProc(void *clientData, Tk_Window tkwin,
		    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr);
		    char *widgRec, int offset);
static const char * StylePrintProc(ClientData clientData, Tk_Window tkwin,
		    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr);

static const Tk_CustomOption stateOption = {
    TkStateParseProc, TkStatePrintProc, INT2PTR(2)
};
static const Tk_CustomOption styleOption = {
    StyleParseProc, StylePrintProc, NULL
};
109
110
111
112
113
114
115
116

117
118
119

120
121

122
123

124
125

126
127

128
129
130

131
132
133

134
135

136
137
138

139
140

141
142

143
144

145
146

147
148
149

150
151

152
153
154
155

156
157
158

159
160

161
162
163

164
165

166
167

168
169

170
171

172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192

193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
100
101
102
103
104
105
106

107
108
109

110
111

112
113

114
115

116
117

118
119
120

121
122
123

124
125

126
127
128

129
130

131
132

133
134

135
136

137
138
139

140
141

142


143

144
145
146

147
148

149
150
151

152
153

154
155

156
157

158
159

160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175

176
177

178
179

180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
242







-
+


-
+

-
+

-
+

-
+

-
+


-
+


-
+

-
+


-
+

-
+

-
+

-
+

-
+


-
+

-
+
-
-

-
+


-
+

-
+


-
+

-
+

-
+

-
+

-
+




-
+










-
+

-


-
+






-
+




















-
-















-
+











-
-
+







};
static const Tk_CustomOption pixelOption = {
    TkPixelParseProc, TkPixelPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL,
	NULL, offsetof(ArcItem, outline.activeDash),
	NULL, Tk_Offset(ArcItem, outline.activeDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-activefill", NULL, NULL,
	NULL, offsetof(ArcItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL,
	NULL, offsetof(ArcItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL,
	NULL, offsetof(ArcItem, outline.activeStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, outline.activeStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
	NULL, offsetof(ArcItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL,
	"0.0", offsetof(ArcItem, outline.activeWidth),
	"0.0", Tk_Offset(ArcItem, outline.activeWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_CUSTOM, "-dash", NULL, NULL,
	NULL, offsetof(ArcItem, outline.dash),
	NULL, Tk_Offset(ArcItem, outline.dash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL,
	"0", offsetof(ArcItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(ArcItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL,
	NULL, offsetof(ArcItem, outline.disabledDash),
	NULL, Tk_Offset(ArcItem, outline.disabledDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
	NULL, offsetof(ArcItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL,
	NULL, offsetof(ArcItem, outline.disabledColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, outline.disabledColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL,
	NULL, offsetof(ArcItem, outline.disabledStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, outline.disabledStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
	NULL, offsetof(ArcItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL,
	"0.0", offsetof(ArcItem, outline.disabledWidth),
	"0.0", Tk_Offset(ArcItem, outline.disabledWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_DOUBLE, "-extent", NULL, NULL,
	"90", offsetof(ArcItem, extent), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"90", Tk_Offset(ArcItem, extent), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_COLOR, "-fill", NULL, NULL,
	NULL, offsetof(ArcItem, fillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, fillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_DOUBLE, "-height", NULL, NULL,
	0, offsetof(ArcItem, height), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
	"0,0", offsetof(ArcItem, tsoffset),
	"0,0", Tk_Offset(ArcItem, tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_COLOR, "-outline", NULL, NULL,
	DEF_CANVITEM_OUTLINE, offsetof(ArcItem, outline.color), TK_CONFIG_NULL_OK, NULL},
	"black", Tk_Offset(ArcItem, outline.color), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL,
	"0,0", offsetof(ArcItem, outline.tsoffset),
	"0,0", Tk_Offset(ArcItem, outline.tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL,
	NULL, offsetof(ArcItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_DOUBLE, "-start", NULL, NULL,
	"0", offsetof(ArcItem, start), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(ArcItem, start), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
	NULL, offsetof(ArcItem, fillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ArcItem, fillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-style", NULL, NULL,
	NULL, offsetof(ArcItem, style), TK_CONFIG_DONT_SET_DEFAULT,
	NULL, Tk_Offset(ArcItem, style), TK_CONFIG_DONT_SET_DEFAULT,
	&styleOption},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_CUSTOM, "-width", NULL, NULL,
	"1.0", offsetof(ArcItem, outline.width), TK_CONFIG_DONT_SET_DEFAULT,
	"1.0", Tk_Offset(ArcItem, outline.width), TK_CONFIG_DONT_SET_DEFAULT,
	&pixelOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ComputeArcBbox(Tk_Canvas canvas, ArcItem *arcPtr);
static int		ConfigureArc(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static void		ComputeArcParametersFromHeight(ArcItem *arcPtr);
static int		CreateArc(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeleteArc(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayArc(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static int		ArcCoords(Tcl_Interp *interp, Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[]);
static int		ArcToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		ArcToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *coordPtr);
static int		ArcToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static void		ScaleArc(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateArc(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);
static int		AngleInRange(double x, double y,
			    double start, double extent);
static void		ComputeArcOutline(Tk_Canvas canvas, ArcItem *arcPtr);
static int		HorizLineToArc(double x1, double x2,
			    double y, double rx, double ry,
			    double start, double extent);
static int		VertLineToArc(double x, double y1,
			    double y2, double rx, double ry,
			    double start, double extent);
static void		RotateArc(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);

/*
 * The structures below defines the arc item types by means of functions that
 * can be invoked by generic item code.
 */

Tk_ItemType tkArcType = {
    "arc",			/* name */
    sizeof(ArcItem),		/* itemSize */
    CreateArc,			/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureArc,		/* configureProc */
    ArcCoords,			/* coordProc */
    DeleteArc,			/* deleteProc */
    DisplayArc,			/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    ArcToPoint,			/* pointProc */
    ArcToArea,			/* areaProc */
    ArcToPostscript,		/* postscriptProc */
    ScaleArc,			/* scaleProc */
    TranslateArc,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* icursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateArc,			/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 *--------------------------------------------------------------
 *
 * CreateArc --
 *
271
272
273
274
275
276
277
278

279
280
281
282

283
284
285
286
287
288
289
256
257
258
259
260
261
262

263
264
265
266

267
268
269
270
271
272
273
274







-
+



-
+








static int
CreateArc(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing arc. */
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Carry out initialization that is needed in order to clean up after
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
286
287
288
289
290
291
292

293

294
295
296
297
298
299
300







-
+
-







    arcPtr->fillColor = NULL;
    arcPtr->activeFillColor = NULL;
    arcPtr->disabledFillColor = NULL;
    arcPtr->fillStipple = None;
    arcPtr->activeFillStipple = None;
    arcPtr->disabledFillStipple = None;
    arcPtr->style = PIESLICE_STYLE;
    arcPtr->fillGC = NULL;
    arcPtr->fillGC = None;
    arcPtr->height = 0;

    /*
     * Process the arguments to fill in the item record.
     */

    for (i = 1; i < objc; i++) {
	const char *arg = Tcl_GetString(objv[i]);
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371


372
373
374
375
376
377

378
379

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408


409
410
411
412
413
414
415
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353


354
355
356
357
358
359
360

361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376











377
378
379


380
381
382
383
384
385
386
387
388







-
+












-
-
+
+





-
+

-
+













-
-
-
-
-
-
-
-
-
-
-



-
-
+
+








static int
ArcCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;

    if (objc == 0) {
	Tcl_Obj *objs[4];

	objs[0] = Tcl_NewDoubleObj(arcPtr->bbox[0]);
	objs[1] = Tcl_NewDoubleObj(arcPtr->bbox[1]);
	objs[2] = Tcl_NewDoubleObj(arcPtr->bbox[2]);
	objs[3] = Tcl_NewDoubleObj(arcPtr->bbox[3]);
	Tcl_SetObjResult(interp, Tcl_NewListObj(4, objs));
    } else if ((objc == 1) || (objc == 4)) {
	if (objc == 1) {
    } else if ((objc == 1)||(objc == 4)) {
	if (objc==1) {
	    if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		    (Tcl_Obj ***) &objv) != TCL_OK) {
		return TCL_ERROR;
	    } else if (objc != 4) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"wrong # coordinates: expected 4, got %" TCL_SIZE_MODIFIER "d", objc));
			"wrong # coordinates: expected 4, got %d", objc));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "ARC",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	}
	if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
 		    &arcPtr->bbox[0]) != TCL_OK)
		|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
		    &arcPtr->bbox[1]) != TCL_OK)
		|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[2],
			&arcPtr->bbox[2]) != TCL_OK)
		|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[3],
			&arcPtr->bbox[3]) != TCL_OK)) {
	    return TCL_ERROR;
	}

	/*
	 * Store bbox as start and end points so they can be used if either
	 * radius or height is specified.
	 */

	arcPtr->startPoint[0] = arcPtr->bbox[0];
	arcPtr->startPoint[1] = arcPtr->bbox[1];
	arcPtr->endPoint[0] = arcPtr->bbox[2];
	arcPtr->endPoint[1] = arcPtr->bbox[3];

	ComputeArcBbox(canvas, arcPtr);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 4, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "ARC", (char *)NULL);
		"wrong # coordinates: expected 0 or 4, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "ARC", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

456
457
458
459
460
461
462
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435







-
+
















-
+







 */

static int
ConfigureArc(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Arc item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
    XGCValues gcValues;
    GC newGC;
    unsigned long mask;
    int i;
    Tk_Window tkwin;
    Tk_TSOffset *tsoffset;
    XColor *color;
    Pixmap stipple;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, arcPtr, flags)) {
	    (const char **) objv, (char *) arcPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    state = itemPtr->state;

    /*
     * A few of the options require additional processing, such as style and
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509








510

511
512
513
514
515
516

517
518

519
520
521
522
523
524
525
443
444
445
446
447
448
449
















450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480

481
482

483
484
485
486
487
488
489
490







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

















+
+
+
+
+
+
+
+
-
+





-
+

-
+







	    arcPtr->activeFillColor != NULL ||
	    arcPtr->activeFillStipple != None) {
	itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT;
    } else {
	itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
    }

    /*
     * Override the start and extent if the height is given.
     */

    ComputeArcParametersFromHeight(arcPtr);

    ComputeArcBbox(canvas, arcPtr);

    i = (int) (arcPtr->start/360.0);
    arcPtr->start -= i*360.0;
    if (arcPtr->start < 0) {
	arcPtr->start += 360.0;
    }
    i = (int) (arcPtr->extent/360.0);
    arcPtr->extent -= i*360.0;

    tsoffset = &arcPtr->outline.tsoffset;
    flags = tsoffset->flags;
    if (flags & TK_OFFSET_LEFT) {
	tsoffset->xoffset = (int) (arcPtr->bbox[0] + 0.5);
    } else if (flags & TK_OFFSET_CENTER) {
	tsoffset->xoffset = (int) ((arcPtr->bbox[0]+arcPtr->bbox[2]+1)/2);
    } else if (flags & TK_OFFSET_RIGHT) {
	tsoffset->xoffset = (int) (arcPtr->bbox[2] + 0.5);
    }
    if (flags & TK_OFFSET_TOP) {
	tsoffset->yoffset = (int) (arcPtr->bbox[1] + 0.5);
    } else if (flags & TK_OFFSET_MIDDLE) {
	tsoffset->yoffset = (int) ((arcPtr->bbox[1]+arcPtr->bbox[3]+1)/2);
    } else if (flags & TK_OFFSET_BOTTOM) {
	tsoffset->yoffset = (int) (arcPtr->bbox[2] + 0.5);
    }

    i = (int) (arcPtr->start/360.0);
    arcPtr->start -= i*360.0;
    if (arcPtr->start < 0) {
	arcPtr->start += 360.0;
    }
    i = (int) (arcPtr->extent/360.0);
    arcPtr->extent -= i*360.0;

    mask = (unsigned long)Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(arcPtr->outline));
    mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(arcPtr->outline));
    if (mask) {
	gcValues.cap_style = CapButt;
	mask |= GCCapStyle;
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    } else {
	newGC = NULL;
	newGC = None;
    }
    if (arcPtr->outline.gc != NULL) {
    if (arcPtr->outline.gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), arcPtr->outline.gc);
    }
    arcPtr->outline.gc = newGC;

    if(state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }
540
541
542
543
544
545
546
547

548
549
550

551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568

569
570
571
572
573
574
575
505
506
507
508
509
510
511

512
513
514

515
516

517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532

533
534
535
536
537
538
539
540







-
+


-
+

-
+















-
+







    } else if (state==TK_STATE_DISABLED) {
	if (arcPtr->disabledFillColor!=NULL) {
	    color = arcPtr->disabledFillColor;
	}
	if (arcPtr->disabledFillStipple!=None) {
	    stipple = arcPtr->disabledFillStipple;
	}
    }
      }

    if (arcPtr->style == ARC_STYLE) {
	newGC = NULL;
	newGC = None;
    } else if (color == NULL) {
	newGC = NULL;
	newGC = None;
    } else {
	gcValues.foreground = color->pixel;
	if (arcPtr->style == CHORD_STYLE) {
	    gcValues.arc_mode = ArcChord;
	} else {
	    gcValues.arc_mode = ArcPieSlice;
	}
	mask = GCForeground|GCArcMode;
	if (stipple != None) {
	    gcValues.stipple = stipple;
	    gcValues.fill_style = FillStippled;
	    mask |= GCStipple|GCFillStyle;
	}
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    }
    if (arcPtr->fillGC != NULL) {
    if (arcPtr->fillGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), arcPtr->fillGC);
    }
    arcPtr->fillGC = newGC;

    tsoffset = &arcPtr->tsoffset;
    flags = tsoffset->flags;
    if (flags & TK_OFFSET_LEFT) {
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710

711
712
713
714

715
716
717
718
719
720
721
555
556
557
558
559
560
561

































































































562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

578
579
580
581

582
583
584
585
586
587
588
589







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















-
+



-
+







    ComputeArcBbox(canvas, arcPtr);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * ComputeArcParametersFromHeight --
 *
 *	This function calculates the arc parameters given start-point,
 *	end-point and height (!= 0).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The height parameter is set to 0 on exit.
 *
 *--------------------------------------------------------------
 */

static void
ComputeArcParametersFromHeight(
    ArcItem* arcPtr)
{
    double chordLen, chordDir[2], chordCen[2], arcCen[2], d, radToDeg, radius;

    /*
     * Do nothing if no height has been specified.
     */

    if (arcPtr->height == 0)
        return;

    /*
     * Calculate the chord length, return early if it is too small.
     */

    chordLen = hypot(arcPtr->endPoint[1] - arcPtr->startPoint[1],
	    arcPtr->startPoint[0] - arcPtr->endPoint[0]);

    if (chordLen < DBL_EPSILON) {
        arcPtr->start = arcPtr->extent = arcPtr->height = 0;
        return;
    }

    chordDir[0] = (arcPtr->endPoint[0] - arcPtr->startPoint[0]) / chordLen;
    chordDir[1] = (arcPtr->endPoint[1] - arcPtr->startPoint[1]) / chordLen;
    chordCen[0] = (arcPtr->startPoint[0] + arcPtr->endPoint[0]) / 2;
    chordCen[1] = (arcPtr->startPoint[1] + arcPtr->endPoint[1]) / 2;

    /*
     * Calculate the radius (assumes height != 0).
     */

    radius = (4*pow(arcPtr->height, 2) + pow(chordLen, 2))
	    / (8 * arcPtr->height);

    /*
     * The arc centre.
     */

    d = radius - arcPtr->height;
    arcCen[0] = chordCen[0] - d * chordDir[1];
    arcCen[1] = chordCen[1] + d * chordDir[0];

    /*
     * The arc start and span. Angles are negated because the coordinate
     * system is left-handed.
     */

    radToDeg = 45 / atan(1);
    arcPtr->start = atan2(arcCen[1] - arcPtr->startPoint[1],
	    arcPtr->startPoint[0] - arcCen[0]) * radToDeg;
    arcPtr->extent = -2 * asin(chordLen / (2 * radius)) * radToDeg;

    /*
     * Handle spans > 180.
     */

    if (fabs(2 * arcPtr->height) > chordLen) {
	arcPtr->extent = arcPtr->extent > 0 ? (360 - arcPtr->extent)
		: -(360 + arcPtr->extent);
    }

    /*
     * Create the bounding box.
     */

    arcPtr->bbox[0] = arcCen[0] - radius;
    arcPtr->bbox[1] = arcCen[1] - radius;
    arcPtr->bbox[2] = arcCen[0] + radius;
    arcPtr->bbox[3] = arcCen[1] + radius;

    /*
     * Set the height to 0 so that itemcget -height returns 0.
     */

    arcPtr->height = 0;
}

/*
 *--------------------------------------------------------------
 *
 * DeleteArc --
 *
 *	This function is called to clean up the data structure associated with
 *	an arc item.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteArc(
    TCL_UNUSED(Tk_Canvas),		/* Info about overall canvas. */
    Tk_Canvas canvas,		/* Info about overall canvas. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    ArcItem *arcPtr = (ArcItem *)itemPtr;
    ArcItem *arcPtr = (ArcItem *) itemPtr;

    Tk_DeleteOutline(display, &(arcPtr->outline));
    if (arcPtr->numOutlinePoints != 0) {
	ckfree(arcPtr->outlinePtr);
    }
    if (arcPtr->fillColor != NULL) {
	Tk_FreeColor(arcPtr->fillColor);
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
599
600
601
602
603
604
605

606
607
608
609
610
611
612
613







-
+







    }
    if (arcPtr->activeFillStipple != None) {
	Tk_FreeBitmap(display, arcPtr->activeFillStipple);
    }
    if (arcPtr->disabledFillStipple != None) {
	Tk_FreeBitmap(display, arcPtr->disabledFillStipple);
    }
    if (arcPtr->fillGC != NULL) {
    if (arcPtr->fillGC != None) {
	Tk_FreeGC(display, arcPtr->fillGC);
    }
}

/*
 *--------------------------------------------------------------
 *
753
754
755
756
757
758
759

760
761
762
763
764
765
766
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635







+







 *
 * Side effects:
 *	The fields x1, y1, x2, and y2 are updated in the header for itemPtr.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ComputeArcBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    ArcItem *arcPtr)		/* Item whose bbox is to be recomputed. */
{
    double tmp, center[2], point[2];
    double width;
789
790
791
792
793
794
795
796

797
798
799
800
801
802

803
804
805
806
807
808
809
810
811

812
813
814
815
816
817
818
658
659
660
661
662
663
664

665
666
667
668
669
670

671
672
673
674
675
676
677
678
679

680
681
682
683
684
685
686
687







-
+





-
+








-
+







    }

    /*
     * Make sure that the first coordinates are the lowest ones.
     */

    if (arcPtr->bbox[1] > arcPtr->bbox[3]) {
	tmp = arcPtr->bbox[3];
	double tmp = arcPtr->bbox[3];

	arcPtr->bbox[3] = arcPtr->bbox[1];
	arcPtr->bbox[1] = tmp;
    }
    if (arcPtr->bbox[0] > arcPtr->bbox[2]) {
	tmp = arcPtr->bbox[2];
	double tmp = arcPtr->bbox[2];

	arcPtr->bbox[2] = arcPtr->bbox[0];
	arcPtr->bbox[0] = tmp;
    }

    ComputeArcOutline(canvas,arcPtr);

    /*
     * To compute the bounding box, start with the bbox formed by the two
     * To compute the bounding box, start with the the bbox formed by the two
     * endpoints of the arc. Then add in the center of the arc's oval (if
     * relevant) and the 3-o'clock, 6-o'clock, 9-o'clock, and 12-o'clock
     * positions, if they are relevant.
     */

    arcPtr->header.x1 = arcPtr->header.x2 = (int) arcPtr->center1[0];
    arcPtr->header.y1 = arcPtr->header.y2 = (int) arcPtr->center1[1];
861
862
863
864
865
866
867
868

869
870
871
872
873
874
875
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744







-
+







    }

    /*
     * Lastly, expand by the width of the arc (if the arc's outline is being
     * drawn) and add one extra pixel just for safety.
     */

    if (arcPtr->outline.gc == NULL) {
    if (arcPtr->outline.gc == None) {
	tmp = 1;
    } else {
	tmp = (int) ((width + 1.0)/2.0 + 1);
    }
    arcPtr->header.x1 -= (int) tmp;
    arcPtr->header.y1 -= (int) tmp;
    arcPtr->header.x2 += (int) tmp;
895
896
897
898
899
900
901
902
903


904
905
906
907
908
909
910
911
912
764
765
766
767
768
769
770


771
772


773
774
775
776
777
778
779







-
-
+
+
-
-








static void
DisplayArc(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    Tk_Item *itemPtr,		/* Item to be displayed. */
    Display *display,		/* Display on which to draw item. */
    Drawable drawable,		/* Pixmap or window in which to draw item. */
    TCL_UNUSED(int),		/* Describes region of canvas that must be */
    TCL_UNUSED(int),	/* redisplayed (not used). */
    int x, int y,		/* Describes region of canvas that must be */
    int width, int height)	/* redisplayed (not used). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
    short x1, y1, x2, y2;
    int start, extent, dashnumber;
    double lineWidth;
    Tk_State state = itemPtr->state;
    Pixmap stipple;
962
963
964
965
966
967
968
969

970
971
972
973
974
975
976
829
830
831
832
833
834
835

836
837
838
839
840
841
842
843







-
+








    /*
     * Display filled arc first (if wanted), then outline. If the extent is
     * zero then don't invoke XFillArc or XDrawArc, since this causes some
     * window servers to crash and should be a no-op anyway.
     */

    if ((arcPtr->fillGC != NULL) && (extent != 0)) {
    if ((arcPtr->fillGC != None) && (extent != 0)) {
	if (stipple != None) {
	    int w = 0;
	    int h = 0;
	    Tk_TSOffset *tsoffset = &arcPtr->tsoffset;
	    int flags = tsoffset->flags;

	    if (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE)) {
996
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
863
864
865
866
867
868
869

870
871
872
873
874
875
876
877







-
+







	}
	XFillArc(display, drawable, arcPtr->fillGC, x1, y1, (unsigned) (x2-x1),
		(unsigned) (y2-y1), start, extent);
	if (stipple != None) {
	    XSetTSOrigin(display, arcPtr->fillGC, 0, 0);
	}
    }
    if (arcPtr->outline.gc != NULL) {
    if (arcPtr->outline.gc != None) {
	Tk_ChangeOutlineGC(canvas, itemPtr, &(arcPtr->outline));

	if (extent != 0) {
	    XDrawArc(display, drawable, arcPtr->outline.gc, x1, y1,
		    (unsigned) (x2-x1), (unsigned) (y2-y1), start, extent);
	}

1034
1035
1036
1037
1038
1039
1040
1041

1042
1043
1044

1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
901
902
903
904
905
906
907

908
909
910

911
912
913

914
915
916
917
918
919
920
921







-
+


-
+


-
+







			cx, cy, x1, y1);
		XDrawLine(display, drawable, arcPtr->outline.gc,
			cx, cy, x2, y2);
	    }
	} else {
	    if (arcPtr->style == CHORD_STYLE) {
		TkFillPolygon(canvas, arcPtr->outlinePtr, CHORD_OUTLINE_PTS,
			display, drawable, arcPtr->outline.gc, NULL);
			display, drawable, arcPtr->outline.gc, None);
	    } else if (arcPtr->style == PIESLICE_STYLE) {
		TkFillPolygon(canvas, arcPtr->outlinePtr, PIE_OUTLINE1_PTS,
			display, drawable, arcPtr->outline.gc, NULL);
			display, drawable, arcPtr->outline.gc, None);
		TkFillPolygon(canvas, arcPtr->outlinePtr + 2*PIE_OUTLINE1_PTS,
			PIE_OUTLINE2_PTS, display, drawable,
			arcPtr->outline.gc, NULL);
			arcPtr->outline.gc, None);
	    }
	}

	Tk_ResetOutlineGC(canvas, itemPtr, &(arcPtr->outline));
    }
}

1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
ArcToPoint(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032







-
+




-
+







		pointPtr[1] - arcPtr->center2[1]);
	if (newDist < dist) {
	    return newDist;
	}
	return dist;
    }

    if ((arcPtr->fillGC != NULL) || (arcPtr->outline.gc == NULL)) {
    if ((arcPtr->fillGC != None) || (arcPtr->outline.gc == None)) {
	filled = 1;
    } else {
	filled = 0;
    }
    if (arcPtr->outline.gc == NULL) {
    if (arcPtr->outline.gc == None) {
	width = 0.0;
    }

    if (arcPtr->style == PIESLICE_STYLE) {
	if (width > 1.0) {
	    dist = TkPolygonToPoint(arcPtr->outlinePtr, PIE_OUTLINE1_PTS,
		    pointPtr);
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245
1246
1247
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ArcToArea(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against arc. */
    double *rectPtr)		/* Pointer to array of four coordinates (x1,
				 * y1, x2, y2) describing rectangular area. */
{
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1140
1141
1142
1143
1144
1145
1146

1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
1159







-
+




-
+







	}
    } else if (state == TK_STATE_DISABLED) {
	if (arcPtr->outline.disabledWidth>0) {
	    width = (double) arcPtr->outline.disabledWidth;
	}
    }

    if ((arcPtr->fillGC != NULL) || (arcPtr->outline.gc == NULL)) {
    if ((arcPtr->fillGC != None) || (arcPtr->outline.gc == None)) {
	filled = 1;
    } else {
	filled = 0;
    }
    if (arcPtr->outline.gc == NULL) {
    if (arcPtr->outline.gc == None) {
	width = 0.0;
    }

    /*
     * Transform both the arc and the rectangle so that the arc's oval is
     * centered on the origin.
     */
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1375
1376
1377
1378
1379
1380
1381






















































1382
1383
1384
1385
1386
1387
1388







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    arcPtr->bbox[3] = originY + scaleY*(arcPtr->bbox[3] - originY);
    ComputeArcBbox(canvas, arcPtr);
}

/*
 *--------------------------------------------------------------
 *
 * RotateArc --
 *
 *	This function is called to rotate an arc by a given amount.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the arc is rotated by angleRad radians about (originX,
 *	originY), and the bounding box is updated in the generic part of the
 *	item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateArc(
    Tk_Canvas canvas,
    Tk_Item *itemPtr,
    double originX,
    double originY,
    double angleRad)
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
    double newX, newY, oldX, oldY;

    /*
     * Compute the centre of the box, then rotate that about the origin.
     */

    newX = oldX = (arcPtr->bbox[0] + arcPtr->bbox[2]) / 2.0;
    newY = oldY = (arcPtr->bbox[1] + arcPtr->bbox[3]) / 2.0;
    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &newX, &newY);

    /*
     * Apply the translation to the box.
     */

    arcPtr->bbox[0] += newX - oldX;
    arcPtr->bbox[1] += newY - oldY;
    arcPtr->bbox[2] += newX - oldX;
    arcPtr->bbox[3] += newY - oldY;

    /*
     * TODO: update the arc endpoints?
     */

    ComputeArcBbox(canvas, arcPtr);
}

/*
 *--------------------------------------------------------------
 *
 * TranslateArc --
 *
 *	This function is called to move an arc by a given amount.
 *
 * Results:
 *	None.
 *
1627
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462

1463
1464
1465
1466
1467
1468
1469
1470







-
+













-
+








    /*
     * Make sure that the outlinePtr array is large enough to hold either a
     * chord or pie-slice outline.
     */

    if (arcPtr->numOutlinePoints == 0) {
	arcPtr->outlinePtr = (double *)ckalloc(26 * sizeof(double));
	arcPtr->outlinePtr = ckalloc(26 * sizeof(double));
	arcPtr->numOutlinePoints = 22;
    }
    outlinePtr = arcPtr->outlinePtr;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    /*
     * First compute the two points that lie at the centers of the ends of the
     * curved arc segment, which are marked with X's in the figure below:
     *
     *
     *			          * * *
     *				  * * *
     *			      *          *
     *			   *      * *      *
     *			 *    *         *    *
     *			*   *             *   *
     *			 X *               * X
     *
     * The code is tricky because the arc can be ovular in shape. It computes
1994
1995
1996
1997
1998
1999
2000
2001

2002
2003
2004
2005
2006
2007
2008
1809
1810
1811
1812
1813
1814
1815

1816
1817
1818
1819
1820
1821
1822
1823







-
+







 */

static int
ArcToPostscript(
    Tcl_Interp *interp,		/* Leave Postscript or error message here. */
    Tk_Canvas canvas,		/* Information about overall canvas. */
    Tk_Item *itemPtr,		/* Item for which Postscript is wanted. */
    TCL_UNUSED(int))		/* 1 means this is a prepass to collect font
    int prepass)		/* 1 means this is a prepass to collect font
				 * information; 0 means final Postscript is
				 * being created. */
{
    ArcItem *arcPtr = (ArcItem *) itemPtr;
    double y1, y2, ang1, ang2;
    XColor *color;
    Pixmap stipple;
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
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







-
+







-
+






-
+
+
+



-
+


-
+
+
+


-
-
+
+


-
+







-
+










-
+
+
+



-
+








-
+
+
+



-
+


-
+
+
+


-
+

-
+






-
+
+
+



-
+


-
+
+
+


-
+












+
+
+
+
+







    interpState = Tcl_SaveInterpState(interp, TCL_OK);

    /*
     * If the arc is filled, output Postscript for the interior region of the
     * arc.
     */

    if (arcPtr->fillGC != NULL) {
    if (arcPtr->fillGC != None) {
	Tcl_AppendPrintfToObj(psObj,
		"matrix currentmatrix\n"
		"%.15g %.15g translate %.15g %.15g scale\n",
		(arcPtr->bbox[0] + arcPtr->bbox[2])/2, (y1 + y2)/2,
		(arcPtr->bbox[2] - arcPtr->bbox[0])/2, (y1 - y2)/2);

	if (arcPtr->style != CHORD_STYLE) {
	    Tcl_AppendToObj(psObj, "0 0 moveto ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "0 0 moveto ", -1);
	}
	Tcl_AppendPrintfToObj(psObj,
		"0 0 1 %.15g %.15g arc closepath\nsetmatrix\n",
		ang1, ang2);

	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, fillColor);
	if (Tk_CanvasPsColor(interp, canvas, fillColor) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (fillStipple != None) {
	    Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "clip ", -1);

	    Tcl_ResetResult(interp);
	    Tk_CanvasPsStipple(interp, canvas, fillStipple);
	    if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	    if (arcPtr->outline.gc != NULL) {
		Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
	    if (arcPtr->outline.gc != None) {
		Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
	    }
	} else {
	    Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "fill\n", -1);
	}
    }

    /*
     * If there's an outline for the arc, draw it.
     */

    if (arcPtr->outline.gc != NULL) {
    if (arcPtr->outline.gc != None) {
	Tcl_AppendPrintfToObj(psObj,
		"matrix currentmatrix\n"
		"%.15g %.15g translate %.15g %.15g scale\n",
		(arcPtr->bbox[0] + arcPtr->bbox[2])/2, (y1 + y2)/2,
		(arcPtr->bbox[2] - arcPtr->bbox[0])/2, (y1 - y2)/2);
	Tcl_AppendPrintfToObj(psObj,
		"0 0 1 %.15g %.15g arc\nsetmatrix\n0 setlinecap\n",
		ang1, ang2);

	Tcl_ResetResult(interp);
	Tk_CanvasPsOutline(canvas, itemPtr, &arcPtr->outline);
	if (Tk_CanvasPsOutline(canvas, itemPtr, &arcPtr->outline) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (arcPtr->style != ARC_STYLE) {
	    Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "grestore gsave\n", -1);

	    Tcl_ResetResult(interp);
	    if (arcPtr->style == CHORD_STYLE) {
		Tk_CanvasPsPath(interp, canvas, arcPtr->outlinePtr,
			CHORD_OUTLINE_PTS);
	    } else {
		Tk_CanvasPsPath(interp, canvas, arcPtr->outlinePtr,
			PIE_OUTLINE1_PTS);
		Tk_CanvasPsColor(interp, canvas, color);
		if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
		    goto error;
		}
		Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

		if (stipple != None) {
		    Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "clip ", -1);

		    Tcl_ResetResult(interp);
		    Tk_CanvasPsStipple(interp, canvas, stipple);
		    if (Tk_CanvasPsStipple(interp, canvas, stipple) !=TCL_OK){
			goto error;
		    }
		    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
		} else {
		    Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "fill\n", -1);
		}
		Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "grestore gsave\n", -1);

		Tcl_ResetResult(interp);
		Tk_CanvasPsPath(interp, canvas,
			arcPtr->outlinePtr + 2*PIE_OUTLINE1_PTS,
			PIE_OUTLINE2_PTS);
	    }
	    Tk_CanvasPsColor(interp, canvas, color);
	    if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	    if (stipple != None) {
		Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "clip ", -1);

		Tcl_ResetResult(interp);
		Tk_CanvasPsStipple(interp, canvas, stipple);
		if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
		    goto error;
		}
		Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	    } else {
		Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "fill\n", -1);
	    }
	}
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

    (void) Tcl_RestoreInterpState(interp, interpState);
    Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    Tcl_DecrRefCount(psObj);
    return TCL_OK;

  error:
    Tcl_DiscardInterpState(interpState);
    Tcl_DecrRefCount(psObj);
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * StyleParseProc --
 *
2189
2190
2191
2192
2193
2194
2195
2196

2197
2198

2199
2200
2201

2202
2203
2204

2205

2206
2207
2208
2209
2210
2211
2212
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







-
+

-
+


-
+



+
-
+







 *	value argument.
 *
 *--------------------------------------------------------------
 */

static int
StyleParseProc(
    TCL_UNUSED(void *),
    ClientData clientData,	/* some flags.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    int c;
    size_t length;

    Style *stylePtr = (Style *) (widgRec + offset);
    register Style *stylePtr = (Style *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*stylePtr = PIESLICE_STYLE;
	return TCL_OK;
    }

    c = value[0];
2224
2225
2226
2227
2228
2229
2230
2231

2232
2233
2234
2235
2236
2237
2238
2059
2060
2061
2062
2063
2064
2065

2066
2067
2068
2069
2070
2071
2072
2073







-
+







	*stylePtr = PIESLICE_STYLE;
	return TCL_OK;
    }

    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad -style option \"%s\": must be arc, chord, or pieslice",
	    value));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARC_STYLE", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARC_STYLE", NULL);
    *stylePtr = PIESLICE_STYLE;
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
2252
2253
2254
2255
2256
2257
2258
2259
2260


2261
2262
2263


2264
2265
2266
2267

2268
2269
2270
2271
2272
2273
2274
2087
2088
2089
2090
2091
2092
2093


2094
2095
2096


2097
2098
2099
2100
2101

2102
2103
2104
2105
2106
2107
2108
2109







-
-
+
+

-
-
+
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static const char *
StylePrintProc(
    TCL_UNUSED(void *),	/* Ignored. */
    TCL_UNUSED(Tk_Window),		/* Ignored. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Ignored. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset into item. */
    TCL_UNUSED(Tcl_FreeProc **))	/* Pointer to variable to fill in with
    int offset,			/* Offset into item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    Style *stylePtr = (Style *) (widgRec + offset);
    register Style *stylePtr = (Style *) (widgRec + offset);

    if (*stylePtr == ARC_STYLE) {
	return "arc";
    } else if (*stylePtr == CHORD_STYLE) {
	return "chord";
    } else {
	return "pieslice";

Changes to generic/tkCanvBmap.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5


6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21





-
-
+
+







-







/*
 * tkCanvBmap.c --
 *
 *	This file implements bitmap items for canvas widgets.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

/*
 * The structure below defines the record for each bitmap item.
 */

typedef struct BitmapItem  {
    Tk_Item header;		/* Generic stuff that's the same for all
46
47
48
49
50
51
52
53

54
55

56
57

58
59

60
61

62
63

64
65

66
67
68

69
70
71

72
73
74

75
76

77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99

100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
45
46
47
48
49
50
51

52
53

54
55

56
57

58
59

60
61

62
63

64
65
66

67
68
69

70
71
72

73
74

75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97

98
99
100
101

102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139


140
141
142
143
144
145
146
147







-
+

-
+

-
+

-
+

-
+

-
+

-
+


-
+


-
+


-
+

-
+











-
+










-
+



-
+





-
-




















-
+











-
-
+







};
static const Tk_CustomOption tagsOption = {
    Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_COLOR, "-activebackground", NULL, NULL,
	NULL, offsetof(BitmapItem, activeBgColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapItem, activeBgColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activebitmap", NULL, NULL,
	NULL, offsetof(BitmapItem, activeBitmap), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapItem, activeBitmap), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-activeforeground", NULL, NULL,
	NULL, offsetof(BitmapItem, activeFgColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapItem, activeFgColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
	"center", offsetof(BitmapItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"center", Tk_Offset(BitmapItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_COLOR, "-background", NULL, NULL,
	NULL, offsetof(BitmapItem, bgColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapItem, bgColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-bitmap", NULL, NULL,
	NULL, offsetof(BitmapItem, bitmap), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapItem, bitmap), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-disabledbackground", NULL, NULL,
	NULL, offsetof(BitmapItem, disabledBgColor),
	NULL, Tk_Offset(BitmapItem, disabledBgColor),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledbitmap", NULL, NULL,
	NULL, offsetof(BitmapItem, disabledBitmap),
	NULL, Tk_Offset(BitmapItem, disabledBitmap),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-disabledforeground", NULL, NULL,
	NULL, offsetof(BitmapItem, disabledFgColor),
	NULL, Tk_Offset(BitmapItem, disabledFgColor),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-foreground", NULL, NULL,
	DEF_CANVBMAP_FG, offsetof(BitmapItem, fgColor), 0, NULL},
	"black", Tk_Offset(BitmapItem, fgColor), 0, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK,
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK,
	&stateOption},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static int		BitmapCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[]);
static int		BitmapToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		BitmapToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *coordPtr);
static int		BitmapToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static void		ComputeBitmapBbox(Tk_Canvas canvas,
			    BitmapItem *bmapPtr);
static int		ConfigureBitmap(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static int		TkcCreateBitmap(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeleteBitmap(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayBitmap(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static void		RotateBitmap(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScaleBitmap(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateBitmap(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double deltaX, double deltaY);

/*
 * The structures below defines the bitmap item type in terms of functions
 * that can be invoked by generic item code.
 */

Tk_ItemType tkBitmapType = {
    "bitmap",			/* name */
    sizeof(BitmapItem),		/* itemSize */
    TkcCreateBitmap,		/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureBitmap,		/* configureProc */
    BitmapCoords,		/* coordProc */
    DeleteBitmap,		/* deleteProc */
    DisplayBitmap,		/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    BitmapToPoint,		/* pointProc */
    BitmapToArea,		/* areaProc */
    BitmapToPostscript,		/* postscriptProc */
    ScaleBitmap,		/* scaleProc */
    TranslateBitmap,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* icursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateBitmap,		/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 *--------------------------------------------------------------
 *
 * TkcCreateBitmap --
 *
165
166
167
168
169
170
171
172

173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
161
162
163
164
165
166
167

168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
199







-
+



-
+



















-
+








static int
TkcCreateBitmap(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing rectangle. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Initialize item's record.
     */

    bmapPtr->anchor = TK_ANCHOR_CENTER;
    bmapPtr->bitmap = None;
    bmapPtr->activeBitmap = None;
    bmapPtr->disabledBitmap = None;
    bmapPtr->fgColor = NULL;
    bmapPtr->activeFgColor = NULL;
    bmapPtr->disabledFgColor = NULL;
    bmapPtr->bgColor = NULL;
    bmapPtr->activeBgColor = NULL;
    bmapPtr->disabledBgColor = NULL;
    bmapPtr->gc = NULL;
    bmapPtr->gc = None;

    /*
     * Process the arguments to fill in the item record. Only 1 (list) or 2 (x
     * y) coords are allowed.
     */

    if (objc == 1) {
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268

269
270
271
272
273
274
275
276
277
278
279
280
281
282


283
284
285
286
287
288
289
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263

264
265
266
267
268
269
270
271
272
273
274
275
276


277
278
279
280
281
282
283
284
285







-
+

















-
+

-
+












-
-
+
+








static int
BitmapCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;

    if (objc == 0) {
	Tcl_Obj *obj = Tcl_NewObj();

	Tcl_ListObjAppendElement(NULL, obj, Tcl_NewDoubleObj(bmapPtr->x));
	Tcl_ListObjAppendElement(NULL, obj, Tcl_NewDoubleObj(bmapPtr->y));
	Tcl_SetObjResult(interp, obj);
    } else if (objc < 3) {
	if (objc == 1) {
	    if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		    (Tcl_Obj ***) &objv) != TCL_OK) {
		return TCL_ERROR;
	    } else if (objc != 2) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"wrong # coordinates: expected 2, got %" TCL_SIZE_MODIFIER "d", objc));
			"wrong # coordinates: expected 2, got %d", objc));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "BITMAP",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	}
	if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
		&bmapPtr->x) != TCL_OK)
		|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
			&bmapPtr->y) != TCL_OK)) {
	    return TCL_ERROR;
	}
	ComputeBitmapBbox(canvas, bmapPtr);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 2, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "BITMAP", (char *)NULL);
		"wrong # coordinates: expected 0 or 2, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "BITMAP", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330







-
+















-
+







 */

static int
ConfigureBitmap(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Bitmap item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv.  */
    int objc,			/* Number of elements in objv.  */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
    XGCValues gcValues;
    GC newGC;
    Tk_Window tkwin;
    unsigned long mask;
    XColor *fgColor;
    XColor *bgColor;
    Pixmap bitmap;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, bmapPtr, flags)) {
	    (const char **) objv, (char *) bmapPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * A few of the options require additional processing, such as those that
     * determine the graphics context.
     */
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395







-
+












-
+







	}
	if (bmapPtr->disabledBitmap!=None) {
	    bitmap = bmapPtr->disabledBitmap;
	}
    }

    if (bitmap == None) {
	newGC = NULL;
	newGC = None;
    } else {
	gcValues.foreground = fgColor->pixel;
	mask = GCForeground;
	if (bgColor != NULL) {
	    gcValues.background = bgColor->pixel;
	    mask |= GCBackground;
	} else {
	    gcValues.clip_mask = bitmap;
	    mask |= GCClipMask;
	}
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    }
    if (bmapPtr->gc != NULL) {
    if (bmapPtr->gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), bmapPtr->gc);
    }
    bmapPtr->gc = newGC;

    ComputeBitmapBbox(canvas, bmapPtr);
    return TCL_OK;
}
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423







-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteBitmap(
    TCL_UNUSED(Tk_Canvas),		/* Info about overall canvas widget. */
    Tk_Canvas canvas,		/* Info about overall canvas widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;

    if (bmapPtr->bitmap != None) {
	Tk_FreeBitmap(display, bmapPtr->bitmap);
469
470
471
472
473
474
475

476
477
478
479
480
481
482
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479







+







 *
 * Side effects:
 *	The fields x1, y1, x2, and y2 are updated in the header for itemPtr.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ComputeBitmapBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    BitmapItem *bmapPtr)	/* Item whose bbox is to be recomputed. */
{
    int width, height;
    int x, y;
535
536
537
538
539
540
541
542

543
544
545
546
547
548
549
532
533
534
535
536
537
538

539
540
541
542
543
544
545
546







-
+







	y -= height;
	break;
    case TK_ANCHOR_W:
	y -= height/2;
	break;
    case TK_ANCHOR_NW:
	break;
    default:
    case TK_ANCHOR_CENTER:
	x -= width/2;
	y -= height/2;
	break;
    }

    /*
     * Store the information in the item header.
666
667
668
669
670
671
672

673
674
675

676
677
678
679
680
681
682
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680







+


-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
BitmapToPoint(
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *coordPtr)		/* Pointer to x and y coordinates. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
    double x1, x2, y1, y2, xDiff, yDiff;

    x1 = bmapPtr->header.x1;
722
723
724
725
726
727
728

729
730
731

732
733
734
735
736
737
738
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
737







+


-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
BitmapToArea(
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against rectangle. */
    double *rectPtr)		/* Pointer to array of four coordinates
				 * (x1,y1,x2,y2) describing rectangular
				 * area. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;

787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
786
787
788
789
790
791
792

































793
794
795
796
797
798
799







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    bmapPtr->y = originY + scaleY*(bmapPtr->y - originY);
    ComputeBitmapBbox(canvas, bmapPtr);
}

/*
 *--------------------------------------------------------------
 *
 * RotateBitmap --
 *
 *	This function is called to rotate a bitmap's origin by a given amount.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the bitmap is rotated by angleRad radians about
 *	(originX, originY), and the bounding box is updated in the generic
 *	part of the item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateBitmap(
    Tk_Canvas canvas,
    Tk_Item *itemPtr,
    double originX,
    double originY,
    double angleRad)
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;

    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &bmapPtr->x, &bmapPtr->y);
    ComputeBitmapBbox(canvas, bmapPtr);
}

/*
 *--------------------------------------------------------------
 *
 * TranslateBitmap --
 *
 *	This function is called to move an item by a given amount.
 *
 * Results:
 *	None.
 *
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
838
839
840
841
842
843
844

845
846
847
848
849
850
851
852







-
+







 */

static int
BitmapToPostscript(
    Tcl_Interp *interp,		/* Leave Postscript or error message here. */
    Tk_Canvas canvas,		/* Information about overall canvas. */
    Tk_Item *itemPtr,		/* Item for which Postscript is wanted. */
    TCL_UNUSED(int))		/* 1 means this is a prepass to collect font
    int prepass)		/* 1 means this is a prepass to collect font
				 * information; 0 means final Postscript is
				 * being created. */
{
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
    double x, y;
    int width, height, rowsAtOnce, rowsThisTime;
    int curRow;
937
938
939
940
941
942
943
944

945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965



966
967
968

969
970
971
972
973
974
975
976
977
978
979
980



981
982
983
984
985
986
987


988
989
990
991
992
993
994
903
904
905
906
907
908
909

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947

948
949
950
951
952
953
954
955


956
957
958
959
960
961
962
963
964







-
+




















-
+
+
+


-
+











-
+
+
+





-
-
+
+







    case TK_ANCHOR_N:	   x -= width/2.0; y -= height;		break;
    case TK_ANCHOR_NE:	   x -= width;	   y -= height;		break;
    case TK_ANCHOR_E:	   x -= width;	   y -= height/2.0;	break;
    case TK_ANCHOR_SE:	   x -= width;				break;
    case TK_ANCHOR_S:	   x -= width/2.0;			break;
    case TK_ANCHOR_SW:						break;
    case TK_ANCHOR_W:			   y -= height/2.0;	break;
    default: x -= width/2.0; y -= height/2.0;	break;
    case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0;	break;
    }

    /*
     * Make our working space.
     */

    psObj = Tcl_NewObj();
    interpState = Tcl_SaveInterpState(interp, TCL_OK);

    /*
     * Color the background, if there is one.
     */

    if (bgColor != NULL) {
	Tcl_AppendPrintfToObj(psObj,
		"%.15g %.15g moveto %d 0 rlineto 0 %d rlineto "
		"%d 0 rlineto closepath\n",
		x, y, width, height, -width);

	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, bgColor);
	if (Tk_CanvasPsColor(interp, canvas, bgColor) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "fill\n", -1);
    }

    /*
     * Draw the bitmap, if there is a foreground color. If the bitmap is very
     * large, then chop it up into multiple bitmaps, each consisting of one or
     * more rows. This is needed because Postscript can't handle single
     * strings longer than 64 KBytes long.
     */

    if (fgColor != NULL) {
	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, fgColor);
	if (Tk_CanvasPsColor(interp, canvas, fgColor) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (width > 60000) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't generate Postscript for bitmaps more than 60000"
		    " pixels wide", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", (char *)NULL);
		    " pixels wide", -1));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", NULL);
	    goto error;
	}

	rowsAtOnce = 60000/width;
	if (rowsAtOnce < 1) {
	    rowsAtOnce = 1;
	}
1002
1003
1004
1005
1006
1007
1008
1009
1010




1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
972
973
974
975
976
977
978


979
980
981
982
983
984

985
986
987
988
989
990
991
992







-
-
+
+
+
+


-
+







	    }

	    Tcl_AppendPrintfToObj(psObj,
		    "0 -%.15g translate\n%d %d true matrix {\n",
		    (double) rowsThisTime, width, rowsThisTime);

	    Tcl_ResetResult(interp);
	    Tk_CanvasPsBitmap(interp, canvas, bitmap, 0, curRow, width,
		    rowsThisTime);
	    if (Tk_CanvasPsBitmap(interp, canvas, bitmap,
		    0, curRow, width, rowsThisTime) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	    Tcl_AppendToObj(psObj, "\n} imagemask\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "\n} imagemask\n", -1);
	}
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

Changes to generic/tkCanvImg.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkCanvImg.c --
 *
 *	This file implements image items for canvas widgets.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
48
49
50
51
52
53
54
55

56
57

58
59

60
61

62
63

64
65
66
67
68
69
70
71
72
73

74
75
76
77
78


79
80
81
82
83
84
85
86
87
88


89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
48
49
50
51
52
53
54

55
56

57
58

59
60

61
62

63
64
65
66
67
68
69
70
71
72

73
74
75
76


77
78
79
80
81
82
83
84
85
86


87
88
89
90

91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128


129
130
131
132
133
134
135
136







-
+

-
+

-
+

-
+

-
+









-
+



-
-
+
+








-
-
+
+


-
+





-
-




















-
+











-
-
+







};
static const Tk_CustomOption tagsOption = {
    Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_STRING, "-activeimage", NULL, NULL,
	NULL, offsetof(ImageItem, activeImageString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ImageItem, activeImageString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
	"center", offsetof(ImageItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"center", Tk_Offset(ImageItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_STRING, "-disabledimage", NULL, NULL,
	NULL, offsetof(ImageItem, disabledImageString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ImageItem, disabledImageString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_STRING, "-image", NULL, NULL,
	NULL, offsetof(ImageItem, imageString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(ImageItem, imageString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ImageChangedProc(void *clientData,
static void		ImageChangedProc(ClientData clientData,
			    int x, int y, int width, int height, int imgWidth,
			    int imgHeight);
static int		ImageCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tcl_Obj *const objv[]);
			    Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
			    Tcl_Obj *const argv[]);
static int		ImageToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		ImageToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *coordPtr);
static int		ImageToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static void		ComputeImageBbox(Tk_Canvas canvas, ImageItem *imgPtr);
static int		ConfigureImage(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tcl_Obj *const objv[], int flags);
			    Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
			    Tcl_Obj *const argv[], int flags);
static int		CreateImage(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int argc, Tcl_Obj *const argv[]);
static void		DeleteImage(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayImage(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static void		RotateImage(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScaleImage(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateImage(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);

/*
 * The structures below defines the image item type in terms of functions that
 * can be invoked by generic item code.
 */

Tk_ItemType tkImageType = {
    "image",			/* name */
    sizeof(ImageItem),		/* itemSize */
    CreateImage,		/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureImage,		/* configureProc */
    ImageCoords,		/* coordProc */
    DeleteImage,		/* deleteProc */
    DisplayImage,		/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    ImageToPoint,		/* pointProc */
    ImageToArea,		/* areaProc */
    ImageToPostscript,		/* postscriptProc */
    ScaleImage,			/* scaleProc */
    TranslateImage,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* icursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateImage,		/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 *--------------------------------------------------------------
 *
 * CreateImage --
 *
153
154
155
156
157
158
159
160

161
162
163
164

165
166
167
168
169
170
171
150
151
152
153
154
155
156

157
158
159
160

161
162
163
164
165
166
167
168







-
+



-
+








static int
CreateImage(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing rectangle. */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Initialize item's record.
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266


267
268
269
270
271
272
273
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248

249
250
251
252
253
254
255
256
257
258
259
260
261


262
263
264
265
266
267
268
269
270







-
+

















-
+

-
+












-
-
+
+








static int
ImageCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;

    if (objc == 0) {
	Tcl_Obj *objs[2];

	objs[0] = Tcl_NewDoubleObj(imgPtr->x);
	objs[1] = Tcl_NewDoubleObj(imgPtr->y);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, objs));
    } else if (objc < 3) {
	if (objc==1) {
	    if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		    (Tcl_Obj ***) &objv) != TCL_OK) {
		return TCL_ERROR;
	    } else if (objc != 2) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"wrong # coordinates: expected 2, got %" TCL_SIZE_MODIFIER "d", objc));
			"wrong # coordinates: expected 2, got %d", objc));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "IMAGE",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	}
	if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
		    &imgPtr->x) != TCL_OK)
		|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
  		    &imgPtr->y) != TCL_OK)) {
	    return TCL_ERROR;
	}
	ComputeImageBbox(canvas, imgPtr);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 2, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "IMAGE", (char *)NULL);
		"wrong # coordinates: expected 0 or 2, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "IMAGE", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303
304
305

306
307
308
309
310
311
312
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309







-
+









-
+







 */

static int
ConfigureImage(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Image item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv.  */
    int objc,			/* Number of elements in objv.  */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;
    Tk_Window tkwin;
    Tk_Image image;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, imgPtr, flags)) {
	    (const char **) objv, (char *) imgPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * Create the image. Save the old image around and don't free it until
     * after the new one is allocated. This keeps the reference count from
     * going to zero so the image doesn't have to be recreated if it hasn't
376
377
378
379
380
381
382
383

384
385

386
387
388
389
390
391
392
373
374
375
376
377
378
379

380
381

382
383
384
385
386
387
388
389







-
+

-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteImage(
    TCL_UNUSED(Tk_Canvas),	/* Info about overall canvas widget. */
    Tk_Canvas canvas,		/* Info about overall canvas widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    TCL_UNUSED(Display *))	/* Display containing window for canvas. */
    Display *display)		/* Display containing window for canvas. */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;

    if (imgPtr->imageString != NULL) {
	ckfree(imgPtr->imageString);
    }
    if (imgPtr->activeImageString != NULL) {
420
421
422
423
424
425
426

427
428
429
430
431
432
433
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431







+







 *
 * Side effects:
 *	The fields x1, y1, x2, and y2 are updated in the header for itemPtr.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ComputeImageBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    ImageItem *imgPtr)		/* Item whose bbox is to be recomputed. */
{
    int width, height;
    int x, y;
447
448
449
450
451
452
453
454

455
456
457
458
459
460
461
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459







-
+







	    image = imgPtr->disabledImage;
	}
    }

    x = (int) (imgPtr->x + ((imgPtr->x >= 0) ? 0.5 : - 0.5));
    y = (int) (imgPtr->y + ((imgPtr->y >= 0) ? 0.5 : - 0.5));

    if ((state == TK_STATE_HIDDEN) || (image == NULL)) {
    if ((state == TK_STATE_HIDDEN) || (image == None)) {
	imgPtr->header.x1 = imgPtr->header.x2 = x;
	imgPtr->header.y1 = imgPtr->header.y2 = y;
	return;
    }

    /*
     * Compute location and size of image, using anchor information.
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497







-
+







	y -= height;
	break;
    case TK_ANCHOR_W:
	y -= height/2;
	break;
    case TK_ANCHOR_NW:
	break;
    default:
    case TK_ANCHOR_CENTER:
	x -= width/2;
	y -= height/2;
	break;
    }

    /*
     * Store the information in the item header.
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
530
531
532
533
534
535
536

537
538
539
540
541
542
543







-







				/* Describes region of canvas that must be
				 * redisplayed (not used). */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;
    short drawableX, drawableY;
    Tk_Image image;
    Tk_State state = itemPtr->state;
    (void)display;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    image = imgPtr->image;
    if (Canvas(canvas)->currentItemPtr == itemPtr) {
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static double
ImageToPoint(
    TCL_UNUSED(Tk_Canvas),	/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *coordPtr)		/* Pointer to x and y coordinates. */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;
    double x1, x2, y1, y2, xDiff, yDiff;

    x1 = imgPtr->header.x1;
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static int
ImageToArea(
    TCL_UNUSED(Tk_Canvas),	/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against rectangle. */
    double *rectPtr)		/* Pointer to array of four coordinates
				 * (x1,y1,x2,y2) describing rectangular
				 * area. */
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;

739
740
741
742
743
744
745
746

747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
736
737
738
739
740
741
742

743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759


































760
761
762
763
764
765
766







-
+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    case TK_ANCHOR_N:	   x -= width/2.0; y -= height;		break;
    case TK_ANCHOR_NE:	   x -= width;	   y -= height;		break;
    case TK_ANCHOR_E:	   x -= width;	   y -= height/2.0;	break;
    case TK_ANCHOR_SE:	   x -= width;				break;
    case TK_ANCHOR_S:	   x -= width/2.0;			break;
    case TK_ANCHOR_SW:						break;
    case TK_ANCHOR_W:			   y -= height/2.0;	break;
    default: x -= width/2.0; y -= height/2.0;	break;
    case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0;	break;
    }

    if (!prepass) {
	Tcl_Obj *psObj = Tcl_GetObjResult(interp);

	if (Tcl_IsShared(psObj)) {
	    psObj = Tcl_DuplicateObj(psObj);
	    Tcl_SetObjResult(interp, psObj);
	}

	Tcl_AppendPrintfToObj(psObj, "%.15g %.15g translate\n", x, y);
    }

    return Tk_PostscriptImage(image, interp, canvasWin,
	    ((TkCanvas *) canvas)->psInfo, 0, 0, width, height, prepass);
}

/*
 *--------------------------------------------------------------
 *
 * RotateImage --
 *
 *	This function is called to rotate an image's origin by a given amount.
 *	This does *not* rotate the contents of the image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the image anchor is rotated by angleRad radians about
 *	(originX, originY), and the bounding box is updated in the generic
 *	part of the item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateImage(
    Tk_Canvas canvas,
    Tk_Item *itemPtr,
    double originX,
    double originY,
    double angleRad)
{
    ImageItem *imgPtr = (ImageItem *) itemPtr;

    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &imgPtr->x, &imgPtr->y);
    ComputeImageBbox(canvas, imgPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ScaleImage --
 *
 *	This function is invoked to rescale an item.
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891

892
893
894
895
896
897
898
840
841
842
843
844
845
846

847
848
849
850
851
852
853

854
855
856
857
858
859
860
861







-
+






-
+







 *	Arranges for the canvas to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
ImageChangedProc(
    void *clientData,	/* Pointer to canvas item for image. */
    ClientData clientData,	/* Pointer to canvas item for image. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (may be <=
				 * 0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    ImageItem *imgPtr = (ImageItem *)clientData;
    ImageItem *imgPtr = clientData;

    /*
     * If the image's size changed and it's not anchored at its northwest
     * corner then just redisplay the entire area of the image. This is a bit
     * over-conservative, but we need to do something because a size change
     * also means a position change.
     */

Changes to generic/tkCanvLine.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38





-
-
-
+
+
+







-
-
-
-
-















-
+







/*
 * tkCanvLine.c --
 *
 *	This file implements line items for canvas widgets.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1991-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The structure below defines the record for each line item.
 */

typedef enum {
    ARROWS_NONE, ARROWS_FIRST, ARROWS_LAST, ARROWS_BOTH
} Arrows;

typedef struct LineItem {
    Tk_Item header;		/* Generic stuff that's the same for all
				 * types. MUST BE FIRST IN STRUCTURE. */
    Tk_Outline outline;		/* Outline structure */
    Tk_Canvas canvas;		/* Canvas containing item. Needed for parsing
				 * arrow shapes. */
    Tcl_Size numPoints;		/* Number of points in line (always >= 0). */
    int numPoints;		/* Number of points in line (always >= 0). */
    double *coordPtr;		/* Pointer to malloc-ed array containing x-
				 * and y-coords of all points in line.
				 * X-coords are even-valued indices, y-coords
				 * are corresponding odd-valued indices. If
				 * the line has arrowheads then the first and
				 * last points have been adjusted to refer to
				 * the necks of the arrowheads rather than
79
80
81
82
83
84
85
86

87
88
89
90
91

92
93
94
95
96
97
98
99

100
101
102

103
104

105
106

107
108
109
110
111
112
113

114
115
116
117



118
119

120
121
122
123



124
125
126
127
128
129
130
131
132
133
74
75
76
77
78
79
80

81
82
83
84
85

86
87
88
89
90
91
92
93

94
95
96

97
98

99
100

101
102
103
104
105
106
107

108
109



110
111
112
113

114
115



116
117
118
119


120
121
122
123
124
125
126







-
+




-
+







-
+


-
+

-
+

-
+






-
+

-
-
-
+
+
+

-
+

-
-
-
+
+
+

-
-







 */

static int		ArrowheadPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, LineItem *linePtr,
			    double *arrowPtr, Tcl_Obj *psObj);
static void		ComputeLineBbox(Tk_Canvas canvas, LineItem *linePtr);
static int		ConfigureLine(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static int		ConfigureArrows(Tk_Canvas canvas, LineItem *linePtr);
static int		CreateLine(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeleteLine(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayLine(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static int		GetLineIndex(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Obj *obj, Tcl_Size *indexPtr);
			    Tcl_Obj *obj, int *indexPtr);
static int		LineCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		LineDeleteCoords(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size first, Tcl_Size last);
			    Tk_Item *itemPtr, int first, int last);
static void		LineInsert(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size beforeThis, Tcl_Obj *obj);
			    Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj);
static int		LineToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		LineToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *coordPtr);
static int		LineToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static int		ArrowParseProc(void *clientData,
static int		ArrowParseProc(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    const char *value, char *recordPtr, Tcl_Size offset);
static const char * ArrowPrintProc(void *clientData,
			    Tk_Window tkwin, char *recordPtr, Tcl_Size offset,
			    const char *value, char *recordPtr, int offset);
static const char * ArrowPrintProc(ClientData clientData,
			    Tk_Window tkwin, char *recordPtr, int offset,
			    Tcl_FreeProc **freeProcPtr);
static int		ParseArrowShape(void *clientData,
static int		ParseArrowShape(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    const char *value, char *recordPtr, Tcl_Size offset);
static const char * PrintArrowShape(void *clientData,
			    Tk_Window tkwin, char *recordPtr, Tcl_Size offset,
			    const char *value, char *recordPtr, int offset);
static const char * PrintArrowShape(ClientData clientData,
			    Tk_Window tkwin, char *recordPtr, int offset,
			    Tcl_FreeProc **freeProcPtr);
static void		RotateLine(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScaleLine(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateLine(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);

/*
160
161
162
163
164
165
166
167

168
169
170

171
172

173
174

175
176
177

178
179
180

181
182
183

184
185

186
187

188
189
190

191
192

193
194
195

196
197

198
199

200
201
202

203
204

205
206
207

208
209
210

211
212

213
214

215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
153
154
155
156
157
158
159

160
161
162

163
164

165
166

167
168
169

170
171
172

173
174
175

176
177

178
179

180
181
182

183
184

185
186
187

188
189

190
191

192
193
194

195
196

197
198
199

200
201
202

203
204

205
206

207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237
238
239
240
241


242
243
244
245
246
247
248
249







-
+


-
+

-
+

-
+


-
+


-
+


-
+

-
+

-
+


-
+

-
+


-
+

-
+

-
+


-
+

-
+


-
+


-
+

-
+

-
+



-
+


















-
+











-
-
+







};
static const Tk_CustomOption pixelOption = {
    TkPixelParseProc, TkPixelPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL,
	NULL, offsetof(LineItem, outline.activeDash),
	NULL, Tk_Offset(LineItem, outline.activeDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-activefill", NULL, NULL,
	NULL, offsetof(LineItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(LineItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
	NULL, offsetof(LineItem, outline.activeStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(LineItem, outline.activeStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL,
	"0.0", offsetof(LineItem, outline.activeWidth),
	"0.0", Tk_Offset(LineItem, outline.activeWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_CUSTOM, "-arrow", NULL, NULL,
	"none", offsetof(LineItem, arrow),
	"none", Tk_Offset(LineItem, arrow),
	TK_CONFIG_DONT_SET_DEFAULT, &arrowOption},
    {TK_CONFIG_CUSTOM, "-arrowshape", NULL, NULL,
	"8 10 3", offsetof(LineItem, arrowShapeA),
	"8 10 3", Tk_Offset(LineItem, arrowShapeA),
	TK_CONFIG_DONT_SET_DEFAULT, &arrowShapeOption},
    {TK_CONFIG_CAP_STYLE, "-capstyle", NULL, NULL,
	"butt", offsetof(LineItem, capStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"butt", Tk_Offset(LineItem, capStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_COLOR, "-fill", NULL, NULL,
	DEF_CANVITEM_OUTLINE, offsetof(LineItem, outline.color), TK_CONFIG_NULL_OK, NULL},
	"black", Tk_Offset(LineItem, outline.color), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-dash", NULL, NULL,
	NULL, offsetof(LineItem, outline.dash),
	NULL, Tk_Offset(LineItem, outline.dash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL,
	"0", offsetof(LineItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(LineItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL,
	NULL, offsetof(LineItem, outline.disabledDash),
	NULL, Tk_Offset(LineItem, outline.disabledDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
	NULL, offsetof(LineItem, outline.disabledColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(LineItem, outline.disabledColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
	NULL, offsetof(LineItem, outline.disabledStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(LineItem, outline.disabledStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL,
	"0.0", offsetof(LineItem, outline.disabledWidth),
	"0.0", Tk_Offset(LineItem, outline.disabledWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL,
	"round", offsetof(LineItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"round", Tk_Offset(LineItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
	"0,0", offsetof(LineItem, outline.tsoffset),
	"0,0", Tk_Offset(LineItem, outline.tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL,
	"0", offsetof(LineItem, smooth),
	"0", Tk_Offset(LineItem, smooth),
	TK_CONFIG_DONT_SET_DEFAULT, &smoothOption},
    {TK_CONFIG_INT, "-splinesteps", NULL, NULL,
	"12", offsetof(LineItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"12", Tk_Offset(LineItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
	NULL, offsetof(LineItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(LineItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_CUSTOM, "-width", NULL, NULL,
	"1.0", offsetof(LineItem, outline.width),
	"1.0", Tk_Offset(LineItem, outline.width),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * The structures below defines the line item type by means of functions that
 * can be invoked by generic item code.
 */

Tk_ItemType tkLineType = {
    "line",				/* name */
    sizeof(LineItem),			/* itemSize */
    CreateLine,				/* createProc */
    configSpecs,			/* configSpecs */
    ConfigureLine,			/* configureProc */
    LineCoords,				/* coordProc */
    DeleteLine,				/* deleteProc */
    DisplayLine,			/* displayProc */
    TK_MOVABLE_POINTS,		/* flags */
    TK_CONFIG_OBJS | TK_MOVABLE_POINTS,	/* flags */
    LineToPoint,			/* pointProc */
    LineToArea,				/* areaProc */
    LineToPostscript,			/* postscriptProc */
    ScaleLine,				/* scaleProc */
    TranslateLine,			/* translateProc */
    GetLineIndex,			/* indexProc */
    NULL,				/* icursorProc */
    NULL,				/* selectionProc */
    LineInsert,				/* insertProc */
    LineDeleteCoords,			/* dTextProc */
    NULL,				/* nextPtr */
    RotateLine,				/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 * The definition below determines how large are static arrays used to hold
 * spline points (splines larger than this have to have their arrays
 * malloc-ed).
 */
279
280
281
282
283
284
285
286

287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
271
272
273
274
275
276
277

278
279
280
281

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306







-
+



-
+
















-
+








static int
CreateLine(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing line. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Carry out initialization that is needed to set defaults and to allow
     * proper cleanup after errors during the the remainder of this function.
     */

    Tk_CreateOutline(&linePtr->outline);
    linePtr->canvas = canvas;
    linePtr->numPoints = 0;
    linePtr->coordPtr = NULL;
    linePtr->capStyle = CapButt;
    linePtr->joinStyle = JoinRound;
    linePtr->arrowGC = NULL;
    linePtr->arrowGC = None;
    linePtr->arrow = ARROWS_NONE;
    linePtr->arrowShapeA = (float)8.0;
    linePtr->arrowShapeB = (float)10.0;
    linePtr->arrowShapeC = (float)3.0;
    linePtr->firstArrowPtr = NULL;
    linePtr->lastArrowPtr = NULL;
    linePtr->smooth = NULL;
358
359
360
361
362
363
364
365

366
367
368
369

370
371
372
373

374
375
376
377
378
379
380
350
351
352
353
354
355
356

357
358
359
360

361
362
363
364

365
366
367
368
369
370
371
372







-
+



-
+



-
+








static int
LineCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    Tcl_Size i, numPoints;
    int i, numPoints;
    double *coordPtr;

    if (objc == 0) {
	Tcl_Size numCoords;
	int numCoords;
	Tcl_Obj *subobj, *obj = Tcl_NewObj();

	numCoords = 2*linePtr->numPoints;
	if (linePtr->firstArrowPtr != NULL) {
	    coordPtr = linePtr->firstArrowPtr;
	} else {
	    coordPtr = linePtr->coordPtr;
396
397
398
399
400
401
402
403

404
405

406
407
408
409
410


411
412
413
414
415
416

417
418
419
420
421
422
423
388
389
390
391
392
393
394

395
396

397
398
399
400


401
402
403
404
405
406
407

408
409
410
411
412
413
414
415







-
+

-
+



-
-
+
+





-
+







	if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		(Tcl_Obj ***) &objv) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    if (objc & 1) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected an even number, got %" TCL_SIZE_MODIFIER "d",
		"wrong # coordinates: expected an even number, got %d",
		objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "LINE", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "LINE", NULL);
	return TCL_ERROR;
    } else if (objc < 4) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected at least 4, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "LINE", (char *)NULL);
		"wrong # coordinates: expected at least 4, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "LINE", NULL);
	return TCL_ERROR;
    }

    numPoints = objc/2;
    if (linePtr->numPoints != numPoints) {
	coordPtr = (double *)ckalloc(sizeof(double) * objc);
	coordPtr = ckalloc(sizeof(double) * objc);
	if (linePtr->coordPtr != NULL) {
	    ckfree(linePtr->coordPtr);
	}
	linePtr->coordPtr = coordPtr;
	linePtr->numPoints = numPoints;
    }
    coordPtr = linePtr->coordPtr;
468
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486
487







-
+












-
+







 */

static int
ConfigureLine(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Line item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    XGCValues gcValues;
    GC newGC, arrowGC;
    unsigned long mask;
    Tk_Window tkwin;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, linePtr, flags)) {
	    (const char **) objv, (char *) linePtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * A few of the options require additional processing, such as graphics
     * contexts.
     */
525
526
527
528
529
530
531
532

533
534

535
536
537

538
539
540
541
542
543
544
517
518
519
520
521
522
523

524
525

526
527
528

529
530
531
532
533
534
535
536







-
+

-
+


-
+








	mask |= GCLineWidth;
#else
	gcValues.line_width = 0;
#endif
	arrowGC = Tk_GetGC(tkwin, mask, &gcValues);
    } else {
	newGC = arrowGC = NULL;
	newGC = arrowGC = None;
    }
    if (linePtr->outline.gc != NULL) {
    if (linePtr->outline.gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), linePtr->outline.gc);
    }
    if (linePtr->arrowGC != NULL) {
    if (linePtr->arrowGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), linePtr->arrowGC);
    }
    linePtr->outline.gc = newGC;
    linePtr->arrowGC = arrowGC;

    /*
     * Keep spline parameters within reasonable limits.
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
621







-
+









-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteLine(
    TCL_UNUSED(Tk_Canvas),		/* Info about overall canvas widget. */
    Tk_Canvas canvas,		/* Info about overall canvas widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    LineItem *linePtr = (LineItem *) itemPtr;

    Tk_DeleteOutline(display, &linePtr->outline);
    if (linePtr->coordPtr != NULL) {
	ckfree(linePtr->coordPtr);
    }
    if (linePtr->arrowGC != NULL) {
    if (linePtr->arrowGC != None) {
	Tk_FreeGC(display, linePtr->arrowGC);
    }
    if (linePtr->firstArrowPtr != NULL) {
	ckfree(linePtr->firstArrowPtr);
    }
    if (linePtr->lastArrowPtr != NULL) {
	ckfree(linePtr->lastArrowPtr);
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664
641
642
643
644
645
646
647


648
649
650
651
652
653
654
655







-
-
+








static void
ComputeLineBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    LineItem *linePtr)		/* Item whose bbos is to be recomputed. */
{
    double *coordPtr;
    Tcl_Size i;
    int intWidth;
    int i, intWidth;
    double width;
    Tk_State state = linePtr->header.state;
    Tk_TSOffset *tsoffset;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }
710
711
712
713
714
715
716
717

718
719
720
721
722
723
724
701
702
703
704
705
706
707

708
709
710
711
712
713
714
715







-
+







	if (linePtr->arrow != ARROWS_FIRST) {
	    TkIncludePoint((Tk_Item *) linePtr, linePtr->lastArrowPtr);
	}
    }

    tsoffset = &linePtr->outline.tsoffset;
    if (tsoffset->flags & TK_OFFSET_INDEX) {
	coordPtr = linePtr->coordPtr
	double *coordPtr = linePtr->coordPtr
		+ (tsoffset->flags & ~TK_OFFSET_INDEX);

	if (tsoffset->flags <= 0) {
	    coordPtr = linePtr->coordPtr;
	    if ((linePtr->arrow == ARROWS_FIRST)
		    || (linePtr->arrow == ARROWS_BOTH)) {
		coordPtr = linePtr->firstArrowPtr;
834
835
836
837
838
839
840

841
842


843
844
845
846

847
848
849
850
851
852
853

854
855
856
857
858
859
860
825
826
827
828
829
830
831
832


833
834


835

836
837
838
839
840
841
842

843
844
845
846
847
848
849
850







+
-
-
+
+
-
-

-
+






-
+








static void
DisplayLine(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    Tk_Item *itemPtr,		/* Item to be displayed. */
    Display *display,		/* Display on which to draw item. */
    Drawable drawable,		/* Pixmap or window in which to draw item. */
    int x, int y, int width, int height)
    TCL_UNUSED(int),		/* Describes region of canvas that must be */
    TCL_UNUSED(int),		/* redisplayed (not used). */
				/* Describes region of canvas that must be
				 * redisplayed (not used). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    LineItem *linePtr = (LineItem *)itemPtr;
    LineItem *linePtr = (LineItem *) itemPtr;
    XPoint staticPoints[MAX_STATIC_POINTS*3];
    XPoint *pointPtr;
    double linewidth;
    int numPoints;
    Tk_State state = itemPtr->state;

    if (!linePtr->numPoints || (linePtr->outline.gc == NULL)) {
    if ((!linePtr->numPoints) || (linePtr->outline.gc == None)) {
	return;
    }

    if (state == TK_STATE_NULL) {
	    state = Canvas(canvas)->canvas_state;
    }
    linewidth = linePtr->outline.width;
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884







-
+







    } else {
	numPoints = linePtr->numPoints;
    }

    if (numPoints <= MAX_STATIC_POINTS) {
	pointPtr = staticPoints;
    } else {
	pointPtr = (XPoint *)ckalloc(numPoints * 3 * sizeof(XPoint));
	pointPtr = ckalloc(numPoints * 3 * sizeof(XPoint));
    }

    if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
	numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
		linePtr->numPoints, linePtr->splineSteps, pointPtr, NULL);
    } else {
	numPoints = TkCanvTranslatePath((TkCanvas *) canvas, numPoints,
956
957
958
959
960
961
962
963

964
965
966
967
968

969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058



1059
1060
1061
1062
1063
1064
1065
1066
1067
1068





1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088




1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111






1112
1113
1114
1115
1116
1117
1118
1119
1120
1121









1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133











1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164

1165
1166
1167
1168
1169
1170
1171
946
947
948
949
950
951
952

953
954
955
956
957

958
959
960
961
962
963
964
965
966
967
968
969
970

971

972
973
974
975
976
977






978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016


1017
1018
1019
1020






1021












1022
1023
1024










1025
1026
1027
1028
1029




















1030
1031
1032
1033





1034

1035
1036















1037
1038
1039
1040
1041
1042
1043









1044
1045
1046
1047
1048
1049
1050
1051
1052
1053











1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064


1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092

1093
1094
1095
1096
1097
1098
1099
1100







-
+




-
+












-

-






-
-
-
-
-
-








-
+












-
+












-
+




-
-




-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
















-
+









-
+

-
+







 *--------------------------------------------------------------
 */

static void
LineInsert(
    Tk_Canvas canvas,		/* Canvas containing text item. */
    Tk_Item *itemPtr,		/* Line item to be modified. */
    Tcl_Size beforeThis,		/* Index before which new coordinates are to
    int beforeThis,		/* Index before which new coordinates are to
				 * be inserted. */
    Tcl_Obj *obj)		/* New coordinates to be inserted. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    Tcl_Size length, oriNumPoints, objc, nbInsPoints, i;
    int length, objc, i;
    double *newCoordPtr, *coordPtr;
    Tk_State state = itemPtr->state;
    Tcl_Obj **objv;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK)
	    || !objc || objc&1) {
	return;
    }
    oriNumPoints = linePtr->numPoints;
    length = 2*linePtr->numPoints;
    nbInsPoints = objc / 2;
    if (beforeThis < 0) {
	beforeThis = 0;
    }
    if (beforeThis > length) {
	beforeThis = length;
    }

    /*
     * With arrows, the end points of the line are adjusted so that a thick
     * line doesn't stick out past the arrowheads (see ConfigureArrows).
     */

    if (linePtr->firstArrowPtr != NULL) {
	linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
	linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
    }
    if (linePtr->lastArrowPtr != NULL) {
	linePtr->coordPtr[length-2] = linePtr->lastArrowPtr[0];
	linePtr->coordPtr[length-1] = linePtr->lastArrowPtr[1];
    }
    newCoordPtr = (double *)ckalloc(sizeof(double) * (length + objc));
    newCoordPtr = ckalloc(sizeof(double) * (length + objc));
    for (i=0; i<beforeThis; i++) {
	newCoordPtr[i] = linePtr->coordPtr[i];
    }
    for (i=0; i<objc; i++) {
	if (Tcl_GetDoubleFromObj(NULL, objv[i],
		&newCoordPtr[i + beforeThis]) != TCL_OK) {
	    Tcl_ResetResult(Canvas(canvas)->interp);
	    ckfree(newCoordPtr);
	    return;
	}
    }

    for (i=(int)beforeThis; i<length; i++) {
    for (i=beforeThis; i<length; i++) {
	newCoordPtr[i+objc] = linePtr->coordPtr[i];
    }
    if (linePtr->coordPtr) {
        ckfree(linePtr->coordPtr);
    }
    linePtr->coordPtr = newCoordPtr;
    length += objc ;
    linePtr->numPoints = length / 2;

    if ((length > 3) && (state != TK_STATE_HIDDEN)) {
	/*
	 * This is some optimizing code that will result that only the part of
	 * the line that changed (and the objects that are overlapping with
	 * the polygon that changed (and the objects that are overlapping with
	 * that part) need to be redrawn. A special flag is set that instructs
	 * the general canvas code not to redraw the whole object. If this
	 * flag is not set, the canvas will do the redrawing, otherwise I have
	 * to do it here.
	 * Rationale for the optimization code can be found in Tk ticket
	 * [5fb8145997].
	 */

	itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;

	/*
	 * Include one point at left of the left insert position, and one
	 * point at right of the right insert position.
	 */

	beforeThis -= 2;
	if (beforeThis > 0) {
	objc += 4;

	if (linePtr->smooth) {
	    if (!strcmp(linePtr->smooth->name, "true")) {
		/*
		 * Quadratic Bezier splines. A second point must be included at
		 * each side of the insert position.
		 */

		beforeThis -= 2;
		objc += 4;

	    beforeThis -= 2;
	    objc += 2;
	}
		/*
		 * Moreover, if the insert position is the first or last point
		 * of the line, include a third point.
		 */

		if (beforeThis == (Tcl_Size)-4) {
		    objc += 2;
		}
		if (beforeThis + 4 == length - (objc - 8)) {
		    beforeThis -= 2;
	if (beforeThis+objc < length) {
	    objc += 2;
	}
	if (linePtr->smooth) {
	    if (beforeThis > 0) {
		    objc += 2;
		}

	    } else if (!strcmp(linePtr->smooth->name, "raw")) {
		/*
		 * Cubic Bezier splines. See details in ticket [5fb8145997].
		 */

		if (((oriNumPoints - 1) % 3) || (nbInsPoints % 3)) {
		    /*
		     * No optimization for "degenerate" lines or when inserting
		     * something else than a multiple of 3 points.
		     */

		    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
		} else {
		    beforeThis -= (int)beforeThis % 6;
		    objc += 4;
		}

		beforeThis -= 2;
		objc += 2;
	    }
	    if (beforeThis+objc+2 < length) {
	    } else {
		/*
		 * Custom smoothing method. No optimization is possible.
		 */

		objc += 2;
		itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    }
	}

	if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
	    if ((int)beforeThis < 0) {
		beforeThis = 0;
	    }
	    if ((int)beforeThis + objc > length) {
		objc = length - (int)beforeThis;
	    }

	    itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[beforeThis];
	    itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[beforeThis+1];
	    if ((linePtr->firstArrowPtr != NULL) && ((int)beforeThis < 2)) {
		/*
		 * Include old first arrow.
		 */
	itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[beforeThis];
	itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[beforeThis+1];
	if ((linePtr->firstArrowPtr != NULL) && (beforeThis < 1)) {
	    /*
	     * Include old first arrow.
	     */

		for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
			i++, coordPtr += 2) {
		    TkIncludePoint(itemPtr, coordPtr);
		}
	    }
	    if ((linePtr->lastArrowPtr != NULL) && ((int)beforeThis+objc >= length)) {
		/*
		 * Include old last arrow.
		 */
	    for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
	if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc >= length)) {
	    /*
	     * Include old last arrow.
	     */

		for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
			i++, coordPtr += 2) {
		    TkIncludePoint(itemPtr, coordPtr);
		}
	    }
	    coordPtr = linePtr->coordPtr + beforeThis;
	    for (i=0; i<objc; i+=2) {
		TkIncludePoint(itemPtr, coordPtr);
		coordPtr += 2;
	    }
	}
	    for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
	coordPtr = linePtr->coordPtr + beforeThis + 2;
	for (i=2; i<objc; i+=2) {
	    TkIncludePoint(itemPtr, coordPtr);
	    coordPtr += 2;
	}
    }
    }

    if (linePtr->firstArrowPtr != NULL) {
	ckfree(linePtr->firstArrowPtr);
	linePtr->firstArrowPtr = NULL;
    }
    if (linePtr->lastArrowPtr != NULL) {
	ckfree(linePtr->lastArrowPtr);
	linePtr->lastArrowPtr = NULL;
    }
    if (linePtr->arrow != ARROWS_NONE) {
	ConfigureArrows(canvas, linePtr);
    }

    if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
	double width;
	int intWidth;

	if ((linePtr->firstArrowPtr != NULL) && ((int)beforeThis < 2)) {
	if ((linePtr->firstArrowPtr != NULL) && (beforeThis > 2)) {
	    /*
	     * Include new first arrow.
	     */

	    for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
	if ((linePtr->lastArrowPtr != NULL) && ((int)beforeThis+objc >= length)) {
	if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc < length-2)) {
	    /*
	     * Include new last arrow.
	     * Include new right arrow.
	     */

	    for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
1211
1212
1213
1214
1215
1216
1217
1218
1219


1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

1234
1235
1236

1237
1238
1239
1240


1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268

1269
1270

1271
1272

1273
1274
1275
1276
1277
1278
1279
1280
1281


1282
1283
1284
1285
1286
1287


1288
1289
1290
1291
1292
1293



1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1140
1141
1142
1143
1144
1145
1146


1147
1148
1149
1150

1151


1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162

1163
1164
1165


1166
1167
1168

1169
1170
1171






1172
1173
1174
1175
1176
1177
1178
1179
1180
1181


1182






1183


1184


1185









1186
1187






1188
1189






1190
1191
1192


















1193
1194
1195




1196












1197
1198
1199
1200
1201
1202
1203
1204


1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227







-
-
+
+


-
+
-
-








-
+


-
+


-
-
+
+

-
+


-
-
-
-
-
-










-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+







-
-















-
+







 *--------------------------------------------------------------
 */

static void
LineDeleteCoords(
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Item in which to delete characters. */
    Tcl_Size first,			/* Index of first character to delete. */
    Tcl_Size last)			/* Index of last character to delete. */
    int first,			/* Index of first character to delete. */
    int last)			/* Index of last character to delete. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    int count, i, first1, last1, nbDelPoints;
    int count, i, first1, last1;
    int oriNumPoints = linePtr->numPoints;
    int canOptimize = 1;
    int length = 2*linePtr->numPoints;
    double *coordPtr;
    Tk_State state = itemPtr->state;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    first &= -2;	/* If odd, make it even. */
    first &= -2;
    last &= -2;

    if ((int)first < 0) {
    if (first < 0) {
	first = 0;
    }
    if ((int)last >= length) {
	last = length - 2;
    if (last >= length) {
	last = length-2;
    }
    if ((int)first > (int)last) {
    if (first > last) {
	return;
    }

    /*
     * With arrows, the end points of the line are adjusted so that a thick
     * line doesn't stick out past the arrowheads (see ConfigureArrows).
     */

    if (linePtr->firstArrowPtr != NULL) {
	linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
	linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
    }
    if (linePtr->lastArrowPtr != NULL) {
	linePtr->coordPtr[length-2] = linePtr->lastArrowPtr[0];
	linePtr->coordPtr[length-1] = linePtr->lastArrowPtr[1];
    }
    first1 = first;
    last1 = last;
    nbDelPoints = (last - first) / 2 + 1;

    if (first1 > 0) {
    /*
     * Include one point at left of the left delete position, and one
     * point at right of the right delete position.
     */

    first1 -= 2;
	first1 -= 2;
    last1 += 2;

    }
    if (linePtr->smooth) {

    if (last1 < length-2) {
	if (!strcmp(linePtr->smooth->name, "true")) {
	    /*
	     * Quadratic Bezier splines. A second point must be included at
	     * each side of the delete position.
	     */

	    first1 -= 2;
	    last1 += 2;

	last1 += 2;
    }
	    /*
	     * If the delete position is the first or last point of the line,
	     * include a third point.
	     */

	    if (first1 == -4) {
    if (linePtr->smooth) {
	if (first1 > 0) {
		last1 += 2;
	    }
	    if (last1 - 4 == length - 2) {
		first1 -= 2;
	    }

	    first1 -= 2;
	}
	if (last1 < length-2) {
	} else if (!strcmp(linePtr->smooth->name, "raw")) {
	    /*
	     * Cubic Bezier splines. See details in ticket [5fb8145997].
	     */

	    if (((oriNumPoints - 1) % 3) || (nbDelPoints % 3)) {
		/*
		 * No optimization for "degenerate" lines or when deleting
		 * something else than a multiple of 3 points.
		 */

		canOptimize = 0;
	    }
	    else {
		first1 -= first1 % 6;
		last1 = last + 6 - last % 6;
	    }

	    last1 += 2;
	}
    }
	} else {
	    /*
	     * Custom smoothing method. No optimization is possible.
	     */

	    canOptimize = 0;
	}
    }

    if (first1 < 0) {
	first1 = 0;
    }
    if (last1 >= length) {
	last1 = length - 2;
    }

    if (canOptimize && ((first1 >= 2) || (last1 < length-2))) {
    if ((first1 >= 2) || (last1 < length-2)) {
	/*
	 * This is some optimizing code that will result that only the part of
	 * the line that changed (and the objects that are overlapping with
	 * that part) need to be redrawn. A special flag is set that instructs
	 * the general canvas code not to redraw the whole object. If this
	 * flag is set, the redrawing has to be done here, otherwise the
	 * general Canvas code will take care of it.
	 * Rationale for the optimization code can be found in Tk ticket
	 * [5fb8145997].
	 */

	itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
	itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[first1];
	itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[first1+1];
	if ((linePtr->firstArrowPtr != NULL) && (first1 < 2)) {
	    /*
	     * Include old first arrow.
	     */

	    for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
	if ((linePtr->lastArrowPtr != NULL) && (last1 >= length - 2)) {
	if ((linePtr->lastArrowPtr != NULL) && (last1 >= length-2)) {
	    /*
	     * Include old last arrow.
	     */

	    for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402

1403
1404
1405
1406
1407
1408
1409
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1264
1265
1266

1267
1268

1269
1270
1271
1272
1273
1274
1275
1276







-
+









-
+

-
+







    if (linePtr->arrow != ARROWS_NONE) {
	ConfigureArrows(canvas, linePtr);
    }
    if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
	double width;
	int intWidth;

	if ((linePtr->firstArrowPtr != NULL) && (first1 < 2)) {
	if ((linePtr->firstArrowPtr != NULL) && (first1 < 4)) {
	    /*
	     * Include new first arrow.
	     */

	    for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
	if ((linePtr->lastArrowPtr != NULL) && (last1 >= length - 2)) {
	if ((linePtr->lastArrowPtr != NULL) && (last1 > length-4)) {
	    /*
	     * Include new last arrow.
	     * Include new right arrow.
	     */

	    for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
		    i++, coordPtr += 2) {
		TkIncludePoint(itemPtr, coordPtr);
	    }
	}
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
LineToPoint(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    Tk_State state = itemPtr->state;
1492
1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1374







-
+








    if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
	numPoints = linePtr->smooth->coordProc(canvas, NULL,
		linePtr->numPoints, linePtr->splineSteps, NULL, NULL);
	if (numPoints <= MAX_STATIC_POINTS) {
	    linePoints = staticSpace;
	} else {
	    linePoints = (double *)ckalloc(2 * numPoints * sizeof(double));
	    linePoints = ckalloc(2 * numPoints * sizeof(double));
	}
	numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
		linePtr->numPoints, linePtr->splineSteps, NULL, linePoints);
    } else {
	numPoints = linePtr->numPoints;
	linePoints = linePtr->coordPtr;
    }
1674
1675
1676
1677
1678
1679
1680

1681
1682
1683
1684
1685
1686
1687
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
LineToArea(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against line. */
    double *rectPtr)
{
    LineItem *linePtr = (LineItem *) itemPtr;
1726
1727
1728
1729
1730
1731
1732
1733

1734
1735
1736
1737
1738
1739
1740
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1609







-
+








    if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
	numPoints = linePtr->smooth->coordProc(canvas, NULL,
		linePtr->numPoints, linePtr->splineSteps, NULL, NULL);
	if (numPoints <= MAX_STATIC_POINTS) {
	    linePoints = staticSpace;
	} else {
	    linePoints = (double *)ckalloc(2 * numPoints * sizeof(double));
	    linePoints = ckalloc(2 * numPoints * sizeof(double));
	}
	numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
		linePtr->numPoints, linePtr->splineSteps, NULL, linePoints);
    } else {
	numPoints = linePtr->numPoints;
	linePoints = linePtr->coordPtr;
    }
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
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







-
+













+
+







    double originX, double originY,
				/* Origin about which to scale rect. */
    double scaleX,		/* Amount to scale in X direction. */
    double scaleY)		/* Amount to scale in Y direction. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    double *coordPtr;
    Tcl_Size i;
    int i;

    /*
     * Delete any arrowheads before scaling all the points (so that the
     * end-points of the line get restored).
     */

    if (linePtr->firstArrowPtr != NULL) {
	linePtr->coordPtr[0] = linePtr->firstArrowPtr[0];
	linePtr->coordPtr[1] = linePtr->firstArrowPtr[1];
	ckfree(linePtr->firstArrowPtr);
	linePtr->firstArrowPtr = NULL;
    }
    if (linePtr->lastArrowPtr != NULL) {
	int i;

	i = 2*(linePtr->numPoints-1);
	linePtr->coordPtr[i] = linePtr->lastArrowPtr[0];
	linePtr->coordPtr[i+1] = linePtr->lastArrowPtr[1];
	ckfree(linePtr->lastArrowPtr);
	linePtr->lastArrowPtr = NULL;
    }
    for (i = 0, coordPtr = linePtr->coordPtr; i < linePtr->numPoints;
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
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







-
+




-
+

-

-
+

-
-
+
-
-
-
+
+

-
-
-
-
-
-
+
-
-
-
-
+
+
+

-
-
+
+


-
-
+
+


-
-
+
-
-
-
-
-
-
+
-
-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-







 *
 *--------------------------------------------------------------
 */

static int
GetLineIndex(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item for which the index is being
				 * specified. */
    Tcl_Obj *obj,		/* Specification of a particular coord in
				 * itemPtr's line. */
    Tcl_Size *indexPtr)		/* Where to store converted index. */
    int *indexPtr)		/* Where to store converted index. */
{
    Tcl_Size idx, length;
    LineItem *linePtr = (LineItem *) itemPtr;
    char *string;
    const char *string = Tcl_GetString(obj);

    if (TCL_OK == TkGetIntForIndex(obj, 2*linePtr->numPoints - 1, 1, &idx)) {
	if (idx < 0) {
    if (string[0] == 'e') {
	    idx = 0;
	} else if (idx > (2*(Tcl_Size)linePtr->numPoints)) {
	    idx = 2*linePtr->numPoints;
	if (strncmp(string, "end", obj->length) == 0) {
	    *indexPtr = 2*linePtr->numPoints;
	} else {
	    idx &= (Tcl_Size)-2;	/* If index is odd, make it even. */
	}
	*indexPtr = idx;
	return TCL_OK;
    }

	    goto badIndex;
    string = Tcl_GetStringFromObj(obj, &length);

    if (string[0] == '@') {
	Tcl_Size i;
	}
    } else if (string[0] == '@') {
	int i;
	double x, y, bestDist, dist, *coordPtr;
	char savechar;
	char *p, *sep;
	char *end;
	const char *p;

	p = string+1;
	sep = strchr(p, ',');
	if (!sep) {
	x = strtod(p, &end);
	if ((end == p) || (*end != ',')) {
	    goto badIndex;
	}
	savechar = *sep;
	*sep = '\0';
	p = end+1;
	i = Tcl_GetDouble(NULL, p, &x);
	*sep = savechar;
	if (i != TCL_OK) {
	    goto badIndex;
	}
	p = sep+1;
	y = strtod(p, &end);
	i = Tcl_GetDouble(NULL, p, &y);
	if (i != TCL_OK) {
	if ((end == p) || (*end != 0)) {
	    goto badIndex;
	}
	bestDist = 1.0e36;
	coordPtr = linePtr->coordPtr;
	*indexPtr = 0;
	for (i=0; i<linePtr->numPoints; i++) {
	    dist = hypot(coordPtr[0] - x, coordPtr[1] - y);
	    if (dist < bestDist) {
		bestDist = dist;
		*indexPtr = 2*i;
	    }
	    coordPtr += 2;
	}
    } else {
	if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) {
	    goto badIndex;
	}
	*indexPtr &= -2;	/* If index is odd, make it even. */
	if (*indexPtr < 0){
	    *indexPtr = 0;
	} else if (*indexPtr > (2*linePtr->numPoints)) {
	    *indexPtr = (2*linePtr->numPoints);
	}
    }
    return TCL_OK;

    /*
     * Some of the paths here leave messages in interp->result, so we have to
     * clear it out before storing our own message.
     */

    badIndex:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "LINE", (char *)NULL);
	return TCL_ERROR;
  badIndex:
    Tcl_ResetResult(interp);
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "LINE", NULL);
    return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * TranslateLine --
 *
1954
1955
1956
1957
1958
1959
1960
1961

1962
1963
1964
1965
1966
1967
1968
1825
1826
1827
1828
1829
1830
1831

1832
1833
1834
1835
1836
1837
1838
1839







-
+







    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item that is being moved. */
    double deltaX, double deltaY)
				/* Amount by which item is to be moved. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    double *coordPtr;
    Tcl_Size i;
    int i;

    for (i = 0, coordPtr = linePtr->coordPtr; i < linePtr->numPoints;
	    i++, coordPtr += 2) {
	coordPtr[0] += deltaX;
	coordPtr[1] += deltaY;
    }
    if (linePtr->firstArrowPtr != NULL) {
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















+


-
+

-
+



-
+




-
+


-
+







    }
    ComputeLineBbox(canvas, linePtr);
}

/*
 *--------------------------------------------------------------
 *
 * RotateLine --
 *
 *	This function is called to rotate a line by a given amount about a
 *	point.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the line is rotated by angleRad about (originX,
 *	originY), and the bounding box is updated in the generic part of the
 *	item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateLine(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item that is being moved. */
    double originX, double originY,
    double angleRad)		/* Amount by which item is to be rotated. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    double *coordPtr;
    Tcl_Size i;
    double s = sin(angleRad), c = cos(angleRad);

    for (i = 0, coordPtr = linePtr->coordPtr; i < linePtr->numPoints;
	    i++, coordPtr += 2) {
	TkRotatePoint(originX, originY, s, c, &coordPtr[0], &coordPtr[1]);
    }
    if (linePtr->firstArrowPtr != NULL) {
	for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW;
		i++, coordPtr += 2) {
	    TkRotatePoint(originX, originY, s, c, &coordPtr[0], &coordPtr[1]);
	}
    }
    if (linePtr->lastArrowPtr != NULL) {
	for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW;
		i++, coordPtr += 2) {
	    TkRotatePoint(originX, originY, s, c, &coordPtr[0], &coordPtr[1]);
	}
    }
    ComputeLineBbox(canvas, linePtr);
}

/*
 *--------------------------------------------------------------
 *
 * ParseArrowShape --
 *
 *	This function is called back during option parsing to parse arrow
 *	shape information.
 *
 * Results:
 *	The return value is a standard Tcl result: TCL_OK means that the arrow
 *	shape information was parsed ok, and TCL_ERROR means it couldn't be
 *	parsed.
 *
 * Side effects:
 *	Arrow information in recordPtr is updated.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ParseArrowShape(
    TCL_UNUSED(void *),	/* Not used. */
    ClientData clientData,	/* Not used. */
    Tcl_Interp *interp,		/* Used for error reporting. */
    TCL_UNUSED(Tk_Window),		/* Not used. */
    Tk_Window tkwin,		/* Not used. */
    const char *value,		/* Textual specification of arrow shape. */
    char *recordPtr,		/* Pointer to item record in which to store
				 * arrow information. */
    Tcl_Size offset)			/* Offset of shape information in widget
    int offset)			/* Offset of shape information in widget
				 * record. */
{
    LineItem *linePtr = (LineItem *) recordPtr;
    double a, b, c;
    Tcl_Size argc;
    int argc;
    const char **argv = NULL;

    if ((size_t)offset != offsetof(LineItem, arrowShapeA)) {
    if (offset != Tk_Offset(LineItem, arrowShapeA)) {
	Tcl_Panic("ParseArrowShape received bogus offset");
    }

    if (Tcl_SplitList(interp, (char *) value, &argc, &argv) != TCL_OK) {
	goto syntaxError;
    } else if (argc != 3) {
	goto syntaxError;
2091
2092
2093
2094
2095
2096
2097
2098

2099
2100
2101
2102
2103
2104
2105
1913
1914
1915
1916
1917
1918
1919

1920
1921
1922
1923
1924
1925
1926
1927







-
+







    return TCL_OK;

  syntaxError:
    Tcl_ResetResult(interp);
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad arrow shape \"%s\": must be list with three numbers",
	    value));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARROW_SHAPE", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARROW_SHAPE", NULL);
    if (argv != NULL) {
	ckfree(argv);
    }
    return TCL_ERROR;
}

/*
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
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







+


-
-
+
+


-
+




-
+

-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

    /* ARGSUSED */
static const char *
PrintArrowShape(
    TCL_UNUSED(void *),	/* Not used. */
    TCL_UNUSED(Tk_Window),		/* Window associated with linePtr's widget. */
    ClientData clientData,	/* Not used. */
    Tk_Window tkwin,		/* Window associated with linePtr's widget. */
    char *recordPtr,		/* Pointer to item record containing current
				 * shape information. */
    TCL_UNUSED(Tcl_Size),			/* Offset of arrow information in record. */
    int offset,			/* Offset of arrow information in record. */
    Tcl_FreeProc **freeProcPtr)	/* Store address of function to call to free
				 * string here. */
{
    LineItem *linePtr = (LineItem *) recordPtr;
    char *buffer = (char *)ckalloc(120);
    char *buffer = ckalloc(120);

    snprintf(buffer, 120, "%.5g %.5g %.5g", linePtr->arrowShapeA,
    sprintf(buffer, "%.5g %.5g %.5g", linePtr->arrowShapeA,
	    linePtr->arrowShapeB, linePtr->arrowShapeC);
    *freeProcPtr = TCL_DYNAMIC;
    return buffer;
}

/*
 *--------------------------------------------------------------
2154
2155
2156
2157
2158
2159
2160
2161

2162
2163

2164
2165
2166

2167
2168
2169

2170

2171
2172
2173
2174
2175
2176
2177
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







-
+

-
+


-
+



+
-
+







 *	value argument.
 *
 *--------------------------------------------------------------
 */

static int
ArrowParseProc(
    TCL_UNUSED(void *),
    ClientData clientData,	/* some flags.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    int c;
    size_t length;

    Arrows *arrowPtr = (Arrows *) (widgRec + offset);
    register Arrows *arrowPtr = (Arrows *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*arrowPtr = ARROWS_NONE;
	return TCL_OK;
    }

    c = value[0];
2193
2194
2195
2196
2197
2198
2199
2200

2201
2202
2203
2204
2205
2206
2207
2017
2018
2019
2020
2021
2022
2023

2024
2025
2026
2027
2028
2029
2030
2031







-
+







	*arrowPtr = ARROWS_BOTH;
	return TCL_OK;
    }

    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad arrow spec \"%s\": must be none, first, last, or both",
	    value));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARROW", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ARROW", NULL);
    *arrowPtr = ARROWS_NONE;
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
2221
2222
2223
2224
2225
2226
2227
2228
2229


2230
2231
2232


2233
2234
2235
2236

2237
2238
2239
2240
2241
2242
2243
2045
2046
2047
2048
2049
2050
2051


2052
2053
2054


2055
2056
2057
2058
2059

2060
2061
2062
2063
2064
2065
2066
2067







-
-
+
+

-
-
+
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static const char *
ArrowPrintProc(
    TCL_UNUSED(void *),	/* Ignored. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset into item. */
    TCL_UNUSED(Tcl_FreeProc **))	/* Pointer to variable to fill in with
    int offset,			/* Offset into item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    Arrows *arrowPtr = (Arrows *) (widgRec + offset);
    register Arrows *arrowPtr = (Arrows *) (widgRec + offset);

    switch (*arrowPtr) {
    case ARROWS_FIRST:
	return "first";
    case ARROWS_LAST:
	return "last";
    case ARROWS_BOTH:
2263
2264
2265
2266
2267
2268
2269

2270
2271
2272
2273
2274
2275
2276
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101







+







 *	firstArrowPtr and lastArrowPtr polygons are allocated and initialized,
 *	if need be, and the end points of the line are adjusted so that a
 *	thick line doesn't stick out past the arrowheads.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ConfigureArrows(
    Tk_Canvas canvas,		/* Canvas in which arrows will be displayed
				 * (interp and tkwin fields are needed). */
    LineItem *linePtr)		/* Item to configure for arrows. */
{
    double *poly, *coordPtr;
2323
2324
2325
2326
2327
2328
2329
2330

2331
2332
2333
2334
2335
2336
2337
2148
2149
2150
2151
2152
2153
2154

2155
2156
2157
2158
2159
2160
2161
2162







-
+







     */

    fracHeight = (width/2.0)/shapeC;
    backup = fracHeight*shapeB + shapeA*(1.0 - fracHeight)/2.0;
    if (linePtr->arrow != ARROWS_LAST) {
	poly = linePtr->firstArrowPtr;
	if (poly == NULL) {
	    poly = (double *)ckalloc(2 * PTS_IN_ARROW * sizeof(double));
	    poly = ckalloc(2 * PTS_IN_ARROW * sizeof(double));
	    poly[0] = poly[10] = linePtr->coordPtr[0];
	    poly[1] = poly[11] = linePtr->coordPtr[1];
	    linePtr->firstArrowPtr = poly;
	}
	dx = poly[0] - linePtr->coordPtr[2];
	dy = poly[1] - linePtr->coordPtr[3];
	length = hypot(dx, dy);
2367
2368
2369
2370
2371
2372
2373
2374

2375
2376
2377
2378
2379
2380
2381
2192
2193
2194
2195
2196
2197
2198

2199
2200
2201
2202
2203
2204
2205
2206







-
+







     * Similar arrowhead calculation for the last point of the line.
     */

    if (linePtr->arrow != ARROWS_FIRST) {
	coordPtr = linePtr->coordPtr + 2*(linePtr->numPoints-2);
	poly = linePtr->lastArrowPtr;
	if (poly == NULL) {
	    poly = (double *)ckalloc(2 * PTS_IN_ARROW * sizeof(double));
	    poly = ckalloc(2 * PTS_IN_ARROW * sizeof(double));
	    poly[0] = poly[10] = coordPtr[2];
	    poly[1] = poly[11] = coordPtr[3];
	    linePtr->lastArrowPtr = poly;
	}
	dx = poly[0] - coordPtr[0];
	dy = poly[1] - coordPtr[1];
	length = hypot(dx, dy);
2424
2425
2426
2427
2428
2429
2430
2431

2432
2433
2434
2435
2436
2437
2438
2249
2250
2251
2252
2253
2254
2255

2256
2257
2258
2259
2260
2261
2262
2263







-
+







 */

static int
LineToPostscript(
    Tcl_Interp *interp,		/* Leave Postscript or error message here. */
    Tk_Canvas canvas,		/* Information about overall canvas. */
    Tk_Item *itemPtr,		/* Item for which Postscript is wanted. */
    TCL_UNUSED(int))		/* 1 means this is a prepass to collect font
    int prepass)		/* 1 means this is a prepass to collect font
				 * information; 0 means final Postscript is
				 * being created. */
{
    LineItem *linePtr = (LineItem *) itemPtr;
    int style;
    double width;
    XColor *color;
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
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







-
+




-
+


-
+
+
+



-
+

-
+
+
+


-
+







    interpState = Tcl_SaveInterpState(interp, TCL_OK);

    /*
     * Check if we're just doing a "pixel".
     */

    if (linePtr->numPoints == 1) {
	Tcl_AppendToObj(psObj, "matrix currentmatrix\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "matrix currentmatrix\n", -1);
	Tcl_AppendPrintfToObj(psObj, "%.15g %.15g translate %.15g %.15g",
		linePtr->coordPtr[0], Tk_CanvasPsY(canvas, linePtr->coordPtr[1]),
		width/2.0, width/2.0);
	Tcl_AppendToObj(psObj,
		" scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", TCL_INDEX_NONE);
		" scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", -1);

	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, color);
	if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (stipple != None) {
	    Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "clip ", -1);
	    Tcl_ResetResult(interp);
	    Tk_CanvasPsStipple(interp, canvas, stipple);
	    if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	} else {
	    Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "fill\n", -1);
	}
	goto done;
    }

    /*
     * Generate a path for the line's center-line (do this differently for
     * straight lines and smoothed lines).
2532
2533
2534
2535
2536
2537
2538
2539

2540
2541
2542
2543
2544
2545
2546
2361
2362
2363
2364
2365
2366
2367

2368
2369
2370
2371
2372
2373
2374
2375







-
+







	double *pointPtr;
	int numPoints;

	numPoints = linePtr->smooth->coordProc(canvas, NULL,
		linePtr->numPoints, linePtr->splineSteps, NULL, NULL);
	pointPtr = staticPoints;
	if (numPoints > MAX_STATIC_POINTS) {
	    pointPtr = (double *)ckalloc(numPoints * 2 * sizeof(double));
	    pointPtr = ckalloc(numPoints * 2 * sizeof(double));
	}
	numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
		linePtr->numPoints, linePtr->splineSteps, NULL, pointPtr);
	Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints);
	if (pointPtr != staticPoints) {
	    ckfree(pointPtr);
	}
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
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







-
+
+
+








-
+

-
-
+
+
+
+



-
+

-
-
+
+
+
+











+
+
+
+
+







	style = 2;
    } else {
	style = 0;
    }
    Tcl_AppendPrintfToObj(psObj, "%d setlinejoin\n", style);

    Tcl_ResetResult(interp);
    Tk_CanvasPsOutline(canvas, itemPtr, &linePtr->outline);
    if (Tk_CanvasPsOutline(canvas, itemPtr, &linePtr->outline) != TCL_OK) {
	goto error;
    }
    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

    /*
     * Output polygons for the arrowheads, if there are any.
     */

    if (linePtr->firstArrowPtr != NULL) {
	if (stipple != None) {
	    Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
	}
	ArrowheadPostscript(interp, canvas, linePtr,
		linePtr->firstArrowPtr, psObj);
	if (ArrowheadPostscript(interp, canvas, linePtr,
		linePtr->firstArrowPtr, psObj) != TCL_OK) {
	    goto error;
	}
    }
    if (linePtr->lastArrowPtr != NULL) {
	if (stipple != None) {
	    Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
	}
	ArrowheadPostscript(interp, canvas, linePtr,
		linePtr->lastArrowPtr, psObj);
	if (ArrowheadPostscript(interp, canvas, linePtr,
		linePtr->lastArrowPtr, psObj) != TCL_OK) {
	    goto error;
	}
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

  done:
    (void) Tcl_RestoreInterpState(interp, interpState);
    Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    Tcl_DecrRefCount(psObj);
    return TCL_OK;

  error:
    Tcl_DiscardInterpState(interpState);
    Tcl_DecrRefCount(psObj);
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * ArrowheadPostscript --
 *
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
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







-
+


-
+
+
+


-
+











    }

    Tcl_ResetResult(interp);
    Tk_CanvasPsPath(interp, canvas, arrowPtr, PTS_IN_ARROW);
    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

    if (stipple != None) {
	Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "clip ", -1);

	Tcl_ResetResult(interp);
	Tk_CanvasPsStipple(interp, canvas, stipple);
	if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
    } else {
	Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "fill\n", -1);
    }
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCanvPoly.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22





-
-
-
+
+
+







-







/*
 * tkCanvPoly.c --
 *
 *	This file implements polygon items for canvas widgets.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Ajuba Solutions.
 * Copyright (c) 1991-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 Ajuba Solutions.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

/*
 * The structure below defines the record for each polygon item.
 */

typedef struct PolygonItem  {
    Tk_Item header;		/* Generic stuff that's the same for all
73
74
75
76
77
78
79
80

81
82
83

84
85

86
87

88
89
90

91
92

93
94
95

96
97
98

99
100
101

102
103
104

105
106

107
108
109

110
111
112

113
114

115
116
117

118
119

120
121

122
123
124

125
126

127
128
129

130
131

132
133
134

135
136

137
138

139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154

155
156
157
158

159
160
161
162
163
164
165
166

167
168
169

170
171

172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
72
73
74
75
76
77
78

79
80
81

82
83

84
85

86
87
88

89
90

91
92
93

94
95
96

97
98
99

100
101
102

103
104

105
106
107

108
109
110

111
112

113
114
115

116
117

118
119

120
121
122

123
124

125
126
127

128
129

130
131
132

133
134

135
136

137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156

157
158
159
160
161
162
163
164

165
166
167

168
169

170
171

172
173
174
175
176
177
178


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210


211
212
213
214
215
216
217
218







-
+


-
+

-
+

-
+


-
+

-
+


-
+


-
+


-
+


-
+

-
+


-
+


-
+

-
+


-
+

-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+

-
+



-
+











-
+



-
+







-
+


-
+

-
+

-
+






-
-




















-
+











-
-
+







};
static const Tk_CustomOption pixelOption = {
    TkPixelParseProc, TkPixelPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.activeDash),
	NULL, Tk_Offset(PolygonItem, outline.activeDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-activefill", NULL, NULL,
	NULL, offsetof(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.activeStipple),
	NULL, Tk_Offset(PolygonItem, outline.activeStipple),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
	NULL, offsetof(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL,
	"0.0", offsetof(PolygonItem, outline.activeWidth),
	"0.0", Tk_Offset(PolygonItem, outline.activeWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_CUSTOM, "-dash", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.dash),
	NULL, Tk_Offset(PolygonItem, outline.dash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL,
	"0", offsetof(PolygonItem, outline.offset),
	"0", Tk_Offset(PolygonItem, outline.offset),
	TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.disabledDash),
	NULL, Tk_Offset(PolygonItem, outline.disabledDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
	NULL, offsetof(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.disabledColor),
	NULL, Tk_Offset(PolygonItem, outline.disabledColor),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.disabledStipple),
	NULL, Tk_Offset(PolygonItem, outline.disabledStipple),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
	NULL, offsetof(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL,
	"0.0", offsetof(PolygonItem, outline.disabledWidth),
	"0.0", Tk_Offset(PolygonItem, outline.disabledWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_COLOR, "-fill", NULL, NULL,
	NULL, offsetof(PolygonItem, fillColor), TK_CONFIG_NULL_OK, NULL},
	"black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL,
	"round", offsetof(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
	"0,0", offsetof(PolygonItem, tsoffset),
	"0,0", Tk_Offset(PolygonItem, tsoffset),
	TK_CONFIG_NULL_OK, &offsetOption},
    {TK_CONFIG_COLOR, "-outline", NULL, NULL,
	DEF_CANVITEM_OUTLINE, offsetof(PolygonItem, outline.color), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, outline.color), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL,
	"0,0", offsetof(PolygonItem, outline.tsoffset),
	"0,0", Tk_Offset(PolygonItem, outline.tsoffset),
	TK_CONFIG_NULL_OK, &offsetOption},
    {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL,
	NULL, offsetof(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL,
	"0", offsetof(PolygonItem, smooth),
	"0", Tk_Offset(PolygonItem, smooth),
	TK_CONFIG_DONT_SET_DEFAULT, &smoothOption},
    {TK_CONFIG_INT, "-splinesteps", NULL, NULL,
	"12", offsetof(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
	NULL, offsetof(PolygonItem, fillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_CUSTOM, "-width", NULL, NULL,
	"1.0", offsetof(PolygonItem, outline.width),
	"1.0", Tk_Offset(PolygonItem, outline.width),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ComputePolygonBbox(Tk_Canvas canvas,
			    PolygonItem *polyPtr);
static int		ConfigurePolygon(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static int		CreatePolygon(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeletePolygon(Tk_Canvas canvas,
			    Tk_Item *itemPtr,  Display *display);
static void		DisplayPolygon(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static int		GetPolygonIndex(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Obj *obj, Tcl_Size *indexPtr);
			    Tcl_Obj *obj, int *indexPtr);
static int		PolygonCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		PolygonDeleteCoords(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size first, Tcl_Size last);
			    Tk_Item *itemPtr, int first, int last);
static void		PolygonInsert(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size beforeThis, Tcl_Obj *obj);
			    Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj);
static int		PolygonToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		PolygonToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *pointPtr);
static int		PolygonToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static void		RotatePolygon(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScalePolygon(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslatePolygon(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);

/*
 * The structures below defines the polygon item type by means of functions
 * that can be invoked by generic item code.
 */

Tk_ItemType tkPolygonType = {
    "polygon",				/* name */
    sizeof(PolygonItem),		/* itemSize */
    CreatePolygon,			/* createProc */
    configSpecs,			/* configSpecs */
    ConfigurePolygon,			/* configureProc */
    PolygonCoords,			/* coordProc */
    DeletePolygon,			/* deleteProc */
    DisplayPolygon,			/* displayProc */
    TK_MOVABLE_POINTS,		/* flags */
    TK_CONFIG_OBJS | TK_MOVABLE_POINTS,	/* flags */
    PolygonToPoint,			/* pointProc */
    PolygonToArea,			/* areaProc */
    PolygonToPostscript,		/* postscriptProc */
    ScalePolygon,			/* scaleProc */
    TranslatePolygon,			/* translateProc */
    GetPolygonIndex,	/* indexProc */
    NULL,				/* icursorProc */
    NULL,				/* selectionProc */
    PolygonInsert,		/* insertProc */
    PolygonDeleteCoords,		/* dTextProc */
    NULL,				/* nextPtr */
    RotatePolygon,			/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 * The definition below determines how large are static arrays used to hold
 * spline points (splines larger than this have to have their arrays
 * malloc-ed).
 */
244
245
246
247
248
249
250
251

252
253
254
255

256
257
258
259
260
261
262
240
241
242
243
244
245
246

247
248
249
250

251
252
253
254
255
256
257
258







-
+



-
+








static int
CreatePolygon(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing polygon. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Carry out initialization that is needed in order to clean up after
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283







-
+







    polyPtr->tsoffset.yoffset = 0;
    polyPtr->fillColor = NULL;
    polyPtr->activeFillColor = NULL;
    polyPtr->disabledFillColor = NULL;
    polyPtr->fillStipple = None;
    polyPtr->activeFillStipple = None;
    polyPtr->disabledFillStipple = None;
    polyPtr->fillGC = NULL;
    polyPtr->fillGC = None;
    polyPtr->smooth = NULL;
    polyPtr->splineSteps = 12;
    polyPtr->autoClosed = 0;

    /*
     * Count the number of points and then parse them into a point array.
     * Leading arguments are assumed to be points if they start with a digit
328
329
330
331
332
333
334
335

336
337
338
339
340

341
342
343
344
345
346
347
324
325
326
327
328
329
330

331
332
333
334


335
336
337
338
339
340
341
342







-
+



-
-
+








static int
PolygonCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    int i;
    int numPoints;
    int i, numPoints;

    if (objc == 0) {
	/*
	 * Print the coords used to create the polygon. If we auto closed the
	 * polygon then we don't report the last point.
	 */

358
359
360
361
362
363
364
365

366
367

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
353
354
355
356
357
358
359

360
361

362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384







-
+

-
+














-
+







	if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		(Tcl_Obj ***) &objv) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    if (objc & 1) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected an even number, got %" TCL_SIZE_MODIFIER "d",
		"wrong # coordinates: expected an even number, got %d",
		objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "POLYGON", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "POLYGON", NULL);
	return TCL_ERROR;
    }

    numPoints = objc/2;
    if (polyPtr->pointsAllocated <= numPoints) {
	if (polyPtr->coordPtr != NULL) {
	    ckfree(polyPtr->coordPtr);
	}

	/*
	 * One extra point gets allocated here, because we always add
	 * another point to close the polygon.
	 */

	polyPtr->coordPtr = (double *)ckalloc(sizeof(double) * (objc+2));
	polyPtr->coordPtr = ckalloc(sizeof(double) * (objc+2));
	polyPtr->pointsAllocated = numPoints+1;
    }
    for (i = objc-1; i >= 0; i--) {
	if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i],
		&polyPtr->coordPtr[i]) != TCL_OK) {
	    return TCL_ERROR;
	}
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
451







-
+














-
+







 */

static int
ConfigurePolygon(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Polygon item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv.  */
    int objc,			/* Number of elements in objv.  */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    XGCValues gcValues;
    GC newGC;
    unsigned long mask;
    Tk_Window tkwin;
    XColor *color;
    Pixmap stipple;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, polyPtr, flags)) {
	    (const char **) objv, (char *) polyPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * A few of the options require additional processing, such as graphics
     * contexts.
     */
479
480
481
482
483
484
485
486

487
488

489
490
491
492
493
494
495
474
475
476
477
478
479
480

481
482

483
484
485
486
487
488
489
490







-
+

-
+







    mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &polyPtr->outline);
    if (mask) {
	gcValues.cap_style = CapRound;
	gcValues.join_style = polyPtr->joinStyle;
	mask |= GCCapStyle|GCJoinStyle;
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    } else {
	newGC = NULL;
	newGC = None;
    }
    if (polyPtr->outline.gc != NULL) {
    if (polyPtr->outline.gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), polyPtr->outline.gc);
    }
    polyPtr->outline.gc = newGC;

    color = polyPtr->fillColor;
    stipple = polyPtr->fillStipple;
    if (Canvas(canvas)->currentItemPtr == itemPtr) {
505
506
507
508
509
510
511
512

513
514
515
516
517
518
519
520
521
522
523
524
525
526

527
528
529
530
531
532

533
534
535
536
537
538
539
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526

527
528
529
530
531
532
533
534







-
+













-
+





-
+







	}
	if (polyPtr->disabledFillStipple != None) {
	    stipple = polyPtr->disabledFillStipple;
	}
    }

    if (color == NULL) {
	newGC = NULL;
	newGC = None;
    } else {
	gcValues.foreground = color->pixel;
	mask = GCForeground;
	if (stipple != None) {
	    gcValues.stipple = stipple;
	    gcValues.fill_style = FillStippled;
	    mask |= GCStipple|GCFillStyle;
	}
#ifdef MAC_OSX_TK
	/*
	 * Mac OS X CG drawing needs access to the outline linewidth
	 * even for fills (as linewidth controls antialiasing).
	 */
	gcValues.line_width = polyPtr->outline.gc != NULL ?
	gcValues.line_width = polyPtr->outline.gc != None ?
		polyPtr->outline.gc->line_width : 0;
	mask |= GCLineWidth;
#endif
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    }
    if (polyPtr->fillGC != NULL) {
    if (polyPtr->fillGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), polyPtr->fillGC);
    }
    polyPtr->fillGC = newGC;

    /*
     * Keep spline parameters within reasonable limits.
     */
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572







-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeletePolygon(
    TCL_UNUSED(Tk_Canvas),		/* Info about overall canvas widget. */
    Tk_Canvas canvas,		/* Info about overall canvas widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;

    Tk_DeleteOutline(display, &polyPtr->outline);
    if (polyPtr->coordPtr != NULL) {
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600







-
+







    }
    if (polyPtr->activeFillStipple != None) {
	Tk_FreeBitmap(display, polyPtr->activeFillStipple);
    }
    if (polyPtr->disabledFillStipple != None) {
	Tk_FreeBitmap(display, polyPtr->disabledFillStipple);
    }
    if (polyPtr->fillGC != NULL) {
    if (polyPtr->fillGC != None) {
	Tk_FreeGC(display, polyPtr->fillGC);
    }
}

/*
 *--------------------------------------------------------------
 *
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704







-
+







	} else if (tsoffset->flags & TK_OFFSET_MIDDLE) {
	    tsoffset->yoffset = (polyPtr->header.y1 + polyPtr->header.y2)/2;
	} else if (tsoffset->flags & TK_OFFSET_BOTTOM) {
	    tsoffset->yoffset = polyPtr->header.y2;
	}
    }

    if (polyPtr->outline.gc != NULL) {
    if (polyPtr->outline.gc != None) {
	tsoffset = &polyPtr->outline.tsoffset;
	if (tsoffset) {
	    if (tsoffset->flags & TK_OFFSET_INDEX) {
		int index = tsoffset->flags & ~TK_OFFSET_INDEX;

		if (tsoffset->flags == INT_MAX) {
		    index = (polyPtr->numPoints - 1) * 2;
824
825
826
827
828
829
830
831

832
833
834
835
836
837
838
839
840
841
842
843
844

845
846
847
848

849
850
851
852
853
854
855
819
820
821
822
823
824
825

826
827
828
829
830
831
832
833
834
835
836
837
838

839
840
841
842

843
844
845
846
847
848
849
850







-
+












-
+



-
+







     * unless the polygon has an enormous number of points; in this case,
     * dynamically allocate an array.
     */

    if (numPoints <= MAX_STATIC_POINTS) {
	pointPtr = staticPoints;
    } else {
	pointPtr = (XPoint *)ckalloc(numPoints * sizeof(XPoint));
	pointPtr = ckalloc(numPoints * sizeof(XPoint));
    }

    for (i=0, pPtr=pointPtr ; i<numPoints; i+=1, coordPtr+=2, pPtr++) {
	Tk_CanvasDrawableCoords(canvas, coordPtr[0], coordPtr[1], &pPtr->x,
		&pPtr->y);
    }

    /*
     * Display polygon, then free up polygon storage if it was dynamically
     * allocated.
     */

    if (gc != NULL && numPoints > 3) {
    if (gc != None && numPoints > 3) {
	XFillPolygon(display, drawable, gc, pointPtr, numPoints, Complex,
		CoordModeOrigin);
    }
    if (outlineGC != NULL) {
    if (outlineGC != None) {
	XDrawLines(display, drawable, outlineGC, pointPtr, numPoints,
		CoordModeOrigin);
    }
    if (pointPtr != staticPoints) {
	ckfree(pointPtr);
    }
}
873
874
875
876
877
878
879

880
881


882
883
884
885
886
887
888
889
890

891
892

893
894
895
896
897
898
899
868
869
870
871
872
873
874
875


876
877


878
879
880
881
882
883

884
885

886
887
888
889
890
891
892
893







+
-
-
+
+
-
-






-
+

-
+








static void
DisplayPolygon(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    Tk_Item *itemPtr,		/* Item to be displayed. */
    Display *display,		/* Display on which to draw item. */
    Drawable drawable,		/* Pixmap or window in which to draw item. */
    int x, int y, int width, int height)
    TCL_UNUSED(int),	/* Describes region of canvas that must be */
    TCL_UNUSED(int),	/* redisplayed (not used). */
				/* Describes region of canvas that must be
				 * redisplayed (not used). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    Tk_State state = itemPtr->state;
    Pixmap stipple = polyPtr->fillStipple;
    double linewidth = polyPtr->outline.width;

    if (((polyPtr->fillGC == NULL) && (polyPtr->outline.gc == NULL)) ||
    if (((polyPtr->fillGC == None) && (polyPtr->outline.gc == None)) ||
	    (polyPtr->numPoints < 1) ||
	    (polyPtr->numPoints < 3 && polyPtr->outline.gc == NULL)) {
	    (polyPtr->numPoints < 3 && polyPtr->outline.gc == None)) {
	return;
    }

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }
    if (Canvas(canvas)->currentItemPtr == itemPtr) {
913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
907
908
909
910
911
912
913

914
915
916
917
918
919
920
921







-
+







    }

    /*
     * If we're stippling then modify the stipple offset in the GC. Be sure to
     * reset the offset when done, since the GC is supposed to be read-only.
     */

    if ((stipple != None) && (polyPtr->fillGC != NULL)) {
    if ((stipple != None) && (polyPtr->fillGC != None)) {
	Tk_TSOffset *tsoffset = &polyPtr->tsoffset;
	int w = 0, h = 0;
	int flags = tsoffset->flags;

	if (!(flags & TK_OFFSET_INDEX)
		&& (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) {
	    Tk_SizeOfBitmap(display, stipple, &w, &h);
971
972
973
974
975
976
977
978

979
980
981
982

983
984
985
986

987
988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045

1046
1047
1048
1049


1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060

1061
1062
1063
1064
1065
1066
1067
965
966
967
968
969
970
971

972
973
974
975

976
977
978
979

980
981
982
983
984
985
986
987
988

989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018

1019

1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031

1032


1033
1034
1035

1036
1037
1038


1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1058







-
+



-
+



-
+








-
+









-
+














-
+




-
+
-












-

-
-
+


-
+


-
-
+
+










-
+







	 */

	numPoints = polyPtr->smooth->coordProc(canvas, NULL,
		polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL);
	if (numPoints <= MAX_STATIC_POINTS) {
	    pointPtr = staticPoints;
	} else {
	    pointPtr = (XPoint *)ckalloc(numPoints * sizeof(XPoint));
	    pointPtr = ckalloc(numPoints * sizeof(XPoint));
	}
	numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
		polyPtr->numPoints, polyPtr->splineSteps, pointPtr, NULL);
	if (polyPtr->fillGC != NULL) {
	if (polyPtr->fillGC != None) {
	    XFillPolygon(display, drawable, polyPtr->fillGC, pointPtr,
		    numPoints, Complex, CoordModeOrigin);
	}
	if (polyPtr->outline.gc != NULL) {
	if (polyPtr->outline.gc != None) {
	    XDrawLines(display, drawable, polyPtr->outline.gc, pointPtr,
		    numPoints, CoordModeOrigin);
	}
	if (pointPtr != staticPoints) {
	    ckfree(pointPtr);
	}
    }
    Tk_ResetOutlineGC(canvas, itemPtr, &polyPtr->outline);
    if ((stipple != None) && (polyPtr->fillGC != NULL)) {
    if ((stipple != None) && (polyPtr->fillGC != None)) {
	XSetTSOrigin(display, polyPtr->fillGC, 0, 0);
    }
}

/*
 *--------------------------------------------------------------
 *
 * PolygonInsert --
 *
 *	Insert coords into a polygon item at a given index.
 *	Insert coords into a polugon item at a given index.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The coords in the given item is modified.
 *
 *--------------------------------------------------------------
 */

static void
PolygonInsert(
    Tk_Canvas canvas,		/* Canvas containing text item. */
    Tk_Item *itemPtr,		/* Line item to be modified. */
    Tcl_Size beforeThis,		/* Index before which new coordinates are to
    int beforeThis,		/* Index before which new coordinates are to
				 * be inserted. */
    Tcl_Obj *obj)		/* New coordinates to be inserted. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    int length, oriNumPoints, nbInsPoints, i;
    int length, objc, i;
    Tcl_Size objc;
    Tcl_Obj **objv;
    double *newCoordPtr;
    Tk_State state = itemPtr->state;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK)
	    || !objc || objc&1) {
	return;
    }
    oriNumPoints = polyPtr->numPoints - polyPtr->autoClosed;
    length = 2*(polyPtr->numPoints - polyPtr->autoClosed);
    nbInsPoints = objc / 2;
    while ((int)beforeThis > length) {
    while (beforeThis > length) {
	beforeThis -= length;
    }
    while ((int)beforeThis < 0) {
    while (beforeThis < 0) {
	beforeThis += length;
    }
    newCoordPtr = (double *)ckalloc(sizeof(double) * (length + 2 + objc));
    for (i=0; i<(int)beforeThis; i++) {
    newCoordPtr = ckalloc(sizeof(double) * (length + 2 + objc));
    for (i=0; i<beforeThis; i++) {
	newCoordPtr[i] = polyPtr->coordPtr[i];
    }
    for (i=0; i<objc; i++) {
	if (Tcl_GetDoubleFromObj(NULL, objv[i],
		&newCoordPtr[i+beforeThis]) != TCL_OK){
	    ckfree(newCoordPtr);
	    return;
	}
    }

    for (i=(int)beforeThis; i<length; i++) {
    for (i=beforeThis; i<length; i++) {
	newCoordPtr[i+objc] = polyPtr->coordPtr[i];
    }
    if (polyPtr->coordPtr) {
	ckfree(polyPtr->coordPtr);
    }
    length += objc;
    polyPtr->coordPtr = newCoordPtr;
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129



1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159


1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185

























1186
1187
1188
1189
1190
1191
1192
1193
1083
1084
1085
1086
1087
1088
1089


1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107

1108








1109
1110
1111




1112


1113























1114
1115
1116

























1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141

1142
1143
1144
1145
1146
1147
1148







-
-
















-


-

-
-
-
-
-
-
-
-
+
+
+
-
-
-
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-







	/*
	 * This is some optimizing code that will result that only the part of
	 * the polygon that changed (and the objects that are overlapping with
	 * that part) need to be redrawn. A special flag is set that instructs
	 * the general canvas code not to redraw the whole object. If this
	 * flag is not set, the canvas will do the redrawing, otherwise I have
	 * to do it here.
	 * Rationale for the optimization code can be found in Tk ticket
	 * [5fb8145997].
	 */

    	double width;
	int j;

	itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;

	/*
	 * The header elements that normally are used for the bounding box,
	 * are now used to calculate the bounding box for only the part that
	 * has to be redrawn. That doesn't matter, because afterwards the
	 * bounding box has to be re-calculated anyway.
	 */

	itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis];
	itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1];

	beforeThis -= 2;
	objc += 4;

	if (polyPtr->smooth) {
	    if (!strcmp(polyPtr->smooth->name, "true")) {
		/*
		 * Quadratic Bezier splines.
		 */

		beforeThis -= 2;
		objc += 4;

	    beforeThis -= 2;
	    objc += 4;
	}
	    } else if (!strcmp(polyPtr->smooth->name, "raw")) {
		/*
		 * Cubic Bezier splines.
		 */

		if ((oriNumPoints % 3) || (nbInsPoints % 3)) {
		    /*
	/*
		     * No optimization for "degenerate" polygons or when inserting
		     * something else than a multiple of 3 points.
		     */

		    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
		} else {
		    beforeThis -= abs((int)beforeThis) % 6;
		    objc += 4;
		}

	    } else {
		/*
		 * Custom smoothing method. No optimization is possible.
		 */

		itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    }
	}

	if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
	    /*
	     * Be careful; beforeThis could now be negative
	     */
	 * Be careful; beforeThis could now be negative
	 */

	    for (i=(int)beforeThis; i<(int)beforeThis+objc; i+=2) {
		j = i;
		if (j < 0) {
		    j += length;
		} else if (j >= length) {
		    j -= length;
		}
		TkIncludePoint(itemPtr, polyPtr->coordPtr+j);
	    }
	    width = polyPtr->outline.width;
	    if (Canvas(canvas)->currentItemPtr == itemPtr) {
		if (polyPtr->outline.activeWidth > width) {
		    width = polyPtr->outline.activeWidth;
		}
	    } else if (state == TK_STATE_DISABLED) {
		if (polyPtr->outline.disabledWidth > 0.0) {
		    width = polyPtr->outline.disabledWidth;
		}
	    }
	    itemPtr->x1 -= (int) width;
	    itemPtr->y1 -= (int) width;
	    itemPtr->x2 += (int) width;
	    itemPtr->y2 += (int) width;
	    Tk_CanvasEventuallyRedraw(canvas,
		    itemPtr->x1, itemPtr->y1, itemPtr->x2, itemPtr->y2);
	for (i=beforeThis; i<beforeThis+objc; i+=2) {
	    j = i;
	    if (j < 0) {
		j += length;
	    } else if (j >= length) {
		j -= length;
	    }
	    TkIncludePoint(itemPtr, polyPtr->coordPtr+j);
	}
	width = polyPtr->outline.width;
	if (Canvas(canvas)->currentItemPtr == itemPtr) {
	    if (polyPtr->outline.activeWidth > width) {
		width = polyPtr->outline.activeWidth;
	    }
	} else if (state == TK_STATE_DISABLED) {
	    if (polyPtr->outline.disabledWidth > 0.0) {
		width = polyPtr->outline.disabledWidth;
	    }
	}
	itemPtr->x1 -= (int) width;
	itemPtr->y1 -= (int) width;
	itemPtr->x2 += (int) width;
	itemPtr->y2 += (int) width;
	Tk_CanvasEventuallyRedraw(canvas,
		itemPtr->x1, itemPtr->y1, itemPtr->x2, itemPtr->y2);
	}
    }

    ComputePolygonBbox(canvas, polyPtr);
}

/*
 *--------------------------------------------------------------
1206
1207
1208
1209
1210
1211
1212
1213
1214


1215
1216
1217
1218
1219
1220

1221
1222
1223

1224
1225
1226

1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1161
1162
1163
1164
1165
1166
1167


1168
1169
1170
1171
1172
1173
1174

1175
1176
1177

1178
1179
1180

1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191







-
-
+
+





-
+


-
+


-
+


-
+







 *--------------------------------------------------------------
 */

static void
PolygonDeleteCoords(
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Item in which to delete characters. */
    Tcl_Size first,			/* Index of first character to delete. */
    Tcl_Size last)			/* Index of last character to delete. */
    int first,			/* Index of first character to delete. */
    int last)			/* Index of last character to delete. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    int count, i;
    int length = 2*(polyPtr->numPoints - polyPtr->autoClosed);

    while ((int)first >= length) {
    while (first >= length) {
	first -= length;
    }
    while ((int)first < 0) {
    while (first < 0) {
	first += length;
    }
    while ((int)last >= length) {
    while (last >= length) {
	last -= length;
    }
    while ((int)last < 0) {
    while (last < 0) {
	last += length;
    }

    first &= -2;
    last &= -2;

    count = last + 2 - first;
1249
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218







-
+







    }

    if (last >= first) {
	for (i=last+2; i<length; i++) {
	    polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i];
	}
    } else {
	for (i=last; i<=(int)first; i++) {
	for (i=last; i<=first; i++) {
	    polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i];
	}
    }
    polyPtr->coordPtr[length-count] = polyPtr->coordPtr[0];
    polyPtr->coordPtr[length-count+1] = polyPtr->coordPtr[1];
    polyPtr->numPoints -= count/2;
    ComputePolygonBbox(canvas, polyPtr);
1279
1280
1281
1282
1283
1284
1285

1286
1287
1288
1289
1290
1291
1292
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
PolygonToPoint(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301

1302
1303
1304
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1319







-
+












-
+









-
+








    if ((polyPtr->smooth) && (polyPtr->numPoints > 2)) {
	numPoints = polyPtr->smooth->coordProc(canvas, NULL,
		polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL);
	if (numPoints <= MAX_STATIC_POINTS) {
	    polyPoints = staticSpace;
	} else {
	    polyPoints = (double *)ckalloc(2 * numPoints * sizeof(double));
	    polyPoints = ckalloc(2 * numPoints * sizeof(double));
	}
	numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
		polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints);
    } else {
	numPoints = polyPtr->numPoints;
	polyPoints = polyPtr->coordPtr;
    }

    bestDist = TkPolygonToPoint(polyPoints, numPoints, pointPtr);
    if (bestDist <= 0.0) {
	goto donepoint;
    }
    if ((polyPtr->outline.gc != NULL) && (polyPtr->joinStyle == JoinRound)) {
    if ((polyPtr->outline.gc != None) && (polyPtr->joinStyle == JoinRound)) {
	dist = bestDist - radius;
	if (dist <= 0.0) {
	    bestDist = 0.0;
	    goto donepoint;
	} else {
	    bestDist = dist;
	}
    }

    if ((polyPtr->outline.gc == NULL) || (width <= 1)) {
    if ((polyPtr->outline.gc == None) || (width <= 1)) {
	goto donepoint;
    }

    /*
     * The overall idea is to iterate through all of the edges of the line,
     * computing a polygon for each edge and testing the point against that
     * polygon. In addition, there are additional tests to deal with rounded
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
PolygonToArea(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against polygon. */
    double *rectPtr)		/* Pointer to array of four coordinates
				 * (x1,y1,x2,y2) describing rectangular
				 * area. */
1534
1535
1536
1537
1538
1539
1540
1541

1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1525







-
+



















-
+








    if (polyPtr->smooth) {
	numPoints = polyPtr->smooth->coordProc(canvas, NULL,
		polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL);
	if (numPoints <= MAX_STATIC_POINTS) {
	    polyPoints = staticSpace;
	} else {
	    polyPoints = (double *)ckalloc(2 * numPoints * sizeof(double));
	    polyPoints = ckalloc(2 * numPoints * sizeof(double));
	}
	numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
		polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints);
    } else {
	numPoints = polyPtr->numPoints;
	polyPoints = polyPtr->coordPtr;
    }

    /*
     * Simple test to see if we are in the polygon. Polygons are different
     * from othe canvas items in that they register points being inside even
     * if it isn't filled.
     */

    inside = TkPolygonToArea(polyPoints, numPoints, rectPtr);
    if (inside == 0) {
	goto donearea;
    }

    if (polyPtr->outline.gc == NULL) {
    if (polyPtr->outline.gc == None) {
	goto donearea;
    }

    /*
     * Iterate through all of the edges of the line, computing a polygon for
     * each edge and testing the area against that polygon. In addition, there
     * are additional tests to deal with rounded joints and caps.
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
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







-
+




-
+

-

-
+
-

-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
+


-
+



-
+
-
-
-
+


-
-
-
+
+
+














+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-







 *
 *--------------------------------------------------------------
 */

static int
GetPolygonIndex(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item for which the index is being
				 * specified. */
    Tcl_Obj *obj,		/* Specification of a particular coord in
				 * itemPtr's line. */
    Tcl_Size *indexPtr)		/* Where to store converted index. */
    int *indexPtr)		/* Where to store converted index. */
{
    Tcl_Size length, idx;
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    const char *string;
    const char *string = Tcl_GetString(obj);
    Tcl_Size count = 2*(polyPtr->numPoints - polyPtr->autoClosed);

    if (TCL_OK == TkGetIntForIndex(obj,  (INT_MAX - 1) - ((INT_MAX) % count), 1, &idx)) {
	if (idx < 0) {
	    idx = 0;
    if (string[0] == 'e') {
	if (strncmp(string, "end", obj->length) != 0) {
	} else if (idx >= INT_MAX - ((INT_MAX) % count)) {
	    idx = count;
	} else {
	    idx = (idx & (Tcl_Size)-2) % count;
	}
	*indexPtr = idx;
	    goto badIndex;
	return TCL_OK;
    }

	}
	*indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed);
    string = Tcl_GetStringFromObj(obj, &length);

    if (string[0] == '@') {
    } else if (string[0] == '@') {
	int i;
	double x, y, bestDist, dist, *coordPtr;
	char *rest;
	char *end;
	const char *p;

	p = string+1;
	rest = strchr((char *)p, ',');
	x = strtod(p, &end);
	*rest = '\0';
	if (Tcl_GetDouble(NULL, p, &x) != TCL_OK) {
	    *rest = ',';
	if ((end == p) || (*end != ',')) {
	    goto badIndex;
	}
	*rest = ',';
	p = rest+1;
	if (Tcl_GetDouble(NULL, p, &y) != TCL_OK) {
	p = end+1;
	y = strtod(p, &end);
	if ((end == p) || (*end != 0)) {
	    goto badIndex;
	}
	bestDist = 1.0e36;
	coordPtr = polyPtr->coordPtr;
	*indexPtr = 0;
	for (i=0; i<polyPtr->numPoints-1; i++) {
	    dist = hypot(coordPtr[0] - x, coordPtr[1] - y);
	    if (dist < bestDist) {
		bestDist = dist;
		*indexPtr = 2*i;
	    }
	    coordPtr += 2;
	}
    } else {
	int count = 2*(polyPtr->numPoints - polyPtr->autoClosed);

	if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) {
    badIndex:
	    goto badIndex;
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "POLY", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

	}
	*indexPtr &= -2; /* if odd, make it even */
	if (!count) {
	    *indexPtr = 0;
	} else if (*indexPtr > 0) {
	    *indexPtr = ((*indexPtr - 2) % count) + 2;
	} else {
	    *indexPtr = -((-(*indexPtr)) % count);
	}
    }
/*
 *--------------------------------------------------------------
 *
 * RotatePolygon --
 *
    return TCL_OK;

 *	This function is called to rotate a polygon by a given amount about a
 *	point.
 *
    /*
     * Some of the paths here leave messages in interp->result, so we have to
     * clear it out before storing our own message.
     */
 * Results:
 *	None.
 *
 * Side effects:

  badIndex:
 *	The position of the polygon is rotated by angleRad about (originX,
 *	originY), and the bounding box is updated in the generic part of the
 *	item structure.
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
 *
 *--------------------------------------------------------------
 */

    Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "POLY", NULL);
static void
RotatePolygon(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item that is being moved. */
    double originX, double originY,
    double angleRad)		/* Amount by which item is to be rotated. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    double *coordPtr;
    int i;
    double s = sin(angleRad), c = cos(angleRad);

    return TCL_ERROR;
    for (i = 0, coordPtr = polyPtr->coordPtr; i < polyPtr->numPoints;
	    i++, coordPtr += 2) {
	TkRotatePoint(originX, originY, s, c, &coordPtr[0], &coordPtr[1]);
    }
    ComputePolygonBbox(canvas, polyPtr);
}

/*
 *--------------------------------------------------------------
 *
 * TranslatePolygon --
 *
1866
1867
1868
1869
1870
1871
1872
1873

1874
1875
1876
1877
1878
1879
1880
1791
1792
1793
1794
1795
1796
1797

1798
1799
1800
1801
1802
1803
1804
1805







-
+







 */

static int
PolygonToPostscript(
    Tcl_Interp *interp,		/* Leave Postscript or error message here. */
    Tk_Canvas canvas,		/* Information about overall canvas. */
    Tk_Item *itemPtr,		/* Item for which Postscript is wanted. */
    TCL_UNUSED(int))	/* 1 means this is a prepass to collect font
    int prepass)		/* 1 means this is a prepass to collect font
				 * information; 0 means final Postscript is
				 * being created. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    int style;
    XColor *color;
    XColor *fillColor;
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
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







-
+
+
+



-
+


-
+
+
+


-
+

















-
+
+
+



-
+


-
+
+
+



-
+


-
+







		width/2.0, width/2.0);

	/*
	 * Color it in.
	 */

	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, color);
	if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (stipple != None) {
	    Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "clip ", -1);

	    Tcl_ResetResult(interp);
	    Tk_CanvasPsStipple(interp, canvas, stipple);
	    if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	} else {
	    Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "fill\n", -1);
	}
	goto done;
    }

    /*
     * Fill the area of the polygon.
     */

    if (fillColor != NULL && polyPtr->numPoints > 3) {
	Tcl_ResetResult(interp);
	if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) {
	    Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr,
		    polyPtr->numPoints);
	} else {
	    polyPtr->smooth->postscriptProc(interp, canvas, polyPtr->coordPtr,
		    polyPtr->numPoints, polyPtr->splineSteps);
	}
	Tk_CanvasPsColor(interp, canvas, fillColor);
	if (Tk_CanvasPsColor(interp, canvas, fillColor) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (fillStipple != None) {
	    Tcl_AppendToObj(psObj, "eoclip ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "eoclip ", -1);

	    Tcl_ResetResult(interp);
	    Tk_CanvasPsStipple(interp, canvas, fillStipple);
	    if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	    if (color != NULL) {
		Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
	    }
	} else {
	    Tcl_AppendToObj(psObj, "eofill\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "eofill\n", -1);
	}
    }

    /*
     * Now draw the outline, if there is one.
     */

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
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







-
+
+
+












+
+
+
+
+









	    style = 2;
	} else {
	    style = 0;
	}
	Tcl_AppendPrintfToObj(psObj, "%d setlinejoin 1 setlinecap\n", style);

	Tcl_ResetResult(interp);
	Tk_CanvasPsOutline(canvas, itemPtr, &polyPtr->outline);
	if (Tk_CanvasPsOutline(canvas, itemPtr, &polyPtr->outline) != TCL_OK){
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

  done:
    (void) Tcl_RestoreInterpState(interp, interpState);
    Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    Tcl_DecrRefCount(psObj);
    return TCL_OK;

  error:
    Tcl_DiscardInterpState(interpState);
    Tcl_DecrRefCount(psObj);
    return TCL_ERROR;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCanvPs.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







/*
 * tkCanvPs.c --
 *
 *	This module provides Postscript output support for canvases, including
 *	the "postscript" widget command plus a few utility functions used for
 *	generating Postscript.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1991-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
90
91
92
93
94
95
96
97

98
99

100
101

102
103

104
105

106
107

108
109

110
111

112
113

114
115

116
117

118
119

120
121

122
123

124
125

126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161

162
163
164
165
166



167
168
169
170
171
172
173
90
91
92
93
94
95
96

97
98

99
100

101
102

103
104

105
106

107
108

109
110

111
112

113
114

115
116

117
118

119
120

121
122

123
124

125
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164



165
166
167
168
169
170
171
172
173
174







-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

















-
+














+

-
+


-
-
-
+
+
+







/*
 * The table below provides a template that's used to process arguments to the
 * canvas "postscript" command and fill in TkPostscriptInfo structures.
 */

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_STRING, "-colormap", NULL, NULL,
	"", offsetof(TkPostscriptInfo, colorVar), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, colorVar), 0, NULL},
    {TK_CONFIG_STRING, "-colormode", NULL, NULL,
	"", offsetof(TkPostscriptInfo, colorMode), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, colorMode), 0, NULL},
    {TK_CONFIG_STRING, "-file", NULL, NULL,
	"", offsetof(TkPostscriptInfo, fileName), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, fileName), 0, NULL},
    {TK_CONFIG_STRING, "-channel", NULL, NULL,
	"", offsetof(TkPostscriptInfo, channelName), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, channelName), 0, NULL},
    {TK_CONFIG_STRING, "-fontmap", NULL, NULL,
	"", offsetof(TkPostscriptInfo, fontVar), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, fontVar), 0, NULL},
    {TK_CONFIG_PIXELS, "-height", NULL, NULL,
	"", offsetof(TkPostscriptInfo, height), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, height), 0, NULL},
    {TK_CONFIG_ANCHOR, "-pageanchor", NULL, NULL,
	"", offsetof(TkPostscriptInfo, pageAnchor), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, pageAnchor), 0, NULL},
    {TK_CONFIG_STRING, "-pageheight", NULL, NULL,
	"", offsetof(TkPostscriptInfo, pageHeightString), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, pageHeightString), 0, NULL},
    {TK_CONFIG_STRING, "-pagewidth", NULL, NULL,
	"", offsetof(TkPostscriptInfo, pageWidthString), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, pageWidthString), 0, NULL},
    {TK_CONFIG_STRING, "-pagex", NULL, NULL,
	"", offsetof(TkPostscriptInfo, pageXString), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, pageXString), 0, NULL},
    {TK_CONFIG_STRING, "-pagey", NULL, NULL,
	"", offsetof(TkPostscriptInfo, pageYString), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, pageYString), 0, NULL},
    {TK_CONFIG_BOOLEAN, "-prolog", NULL, NULL,
	"", offsetof(TkPostscriptInfo, prolog), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, prolog), 0, NULL},
    {TK_CONFIG_BOOLEAN, "-rotate", NULL, NULL,
	"", offsetof(TkPostscriptInfo, rotate), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, rotate), 0, NULL},
    {TK_CONFIG_PIXELS, "-width", NULL, NULL,
	"", offsetof(TkPostscriptInfo, width), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, width), 0, NULL},
    {TK_CONFIG_PIXELS, "-x", NULL, NULL,
	"", offsetof(TkPostscriptInfo, x), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, x), 0, NULL},
    {TK_CONFIG_PIXELS, "-y", NULL, NULL,
	"", offsetof(TkPostscriptInfo, y), 0, NULL},
	"", Tk_Offset(TkPostscriptInfo, y), 0, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Forward declarations for functions defined later in this file:
 */

static int		GetPostscriptPoints(Tcl_Interp *interp,
			    char *string, double *doublePtr);
static void		PostscriptBitmap(Tk_Window tkwin, Pixmap bitmap,
			    int startX, int startY, int width, int height,
			    Tcl_Obj *psObj);
static inline Tcl_Obj *	GetPostscriptBuffer(Tcl_Interp *interp);

/*
 *--------------------------------------------------------------
 *
 * TkCanvPostscriptObjCmd --
 * TkCanvPostscriptCmd --
 *
 *	This function is invoked to process the "postscript" options of the
 *	widget command for canvas widgets. See the user documentation for
 *	details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

    /* ARGSUSED */
int
TkCanvPostscriptObjCmd(
TkCanvPostscriptCmd(
    TkCanvas *canvasPtr,	/* Information about canvas widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
	Tcl_Obj *const objv[])		/* Argument strings. Caller has already parsed
				 * this command enough to know that objv[1] is
    int argc,			/* Number of arguments. */
    const char **argv)		/* Argument strings. Caller has already parsed
				 * this command enough to know that argv[1] is
				 * "postscript". */
{
    TkPostscriptInfo psInfo, *psInfoPtr = &psInfo;
    Tk_PostscriptInfo oldInfoPtr;
    int result;
    Tk_Item *itemPtr;
#define STRING_LENGTH 400
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203







-
+








    /*
     * Get the generic preamble. We only ever bother with the ASCII encoding;
     * the others just make life too complicated and never actually worked as
     * such.
     */

    result = Tcl_EvalEx(interp, "::tk::ensure_psenc_is_loaded", TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
    result = Tcl_EvalEx(interp, "::tk::ensure_psenc_is_loaded", -1, 0);
    if (result != TCL_OK) {
	return result;
    }
    preambleObj = Tcl_GetVar2Ex(interp, "::tk::ps_preamble", NULL,
	    TCL_LEAVE_ERR_MSG);
    if (preambleObj == NULL) {
	return TCL_ERROR;
232
233
234
235
236
237
238
239
240


241
242
243
244
245
246
247
233
234
235
236
237
238
239


240
241
242
243
244
245
246
247
248







-
-
+
+







    psInfo.fileName = NULL;
    psInfo.channelName = NULL;
    psInfo.chan = NULL;
    psInfo.prepass = 0;
    psInfo.prolog = 1;
    psInfo.tkwin = tkwin;
    Tcl_InitHashTable(&psInfo.fontTable, TCL_STRING_KEYS);
    result = Tk_ConfigureWidget(interp, tkwin, configSpecs, objc-2, objv+2,
	    &psInfo, TK_CONFIG_ARGV_ONLY);
    result = Tk_ConfigureWidget(interp, tkwin, configSpecs, argc-2, argv+2,
	    (char *) &psInfo, TK_CONFIG_ARGV_ONLY);
    if (result != TCL_OK) {
	goto cleanup;
    }

    if (psInfo.width == -1) {
	psInfo.width = Tk_Width(tkwin);
    }
281
282
283
284
285
286
287





288
289
290
291
292
293
294
295
296
297
298
299
300
301
302





303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341


342
343
344
345
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344


345
346
347
348
349
350
351
352
353
354
355
356
357


358
359
360
361
362
363
364
365
366







+
+
+
+
+





-
-
-







+
+
+
+
+





-
-
-
















-
+












-
-
+
+











-
-
+
+







    }
    switch (psInfo.pageAnchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_W:
    case TK_ANCHOR_SW:
	deltaX = 0;
	break;
    case TK_ANCHOR_N:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_S:
	deltaX = -psInfo.width/2;
	break;
    case TK_ANCHOR_NE:
    case TK_ANCHOR_E:
    case TK_ANCHOR_SE:
	deltaX = -psInfo.width;
	break;
    default:
	deltaX = -psInfo.width/2;
	break;
    }
    switch (psInfo.pageAnchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_N:
    case TK_ANCHOR_NE:
	deltaY = - psInfo.height;
	break;
    case TK_ANCHOR_W:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_E:
	deltaY = -psInfo.height/2;
	break;
    case TK_ANCHOR_SW:
    case TK_ANCHOR_S:
    case TK_ANCHOR_SE:
	deltaY = 0;
	break;
    default:
	deltaY = -psInfo.height/2;
	break;
    }

    if (psInfo.colorMode == NULL) {
	psInfo.colorLevel = 2;
    } else {
	length = strlen(psInfo.colorMode);
	if (strncmp(psInfo.colorMode, "monochrome", length) == 0) {
	    psInfo.colorLevel = 0;
	} else if (strncmp(psInfo.colorMode, "gray", length) == 0) {
	    psInfo.colorLevel = 1;
	} else if (strncmp(psInfo.colorMode, "color", length) == 0) {
	    psInfo.colorLevel = 2;
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad color mode \"%s\": must be monochrome, gray, or color",
		    psInfo.colorMode));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "COLORMODE", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "COLORMODE", NULL);
	    result = TCL_ERROR;
	    goto cleanup;
	}
    }

    if (psInfo.fileName != NULL) {
	/*
	 * Check that -file and -channel are not both specified.
	 */

	if (psInfo.channelName != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't specify both -file and -channel", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "USAGE", (char *)NULL);
		    "can't specify both -file and -channel", -1));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "USAGE", NULL);
	    result = TCL_ERROR;
	    goto cleanup;
	}

	/*
	 * Check that we are not in a safe interpreter. If we are, disallow
	 * the -file specification.
	 */

	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't specify -file in a safe interpreter", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PS_FILE", (char *)NULL);
		    "can't specify -file in a safe interpreter", -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PS_FILE", NULL);
	    result = TCL_ERROR;
	    goto cleanup;
	}

	p = Tcl_TranslateFileName(interp, psInfo.fileName, &buffer);
	if (p == NULL) {
	    goto cleanup;
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399







-
+







-
+








	/*
	 * Check that the channel is found in this interpreter and that it is
	 * open for writing.
	 */

	psInfo.chan = Tcl_GetChannel(interp, psInfo.channelName, &mode);
	if (psInfo.chan == NULL) {
	if (psInfo.chan == (Tcl_Channel) NULL) {
	    result = TCL_ERROR;
	    goto cleanup;
	}
	if (!(mode & TCL_WRITABLE)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "channel \"%s\" wasn't opened for writing",
		    psInfo.channelName));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "UNWRITABLE", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "UNWRITABLE",NULL);
	    result = TCL_ERROR;
	    goto cleanup;
	}
    }

    /*
     * Make a pre-pass over all of the items, generating Postscript and then
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446







-
+







    /*
     * Generate the header and prolog for the Postscript.
     */

    if (psInfo.prolog) {
	Tcl_AppendToObj(psObj,
		"%!PS-Adobe-3.0 EPSF-3.0\n"
		"%%Creator: Tk Canvas Widget\n", TCL_INDEX_NONE);
		"%%Creator: Tk Canvas Widget\n", -1);

#ifdef HAVE_PW_GECOS
	if (!Tcl_IsSafe(interp)) {
	    struct passwd *pwPtr = getpwuid(getuid());	/* INTL: Native. */

	    Tcl_AppendPrintfToObj(psObj,
		    "%%%%For: %s\n", (pwPtr ? pwPtr->pw_gecos : "Unknown"));
473
474
475
476
477
478
479
480

481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501







-
+








-
+







	p = "%%%%DocumentNeededResources: font %s\n";
	for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search);
		hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    Tcl_AppendPrintfToObj(psObj, p,
		    Tcl_GetHashKey(&psInfo.fontTable, hPtr));
	    p = "%%%%+ font %s\n";
	}
	Tcl_AppendToObj(psObj, "%%EndComments\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "%%EndComments\n\n", -1);

	/*
	 * Insert the prolog
	 */

	Tcl_AppendObjToObj(psObj, preambleObj);

	if (psInfo.chan != NULL) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == TCL_IO_FAILURE) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
	    channelWriteFailed:
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"problem writing postscript data to channel: %s",
			Tcl_PosixError(interp)));
		result = TCL_ERROR;
		goto cleanup;
	    }
506
507
508
509
510
511
512
513

514
515
516
517
518
519
520
521

522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

544
545
546
547
548
549
550
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525

526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
555







-
+







-
+



-
+

















-
+







		"%%%%BeginSetup\n/CL %d def\n", psInfo.colorLevel);
	for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search);
		hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    Tcl_AppendPrintfToObj(psObj,
		    "%%%%IncludeResource: font %s\n",
		    (char *) Tcl_GetHashKey(&psInfo.fontTable, hPtr));
	}
	Tcl_AppendToObj(psObj, "%%EndSetup\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "%%EndSetup\n\n", -1);

	/*
	 * Page setup: move to page positioning point, rotate if needed, set
	 * scale factor, offset for proper anchor position, and set clip
	 * region.
	 */

	Tcl_AppendToObj(psObj, "%%Page: 1 1\nsave\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "%%Page: 1 1\nsave\n", -1);
	Tcl_AppendPrintfToObj(psObj,
		"%.1f %.1f translate\n", psInfo.pageX, psInfo.pageY);
	if (psInfo.rotate) {
	    Tcl_AppendToObj(psObj, "90 rotate\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "90 rotate\n", -1);
	}
	Tcl_AppendPrintfToObj(psObj,
		"%.4g %.4g scale\n", psInfo.scale, psInfo.scale);
	Tcl_AppendPrintfToObj(psObj,
		"%d %d translate\n", deltaX - psInfo.x, deltaY);
	Tcl_AppendPrintfToObj(psObj,
		"%d %.15g moveto %d %.15g lineto %d %.15g lineto %d %.15g "
		"lineto closepath clip newpath\n",
		psInfo.x, Tk_PostscriptY((double)psInfo.y,
			(Tk_PostscriptInfo)psInfoPtr),
		psInfo.x2, Tk_PostscriptY((double)psInfo.y,
			(Tk_PostscriptInfo)psInfoPtr),
		psInfo.x2, Tk_PostscriptY((double)psInfo.y2,
			(Tk_PostscriptInfo)psInfoPtr),
		psInfo.x, Tk_PostscriptY((double)psInfo.y2,
			(Tk_PostscriptInfo)psInfoPtr));
	if (psInfo.chan != NULL) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == TCL_IO_FAILURE) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
		goto channelWriteFailed;
	    }
	    Tcl_DecrRefCount(psObj);
	    psObj = Tcl_NewObj();
	}
    }

563
564
565
566
567
568
569

570
571
572
573
574
575

576
577
578
579

580
581

582
583
584
585

586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606

607
608
609
610
611
612
613
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584

585
586

587

588
589

590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610

611
612
613
614
615
616
617
618







+





-
+



-
+

-
+
-


-
+

















-
+


-
+







	if (itemPtr->typePtr->postscriptProc == NULL) {
	    continue;
	}
	if (itemPtr->state == TK_STATE_HIDDEN) {
	    continue;
	}

	Tcl_ResetResult(interp);
	result = itemPtr->typePtr->postscriptProc(interp,
		(Tk_Canvas) canvasPtr, itemPtr, 0);
	if (result != TCL_OK) {
	    Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
		    "\n    (generating Postscript for item %d)",
		    (int)itemPtr->id));
		    itemPtr->id));
	    goto cleanup;
	}

	Tcl_AppendToObj(psObj, "gsave\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "gsave\n", -1);
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	Tcl_AppendToObj(psObj, "grestore\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "grestore\n", -1);
	Tcl_ResetResult(interp);

	if (psInfo.chan != NULL) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == TCL_IO_FAILURE) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
		goto channelWriteFailed;
	    }
	    Tcl_DecrRefCount(psObj);
	    psObj = Tcl_NewObj();
	}
    }

    /*
     * Output page-end information, such as commands to print the page and
     * document trailer stuff.
     */

    if (psInfo.prolog) {
	Tcl_AppendToObj(psObj,
		"restore showpage\n\n"
		"%%Trailer\n"
		"end\n"
		"%%EOF\n", TCL_INDEX_NONE);
		"%%EOF\n", -1);

	if (psInfo.chan != NULL) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == TCL_IO_FAILURE) {
	    if (Tcl_WriteObj(psInfo.chan, psObj) == -1) {
		goto channelWriteFailed;
	    }
	}
    }

    if (psInfo.chan == NULL) {
	Tcl_SetObjResult(interp, psObj);
779
780
781
782
783
784
785
786

787
788
789
790
791
792
793
794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813







-
+














-
+







     * there is an entry for this font, it consists of a list containing font
     * name and size. Use this information.
     */

    if (psInfoPtr->fontVar != NULL) {
	const char *name = Tk_NameOfFont(tkfont);
	Tcl_Obj **objv;
	Tcl_Size objc;
	int objc;
	double size;
	Tcl_Obj *list = Tcl_GetVar2Ex(interp, psInfoPtr->fontVar, name, 0);

	if (list != NULL) {
	    if (Tcl_ListObjGetElements(interp, list, &objc, &objv) != TCL_OK
		    || objc != 2
		    || (fontname = Tcl_GetString(objv[0]))[0] == '\0'
		    || strchr(fontname, ' ') != NULL
		    || Tcl_GetDoubleFromObj(interp, objv[1], &size) != TCL_OK
		    || size <= 0) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad font map entry for \"%s\": \"%s\"",
			name, Tcl_GetString(list)));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "FONTMAP",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }

	    Tcl_AppendPrintfToObj(GetPostscriptBuffer(interp),
		    "/%s findfont %d scalefont%s setfont\n",
		    fontname, (int) size,
		    strncasecmp(fontname, "Symbol", 7) ? " ISOEncode" : "");
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932

933
934
935
936
937
938
939
940
941
942
943
944

945
946
947
948
949
950
951
900
901
902
903
904
905
906









907




908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924

925
926
927
928
929
930
931
932
933
934
935
936

937
938
939
940
941
942
943
944







-
-
-
-
-
-
-
-
-
+
-
-
-
-

















-
+











-
+








    XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot,
	    (int *) &dummyX, (int *) &dummyY, (unsigned int *) &totalWidth,
	    (unsigned int *) &totalHeight, &dummyBorderwidth, &dummyDepth);
    imagePtr = XGetImage(Tk_Display(tkwin), bitmap, 0, 0,
	    totalWidth, totalHeight, 1, XYPixmap);


    if (!imagePtr) {
	/*
	 * The XGetImage() function is apparently not implemented on this
	 * system. Just skip the pixels, the Postscript will still be
	 * syntactically correct.
	 */

        Tcl_AppendToObj(psObj, "<>", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, "<", -1);
	return;
    }

    Tcl_AppendToObj(psObj, "<", TCL_INDEX_NONE);
    mask = 0x80;
    value = 0;
    charsInLine = 0;
    lastX = startX + width - 1;
    lastY = startY + height - 1;
    for (y = lastY; y >= startY; y--) {
	for (x = startX; x <= lastX; x++) {
	    if (XGetPixel(imagePtr, x, y)) {
		value |= mask;
	    }
	    mask >>= 1;
	    if (mask == 0) {
		Tcl_AppendPrintfToObj(psObj, "%02x", value);
		mask = 0x80;
		value = 0;
		charsInLine += 2;
		if (charsInLine >= 60) {
		    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "\n", -1);
		    charsInLine = 0;
		}
	    }
	}
	if (mask != 0x80) {
	    Tcl_AppendPrintfToObj(psObj, "%02x", value);
	    mask = 0x80;
	    value = 0;
	    charsInLine += 2;
	}
    }
    Tcl_AppendToObj(psObj, ">", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, ">", -1);

    XDestroyImage(imagePtr);
}

/*
 *--------------------------------------------------------------
 *
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004
1005







-
+







    XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot,
	    (int *) &dummyX, (int *) &dummyY, (unsigned *) &width,
	    (unsigned *) &height, &dummyBorderwidth, &dummyDepth);

    psObj = GetPostscriptBuffer(interp);
    Tcl_AppendPrintfToObj(psObj, "%d %d ", width, height);
    PostscriptBitmap(tkwin, bitmap, 0, 0, width, height, psObj);
    Tcl_AppendToObj(psObj, " StippleFill\n", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, " StippleFill\n", -1);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_PostscriptY --
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
1062







-
+







void
Tk_PostscriptPath(
    Tcl_Interp *interp,
    Tk_PostscriptInfo psInfo,	/* Canvas on whose behalf Postscript is being
				 * generated. */
    double *coordPtr,		/* Pointer to first in array of 2*numPoints
				 * coordinates giving points for path. */
    Tcl_Size numPoints)		/* Number of points at *coordPtr. */
    int numPoints)		/* Number of points at *coordPtr. */
{
    TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo;
    Tcl_Obj *psObj;

    if (psInfoPtr->prepass) {
	return;
    }
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109
1110
1111
1112


1113

1114
1115
1116
1117


1118
1119
1120




1121
1122
1123
1124
1125
1126
1127







1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

1143
1144
1145
1146
1147
1148

1149
1150
1151
1152






1153
1154





1155
1156
1157
1158
1159
1160
1161
1093
1094
1095
1096
1097
1098
1099

1100
1101

1102


1103
1104

1105
1106



1107
1108
1109


1110
1111
1112
1113







1114
1115
1116
1117
1118
1119
1120



1121










1122

1123

1124



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150







-
+

-

-
-
+
+
-
+

-
-
-
+
+

-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-

-
+
-

-
-
-

+




+
+
+
+
+
+


+
+
+
+
+








static int
GetPostscriptPoints(
    Tcl_Interp *interp,		/* Use this for error reporting. */
    char *string,		/* String describing a screen distance. */
    double *doublePtr)		/* Place to store converted result. */
{
    const char *rest;
    char *end;
    double d;
    Tcl_DString ds;

    if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
	*doublePtr = d;
    d = strtod(string, &end);
    if (end == string) {
	return TCL_OK;
	goto error;
    }
    rest = string + strlen(string);
    while ((rest > string) && isspace(UCHAR(rest[-1]))) {
	--rest; /* skip all spaces at the end */
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    }
    if (rest > string) {
	--rest; /* point to the character just before the last space */
    switch (*end) {
    case 'c':
	d *= 72.0/2.54;
	end++;
    }
	if (rest == string) {
	error:
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad distance \"%s\"", string));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "POINTS", (char *)NULL);
	break;
    case 'i':
	d *= 72.0;
	end++;
	break;
    case 'm':
	d *= 72.0/25.4;
	    }
	    return TCL_ERROR;
	}
	end++;
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, string, rest-string);
    if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
	Tcl_DStringFree(&ds);
	goto error;
    }
    Tcl_DStringFree(&ds);
    switch (*rest) {
    case 'c':
	d *= 72.0/2.54;
	break;
    case 'i':
    case 0:
	d *= 72.0;
	break;
    case 'm':
	d *= 72.0/25.4;
	break;
    case 'p':
	end++;
	break;
    default:
	goto error;
    }
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    }
    if (*end != 0) {
	goto error;
    }
    *doublePtr = d;
    return TCL_OK;

  error:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad distance \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "POINTS", NULL);
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * TkImageGetColor --
 *
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196


1197
1198
1199
1200
1201
1202
1203







-
+




-
-







#define GetBValue(rgb)	((rgb & cdata->blue_mask) >> cdata->blue_shift)

#endif /* _WIN32 */

#if defined(_WIN32) || defined(MAC_OSX_TK)
static void
TkImageGetColor(
    TkColormapData *cdata,
    TkColormapData *cdata,	/* Colormap data */
    unsigned long pixel,	/* Pixel value to look up */
    double *red, double *green, double *blue)
				/* Color data to return */
{
	(void)cdata;

    *red   = (double) GetRValue(pixel) / 255.0;
    *green = (double) GetGValue(pixel) / 255.0;
    *blue  = (double) GetBValue(pixel) / 255.0;
}
#else /* ! (_WIN32 || MAC_OSX_TK) */
static void
TkImageGetColor(
1258
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259







-
+








int
TkPostscriptImage(
    Tcl_Interp *interp,
    Tk_Window tkwin,
    Tk_PostscriptInfo psInfo,	/* postscript info */
    XImage *ximage,		/* Image to draw */
    int x, TCL_UNUSED(int),		/* First pixel to output */
    int x, int y,		/* First pixel to output */
    int width, int height)	/* Width and height of area */
{
    TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo;
    int xx, yy, band, maxRows;
    double red, green, blue;
    int bytesPerLine = 0, maxWidth = 0;
    int level = psInfoPtr->colorLevel;
1285
1286
1287
1288
1289
1290
1291
1292

1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281

1282
1283
1284
1285
1286
1287
1288
1289







-
+


-
+








    /*
     * Obtain information about the colormap, ie the mapping between pixel
     * values and RGB values. The code below should work for all Visual types.
     */

    ncolors = visual->map_entries;
    cdata.colors = (XColor *)ckalloc(sizeof(XColor) * ncolors);
    cdata.colors = ckalloc(sizeof(XColor) * ncolors);
    cdata.ncolors = ncolors;

    if (visual->c_class == DirectColor || visual->c_class == TrueColor) {
    if (visual->class == DirectColor || visual->class == TrueColor) {
	cdata.separated = 1;
	cdata.red_mask = visual->red_mask;
	cdata.green_mask = visual->green_mask;
	cdata.blue_mask = visual->blue_mask;
	cdata.red_shift = 0;
	cdata.green_shift = 0;
	cdata.blue_shift = 0;
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329
1330
1331
1332
1333
1334
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321







-
+







    } else {
	cdata.separated=0;
	for (i = 0; i < ncolors; i ++) {
	    cdata.colors[i].pixel = i;
	}
    }

    if (visual->c_class == StaticGray || visual->c_class == GrayScale) {
    if (visual->class == StaticGray || visual->class == GrayScale) {
	cdata.color = 0;
    } else {
	cdata.color = 1;
    }

    XQueryColors(Tk_Display(tkwin), cmap, cdata.colors, ncolors);

1359
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1360







-
+







    }

    if (bytesPerLine > 60000) {
	Tcl_ResetResult(interp);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't generate Postscript for images more than %d pixels wide",
		maxWidth));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", NULL);
	ckfree(cdata.colors);
	return TCL_ERROR;
    }

    maxRows = 60000 / bytesPerLine;
    psObj = GetPostscriptBuffer(interp);

1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
1406







-
+







		    }
		    mask >>= 1;
		    if (mask == 0) {
			Tcl_AppendPrintfToObj(psObj, "%02X", data);
			lineLen += 2;
			if (lineLen > 60) {
			    lineLen = 0;
			    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
			    Tcl_AppendToObj(psObj, "\n", -1);
			}
			mask = 0x80;
			data = 0x00;
		    }
		}
		if ((width % 8) != 0) {
		    Tcl_AppendPrintfToObj(psObj, "%02X", data);
1433
1434
1435
1436
1437
1438
1439
1440

1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468

1469
1470

1471
1472
1473
1474
1475
1476
1477
1420
1421
1422
1423
1424
1425
1426

1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454

1455
1456

1457
1458
1459
1460
1461
1462
1463
1464







-
+



















-
+







-
+

-
+







			    &red, &green, &blue);
		    Tcl_AppendPrintfToObj(psObj, "%02X",
			    (int) floor(0.5 + 255.0 *
			    (0.30 * red + 0.59 * green + 0.11 * blue)));
		    lineLen += 2;
		    if (lineLen > 60) {
			lineLen = 0;
			Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
			Tcl_AppendToObj(psObj, "\n", -1);
		    }
		}
		break;
	    default:
		/*
		 * Finally, color mode. Here, just output the red, green, and
		 * blue values directly.
		 */

		for (xx = x; xx < x+width; xx++) {
		    TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy),
			    &red, &green, &blue);
		    Tcl_AppendPrintfToObj(psObj, "%02X%02X%02X",
			    (int) floor(0.5 + 255.0 * red),
			    (int) floor(0.5 + 255.0 * green),
			    (int) floor(0.5 + 255.0 * blue));
		    lineLen += 6;
		    if (lineLen > 60) {
			lineLen = 0;
			Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
			Tcl_AppendToObj(psObj, "\n", -1);
		    }
		}
		break;
	    }
	}
	switch (level) {
	case 0: case 1:
	    Tcl_AppendToObj(psObj, ">\n} image\n", TCL_INDEX_NONE); break;
	    Tcl_AppendToObj(psObj, ">\n} image\n", -1); break;
	default:
	    Tcl_AppendToObj(psObj, ">\n} false 3 colorimage\n", TCL_INDEX_NONE); break;
	    Tcl_AppendToObj(psObj, ">\n} false 3 colorimage\n", -1); break;
	}
	Tcl_AppendPrintfToObj(psObj, "0 %d translate\n", rows);
    }
    ckfree(cdata.colors);
    return TCL_OK;
}

1545
1546
1547
1548
1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563

1564
1565
1566
1567
1568

1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549

1550
1551
1552
1553
1554

1555
1556
1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567







-
+










-
+




-
+




-
+







    default: bytesPerLine = 3 * width;	    maxWidth = 20000;  break;
    }
    if (bytesPerLine > 60000) {
	Tcl_ResetResult(interp);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't generate Postscript for images more than %d pixels wide",
		maxWidth));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", NULL);
	return TCL_ERROR;
    }

    /*
     * Set up the postscript code except for the image-data stream.
     */

    psObj = GetPostscriptBuffer(interp);
    switch (colorLevel) {
    case 0:
	Tcl_AppendToObj(psObj, "/DeviceGray setcolorspace\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "/DeviceGray setcolorspace\n\n", -1);
	decode = "1 0";
	bpc = 1;
	break;
    case 1:
	Tcl_AppendToObj(psObj, "/DeviceGray setcolorspace\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "/DeviceGray setcolorspace\n\n", -1);
	decode = "0 1";
	bpc = 8;
	break;
    default:
	Tcl_AppendToObj(psObj, "/DeviceRGB setcolorspace\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "/DeviceRGB setcolorspace\n\n", -1);
	decode = "0 1 0 1 0 1";
	bpc = 8;
	break;
    }

    Tcl_AppendPrintfToObj(psObj,
	    "<<\n  /ImageType 1\n"
1610
1611
1612
1613
1614
1615
1616
1617

1618
1619
1620
1621
1622
1623
1624
1597
1598
1599
1600
1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1611







-
+








    for (yy = 0, lineLen=0; yy < height; yy++) {
	switch (colorLevel) {
	case 0: {
	    /*
	     * Generate data for image in monochrome mode. No attempt at
	     * dithering is made--instead, just set a threshold. To handle
	     * transparencies we need to output two lines: one for the black
	     * transparecies we need to output two lines: one for the black
	     * pixels, one for the white ones.
	     */

	    unsigned char mask = 0x80;
	    unsigned char data = 0x00;

	    for (xx = 0; xx< width; xx ++) {
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1643







-
+







		}
		mask >>= 1;
		if (mask == 0) {
		    Tcl_AppendPrintfToObj(psObj, "%02X", data);
		    lineLen += 2;
		    if (lineLen >= 60) {
			lineLen = 0;
			Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
			Tcl_AppendToObj(psObj, "\n", -1);
		    }
		    mask = 0x80;
		    data = 0x00;
		}
	    }
	    if ((width % 8) != 0) {
		Tcl_AppendPrintfToObj(psObj, "%02X", data);
1681
1682
1683
1684
1685
1686
1687
1688

1689
1690
1691
1692
1693
1694
1695
1668
1669
1670
1671
1672
1673
1674

1675
1676
1677
1678
1679
1680
1681
1682







-
+







		}
		mask >>= 1;
		if (mask == 0) {
		    Tcl_AppendPrintfToObj(psObj, "%02X", data);
		    lineLen += 2;
		    if (lineLen >= 60) {
			lineLen = 0;
			Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
			Tcl_AppendToObj(psObj, "\n", -1);
		    }
		    mask = 0x80;
		    data = 0x00;
		}
	    }
	    if ((width % 8) != 0) {
		Tcl_AppendPrintfToObj(psObj, "%02X", data);
1707
1708
1709
1710
1711
1712
1713
1714

1715
1716
1717
1718
1719
1720
1721
1694
1695
1696
1697
1698
1699
1700

1701
1702
1703
1704
1705
1706
1707
1708







-
+







	    for (xx = 0; xx < width; xx ++) {
		alpha = *(alphaPtr + (yy * alphaPitch)
			+ (xx * alphaIncr) + alphaOffset);
		Tcl_AppendPrintfToObj(psObj, "%02X", alpha | 0x01);
		lineLen += 2;
		if (lineLen >= 60) {
		    lineLen = 0;
		    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "\n", -1);
		}
	    }

	    /*
	     * Generate data in gray mode; in this case, take a weighted sum
	     * of the red, green, and blue values.
	     */
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
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







-
+

















-
+



















-
+










-
+










		blue = pixelPtr[blockPtr->offset[2]];

		Tcl_AppendPrintfToObj(psObj, "%02X", (int) floor(0.5 +
			( 0.3086 * red + 0.6094 * green + 0.0820 * blue)));
		lineLen += 2;
		if (lineLen >= 60) {
		    lineLen = 0;
		    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "\n", -1);
		}
	    }
	    break;
	}
	default:
	    /*
	     * Generate transparency data. We must prevent a transparent value
	     * of 0 because of a bug in some HP printers.
	     */

	    for (xx = 0; xx < width; xx ++) {
		alpha = *(alphaPtr + (yy * alphaPitch)
			+ (xx * alphaIncr) + alphaOffset);
		Tcl_AppendPrintfToObj(psObj, "%02X", alpha | 0x01);
		lineLen += 2;
		if (lineLen >= 60) {
		    lineLen = 0;
		    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "\n", -1);
		}
	    }

	    /*
	     * Finally, color mode. Here, just output the red, green, and blue
	     * values directly.
	     */

	    for (xx = 0; xx < width; xx ++) {
		pixelPtr = blockPtr->pixelPtr + (yy * blockPtr->pitch)
			+ (xx * blockPtr->pixelSize);

		Tcl_AppendPrintfToObj(psObj, "%02X%02X%02X",
			pixelPtr[blockPtr->offset[0]],
			pixelPtr[blockPtr->offset[1]],
			pixelPtr[blockPtr->offset[2]]);
		lineLen += 6;
		if (lineLen >= 60) {
		    lineLen = 0;
		    Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, "\n", -1);
		}
	    }
	    break;
	}
    }

    /*
     * The end-of-data marker.
     */

    Tcl_AppendToObj(psObj, ">\n", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, ">\n", -1);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCanvText.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70


71
72
73
74
75
76
77
1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73





-
-
+
+









-
-
-
-


















-
+




















-
+








-
-
+
+







/*
 * tkCanvText.c --
 *
 *	This file implements text items for canvas widgets.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1991-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The structure below defines the record for each text item.
 */

typedef struct TextItem {
    Tk_Item header;		/* Generic stuff that's the same for all
				 * types. MUST BE FIRST IN STRUCTURE. */
    Tk_CanvasTextInfo *textInfoPtr;
				/* Pointer to a structure containing
				 * information about the selection and
				 * insertion cursor. The structure is owned by
				 * (and shared with) the generic canvas
				 * code. */
    /*
     * Fields that are set by widget commands other than "configure".
     */

    double x, y;		/* Positioning point for text. */
    Tcl_Size insertPos;		/* Character index of character just before
    int insertPos;		/* Character index of character just before
				 * which the insertion cursor is displayed. */

    /*
     * Configuration settings that are updated by Tk_ConfigureWidget.
     */

    Tk_Anchor anchor;		/* Where to anchor text relative to (x,y). */
    Tk_TSOffset tsoffset;
    XColor *color;		/* Color for text. */
    XColor *activeColor;	/* Color for text. */
    XColor *disabledColor;	/* Color for text. */
    Tk_Font tkfont;		/* Font for drawing text. */
    Tk_Justify justify;		/* Justification mode for text. */
    Pixmap stipple;		/* Stipple bitmap for text, or None. */
    Pixmap activeStipple;	/* Stipple bitmap for text, or None. */
    Pixmap disabledStipple;	/* Stipple bitmap for text, or None. */
    char *text;			/* Text for item (malloc-ed). */
    int width;			/* Width of lines for word-wrap, pixels. Zero
				 * means no word-wrap. */
    int underline;		/* Index of character to put underline beneath
				 * or INT_MIN for no underlining. */
				 * or -1 for no underlining. */
    double angle;		/* What angle, in degrees, to draw the text
				 * at. */

    /*
     * Fields whose values are derived from the current values of the
     * configuration settings above.
     */

    Tcl_Size numChars;		/* Length of text in characters. */
    Tcl_Size numBytes;		/* Length of text in bytes. */
    int numChars;		/* Length of text in characters. */
    int numBytes;		/* Length of text in bytes. */
    Tk_TextLayout textLayout;	/* Cached text layout information. */
    int actualWidth;		/* Width of text as computed. Used to make
				 * selections of wrapped text display
				 * right. */
    double drawOrigin[2];	/* Where we start drawing from. */
    GC gc;			/* Graphics context for drawing text. */
    GC selTextGC;		/* Graphics context for selected text. */
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183

184
185

186
187

188
189

190
191

192
193

194
195

196
197

198
199

200
201
202

203
204

205
206
207
208
209
210



211
212

213
214
215
216
217
218
219
220
221
222

223
224
225
226

227
228
229
230
231
232
233
234



235
236
237

238
239
240
241
242

243
244
245

246
247

248
249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
89
90
91
92
93
94
95















































































96
97

98
99

100
101

102
103

104
105

106
107

108
109

110
111

112
113

114
115

116
117
118

119
120

121
122
123
124



125
126
127
128

129
130
131
132
133
134
135
136
137
138

139
140
141
142

143
144
145
146
147
148



149
150
151
152
153

154
155
156
157
158

159
160
161

162
163

164
165

166
167
168
169
170
171
172


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201


202
203
204
205
206
207
208
209







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+


-
+

-
+



-
-
-
+
+
+

-
+









-
+



-
+





-
-
-
+
+
+


-
+




-
+


-
+

-
+

-
+






-
-

















-
+











-
-
+







static const Tk_CustomOption tagsOption = {
    Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL
};
static const Tk_CustomOption offsetOption = {
    TkOffsetParseProc, TkOffsetPrintProc, INT2PTR(TK_OFFSET_RELATIVE)
};

static int
UnderlineParseProc(
    TCL_UNUSED(void *),	/* Not used.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item (ignored). */
{
    int *underlinePtr = (int *) (widgRec + offset);
    Tcl_Obj obj;
    int code;
    Tcl_Size underline;

    if (value == NULL || *value == 0) {
	*underlinePtr = INT_MIN; /* No underline */
	return TCL_OK;
    }

    obj.refCount = 1;
    obj.bytes = (char *)value;
    obj.length = strlen(value);
    obj.typePtr = NULL;
    code = TkGetIntForIndex(&obj, TCL_INDEX_NONE, 0, &underline);
    if (code == TCL_OK) {
	if (underline < INT_MIN) {
	    underline = INT_MIN;
	} else if (underline > INT_MAX) {
	    underline = INT_MAX;
	}
	*underlinePtr = (int)underline;

    } else {
	Tcl_AppendResult(interp, "bad index \"", value,
		"\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"", (char *)NULL);
    }
	return code;
}

static const char *
UnderlinePrintProc(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Pointer to record for item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    int underline = *(int *)(widgRec + offset);
    char *p;

    if (underline == INT_MIN) {
	p = (char *)"";
	*freeProcPtr = TCL_STATIC;
	return p;
    } else if (underline == INT_MAX) {
	p = (char *)"end+1";
	*freeProcPtr = TCL_STATIC;
	return p;
    } else if (underline == -1) {
	p = (char *)"end";
	*freeProcPtr = TCL_STATIC;
	return p;
    }
    p = (char *)ckalloc(32);
    if (underline < 0) {
	snprintf(p, 32, "end%d", 1 + underline);
    } else {
	snprintf(p, 32, "%d", underline);
    }
    *freeProcPtr = TCL_DYNAMIC;
    return p;
}

static const Tk_CustomOption underlineOption = {
    UnderlineParseProc, UnderlinePrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_COLOR, "-activefill", NULL, NULL,
	NULL, offsetof(TextItem, activeColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
	NULL, offsetof(TextItem, activeStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
	"center", offsetof(TextItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"center", Tk_Offset(TextItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_DOUBLE, "-angle", NULL, NULL,
	"0.0", offsetof(TextItem, angle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0.0", Tk_Offset(TextItem, angle), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
	NULL, offsetof(TextItem, disabledColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
	NULL, offsetof(TextItem, disabledStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-fill", NULL, NULL,
	DEF_CANVITEM_OUTLINE, offsetof(TextItem, color), TK_CONFIG_NULL_OK, NULL},
	"black", Tk_Offset(TextItem, color), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_FONT, "-font", NULL, NULL,
	DEF_CANVTEXT_FONT, offsetof(TextItem, tkfont), 0, NULL},
	DEF_CANVTEXT_FONT, Tk_Offset(TextItem, tkfont), 0, NULL},
    {TK_CONFIG_JUSTIFY, "-justify", NULL, NULL,
	"left", offsetof(TextItem, justify), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"left", Tk_Offset(TextItem, justify), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
	"0,0", offsetof(TextItem, tsoffset),
	"0,0", Tk_Offset(TextItem, tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
	NULL, offsetof(TextItem, stipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_STRING, "-text", NULL, NULL,
	"", offsetof(TextItem, text), 0, NULL},
    {TK_CONFIG_CUSTOM, "-underline", NULL, NULL, NULL,
	offsetof(TextItem, underline), TK_CONFIG_NULL_OK, &underlineOption},
	"", Tk_Offset(TextItem, text), 0, NULL},
    {TK_CONFIG_INT, "-underline", NULL, NULL,
	"-1", Tk_Offset(TextItem, underline), 0, NULL},
    {TK_CONFIG_PIXELS, "-width", NULL, NULL,
	"0", offsetof(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ComputeTextBbox(Tk_Canvas canvas, TextItem *textPtr);
static int		ConfigureText(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size argc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
			    Tcl_Obj *const objv[], int flags);
static int		CreateText(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int argc, Tcl_Obj *const objv[]);
static void		DeleteText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayCanvText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static Tcl_Size	GetSelText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size offset, char *buffer,
			    Tcl_Size maxBytes);
static int		GetSelText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, int offset, char *buffer,
			    int maxBytes);
static int		GetTextIndex(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Obj *obj, Tcl_Size *indexPtr);
			    Tcl_Obj *obj, int *indexPtr);
static void		ScaleText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		SetTextCursor(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size index);
			    Tk_Item *itemPtr, int index);
static int		TextCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int argc, Tcl_Obj *const objv[]);
static void		TextDeleteChars(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size first, Tcl_Size last);
			    Tk_Item *itemPtr, int first, int last);
static void		TextInsert(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size beforeThis, Tcl_Obj *obj);
			    Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj);
static int		TextToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static double		TextToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *pointPtr);
static int		TextToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static void		RotateText(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		TranslateText(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);

/*
 * The structures below defines the rectangle and oval item types by means of
 * functions that can be invoked by generic item code.
 */

Tk_ItemType tkTextType = {
    "text",			/* name */
    sizeof(TextItem),		/* itemSize */
    CreateText,			/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureText,		/* configureProc */
    TextCoords,			/* coordProc */
    DeleteText,			/* deleteProc */
    DisplayCanvText,		/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    TextToPoint,		/* pointProc */
    TextToArea,			/* areaProc */
    TextToPostscript,		/* postscriptProc */
    ScaleText,			/* scaleProc */
    TranslateText,		/* translateProc */
    GetTextIndex,		/* indexProc */
    SetTextCursor,		/* icursorProc */
    GetSelText,			/* selectionProc */
    TextInsert,			/* insertProc */
    TextDeleteChars,		/* dTextProc */
    NULL,			/* nextPtr */
    RotateText,			/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

#define ROUND(d) ((int) floor((d) + 0.5))

/*
 *--------------------------------------------------------------
 *
310
311
312
313
314
315
316
317

318
319
320
321

322
323
324
325
326
327
328
224
225
226
227
228
229
230

231
232
233
234

235
236
237
238
239
240
241
242







-
+



-
+








static int
CreateText(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing rectangle. */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Carry out initialization that is needed in order to clean up after
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360



361
362
363
364
365
366
367
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271



272
273
274
275
276
277
278
279
280
281







-
+







-
-
-
+
+
+







    textPtr->tkfont	= NULL;
    textPtr->justify	= TK_JUSTIFY_LEFT;
    textPtr->stipple	= None;
    textPtr->activeStipple = None;
    textPtr->disabledStipple = None;
    textPtr->text	= NULL;
    textPtr->width	= 0;
    textPtr->underline	= INT_MIN;
    textPtr->underline	= -1;
    textPtr->angle	= 0.0;

    textPtr->numChars	= 0;
    textPtr->numBytes	= 0;
    textPtr->textLayout = NULL;
    textPtr->actualWidth = 0;
    textPtr->drawOrigin[0] = textPtr->drawOrigin[1] = 0.0;
    textPtr->gc		= NULL;
    textPtr->selTextGC	= NULL;
    textPtr->cursorOffGC = NULL;
    textPtr->gc		= None;
    textPtr->selTextGC	= None;
    textPtr->cursorOffGC = None;
    textPtr->sine	= 0.0;
    textPtr->cosine	= 1.0;

    /*
     * Process the arguments to fill in the item record. Only 1 (list) or 2 (x
     * y) coords are allowed.
     */
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431


432
433
434
435
436
437
438
439
440
441
442


443
444
445
446
447
448
449
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343


344
345
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
363







-
+















-
-
+
+









-
-
+
+








static int
TextCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    TextItem *textPtr = (TextItem *) itemPtr;

    if (objc == 0) {
	Tcl_Obj *obj = Tcl_NewObj();
	Tcl_Obj *subobj = Tcl_NewDoubleObj(textPtr->x);

	Tcl_ListObjAppendElement(interp, obj, subobj);
	subobj = Tcl_NewDoubleObj(textPtr->y);
	Tcl_ListObjAppendElement(interp, obj, subobj);
	Tcl_SetObjResult(interp, obj);
	return TCL_OK;
    } else if (objc > 2) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 2, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", (char *)NULL);
		"wrong # coordinates: expected 0 or 2, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", NULL);
	return TCL_ERROR;
    }

    if (objc == 1) {
	if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		(Tcl_Obj ***) &objv) != TCL_OK) {
	    return TCL_ERROR;
	} else if (objc != 2) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "wrong # coordinates: expected 2, got %" TCL_SIZE_MODIFIER "d", objc));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", (char *)NULL);
		    "wrong # coordinates: expected 2, got %d", objc));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", NULL);
	    return TCL_ERROR;
	}
    }
    if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
		&textPtr->x) != TCL_OK)
	    || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
		&textPtr->y) != TCL_OK)) {
473
474
475
476
477
478
479
480

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418







-
+
















-
+







 */

static int
ConfigureText(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Rectangle item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    XGCValues gcValues;
    GC newGC, newSelGC;
    unsigned long mask;
    Tk_Window tkwin;
    Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
    XColor *selBgColorPtr;
    XColor *color;
    Pixmap stipple;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, textPtr, flags)) {
	    (const char **) objv, (char *) textPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * A few of the options require additional processing, such as graphics
     * contexts.
     */
529
530
531
532
533
534
535
536

537
538
539
540
541
542
543
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457







-
+







	    color = textPtr->disabledColor;
	}
	if (textPtr->disabledStipple != None) {
	    stipple = textPtr->disabledStipple;
	}
    }

    newGC = newSelGC = NULL;
    newGC = newSelGC = None;
    if (textPtr->tkfont != NULL) {
	gcValues.font = Tk_FontId(textPtr->tkfont);
	mask = GCFont;
	if (color != NULL) {
	    gcValues.foreground = color->pixel;
	    mask |= GCForeground;
	    if (stipple != None) {
554
555
556
557
558
559
560
561

562
563
564
565

566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582

583
584
585
586
587
588
589
468
469
470
471
472
473
474

475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

494
495

496
497
498
499
500
501
502
503







-
+



-
+














-
+

-
+







	    mask |= GCStipple|GCFillStyle;
	}
	if (textInfoPtr->selFgColorPtr != NULL) {
	    gcValues.foreground = textInfoPtr->selFgColorPtr->pixel;
	}
	newSelGC = Tk_GetGC(tkwin, mask|GCForeground, &gcValues);
    }
    if (textPtr->gc != NULL) {
    if (textPtr->gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), textPtr->gc);
    }
    textPtr->gc = newGC;
    if (textPtr->selTextGC != NULL) {
    if (textPtr->selTextGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), textPtr->selTextGC);
    }
    textPtr->selTextGC = newSelGC;

    selBgColorPtr = Tk_3DBorderColor(textInfoPtr->selBorder);
    if (Tk_3DBorderColor(textInfoPtr->insertBorder)->pixel
	    == selBgColorPtr->pixel) {
	if (selBgColorPtr->pixel == BlackPixelOfScreen(Tk_Screen(tkwin))) {
	    gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin));
	} else {
	    gcValues.foreground = BlackPixelOfScreen(Tk_Screen(tkwin));
	}
	newGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
    } else {
	newGC = NULL;
	newGC = None;
    }
    if (textPtr->cursorOffGC != NULL) {
    if (textPtr->cursorOffGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), textPtr->cursorOffGC);
    }
    textPtr->cursorOffGC = newGC;

    /*
     * If the text was changed, move the selection and insertion indices to
     * keep them inside the item.
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572







-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteText(
    TCL_UNUSED(Tk_Canvas),	/* Info about overall canvas widget. */
    Tk_Canvas canvas,		/* Info about overall canvas widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    TextItem *textPtr = (TextItem *) itemPtr;

    if (textPtr->color != NULL) {
	Tk_FreeColor(textPtr->color);
674
675
676
677
678
679
680
681

682
683
684

685
686
687

688
689
690
691
692
693
694
588
589
590
591
592
593
594

595
596
597

598
599
600

601
602
603
604
605
606
607
608







-
+


-
+


-
+







	Tk_FreeBitmap(display, textPtr->disabledStipple);
    }
    if (textPtr->text != NULL) {
	ckfree(textPtr->text);
    }

    Tk_FreeTextLayout(textPtr->textLayout);
    if (textPtr->gc != NULL) {
    if (textPtr->gc != None) {
	Tk_FreeGC(display, textPtr->gc);
    }
    if (textPtr->selTextGC != NULL) {
    if (textPtr->selTextGC != None) {
	Tk_FreeGC(display, textPtr->selTextGC);
    }
    if (textPtr->cursorOffGC != NULL) {
    if (textPtr->cursorOffGC != None) {
	Tk_FreeGC(display, textPtr->cursorOffGC);
    }
}

/*
 *--------------------------------------------------------------
 *
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639







-
+








static void
ComputeTextBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    TextItem *textPtr)		/* Item whose bbox is to be recomputed. */
{
    Tk_CanvasTextInfo *textInfoPtr;
    int width, height, fudge, i;
    int leftX, topY, width, height, fudge, i;
    Tk_State state = textPtr->header.state;
    double x[4], y[4], dx[4], dy[4], sinA, cosA, tmp;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

733
734
735
736
737
738
739


740
741
742
743
744
745
746
747
748
749
750
751




752
753

754
755
756
757




758
759

760
761
762
763
764
765
766
767
768
769
770
771




772
773

774
775
776



777

778
779

780
781
782
783
784
785
786
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664



665
666
667
668
669

670
671
672
673

674
675
676
677
678

679
680
681
682
683
684
685
686
687
688



689
690
691
692
693

694
695
696
697
698
699
700

701
702

703
704
705
706
707
708
709
710







+
+









-
-
-
+
+
+
+

-
+



-
+
+
+
+

-
+









-
-
-
+
+
+
+

-
+



+
+
+
-
+

-
+







    }

    /*
     * Use overall geometry information to compute the top-left corner of the
     * bounding box for the text item.
     */

    leftX = ROUND(textPtr->x);
    topY = ROUND(textPtr->y);
    for (i=0 ; i<4 ; i++) {
	dx[i] = dy[i] = 0.0;
    }
    switch (textPtr->anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_N:
    case TK_ANCHOR_NE:
	break;

    case TK_ANCHOR_SW:
    case TK_ANCHOR_S:
    case TK_ANCHOR_SE:
    case TK_ANCHOR_W:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_E:
	topY -= height / 2;
	for (i=0 ; i<4 ; i++) {
	    dy[i] = -height;
	    dy[i] = -height / 2;
	}
	break;

    default:
    case TK_ANCHOR_SW:
    case TK_ANCHOR_S:
    case TK_ANCHOR_SE:
	topY -= height;
	for (i=0 ; i<4 ; i++) {
	    dy[i] = -height / 2;
	    dy[i] = -height;
	}
	break;
    }
    switch (textPtr->anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_W:
    case TK_ANCHOR_SW:
	break;

    case TK_ANCHOR_NE:
    case TK_ANCHOR_E:
    case TK_ANCHOR_SE:
    case TK_ANCHOR_N:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_S:
	leftX -= width / 2;
	for (i=0 ; i<4 ; i++) {
	    dx[i] = -width;
	    dx[i] = -width / 2;
	}
	break;

    case TK_ANCHOR_NE:
    case TK_ANCHOR_E:
    case TK_ANCHOR_SE:
    default:
	leftX -= width;
	for (i=0 ; i<4 ; i++) {
	    dx[i] = -width / 2;
	    dx[i] = -width;
	}
	break;
    }

    textPtr->actualWidth = width;

    sinA = textPtr->sine;
870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
794
795
796
797
798
799
800

801
802
803
804
805
806
807
808







-
+







    Drawable drawable,		/* Pixmap or window in which to draw item. */
    int x, int y, int width, int height)
				/* Describes region of canvas that must be
				 * redisplayed (not used). */
{
    TextItem *textPtr;
    Tk_CanvasTextInfo *textInfoPtr;
    Tcl_Size selFirstChar, selLastChar;
    int selFirstChar, selLastChar;
    short drawableX, drawableY;
    Pixmap stipple;
    Tk_State state = itemPtr->state;

    textPtr = (TextItem *) itemPtr;
    textInfoPtr = textPtr->textInfoPtr;

892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914


915
916
917
918
919
920
921
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830
831
832
833
834
835
836


837
838
839
840
841
842
843
844
845







-
+













-
-
+
+







	}
    } else if (state == TK_STATE_DISABLED) {
	if (textPtr->disabledStipple != None) {
	    stipple = textPtr->disabledStipple;
	}
    }

    if (textPtr->gc == NULL) {
    if (textPtr->gc == None) {
	return;
    }

    /*
     * If we're stippling, then modify the stipple offset in the GC. Be sure
     * to reset the offset when done, since the GC is supposed to be
     * read-only.
     */

    if (stipple != None) {
	Tk_CanvasSetOffset(canvas, textPtr->gc, &textPtr->tsoffset);
    }

    selFirstChar = TCL_INDEX_NONE;
    selLastChar = 0;
    selFirstChar = -1;
    selLastChar = 0;		/* lint. */
    Tk_CanvasDrawableCoords(canvas, textPtr->drawOrigin[0],
	    textPtr->drawOrigin[1], &drawableX, &drawableY);

    if (textInfoPtr->selItemPtr == itemPtr) {
	selFirstChar = textInfoPtr->selectFirst;
	selLastChar = textInfoPtr->selectLast;
	if (selLastChar > textPtr->numChars) {
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
928
929
930
931
932
933
934

935
936
937
938
939
940
941
942







-
+








	    Tk_SetCaretPos(Tk_CanvasTkwin(canvas), points[0].x, points[0].y,
		    height);
	    if (textInfoPtr->cursorOn) {
		Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable,
			textInfoPtr->insertBorder, points, 4,
			textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED);
	    } else if (textPtr->cursorOffGC != NULL) {
	    } else if (textPtr->cursorOffGC != None) {
		/*
		 * Redraw the background over the area of the cursor, even
		 * though the cursor is turned off. This guarantees that the
		 * selection won't make the cursor invisible on mono displays,
		 * where both may be drawn in the same color.
		 */

1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039



1040
1041
1042
1043
1044
1045
1046
1047



1048
1049
1050
1051
1052

1053
1054
1055
1056
1057
1058
1059
952
953
954
955
956
957
958

959




960
961
962

963
964
965




966
967
968

969
970
971

972
973
974
975
976
977
978
979







-
+
-
-
-
-
+
+
+
-



-
-
-
-
+
+
+
-



-
+







     * there is selected text and the foregrounds differ, draw the regular
     * text up to the selection, draw the selection, then draw the rest of the
     * regular text. Drawing the regular text and then the selected text over
     * it would causes problems with anti-aliased text because the two
     * anti-aliasing colors would blend together.
     */

    if ((selFirstChar != TCL_INDEX_NONE) && (textPtr->selTextGC != textPtr->gc)) {
    if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) {
	if (0 < selFirstChar) {
	    TkDrawAngledTextLayout(display, drawable, textPtr->gc,
		    textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		    0, selFirstChar);
	TkDrawAngledTextLayout(display, drawable, textPtr->gc,
		textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		0, selFirstChar);
	}
	TkDrawAngledTextLayout(display, drawable, textPtr->selTextGC,
		textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		selFirstChar, selLastChar + 1);
	if (selLastChar + 1 < textPtr->numChars) {
	    TkDrawAngledTextLayout(display, drawable, textPtr->gc,
		    textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		    selLastChar + 1, textPtr->numChars);
	TkDrawAngledTextLayout(display, drawable, textPtr->gc,
		textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		selLastChar + 1, -1);
	}
    } else {
	TkDrawAngledTextLayout(display, drawable, textPtr->gc,
		textPtr->textLayout, drawableX, drawableY, textPtr->angle,
		0, textPtr->numChars);
		0, -1);
    }
    TkUnderlineAngledTextLayout(display, drawable, textPtr->gc,
	    textPtr->textLayout, drawableX, drawableY, textPtr->angle,
	    textPtr->underline);

    if (stipple != None) {
	XSetTSOrigin(display, textPtr->gc, 0, 0);
1077
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112


1113
1114
1115
1116
1117
1118
1119
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008

1009

1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029


1030
1031
1032
1033
1034
1035
1036
1037
1038







-
+




-
+
-




















-
-
+
+







 *----------------------------------------------------------------------
 */

static void
TextInsert(
    Tk_Canvas canvas,		/* Canvas containing text item. */
    Tk_Item *itemPtr,		/* Text item to be modified. */
    Tcl_Size index,			/* Character index before which string is to
    int index,			/* Character index before which string is to
				 * be inserted. */
    Tcl_Obj *obj)		/* New characters to be inserted. */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    int byteIndex, charsAdded;
    int byteIndex, byteCount, charsAdded;
    Tcl_Size byteCount;
    char *newStr, *text;
    const char *string;
    Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;

    string = Tcl_GetStringFromObj(obj, &byteCount);

    text = textPtr->text;

    if (index < 0) {
	index = 0;
    }
    if (index > textPtr->numChars) {
	index = textPtr->numChars;
    }
    byteIndex = Tcl_UtfAtIndex(text, index) - text;
    byteCount = strlen(string);
    if (byteCount == 0) {
	return;
    }

    newStr = (char *)ckalloc(textPtr->numBytes + byteCount + 1);
    memcpy(newStr, text, byteIndex);
    newStr = ckalloc(textPtr->numBytes + byteCount + 1);
    memcpy(newStr, text, (size_t) byteIndex);
    strcpy(newStr + byteIndex, string);
    strcpy(newStr + byteIndex + byteCount, text + byteIndex);

    ckfree(text);
    textPtr->text = newStr;
    charsAdded = Tcl_NumUtfChars(string, byteCount);
    textPtr->numChars += charsAdded;
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168

1169
1170
1171
1172
1173
1174
1175
1078
1079
1080
1081
1082
1083
1084

1085
1086

1087
1088
1089
1090
1091
1092
1093
1094







-
+

-
+







 *--------------------------------------------------------------
 */

static void
TextDeleteChars(
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Item in which to delete characters. */
    Tcl_Size first,			/* Character index of first character to
    int first,			/* Character index of first character to
				 * delete. */
    Tcl_Size last)			/* Character index of last character to delete
    int last)			/* Character index of last character to delete
				 * (inclusive). */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    int byteIndex, byteCount, charsRemoved;
    char *newStr, *text;
    Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;

1185
1186
1187
1188
1189
1190
1191
1192
1193


1194
1195
1196
1197
1198
1199
1200
1104
1105
1106
1107
1108
1109
1110


1111
1112
1113
1114
1115
1116
1117
1118
1119







-
-
+
+







    }
    charsRemoved = last + 1 - first;

    byteIndex = Tcl_UtfAtIndex(text, first) - text;
    byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
	- (text + byteIndex);

    newStr = (char *)ckalloc(textPtr->numBytes + 1 - byteCount);
    memcpy(newStr, text, byteIndex);
    newStr = ckalloc(textPtr->numBytes + 1 - byteCount);
    memcpy(newStr, text, (size_t) byteIndex);
    strcpy(newStr + byteIndex, text + byteIndex + byteCount);

    ckfree(text);
    textPtr->text = newStr;
    textPtr->numChars -= charsRemoved;
    textPtr->numBytes -= byteCount;

1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379

1380
1381
1382
1383
1384
1385
1386
1245
1246
1247
1248
1249
1250
1251

































1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














+







	    (int) (rectPtr[3] - rectPtr[1] + 0.5),
	    textPtr->angle);
}

/*
 *--------------------------------------------------------------
 *
 * RotateText --
 *
 *	This function is called to rotate a text item by a given amount about a
 *	point. Note that this does *not* rotate the text of the item.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the text anchor is rotated by angleRad about (originX,
 *	originY), and the bounding box is updated in the generic part of the
 *	item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateText(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item that is being rotated. */
    double originX, double originY,
    double angleRad)		/* Amount by which item is to be rotated. */
{
    TextItem *textPtr = (TextItem *) itemPtr;

    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &textPtr->x, &textPtr->y);
    ComputeTextBbox(canvas, textPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ScaleText --
 *
 *	This function is invoked to rescale a text item.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Scales the position of the text, but not the size of the font for the
 *	text.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ScaleText(
    Tk_Canvas canvas,		/* Canvas containing rectangle. */
    Tk_Item *itemPtr,		/* Rectangle to be scaled. */
    double originX, double originY,
				/* Origin about which to scale rect. */
    double scaleX,		/* Amount to scale in X direction. */
1443
1444
1445
1446
1447
1448
1449
1450

1451
1452
1453
1454
1455

1456
1457
1458
1459

1460

1461
1462

1463
1464
1465
1466

1467
1468
1469
1470



1471
1472
1473
1474
1475
1476
1477
1478


1479
1480
1481

1482
1483
1484
1485


1486
1487
1488
1489
1490

1491
1492
1493
1494


1495
1496
1497
1498
1499
1500
1501


1502
1503
1504
1505
1506


1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517



1518
1519
1520
1521
1522


1523
1524







1525





1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341

1342
1343
1344
1345

1346
1347
1348
1349

1350
1351



1352




1353
1354
1355








1356
1357
1358
1359

1360
1361
1362


1363
1364
1365
1366
1367
1368

1369
1370
1371


1372
1373
1374
1375
1376
1377
1378


1379
1380
1381
1382
1383


1384
1385
1386
1387






1388


1389
1390
1391
1392
1393
1394


1395
1396
1397

1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420







-
+




-
+



-
+

+

-
+

-
-
-
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+


-
+


-
-
+
+




-
+


-
-
+
+





-
-
+
+



-
-
+
+


-
-
-
-
-
-

-
-
+
+
+



-
-
+
+

-
+
+
+
+
+
+
+

+
+
+
+
+


-
+







 *
 *--------------------------------------------------------------
 */

static int
GetTextIndex(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item for which the index is being
				 * specified. */
    Tcl_Obj *obj,		/* Specification of a particular character in
				 * itemPtr's text. */
    Tcl_Size *indexPtr)		/* Where to store converted character
    int *indexPtr)		/* Where to store converted character
				 * index. */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    Tcl_Size length, idx;
    int length;
    int c;
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
    Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
    const char *string;
    const char *string = Tcl_GetStringFromObj(obj, &length);

    if (TCL_OK == TkGetIntForIndex(obj, textPtr->numChars - 1, 1, &idx)) {
	if (idx < 0) {
	    idx = 0;
    c = string[0];
	} else if (idx > textPtr->numChars) {
	    idx = textPtr->numChars;
	}
	*indexPtr = idx;

    if ((c == 'e') && (strncmp(string, "end", (unsigned) length) == 0)) {
	*indexPtr = textPtr->numChars;
	return TCL_OK;
    }

    string = Tcl_GetStringFromObj(obj, &length);
    c = string[0];

    if ((c == 'i')
	    && (strncmp(string, "insert", length) == 0)) {
    } else if ((c == 'i')
	    && (strncmp(string, "insert", (unsigned) length) == 0)) {
	*indexPtr = textPtr->insertPos;
    } else if ((c == 's') && (length >= 5)
	    && (strncmp(string, "sel.first", length) == 0)) {
	    && (strncmp(string, "sel.first", (unsigned) length) == 0)) {
	if (textInfoPtr->selItemPtr != itemPtr) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "selection isn't in item", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", (char *)NULL);
		    "selection isn't in item", -1));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", NULL);
	    return TCL_ERROR;
	}
	*indexPtr = textInfoPtr->selectFirst;
    } else if ((c == 's') && (length >= 5)
	    && (strncmp(string, "sel.last", length) == 0)) {
	    && (strncmp(string, "sel.last", (unsigned) length) == 0)) {
	if (textInfoPtr->selItemPtr != itemPtr) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "selection isn't in item", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", (char *)NULL);
		    "selection isn't in item", -1));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "UNSELECTED", NULL);
	    return TCL_ERROR;
	}
	*indexPtr = textInfoPtr->selectLast;
    } else if (c == '@') {
	int x, y;
	double tmp, cs = textPtr->cosine, s = textPtr->sine;
	char *rest;
	double tmp, c = textPtr->cosine, s = textPtr->sine;
	char *end;
	const char *p;

	p = string+1;
	rest = strchr((char *)p, ',');
	if (!rest) {
	tmp = strtod(p, &end);
	if ((end == p) || (*end != ',')) {
	    goto badIndex;
	}
	*rest = '\0';
	if (Tcl_GetDouble(NULL, p, &tmp) != TCL_OK) {
	    *rest = ',';
	    goto badIndex;
	}
	*rest = ',';
	x = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
	p = rest+1;
	if (Tcl_GetDouble(NULL, p, &tmp) != TCL_OK) {
	p = end+1;
	tmp = strtod(p, &end);
	if ((end == p) || (*end != 0)) {
	    goto badIndex;
	}
	y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
	x -= (int) textPtr->drawOrigin[0];
	y -= (int) textPtr->drawOrigin[1];
	x += canvasPtr->scrollX1 - (int) textPtr->drawOrigin[0];
	y += canvasPtr->scrollY1 - (int) textPtr->drawOrigin[1];
	*indexPtr = Tk_PointToChar(textPtr->textLayout,
		(int) (x*cs - y*s), (int) (y*cs + x*s));
		(int) (x*c - y*s), (int) (y*c + x*s));
    } else if (Tcl_GetIntFromObj(NULL, obj, indexPtr) == TCL_OK) {
	if (*indexPtr < 0) {
	    *indexPtr = 0;
	} else if (*indexPtr > textPtr->numChars) {
	    *indexPtr = textPtr->numChars;
	}
    } else {
	/*
	 * Some of the paths here leave messages in the interp's result, so we
	 * have to clear it out before storing our own message.
	 */

    badIndex:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "TEXT", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "TEXT", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
1543
1544
1545
1546
1547
1548
1549

1550
1551
1552

1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440

1441
1442
1443
1444
1445
1446
1447
1448







+


-
+


-
+







 *
 * Side effects:
 *	The cursor position will change.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
SetTextCursor(
    TCL_UNUSED(Tk_Canvas),		/* Record describing canvas widget. */
    Tk_Canvas canvas,		/* Record describing canvas widget. */
    Tk_Item *itemPtr,		/* Text item in which cursor position is to be
				 * set. */
    Tcl_Size index)			/* Character index of character just before
    int index)			/* Character index of character just before
				 * which cursor is to be positioned. */
{
    TextItem *textPtr = (TextItem *) itemPtr;

    if (index < 0) {
	textPtr->insertPos = 0;
    } else if (index > textPtr->numChars) {
1582
1583
1584
1585
1586
1587
1588
1589

1590
1591

1592
1593

1594
1595
1596

1597
1598
1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620



1621

1622
1623
1624
1625
1626
1627
1628
1468
1469
1470
1471
1472
1473
1474

1475
1476

1477
1478

1479
1480
1481

1482
1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499



1500
1501
1502
1503
1504
1505
1506

1507
1508
1509
1510
1511
1512
1513
1514







-
+

-
+

-
+


-
+




-
+












-
-
-




+
+
+
-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static Tcl_Size
static int
GetSelText(
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing selection. */
    Tk_Canvas canvas,		/* Canvas containing selection. */
    Tk_Item *itemPtr,		/* Text item containing selection. */
    Tcl_Size offset,			/* Byte offset within selection of first
    int offset,			/* Byte offset within selection of first
				 * character to be returned. */
    char *buffer,		/* Location in which to place selection. */
    Tcl_Size maxBytes)		/* Maximum number of bytes to place at buffer,
    int maxBytes)		/* Maximum number of bytes to place at buffer,
				 * not including terminating NULL
				 * character. */
{
    TextItem *textPtr = (TextItem *) itemPtr;
    Tcl_Size byteCount;
    int byteCount;
    char *text;
    const char *selStart, *selEnd;
    Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;

    if ((textInfoPtr->selectFirst < 0) ||
	    (textInfoPtr->selectFirst > textInfoPtr->selectLast)) {
	return 0;
    }
    text = textPtr->text;
    selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst);
    selEnd = Tcl_UtfAtIndex(selStart,
	    textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst);
    if (selEnd  <= selStart + offset) {
	return 0;
    }
    byteCount = selEnd - selStart - offset;
    if (byteCount > maxBytes) {
	byteCount = maxBytes;
    }
    if (byteCount <= 0) {
	return 0;
    }
    memcpy(buffer, selStart + offset, byteCount);
    memcpy(buffer, selStart + offset, (size_t) byteCount);
    buffer[byteCount] = '\0';
    return byteCount;
}

/*
 *--------------------------------------------------------------
 *
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
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617

1618
1619
1620
1621
1622
1623

1624
1625
1626
1627
1628
1629
1630







-
+
+
+









+









-
+


+


-







    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

    if (prepass != 0) {
	goto done;
    }

    Tcl_ResetResult(interp);
    Tk_CanvasPsColor(interp, canvas, color);
    if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
	goto error;
    }
    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

    if (stipple != None) {
	Tcl_ResetResult(interp);
	Tk_CanvasPsStipple(interp, canvas, stipple);
	Tcl_AppendPrintfToObj(psObj, "/StippleText {\n    %s} bind def\n",
		Tcl_GetString(Tcl_GetObjResult(interp)));
    }

    x = 0;  y = 0;  justify = NULL;	/* lint. */
    switch (textPtr->anchor) {
    case TK_ANCHOR_NW:	   x = 0; y = 0; break;
    case TK_ANCHOR_N:	   x = 1; y = 0; break;
    case TK_ANCHOR_NE:	   x = 2; y = 0; break;
    case TK_ANCHOR_E:	   x = 2; y = 1; break;
    case TK_ANCHOR_SE:	   x = 2; y = 2; break;
    case TK_ANCHOR_S:	   x = 1; y = 2; break;
    case TK_ANCHOR_SW:	   x = 0; y = 2; break;
    case TK_ANCHOR_W:	   x = 0; y = 1; break;
    default: x = 1; y = 1; break;
    case TK_ANCHOR_CENTER: x = 1; y = 1; break;
    }
    switch (textPtr->justify) {
    case TK_JUSTIFY_LEFT:   justify = "0";   break;
    case TK_JUSTIFY_CENTER: justify = "0.5"; break;
    case TK_JUSTIFY_RIGHT:  justify = "1";   break;
    default:                justify = "0";   break;
    }

    Tk_GetFontMetrics(textPtr->tkfont, &fm);

    Tcl_AppendPrintfToObj(psObj, "%.15g %.15g %.15g [\n",
	    textPtr->angle, textPtr->x, Tk_CanvasPsY(canvas, textPtr->y));
    Tcl_ResetResult(interp);

Changes to generic/tkCanvUtil.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41

42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
1
2
3
4
5
6

7
8
9
10
11
12
13
14



15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37

38
39

40
41
42
43
44

45
46
47
48
49
50
51
52






-
+







-
-
-
+
-
















-
+





-
+

-





-
+







/*
 * tkCanvUtil.c --
 *
 *	This file contains a collection of utility functions used by the
 *	implementations of various canvas item types.
 *
 * Copyright © 1994 Sun Microsystems, Inc.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkCanvas.h"

#ifdef _WIN32
#include "tkWinInt.h"
#include <assert.h>
#endif

/*
 * Structures defined only in this file.
 */

typedef struct SmoothAssocData {
    struct SmoothAssocData *nextPtr;
				/* Pointer to next SmoothAssocData. */
    Tk_SmoothMethod smooth;	/* Name and functions associated with this
				 * option. */
} SmoothAssocData;

const Tk_SmoothMethod tkBezierSmoothMethod = {
    "true",
    TkMakeBezierCurve,
    (void (*) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr,
	    int numPoints, int numSteps))(void *)TkMakeBezierPostscript,
	    int numPoints, int numSteps)) TkMakeBezierPostscript,
};
static const Tk_SmoothMethod tkRawSmoothMethod = {
    "raw",
    TkMakeRawCurve,
    (void (*) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr,
	    int numPoints, int numSteps))(void *)TkMakeRawCurvePostscript,
	    int numPoints, int numSteps)) TkMakeRawCurvePostscript,
};


/*
 * Function forward-declarations.
 */

static void		SmoothMethodCleanupProc(void *clientData,
static void		SmoothMethodCleanupProc(ClientData clientData,
			    Tcl_Interp *interp);
static SmoothAssocData *InitSmoothMethods(Tcl_Interp *interp);
static int		DashConvert(char *l, const char *p, int n,
			    double width);
static void		TranslateAndAppendCoords(TkCanvas *canvPtr,
			    double x, double y, XPoint *outArr, int numOut);
static inline Tcl_Obj *	GetPostscriptBuffer(Tcl_Interp *interp);
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
Tk_CanvasGetCoord(
    TCL_UNUSED(Tcl_Interp *),		/* Interpreter for error reporting. */
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to which coordinate applies. */
    const char *string,		/* Describes coordinate (any screen coordinate
				 * form may be used here). */
    double *doublePtr)		/* Place to store converted coordinate. */
{
    if (Tk_GetScreenMM(Canvas(canvas)->interp, Canvas(canvas)->tkwin, string,
	    doublePtr) != TCL_OK) {
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
Tk_CanvasGetCoordFromObj(
    TCL_UNUSED(Tcl_Interp *),		/* Interpreter for error reporting. */
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to which coordinate applies. */
    Tcl_Obj *obj,		/* Describes coordinate (any screen coordinate
				 * form may be used here). */
    double *doublePtr)		/* Place to store converted coordinate. */
{
    return Tk_GetDoublePixelsFromObj(Canvas(canvas)->interp, Canvas(canvas)->tkwin, obj, doublePtr);
}
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342







-
+







Tk_CanvasSetOffset(
    Tk_Canvas canvas,		/* Token for a canvas. */
    GC gc,			/* Graphics context that is about to be used
				 * to draw a stippled pattern as part of
				 * redisplaying the canvas. */
    Tk_TSOffset *offset)	/* Offset (may be NULL pointer)*/
{
    TkCanvas *canvasPtr = Canvas(canvas);
    register TkCanvas *canvasPtr = Canvas(canvas);
    int flags = 0;
    int x = - canvasPtr->drawableXOrigin;
    int y = - canvasPtr->drawableYOrigin;

    if (offset != NULL) {
	flags = offset->flags;
	x += offset->xoffset;
399
400
401
402
403
404
405
406

407
408

409
410
411

412
413
414


415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432


433
434
435
436
437
438
439
395
396
397
398
399
400
401

402
403

404
405
406

407
408


409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426


427
428
429
430
431
432
433
434
435







-
+

-
+


-
+

-
-
+
+
















-
-
+
+







 *	argument.
 *
 *--------------------------------------------------------------
 */

int
Tk_CanvasTagsParseProc(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Not used.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option (list of tag names). */
    char *widgRec,		/* Pointer to record for item. */
    TCL_UNUSED(Tcl_Size))			/* Offset into item (ignored). */
    int offset)			/* Offset into item (ignored). */
{
    Tk_Item *itemPtr = (Tk_Item *) widgRec;
    Tcl_Size argc, i;
    register Tk_Item *itemPtr = (Tk_Item *) widgRec;
    int argc, i;
    const char **argv;
    Tk_Uid *newPtr;

    /*
     * Break the value up into the individual tag names.
     */

    if (Tcl_SplitList(interp, value, &argc, &argv) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Make sure that there's enough space in the item to hold the tag names.
     */

    if (itemPtr->tagSpace < argc) {
	newPtr = (Tk_Uid *)ckalloc(argc * sizeof(Tk_Uid));
	for (i = itemPtr->numTags - 1; i != TCL_INDEX_NONE; i--) {
	newPtr = ckalloc(argc * sizeof(Tk_Uid));
	for (i = itemPtr->numTags-1; i >= 0; i--) {
	    newPtr[i] = itemPtr->tagPtr[i];
	}
	if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
	    ckfree(itemPtr->tagPtr);
	}
	itemPtr->tagPtr = newPtr;
	itemPtr->tagSpace = argc;
466
467
468
469
470
471
472
473
474


475
476

477
478
479
480
481

482
483
484
485
486
487
488
462
463
464
465
466
467
468


469
470
471

472
473
474
475
476

477
478
479
480
481
482
483
484







-
-
+
+

-
+




-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

const char *
Tk_CanvasTagsPrintProc(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    TCL_UNUSED(Tcl_Size),			/* Ignored. */
    int offset,			/* Ignored. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    Tk_Item *itemPtr = (Tk_Item *) widgRec;
    register Tk_Item *itemPtr = (Tk_Item *) widgRec;

    if (itemPtr->numTags == 0) {
	*freeProcPtr = NULL;
	return "";
    }
    if (itemPtr->numTags == 1) {
	*freeProcPtr = NULL;
508
509
510
511
512
513
514
515

516
517

518
519
520

521
522
523
524
525
526
527
504
505
506
507
508
509
510

511
512

513
514
515

516
517
518
519
520
521
522
523







-
+

-
+


-
+







 *	indicated in the value argument.
 *
 *--------------------------------------------------------------
 */

int
TkCanvasDashParseProc(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Not used.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    return Tk_GetDash(interp, value, (Tk_Dash *) (widgRec+offset));
}

/*
 *--------------------------------------------------------------
 *
542
543
544
545
546
547
548
549
550


551
552

553
554
555
556
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573

574
575
576
577

578
579

580
581
582
583
584
585
586
538
539
540
541
542
543
544


545
546
547

548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
567
568

569
570
571
572

573
574

575
576
577
578
579
580
581
582







-
-
+
+

-
+











-
+








-
+



-
+

-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

const char *
TkCanvasDashPrintProc(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),	/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset in record for item. */
    int offset,			/* Offset in record for item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    Tk_Dash *dash = (Tk_Dash *) (widgRec+offset);
    char *buffer, *p;
    int i = dash->number;

    if (i < 0) {
	i = -i;
	*freeProcPtr = TCL_DYNAMIC;
	buffer = (char *)ckalloc((Tcl_Size)i + 1);
	buffer = ckalloc(i + 1);
	p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array;
	memcpy(buffer, p, (unsigned int) i);
	buffer[i] = 0;
	return buffer;
    } else if (!i) {
	*freeProcPtr = NULL;
	return "";
    }
    buffer = (char *)ckalloc(4 * (Tcl_Size)i);
    buffer = ckalloc(4 * i);
    *freeProcPtr = TCL_DYNAMIC;

    p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array;
    snprintf(buffer, 4 * (size_t)i, "%d", *p++ & 0xff);
    sprintf(buffer, "%d", *p++ & 0xff);
    while (--i) {
	snprintf(buffer + strlen(buffer), 4 * (size_t)i - strlen(buffer), " %d", *p++ & 0xff);
	sprintf(buffer+strlen(buffer), " %d", *p++ & 0xff);
    }
    return buffer;
}

/*
 *--------------------------------------------------------------
 *
602
603
604
605
606
607
608
609

610
611
612
613
614

615
616
617
618
619
620
621
598
599
600
601
602
603
604

605
606
607
608
609

610
611
612
613
614
615
616
617







-
+




-
+








static SmoothAssocData *
InitSmoothMethods(
    Tcl_Interp *interp)
{
    SmoothAssocData *methods, *ptr;

    methods = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
    methods = ckalloc(sizeof(SmoothAssocData));
    methods->smooth.name = tkRawSmoothMethod.name;
    methods->smooth.coordProc = tkRawSmoothMethod.coordProc;
    methods->smooth.postscriptProc = tkRawSmoothMethod.postscriptProc;

    ptr = methods->nextPtr = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
    ptr = methods->nextPtr = ckalloc(sizeof(SmoothAssocData));
    ptr->smooth.name = tkBezierSmoothMethod.name;
    ptr->smooth.coordProc = tkBezierSmoothMethod.coordProc;
    ptr->smooth.postscriptProc = tkBezierSmoothMethod.postscriptProc;
    ptr->nextPtr = NULL;

    Tcl_SetAssocData(interp, "smoothMethod", SmoothMethodCleanupProc,methods);
    return methods;
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655
637
638
639
640
641
642
643

644
645
646
647
648
649
650
651







-
+








void
Tk_CreateSmoothMethod(
    Tcl_Interp *interp,
    const Tk_SmoothMethod *smooth)
{
    SmoothAssocData *methods, *typePtr2, *prevPtr, *ptr;
    methods = (SmoothAssocData *)Tcl_GetAssocData(interp, "smoothMethod", NULL);
    methods = Tcl_GetAssocData(interp, "smoothMethod", NULL);

    /*
     * Initialize if we were not previously initialized.
     */

    if (methods == NULL) {
	methods = InitSmoothMethods(interp);
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677







-
+







	    } else {
		prevPtr->nextPtr = typePtr2->nextPtr;
	    }
	    ckfree(typePtr2);
	    break;
	}
    }
    ptr = (SmoothAssocData *)ckalloc(sizeof(SmoothAssocData));
    ptr = ckalloc(sizeof(SmoothAssocData));
    ptr->smooth.name = smooth->name;
    ptr->smooth.coordProc = smooth->coordProc;
    ptr->smooth.postscriptProc = smooth->postscriptProc;
    ptr->nextPtr = methods;
    Tcl_SetAssocData(interp, "smoothMethod", SmoothMethodCleanupProc, ptr);
}

694
695
696
697
698
699
700
701

702
703

704
705

706
707
708
709
710
711
712
690
691
692
693
694
695
696

697
698

699
700

701
702
703
704
705
706
707
708







-
+

-
+

-
+







 *	Smooth methods are removed.
 *
 *----------------------------------------------------------------------
 */

static void
SmoothMethodCleanupProc(
    void *clientData,	/* Points to "smoothMethod" AssocData for the
    ClientData clientData,	/* Points to "smoothMethod" AssocData for the
				 * interpreter. */
    TCL_UNUSED(Tcl_Interp *))		/* Interpreter that is being deleted. */
    Tcl_Interp *interp)		/* Interpreter that is being deleted. */
{
    SmoothAssocData *ptr, *methods = (SmoothAssocData *)clientData;
    SmoothAssocData *ptr, *methods = clientData;

    while (methods != NULL) {
	ptr = methods;
	methods = methods->nextPtr;
	ckfree(ptr);
    }
}
726
727
728
729
730
731
732
733

734
735

736
737
738

739
740

741
742
743
744
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

781
782
783
784
785
786
787
722
723
724
725
726
727
728

729
730

731
732
733

734
735

736
737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

776
777
778
779
780
781
782
783







-
+

-
+


-
+

-
+











-
+










-
+
















-
+







 *	indicated in the value argument.
 *
 *--------------------------------------------------------------
 */

int
TkSmoothParseProc(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Ignored. */
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    const Tk_SmoothMethod **smoothPtr =
    register const Tk_SmoothMethod **smoothPtr =
	    (const Tk_SmoothMethod **) (widgRec + offset);
    const Tk_SmoothMethod *smooth = NULL;
    int b;
    size_t length;
    SmoothAssocData *methods;

    if (value == NULL || *value == 0) {
	*smoothPtr = NULL;
	return TCL_OK;
    }
    length = strlen(value);
    methods = (SmoothAssocData *)Tcl_GetAssocData(interp, "smoothMethod", NULL);
    methods = Tcl_GetAssocData(interp, "smoothMethod", NULL);

    /*
     * Not initialized yet; fix that now.
     */

    if (methods == NULL) {
	methods = InitSmoothMethods(interp);
    }

    /*
     * Backward compatibility hack.
     * Backward compatability hack.
     */

    if (strncmp(value, "bezier", length) == 0) {
	smooth = &tkBezierSmoothMethod;
    }

    /*
     * Search the list of installed smooth methods.
     */

    while (methods != NULL) {
	if (strncmp(value, methods->smooth.name, length) == 0) {
	    if (smooth != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"ambiguous smooth method \"%s\"", value));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "SMOOTH", value,
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	    smooth = &methods->smooth;
	}
	methods = methods->nextPtr;
    }
    if (smooth) {
818
819
820
821
822
823
824
825
826


827
828
829


830
831
832
833

834
835
836
837
838
839
840
814
815
816
817
818
819
820


821
822
823


824
825
826
827
828

829
830
831
832
833
834
835
836







-
-
+
+

-
-
+
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

const char *
TkSmoothPrintProc(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),	/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset into item. */
    TCL_UNUSED(Tcl_FreeProc **))	/* Pointer to variable to fill in with
    int offset,			/* Offset into item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    const Tk_SmoothMethod *smoothPtr =
    register const Tk_SmoothMethod *smoothPtr =
	    * (Tk_SmoothMethod **) (widgRec + offset);

    return smoothPtr ? smoothPtr->name : "0";
}
/*
 *--------------------------------------------------------------
 *
856
857
858
859
860
861
862
863
864

865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883

884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907
908
909
910
911
912
913
914
915

916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936

937
938
939
940
941
942
943
852
853
854
855
856
857
858


859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877

878
879

880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897

898
899
900
901
902
903
904
905
906
907
908
909

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

931
932
933
934
935
936
937
938







-
-
+


















-
+

-
+

















-
+











-
+




















-
+







int
Tk_GetDash(
    Tcl_Interp *interp,		/* Used for error reporting. */
    const char *value,		/* Textual specification of dash list. */
    Tk_Dash *dash)		/* Pointer to record in which to store dash
				 * information. */
{
    Tcl_Size argc;
    int i;
    int argc, i;
    const char **largv, **argv = NULL;
    char *pt;

    if ((value == NULL) || (*value == '\0')) {
	dash->number = 0;
	return TCL_OK;
    }

    /*
     * switch is usually compiled more efficiently than a chain of conditions.
     */

    switch (*value) {
    case '.': case ',': case '-': case '_':
	i = DashConvert(NULL, value, -1, 0.0);
	if (i <= 0) {
	    goto badDashList;
	}
	i = (int)strlen(value);
	i = strlen(value);
	if (i > (int) sizeof(char *)) {
	    dash->pattern.pt = pt = (char *)ckalloc(strlen(value));
	    dash->pattern.pt = pt = ckalloc(strlen(value));
	} else {
	    pt = dash->pattern.array;
	}
	memcpy(pt, value, (unsigned) i);
	dash->number = -i;
	return TCL_OK;
    }

    if (Tcl_SplitList(interp, (char *) value, &argc, &argv) != TCL_OK) {
	Tcl_ResetResult(interp);
	goto badDashList;
    }

    if ((unsigned) ABS(dash->number) > sizeof(char *)) {
	ckfree(dash->pattern.pt);
    }
    if (argc > (int) sizeof(char *)) {
	dash->pattern.pt = pt = (char *)ckalloc(argc);
	dash->pattern.pt = pt = ckalloc(argc);
    } else {
	pt = dash->pattern.array;
    }
    dash->number = argc;

    largv = argv;
    while (argc > 0) {
	if (Tcl_GetInt(interp, *largv, &i) != TCL_OK || i < 1 || i>255) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "expected integer in the range 1..255 but got \"%s\"",
		    *largv));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", NULL);
	    goto syntaxError;
	}
	*pt++ = i;
	argc--;
	largv++;
    }

    if (argv != NULL) {
	ckfree(argv);
    }
    return TCL_OK;

    /*
     * Something went wrong. Generate error message, clean up and return.
     */

  badDashList:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad dash list \"%s\": must be a list of integers or a format like \"-..\"",
	    value));
    Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "VALUE", "DASH", NULL);
  syntaxError:
    if (argv != NULL) {
	ckfree(argv);
    }
    if ((unsigned) ABS(dash->number) > sizeof(char *)) {
	ckfree(dash->pattern.pt);
    }
962
963
964
965
966
967
968
969

970
971
972
973
974
975
976
957
958
959
960
961
962
963

964
965
966
967
968
969
970
971







-
+







 *--------------------------------------------------------------
 */

void
Tk_CreateOutline(
    Tk_Outline *outline)	/* Outline structure to be filled in. */
{
    outline->gc = NULL;
    outline->gc = None;
    outline->width = 1.0;
    outline->activeWidth = 0.0;
    outline->disabledWidth = 0.0;
    outline->offset = 0;
    outline->dash.number = 0;
    outline->activeDash.number = 0;
    outline->disabledDash.number = 0;
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
1012







-
+







 */

void
Tk_DeleteOutline(
    Display *display,		/* Display containing window. */
    Tk_Outline *outline)
{
    if (outline->gc != NULL) {
    if (outline->gc != None) {
	Tk_FreeGC(display, outline->gc);
    }
    if ((unsigned) ABS(outline->dash.number) > sizeof(char *)) {
	ckfree(outline->dash.pattern.pt);
    }
    if ((unsigned) ABS(outline->activeDash.number) > sizeof(char *)) {
	ckfree(outline->activeDash.pattern.pt);
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233
1234
1235
1236







-
+








    if ((dash->number<-1) ||
	    ((dash->number == -1) && (dash->pattern.array[0] != ','))) {
	char *q;
	int i = -dash->number;

	p = (i > (int)sizeof(char *)) ? dash->pattern.pt : dash->pattern.array;
	q = (char *)ckalloc(2 * i);
	q = ckalloc(2 * i);
	i = DashConvert(q, p, i, width);
	XSetDashes(Canvas(canvas)->display, outline->gc, outline->offset, q,i);
	ckfree(q);
    } else if (dash->number>2 || (dash->number==2 &&
	    (dash->pattern.array[0]!=dash->pattern.array[1]))) {
	p = (dash->number > (int) sizeof(char *))
		? dash->pattern.pt : dash->pattern.array;
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275







+







	Tk_CanvasSetOffset(canvas, outline->gc, tsoffset);
	tsoffset->xoffset += w;
	tsoffset->yoffset += h;
	return 1;
    }
    return 0;
}


/*
 *--------------------------------------------------------------
 *
 * Tk_ResetOutlineGC
 *
 *	Restores the GC to the situation before Tk_ChangeOutlineGC() was
1430
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473

1474
1475
1476
1477








1478
1479
1480




1481
1482

1483
1484
1485
1486
1487
1488
1489
1426
1427
1428
1429
1430
1431
1432

1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450

1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462

1463
1464
1465
1466
1467
1468

1469
1470
1471


1472
1473
1474
1475
1476
1477
1478
1479
1480


1481
1482
1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493







-
+










-
+






-
+











-
+





-
+


-
-
+
+
+
+
+
+
+
+

-
-
+
+
+
+

-
+







	}
    }

    Tcl_AppendPrintfToObj(psObj, "%.15g setlinewidth\n", width);

    ptr = ((unsigned) ABS(dash->number) > sizeof(char *)) ?
	    dash->pattern.pt : dash->pattern.array;
    Tcl_AppendToObj(psObj, "[", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, "[", -1);
    if (dash->number > 0) {
	Tcl_Obj *converted;
	char *p = ptr;

	converted = Tcl_ObjPrintf("%d", *p++ & 0xff);
	for (i = dash->number-1 ; i>0 ; i--) {
	    Tcl_AppendPrintfToObj(converted, " %d", *p++ & 0xff);
	}
	Tcl_AppendObjToObj(psObj, converted);
	if (dash->number & 1) {
	    Tcl_AppendToObj(psObj, " ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, " ", -1);
	    Tcl_AppendObjToObj(psObj, converted);
	}
	Tcl_DecrRefCount(converted);
	Tcl_AppendPrintfToObj(psObj, "] %d setdash\n", outline->offset);
    } else if (dash->number < 0) {
	if (dash->number < -5) {
	    lptr = (char *)ckalloc(1 - 2*dash->number);
	    lptr = ckalloc(1 - 2*dash->number);
	}
	i = DashConvert(lptr, ptr, -dash->number, width);
	if (i > 0) {
	    char *p = lptr;

	    Tcl_AppendPrintfToObj(psObj, "%d", *p++ & 0xff);
	    for (; --i>0 ;) {
		Tcl_AppendPrintfToObj(psObj, " %d", *p++ & 0xff);
	    }
	    Tcl_AppendPrintfToObj(psObj, "] %d setdash\n", outline->offset);
	} else {
	    Tcl_AppendToObj(psObj, "] 0 setdash\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "] 0 setdash\n", -1);
	}
	if (lptr != pattern) {
	    ckfree(lptr);
	}
    } else {
	Tcl_AppendToObj(psObj, "] 0 setdash\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "] 0 setdash\n", -1);
    }

    Tk_CanvasPsColor(interp, canvas, color);

    if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Note that psObj might hold an invalid reference now.
     */

    if (stipple != None) {
	Tcl_AppendToObj(GetPostscriptBuffer(interp), "StrokeClip ", TCL_INDEX_NONE);
	Tk_CanvasPsStipple(interp, canvas, stipple);
	Tcl_AppendToObj(GetPostscriptBuffer(interp), "StrokeClip ", -1);
	if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	Tcl_AppendToObj(GetPostscriptBuffer(interp), "stroke\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(GetPostscriptBuffer(interp), "stroke\n", -1);
    }

    return TCL_OK;
}

/*
 *--------------------------------------------------------------
1641
1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659







-
+








int
TkCanvTranslatePath(
    TkCanvas *canvPtr,		/* The canvas */
    int numVertex,		/* Number of vertices specified by
				 * coordArr[] */
    double *coordArr,		/* X and Y coordinates for each vertex */
    TCL_UNUSED(int),		/* True if this is a closed polygon */
    int closedPath,		/* True if this is a closed polygon */
    XPoint *outArr)		/* Write results here, if not NULL */
{
    int numOutput = 0;		/* Number of output coordinates */
    double lft, rgh;		/* Left and right sides of the bounding box */
    double top, btm;		/* Top and bottom sizes of the bounding box */
    double *tempArr;		/* Temporary storage used by the clipper */
    double *a, *b, *t;		/* Pointers to parts of the temporary
1712
1713
1714
1715
1716
1717
1718
1719

1720
1721
1722
1723
1724
1725
1726
1716
1717
1718
1719
1720
1721
1722

1723
1724
1725
1726
1727
1728
1729
1730







-
+







     * coordArr[] requires. Divide this space into two separate arrays a[] and
     * b[]. Initialize a[] to be equal to coordArr[].
     */

    if (numVertex*12 <= (int) (sizeof(staticSpace) / sizeof(double))) {
	tempArr = staticSpace;
    } else {
	tempArr = (double *)ckalloc(numVertex * 12 * sizeof(double));
	tempArr = ckalloc(numVertex * 12 * sizeof(double));
    }
    for (i=0; i<numVertex*2; i++){
	tempArr[i] = coordArr[i];
    }
    a = tempArr;
    b = &tempArr[numVertex*6];

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
1859
1860
1861
1862
1863
1864
1865





































1866
1867
1868
1869
1870
1871
1872
1873







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








	TranslateAndAppendCoords(canvPtr, a[i*2], a[i*2+1], outArr, i);
    }
    if (tempArr != staticSpace) {
	ckfree(tempArr);
    }
    return numOutput;
}

/*
 *--------------------------------------------------------------
 *
 * TkRotatePoint --
 *
 *	Rotate a point about another point. The angle should be converted into
 *	its sine and cosine before calling this function.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The point in (*xPtr,*yPtr) is updated to be rotated about
 *	(originX,originY) by the amount given by the sine and cosine of the
 *	angle to rotate.
 *
 *--------------------------------------------------------------
 */

void
TkRotatePoint(
    double originX, double originY,	/* The point about which to rotate. */
    double sine, double cosine,		/* How much to rotate? */
    double *xPtr, double *yPtr)		/* The point to be rotated. (INOUT) */
{
    double x = *xPtr - originX;
    double y = *yPtr - originY;

    /*
     * Beware! The canvas coordinate space is flipped vertically, so rotations
     * go the "wrong" way with respect to mathematics.
     */

    *xPtr = originX + x * cosine + y * sine;
    *yPtr = originY - x * sine + y * cosine;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCanvWind.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkCanvWind.c --
 *
 *	This file implements window items for canvas widgets.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
42
43
44
45
46
47
48
49

50
51

52
53

54
55
56
57

58
59

60
61
62
63
64
65
66
67
68
69
70

71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90

91
92

93
94

95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
42
43
44
45
46
47
48

49
50

51
52

53
54
55
56

57
58

59
60
61
62
63
64
65
66
67
68
69

70
71
72
73

74
75
76
77
78
79


80
81
82
83
84
85

86
87

88
89

90
91

92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132


133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151







-
+

-
+

-
+



-
+

-
+










-
+



-
+





-
-






-
+

-
+

-
+

-
+








-
+



















-
+











-
-
+










-
+







};
static const Tk_CustomOption tagsOption = {
    Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL,
	"center", offsetof(WindowItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"center", Tk_Offset(WindowItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_PIXELS, "-height", NULL, NULL,
	"0", offsetof(WindowItem, height), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(WindowItem, height), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_PIXELS, "-width", NULL, NULL,
	"0", offsetof(WindowItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL},
	"0", Tk_Offset(WindowItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_WINDOW, "-window", NULL, NULL,
	NULL, offsetof(WindowItem, tkwin), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(WindowItem, tkwin), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ComputeWindowBbox(Tk_Canvas canvas,
			    WindowItem *winItemPtr);
static int		ConfigureWinItem(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static int		CreateWinItem(Tcl_Interp *interp,
			    Tk_Canvas canvas, struct Tk_Item *itemPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeleteWinItem(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display);
static void		DisplayWinItem(Tk_Canvas canvas,
			    Tk_Item *itemPtr, Display *display, Drawable dst,
			    int x, int y, int width, int height);
static void		RotateWinItem(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScaleWinItem(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateWinItem(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double deltaX, double deltaY);
static int		WinItemCoords(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, Tcl_Size objc,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
			    Tcl_Obj *const objv[]);
static void		WinItemLostContentProc(void *clientData,
static void		WinItemLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		WinItemRequestProc(void *clientData,
static void		WinItemRequestProc(ClientData clientData,
			    Tk_Window tkwin);
static void		WinItemStructureProc(void *clientData,
static void		WinItemStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static int		WinItemToArea(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *rectPtr);
static int		WinItemToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static double		WinItemToPoint(Tk_Canvas canvas,
			    Tk_Item *itemPtr, double *pointPtr);
#ifdef X_GetImage
static int		xerrorhandler(void *clientData, XErrorEvent *e);
static int		xerrorhandler(ClientData clientData, XErrorEvent *e);
#endif
static int		CanvasPsWindow(Tcl_Interp *interp,
			    Tk_Window tkwin, Tk_Canvas canvas, double x,
			    double y, int width, int height);

/*
 * The structure below defines the window item type by means of functions
 * that can be invoked by generic item code.
 */

Tk_ItemType tkWindowType = {
    "window",			/* name */
    sizeof(WindowItem),		/* itemSize */
    CreateWinItem,		/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureWinItem,		/* configureProc */
    WinItemCoords,		/* coordProc */
    DeleteWinItem,		/* deleteProc */
    DisplayWinItem,		/* displayProc */
    TK_ALWAYS_REDRAW,		/* flags */
    1|TK_CONFIG_OBJS,		/* flags */
    WinItemToPoint,		/* pointProc */
    WinItemToArea,		/* areaProc */
    WinItemToPostscript,	/* postscriptProc */
    ScaleWinItem,		/* scaleProc */
    TranslateWinItem,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* cursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateWinItem,		/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 * The structure below defines the official type record for the canvas (as
 * geometry manager):
 */

static const Tk_GeomMgr canvasGeomType = {
    "canvas",				/* name */
    WinItemRequestProc,			/* requestProc */
    WinItemLostContentProc,		/* lostContentProc */
    WinItemLostSlaveProc,		/* lostSlaveProc */
};

/*
 *--------------------------------------------------------------
 *
 * CreateWinItem --
 *
168
169
170
171
172
173
174
175

176
177
178
179

180
181
182
183
184
185
186
165
166
167
168
169
170
171

172
173
174
175

176
177
178
179
180
181
182
183







-
+



-
+








static int
CreateWinItem(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing window. */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Initialize item's record.
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217







-
+







	if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) {
	    i = 1;
	}
    }
    if (WinItemCoords(interp, canvas, itemPtr, i, objv) != TCL_OK) {
	goto error;
    }
    if (ConfigureWinItem(interp, canvas, itemPtr, objc - i, objv + i, 0)
    if (ConfigureWinItem(interp, canvas, itemPtr, objc-i, objv+i, 0)
	    == TCL_OK) {
	return TCL_OK;
    }

  error:
    DeleteWinItem(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas)));
    return TCL_ERROR;
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264

265
266

267
268
269
270
271
272
273
274
275
276
277
278
279


280
281
282
283
284
285
286
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262

263
264
265
266
267
268
269
270
271
272
273
274


275
276
277
278
279
280
281
282
283







-
+

















-
+

-
+











-
-
+
+








static int
WinItemCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1, y1, x2, y2, ... */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;

    if (objc == 0) {
	Tcl_Obj *objs[2];

	objs[0] = Tcl_NewDoubleObj(winItemPtr->x);
	objs[1] = Tcl_NewDoubleObj(winItemPtr->y);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, objs));
    } else if (objc < 3) {
	if (objc==1) {
	    if (Tcl_ListObjGetElements(interp, objv[0], &objc,
		    (Tcl_Obj ***) &objv) != TCL_OK) {
		return TCL_ERROR;
	    } else if (objc != 2) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"wrong # coordinates: expected 2, got %" TCL_SIZE_MODIFIER "d", objc));
			"wrong # coordinates: expected 2, got %d", objc));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "WINDOW",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	}
	if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0], &winItemPtr->x)
		!= TCL_OK) || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
		&winItemPtr->y) != TCL_OK)) {
	    return TCL_ERROR;
	}
	ComputeWindowBbox(canvas, winItemPtr);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 2, got %" TCL_SIZE_MODIFIER "d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "WINDOW", (char *)NULL);
		"wrong # coordinates: expected 0 or 2, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "WINDOW", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323







-
+










-
+







 */

static int
ConfigureWinItem(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Window item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv.  */
    int objc,			/* Number of elements in objv.  */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;
    Tk_Window oldWindow;
    Tk_Window canvasTkwin;

    oldWindow = winItemPtr->tkwin;
    canvasTkwin = Tk_CanvasTkwin(canvas);
    if (TCL_OK != Tk_ConfigureWidget(interp, canvasTkwin, configSpecs, objc,
	    objv, winItemPtr, flags)) {
	    (const char **) objv, (char *) winItemPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }

    /*
     * A few of the options require additional processing.
     */

374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385







-
+







    ComputeWindowBbox(canvas, winItemPtr);
    return TCL_OK;

  badWindow:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "can't use %s in a window item of this canvas",
	    Tk_PathName(winItemPtr->tkwin)));
    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
    winItemPtr->tkwin = NULL;
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411







-
+







 *--------------------------------------------------------------
 */

static void
DeleteWinItem(
    Tk_Canvas canvas,		/* Overall info about widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    TCL_UNUSED(Display *))	/* Display containing window for canvas. */
    Display *display)		/* Display containing window for canvas. */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;
    Tk_Window canvasTkwin = Tk_CanvasTkwin(canvas);

    if (winItemPtr->tkwin != NULL) {
	Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask,
		WinItemStructureProc, winItemPtr);
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524







-
+







	y -= height;
	break;
    case TK_ANCHOR_W:
	y -= height/2;
	break;
    case TK_ANCHOR_NW:
	break;
    default:
    case TK_ANCHOR_CENTER:
	x -= width/2;
	y -= height/2;
	break;
    }

    /*
     * Store the information in the item header.
555
556
557
558
559
560
561
562

563

564
565


566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
552
553
554
555
556
557
558

559
560
561


562
563


564
565
566
567
568
569
570
571
572
573



574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594







-
+

+
-
-
+
+
-
-










-
-
-














-







 *--------------------------------------------------------------
 */

static void
DisplayWinItem(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    Tk_Item *itemPtr,		/* Item to be displayed. */
    TCL_UNUSED(Display *),	/* Display on which to draw item. */
    Display *display,		/* Display on which to draw item. */
    Drawable drawable,		/* Pixmap or window in which to draw item. */
    int regionX, int regionY, int regionWidth, int regionHeight)
    TCL_UNUSED(int), /* Describes region of canvas that must be */
    TCL_UNUSED(int), /* redisplayed (not used). */
				/* Describes region of canvas that must be
				 * redisplayed (not used). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;
    int width, height;
    short x, y;
    Tk_Window canvasTkwin = Tk_CanvasTkwin(canvas);
    Tk_State state = itemPtr->state;

    if (winItemPtr->tkwin == NULL) {
	return;
    }

    Tcl_Preserve(canvas);

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }

    /*
     * A drawable of None is used by the canvas UnmapNotify handler
     * to indicate that we should no longer display ourselves.
     */
    if (state == TK_STATE_HIDDEN || drawable == None) {
	if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) {
	    Tk_UnmapWindow(winItemPtr->tkwin);
	} else {
	    Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin);
	}
	Tcl_Release(canvas);
	return;
    }
    Tk_CanvasWindowCoords(canvas, (double) winItemPtr->header.x1,
	    (double) winItemPtr->header.y1, &x, &y);
    width = winItemPtr->header.x2 - winItemPtr->header.x1;
    height = winItemPtr->header.y2 - winItemPtr->header.y1;

610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642
643
644
645
646
647
648
602
603
604
605
606
607
608

609
610
611
612
613
614
615
616
617
618
619
620
621
622



623


624
625
626
627

628
629
630
631
632
633
634







-














-
-
-
+
-
-




-







    if (((x + width) <= 0) || ((y + height) <= 0)
	    || (x >= Tk_Width(canvasTkwin)) || (y >= Tk_Height(canvasTkwin))) {
	if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) {
	    Tk_UnmapWindow(winItemPtr->tkwin);
	} else {
	    Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin);
	}
	Tcl_Release(canvas);
	return;
    }

    /*
     * Reposition and map the window (but in different ways depending on
     * whether the canvas is the window's parent).
     */

    if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) {
	if ((x != Tk_X(winItemPtr->tkwin)) || (y != Tk_Y(winItemPtr->tkwin))
		|| (width != Tk_Width(winItemPtr->tkwin))
		|| (height != Tk_Height(winItemPtr->tkwin))) {
	    Tk_MoveResizeWindow(winItemPtr->tkwin, x, y, width, height);
	}

	if (winItemPtr->tkwin) {
	    Tk_MapWindow(winItemPtr->tkwin);
	Tk_MapWindow(winItemPtr->tkwin);
	}

    } else {
	Tk_MaintainGeometry(winItemPtr->tkwin, canvasTkwin, x, y,
		width, height);
    }
    Tcl_Release(canvas);
}

/*
 *--------------------------------------------------------------
 *
 * WinItemToPoint --
 *
659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
645
646
647
648
649
650
651

652
653
654
655
656
657
658
659







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static double
WinItemToPoint(
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;
    double x1, x2, y1, y2, xDiff, yDiff;

    x1 = winItemPtr->header.x1;
715
716
717
718
719
720
721
722

723
724
725
726
727
728
729
701
702
703
704
705
706
707

708
709
710
711
712
713
714
715







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static int
WinItemToArea(
    TCL_UNUSED(Tk_Canvas),		/* Canvas containing item. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against rectangle. */
    double *rectPtr)		/* Pointer to array of four coordinates
				 * (x1,y1,x2,y2) describing rectangular
				 * area.  */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;

758
759
760
761
762
763
764
765
766


767
768
769
770
771
772
773
744
745
746
747
748
749
750


751
752
753
754
755
756
757
758
759







-
-
+
+







 *
 *--------------------------------------------------------------
 */

#ifdef X_GetImage
static int
xerrorhandler(
    TCL_UNUSED(void *),
    TCL_UNUSED(XErrorEvent *))
    ClientData clientData,
    XErrorEvent *e)
{
    return 0;
}
#endif /* X_GetImage */

/*
 *--------------------------------------------------------------
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
808
809
810
811
812
813
814

815
816
817
818
819
820
821
822







-
+







    case TK_ANCHOR_N:	    x -= width/2.0; y -= height;	    break;
    case TK_ANCHOR_NE:	    x -= width;	    y -= height;	    break;
    case TK_ANCHOR_E:	    x -= width;	    y -= height/2.0;	    break;
    case TK_ANCHOR_SE:	    x -= width;				    break;
    case TK_ANCHOR_S:	    x -= width/2.0;			    break;
    case TK_ANCHOR_SW:						    break;
    case TK_ANCHOR_W:			    y -= height/2.0;	    break;
    default:  x -= width/2.0; y -= height/2.0;	    break;
    case TK_ANCHOR_CENTER:  x -= width/2.0; y -= height/2.0;	    break;
    }

    return CanvasPsWindow(interp, tkwin, canvas, x, y, width, height);
}

static int
CanvasPsWindow(
871
872
873
874
875
876
877
878

879
880
881
882
883
884
885
857
858
859
860
861
862
863

864
865
866
867
868
869
870
871







-
+







    if (result == TCL_OK) {
	Tcl_AppendPrintfToObj(psObj,
		"50 dict begin\nsave\ngsave\n"
		"0 %d moveto %d 0 rlineto 0 -%d rlineto -%d 0 rlineto closepath\n"
		"1.000 1.000 1.000 setrgbcolor AdjustColor\nfill\ngrestore\n",
		height, width, height, width);
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	Tcl_AppendToObj(psObj, "\nrestore\nend\n\n\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "\nrestore\nend\n\n\n", -1);
	goto done;
    }

    /*
     * If the window is off the screen it will generate a BadMatch/XError. We
     * catch any BadMatch errors here
     */
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
907
908
909
910
911
912
913


































914
915
916
917
918
919
920







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    } else {
	Tcl_DiscardInterpState(interpState);
    }
    Tcl_DecrRefCount(psObj);
    return result;
}

/*
 *--------------------------------------------------------------
 *
 * RotateWinItem --
 *
 *	This function is called to rotate a window item by a given amount
 *	about a point. Note that this does *not* rotate the window of the
 *	item.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the window anchor is rotated by angleRad about (originX,
 *	originY), and the bounding box is updated in the generic part of the
 *	item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateWinItem(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item that is being rotated. */
    double originX, double originY,
    double angleRad)		/* Amount by which item is to be rotated. */
{
    WindowItem *winItemPtr = (WindowItem *) itemPtr;

    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &winItemPtr->x, &winItemPtr->y);
    ComputeWindowBbox(canvas, winItemPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ScaleWinItem --
 *
 *	This function is invoked to rescale a window item.
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009

1010
1011
1012
1013
1014
1015
1016
1017







-
+


-
+







 *	The window is disassociated from the window item when it is deleted.
 *
 *--------------------------------------------------------------
 */

static void
WinItemStructureProc(
    void *clientData,	/* Pointer to record describing window item. */
    ClientData clientData,	/* Pointer to record describing window item. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    WindowItem *winItemPtr = (WindowItem *)clientData;
    WindowItem *winItemPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	winItemPtr->tkwin = NULL;
    }
}

/*
1078
1079
1080
1081
1082
1083
1084
1085
1086


1087
1088

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107

1108
1109
1110
1111
1112
1113

1114
1115
1116
1117

1118
1119
1120


1121
1122

1123
1124

1125
1126
1127
1128
1129
1130
1131
1030
1031
1032
1033
1034
1035
1036


1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058

1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071


1072
1073
1074

1075
1076

1077
1078
1079
1080
1081
1082
1083
1084







-
-
+
+

-
+















-
+


-
+





-
+




+

-
-
+
+

-
+

-
+







 *	depending on the options specified for the window item.
 *
 *--------------------------------------------------------------
 */

static void
WinItemRequestProc(
    void *clientData,	/* Pointer to record for window item. */
    TCL_UNUSED(Tk_Window))		/* Window that changed its desired size. */
    ClientData clientData,	/* Pointer to record for window item. */
    Tk_Window tkwin)		/* Window that changed its desired size. */
{
    WindowItem *winItemPtr = (WindowItem *)clientData;
    WindowItem *winItemPtr = clientData;

    ComputeWindowBbox(winItemPtr->canvas, winItemPtr);

    /*
     * A drawable argument of None to DisplayWinItem is used by the canvas
     * UnmapNotify handler to indicate that we should no longer display
     * ourselves, so need to pass a (bogus) non-zero drawable value here.
     */
    DisplayWinItem(winItemPtr->canvas, (Tk_Item *) winItemPtr, NULL,
	    (Drawable) -1, 0, 0, 0, 0);
}

/*
 *--------------------------------------------------------------
 *
 * WinItemLostContentProc --
 * WinItemLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a content window that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all canvas-related information about the content window.
 *	Forgets all canvas-related information about the slave.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
WinItemLostContentProc(
    void *clientData,	/* WindowItem structure for content window window that
WinItemLostSlaveProc(
    ClientData clientData,	/* WindowItem structure for slave window that
				 * was stolen away. */
    TCL_UNUSED(Tk_Window))		/* Tk's handle for the content window. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    WindowItem *winItemPtr = (WindowItem *)clientData;
    WindowItem *winItemPtr = clientData;
    Tk_Window canvasTkwin = Tk_CanvasTkwin(winItemPtr->canvas);

    Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask,
	    WinItemStructureProc, winItemPtr);
    if (canvasTkwin != Tk_Parent(winItemPtr->tkwin)) {
	Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin);
    }

Changes to generic/tkCanvas.c.

1
2
3
4
5
6
7
8
9
10



11
12
13
14
15


16
17


18
19


20
21
22
23
24
25

26
27
28
29
30




















31
32
33
34
35
36
37
1
2
3
4
5
6
7



8
9
10
11
12
13
14
15
16
17


18
19


20
21
22
23
24



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







-
-
-
+
+
+





+
+
-
-
+
+
-
-
+
+



-
-
-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







/*
 * tkCanvas.c --
 *
 *	This module implements canvas widgets for the Tk toolkit. A canvas
 *	displays a background and a collection of graphical objects such as
 *	rectangles, lines, and texts.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1991-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/* #define USE_OLD_TAG_SEARCH 1 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"
#include "tkInt.h"
#include "default.h"
#include "tkPort.h"
#include "tkCanvas.h"
#ifdef TK_NO_DOUBLE_BUFFERING
#ifdef MAC_OSX_TK
#include "tkMacOSXInt.h"
#endif
#ifdef _WIN32
#include "tkWinInt.h"
#endif
#endif /* TK_NO_DOUBLE_BUFFERING */

/*
 * See tkCanvas.h for key data structures used to implement canvases.
 */

#ifdef USE_OLD_TAG_SEARCH
/*
 * The structure defined below is used to keep track of a tag search in
 * progress. No field should be accessed by anyone other than StartTagSearch
 * and NextItem.
 */

typedef struct TagSearch {
    TkCanvas *canvasPtr;	/* Canvas widget being searched. */
    Tk_Uid tag;			/* Tag to search for. 0 means return all
				 * items. */
    Tk_Item *currentPtr;	/* Pointer to last item returned. */
    Tk_Item *lastPtr;		/* The item right before the currentPtr is
				 * tracked so if the currentPtr is deleted we
				 * don't have to start from the beginning. */
    int searchOver;		/* Non-zero means NextItem should always
				 * return NULL. */
} TagSearch;

#else /* USE_OLD_TAG_SEARCH */
/*
 * The structure defined below is used to keep track of a tag search in
 * progress. No field should be accessed by anyone other than TagSearchScan,
 * TagSearchFirst, TagSearchNext, TagSearchScanExpr, TagSearchEvalExpr,
 * TagSearchExprInit, TagSearchExprDestroy, TagSearchDestroy.
 * (
 *   Not quite accurate: the TagSearch structure is also accessed from:
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99

100
101
102
103
104

105
106

107
108

109
110

111
112

113
114
115

116
117

118
119
120

121
122

123
124
125

126
127
128

129
130

131
132

133
134

135
136

137
138
139

140
141

142
143
144

145
146
147

148
149
150
151

152
153

154
155
156

157
158
159

160
161
162

163
164
165

166
167
168

169
170

171
172
173
174

175
176
177

178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221

222
223
224


225
226

227
228
229


230
231
232
233

234
235

236
237
238
239
240
241
242




243
244
245


246
247
248
249

250
251

252
253
254
255

256
257
258






259

260
261

262

263



264
265
266






267
268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296











297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335

336
337
338

339

340
341












342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370

371
372
373
374
375
376
377



378


379
380




381
382
383
384
385
386
387
388
389
390

391
392
393

394

395

396










397
398
399
400
401
402
403
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120

121
122
123
124
125

126
127

128
129

130
131

132
133

134
135
136

137
138

139
140
141

142
143

144
145
146

147
148
149

150
151

152
153

154
155

156
157

158
159
160

161
162

163
164
165

166
167
168

169
170
171
172

173
174

175
176
177

178
179
180

181
182
183

184
185
186

187
188
189

190
191

192
193
194
195

196
197
198

199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245
246


247
248
249

250
251


252
253
254
255
256

257
258

259
260
261
262




263
264
265
266
267


268
269




270


271
272
273
274
275
276
277


278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

377
378
379
380
381
382
383

384
385
386
387
388
389
390


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484







-
+


















+
+




















-
+


-
+




-
+

-
+

-
+

-
+

-
+


-
+

-
+


-
+

-
+


-
+


-
+

-
+

-
+

-
+

-
+


-
+

-
+


-
+


-
+



-
+

-
+


-
+


-
+


-
+


-
+


-
+

-
+



-
+


-
+



-
+














+




















+





-
+

-
-
+
+

-
+

-
-
+
+



-
+

-
+



-
-
-
-
+
+
+
+

-
-
+
+
-
-
-
-
+
-
-
+




+

-
-
+
+
+
+
+
+

+

-
+

+

+
+
+



+
+
+
+
+
+













+

















+
+
+
+
+
+
+
+
+
+
+















+
















-
+






-
+



+

+
-
-
+
+
+
+
+
+
+
+
+
+
+
+









-
+










-
+







-
+







+
+
+

+
+

-
+
+
+
+









-
+



+

+
-
+

+
+
+
+
+
+
+
+
+
+







    Tk_Item *currentPtr;	/* Pointer to last item returned. */
    Tk_Item *lastPtr;		/* The item right before the currentPtr is
				 * tracked so if the currentPtr is deleted we
				 * don't have to start from the beginning. */
    int searchOver;		/* Non-zero means NextItem should always
				 * return NULL. */
    int type;			/* Search type (see #defs below) */
    Tcl_Size id;			/* Item id for searches by id */
    int id;			/* Item id for searches by id */
    const char *string;		/* Tag expression string */
    int stringIndex;		/* Current position in string scan */
    int stringLength;		/* Length of tag expression string */
    char *rewritebuffer;	/* Tag string (after removing escapes) */
    unsigned int rewritebufferAllocated;
				/* Available space for rewrites. */
    TagSearchExpr *expr;	/* Compiled tag expression. */
} TagSearch;

/*
 * Values for the TagSearch type field.
 */

#define SEARCH_TYPE_EMPTY	0	/* Looking for empty tag */
#define SEARCH_TYPE_ID		1	/* Looking for an item by id */
#define SEARCH_TYPE_ALL		2	/* Looking for all items */
#define SEARCH_TYPE_TAG		3	/* Looking for an item by simple tag */
#define SEARCH_TYPE_EXPR	4	/* Compound search */

#endif /* USE_OLD_TAG_SEARCH */

/*
 * Custom option for handling "-state" and "-offset"
 */

static const Tk_CustomOption stateOption = {
    TkStateParseProc, TkStatePrintProc,
    NULL		/* Only "normal" and "disabled". */
};

static const Tk_CustomOption offsetOption = {
    TkOffsetParseProc, TkOffsetPrintProc, INT2PTR(TK_OFFSET_RELATIVE)
};

/*
 * Information used for argv parsing.
 */

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_BORDER, "-background", "background", "Background",
	DEF_CANVAS_BG_COLOR, offsetof(TkCanvas, bgBorder),
	DEF_CANVAS_BG_COLOR, Tk_Offset(TkCanvas, bgBorder),
	TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_BORDER, "-background", "background", "Background",
	DEF_CANVAS_BG_MONO, offsetof(TkCanvas, bgBorder),
	DEF_CANVAS_BG_MONO, Tk_Offset(TkCanvas, bgBorder),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", NULL, NULL, 0, 0, NULL},
    {TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0, NULL},
    {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_CANVAS_BORDER_WIDTH, offsetof(TkCanvas, borderWidth), 0, NULL},
	DEF_CANVAS_BORDER_WIDTH, Tk_Offset(TkCanvas, borderWidth), 0, NULL},
    {TK_CONFIG_DOUBLE, "-closeenough", "closeEnough", "CloseEnough",
	DEF_CANVAS_CLOSE_ENOUGH, offsetof(TkCanvas, closeEnough), 0, NULL},
	DEF_CANVAS_CLOSE_ENOUGH, Tk_Offset(TkCanvas, closeEnough), 0, NULL},
    {TK_CONFIG_BOOLEAN, "-confine", "confine", "Confine",
	DEF_CANVAS_CONFINE, offsetof(TkCanvas, confine), 0, NULL},
	DEF_CANVAS_CONFINE, Tk_Offset(TkCanvas, confine), 0, NULL},
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_CANVAS_CURSOR, offsetof(TkCanvas, cursor), TK_CONFIG_NULL_OK, NULL},
	DEF_CANVAS_CURSOR, Tk_Offset(TkCanvas, cursor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-height", "height", "Height",
	DEF_CANVAS_HEIGHT, offsetof(TkCanvas, height), 0, NULL},
	DEF_CANVAS_HEIGHT, Tk_Offset(TkCanvas, height), 0, NULL},
    {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_CANVAS_HIGHLIGHT_BG,
	offsetof(TkCanvas, highlightBgColorPtr), 0, NULL},
	Tk_Offset(TkCanvas, highlightBgColorPtr), 0, NULL},
    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_CANVAS_HIGHLIGHT, offsetof(TkCanvas, highlightColorPtr), 0, NULL},
	DEF_CANVAS_HIGHLIGHT, Tk_Offset(TkCanvas, highlightColorPtr), 0, NULL},
    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness",
	DEF_CANVAS_HIGHLIGHT_WIDTH, offsetof(TkCanvas, highlightWidth), 0, NULL},
	DEF_CANVAS_HIGHLIGHT_WIDTH, Tk_Offset(TkCanvas, highlightWidth), 0, NULL},
    {TK_CONFIG_BORDER, "-insertbackground", "insertBackground", "Foreground",
	DEF_CANVAS_INSERT_BG, offsetof(TkCanvas, textInfo.insertBorder), 0, NULL},
	DEF_CANVAS_INSERT_BG, Tk_Offset(TkCanvas, textInfo.insertBorder), 0, NULL},
    {TK_CONFIG_PIXELS, "-insertborderwidth", "insertBorderWidth", "BorderWidth",
	DEF_CANVAS_INSERT_BD_COLOR,
	offsetof(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_COLOR_ONLY, NULL},
	Tk_Offset(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_PIXELS, "-insertborderwidth", "insertBorderWidth", "BorderWidth",
	DEF_CANVAS_INSERT_BD_MONO,
	offsetof(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_MONO_ONLY, NULL},
	Tk_Offset(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_INT, "-insertofftime", "insertOffTime", "OffTime",
	DEF_CANVAS_INSERT_OFF_TIME, offsetof(TkCanvas, insertOffTime), 0, NULL},
	DEF_CANVAS_INSERT_OFF_TIME, Tk_Offset(TkCanvas, insertOffTime), 0, NULL},
    {TK_CONFIG_INT, "-insertontime", "insertOnTime", "OnTime",
	DEF_CANVAS_INSERT_ON_TIME, offsetof(TkCanvas, insertOnTime), 0, NULL},
	DEF_CANVAS_INSERT_ON_TIME, Tk_Offset(TkCanvas, insertOnTime), 0, NULL},
    {TK_CONFIG_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
	DEF_CANVAS_INSERT_WIDTH, offsetof(TkCanvas, textInfo.insertWidth), 0, NULL},
	DEF_CANVAS_INSERT_WIDTH, Tk_Offset(TkCanvas, textInfo.insertWidth), 0, NULL},
    {TK_CONFIG_CUSTOM, "-offset", "offset", "Offset", "0,0",
	offsetof(TkCanvas, tsoffset),TK_CONFIG_DONT_SET_DEFAULT,
	Tk_Offset(TkCanvas, tsoffset),TK_CONFIG_DONT_SET_DEFAULT,
	&offsetOption},
    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
	DEF_CANVAS_RELIEF, offsetof(TkCanvas, relief), 0, NULL},
	DEF_CANVAS_RELIEF, Tk_Offset(TkCanvas, relief), 0, NULL},
    {TK_CONFIG_STRING, "-scrollregion", "scrollRegion", "ScrollRegion",
	DEF_CANVAS_SCROLL_REGION, offsetof(TkCanvas, regionString),
	DEF_CANVAS_SCROLL_REGION, Tk_Offset(TkCanvas, regionString),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_CANVAS_SELECT_COLOR, offsetof(TkCanvas, textInfo.selBorder),
	DEF_CANVAS_SELECT_COLOR, Tk_Offset(TkCanvas, textInfo.selBorder),
	TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_CANVAS_SELECT_MONO, offsetof(TkCanvas, textInfo.selBorder),
	DEF_CANVAS_SELECT_MONO, Tk_Offset(TkCanvas, textInfo.selBorder),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth",
	DEF_CANVAS_SELECT_BD_COLOR,
	offsetof(TkCanvas, textInfo.selBorderWidth), TK_CONFIG_COLOR_ONLY, NULL},
	Tk_Offset(TkCanvas, textInfo.selBorderWidth), TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth",
	DEF_CANVAS_SELECT_BD_MONO, offsetof(TkCanvas, textInfo.selBorderWidth),
	DEF_CANVAS_SELECT_BD_MONO, Tk_Offset(TkCanvas, textInfo.selBorderWidth),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
	DEF_CANVAS_SELECT_FG_COLOR, offsetof(TkCanvas, textInfo.selFgColorPtr),
	DEF_CANVAS_SELECT_FG_COLOR, Tk_Offset(TkCanvas, textInfo.selFgColorPtr),
	TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
	DEF_CANVAS_SELECT_FG_MONO, offsetof(TkCanvas, textInfo.selFgColorPtr),
	DEF_CANVAS_SELECT_FG_MONO, Tk_Offset(TkCanvas, textInfo.selFgColorPtr),
	TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-state", "state", "State",
	"normal", offsetof(TkCanvas, canvas_state), TK_CONFIG_DONT_SET_DEFAULT,
	"normal", Tk_Offset(TkCanvas, canvas_state), TK_CONFIG_DONT_SET_DEFAULT,
	&stateOption},
    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_CANVAS_TAKE_FOCUS, offsetof(TkCanvas, takeFocus),
	DEF_CANVAS_TAKE_FOCUS, Tk_Offset(TkCanvas, takeFocus),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-width", "width", "Width",
	DEF_CANVAS_WIDTH, offsetof(TkCanvas, width), 0, NULL},
	DEF_CANVAS_WIDTH, Tk_Offset(TkCanvas, width), 0, NULL},
    {TK_CONFIG_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	DEF_CANVAS_X_SCROLL_CMD, offsetof(TkCanvas, xScrollCmd),
	DEF_CANVAS_X_SCROLL_CMD, Tk_Offset(TkCanvas, xScrollCmd),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-xscrollincrement", "xScrollIncrement",
	"ScrollIncrement",
	DEF_CANVAS_X_SCROLL_INCREMENT, offsetof(TkCanvas, xScrollIncrement),
	DEF_CANVAS_X_SCROLL_INCREMENT, Tk_Offset(TkCanvas, xScrollIncrement),
	0, NULL},
    {TK_CONFIG_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
	DEF_CANVAS_Y_SCROLL_CMD, offsetof(TkCanvas, yScrollCmd),
	DEF_CANVAS_Y_SCROLL_CMD, Tk_Offset(TkCanvas, yScrollCmd),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-yscrollincrement", "yScrollIncrement",
	"ScrollIncrement",
	DEF_CANVAS_Y_SCROLL_INCREMENT, offsetof(TkCanvas, yScrollIncrement),
	DEF_CANVAS_Y_SCROLL_INCREMENT, Tk_Offset(TkCanvas, yScrollIncrement),
	0, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * List of all the item types known at present. This is *global* and is
 * protected by typeListMutex.
 */

static Tk_ItemType *typeList = NULL;
				/* NULL means initialization hasn't been done
				 * yet. */
TCL_DECLARE_MUTEX(typeListMutex)

#ifndef USE_OLD_TAG_SEARCH
/*
 * Uids for operands in compiled advanced tag search expressions.
 * Initialization is done by GetStaticUids()
 */

typedef struct {
    Tk_Uid allUid;
    Tk_Uid currentUid;
    Tk_Uid andUid;
    Tk_Uid orUid;
    Tk_Uid xorUid;
    Tk_Uid parenUid;
    Tk_Uid negparenUid;
    Tk_Uid endparenUid;
    Tk_Uid tagvalUid;
    Tk_Uid negtagvalUid;
} SearchUids;

static Tcl_ThreadDataKey dataKey;
static SearchUids *	GetStaticUids(void);
#endif /* USE_OLD_TAG_SEARCH */

/*
 * Prototypes for functions defined later in this file:
 */

static void		CanvasBindProc(void *clientData,
static void		CanvasBindProc(ClientData clientData,
			    XEvent *eventPtr);
static void		CanvasBlinkProc(void *clientData);
static void		CanvasCmdDeletedProc(void *clientData);
static void		CanvasBlinkProc(ClientData clientData);
static void		CanvasCmdDeletedProc(ClientData clientData);
static void		CanvasDoEvent(TkCanvas *canvasPtr, XEvent *eventPtr);
static void		CanvasEventProc(void *clientData,
static void		CanvasEventProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_Size	CanvasFetchSelection(void *clientData, Tcl_Size offset,
			    char *buffer, Tcl_Size maxBytes);
static int		CanvasFetchSelection(ClientData clientData, int offset,
			    char *buffer, int maxBytes);
static Tk_Item *	CanvasFindClosest(TkCanvas *canvasPtr,
			    double coords[2]);
static void		CanvasFocusProc(TkCanvas *canvasPtr, int gotFocus);
static void		CanvasLostSelection(void *clientData);
static void		CanvasLostSelection(ClientData clientData);
static void		CanvasSelectTo(TkCanvas *canvasPtr,
			    Tk_Item *itemPtr, Tcl_Size index);
			    Tk_Item *itemPtr, int index);
static void		CanvasSetOrigin(TkCanvas *canvasPtr,
			    int xOrigin, int yOrigin);
static void		CanvasUpdateScrollbars(TkCanvas *canvasPtr);
static int		CanvasWidgetCmd(void *clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);
static void		CanvasWorldChanged(void *instanceData);
static int		CanvasWidgetCmd(ClientData clientData,
			    Tcl_Interp *interp, int argc,
			    Tcl_Obj *const *argv);
static void		CanvasWorldChanged(ClientData instanceData);
static int		ConfigureCanvas(Tcl_Interp *interp,
			    TkCanvas *canvasPtr, Tcl_Size objc,
			    Tcl_Obj *const *objv, int flags);
			    TkCanvas *canvasPtr, int argc,
			    Tcl_Obj *const *argv, int flags);
static void		DefaultRotateImplementation(TkCanvas *canvasPtr,
			    Tk_Item *itemPtr, double x, double y,
			    double angleRadians);
static Tcl_FreeProc	DestroyCanvas;
static void		DestroyCanvas(char *memPtr);
static int		DrawCanvas(Tcl_Interp *interp, void *clientData, Tk_PhotoHandle photohandle, int subsample, int zoom);
static void		DisplayCanvas(void *clientData);
static void		DisplayCanvas(ClientData clientData);
static void		DoItem(Tcl_Obj *accumObj,
			    Tk_Item *itemPtr, Tk_Uid tag);
static void		EventuallyRedrawItem(TkCanvas *canvasPtr,
			    Tk_Item *itemPtr);
#ifdef USE_OLD_TAG_SEARCH
static int		FindItems(Tcl_Interp *interp, TkCanvas *canvasPtr,
			    Tcl_Size objc, Tcl_Obj *const *objv,
			    Tcl_Obj *newTagObj, Tcl_Size first,
			    int argc, Tcl_Obj *const *argv,
			    Tcl_Obj *newTagObj, int first);
#else /* USE_OLD_TAG_SEARCH */
static int		FindItems(Tcl_Interp *interp, TkCanvas *canvasPtr,
			    int argc, Tcl_Obj *const *argv,
			    Tcl_Obj *newTagObj, int first,
			    TagSearch **searchPtrPtr);
#endif /* USE_OLD_TAG_SEARCH */
static int		FindArea(Tcl_Interp *interp, TkCanvas *canvasPtr,
			    Tcl_Obj *const *objv, Tk_Uid uid, int enclosed);
			    Tcl_Obj *const *argv, Tk_Uid uid, int enclosed);
static double		GridAlign(double coord, double spacing);
static const char**	TkGetStringsFromObjs(int argc, Tcl_Obj *const *objv);
static void		InitCanvas(void);
#ifdef USE_OLD_TAG_SEARCH
static Tk_Item *	NextItem(TagSearch *searchPtr);
#endif /* USE_OLD_TAG_SEARCH */
static void		PickCurrentItem(TkCanvas *canvasPtr, XEvent *eventPtr);
static Tcl_Obj *	ScrollFractions(int screen1,
			    int screen2, int object1, int object2);
#ifdef USE_OLD_TAG_SEARCH
static void		RelinkItems(TkCanvas *canvasPtr,
			    Tcl_Obj *tag, Tk_Item *prevPtr);
static Tk_Item *	StartTagSearch(TkCanvas *canvasPtr,
			    Tcl_Obj *tag, TagSearch *searchPtr);
#else /* USE_OLD_TAG_SEARCH */
static int		RelinkItems(TkCanvas *canvasPtr, Tcl_Obj *tag,
			    Tk_Item *prevPtr, TagSearch **searchPtrPtr);
static void 		TagSearchExprInit(TagSearchExpr **exprPtrPtr);
static void		TagSearchExprDestroy(TagSearchExpr *expr);
static void		TagSearchDestroy(TagSearch *searchPtr);
static int		TagSearchScan(TkCanvas *canvasPtr,
			    Tcl_Obj *tag, TagSearch **searchPtrPtr);
static int		TagSearchScanExpr(Tcl_Interp *interp,
			    TagSearch *searchPtr, TagSearchExpr *expr);
static int		TagSearchEvalExpr(TagSearchExpr *expr,
			    Tk_Item *itemPtr);
static Tk_Item *	TagSearchFirst(TagSearch *searchPtr);
static Tk_Item *	TagSearchNext(TagSearch *searchPtr);
#endif /* USE_OLD_TAG_SEARCH */

/*
 * The structure below defines canvas class behavior by means of functions
 * that can be invoked from generic window code.
 */

static const Tk_ClassProcs canvasClass = {
    sizeof(Tk_ClassProcs),	/* size */
    CanvasWorldChanged,		/* worldChangedProc */
    NULL,					/* createProc */
    NULL					/* modalProc */
};

/*
 * Macros that significantly simplify all code that finds items.
 */

#ifdef USE_OLD_TAG_SEARCH
#define FIRST_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
    itemPtr = StartTagSearch(canvasPtr,(objPtr),&search)
#define FOR_EVERY_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
    for (itemPtr = StartTagSearch(canvasPtr, (objPtr), &search); \
	    itemPtr != NULL; itemPtr = NextItem(&search))
#define FIND_ITEMS(objPtr, n) \
    FindItems(interp, canvasPtr, objc, objv, (objPtr), (n))
#define RELINK_ITEMS(objPtr, itemPtr) \
    RelinkItems(canvasPtr, (objPtr), (itemPtr))
#else /* USE_OLD_TAG_SEARCH */
#define FIRST_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
    if ((result=TagSearchScan(canvasPtr,(objPtr),(searchPtrPtr))) != TCL_OK){ \
	errorExitClause; \
    } \
    itemPtr = TagSearchFirst(*(searchPtrPtr));
#define FOR_EVERY_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
    if ((result=TagSearchScan(canvasPtr,(objPtr),(searchPtrPtr))) != TCL_OK){ \
	errorExitClause; \
    } \
    for (itemPtr = TagSearchFirst(*(searchPtrPtr)); \
	    itemPtr != NULL; itemPtr = TagSearchNext(*(searchPtrPtr)))
#define FIND_ITEMS(objPtr, n) \
    FindItems(interp, canvasPtr, objc, objv, (objPtr), (n), &searchPtr)
#define RELINK_ITEMS(objPtr, itemPtr) \
    result = RelinkItems(canvasPtr, (objPtr), (itemPtr), &searchPtr)
#endif /* USE_OLD_TAG_SEARCH */

/*
 * ----------------------------------------------------------------------
 *
 * AlwaysRedraw, ItemConfigure, ItemCoords, etc. --
 *
 *	Helper functions that make access to canvas item functions simpler.
 *	Note that these are all inline functions.
 *
 * ----------------------------------------------------------------------
 */

static inline int
AlwaysRedraw(
    Tk_Item *itemPtr)
{
    return itemPtr->typePtr->flags & TK_ALWAYS_REDRAW;
    return itemPtr->typePtr->alwaysRedraw & 1;
}

static inline int
ItemConfigure(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_Interp *interp = canvasPtr->interp;
    int result;

    if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
    return itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr,
	    itemPtr, objc, objv, TK_CONFIG_ARGV_ONLY);
	result = itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc, objv, TK_CONFIG_ARGV_ONLY);
    } else {
	const char **args = TkGetStringsFromObjs(objc, objv);

	result = itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc, (Tcl_Obj **) args, TK_CONFIG_ARGV_ONLY);
	if (args != NULL) {
	    ckfree(args);
	}
    }
    return result;
}

static inline int
ItemConfigInfo(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    Tcl_Obj *fieldName)
{
    return Tk_ConfigureInfo(canvasPtr->interp, canvasPtr->tkwin,
	    itemPtr->typePtr->configSpecs, itemPtr,
	    itemPtr->typePtr->configSpecs, (char *) itemPtr,
	    (fieldName ? Tcl_GetString(fieldName) : NULL), 0);
}

static inline int
ItemConfigValue(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    Tcl_Obj *fieldName)
{
    return Tk_ConfigureValue(canvasPtr->interp, canvasPtr->tkwin,
	    itemPtr->typePtr->configSpecs, itemPtr,
	    itemPtr->typePtr->configSpecs, (char *) itemPtr,
	    Tcl_GetString(fieldName), 0);
}

static inline int
ItemCoords(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_Interp *interp = canvasPtr->interp;
    int result;

    if (itemPtr->typePtr->coordProc == NULL) {
	result = TCL_OK;
    } else if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
	result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc, objv);
    } else {
	const char **args = TkGetStringsFromObjs(objc, objv);

	result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc, objv);
		itemPtr, objc, (Tcl_Obj **) args);
	if (args != NULL) {
	    ckfree(args);
	}
    }
    return result;
}

static inline int
ItemCreate(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,		/* Warning: incomplete! typePtr field must be
				 * set by this point. */
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_Interp *interp = canvasPtr->interp;
    int result;

    if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
	return itemPtr->typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
	result = itemPtr->typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc-3, objv+3);
    } else {
	const char **args = TkGetStringsFromObjs(objc-3, objv+3);

	result = itemPtr->typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objc-3, (Tcl_Obj **) args);
	if (args != NULL) {
	    ckfree(args);
	}
    }
    return result;
}

static inline void
ItemCursor(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    int index)
432
433
434
435
436
437
438
439

440
441
442
443
444

445
446
447
448
449
450
451
452







453
454
455
456
457
458
459
460
461

462
463






464
465
466
467
468
469
470
513
514
515
516
517
518
519

520
521
522
523
524

525
526
527
528
529
530



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547


548
549
550
551
552
553
554
555
556
557
558
559
560







-
+




-
+





-
-
-
+
+
+
+
+
+
+









+
-
-
+
+
+
+
+
+







    int screenX1, int screenY1,
    int width, int height)
{
    itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr,
	    canvasPtr->display, pixmap, screenX1, screenY1, width, height);
}

static int
static inline int
ItemIndex(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    Tcl_Obj *objPtr,
    Tcl_Size *indexPtr)
    int *indexPtr)
{
    Tcl_Interp *interp = canvasPtr->interp;

    if (itemPtr->typePtr->indexProc == NULL) {
	return TCL_OK;
    }
    return itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr,
	    itemPtr, objPtr, indexPtr);
    } else if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
	return itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, objPtr, indexPtr);
    } else {
	return itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr,
		itemPtr, (Tcl_Obj *) Tcl_GetString(objPtr), indexPtr);
    }
}

static inline void
ItemInsert(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    int beforeThis,
    Tcl_Obj *toInsert)
{
    if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
    itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
	    beforeThis, toInsert);
	itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
		beforeThis, toInsert);
    } else {
	itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
		beforeThis, (Tcl_Obj *) Tcl_GetString(toInsert));
    }
}

static inline int
ItemOverlap(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    double rect[])
493
494
495
496
497
498
499
500

501
502
503
504
505
506

507
508
509

510
511
512
513

514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

644
645
646


647
648

649
650
651
652
653
654
655
656
657


658
659
660
661

662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697


698
699
700
701
702
703
704
705
706
707
708

709
710
711
712
713
714
715
583
584
585
586
587
588
589

590
591
592
593
594
595

596
597
598

599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614
615

































































































616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635

636
637


638
639
640

641
642
643
644
645
646
647
648


649
650
651
652
653

654
655
656
657
658
659
660
661
662
663
664

665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

681
682
683
684
685
686
687
688


689
690
691
692
693
694
695
696
697
698
699
700

701
702
703
704
705
706
707
708







-
+





-
+


-
+



-
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+

-
-
+
+

-
+







-
-
+
+



-
+










-
+















-
+







-
-
+
+










-
+







    double xOrigin, double yOrigin,
    double xScale, double yScale)
{
    itemPtr->typePtr->scaleProc((Tk_Canvas) canvasPtr, itemPtr,
	    xOrigin, yOrigin, xScale, yScale);
}

static inline Tcl_Size
static inline int
ItemSelection(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    int offset,
    char *buffer,
    Tcl_Size maxBytes)
    int maxBytes)
{
    if (itemPtr == NULL || itemPtr->typePtr->selectionProc == NULL) {
	return TCL_INDEX_NONE;
	return -1;
    }

    return itemPtr->typePtr->selectionProc((Tk_Canvas) canvasPtr, itemPtr,
	    offset, buffer, (int)maxBytes);
	    offset, buffer, maxBytes);
}

static inline void
ItemTranslate(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    double xDelta,
    double yDelta)
{
    itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr, itemPtr,
	    xDelta, yDelta);
}

static inline void
ItemRotate(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    double x,
    double y,
    double angleRadians)
{
    if (itemPtr->typePtr->rotateProc != NULL) {
	itemPtr->typePtr->rotateProc((Tk_Canvas) canvasPtr,
		itemPtr, x, y, angleRadians);
    } else {
	DefaultRotateImplementation(canvasPtr, itemPtr, x, y, angleRadians);
    }
}

/*
 *--------------------------------------------------------------
 *
 * DefaultRotateImplementation --
 *
 *	The default implementation of the rotation operation, used when items
 *	do not provide their own version.
 *
 *--------------------------------------------------------------
 */

static void
DefaultRotateImplementation(
    TkCanvas *canvasPtr,
    Tk_Item *itemPtr,
    double x,
    double y,
    double angleRadians)
{
    Tcl_Size i, objc;
    int ok = 1;
    Tcl_Obj **objv, **newObjv;
    double *coordv;
    double s = sin(angleRadians);
    double c = cos(angleRadians);
    Tcl_Interp *interp = canvasPtr->interp;

    /*
     * Get the coordinates out of the item.
     */

    if (ItemCoords(canvasPtr, itemPtr, 0, NULL) == TCL_OK &&
	    Tcl_ListObjGetElements(NULL, Tcl_GetObjResult(interp),
		    &objc, &objv) == TCL_OK) {
	coordv = (double *) ckalloc(sizeof(double) * objc);
	for (i=0 ; i<objc ; i++) {
	    if (Tcl_GetDoubleFromObj(NULL, objv[i], &coordv[i]) != TCL_OK) {
		ok = 0;
		break;
	    }
	}
	if (ok) {
	    /*
	     * Apply the rotation.
	     */

	    for (i=0 ; i<objc ; i+=2) {
		double px = coordv[i+0] - x;
		double py = coordv[i+1] - y;
		double nx = px * c - py * s;
		double ny = px * s + py * c;

		coordv[i+0] = nx + x;
		coordv[i+1] = ny + y;
	    }

	    /*
	     * Write the coordinates back into the item.
	     */

	    newObjv = (Tcl_Obj **) ckalloc(sizeof(Tcl_Obj *) * objc);
	    for (i=0 ; i<objc ; i++) {
		newObjv[i] = Tcl_NewDoubleObj(coordv[i]);
		Tcl_IncrRefCount(newObjv[i]);
	    }
	    ItemCoords(canvasPtr, itemPtr, objc, newObjv);
	    for (i=0 ; i<objc ; i++) {
		Tcl_DecrRefCount(newObjv[i]);
	    }
	    ckfree(newObjv);
	}
	ckfree(coordv);
    }

    /*
     * The interpreter result was (probably) modified above; reset it.
     */

    Tcl_ResetResult(interp);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_CanvasObjCmd --
 *
 *	This function is invoked to process the "canvas" Tcl command. See the
 *	user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_CanvasObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
    int argc,			/* Number of arguments. */
    Tcl_Obj *const argv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkCanvas *canvasPtr;
    Tk_Window newWin;

    if (typeList == NULL) {
	InitCanvas();
    }

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
    if (argc < 2) {
	Tcl_WrongNumArgs(interp, 1, argv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

    newWin = Tk_CreateWindowFromPath(interp,tkwin,Tcl_GetString(objv[1]),NULL);
    newWin = Tk_CreateWindowFromPath(interp,tkwin,Tcl_GetString(argv[1]),NULL);
    if (newWin == NULL) {
	return TCL_ERROR;
    }

    /*
     * Initialize fields that won't be initialized by ConfigureCanvas, or
     * which ConfigureCanvas expects to have reasonable values (e.g. resource
     * pointers).
     */

    canvasPtr = (TkCanvas *)ckalloc(sizeof(TkCanvas));
    canvasPtr = ckalloc(sizeof(TkCanvas));
    canvasPtr->tkwin = newWin;
    canvasPtr->display = Tk_Display(newWin);
    canvasPtr->interp = interp;
    canvasPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(canvasPtr->tkwin), CanvasWidgetCmd, canvasPtr,
	    CanvasCmdDeletedProc);
    canvasPtr->firstItemPtr = NULL;
    canvasPtr->lastItemPtr = NULL;
    canvasPtr->borderWidth = 0;
    canvasPtr->bgBorder = NULL;
    canvasPtr->relief = TK_RELIEF_FLAT;
    canvasPtr->highlightWidth = 0;
    canvasPtr->highlightBgColorPtr = NULL;
    canvasPtr->highlightColorPtr = NULL;
    canvasPtr->inset = 0;
    canvasPtr->pixmapGC = NULL;
    canvasPtr->pixmapGC = None;
    canvasPtr->width = None;
    canvasPtr->height = None;
    canvasPtr->confine = 0;
    canvasPtr->textInfo.selBorder = NULL;
    canvasPtr->textInfo.selBorderWidth = 0;
    canvasPtr->textInfo.selFgColorPtr = NULL;
    canvasPtr->textInfo.selItemPtr = NULL;
    canvasPtr->textInfo.selectFirst = TCL_INDEX_NONE;
    canvasPtr->textInfo.selectLast = TCL_INDEX_NONE;
    canvasPtr->textInfo.selectFirst = -1;
    canvasPtr->textInfo.selectLast = -1;
    canvasPtr->textInfo.anchorItemPtr = NULL;
    canvasPtr->textInfo.selectAnchor = 0;
    canvasPtr->textInfo.insertBorder = NULL;
    canvasPtr->textInfo.insertWidth = 0;
    canvasPtr->textInfo.insertBorderWidth = 0;
    canvasPtr->textInfo.focusItemPtr = NULL;
    canvasPtr->textInfo.gotFocus = 0;
    canvasPtr->textInfo.cursorOn = 0;
    canvasPtr->insertOnTime = 0;
    canvasPtr->insertOffTime = 0;
    canvasPtr->insertBlinkHandler = NULL;
    canvasPtr->insertBlinkHandler = (Tcl_TimerToken) NULL;
    canvasPtr->xOrigin = canvasPtr->yOrigin = 0;
    canvasPtr->drawableXOrigin = canvasPtr->drawableYOrigin = 0;
    canvasPtr->bindingTable = NULL;
    canvasPtr->currentItemPtr = NULL;
    canvasPtr->newCurrentPtr = NULL;
    canvasPtr->closeEnough = 0.0;
    canvasPtr->pickEvent.type = LeaveNotify;
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744

745

746
747
748
749
750
751
752
753
754
755
756
757
758
759

760
761
762
763

764
765
766
767
768
769
770
720
721
722
723
724
725
726

727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753

754
755
756
757

758
759
760
761
762
763
764
765







-
+










+

+













-
+



-
+







    canvasPtr->yScrollIncrement = 0;
    canvasPtr->scanX = 0;
    canvasPtr->scanXOrigin = 0;
    canvasPtr->scanY = 0;
    canvasPtr->scanYOrigin = 0;
    canvasPtr->hotPtr = NULL;
    canvasPtr->hotPrevPtr = NULL;
    canvasPtr->cursor = NULL;
    canvasPtr->cursor = None;
    canvasPtr->takeFocus = NULL;
    canvasPtr->pixelsPerMM = WidthOfScreen(Tk_Screen(newWin));
    canvasPtr->pixelsPerMM /= WidthMMOfScreen(Tk_Screen(newWin));
    canvasPtr->flags = 0;
    canvasPtr->nextId = 1;
    canvasPtr->psInfo = NULL;
    canvasPtr->canvas_state = TK_STATE_NORMAL;
    canvasPtr->tsoffset.flags = 0;
    canvasPtr->tsoffset.xoffset = 0;
    canvasPtr->tsoffset.yoffset = 0;
#ifndef USE_OLD_TAG_SEARCH
    canvasPtr->bindTagExprs = NULL;
#endif
    Tcl_InitHashTable(&canvasPtr->idTable, TCL_ONE_WORD_KEYS);

    Tk_SetClass(canvasPtr->tkwin, "Canvas");
    Tk_SetClassProcs(canvasPtr->tkwin, &canvasClass, canvasPtr);
    Tk_CreateEventHandler(canvasPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    CanvasEventProc, canvasPtr);
    Tk_CreateEventHandler(canvasPtr->tkwin, KeyPressMask|KeyReleaseMask
	    |ButtonPressMask|ButtonReleaseMask|EnterWindowMask
	    |LeaveWindowMask|PointerMotionMask|VirtualEventMask,
	    CanvasBindProc, canvasPtr);
    Tk_CreateSelHandler(canvasPtr->tkwin, XA_PRIMARY, XA_STRING,
	    CanvasFetchSelection, canvasPtr, XA_STRING);
    if (ConfigureCanvas(interp, canvasPtr, objc-2, objv+2, 0) != TCL_OK) {
    if (ConfigureCanvas(interp, canvasPtr, argc-2, argv+2, 0) != TCL_OK) {
	goto error;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(canvasPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(canvasPtr->tkwin));
    return TCL_OK;

  error:
    Tk_DestroyWindow(canvasPtr->tkwin);
    return TCL_ERROR;
}

784
785
786
787
788
789
790
791

792
793
794
795
796

797
798
799



800
801

802
803
804


805
806
807
808
809
810


811
812
813
814



815
816

817
818
819
820
821
822


823
824
825


826
827
828
829
830
831
832
833
834


835
836
837
838
839
840

841
842
843
844
845
846
847
848
849
850
851

852
853
854
855
856
857
858
859
779
780
781
782
783
784
785

786
787
788
789
790

791
792
793
794
795
796
797
798
799
800
801


802
803
804
805
806
807


808
809
810



811
812
813
814

815
816
817
818
819


820
821
822


823
824

825
826
827
828
829
830


831
832
833
834
835
836
837

838
839
840
841
842
843
844
845
846
847
848

849

850
851
852
853
854
855
856







-
+




-
+



+
+
+


+

-
-
+
+




-
-
+
+

-
-
-
+
+
+

-
+




-
-
+
+

-
-
+
+
-






-
-
+
+





-
+










-
+
-







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
CanvasWidgetCmd(
    void *clientData,	/* Information about canvas widget. */
    ClientData clientData,	/* Information about canvas widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;
    int c, result;
    Tk_Item *itemPtr = NULL;	/* Initialization needed only to prevent
				 * compiler warning. */
#ifdef USE_OLD_TAG_SEARCH
    TagSearch search;
#else /* USE_OLD_TAG_SEARCH */
    TagSearch *searchPtr = NULL;/* Allocated by first TagSearchScan, freed by
				 * TagSearchDestroy */
#endif /* USE_OLD_TAG_SEARCH */

    int idx;
    static const char *const canvasOptionStrings[] = {
    int index;
    static const char *const optionStrings[] = {
	"addtag",	"bbox",		"bind",		"canvasx",
	"canvasy",	"cget",		"configure",	"coords",
	"create",	"dchars",	"delete",	"dtag",
	"find",		"focus",	"gettags",	"icursor",
        "image",	"imove",	"index",	"insert",
	"itemcget",	"itemconfigure",
	"imove",	"index",	"insert",	"itemcget",
	"itemconfigure",
	"lower",	"move",		"moveto",	"postscript",
	"raise",	"rchars",	"rotate",	"scale",
	"scan",		"select",	"type",		"xview",
	"yview",	NULL
	"raise",	"rchars",	"scale",	"scan",
	"select",	"type",		"xview",	"yview",
	NULL
    };
    enum canvasOptionStringsEnum {
    enum options {
	CANV_ADDTAG,	CANV_BBOX,	CANV_BIND,	CANV_CANVASX,
	CANV_CANVASY,	CANV_CGET,	CANV_CONFIGURE,	CANV_COORDS,
	CANV_CREATE,	CANV_DCHARS,	CANV_DELETE,	CANV_DTAG,
	CANV_FIND,	CANV_FOCUS,	CANV_GETTAGS,	CANV_ICURSOR,
        CANV_IMAGE,	CANV_IMOVE,	CANV_INDEX,	CANV_INSERT,
	CANV_ITEMCGET,	CANV_ITEMCONFIGURE,
	CANV_IMOVE,	CANV_INDEX,	CANV_INSERT,	CANV_ITEMCGET,
	CANV_ITEMCONFIGURE,
	CANV_LOWER,	CANV_MOVE,	CANV_MOVETO,	CANV_POSTSCRIPT,
	CANV_RAISE,	CANV_RCHARS,	CANV_ROTATE,	CANV_SCALE,
	CANV_SCAN,	CANV_SELECT,	CANV_TYPE,	CANV_XVIEW,
	CANV_RAISE,	CANV_RCHARS,	CANV_SCALE,	CANV_SCAN,
	CANV_SELECT,	CANV_TYPE,	CANV_XVIEW,	CANV_YVIEW
	CANV_YVIEW
    };

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObj(interp, objv[1], canvasOptionStrings, "option", 0,
	    &idx) != TCL_OK) {
    if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0,
	    &index) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_Preserve(canvasPtr);

    result = TCL_OK;
    switch ((enum canvasOptionStringsEnum)idx) {
    switch ((enum options) index) {
    case CANV_ADDTAG:
	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tag searchCommand ?arg ...?");
	    result = TCL_ERROR;
	    goto done;
	}
	result = FIND_ITEMS(objv[2], 3);
	break;

    case CANV_BBOX: {
	int gotAny;
	int i, gotAny;
	Tcl_Size i;
	int x1 = 0, y1 = 0, x2 = 0, y2 = 0;	/* Initializations needed only
						 * to prevent overcautious
						 * compiler warnings. */

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?tagOrId ...?");
	    result = TCL_ERROR;
887
888
889
890
891
892
893
894
895
896
897




898
899
900
901
902
903

904
905
906
907
908
909
910
911
912
913
914
915
916





























917
918
919
920
921
922
923
924
925

926
927

928
929
930
931
932
933
934
935

936
937
938
939
940

941

942
943
944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960

961
962
963
964
965
966
967
884
885
886
887
888
889
890




891
892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950

951
952

953
954
955
956
957
958
959
960

961
962
963
964
965

966
967
968
969
970
971
972
973
974
975
976
977
978
979

980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995







-
-
-
-
+
+
+
+





-
+













+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+

-
+







-
+




-
+

+











-
+







+







		    }
		}
	    }
	}
	if (gotAny) {
	    Tcl_Obj *resultObjs[4];

	    resultObjs[0] = Tcl_NewWideIntObj(x1);
	    resultObjs[1] = Tcl_NewWideIntObj(y1);
	    resultObjs[2] = Tcl_NewWideIntObj(x2);
	    resultObjs[3] = Tcl_NewWideIntObj(y2);
	    resultObjs[0] = Tcl_NewIntObj(x1);
	    resultObjs[1] = Tcl_NewIntObj(y1);
	    resultObjs[2] = Tcl_NewIntObj(x2);
	    resultObjs[3] = Tcl_NewIntObj(y2);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, resultObjs));
	}
	break;
    }
    case CANV_BIND: {
	void *object;
	ClientData object;

	if ((objc < 3) || (objc > 5)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?sequence? ?command?");
	    result = TCL_ERROR;
	    goto done;
	}

	/*
	 * Figure out what object to use for the binding (individual item vs.
	 * tag).
	 */

	object = NULL;
#ifdef USE_OLD_TAG_SEARCH
	if (isdigit(UCHAR(Tcl_GetString(objv[2])[0]))) {
	    int id;
	    char *end;
	    Tcl_HashEntry *entryPtr;

	    id = strtoul(Tcl_GetString(objv[2]), &end, 0);
	    if (*end != 0) {
		goto bindByTag;
	    }
	    entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char *) id);
	    if (entryPtr != NULL) {
		itemPtr = Tcl_GetHashValue(entryPtr);
		object = itemPtr;
	    }

	    if (object == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"item \"%s\" doesn't exist", Tcl_GetString(objv[2])));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "CANVAS_ITEM",
			Tcl_GetString(objv[2]), NULL);
		result = TCL_ERROR;
		goto done;
	    }
	} else {
	bindByTag:
	    object = Tk_GetUid(Tcl_GetString(objv[2]));
	}
#else /* USE_OLD_TAG_SEARCH */
	result = TagSearchScan(canvasPtr, objv[2], &searchPtr);
	if (result != TCL_OK) {
	    goto done;
	}
	if (searchPtr->type == SEARCH_TYPE_ID) {
	    Tcl_HashEntry *entryPtr;

	    entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable,
		    INT2PTR(searchPtr->id));
		    (char *) INT2PTR(searchPtr->id));
	    if (entryPtr != NULL) {
		itemPtr = (Tk_Item *)Tcl_GetHashValue(entryPtr);
		itemPtr = Tcl_GetHashValue(entryPtr);
		object = itemPtr;
	    }

	    if (object == 0) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"item \"%s\" doesn't exist", Tcl_GetString(objv[2])));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "CANVAS_ITEM",
			Tcl_GetString(objv[2]), (char *)NULL);
			Tcl_GetString(objv[2]), NULL);
		result = TCL_ERROR;
		goto done;
	    }
	} else {
	    object = (char *)searchPtr->expr->uid;
    	    object = (ClientData) searchPtr->expr->uid;
	}
#endif /* USE_OLD_TAG_SEARCH */

	/*
	 * Make a binding table if the canvas doesn't already have one.
	 */

	if (canvasPtr->bindingTable == NULL) {
	    canvasPtr->bindingTable = Tk_CreateBindingTable(interp);
	}

	if (objc == 5) {
	    int append = 0;
	    unsigned int mask;
	    unsigned long mask;
	    const char *argv4 = Tcl_GetString(objv[4]);

	    if (argv4[0] == 0) {
		result = Tk_DeleteBinding(interp, canvasPtr->bindingTable,
			object, Tcl_GetString(objv[3]));
		goto done;
	    }
#ifndef USE_OLD_TAG_SEARCH
	    if (searchPtr->type == SEARCH_TYPE_EXPR) {
		/*
		 * If new tag expression, then insert in linked list.
		 */

	    	TagSearchExpr *expr, **lastPtr;

984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011


1012
1013
1014
1015
1016
1017
1018
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037
1038


1039
1040
1041
1042
1043
1044
1045
1046
1047







+










-
+








-
-
+
+







		     * Flag in TagSearch that expr has changed ownership so
		     * that TagSearchDestroy doesn't try to free it.
		     */

		    searchPtr->expr = NULL;
		}
	    }
#endif /* not USE_OLD_TAG_SEARCH */
	    if (argv4[0] == '+') {
		argv4++;
		append = 1;
	    }
	    mask = Tk_CreateBinding(interp, canvasPtr->bindingTable,
		    object, Tcl_GetString(objv[3]), argv4, append);
	    if (mask == 0) {
		result = TCL_ERROR;
		goto done;
	    }
	    if (mask & ~(ButtonMotionMask|Button1MotionMask
	    if (mask & (unsigned) ~(ButtonMotionMask|Button1MotionMask
		    |Button2MotionMask|Button3MotionMask|Button4MotionMask
		    |Button5MotionMask|ButtonPressMask|ButtonReleaseMask
		    |EnterWindowMask|LeaveWindowMask|KeyPressMask
		    |KeyReleaseMask|PointerMotionMask|VirtualEventMask)) {
		Tk_DeleteBinding(interp, canvasPtr->bindingTable,
			object, Tcl_GetString(objv[3]));
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"requested illegal events; only key, button, motion,"
			" enter, leave, and virtual events may be used", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "BAD_EVENTS", (char *)NULL);
			" enter, leave, and virtual events may be used", -1));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "BAD_EVENTS", NULL);
		result = TCL_ERROR;
		goto done;
	    }
	} else if (objc == 4) {
	    const char *command;

	    command = Tk_GetBinding(interp, canvasPtr->bindingTable,
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071







-
+








		if (string[0] != '\0') {
		    result = TCL_ERROR;
		    goto done;
		}
		Tcl_ResetResult(interp);
	    } else {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(command, TCL_INDEX_NONE));
		Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
	    }
	} else {
	    Tk_GetAllBindings(interp, canvasPtr->bindingTable, object);
	}
	break;
    }
    case CANV_CANVASX: {
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108

1109
1110
1111

1112
1113
1114
1115
1116
1117
1118
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134
1135
1136

1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147







-
+




-
+


-
+







    case CANV_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    goto done;
	}
	result = Tk_ConfigureValue(interp, canvasPtr->tkwin, configSpecs,
		canvasPtr, Tcl_GetString(objv[2]), 0);
		(char *) canvasPtr, Tcl_GetString(objv[2]), 0);
	break;
    case CANV_CONFIGURE:
	if (objc == 2) {
	    result = Tk_ConfigureInfo(interp, canvasPtr->tkwin, configSpecs,
		    canvasPtr, NULL, 0);
		    (char *) canvasPtr, NULL, 0);
	} else if (objc == 3) {
	    result = Tk_ConfigureInfo(interp, canvasPtr->tkwin, configSpecs,
		    canvasPtr, Tcl_GetString(objv[2]), 0);
		    (char *) canvasPtr, Tcl_GetString(objv[2]), 0);
	} else {
	    result = ConfigureCanvas(interp, canvasPtr, objc-2, objv+2,
		    TK_CONFIG_ARGV_ONLY);
	}
	break;
    case CANV_COORDS:
	if (objc < 3) {
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161



1162
1163
1164
1165
1166
1167
1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215

1216
1217
1218
1219
1220
1221
1222


1223
1224
1225
1226
1227
1228
1229
1181
1182
1183
1184
1185
1186
1187



1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259
1260







-
-
-
+
+
+








-
+




















-
+



-
+
















+



-
+






-
+
+







	 * Make a temporary object here that we can reuse for all the
	 * modifications in the loop.
	 */

	tmpObj = Tcl_NewListObj(2, objv+4);

	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto doneImove) {
	    Tcl_Size index;
	    int x1, x2, y1, y2;
	    int dontRedraw1, dontRedraw2;
	    int index;
	    int x1,x2,y1,y2;
	    int dontRedraw1,dontRedraw2;

	    /*
	     * The TK_MOVABLE_POINTS flag should only be set for types that
	     * support the same semantics of index, dChars and insert methods
	     * as lines and canvases.
	     */

	    if (itemPtr == NULL ||
		    !(itemPtr->typePtr->flags & TK_MOVABLE_POINTS)) {
		    !(itemPtr->typePtr->alwaysRedraw & TK_MOVABLE_POINTS)) {
		continue;
	    }

	    result = ItemIndex(canvasPtr, itemPtr, objv[3], &index);
	    if (result != TCL_OK) {
		break;
	    }

	    /*
	     * Redraw both item's old and new areas: it's possible that a
	     * replace could result in a new area larger than the old area.
	     * Except if the dCharsProc or insertProc sets the
	     * TK_ITEM_DONT_REDRAW flag, nothing more needs to be done.
	     */

	    x1 = itemPtr->x1; y1 = itemPtr->y1;
	    x2 = itemPtr->x2; y2 = itemPtr->y2;

	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    ItemDelChars(canvasPtr, itemPtr, index, index);
	    dontRedraw1 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;
	    dontRedraw1=itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;

	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    ItemInsert(canvasPtr, itemPtr, index, tmpObj);
	    dontRedraw2 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;
	    dontRedraw2=itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;

	    if (!(dontRedraw1 && dontRedraw2)) {
		Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
			x1, y1, x2, y2);
		EventuallyRedrawItem(canvasPtr, itemPtr);
	    }
	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	}

    doneImove:
	Tcl_DecrRefCount(tmpObj);
	break;
    }
    case CANV_CREATE: {
	Tk_ItemType *typePtr;
	Tk_ItemType *matchPtr = NULL;
	Tk_Item *itemPtr;
	int isNew = 0;
	Tcl_HashEntry *entryPtr;
	const char *arg;
	Tcl_Size length;
	size_t length;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "type coords ?arg ...?");
	    result = TCL_ERROR;
	    goto done;
	}
	arg = Tcl_GetStringFromObj(objv[2], &length);
	arg = Tcl_GetString(objv[2]);
	length = objv[2]->length;
	c = arg[0];

	/*
	 * Lock because the list of types is a global resource that could be
	 * updated by another thread. That's fairly unlikely, but not
	 * impossible.
	 */
1247
1248
1249
1250
1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270



1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305


1306
1307
1308
1309
1310
1311
1312
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299


1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331

1332
1333
1334
1335


1336
1337
1338
1339
1340
1341
1342
1343
1344







-
+














-
-
+
+
+















-
+













-
+



-
-
+
+








	Tcl_MutexUnlock(&typeListMutex);
	if (matchPtr == NULL) {
	badType:
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "unknown or ambiguous item type \"%s\"", arg));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "CANVAS_ITEM_TYPE", arg,
		    (char *)NULL);
		    NULL);
	    result = TCL_ERROR;
	    goto done;
	}
	if (objc < 4) {
	    /*
	     * Allow more specific error return.
	     */

	    Tcl_WrongNumArgs(interp, 3, objv, "coords ?arg ...?");
	    result = TCL_ERROR;
	    goto done;
	}

	typePtr = matchPtr;
	itemPtr = (Tk_Item *)ckalloc(typePtr->itemSize);
	itemPtr->id = canvasPtr->nextId++;
	itemPtr = ckalloc(typePtr->itemSize);
	itemPtr->id = canvasPtr->nextId;
	canvasPtr->nextId++;
	itemPtr->tagPtr = itemPtr->staticTagSpace;
	itemPtr->tagSpace = TK_TAG_SPACE;
	itemPtr->numTags = 0;
	itemPtr->typePtr = typePtr;
	itemPtr->state = TK_STATE_NULL;
	itemPtr->redraw_flags = 0;

	if (ItemCreate(canvasPtr, itemPtr, objc, objv) != TCL_OK) {
	    ckfree(itemPtr);
	    result = TCL_ERROR;
	    goto done;
	}

	itemPtr->nextPtr = NULL;
	entryPtr = Tcl_CreateHashEntry(&canvasPtr->idTable,
		INT2PTR(itemPtr->id), &isNew);
		(char *) INT2PTR(itemPtr->id), &isNew);
	Tcl_SetHashValue(entryPtr, itemPtr);
	itemPtr->prevPtr = canvasPtr->lastItemPtr;
	canvasPtr->hotPtr = itemPtr;
	canvasPtr->hotPrevPtr = canvasPtr->lastItemPtr;
	if (canvasPtr->lastItemPtr == NULL) {
	    canvasPtr->firstItemPtr = itemPtr;
	} else {
	    canvasPtr->lastItemPtr->nextPtr = itemPtr;
	}
	canvasPtr->lastItemPtr = itemPtr;
	itemPtr->redraw_flags |= FORCE_REDRAW;
	EventuallyRedrawItem(canvasPtr, itemPtr);
	canvasPtr->flags |= REPICK_NEEDED;
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(itemPtr->id));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(itemPtr->id));
	break;
    }
    case CANV_DCHARS: {
	Tcl_Size first, last;
	int x1, x2, y1, y2;
	int first, last;
	int x1,x2,y1,y2;

	if ((objc != 4) && (objc != 5)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId first ?last?");
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351

1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365

1366
1367
1368
1369
1370
1371
1372
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382

1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404







-
+

















-
+













-
+







	    } else {
		last = first;
	    }

	    /*
	     * Redraw both item's old and new areas: it's possible that a
	     * delete could result in a new area larger than the old area.
	     * Except if the dCharsProc sets the TK_ITEM_DONT_REDRAW flag,
	     * Except if the insertProc sets the TK_ITEM_DONT_REDRAW flag,
	     * nothing more needs to be done.
	     */

	    x1 = itemPtr->x1; y1 = itemPtr->y1;
	    x2 = itemPtr->x2; y2 = itemPtr->y2;
	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    ItemDelChars(canvasPtr, itemPtr, first, last);
	    if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
		Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
			x1, y1, x2, y2);
		EventuallyRedrawItem(canvasPtr, itemPtr);
	    }
	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	}
	break;
    }
    case CANV_DELETE: {
	Tcl_Size i;
	int i;
	Tcl_HashEntry *entryPtr;

	for (i = 2; i < objc; i++) {
	    FOR_EVERY_CANVAS_ITEM_MATCHING(objv[i], &searchPtr, goto done) {
		EventuallyRedrawItem(canvasPtr, itemPtr);
		if (canvasPtr->bindingTable != NULL) {
		    Tk_DeleteAllBindings(canvasPtr->bindingTable, itemPtr);
		}
		ItemDelete(canvasPtr, itemPtr);
		if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
		    ckfree(itemPtr->tagPtr);
		}
		entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable,
			INT2PTR(itemPtr->id));
			(char *) INT2PTR(itemPtr->id));
		Tcl_DeleteHashEntry(entryPtr);
		if (itemPtr->nextPtr != NULL) {
		    itemPtr->nextPtr->prevPtr = itemPtr->prevPtr;
		}
		if (itemPtr->prevPtr != NULL) {
		    itemPtr->prevPtr->nextPtr = itemPtr->nextPtr;
		}
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453







1454

1455

1456






1457
1458
1459
1460
1461
1462
1463







-
+












-
+

-
-
-
-
-
-
-
+
-

-
+
-
-
-
-
-
-







		}
	    }
	}
	break;
    }
    case CANV_DTAG: {
	Tk_Uid tag;
	Tcl_Size i;
	int i;

	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?tagToDelete?");
	    result = TCL_ERROR;
	    goto done;
	}
	if (objc == 4) {
	    tag = Tk_GetUid(Tcl_GetString(objv[3]));
	} else {
	    tag = Tk_GetUid(Tcl_GetString(objv[2]));
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
	    for (i = itemPtr->numTags-1; i != TCL_INDEX_NONE; i--) {
	    for (i = itemPtr->numTags-1; i >= 0; i--) {
		if (itemPtr->tagPtr[i] == tag) {

                    /*
                     * Don't shuffle the tags sequence: memmove the tags.
                     */

                    memmove((void *)(itemPtr->tagPtr + i),
                            itemPtr->tagPtr + i + 1,
		    itemPtr->tagPtr[i] = itemPtr->tagPtr[itemPtr->numTags-1];
                            (itemPtr->numTags - (i+1)) * sizeof(Tk_Uid));
		    itemPtr->numTags--;

		}
                    /*
                     * There must be no break here: all tags with the same name must
                     * be deleted.
                     */

 		}
	    }
	}
	break;
    }
    case CANV_FIND:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "searchCommand ?arg ...?");
1452
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485







-
+







	    Tcl_WrongNumArgs(interp, 2, objv, "?tagOrId?");
	    result = TCL_ERROR;
	    goto done;
	}
	itemPtr = canvasPtr->textInfo.focusItemPtr;
	if (objc == 2) {
	    if (itemPtr != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj(itemPtr->id));
		Tcl_SetObjResult(interp, Tcl_NewIntObj(itemPtr->id));
	    }
	    goto done;
	}
	if (canvasPtr->textInfo.gotFocus) {
	    EventuallyRedrawItem(canvasPtr, itemPtr);
	}
	if (Tcl_GetString(objv[2])[0] == 0) {
1487
1488
1489
1490
1491
1492
1493
1494

1495
1496

1497
1498
1499
1500
1501
1502

1503
1504
1505
1506
1507
1508
1509
1506
1507
1508
1509
1510
1511
1512

1513
1514

1515
1516
1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527
1528







-
+

-
+





-
+







	    goto done;
	}
	FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done);
	if (itemPtr != NULL) {
	    int i;
	    Tcl_Obj *resultObj = Tcl_NewObj();

	    for (i = 0; i < (int)itemPtr->numTags; i++) {
	    for (i = 0; i < itemPtr->numTags; i++) {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tcl_NewStringObj(itemPtr->tagPtr[i], TCL_INDEX_NONE));
			Tcl_NewStringObj(itemPtr->tagPtr[i], -1));
	    }
	    Tcl_SetObjResult(interp, resultObj);
	}
	break;
    case CANV_ICURSOR: {
	Tcl_Size index;
	int index;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId index");
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
1520
1521
1522
1523
1524
1525
1526
1527

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551

1552
1553
1554
1555
1556


1557
1558
1559
1560
1561
1562
1563
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569

1570
1571
1572
1573


1574
1575
1576
1577
1578
1579
1580
1581
1582







-
+















-
+







-
+



-
-
+
+







		    && (canvasPtr->textInfo.cursorOn)) {
		EventuallyRedrawItem(canvasPtr, itemPtr);
	    }
	}
	break;
    }
    case CANV_INDEX: {
	Tcl_Size index;
	int index;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId string");
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
	    if (itemPtr->typePtr->indexProc != NULL) {
		break;
	    }
	}
	if (itemPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't find an indexable item \"%s\"",
		    Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "INDEXABLE_ITEM", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "INDEXABLE_ITEM", NULL);
	    result = TCL_ERROR;
	    goto done;
	}
	result = ItemIndex(canvasPtr, itemPtr, objv[3], &index);
	if (result != TCL_OK) {
	    goto done;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	break;
    }
    case CANV_INSERT: {
	Tcl_Size beforeThis;
	int x1, x2, y1, y2;
	int beforeThis;
	int x1,x2,y1,y2;

	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId beforeThis string");
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
1620
1621
1622
1623
1624
1625
1626

1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642





1643
1644
1645
1646
1647
1648
1649
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674







+
















+
+
+
+
+







	    }
	    if ((result != TCL_OK) || (objc < 5)) {
		break;
	    }
	}
	break;
    case CANV_LOWER: {
	Tk_Item *itemPtr;

	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?belowThis?");
	    result = TCL_ERROR;
	    goto done;
	}

	/*
	 * First find the item just after which we'll insert the named items.
	 */

	if (objc == 3) {
	    itemPtr = NULL;
	} else {
	    FIRST_CANVAS_ITEM_MATCHING(objv[3], &searchPtr, goto done);
	    if (itemPtr == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"tagOrId \"%s\" doesn't match any items",
			Tcl_GetString(objv[3])));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM", NULL);
		result = TCL_ERROR;
		goto done;
	    }
	    itemPtr = itemPtr->prevPtr;
	}
	RELINK_ITEMS(objv[2], itemPtr);
	break;
    }
1729
1730
1731
1732
1733
1734
1735


1736




1737
1738
1739
1740
1741
1742
1743
1754
1755
1756
1757
1758
1759
1760
1761
1762

1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773







+
+
-
+
+
+
+







		EventuallyRedrawItem(canvasPtr, itemPtr);
		canvasPtr->flags |= REPICK_NEEDED;
	    }
	}
	break;
    }
    case CANV_POSTSCRIPT: {
	const char **args = TkGetStringsFromObjs(objc, objv);

	result = TkCanvPostscriptObjCmd(canvasPtr, interp, objc, objv);
	result = TkCanvPostscriptCmd(canvasPtr, interp, objc, args);
	if (args != NULL) {
	    ckfree(args);
	}
	break;
    }
    case CANV_RAISE: {
	Tk_Item *prevPtr;

	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId ?aboveThis?");
1753
1754
1755
1756
1757
1758
1759





1760
1761
1762
1763
1764
1765
1766
1767
1768


1769
1770
1771
1772
1773
1774
1775
1776
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







+
+
+
+
+







-
-
+
+
-







	    prevPtr = canvasPtr->lastItemPtr;
	} else {
	    prevPtr = NULL;
	    FOR_EVERY_CANVAS_ITEM_MATCHING(objv[3], &searchPtr, goto done) {
		prevPtr = itemPtr;
	    }
	    if (prevPtr == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"tagOrId \"%s\" doesn't match any items",
			Tcl_GetString(objv[3])));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM", NULL);
		result = TCL_ERROR;
		goto done;
	    }
	}
	RELINK_ITEMS(objv[2], prevPtr);
	break;
    }
    case CANV_RCHARS: {
	Tcl_Size first, last;
	int x1, x2, y1, y2;
	int first, last;
	int x1,x2,y1,y2;
	int dontRedraw1, dontRedraw2;

	if (objc != 6) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId first last string");
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
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
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







-
-
+
-
-

-
+

-

-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	     * replace could result in a new area larger than the old area.
	     * Except if the dCharsProc or insertProc sets the
	     * TK_ITEM_DONT_REDRAW flag, nothing more needs to be done.
	     */

	    x1 = itemPtr->x1; y1 = itemPtr->y1;
	    x2 = itemPtr->x2; y2 = itemPtr->y2;

            itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    ItemDelChars(canvasPtr, itemPtr, first, last);
	    dontRedraw1 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;

            itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	    ItemDelChars(canvasPtr, itemPtr, first, last);
	    ItemInsert(canvasPtr, itemPtr, first, objv[5]);
	    dontRedraw2 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW;

            if (!(dontRedraw1 && dontRedraw2)) {
	    if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
		Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
			x1, y1, x2, y2);
		EventuallyRedrawItem(canvasPtr, itemPtr);
	    }
	    itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
	}
	break;
    }
    case CANV_ROTATE: {
	double x, y, angle;
	Tk_Canvas canvas = (Tk_Canvas) canvasPtr;

	if (objc != 6) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tagOrId x y angle");
	    result = TCL_ERROR;
	    goto done;
	}
	if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[3], &x) != TCL_OK ||
		Tk_CanvasGetCoordFromObj(interp, canvas, objv[4], &y) != TCL_OK ||
		Tcl_GetDoubleFromObj(interp, objv[5], &angle) != TCL_OK) {
	    result = TCL_ERROR;
	    goto done;
	}
	angle = angle * 3.1415927 / 180.0;
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
	    EventuallyRedrawItem(canvasPtr, itemPtr);
	    ItemRotate(canvasPtr, itemPtr, x, y, angle);
	    EventuallyRedrawItem(canvasPtr, itemPtr);
	    canvasPtr->flags |= REPICK_NEEDED;
	}
	break;
    }
    case CANV_SCALE: {
	double xOrigin, yOrigin, xScale, yScale;

	if (objc != 7) {
	    Tcl_WrongNumArgs(interp, 2, objv,
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
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







-
-
+
+














-
+






-
+

-
-
+
+







-
+







		|| (Tcl_GetDoubleFromObj(interp, objv[5], &xScale)!=TCL_OK)
		|| (Tcl_GetDoubleFromObj(interp, objv[6], &yScale)!=TCL_OK)) {
	    result = TCL_ERROR;
	    goto done;
	}
	if ((xScale == 0.0) || (yScale == 0.0)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "scale factor cannot be zero", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "BAD_SCALE", (char *)NULL);
		    "scale factor cannot be zero", -1));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "BAD_SCALE", NULL);
	    result = TCL_ERROR;
	    goto done;
	}
	FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
	    EventuallyRedrawItem(canvasPtr, itemPtr);
	    ItemScale(canvasPtr, itemPtr, xOrigin, yOrigin, xScale, yScale);
	    EventuallyRedrawItem(canvasPtr, itemPtr);
	    canvasPtr->flags |= REPICK_NEEDED;
	}
	break;
    }
    case CANV_SCAN: {
	int x, y, gain = 10;
	static const char *const optionStrings[] = {
	    "dragto", "mark", NULL
	    "mark", "dragto", NULL
	};

	if (objc < 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "mark|dragto x y ?dragGain?");
	    result = TCL_ERROR;
	} else if (Tcl_GetIndexFromObj(interp, objv[2], optionStrings,
		"scan option", 0, &idx) != TCL_OK) {
		"scan option", 0, &index) != TCL_OK) {
	    result = TCL_ERROR;
	} else if ((objc != 5) && (objc + idx != 6)) {
	    Tcl_WrongNumArgs(interp, 3, objv, idx?"x y":"x y ?gain?");
	} else if ((objc != 5) && (objc != 5+index)) {
	    Tcl_WrongNumArgs(interp, 3, objv, index?"x y ?gain?":"x y");
	    result = TCL_ERROR;
	} else if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){
	    result = TCL_ERROR;
	} else if ((objc == 6) &&
		(Tcl_GetIntFromObj(interp, objv[5], &gain) != TCL_OK)) {
	    result = TCL_ERROR;
	} else if (idx) {
	} else if (!index) {
	    canvasPtr->scanX = x;
	    canvasPtr->scanXOrigin = canvasPtr->xOrigin;
	    canvasPtr->scanY = y;
	    canvasPtr->scanYOrigin = canvasPtr->yOrigin;
	} else {
	    int newXOrigin, newYOrigin, tmp;

1913
1914
1915
1916
1917
1918
1919
1920
1921

1922
1923
1924
1925
1926
1927
1928
1919
1920
1921
1922
1923
1924
1925


1926
1927
1928
1929
1930
1931
1932
1933







-
-
+







		    - canvasPtr->scrollY1;
	    newYOrigin = canvasPtr->scrollY1 + tmp;
	    CanvasSetOrigin(canvasPtr, newXOrigin, newYOrigin);
	}
	break;
    }
    case CANV_SELECT: {
	Tcl_Size index;
	int optionindex;
	int index, optionindex;
	static const char *const optionStrings[] = {
	    "adjust", "clear", "from", "item", "to", NULL
	};
	enum options {
	    CANV_ADJUST, CANV_CLEAR, CANV_FROM, CANV_ITEM, CANV_TO
	};

1939
1940
1941
1942
1943
1944
1945
1946

1947
1948
1949
1950
1951
1952
1953
1944
1945
1946
1947
1948
1949
1950

1951
1952
1953
1954
1955
1956
1957
1958







-
+







		}
	    }
	    if (itemPtr == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't find an indexable and selectable item \"%s\"",
			Tcl_GetString(objv[3])));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "SELECTABLE_ITEM",
			(char *)NULL);
			NULL);
		result = TCL_ERROR;
		goto done;
	    }
	}
	if (objc == 5) {
	    result = ItemIndex(canvasPtr, itemPtr, objv[4], &index);
	    if (result != TCL_OK) {
1963
1964
1965
1966
1967
1968
1969
1970
1971


1972
1973
1974
1975
1976
1977
1978
1968
1969
1970
1971
1972
1973
1974


1975
1976
1977
1978
1979
1980
1981
1982
1983







-
-
+
+







	case CANV_ADJUST:
	    if (objc != 5) {
		Tcl_WrongNumArgs(interp, 3, objv, "tagOrId index");
		result = TCL_ERROR;
		goto done;
	    }
	    if (canvasPtr->textInfo.selItemPtr == itemPtr) {
		if (index + 1 <= ((canvasPtr->textInfo.selectFirst
			+ canvasPtr->textInfo.selectLast)/2)) {
		if (index < (canvasPtr->textInfo.selectFirst
			+ canvasPtr->textInfo.selectLast)/2) {
		    canvasPtr->textInfo.selectAnchor =
			    canvasPtr->textInfo.selectLast + 1;
		} else {
		    canvasPtr->textInfo.selectAnchor =
			    canvasPtr->textInfo.selectFirst;
		}
	    }
2000
2001
2002
2003
2004
2005
2006
2007

2008
2009
2010
2011
2012
2013
2014
2005
2006
2007
2008
2009
2010
2011

2012
2013
2014
2015
2016
2017
2018
2019







-
+







	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, NULL);
		result = TCL_ERROR;
		goto done;
	    }
	    if (canvasPtr->textInfo.selItemPtr != NULL) {
		Tcl_SetObjResult(interp,
			Tcl_NewWideIntObj(canvasPtr->textInfo.selItemPtr->id));
			Tcl_NewIntObj(canvasPtr->textInfo.selItemPtr->id));
	    }
	    break;
	case CANV_TO:
	    if (objc != 5) {
		Tcl_WrongNumArgs(interp, 2, objv, "tagOrId index");
		result = TCL_ERROR;
		goto done;
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
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







-
+







+










+
-
+
+
+
+

+
+
+

















-
-
-









+










+
-
+
+
+
+

+
+
+
















-
-
-




-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+

+







	    Tcl_WrongNumArgs(interp, 2, objv, "tag");
	    result = TCL_ERROR;
	    goto done;
	}
	FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done);
	if (itemPtr != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(itemPtr->typePtr->name, TCL_INDEX_NONE));
		    Tcl_NewStringObj(itemPtr->typePtr->name, -1));
	}
	break;
    case CANV_XVIEW: {
	int count, type;
	int newX = 0;		/* Initialization needed only to prevent gcc
				 * warnings. */
	double fraction;
	const char **args;

	if (objc == 2) {
	    Tcl_SetObjResult(interp, ScrollFractions(
		    canvasPtr->xOrigin + canvasPtr->inset,
		    canvasPtr->xOrigin + Tk_Width(canvasPtr->tkwin)
		    - canvasPtr->inset, canvasPtr->scrollX1,
		    canvasPtr->scrollX2));
	    break;
	}

	args = TkGetStringsFromObjs(objc, objv);
	type = Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count);
	type = Tk_GetScrollInfo(interp, objc, args, &fraction, &count);
	if (args != NULL) {
	    ckfree(args);
	}
	switch (type) {
	case TK_SCROLL_ERROR:
	    result = TCL_ERROR;
	    goto done;
	case TK_SCROLL_MOVETO:
	    newX = canvasPtr->scrollX1 - canvasPtr->inset
		    + (int) (fraction * (canvasPtr->scrollX2
			    - canvasPtr->scrollX1) + 0.5);
	    break;
	case TK_SCROLL_PAGES:
	    newX = (int) (canvasPtr->xOrigin + count * .9
		    * (Tk_Width(canvasPtr->tkwin) - 2*canvasPtr->inset));
	    break;
	case TK_SCROLL_UNITS:
	    if (canvasPtr->xScrollIncrement > 0) {
		newX = canvasPtr->xOrigin + count*canvasPtr->xScrollIncrement;
	    } else {
		newX = (int) (canvasPtr->xOrigin + count * .1
			* (Tk_Width(canvasPtr->tkwin) - 2*canvasPtr->inset));
	    }
	    break;
	default:
	    result = TCL_ERROR;
	    goto done;
	}
	CanvasSetOrigin(canvasPtr, newX, canvasPtr->yOrigin);
	break;
    }
    case CANV_YVIEW: {
	int count, type;
	int newY = 0;		/* Initialization needed only to prevent gcc
				 * warnings. */
	double fraction;
	const char **args;

	if (objc == 2) {
	    Tcl_SetObjResult(interp, ScrollFractions(
		    canvasPtr->yOrigin + canvasPtr->inset,
		    canvasPtr->yOrigin + Tk_Height(canvasPtr->tkwin)
		    - canvasPtr->inset,
		    canvasPtr->scrollY1, canvasPtr->scrollY2));
	    break;
	}

	args = TkGetStringsFromObjs(objc, objv);
	type = Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count);
	type = Tk_GetScrollInfo(interp, objc, args, &fraction, &count);
	if (args != NULL) {
	    ckfree(args);
	}
	switch (type) {
	case TK_SCROLL_ERROR:
	    result = TCL_ERROR;
	    goto done;
	case TK_SCROLL_MOVETO:
	    newY = canvasPtr->scrollY1 - canvasPtr->inset + (int) (
		    fraction*(canvasPtr->scrollY2-canvasPtr->scrollY1) + 0.5);
	    break;
	case TK_SCROLL_PAGES:
	    newY = (int) (canvasPtr->yOrigin + count * .9
		    * (Tk_Height(canvasPtr->tkwin) - 2*canvasPtr->inset));
	    break;
	case TK_SCROLL_UNITS:
	    if (canvasPtr->yScrollIncrement > 0) {
		newY = canvasPtr->yOrigin + count*canvasPtr->yScrollIncrement;
	    } else {
		newY = (int) (canvasPtr->yOrigin + count * .1
			* (Tk_Height(canvasPtr->tkwin) - 2*canvasPtr->inset));
	    }
	    break;
	default:
	    result = TCL_ERROR;
	    goto done;
	}
	CanvasSetOrigin(canvasPtr, canvasPtr->xOrigin, newY);
	break;
    }
    case CANV_IMAGE: {
        Tk_PhotoHandle photohandle;
        int subsample = 1, zoom = 1;

    }
        if (objc < 3 || objc > 5) {
            Tcl_WrongNumArgs(interp, 2, objv, "imagename ?subsample? ?zoom?");
            result = TCL_ERROR;
            goto done;
        }


        if ((photohandle = Tk_FindPhoto(interp, Tcl_GetString(objv[2]) )) == 0) {
            result = TCL_ERROR;
            goto done;
        }

        /*
         * If we are given a subsample or a zoom then grab them.
         */

        if (objc >= 4 && Tcl_GetIntFromObj(interp, objv[3], &subsample) != TCL_OK) {
            result = TCL_ERROR;
            goto done;
        }
        if (objc >= 5 && Tcl_GetIntFromObj(interp, objv[4], &zoom) != TCL_OK) {
            result = TCL_ERROR;
            goto done;
        }

        /*
         * Set the image size to zero, which allows the DrawCanvas() function
         * to expand the image automatically when it copies the pixmap into it.
         */

        if (Tk_PhotoSetSize(interp, photohandle, 0, 0) != TCL_OK) {
            result = TCL_ERROR;
            goto done;
        }

        result = DrawCanvas(interp, clientData, photohandle, subsample, zoom);
    }
    }

  done:
#ifndef USE_OLD_TAG_SEARCH
    TagSearchDestroy(searchPtr);
#endif /* not USE_OLD_TAG_SEARCH */
    Tcl_Release(canvasPtr);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
2175
2176
2177
2178
2179
2180
2181
2182
2183

2184
2185
2186
2187
2188

2189

2190

2191
2192
2193
2194
2195
2196
2197
2152
2153
2154
2155
2156
2157
2158


2159



2160

2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172







-
-
+
-
-
-

-
+

+

+







 *	Everything associated with the canvas is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyCanvas(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about canvas widget. */
    char *memPtr)		/* Info about canvas widget. */
#else
    char *memPtr)
#endif
{
    TkCanvas *canvasPtr = (TkCanvas *)memPtr;
    TkCanvas *canvasPtr = (TkCanvas *) memPtr;
    Tk_Item *itemPtr;
#ifndef USE_OLD_TAG_SEARCH
    TagSearchExpr *expr, *next;
#endif

    /*
     * Free up all of the items in the canvas.
     */

    for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
	    itemPtr = canvasPtr->firstItemPtr) {
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
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







-
+


+






+




-
+








    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeOptions handle all the standard option-related stuff.
     */

    Tcl_DeleteHashTable(&canvasPtr->idTable);
    if (canvasPtr->pixmapGC != NULL) {
    if (canvasPtr->pixmapGC != None) {
	Tk_FreeGC(canvasPtr->display, canvasPtr->pixmapGC);
    }
#ifndef USE_OLD_TAG_SEARCH
    expr = canvasPtr->bindTagExprs;
    while (expr) {
	next = expr->next;
	TagSearchExprDestroy(expr);
	expr = next;
    }
#endif /* USE_OLD_TAG_SEARCH */
    Tcl_DeleteTimerHandler(canvasPtr->insertBlinkHandler);
    if (canvasPtr->bindingTable != NULL) {
	Tk_DeleteBindingTable(canvasPtr->bindingTable);
    }
    Tk_FreeOptions(configSpecs, canvasPtr, canvasPtr->display, 0);
    Tk_FreeOptions(configSpecs, (char *) canvasPtr, canvasPtr->display, 0);
    canvasPtr->tkwin = NULL;
    ckfree(canvasPtr);
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+








-
-
+
+




















-
+







 */

static int
ConfigureCanvas(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkCanvas *canvasPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in objv. */
    int objc,			/* Number of valid entries in objv. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    XGCValues gcValues;
    GC newGC;
    Tk_State old_canvas_state=canvasPtr->canvas_state;

    if (Tk_ConfigureWidget(interp, canvasPtr->tkwin, configSpecs,
	    objc, objv, canvasPtr,
	    flags) != TCL_OK) {
	    objc, (const char **) objv, (char *) canvasPtr,
	    flags|TK_CONFIG_OBJS) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * A few options need special processing, such as setting the background
     * from a 3-D border and creating a GC for copying bits to the screen.
     */

    Tk_SetBackgroundFromBorder(canvasPtr->tkwin, canvasPtr->bgBorder);

    if (canvasPtr->highlightWidth < 0) {
	canvasPtr->highlightWidth = 0;
    }
    canvasPtr->inset = canvasPtr->borderWidth + canvasPtr->highlightWidth;

    gcValues.function = GXcopy;
    gcValues.graphics_exposures = False;
    gcValues.foreground = Tk_3DBorderColor(canvasPtr->bgBorder)->pixel;
    newGC = Tk_GetGC(canvasPtr->tkwin,
	    GCFunction|GCGraphicsExposures|GCForeground, &gcValues);
    if (canvasPtr->pixmapGC != NULL) {
    if (canvasPtr->pixmapGC != None) {
	Tk_FreeGC(canvasPtr->display, canvasPtr->pixmapGC);
    }
    canvasPtr->pixmapGC = newGC;

    /*
     * Reconfigure items to reflect changed state disabled/normal.
     */
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
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







-
+









-
+







     */

    canvasPtr->scrollX1 = 0;
    canvasPtr->scrollY1 = 0;
    canvasPtr->scrollX2 = 0;
    canvasPtr->scrollY2 = 0;
    if (canvasPtr->regionString != NULL) {
	Tcl_Size argc2;
	int argc2;
	const char **argv2;

	if (Tcl_SplitList(canvasPtr->interp, canvasPtr->regionString,
		&argc2, &argv2) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (argc2 != 4) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad scrollRegion \"%s\"", canvasPtr->regionString));
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SCROLL_REGION", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SCROLL_REGION", NULL);
	badRegion:
	    ckfree(canvasPtr->regionString);
	    ckfree(argv2);
	    canvasPtr->regionString = NULL;
	    return TCL_ERROR;
	}
	if ((Tk_GetPixels(canvasPtr->interp, canvasPtr->tkwin,
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
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







-
+

-
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+

-
+




-
-
-
-














-
-
+
+







 *	to be redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
CanvasWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    TkCanvas *canvasPtr = (TkCanvas *)instanceData;
    TkCanvas *canvasPtr = instanceData;
    Tk_Item *itemPtr;

    itemPtr = canvasPtr->firstItemPtr;
    for ( ; itemPtr != NULL; itemPtr = itemPtr->nextPtr) {
	if (ItemConfigure(canvasPtr, itemPtr, 0, NULL) != TCL_OK) {
	    Tcl_ResetResult(canvasPtr->interp);
	}
    }
    canvasPtr->flags |= REPICK_NEEDED;
    Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
	    canvasPtr->xOrigin, canvasPtr->yOrigin,
	    canvasPtr->xOrigin + Tk_Width(canvasPtr->tkwin),
	    canvasPtr->yOrigin + Tk_Height(canvasPtr->tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * DecomposeMaskToShiftAndBits --
 *
 *      Given a 32 bit pixel mask, we find the position of the lowest bit and the
 *      width of the mask bits.
 *
 * Results:
 *	None.
 *
 * Side effects:
*       None.
 *
 *----------------------------------------------------------------------
 */
static void
DecomposeMaskToShiftAndBits(
    unsigned int mask,     /* The pixel mask to examine */
    int *shift,             /* Where to put the shift count (position of lowest bit) */
    int *bits)              /* Where to put the bit count (width of the pixel mask) */
{
    int i;

    *shift = 0;
    *bits = 0;

    /*
     * Find the lowest '1' bit in the mask.
     */

    for (i = 0; i < 32; ++i) {
        if (mask & 1 << i)
            break;
    }
    if (i < 32) {
        *shift = i;

        /*
        * Now find the next '0' bit and the width of the mask.
        */

        for ( ; i < 32; ++i) {
            if ((mask & 1 << i) == 0)
                break;
            else
                ++*bits;
        }

        /*
        * Limit to the top 8 bits if the mask was wider than 8.
        */

        if (*bits > 8) {
            *shift += *bits - 8;
            *bits = 8;
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DrawCanvas --
 *
 *      This function draws the contents of a canvas into the given Photo image.
 *      This function is called from the widget "image" subcommand.
 *      The canvas does not need to be mapped (one of it's ancestors must be)
 *      in order for this function to work.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *      Canvas contents from within the -scrollregion or widget size are rendered
 *      into the Photo. Any errors are left in the result.
 *
 *----------------------------------------------------------------------
 */

#define OVERDRAW_PIXELS 32        /* How much larger we make the pixmap
                                   * that the canvas objects are drawn into */

#ifdef WORDS_BIGENDIAN
#define IS_BIG_ENDIAN 1
#else
#define IS_BIG_ENDIAN 0
#endif

#define BYTE_SWAP16(n) ((((unsigned short)n)>>8) | (((unsigned short)n)<<8))
#define BYTE_SWAP32(n) (((n>>24)&0x000000FF) | ((n<<8)&0x00FF0000) | ((n>>8)&0x0000FF00) | ((n<<24)&0xFF000000))

static int
DrawCanvas(
    Tcl_Interp *interp,           /* As passed to the widget command, and we will leave errors here */
    void *clientData,
    Tk_PhotoHandle photohandle,   /* The photo we are rendering into */
    int subsample,                /* If either subsample or zoom are not 1 then we call Tk_PhotoPutZoomedBlock() */
    int zoom)
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    Tk_Window tkwin;
    Display *displayPtr;
    Tk_PhotoImageBlock blockPtr = {0,0,0,0,0,{0,0,0,0}};
    Window wid;
    Tk_Item *itemPtr;
    Pixmap pixmap = 0;
    XImage *ximagePtr = NULL;
    Visual *visualPtr;
    GC xgc = 0;
    XGCValues xgcValues;
    int canvasX1, canvasY1, canvasX2, canvasY2, cWidth, cHeight,
        pixmapX1, pixmapY1, pixmapX2, pixmapY2, pmWidth, pmHeight,
        bitsPerPixel, bytesPerPixel, x, y, result = TCL_OK,
        rshift, gshift, bshift, rbits, gbits, bbits;

#ifdef DEBUG_DRAWCANVAS
    char buffer[128];
#endif

    if ((tkwin = canvasPtr->tkwin) == NULL) {
        Tcl_AppendResult(interp, "canvas tkwin is NULL!", (char *)NULL);
        result = TCL_ERROR;
        goto done;
    }

    /*
     * If this canvas is unmapped, then we won't have a window id, so we will
     * try the ancestors of the canvas until we find a window that has a
     * valid window id. The Tk_GetPixmap() call requires a valid window id.
     */

    do {

        if ((displayPtr = Tk_Display(tkwin)) == NULL) {
            Tcl_AppendResult(interp, "canvas (or parent) display is NULL!", (char *)NULL);
            result = TCL_ERROR;
            goto done;
        }

        if ((wid = Tk_WindowId(tkwin)) != 0) {
            continue;
        }

        if ((tkwin = Tk_Parent(tkwin)) == NULL) {
            Tcl_AppendResult(interp, "canvas has no parent with a valid window id! Is the toplevel window mapped?", (char *)NULL);
            result = TCL_ERROR;
            goto done;
        }

    } while (wid == 0);

    bitsPerPixel = Tk_Depth(tkwin);
    visualPtr = Tk_Visual(tkwin);

    if (subsample == 0) {
        Tcl_AppendResult(interp, "subsample cannot be zero", (char *)NULL);
        result = TCL_ERROR;
        goto done;
    }

    /*
    * Scan through the item list, registering the bounding box for all items
    * that didn't do that for the final coordinates yet. This can be
    * determined by the FORCE_REDRAW flag.
    */

    for (itemPtr = canvasPtr -> firstItemPtr; itemPtr != NULL;
            itemPtr = itemPtr -> nextPtr) {
        if (itemPtr -> redraw_flags & FORCE_REDRAW) {
            itemPtr -> redraw_flags &= ~FORCE_REDRAW;
            EventuallyRedrawItem(canvasPtr, itemPtr);
            itemPtr -> redraw_flags &= ~FORCE_REDRAW;
        }
    }

    /*
     * The DisplayCanvas() function works out the region that needs redrawing,
     * but we don't do this. We grab the whole scrollregion or canvas window
     * area. If we have a defined -scrollregion we use that as the drawing
     * region, otherwise use the canvas window height and width with an origin
     * of 0,0.
     */
    if (canvasPtr->scrollX1 != 0 || canvasPtr->scrollY1 != 0 ||
            canvasPtr->scrollX2 != 0 || canvasPtr->scrollY2 != 0) {

        canvasX1 = canvasPtr->scrollX1;
        canvasY1 = canvasPtr->scrollY1;
        canvasX2 = canvasPtr->scrollX2;
        canvasY2 = canvasPtr->scrollY2;
        cWidth = canvasX2 - canvasX1 + 1;
        cHeight = canvasY2 - canvasY1 + 1;

    } else {

        cWidth = Tk_Width(tkwin);
        cHeight = Tk_Height(tkwin);
        canvasX1 = 0;
        canvasY1 = 0;
        canvasX2 = canvasX1 + cWidth - 1;
        canvasY2 = canvasY1 + cHeight - 1;
    }

    /*
     * Allocate a pixmap to draw into. We add OVERDRAW_PIXELS in the same way
     * that DisplayCanvas() does to avoid problems on some systems when objects
     * are being drawn too close to the edge.
     */

    pixmapX1 = canvasX1 - OVERDRAW_PIXELS;
    pixmapY1 = canvasY1 - OVERDRAW_PIXELS;
    pixmapX2 = canvasX2 + OVERDRAW_PIXELS;
    pixmapY2 = canvasY2 + OVERDRAW_PIXELS;
    pmWidth = pixmapX2 - pixmapX1 + 1;
    pmHeight = pixmapY2 - pixmapY1 + 1;
    if ((pixmap = Tk_GetPixmap(displayPtr, Tk_WindowId(tkwin), pmWidth, pmHeight,
            bitsPerPixel)) == 0) {
        Tcl_AppendResult(interp, "failed to create drawing Pixmap", (char *)NULL);
        result = TCL_ERROR;
        goto done;
    }

    /*
     * Before we can draw the canvas objects into the pixmap it's background
     * should be filled with canvas background colour.
     */

    xgcValues.function = GXcopy;
    xgcValues.foreground = Tk_3DBorderColor(canvasPtr->bgBorder)->pixel;
    xgc = XCreateGC(displayPtr, pixmap, GCFunction|GCForeground, &xgcValues);
    XFillRectangle(displayPtr,pixmap,xgc,0,0,pmWidth,pmHeight);

    /*
     * Draw all the cavas items into the pixmap
     */

    canvasPtr->drawableXOrigin = pixmapX1;
    canvasPtr->drawableYOrigin = pixmapY1;
    for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
            itemPtr = itemPtr->nextPtr) {
        if ((itemPtr->x1 >= pixmapX2) || (itemPtr->y1 >= pixmapY2) ||
                (itemPtr->x2 < pixmapX1) || (itemPtr->y2 < pixmapY1)) {
            if (!AlwaysRedraw(itemPtr)) {
                continue;
            }
        }
        if (itemPtr->state == TK_STATE_HIDDEN ||
                (itemPtr->state == TK_STATE_NULL && canvasPtr->canvas_state
                == TK_STATE_HIDDEN)) {
            continue;
        }
        ItemDisplay(canvasPtr, itemPtr, pixmap, pixmapX1, pixmapY1, pmWidth,
                pmHeight);
    }

    /*
     * Copy the Pixmap into an ZPixmap format XImage so we can copy it across
     * to the photo image. This seems to be the only way to get Pixmap image
     * data out of an image. Note we have to account for the OVERDRAW_PIXELS
     * border width.
     */

    if ((ximagePtr = XGetImage(displayPtr, pixmap, -pixmapX1, -pixmapY1, cWidth,
            cHeight, AllPlanes, ZPixmap)) == NULL) {
        Tcl_AppendResult(interp, "failed to copy Pixmap to XImage", (char *)NULL);
        result = TCL_ERROR;
        goto done;
    }

#ifdef DEBUG_DRAWCANVAS
    Tcl_AppendResult(interp, "ximagePtr {", (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->width);   Tcl_AppendResult(interp, " width ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->height);  Tcl_AppendResult(interp, " height ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->xoffset); Tcl_AppendResult(interp, " xoffset ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->format);  Tcl_AppendResult(interp, " format ", buffer, (char *)NULL);
    Tcl_AppendResult(interp, " ximagePtr->data", (char *)NULL);
    if (ximagePtr->data != NULL) {
	int ix, iy;

        Tcl_AppendResult(interp, " {", (char *)NULL);
	for (iy = 0; iy < ximagePtr->height; ++ iy) {
	    Tcl_AppendResult(interp, " {", (char *)NULL);
	    for (ix = 0; ix < ximagePtr->bytes_per_line; ++ ix) {
	        if (ix > 0) {
                    if (ix % 4 == 0)
                        Tcl_AppendResult(interp, "-", (char *)NULL);
                    else
                        Tcl_AppendResult(interp, " ", (char *)NULL);
                }
	        snprintf(buffer,sizeof(buffer),"%2.2x",ximagePtr->data[ximagePtr->bytes_per_line * iy + ix]&0xFF);
	        Tcl_AppendResult(interp, buffer, (char *)NULL);
	    }
	    Tcl_AppendResult(interp, " }", (char *)NULL);
	}
	Tcl_AppendResult(interp, " }", (char *)NULL);
    } else
	snprintf(buffer,sizeof(buffer)," NULL");
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->byte_order);       Tcl_AppendResult(interp, " byte_order ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->bitmap_unit);      Tcl_AppendResult(interp, " bitmap_unit ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->bitmap_bit_order); Tcl_AppendResult(interp, " bitmap_bit_order ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->bitmap_pad);       Tcl_AppendResult(interp, " bitmap_pad ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->depth);            Tcl_AppendResult(interp, " depth ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->bytes_per_line);   Tcl_AppendResult(interp, " bytes_per_line ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",ximagePtr->bits_per_pixel);   Tcl_AppendResult(interp, " bits_per_pixel ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",ximagePtr->red_mask);   Tcl_AppendResult(interp, " red_mask ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",ximagePtr->green_mask); Tcl_AppendResult(interp, " green_mask ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",ximagePtr->blue_mask);  Tcl_AppendResult(interp, " blue_mask ", buffer, (char *)NULL);
    Tcl_AppendResult(interp, " }", (char *)NULL);

    Tcl_AppendResult(interp, "\nvisualPtr {", (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",visualPtr->red_mask);   Tcl_AppendResult(interp, " red_mask ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",visualPtr->green_mask); Tcl_AppendResult(interp, " green_mask ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"0x%8.8lx",visualPtr->blue_mask);  Tcl_AppendResult(interp, " blue_mask ", buffer, (char *)NULL);
    Tcl_AppendResult(interp, " }", (char *)NULL);

#endif

    /*
     * Fill in the PhotoImageBlock structure abd allocate a block of memory
     * for the converted image data. Note we allocate an alpha channel even
     * though we don't use one, because this layout helps Tk_PhotoPutBlock()
     * use memcpy() instead of the slow pixel or line copy.
     */

    blockPtr.width = cWidth;
    blockPtr.height = cHeight;
    blockPtr.pixelSize = 4;
    blockPtr.pitch = blockPtr.pixelSize * blockPtr.width;

#ifdef TK_XGETIMAGE_USES_ABGR32
    blockPtr.offset[0] = 1;
    blockPtr.offset[1] = 2;
    blockPtr.offset[2] = 3;
    blockPtr.offset[3] = 0;
#else
    blockPtr.offset[0] = 0;
    blockPtr.offset[1] = 1;
    blockPtr.offset[2] = 2;
    blockPtr.offset[3] = 3;
#endif

    blockPtr.pixelPtr = (unsigned char *)ckalloc(blockPtr.pixelSize * blockPtr.height * blockPtr.width);

    /*
     * Now convert the image data pixel by pixel from XImage to 32bit RGBA
     * format suitable for Tk_PhotoPutBlock().
     */

    DecomposeMaskToShiftAndBits(visualPtr->red_mask,&rshift,&rbits);
    DecomposeMaskToShiftAndBits(visualPtr->green_mask,&gshift,&gbits);
    DecomposeMaskToShiftAndBits(visualPtr->blue_mask,&bshift,&bbits);

#ifdef DEBUG_DRAWCANVAS
    snprintf(buffer,sizeof(buffer),"%d",rshift); Tcl_AppendResult(interp, "\nbits { rshift ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",gshift); Tcl_AppendResult(interp, " gshift ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",bshift); Tcl_AppendResult(interp, " bshift ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",rbits);  Tcl_AppendResult(interp, " rbits ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",gbits);  Tcl_AppendResult(interp, " gbits ", buffer, (char *)NULL);
    snprintf(buffer,sizeof(buffer),"%d",bbits);  Tcl_AppendResult(interp, " bbits ", buffer, " }", (char *)NULL);
    Tcl_AppendResult(interp, "\nConverted_image {", (char *)NULL);
#endif

    /* Ok, had to use ximagePtr->bits_per_pixel here and in the switch (...)
     * below to get this to work on Windows. X11 correctly sets the bitmap
     *_pad and bitmap_unit fields to 32, but on Windows they are 0 and 8
     * respectively!
     */

    bytesPerPixel = ximagePtr->bits_per_pixel/8;
    for (y = 0; y < blockPtr.height; ++y) {

#ifdef DEBUG_DRAWCANVAS
        Tcl_AppendResult(interp, " {", (char *)NULL);
#endif

        for(x = 0; x < blockPtr.width; ++x) {
            unsigned int pixel = 0;
	    int pixel_offset = blockPtr.pitch * y + blockPtr.pixelSize * x;
            switch (ximagePtr->bits_per_pixel) {

                /*
                 * Get an 8 bit pixel from the XImage.
                 */

                case 8 :
                    pixel = *((unsigned char *)(ximagePtr->data + bytesPerPixel * x
                            + ximagePtr->bytes_per_line * y));
                    break;

                /*
                 * Get a 16 bit pixel from the XImage, and correct the
                 * byte order as necessary.
                 */

                case 16 :
                    pixel = *((unsigned short *)(ximagePtr->data + bytesPerPixel * x
                            + ximagePtr->bytes_per_line * y));
                    if ((IS_BIG_ENDIAN && ximagePtr->byte_order == LSBFirst)
                            || (!IS_BIG_ENDIAN && ximagePtr->byte_order == MSBFirst))
                        pixel = BYTE_SWAP16(pixel);
                    break;

                /*
                 * Grab a 32 bit pixel from the XImage, and correct the
                 * byte order as necessary.
                 */

                case 32 :
                    pixel = *((unsigned int *)(ximagePtr->data + bytesPerPixel * x
                            + ximagePtr->bytes_per_line * y));
                    if ((IS_BIG_ENDIAN && ximagePtr->byte_order == LSBFirst)
                            || (!IS_BIG_ENDIAN && ximagePtr->byte_order == MSBFirst))
                        pixel = BYTE_SWAP32(pixel);
                    break;
            }

            /*
             * We have a pixel with the correct byte order, so pull out the
             * colours and place them in the photo block. Perhaps we could
             * just not bother with the alpha byte because we are using
             * TK_PHOTO_COMPOSITE_SET later?
             * ***Windows: We have to swap the red and blue values. The
             * XImage storage is B - G - R - A which becomes a 32bit ARGB
             * quad. However the visual mask is a 32bit ABGR quad. And
             * Tk_PhotoPutBlock() wants R-G-B-A which is a 32bit ABGR quad.
             * If the visual mask was correct there would be no need to
             * swap anything here.
             */

#ifdef _WIN32
#define   R_OFFSET blockPtr.offset[2]
#define   G_OFFSET blockPtr.offset[1]
#define   B_OFFSET blockPtr.offset[0]
#define   A_OFFSET blockPtr.offset[3]
#else
#define   R_OFFSET blockPtr.offset[0]
#define   G_OFFSET blockPtr.offset[1]
#define   B_OFFSET blockPtr.offset[2]
#define   A_OFFSET blockPtr.offset[3]
#endif
#ifdef TK_XGETIMAGE_USES_ABGR32
#define COPY_PIXEL (ximagePtr->bits_per_pixel == 32)
#else
#define COPY_PIXEL 0
#endif

	    if (COPY_PIXEL) {
		/*
		 * This platform packs pixels in RGBA byte order, as expected
		 * by Tk_PhotoPutBlock() so we can just copy the pixel as an int.
		 */
		*((unsigned int *) (blockPtr.pixelPtr + pixel_offset)) = pixel;
	    } else {
		blockPtr.pixelPtr[pixel_offset + R_OFFSET] =
                    (unsigned char)((pixel & visualPtr->red_mask) >> rshift);
		blockPtr.pixelPtr[pixel_offset + G_OFFSET] =
                    (unsigned char)((pixel & visualPtr->green_mask) >> gshift);
		blockPtr.pixelPtr[pixel_offset + B_OFFSET] =
                    (unsigned char)((pixel & visualPtr->blue_mask) >> bshift);
		blockPtr.pixelPtr[pixel_offset + A_OFFSET] = 0xFF;
	    }

#ifdef DEBUG_DRAWCANVAS
	    fprintf(stderr, "Converted pixel %x to %hhx %hhx %hhx %hhx \n",
		    pixel,
		    blockPtr.pixelPtr[pixel_offset + 0],
		    blockPtr.pixelPtr[pixel_offset + 1],
		    blockPtr.pixelPtr[pixel_offset + 2],
		    blockPtr.pixelPtr[pixel_offset + 3]);
            {
		int ix;
                if (x > 0)
                    Tcl_AppendResult(interp, "-", (char *)NULL);
	        for (ix = 0; ix < 4; ++ix) {
                    if (ix > 0)
                        Tcl_AppendResult(interp, " ", (char *)NULL);
		    snprintf(buffer,sizeof(buffer),"%2.2x",
		            blockPtr.pixelPtr[blockPtr.pitch * y
                            + blockPtr.pixelSize * x + ix]&0xFF);
                    Tcl_AppendResult(interp, buffer, (char *)NULL);
                }
            }
#endif

        }

#ifdef DEBUG_DRAWCANVAS
        Tcl_AppendResult(interp, " }", (char *)NULL);
#endif

    }

#ifdef DEBUG_DRAWCANVAS
    Tcl_AppendResult(interp, " }", (char *)NULL);
#endif

    /*
     * Now put the copied pixmap into the photo.
     * If either zoom or subsample are not 1, we use the zoom function.
     */

    if (subsample != 1 || zoom != 1) {
        if ((result = Tk_PhotoPutZoomedBlock(interp, photohandle, &blockPtr,
                0, 0, cWidth * zoom / subsample, cHeight * zoom / subsample,
                zoom, zoom, subsample, subsample, TK_PHOTO_COMPOSITE_SET))
                != TCL_OK) {
            goto done;
        }
    } else {
        if ((result = Tk_PhotoPutBlock(interp, photohandle, &blockPtr, 0, 0,
            cWidth, cHeight, TK_PHOTO_COMPOSITE_SET)) != TCL_OK) {
            goto done;
        }
    }

    /*
     * Clean up anything we have allocated and exit.
     */

done:
    if (blockPtr.pixelPtr)
        ckfree(blockPtr.pixelPtr);
    if (pixmap)
        Tk_FreePixmap(Tk_Display(tkwin), pixmap);
    if (ximagePtr)
        XDestroyImage(ximagePtr);
    if (xgc)
        XFreeGC(displayPtr,xgc);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * DisplayCanvas --
 *
 *	This function redraws the contents of a canvas window. It is invoked
 *	as a do-when-idle handler, so it only runs when there's nothing else
 *	for the application to do.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information appears on the screen.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayCanvas(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;
    Tk_Window tkwin = canvasPtr->tkwin;
    Tk_Item *itemPtr;
    Pixmap pixmap;
    int screenX1, screenX2, screenY1, screenY2, width, height;
#ifdef MAC_OSX_TK
    TkWindow *winPtr;
    MacDrawable *macWin;
#endif

    if (canvasPtr->tkwin == NULL) {
	return;
    }

    if (!Tk_IsMapped(tkwin)) {
	goto done;
    }

#ifdef MAC_OSX_TK
    /*
     * If drawing is disabled, all we need to do is
     * clear the REDRAW_PENDING flag.
     */
    winPtr = (TkWindow *)(canvasPtr->tkwin);
    macWin = winPtr->privatePtr;
    TkWindow *winPtr = (TkWindow *)(canvasPtr->tkwin);
    MacDrawable *macWin = winPtr->privatePtr;
    if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){
	canvasPtr->flags &= ~REDRAW_PENDING;
	return;
    }
#endif

    /*
3114
3115
3116
3117
3118
3119
3120
3121

3122
3123
3124
3125
3126
3127
3128
2556
2557
2558
2559
2560
2561
2562

2563
2564
2565
2566
2567
2568
2569
2570







-
+







	    (screenX2 + 30 - canvasPtr->drawableXOrigin),
	    (screenY2 + 30 - canvasPtr->drawableYOrigin),
	    Tk_Depth(tkwin));
#else
	canvasPtr->drawableXOrigin = canvasPtr->xOrigin;
	canvasPtr->drawableYOrigin = canvasPtr->yOrigin;
	pixmap = Tk_WindowId(tkwin);
	Tk_ClipDrawableToRect(Tk_Display(tkwin), pixmap,
	TkpClipDrawableToRect(Tk_Display(tkwin), pixmap,
		screenX1 - canvasPtr->xOrigin, screenY1 - canvasPtr->yOrigin,
		width, height);
#endif /* TK_NO_DOUBLE_BUFFERING */

	/*
	 * Clear the area to be redrawn.
	 */
3173
3174
3175
3176
3177
3178
3179
3180

3181
3182
3183
3184
3185
3186
3187
2615
2616
2617
2618
2619
2620
2621

2622
2623
2624
2625
2626
2627
2628
2629







-
+







		canvasPtr->pixmapGC,
		screenX1 - canvasPtr->drawableXOrigin,
		screenY1 - canvasPtr->drawableYOrigin,
		(unsigned int) width, (unsigned int) height,
		screenX1 - canvasPtr->xOrigin, screenY1 - canvasPtr->yOrigin);
	Tk_FreePixmap(Tk_Display(tkwin), pixmap);
#else
	Tk_ClipDrawableToRect(Tk_Display(tkwin), pixmap, 0, 0, -1, -1);
	TkpClipDrawableToRect(Tk_Display(tkwin), pixmap, 0, 0, -1, -1);
#endif /* TK_NO_DOUBLE_BUFFERING */
    }

    /*
     * Draw the window borders, if needed.
     */

3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210

3211
3212
3213
3214
3215
3216
3217
2642
2643
2644
2645
2646
2647
2648

2649
2650
2651

2652
2653
2654
2655
2656
2657
2658
2659







-
+


-
+







	    GC fgGC, bgGC;

	    bgGC = Tk_GCForColor(canvasPtr->highlightBgColorPtr,
		    Tk_WindowId(tkwin));
	    if (canvasPtr->textInfo.gotFocus) {
		fgGC = Tk_GCForColor(canvasPtr->highlightColorPtr,
			Tk_WindowId(tkwin));
	    	Tk_DrawHighlightBorder(tkwin, fgGC, bgGC,
	    	TkpDrawHighlightBorder(tkwin, fgGC, bgGC,
			canvasPtr->highlightWidth, Tk_WindowId(tkwin));
	    } else {
	    	Tk_DrawHighlightBorder(tkwin, bgGC, bgGC,
	    	TkpDrawHighlightBorder(tkwin, bgGC, bgGC,
			canvasPtr->highlightWidth, Tk_WindowId(tkwin));
	    }
	}
    }

  done:
    canvasPtr->flags &= ~(REDRAW_PENDING|BBOX_NOT_EMPTY);
3238
3239
3240
3241
3242
3243
3244
3245

3246
3247
3248

3249
3250
3251
3252
3253
3254
3255
2680
2681
2682
2683
2684
2685
2686

2687
2688
2689

2690
2691
2692
2693
2694
2695
2696
2697







-
+


-
+







 *	it gets exposed, it is redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
CanvasEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;

    if (eventPtr->type == Expose) {
	int x, y;

	x = eventPtr->xexpose.x + canvasPtr->xOrigin;
	y = eventPtr->xexpose.y + canvasPtr->yOrigin;
	Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x, y,
3268
3269
3270
3271
3272
3273
3274
3275

3276
3277
3278
3279
3280
3281
3282
2710
2711
2712
2713
2714
2715
2716

2717
2718
2719
2720
2721
2722
2723
2724







-
+







	    canvasPtr->tkwin = NULL;
	    Tcl_DeleteCommandFromToken(canvasPtr->interp,
		    canvasPtr->widgetCmd);
	}
	if (canvasPtr->flags & REDRAW_PENDING) {
	    Tcl_CancelIdleCall(DisplayCanvas, canvasPtr);
	}
	Tcl_EventuallyFree(canvasPtr, DestroyCanvas);
	Tcl_EventuallyFree(canvasPtr, (Tcl_FreeProc *) DestroyCanvas);
    } else if (eventPtr->type == ConfigureNotify) {
	canvasPtr->flags |= UPDATE_SCROLLBARS;

	/*
	 * The call below is needed in order to recenter the canvas if it's
	 * confined and its scroll region is smaller than the window.
	 */
3296
3297
3298
3299
3300
3301
3302
3303
3304


3305
3306
3307
3308
3309
3310
3311
2738
2739
2740
2741
2742
2743
2744


2745
2746
2747
2748
2749
2750
2751
2752
2753







-
-
+
+







	    CanvasFocusProc(canvasPtr, 0);
	}
    } else if (eventPtr->type == UnmapNotify) {
	Tk_Item *itemPtr;

	/*
	 * Special hack: if the canvas is unmapped, then must notify all items
	 * with flag TK_ALWAYS_REDRAW set, so that they know that they are no
	 * longer displayed.
	 * with "alwaysRedraw" set, so that they know that they are no longer
	 * displayed.
	 */

	for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
		itemPtr = itemPtr->nextPtr) {
	    if (AlwaysRedraw(itemPtr)) {
		ItemDisplay(canvasPtr, itemPtr, None, 0, 0, 0, 0);
	    }
3329
3330
3331
3332
3333
3334
3335
3336

3337
3338

3339
3340
3341
3342
3343
3344
3345
2771
2772
2773
2774
2775
2776
2777

2778
2779

2780
2781
2782
2783
2784
2785
2786
2787







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
CanvasCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;
    Tk_Window tkwin = canvasPtr->tkwin;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.
3438
3439
3440
3441
3442
3443
3444
3445

3446
3447
3448
3449
3450
3451
3452
2880
2881
2882
2883
2884
2885
2886

2887
2888
2889
2890
2891
2892
2893
2894







-
+








static void
EventuallyRedrawItem(
    TkCanvas *canvasPtr,	/* Information about widget. */
    Tk_Item *itemPtr)		/* Item to be redrawn. May be NULL, in which
				 * case nothing happens. */
{
    if (itemPtr == NULL || canvasPtr->tkwin == NULL) {
    if (itemPtr == NULL) {
	return;
    }
    if ((itemPtr->x1 >= itemPtr->x2) || (itemPtr->y1 >= itemPtr->y2) ||
 	    (itemPtr->x2 < canvasPtr->xOrigin) ||
	    (itemPtr->y2 < canvasPtr->yOrigin) ||
	    (itemPtr->x1 >= canvasPtr->xOrigin+Tk_Width(canvasPtr->tkwin)) ||
	    (itemPtr->y1 >= canvasPtr->yOrigin+Tk_Height(canvasPtr->tkwin))) {
3599
3600
3601
3602
3603
3604
3605










































































































































































































3606
3607
3608
3609
3610
3611
3612
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    tkOvalType.nextPtr = &tkBitmapType;
    tkBitmapType.nextPtr = &tkArcType;
    tkArcType.nextPtr = &tkWindowType;
    tkWindowType.nextPtr = NULL;
    Tcl_MutexUnlock(&typeListMutex);
}

#ifdef USE_OLD_TAG_SEARCH
/*
 *--------------------------------------------------------------
 *
 * StartTagSearch --
 *
 *	This function is called to initiate an enumeration of all items in a
 *	given canvas that contain a given tag.
 *
 * Results:
 *	The return value is a pointer to the first item in canvasPtr that
 *	matches tag, or NULL if there is no such item. The information at
 *	*searchPtr is initialized such that successive calls to NextItem will
 *	return successive items that match tag.
 *
 * Side effects:
 *	SearchPtr is linked into a list of searches in progress on canvasPtr,
 *	so that elements can safely be deleted while the search is in
 *	progress. EndTagSearch must be called at the end of the search to
 *	unlink searchPtr from this list.
 *
 *--------------------------------------------------------------
 */

static Tk_Item *
StartTagSearch(
    TkCanvas *canvasPtr,	/* Canvas whose items are to be searched. */
    Tcl_Obj *tagObj,		/* Object giving tag value. */
    TagSearch *searchPtr)	/* Record describing tag search; will be
				 * initialized here. */
{
    int id;
    Tk_Item *itemPtr, *lastPtr;
    Tk_Uid *tagPtr;
    Tk_Uid uid;
    char *tag = Tcl_GetString(tagObj);
    int count;
    TkWindow *tkwin = (TkWindow *) canvasPtr->tkwin;
    TkDisplay *dispPtr = tkwin->dispPtr;

    /*
     * Initialize the search.
     */

    searchPtr->canvasPtr = canvasPtr;
    searchPtr->searchOver = 0;

    /*
     * Find the first matching item in one of several ways. If the tag is a
     * number then it selects the single item with the matching identifier.
     * In this case see if the item being requested is the hot item, in which
     * case the search can be skipped.
     */

    if (isdigit(UCHAR(*tag))) {
	char *end;
	Tcl_HashEntry *entryPtr;

	dispPtr->numIdSearches++;
	id = strtoul(tag, &end, 0);
	if (*end == 0) {
	    itemPtr = canvasPtr->hotPtr;
	    lastPtr = canvasPtr->hotPrevPtr;
	    if ((itemPtr == NULL) || (itemPtr->id != id) || (lastPtr == NULL)
		    || (lastPtr->nextPtr != itemPtr)) {
		dispPtr->numSlowSearches++;
		entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char*) id);
		if (entryPtr != NULL) {
		    itemPtr = Tcl_GetHashValue(entryPtr);
		    lastPtr = itemPtr->prevPtr;
		} else {
		    lastPtr = itemPtr = NULL;
		}
	    }
	    searchPtr->lastPtr = lastPtr;
	    searchPtr->searchOver = 1;
	    canvasPtr->hotPtr = itemPtr;
	    canvasPtr->hotPrevPtr = lastPtr;
	    return itemPtr;
	}
    }

    searchPtr->tag = uid = Tk_GetUid(tag);
    if (uid == Tk_GetUid("all")) {
	/*
	 * All items match.
	 */

	searchPtr->tag = NULL;
	searchPtr->lastPtr = NULL;
	searchPtr->currentPtr = canvasPtr->firstItemPtr;
	return canvasPtr->firstItemPtr;
    }

    /*
     * None of the above. Search for an item with a matching tag.
     */

    for (lastPtr = NULL, itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
	    lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) {
	for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
		count > 0; tagPtr++, count--) {
	    if (*tagPtr == uid) {
		searchPtr->lastPtr = lastPtr;
		searchPtr->currentPtr = itemPtr;
		return itemPtr;
	    }
	}
    }
    searchPtr->lastPtr = lastPtr;
    searchPtr->searchOver = 1;
    return NULL;
}

/*
 *--------------------------------------------------------------
 *
 * NextItem --
 *
 *	This function returns successive items that match a given tag; it
 *	should be called only after StartTagSearch has been used to begin a
 *	search.
 *
 * Results:
 *	The return value is a pointer to the next item that matches the tag
 *	specified to StartTagSearch, or NULL if no such item exists.
 *	*SearchPtr is updated so that the next call to this function will
 *	return the next item.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static Tk_Item *
NextItem(
    TagSearch *searchPtr)	/* Record describing search in progress. */
{
    Tk_Item *itemPtr, *lastPtr;
    int count;
    Tk_Uid uid;
    Tk_Uid *tagPtr;

    /*
     * Find next item in list (this may not actually be a suitable one to
     * return), and return if there are no items left.
     */

    lastPtr = searchPtr->lastPtr;
    if (lastPtr == NULL) {
	itemPtr = searchPtr->canvasPtr->firstItemPtr;
    } else {
	itemPtr = lastPtr->nextPtr;
    }
    if ((itemPtr == NULL) || (searchPtr->searchOver)) {
	searchPtr->searchOver = 1;
	return NULL;
    }
    if (itemPtr != searchPtr->currentPtr) {
	/*
	 * The structure of the list has changed. Probably the previously-
	 * returned item was removed from the list. In this case, don't
	 * advance lastPtr; just return its new successor (i.e. do nothing
	 * here).
	 */
    } else {
	lastPtr = itemPtr;
	itemPtr = lastPtr->nextPtr;
    }

    /*
     * Handle special case of "all" search by returning next item.
     */

    uid = searchPtr->tag;
    if (uid == NULL) {
	searchPtr->lastPtr = lastPtr;
	searchPtr->currentPtr = itemPtr;
	return itemPtr;
    }

    /*
     * Look for an item with a particular tag.
     */

    for ( ; itemPtr != NULL; lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) {
	for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
		count > 0; tagPtr++, count--) {
	    if (*tagPtr == uid) {
		searchPtr->lastPtr = lastPtr;
		searchPtr->currentPtr = itemPtr;
		return itemPtr;
	    }
	}
    }
    searchPtr->lastPtr = lastPtr;
    searchPtr->searchOver = 1;
    return NULL;
}

#else /* !USE_OLD_TAG_SEARCH */
/*
 *----------------------------------------------------------------------
 *
 * GetStaticUids --
 *
 *	This function is invoked to return a structure filled with the Uids
 *	used when doing tag searching. If it was never before called in the
3621
3622
3623
3624
3625
3626
3627
3628

3629
3630
3631
3632
3633
3634
3635
3265
3266
3267
3268
3269
3270
3271

3272
3273
3274
3275
3276
3277
3278
3279







-
+







 *
 *----------------------------------------------------------------------
 */

static SearchUids *
GetStaticUids(void)
{
    SearchUids *searchUids = (SearchUids *)
    SearchUids *searchUids =
	    Tcl_GetThreadData(&dataKey, sizeof(SearchUids));

    if (searchUids->allUid == NULL) {
	searchUids->allUid       = Tk_GetUid("all");
	searchUids->currentUid   = Tk_GetUid("current");
	searchUids->andUid       = Tk_GetUid("&&");
	searchUids->orUid        = Tk_GetUid("||");
3660
3661
3662
3663
3664
3665
3666
3667

3668
3669
3670
3671
3672
3673
3674
3304
3305
3306
3307
3308
3309
3310

3311
3312
3313
3314
3315
3316
3317
3318







-
+







static void
TagSearchExprInit(
    TagSearchExpr **exprPtrPtr)
{
    TagSearchExpr *expr = *exprPtrPtr;

    if (expr == NULL) {
	expr = (TagSearchExpr *)ckalloc(sizeof(TagSearchExpr));
	expr = ckalloc(sizeof(TagSearchExpr));
	expr->allocated = 0;
	expr->uids = NULL;
	expr->next = NULL;
    }
    expr->uid = NULL;
    expr->index = 0;
    expr->length = 0;
3741
3742
3743
3744
3745
3746
3747
3748

3749
3750
3751
3752
3753
3754
3755
3756

3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773

3774
3775
3776
3777
3778
3779
3780
3385
3386
3387
3388
3389
3390
3391

3392
3393
3394
3395
3396
3397
3398
3399

3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416

3417
3418
3419
3420
3421
3422
3423
3424







-
+







-
+
















-
+







    if (*searchPtrPtr != NULL) {
	searchPtr = *searchPtrPtr;
    } else {
	/*
	 * Allocate primary search struct on first call.
	 */

	*searchPtrPtr = searchPtr = (TagSearch *)ckalloc(sizeof(TagSearch));
	*searchPtrPtr = searchPtr = ckalloc(sizeof(TagSearch));
	searchPtr->expr = NULL;

	/*
	 * Allocate buffer for rewritten tags (after de-escaping).
	 */

	searchPtr->rewritebufferAllocated = 100;
	searchPtr->rewritebuffer = (char *)ckalloc(searchPtr->rewritebufferAllocated);
	searchPtr->rewritebuffer = ckalloc(searchPtr->rewritebufferAllocated);
    }
    TagSearchExprInit(&searchPtr->expr);

    /*
     * How long is the tagOrId?
     */

    searchPtr->stringLength = strlen(tag);

    /*
     * Make sure there is enough buffer to hold rewritten tags.
     */

    if ((unsigned) searchPtr->stringLength >=
	    searchPtr->rewritebufferAllocated) {
	searchPtr->rewritebufferAllocated = searchPtr->stringLength + 100;
	searchPtr->rewritebuffer = (char *)
	searchPtr->rewritebuffer =
		ckrealloc(searchPtr->rewritebuffer,
		searchPtr->rewritebufferAllocated);
    }

    /*
     * Initialize search.
     */
3949
3950
3951
3952
3953
3954
3955
3956

3957
3958
3959

3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974

3975
3976

3977
3978
3979
3980
3981
3982
3983
3593
3594
3595
3596
3597
3598
3599

3600
3601
3602

3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617

3618
3619

3620
3621
3622
3623
3624
3625
3626
3627







-
+


-
+














-
+

-
+







	/*
	 * Need two slots free at this point, not one. [Bug 2931374]
	 */

	if (expr->index >= expr->allocated-1) {
	    expr->allocated += 15;
	    if (expr->uids) {
		expr->uids = (Tk_Uid *)ckrealloc(expr->uids,
		expr->uids = ckrealloc(expr->uids,
			expr->allocated * sizeof(Tk_Uid));
	    } else {
		expr->uids = (Tk_Uid *)ckalloc(expr->allocated * sizeof(Tk_Uid));
		expr->uids = ckalloc(expr->allocated * sizeof(Tk_Uid));
	    }
	}

	if (looking_for_tag) {
	    switch (c) {
	    case ' ':		/* Ignore unquoted whitespace */
	    case '\t':
	    case '\n':
	    case '\r':
		break;

	    case '!':		/* Negate next tag or subexpr */
		if (looking_for_tag > 1) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "too many '!' in tag search expression", TCL_INDEX_NONE));
			    "too many '!' in tag search expression", -1));
		    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			    "COMPLEXITY", (char *)NULL);
			    "COMPLEXITY", NULL);
		    return TCL_ERROR;
		}
		looking_for_tag++;
		negate_result = 1;
		break;

	    case '(':		/* Scan (negated) subexpr recursively */
4017
4018
4019
4020
4021
4022
4023
4024

4025
4026

4027
4028
4029
4030
4031
4032

4033
4034

4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049

4050
4051

4052
4053
4054
4055
4056
4057
4058
3661
3662
3663
3664
3665
3666
3667

3668
3669

3670
3671
3672
3673
3674
3675

3676
3677

3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692

3693
3694

3695
3696
3697
3698
3699
3700
3701
3702







-
+

-
+





-
+

-
+














-
+

-
+







			found_endquote = 1;
			break;
		    }
		    *tag++ = c;
		}
		if (!found_endquote) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "missing endquote in tag search expression", TCL_INDEX_NONE));
			    "missing endquote in tag search expression", -1));
		    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			    "ENDQUOTE", (char *)NULL);
			    "ENDQUOTE", NULL);
		    return TCL_ERROR;
		}
		if (!(tag - searchPtr->rewritebuffer)) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "null quoted tag string in tag search expression",
			    TCL_INDEX_NONE));
			    -1));
		    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			    "EMPTY", (char *)NULL);
			    "EMPTY", NULL);
		    return TCL_ERROR;
		}
		*tag++ = '\0';
		expr->uids[expr->index++] =
			Tk_GetUid(searchPtr->rewritebuffer);
		looking_for_tag = 0;
		found_tag = 1;
		break;

	    case '&':		/* Illegal chars when looking for tag */
	    case '|':
	    case '^':
	    case ')':
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"unexpected operator in tag search expression", TCL_INDEX_NONE));
			"unexpected operator in tag search expression", -1));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			"UNEXPECTED", (char *)NULL);
			"UNEXPECTED", NULL);
		return TCL_ERROR;

	    default:		/* Unquoted tag string */
		if (negate_result) {
		    expr->uids[expr->index++] = searchUids->negtagvalUid;
		    negate_result = 0;
		} else {
4106
4107
4108
4109
4110
4111
4112
4113

4114
4115

4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126

4127
4128

4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147

4148
4149

4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161


4162
4163
4164
4165
4166
4167
4168
3750
3751
3752
3753
3754
3755
3756

3757
3758

3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769

3770
3771

3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790

3791
3792

3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803


3804
3805
3806
3807
3808
3809
3810
3811
3812







-
+

-
+










-
+

-
+


















-
+

-
+










-
-
+
+







	    case '\r':
		break;

	    case '&':		/* AND operator */
		c = searchPtr->string[searchPtr->stringIndex++];
		if (c != '&') {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "singleton '&' in tag search expression", TCL_INDEX_NONE));
			    "singleton '&' in tag search expression", -1));
		    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			    "INCOMPLETE_OP", (char *)NULL);
			    "INCOMPLETE_OP", NULL);
		    return TCL_ERROR;
		}
		expr->uids[expr->index++] = searchUids->andUid;
		looking_for_tag = 1;
		break;

	    case '|':		/* OR operator */
		c = searchPtr->string[searchPtr->stringIndex++];
		if (c != '|') {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "singleton '|' in tag search expression", TCL_INDEX_NONE));
			    "singleton '|' in tag search expression", -1));
		    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH",
			    "INCOMPLETE_OP", (char *)NULL);
			    "INCOMPLETE_OP", NULL);
		    return TCL_ERROR;
		}
		expr->uids[expr->index++] = searchUids->orUid;
		looking_for_tag = 1;
		break;

	    case '^':		/* XOR operator */
		expr->uids[expr->index++] = searchUids->xorUid;
		looking_for_tag = 1;
		break;

	    case ')':		/* End subexpression */
		expr->uids[expr->index++] = searchUids->endparenUid;
		goto breakwhile;

	    default:		/* syntax error */
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"invalid boolean operator in tag search expression",
			TCL_INDEX_NONE));
			-1));
		Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH", "BAD_OP",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	}
    }

  breakwhile:
    if (found_tag && !looking_for_tag) {
	return TCL_OK;
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    "missing tag in tag search expression", TCL_INDEX_NONE));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH", "NO_TAG", (char *)NULL);
	    "missing tag in tag search expression", -1));
    Tcl_SetErrorCode(interp, "TK", "CANVAS", "SEARCH", "NO_TAG", NULL);
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * TagSearchEvalExpr --
4209
4210
4211
4212
4213
4214
4215
4216

4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236

4237
4238
4239
4240
4241
4242
4243
3853
3854
3855
3856
3857
3858
3859

3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879

3880
3881
3882
3883
3884
3885
3886
3887







-
+



















-
+







		uid = expr->uids[expr->index++];
		result = 0;

		/*
		 * set result 1 if tag is found in item's tags
		 */

		for (tagPtr = itemPtr->tagPtr, count = (int)itemPtr->numTags;
		for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
			count > 0; tagPtr++, count--) {
		    if (*tagPtr == uid) {
			result = 1;
			break;
		    }
		}

	    } else if (uid == searchUids->negtagvalUid) {
		negate_result = ! negate_result;
/*
 *		assert(expr->index < expr->length);
 */
		uid = expr->uids[expr->index++];
		result = 0;

		/*
		 * set result 1 if tag is found in item's tags.
		 */

		for (tagPtr = itemPtr->tagPtr, count = (int)itemPtr->numTags;
		for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
			count > 0; tagPtr++, count--) {
		    if (*tagPtr == uid) {
			result = 1;
			break;
		    }
		}

4362
4363
4364
4365
4366
4367
4368
4369

4370
4371

4372
4373
4374
4375
4376
4377
4378
4006
4007
4008
4009
4010
4011
4012

4013
4014

4015
4016
4017
4018
4019
4020
4021
4022







-
+

-
+







	Tcl_HashEntry *entryPtr;

	itemPtr = searchPtr->canvasPtr->hotPtr;
	lastPtr = searchPtr->canvasPtr->hotPrevPtr;
	if ((itemPtr == NULL) || (itemPtr->id != searchPtr->id)
		|| (lastPtr == NULL) || (lastPtr->nextPtr != itemPtr)) {
	    entryPtr = Tcl_FindHashEntry(&searchPtr->canvasPtr->idTable,
		    INT2PTR(searchPtr->id));
		    (char *) INT2PTR(searchPtr->id));
	    if (entryPtr != NULL) {
		itemPtr = (Tk_Item *)Tcl_GetHashValue(entryPtr);
		itemPtr = Tcl_GetHashValue(entryPtr);
		lastPtr = itemPtr->prevPtr;
	    } else {
		lastPtr = itemPtr = NULL;
	    }
	}
	searchPtr->lastPtr = lastPtr;
	searchPtr->searchOver = 1;
4395
4396
4397
4398
4399
4400
4401
4402

4403
4404
4405
4406
4407
4408
4409
4039
4040
4041
4042
4043
4044
4045

4046
4047
4048
4049
4050
4051
4052
4053







-
+







	/*
	 * Optimized single-tag search
	 */

	uid = searchPtr->expr->uid;
	for (lastPtr = NULL, itemPtr = searchPtr->canvasPtr->firstItemPtr;
		itemPtr != NULL; lastPtr=itemPtr, itemPtr=itemPtr->nextPtr) {
	    for (tagPtr = itemPtr->tagPtr, count = (int)itemPtr->numTags;
	    for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
		    count > 0; tagPtr++, count--) {
		if (*tagPtr == uid) {
		    searchPtr->lastPtr = lastPtr;
		    searchPtr->currentPtr = itemPtr;
		    return itemPtr;
		}
	    }
4497
4498
4499
4500
4501
4502
4503
4504

4505
4506
4507
4508
4509
4510
4511
4141
4142
4143
4144
4145
4146
4147

4148
4149
4150
4151
4152
4153
4154
4155







-
+







    if (searchPtr->type == SEARCH_TYPE_TAG) {
	/*
	 * Optimized single-tag search
	 */

	uid = searchPtr->expr->uid;
	for (; itemPtr != NULL; lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) {
	    for (tagPtr = itemPtr->tagPtr, count = (int)itemPtr->numTags;
	    for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
		    count > 0; tagPtr++, count--) {
		if (*tagPtr == uid) {
		    searchPtr->lastPtr = lastPtr;
		    searchPtr->currentPtr = itemPtr;
		    return itemPtr;
		}
	    }
4527
4528
4529
4530
4531
4532
4533

4534
4535
4536
4537
4538
4539
4540
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185







+







	    return itemPtr;
	}
    }
    searchPtr->lastPtr = lastPtr;
    searchPtr->searchOver = 1;
    return NULL;
}
#endif /* USE_OLD_TAG_SEARCH */

/*
 *--------------------------------------------------------------
 *
 * DoItem --
 *
 *	This is a utility function called by FindItems. It either adds
4563
4564
4565
4566
4567
4568
4569
4570

4571
4572
4573
4574

4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590


4591
4592
4593
4594
4595
4596
4597
4208
4209
4210
4211
4212
4213
4214

4215
4216
4217
4218

4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233


4234
4235
4236
4237
4238
4239
4240
4241
4242







-
+



-
+














-
-
+
+







    int count;

    /*
     * Handle the "add-to-result" case and return, if appropriate.
     */

    if (tag == NULL) {
	Tcl_ListObjAppendElement(NULL, accumObj, Tcl_NewWideIntObj(itemPtr->id));
	Tcl_ListObjAppendElement(NULL, accumObj, Tcl_NewIntObj(itemPtr->id));
	return;
    }

    for (tagPtr = itemPtr->tagPtr, count = (int)itemPtr->numTags;
    for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags;
	    count > 0; tagPtr++, count--) {
	if (tag == *tagPtr) {
	    return;
	}
    }

    /*
     * Grow the tag space if there's no more room left in the current block.
     */

    if (itemPtr->tagSpace == itemPtr->numTags) {
	Tk_Uid *newTagPtr;

	itemPtr->tagSpace += 5;
	newTagPtr = (Tk_Uid *)ckalloc(itemPtr->tagSpace * sizeof(Tk_Uid));
	memcpy(newTagPtr, itemPtr->tagPtr,
	newTagPtr = ckalloc(itemPtr->tagSpace * sizeof(Tk_Uid));
	memcpy((void *) newTagPtr, itemPtr->tagPtr,
		itemPtr->numTags * sizeof(Tk_Uid));
	if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
	    ckfree(itemPtr->tagPtr);
	}
	itemPtr->tagPtr = newTagPtr;
	tagPtr = &itemPtr->tagPtr[itemPtr->numTags];
    }
4627
4628
4629
4630
4631
4632
4633
4634

4635
4636
4637
4638
4639
4640
4641
4642
4643

4644
4645

4646

4647
4648



4649
4650
4651
4652
4653
4654
4655
4272
4273
4274
4275
4276
4277
4278

4279
4280
4281
4282
4283
4284
4285
4286
4287

4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305







-
+








-
+


+

+


+
+
+







 *--------------------------------------------------------------
 */

static int
FindItems(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    TkCanvas *canvasPtr,	/* Canvas whose items are to be searched. */
    Tcl_Size objc,			/* Number of entries in argv. Must be greater
    int objc,			/* Number of entries in argv. Must be greater
				 * than zero. */
    Tcl_Obj *const *objv,	/* Arguments that describe what items to
				 * search for (see user doc on "find" and
				 * "addtag" options). */
    Tcl_Obj *newTag,		/* If non-NULL, gives new tag to set on all
				 * found items; if NULL, then ids of found
				 * items are returned in the interp's
				 * result. */
    Tcl_Size first			/* For error messages: gives number of
    int first			/* For error messages: gives number of
				 * elements of objv which are already
				 * handled. */
#ifndef USE_OLD_TAG_SEARCH
    ,TagSearch **searchPtrPtr	/* From CanvasWidgetCmd local vars*/
#endif /* not USE_OLD_TAG_SEARCH */
    )
{
#ifdef USE_OLD_TAG_SEARCH
    TagSearch search;
#endif /* USE_OLD_TAG_SEARCH */
    Tk_Item *itemPtr;
    Tk_Uid uid;
    int index, result;
    Tcl_Obj *resultObj;
    static const char *const optionStrings[] = {
	"above", "all", "below", "closest",
	"enclosed", "overlapping", "withtag", NULL
4958
4959
4960
4961
4962
4963
4964










4965
4966
4967
4968
4969
4970
4971
4972
4973

4974
4975



4976
4977
4978
4979
4980
4981
4982
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646







+
+
+
+
+
+
+
+
+
+









+


+
+
+







 *	The items identified by "tag" are moved so that they are all together
 *	in the display list and immediately after prevPtr. The order of the
 *	moved items relative to each other is not changed.
 *
 *--------------------------------------------------------------
 */

#ifdef USE_OLD_TAG_SEARCH
static void
RelinkItems(
    TkCanvas *canvasPtr,	/* Canvas to be modified. */
    Tcl_Obj *tag,		/* Tag identifying items to be moved in the
				 * redisplay list. */
    Tk_Item *prevPtr)		/* Reposition the items so that they go just
				 * after this item (NULL means put at
				 * beginning of list). */
#else /* USE_OLD_TAG_SEARCH */
static int
RelinkItems(
    TkCanvas *canvasPtr,	/* Canvas to be modified. */
    Tcl_Obj *tag,		/* Tag identifying items to be moved in the
				 * redisplay list. */
    Tk_Item *prevPtr,		/* Reposition the items so that they go just
				 * after this item (NULL means put at
				 * beginning of list). */
    TagSearch **searchPtrPtr)	/* From CanvasWidgetCmd local vars */
#endif /* USE_OLD_TAG_SEARCH */
{
    Tk_Item *itemPtr;
#ifdef USE_OLD_TAG_SEARCH
    TagSearch search;
#endif /* USE_OLD_TAG_SEARCH */
    Tk_Item *firstMovePtr, *lastMovePtr;
    int result;

    /*
     * Find all of the items to be moved and remove them from the list, making
     * an auxiliary list running from firstMovePtr to lastMovePtr. Record
     * their areas for redisplay.
5020
5021
5022
5023
5024
5025
5026



5027

5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047

5048

5049
5050
5051
5052
5053
5054
5055
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725







+
+
+

+




















+

+








    /*
     * Insert the list of to-be-moved items back into the canvas's at the
     * desired position.
     */

    if (firstMovePtr == NULL) {
#ifdef USE_OLD_TAG_SEARCH
	return;
#else /* USE_OLD_TAG_SEARCH */
	return TCL_OK;
#endif /* USE_OLD_TAG_SEARCH */
    }
    if (prevPtr == NULL) {
	if (canvasPtr->firstItemPtr != NULL) {
	    canvasPtr->firstItemPtr->prevPtr = lastMovePtr;
	}
	lastMovePtr->nextPtr = canvasPtr->firstItemPtr;
	canvasPtr->firstItemPtr = firstMovePtr;
    } else {
	if (prevPtr->nextPtr != NULL) {
	    prevPtr->nextPtr->prevPtr = lastMovePtr;
	}
	lastMovePtr->nextPtr = prevPtr->nextPtr;
	if (firstMovePtr != NULL) {
	    firstMovePtr->prevPtr = prevPtr;
	}
	prevPtr->nextPtr = firstMovePtr;
    }
    if (canvasPtr->lastItemPtr == prevPtr) {
	canvasPtr->lastItemPtr = lastMovePtr;
    }
#ifndef USE_OLD_TAG_SEARCH
    return TCL_OK;
#endif /* not USE_OLD_TAG_SEARCH */
}

/*
 *--------------------------------------------------------------
 *
 * CanvasBindProc --
 *
5064
5065
5066
5067
5068
5069
5070
5071

5072
5073
5074
5075


5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088




















5089
5090
5091
5092
5093
5094
5095
4734
4735
4736
4737
4738
4739
4740

4741
4742
4743


4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757

4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784







-
+


-
-
+
+












-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	any).
 *
 *--------------------------------------------------------------
 */

static void
CanvasBindProc(
    void *clientData,	/* Pointer to canvas structure. */
    ClientData clientData,	/* Pointer to canvas structure. */
    XEvent *eventPtr)		/* Pointer to X event that just happened. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    unsigned mask;
    TkCanvas *canvasPtr = clientData;
    int mask;

    Tcl_Preserve(canvasPtr);

    /*
     * This code below keeps track of the current modifier state in
     * canvasPtr>state. This information is used to defer repicks of the
     * current item while buttons are down.
     */

    switch (eventPtr->type) {
    case ButtonPress:
    case ButtonRelease:
	mask = Tk_GetButtonMask(eventPtr->xbutton.button);
	switch (eventPtr->xbutton.button) {
	case Button1:
	    mask = Button1Mask;
	    break;
	case Button2:
	    mask = Button2Mask;
	    break;
	case Button3:
	    mask = Button3Mask;
	    break;
	case Button4:
	    mask = Button4Mask;
	    break;
	case Button5:
	    mask = Button5Mask;
	    break;
	default:
	    mask = 0;
	    break;
	}

	/*
	 * For button press events, repick the current item using the button
	 * state before the event, then process the event. For button release
	 * events, first process the event, then repick the current item using
	 * the button state *after* the event (the button has logically gone
	 * up before we change the current item).
5164
5165
5166
5167
5168
5169
5170
5171

5172

5173

5174
5175
5176
5177
5178
5179
5180
5181
5182


5183
5184
5185
5186
5187
5188
5189
4853
4854
4855
4856
4857
4858
4859

4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872

4873
4874
4875
4876
4877
4878
4879
4880
4881







-
+

+

+








-
+
+







    TkCanvas *canvasPtr,	/* Canvas widget in which to select current
				 * item. */
    XEvent *eventPtr)		/* Event describing location of mouse cursor.
				 * Must be EnterWindow, LeaveWindow,
				 * ButtonRelease, or MotionNotify. */
{
    double coords[2];
    unsigned int buttonDown;
    int buttonDown;
    Tk_Item *prevItemPtr;
#ifndef USE_OLD_TAG_SEARCH
    SearchUids *searchUids = GetStaticUids();
#endif

    /*
     * Check whether or not a button is down. If so, we'll log entry and exit
     * into and out of the current item, but not entry into any other item.
     * This implements a form of grabbing equivalent to what the X server does
     * for windows.
     */

    buttonDown = canvasPtr->state & ALL_BUTTONS;
    buttonDown = canvasPtr->state
	    & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask);

    /*
     * Save information about this event in the canvas. The event in the
     * canvas is used for two purposes:
     *
     * 1. Event bindings: if the current item changes, fake events are
     *    generated to allow item-enter and item-leave bindings to trigger.
5265
5266
5267
5268
5269
5270
5271
5272

5273
5274
5275
5276
5277
5278
5279
5280
5281



5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302




5303

5304
5305
5306

5307
5308
5309
5310
5311
5312
5313
5314
4957
4958
4959
4960
4961
4962
4963

4964
4965
4966
4967
4968
4969




4970
4971
4972







4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985

4986
4987
4988
4989
4990
4991
4992


4993

4994
4995
4996
4997
4998
4999
5000







-
+





-
-
-
-
+
+
+
-
-
-
-
-
-
-













-
+
+
+
+

+

-
-
+
-







     */

    if ((canvasPtr->newCurrentPtr != canvasPtr->currentItemPtr)
	    && (canvasPtr->currentItemPtr != NULL)
	    && !(canvasPtr->flags & LEFT_GRABBED_ITEM)) {
	XEvent event;
	Tk_Item *itemPtr = canvasPtr->currentItemPtr;
	Tcl_Size i;
	int i;

	event = canvasPtr->pickEvent;
	event.type = LeaveNotify;

	/*
	 * Behaviour before ticket #47d4f29159:
	 *    If the event's detail happens to be NotifyInferior the binding
	 *    mechanism will discard the event. To be consistent, always use
	 *    NotifyAncestor.
	 * If the event's detail happens to be NotifyInferior the binding
	 * mechanism will discard the event. To be consistent, always use
	 * NotifyAncestor.
	 *
	 * Behaviour after ticket #47d4f29159:
	 *    The binding mechanism doesn't discard events with detail field
	 *    NotifyInferior anymore. It would be best to base the detail
	 *    field on the ancestry relationship between the old and new
	 *    canvas items. For the time being, retain the choice from before
	 *    ticket #47d4f29159, which doesn't harm.
	 */

	event.xcrossing.detail = NotifyAncestor;
	canvasPtr->flags |= REPICK_IN_PROGRESS;
	CanvasDoEvent(canvasPtr, &event);
	canvasPtr->flags &= ~REPICK_IN_PROGRESS;

	/*
	 * The check below is needed because there could be an event handler
	 * for <LeaveNotify> that deletes the current item.
	 */

	if ((itemPtr == canvasPtr->currentItemPtr) && !buttonDown) {
	    for (i = itemPtr->numTags-1; i != TCL_INDEX_NONE; i--) {
	    for (i = itemPtr->numTags-1; i >= 0; i--) {
#ifdef USE_OLD_TAG_SEARCH
		if (itemPtr->tagPtr[i] == Tk_GetUid("current"))
#else /* USE_OLD_TAG_SEARCH */
		if (itemPtr->tagPtr[i] == searchUids->currentUid)
#endif /* USE_OLD_TAG_SEARCH */
		    /* then */ {
                    memmove((void *)(itemPtr->tagPtr + i),
                            itemPtr->tagPtr + i + 1,
		    itemPtr->tagPtr[i] = itemPtr->tagPtr[itemPtr->numTags-1];
                            (itemPtr->numTags - (i+1)) * sizeof(Tk_Uid));
		    itemPtr->numTags--;
		    break;
		}
	    }
	}

	/*
5335
5336
5337
5338
5339
5340
5341



5342

5343
5344
5345
5346
5347
5348
5349
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039







+
+
+

+







	    (prevItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT)) {
	EventuallyRedrawItem(canvasPtr, prevItemPtr);
	ItemConfigure(canvasPtr, prevItemPtr, 0, NULL);
    }
    if (canvasPtr->currentItemPtr != NULL) {
	XEvent event;

#ifdef USE_OLD_TAG_SEARCH
	DoItem(NULL, canvasPtr->currentItemPtr, Tk_GetUid("current"));
#else /* USE_OLD_TAG_SEARCH */
	DoItem(NULL, canvasPtr->currentItemPtr, searchUids->currentUid);
#endif /* USE_OLD_TAG_SEARCH */
	if ((canvasPtr->currentItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT
		&& prevItemPtr != canvasPtr->currentItemPtr)) {
	    ItemConfigure(canvasPtr, canvasPtr->currentItemPtr, 0, NULL);
	    EventuallyRedrawItem(canvasPtr, canvasPtr->currentItemPtr);
	}
	event = canvasPtr->pickEvent;
	event.type = EnterNotify;
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438



5439

5440
5441

5442

5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455










5456
5457
5458
5459
5460
5461
5462
5119
5120
5121
5122
5123
5124
5125



5126
5127
5128
5129
5130
5131

5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164







-
-
-
+
+
+

+

-
+

+













+
+
+
+
+
+
+
+
+
+







static void
CanvasDoEvent(
    TkCanvas *canvasPtr,	/* Canvas widget in which event occurred. */
    XEvent *eventPtr)		/* Real or simulated X event that is to be
				 * processed. */
{
#define NUM_STATIC 3
    void *staticObjects[NUM_STATIC];
    void **objectPtr;
    Tcl_Size numObjects, i;
    ClientData staticObjects[NUM_STATIC];
    ClientData *objectPtr;
    int numObjects, i;
    Tk_Item *itemPtr;
#ifndef USE_OLD_TAG_SEARCH
    TagSearchExpr *expr;
    Tcl_Size numExprs;
    int numExprs;
    SearchUids *searchUids = GetStaticUids();
#endif /* not USE_OLD_TAG_SEARCH */

    if (canvasPtr->bindingTable == NULL) {
	return;
    }

    itemPtr = canvasPtr->currentItemPtr;
    if ((eventPtr->type == KeyPress) || (eventPtr->type == KeyRelease)) {
	itemPtr = canvasPtr->textInfo.focusItemPtr;
    }
    if (itemPtr == NULL) {
	return;
    }

#ifdef USE_OLD_TAG_SEARCH
    /*
     * Set up an array with all the relevant objects for processing this
     * event. The relevant objects are (a) the event's item, (b) the tags
     * associated with the event's item, and (c) the tag "all". If there are a
     * lot of tags then malloc an array to hold all of the objects.
     */

    numObjects = itemPtr->numTags + 2;
#else /* USE_OLD_TAG_SEARCH */
    /*
     * Set up an array with all the relevant objects for processing this
     * event. The relevant objects are:
     * (a) the event's item,
     * (b) the tags associated with the event's item,
     * (c) the expressions that are true for the event's item's tags, and
     * (d) the tag "all".
5477
5478
5479
5480
5481
5482
5483

5484
5485
5486
5487

5488



5489
5490
5491




5492
5493

5494

5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506

5507
5508
5509
5510
5511
5512
5513
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189

5190
5191
5192
5193
5194



5195
5196
5197
5198
5199

5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222







+



-
+

+
+
+
-
-
-
+
+
+
+

-
+

+












+







	if (expr->match) {
	    numExprs++;
	}
	expr = expr->next;
    }

    numObjects = itemPtr->numTags + numExprs + 2;
#endif /* not USE_OLD_TAG_SEARCH */
    if (numObjects <= NUM_STATIC) {
	objectPtr = staticObjects;
    } else {
	objectPtr = (void **)ckalloc(numObjects * sizeof(void *));
	objectPtr = ckalloc(numObjects * sizeof(ClientData));
    }
#ifdef USE_OLD_TAG_SEARCH
    objectPtr[0] = (ClientData) Tk_GetUid("all");
#else /* USE_OLD_TAG_SEARCH */
    objectPtr[0] = (char *)searchUids->allUid;
    for (i = itemPtr->numTags - 1; i != TCL_INDEX_NONE; i--) {
	objectPtr[i+1] = (char *)itemPtr->tagPtr[i];
    objectPtr[0] = (ClientData) searchUids->allUid;
#endif /* USE_OLD_TAG_SEARCH */
    for (i = itemPtr->numTags-1; i >= 0; i--) {
	objectPtr[i+1] = (ClientData) itemPtr->tagPtr[i];
    }
    objectPtr[itemPtr->numTags + 1] = itemPtr;
    objectPtr[itemPtr->numTags+1] = itemPtr;

#ifndef USE_OLD_TAG_SEARCH
    /*
     * Copy uids of matching expressions into object array
     */

    i = itemPtr->numTags+2;
    expr = canvasPtr->bindTagExprs;
    while (expr) {
    	if (expr->match) {
	    objectPtr[i++] = (int *) expr->uid;
	}
	expr = expr->next;
    }
#endif /* not USE_OLD_TAG_SEARCH */

    /*
     * Invoke the binding system, then free up the object array if it was
     * malloc-ed.
     */

    if (canvasPtr->tkwin != NULL) {
5535
5536
5537
5538
5539
5540
5541
5542

5543
5544

5545
5546
5547
5548
5549
5550
5551
5244
5245
5246
5247
5248
5249
5250

5251
5252

5253
5254
5255
5256
5257
5258
5259
5260







-
+

-
+







 *	function reschedules itself.
 *
 *----------------------------------------------------------------------
 */

static void
CanvasBlinkProc(
    void *clientData)	/* Pointer to record describing entry. */
    ClientData clientData)	/* Pointer to record describing entry. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;

    if (!canvasPtr->textInfo.gotFocus || (canvasPtr->insertOffTime == 0)) {
	return;
    }
    if (canvasPtr->textInfo.cursorOn) {
	canvasPtr->textInfo.cursorOn = 0;
	canvasPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
5589
5590
5591
5592
5593
5594
5595
5596

5597
5598
5599
5600
5601
5602
5603
5298
5299
5300
5301
5302
5303
5304

5305
5306
5307
5308
5309
5310
5311
5312







-
+







	if (canvasPtr->insertOffTime != 0) {
	    canvasPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
		    canvasPtr->insertOffTime, CanvasBlinkProc, canvasPtr);
	}
    } else {
	canvasPtr->textInfo.gotFocus = 0;
	canvasPtr->textInfo.cursorOn = 0;
	canvasPtr->insertBlinkHandler = NULL;
	canvasPtr->insertBlinkHandler = (Tcl_TimerToken) NULL;
    }
    EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.focusItemPtr);
    if (canvasPtr->highlightWidth > 0) {
	canvasPtr->flags |= REDRAW_BORDERS;
	if (!(canvasPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayCanvas, canvasPtr);
	    canvasPtr->flags |= REDRAW_PENDING;
5622
5623
5624
5625
5626
5627
5628
5629

5630
5631
5632

5633
5634
5635
5636
5637
5638
5639
5331
5332
5333
5334
5335
5336
5337

5338
5339
5340

5341
5342
5343
5344
5345
5346
5347
5348







-
+


-
+







 *----------------------------------------------------------------------
 */

static void
CanvasSelectTo(
    TkCanvas *canvasPtr,	/* Information about widget. */
    Tk_Item *itemPtr,		/* Item that is to hold selection. */
    Tcl_Size index)			/* Index of element that is to become the
    int index)			/* Index of element that is to become the
				 * "other" end of the selection. */
{
    Tcl_Size oldFirst, oldLast;
    int oldFirst, oldLast;
    Tk_Item *oldSelPtr;

    oldFirst = canvasPtr->textInfo.selectFirst;
    oldLast = canvasPtr->textInfo.selectLast;
    oldSelPtr = canvasPtr->textInfo.selItemPtr;

    /*
5652
5653
5654
5655
5656
5657
5658
5659

5660
5661
5662
5663
5664
5665
5666
5361
5362
5363
5364
5365
5366
5367

5368
5369
5370
5371
5372
5373
5374
5375







-
+







	canvasPtr->textInfo.anchorItemPtr = itemPtr;
	canvasPtr->textInfo.selectAnchor = index;
    }
    if (canvasPtr->textInfo.selectAnchor <= index) {
	canvasPtr->textInfo.selectFirst = canvasPtr->textInfo.selectAnchor;
	canvasPtr->textInfo.selectLast = index;
    } else {
	canvasPtr->textInfo.selectFirst = ((int)index < 0) ? TCL_INDEX_NONE : index;
	canvasPtr->textInfo.selectFirst = index;
	canvasPtr->textInfo.selectLast = canvasPtr->textInfo.selectAnchor - 1;
    }
    if ((canvasPtr->textInfo.selectFirst != oldFirst)
	    || (canvasPtr->textInfo.selectLast != oldLast)
	    || (itemPtr != oldSelPtr)) {
	EventuallyRedrawItem(canvasPtr, itemPtr);
    }
5683
5684
5685
5686
5687
5688
5689
5690

5691
5692
5693


5694
5695
5696

5697
5698
5699
5700

5701
5702
5703
5704
5705
5706
5707
5392
5393
5394
5395
5396
5397
5398

5399
5400


5401
5402
5403
5404

5405
5406
5407
5408

5409
5410
5411
5412
5413
5414
5415
5416







-
+

-
-
+
+


-
+



-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static Tcl_Size
static int
CanvasFetchSelection(
    void *clientData,	/* Information about canvas widget. */
    Tcl_Size offset,			/* Offset within selection of first character
    ClientData clientData,	/* Information about canvas widget. */
    int offset,			/* Offset within selection of first character
				 * to be returned. */
    char *buffer,		/* Location in which to place selection. */
    Tcl_Size maxBytes)		/* Maximum number of bytes to place at buffer,
    int maxBytes)		/* Maximum number of bytes to place at buffer,
				 * not including terminating NULL
				 * character. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;

    return ItemSelection(canvasPtr, canvasPtr->textInfo.selItemPtr, offset,
	    buffer, maxBytes);
}

/*
 *----------------------------------------------------------------------
5719
5720
5721
5722
5723
5724
5725
5726

5727
5728

5729
5730
5731
5732
5733
5734
5735
5428
5429
5430
5431
5432
5433
5434

5435
5436

5437
5438
5439
5440
5441
5442
5443
5444







-
+

-
+







 *	not containing a selection.
 *
 *----------------------------------------------------------------------
 */

static void
CanvasLostSelection(
    void *clientData)	/* Information about entry widget. */
    ClientData clientData)	/* Information about entry widget. */
{
    TkCanvas *canvasPtr = (TkCanvas *)clientData;
    TkCanvas *canvasPtr = clientData;

    EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.selItemPtr);
    canvasPtr->textInfo.selItemPtr = NULL;
}

/*
 *--------------------------------------------------------------
5843
5844
5845
5846
5847
5848
5849
5850
5851


5852
5853
5854
5855
5856
5857
5858
5552
5553
5554
5555
5556
5557
5558


5559
5560
5561
5562
5563
5564
5565
5566
5567







-
-
+
+







    Tcl_Interp *interp;
    int xOrigin, yOrigin, inset, width, height;
    int scrollX1, scrollX2, scrollY1, scrollY2;
    char *xScrollCmd, *yScrollCmd;
    Tcl_DString buf;

    /*
     * Preserve the relevant values from the canvasPtr, because it might be
     * deleted as part of either of the two calls to Tcl_EvalEx below.
     * Save all the relevant values from the canvasPtr, because it might be
     * deleted as part of either of the two calls to Tcl_VarEval below.
     */

    interp = canvasPtr->interp;
    Tcl_Preserve(interp);
    xScrollCmd = canvasPtr->xScrollCmd;
    if (xScrollCmd != NULL) {
	Tcl_Preserve(xScrollCmd);
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882




5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900




5901
5902
5903
5904
5905
5906
5907
5581
5582
5583
5584
5585
5586
5587




5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605




5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616







-
-
-
-
+
+
+
+














-
-
-
-
+
+
+
+







    scrollY2 = canvasPtr->scrollY2;
    canvasPtr->flags &= ~UPDATE_SCROLLBARS;
    if (canvasPtr->xScrollCmd != NULL) {
	Tcl_Obj *fractions = ScrollFractions(xOrigin + inset,
		xOrigin + width - inset, scrollX1, scrollX2);

	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, xScrollCmd, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, Tcl_GetString(fractions), TCL_INDEX_NONE);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, xScrollCmd, -1);
	Tcl_DStringAppend(&buf, " ", -1);
	Tcl_DStringAppend(&buf, Tcl_GetString(fractions), -1);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	Tcl_DecrRefCount(fractions);
	if (result != TCL_OK) {
	    Tcl_BackgroundException(interp, result);
	}
	Tcl_ResetResult(interp);
	Tcl_Release(xScrollCmd);
    }

    if (yScrollCmd != NULL) {
	Tcl_Obj *fractions = ScrollFractions(yOrigin + inset,
		yOrigin + height - inset, scrollY1, scrollY2);

	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, yScrollCmd, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, Tcl_GetString(fractions), TCL_INDEX_NONE);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, yScrollCmd, -1);
	Tcl_DStringAppend(&buf, " ", -1);
	Tcl_DStringAppend(&buf, Tcl_GetString(fractions), -1);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	Tcl_DecrRefCount(fractions);
	if (result != TCL_OK) {
	    Tcl_BackgroundException(interp, result);
	}
	Tcl_ResetResult(interp);
	Tcl_Release(yScrollCmd);
6034
6035
6036
6037
6038
6039
6040
6041




































6042
6043
6044
6045
6046
6047
6048
5743
5744
5745
5746
5747
5748
5749

5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    canvasPtr->yOrigin = yOrigin;
    canvasPtr->flags |= UPDATE_SCROLLBARS;
    Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
	    canvasPtr->xOrigin, canvasPtr->yOrigin,
	    canvasPtr->xOrigin + Tk_Width(canvasPtr->tkwin),
	    canvasPtr->yOrigin + Tk_Height(canvasPtr->tkwin));
}


/*
 *----------------------------------------------------------------------
 *
 * TkGetStringsFromObjs --
 *
 * Results:
 *	Converts object list into string list.
 *
 * Side effects:
 *	Memory is allocated for the objv array, which must be freed using
 *	ckfree() when no longer needed.
 *
 *----------------------------------------------------------------------
 */

/* ARGSUSED */
static const char **
TkGetStringsFromObjs(
    int objc,
    Tcl_Obj *const objv[])
{
    register int i;
    const char **argv;

    if (objc <= 0) {
	return NULL;
    }
    argv = ckalloc((objc+1) * sizeof(char *));
    for (i = 0; i < objc; i++) {
	argv[i] = Tcl_GetString(objv[i]);
    }
    argv[objc] = 0;
    return argv;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_CanvasPsColor --
 *
 *	This function is called by individual canvas items when they want to
 *	set a color value for output. Given information about an X color, this
6217
6218
6219
6220
6221
6222
6223
6224

6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
5961
5962
5963
5964
5965
5966
5967

5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979







-
+











Tk_CanvasPsPath(
    Tcl_Interp *interp,		/* Put generated Postscript in this
				 * interpreter's result field. */
    Tk_Canvas canvas,		/* Canvas on whose behalf Postscript is being
				 * generated. */
    double *coordPtr,		/* Pointer to first in array of 2*numPoints
				 * coordinates giving points for path. */
    Tcl_Size numPoints)		/* Number of points at *coordPtr. */
    int numPoints)		/* Number of points at *coordPtr. */
{
    Tk_PostscriptPath(interp, Canvas(canvas)->psInfo, coordPtr, numPoints);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCanvas.h.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







/*
 * tkCanvas.h --
 *
 *	Declarations shared among all the files that implement canvas widgets.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1995 Sun Microsystems, Inc.
 * Copyright © 1998 Scriptics Corporation.
 * Copyright (c) 1991-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1998 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKCANVAS
#define _TKCANVAS
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157







-
+







				 * of the previous current item. */
    double closeEnough;		/* The mouse is assumed to be inside an item
				 * if it is this close to it. */
    XEvent pickEvent;		/* The event upon which the current choice of
				 * currentItem is based. Must be saved so that
				 * if the currentItem is deleted, can pick
				 * another. */
    unsigned int state;		/* Last known modifier state. Used to defer
    int state;			/* Last known modifier state. Used to defer
				 * picking a new current object while buttons
				 * are down. */

    /*
     * Information used for managing scrollbars:
     */

202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224







-
+







-
+







				 * a hint and may not really be hotPtr's
				 * predecessor. */

    /*
     * Miscellaneous information:
     */

    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    char *takeFocus;		/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    double pixelsPerMM;		/* Scale factor between MM and pixels; used
				 * when converting coordinates. */
    int flags;			/* Various flags; see below for
				 * definitions. */
    Tcl_Size nextId;			/* Number to use as id for next item created
    int nextId;			/* Number to use as id for next item created
				 * in widget. */
    Tk_PostscriptInfo psInfo;	/* Pointer to information used for generating
				 * Postscript for the canvas. NULL means no
				 * Postscript is currently being generated. */
    Tcl_HashTable idTable;	/* Table of integer indices. */

    /*
286
287
288
289
290
291
292
293
294


295
296
297
298
299
300
301
286
287
288
289
290
291
292


293
294
295
296
297
298
299
300
301







-
-
+
+







#define FORCE_REDRAW		8

/*
 * Canvas-related functions that are shared among Tk modules but not exported
 * to the outside world:
 */

MODULE_SCOPE int	TkCanvPostscriptObjCmd(TkCanvas *canvasPtr,
			    Tcl_Interp *interp, Tcl_Size argc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkCanvPostscriptCmd(TkCanvas *canvasPtr,
			    Tcl_Interp *interp, int argc, const char **argv);
MODULE_SCOPE int 	TkCanvTranslatePath(TkCanvas *canvPtr,
			    int numVertex, double *coordPtr, int closed,
			    XPoint *outPtr);
/*
 * Standard item types provided by Tk:
 */

Changes to generic/tkClipboard.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29








30
31
32
33
34
35
36
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21








22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







-
-
+
+












-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







/*
 * tkClipboard.c --
 *
 * 	This file manages the clipboard for the Tk toolkit, maintaining a
 * 	collection of data buffers that will be supplied on demand to
 * 	requesting applications.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"
#include "tkSelect.h"

/*
 * Prototypes for functions used only in this file:
 */

static Tcl_Size	ClipboardAppHandler(void *clientData,
			    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
static Tcl_Size	ClipboardHandler(void *clientData,
			    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
static Tcl_Size	ClipboardWindowHandler(void *clientData,
			    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
static void		ClipboardLostSel(void *clientData);
static int		ClipboardGetProc(void *clientData,
static int		ClipboardAppHandler(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static int		ClipboardHandler(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static int		ClipboardWindowHandler(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static void		ClipboardLostSel(ClientData clientData);
static int		ClipboardGetProc(ClientData clientData,
			    Tcl_Interp *interp, const char *portion);

/*
 *----------------------------------------------------------------------
 *
 * ClipboardHandler --
 *
44
45
46
47
48
49
50
51

52
53
54


55
56
57

58
59

60
61
62
63
64



65
66
67
68
69
70
71
44
45
46
47
48
49
50

51
52


53
54
55
56

57
58

59
60
61



62
63
64
65
66
67
68
69
70
71







-
+

-
-
+
+


-
+

-
+


-
-
-
+
+
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
ClipboardHandler(
    void *clientData,	/* Information about data to fetch. */
    Tcl_Size offset,			/* Return selection bytes starting at this
    ClientData clientData,	/* Information about data to fetch. */
    int offset,			/* Return selection bytes starting at this
				 * offset. */
    char *buffer,		/* Place to store converted selection. */
    Tcl_Size maxBytes)		/* Maximum # of bytes to store at buffer. */
    int maxBytes)		/* Maximum # of bytes to store at buffer. */
{
    TkClipboardTarget *targetPtr = (TkClipboardTarget *)clientData;
    TkClipboardTarget *targetPtr = clientData;
    TkClipboardBuffer *cbPtr;
    char *srcPtr, *destPtr;
    Tcl_Size count = 0;
    Tcl_Size scanned = 0;
    Tcl_Size length, freeCount;
    size_t count = 0;
    int scanned = 0;
    size_t length, freeCount;

    /*
     * Skip to buffer containing offset byte
     */

    for (cbPtr = targetPtr->firstBufferPtr; ; cbPtr = cbPtr->nextPtr) {
	if (cbPtr == NULL) {
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112







-
+







	cbPtr = cbPtr->nextPtr;
	if (cbPtr == NULL) {
	    break;
	}
	srcPtr = cbPtr->buffer;
	length = cbPtr->length;
    }
    return count;
    return (int)count;
}

/*
 *----------------------------------------------------------------------
 *
 * ClipboardAppHandler --
 *
122
123
124
125
126
127
128
129

130
131
132


133
134
135

136
137
138


139
140
141
142

143

144
145
146
147

148
149
150

151
152

153
154
155
156
157
158
159
122
123
124
125
126
127
128

129
130


131
132
133
134

135
136


137
138
139
140
141
142
143

144
145
146


147
148
149

150


151
152
153
154
155
156
157
158







-
+

-
-
+
+


-
+

-
-
+
+




+
-
+


-
-
+


-
+
-
-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
ClipboardAppHandler(
    void *clientData,	/* Pointer to TkDisplay structure. */
    Tcl_Size offset,			/* Return selection bytes starting at this
    ClientData clientData,	/* Pointer to TkDisplay structure. */
    int offset,			/* Return selection bytes starting at this
				 * offset. */
    char *buffer,		/* Place to store converted selection. */
    Tcl_Size maxBytes)		/* Maximum # of bytes to store at buffer. */
    int maxBytes)		/* Maximum # of bytes to store at buffer. */
{
    TkDisplay *dispPtr = (TkDisplay *)clientData;
    Tcl_Size length;
    TkDisplay *dispPtr = clientData;
    size_t length;
    const char *p;

    p = dispPtr->clipboardAppPtr->winPtr->nameUid;
    length = strlen(p);
    length -= offset;
    if (length <= offset) {
    if (length <= 0) {
	return 0;
    }
    length -= offset;
    if (length > maxBytes) {
    if (length > (size_t) maxBytes) {
	length = maxBytes;
    }
    memcpy(buffer, p, length);
    strncpy(buffer, p, length);
    buffer[length] = 0;
    return length;
    return (int)length;
}

/*
 *----------------------------------------------------------------------
 *
 * ClipboardWindowHandler --
 *
167
168
169
170
171
172
173
174

175
176
177


178
179
180

181
182
183
184
185
186
187
166
167
168
169
170
171
172

173
174


175
176
177
178

179
180
181
182
183
184
185
186







-
+

-
-
+
+


-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
ClipboardWindowHandler(
    TCL_UNUSED(void *),	/* Not used. */
    TCL_UNUSED(Tcl_Size),			/* Return selection bytes starting at this
    ClientData clientData,	/* Not used. */
    int offset,			/* Return selection bytes starting at this
				 * offset. */
    char *buffer,		/* Place to store converted selection. */
    TCL_UNUSED(Tcl_Size))		/* Maximum # of bytes to store at buffer. */
    int maxBytes)		/* Maximum # of bytes to store at buffer. */
{
    buffer[0] = '.';
    buffer[1] = 0;
    return 1;
}

/*
200
201
202
203
204
205
206
207

208
209

210
211
212
213
214
215
216
199
200
201
202
203
204
205

206
207

208
209
210
211
212
213
214
215







-
+

-
+







 *	The clipboard is marked as inactive.
 *
 *----------------------------------------------------------------------
 */

static void
ClipboardLostSel(
    void *clientData)	/* Pointer to TkDisplay structure. */
    ClientData clientData)	/* Pointer to TkDisplay structure. */
{
    TkDisplay *dispPtr = (TkDisplay *)clientData;
    TkDisplay *dispPtr = clientData;

    dispPtr->clipboardActive = 0;
}

/*
 *----------------------------------------------------------------------
 *
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368







-
+







    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
	    targetPtr = targetPtr->nextPtr) {
	if (targetPtr->type == type) {
	    break;
	}
    }
    if (targetPtr == NULL) {
	targetPtr = (TkClipboardTarget *)ckalloc(sizeof(TkClipboardTarget));
	targetPtr = ckalloc(sizeof(TkClipboardTarget));
	targetPtr->type = type;
	targetPtr->format = format;
	targetPtr->firstBufferPtr = targetPtr->lastBufferPtr = NULL;
	targetPtr->nextPtr = dispPtr->clipTargetPtr;
	dispPtr->clipTargetPtr = targetPtr;
	Tk_CreateSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
		type, ClipboardHandler, targetPtr, format);
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400







-
+









-
+







	return TCL_ERROR;
    }

    /*
     * Append a new buffer to the buffer chain.
     */

    cbPtr = (TkClipboardBuffer *)ckalloc(sizeof(TkClipboardBuffer));
    cbPtr = ckalloc(sizeof(TkClipboardBuffer));
    cbPtr->nextPtr = NULL;
    if (targetPtr->lastBufferPtr != NULL) {
	targetPtr->lastBufferPtr->nextPtr = cbPtr;
    } else {
	targetPtr->firstBufferPtr = cbPtr;
    }
    targetPtr->lastBufferPtr = cbPtr;

    cbPtr->length = strlen(buffer);
    cbPtr->buffer = (char *)ckalloc(cbPtr->length + 1);
    cbPtr->buffer = ckalloc(cbPtr->length + 1);
    strcpy(cbPtr->buffer, buffer);

    TkSelUpdateClipboard((TkWindow *) dispPtr->clipWindow, targetPtr);

    return TCL_OK;
}

414
415
416
417
418
419
420
421

422
423
424
425
426

427
428
429
430
431
432
433
413
414
415
416
417
418
419

420
421
422
423
424

425
426
427
428
429
430
431
432







-
+




-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ClipboardObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = (Tk_Window) clientData;
    const char *path = NULL;
    Atom selection;
    static const char *const optionStrings[] = { "append", "clear", "get", NULL };
    enum options { CLIPBOARD_APPEND, CLIPBOARD_CLEAR, CLIPBOARD_GET };
    int index, i;

    if (objc < 2) {
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
445
446
447
448
449
450
451

452

453
454
455
456
457
458
459







-
+
-







	const char *targetName = NULL;
	const char *formatName = NULL;
	const char *string;
	static const char *const appendOptionStrings[] = {
	    "-displayof", "-format", "-type", NULL
	};
	enum appendOptions { APPEND_DISPLAYOF, APPEND_FORMAT, APPEND_TYPE };
	int subIndex;
	int subIndex, length;
	Tcl_Size length;

	for (i = 2; i < objc - 1; i++) {
	    string = Tcl_GetStringFromObj(objv[i], &length);
	    if (string[0] != '-') {
		break;
	    }

633
634
635
636
637
638
639
640
641


642
643
644
645
646
647
648
631
632
633
634
635
636
637


638
639
640
641
642
643
644
645
646







-
-
+
+







 *	Sets up the clipWindow and related data structures.
 *
 *----------------------------------------------------------------------
 */

int
TkClipInit(
    TCL_UNUSED(Tcl_Interp *),		/* Interpreter to use for error reporting. */
    TkDisplay *dispPtr)/* Display to initialize. */
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    register TkDisplay *dispPtr)/* Display to initialize. */
{
    XSetWindowAttributes atts;

    dispPtr->clipTargetPtr = NULL;
    dispPtr->clipboardActive = 0;
    dispPtr->clipboardAppPtr = NULL;

697
698
699
700
701
702
703

704
705
706

707
708

709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726
727
728
695
696
697
698
699
700
701
702
703
704

705
706

707
708
709
710





711


712
713
714
715
716
717
718
719
720
721







+


-
+

-
+



-
-
-
-
-
+
-
-










 * Side effects:
 *	Bytes get appended to the dynamic string pointed to by the clientData
 *	argument.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ClipboardGetProc(
    void *clientData,	/* Dynamic string holding partially assembled
    ClientData clientData,	/* Dynamic string holding partially assembled
				 * selection. */
    TCL_UNUSED(Tcl_Interp *),		/* Interpreter used for error reporting (not
    Tcl_Interp *interp,		/* Interpreter used for error reporting (not
				 * used). */
    const char *portion)	/* New information to be appended. */
{
    Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8");
    Tcl_DString ds;

    const char *str = Tcl_ExternalToUtfDString(utf8, portion, TCL_INDEX_NONE, &ds);
    Tcl_DStringAppend((Tcl_DString *) clientData, str, Tcl_DStringLength(&ds));
    Tcl_DStringAppend((Tcl_DString *) clientData, portion, -1);
    Tcl_DStringFree(&ds);
    Tcl_FreeEncoding(utf8);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkCmds.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33

34
35

36
37
38
39
40
41
42
43
44
45
46










47
48
49


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32

33
34

35
36










37
38
39
40
41
42
43
44
45
46
47


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77






-
-
-
+
+
+




















-
+


-
+

-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
+
+













-







+







/*
 * tkCmds.c --
 *
 *	This file contains a collection of Tk-related Tcl commands that didn't
 *	fit in any particular file of the toolkit.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2000 Scriptics Corporation.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#if defined(_WIN32)
#include "tkWinInt.h"
#elif defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#else
#include "tkUnixInt.h"
#endif

/*
 * Forward declarations for functions defined later in this file:
 */

static TkWindow *	GetTopHierarchy(Tk_Window tkwin);
static char *		WaitVariableProc(void *clientData,
static char *		WaitVariableProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static void		WaitVisibilityProc(void *clientData,
static void		WaitVisibilityProc(ClientData clientData,
			    XEvent *eventPtr);
static void		WaitWindowProc(void *clientData,
static void		WaitWindowProc(ClientData clientData,
			    XEvent *eventPtr);
static int		AppnameCmd(void *dummy, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const *objv);
static int		CaretCmd(void *dummy, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const *objv);
static int		InactiveCmd(void *dummy, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const *objv);
static int		ScalingCmd(void *dummy, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const *objv);
static int		UseinputmethodsCmd(void *dummy,
			    Tcl_Interp *interp, Tcl_Size objc,
static int		AppnameCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		CaretCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		InactiveCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		ScalingCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		UseinputmethodsCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);
static int		WindowingsystemCmd(void *dummy,
			    Tcl_Interp *interp, Tcl_Size objc,
static int		WindowingsystemCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);

#if defined(_WIN32) || defined(MAC_OSX_TK)
MODULE_SCOPE const TkEnsemble tkFontchooserEnsemble[];
#else
#define tkFontchooserEnsemble NULL
#endif

/*
 * Table of tk subcommand names and implementations.
 */

static const TkEnsemble tkCmdMap[] = {
    {"fontchooser",	NULL, tkFontchooserEnsemble},
    {"appname",		AppnameCmd, NULL },
    {"busy",		Tk_BusyObjCmd, NULL },
    {"caret",		CaretCmd, NULL },
    {"inactive",	InactiveCmd, NULL },
    {"scaling",		ScalingCmd, NULL },
    {"useinputmethods",	UseinputmethodsCmd, NULL },
    {"windowingsystem",	WindowingsystemCmd, NULL },
    {"fontchooser",	NULL, tkFontchooserEnsemble},
    {NULL, NULL, NULL}
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_BellObjCmd --
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102

103
104

105
106
107
108
109
110
111
112
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101

102


103

104
105
106
107
108
109
110







-
+








-
+
-
-
+
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_BellObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const bellOptions[] = {
	"-displayof", "-nice", NULL
    };
    enum options { TK_BELL_DISPLAYOF, TK_BELL_NICE };
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    Tcl_Size i;
    int index, nice = 0;
    int i, index, nice = 0;
    Tk_ErrorHandler handler;

    if (objc > 4) {
    wrongArgs:
	Tcl_WrongNumArgs(interp, 1, objv, "?-displayof window? ?-nice?");
	return TCL_ERROR;
    }

126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
124
125
126
127
128
129
130

131
132
133
134

135

136
137
138
139
140
141
142







-




-
+
-







	    }
	    break;
	case TK_BELL_NICE:
	    nice = 1;
	    break;
	}
    }
    handler = Tk_CreateErrorHandler(Tk_Display(tkwin), -1, -1, -1, NULL, NULL);
    XBell(Tk_Display(tkwin), 0);
    if (!nice) {
	XForceScreenSaver(Tk_Display(tkwin), ScreenSaverReset);
    }
    (void)XFlush(Tk_Display(tkwin));
    XFlush(Tk_Display(tkwin));
    Tk_DeleteErrorHandler(handler);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_BindObjCmd --
155
156
157
158
159
160
161
162

163
164
165
166
167

168
169

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192


193
194
195
196
197
198
199
151
152
153
154
155
156
157

158
159
160
161
162

163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186


187
188
189
190
191
192
193
194
195







-
+




-
+

-
+



















-
+

-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_BindObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkWindow *winPtr;
    void *object;
    ClientData object;
    const char *string;

    if ((objc < 2) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 1, objv, "window ?pattern? ?command?");
	return TCL_ERROR;
    }
    string = Tcl_GetString(objv[1]);

    /*
     * Bind tags either a window name or a tag name for the first argument.
     * If the argument starts with ".", assume it is a window; otherwise, it
     * is a tag.
     */

    if (string[0] == '.') {
	winPtr = (TkWindow *) Tk_NameToWindow(interp, string, tkwin);
	if (winPtr == NULL) {
	    return TCL_ERROR;
	}
	object = winPtr->pathName;
	object = (ClientData) winPtr->pathName;
    } else {
	winPtr = (TkWindow *)clientData;
	object = (void *) Tk_GetUid(string);
	winPtr = clientData;
	object = (ClientData) Tk_GetUid(string);
    }

    /*
     * If there are four arguments, the command is modifying a binding. If
     * there are three arguments, the command is querying a binding. If there
     * are only two arguments, the command is querying all the bindings for
     * the given tag/window.
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+








	command = Tk_GetBinding(interp, winPtr->mainPtr->bindingTable,
		object, Tcl_GetString(objv[2]));
	if (command == NULL) {
	    Tcl_ResetResult(interp);
	    return TCL_OK;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(command, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
    } else {
	Tk_GetAllBindings(interp, winPtr->mainPtr->bindingTable, object);
    }
    return TCL_OK;
}

/*
264
265
266
267
268
269
270
271

272
273
274


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292

293
294
295
296
297
298
299
300
301

302
303
304
305
306


307
308
309
310
311
312
313
314

315
316
317
318

319
320
321
322
323
324
325
260
261
262
263
264
265
266

267
268


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287

288
289
290
291
292
293
294
295
296

297
298
299
300


301
302
303
304
305
306
307
308
309

310
311
312
313

314
315
316
317
318
319
320
321







-
+

-
-
+
+














-
+


-
+








-
+



-
-
+
+







-
+



-
+








void
TkBindEventProc(
    TkWindow *winPtr,		/* Pointer to info about window. */
    XEvent *eventPtr)		/* Information about event. */
{
#define MAX_OBJS 20
    void *objects[MAX_OBJS], **objPtr;
    ClientData objects[MAX_OBJS], *objPtr;
    TkWindow *topLevPtr;
    Tcl_Size i, count;
    char *p;
    int i, count;
    const char *p;
    Tcl_HashEntry *hPtr;

    if ((winPtr->mainPtr == NULL) || (winPtr->mainPtr->bindingTable == NULL)) {
	return;
    }

    objPtr = objects;
    if (winPtr->numTags != 0) {
	/*
	 * Make a copy of the tags for the window, replacing window names with
	 * pointers to the pathName from the appropriate window.
	 */

	if (winPtr->numTags > MAX_OBJS) {
	    objPtr = (void **)ckalloc(winPtr->numTags * sizeof(void *));
	    objPtr = ckalloc(winPtr->numTags * sizeof(ClientData));
	}
	for (i = 0; i < winPtr->numTags; i++) {
	    p = (char *)winPtr->tagPtr[i];
	    p = winPtr->tagPtr[i];
	    if (*p == '.') {
		hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->nameTable, p);
		if (hPtr != NULL) {
		    p = ((TkWindow *) Tcl_GetHashValue(hPtr))->pathName;
		} else {
		    p = NULL;
		}
	    }
	    objPtr[i] = p;
	    objPtr[i] = (ClientData) p;
	}
	count = winPtr->numTags;
    } else {
	objPtr[0] = winPtr->pathName;
	objPtr[1] = (void *)winPtr->classUid;
	objPtr[0] = (ClientData) winPtr->pathName;
	objPtr[1] = (ClientData) winPtr->classUid;
	for (topLevPtr = winPtr;
		(topLevPtr != NULL) && !(topLevPtr->flags & TK_TOP_HIERARCHY);
		topLevPtr = topLevPtr->parentPtr) {
	    /* Empty loop body. */
	}
	if ((winPtr != topLevPtr) && (topLevPtr != NULL)) {
	    count = 4;
	    objPtr[2] = topLevPtr->pathName;
	    objPtr[2] = (ClientData) topLevPtr->pathName;
	} else {
	    count = 3;
	}
	objPtr[count-1] = (void *) Tk_GetUid("all");
	objPtr[count-1] = (ClientData) Tk_GetUid("all");
    }
    Tk_BindEvent(winPtr->mainPtr->bindingTable, eventPtr, (Tk_Window) winPtr,
	    count, objPtr);
    if (objPtr != objects) {
	ckfree(objPtr);
    }
}
339
340
341
342
343
344
345
346

347
348
349
350
351

352
353

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

371
372

373
374
375
376
377
378
379

380
381
382

383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413
414
415
416

417
418

419
420

421
422
423
424
425
426
427
335
336
337
338
339
340
341

342
343
344
345
346

347
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

366
367

368
369
370
371
372
373
374

375
376
377

378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406
407
408
409
410
411

412
413

414
415

416
417
418
419
420
421
422
423







-
+




-
+

-
+
















-
+

-
+






-
+


-
+



-
+
















-
+












-
+

-
+

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_BindtagsObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkWindow *winPtr, *winPtr2;
    Tcl_Size i, length;
    int i, length;
    const char *p;
    Tcl_Obj *listPtr, **tags;

    if ((objc < 2) || (objc > 3)) {
	Tcl_WrongNumArgs(interp, 1, objv, "window ?taglist?");
	return TCL_ERROR;
    }
    winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[1]),
	    tkwin);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }
    if (objc == 2) {
	listPtr = Tcl_NewObj();
	if (winPtr->numTags == 0) {
	    Tcl_ListObjAppendElement(NULL, listPtr,
		    Tcl_NewStringObj(winPtr->pathName, TCL_INDEX_NONE));
		    Tcl_NewStringObj(winPtr->pathName, -1));
	    Tcl_ListObjAppendElement(NULL, listPtr,
		    Tcl_NewStringObj(winPtr->classUid, TCL_INDEX_NONE));
		    Tcl_NewStringObj(winPtr->classUid, -1));
	    winPtr2 = winPtr;
	    while ((winPtr2 != NULL) && !(Tk_TopWinHierarchy(winPtr2))) {
		winPtr2 = winPtr2->parentPtr;
	    }
	    if ((winPtr != winPtr2) && (winPtr2 != NULL)) {
		Tcl_ListObjAppendElement(NULL, listPtr,
			Tcl_NewStringObj(winPtr2->pathName, TCL_INDEX_NONE));
			Tcl_NewStringObj(winPtr2->pathName, -1));
	    }
	    Tcl_ListObjAppendElement(NULL, listPtr,
		    Tcl_NewStringObj("all", TCL_INDEX_NONE));
		    Tcl_NewStringObj("all", -1));
	} else {
	    for (i = 0; i < winPtr->numTags; i++) {
		Tcl_ListObjAppendElement(NULL, listPtr,
			Tcl_NewStringObj((const char *)winPtr->tagPtr[i], TCL_INDEX_NONE));
			Tcl_NewStringObj((char *) winPtr->tagPtr[i], -1));
	    }
	}
	Tcl_SetObjResult(interp, listPtr);
	return TCL_OK;
    }
    if (winPtr->tagPtr != NULL) {
	TkFreeBindingTags(winPtr);
    }
    if (Tcl_ListObjGetElements(interp, objv[2], &length, &tags) != TCL_OK) {
	return TCL_ERROR;
    }
    if (length == 0) {
	return TCL_OK;
    }

    winPtr->numTags = length;
    winPtr->tagPtr = (void **)ckalloc(length * sizeof(void *));
    winPtr->tagPtr = ckalloc(length * sizeof(ClientData));
    for (i = 0; i < length; i++) {
	p = Tcl_GetString(tags[i]);
	if (p[0] == '.') {
	    char *copy;

	    /*
	     * Handle names starting with "." specially: store a malloc'ed
	     * string, rather than a Uid; at event time we'll look up the name
	     * in the window table and use the corresponding window, if there
	     * is one.
	     */

	    copy = (char *)ckalloc(strlen(p) + 1);
	    copy = ckalloc(strlen(p) + 1);
	    strcpy(copy, p);
	    winPtr->tagPtr[i] = copy;
	    winPtr->tagPtr[i] = (ClientData) copy;
	} else {
	    winPtr->tagPtr[i] = (void *)Tk_GetUid(p);
	    winPtr->tagPtr[i] = (ClientData) Tk_GetUid(p);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
441
442
443
444
445
446
447
448

449
450
451
452

453
454
455
456
457
458
459

460
461
462
463
464
465
466
437
438
439
440
441
442
443

444
445
446
447

448
449
450
451
452
453
454

455
456
457
458
459
460
461
462







-
+



-
+






-
+







 *----------------------------------------------------------------------
 */

void
TkFreeBindingTags(
    TkWindow *winPtr)		/* Window whose tags are to be released. */
{
    Tcl_Size i;
    int i;
    const char *p;

    for (i = 0; i < winPtr->numTags; i++) {
	p = (const char *)winPtr->tagPtr[i];
	p = winPtr->tagPtr[i];
	if (*p == '.') {
	    /*
	     * Names starting with "." are malloced rather than Uids, so they
	     * have to be freed.
	     */

	    ckfree((void *)p);
	    ckfree((char *)p);
	}
    }
    ckfree(winPtr->tagPtr);
    winPtr->numTags = 0;
    winPtr->tagPtr = NULL;
}

479
480
481
482
483
484
485
486

487
488
489
490
491
492
493


494
495
496
497
498
499
500
475
476
477
478
479
480
481

482
483
484
485
486
487


488
489
490
491
492
493
494
495
496







-
+





-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_DestroyObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window window;
    Tk_Window tkwin = (Tk_Window)clientData;
    Tcl_Size i;
    Tk_Window tkwin = clientData;
    int i;

    for (i = 1; i < objc; i++) {
	window = Tk_NameToWindow(interp, Tcl_GetString(objv[i]), tkwin);
	if (window == NULL) {
	    Tcl_ResetResult(interp);
	    continue;
	}
524
525
526
527
528
529
530

531
532
533

534
535
536
537
538

539
540
541
542
543
544
545
520
521
522
523
524
525
526
527
528
529

530
531
532
533
534

535
536
537
538
539
540
541
542







+


-
+




-
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_LowerObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window mainwin = (Tk_Window)clientData;
    Tk_Window mainwin = clientData;
    Tk_Window tkwin, other;

    if ((objc != 2) && (objc != 3)) {
	Tcl_WrongNumArgs(interp, 1, objv, "window ?belowThis?");
	return TCL_ERROR;
    }

583
584
585
586
587
588
589

590
591
592

593
594
595
596
597

598
599
600
601
602
603
604
580
581
582
583
584
585
586
587
588
589

590
591
592
593
594

595
596
597
598
599
600
601
602







+


-
+




-
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_RaiseObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window mainwin = (Tk_Window)clientData;
    Tk_Window mainwin = clientData;
    Tk_Window tkwin, other;

    if ((objc != 2) && (objc != 3)) {
	Tcl_WrongNumArgs(interp, 1, objv, "window ?aboveThis?");
	return TCL_ERROR;
    }

644
645
646
647
648
649
650
651

652
653
654
655

656
657
658

659
660
661
662
663
664
665
666
642
643
644
645
646
647
648

649
650



651
652


653

654
655
656
657
658
659
660







-
+

-
-
-
+

-
-
+
-







 *
 * ----------------------------------------------------------------------
 */

int
TkInitTkCmd(
    Tcl_Interp *interp,
    void *clientData)
    ClientData clientData)
{
    /* If the interp is safe, leave out "fontchooser" */
    int isSafe = Tcl_IsSafe(interp);
    TkMakeEnsemble(interp, "::", "tk", clientData, tkCmdMap + isSafe);
    TkMakeEnsemble(interp, "::", "tk", clientData, tkCmdMap);
#if defined(_WIN32) || defined(MAC_OSX_TK)
    if (!isSafe) {
	TkInitFontchooser(interp, clientData);
    TkInitFontchooser(interp, clientData);
    }
#endif
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
677
678
679
680
681
682
683
684

685
686

687
688
689

690
691
692
693
694
695

696
697
698
699
700
701
702

703
704
705
706
707
708




709

710
711
712
713
714
715

716
717

718
719
720

721
722
723
724
725
726
727
671
672
673
674
675
676
677

678
679

680
681
682

683
684
685
686
687
688

689
690
691
692
693
694
695

696



697
698
699
700
701
702
703

704
705
706
707
708
709

710
711

712
713
714

715
716
717
718
719
720
721
722







-
+

-
+


-
+





-
+






-
+
-
-
-



+
+
+
+
-
+





-
+

-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
AppnameCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkWindow *winPtr;
    const char *string;

    if (Tcl_IsSafe(interp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"appname not accessible in a safe interpreter", TCL_INDEX_NONE));
		"appname not accessible in a safe interpreter", -1));
	Tcl_SetErrorCode(interp, "TK", "SAFE", "APPLICATION", NULL);
	return TCL_ERROR;
    }

    winPtr = (TkWindow *) tkwin;

    if (objc == 2) {
    if (objc > 2) {
	string = Tcl_GetString(objv[1]);
	winPtr->nameUid = Tk_GetUid(Tk_SetAppName(tkwin, string));
    } else if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, "?newName?");
	return TCL_ERROR;
    }
    if (objc == 2) {
	string = Tcl_GetString(objv[1]);
	winPtr->nameUid = Tk_GetUid(Tk_SetAppName(tkwin, string));
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->nameUid, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->nameUid, -1));
    return TCL_OK;
}

int
CaretCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    int index;
    Tcl_Obj *objPtr;
    TkCaret *caretPtr;
    Tk_Window window;
    static const char *const caretStrings[] = {
	"-x",	"-y", "-height", NULL
    };
744
745
746
747
748
749
750
751

752
753
754
755

756
757
758
759

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782

783
784
785
786
787
788
789
739
740
741
742
743
744
745

746
747
748
749

750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

774
775


776
777
778
779
780
781
782
783







-
+



-
+



-
+



















-
+

-
-
+







	 * Return all the current values
	 */

	objPtr = Tcl_NewObj();
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewStringObj("-height", 7));
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewWideIntObj(caretPtr->height));
		Tcl_NewIntObj(caretPtr->height));
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewStringObj("-x", 2));
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewWideIntObj(caretPtr->x));
		Tcl_NewIntObj(caretPtr->x));
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewStringObj("-y", 2));
	Tcl_ListObjAppendElement(interp, objPtr,
		Tcl_NewWideIntObj(caretPtr->y));
		Tcl_NewIntObj(caretPtr->y));
	Tcl_SetObjResult(interp, objPtr);
    } else if (objc == 3) {
	int value;

	/*
	 * Return the current value of the selected option
	 */

	if (Tcl_GetIndexFromObj(interp, objv[2], caretStrings,
		"caret option", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (index == TK_CARET_X) {
	    value = caretPtr->x;
	} else if (index == TK_CARET_Y) {
	    value = caretPtr->y;
	} else /* if (index == TK_CARET_HEIGHT) -- last case */ {
	    value = caretPtr->height;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(value));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(value));
    } else {
	Tcl_Size i;
	int value, x = 0, y = 0, height = -1;
	int i, value, x = 0, y = 0, height = -1;

	for (i = 2; i < objc; i += 2) {
	    if ((Tcl_GetIndexFromObj(interp, objv[i], caretStrings,
		    "caret option", 0, &index) != TCL_OK) ||
		    Tcl_GetIntFromObj(interp,objv[i+1],&value) != TCL_OK) {
		return TCL_ERROR;
	    }
801
802
803
804
805
806
807
808

809
810

811
812
813

814
815
816
817









818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881

882
883

884
885
886

887
888

889
890
891
892

893
894
895
896
897

898
899
900
901
902






903
904
905
906
907
908
909

910

911
912
913
914

915

916
917
918
919
920
921
922
923
924
925
926
927

928
929

930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945

946
947
948
949
950
951

952
953

954
955
956
957


958
959
960
961
962
963


964
965
966
967
968


969
970
971
972
973
974
975
976
977
978
979
980
981
982

983
984
985
986
987
988
989
795
796
797
798
799
800
801

802
803

804
805
806

807
808



809
810
811
812
813
814
815
816
817
818
819
820
821
822
823

824
825
826
827
828






829
830
831
832

833
834
835
836
837
838
839
840
841
842
843






















844
845
846
847
848
849
850
851
852

853
854

855
856
857

858
859

860
861
862
863

864
865
866
867
868

869
870
871
872
873

874
875
876
877
878
879
880
881
882
883
884
885
886
887

888
889
890
891
892
893

894
895
896
897
898
899
900
901
902
903
904
905

906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923

924
925
926
927
928
929

930
931

932
933
934


935
936
937
938
939
940


941
942
943
944
945


946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

961
962
963
964
965
966
967
968







-
+

-
+


-
+

-
-
-
+
+
+
+
+
+
+
+
+






-
+




-
-
-
-
-
-
+



-











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+

-
+


-
+

-
+



-
+




-
+




-
+
+
+
+
+
+







+
-
+




+
-
+











-
+

-
+















-
+





-
+

-
+


-
-
+
+




-
-
+
+



-
-
+
+













-
+







	Tk_SetCaretPos(window, x, y, height);
    }
    return TCL_OK;
}

int
ScalingCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    Screen *screenPtr;
    Tcl_Size skip;
    int width, height, intPct;
    double d, dblPct;
    int skip, width, height;
    double d;

    if (Tcl_IsSafe(interp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"scaling not accessible in a safe interpreter", -1));
	Tcl_SetErrorCode(interp, "TK", "SAFE", "SCALING", NULL);
	return TCL_ERROR;
    }

    skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);
    if (skip < 0) {
	return TCL_ERROR;
    }
    screenPtr = Tk_Screen(tkwin);
    if (objc == 1 + skip) {
    if (objc - skip == 1) {
	d = 25.4 / 72;
	d *= WidthOfScreen(screenPtr);
	d /= WidthMMOfScreen(screenPtr);
	Tcl_SetObjResult(interp, Tcl_NewDoubleObj(d));
    } else if (Tcl_IsSafe(interp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"setting the scaling not accessible in a safe interpreter", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "SAFE", "SCALING", NULL);
	return TCL_ERROR;
    } else if (objc == 2 + skip) {
    } else if (objc - skip == 2) {
	if (Tcl_GetDoubleFromObj(interp, objv[1+skip], &d) != TCL_OK) {
	    return TCL_ERROR;
	}
	dblPct = d * 75;
	d = (25.4 / 72) / d;
	width = (int) (d * WidthOfScreen(screenPtr) + 0.5);
	if (width <= 0) {
	    width = 1;
	}
	height = (int) (d * HeightOfScreen(screenPtr) + 0.5);
	if (height <= 0) {
	    height = 1;
	}
	WidthMMOfScreen(screenPtr) = width;
	HeightMMOfScreen(screenPtr) = height;

	/*
	 * Keep the variables ::tk::scalingPct and ::tk::svgFmt
	 * in sync with the new value of the scaling factor
	 */

	for (intPct = 100; 1; intPct += 25) {
	    if (dblPct < intPct + 12.5) {
		break;
	    }
	}
	Tcl_SetVar2Ex(interp, "::tk::scalingPct", NULL, Tcl_NewIntObj(intPct),
		TCL_GLOBAL_ONLY);

	Tcl_SetVar2Ex(interp, "::tk::svgFmt", NULL,
		Tcl_NewStringObj("svg", TCL_INDEX_NONE), TCL_GLOBAL_ONLY);
	Tcl_SetVar2Ex(interp, "::tk::svgFmt", NULL,
		Tcl_NewStringObj("-scale", TCL_INDEX_NONE),
		TCL_GLOBAL_ONLY | TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
	Tcl_SetVar2Ex(interp, "::tk::svgFmt", NULL,
		Tcl_NewDoubleObj(intPct / 100.0),
		TCL_GLOBAL_ONLY | TCL_APPEND_VALUE | TCL_LIST_ELEMENT);
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "?-displayof window? ?factor?");
	return TCL_ERROR;
    }
    return TCL_OK;
}

int
UseinputmethodsCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkDisplay *dispPtr;
    Tcl_Size skip;
    int skip;

    if (Tcl_IsSafe(interp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"useinputmethods not accessible in a safe interpreter", TCL_INDEX_NONE));
		"useinputmethods not accessible in a safe interpreter", -1));
	Tcl_SetErrorCode(interp, "TK", "SAFE", "INPUT_METHODS", NULL);
	return TCL_ERROR;
    }

    skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);
    skip = TkGetDisplayOf(interp, objc-1, objv+1, &tkwin);
    if (skip < 0) {
	return TCL_ERROR;
    }
    dispPtr = ((TkWindow *) tkwin)->dispPtr;
    if (objc == 2 + skip) {
    if ((objc - skip) == 2) {
	/*
	 * In the case where TK_USE_INPUT_METHODS is not defined, this
	 * will be ignored and we will always return 0. That will indicate
	 * to the user that input methods are just not available.
	 */

	int boolVal;

	if (Tcl_GetBooleanFromObj(interp, objv[1+skip],
		&boolVal) != TCL_OK) {
	    return TCL_ERROR;
	}
#ifdef TK_USE_INPUT_METHODS
	if (boolVal && (dispPtr->inputMethod != NULL)) {
	if (boolVal) {
	    dispPtr->flags |= TK_DISPLAY_USE_IM;
	} else {
	    dispPtr->flags &= ~TK_DISPLAY_USE_IM;
	}
#endif /* TK_USE_INPUT_METHODS */
    } else if (objc != 1 + skip) {
    } else if ((objc - skip) != 1) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"?-displayof window? ?boolean?");
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp,
	    Tcl_NewBooleanObj(dispPtr->flags & TK_DISPLAY_USE_IM));
    return TCL_OK;
}

int
WindowingsystemCmd(
    TCL_UNUSED(void *),		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    const char *windowingsystem;

    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
#if defined(_WIN32)
    windowingsystem = "win32";
#elif defined(MAC_OSX_TK)
    windowingsystem = "aqua";
#else
    windowingsystem = "x11";
#endif
    Tcl_SetObjResult(interp, Tcl_NewStringObj(windowingsystem, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(windowingsystem, -1));
    return TCL_OK;
}

int
InactiveCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tcl_Size skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);
    Tk_Window tkwin = clientData;
    int skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);

    if (skip < 0) {
	return TCL_ERROR;
    }
    if (objc == 1 + skip) {
	Tcl_WideInt inactive;
    if (objc - skip == 1) {
	long inactive;

	inactive = (Tcl_IsSafe(interp) ? -1 :
		Tk_GetUserInactiveTime(Tk_Display(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(inactive));
    } else if (objc == 2 + skip) {
	Tcl_SetObjResult(interp, Tcl_NewLongObj(inactive));
    } else if (objc - skip == 2) {
	const char *string;

	string = Tcl_GetString(objv[objc-1]);
	if (strcmp(string, "reset") != 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad option \"%s\": must be reset", string));
	    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option",
		    string, NULL);
	    return TCL_ERROR;
	}
	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "resetting the user inactivity timer "
		    "is not allowed in a safe interpreter", TCL_INDEX_NONE));
		    "is not allowed in a safe interpreter", -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "INACTIVITY_TIMER", NULL);
	    return TCL_ERROR;
	}
	Tk_ResetUserInactiveTime(Tk_Display(tkwin));
	Tcl_ResetResult(interp);
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "?-displayof window? ?reset?");
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014

1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
984
985
986
987
988
989
990
991
992
993

994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006







+


-
+




-
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_TkwaitObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    int done, index;
    int code = TCL_OK;
    static const char *const optionStrings[] = {
	"variable", "visibility", "window", NULL
    };
    enum options {
	TKWAIT_VARIABLE, TKWAIT_VISIBILITY, TKWAIT_WINDOW
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142

1143
1144
1145
1146


1147
1148

1149
1150
1151
1152
1153
1154
1155

1156
1157
1158

1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125


1126
1127
1128

1129
1130
1131


1132
1133
1134
1135
1136
1137

1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151

1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162







+


-
+


-
-
+
+

-
+


-
-



+


-
+


-
+










-
+


-
+








    if (code == TCL_OK)
    Tcl_ResetResult(interp);

    return code;
}

	/* ARGSUSED */
static char *
WaitVariableProc(
    void *clientData,		/* Pointer to integer to set to 1. */
    ClientData clientData,	/* Pointer to integer to set to 1. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    const char *name1,		/* Name of variable. */
    TCL_UNUSED(const char *),	/* Second part of variable name. */
    TCL_UNUSED(int))		/* Information about what happened. */
    const char *name2,		/* Second part of variable name. */
    int flags)			/* Information about what happened. */
{
    int *donePtr = (int *)clientData;
    int *donePtr = clientData;

    *donePtr = 1;
    Tcl_UntraceVar(interp, name1, TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
	    WaitVariableProc, clientData);
    return NULL;
}

	/*ARGSUSED*/
static void
WaitVisibilityProc(
    void *clientData,		/* Pointer to integer to set to 1. */
    ClientData clientData,	/* Pointer to integer to set to 1. */
    XEvent *eventPtr)		/* Information about event (not used). */
{
    int *donePtr = (int *)clientData;
    int *donePtr = clientData;

    if (eventPtr->type == VisibilityNotify) {
	*donePtr = 1;
    } else if (eventPtr->type == DestroyNotify) {
	*donePtr = 2;
    }
}

static void
WaitWindowProc(
    void *clientData,		/* Pointer to integer to set to 1. */
    ClientData clientData,	/* Pointer to integer to set to 1. */
    XEvent *eventPtr)		/* Information about event. */
{
    int *donePtr = (int *)clientData;
    int *donePtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	*donePtr = 1;
    }
}

/*
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201

1202
1203
1204
1205
1206
1207
1208
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189







+


-
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_UpdateObjCmd(
    TCL_UNUSED(void *),		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const updateOptions[] = {"idletasks", NULL};
    int flags, index;
    TkDisplay *dispPtr;
1292
1293
1294
1295
1296
1297
1298
1299

1300
1301
1302
1303
1304

1305
1306
1307
1308

1309
1310
1311
1312
1313
1314
1315
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284

1285

1286
1287

1288
1289
1290
1291
1292
1293
1294
1295







-
+




-
+
-


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_WinfoObjCmd(
    void *clientData,		/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int index, x, y, width, height, useX, useY, c_class;
    int index, x, y, width, height, useX, useY, class, skip;
    Tcl_Size skip;
    const char *string;
    TkWindow *winPtr;
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;

    static const TkStateMap visualMap[] = {
	{PseudoColor,	"pseudocolor"},
	{GrayScale,	"grayscale"},
	{DirectColor,	"directcolor"},
	{TrueColor,	"truecolor"},
	{StaticColor,	"staticcolor"},
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433

1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445
1356
1357
1358
1359
1360
1361
1362

1363
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406
1407
1408

1409
1410
1411
1412

1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1425







-
+







-
+







-
+






-
+






-
+






-
+








-
+



-
+




-
+







	}
    }
    winPtr = (TkWindow *) tkwin;

    switch ((enum options) index) {
    case WIN_CELLS:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(Tk_Visual(tkwin)->map_entries));
		Tcl_NewIntObj(Tk_Visual(tkwin)->map_entries));
	break;
    case WIN_CHILDREN: {
	Tcl_Obj *strPtr, *resultPtr = Tcl_NewObj();

	winPtr = winPtr->childList;
	for ( ; winPtr != NULL; winPtr = winPtr->nextPtr) {
	    if (!(winPtr->flags & TK_ANONYMOUS_WINDOW)) {
		strPtr = Tcl_NewStringObj(winPtr->pathName, TCL_INDEX_NONE);
		strPtr = Tcl_NewStringObj(winPtr->pathName, -1);
		Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
	    }
	}
	Tcl_SetObjResult(interp, resultPtr);
	break;
    }
    case WIN_CLASS:
	Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_Class(tkwin), TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_Class(tkwin), -1));
	break;
    case WIN_COLORMAPFULL:
	Tcl_SetObjResult(interp,
		Tcl_NewBooleanObj(TkpCmapStressed(tkwin,Tk_Colormap(tkwin))));
	break;
    case WIN_DEPTH:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_Depth(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_Depth(tkwin)));
	break;
    case WIN_GEOMETRY:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%dx%d+%d+%d",
		Tk_Width(tkwin), Tk_Height(tkwin), Tk_X(tkwin), Tk_Y(tkwin)));
	break;
    case WIN_HEIGHT:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_Height(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_Height(tkwin)));
	break;
    case WIN_ID: {
	char buf[TCL_INTEGER_SPACE];

	Tk_MakeWindowExist(tkwin);
	TkpPrintWindowId(buf, Tk_WindowId(tkwin));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
	break;
    }
    case WIN_ISMAPPED:
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(Tk_IsMapped(tkwin)));
	break;
    case WIN_MANAGER:
	if (winPtr->geomMgrPtr != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(winPtr->geomMgrPtr->name, TCL_INDEX_NONE));
		    Tcl_NewStringObj(winPtr->geomMgrPtr->name, -1));
	}
	break;
    case WIN_NAME:
	Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_Name(tkwin), TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_Name(tkwin), -1));
	break;
    case WIN_PARENT:
	if (winPtr->parentPtr != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(winPtr->parentPtr->pathName, TCL_INDEX_NONE));
		    Tcl_NewStringObj(winPtr->parentPtr->pathName, -1));
	}
	break;
    case WIN_POINTERX:
	useX = 1;
	useY = 0;
	goto pointerxy;
    case WIN_POINTERY:
1457
1458
1459
1460
1461
1462
1463
1464
1465


1466
1467
1468

1469
1470

1471
1472
1473
1474

1475
1476
1477

1478
1479
1480
1481

1482
1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496
1497

1498
1499
1500
1501

1502
1503
1504
1505

1506
1507
1508
1509

1510
1511
1512
1513

1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544

1545
1546
1547

1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559

1560
1561
1562
1563

1564
1565
1566
1567

1568
1569
1570
1571

1572
1573
1574

1575
1576
1577

1578
1579
1580

1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592

1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603

1604
1605
1606
1607
1608
1609

1610
1611
1612
1613
1614

1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1657

1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669

1670
1671
1672
1673
1674
1675
1676
1437
1438
1439
1440
1441
1442
1443


1444
1445
1446
1447

1448
1449

1450
1451
1452
1453

1454
1455
1456

1457
1458
1459
1460

1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475
1476

1477
1478
1479
1480

1481
1482
1483
1484

1485
1486
1487
1488

1489
1490
1491
1492

1493
1494
1495

1496
1497
1498
1499
1500
1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526

1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542

1543
1544
1545
1546

1547
1548
1549
1550

1551
1552
1553

1554
1555
1556

1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573
1574
1575
1576
1577
1578

1579
1580
1581
1582

1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593

1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612

1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628

1629
1630
1631
1632
1633
1634
1635
1636

1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
1656







-
-
+
+


-
+

-
+



-
+


-
+



-
+



-
+







-
+



-
+



-
+



-
+



-
+



-
+


-
+







-
+



















-
+


-
+



-
+







-
+



-
+



-
+



-
+


-
+


-
+


-
+











-
+






-
+



-
+





-
+




-
+










-
+







-
+















-
+







-
+











-
+







	    y = -1;
	} else {
	    TkGetPointerCoords((Tk_Window) winPtr, &x, &y);
	}
	if (useX & useY) {
	    Tcl_Obj *xyObj[2];

	    xyObj[0] = Tcl_NewWideIntObj(x);
	    xyObj[1] = Tcl_NewWideIntObj(y);
	    xyObj[0] = Tcl_NewIntObj(x);
	    xyObj[1] = Tcl_NewIntObj(y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, xyObj));
	} else if (useX) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(x));
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(y));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(y));
	}
	break;
    case WIN_REQHEIGHT:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_ReqHeight(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_ReqHeight(tkwin)));
	break;
    case WIN_REQWIDTH:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_ReqWidth(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_ReqWidth(tkwin)));
	break;
    case WIN_ROOTX:
	Tk_GetRootCoords(tkwin, &x, &y);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(x));
	break;
    case WIN_ROOTY:
	Tk_GetRootCoords(tkwin, &x, &y);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(y));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(y));
	break;
    case WIN_SCREEN:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s.%d",
		Tk_DisplayName(tkwin), Tk_ScreenNumber(tkwin)));
	break;
    case WIN_SCREENCELLS:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(CellsOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(CellsOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENDEPTH:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(DefaultDepthOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(DefaultDepthOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENHEIGHT:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(HeightOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(HeightOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENWIDTH:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(WidthOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(WidthOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENMMHEIGHT:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(HeightMMOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(HeightMMOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENMMWIDTH:
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(WidthMMOfScreen(Tk_Screen(tkwin))));
		Tcl_NewIntObj(WidthMMOfScreen(Tk_Screen(tkwin))));
	break;
    case WIN_SCREENVISUAL:
	c_class = DefaultVisualOfScreen(Tk_Screen(tkwin))->c_class;
	class = DefaultVisualOfScreen(Tk_Screen(tkwin))->class;
	goto visual;
    case WIN_SERVER:
	TkGetServerInfo(interp, tkwin);
	break;
    case WIN_TOPLEVEL:
	winPtr = GetTopHierarchy(tkwin);
	if (winPtr != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->pathName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->pathName, -1));
	}
	break;
    case WIN_VIEWABLE: {
	int viewable = 0;

	for ( ; ; winPtr = winPtr->parentPtr) {
	    if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) {
		break;
	    }
	    if (winPtr->flags & TK_TOP_HIERARCHY) {
		viewable = 1;
		break;
	    }
	}

	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(viewable));
	break;
    }
    case WIN_VISUAL:
	c_class = Tk_Visual(tkwin)->c_class;
	class = Tk_Visual(tkwin)->class;

    visual:
	string = TkFindStateString(visualMap, c_class);
	string = TkFindStateString(visualMap, class);
	if (string == NULL) {
	    string = "unknown";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(string, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(string, -1));
	break;
    case WIN_VISUALID:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("0x%x", (unsigned)
		XVisualIDFromVisual(Tk_Visual(tkwin))));
	break;
    case WIN_VROOTHEIGHT:
	Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(height));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(height));
	break;
    case WIN_VROOTWIDTH:
	Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(width));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(width));
	break;
    case WIN_VROOTX:
	Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(x));
	break;
    case WIN_VROOTY:
	Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(y));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(y));
	break;
    case WIN_WIDTH:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_Width(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_Width(tkwin)));
	break;
    case WIN_X:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_X(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_X(tkwin)));
	break;
    case WIN_Y:
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tk_Y(tkwin)));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(Tk_Y(tkwin)));
	break;

	/*
	 * Uses -displayof.
	 */

    case WIN_ATOM:
	skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 3 + skip) {
	if (objc - skip != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? name");
	    return TCL_ERROR;
	}
	objv += skip;
	string = Tcl_GetString(objv[2]);
	Tcl_SetObjResult(interp,
		Tcl_NewWideIntObj(Tk_InternAtom(tkwin, string)));
		Tcl_NewLongObj((long) Tk_InternAtom(tkwin, string)));
	break;
    case WIN_ATOMNAME: {
	const char *name;
	Tcl_WideInt id;
	long id;

	skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 3 + skip) {
	if (objc - skip != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? id");
	    return TCL_ERROR;
	}
	objv += skip;
	if (Tcl_GetWideIntFromObj(interp, objv[2], &id) != TCL_OK) {
	if (Tcl_GetLongFromObj(interp, objv[2], &id) != TCL_OK) {
	    return TCL_ERROR;
	}
	name = Tk_GetAtomName(tkwin, (Atom) id);
	if (strcmp(name, "?bad atom?") == 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "no atom exists with id \"%s\"", Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "ATOM",
		    Tcl_GetString(objv[2]), NULL);
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(name, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
	break;
    }
    case WIN_CONTAINING:
	skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 4 + skip) {
	if (objc - skip != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "?-displayof window? rootX rootY");
	    return TCL_ERROR;
	}
	objv += skip;
	string = Tcl_GetString(objv[2]);
	if (Tk_GetPixels(interp, tkwin, string, &x) != TCL_OK) {
	    return TCL_ERROR;
	}
	string = Tcl_GetString(objv[3]);
	if (Tk_GetPixels(interp, tkwin, string, &y) != TCL_OK) {
	    return TCL_ERROR;
	}
	tkwin = Tk_CoordsToWindow(x, y, tkwin);
	if (tkwin != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(tkwin), TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(tkwin),-1));
	}
	break;
    case WIN_INTERPS:
	skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 2 + skip) {
	if (objc - skip != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?");
	    return TCL_ERROR;
	}
	return TkGetInterpNames(interp, tkwin);
    case WIN_PATHNAME: {
	Window id;

	skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 3 + skip) {
	if (objc - skip != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? id");
	    return TCL_ERROR;
	}
	string = Tcl_GetString(objv[2 + skip]);
	if (TkpScanWindowId(interp, string, &id) != TCL_OK) {
	    return TCL_ERROR;
	}
1688
1689
1690
1691
1692
1693
1694
1695

1696
1697
1698
1699
1700
1701
1702
1668
1669
1670
1671
1672
1673
1674

1675
1676
1677
1678
1679
1680
1681
1682







-
+







	 * If the window is a utility window with no associated path (such as
	 * a wrapper window or send communication window), just return an
	 * empty string.
	 */

	tkwin = (Tk_Window) winPtr;
	if (Tk_PathName(tkwin) != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(tkwin), TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(tkwin),-1));
	}
	break;
    }

	/*
	 * objv[3] is window.
	 */
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
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







-
+












-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-









-
+




















-
+

-
+


-
+





-
+



-
+


-
-
+
+


-
+



-
+






+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
-
+
+


-
-
+
+







-
+


-
+











-

-
+


-
-
-
+
+
+


-
+

-
+



-
+







	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin) != TCL_OK) {
	    return TCL_ERROR;
	}
	string = Tcl_GetString(objv[3]);
	if (Tk_GetPixels(interp, tkwin, string, &pixels) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pixels));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(pixels));
	break;
    }
    case WIN_RGB: {
	XColor *colorPtr;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window colorName");
	    return TCL_ERROR;
	}
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin) != TCL_OK) {
	    return TCL_ERROR;
	}
#ifdef TK_HAS_DYNAMIC_COLORS

	/*
	 * Make sure that the TkColor used for the winfo rgb command is
	 * destroyed when we are through with it, so we do not get stale RGB
	 * values next time.
	 */

	{
	    Colormap temp = Tk_Colormap(tkwin);
	    Tk_Colormap(tkwin) = TK_DYNAMIC_COLORMAP;
	    colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3]));
	colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3]));
	    Tk_Colormap(tkwin) = temp;
	}
#else
	colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3]));
#endif
	if (colorPtr == NULL) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%d %d %d",
		colorPtr->red, colorPtr->green, colorPtr->blue));
	Tk_FreeColor(colorPtr);
	break;
    }
    case WIN_VISUALSAVAILABLE: {
	XVisualInfo templ, *visInfoPtr;
	XVisualInfo template, *visInfoPtr;
	int count, i;
	int includeVisualId;
	Tcl_Obj *strPtr, *resultPtr;
	char buf[16 + TCL_INTEGER_SPACE];
	char visualIdString[TCL_INTEGER_SPACE];

	if (objc == 3) {
	    includeVisualId = 0;
	} else if ((objc == 4)
		&& (strcmp(Tcl_GetString(objv[3]), "includeids") == 0)) {
	    includeVisualId = 1;
	} else {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?includeids?");
	    return TCL_ERROR;
	}

	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin) != TCL_OK) {
	    return TCL_ERROR;
	}

	templ.screen = Tk_ScreenNumber(tkwin);
	template.screen = Tk_ScreenNumber(tkwin);
	visInfoPtr = XGetVisualInfo(Tk_Display(tkwin), VisualScreenMask,
		&templ, &count);
		&template, &count);
	if (visInfoPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't find any visuals for screen", TCL_INDEX_NONE));
		    "can't find any visuals for screen", -1));
	    Tcl_SetErrorCode(interp, "TK", "VISUAL", "NONE", NULL);
	    return TCL_ERROR;
	}
	resultPtr = Tcl_NewObj();
	for (i = 0; i < count; i++) {
	    string = TkFindStateString(visualMap, visInfoPtr[i].c_class);
	    string = TkFindStateString(visualMap, visInfoPtr[i].class);
	    if (string == NULL) {
		strcpy(buf, "unknown");
	    } else {
		snprintf(buf, sizeof(buf), "%s %d", string, visInfoPtr[i].depth);
		sprintf(buf, "%s %d", string, visInfoPtr[i].depth);
	    }
	    if (includeVisualId) {
		snprintf(visualIdString, sizeof(visualIdString), " 0x%lx",
			(unsigned long) visInfoPtr[i].visualid);
		sprintf(visualIdString, " 0x%x",
			(unsigned) visInfoPtr[i].visualid);
		strcat(buf, visualIdString);
	    }
	    strPtr = Tcl_NewStringObj(buf, TCL_INDEX_NONE);
	    strPtr = Tcl_NewStringObj(buf, -1);
	    Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
	}
	Tcl_SetObjResult(interp, resultPtr);
	XFree(visInfoPtr);
	XFree((char *) visInfoPtr);
	break;
    }
    }
    return TCL_OK;
}

#if 0
/*
 *----------------------------------------------------------------------

 *
 * Tk_WmObjCmd --
 *
 *	This function is invoked to process the "wm" Tcl command. See the user
 *	documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_WmObjCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin;
    TkWindow *winPtr;

    static const char *const optionStrings[] = {
	"aspect",	"client",	"command",	"deiconify",
	"focusmodel",	"frame",	"geometry",	"grid",
	"group",	"iconbitmap",	"iconify",	"iconmask",
	"iconname",	"iconposition",	"iconwindow",	"maxsize",
	"minsize",	"overrideredirect",	"positionfrom",	"protocol",
	"resizable",	"sizefrom",	"state",	"title",
	"tracing",	"transient",	"withdraw",	NULL
    };
    enum options {
	TKWM_ASPECT,	TKWM_CLIENT,	TKWM_COMMAND,	TKWM_DEICONIFY,
	TKWM_FOCUSMOD,	TKWM_FRAME,	TKWM_GEOMETRY,	TKWM_GRID,
	TKWM_GROUP,	TKWM_ICONBMP,	TKWM_ICONIFY,	TKWM_ICONMASK,
	TKWM_ICONNAME,	TKWM_ICONPOS,	TKWM_ICONWIN,	TKWM_MAXSIZE,
	TKWM_MINSIZE,	TKWM_OVERRIDE,	TKWM_POSFROM,	TKWM_PROTOCOL,
	TKWM_RESIZABLE,	TKWM_SIZEFROM,	TKWM_STATE,	TKWM_TITLE,
	TKWM_TRACING,	TKWM_TRANSIENT,	TKWM_WITHDRAW
    };

    tkwin = (Tk_Window) clientData;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0,
	    &index) != TCL_OK) {
	return TCL_ERROR;
    }

    if (index == TKWM_TRACING) {
	int wmTracing;
	TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

	if ((objc != 2) && (objc != 3)) {
	    Tcl_WrongNumArgs(interp, 1, objv, "tracing ?boolean?");
	    return TCL_ERROR;
	}
	if (objc == 2) {
	    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		    dispPtr->flags & TK_DISPLAY_WM_TRACING));
	    return TCL_OK;
	}
	if (Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (wmTracing) {
	    dispPtr->flags |= TK_DISPLAY_WM_TRACING;
	} else {
	    dispPtr->flags &= ~TK_DISPLAY_WM_TRACING;
	}
	return TCL_OK;
    }

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?arg?");
	return TCL_ERROR;
    }

    winPtr = (TkWindow *) Tk_NameToWindow(interp,
	    Tcl_GetString(objv[2]), tkwin);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }
    if (!(winPtr->flags & TK_TOP_LEVEL)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window \"%s\" isn't a top-level window", winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TOPLEVEL", winPtr->pathName,
		NULL);
	return TCL_ERROR;
    }

    switch ((enum options) index) {
    case TKWM_ASPECT:
	TkpWmAspectCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_CLIENT:
	TkpWmClientCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_COMMAND:
	TkpWmCommandCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_DEICONIFY:
	TkpWmDeiconifyCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_FOCUSMOD:
	TkpWmFocusmodCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_FRAME:
	TkpWmFrameCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_GEOMETRY:
	TkpWmGeometryCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_GRID:
	TkpWmGridCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_GROUP:
	TkpWmGroupCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONBMP:
	TkpWmIconbitmapCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONIFY:
	TkpWmIconifyCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONMASK:
	TkpWmIconmaskCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONNAME:
	/*
	 * Slight Unix variation.
	 */
	TkpWmIconnameCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONPOS:
	/*
	 * nearly same - 1 line more on Unix.
	 */
	TkpWmIconpositionCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_ICONWIN:
	TkpWmIconwindowCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_MAXSIZE:
	/*
	 * Nearly same, win diffs.
	 */
	TkpWmMaxsizeCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_MINSIZE:
	/*
	 * Nearly same, win diffs
	 */
	TkpWmMinsizeCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_OVERRIDE:
	/*
	 * Almost same.
	 */
	TkpWmOverrideCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_POSFROM:
	/*
	 * Equal across platforms
	 */
	TkpWmPositionfromCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_PROTOCOL:
	/*
	 * Equal across platforms
	 */
	TkpWmProtocolCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_RESIZABLE:
	/*
	 * Almost same
	 */
	TkpWmResizableCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_SIZEFROM:
	/*
	 * Equal across platforms
	 */
	TkpWmSizefromCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_STATE:
	TkpWmStateCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_TITLE:
	TkpWmTitleCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_TRANSIENT:
	TkpWmTransientCmd(interp, tkwin, winPtr, objc, objv);
	break;
    case TKWM_WITHDRAW:
	TkpWmWithdrawCmd(interp, tkwin, winPtr, objc, objv);
	break;
    }

  updateGeom:
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
    return TCL_OK;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * TkGetDisplayOf --
 *
 *	Parses a "-displayof window" option for various commands. If present,
 *	the literal "-displayof" should be in objv[0] and the window name in
 *	objv[1].
 *
 * Results:
 *	The return value is 0 if the argument strings did not contain the
 *	"-displayof" option. The return value is 2 if the argument strings
 *	contained both the "-displayof" option and a valid window name.
 *	Otherwise, the return value is TCL_INDEX_NONE if the window name
 *	was missing or did not specify a valid window.
 *	Otherwise, the return value is -1 if the window name was missing or
 *	did not specify a valid window.
 *
 *	If the return value was 2, *tkwinPtr is filled with the token for the
 *	window specified on the command line. If the return value was
 *	TCL_INDEX_NONE, an error message is left in interp's result object.
 *	window specified on the command line. If the return value was -1, an
 *	error message is left in interp's result object.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_Size
int
TkGetDisplayOf(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tcl_Size objc,		/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. If it is present,
				 * "-displayof" should be in objv[0] and
				 * objv[1] the name of a window. */
    Tk_Window *tkwinPtr)	/* On input, contains main window of
				 * application associated with interp. On
				 * output, filled with window specified as
				 * option to "-displayof" argument, or
				 * unmodified if "-displayof" argument was not
				 * present. */
{
    const char *string;
    Tcl_Size length;

    if (objc + 1 < 2) {
    if (objc < 1) {
	return 0;
    }
    string = Tcl_GetStringFromObj(objv[0], &length);
    if ((length >= 2) &&
	    (strncmp(string, "-displayof", length) == 0)) {
    string = Tcl_GetString(objv[0]);
    if ((objv[0]->length >= 2) &&
	    (strncmp(string, "-displayof", objv[0]->length) == 0)) {
        if (objc < 2) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "value for \"-displayof\" missing", TCL_INDEX_NONE));
		    "value for \"-displayof\" missing", -1));
	    Tcl_SetErrorCode(interp, "TK", "NO_VALUE", "DISPLAYOF", NULL);
	    return TCL_INDEX_NONE;
	    return -1;
	}
	*tkwinPtr = Tk_NameToWindow(interp, Tcl_GetString(objv[1]), *tkwinPtr);
	if (*tkwinPtr == NULL) {
	    return TCL_INDEX_NONE;
	    return -1;
	}
	return 2;
    }
    return 0;
}

/*
1924
1925
1926
1927
1928
1929
1930

1931
1932
1933

1934
1935
1936


1937
1938
1939
1940
1941
1942
1943
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113

2114
2115


2116
2117
2118
2119
2120
2121
2122
2123
2124







+


-
+

-
-
+
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
TkDeadAppObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Dummy. */
    Tcl_Interp *interp,		/* Current interpreter. */
    TCL_UNUSED(int),		/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "can't invoke \"%s\" command: application has been destroyed",
	    Tcl_GetString(objv[0])));
    return TCL_ERROR;
}

1958
1959
1960
1961
1962
1963
1964
1965

1966
1967
1968
1969
1970
1971
1972
2139
2140
2141
2142
2143
2144
2145

2146
2147
2148
2149
2150
2151
2152
2153







-
+







 *
 *----------------------------------------------------------------------
 */

static TkWindow *
GetTopHierarchy(
    Tk_Window tkwin)		/* Window for which the top-of-hierarchy
				 * ancestor should be determined. */
				 * ancestor should be deterined. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;

    while ((winPtr != NULL) && !(winPtr->flags & TK_TOP_HIERARCHY)) {
	winPtr = winPtr->parentPtr;
    }
    return winPtr;

Changes to generic/tkColor.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


61
62
63
64

65
66
67
68
69
70
71
72
73
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17




18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58
59

60


61
62
63
64
65
66
67







-
-
+
+








-
-
-
-
















-
+




















-
-
+
+



-
+
-
-







/*
 * tkColor.c --
 *
 *	This file maintains a database of color values for the Tk toolkit, in
 *	order to avoid round-trips to the server to map color names to pixel
 *	values.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "tkColor.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Structures of the following following type are used as keys for
 * colorValueTable (in TkDisplay).
 */

typedef struct {
    int red, green, blue;	/* Values for desired color. */
    Colormap colormap;		/* Colormap from which color will be
				 * allocated. */
    Display *display;		/* Display for colormap. */
} ValueKey;

/*
 * The structure below is used to allocate thread-local data.
 */

typedef struct {
typedef struct ThreadSpecificData {
    char rgbString[20];		/* */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Forward declarations for functions defined in this file:
 */

static void		ColorInit(TkDisplay *dispPtr);
static void		DupColorObjProc(Tcl_Obj *srcObjPtr,Tcl_Obj *dupObjPtr);
static void		FreeColorObj(Tcl_Obj *objPtr);
static void		FreeColorObjProc(Tcl_Obj *objPtr);
static void		InitColorObj(Tcl_Obj *objPtr);

/*
 * The following structure defines the implementation of the "color" Tcl
 * object, which maps a string color name to a TkColor object. The ptr1 field
 * of the Tcl_Obj points to a TkColor object.
 */

const TkObjType tkColorObjType = {
    {"color",			/* name */
const Tcl_ObjType tkColorObjType = {
    "color",			/* name */
    FreeColorObjProc,		/* freeIntRepProc */
    DupColorObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_AllocColorFromObj --
 *
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105







-
+







    Tk_Window tkwin,		/* Window in which the color will be used.*/
    Tcl_Obj *objPtr)		/* Object that describes the color; string
				 * value is a color name such as "red" or
				 * "#ff0000".*/
{
    TkColor *tkColPtr;

    if (objPtr->typePtr != &tkColorObjType.objType) {
    if (objPtr->typePtr != &tkColorObjType) {
	InitColorObj(objPtr);
    }
    tkColPtr = (TkColor *) objPtr->internalRep.twoPtrValue.ptr1;

    /*
     * If the object currently points to a TkColor, see if it's the one we
     * want. If so, increment its reference count and return.
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
+







    /*
     * The object didn't point to the TkColor that we wanted. Search the list
     * of TkColors with the same name to see if one of the other TkColors is
     * the right one.
     */

    if (tkColPtr != NULL) {
	TkColor *firstColorPtr = (TkColor *)Tcl_GetHashValue(tkColPtr->hashPtr);
	TkColor *firstColorPtr = Tcl_GetHashValue(tkColPtr->hashPtr);

	FreeColorObj(objPtr);
	for (tkColPtr = firstColorPtr; tkColPtr != NULL;
		tkColPtr = tkColPtr->nextPtr) {
	    if ((Tk_Screen(tkwin) == tkColPtr->screen)
		    && (Tk_Colormap(tkwin) == tkColPtr->colormap)) {
		tkColPtr->resourceRefCount++;
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213







-
+








    /*
     * First, check to see if there's already a mapping for this color name.
     */

    nameHashPtr = Tcl_CreateHashEntry(&dispPtr->colorNameTable, name, &isNew);
    if (!isNew) {
	existingColPtr = (TkColor *)Tcl_GetHashValue(nameHashPtr);
	existingColPtr = Tcl_GetHashValue(nameHashPtr);
	for (tkColPtr = existingColPtr; tkColPtr != NULL;
		tkColPtr = tkColPtr->nextPtr) {
	    if ((tkColPtr->screen == Tk_Screen(tkwin))
		    && (Tk_Colormap(tkwin) == tkColPtr->colormap)) {
		tkColPtr->resourceRefCount++;
		return &tkColPtr->color;
	    }
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+








    /*
     * Now create a new TkColor structure and add it to colorNameTable (in
     * TkDisplay).
     */

    tkColPtr->magic = COLOR_MAGIC;
    tkColPtr->gc = NULL;
    tkColPtr->gc = None;
    tkColPtr->screen = Tk_Screen(tkwin);
    tkColPtr->colormap = Tk_Colormap(tkwin);
    tkColPtr->visual = Tk_Visual(tkwin);
    tkColPtr->resourceRefCount = 1;
    tkColPtr->objRefCount = 0;
    tkColPtr->type = TK_COLOR_BY_NAME;
    tkColPtr->hashPtr = nameHashPtr;
316
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336







-
+











-
+







    valueKey.green = colorPtr->green;
    valueKey.blue = colorPtr->blue;
    valueKey.colormap = Tk_Colormap(tkwin);
    valueKey.display = display;
    valueHashPtr = Tcl_CreateHashEntry(&dispPtr->colorValueTable,
	    (char *) &valueKey, &isNew);
    if (!isNew) {
	tkColPtr = (TkColor *)Tcl_GetHashValue(valueHashPtr);
	tkColPtr = Tcl_GetHashValue(valueHashPtr);
	tkColPtr->resourceRefCount++;
	return &tkColPtr->color;
    }

    /*
     * The name isn't currently known. Find a pixel value for this color and
     * add a new structure to colorValueTable (in TkDisplay).
     */

    tkColPtr = TkpGetColorByValue(tkwin, colorPtr);
    tkColPtr->magic = COLOR_MAGIC;
    tkColPtr->gc = NULL;
    tkColPtr->gc = None;
    tkColPtr->screen = Tk_Screen(tkwin);
    tkColPtr->colormap = valueKey.colormap;
    tkColPtr->visual = Tk_Visual(tkwin);
    tkColPtr->resourceRefCount = 1;
    tkColPtr->objRefCount = 0;
    tkColPtr->type = TK_COLOR_BY_VALUE;
    tkColPtr->hashPtr = valueHashPtr;
365
366
367
368
369
370
371
372

373
374
375
376
377

378
379
380

381
382
383
384
385
386
387
359
360
361
362
363
364
365

366
367
368
369
370

371
372
373

374
375
376
377
378
379
380
381







-
+




-
+


-
+







 *--------------------------------------------------------------
 */

const char *
Tk_NameOfColor(
    XColor *colorPtr)		/* Color whose name is desired. */
{
    TkColor *tkColPtr = (TkColor *) colorPtr;
    register TkColor *tkColPtr = (TkColor *) colorPtr;

    if (tkColPtr->magic==COLOR_MAGIC && tkColPtr->type==TK_COLOR_BY_NAME) {
	return tkColPtr->hashPtr->key.string;
    } else {
	ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	ThreadSpecificData *tsdPtr =
		Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

	snprintf(tsdPtr->rgbString, sizeof(tsdPtr->rgbString), "#%04x%04x%04x", colorPtr->red,
	sprintf(tsdPtr->rgbString, "#%04x%04x%04x", colorPtr->red,
		colorPtr->green, colorPtr->blue);

	/*
	 * If the string has the form #RSRSTUTUVWVW (where equal letters
	 * denote equal hexdigits) then this is equivalent to #RSTUVW. Then
	 * output the shorter form.
	 */
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446







-
+







     * Tk_GetColor.
     */

    if (tkColPtr->magic != COLOR_MAGIC) {
	Tcl_Panic("Tk_GCForColor called with bogus color");
    }

    if (tkColPtr->gc == NULL) {
    if (tkColPtr->gc == None) {
	gcValues.foreground = tkColPtr->color.pixel;
	tkColPtr->gc = XCreateGC(DisplayOfScreen(tkColPtr->screen), drawable,
		GCForeground, &gcValues);
    }
    return tkColPtr->gc;
}

482
483
484
485
486
487
488

489

490
491
492
493
494
495
496
497
498
499

500
501

502
503
504
505

506
507
508
509
510
511
512
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493

494
495

496
497
498
499

500
501
502
503
504
505
506
507







+
-
+









-
+

-
+



-
+







     * Tk_GetColor.
     */

    if (tkColPtr->magic != COLOR_MAGIC) {
	Tcl_Panic("Tk_FreeColor called with bogus color");
    }

    tkColPtr->resourceRefCount--;
    if (tkColPtr->resourceRefCount-- > 1) {
    if (tkColPtr->resourceRefCount > 0) {
	return;
    }

    /*
     * This color is no longer being actively used, so free the color
     * resources associated with it and remove it from the hash table. No
     * longer any objects referencing it.
     */

    if (tkColPtr->gc != NULL) {
    if (tkColPtr->gc != None) {
	XFreeGC(DisplayOfScreen(screen), tkColPtr->gc);
	tkColPtr->gc = NULL;
	tkColPtr->gc = None;
    }
    TkpFreeColor(tkColPtr);

    prevPtr = (TkColor *)Tcl_GetHashValue(tkColPtr->hashPtr);
    prevPtr = Tcl_GetHashValue(tkColPtr->hashPtr);
    if (prevPtr == tkColPtr) {
	if (tkColPtr->nextPtr == NULL) {
	    Tcl_DeleteHashEntry(tkColPtr->hashPtr);
	} else {
	    Tcl_SetHashValue(tkColPtr->hashPtr, tkColPtr->nextPtr);
	}
    } else {
585
586
587
588
589
590
591
592

593
594

595

596
597
598
599
600
601
602
580
581
582
583
584
585
586

587
588
589
590

591
592
593
594
595
596
597
598







-
+


+
-
+







    objPtr->typePtr = NULL;
}

static void
FreeColorObj(
    Tcl_Obj *objPtr)		/* The object we are releasing. */
{
    TkColor *tkColPtr = (TkColor *)objPtr->internalRep.twoPtrValue.ptr1;
    TkColor *tkColPtr = objPtr->internalRep.twoPtrValue.ptr1;

    if (tkColPtr != NULL) {
	tkColPtr->objRefCount--;
	if ((tkColPtr->objRefCount-- <= 1)
	if ((tkColPtr->objRefCount == 0)
		&& (tkColPtr->resourceRefCount == 0)) {
	    ckfree(tkColPtr);
	}
	objPtr->internalRep.twoPtrValue.ptr1 = NULL;
    }
}

619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
615
616
617
618
619
620
621

622
623
624
625
626
627
628
629







-
+







 */

static void
DupColorObjProc(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    TkColor *tkColPtr = (TkColor *)srcObjPtr->internalRep.twoPtrValue.ptr1;
    TkColor *tkColPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;

    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep.twoPtrValue.ptr1 = tkColPtr;

    if (tkColPtr != NULL) {
	tkColPtr->objRefCount++;
    }
659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669
670
671

672
673
674
675
676
677
678
679







-
+









-
+







    Tcl_Obj *objPtr)		/* String value contains the name of the
				 * desired color. */
{
    TkColor *tkColPtr;
    Tcl_HashEntry *hashPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (objPtr->typePtr != &tkColorObjType.objType) {
    if (objPtr->typePtr != &tkColorObjType) {
	InitColorObj(objPtr);
    }

    /*
     * First check to see if the internal representation of the object is
     * defined and is a color that is valid for the current screen and color
     * map. If it is, we are done.
     */

    tkColPtr = (TkColor *)objPtr->internalRep.twoPtrValue.ptr1;
    tkColPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if ((tkColPtr != NULL)
	    && (tkColPtr->resourceRefCount > 0)
	    && (Tk_Screen(tkwin) == tkColPtr->screen)
	    && (Tk_Colormap(tkwin) == tkColPtr->colormap)) {
	/*
	 * The object already points to the right TkColor structure. Just
	 * return it.
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705







-
+







     */

    hashPtr = Tcl_FindHashEntry(&dispPtr->colorNameTable,
	    Tcl_GetString(objPtr));
    if (hashPtr == NULL) {
	goto error;
    }
    for (tkColPtr = (TkColor *)Tcl_GetHashValue(hashPtr);
    for (tkColPtr = Tcl_GetHashValue(hashPtr);
	    (tkColPtr != NULL); tkColPtr = tkColPtr->nextPtr) {
	if ((Tk_Screen(tkwin) == tkColPtr->screen)
		&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) {
	    FreeColorObj(objPtr);
	    objPtr->internalRep.twoPtrValue.ptr1 = tkColPtr;
	    tkColPtr->objRefCount++;
	    return (XColor *) tkColPtr;
747
748
749
750
751
752
753
754

755
756
757
758
759
760
761
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757







-
+







     */

    Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }
    objPtr->typePtr = &tkColorObjType.objType;
    objPtr->typePtr = &tkColorObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * ColorInit --
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827

828
829

830
831
832
833
834
835
836
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822

823
824

825
826
827
828
829
830
831
832







-
+








-
+

-
+







    Tcl_HashEntry *hashPtr;
    Tcl_Obj *resultPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    resultPtr = Tcl_NewObj();
    hashPtr = Tcl_FindHashEntry(&dispPtr->colorNameTable, name);
    if (hashPtr != NULL) {
	TkColor *tkColPtr = (TkColor *)Tcl_GetHashValue(hashPtr);
	TkColor *tkColPtr = Tcl_GetHashValue(hashPtr);

	if (tkColPtr == NULL) {
	    Tcl_Panic("TkDebugColor found empty hash table entry");
	}
	for ( ; (tkColPtr != NULL); tkColPtr = tkColPtr->nextPtr) {
	    Tcl_Obj *objPtr = Tcl_NewObj();

	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj((Tcl_WideInt)tkColPtr->resourceRefCount));
		    Tcl_NewIntObj(tkColPtr->resourceRefCount));
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj((Tcl_WideInt)tkColPtr->objRefCount));
		    Tcl_NewIntObj(tkColPtr->objRefCount));
	    Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
	}
    }
    return resultPtr;
}

#ifndef _WIN32

Changes to generic/tkColor.h.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkColor.h --
 *
 *	Declarations of data types and functions used by the Tk color module.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKCOLOR
#define _TKCOLOR
28
29
30
31
32
33
34
35

36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
28
29
30
31
32
33
34

35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-
+





-
+









-
+







typedef struct TkColor {
    XColor color;		/* Information about this color. */
    unsigned int magic;		/* Used for quick integrity check on this
				 * structure. Must always have the value
				 * COLOR_MAGIC. */
    GC gc;			/* Simple gc with this color as foreground
				 * color and all other fields defaulted. May
				 * be NULL. */
				 * be None. */
    Screen *screen;		/* Screen where this color is valid. Used to
				 * delete it, and to find its display. */
    Colormap colormap;		/* Colormap from which this entry was
				 * allocated. */
    Visual *visual;		/* Visual associated with colormap. */
    Tcl_Size resourceRefCount;	/* Number of active uses of this color (each
    int resourceRefCount;	/* Number of active uses of this color (each
				 * active use corresponds to a call to
				 * Tk_AllocColorFromObj or Tk_GetColor). If
				 * this count is 0, then this TkColor
				 * structure is no longer valid and it isn't
				 * present in a hash table: it is being kept
				 * around only because there are objects
				 * referring to it. The structure is freed
				 * when resourceRefCount and objRefCount are
				 * both 0. */
    Tcl_Size objRefCount;		/* The number of Tcl objects that reference
    int objRefCount;		/* The number of Tcl objects that reference
				 * this structure. */
    int type;			/* TK_COLOR_BY_NAME or TK_COLOR_BY_VALUE. */
    Tcl_HashEntry *hashPtr;	/* Pointer to hash table entry for this
				 * structure. (for use in deleting entry). */
    struct TkColor *nextPtr;	/* Points to the next TkColor structure with
				 * the same color name. Colors with the same
				 * name but different screens or colormaps are

Changes to generic/tkConfig.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkConfig.c --
 *
 *	This file contains functions that manage configuration options for
 *	widgets and other things.
 *
 * Copyright © 1997-1998 Sun Microsystems, Inc.
 * Copyright (c) 1997-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Temporary flag for working on new config package.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
22
23
24
25
26
27
28














29
30
31
32
33

34
35
36
37
38
39
40
41







-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+








#define __NO_OLD_CONFIG
#endif

#include "tkInt.h"
#include "tkFont.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The following encoding is used in TK_OPTION_VAR:
 *
 * if sizeof(type) == sizeof(int)        =>    TK_OPTION_VAR(type) = 0
 * if sizeof(type) == 1                  =>    TK_OPTION_VAR(type) = 64
 * if sizeof(type) == 2                  =>    TK_OPTION_VAR(type) = 128
 * if sizeof(type) == sizeof(long long)  =>    TK_OPTION_VAR(type) = 192
 */
#define TYPE_MASK        (((((int)sizeof(int)-1))|3)<<6)

/*
 * The following definition keeps track of all of
 * the option tables that have been created for a thread.
 */

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;		/* 0 means table below needs initializing. */
    Tcl_HashTable hashTable;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;


/*
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







    Tcl_Obj *defaultPtr;	/* Default value for this option. */
    union {
	Tcl_Obj *monoColorPtr;	/* For color and border options, this is an
				 * alternate default value to use on
				 * monochrome displays. */
	struct TkOption *synonymPtr;
				/* For synonym options, this points to the
				 * original entry. */
				 * master entry. */
	const struct Tk_ObjCustomOption *custom;
				/* For TK_OPTION_CUSTOM. */
    } extra;
    int flags;			/* Miscellaneous flag values; see below for
				 * definitions. */
} Option;

125
126
127
128
129
130
131
132

133
134
135
136
137


138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156


157
158
159
160

161
162
163
164
165
166
167
168
169
111
112
113
114
115
116
117

118
119
120
121


122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140


141
142
143
144
145

146


147
148
149
150
151
152
153







-
+



-
-
+
+

-
+















-
-
+
+



-
+
-
-







				 * will be numOptions, not 1. */
} OptionTable;

/*
 * Forward declarations for functions defined later in this file:
 */

static int		DoObjConfig(Tcl_Interp *interp, void *recordPtr,
static int		DoObjConfig(Tcl_Interp *interp, char *recordPtr,
			    Option *optionPtr, Tcl_Obj *valuePtr,
			    Tk_Window tkwin, Tk_SavedOption *savePtr);
static void		FreeResources(Option *optionPtr, Tcl_Obj *objPtr,
			    void *internalPtr, Tk_Window tkwin);
static Tcl_Obj *	GetConfigList(void *recordPtr,
			    char *internalPtr, Tk_Window tkwin);
static Tcl_Obj *	GetConfigList(char *recordPtr,
			    Option *optionPtr, Tk_Window tkwin);
static Tcl_Obj *	GetObjectForOption(void *recordPtr,
static Tcl_Obj *	GetObjectForOption(char *recordPtr,
			    Option *optionPtr, Tk_Window tkwin);
static Option *		GetOption(const char *name, OptionTable *tablePtr);
static Option *		GetOptionFromObj(Tcl_Interp *interp,
			    Tcl_Obj *objPtr, OptionTable *tablePtr);
static int		ObjectIsEmpty(Tcl_Obj *objPtr);
static void		FreeOptionInternalRep(Tcl_Obj *objPtr);
static void		DupOptionInternalRep(Tcl_Obj *, Tcl_Obj *);

/*
 * The structure below defines an object type that is used to cache the result
 * of looking up an option name. If an object has this type, then its
 * internalPtr1 field points to the OptionTable in which it was looked up, and
 * the internalPtr2 field points to the entry that matched.
 */

static const TkObjType optionObjType = {
    {"option",			/* name */
static const Tcl_ObjType optionObjType = {
    "option",			/* name */
    FreeOptionInternalRep,	/* freeIntRepProc */
    DupOptionInternalRep,	/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *--------------------------------------------------------------
 *
 * Tk_CreateOptionTable --
 *
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188







-
+







{
    Tcl_HashEntry *hashEntryPtr;
    int newEntry;
    OptionTable *tablePtr;
    const Tk_OptionSpec *specPtr, *specPtr2;
    Option *optionPtr;
    size_t numOptions, i;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * We use an TSD in the thread to keep a hash table of
     * all the option tables we've created for this application. This is
     * used for allowing us to share the tables (e.g. in several chains).
     * The code below finds the hash table or creates a new one if it
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257


258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294

295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277

278
279
280
281

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310







-
+













-
+




















-
-
+
+




















-
+






-
+








-
+



-
+




















-
+







     * See if a table has already been created for this template. If so, just
     * reuse the existing table.
     */

    hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->hashTable, (char *) templatePtr,
	    &newEntry);
    if (!newEntry) {
	tablePtr = (OptionTable *)Tcl_GetHashValue(hashEntryPtr);
	tablePtr = Tcl_GetHashValue(hashEntryPtr);
	tablePtr->refCount++;
	return (Tk_OptionTable) tablePtr;
    }

    /*
     * Count the number of options in the template, then create the table
     * structure.
     */

    numOptions = 0;
    for (specPtr = templatePtr; specPtr->type != TK_OPTION_END; specPtr++) {
	numOptions++;
    }
    tablePtr = (OptionTable *)ckalloc(sizeof(OptionTable) + (numOptions * sizeof(Option)));
    tablePtr = ckalloc(sizeof(OptionTable) + (numOptions * sizeof(Option)));
    tablePtr->refCount = 1;
    tablePtr->hashEntryPtr = hashEntryPtr;
    tablePtr->nextPtr = NULL;
    tablePtr->numOptions = numOptions;

    /*
     * Initialize all of the Option structures in the table.
     */

    for (specPtr = templatePtr, optionPtr = tablePtr->options;
	    specPtr->type != TK_OPTION_END; specPtr++, optionPtr++) {
	optionPtr->specPtr = specPtr;
	optionPtr->dbNameUID = NULL;
	optionPtr->dbClassUID = NULL;
	optionPtr->defaultPtr = NULL;
	optionPtr->extra.monoColorPtr = NULL;
	optionPtr->flags = 0;

	if (specPtr->type == TK_OPTION_SYNONYM) {
	    /*
	     * This is a synonym option; find the original option that it refers
	     * to and create a pointer from the synonym to the origin.
	     * This is a synonym option; find the master option that it refers
	     * to and create a pointer from the synonym to the master.
	     */

	    for (specPtr2 = templatePtr, i = 0; ; specPtr2++, i++) {
		if (specPtr2->type == TK_OPTION_END) {
		    Tcl_Panic("Tk_CreateOptionTable couldn't find synonym");
		}
		if (strcmp(specPtr2->optionName,
			(char *) specPtr->clientData) == 0) {
		    optionPtr->extra.synonymPtr = tablePtr->options + i;
		    break;
		}
	    }
	} else {
	    if (specPtr->dbName != NULL) {
		optionPtr->dbNameUID = Tk_GetUid(specPtr->dbName);
	    }
	    if (specPtr->dbClass != NULL) {
		optionPtr->dbClassUID = Tk_GetUid(specPtr->dbClass);
	    }
	    if (specPtr->defValue != NULL) {
		optionPtr->defaultPtr = Tcl_NewStringObj(specPtr->defValue, TCL_INDEX_NONE);
		optionPtr->defaultPtr = Tcl_NewStringObj(specPtr->defValue,-1);
		Tcl_IncrRefCount(optionPtr->defaultPtr);
	    }
	    if (((specPtr->type == TK_OPTION_COLOR)
		    || (specPtr->type == TK_OPTION_BORDER))
		    && (specPtr->clientData != NULL)) {
		optionPtr->extra.monoColorPtr =
			Tcl_NewStringObj((const char *)specPtr->clientData, TCL_INDEX_NONE);
			Tcl_NewStringObj(specPtr->clientData, -1);
		Tcl_IncrRefCount(optionPtr->extra.monoColorPtr);
	    }

	    if (specPtr->type == TK_OPTION_CUSTOM) {
		/*
		 * Get the custom parsing, etc., functions.
		 */

		optionPtr->extra.custom = (const Tk_ObjCustomOption *)specPtr->clientData;
		optionPtr->extra.custom = specPtr->clientData;
	    }
	}
	if (((specPtr->type == TK_OPTION_STRING)
		&& (specPtr->internalOffset != TCL_INDEX_NONE))
		&& (specPtr->internalOffset >= 0))
		|| (specPtr->type == TK_OPTION_COLOR)
		|| (specPtr->type == TK_OPTION_FONT)
		|| (specPtr->type == TK_OPTION_BITMAP)
		|| (specPtr->type == TK_OPTION_BORDER)
		|| (specPtr->type == TK_OPTION_CURSOR)
		|| (specPtr->type == TK_OPTION_CUSTOM)) {
	    optionPtr->flags |= OPTION_NEEDS_FREEING;
	}
    }
    tablePtr->hashEntryPtr = hashEntryPtr;
    Tcl_SetHashValue(hashEntryPtr, tablePtr);

    /*
     * Finally, check to see if this template chains to another template with
     * additional options. If so, call ourselves recursively to create the
     * next table(s).
     */

    if (specPtr->clientData != NULL) {
	tablePtr->nextPtr = (OptionTable *)
		Tk_CreateOptionTable(interp, (Tk_OptionSpec *)specPtr->clientData);
		Tk_CreateOptionTable(interp, specPtr->clientData);
    }

    return (Tk_OptionTable) tablePtr;
}

/*
 *----------------------------------------------------------------------
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406







-
+














-
+







 *--------------------------------------------------------------
 */

int
Tk_InitOptions(
    Tcl_Interp *interp,		/* Interpreter for error reporting. NULL means
				 * don't leave an error message. */
    void *recordPtr,		/* Pointer to the record to configure. Note:
    char *recordPtr,		/* Pointer to the record to configure. Note:
				 * the caller should have properly initialized
				 * the record with NULL pointers for each
				 * option value. */
    Tk_OptionTable optionTable,	/* The token which matches the config specs
				 * for the widget in question. */
    Tk_Window tkwin)		/* Certain options types (such as
				 * TK_OPTION_COLOR) need fields out of the
				 * window they are used in to be able to
				 * calculate their values. Not needed unless
				 * one of these options is in the configSpecs
				 * record. */
{
    OptionTable *tablePtr = (OptionTable *) optionTable;
    Option *optionPtr;
    size_t count;
    int count;
    Tk_Uid value;
    Tcl_Obj *valuePtr;
    enum {
	OPTION_DATABASE, SYSTEM_DEFAULT, TABLE_DEFAULT
    } source;

    /*
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
440
441
442
443
444
445
446

447
448
449
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+










-
+







	 */

	valuePtr = NULL;
	if (optionPtr->dbNameUID != NULL) {
	    value = Tk_GetOption(tkwin, optionPtr->dbNameUID,
		    optionPtr->dbClassUID);
	    if (value != NULL) {
		valuePtr = Tcl_NewStringObj(value, TCL_INDEX_NONE);
		valuePtr = Tcl_NewStringObj(value, -1);
		source = OPTION_DATABASE;
	    }
	}

	/*
	 * Second, check for a system-specific default value.
	 */

	if ((valuePtr == NULL)
		&& (optionPtr->dbNameUID != NULL)) {
	    valuePtr = Tk_GetSystemDefault(tkwin, optionPtr->dbNameUID,
	    valuePtr = TkpGetSystemDefault(tkwin, optionPtr->dbNameUID,
		    optionPtr->dbClassUID);
	    if (valuePtr != NULL) {
		source = SYSTEM_DEFAULT;
	    }
	}

	/*
511
512
513
514
515
516
517
518

519
520
521
522

523
524
525
526

527
528
529
530

531
532
533
534
535
536
537
495
496
497
498
499
500
501

502
503
504
505

506
507
508
509

510
511
512
513

514
515
516
517
518
519
520
521







-
+



-
+



-
+



-
+







	if (DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin,
		NULL) != TCL_OK) {
	    if (interp != NULL) {
		char msg[200];

		switch (source) {
		case OPTION_DATABASE:
		    snprintf(msg, 200, "\n    (database entry for \"%.50s\")",
		    sprintf(msg, "\n    (database entry for \"%.50s\")",
			    optionPtr->specPtr->optionName);
		    break;
		case SYSTEM_DEFAULT:
		    snprintf(msg, 200, "\n    (system default for \"%.50s\")",
		    sprintf(msg, "\n    (system default for \"%.50s\")",
			    optionPtr->specPtr->optionName);
		    break;
		case TABLE_DEFAULT:
		    snprintf(msg, 200, "\n    (default value for \"%.50s\")",
		    sprintf(msg, "\n    (default value for \"%.50s\")",
			    optionPtr->specPtr->optionName);
		}
		if (tkwin != NULL) {
		    snprintf(msg + strlen(msg) - 1, 200 - (strlen(msg) - 1), " in widget \"%.50s\")",
		    sprintf(msg + strlen(msg) - 1, " in widget \"%.50s\")",
			    Tk_PathName(tkwin));
		}
		Tcl_AddErrorInfo(interp, msg);
	    }
	    Tcl_DecrRefCount(valuePtr);
	    return TCL_ERROR;
	}
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604


605
606
607
608
609
610
611
612
613
614
615
616
617


618
619
620
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656


657
658
659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679
680






681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757

758
759
760
761
762
763
764
765

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786





787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805


806
807
808
809
810
811
812
813
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586


587
588
589
590
591
592
593
594
595
596
597
598
599


600
601
602
603
604
605
606
607
608
609
610
611

612
613
614
615
616




617




618
619
620













621
622

623
624
625
626
627
628





629












630
631
632
633
634
635




















636
637





















638
639
640
641
642


643



644

645








646
647
648
649
650
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679









680
681
682
683
684





685













686
687

688
689
690
691
692
693
694







-
+















-
+


-
+












-
-
+
+











-
-
+
+










-
+




-
-
-
-
+
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-






-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
-
+
-
-
-

-
+
-
-
-
-
-
-
-
-













-
+







-
+












-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-







 */

static int
DoObjConfig(
    Tcl_Interp *interp,		/* Interpreter for error reporting. If NULL,
				 * then no message is left if an error
				 * occurs. */
    void *recordPtr,		/* The record to modify to hold the new option
    char *recordPtr,		/* The record to modify to hold the new option
				 * value. */
    Option *optionPtr,		/* Pointer to information about the option. */
    Tcl_Obj *valuePtr,		/* New value for option. */
    Tk_Window tkwin,		/* Window in which option will be used (needed
				 * to allocate resources for some options).
				 * May be NULL if the option doesn't require
				 * window-related resources. */
    Tk_SavedOption *savedOptionPtr)
				/* If NULL, the old value for the option will
				 * be freed. If non-NULL, the old value will
				 * be stored here, and it becomes the property
				 * of the caller (the caller must eventually
				 * free the old value). */
{
    Tcl_Obj **slotPtrPtr, *oldPtr;
    void *internalPtr;		/* Points to location in record where internal
    char *internalPtr;		/* Points to location in record where internal
				 * representation of value should be stored,
				 * or NULL. */
    void *oldInternalPtr;	/* Points to location in which to save old
    char *oldInternalPtr;	/* Points to location in which to save old
				 * internal representation of value. */
    Tk_SavedOption internal;	/* Used to save the old internal
				 * representation of the value if
				 * savedOptionPtr is NULL. */
    const Tk_OptionSpec *specPtr;
    int nullOK;

    /*
     * Save the old object form for the value, if there is one.
     */

    specPtr = optionPtr->specPtr;
    if (specPtr->objOffset != TCL_INDEX_NONE) {
	slotPtrPtr = (Tcl_Obj **) ((char *)recordPtr + specPtr->objOffset);
    if (specPtr->objOffset >= 0) {
	slotPtrPtr = (Tcl_Obj **) (recordPtr + specPtr->objOffset);
	oldPtr = *slotPtrPtr;
    } else {
	slotPtrPtr = NULL;
	oldPtr = NULL;
    }

    /*
     * Apply the new value in a type-specific way. Also remember the old
     * object and internal forms, if they exist.
     */

    if (specPtr->internalOffset != TCL_INDEX_NONE) {
	internalPtr = (char *)recordPtr + specPtr->internalOffset;
    if (specPtr->internalOffset >= 0) {
	internalPtr = recordPtr + specPtr->internalOffset;
    } else {
	internalPtr = NULL;
    }
    if (savedOptionPtr != NULL) {
	savedOptionPtr->optionPtr = optionPtr;
	savedOptionPtr->valuePtr = oldPtr;
	oldInternalPtr = (char *) &savedOptionPtr->internalForm;
    } else {
	oldInternalPtr = (char *) &internal.internalForm;
    }
    nullOK = (optionPtr->specPtr->flags & (TK_OPTION_NULL_OK|TCL_NULL_OK));
    nullOK = (optionPtr->specPtr->flags & TK_OPTION_NULL_OK);
    switch (optionPtr->specPtr->type) {
    case TK_OPTION_BOOLEAN: {
	int newBool;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newBool = -1;
	} else if (Tcl_GetBooleanFromObj(nullOK ? NULL : interp, valuePtr, &newBool) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, valuePtr, &newBool) != TCL_OK) {
	    if (nullOK && interp) {
		Tcl_AppendResult(interp, "expected boolean value or \"\" but got \"",
			Tcl_GetString(valuePtr), "\"", NULL);
	    }
	    return TCL_ERROR;
	}
	if (internalPtr != NULL) {
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    *((char *) oldInternalPtr) = *((char *) internalPtr);
		    *((char *) internalPtr) = (char)newBool;
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    *((short *) oldInternalPtr) = *((short *) internalPtr);
		    *((short *) internalPtr) = (short)newBool;
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_BOOLEAN");
		}
	    } else {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newBool;
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = newBool;
	    }
	}
	break;
    }
    case TK_OPTION_INT: {
	int newInt;

	if ((optionPtr->specPtr->flags & TYPE_MASK) == 0) {
	    if (nullOK && ObjectIsEmpty(valuePtr)) {
		valuePtr = NULL;
		newInt = INT_MIN;
	    } else if (Tcl_GetIntFromObj(nullOK ? NULL : interp, valuePtr, &newInt) != TCL_OK) {
	if (Tcl_GetIntFromObj(interp, valuePtr, &newInt) != TCL_OK) {
	    invalidIntValue:
		if (nullOK && interp) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "expected integer or \"\" but got \"%.50s\"", Tcl_GetString(valuePtr)));
		    Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", NULL);
		}
		return TCL_ERROR;
	    }
	    if (internalPtr != NULL) {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newInt;
	    }
	    return TCL_ERROR;
	}
	if (internalPtr != NULL) {
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = newInt;
	}
	} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TYPE_MASK) {
	    Tcl_WideInt newWideInt;
	    if (nullOK && ObjectIsEmpty(valuePtr)) {
		valuePtr = NULL;
		newWideInt = (sizeof(long) > sizeof(int)) ? LONG_MIN : LLONG_MIN;
	    } else if (Tcl_GetWideIntFromObj(nullOK ? NULL : interp, valuePtr, &newWideInt) != TCL_OK) {
		goto invalidIntValue;
	    }
		if (internalPtr != NULL) {
			if (sizeof(long) > sizeof(int)) {
			    *((long *) oldInternalPtr) = *((long *) internalPtr);
			    *((long *) internalPtr) = (long)newWideInt;
			} else {
			    *((long long *) oldInternalPtr) = *((long long *) internalPtr);
			    *((long long *) internalPtr) = (long long)newWideInt;
			}
		}
	} else {
	    Tcl_Panic("Invalid flags for %s", "TK_OPTION_INT");
	}
	break;
    }
    case TK_OPTION_INDEX: {
	Tcl_Size newIndex;

	if (TkGetIntForIndex(valuePtr, TCL_INDEX_NONE, 0, &newIndex) != TCL_OK) {
	    if (interp) {
		Tcl_AppendResult(interp, "bad index \"", Tcl_GetString(valuePtr),
			"\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"", NULL);
	    }
	    return TCL_ERROR;
	}
	if (newIndex < INT_MIN) {
	    newIndex = INT_MIN;
	} else if (newIndex > INT_MAX) {
	    newIndex = INT_MAX;
	}
	if (internalPtr != NULL) {
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = (int)newIndex;
	}
	break;
    }
    case TK_OPTION_DOUBLE: {
	double newDbl;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
#if defined(NAN)
	    newDbl = NAN;
	    newDbl = 0;
#else
	    newDbl = 0.0;
#endif
	} else {
	    if (Tcl_GetDoubleFromObj(nullOK ? NULL : interp, valuePtr, &newDbl) != TCL_OK) {
	    if (Tcl_GetDoubleFromObj(interp, valuePtr, &newDbl) != TCL_OK) {
		if (nullOK && interp) {
		    Tcl_Obj *msg = Tcl_NewStringObj("expected floating-point number or \"\" but got \"", TCL_INDEX_NONE);

		    Tcl_AppendLimitedToObj(msg, Tcl_GetString(valuePtr), TCL_INDEX_NONE, 50, "");
		    Tcl_AppendToObj(msg, "\"", TCL_INDEX_NONE);
		    Tcl_SetObjResult(interp, msg);
		    Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", NULL);
		}
		return TCL_ERROR;
	    }
	}

	if (internalPtr != NULL) {
	    *((double *) oldInternalPtr) = *((double *) internalPtr);
	    *((double *) internalPtr) = newDbl;
	}
	break;
    }
    case TK_OPTION_STRING: {
	char *newStr;
	const char *value;
	Tcl_Size length;
	int length;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	}
	if (internalPtr != NULL) {
	    if (valuePtr != NULL) {
		value = Tcl_GetStringFromObj(valuePtr, &length);
		newStr = (char *)ckalloc(length + 1);
		newStr = ckalloc(length + 1);
		strcpy(newStr, value);
	    } else {
		newStr = NULL;
	    }
	    *((char **) oldInternalPtr) = *((char **) internalPtr);
	    *((char **) internalPtr) = newStr;
	}
	break;
    }
    case TK_OPTION_STRING_TABLE: {
	int newValue;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newValue = -1;
	} else {
	    if (Tcl_GetIndexFromObjStruct(interp, valuePtr,
		    optionPtr->specPtr->clientData, sizeof(char *),
		    optionPtr->specPtr->optionName+1, (nullOK ? TCL_NULL_OK : 0), &newValue) != TCL_OK) {
		return TCL_ERROR;
	    }
	if (Tcl_GetIndexFromObjStruct(interp, valuePtr,
		optionPtr->specPtr->clientData, sizeof(char *),
		optionPtr->specPtr->optionName+1, 0, &newValue) != TCL_OK) {
	    return TCL_ERROR;
	}
	    if (slotPtrPtr != NULL && valuePtr != NULL) {
		valuePtr = Tcl_DuplicateObj(valuePtr);
		Tcl_InvalidateStringRep(valuePtr);
	    }
	}
	if (internalPtr != NULL) {
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    *((char *) oldInternalPtr) = *((char *) internalPtr);
		    *((char *) internalPtr) = (char)newValue;
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    *((short *) oldInternalPtr) = *((short *) internalPtr);
		    *((short *) internalPtr) = (short)newValue;
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_STRING_TABLE");
		}
	    } else {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newValue;
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = newValue;
	    }
	}
	break;
    }
    case TK_OPTION_COLOR: {
	XColor *newPtr;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
899
900
901
902
903
904
905
906
907
908
909




910
911
912
913
914
915
916
917
918
919
920

921
922
923



924
925
926
927
928
929
930
931
932
933
934
935
936

937
938
939
940

941
942
943
944
945
946
947
948
949
950
951
952

953
954
955
956
957

958
959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982
983
984

985
986
987
988
989

990
991
992
993
994
995
996

997
998
999
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022




1023
1024

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044






1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
780
781
782
783
784
785
786




787
788
789
790











791



792
793
794





795
796
797
798
799
800
801

802
803
804
805

806
807
808
809
810
811
812
813
814
815
816
817

818
819




820

821
822
823



824










825





826
827
828
829

830
831




832

833
834
835



836










837





838
839
840
841
842
843
844
845



846
847
848
849


850


851

852
853
854
855
856
857
858
859
860
861
862
863




864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888







-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
+
-
-
-
-
-







-
+



-
+











-
+

-
-
-
-
+
-



-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-




-
+

-
-
-
-
+
-



-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-








-
-
-
+
+
+
+
-
-
+
-
-

-












-
-
-
-
+
+
+
+
+
+











-
+







    }
    case TK_OPTION_RELIEF: {
	int newRelief;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newRelief = TK_RELIEF_NULL;
	} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkReliefStrings,
		"relief", (nullOK ? TCL_NULL_OK : 0), &newRelief) != TCL_OK) {
	    return TCL_ERROR;
	}
	} else {
	    if (Tk_GetReliefFromObj(interp, valuePtr, &newRelief) != TCL_OK) {
		return TCL_ERROR;
	    }
	if (internalPtr != NULL) {
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    *((char *) oldInternalPtr) = *((char *) internalPtr);
		    *((char *) internalPtr) = (char)newRelief;
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    *((short *) oldInternalPtr) = *((short *) internalPtr);
		    *((short *) internalPtr) = (short)newRelief;
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_RELIEF");
		}
	}
	    } else {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newRelief;
	if (internalPtr != NULL) {
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = newRelief;
	    }
	}
	if (slotPtrPtr != NULL && valuePtr != NULL) {
	    valuePtr = Tcl_DuplicateObj(valuePtr);
	    Tcl_InvalidateStringRep(valuePtr);
	}
	break;
    }
    case TK_OPTION_CURSOR: {
	Tk_Cursor newCursor;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    newCursor = NULL;
	    newCursor = None;
	    valuePtr = NULL;
	} else {
	    newCursor = Tk_AllocCursorFromObj(interp, tkwin, valuePtr);
	    if (newCursor == NULL) {
	    if (newCursor == None) {
		return TCL_ERROR;
	    }
	}
	if (internalPtr != NULL) {
	    *((Tk_Cursor *) oldInternalPtr) = *((Tk_Cursor *) internalPtr);
	    *((Tk_Cursor *) internalPtr) = newCursor;
	}
	Tk_DefineCursor(tkwin, newCursor);
	break;
    }
    case TK_OPTION_JUSTIFY: {
	int newJustify;
	Tk_Justify newJustify;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newJustify = -1;
	} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkJustifyStrings,
	if (Tk_GetJustifyFromObj(interp, valuePtr, &newJustify) != TCL_OK) {
		"justification", (nullOK ? TCL_NULL_OK : 0), &newJustify) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (internalPtr != NULL) {
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    *((char *) oldInternalPtr) = *((char *) internalPtr);
	    *((Tk_Justify *) oldInternalPtr) = *((Tk_Justify *) internalPtr);
		    *((char *) internalPtr) = (char)newJustify;
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    *((short *) oldInternalPtr) = *((short *) internalPtr);
		    *((short *) internalPtr) = (short)newJustify;
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
		}
	    } else {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newJustify;
	    *((Tk_Justify *) internalPtr) = newJustify;
	    }
	}
	if (slotPtrPtr != NULL && valuePtr != NULL) {
	    valuePtr = Tcl_DuplicateObj(valuePtr);
	    Tcl_InvalidateStringRep(valuePtr);
	}
	break;
    }
    case TK_OPTION_ANCHOR: {
	int newAnchor;
	Tk_Anchor newAnchor;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newAnchor = -1;
	} else if (Tcl_GetIndexFromObj(interp, valuePtr, tkAnchorStrings,
	if (Tk_GetAnchorFromObj(interp, valuePtr, &newAnchor) != TCL_OK) {
		"anchor", (nullOK ? TCL_NULL_OK : 0), &newAnchor) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (internalPtr != NULL) {
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    *((char *) oldInternalPtr) = *((char *) internalPtr);
	    *((Tk_Anchor *) oldInternalPtr) = *((Tk_Anchor *) internalPtr);
		    *((char *) internalPtr) = (char)newAnchor;
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    *((short *) oldInternalPtr) = *((short *) internalPtr);
		    *((short *) internalPtr) = (short)newAnchor;
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
		}
	    } else {
		*((int *) oldInternalPtr) = *((int *) internalPtr);
		*((int *) internalPtr) = newAnchor;
	    *((Tk_Anchor *) internalPtr) = newAnchor;
	    }
	}
	if (slotPtrPtr != NULL && valuePtr != NULL) {
	    valuePtr = Tcl_DuplicateObj(valuePtr);
	    Tcl_InvalidateStringRep(valuePtr);
	}
	break;
    }
    case TK_OPTION_PIXELS: {
	int newPixels;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newPixels = INT_MIN;
	} else if (Tk_GetPixelsFromObj(nullOK ? NULL : interp, tkwin, valuePtr,
		&newPixels) != TCL_OK) {
	    newPixels = 0;
	} else {
	    if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr,
		    &newPixels) != TCL_OK) {
	    if (nullOK && interp) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		return TCL_ERROR;
		    "expected screen distance or \"\" but got \"%.50s\"", Tcl_GetString(valuePtr)));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
	    }
	    return TCL_ERROR;
	}
	if (internalPtr != NULL) {
	    *((int *) oldInternalPtr) = *((int *) internalPtr);
	    *((int *) internalPtr) = newPixels;
	}
	break;
    }
    case TK_OPTION_WINDOW: {
	Tk_Window newWin;

	if (nullOK && ObjectIsEmpty(valuePtr)) {
	    valuePtr = NULL;
	    newWin = NULL;
	} else if (TkGetWindowFromObj(interp, tkwin, valuePtr,
		&newWin) != TCL_OK) {
	    return TCL_ERROR;
	    newWin = None;
	} else {
	    if (TkGetWindowFromObj(interp, tkwin, valuePtr,
		    &newWin) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	if (internalPtr != NULL) {
	    *((Tk_Window *) oldInternalPtr) = *((Tk_Window *) internalPtr);
	    *((Tk_Window *) internalPtr) = newWin;
	}
	break;
    }
    case TK_OPTION_CUSTOM: {
	const Tk_ObjCustomOption *custom = optionPtr->extra.custom;

	if (custom->setProc(custom->clientData, interp, tkwin,
		&valuePtr, (char *)recordPtr, optionPtr->specPtr->internalOffset,
		&valuePtr, recordPtr, optionPtr->specPtr->internalOffset,
		(char *)oldInternalPtr, optionPtr->specPtr->flags) != TCL_OK) {
	    return TCL_ERROR;
	}
	break;
    }

    default:
1107
1108
1109
1110
1111
1112
1113


1114
1115
1116
1117
1118


1119

1120

1121
1122
1123
1124
1125
1126
1127
932
933
934
935
936
937
938
939
940
941
942
943


944
945
946
947

948
949
950
951
952
953
954
955







+
+



-
-
+
+

+
-
+







 *----------------------------------------------------------------------
 */

static int
ObjectIsEmpty(
    Tcl_Obj *objPtr)		/* Object to test. May be NULL. */
{
    int length;

    if (objPtr == NULL) {
	return 1;
    }
    if (objPtr->bytes == NULL) {
	Tcl_GetString(objPtr);
    if (objPtr->bytes != NULL) {
	return (objPtr->length == 0);
    }
    (void)Tcl_GetStringFromObj(objPtr, &length);
    return (objPtr->length == 0);
    return (length == 0);
}

/*
 *----------------------------------------------------------------------
 *
 * GetOption --
 *
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079







-
+







    Option *bestPtr;
    const char *name;

    /*
     * First, check to see if the object already has the answer cached.
     */

    if (objPtr->typePtr == &optionObjType.objType) {
    if (objPtr->typePtr == &optionObjType) {
	if (objPtr->internalRep.twoPtrValue.ptr1 == (void *) tablePtr) {
	    return (Option *) objPtr->internalRep.twoPtrValue.ptr2;
	}
    }

    /*
     * The answer isn't cached.
1259
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101







-
+








    if ((objPtr->typePtr != NULL)
	    && (objPtr->typePtr->freeIntRepProc != NULL)) {
	objPtr->typePtr->freeIntRepProc(objPtr);
    }
    objPtr->internalRep.twoPtrValue.ptr1 = (void *) tablePtr;
    objPtr->internalRep.twoPtrValue.ptr2 = (void *) bestPtr;
    objPtr->typePtr = &optionObjType.objType;
    objPtr->typePtr = &optionObjType;
    tablePtr->refCount++;
    return bestPtr;

  error:
    if (interp != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"unknown option \"%s\"", name));
1331
1332
1333
1334
1335
1336
1337
1338

1339
1340

1341
1342
1343
1344
1345
1346
1347
1159
1160
1161
1162
1163
1164
1165

1166
1167

1168
1169
1170
1171
1172
1173
1174
1175







-
+

-
+







 *	cleanup is delayed until the last reference goes away.
 *
 *----------------------------------------------------------------------
 */

static void
FreeOptionInternalRep(
    Tcl_Obj *objPtr)	/* Object whose internal rep to free. */
    register Tcl_Obj *objPtr)	/* Object whose internal rep to free. */
{
    Tk_OptionTable tablePtr = (Tk_OptionTable) objPtr->internalRep.twoPtrValue.ptr1;
    register Tk_OptionTable tablePtr = (Tk_OptionTable) objPtr->internalRep.twoPtrValue.ptr1;

    Tk_DeleteOptionTable(tablePtr);
    objPtr->typePtr = NULL;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
    objPtr->internalRep.twoPtrValue.ptr2 = NULL;
}

1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199







-
+







 */

static void
DupOptionInternalRep(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    OptionTable *tablePtr = (OptionTable *) srcObjPtr->internalRep.twoPtrValue.ptr1;
    register OptionTable *tablePtr = (OptionTable *) srcObjPtr->internalRep.twoPtrValue.ptr1;
    tablePtr->refCount++;
    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep = srcObjPtr->internalRep;
}

/*
 *--------------------------------------------------------------
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402

1403
1404
1405
1406
1407
1408
1409
1221
1222
1223
1224
1225
1226
1227

1228
1229

1230
1231
1232
1233
1234
1235
1236
1237







-
+

-
+







 *--------------------------------------------------------------
 */

int
Tk_SetOptions(
    Tcl_Interp *interp,		/* Interpreter for error reporting. If NULL,
				 * then no error message is returned.*/
    void *recordPtr,	    	/* The record to configure. */
    char *recordPtr,	    	/* The record to configure. */
    Tk_OptionTable optionTable,	/* Describes valid options. */
    Tcl_Size objc,			/* The number of elements in objv. */
    int objc,			/* The number of elements in objv. */
    Tcl_Obj *const objv[],	/* Contains one or more name-value pairs. */
    Tk_Window tkwin,		/* Window associated with the thing being
				 * configured; needed for some options (such
				 * as colors). */
    Tk_SavedOptions *savePtr,	/* If non-NULL, the old values of modified
				 * options are saved here so that they can be
				 * restored after an error. */
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296







-
+







	if ((savePtr != NULL)
		&& (lastSavePtr->numItems >= TK_NUM_SAVED_OPTIONS)) {
	    /*
	     * We've run out of space for saving old option values. Allocate
	     * more space.
	     */

	    newSavePtr = (Tk_SavedOptions *)ckalloc(sizeof(Tk_SavedOptions));
	    newSavePtr = ckalloc(sizeof(Tk_SavedOptions));
	    newSavePtr->recordPtr = recordPtr;
	    newSavePtr->tkwin = tkwin;
	    newSavePtr->numItems = 0;
	    newSavePtr->nextPtr = NULL;
	    lastSavePtr->nextPtr = newSavePtr;
	    lastSavePtr = newSavePtr;
	}
1511
1512
1513
1514
1515
1516
1517
1518

1519
1520
1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350

1351
1352
1353
1354
1355
1356
1357
1358







-
+




-
+







 */

void
Tk_RestoreSavedOptions(
    Tk_SavedOptions *savePtr)	/* Holds saved option information; must have
				 * been passed to Tk_SetOptions. */
{
    Tcl_Size i;
    int i;
    Option *optionPtr;
    Tcl_Obj *newPtr;		/* New object value of option, which we
				 * replace with old value and free. Taken from
				 * record. */
    void *internalPtr;		/* Points to internal value of option in
    char *internalPtr;		/* Points to internal value of option in
				 * record. */
    const Tk_OptionSpec *specPtr;

    /*
     * Be sure to restore the options in the opposite order they were set.
     * This is important because it's possible that the same option name was
     * used twice in a single call to Tk_SetOptions.
1541
1542
1543
1544
1545
1546
1547
1548

1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569


1570
1571
1572
1573


1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652

1653
1654
1655
1656
1657
1658
1659
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
1369
1370
1371
1372
1373
1374
1375

1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395


1396
1397
1398
1399


1400
1401
1402
1403
1404
1405










1406

1407
1408















1409
1410
1411
1412
1413
1414
1415
1416
1417










1418

1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435










1436

1437
1438
1439
1440
1441
1442










1443

1444
1445



1446








1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466







-
+




-
+














-
-
+
+


-
-
+
+




-
-
-
-
-
-
-
-
-
-
+
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
-
-
-
-
-
-
-
-
+
-

















-
-
-
-
-
-
-
-
-
-
+
-






-
-
-
-
-
-
-
-
-
-
+
-


-
-
-
+
-
-
-
-
-
-
-
-












-
+








	/*
	 * First free the new value of the option, which is currently in the
	 * record.
	 */

	if (specPtr->objOffset >= 0) {
	    newPtr = *((Tcl_Obj **) ((char *)savePtr->recordPtr + specPtr->objOffset));
	    newPtr = *((Tcl_Obj **) (savePtr->recordPtr + specPtr->objOffset));
	} else {
	    newPtr = NULL;
	}
	if (specPtr->internalOffset >= 0) {
	    internalPtr = (char *)savePtr->recordPtr + specPtr->internalOffset;
	    internalPtr = savePtr->recordPtr + specPtr->internalOffset;
	} else {
	    internalPtr = NULL;
	}
	if (optionPtr->flags & OPTION_NEEDS_FREEING) {
	    FreeResources(optionPtr, newPtr, internalPtr, savePtr->tkwin);
	}
	if (newPtr != NULL) {
	    Tcl_DecrRefCount(newPtr);
	}

	/*
	 * Now restore the old value of the option.
	 */

	if (specPtr->objOffset != TCL_INDEX_NONE) {
	    *((Tcl_Obj **) ((char *)savePtr->recordPtr + specPtr->objOffset))
	if (specPtr->objOffset >= 0) {
	    *((Tcl_Obj **) (savePtr->recordPtr + specPtr->objOffset))
		    = savePtr->items[i].valuePtr;
	}
	if (specPtr->internalOffset != TCL_INDEX_NONE) {
	    char *ptr = (char *) &savePtr->items[i].internalForm;
	if (specPtr->internalOffset >= 0) {
	    register char *ptr = (char *) &savePtr->items[i].internalForm;

	    CLANG_ASSERT(internalPtr);
	    switch (specPtr->type) {
	    case TK_OPTION_BOOLEAN:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
			*((char *) internalPtr) = *((char *) ptr);
		    } else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
			*((short *) internalPtr) = *((short *) ptr);
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_BOOLEAN");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		*((int *) internalPtr) = *((int *) ptr);
		}
		break;
	    case TK_OPTION_INT:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TYPE_MASK) {
			if (sizeof(long) > sizeof(int)) {
			    *((long *) internalPtr) = *((long *) ptr);
			} else {
			    *((long long *) internalPtr) = *((long long *) ptr);
			}
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_INT");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		}
		break;
	    case TK_OPTION_INDEX:
		*((int *) internalPtr) = *((int *) ptr);
		break;
	    case TK_OPTION_DOUBLE:
		*((double *) internalPtr) = *((double *) ptr);
		break;
	    case TK_OPTION_STRING:
		*((char **) internalPtr) = *((char **) ptr);
		break;
	    case TK_OPTION_STRING_TABLE:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
			*((char *) internalPtr) = *((char *) ptr);
		    } else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
			*((short *) internalPtr) = *((short *) ptr);
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_STRING_TABLE");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		*((int *) internalPtr) = *((int *) ptr);
		}
		break;
	    case TK_OPTION_COLOR:
		*((XColor **) internalPtr) = *((XColor **) ptr);
		break;
	    case TK_OPTION_FONT:
		*((Tk_Font *) internalPtr) = *((Tk_Font *) ptr);
		break;
	    case TK_OPTION_STYLE:
		*((Tk_Style *) internalPtr) = *((Tk_Style *) ptr);
		break;
	    case TK_OPTION_BITMAP:
		*((Pixmap *) internalPtr) = *((Pixmap *) ptr);
		break;
	    case TK_OPTION_BORDER:
		*((Tk_3DBorder *) internalPtr) = *((Tk_3DBorder *) ptr);
		break;
	    case TK_OPTION_RELIEF:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
			*((char *) internalPtr) = *((char *) ptr);
		    } else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
			*((short *) internalPtr) = *((short *) ptr);
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_RELIEF");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		*((int *) internalPtr) = *((int *) ptr);
		}
		break;
	    case TK_OPTION_CURSOR:
		*((Tk_Cursor *) internalPtr) = *((Tk_Cursor *) ptr);
		Tk_DefineCursor(savePtr->tkwin, *((Tk_Cursor *) internalPtr));
		break;
	    case TK_OPTION_JUSTIFY:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
			*((char *) internalPtr) = *((char *) ptr);
		    } else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
			*((short *) internalPtr) = *((short *) ptr);
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		*((Tk_Justify *) internalPtr) = *((Tk_Justify *) ptr);
		}
		break;
	    case TK_OPTION_ANCHOR:
		if (optionPtr->specPtr->flags & TYPE_MASK) {
		    if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
			*((char *) internalPtr) = *((char *) ptr);
		*((Tk_Anchor *) internalPtr) = *((Tk_Anchor *) ptr);
		    } else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
			*((short *) internalPtr) = *((short *) ptr);
		    } else {
			Tcl_Panic("Invalid flags for %s", "TK_OPTION_ANCHOR");
		    }
		} else {
		    *((int *) internalPtr) = *((int *) ptr);
		}
		break;
	    case TK_OPTION_PIXELS:
		*((int *) internalPtr) = *((int *) ptr);
		break;
	    case TK_OPTION_WINDOW:
		*((Tk_Window *) internalPtr) = *((Tk_Window *) ptr);
		break;
	    case TK_OPTION_CUSTOM: {
		const Tk_ObjCustomOption *custom = optionPtr->extra.custom;

		if (custom->restoreProc != NULL) {
		    custom->restoreProc(custom->clientData, savePtr->tkwin,
			    (char *)internalPtr, ptr);
			    internalPtr, ptr);
		}
		break;
	    }
	    default:
		Tcl_Panic("bad option type in Tk_RestoreSavedOptions");
	    }
	}
1723
1724
1725
1726
1727
1728
1729
1730

1731
1732
1733
1734
1735
1736
1737
1738



1739
1740
1741
1742
1743
1744
1745
1486
1487
1488
1489
1490
1491
1492

1493
1494
1495
1496
1497
1498
1499


1500
1501
1502
1503
1504
1505
1506
1507
1508
1509







-
+






-
-
+
+
+







 */

void
Tk_FreeSavedOptions(
    Tk_SavedOptions *savePtr)	/* Contains options saved in a previous call
				 * to Tk_SetOptions. */
{
    size_t count;
    int count;
    Tk_SavedOption *savedOptionPtr;

    if (savePtr->nextPtr != NULL) {
	Tk_FreeSavedOptions(savePtr->nextPtr);
	ckfree(savePtr->nextPtr);
    }
    for (count = savePtr->numItems; count > 0; count--) {
	savedOptionPtr = &savePtr->items[count-1];
    for (count = savePtr->numItems,
	    savedOptionPtr = &savePtr->items[savePtr->numItems-1];
	    count > 0;  count--, savedOptionPtr--) {
	if (savedOptionPtr->optionPtr->flags & OPTION_NEEDS_FREEING) {
	    FreeResources(savedOptionPtr->optionPtr, savedOptionPtr->valuePtr,
		    (char *) &savedOptionPtr->internalForm, savePtr->tkwin);
	}
	if (savedOptionPtr->valuePtr != NULL) {
	    Tcl_DecrRefCount(savedOptionPtr->valuePtr);
	}
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
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553


1554
1555
1556
1557
1558
1559
1560


1561
1562
1563
1564
1565
1566
1567
1568
1569







+


-
+









-
+










-
-
+
+





-
-
+
+







 * Side effects:
 *	All of the Tcl_Obj's in recordPtr that are controlled by configuration
 *	options in optionTable are freed.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
void
Tk_FreeConfigOptions(
    void *recordPtr,		/* Record whose fields contain current values
    char *recordPtr,		/* Record whose fields contain current values
				 * for options. */
    Tk_OptionTable optionTable,	/* Describes legal options. */
    Tk_Window tkwin)		/* Window associated with recordPtr; needed
				 * for freeing some options. */
{
    OptionTable *tablePtr;
    Option *optionPtr;
    size_t count;
    Tcl_Obj **oldPtrPtr, *oldPtr;
    void *oldInternalPtr;
    char *oldInternalPtr;
    const Tk_OptionSpec *specPtr;

    for (tablePtr = (OptionTable *) optionTable; tablePtr != NULL;
	    tablePtr = tablePtr->nextPtr) {
	for (optionPtr = tablePtr->options, count = tablePtr->numOptions;
		count > 0; optionPtr++, count--) {
	    specPtr = optionPtr->specPtr;
	    if (specPtr->type == TK_OPTION_SYNONYM) {
		continue;
	    }
	    if (specPtr->objOffset != TCL_INDEX_NONE) {
		oldPtrPtr = (Tcl_Obj **) ((char *)recordPtr + specPtr->objOffset);
	    if (specPtr->objOffset >= 0) {
		oldPtrPtr = (Tcl_Obj **) (recordPtr + specPtr->objOffset);
		oldPtr = *oldPtrPtr;
		*oldPtrPtr = NULL;
	    } else {
		oldPtr = NULL;
	    }
	    if (specPtr->internalOffset != TCL_INDEX_NONE) {
		oldInternalPtr = (char *)recordPtr + specPtr->internalOffset;
	    if (specPtr->internalOffset >= 0) {
		oldInternalPtr = recordPtr + specPtr->internalOffset;
	    } else {
		oldInternalPtr = NULL;
	    }
	    if (optionPtr->flags & OPTION_NEEDS_FREEING) {
		FreeResources(optionPtr, oldPtr, oldInternalPtr, tkwin);
	    }
	    if (oldPtr != NULL) {
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
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612

1613
1614
1615
1616
1617
1618
1619
1620







-
+


-
+










-
+







 */

static void
FreeResources(
    Option *optionPtr,		/* Description of the configuration option. */
    Tcl_Obj *objPtr,		/* The current value of the option, specified
				 * as an object. */
    void *internalPtr,		/* A pointer to an internal representation for
    char *internalPtr,		/* A pointer to an internal representation for
				 * the option's value, such as an int or
				 * (XColor *). Only valid if
				 * optionPtr->specPtr->internalOffset != -1. */
				 * optionPtr->specPtr->internalOffset >= 0. */
    Tk_Window tkwin)		/* The window in which this option is used. */
{
    int internalFormExists;

    /*
     * If there exists an internal form for the value, use it to free
     * resources (also zero out the internal form). If there is no internal
     * form, then use the object form.
     */

    internalFormExists = optionPtr->specPtr->internalOffset != TCL_INDEX_NONE;
    internalFormExists = optionPtr->specPtr->internalOffset >= 0;
    switch (optionPtr->specPtr->type) {
    case TK_OPTION_STRING:
	if (internalFormExists) {
	    if (*((char **) internalPtr) != NULL) {
		ckfree(*((char **) internalPtr));
		*((char **) internalPtr) = NULL;
	    }
1873
1874
1875
1876
1877
1878
1879


1880
1881
1882
1883
1884
1885
1886
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653







+
+







	    Tk_FreeFontFromObj(tkwin, objPtr);
	}
	break;
    case TK_OPTION_STYLE:
	if (internalFormExists) {
	    Tk_FreeStyle(*((Tk_Style *) internalPtr));
	    *((Tk_Style *) internalPtr) = NULL;
	} else if (objPtr != NULL) {
	    Tk_FreeStyleFromObj(objPtr);
	}
	break;
    case TK_OPTION_BITMAP:
	if (internalFormExists) {
	    if (*((Pixmap *) internalPtr) != None) {
		Tk_FreeBitmap(Tk_Display(tkwin), *((Pixmap *) internalPtr));
		*((Pixmap *) internalPtr) = None;
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
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







-
+

-
+








-
+







	    }
	} else if (objPtr != NULL) {
	    Tk_Free3DBorderFromObj(tkwin, objPtr);
	}
	break;
    case TK_OPTION_CURSOR:
	if (internalFormExists) {
	    if (*((Tk_Cursor *) internalPtr) != NULL) {
	    if (*((Tk_Cursor *) internalPtr) != None) {
		Tk_FreeCursor(Tk_Display(tkwin), *((Tk_Cursor *) internalPtr));
		*((Tk_Cursor *) internalPtr) = NULL;
		*((Tk_Cursor *) internalPtr) = None;
	    }
	} else if (objPtr != NULL) {
	    Tk_FreeCursorFromObj(tkwin, objPtr);
	}
	break;
    case TK_OPTION_CUSTOM: {
	const Tk_ObjCustomOption *custom = optionPtr->extra.custom;
	if (internalFormExists && custom->freeProc != NULL) {
	    custom->freeProc(custom->clientData, tkwin, (char *)internalPtr);
	    custom->freeProc(custom->clientData, tkwin, internalPtr);
	}
	break;
    }
    default:
	break;
    }
}
1947
1948
1949
1950
1951
1952
1953
1954

1955
1956
1957
1958
1959
1960
1961
1714
1715
1716
1717
1718
1719
1720

1721
1722
1723
1724
1725
1726
1727
1728







-
+







 *--------------------------------------------------------------
 */

Tcl_Obj *
Tk_GetOptionInfo(
    Tcl_Interp *interp,		/* Interpreter for error reporting. If NULL,
				 * then no error message is created. */
    void *recordPtr,		/* Record whose fields contain current values
    char *recordPtr,		/* Record whose fields contain current values
				 * for options. */
    Tk_OptionTable optionTable,	/* Describes all the legal options. */
    Tcl_Obj *namePtr,		/* If non-NULL, the string value selects a
				 * single option whose info is to be returned.
				 * Otherwise info is returned for all options
				 * in optionTable. */
    Tk_Window tkwin)		/* Window associated with recordPtr; needed to
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
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







-
+









-
+



-
+





-
+






-
+















-
-
+
+







 *	Memory is allocated.
 *
 *--------------------------------------------------------------
 */

static Tcl_Obj *
GetConfigList(
    void *recordPtr,		/* Pointer to record holding current values of
    char *recordPtr,		/* Pointer to record holding current values of
				 * configuration options. */
    Option *optionPtr,		/* Pointer to information describing a
				 * particular option. */
    Tk_Window tkwin)		/* Window corresponding to recordPtr. */
{
    Tcl_Obj *listPtr, *elementPtr;

    listPtr = Tcl_NewListObj(0, NULL);
    Tcl_ListObjAppendElement(NULL, listPtr,
	    Tcl_NewStringObj(optionPtr->specPtr->optionName, TCL_INDEX_NONE));
	    Tcl_NewStringObj(optionPtr->specPtr->optionName, -1));

    if (optionPtr->specPtr->type == TK_OPTION_SYNONYM) {
	elementPtr = Tcl_NewStringObj(
		optionPtr->extra.synonymPtr->specPtr->optionName, TCL_INDEX_NONE);
		optionPtr->extra.synonymPtr->specPtr->optionName, -1);
	Tcl_ListObjAppendElement(NULL, listPtr, elementPtr);
    } else {
	if (optionPtr->dbNameUID == NULL) {
	    elementPtr = Tcl_NewObj();
	} else {
	    elementPtr = Tcl_NewStringObj(optionPtr->dbNameUID, TCL_INDEX_NONE);
	    elementPtr = Tcl_NewStringObj(optionPtr->dbNameUID, -1);
	}
	Tcl_ListObjAppendElement(NULL, listPtr, elementPtr);

	if (optionPtr->dbClassUID == NULL) {
	    elementPtr = Tcl_NewObj();
	} else {
	    elementPtr = Tcl_NewStringObj(optionPtr->dbClassUID, TCL_INDEX_NONE);
	    elementPtr = Tcl_NewStringObj(optionPtr->dbClassUID, -1);
	}
	Tcl_ListObjAppendElement(NULL, listPtr, elementPtr);

	if ((tkwin != NULL) && ((optionPtr->specPtr->type == TK_OPTION_COLOR)
		|| (optionPtr->specPtr->type == TK_OPTION_BORDER))
		&& (Tk_Depth(tkwin) <= 1)
		&& (optionPtr->extra.monoColorPtr != NULL)) {
	    elementPtr = optionPtr->extra.monoColorPtr;
	} else if (optionPtr->defaultPtr != NULL) {
	    elementPtr = optionPtr->defaultPtr;
	} else {
	    elementPtr = Tcl_NewObj();
	}
	Tcl_ListObjAppendElement(NULL, listPtr, elementPtr);

	if (optionPtr->specPtr->objOffset != TCL_INDEX_NONE) {
	    elementPtr = *((Tcl_Obj **) ((char *)recordPtr
	if (optionPtr->specPtr->objOffset >= 0) {
	    elementPtr = *((Tcl_Obj **) (recordPtr
		    + optionPtr->specPtr->objOffset));
	    if (elementPtr == NULL) {
		elementPtr = Tcl_NewObj();
	    }
	} else {
	    elementPtr = GetObjectForOption(recordPtr, optionPtr, tkwin);
	}
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
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







-
+






-
-
+
+
+

-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
+
-
-
+
-
-
-
-
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetObjectForOption(
    void *recordPtr,		/* Pointer to record holding current values of
    char *recordPtr,		/* Pointer to record holding current values of
				 * configuration options. */
    Option *optionPtr,		/* Pointer to information describing an option
				 * whose internal value is stored in
				 * *recordPtr. */
    Tk_Window tkwin)		/* Window corresponding to recordPtr. */
{
    Tcl_Obj *objPtr = NULL;
    void *internalPtr;		/* Points to internal value of option in record. */
    Tcl_Obj *objPtr;
    char *internalPtr;		/* Points to internal value of option in
				 * record. */

    if (optionPtr->specPtr->internalOffset != TCL_INDEX_NONE) {
	internalPtr = (char *)recordPtr + optionPtr->specPtr->internalOffset;
	switch (optionPtr->specPtr->type) {
	case TK_OPTION_BOOLEAN: {
    internalPtr = recordPtr + optionPtr->specPtr->internalOffset;
    objPtr = NULL;
    switch (optionPtr->specPtr->type) {
    case TK_OPTION_BOOLEAN:
	    int value;
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    value = *((signed char *)internalPtr);
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    value = *((short *)internalPtr);
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_BOOLEAN");
		}
	    } else {
		value = *((int *)internalPtr);
	    }
	    if (value != -1) {
		objPtr = Tcl_NewBooleanObj(value);
	objPtr = Tcl_NewIntObj(*((int *) internalPtr));
	    }
	    break;
	break;
	}
	case TK_OPTION_INT: {
    case TK_OPTION_INT:
	    Tcl_WideInt value;
	    int nullOK = (optionPtr->specPtr->flags & (TK_OPTION_NULL_OK|TCL_NULL_OK));
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TYPE_MASK) {
		    if (sizeof(long) > sizeof(int)) {
			value = *((long *)internalPtr);
			if (nullOK && (value == LONG_MIN)) {break;}
	objPtr = Tcl_NewIntObj(*((int *) internalPtr));
	break;
		    } else {
			value = *((long long *)internalPtr);
			if (nullOK && (value == LLONG_MIN)) {break;}
		    }
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_INT");
    case TK_OPTION_DOUBLE:
		}
	    } else {
		value = *((int *)internalPtr);
		if (nullOK && (value == INT_MIN)) {break;}
	    }
		objPtr = Tcl_NewWideIntObj(value);
	    break;
	objPtr = Tcl_NewDoubleObj(*((double *) internalPtr));
	break;
	}
	case TK_OPTION_INDEX:
    case TK_OPTION_STRING:
	    if (!(optionPtr->specPtr->flags & (TK_OPTION_NULL_OK|TCL_NULL_OK)) || *((int *) internalPtr) != INT_MIN) {
		if (*((int *) internalPtr) == INT_MIN) {
		    objPtr = TkNewIndexObj(TCL_INDEX_NONE);
		} else if (*((int *) internalPtr) == INT_MAX) {
		    objPtr = Tcl_NewStringObj("end+1", TCL_INDEX_NONE);
		} else if (*((int *) internalPtr) == -1) {
		    objPtr = Tcl_NewStringObj("end", TCL_INDEX_NONE);
		} else if (*((int *) internalPtr) < 0) {
		    char buf[32];
	objPtr = Tcl_NewStringObj(*((char **) internalPtr), -1);
	break;
    case TK_OPTION_STRING_TABLE:
	objPtr = Tcl_NewStringObj(((char **) optionPtr->specPtr->clientData)[
		*((int *) internalPtr)], -1);
	break;
		    snprintf(buf, 32, "end%d", 1 + *((int *) internalPtr));
		    objPtr = Tcl_NewStringObj(buf, TCL_INDEX_NONE);
		} else {
		    objPtr = Tcl_NewWideIntObj(*((int *) internalPtr));
		}
	    }
	    break;
    case TK_OPTION_COLOR: {
	XColor *colorPtr = *((XColor **) internalPtr);

	if (colorPtr != NULL) {
	    objPtr = Tcl_NewStringObj(Tk_NameOfColor(colorPtr), -1);
	}
	break;
	case TK_OPTION_DOUBLE:
	    if (!(optionPtr->specPtr->flags & (TK_OPTION_NULL_OK|TCL_NULL_OK)) || !isnan(*((double *) internalPtr))) {
		objPtr = Tcl_NewDoubleObj(*((double *) internalPtr));
	    }
    }
	    break;
	case TK_OPTION_STRING:
    case TK_OPTION_FONT: {
	    objPtr = Tcl_NewStringObj(*((char **)internalPtr), TCL_INDEX_NONE);
	    break;
	case TK_OPTION_STRING_TABLE: {
	    int value = 0;
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    value = *((signed char *)internalPtr);
	Tk_Font tkfont = *((Tk_Font *) internalPtr);
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    value = *((short *)internalPtr);
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_STRING_TABLE");
		}

	    } else {
		value = *((int *)internalPtr);
	    }
	    if (value >= 0) {
		objPtr = Tcl_NewStringObj(((char **) optionPtr->specPtr->clientData)[
			value], TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_COLOR: {
	    XColor *colorPtr = *((XColor **)internalPtr);

	    if (colorPtr != NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfColor(colorPtr), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_FONT: {
	    Tk_Font tkfont = *((Tk_Font *)internalPtr);
	if (tkfont != NULL) {
	    objPtr = Tcl_NewStringObj(Tk_NameOfFont(tkfont), -1);
	}
	break;
    }
    case TK_OPTION_STYLE: {
	Tk_Style style = *((Tk_Style *) internalPtr);

	    if (tkfont != NULL) {
	if (style != NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfFont(tkfont), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_STYLE: {
	    Tk_Style style = *((Tk_Style *)internalPtr);

	    if (style != NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfStyle(style), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_BITMAP: {
	    Pixmap pixmap = *((Pixmap *)internalPtr);
	    objPtr = Tcl_NewStringObj(Tk_NameOfStyle(style), -1);
	}
	break;
    }
    case TK_OPTION_BITMAP: {
	Pixmap pixmap = *((Pixmap *) internalPtr);

	    if (pixmap != None) {
		objPtr = Tcl_NewStringObj(
		    Tk_NameOfBitmap(Tk_Display(tkwin), pixmap), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_BORDER: {
	    Tk_3DBorder border = *((Tk_3DBorder *)internalPtr);
	if (pixmap != None) {
	    objPtr = Tcl_NewStringObj(
		    Tk_NameOfBitmap(Tk_Display(tkwin), pixmap), -1);
	}
	break;
    }
    case TK_OPTION_BORDER: {
	Tk_3DBorder border = *((Tk_3DBorder *) internalPtr);

	    if (border != NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOf3DBorder(border), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_RELIEF: {
	if (border != NULL) {
	    objPtr = Tcl_NewStringObj(Tk_NameOf3DBorder(border), -1);
	}
	break;
    }
    case TK_OPTION_RELIEF:
	    int value;
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    value = *((signed char *)internalPtr);
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    value = *((short *)internalPtr);
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_RELIEF");
		}
	    } else {
		value = *((int *)internalPtr);
	    }
	    if (value != TK_RELIEF_NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfRelief(value), TCL_INDEX_NONE);
	objPtr = Tcl_NewStringObj(Tk_NameOfRelief(*((int *) internalPtr)), -1);
	    }
	    break;
	break;
	}
	case TK_OPTION_CURSOR: {
	    Tk_Cursor cursor = *((Tk_Cursor *)internalPtr);
    case TK_OPTION_CURSOR: {
	Tk_Cursor cursor = *((Tk_Cursor *) internalPtr);

	    if (cursor != NULL) {
		objPtr = Tcl_NewStringObj(
		Tk_NameOfCursor(Tk_Display(tkwin), cursor), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_JUSTIFY: {
	if (cursor != None) {
	    objPtr = Tcl_NewStringObj(
		    Tk_NameOfCursor(Tk_Display(tkwin), cursor), -1);
	}
	break;
    }
    case TK_OPTION_JUSTIFY:
	    Tk_Justify value;
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    value = (Tk_Justify)*((signed char *)internalPtr);
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    value = (Tk_Justify)*((short *)internalPtr);
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_JUSTIFY");
		}
	    } else {
		value = (Tk_Justify)*((int *)internalPtr);
	    }
	    if (value != TK_JUSTIFY_NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfJustify(value), TCL_INDEX_NONE);
	objPtr = Tcl_NewStringObj(Tk_NameOfJustify(
	    }
	    break;
		*((Tk_Justify *) internalPtr)), -1);
	break;
	}
	case TK_OPTION_ANCHOR: {
    case TK_OPTION_ANCHOR:
	    Tk_Anchor value;
	    if (optionPtr->specPtr->flags & TYPE_MASK) {
		if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
		    value = (Tk_Anchor)*((signed char *)internalPtr);
		} else if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(short)) {
		    value = (Tk_Anchor)*((short *)internalPtr);
		} else {
		    Tcl_Panic("Invalid flags for %s", "TK_OPTION_ANCHOR");
		}
	    } else {
		value = (Tk_Anchor)*((int *)internalPtr);
	    }
	    if (value != TK_ANCHOR_NULL) {
		objPtr = Tcl_NewStringObj(Tk_NameOfAnchor(value), TCL_INDEX_NONE);
	objPtr = Tcl_NewStringObj(Tk_NameOfAnchor(
	    }
	    break;
		*((Tk_Anchor *) internalPtr)), -1);
	break;
	}
	case TK_OPTION_PIXELS:
    case TK_OPTION_PIXELS:
	    if (!(optionPtr->specPtr->flags & (TK_OPTION_NULL_OK|TCL_NULL_OK)) || *((int *) internalPtr) != INT_MIN) {
		objPtr = Tcl_NewWideIntObj(*((int *)internalPtr));
	objPtr = Tcl_NewIntObj(*((int *) internalPtr));
	    }
	    break;
	case TK_OPTION_WINDOW: {
	    tkwin = *((Tk_Window *) internalPtr);
	break;
    case TK_OPTION_WINDOW: {
	Tk_Window tkwin = *((Tk_Window *) internalPtr);

	    if (tkwin != NULL) {
		objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), TCL_INDEX_NONE);
	    }
	    break;
	}
	case TK_OPTION_CUSTOM: {
	    const Tk_ObjCustomOption *custom = optionPtr->extra.custom;
	if (tkwin != NULL) {
	    objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
	}
	break;
    }
    case TK_OPTION_CUSTOM: {
	const Tk_ObjCustomOption *custom = optionPtr->extra.custom;

	    objPtr = custom->getProc(custom->clientData, tkwin, (char *)recordPtr,
		    optionPtr->specPtr->internalOffset);
	    break;
	}
	default:
	    Tcl_Panic("bad option type in GetObjectForOption");
	objPtr = custom->getProc(custom->clientData, tkwin, recordPtr,
		optionPtr->specPtr->internalOffset);
	break;
    }
    default:
	Tcl_Panic("bad option type in GetObjectForOption");
	}
    }
    if (objPtr == NULL) {
	objPtr = Tcl_NewObj();
    }
    return objPtr;
}

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
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







-
+

















-
-
+
+







 */

Tcl_Obj *
Tk_GetOptionValue(
    Tcl_Interp *interp,		/* Interpreter for error reporting. If NULL
				 * then no messages are provided for
				 * errors. */
    void *recordPtr,		/* Record whose fields contain current values
    char *recordPtr,		/* Record whose fields contain current values
				 * for options. */
    Tk_OptionTable optionTable,	/* Describes legal options. */
    Tcl_Obj *namePtr,		/* Gives the command-line name for the option
				 * whose value is to be returned. */
    Tk_Window tkwin)		/* Window corresponding to recordPtr. */
{
    OptionTable *tablePtr = (OptionTable *) optionTable;
    Option *optionPtr;
    Tcl_Obj *resultPtr;

    optionPtr = GetOptionFromObj(interp, namePtr, tablePtr);
    if (optionPtr == NULL) {
	return NULL;
    }
    if (optionPtr->specPtr->type == TK_OPTION_SYNONYM) {
	optionPtr = optionPtr->extra.synonymPtr;
    }
    if (optionPtr->specPtr->objOffset != TCL_INDEX_NONE) {
	resultPtr = *((Tcl_Obj **) ((char *)recordPtr+optionPtr->specPtr->objOffset));
    if (optionPtr->specPtr->objOffset >= 0) {
	resultPtr = *((Tcl_Obj **) (recordPtr+optionPtr->specPtr->objOffset));
	if (resultPtr == NULL) {
	    /*
	     * This option has a null value and is represented by a null
	     * object pointer. We can't return the null pointer, since that
	     * would indicate an error. Instead, return a new empty object.
	     */

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
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







-
+









-
+


















-
+

-
+

-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
TkDebugConfig(
    TCL_UNUSED(Tcl_Interp *),		/* Interpreter in which the table is
    Tcl_Interp *interp,		/* Interpreter in which the table is
				 * defined. */
    Tk_OptionTable table)	/* Table about which information is to be
				 * returned. May not necessarily exist in the
				 * interpreter anymore. */
{
    OptionTable *tablePtr = (OptionTable *) table;
    Tcl_HashEntry *hashEntryPtr;
    Tcl_HashSearch search;
    Tcl_Obj *objPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    objPtr = Tcl_NewObj();
    if (!tablePtr || !tsdPtr->initialized) {
	return objPtr;
    }

    /*
     * Scan all the tables for this interpreter to make sure that the one we
     * want still is valid.
     */

    for (hashEntryPtr = Tcl_FirstHashEntry(&tsdPtr->hashTable, &search);
	    hashEntryPtr != NULL;
	    hashEntryPtr = Tcl_NextHashEntry(&search)) {
	if (tablePtr == (OptionTable *) Tcl_GetHashValue(hashEntryPtr)) {
	    for ( ; tablePtr != NULL; tablePtr = tablePtr->nextPtr) {
		Tcl_ListObjAppendElement(NULL, objPtr,
			Tcl_NewWideIntObj((Tcl_WideInt)tablePtr->refCount));
			Tcl_NewWideIntObj(tablePtr->refCount));
		Tcl_ListObjAppendElement(NULL, objPtr,
			Tcl_NewWideIntObj((Tcl_WideInt)tablePtr->numOptions));
			Tcl_NewWideIntObj(tablePtr->numOptions));
		Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewStringObj(
			tablePtr->options[0].specPtr->optionName, TCL_INDEX_NONE));
			tablePtr->options[0].specPtr->optionName, -1));
	    }
	    break;
	}
    }
    return objPtr;
}


Changes to generic/tkConsole.c.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15







-
+







/*
 * tkConsole.c --
 *
 *	This file implements a Tcl console for systems that may not otherwise
 *	have access to a console. It uses the Text widget and provides special
 *	access via a console command.
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * 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.
 */

#include "tkInt.h"

39
40
41
42
43
44
45
46

47
48
49
50
51
52





53
54
55



56
57
58
59
60





61
62
63
64
65
66
67
68
69


70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
39
40
41
42
43
44
45

46






47
48
49
50
51
52


53
54
55
56




57
58
59
60
61
62
63
64
65
66
67
68


69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+
-
-
-
-
-
-
+
+
+
+
+

-
-
+
+
+

-
-
-
-
+
+
+
+
+







-
-
+
+







-
+







    int type;			/* TCL_STDOUT or TCL_STDERR */
} ChannelData;

/*
 * Prototypes for local procedures defined in this file:
 */

static int	ConsoleClose(void *instanceData, Tcl_Interp *interp);
static int	ConsoleClose(ClientData instanceData, Tcl_Interp *interp);
static int	Console2Close(void *instanceData, Tcl_Interp *interp, int flags);
static void	ConsoleDeleteProc(void *clientData);
static void	ConsoleEventProc(void *clientData, XEvent *eventPtr);
static int	ConsoleHandle(void *instanceData, int direction,
		    void **handlePtr);
static int	ConsoleInput(void *instanceData, char *buf, int toRead,
static void	ConsoleDeleteProc(ClientData clientData);
static void	ConsoleEventProc(ClientData clientData, XEvent *eventPtr);
static int	ConsoleHandle(ClientData instanceData, int direction,
		    ClientData *handlePtr);
static int	ConsoleInput(ClientData instanceData, char *buf, int toRead,
		    int *errorCode);
static Tcl_ObjCmdProc ConsoleObjCmd;
static int	ConsoleOutput(void *instanceData, const char *buf,
static int	ConsoleObjCmd(ClientData clientData, Tcl_Interp *interp,
		    int objc, Tcl_Obj *const objv[]);
static int	ConsoleOutput(ClientData instanceData, const char *buf,
		    int toWrite, int *errorCode);
static void	ConsoleWatch(void *instanceData, int mask);
static void	DeleteConsoleInterp(void *clientData);
static void	InterpDeleteProc(void *clientData, Tcl_Interp *interp);
static Tcl_ObjCmdProc InterpreterObjCmd;
static void	ConsoleWatch(ClientData instanceData, int mask);
static void	DeleteConsoleInterp(ClientData clientData);
static void	InterpDeleteProc(ClientData clientData, Tcl_Interp *interp);
static int	InterpreterObjCmd(ClientData clientData, Tcl_Interp *interp,
		    int objc, Tcl_Obj *const objv[]);

/*
 * This structure describes the channel type structure for file based IO:
 */

static const Tcl_ChannelType consoleChannelType = {
    "console",			/* Type name. */
    TCL_CHANNEL_VERSION_5,	/* v5 channel */
    (Tcl_DriverCloseProc *)ConsoleClose,		/* Close proc. */
    TCL_CHANNEL_VERSION_4,	/* v4 channel */
    ConsoleClose,		/* Close proc. */
    ConsoleInput,		/* Input proc. */
    ConsoleOutput,		/* Output proc. */
    NULL,			/* Seek proc. */
    NULL,			/* Set option proc. */
    NULL,			/* Get option proc. */
    ConsoleWatch,		/* Watch for events on console. */
    ConsoleHandle,		/* Get a handle from the device. */
    Console2Close,			/* close2proc. */
    NULL,			/* close2proc. */
    NULL,			/* Always non-blocking.*/
    NULL,			/* flush proc. */
    NULL,			/* handler proc. */
    NULL,			/* wide seek proc */
    NULL,			/* thread action proc */
    NULL
};
218
219
220
221
222
223
224
225

226
227
228
229

230
231
232
233
234
235
236
219
220
221
222
223
224
225

226
227
228
229

230
231
232
233
234
235
236
237







-
+



-
+







    ConsoleInfo *info;
    Tcl_Channel consoleChannel;

    /*
     * Ensure that we are getting a compatible version of Tcl.
     */

    if (Tcl_InitStubs(interp, "8.7-", 0) == NULL) {
    if (Tcl_InitStubs(interp, "8.6-", 0) == NULL) {
        return;
    }

    consoleInitPtr = (int *)Tcl_GetThreadData(&consoleInitKey, (int) sizeof(int));
    consoleInitPtr = Tcl_GetThreadData(&consoleInitKey, (int) sizeof(int));
    if (*consoleInitPtr) {
	/*
	 * We've already initialized console channels in this thread.
	 */

	return;
    }
250
251
252
253
254
255
256
257

258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
251
252
253
254
255
256
257

258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305







-
+





-
+
















-
+
















-
+







    }

    /*
     * At least one std channel wants to be tied to the console, so create the
     * interp for it to live in.
     */

    info = (ConsoleInfo *) ckalloc(sizeof(ConsoleInfo));
    info = ckalloc(sizeof(ConsoleInfo));
    info->consoleInterp = NULL;
    info->interp = NULL;
    info->refCount = 0;

    if (doIn) {
	ChannelData *data = (ChannelData *)ckalloc(sizeof(ChannelData));
	ChannelData *data = ckalloc(sizeof(ChannelData));

	data->info = info;
	data->info->refCount++;
	data->type = TCL_STDIN;
	consoleChannel = Tcl_CreateChannel(&consoleChannelType, "console0",
		data, TCL_READABLE);
	if (consoleChannel != NULL) {
	    Tcl_SetChannelOption(NULL, consoleChannel, "-translation", "lf");
	    Tcl_SetChannelOption(NULL, consoleChannel, "-buffering", "none");
	    Tcl_SetChannelOption(NULL, consoleChannel, "-encoding", "utf-8");
	}
	Tcl_SetStdChannel(consoleChannel, TCL_STDIN);
	Tcl_RegisterChannel(NULL, consoleChannel);
    }

    if (doOut) {
	ChannelData *data = (ChannelData *)ckalloc(sizeof(ChannelData));
	ChannelData *data = ckalloc(sizeof(ChannelData));

	data->info = info;
	data->info->refCount++;
	data->type = TCL_STDOUT;
	consoleChannel = Tcl_CreateChannel(&consoleChannelType, "console1",
		data, TCL_WRITABLE);
	if (consoleChannel != NULL) {
	    Tcl_SetChannelOption(NULL, consoleChannel, "-translation", "lf");
	    Tcl_SetChannelOption(NULL, consoleChannel, "-buffering", "none");
	    Tcl_SetChannelOption(NULL, consoleChannel, "-encoding", "utf-8");
	}
	Tcl_SetStdChannel(consoleChannel, TCL_STDOUT);
	Tcl_RegisterChannel(NULL, consoleChannel);
    }

    if (doErr) {
	ChannelData *data = (ChannelData *)ckalloc(sizeof(ChannelData));
	ChannelData *data = ckalloc(sizeof(ChannelData));

	data->info = info;
	data->info->refCount++;
	data->type = TCL_STDERR;
	consoleChannel = Tcl_CreateChannel(&consoleChannelType, "console2",
		data, TCL_WRITABLE);
	if (consoleChannel != NULL) {
313
314
315
316
317
318
319
320

321
322
323
324
325
326
327
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328







-
+








/*
 *----------------------------------------------------------------------
 *
 * Tk_CreateConsoleWindow --
 *
 *	Initialize the console. This code actually creates a new application
 *	and associated interpreter. This effectively hides the implementation
 *	and associated interpreter. This effectivly hides the implementation
 *	from the main application.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A new console it created.
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
340
341
342
343
344
345
346


347
348
349


350
351
352
353
354
355
356







-
-



-
-







    Tcl_Command token;
    int result = TCL_OK;
    int haveConsoleChannel = 1;

    /* Init an interp with Tcl and Tk */
    Tcl_Interp *consoleInterp = Tcl_CreateInterp();
    if (Tcl_Init(consoleInterp) != TCL_OK) {
	Tcl_Obj *result_obj = Tcl_GetObjResult(consoleInterp);
	Tcl_SetObjResult(interp, result_obj);
	goto error;
    }
    if (Tk_Init(consoleInterp) != TCL_OK) {
	Tcl_Obj *result_obj = Tcl_GetObjResult(consoleInterp);
	Tcl_SetObjResult(interp, result_obj);
	goto error;
    }

    /*
     * Fetch the instance data from whatever std channel is a
     * console channel.  If none, create fresh instance data.
     */
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383







-
+







	ChannelData *data = (ChannelData *) Tcl_GetChannelInstanceData(chan);
	info = data->info;
	if (info->consoleInterp) {
	    /*
	     * New ConsoleInfo for a new console window.
	     */

	    info = (ConsoleInfo *)ckalloc(sizeof(ConsoleInfo));
	    info = ckalloc(sizeof(ConsoleInfo));
	    info->refCount = 0;

	    /*
	     * Update any console channels to make use of the new console.
	     */

	    if (Tcl_GetChannelType(chan = Tcl_GetStdChannel(TCL_STDIN))
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413







-
+







		data = (ChannelData *) Tcl_GetChannelInstanceData(chan);
		data->info->refCount--;
		data->info = info;
		data->info->refCount++;
	    }
	}
    } else {
	info = (ConsoleInfo *)ckalloc(sizeof(ConsoleInfo));
	info = ckalloc(sizeof(ConsoleInfo));
	info->refCount = 0;
    }

    info->consoleInterp = consoleInterp;
    info->interp = interp;

    Tcl_CallWhenDeleted(consoleInterp, InterpDeleteProc, info);
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449







-
+







	Tk_CreateEventHandler(mainWindow, StructureNotifyMask,
		ConsoleEventProc, info);
	info->refCount++;
    }

    Tcl_Preserve(consoleInterp);
    result = Tcl_EvalEx(consoleInterp, "source $tk_library/console.tcl",
	    TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    -1, TCL_EVAL_GLOBAL);
    if (result == TCL_ERROR) {
	Tcl_SetReturnOptions(interp,
		Tcl_GetReturnOptions(consoleInterp, result));
	Tcl_SetObjResult(interp, Tcl_GetObjResult(consoleInterp));
    }
    Tcl_Release(consoleInterp);
    if (result == TCL_ERROR) {
487
488
489
490
491
492
493
494

495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

518
519
520



521
522
523
524
525
526

527
528
529

530
531
532
533
534
535
536
484
485
486
487
488
489
490

491
492
493
494
495

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515



516
517
518
519
520
521
522
523

524
525
526

527
528
529
530
531
532
533
534







-
+




-
+


















+
-
-
-
+
+
+





-
+


-
+







 *	Writes output on the actual channel.
 *
 *----------------------------------------------------------------------
 */

static int
ConsoleOutput(
    void *instanceData,	/* Indicates which device to use. */
    ClientData instanceData,	/* Indicates which device to use. */
    const char *buf,		/* The data buffer. */
    int toWrite,		/* How many bytes to write? */
    int *errorCode)		/* Where to store error code. */
{
    ChannelData *data = (ChannelData *)instanceData;
    ChannelData *data = instanceData;
    ConsoleInfo *info = data->info;

    *errorCode = 0;
    Tcl_SetErrno(0);

    if (info) {
	Tcl_Interp *consoleInterp = info->consoleInterp;

	if (consoleInterp && !Tcl_InterpDeleted(consoleInterp)) {
	    Tcl_DString ds;
	    Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8");

	    /*
	     * Not checking for utf8 == NULL.  Did not check for TCL_ERROR
	     * from Tcl_SetChannelOption() in Tk_InitConsoleChannels() either.
	     * Assumption is utf-8 Tcl_Encoding is reliably present.
	     */

	    const char *bytes
	    const char *bytes = Tcl_ExternalToUtfDString(utf8, buf, toWrite, &ds);
	    Tcl_Size numBytes = Tcl_DStringLength(&ds);
	    Tcl_Obj *cmd = Tcl_NewStringObj("tk::ConsoleOutput", TCL_INDEX_NONE);
		    = Tcl_ExternalToUtfDString(utf8, buf, toWrite, &ds);
	    int numBytes = Tcl_DStringLength(&ds);
	    Tcl_Obj *cmd = Tcl_NewStringObj("tk::ConsoleOutput", -1);

	    Tcl_FreeEncoding(utf8);

	    if (data->type == TCL_STDERR) {
		Tcl_ListObjAppendElement(NULL, cmd,
			Tcl_NewStringObj("stderr", TCL_INDEX_NONE));
			Tcl_NewStringObj("stderr", -1));
	    } else {
		Tcl_ListObjAppendElement(NULL, cmd,
			Tcl_NewStringObj("stdout", TCL_INDEX_NONE));
			Tcl_NewStringObj("stdout", -1));
	    }
	    Tcl_ListObjAppendElement(NULL, cmd,
		    Tcl_NewStringObj(bytes, numBytes));

	    Tcl_DStringFree(&ds);
	    Tcl_IncrRefCount(cmd);
	    Tcl_EvalObjEx(consoleInterp, cmd, TCL_EVAL_GLOBAL);
552
553
554
555
556
557
558

559
560
561
562
563



564
565

566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585

586
587
588
589


590
591

592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640


641
642
643
644
645
646
647
550
551
552
553
554
555
556
557
558
559



560
561
562
563

564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587


588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605












606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627


628
629
630
631
632
633
634
635
636







+


-
-
-
+
+
+

-
+







-
+












+


-
-
+
+

-
+














-
-
-
-
-
-
-
-
-
-
-
-



















+


-
-
+
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ConsoleInput(
    TCL_UNUSED(void *),
    TCL_UNUSED(char *),			/* Where to store data read. */
    TCL_UNUSED(int),		/* How much space is available in the
    ClientData instanceData,	/* Unused. */
    char *buf,			/* Where to store data read. */
    int bufSize,		/* How much space is available in the
				 * buffer? */
    TCL_UNUSED(int *))		/* Where to store error code. */
    int *errorCode)		/* Where to store error code. */
{
    return 0;			/* Always return EOF. */
}

/*
 *----------------------------------------------------------------------
 *
 * ConsoleClose/Console2Close --
 * ConsoleClose --
 *
 *	Closes the IO channel.
 *
 * Results:
 *	Always returns 0 (success).
 *
 * Side effects:
 *	Frees the dummy file associated with the channel.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ConsoleClose(
    void *instanceData,
    TCL_UNUSED(Tcl_Interp *))
    ClientData instanceData,	/* Unused. */
    Tcl_Interp *interp)		/* Unused. */
{
    ChannelData *data = (ChannelData *)instanceData;
    ChannelData *data = instanceData;
    ConsoleInfo *info = data->info;

    if (info) {
	if (info->refCount-- <= 1) {
	    /*
	     * Assuming the Tcl_Interp * fields must already be NULL.
	     */

	    ckfree(info);
	}
    }
    ckfree(data);
    return 0;
}

static int
Console2Close(
    void *instanceData,	/* Unused. */
    Tcl_Interp *interp,		/* Unused. */
    int flags)
{
    if ((flags&(TCL_CLOSE_READ|TCL_CLOSE_WRITE))==0) {
	return ConsoleClose(instanceData, interp);
    }
    return EINVAL;
}

/*
 *----------------------------------------------------------------------
 *
 * ConsoleWatch --
 *
 *	Called by the notifier to set up the console device so that events
 *	will be noticed. Since there are no events on the console, this
 *	routine just returns without doing anything.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ConsoleWatch(
    TCL_UNUSED(void *),	/* Device ID for the channel. */
    TCL_UNUSED(int))			/* OR-ed combination of TCL_READABLE,
    ClientData instanceData,	/* Device ID for the channel. */
    int mask)			/* OR-ed combination of TCL_READABLE,
				 * TCL_WRITABLE and TCL_EXCEPTION, for the
				 * events we are interested in. */
{
}

/*
 *----------------------------------------------------------------------
656
657
658
659
660
661
662

663
664
665
666


667
668
669

670
671
672
673
674
675
676
645
646
647
648
649
650
651
652
653
654


655
656
657
658

659
660
661
662
663
664
665
666







+


-
-
+
+


-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ConsoleHandle(
    TCL_UNUSED(void *),	/* Device ID for the channel. */
    TCL_UNUSED(int),		/* TCL_READABLE or TCL_WRITABLE to indicate
    ClientData instanceData,	/* Device ID for the channel. */
    int direction,		/* TCL_READABLE or TCL_WRITABLE to indicate
				 * which direction of the channel is being
				 * requested. */
    TCL_UNUSED(void **))	/* Where to store handle */
    ClientData *handlePtr)	/* Where to store handle */
{
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701
702
703

704
705
706
707
708
709
710
676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700







-
+









-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ConsoleObjCmd(
    void *clientData,	/* Access to the console interp */
    ClientData clientData,	/* Access to the console interp */
    Tcl_Interp *interp,		/* Current interpreter */
    int objc,			/* Number of arguments */
    Tcl_Obj *const objv[])	/* Argument objects */
{
    int index, result;
    static const char *const options[] = {
	"eval", "hide", "show", "title", NULL};
    enum option {CON_EVAL, CON_HIDE, CON_SHOW, CON_TITLE};
    Tcl_Obj *cmd = NULL;
    ConsoleInfo *info = (ConsoleInfo *)clientData;
    ConsoleInfo *info = clientData;
    Tcl_Interp *consoleInterp = info->consoleInterp;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
721
722
723
724
725
726
727
728

729
730
731
732
733
734
735

736
737
738
739
740
741
742

743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
711
712
713
714
715
716
717

718
719
720
721
722
723
724

725
726
727
728
729
730
731

732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750

751
752
753
754
755
756
757
758







-
+






-
+






-
+


















-
+







	cmd = objv[2];
	break;
    case CON_HIDE:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}
	cmd = Tcl_NewStringObj("wm withdraw .", TCL_INDEX_NONE);
	cmd = Tcl_NewStringObj("wm withdraw .", -1);
	break;
    case CON_SHOW:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}
	cmd = Tcl_NewStringObj("wm deiconify .", TCL_INDEX_NONE);
	cmd = Tcl_NewStringObj("wm deiconify .", -1);
	break;
    case CON_TITLE:
	if (objc > 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?title?");
	    return TCL_ERROR;
	}
	cmd = Tcl_NewStringObj("wm title .", TCL_INDEX_NONE);
	cmd = Tcl_NewStringObj("wm title .", -1);
	if (objc == 3) {
	    Tcl_ListObjAppendElement(NULL, cmd, objv[2]);
	}
	break;
    default:
	CLANG_ASSERT(0);
    }

    Tcl_IncrRefCount(cmd);
    if (consoleInterp && !Tcl_InterpDeleted(consoleInterp)) {
	Tcl_Preserve(consoleInterp);
	result = Tcl_EvalObjEx(consoleInterp, cmd, TCL_EVAL_GLOBAL);
	Tcl_SetReturnOptions(interp,
		Tcl_GetReturnOptions(consoleInterp, result));
	Tcl_SetObjResult(interp, Tcl_GetObjResult(consoleInterp));
	Tcl_Release(consoleInterp);
    } else {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"no active console interp", TCL_INDEX_NONE));
		"no active console interp", -1));
	Tcl_SetErrorCode(interp, "TK", "CONSOLE", "NONE", NULL);
	result = TCL_ERROR;
    }
    Tcl_DecrRefCount(cmd);
    return result;
}

778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793

794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782

783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
809







-
+







-
+


















-
+







 *	A standard Tcl result.
 *
 *----------------------------------------------------------------------
 */

static int
InterpreterObjCmd(
    void *clientData,	/* */
    ClientData clientData,	/* */
    Tcl_Interp *interp,		/* Current interpreter */
    int objc,			/* Number of arguments */
    Tcl_Obj *const objv[])	/* Argument objects */
{
    int index, result = TCL_OK;
    static const char *const options[] = {"eval", "record", NULL};
    enum option {OTHER_EVAL, OTHER_RECORD};
    ConsoleInfo *info = (ConsoleInfo *)clientData;
    ConsoleInfo *info = clientData;
    Tcl_Interp *otherInterp = info->interp;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option arg");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "script");
	return TCL_ERROR;
    }

    if ((otherInterp == NULL) || Tcl_InterpDeleted(otherInterp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"no active parent interp", TCL_INDEX_NONE));
		"no active master interp", -1));
	Tcl_SetErrorCode(interp, "TK", "CONSOLE", "NO_INTERP", NULL);
	return TCL_ERROR;
    }

    Tcl_Preserve(otherInterp);
    switch ((enum option) index) {
    case OTHER_EVAL:
852
853
854
855
856
857
858
859

860
861

862
863
864
865
866
867
868
842
843
844
845
846
847
848

849
850

851
852
853
854
855
856
857
858







-
+

-
+







 *	lives in gets torn down.
 *
 *----------------------------------------------------------------------
 */

static void
DeleteConsoleInterp(
    void *clientData)
    ClientData clientData)
{
    Tcl_Interp *interp = (Tcl_Interp *)clientData;
    Tcl_Interp *interp = clientData;

    Tcl_DeleteInterp(interp);
}

/*
 *----------------------------------------------------------------------
 *
878
879
880
881
882
883
884
885

886
887
888

889
890
891
892
893
894
895
868
869
870
871
872
873
874

875
876
877

878
879
880
881
882
883
884
885







-
+


-
+







 *	A new console it created.
 *
 *----------------------------------------------------------------------
 */

static void
InterpDeleteProc(
    void *clientData,
    ClientData clientData,
    Tcl_Interp *interp)
{
    ConsoleInfo *info = (ConsoleInfo *)clientData;
    ConsoleInfo *info = clientData;

    if (info->consoleInterp == interp) {
	Tcl_DeleteThreadExitHandler(DeleteConsoleInterp, info->consoleInterp);
	info->consoleInterp = NULL;
    }
    if (info->refCount-- <= 1) {
	ckfree(info);
911
912
913
914
915
916
917
918

919
920

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951

952
953
954
955

956
957
958
959

960
961
962
963
964
965
966
901
902
903
904
905
906
907

908
909

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924

925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940

941
942
943
944

945
946
947
948

949
950
951
952
953
954
955
956







-
+

-
+














-
+















-
+



-
+



-
+







 *	A new console it created.
 *
 *----------------------------------------------------------------------
 */

static void
ConsoleDeleteProc(
    void *clientData)
    ClientData clientData)
{
    ConsoleInfo *info = (ConsoleInfo *)clientData;
    ConsoleInfo *info = clientData;

    if (info->consoleInterp) {
	Tcl_DeleteInterp(info->consoleInterp);
    }
    if (info->refCount-- <= 1) {
	ckfree(info);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ConsoleEventProc --
 *
 *	This event function is registered on the main window of the child
 *	This event function is registered on the main window of the slave
 *	interpreter. If the user or a running script causes the main window to
 *	be destroyed, then we need to inform the console interpreter by
 *	invoking "::tk::ConsoleExit".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Invokes the "::tk::ConsoleExit" command in the console interp.
 *
 *----------------------------------------------------------------------
 */

static void
ConsoleEventProc(
    void *clientData,
    ClientData clientData,
    XEvent *eventPtr)
{
    if (eventPtr->type == DestroyNotify) {
	ConsoleInfo *info = (ConsoleInfo *)clientData;
	ConsoleInfo *info = clientData;
	Tcl_Interp *consoleInterp = info->consoleInterp;

	if (consoleInterp && !Tcl_InterpDeleted(consoleInterp)) {
	    Tcl_EvalEx(consoleInterp, "tk::ConsoleExit", TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    Tcl_EvalEx(consoleInterp, "tk::ConsoleExit", -1, TCL_EVAL_GLOBAL);
	}

	if (info->refCount-- <= 1) {
	    ckfree(info);
	}
    }
}

Changes to generic/tkCursor.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23







-
-
+
+







-
-
-
-







/*
 * tkCursor.c --
 *
 *	This file maintains a database of read-only cursors for the Tk
 *	toolkit. This allows cursors to be shared between widgets and also
 *	avoids round-trips to the X server.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * A TkCursor structure exists for each cursor that is currently active. Each
 * structure is indexed with two hash tables defined below. One of the tables
 * is cursorIdTable, and the other is either cursorNameTable or
 * cursorDataTable, each of which are stored in the TkDisplay structure for
 * the current thread.
 */
55
56
57
58
59
60
61
62
63


64
65
66
67

68
69
70
71
72
73
74
75
76
51
52
53
54
55
56
57


58
59
60
61
62

63


64
65
66
67
68
69
70







-
-
+
+



-
+
-
-







 * The following structure defines the implementation of the "cursor" Tcl
 * object, used for drawing. The color object remembers the hash table
 * entry associated with a color. The actual allocation and deallocation
 * of the color should be done by the configuration package when the cursor
 * option is set.
 */

const TkObjType tkCursorObjType = {
    {"cursor",			/* name */
Tcl_ObjType const tkCursorObjType = {
    "cursor",			/* name */
    FreeCursorObjProc,		/* freeIntRepProc */
    DupCursorObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_AllocCursorFromObj --
 *
99
100
101
102
103
104
105
106

107
108
109

110
111
112
113
114
115
116
93
94
95
96
97
98
99

100
101
102

103
104
105
106
107
108
109
110







-
+


-
+







    Tk_Window tkwin,		/* Window in which the cursor will be used.*/
    Tcl_Obj *objPtr)		/* Object describing cursor; see manual entry
				 * for description of legal syntax of this
				 * obj's string rep. */
{
    TkCursor *cursorPtr;

    if (objPtr->typePtr != &tkCursorObjType.objType) {
    if (objPtr->typePtr != &tkCursorObjType) {
	InitCursorObj(objPtr);
    }
    cursorPtr = (TkCursor *)objPtr->internalRep.twoPtrValue.ptr1;
    cursorPtr = objPtr->internalRep.twoPtrValue.ptr1;

    /*
     * If the object currently points to a TkCursor, see if it's the one we
     * want. If so, increment its reference count and return.
     */

    if (cursorPtr != NULL) {
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160







-
+




















-
+







    /*
     * The object didn't point to the TkCursor that we wanted. Search the list
     * of TkCursors with the same name to see if one of the other TkCursors is
     * the right one.
     */

    if (cursorPtr != NULL) {
	TkCursor *firstCursorPtr = (TkCursor *)Tcl_GetHashValue(cursorPtr->hashPtr);
	TkCursor *firstCursorPtr = Tcl_GetHashValue(cursorPtr->hashPtr);

	FreeCursorObj(objPtr);
	for (cursorPtr = firstCursorPtr;  cursorPtr != NULL;
		cursorPtr = cursorPtr->nextPtr) {
	    if (Tk_Display(tkwin) == cursorPtr->display) {
		cursorPtr->resourceRefCount++;
		cursorPtr->objRefCount++;
		objPtr->internalRep.twoPtrValue.ptr1 = cursorPtr;
		return cursorPtr->cursor;
	    }
	}
    }

    /*
     * Still no luck. Call TkcGetCursor to allocate a new TkCursor object.
     */

    cursorPtr = TkcGetCursor(interp, tkwin, Tcl_GetString(objPtr));
    objPtr->internalRep.twoPtrValue.ptr1 = cursorPtr;
    if (cursorPtr == NULL) {
	return NULL;
	return None;
    }
    cursorPtr->objRefCount++;
    return cursorPtr->cursor;
}

/*
 *----------------------------------------------------------------------
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+







    Tk_Window tkwin,		/* Window in which cursor will be used. */
    Tk_Uid string)		/* Description of cursor. See manual entry for
				 * details on legal syntax. */
{
    TkCursor *cursorPtr = TkcGetCursor(interp, tkwin, string);

    if (cursorPtr == NULL) {
	return NULL;
	return None;
    }
    return cursorPtr->cursor;
}

/*
 *----------------------------------------------------------------------
 *
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251







-
+











-
+







TkcGetCursor(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    const char *string)		/* Description of cursor. See manual entry for
				 * details on legal syntax. */
{
    Tcl_HashEntry *nameHashPtr;
    TkCursor *cursorPtr;
    register TkCursor *cursorPtr;
    TkCursor *existingCursorPtr = NULL;
    int isNew;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (!dispPtr->cursorInit) {
	CursorInit(dispPtr);
    }

    nameHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorNameTable,
	    string, &isNew);
    if (!isNew) {
	existingCursorPtr = (TkCursor *)Tcl_GetHashValue(nameHashPtr);
	existingCursorPtr = Tcl_GetHashValue(nameHashPtr);
	for (cursorPtr = existingCursorPtr; cursorPtr != NULL;
		cursorPtr = cursorPtr->nextPtr) {
	    if (Tk_Display(tkwin) == cursorPtr->display) {
		cursorPtr->resourceRefCount++;
		return cursorPtr;
	    }
	}
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+




















-
+







    int width, int height,	/* Dimensions of cursor. */
    int xHot, int yHot,		/* Location of hot-spot in cursor. */
    Tk_Uid fg,			/* Foreground color for cursor. */
    Tk_Uid bg)			/* Background color for cursor. */
{
    DataKey dataKey;
    Tcl_HashEntry *dataHashPtr;
    TkCursor *cursorPtr;
    register TkCursor *cursorPtr;
    int isNew;
    XColor fgColor, bgColor;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (!dispPtr->cursorInit) {
	CursorInit(dispPtr);
    }

    dataKey.source = source;
    dataKey.mask = mask;
    dataKey.width = width;
    dataKey.height = height;
    dataKey.xHot = xHot;
    dataKey.yHot = yHot;
    dataKey.fg = fg;
    dataKey.bg = bg;
    dataKey.display = Tk_Display(tkwin);
    dataHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorDataTable,
	    (char *) &dataKey, &isNew);
    if (!isNew) {
	cursorPtr = (TkCursor *)Tcl_GetHashValue(dataHashPtr);
	cursorPtr = Tcl_GetHashValue(dataHashPtr);
	cursorPtr->resourceRefCount++;
	return cursorPtr->cursor;
    }

    /*
     * No suitable cursor exists yet. Make one using the data available and
     * add it to the database.
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398







-
+







    }
    Tcl_SetHashValue(dataHashPtr, cursorPtr);
    Tcl_SetHashValue(cursorPtr->idHashPtr, cursorPtr);
    return cursorPtr->cursor;

  error:
    Tcl_DeleteHashEntry(dataHashPtr);
    return NULL;
    return None;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_NameOfCursor --
 *
427
428
429
430
431
432
433
434

435
436
437

438
439
440
441

442
443
444
445
446
447
448
421
422
423
424
425
426
427

428
429
430

431
432
433
434

435
436
437
438
439
440
441
442







-
+


-
+



-
+







    TkCursor *cursorPtr;
    TkDisplay *dispPtr;

    dispPtr = TkGetDisplay(display);

    if (!dispPtr->cursorInit) {
    printid:
	snprintf(dispPtr->cursorString, sizeof(dispPtr->cursorString), "cursor id 0x%" TCL_Z_MODIFIER "x", PTR2INT(cursor));
	sprintf(dispPtr->cursorString, "cursor id %p", cursor);
	return dispPtr->cursorString;
    }
    idHashPtr = Tcl_FindHashEntry(&dispPtr->cursorIdTable, cursor);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->cursorIdTable, (char *) cursor);
    if (idHashPtr == NULL) {
	goto printid;
    }
    cursorPtr = (TkCursor *)Tcl_GetHashValue(idHashPtr);
    cursorPtr = Tcl_GetHashValue(idHashPtr);
    if (cursorPtr->otherTable != &dispPtr->cursorNameTable) {
	goto printid;
    }
    return cursorPtr->hashPtr->key.string;
}

/*
465
466
467
468
469
470
471

472

473
474
475
476
477

478
479
480
481
482
483
484
459
460
461
462
463
464
465
466

467
468
469
470
471

472
473
474
475
476
477
478
479







+
-
+




-
+








static void
FreeCursor(
    TkCursor *cursorPtr)	/* Cursor to be released. */
{
    TkCursor *prevPtr;

    cursorPtr->resourceRefCount--;
    if (cursorPtr->resourceRefCount-- > 1) {
    if (cursorPtr->resourceRefCount > 0) {
	return;
    }

    Tcl_DeleteHashEntry(cursorPtr->idHashPtr);
    prevPtr = (TkCursor *)Tcl_GetHashValue(cursorPtr->hashPtr);
    prevPtr = Tcl_GetHashValue(cursorPtr->hashPtr);
    if (prevPtr == cursorPtr) {
	if (cursorPtr->nextPtr == NULL) {
	    Tcl_DeleteHashEntry(cursorPtr->hashPtr);
	} else {
	    Tcl_SetHashValue(cursorPtr->hashPtr, cursorPtr->nextPtr);
	}
    } else {
519
520
521
522
523
524
525
526

527
528
529
530

531
532
533
534
535
536
537
514
515
516
517
518
519
520

521
522
523
524

525
526
527
528
529
530
531
532







-
+



-
+







    Tcl_HashEntry *idHashPtr;
    TkDisplay *dispPtr = TkGetDisplay(display);

    if (!dispPtr->cursorInit) {
	Tcl_Panic("Tk_FreeCursor called before Tk_GetCursor");
    }

    idHashPtr = Tcl_FindHashEntry(&dispPtr->cursorIdTable, cursor);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->cursorIdTable, (char *) cursor);
    if (idHashPtr == NULL) {
	Tcl_Panic("Tk_FreeCursor received unknown cursor argument");
    }
    FreeCursor((TkCursor *)Tcl_GetHashValue(idHashPtr));
    FreeCursor(Tcl_GetHashValue(idHashPtr));
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_FreeCursorFromObj --
 *
588
589
590
591
592
593
594
595

596
597

598

599
600
601
602
603
604
605
583
584
585
586
587
588
589

590
591
592
593

594
595
596
597
598
599
600
601







-
+


+
-
+







    objPtr->typePtr = NULL;
}

static void
FreeCursorObj(
    Tcl_Obj *objPtr)		/* The object we are releasing. */
{
    TkCursor *cursorPtr = (TkCursor *)objPtr->internalRep.twoPtrValue.ptr1;
    TkCursor *cursorPtr = objPtr->internalRep.twoPtrValue.ptr1;

    if (cursorPtr != NULL) {
	cursorPtr->objRefCount--;
	if ((cursorPtr->objRefCount-- <= 1)
	if ((cursorPtr->objRefCount == 0)
		&& (cursorPtr->resourceRefCount == 0)) {
	    ckfree(cursorPtr);
	}
	objPtr->internalRep.twoPtrValue.ptr1 = NULL;
    }
}

622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632







-
+







 */

static void
DupCursorObjProc(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    TkCursor *cursorPtr = (TkCursor *)srcObjPtr->internalRep.twoPtrValue.ptr1;
    TkCursor *cursorPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;

    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep.twoPtrValue.ptr1 = cursorPtr;

    if (cursorPtr != NULL) {
	cursorPtr->objRefCount++;
    }
696
697
698
699
700
701
702
703

704
705
706
707
708
709
710
711
712
713
714

715
716
717
718
719
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
692
693
694
695
696
697
698

699
700
701
702
703
704
705
706
707
708
709

710
711
712
713
714
715
716
717
718
719
720
721
722
723
724

725
726
727
728
729
730
731
732







-
+










-
+














-
+







    Tcl_Obj *objPtr)		/* The object that describes the desired
				 * cursor. */
{
    TkCursor *cursorPtr;
    Tcl_HashEntry *hashPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (objPtr->typePtr != &tkCursorObjType.objType) {
    if (objPtr->typePtr != &tkCursorObjType) {
	InitCursorObj(objPtr);
    }

    /*
     * The internal representation is a cache of the last cursor used with the
     * given name. But there can be lots different cursors for each cursor
     * name; one cursor for each display. Check to see if the cursor we have
     * cached is the one that is needed.
     */

    cursorPtr = (TkCursor *)objPtr->internalRep.twoPtrValue.ptr1;
    cursorPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if ((cursorPtr != NULL) && (Tk_Display(tkwin) == cursorPtr->display)) {
	return cursorPtr;
    }

    /*
     * If we get to here, it means the cursor we need is not in the cache.
     * Try to look up the cursor in the TkDisplay structure of the window.
     */

    hashPtr = Tcl_FindHashEntry(&dispPtr->cursorNameTable,
	    Tcl_GetString(objPtr));
    if (hashPtr == NULL) {
	goto error;
    }
    for (cursorPtr = (TkCursor *)Tcl_GetHashValue(hashPtr);
    for (cursorPtr = Tcl_GetHashValue(hashPtr);
	    cursorPtr != NULL; cursorPtr = cursorPtr->nextPtr) {
	if (Tk_Display(tkwin) == cursorPtr->display) {
	    FreeCursorObj(objPtr);
	    objPtr->internalRep.twoPtrValue.ptr1 = cursorPtr;
	    cursorPtr->objRefCount++;
	    return cursorPtr;
	}
773
774
775
776
777
778
779
780

781
782
783
784
785
786
787
769
770
771
772
773
774
775

776
777
778
779
780
781
782
783







-
+







     */

    Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }
    objPtr->typePtr = &tkCursorObjType.objType;
    objPtr->typePtr = &tkCursorObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * CursorInit --
857
858
859
860
861
862
863
864

865
866
867
868
869
870
871

872
873

874
875
876
877
878
879
880
881
882
883
884
885
886
853
854
855
856
857
858
859

860
861
862
863
864
865
866

867
868

869
870
871
872
873
874
875
876
877
878
879
880
881
882







-
+






-
+

-
+














    if (!dispPtr->cursorInit) {
	CursorInit(dispPtr);
    }
    resultPtr = Tcl_NewObj();
    hashPtr = Tcl_FindHashEntry(&dispPtr->cursorNameTable, name);
    if (hashPtr != NULL) {
	cursorPtr = (TkCursor *)Tcl_GetHashValue(hashPtr);
	cursorPtr = Tcl_GetHashValue(hashPtr);
	if (cursorPtr == NULL) {
	    Tcl_Panic("TkDebugCursor found empty hash table entry");
	}
	for ( ; (cursorPtr != NULL); cursorPtr = cursorPtr->nextPtr) {
	    objPtr = Tcl_NewObj();
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(cursorPtr->resourceRefCount));
		    Tcl_NewIntObj(cursorPtr->resourceRefCount));
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(cursorPtr->objRefCount));
		    Tcl_NewIntObj(cursorPtr->objRefCount));
	    Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
	}
    }
    return resultPtr;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted generic/tkDList.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546


































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkDList.h --
 *
 * A list is headed by pointers to first and last element. The elements
 * are doubly linked so that an arbitrary element can be removed without
 * a need to traverse the list. New elements can be added to the list
 * before or after an existing element or at the head/tail of the list.
 * A list may be traversed in the forward or backward direction.
 *
 * Copyright © 2018 Gregor Cramer.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Note that this file will not be included in header files, it is the purpose
 * of this file to be included in source files only. Thus we are not using the
 * prefix "Tk_" here for functions, because all the functions have private scope.
 */

/*
 * -------------------------------------------------------------------------------
 * Use the double linked list in the following way:
 * -------------------------------------------------------------------------------
 * typedef struct MyListEntry { TK_DLIST_LINKS(MyListEntry); int value; } MyListEntry;
 * TK_DLIST_DEFINE(MyList, MyListEntry);
 * MyList listHdr = TK_DLIST_LIST_INITIALIZER; // or MyList_Init(&listHdr)
 * MyListEntry *p;
 * int i = 0;
 * MyList_Append(&listHdr, (MyListEntry *)ckalloc(sizeof(MyListEntry)));
 * MyList_Append(&listHdr, (MyListEntry *)ckalloc(sizeof(MyListEntry)));
 * TK_DLIST_FOREACH(p, &listHdr) { p->value = i++; }
 * // ...
 * MyList_RemoveHead(&listHdr);
 * MyList_RemoveHead(&listHdr);
 * MyList_Clear(MyListEntry, &listHdr); // invokes ckfree() for each element
 * -------------------------------------------------------------------------------
 * IMPORTANT NOTE: TK_DLIST_LINKS must be used at start of struct!
 */

#ifndef TK_DLIST_DEFINED
#define TK_DLIST_DEFINED

#include "tkInt.h"

/*
 * List definitions.
 */

#define TK_DLIST_LINKS(ElemType)						\
struct {									\
    struct ElemType *prev;	/* previous element */				\
    struct ElemType *next;	/* next element */				\
} _dl_

#define TK_DLIST_LIST_INITIALIZER { NULL, NULL }
#define TK_DLIST_ELEM_INITIALIZER { NULL, NULL }

/*************************************************************************/
/*
 * DList_Init: Initialize list header. This can also be used to clear the
 * list.
 *
 * See also: DList_Clear()
 */
/*************************************************************************/
/*
 * DList_ElemInit: Initialize a list element.
 */
/*************************************************************************/
/*
 * DList_InsertAfter: Insert 'elem' after 'listElem'. 'elem' must not
 * be linked, but 'listElem' must be linked.
 */
/*************************************************************************/
/*
 * DList_InsertBefore: Insert 'elem' before 'listElem'. 'elem' must not
 * be linked, but 'listElem' must be linked.
 */
/*************************************************************************/
/*
 * DList_Prepend: Insert 'elem' at start of list. This element must not
 * be linked.
 *
 * See also: DList_Append()
 */
/*************************************************************************/
/*
 * DList_Append: Append 'elem' to end of list. This element must not
 * be linked.
 *
 * See also: DList_Prepend()
 */
/*************************************************************************/
/*
 * DList_Move: Append all list items of 'src' to end of 'dst'.
 */
/*************************************************************************/
/*
 * DList_Remove: Remove 'elem' from list. This element must be linked.
 *
 * See also: DList_Free()
 */
/*************************************************************************/
/*
 * DList_Free: Remove 'elem' from list and free it. This element must
 * be linked.
 *
 * See also: DList_Remove()
 */
/*************************************************************************/
/*
 * DList_RemoveHead: Remove first element from list. The list must
 * not be empty.
 *
 * See also: DList_FreeHead()
 */
/*************************************************************************/
/*
 * DList_RemoveTail: Remove last element from list. The list must
 * not be empty.
 *
 * See also: DList_FreeTail()
 */
/*************************************************************************/
/*
 * DList_FreeHead: Remove first element from list and free it.
 * The list must not be empty.
 *
 * See also: DList_RemoveHead()
 */
/*************************************************************************/
/*
 * DList_FreeTail: Remove last element from list and free it.
 * The list must not be empty.
 *
 * See also: DList_RemoveTail()
 */
/*************************************************************************/
/*
 * DList_SwapElems: Swap positions of given elements 'lhs' and 'rhs'.
 * Both elements must be linked, and must belong to same list.
 */
/*************************************************************************/
/*
 * DList_Clear: Clear whole list and free all elements.
 *
 * See also: DList_Init
 */
/*************************************************************************/
/*
 * DList_Traverse: Iterate over all elements in list from first to last.
 * Call given function func(head, elem) for each element. The function has
 * to return the next element in list to traverse, normally this is
 * DList_Next(elem).
 *
 * See also: TK_DLIST_FOREACH, TK_DLIST_FOREACH_REVERSE
 */
/*************************************************************************/
/*
 * DList_First: Return pointer of first element in list, maybe it's NULL.
 */
/*************************************************************************/
/*
 * DList_Last: Return pointer of last element in list, maybe it's NULL.
 */
/*************************************************************************/
/*
 * DList_Next: Return pointer of next element after 'elem', maybe it's NULL.
 *
 * See also: DList_Prev()
 */
/*************************************************************************/
/*
 * DList_Prev: Return pointer of previous element before 'elem', maybe it's
 * NULL.
 *
 * See also: DList_Next()
 */
/*************************************************************************/
/*
 * DList_IsEmpty: Test whether given list is empty.
 */
/*************************************************************************/
/*
 * DList_IsLinked: Test whether given element is linked.
 */
/*************************************************************************/
/*
 * DList_IsFirst: Test whether given element is first element in list.
 * Note that 'elem' must be linked.
 *
 * See also: DList_IsLast(), DList_IsLinked()
 */
/*************************************************************************/
/*
 * DList_IsLast: Test whether given element is last element in list.
 * Note that 'elem' must be linked.
 *
 * See also: DList_IsFirst(), DList_IsLinked()
 */
/*************************************************************************/
/*
 * DList_Size: Count number of elements in given list.
 */
/*************************************************************************/
/*
 * TK_DLIST_FOREACH: Iterate over all elements in list from first to last.
 * 'var' is the name of the variable which points to current element.
 *
 * See also: TK_DLIST_FOREACH_REVERSE, DList_Traverse()
 */
/*************************************************************************/
/*
 * TK_DLIST_FOREACH_REVERSE: Iterate over all elements in list from last
 * to first (backwards). 'var' is the name of the variable which points to
 * current element.
 */
/*************************************************************************/

#if defined(__GNUC__) || defined(__clang__)
# define __TK_DLIST_UNUSED __attribute__((unused))
#else
# define __TK_DLIST_UNUSED
#endif

#define TK_DLIST_DEFINE(LT, ElemType) /* LT = type of head/list */		\
/* ------------------------------------------------------------------------- */	\
typedef struct LT {								\
    struct ElemType *first;	/* first element */				\
    struct ElemType *last;	/* last element */				\
} LT;										\
										\
typedef struct ElemType *(LT##_Func)(LT *head, struct ElemType *elem);		\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Init(LT *head)								\
{										\
    assert(head);								\
    head->first = NULL;								\
    head->last = NULL;								\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_ElemInit(struct ElemType *elem)						\
{										\
    assert(elem);								\
    elem->_dl_.next = NULL;							\
    elem->_dl_.prev = NULL;							\
}										\
										\
__TK_DLIST_UNUSED								\
static int									\
LT##_IsEmpty(LT *head)								\
{										\
    assert(head);								\
    return head->first == NULL;							\
}										\
										\
__TK_DLIST_UNUSED								\
static int									\
LT##_IsLinked(struct ElemType *elem)						\
{										\
    assert(elem);								\
    return elem->_dl_.next && elem->_dl_.prev;					\
}										\
										\
__TK_DLIST_UNUSED								\
static int									\
LT##_IsFirst(struct ElemType *elem)						\
{										\
    assert(LT##_IsLinked(elem));						\
    return elem->_dl_.prev->_dl_.prev == elem;					\
}										\
										\
__TK_DLIST_UNUSED								\
static int									\
LT##_IsLast(struct ElemType *elem)						\
{										\
    assert(LT##_IsLinked(elem));						\
    return elem->_dl_.next->_dl_.next == elem;					\
}										\
										\
__TK_DLIST_UNUSED								\
static struct ElemType *							\
LT##_First(LT *head)								\
{										\
    assert(head);								\
    return head->first;								\
}										\
										\
__TK_DLIST_UNUSED								\
static struct ElemType *							\
LT##_Last(LT *head)								\
{										\
    assert(head);								\
    return head->last;								\
}										\
										\
__TK_DLIST_UNUSED								\
static struct ElemType *							\
LT##_Next(struct ElemType *elem)						\
{										\
    assert(elem);								\
    return LT##_IsLast(elem) ? NULL : elem->_dl_.next;				\
}										\
										\
__TK_DLIST_UNUSED								\
static struct ElemType *							\
LT##_Prev(struct ElemType *elem)						\
{										\
    assert(elem);								\
    return LT##_IsFirst(elem) ? NULL : elem->_dl_.prev;				\
}										\
										\
__TK_DLIST_UNUSED								\
static unsigned									\
LT##_Size(const LT *head)							\
{										\
    const struct ElemType *elem;						\
    unsigned size = 0;								\
    assert(head);								\
    if ((elem = head->first)) {							\
	for ( ; elem != (void *) head; elem = elem->_dl_.next) {		\
	    ++size;								\
	}									\
    }										\
    return size;								\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_InsertAfter(struct ElemType *listElem, struct ElemType *elem)		\
{										\
    assert(listElem);								\
    assert(elem);								\
    elem->_dl_.next = listElem->_dl_.next;					\
    elem->_dl_.prev = listElem;							\
    listElem->_dl_.next->_dl_.prev = elem;					\
    listElem->_dl_.next = elem;							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_InsertBefore(struct ElemType *listElem, struct ElemType *elem)		\
{										\
    assert(listElem);								\
    assert(elem);								\
    elem->_dl_.next = listElem;							\
    elem->_dl_.prev = listElem->_dl_.prev;;					\
    listElem->_dl_.prev->_dl_.next = elem;					\
    listElem->_dl_.prev = elem;							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Prepend(LT *head, struct ElemType *elem)					\
{										\
    assert(head);								\
    assert(elem);								\
    elem->_dl_.prev = (PSEntry *) head;						\
    if (!head->first) {								\
	elem->_dl_.next = (PSEntry *) head;					\
	head->last = elem;							\
    } else {									\
	elem->_dl_.next = head->first;						\
	head->first->_dl_.prev = elem;						\
    }										\
    head->first = elem;								\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Append(LT *head, struct ElemType *elem)					\
{										\
    assert(head);								\
    assert(elem);								\
    elem->_dl_.next = (PSEntry *) head;						\
    if (!head->first) {								\
	elem->_dl_.prev = (PSEntry *) head;					\
	head->first = elem;							\
    } else {									\
	elem->_dl_.prev = head->last;						\
	head->last->_dl_.next = elem;						\
    }										\
    head->last = elem;								\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Move(LT *dst, LT *src)							\
{										\
    assert(dst);								\
    assert(src);								\
    if (src->first) {								\
	if (dst->first) {							\
	    dst->last->_dl_.next = src->first;					\
	    src->first->_dl_.prev = dst->last;					\
	    dst->last = src->last;						\
	} else {								\
	    *dst = *src;							\
	    dst->first->_dl_.prev = (PSEntry *) dst;				\
	}									\
	dst->last->_dl_.next = (PSEntry *) dst;					\
	LT##_Init(src);								\
    }										\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Remove(struct ElemType *elem)						\
{										\
    int isFirst, isLast;							\
    assert(LT##_IsLinked(elem));						\
    isFirst = LT##_IsFirst(elem);						\
    isLast = LT##_IsLast(elem);							\
    if (isFirst && isLast) {							\
	((LT *) elem->_dl_.prev)->first = NULL;					\
	((LT *) elem->_dl_.next)->last = NULL;					\
    } else {									\
	if (isFirst) {								\
	    ((LT *) elem->_dl_.prev)->first = elem->_dl_.next;			\
	} else {								\
	    elem->_dl_.prev->_dl_.next = elem->_dl_.next;			\
	}									\
	if (isLast) {								\
	    ((LT *) elem->_dl_.next)->last = elem->_dl_.prev;			\
	} else {								\
	    elem->_dl_.next->_dl_.prev = elem->_dl_.prev;			\
	}									\
    }										\
    LT##_ElemInit(elem);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Free(struct ElemType *elem)						\
{										\
    LT##_Remove(elem);								\
    ckfree((void *)elem);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_RemoveHead(LT *head)							\
{										\
    assert(!LT##_IsEmpty(head));						\
    LT##_Remove(head->first);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_RemoveTail(LT *head)							\
{										\
    assert(!LT##_IsEmpty(head));						\
    LT##_Remove(head->last);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_FreeHead(LT *head)								\
{										\
    assert(!LT##_IsEmpty(head));						\
    LT##_Free(head->first);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_FreeTail(LT *head)								\
{										\
    assert(!LT##_IsEmpty(head));						\
    LT##_Free(head->last);							\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_SwapElems(struct ElemType *lhs, struct ElemType *rhs)			\
{										\
    assert(lhs);								\
    assert(rhs);								\
    if (lhs != rhs) {								\
	struct ElemType tmp;							\
	if (LT##_IsFirst(lhs))  {						\
	    ((LT *) lhs->_dl_.prev)->first = rhs;				\
	} else if (LT##_IsFirst(rhs)) {						\
	    ((LT *) rhs->_dl_.prev)->first = lhs;				\
	}									\
	if (LT##_IsLast(lhs))  {						\
	    ((LT *) lhs->_dl_.next)->last = rhs;				\
	} else if (LT##_IsLast(rhs)) {						\
	    ((LT *) rhs->_dl_.next)->last = lhs;				\
	}									\
	tmp._dl_ = lhs->_dl_;							\
	lhs->_dl_ = rhs->_dl_;							\
	rhs->_dl_ = tmp._dl_;							\
    }										\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Clear(LT *head)								\
{										\
    struct ElemType *p;								\
    struct ElemType *next;							\
    assert(head);								\
    for (p = head->first; p; p = next) {					\
	next = LT##_Next(p);							\
	ckfree((void *)p);							\
    }										\
    LT##_Init(head);								\
}										\
										\
__TK_DLIST_UNUSED								\
static void									\
LT##_Traverse(LT *head, LT##_Func func)						\
{										\
    struct ElemType *next;							\
    struct ElemType *p;								\
    assert(head);								\
    for (p = head->first; p; p = next) {					\
	next = func(head, p);							\
    }										\
}										\
/* ------------------------------------------------------------------------- */

#define TK_DLIST_FOREACH(var, head)						\
    assert(head);								\
    for (var = head->first ? head->first : (PSEntry *) head; var != (PSEntry *) head; var = var->_dl_.next)

#define TK_DLIST_FOREACH_REVERSE(var, head)					\
    assert(head);								\
    for (var = head->last ? head->last : (PSEntry *) head; var != (PSEntry *) head; var = var->_dl_.prev)

#endif /* TK_DLIST_DEFINED */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 105
 * End:
 * vi:set ts=8 sw=4:
 */

Changes to generic/tkDecls.h.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25

26
27
28
29
30
31
32
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19



20
21
22

23
24
25
26
27
28
29
30





-
+













-
-
-
+


-
+







/*
 * tkDecls.h --
 *
 *	Declarations of functions in the platform independent public Tcl API.
 *
 * Copyright (c) 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKDECLS
#define _TKDECLS

#ifdef BUILD_tk
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT
#endif

#if !defined(BUILD_tk)
# define TK_DEPRECATED(msg) EXTERN TCL_DEPRECATED_API(msg)
#elif defined(TK_NO_DEPRECATED)
#if defined(TK_NO_DEPRECATED) && defined(BUILD_tk)
# define TK_DEPRECATED(msg) MODULE_SCOPE
#else
# define TK_DEPRECATED(msg) EXTERN
# define TK_DEPRECATED(msg) EXTERN TCL_DEPRECATED_API(msg)
#endif

/*
 * WARNING: This file is automatically generated by the tools/genStubs.tcl
 * script.  Any modifications to the function declarations below should be made
 * in the generic/tk.decls script.
 */
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-
+







				int relief);
/* 5 */
EXTERN void		Tk_AddOption(Tk_Window tkwin, const char *name,
				const char *value, int priority);
/* 6 */
EXTERN void		Tk_BindEvent(Tk_BindingTable bindingTable,
				XEvent *eventPtr, Tk_Window tkwin,
				Tcl_Size numObjects, void **objectPtr);
				int numObjects, ClientData *objectPtr);
/* 7 */
EXTERN void		Tk_CanvasDrawableCoords(Tk_Canvas canvas, double x,
				double y, short *drawableXPtr,
				short *drawableYPtr);
/* 8 */
EXTERN void		Tk_CanvasEventuallyRedraw(Tk_Canvas canvas, int x1,
				int y1, int x2, int y2);
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102

103
104

105
106
107
108
109



110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140

141
142
143
144
145
146


147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163



164
165
166
167
168
169


170
171
172
173

174
175
176

177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206


207
208
209
210
211
212
213
214

215
216
217

218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251

252
253
254
255

256
257
258
259
260
261
262
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99

100
101

102

103



104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136

137
138
139
140
141


142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157



158
159
160
161
162
163
164
165

166
167
168
169
170

171
172
173

174
175
176
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202


203
204
205
206
207
208
209
210
211

212
213
214

215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248

249
250
251
252

253
254
255
256
257
258
259
260







-
+








-
+

-
+
-

-
-
-
+
+
+











-
+













-
+




-
+




-
-
+
+






-
+







-
-
-
+
+
+





-
+
+



-
+


-
+










-
+














-
+


-
-
+
+







-
+


-
+








-
+






-
+









-
+







-
+



-
+







EXTERN int		Tk_CanvasPsColor(Tcl_Interp *interp,
				Tk_Canvas canvas, XColor *colorPtr);
/* 13 */
EXTERN int		Tk_CanvasPsFont(Tcl_Interp *interp, Tk_Canvas canvas,
				Tk_Font font);
/* 14 */
EXTERN void		Tk_CanvasPsPath(Tcl_Interp *interp, Tk_Canvas canvas,
				double *coordPtr, Tcl_Size numPoints);
				double *coordPtr, int numPoints);
/* 15 */
EXTERN int		Tk_CanvasPsStipple(Tcl_Interp *interp,
				Tk_Canvas canvas, Pixmap bitmap);
/* 16 */
EXTERN double		Tk_CanvasPsY(Tk_Canvas canvas, double y);
/* 17 */
EXTERN void		Tk_CanvasSetStippleOrigin(Tk_Canvas canvas, GC gc);
/* 18 */
EXTERN int		Tk_CanvasTagsParseProc(void *clientData,
EXTERN int		Tk_CanvasTagsParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 19 */
EXTERN const char *	Tk_CanvasTagsPrintProc(void *clientData,
				Tk_Window tkwin, char *widgRec,
				Tcl_Size offset, Tcl_FreeProc **freeProcPtr);
EXTERN CONST86 char *	Tk_CanvasTagsPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 20 */
EXTERN Tk_Window	Tk_CanvasTkwin(Tk_Canvas canvas);
/* 21 */
EXTERN void		Tk_CanvasWindowCoords(Tk_Canvas canvas, double x,
				double y, short *screenXPtr,
				short *screenYPtr);
/* 22 */
EXTERN void		Tk_ChangeWindowAttributes(Tk_Window tkwin,
				unsigned long valueMask,
				XSetWindowAttributes *attsPtr);
/* 23 */
EXTERN int		Tk_CharBbox(Tk_TextLayout layout, Tcl_Size index,
EXTERN int		Tk_CharBbox(Tk_TextLayout layout, int index,
				int *xPtr, int *yPtr, int *widthPtr,
				int *heightPtr);
/* 24 */
EXTERN void		Tk_ClearSelection(Tk_Window tkwin, Atom selection);
/* 25 */
EXTERN int		Tk_ClipboardAppend(Tcl_Interp *interp,
				Tk_Window tkwin, Atom target, Atom format,
				const char *buffer);
/* 26 */
EXTERN int		Tk_ClipboardClear(Tcl_Interp *interp,
				Tk_Window tkwin);
/* 27 */
EXTERN int		Tk_ConfigureInfo(Tcl_Interp *interp, Tk_Window tkwin,
				const Tk_ConfigSpec *specs, void *widgRec,
				const Tk_ConfigSpec *specs, char *widgRec,
				const char *argvName, int flags);
/* 28 */
EXTERN int		Tk_ConfigureValue(Tcl_Interp *interp,
				Tk_Window tkwin, const Tk_ConfigSpec *specs,
				void *widgRec, const char *argvName,
				char *widgRec, const char *argvName,
				int flags);
/* 29 */
EXTERN int		Tk_ConfigureWidget(Tcl_Interp *interp,
				Tk_Window tkwin, const Tk_ConfigSpec *specs,
				Tcl_Size objc, Tcl_Obj *const *objv,
				void *widgRec, int flags);
				int argc, CONST84 char **argv, char *widgRec,
				int flags);
/* 30 */
EXTERN void		Tk_ConfigureWindow(Tk_Window tkwin,
				unsigned int valueMask,
				XWindowChanges *valuePtr);
/* 31 */
EXTERN Tk_TextLayout	Tk_ComputeTextLayout(Tk_Font font, const char *str,
				Tcl_Size numChars, int wrapLength,
				int numChars, int wrapLength,
				Tk_Justify justify, int flags, int *widthPtr,
				int *heightPtr);
/* 32 */
EXTERN Tk_Window	Tk_CoordsToWindow(int rootX, int rootY,
				Tk_Window tkwin);
/* 33 */
EXTERN unsigned long	Tk_CreateBinding(Tcl_Interp *interp,
				Tk_BindingTable bindingTable, void *object,
				const char *eventStr, const char *script,
				int append);
				Tk_BindingTable bindingTable,
				ClientData object, const char *eventStr,
				const char *script, int append);
/* 34 */
EXTERN Tk_BindingTable	Tk_CreateBindingTable(Tcl_Interp *interp);
/* 35 */
EXTERN Tk_ErrorHandler	Tk_CreateErrorHandler(Display *display, int errNum,
				int request, int minorCode,
				Tk_ErrorProc *errorProc, void *clientData);
				Tk_ErrorProc *errorProc,
				ClientData clientData);
/* 36 */
EXTERN void		Tk_CreateEventHandler(Tk_Window token,
				unsigned long mask, Tk_EventProc *proc,
				void *clientData);
				ClientData clientData);
/* 37 */
EXTERN void		Tk_CreateGenericHandler(Tk_GenericProc *proc,
				void *clientData);
				ClientData clientData);
/* 38 */
EXTERN void		Tk_CreateImageType(const Tk_ImageType *typePtr);
/* 39 */
EXTERN void		Tk_CreateItemType(Tk_ItemType *typePtr);
/* 40 */
EXTERN void		Tk_CreatePhotoImageFormat(
				const Tk_PhotoImageFormat *formatPtr);
/* 41 */
EXTERN void		Tk_CreateSelHandler(Tk_Window tkwin, Atom selection,
				Atom target, Tk_SelectionProc *proc,
				void *clientData, Atom format);
				ClientData clientData, Atom format);
/* 42 */
EXTERN Tk_Window	Tk_CreateWindow(Tcl_Interp *interp, Tk_Window parent,
				const char *name, const char *screenName);
/* 43 */
EXTERN Tk_Window	Tk_CreateWindowFromPath(Tcl_Interp *interp,
				Tk_Window tkwin, const char *pathName,
				const char *screenName);
/* 44 */
EXTERN int		Tk_DefineBitmap(Tcl_Interp *interp, const char *name,
				const void *source, int width, int height);
/* 45 */
EXTERN void		Tk_DefineCursor(Tk_Window window, Tk_Cursor cursor);
/* 46 */
EXTERN void		Tk_DeleteAllBindings(Tk_BindingTable bindingTable,
				void *object);
				ClientData object);
/* 47 */
EXTERN int		Tk_DeleteBinding(Tcl_Interp *interp,
				Tk_BindingTable bindingTable, void *object,
				const char *eventStr);
				Tk_BindingTable bindingTable,
				ClientData object, const char *eventStr);
/* 48 */
EXTERN void		Tk_DeleteBindingTable(Tk_BindingTable bindingTable);
/* 49 */
EXTERN void		Tk_DeleteErrorHandler(Tk_ErrorHandler handler);
/* 50 */
EXTERN void		Tk_DeleteEventHandler(Tk_Window token,
				unsigned long mask, Tk_EventProc *proc,
				void *clientData);
				ClientData clientData);
/* 51 */
EXTERN void		Tk_DeleteGenericHandler(Tk_GenericProc *proc,
				void *clientData);
				ClientData clientData);
/* 52 */
EXTERN void		Tk_DeleteImage(Tcl_Interp *interp, const char *name);
/* 53 */
EXTERN void		Tk_DeleteSelHandler(Tk_Window tkwin, Atom selection,
				Atom target);
/* 54 */
EXTERN void		Tk_DestroyWindow(Tk_Window tkwin);
/* 55 */
EXTERN const char *	Tk_DisplayName(Tk_Window tkwin);
EXTERN CONST84_RETURN char * Tk_DisplayName(Tk_Window tkwin);
/* 56 */
EXTERN int		Tk_DistanceToTextLayout(Tk_TextLayout layout, int x,
				int y);
/* 57 */
EXTERN void		Tk_Draw3DPolygon(Tk_Window tkwin, Drawable drawable,
				Tk_3DBorder border, XPoint *pointPtr,
				Tcl_Size numPoints, int borderWidth,
				int numPoints, int borderWidth,
				int leftRelief);
/* 58 */
EXTERN void		Tk_Draw3DRectangle(Tk_Window tkwin,
				Drawable drawable, Tk_3DBorder border, int x,
				int y, int width, int height,
				int borderWidth, int relief);
/* 59 */
EXTERN void		Tk_DrawChars(Display *display, Drawable drawable,
				GC gc, Tk_Font tkfont, const char *source,
				Tcl_Size numBytes, int x, int y);
				int numBytes, int x, int y);
/* 60 */
EXTERN void		Tk_DrawFocusHighlight(Tk_Window tkwin, GC gc,
				int width, Drawable drawable);
/* 61 */
EXTERN void		Tk_DrawTextLayout(Display *display,
				Drawable drawable, GC gc,
				Tk_TextLayout layout, int x, int y,
				Tcl_Size firstChar, Tcl_Size lastChar);
				int firstChar, int lastChar);
/* 62 */
EXTERN void		Tk_Fill3DPolygon(Tk_Window tkwin, Drawable drawable,
				Tk_3DBorder border, XPoint *pointPtr,
				Tcl_Size numPoints, int borderWidth,
				int numPoints, int borderWidth,
				int leftRelief);
/* 63 */
EXTERN void		Tk_Fill3DRectangle(Tk_Window tkwin,
				Drawable drawable, Tk_3DBorder border, int x,
				int y, int width, int height,
				int borderWidth, int relief);
/* 64 */
278
279
280
281
282
283
284
285

286
287
288
289
290
291




292
293
294
295
296
297
298
299
300
301
302


303
304
305
306
307

308
309
310
311



312
313
314
315
316
317
318
276
277
278
279
280
281
282

283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308

309
310



311
312
313
314
315
316
317
318
319
320







-
+





-
+
+
+
+










-
+
+




-
+

-
-
-
+
+
+







EXTERN void		Tk_FreeFont(Tk_Font f);
/* 72 */
EXTERN void		Tk_FreeGC(Display *display, GC gc);
/* 73 */
EXTERN void		Tk_FreeImage(Tk_Image image);
/* 74 */
EXTERN void		Tk_FreeOptions(const Tk_ConfigSpec *specs,
				void *widgRec, Display *display,
				char *widgRec, Display *display,
				int needFlags);
/* 75 */
EXTERN void		Tk_FreePixmap(Display *display, Pixmap pixmap);
/* 76 */
EXTERN void		Tk_FreeTextLayout(Tk_TextLayout textLayout);
/* Slot 77 is reserved */
/* 77 */
TK_DEPRECATED("function does nothing, call can be removed")
void Tk_FreeXId(
				Display *display, XID xid);
/* 78 */
EXTERN GC		Tk_GCForColor(XColor *colorPtr, Drawable drawable);
/* 79 */
EXTERN void		Tk_GeometryRequest(Tk_Window tkwin, int reqWidth,
				int reqHeight);
/* 80 */
EXTERN Tk_3DBorder	Tk_Get3DBorder(Tcl_Interp *interp, Tk_Window tkwin,
				Tk_Uid colorName);
/* 81 */
EXTERN void		Tk_GetAllBindings(Tcl_Interp *interp,
				Tk_BindingTable bindingTable, void *object);
				Tk_BindingTable bindingTable,
				ClientData object);
/* 82 */
EXTERN int		Tk_GetAnchor(Tcl_Interp *interp, const char *str,
				Tk_Anchor *anchorPtr);
/* 83 */
EXTERN const char *	Tk_GetAtomName(Tk_Window tkwin, Atom atom);
EXTERN CONST84_RETURN char * Tk_GetAtomName(Tk_Window tkwin, Atom atom);
/* 84 */
EXTERN const char *	Tk_GetBinding(Tcl_Interp *interp,
				Tk_BindingTable bindingTable, void *object,
				const char *eventStr);
EXTERN CONST84_RETURN char * Tk_GetBinding(Tcl_Interp *interp,
				Tk_BindingTable bindingTable,
				ClientData object, const char *eventStr);
/* 85 */
EXTERN Pixmap		Tk_GetBitmap(Tcl_Interp *interp, Tk_Window tkwin,
				const char *str);
/* 86 */
EXTERN Pixmap		Tk_GetBitmapFromData(Tcl_Interp *interp,
				Tk_Window tkwin, const void *source,
				int width, int height);
346
347
348
349
350
351
352
353

354
355

356
357

358
359
360
361
362
363
364
348
349
350
351
352
353
354

355
356

357
358

359
360
361
362
363
364
365
366







-
+

-
+

-
+







/* 96 */
EXTERN GC		Tk_GetGC(Tk_Window tkwin, unsigned long valueMask,
				XGCValues *valuePtr);
/* 97 */
EXTERN Tk_Image		Tk_GetImage(Tcl_Interp *interp, Tk_Window tkwin,
				const char *name,
				Tk_ImageChangedProc *changeProc,
				void *clientData);
				ClientData clientData);
/* 98 */
EXTERN void *		Tk_GetImageModelData(Tcl_Interp *interp,
EXTERN ClientData	Tk_GetImageMasterData(Tcl_Interp *interp,
				const char *name,
				const Tk_ImageType **typePtrPtr);
				CONST86 Tk_ImageType **typePtrPtr);
/* 99 */
EXTERN Tk_ItemType *	Tk_GetItemTypes(void);
/* 100 */
EXTERN int		Tk_GetJoinStyle(Tcl_Interp *interp, const char *str,
				int *joinPtr);
/* 101 */
EXTERN int		Tk_GetJustify(Tcl_Interp *interp, const char *str,
377
378
379
380
381
382
383
384
385


386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414


415
416
417
418
419
420
421
422


423
424
425
426
427
428
429
430


431
432
433
434
435

436
437
438
439
440
441
442
443
444
445

446
447

448
449

450
451

452
453

454
455


456
457

458
459

460
461

462
463

464
465

466
467
468
469
470
471

472
473
474

475
476
477













478
479
480
481
482
483




484
485
486
487




488
489
490
491
492
493
494
379
380
381
382
383
384
385


386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415

416
417
418
419
420
421
422
423


424
425
426
427
428
429
430
431
432

433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448

449
450

451
452

453
454

455
456

457
458

459
460
461

462
463

464
465

466
467

468
469

470
471
472
473
474
475

476
477
478

479
480


481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505

506
507
508
509
510
511
512
513
514
515
516







-
-
+
+







-
+

















-
+


-
+
+






-
-
+
+







-
+
+




-
+









-
+

-
+

-
+

-
+

-
+

-
+
+

-
+

-
+

-
+

-
+

-
+





-
+


-
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+
+
+
+



-
+
+
+
+







/* 106 */
EXTERN int		Tk_GetRelief(Tcl_Interp *interp, const char *name,
				int *reliefPtr);
/* 107 */
EXTERN void		Tk_GetRootCoords(Tk_Window tkwin, int *xPtr,
				int *yPtr);
/* 108 */
EXTERN int		Tk_GetScrollInfo(Tcl_Interp *interp, Tcl_Size argc,
				const char **argv, double *dblPtr,
EXTERN int		Tk_GetScrollInfo(Tcl_Interp *interp, int argc,
				CONST84 char **argv, double *dblPtr,
				int *intPtr);
/* 109 */
EXTERN int		Tk_GetScreenMM(Tcl_Interp *interp, Tk_Window tkwin,
				const char *str, double *doublePtr);
/* 110 */
EXTERN int		Tk_GetSelection(Tcl_Interp *interp, Tk_Window tkwin,
				Atom selection, Atom target,
				Tk_GetSelProc *proc, void *clientData);
				Tk_GetSelProc *proc, ClientData clientData);
/* 111 */
EXTERN Tk_Uid		Tk_GetUid(const char *str);
/* 112 */
EXTERN Visual *		Tk_GetVisual(Tcl_Interp *interp, Tk_Window tkwin,
				const char *str, int *depthPtr,
				Colormap *colormapPtr);
/* 113 */
EXTERN void		Tk_GetVRootGeometry(Tk_Window tkwin, int *xPtr,
				int *yPtr, int *widthPtr, int *heightPtr);
/* 114 */
EXTERN int		Tk_Grab(Tcl_Interp *interp, Tk_Window tkwin,
				int grabGlobal);
/* 115 */
EXTERN void		Tk_HandleEvent(XEvent *eventPtr);
/* 116 */
EXTERN Tk_Window	Tk_IdToWindow(Display *display, Window window);
/* 117 */
EXTERN void		Tk_ImageChanged(Tk_ImageModel model, int x, int y,
EXTERN void		Tk_ImageChanged(Tk_ImageMaster master, int x, int y,
				int width, int height, int imageWidth,
				int imageHeight);
/* Slot 118 is reserved */
/* 118 */
EXTERN int		Tk_Init(Tcl_Interp *interp);
/* 119 */
EXTERN Atom		Tk_InternAtom(Tk_Window tkwin, const char *name);
/* 120 */
EXTERN int		Tk_IntersectTextLayout(Tk_TextLayout layout, int x,
				int y, int width, int height);
/* 121 */
EXTERN void		Tk_MaintainGeometry(Tk_Window window,
				Tk_Window container, int x, int y, int width,
EXTERN void		Tk_MaintainGeometry(Tk_Window slave,
				Tk_Window master, int x, int y, int width,
				int height);
/* 122 */
EXTERN Tk_Window	Tk_MainWindow(Tcl_Interp *interp);
/* 123 */
EXTERN void		Tk_MakeWindowExist(Tk_Window tkwin);
/* 124 */
EXTERN void		Tk_ManageGeometry(Tk_Window tkwin,
				const Tk_GeomMgr *mgrPtr, void *clientData);
				const Tk_GeomMgr *mgrPtr,
				ClientData clientData);
/* 125 */
EXTERN void		Tk_MapWindow(Tk_Window tkwin);
/* 126 */
EXTERN int		Tk_MeasureChars(Tk_Font tkfont, const char *source,
				Tcl_Size numBytes, int maxPixels, int flags,
				int numBytes, int maxPixels, int flags,
				int *lengthPtr);
/* 127 */
EXTERN void		Tk_MoveResizeWindow(Tk_Window tkwin, int x, int y,
				int width, int height);
/* 128 */
EXTERN void		Tk_MoveWindow(Tk_Window tkwin, int x, int y);
/* 129 */
EXTERN void		Tk_MoveToplevelWindow(Tk_Window tkwin, int x, int y);
/* 130 */
EXTERN const char *	Tk_NameOf3DBorder(Tk_3DBorder border);
EXTERN CONST84_RETURN char * Tk_NameOf3DBorder(Tk_3DBorder border);
/* 131 */
EXTERN const char *	Tk_NameOfAnchor(Tk_Anchor anchor);
EXTERN CONST84_RETURN char * Tk_NameOfAnchor(Tk_Anchor anchor);
/* 132 */
EXTERN const char *	Tk_NameOfBitmap(Display *display, Pixmap bitmap);
EXTERN CONST84_RETURN char * Tk_NameOfBitmap(Display *display, Pixmap bitmap);
/* 133 */
EXTERN const char *	Tk_NameOfCapStyle(int cap);
EXTERN CONST84_RETURN char * Tk_NameOfCapStyle(int cap);
/* 134 */
EXTERN const char *	Tk_NameOfColor(XColor *colorPtr);
EXTERN CONST84_RETURN char * Tk_NameOfColor(XColor *colorPtr);
/* 135 */
EXTERN const char *	Tk_NameOfCursor(Display *display, Tk_Cursor cursor);
EXTERN CONST84_RETURN char * Tk_NameOfCursor(Display *display,
				Tk_Cursor cursor);
/* 136 */
EXTERN const char *	Tk_NameOfFont(Tk_Font font);
EXTERN CONST84_RETURN char * Tk_NameOfFont(Tk_Font font);
/* 137 */
EXTERN const char *	Tk_NameOfImage(Tk_ImageModel model);
EXTERN CONST84_RETURN char * Tk_NameOfImage(Tk_ImageMaster imageMaster);
/* 138 */
EXTERN const char *	Tk_NameOfJoinStyle(int join);
EXTERN CONST84_RETURN char * Tk_NameOfJoinStyle(int join);
/* 139 */
EXTERN const char *	Tk_NameOfJustify(Tk_Justify justify);
EXTERN CONST84_RETURN char * Tk_NameOfJustify(Tk_Justify justify);
/* 140 */
EXTERN const char *	Tk_NameOfRelief(int relief);
EXTERN CONST84_RETURN char * Tk_NameOfRelief(int relief);
/* 141 */
EXTERN Tk_Window	Tk_NameToWindow(Tcl_Interp *interp,
				const char *pathName, Tk_Window tkwin);
/* 142 */
EXTERN void		Tk_OwnSelection(Tk_Window tkwin, Atom selection,
				Tk_LostSelProc *proc, void *clientData);
				Tk_LostSelProc *proc, ClientData clientData);
/* 143 */
EXTERN int		Tk_ParseArgv(Tcl_Interp *interp, Tk_Window tkwin,
				int *argcPtr, const char **argv,
				int *argcPtr, CONST84 char **argv,
				const Tk_ArgvInfo *argTable, int flags);
/* Slot 144 is reserved */
/* Slot 145 is reserved */
/* 144 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoPutBlock_NoComposite(
				Tk_PhotoHandle handle,
				Tk_PhotoImageBlock *blockPtr, int x, int y,
				int width, int height);
/* 145 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoPutZoomedBlock_NoComposite(
				Tk_PhotoHandle handle,
				Tk_PhotoImageBlock *blockPtr, int x, int y,
				int width, int height, int zoomX, int zoomY,
				int subsampleX, int subsampleY);
/* 146 */
EXTERN int		Tk_PhotoGetImage(Tk_PhotoHandle handle,
				Tk_PhotoImageBlock *blockPtr);
/* 147 */
EXTERN void		Tk_PhotoBlank(Tk_PhotoHandle handle);
/* Slot 148 is reserved */
/* 148 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoExpand_Panic(
				Tk_PhotoHandle handle, int width, int height);
/* 149 */
EXTERN void		Tk_PhotoGetSize(Tk_PhotoHandle handle, int *widthPtr,
				int *heightPtr);
/* Slot 150 is reserved */
/* 150 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoSetSize_Panic(
				Tk_PhotoHandle handle, int width, int height);
/* 151 */
EXTERN int		Tk_PointToChar(Tk_TextLayout layout, int x, int y);
/* 152 */
EXTERN int		Tk_PostscriptFontName(Tk_Font tkfont,
				Tcl_DString *dsPtr);
/* 153 */
EXTERN void		Tk_PreserveColormap(Display *display,
504
505
506
507
508
509
510
511
512
513




514
515
516
517
518
519
520
526
527
528
529
530
531
532



533
534
535
536
537
538
539
540
541
542
543







-
-
-
+
+
+
+







/* 156 */
EXTERN void		Tk_ResizeWindow(Tk_Window tkwin, int width,
				int height);
/* 157 */
EXTERN int		Tk_RestackWindow(Tk_Window tkwin, int aboveBelow,
				Tk_Window other);
/* 158 */
EXTERN Tk_RestrictProc * Tk_RestrictEvents(Tk_RestrictProc *proc, void *arg,
				void **prevArgPtr);
/* Slot 159 is reserved */
EXTERN Tk_RestrictProc * Tk_RestrictEvents(Tk_RestrictProc *proc,
				ClientData arg, ClientData *prevArgPtr);
/* 159 */
EXTERN int		Tk_SafeInit(Tcl_Interp *interp);
/* 160 */
EXTERN const char *	Tk_SetAppName(Tk_Window tkwin, const char *name);
/* 161 */
EXTERN void		Tk_SetBackgroundFromBorder(Tk_Window tkwin,
				Tk_3DBorder border);
/* 162 */
EXTERN void		Tk_SetClass(Tk_Window tkwin, const char *className);
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566

567
568
569
570
571
572
573
574
575
576


577
578
579
580
581
582
583
575
576
577
578
579
580
581

582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597


598
599
600
601
602
603
604
605
606







-
+






-
+








-
-
+
+







/* 174 */
EXTERN int		Tk_StrictMotif(Tk_Window tkwin);
/* 175 */
EXTERN void		Tk_TextLayoutToPostscript(Tcl_Interp *interp,
				Tk_TextLayout layout);
/* 176 */
EXTERN int		Tk_TextWidth(Tk_Font font, const char *str,
				Tcl_Size numBytes);
				int numBytes);
/* 177 */
EXTERN void		Tk_UndefineCursor(Tk_Window window);
/* 178 */
EXTERN void		Tk_UnderlineChars(Display *display,
				Drawable drawable, GC gc, Tk_Font tkfont,
				const char *source, int x, int y,
				Tcl_Size firstByte, Tcl_Size lastByte);
				int firstByte, int lastByte);
/* 179 */
EXTERN void		Tk_UnderlineTextLayout(Display *display,
				Drawable drawable, GC gc,
				Tk_TextLayout layout, int x, int y,
				int underline);
/* 180 */
EXTERN void		Tk_Ungrab(Tk_Window tkwin);
/* 181 */
EXTERN void		Tk_UnmaintainGeometry(Tk_Window window,
				Tk_Window container);
EXTERN void		Tk_UnmaintainGeometry(Tk_Window slave,
				Tk_Window master);
/* 182 */
EXTERN void		Tk_UnmapWindow(Tk_Window tkwin);
/* 183 */
EXTERN void		Tk_UnsetGrid(Tk_Window tkwin);
/* 184 */
EXTERN void		Tk_UpdatePointer(Tk_Window tkwin, int x, int y,
				int state);
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643







-
+







				Tcl_Obj *objPtr);
/* 193 */
EXTERN void		Tk_FreeBitmapFromObj(Tk_Window tkwin,
				Tcl_Obj *objPtr);
/* 194 */
EXTERN void		Tk_FreeColorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr);
/* 195 */
EXTERN void		Tk_FreeConfigOptions(void *recordPtr,
EXTERN void		Tk_FreeConfigOptions(char *recordPtr,
				Tk_OptionTable optionToken, Tk_Window tkwin);
/* 196 */
EXTERN void		Tk_FreeSavedOptions(Tk_SavedOptions *savePtr);
/* 197 */
EXTERN void		Tk_FreeCursorFromObj(Tk_Window tkwin,
				Tcl_Obj *objPtr);
/* 198 */
628
629
630
631
632
633
634
635

636
637
638
639
640

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658



659
660

661
662




663
664
665
666
667


668
669
670
671
672


673
674
675
676
677
678
679
651
652
653
654
655
656
657

658
659
660
661
662

663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678



679
680
681
682

683
684

685
686
687
688
689
690
691


692
693
694
695
696
697

698
699
700
701
702
703
704
705
706







-
+




-
+















-
-
-
+
+
+

-
+

-
+
+
+
+



-
-
+
+




-
+
+







/* 201 */
EXTERN Pixmap		Tk_GetBitmapFromObj(Tk_Window tkwin, Tcl_Obj *objPtr);
/* 202 */
EXTERN XColor *		Tk_GetColorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr);
/* 203 */
EXTERN Tk_Cursor	Tk_GetCursorFromObj(Tk_Window tkwin, Tcl_Obj *objPtr);
/* 204 */
EXTERN Tcl_Obj *	Tk_GetOptionInfo(Tcl_Interp *interp, void *recordPtr,
EXTERN Tcl_Obj *	Tk_GetOptionInfo(Tcl_Interp *interp, char *recordPtr,
				Tk_OptionTable optionTable, Tcl_Obj *namePtr,
				Tk_Window tkwin);
/* 205 */
EXTERN Tcl_Obj *	Tk_GetOptionValue(Tcl_Interp *interp,
				void *recordPtr, Tk_OptionTable optionTable,
				char *recordPtr, Tk_OptionTable optionTable,
				Tcl_Obj *namePtr, Tk_Window tkwin);
/* 206 */
EXTERN int		Tk_GetJustifyFromObj(Tcl_Interp *interp,
				Tcl_Obj *objPtr, Tk_Justify *justifyPtr);
/* 207 */
EXTERN int		Tk_GetMMFromObj(Tcl_Interp *interp, Tk_Window tkwin,
				Tcl_Obj *objPtr, double *doublePtr);
/* 208 */
EXTERN int		Tk_GetPixelsFromObj(Tcl_Interp *interp,
				Tk_Window tkwin, Tcl_Obj *objPtr,
				int *intPtr);
/* 209 */
EXTERN int		Tk_GetReliefFromObj(Tcl_Interp *interp,
				Tcl_Obj *objPtr, int *resultPtr);
/* 210 */
EXTERN int		Tk_GetScrollInfoObj(Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[],
				double *dblPtr, int *intPtr);
EXTERN int		Tk_GetScrollInfoObj(Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[], double *dblPtr,
				int *intPtr);
/* 211 */
EXTERN int		Tk_InitOptions(Tcl_Interp *interp, void *recordPtr,
EXTERN int		Tk_InitOptions(Tcl_Interp *interp, char *recordPtr,
				Tk_OptionTable optionToken, Tk_Window tkwin);
/* Slot 212 is reserved */
/* 212 */
EXTERN void		Tk_MainEx(int argc, char **argv,
				Tcl_AppInitProc *appInitProc,
				Tcl_Interp *interp);
/* 213 */
EXTERN void		Tk_RestoreSavedOptions(Tk_SavedOptions *savePtr);
/* 214 */
EXTERN int		Tk_SetOptions(Tcl_Interp *interp, void *recordPtr,
				Tk_OptionTable optionTable, Tcl_Size objc,
EXTERN int		Tk_SetOptions(Tcl_Interp *interp, char *recordPtr,
				Tk_OptionTable optionTable, int objc,
				Tcl_Obj *const objv[], Tk_Window tkwin,
				Tk_SavedOptions *savePtr, int *maskPtr);
/* 215 */
EXTERN void		Tk_InitConsoleChannels(Tcl_Interp *interp);
/* Slot 216 is reserved */
/* 216 */
EXTERN int		Tk_CreateConsoleWindow(Tcl_Interp *interp);
/* 217 */
EXTERN void		Tk_CreateSmoothMethod(Tcl_Interp *interp,
				const Tk_SmoothMethod *method);
/* Slot 218 is reserved */
/* Slot 219 is reserved */
/* 220 */
EXTERN int		Tk_GetDash(Tcl_Interp *interp, const char *value,
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764







-
+







EXTERN int		Tk_PostscriptImage(Tk_Image image,
				Tcl_Interp *interp, Tk_Window tkwin,
				Tk_PostscriptInfo psinfo, int x, int y,
				int width, int height, int prepass);
/* 235 */
EXTERN void		Tk_PostscriptPath(Tcl_Interp *interp,
				Tk_PostscriptInfo psInfo, double *coordPtr,
				Tcl_Size numPoints);
				int numPoints);
/* 236 */
EXTERN int		Tk_PostscriptStipple(Tcl_Interp *interp,
				Tk_Window tkwin, Tk_PostscriptInfo psInfo,
				Pixmap bitmap);
/* 237 */
EXTERN double		Tk_PostscriptY(double y, Tk_PostscriptInfo psInfo);
/* 238 */
747
748
749
750
751
752
753
754

755
756
757
758
759
760
761
762
763
764
765













766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781

782
783
784
785
786
787
788
789
790
791
792




793
794

795
796
797
798
799

800
801
802
803
804

805
806
807
808
809
810

811
812
813
814

815
816
817
818
819
820
821
774
775
776
777
778
779
780

781
782
783
784
785
786
787
788
789
790


791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828


829
830
831
832
833

834

835
836
837

838
839
840
841
842

843
844
845
846
847
848

849
850
851
852

853
854
855
856
857
858
859
860







-
+









-
-
+
+
+
+
+
+
+
+
+
+
+
+
+















-
+









-
-
+
+
+
+

-
+
-



-
+




-
+





-
+



-
+







				Tk_ClientMessageProc *proc);
/* 241 */
EXTERN Tk_Window	Tk_CreateAnonymousWindow(Tcl_Interp *interp,
				Tk_Window parent, const char *screenName);
/* 242 */
EXTERN void		Tk_SetClassProcs(Tk_Window tkwin,
				const Tk_ClassProcs *procs,
				void *instanceData);
				ClientData instanceData);
/* 243 */
EXTERN void		Tk_SetInternalBorderEx(Tk_Window tkwin, int left,
				int right, int top, int bottom);
/* 244 */
EXTERN void		Tk_SetMinimumRequestSize(Tk_Window tkwin,
				int minWidth, int minHeight);
/* 245 */
EXTERN void		Tk_SetCaretPos(Tk_Window tkwin, int x, int y,
				int height);
/* Slot 246 is reserved */
/* Slot 247 is reserved */
/* 246 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoPutBlock_Panic(
				Tk_PhotoHandle handle,
				Tk_PhotoImageBlock *blockPtr, int x, int y,
				int width, int height, int compRule);
/* 247 */
TK_DEPRECATED("function signature changed")
void Tk_PhotoPutZoomedBlock_Panic(
				Tk_PhotoHandle handle,
				Tk_PhotoImageBlock *blockPtr, int x, int y,
				int width, int height, int zoomX, int zoomY,
				int subsampleX, int subsampleY, int compRule);
/* 248 */
EXTERN int		Tk_CollapseMotionEvents(Display *display,
				int collapse);
/* 249 */
EXTERN Tk_StyleEngine	Tk_RegisterStyleEngine(const char *name,
				Tk_StyleEngine parent);
/* 250 */
EXTERN Tk_StyleEngine	Tk_GetStyleEngine(const char *name);
/* 251 */
EXTERN int		Tk_RegisterStyledElement(Tk_StyleEngine engine,
				Tk_ElementSpec *templatePtr);
/* 252 */
EXTERN int		Tk_GetElementId(const char *name);
/* 253 */
EXTERN Tk_Style		Tk_CreateStyle(const char *name,
				Tk_StyleEngine engine, void *clientData);
				Tk_StyleEngine engine, ClientData clientData);
/* 254 */
EXTERN Tk_Style		Tk_GetStyle(Tcl_Interp *interp, const char *name);
/* 255 */
EXTERN void		Tk_FreeStyle(Tk_Style style);
/* 256 */
EXTERN const char *	Tk_NameOfStyle(Tk_Style style);
/* 257 */
EXTERN Tk_Style		Tk_AllocStyleFromObj(Tcl_Interp *interp,
				Tcl_Obj *objPtr);
/* Slot 258 is reserved */
/* Slot 259 is reserved */
/* 258 */
EXTERN Tk_Style		Tk_GetStyleFromObj(Tcl_Obj *objPtr);
/* 259 */
EXTERN void		Tk_FreeStyleFromObj(Tcl_Obj *objPtr);
/* 260 */
EXTERN Tk_StyledElement	 Tk_GetStyledElement(Tk_Style style,
EXTERN Tk_StyledElement	 Tk_GetStyledElement(Tk_Style style, int elementId,
				Tcl_Size elementId,
				Tk_OptionTable optionTable);
/* 261 */
EXTERN void		Tk_GetElementSize(Tk_Style style,
				Tk_StyledElement element, void *recordPtr,
				Tk_StyledElement element, char *recordPtr,
				Tk_Window tkwin, int width, int height,
				int inner, int *widthPtr, int *heightPtr);
/* 262 */
EXTERN void		Tk_GetElementBox(Tk_Style style,
				Tk_StyledElement element, void *recordPtr,
				Tk_StyledElement element, char *recordPtr,
				Tk_Window tkwin, int x, int y, int width,
				int height, int inner, int *xPtr, int *yPtr,
				int *widthPtr, int *heightPtr);
/* 263 */
EXTERN int		Tk_GetElementBorderWidth(Tk_Style style,
				Tk_StyledElement element, void *recordPtr,
				Tk_StyledElement element, char *recordPtr,
				Tk_Window tkwin);
/* 264 */
EXTERN void		Tk_DrawElement(Tk_Style style,
				Tk_StyledElement element, void *recordPtr,
				Tk_StyledElement element, char *recordPtr,
				Tk_Window tkwin, Drawable d, int x, int y,
				int width, int height, int state);
/* 265 */
EXTERN int		Tk_PhotoExpand(Tcl_Interp *interp,
				Tk_PhotoHandle handle, int width, int height);
/* 266 */
EXTERN int		Tk_PhotoPutBlock(Tcl_Interp *interp,
833
834
835
836
837
838
839
840
841
842

843
844
845
846
847
848
849
850
851
852
853

854
855

856
857
858
859


860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908

909
910
911
912
913
914
915
916

917
918
919
920
921


922
923
924
925

926
927
928
929
930
931



932
933

934
935

936
937
938
939



940
941
942
943

944
945
946
947
948
949


950
951
952
953


954
955
956
957

958
959

960
961

962
963
964


965
966
967
968
969
970
971
972
973
974
975
976

977
978
979

980
981
982
983

984
985
986


987
988
989
990
991
992
993
994
995
996
997
998
999
1000


1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012

1013
1014
1015
1016
1017
1018
1019
1020


1021
1022
1023

1024
1025
1026

1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042











1043
1044
1045
1046
1047




1048
1049
1050

1051
1052

1053
1054
1055
1056
1057
1058
1059
1060
1061


1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078

1079
1080

1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104
1105
1106
1107


1108
1109
1110
1111
1112
1113
1114



1115
1116

1117
1118

1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144

1145
1146
1147
1148
1149


1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166







1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
872
873
874
875
876
877
878



879











880


881




882
883






























884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901

902
903
904
905
906
907
908
909

910
911
912
913


914
915
916
917
918

919
920
921
922



923
924
925
926

927
928

929
930



931
932
933
934
935
936

937
938
939
940
941


942
943
944
945


946
947
948
949
950

951
952

953
954

955
956


957
958
959
960
961
962
963
964
965
966
967
968
969

970
971
972

973
974
975
976

977
978


979
980
981
982
983
984
985
986
987
988
989
990
991
992


993
994
995
996
997
998
999
1000
1001
1002
1003

1004
1005

1006
1007
1008
1009
1010
1011
1012


1013
1014
1015
1016

1017
1018
1019

1020
1021

1022
1023
1024
1025











1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037




1038
1039
1040
1041
1042
1043

1044
1045

1046
1047
1048
1049
1050
1051
1052
1053


1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073

1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099


1100
1101
1102
1103
1104
1105



1106
1107
1108
1109

1110
1111

1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141


1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153







1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167

1168








1169










1170
1171
1172
1173
1174
1175
1176







-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-
+







-
+



-
-
+
+



-
+



-
-
-
+
+
+

-
+

-
+

-
-
-
+
+
+



-
+




-
-
+
+


-
-
+
+



-
+

-
+

-
+

-
-
+
+











-
+


-
+



-
+

-
-
+
+












-
-
+
+









-
+

-
+






-
-
+
+


-
+


-
+

-
+



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+


-
+

-
+







-
-
+
+
















-
+

-
+


-
+













-
+








-
-
+
+




-
-
-
+
+
+

-
+

-
+


















-
+






-
+



-
-
+
+





-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+







-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-







				Tk_PhotoHandle handle, int width, int height);
/* 269 */
EXTERN long		Tk_GetUserInactiveTime(Display *dpy);
/* 270 */
EXTERN void		Tk_ResetUserInactiveTime(Display *dpy);
/* 271 */
EXTERN Tcl_Interp *	Tk_Interp(Tk_Window tkwin);
/* Slot 272 is reserved */
/* Slot 273 is reserved */
/* 274 */
/* 272 */
EXTERN int		Tk_AlwaysShowSelection(Tk_Window tkwin);
/* 275 */
EXTERN unsigned		Tk_GetButtonMask(unsigned button);
/* 276 */
EXTERN int		Tk_GetDoublePixelsFromObj(Tcl_Interp *interp,
				Tk_Window tkwin, Tcl_Obj *objPtr,
				double *doublePtr);
/* 277 */
EXTERN Tcl_Obj *	Tk_NewWindowObj(Tk_Window tkwin);
/* 278 */
EXTERN void		Tk_SendVirtualEvent(Tk_Window tkwin,
EXTERN void		Tk_CreateOldImageType(const Tk_ImageType *typePtr);
				const char *eventName, Tcl_Obj *detail);
/* 279 */
/* 273 */
EXTERN Tcl_Obj *	Tk_FontGetDescription(Tk_Font tkfont);
/* 280 */
EXTERN void		Tk_CreatePhotoImageFormatVersion3(
				const Tk_PhotoImageFormatVersion3 *formatPtr);
EXTERN void		Tk_CreateOldPhotoImageFormat(
				const Tk_PhotoImageFormat *formatPtr);
/* 281 */
EXTERN void		Tk_DrawHighlightBorder(Tk_Window tkwin, GC fgGC,
				GC bgGC, int highlightWidth,
				Drawable drawable);
/* 282 */
EXTERN void		Tk_SetMainMenubar(Tcl_Interp *interp,
				Tk_Window tkwin, const char *menuName);
/* 283 */
EXTERN void		Tk_SetWindowMenubar(Tcl_Interp *interp,
				Tk_Window tkwin, const char *oldMenuName,
				const char *menuName);
/* 284 */
EXTERN void		Tk_ClipDrawableToRect(Display *display, Drawable d,
				int x, int y, int width, int height);
/* 285 */
EXTERN Tcl_Obj *	Tk_GetSystemDefault(Tk_Window tkwin,
				const char *dbName, const char *className);
/* 286 */
EXTERN int		Tk_UseWindow(Tcl_Interp *interp, Tk_Window tkwin,
				const char *string);
/* 287 */
EXTERN void		Tk_MakeContainer(Tk_Window tkwin);
/* 288 */
EXTERN Tk_Window	Tk_GetOtherWindow(Tk_Window tkwin);
/* 289 */
EXTERN void		Tk_Get3DBorderColors(Tk_3DBorder border,
				XColor *bgColorPtr, XColor *darkColorPtr,
				XColor *lightColorPtr);
/* 290 */
EXTERN Window		Tk_MakeWindow(Tk_Window tkwin, Window parent);

typedef struct {
    const struct TkPlatStubs *tkPlatStubs;
    const struct TkIntStubs *tkIntStubs;
    const struct TkIntPlatStubs *tkIntPlatStubs;
    const struct TkIntXlibStubs *tkIntXlibStubs;
} TkStubHooks;

typedef struct TkStubs {
    int magic;
    const TkStubHooks *hooks;

    void (*tk_MainLoop) (void); /* 0 */
    XColor * (*tk_3DBorderColor) (Tk_3DBorder border); /* 1 */
    GC (*tk_3DBorderGC) (Tk_Window tkwin, Tk_3DBorder border, int which); /* 2 */
    void (*tk_3DHorizontalBevel) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int x, int y, int width, int height, int leftIn, int rightIn, int topBevel, int relief); /* 3 */
    void (*tk_3DVerticalBevel) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int x, int y, int width, int height, int leftBevel, int relief); /* 4 */
    void (*tk_AddOption) (Tk_Window tkwin, const char *name, const char *value, int priority); /* 5 */
    void (*tk_BindEvent) (Tk_BindingTable bindingTable, XEvent *eventPtr, Tk_Window tkwin, Tcl_Size numObjects, void **objectPtr); /* 6 */
    void (*tk_BindEvent) (Tk_BindingTable bindingTable, XEvent *eventPtr, Tk_Window tkwin, int numObjects, ClientData *objectPtr); /* 6 */
    void (*tk_CanvasDrawableCoords) (Tk_Canvas canvas, double x, double y, short *drawableXPtr, short *drawableYPtr); /* 7 */
    void (*tk_CanvasEventuallyRedraw) (Tk_Canvas canvas, int x1, int y1, int x2, int y2); /* 8 */
    int (*tk_CanvasGetCoord) (Tcl_Interp *interp, Tk_Canvas canvas, const char *str, double *doublePtr); /* 9 */
    Tk_CanvasTextInfo * (*tk_CanvasGetTextInfo) (Tk_Canvas canvas); /* 10 */
    int (*tk_CanvasPsBitmap) (Tcl_Interp *interp, Tk_Canvas canvas, Pixmap bitmap, int x, int y, int width, int height); /* 11 */
    int (*tk_CanvasPsColor) (Tcl_Interp *interp, Tk_Canvas canvas, XColor *colorPtr); /* 12 */
    int (*tk_CanvasPsFont) (Tcl_Interp *interp, Tk_Canvas canvas, Tk_Font font); /* 13 */
    void (*tk_CanvasPsPath) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr, Tcl_Size numPoints); /* 14 */
    void (*tk_CanvasPsPath) (Tcl_Interp *interp, Tk_Canvas canvas, double *coordPtr, int numPoints); /* 14 */
    int (*tk_CanvasPsStipple) (Tcl_Interp *interp, Tk_Canvas canvas, Pixmap bitmap); /* 15 */
    double (*tk_CanvasPsY) (Tk_Canvas canvas, double y); /* 16 */
    void (*tk_CanvasSetStippleOrigin) (Tk_Canvas canvas, GC gc); /* 17 */
    int (*tk_CanvasTagsParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 18 */
    const char * (*tk_CanvasTagsPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 19 */
    int (*tk_CanvasTagsParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 18 */
    CONST86 char * (*tk_CanvasTagsPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 19 */
    Tk_Window (*tk_CanvasTkwin) (Tk_Canvas canvas); /* 20 */
    void (*tk_CanvasWindowCoords) (Tk_Canvas canvas, double x, double y, short *screenXPtr, short *screenYPtr); /* 21 */
    void (*tk_ChangeWindowAttributes) (Tk_Window tkwin, unsigned long valueMask, XSetWindowAttributes *attsPtr); /* 22 */
    int (*tk_CharBbox) (Tk_TextLayout layout, Tcl_Size index, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); /* 23 */
    int (*tk_CharBbox) (Tk_TextLayout layout, int index, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); /* 23 */
    void (*tk_ClearSelection) (Tk_Window tkwin, Atom selection); /* 24 */
    int (*tk_ClipboardAppend) (Tcl_Interp *interp, Tk_Window tkwin, Atom target, Atom format, const char *buffer); /* 25 */
    int (*tk_ClipboardClear) (Tcl_Interp *interp, Tk_Window tkwin); /* 26 */
    int (*tk_ConfigureInfo) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, void *widgRec, const char *argvName, int flags); /* 27 */
    int (*tk_ConfigureValue) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, void *widgRec, const char *argvName, int flags); /* 28 */
    int (*tk_ConfigureWidget) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, Tcl_Size objc, Tcl_Obj *const *objv, void *widgRec, int flags); /* 29 */
    int (*tk_ConfigureInfo) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, char *widgRec, const char *argvName, int flags); /* 27 */
    int (*tk_ConfigureValue) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, char *widgRec, const char *argvName, int flags); /* 28 */
    int (*tk_ConfigureWidget) (Tcl_Interp *interp, Tk_Window tkwin, const Tk_ConfigSpec *specs, int argc, CONST84 char **argv, char *widgRec, int flags); /* 29 */
    void (*tk_ConfigureWindow) (Tk_Window tkwin, unsigned int valueMask, XWindowChanges *valuePtr); /* 30 */
    Tk_TextLayout (*tk_ComputeTextLayout) (Tk_Font font, const char *str, Tcl_Size numChars, int wrapLength, Tk_Justify justify, int flags, int *widthPtr, int *heightPtr); /* 31 */
    Tk_TextLayout (*tk_ComputeTextLayout) (Tk_Font font, const char *str, int numChars, int wrapLength, Tk_Justify justify, int flags, int *widthPtr, int *heightPtr); /* 31 */
    Tk_Window (*tk_CoordsToWindow) (int rootX, int rootY, Tk_Window tkwin); /* 32 */
    unsigned long (*tk_CreateBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, void *object, const char *eventStr, const char *script, int append); /* 33 */
    unsigned long (*tk_CreateBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, ClientData object, const char *eventStr, const char *script, int append); /* 33 */
    Tk_BindingTable (*tk_CreateBindingTable) (Tcl_Interp *interp); /* 34 */
    Tk_ErrorHandler (*tk_CreateErrorHandler) (Display *display, int errNum, int request, int minorCode, Tk_ErrorProc *errorProc, void *clientData); /* 35 */
    void (*tk_CreateEventHandler) (Tk_Window token, unsigned long mask, Tk_EventProc *proc, void *clientData); /* 36 */
    void (*tk_CreateGenericHandler) (Tk_GenericProc *proc, void *clientData); /* 37 */
    Tk_ErrorHandler (*tk_CreateErrorHandler) (Display *display, int errNum, int request, int minorCode, Tk_ErrorProc *errorProc, ClientData clientData); /* 35 */
    void (*tk_CreateEventHandler) (Tk_Window token, unsigned long mask, Tk_EventProc *proc, ClientData clientData); /* 36 */
    void (*tk_CreateGenericHandler) (Tk_GenericProc *proc, ClientData clientData); /* 37 */
    void (*tk_CreateImageType) (const Tk_ImageType *typePtr); /* 38 */
    void (*tk_CreateItemType) (Tk_ItemType *typePtr); /* 39 */
    void (*tk_CreatePhotoImageFormat) (const Tk_PhotoImageFormat *formatPtr); /* 40 */
    void (*tk_CreateSelHandler) (Tk_Window tkwin, Atom selection, Atom target, Tk_SelectionProc *proc, void *clientData, Atom format); /* 41 */
    void (*tk_CreateSelHandler) (Tk_Window tkwin, Atom selection, Atom target, Tk_SelectionProc *proc, ClientData clientData, Atom format); /* 41 */
    Tk_Window (*tk_CreateWindow) (Tcl_Interp *interp, Tk_Window parent, const char *name, const char *screenName); /* 42 */
    Tk_Window (*tk_CreateWindowFromPath) (Tcl_Interp *interp, Tk_Window tkwin, const char *pathName, const char *screenName); /* 43 */
    int (*tk_DefineBitmap) (Tcl_Interp *interp, const char *name, const void *source, int width, int height); /* 44 */
    void (*tk_DefineCursor) (Tk_Window window, Tk_Cursor cursor); /* 45 */
    void (*tk_DeleteAllBindings) (Tk_BindingTable bindingTable, void *object); /* 46 */
    int (*tk_DeleteBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, void *object, const char *eventStr); /* 47 */
    void (*tk_DeleteAllBindings) (Tk_BindingTable bindingTable, ClientData object); /* 46 */
    int (*tk_DeleteBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, ClientData object, const char *eventStr); /* 47 */
    void (*tk_DeleteBindingTable) (Tk_BindingTable bindingTable); /* 48 */
    void (*tk_DeleteErrorHandler) (Tk_ErrorHandler handler); /* 49 */
    void (*tk_DeleteEventHandler) (Tk_Window token, unsigned long mask, Tk_EventProc *proc, void *clientData); /* 50 */
    void (*tk_DeleteGenericHandler) (Tk_GenericProc *proc, void *clientData); /* 51 */
    void (*tk_DeleteEventHandler) (Tk_Window token, unsigned long mask, Tk_EventProc *proc, ClientData clientData); /* 50 */
    void (*tk_DeleteGenericHandler) (Tk_GenericProc *proc, ClientData clientData); /* 51 */
    void (*tk_DeleteImage) (Tcl_Interp *interp, const char *name); /* 52 */
    void (*tk_DeleteSelHandler) (Tk_Window tkwin, Atom selection, Atom target); /* 53 */
    void (*tk_DestroyWindow) (Tk_Window tkwin); /* 54 */
    const char * (*tk_DisplayName) (Tk_Window tkwin); /* 55 */
    CONST84_RETURN char * (*tk_DisplayName) (Tk_Window tkwin); /* 55 */
    int (*tk_DistanceToTextLayout) (Tk_TextLayout layout, int x, int y); /* 56 */
    void (*tk_Draw3DPolygon) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint *pointPtr, Tcl_Size numPoints, int borderWidth, int leftRelief); /* 57 */
    void (*tk_Draw3DPolygon) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint *pointPtr, int numPoints, int borderWidth, int leftRelief); /* 57 */
    void (*tk_Draw3DRectangle) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int x, int y, int width, int height, int borderWidth, int relief); /* 58 */
    void (*tk_DrawChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, Tcl_Size numBytes, int x, int y); /* 59 */
    void (*tk_DrawChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, int x, int y); /* 59 */
    void (*tk_DrawFocusHighlight) (Tk_Window tkwin, GC gc, int width, Drawable drawable); /* 60 */
    void (*tk_DrawTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, Tcl_Size firstChar, Tcl_Size lastChar); /* 61 */
    void (*tk_Fill3DPolygon) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint *pointPtr, Tcl_Size numPoints, int borderWidth, int leftRelief); /* 62 */
    void (*tk_DrawTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int firstChar, int lastChar); /* 61 */
    void (*tk_Fill3DPolygon) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint *pointPtr, int numPoints, int borderWidth, int leftRelief); /* 62 */
    void (*tk_Fill3DRectangle) (Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int x, int y, int width, int height, int borderWidth, int relief); /* 63 */
    Tk_PhotoHandle (*tk_FindPhoto) (Tcl_Interp *interp, const char *imageName); /* 64 */
    Font (*tk_FontId) (Tk_Font font); /* 65 */
    void (*tk_Free3DBorder) (Tk_3DBorder border); /* 66 */
    void (*tk_FreeBitmap) (Display *display, Pixmap bitmap); /* 67 */
    void (*tk_FreeColor) (XColor *colorPtr); /* 68 */
    void (*tk_FreeColormap) (Display *display, Colormap colormap); /* 69 */
    void (*tk_FreeCursor) (Display *display, Tk_Cursor cursor); /* 70 */
    void (*tk_FreeFont) (Tk_Font f); /* 71 */
    void (*tk_FreeGC) (Display *display, GC gc); /* 72 */
    void (*tk_FreeImage) (Tk_Image image); /* 73 */
    void (*tk_FreeOptions) (const Tk_ConfigSpec *specs, void *widgRec, Display *display, int needFlags); /* 74 */
    void (*tk_FreeOptions) (const Tk_ConfigSpec *specs, char *widgRec, Display *display, int needFlags); /* 74 */
    void (*tk_FreePixmap) (Display *display, Pixmap pixmap); /* 75 */
    void (*tk_FreeTextLayout) (Tk_TextLayout textLayout); /* 76 */
    void (*reserved77)(void);
    TCL_DEPRECATED_API("function does nothing, call can be removed") void (*tk_FreeXId) (Display *display, XID xid); /* 77 */
    GC (*tk_GCForColor) (XColor *colorPtr, Drawable drawable); /* 78 */
    void (*tk_GeometryRequest) (Tk_Window tkwin, int reqWidth, int reqHeight); /* 79 */
    Tk_3DBorder (*tk_Get3DBorder) (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid colorName); /* 80 */
    void (*tk_GetAllBindings) (Tcl_Interp *interp, Tk_BindingTable bindingTable, void *object); /* 81 */
    void (*tk_GetAllBindings) (Tcl_Interp *interp, Tk_BindingTable bindingTable, ClientData object); /* 81 */
    int (*tk_GetAnchor) (Tcl_Interp *interp, const char *str, Tk_Anchor *anchorPtr); /* 82 */
    const char * (*tk_GetAtomName) (Tk_Window tkwin, Atom atom); /* 83 */
    const char * (*tk_GetBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, void *object, const char *eventStr); /* 84 */
    CONST84_RETURN char * (*tk_GetAtomName) (Tk_Window tkwin, Atom atom); /* 83 */
    CONST84_RETURN char * (*tk_GetBinding) (Tcl_Interp *interp, Tk_BindingTable bindingTable, ClientData object, const char *eventStr); /* 84 */
    Pixmap (*tk_GetBitmap) (Tcl_Interp *interp, Tk_Window tkwin, const char *str); /* 85 */
    Pixmap (*tk_GetBitmapFromData) (Tcl_Interp *interp, Tk_Window tkwin, const void *source, int width, int height); /* 86 */
    int (*tk_GetCapStyle) (Tcl_Interp *interp, const char *str, int *capPtr); /* 87 */
    XColor * (*tk_GetColor) (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid name); /* 88 */
    XColor * (*tk_GetColorByValue) (Tk_Window tkwin, XColor *colorPtr); /* 89 */
    Colormap (*tk_GetColormap) (Tcl_Interp *interp, Tk_Window tkwin, const char *str); /* 90 */
    Tk_Cursor (*tk_GetCursor) (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid str); /* 91 */
    Tk_Cursor (*tk_GetCursorFromData) (Tcl_Interp *interp, Tk_Window tkwin, const char *source, const char *mask, int width, int height, int xHot, int yHot, Tk_Uid fg, Tk_Uid bg); /* 92 */
    Tk_Font (*tk_GetFont) (Tcl_Interp *interp, Tk_Window tkwin, const char *str); /* 93 */
    Tk_Font (*tk_GetFontFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 94 */
    void (*tk_GetFontMetrics) (Tk_Font font, Tk_FontMetrics *fmPtr); /* 95 */
    GC (*tk_GetGC) (Tk_Window tkwin, unsigned long valueMask, XGCValues *valuePtr); /* 96 */
    Tk_Image (*tk_GetImage) (Tcl_Interp *interp, Tk_Window tkwin, const char *name, Tk_ImageChangedProc *changeProc, void *clientData); /* 97 */
    void * (*tk_GetImageModelData) (Tcl_Interp *interp, const char *name, const Tk_ImageType **typePtrPtr); /* 98 */
    Tk_Image (*tk_GetImage) (Tcl_Interp *interp, Tk_Window tkwin, const char *name, Tk_ImageChangedProc *changeProc, ClientData clientData); /* 97 */
    ClientData (*tk_GetImageMasterData) (Tcl_Interp *interp, const char *name, CONST86 Tk_ImageType **typePtrPtr); /* 98 */
    Tk_ItemType * (*tk_GetItemTypes) (void); /* 99 */
    int (*tk_GetJoinStyle) (Tcl_Interp *interp, const char *str, int *joinPtr); /* 100 */
    int (*tk_GetJustify) (Tcl_Interp *interp, const char *str, Tk_Justify *justifyPtr); /* 101 */
    int (*tk_GetNumMainWindows) (void); /* 102 */
    Tk_Uid (*tk_GetOption) (Tk_Window tkwin, const char *name, const char *className); /* 103 */
    int (*tk_GetPixels) (Tcl_Interp *interp, Tk_Window tkwin, const char *str, int *intPtr); /* 104 */
    Pixmap (*tk_GetPixmap) (Display *display, Drawable d, int width, int height, int depth); /* 105 */
    int (*tk_GetRelief) (Tcl_Interp *interp, const char *name, int *reliefPtr); /* 106 */
    void (*tk_GetRootCoords) (Tk_Window tkwin, int *xPtr, int *yPtr); /* 107 */
    int (*tk_GetScrollInfo) (Tcl_Interp *interp, Tcl_Size argc, const char **argv, double *dblPtr, int *intPtr); /* 108 */
    int (*tk_GetScrollInfo) (Tcl_Interp *interp, int argc, CONST84 char **argv, double *dblPtr, int *intPtr); /* 108 */
    int (*tk_GetScreenMM) (Tcl_Interp *interp, Tk_Window tkwin, const char *str, double *doublePtr); /* 109 */
    int (*tk_GetSelection) (Tcl_Interp *interp, Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc *proc, void *clientData); /* 110 */
    int (*tk_GetSelection) (Tcl_Interp *interp, Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc *proc, ClientData clientData); /* 110 */
    Tk_Uid (*tk_GetUid) (const char *str); /* 111 */
    Visual * (*tk_GetVisual) (Tcl_Interp *interp, Tk_Window tkwin, const char *str, int *depthPtr, Colormap *colormapPtr); /* 112 */
    void (*tk_GetVRootGeometry) (Tk_Window tkwin, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); /* 113 */
    int (*tk_Grab) (Tcl_Interp *interp, Tk_Window tkwin, int grabGlobal); /* 114 */
    void (*tk_HandleEvent) (XEvent *eventPtr); /* 115 */
    Tk_Window (*tk_IdToWindow) (Display *display, Window window); /* 116 */
    void (*tk_ImageChanged) (Tk_ImageModel model, int x, int y, int width, int height, int imageWidth, int imageHeight); /* 117 */
    void (*reserved118)(void);
    void (*tk_ImageChanged) (Tk_ImageMaster master, int x, int y, int width, int height, int imageWidth, int imageHeight); /* 117 */
    int (*tk_Init) (Tcl_Interp *interp); /* 118 */
    Atom (*tk_InternAtom) (Tk_Window tkwin, const char *name); /* 119 */
    int (*tk_IntersectTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height); /* 120 */
    void (*tk_MaintainGeometry) (Tk_Window window, Tk_Window container, int x, int y, int width, int height); /* 121 */
    void (*tk_MaintainGeometry) (Tk_Window slave, Tk_Window master, int x, int y, int width, int height); /* 121 */
    Tk_Window (*tk_MainWindow) (Tcl_Interp *interp); /* 122 */
    void (*tk_MakeWindowExist) (Tk_Window tkwin); /* 123 */
    void (*tk_ManageGeometry) (Tk_Window tkwin, const Tk_GeomMgr *mgrPtr, void *clientData); /* 124 */
    void (*tk_ManageGeometry) (Tk_Window tkwin, const Tk_GeomMgr *mgrPtr, ClientData clientData); /* 124 */
    void (*tk_MapWindow) (Tk_Window tkwin); /* 125 */
    int (*tk_MeasureChars) (Tk_Font tkfont, const char *source, Tcl_Size numBytes, int maxPixels, int flags, int *lengthPtr); /* 126 */
    int (*tk_MeasureChars) (Tk_Font tkfont, const char *source, int numBytes, int maxPixels, int flags, int *lengthPtr); /* 126 */
    void (*tk_MoveResizeWindow) (Tk_Window tkwin, int x, int y, int width, int height); /* 127 */
    void (*tk_MoveWindow) (Tk_Window tkwin, int x, int y); /* 128 */
    void (*tk_MoveToplevelWindow) (Tk_Window tkwin, int x, int y); /* 129 */
    const char * (*tk_NameOf3DBorder) (Tk_3DBorder border); /* 130 */
    const char * (*tk_NameOfAnchor) (Tk_Anchor anchor); /* 131 */
    const char * (*tk_NameOfBitmap) (Display *display, Pixmap bitmap); /* 132 */
    const char * (*tk_NameOfCapStyle) (int cap); /* 133 */
    const char * (*tk_NameOfColor) (XColor *colorPtr); /* 134 */
    const char * (*tk_NameOfCursor) (Display *display, Tk_Cursor cursor); /* 135 */
    const char * (*tk_NameOfFont) (Tk_Font font); /* 136 */
    const char * (*tk_NameOfImage) (Tk_ImageModel model); /* 137 */
    const char * (*tk_NameOfJoinStyle) (int join); /* 138 */
    const char * (*tk_NameOfJustify) (Tk_Justify justify); /* 139 */
    const char * (*tk_NameOfRelief) (int relief); /* 140 */
    CONST84_RETURN char * (*tk_NameOf3DBorder) (Tk_3DBorder border); /* 130 */
    CONST84_RETURN char * (*tk_NameOfAnchor) (Tk_Anchor anchor); /* 131 */
    CONST84_RETURN char * (*tk_NameOfBitmap) (Display *display, Pixmap bitmap); /* 132 */
    CONST84_RETURN char * (*tk_NameOfCapStyle) (int cap); /* 133 */
    CONST84_RETURN char * (*tk_NameOfColor) (XColor *colorPtr); /* 134 */
    CONST84_RETURN char * (*tk_NameOfCursor) (Display *display, Tk_Cursor cursor); /* 135 */
    CONST84_RETURN char * (*tk_NameOfFont) (Tk_Font font); /* 136 */
    CONST84_RETURN char * (*tk_NameOfImage) (Tk_ImageMaster imageMaster); /* 137 */
    CONST84_RETURN char * (*tk_NameOfJoinStyle) (int join); /* 138 */
    CONST84_RETURN char * (*tk_NameOfJustify) (Tk_Justify justify); /* 139 */
    CONST84_RETURN char * (*tk_NameOfRelief) (int relief); /* 140 */
    Tk_Window (*tk_NameToWindow) (Tcl_Interp *interp, const char *pathName, Tk_Window tkwin); /* 141 */
    void (*tk_OwnSelection) (Tk_Window tkwin, Atom selection, Tk_LostSelProc *proc, void *clientData); /* 142 */
    int (*tk_ParseArgv) (Tcl_Interp *interp, Tk_Window tkwin, int *argcPtr, const char **argv, const Tk_ArgvInfo *argTable, int flags); /* 143 */
    void (*reserved144)(void);
    void (*reserved145)(void);
    void (*tk_OwnSelection) (Tk_Window tkwin, Atom selection, Tk_LostSelProc *proc, ClientData clientData); /* 142 */
    int (*tk_ParseArgv) (Tcl_Interp *interp, Tk_Window tkwin, int *argcPtr, CONST84 char **argv, const Tk_ArgvInfo *argTable, int flags); /* 143 */
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoPutBlock_NoComposite) (Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height); /* 144 */
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoPutZoomedBlock_NoComposite) (Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height, int zoomX, int zoomY, int subsampleX, int subsampleY); /* 145 */
    int (*tk_PhotoGetImage) (Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr); /* 146 */
    void (*tk_PhotoBlank) (Tk_PhotoHandle handle); /* 147 */
    void (*reserved148)(void);
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoExpand_Panic) (Tk_PhotoHandle handle, int width, int height); /* 148 */
    void (*tk_PhotoGetSize) (Tk_PhotoHandle handle, int *widthPtr, int *heightPtr); /* 149 */
    void (*reserved150)(void);
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoSetSize_Panic) (Tk_PhotoHandle handle, int width, int height); /* 150 */
    int (*tk_PointToChar) (Tk_TextLayout layout, int x, int y); /* 151 */
    int (*tk_PostscriptFontName) (Tk_Font tkfont, Tcl_DString *dsPtr); /* 152 */
    void (*tk_PreserveColormap) (Display *display, Colormap colormap); /* 153 */
    void (*tk_QueueWindowEvent) (XEvent *eventPtr, Tcl_QueuePosition position); /* 154 */
    void (*tk_RedrawImage) (Tk_Image image, int imageX, int imageY, int width, int height, Drawable drawable, int drawableX, int drawableY); /* 155 */
    void (*tk_ResizeWindow) (Tk_Window tkwin, int width, int height); /* 156 */
    int (*tk_RestackWindow) (Tk_Window tkwin, int aboveBelow, Tk_Window other); /* 157 */
    Tk_RestrictProc * (*tk_RestrictEvents) (Tk_RestrictProc *proc, void *arg, void **prevArgPtr); /* 158 */
    void (*reserved159)(void);
    Tk_RestrictProc * (*tk_RestrictEvents) (Tk_RestrictProc *proc, ClientData arg, ClientData *prevArgPtr); /* 158 */
    int (*tk_SafeInit) (Tcl_Interp *interp); /* 159 */
    const char * (*tk_SetAppName) (Tk_Window tkwin, const char *name); /* 160 */
    void (*tk_SetBackgroundFromBorder) (Tk_Window tkwin, Tk_3DBorder border); /* 161 */
    void (*tk_SetClass) (Tk_Window tkwin, const char *className); /* 162 */
    void (*tk_SetGrid) (Tk_Window tkwin, int reqWidth, int reqHeight, int gridWidth, int gridHeight); /* 163 */
    void (*tk_SetInternalBorder) (Tk_Window tkwin, int width); /* 164 */
    void (*tk_SetWindowBackground) (Tk_Window tkwin, unsigned long pixel); /* 165 */
    void (*tk_SetWindowBackgroundPixmap) (Tk_Window tkwin, Pixmap pixmap); /* 166 */
    void (*tk_SetWindowBorder) (Tk_Window tkwin, unsigned long pixel); /* 167 */
    void (*tk_SetWindowBorderWidth) (Tk_Window tkwin, int width); /* 168 */
    void (*tk_SetWindowBorderPixmap) (Tk_Window tkwin, Pixmap pixmap); /* 169 */
    void (*tk_SetWindowColormap) (Tk_Window tkwin, Colormap colormap); /* 170 */
    int (*tk_SetWindowVisual) (Tk_Window tkwin, Visual *visual, int depth, Colormap colormap); /* 171 */
    void (*tk_SizeOfBitmap) (Display *display, Pixmap bitmap, int *widthPtr, int *heightPtr); /* 172 */
    void (*tk_SizeOfImage) (Tk_Image image, int *widthPtr, int *heightPtr); /* 173 */
    int (*tk_StrictMotif) (Tk_Window tkwin); /* 174 */
    void (*tk_TextLayoutToPostscript) (Tcl_Interp *interp, Tk_TextLayout layout); /* 175 */
    int (*tk_TextWidth) (Tk_Font font, const char *str, Tcl_Size numBytes); /* 176 */
    int (*tk_TextWidth) (Tk_Font font, const char *str, int numBytes); /* 176 */
    void (*tk_UndefineCursor) (Tk_Window window); /* 177 */
    void (*tk_UnderlineChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int x, int y, Tcl_Size firstByte, Tcl_Size lastByte); /* 178 */
    void (*tk_UnderlineChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int x, int y, int firstByte, int lastByte); /* 178 */
    void (*tk_UnderlineTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int underline); /* 179 */
    void (*tk_Ungrab) (Tk_Window tkwin); /* 180 */
    void (*tk_UnmaintainGeometry) (Tk_Window window, Tk_Window container); /* 181 */
    void (*tk_UnmaintainGeometry) (Tk_Window slave, Tk_Window master); /* 181 */
    void (*tk_UnmapWindow) (Tk_Window tkwin); /* 182 */
    void (*tk_UnsetGrid) (Tk_Window tkwin); /* 183 */
    void (*tk_UpdatePointer) (Tk_Window tkwin, int x, int y, int state); /* 184 */
    Pixmap (*tk_AllocBitmapFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr); /* 185 */
    Tk_3DBorder (*tk_Alloc3DBorderFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr); /* 186 */
    XColor * (*tk_AllocColorFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr); /* 187 */
    Tk_Cursor (*tk_AllocCursorFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr); /* 188 */
    Tk_Font (*tk_AllocFontFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr); /* 189 */
    Tk_OptionTable (*tk_CreateOptionTable) (Tcl_Interp *interp, const Tk_OptionSpec *templatePtr); /* 190 */
    void (*tk_DeleteOptionTable) (Tk_OptionTable optionTable); /* 191 */
    void (*tk_Free3DBorderFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 192 */
    void (*tk_FreeBitmapFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 193 */
    void (*tk_FreeColorFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 194 */
    void (*tk_FreeConfigOptions) (void *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin); /* 195 */
    void (*tk_FreeConfigOptions) (char *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin); /* 195 */
    void (*tk_FreeSavedOptions) (Tk_SavedOptions *savePtr); /* 196 */
    void (*tk_FreeCursorFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 197 */
    void (*tk_FreeFontFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 198 */
    Tk_3DBorder (*tk_Get3DBorderFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 199 */
    int (*tk_GetAnchorFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Tk_Anchor *anchorPtr); /* 200 */
    Pixmap (*tk_GetBitmapFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 201 */
    XColor * (*tk_GetColorFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 202 */
    Tk_Cursor (*tk_GetCursorFromObj) (Tk_Window tkwin, Tcl_Obj *objPtr); /* 203 */
    Tcl_Obj * (*tk_GetOptionInfo) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin); /* 204 */
    Tcl_Obj * (*tk_GetOptionValue) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin); /* 205 */
    Tcl_Obj * (*tk_GetOptionInfo) (Tcl_Interp *interp, char *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin); /* 204 */
    Tcl_Obj * (*tk_GetOptionValue) (Tcl_Interp *interp, char *recordPtr, Tk_OptionTable optionTable, Tcl_Obj *namePtr, Tk_Window tkwin); /* 205 */
    int (*tk_GetJustifyFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Tk_Justify *justifyPtr); /* 206 */
    int (*tk_GetMMFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, double *doublePtr); /* 207 */
    int (*tk_GetPixelsFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, int *intPtr); /* 208 */
    int (*tk_GetReliefFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr); /* 209 */
    int (*tk_GetScrollInfoObj) (Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], double *dblPtr, int *intPtr); /* 210 */
    int (*tk_InitOptions) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin); /* 211 */
    void (*reserved212)(void);
    int (*tk_GetScrollInfoObj) (Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], double *dblPtr, int *intPtr); /* 210 */
    int (*tk_InitOptions) (Tcl_Interp *interp, char *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin); /* 211 */
    void (*tk_MainEx) (int argc, char **argv, Tcl_AppInitProc *appInitProc, Tcl_Interp *interp); /* 212 */
    void (*tk_RestoreSavedOptions) (Tk_SavedOptions *savePtr); /* 213 */
    int (*tk_SetOptions) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionTable, Tcl_Size objc, Tcl_Obj *const objv[], Tk_Window tkwin, Tk_SavedOptions *savePtr, int *maskPtr); /* 214 */
    int (*tk_SetOptions) (Tcl_Interp *interp, char *recordPtr, Tk_OptionTable optionTable, int objc, Tcl_Obj *const objv[], Tk_Window tkwin, Tk_SavedOptions *savePtr, int *maskPtr); /* 214 */
    void (*tk_InitConsoleChannels) (Tcl_Interp *interp); /* 215 */
    void (*reserved216)(void);
    int (*tk_CreateConsoleWindow) (Tcl_Interp *interp); /* 216 */
    void (*tk_CreateSmoothMethod) (Tcl_Interp *interp, const Tk_SmoothMethod *method); /* 217 */
    void (*reserved218)(void);
    void (*reserved219)(void);
    int (*tk_GetDash) (Tcl_Interp *interp, const char *value, Tk_Dash *dash); /* 220 */
    void (*tk_CreateOutline) (Tk_Outline *outline); /* 221 */
    void (*tk_DeleteOutline) (Display *display, Tk_Outline *outline); /* 222 */
    int (*tk_ConfigOutlineGC) (XGCValues *gcValues, Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline); /* 223 */
    int (*tk_ChangeOutlineGC) (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline); /* 224 */
    int (*tk_ResetOutlineGC) (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline); /* 225 */
    int (*tk_CanvasPsOutline) (Tk_Canvas canvas, Tk_Item *item, Tk_Outline *outline); /* 226 */
    void (*tk_SetTSOrigin) (Tk_Window tkwin, GC gc, int x, int y); /* 227 */
    int (*tk_CanvasGetCoordFromObj) (Tcl_Interp *interp, Tk_Canvas canvas, Tcl_Obj *obj, double *doublePtr); /* 228 */
    void (*tk_CanvasSetOffset) (Tk_Canvas canvas, GC gc, Tk_TSOffset *offset); /* 229 */
    void (*tk_DitherPhoto) (Tk_PhotoHandle handle, int x, int y, int width, int height); /* 230 */
    int (*tk_PostscriptBitmap) (Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psInfo, Pixmap bitmap, int startX, int startY, int width, int height); /* 231 */
    int (*tk_PostscriptColor) (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, XColor *colorPtr); /* 232 */
    int (*tk_PostscriptFont) (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, Tk_Font font); /* 233 */
    int (*tk_PostscriptImage) (Tk_Image image, Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y, int width, int height, int prepass); /* 234 */
    void (*tk_PostscriptPath) (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, double *coordPtr, Tcl_Size numPoints); /* 235 */
    void (*tk_PostscriptPath) (Tcl_Interp *interp, Tk_PostscriptInfo psInfo, double *coordPtr, int numPoints); /* 235 */
    int (*tk_PostscriptStipple) (Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psInfo, Pixmap bitmap); /* 236 */
    double (*tk_PostscriptY) (double y, Tk_PostscriptInfo psInfo); /* 237 */
    int (*tk_PostscriptPhoto) (Tcl_Interp *interp, Tk_PhotoImageBlock *blockPtr, Tk_PostscriptInfo psInfo, int width, int height); /* 238 */
    void (*tk_CreateClientMessageHandler) (Tk_ClientMessageProc *proc); /* 239 */
    void (*tk_DeleteClientMessageHandler) (Tk_ClientMessageProc *proc); /* 240 */
    Tk_Window (*tk_CreateAnonymousWindow) (Tcl_Interp *interp, Tk_Window parent, const char *screenName); /* 241 */
    void (*tk_SetClassProcs) (Tk_Window tkwin, const Tk_ClassProcs *procs, void *instanceData); /* 242 */
    void (*tk_SetClassProcs) (Tk_Window tkwin, const Tk_ClassProcs *procs, ClientData instanceData); /* 242 */
    void (*tk_SetInternalBorderEx) (Tk_Window tkwin, int left, int right, int top, int bottom); /* 243 */
    void (*tk_SetMinimumRequestSize) (Tk_Window tkwin, int minWidth, int minHeight); /* 244 */
    void (*tk_SetCaretPos) (Tk_Window tkwin, int x, int y, int height); /* 245 */
    void (*reserved246)(void);
    void (*reserved247)(void);
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoPutBlock_Panic) (Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height, int compRule); /* 246 */
    TCL_DEPRECATED_API("function signature changed") void (*tk_PhotoPutZoomedBlock_Panic) (Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height, int zoomX, int zoomY, int subsampleX, int subsampleY, int compRule); /* 247 */
    int (*tk_CollapseMotionEvents) (Display *display, int collapse); /* 248 */
    Tk_StyleEngine (*tk_RegisterStyleEngine) (const char *name, Tk_StyleEngine parent); /* 249 */
    Tk_StyleEngine (*tk_GetStyleEngine) (const char *name); /* 250 */
    int (*tk_RegisterStyledElement) (Tk_StyleEngine engine, Tk_ElementSpec *templatePtr); /* 251 */
    int (*tk_GetElementId) (const char *name); /* 252 */
    Tk_Style (*tk_CreateStyle) (const char *name, Tk_StyleEngine engine, void *clientData); /* 253 */
    Tk_Style (*tk_CreateStyle) (const char *name, Tk_StyleEngine engine, ClientData clientData); /* 253 */
    Tk_Style (*tk_GetStyle) (Tcl_Interp *interp, const char *name); /* 254 */
    void (*tk_FreeStyle) (Tk_Style style); /* 255 */
    const char * (*tk_NameOfStyle) (Tk_Style style); /* 256 */
    Tk_Style (*tk_AllocStyleFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr); /* 257 */
    void (*reserved258)(void);
    void (*reserved259)(void);
    Tk_StyledElement (*tk_GetStyledElement) (Tk_Style style, Tcl_Size elementId, Tk_OptionTable optionTable); /* 260 */
    void (*tk_GetElementSize) (Tk_Style style, Tk_StyledElement element, void *recordPtr, Tk_Window tkwin, int width, int height, int inner, int *widthPtr, int *heightPtr); /* 261 */
    void (*tk_GetElementBox) (Tk_Style style, Tk_StyledElement element, void *recordPtr, Tk_Window tkwin, int x, int y, int width, int height, int inner, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); /* 262 */
    int (*tk_GetElementBorderWidth) (Tk_Style style, Tk_StyledElement element, void *recordPtr, Tk_Window tkwin); /* 263 */
    void (*tk_DrawElement) (Tk_Style style, Tk_StyledElement element, void *recordPtr, Tk_Window tkwin, Drawable d, int x, int y, int width, int height, int state); /* 264 */
    Tk_Style (*tk_GetStyleFromObj) (Tcl_Obj *objPtr); /* 258 */
    void (*tk_FreeStyleFromObj) (Tcl_Obj *objPtr); /* 259 */
    Tk_StyledElement (*tk_GetStyledElement) (Tk_Style style, int elementId, Tk_OptionTable optionTable); /* 260 */
    void (*tk_GetElementSize) (Tk_Style style, Tk_StyledElement element, char *recordPtr, Tk_Window tkwin, int width, int height, int inner, int *widthPtr, int *heightPtr); /* 261 */
    void (*tk_GetElementBox) (Tk_Style style, Tk_StyledElement element, char *recordPtr, Tk_Window tkwin, int x, int y, int width, int height, int inner, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr); /* 262 */
    int (*tk_GetElementBorderWidth) (Tk_Style style, Tk_StyledElement element, char *recordPtr, Tk_Window tkwin); /* 263 */
    void (*tk_DrawElement) (Tk_Style style, Tk_StyledElement element, char *recordPtr, Tk_Window tkwin, Drawable d, int x, int y, int width, int height, int state); /* 264 */
    int (*tk_PhotoExpand) (Tcl_Interp *interp, Tk_PhotoHandle handle, int width, int height); /* 265 */
    int (*tk_PhotoPutBlock) (Tcl_Interp *interp, Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height, int compRule); /* 266 */
    int (*tk_PhotoPutZoomedBlock) (Tcl_Interp *interp, Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr, int x, int y, int width, int height, int zoomX, int zoomY, int subsampleX, int subsampleY, int compRule); /* 267 */
    int (*tk_PhotoSetSize) (Tcl_Interp *interp, Tk_PhotoHandle handle, int width, int height); /* 268 */
    long (*tk_GetUserInactiveTime) (Display *dpy); /* 269 */
    void (*tk_ResetUserInactiveTime) (Display *dpy); /* 270 */
    Tcl_Interp * (*tk_Interp) (Tk_Window tkwin); /* 271 */
    void (*reserved272)(void);
    void (*tk_CreateOldImageType) (const Tk_ImageType *typePtr); /* 272 */
    void (*reserved273)(void);
    int (*tk_AlwaysShowSelection) (Tk_Window tkwin); /* 274 */
    unsigned (*tk_GetButtonMask) (unsigned button); /* 275 */
    int (*tk_GetDoublePixelsFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, double *doublePtr); /* 276 */
    Tcl_Obj * (*tk_NewWindowObj) (Tk_Window tkwin); /* 277 */
    void (*tk_SendVirtualEvent) (Tk_Window tkwin, const char *eventName, Tcl_Obj *detail); /* 278 */
    Tcl_Obj * (*tk_FontGetDescription) (Tk_Font tkfont); /* 279 */
    void (*tk_CreatePhotoImageFormatVersion3) (const Tk_PhotoImageFormatVersion3 *formatPtr); /* 280 */
    void (*tk_CreateOldPhotoImageFormat) (const Tk_PhotoImageFormat *formatPtr); /* 273 */
    void (*tk_DrawHighlightBorder) (Tk_Window tkwin, GC fgGC, GC bgGC, int highlightWidth, Drawable drawable); /* 281 */
    void (*tk_SetMainMenubar) (Tcl_Interp *interp, Tk_Window tkwin, const char *menuName); /* 282 */
    void (*tk_SetWindowMenubar) (Tcl_Interp *interp, Tk_Window tkwin, const char *oldMenuName, const char *menuName); /* 283 */
    void (*tk_ClipDrawableToRect) (Display *display, Drawable d, int x, int y, int width, int height); /* 284 */
    Tcl_Obj * (*tk_GetSystemDefault) (Tk_Window tkwin, const char *dbName, const char *className); /* 285 */
    int (*tk_UseWindow) (Tcl_Interp *interp, Tk_Window tkwin, const char *string); /* 286 */
    void (*tk_MakeContainer) (Tk_Window tkwin); /* 287 */
    Tk_Window (*tk_GetOtherWindow) (Tk_Window tkwin); /* 288 */
    void (*tk_Get3DBorderColors) (Tk_3DBorder border, XColor *bgColorPtr, XColor *darkColorPtr, XColor *lightColorPtr); /* 289 */
    Window (*tk_MakeWindow) (Tk_Window tkwin, Window parent); /* 290 */
} TkStubs;

extern const TkStubs *tkStubsPtr;

#ifdef __cplusplus
}
#endif
1354
1355
1356
1357
1358
1359
1360

1361

1362
1363
1364
1365
1366
1367
1368
1331
1332
1333
1334
1335
1336
1337
1338

1339
1340
1341
1342
1343
1344
1345
1346







+
-
+







	(tkStubsPtr->tk_FreeImage) /* 73 */
#define Tk_FreeOptions \
	(tkStubsPtr->tk_FreeOptions) /* 74 */
#define Tk_FreePixmap \
	(tkStubsPtr->tk_FreePixmap) /* 75 */
#define Tk_FreeTextLayout \
	(tkStubsPtr->tk_FreeTextLayout) /* 76 */
#define Tk_FreeXId \
/* Slot 77 is reserved */
	(tkStubsPtr->tk_FreeXId) /* 77 */
#define Tk_GCForColor \
	(tkStubsPtr->tk_GCForColor) /* 78 */
#define Tk_GeometryRequest \
	(tkStubsPtr->tk_GeometryRequest) /* 79 */
#define Tk_Get3DBorder \
	(tkStubsPtr->tk_Get3DBorder) /* 80 */
#define Tk_GetAllBindings \
1395
1396
1397
1398
1399
1400
1401
1402
1403


1404
1405
1406
1407
1408
1409
1410
1373
1374
1375
1376
1377
1378
1379


1380
1381
1382
1383
1384
1385
1386
1387
1388







-
-
+
+







	(tkStubsPtr->tk_GetFontFromObj) /* 94 */
#define Tk_GetFontMetrics \
	(tkStubsPtr->tk_GetFontMetrics) /* 95 */
#define Tk_GetGC \
	(tkStubsPtr->tk_GetGC) /* 96 */
#define Tk_GetImage \
	(tkStubsPtr->tk_GetImage) /* 97 */
#define Tk_GetImageModelData \
	(tkStubsPtr->tk_GetImageModelData) /* 98 */
#define Tk_GetImageMasterData \
	(tkStubsPtr->tk_GetImageMasterData) /* 98 */
#define Tk_GetItemTypes \
	(tkStubsPtr->tk_GetItemTypes) /* 99 */
#define Tk_GetJoinStyle \
	(tkStubsPtr->tk_GetJoinStyle) /* 100 */
#define Tk_GetJustify \
	(tkStubsPtr->tk_GetJustify) /* 101 */
#define Tk_GetNumMainWindows \
1435
1436
1437
1438
1439
1440
1441

1442

1443
1444
1445
1446
1447
1448
1449
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425
1426
1427
1428







+
-
+







	(tkStubsPtr->tk_Grab) /* 114 */
#define Tk_HandleEvent \
	(tkStubsPtr->tk_HandleEvent) /* 115 */
#define Tk_IdToWindow \
	(tkStubsPtr->tk_IdToWindow) /* 116 */
#define Tk_ImageChanged \
	(tkStubsPtr->tk_ImageChanged) /* 117 */
#define Tk_Init \
/* Slot 118 is reserved */
	(tkStubsPtr->tk_Init) /* 118 */
#define Tk_InternAtom \
	(tkStubsPtr->tk_InternAtom) /* 119 */
#define Tk_IntersectTextLayout \
	(tkStubsPtr->tk_IntersectTextLayout) /* 120 */
#define Tk_MaintainGeometry \
	(tkStubsPtr->tk_MaintainGeometry) /* 121 */
#define Tk_MainWindow \
1486
1487
1488
1489
1490
1491
1492

1493
1494



1495
1496
1497
1498

1499

1500
1501

1502

1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518

1519

1520
1521
1522
1523
1524
1525
1526
1465
1466
1467
1468
1469
1470
1471
1472


1473
1474
1475
1476
1477
1478
1479
1480

1481
1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502

1503
1504
1505
1506
1507
1508
1509
1510







+
-
-
+
+
+




+
-
+


+
-
+
















+
-
+







	(tkStubsPtr->tk_NameOfRelief) /* 140 */
#define Tk_NameToWindow \
	(tkStubsPtr->tk_NameToWindow) /* 141 */
#define Tk_OwnSelection \
	(tkStubsPtr->tk_OwnSelection) /* 142 */
#define Tk_ParseArgv \
	(tkStubsPtr->tk_ParseArgv) /* 143 */
#define Tk_PhotoPutBlock_NoComposite \
/* Slot 144 is reserved */
/* Slot 145 is reserved */
	(tkStubsPtr->tk_PhotoPutBlock_NoComposite) /* 144 */
#define Tk_PhotoPutZoomedBlock_NoComposite \
	(tkStubsPtr->tk_PhotoPutZoomedBlock_NoComposite) /* 145 */
#define Tk_PhotoGetImage \
	(tkStubsPtr->tk_PhotoGetImage) /* 146 */
#define Tk_PhotoBlank \
	(tkStubsPtr->tk_PhotoBlank) /* 147 */
#define Tk_PhotoExpand_Panic \
/* Slot 148 is reserved */
	(tkStubsPtr->tk_PhotoExpand_Panic) /* 148 */
#define Tk_PhotoGetSize \
	(tkStubsPtr->tk_PhotoGetSize) /* 149 */
#define Tk_PhotoSetSize_Panic \
/* Slot 150 is reserved */
	(tkStubsPtr->tk_PhotoSetSize_Panic) /* 150 */
#define Tk_PointToChar \
	(tkStubsPtr->tk_PointToChar) /* 151 */
#define Tk_PostscriptFontName \
	(tkStubsPtr->tk_PostscriptFontName) /* 152 */
#define Tk_PreserveColormap \
	(tkStubsPtr->tk_PreserveColormap) /* 153 */
#define Tk_QueueWindowEvent \
	(tkStubsPtr->tk_QueueWindowEvent) /* 154 */
#define Tk_RedrawImage \
	(tkStubsPtr->tk_RedrawImage) /* 155 */
#define Tk_ResizeWindow \
	(tkStubsPtr->tk_ResizeWindow) /* 156 */
#define Tk_RestackWindow \
	(tkStubsPtr->tk_RestackWindow) /* 157 */
#define Tk_RestrictEvents \
	(tkStubsPtr->tk_RestrictEvents) /* 158 */
#define Tk_SafeInit \
/* Slot 159 is reserved */
	(tkStubsPtr->tk_SafeInit) /* 159 */
#define Tk_SetAppName \
	(tkStubsPtr->tk_SetAppName) /* 160 */
#define Tk_SetBackgroundFromBorder \
	(tkStubsPtr->tk_SetBackgroundFromBorder) /* 161 */
#define Tk_SetClass \
	(tkStubsPtr->tk_SetClass) /* 162 */
#define Tk_SetGrid \
1617
1618
1619
1620
1621
1622
1623

1624

1625
1626
1627
1628
1629
1630

1631

1632
1633
1634
1635
1636
1637
1638
1601
1602
1603
1604
1605
1606
1607
1608

1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624







+
-
+






+
-
+







	(tkStubsPtr->tk_GetPixelsFromObj) /* 208 */
#define Tk_GetReliefFromObj \
	(tkStubsPtr->tk_GetReliefFromObj) /* 209 */
#define Tk_GetScrollInfoObj \
	(tkStubsPtr->tk_GetScrollInfoObj) /* 210 */
#define Tk_InitOptions \
	(tkStubsPtr->tk_InitOptions) /* 211 */
#define Tk_MainEx \
/* Slot 212 is reserved */
	(tkStubsPtr->tk_MainEx) /* 212 */
#define Tk_RestoreSavedOptions \
	(tkStubsPtr->tk_RestoreSavedOptions) /* 213 */
#define Tk_SetOptions \
	(tkStubsPtr->tk_SetOptions) /* 214 */
#define Tk_InitConsoleChannels \
	(tkStubsPtr->tk_InitConsoleChannels) /* 215 */
#define Tk_CreateConsoleWindow \
/* Slot 216 is reserved */
	(tkStubsPtr->tk_CreateConsoleWindow) /* 216 */
#define Tk_CreateSmoothMethod \
	(tkStubsPtr->tk_CreateSmoothMethod) /* 217 */
/* Slot 218 is reserved */
/* Slot 219 is reserved */
#define Tk_GetDash \
	(tkStubsPtr->tk_GetDash) /* 220 */
#define Tk_CreateOutline \
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
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







+
-
-
+
+
+




















+
-
-
+
+
+







	(tkStubsPtr->tk_SetClassProcs) /* 242 */
#define Tk_SetInternalBorderEx \
	(tkStubsPtr->tk_SetInternalBorderEx) /* 243 */
#define Tk_SetMinimumRequestSize \
	(tkStubsPtr->tk_SetMinimumRequestSize) /* 244 */
#define Tk_SetCaretPos \
	(tkStubsPtr->tk_SetCaretPos) /* 245 */
#define Tk_PhotoPutBlock_Panic \
/* Slot 246 is reserved */
/* Slot 247 is reserved */
	(tkStubsPtr->tk_PhotoPutBlock_Panic) /* 246 */
#define Tk_PhotoPutZoomedBlock_Panic \
	(tkStubsPtr->tk_PhotoPutZoomedBlock_Panic) /* 247 */
#define Tk_CollapseMotionEvents \
	(tkStubsPtr->tk_CollapseMotionEvents) /* 248 */
#define Tk_RegisterStyleEngine \
	(tkStubsPtr->tk_RegisterStyleEngine) /* 249 */
#define Tk_GetStyleEngine \
	(tkStubsPtr->tk_GetStyleEngine) /* 250 */
#define Tk_RegisterStyledElement \
	(tkStubsPtr->tk_RegisterStyledElement) /* 251 */
#define Tk_GetElementId \
	(tkStubsPtr->tk_GetElementId) /* 252 */
#define Tk_CreateStyle \
	(tkStubsPtr->tk_CreateStyle) /* 253 */
#define Tk_GetStyle \
	(tkStubsPtr->tk_GetStyle) /* 254 */
#define Tk_FreeStyle \
	(tkStubsPtr->tk_FreeStyle) /* 255 */
#define Tk_NameOfStyle \
	(tkStubsPtr->tk_NameOfStyle) /* 256 */
#define Tk_AllocStyleFromObj \
	(tkStubsPtr->tk_AllocStyleFromObj) /* 257 */
#define Tk_GetStyleFromObj \
/* Slot 258 is reserved */
/* Slot 259 is reserved */
	(tkStubsPtr->tk_GetStyleFromObj) /* 258 */
#define Tk_FreeStyleFromObj \
	(tkStubsPtr->tk_FreeStyleFromObj) /* 259 */
#define Tk_GetStyledElement \
	(tkStubsPtr->tk_GetStyledElement) /* 260 */
#define Tk_GetElementSize \
	(tkStubsPtr->tk_GetElementSize) /* 261 */
#define Tk_GetElementBox \
	(tkStubsPtr->tk_GetElementBox) /* 262 */
#define Tk_GetElementBorderWidth \
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-





+
-
+
+
+
+

-
-
-
+
+

-
-


-
+


-
+
-
-

-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+





	(tkStubsPtr->tk_PhotoSetSize) /* 268 */
#define Tk_GetUserInactiveTime \
	(tkStubsPtr->tk_GetUserInactiveTime) /* 269 */
#define Tk_ResetUserInactiveTime \
	(tkStubsPtr->tk_ResetUserInactiveTime) /* 270 */
#define Tk_Interp \
	(tkStubsPtr->tk_Interp) /* 271 */
/* Slot 272 is reserved */
/* Slot 273 is reserved */
#define Tk_AlwaysShowSelection \
	(tkStubsPtr->tk_AlwaysShowSelection) /* 274 */
#define Tk_GetButtonMask \
	(tkStubsPtr->tk_GetButtonMask) /* 275 */
#define Tk_GetDoublePixelsFromObj \
	(tkStubsPtr->tk_GetDoublePixelsFromObj) /* 276 */
#define Tk_NewWindowObj \
	(tkStubsPtr->tk_NewWindowObj) /* 277 */
#define Tk_SendVirtualEvent \
	(tkStubsPtr->tk_SendVirtualEvent) /* 278 */
#define Tk_FontGetDescription \
	(tkStubsPtr->tk_FontGetDescription) /* 279 */
#define Tk_CreatePhotoImageFormatVersion3 \
	(tkStubsPtr->tk_CreatePhotoImageFormatVersion3) /* 280 */
#define Tk_CreateOldImageType \
	(tkStubsPtr->tk_CreateOldImageType) /* 272 */
#define Tk_DrawHighlightBorder \
	(tkStubsPtr->tk_DrawHighlightBorder) /* 281 */
#define Tk_SetMainMenubar \
	(tkStubsPtr->tk_SetMainMenubar) /* 282 */
#define Tk_SetWindowMenubar \
	(tkStubsPtr->tk_SetWindowMenubar) /* 283 */
#define Tk_ClipDrawableToRect \
	(tkStubsPtr->tk_ClipDrawableToRect) /* 284 */
#define Tk_GetSystemDefault \
	(tkStubsPtr->tk_GetSystemDefault) /* 285 */
#define Tk_UseWindow \
	(tkStubsPtr->tk_UseWindow) /* 286 */
#define Tk_CreateOldPhotoImageFormat \
	(tkStubsPtr->tk_CreateOldPhotoImageFormat) /* 273 */
#define Tk_MakeContainer \
	(tkStubsPtr->tk_MakeContainer) /* 287 */
#define Tk_GetOtherWindow \
	(tkStubsPtr->tk_GetOtherWindow) /* 288 */
#define Tk_Get3DBorderColors \
	(tkStubsPtr->tk_Get3DBorderColors) /* 289 */
#define Tk_MakeWindow \
	(tkStubsPtr->tk_MakeWindow) /* 290 */

#endif /* defined(USE_TK_STUBS) */

/* !END!: Do not edit above this line. */

/* Functions that don't belong in the stub table */
#define Tk_GetImageMasterData Tk_GetImageModelData
#undef Tk_MainEx
#undef Tk_Init
#undef Tk_SafeInit
#undef Tk_CreateConsoleWindow

#ifndef MAC_OSX_TK
#   undef Tk_ClipDrawableToRect
#endif
#undef Tk_FreeXId
#define Tk_FreeXId(display,xid)

EXTERN void  Tk_MainEx(Tcl_Size argc, char **argv,
	Tcl_AppInitProc *appInitProc, Tcl_Interp *interp);
#if defined(_WIN32) && defined(UNICODE)
#   define Tk_MainEx Tk_MainExW
    EXTERN void Tk_MainExW(Tcl_Size argc, wchar_t **argv,
    EXTERN void Tk_MainExW(int argc, wchar_t **argv,
	    Tcl_AppInitProc *appInitProc, Tcl_Interp *interp);
#endif
EXTERN int Tk_Init(Tcl_Interp *interp);

EXTERN int Tk_SafeInit(Tcl_Interp *interp);
EXTERN int Tk_CreateConsoleWindow(Tcl_Interp *interp);

#if TK_MAJOR_VERSION < 9
/* Restore 8.x signature of Tk_ConfigureWidget, but panic if TK_CONFIG_OBJS flag is not set */
#undef Tk_ConfigureWidget
#define Tk_ConfigureWidget(interp, tkwin, specs, argc, argv, widgRec, flags) \
	((int (*)(Tcl_Interp *, Tk_Window, const Tk_ConfigSpec *, \
	int, const char **, char *, int))(void *)(tkStubsPtr->tk_ConfigureWidget)) \
#ifdef TK_NO_DEPRECATED
#undef Tk_PhotoPutBlock_NoComposite
#undef Tk_PhotoPutZoomedBlock_NoComposite
#undef Tk_PhotoExpand_Panic
#undef Tk_PhotoPutBlock_Panic
#undef Tk_PhotoPutZoomedBlock_Panic
#undef Tk_PhotoSetSize_Panic
	(((flags & TK_CONFIG_OBJS) ? interp : (Tcl_Panic("Flag TK_CONFIG_OBJS is mandatory in Tk_ConfigureWidget"), \
	NULL)), tkwin, specs, argc, argv, widgRec, flags)
#endif
#endif /* TK_NO_DEPRECATED */

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

#endif /* _TKDECLS */

Changes to generic/tkEntry.c.

1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8




9
10
11
12
13
14
15
16
17
18

19



20

21
22
23
24
25
26
27








-
-
-
-
+
+
+
+






-

-
-
-
+
-







/*
 * tkEntry.c --
 *
 *	This module implements entry and spinbox widgets for the Tk toolkit.
 *	An entry displays a string and allows the string to be edited. A
 *	spinbox expands on the entry by adding up/down buttons that control
 *	the value of the entry widget.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2000 Ajuba Solutions.
 * Copyright © 2002 ActiveState Corporation.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Ajuba Solutions.
 * Copyright (c) 2002 ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkEntry.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#include "tkEntry.h"
#endif

/*
 * The following macro defines how many extra pixels to leave on each side of
 * the text in the entry.
 */

#define XPAD 1
63
64
65
66
67
68
69
70

71
72
73

74
75

76
77

78
79

80
81
82
83
84



85
86
87


88
89
90


91
92

93
94

95
96

97
98
99

100
101

102
103
104


105
106

107
108
109
110



111
112

113
114
115

116
117

118
119

120
121
122

123
124

125
126
127
128
129
130
131
132
133
134



135
136

137
138

139
140
141
142


143
144
145

146
147
148

149
150
151

152
153
154

155
156
157

158
159
160

161
162
163

164
165

166
167

168
169

170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185



186
187
188
189
190
191
192
193

194
195
196

197
198
199

200
201

202
203
204
205



206
207
208


209
210
211
212
213




214
215

216
217
218

219
220
221
222
223



224
225
226


227
228
229


230
231

232
233

234
235

236
237

238
239
240

241
242
243

244
245

246
247
248


249
250

251
252

253
254
255
256



257
258

259
260
261

262
263

264
265

266
267
268

269
270

271
272
273
274
275
276
277
278

279
280
281
282



283
284

285
286
287

288
289
290

291
292
293
294


295
296
297

298
299
300

301
302
303

304
305
306

307
308
309

310
311

312
313
314

315
316

317
318
319

320
321

322
323

324
325

326
327

328
329
330
331
332
333
334
59
60
61
62
63
64
65

66
67
68

69
70

71
72

73
74

75
76
77



78
79
80
81


82
83
84


85
86
87

88
89

90
91

92
93
94

95
96

97
98


99
100
101

102
103



104
105
106
107

108
109
110

111
112

113
114

115
116
117

118
119

120






121



122
123
124
125

126
127

128
129
130


131
132
133
134

135
136
137

138
139
140

141
142
143

144
145
146

147
148
149

150
151
152

153
154

155
156

157
158

159
160

161
162
163
164
165
166
167
168
169
170
171
172



173
174
175
176
177
178
179
180
181
182

183
184
185

186
187
188

189
190

191
192



193
194
195
196


197
198
199




200
201
202
203
204

205
206
207

208
209
210



211
212
213
214


215
216
217


218
219
220

221
222

223
224

225
226

227
228
229

230
231
232

233
234

235
236


237
238
239

240
241

242
243



244
245
246
247

248
249
250

251
252

253
254

255
256
257

258
259

260






261

262
263



264
265
266
267

268
269
270

271
272
273

274
275
276


277
278
279
280

281
282
283

284
285
286

287
288
289

290
291
292

293
294

295
296
297

298
299

300
301
302

303
304

305
306

307
308

309
310

311
312
313
314
315
316
317
318







-
+


-
+

-
+

-
+

-
+


-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
+

-
+

-
+


-
+

-
+

-
-
+
+

-
+

-
-
-
+
+
+

-
+


-
+

-
+

-
+


-
+

-
+
-
-
-
-
-
-

-
-
-
+
+
+

-
+

-
+


-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+

-
+

-
+

-
+

-
+











-
-
-
+
+
+







-
+


-
+


-
+

-
+

-
-
-
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
+


-
+


-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
+

-
+

-
+

-
+


-
+


-
+

-
+

-
-
+
+

-
+

-
+

-
-
-
+
+
+

-
+


-
+

-
+

-
+


-
+

-
+
-
-
-
-
-
-

-
+

-
-
-
+
+
+

-
+


-
+


-
+


-
-
+
+


-
+


-
+


-
+


-
+


-
+

-
+


-
+

-
+


-
+

-
+

-
+

-
+

-
+








/*
 * Information used for Entry objv parsing.
 */

static const Tk_OptionSpec entryOptSpec[] = {
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_ENTRY_BG_COLOR, TCL_INDEX_NONE, offsetof(Entry, normalBorder),
	DEF_ENTRY_BG_COLOR, -1, Tk_Offset(Entry, normalBorder),
	0, DEF_ENTRY_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_ENTRY_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Entry, borderWidth), 0, 0, 0},
	DEF_ENTRY_BORDER_WIDTH, -1, Tk_Offset(Entry, borderWidth), 0, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_ENTRY_CURSOR, TCL_INDEX_NONE, offsetof(Entry, cursor),
	DEF_ENTRY_CURSOR, -1, Tk_Offset(Entry, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BORDER, "-disabledbackground", "disabledBackground",
	"DisabledBackground", DEF_ENTRY_DISABLED_BG_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, disabledBorder), TK_OPTION_NULL_OK,
	DEF_ENTRY_DISABLED_BG_MONO, 0},
	"DisabledBackground", DEF_ENTRY_DISABLED_BG_COLOR, -1,
	Tk_Offset(Entry, disabledBorder), TK_OPTION_NULL_OK,
	(ClientData) DEF_ENTRY_DISABLED_BG_MONO, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_ENTRY_DISABLED_FG, TCL_INDEX_NONE,
	offsetof(Entry, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
	"DisabledForeground", DEF_ENTRY_DISABLED_FG, -1,
	Tk_Offset(Entry, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
	"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, TCL_INDEX_NONE,
	offsetof(Entry, exportSelection), 0, 0, 0},
	"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, -1,
	Tk_Offset(Entry, exportSelection), 0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_ENTRY_FONT, TCL_INDEX_NONE, offsetof(Entry, tkfont), 0, 0, 0},
	DEF_ENTRY_FONT, -1, Tk_Offset(Entry, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_ENTRY_FG, TCL_INDEX_NONE, offsetof(Entry, fgColorPtr), 0, 0, 0},
	DEF_ENTRY_FG, -1, Tk_Offset(Entry, fgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_ENTRY_HIGHLIGHT_BG,
	TCL_INDEX_NONE, offsetof(Entry, highlightBgColorPtr), 0, 0, 0},
	-1, Tk_Offset(Entry, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_ENTRY_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Entry, highlightColorPtr), 0, 0, 0},
	DEF_ENTRY_HIGHLIGHT, -1, Tk_Offset(Entry, highlightColorPtr), 0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	offsetof(Entry, highlightWidth), 0, 0, 0},
	"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, -1,
	Tk_Offset(Entry, highlightWidth), 0, 0, 0},
    {TK_OPTION_BORDER, "-insertbackground", "insertBackground", "Foreground",
	DEF_ENTRY_INSERT_BG, TCL_INDEX_NONE, offsetof(Entry, insertBorder), 0, 0, 0},
	DEF_ENTRY_INSERT_BG, -1, Tk_Offset(Entry, insertBorder), 0, 0, 0},
    {TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth",
	"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, insertBorderWidth), 0,
	DEF_ENTRY_INSERT_BD_MONO, 0},
	"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, -1,
	Tk_Offset(Entry, insertBorderWidth), 0,
	(ClientData) DEF_ENTRY_INSERT_BD_MONO, 0},
    {TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime",
	DEF_ENTRY_INSERT_OFF_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOffTime),
	DEF_ENTRY_INSERT_OFF_TIME, -1, Tk_Offset(Entry, insertOffTime),
	0, 0, 0},
    {TK_OPTION_INT, "-insertontime", "insertOnTime", "OnTime",
	DEF_ENTRY_INSERT_ON_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOnTime), 0, 0, 0},
	DEF_ENTRY_INSERT_ON_TIME, -1, Tk_Offset(Entry, insertOnTime), 0, 0, 0},
    {TK_OPTION_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
	DEF_ENTRY_INSERT_WIDTH, TCL_INDEX_NONE, offsetof(Entry, insertWidth), 0, 0, 0},
	DEF_ENTRY_INSERT_WIDTH, -1, Tk_Offset(Entry, insertWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
	DEF_ENTRY_INVALIDCMD, TCL_INDEX_NONE, offsetof(Entry, invalidCmd),
	DEF_ENTRY_INVALIDCMD, -1, Tk_Offset(Entry, invalidCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-invcmd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-invalidcommand", 0},
	NULL, 0, -1, 0, "-invalidcommand", 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_ENTRY_JUSTIFY, TCL_INDEX_NONE, offsetof(Entry, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_ENTRY_JUSTIFY, -1, Tk_Offset(Entry, justify), 0, 0, 0},
    {TK_OPTION_STRING, "-placeholder", "placeHolder", "PlaceHolder",
	DEF_ENTRY_PLACEHOLDER, TCL_INDEX_NONE, offsetof(Entry, placeholderString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground",
	"PlaceholderForeground", DEF_ENTRY_PLACEHOLDERFG, TCL_INDEX_NONE,
	offsetof(Entry, placeholderColorPtr), 0, 0, 0},
    {TK_OPTION_BORDER, "-readonlybackground", "readonlyBackground",
	"ReadonlyBackground", DEF_ENTRY_READONLY_BG_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, readonlyBorder), TK_OPTION_NULL_OK,
	DEF_ENTRY_READONLY_BG_MONO, 0},
	"ReadonlyBackground", DEF_ENTRY_READONLY_BG_COLOR, -1,
	Tk_Offset(Entry, readonlyBorder), TK_OPTION_NULL_OK,
	(ClientData) DEF_ENTRY_READONLY_BG_MONO, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_ENTRY_RELIEF, TCL_INDEX_NONE, offsetof(Entry, relief), 0, 0, 0},
	DEF_ENTRY_RELIEF, -1, Tk_Offset(Entry, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_ENTRY_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Entry, selBorder),
	DEF_ENTRY_SELECT_COLOR, -1, Tk_Offset(Entry, selBorder),
	0, DEF_ENTRY_SELECT_MONO, 0},
    {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
	"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, selBorderWidth),
	"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, -1,
	Tk_Offset(Entry, selBorderWidth),
	0, DEF_ENTRY_SELECT_BD_MONO, 0},
    {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
	DEF_ENTRY_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Entry, selFgColorPtr),
	DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
	TK_OPTION_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0},
    {TK_OPTION_STRING, "-show", "show", "Show",
	DEF_ENTRY_SHOW, TCL_INDEX_NONE, offsetof(Entry, showChar),
	DEF_ENTRY_SHOW, -1, Tk_Offset(Entry, showChar),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_ENTRY_STATE, TCL_INDEX_NONE, offsetof(Entry, state),
	DEF_ENTRY_STATE, -1, Tk_Offset(Entry, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_ENTRY_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(Entry, takeFocus),
	DEF_ENTRY_TAKE_FOCUS, -1, Tk_Offset(Entry, takeFocus),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_ENTRY_TEXT_VARIABLE, TCL_INDEX_NONE, offsetof(Entry, textVarName),
	DEF_ENTRY_TEXT_VARIABLE, -1, Tk_Offset(Entry, textVarName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate",
	DEF_ENTRY_VALIDATE, TCL_INDEX_NONE, offsetof(Entry, validate),
	DEF_ENTRY_VALIDATE, -1, Tk_Offset(Entry, validate),
	0, validateStrings, 0},
    {TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand",
	NULL, TCL_INDEX_NONE, offsetof(Entry, validateCmd), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(Entry, validateCmd), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-vcmd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-validatecommand", 0},
	NULL, 0, -1, 0, "-validatecommand", 0},
    {TK_OPTION_INT, "-width", "width", "Width",
	DEF_ENTRY_WIDTH, TCL_INDEX_NONE, offsetof(Entry, prefWidth), 0, 0, 0},
	DEF_ENTRY_WIDTH, -1, Tk_Offset(Entry, prefWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	DEF_ENTRY_SCROLL_COMMAND, TCL_INDEX_NONE, offsetof(Entry, scrollCmd),
	DEF_ENTRY_SCROLL_COMMAND, -1, Tk_Offset(Entry, scrollCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * Information used for Spinbox objv parsing.
 */

#define DEF_SPINBOX_REPEAT_DELAY	"400"
#define DEF_SPINBOX_REPEAT_INTERVAL	"100"

#define DEF_SPINBOX_CMD			""

#define DEF_SPINBOX_FROM		"0.0"
#define DEF_SPINBOX_TO			"0.0"
#define DEF_SPINBOX_INCREMENT		"1.0"
#define DEF_SPINBOX_FROM		"0"
#define DEF_SPINBOX_TO			"0"
#define DEF_SPINBOX_INCREMENT		"1"
#define DEF_SPINBOX_FORMAT		""

#define DEF_SPINBOX_VALUES		""
#define DEF_SPINBOX_WRAP		"0"

static const Tk_OptionSpec sbOptSpec[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Background",
	DEF_BUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(Spinbox, activeBorder),
	DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(Spinbox, activeBorder),
	0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_ENTRY_BG_COLOR, TCL_INDEX_NONE, offsetof(Entry, normalBorder),
	DEF_ENTRY_BG_COLOR, -1, Tk_Offset(Entry, normalBorder),
	0, DEF_ENTRY_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_ENTRY_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Entry, borderWidth), 0, 0, 0},
    {TK_OPTION_BORDER, "-buttonbackground", "buttonBackground", "Background",
	DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(Spinbox, buttonBorder),
	DEF_ENTRY_BORDER_WIDTH, -1, Tk_Offset(Entry, borderWidth), 0, 0, 0},
    {TK_OPTION_BORDER, "-buttonbackground", "Button.background", "Background",
	DEF_BUTTON_BG_COLOR, -1, Tk_Offset(Spinbox, buttonBorder),
	0, DEF_BUTTON_BG_MONO, 0},
    {TK_OPTION_CURSOR, "-buttoncursor", "buttonCursor", "Cursor",
	DEF_BUTTON_CURSOR, TCL_INDEX_NONE, offsetof(Spinbox, bCursor),
    {TK_OPTION_CURSOR, "-buttoncursor", "Button.cursor", "Cursor",
	DEF_BUTTON_CURSOR, -1, Tk_Offset(Spinbox, bCursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_RELIEF, "-buttondownrelief", "buttonDownRelief", "Relief",
	DEF_BUTTON_RELIEF, TCL_INDEX_NONE, offsetof(Spinbox, bdRelief), 0, 0, 0},
    {TK_OPTION_RELIEF, "-buttonuprelief", "buttonUpRelief", "Relief",
	DEF_BUTTON_RELIEF, TCL_INDEX_NONE, offsetof(Spinbox, buRelief), 0, 0, 0},
    {TK_OPTION_RELIEF, "-buttondownrelief", "Button.relief", "Relief",
	DEF_BUTTON_RELIEF, -1, Tk_Offset(Spinbox, bdRelief), 0, 0, 0},
    {TK_OPTION_RELIEF, "-buttonuprelief", "Button.relief", "Relief",
	DEF_BUTTON_RELIEF, -1, Tk_Offset(Spinbox, buRelief), 0, 0, 0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	DEF_SPINBOX_CMD, TCL_INDEX_NONE, offsetof(Spinbox, command),
	DEF_SPINBOX_CMD, -1, Tk_Offset(Spinbox, command),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_ENTRY_CURSOR, TCL_INDEX_NONE, offsetof(Entry, cursor),
	DEF_ENTRY_CURSOR, -1, Tk_Offset(Entry, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BORDER, "-disabledbackground", "disabledBackground",
	"DisabledBackground", DEF_ENTRY_DISABLED_BG_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, disabledBorder), TK_OPTION_NULL_OK,
	DEF_ENTRY_DISABLED_BG_MONO, 0},
	"DisabledBackground", DEF_ENTRY_DISABLED_BG_COLOR, -1,
	Tk_Offset(Entry, disabledBorder), TK_OPTION_NULL_OK,
	(ClientData) DEF_ENTRY_DISABLED_BG_MONO, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_ENTRY_DISABLED_FG, TCL_INDEX_NONE,
	offsetof(Entry, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
	"DisabledForeground", DEF_ENTRY_DISABLED_FG, -1,
	Tk_Offset(Entry, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
	"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, TCL_INDEX_NONE,
	offsetof(Entry, exportSelection), 0, 0, 0},
	"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, -1,
	Tk_Offset(Entry, exportSelection), 0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_ENTRY_FONT, TCL_INDEX_NONE, offsetof(Entry, tkfont), 0, 0, 0},
	DEF_ENTRY_FONT, -1, Tk_Offset(Entry, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_ENTRY_FG, TCL_INDEX_NONE, offsetof(Entry, fgColorPtr), 0, 0, 0},
	DEF_ENTRY_FG, -1, Tk_Offset(Entry, fgColorPtr), 0, 0, 0},
    {TK_OPTION_STRING, "-format", "format", "Format",
	DEF_SPINBOX_FORMAT, TCL_INDEX_NONE, offsetof(Spinbox, reqFormat),
	DEF_SPINBOX_FORMAT, -1, Tk_Offset(Spinbox, reqFormat),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_DOUBLE, "-from", "from", "From",
	DEF_SPINBOX_FROM, TCL_INDEX_NONE, offsetof(Spinbox, fromValue), 0, 0, 0},
	DEF_SPINBOX_FROM, -1, Tk_Offset(Spinbox, fromValue), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_ENTRY_HIGHLIGHT_BG,
	TCL_INDEX_NONE, offsetof(Entry, highlightBgColorPtr), 0, 0, 0},
	-1, Tk_Offset(Entry, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_ENTRY_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Entry, highlightColorPtr), 0, 0, 0},
	DEF_ENTRY_HIGHLIGHT, -1, Tk_Offset(Entry, highlightColorPtr), 0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	offsetof(Entry, highlightWidth), 0, 0, 0},
	"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, -1,
	Tk_Offset(Entry, highlightWidth), 0, 0, 0},
    {TK_OPTION_DOUBLE, "-increment", "increment", "Increment",
	DEF_SPINBOX_INCREMENT, TCL_INDEX_NONE, offsetof(Spinbox, increment), 0, 0, 0},
	DEF_SPINBOX_INCREMENT, -1, Tk_Offset(Spinbox, increment), 0, 0, 0},
    {TK_OPTION_BORDER, "-insertbackground", "insertBackground", "Foreground",
	DEF_ENTRY_INSERT_BG, TCL_INDEX_NONE, offsetof(Entry, insertBorder), 0, 0, 0},
	DEF_ENTRY_INSERT_BG, -1, Tk_Offset(Entry, insertBorder), 0, 0, 0},
    {TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth",
	"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, insertBorderWidth), 0,
	DEF_ENTRY_INSERT_BD_MONO, 0},
	"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, -1,
	Tk_Offset(Entry, insertBorderWidth), 0,
	(ClientData) DEF_ENTRY_INSERT_BD_MONO, 0},
    {TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime",
	DEF_ENTRY_INSERT_OFF_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOffTime),
	DEF_ENTRY_INSERT_OFF_TIME, -1, Tk_Offset(Entry, insertOffTime),
	0, 0, 0},
    {TK_OPTION_INT, "-insertontime", "insertOnTime", "OnTime",
	DEF_ENTRY_INSERT_ON_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOnTime), 0, 0, 0},
	DEF_ENTRY_INSERT_ON_TIME, -1, Tk_Offset(Entry, insertOnTime), 0, 0, 0},
    {TK_OPTION_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
	DEF_ENTRY_INSERT_WIDTH, TCL_INDEX_NONE, offsetof(Entry, insertWidth), 0, 0, 0},
	DEF_ENTRY_INSERT_WIDTH, -1, Tk_Offset(Entry, insertWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
	DEF_ENTRY_INVALIDCMD, TCL_INDEX_NONE, offsetof(Entry, invalidCmd),
	DEF_ENTRY_INVALIDCMD, -1, Tk_Offset(Entry, invalidCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-invcmd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-invalidcommand", 0},
	NULL, 0, -1, 0, "-invalidcommand", 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_ENTRY_JUSTIFY, TCL_INDEX_NONE, offsetof(Entry, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_ENTRY_JUSTIFY, -1, Tk_Offset(Entry, justify), 0, 0, 0},
    {TK_OPTION_STRING, "-placeholder", "placeHolder", "PlaceHolder",
	DEF_ENTRY_PLACEHOLDER, TCL_INDEX_NONE, offsetof(Entry, placeholderString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground",
        "PlaceholderForeground", DEF_ENTRY_PLACEHOLDERFG, TCL_INDEX_NONE,
        offsetof(Entry, placeholderColorPtr), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_ENTRY_RELIEF, TCL_INDEX_NONE, offsetof(Entry, relief), 0, 0, 0},
	DEF_ENTRY_RELIEF, -1, Tk_Offset(Entry, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-readonlybackground", "readonlyBackground",
	"ReadonlyBackground", DEF_ENTRY_READONLY_BG_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, readonlyBorder), TK_OPTION_NULL_OK,
	DEF_ENTRY_READONLY_BG_MONO, 0},
	"ReadonlyBackground", DEF_ENTRY_READONLY_BG_COLOR, -1,
	Tk_Offset(Entry, readonlyBorder), TK_OPTION_NULL_OK,
	(ClientData) DEF_ENTRY_READONLY_BG_MONO, 0},
    {TK_OPTION_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
	DEF_SPINBOX_REPEAT_DELAY, TCL_INDEX_NONE, offsetof(Spinbox, repeatDelay),
	DEF_SPINBOX_REPEAT_DELAY, -1, Tk_Offset(Spinbox, repeatDelay),
	0, 0, 0},
    {TK_OPTION_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
	DEF_SPINBOX_REPEAT_INTERVAL, TCL_INDEX_NONE, offsetof(Spinbox, repeatInterval),
	DEF_SPINBOX_REPEAT_INTERVAL, -1, Tk_Offset(Spinbox, repeatInterval),
	0, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_ENTRY_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Entry, selBorder),
	DEF_ENTRY_SELECT_COLOR, -1, Tk_Offset(Entry, selBorder),
	0, DEF_ENTRY_SELECT_MONO, 0},
    {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
	"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE,
	offsetof(Entry, selBorderWidth),
	"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, -1,
	Tk_Offset(Entry, selBorderWidth),
	0, DEF_ENTRY_SELECT_BD_MONO, 0},
    {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
	DEF_ENTRY_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Entry, selFgColorPtr),
	DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
	TK_OPTION_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_ENTRY_STATE, TCL_INDEX_NONE, offsetof(Entry, state),
	DEF_ENTRY_STATE, -1, Tk_Offset(Entry, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_ENTRY_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(Entry, takeFocus),
	DEF_ENTRY_TAKE_FOCUS, -1, Tk_Offset(Entry, takeFocus),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_ENTRY_TEXT_VARIABLE, TCL_INDEX_NONE, offsetof(Entry, textVarName),
	DEF_ENTRY_TEXT_VARIABLE, -1, Tk_Offset(Entry, textVarName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_DOUBLE, "-to", "to", "To",
	DEF_SPINBOX_TO, TCL_INDEX_NONE, offsetof(Spinbox, toValue), 0, 0, 0},
	DEF_SPINBOX_TO, -1, Tk_Offset(Spinbox, toValue), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate",
	DEF_ENTRY_VALIDATE, TCL_INDEX_NONE, offsetof(Entry, validate),
	DEF_ENTRY_VALIDATE, -1, Tk_Offset(Entry, validate),
	0, validateStrings, 0},
    {TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand",
	NULL, TCL_INDEX_NONE, offsetof(Entry, validateCmd), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(Entry, validateCmd), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-values", "values", "Values",
	DEF_SPINBOX_VALUES, TCL_INDEX_NONE, offsetof(Spinbox, valueStr),
	DEF_SPINBOX_VALUES, -1, Tk_Offset(Spinbox, valueStr),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-vcmd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-validatecommand", 0},
	NULL, 0, -1, 0, "-validatecommand", 0},
    {TK_OPTION_INT, "-width", "width", "Width",
	DEF_ENTRY_WIDTH, TCL_INDEX_NONE, offsetof(Entry, prefWidth), 0, 0, 0},
	DEF_ENTRY_WIDTH, -1, Tk_Offset(Entry, prefWidth), 0, 0, 0},
    {TK_OPTION_BOOLEAN, "-wrap", "wrap", "Wrap",
	DEF_SPINBOX_WRAP, TCL_INDEX_NONE, offsetof(Spinbox, wrap), 0, 0, 0},
	DEF_SPINBOX_WRAP, -1, Tk_Offset(Spinbox, wrap), 0, 0, 0},
    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	DEF_ENTRY_SCROLL_COMMAND, TCL_INDEX_NONE, offsetof(Entry, scrollCmd),
	DEF_ENTRY_SCROLL_COMMAND, -1, Tk_Offset(Entry, scrollCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * The following tables define the entry widget commands (and sub-commands)
 * and map the indexes into the string tables into enumerated types used to
 * dispatch the entry widget command.
 */
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414






415
416

417
418
419
420
421



422
423
424
425
426


427
428
429
430
431
432

433
434

435
436
437
438
439
440
441




442
443
444


445
446
447
448
449
450



451
452
453
454
455
456
457
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392






393
394
395
396
397
398
399

400
401
402



403
404
405
406
407
408


409
410
411
412
413
414
415

416
417

418
419
420
421
422
423


424
425
426
427
428


429
430
431
432
433
434
435

436
437
438
439
440
441
442
443
444
445







-
+














-
-
-
-
-
-
+
+
+
+
+
+

-
+


-
-
-
+
+
+



-
-
+
+





-
+

-
+





-
-
+
+
+
+

-
-
+
+





-
+
+
+








/*
 * This is the string array corresponding to the enum in selelement. If you
 * modify them, you must modify the strings here.
 */

static const char *const selElementNames[] = {
    "buttondown", "buttonup", "none", NULL, "entry"
    "none", "buttondown", "buttonup", NULL, "entry"
};

/*
 * Flags for GetEntryIndex function:
 */

#define ZERO_OK			1
#define LAST_PLUS_ONE_OK	2

/*
 * Forward declarations for functions defined later in this file:
 */

static int		ConfigureEntry(Tcl_Interp *interp, Entry *entryPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static int		DeleteChars(Entry *entryPtr, Tcl_Size index, Tcl_Size count);
static Tcl_FreeProc	DestroyEntry;
static void		DisplayEntry(void *clientData);
static void		EntryBlinkProc(void *clientData);
static void		EntryCmdDeletedProc(void *clientData);
			    int objc, Tcl_Obj *const objv[]);
static int		DeleteChars(Entry *entryPtr, int index, int count);
static void		DestroyEntry(void *memPtr);
static void		DisplayEntry(ClientData clientData);
static void		EntryBlinkProc(ClientData clientData);
static void		EntryCmdDeletedProc(ClientData clientData);
static void		EntryComputeGeometry(Entry *entryPtr);
static void		EntryEventProc(void *clientData,
static void		EntryEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EntryFocusProc(Entry *entryPtr, int gotFocus);
static Tcl_Size	EntryFetchSelection(void *clientData, Tcl_Size offset,
			    char *buffer, Tcl_Size maxBytes);
static void		EntryLostSelection(void *clientData);
static int		EntryFetchSelection(ClientData clientData, int offset,
			    char *buffer, int maxBytes);
static void		EntryLostSelection(ClientData clientData);
static void		EventuallyRedraw(Entry *entryPtr);
static void		EntryScanTo(Entry *entryPtr, int y);
static void		EntrySetValue(Entry *entryPtr, const char *value);
static void		EntrySelectTo(Entry *entryPtr, Tcl_Size index);
static char *		EntryTextVarProc(void *clientData,
static void		EntrySelectTo(Entry *entryPtr, int index);
static char *		EntryTextVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static void		EntryUpdateScrollbar(Entry *entryPtr);
static int		EntryValidate(Entry *entryPtr, char *cmd);
static int		EntryValidateChange(Entry *entryPtr, const char *change,
			    const char *newStr, Tcl_Size index, int type);
			    const char *newStr, int index, int type);
static void		ExpandPercents(Entry *entryPtr, const char *before,
			    const char *change, const char *newStr, Tcl_Size index,
			    const char *change, const char *newStr, int index,
			    int type, Tcl_DString *dsPtr);
static int		EntryValueChanged(Entry *entryPtr,
			    const char *newValue);
static void		EntryVisibleRange(Entry *entryPtr,
			    double *firstPtr, double *lastPtr);
static Tcl_ObjCmdProc EntryWidgetObjCmd;
static void		EntryWorldChanged(void *instanceData);
static int		EntryWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		EntryWorldChanged(ClientData instanceData);
static int		GetEntryIndex(Tcl_Interp *interp, Entry *entryPtr,
			    Tcl_Obj *indexObj, Tcl_Size *indexPtr);
static int		InsertChars(Entry *entryPtr, Tcl_Size index, const char *string);
			    const char *string, int *indexPtr);
static int		InsertChars(Entry *entryPtr, int index, const char *string);

/*
 * These forward declarations are the spinbox specific ones:
 */

static Tcl_ObjCmdProc SpinboxWidgetObjCmd;
static int		SpinboxWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GetSpinboxElement(Spinbox *sbPtr, int x, int y);
static int		SpinboxInvoke(Tcl_Interp *interp, Spinbox *sbPtr,
			    int element);
static int		ComputeFormat(Spinbox *sbPtr);

/*
 * The structure below defines widget class behavior by means of functions
480
481
482
483
484
485
486
487

488
489
490
491
492

493
494
495
496
497
498
499
468
469
470
471
472
473
474

475
476
477
478
479

480
481
482
483
484
485
486
487







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_EntryObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Entry *entryPtr;
    register Entry *entryPtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;
    char *tmp;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530
531
532
533

534
535
536
537


538
539

540
541
542
543
544
545
546
547
548



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576

577
578
579
580
581
582
583
503
504
505
506
507
508
509

510
511
512
513
514
515
516
517
518
519
520

521
522
523


524
525
526

527
528
529
530
531
532
533



534
535
536
537
538
539


540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561

562
563
564
565
566
567
568
569







-
+










-
+


-
-
+
+

-
+






-
-
-
+
+
+



-
-















-
+






-
+







    /*
     * Initialize the fields of the structure that won't be initialized by
     * ConfigureEntry, or that ConfigureEntry requires to be initialized
     * already (e.g. resource pointers). Only the non-NULL/0 data must be
     * initialized as memset covers the rest.
     */

    entryPtr = (Entry *)ckalloc(sizeof(Entry));
    entryPtr = ckalloc(sizeof(Entry));
    memset(entryPtr, 0, sizeof(Entry));

    entryPtr->tkwin		= tkwin;
    entryPtr->display		= Tk_Display(tkwin);
    entryPtr->interp		= interp;
    entryPtr->widgetCmd		= Tcl_CreateObjCommand(interp,
	    Tk_PathName(entryPtr->tkwin), EntryWidgetObjCmd, entryPtr,
	    EntryCmdDeletedProc);
    entryPtr->optionTable	= optionTable;
    entryPtr->type		= TK_ENTRY;
    tmp				= (char *)ckalloc(1);
    tmp				= ckalloc(1);
    tmp[0]			= '\0';
    entryPtr->string		= tmp;
    entryPtr->selectFirst	= TCL_INDEX_NONE;
    entryPtr->selectLast	= TCL_INDEX_NONE;
    entryPtr->selectFirst	= -1;
    entryPtr->selectLast	= -1;

    entryPtr->cursor		= NULL;
    entryPtr->cursor		= None;
    entryPtr->exportSelection	= 1;
    entryPtr->justify		= TK_JUSTIFY_LEFT;
    entryPtr->relief		= TK_RELIEF_FLAT;
    entryPtr->state		= STATE_NORMAL;
    entryPtr->displayString	= entryPtr->string;
    entryPtr->inset		= XPAD;
    entryPtr->textGC		= NULL;
    entryPtr->selTextGC		= NULL;
    entryPtr->highlightGC	= NULL;
    entryPtr->textGC		= None;
    entryPtr->selTextGC		= None;
    entryPtr->highlightGC	= None;
    entryPtr->avgWidth		= 1;
    entryPtr->validate		= VALIDATE_NONE;

    entryPtr->placeholderGC	= NULL;

    /*
     * Keep a hold of the associated tkwin until we destroy the entry,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(entryPtr->tkwin);

    Tk_SetClass(entryPtr->tkwin, "Entry");
    Tk_SetClassProcs(entryPtr->tkwin, &entryClass, entryPtr);
    Tk_CreateEventHandler(entryPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    EntryEventProc, entryPtr);
    Tk_CreateSelHandler(entryPtr->tkwin, XA_PRIMARY, XA_STRING,
	    EntryFetchSelection, entryPtr, XA_STRING);

    if ((Tk_InitOptions(interp, entryPtr, optionTable, tkwin)
    if ((Tk_InitOptions(interp, (char *) entryPtr, optionTable, tkwin)
	    != TCL_OK) ||
	    (ConfigureEntry(interp, entryPtr, objc-2, objv+2) != TCL_OK)) {
	Tk_DestroyWindow(entryPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(entryPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(entryPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * EntryWidgetObjCmd --
593
594
595
596
597
598
599
600

601
602
603
604
605

606
607
608
609
610
611
612
579
580
581
582
583
584
585

586
587
588
589
590

591
592
593
594
595
596
597
598







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
EntryWidgetObjCmd(
    void *clientData,	/* Information about entry widget. */
    ClientData clientData,	/* Information about entry widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;
    int cmdIndex, selIndex, result;
    Tcl_Obj *objPtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
621
622
623
624
625
626
627
628
629

630
631
632
633
634
635
636

637
638
639
640

641
642
643
644
645
646
647




648
649
650
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689

690
691
692
693
694
695

696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
729

730
731
732
733
734
735

736
737
738
739

740
741
742
743
744

745
746
747
748
749
750
751

752
753
754
755
756
757
758
607
608
609
610
611
612
613


614
615
616
617
618
619
620

621
622
623
624

625
626
627
628




629
630
631
632
633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666

667

668
669
670
671
672

673
674
675
676
677
678

679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712

713
714
715
716
717
718

719
720
721
722

723
724
725
726
727

728

729
730
731
732
733

734
735
736
737
738
739
740
741







-
-
+






-
+



-
+



-
-
-
-
+
+
+
+










-
+









-
+













-
+
-





-
+





-
+

















-
+







-
+







-
+





-
+



-
+




-
+
-





-
+







    if (result != TCL_OK) {
	return result;
    }

    Tcl_Preserve(entryPtr);
    switch ((enum entryCmd) cmdIndex) {
    case COMMAND_BBOX: {
	Tcl_Size index;
	int x, y, width, height;
	int index, x, y, width, height;
	Tcl_Obj *bbox[4];

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	if ((index == entryPtr->numChars) && (index + 1 > 1)) {
	if ((index == entryPtr->numChars) && (index > 0)) {
	    index--;
	}
	Tk_CharBbox(entryPtr->textLayout, index, &x, &y, &width, &height);
	bbox[0] = Tcl_NewWideIntObj(x + entryPtr->layoutX);
	bbox[1] = Tcl_NewWideIntObj(y + entryPtr->layoutY);
	bbox[2] = Tcl_NewWideIntObj(width);
	bbox[3] = Tcl_NewWideIntObj(height);
	bbox[0] = Tcl_NewIntObj(x + entryPtr->layoutX);
	bbox[1] = Tcl_NewIntObj(y + entryPtr->layoutY);
	bbox[2] = Tcl_NewIntObj(width);
	bbox[3] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(4, bbox));
	break;
    }

    case COMMAND_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    goto error;
	}

	objPtr = Tk_GetOptionValue(interp, entryPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) entryPtr,
		entryPtr->optionTable, objv[2], entryPtr->tkwin);
	if (objPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;

    case COMMAND_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, entryPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) entryPtr,
		    entryPtr->optionTable,
		    (objc == 3) ? objv[2] : NULL,
		    entryPtr->tkwin);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
	    result = ConfigureEntry(interp, entryPtr, objc-2, objv+2);
	}
	break;

    case COMMAND_DELETE: {
	Tcl_Size first, last;
	int first, last, code;
	int code;

	if ((objc < 3) || (objc > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&first) != TCL_OK) {
	    goto error;
	}
	if (objc == 3) {
	    last = first + 1;
	} else if (GetEntryIndex(interp, entryPtr, objv[3],
	} else if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[3]),
		&last) != TCL_OK) {
	    goto error;
	}
	if ((last >= first) && (entryPtr->state == STATE_NORMAL)) {
	    code = DeleteChars(entryPtr, first, last - first);
            if (code != TCL_OK) {
                goto error;
            }
	}
	break;
    }

    case COMMAND_GET:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    goto error;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
	break;

    case COMMAND_ICURSOR:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "pos");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&entryPtr->insertPos) != TCL_OK) {
	    goto error;
	}
	EventuallyRedraw(entryPtr);
	break;

    case COMMAND_INDEX: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "string");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	break;
    }

    case COMMAND_INSERT: {
	Tcl_Size index;
	int index, code;
	int code;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index text");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	if (entryPtr->state == STATE_NORMAL) {
	    code = InsertChars(entryPtr, index, Tcl_GetString(objv[3]));
            if (code != TCL_OK) {
                goto error;
779
780
781
782
783
784
785
786

787
788
789
790
791
792
793
794
795
796

797
798
799
800
801
802
803
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
786







-
+









-
+







	    entryPtr->scanMarkX = x;
	    entryPtr->scanMarkIndex = entryPtr->leftIndex;
	} else if ((minorCmd[0] == 'd')
		&& (strncmp(minorCmd, "dragto", strlen(minorCmd)) == 0)) {
	    EntryScanTo(entryPtr, x);
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad scan option \"%s\": must be dragto or mark",
		    "bad scan option \"%s\": must be mark or dragto",
		    minorCmd));
	    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "scan option",
		    minorCmd, NULL);
	    goto error;
	}
	break;
    }

    case COMMAND_SELECTION: {
	Tcl_Size index, index2;
	int index, index2;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option ?index?");
	    goto error;
	}

	/*
824
825
826
827
828
829
830
831

832
833
834
835


836
837
838
839
840
841
842
807
808
809
810
811
812
813

814
815
816


817
818
819
820
821
822
823
824
825







-
+


-
-
+
+







	switch (selIndex) {
	case SELECTION_ADJUST:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    if (entryPtr->selectFirst != TCL_INDEX_NONE) {
		Tcl_Size half1, half2;
	    if (entryPtr->selectFirst >= 0) {
		int half1, half2;

		half1 = (entryPtr->selectFirst + entryPtr->selectLast)/2;
		half2 = (entryPtr->selectFirst + entryPtr->selectLast + 1)/2;
		if (index < half1) {
		    entryPtr->selectAnchor = entryPtr->selectLast;
		} else if (index > half2) {
		    entryPtr->selectAnchor = entryPtr->selectFirst;
851
852
853
854
855
856
857
858
859
860



861
862
863
864
865
866
867
868
869
870
871

872
873
874
875
876
877
878
879
880
881
882
883

884
885
886
887
888
889
890
891

892
893
894
895

896
897
898
899
900
901


902
903
904
905
906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922

923
924
925
926
927
928
929
834
835
836
837
838
839
840



841
842
843
844
845
846
847
848
849
850
851
852
853

854
855
856
857
858
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873

874
875
876
877

878
879
880
881
882


883
884
885
886
887
888
889

890

891
892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907
908
909
910
911







-
-
-
+
+
+










-
+











-
+







-
+



-
+




-
-
+
+





-
+
-













-
+







	    break;

	case SELECTION_CLEAR:
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, NULL);
		goto error;
	    }
	    if (entryPtr->selectFirst != TCL_INDEX_NONE) {
		entryPtr->selectFirst = TCL_INDEX_NONE;
		entryPtr->selectLast = TCL_INDEX_NONE;
	    if (entryPtr->selectFirst >= 0) {
		entryPtr->selectFirst = -1;
		entryPtr->selectLast = -1;
		EventuallyRedraw(entryPtr);
	    }
	    goto done;

	case SELECTION_FROM:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    entryPtr->selectAnchor = index;
	    break;

	case SELECTION_PRESENT:
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, NULL);
		goto error;
	    }
	    Tcl_SetObjResult(interp,
		    Tcl_NewBooleanObj(entryPtr->selectFirst != TCL_INDEX_NONE));
		    Tcl_NewBooleanObj(entryPtr->selectFirst >= 0));
	    goto done;

	case SELECTION_RANGE:
	    if (objc != 5) {
		Tcl_WrongNumArgs(interp, 3, objv, "start end");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr, objv[3],
	    if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[3]),
		    &index) != TCL_OK) {
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr, objv[4],
	    if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[4]),
		    &index2) != TCL_OK) {
		goto error;
	    }
	    if (index >= index2) {
		entryPtr->selectFirst = TCL_INDEX_NONE;
		entryPtr->selectLast = TCL_INDEX_NONE;
		entryPtr->selectFirst = -1;
		entryPtr->selectLast = -1;
	    } else {
		entryPtr->selectFirst = index;
		entryPtr->selectLast = index2;
	    }
	    if (!(entryPtr->flags & GOT_SELECTION)
		    && (entryPtr->exportSelection)
		    && (entryPtr->exportSelection)) {
		    && (!Tcl_IsSafe(entryPtr->interp))) {
		Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY,
			EntryLostSelection, entryPtr);
		entryPtr->flags |= GOT_SELECTION;
	    }
	    EventuallyRedraw(entryPtr);
	    break;

	case SELECTION_TO:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    EntrySelectTo(entryPtr, index);
	    break;
	}
	break;
    }
943
944
945
946
947
948
949
950

951
952
953
954
955
956
957
958
959
960
961
962

963
964
965
966
967
968
969
970
971
972


973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004
925
926
927
928
929
930
931

932
933
934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973


974
975
976
977
978

979
980
981
982
983
984
985
986







-
+











-
+










+
+

















-
-





-
+







	    entryPtr->validate = selIndex;
	}
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(code == TCL_OK));
	break;
    }

    case COMMAND_XVIEW: {
	Tcl_Size index;
	int index;

	if (objc == 2) {
	    double first, last;
	    Tcl_Obj *span[2];

	    EntryVisibleRange(entryPtr, &first, &last);
	    span[0] = Tcl_NewDoubleObj(first);
	    span[1] = Tcl_NewDoubleObj(last);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, span));
	    goto done;
	} else if (objc == 3) {
	    if (GetEntryIndex(interp, entryPtr, objv[2],
	    if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		    &index) != TCL_OK) {
		goto error;
	    }
	} else {
	    double fraction;
	    int count;

	    index = entryPtr->leftIndex;
	    switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction,
		    &count)) {
	    case TK_SCROLL_ERROR:
		goto error;
	    case TK_SCROLL_MOVETO:
		index = (int) ((fraction * entryPtr->numChars) + 0.5);
		break;
	    case TK_SCROLL_PAGES: {
		int charsPerPage;

		charsPerPage = ((Tk_Width(entryPtr->tkwin)
			- 2 * entryPtr->inset) / entryPtr->avgWidth) - 2;
		if (charsPerPage < 1) {
		    charsPerPage = 1;
		}
		index += count * charsPerPage;
		break;
	    }
	    case TK_SCROLL_UNITS:
		index += count;
		break;
	    default:
		goto error;
	    }
	}
	if (index >= entryPtr->numChars) {
	    index = entryPtr->numChars - 1;
	}
	if ((int)index < 0) {
	if (index < 0) {
	    index = 0;
	}
	entryPtr->leftIndex = index;
	entryPtr->flags |= UPDATE_SCROLLBAR;
	EntryComputeGeometry(entryPtr);
	EventuallyRedraw(entryPtr);
	break;
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057

1058
1059
1060

1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1012
1013
1014
1015
1016
1017
1018

1019



1020

1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034

1035
1036
1037

1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1064







-

-
-
-

-
+






-
+






-
+


-
+




-
+













-
+







 *	Everything associated with the entry is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyEntry(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about entry widget. */
#else
    char *memPtr)
#endif
{
    Entry *entryPtr = (Entry *)memPtr;
    Entry *entryPtr = memPtr;

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeOptions handle all the standard option-related stuff.
     */

    ckfree((void *)entryPtr->string);
    ckfree((char *)entryPtr->string);
    if (entryPtr->textVarName != NULL) {
	Tcl_UntraceVar2(entryPtr->interp, entryPtr->textVarName,
		NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		EntryTextVarProc, entryPtr);
	entryPtr->flags &= ~ENTRY_VAR_TRACED;
    }
    if (entryPtr->textGC != NULL) {
    if (entryPtr->textGC != None) {
	Tk_FreeGC(entryPtr->display, entryPtr->textGC);
    }
    if (entryPtr->selTextGC != NULL) {
    if (entryPtr->selTextGC != None) {
	Tk_FreeGC(entryPtr->display, entryPtr->selTextGC);
    }
    Tcl_DeleteTimerHandler(entryPtr->insertBlinkHandler);
    if (entryPtr->displayString != entryPtr->string) {
	ckfree((void *)entryPtr->displayString);
	ckfree((char *)entryPtr->displayString);
    }
    if (entryPtr->type == TK_SPINBOX) {
	Spinbox *sbPtr = (Spinbox *) entryPtr;

	if (sbPtr->listObj != NULL) {
	    Tcl_DecrRefCount(sbPtr->listObj);
	    sbPtr->listObj = NULL;
	}
	if (sbPtr->formatBuf) {
	    ckfree(sbPtr->formatBuf);
	}
    }
    Tk_FreeTextLayout(entryPtr->textLayout);
    Tk_FreeConfigOptions(entryPtr, entryPtr->optionTable,
    Tk_FreeConfigOptions((char *) entryPtr, entryPtr->optionTable,
	    entryPtr->tkwin);
    Tcl_Release(entryPtr->tkwin);
    entryPtr->tkwin = NULL;

    ckfree(entryPtr);
}

1105
1106
1107
1108
1109
1110
1111
1112

1113
1114
1115
1116
1117
1118
1119
1120
1121
1122


1123
1124
1125
1126
1127




1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097
1098


1099
1100
1101




1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1146







-
+








-
-
+
+

-
-
-
-
+
+
+
+

-


















-
+













-
+







 */

static int
ConfigureEntry(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Entry *entryPtr,		/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_SavedOptions savedOptions;
    Tk_3DBorder border;
    Tcl_Obj *errorResult = NULL;
    Spinbox *sbPtr = (Spinbox *) entryPtr;
				/* Only used when this widget is of type
				 * TK_SPINBOX */
    char *oldValues = NULL;
    char *oldFormat = NULL;
    char *oldValues = NULL;	/* lint initialization */
    char *oldFormat = NULL;	/* lint initialization */
    int error;
    int oldExport = 0;
    int valuesChanged = 0;
    double oldFrom = 0.0;
    double oldTo = 0.0;
    int oldExport = 0;		/* lint initialization */
    int valuesChanged = 0;	/* lint initialization */
    double oldFrom = 0.0;	/* lint initialization */
    double oldTo = 0.0;		/* lint initialization */
    int code;
    size_t formatSpace = TCL_DOUBLE_SPACE;

    /*
     * Eliminate any existing trace on a variable monitored by the entry.
     */

    if ((entryPtr->textVarName != NULL)
	    && (entryPtr->flags & ENTRY_VAR_TRACED)) {
	Tcl_UntraceVar2(interp, entryPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		EntryTextVarProc, entryPtr);
	entryPtr->flags &= ~ENTRY_VAR_TRACED;
    }

    /*
     * Store old values that we need to effect certain behavior if they change
     * value.
     */

    oldExport = (entryPtr->exportSelection) && (!Tcl_IsSafe(entryPtr->interp));
    oldExport = entryPtr->exportSelection;
    if (entryPtr->type == TK_SPINBOX) {
	oldValues = sbPtr->valueStr;
	oldFormat = sbPtr->reqFormat;
	oldFrom = sbPtr->fromValue;
	oldTo = sbPtr->toValue;
    }

    for (error = 0; error <= 1; error++) {
	if (!error) {
	    /*
	     * First pass: set options to new values.
	     */

	    if (Tk_SetOptions(interp, entryPtr,
	    if (Tk_SetOptions(interp, (char *) entryPtr,
		    entryPtr->optionTable, objc, objv,
		    entryPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
		continue;
	    }
	} else {
	    /*
	     * Second pass: restore options to old values.
1213
1214
1215
1216
1217
1218
1219
1220

1221
1222
1223
1224
1225
1226
1227
1190
1191
1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204







-
+







		/*
		 * Make sure that the given format is somewhat correct, and
		 * calculate the minimum space we'll need for the values as
		 * strings.
		 */

		int min, max;
		size_t formatLen;
		size_t formatLen, formatSpace = TCL_DOUBLE_SPACE;
		char fbuf[4], *fmt = sbPtr->reqFormat;

		formatLen = strlen(fmt);
		if ((fmt[0] != '%') || (fmt[formatLen-1] != 'f')) {
		badFormatOpt:
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad spinbox format specifier \"%s\"",
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268

1269
1270

1271
1272
1273
1274
1275
1276
1277
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246

1247
1248
1249
1250
1251
1252
1253
1254







-
+




















-
+

-
+







		    formatSpace = min + 1;
		} else {
		    goto badFormatOpt;
		}
		if (formatSpace < TCL_DOUBLE_SPACE) {
		    formatSpace = TCL_DOUBLE_SPACE;
		}
		sbPtr->formatBuf = (char *)ckrealloc(sbPtr->formatBuf, formatSpace);
		sbPtr->formatBuf = ckrealloc(sbPtr->formatBuf, formatSpace);

		/*
		 * We perturb the value of oldFrom to allow us to go into the
		 * branch below that will reformat the displayed value.
		 */

		oldFrom = sbPtr->fromValue - 1;
	    }

	    /*
	     * See if we have to rearrange our listObj data.
	     */

	    if (oldValues != sbPtr->valueStr) {
		if (sbPtr->listObj != NULL) {
		    Tcl_DecrRefCount(sbPtr->listObj);
		}
		sbPtr->listObj = NULL;
		if (sbPtr->valueStr != NULL) {
		    Tcl_Obj *newObjPtr;
		    Tcl_Size nelems;
		    int nelems;

		    newObjPtr = Tcl_NewStringObj(sbPtr->valueStr, TCL_INDEX_NONE);
		    newObjPtr = Tcl_NewStringObj(sbPtr->valueStr, -1);
		    if (Tcl_ListObjLength(interp, newObjPtr, &nelems)
			    != TCL_OK) {
			valuesChanged = -1;
			continue;
		    }
		    sbPtr->listObj = newObjPtr;
		    Tcl_IncrRefCount(sbPtr->listObj);
1297
1298
1299
1300
1301
1302
1303
1304
1305

1306
1307
1308
1309
1310
1311
1312
1274
1275
1276
1277
1278
1279
1280


1281
1282
1283
1284
1285
1286
1287
1288







-
-
+







	}

	/*
	 * Claim the selection if we've suddenly started exporting it.
	 */

	if (entryPtr->exportSelection && (!oldExport)
		&& (!Tcl_IsSafe(entryPtr->interp))
		&& (entryPtr->selectFirst != TCL_INDEX_NONE)
		&& (entryPtr->selectFirst != -1)
		&& !(entryPtr->flags & GOT_SELECTION)) {
	    Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection,
		    entryPtr);
	    entryPtr->flags |= GOT_SELECTION;
	}

	/*
1390
1391
1392
1393
1394
1395
1396
1397

1398
1399

1400
1401
1402
1403
1404
1405
1406
1366
1367
1368
1369
1370
1371
1372

1373
1374

1375
1376
1377
1378
1379
1380
1381
1382







-
+

-
+







		/* Scan failure */
		dvalue = sbPtr->fromValue;
	    } else if (dvalue > sbPtr->toValue) {
		dvalue = sbPtr->toValue;
	    } else if (dvalue < sbPtr->fromValue) {
		dvalue = sbPtr->fromValue;
	    }
	    snprintf(sbPtr->formatBuf, formatSpace, sbPtr->valueFormat, dvalue);
	    sprintf(sbPtr->formatBuf, sbPtr->valueFormat, dvalue);

	    /*
            /*
	     * No check for error return here as well, because any possible
	     * error will be trapped below when attempting tracing.
	     */

	    EntryValueChanged(entryPtr, sbPtr->formatBuf);
	}
    }
1447
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457

1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432

1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444







-
+


-
+



-
+







 *	Entry will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
EntryWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC gc = NULL;
    GC gc = None;
    unsigned long mask;
    Tk_3DBorder border;
    XColor *colorPtr;
    Entry *entryPtr = (Entry *)instanceData;
    Entry *entryPtr = instanceData;

    entryPtr->avgWidth = Tk_TextWidth(entryPtr->tkfont, "0", 1);
    if (entryPtr->avgWidth == 0) {
	entryPtr->avgWidth = 1;
    }

    if (entryPtr->type == TK_SPINBOX) {
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554





1555
1556
1557

1558
1559
1560

1561
1562
1563
1564
1565
1566
1567
1568
1569



1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581





1582
1583
1584

1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595


1596
1597
1598
1599
1600
1601
1602
1478
1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489










1490
1491


1492
1493
1494
1495

1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515



1516
1517
1518
1519
1520
1521
1522

1523
1524
1525

1526
1527
1528
1529
1530
1531
1532



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544



1545
1546
1547
1548
1549
1550
1551

1552
1553
1554

1555
1556
1557
1558
1559
1560
1561


1562
1563
1564
1565
1566
1567
1568
1569
1570







-
+




-
-
-
-
-
-
-
-
-
-


-
-




-
+



















-
-
-
+
+
+
+
+


-
+


-
+






-
-
-
+
+
+









-
-
-
+
+
+
+
+


-
+


-
+






-
-
+
+








    Tk_SetBackgroundFromBorder(entryPtr->tkwin, border);
    gcValues.foreground = colorPtr->pixel;
    gcValues.font = Tk_FontId(entryPtr->tkfont);
    gcValues.graphics_exposures = False;
    mask = GCForeground | GCFont | GCGraphicsExposures;
    gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues);
    if (entryPtr->textGC != NULL) {
    if (entryPtr->textGC != None) {
	Tk_FreeGC(entryPtr->display, entryPtr->textGC);
    }
    entryPtr->textGC = gc;

    if (entryPtr->placeholderColorPtr != NULL) {
	gcValues.foreground = entryPtr->placeholderColorPtr->pixel;
    }
    mask = GCForeground | GCFont | GCGraphicsExposures;
    gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues);
    if (entryPtr->placeholderGC != NULL) {
	Tk_FreeGC(entryPtr->display, entryPtr->placeholderGC);
    }
    entryPtr->placeholderGC = gc;

    if (entryPtr->selFgColorPtr != NULL) {
	gcValues.foreground = entryPtr->selFgColorPtr->pixel;
    } else {
        gcValues.foreground = colorPtr->pixel;
    }
    gcValues.font = Tk_FontId(entryPtr->tkfont);
    mask = GCForeground | GCFont;
    gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues);
    if (entryPtr->selTextGC != NULL) {
    if (entryPtr->selTextGC != None) {
	Tk_FreeGC(entryPtr->display, entryPtr->selTextGC);
    }
    entryPtr->selTextGC = gc;

    /*
     * Recompute the window's geometry and arrange for it to be redisplayed.
     */

    EntryComputeGeometry(entryPtr);
    entryPtr->flags |= UPDATE_SCROLLBAR;
    EventuallyRedraw(entryPtr);
}

#ifndef MAC_OSX_TK
/*
 *--------------------------------------------------------------
 *
 * TkpDrawEntryBorderAndFocus --
 *
 *	Stub function for Tk on platforms other than Aqua
 *	(Windows and X11), which do not draw native entry borders.
 *	See macosx/tkMacOSXEntry.c for function definition in Tk Aqua.
 *	This function redraws the border of an entry widget. It overrides the
 *	generic border drawing code if the entry widget parameters are such
 *	that the native widget drawing is a good fit. This version just
 *	returns 0, so platforms that don't do special native drawing don't
 *	have to implement it.
 *
 * Results:
 *	Returns 0.
 *	1 if it has drawn the border, 0 if not.
 *
 * Side effects:
 *	None.
 *	May draw the entry border into pixmap.
 *
 *--------------------------------------------------------------
 */

int
TkpDrawEntryBorderAndFocus(
    TCL_UNUSED(Entry *),
    TCL_UNUSED(Drawable),
    TCL_UNUSED(int))
    Entry *entryPtr,
    Drawable pixmap,
    int isSpinbox)
{
    return 0;
}

/*
 *--------------------------------------------------------------
 *
 * TkpDrawSpinboxButtons --
 *
 *	Stub function for Tk on platforms other than Aqua
 *	(Windows and X11), which do not draw native spinbox buttons.
 *	See macosx/tkMacOSXEntry.c for function definition in Tk Aqua.
 *	This function redraws the buttons of an spinbox widget. It overrides
 *	the generic button drawing code if the spinbox widget parameters are
 *	such that the native widget drawing is a good fit. This version just
 *	returns 0, so platforms that don't do special native drawing don't
 *	have to implement it.
 *
 * Results:
 *	Returns 0.
 *	1 if it has drawn the border, 0 if not.
 *
 * Side effects:
 *	None.
 *	May draw the entry border into pixmap.
 *
 *--------------------------------------------------------------
 */

int
TkpDrawSpinboxButtons(
    TCL_UNUSED(Spinbox *),
    TCL_UNUSED(Pixmap))
    Spinbox *sbPtr,
    Pixmap pixmap)
{
    return 0;
}
#endif /* Not MAC_OSX_TK */

/*
 *--------------------------------------------------------------
1612
1613
1614
1615
1616
1617
1618
1619

1620
1621

1622
1623
1624
1625
1626
1627
1628
1580
1581
1582
1583
1584
1585
1586

1587
1588

1589
1590
1591
1592
1593
1594
1595
1596







-
+

-
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayEntry(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;
    Tk_Window tkwin = entryPtr->tkwin;
    int baseY, selStartX, selEndX, cursorX;
    int showSelection, xBound;
    Tk_FontMetrics fm;
    Pixmap pixmap;
    Tk_3DBorder border;

1677
1678
1679
1680
1681
1682
1683
1684

1685
1686
1687
1688
1689
1690
1691
1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659







-
+







    xBound = Tk_Width(tkwin) - entryPtr->inset - entryPtr->xWidth;
    baseY = (Tk_Height(tkwin) + fm.ascent - fm.descent) / 2;

    /*
     * Hide the selection whenever we don't have the focus, unless we
     * always want to show selection.
     */
    if (Tk_AlwaysShowSelection(entryPtr->tkwin)) {
    if (TkpAlwaysShowSelection(entryPtr->tkwin)) {
	showSelection = 1;
    } else {
	showSelection = (entryPtr->flags & GOT_FOCUS);
    }

    /*
     * Draw the background in three layers. From bottom to top the layers are:
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
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







-
+













-
-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
-
-
-
-
-
-
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    if ((entryPtr->state == STATE_NORMAL) && (entryPtr->flags & GOT_FOCUS)) {
	Tk_CharBbox(entryPtr->textLayout, entryPtr->insertPos, &cursorX, NULL,
		NULL, NULL);
	cursorX += entryPtr->layoutX;
	cursorX -= (entryPtr->insertWidth == 1) ? 1 : (entryPtr->insertWidth)/2;
	Tk_SetCaretPos(entryPtr->tkwin, cursorX, baseY - fm.ascent,
		fm.ascent + fm.descent);
	if ((entryPtr->insertPos >= entryPtr->leftIndex) && cursorX < xBound) {
	if (entryPtr->insertPos >= entryPtr->leftIndex && cursorX < xBound) {
	    if (entryPtr->flags & CURSOR_ON) {
		Tk_Fill3DRectangle(tkwin, pixmap, entryPtr->insertBorder,
			cursorX, baseY - fm.ascent, entryPtr->insertWidth,
			fm.ascent + fm.descent, entryPtr->insertBorderWidth,
			TK_RELIEF_RAISED);
	    } else if (entryPtr->insertBorder == entryPtr->selBorder) {
		Tk_Fill3DRectangle(tkwin, pixmap, border, cursorX,
			baseY - fm.ascent, entryPtr->insertWidth,
			fm.ascent + fm.descent, 0, TK_RELIEF_FLAT);
	    }
	}
    }

    if ((entryPtr->numChars == 0) && (entryPtr->placeholderChars != 0)) {

        /*
         * Draw the placeholder text.
         */
    /*
     * Draw the text in two pieces: first the unselected portion, then the
     * selected portion on top of it.
     */

        Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->placeholderGC,
	    entryPtr->placeholderLayout, entryPtr->placeholderX, entryPtr->layoutY,
	    entryPtr->placeholderLeftIndex, entryPtr->placeholderChars);
    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
	    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
	    entryPtr->leftIndex, entryPtr->numChars);

    } else {

        if (showSelection && (entryPtr->state != STATE_DISABLED)
	        && (entryPtr->selTextGC != entryPtr->textGC)
	        && (entryPtr->selectFirst < entryPtr->selectLast)) {
    if (showSelection && (entryPtr->state != STATE_DISABLED)
	    && (entryPtr->selTextGC != entryPtr->textGC)
	    && (entryPtr->selectFirst < entryPtr->selectLast)) {

	    /*
	     * Draw the selected and unselected portions separately.
	     */

	    Tcl_Size selFirst;
	int selFirst;

	    if (entryPtr->selectFirst < entryPtr->leftIndex) {
	        selFirst = entryPtr->leftIndex;
	    } else {
	        selFirst = entryPtr->selectFirst;
	    }
	if (entryPtr->selectFirst < entryPtr->leftIndex) {
	    selFirst = entryPtr->leftIndex;
	} else {
	    selFirst = entryPtr->selectFirst;
	}
	    if (entryPtr->leftIndex < selFirst) {
	        Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
		        entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
		        entryPtr->leftIndex, selFirst);
	    }
	    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->selTextGC,
		    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
		    selFirst, entryPtr->selectLast);
	Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->selTextGC,
		entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
		selFirst, entryPtr->selectLast);
	    if (entryPtr->selectLast < entryPtr->numChars) {
	        Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
		        entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
		        entryPtr->selectLast, entryPtr->numChars);
	    }
        } else {

            /*
             * Draw the entire visible text
             */

	    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
		    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
		    entryPtr->leftIndex, entryPtr->numChars);
        }
    }

    if (entryPtr->type == TK_SPINBOX) {
	int startx, height, inset, pad, tHeight, xWidth;
	Spinbox *sbPtr = (Spinbox *) entryPtr;

	/*
1920
1921
1922
1923
1924
1925
1926
1927

1928
1929

1930
1931
1932
1933
1934
1935
1936
1860
1861
1862
1863
1864
1865
1866

1867
1868

1869
1870
1871
1872
1873
1874
1875
1876







-
+

-
+







	}
	if (xBound > 0) {
	    GC fgGC, bgGC;

	    bgGC = Tk_GCForColor(entryPtr->highlightBgColorPtr, pixmap);
	    if (entryPtr->flags & GOT_FOCUS) {
		fgGC = Tk_GCForColor(entryPtr->highlightColorPtr, pixmap);
		Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, xBound, pixmap);
		TkpDrawHighlightBorder(tkwin, fgGC, bgGC, xBound, pixmap);
	    } else {
		Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, xBound, pixmap);
		TkpDrawHighlightBorder(tkwin, bgGC, bgGC, xBound, pixmap);
	    }
	}
    }

#ifndef TK_NO_DOUBLE_BUFFERING
    /*
     * Everything's been redisplayed; now copy the pixmap onto the screen and
1965
1966
1967
1968
1969
1970
1971
1972

1973
1974
1975
1976
1977
1978
1979

1980
1981
1982
1983
1984
1985
1986
1905
1906
1907
1908
1909
1910
1911

1912

1913
1914
1915
1916
1917

1918
1919
1920
1921
1922
1923
1924
1925







-
+
-





-
+







 *----------------------------------------------------------------------
 */

static void
EntryComputeGeometry(
    Entry *entryPtr)		/* Widget record for entry. */
{
    int totalLength, overflow, rightX;
    int totalLength, overflow, maxOffScreen, rightX;
    Tcl_Size maxOffScreen;
    int height, width, i;
    Tk_FontMetrics fm;
    char *p;

    if (entryPtr->displayString != entryPtr->string) {
	ckfree((void *)entryPtr->displayString);
	ckfree((char *)entryPtr->displayString);
	entryPtr->displayString = entryPtr->string;
	entryPtr->numDisplayBytes = entryPtr->numBytes;
    }

    /*
     * If we're displaying a special character instead of the value of the
     * entry, recompute the displayString.
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
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







-
-
+
+


-
+


-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	/*
	 * Normalize the special character so we can safely duplicate it in
	 * the display string. If we didn't do this, then two malformed
	 * characters might end up looking like one valid UTF character in the
	 * resulting string.
	 */

	Tcl_UtfToUniChar(entryPtr->showChar, &ch);
	size = Tcl_UniCharToUtf(ch, buf);
	TkUtfToUniChar(entryPtr->showChar, &ch);
	size = TkUniCharToUtf(ch, buf);

	entryPtr->numDisplayBytes = entryPtr->numChars * size;
	p = (char *)ckalloc(entryPtr->numDisplayBytes + 1);
	p = ckalloc(entryPtr->numDisplayBytes + 1);
	entryPtr->displayString = p;

	for (i = entryPtr->numChars; i-- > 0; ) {
	for (i = entryPtr->numChars; --i >= 0; ) {
	    memcpy(p, buf, size);
	    p += size;
	}
	*p = '\0';
    }

    /* Recompute layout of placeholder text.
     * Only the placeholderX and placeholderLeftIndex value is needed.
     * We use the same font so we can use the layoutY value from below.
     */

    Tk_FreeTextLayout(entryPtr->placeholderLayout);
    if (entryPtr->placeholderString) {
        entryPtr->placeholderChars = strlen(entryPtr->placeholderString);
        entryPtr->placeholderLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
	        entryPtr->placeholderString, entryPtr->placeholderChars, 0,
	        entryPtr->justify, TK_IGNORE_NEWLINES, &totalLength, NULL);
	overflow = totalLength -
	        (Tk_Width(entryPtr->tkwin) - 2*entryPtr->inset - entryPtr->xWidth);
	if (overflow <= 0) {
	    entryPtr->placeholderLeftIndex = 0;
	    if (entryPtr->justify == TK_JUSTIFY_LEFT) {
		entryPtr->placeholderX = entryPtr->inset;
	    } else if (entryPtr->justify == TK_JUSTIFY_RIGHT) {
		entryPtr->placeholderX = Tk_Width(entryPtr->tkwin) - entryPtr->inset
		        - entryPtr->xWidth - totalLength;
	    } else {
		entryPtr->placeholderX = (Tk_Width(entryPtr->tkwin)
		        - entryPtr->xWidth - totalLength)/2;
	    }
    	} else {

	    /*
	     * The whole string can't fit in the window. Compute the maximum
	     * number of characters that may be off-screen to the left without
	     * leaving empty space on the right of the window, then don't let
	     * placeholderLeftIndex be any greater than that.
	     */

	    maxOffScreen = Tk_PointToChar(entryPtr->placeholderLayout, overflow, 0);
	    Tk_CharBbox(entryPtr->placeholderLayout, maxOffScreen,
		&rightX, NULL, NULL, NULL);
	    if (rightX < overflow) {
		maxOffScreen++;
	    }
	    entryPtr->placeholderLeftIndex = maxOffScreen;
	    Tk_CharBbox(entryPtr->placeholderLayout, entryPtr->placeholderLeftIndex, &rightX,
		NULL, NULL, NULL);
	    entryPtr->placeholderX = entryPtr->inset -rightX;
        }
    } else {
        entryPtr->placeholderChars = 0;
        entryPtr->placeholderLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
	        entryPtr->placeholderString, 0, 0,
	        entryPtr->justify, TK_IGNORE_NEWLINES, NULL, NULL);
	entryPtr->placeholderX = entryPtr->inset;
    }

    Tk_FreeTextLayout(entryPtr->textLayout);
    entryPtr->textLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
	    entryPtr->displayString, entryPtr->numChars, 0,
	    entryPtr->justify, TK_IGNORE_NEWLINES, &totalLength, &height);

    entryPtr->layoutY = (Tk_Height(entryPtr->tkwin) - height) / 2;

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
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







-
+




+
-
+
+











-
+












-
+






-
+





-
+







 *
 *----------------------------------------------------------------------
 */

static int
InsertChars(
    Entry *entryPtr,		/* Entry that is to get the new elements. */
    Tcl_Size index,			/* Add the new elements before this character
    int index,			/* Add the new elements before this character
				 * index. */
    const char *value)		/* New characters to add (NULL-terminated
				 * string). */
{
    ptrdiff_t byteIndex;
    size_t byteIndex, byteCount, newByteCount, oldChars, charsAdded;
    size_t byteCount, newByteCount;
    int oldChars, charsAdded;
    const char *string;
    char *newStr;

    string = entryPtr->string;
    byteIndex = Tcl_UtfAtIndex(string, index) - string;
    byteCount = strlen(value);
    if (byteCount == 0) {
	return TCL_OK;
    }

    newByteCount = entryPtr->numBytes + byteCount + 1;
    newStr = (char *)ckalloc(newByteCount);
    newStr = ckalloc(newByteCount);
    memcpy(newStr, string, byteIndex);
    strcpy(newStr + byteIndex, value);
    strcpy(newStr + byteIndex + byteCount, string + byteIndex);

    if ((entryPtr->validate == VALIDATE_KEY ||
	    entryPtr->validate == VALIDATE_ALL) &&
	    EntryValidateChange(entryPtr, value, newStr, index,
		    VALIDATE_INSERT) != TCL_OK) {
	ckfree(newStr);
	return TCL_OK;
    }

    ckfree((void *)string);
    ckfree((char *)string);
    entryPtr->string = newStr;

    /*
     * The following construction is used because inserting improperly formed
     * UTF-8 sequences between other improperly formed UTF-8 sequences could
     * result in actually forming valid UTF-8 sequences; the number of
     * characters added may not be Tcl_NumUtfChars(string, TCL_INDEX_NONE), because of
     * characters added may not be Tcl_NumUtfChars(string, -1), because of
     * context. The actual number of characters added is how many characters
     * are in the string now minus the number that used to be there.
     */

    oldChars = entryPtr->numChars;
    entryPtr->numChars = Tcl_NumUtfChars(newStr, TCL_INDEX_NONE);
    entryPtr->numChars = Tcl_NumUtfChars(newStr, -1);
    charsAdded = entryPtr->numChars - oldChars;
    entryPtr->numBytes += byteCount;

    if (entryPtr->displayString == string) {
	entryPtr->displayString = newStr;
	entryPtr->numDisplayBytes = entryPtr->numBytes;
    }
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
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







-
-
+
+





-
+


-
+








-
+



-
+













-
+
















-
+






-
+






-
-
+
+


-
+






-
+






-
+







 *
 *----------------------------------------------------------------------
 */

static int
DeleteChars(
    Entry *entryPtr,		/* Entry widget to modify. */
    Tcl_Size index,			/* Index of first character to delete. */
    Tcl_Size count)			/* How many characters to delete. */
    int index,			/* Index of first character to delete. */
    int count)			/* How many characters to delete. */
{
    int byteIndex, byteCount, newByteCount;
    const char *string;
    char *newStr, *toDelete;

    if (index + count > entryPtr->numChars) {
    if ((index + count) > entryPtr->numChars) {
	count = entryPtr->numChars - index;
    }
    if ((int)count <= 0) {
    if (count <= 0) {
	return TCL_OK;
    }

    string = entryPtr->string;
    byteIndex = Tcl_UtfAtIndex(string, index) - string;
    byteCount = Tcl_UtfAtIndex(string + byteIndex, count) - (string+byteIndex);

    newByteCount = entryPtr->numBytes + 1 - byteCount;
    newStr = (char *)ckalloc(newByteCount);
    newStr = ckalloc(newByteCount);
    memcpy(newStr, string, (size_t) byteIndex);
    strcpy(newStr + byteIndex, string + byteIndex + byteCount);

    toDelete = (char *)ckalloc(byteCount + 1);
    toDelete = ckalloc(byteCount + 1);
    memcpy(toDelete, string + byteIndex, (size_t) byteCount);
    toDelete[byteCount] = '\0';

    if ((entryPtr->validate == VALIDATE_KEY ||
	    entryPtr->validate == VALIDATE_ALL) &&
	    EntryValidateChange(entryPtr, toDelete, newStr, index,
		    VALIDATE_DELETE) != TCL_OK) {
	ckfree(newStr);
	ckfree(toDelete);
	return TCL_OK;
    }

    ckfree(toDelete);
    ckfree((void *)entryPtr->string);
    ckfree((char *)entryPtr->string);
    entryPtr->string = newStr;
    entryPtr->numChars -= count;
    entryPtr->numBytes -= byteCount;

    if (entryPtr->displayString == string) {
	entryPtr->displayString = newStr;
	entryPtr->numDisplayBytes = entryPtr->numBytes;
    }

    /*
     * Deleting characters results in the remaining characters being
     * renumbered. Update the various indexes into the string to reflect this
     * change.
     */

    if (entryPtr->selectFirst >= index) {
	if (entryPtr->selectFirst >= index + count) {
	if (entryPtr->selectFirst >= (index + count)) {
	    entryPtr->selectFirst -= count;
	} else {
	    entryPtr->selectFirst = index;
	}
    }
    if (entryPtr->selectLast >= index) {
	if (entryPtr->selectLast >= index + count) {
	if (entryPtr->selectLast >= (index + count)) {
	    entryPtr->selectLast -= count;
	} else {
	    entryPtr->selectLast = index;
	}
    }
    if (entryPtr->selectLast <= entryPtr->selectFirst) {
	entryPtr->selectFirst = TCL_INDEX_NONE;
	entryPtr->selectLast = TCL_INDEX_NONE;
	entryPtr->selectFirst = -1;
	entryPtr->selectLast = -1;
    }
    if (entryPtr->selectAnchor >= index) {
	if (entryPtr->selectAnchor >= index + count) {
	if (entryPtr->selectAnchor >= (index+count)) {
	    entryPtr->selectAnchor -= count;
	} else {
	    entryPtr->selectAnchor = index;
	}
    }
    if (entryPtr->leftIndex > index) {
	if (entryPtr->leftIndex >= index + count) {
	if (entryPtr->leftIndex >= (index + count)) {
	    entryPtr->leftIndex -= count;
	} else {
	    entryPtr->leftIndex = index;
	}
    }
    if (entryPtr->insertPos >= index) {
	if (entryPtr->insertPos >= index + count) {
	if (entryPtr->insertPos >= (index + count)) {
	    entryPtr->insertPos -= count;
	} else {
	    entryPtr->insertPos = index;
	}
    }
    return EntryValueChanged(entryPtr, NULL);
}
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
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







-
+






-
+










-
+





-
+




-
+












-
+

-
-
+
+







    } else {
	/*
	 * If we validate, we create a copy of the value, as it may point to
	 * volatile memory, like the value of the -textvar which may get freed
	 * during validation
	 */

	char *tmp = (char *)ckalloc(valueLen + 1);
	char *tmp = ckalloc(valueLen + 1);

	strcpy(tmp, value);
	value = tmp;
	malloced = 1;

	entryPtr->flags |= VALIDATE_VAR;
	(void) EntryValidateChange(entryPtr, NULL, value, TCL_INDEX_NONE,
	(void) EntryValidateChange(entryPtr, NULL, value, -1,
		VALIDATE_FORCED);
	entryPtr->flags &= ~VALIDATE_VAR;

	/*
	 * If VALIDATE_ABORT has been set, then this operation should be
	 * aborted because the validatecommand did something else instead
	 */

	if (entryPtr->flags & VALIDATE_ABORT) {
	    entryPtr->flags &= ~VALIDATE_ABORT;
	    ckfree((void *)value);
	    ckfree((char *)value);
	    return;
	}
    }

    oldSource = entryPtr->string;
    ckfree((void *)entryPtr->string);
    ckfree((char *)entryPtr->string);

    if (malloced) {
	entryPtr->string = value;
    } else {
	char *tmp = (char *)ckalloc(valueLen + 1);
	char *tmp = ckalloc(valueLen + 1);

	strcpy(tmp, value);
	entryPtr->string = tmp;
    }
    entryPtr->numBytes = valueLen;
    entryPtr->numChars = Tcl_NumUtfChars(value, valueLen);

    if (entryPtr->displayString == oldSource) {
	entryPtr->displayString = entryPtr->string;
	entryPtr->numDisplayBytes = entryPtr->numBytes;
    }

    if (entryPtr->selectFirst != TCL_INDEX_NONE) {
    if (entryPtr->selectFirst >= 0) {
	if (entryPtr->selectFirst >= entryPtr->numChars) {
	    entryPtr->selectFirst = TCL_INDEX_NONE;
	    entryPtr->selectLast = TCL_INDEX_NONE;
	    entryPtr->selectFirst = -1;
	    entryPtr->selectLast = -1;
	} else if (entryPtr->selectLast > entryPtr->numChars) {
	    entryPtr->selectLast = entryPtr->numChars;
	}
    }
    if (entryPtr->leftIndex >= entryPtr->numChars) {
	if (entryPtr->numChars > 0) {
	    entryPtr->leftIndex = entryPtr->numChars - 1;
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
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







-
+


-
+


-
+













-
+

-
+




















-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
EntryEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;

    if ((entryPtr->type == TK_SPINBOX) && (eventPtr->type == MotionNotify)) {
	Spinbox *sbPtr = (Spinbox *)clientData;
	Spinbox *sbPtr = clientData;
	int elem;

	elem = GetSpinboxElement(sbPtr, eventPtr->xmotion.x,
		eventPtr->xmotion.y);
	if (elem != sbPtr->curElement) {
	    Tk_Cursor cursor;

	    sbPtr->curElement = elem;
	    if (elem == SEL_ENTRY) {
		cursor = entryPtr->cursor;
	    } else if ((elem == SEL_BUTTONDOWN) || (elem == SEL_BUTTONUP)) {
		cursor = sbPtr->bCursor;
	    } else {
		cursor = NULL;
		cursor = None;
	    }
	    if (cursor != NULL) {
	    if (cursor != None) {
		Tk_DefineCursor(entryPtr->tkwin, cursor);
	    } else {
		Tk_UndefineCursor(entryPtr->tkwin);
	    }
	}
	return;
    }

    switch (eventPtr->type) {
    case Expose:
	EventuallyRedraw(entryPtr);
	entryPtr->flags |= BORDER_NEEDED;
	break;
    case DestroyNotify:
	if (!(entryPtr->flags & ENTRY_DELETED)) {
	    entryPtr->flags |= (ENTRY_DELETED | VALIDATE_ABORT);
	    Tcl_DeleteCommandFromToken(entryPtr->interp, entryPtr->widgetCmd);
	    if (entryPtr->flags & REDRAW_PENDING) {
		Tcl_CancelIdleCall(DisplayEntry, clientData);
	    }
	    Tcl_EventuallyFree(clientData, DestroyEntry);
	    Tcl_EventuallyFree(clientData, (Tcl_FreeProc *) DestroyEntry);
	}
	break;
    case ConfigureNotify:
	Tcl_Preserve(entryPtr);
	entryPtr->flags |= UPDATE_SCROLLBAR;
	EntryComputeGeometry(entryPtr);
	EventuallyRedraw(entryPtr);
2626
2627
2628
2629
2630
2631
2632
2633

2634
2635

2636
2637
2638
2639
2640
2641
2642
2515
2516
2517
2518
2519
2520
2521

2522
2523

2524
2525
2526
2527
2528
2529
2530
2531







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
EntryCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.
     */
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
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







-
-
+
+

-
+
-

-
-
-
-
-
-
-
-
-
-
+
-








+
+
+
+
+
+







 */

static int
GetEntryIndex(
    Tcl_Interp *interp,		/* For error messages. */
    Entry *entryPtr,		/* Entry for which the index is being
				 * specified. */
    Tcl_Obj *indexObj,	/* Specifies character in entryPtr. */
    Tcl_Size *indexPtr)		/* Where to store converted character index */
    const char *string,	/* Specifies character in entryPtr. */
    int *indexPtr)		/* Where to store converted character index */
{
    Tcl_Size length, idx;
    size_t length;
    const char *string;

    if (TCL_OK == TkGetIntForIndex(indexObj, entryPtr->numChars - 1, 1, &idx)) {
	if (idx < 0) {
	    idx = 0;
	} else if (idx > entryPtr->numChars) {
	    idx = entryPtr->numChars;
	}
	*indexPtr = idx;
	return TCL_OK;
    }

    length = strlen(string);
    string = Tcl_GetStringFromObj(indexObj, &length);

    switch (string[0]) {
    case 'a':
	if (strncmp(string, "anchor", length) != 0) {
	    goto badIndex;
	}
	*indexPtr = entryPtr->selectAnchor;
	break;
    case 'e':
	if (strncmp(string, "end", length) != 0) {
	    goto badIndex;
	}
	*indexPtr = entryPtr->numChars;
	break;
    case 'i':
	if (strncmp(string, "insert", length) != 0) {
	    goto badIndex;
	}
	*indexPtr = entryPtr->insertPos;
	break;
    case 's':
2752
2753
2754
2755
2756
2757
2758











2759
2760
2761
2762
2763
2764
2765







2766
2767
2768
2769
2770
2771
2772
2773
2774
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







+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-








	if (roundUp && (*indexPtr < entryPtr->numChars)) {
	    *indexPtr += 1;
	}
	break;
    }
    default:
	if (Tcl_GetInt(NULL, string, indexPtr) != TCL_OK) {
	    goto badIndex;
	}
	if (*indexPtr < 0){
	    *indexPtr = 0;
	} else if (*indexPtr > entryPtr->numChars) {
	    *indexPtr = entryPtr->numChars;
	}
    }
    return TCL_OK;

	  badIndex:
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad %s index \"%s\"",
		    (entryPtr->type == TK_ENTRY) ? "entry" : "spinbox", string));
	    Tcl_SetErrorCode(interp, "TK",
		    (entryPtr->type == TK_ENTRY) ? "ENTRY" : "SPINBOX",
		    "BAD_INDEX", NULL);
	    return TCL_ERROR;
  badIndex:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad %s index \"%s\"",
	    (entryPtr->type == TK_ENTRY) ? "entry" : "spinbox", string));
    Tcl_SetErrorCode(interp, "TK",
	    (entryPtr->type == TK_ENTRY) ? "ENTRY" : "SPINBOX",
	    "BAD_INDEX", NULL);
    return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * EntryScanTo --
 *
2785
2786
2787
2788
2789
2790
2791
2792

2793
2794
2795
2796
2797
2798
2799
2678
2679
2680
2681
2682
2683
2684

2685
2686
2687
2688
2689
2690
2691
2692







-
+







 */

static void
EntryScanTo(
    Entry *entryPtr,		/* Information about widget. */
    int x)			/* X-coordinate to use for scan operation. */
{
    Tcl_Size newLeftIndex;
    int newLeftIndex;

    /*
     * Compute new leftIndex for entry by amplifying the difference between
     * the current position and the place where the scan started (the "mark"
     * position). If we run off the left or right side of the entry, then
     * reset the mark point so that the current position continues to
     * correspond to the edge of the window. This means that the picture will
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
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







-
+


-
+





-
+
-



















-
+







 *
 *----------------------------------------------------------------------
 */

static void
EntrySelectTo(
    Entry *entryPtr,		/* Information about widget. */
    Tcl_Size index)			/* Character index of element that is to
    int index)			/* Character index of element that is to
				 * become the "other" end of the selection. */
{
    Tcl_Size newFirst, newLast;
    int newFirst, newLast;

    /*
     * Grab the selection if we don't own it already.
     */

    if (!(entryPtr->flags & GOT_SELECTION) && (entryPtr->exportSelection)
    if (!(entryPtr->flags & GOT_SELECTION) && (entryPtr->exportSelection)) {
	    && (!Tcl_IsSafe(entryPtr->interp))) {
	Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection,
		entryPtr);
	entryPtr->flags |= GOT_SELECTION;
    }

    /*
     * Pick new starting and ending points for the selection.
     */

    if (entryPtr->selectAnchor > entryPtr->numChars) {
	entryPtr->selectAnchor = entryPtr->numChars;
    }
    if (entryPtr->selectAnchor <= index) {
	newFirst = entryPtr->selectAnchor;
	newLast = index;
    } else {
	newFirst = index;
	newLast = entryPtr->selectAnchor;
	if (newLast < 0) {
	    newFirst = newLast = TCL_INDEX_NONE;
	    newFirst = newLast = -1;
	}
    }
    if ((entryPtr->selectFirst == newFirst)
	    && (entryPtr->selectLast == newLast)) {
	return;
    }
    entryPtr->selectFirst = newFirst;
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
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







-
+

-
-
+
+


-
+


-
-
+
+



-
+
-






-
-
-




+
+
+
-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
EntryFetchSelection(
    void *clientData,	/* Information about entry widget. */
    Tcl_Size offset,			/* Byte offset within selection of first
    ClientData clientData,	/* Information about entry widget. */
    int offset,			/* Byte offset within selection of first
				 * character to be returned. */
    char *buffer,		/* Location in which to place selection. */
    Tcl_Size maxBytes)		/* Maximum number of bytes to place at buffer,
    int maxBytes)		/* Maximum number of bytes to place at buffer,
				 * not including terminating NUL character. */
{
    Entry *entryPtr = (Entry *)clientData;
    Tcl_Size byteCount;
    Entry *entryPtr = clientData;
    int byteCount;
    const char *string;
    const char *selStart, *selEnd;

    if ((entryPtr->selectFirst < 0) || (!entryPtr->exportSelection)
    if ((entryPtr->selectFirst < 0) || !(entryPtr->exportSelection)) {
	    || Tcl_IsSafe(entryPtr->interp)) {
	return -1;
    }
    string = entryPtr->displayString;
    selStart = Tcl_UtfAtIndex(string, entryPtr->selectFirst);
    selEnd = Tcl_UtfAtIndex(selStart,
	    entryPtr->selectLast - entryPtr->selectFirst);
    if (selEnd <= selStart + offset) {
	return 0;
    }
    byteCount = selEnd - selStart - offset;
    if (byteCount > maxBytes) {
	byteCount = maxBytes;
    }
    if (byteCount <= 0) {
	return 0;
    }
    memcpy(buffer, selStart + offset, byteCount);
    memcpy(buffer, selStart + offset, (size_t) byteCount);
    buffer[byteCount] = '\0';
    return byteCount;
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+

-
+










-
-
+
+
-
-
-
+
+







 *	not containing a selection.
 *
 *----------------------------------------------------------------------
 */

static void
EntryLostSelection(
    void *clientData)	/* Information about entry widget. */
    ClientData clientData)	/* Information about entry widget. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;

    entryPtr->flags &= ~GOT_SELECTION;

    /*
     * On Windows and Mac systems, we want to remember the selection for the
     * next time the focus enters the window. On Unix, we need to clear the
     * selection since it is always visible.
     * This is controlled by ::tk::AlwaysShowSelection.
     */

    if (Tk_AlwaysShowSelection(entryPtr->tkwin)
	    && (entryPtr->selectFirst != TCL_INDEX_NONE) && entryPtr->exportSelection
    if (TkpAlwaysShowSelection(entryPtr->tkwin)
	    && (entryPtr->selectFirst >= 0) && entryPtr->exportSelection) {
	    && (!Tcl_IsSafe(entryPtr->interp))) {
	entryPtr->selectFirst = TCL_INDEX_NONE;
	entryPtr->selectLast = TCL_INDEX_NONE;
	entryPtr->selectFirst = -1;
	entryPtr->selectLast = -1;
	EventuallyRedraw(entryPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
3054
3055
3056
3057
3058
3059
3060
3061

3062
3063
3064
3065
3066
3067
3068
2944
2945
2946
2947
2948
2949
2950

2951
2952
2953
2954
2955
2956
2957
2958







-
+







    if (entryPtr->numChars == 0) {
	*firstPtr = 0.0;
	*lastPtr = 1.0;
    } else {
	charsInWindow = Tk_PointToChar(entryPtr->textLayout,
		Tk_Width(entryPtr->tkwin) - entryPtr->inset
		- entryPtr->xWidth - entryPtr->layoutX - 1, 0);
	if (charsInWindow < (int)entryPtr->numChars) {
	if (charsInWindow < entryPtr->numChars) {
	    charsInWindow++;
	}
	charsInWindow -= entryPtr->leftIndex;
	if (charsInWindow == 0) {
	    charsInWindow = 1;
	}

3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120






3121
3122
3123
3124
3125
3126
3127
2998
2999
3000
3001
3002
3003
3004






3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017







-
-
-
-
-
-
+
+
+
+
+
+








    interp = entryPtr->interp;
    Tcl_Preserve(interp);
    EntryVisibleRange(entryPtr, &first, &last);
    Tcl_PrintDouble(NULL, first, firstStr);
    Tcl_PrintDouble(NULL, last, lastStr);
    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, entryPtr->scrollCmd, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, firstStr, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, lastStr, TCL_INDEX_NONE);
    code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
    Tcl_DStringAppend(&buf, entryPtr->scrollCmd, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, firstStr, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, lastStr, -1);
    code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
    Tcl_DStringFree(&buf);
    if (code != TCL_OK) {
	Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
		"\n    (horizontal scrolling command executed by %s)",
		Tk_PathName(entryPtr->tkwin)));
	Tcl_BackgroundException(interp, code);
    }
3145
3146
3147
3148
3149
3150
3151
3152

3153
3154

3155
3156
3157
3158
3159
3160
3161
3035
3036
3037
3038
3039
3040
3041

3042
3043

3044
3045
3046
3047
3048
3049
3050
3051







-
+

-
+







 *	function reschedules itself.
 *
 *----------------------------------------------------------------------
 */

static void
EntryBlinkProc(
    void *clientData)	/* Pointer to record describing entry. */
    ClientData clientData)	/* Pointer to record describing entry. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;

    if ((entryPtr->state == STATE_DISABLED) ||
	    (entryPtr->state == STATE_READONLY) ||
	    !(entryPtr->flags & GOT_FOCUS) || (entryPtr->insertOffTime == 0)) {
	return;
    }
    if (entryPtr->flags & CURSOR_ON) {
3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210
3211
3212
3213
3214
3215
3216

3217
3218
3219
3220
3221
3222
3223
3090
3091
3092
3093
3094
3095
3096

3097
3098
3099
3100
3101
3102
3103
3104
3105

3106
3107
3108
3109
3110
3111
3112
3113







-
+








-
+







	if (entryPtr->insertOffTime != 0) {
	    entryPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
		    entryPtr->insertOnTime, EntryBlinkProc, entryPtr);
	}
	if (entryPtr->validate == VALIDATE_ALL ||
		entryPtr->validate == VALIDATE_FOCUS ||
		entryPtr->validate == VALIDATE_FOCUSIN) {
	    EntryValidateChange(entryPtr, NULL, entryPtr->string, TCL_INDEX_NONE,
	    EntryValidateChange(entryPtr, NULL, entryPtr->string, -1,
		    VALIDATE_FOCUSIN);
	}
    } else {
	entryPtr->flags &= ~(GOT_FOCUS | CURSOR_ON);
	entryPtr->insertBlinkHandler = NULL;
	if (entryPtr->validate == VALIDATE_ALL ||
		entryPtr->validate == VALIDATE_FOCUS ||
		entryPtr->validate == VALIDATE_FOCUSOUT) {
	    EntryValidateChange(entryPtr, NULL, entryPtr->string, TCL_INDEX_NONE,
	    EntryValidateChange(entryPtr, NULL, entryPtr->string, -1,
		    VALIDATE_FOCUSOUT);
	}
    }
    EventuallyRedraw(entryPtr);
}

/*
3233
3234
3235
3236
3237
3238
3239

3240
3241
3242

3243
3244
3245


3246
3247
3248

3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266

3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291

3292
3293
3294
3295
3296
3297
3298
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







+


-
+

-
-
+
+


-
+















-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
+







 *
 * Side effects:
 *	The text displayed in the entry will change to match the variable.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static char *
EntryTextVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),
    TCL_UNUSED(const char *),
    const char *name1,		/* Not used. */
    const char *name2,		/* Not used. */
    int flags)			/* Information about what happened. */
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;
    const char *value;

    if (entryPtr->flags & ENTRY_DELETED) {
	/*
	 * Just abort early if we entered here while being deleted.
	 */
	return NULL;
    }

    /*
     * If the variable is unset, then immediately recreate it unless the whole
     * interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
        if (!Tcl_InterpDeleted(interp) && entryPtr->textVarName) {
            void *probe = NULL;

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
            do {
                probe = Tcl_VarTraceInfo(interp,
                        entryPtr->textVarName,
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        EntryTextVarProc, probe);
                if (probe == entryPtr) {
                    break;
                }
            } while (probe);
            if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * textVarName, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
                return NULL;
            }
	    Tcl_SetVar2(interp, entryPtr->textVarName, NULL,
		    entryPtr->string, TCL_GLOBAL_ONLY);
	    Tcl_TraceVar2(interp, entryPtr->textVarName, NULL,
		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    EntryTextVarProc, clientData);
	    entryPtr->flags |= ENTRY_VAR_TRACED;
        }
	}
	return NULL;
    }

    /*
     * Update the entry's text with the value of the variable, unless the
     * entry already has that value (this happens when the variable changes
     * value because we changed it because someone typed in the entry).
3324
3325
3326
3327
3328
3329
3330
3331
3332


3333
3334
3335
3336


3337
3338

3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358

3359
3360
3361
3362
3363
3364
3365
3366
3367

3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380

3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391

3392
3393
3394
3395

3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414



3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3195
3196
3197
3198
3199
3200
3201


3202
3203
3204
3205


3206
3207
3208

3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228

3229
3230
3231
3232
3233
3234
3235
3236
3237

3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250

3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261

3262
3263
3264
3265

3266
3267
3268
3269
3270
3271
3272
3273
3274
3275



3276
3277
3278
3279



3280
3281
3282
3283
3284
3285
3286

3287
3288
3289
3290
3291
3292
3293







-
-
+
+


-
-
+
+

-
+



















-
+








-
+












-
+










-
+



-
+









-
-
-




-
-
-
+
+
+




-







 *	An error condition may arise
 *
 *--------------------------------------------------------------
 */

static int
EntryValidate(
     Entry *entryPtr,	/* Entry that needs validation. */
     char *cmd)	/* Validation command (NULL-terminated
     register Entry *entryPtr,	/* Entry that needs validation. */
     register char *cmd)	/* Validation command (NULL-terminated
				 * string). */
{
    Tcl_Interp *interp = entryPtr->interp;
    int code, isOK;
    register Tcl_Interp *interp = entryPtr->interp;
    int code, bool;

    code = Tcl_EvalEx(interp, cmd, TCL_INDEX_NONE, TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
    code = Tcl_EvalEx(interp, cmd, -1, TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

    /*
     * We accept TCL_OK and TCL_RETURN as valid return codes from the command
     * callback.
     */

    if (code != TCL_OK && code != TCL_RETURN) {
	Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
		"\n    (in validation command executed by %s)",
		Tk_PathName(entryPtr->tkwin)));
	Tcl_BackgroundException(interp, code);
	return TCL_ERROR;
    }

    /*
     * The command callback should return an acceptable Tcl boolean.
     */

    if (Tcl_GetBooleanFromObj(interp, Tcl_GetObjResult(interp),
	    &isOK) != TCL_OK) {
	    &bool) != TCL_OK) {
	Tcl_AddErrorInfo(interp,
		 "\n    (invalid boolean result from validation command)");
	Tcl_BackgroundException(interp, TCL_ERROR);
	Tcl_ResetResult(interp);
	return TCL_ERROR;
    }

    Tcl_ResetResult(interp);
    return (isOK ? TCL_OK : TCL_BREAK);
    return (bool ? TCL_OK : TCL_BREAK);
}

/*
 *--------------------------------------------------------------
 *
 * EntryValidateChange --
 *
 *	This function is invoked when any character is added or removed from
 *	the entry widget, or a focus has trigerred validation.
 *
 * Results:
 *	TCL_OK if the validatecommand accepts the new string, TCL_ERROR if any
 *	problems occurred with validatecommand.
 *	problems occured with validatecommand.
 *
 * Side effects:
 *	The insertion/deletion may be aborted, and the validatecommand might
 *	turn itself off (if an error or loop condition arises).
 *
 *--------------------------------------------------------------
 */

static int
EntryValidateChange(
     Entry *entryPtr,	/* Entry that needs validation. */
     register Entry *entryPtr,	/* Entry that needs validation. */
     const char *change,	/* Characters to be added/deleted
				 * (NUL-terminated string). */
     const char *newValue,	/* Potential new value of entry string */
     Tcl_Size index,			/* index of insert/delete, TCL_INDEX_NONE otherwise */
     int index,			/* index of insert/delete, -1 otherwise */
     int type)			/* forced, delete, insert, focusin or
				 * focusout */
{
    int code, varValidate = (entryPtr->flags & VALIDATE_VAR);
    char *p;
    Tcl_DString script;

    if (entryPtr->validateCmd == NULL ||
	entryPtr->validate == VALIDATE_NONE) {
        if (entryPtr->flags & VALIDATING) {
            entryPtr->flags |= VALIDATE_ABORT;
        }
	return (varValidate ? TCL_ERROR : TCL_OK);
    }

    /*
     * If we're already validating, then we're hitting a loop condition. Set
     * validate to none to disallow further validations, arrange for flags
     * to prevent current validation from finishing, and return.
     * If we're already validating, then we're hitting a loop condition Return
     * and set validate to 0 to disallow further validations and prevent
     * current validation from finishing
     */

    if (entryPtr->flags & VALIDATING) {
	entryPtr->validate = VALIDATE_NONE;
        entryPtr->flags |= VALIDATE_ABORT;
	return (varValidate ? TCL_ERROR : TCL_OK);
    }

    entryPtr->flags |= VALIDATING;

    /*
     * Now form command string and run through the -validatecommand
3434
3435
3436
3437
3438
3439
3440
3441

3442
3443
3444
3445
3446
3447
3448
3301
3302
3303
3304
3305
3306
3307

3308
3309
3310
3311
3312
3313
3314
3315







-
+







    p = Tcl_DStringValue(&script);
    code = EntryValidate(entryPtr, p);
    Tcl_DStringFree(&script);

    /*
     * If e->validate has become VALIDATE_NONE during the validation, or we
     * now have VALIDATE_VAR set (from EntrySetValue) and didn't before, it
     * means that a loop condition almost occurred. Do not allow this
     * means that a loop condition almost occured. Do not allow this
     * validation result to finish.
     */

    if (entryPtr->validate == VALIDATE_NONE
	    || (!varValidate && (entryPtr->flags & VALIDATE_VAR))) {
	code = TCL_ERROR;
    }
3479
3480
3481
3482
3483
3484
3485
3486

3487
3488
3489
3490
3491
3492
3493
3346
3347
3348
3349
3350
3351
3352

3353
3354
3355
3356
3357
3358
3359
3360







-
+







	    int result;

	    Tcl_DStringInit(&script);
	    ExpandPercents(entryPtr, entryPtr->invalidCmd,
		    change, newValue, index, type, &script);
	    Tcl_DStringAppend(&script, "", 1);
	    p = Tcl_DStringValue(&script);
	    result = Tcl_EvalEx(entryPtr->interp, p, TCL_INDEX_NONE,
	    result = Tcl_EvalEx(entryPtr->interp, p, -1,
		    TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
	    if (result != TCL_OK) {
		Tcl_AddErrorInfo(entryPtr->interp,
			"\n    (in invalidcommand executed by entry)");
		Tcl_BackgroundException(entryPtr->interp, result);
		code = TCL_ERROR;
		entryPtr->validate = VALIDATE_NONE;
3527
3528
3529
3530
3531
3532
3533
3534
3535


3536
3537
3538
3539
3540
3541

3542
3543
3544
3545
3546
3547
3548
3549

3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570

3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583

3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603

3604
3605
3606
3607
3608
3609
3610
3394
3395
3396
3397
3398
3399
3400


3401
3402
3403
3404
3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3415

3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436

3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449

3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469

3470
3471
3472
3473
3474
3475
3476
3477







-
-
+
+





-
+







-
+




















-
+












-
+



















-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static void
ExpandPercents(
     Entry *entryPtr,	/* Entry that needs validation. */
     const char *before,
     register Entry *entryPtr,	/* Entry that needs validation. */
     register const char *before,
				/* Command containing percent expressions to
				 * be replaced. */
     const char *change,	/* Characters to added/deleted (NUL-terminated
				 * string). */
     const char *newValue,	/* Potential new value of entry string */
     Tcl_Size index,			/* index of insert/delete */
     int index,			/* index of insert/delete */
     int type,			/* INSERT or DELETE */
     Tcl_DString *dsPtr)	/* Dynamic string in which to append new
				 * command. */
{
    int spaceNeeded, cvtFlags;	/* Used to substitute string as proper Tcl
				 * list element. */
    int number, length;
    const char *string;
    register const char *string;
    int ch;
    char numStorage[2*TCL_INTEGER_SPACE];

    while (1) {
	if (*before == '\0') {
	    break;
	}
	/*
	 * Find everything up to the next % character and append it to the
	 * result string.
	 */

	string = before;

	/*
	 * No need to convert '%', as it is in ascii range.
	 */

	string = Tcl_UtfFindFirst(before, '%');
	if (string == NULL) {
	    Tcl_DStringAppend(dsPtr, before, TCL_INDEX_NONE);
	    Tcl_DStringAppend(dsPtr, before, -1);
	    break;
	} else if (string != before) {
	    Tcl_DStringAppend(dsPtr, before, string-before);
	    before = string;
	}

	/*
	 * There's a percent sequence here. Process it.
	 */

	before++; /* skip over % */
	if (*before != '\0') {
	    before += Tcl_UtfToUniChar(before, &ch);
	    before += TkUtfToUniChar(before, &ch);
	} else {
	    ch = '%';
	}
	if (type == VALIDATE_BUTTON) {
	    /*
	     * -command %-substitution
	     */

	    switch (ch) {
	    case 's':		/* Current string value of spinbox */
		string = entryPtr->string;
		break;
	    case 'd':		/* direction, up or down */
		string = change;
		break;
	    case 'W':		/* widget name */
		string = Tk_PathName(entryPtr->tkwin);
		break;
	    default:
		length = Tcl_UniCharToUtf(ch, numStorage);
		length = TkUniCharToUtf(ch, numStorage);
		numStorage[length] = '\0';
		string = numStorage;
		break;
	    }
	} else {
	    /*
	     * -validatecommand / -invalidcommand %-substitution
3619
3620
3621
3622
3623
3624
3625
3626

3627
3628
3629
3630

3631
3632
3633
3634
3635
3636
3637
3486
3487
3488
3489
3490
3491
3492

3493
3494
3495
3496

3497
3498
3499
3500
3501
3502
3503
3504







-
+



-
+







		case VALIDATE_DELETE:
		    number = 0;
		    break;
		default:
		    number = -1;
		    break;
		}
		snprintf(numStorage, sizeof(numStorage), "%d", number);
		sprintf(numStorage, "%d", number);
		string = numStorage;
		break;
	    case 'i':		/* index of insert/delete */
		snprintf(numStorage, sizeof(numStorage), "%d", (int)index);
		sprintf(numStorage, "%d", index);
		string = numStorage;
		break;
	    case 'P':		/* 'Peeked' new value of the string */
		string = newValue;
		break;
	    case 's':		/* Current string value of spinbox */
		string = entryPtr->string;
3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666
3667
3668
3669
3670

3671
3672
3673

3674
3675
3676
3677
3678
3679
3680
3523
3524
3525
3526
3527
3528
3529

3530
3531
3532
3533
3534
3535
3536

3537
3538
3539

3540
3541
3542
3543
3544
3545
3546
3547







-
+






-
+


-
+







		    break;
		}
		break;
	    case 'W': /* widget name */
		string = Tk_PathName(entryPtr->tkwin);
		break;
	    default:
		length = Tcl_UniCharToUtf(ch, numStorage);
		length = TkUniCharToUtf(ch, numStorage);
		numStorage[length] = '\0';
		string = numStorage;
		break;
	    }
	}

	spaceNeeded = Tcl_ScanCountedElement(string, TCL_INDEX_NONE, &cvtFlags);
	spaceNeeded = Tcl_ScanCountedElement(string, -1, &cvtFlags);
	length = Tcl_DStringLength(dsPtr);
	Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
	spaceNeeded = Tcl_ConvertCountedElement(string, TCL_INDEX_NONE,
	spaceNeeded = Tcl_ConvertCountedElement(string, -1,
		Tcl_DStringValue(dsPtr) + length,
		cvtFlags | TCL_DONT_USE_BRACES);
	Tcl_DStringSetLength(dsPtr, length + spaceNeeded);
    }
}

/*
3692
3693
3694
3695
3696
3697
3698
3699

3700
3701
3702
3703
3704
3705


3706
3707
3708
3709
3710
3711
3712
3559
3560
3561
3562
3563
3564
3565

3566
3567
3568
3569
3570


3571
3572
3573
3574
3575
3576
3577
3578
3579







-
+




-
-
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_SpinboxObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Entry *entryPtr;
    Spinbox *sbPtr;
    register Entry *entryPtr;
    register Spinbox *sbPtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;
    char *tmp;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
3728
3729
3730
3731
3732
3733
3734
3735

3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747

3748
3749
3750
3751


3752
3753

3754
3755
3756
3757
3758
3759
3760
3761
3762



3763
3764
3765
3766
3767
3768

3769
3770
3771
3772
3773
3774

3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795

3796
3797
3798
3799
3800
3801
3802
3803
3804

3805
3806
3807
3808
3809
3810
3811
3595
3596
3597
3598
3599
3600
3601

3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613

3614
3615
3616


3617
3618
3619

3620
3621
3622
3623
3624
3625
3626



3627
3628
3629
3630
3631
3632
3633
3634

3635
3636
3637
3638
3639
3640

3641
3642
3643
3644


3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659

3660
3661
3662
3663
3664
3665
3666
3667
3668

3669
3670
3671
3672
3673
3674
3675
3676







-
+











-
+


-
-
+
+

-
+






-
-
-
+
+
+





-
+





-
+



-
-















-
+








-
+







    /*
     * Initialize the fields of the structure that won't be initialized by
     * ConfigureEntry, or that ConfigureEntry requires to be initialized
     * already (e.g. resource pointers). Only the non-NULL/0 data must be
     * initialized as memset covers the rest.
     */

    sbPtr = (Spinbox *)ckalloc(sizeof(Spinbox));
    sbPtr = ckalloc(sizeof(Spinbox));
    entryPtr			= (Entry *) sbPtr;
    memset(sbPtr, 0, sizeof(Spinbox));

    entryPtr->tkwin		= tkwin;
    entryPtr->display		= Tk_Display(tkwin);
    entryPtr->interp		= interp;
    entryPtr->widgetCmd		= Tcl_CreateObjCommand(interp,
	    Tk_PathName(entryPtr->tkwin), SpinboxWidgetObjCmd, sbPtr,
	    EntryCmdDeletedProc);
    entryPtr->optionTable	= optionTable;
    entryPtr->type		= TK_SPINBOX;
    tmp				= (char *)ckalloc(1);
    tmp				= ckalloc(1);
    tmp[0]			= '\0';
    entryPtr->string		= tmp;
    entryPtr->selectFirst	= TCL_INDEX_NONE;
    entryPtr->selectLast	= TCL_INDEX_NONE;
    entryPtr->selectFirst	= -1;
    entryPtr->selectLast	= -1;

    entryPtr->cursor		= NULL;
    entryPtr->cursor		= None;
    entryPtr->exportSelection	= 1;
    entryPtr->justify		= TK_JUSTIFY_LEFT;
    entryPtr->relief		= TK_RELIEF_FLAT;
    entryPtr->state		= STATE_NORMAL;
    entryPtr->displayString	= entryPtr->string;
    entryPtr->inset		= XPAD;
    entryPtr->textGC		= NULL;
    entryPtr->selTextGC		= NULL;
    entryPtr->highlightGC	= NULL;
    entryPtr->textGC		= None;
    entryPtr->selTextGC		= None;
    entryPtr->highlightGC	= None;
    entryPtr->avgWidth		= 1;
    entryPtr->validate		= VALIDATE_NONE;

    sbPtr->selElement		= SEL_NONE;
    sbPtr->curElement		= SEL_NONE;
    sbPtr->bCursor		= NULL;
    sbPtr->bCursor		= None;
    sbPtr->repeatDelay		= 400;
    sbPtr->repeatInterval	= 100;
    sbPtr->fromValue		= 0.0;
    sbPtr->toValue		= 100.0;
    sbPtr->increment		= 1.0;
    sbPtr->formatBuf		= (char *)ckalloc(TCL_DOUBLE_SPACE);
    sbPtr->formatBuf		= ckalloc(TCL_DOUBLE_SPACE);
    sbPtr->bdRelief		= TK_RELIEF_FLAT;
    sbPtr->buRelief		= TK_RELIEF_FLAT;

    entryPtr->placeholderGC	= NULL;

    /*
     * Keep a hold of the associated tkwin until we destroy the spinbox,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(entryPtr->tkwin);

    Tk_SetClass(entryPtr->tkwin, "Spinbox");
    Tk_SetClassProcs(entryPtr->tkwin, &entryClass, entryPtr);
    Tk_CreateEventHandler(entryPtr->tkwin,
	    PointerMotionMask|ExposureMask|StructureNotifyMask|FocusChangeMask,
	    EntryEventProc, entryPtr);
    Tk_CreateSelHandler(entryPtr->tkwin, XA_PRIMARY, XA_STRING,
	    EntryFetchSelection, entryPtr, XA_STRING);

    if (Tk_InitOptions(interp, sbPtr, optionTable, tkwin)
    if (Tk_InitOptions(interp, (char *) sbPtr, optionTable, tkwin)
	    != TCL_OK) {
	Tk_DestroyWindow(entryPtr->tkwin);
	return TCL_ERROR;
    }
    if (ConfigureEntry(interp, entryPtr, objc-2, objv+2) != TCL_OK) {
	goto error;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(entryPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(entryPtr->tkwin));
    return TCL_OK;

  error:
    Tk_DestroyWindow(entryPtr->tkwin);
    return TCL_ERROR;
}

3825
3826
3827
3828
3829
3830
3831
3832

3833
3834
3835
3836
3837
3838


3839
3840
3841
3842
3843
3844
3845
3690
3691
3692
3693
3694
3695
3696

3697
3698
3699
3700
3701


3702
3703
3704
3705
3706
3707
3708
3709
3710







-
+




-
-
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
SpinboxWidgetObjCmd(
    void *clientData,	/* Information about spinbox widget. */
    ClientData clientData,	/* Information about spinbox widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Entry *entryPtr = (Entry *)clientData;
    Spinbox *sbPtr = (Spinbox *)clientData;
    Entry *entryPtr = clientData;
    Spinbox *sbPtr = clientData;
    int cmdIndex, selIndex, result;
    Tcl_Obj *objPtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
3854
3855
3856
3857
3858
3859
3860
3861
3862

3863
3864
3865
3866
3867
3868
3869

3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880




3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891

3892
3893
3894
3895
3896
3897
3898
3899
3900
3901

3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914

3915
3916
3917
3918
3919
3920
3921

3922
3923
3924
3925
3926
3927
3928

3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947

3948
3949
3950
3951
3952
3953
3954
3955

3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976

3977
3978
3979
3980
3981
3982

3983
3984
3985
3986
3987
3988

3989
3990
3991
3992

3993
3994
3995
3996
3997

3998
3999
4000
4001
4002
4003
4004

4005
4006
4007
4008
4009
4010
4011
3719
3720
3721
3722
3723
3724
3725


3726
3727
3728
3729
3730
3731
3732

3733
3734
3735
3736
3737
3738
3739
3740




3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754

3755
3756
3757
3758
3759
3760
3761
3762
3763
3764

3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777

3778

3779
3780
3781
3782
3783

3784
3785
3786
3787
3788
3789
3790

3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809

3810
3811
3812
3813
3814
3815
3816
3817

3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838

3839
3840
3841
3842
3843
3844

3845
3846
3847
3848
3849
3850

3851
3852
3853
3854

3855
3856
3857
3858
3859

3860

3861
3862
3863
3864
3865

3866
3867
3868
3869
3870
3871
3872
3873







-
-
+






-
+







-
-
-
-
+
+
+
+










-
+









-
+












-
+
-





-
+






-
+


















-
+







-
+




















-
+





-
+





-
+



-
+




-
+
-





-
+







    if (result != TCL_OK) {
	return result;
    }

    Tcl_Preserve(entryPtr);
    switch ((enum sbCmd) cmdIndex) {
    case SB_CMD_BBOX: {
	Tcl_Size index;
	int x, y, width, height;
	int index, x, y, width, height;
	Tcl_Obj *bbox[4];

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	if ((index == entryPtr->numChars) && (index > 0)) {
	    index--;
	}
	Tk_CharBbox(entryPtr->textLayout, index, &x, &y, &width, &height);
	bbox[0] = Tcl_NewWideIntObj(x + entryPtr->layoutX);
	bbox[1] = Tcl_NewWideIntObj(y + entryPtr->layoutY);
	bbox[2] = Tcl_NewWideIntObj(width);
	bbox[3] = Tcl_NewWideIntObj(height);
	bbox[0] = Tcl_NewIntObj(x + entryPtr->layoutX);
	bbox[1] = Tcl_NewIntObj(y + entryPtr->layoutY);
	bbox[2] = Tcl_NewIntObj(width);
	bbox[3] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(4, bbox));
	break;
    }

    case SB_CMD_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    goto error;
	}

	objPtr = Tk_GetOptionValue(interp, entryPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) entryPtr,
		entryPtr->optionTable, objv[2], entryPtr->tkwin);
	if (objPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;

    case SB_CMD_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, entryPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) entryPtr,
		    entryPtr->optionTable, (objc == 3) ? objv[2] : NULL,
		    entryPtr->tkwin);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
	    result = ConfigureEntry(interp, entryPtr, objc-2, objv+2);
	}
	break;

    case SB_CMD_DELETE: {
	Tcl_Size first, last;
	int first, last, code;
	int code;

	if ((objc < 3) || (objc > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&first) != TCL_OK) {
	    goto error;
	}
	if (objc == 3) {
	    last = first + 1;
	} else {
	    if (GetEntryIndex(interp, entryPtr, objv[3],
	    if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[3]),
		    &last) != TCL_OK) {
		goto error;
	    }
	}
	if ((last >= first) && (entryPtr->state == STATE_NORMAL)) {
	    code = DeleteChars(entryPtr, first, last - first);
            if (code != TCL_OK) {
                goto error;
            }
	}
	break;
    }

    case SB_CMD_GET:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    goto error;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
	break;

    case SB_CMD_ICURSOR:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "pos");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&entryPtr->insertPos) != TCL_OK) {
	    goto error;
	}
	EventuallyRedraw(entryPtr);
	break;

    case SB_CMD_IDENTIFY: {
	int x, y, elem;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "x y");
	    goto error;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK) ||
		(Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	    goto error;
	}
	elem = GetSpinboxElement(sbPtr, x, y);
	if (elem != SEL_NONE) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(selElementNames[elem], TCL_INDEX_NONE));
		    Tcl_NewStringObj(selElementNames[elem], -1));
	}
	break;
    }

    case SB_CMD_INDEX: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "string");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	break;
    }

    case SB_CMD_INSERT: {
	Tcl_Size index;
	int index, code;
	int code;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index text");
	    goto error;
	}
	if (GetEntryIndex(interp, entryPtr, objv[2],
	if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		&index) != TCL_OK) {
	    goto error;
	}
	if (entryPtr->state == STATE_NORMAL) {
	    code = InsertChars(entryPtr, index, Tcl_GetString(objv[3]));
            if (code != TCL_OK) {
                goto error;
4049
4050
4051
4052
4053
4054
4055
4056

4057
4058
4059
4060
4061
4062
4063
4064
4065
4066

4067
4068
4069
4070
4071
4072
4073
3911
3912
3913
3914
3915
3916
3917

3918
3919
3920
3921
3922
3923
3924
3925
3926
3927

3928
3929
3930
3931
3932
3933
3934
3935







-
+









-
+







	    entryPtr->scanMarkX = x;
	    entryPtr->scanMarkIndex = entryPtr->leftIndex;
	} else if ((minorCmd[0] == 'd')
		&& (strncmp(minorCmd, "dragto", strlen(minorCmd)) == 0)) {
	    EntryScanTo(entryPtr, x);
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad scan option \"%s\": must be dragto or mark",
		    "bad scan option \"%s\": must be mark or dragto",
		    minorCmd));
	    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "scan option",
		    minorCmd, NULL);
	    goto error;
	}
	break;
    }

    case SB_CMD_SELECTION: {
	Tcl_Size index, index2;
	int index, index2;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option ?index?");
	    goto error;
	}

	/*
4094
4095
4096
4097
4098
4099
4100
4101

4102
4103
4104
4105


4106
4107
4108
4109
4110
4111
4112
3956
3957
3958
3959
3960
3961
3962

3963
3964
3965


3966
3967
3968
3969
3970
3971
3972
3973
3974







-
+


-
-
+
+







	switch (selIndex) {
	case SB_SEL_ADJUST:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    if (entryPtr->selectFirst != TCL_INDEX_NONE) {
		Tcl_Size half1, half2;
	    if (entryPtr->selectFirst >= 0) {
		int half1, half2;

		half1 = (entryPtr->selectFirst + entryPtr->selectLast)/2;
		half2 = (entryPtr->selectFirst + entryPtr->selectLast + 1)/2;
		if (index < half1) {
		    entryPtr->selectAnchor = entryPtr->selectLast;
		} else if (index > half2) {
		    entryPtr->selectAnchor = entryPtr->selectFirst;
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130



4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141

4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153

4154
4155
4156
4157
4158
4159
4160
4161
4162

4163
4164
4165
4166

4167
4168
4169
4170
4171


4172
4173
4174
4175
4176
4177

4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192

4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205

4206
4207
4208
4209
4210
4211
4212
3983
3984
3985
3986
3987
3988
3989



3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002

4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014

4015
4016
4017
4018
4019
4020
4021
4022
4023

4024
4025
4026
4027

4028
4029
4030
4031


4032
4033
4034
4035
4036
4037
4038

4039

4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052

4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065

4066
4067
4068
4069
4070
4071
4072
4073







-
-
-
+
+
+










-
+











-
+








-
+



-
+



-
-
+
+





-
+
-













-
+












-
+







	    break;

	case SB_SEL_CLEAR:
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, NULL);
		goto error;
	    }
	    if (entryPtr->selectFirst != TCL_INDEX_NONE) {
		entryPtr->selectFirst = TCL_INDEX_NONE;
		entryPtr->selectLast = TCL_INDEX_NONE;
	    if (entryPtr->selectFirst >= 0) {
		entryPtr->selectFirst = -1;
		entryPtr->selectLast = -1;
		EventuallyRedraw(entryPtr);
	    }
	    goto done;

	case SB_SEL_FROM:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    entryPtr->selectAnchor = index;
	    break;

	case SB_SEL_PRESENT:
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, NULL);
		goto error;
	    }
	    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		    entryPtr->selectFirst != TCL_INDEX_NONE));
		    entryPtr->selectFirst >= 0));
	    goto done;

	case SB_SEL_RANGE:
	    if (objc != 5) {
		Tcl_WrongNumArgs(interp, 3, objv, "start end");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[4],& index2) != TCL_OK) {
		    Tcl_GetString(objv[4]),& index2) != TCL_OK) {
		goto error;
	    }
	    if (index >= index2) {
		entryPtr->selectFirst = TCL_INDEX_NONE;
		entryPtr->selectLast = TCL_INDEX_NONE;
		entryPtr->selectFirst = -1;
		entryPtr->selectLast = -1;
	    } else {
		entryPtr->selectFirst = index;
		entryPtr->selectLast = index2;
	    }
	    if (!(entryPtr->flags & GOT_SELECTION)
		    && entryPtr->exportSelection
		    && entryPtr->exportSelection) {
		    && (!Tcl_IsSafe(entryPtr->interp))) {
		Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY,
			EntryLostSelection, entryPtr);
		entryPtr->flags |= GOT_SELECTION;
	    }
	    EventuallyRedraw(entryPtr);
	    break;

	case SB_SEL_TO:
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "index");
		goto error;
	    }
	    if (GetEntryIndex(interp, entryPtr,
		    objv[3], &index) != TCL_OK) {
		    Tcl_GetString(objv[3]), &index) != TCL_OK) {
		goto error;
	    }
	    EntrySelectTo(entryPtr, index);
	    break;

	case SB_SEL_ELEMENT:
	    if ((objc < 3) || (objc > 4)) {
		Tcl_WrongNumArgs(interp, 3, objv, "?elemName?");
		goto error;
	    }
	    if (objc == 3) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			selElementNames[sbPtr->selElement], TCL_INDEX_NONE));
			selElementNames[sbPtr->selElement], -1));
	    } else {
		int lastElement = sbPtr->selElement;

		result = Tcl_GetIndexFromObj(interp, objv[3], selElementNames,
			"selection element", 0, &(sbPtr->selElement));
		if (result != TCL_OK) {
		    goto error;
4229
4230
4231
4232
4233
4234
4235
4236

4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250

4251
4252
4253
4254
4255
4256
4257
4258
4259
4260

4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272

4273
4274
4275
4276
4277
4278
4279
4280
4281
4282


4283
4284

4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4090
4091
4092
4093
4094
4095
4096

4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110

4111
4112
4113
4114
4115
4116
4117
4118
4119
4120

4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132

4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146

4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163


4164
4165
4166
4167
4168
4169
4170







-
+













-
+









-
+











-
+










+
+

-
+
















-
-







	}
	if (objc == 3) {
	    code = EntryValueChanged(entryPtr, Tcl_GetString(objv[2]));
            if (code != TCL_OK) {
                goto error;
            }
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
	break;
    }

    case SB_CMD_VALIDATE: {
	int code;

	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    goto error;
	}
	selIndex = entryPtr->validate;
	entryPtr->validate = VALIDATE_ALL;
	code = EntryValidateChange(entryPtr, NULL, entryPtr->string,
		TCL_INDEX_NONE, VALIDATE_FORCED);
		-1, VALIDATE_FORCED);
	if (entryPtr->validate != VALIDATE_NONE) {
	    entryPtr->validate = selIndex;
	}

	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(code == TCL_OK));
	break;
    }

    case SB_CMD_XVIEW: {
	Tcl_Size index;
	int index;

	if (objc == 2) {
	    double first, last;
	    Tcl_Obj *span[2];

	    EntryVisibleRange(entryPtr, &first, &last);
	    span[0] = Tcl_NewDoubleObj(first);
	    span[1] = Tcl_NewDoubleObj(last);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, span));
	    goto done;
	} else if (objc == 3) {
	    if (GetEntryIndex(interp, entryPtr, objv[2],
	    if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
		    &index) != TCL_OK) {
		goto error;
	    }
	} else {
	    double fraction;
	    int count;

	    index = entryPtr->leftIndex;
	    switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction,
		    &count)) {
	    case TK_SCROLL_ERROR:
		goto error;
	    case TK_SCROLL_MOVETO:
		index = ((fraction * entryPtr->numChars) + 0.5);
		index = (int) ((fraction * entryPtr->numChars) + 0.5);
		break;
	    case TK_SCROLL_PAGES: {
		int charsPerPage;

		charsPerPage = ((Tk_Width(entryPtr->tkwin)
			- 2 * entryPtr->inset - entryPtr->xWidth)
			/ entryPtr->avgWidth) - 2;
		if (charsPerPage < 1) {
		    charsPerPage = 1;
		}
		index += count * charsPerPage;
		break;
	    }
	    case TK_SCROLL_UNITS:
		index += count;
		break;
	    default:
		goto error;
	    }
	}
	if (index >= entryPtr->numChars) {
	    index = entryPtr->numChars - 1;
	}
	if (index < 0) {
	    index = 0;
4380
4381
4382
4383
4384
4385
4386
4387
4388


4389
4390
4391
4392
4393
4394
4395
4241
4242
4243
4244
4245
4246
4247


4248
4249
4250
4251
4252
4253
4254
4255
4256







-
-
+
+







 *	The widget value may change.
 *
 *--------------------------------------------------------------
 */

static int
SpinboxInvoke(
    Tcl_Interp *interp,/* Current interpreter. */
    Spinbox *sbPtr,	/* Spinbox to invoke. */
    register Tcl_Interp *interp,/* Current interpreter. */
    register Spinbox *sbPtr,	/* Spinbox to invoke. */
    int element)		/* Element to invoke, either the "up" or
				 * "down" button. */
{
    Entry *entryPtr = (Entry *) sbPtr;
    const char *type;
    int code, up;
    Tcl_DString script;
4416
4417
4418
4419
4420
4421
4422
4423
4424

4425
4426
4427
4428
4429
4430
4431
4432
4433

4434
4435
4436
4437
4438
4439
4440
4277
4278
4279
4280
4281
4282
4283


4284
4285
4286
4287
4288
4289
4290
4291
4292

4293
4294
4295
4296
4297
4298
4299
4300







-
-
+








-
+







	    if (strcmp(Tcl_GetString(objPtr), entryPtr->string)) {
		/*
		 * Somehow the string changed from what we expected, so let's
		 * do a search on the list to see if the current value is
		 * there. If not, move to the first element of the list.
		 */

		Tcl_Size i, listc;
		Tcl_Size elemLen, length = entryPtr->numChars;
		int i, listc, elemLen, length = entryPtr->numChars;
		const char *bytes;
		Tcl_Obj **listv;

		Tcl_ListObjGetElements(interp, sbPtr->listObj, &listc, &listv);
		for (i = 0; i < listc; i++) {
		    bytes = Tcl_GetStringFromObj(listv[i], &elemLen);
		    if ((length == elemLen) &&
			    (memcmp(bytes, entryPtr->string,
				    length) == 0)) {
				    (size_t) length) == 0)) {
			sbPtr->eIndex = i;
			break;
		    }
		}
	    }
	    if (up) {
		if (++sbPtr->eIndex >= sbPtr->nElements) {
4496
4497
4498
4499
4500
4501
4502
4503

4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517

4518
4519
4520
4521
4522
4523
4524
4356
4357
4358
4359
4360
4361
4362

4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376

4377
4378
4379
4380
4381
4382
4383
4384







-
+













-
+







		     * greater than the toValue, because the user may have
		     * manipulated the value by hand.
		     */

		    dvalue = sbPtr->toValue;
		}
	    }
	    snprintf(sbPtr->formatBuf, TCL_DOUBLE_SPACE, sbPtr->valueFormat, dvalue);
	    sprintf(sbPtr->formatBuf, sbPtr->valueFormat, dvalue);
	    code = EntryValueChanged(entryPtr, sbPtr->formatBuf);
	}
    }
    if (code != TCL_OK) {
        return TCL_ERROR;
    }

    if (sbPtr->command != NULL) {
	Tcl_DStringInit(&script);
	ExpandPercents(entryPtr, sbPtr->command, type, "", 0,
		VALIDATE_BUTTON, &script);
	Tcl_DStringAppend(&script, "", 1);

	code = Tcl_EvalEx(interp, Tcl_DStringValue(&script), TCL_INDEX_NONE,
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&script), -1,
		TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
	Tcl_DStringFree(&script);

	if (code != TCL_OK) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (in command executed by spinbox)");
	    Tcl_BackgroundException(interp, code);
4613
4614
4615
4616
4617
4618
4619
4620

4621
4622

4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4473
4474
4475
4476
4477
4478
4479

4480
4481

4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494







-
+

-
+












    if (afterDecimal > 0) {
	fDigits++;		/* Decimal point. */
    }
    if (mostSigDigit < 0) {
	fDigits++;		/* Zero to left of decimal point. */
    }
    if (fDigits <= eDigits) {
	snprintf(sbPtr->digitFormat, sizeof(sbPtr->digitFormat), "%%.%df", afterDecimal);
	sprintf(sbPtr->digitFormat, "%%.%df", afterDecimal);
    } else {
	snprintf(sbPtr->digitFormat, sizeof(sbPtr->digitFormat), "%%.%de", numDigits-1);
	sprintf(sbPtr->digitFormat, "%%.%de", numDigits-1);
    }
    sbPtr->valueFormat = sbPtr->digitFormat;
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkEntry.h.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 *  tkEntry.h --
 *
 * This module defined the structures for the Entry & SpinBox widgets.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * Copyright © 2002 Apple Inc.
 * Copyright (c) 2002 Apple Inc.
 */

#ifndef _TKENTRY
#define _TKENTRY

#ifndef _TKINT
#include "tkInt.h"
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55

56
57

58
59

60
61
62
63
64
65
66
41
42
43
44
45
46
47

48
49
50
51
52
53
54

55
56

57
58

59
60
61
62
63
64
65
66







-
+






-
+

-
+

-
+








    /*
     * Fields that are set by widget commands other than "configure".
     */

    const char *string;		/* Pointer to storage for string;
				 * NULL-terminated; malloc-ed. */
    Tcl_Size insertPos;		/* Character index before which next typed
    int insertPos;		/* Character index before which next typed
				 * character will be inserted. */

    /*
     * Information about what's selected, if any.
     */

    Tcl_Size selectFirst;		/* Character index of first selected character
    int selectFirst;		/* Character index of first selected character
				 * (-1 means nothing selected. */
    Tcl_Size selectLast;		/* Character index just after last selected
    int selectLast;		/* Character index just after last selected
				 * character (-1 means nothing selected. */
    Tcl_Size selectAnchor;		/* Fixed end of selection (i.e. "select to"
    int selectAnchor;		/* Fixed end of selection (i.e. "select to"
				 * operation will use this as one end of the
				 * selection). */

    /*
     * Information for scanning:
     */

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+







    Tk_3DBorder disabledBorder;	/* Used for drawing border around whole window
				 * in disabled state, plus used for
				 * background. */
    Tk_3DBorder readonlyBorder;	/* Used for drawing border around whole window
				 * in readonly state, plus used for
				 * background. */
    int borderWidth;		/* Width of 3-D border around window. */
    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    int exportSelection;	/* Non-zero means tie internal entry selection
				 * to X selection. */
    Tk_Font tkfont;		/* Information about text font, or NULL. */
    XColor *fgColorPtr;		/* Text color in normal mode. */
    XColor *dfgColorPtr;	/* Text color in disabled mode. */
    XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area
				 * when highlight is off. */
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155


156
157
158
159
160

161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
124
125
126
127
128
129
130













131
132
133
134
135
136
137
138
139
140


141
142
143
144
145
146

147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
+
+




-
+








-
+







				 * scrollbar(s). Malloc'ed. NULL means no
				 * command to issue. */
    char *showChar;		/* Value of -show option. If non-NULL, first
				 * character is used for displaying all
				 * characters in entry. Malloc'ed. This is
				 * only used by the Entry widget. */

    /*
     * Fields used in displaying help text if entry value is empty
     */

    Tk_TextLayout placeholderLayout;/* Cached placeholder text layout information. */
    char *placeholderString;	/* String value of placeholder. */
    Tcl_Size placeholderChars;	/* Number of chars in placeholder. */
    XColor *placeholderColorPtr;/* Color value of placeholder foreground. */
    GC placeholderGC;		/* For drawing placeholder text. */
    int placeholderX;		/* Origin for layout. */
    int placeholderLeftIndex;	/* Character index of left-most character
				 * visible in window. */

    /*
     * Fields whose values are derived from the current values of the
     * configuration settings above.
     */

    const char *displayString;	/* String to use when displaying. This may be
				 * a pointer to string, or a pointer to
				 * malloced memory with the same character
				 * length as string but whose characters are
				 * all equal to showChar. */
    Tcl_Size numBytes;		/* Length of string in bytes. */
    Tcl_Size numChars;		/* Length of string in characters. Both string
    int numBytes;		/* Length of string in bytes. */
    int numChars;		/* Length of string in characters. Both string
				 * and displayString have the same character
				 * length, but may have different byte lengths
				 * due to being made from different UTF-8
				 * characters. */
    Tcl_Size numDisplayBytes;	/* Length of displayString in bytes. */
    int numDisplayBytes;	/* Length of displayString in bytes. */
    int inset;			/* Number of pixels on the left and right
				 * sides that are taken up by XPAD,
				 * borderWidth (if any), and highlightWidth
				 * (if any). */
    Tk_TextLayout textLayout;	/* Cached text layout information. */
    int layoutX, layoutY;	/* Origin for layout. */
    int leftX;			/* X position at which character at leftIndex
				 * is drawn (varies depending on justify). */
    Tcl_Size leftIndex;		/* Character index of left-most character
    int leftIndex;		/* Character index of left-most character
				 * visible in window. */
    Tcl_TimerToken insertBlinkHandler;
				/* Timer handler used to blink cursor on and
				 * off. */
    GC textGC;			/* For drawing normal text. */
    GC selTextGC;		/* For drawing selected text. */
    GC highlightGC;		/* For drawing traversal highlight. */
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+







    /*
     * Spinbox specific configuration settings.
     */

    Tk_3DBorder activeBorder;	/* Used for drawing border around active
				 * buttons. */
    Tk_3DBorder buttonBorder;	/* Used for drawing border around buttons. */
    Tk_Cursor bCursor;		/* cursor for buttons, or NULL. */
    Tk_Cursor bCursor;		/* cursor for buttons, or None. */
    int bdRelief;		/* 3-D effect: TK_RELIEF_RAISED, etc. */
    int buRelief;		/* 3-D effect: TK_RELIEF_RAISED, etc. */
    char *command;		/* Command to invoke for spin buttons. NULL
				 * means no command to issue. */

    /*
     * Spinbox specific fields for use with configuration settings above.
226
227
228
229
230
231
232
233

234
235

236
237

238
239
240
241
242
243
244
213
214
215
216
217
218
219

220
221

222
223

224
225
226
227
228
229
230
231







-
+

-
+

-
+







    double fromValue;		/* Value corresponding to left/top of dial */
    double toValue;		/* Value corresponding to right/bottom of
				 * dial */
    double increment;		/* If > 0, all values are rounded to an even
				 * multiple of this value. */
    char *formatBuf;		/* string into which to format value.
				 * Malloc'ed. */
    char *reqFormat;		/* Snprintf conversion specifier used for the
    char *reqFormat;		/* Sprintf conversion specifier used for the
				 * value that the users requests. Malloc'ed */
    char *valueFormat;		/* Snprintf conversion specifier used for the
    char *valueFormat;		/* Sprintf conversion specifier used for the
				 * value. */
    char digitFormat[16];	/* Snprintf conversion specifier computed from
    char digitFormat[10];	/* Sprintf conversion specifier computed from
				 * digits and other information; used for the
				 * value. */

    char *valueStr;		/* Values List. Malloc'ed. */
    Tcl_Obj *listObj;		/* Pointer to the list object being used */
    int eIndex;			/* Holds the current index into elements */
    int nElements;		/* Holds the current count of elements */
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294
295
296
297
298







-
+













/*
 * This is the element index corresponding to the strings in selElementNames.
 * If you modify them, you must modify the numbers here.
 */

enum selelement {
    SEL_BUTTONDOWN, SEL_BUTTONUP, SEL_NONE, SEL_NULL, SEL_ENTRY
    SEL_NONE, SEL_BUTTONDOWN, SEL_BUTTONUP, SEL_NULL, SEL_ENTRY
};

/*
 * Declaration of functions used in the implementation of the native side of
 * the Entry widget.
 */

MODULE_SCOPE int	TkpDrawEntryBorderAndFocus(Entry *entryPtr,
			    Drawable d, int isSpinbox);
MODULE_SCOPE int	TkpDrawSpinboxButtons(Spinbox *sbPtr, Drawable d);

#endif /* _TKENTRY */

Changes to generic/tkError.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17








-
-
+
+







/*
 * tkError.c --
 *
 *	This file provides a high-performance mechanism for selectively
 *	dealing with errors that occur in talking to the X server. This is
 *	useful, for example, when communicating with a window that may not
 *	exist.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

78
79
80
81
82
83
84
85
86


87
88
89
90
91
92
93
78
79
80
81
82
83
84


85
86
87
88
89
90
91
92
93







-
-
+
+







				 * request code (-1 means consider all minor
				 * codes). */
    Tk_ErrorProc *errorProc,	/* Procedure to invoke when a matching error
				 * occurs. NULL means just ignore matching
				 * errors. */
    ClientData clientData)	/* Arbitrary value to pass to errorProc. */
{
    TkErrorHandler *errorPtr;
    TkDisplay *dispPtr;
    register TkErrorHandler *errorPtr;
    register TkDisplay *dispPtr;

    /*
     * Find the display. If Tk doesn't know about this display then it's an
     * error: panic.
     */

    dispPtr = TkGetDisplay(display);
103
104
105
106
107
108
109
110

111
112
113

114
115
116
117
118
119
120
103
104
105
106
107
108
109

110
111
112

113
114
115
116
117
118
119
120







-
+


-
+







	defaultHandler = XSetErrorHandler(ErrorProc);
    }

    /*
     * Create the handler record.
     */

    errorPtr = (TkErrorHandler *)ckalloc(sizeof(TkErrorHandler));
    errorPtr = ckalloc(sizeof(TkErrorHandler));
    errorPtr->dispPtr = dispPtr;
    errorPtr->firstRequest = NextRequest(display);
    errorPtr->lastRequest = (unsigned long) -1;
    errorPtr->lastRequest = (unsigned) -1;
    errorPtr->error = error;
    errorPtr->request = request;
    errorPtr->minorCode = minorCode;
    errorPtr->errorProc = errorProc;
    errorPtr->clientData = clientData;
    errorPtr->nextPtr = dispPtr->errorPtr;
    dispPtr->errorPtr = errorPtr;
143
144
145
146
147
148
149
150
151


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168


169
170
171
172
173
174
175
176
177
178

179
180

181

182
183
184
185
186

187
188
189
190
191
192
193
143
144
145
146
147
148
149


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167


168
169
170









171


172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
-
+
+















+
-
-
+
+

-
-
-
-
-
-
-
-
-
+
-
-
+

+




-
+







 */

void
Tk_DeleteErrorHandler(
    Tk_ErrorHandler handler)	/* Token for handler to delete; was previous
				 * return value from Tk_CreateErrorHandler. */
{
    TkErrorHandler *errorPtr = (TkErrorHandler *) handler;
    TkDisplay *dispPtr = errorPtr->dispPtr;
    register TkErrorHandler *errorPtr = (TkErrorHandler *) handler;
    register TkDisplay *dispPtr = errorPtr->dispPtr;

    errorPtr->lastRequest = NextRequest(dispPtr->display) - 1;

    /*
     * Every once-in-a-while, cleanup handlers that are no longer active. We
     * probably won't be able to free the handler that was just deleted (need
     * to wait for any outstanding requests to be processed by server), but
     * there may be previously-deleted handlers that are now ready for garbage
     * collection. To reduce the cost of the cleanup, let a few dead handlers
     * pile up, then clean them all at once. This adds a bit of overhead to
     * errors that might occur while the dead handlers are hanging around, but
     * reduces the overhead of scanning the list to clean up (particularly if
     * there are many handlers that stay around forever).
     */

    dispPtr->deleteCount += 1;
    if (dispPtr->deleteCount++ >= 9) {
	TkErrorHandler *prevPtr;
    if (dispPtr->deleteCount >= 10) {
	register TkErrorHandler *prevPtr;
	TkErrorHandler *nextPtr;
	unsigned long lastSerial = LastKnownRequestProcessed(dispPtr->display);

	/*
	 * Last chance to catch errors for this handler: if no event/error
	 * processing took place to follow up the end of this error handler
	 * we need a round trip with the X server now.
	 */

	if (errorPtr->lastRequest > lastSerial) {
	int lastSerial;
	    XSync(dispPtr->display, False);
	}

	dispPtr->deleteCount = 0;
	lastSerial = LastKnownRequestProcessed(dispPtr->display);
	errorPtr = dispPtr->errorPtr;
	for (prevPtr = NULL; errorPtr != NULL; errorPtr = nextPtr) {
	    nextPtr = errorPtr->nextPtr;
	    if ((errorPtr->lastRequest != (unsigned long) -1)
		    && (errorPtr->lastRequest <= lastSerial)) {
		    && (errorPtr->lastRequest <= (unsigned long) lastSerial)) {
		if (prevPtr == NULL) {
		    dispPtr->errorPtr = nextPtr;
		} else {
		    prevPtr->nextPtr = nextPtr;
		}
		ckfree(errorPtr);
		continue;
216
217
218
219
220
221
222
223

224
225
226
227


228
229
230
231
232
233
234
209
210
211
212
213
214
215

216
217
218


219
220
221
222
223
224
225
226
227







-
+


-
-
+
+







 *
 *--------------------------------------------------------------
 */

static int
ErrorProc(
    Display *display,		/* Display for which error occurred. */
    XErrorEvent *errEventPtr)
    register XErrorEvent *errEventPtr)
				/* Information about error. */
{
    TkDisplay *dispPtr;
    TkErrorHandler *errorPtr;
    register TkDisplay *dispPtr;
    register TkErrorHandler *errorPtr;

    /*
     * See if we know anything about the display. If not, then invoke the
     * default error handler.
     */

    dispPtr = TkGetDisplay(display);

Changes to generic/tkEvent.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17








18
19
20
21
22
23
24






-
-
-
-
+
+
+
+







-
-
-
-
-
-
-
-







/*
 * tkEvent.c --
 *
 *	This file provides basic low-level facilities for managing X events in
 *	Tk.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1995 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Ajuba Solutions.
 * Copyright © 2004 George Peter Staplin
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 Ajuba Solutions.
 * Copyright (c) 2004 George Peter Staplin
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#elif defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#else
#include "tkUnixInt.h"
#endif

/*
 * There's a potential problem if a handler is deleted while it's current
 * (i.e. its function is executing), since Tk_HandleEvent will need to read
 * the handler's "nextPtr" field when the function returns. To handle this
 * problem, structures of the type below indicate the next handler to be
 * processed for any (recursively nested) dispatches in progress. The
 * nextHandler fields get updated if the handlers pointed to are deleted.
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+







    XEvent event;		/* The X event. */
} TkWindowEvent;

/*
 * Array of event masks corresponding to each X event:
 */

static const unsigned long eventMasks[TK_LASTEVENT] = {
static const unsigned long realEventMasks[MappingNotify+1] = {
    0,
    0,
    KeyPressMask,			/* KeyPress */
    KeyReleaseMask,			/* KeyRelease */
    ButtonPressMask,			/* ButtonPress */
    ButtonReleaseMask,			/* ButtonRelease */
    PointerMotionMask|PointerMotionHintMask|ButtonMotionMask
115
116
117
118
119
120
121
122




123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
107
108
109
110
111
112
113

114
115
116
117
118
119
120

121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149







-
+
+
+
+



-
+
-




















-
+







    SubstructureRedirectMask,		/* CirculateRequest */
    PropertyChangeMask,			/* PropertyNotify */
    0,					/* SelectionClear */
    0,					/* SelectionRequest */
    0,					/* SelectionNotify */
    ColormapChangeMask,			/* ColormapNotify */
    0,					/* ClientMessage */
    0,					/* Mapping Notify */
    0					/* Mapping Notify */
};

static const unsigned long virtualEventMasks[TK_LASTEVENT-VirtualEvent] = {
    VirtualEventMask,			/* VirtualEvents */
    ActivateMask,			/* ActivateNotify */
    ActivateMask,			/* DeactivateNotify */
    MouseWheelMask,			/* MouseWheelEvent */
    MouseWheelMask			/* MouseWheelEvent */
    TouchpadScrollMask			/* TouchpadScroll */
};

/*
 * For each exit handler created with a call to TkCreateExitHandler or
 * TkCreateThreadExitHandler there is a structure of the following type:
 */

typedef struct ExitHandler {
    Tcl_ExitProc *proc;		/* Function to call when process exits. */
    ClientData clientData;	/* One word of information to pass to proc. */
    struct ExitHandler *nextPtr;/* Next in list of all exit handlers for this
				 * application, or NULL for end of list. */
} ExitHandler;

/*
 * The structure below is used to store Data for the Event module that must be
 * kept thread-local. The "dataKey" is used to fetch the thread-specific
 * storage for the current thread.
 */

typedef struct {
typedef struct ThreadSpecificData {
    int handlersActive;		/* The following variable has a non-zero value
				 * when a handler is active. */
    InProgress *pendingPtr;	/* Topmost search in progress, or NULL if
				 * none. */

    /*
     * List of generic handler records.
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215

216

217

218
219
220
221
222
223
224
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222







+














+

+

+








/*
 * Prototypes for functions that are only referenced locally within this file.
 */

static void		CleanUpTkEvent(XEvent *eventPtr);
static void		DelayedMotionProc(ClientData clientData);
static int		GetButtonMask(unsigned int Button);
static unsigned long    GetEventMaskFromXEvent(XEvent *eventPtr);
static TkWindow *	GetTkWindowFromXEvent(XEvent *eventPtr);
static void		InvokeClientMessageHandlers(ThreadSpecificData *tsdPtr,
			    Tk_Window tkwin, XEvent *eventPtr);
static int		InvokeFocusHandlers(TkWindow **winPtrPtr,
			    unsigned long mask, XEvent *eventPtr);
static int		InvokeGenericHandlers(ThreadSpecificData *tsdPtr,
			    XEvent *eventPtr);
static int		InvokeMouseHandlers(TkWindow *winPtr,
			    unsigned long mask, XEvent *eventPtr);
static Window		ParentXId(Display *display, Window w);
static int		RefreshKeyboardMappingIfNeeded(XEvent *eventPtr);
static int		TkXErrorHandler(ClientData clientData,
			    XErrorEvent *errEventPtr);
static void		UpdateButtonEventState(XEvent *eventPtr);
static int		WindowEventProc(Tcl_Event *evPtr, int flags);
#ifdef TK_USE_INPUT_METHODS
static void		CreateXIC(TkWindow *winPtr);
#endif /* TK_USE_INPUT_METHODS */

/*
 *----------------------------------------------------------------------
 *
 * InvokeFocusHandlers --
 *
 *	Call focus-related code to look at FocusIn, FocusOut, Enter, and Leave
318
319
320
321
322
323
324

325
326
327
328
329
330
331
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330







+







 *
 *	Create the X input context for our winPtr.
 *	XIM is only ever enabled on Unix.
 *
 *----------------------------------------------------------------------
 */

#ifdef TK_USE_INPUT_METHODS
static void
CreateXIC(
    TkWindow *winPtr)
{
    TkDisplay *dispPtr = winPtr->dispPtr;
    long im_event_mask = 0L;
    const char *preedit_attname = NULL;
364
365
366
367
368
369
370

371
372
373
374
375
376
377
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377







+







     */
    XGetICValues(winPtr->inputContext, XNFilterEvents, &im_event_mask, NULL);
    if ((winPtr->atts.event_mask & im_event_mask) != im_event_mask) {
	winPtr->atts.event_mask |= im_event_mask;
	XSelectInput(winPtr->display, winPtr->window, winPtr->atts.event_mask);
    }
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * GetTkWindowFromXEvent --
 *
 *	Attempt to find which TkWindow is associated with an event. If it
450
451
452
453
454
455
456







457
458





459
460
461
462
463
464
465
450
451
452
453
454
455
456
457
458
459
460
461
462
463


464
465
466
467
468
469
470
471
472
473
474
475







+
+
+
+
+
+
+
-
-
+
+
+
+
+








static unsigned long
GetEventMaskFromXEvent(
    XEvent *eventPtr)
{
    unsigned long mask;

    /*
     * Get the event mask from the correct table. Note that there are two
     * tables here because that means we no longer need this code to rely on
     * the exact value of VirtualEvent, which has caused us problems in the
     * past when X11 changed the value of LASTEvent. [Bug ???]
     */

    if (eventPtr->xany.type <TK_LASTEVENT) {
	mask = eventMasks[eventPtr->xany.type];
    if (eventPtr->xany.type <= MappingNotify) {
	mask = realEventMasks[eventPtr->xany.type];
    } else if (eventPtr->xany.type >= VirtualEvent
	    && eventPtr->xany.type<TK_LASTEVENT) {
	mask = virtualEventMasks[eventPtr->xany.type - VirtualEvent];
    } else {
	mask = 0;
    }

    /*
     * Events selected by StructureNotify require special handling. They look
     * the same as those selected by SubstructureNotify. The only difference
510
511
512
513
514
515
516
517

518
519

520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542


















































































543
544
545
546
547
548
549
520
521
522
523
524
525
526

527
528

529



530
531
532
533
534
535
536
537
538
539










540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628







-
+

-
+
-
-
-










-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetButtonMask --
 * GetButtonMask --
 *
 *	Return the proper Button${n}Mask for the button. Don't care about
 *	Return the proper Button${n}Mask for the button.
 *	Button4 - Button7, because those are not actually buttons: Those
 *	are used for the horizontal or vertical mouse wheels. Button4Mask
 *	and higher is actually used for Button 8 and higher.
 *
 * Results:
 *	A button mask.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static const unsigned buttonMasks[] = {
    0, Button1Mask, Button2Mask, Button3Mask, 0, 0, 0, 0, Button4Mask, \
	    Button5Mask, Button6Mask, Button7Mask, Button8Mask, Button9Mask
};

unsigned
Tk_GetButtonMask(
    unsigned button)
{
    return (button > Button9) ? 0 : buttonMasks[button];
static int
GetButtonMask(
    unsigned int button)
{
    switch (button) {
    case 1:
	return Button1Mask;
    case 2:
	return Button2Mask;
    case 3:
	return Button3Mask;
    case 4:
	return Button4Mask;
    case 5:
	return Button5Mask;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateButtonEventState --
 *
 *	Update the button event state in our TkDisplay using the XEvent
 *	passed. We also may modify the the XEvent passed to fit some aspects
 *	of our TkDisplay.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The TkDisplay's private button state may be modified. The eventPtr's
 *	state may be updated to reflect masks stored in our TkDisplay that the
 *	event doesn't contain. The eventPtr may also be modified to not
 *	contain a button state for the window in which it was not pressed in.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateButtonEventState(
    XEvent *eventPtr)
{
    TkDisplay *dispPtr;
    int allButtonsMask = Button1Mask | Button2Mask | Button3Mask
	    | Button4Mask | Button5Mask;

    switch (eventPtr->type) {
    case ButtonPress:
	dispPtr = TkGetDisplay(eventPtr->xbutton.display);
	dispPtr->mouseButtonWindow = eventPtr->xbutton.window;
	eventPtr->xbutton.state |= dispPtr->mouseButtonState;

	dispPtr->mouseButtonState |= GetButtonMask(eventPtr->xbutton.button);
	break;

    case ButtonRelease:
	dispPtr = TkGetDisplay(eventPtr->xbutton.display);
	dispPtr->mouseButtonWindow = None;
	dispPtr->mouseButtonState &= ~GetButtonMask(eventPtr->xbutton.button);
	eventPtr->xbutton.state |= dispPtr->mouseButtonState;
	break;

    case MotionNotify:
	dispPtr = TkGetDisplay(eventPtr->xmotion.display);
	if (dispPtr->mouseButtonState & allButtonsMask) {
	    if (eventPtr->xbutton.window != dispPtr->mouseButtonWindow) {
		/*
		 * This motion event should not be interpreted as a button
		 * press + motion event since this is not the same window the
		 * button was pressed down in.
		 */

		dispPtr->mouseButtonState &= ~allButtonsMask;
		dispPtr->mouseButtonWindow = None;
	    } else {
		eventPtr->xmotion.state |= dispPtr->mouseButtonState;
	    }
	}
	break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * InvokeClientMessageHandlers --
 *
690
691
692
693
694
695
696
697
698


699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
769
770
771
772
773
774
775


776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799







-
-
+
+














-
+







Tk_CreateEventHandler(
    Tk_Window token,		/* Token for window in which to create
				 * handler. */
    unsigned long mask,		/* Events for which proc should be called. */
    Tk_EventProc *proc,		/* Function to call for each selected event */
    ClientData clientData)	/* Arbitrary data to pass to proc. */
{
    TkEventHandler *handlerPtr;
    TkWindow *winPtr = (TkWindow *)token;
    register TkEventHandler *handlerPtr;
    register TkWindow *winPtr = (TkWindow *) token;

    /*
     * Skim through the list of existing handlers to (a) compute the overall
     * event mask for the window (so we can pass this new value to the X
     * system) and (b) see if there's already a handler declared with the same
     * callback and clientData (if so, just change the mask). If no existing
     * handler matches, then create a new handler.
     */

    if (winPtr->handlerList == NULL) {
	/*
	 * No event handlers defined at all, so must create.
	 */

	handlerPtr = (TkEventHandler *)ckalloc(sizeof(TkEventHandler));
	handlerPtr = ckalloc(sizeof(TkEventHandler));
	winPtr->handlerList = handlerPtr;
    } else {
	int found = 0;

	for (handlerPtr = winPtr->handlerList; ;
		handlerPtr = handlerPtr->nextPtr) {
	    if ((handlerPtr->proc == proc)
737
738
739
740
741
742
743
744

745
746
747
748
749
750
751
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830







-
+







	    return;
	}

	/*
	 * No event handler matched, so create a new one.
	 */

	handlerPtr->nextPtr = (TkEventHandler *)ckalloc(sizeof(TkEventHandler));
	handlerPtr->nextPtr = ckalloc(sizeof(TkEventHandler));
	handlerPtr = handlerPtr->nextPtr;
    }

    /*
     * Initialize the new event handler.
     */

780
781
782
783
784
785
786
787
788


789
790
791


792
793
794
795
796
797
798
859
860
861
862
863
864
865


866
867
868


869
870
871
872
873
874
875
876
877







-
-
+
+

-
-
+
+







void
Tk_DeleteEventHandler(
    Tk_Window token,		/* Same as corresponding arguments passed */
    unsigned long mask,		/* previously to Tk_CreateEventHandler. */
    Tk_EventProc *proc,
    ClientData clientData)
{
    TkEventHandler *handlerPtr;
    InProgress *ipPtr;
    register TkEventHandler *handlerPtr;
    register InProgress *ipPtr;
    TkEventHandler *prevPtr;
    TkWindow *winPtr = (TkWindow *) token;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register TkWindow *winPtr = (TkWindow *) token;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Find the event handler to be deleted, or return immediately if it
     * doesn't exist.
     */

856
857
858
859
860
861
862
863

864
865
866

867
868
869
870
871
872
873
935
936
937
938
939
940
941

942
943
944

945
946
947
948
949
950
951
952







-
+


-
+








void
Tk_CreateGenericHandler(
    Tk_GenericProc *proc,	/* Function to call on every event. */
    ClientData clientData)	/* One-word value to pass to proc. */
{
    GenericHandler *handlerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    handlerPtr = (GenericHandler *)ckalloc(sizeof(GenericHandler));
    handlerPtr = ckalloc(sizeof(GenericHandler));

    handlerPtr->proc		= proc;
    handlerPtr->clientData	= clientData;
    handlerPtr->deleteFlag	= 0;
    handlerPtr->nextPtr		= NULL;
    if (tsdPtr->genericList == NULL) {
	tsdPtr->genericList	= handlerPtr;
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
976
977
978
979
980
981
982

983
984
985
986
987
988
989
990







-
+








void
Tk_DeleteGenericHandler(
    Tk_GenericProc *proc,
    ClientData clientData)
{
    GenericHandler * handler;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (handler=tsdPtr->genericList ; handler ; handler=handler->nextPtr) {
	if ((handler->proc == proc) && (handler->clientData == clientData)) {
	    handler->deleteFlag = 1;
	}
    }
930
931
932
933
934
935
936
937

938
939
940
941
942
943
944
945

946
947
948
949
950
951
952
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
1031







-
+







-
+







 */

void
Tk_CreateClientMessageHandler(
    Tk_ClientMessageProc *proc)	/* Function to call on event. */
{
    GenericHandler *handlerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * We use a GenericHandler struct, because it's basically the same, except
     * with an extra clientData field we'll never use.
     */

    handlerPtr = (GenericHandler *)ckalloc(sizeof(GenericHandler));
    handlerPtr = ckalloc(sizeof(GenericHandler));

    handlerPtr->proc = (Tk_GenericProc *) proc;
    handlerPtr->clientData = NULL;	/* never used */
    handlerPtr->deleteFlag = 0;
    handlerPtr->nextPtr = NULL;
    if (tsdPtr->cmList == NULL) {
	tsdPtr->cmList = handlerPtr;
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
1055
1056
1057
1058
1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069







-
+







 */

void
Tk_DeleteClientMessageHandler(
    Tk_ClientMessageProc *proc)
{
    GenericHandler * handler;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (handler=tsdPtr->cmList ; handler!=NULL ; handler=handler->nextPtr) {
	if (handler->proc == (Tk_GenericProc *) proc) {
	    handler->deleteFlag = 1;
	}
    }
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
1100







-
+







 *
 *----------------------------------------------------------------------
 */

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

    tsdPtr->handlersActive	= 0;
    tsdPtr->pendingPtr		= NULL;
    tsdPtr->genericList		= NULL;
    tsdPtr->lastGenericPtr	= NULL;
    tsdPtr->cmList		= NULL;
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049

1050
1051
1052
1053
1054
1055
1056
1119
1120
1121
1122
1123
1124
1125

1126
1127

1128
1129
1130
1131
1132
1133
1134
1135







-
+

-
+







 *
 *----------------------------------------------------------------------
 */

static int
TkXErrorHandler(
    ClientData clientData,	/* Pointer to flag we set. */
    TCL_UNUSED(XErrorEvent *))	/* X error info. */
    XErrorEvent *errEventPtr)	/* X error info. */
{
    int *error = (int *)clientData;
    int *error = clientData;

    *error = 1;
    return 0;
}

/*
 *----------------------------------------------------------------------
1129
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141

1142
1143
1144

1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1208
1209
1210
1211
1212
1213
1214

1215
1216
1217
1218
1219

1220
1221
1222

1223

















1224
1225
1226
1227
1228
1229
1230







-
+




-
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *----------------------------------------------------------------------
 */

void
Tk_HandleEvent(
    XEvent *eventPtr)	/* Event to dispatch. */
{
    TkEventHandler *handlerPtr;
    register TkEventHandler *handlerPtr;
    TkWindow *winPtr;
    unsigned long mask;
    InProgress ip;
    Tcl_Interp *interp = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));


    UpdateButtonEventState(eventPtr);
#if !defined(_WIN32) && !defined(MAC_OSX_TK)
    if ((eventPtr->type == ButtonRelease) || (eventPtr->type == ButtonPress)) {
	if ((eventPtr->xbutton.button >= Button4) && (eventPtr->xbutton.button < Button8)) {
	    if (eventPtr->type == ButtonRelease) {
		return;
	    } else { /* eventPtr->type == ButtonPress */
		int but = eventPtr->xbutton.button;
		eventPtr->type = MouseWheelEvent;
		eventPtr->xany.send_event = -1;
		eventPtr->xkey.keycode = (but & 1) ? -120 : 120;
		if (but > Button5) {
		    eventPtr->xkey.state |= ShiftMask;
		}
	    }
	}
    }
#endif

    /*
     * If the generic handler processed this event we are done and can return.
     */

    if (InvokeGenericHandlers(tsdPtr, eventPtr)) {
	goto releaseEventResources;
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233
1234
1235
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298







+







    /*
     * Create the input context for the window if it hasn't already been done
     * (XFilterEvent needs this context). When the event is a FocusIn event,
     * set the input context focus to the receiving window. This code is only
     * ever active for X11.
     */

#ifdef TK_USE_INPUT_METHODS
    /*
     * If the XIC has been invalidated, it must be recreated.
     */
    if (winPtr->dispPtr->ximGeneration != winPtr->ximGeneration) {
	winPtr->flags &= ~TK_CHECKED_IC;
	winPtr->inputContext = NULL;
    }
1243
1244
1245
1246
1247
1248
1249

1250
1251
1252
1253
1254
1255
1256
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320







+







	}
	if ((eventPtr->type == FocusIn) &&
		(winPtr->dispPtr->inputMethod != NULL) &&
		(winPtr->inputContext != NULL)) {
	    XSetICFocus(winPtr->inputContext);
	}
    }
#endif /*TK_USE_INPUT_METHODS*/

    /*
     * For events where it hasn't already been done, update the current time
     * in the display.
     */

    if (eventPtr->type == PropertyNotify) {
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1378







-
+







	 */

	/*
	 * ...well, except when we use the tkwm patches, in which case we DO
	 * handle CreateNotify events, so we gotta pass 'em through.
	 */

	if ((ip.winPtr != NULL)
	if ((ip.winPtr != None)
		&& ((mask != SubstructureNotifyMask)
		|| (eventPtr->type == CreateNotify))) {
	    TkBindEventProc(winPtr, eventPtr);
	}
    }
    tsdPtr->pendingPtr = ip.nextPtr;

1351
1352
1353
1354
1355
1356
1357
1358
1359
1360



1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385
1415
1416
1417
1418
1419
1420
1421



1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441

1442
1443
1444
1445
1446
1447
1448
1449







-
-
-
+
+
+

















-
+







 */

void
TkEventDeadWindow(
    TkWindow *winPtr)		/* Information about the window that is being
				 * deleted. */
{
    TkEventHandler *handlerPtr;
    InProgress *ipPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register TkEventHandler *handlerPtr;
    register InProgress *ipPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * While deleting all the handlers, be careful to check for Tk_HandleEvent
     * being about to process one of the deleted handlers. If it is, tell it
     * to quit (all of the handlers are being deleted).
     */

    while (winPtr->handlerList != NULL) {
	handlerPtr = winPtr->handlerList;
	winPtr->handlerList = handlerPtr->nextPtr;
	for (ipPtr = tsdPtr->pendingPtr; ipPtr != NULL;
		ipPtr = ipPtr->nextPtr) {
	    if (ipPtr->nextHandler == handlerPtr) {
		ipPtr->nextHandler = NULL;
	    }
	    if (ipPtr->winPtr == winPtr) {
		ipPtr->winPtr = NULL;
		ipPtr->winPtr = None;
	    }
	}
	ckfree(handlerPtr);
    }
}

/*
1401
1402
1403
1404
1405
1406
1407
1408
1409


1410
1411
1412
1413
1414
1415
1416
1465
1466
1467
1468
1469
1470
1471


1472
1473
1474
1475
1476
1477
1478
1479
1480







-
-
+
+







 *----------------------------------------------------------------------
 */

Time
TkCurrentTime(
    TkDisplay *dispPtr)		/* Display for which the time is desired. */
{
    XEvent *eventPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register XEvent *eventPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->pendingPtr == NULL) {
	return dispPtr->lastEventTime;
    }
    eventPtr = tsdPtr->pendingPtr->eventPtr;
    switch (eventPtr->type) {
1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1520
1521
1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532
1533
1534







-
+







Tk_RestrictEvents(
    Tk_RestrictProc *proc,	/* Function to call for each incoming event */
    ClientData arg,		/* Arbitrary argument to pass to proc. */
    ClientData *prevArgPtr)	/* Place to store information about previous
				 * argument. */
{
    Tk_RestrictProc *prev;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    prev = tsdPtr->restrictProc;
    *prevArgPtr = tsdPtr->restrictArg;
    tsdPtr->restrictProc = proc;
    tsdPtr->restrictArg = arg;
    return prev;
1549
1550
1551
1552
1553
1554
1555
1556

1557
1558
1559
1560
1561
1562
1563
1613
1614
1615
1616
1617
1618
1619

1620
1621
1622
1623
1624
1625
1626
1627







-
+







    /*
     * Don't filter motion events if the user defaulting to true (1), which
     * could be set to false (0) when the user wishes to receive all the
     * motion data)
     */

    if (!(dispPtr->flags & TK_DISPLAY_COLLAPSE_MOTION_EVENTS)) {
	wevPtr = (TkWindowEvent *)ckalloc(sizeof(TkWindowEvent));
	wevPtr = ckalloc(sizeof(TkWindowEvent));
	wevPtr->header.proc = WindowEventProc;
	wevPtr->event = *eventPtr;
	Tcl_QueueEvent(&wevPtr->header, position);
	return;
    }

    if ((dispPtr->delayedMotionPtr != NULL) && (position == TCL_QUEUE_TAIL)) {
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659







-
+








	    Tcl_QueueEvent(&dispPtr->delayedMotionPtr->header, position);
	    dispPtr->delayedMotionPtr = NULL;
	    Tcl_CancelIdleCall(DelayedMotionProc, dispPtr);
	}
    }

    wevPtr = (TkWindowEvent *)ckalloc(sizeof(TkWindowEvent));
    wevPtr = ckalloc(sizeof(TkWindowEvent));
    wevPtr->header.proc = WindowEventProc;
    wevPtr->event = *eventPtr;
    if ((eventPtr->type == MotionNotify) && (position == TCL_QUEUE_TAIL)) {
	/*
	 * The new event is a motion event so don't queue it immediately; save
	 * it around in case another motion event arrives that it can be
	 * collapsed with.
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1708
1709
1710
1711
1712
1713
1714









































1715
1716
1717
1718
1719
1720
1721







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	childPtr = childPtr->nextPtr;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenerateActivateEvents --
 *
 *	This function is called by the Mac and Windows window manager routines
 *	when a toplevel window is activated or deactivated.
 *	Activate/Deactivate events will be sent to every subwindow of the
 *	toplevel followed by a FocusIn/FocusOut message.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Generates X events.
 *
 *----------------------------------------------------------------------
 */

void
TkGenerateActivateEvents(
    TkWindow *winPtr,		/* Toplevel to activate. */
    int active)			/* Non-zero if the window is being activated,
				 * else 0.*/
{
    XEvent event;

    /*
     * Generate Activate and Deactivate events. This event is sent to every
     * subwindow in a toplevel window.
     */

    event.xany.serial = NextRequest(winPtr->display);
    event.xany.send_event = False;
    event.xany.display = winPtr->display;
    event.xany.window = winPtr->window;

    event.xany.type = active ? ActivateNotify : DeactivateNotify;
    TkQueueEventForAllChildren(winPtr, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * WindowEventProc --
 *
 *	This function is called by Tcl_DoOneEvent when a window event reaches
 *	the front of the event queue. This function is responsible for
 *	actually handling the event.
 *
 * Results:
1712
1713
1714
1715
1716
1717
1718
1719

1720
1721
1722
1723
1724
1725
1726
1735
1736
1737
1738
1739
1740
1741

1742
1743
1744
1745
1746
1747
1748
1749







-
+







WindowEventProc(
    Tcl_Event *evPtr,		/* Event to service. */
    int flags)			/* Flags that indicate what events to handle,
				 * such as TCL_WINDOW_EVENTS. */
{
    TkWindowEvent *wevPtr = (TkWindowEvent *) evPtr;
    Tk_RestrictAction result;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!(flags & TCL_WINDOW_EVENTS)) {
	return 0;
    }
    if (tsdPtr->restrictProc != NULL) {
	result = tsdPtr->restrictProc(tsdPtr->restrictArg, &wevPtr->event);
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







-
-

+





-







static void
CleanUpTkEvent(
    XEvent *eventPtr)
{
    switch (eventPtr->type) {
    case KeyPress:
    case KeyRelease: {

#if !defined(_WIN32) && !defined(MAC_OSX_TK)
	TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr;

	if (kePtr->charValuePtr != NULL) {
	    ckfree(kePtr->charValuePtr);
	    kePtr->charValuePtr = NULL;
	    kePtr->charValueLen = 0;
	}
#endif
	break;
    }

    case VirtualEvent: {
	XVirtualEvent *vePtr = (XVirtualEvent *) eventPtr;

	if (vePtr->user_data != NULL) {
1813
1814
1815
1816
1817
1818
1819
1820

1821
1822
1823
1824
1825
1826
1827
1834
1835
1836
1837
1838
1839
1840

1841
1842
1843
1844
1845
1846
1847
1848







-
+







 */

static void
DelayedMotionProc(
    ClientData clientData)	/* Pointer to display containing a delayed
				 * motion event to be serviced. */
{
    TkDisplay *dispPtr = (TkDisplay *)clientData;
    TkDisplay *dispPtr = clientData;

    if (dispPtr->delayedMotionPtr == NULL) {
	Tcl_Panic("DelayedMotionProc found no delayed mouse motion event");
    }
    Tcl_QueueEvent(&dispPtr->delayedMotionPtr->header, TCL_QUEUE_TAIL);
    dispPtr->delayedMotionPtr = NULL;
}
1841
1842
1843
1844
1845
1846
1847
1848

1849
1850
1851
1852

1853
1854
1855
1856
1857
1858
1859
1862
1863
1864
1865
1866
1867
1868

1869
1870
1871
1872

1873
1874
1875
1876
1877
1878
1879
1880







-
+



-
+







 *
 *----------------------------------------------------------------------
 */

void
TkCreateExitHandler(
    Tcl_ExitProc *proc,		/* Function to invoke. */
    void *clientData)	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;

    exitPtr = (ExitHandler *)ckalloc(sizeof(ExitHandler));
    exitPtr = ckalloc(sizeof(ExitHandler));
    exitPtr->proc = proc;
    exitPtr->clientData = clientData;
    Tcl_MutexLock(&exitMutex);

    /*
     * The call to TclInExit() is disabled here. That's a private Tcl routine,
     * and calling it is causing some trouble with portability of building Tk.
1941
1942
1943
1944
1945
1946
1947
1948

1949
1950
1951

1952
1953
1954
1955
1956
1957
1958
1962
1963
1964
1965
1966
1967
1968

1969
1970
1971

1972
1973
1974
1975
1976
1977
1978
1979







-
+


-
+








void
TkCreateThreadExitHandler(
    Tcl_ExitProc *proc,		/* Function to invoke. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    exitPtr = (ExitHandler *)ckalloc(sizeof(ExitHandler));
    exitPtr = ckalloc(sizeof(ExitHandler));
    exitPtr->proc = proc;
    exitPtr->clientData = clientData;

    /*
     * See comments in TkCreateExitHandler().
     */

1982
1983
1984
1985
1986
1987
1988
1989

1990
1991
1992
1993
1994
1995
1996
2003
2004
2005
2006
2007
2008
2009

2010
2011
2012
2013
2014
2015
2016
2017







-
+








void
TkDeleteThreadExitHandler(
    Tcl_ExitProc *proc,		/* Function that was previously registered. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr, *prevPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (prevPtr = NULL, exitPtr = tsdPtr->firstExitPtr; exitPtr != NULL;
	    prevPtr = exitPtr, exitPtr = exitPtr->nextPtr) {
	if ((exitPtr->proc == proc)
		&& (exitPtr->clientData == clientData)) {
	    if (prevPtr == NULL) {
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
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







-
+














-
+








/*
 *----------------------------------------------------------------------
 *
 * TkFinalize --
 *
 *	Runs our private exit handlers and removes itself from Tcl. This is
 *	beneficial should we want to protect from dangling pointers should the
 *	benificial should we want to protect from dangling pointers should the
 *	Tk shared library be unloaded prior to Tcl which can happen on windows
 *	should the process be forcefully exiting from an exception handler.
 *
 * Results:
 *	None.
 *
 * Side effects.
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkFinalize(
    TCL_UNUSED(void *))	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;

#if defined(_WIN32) && !defined(STATIC_BUILD)
    if (!tclStubsPtr) {
	return;
    }
2073
2074
2075
2076
2077
2078
2079
2080

2081
2082
2083

2084
2085
2086
2087
2088
2089
2090
2094
2095
2096
2097
2098
2099
2100

2101
2102
2103

2104
2105
2106
2107
2108
2109
2110
2111







-
+


-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkFinalizeThread(
    TCL_UNUSED(void *))	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    Tcl_DeleteThreadExitHandler(TkFinalizeThread, NULL);

    if (tsdPtr != NULL) {
	tsdPtr->inExit = 1;

Changes to generic/tkFileFilter.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkFileFilter.c --
 *
 *	Process the -filetypes option for the file dialogs on Windows and the
 *	Mac.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"
#include "tkFileFilter.h"
75
76
77
78
79
80
81
82

83

84
85
86
87
88
89
90
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91







-
+

+







int
TkGetFileFilters(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    FileFilterList *flistPtr,	/* Stores the list of file filters. */
    Tcl_Obj *types,		/* Value of the -filetypes option. */
    int isWindows)		/* True if we are running on Windows. */
{
    Tcl_Size i, listObjc;
    int listObjc;
    Tcl_Obj ** listObjv = NULL;
    int i;

    if (types == NULL) {
	return TCL_OK;
    }

    if (Tcl_ListObjGetElements(interp, types, &listObjc,
	    &listObjv) != TCL_OK) {
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+







    for (i = 0; i<listObjc; i++) {
	/*
	 * Each file type should have two or three elements: the first one is
	 * the name of the type and the second is the filter of the type. The
	 * third is the Mac OSType ID, but we don't care about them here.
	 */

	Tcl_Size count;
	int count;
	FileFilter *filterPtr;
	Tcl_Obj **typeInfo;

	if (Tcl_ListObjGetElements(interp, listObjv[i], &count,
		&typeInfo) != TCL_OK) {
	    return TCL_ERROR;
	}
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174







-
+







TkFreeFileFilters(
    FileFilterList *flistPtr)	/* List of file filters to free */
{
    FileFilter *filterPtr;
    FileFilterClause *clausePtr;
    GlobPattern *globPtr;
    MacFileType *mfPtr;
    void *toFree;	/* A pointer that we are about to free. */
    register void *toFree;	/* A pointer that we are about to free. */

    for (filterPtr = flistPtr->filters; filterPtr != NULL; ) {
	for (clausePtr = filterPtr->clauses; clausePtr != NULL; ) {
	    /*
	     * Squelch each of the glob patterns.
	     */

228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
229
230
231
232
233
234
235

236

237
238
239
240
241
242
243







-
+
-







    Tcl_Obj *ostypesObj,	/* A Tcl list of Mac OSType strings. */
    int isWindows)		/* True if we are running on Windows; False if
				 * we are running on the Mac; Glob patterns
				 * need to be processed differently on these
				 * two platforms */
{
    Tcl_Obj **globList = NULL, **ostypeList = NULL;
    Tcl_Size globCount, ostypeCount, i;
    int globCount, ostypeCount, i, code = TCL_OK;
    int code = TCL_OK;
    FileFilterClause *clausePtr;
    Tcl_Encoding macRoman = NULL;

    if (Tcl_ListObjGetElements(interp, patternsObj,
	    &globCount, &globList) != TCL_OK) {
	code = TCL_ERROR;
	goto done;
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272







-
+







	/*
	 * Might be cleaner to use 'Tcl_GetOSTypeFromObj' but that is actually
	 * static to the MacOS X/Darwin version of Tcl, and would therefore
	 * require further code refactoring.
	 */

	for (i=0; i<ostypeCount; i++) {
	    Tcl_Size len;
	    int len;
	    const char *strType = Tcl_GetStringFromObj(ostypeList[i], &len);

	    /*
	     * If len is < 4, it is definitely an error. If equal or longer,
	     * we need to use the macRoman encoding to determine the correct
	     * length (assuming there may be non-ascii characters, e.g.,
	     * embedded nulls or accented characters in the string, the
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325


326
327
328
329
330
331
332
333
334

335
336
337
338
339

340
341
342
343
344
345
346
347
348

349
350
351

352
353
354
355

356
357
358
359
360
361
362
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323


324
325
326
327
328
329
330
331
332
333

334
335
336
337
338

339
340
341
342
343
344
345
346
347

348
349
350

351
352
353
354

355
356
357
358
359
360
361
362







-
+


















-
+















-
-
+
+








-
+




-
+








-
+


-
+



-
+







		Tcl_DString osTypeDS;

		/*
		 * Convert utf to macRoman, since MacOS types are defined to
		 * be 4 macRoman characters long
		 */

		(void)Tcl_UtfToExternalDString(macRoman, strType, len, &osTypeDS);
		Tcl_UtfToExternalDString(macRoman, strType, len, &osTypeDS);
		len = Tcl_DStringLength(&osTypeDS);
		Tcl_DStringFree(&osTypeDS);
	    }
	    if (len != 4) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad Macintosh file type \"%s\"",
			Tcl_GetString(ostypeList[i])));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "MAC_TYPE", NULL);
		code = TCL_ERROR;
		goto done;
	    }
	}
    }

    /*
     * Add the clause into the list of clauses
     */

    clausePtr = (FileFilterClause *)ckalloc(sizeof(FileFilterClause));
    clausePtr = ckalloc(sizeof(FileFilterClause));
    clausePtr->patterns = NULL;
    clausePtr->patternsTail = NULL;
    clausePtr->macTypes = NULL;
    clausePtr->macTypesTail = NULL;

    if (filterPtr->clauses == NULL) {
	filterPtr->clauses = filterPtr->clausesTail = clausePtr;
    } else {
	filterPtr->clausesTail->next = clausePtr;
	filterPtr->clausesTail = clausePtr;
    }
    clausePtr->next = NULL;

    if (globCount > 0 && globList != NULL) {
	for (i=0; i<globCount; i++) {
	    GlobPattern *globPtr = (GlobPattern *)ckalloc(sizeof(GlobPattern));
	    Tcl_Size len;
	    GlobPattern *globPtr = ckalloc(sizeof(GlobPattern));
	    int len;
	    const char *str = Tcl_GetStringFromObj(globList[i], &len);

	    len = (len + 1) * sizeof(char);
	    if (str[0] && str[0] != '*') {
		/*
		 * Prepend a "*" to patterns that do not have a leading "*"
		 */

		globPtr->pattern = (char *)ckalloc(len + 1);
		globPtr->pattern = ckalloc(len + 1);
		globPtr->pattern[0] = '*';
		strcpy(globPtr->pattern+1, str);
	    } else if (isWindows) {
		if (strcmp(str, "*") == 0) {
		    globPtr->pattern = (char *)ckalloc(4);
		    globPtr->pattern = ckalloc(4);
		    strcpy(globPtr->pattern, "*.*");
		} else if (strcmp(str, "") == 0) {
		    /*
		     * An empty string means "match all files with no
		     * extensions"
		     * TODO: "*." actually matches with all files on Win95
		     */

		    globPtr->pattern = (char *)ckalloc(3);
		    globPtr->pattern = ckalloc(3);
		    strcpy(globPtr->pattern, "*.");
		} else {
		    globPtr->pattern = (char *)ckalloc(len);
		    globPtr->pattern = ckalloc(len);
		    strcpy(globPtr->pattern, str);
		}
	    } else {
		globPtr->pattern = (char *)ckalloc(len);
		globPtr->pattern = ckalloc(len);
		strcpy(globPtr->pattern, str);
	    }

	    /*
	     * Add the glob pattern into the list of patterns.
	     */

371
372
373
374
375
376
377
378
379


380
381
382
383
384
385
386
387
388


389
390
391
392
393
394
395
371
372
373
374
375
376
377


378
379
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395
396







-
-
+
+








-
+
+







    }
    if (ostypeList != NULL && ostypeCount > 0) {
	if (macRoman == NULL) {
	    macRoman = Tcl_GetEncoding(NULL, "macRoman");
	}
	for (i=0; i<ostypeCount; i++) {
	    Tcl_DString osTypeDS;
	    Tcl_Size len;
	    MacFileType *mfPtr = (MacFileType *)ckalloc(sizeof(MacFileType));
	    int len;
	    MacFileType *mfPtr = ckalloc(sizeof(MacFileType));
	    const char *strType = Tcl_GetStringFromObj(ostypeList[i], &len);
	    char *string;

	    /*
	     * Convert utf to macRoman, since MacOS types are defined to be 4
	     * macRoman characters long
	     */

	    string = Tcl_UtfToExternalDString(macRoman, strType, len, &osTypeDS);
	    Tcl_UtfToExternalDString(macRoman, strType, len, &osTypeDS);
	    string = Tcl_DStringValue(&osTypeDS);
	    mfPtr->type = (OSType) string[0] << 24 | (OSType) string[1] << 16 |
		    (OSType) string[2] <<  8 | (OSType) string[3];
	    Tcl_DStringFree(&osTypeDS);

	    /*
	     * Add the Mac type pattern into the list of Mac types
	     */
440
441
442
443
444
445
446
447

448
449
450
451

452
453
454
455
456
457
458
441
442
443
444
445
446
447

448
449
450
451

452
453
454
455
456
457
458
459







-
+



-
+








    for (; filterPtr; filterPtr=filterPtr->next) {
	if (strcmp(filterPtr->name, name) == 0) {
	    return filterPtr;
	}
    }

    filterPtr = (FileFilter *)ckalloc(sizeof(FileFilter));
    filterPtr = ckalloc(sizeof(FileFilter));
    filterPtr->clauses = NULL;
    filterPtr->clausesTail = NULL;
    len = strlen(name) + 1;
    filterPtr->name = (char *)ckalloc(len);
    filterPtr->name = ckalloc(len);
    memcpy(filterPtr->name, name, len);

    if (flistPtr->filters == NULL) {
	flistPtr->filters = flistPtr->filtersTail = filterPtr;
    } else {
	flistPtr->filtersTail->next = filterPtr;
	flistPtr->filtersTail = filterPtr;

Changes to generic/tkFileFilter.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15




16
17
18
19
20
21
22






-
+








-
-
-
-







/*
 * tkFileFilter.h --
 *
 *	Declarations for the file filter processing routines needed by the
 *	file selection dialogs.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#ifndef _TK_FILE_FILTER
#define _TK_FILE_FILTER

#ifdef __cplusplus
extern "C" {
#endif

#define OSType long

typedef struct GlobPattern {
    struct GlobPattern *next;	/* Chains to the next glob pattern in a glob
				 * pattern list */
    char *pattern;		/* String value of the pattern, such as
				 * "*.txt" or "*.*" */
75
76
77
78
79
80
81
82
83
84
85
86
71
72
73
74
75
76
77




78







-
-
-
-


MODULE_SCOPE void	TkFreeFileFilters(FileFilterList *flistPtr);
MODULE_SCOPE void	TkInitFileFilters(FileFilterList *flistPtr);
MODULE_SCOPE int	TkGetFileFilters(Tcl_Interp *interp,
    			    FileFilterList *flistPtr, Tcl_Obj *valuePtr,
			    int isWindows);

#ifdef __cplusplus
}
#endif

#endif	/* _TK_FILE_FILTER */

Changes to generic/tkFocus.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkFocus.c --
 *
 *	This file contains functions that manage the input focus for Tk.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+








/*
 * Debugging support...
 */

#define DEBUG(dispPtr, arguments) \
    if ((dispPtr)->focusDebug) { \
	printf arguments; fflush(stdout); \
	printf arguments; \
    }

/*
 * Forward declarations for functions defined in this file:
 */

static DisplayFocusInfo*FindDisplayFocusInfo(TkMainInfo *mainPtr,
109
110
111
112
113
114
115
116
117


118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
109
110
111
112
113
114
115


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
-
+
+













-
+







    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const focusOptions[] = {
	"-displayof", "-force", "-lastfor", NULL
    };
    Tk_Window tkwin = (Tk_Window)clientData;
    TkWindow *winPtr = (TkWindow *)clientData;
    Tk_Window tkwin = clientData;
    TkWindow *winPtr = clientData;
    TkWindow *newPtr, *topLevelPtr;
    ToplevelFocusInfo *tlFocusPtr;
    const char *windowName;
    int index;

    /*
     * If invoked with no arguments, just return the current focus window.
     */

    if (objc == 1) {
	Tk_Window focusWin = (Tk_Window) TkGetFocusWin(winPtr);

	if (focusWin != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj(focusWin));
	    Tcl_SetObjResult(interp, TkNewWindowObj(focusWin));
	}
	return TCL_OK;
    }

    /*
     * If invoked with a single argument beginning with "." then focus on that
     * window.
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189







-
+







	windowName = Tcl_GetString(objv[2]);
	newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin);
	if (newPtr == NULL) {
	    return TCL_ERROR;
	}
	newPtr = TkGetFocusWin(newPtr);
	if (newPtr != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window) newPtr));
	    Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window) newPtr));
	}
	break;
    case 1:			/* -force */
	windowName = Tcl_GetString(objv[2]);

	/*
	 * The empty string case exists for backwards compatibility.
208
209
210
211
212
213
214
215

216
217
218
219
220

221
222
223
224
225
226
227
208
209
210
211
212
213
214

215
216
217
218
219

220
221
222
223
224
225
226
227







-
+




-
+







		topLevelPtr = topLevelPtr->parentPtr) {
	    if (!(topLevelPtr->flags & TK_TOP_HIERARCHY)) {
		continue;
	    }
	    for (tlFocusPtr = newPtr->mainPtr->tlFocusPtr; tlFocusPtr != NULL;
		    tlFocusPtr = tlFocusPtr->nextPtr) {
		if (tlFocusPtr->topLevelPtr == topLevelPtr) {
		    Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window)
		    Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window)
			    tlFocusPtr->focusWinPtr));
		    return TCL_OK;
		}
	    }
	    Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window) topLevelPtr));
	    Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window) topLevelPtr));
	    return TCL_OK;
	}
	break;
    default:
	Tcl_Panic("bad const entries to focusOptions in focus command");
    }
    return TCL_OK;
275
276
277
278
279
280
281
282
283


284
285
286
287
288
289
290
275
276
277
278
279
280
281


282
283
284
285
286
287
288
289
290







-
-
+
+







    int retValue, delta;

    /*
     * If this was a generated event, just turn off the generated flag and
     * pass the event through to Tk bindings.
     */

    if ((eventPtr->xfocus.send_event & GENERATED_FOCUS_EVENT_MAGIC) == GENERATED_FOCUS_EVENT_MAGIC) {
	eventPtr->xfocus.send_event &= ~GENERATED_FOCUS_EVENT_MAGIC;
    if (eventPtr->xfocus.send_event == GENERATED_FOCUS_EVENT_MAGIC) {
	eventPtr->xfocus.send_event = 0;
	return 1;
    }

    /*
     * Check for special events generated by embedded applications to request
     * the input focus. If this is one of those events, make the change in
     * focus and return without any additional processing of the event (note:
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325







-
+







	 * Skip FocusIn events that cause confusion
	 * NotifyVirtual and NotifyNonlinearVirtual - Virtual events occur on
	 *	windows in between the origin and destination of the focus
	 *	change. For FocusIn we may see this when focus goes into an
	 *	embedded child. We don't care about this, although we may end
	 *	up getting a NotifyPointer later.
	 * NotifyInferior - focus is coming to us from an embedded child. When
	 *	focus is on an embedded focus, we still think we have the
	 *	focus is on an embeded focus, we still think we have the
	 *	focus, too, so this message doesn't change our state.
	 * NotifyPointerRoot - should never happen because this is sent to the
	 *	root window.
	 *
	 * Interesting FocusIn events are
	 * NotifyAncestor - focus is coming from our parent, probably the root.
	 * NotifyNonlinear - focus is coming from a different branch, probably
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+







	retValue = 1;
	if (eventPtr->xcrossing.detail == NotifyInferior) {
	    return retValue;
	}
    }

    /*
     * If winPtr isn't a top-level window then just ignore the event.
     * If winPtr isn't a top-level window than just ignore the event.
     */

    winPtr = TkWmFocusToplevel(winPtr);
    if (winPtr == NULL) {
	return retValue;
    }

411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425







-
+







    for (tlFocusPtr = winPtr->mainPtr->tlFocusPtr; tlFocusPtr != NULL;
	    tlFocusPtr = tlFocusPtr->nextPtr) {
	if (tlFocusPtr->topLevelPtr == winPtr) {
	    break;
	}
    }
    if (tlFocusPtr == NULL) {
	tlFocusPtr = (ToplevelFocusInfo *)ckalloc(sizeof(ToplevelFocusInfo));
	tlFocusPtr = ckalloc(sizeof(ToplevelFocusInfo));
	tlFocusPtr->topLevelPtr = tlFocusPtr->focusWinPtr = winPtr;
	tlFocusPtr->nextPtr = winPtr->mainPtr->tlFocusPtr;
	winPtr->mainPtr->tlFocusPtr = tlFocusPtr;
    }
    newFocusPtr = tlFocusPtr->focusWinPtr;

    /*
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
497
498
499
500
501
502
503

504
505
506
507
508
509

510
511
512
513
514
515
516







-
+





-







	 * dispPtr->implicitWinPtr)!! In addition, we generate events because
	 * the window manager won't give us a FocusOut event when we focus on
	 * the root.
	 */

	if ((dispPtr->implicitWinPtr != NULL)
		&& !(winPtr->flags & TK_EMBEDDED)) {
	    DEBUG(dispPtr, ("Defocussed implicit Async from %s\n", displayFocusPtr->focusWinPtr->pathName));
	    DEBUG(dispPtr, ("Defocussed implicit Async\n"));
	    GenerateFocusEvents(displayFocusPtr->focusWinPtr, NULL);
	    XSetInputFocus(dispPtr->display, PointerRoot, RevertToPointerRoot,
		    CurrentTime);
	    displayFocusPtr->focusWinPtr = NULL;
	    dispPtr->implicitWinPtr = NULL;
	    dispPtr->focusPtr = NULL;
	}
    }
    return retValue;
}

/*
 *----------------------------------------------------------------------
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565



566
567
568
569
570
571
572
573
574


575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602





603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634
635
636

637
638


639
640
641
642

643
644
645

646
647
648
649
650






651
652

653
654
655
656


657
658
659
660

661

662
663




664
665
666
667
668
669
670
547
548
549
550
551
552
553





554
555
556



557
558
559
560
561
562
563
564
565
566


567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590





591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625




626


627
628




629



630





631
632
633
634
635
636
637

638




639
640




641
642
643


644
645
646
647
648
649
650
651
652
653
654







-
-
-
-
-



-
-
-
+
+
+







-
-
+
+






-
















-
-
-
-
-
+
+
+
+
+




-
+


















-
+






-
-
-
-
+
-
-
+
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+

-
+
-
-
-
-
+
+
-
-
-
-
+

+
-
-
+
+
+
+







     * Don't set focus if window is already dead. [Bug 3574708]
     */

    if (winPtr->flags & TK_ALREADY_DEAD) {
	return;
    }

    /*
     * Get the current focus window with the same display and application
     * as winPtr.
     */

    displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr);

    /*
     * Do nothing if the window already has focus and force is not set.  If
     * force is set, we need to grab the focus, since under Windows or macOS
     * this may involve taking control away from another application.
     * If force is set, we should make sure we grab the focus regardless of
     * the current focus window since under Windows, we may need to take
     * control away from another application.
     */

    if (winPtr == displayFocusPtr->focusWinPtr && !force) {
	return;
    }

    /*
     * Find the toplevel window for winPtr, then find (or create) a record
     * for the toplevel. Also see whether winPtr and all its ancestors are
     * Find the top-level window for winPtr, then find (or create) a record
     * for the top-level. Also see whether winPtr and all its ancestors are
     * mapped.
     */

    allMapped = 1;
    for (topLevelPtr = winPtr; ; topLevelPtr = topLevelPtr->parentPtr) {
	if (topLevelPtr == NULL) {

	    /*
	     * The window is being deleted. No point in worrying about giving
	     * it the focus.
	     */

	    return;
	}
	if (!(topLevelPtr->flags & TK_MAPPED)) {
	    allMapped = 0;
	}
	if (topLevelPtr->flags & TK_TOP_HIERARCHY) {
	    break;
	}
    }

    /*
     * If any ancestor of the new focus window isn't mapped, then we can't set
     * focus for it (X will generate an error, for example). Instead, create
     * an event handler that will set the focus to this window once it gets
     * mapped. At the same time, delete any old handler that might be around;
     * it's no longer relevant.
     * If the new focus window isn't mapped, then we can't focus on it (X will
     * generate an error, for example). Instead, create an event handler that
     * will set the focus to this window once it gets mapped. At the same
     * time, delete any old handler that might be around; it's no longer
     * relevant.
     */

    if (displayFocusPtr->focusOnMapPtr != NULL) {
	Tk_DeleteEventHandler((Tk_Window) displayFocusPtr->focusOnMapPtr,
		VisibilityChangeMask, FocusMapProc,
		StructureNotifyMask, FocusMapProc,
		displayFocusPtr->focusOnMapPtr);
	displayFocusPtr->focusOnMapPtr = NULL;
    }
    if (!allMapped) {
	Tk_CreateEventHandler((Tk_Window) winPtr, VisibilityChangeMask,
		FocusMapProc, winPtr);
	displayFocusPtr->focusOnMapPtr = winPtr;
	displayFocusPtr->forceFocus = force;
	return;
    }

    for (tlFocusPtr = winPtr->mainPtr->tlFocusPtr; tlFocusPtr != NULL;
	    tlFocusPtr = tlFocusPtr->nextPtr) {
	if (tlFocusPtr->topLevelPtr == topLevelPtr) {
	    break;
	}
    }
    if (tlFocusPtr == NULL) {
	tlFocusPtr = (ToplevelFocusInfo *)ckalloc(sizeof(ToplevelFocusInfo));
	tlFocusPtr = ckalloc(sizeof(ToplevelFocusInfo));
	tlFocusPtr->topLevelPtr = topLevelPtr;
	tlFocusPtr->nextPtr = winPtr->mainPtr->tlFocusPtr;
	winPtr->mainPtr->tlFocusPtr = tlFocusPtr;
    }
    tlFocusPtr->focusWinPtr = winPtr;

    if (topLevelPtr->flags & TK_EMBEDDED &&
        (displayFocusPtr->focusWinPtr == NULL)) {

	/*
    /*
	 * We are assigning focus to an embedded toplevel.  The platform
	 * specific function TkpClaimFocus needs to handle the job of
     * Reset the window system's focus window and generate focus events, with
     * two special cases:
	 * assigning focus to the container, since we have no way to find the
	 * container.
	 */

     *
	TkpClaimFocus(topLevelPtr, force);
    } else if ((displayFocusPtr->focusWinPtr != NULL) || force) {

     * 1. If the application is embedded and doesn't currently have the focus,
	/*
	 * If we are forcing removal of focus from a container hosting a
	 * toplevel from a different application, clear the focus in that
	 * application.
	 */
     *    don't set the focus directly. Instead, see if the embedding code can
     *    claim the focus from the enclosing container.
     * 2. Otherwise, if the application doesn't currently have the focus,
     *    don't change the window system's focus unless it was already in this
     *    application or "force" was specified.
     */

    	if (force) {
    if ((topLevelPtr->flags & TK_EMBEDDED)
	    TkWindow *focusPtr = winPtr->dispPtr->focusPtr;
	    if (focusPtr && focusPtr->mainPtr != winPtr->mainPtr) {
		DisplayFocusInfo *displayFocusPtr2 = FindDisplayFocusInfo(
		    focusPtr->mainPtr, focusPtr->dispPtr);
	    && (displayFocusPtr->focusWinPtr == NULL)) {
	TkpClaimFocus(topLevelPtr, force);
		displayFocusPtr2->focusWinPtr = NULL;
	    }
    	}

    } else if ((displayFocusPtr->focusWinPtr != NULL) || force) {
	/*
	 * Generate events to shift focus between Tk windows. We do this
	 * Call the platform specific function TkpChangeFocus to move the
	 * window manager's focus to a new toplevel.
	 * regardless of what TkpChangeFocus does with the real X focus so
	 * that Tk widgets track focus commands when there is no window
	 * manager. GenerateFocusEvents will set up a serial number marker so
	 * we discard focus events that are triggered by the ChangeFocus.
	 */

	serial = TkpChangeFocus(TkpGetWrapperWindow(topLevelPtr), force);
	if (serial != 0) {
	    displayFocusPtr->focusSerial = serial;
	}
	GenerateFocusEvents(displayFocusPtr->focusWinPtr, winPtr);
804
805
806
807
808
809
810
811

812
813
814
815
816
817
818
819
820
821
822
823
824
788
789
790
791
792
793
794

795
796
797
798
799
800

801
802
803
804
805
806
807







-
+





-







 *	Various things get cleaned up and recycled.
 *
 *----------------------------------------------------------------------
 */

void
TkFocusDeadWindow(
    TkWindow *winPtr)	/* Information about the window that is being
    register TkWindow *winPtr)	/* Information about the window that is being
				 * deleted. */
{
    ToplevelFocusInfo *tlFocusPtr, *prevPtr;
    DisplayFocusInfo *displayFocusPtr;
    TkDisplay *dispPtr = winPtr->dispPtr;
    int noMatch = 1;

    /*
     * Certain special windows like those used for send and clipboard have no
     * mainPtr.
     */

    if (winPtr->mainPtr == NULL) {
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860

861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877









878
879
880
881
882
883
884







-

















-

















-
-
-
-
-
-
-
-
-







	    }
	    if (prevPtr == NULL) {
		winPtr->mainPtr->tlFocusPtr = tlFocusPtr->nextPtr;
	    } else {
		prevPtr->nextPtr = tlFocusPtr->nextPtr;
	    }
	    ckfree(tlFocusPtr);
	    noMatch = 0;
	    break;
	} else if (winPtr == tlFocusPtr->focusWinPtr) {
	    /*
	     * The deleted window had the focus for its top-level: move the
	     * focus to the top-level itself.
	     */

	    tlFocusPtr->focusWinPtr = tlFocusPtr->topLevelPtr;
	    if ((displayFocusPtr->focusWinPtr == winPtr)
		    && !(tlFocusPtr->topLevelPtr->flags & TK_ALREADY_DEAD)) {
		DEBUG(dispPtr, ("forwarding focus to %s after %s died\n",
			tlFocusPtr->topLevelPtr->pathName, winPtr->pathName));
		GenerateFocusEvents(displayFocusPtr->focusWinPtr,
			tlFocusPtr->topLevelPtr);
		displayFocusPtr->focusWinPtr = tlFocusPtr->topLevelPtr;
		dispPtr->focusPtr = tlFocusPtr->topLevelPtr;
	    }
	    noMatch = 0;
	    break;
	}
    }

    /*
     * Occasionally, things can become unsynchronized. Move them back into
     * synch now. [Bug 2496114]
     */

    if (displayFocusPtr->focusWinPtr == winPtr) {
	DEBUG(dispPtr, ("focus cleared after %s died\n", winPtr->pathName));
	displayFocusPtr->focusWinPtr = NULL;
    }

    if (displayFocusPtr->focusOnMapPtr == winPtr) {
	displayFocusPtr->focusOnMapPtr = NULL;
    }

    /*
     * It may happen that the search above for focus records that refer
     * to this window did not find any match. In such a case, when the
     * dead window had the focus, release it.
     */
    if (noMatch && (dispPtr->focusPtr == winPtr)) {
	dispPtr->focusPtr = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateFocusEvents --
 *
970
971
972
973
974
975
976
977

978
979
980
981
982
983
984
942
943
944
945
946
947
948

949
950
951
952
953
954
955
956







-
+







 */

static void
FocusMapProc(
    ClientData clientData,	/* Toplevel window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    DisplayFocusInfo *displayFocusPtr;

    if (eventPtr->type == VisibilityNotify) {
	displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr,
		winPtr->dispPtr);
	DEBUG(winPtr->dispPtr, ("auto-focussing on %s, force %d\n",
		winPtr->pathName, displayFocusPtr->forceFocus));
1024
1025
1026
1027
1028
1029
1030
1031

1032
1033
1034
1035
1036
1037
1038
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010







-
+







	}
    }

    /*
     * The record doesn't exist yet. Make a new one.
     */

    displayFocusPtr = (DisplayFocusInfo *)ckalloc(sizeof(DisplayFocusInfo));
    displayFocusPtr = ckalloc(sizeof(DisplayFocusInfo));
    displayFocusPtr->dispPtr = dispPtr;
    displayFocusPtr->focusWinPtr = NULL;
    displayFocusPtr->focusOnMapPtr = NULL;
    displayFocusPtr->forceFocus = 0;
    displayFocusPtr->focusSerial = 0;
    displayFocusPtr->nextPtr = mainPtr->displayFocusPtr;
    mainPtr->displayFocusPtr = displayFocusPtr;
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032







-
+







 *
 *	Free resources associated with maintaining the focus.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	This mainPtr should no longer access focus information.
 *	This mainPtr should no long access focus information.
 *
 *----------------------------------------------------------------------
 */

void
TkFocusFree(
    TkMainInfo *mainPtr)	/* Record that identifies a particular
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138







-
+







    }

    if (subWinPtr == winPtr) {
	/*
	 * Move focus to new toplevel.
	 */

	ToplevelFocusInfo *newTlFocusPtr = (ToplevelFocusInfo *)ckalloc(sizeof(ToplevelFocusInfo));
	ToplevelFocusInfo *newTlFocusPtr = ckalloc(sizeof(ToplevelFocusInfo));

	newTlFocusPtr->topLevelPtr = winPtr;
	newTlFocusPtr->focusWinPtr = tlFocusPtr->focusWinPtr;
	newTlFocusPtr->nextPtr = winPtr->mainPtr->tlFocusPtr;
	winPtr->mainPtr->tlFocusPtr = newTlFocusPtr;

	/*
1176
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162







-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkFocusJoin --
 *
 *	Remove the focus record for this window that is no longer managed
 *	Remove the focus record for this window that is nolonger managed
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A tlFocusPtr record is removed
 *

Changes to generic/tkFont.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15







16
17
18
19
20
21
22






-
-
+
+







-
-
-
-
-
-
-







/*
 * tkFont.c --
 *
 *	This file maintains a database of fonts for the Tk toolkit. It also
 *	provides several utility functions for measuring and displaying text.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkFont.h"
#if defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"    /* Defines TK_DRAW_IN_CONTEXT */
#endif

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The following structure is used to keep track of all the fonts that exist
 * in the current application. It must be stored in the TkMainInfo for the
 * application.
 */

69
70
71
72
73
74
75
76
77
78



79
80
81
82
83
84
85
62
63
64
65
66
67
68



69
70
71
72
73
74
75
76
77
78







-
-
-
+
+
+







 * token.
 */

typedef struct LayoutChunk {
    const char *start;		/* Pointer to simple string to be displayed.
				 * This is a pointer into the TkTextLayout's
				 * string. */
    Tcl_Size numBytes;		/* The number of bytes in this chunk. */
    Tcl_Size numChars;		/* The number of characters in this chunk. */
    Tcl_Size numDisplayChars;	/* The number of characters to display when
    int numBytes;		/* The number of bytes in this chunk. */
    int numChars;		/* The number of characters in this chunk. */
    int numDisplayChars;	/* The number of characters to display when
				 * this chunk is displayed. Can be less than
				 * numChars if extra space characters were
				 * absorbed by the end of the chunk. This will
				 * be < 0 if this is a chunk that is holding a
				 * tab or newline. */
    int x, y;			/* The origin of the first character in this
				 * chunk with respect to the upper-left hand
94
95
96
97
98
99
100
101

102
103

104
105
106
107
108
109
110
87
88
89
90
91
92
93

94
95

96
97
98
99
100
101
102
103







-
+

-
+







} LayoutChunk;

typedef struct TextLayout {
    Tk_Font tkfont;		/* The font used when laying out the text. */
    const char *string;		/* The string that was layed out. */
    int width;			/* The maximum width of all lines in the text
				 * layout. */
    Tcl_Size numChunks;		/* Number of chunks actually used in following
    int numChunks;		/* Number of chunks actually used in following
				 * array. */
    LayoutChunk chunks[TKFLEXARRAY];/* Array of chunks. The actual size will be
    LayoutChunk chunks[1];	/* Array of chunks. The actual size will be
				 * maxChunks. THIS FIELD MUST BE THE LAST IN
				 * THE STRUCTURE. */
} TextLayout;

/*
 * The following structures are used as two-way maps between the values for
 * the fields in the TkFontAttributes structure and the strings used in Tcl,
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340

341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357


358
359
360
361

362
363
364
365
366
367
368
369
370
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332

333
334
335
336
337
338

339
340
341
342
343
344
345
346
347
348


349
350
351
352
353

354


355
356
357
358
359
360
361







-
+








-
+





-
+









-
-
+
+



-
+
-
-







	((const TkFontAttributes *) &((TkFont *) (tkfont))->fa)

#define GetFontMetrics(tkfont)    \
	((const TkFontMetrics *) &((TkFont *) (tkfont))->fm)


static int		ConfigAttributesObj(Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Size objc, Tcl_Obj *const objv[],
			    Tk_Window tkwin, int objc, Tcl_Obj *const objv[],
			    TkFontAttributes *faPtr);
static void		DupFontObjProc(Tcl_Obj *srcObjPtr, Tcl_Obj *dupObjPtr);
static int		FieldSpecified(const char *field);
static void		FreeFontObj(Tcl_Obj *objPtr);
static void		FreeFontObjProc(Tcl_Obj *objPtr);
static int		GetAttributeInfoObj(Tcl_Interp *interp,
			    const TkFontAttributes *faPtr, Tcl_Obj *objPtr);
static LayoutChunk *	NewChunk(TextLayout **layoutPtrPtr, int *maxPtr,
			    const char *start, Tcl_Size numChars, int curX,
			    const char *start, int numChars, int curX,
			    int newX, int y);
static int		ParseFontNameObj(Tcl_Interp *interp, Tk_Window tkwin,
			    Tcl_Obj *objPtr, TkFontAttributes *faPtr);
static void		RecomputeWidgets(TkWindow *winPtr);
static int		SetFontFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static void		TheWorldHasChanged(void *clientData);
static void		TheWorldHasChanged(ClientData clientData);
static void		UpdateDependentFonts(TkFontInfo *fiPtr,
			    Tk_Window tkwin, Tcl_HashEntry *namedHashPtr);

/*
 * The following structure defines the implementation of the "font" Tcl
 * object, used for drawing. The internalRep.twoPtrValue.ptr1 field of each
 * font object points to the TkFont structure for the font, or NULL.
 */

const TkObjType tkFontObjType = {
    {"font",			/* name */
const Tcl_ObjType tkFontObjType = {
    "font",			/* name */
    FreeFontObjProc,		/* freeIntRepProc */
    DupFontObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    SetFontFromAny		/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *---------------------------------------------------------------------------
 *
 * TkFontPkgInit --
 *
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387







-
+







 *---------------------------------------------------------------------------
 */

void
TkFontPkgInit(
    TkMainInfo *mainPtr)	/* The application being created. */
{
    TkFontInfo *fiPtr = (TkFontInfo *)ckalloc(sizeof(TkFontInfo));
    TkFontInfo *fiPtr = ckalloc(sizeof(TkFontInfo));

    Tcl_InitHashTable(&fiPtr->fontCache, TCL_STRING_KEYS);
    Tcl_InitHashTable(&fiPtr->namedTable, TCL_STRING_KEYS);
    fiPtr->mainPtr = mainPtr;
    fiPtr->updatePending = 0;
    mainPtr->fontInfoPtr = fiPtr;

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
409
410
411
412
413
414
415

416

417
418
419
420

421

422
423
424
425
426
427
428







-

-




-

-







void
TkFontPkgFree(
    TkMainInfo *mainPtr)	/* The application being deleted. */
{
    TkFontInfo *fiPtr = mainPtr->fontInfoPtr;
    Tcl_HashEntry *hPtr, *searchPtr;
    Tcl_HashSearch search;
#ifdef PURIFY
    int fontsLeft = 0;
#endif

    for (searchPtr = Tcl_FirstHashEntry(&fiPtr->fontCache, &search);
	    searchPtr != NULL;
	    searchPtr = Tcl_NextHashEntry(&search)) {
#ifdef PURIFY
	fontsLeft++;
#endif
#ifdef DEBUG_FONTS
	fprintf(stderr, "Font %s still in cache.\n",
		(char *) Tcl_GetHashKey(&fiPtr->fontCache, searchPtr));
#endif
    }

#ifdef PURIFY
473
474
475
476
477
478
479
480

481
482
483
484
485
486

487
488
489
490
491
492
493
460
461
462
463
464
465
466

467
468
469
470
471
472

473
474
475
476
477
478
479
480







-
+





-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_FontObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int index;
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr;
    static const char *const optionStrings[] = {
	"actual",	"configure",	"create",	"delete",
	"families",	"measure",	"metrics",	"names",
	NULL
    };
    enum options {
524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525







-
+







	    return TCL_ERROR;
	}

	/*
	 * Next parameter may be an option.
	 */

	n = 3 + skip;
	n = skip + 3;
	optPtr = NULL;
	charPtr = NULL;
	if (n < objc) {
	    s = Tcl_GetString(objv[n]);
	    if (s[0] == '-' && s[1] != '-') {
		optPtr = objv[n];
		n++;
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578
579

580
581

582
583

584
585
586


587
588
589
590
591
592
593
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563
564
565

566
567

568
569

570
571


572
573
574
575
576
577
578
579
580







-
+









-
+

-
+

-
+

-
-
+
+








	/*
	 * If there were fewer than 3 args, or args remain, that's an error.
	 */

	if (objc < 3 || n < objc) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "font ?-displayof window? ?-option? ?--? ?char?");
		    "font ?-displayof window? ?option? ?--? ?char?");
	    return TCL_ERROR;
	}

	/*
	 * The 'charPtr' arg must be a single Unicode.
	 */

	if (charPtr != NULL) {
	    const char *string = Tcl_GetString(charPtr);
	    size_t len = Tcl_UtfToUniChar(string, &uniChar);
	    int len = TkUtfToUniChar(string, &uniChar);

	    if (len != (size_t)charPtr->length) {
	    if (len != charPtr->length) {
		resultPtr = Tcl_NewStringObj(
			"expected a single character but got \"", TCL_INDEX_NONE);
			"expected a single character but got \"", -1);
		Tcl_AppendLimitedToObj(resultPtr, string,
			TCL_INDEX_NONE, 40, "...");
		Tcl_AppendToObj(resultPtr, "\"", TCL_INDEX_NONE);
			-1, 40, "...");
		Tcl_AppendToObj(resultPtr, "\"", -1);
		Tcl_SetObjResult(interp, resultPtr);
		Tcl_SetErrorCode(interp, "TK", "VALUE", "FONT_SAMPLE", NULL);
		return TCL_ERROR;
	    }
	}

	/*
623
624
625
626
627
628
629
630

631
632

633
634
635
636
637
638
639
610
611
612
613
614
615
616

617
618

619
620
621
622
623
624
625
626







-
+

-
+








    	if (objc < 3) {
    	    Tcl_WrongNumArgs(interp, 2, objv, "fontname ?-option value ...?");
    	    return TCL_ERROR;
    	}
    	string = Tcl_GetString(objv[2]);
    	namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, string);
	nfPtr = NULL;
	nfPtr = NULL;		/* lint. */
    	if (namedHashPtr != NULL) {
    	    nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
    	    nfPtr = Tcl_GetHashValue(namedHashPtr);
    	}
    	if ((namedHashPtr == NULL) || nfPtr->deletePending) {
    	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
    		    "named font \"%s\" doesn't exist", string));
    	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "FONT", string, NULL);
    	    return TCL_ERROR;
    	}
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

691
692
693
694
695
696
697
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
684







-
+
















-
+







	}
	if (name == NULL) {
	    /*
	     * No font name specified. Generate one of the form "fontX".
	     */

	    for (i = 1; ; i++) {
		snprintf(buf, sizeof(buf), "font%d", i);
		sprintf(buf, "font%d", i);
		namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, buf);
		if (namedHashPtr == NULL) {
		    break;
		}
	    }
	    name = buf;
	    skip = 2;
	}
	TkInitFontAttributes(&fa);
	if (ConfigAttributesObj(interp, tkwin, objc - skip, objv + skip,
		&fa) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (TkCreateNamedFont(interp, tkwin, name, &fa) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(name, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
	break;
    }
    case FONT_DELETE: {
	int i, result = TCL_OK;
	const char *string;

	/*
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
726
727
728

729
730
731
732
733
734
735
736
737

738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754

755
756
757

758
759
760
761
762
763
764

765
766

767
768
769
770
771
772
773
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714

715

716
717
718
719
720
721
722

723
724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739

740
741
742

743
744
745
746
747
748
749

750
751

752
753
754
755
756
757
758
759







-
+









-
+
-







-
+









-
+






-
+


-
+






-
+

-
+







    }
    case FONT_FAMILIES: {
	int skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin);

	if (skip < 0) {
	    return TCL_ERROR;
	}
	if (objc != 2 + skip) {
	if (objc - skip != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?");
	    return TCL_ERROR;
	}
	TkpGetFontFamilies(interp, tkwin);
	break;
    }
    case FONT_MEASURE: {
	const char *string;
	Tk_Font tkfont;
	Tcl_Size length = 0;
	int length = 0, skip = 0;
	int skip = 0;

	if (objc > 4) {
	    skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin);
	    if (skip < 0) {
		return TCL_ERROR;
	    }
	}
	if (objc != 4 + skip) {
	if (objc - skip != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "font ?-displayof window? text");
	    return TCL_ERROR;
	}
	tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]);
	if (tkfont == NULL) {
	    return TCL_ERROR;
	}
	string = Tcl_GetStringFromObj(objv[3 + skip], &length);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
	Tcl_SetObjResult(interp, Tcl_NewIntObj(
		Tk_TextWidth(tkfont, string, length)));
	Tk_FreeFont(tkfont);
	break;
    }
    case FONT_METRICS: {
	Tk_Font tkfont;
	int skip, i;
	int skip, index, i;
	const TkFontMetrics *fmPtr;
	static const char *const switches[] = {
	    "-ascent", "-descent", "-fixed", "-linespace", NULL
	    "-ascent", "-descent", "-linespace", "-fixed", NULL
	};

	skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin);
	if (skip < 0) {
	    return TCL_ERROR;
	}
	if ((objc < 3) || (objc > 4 + skip)) {
	if ((objc < 3) || ((objc - skip) > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "font ?-displayof window? ?-option?");
		    "font ?-displayof window? ?option?");
	    return TCL_ERROR;
	}
	tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]);
	if (tkfont == NULL) {
	    return TCL_ERROR;
	}
	objc -= skip;
784
785
786
787
788
789
790
791
792


793
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811

812
813
814

815
816
817
818

819
820
821
822
823
824
825
770
771
772
773
774
775
776


777
778
779

780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796

797
798
799

800
801
802
803

804
805
806
807
808
809
810
811







-
-
+
+

-
+
















-
+


-
+



-
+







		Tk_FreeFont(tkfont);
		return TCL_ERROR;
	    }
	    i = 0;		/* Needed only to prevent compiler warning. */
	    switch (index) {
	    case 0: i = fmPtr->ascent;			break;
	    case 1: i = fmPtr->descent;			break;
	    case 2: i = fmPtr->fixed;			break;
	    case 3: i = fmPtr->ascent + fmPtr->descent;	break;
	    case 2: i = fmPtr->ascent + fmPtr->descent;	break;
	    case 3: i = fmPtr->fixed;			break;
	    }
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(i));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
	}
	Tk_FreeFont(tkfont);
	break;
    }
    case FONT_NAMES: {
	Tcl_HashSearch search;
	Tcl_HashEntry *namedHashPtr;
	Tcl_Obj *resultPtr;

	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 1, objv, "names");
	    return TCL_ERROR;
	}
	resultPtr = Tcl_NewObj();
	namedHashPtr = Tcl_FirstHashEntry(&fiPtr->namedTable, &search);
	while (namedHashPtr != NULL) {
	    NamedFont *nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
	    NamedFont *nfPtr = Tcl_GetHashValue(namedHashPtr);

	    if (!nfPtr->deletePending) {
		char *string = (char *)Tcl_GetHashKey(&fiPtr->namedTable,
		char *string = Tcl_GetHashKey(&fiPtr->namedTable,
			namedHashPtr);

		Tcl_ListObjAppendElement(NULL, resultPtr,
			Tcl_NewStringObj(string, TCL_INDEX_NONE));
			Tcl_NewStringObj(string, -1));
	    }
	    namedHashPtr = Tcl_NextHashEntry(&search);
	}
	Tcl_SetObjResult(interp, resultPtr);
	break;
    }
    }
850
851
852
853
854
855
856
857

858
859
860
861
862
863
864
865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886

887
888

889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922

923
924
925
926
927
928
929
930




931
932
933
934
935
936
937


938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
836
837
838
839
840
841
842

843
844
845
846
847
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871

872
873

874











875
876
877
878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
893
894
895

896
897
898
899
900




901
902
903
904
905
906
907
908
909


910
911
912







913
914
915
916
917
918
919







-
+












-
+















-
+

-
+
-
-
-
-
-
-
-
-
-
-
-











-










-
+




-
-
-
-
+
+
+
+





-
-
+
+

-
-
-
-
-
-
-







    TkFontInfo *fiPtr,		/* Info about application's fonts. */
    Tk_Window tkwin,		/* A window in the application. */
    Tcl_HashEntry *namedHashPtr)/* The named font that is changing. */
{
    Tcl_HashEntry *cacheHashPtr;
    Tcl_HashSearch search;
    TkFont *fontPtr;
    NamedFont *nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
    NamedFont *nfPtr = Tcl_GetHashValue(namedHashPtr);

    if (nfPtr->refCount == 0) {
	/*
	 * Well nobody's using this named font, so don't have to tell any
	 * widgets to recompute themselves.
	 */

	return;
    }

    cacheHashPtr = Tcl_FirstHashEntry(&fiPtr->fontCache, &search);
    while (cacheHashPtr != NULL) {
	for (fontPtr = (TkFont *)Tcl_GetHashValue(cacheHashPtr);
	for (fontPtr = Tcl_GetHashValue(cacheHashPtr);
		fontPtr != NULL; fontPtr = fontPtr->nextPtr) {
	    if (fontPtr->namedHashPtr == namedHashPtr) {
		TkpGetFontFromAttributes(fontPtr, tkwin, &nfPtr->fa);
		if (!fiPtr->updatePending) {
		    fiPtr->updatePending = 1;
		    Tcl_DoWhenIdle(TheWorldHasChanged, fiPtr);
		}
	    }
	}
	cacheHashPtr = Tcl_NextHashEntry(&search);
    }
}

static void
TheWorldHasChanged(
    void *clientData)	/* Info about application's fonts. */
    ClientData clientData)	/* Info about application's fonts. */
{
    TkFontInfo *fiPtr = (TkFontInfo *)clientData;
    TkFontInfo *fiPtr = clientData;

    /*
     * On macOS it is catastrophic to recompute all widgets while the
     * [NSView drawRect] method is drawing. The best that we can do in
     * that situation is to abort the recomputation and hope for the best.
     * This is ignored on other platforms.
     */

    if (TkpWillDrawWidget(NULL)) {
	return;
    }

    fiPtr->updatePending = 0;
    RecomputeWidgets(fiPtr->mainPtr->winPtr);
}

static void
RecomputeWidgets(
    TkWindow *winPtr)		/* Window to which command is sent. */
{
    Tk_ClassWorldChangedProc *proc =
	    Tk_GetClassProc(winPtr->classProcsPtr, worldChangedProc);
    TkWindow *tkwinPtr;

    if (proc != NULL) {
	proc(winPtr->instanceData);
    }

    /*
     * Notify all the descendants of this window that the world has changed.
     *
     * This could be done recursively or iteratively. The recursive version is
     * easier to implement and understand, and typically, windows with a -font
     * option will be leaf nodes in the widget hierarchy (buttons, labels,
     * option will be leaf nodes in the widget heirarchy (buttons, labels,
     * etc.), so the recursion depth will be shallow.
     *
     * However, the additional overhead of the recursive calls may become a
     * performance problem if typical usage alters such that -font'ed widgets
     * appear high in the hierarchy, causing deep recursion. This could happen
     * with text widgets, or more likely with the labelframe
     * widget. With these widgets it is possible, even likely, that a
     * -font'ed widget (text or labelframe) will not be a leaf node, but
     * appear high in the heirarchy, causing deep recursion. This could happen
     * with text widgets, or more likely with the (not yet existant) labeled
     * frame widget. With these widgets it is possible, even likely, that a
     * -font'ed widget (text or labeled frame) will not be a leaf node, but
     * will instead have many descendants. If this is ever found to cause a
     * performance problem, it may be worth investigating an iterative version
     * of the code below.
     */

    for (tkwinPtr=winPtr->childList ; tkwinPtr!=NULL ; tkwinPtr=tkwinPtr->nextPtr) {
	RecomputeWidgets(tkwinPtr);
    for (winPtr=winPtr->childList ; winPtr!=NULL ; winPtr=winPtr->nextPtr) {
	RecomputeWidgets(winPtr);
    }

    /*
     * Broadcast font change virtually for mega-widget layout managers.
     * Do this after the font change has been propagated to core widgets.
    */
    Tk_SendVirtualEvent((Tk_Window)winPtr, "TkWorldChanged",
			Tcl_NewStringObj("FontChanged",-1));
}

/*
 *---------------------------------------------------------------------------
 *
 * TkCreateNamedFont --
 *
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
946
947
948
949
950
951
952

953
954
955
956
957
958
959
960







-
+







    TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr;
    Tcl_HashEntry *namedHashPtr;
    int isNew;
    NamedFont *nfPtr;

    namedHashPtr = Tcl_CreateHashEntry(&fiPtr->namedTable, name, &isNew);
    if (!isNew) {
	nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
	nfPtr = Tcl_GetHashValue(namedHashPtr);
	if (!nfPtr->deletePending) {
	    if (interp) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"named font \"%s\" already exists", name));
		Tcl_SetErrorCode(interp, "TK", "FONT", "EXISTS", NULL);
	    }
	    return TCL_ERROR;
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982







-
+








	nfPtr->fa = *faPtr;
	nfPtr->deletePending = 0;
	UpdateDependentFonts(fiPtr, tkwin, namedHashPtr);
	return TCL_OK;
    }

    nfPtr = (NamedFont *)ckalloc(sizeof(NamedFont));
    nfPtr = ckalloc(sizeof(NamedFont));
    nfPtr->deletePending = 0;
    Tcl_SetHashValue(namedHashPtr, nfPtr);
    nfPtr->fa = *faPtr;
    nfPtr->refCount = 0;
    nfPtr->deletePending = 0;
    return TCL_OK;
}
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1021







-
+







	if (interp) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "named font \"%s\" doesn't exist", name));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "FONT", name, NULL);
	}
	return TCL_ERROR;
    }
    nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
    nfPtr = Tcl_GetHashValue(namedHashPtr);
    if (nfPtr->refCount != 0) {
	nfPtr->deletePending = 1;
    } else {
	Tcl_DeleteHashEntry(namedHashPtr);
	ckfree(nfPtr);
    }
    return TCL_OK;
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063







-
+







    Tk_Window tkwin,		/* For display on which font will be used. */
    const char *string)		/* String describing font, as: named font,
				 * native format, or parseable string. */
{
    Tk_Font tkfont;
    Tcl_Obj *strPtr;

    strPtr = Tcl_NewStringObj(string, TCL_INDEX_NONE);
    strPtr = Tcl_NewStringObj(string, -1);
    Tcl_IncrRefCount(strPtr);
    tkfont = Tk_AllocFontFromObj(interp, tkwin, strPtr);
    Tcl_DecrRefCount(strPtr);
    return tkfont;
}

/*
1124
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102

1103
1104
1105
1106
1107
1108
1109
1110







-
+




-
+







{
    TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr;
    Tcl_HashEntry *cacheHashPtr, *namedHashPtr;
    TkFont *fontPtr, *firstFontPtr, *oldFontPtr;
    int isNew, descent;
    NamedFont *nfPtr;

    if (objPtr->typePtr != &tkFontObjType.objType
    if (objPtr->typePtr != &tkFontObjType
	    || objPtr->internalRep.twoPtrValue.ptr2 != fiPtr) {
	SetFontFromAny(interp, objPtr);
    }

    oldFontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
    oldFontPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if (oldFontPtr != NULL) {
	if (oldFontPtr->resourceRefCount == 0) {
	    /*
	     * This is a stale reference: it refers to a TkFont that's no
	     * longer in use. Clear the reference.
	     */

1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134
1135
1136
1137
1138
1139







-
+







    if (oldFontPtr != NULL) {
	cacheHashPtr = oldFontPtr->cacheHashPtr;
	FreeFontObj(objPtr);
    } else {
	cacheHashPtr = Tcl_CreateHashEntry(&fiPtr->fontCache,
		Tcl_GetString(objPtr), &isNew);
    }
    firstFontPtr = (TkFont *)Tcl_GetHashValue(cacheHashPtr);
    firstFontPtr = Tcl_GetHashValue(cacheHashPtr);
    for (fontPtr = firstFontPtr; (fontPtr != NULL);
	    fontPtr = fontPtr->nextPtr) {
	if (Tk_Screen(tkwin) == fontPtr->screen) {
	    fontPtr->resourceRefCount++;
	    fontPtr->objRefCount++;
	    objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
	    objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;
1181
1182
1183
1184
1185
1186
1187
1188

1189
1190
1191
1192
1193
1194
1195
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162







-
+







    namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable,
	    Tcl_GetString(objPtr));
    if (namedHashPtr != NULL) {
	/*
	 * Construct a font based on a named font.
	 */

	nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
	nfPtr = Tcl_GetHashValue(namedHashPtr);
	nfPtr->refCount++;

	fontPtr = TkpGetFontFromAttributes(NULL, tkwin, &nfPtr->fa);
    } else {
	/*
	 * Native font?
	 */
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203







-
+








    if (fontPtr == NULL) {
	if (isNew) {
	    Tcl_DeleteHashEntry(cacheHashPtr);
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"failed to allocate font due to internal system font engine"
		" problem", TCL_INDEX_NONE));
		" problem", -1));
	Tcl_SetErrorCode(interp, "TK", "FONT", "INTERNAL_PROBLEM", NULL);
	return NULL;
    }

    fontPtr->resourceRefCount = 1;
    fontPtr->objRefCount = 1;
    fontPtr->cacheHashPtr = cacheHashPtr;
1309
1310
1311
1312
1313
1314
1315
1316

1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1276
1277
1278
1279
1280
1281
1282

1283
1284
1285
1286
1287

1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318
1319
1320
1321
1322







-
+




-
+










-
















-
+







				 * in. */
    Tcl_Obj *objPtr)		/* The object from which to get the font. */
{
    TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr;
    TkFont *fontPtr;
    Tcl_HashEntry *hashPtr;

    if (objPtr->typePtr != &tkFontObjType.objType
    if (objPtr->typePtr != &tkFontObjType
	    || objPtr->internalRep.twoPtrValue.ptr2 != fiPtr) {
	SetFontFromAny(NULL, objPtr);
    }

    fontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
    fontPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if (fontPtr != NULL) {
	if (fontPtr->resourceRefCount == 0) {
	    /*
	     * This is a stale reference: it refers to a TkFont that's no
	     * longer in use. Clear the reference.
	     */

	    FreeFontObj(objPtr);
	    fontPtr = NULL;
	} else if (Tk_Screen(tkwin) == fontPtr->screen) {
	    fontPtr->resourceRefCount++;
	    return (Tk_Font) fontPtr;
	}
    }

    /*
     * Next, search the list of fonts that have the name we want, to see if
     * one of them is for the right screen.
     */

    if (fontPtr != NULL) {
	hashPtr = fontPtr->cacheHashPtr;
	FreeFontObj(objPtr);
    } else {
	hashPtr = Tcl_FindHashEntry(&fiPtr->fontCache, Tcl_GetString(objPtr));
    }
    if (hashPtr != NULL) {
	for (fontPtr = (TkFont *)Tcl_GetHashValue(hashPtr); fontPtr != NULL;
	for (fontPtr = Tcl_GetHashValue(hashPtr); fontPtr != NULL;
		fontPtr = fontPtr->nextPtr) {
	    if (Tk_Screen(tkwin) == fontPtr->screen) {
		fontPtr->objRefCount++;
		objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
		objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;
		return (Tk_Font) fontPtr;
	    }
1377
1378
1379
1380
1381
1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363

1364
1365
1366
1367
1368
1369
1370
1371







-
+













-
+







 *	TkFont pointer is NULL.
 *
 *----------------------------------------------------------------------
 */

static int
SetFontFromAny(
    TCL_UNUSED(Tcl_Interp *),	/* Used for error reporting if not NULL. */
    Tcl_Interp *interp,		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr)		/* The object to convert. */
{
    const Tcl_ObjType *typePtr;

    /*
     * Free the old internalRep before setting the new one.
     */

    Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }
    objPtr->typePtr = &tkFontObjType.objType;
    objPtr->typePtr = &tkFontObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
    objPtr->internalRep.twoPtrValue.ptr2 = NULL;

    return TCL_OK;
}

/*
1453
1454
1455
1456
1457
1458
1459

1460

1461
1462
1463
1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475
1476

1477
1478
1479
1480
1481
1482
1483
1419
1420
1421
1422
1423
1424
1425
1426

1427
1428
1429
1430
1431
1432
1433
1434
1435

1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450







+
-
+








-
+






-
+







{
    TkFont *fontPtr = (TkFont *) tkfont, *prevPtr;
    NamedFont *nfPtr;

    if (fontPtr == NULL) {
	return;
    }
    fontPtr->resourceRefCount--;
    if (fontPtr->resourceRefCount-- > 1) {
    if (fontPtr->resourceRefCount > 0) {
	return;
    }
    if (fontPtr->namedHashPtr != NULL) {
	/*
	 * This font derived from a named font. Reduce the reference count on
	 * the named font and free it if no-one else is using it.
	 */

	nfPtr = (NamedFont *)Tcl_GetHashValue(fontPtr->namedHashPtr);
	nfPtr = Tcl_GetHashValue(fontPtr->namedHashPtr);
	if ((nfPtr->refCount-- <= 1) && nfPtr->deletePending) {
	    Tcl_DeleteHashEntry(fontPtr->namedHashPtr);
	    ckfree(nfPtr);
	}
    }

    prevPtr = (TkFont *)Tcl_GetHashValue(fontPtr->cacheHashPtr);
    prevPtr = Tcl_GetHashValue(fontPtr->cacheHashPtr);
    if (prevPtr == fontPtr) {
	if (fontPtr->nextPtr == NULL) {
	    Tcl_DeleteHashEntry(fontPtr->cacheHashPtr);
	} else {
	    Tcl_SetHashValue(fontPtr->cacheHashPtr, fontPtr->nextPtr);
	}
    } else {
1547
1548
1549
1550
1551
1552
1553
1554

1555
1556
1557


1558
1559
1560
1561
1562
1563
1564
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
1531
1532







-
+


-
+
+







    objPtr->typePtr = NULL;
}

static void
FreeFontObj(
    Tcl_Obj *objPtr)		/* The object we are releasing. */
{
    TkFont *fontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
    TkFont *fontPtr = objPtr->internalRep.twoPtrValue.ptr1;

    if (fontPtr != NULL) {
	if ((fontPtr->objRefCount-- <= 1) && (fontPtr->resourceRefCount == 0)) {
	fontPtr->objRefCount--;
	if ((fontPtr->resourceRefCount == 0) && (fontPtr->objRefCount == 0)) {
	    ckfree(fontPtr);
	}
	objPtr->internalRep.twoPtrValue.ptr1 = NULL;
	objPtr->internalRep.twoPtrValue.ptr2 = NULL;
    }
}

1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1549
1550
1551
1552
1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
1563







-
+







 */

static void
DupFontObjProc(
    Tcl_Obj *srcObjPtr,		/* The object we are copying from. */
    Tcl_Obj *dupObjPtr)		/* The object we are copying to. */
{
    TkFont *fontPtr = (TkFont *)srcObjPtr->internalRep.twoPtrValue.ptr1;
    TkFont *fontPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;

    dupObjPtr->typePtr = srcObjPtr->typePtr;
    dupObjPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
    dupObjPtr->internalRep.twoPtrValue.ptr2
	    = srcObjPtr->internalRep.twoPtrValue.ptr2;

    if (fontPtr != NULL) {
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
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







-
+








-
+






-
+






-
+





-
+







	/*
	 * Inline, capitalize the first letter of each word, lowercase the
	 * rest of the letters in each word, and then take out the spaces
	 * between the words. This may make the DString shorter, which is safe
	 * to do.
	 */

	Tcl_DStringAppend(dsPtr, family, TCL_INDEX_NONE);
	Tcl_DStringAppend(dsPtr, family, -1);

	src = dest = Tcl_DStringValue(dsPtr) + len;
	upper = 1;
	for (; *src != '\0'; ) {
	    while (isspace(UCHAR(*src))) { /* INTL: ISO space */
		src++;
		upper = 1;
	    }
	    src += Tcl_UtfToUniChar(src, &ch);
	    src += TkUtfToUniChar(src, &ch);
	    if (upper) {
		ch = Tcl_UniCharToUpper(ch);
		upper = 0;
	    } else {
		ch = Tcl_UniCharToLower(ch);
	    }
	    dest += Tcl_UniCharToUtf(ch, dest);
	    dest += TkUniCharToUtf(ch, dest);
	}
	*dest = '\0';
	Tcl_DStringSetLength(dsPtr, dest - Tcl_DStringValue(dsPtr));
	family = Tcl_DStringValue(dsPtr) + len;
    }
    if (family != Tcl_DStringValue(dsPtr) + len) {
	Tcl_DStringAppend(dsPtr, family, TCL_INDEX_NONE);
	Tcl_DStringAppend(dsPtr, family, -1);
	family = Tcl_DStringValue(dsPtr) + len;
    }

    if (strcasecmp(family, "NewCenturySchoolbook") == 0) {
	Tcl_DStringSetLength(dsPtr, len);
	Tcl_DStringAppend(dsPtr, "NewCenturySchlbk", TCL_INDEX_NONE);
	Tcl_DStringAppend(dsPtr, "NewCenturySchlbk", -1);
	family = Tcl_DStringValue(dsPtr) + len;
    }

    /*
     * Get the string to use for the weight.
     */

1811
1812
1813
1814
1815
1816
1817
1818

1819
1820
1821

1822
1823

1824
1825
1826

1827
1828
1829
1830
1831
1832
1833
1779
1780
1781
1782
1783
1784
1785

1786
1787
1788

1789
1790

1791
1792
1793

1794
1795
1796
1797
1798
1799
1800
1801







-
+


-
+

-
+


-
+







     * and not italic.
     */

    if ((slantString == NULL) && (weightString == NULL)) {
	if ((strcmp(family, "Times") == 0)
		|| (strcmp(family, "NewCenturySchlbk") == 0)
		|| (strcmp(family, "Palatino") == 0)) {
	    Tcl_DStringAppend(dsPtr, "-Roman", TCL_INDEX_NONE);
	    Tcl_DStringAppend(dsPtr, "-Roman", -1);
	}
    } else {
	Tcl_DStringAppend(dsPtr, "-", TCL_INDEX_NONE);
	Tcl_DStringAppend(dsPtr, "-", -1);
	if (weightString != NULL) {
	    Tcl_DStringAppend(dsPtr, weightString, TCL_INDEX_NONE);
	    Tcl_DStringAppend(dsPtr, weightString, -1);
	}
	if (slantString != NULL) {
	    Tcl_DStringAppend(dsPtr, slantString, TCL_INDEX_NONE);
	    Tcl_DStringAppend(dsPtr, slantString, -1);
	}
    }

    return (int)(fontPtr->fa.size + 0.5);
}

/*
1848
1849
1850
1851
1852
1853
1854
1855
1856


1857
1858
1859
1860
1861
1862
1863
1816
1817
1818
1819
1820
1821
1822


1823
1824
1825
1826
1827
1828
1829
1830
1831







-
-
+
+







 *---------------------------------------------------------------------------
 */

int
Tk_TextWidth(
    Tk_Font tkfont,		/* Font in which text will be measured. */
    const char *string,		/* String whose width will be computed. */
    Tcl_Size numBytes)		/* Number of bytes to consider from string, or
				 * TCL_INDEX_NONE for strlen(). */
    int numBytes)		/* Number of bytes to consider from string, or
				 * < 0 for strlen(). */
{
    int width;

    if (numBytes < 0) {
	numBytes = strlen(string);
    }
    Tk_MeasureChars(tkfont, string, numBytes, -1, 0, &width);
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
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







-
-
+
+

















-
+


-
-
+
+







    Tk_Font tkfont,		/* Font used in GC; must have been allocated
				 * by Tk_GetFont(). Used for character
				 * dimensions, etc. */
    const char *string,		/* String containing characters to be
				 * underlined or overstruck. */
    int x, int y,		/* Coordinates at which first character of
				 * string is drawn. */
    Tcl_Size firstByte,		/* Index of first byte of first character. */
    Tcl_Size lastByte)		/* Index of first byte after the last
    int firstByte,		/* Index of first byte of first character. */
    int lastByte)		/* Index of first byte after the last
				 * character. */
{
    TkUnderlineCharsInContext(display, drawable, gc, tkfont, string,
	    lastByte, x, y, firstByte, lastByte);
}

void
TkUnderlineCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for actually drawing
				 * line. */
    Tk_Font tkfont,		/* Font used in GC; must have been allocated
				 * by Tk_GetFont(). Used for character
				 * dimensions, etc. */
    const char *string,		/* String containing characters to be
				 * underlined or overstruck. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int x, int y,		/* Coordinates at which the first character of
				 * the whole string would be drawn. */
    Tcl_Size firstByte,		/* Index of first byte of first character. */
    Tcl_Size lastByte)		/* Index of first byte after the last
    int firstByte,		/* Index of first byte of first character. */
    int lastByte)		/* Index of first byte after the last
				 * character. */
{
    TkFont *fontPtr = (TkFont *) tkfont;
    int startX, endX;

    TkpMeasureCharsInContext(tkfont, string, numBytes, 0, firstByte, -1, 0,
	    &startX);
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
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







-
-
+
+













-
+
-
-
+







 */

Tk_TextLayout
Tk_ComputeTextLayout(
    Tk_Font tkfont,		/* Font that will be used to display text. */
    const char *string,		/* String whose dimensions are to be
				 * computed. */
    Tcl_Size numChars,		/* Number of characters to consider from
				 * string, or TCL_INDEX_NONE for strlen(). */
    int numChars,		/* Number of characters to consider from
				 * string, or < 0 for strlen(). */
    int wrapLength,		/* Longest permissible line length, in pixels.
				 * <= 0 means no automatic wrapping: just let
				 * lines get as long as needed. */
    Tk_Justify justify,		/* How to justify lines. */
    int flags,			/* Flag bits OR-ed together. TK_IGNORE_TABS
				 * means that tab characters should not be
				 * expanded. TK_IGNORE_NEWLINES means that
				 * newline characters should not cause a line
				 * break. */
    int *widthPtr,		/* Filled with width of string. */
    int *heightPtr)		/* Filled with height of string. */
{
    TkFont *fontPtr = (TkFont *) tkfont;
    const char *start, *endp, *special;
    const char *start, *end, *special;
    Tcl_Size n;
    int y, bytesThisChunk, maxChunks, curLine, layoutHeight;
    int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight;
    int baseline, height, curX, newX, maxWidth, *lineLengths;
    TextLayout *layoutPtr;
    LayoutChunk *chunkPtr;
    const TkFontMetrics *fmPtr;
    Tcl_DString lineBuffer;

    Tcl_DStringInit(&lineBuffer);
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
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







-
+







-
-
+
+













-
+




-
+










-
+







    }

    fmPtr = &fontPtr->fm;

    height = fmPtr->ascent + fmPtr->descent;

    if (numChars < 0) {
	numChars = Tcl_NumUtfChars(string, TCL_INDEX_NONE);
	numChars = Tcl_NumUtfChars(string, -1);
    }
    if (wrapLength == 0) {
	wrapLength = -1;
    }

    maxChunks = 1;

    layoutPtr = (TextLayout *)ckalloc(offsetof(TextLayout, chunks)
	    + maxChunks * sizeof(LayoutChunk));
    layoutPtr = ckalloc(sizeof(TextLayout)
	    + (maxChunks-1) * sizeof(LayoutChunk));
    layoutPtr->tkfont = tkfont;
    layoutPtr->string = string;
    layoutPtr->numChunks = 0;

    baseline = fmPtr->ascent;
    maxWidth = 0;

    /*
     * Divide the string up into simple strings and measure each string.
     */

    curX = 0;

    endp = Tcl_UtfAtIndex(string, numChars);
    end = Tcl_UtfAtIndex(string, numChars);
    special = string;

    flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
    flags |= TK_WHOLE_WORDS | TK_AT_LEAST_ONE;
    for (start = string; start < endp; ) {
    for (start = string; start < end; ) {
	if (start >= special) {
	    /*
	     * Find the next special character in the string.
	     *
	     * INTL: Note that it is safe to increment by byte, because we are
	     * looking for 7-bit characters that will appear unchanged in
	     * UTF-8. At some point we may need to support the full Unicode
	     * whitespace set.
	     */

	    for (special = start; special < endp; special++) {
	    for (special = start; special < end; special++) {
		if (!(flags & TK_IGNORE_NEWLINES)) {
		    if ((*special == '\n') || (*special == '\r')) {
			break;
		    }
		}
		if (!(flags & TK_IGNORE_TABS)) {
		    if (*special == '\t') {
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
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







-
+
















-
+







			bytesThisChunk, curX, newX, baseline);

		start += bytesThisChunk;
		curX = newX;
	    }
	}

	if ((start == special) && (special < endp)) {
	if ((start == special) && (special < end)) {
	    /*
	     * Handle the special character.
	     *
	     * INTL: Special will be pointing at a 7-bit character so we can
	     * safely treat it as a single byte.
	     */

	    chunkPtr = NULL;
	    if (*special == '\t') {
		newX = curX + fontPtr->tabWidth;
		newX -= newX % fontPtr->tabWidth;
		NewChunk(&layoutPtr, &maxChunks, start, 1, curX, newX,
			baseline)->numDisplayChars = -1;
		start++;
		curX = newX;
		flags &= ~TK_AT_LEAST_ONE;
		if ((start < endp) &&
		if ((start < end) &&
			((wrapLength <= 0) || (newX <= wrapLength))) {
		    /*
		     * More chars can still fit on this line.
		     */

		    continue;
		}
2121
2122
2123
2124
2125
2126
2127
2128

2129
2130
2131
2132
2133
2134
2135
2088
2089
2090
2091
2092
2093
2094

2095
2096
2097
2098
2099
2100
2101
2102







-
+








	/*
	 * No more characters are going to go on this line, either because no
	 * more characters can fit or there are no more characters left.
	 * Consume all extra spaces at end of line.
	 */

	while ((start < endp) && isspace(UCHAR(*start))) { /* INTL: ISO space */
	while ((start < end) && isspace(UCHAR(*start))) { /* INTL: ISO space */
	    if (!(flags & TK_IGNORE_NEWLINES)) {
		if ((*start == '\n') || (*start == '\r')) {
		    break;
		}
	    }
	    if (!(flags & TK_IGNORE_TABS)) {
		if (*start == '\t') {
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
2275
2276
2277
2278
2279
2280
2281


2282
2283
2284

2285
2286
2287
2288




2289


2290
2291
2292
2293
2294
2295
2296
2297







-
-
+
+

-
+



-
-
-
-

-
-
+







    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context to use for drawing
				 * text. */
    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    int x, int y,		/* Upper-left hand corner of rectangle in
				 * which to draw (pixels). */
    Tcl_Size firstChar,		/* The index of the first character to draw
				 * from the given text item. 0 specifies the
    int firstChar,		/* The index of the first character to draw
				 * from the given text item. 0 specfies the
				 * beginning. */
    Tcl_Size lastChar)		/* The index just after the last character to
    int lastChar)		/* The index just after the last character to
				 * draw from the given text item. A number < 0
				 * means to draw all characters. */
{
#if 0
    /* Use TkDrawAngledTextLayout() implementation - testing purposes at this point */
    TkDrawAngledTextLayout(display, drawable, gc, layout, x, y, 0.0, firstChar, lastChar);
#else
    TextLayout *layoutPtr = (TextLayout *) layout;
    int i, drawX;
    Tcl_Size numDisplayChars;
    int i, numDisplayChars, drawX;
    const char *firstByte, *lastByte;
    LayoutChunk *chunkPtr;

    if (layoutPtr == NULL) {
	return;
    }

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
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







-
-
-
-
-
-


-








-













-
-
+
+

-
+







		Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
			firstByte - chunkPtr->start, -1, 0, &drawX);
	    }
	    if (lastChar < numDisplayChars) {
		numDisplayChars = lastChar;
	    }
	    lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
#ifdef TK_DRAW_IN_CONTEXT
	    TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont,
		    chunkPtr->start, chunkPtr->numBytes,
		    firstByte - chunkPtr->start, lastByte - firstByte,
		    x+chunkPtr->x, y+chunkPtr->y);
#else /* !TK_DRAW_IN_CONTEXT */
	    Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont, firstByte,
		    lastByte - firstByte, x+chunkPtr->x+drawX, y+chunkPtr->y);
#endif /* TK_DRAW_IN_CONTEXT */
	}
	firstChar -= chunkPtr->numChars;
	lastChar -= chunkPtr->numChars;
	if (lastChar <= 0) {
	    break;
	}
	chunkPtr++;
    }
#endif /* Use TkDrawAngledTextLayout() implementation */
}

void
TkDrawAngledTextLayout(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context to use for drawing
				 * text. */
    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    int x, int y,		/* Upper-left hand corner of rectangle in
				 * which to draw (pixels). */
    double angle,
    Tcl_Size firstChar,		/* The index of the first character to draw
				 * from the given text item. 0 specifies the
    int firstChar,		/* The index of the first character to draw
				 * from the given text item. 0 specfies the
				 * beginning. */
    Tcl_Size lastChar)		/* The index just after the last character to
    int lastChar)		/* The index just after the last character to
				 * draw from the given text item. A number < 0
				 * means to draw all characters. */
{
    TextLayout *layoutPtr = (TextLayout *) layout;
    int i, numDisplayChars, drawX;
    const char *firstByte, *lastByte;
    LayoutChunk *chunkPtr;
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
2373
2374
2375
2376
2377
2378
2379















2380
2381
2382
2383
2384
2385
2386
2387
2388
2389

2390
2391
2392
2393
2394
2395
2396







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-







		Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
			firstByte - chunkPtr->start, -1, 0, &drawX);
	    }
	    if (lastChar < numDisplayChars) {
		numDisplayChars = lastChar;
	    }
	    lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
#ifdef TK_DRAW_IN_CONTEXT
	    dx = cosA * (chunkPtr->x) + sinA * (chunkPtr->y);
	    dy = -sinA * (chunkPtr->x) + cosA * (chunkPtr->y);
	    if (angle == 0.0) {
		TkpDrawCharsInContext(display, drawable, gc,
			layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
			firstByte - chunkPtr->start, lastByte - firstByte,
			(int)(x + dx), (int)(y + dy));
	    } else {
		TkpDrawAngledCharsInContext(display, drawable, gc,
			layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
			firstByte - chunkPtr->start, lastByte - firstByte,
			x+dx, y+dy, angle);
	    }
#else /* !TK_DRAW_IN_CONTEXT */
	    dx = cosA * (chunkPtr->x + drawX) + sinA * (chunkPtr->y);
	    dy = -sinA * (chunkPtr->x + drawX) + cosA * (chunkPtr->y);
	    if (angle == 0.0) {
		Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
			firstByte, lastByte - firstByte,
			(int)(x + dx), (int)(y + dy));
	    } else {
		TkDrawAngledChars(display, drawable, gc, layoutPtr->tkfont,
			firstByte, lastByte - firstByte, x+dx, y+dy, angle);
	    }
#endif /* TK_DRAW_IN_CONTEXT */
	}
	firstChar -= chunkPtr->numChars;
	lastChar -= chunkPtr->numChars;
	if (lastChar <= 0) {
	    break;
	}
	chunkPtr++;
2488
2489
2490
2491
2492
2493
2494
2495

2496
2497
2498
2499
2500
2501
2502
2426
2427
2428
2429
2430
2431
2432

2433
2434
2435
2436
2437
2438
2439
2440







-
+







    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context to use for drawing text. */
    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    int x, int y,		/* Upper-left hand corner of rectangle in
				 * which to draw (pixels). */
    int underline)		/* Index of the single character to underline,
				 * or INT_MIN for no underline. */
				 * or -1 for no underline. */
{
    int xx, yy, width, height;

    if ((Tk_CharBbox(layout, underline, &xx, &yy, &width, &height) != 0)
	    && (width != 0)) {
	TextLayout *layoutPtr = (TextLayout *) layout;
	TkFont *fontPtr = (TkFont *) layoutPtr->tkfont;
2515
2516
2517
2518
2519
2520
2521
2522

2523
2524
2525
2526
2527
2528
2529
2453
2454
2455
2456
2457
2458
2459

2460
2461
2462
2463
2464
2465
2466
2467







-
+







				 * text. */
    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    int x, int y,		/* Upper-left hand corner of rectangle in
				 * which to draw (pixels). */
    double angle,
    int underline)		/* Index of the single character to underline,
				 * or INT_MIN for no underline. */
				 * or -1 for no underline. */
{
    int xx, yy, width, height;

    if (angle == 0.0) {
	Tk_UnderlineTextLayout(display, drawable, gc, layout, x,y, underline);
	return;
    }
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
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







-
-
+
+










-
+






-
-
-
-
-
-
-
-
+
+
+
+


















-
-
+
+







 *---------------------------------------------------------------------------
 */

int
Tk_CharBbox(
    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    Tcl_Size index,			/* The index of the character whose bbox is
				 * desired. Negative means count backwards. */
    int index,			/* The index of the character whose bbox is
				 * desired. */
    int *xPtr, int *yPtr,	/* Filled with the upper-left hand corner, in
				 * pixels, of the bounding box for the
				 * character specified by index, if
				 * non-NULL. */
    int *widthPtr, int *heightPtr)
				/* Filled with the width and height of the
				 * bounding box for the character specified by
				 * index, if non-NULL. */
{
    TextLayout *layoutPtr = (TextLayout *) layout;
    LayoutChunk *chunkPtr = layoutPtr->chunks;
    LayoutChunk *chunkPtr;
    int i, x = 0, w;
    Tk_Font tkfont;
    TkFont *fontPtr;
    const char *end;

    if (index < 0) {
	for (i = 0; i < layoutPtr->numChunks; i++) {
	    index += (chunkPtr + i)->numChars;
	}
	if (index < 0) {
	    return 0;
	}
    }

	return 0;
    }

    chunkPtr = layoutPtr->chunks;
    tkfont = layoutPtr->tkfont;
    fontPtr = (TkFont *) tkfont;

    for (i = 0; i < layoutPtr->numChunks; i++) {
	if (chunkPtr->numDisplayChars < 0) {
	    if (index == 0) {
		x = chunkPtr->x;
		w = chunkPtr->totalWidth;
		goto check;
	    }
	} else if (index < chunkPtr->numChars) {
	    end = Tcl_UtfAtIndex(chunkPtr->start, index);
	    if (xPtr != NULL) {
		Tk_MeasureChars(tkfont, chunkPtr->start,
			end - chunkPtr->start, -1, 0, &x);
		x += chunkPtr->x;
	    }
	    if (widthPtr != NULL) {
		int ch;
		Tk_MeasureChars(tkfont, end, Tcl_UtfToUniChar(end, &ch), -1, 0, &w);
		Tk_MeasureChars(tkfont, end, Tcl_UtfNext(end) - end,
			-1, 0, &w);
	    }
	    goto check;
	}
	index -= chunkPtr->numChars;
	chunkPtr++;
    }
    if (index != 0) {
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220






3221

3222
3223
3224
3225
3226
3227
3228

3229
3230
3231
3232
3233
3234
3235
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
3171







-
-
-
-
-
-
+
+
+
+
+
+

+







+







	    continue;
	}

	cx[0] = cx[3] = chunkPtr->x;
	cy[0] = cy[1] = chunkPtr->y - fontPtr->fm.ascent;
	cx[1] = cx[2] = chunkPtr->x + chunkPtr->displayWidth;
	cy[2] = cy[3] = chunkPtr->y + fontPtr->fm.descent;
	if (	PointInQuadrilateral(cx, cy, rx[0], ry[0]) &&
		PointInQuadrilateral(cx, cy, rx[1], ry[1]) &&
		PointInQuadrilateral(cx, cy, rx[2], ry[2]) &&
		PointInQuadrilateral(cx, cy, rx[3], ry[3])) {
            return 0;
        }
	if (	!PointInQuadrilateral(cx, cy, rx[0], ry[0]) ||
		!PointInQuadrilateral(cx, cy, rx[1], ry[1]) ||
		!PointInQuadrilateral(cx, cy, rx[2], ry[2]) ||
		!PointInQuadrilateral(cx, cy, rx[3], ry[3])) {
	    goto notReverseInside;
	}
    }
    return 0;

    /*
     * If we're overlapping now, we must be partially in and out of at least
     * one chunk. If that is the case, there must be one line segment of the
     * rectangle that is touching or crossing a line segment of a chunk.
     */

  notReverseInside:
    chunkPtr = layoutPtr->chunks;

    for (i=0 ; i<layoutPtr->numChunks ; i++,chunkPtr++) {
	int j;

	if (chunkPtr->start[0] == '\n') {
	    /*
3307
3308
3309
3310
3311
3312
3313
3314

3315
3316
3317
3318
3319
3320

3321
3322
3323

3324
3325
3326
3327
3328

3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341

3342
3343
3344

3345
3346
3347
3348
3349
3350
3351
3243
3244
3245
3246
3247
3248
3249

3250

3251
3252
3253
3254

3255
3256
3257

3258
3259
3260
3261
3262

3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275

3276
3277
3278

3279
3280
3281
3282
3283
3284
3285
3286







-
+
-




-
+


-
+




-
+












-
+


-
+







    Tcl_Interp *interp,		/* Filled with Postscript code. */
    Tk_TextLayout layout)	/* The layout to be rendered. */
{
    TextLayout *layoutPtr = (TextLayout *) layout;
    LayoutChunk *chunkPtr = layoutPtr->chunks;
    int baseline = chunkPtr->y;
    Tcl_Obj *psObj = Tcl_NewObj();
    int i, j;
    int i, j, len;
    Tcl_Size len;
    const char *p, *glyphname;
    char uindex[5], c, *ps;
    int ch;

    Tcl_AppendToObj(psObj, "[(", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, "[(", -1);
    for (i = 0; i < layoutPtr->numChunks; i++, chunkPtr++) {
	if (baseline != chunkPtr->y) {
	    Tcl_AppendToObj(psObj, ")]\n[(", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, ")]\n[(", -1);
	    baseline = chunkPtr->y;
	}
	if (chunkPtr->numDisplayChars <= 0) {
	    if (chunkPtr->start[0] == '\t') {
		Tcl_AppendToObj(psObj, "\\t", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "\\t", -1);
	    }
	    continue;
	}

	for (p=chunkPtr->start, j=0; j<chunkPtr->numDisplayChars; j++) {
	    /*
	     * INTL: We only handle symbols that have an encoding as a glyph
	     * from the standard set defined by Adobe. The rest get punted.
	     * Eventually this should be revised to handle more sophsticiated
	     * international postscript fonts.
	     */

	    p += Tcl_UtfToUniChar(p, &ch);
	    p += TkUtfToUniChar(p, &ch);
	    if ((ch == '(') || (ch == ')') || (ch == '\\') || (ch < 0x20)) {
		/*
		 * Tricky point: the "03" is necessary in the snprintf below,
		 * Tricky point: the "03" is necessary in the sprintf below,
		 * so that a full three digits of octal are always generated.
		 * Without the "03", a number following this sequence could be
		 * interpreted by Postscript as part of this sequence.
		 */

		Tcl_AppendPrintfToObj(psObj, "\\%03o", ch);
		continue;
3363
3364
3365
3366
3367
3368
3369
3370

3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381

3382
3383
3384


3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399

3400
3401
3402
3403
3404
3405
3406
3298
3299
3300
3301
3302
3303
3304

3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315

3316
3317


3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333

3334
3335
3336
3337
3338
3339
3340
3341







-
+










-
+

-
-
+
+














-
+







	     * This character doesn't belong to the ASCII character set, so we
	     * use the full glyph name.
	     */

	    if (ch > 0xffff) {
		goto noMapping;
	    }
	    snprintf(uindex, sizeof(uindex), "%04X", ch);		/* endianness? */
	    sprintf(uindex, "%04X", ch);		/* endianness? */
	    glyphname = Tcl_GetVar2(interp, "::tk::psglyphs", uindex, 0);
	    if (glyphname) {
		ps = Tcl_GetStringFromObj(psObj, &len);
		if (ps[len-1] == '(') {
		    /*
		     * In-place edit. Ewww!
		     */

		    ps[len-1] = '/';
		} else {
		    Tcl_AppendToObj(psObj, ")/", TCL_INDEX_NONE);
		    Tcl_AppendToObj(psObj, ")/", -1);
		}
		Tcl_AppendToObj(psObj, glyphname, TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "(", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, glyphname, -1);
		Tcl_AppendToObj(psObj, "(", -1);
	    } else {
		/*
		 * No known mapping for the character into the space of
		 * PostScript glyphs. Ignore it. :-(
		 */
noMapping:	;

#ifdef TK_DEBUG_POSTSCRIPT_OUTPUT
		fprintf(stderr, "Warning: no mapping to PostScript "
			"glyphs for \\u%04x\n", ch);
#endif
	    }
	}
    }
    Tcl_AppendToObj(psObj, ")]\n", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, ")]\n", -1);
    Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    Tcl_DecrRefCount(psObj);
}

/*
 *---------------------------------------------------------------------------
 *
3421
3422
3423
3424
3425
3426
3427
3428
3429


3430
3431
3432
3433
3434
3435
3436

3437
3438
3439
3440
3441
3442
3443
3356
3357
3358
3359
3360
3361
3362


3363
3364
3365
3366
3367
3368
3369


3370
3371
3372
3373
3374
3375
3376
3377







-
-
+
+





-
-
+







 *
 *---------------------------------------------------------------------------
 */

static int
ConfigAttributesObj(
    Tcl_Interp *interp,		/* Interp for error return. */
    TCL_UNUSED(Tk_Window),	/* For display on which font will be used. */
    Tcl_Size objc,			/* Number of elements in argv. */
    Tk_Window tkwin,		/* For display on which font will be used. */
    int objc,			/* Number of elements in argv. */
    Tcl_Obj *const objv[],	/* Command line options. */
    TkFontAttributes *faPtr)	/* Font attributes structure whose fields are
				 * to be modified. Structure must already be
				 * properly initialized. */
{
    Tcl_Size i;
    int n, index;
    int i, n, index;
    Tcl_Obj *optionPtr, *valuePtr;
    const char *value;

    for (i = 0; i < objc; i += 2) {
	optionPtr = objv[i];

	if (Tcl_GetIndexFromObj(interp, optionPtr, fontOpt, "option", 1,
3558
3559
3560
3561
3562
3563
3564
3565

3566
3567

3568
3569
3570
3571
3572
3573

3574
3575
3576
3577
3578

3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594

3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3492
3493
3494
3495
3496
3497
3498

3499
3500

3501
3502
3503
3504
3505
3506

3507
3508
3509
3510
3511

3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527

3528
3529
3530
3531
3532
3533



















































3534
3535
3536
3537
3538
3539
3540







-
+

-
+





-
+




-
+















-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	case FONT_FAMILY:
	    str = faPtr->family;
	    valuePtr = Tcl_NewStringObj(str, ((str == NULL) ? 0 : -1));
	    break;

	case FONT_SIZE:
	    if (faPtr->size >= 0.0) {
		valuePtr = Tcl_NewWideIntObj((Tcl_WideInt)(faPtr->size + 0.5));
		valuePtr = Tcl_NewIntObj((int)(faPtr->size + 0.5));
	    } else {
		valuePtr = Tcl_NewWideIntObj(-(Tcl_WideInt)(-faPtr->size + 0.5));
		valuePtr = Tcl_NewIntObj(-(int)(-faPtr->size + 0.5));
	    }
	    break;

	case FONT_WEIGHT:
	    str = TkFindStateString(weightMap, faPtr->weight);
	    valuePtr = Tcl_NewStringObj(str, TCL_INDEX_NONE);
	    valuePtr = Tcl_NewStringObj(str, -1);
	    break;

	case FONT_SLANT:
	    str = TkFindStateString(slantMap, faPtr->slant);
	    valuePtr = Tcl_NewStringObj(str, TCL_INDEX_NONE);
	    valuePtr = Tcl_NewStringObj(str, -1);
	    break;

	case FONT_UNDERLINE:
	    valuePtr = Tcl_NewBooleanObj(faPtr->underline);
	    break;

	case FONT_OVERSTRIKE:
	    valuePtr = Tcl_NewBooleanObj(faPtr->overstrike);
	    break;
	}
	if (objPtr != NULL) {
	    Tcl_SetObjResult(interp, valuePtr);
	    return TCL_OK;
	}
	Tcl_ListObjAppendElement(NULL, resultPtr,
		Tcl_NewStringObj(fontOpt[i], TCL_INDEX_NONE));
		Tcl_NewStringObj(fontOpt[i], -1));
	Tcl_ListObjAppendElement(NULL, resultPtr, valuePtr);
    }
    Tcl_SetObjResult(interp, resultPtr);
    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_FontGetDescription --
 *
 *	Return information about the font description as a Tcl list. One
 *	possible result is "{{DejaVu Sans} -16 bold underline}".
 *
 * Results:
 *	The list of descriptions.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

Tcl_Obj *
Tk_FontGetDescription(
    Tk_Font tkfont)		/* Font whose description is desired. */
{
    const TkFontAttributes *faPtr = GetFontAttributes(tkfont);
    Tcl_Obj *resultPtr = Tcl_NewObj();
    const char *str;

    str = faPtr->family;
    Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, str ? -1 : 0));
    if (faPtr->size >= 0.0) {
    	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewWideIntObj((int)(faPtr->size + 0.5)));
    } else {
    	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewWideIntObj(-(int)(-faPtr->size + 0.5)));
    }
    if (faPtr->weight != TK_FW_NORMAL) {
	str = TkFindStateString(weightMap, faPtr->weight);
	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, TCL_INDEX_NONE));
    }
    if (faPtr->slant != TK_FS_ROMAN) {
	str = TkFindStateString(slantMap, faPtr->slant);
	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, TCL_INDEX_NONE));
    }
    if (faPtr->underline) {
	str = TkFindStateString(underlineMap, faPtr->underline);
	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, TCL_INDEX_NONE));
    }
    if (faPtr->overstrike) {
	str = TkFindStateString(overstrikeMap, faPtr->overstrike);
	Tcl_ListObjAppendElement(NULL, resultPtr, Tcl_NewStringObj(str, TCL_INDEX_NONE));
    }
    return resultPtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * ParseFontNameObj --
 *
 *	Converts a object into a set of font attributes that can be used to
3680
3681
3682
3683
3684
3685
3686
3687
3688


3689
3690
3691
3692
3693
3694
3695
3696
3563
3564
3565
3566
3567
3568
3569


3570
3571

3572
3573
3574
3575
3576
3577
3578







-
-
+
+
-







    Tk_Window tkwin,		/* For display on which font is used. */
    Tcl_Obj *objPtr,		/* Parseable font description object. */
    TkFontAttributes *faPtr)	/* Filled with attributes parsed from font
				 * name. Any attributes that were not
				 * specified in font name are filled with
				 * default values. */
{
    const char *dash;
    int result, n;
    char *dash;
    int objc, result, i, n;
    Tcl_Size objc, i;
    Tcl_Obj **objv;
    const char *string;

    TkInitFontAttributes(faPtr);

    string = Tcl_GetString(objPtr);
    if (*string == '-') {
3835
3836
3837
3838
3839
3840
3841
3842

3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857


3858
3859
3860
3861
3862
3863
3864
3717
3718
3719
3720
3721
3722
3723

3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737


3738
3739
3740
3741
3742
3743
3744
3745
3746







-
+













-
-
+
+







 */

static LayoutChunk *
NewChunk(
    TextLayout **layoutPtrPtr,
    int *maxPtr,
    const char *start,
    Tcl_Size numBytes,
    int numBytes,
    int curX,
    int newX,
    int y)
{
    TextLayout *layoutPtr;
    LayoutChunk *chunkPtr;
    int maxChunks, numChars;
    size_t s;

    layoutPtr = *layoutPtrPtr;
    maxChunks = *maxPtr;
    if (layoutPtr->numChunks == maxChunks) {
	maxChunks *= 2;
	s = offsetof(TextLayout, chunks) + (maxChunks * sizeof(LayoutChunk));
	layoutPtr = (TextLayout *)ckrealloc(layoutPtr, s);
	s = sizeof(TextLayout) + ((maxChunks - 1) * sizeof(LayoutChunk));
	layoutPtr = ckrealloc(layoutPtr, s);

	*layoutPtrPtr = layoutPtr;
	*maxPtr = maxChunks;
    }
    numChars = Tcl_NumUtfChars(start, numBytes);
    chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks];
    chunkPtr->start		= start;
3922
3923
3924
3925
3926
3927
3928
3929

3930
3931
3932
3933
3934
3935
3936
3804
3805
3806
3807
3808
3809
3810

3811
3812
3813
3814
3815
3816
3817
3818







-
+








    str = string;
    if (*str == '-') {
	str++;
    }

    Tcl_DStringInit(&ds);
    Tcl_DStringAppend(&ds, str, TCL_INDEX_NONE);
    Tcl_DStringAppend(&ds, str, -1);
    src = Tcl_DStringValue(&ds);

    field[0] = src;
    for (i = 0; *src != '\0'; src++) {
	if (!(*src & 0x80)
		&& Tcl_UniCharIsUpper(UCHAR(*src))) {
	    *src = (char) Tcl_UniCharToLower(UCHAR(*src));
4313
4314
4315
4316
4317
4318
4319
4320

4321
4322
4323
4324
4325
4326
4327

4328
4329

4330
4331
4332
4333
4334
4335
4336
4195
4196
4197
4198
4199
4200
4201

4202
4203
4204
4205
4206
4207
4208

4209
4210

4211
4212
4213
4214
4215
4216
4217
4218







-
+






-
+

-
+







    Tcl_HashEntry *hashPtr;
    Tcl_Obj *resultPtr, *objPtr;

    resultPtr = Tcl_NewObj();
    hashPtr = Tcl_FindHashEntry(
	    &((TkWindow *) tkwin)->mainPtr->fontInfoPtr->fontCache, name);
    if (hashPtr != NULL) {
	fontPtr = (TkFont *)Tcl_GetHashValue(hashPtr);
	fontPtr = Tcl_GetHashValue(hashPtr);
	if (fontPtr == NULL) {
	    Tcl_Panic("TkDebugFont found empty hash table entry");
	}
	for ( ; (fontPtr != NULL); fontPtr = fontPtr->nextPtr) {
	    objPtr = Tcl_NewObj();
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(fontPtr->resourceRefCount));
		    Tcl_NewIntObj(fontPtr->resourceRefCount));
	    Tcl_ListObjAppendElement(NULL, objPtr,
		    Tcl_NewWideIntObj(fontPtr->objRefCount));
		    Tcl_NewIntObj(fontPtr->objRefCount));
	    Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
	}
    }
    return resultPtr;
}

/*
4357
4358
4359
4360
4361
4362
4363
4364

4365
4366
4367
4368
4369
4370
4371
4372
4373

4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4239
4240
4241
4242
4243
4244
4245

4246
4247
4248
4249
4250
4251
4252
4253
4254

4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266







-
+








-
+











    Tk_TextLayout layout,	/* Layout information, from a previous call to
				 * Tk_ComputeTextLayout(). */
    Tk_Font *font,
    char *dst)
{
    TextLayout *layoutPtr = (TextLayout *) layout;
    LayoutChunk *chunkPtr;
    Tcl_Size numBytesInChunk;
    int numBytesInChunk;

    if ((layoutPtr == NULL) || (layoutPtr->numChunks == 0)
	    || (layoutPtr->chunks->numDisplayChars <= 0)) {
	dst[0] = '\0';
	return 0;
    }
    chunkPtr = layoutPtr->chunks;
    numBytesInChunk = chunkPtr->numBytes;
    strncpy(dst, chunkPtr->start, numBytesInChunk);
    strncpy(dst, chunkPtr->start, (size_t) numBytesInChunk);
    *font = layoutPtr->tkfont;
    return numBytesInChunk;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkFont.h.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23







-
+








-
-
-
-







/*
 * tkFont.h --
 *
 *	Declarations for interfaces between the generic and platform-specific
 *	parts of the font package. This information is not visible outside of
 *	the font package.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-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.
 */

#ifndef _TKFONT
#define _TKFONT

#ifdef __cplusplus
extern "C" {
#endif

/*
 * The following structure keeps track of the attributes of a font. It can be
 * used to keep track of either the desired attributes or the actual
 * attributes gotten when the font was instantiated.
 */

struct TkFontAttributes {
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105







-
+









-
+







 */

typedef struct TkFont {
    /*
     * Fields used and maintained exclusively by generic code.
     */

    Tcl_Size resourceRefCount;	/* Number of active uses of this font (each
    int resourceRefCount;	/* Number of active uses of this font (each
				 * active use corresponds to a call to
				 * Tk_AllocFontFromTable or Tk_GetFont). If
				 * this count is 0, then this TkFont structure
				 * is no longer valid and it isn't present in
				 * a hash table: it is being kept around only
				 * because there are objects referring to it.
				 * The structure is freed when
				 * resourceRefCount and objRefCount are both
				 * 0. */
    Tcl_Size objRefCount;		/* The number of Tcl objects that reference
    int objRefCount;		/* The number of Tcl objects that reference
				 * this structure. */
    Tcl_HashEntry *cacheHashPtr;/* Entry in font cache for this structure,
				 * used when deleting it. */
    Tcl_HashEntry *namedHashPtr;/* Pointer to hash table entry that
				 * corresponds to the named font that the
				 * tkfont was based on, or NULL if the tkfont
				 * was not based on a named font. */
221
222
223
224
225
226
227
228
229
230
231
232
217
218
219
220
221
222
223




224







-
-
-
-

MODULE_SCOPE void	TkpFontPkgInit(TkMainInfo *mainPtr);
MODULE_SCOPE TkFont *	TkpGetFontFromAttributes(TkFont *tkFontPtr,
			    Tk_Window tkwin, const TkFontAttributes *faPtr);
MODULE_SCOPE void	TkpGetFontFamilies(Tcl_Interp *interp,
			    Tk_Window tkwin);
MODULE_SCOPE TkFont *	TkpGetNativeFont(Tk_Window tkwin, const char *name);

#ifdef __cplusplus
}
#endif

#endif	/* _TKFONT */

Changes to generic/tkFrame.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7


8
9
10
11
12
13
14


15
16
17
18
19
20
21
22
23







-
-
+
+





-
-
+
+







/*
 * tkFrame.c --
 *
 *	This module implements "frame", "labelframe" and "toplevel" widgets
 *	for the Tk toolkit. Frames are windows with a background color and
 *	possibly a 3-D effect, but not much else in the way of attributes.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"

/*
 * The following enum is used to define the type of the frame.
 */

enum FrameType {
    TYPE_FRAME, TYPE_TOPLEVEL, TYPE_LABELFRAME
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







    Tcl_Interp *interp;		/* Interpreter associated with widget. Used to
				 * delete widget command. */
    Tcl_Command widgetCmd;	/* Token for frame's widget command. */
    Tk_OptionTable optionTable;	/* Table that defines configuration options
				 * available for this widget. */
    char *className;		/* Class name for widget (from configuration
				 * option). Malloc-ed. */
    int type;			/* Type of widget, such as TYPE_FRAME. */
    enum FrameType type;	/* Type of widget, such as TYPE_FRAME. */
    char *screenName;		/* Screen on which widget is created. Non-null
				 * only for top-levels. Malloc-ed, may be
				 * NULL. */
    char *visualName;		/* Textual description of visual for window,
				 * from -visual option. Malloc-ed, may be
				 * NULL. */
    char *colormapName;		/* Textual description of colormap for window,
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
90
91
92
93
94
95
96










97
98
99
100
101
102
103







-
-
-
-
-
-
-
-
-
-







				 * pixels of extra space to leave on left and
				 * right of child area. */
    int padX;			/* Integer value corresponding to padXPtr. */
    Tcl_Obj *padYPtr;		/* Value of -padx option: specifies how many
				 * pixels of extra space to leave above and
				 * below child area. */
    int padY;			/* Integer value corresponding to padYPtr. */
    Tcl_Obj *bgimgPtr;		/* Value of -backgroundimage option: specifies
				 * image to display on window's background, or
				 * NULL if none. */
    Tk_Image bgimg;		/* Derived from bgimgPtr by calling
				 * Tk_GetImage, or NULL if bgimgPtr is
				 * NULL. */
    int tile;			/* Whether to tile the bgimg. */
#ifndef TK_NO_DOUBLE_BUFFERING
    GC copyGC;			/* GC for copying when double-buffering. */
#endif /* TK_NO_DOUBLE_BUFFERING */
} Frame;

/*
 * A data structure of the following type is kept for each labelframe widget
 * managed by this file:
 */

180
181
182
183
184
185
186
187

188
189
190

191
192

193
194
195
196
197
198
199

200
201

202
203
204

205
206
207


208
209

210
211
212
213


214
215
216


217
218
219


220
221

222
223
224

225
226
227

228
229
230
231
232
233
234
235
236

237
238
239
240

241
242

243
244

245
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260

261
262

263
264

265
266
267

268
269

270
271
272
273
274

275
276
277
278
279
280
281
282

283
284

285
286
287

288
289

290
291

292
293

294
295

296
297
298

299
300

301
302

303
304
305
306
307
308
309
170
171
172
173
174
175
176

177
178
179

180
181

182
183
184
185
186
187
188

189
190

191
192
193

194
195


196
197
198

199
200
201


202
203
204


205
206
207


208
209
210

211
212
213

214
215
216

217
218
219
220
221



222

223


224

225
226

227
228

229


230
231
232
233
234



235

236


237

238
239

240
241

242
243
244

245
246

247
248


249

250
251
252
253
254
255
256
257

258
259

260
261
262

263
264

265
266

267
268

269
270

271
272
273

274
275

276
277

278
279
280
281
282
283
284
285







-
+


-
+

-
+






-
+

-
+


-
+

-
-
+
+

-
+


-
-
+
+

-
-
+
+

-
-
+
+

-
+


-
+


-
+




-
-
-

-
+
-
-

-
+

-
+

-
+
-
-





-
-
-

-
+
-
-

-
+

-
+

-
+


-
+

-
+

-
-

-
+







-
+

-
+


-
+

-
+

-
+

-
+

-
+


-
+

-
+

-
+







/*
 * Information used for parsing configuration options. There are one common
 * table used by all and one table for each widget class.
 */

static const Tk_OptionSpec commonOptSpec[] = {
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_FRAME_BG_COLOR, TCL_INDEX_NONE, offsetof(Frame, border),
	DEF_FRAME_BG_COLOR, -1, Tk_Offset(Frame, border),
	TK_OPTION_NULL_OK, DEF_FRAME_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_STRING, "-colormap", "colormap", "Colormap",
	DEF_FRAME_COLORMAP, TCL_INDEX_NONE, offsetof(Frame, colormapName),
	DEF_FRAME_COLORMAP, -1, Tk_Offset(Frame, colormapName),
	TK_OPTION_NULL_OK, 0, 0},
    /*
     * Having -container is useless in a labelframe since a container has
     * no border. It should be deprecated.
     */
    {TK_OPTION_BOOLEAN, "-container", "container", "Container",
	DEF_FRAME_CONTAINER, TCL_INDEX_NONE, offsetof(Frame, isContainer), 0, 0, 0},
	DEF_FRAME_CONTAINER, -1, Tk_Offset(Frame, isContainer), 0, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_FRAME_CURSOR, TCL_INDEX_NONE, offsetof(Frame, cursor),
	DEF_FRAME_CURSOR, -1, Tk_Offset(Frame, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-height", "height", "Height",
	DEF_FRAME_HEIGHT, TCL_INDEX_NONE, offsetof(Frame, height), 0, 0, 0},
	DEF_FRAME_HEIGHT, -1, Tk_Offset(Frame, height), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_FRAME_HIGHLIGHT_BG, TCL_INDEX_NONE,
	offsetof(Frame, highlightBgColorPtr), 0, 0, 0},
	"HighlightBackground", DEF_FRAME_HIGHLIGHT_BG, -1,
	Tk_Offset(Frame, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_FRAME_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Frame, highlightColorPtr),
	DEF_FRAME_HIGHLIGHT, -1, Tk_Offset(Frame, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_FRAME_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	offsetof(Frame, highlightWidth), 0, 0, 0},
	"HighlightThickness", DEF_FRAME_HIGHLIGHT_WIDTH, -1,
	Tk_Offset(Frame, highlightWidth), 0, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	DEF_FRAME_PADX, offsetof(Frame, padXPtr),
	offsetof(Frame, padX), 0, 0, 0},
	DEF_FRAME_PADX, Tk_Offset(Frame, padXPtr),
	Tk_Offset(Frame, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	DEF_FRAME_PADY, offsetof(Frame, padYPtr),
	offsetof(Frame, padY), 0, 0, 0},
	DEF_FRAME_PADY, Tk_Offset(Frame, padYPtr),
	Tk_Offset(Frame, padY), 0, 0, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_FRAME_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(Frame, takeFocus),
	DEF_FRAME_TAKE_FOCUS, -1, Tk_Offset(Frame, takeFocus),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-visual", "visual", "Visual",
	DEF_FRAME_VISUAL, TCL_INDEX_NONE, offsetof(Frame, visualName),
	DEF_FRAME_VISUAL, -1, Tk_Offset(Frame, visualName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-width", "width", "Width",
	DEF_FRAME_WIDTH, TCL_INDEX_NONE, offsetof(Frame, width), 0, 0, 0},
	DEF_FRAME_WIDTH, -1, Tk_Offset(Frame, width), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

static const Tk_OptionSpec frameOptSpec[] = {
    {TK_OPTION_STRING, "-backgroundimage", "backgroundImage", "BackgroundImage",
	DEF_FRAME_BG_IMAGE, offsetof(Frame, bgimgPtr), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bgimg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-backgroundimage", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_FRAME_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Frame, borderWidth), 0, 0, 0},
	DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-class", "class", "Class",
	DEF_FRAME_CLASS, TCL_INDEX_NONE, offsetof(Frame, className), 0, 0, 0},
	DEF_FRAME_CLASS, -1, Tk_Offset(Frame, className), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_FRAME_RELIEF, TCL_INDEX_NONE, offsetof(Frame, relief), 0, 0, 0},
	DEF_FRAME_RELIEF, -1, Tk_Offset(Frame, relief), 0, 0, 0},
    {TK_OPTION_BOOLEAN, "-tile", "tile", "Tile",
	DEF_FRAME_BG_TILE, TCL_INDEX_NONE, offsetof(Frame, tile), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, 0, 0, commonOptSpec, 0}
};

static const Tk_OptionSpec toplevelOptSpec[] = {
    {TK_OPTION_STRING, "-backgroundimage", "backgroundImage", "BackgroundImage",
	DEF_FRAME_BG_IMAGE, offsetof(Frame, bgimgPtr), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bgimg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-backgroundimage", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_FRAME_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Frame, borderWidth), 0, 0, 0},
	DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-class", "class", "Class",
	DEF_TOPLEVEL_CLASS, TCL_INDEX_NONE, offsetof(Frame, className), 0, 0, 0},
	DEF_TOPLEVEL_CLASS, -1, Tk_Offset(Frame, className), 0, 0, 0},
    {TK_OPTION_STRING, "-menu", "menu", "Menu",
	DEF_TOPLEVEL_MENU, TCL_INDEX_NONE, offsetof(Frame, menuName),
	DEF_TOPLEVEL_MENU, -1, Tk_Offset(Frame, menuName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_FRAME_RELIEF, TCL_INDEX_NONE, offsetof(Frame, relief), 0, 0, 0},
	DEF_FRAME_RELIEF, -1, Tk_Offset(Frame, relief), 0, 0, 0},
    {TK_OPTION_STRING, "-screen", "screen", "Screen",
	DEF_TOPLEVEL_SCREEN, TCL_INDEX_NONE, offsetof(Frame, screenName),
	DEF_TOPLEVEL_SCREEN, -1, Tk_Offset(Frame, screenName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-tile", "tile", "Tile",
	DEF_FRAME_BG_TILE, TCL_INDEX_NONE, offsetof(Frame, tile), 0, 0, 0},
    {TK_OPTION_STRING, "-use", "use", "Use",
	DEF_TOPLEVEL_USE, TCL_INDEX_NONE, offsetof(Frame, useThis),
	DEF_TOPLEVEL_USE, -1, Tk_Offset(Frame, useThis),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, 0, 0, commonOptSpec, 0}
};

static const Tk_OptionSpec labelframeOptSpec[] = {
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_LABELFRAME_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Frame, borderWidth),
	DEF_LABELFRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth),
	0, 0, 0},
    {TK_OPTION_STRING, "-class", "class", "Class",
	DEF_LABELFRAME_CLASS, TCL_INDEX_NONE, offsetof(Frame, className), 0, 0, 0},
	DEF_LABELFRAME_CLASS, -1, Tk_Offset(Frame, className), 0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_LABELFRAME_FONT, TCL_INDEX_NONE, offsetof(Labelframe, tkfont), 0, 0, 0},
	DEF_LABELFRAME_FONT, -1, Tk_Offset(Labelframe, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_LABELFRAME_FG, TCL_INDEX_NONE, offsetof(Labelframe, textColorPtr), 0, 0, 0},
	DEF_LABELFRAME_FG, -1, Tk_Offset(Labelframe, textColorPtr), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-labelanchor", "labelAnchor", "LabelAnchor",
	DEF_LABELFRAME_LABELANCHOR, TCL_INDEX_NONE, offsetof(Labelframe, labelAnchor),
	DEF_LABELFRAME_LABELANCHOR, -1, Tk_Offset(Labelframe, labelAnchor),
	0, labelAnchorStrings, 0},
    {TK_OPTION_WINDOW, "-labelwidget", "labelWidget", "LabelWidget",
	NULL, TCL_INDEX_NONE, offsetof(Labelframe, labelWin), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(Labelframe, labelWin), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_LABELFRAME_RELIEF, TCL_INDEX_NONE, offsetof(Frame, relief), 0, 0, 0},
	DEF_LABELFRAME_RELIEF, -1, Tk_Offset(Frame, relief), 0, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_LABELFRAME_TEXT, offsetof(Labelframe, textPtr), TCL_INDEX_NONE,
	DEF_LABELFRAME_TEXT, Tk_Offset(Labelframe, textPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, 0, 0, commonOptSpec, 0}
};

/*
 * Class names for widgets, indexed by FrameType.
324
325
326
327
328
329
330
331
332





333
334

335
336
337
338
339
340
341
342


343
344

345
346

347
348

349
350
351
352





353
354
355
356
357
358
359
300
301
302
303
304
305
306


307
308
309
310
311
312

313








314
315
316

317
318

319
320

321
322



323
324
325
326
327
328
329
330
331
332
333
334







-
-
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
+
+

-
+

-
+

-
+

-
-
-
+
+
+
+
+








/*
 * Forward declarations for functions defined later in this file:
 */

static void		ComputeFrameGeometry(Frame *framePtr);
static int		ConfigureFrame(Tcl_Interp *interp, Frame *framePtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static Tcl_FreeProc	DestroyFrame;
			    int objc, Tcl_Obj *const objv[]);
static int		CreateFrame(ClientData clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const argv[],
			    enum FrameType type, const char *appName);
static void		DestroyFrame(void *memPtr);
static void		DestroyFramePartly(Frame *framePtr);
static void		DisplayFrame(void *clientData);
static void		DisplayFrame(ClientData clientData);
static void		DrawFrameBackground(Tk_Window tkwin, Pixmap pixmap,
			    int highlightWidth, int borderWidth,
			    Tk_Image bgimg, int bgtile);
static void		FrameBgImageProc(void *clientData,
			    int x, int y, int width, int height,
			    int imgWidth, int imgHeight);
static void		FrameCmdDeletedProc(void *clientData);
static void		FrameEventProc(void *clientData,
static void		FrameCmdDeletedProc(ClientData clientData);
static void		FrameEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		FrameLostContentProc(void *clientData,
static void		FrameLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		FrameRequestProc(void *clientData,
static void		FrameRequestProc(ClientData clientData,
			    Tk_Window tkwin);
static void		FrameStructureProc(void *clientData,
static void		FrameStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_ObjCmdProc FrameWidgetObjCmd;
static void		FrameWorldChanged(void *instanceData);
static void		MapFrame(void *clientData);
static int		FrameWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		FrameWorldChanged(ClientData instanceData);
static void		MapFrame(ClientData clientData);

/*
 * The structure below defines frame class behavior by means of functions that
 * can be invoked from generic window code.
 */

static const Tk_ClassProcs frameClass = {
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+







 * The structure below defines the official type record for the labelframe's
 * geometry manager:
 */

static const Tk_GeomMgr frameGeomType = {
    "labelframe",		/* name */
    FrameRequestProc,		/* requestProc */
    FrameLostContentProc		/* lostContentProc */
    FrameLostSlaveProc		/* lostSlaveProc */
};

/*
 *--------------------------------------------------------------
 *
 * Tk_FrameObjCmd, Tk_ToplevelObjCmd, Tk_LabelframeObjCmd --
 *
391
392
393
394
395
396
397
398

399
400
401
402
403

404
405
406
407
408

409
410
411
412
413

414
415
416
417
418

419
420
421
422
423

424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445













446


















447























448

449
450

451
452
453
454
455
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
366
367
368
369
370
371
372

373
374
375
376
377

378
379
380
381
382

383
384
385
386
387

388
389
390
391
392

393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478

479
480
481
482
483
484
485
486
487
488
489
490


491
492
493
494
495
496
497
498







-
+




-
+




-
+




-
+




-
+




-
+




















+


+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
+











-
-
+







 *	call CreateFrame to do all of the real work.
 *
 *--------------------------------------------------------------
 */

int
Tk_FrameObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    return TkCreateFrame(clientData, interp, objc, objv, TYPE_FRAME, NULL);
    return CreateFrame(clientData, interp, objc, objv, TYPE_FRAME, NULL);
}

int
Tk_ToplevelObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    return TkCreateFrame(clientData, interp, objc, objv, TYPE_TOPLEVEL, NULL);
    return CreateFrame(clientData, interp, objc, objv, TYPE_TOPLEVEL, NULL);
}

int
Tk_LabelframeObjCmd(
    void *clientData,	/* Either NULL or pointer to option table. */
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    return TkCreateFrame(clientData, interp, objc, objv, TYPE_LABELFRAME, NULL);
    return CreateFrame(clientData, interp, objc, objv, TYPE_LABELFRAME, NULL);
}

/*
 *--------------------------------------------------------------
 *
 * TkCreateFrame --
 *
 *	This function is the old command function for the "frame" and
 *	"toplevel" commands. Now it is used directly by Tk_Init to create a
 *	new main window. See the user documentation for the "frame" and
 *	"toplevel" commands for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkCreateFrame(
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int argc,			/* Number of arguments. */
    const char *const *argv,	/* Argument strings. */
    int toplevel,		/* Non-zero means create a toplevel window,
				 * zero means create a frame. */
    const char *appName)	/* Should only be non-NULL if there is no main
				 * window associated with the interpreter.
				 * Gives the base name to use for the new
				 * application. */
{
    int result, i;
    Tcl_Obj **objv = ckalloc((argc+1) * sizeof(Tcl_Obj **));
    TCL_UNUSED(void *),

    for (i=0; i<argc; i++) {
	objv[i] = Tcl_NewStringObj(argv[i], -1);
	Tcl_IncrRefCount(objv[i]);
    }
    objv[argc] = NULL;
    result = CreateFrame(clientData, interp, argc, objv,
	    toplevel ? TYPE_TOPLEVEL : TYPE_FRAME, appName);
    for (i=0; i<argc; i++) {
	Tcl_DecrRefCount(objv[i]);
    }
    ckfree(objv);
    return result;
}

int
TkListCreateFrame(
    ClientData clientData,	/* Either NULL or pointer to option table. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Obj *listObj,		/* List of arguments. */
    int toplevel,		/* Non-zero means create a toplevel window,
				 * zero means create a frame. */
    Tcl_Obj *nameObj)		/* Should only be non-NULL if there is no main
				 * window associated with the interpreter.
				 * Gives the base name to use for the new
				 * application. */
{
    int objc;
    Tcl_Obj **objv;

    if (TCL_OK != Tcl_ListObjGetElements(interp, listObj, &objc, &objv)) {
	return TCL_ERROR;
    }
    return CreateFrame(clientData, interp, objc, objv,
	    toplevel ? TYPE_TOPLEVEL : TYPE_FRAME,
	    nameObj ? Tcl_GetString(nameObj) : NULL);
}

static int
CreateFrame(
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    int type,	/* What widget type to create. */
    enum FrameType type,	/* What widget type to create. */
    const char *appName)	/* Should only be non-NULL if there are no
				 * Main window associated with the
				 * interpreter. Gives the base name to use for
				 * the new application. */
{
    Tk_Window tkwin;
    Frame *framePtr;
    Tk_OptionTable optionTable;
    Tk_Window newWin;
    const char *className, *screenName, *visualName, *colormapName;
    const char *arg, *useOption;
    int depth;
    Tcl_Size i, length;
    int i, length, depth;
    unsigned int mask;
    Colormap colormap;
    Visual *visual;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
488
489
490
491
492
493
494
495

496
497
498

499
500
501

502
503
504

505
506
507

508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523


524
525
526
527
528
529
530
516
517
518
519
520
521
522

523
524
525

526
527
528

529
530
531

532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549


550
551
552
553
554
555
556
557
558







-
+


-
+


-
+


-
+


-
+














-
-
+
+







    colormap = None;
    for (i = 2; i < objc; i += 2) {
	arg = Tcl_GetStringFromObj(objv[i], &length);
	if (length < 2) {
	    continue;
	}
	if ((arg[1] == 'c') && (length >= 3)
		&& (strncmp(arg, "-class", length) == 0)) {
		&& (strncmp(arg, "-class", (unsigned) length) == 0)) {
	    className = Tcl_GetString(objv[i+1]);
	} else if ((arg[1] == 'c') && (length >= 3)
		&& (strncmp(arg, "-colormap", length) == 0)) {
		&& (strncmp(arg, "-colormap", (unsigned) length) == 0)) {
	    colormapName = Tcl_GetString(objv[i+1]);
	} else if ((arg[1] == 's') && (type == TYPE_TOPLEVEL)
		&& (strncmp(arg, "-screen", length) == 0)) {
		&& (strncmp(arg, "-screen", (unsigned) length) == 0)) {
	    screenName = Tcl_GetString(objv[i+1]);
	} else if ((arg[1] == 'u') && (type == TYPE_TOPLEVEL)
		&& (strncmp(arg, "-use", length) == 0)) {
		&& (strncmp(arg, "-use", (unsigned) length) == 0)) {
	    useOption = Tcl_GetString(objv[i+1]);
	} else if ((arg[1] == 'v')
		&& (strncmp(arg, "-visual", length) == 0)) {
		&& (strncmp(arg, "-visual", (unsigned) length) == 0)) {
	    visualName = Tcl_GetString(objv[i+1]);
	}
    }

    /*
     * Create the window, and deal with the special options -use, -classname,
     * -colormap, -screenname, and -visual. These options must be handle
     * before calling ConfigureFrame below, and they must also be processed in
     * a particular order, for the following reasons:
     * 1. Must set the window's class before calling ConfigureFrame, so that
     *	  unspecified options are looked up in the option database using the
     *	  correct class.
     * 2. Must set visual information before calling ConfigureFrame so that
     *	  colors are allocated in a proper colormap.
     * 3. Must call Tk_UseWindow before setting non-default visual
     *	  information, since Tk_UseWindow changes the defaults.
     * 3. Must call TkpUseWindow before setting non-default visual
     *	  information, since TkpUseWindow changes the defaults.
     */

    if (screenName == NULL) {
	screenName = (type == TYPE_TOPLEVEL) ? "" : NULL;
    }

    /*
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
598
599
600
601
602
603
604

605
606
607
608
609
610
611
612







-
+







	}
    }
    Tk_SetClass(newWin, className);
    if (useOption == NULL) {
	useOption = Tk_GetOption(newWin, "use", "Use");
    }
    if ((useOption != NULL) && (*useOption != 0)
	    && (Tk_UseWindow(interp, newWin, useOption) != TCL_OK)) {
	    && (TkpUseWindow(interp, newWin, useOption) != TCL_OK)) {
	goto error;
    }
    if (visualName == NULL) {
	visualName = Tk_GetOption(newWin, "visual", "Visual");
    }
    if (colormapName == NULL) {
	colormapName = Tk_GetOption(newWin, "colormap", "Colormap");
615
616
617
618
619
620
621
622

623
624
625

626
627
628
629
630
631
632
633
634
635
636
637

638
639
640
641
642
643

644
645
646
647
648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664
665
666

667
668
669
670

671
672
673
674
675

676
677
678
679
680
681
682
643
644
645
646
647
648
649

650
651
652

653
654
655
656
657
658
659
660
661
662
663
664

665
666
667
668
669
670

671
672
673
674
675
676
677
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693

694
695
696
697

698
699
700
701
702

703
704
705
706
707
708
709
710







-
+


-
+











-
+





-
+













-
+








-
+



-
+




-
+







    /*
     * Create the widget record, process configuration options, and create
     * event handlers. Then fill in a few additional fields in the widget
     * record from the special options.
     */

    if (type == TYPE_LABELFRAME) {
	framePtr = (Frame *)ckalloc(sizeof(Labelframe));
	framePtr = ckalloc(sizeof(Labelframe));
	memset(framePtr, 0, sizeof(Labelframe));
    } else {
	framePtr = (Frame *)ckalloc(sizeof(Frame));
	framePtr = ckalloc(sizeof(Frame));
	memset(framePtr, 0, sizeof(Frame));
    }
    framePtr->tkwin = newWin;
    framePtr->display = Tk_Display(newWin);
    framePtr->interp = interp;
    framePtr->widgetCmd	= Tcl_CreateObjCommand(interp, Tk_PathName(newWin),
	    FrameWidgetObjCmd, framePtr, FrameCmdDeletedProc);
    framePtr->optionTable = optionTable;
    framePtr->type = type;
    framePtr->colormap = colormap;
    framePtr->relief = TK_RELIEF_FLAT;
    framePtr->cursor = NULL;
    framePtr->cursor = None;

    if (framePtr->type == TYPE_LABELFRAME) {
	Labelframe *labelframePtr = (Labelframe *) framePtr;

	labelframePtr->labelAnchor = LABELANCHOR_NW;
	labelframePtr->textGC = NULL;
	labelframePtr->textGC = None;
    }

    /*
     * Store backreference to frame widget in window structure.
     */

    Tk_SetClassProcs(newWin, &frameClass, framePtr);

    mask = ExposureMask | StructureNotifyMask | FocusChangeMask;
    if (type == TYPE_TOPLEVEL) {
	mask |= ActivateMask;
    }
    Tk_CreateEventHandler(newWin, mask, FrameEventProc, framePtr);
    if ((Tk_InitOptions(interp, framePtr, optionTable, newWin)
    if ((Tk_InitOptions(interp, (char *) framePtr, optionTable, newWin)
	    != TCL_OK) ||
	    (ConfigureFrame(interp, framePtr, objc-2, objv+2) != TCL_OK)) {
	goto error;
    }
    if (framePtr->isContainer) {
	if (framePtr->useThis != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "windows cannot have both the -use and the -container"
		    " option set", TCL_INDEX_NONE));
		    " option set", -1));
	    Tcl_SetErrorCode(interp, "TK", "FRAME", "CONTAINMENT", NULL);
	    goto error;
	}
	Tk_MakeContainer(framePtr->tkwin);
	TkpMakeContainer(framePtr->tkwin);
    }
    if (type == TYPE_TOPLEVEL) {
	Tcl_DoWhenIdle(MapFrame, framePtr);
    }
    Tcl_SetObjResult(interp, Tk_NewWindowObj(newWin));
    Tcl_SetObjResult(interp, TkNewWindowObj(newWin));
    return TCL_OK;

  error:
    if (newWin != NULL) {
	Tk_DestroyWindow(newWin);
    }
    return TCL_ERROR;
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713
714
715
716

717
718
719

720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748

749
750
751
752
753
754
755
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743

744
745


746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764

765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782







-
+










-
+

-
-
+


















-
+









-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
FrameWidgetObjCmd(
    void *clientData,	/* Information about frame widget. */
    ClientData clientData,	/* Information about frame widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const frameOptions[] = {
	"cget", "configure", NULL
    };
    enum options {
	FRAME_CGET, FRAME_CONFIGURE
    };
    Frame *framePtr = (Frame *)clientData;
    register Frame *framePtr = clientData;
    int result = TCL_OK, index;
    int c;
    Tcl_Size i, length;
    int c, i, length;
    Tcl_Obj *objPtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], frameOptions,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_Preserve(framePtr);
    switch ((enum options) index) {
    case FRAME_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    goto done;
	}
	objPtr = Tk_GetOptionValue(interp, framePtr,
	objPtr = Tk_GetOptionValue(interp, (char *) framePtr,
		framePtr->optionTable, objv[2], framePtr->tkwin);
	if (objPtr == NULL) {
	    result = TCL_ERROR;
	    goto done;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;
    case FRAME_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, framePtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) framePtr,
		    framePtr->optionTable, (objc == 3) ? objv[2] : NULL,
		    framePtr->tkwin);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
		goto done;
	    }
	    Tcl_SetObjResult(interp, objPtr);
763
764
765
766
767
768
769
770

771
772

773
774

775
776

777
778

779
780

781
782

783
784
785
786

787
788
789
790
791
792
793
790
791
792
793
794
795
796

797
798

799
800

801
802

803
804

805
806

807
808

809
810
811
812

813
814
815
816
817
818
819
820







-
+

-
+

-
+

-
+

-
+

-
+

-
+



-
+







		const char *arg = Tcl_GetStringFromObj(objv[i], &length);

		if (length < 2) {
		    continue;
		}
		c = arg[1];
		if (((c == 'c') && (length >= 2)
			&& (strncmp(arg, "-class", length) == 0))
			&& (strncmp(arg, "-class", (unsigned)length) == 0))
		    || ((c == 'c') && (length >= 3)
			&& (strncmp(arg, "-colormap", length) == 0))
			&& (strncmp(arg, "-colormap", (unsigned)length) == 0))
		    || ((c == 'c') && (length >= 3)
			&& (strncmp(arg, "-container", length) == 0))
			&& (strncmp(arg, "-container", (unsigned)length) == 0))
		    || ((c == 's') && (framePtr->type == TYPE_TOPLEVEL)
			&& (strncmp(arg, "-screen", length) == 0))
			&& (strncmp(arg, "-screen", (unsigned)length) == 0))
		    || ((c == 'u') && (framePtr->type == TYPE_TOPLEVEL)
			&& (strncmp(arg, "-use", length) == 0))
			&& (strncmp(arg, "-use", (unsigned)length) == 0))
		    || ((c == 'v')
			&& (strncmp(arg, "-visual", length) == 0))) {
			&& (strncmp(arg, "-visual", (unsigned)length) == 0))) {

#ifdef _WIN32
#ifdef SUPPORT_CONFIG_EMBEDDED
		    if (c == 'u') {
			const char *string = Tcl_GetString(objv[i+1]);

			if (Tk_UseWindow(interp, framePtr->tkwin,
			if (TkpUseWindow(interp, framePtr->tkwin,
				string) != TCL_OK) {
			    result = TCL_ERROR;
			    goto done;
			}
			continue;
		    }
#endif
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840


841
842
843
844

845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
853
854
855
856
857
858
859

860



861


862
863
864
865
866

867
868
869
870





871
872
873



874
875
876
877
878
879
880







-

-
-
-

-
-
+
+



-
+



-
-
-
-
-



-
-
-







 *	Everything associated with the frame is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyFrame(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about frame widget. */
#else
    char *memPtr)
#endif
{
    Frame *framePtr = (Frame *)memPtr;
    Labelframe *labelframePtr = (Labelframe *)memPtr;
    register Frame *framePtr = memPtr;
    register Labelframe *labelframePtr = memPtr;

    if (framePtr->type == TYPE_LABELFRAME) {
	Tk_FreeTextLayout(labelframePtr->textLayout);
	if (labelframePtr->textGC != NULL) {
	if (labelframePtr->textGC != None) {
	    Tk_FreeGC(framePtr->display, labelframePtr->textGC);
	}
    }
#ifndef TK_NO_DOUBLE_BUFFERING
    if (framePtr->copyGC != NULL) {
	Tk_FreeGC(framePtr->display, framePtr->copyGC);
    }
#endif /* TK_NO_DOUBLE_BUFFERING */
    if (framePtr->colormap != None) {
	Tk_FreeColormap(framePtr->display, framePtr->colormap);
    }
    if (framePtr->bgimg) {
	Tk_FreeImage(framePtr->bgimg);
    }
    ckfree(framePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyFramePartly --
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896
897

898
899
900
901
902
903
904
892
893
894
895
896
897
898

899
900
901
902
903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919







-
+












-
+







 *----------------------------------------------------------------------
 */

static void
DestroyFramePartly(
    Frame *framePtr)		/* Info about frame widget. */
{
    Labelframe *labelframePtr = (Labelframe *) framePtr;
    register Labelframe *labelframePtr = (Labelframe *) framePtr;

    if (framePtr->type == TYPE_LABELFRAME && labelframePtr->labelWin != NULL) {
	Tk_DeleteEventHandler(labelframePtr->labelWin, StructureNotifyMask,
		FrameStructureProc, framePtr);
	Tk_ManageGeometry(labelframePtr->labelWin, NULL, NULL);
	if (framePtr->tkwin != Tk_Parent(labelframePtr->labelWin)) {
	    Tk_UnmaintainGeometry(labelframePtr->labelWin, framePtr->tkwin);
	}
	Tk_UnmapWindow(labelframePtr->labelWin);
	labelframePtr->labelWin = NULL;
    }

    Tk_FreeConfigOptions(framePtr, framePtr->optionTable,
    Tk_FreeConfigOptions((char *) framePtr, framePtr->optionTable,
	    framePtr->tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigureFrame --
917
918
919
920
921
922
923
924

925
926

927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942

943
944
945
946
947
948
949

950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982

983
984
985
986
987
988
989
932
933
934
935
936
937
938

939
940

941
942
943
944
945
946
947

948
949
950
951
952
953
954
955

956
957
958
959
960
961
962

963
964
965
966
967
968
969
970














971
972
973
974
975
976
977
978
979
980
981

982
983
984
985
986
987
988
989







-
+

-
+






-








-
+






-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureFrame(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Frame *framePtr,	/* Information about widget; may or may not
    register Frame *framePtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in objv. */
    int objc,			/* Number of valid entries in objv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    Tk_SavedOptions savedOptions;
    char *oldMenuName;
    Tk_Window oldWindow = NULL;
    Labelframe *labelframePtr = (Labelframe *) framePtr;
    Tk_Image image = NULL;

    /*
     * Need the old menubar name for the menu code to delete it.
     */

    if (framePtr->menuName == NULL) {
    	oldMenuName = NULL;
    } else {
    	oldMenuName = (char *)ckalloc(strlen(framePtr->menuName) + 1);
    	oldMenuName = ckalloc(strlen(framePtr->menuName) + 1);
    	strcpy(oldMenuName, framePtr->menuName);
    }

    if (framePtr->type == TYPE_LABELFRAME) {
	oldWindow = labelframePtr->labelWin;
    }
    if (Tk_SetOptions(interp, framePtr,
    if (Tk_SetOptions(interp, (char *) framePtr,
	    framePtr->optionTable, objc, objv,
	    framePtr->tkwin, &savedOptions, NULL) != TCL_OK) {
	if (oldMenuName != NULL) {
	    ckfree(oldMenuName);
	}
	return TCL_ERROR;
    }

    if (framePtr->bgimgPtr) {
	image = Tk_GetImage(interp, framePtr->tkwin,
		Tcl_GetString(framePtr->bgimgPtr), FrameBgImageProc, framePtr);
	if (image == NULL) {
	    Tk_RestoreSavedOptions(&savedOptions);
	    return TCL_ERROR;
	}
    }
    if (framePtr->bgimg) {
	Tk_FreeImage(framePtr->bgimg);
    }
    framePtr->bgimg = image;

    Tk_FreeSavedOptions(&savedOptions);

    /*
     * A few of the options require additional processing.
     */

    if ((((oldMenuName == NULL) && (framePtr->menuName != NULL))
	    || ((oldMenuName != NULL) && (framePtr->menuName == NULL))
	    || ((oldMenuName != NULL) && (framePtr->menuName != NULL)
	    && strcmp(oldMenuName, framePtr->menuName) != 0))
	    && framePtr->type == TYPE_TOPLEVEL) {
	Tk_SetWindowMenubar(interp, framePtr->tkwin, oldMenuName,
	TkSetWindowMenuBar(interp, framePtr->tkwin, oldMenuName,
		framePtr->menuName);
    }

    if (oldMenuName != NULL) {
    	ckfree(oldMenuName);
    }

1088
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098


1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155
1088
1089
1090
1091
1092
1093
1094

1095
1096


1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111









1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1146







-
+

-
-
+
+













-
-
-
-
-
-
-
-
-











-
+















-
+







 *	Frame will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
FrameWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    Frame *framePtr = (Frame *)instanceData;
    Labelframe *labelframePtr = (Labelframe *)instanceData;
    Frame *framePtr = instanceData;
    Labelframe *labelframePtr = instanceData;
    Tk_Window tkwin = framePtr->tkwin;
    XGCValues gcValues;
    GC gc;
    int anyTextLabel, anyWindowLabel;
    int bWidthLeft, bWidthRight, bWidthTop, bWidthBottom;
    const char *labelText;

    anyTextLabel = (framePtr->type == TYPE_LABELFRAME) &&
	    (labelframePtr->textPtr != NULL) &&
	    (labelframePtr->labelWin == NULL);
    anyWindowLabel = (framePtr->type == TYPE_LABELFRAME) &&
	    (labelframePtr->labelWin != NULL);

#ifndef TK_NO_DOUBLE_BUFFERING
    gcValues.graphics_exposures = False;
    gc = Tk_GetGC(tkwin, GCGraphicsExposures, &gcValues);
    if (framePtr->copyGC != NULL) {
	Tk_FreeGC(framePtr->display, framePtr->copyGC);
    }
    framePtr->copyGC = gc;
#endif /* TK_NO_DOUBLE_BUFFERING */

    if (framePtr->type == TYPE_LABELFRAME) {
	/*
	 * The textGC is needed even in the labelWin case, so it's always
	 * created for a labelframe.
	 */

	gcValues.font = Tk_FontId(labelframePtr->tkfont);
	gcValues.foreground = labelframePtr->textColorPtr->pixel;
	gcValues.graphics_exposures = False;
	gc = Tk_GetGC(tkwin, GCForeground | GCFont | GCGraphicsExposures,
		&gcValues);
	if (labelframePtr->textGC != NULL) {
	if (labelframePtr->textGC != None) {
	    Tk_FreeGC(framePtr->display, labelframePtr->textGC);
	}
	labelframePtr->textGC = gc;

	/*
	 * Calculate label size.
	 */

	labelframePtr->labelReqWidth = labelframePtr->labelReqHeight = 0;

	if (anyTextLabel) {
	    labelText = Tcl_GetString(labelframePtr->textPtr);
	    Tk_FreeTextLayout(labelframePtr->textLayout);
	    labelframePtr->textLayout =
		    Tk_ComputeTextLayout(labelframePtr->tkfont,
		    labelText, TCL_INDEX_NONE, 0, TK_JUSTIFY_CENTER, 0,
		    labelText, -1, 0, TK_JUSTIFY_CENTER, 0,
		    &labelframePtr->labelReqWidth,
		    &labelframePtr->labelReqHeight);
	    labelframePtr->labelReqWidth += 2 * LABELSPACING;
	    labelframePtr->labelReqHeight += 2 * LABELSPACING;
	} else if (anyWindowLabel) {
	    labelframePtr->labelReqWidth = Tk_ReqWidth(labelframePtr->labelWin);
	    labelframePtr->labelReqHeight =
1268
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279
1280
1281
1282
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273







-
+







 *	Display-related numbers get changed in *framePtr.
 *
 *----------------------------------------------------------------------
 */

static void
ComputeFrameGeometry(
    Frame *framePtr)	/* Information about widget. */
    register Frame *framePtr)	/* Information about widget. */
{
    int otherWidth, otherHeight, otherWidthT, otherHeightT, padding;
    int maxWidth, maxHeight;
    Tk_Window tkwin;
    Labelframe *labelframePtr = (Labelframe *) framePtr;

    /*
1415
1416
1417
1418
1419
1420
1421
1422

1423
1424
1425


1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449

1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499














1500
1501
1502
1503
1504
1505
1506
1406
1407
1408
1409
1410
1411
1412

1413
1414


1415
1416
1417
1418

1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455














1456
1457
1458
1459
1460
1461
1462

1463
1464




1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493







-
+

-
-
+
+


-
+




















-
+


-
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+

-
-
-
-








+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	Commands are output to X to display the frame in its current mode.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayFrame(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    Frame *framePtr = (Frame *)clientData;
    Tk_Window tkwin = framePtr->tkwin;
    register Frame *framePtr = clientData;
    register Tk_Window tkwin = framePtr->tkwin;
    int bdX1, bdY1, bdX2, bdY2, hlWidth;
    Pixmap pixmap;
    Bool useClipping = False;
    TkRegion clipRegion = NULL;

    framePtr->flags &= ~REDRAW_PENDING;
    if ((framePtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    /*
     * Highlight shall always be drawn if it exists, so do that first.
     */

    hlWidth = framePtr->highlightWidth;

    if (hlWidth != 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(framePtr->highlightBgColorPtr,
		Tk_WindowId(tkwin));
	if (framePtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(framePtr->highlightColorPtr,
		    Tk_WindowId(tkwin));
	    Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, hlWidth,
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC, hlWidth,
		    Tk_WindowId(tkwin));
	} else {
	    Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, hlWidth,
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC, hlWidth,
		    Tk_WindowId(tkwin));
	}
    }

    /*
     * If -background is set to "", no interior is drawn.
     */

    if (framePtr->border == NULL) {
	return;
    }

#ifndef TK_NO_DOUBLE_BUFFERING
    /*
     * In order to avoid screen flashes, this function redraws the frame into
     * off-screen memory, then copies it back on-screen in a single operation.
     * This means there's no point in time where the on-screen image has been
     * cleared.
     */

    pixmap = Tk_GetPixmap(framePtr->display, Tk_WindowId(tkwin),
	    Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
#else
    pixmap = Tk_WindowId(tkwin);
#endif /* TK_NO_DOUBLE_BUFFERING */

    if (framePtr->type != TYPE_LABELFRAME) {
	/*
	 * Pass to platform specific draw function. In general, it just draws
	 * a simple rectangle, but it may "theme" the background.
	 */

    noLabel:
	TkpDrawFrameEx(tkwin, pixmap, framePtr->border, hlWidth,
	TkpDrawFrame(tkwin, framePtr->border, hlWidth,
		framePtr->borderWidth, framePtr->relief);
	if (framePtr->bgimg) {
	    DrawFrameBackground(tkwin, pixmap, hlWidth, framePtr->borderWidth,
		    framePtr->bgimg, framePtr->tile);
	}
    } else {
	Labelframe *labelframePtr = (Labelframe *) framePtr;

	if ((labelframePtr->textPtr == NULL) &&
		(labelframePtr->labelWin == NULL)) {
	    goto noLabel;
	}

#ifndef TK_NO_DOUBLE_BUFFERING
	/*
	 * In order to avoid screen flashes, this function redraws the frame
	 * into off-screen memory, then copies it back on-screen in a single
	 * operation. This means there's no point in time where the on-screen
	 * image has been cleared.
	 */

	pixmap = Tk_GetPixmap(framePtr->display, Tk_WindowId(tkwin),
		Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
#else
	pixmap = Tk_WindowId(tkwin);
#endif /* TK_NO_DOUBLE_BUFFERING */

	/*
	 * Clear the pixmap.
	 */

	Tk_Fill3DRectangle(tkwin, pixmap, framePtr->border, 0, 0,
		Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);

1560
1561
1562
1563
1564
1565
1566


1567
1568


1569

1570
1571
1572
1573
1574
1575
1576
1577

1578

1579
1580
1581
1582
1583
1584
1585
1547
1548
1549
1550
1551
1552
1553
1554
1555


1556
1557

1558
1559
1560
1561
1562
1563
1564
1565

1566
1567
1568
1569
1570
1571
1572
1573
1574
1575







+
+
-
-
+
+
-
+







-
+

+







	     * Draw label. If there is not room for the entire label, use
	     * clipping to get a nice appearance.
	     */

	    if ((labelframePtr->labelBox.width < labelframePtr->labelReqWidth)
		    || (labelframePtr->labelBox.height <
			    labelframePtr->labelReqHeight)) {
		clipRegion = TkCreateRegion();
		TkUnionRectWithRegion(&labelframePtr->labelBox, clipRegion,
		useClipping = True;
		XSetClipRectangles(framePtr->display, labelframePtr->textGC, 0, 0,
			clipRegion);
		TkSetRegion(framePtr->display, labelframePtr->textGC,
			&labelframePtr->labelBox, 1, Unsorted);
			clipRegion);
	    }

	    Tk_DrawTextLayout(framePtr->display, pixmap,
		    labelframePtr->textGC, labelframePtr->textLayout,
		    labelframePtr->labelTextX + LABELSPACING,
		    labelframePtr->labelTextY + LABELSPACING, 0, -1);

	    if (useClipping) {
	    if (clipRegion != NULL) {
		XSetClipMask(framePtr->display, labelframePtr->textGC, None);
		TkDestroyRegion(clipRegion);
	    }
	} else {
	    /*
	     * Reposition and map the window (but in different ways depending
	     * on whether the frame is the window's parent).
	     */

1601
1602
1603
1604
1605
1606
1607
1608

1609
1610
1611
1612
1613
1614




1615
1616
1617
1618
1619
1620
1621






1622
1623
1624


1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1591
1592
1593
1594
1595
1596
1597

1598

1599




1600
1601
1602
1603
1604






1605
1606
1607
1608
1609
1610
1611


1612
1613































1614
1615
1616
1617
1618
1619
1620







-
+
-

-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    } else {
		Tk_MaintainGeometry(labelframePtr->labelWin, framePtr->tkwin,
			labelframePtr->labelBox.x, labelframePtr->labelBox.y,
			labelframePtr->labelBox.width,
			labelframePtr->labelBox.height);
	    }
	}
    }


#ifndef TK_NO_DOUBLE_BUFFERING
    /*
     * Everything's been redisplayed; now copy the pixmap onto the screen and
     * free up the pixmap.
     */
	/*
	 * Everything's been redisplayed; now copy the pixmap onto the screen
	 * and free up the pixmap.
	 */

    XCopyArea(framePtr->display, pixmap, Tk_WindowId(tkwin),
	    framePtr->copyGC, hlWidth, hlWidth,
	    (unsigned) (Tk_Width(tkwin) - 2 * hlWidth),
	    (unsigned) (Tk_Height(tkwin) - 2 * hlWidth),
	    hlWidth, hlWidth);
    Tk_FreePixmap(framePtr->display, pixmap);
	XCopyArea(framePtr->display, pixmap, Tk_WindowId(tkwin),
		labelframePtr->textGC, hlWidth, hlWidth,
		(unsigned) (Tk_Width(tkwin) - 2 * hlWidth),
		(unsigned) (Tk_Height(tkwin) - 2 * hlWidth),
		hlWidth, hlWidth);
	Tk_FreePixmap(framePtr->display, pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
}

    }

/*
 *----------------------------------------------------------------------
 *
 * TkpDrawFrame --
 *
 *	This procedure draws the rectangular frame area.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws inside the tkwin area.
 *
 *----------------------------------------------------------------------
 */

void
TkpDrawFrame(
    Tk_Window tkwin,
    Tk_3DBorder border,
    int highlightWidth,
    int borderWidth,
    int relief)
{
    /*
     * Legacy shim to allow for external callers. Internal ones use
     * non-exposed TkpDrawFrameEx directly so they can use double-buffering.
     */

    TkpDrawFrameEx(tkwin, Tk_WindowId(tkwin), border,
	    highlightWidth, borderWidth, relief);
}

/*
 *--------------------------------------------------------------
 *
 * FrameEventProc --
 *
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
1630
1631
1632
1633
1634
1635
1636


1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
1656







-
-
+
+

-
+








-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
FrameEventProc(
    void *clientData,	/* Information about window. */
    XEvent *eventPtr)	/* Information about event. */
    ClientData clientData,	/* Information about window. */
    register XEvent *eventPtr)	/* Information about event. */
{
    Frame *framePtr = (Frame *)clientData;
    register Frame *framePtr = clientData;

    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	goto redraw;
    } else if (eventPtr->type == ConfigureNotify) {
	ComputeFrameGeometry(framePtr);
	goto redraw;
    } else if (eventPtr->type == DestroyNotify) {
	if (framePtr->menuName != NULL) {
	    Tk_SetWindowMenubar(framePtr->interp, framePtr->tkwin,
	    TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
		    framePtr->menuName, NULL);
	    ckfree(framePtr->menuName);
	    framePtr->menuName = NULL;
	}
	if (framePtr->tkwin != NULL) {
	    /*
	     * If this window is a container, then this event could be coming
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
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







-
+















-
+







	    framePtr->tkwin = NULL;
	    Tcl_DeleteCommandFromToken(framePtr->interp, framePtr->widgetCmd);
	}
	if (framePtr->flags & REDRAW_PENDING) {
	    Tcl_CancelIdleCall(DisplayFrame, framePtr);
	}
	Tcl_CancelIdleCall(MapFrame, framePtr);
	Tcl_EventuallyFree(framePtr, DestroyFrame);
	Tcl_EventuallyFree(framePtr, (Tcl_FreeProc *) DestroyFrame);
    } else if (eventPtr->type == FocusIn) {
	if (eventPtr->xfocus.detail != NotifyInferior) {
	    framePtr->flags |= GOT_FOCUS;
	    if (framePtr->highlightWidth > 0) {
		goto redraw;
	    }
	}
    } else if (eventPtr->type == FocusOut) {
	if (eventPtr->xfocus.detail != NotifyInferior) {
	    framePtr->flags &= ~GOT_FOCUS;
	    if (framePtr->highlightWidth > 0) {
		goto redraw;
	    }
	}
    } else if (eventPtr->type == ActivateNotify) {
    	Tk_SetMainMenubar(framePtr->interp, framePtr->tkwin,
    	TkpSetMainMenubar(framePtr->interp, framePtr->tkwin,
    		framePtr->menuName);
    }
    return;

  redraw:
    if ((framePtr->tkwin != NULL) && !(framePtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(DisplayFrame, framePtr);
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774

1775
1776
1777
1778

1779
1780
1781
1782
1783
1784
1785
1723
1724
1725
1726
1727
1728
1729

1730
1731

1732
1733
1734
1735

1736
1737
1738
1739
1740
1741
1742
1743







-
+

-
+



-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
FrameCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    Frame *framePtr = (Frame *)clientData;
    Frame *framePtr = clientData;
    Tk_Window tkwin = framePtr->tkwin;

    if (framePtr->menuName != NULL) {
	Tk_SetWindowMenubar(framePtr->interp, framePtr->tkwin,
	TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
		framePtr->menuName, NULL);
	ckfree(framePtr->menuName);
	framePtr->menuName = NULL;
    }

    /*
     * This function could be invoked either because the window was destroyed
1816
1817
1818
1819
1820
1821
1822
1823

1824
1825

1826
1827
1828
1829
1830
1831
1832
1774
1775
1776
1777
1778
1779
1780

1781
1782

1783
1784
1785
1786
1787
1788
1789
1790







-
+

-
+







 *	The frame given by the clientData argument is mapped.
 *
 *----------------------------------------------------------------------
 */

static void
MapFrame(
    void *clientData)		/* Pointer to frame structure. */
    ClientData clientData)		/* Pointer to frame structure. */
{
    Frame *framePtr = (Frame *)clientData;
    Frame *framePtr = clientData;

    /*
     * Wait for all other background events to be processed before mapping
     * window. This ensures that the window's correct geometry will have been
     * determined before it is first mapped, so that the window manager
     * doesn't get a false idea of its desired geometry.
     */
1873
1874
1875
1876
1877
1878
1879
1880

1881
1882
1883
1884
1885
1886
1887
1831
1832
1833
1834
1835
1836
1837

1838
1839
1840
1841
1842
1843
1844
1845







-
+







void
TkInstallFrameMenu(
    Tk_Window tkwin)		/* The window that was just created. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;

    if (winPtr->mainPtr != NULL) {
	Frame *framePtr = (Frame *)winPtr->instanceData;
	Frame *framePtr = winPtr->instanceData;

	if (framePtr == NULL) {
	    Tcl_Panic("TkInstallFrameMenu couldn't get frame pointer");
	}
	TkpMenuNotifyToplevelCreate(winPtr->mainPtr->interp,
		framePtr->menuName);
    }
1903
1904
1905
1906
1907
1908
1909
1910

1911
1912
1913

1914
1915
1916
1917
1918
1919
1920
1861
1862
1863
1864
1865
1866
1867

1868
1869
1870

1871
1872
1873
1874
1875
1876
1877
1878







-
+


-
+







 *	The window is disassociated from the frame when it is deleted.
 *
 *--------------------------------------------------------------
 */

static void
FrameStructureProc(
    void *clientData,	/* Pointer to record describing frame. */
    ClientData clientData,	/* Pointer to record describing frame. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Labelframe *labelframePtr = (Labelframe *)clientData;
    Labelframe *labelframePtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	/*
	 * This should only happen in a labelframe but it doesn't hurt to be
	 * careful.
	 */

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
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







-
-
+
+

-
+







-
+


-
+





-
+





-
-
+
+

-
+

-
-
+
+







 *	on the options specified for the frame.
 *
 *--------------------------------------------------------------
 */

static void
FrameRequestProc(
    void *clientData,	/* Pointer to record for frame. */
    TCL_UNUSED(Tk_Window))		/* Window that changed its desired size. */
    ClientData clientData,	/* Pointer to record for frame. */
    Tk_Window tkwin)		/* Window that changed its desired size. */
{
    Frame *framePtr = (Frame *)clientData;
    Frame *framePtr = clientData;

    FrameWorldChanged(framePtr);
}

/*
 *--------------------------------------------------------------
 *
 * FrameLostContentProc --
 * FrameLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a content window that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all frame-related information about the content window.
 *	Forgets all frame-related information about the slave.
 *
 *--------------------------------------------------------------
 */

static void
FrameLostContentProc(
    void *clientData,	/* Frame structure for content window window that was
FrameLostSlaveProc(
    ClientData clientData,	/* Frame structure for slave window that was
				 * stolen away. */
    TCL_UNUSED(Tk_Window))		/* Tk's handle for the content window window. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    Frame *framePtr = (Frame *)clientData;
    Labelframe *labelframePtr = (Labelframe *)clientData;
    Frame *framePtr = clientData;
    Labelframe *labelframePtr = clientData;

    /*
     * This should only happen in a labelframe but it doesn't hurt to be
     * careful.
     */

    if (labelframePtr->frame.type == TYPE_LABELFRAME) {
1996
1997
1998
1999
2000
2001
2002
2003

2004
2005
2006
2007
2008
2009
2010

2011
2012
2013
2014
2015
2016
2017
1954
1955
1956
1957
1958
1959
1960

1961
1962
1963
1964
1965
1966
1967

1968
1969
1970
1971
1972
1973
1974
1975







-
+






-
+







    FrameWorldChanged(framePtr);
}

void
TkMapTopFrame(
     Tk_Window tkwin)
{
    Frame *framePtr = (Frame *)((TkWindow *) tkwin)->instanceData;
    Frame *framePtr = ((TkWindow *) tkwin)->instanceData;
    Tk_OptionTable optionTable;

    if (Tk_IsTopLevel(tkwin) && framePtr->type == TYPE_FRAME) {
	framePtr->type = TYPE_TOPLEVEL;
	Tcl_DoWhenIdle(MapFrame, framePtr);
	if (framePtr->menuName != NULL) {
	    Tk_SetWindowMenubar(framePtr->interp, framePtr->tkwin, NULL,
	    TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin, NULL,
		    framePtr->menuName);
	}
    } else if (!Tk_IsTopLevel(tkwin) && framePtr->type == TYPE_TOPLEVEL) {
	framePtr->type = TYPE_FRAME;
    } else {
	/*
	 * Not a frame or toplevel, skip it.
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
2018
2019
2020
2021
2022
2023
2024

2025
2026
2027
2028
2029
2030



























































































































2031
2032
2033
2034
2035
2036
2037
2038







-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









    if (Tcl_GetCommandInfo(interp, cmdName, &cmdInfo) == 0) {
	return NULL;
    }
    if (cmdInfo.objProc != FrameWidgetObjCmd) {
	return NULL;
    }
    framePtr = (Frame *)cmdInfo.objClientData;
    framePtr = cmdInfo.objClientData;
    if (framePtr->type != TYPE_TOPLEVEL) {
	return NULL;
    }
    return framePtr->tkwin;
}

/*
 *----------------------------------------------------------------------
 *
 * FrameBgImageProc --
 *
 *	This function is invoked by the image code whenever the manager for an
 *	image does something that affects the size or contents of an image
 *	displayed on a frame's background.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Arranges for the button to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
FrameBgImageProc(
    void *clientData,	/* Pointer to widget record. */
    TCL_UNUSED(int), /* Upper left pixel (within image) that must */
    TCL_UNUSED(int), /* be redisplayed. */
    TCL_UNUSED(int),	/* Dimensions of area to redisplay (might be */
    TCL_UNUSED(int), /* <= 0). */
    TCL_UNUSED(int), /* New dimensions of image. */
    TCL_UNUSED(int))
{
    Frame *framePtr = (Frame *)clientData;

    /*
     * Changing the background image never alters the dimensions of the frame.
     */

    if (framePtr->tkwin && Tk_IsMapped(framePtr->tkwin) &&
	    !(framePtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(DisplayFrame, framePtr);
	framePtr->flags |= REDRAW_PENDING;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DrawFrameBackground --
 *
 *	This function draws the background image of a rectangular frame area.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws inside the tkwin area.
 *
 *----------------------------------------------------------------------
 */

static void
DrawFrameBackground(
    Tk_Window tkwin,
    Pixmap pixmap,
    int highlightWidth,
    int borderWidth,
    Tk_Image bgimg,
    int bgtile)
{
    int width, height;			/* Area to paint on. */
    int imageWidth, imageHeight;	/* Dimensions of image. */
    const int bw = highlightWidth + borderWidth;

    Tk_SizeOfImage(bgimg, &imageWidth, &imageHeight);
    width = Tk_Width(tkwin) - 2*bw;
    height = Tk_Height(tkwin) - 2*bw;

    if (bgtile) {
	/*
	 * Draw the image tiled in the widget (inside the border).
	 */

	int x, y;

	for (x = bw; x - bw < width; x += imageWidth) {
	    int w = imageWidth;
	    if (x - bw + imageWidth > width) {
		w = (width + bw) - x;
	    }
	    for (y = bw; y < height + bw; y += imageHeight) {
		int h = imageHeight;
		if (y - bw + imageHeight > height) {
		    h = (height + bw) - y;
		}
		Tk_RedrawImage(bgimg, 0, 0, w, h, pixmap, x, y);
	    }
	}
    } else {
	/*
	 * Draw the image centred in the widget (inside the border).
	 */

	int x, y, xOff, yOff, w, h;

	if (width > imageWidth) {
	    x = 0;
	    xOff = (Tk_Width(tkwin) - imageWidth) / 2;
	    w = imageWidth;
	} else {
	    x = (imageWidth - width) / 2;
	    xOff = bw;
	    w = width;
	}
	if (height > imageHeight) {
	    y = 0;
	    yOff = (Tk_Height(tkwin) - imageHeight) / 2;
	    h = imageHeight;
	} else {
	    y = (imageHeight - height) / 2;
	    yOff = bw;
	    h = height;
	}
	Tk_RedrawImage(bgimg, x, y, w, h, pixmap, xOff, yOff);
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkGC.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkGC.c --
 *
 *	This file maintains a database of read-only graphics contexts for the
 *	Tk toolkit, in order to allow GC's to be shared.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

62
63
64
65
66
67
68
69

70
71
72
73

74
75
76
77
78
79

80
81
82
83
84
85
86
62
63
64
65
66
67
68

69
70
71
72

73
74
75
76
77
78

79
80
81
82
83
84
85
86







-
+



-
+





-
+







 *
 *----------------------------------------------------------------------
 */

GC
Tk_GetGC(
    Tk_Window tkwin,		/* Window in which GC will be used. */
    unsigned long valueMask,
    register unsigned long valueMask,
				/* 1 bits correspond to values specified in
				 * *valuesPtr; other values are set from
				 * defaults. */
    XGCValues *valuePtr)
    register XGCValues *valuePtr)
				/* Values are specified here for bits set in
				 * valueMask. */
{
    ValueKey valueKey;
    Tcl_HashEntry *valueHashPtr, *idHashPtr;
    TkGC *gcPtr;
    register TkGC *gcPtr;
    int isNew;
    Drawable d, freeDrawable;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (dispPtr->gcInit <= 0) {
	GCInit(dispPtr);
    }
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238







-
+









-
+







    }
    valueKey.display = Tk_Display(tkwin);
    valueKey.screenNum = Tk_ScreenNumber(tkwin);
    valueKey.depth = Tk_Depth(tkwin);
    valueHashPtr = Tcl_CreateHashEntry(&dispPtr->gcValueTable,
	    (char *) &valueKey, &isNew);
    if (!isNew) {
	gcPtr = (TkGC *)Tcl_GetHashValue(valueHashPtr);
	gcPtr = Tcl_GetHashValue(valueHashPtr);
	gcPtr->refCount++;
	return gcPtr->gc;
    }

    /*
     * No GC is currently available for this set of values. Allocate a new GC
     * and add a new structure to the database.
     */

    gcPtr = (TkGC *)ckalloc(sizeof(TkGC));
    gcPtr = ckalloc(sizeof(TkGC));

    /*
     * Find or make a drawable to use to specify the screen and depth of the
     * GC. We may have to make a small pixmap, to avoid doing
     * Tk_MakeWindowExist on the window.
     */

287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314

315
316
317
318
319
320
321
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

310
311
312
313

314
315
316
317
318
319
320
321







-
+















-
+



-
+








void
Tk_FreeGC(
    Display *display,		/* Display for which gc was allocated. */
    GC gc)			/* Graphics context to be released. */
{
    Tcl_HashEntry *idHashPtr;
    TkGC *gcPtr;
    register TkGC *gcPtr;
    TkDisplay *dispPtr = TkGetDisplay(display);

    if (!dispPtr->gcInit) {
	Tcl_Panic("Tk_FreeGC called before Tk_GetGC");
    }
    if (dispPtr->gcInit < 0) {
	/*
	 * The GCCleanup has been called, and remaining GCs have been freed.
	 * This may still get called by other things shutting down, but the
	 * GCs should no longer be in use.
	 */

	return;
    }

    idHashPtr = Tcl_FindHashEntry(&dispPtr->gcIdTable, gc);
    idHashPtr = Tcl_FindHashEntry(&dispPtr->gcIdTable, (char *) gc);
    if (idHashPtr == NULL) {
	Tcl_Panic("Tk_FreeGC received unknown gc argument");
    }
    gcPtr = (TkGC *)Tcl_GetHashValue(idHashPtr);
    gcPtr = Tcl_GetHashValue(idHashPtr);
    if (gcPtr->refCount-- <= 1) {
	XFreeGC(gcPtr->display, gcPtr->gc);
	Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
	Tcl_DeleteHashEntry(idHashPtr);
	ckfree(gcPtr);
    }
}
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357







-
+







{
    Tcl_HashEntry *entryPtr;
    Tcl_HashSearch search;
    TkGC *gcPtr;

    for (entryPtr = Tcl_FirstHashEntry(&dispPtr->gcIdTable, &search);
	    entryPtr != NULL; entryPtr = Tcl_NextHashEntry(&search)) {
	gcPtr = (TkGC *)Tcl_GetHashValue(entryPtr);
	gcPtr = Tcl_GetHashValue(entryPtr);

	XFreeGC(gcPtr->display, gcPtr->gc);
	Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
	Tcl_DeleteHashEntry(entryPtr);
	ckfree(gcPtr);
    }
    Tcl_DeleteHashTable(&dispPtr->gcValueTable);

Changes to generic/tkGeometry.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19


20
21
22
23
24



25
26
27
28
29
30





31
32
33


34
35
36

37
38
39
40

41
42
43
44
45
46
47
48
49
50



51
52
53
54
55
56
57

58
59

60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99


100
101
102
103
104
105
106
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17


18
19
20
21



22
23
24
25





26
27
28
29
30
31


32
33
34
35

36
37
38
39

40
41
42
43
44
45
46
47



48
49
50
51
52
53
54
55
56

57
58

59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97


98
99
100
101
102
103
104
105
106






-
-
+
+









-
-
+
+


-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+


-
+



-
+







-
-
-
+
+
+






-
+

-
+








-
+









-
+














-
+




-
-
+
+







/*
 * tkGeometry.c --
 *
 *	This file contains generic Tk code for geometry management (stuff
 *	that's used by all geometry managers).
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

/*
 * Data structures of the following type are used by Tk_MaintainGeometry. For
 * each content managed by Tk_MaintainGeometry, there is one of these structures
 * associated with its container.
 * each slave managed by Tk_MaintainGeometry, there is one of these structures
 * associated with its master.
 */

typedef struct MaintainContent {
    Tk_Window content;		/* The content window being positioned. */
    Tk_Window container;		/* The container that determines content's
typedef struct MaintainSlave {
    Tk_Window slave;		/* The slave window being positioned. */
    Tk_Window master;		/* The master that determines slave's
				 * position; it must be a descendant of
				 * content's parent. */
    int x, y;			/* Desired position of content relative to
				 * container. */
    int width, height;		/* Desired dimensions of content. */
    struct MaintainContent *nextPtr;
				 * slave's parent. */
    int x, y;			/* Desired position of slave relative to
				 * master. */
    int width, height;		/* Desired dimensions of slave. */
    struct MaintainSlave *nextPtr;
				/* Next in list of Maintains associated with
				 * container. */
} MaintainContent;
				 * master. */
} MaintainSlave;

/*
 * For each window that has been specified as a content to Tk_MaintainGeometry,
 * For each window that has been specified as a master to Tk_MaintainGeometry,
 * there is a structure of the following type:
 */

typedef struct MaintainContainer {
typedef struct MaintainMaster {
    Tk_Window ancestor;		/* The lowest ancestor of this window for
				 * which we have *not* created a
				 * StructureNotify handler. May be the same as
				 * the window itself. */
    int checkScheduled;		/* Non-zero means that there is already a call
				 * to MaintainCheckProc scheduled as an idle
				 * handler. */
    MaintainContent *contentPtr;	/* First in list of all content associated with
				 * this container. */
} MaintainContainer;
    MaintainSlave *slavePtr;	/* First in list of all slaves associated with
				 * this master. */
} MaintainMaster;

/*
 * Prototypes for static procedures in this file:
 */

static void		MaintainCheckProc(ClientData clientData);
static void		MaintainContainerProc(ClientData clientData,
static void		MaintainMasterProc(ClientData clientData,
			    XEvent *eventPtr);
static void		MaintainContentProc(ClientData clientData,
static void		MaintainSlaveProc(ClientData clientData,
			    XEvent *eventPtr);

/*
 *--------------------------------------------------------------
 *
 * Tk_ManageGeometry --
 *
 *	Arrange for a particular procedure to manage the geometry of a given
 *	content window.
 *	slave window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Proc becomes the new geometry manager for tkwin, replacing any
 *	previous geometry manager. The geometry manager will be notified (by
 *	calling procedures in *mgrPtr) when interesting things happen in the
 *	future. If there was an existing geometry manager for tkwin different
 *	from the new one, it is notified by calling its lostContentProc.
 *	from the new one, it is notified by calling its lostSlaveProc.
 *
 *--------------------------------------------------------------
 */

void
Tk_ManageGeometry(
    Tk_Window tkwin,		/* Window whose geometry is to be managed by
				 * proc. */
    const Tk_GeomMgr *mgrPtr,	/* Static structure describing the geometry
				 * manager. This structure must never go
				 * away. */
    ClientData clientData)	/* Arbitrary one-word argument to pass to
				 * geometry manager procedures. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if ((winPtr->geomMgrPtr != NULL) && (mgrPtr != NULL)
	    && ((winPtr->geomMgrPtr != mgrPtr)
		|| (winPtr->geomData != clientData))
	    && (winPtr->geomMgrPtr->lostContentProc != NULL)) {
	winPtr->geomMgrPtr->lostContentProc(winPtr->geomData, tkwin);
	    && (winPtr->geomMgrPtr->lostSlaveProc != NULL)) {
	winPtr->geomMgrPtr->lostSlaveProc(winPtr->geomData, tkwin);
    }

    winPtr->geomMgrPtr = mgrPtr;
    winPtr->geomData = clientData;
}

/*
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142







-
+







void
Tk_GeometryRequest(
    Tk_Window tkwin,		/* Window that geometry information pertains
				 * to. */
    int reqWidth, int reqHeight)/* Minimum desired dimensions for window, in
				 * pixels. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * X gets very upset if a window requests a width or height of zero, so
     * rounds requested sizes up to at least 1.
     */

    if (reqWidth <= 0) {
178
179
180
181
182
183
184
185
186


187
188
189
190
191
192
193
178
179
180
181
182
183
184


185
186
187
188
189
190
191
192
193







-
-
+
+








void
Tk_SetInternalBorderEx(
    Tk_Window tkwin,		/* Window that will have internal border. */
    int left, int right,	/* Width of internal border, in pixels. */
    int top, int bottom)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    int changed = 0;
    register TkWindow *winPtr = (TkWindow *) tkwin;
    register int changed = 0;

    if (left < 0) {
	left = 0;
    }
    if (left != winPtr->internalBorderLeft) {
	winPtr->internalBorderLeft = left;
	changed = 1;
214
215
216
217
218
219
220
221

222
223
224



225
226
227
228

229
230
231
232
233
234
235
214
215
216
217
218
219
220

221
222


223
224
225
226
227
228

229
230
231
232
233
234
235
236







-
+

-
-
+
+
+



-
+







    }
    if (bottom != winPtr->internalBorderBottom) {
	winPtr->internalBorderBottom = bottom;
	changed = 1;
    }

    /*
     * All the content for which this is the container window must now be
     * All the slaves for which this is the master window must now be
     * repositioned to take account of the new internal border width. To
     * signal all the geometry managers to do this, trigger a ConfigureNotify
     * event. This will cause geometry managers to recompute everything.
     * signal all the geometry managers to do this, just resize the window to
     * its current size. The ConfigureNotify event will cause geometry
     * managers to recompute everything.
     */

    if (changed) {
	TkDoConfigureNotify(winPtr);
	Tk_ResizeWindow(tkwin, Tk_Width(tkwin), Tk_Height(tkwin));
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetInternalBorder --
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290







-
+







 */

void
Tk_SetMinimumRequestSize(
    Tk_Window tkwin,		/* Window that will have internal border. */
    int minWidth, int minHeight)/* Minimum requested size, in pixels. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if ((winPtr->minReqWidth == minWidth) &&
	    (winPtr->minReqHeight == minHeight)) {
	return;
    }

    winPtr->minReqWidth = minWidth;
299
300
301
302
303
304
305
306

307
308

309
310
311
312
313
314
315

316
317
318
319
320
321

322
323

324
325

326
327

328
329
330


331
332
333

334
335
336
337
338



339
340
341
342
343
344
345


346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361

362
363
364
365
366
367
368


369
370

371
372

373
374
375


376
377

378
379
380
381



382
383
384
385
386
387
388
389
390
391
392
393
394
395






396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418





419
420
421
422


423
424
425

426
427
428
429

430
431

432
433
434
435
436
437

438
439
440
441


442
443
444
445
446


447
448
449
450
451
452
453
454
455
456
457

458
459
460
461

462
463

464
465

466
467
468
469
470
471





472
473
474
475

476
477
478
479
480
481
482




483
484
485
486
487
488
489
490
491







492
493
494
495
496
497



498
499
500

501
502

503
504
505


506
507
508
509
510
511
512
513
514
515
516
517
518





519
520

521
522
523
524
525
526
527
528
529





530
531
532

533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557



558
559
560
561
562
563
564
565
566



567
568
569
570


571
572

573
574
575
576

577
578

579
580
581
582
583
584
585
586
587
588
589
590
591


592
593

594
595
596
597
598
599
600




601
602
603
604



605
606
607
608


609
610
611
612
613
614
615
616
617
618






619
620
621


622
623
624
625
626
627


628
629
630

631
632
633
634
635
636
637

638
639
640

641
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
658



659
660
661
662


663
664
665
666
667
668
669
670



671
672
673
674
675


676
677
678
679
680
681
682


683
684
685

686
687
688
689
690
691
692
693

694
695
696

697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712



713
714
715

716
717
718

719
720
721
722
723
724
725
726
727
728
729
730
731




732
733
734
735
736
737

738
739
740
741
742
743
744
745


746
747
748


749
750
751
752
753
754
755
756
757






758
759

760
761
762
763
764
765
766



767
768
769

770
771

772
773
774
775
776
777
778
300
301
302
303
304
305
306

307
308

309
310
311
312
313
314
315

316
317
318
319
320
321

322
323

324
325

326
327

328
329


330
331
332
333

334
335
336



337
338
339
340
341
342
343
344


345
346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361

362
363
364
365
366
367


368
369
370

371
372

373
374


375
376
377

378
379



380
381
382
383
384
385
386
387
388
389
390






391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413
414





415
416
417
418
419
420
421


422
423
424
425

426
427



428
429

430
431
432
433
434
435

436
437
438


439
440
441
442
443


444
445
446
447
448
449
450
451
452
453
454
455

456
457
458
459

460
461

462
463

464
465





466
467
468
469
470
471
472
473

474
475
476
477




478
479
480
481
482
483







484
485
486
487
488
489
490
491
492
493



494
495
496
497
498

499
500

501
502


503
504
505
506
507
508
509
510
511
512





513
514
515
516
517
518

519
520
521
522
523





524
525
526
527
528
529
530

531
532

533
534
535
536
537
538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553



554
555
556
557
558
559
560
561
562



563
564
565
566
567


568
569
570

571
572



573
574

575
576
577
578
579
580
581
582
583
584
585
586


587
588
589

590
591
592
593




594
595
596
597
598



599
600
601
602
603


604
605
606
607
608
609






610
611
612
613
614
615
616


617
618
619
620
621
622


623
624
625
626

627
628
629
630
631
632
633

634
635
636

637
638
639
640
641
642
643
644
645

646
647
648
649
650
651
652



653
654
655
656
657


658
659
660
661
662
663
664



665
666
667
668
669
670


671
672
673
674
675
676
677


678
679
680
681

682
683
684
685
686
687
688
689

690
691
692

693
694
695
696
697
698
699
700

701
702
703
704
705
706



707
708
709
710
711

712
713
714

715
716
717
718
719
720
721
722
723
724




725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740


741
742
743


744
745
746
747
748






749
750
751
752
753
754
755

756
757
758
759
760



761
762
763
764
765

766
767

768
769
770
771
772
773
774
775







-
+

-
+






-
+





-
+

-
+

-
+

-
+

-
-
+
+


-
+


-
-
-
+
+
+





-
-
+
+






-
+

-
+






-
+





-
-
+
+

-
+

-
+

-
-
+
+

-
+

-
-
-
+
+
+








-
-
-
-
-
-
+
+
+
+
+
+







-
+










-
-
-
-
-
+
+
+
+
+


-
-
+
+


-
+

-
-
-
+

-
+





-
+


-
-
+
+



-
-
+
+










-
+



-
+

-
+

-
+

-
-
-
-
-
+
+
+
+
+



-
+



-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
+
+
+


-
+

-
+

-
-
+
+








-
-
-
-
-
+
+
+
+
+

-
+




-
-
-
-
-
+
+
+
+
+


-
+

-
+














-
+





-
-
-
+
+
+






-
-
-
+
+
+


-
-
+
+

-
+

-
-
-
+

-
+











-
-
+
+

-
+



-
-
-
-
+
+
+
+

-
-
-
+
+
+


-
-
+
+




-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+




-
-
+
+


-
+






-
+


-
+








-
+






-
-
-
+
+
+


-
-
+
+





-
-
-
+
+
+



-
-
+
+





-
-
+
+


-
+







-
+


-
+







-
+





-
-
-
+
+
+


-
+


-
+









-
-
-
-
+
+
+
+





-
+






-
-
+
+

-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+

-
+




-
-
-
+
+
+


-
+

-
+








    Tk_ResizeWindow(tkwin, Tk_Width(tkwin), Tk_Height(tkwin));
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetGeometryContainer --
 * TkSetGeometryMaster --
 *
 *	Set a geometry container for this window. Only one container may own
 *	Set a geometry master for this window. Only one master may own
 *	a window at any time.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	The geometry container is recorded for the window.
 *	The geometry master is recorded for the window.
 *
 *----------------------------------------------------------------------
 */

int
TkSetGeometryContainer(
TkSetGeometryMaster(
    Tcl_Interp *interp,		/* Current interpreter, for error. */
    Tk_Window tkwin,		/* Window that will have geometry container
    Tk_Window tkwin,		/* Window that will have geometry master
				 * set. */
    const char *name)		/* The name of the geometry manager. */
    const char *master)		/* The master identity. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if (winPtr->geomMgrName != NULL &&
	    strcmp(winPtr->geomMgrName, name) == 0) {
    if (winPtr->geometryMaster != NULL &&
	    strcmp(winPtr->geometryMaster, master) == 0) {
	return TCL_OK;
    }
    if (winPtr->geomMgrName != NULL) {
    if (winPtr->geometryMaster != NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "cannot use geometry manager %s inside %s because"
		    " %s is already managing it's content windows",
		    name, Tk_PathName(tkwin), winPtr->geomMgrName));
		    "cannot use geometry manager %s inside %s which already"
		    " has slaves managed by %s",
		    master, Tk_PathName(tkwin), winPtr->geometryMaster));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "FIGHT", NULL);
	}
	return TCL_ERROR;
    }

    winPtr->geomMgrName = (char *)ckalloc(strlen(name) + 1);
    strcpy(winPtr->geomMgrName, name);
    winPtr->geometryMaster = ckalloc(strlen(master) + 1);
    strcpy(winPtr->geometryMaster, master);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkFreeGeometryContainer --
 * TkFreeGeometryMaster --
 *
 *	Remove a geometry container for this window. Only one container may own
 *	Remove a geometry master for this window. Only one master may own
 *	a window at any time.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The geometry container is cleared for the window.
 *	The geometry master is cleared for the window.
 *
 *----------------------------------------------------------------------
 */

void
TkFreeGeometryContainer(
    Tk_Window tkwin,		/* Window that will have geometry container
TkFreeGeometryMaster(
    Tk_Window tkwin,		/* Window that will have geometry master
				 * cleared. */
    const char *name)		/* The name of the geometry manager. */
    const char *master)		/* The master identity. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if (winPtr->geomMgrName != NULL &&
	    strcmp(winPtr->geomMgrName, name) != 0) {
    if (winPtr->geometryMaster != NULL &&
	    strcmp(winPtr->geometryMaster, master) != 0) {
	Tcl_Panic("Trying to free %s from geometry manager %s",
		winPtr->geomMgrName, name);
		winPtr->geometryMaster, master);
    }
    if (winPtr->geomMgrName != NULL) {
	ckfree(winPtr->geomMgrName);
	winPtr->geomMgrName = NULL;
    if (winPtr->geometryMaster != NULL) {
	ckfree(winPtr->geometryMaster);
	winPtr->geometryMaster = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MaintainGeometry --
 *
 *	This procedure is invoked by geometry managers to handle content whose
 *	container's are not their parents. It translates the desired geometry for
 *	the content into the coordinate system of the parent and respositions
 *	the content if it isn't already at the right place. Furthermore, it sets
 *	up event handlers so that if the container (or any of its ancestors up to
 *	the content's parent) is mapped, unmapped, or moved, then the content will
 *	This procedure is invoked by geometry managers to handle slaves whose
 *	master's are not their parents. It translates the desired geometry for
 *	the slave into the coordinate system of the parent and respositions
 *	the slave if it isn't already at the right place. Furthermore, it sets
 *	up event handlers so that if the master (or any of its ancestors up to
 *	the slave's parent) is mapped, unmapped, or moved, then the slave will
 *	be adjusted to match.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Event handlers are created and state is allocated to keep track of
 *	content. Note: if content was already managed for container by
 *	slave. Note: if slave was already managed for master by
 *	Tk_MaintainGeometry, then the previous information is replaced with
 *	the new information. The caller must eventually call
 *	Tk_UnmaintainGeometry to eliminate the correspondence (or, the state
 *	is automatically freed when either window is destroyed).
 *
 *----------------------------------------------------------------------
 */

void
Tk_MaintainGeometry(
    Tk_Window window,		/* Window for geometry management. */
    Tk_Window container,		/* Container for window; must be a descendant of
				 * window's parent. */
    int x, int y,		/* Desired position of window within container. */
    int width, int height)	/* Desired dimensions for window. */
    Tk_Window slave,		/* Slave for geometry management. */
    Tk_Window master,		/* Master for slave; must be a descendant of
				 * slave's parent. */
    int x, int y,		/* Desired position of slave within master. */
    int width, int height)	/* Desired dimensions for slave. */
{
    Tcl_HashEntry *hPtr;
    MaintainContainer *containerPtr;
    MaintainContent *contentPtr;
    MaintainMaster *masterPtr;
    register MaintainSlave *slavePtr;
    int isNew, map;
    Tk_Window ancestor, parent;
    TkDisplay *dispPtr = ((TkWindow *) container)->dispPtr;
    TkDisplay *dispPtr = ((TkWindow *) master)->dispPtr;

    ((TkWindow *)window)->maintainerPtr = (TkWindow *)container;

    if (container == Tk_Parent(window)) {
    if (master == Tk_Parent(slave)) {
	/*
	 * If the window is a direct descendant of the container, don't bother
	 * If the slave is a direct descendant of the master, don't bother
	 * setting up the extra infrastructure for management, just make a
	 * call to Tk_MoveResizeWindow; the parent/child relationship will
	 * take care of the rest.
	 */

	Tk_MoveResizeWindow(window, x, y, width, height);
	Tk_MoveResizeWindow(slave, x, y, width, height);

	/*
	 * Map the window if the container is already mapped; otherwise, wait
	 * until the container is mapped later (in which case mapping the window
	 * Map the slave if the master is already mapped; otherwise, wait
	 * until the master is mapped later (in which case mapping the slave
	 * is taken care of elsewhere).
	 */

	if (Tk_IsMapped(container)) {
	    Tk_MapWindow(window);
	if (Tk_IsMapped(master)) {
	    Tk_MapWindow(slave);
	}
	return;
    }

    if (!dispPtr->geomInit) {
	dispPtr->geomInit = 1;
	Tcl_InitHashTable(&dispPtr->maintainHashTable, TCL_ONE_WORD_KEYS);
    }

    /*
     * See if there is already a MaintainContainer structure for the container; if
     * See if there is already a MaintainMaster structure for the master; if
     * not, then create one.
     */

    parent = Tk_Parent(window);
    parent = Tk_Parent(slave);
    hPtr = Tcl_CreateHashEntry(&dispPtr->maintainHashTable,
	    (char *) container, &isNew);
	    (char *) master, &isNew);
    if (!isNew) {
	containerPtr = (MaintainContainer *)Tcl_GetHashValue(hPtr);
	masterPtr = Tcl_GetHashValue(hPtr);
    } else {
	containerPtr = (MaintainContainer *)ckalloc(sizeof(MaintainContainer));
	containerPtr->ancestor = container;
	containerPtr->checkScheduled = 0;
	containerPtr->contentPtr = NULL;
	Tcl_SetHashValue(hPtr, containerPtr);
	masterPtr = ckalloc(sizeof(MaintainMaster));
	masterPtr->ancestor = master;
	masterPtr->checkScheduled = 0;
	masterPtr->slavePtr = NULL;
	Tcl_SetHashValue(hPtr, masterPtr);
    }

    /*
     * Create a MaintainContent structure for the window if there isn't already
     * Create a MaintainSlave structure for the slave if there isn't already
     * one.
     */

    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	if (contentPtr->content == window) {
	    goto gotContent;
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	if (slavePtr->slave == slave) {
	    goto gotSlave;
	}
    }
    contentPtr = (MaintainContent *)ckalloc(sizeof(MaintainContent));
    contentPtr->content = window;
    contentPtr->container = container;
    contentPtr->nextPtr = containerPtr->contentPtr;
    containerPtr->contentPtr = contentPtr;
    Tk_CreateEventHandler(window, StructureNotifyMask, MaintainContentProc,
	    contentPtr);
    slavePtr = ckalloc(sizeof(MaintainSlave));
    slavePtr->slave = slave;
    slavePtr->master = master;
    slavePtr->nextPtr = masterPtr->slavePtr;
    masterPtr->slavePtr = slavePtr;
    Tk_CreateEventHandler(slave, StructureNotifyMask, MaintainSlaveProc,
	    slavePtr);

    /*
     * Make sure that there are event handlers registered for all the windows
     * between container and windows's parent (including container but not window's
     * parent). There may already be handlers for container and some of its
     * ancestors (containerPtr->ancestor tells how many).
     * between master and slave's parent (including master but not slave's
     * parent). There may already be handlers for master and some of its
     * ancestors (masterPtr->ancestor tells how many).
     */

    for (ancestor = container; ancestor != parent;
    for (ancestor = master; ancestor != parent;
	    ancestor = Tk_Parent(ancestor)) {
	if (ancestor == containerPtr->ancestor) {
	if (ancestor == masterPtr->ancestor) {
	    Tk_CreateEventHandler(ancestor, StructureNotifyMask,
		    MaintainContainerProc, containerPtr);
	    containerPtr->ancestor = Tk_Parent(ancestor);
		    MaintainMasterProc, masterPtr);
	    masterPtr->ancestor = Tk_Parent(ancestor);
	}
    }

    /*
     * Fill in up-to-date information in the structure, then update the window
     * if it's not currently in the right place or state.
     */

  gotContent:
    contentPtr->x = x;
    contentPtr->y = y;
    contentPtr->width = width;
    contentPtr->height = height;
  gotSlave:
    slavePtr->x = x;
    slavePtr->y = y;
    slavePtr->width = width;
    slavePtr->height = height;
    map = 1;
    for (ancestor = contentPtr->container; ; ancestor = Tk_Parent(ancestor)) {
    for (ancestor = slavePtr->master; ; ancestor = Tk_Parent(ancestor)) {
	if (!Tk_IsMapped(ancestor) && (ancestor != parent)) {
	    map = 0;
	}
	if (ancestor == parent) {
	    if ((x != Tk_X(contentPtr->content))
		    || (y != Tk_Y(contentPtr->content))
		    || (width != Tk_Width(contentPtr->content))
		    || (height != Tk_Height(contentPtr->content))) {
		Tk_MoveResizeWindow(contentPtr->content, x, y, width, height);
	    if ((x != Tk_X(slavePtr->slave))
		    || (y != Tk_Y(slavePtr->slave))
		    || (width != Tk_Width(slavePtr->slave))
		    || (height != Tk_Height(slavePtr->slave))) {
		Tk_MoveResizeWindow(slavePtr->slave, x, y, width, height);
	    }
	    if (map) {
		Tk_MapWindow(contentPtr->content);
		Tk_MapWindow(slavePtr->slave);
	    } else {
		Tk_UnmapWindow(contentPtr->content);
		Tk_UnmapWindow(slavePtr->slave);
	    }
	    break;
	}
	x += Tk_X(ancestor) + Tk_Changes(ancestor)->border_width;
	y += Tk_Y(ancestor) + Tk_Changes(ancestor)->border_width;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_UnmaintainGeometry --
 *
 *	This procedure cancels a previous Tk_MaintainGeometry call, so that
 *	the relationship between window and container is no longer maintained.
 *	the relationship between slave and master is no longer maintained.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is unmapped and state is released, so that window won't track
 *	container any more. If we weren't previously managing window relative to
 *	container, then this procedure has no effect.
 *	The slave is unmapped and state is released, so that slave won't track
 *	master any more. If we weren't previously managing slave relative to
 *	master, then this procedure has no effect.
 *
 *----------------------------------------------------------------------
 */

void
Tk_UnmaintainGeometry(
    Tk_Window window,		/* Window for geometry management. */
    Tk_Window container)		/* Container for window; must be a descendant of
				 * window's parent. */
    Tk_Window slave,		/* Slave for geometry management. */
    Tk_Window master)		/* Master for slave; must be a descendant of
				 * slave's parent. */
{
    Tcl_HashEntry *hPtr;
    MaintainContainer *containerPtr;
    MaintainContent *contentPtr, *prevPtr;
    MaintainMaster *masterPtr;
    register MaintainSlave *slavePtr, *prevPtr;
    Tk_Window ancestor;
    TkDisplay *dispPtr = ((TkWindow *) window)->dispPtr;
    TkDisplay *dispPtr = ((TkWindow *) slave)->dispPtr;

    ((TkWindow *)window)->maintainerPtr = NULL;

    if (container == Tk_Parent(window)) {
    if (master == Tk_Parent(slave)) {
	/*
	 * If the window is a direct descendant of the container,
	 * If the slave is a direct descendant of the master,
	 * Tk_MaintainGeometry will not have set up any of the extra
	 * infrastructure. Don't even bother to look for it, just return.
	 */
	return;
    }

    if (!dispPtr->geomInit) {
	dispPtr->geomInit = 1;
	Tcl_InitHashTable(&dispPtr->maintainHashTable, TCL_ONE_WORD_KEYS);
    }

    if (!(((TkWindow *) window)->flags & TK_ALREADY_DEAD)) {
	Tk_UnmapWindow(window);
    if (!(((TkWindow *) slave)->flags & TK_ALREADY_DEAD)) {
	Tk_UnmapWindow(slave);
    }
    hPtr = Tcl_FindHashEntry(&dispPtr->maintainHashTable, container);
    hPtr = Tcl_FindHashEntry(&dispPtr->maintainHashTable, (char *) master);
    if (hPtr == NULL) {
	return;
    }
    containerPtr = (MaintainContainer *)Tcl_GetHashValue(hPtr);
    contentPtr = containerPtr->contentPtr;
    if (contentPtr->content == window) {
	containerPtr->contentPtr = contentPtr->nextPtr;
    masterPtr = Tcl_GetHashValue(hPtr);
    slavePtr = masterPtr->slavePtr;
    if (slavePtr->slave == slave) {
	masterPtr->slavePtr = slavePtr->nextPtr;
    } else {
	for (prevPtr = contentPtr, contentPtr = contentPtr->nextPtr; ;
		prevPtr = contentPtr, contentPtr = contentPtr->nextPtr) {
	    if (contentPtr == NULL) {
	for (prevPtr = slavePtr, slavePtr = slavePtr->nextPtr; ;
		prevPtr = slavePtr, slavePtr = slavePtr->nextPtr) {
	    if (slavePtr == NULL) {
		return;
	    }
	    if (contentPtr->content == window) {
		prevPtr->nextPtr = contentPtr->nextPtr;
	    if (slavePtr->slave == slave) {
		prevPtr->nextPtr = slavePtr->nextPtr;
		break;
	    }
	}
    }
    Tk_DeleteEventHandler(contentPtr->content, StructureNotifyMask,
	    MaintainContentProc, contentPtr);
    ckfree(contentPtr);
    if (containerPtr->contentPtr == NULL) {
	if (containerPtr->ancestor != NULL) {
	    for (ancestor = container; ; ancestor = Tk_Parent(ancestor)) {
    Tk_DeleteEventHandler(slavePtr->slave, StructureNotifyMask,
	    MaintainSlaveProc, slavePtr);
    ckfree(slavePtr);
    if (masterPtr->slavePtr == NULL) {
	if (masterPtr->ancestor != NULL) {
	    for (ancestor = master; ; ancestor = Tk_Parent(ancestor)) {
		Tk_DeleteEventHandler(ancestor, StructureNotifyMask,
			MaintainContainerProc, containerPtr);
		if (ancestor == containerPtr->ancestor) {
			MaintainMasterProc, masterPtr);
		if (ancestor == masterPtr->ancestor) {
		    break;
		}
	    }
	}
	if (containerPtr->checkScheduled) {
	    Tcl_CancelIdleCall(MaintainCheckProc, containerPtr);
	if (masterPtr->checkScheduled) {
	    Tcl_CancelIdleCall(MaintainCheckProc, masterPtr);
	}
	Tcl_DeleteHashEntry(hPtr);
	ckfree(containerPtr);
	ckfree(masterPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MaintainContainerProc --
 * MaintainMasterProc --
 *
 *	This procedure is invoked by the Tk event dispatcher in response to
 *	StructureNotify events on the container or one of its ancestors, on
 *	StructureNotify events on the master or one of its ancestors, on
 *	behalf of Tk_MaintainGeometry.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	It schedules a call to MaintainCheckProc, which will eventually caused
 *	the postions and mapped states to be recalculated for all the
 *	maintained windows of the container. Or, if the container window is being
 *	maintained slaves of the master. Or, if the master window is being
 *	deleted then state is cleaned up.
 *
 *----------------------------------------------------------------------
 */

static void
MaintainContainerProc(
    ClientData clientData,	/* Pointer to MaintainContainer structure for the
				 * container window. */
MaintainMasterProc(
    ClientData clientData,	/* Pointer to MaintainMaster structure for the
				 * master window. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    MaintainContainer *containerPtr = (MaintainContainer *)clientData;
    MaintainContent *contentPtr;
    MaintainMaster *masterPtr = clientData;
    MaintainSlave *slavePtr;
    int done;

    if ((eventPtr->type == ConfigureNotify)
	    || (eventPtr->type == MapNotify)
	    || (eventPtr->type == UnmapNotify)) {
	if (!containerPtr->checkScheduled) {
	    containerPtr->checkScheduled = 1;
	    Tcl_DoWhenIdle(MaintainCheckProc, containerPtr);
	if (!masterPtr->checkScheduled) {
	    masterPtr->checkScheduled = 1;
	    Tcl_DoWhenIdle(MaintainCheckProc, masterPtr);
	}
    } else if (eventPtr->type == DestroyNotify) {
	/*
	 * Delete all of the state associated with this container, but be careful
	 * not to use containerPtr after the last window is deleted, since its
	 * Delete all of the state associated with this master, but be careful
	 * not to use masterPtr after the last slave is deleted, since its
	 * memory will have been freed.
	 */

	done = 0;
	do {
	    contentPtr = containerPtr->contentPtr;
	    if (contentPtr->nextPtr == NULL) {
	    slavePtr = masterPtr->slavePtr;
	    if (slavePtr->nextPtr == NULL) {
		done = 1;
	    }
	    Tk_UnmaintainGeometry(contentPtr->content, contentPtr->container);
	    Tk_UnmaintainGeometry(slavePtr->slave, slavePtr->master);
	} while (!done);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MaintainContentProc --
 * MaintainSlaveProc --
 *
 *	This procedure is invoked by the Tk event dispatcher in response to
 *	StructureNotify events on a window being managed by
 *	StructureNotify events on a slave being managed by
 *	Tk_MaintainGeometry.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	If the event is a DestroyNotify event then the Maintain state and
 *	event handlers for this window are deleted.
 *	event handlers for this slave are deleted.
 *
 *----------------------------------------------------------------------
 */

static void
MaintainContentProc(
    ClientData clientData,	/* Pointer to MaintainContent structure for
				 * container-window pair. */
MaintainSlaveProc(
    ClientData clientData,	/* Pointer to MaintainSlave structure for
				 * master-slave pair. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    MaintainContent *contentPtr = (MaintainContent *)clientData;
    MaintainSlave *slavePtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	Tk_UnmaintainGeometry(contentPtr->content, contentPtr->container);
	Tk_UnmaintainGeometry(slavePtr->slave, slavePtr->master);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MaintainCheckProc --
 *
 *	This procedure is invoked by the Tk event dispatcher as an idle
 *	handler, when a container or one of its ancestors has been reconfigured,
 *	mapped, or unmapped. Its job is to scan all of the windows for the
 *	container and reposition them, map them, or unmap them as needed to
 *	maintain their geometry relative to the container.
 *	handler, when a master or one of its ancestors has been reconfigured,
 *	mapped, or unmapped. Its job is to scan all of the slaves for the
 *	master and reposition them, map them, or unmap them as needed to
 *	maintain their geometry relative to the master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Windows can get repositioned, mapped, or unmapped.
 *	Slaves can get repositioned, mapped, or unmapped.
 *
 *----------------------------------------------------------------------
 */

static void
MaintainCheckProc(
    ClientData clientData)	/* Pointer to MaintainContainer structure for the
				 * container window. */
    ClientData clientData)	/* Pointer to MaintainMaster structure for the
				 * master window. */
{
    MaintainContainer *containerPtr = (MaintainContainer *)clientData;
    MaintainContent *contentPtr;
    MaintainMaster *masterPtr = clientData;
    MaintainSlave *slavePtr;
    Tk_Window ancestor, parent;
    int x, y, map;

    containerPtr->checkScheduled = 0;
    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	parent = Tk_Parent(contentPtr->content);
	x = contentPtr->x;
	y = contentPtr->y;
    masterPtr->checkScheduled = 0;
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	parent = Tk_Parent(slavePtr->slave);
	x = slavePtr->x;
	y = slavePtr->y;
	map = 1;
	for (ancestor = contentPtr->container; ; ancestor = Tk_Parent(ancestor)) {
	for (ancestor = slavePtr->master; ; ancestor = Tk_Parent(ancestor)) {
	    if (!Tk_IsMapped(ancestor) && (ancestor != parent)) {
		map = 0;
	    }
	    if (ancestor == parent) {
		if ((x != Tk_X(contentPtr->content))
			|| (y != Tk_Y(contentPtr->content))) {
		    Tk_MoveWindow(contentPtr->content, x, y);
		if ((x != Tk_X(slavePtr->slave))
			|| (y != Tk_Y(slavePtr->slave))) {
		    Tk_MoveWindow(slavePtr->slave, x, y);
		}
		if (map) {
		    Tk_MapWindow(contentPtr->content);
		    Tk_MapWindow(slavePtr->slave);
		} else {
		    Tk_UnmapWindow(contentPtr->content);
		    Tk_UnmapWindow(slavePtr->slave);
		}
		break;
	    }
	    x += Tk_X(ancestor) + Tk_Changes(ancestor)->border_width;
	    y += Tk_Y(ancestor) + Tk_Changes(ancestor)->border_width;
	}
    }

Changes to generic/tkGet.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41

42
43
44
45
46
47
48
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40

41
42
43
44
45
46
47
48








-
-
+
+














-
+












-
+


-
+







/*
 * tkGet.c --
 *
 *	This file contains a number of "Tk_GetXXX" procedures, which parse
 *	text strings into useful forms for Tk. This file has the simpler
 *	functions, like Tk_GetDirection and Tk_GetUid. The more complex
 *	functions like Tk_GetColor are in separate files.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1991-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.
 */

#include "tkInt.h"

/*
 * One of these structures is created per thread to store thread-specific
 * data. In this case, it is used to house the Tk_Uid structs used by each
 * thread. The "dataKey" below is used to locate the ThreadSpecificData for
 * the current thread.
 */

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;
    Tcl_HashTable uidTable;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

static void		FreeUidThreadExitProc(ClientData clientData);

/*
 * The following tables defines the string values for reliefs, which are
 * used by Tk_GetAnchorFromObj and Tk_GetJustifyFromObj.
 */

const char *const tkAnchorStrings[] = {
static const char *const anchorStrings[] = {
    "n", "ne", "e", "se", "s", "sw", "w", "nw", "center", NULL
};
const char *const tkJustifyStrings[] = {
static const char *const justifyStrings[] = {
    "left", "right", "center", NULL
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetAnchorFromObj --
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







				 * from. */
    Tk_Anchor *anchorPtr)	/* Where to place the Tk_Anchor that
				 * corresponds to the string value of
				 * objPtr. */
{
    int index, code;

    code = Tcl_GetIndexFromObj(interp, objPtr, tkAnchorStrings, "anchor", 0,
    code = Tcl_GetIndexFromObj(interp, objPtr, anchorStrings, "anchor", 0,
	    &index);
    if (code == TCL_OK) {
	*anchorPtr = (Tk_Anchor) index;
    }
    return code;
}

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
186
187
188
189
190
191
192

193
194
195
196
197
198
199







-







    case TK_ANCHOR_E: return "e";
    case TK_ANCHOR_SE: return "se";
    case TK_ANCHOR_S: return "s";
    case TK_ANCHOR_SW: return "sw";
    case TK_ANCHOR_W: return "w";
    case TK_ANCHOR_NW: return "nw";
    case TK_ANCHOR_CENTER: return "center";
    case TK_ANCHOR_NULL: return "";
    }
    return "unknown anchor position";
}

/*
 *--------------------------------------------------------------
 *
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395







-
+







				 * from. */
    Tk_Justify *justifyPtr)	/* Where to place the Tk_Justify that
				 * corresponds to the string value of
				 * objPtr. */
{
    int index, code;

    code = Tcl_GetIndexFromObj(interp, objPtr, tkJustifyStrings,
    code = Tcl_GetIndexFromObj(interp, objPtr, justifyStrings,
	    "justification", 0, &index);
    if (code == TCL_OK) {
	*justifyPtr = (Tk_Justify) index;
    }
    return code;
}

468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
467
468
469
470
471
472
473

474
475
476
477
478
479
480







-







    Tk_Justify justify)		/* Justification style for which identifying
				 * string is desired. */
{
    switch (justify) {
    case TK_JUSTIFY_LEFT: return "left";
    case TK_JUSTIFY_RIGHT: return "right";
    case TK_JUSTIFY_CENTER: return "center";
    case TK_JUSTIFY_NULL: return "";
    }
    return "unknown justification style";
}

/*
 *----------------------------------------------------------------------
 *
491
492
493
494
495
496
497
498

499
500
501


502
503
504
505
506
507
508
489
490
491
492
493
494
495

496
497


498
499
500
501
502
503
504
505
506







-
+

-
-
+
+







 *	All information in the identifier table is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
FreeUidThreadExitProc(
    TCL_UNUSED(void *))
    ClientData clientData)		/* Not used. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    Tcl_DeleteHashTable(&tsdPtr->uidTable);
    tsdPtr->initialized = 0;
}

/*
 *----------------------------------------------------------------------
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
525
526
527
528
529
530
531

532
533
534
535
536
537
538
539







-
+







 */

Tk_Uid
Tk_GetUid(
    const char *string)		/* String to convert. */
{
    int dummy;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashTable *tablePtr = &tsdPtr->uidTable;

    if (!tsdPtr->initialized) {
	Tcl_InitHashTable(tablePtr, TCL_STRING_KEYS);
	Tcl_CreateThreadExitHandler(FreeUidThreadExitProc, NULL);
	tsdPtr->initialized = 1;
569
570
571
572
573
574
575
576

577
578
579
580
581
582



583
584
585

586
587





588
589
590
591

592
593


594
595

596
597

598
599
600
601



602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623

624
625
626

627
628
629
630






631
632






633
634
635
636
637
638
639
567
568
569
570
571
572
573

574
575

576



577
578
579



580


581
582
583
584
585
586
587


588


589
590


591


592




593
594
595


596



















597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627







-
+

-

-
-
-
+
+
+
-
-
-
+
-
-
+
+
+
+
+


-
-
+
-
-
+
+
-
-
+
-
-
+
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+



+




+
+
+
+
+
+


+
+
+
+
+
+







    Tcl_Interp *interp,		/* Use this for error reporting. */
    Tk_Window tkwin,		/* Window whose screen determines conversion
				 * from centimeters and other absolute
				 * units. */
    const char *string,		/* String describing a screen distance. */
    double *doublePtr)		/* Place to store converted result. */
{
    const char *rest;
    char *end;
    double d;
    Tcl_DString ds;

    if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
	if (!tkwin) {
	    if (interp != NULL) {
    d = strtod(string, &end);
    if (end == string) {
	goto error;
		Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL);
	    }
    }
	    return TCL_ERROR;
	}
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    }
    switch (*end) {
    case 0:
	d /= WidthOfScreen(Tk_Screen(tkwin));
	d *= WidthMMOfScreen(Tk_Screen(tkwin));
	*doublePtr = d;
	return TCL_OK;
	break;
    }
    rest = string + strlen(string);
    case 'c':
	d *= 10;
    while ((rest > string) && isspace(UCHAR(rest[-1]))) {
	--rest; /* skip all spaces at the end */
	end++;
    }
    if (rest > string) {
	break;
	--rest; /* point to the character just before the last space */
    }
	if (rest == string) {
	error:
    case 'i':
	d *= 25.4;
	end++;
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	break;
			"expected screen distance or \"\" but got \"%.50s\"", string));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
	    }
	    return TCL_ERROR;
	}
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, string, rest-string);
    if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
	Tcl_DStringFree(&ds);
	goto error;
    }
    Tcl_DStringFree(&ds);
    switch (*rest) {
    case 'c':
	d *= 10;
	break;
    case 'i':
	d *= 25.4;
	break;
    case 'm':
	end++;
	break;
    case 'p':
	d *= 25.4/72.0;
	end++;
	break;
    default:
	goto error;
    }
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    }
    if (*end != 0) {
	goto error;
    }
    *doublePtr = d;
    return TCL_OK;

  error:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad screen distance \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "VALUE", "SCREEN_DISTANCE", NULL);
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_GetPixels --
 *
699
700
701
702
703
704
705
706

707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

726
727
728
729


730
731
732
733
734

735
736
737
738


739
740
741
742
743
744



745
746
747

748
749
750
751

752
753
754
755

756
757
758
759

760
761
762






763
764
765






766
767
768
769
770
771
772
773
774
687
688
689
690
691
692
693

694
695

696
















697




698
699





700




701
702



703


704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752







-
+

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-

-
-
+
+
+



+




+




+




+



+
+
+
+
+
+



+
+
+
+
+
+









    Tcl_Interp *interp,		/* Use this for error reporting. */
    Tk_Window tkwin,		/* Window whose screen determines conversion
				 * from centimeters and other absolute
				 * units. */
    const char *string,		/* String describing a number of pixels. */
    double *doublePtr)		/* Place to store converted result. */
{
    const char *rest;
    char *end;
    double d;
    Tcl_DString ds;

    if (Tcl_GetDouble(NULL, string, &d) == TCL_OK) {
	*doublePtr = d;
	return TCL_OK;
    }
    if (!tkwin) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("bad screen", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
	}
	return TCL_ERROR;
    }
    rest = string + strlen(string);
    while ((rest > string) && isspace(UCHAR(rest[-1]))) {
	--rest; /* skip all spaces at the end */
    }
    if (rest > string) {
    d = strtod((char *) string, &end);
	--rest; /* point to the character just before the last space */
    }
	if (rest == string) {
	error:
    if (end == string) {
	goto error;
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"expected screen distance but got \"%.50s\"", string));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
	    }
    }
	    return TCL_ERROR;
	}
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, string, rest-string);
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    if (Tcl_GetDouble(NULL, Tcl_DStringValue(&ds), &d) != TCL_OK) {
	Tcl_DStringFree(&ds);
	goto error;
    }
    Tcl_DStringFree(&ds);
    switch (*rest) {
    switch (*end) {
    case 0:
	break;
    case 'c':
	d *= 10*WidthOfScreen(Tk_Screen(tkwin));
	d /= WidthMMOfScreen(Tk_Screen(tkwin));
	end++;
	break;
    case 'i':
	d *= 25.4*WidthOfScreen(Tk_Screen(tkwin));
	d /= WidthMMOfScreen(Tk_Screen(tkwin));
	end++;
	break;
    case 'm':
	d *= WidthOfScreen(Tk_Screen(tkwin));
	d /= WidthMMOfScreen(Tk_Screen(tkwin));
	end++;
	break;
    case 'p':
	d *= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin));
	d /= WidthMMOfScreen(Tk_Screen(tkwin));
	end++;
	break;
    default:
	goto error;
    }
    while ((*end != '\0') && isspace(UCHAR(*end))) {
	end++;
    }
    if (*end != 0) {
	goto error;
    }
    *doublePtr = d;
    return TCL_OK;

  error:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad screen distance \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL);
    return TCL_ERROR;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkGrab.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18


19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34





-
-
+
+











-
-








-
+







/*
 * tkGrab.c --
 *
 *	This file provides functions that implement grabs for Tk.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#elif !defined(MAC_OSX_TK)
#include "tkUnixInt.h"
#else
#include "tkMacOSXInt.h"
#endif

/*
 * The grab state machine has four states: ungrabbed, button pressed, grabbed,
 * and button pressed while grabbed. In addition, there are three pieces of
 * grab state information: the current grab window, the current restrict
 * window, and whether the mouse is captured.
 *
 * The current grab window specifies the point in the Tk window hierarchy
 * The current grab window specifies the point in the Tk window heirarchy
 * above which pointer events will not be reported. Any window within the
 * subtree below the grab window will continue to receive events as normal.
 * Events outside of the grab tree will be reported to the grab window.
 *
 * If the current restrict window is set, then all pointer events will be
 * reported only to the restrict window. The restrict window is normally set
 * during an automatic button grab.
132
133
134
135
136
137
138











139
140
141
142
143
144
145
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154







+
+
+
+
+
+
+
+
+
+
+







 * EnterNotify and LeaveNotify events that are generated in this file. This
 * allows us to separate "real" events coming from the server from those that
 * we generated.
 */

#define GENERATED_GRAB_EVENT_MAGIC ((Bool) 0x147321ac)

/*
 * Mask that selects any of the state bits corresponding to buttons, plus
 * masks that select individual buttons' bits:
 */

#define ALL_BUTTONS \
	(Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask)
static const unsigned int buttonStates[] = {
    Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask
};

/*
 * Forward declarations for functions declared later in this file:
 */

static void		EatGrabEvents(TkDisplay *dispPtr, unsigned int serial);
static TkWindow *	FindCommonAncestor(TkWindow *winPtr1,
			    TkWindow *winPtr2, int *countPtr1, int *countPtr2);
164
165
166
167
168
169
170

171
172
173

174
175
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







+


-
+









-
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_GrabObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int globalGrab;
    Tk_Window tkwin;
    TkDisplay *dispPtr;
    const char *arg;
    int index;
    Tcl_Size len;
    int len;
    static const char *const optionStrings[] = {
	"current", "release", "set", "status", NULL
    };
    static const char *const flagStrings[] = {
	"-global", NULL
    };
    enum options {
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260







-
+















-
+







    arg = Tcl_GetStringFromObj(objv[1], &len);
    if (arg[0] == '.') {
	/* [grab window] */
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 1, objv, "?-global? window");
	    return TCL_ERROR;
	}
	tkwin = Tk_NameToWindow(interp, arg, (Tk_Window)clientData);
	tkwin = Tk_NameToWindow(interp, arg, clientData);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	return Tk_Grab(interp, tkwin, 0);
    } else if (arg[0] == '-' && len > 1) {
	if (Tcl_GetIndexFromObj(interp, objv[1], flagStrings, "option", 0,
		&index) != TCL_OK) {
	    return TCL_ERROR;
	}

	/* [grab -global window] */
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "?-global? window");
	    return TCL_ERROR;
	}
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), (Tk_Window)clientData);
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), clientData);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	return Tk_Grab(interp, tkwin, 1);
    }

    /*
262
263
264
265
266
267
268
269

270
271
272
273
274
275

276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
272
273
274
275
276
277
278

279
280
281
282
283
284

285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377







-
+





-
+








-
+













-
+
















-
+















-
+
















-
+











-
+







	/* [grab current ?window?] */
	if (objc > 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "current ?window?");
	    return TCL_ERROR;
	}
	if (objc == 3) {
	    tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
		    (Tk_Window)clientData);
		    clientData);
	    if (tkwin == NULL) {
		return TCL_ERROR;
	    }
	    dispPtr = ((TkWindow *) tkwin)->dispPtr;
	    if (dispPtr->eventualGrabWinPtr != NULL) {
		Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window)
		Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window)
			dispPtr->eventualGrabWinPtr));
	    }
	} else {
	    Tcl_Obj *resultObj = Tcl_NewObj();

	    for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
		    dispPtr = dispPtr->nextPtr) {
		if (dispPtr->eventualGrabWinPtr != NULL) {
		    Tcl_ListObjAppendElement(NULL, resultObj, Tk_NewWindowObj(
		    Tcl_ListObjAppendElement(NULL, resultObj, TkNewWindowObj(
			    (Tk_Window) dispPtr->eventualGrabWinPtr));
		}
	    }
	    Tcl_SetObjResult(interp, resultObj);
	}
	return TCL_OK;

    case GRABCMD_RELEASE:
	/* [grab release window] */
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "release window");
	    return TCL_ERROR;
	}
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), (Tk_Window)clientData);
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), clientData);
	if (tkwin == NULL) {
	    Tcl_ResetResult(interp);
	} else {
	    Tk_Ungrab(tkwin);
	}
	break;

    case GRABCMD_SET:
	/* [grab set ?-global? window] */
	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 1, objv, "set ?-global? window");
	    return TCL_ERROR;
	}
	if (objc == 3) {
	    globalGrab = 0;
	    tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
		    (Tk_Window)clientData);
		    clientData);
	} else {
	    globalGrab = 1;

	    /*
	     * We could just test the argument by hand instead of using
	     * Tcl_GetIndexFromObj; the benefit of using the function is that
	     * it sets up the error message for us, so we are certain to be
	     * consistant with the rest of Tcl.
	     */

	    if (Tcl_GetIndexFromObj(interp, objv[2], flagStrings, "option",
		    0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }
	    tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[3]),
		    (Tk_Window)clientData);
		    clientData);
	}
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	return Tk_Grab(interp, tkwin, globalGrab);

    case GRABCMD_STATUS: {
	/* [grab status window] */
	TkWindow *winPtr;
	const char *statusString;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "status window");
	    return TCL_ERROR;
	}
	winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
		(Tk_Window)clientData);
		clientData);
	if (winPtr == NULL) {
	    return TCL_ERROR;
	}
	dispPtr = winPtr->dispPtr;
	if (dispPtr->eventualGrabWinPtr != winPtr) {
	    statusString = "none";
	} else if (dispPtr->grabFlags & GRAB_GLOBAL) {
	    statusString = "global";
	} else {
	    statusString = "local";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(statusString, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(statusString, -1));
	break;
    }
    }

    return TCL_OK;
}

412
413
414
415
416
417
418

419





420
421
422
423
424
425
426
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441







+
-
+
+
+
+
+







	if (dispPtr->eventualGrabWinPtr->mainPtr != winPtr->mainPtr) {
	    goto alreadyGrabbed;
	}
	Tk_Ungrab((Tk_Window) dispPtr->eventualGrabWinPtr);
    }

    Tk_MakeWindowExist(tkwin);
#ifndef MAC_OSX_TK
    if (!grabGlobal) {
    if (!grabGlobal)
#else
    if (0)
#endif /* MAC_OSX_TK */
    {
	Window dummy1, dummy2;
	int dummy3, dummy4, dummy5, dummy6;
	unsigned int state;

	/*
	 * Local grab. However, if any mouse buttons are down, turn it into a
	 * global grab temporarily, until the last button goes up. This does
519
520
521
522
523
524
525
526

527
528
529
530
531

532
533
534
535

536
537
538
539

540
541
542
543
544
545
546
534
535
536
537
538
539
540

541
542
543
544
545

546
547
548
549

550
551
552
553

554
555
556
557
558
559
560
561







-
+




-
+



-
+



-
+







    }
    QueueGrabWindowChange(dispPtr, winPtr);
    return TCL_OK;

  grabError:
    if (grabResult == GrabNotViewable) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"grab failed: window not viewable", TCL_INDEX_NONE));
		"grab failed: window not viewable", -1));
	Tcl_SetErrorCode(interp, "TK", "GRAB", "UNVIEWABLE", NULL);
    } else if (grabResult == AlreadyGrabbed) {
    alreadyGrabbed:
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"grab failed: another application has grab", TCL_INDEX_NONE));
		"grab failed: another application has grab", -1));
	Tcl_SetErrorCode(interp, "TK", "GRAB", "GRABBED", NULL);
    } else if (grabResult == GrabFrozen) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"grab failed: keyboard or pointer frozen", TCL_INDEX_NONE));
		"grab failed: keyboard or pointer frozen", -1));
	Tcl_SetErrorCode(interp, "TK", "GRAB", "FROZEN", NULL);
    } else if (grabResult == GrabInvalidTime) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"grab failed: invalid time", TCL_INDEX_NONE));
		"grab failed: invalid time", -1));
	Tcl_SetErrorCode(interp, "TK", "GRAB", "BAD_TIME", NULL);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"grab failed for unknown reason (code %d)", grabResult));
	Tcl_SetErrorCode(interp, "TK", "GRAB", "UNKNOWN", NULL);
    }
    return TCL_ERROR;
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664







-
+







 *	to its current window.
 *
 *----------------------------------------------------------------------
 */

static void
ReleaseButtonGrab(
    TkDisplay *dispPtr)/* Display whose button grab is to be
    register TkDisplay *dispPtr)/* Display whose button grab is to be
				 * released. */
{
    unsigned int serial;

    if (dispPtr->buttonWinPtr != NULL) {
	if (dispPtr->buttonWinPtr != dispPtr->serverWinPtr) {
	    MovePointer2(dispPtr->buttonWinPtr, dispPtr->serverWinPtr,
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

693
694
695
696

697
698
699
700
701
702
703
679
680
681
682
683
684
685



686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702

703
704
705
706

707
708
709
710
711
712
713
714







-
-
-











-






-
+



-
+







 *----------------------------------------------------------------------
 *
 * TkPointerEvent --
 *
 *	This function is called for each pointer-related event, before the
 *	event has been processed. It does various things to make grabs work
 *	correctly.
 *	Also, this function takes care of warping the mouse pointer with
 *	respect to a given window, both when there is a grab in effect and
 *	when there is none.
 *
 * Results:
 *	If the return value is 1 it means the event should be processed (event
 *	handlers should be invoked). If the return value is 0 it means the
 *	event should be ignored in order to make grabs work correctly. In some
 *	cases this function modifies the event.
 *
 * Side effects:
 *	Grab state information may be updated. New events may also be pushed
 *	back onto the event queue to replace or augment the one passed in
 *	here.
 *	The mouse pointer may be moved.
 *
 *----------------------------------------------------------------------
 */

int
TkPointerEvent(
    XEvent *eventPtr,	/* Pointer to the event. */
    register XEvent *eventPtr,	/* Pointer to the event. */
    TkWindow *winPtr)		/* Tk's information for window where event was
				 * reported. */
{
    TkWindow *winPtr2;
    register TkWindow *winPtr2;
    TkDisplay *dispPtr = winPtr->dispPtr;
    unsigned int serial;
    int outsideGrabTree = 0;
    int ancestorOfGrab = 0;
    int appGrabbed = 0;		/* Non-zero means event is being reported to
				 * an application that is affected by the
				 * grab. */
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
786
787
788
789
790
791
792










793
794
795
796




797
798
799
800
801
802
803







-
-
-
-
-
-
-
-
-
-




-
-
-
-







		    && (winPtr != dispPtr->buttonWinPtr)) {
		return 0;
	    }
	}
	return 1;
    }

    if ((eventPtr->type == MotionNotify) && !appGrabbed) {

        /*
         * Warp the mouse pointer with respect to window dispPtr->warpWindow
         * if such a window was set in HandleEventGenerate.
         */

        TkDoWarpWrtWin(dispPtr);
    }

    if (!appGrabbed) {
	return 1;
    }

    /*
     * From this point on, there is a grab in effect.
     */

    if (eventPtr->type == MotionNotify) {
	/*
	 * When grabs are active, X reports motion events relative to the
	 * window under the pointer. Instead, it should report the events
	 * relative to the window the button went down in, if there is a
	 * button down. Otherwise, if the pointer window is outside the
	 * subtree of the grab window, the events should be reported relative
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
812
813
814
815
816
817
818







819
820
821
822
823
824
825







-
-
-
-
-
-
-







	    winPtr2 = dispPtr->grabWinPtr;
	}
	if (winPtr2 != winPtr) {
	    TkChangeEventWindow(eventPtr, winPtr2);
	    Tk_QueueWindowEvent(eventPtr, TCL_QUEUE_HEAD);
	    return 0;
	}

        /*
         * Warp the mouse pointer with respect to window dispPtr->warpWindow
         * if such a window was set in HandleEventGenerate.
         */

        TkDoWarpWrtWin(dispPtr);
	return 1;
    }

    /*
     * Process ButtonPress and ButtonRelease events:
     * 1. Keep track of whether a button is down and what window it went down
     *    in.
892
893
894
895
896
897
898
899
900
901


902
903
904
905
906
907
908
882
883
884
885
886
887
888



889
890
891
892
893
894
895
896
897







-
-
-
+
+







			}
		    }
		}
		dispPtr->buttonWinPtr = winPtr;
		return 1;
	    }
	} else {
	    if (eventPtr->xbutton.button != AnyButton &&
		    ((eventPtr->xbutton.state & ALL_BUTTONS)
		    == Tk_GetButtonMask(eventPtr->xbutton.button))) {
	    if ((eventPtr->xbutton.state & ALL_BUTTONS)
		    == buttonStates[eventPtr->xbutton.button - Button1]) {
		ReleaseButtonGrab(dispPtr);			/* Note 4. */
	    }
	}
	if (winPtr2 != winPtr) {
	    TkChangeEventWindow(eventPtr, winPtr2);
	    Tk_QueueWindowEvent(eventPtr, TCL_QUEUE_HEAD);
	    return 0;						/* Note 3. */
929
930
931
932
933
934
935
936

937
938
939
940
941
942
943

944
945
946
947
948
949
950
918
919
920
921
922
923
924

925
926
927
928
929
930
931

932
933
934
935
936
937
938
939







-
+






-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkChangeEventWindow(
    XEvent *eventPtr,	/* Event to retarget. Must have type
    register XEvent *eventPtr,	/* Event to retarget. Must have type
				 * ButtonPress, ButtonRelease, KeyPress,
				 * KeyRelease, MotionNotify, EnterNotify, or
				 * LeaveNotify. */
    TkWindow *winPtr)		/* New target window for event. */
{
    int x, y, sameScreen, bd;
    TkWindow *childPtr;
    register TkWindow *childPtr;

    eventPtr->xmotion.window = Tk_WindowId(winPtr);
    if (eventPtr->xmotion.root ==
	    RootWindow(winPtr->display, winPtr->screenNum)) {
	Tk_GetRootCoords((Tk_Window) winPtr, &x, &y);
	eventPtr->xmotion.x = eventPtr->xmotion.x_root - x;
	eventPtr->xmotion.y = eventPtr->xmotion.y_root - y;
1017
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020







-
+







				 * means don't generate leave events. */
    int enterType,		/* Type of events to generate for windows
				 * being entered (EnterNotify or FocusIn). 0
				 * means don't generate enter events. */
    Tcl_QueuePosition position)	/* Position at which events are added to the
				 * system event queue. */
{
    TkWindow *winPtr;
    register TkWindow *winPtr;
    int upLevels, downLevels, i, j, focus;

    /*
     * There are four possible cases to deal with:
     *
     * 1. SourcePtr and destPtr are the same. There's nothing to do in this
     *    case.
1210
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213







-
+







 *	code.
 *
 *----------------------------------------------------------------------
 */

void
TkGrabDeadWindow(
    TkWindow *winPtr)	/* Window that is in the process of being
    register TkWindow *winPtr)	/* Window that is in the process of being
				 * deleted. */
{
    TkDisplay *dispPtr = winPtr->dispPtr;

    if (dispPtr->eventualGrabWinPtr == winPtr) {
	/*
	 * Grab window was deleted. Release the grab.
1264
1265
1266
1267
1268
1269
1270
1271

1272
1273
1274
1275
1276
1277
1278
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267







-
+







EatGrabEvents(
    TkDisplay *dispPtr,		/* Display from which to consume events. */
    unsigned int serial)	/* Only discard events that have a serial
				 * number at least this great. */
{
    Tk_RestrictProc *prevProc;
    GrabInfo info;
    void *prevArg;
    ClientData prevArg;

    info.display = dispPtr->display;
    info.serial = serial;
    TkpSync(info.display);
    prevProc = Tk_RestrictEvents(GrabRestrictProc, &info, &prevArg);
    while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {
	/* EMPTY */
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1286
1287
1288
1289
1290
1291
1292

1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303







-
+


-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tk_RestrictAction
GrabRestrictProc(
    void *arg,
    ClientData arg,
    XEvent *eventPtr)
{
    GrabInfo *info = (GrabInfo *)arg;
    GrabInfo *info = arg;
    int mode, diff;

    /*
     * The diff caculation is trickier than it may seem. Don't forget that
     * serial numbers can wrap around, so can't compare the two serial numbers
     * directly.
     */
1358
1359
1360
1361
1362
1363
1364
1365

1366
1367
1368
1369
1370
1371
1372
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1361







-
+







    TkDisplay *dispPtr,		/* Display on which to change the grab
				 * window. */
    TkWindow *grabWinPtr)	/* Window that is to become the new grab
				 * window (may be NULL). */
{
    NewGrabWinEvent *grabEvPtr;

    grabEvPtr = (NewGrabWinEvent *)ckalloc(sizeof(NewGrabWinEvent));
    grabEvPtr = ckalloc(sizeof(NewGrabWinEvent));
    grabEvPtr->header.proc = GrabWinEventProc;
    grabEvPtr->dispPtr = dispPtr;
    if (grabWinPtr == NULL) {
	grabEvPtr->grabWindow = None;
    } else {
	grabEvPtr->grabWindow = grabWinPtr->window;
    }
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1382
1383
1384
1385
1386
1387
1388

1389
1390
1391
1392
1393
1394
1395
1396







-
+







 *
 *----------------------------------------------------------------------
 */

static int
GrabWinEventProc(
    Tcl_Event *evPtr,		/* Event of type NewGrabWinEvent. */
    TCL_UNUSED(int))			/* Flags argument to Tcl_DoOneEvent: indicates
    int flags)			/* Flags argument to Tk_DoOneEvent: indicates
				 * what kinds of events are being processed
				 * right now. */
{
    NewGrabWinEvent *grabEvPtr = (NewGrabWinEvent *) evPtr;

    grabEvPtr->dispPtr->grabWinPtr = (TkWindow *) Tk_IdToWindow(
	    grabEvPtr->dispPtr->display, grabEvPtr->grabWindow);
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1441







-
+







    TkWindow *winPtr1,		/* First window. May be NULL. */
    TkWindow *winPtr2,		/* Second window. May be NULL. */
    int *countPtr1,		/* Store nesting level of winPtr1 within
				 * common ancestor here. */
    int *countPtr2)		/* Store nesting level of winPtr2 within
				 * common ancestor here. */
{
    TkWindow *winPtr;
    register TkWindow *winPtr;
    TkWindow *ancestorPtr;
    int count1, count2, i;

    /*
     * Mark winPtr1 and all of its ancestors with a special flag bit.
     */

Changes to generic/tkGrid.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkGrid.c --
 *
 *	Grid based geometry manager.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103


104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133

134
135
136
137

138
139
140
141
142

143
144

145
146
147

148
149
150
151

152
153
154
155
156
157
158
159
160

161
162
163

164
165
166
167
168




169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193

194
195
196
197
198
199
200
201
202

203
204

205
206
207
208
209
210
211
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101


102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132

133
134
135
136

137
138
139
140
141

142
143

144
145
146

147
148
149
150

151
152
153
154
155
156
157
158
159

160
161
162

163
164




165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192

193
194
195
196
197
198
199
200
201

202
203

204
205
206
207
208
209
210
211







-
+













-
+


















-
-
+
+




-
+


















-
+





-
+



-
+




-
+

-
+


-
+



-
+








-
+


-
+

-
-
-
-
+
+
+
+


-
+
















-
+




-
+








-
+

-
+







/*
 * Default value for 'grid anchor'.
 */

#define GRID_DEFAULT_ANCHOR TK_ANCHOR_NW

/*
 * Structure to hold information for grid containers. A slot is either a row or
 * Structure to hold information for grid masters. A slot is either a row or
 * column.
 */

typedef struct SlotInfo {
    int minSize;		/* The minimum size of this slot (in pixels).
				 * It is set via the rowconfigure or
				 * columnconfigure commands. */
    int weight;			/* The resize weight of this slot. (0) means
				 * this slot doesn't resize. Extra space in
				 * the layout is given distributed among slots
				 * inproportion to their weights. */
    int pad;			/* Extra padding, in pixels, required for this
				 * slot. This amount is "added" to the largest
				 * content in the slot. */
				 * slave in the slot. */
    Tk_Uid uniform;		/* Value of -uniform option. It is used to
				 * group slots that should have the same
				 * size. */
    int offset;			/* This is a cached value used for
				 * introspection. It is the pixel offset of
				 * the right or bottom edge of this slot from
				 * the beginning of the layout. */
    int temp;			/* This is a temporary value used for
				 * calculating adjusted weights when shrinking
				 * the layout below its nominal size. */
} SlotInfo;

/*
 * Structure to hold information during layout calculations. There is one of
 * these for each slot, an array for each of the rows or columns.
 */

typedef struct GridLayout {
    struct Gridder *binNextPtr;	/* The next content window in this bin. Each bin
    				 * contains a list of all content whose spans
    struct Gridder *binNextPtr;	/* The next slave window in this bin. Each bin
    				 * contains a list of all slaves whose spans
    				 * are >1 and whose right edges fall in this
    				 * slot. */
    int minSize;		/* Minimum size needed for this slot, in
    				 * pixels. This is the space required to hold
    				 * any content contained entirely in this slot,
    				 * any slaves contained entirely in this slot,
    				 * adjusted for any slot constrants, such as
    				 * size or padding. */
    int pad;			/* Padding needed for this slot */
    int weight;			/* Slot weight, controls resizing. */
    Tk_Uid uniform;		/* Value of -uniform option. It is used to
				 * group slots that should have the same
				 * size. */
    int minOffset;		/* The minimum offset, in pixels, from the
    				 * beginning of the layout to the bottom/right
    				 * edge of the slot calculated from top/left
    				 * to bottom/right. */
    int maxOffset;		/* The maximum offset, in pixels, from the
    				 * beginning of the layout to the bottom/right
    				 * edge of the slot calculated from
    				 * bottom/right to top/left. */
} GridLayout;

/*
 * Keep one of these for each geometry container.
 * Keep one of these for each geometry master.
 */

typedef struct {
    SlotInfo *columnPtr;	/* Pointer to array of column constraints. */
    SlotInfo *rowPtr;		/* Pointer to array of row constraints. */
    int columnEnd;		/* The last column occupied by any content. */
    int columnEnd;		/* The last column occupied by any slave. */
    int columnMax;		/* The number of columns with constraints. */
    int columnSpace;		/* The number of slots currently allocated for
    				 * column constraints. */
    int rowEnd;			/* The last row occupied by any content. */
    int rowEnd;			/* The last row occupied by any slave. */
    int rowMax;			/* The number of rows with constraints. */
    int rowSpace;		/* The number of slots currently allocated for
    				 * row constraints. */
    int startX;			/* Pixel offset of this layout within its
    				 * container. */
    				 * master. */
    int startY;			/* Pixel offset of this layout within its
    				 * container. */
    				 * master. */
    Tk_Anchor anchor;		/* Value of anchor option: specifies where a
				 * grid without weight should be placed. */
} GridContainer;
} GridMaster;

/*
 * For each window that the grid cares about (either because the window is
 * managed by the grid or because the window has content that are managed by
 * managed by the grid or because the window has slaves that are managed by
 * the grid), there is a structure of the following type:
 */

typedef struct Gridder {
    Tk_Window tkwin;		/* Tk token for window. NULL means that the
				 * window has been deleted, but the gridder
				 * hasn't had a chance to clean up yet because
				 * the structure is still in use. */
    struct Gridder *containerPtr;	/* Container window within which this window is
    struct Gridder *masterPtr;	/* Master window within which this window is
				 * managed (NULL means this window isn't
				 * managed by the gridder). */
    struct Gridder *nextPtr;	/* Next window managed within same container.
    struct Gridder *nextPtr;	/* Next window managed within same master.
				 * List order doesn't matter. */
    struct Gridder *contentPtr;	/* First in list of content managed inside this
				 * window (NULL means no grid content). */
    GridContainer *containerDataPtr;	/* Additional data for geometry container. */
    Tcl_Obj *in;                /* Store container name when removed. */
    struct Gridder *slavePtr;	/* First in list of slaves managed inside this
				 * window (NULL means no grid slaves). */
    GridMaster *masterDataPtr;	/* Additional data for geometry master. */
    Tcl_Obj *in;                /* Store master name when removed. */
    int column, row;		/* Location in the grid (starting from
				 * zero). */
    int numCols, numRows;	/* Number of columns or rows this content spans.
    int numCols, numRows;	/* Number of columns or rows this slave spans.
				 * Should be at least 1. */
    int padX, padY;		/* Total additional pixels to leave around the
				 * window. Some is of this space is on each
				 * side. This is space *outside* the window:
				 * we'll allocate extra space in frame but
				 * won't enlarge window). */
    int padLeft, padTop;	/* The part of padX or padY to use on the left
				 * or top of the widget, respectively. By
				 * default, this is half of padX or padY. */
    int iPadX, iPadY;		/* Total extra pixels to allocate inside the
				 * window (half this amount will appear on
				 * each side). */
    int sticky;			/* which sides of its cavity this window
				 * sticks to. See below for definitions */
    int doubleBw;		/* Twice the window's last known border width.
				 * If this changes, the window must be
				 * re-arranged within its container. */
				 * re-arranged within its master. */
    int *abortPtr;		/* If non-NULL, it means that there is a
				 * nested call to ArrangeGrid already working
				 * on this window. *abortPtr may be set to 1
				 * to abort that nested call. This happens,
				 * for example, if tkwin or any of its content
				 * for example, if tkwin or any of its slaves
				 * is deleted. */
    int flags;			/* Miscellaneous flags; see below for
				 * definitions. */

    /*
     * These fields are used temporarily for layout calculations only.
     */

    struct Gridder *binNextPtr;	/* Link to next span>1 content in this bin. */
    struct Gridder *binNextPtr;	/* Link to next span>1 slave in this bin. */
    int size;			/* Nominal size (width or height) in pixels of
    				 * the content. This includes the padding. */
    				 * the slave. This includes the padding. */
} Gridder;

/*
 * Flag values for "sticky"ness. The 16 combinations subsume the packer's
 * notion of anchor and fill.
 *
 * STICK_NORTH			This window sticks to the top of its cavity.
231
232
233
234
235
236
237
238

239
240
241

242
243
244
245



246
247
248
249
250

251
252
253
254
255
256

257
258

259
260
261


262
263
264
265



266
267
268

269
270

271
272

273
274
275

276
277

278
279
280

281
282
283

284
285
286
287
288
289




290
291

292
293
294
295
296




297
298
299
300

301
302

303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
231
232
233
234
235
236
237

238
239
240

241
242



243
244
245
246
247
248
249

250
251
252
253
254
255

256
257

258
259


260
261
262



263
264
265
266
267

268
269

270
271

272
273
274

275
276

277
278
279

280
281
282

283
284
285




286
287
288
289
290

291
292




293
294
295
296
297
298
299

300
301

302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318







-
+


-
+

-
-
-
+
+
+




-
+





-
+

-
+

-
-
+
+

-
-
-
+
+
+


-
+

-
+

-
+


-
+

-
+


-
+


-
+


-
-
-
-
+
+
+
+

-
+

-
-
-
-
+
+
+
+



-
+

-
+








-
+







    int minSize;
} UniformGroup;

/*
 * Flag values for Grid structures:
 *
 * REQUESTED_RELAYOUT		1 means a Tcl_DoWhenIdle request has already
 *				been made to re-arrange all the content of this
 *				been made to re-arrange all the slaves of this
 *				window.
 * DONT_PROPAGATE		1 means don't set this window's requested
 *				size. 0 means if this window is a container then
 *				size. 0 means if this window is a master then
 *				Tk will set its requested size to fit the
 *				needs of its content.
 * ALLOCED_CONTAINER		1 means that Grid has allocated itself as
 *				geometry container for this window.
 *				needs of its slaves.
 * ALLOCED_MASTER               1 means that Grid has allocated itself as
 *                              geometry master for this window.
 */

#define REQUESTED_RELAYOUT	1
#define DONT_PROPAGATE		2
#define ALLOCED_CONTAINER	4
#define ALLOCED_MASTER		4

/*
 * Prototypes for procedures used only in this file:
 */

static void		AdjustForSticky(Gridder *contentPtr, int *xPtr,
static void		AdjustForSticky(Gridder *slavePtr, int *xPtr,
			    int *yPtr, int *widthPtr, int *heightPtr);
static int		AdjustOffsets(int width, Tcl_Size elements,
static int		AdjustOffsets(int width, int elements,
			    SlotInfo *slotPtr);
static void		ArrangeGrid(void *clientData);
static int		CheckSlotData(Gridder *containerPtr, Tcl_Size slot,
static void		ArrangeGrid(ClientData clientData);
static int		CheckSlotData(Gridder *masterPtr, int slot,
			    int slotType, int checkOnly);
static int		ConfigureContent(Tcl_Interp *interp, Tk_Window tkwin,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static Tcl_FreeProc	DestroyGrid;
static int		ConfigureSlaves(Tcl_Interp *interp, Tk_Window tkwin,
			    int objc, Tcl_Obj *const objv[]);
static void		DestroyGrid(void *memPtr);
static Gridder *	GetGrid(Tk_Window tkwin);
static int		GridAnchorCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		GridBboxCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		GridForgetRemoveCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridInfoCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		GridLocationCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridPropagateCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridRowColumnConfigureCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridSizeCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static int		GridContentCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static void		GridStructureProc(void *clientData,
			    int objc, Tcl_Obj *const objv[]);
static int		GridSlavesCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static void		GridStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		GridLostContentProc(void *clientData,
static void		GridLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		GridReqProc(void *clientData, Tk_Window tkwin);
static void		InitContainerData(Gridder *containerPtr);
static Tcl_Obj *	NewPairObj(Tcl_WideInt, Tcl_WideInt);
static Tcl_Obj *	NewQuadObj(Tcl_WideInt, Tcl_WideInt, Tcl_WideInt, Tcl_WideInt);
static void		GridReqProc(ClientData clientData, Tk_Window tkwin);
static void		InitMasterData(Gridder *masterPtr);
static Tcl_Obj *	NewPairObj(int, int);
static Tcl_Obj *	NewQuadObj(int, int, int, int);
static int		ResolveConstraints(Gridder *gridPtr, int rowOrColumn,
			    int maxOffset);
static void		SetGridSize(Gridder *gridPtr);
static int		SetContentColumn(Tcl_Interp *interp, Gridder *contentPtr,
static int		SetSlaveColumn(Tcl_Interp *interp, Gridder *slavePtr,
			    int column, int numCols);
static int		SetContentRow(Tcl_Interp *interp, Gridder *contentPtr,
static int		SetSlaveRow(Tcl_Interp *interp, Gridder *slavePtr,
			    int row, int numRows);
static Tcl_Obj *	StickyToObj(int flags);
static int		StringToSticky(const char *string);
static void		Unlink(Gridder *gridPtr);

static const Tk_GeomMgr gridMgrType = {
    "grid",			/* name */
    GridReqProc,		/* requestProc */
    GridLostContentProc,		/* lostContentProc */
    GridLostSlaveProc,		/* lostSlaveProc */
};

/*
 *----------------------------------------------------------------------
 *
 * Tk_GridCmd --
 *
326
327
328
329
330
331
332
333

334
335
336
337
338

339
340
341

342
343
344
345
346
347

348
349
350
351
352


353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378


379
380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410





411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
326
327
328
329
330
331
332

333
334
335
336
337

338
339
340

341






342
343
344
345


346
347
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363










364
365
366
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384
385
386
387


388
389
390
391





392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412







-
+




-
+


-
+
-
-
-
-
-
-
+



-
-
+
+








-
+







-
-
-
-
-
-
-
-
-
-
+
+









-
+












-
-
+



-
-
-
-
-
+
+
+
+
+








-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GridObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    static const char *const optionStrings[] = {
	"anchor", "bbox", "columnconfigure", "configure",
	"content", "forget", "info", "location", "propagate",
	"forget", "info", "location", "propagate", "remove",
	"remove", "rowconfigure", "size", "slaves", NULL
    };
    static const char *const optionStringsNoDep[] = {
	"anchor", "bbox", "columnconfigure", "configure",
	"content", "forget", "info", "location", "propagate",
	"remove", "rowconfigure", "size", NULL
	"rowconfigure", "size",	"slaves", NULL
    };
    enum options {
	GRID_ANCHOR, GRID_BBOX, GRID_COLUMNCONFIGURE, GRID_CONFIGURE,
	GRID_CONTENT, GRID_FORGET, GRID_INFO, GRID_LOCATION, GRID_PROPAGATE,
	GRID_REMOVE, GRID_ROWCONFIGURE, GRID_SIZE, GRID_SLAVES
	GRID_FORGET, GRID_INFO, GRID_LOCATION, GRID_PROPAGATE, GRID_REMOVE,
	GRID_ROWCONFIGURE, GRID_SIZE, GRID_SLAVES
    };
    int index;

    if (objc >= 2) {
	const char *argv1 = Tcl_GetString(objv[1]);

	if ((argv1[0] == '.') || (argv1[0] == REL_SKIP) ||
    		(argv1[0] == REL_VERT)) {
	    return ConfigureContent(interp, tkwin, objc-1, objv+1);
	    return ConfigureSlaves(interp, tkwin, objc-1, objv+1);
	}
    }
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(NULL, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	/*
	 * Call it again without the deprecated ones to get a proper error
	 * message. This works well since there can't be any ambiguity between
	 * deprecated and new options.
	 */

	Tcl_GetIndexFromObjStruct(interp, objv[1], optionStringsNoDep,
		sizeof(char *), "option", 0, &index);
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum options) index) {
    case GRID_ANCHOR:
	return GridAnchorCommand(tkwin, interp, objc, objv);
    case GRID_BBOX:
	return GridBboxCommand(tkwin, interp, objc, objv);
    case GRID_CONFIGURE:
	return ConfigureContent(interp, tkwin, objc-2, objv+2);
	return ConfigureSlaves(interp, tkwin, objc-2, objv+2);
    case GRID_FORGET:
    case GRID_REMOVE:
	return GridForgetRemoveCommand(tkwin, interp, objc, objv);
    case GRID_INFO:
	return GridInfoCommand(tkwin, interp, objc, objv);
    case GRID_LOCATION:
	return GridLocationCommand(tkwin, interp, objc, objv);
    case GRID_PROPAGATE:
	return GridPropagateCommand(tkwin, interp, objc, objv);
    case GRID_SIZE:
	return GridSizeCommand(tkwin, interp, objc, objv);
    case GRID_SLAVES:
    case GRID_CONTENT:
	return GridContentCommand(tkwin, interp, objc, objv);
	return GridSlavesCommand(tkwin, interp, objc, objv);

    /*
     * Sample argument combinations:
     *  grid columnconfigure <container> <index> -option
     *  grid columnconfigure <container> <index> -option value -option value
     *  grid rowconfigure <container> <index>
     *  grid rowconfigure <container> <index> -option
     *  grid rowconfigure <container> <index> -option value -option value.
     *  grid columnconfigure <master> <index> -option
     *  grid columnconfigure <master> <index> -option value -option value
     *  grid rowconfigure <master> <index>
     *  grid rowconfigure <master> <index> -option
     *  grid rowconfigure <master> <index> -option value -option value.
     */

    case GRID_COLUMNCONFIGURE:
    case GRID_ROWCONFIGURE:
	return GridRowColumnConfigureCommand(tkwin, interp, objc, objv);
    }

    /* This should not happen */
    Tcl_SetObjResult(interp, Tcl_NewStringObj("internal error in grid", TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj("internal error in grid", -1));
    Tcl_SetErrorCode(interp, "TK", "API_ABUSE", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
438
439
440
441
442
443
444
445

446
447
448
449
450



451
452
453
454
455
456
457
458

459
460
461

462
463
464

465
466
467
468
469
470
471
472


473
474
475
476
477
478
479
480
481
482
483
484


485
486
487
488



489
490
491
492
493
494
495
424
425
426
427
428
429
430

431
432
433



434
435
436
437
438
439
440
441
442
443

444
445
446

447
448
449

450
451
452
453
454
455
456


457
458
459
460
461
462
463
464
465
466
467
468


469
470
471



472
473
474
475
476
477
478
479
480
481







-
+


-
-
-
+
+
+







-
+


-
+


-
+






-
-
+
+










-
-
+
+

-
-
-
+
+
+







 *----------------------------------------------------------------------
 */

static int
GridAnchorCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;
    GridContainer *gridPtr;
    Tk_Window master;
    Gridder *masterPtr;
    GridMaster *gridPtr;
    Tk_Anchor old;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?anchor?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    containerPtr = GetGrid(container);
    masterPtr = GetGrid(master);

    if (objc == 3) {
	gridPtr = containerPtr->containerDataPtr;
	gridPtr = masterPtr->masterDataPtr;
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		Tk_NameOfAnchor(gridPtr?gridPtr->anchor:GRID_DEFAULT_ANCHOR),
		-1));
	return TCL_OK;
    }

    InitContainerData(containerPtr);
    gridPtr = containerPtr->containerDataPtr;
    InitMasterData(masterPtr);
    gridPtr = masterPtr->masterDataPtr;
    old = gridPtr->anchor;
    if (Tk_GetAnchorFromObj(interp, objv[3], &gridPtr->anchor) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Only request a relayout if the anchor changes.
     */

    if (old != gridPtr->anchor) {
	if (containerPtr->abortPtr != NULL) {
	    *containerPtr->abortPtr = 1;
	if (masterPtr->abortPtr != NULL) {
	    *masterPtr->abortPtr = 1;
	}
	if (!(containerPtr->flags & REQUESTED_RELAYOUT)) {
	    containerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
	if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
507
508
509
510
511
512
513
514

515
516
517
518
519



520
521
522
523
524
525
526
527

528
529
530
531

532
533
534

535
536
537
538
539
540
541
493
494
495
496
497
498
499

500
501
502



503
504
505
506
507
508
509
510
511
512

513
514
515
516

517
518
519

520
521
522
523
524
525
526
527







-
+


-
-
-
+
+
+







-
+



-
+


-
+







 *----------------------------------------------------------------------
 */

static int
GridBboxCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;		/* container grid record */
    GridContainer *gridPtr;	/* pointer to grid data */
    Tk_Window master;
    Gridder *masterPtr;		/* master grid record */
    GridMaster *gridPtr;	/* pointer to grid data */
    int row, column;		/* origin for bounding box */
    int row2, column2;		/* end of bounding box */
    int endX, endY;		/* last column/row in the layout */
    int x=0, y=0;		/* starting pixels for this bounding box */
    int width, height;		/* size of the bounding box */

    if (objc!=3 && objc != 5 && objc != 7) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?column row ?column row??");
	Tcl_WrongNumArgs(interp, 2, objv, "master ?column row ?column row??");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    containerPtr = GetGrid(container);
    masterPtr = GetGrid(master);

    if (objc >= 5) {
	if (Tcl_GetIntFromObj(interp, objv[3], &column) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp, objv[4], &row) != TCL_OK) {
	    return TCL_ERROR;
549
550
551
552
553
554
555
556

557
558
559
560
561
562

563
564
565
566
567
568
569
535
536
537
538
539
540
541

542
543
544
545
546
547

548
549
550
551
552
553
554
555







-
+





-
+







	    return TCL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp, objv[6], &row2) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    gridPtr = containerPtr->containerDataPtr;
    gridPtr = masterPtr->masterDataPtr;
    if (gridPtr == NULL) {
	Tcl_SetObjResult(interp, NewQuadObj(0, 0, 0, 0));
	return TCL_OK;
    }

    SetGridSize(containerPtr);
    SetGridSize(masterPtr);
    endX = MAX(gridPtr->columnEnd, gridPtr->columnMax);
    endY = MAX(gridPtr->rowEnd, gridPtr->rowMax);

    if ((endX == 0) || (endY == 0)) {
	Tcl_SetObjResult(interp, NewQuadObj(0, 0, 0, 0));
	return TCL_OK;
    }
637
638
639
640
641
642
643
644

645
646
647
648
649



650
651
652
653
654

655
656
657
658
659


660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677













678
679
680
681



682
683
684


685
686
687
688


689
690
691
692
693



694
695
696
697
698




699
700
701
702
703
704




705
706
707


708
709
710
711
712
713
714
623
624
625
626
627
628
629

630
631
632



633
634
635
636
637
638
639

640
641
642
643


644
645
646
647
648
649
650













651
652
653
654
655
656
657
658
659
660
661
662
663
664



665
666
667
668


669
670
671
672


673
674
675
676



677
678
679
680




681
682
683
684
685
686




687
688
689
690
691


692
693
694
695
696
697
698
699
700







-
+


-
-
-
+
+
+




-
+



-
-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+

-
-
+
+


-
-
+
+


-
-
-
+
+
+

-
-
-
-
+
+
+
+


-
-
-
-
+
+
+
+

-
-
+
+







 *----------------------------------------------------------------------
 */

static int
GridForgetRemoveCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window content;
    Gridder *contentPtr;
    Tcl_Size i;
    Tk_Window slave;
    Gridder *slavePtr;
    int i;
    const char *string = Tcl_GetString(objv[1]);
    char c = string[0];

    for (i = 2; i < objc; i++) {
	if (TkGetWindowFromObj(interp, tkwin, objv[i], &content) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[i], &slave) != TCL_OK) {
	    return TCL_ERROR;
	}

	contentPtr = GetGrid(content);
	if (contentPtr->containerPtr != NULL) {
	slavePtr = GetGrid(slave);
	if (slavePtr->masterPtr != NULL) {
	    /*
	     * For "forget", reset all the settings to their defaults
	     */

	    if (c == 'f') {
		contentPtr->column = -1;
		contentPtr->row = -1;
		contentPtr->numCols = 1;
		contentPtr->numRows = 1;
		contentPtr->padX = 0;
		contentPtr->padY = 0;
		contentPtr->padLeft = 0;
		contentPtr->padTop = 0;
		contentPtr->iPadX = 0;
		contentPtr->iPadY = 0;
		if (contentPtr->in != NULL) {
		    Tcl_DecrRefCount(contentPtr->in);
		    contentPtr->in = NULL;
		slavePtr->column = -1;
		slavePtr->row = -1;
		slavePtr->numCols = 1;
		slavePtr->numRows = 1;
		slavePtr->padX = 0;
		slavePtr->padY = 0;
		slavePtr->padLeft = 0;
		slavePtr->padTop = 0;
		slavePtr->iPadX = 0;
		slavePtr->iPadY = 0;
		if (slavePtr->in != NULL) {
		    Tcl_DecrRefCount(slavePtr->in);
		    slavePtr->in = NULL;
		}
		contentPtr->doubleBw = 2*Tk_Changes(tkwin)->border_width;
		if (contentPtr->flags & REQUESTED_RELAYOUT) {
		    Tcl_CancelIdleCall(ArrangeGrid, contentPtr);
		slavePtr->doubleBw = 2*Tk_Changes(tkwin)->border_width;
		if (slavePtr->flags & REQUESTED_RELAYOUT) {
		    Tcl_CancelIdleCall(ArrangeGrid, slavePtr);
		}
		contentPtr->flags = 0;
		contentPtr->sticky = 0;
		slavePtr->flags = 0;
		slavePtr->sticky = 0;
	    } else {
		/*
		 * When removing, store name of container to be able to
		 * restore it later, even if the container is recreated.
		 * When removing, store name of master to be able to
		 * restore it later, even if the master is recreated.
		 */

		if (contentPtr->in != NULL) {
		    Tcl_DecrRefCount(contentPtr->in);
		    contentPtr->in = NULL;
		if (slavePtr->in != NULL) {
		    Tcl_DecrRefCount(slavePtr->in);
		    slavePtr->in = NULL;
		}
		if (contentPtr->containerPtr != NULL) {
		    contentPtr->in = Tcl_NewStringObj(
			    Tk_PathName(contentPtr->containerPtr->tkwin), TCL_INDEX_NONE);
		    Tcl_IncrRefCount(contentPtr->in);
		if (slavePtr->masterPtr != NULL) {
		    slavePtr->in = Tcl_NewStringObj(
			    Tk_PathName(slavePtr->masterPtr->tkwin), -1);
		    Tcl_IncrRefCount(slavePtr->in);
		}
	    }
	    Tk_ManageGeometry(content, NULL, NULL);
	    if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
		Tk_UnmaintainGeometry(contentPtr->tkwin,
			contentPtr->containerPtr->tkwin);
	    Tk_ManageGeometry(slave, NULL, NULL);
	    if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
		Tk_UnmaintainGeometry(slavePtr->tkwin,
			slavePtr->masterPtr->tkwin);
	    }
	    Unlink(contentPtr);
	    Tk_UnmapWindow(contentPtr->tkwin);
	    Unlink(slavePtr);
	    Tk_UnmapWindow(slavePtr->tkwin);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
727
728
729
730
731
732
733
734

735
736
737
738


739
740
741
742
743
744
745

746
747
748
749


750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
















771
772
773
774
775
776
777
713
714
715
716
717
718
719

720
721
722


723
724
725
726
727
728
729
730

731
732
733


734
735
736
737
738
739
740
















741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763







-
+


-
-
+
+






-
+


-
-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

static int
GridInfoCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Gridder *contentPtr;
    Tk_Window content;
    register Gridder *slavePtr;
    Tk_Window slave;
    Tcl_Obj *infoObj;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &content) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &slave) != TCL_OK) {
	return TCL_ERROR;
    }
    contentPtr = GetGrid(content);
    if (contentPtr->containerPtr == NULL) {
    slavePtr = GetGrid(slave);
    if (slavePtr->masterPtr == NULL) {
	Tcl_ResetResult(interp);
	return TCL_OK;
    }

    infoObj = Tcl_NewObj();
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", TCL_INDEX_NONE),
	    Tk_NewWindowObj(contentPtr->containerPtr->tkwin));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-column", TCL_INDEX_NONE),
	    Tcl_NewWideIntObj(contentPtr->column));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-row", TCL_INDEX_NONE),
	    Tcl_NewWideIntObj(contentPtr->row));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-columnspan", TCL_INDEX_NONE),
	    Tcl_NewWideIntObj(contentPtr->numCols));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-rowspan", TCL_INDEX_NONE),
	    Tcl_NewWideIntObj(contentPtr->numRows));
    TkAppendPadAmount(infoObj, "-ipadx", contentPtr->iPadX/2, contentPtr->iPadX);
    TkAppendPadAmount(infoObj, "-ipady", contentPtr->iPadY/2, contentPtr->iPadY);
    TkAppendPadAmount(infoObj, "-padx", contentPtr->padLeft, contentPtr->padX);
    TkAppendPadAmount(infoObj, "-pady", contentPtr->padTop, contentPtr->padY);
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-sticky", TCL_INDEX_NONE),
	    StickyToObj(contentPtr->sticky));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", -1),
	    TkNewWindowObj(slavePtr->masterPtr->tkwin));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-column", -1),
	    Tcl_NewIntObj(slavePtr->column));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-row", -1),
	    Tcl_NewIntObj(slavePtr->row));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-columnspan", -1),
	    Tcl_NewIntObj(slavePtr->numCols));
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-rowspan", -1),
	    Tcl_NewIntObj(slavePtr->numRows));
    TkAppendPadAmount(infoObj, "-ipadx", slavePtr->iPadX/2, slavePtr->iPadX);
    TkAppendPadAmount(infoObj, "-ipady", slavePtr->iPadY/2, slavePtr->iPadY);
    TkAppendPadAmount(infoObj, "-padx", slavePtr->padLeft, slavePtr->padX);
    TkAppendPadAmount(infoObj, "-pady", slavePtr->padTop, slavePtr->padY);
    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-sticky", -1),
	    StickyToObj(slavePtr->sticky));
    Tcl_SetObjResult(interp, infoObj);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
789
790
791
792
793
794
795
796

797
798
799
800
801
802
803





804
805
806
807
808





809
810
811
812
813
814
815
816

817
818
819

820
821
822
823
824
825



826
827
828

829
830
831
832
833
834
835
836
837
838



839
840

841
842
843
844
845


846
847
848

849
850
851
852
853
854
855


856
857
858

859
860
861
862
863
864
865
775
776
777
778
779
780
781

782
783
784





785
786
787
788
789
790
791
792
793

794
795
796
797
798
799
800
801





802
803
804

805
806
807
808



809
810
811
812
813

814
815
816
817
818
819
820
821



822
823
824
825

826
827
828
829


830
831
832
833

834
835
836
837
838
839


840
841
842
843

844
845
846
847
848
849
850
851







-
+


-
-
-
-
-
+
+
+
+
+




-
+
+
+
+
+



-
-
-
-
-
+


-
+



-
-
-
+
+
+


-
+







-
-
-
+
+
+

-
+



-
-
+
+


-
+





-
-
+
+


-
+







 *----------------------------------------------------------------------
 */

static int
GridLocationCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;		/* Container grid record. */
    GridContainer *gridPtr;	/* Pointer to grid data. */
    SlotInfo *slotPtr;
    int x, y;			/* Offset in pixels, from edge of container. */
    Tk_Window master;
    Gridder *masterPtr;		/* Master grid record. */
    GridMaster *gridPtr;	/* Pointer to grid data. */
    register SlotInfo *slotPtr;
    int x, y;			/* Offset in pixels, from edge of master. */
    int i, j;			/* Corresponding column and row indeces. */
    int endX, endY;		/* End of grid. */

    if (objc != 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "window x y");
	Tcl_WrongNumArgs(interp, 2, objv, "master x y");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
	return TCL_ERROR;
    }

    if (Tk_GetPixelsFromObj(interp, container, objv[3], &x) != TCL_OK) {
    if (Tk_GetPixelsFromObj(interp, master, objv[3], &x) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tk_GetPixelsFromObj(interp, container, objv[4], &y) != TCL_OK) {
    if (Tk_GetPixelsFromObj(interp, master, objv[4], &y) != TCL_OK) {
	return TCL_ERROR;
    }

    containerPtr = GetGrid(container);
    if (containerPtr->containerDataPtr == NULL) {
	Tcl_SetObjResult(interp, NewPairObj(-1, TCL_INDEX_NONE));
    masterPtr = GetGrid(master);
    if (masterPtr->masterDataPtr == NULL) {
	Tcl_SetObjResult(interp, NewPairObj(-1, -1));
	return TCL_OK;
    }
    gridPtr = containerPtr->containerDataPtr;
    gridPtr = masterPtr->masterDataPtr;

    /*
     * Update any pending requests. This is not always the steady state value,
     * as more configure events could be in the pipeline, but its as close as
     * its easy to get.
     */

    while (containerPtr->flags & REQUESTED_RELAYOUT) {
	Tcl_CancelIdleCall(ArrangeGrid, containerPtr);
	ArrangeGrid(containerPtr);
    while (masterPtr->flags & REQUESTED_RELAYOUT) {
	Tcl_CancelIdleCall(ArrangeGrid, masterPtr);
	ArrangeGrid(masterPtr);
    }
    SetGridSize(containerPtr);
    SetGridSize(masterPtr);
    endX = MAX(gridPtr->columnEnd, gridPtr->columnMax);
    endY = MAX(gridPtr->rowEnd, gridPtr->rowMax);

    slotPtr = containerPtr->containerDataPtr->columnPtr;
    if (x < containerPtr->containerDataPtr->startX) {
    slotPtr = masterPtr->masterDataPtr->columnPtr;
    if (x < masterPtr->masterDataPtr->startX) {
	i = -1;
    } else {
	x -= containerPtr->containerDataPtr->startX;
	x -= masterPtr->masterDataPtr->startX;
	for (i = 0; slotPtr[i].offset < x && i < endX; i++) {
	    /* null body */
	}
    }

    slotPtr = containerPtr->containerDataPtr->rowPtr;
    if (y < containerPtr->containerDataPtr->startY) {
    slotPtr = masterPtr->masterDataPtr->rowPtr;
    if (y < masterPtr->masterDataPtr->startY) {
	j = -1;
    } else {
	y -= containerPtr->containerDataPtr->startY;
	y -= masterPtr->masterDataPtr->startY;
	for (j = 0; slotPtr[j].offset < y && j < endY; j++) {
	    /* null body */
	}
    }

    Tcl_SetObjResult(interp, NewPairObj(i, j));
    return TCL_OK;
882
883
884
885
886
887
888
889

890
891
892
893


894
895
896
897
898
899
900
901

902
903
904

905
906
907

908
909
910
911
912
913
914
915
916
917
918

919
920
921
922

923
924
925
926


927
928
929

930
931

932
933
934
935



936
937

938
939
940
941
942


943
944
945
946


947
948
949
950



951
952
953
954
955
956
957
868
869
870
871
872
873
874

875
876
877


878
879
880
881
882
883
884
885
886

887
888
889

890
891
892

893
894
895
896
897
898
899
900
901
902
903

904
905
906
907

908
909
910


911
912
913
914

915
916

917
918



919
920
921
922

923
924
925
926


927
928
929
930


931
932
933



934
935
936
937
938
939
940
941
942
943







-
+


-
-
+
+







-
+


-
+


-
+










-
+



-
+


-
-
+
+


-
+

-
+

-
-
-
+
+
+

-
+



-
-
+
+


-
-
+
+

-
-
-
+
+
+







 *----------------------------------------------------------------------
 */

static int
GridPropagateCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;
    Tk_Window master;
    Gridder *masterPtr;
    int propagate, old;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    containerPtr = GetGrid(container);
    masterPtr = GetGrid(master);
    if (objc == 3) {
	Tcl_SetObjResult(interp,
		Tcl_NewBooleanObj(!(containerPtr->flags & DONT_PROPAGATE)));
		Tcl_NewBooleanObj(!(masterPtr->flags & DONT_PROPAGATE)));
	return TCL_OK;
    }
    if (Tcl_GetBooleanFromObj(interp, objv[3], &propagate) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Only request a relayout if the propagation bit changes.
     */

    old = !(containerPtr->flags & DONT_PROPAGATE);
    old = !(masterPtr->flags & DONT_PROPAGATE);
    if (propagate != old) {
	if (propagate) {
	    /*
	     * If we have content, we need to register as geometry container.
	     * If we have slaves, we need to register as geometry master.
	     */

	    if (containerPtr->contentPtr != NULL) {
		if (TkSetGeometryContainer(interp, container, "grid")	!= TCL_OK) {
	    if (masterPtr->slavePtr != NULL) {
		if (TkSetGeometryMaster(interp, master, "grid")	!= TCL_OK) {
		    return TCL_ERROR;
		}
		containerPtr->flags |= ALLOCED_CONTAINER;
		masterPtr->flags |= ALLOCED_MASTER;
	    }
	    containerPtr->flags &= ~DONT_PROPAGATE;
	    masterPtr->flags &= ~DONT_PROPAGATE;
	} else {
	    if (containerPtr->flags & ALLOCED_CONTAINER) {
		TkFreeGeometryContainer(container, "grid");
		containerPtr->flags &= ~ALLOCED_CONTAINER;
	    if (masterPtr->flags & ALLOCED_MASTER) {
		TkFreeGeometryMaster(master, "grid");
		masterPtr->flags &= ~ALLOCED_MASTER;
	    }
	    containerPtr->flags |= DONT_PROPAGATE;
	    masterPtr->flags |= DONT_PROPAGATE;
	}

	/*
	 * Re-arrange the container to allow new geometry information to
	 * propagate upwards to the container's container.
	 * Re-arrange the master to allow new geometry information to
	 * propagate upwards to the master's master.
	 */

	if (containerPtr->abortPtr != NULL) {
	    *containerPtr->abortPtr = 1;
	if (masterPtr->abortPtr != NULL) {
	    *masterPtr->abortPtr = 1;
	}
	if (!(containerPtr->flags & REQUESTED_RELAYOUT)) {
	    containerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
	if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
970
971
972
973
974
975
976
977

978
979
980
981


982
983
984
985
986

987
988
989

990
991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028



1029
1030
1031
1032
1033

1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050


1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072


1073
1074
1075


1076
1077

1078
1079

1080
1081
1082


1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099

1100
1101
1102

1103
1104
1105
1106
1107
1108

1109
1110

1111
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123

1124
1125
1126

1127
1128
1129

1130
1131
1132


1133
1134
1135
1136


1137
1138
1139

1140
1141
1142
1143


1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165
1166

1167
1168

1169
1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184


1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
956
957
958
959
960
961
962

963
964
965


966
967
968
969
970
971

972
973
974

975
976
977
978
979
980
981
982
983
984
985
986

987
988
989
990

991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011



1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031

1032
1033
1034


1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056


1057
1058
1059


1060
1061
1062

1063
1064

1065
1066


1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087

1088
1089
1090
1091
1092
1093

1094
1095

1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108

1109
1110
1111

1112
1113
1114

1115
1116


1117
1118
1119
1120


1121
1122
1123
1124

1125
1126
1127


1128
1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149

1150
1151

1152
1153

1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168


1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191







-
+


-
-
+
+




-
+


-
+











-
+



-
+




















-
-
-
+
+
+




-
+












-
+


-
-
+
+




















-
-
+
+

-
-
+
+

-
+

-
+

-
-
+
+
















-
+


-
+





-
+

-
+







-
+




-
+


-
+


-
+

-
-
+
+


-
-
+
+


-
+


-
-
+
+



-
+
















-
+

-
+

-
+



-
+










-
-
+
+













-
+







 *----------------------------------------------------------------------
 */

static int
GridRowColumnConfigureCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container, content;
    Gridder *containerPtr, *contentPtr;
    Tk_Window master, slave;
    Gridder *masterPtr, *slavePtr;
    SlotInfo *slotPtr = NULL;
    int slot;			/* the column or row number */
    int slotType;		/* COLUMN or ROW */
    int size;			/* the configuration value */
    Tcl_Size lObjc;		/* Number of items in index list */
    int lObjc;			/* Number of items in index list */
    Tcl_Obj **lObjv;		/* array of indices */
    int ok;			/* temporary TCL result code */
    Tcl_Size i, j, first, last;
    int i, j, first, last;
    const char *string;
    static const char *const optionStrings[] = {
	"-minsize", "-pad", "-uniform", "-weight", NULL
    };
    enum options {
	ROWCOL_MINSIZE, ROWCOL_PAD, ROWCOL_UNIFORM, ROWCOL_WEIGHT
    };
    int index;
    Tcl_Obj *listCopy;

    if (((objc % 2 != 0) && (objc > 6)) || (objc < 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window index ?-option value ...?");
	Tcl_WrongNumArgs(interp, 2, objv, "master index ?-option value ...?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }

    listCopy = Tcl_DuplicateObj(objv[3]);
    Tcl_IncrRefCount(listCopy);
    if (Tcl_ListObjGetElements(interp, listCopy, &lObjc, &lObjv) != TCL_OK) {
	Tcl_DecrRefCount(listCopy);
	return TCL_ERROR;
    }

    string = Tcl_GetString(objv[1]);
    slotType = (*string == 'c') ? COLUMN : ROW;
    if (lObjc == 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("no %s indices specified",
		(slotType == COLUMN) ? "column" : "row"));
	Tcl_SetErrorCode(interp, "TK", "GRID", "NO_INDEX", NULL);
	Tcl_DecrRefCount(listCopy);
	return TCL_ERROR;
    }

    containerPtr = GetGrid(container);
    first = 0;
    last = 0;
    masterPtr = GetGrid(master);
    first = 0; /* lint */
    last = 0; /* lint */

    if ((objc == 4) || (objc == 5)) {
	if (lObjc != 1) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "must specify a single element on retrieval", TCL_INDEX_NONE));
		    "must specify a single element on retrieval", -1));
	    Tcl_SetErrorCode(interp, "TK", "GRID", "USAGE", NULL);
	    Tcl_DecrRefCount(listCopy);
	    return TCL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp, lObjv[0], &slot) != TCL_OK) {
	    Tcl_AppendResult(interp,
		    " (when retrieving options only integer indices are "
		    "allowed)", NULL);
	    Tcl_SetErrorCode(interp, "TK", "GRID", "INDEX_FORMAT", NULL);
	    Tcl_DecrRefCount(listCopy);
	    return TCL_ERROR;
	}
	ok = CheckSlotData(containerPtr, slot, slotType, /* checkOnly */ 1);
	ok = CheckSlotData(masterPtr, slot, slotType, /* checkOnly */ 1);
	if (ok == TCL_OK) {
	    slotPtr = (slotType == COLUMN) ?
		    containerPtr->containerDataPtr->columnPtr :
		    containerPtr->containerDataPtr->rowPtr;
		    masterPtr->masterDataPtr->columnPtr :
		    masterPtr->masterDataPtr->rowPtr;
	}

	/*
	 * Return all of the options for this row or column. If the request is
	 * out of range, return all 0's.
	 */

	if (objc == 4) {
	    int minsize = 0, pad = 0, weight = 0;
	    Tk_Uid uniform = NULL;
	    Tcl_Obj *res = Tcl_NewListObj(0, NULL);

	    if (ok == TCL_OK) {
		minsize = slotPtr[slot].minSize;
		pad     = slotPtr[slot].pad;
		weight  = slotPtr[slot].weight;
		uniform = slotPtr[slot].uniform;
	    }

	    Tcl_ListObjAppendElement(interp, res,
		    Tcl_NewStringObj("-minsize", TCL_INDEX_NONE));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewWideIntObj(minsize));
		    Tcl_NewStringObj("-minsize", -1));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(minsize));
	    Tcl_ListObjAppendElement(interp, res,
		    Tcl_NewStringObj("-pad", TCL_INDEX_NONE));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewWideIntObj(pad));
		    Tcl_NewStringObj("-pad", -1));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(pad));
	    Tcl_ListObjAppendElement(interp, res,
		    Tcl_NewStringObj("-uniform", TCL_INDEX_NONE));
		    Tcl_NewStringObj("-uniform", -1));
	    Tcl_ListObjAppendElement(interp, res,
		    Tcl_NewStringObj(uniform == NULL ? "" : uniform, TCL_INDEX_NONE));
		    Tcl_NewStringObj(uniform == NULL ? "" : uniform, -1));
	    Tcl_ListObjAppendElement(interp, res,
		    Tcl_NewStringObj("-weight", TCL_INDEX_NONE));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewWideIntObj(weight));
		    Tcl_NewStringObj("-weight", -1));
	    Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(weight));
	    Tcl_SetObjResult(interp, res);
	    Tcl_DecrRefCount(listCopy);
	    return TCL_OK;
	}

	/*
	 * If only one option is given, with no value, the current value is
	 * returned.
	 */

	if (Tcl_GetIndexFromObjStruct(interp, objv[4], optionStrings,
		sizeof(char *), "option", 0, &index) != TCL_OK) {
	    Tcl_DecrRefCount(listCopy);
	    return TCL_ERROR;
	}
	if (index == ROWCOL_MINSIZE) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(
		    (ok == TCL_OK) ? slotPtr[slot].minSize : 0));
	} else if (index == ROWCOL_WEIGHT) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(
		    (ok == TCL_OK) ? slotPtr[slot].weight : 0));
	} else if (index == ROWCOL_UNIFORM) {
	    Tk_Uid value = (ok == TCL_OK) ? slotPtr[slot].uniform : "";

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    (value == NULL) ? "" : value, TCL_INDEX_NONE));
		    (value == NULL) ? "" : value, -1));
	} else if (index == ROWCOL_PAD) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(
		    (ok == TCL_OK) ? slotPtr[slot].pad : 0));
	}
	Tcl_DecrRefCount(listCopy);
	return TCL_OK;
    }

    for (j = 0; j < lObjc; j++) {
	int allContent = 0;
	int allSlaves = 0;

	if (Tcl_GetIntFromObj(NULL, lObjv[j], &slot) == TCL_OK) {
	    first = slot;
	    last = slot;
	    contentPtr = NULL;
	    slavePtr = NULL;
	} else if (strcmp(Tcl_GetString(lObjv[j]), "all") == 0) {
	    /*
	     * Make sure container is initialised.
	     * Make sure master is initialised.
	     */

	    InitContainerData(containerPtr);
	    InitMasterData(masterPtr);

	    contentPtr = containerPtr->contentPtr;
	    if (contentPtr == NULL) {
	    slavePtr = masterPtr->slavePtr;
	    if (slavePtr == NULL) {
		continue;
	    }
	    allContent = 1;
	} else if (TkGetWindowFromObj(NULL, tkwin, lObjv[j], &content)
	    allSlaves = 1;
	} else if (TkGetWindowFromObj(NULL, tkwin, lObjv[j], &slave)
		== TCL_OK) {
	    /*
	     * Is it gridded in this container?
	     * Is it gridded in this master?
	     */

	    contentPtr = GetGrid(content);
	    if (contentPtr->containerPtr != containerPtr) {
	    slavePtr = GetGrid(slave);
	    if (slavePtr->masterPtr != masterPtr) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"the window \"%s\" is not managed by \"%s\"",
			Tcl_GetString(lObjv[j]), Tcl_GetString(objv[2])));
		Tcl_SetErrorCode(interp, "TK", "GRID", "NOT_MANAGED", NULL);
		Tcl_SetErrorCode(interp, "TK", "GRID", "NOT_MASTER", NULL);
		Tcl_DecrRefCount(listCopy);
		return TCL_ERROR;
	    }
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "illegal index \"%s\"", Tcl_GetString(lObjv[j])));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID_INDEX", NULL);
	    Tcl_DecrRefCount(listCopy);
	    return TCL_ERROR;
	}

	/*
	 * The outer loop is only to handle "all".
	 */

	do {
	    if (contentPtr != NULL) {
	    if (slavePtr != NULL) {
		first = (slotType == COLUMN) ?
			contentPtr->column : contentPtr->row;
			slavePtr->column : slavePtr->row;
		last = first - 1 + ((slotType == COLUMN) ?
			contentPtr->numCols : contentPtr->numRows);
			slavePtr->numCols : slavePtr->numRows);
	    }

	    for (slot = first; slot <= last; slot++) {
		ok = CheckSlotData(containerPtr, slot, slotType, /*checkOnly*/ 0);
		ok = CheckSlotData(masterPtr, slot, slotType, /*checkOnly*/ 0);
		if (ok != TCL_OK) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "\"%s\" is out of range",
			    Tcl_GetString(lObjv[j])));
		    Tcl_SetErrorCode(interp, "TK", "GRID", "INDEX_RANGE",
			    NULL);
		    Tcl_DecrRefCount(listCopy);
		    return TCL_ERROR;
		}
		slotPtr = (slotType == COLUMN) ?
			containerPtr->containerDataPtr->columnPtr :
			containerPtr->containerDataPtr->rowPtr;
			masterPtr->masterDataPtr->columnPtr :
			masterPtr->masterDataPtr->rowPtr;

		/*
		 * Loop through each option value pair, setting the values as
		 * required.
		 */

		for (i = 4; i < objc; i += 2) {
		    if (Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
			    sizeof(char *), "option", 0, &index) != TCL_OK) {
			Tcl_DecrRefCount(listCopy);
			return TCL_ERROR;
		    }
		    if (index == ROWCOL_MINSIZE) {
			if (Tk_GetPixelsFromObj(interp, container, objv[i+1],
			if (Tk_GetPixelsFromObj(interp, master, objv[i+1],
				&size) != TCL_OK) {
			    Tcl_DecrRefCount(listCopy);
			    return TCL_ERROR;
			} else {
			    slotPtr[slot].minSize = size;
			}
		    } else if (index == ROWCOL_WEIGHT) {
1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239


1240
1241

1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259

1260
1261

1262
1263
1264
1265
1266
1267
1268

1269
1270
1271
1272
1273


1274
1275
1276
1277



1278
1279
1280
1281
1282
1283
1284
1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223


1224
1225
1226

1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243
1244

1245
1246

1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257


1258
1259
1260



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270







-
+












-
-
+
+

-
+










-
+






-
+

-
+






-
+



-
-
+
+

-
-
-
+
+
+







			slotPtr[slot].uniform =
				Tk_GetUid(Tcl_GetString(objv[i+1]));
			if (slotPtr[slot].uniform != NULL &&
				slotPtr[slot].uniform[0] == 0) {
			    slotPtr[slot].uniform = NULL;
			}
		    } else if (index == ROWCOL_PAD) {
			if (Tk_GetPixelsFromObj(interp, container, objv[i+1],
			if (Tk_GetPixelsFromObj(interp, master, objv[i+1],
				&size) != TCL_OK) {
			    Tcl_DecrRefCount(listCopy);
			    return TCL_ERROR;
			} else if (size < 0) {
			    Tcl_DecrRefCount(listCopy);
			    goto negativeIndex;
			} else {
			    slotPtr[slot].pad = size;
			}
		    }
		}
	    }
	    if (contentPtr != NULL) {
		contentPtr = contentPtr->nextPtr;
	    if (slavePtr != NULL) {
		slavePtr = slavePtr->nextPtr;
	    }
	} while ((allContent == 1) && (contentPtr != NULL));
	} while ((allSlaves == 1) && (slavePtr != NULL));
    }
    Tcl_DecrRefCount(listCopy);

    /*
     * We changed a property, re-arrange the table, and check for constraint
     * shrinkage. A null slotPtr will occur for 'all' checks.
     */

    if (slotPtr != NULL) {
	if (slotType == ROW) {
	    last = containerPtr->containerDataPtr->rowMax - 1;
	    int last = masterPtr->masterDataPtr->rowMax - 1;

	    while ((last >= 0) && (slotPtr[last].weight == 0)
		    && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0)
		    && (slotPtr[last].uniform == NULL)) {
		last--;
	    }
	    containerPtr->containerDataPtr->rowMax = last+1;
	    masterPtr->masterDataPtr->rowMax = last+1;
	} else {
	    last = containerPtr->containerDataPtr->columnMax - 1;
	    int last = masterPtr->masterDataPtr->columnMax - 1;

	    while ((last >= 0) && (slotPtr[last].weight == 0)
		    && (slotPtr[last].pad == 0) && (slotPtr[last].minSize == 0)
		    && (slotPtr[last].uniform == NULL)) {
		last--;
	    }
	    containerPtr->containerDataPtr->columnMax = last + 1;
	    masterPtr->masterDataPtr->columnMax = last + 1;
	}
    }

    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    if (!(containerPtr->flags & REQUESTED_RELAYOUT)) {
	containerPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
    if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	masterPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
    }
    return TCL_OK;

  negativeIndex:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "invalid arg \"%s\": should be non-negative",
	    Tcl_GetString(objv[i])));
1303
1304
1305
1306
1307
1308
1309
1310

1311
1312
1313
1314
1315



1316
1317
1318
1319
1320
1321
1322

1323
1324
1325

1326
1327
1328
1329



1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342

1343
1344

1345
1346
1347
1348
1349
1350
1351
1352


1353
1354
1355
1356
1357
1358

1359
1360
1361

1362
1363
1364
1365
1366



1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298



1299
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310

1311
1312



1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329

1330
1331
1332
1333
1334
1335
1336


1337
1338
1339
1340
1341
1342
1343

1344
1345
1346

1347
1348
1349



1350
1351
1352
1353
1354
1355
1356
1357

1358
1359
1360
1361
1362
1363
1364
1365







-
+


-
-
-
+
+
+






-
+


-
+

-
-
-
+
+
+












-
+

-
+






-
-
+
+





-
+


-
+


-
-
-
+
+
+





-
+







 *----------------------------------------------------------------------
 */

static int
GridSizeCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;
    GridContainer *gridPtr;	/* pointer to grid data */
    Tk_Window master;
    Gridder *masterPtr;
    GridMaster *gridPtr;	/* pointer to grid data */

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    containerPtr = GetGrid(container);
    masterPtr = GetGrid(master);

    if (containerPtr->containerDataPtr != NULL) {
	SetGridSize(containerPtr);
	gridPtr = containerPtr->containerDataPtr;
    if (masterPtr->masterDataPtr != NULL) {
	SetGridSize(masterPtr);
	gridPtr = masterPtr->masterDataPtr;
	Tcl_SetObjResult(interp, NewPairObj(
		MAX(gridPtr->columnEnd, gridPtr->columnMax),
		MAX(gridPtr->rowEnd, gridPtr->rowMax)));
    } else {
	Tcl_SetObjResult(interp, NewPairObj(0, 0));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GridContentCommand --
 * GridSlavesCommand --
 *
 *	Implementation of the [grid content] subcommand. See the user
 *	Implementation of the [grid slaves] subcommand. See the user
 *	documentation for details on what it does.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	Places a list of content windows of the specified window in the
 *	interpreter's result field.
 *	Places a list of slaves of the specified window in the interpreter's
 *	result field.
 *
 *----------------------------------------------------------------------
 */

static int
GridContentCommand(
GridSlavesCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window container;
    Gridder *containerPtr;		/* container grid record */
    Gridder *contentPtr;
    Tk_Window master;
    Gridder *masterPtr;		/* master grid record */
    Gridder *slavePtr;
    int i, value, index;
    int row = -1, column = -1;
    static const char *const optionStrings[] = {
	"-column", "-row", NULL
    };
    enum options { CONTENT_COLUMN, CONTENT_ROW };
    enum options { SLAVES_COLUMN, SLAVES_ROW };
    Tcl_Obj *res;

    if ((objc < 3) || ((objc % 2) == 0)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?-option value ...?");
	return TCL_ERROR;
    }

1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401

1402
1403
1404

1405
1406
1407
1408
1409
1410




1411
1412
1413
1414


1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1373
1374
1375
1376
1377
1378
1379

1380
1381
1382
1383
1384
1385
1386

1387
1388
1389

1390
1391
1392




1393
1394
1395
1396
1397
1398


1399
1400
1401
1402

1403
1404
1405
1406
1407
1408
1409
1410







-
+






-
+


-
+


-
-
-
-
+
+
+
+


-
-
+
+


-
+







	}
	if (value < 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "%d is an invalid value: should NOT be < 0", value));
	    Tcl_SetErrorCode(interp, "TK", "GRID", "NEG_INDEX", NULL);
	    return TCL_ERROR;
	}
	if (index == CONTENT_COLUMN) {
	if (index == SLAVES_COLUMN) {
	    column = value;
	} else {
	    row = value;
	}
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    containerPtr = GetGrid(container);
    masterPtr = GetGrid(master);

    res = Tcl_NewListObj(0, NULL);
    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	if ((column >= 0) && (contentPtr->column > column
		|| contentPtr->column+contentPtr->numCols-1 < column)) {
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	if ((column >= 0) && (slavePtr->column > column
		|| slavePtr->column+slavePtr->numCols-1 < column)) {
	    continue;
	}
	if ((row >= 0) && (contentPtr->row > row ||
		contentPtr->row+contentPtr->numRows-1 < row)) {
	if ((row >= 0) && (slavePtr->row > row ||
		slavePtr->row+slavePtr->numRows-1 < row)) {
	    continue;
	}
	Tcl_ListObjAppendElement(interp,res, Tk_NewWindowObj(contentPtr->tkwin));
	Tcl_ListObjAppendElement(interp,res, TkNewWindowObj(slavePtr->tkwin));
    }
    Tcl_SetObjResult(interp, res);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1436
1437
1438
1439
1440
1441
1442
1443

1444
1445

1446
1447
1448

1449
1450

1451
1452
1453
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463

1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475
1476


1477
1478

1479
1480

1481
1482
1483


1484
1485
1486


1487
1488
1489
1490
1491
1492
1493
1422
1423
1424
1425
1426
1427
1428

1429
1430

1431
1432
1433

1434
1435

1436
1437
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448

1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460


1461
1462
1463

1464
1465

1466
1467


1468
1469
1470


1471
1472
1473
1474
1475
1476
1477
1478
1479







-
+

-
+


-
+

-
+









-
+


-
+





-
+





-
-
+
+

-
+

-
+

-
-
+
+

-
-
+
+







 *	the next idle point.
 *
 *----------------------------------------------------------------------
 */

static void
GridReqProc(
    void *clientData,	/* Grid's information about window that got
    ClientData clientData,	/* Grid's information about window that got
				 * new preferred geometry. */
    TCL_UNUSED(Tk_Window))		/* Other Tk-related information about the
    Tk_Window tkwin)		/* Other Tk-related information about the
				 * window. */
{
    Gridder *gridPtr = (Gridder *)clientData;
    register Gridder *gridPtr = clientData;

    gridPtr = gridPtr->containerPtr;
    gridPtr = gridPtr->masterPtr;
    if (gridPtr && !(gridPtr->flags & REQUESTED_RELAYOUT)) {
	gridPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, gridPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GridLostContentProc --
 * GridLostSlaveProc --
 *
 *	This procedure is invoked by Tk whenever some other geometry claims
 *	control over a content that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all grid-related information about the content.
 *	Forgets all grid-related information about the slave.
 *
 *----------------------------------------------------------------------
 */

static void
GridLostContentProc(
    void *clientData,	/* Grid structure for content window that was
GridLostSlaveProc(
    ClientData clientData,	/* Grid structure for slave window that was
				 * stolen away. */
    TCL_UNUSED(Tk_Window))		/* Tk's handle for the content window. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    Gridder *contentPtr = (Gridder *)clientData;
    register Gridder *slavePtr = clientData;

    if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
	Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
    if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
	Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
    }
    Unlink(contentPtr);
    Tk_UnmapWindow(contentPtr->tkwin);
    Unlink(slavePtr);
    Tk_UnmapWindow(slavePtr->tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * AdjustOffsets --
 *
1505
1506
1507
1508
1509
1510
1511
1512
1513


1514
1515

1516
1517
1518
1519
1520
1521
1522
1491
1492
1493
1494
1495
1496
1497


1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508







-
-
+
+

-
+







 *
 *----------------------------------------------------------------------
 */

static int
AdjustOffsets(
    int size,			/* The total layout size (in pixels). */
    Tcl_Size slots,			/* Number of slots. */
    SlotInfo *slotPtr)	/* Pointer to slot array. */
    int slots,			/* Number of slots. */
    register SlotInfo *slotPtr)	/* Pointer to slot array. */
{
    Tcl_Size slot;		/* Current slot. */
    register int slot;		/* Current slot. */
    int diff;			/* Extra pixels needed to add to the layout. */
    int totalWeight;		/* Sum of the weights for all the slots. */
    int weight;			/* Sum of the weights so far. */
    int minSize;		/* Minimum possible layout size. */
    int newDiff;		/* The most pixels that can be added on the
    				 * current pass. */

1653
1654
1655
1656
1657
1658
1659
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
1639
1640
1641
1642
1643
1644
1645

1646
1647
1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
+




-
+









-
+





-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+


-
-
-
+
+
+







}

/*
 *----------------------------------------------------------------------
 *
 * AdjustForSticky --
 *
 *	This procedure adjusts the size of a content in its cavity based on its
 *	This procedure adjusts the size of a slave in its cavity based on its
 *	"sticky" flags.
 *
 * Results:
 *	The input x, y, width, and height are changed to represent the desired
 *	coordinates of the content.
 *	coordinates of the slave.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
AdjustForSticky(
    Gridder *contentPtr,	/* Content window to arrange in its cavity. */
    Gridder *slavePtr,	/* Slave window to arrange in its cavity. */
    int *xPtr,		/* Pixel location of the left edge of the cavity. */
    int *yPtr,		/* Pixel location of the top edge of the cavity. */
    int *widthPtr,	/* Width of the cavity (in pixels). */
    int *heightPtr)	/* Height of the cavity (in pixels). */
{
    int diffx = 0;	/* Cavity width - content width. */
    int diffy = 0;	/* Cavity hight - content height. */
    int sticky = contentPtr->sticky;
    int diffx = 0;	/* Cavity width - slave width. */
    int diffy = 0;	/* Cavity hight - slave height. */
    int sticky = slavePtr->sticky;

    *xPtr += contentPtr->padLeft;
    *widthPtr -= contentPtr->padX;
    *yPtr += contentPtr->padTop;
    *heightPtr -= contentPtr->padY;
    *xPtr += slavePtr->padLeft;
    *widthPtr -= slavePtr->padX;
    *yPtr += slavePtr->padTop;
    *heightPtr -= slavePtr->padY;

    if (*widthPtr > (Tk_ReqWidth(contentPtr->tkwin) + contentPtr->iPadX)) {
	diffx = *widthPtr - (Tk_ReqWidth(contentPtr->tkwin) + contentPtr->iPadX);
	*widthPtr = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->iPadX;
    if (*widthPtr > (Tk_ReqWidth(slavePtr->tkwin) + slavePtr->iPadX)) {
	diffx = *widthPtr - (Tk_ReqWidth(slavePtr->tkwin) + slavePtr->iPadX);
	*widthPtr = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->iPadX;
    }

    if (*heightPtr > (Tk_ReqHeight(contentPtr->tkwin) + contentPtr->iPadY)) {
	diffy = *heightPtr - (Tk_ReqHeight(contentPtr->tkwin) + contentPtr->iPadY);
	*heightPtr = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->iPadY;
    if (*heightPtr > (Tk_ReqHeight(slavePtr->tkwin) + slavePtr->iPadY)) {
	diffy = *heightPtr - (Tk_ReqHeight(slavePtr->tkwin) + slavePtr->iPadY);
	*heightPtr = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->iPadY;
    }

    if (sticky&STICK_EAST && sticky&STICK_WEST) {
	*widthPtr += diffx;
    }
    if (sticky&STICK_NORTH && sticky&STICK_SOUTH) {
	*heightPtr += diffy;
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
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







-
+






-
+


-
-
-
+
+
+





-
+


-
-
-
+
+
+
+


-
+



-
+









-
-
+
+

-
+

-
+





-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
-
+
+

-
-
+
+




-
+





-
-
-
-
-
-
+
+
+
+
+
+




-
+



-
+



-
-
+
+

+
-
-
+
+




-
-
+
+




-
+



-
+



-
+

-
+

-
-
-
-
-
+
+
+
+
+






-
-
+
+


-
-
+
+



-
-
+
+

-
+




-
-
+
+

















-
+






-
+




-
-
+
+








-
+
















-
+










-
-
-
+
+
+

-
-
-
+
+
+








-
+







 *	time so that a series of grid requests can be merged into a single
 *	layout operation.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The content of containerPtr may get resized or moved.
 *	The slaves of masterPtr may get resized or moved.
 *
 *----------------------------------------------------------------------
 */

static void
ArrangeGrid(
    void *clientData)	/* Structure describing container whose content
    ClientData clientData)	/* Structure describing master whose slaves
				 * are to be re-layed out. */
{
    Gridder *containerPtr = (Gridder *)clientData;
    Gridder *contentPtr;
    GridContainer *slotPtr = containerPtr->containerDataPtr;
    register Gridder *masterPtr = clientData;
    register Gridder *slavePtr;
    GridMaster *slotPtr = masterPtr->masterDataPtr;
    int abort;
    int width, height;		/* Requested size of layout, in pixels. */
    int realWidth, realHeight;	/* Actual size layout should take-up. */
    int usedX, usedY;

    containerPtr->flags &= ~REQUESTED_RELAYOUT;
    masterPtr->flags &= ~REQUESTED_RELAYOUT;

    /*
     * If the container has no content anymore, then don't change the container size.
     * Otherwise there is no way to "relinquish" control over the container
     * so another geometry manager can take over.
     * If the master has no slaves anymore, then don't do anything at all:
     * just leave the master's size as-is. Otherwise there is no way to
     * "relinquish" control over the master so another geometry manager can
     * take over.
     */

    if (containerPtr->contentPtr == NULL) {
    if (masterPtr->slavePtr == NULL) {
	return;
    }

    if (containerPtr->containerDataPtr == NULL) {
    if (masterPtr->masterDataPtr == NULL) {
	return;
    }

    /*
     * Abort any nested call to ArrangeGrid for this window, since we'll do
     * everything necessary here, and set up so this call can be aborted if
     * necessary.
     */

    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    containerPtr->abortPtr = &abort;
    masterPtr->abortPtr = &abort;
    abort = 0;
    Tcl_Preserve(containerPtr);
    Tcl_Preserve(masterPtr);

    /*
     * Call the constraint engine to fill in the row and column offsets.
     */

    SetGridSize(containerPtr);
    width = ResolveConstraints(containerPtr, COLUMN, 0);
    height = ResolveConstraints(containerPtr, ROW, 0);
    width += Tk_InternalBorderLeft(containerPtr->tkwin) +
	    Tk_InternalBorderRight(containerPtr->tkwin);
    height += Tk_InternalBorderTop(containerPtr->tkwin) +
	    Tk_InternalBorderBottom(containerPtr->tkwin);
    SetGridSize(masterPtr);
    width = ResolveConstraints(masterPtr, COLUMN, 0);
    height = ResolveConstraints(masterPtr, ROW, 0);
    width += Tk_InternalBorderLeft(masterPtr->tkwin) +
	    Tk_InternalBorderRight(masterPtr->tkwin);
    height += Tk_InternalBorderTop(masterPtr->tkwin) +
	    Tk_InternalBorderBottom(masterPtr->tkwin);

    if (width < Tk_MinReqWidth(containerPtr->tkwin)) {
	width = Tk_MinReqWidth(containerPtr->tkwin);
    if (width < Tk_MinReqWidth(masterPtr->tkwin)) {
	width = Tk_MinReqWidth(masterPtr->tkwin);
    }
    if (height < Tk_MinReqHeight(containerPtr->tkwin)) {
	height = Tk_MinReqHeight(containerPtr->tkwin);
    if (height < Tk_MinReqHeight(masterPtr->tkwin)) {
	height = Tk_MinReqHeight(masterPtr->tkwin);
    }

    if (((width != Tk_ReqWidth(containerPtr->tkwin))
	    || (height != Tk_ReqHeight(containerPtr->tkwin)))
	    && !(containerPtr->flags & DONT_PROPAGATE)) {
	Tk_GeometryRequest(containerPtr->tkwin, width, height);
    if (((width != Tk_ReqWidth(masterPtr->tkwin))
	    || (height != Tk_ReqHeight(masterPtr->tkwin)))
	    && !(masterPtr->flags & DONT_PROPAGATE)) {
	Tk_GeometryRequest(masterPtr->tkwin, width, height);
	if (width>1 && height>1) {
	    containerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
	containerPtr->abortPtr = NULL;
	Tcl_Release(containerPtr);
	masterPtr->abortPtr = NULL;
	Tcl_Release(masterPtr);
	return;
    }

    /*
     * If the currently requested layout size doesn't match the container's
     * If the currently requested layout size doesn't match the master's
     * window size, then adjust the slot offsets according to the weights. If
     * all of the weights are zero, place the layout according to the anchor
     * value.
     */

    realWidth = Tk_Width(containerPtr->tkwin) -
	    Tk_InternalBorderLeft(containerPtr->tkwin) -
	    Tk_InternalBorderRight(containerPtr->tkwin);
    realHeight = Tk_Height(containerPtr->tkwin) -
	    Tk_InternalBorderTop(containerPtr->tkwin) -
	    Tk_InternalBorderBottom(containerPtr->tkwin);
    realWidth = Tk_Width(masterPtr->tkwin) -
	    Tk_InternalBorderLeft(masterPtr->tkwin) -
	    Tk_InternalBorderRight(masterPtr->tkwin);
    realHeight = Tk_Height(masterPtr->tkwin) -
	    Tk_InternalBorderTop(masterPtr->tkwin) -
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    usedX = AdjustOffsets(realWidth,
	    MAX(slotPtr->columnEnd, slotPtr->columnMax), slotPtr->columnPtr);
    usedY = AdjustOffsets(realHeight, MAX(slotPtr->rowEnd, slotPtr->rowMax),
	    slotPtr->rowPtr);
    TkComputeAnchor(containerPtr->containerDataPtr->anchor, containerPtr->tkwin,
    TkComputeAnchor(masterPtr->masterDataPtr->anchor, masterPtr->tkwin,
	    0, 0, usedX, usedY, &slotPtr->startX, &slotPtr->startY);

    /*
     * Now adjust the actual size of the content to its cavity by computing the
     * Now adjust the actual size of the slave to its cavity by computing the
     * cavity size, and adjusting the widget according to its stickyness.
     */

    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL && !abort;
	    contentPtr = contentPtr->nextPtr) {
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL && !abort;
	    slavePtr = slavePtr->nextPtr) {
	int x, y;			/* Top left coordinate */
	int width, height;		/* Slot or slave size */
	int col = contentPtr->column;
	int row = contentPtr->row;
	int col = slavePtr->column;
	int row = slavePtr->row;

	x = (col>0) ? slotPtr->columnPtr[col-1].offset : 0;
	y = (row>0) ? slotPtr->rowPtr[row-1].offset : 0;

	width = slotPtr->columnPtr[contentPtr->numCols+col-1].offset - x;
	height = slotPtr->rowPtr[contentPtr->numRows+row-1].offset - y;
	width = slotPtr->columnPtr[slavePtr->numCols+col-1].offset - x;
	height = slotPtr->rowPtr[slavePtr->numRows+row-1].offset - y;

	x += slotPtr->startX;
	y += slotPtr->startY;

	AdjustForSticky(contentPtr, &x, &y, &width, &height);
	AdjustForSticky(slavePtr, &x, &y, &width, &height);

	/*
	 * Now put the window in the proper spot. (This was taken directly
	 * from tkPack.c.) If the content is a child of the container, then do this
	 * from tkPack.c.) If the slave is a child of the master, then do this
	 * here. Otherwise let Tk_MaintainGeometry do the work.
	 */

	if (containerPtr->tkwin == Tk_Parent(contentPtr->tkwin)) {
	if (masterPtr->tkwin == Tk_Parent(slavePtr->tkwin)) {
	    if ((width <= 0) || (height <= 0)) {
		Tk_UnmapWindow(contentPtr->tkwin);
		Tk_UnmapWindow(slavePtr->tkwin);
	    } else {
		if ((x != Tk_X(contentPtr->tkwin))
			|| (y != Tk_Y(contentPtr->tkwin))
			|| (width != Tk_Width(contentPtr->tkwin))
			|| (height != Tk_Height(contentPtr->tkwin))) {
		    Tk_MoveResizeWindow(contentPtr->tkwin, x, y, width, height);
		if ((x != Tk_X(slavePtr->tkwin))
			|| (y != Tk_Y(slavePtr->tkwin))
			|| (width != Tk_Width(slavePtr->tkwin))
			|| (height != Tk_Height(slavePtr->tkwin))) {
		    Tk_MoveResizeWindow(slavePtr->tkwin, x, y, width, height);
		}
		if (abort) {
		    break;
		}

		/*
		 * Don't map the content if the container isn't mapped: wait until
		 * the container gets mapped later.
		 * Don't map the slave if the master isn't mapped: wait until
		 * the master gets mapped later.
		 */

		if (Tk_IsMapped(containerPtr->tkwin)) {
		    Tk_MapWindow(contentPtr->tkwin);
		if (Tk_IsMapped(masterPtr->tkwin)) {
		    Tk_MapWindow(slavePtr->tkwin);
		}
	    }
	} else if ((width <= 0) || (height <= 0)) {
	    Tk_UnmaintainGeometry(contentPtr->tkwin, containerPtr->tkwin);
	    Tk_UnmapWindow(contentPtr->tkwin);
	    Tk_UnmaintainGeometry(slavePtr->tkwin, masterPtr->tkwin);
	    Tk_UnmapWindow(slavePtr->tkwin);
	} else {
	    Tk_MaintainGeometry(contentPtr->tkwin, containerPtr->tkwin, x, y,
	    Tk_MaintainGeometry(slavePtr->tkwin, masterPtr->tkwin, x, y,
		    width, height);
	}
    }

    containerPtr->abortPtr = NULL;
    Tcl_Release(containerPtr);
    masterPtr->abortPtr = NULL;
    Tcl_Release(masterPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ResolveConstraints --
 *
 *	Resolve all of the column and row boundaries. Most of the calculations
 *	are identical for rows and columns, so this procedure is called twice,
 *	once for rows, and again for columns.
 *
 * Results:
 *	The offset (in pixels) from the left/top edge of this layout is
 *	returned.
 *
 * Side effects:
 *	The slot offsets are copied into the SlotInfo structure for the
 *	geometry container.
 *	geometry master.
 *
 *----------------------------------------------------------------------
 */

static int
ResolveConstraints(
    Gridder *containerPtr,		/* The geometry container for this grid. */
    Gridder *masterPtr,		/* The geometry master for this grid. */
    int slotType,		/* Either ROW or COLUMN. */
    int maxOffset)		/* The actual maximum size of this layout in
				 * pixels, or 0 (not currently used). */
{
    SlotInfo *slotPtr;	/* Pointer to row/col constraints. */
    Gridder *contentPtr;	/* List of content windows in this grid. */
    register SlotInfo *slotPtr;	/* Pointer to row/col constraints. */
    register Gridder *slavePtr;	/* List of slave windows in this grid. */
    int constraintCount;	/* Count of rows or columns that have
				 * constraints. */
    int slotCount;		/* Last occupied row or column. */
    int gridCount;		/* The larger of slotCount and
				 * constraintCount. */
    GridLayout *layoutPtr;	/* Temporary layout structure. */
    int requiredSize;		/* The natural size of the grid (pixels).
				 * This is the minimum size needed to
				 * accommodate all of the content at their
				 * accomodate all of the slaves at their
				 * requested sizes. */
    int offset;			/* The pixel offset of the right edge of the
				 * current slot from the beginning of the
				 * layout. */
    int slot;			/* The current slot. */
    int start;			/* The first slot of a contiguous set whose
				 * constraints are not yet fully resolved. */
    int end;			/* The Last slot of a contiguous set whose
				 * constraints are not yet fully resolved. */
    UniformGroup uniformPre[UNIFORM_PREALLOC];
				/* Pre-allocated space for uniform groups. */
    UniformGroup *uniformGroupPtr;
				/* Uniform groups data. */
    int uniformGroups;		/* Number of currently used uniform groups. */
    int uniformGroupsAlloced;	/* Size of allocated space for uniform
				 * groups. */
    int minSize;
    int weight, minSize;
    int prevGrow, accWeight, grow;

    /*
     * For typical sized tables, we'll use stack space for the layout data to
     * avoid the overhead of a malloc and free for every layout.
     */

    GridLayout layoutData[TYPICAL_SIZE + 1];

    if (slotType == COLUMN) {
	constraintCount = containerPtr->containerDataPtr->columnMax;
	slotCount = containerPtr->containerDataPtr->columnEnd;
	slotPtr = containerPtr->containerDataPtr->columnPtr;
	constraintCount = masterPtr->masterDataPtr->columnMax;
	slotCount = masterPtr->masterDataPtr->columnEnd;
	slotPtr = masterPtr->masterDataPtr->columnPtr;
    } else {
	constraintCount = containerPtr->containerDataPtr->rowMax;
	slotCount = containerPtr->containerDataPtr->rowEnd;
	slotPtr = containerPtr->containerDataPtr->rowPtr;
	constraintCount = masterPtr->masterDataPtr->rowMax;
	slotCount = masterPtr->masterDataPtr->rowEnd;
	slotPtr = masterPtr->masterDataPtr->rowPtr;
    }

    /*
     * Make sure there is enough memory for the layout.
     */

    gridCount = MAX(constraintCount, slotCount);
    if (gridCount >= TYPICAL_SIZE) {
	layoutPtr = (GridLayout *)ckalloc(sizeof(GridLayout) * (1+gridCount));
	layoutPtr = ckalloc(sizeof(GridLayout) * (1+gridCount));
    } else {
	layoutPtr = layoutData;
    }

    /*
     * Allocate an extra layout slot to represent the left/top edge of the 0th
     * slot to make it easier to calculate slot widths from offsets without
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
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







-
-
+
+



-
+

-
+




-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+








-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+




















-



















-
+







	layoutPtr[slot].uniform = NULL;
	layoutPtr[slot].pad = 0;
	layoutPtr[slot].binNextPtr = NULL;
    }

    /*
     * Step 2.
     * Content with a span of 1 are used to determine the minimum size of each
     * slot. Content whose span is two or more slots don't contribute to the
     * Slaves with a span of 1 are used to determine the minimum size of each
     * slot. Slaves whose span is two or more slots don't contribute to the
     * minimum size of each slot directly, but can cause slots to grow if
     * their size exceeds the the sizes of the slots they span.
     *
     * Bin all content whose spans are > 1 by their right edges. This allows
     * Bin all slaves whose spans are > 1 by their right edges. This allows
     * the computation on minimum and maximum possible layout sizes at each
     * slot boundary, without the need to re-sort the content.
     * slot boundary, without the need to re-sort the slaves.
     */

    switch (slotType) {
    case COLUMN:
	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	    int rightEdge = contentPtr->column + contentPtr->numCols - 1;
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    int rightEdge = slavePtr->column + slavePtr->numCols - 1;

	    contentPtr->size = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->padX
		    + contentPtr->iPadX + contentPtr->doubleBw;
	    if (contentPtr->numCols > 1) {
		contentPtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = contentPtr;
	    slavePtr->size = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->padX
		    + slavePtr->iPadX + slavePtr->doubleBw;
	    if (slavePtr->numCols > 1) {
		slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = slavePtr;
	    } else if (rightEdge >= 0) {
		int size = contentPtr->size + layoutPtr[rightEdge].pad;
		int size = slavePtr->size + layoutPtr[rightEdge].pad;

		if (size > layoutPtr[rightEdge].minSize) {
		    layoutPtr[rightEdge].minSize = size;
		}
	    }
	}
	break;
    case ROW:
	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	    int rightEdge = contentPtr->row + contentPtr->numRows - 1;
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    int rightEdge = slavePtr->row + slavePtr->numRows - 1;

	    contentPtr->size = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->padY
		    + contentPtr->iPadY + contentPtr->doubleBw;
	    if (contentPtr->numRows > 1) {
		contentPtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = contentPtr;
	    slavePtr->size = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->padY
		    + slavePtr->iPadY + slavePtr->doubleBw;
	    if (slavePtr->numRows > 1) {
		slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = slavePtr;
	    } else if (rightEdge >= 0) {
		int size = contentPtr->size + layoutPtr[rightEdge].pad;
		int size = slavePtr->size + layoutPtr[rightEdge].pad;

		if (size > layoutPtr[rightEdge].minSize) {
		    layoutPtr[rightEdge].minSize = size;
		}
	    }
	}
	break;
    }

    /*
     * Step 2b.
     * Consider demands on uniform sizes.
     */

    uniformGroupPtr = uniformPre;
    uniformGroupsAlloced = UNIFORM_PREALLOC;
    uniformGroups = 0;

    for (slot = 0; slot < gridCount; slot++) {
	if (layoutPtr[slot].uniform != NULL) {
		int weight;
	    for (start = 0; start < uniformGroups; start++) {
		if (uniformGroupPtr[start].group == layoutPtr[slot].uniform) {
		    break;
		}
	    }
	    if (start >= uniformGroups) {
		/*
		 * Have not seen that group before, set up data for it.
		 */

		if (uniformGroups >= uniformGroupsAlloced) {
		    /*
		     * We need to allocate more space.
		     */

		    size_t oldSize = uniformGroupsAlloced
			    * sizeof(UniformGroup);
		    size_t newSize = (uniformGroupsAlloced + UNIFORM_PREALLOC)
			    * sizeof(UniformGroup);
		    UniformGroup *newUG = (UniformGroup *)ckalloc(newSize);
		    UniformGroup *newUG = ckalloc(newSize);
		    UniformGroup *oldUG = uniformGroupPtr;

		    memcpy(newUG, oldUG, oldSize);
		    if (oldUG != uniformPre) {
			ckfree(oldUG);
		    }
		    uniformGroupPtr = newUG;
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
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







-
+

















-
+




-
-
+
+

-
-
+
+










-
+




















-
-
+
+

-
-
+
+








    if (uniformGroups > 0) {
	for (slot = 0; slot < gridCount; slot++) {
	    if (layoutPtr[slot].uniform != NULL) {
		for (start = 0; start < uniformGroups; start++) {
		    if (uniformGroupPtr[start].group ==
			    layoutPtr[slot].uniform) {
			int weight = layoutPtr[slot].weight;
			weight = layoutPtr[slot].weight;
			weight = weight > 0 ? weight : 1;
			layoutPtr[slot].minSize =
				uniformGroupPtr[start].minSize * weight;
			break;
		    }
		}
	    }
	}
    }

    if (uniformGroupPtr != uniformPre) {
	ckfree(uniformGroupPtr);
    }

    /*
     * Step 3.
     * Determine the minimum slot offsets going from left to right that would
     * fit all of the content. This determines the minimum
     * fit all of the slaves. This determines the minimum
     */

    for (offset=0,slot=0; slot < gridCount; slot++) {
	layoutPtr[slot].minOffset = layoutPtr[slot].minSize + offset;
	for (contentPtr = layoutPtr[slot].binNextPtr; contentPtr != NULL;
		contentPtr = contentPtr->binNextPtr) {
	for (slavePtr = layoutPtr[slot].binNextPtr; slavePtr != NULL;
		slavePtr = slavePtr->binNextPtr) {
	    int span = (slotType == COLUMN) ?
		    contentPtr->numCols : contentPtr->numRows;
	    int required = contentPtr->size + layoutPtr[slot - span].minOffset;
		    slavePtr->numCols : slavePtr->numRows;
	    int required = slavePtr->size + layoutPtr[slot - span].minOffset;

	    if (required > layoutPtr[slot].minOffset) {
		layoutPtr[slot].minOffset = required;
	    }
	}
	offset = layoutPtr[slot].minOffset;
    }

    /*
     * At this point, we know the minimum required size of the entire layout.
     * It might be prudent to stop here if our "container" will resize itself to
     * It might be prudent to stop here if our "master" will resize itself to
     * this size.
     */

    requiredSize = offset;
    if (maxOffset > offset) {
	offset=maxOffset;
    }

    /*
     * Step 4.
     * Determine the minimum slot offsets going from right to left, bounding
     * the pixel range of each slot boundary. Pre-fill all of the right
     * offsets with the actual size of the table; they will be reduced as
     * required.
     */

    for (slot=0; slot < gridCount; slot++) {
	layoutPtr[slot].maxOffset = offset;
    }
    for (slot=gridCount-1; slot > 0;) {
	for (contentPtr = layoutPtr[slot].binNextPtr; contentPtr != NULL;
		contentPtr = contentPtr->binNextPtr) {
	for (slavePtr = layoutPtr[slot].binNextPtr; slavePtr != NULL;
		slavePtr = slavePtr->binNextPtr) {
	    int span = (slotType == COLUMN) ?
		    contentPtr->numCols : contentPtr->numRows;
	    int require = offset - contentPtr->size;
		    slavePtr->numCols : slavePtr->numRows;
	    int require = offset - slavePtr->size;
	    int startSlot = slot - span;

	    if (startSlot >=0 && require < layoutPtr[startSlot].maxOffset) {
		layoutPtr[startSlot].maxOffset = require;
	    }
	}
	offset -= layoutPtr[slot].minSize;
2393
2394
2395
2396
2397
2398
2399
2400

2401
2402
2403
2404
2405
2406
2407
2380
2381
2382
2383
2384
2385
2386

2387
2388
2389
2390
2391
2392
2393
2394







-
+







	    }
	}
    }

    /*
     * Step 6.
     * All of the space has been apportioned; copy the layout information back
     * into the container.
     * into the master.
     */

    for (slot=0; slot < gridCount; slot++) {
	slotPtr[slot].offset = layoutPtr[slot].minOffset;
    }

    --layoutPtr;
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
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







-
+
















-
+

-
+

-
-
+
+

-
+



















-
+











-
+





-
+

-
+






-
+

-
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+





-
+

-
+






-
+





-
+

-
+





-
-
+
+








-
-
+
+






-
+

-
+






-
+





-
+

-
+





-
-
+
+



-
+




-
-
+
+















-
+









-
-
+
+



-
+










-
+









-
-
-
+
+
+



-
-
+
+




-
+

-
-
+
+





-
-
+
+

-
-
+
+




-
+

-
+









-
+


-
+





-
+






-
-
+
+

-
-
-
+
+
+




-
+



-
+















-
+





-
+







-
+

-
+

-
-
+
+



-
-
+
+

-
-
+
+


-
-
+
+




-
-
-
+
+
+

-
-
+
+


-
-
+
+


-
+

-
-
-


-
-
-
+
+
+
-











-
+













-

-
-
-

-
+

-
-
-
-
-
-
+
+
+

-
-
+
+

-
+




















-
+






-
+



-
+



-
+




-
+

-
+

-
-
+
+



-
+

-
+


-
-
+
+
-
-
-
-
-
+
+
+
+


-
+




-
+

-
+





-
+

-
-
-
+
+
+







-
+


-
-
+
+







-
+





-
+


-
-
+
+





-
-
-
+
+
+
-







 */

static Gridder *
GetGrid(
    Tk_Window tkwin)		/* Token for window for which grid structure
				 * is desired. */
{
    Gridder *gridPtr;
    register Gridder *gridPtr;
    Tcl_HashEntry *hPtr;
    int isNew;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (!dispPtr->gridInit) {
	Tcl_InitHashTable(&dispPtr->gridHashTable, TCL_ONE_WORD_KEYS);
	dispPtr->gridInit = 1;
    }

    /*
     * See if there's already grid for this window. If not, then create a new
     * one.
     */

    hPtr = Tcl_CreateHashEntry(&dispPtr->gridHashTable, (char*) tkwin, &isNew);
    if (!isNew) {
	return (Gridder *)Tcl_GetHashValue(hPtr);
	return Tcl_GetHashValue(hPtr);
    }
    gridPtr = (Gridder *)ckalloc(sizeof(Gridder));
    gridPtr = ckalloc(sizeof(Gridder));
    gridPtr->tkwin = tkwin;
    gridPtr->containerPtr = NULL;
    gridPtr->containerDataPtr = NULL;
    gridPtr->masterPtr = NULL;
    gridPtr->masterDataPtr = NULL;
    gridPtr->nextPtr = NULL;
    gridPtr->contentPtr = NULL;
    gridPtr->slavePtr = NULL;
    gridPtr->binNextPtr = NULL;

    gridPtr->column = -1;
    gridPtr->row = -1;
    gridPtr->numCols = 1;
    gridPtr->numRows = 1;

    gridPtr->padX = 0;
    gridPtr->padY = 0;
    gridPtr->padLeft = 0;
    gridPtr->padTop = 0;
    gridPtr->iPadX = 0;
    gridPtr->iPadY = 0;
    gridPtr->doubleBw = 2 * Tk_Changes(tkwin)->border_width;
    gridPtr->abortPtr = NULL;
    gridPtr->flags = 0;
    gridPtr->sticky = 0;
    gridPtr->size = 0;
    gridPtr->in = NULL;
    gridPtr->containerDataPtr = NULL;
    gridPtr->masterDataPtr = NULL;
    Tcl_SetHashValue(hPtr, gridPtr);
    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
	    GridStructureProc, gridPtr);
    return gridPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * SetGridSize --
 *
 *	This internal procedure sets the size of the grid occupied by content.
 *	This internal procedure sets the size of the grid occupied by slaves.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The width and height arguments are filled in the container data
 *	The width and height arguments are filled in the master data
 *	structure. Additional space is allocated for the constraints to
 *	accommodate the offsets.
 *	accomodate the offsets.
 *
 *----------------------------------------------------------------------
 */

static void
SetGridSize(
    Gridder *containerPtr)		/* The geometry container for this grid. */
    Gridder *masterPtr)		/* The geometry master for this grid. */
{
    Gridder *contentPtr;	/* Current content window. */
    register Gridder *slavePtr;	/* Current slave window. */
    int maxX = 0, maxY = 0;

    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	maxX = MAX(maxX, contentPtr->numCols + contentPtr->column);
	maxY = MAX(maxY, contentPtr->numRows + contentPtr->row);
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	maxX = MAX(maxX, slavePtr->numCols + slavePtr->column);
	maxY = MAX(maxY, slavePtr->numRows + slavePtr->row);
    }
    containerPtr->containerDataPtr->columnEnd = maxX;
    containerPtr->containerDataPtr->rowEnd = maxY;
    CheckSlotData(containerPtr, maxX, COLUMN, CHECK_SPACE);
    CheckSlotData(containerPtr, maxY, ROW, CHECK_SPACE);
    masterPtr->masterDataPtr->columnEnd = maxX;
    masterPtr->masterDataPtr->rowEnd = maxY;
    CheckSlotData(masterPtr, maxX, COLUMN, CHECK_SPACE);
    CheckSlotData(masterPtr, maxY, ROW, CHECK_SPACE);
}

/*
 *----------------------------------------------------------------------
 *
 * SetContentColumn --
 * SetSlaveColumn --
 *
 *	Update column data for a content, checking that MAX_ELEMENT bound
 *	Update column data for a slave, checking that MAX_ELEMENT bound
 *      is not passed.
 *
 * Results:
 *	TCL_ERROR if out of bounds, TCL_OK otherwise
 *
 * Side effects:
 *	Content fields are updated.
 *	Slave fields are updated.
 *
 *----------------------------------------------------------------------
 */

static int
SetContentColumn(
SetSlaveColumn(
    Tcl_Interp *interp,		/* Interp for error message. */
    Gridder *contentPtr,		/* Content to be updated. */
    Gridder *slavePtr,		/* Slave to be updated. */
    int column,			/* New column or -1 to be unchanged. */
    int numCols)		/* New columnspan or -1 to be unchanged. */
{
    int newColumn, newNumCols, lastCol;

    newColumn = (column >= 0) ? column : contentPtr->column;
    newNumCols = (numCols >= 1) ? numCols : contentPtr->numCols;
    newColumn = (column >= 0) ? column : slavePtr->column;
    newNumCols = (numCols >= 1) ? numCols : slavePtr->numCols;

    lastCol = ((newColumn >= 0) ? newColumn : 0) + newNumCols;
    if (lastCol >= MAX_ELEMENT) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("column out of bounds",-1));
	Tcl_SetErrorCode(interp, "TK", "GRID", "BAD_COLUMN", NULL);
	return TCL_ERROR;
    }

    contentPtr->column = newColumn;
    contentPtr->numCols = newNumCols;
    slavePtr->column = newColumn;
    slavePtr->numCols = newNumCols;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * SetContentRow --
 * SetSlaveRow --
 *
 *	Update row data for a content, checking that MAX_ELEMENT bound
 *	Update row data for a slave, checking that MAX_ELEMENT bound
 *      is not passed.
 *
 * Results:
 *	TCL_ERROR if out of bounds, TCL_OK otherwise
 *
 * Side effects:
 *	Content fields are updated.
 *	Slave fields are updated.
 *
 *----------------------------------------------------------------------
 */

static int
SetContentRow(
SetSlaveRow(
    Tcl_Interp *interp,		/* Interp for error message. */
    Gridder *contentPtr,		/* Content to be updated. */
    Gridder *slavePtr,		/* Slave to be updated. */
    int row,			/* New row or -1 to be unchanged. */
    int numRows)		/* New rowspan or -1 to be unchanged. */
{
    int newRow, newNumRows, lastRow;

    newRow = (row >= 0) ? row : contentPtr->row;
    newNumRows = (numRows >= 1) ? numRows : contentPtr->numRows;
    newRow = (row >= 0) ? row : slavePtr->row;
    newNumRows = (numRows >= 1) ? numRows : slavePtr->numRows;

    lastRow = ((newRow >= 0) ? newRow : 0) + newNumRows;
    if (lastRow >= MAX_ELEMENT) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("row out of bounds", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("row out of bounds", -1));
	Tcl_SetErrorCode(interp, "TK", "GRID", "BAD_ROW", NULL);
	return TCL_ERROR;
    }

    contentPtr->row = newRow;
    contentPtr->numRows = newNumRows;
    slavePtr->row = newRow;
    slavePtr->numRows = newNumRows;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * CheckSlotData --
 *
 *	This internal procedure is used to manage the storage for row and
 *	column (slot) constraints.
 *
 * Results:
 *	TRUE if the index is OK, False otherwise.
 *
 * Side effects:
 *	A new container grid structure may be created. If so, then it is
 *	A new master grid structure may be created. If so, then it is
 *	initialized. In addition, additional storage for a row or column
 *	constraints may be allocated, and the constraint maximums are
 *	adjusted.
 *
 *----------------------------------------------------------------------
 */

static int
CheckSlotData(
    Gridder *containerPtr,		/* The geometry container for this grid. */
    Tcl_Size slot,			/* Which slot to look at. */
    Gridder *masterPtr,		/* The geometry master for this grid. */
    int slot,			/* Which slot to look at. */
    int slotType,		/* ROW or COLUMN. */
    int checkOnly)		/* Don't allocate new space if true. */
{
    Tcl_Size numSlot;		/* Number of slots already allocated (Space) */
    int numSlot;		/* Number of slots already allocated (Space) */
    int end;			/* Last used constraint. */

    /*
     * If slot is out of bounds, return immediately.
     */

    if (slot < 0 || slot >= MAX_ELEMENT) {
	return TCL_ERROR;
    }

    if ((checkOnly == CHECK_ONLY) && (containerPtr->containerDataPtr == NULL)) {
    if ((checkOnly == CHECK_ONLY) && (masterPtr->masterDataPtr == NULL)) {
	return TCL_ERROR;
    }

    /*
     * If we need to allocate more space, allocate a little extra to avoid
     * repeated re-alloc's for large tables. We need enough space to hold all
     * of the offsets as well.
     */

    InitContainerData(containerPtr);
    end = (slotType == ROW) ? containerPtr->containerDataPtr->rowMax :
	    containerPtr->containerDataPtr->columnMax;
    InitMasterData(masterPtr);
    end = (slotType == ROW) ? masterPtr->masterDataPtr->rowMax :
	    masterPtr->masterDataPtr->columnMax;
    if (checkOnly == CHECK_ONLY) {
    	return ((end < slot) ? TCL_ERROR : TCL_OK);
    } else {
    	numSlot = (slotType == ROW) ? containerPtr->containerDataPtr->rowSpace
		: containerPtr->containerDataPtr->columnSpace;
    	numSlot = (slotType == ROW) ? masterPtr->masterDataPtr->rowSpace
		: masterPtr->masterDataPtr->columnSpace;
    	if (slot >= numSlot) {
	    int newNumSlot = slot + PREALLOC;
	    size_t oldSize = numSlot * sizeof(SlotInfo);
	    size_t newSize = newNumSlot * sizeof(SlotInfo);
	    SlotInfo *newSI = (SlotInfo *)ckalloc(newSize);
	    SlotInfo *newSI = ckalloc(newSize);
	    SlotInfo *oldSI = (slotType == ROW)
		    ? containerPtr->containerDataPtr->rowPtr
		    : containerPtr->containerDataPtr->columnPtr;
		    ? masterPtr->masterDataPtr->rowPtr
		    : masterPtr->masterDataPtr->columnPtr;

	    memcpy(newSI, oldSI, oldSize);
	    memset(newSI+numSlot, 0, newSize - oldSize);
	    ckfree(oldSI);
	    if (slotType == ROW) {
	 	containerPtr->containerDataPtr->rowPtr = newSI;
	    	containerPtr->containerDataPtr->rowSpace = newNumSlot;
	 	masterPtr->masterDataPtr->rowPtr = newSI;
	    	masterPtr->masterDataPtr->rowSpace = newNumSlot;
	    } else {
	    	containerPtr->containerDataPtr->columnPtr = newSI;
	    	containerPtr->containerDataPtr->columnSpace = newNumSlot;
	    	masterPtr->masterDataPtr->columnPtr = newSI;
	    	masterPtr->masterDataPtr->columnSpace = newNumSlot;
	    }
	}
	if (slot >= end && checkOnly != CHECK_SPACE) {
	    if (slotType == ROW) {
		containerPtr->containerDataPtr->rowMax = slot+1;
		masterPtr->masterDataPtr->rowMax = slot+1;
	    } else {
		containerPtr->containerDataPtr->columnMax = slot+1;
		masterPtr->masterDataPtr->columnMax = slot+1;
	    }
	}
    	return TCL_OK;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * InitContainerData --
 * InitMasterData --
 *
 *	This internal procedure is used to allocate and initialize the data
 *	for a geometry container, if the data doesn't exist already.
 *	for a geometry master, if the data doesn't exist already.
 *
 * Results:
 *	none
 *
 * Side effects:
 *	A new container grid structure may be created. If so, then it is
 *	A new master grid structure may be created. If so, then it is
 *	initialized.
 *
 *----------------------------------------------------------------------
 */

static void
InitContainerData(
    Gridder *containerPtr)
InitMasterData(
    Gridder *masterPtr)
{
    if (containerPtr->containerDataPtr == NULL) {
	GridContainer *gridPtr = containerPtr->containerDataPtr = (GridContainer *)
		ckalloc(sizeof(GridContainer));
    if (masterPtr->masterDataPtr == NULL) {
	GridMaster *gridPtr = masterPtr->masterDataPtr =
		ckalloc(sizeof(GridMaster));
	size_t size = sizeof(SlotInfo) * TYPICAL_SIZE;

	gridPtr->columnEnd = 0;
	gridPtr->columnMax = 0;
	gridPtr->columnPtr = (SlotInfo *)ckalloc(size);
	gridPtr->columnPtr = ckalloc(size);
	gridPtr->columnSpace = TYPICAL_SIZE;
	gridPtr->rowEnd = 0;
	gridPtr->rowMax = 0;
	gridPtr->rowPtr = (SlotInfo *)ckalloc(size);
	gridPtr->rowPtr = ckalloc(size);
	gridPtr->rowSpace = TYPICAL_SIZE;
	gridPtr->startX = 0;
	gridPtr->startY = 0;
	gridPtr->anchor = GRID_DEFAULT_ANCHOR;

	memset(gridPtr->columnPtr, 0, size);
	memset(gridPtr->rowPtr, 0, size);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Unlink --
 *
 *	Remove a grid from its container's list of content.
 *	Remove a grid from its master's list of slaves.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The container will be scheduled for re-arranging, and the size of the
 *	The master will be scheduled for re-arranging, and the size of the
 *	grid will be adjusted accordingly
 *
 *----------------------------------------------------------------------
 */

static void
Unlink(
    Gridder *contentPtr)	/* Window to unlink. */
    register Gridder *slavePtr)	/* Window to unlink. */
{
    Gridder *containerPtr, *contentPtr2;
    register Gridder *masterPtr, *slavePtr2;

    containerPtr = contentPtr->containerPtr;
    if (containerPtr == NULL) {
    masterPtr = slavePtr->masterPtr;
    if (masterPtr == NULL) {
	return;
    }

    if (containerPtr->contentPtr == contentPtr) {
	containerPtr->contentPtr = contentPtr->nextPtr;
    if (masterPtr->slavePtr == slavePtr) {
	masterPtr->slavePtr = slavePtr->nextPtr;
    } else {
	for (contentPtr2=containerPtr->contentPtr ; ; contentPtr2=contentPtr2->nextPtr) {
	    if (contentPtr2 == NULL) {
	for (slavePtr2=masterPtr->slavePtr ; ; slavePtr2=slavePtr2->nextPtr) {
	    if (slavePtr2 == NULL) {
		Tcl_Panic("Unlink couldn't find previous window");
	    }
	    if (contentPtr2->nextPtr == contentPtr) {
		contentPtr2->nextPtr = contentPtr->nextPtr;
	    if (slavePtr2->nextPtr == slavePtr) {
		slavePtr2->nextPtr = slavePtr->nextPtr;
		break;
	    }
	}
    }
    if (!(containerPtr->flags & REQUESTED_RELAYOUT)) {
	containerPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
    if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	masterPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
    }
    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }

    SetGridSize(contentPtr->containerPtr);
    contentPtr->containerPtr = NULL;
    SetGridSize(slavePtr->masterPtr);
    slavePtr->masterPtr = NULL;

    /*
     * If we have emptied this container from content it means we are no longer
     * If we have emptied this master from slaves it means we are no longer
     * handling it and should mark it as free.
     *
     * Send the event "NoManagedChild" to the container to inform it about there
     * being no managed children inside it.
     */

    if ((containerPtr->contentPtr == NULL) && (containerPtr->flags & ALLOCED_CONTAINER)) {
	TkFreeGeometryContainer(containerPtr->tkwin, "grid");
	containerPtr->flags &= ~ALLOCED_CONTAINER;
    if ((masterPtr->slavePtr == NULL) && (masterPtr->flags & ALLOCED_MASTER)) {
	TkFreeGeometryMaster(masterPtr->tkwin, "grid");
	masterPtr->flags &= ~ALLOCED_MASTER;
	Tk_SendVirtualEvent(containerPtr->tkwin, "NoManagedChild", NULL);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyGrid --
 *
 *	This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
 *	clean up the internal structure of a grid at a safe time (when no-one
 *	is using it anymore). Cleaning up the grid involves freeing the main
 *	structure for all windows and the container structure for geometry
 *	structure for all windows and the master structure for geometry
 *	managers.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the grid is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyGrid(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about window that is now dead. */
#else
    char *memPtr)
#endif
{
    Gridder *gridPtr = (Gridder *)memPtr;
    register Gridder *gridPtr = memPtr;

    if (gridPtr->flags & REQUESTED_RELAYOUT) {
	Tcl_CancelIdleCall(ArrangeGrid, gridPtr);
    }
    if (gridPtr->containerDataPtr != NULL) {
	if (gridPtr->containerDataPtr->rowPtr != NULL) {
	    ckfree(gridPtr->containerDataPtr -> rowPtr);
    if (gridPtr->masterDataPtr != NULL) {
	if (gridPtr->masterDataPtr->rowPtr != NULL) {
	    ckfree(gridPtr->masterDataPtr -> rowPtr);
	}
	if (gridPtr->containerDataPtr->columnPtr != NULL) {
	    ckfree(gridPtr->containerDataPtr -> columnPtr);
	if (gridPtr->masterDataPtr->columnPtr != NULL) {
	    ckfree(gridPtr->masterDataPtr -> columnPtr);
	}
	ckfree(gridPtr->containerDataPtr);
	ckfree(gridPtr->masterDataPtr);
    }
    if (gridPtr->in != NULL) {
	Tcl_DecrRefCount(gridPtr->in);
    }
    ckfree(gridPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * GridStructureProc --
 *
 *	This procedure is invoked by the Tk event dispatcher in response to
 *	StructureNotify events.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	If a window was just deleted, clean up all its grid-related
 *	information. If it was just resized, re-configure its content, if any.
 *	information. If it was just resized, re-configure its slaves, if any.
 *
 *----------------------------------------------------------------------
 */

static void
GridStructureProc(
    void *clientData,	/* Our information about window referred to by
    ClientData clientData,	/* Our information about window referred to by
				 * eventPtr. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Gridder *gridPtr = (Gridder *)clientData;
    register Gridder *gridPtr = clientData;
    TkDisplay *dispPtr = ((TkWindow *) gridPtr->tkwin)->dispPtr;

    if (eventPtr->type == ConfigureNotify) {
	if ((gridPtr->contentPtr != NULL)
	if ((gridPtr->slavePtr != NULL)
		&& !(gridPtr->flags & REQUESTED_RELAYOUT)) {
	    gridPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, gridPtr);
	}
	if ((gridPtr->containerPtr != NULL) &&
	if ((gridPtr->masterPtr != NULL) &&
		(gridPtr->doubleBw != 2*Tk_Changes(gridPtr->tkwin)->border_width)) {
	    if (!(gridPtr->containerPtr->flags & REQUESTED_RELAYOUT)) {
	    if (!(gridPtr->masterPtr->flags & REQUESTED_RELAYOUT)) {
		gridPtr->doubleBw = 2*Tk_Changes(gridPtr->tkwin)->border_width;
		gridPtr->containerPtr->flags |= REQUESTED_RELAYOUT;
		Tcl_DoWhenIdle(ArrangeGrid, gridPtr->containerPtr);
		gridPtr->masterPtr->flags |= REQUESTED_RELAYOUT;
		Tcl_DoWhenIdle(ArrangeGrid, gridPtr->masterPtr);
	    }
	}
    } else if (eventPtr->type == DestroyNotify) {
	Gridder *contentPtr, *nextPtr;
	register Gridder *gridPtr2, *nextPtr;

	if (gridPtr->containerPtr != NULL) {
	if (gridPtr->masterPtr != NULL) {
	    Unlink(gridPtr);
	}
	for (contentPtr = gridPtr->contentPtr; contentPtr != NULL;
		contentPtr = nextPtr) {
	for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL;
		gridPtr2 = nextPtr) {
	    Tk_ManageGeometry(contentPtr->tkwin, NULL, NULL);
	    Tk_UnmapWindow(contentPtr->tkwin);
	    contentPtr->containerPtr = NULL;
	    nextPtr = contentPtr->nextPtr;
	    contentPtr->nextPtr = NULL;
	    Tk_UnmapWindow(gridPtr2->tkwin);
	    gridPtr2->masterPtr = NULL;
	    nextPtr = gridPtr2->nextPtr;
	    gridPtr2->nextPtr = NULL;
	}
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->gridHashTable,
		gridPtr->tkwin));
		(char *) gridPtr->tkwin));
	if (gridPtr->flags & REQUESTED_RELAYOUT) {
	    Tcl_CancelIdleCall(ArrangeGrid, gridPtr);
	}
	gridPtr->tkwin = NULL;
	Tcl_EventuallyFree(gridPtr, DestroyGrid);
	Tcl_EventuallyFree(gridPtr, (Tcl_FreeProc *)DestroyGrid);
    } else if (eventPtr->type == MapNotify) {
	if ((gridPtr->contentPtr != NULL)
	if ((gridPtr->slavePtr != NULL)
		&& !(gridPtr->flags & REQUESTED_RELAYOUT)) {
	    gridPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, gridPtr);
	}
    } else if (eventPtr->type == UnmapNotify) {
	Gridder *contentPtr;
	register Gridder *gridPtr2;

	for (contentPtr = gridPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	    Tk_UnmapWindow(contentPtr->tkwin);
	for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL;
		gridPtr2 = gridPtr2->nextPtr) {
	    Tk_UnmapWindow(gridPtr2->tkwin);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigureContent --
 * ConfigureSlaves --
 *
 *	This implements the guts of the "grid configure" command. Given a list
 *	of content and configuration options, it arranges for the grid to
 *	manage the content and sets the specified options. Arguments consist
 *	of slaves and configuration options, it arranges for the grid to
 *	manage the slaves and sets the specified options. Arguments consist
 *	of windows or window shortcuts followed by "-option value" pairs.
 *
 * Results:
 *	TCL_OK is returned if all went well. Otherwise, TCL_ERROR is returned
 *	and the interp's result is set to contain an error message.
 *
 * Side effects:
 *	Content windows get taken over by the grid.
 *	Slave windows get taken over by the grid.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureContent(
ConfigureSlaves(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Any window in application containing
				 * content. Used to look up content names. */
    Tcl_Size objc,			/* Number of elements in argv. */
				 * slaves. Used to look up slave names. */
    int objc,			/* Number of elements in argv. */
    Tcl_Obj *const objv[])	/* Argument objects: contains one or more
				 * window names followed by any number of
				 * "option value" pairs. Caller must make sure
				 * that there is at least one window name. */
{
    Gridder *containerPtr = NULL;
    Gridder *contentPtr;
    Tk_Window other, content, parent, ancestor;
    Gridder *masterPtr = NULL;
    Gridder *slavePtr;
    Tk_Window other, slave, parent, ancestor;
    TkWindow *container;
    int i, j, tmp;
    int numWindows;
    int width;
    int defaultRow = -1;
    int defaultColumn = 0;	/* Default column number */
    int defaultColumnSpan = 1;	/* Default number of columns */
    const char *lastWindow;	/* Use this window to base current row/col
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
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







-
+







-
+



-
+


-
+

-
+

-
+


-
-
-
+
+
+

-
-
+
+



-
-
+
+

-
-
+
+








    /*
     * Count the number of windows, or window short-cuts.
     */

    firstChar = 0;
    for (numWindows=0, i=0; i < objc; i++) {
	Tcl_Size length;
	int length;
	char prevChar = firstChar;

	string = Tcl_GetStringFromObj(objv[i], &length);
    	firstChar = string[0];

	if (firstChar == '.') {
	    /*
	     * Check that windows are valid, and locate the first content's
	     * Check that windows are valid, and locate the first slave's
	     * parent window (default for -in).
	     */

	    if (TkGetWindowFromObj(interp, tkwin, objv[i], &content) != TCL_OK) {
	    if (TkGetWindowFromObj(interp, tkwin, objv[i], &slave) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (containerPtr == NULL) {
	    if (masterPtr == NULL) {
		/*
		 * Is there any saved -in from a removed content?
		 * Is there any saved -in from a removed slave?
		 * If there is, it becomes default for -in.
		 * If the stored container does not exist, just ignore it.
		 * If the stored master does not exist, just ignore it.
		 */

		contentPtr = GetGrid(content);
		if (contentPtr->in != NULL) {
		    if (TkGetWindowFromObj(interp, content, contentPtr->in, &parent)
		struct Gridder *slavePtr = GetGrid(slave);
		if (slavePtr->in != NULL) {
		    if (TkGetWindowFromObj(interp, slave, slavePtr->in, &parent)
			    == TCL_OK) {
			containerPtr = GetGrid(parent);
			InitContainerData(containerPtr);
			masterPtr = GetGrid(parent);
			InitMasterData(masterPtr);
		    }
		}
	    }
	    if (containerPtr == NULL) {
		parent = Tk_Parent(content);
	    if (masterPtr == NULL) {
		parent = Tk_Parent(slave);
		if (parent != NULL) {
		    containerPtr = GetGrid(parent);
		    InitContainerData(containerPtr);
		    masterPtr = GetGrid(parent);
		    InitMasterData(masterPtr);
		}
	    }
	    numWindows++;
	    continue;
    	}
	if (length > 1 && i == 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
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
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







-
+



















-
+







	    Tcl_SetErrorCode(interp, "TK", "GRID", "BAD_PARAMETER", NULL);
	    return TCL_ERROR;
	}

	if ((firstChar == REL_HORIZ) && ((numWindows == 0) ||
		(prevChar == REL_SKIP) || (prevChar == REL_VERT))) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "must specify window before shortcut '-'", TCL_INDEX_NONE));
		    "must specify window before shortcut '-'", -1));
	    Tcl_SetErrorCode(interp, "TK", "GRID", "SHORTCUT_USAGE", NULL);
	    return TCL_ERROR;
	}

	if ((firstChar == REL_VERT) || (firstChar == REL_SKIP)
		|| (firstChar == REL_HORIZ)) {
	    continue;
	}

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"invalid window shortcut, \"%s\" should be '-', 'x', or '^'",
		string));
	Tcl_SetErrorCode(interp, "TK", "GRID", "SHORTCUT_USAGE", NULL);
	return TCL_ERROR;
    }
    numWindows = i;

    if ((objc - numWindows) & 1) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"extra option or option with no value", TCL_INDEX_NONE));
		"extra option or option with no value", -1));
	Tcl_SetErrorCode(interp, "TK", "GRID", "BAD_PARAMETER", NULL);
	return TCL_ERROR;
    }

    /*
     * Go through all options looking for -in and -row, which are needed to be
     * found first to handle the special case where ^ is used on a row without
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
3171
3172
3173

3174
3175
3176
3177
3178

3179
3180
3181
3182

3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203

3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216

3217
3218
3219
3220
3221
3222
3223
3224
3225

3226
3227

3228
3229
3230
3231
3232
3233


3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246

3247
3248
3249
3250

3251
3252
3253
3254
3255
3256
3257
3258

3259
3260
3261

3262
3263
3264
3265
3266
3267
3268
3269

3270
3271
3272
3273

3274
3275
3276
3277
3278
3279

3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292

3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305

3306
3307
3308
3309
3310
3311
3312
3313

3314
3315
3316
3317
3318


3319
3320
3321
3322
3323
3324
3325
3326
3327

3328
3329
3330
3331
3332

3333
3334

3335
3336
3337
3338
3339
3340




3341
3342
3343
3344
3345



3346
3347
3348


3349
3350
3351
3352


3353
3354
3355
3356



3357
3358
3359
3360
3361


3362
3363
3364
3365

3366
3367
3368
3369
3370
3371
3372


3373
3374

3375
3376
3377
3378
3379
3380

3381
3382
3383

3384
3385
3386
3387
3388
3389
3390
3391
3392
3393








3394
3395
3396
3397
3398

3399
3400
3401


3402
3403
3404


3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3415


3416
3417
3418
3419
3420


3421
3422
3423
3424


3425
3426
3427
3428

3429
3430
3431
3432

3433
3434
3435
3436
3437


3438
3439
3440
3441



3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457

3458
3459

3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470

3471
3472

3473
3474
3475
3476
3477
3478
3479
3480
3481
3482

3483
3484
3485
3486
3487
3488
3489
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
3171
3172
3173
3174
3175

3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188

3189
3190
3191
3192
3193
3194
3195
3196
3197

3198
3199

3200
3201
3202
3203
3204


3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218

3219
3220
3221
3222

3223
3224
3225
3226
3227
3228
3229
3230

3231
3232
3233

3234
3235
3236
3237
3238
3239
3240
3241

3242
3243
3244
3245

3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264

3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277

3278
3279
3280
3281
3282
3283
3284
3285

3286
3287
3288
3289


3290
3291
3292
3293
3294
3295
3296
3297
3298
3299

3300
3301
3302
3303
3304

3305
3306

3307
3308
3309




3310
3311
3312
3313
3314
3315



3316
3317
3318
3319


3320
3321
3322
3323


3324
3325
3326



3327
3328
3329
3330
3331
3332


3333
3334
3335
3336
3337

3338
3339
3340
3341
3342
3343


3344
3345
3346

3347
3348
3349
3350
3351
3352

3353
3354
3355

3356










3357
3358
3359
3360
3361
3362
3363
3364





3365
3366


3367
3368
3369


3370
3371
3372
3373

3374
3375
3376
3377
3378
3379
3380


3381
3382
3383
3384
3385


3386
3387
3388
3389


3390
3391
3392
3393
3394

3395
3396
3397
3398

3399
3400
3401
3402


3403
3404
3405



3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423

3424
3425

3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436

3437
3438

3439
3440
3441
3442
3443
3444
3445
3446
3447
3448

3449
3450
3451
3452
3453
3454
3455
3456







-
-
+
+














-
+
-



-
-
-
+
+
+






-
-
-
-
+
+
+
+












-
+












-
+






-
+



-
+






-
+




-
+



-
+




















-
+












-
+








-
+

-
+




-
-
+
+












-
+



-
+







-
+


-
+







-
+



-
+





-
+












-
+












-
+







-
+



-
-
+
+








-
+




-
+

-
+


-
-
-
-
+
+
+
+


-
-
-
+
+
+

-
-
+
+


-
-
+
+

-
-
-
+
+
+



-
-
+
+



-
+





-
-
+
+

-
+





-
+


-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+

-
-
+
+

-
-
+
+


-
+






-
-
+
+



-
-
+
+


-
-
+
+



-
+



-
+



-
-
+
+

-
-
-
+
+
+















-
+

-
+










-
+

-
+









-
+







	    return TCL_ERROR;
	}
	if (index == CONF_IN) {
	    if (TkGetWindowFromObj(interp, tkwin, objv[i+1], &other) !=
		    TCL_OK) {
		return TCL_ERROR;
	    }
	    containerPtr = GetGrid(other);
	    InitContainerData(containerPtr);
	    masterPtr = GetGrid(other);
	    InitMasterData(masterPtr);
	} else if (index == CONF_ROW) {
	    if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK
		    || tmp < 0) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad row value \"%s\": must be a non-negative integer",
			Tcl_GetString(objv[i+1])));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "POSITIVE_INT", NULL);
		return TCL_ERROR;
	    }
	    defaultRow = tmp;
	}
    }

    /*
     * If no -row is given, use the next row after the highest occupied row
     * If no -row is given, use the first unoccupied row of the master.
     * of the container.
     */

    if (defaultRow < 0) {
	if (containerPtr != NULL && containerPtr->containerDataPtr != NULL) {
	    SetGridSize(containerPtr);
	    defaultRow = containerPtr->containerDataPtr->rowEnd;
	if (masterPtr != NULL && masterPtr->masterDataPtr != NULL) {
	    SetGridSize(masterPtr);
	    defaultRow = masterPtr->masterDataPtr->rowEnd;
	} else {
	    defaultRow = 0;
	}
    }

    /*
     * Iterate over all of the content windows and short-cuts, parsing options
     * for each content. It's a bit wasteful to re-parse the options for each
     * content, but things get too messy if we try to parse the arguments just
     * once at the beginning. For example, if a content already is managed we
     * Iterate over all of the slave windows and short-cuts, parsing options
     * for each slave. It's a bit wasteful to re-parse the options for each
     * slave, but things get too messy if we try to parse the arguments just
     * once at the beginning. For example, if a slave already is managed we
     * want to just change a few existing values without resetting everything.
     * If there are multiple windows, the -in option only gets processed for
     * the first window.
     */

    positionGiven = 0;
    for (j = 0; j < numWindows; j++) {
	string = Tcl_GetString(objv[j]);
    	firstChar = string[0];

	/*
	 * '^' and 'x' cause us to skip a column. '-' is processed as part of
	 * its preceeding content.
	 * its preceeding slave.
	 */

	if ((firstChar == REL_VERT) || (firstChar == REL_SKIP)) {
	    defaultColumn++;
	    continue;
	}
	if (firstChar == REL_HORIZ) {
	    continue;
	}

	for (defaultColumnSpan = 1; j + defaultColumnSpan < numWindows;
		defaultColumnSpan++) {
	    string = Tcl_GetString(objv[j + defaultColumnSpan]);
	    const char *string = Tcl_GetString(objv[j + defaultColumnSpan]);

	    if (*string != REL_HORIZ) {
		break;
	    }
	}

	if (TkGetWindowFromObj(interp, tkwin, objv[j], &content) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[j], &slave) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (Tk_TopWinHierarchy(content)) {
	if (Tk_TopWinHierarchy(slave)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't manage \"%s\": it's a top-level window",
		    Tcl_GetString(objv[j])));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", NULL);
	    return TCL_ERROR;
	}
	contentPtr = GetGrid(content);
	slavePtr = GetGrid(slave);

	/*
	 * The following statement is taken from tkPack.c:
	 *
	 * "If the content isn't currently managed, reset all of its
	 * "If the slave isn't currently managed, reset all of its
	 * configuration information to default values (there could be old
	 * values left from a previous packer)."
	 *
	 * I [D.S.] disagree with this statement. If a content is disabled
	 * I [D.S.] disagree with this statement. If a slave is disabled
	 * (using "forget") and then re-enabled, I submit that 90% of the time
	 * the programmer will want it to retain its old configuration
	 * information. If the programmer doesn't want this behavior, then the
	 * defaults can be reestablished by hand, without having to worry
	 * about keeping track of the old state.
	 */

	for (i = numWindows; i < objc; i += 2) {
	    Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
		    sizeof(char *), "option", 0, &index);
	    switch ((enum options) index) {
	    case CONF_COLUMN:
		if (Tcl_GetIntFromObj(NULL, objv[i+1], &tmp) != TCL_OK
			|| tmp < 0) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad column value \"%s\": must be a non-negative integer",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "COLUMN", NULL);
		    return TCL_ERROR;
		}
		if (SetContentColumn(interp, contentPtr, tmp, -1) != TCL_OK) {
		if (SetSlaveColumn(interp, slavePtr, tmp, -1) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_COLUMNSPAN:
		if (Tcl_GetIntFromObj(NULL, objv[i+1], &tmp) != TCL_OK
			|| tmp <= 0) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad columnspan value \"%s\": must be a positive integer",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "SPAN", NULL);
		    return TCL_ERROR;
		}
		if (SetContentColumn(interp, contentPtr, -1, tmp) != TCL_OK) {
		if (SetSlaveColumn(interp, slavePtr, -1, tmp) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_IN:
		if (TkGetWindowFromObj(interp, tkwin, objv[i+1],
			&other) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (other == content) {
		if (other == slave) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "window can't be managed in itself", TCL_INDEX_NONE));
			    "window can't be managed in itself", -1));
		    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "SELF", NULL);
		    return TCL_ERROR;
		}
		positionGiven = 1;
		containerPtr = GetGrid(other);
		InitContainerData(containerPtr);
		masterPtr = GetGrid(other);
		InitMasterData(masterPtr);
		break;
	    case CONF_STICKY: {
		int sticky = StringToSticky(Tcl_GetString(objv[i+1]));

		if (sticky == -1) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad stickyness value \"%s\": must be"
			    " a string containing n, e, s, and/or w",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "STICKY", NULL);
		    return TCL_ERROR;
		}
		contentPtr->sticky = sticky;
		slavePtr->sticky = sticky;
		break;
	    }
	    case CONF_IPADX:
		if ((Tk_GetPixelsFromObj(NULL, content, objv[i+1],
		if ((Tk_GetPixelsFromObj(NULL, slave, objv[i+1],
			&tmp) != TCL_OK) || (tmp < 0)) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad ipadx value \"%s\": must be positive screen distance",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL);
		    return TCL_ERROR;
		}
		contentPtr->iPadX = tmp * 2;
		slavePtr->iPadX = tmp * 2;
		break;
	    case CONF_IPADY:
		if ((Tk_GetPixelsFromObj(NULL, content, objv[i+1],
		if ((Tk_GetPixelsFromObj(NULL, slave, objv[i+1],
			&tmp) != TCL_OK) || (tmp < 0)) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad ipady value \"%s\": must be positive screen distance",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL);
		    return TCL_ERROR;
		}
		contentPtr->iPadY = tmp * 2;
		slavePtr->iPadY = tmp * 2;
		break;
	    case CONF_PADX:
		if (TkParsePadAmount(interp, tkwin, objv[i+1],
			&contentPtr->padLeft, &contentPtr->padX) != TCL_OK) {
			&slavePtr->padLeft, &slavePtr->padX) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_PADY:
		if (TkParsePadAmount(interp, tkwin, objv[i+1],
			&contentPtr->padTop, &contentPtr->padY) != TCL_OK) {
			&slavePtr->padTop, &slavePtr->padY) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_ROW:
		if (Tcl_GetIntFromObj(NULL, objv[i+1], &tmp) != TCL_OK
			|| tmp < 0) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad row value \"%s\": must be a non-negative integer",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "COLUMN", NULL);
		    return TCL_ERROR;
		}
		if (SetContentRow(interp, contentPtr, tmp, -1) != TCL_OK) {
		if (SetSlaveRow(interp, slavePtr, tmp, -1) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_ROWSPAN:
		if ((Tcl_GetIntFromObj(NULL, objv[i+1], &tmp) != TCL_OK)
			|| tmp <= 0) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad rowspan value \"%s\": must be a positive integer",
			    Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "SPAN", NULL);
		    return TCL_ERROR;
		}
		if (SetContentRow(interp, contentPtr, -1, tmp) != TCL_OK) {
		if (SetSlaveRow(interp, slavePtr, -1, tmp) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    }
	}

	/*
	 * If no position was specified via -in and the content is already
	 * If no position was specified via -in and the slave is already
	 * packed, then leave it in its current location.
	 */

    	if (!positionGiven && (contentPtr->containerPtr != NULL)) {
	    containerPtr = contentPtr->containerPtr;
    	if (!positionGiven && (slavePtr->masterPtr != NULL)) {
	    masterPtr = slavePtr->masterPtr;
	    goto scheduleLayout;
    	}

	/*
	 * If the same -in window is passed in again, then just leave it in
	 * its current location.
	 */

	if (positionGiven && (containerPtr == contentPtr->containerPtr)) {
	if (positionGiven && (masterPtr == slavePtr->masterPtr)) {
	    goto scheduleLayout;
	}

	/*
	 * Make sure we have a geometry container. We look at:
	 * Make sure we have a geometry master. We look at:
	 *  1)   the -in flag
	 *  2)   the parent of the first content.
	 *  2)   the parent of the first slave.
	 */

	parent = Tk_Parent(content);
    	if (containerPtr == NULL) {
	    containerPtr = GetGrid(parent);
	    InitContainerData(containerPtr);
	parent = Tk_Parent(slave);
    	if (masterPtr == NULL) {
	    masterPtr = GetGrid(parent);
	    InitMasterData(masterPtr);
    	}

	if (contentPtr->containerPtr != NULL && contentPtr->containerPtr != containerPtr) {
            if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
                Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
	if (slavePtr->masterPtr != NULL && slavePtr->masterPtr != masterPtr) {
            if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
                Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
            }
	    Unlink(contentPtr);
	    contentPtr->containerPtr = NULL;
	    Unlink(slavePtr);
	    slavePtr->masterPtr = NULL;
	}

	if (contentPtr->containerPtr == NULL) {
	    Gridder *tempPtr = containerPtr->contentPtr;
	if (slavePtr->masterPtr == NULL) {
	    Gridder *tempPtr = masterPtr->slavePtr;

	    contentPtr->containerPtr = containerPtr;
	    containerPtr->contentPtr = contentPtr;
	    contentPtr->nextPtr = tempPtr;
	    slavePtr->masterPtr = masterPtr;
	    masterPtr->slavePtr = slavePtr;
	    slavePtr->nextPtr = tempPtr;
	}

	/*
	 * Make sure that the content's parent is either the container or an
	 * ancestor of the container, and that the container and content aren't the
	 * Make sure that the slave's parent is either the master or an
	 * ancestor of the master, and that the master and slave aren't the
	 * same.
	 */

	for (ancestor = containerPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	for (ancestor = masterPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == parent) {
		break;
	    }
	    if (Tk_TopWinHierarchy(ancestor)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't put \"%s\" inside \"%s\"", Tcl_GetString(objv[j]),
			Tk_PathName(containerPtr->tkwin)));
			"can't put %s inside %s", Tcl_GetString(objv[j]),
			Tk_PathName(masterPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
		Unlink(contentPtr);
		Unlink(slavePtr);
		return TCL_ERROR;
	    }
	}

	/*
	 * Check for management loops.
	 * Try to make sure our master isn't managed by us.
	 */

	for (container = (TkWindow *)containerPtr->tkwin; container != NULL;
     	if (masterPtr->masterPtr == slavePtr) {
	     container = (TkWindow *)TkGetContainer(container)) {
	    if (container == (TkWindow *)content) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't put \"%s\" inside \"%s\": would cause management loop",
	            Tcl_GetString(objv[j]), Tk_PathName(containerPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL);
		Unlink(contentPtr);
		return TCL_ERROR;
	    }
	}
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't put %s inside %s, would cause management loop",
		    Tcl_GetString(objv[j]), Tk_PathName(masterPtr->tkwin)));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL);
	    Unlink(slavePtr);
	    return TCL_ERROR;
     	}

	if (containerPtr->tkwin != Tk_Parent(content)) {
	    ((TkWindow *)content)->maintainerPtr = (TkWindow *)containerPtr->tkwin;
	}

	Tk_ManageGeometry(content, &gridMgrType, contentPtr);
	Tk_ManageGeometry(slave, &gridMgrType, slavePtr);

	if (!(containerPtr->flags & DONT_PROPAGATE)) {
	    if (TkSetGeometryContainer(interp, containerPtr->tkwin, "grid")
	if (!(masterPtr->flags & DONT_PROPAGATE)) {
	    if (TkSetGeometryMaster(interp, masterPtr->tkwin, "grid")
		    != TCL_OK) {
		Tk_ManageGeometry(content, NULL, NULL);
		Unlink(contentPtr);
		Tk_ManageGeometry(slave, NULL, NULL);
		Unlink(slavePtr);
		return TCL_ERROR;
	    }
	    containerPtr->flags |= ALLOCED_CONTAINER;
	    masterPtr->flags |= ALLOCED_MASTER;
	}

	/*
	 * Assign default position information.
	 */

	if (contentPtr->column == -1) {
	    if (SetContentColumn(interp, contentPtr, defaultColumn,-1) != TCL_OK){
	if (slavePtr->column == -1) {
	    if (SetSlaveColumn(interp, slavePtr, defaultColumn,-1) != TCL_OK){
		return TCL_ERROR;
	    }
	}
	if (SetContentColumn(interp, contentPtr, -1,
		contentPtr->numCols + defaultColumnSpan - 1) != TCL_OK) {
	if (SetSlaveColumn(interp, slavePtr, -1,
		slavePtr->numCols + defaultColumnSpan - 1) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (contentPtr->row == -1) {
	    if (SetContentRow(interp, contentPtr, defaultRow, -1) != TCL_OK) {
	if (slavePtr->row == -1) {
	    if (SetSlaveRow(interp, slavePtr, defaultRow, -1) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	defaultColumn += contentPtr->numCols;
	defaultColumn += slavePtr->numCols;
	defaultColumnSpan = 1;

	/*
	 * Arrange for the container to be re-arranged at the first idle moment.
	 * Arrange for the master to be re-arranged at the first idle moment.
	 */

    scheduleLayout:
	if (containerPtr->abortPtr != NULL) {
	    *containerPtr->abortPtr = 1;
	if (masterPtr->abortPtr != NULL) {
	    *masterPtr->abortPtr = 1;
	}
	if (!(containerPtr->flags & REQUESTED_RELAYOUT)) {
	    containerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, containerPtr);
	if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
    }

    /*
     * Now look for all the "^"'s.
     */

    lastWindow = NULL;
    numSkip = 0;
    for (j = 0; j < numWindows; j++) {
	struct Gridder *otherPtr;
	int match;			/* Found a match for the ^ */
	int lastRow, lastColumn;	/* Implied end of table. */

	string = Tcl_GetString(objv[j]);
	firstChar = string[0];
    	firstChar = string[0];

	if (firstChar == '.') {
    	if (firstChar == '.') {
	    lastWindow = string;
	    numSkip = 0;
	}
	if (firstChar == REL_SKIP) {
	    numSkip++;
	}
	if (firstChar != REL_VERT) {
	    continue;
	}

	if (containerPtr == NULL) {
	if (masterPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't use '^', can't find container window", TCL_INDEX_NONE));
		    "can't use '^', cant find master", -1));
	    Tcl_SetErrorCode(interp, "TK", "GRID", "SHORTCUT_USAGE", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Count the number of consecutive ^'s starting from this position.
	 */

	for (width = 1; width + j < numWindows; width++) {
	    string = Tcl_GetString(objv[j+width]);
	    const char *string = Tcl_GetString(objv[j+width]);

	    if (*string != REL_VERT) {
		break;
	    }
	}

	/*
3499
3500
3501
3502
3503
3504
3505
3506
3507


3508
3509
3510
3511
3512
3513





3514
3515
3516
3517
3518


3519
3520
3521
3522
3523
3524
3525
3526

3527
3528
3529
3530
3531
3532

3533
3534

3535
3536
3537
3538

3539
3540
3541

3542
3543
3544
3545
3546
3547
3548
3549
3550



3551
3552
3553
3554
3555
3556
3557
3558
3466
3467
3468
3469
3470
3471
3472


3473
3474
3475





3476
3477
3478
3479
3480
3481
3482
3483


3484
3485
3486
3487
3488
3489
3490
3491
3492

3493
3494
3495
3496
3497
3498

3499
3500

3501
3502
3503
3504

3505
3506
3507

3508
3509



3510
3511



3512
3513
3514

3515
3516
3517
3518
3519
3520
3521







-
-
+
+

-
-
-
-
-
+
+
+
+
+



-
-
+
+







-
+





-
+

-
+



-
+


-
+

-
-
-


-
-
-
+
+
+
-







	    lastRow = otherPtr->row + otherPtr->numRows - 2;
	    lastColumn = otherPtr->column + otherPtr->numCols;
	}

	lastColumn += numSkip;

	match = 0;
	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {

	    if (contentPtr->column == lastColumn
		    && contentPtr->row + contentPtr->numRows - 1 == lastRow) {
		if (contentPtr->numCols <= width) {
		    if (SetContentRow(interp, contentPtr, -1,
			    contentPtr->numRows + 1) != TCL_OK) {
	    if (slavePtr->column == lastColumn
		    && slavePtr->row + slavePtr->numRows - 1 == lastRow) {
		if (slavePtr->numCols <= width) {
		    if (SetSlaveRow(interp, slavePtr, -1,
			    slavePtr->numRows + 1) != TCL_OK) {
			return TCL_ERROR;
		    }
		    match++;
		    j += contentPtr->numCols - 1;
		    lastWindow = Tk_PathName(contentPtr->tkwin);
		    j += slavePtr->numCols - 1;
		    lastWindow = Tk_PathName(slavePtr->tkwin);
		    numSkip = 0;
		    break;
		}
	    }
	}
	if (!match) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't find content to extend with \"^\"", TCL_INDEX_NONE));
		    "can't find slave to extend with \"^\"", -1));
	    Tcl_SetErrorCode(interp, "TK", "GRID", "SHORTCUT_USAGE", NULL);
	    return TCL_ERROR;
	}
    }

    if (containerPtr == NULL) {
    if (masterPtr == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't determine container window", TCL_INDEX_NONE));
		"can't determine master window", -1));
	Tcl_SetErrorCode(interp, "TK", "GRID", "SHORTCUT_USAGE", NULL);
	return TCL_ERROR;
    }
    SetGridSize(containerPtr);
    SetGridSize(masterPtr);

    /*
     * If we have emptied this container from content it means we are no longer
     * If we have emptied this master from slaves it means we are no longer
     * handling it and should mark it as free.
     *
     * Send the event "NoManagedChild" to the container to inform it about there
     * being no managed children inside it.
     */

    if (containerPtr->contentPtr == NULL && containerPtr->flags & ALLOCED_CONTAINER) {
	TkFreeGeometryContainer(containerPtr->tkwin, "grid");
	containerPtr->flags &= ~ALLOCED_CONTAINER;
    if (masterPtr->slavePtr == NULL && masterPtr->flags & ALLOCED_MASTER) {
	TkFreeGeometryMaster(masterPtr->tkwin, "grid");
	masterPtr->flags &= ~ALLOCED_MASTER;
	Tk_SendVirtualEvent(containerPtr->tkwin, "NoManagedChild", NULL);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
3655
3656
3657
3658
3659
3660
3661
3662

3663
3664
3665
3666
3667


3668
3669
3670
3671
3672
3673
3674
3618
3619
3620
3621
3622
3623
3624

3625
3626
3627
3628


3629
3630
3631
3632
3633
3634
3635
3636
3637







-
+



-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
NewPairObj(
    Tcl_WideInt val1, Tcl_WideInt val2)
    int val1, int val2)
{
    Tcl_Obj *ary[2];

    ary[0] = Tcl_NewWideIntObj(val1);
    ary[1] = Tcl_NewWideIntObj(val2);
    ary[0] = Tcl_NewIntObj(val1);
    ary[1] = Tcl_NewIntObj(val2);
    return Tcl_NewListObj(2, ary);
}

/*
 *----------------------------------------------------------------------
 *
 * NewQuadObj --
3682
3683
3684
3685
3686
3687
3688
3689

3690
3691
3692
3693
3694
3695
3696




3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3645
3646
3647
3648
3649
3650
3651

3652
3653
3654
3655




3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669







-
+



-
-
-
-
+
+
+
+










 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
NewQuadObj(
    Tcl_WideInt val1, Tcl_WideInt val2, Tcl_WideInt val3, Tcl_WideInt val4)
    int val1, int val2, int val3, int val4)
{
    Tcl_Obj *ary[4];

    ary[0] = Tcl_NewWideIntObj(val1);
    ary[1] = Tcl_NewWideIntObj(val2);
    ary[2] = Tcl_NewWideIntObj(val3);
    ary[3] = Tcl_NewWideIntObj(val4);
    ary[0] = Tcl_NewIntObj(val1);
    ary[1] = Tcl_NewIntObj(val2);
    ary[2] = Tcl_NewIntObj(val3);
    ary[3] = Tcl_NewIntObj(val4);
    return Tcl_NewListObj(4, ary);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted generic/tkIcu.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322


































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkIcu.c --
 *
 * 	tkIcu.c implements various Tk commands which can find
 * 	grapheme cluster and workchar bounderies in Unicode strings.
 *
 * Copyright © 2021 Jan Nijtmans
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

/*
 * Runtime linking of libicu.
 */
typedef enum UBreakIteratorTypex {
	  UBRK_CHARACTERX = 0,
	  UBRK_WORDX = 1
} UBreakIteratorTypex;

typedef enum UErrorCodex {
    U_ZERO_ERRORZ              =  0     /**< No error, no warning. */
} UErrorCodex;

typedef void *(*fn_icu_open)(UBreakIteratorTypex, const char *,
	const uint16_t *, int32_t, UErrorCodex *);
typedef void	(*fn_icu_close)(void *);
typedef int32_t	(*fn_icu_preceding)(void *, int32_t);
typedef int32_t	(*fn_icu_following)(void *, int32_t);
typedef int32_t	(*fn_icu_previous)(void *);
typedef int32_t	(*fn_icu_next)(void *);
typedef void	(*fn_icu_setText)(void *, const void *, int32_t, UErrorCodex *);

static struct {
    size_t				nopen;
    Tcl_LoadHandle		lib;
    fn_icu_open			open;
    fn_icu_close		close;
    fn_icu_preceding	preceding;
    fn_icu_following	following;
    fn_icu_previous	previous;
    fn_icu_next	next;
    fn_icu_setText	setText;
} icu_fns = {
    0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

#define FLAG_WORD 1
#define FLAG_FOLLOWING 4
#define FLAG_SPACE 8

#define icu_open			icu_fns.open
#define icu_close			icu_fns.close
#define icu_preceding		icu_fns.preceding
#define icu_following		icu_fns.following
#define icu_previous		icu_fns.previous
#define icu_next		icu_fns.next
#define icu_setText		icu_fns.setText

TCL_DECLARE_MUTEX(icu_mutex);

static int
startEndOfCmd(
    void *clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_DString ds;
    Tcl_Size len;
    const char *str;
    UErrorCodex errorCode = U_ZERO_ERRORZ;
    void *it;
    Tcl_Size idx;
    int flags = PTR2INT(clientData);
    const uint16_t *ustr;
    const char *locale = NULL;

    if ((unsigned)(objc - 3) > 1) {
	Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?");
	return TCL_ERROR;
    }
    if (objc > 3) {
	locale = Tcl_GetString(objv[3]);
	if (!*locale) {
	    locale = NULL;
	}
    }
    Tcl_DStringInit(&ds);
    str = Tcl_GetStringFromObj(objv[1], &len);
    Tcl_UtfToChar16DString(str, len, &ds);
    len = Tcl_DStringLength(&ds)/2;
    Tcl_Size ulen = Tcl_GetCharLength(objv[1]);
    if (TkGetIntForIndex(objv[2], ulen-1, 0, &idx) != TCL_OK) {
	Tcl_DStringFree(&ds);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"", Tcl_GetString(objv[2])));
	Tcl_SetErrorCode(interp, "TK", "ICU", "INDEX", NULL);
	return TCL_ERROR;
    }
    it = icu_open((UBreakIteratorTypex)(flags&3), locale,
    		NULL, -1, &errorCode);
    if (it != NULL) {
	errorCode = U_ZERO_ERRORZ;
	ustr = (const uint16_t *)Tcl_DStringValue(&ds);
	icu_setText(it, ustr, len, &errorCode);
    }
    if (it == NULL || errorCode != U_ZERO_ERRORZ) {
    	Tcl_DStringFree(&ds);
    	Tcl_SetObjResult(interp, Tcl_ObjPrintf("cannot open ICU iterator, errorcode: %d", (int)errorCode));
    	Tcl_SetErrorCode(interp, "TK", "ICU", "CANNOTOPEN", NULL);
    	return TCL_ERROR;
    }
    if (idx > 0 && len != ulen) {
	/* The string contains codepoints > \uFFFF. Determine UTF-16 index */
	Tcl_Size newIdx = 0;
	for (Tcl_Size i = 0; i < idx; i++) {
	    newIdx += 1 + (((newIdx < (Tcl_Size)len-1) && (ustr[newIdx]&0xFC00) == 0xD800) && ((ustr[newIdx+1]&0xFC00) == 0xDC00));
	}
	idx = newIdx;
    }
    if (flags & FLAG_FOLLOWING) {
	if ((idx < 0) && (flags & FLAG_WORD)) {
	    idx = 0;
	}
	idx = icu_following(it, idx);
	if ((flags & FLAG_WORD) && idx >= len) {
	    idx = -1;
	}
    } else if (idx > 0) {
	if (!(flags & FLAG_WORD)) {
	    idx += 1 + (((ustr[idx]&0xFC00) == 0xD800) && ((ustr[idx+1]&0xFC00) == 0xDC00));
	}
	idx = icu_preceding(it, idx);
	if (idx == 0 && (flags & FLAG_WORD)) {
	    flags &= ~FLAG_WORD; /* If 0 is reached here, don't do a further search */
	}
    }
    if ((flags & FLAG_WORD) && (idx != TCL_INDEX_NONE)) {
	if (!(flags & FLAG_SPACE) == ((idx >= len) || Tcl_UniCharIsSpace(ustr[idx]))) {
	    if (flags & FLAG_FOLLOWING) {
		idx = icu_next(it);
		if (idx >= len) {
		    idx = TCL_INDEX_NONE;
		}
	    } else {
		idx = icu_previous(it);
	    }
	} else if (idx == 0 && !(flags & FLAG_FOLLOWING)) {
	    idx = TCL_INDEX_NONE;
	}
    }
    icu_close(it);
    Tcl_DStringFree(&ds);
    if (idx != TCL_INDEX_NONE) {
	if (idx > 0 && len != ulen) {
	    /* The string contains codepoints > \uFFFF. Determine UTF-32 index */
	    Tcl_Size newIdx = 1;
	    for (Tcl_Size i = 1; i < idx; i++) {
    	if (((ustr[i-1]&0xFC00) != 0xD800) || ((ustr[i]&0xFC00) != 0xDC00)) newIdx++;
	    }
	    idx = newIdx;
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(idx));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * SysNotifyDeleteCmd --
 *
 *      Delete notification and clean up.
 *
 * Results:
 *	Window destroyed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
icuCleanup(
    TCL_UNUSED(void *))
{
    Tcl_MutexLock(&icu_mutex);
    if (icu_fns.nopen-- <= 1) {
	if (icu_fns.lib != NULL) {
	    Tcl_FSUnloadFile(NULL, icu_fns.lib);
	}
	memset(&icu_fns, 0, sizeof(icu_fns));
    }
    Tcl_MutexUnlock(&icu_mutex);
}

void
Icu_Init(
    Tcl_Interp *interp)
{
    Tcl_MutexLock(&icu_mutex);
    char symbol[24];
    char icuversion[4] = "_80"; /* Highest ICU version + 1 */

    if (icu_fns.nopen == 0) {
	int i = 0;
	Tcl_Obj *nameobj;
	static const char *iculibs[] = {
#if defined(_WIN32)
	    "icuuc??.dll", /* When running under Windows, user-provided */
	    NULL,
	    "cygicuuc??.dll", /* When running under Cygwin */
#elif defined(__CYGWIN__)
	    "cygicuuc??.dll",
#elif defined(MAC_OSX_TCL)
	    "libicuuc.??.dylib",
#else
	    "libicuuc.so.??",
#endif
	    NULL
	};

	/* Going back down to ICU version 60 */
	while ((icu_fns.lib == NULL) && (icuversion[1] >= '6')) {
	    if (--icuversion[2] < '0') {
		icuversion[1]--; icuversion[2] = '9';
	    }
#if defined(_WIN32) && !defined(STATIC_BUILD)
	    if (tclStubsPtr->tcl_CreateFileHandler) {
		/* Running on Cygwin, so try to load the cygwin icu dll */
		i = 2;
	    } else
#endif
	    i = 0;
	    while (iculibs[i] != NULL) {
		Tcl_ResetResult(interp);
		nameobj = Tcl_NewStringObj(iculibs[i], TCL_INDEX_NONE);
		char *nameStr = Tcl_GetString(nameobj);
		char *p = strchr(nameStr, '?');
		if (p != NULL) {
		    memcpy(p, icuversion+1, 2);
		}
		Tcl_IncrRefCount(nameobj);
		if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &icu_fns.lib)
			== TCL_OK) {
		    if (p == NULL) {
			icuversion[0] = '\0';
		    }
		    Tcl_DecrRefCount(nameobj);
		    break;
		}
		Tcl_DecrRefCount(nameobj);
		++i;
	    }
	}
#if defined(_WIN32)
	if (icu_fns.lib == NULL) {
	    Tcl_ResetResult(interp);
		nameobj = Tcl_NewStringObj("icu.dll", TCL_INDEX_NONE);
		Tcl_IncrRefCount(nameobj);
		if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &icu_fns.lib)
			== TCL_OK) {
		    icuversion[0] = '\0';
		}
		Tcl_DecrRefCount(nameobj);
	}
	if (icu_fns.lib == NULL) {
	    Tcl_ResetResult(interp);
		nameobj = Tcl_NewStringObj("icuuc.dll", TCL_INDEX_NONE);
		Tcl_IncrRefCount(nameobj);
		if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &icu_fns.lib)
			== TCL_OK) {
		    icuversion[0] = '\0';
		}
		Tcl_DecrRefCount(nameobj);
	}
#endif
	if (icu_fns.lib != NULL) {
#define ICU_SYM(name)							\
	    strcpy(symbol, "ubrk_" #name ); \
	    strcat(symbol, icuversion); \
	    icu_fns.name = (fn_icu_ ## name)				\
		Tcl_FindSymbol(NULL, icu_fns.lib, symbol)
	    ICU_SYM(open);
	    ICU_SYM(close);
	    ICU_SYM(preceding);
	    ICU_SYM(following);
	    ICU_SYM(previous);
	    ICU_SYM(next);
	    ICU_SYM(setText);
#undef ICU_SYM
	}
    }
    Tcl_MutexUnlock(&icu_mutex);

    if (icu_fns.lib != NULL) {
	Tcl_CreateObjCommand(interp, "::tk::startOfCluster", startEndOfCmd,
		INT2PTR(0), icuCleanup);
	Tcl_CreateObjCommand(interp, "::tk::startOfNextWord", startEndOfCmd,
		INT2PTR(FLAG_WORD|FLAG_FOLLOWING), icuCleanup);
	Tcl_CreateObjCommand(interp, "::tk::startOfPreviousWord", startEndOfCmd,
		INT2PTR(FLAG_WORD), icuCleanup);
	Tcl_CreateObjCommand(interp, "::tk::endOfCluster", startEndOfCmd,
		INT2PTR(FLAG_FOLLOWING), icuCleanup);
	Tcl_CreateObjCommand(interp, "::tk::endOfWord", startEndOfCmd,
		INT2PTR(FLAG_WORD|FLAG_FOLLOWING|FLAG_SPACE), icuCleanup);
    icu_fns.nopen += 5;
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * coding: utf-8
 * End:
 */

Changes to generic/tkImage.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


35
36

37
38
39
40
41

42
43
44
45
46
47
48
49

50
51
52
53
54

55
56
57
58
59


60
61
62
63
64
65
66
67
68
69
70
71
72
73

74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148





















149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165

166
167
168
169
170
171
172
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15




16
17
18
19
20
21
22
23
24
25
26
27
28


29
30
31

32
33
34
35
36

37
38
39


40
41
42

43
44
45
46
47

48
49
50
51


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179

180
181
182
183
184
185
186
187






-
-
+
+







-
-
-
-













-
-
+
+

-
+




-
+


-
-



-
+




-
+



-
-
+
+













-
+

-
+














-
-
-
+
+
+




















-
+


-
+

















-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+






-
+







/*
 * tkImage.c --
 *
 *	This module implements the image protocol, which allows lots of
 *	different kinds of images to be used in lots of different widgets.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Each call to Tk_GetImage returns a pointer to one of the following
 * structures, which is used as a token by clients (widgets) that display
 * images.
 */

typedef struct Image {
    Tk_Window tkwin;		/* Window passed to Tk_GetImage (needed to
				 * "re-get" the image later if the manager
				 * changes). */
    Display *display;		/* Display for tkwin. Needed because when the
				 * image is eventually freed tkwin may not
				 * exist anymore. */
    struct ImageModel *modelPtr;
				/* Model for this image (identifiers image
    struct ImageMaster *masterPtr;
				/* Master for this image (identifiers image
				 * manager, for example). */
    void *instanceData;	/* One word argument to pass to image manager
    ClientData instanceData;	/* One word argument to pass to image manager
				 * when dealing with this image instance. */
    Tk_ImageChangedProc *changeProc;
				/* Code in widget to call when image changes
				 * in a way that affects redisplay. */
    void *widgetClientData;/* Argument to pass to changeProc. */
    ClientData widgetClientData;/* Argument to pass to changeProc. */
    struct Image *nextPtr;	/* Next in list of all image instances
				 * associated with the same name. */
    struct Image *prevPtr;	/* Previous in list of all image instances
				 * associated with the same name. */
} Image;

/*
 * For each image model there is one of the following structures, which
 * For each image master there is one of the following structures, which
 * represents a name in the image table and all of the images instantiated
 * from it. Entries in mainPtr->imageTable point to these structures.
 */

typedef struct ImageModel {
typedef struct ImageMaster {
    Tk_ImageType *typePtr;	/* Information about image type. NULL means
				 * that no image manager owns this image: the
				 * image was deleted. */
    void *modelData;	/* One-word argument to pass to image mgr when
				 * dealing with the model, as opposed to
    ClientData masterData;	/* One-word argument to pass to image mgr when
				 * dealing with the master, as opposed to
				 * instances. */
    int width, height;		/* Last known dimensions for image. */
    Tcl_HashTable *tablePtr;	/* Pointer to hash table containing image (the
				 * imageTable field in some TkMainInfo
				 * structure). */
    Tcl_HashEntry *hPtr;	/* Hash entry in mainPtr->imageTable for this
				 * structure (used to delete the hash
				 * entry). */
    Image *instancePtr;		/* Pointer to first in list of instances
				 * derived from this name. */
    int deleted;		/* Flag set when image is being deleted. */
    TkWindow *winPtr;		/* Main window of interpreter (used to detect
				 * when the world is falling apart.) */
} ImageModel;
} ImageMaster;

typedef struct {
typedef struct ThreadSpecificData {
    Tk_ImageType *imageTypeList;/* First in a list of all known image
				 * types. */
    Tk_ImageType *oldImageTypeList;
				/* First in a list of all known old-style
				 * image types. */
    int initialized;		/* Set to 1 if we've initialized the
				 * structure. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Prototypes for local functions:
 */

static void		ImageTypeThreadExitProc(void *clientData);
static Tcl_FreeProc	DeleteImage;
static void		EventuallyDeleteImage(ImageModel *modelPtr,
static void		ImageTypeThreadExitProc(ClientData clientData);
static void		DeleteImage(ImageMaster *masterPtr);
static void		EventuallyDeleteImage(ImageMaster *masterPtr,
			    int forgetImageHashNow);

/*
 *----------------------------------------------------------------------
 *
 * ImageTypeThreadExitProc --
 *
 *	Clean up the registered list of image types.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The thread's linked lists of photo image formats is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ImageTypeThreadExitProc(
    TCL_UNUSED(void *))
    ClientData clientData)	/* not used */
{
    Tk_ImageType *freePtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    while (tsdPtr->oldImageTypeList != NULL) {
	freePtr = tsdPtr->oldImageTypeList;
	tsdPtr->oldImageTypeList = tsdPtr->oldImageTypeList->nextPtr;
	ckfree(freePtr);
    }
    while (tsdPtr->imageTypeList != NULL) {
	freePtr = tsdPtr->imageTypeList;
	tsdPtr->imageTypeList = tsdPtr->imageTypeList->nextPtr;
	ckfree(freePtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_CreateImageType --
 * Tk_CreateOldImageType, Tk_CreateImageType --
 *
 *	This function is invoked by an image manager to tell Tk about a new
 *	kind of image and the functions that manage the new type. The function
 *	is typically invoked during Tcl_AppInit.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The new image type is entered into a table used in the "image create"
 *	command.
 *
 *----------------------------------------------------------------------
 */

void
Tk_CreateOldImageType(
    const Tk_ImageType *typePtr)
				/* Structure describing the type. All of the
				 * fields except "nextPtr" must be filled in
				 * by caller. */
{
    Tk_ImageType *copyPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	Tcl_CreateThreadExitHandler(ImageTypeThreadExitProc, NULL);
    }
    copyPtr = ckalloc(sizeof(Tk_ImageType));
    *copyPtr = *typePtr;
    copyPtr->nextPtr = tsdPtr->oldImageTypeList;
    tsdPtr->oldImageTypeList = copyPtr;
}

void
Tk_CreateImageType(
    const Tk_ImageType *typePtr)
				/* Structure describing the type. All of the
				 * fields except "nextPtr" must be filled in
				 * by caller. */
{
    Tk_ImageType *copyPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	Tcl_CreateThreadExitHandler(ImageTypeThreadExitProc, NULL);
    }
    copyPtr = (Tk_ImageType *)ckalloc(sizeof(Tk_ImageType));
    copyPtr = ckalloc(sizeof(Tk_ImageType));
    *copyPtr = *typePtr;
    copyPtr->nextPtr = tsdPtr->imageTypeList;
    tsdPtr->imageTypeList = copyPtr;
}

/*
 *----------------------------------------------------------------------
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206

207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217

218
219
220

221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236







-
+












-
+


-
+







-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ImageObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    static const char *const imageOptions[] = {
	"create", "delete", "height", "inuse", "names", "type", "types",
	"width", NULL
    };
    enum options {
	IMAGE_CREATE, IMAGE_DELETE, IMAGE_HEIGHT, IMAGE_INUSE, IMAGE_NAMES,
	IMAGE_TYPE, IMAGE_TYPES, IMAGE_WIDTH
    };
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    int i, isNew, firstOption, index;
    Tk_ImageType *typePtr;
    ImageModel *modelPtr;
    ImageMaster *masterPtr;
    Image *imagePtr;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    char idString[16 + TCL_INTEGER_SPACE];
    TkDisplay *dispPtr = winPtr->dispPtr;
    const char *arg, *name;
    Tcl_Obj *resultObj;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
	return TCL_ERROR;
    }

266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316











317
318
319
320

321
322
323
324
325



326
327

328
329
330
331


332
333
334


335
336

337
338
339
340
341
342
343
344
345
346
347
348


349

350
351
352
353
354
355

356
357
358
359
360
361
362
363

364
365
366
367
368



369
370
371
372
373
374

375
376
377
378
379


380
381
382

383
384
385

386
387
388
389
390
391
392
393
394
395
396


397
398
399

400
401
402
403
404
405
406
407
408
409
410
411


412
413
414
415

416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433

434
435
436
437
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459


460
461
462
463
464
465
466
467
468
469

470
471
472
473

474
475
476

477
478

479
480
481
482

483
484
485
486
487
488
489
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320











321
322
323
324
325
326
327
328
329
330
331
332
333
334

335
336
337



338
339
340
341

342
343
344


345
346
347


348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

366
367
368
369
370
371

372








373





374
375
376
377
378
379
380
381

382
383
384
385


386
387
388
389

390
391
392

393
394
395
396
397
398
399
400
401
402


403
404
405
406

407
408
409
410
411
412
413
414
415
416
417


418
419
420
421
422

423
424
425
426
427
428
429
430
431
432
433
434
435

436
437
438
439
440

441
442
443
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459
460
461
462
463
464
465


466
467
468
469
470
471
472
473
474
475
476

477
478
479
480

481
482
483

484
485

486
487
488
489

490
491
492
493
494
495
496
497







-
+











-
+




















-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



-
+


-
-
-
+
+
+

-
+


-
-
+
+

-
-
+
+

-
+












+
+
-
+





-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+





-
+



-
-
+
+


-
+


-
+









-
-
+
+


-
+










-
-
+
+



-
+












-
+




-
+










-
+













-
-
+
+









-
+



-
+


-
+

-
+



-
+







	/*
	 * Figure out a name to use for the new image.
	 */

	if ((objc == 3) || (*(arg = Tcl_GetString(objv[3])) == '-')) {
	    do {
		dispPtr->imageId++;
		snprintf(idString, sizeof(idString), "image%d", dispPtr->imageId);
		sprintf(idString, "image%d", dispPtr->imageId);
		name = idString;
	    } while (Tcl_FindCommand(interp, name, NULL, 0) != NULL);
	    firstOption = 3;
	} else {
	    TkWindow *topWin;

	    name = arg;
	    firstOption = 4;

	    /*
	     * Need to check if the _command_ that we are about to create is
	     * the name of the current model widget command (normally "." but
	     * the name of the current master widget command (normally "." but
	     * could have been renamed) and fail in that case before a really
	     * nasty and hard to stop crash happens.
	     */

	    topWin = (TkWindow *) TkToplevelWindowForCommand(interp, name);
	    if (topWin != NULL && winPtr->mainPtr->winPtr == topWin) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"images may not be named the same as the main window",
			-1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SMASH_MAIN", NULL);
		return TCL_ERROR;
	    }
	}

	/*
	 * Create the data structure for the new image.
	 */

	hPtr = Tcl_CreateHashEntry(&winPtr->mainPtr->imageTable, name, &isNew);
	if (isNew) {
	    modelPtr = (ImageModel *)ckalloc(sizeof(ImageModel));
	    modelPtr->typePtr = NULL;
	    modelPtr->modelData = NULL;
	    modelPtr->width = modelPtr->height = 1;
	    modelPtr->tablePtr = &winPtr->mainPtr->imageTable;
	    modelPtr->hPtr = hPtr;
	    modelPtr->instancePtr = NULL;
	    modelPtr->deleted = 0;
	    modelPtr->winPtr = winPtr->mainPtr->winPtr;
	    Tcl_Preserve(modelPtr->winPtr);
	    Tcl_SetHashValue(hPtr, modelPtr);
	    masterPtr = ckalloc(sizeof(ImageMaster));
	    masterPtr->typePtr = NULL;
	    masterPtr->masterData = NULL;
	    masterPtr->width = masterPtr->height = 1;
	    masterPtr->tablePtr = &winPtr->mainPtr->imageTable;
	    masterPtr->hPtr = hPtr;
	    masterPtr->instancePtr = NULL;
	    masterPtr->deleted = 0;
	    masterPtr->winPtr = winPtr->mainPtr->winPtr;
	    Tcl_Preserve(masterPtr->winPtr);
	    Tcl_SetHashValue(hPtr, masterPtr);
	} else {
	    /*
	     * An image already exists by this name. Disconnect the instances
	     * from the model.
	     * from the master.
	     */

	    modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
	    if (modelPtr->typePtr != NULL) {
		for (imagePtr = modelPtr->instancePtr; imagePtr != NULL;
	    masterPtr = Tcl_GetHashValue(hPtr);
	    if (masterPtr->typePtr != NULL) {
		for (imagePtr = masterPtr->instancePtr; imagePtr != NULL;
			imagePtr = imagePtr->nextPtr) {
		    modelPtr->typePtr->freeProc(imagePtr->instanceData,
		    masterPtr->typePtr->freeProc(imagePtr->instanceData,
			    imagePtr->display);
		    imagePtr->changeProc(imagePtr->widgetClientData, 0, 0,
			    modelPtr->width, modelPtr->height,
			    modelPtr->width, modelPtr->height);
			    masterPtr->width, masterPtr->height,
			    masterPtr->width, masterPtr->height);
		}
		modelPtr->typePtr->deleteProc(modelPtr->modelData);
		modelPtr->typePtr = NULL;
		masterPtr->typePtr->deleteProc(masterPtr->masterData);
		masterPtr->typePtr = NULL;
	    }
	    modelPtr->deleted = 0;
	    masterPtr->deleted = 0;
	}

	/*
	 * Call the image type manager so that it can perform its own
	 * initialization, then re-"get" for any existing instances of the
	 * image.
	 */

	objv += firstOption;
	objc -= firstOption;
	args = (Tcl_Obj **) objv;
	if (oldimage) {
	    int i;

	    args = (Tcl_Obj **)ckalloc((objc+1) * sizeof(Tcl_Obj *));
	    args = ckalloc((objc+1) * sizeof(char *));
	    for (i = 0; i < objc; i++) {
		args[i] = (Tcl_Obj *) Tcl_GetString(objv[i]);
	    }
	    args[objc] = NULL;
	}
	Tcl_Preserve(modelPtr);
	Tcl_Preserve(masterPtr);
	if (oldimage) {
	    typedef int (OldCreateProc)(Tcl_Interp*, char*, Tcl_Size, char**,
		Tk_ImageType*, Tk_ImageModel, ClientData*);
	    i = ((OldCreateProc*)typePtr->createProc)(interp,
		(char*)name, objc, (char**)args, typePtr,
		(Tk_ImageModel)modelPtr, &modelPtr->modelData);
	} else {
	    i = typePtr->createProc(interp, name, objc, args, typePtr,
	if (typePtr->createProc(interp, name, objc, args, typePtr,
		(Tk_ImageModel)modelPtr, &modelPtr->modelData);
	}
	if (i != TCL_OK){
	    EventuallyDeleteImage(modelPtr, 0);
	    Tcl_Release(modelPtr);
		(Tk_ImageMaster)masterPtr, &masterPtr->masterData) != TCL_OK){
	    EventuallyDeleteImage(masterPtr, 0);
	    Tcl_Release(masterPtr);
	    if (oldimage) {
		ckfree(args);
	    }
	    return TCL_ERROR;
	}
	Tcl_Release(modelPtr);
	Tcl_Release(masterPtr);
	if (oldimage) {
	    ckfree(args);
	}
	modelPtr->typePtr = typePtr;
	for (imagePtr = modelPtr->instancePtr; imagePtr != NULL;
	masterPtr->typePtr = typePtr;
	for (imagePtr = masterPtr->instancePtr; imagePtr != NULL;
		imagePtr = imagePtr->nextPtr) {
	    imagePtr->instanceData = typePtr->getProc(imagePtr->tkwin,
		    modelPtr->modelData);
		    masterPtr->masterData);
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		(const char *)Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), TCL_INDEX_NONE));
		Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), -1));
	break;
    }
    case IMAGE_DELETE:
	for (i = 2; i < objc; i++) {
	    arg = Tcl_GetString(objv[i]);
	    hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, arg);
	    if (hPtr == NULL) {
		goto alreadyDeleted;
	    }
	    modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
	    if (modelPtr->deleted) {
	    masterPtr = Tcl_GetHashValue(hPtr);
	    if (masterPtr->deleted) {
		goto alreadyDeleted;
	    }
	    DeleteImage((char *)modelPtr);
	    DeleteImage(masterPtr);
	}
	break;
    case IMAGE_NAMES:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}
	hPtr = Tcl_FirstHashEntry(&winPtr->mainPtr->imageTable, &search);
	resultObj = Tcl_NewObj();
	for ( ; hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
	    if (modelPtr->deleted) {
	    masterPtr = Tcl_GetHashValue(hPtr);
	    if (masterPtr->deleted) {
		continue;
	    }
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    (const char *)Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), TCL_INDEX_NONE));
		    Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), -1));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;
    case IMAGE_TYPES:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}
	resultObj = Tcl_NewObj();
	for (typePtr = tsdPtr->imageTypeList; typePtr != NULL;
		typePtr = typePtr->nextPtr) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    typePtr->name, TCL_INDEX_NONE));
		    typePtr->name, -1));
	}
	for (typePtr = tsdPtr->oldImageTypeList; typePtr != NULL;
		typePtr = typePtr->nextPtr) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    typePtr->name, TCL_INDEX_NONE));
		    typePtr->name, -1));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;

    case IMAGE_HEIGHT:
    case IMAGE_INUSE:
    case IMAGE_TYPE:
    case IMAGE_WIDTH:
	/*
	 * These operations all parse virtually identically. First check to
	 * see if three args are given. Then get a non-deleted model from the
	 * see if three args are given. Then get a non-deleted master from the
	 * third arg.
	 */

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "name");
	    return TCL_ERROR;
	}

	arg = Tcl_GetString(objv[2]);
	hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, arg);
	if (hPtr == NULL) {
	    goto alreadyDeleted;
	}
	modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
	if (modelPtr->deleted) {
	masterPtr = Tcl_GetHashValue(hPtr);
	if (masterPtr->deleted) {
	    goto alreadyDeleted;
	}

	/*
	 * Now we read off the specific piece of data we were asked for.
	 */

	switch ((enum options) index) {
	case IMAGE_HEIGHT:
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(modelPtr->height));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(masterPtr->height));
	    break;
	case IMAGE_INUSE:
	    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		    modelPtr->typePtr && modelPtr->instancePtr));
		    masterPtr->typePtr && masterPtr->instancePtr));
	    break;
	case IMAGE_TYPE:
	    if (modelPtr->typePtr != NULL) {
	    if (masterPtr->typePtr != NULL) {
		Tcl_SetObjResult(interp,
			Tcl_NewStringObj(modelPtr->typePtr->name, TCL_INDEX_NONE));
			Tcl_NewStringObj(masterPtr->typePtr->name, -1));
	    }
	    break;
	case IMAGE_WIDTH:
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(modelPtr->width));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(masterPtr->width));
	    break;
	default:
	    Tcl_Panic("can't happen");
	}
	break;
    }
    return TCL_OK;
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
526
527
528
529

530
531
532
533
534



535
536
537
538
539
540
541
542
543
544
545
546

547
548
549
550

551
552
553
554
555
556
557
558
559
560

561
562

563
564

565
566
567

568
569
570
571
572
573
574
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536

537
538
539



540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557

558
559
560
561
562
563
564
565
566
567

568
569

570
571

572
573
574

575
576
577
578
579
580
581
582







-
+










-
+


-
-
-
+
+
+











-
+



-
+









-
+

-
+

-
+


-
+







 *	redisplay themselves as appropriate.
 *
 *----------------------------------------------------------------------
 */

void
Tk_ImageChanged(
    Tk_ImageModel imageModel,	/* Image that needs redisplay. */
    Tk_ImageMaster imageMaster,	/* Image that needs redisplay. */
    int x, int y,		/* Coordinates of upper-left pixel of region
				 * of image that needs to be redrawn. */
    int width, int height,	/* Dimensions (in pixels) of region of image
				 * to redraw. If either dimension is zero then
				 * the image doesn't need to be redrawn
				 * (perhaps all that happened is that its size
				 * changed). */
    int imageWidth, int imageHeight)
				/* New dimensions of image. */
{
    ImageModel *modelPtr = (ImageModel *) imageModel;
    ImageMaster *masterPtr = (ImageMaster *) imageMaster;
    Image *imagePtr;

    modelPtr->width = imageWidth;
    modelPtr->height = imageHeight;
    for (imagePtr = modelPtr->instancePtr; imagePtr != NULL;
    masterPtr->width = imageWidth;
    masterPtr->height = imageHeight;
    for (imagePtr = masterPtr->instancePtr; imagePtr != NULL;
	    imagePtr = imagePtr->nextPtr) {
	imagePtr->changeProc(imagePtr->widgetClientData, x, y, width, height,
		imageWidth, imageHeight);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_NameOfImage --
 *
 *	Given a token for an image model, this function returns the name of
 *	Given a token for an image master, this function returns the name of
 *	the image.
 *
 * Results:
 *	The return value is the string name for imageModel.
 *	The return value is the string name for imageMaster.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

const char *
Tk_NameOfImage(
    Tk_ImageModel imageModel)	/* Token for image. */
    Tk_ImageMaster imageMaster)	/* Token for image. */
{
    ImageModel *modelPtr = (ImageModel *) imageModel;
    ImageMaster *masterPtr = (ImageMaster *) imageMaster;

    if (modelPtr->hPtr == NULL) {
    if (masterPtr->hPtr == NULL) {
	return NULL;
    }
    return (const char *)Tcl_GetHashKey(modelPtr->tablePtr, modelPtr->hPtr);
    return Tcl_GetHashKey(masterPtr->tablePtr, masterPtr->hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetImage --
 *
595
596
597
598
599
600
601
602

603
604
605

606
607
608
609
610
611
612
613


614
615
616

617
618
619

620
621
622

623
624

625
626
627
628

629
630
631
632

633
634
635
636
637
638
639
603
604
605
606
607
608
609

610
611
612

613
614
615
616
617
618
619


620
621
622
623

624
625
626

627
628
629

630
631

632
633
634


635




636
637
638
639
640
641
642
643







-
+


-
+






-
-
+
+


-
+


-
+


-
+

-
+


-
-
+
-
-
-
-
+







				 * be found. */
    Tk_Window tkwin,		/* Token for window in which image will be
				 * used. */
    const char *name,		/* Name of desired image. */
    Tk_ImageChangedProc *changeProc,
				/* Function to invoke when redisplay is needed
				 * because image's pixels or size changed. */
    void *clientData)	/* One-word argument to pass to damageProc. */
    ClientData clientData)	/* One-word argument to pass to damageProc. */
{
    Tcl_HashEntry *hPtr;
    ImageModel *modelPtr;
    ImageMaster *masterPtr;
    Image *imagePtr;

    hPtr = Tcl_FindHashEntry(&((TkWindow *) tkwin)->mainPtr->imageTable, name);
    if (hPtr == NULL) {
	goto noSuchImage;
    }
    modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
    if (modelPtr->typePtr == NULL) {
    masterPtr = Tcl_GetHashValue(hPtr);
    if (masterPtr->typePtr == NULL) {
	goto noSuchImage;
    }
    if (modelPtr->deleted) {
    if (masterPtr->deleted) {
	goto noSuchImage;
    }
    imagePtr = (Image *)ckalloc(sizeof(Image));
    imagePtr = ckalloc(sizeof(Image));
    imagePtr->tkwin = tkwin;
    imagePtr->display = Tk_Display(tkwin);
    imagePtr->modelPtr = modelPtr;
    imagePtr->masterPtr = masterPtr;
    imagePtr->instanceData =
	    modelPtr->typePtr->getProc(tkwin, modelPtr->modelData);
	    masterPtr->typePtr->getProc(tkwin, masterPtr->masterData);
    imagePtr->changeProc = changeProc;
    imagePtr->widgetClientData = clientData;
    imagePtr->nextPtr = modelPtr->instancePtr;
    if (imagePtr->nextPtr) {
    imagePtr->nextPtr = masterPtr->instancePtr;
	imagePtr->nextPtr->prevPtr = imagePtr;
    }
    imagePtr->prevPtr = NULL;
    modelPtr->instancePtr = imagePtr;
    masterPtr->instancePtr = imagePtr;
    return (Tk_Image) imagePtr;

  noSuchImage:
    if (interp) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"image \"%s\" doesn't exist", name));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE", name, NULL);
661
662
663
664
665
666
667
668


669
670
671
672
673
674
675


676
677
678
679
680



681
682
683
684

685
686

687

688
689
690
691
692
693


694
695
696
697
698



699
700
701


702
703
704
705
706
707
708
665
666
667
668
669
670
671

672
673
674
675
676
677
678


679
680
681
682



683
684
685


686

687


688
689
690
691
692
693
694


695
696
697
698



699
700
701
702


703
704
705
706
707
708
709
710
711







-
+
+





-
-
+
+


-
-
-
+
+
+
-
-

-
+
-
-
+

+




-
-
+
+


-
-
-
+
+
+

-
-
+
+








void
Tk_FreeImage(
    Tk_Image image)		/* Token for image that is no longer needed by
				 * a widget. */
{
    Image *imagePtr = (Image *) image;
    ImageModel *modelPtr = imagePtr->modelPtr;
    ImageMaster *masterPtr = imagePtr->masterPtr;
    Image *prevPtr;

    /*
     * Clean up the particular instance.
     */

    if (modelPtr->typePtr != NULL) {
	modelPtr->typePtr->freeProc(imagePtr->instanceData,
    if (masterPtr->typePtr != NULL) {
	masterPtr->typePtr->freeProc(imagePtr->instanceData,
		imagePtr->display);
    }
    if (imagePtr->prevPtr) {
	imagePtr->prevPtr->nextPtr = imagePtr->nextPtr;
	if (imagePtr->nextPtr) {
    prevPtr = masterPtr->instancePtr;
    if (prevPtr == imagePtr) {
	masterPtr->instancePtr = imagePtr->nextPtr;
	    imagePtr->nextPtr->prevPtr = imagePtr->prevPtr;
	}
    } else {
	modelPtr->instancePtr = imagePtr->nextPtr;
	while (prevPtr->nextPtr != imagePtr) {
	if (modelPtr->instancePtr) {
	    modelPtr->instancePtr->prevPtr = NULL;
	    prevPtr = prevPtr->nextPtr;
	}
	prevPtr->nextPtr = imagePtr->nextPtr;
    }
    ckfree(imagePtr);

    /*
     * If there are no more instances left for the model, and if the model
     * image has been deleted, then delete the model too.
     * If there are no more instances left for the master, and if the master
     * image has been deleted, then delete the master too.
     */

    if ((modelPtr->typePtr == NULL) && (modelPtr->instancePtr == NULL)) {
	if (modelPtr->hPtr != NULL) {
	    Tcl_DeleteHashEntry(modelPtr->hPtr);
    if ((masterPtr->typePtr == NULL) && (masterPtr->instancePtr == NULL)) {
	if (masterPtr->hPtr != NULL) {
	    Tcl_DeleteHashEntry(masterPtr->hPtr);
	}
	Tcl_Release(modelPtr->winPtr);
	ckfree(modelPtr);
	Tcl_Release(masterPtr->winPtr);
	ckfree(masterPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PostscriptImage --
734
735
736
737
738
739
740
741

742
743

744
745
746
747
748
749
750
751
752
753
754
755
756



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

776
777
778
779
780
781
782
737
738
739
740
741
742
743

744
745

746
747
748
749
750
751
752
753
754
755
756



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777

778
779
780
781
782
783
784
785







-
+

-
+










-
-
-
+
+
+


















-
+







    Image *imagePtr = (Image *) image;
    int result;
    XImage *ximage;
    Pixmap pmap;
    GC newGC;
    XGCValues gcValues;

    if (imagePtr->modelPtr->typePtr == NULL) {
    if (imagePtr->masterPtr->typePtr == NULL) {
	/*
	 * No model for image, so nothing to display on postscript.
	 * No master for image, so nothing to display on postscript.
	 */

	return TCL_OK;
    }

    /*
     * Check if an image specific postscript-generation function exists;
     * otherwise go on with generic code.
     */

    if (imagePtr->modelPtr->typePtr->postscriptProc != NULL) {
	return imagePtr->modelPtr->typePtr->postscriptProc(
		imagePtr->modelPtr->modelData, interp, tkwin, psinfo,
    if (imagePtr->masterPtr->typePtr->postscriptProc != NULL) {
	return imagePtr->masterPtr->typePtr->postscriptProc(
		imagePtr->masterPtr->masterData, interp, tkwin, psinfo,
		x, y, width, height, prepass);
    }

    if (prepass) {
	return TCL_OK;
    }

    /*
     * Create a Pixmap, tell the image to redraw itself there, and then
     * generate an XImage from the Pixmap. We can then read pixel values out
     * of the XImage.
     */

    pmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin), width, height,
	    Tk_Depth(tkwin));

    gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin));
    newGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
    if (newGC != NULL) {
    if (newGC != None) {
	XFillRectangle(Tk_Display(tkwin), pmap, newGC, 0, 0,
		(unsigned) width, (unsigned) height);
	Tk_FreeGC(Tk_Display(tkwin), newGC);
    }

    Tk_RedrawImage(image, x, y, width, height, pmap, 0, 0);

830
831
832
833
834
835
836
837

838
839

840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860


861
862
863


864
865

866
867
868
869
870
871
872
833
834
835
836
837
838
839

840
841

842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861


862
863
864


865
866
867

868
869
870
871
872
873
874
875







-
+

-
+



















-
-
+
+

-
-
+
+

-
+







				 * the Tk_GetImage call for the image. */
    int drawableX, int drawableY)
				/* Coordinates in drawable that correspond to
				 * imageX and imageY. */
{
    Image *imagePtr = (Image *) image;

    if (imagePtr->modelPtr->typePtr == NULL) {
    if (imagePtr->masterPtr->typePtr == NULL) {
	/*
	 * No model for image, so nothing to display.
	 * No master for image, so nothing to display.
	 */

	return;
    }

    /*
     * Clip the redraw area to the area of the image.
     */

    if (imageX < 0) {
	width += imageX;
	drawableX -= imageX;
	imageX = 0;
    }
    if (imageY < 0) {
	height += imageY;
	drawableY -= imageY;
	imageY = 0;
    }
    if ((imageX + width) > imagePtr->modelPtr->width) {
	width = imagePtr->modelPtr->width - imageX;
    if ((imageX + width) > imagePtr->masterPtr->width) {
	width = imagePtr->masterPtr->width - imageX;
    }
    if ((imageY + height) > imagePtr->modelPtr->height) {
	height = imagePtr->modelPtr->height - imageY;
    if ((imageY + height) > imagePtr->masterPtr->height) {
	height = imagePtr->masterPtr->height - imageY;
    }
    imagePtr->modelPtr->typePtr->displayProc(imagePtr->instanceData,
    imagePtr->masterPtr->typePtr->displayProc(imagePtr->instanceData,
	    imagePtr->display, drawable, imageX, imageY, width, height,
	    drawableX, drawableY);
}

/*
 *----------------------------------------------------------------------
 *
888
889
890
891
892
893
894
895
896


897
898
899
900
901
902
903
891
892
893
894
895
896
897


898
899
900
901
902
903
904
905
906







-
-
+
+







Tk_SizeOfImage(
    Tk_Image image,		/* Token for image whose size is wanted. */
    int *widthPtr,		/* Return width of image here. */
    int *heightPtr)		/* Return height of image here. */
{
    Image *imagePtr = (Image *) image;

    *widthPtr = imagePtr->modelPtr->width;
    *heightPtr = imagePtr->modelPtr->height;
    *widthPtr = imagePtr->masterPtr->width;
    *heightPtr = imagePtr->masterPtr->height;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DeleteImage --
 *
926
927
928
929
930
931
932
933

934
935
936
937
938
939
940
941
942
943
944
945
946
947
948

949
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964
965
966
967


968
969

970
971
972
973
974


975
976

977
978
979
980



981
982
983


984
985

986
987
988
989
990
991
992
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950

951
952
953
954
955
956
957
958


959



960
961
962

963


964
965
966

967
968
969
970


971
972
973

974
975



976
977
978
979


980
981
982

983
984
985
986
987
988
989
990







-
+














-
+







-
-
+
-
-
-



-

-
-
+
+

-
+



-
-
+
+

-
+

-
-
-
+
+
+

-
-
+
+

-
+







    if (winPtr == NULL) {
	return;
    }
    hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, name);
    if (hPtr == NULL) {
	return;
    }
    DeleteImage((char *)Tcl_GetHashValue(hPtr));
    DeleteImage(Tcl_GetHashValue(hPtr));
}

/*
 *----------------------------------------------------------------------
 *
 * DeleteImage --
 *
 *	This function is responsible for deleting an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The connection is dropped between instances of this image and an image
 *	model. Image instances will redisplay themselves as empty areas, but
 *	master. Image instances will redisplay themselves as empty areas, but
 *	existing instances will not be deleted.
 *
 *----------------------------------------------------------------------
 */

static void
DeleteImage(
#if TCL_MAJOR_VERSION > 8
    void *blockPtr)	/* Pointer to main data structure for image. */
    ImageMaster *masterPtr)	/* Pointer to main data structure for image. */
#else
    char *blockPtr)
#endif
{
    Image *imagePtr;
    Tk_ImageType *typePtr;
    ImageModel *modelPtr = (ImageModel *)blockPtr;

    typePtr = modelPtr->typePtr;
    modelPtr->typePtr = NULL;
    typePtr = masterPtr->typePtr;
    masterPtr->typePtr = NULL;
    if (typePtr != NULL) {
	for (imagePtr = modelPtr->instancePtr; imagePtr != NULL;
	for (imagePtr = masterPtr->instancePtr; imagePtr != NULL;
		imagePtr = imagePtr->nextPtr) {
	    typePtr->freeProc(imagePtr->instanceData, imagePtr->display);
	    imagePtr->changeProc(imagePtr->widgetClientData, 0, 0,
		    modelPtr->width, modelPtr->height, modelPtr->width,
		    modelPtr->height);
		    masterPtr->width, masterPtr->height, masterPtr->width,
		    masterPtr->height);
	}
	typePtr->deleteProc(modelPtr->modelData);
	typePtr->deleteProc(masterPtr->masterData);
    }
    if (modelPtr->instancePtr == NULL) {
	if (modelPtr->hPtr != NULL) {
	    Tcl_DeleteHashEntry(modelPtr->hPtr);
    if (masterPtr->instancePtr == NULL) {
	if (masterPtr->hPtr != NULL) {
	    Tcl_DeleteHashEntry(masterPtr->hPtr);
	}
	Tcl_Release(modelPtr->winPtr);
	ckfree(modelPtr);
	Tcl_Release(masterPtr->winPtr);
	ckfree(masterPtr);
    } else {
	modelPtr->deleted = 1;
	masterPtr->deleted = 1;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * EventuallyDeleteImage --
1002
1003
1004
1005
1006
1007
1008
1009

1010
1011
1012
1013
1014

1015
1016
1017
1018



1019
1020
1021
1022
1023
1024
1025
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009
1010
1011

1012
1013



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023







-
+




-
+

-
-
-
+
+
+







 *	ill effects.
 *
 *----------------------------------------------------------------------
 */

static void
EventuallyDeleteImage(
    ImageModel *modelPtr,	/* Pointer to main data structure for image. */
    ImageMaster *masterPtr,	/* Pointer to main data structure for image. */
    int forgetImageHashNow)	/* Flag to say whether the hash table is about
				 * to vanish. */
{
    if (forgetImageHashNow) {
	modelPtr->hPtr = NULL;
	masterPtr->hPtr = NULL;
    }
    if (!modelPtr->deleted) {
	modelPtr->deleted = 1;
	Tcl_EventuallyFree(modelPtr, DeleteImage);
    if (!masterPtr->deleted) {
	masterPtr->deleted = 1;
	Tcl_EventuallyFree(masterPtr, (Tcl_FreeProc *) DeleteImage);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkDeleteAllImages --
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076


1077
1078
1079
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1094


1095
1096
1097
1098
1099


1100
1101
1102
1103
1104
1105
1106
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072


1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090


1091
1092
1093
1094
1095


1096
1097
1098
1099
1100
1101
1102
1103
1104







-
+







-
+


-
+













-
-
+
+









-
+






-
-
+
+



-
-
+
+







				 * going away. */
{
    Tcl_HashSearch search;
    Tcl_HashEntry *hPtr;

    for (hPtr = Tcl_FirstHashEntry(&mainPtr->imageTable, &search);
	    hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	EventuallyDeleteImage((ImageModel *)Tcl_GetHashValue(hPtr), 1);
	EventuallyDeleteImage(Tcl_GetHashValue(hPtr), 1);
    }
    Tcl_DeleteHashTable(&mainPtr->imageTable);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetImageModelData --
 * Tk_GetImageMasterData --
 *
 *	Given the name of an image, this function returns the type of the
 *	image and the clientData associated with its model.
 *	image and the clientData associated with its master.
 *
 * Results:
 *	If there is no image by the given name, then NULL is returned and a
 *	NULL value is stored at *typePtrPtr. Otherwise the return value is the
 *	clientData returned by the createProc when the image was created and a
 *	pointer to the type structure for the image is stored at *typePtrPtr.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
Tk_GetImageModelData(
ClientData
Tk_GetImageMasterData(
    Tcl_Interp *interp,		/* Interpreter in which the image was
				 * created. */
    const char *name,		/* Name of image. */
    const Tk_ImageType **typePtrPtr)
				/* Points to location to fill in with pointer
				 * to type information for image. */
{
    TkWindow *winPtr = (TkWindow *) Tk_MainWindow(interp);
    Tcl_HashEntry *hPtr;
    ImageModel *modelPtr;
    ImageMaster *masterPtr;

    hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, name);
    if (hPtr == NULL) {
	*typePtrPtr = NULL;
	return NULL;
    }
    modelPtr = (ImageModel *)Tcl_GetHashValue(hPtr);
    if (modelPtr->deleted) {
    masterPtr = Tcl_GetHashValue(hPtr);
    if (masterPtr->deleted) {
	*typePtrPtr = NULL;
	return NULL;
    }
    *typePtrPtr = modelPtr->typePtr;
    return modelPtr->modelData;
    *typePtrPtr = masterPtr->typePtr;
    return masterPtr->masterData;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetTSOrigin --
 *
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128







+







 * Side Effects:
 *	The GCTileStipOrigin is reset in the GC. This will cause the tile
 *	origin to change when the GC is used for drawing.
 *
 *----------------------------------------------------------------------
 */

/*ARGSUSED*/
void
Tk_SetTSOrigin(
    Tk_Window tkwin,
    GC gc,
    int x, int y)
{
    while (!Tk_TopWinHierarchy(tkwin)) {

Changes to generic/tkImgBmap.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17

18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82





83
84
85
86
87
88



89
90
91
92
93
94
95
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15
16

17
18
19
20


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77





78
79
80
81
82
83
84
85



86
87
88
89
90
91
92
93
94
95





-
-
-
+
+
+








-
+



-
-
+
+




















-
-
+
+









-
+













-
+









-
-
-
-
-
+
+
+
+
+



-
-
-
+
+
+







/*
 * tkImgBmap.c --
 *
 *	This procedure implements images of type "bitmap" for Tk.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1999 Scriptics Corporation.
 * Copyright (c) 1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

/*
 * The following data structure represents the model for a bitmap
 * The following data structure represents the master for a bitmap
 * image:
 */

typedef struct {
    Tk_ImageModel tkModel;	/* Tk's token for image model. NULL means the
typedef struct BitmapMaster {
    Tk_ImageMaster tkMaster;	/* Tk's token for image master. NULL means the
				 * image is being deleted. */
    Tcl_Interp *interp;		/* Interpreter for application that is using
				 * image. */
    Tcl_Command imageCmd;	/* Token for image command (used to delete it
				 * when the image goes away). NULL means the
				 * image command has already been deleted. */
    int width, height;		/* Dimensions of image. */
    char *data;			/* Data comprising bitmap (suitable for input
				 * to XCreateBitmapFromData). May be NULL if
				 * no data. Malloc'ed. */
    char *maskData;		/* Data for bitmap's mask (suitable for input
				 * to XCreateBitmapFromData). Malloc'ed. */
    Tk_Uid fgUid;		/* Value of -foreground option (malloc'ed). */
    Tk_Uid bgUid;		/* Value of -background option (malloc'ed). */
    char *fileString;		/* Value of -file option (malloc'ed). */
    char *dataString;		/* Value of -data option (malloc'ed). */
    char *maskFileString;	/* Value of -maskfile option (malloc'ed). */
    char *maskDataString;	/* Value of -maskdata option (malloc'ed). */
    struct BitmapInstance *instancePtr;
				/* First in list of all instances associated
				 * with this model. */
} BitmapModel;
				 * with this master. */
} BitmapMaster;

/*
 * The following data structure represents all of the instances of an image
 * that lie within a particular window:
 */

typedef struct BitmapInstance {
    size_t refCount;		/* Number of instances that share this data
				 * structure. */
    BitmapModel *modelPtr;	/* Pointer to model for image. */
    BitmapMaster *masterPtr;	/* Pointer to master for image. */
    Tk_Window tkwin;		/* Window in which the instances will be
				 * displayed. */
    XColor *fg;			/* Foreground color for displaying image. */
    XColor *bg;			/* Background color for displaying image. */
    Pixmap bitmap;		/* The bitmap to display. */
    Pixmap mask;		/* Mask: only display bitmap pixels where
				 * there are 1's here. */
    GC gc;			/* Graphics context for displaying bitmap.
				 * None means there was an error while setting
				 * up the instance, so it cannot be
				 * displayed. */
    struct BitmapInstance *nextPtr;
				/* Next in list of all instance structures
				 * associated with modelPtr (NULL means end
				 * associated with masterPtr (NULL means end
				 * of list). */
} BitmapInstance;

/*
 * The type record for bitmap images:
 */

static int		GetByte(Tcl_Channel chan);
static int		ImgBmapCreate(Tcl_Interp *interp,
			    const char *name, Tcl_Size objc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageModel model,
			    void **clientDataPtr);
static void	*ImgBmapGet(Tk_Window tkwin, void *clientData);
static void		ImgBmapDisplay(void *clientData,
			    const char *name, int argc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageMaster master,
			    ClientData *clientDataPtr);
static ClientData	ImgBmapGet(Tk_Window tkwin, ClientData clientData);
static void		ImgBmapDisplay(ClientData clientData,
			    Display *display, Drawable drawable,
			    int imageX, int imageY, int width, int height,
			    int drawableX, int drawableY);
static void		ImgBmapFree(void *clientData, Display *display);
static void		ImgBmapDelete(void *clientData);
static int		ImgBmapPostscript(void *clientData,
static void		ImgBmapFree(ClientData clientData, Display *display);
static void		ImgBmapDelete(ClientData clientData);
static int		ImgBmapPostscript(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_PostscriptInfo psinfo, int x, int y,
			    int width, int height, int prepass);

Tk_ImageType tkBitmapImageType = {
    "bitmap",			/* name */
    ImgBmapCreate,		/* createProc */
104
105
106
107
108
109
110
111

112
113

114
115

116
117

118
119

120
121

122
123
124
125
126
127
128
104
105
106
107
108
109
110

111
112

113
114

115
116

117
118

119
120

121
122
123
124
125
126
127
128







-
+

-
+

-
+

-
+

-
+

-
+








/*
 * Information used for parsing configuration specs:
 */

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_UID, "-background", NULL, NULL,
	"", offsetof(BitmapModel, bgUid), 0, NULL},
	"", Tk_Offset(BitmapMaster, bgUid), 0, NULL},
    {TK_CONFIG_STRING, "-data", NULL, NULL,
	NULL, offsetof(BitmapModel, dataString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapMaster, dataString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_STRING, "-file", NULL, NULL,
	NULL, offsetof(BitmapModel, fileString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapMaster, fileString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_UID, "-foreground", NULL, NULL,
	"#000000", offsetof(BitmapModel, fgUid), 0, NULL},
	"#000000", Tk_Offset(BitmapMaster, fgUid), 0, NULL},
    {TK_CONFIG_STRING, "-maskdata", NULL, NULL,
	NULL, offsetof(BitmapModel, maskDataString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapMaster, maskDataString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_STRING, "-maskfile", NULL, NULL,
	NULL, offsetof(BitmapModel, maskFileString), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(BitmapMaster, maskFileString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * The following data structure is used to describe the state of parsing a
 * bitmap file or string. It is used for communication between TkGetBitmapData
 * and NextBitmapWord.
141
142
143
144
145
146
147
148
149
150



151
152
153


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178


179
180
181


182
183

184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
















204
205
206

207
208
209
210
211
212
213

214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232


233
234

235
236
237
238
239
240

241





242
243



244
245

246
247
248
249
250
251
252
253
254



255
256
257
258
259
260





261
262
263
264
265
266



267
268
269
270
271
272
273






274
275
276
277
278


279
280

281
282
283
284
285
286
287
288
289







290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306


307
308
309
310
311
312
313
314
315
316
317


318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342

343
344
345
346
347
348



349
350
351
352
353
354
355
356
357
358
359
360
361


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387


388
389

390
391
392
393
394


395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421

422
423

424
425
426
427
428
429
430
431
432
433
434
435

436
437
438
439


440
441
442


443
444
445
446
447
448
449
141
142
143
144
145
146
147



148
149
150
151


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177


178
179
180


181
182
183

184
185
186

187
188
















189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213

214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231


232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248


249
250
251
252
253
254
255
256
257
258
259
260



261
262
263
264





265
266
267
268
269
270
271
272



273
274
275
276






277
278
279
280
281
282
283
284
285


286
287
288

289
290
291







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

310
311
312
313


314
315
316
317
318
319
320
321
322
323
324


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350

351
352
353
354



355
356
357
358
359
360
361
362
363
364
365
366
367
368


369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394


395
396
397

398
399
400
401


402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431

432
433
434
435
436
437
438
439
440
441
442
443

444
445
446


447
448
449


450
451
452
453
454
455
456
457
458







-
-
-
+
+
+

-
-
+
+


















+





-
-
+
+

-
-
+
+

-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+






-
+







-
+









-
-
+
+

-
+






+

+
+
+
+
+
-
-
+
+
+


+






-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+



-
-
-
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+



-
-
+
+

-
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+











-
+



-
-
+
+









-
-
+
+
















-
+







-
+



-
-
-
+
+
+











-
-
+
+




















-
+



-
-
+
+

-
+



-
-
+
+









-
+
















-
+

-
+











-
+


-
-
+
+

-
-
+
+







    int wordLength;		/* Number of non-NULL bytes in word. */
} ParseInfo;

/*
 * Prototypes for procedures used only locally in this file:
 */

static int		ImgBmapCmd(void *clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static void		ImgBmapCmdDeletedProc(void *clientData);
static int		ImgBmapCmd(ClientData clientData, Tcl_Interp *interp,
			    int argc, Tcl_Obj *const objv[]);
static void		ImgBmapCmdDeletedProc(ClientData clientData);
static void		ImgBmapConfigureInstance(BitmapInstance *instancePtr);
static int		ImgBmapConfigureModel(BitmapModel *modelPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[], int flags);
static int		ImgBmapConfigureMaster(BitmapMaster *masterPtr,
			    int argc, Tcl_Obj *const objv[], int flags);
static int		NextBitmapWord(ParseInfo *parseInfoPtr);

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapCreate --
 *
 *	This procedure is called by the Tk image code to create "test" images.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	The data structure for a new image is allocated.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ImgBmapCreate(
    Tcl_Interp *interp,		/* Interpreter for application containing
				 * image. */
    const char *name,			/* Name to use for image. */
    Tcl_Size objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects for options (doesn't
    int argc,			/* Number of arguments. */
    Tcl_Obj *const argv[],	/* Argument objects for options (doesn't
				 * include image name or type). */
    TCL_UNUSED(const Tk_ImageType *),/* Pointer to our type record (not used). */
    Tk_ImageModel model,	/* Token for image, to be used by us in later
    const Tk_ImageType *typePtr,/* Pointer to our type record (not used). */
    Tk_ImageMaster master,	/* Token for image, to be used by us in later
				 * callbacks. */
    void **clientDataPtr)	/* Store manager's token for image here; it
    ClientData *clientDataPtr)	/* Store manager's token for image here; it
				 * will be returned in later callbacks. */
{
    BitmapModel *modelPtr = (BitmapModel *)ckalloc(sizeof(BitmapModel));
    BitmapMaster *masterPtr = ckalloc(sizeof(BitmapMaster));

    modelPtr->tkModel = model;
    modelPtr->interp = interp;
    modelPtr->imageCmd = Tcl_CreateObjCommand(interp, name, ImgBmapCmd,
	    modelPtr, ImgBmapCmdDeletedProc);
    modelPtr->width = modelPtr->height = 0;
    modelPtr->data = NULL;
    modelPtr->maskData = NULL;
    modelPtr->fgUid = NULL;
    modelPtr->bgUid = NULL;
    modelPtr->fileString = NULL;
    modelPtr->dataString = NULL;
    modelPtr->maskFileString = NULL;
    modelPtr->maskDataString = NULL;
    modelPtr->instancePtr = NULL;
    if (ImgBmapConfigureModel(modelPtr, objc, objv, 0) != TCL_OK) {
	ImgBmapDelete(modelPtr);
    masterPtr->tkMaster = master;
    masterPtr->interp = interp;
    masterPtr->imageCmd = Tcl_CreateObjCommand(interp, name, ImgBmapCmd,
	    masterPtr, ImgBmapCmdDeletedProc);
    masterPtr->width = masterPtr->height = 0;
    masterPtr->data = NULL;
    masterPtr->maskData = NULL;
    masterPtr->fgUid = NULL;
    masterPtr->bgUid = NULL;
    masterPtr->fileString = NULL;
    masterPtr->dataString = NULL;
    masterPtr->maskFileString = NULL;
    masterPtr->maskDataString = NULL;
    masterPtr->instancePtr = NULL;
    if (ImgBmapConfigureMaster(masterPtr, argc, argv, 0) != TCL_OK) {
	ImgBmapDelete(masterPtr);
	return TCL_ERROR;
    }
    *clientDataPtr = modelPtr;
    *clientDataPtr = masterPtr;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapConfigureModel --
 * ImgBmapConfigureMaster --
 *
 *	This procedure is called when a bitmap image is created or
 *	reconfigured. It process configuration options and resets any
 *	instances of the image.
 *
 * Results:
 *	A standard Tcl return value. If TCL_ERROR is returned then an error
 *	message is left in the modelPtr->interp's result.
 *	message is left in the masterPtr->interp's result.
 *
 * Side effects:
 *	Existing instances of the image will be redisplayed to match the new
 *	configuration options.
 *
 *----------------------------------------------------------------------
 */

static int
ImgBmapConfigureModel(
    BitmapModel *modelPtr,	/* Pointer to data structure describing
ImgBmapConfigureMaster(
    BitmapMaster *masterPtr,	/* Pointer to data structure describing
				 * overall bitmap image to (reconfigure). */
    Tcl_Size objc,			/* Number of entries in objv. */
    int objc,			/* Number of entries in objv. */
    Tcl_Obj *const objv[],	/* Pairs of configuration options for image. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget, such
				 * as TK_CONFIG_ARGV_ONLY. */
{
    BitmapInstance *instancePtr;
    int maskWidth, maskHeight, dummy1, dummy2;
    const char **argv = ckalloc((objc+1) * sizeof(char *));

    for (dummy1 = 0; dummy1 < objc; dummy1++) {
	argv[dummy1] = Tcl_GetString(objv[dummy1]);
    }
    argv[objc] = NULL;

    if (Tk_ConfigureWidget(modelPtr->interp, Tk_MainWindow(modelPtr->interp),
	    configSpecs, objc, objv, modelPtr, flags) != TCL_OK) {
    if (Tk_ConfigureWidget(masterPtr->interp, Tk_MainWindow(masterPtr->interp),
	    configSpecs, objc, argv, (char *) masterPtr, flags) != TCL_OK) {
	ckfree(argv);
	return TCL_ERROR;
    }
    ckfree(argv);

    /*
     * Parse the bitmap and/or mask to create binary data. Make sure that the
     * bitmap and mask have the same dimensions.
     */

    if (modelPtr->data != NULL) {
	ckfree(modelPtr->data);
	modelPtr->data = NULL;
    if (masterPtr->data != NULL) {
	ckfree(masterPtr->data);
	masterPtr->data = NULL;
    }
    if ((modelPtr->fileString != NULL) || (modelPtr->dataString != NULL)) {
	modelPtr->data = TkGetBitmapData(modelPtr->interp,
		modelPtr->dataString, modelPtr->fileString,
		&modelPtr->width, &modelPtr->height, &dummy1, &dummy2);
	if (modelPtr->data == NULL) {
    if ((masterPtr->fileString != NULL) || (masterPtr->dataString != NULL)) {
	masterPtr->data = TkGetBitmapData(masterPtr->interp,
		masterPtr->dataString, masterPtr->fileString,
		&masterPtr->width, &masterPtr->height, &dummy1, &dummy2);
	if (masterPtr->data == NULL) {
	    return TCL_ERROR;
	}
    }
    if (modelPtr->maskData != NULL) {
	ckfree(modelPtr->maskData);
	modelPtr->maskData = NULL;
    if (masterPtr->maskData != NULL) {
	ckfree(masterPtr->maskData);
	masterPtr->maskData = NULL;
    }
    if ((modelPtr->maskFileString != NULL)
	    || (modelPtr->maskDataString != NULL)) {
	if (modelPtr->data == NULL) {
	    Tcl_SetObjResult(modelPtr->interp, Tcl_NewStringObj(
		    "can't have mask without bitmap", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(modelPtr->interp, "TK", "IMAGE", "BITMAP",
    if ((masterPtr->maskFileString != NULL)
	    || (masterPtr->maskDataString != NULL)) {
	if (masterPtr->data == NULL) {
	    Tcl_SetObjResult(masterPtr->interp, Tcl_NewStringObj(
		    "can't have mask without bitmap", -1));
	    Tcl_SetErrorCode(masterPtr->interp, "TK", "IMAGE", "BITMAP",
		    "NO_BITMAP", NULL);
	    return TCL_ERROR;
	}
	modelPtr->maskData = TkGetBitmapData(modelPtr->interp,
		modelPtr->maskDataString, modelPtr->maskFileString,
	masterPtr->maskData = TkGetBitmapData(masterPtr->interp,
		masterPtr->maskDataString, masterPtr->maskFileString,
		&maskWidth, &maskHeight, &dummy1, &dummy2);
	if (modelPtr->maskData == NULL) {
	if (masterPtr->maskData == NULL) {
	    return TCL_ERROR;
	}
	if ((maskWidth != modelPtr->width)
		|| (maskHeight != modelPtr->height)) {
	    ckfree(modelPtr->maskData);
	    modelPtr->maskData = NULL;
	    Tcl_SetObjResult(modelPtr->interp, Tcl_NewStringObj(
		    "bitmap and mask have different sizes", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(modelPtr->interp, "TK", "IMAGE", "BITMAP",
	if ((maskWidth != masterPtr->width)
		|| (maskHeight != masterPtr->height)) {
	    ckfree(masterPtr->maskData);
	    masterPtr->maskData = NULL;
	    Tcl_SetObjResult(masterPtr->interp, Tcl_NewStringObj(
		    "bitmap and mask have different sizes", -1));
	    Tcl_SetErrorCode(masterPtr->interp, "TK", "IMAGE", "BITMAP",
		    "MASK_SIZE", NULL);
	    return TCL_ERROR;
	}
    }

    /*
     * Cycle through all of the instances of this image, regenerating the
     * information for each instance. Then force the image to be redisplayed
     * everywhere that it is used.
     */

    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	ImgBmapConfigureInstance(instancePtr);
    }
    Tk_ImageChanged(modelPtr->tkModel, 0, 0, modelPtr->width,
	    modelPtr->height, modelPtr->width, modelPtr->height);
    Tk_ImageChanged(masterPtr->tkMaster, 0, 0, masterPtr->width,
	    masterPtr->height, masterPtr->width, masterPtr->height);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapConfigureInstance --
 *
 *	This procedure is called to create displaying information for a bitmap
 *	image instance based on the configuration information in the model.
 *	It is invoked both when new instances are created and when the model
 *	image instance based on the configuration information in the master.
 *	It is invoked both when new instances are created and when the master
 *	is reconfigured.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Generates errors via Tcl_BackgroundException if there are problems in
 *	setting up the instance.
 *
 *----------------------------------------------------------------------
 */

static void
ImgBmapConfigureInstance(
    BitmapInstance *instancePtr)/* Instance to reconfigure. */
{
    BitmapModel *modelPtr = instancePtr->modelPtr;
    BitmapMaster *masterPtr = instancePtr->masterPtr;
    XColor *colorPtr;
    XGCValues gcValues;
    GC gc;
    unsigned int mask;
    Pixmap oldBitmap, oldMask;

    /*
     * For each of the options in modelPtr, translate the string form into an
     * For each of the options in masterPtr, translate the string form into an
     * internal form appropriate for instancePtr.
     */

    if (*modelPtr->bgUid != 0) {
	colorPtr = Tk_GetColor(modelPtr->interp, instancePtr->tkwin,
		modelPtr->bgUid);
    if (*masterPtr->bgUid != 0) {
	colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin,
		masterPtr->bgUid);
	if (colorPtr == NULL) {
	    goto error;
	}
    } else {
	colorPtr = NULL;
    }
    if (instancePtr->bg != NULL) {
	Tk_FreeColor(instancePtr->bg);
    }
    instancePtr->bg = colorPtr;

    colorPtr = Tk_GetColor(modelPtr->interp, instancePtr->tkwin,
	    modelPtr->fgUid);
    colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin,
	    masterPtr->fgUid);
    if (colorPtr == NULL) {
	goto error;
    }
    if (instancePtr->fg != NULL) {
	Tk_FreeColor(instancePtr->fg);
    }
    instancePtr->fg = colorPtr;

    /*
     * Careful: We have to allocate new Pixmaps before deleting the old ones.
     * Otherwise, The XID allocator will always return the same XID for the
     * new Pixmaps as was used for the old Pixmaps. And that will prevent the
     * data and/or mask from changing in the GC below.
     */

    oldBitmap = instancePtr->bitmap;
    instancePtr->bitmap = None;
    oldMask = instancePtr->mask;
    instancePtr->mask = None;

    if (modelPtr->data != NULL) {
    if (masterPtr->data != NULL) {
	instancePtr->bitmap = XCreateBitmapFromData(
		Tk_Display(instancePtr->tkwin),
		RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)),
		modelPtr->data, (unsigned) modelPtr->width,
		(unsigned) modelPtr->height);
		masterPtr->data, (unsigned) masterPtr->width,
		(unsigned) masterPtr->height);
    }
    if (modelPtr->maskData != NULL) {
    if (masterPtr->maskData != NULL) {
	instancePtr->mask = XCreateBitmapFromData(
		Tk_Display(instancePtr->tkwin),
		RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)),
		modelPtr->maskData, (unsigned) modelPtr->width,
		(unsigned) modelPtr->height);
		masterPtr->maskData, (unsigned) masterPtr->width,
		(unsigned) masterPtr->height);
    }

    if (oldMask != None) {
	Tk_FreePixmap(Tk_Display(instancePtr->tkwin), oldMask);
    }
    if (oldBitmap != None) {
	Tk_FreePixmap(Tk_Display(instancePtr->tkwin), oldBitmap);
    }

    if (modelPtr->data != NULL) {
    if (masterPtr->data != NULL) {
	gcValues.foreground = instancePtr->fg->pixel;
	gcValues.graphics_exposures = False;
	mask = GCForeground|GCGraphicsExposures;
	if (instancePtr->bg != NULL) {
	    gcValues.background = instancePtr->bg->pixel;
	    mask |= GCBackground;
	    if (instancePtr->mask != None) {
		gcValues.clip_mask = instancePtr->mask;
		mask |= GCClipMask;
	    }
	} else {
	    gcValues.clip_mask = instancePtr->bitmap;
	    mask |= GCClipMask;
	}
	gc = Tk_GetGC(instancePtr->tkwin, mask, &gcValues);
    } else {
	gc = NULL;
	gc = None;
    }
    if (instancePtr->gc != NULL) {
    if (instancePtr->gc != None) {
	Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc);
    }
    instancePtr->gc = gc;
    return;

  error:
    /*
     * An error occurred: clear the graphics context in the instance to make
     * it clear that this instance cannot be displayed. Then report the error.
     */

    if (instancePtr->gc != NULL) {
    if (instancePtr->gc != None) {
	Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc);
    }
    instancePtr->gc = NULL;
    Tcl_AppendObjToErrorInfo(modelPtr->interp, Tcl_ObjPrintf(
    instancePtr->gc = None;
    Tcl_AppendObjToErrorInfo(masterPtr->interp, Tcl_ObjPrintf(
	    "\n    (while configuring image \"%s\")", Tk_NameOfImage(
	    modelPtr->tkModel)));
    Tcl_BackgroundException(modelPtr->interp, TCL_ERROR);
	    masterPtr->tkMaster)));
    Tcl_BackgroundException(masterPtr->interp, TCL_ERROR);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetBitmapData --
 *
487
488
489
490
491
492
493
494

495
496

497
498
499
500
501
502
503
504
505
506
507
508
509
496
497
498
499
500
501
502

503
504

505

506
507
508
509

510
511
512
513
514
515
516







-
+

-
+
-




-







	if ((interp != NULL) && Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't get bitmap data from a file in a safe interpreter",
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "BITMAP_FILE", NULL);
	    return NULL;
	}
	expandedFileName = Tcl_TranslateFileName(NULL, fileName, &buffer);
	expandedFileName = Tcl_TranslateFileName(interp, fileName, &buffer);
	if (expandedFileName == NULL) {
	    Tcl_SetErrno(ENOENT);
	    return NULL;
	    goto cannotRead;
	}
	pi.chan = Tcl_OpenFileChannel(interp, expandedFileName, "r", 0);
	Tcl_DStringFree(&buffer);
	if (pi.chan == NULL) {
	cannotRead:
	    if (interp != NULL) {
		Tcl_ResetResult(interp);
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"couldn't read bitmap file \"%s\": %s",
			fileName, Tcl_PosixError(interp)));
	    }
	    return NULL;
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
598
599
600
601
602
603
604

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
630







-
+

















-
+







		    goto getData;
		}
	    }
	} else if ((pi.word[0] == '{') && (pi.word[1] == 0)) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"format error in bitmap data; looks like it's an"
			" obsolete X10 bitmap file", TCL_INDEX_NONE));
			" obsolete X10 bitmap file", -1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "BITMAP", "OBSOLETE",
			NULL);
	    }
	    goto errorCleanup;
	}
    }

    /*
     * Now we've read everything but the data. Allocate an array and read in
     * the data.
     */

  getData:
    if ((width <= 0) || (height <= 0)) {
	goto error;
    }
    numBytes = ((width+7)/8) * height;
    data = (char *)ckalloc(numBytes);
    data = ckalloc(numBytes);
    for (p = data; numBytes > 0; p++, numBytes--) {
	if (NextBitmapWord(&pi) != TCL_OK) {
	    goto error;
	}
	*p = (char) strtol(pi.word, &end, 0);
	if (end == pi.word) {
	    goto error;
636
637
638
639
640
641
642
643

644
645
646
647
648
649
650
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657







-
+







    *hotXPtr = hotX;
    *hotYPtr = hotY;
    return data;

  error:
    if (interp != NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"format error in bitmap data", TCL_INDEX_NONE));
		"format error in bitmap data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "BITMAP", "FORMAT", NULL);
    }

  errorCleanup:
    if (data != NULL) {
	ckfree(data);
    }
740
741
742
743
744
745
746
747

748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

772
773
774
775

776
777
778

779
780
781

782
783
784
785
786
787
788
747
748
749
750
751
752
753

754
755
756
757
758
759

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777

778
779
780
781

782
783
784

785
786
787

788
789
790
791
792
793
794
795







-
+





-
+

















-
+



-
+


-
+


-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
ImgBmapCmd(
    void *clientData,	/* Information about the image model. */
    ClientData clientData,	/* Information about the image master. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const bmapOptions[] = {"cget", "configure", NULL};
    BitmapModel *modelPtr = (BitmapModel *)clientData;
    BitmapMaster *masterPtr = clientData;
    int index;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], bmapOptions,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    switch (index) {
    case 0: /* cget */
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    return TCL_ERROR;
	}
	return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs,
		modelPtr, Tcl_GetString(objv[2]), 0);
		(char *) masterPtr, Tcl_GetString(objv[2]), 0);
    case 1: /* configure */
	if (objc == 2) {
	    return Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
		    configSpecs, modelPtr, NULL, 0);
		    configSpecs, (char *) masterPtr, NULL, 0);
	} else if (objc == 3) {
	    return Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
		    configSpecs, modelPtr,
		    configSpecs, (char *) masterPtr,
		    Tcl_GetString(objv[2]), 0);
	} else {
	    return ImgBmapConfigureModel(modelPtr, objc-2, objv+2,
	    return ImgBmapConfigureMaster(masterPtr, objc-2, objv+2,
		    TK_CONFIG_ARGV_ONLY);
	}
    default:
	Tcl_Panic("bad const entries to bmapOptions in ImgBmapCmd");
	return TCL_OK;
    }
}
801
802
803
804
805
806
807
808

809
810
811
812

813
814
815

816
817
818
819
820
821
822
823

824
825
826
827
828
829
830
831
832
833
834
835
836

837
838

839
840
841
842
843
844
845
846



847
848
849
850
851
852
853
854
855


856
857
858
859
860
861
862
808
809
810
811
812
813
814

815
816
817
818

819
820
821

822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837
838
839
840
841
842

843
844

845
846
847
848
849
850



851
852
853
854
855
856
857
858
859
860


861
862
863
864
865
866
867
868
869







-
+



-
+


-
+







-
+












-
+

-
+





-
-
-
+
+
+







-
-
+
+







 * Side effects:
 *	A data structure is set up for the instance (or, an existing instance
 *	is re-used for the new one).
 *
 *----------------------------------------------------------------------
 */

static void *
static ClientData
ImgBmapGet(
    Tk_Window tkwin,		/* Window in which the instance will be
				 * used. */
    void *modelData)	/* Pointer to our model structure for the
    ClientData masterData)	/* Pointer to our master structure for the
				 * image. */
{
    BitmapModel *modelPtr = (BitmapModel *)modelData;
    BitmapMaster *masterPtr = masterData;
    BitmapInstance *instancePtr;

    /*
     * See if there is already an instance for this window. If so then just
     * re-use it.
     */

    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	if (instancePtr->tkwin == tkwin) {
	    instancePtr->refCount++;
	    return instancePtr;
	}
    }

    /*
     * The image isn't already in use in this window. Make a new instance of
     * the image.
     */

    instancePtr = (BitmapInstance *)ckalloc(sizeof(BitmapInstance));
    instancePtr = ckalloc(sizeof(BitmapInstance));
    instancePtr->refCount = 1;
    instancePtr->modelPtr = modelPtr;
    instancePtr->masterPtr = masterPtr;
    instancePtr->tkwin = tkwin;
    instancePtr->fg = NULL;
    instancePtr->bg = NULL;
    instancePtr->bitmap = None;
    instancePtr->mask = None;
    instancePtr->gc = NULL;
    instancePtr->nextPtr = modelPtr->instancePtr;
    modelPtr->instancePtr = instancePtr;
    instancePtr->gc = None;
    instancePtr->nextPtr = masterPtr->instancePtr;
    masterPtr->instancePtr = instancePtr;
    ImgBmapConfigureInstance(instancePtr);

    /*
     * If this is the first instance, must set the size of the image.
     */

    if (instancePtr->nextPtr == NULL) {
	Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0, modelPtr->width,
		modelPtr->height);
	Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, masterPtr->width,
		masterPtr->height);
    }

    return instancePtr;
}

/*
 *----------------------------------------------------------------------
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
887
888
889
890

891
892
893
894
895
896
897
898

899
900
901
902
903
904
905
879
880
881
882
883
884
885

886
887
888
889
890
891
892
893
894
895
896

897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
912







-
+










-
+







-
+







 *	A portion of the image gets rendered in a pixmap or window.
 *
 *----------------------------------------------------------------------
 */

static void
ImgBmapDisplay(
    void *clientData,	/* Pointer to BitmapInstance structure for
    ClientData clientData,	/* Pointer to BitmapInstance structure for
				 * instance to be displayed. */
    Display *display,		/* Display on which to draw image. */
    Drawable drawable,		/* Pixmap or window in which to draw image. */
    int imageX, int imageY,	/* Upper-left corner of region within image to
				 * draw. */
    int width, int height,	/* Dimensions of region within image to draw. */
    int drawableX, int drawableY)
				/* Coordinates within drawable that correspond
				 * to imageX and imageY. */
{
    BitmapInstance *instancePtr = (BitmapInstance *)clientData;
    BitmapInstance *instancePtr = clientData;
    int masking;

    /*
     * If there's no graphics context, it means that an error occurred while
     * creating the image instance so it can't be displayed.
     */

    if (instancePtr->gc == NULL) {
    if (instancePtr->gc == None) {
	return;
    }

    /*
     * If masking is in effect, must modify the mask origin within the
     * graphics context to line up with the image's origin. Then draw the
     * image and reset the clip origin, if there's a mask.
933
934
935
936
937
938
939
940

941
942
943
944

945
946
947
948
949
950
951
940
941
942
943
944
945
946

947
948
949
950

951
952
953
954
955
956
957
958







-
+



-
+







 *	Internal data structures get cleaned up.
 *
 *----------------------------------------------------------------------
 */

static void
ImgBmapFree(
    void *clientData,	/* Pointer to BitmapInstance structure for
    ClientData clientData,	/* Pointer to BitmapInstance structure for
				 * instance to be displayed. */
    Display *display)		/* Display containing window that used image. */
{
    BitmapInstance *instancePtr = (BitmapInstance *)clientData;
    BitmapInstance *instancePtr = clientData;
    BitmapInstance *prevPtr;

    if (instancePtr->refCount-- > 1) {
	return;
    }

    /*
961
962
963
964
965
966
967
968

969
970
971
972


973
974

975
976
977
978
979
980
981
982
983
984
985
986
987
988

989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002

1003
1004
1005

1006
1007

1008
1009
1010
1011
1012



1013
1014
1015


1016
1017
1018


1019
1020
1021


1022
1023
1024
1025
1026
1027
1028
968
969
970
971
972
973
974

975
976
977


978
979
980

981
982
983
984
985
986
987
988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011

1012
1013

1014
1015
1016



1017
1018
1019
1020


1021
1022
1023


1024
1025
1026


1027
1028
1029
1030
1031
1032
1033
1034
1035







-
+


-
-
+
+

-
+













-
+













-
+


-
+

-
+


-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+







    }
    if (instancePtr->bitmap != None) {
	Tk_FreePixmap(display, instancePtr->bitmap);
    }
    if (instancePtr->mask != None) {
	Tk_FreePixmap(display, instancePtr->mask);
    }
    if (instancePtr->gc != NULL) {
    if (instancePtr->gc != None) {
	Tk_FreeGC(display, instancePtr->gc);
    }
    if (instancePtr->modelPtr->instancePtr == instancePtr) {
	instancePtr->modelPtr->instancePtr = instancePtr->nextPtr;
    if (instancePtr->masterPtr->instancePtr == instancePtr) {
	instancePtr->masterPtr->instancePtr = instancePtr->nextPtr;
    } else {
	for (prevPtr = instancePtr->modelPtr->instancePtr;
	for (prevPtr = instancePtr->masterPtr->instancePtr;
		prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) {
	    /* Empty loop body */
	}
	prevPtr->nextPtr = instancePtr->nextPtr;
    }
    ckfree(instancePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapDelete --
 *
 *	This procedure is called by the image code to delete the model
 *	This procedure is called by the image code to delete the master
 *	structure for an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Resources associated with the image get freed.
 *
 *----------------------------------------------------------------------
 */

static void
ImgBmapDelete(
    void *modelData)	/* Pointer to BitmapModel structure for
    ClientData masterData)	/* Pointer to BitmapMaster structure for
				 * image. Must not have any more instances. */
{
    BitmapModel *modelPtr = (BitmapModel *)modelData;
    BitmapMaster *masterPtr = masterData;

    if (modelPtr->instancePtr != NULL) {
    if (masterPtr->instancePtr != NULL) {
	Tcl_Panic("tried to delete bitmap image when instances still exist");
    }
    modelPtr->tkModel = NULL;
    if (modelPtr->imageCmd != NULL) {
	Tcl_DeleteCommandFromToken(modelPtr->interp, modelPtr->imageCmd);
    masterPtr->tkMaster = NULL;
    if (masterPtr->imageCmd != NULL) {
	Tcl_DeleteCommandFromToken(masterPtr->interp, masterPtr->imageCmd);
    }
    if (modelPtr->data != NULL) {
	ckfree(modelPtr->data);
    if (masterPtr->data != NULL) {
	ckfree(masterPtr->data);
    }
    if (modelPtr->maskData != NULL) {
	ckfree(modelPtr->maskData);
    if (masterPtr->maskData != NULL) {
	ckfree(masterPtr->maskData);
    }
    Tk_FreeOptions(configSpecs, modelPtr, NULL, 0);
    ckfree(modelPtr);
    Tk_FreeOptions(configSpecs, (char *) masterPtr, NULL, 0);
    ckfree(masterPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapCmdDeletedProc --
 *
1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046

1047
1048
1049
1050



1051
1052
1053
1054
1055
1056
1057
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052

1053
1054



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064







-
+


-
+

-
-
-
+
+
+







 *	The image is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ImgBmapCmdDeletedProc(
    void *clientData)	/* Pointer to BitmapModel structure for
    ClientData clientData)	/* Pointer to BitmapMaster structure for
				 * image. */
{
    BitmapModel *modelPtr = (BitmapModel *)clientData;
    BitmapMaster *masterPtr = clientData;

    modelPtr->imageCmd = NULL;
    if (modelPtr->tkModel != NULL) {
	Tk_DeleteImage(modelPtr->interp, Tk_NameOfImage(modelPtr->tkModel));
    masterPtr->imageCmd = NULL;
    if (masterPtr->tkMaster != NULL) {
	Tk_DeleteImage(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster));
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GetByte --
1068
1069
1070
1071
1072
1073
1074

1075
1076


1077
1078
1079
1080
1081
1082
1083
1075
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092







+

-
+
+







 */

static int
GetByte(
    Tcl_Channel chan)	/* The channel we read from. */
{
    char buffer;
    int size;

    if (Tcl_Read(chan, &buffer, 1) != 1) {
    size = Tcl_Read(chan, &buffer, 1);
    if (size <= 0) {
	return EOF;
    } else {
	return buffer;
    }
}

/*
1151
1152
1153
1154
1155
1156
1157
1158

1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169

1170
1171
1172
1173
1174
1175
1176
1177







-
+


-
+








    nBytePerRow = (width + 7) / 8;
    for (i=0; i<height; i++) {
	for (j=0; j<nBytePerRow; j++) {
	    Tcl_AppendPrintfToObj(psObj, " %02x",
		    bit_reverse[0xff & data[i*nBytePerRow + j]]);
	}
	Tcl_AppendToObj(psObj, "\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "\n", -1);
    }

    Tcl_AppendToObj(psObj, ">} imagemask \n", TCL_INDEX_NONE);
    Tcl_AppendToObj(psObj, ">} imagemask \n", -1);
}

/*
 *----------------------------------------------------------------------
 *
 * ImgBmapPostscript --
 *
1177
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213

1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224

1225
1226
1227
1228
1229
1230
1231
1232







-
+






-
+











-
+









-
+


-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
ImgBmapPostscript(
    void *clientData,
    ClientData clientData,
    Tcl_Interp *interp,
    Tk_Window tkwin,
    Tk_PostscriptInfo psinfo,
    int x, int y, int width, int height,
    int prepass)
{
    BitmapModel *modelPtr = (BitmapModel *)clientData;
    BitmapMaster *masterPtr = clientData;
    Tcl_InterpState interpState;
    Tcl_Obj *psObj;

    if (prepass) {
	return TCL_OK;
    }

    /*
     * There is nothing to do for bitmaps with zero width or height.
     */

    if (width<=0 || height<=0 || modelPtr->width<=0 || modelPtr->height<=0){
    if (width<=0 || height<=0 || masterPtr->width<=0 || masterPtr->height<=0){
	return TCL_OK;
    }

    /*
     * Some postscript implementations cannot handle bitmap strings longer
     * than about 60k characters. If the bitmap data is that big or bigger,
     * we bail out.
     */

    if (modelPtr->width*modelPtr->height > 60000) {
    if (masterPtr->width*masterPtr->height > 60000) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"unable to generate postscript for bitmaps larger than 60000"
		" pixels", TCL_INDEX_NONE));
		" pixels", -1));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "PS", "MEMLIMIT", NULL);
	return TCL_ERROR;
    }

    /*
     * Make our working space.
     */
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266

1267
1268
1269


1270
1271
1272
1273
1274
1275
1276
1277

1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1288
1289


1290
1291
1292
1293
1294
1295
1296
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271

1272
1273
1274

1275
1276


1277
1278
1279
1280
1281
1282
1283
1284
1285

1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296


1297
1298
1299
1300
1301
1302
1303
1304
1305







-
+


-
+







-
+


-
+

-
-
+
+







-
+


-
+







-
-
+
+







     * Color the background, if there is one. This step is skipped if the
     * background is transparent. If the background is not transparent and
     * there is no background mask, then color the complete rectangle that
     * encloses the bitmap. If there is a background mask, then only apply
     * color to the bits specified by the mask.
     */

    if ((modelPtr->bgUid != NULL) && (modelPtr->bgUid[0] != '\000')) {
    if ((masterPtr->bgUid != NULL) && (masterPtr->bgUid[0] != '\000')) {
	XColor color;

	TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), modelPtr->bgUid,
	TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->bgUid,
		&color);
	Tcl_ResetResult(interp);
	if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (modelPtr->maskData == NULL) {
	if (masterPtr->maskData == NULL) {
	    Tcl_AppendToObj(psObj,
		    "0 0 moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto "
		    "closepath fill\n", TCL_INDEX_NONE);
		    "closepath fill\n", -1);
	} else {
	    ImgBmapPsImagemask(psObj, modelPtr->width, modelPtr->height,
		    modelPtr->maskData);
	    ImgBmapPsImagemask(psObj, masterPtr->width, masterPtr->height,
		    masterPtr->maskData);
	}
    }

    /*
     * Draw the bitmap foreground, assuming there is one.
     */

    if ((modelPtr->fgUid != NULL) && (modelPtr->data != NULL)) {
    if ((masterPtr->fgUid != NULL) && (masterPtr->data != NULL)) {
	XColor color;

	TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), modelPtr->fgUid,
	TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->fgUid,
		&color);
	Tcl_ResetResult(interp);
	if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	ImgBmapPsImagemask(psObj, modelPtr->width, modelPtr->height,
		modelPtr->data);
	ImgBmapPsImagemask(psObj, masterPtr->width, masterPtr->height,
		masterPtr->data);
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

    (void) Tcl_RestoreInterpState(interp, interpState);

Changes to generic/tkImgGIF.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14




15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18
19
20
21










-
-
-
-
+
+
+
+







/*
 * tkImgGIF.c --
 *
 *	A photo image file handler for GIF files. Reads 87a and 89a GIF files.
 *	At present, there only is a file write function. GIF images may be
 *	read using the -data option of the photo image. The data may be given
 *	as a binary string in a Tcl_Obj or by representing the data as BASE64
 *	encoded ascii. Derived from the giftoppm code found in the pbmplus
 *	package and tkImgFmtPPM.c in the tk4.0b2 distribution.
 *
 * Copyright © Reed Wade ([email protected]), University of Tennessee
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 1997 Australian National University
 * Copyright © 2005-2010 Donal K. Fellows
 * Copyright (c) Reed Wade ([email protected]), University of Tennessee
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1997 Australian National University
 * Copyright (c) 2005-2010 Donal K. Fellows
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * This file also contains code from the giftoppm program, which is
 * copyrighted as follows:
 *
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78

79
80

81
82
83
84
85
86
87
42
43
44
45
46
47
48












49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65

66
67

68
69
70
71
72
73
74
75







-
-
-
-
-
-
-
-
-
-
-
-









-
+







-
+

-
+








#define GIF_SPECIAL	(256)
#define GIF_PAD		(GIF_SPECIAL+1)
#define GIF_SPACE	(GIF_SPECIAL+2)
#define GIF_BAD		(GIF_SPECIAL+3)
#define GIF_DONE	(GIF_SPECIAL+4)

/*
 * structure to hold the data of a Graphic Control Extension block.
 */

typedef struct {
    int blockPresent;		/* if 1, the block was read and is in scope */
    int transparent;		/* Transparency index */
    int delayTime;		/* update delay time in 10ms */
    int disposalMethod;		/* disposal method 0-3 */
    int userInteraction;	/* user interaction 0/1 */
} GIFGraphicControlExtensionBlock;

/*
 * structure to "mimic" FILE for Mread, so we can look like fread. The decoder
 * state keeps track of which byte we are about to read, or EOF.
 */

typedef struct mFile {
    unsigned char *data;	/* mmencoded source string */
    int c;			/* bits left over from previous character */
    int state;			/* decoder state (0-4 or GIF_DONE) */
    Tcl_Size length;			/* Total amount of bytes in data */
    int length;			/* Total amount of bytes in data */
} MFile;

/*
 * Non-ASCII encoding support:
 * Most data in a GIF image is binary and is treated as such. However, a few
 * key bits are stashed in ASCII. If we try to compare those pieces to the
 * char they represent, it will fail on any non-ASCII (eg, EBCDIC) system. To
 * accommodate these systems, we test against the numeric value of the ASCII
 * accomodate these systems, we test against the numeric value of the ASCII
 * characters instead of the characters themselves. This is encoding
 * independent.
 * independant.
 */

static const char GIF87a[] = {			/* ASCII GIF87a */
    0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x00
};
static const char GIF89a[] = {			/* ASCII GIF89a */
    0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00
119
120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135



136
137
138
139
140


141
142

143
144

145
146
147
148

149
150

151
152
153

154
155
156
157

158
159
160
161
162
163

164
165
166
167
168
169
170
107
108
109
110
111
112
113


114
115
116
117
118
119
120



121
122
123

124
125


126
127


128


129

130


131
132

133
134


135
136

137

138

139

140
141

142
143
144
145
146
147
148
149







-
-
+
+





-
-
-
+
+
+
-


-
-
+
+
-
-
+
-
-
+
-

-
-
+

-
+

-
-
+

-

-
+
-

-


-
+







} GIFImageConfig;

/*
 * Type of a function used to do the writing to a file or buffer when
 * serializing in the GIF format.
 */

typedef Tcl_Size (WriteBytesFunc) (void *clientData, const char *bytes,
			    Tcl_Size byteCount);
typedef int (WriteBytesFunc) (ClientData clientData, const char *bytes,
			    int byteCount);

/*
 * The format record for the GIF file format:
 */

static int		FileMatchGIF(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *format,
			    Tcl_Obj *metadataInObj, int *widthPtr,
static int		FileMatchGIF(Tcl_Channel chan, const char *fileName,
			    Tcl_Obj *format, int *widthPtr, int *heightPtr,
			    Tcl_Interp *interp);
			    int *heightPtr, Tcl_Obj *metadataOutObj);
static int		FileReadGIF(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *format,
			    Tcl_Obj *metadataInObj, Tk_PhotoHandle imageHandle,
			    int destX, int destY, int width, int height,
			    Tk_PhotoHandle imageHandle, int destX, int destY,
			    int width, int height, int srcX, int srcY);
			    int srcX, int srcY, Tcl_Obj *metadataOutObj);
static int		StringMatchGIF(Tcl_Interp *interp, Tcl_Obj *dataObj,
static int		StringMatchGIF(Tcl_Obj *dataObj, Tcl_Obj *format,
			    Tcl_Obj *format, Tcl_Obj *metadataInObj,
			    int *widthPtr, int *heightPtr,
			    int *widthPtr, int *heightPtr, Tcl_Interp *interp);
			    Tcl_Obj *metadataOutObj);
static int		StringReadGIF(Tcl_Interp *interp, Tcl_Obj *dataObj,
			    Tcl_Obj *format, Tcl_Obj *metadataInObj,
			    Tk_PhotoHandle imageHandle,
			    Tcl_Obj *format, Tk_PhotoHandle imageHandle,
			    int destX, int destY, int width, int height,
			    int srcX, int srcY, Tcl_Obj *metadataOutObj);
			    int srcX, int srcY);
static int		FileWriteGIF(Tcl_Interp *interp, const char *filename,
			    Tcl_Obj *format, Tcl_Obj *metadataInObj,
			    Tk_PhotoImageBlock *blockPtr);
			    Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
static int		StringWriteGIF(Tcl_Interp *interp, Tcl_Obj *format,
			    Tcl_Obj *metadataInObj,
			    Tk_PhotoImageBlock *blockPtr);
static int		CommonWriteGIF(Tcl_Interp *interp,
static int		CommonWriteGIF(Tcl_Interp *interp, ClientData clientData,
			    void *clientData,
			    WriteBytesFunc *writeProc, Tcl_Obj *format,
			    Tcl_Obj *metadataInObj,
			    Tk_PhotoImageBlock *blockPtr);

Tk_PhotoImageFormatVersion3 tkImgFmtGIF = {
Tk_PhotoImageFormat tkImgFmtGIF = {
    "gif",		/* name */
    FileMatchGIF,	/* fileMatchProc */
    StringMatchGIF,	/* stringMatchProc */
    FileReadGIF,	/* fileReadProc */
    StringReadGIF,	/* stringReadProc */
    FileWriteGIF,	/* fileWriteProc */
    StringWriteGIF,	/* stringWriteProc */
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217



218
219
220
221
222

223
224
225
226
227
228
229
161
162
163
164
165
166
167


168
169



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189



190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







-
-


-
-
-
+



















-
-
-
+
+
+




-
+







#define MAX_LWZ_BITS		12
#define LM_to_uint(a,b)		(((b)<<8)|(a))

/*
 * Prototypes for local functions defined in this file:
 */

static int		ReadOneByte(Tcl_Interp *interp,
			    GIFImageConfig *gifConfPtr, Tcl_Channel chan);
static int		DoExtension(GIFImageConfig *gifConfPtr,
			    Tcl_Channel chan, int label, unsigned char *buffer,
			    GIFGraphicControlExtensionBlock
			    *gifGraphicControlExtensionBlock,
			    Tcl_Obj *metadataOutObj);
			    int *transparent);
static int		GetCode(Tcl_Channel chan, int code_size, int flag,
			    GIFImageConfig *gifConfPtr);
static int		GetDataBlock(GIFImageConfig *gifConfPtr,
			    Tcl_Channel chan, unsigned char *buf);
static int		ReadColorMap(GIFImageConfig *gifConfPtr,
			    Tcl_Channel chan, int number,
			    unsigned char buffer[MAXCOLORMAPSIZE][4]);
static int		ReadGIFHeader(GIFImageConfig *gifConfPtr,
			    Tcl_Channel chan, int *widthPtr, int *heightPtr);
static int		ReadImage(GIFImageConfig *gifConfPtr,
			    Tcl_Interp *interp, unsigned char *imagePtr,
			    Tcl_Channel chan, int len, int rows,
			    unsigned char cmap[MAXCOLORMAPSIZE][4], int srcX,
			    int srcY, int interlace, int transparent);

/*
 * these are for the BASE64 image reader code only
 */

static Tcl_Size		Fread(GIFImageConfig *gifConfPtr, unsigned char *dst,
			    Tcl_Size size, Tcl_Size count, Tcl_Channel chan);
static Tcl_Size		Mread(unsigned char *dst, Tcl_Size size, Tcl_Size count,
static int		Fread(GIFImageConfig *gifConfPtr, unsigned char *dst,
			    size_t size, size_t count, Tcl_Channel chan);
static int		Mread(unsigned char *dst, size_t size, size_t count,
			    MFile *handle);
static int		Mgetc(MFile *handle);
static int		char64(int c);
static void		mInit(unsigned char *string, MFile *handle,
			    Tcl_Size length);
			    int length);

/*
 * Types, defines and variables needed to write and compress a GIF.
 */

#define LSB(a)		((unsigned char) (((short)(a)) & 0x00FF))
#define MSB(a)		((unsigned char) (((short)(a)) >> 8))
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290







-
+







     * codes are re-sized at this point, and a special CLEAR code is generated
     * for the decompressor. Late addition: construct the table according to
     * file size for noticeable speed improvement on small files. Please
     * direct questions about this implementation to ames!jaw.
     */

    int initialBits;
    void *destination;
    ClientData destination;
    WriteBytesFunc *writeProc;

    int clearCode;
    int eofCode;

    unsigned long currentAccumulated;
    int currentBits;
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318







-
+








/*
 * Definition of new functions to write GIFs
 */

static int		ColorNumber(GifWriterState *statePtr,
			    int red, int green, int blue);
static void		Compress(int initBits, void *handle,
static void		Compress(int initBits, ClientData handle,
			    WriteBytesFunc *writeProc, ifunptr readValue,
			    GifWriterState *statePtr);
static int		IsNewColor(GifWriterState *statePtr,
			    int red, int green, int blue);
static void		SaveMap(GifWriterState *statePtr,
			    Tk_PhotoImageBlock *blockPtr);
static int		ReadValue(GifWriterState *statePtr);
366
367
368
369
370
371
372
373
374
375
376


377
378
379
380
381

382
383
384
385
386
387
388
341
342
343
344
345
346
347

348


349
350

351
352
353

354
355
356
357
358
359
360
361







-

-
-
+
+
-



-
+







 *	The access position in f may change.
 *
 *----------------------------------------------------------------------
 */

static int
FileMatchGIF(
    TCL_UNUSED(Tcl_Interp *),	/* not used */
    Tcl_Channel chan,		/* The image file, open for reading. */
    TCL_UNUSED(const char *),	/* The name of the image file. */
    TCL_UNUSED(Tcl_Obj *),	/* User-specified format object, or NULL. */
    const char *fileName,	/* The name of the image file. */
    Tcl_Obj *format,		/* User-specified format object, or NULL. */
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    int *widthPtr, int *heightPtr,
				/* The dimensions of the image are returned
				 * here if the file is a valid raw GIF file. */
    TCL_UNUSED(Tcl_Obj *))	/* metadata return dict, may be NULL */
    Tcl_Interp *interp)		/* not used */
{
    GIFImageConfig gifConf;

    memset(&gifConf, 0, sizeof(GIFImageConfig));
    return ReadGIFHeader(&gifConf, chan, widthPtr, heightPtr);
}

407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422
423
424
425
426

427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442
443
444
445
446
447
380
381
382
383
384
385
386

387
388
389
390
391

392
393

394
395
396

397

398
399
400
401

402

403
404
405
406
407
408

409
410
411
412
413
414
415







-





-
+

-



-
+
-




-

-
+





-








static int
FileReadGIF(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Channel chan,		/* The image file, open for reading. */
    const char *fileName,	/* The name of the image file. */
    Tcl_Obj *format,		/* User-specified format object, or NULL. */
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    Tk_PhotoHandle imageHandle,	/* The photo image to write into. */
    int destX, int destY,	/* Coordinates of top-left pixel in photo
				 * image to be written to. */
    int width, int height,	/* Dimensions of block of photo image to be
				 * written to. */
    int srcX, int srcY,		/* Coordinates of top-left pixel to be used in
    int srcX, int srcY)		/* Coordinates of top-left pixel to be used in
				 * image being read. */
    Tcl_Obj *metadataOutObj)	/* metadata return dict, may be NULL */
{
    int fileWidth, fileHeight, imageWidth, imageHeight;
    unsigned int nBytes;
    int index = 0, result = TCL_ERROR;
    int index = 0, argc = 0, i, result = TCL_ERROR;
    Tcl_Size argc = 0, i;
    Tcl_Obj **objv;
    unsigned char buf[100];
    unsigned char *trashBuffer = NULL;
    int bitPixel;
    int gifLabel;
    unsigned char colorMap[MAXCOLORMAPSIZE][4];
    GIFGraphicControlExtensionBlock gifGraphicControlExtensionBlock;
    int transparent = -1;
    static const char *const optionStrings[] = {
	"-index", NULL
    };
    GIFImageConfig gifConf, *gifConfPtr = &gifConf;

    gifGraphicControlExtensionBlock.blockPresent = 0;
    /*
     * Decode the magic used to convey when we're sourcing data from a string
     * source and not a file.
     */

    memset(colorMap, 0, MAXCOLORMAPSIZE*4);
    memset(gifConfPtr, 0, sizeof(GIFImageConfig));
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483







-
+







	return TCL_OK;
    }
    bitPixel = 2 << (buf[0] & 0x07);

    if (BitSet(buf[0], LOCALCOLORMAP)) {	/* Global Colormap */
	if (!ReadColorMap(gifConfPtr, chan, bitPixel, colorMap)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "error reading color map", TCL_INDEX_NONE));
		    "error reading color map", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "COLOR_MAP", NULL);
	    return TCL_ERROR;
	}
    }

    if ((srcX + width) > fileWidth) {
	width = fileWidth - srcX;
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545




546





547
548
549
550

551
552
553

554
555
556
557
558
559
560
561
562






563
564
565
566


567
568
569
570

571
572
573
574
575
576
577
496
497
498
499
500
501
502






503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519

520
521
522

523
524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
539


540
541


542

543
544
545
546
547
548
549
550







-
-
-
-
-
-





+
+
+
+
-
+
+
+
+
+



-
+


-
+








-
+
+
+
+
+
+


-
-
+
+
-
-

-
+







     */

    if (Tk_PhotoExpand(interp, imageHandle,
	    destX + width, destY + height) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * -------------------------------------------------------------------------
     * From here on, go to error to not leave memory leaks
     * -------------------------------------------------------------------------
     */

    /*
     * Search for the frame from the GIF to display.
     */

    while (1) {
	if (Fread(gifConfPtr, buf, 1, 1, chan) != 1) {
	    /*
	     * Premature end of image.
	     */
	if (-1 == (gifLabel = ReadOneByte( interp, gifConfPtr, chan ) ) ) {

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "premature end of image data for this index", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "PREMATURE_END",
		    NULL);
	    goto error;
	}

	switch (gifLabel) {
	switch (buf[0]) {
	case GIF_TERMINATOR:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "no image data for this index", TCL_INDEX_NONE));
		    "no image data for this index", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "NO_DATA", NULL);
	    goto error;

	case GIF_EXTENSION:
	    /*
	     * This is a GIF extension.
	     */

	    if (-1 == (gifLabel = ReadOneByte( interp, gifConfPtr, chan ) ) ) {
	    if (Fread(gifConfPtr, buf, 1, 1, chan) != 1) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"error reading extension function code in GIF image",
			-1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "BAD_EXT",
			NULL);
		goto error;
	    }
	    if (DoExtension(gifConfPtr, chan, gifLabel,
		    gifConfPtr->workingBuffer, &gifGraphicControlExtensionBlock,
	    if (DoExtension(gifConfPtr, chan, buf[0],
		    gifConfPtr->workingBuffer, &transparent) < 0) {
		    metadataOutObj)
		    < 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"error reading extension in GIF image", TCL_INDEX_NONE));
			"error reading extension in GIF image", -1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "BAD_EXT",
			NULL);
		goto error;
	    }
	    continue;
	case GIF_START:
	    if (Fread(gifConfPtr, buf, 1, 9, chan) != 9) {
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607







-
+















-
+







	    /*
	     * This is not the GIF frame we want to read: skip it.
	     */

	    if (BitSet(buf[8], LOCALCOLORMAP)) {
		if (!ReadColorMap(gifConfPtr, chan, bitPixel, colorMap)) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "error reading color map", TCL_INDEX_NONE));
			    "error reading color map", -1));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF",
			    "COLOR_MAP", NULL);
		    goto error;
		}
	    }

	    /*
	     * If we've not yet allocated a trash buffer, do so now.
	     */

	    if (trashBuffer == NULL) {
		if (fileWidth > (int)((UINT_MAX/3)/fileHeight)) {
		    goto error;
		}
		nBytes = fileWidth * fileHeight * 3;
		trashBuffer = (unsigned char *)ckalloc(nBytes);
		trashBuffer = ckalloc(nBytes);
		if (trashBuffer) {
		    memset(trashBuffer, 0, nBytes);
		}
	    }

	    /*
	     * Slurp! Process the data for this image and stuff it in a trash
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
620
621
622
623
624
625
626







627
628
629
630
631
632
633
634
635
636
637
638
639

640
641
642
643
644
645
646
647







-
-
-
-
-
-
-













-
+







	     * common case.
	     */

	    if (ReadImage(gifConfPtr, interp, trashBuffer, chan, imageWidth,
		    imageHeight, colorMap, 0, 0, 0, -1) != TCL_OK) {
		goto error;
	    }

	    /*
	     * This extension starts a new scope, so Graphic control Extension
	     * data should be cleared
	     */
	    gifGraphicControlExtensionBlock.blockPresent = 0;

	    continue;
	}
	break;
    }

    /*
     * Found the frame we want to read. Next, check for a local color map for
     * this frame.
     */

    if (BitSet(buf[8], LOCALCOLORMAP)) {
	if (!ReadColorMap(gifConfPtr, chan, bitPixel, colorMap)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "error reading color map", TCL_INDEX_NONE));
		    "error reading color map", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "COLOR_MAP", NULL);
	    goto error;
	}
    }

    /*
     * Extract the location within the overall visible image to put the data
701
702
703
704
705
706
707
708
709
710
711

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874

875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951

952
953
954
955

956
957
958

959
960
961
962
963
964
965
667
668
669
670
671
672
673




674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714












































































715
716
717
718











































719
720
721

722

723
724
725
726
727
728
729
730
731







































732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750

751
752

753

754

755
756

757
758
759

760
761
762
763
764
765
766
767







-
-
-
-
+




















-
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
+
-









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-


-

-
+
-


-
+


-
+







    }
    if (height > imageHeight) {
	height = imageHeight;
    }

    if ((width > 0) && (height > 0)) {
	Tk_PhotoImageBlock block;
	int transparent = -1;
	if (gifGraphicControlExtensionBlock.blockPresent) {
	    transparent = gifGraphicControlExtensionBlock.transparent;
	}

	/*
	 * Read the data and put it into the photo buffer for display by the
	 * general image machinery.
	 */

	block.width = width;
	block.height = height;
	block.pixelSize = (transparent>=0) ? 4 : 3;
	block.offset[0] = 0;
	block.offset[1] = 1;
	block.offset[2] = 2;
	block.offset[3] = (transparent>=0) ? 3 : 0;
	if (imageWidth > INT_MAX/block.pixelSize) {
	    goto error;
	}
	block.pitch = block.pixelSize * imageWidth;
	if (imageHeight > (int)(UINT_MAX/block.pitch)) {
	    goto error;
	}
	nBytes = block.pitch * imageHeight;
	block.pixelPtr = (unsigned char *)ckalloc(nBytes);
	block.pixelPtr = ckalloc(nBytes);
	if (block.pixelPtr) {
	    memset(block.pixelPtr, 0, nBytes);
	}

	if (ReadImage(gifConfPtr, interp, block.pixelPtr, chan, imageWidth,
		imageHeight, colorMap, srcX, srcY, BitSet(buf[8], INTERLACE),
		transparent) != TCL_OK) {
	    ckfree(block.pixelPtr);
	    goto error;
	}
	if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
		width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
	    ckfree(block.pixelPtr);
	    goto error;
	}
	ckfree(block.pixelPtr);
    }

    /*
     * Update the metadata dictionary with current image data
     */

    if (NULL != metadataOutObj) {

	/*
	 * Save the update box, if not the whole image
	 */

	if ( width != fileWidth || height != fileHeight) {
	    Tcl_Obj *itemList[4];
	    itemList[0] = Tcl_NewIntObj(destX);
	    itemList[1] = Tcl_NewIntObj(destY);
	    itemList[2] = Tcl_NewIntObj(width);
	    itemList[3] = Tcl_NewIntObj(height);
	    if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
		    Tcl_NewStringObj("update region",-1),
		    Tcl_NewListObj(4, itemList) )) {
		result = TCL_ERROR;
		goto error;
	    }
	}

	/*
	 * Copy the Graphic Control Extension Block data to the metadata
	 * dictionary
	 */

	if (gifGraphicControlExtensionBlock.blockPresent) {
	    if ( gifGraphicControlExtensionBlock.delayTime != 0) {
		if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
			Tcl_NewStringObj("delay time",-1),
			Tcl_NewIntObj(gifGraphicControlExtensionBlock.delayTime)
			)) {
		    result = TCL_ERROR;
		    goto error;
		}
	    }
	    switch ( gifGraphicControlExtensionBlock.disposalMethod ) {
	    case 1: /* Do not dispose */
		if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
			Tcl_NewStringObj("disposal method",-1),
			Tcl_NewStringObj("do not dispose",-1))) {
		    result = TCL_ERROR;
		    goto error;
		}
		break;
	    case 2: /* Restore to background color */
		if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
			Tcl_NewStringObj("disposal method",-1),
			Tcl_NewStringObj("restore to background color",-1))) {
		    result = TCL_ERROR;
		    goto error;
		}
		break;
	    case 3: /* Restore to previous */
		if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
			Tcl_NewStringObj("disposal method",-1),
			Tcl_NewStringObj("restore to previous",-1))) {
		    result = TCL_ERROR;
		    goto error;
		}
		break;
	    }
	    if ( gifGraphicControlExtensionBlock.userInteraction != 0) {
		if ( TCL_OK != Tcl_DictObjPut(interp, metadataOutObj,
			Tcl_NewStringObj("user interaction",-1),
			Tcl_NewBooleanObj(1))) {
		    result = TCL_ERROR;
		    goto error;
		}
	    }
	}
    }

    /*
     * We've successfully read the GIF frame (or there was nothing to read,
     * which suits as well). We're done.
     */

    while (1) {
	if (-1 == (gifLabel = ReadOneByte( interp, gifConfPtr, chan ) ) ) {
	    goto error;
	}
	switch (gifLabel) {
	case GIF_TERMINATOR:
	    break;

	case GIF_EXTENSION:
	    /*
	     * This is a GIF extension.
	     */

	    if (-1 == (gifLabel = ReadOneByte( interp, gifConfPtr, chan ) ) ) {
		goto error;
	    }
	    if (DoExtension(gifConfPtr, chan, gifLabel,
		    gifConfPtr->workingBuffer, &gifGraphicControlExtensionBlock,
		    metadataOutObj)
		    < 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"error reading extension in GIF image", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "BAD_EXT",
			NULL);
		goto error;
	    }
	    continue;
	case GIF_START:
	    /*
	     * There should not be a second image block - bail out without error
	     */
	    break;
	default:
	    /*
	     * Not a valid start character; ignore it.
	     */

	    continue;
	}
	break;
    }

    Tcl_SetObjResult(interp, Tcl_NewStringObj(tkImgFmtGIF.name, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(tkImgFmtGIF.name, -1));
    result = TCL_OK;

error:
  error:

    /*
     * If a trash buffer has been allocated, free it now.
     */

    if (trashBuffer != NULL) {
	ckfree(trashBuffer);
    }
    return result;
}


/*
 *----------------------------------------------------------------------
 *
 * Read one Byte --
 *
 *	Read one byte (label byte) from the image stream.
 *
 * Results:
 *	The return value is 1 if the first characters in the data are like GIF
 *	data, and 0 otherwise.
 *
 * Side effects:
 *	The access position in the source is incremented.
 *
 *----------------------------------------------------------------------
 */

static int
ReadOneByte(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    GIFImageConfig *gifConfPtr,
    Tcl_Channel chan		/* The image file, open for reading. */
    )
{
    unsigned char buf[2];
    if (Fread(gifConfPtr, buf, 1, 1, chan) != 1) {
        /*
         * Premature end of image.
         */

        Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"premature end of image data", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "PREMATURE_END", NULL);
	return -1;
    }
    return buf[0];
}

/*
 *----------------------------------------------------------------------
 *
 * StringMatchGIF --
 *
 *	This function is invoked by the photo image type to see if an object
 *	contains image data in GIF format.
 *
 * Results:
 *	The return value is 1 if the first characters in the data are like GIF
 *	data, and 0 otherwise.
 *
 * Side effects:
 *	The size of the image is placed in widthPtr and heightPtr.
 *
 *----------------------------------------------------------------------
 */


static int
StringMatchGIF(
    TCL_UNUSED(Tcl_Interp *),		/* not used */
    Tcl_Obj *dataObj,		/* the object containing the image data */
    TCL_UNUSED(Tcl_Obj *),		/* the image format object, or NULL */
    Tcl_Obj *format,		/* the image format object, or NULL */
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    int *widthPtr,		/* where to put the string width */
    int *heightPtr,		/* where to put the string height */
    TCL_UNUSED(Tcl_Obj *))	/* metadata return dict, may be NULL */
    Tcl_Interp *interp)		/* not used */
{
    unsigned char *data, header[10];
    Tcl_Size got, length;
    int got, length;
    MFile handle;

    data = Tcl_GetByteArrayFromObj(dataObj, &length);

    /*
     * Header is a minimum of 10 bytes.
     */
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
816
817
818
819
820
821
822

823
824
825

826

827
828

829
830
831
832
833
834
835
836







-



-
+
-


-
+







 */

static int
StringReadGIF(
    Tcl_Interp *interp,		/* interpreter for reporting errors in */
    Tcl_Obj *dataObj,		/* object containing the image */
    Tcl_Obj *format,		/* format object, or NULL */
    Tcl_Obj *metadataInObj,	/* metadata input, may be NULL */
    Tk_PhotoHandle imageHandle,	/* the image to write this data into */
    int destX, int destY,	/* The rectangular region of the */
    int width, int height,	/* image to copy */
    int srcX, int srcY,
    int srcX, int srcY)
    Tcl_Obj *metadataOutObj)	/* metadata return dict, may be NULL */
{
    MFile handle, *hdlPtr = &handle;
    Tcl_Size length;
    int length;
    const char *xferFormat;
    unsigned char *data = Tcl_GetByteArrayFromObj(dataObj, &length);

    mInit(data, hdlPtr, length);

    /*
     * Check whether the data is Base64 encoded by doing a character-by-
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063
848
849
850
851
852
853
854

855

856
857
858
859
860
861
862







-
+
-








    /*
     * Fall through to the file reader now that we have a correctly-configured
     * pseudo-channel to pull the data from.
     */

    return FileReadGIF(interp, (Tcl_Channel) hdlPtr, xferFormat, format,
	    metadataInObj, imageHandle, destX, destY, width, height, srcX, srcY,
	    imageHandle, destX, destY, width, height, srcX, srcY);
	    metadataOutObj);
}

/*
 *----------------------------------------------------------------------
 *
 * ReadGIFHeader --
 *
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164

1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179



1180
1181







1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197

1198
1199
1200

1201
1202
1203
1204
1205
1206
1207

1208
1209
1210
1211
1212
1213

1214
1215

1216
1217

1218
1219
1220
1221
1222
1223
1224
1225
1226


1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249

1250
1251
1252
1253
1254
1255
1256
927
928
929
930
931
932
933






















934
935
936
937
938

939


940
941
942





943
944
945





946
947
948

949
950
951
952
953
954
955
956
957
958
959

960
961











962



963
964






965






966
967

968


969









970
971



















972
973
974

975
976
977
978
979
980
981
982







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+
-
-
+


-
-
-
-
-



-
-
-
-
-
+
+
+
-

+
+
+
+
+
+
+



-
+

-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+

-
-
-
-
-
-
+
-
-
-
-
-
-
+

-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+







	    buffer[i][CM_BLUE] = rgb[2];
	    buffer[i][CM_ALPHA] = 255;
	}
    }
    return 1;
}

/*
*----------------------------------------------------------------------
*
* DoExtension --
*
*	Process a GIF extension block
*
* Results:
*	-1 to trigger an extension read error
*       >= 0 ok
*
* Side effects:
*       The gifGraphicControlExtensionBlock is set if present in current
*       extensions
*       The data of the following extensions are saved to the metadata dict:
*       - Application extension
*         - Comment extension in key "comment"
*       Plain text extensions are currently ignored.
*
*----------------------------------------------------------------------
*/

static int
DoExtension(
    GIFImageConfig *gifConfPtr,
    Tcl_Channel chan,
    int label,
    unsigned char *buf, /* defined as 280 byte working buffer */
    unsigned char *buf,
    GIFGraphicControlExtensionBlock *gifGraphicControlExtensionBlock,
    Tcl_Obj *metadataOutObj)
    int *transparent)
{
    int count;
    /* Prepare extension name
     * Maximum string size: "comment" + Code(3) + trailing zero
     */
    char extensionStreamName[8];
    extensionStreamName[0] = '\0';

    switch (label) {
    case 0x01:			/* Plain Text Extension */
	/*
	 * This extension starts a new scope, so Graphic control Extension
	 * data should be cleared
	 */
	gifGraphicControlExtensionBlock->blockPresent = 0;
	break;

    case 0xff:			/* Application Extension */
	/* this extension is ignored, skip below */
	break;

    case 0xfe:			/* Comment Extension */
	do {
	    count = GetDataBlock(gifConfPtr, chan, buf);
	} while (count > 0);
	return count;

    case 0xf9:			/* Graphic Control Extension */
	count = GetDataBlock(gifConfPtr, chan, buf);
	if (count < 0) {
	    return -1;
	    return 1;
	}
	gifGraphicControlExtensionBlock->blockPresent=1;
	/* save disposal method */
	gifGraphicControlExtensionBlock->disposalMethod
		= ((buf[0] & 0x1C) >> 2);
	/* save disposal method */
	gifGraphicControlExtensionBlock->userInteraction = ((buf[0] & 2) >> 1);
	/* save delay time */
	gifGraphicControlExtensionBlock->delayTime
		= LM_to_uint(buf[1], buf[2]);
	/* save transparent index if given */
	if ((buf[0] & 0x1) == 0) {
	if ((buf[0] & 0x1) != 0) {
	    gifGraphicControlExtensionBlock->transparent = -1;
	} else {
	    gifGraphicControlExtensionBlock->transparent = buf[3];
	    *transparent = buf[3];
	}
	break;
    case 0xfe:			/* Comment Extension */
	strcpy(extensionStreamName,"comment");
        /* copy the extension data below */
	break;
    }

    /* Add extension to dict */
    if (NULL != metadataOutObj
	    && extensionStreamName[0] != '\0' ) {
	Tcl_Obj *ValueObj = NULL;
	int length = 0;
	for (;;) {
	do {
	    count = GetDataBlock(gifConfPtr, chan, buf);
	    switch (count) {
	} while (count > 0);
	    case -1: /* error */
		return -1;
	return count;
	    case 0: /* end of data */
		if (length > 0) {
		    if ( TCL_OK != Tcl_DictObjPut(NULL, metadataOutObj,
			    Tcl_NewByteArrayObj(
				(unsigned char *)extensionStreamName,
			    strlen(extensionStreamName)), ValueObj)) {
			return -1;
		    }
		}
    }

		/* return success */
		return 0;
	    default: /* block received */
		if (length == 0) {
		    /* first block */
		    ValueObj = Tcl_NewByteArrayObj(buf, count);
		    length = count;
		} else {
		    /* consecutive block */
		    unsigned char *bytePtr;
		    bytePtr = Tcl_SetByteArrayLength(ValueObj, length+count);
		    memcpy(bytePtr+length,buf,count);
		    length += count;
		}
		break;
	    }
	} /* for */
    }
    /* skip eventual remaining data block bytes */
    do {
	count = GetDataBlock(gifConfPtr, chan, buf);
    } while (count > 0);
    return count; /* this may be -1 for error or 0 */
    return count;
}

static int
GetDataBlock(
    GIFImageConfig *gifConfPtr,
    Tcl_Channel chan,
    unsigned char *buf)
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313


1314
1315
1316
1317
1318
1319

1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1025
1026
1027
1028
1029
1030
1031

1032

1033
1034
1035
1036


1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066







-
+
-




-
-
+
+





-
+














-
+







ReadImage(
    GIFImageConfig *gifConfPtr,
    Tcl_Interp *interp,
    unsigned char *imagePtr,
    Tcl_Channel chan,
    int len, int rows,
    unsigned char cmap[MAXCOLORMAPSIZE][4],
    TCL_UNUSED(int),
    int srcX, int srcY,
    TCL_UNUSED(int),
    int interlace,
    int transparent)
{
    unsigned char initialCodeSize;
    int xpos = 0, ypos = 0, pass = 0, i, count;
    unsigned char *pixelPtr;
    int xpos = 0, ypos = 0, pass = 0, i;
    register unsigned char *pixelPtr;
    static const int interlaceStep[] = { 8, 8, 4, 2 };
    static const int interlaceStart[] = { 0, 4, 2, 1 };
    unsigned short prefix[(1 << MAX_LWZ_BITS)];
    unsigned char append[(1 << MAX_LWZ_BITS)];
    unsigned char stack[(1 << MAX_LWZ_BITS)*2];
    unsigned char *top;
    register unsigned char *top;
    int codeSize, clearCode, inCode, endCode, oldCode, maxCode;
    int code, firstCode, v;

    /*
     * Initialize the decoder
     */

    if (Fread(gifConfPtr, &initialCodeSize, 1, 1, chan) <= 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"error reading GIF image: %s", Tcl_PosixError(interp)));
	return TCL_ERROR;
    }

    if (initialCodeSize > MAX_LWZ_BITS) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("malformed image", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("malformed image", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "MALFORMED", NULL);
	return TCL_ERROR;
    }

    if (transparent != -1) {
	cmap[transparent][CM_RED] = 0;
	cmap[transparent][CM_GREEN] = 0;
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421



1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432

1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456












1457
1458

1459
1460
1461
1462


1463
1464
1465
1466

1467
1468
1469
1470



1471
1472
1473
1474
1475
1476
1477
1478
1137
1138
1139
1140
1141
1142
1143



1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168
1169

1170
1171
1172
1173
1174
1175
1176
1177
1178



1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193



1194
1195




1196
1197



1198
1199
1200

1201
1202
1203
1204
1205
1206
1207







-
-
-
+
+
+










-
+



-
+








-
+








-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
-
+
+
-
-
-
-
+

-
-
-
+
+
+
-







		}

		if (oldCode == -1) {
		    /*
		     * Last pass reset the decoder, so the first code we see
		     * must be a singleton. Seed the stack with it, and set up
		     * the old/first code pointers for insertion into the
		     * codes table. We can't just roll this into the clearCode
		     * test above, because at that point we have not yet read
		     * the next code.
		     * string table. We can't just roll this into the
		     * clearCode test above, because at that point we have not
		     * yet read the next code.
		     */

		    *top++ = append[code];
		    oldCode = code;
		    firstCode = code;
		    continue;
		}

		inCode = code;

		if ((code == maxCode) && (maxCode < (1 << MAX_LWZ_BITS))) {
		if (code == maxCode) {
		    /*
		     * maxCode is always one bigger than our highest assigned
		     * code. If the code we see is equal to maxCode, then we
		     * are about to add a new entry to the codes table.
		     * are about to add a new string to the table. ???
		     */

		    *top++ = firstCode;
		    code = oldCode;
		}

		while (code > clearCode) {
		    /*
		     * Populate the stack by tracing the code in the codes
		     * Populate the stack by tracing the string in the string
		     * table from its tail to its head
		     */

		    *top++ = append[code];
		    code = prefix[code];
		}
		firstCode = append[code];

	        /*
	         * Push the head of the code onto the stack.
	         */
		/*
		 * If there's no more room in our string table, quit.
		 * Otherwise, add a new string to the table
		 */

		if (maxCode >= (1 << MAX_LWZ_BITS)) {
		    return TCL_OK;
		}

		/*
		 * Push the head of the string onto the stack.
		 */

	        *top++ = firstCode;
		*top++ = firstCode;

                if (maxCode < (1 << MAX_LWZ_BITS)) {
		    /*
		     * If there's still room in our codes table, add a new entry.
		/*
		 * Add a new string to the string table
		     * Otherwise don't, and keep using the current table.
                     * See DEFERRED CLEAR CODE IN LZW COMPRESSION in the GIF89a
                     * specification.
		     */
		 */

		    prefix[maxCode] = oldCode;
		    append[maxCode] = firstCode;
		    maxCode++;
		prefix[maxCode] = oldCode;
		append[maxCode] = firstCode;
		maxCode++;
                }

		/*
		 * maxCode tells us the maximum code value we can accept. If
		 * we see that we need more bits to represent it than we are
		 * requesting from the unpacker, we need to increase the
		 * number we ask for.
		 */
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1251
1252
1253
1254
1255
1256
1257



















1258
1259
1260
1261
1262
1263
1264







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		}
		ypos = interlaceStart[pass];
	    }
	} else {
	    ypos++;
	}
	pixelPtr = imagePtr + (ypos) * len * ((transparent>=0)?4:3);
    }

    /*
     * Now read until the final zero byte.
     * It was observed that there might be 1 length blocks
     * (test imgPhoto-14.1) which are not read.
     *
     * The field "stack" is abused for temporary buffer. it has 4096 bytes
     * and we need 256.
     *
     * Loop until we hit a 0 length block which is the end sign.
     */
    while ( 0 < (count = GetDataBlock(gifConfPtr, chan, stack)))
    {
	if (-1 == count ) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading GIF image: %s", Tcl_PosixError(interp)));
	    return TCL_ERROR;
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
1663
1664
1665
1666
1667
1668
1669
1670

1671
1672
1673
1674
1675
1676
1677
1373
1374
1375
1376
1377
1378
1379

1380
1381
1382
1383
1384
1385
1386
1387







-
+







 *----------------------------------------------------------------------
 */

static void
mInit(
    unsigned char *string,	/* string containing initial mmencoded data */
    MFile *handle,		/* mmdecode "file" handle */
    Tcl_Size length)			/* Number of bytes in string */
    int length)			/* Number of bytes in string */
{
    handle->data = string;
    handle->state = 0;
    handle->c = 0;
    handle->length = length;
}

1689
1690
1691
1692
1693
1694
1695
1696

1697
1698
1699
1700


1701
1702
1703
1704


1705
1706
1707
1708
1709
1710
1711
1399
1400
1401
1402
1403
1404
1405

1406
1407
1408


1409
1410
1411
1412


1413
1414
1415
1416
1417
1418
1419
1420
1421







-
+


-
-
+
+


-
-
+
+







 *
 * Side effects:
 *	The base64 handle will change state.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
Mread(
    unsigned char *dst,		/* where to put the result */
    Tcl_Size chunkSize,		/* size of each transfer */
    Tcl_Size numChunks,		/* number of chunks */
    size_t chunkSize,		/* size of each transfer */
    size_t numChunks,		/* number of chunks */
    MFile *handle)		/* mmdecode "file" handle */
{
    int c;
    Tcl_Size i, count = chunkSize * numChunks;
    register int i, c;
    int count = chunkSize * numChunks;

    for (i=0; i<count && (c=Mgetc(handle)) != GIF_DONE; i++) {
	*dst++ = c;
    }
    return i;
}

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
1548
1549
1550
1551
1552
1553
1554

1555
1556
1557
1558

1559
1560
1561




1562
1563
1564
1565
1566
1567
1568

1569
1570
1571

1572
1573


1574
1575
1576
1577
1578
1579
1580

1581
1582
1583
1584
1585
1586
1587
1588







-
+



-
+


-
-
-
-







-
+


-
+

-
-
+






-
+







 *	a base64 encoded string.
 *
 * Results: - same as POSIX fread() or Tcl Tcl_Read()
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
Fread(
    GIFImageConfig *gifConfPtr,
    unsigned char *dst,		/* where to put the result */
    Tcl_Size hunk, Tcl_Size count,	/* how many */
    size_t hunk, size_t count,	/* how many */
    Tcl_Channel chan)
{
    if (hunk < 0 || count < 0) {
        return -1;
    }

    if (gifConfPtr->fromData == INLINE_DATA_BASE64) {
	return Mread(dst, hunk, count, (MFile *) chan);
    }

    if (gifConfPtr->fromData == INLINE_DATA_BINARY) {
	MFile *handle = (MFile *) chan;

	if ((handle->length <= 0) || (handle->length < hunk*count)) {
	if (handle->length <= 0 || (size_t) handle->length < hunk*count) {
	    return -1;
	}
	memcpy(dst, handle->data, hunk * count);
	memcpy(dst, handle->data, (size_t) (hunk * count));
	handle->data += hunk * count;
	handle->length -= hunk * count;
	return hunk * count;
	return (int)(hunk * count);
    }

    /*
     * Otherwise we've got a real file to read.
     */

    return Tcl_Read(chan, (char *) dst, hunk * count);
    return Tcl_Read(chan, (char *) dst, (int) (hunk * count));
}

/*
 * ChanWriteGIF - writes a image in GIF format.
 *-------------------------------------------------------------------------
 * Author:		Lolo
 *			Engeneering Projects Area
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
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631

1632

1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659

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







-















-
+
-












-







-
+







-
+

-
+

-
+

-
+




-
+

-
+

-
+

-
+











-
+

-
-
+









static int
FileWriteGIF(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    const char *filename,
    Tcl_Obj *format,
    Tcl_Obj *metadataInObj,
    Tk_PhotoImageBlock *blockPtr)
{
    Tcl_Channel chan = NULL;
    int result;

    chan = Tcl_OpenFileChannel(interp, (char *) filename, "w", 0644);
    if (!chan) {
	return TCL_ERROR;
    }
    if (Tcl_SetChannelOption(interp, chan, "-translation",
	    "binary") != TCL_OK) {
	Tcl_Close(NULL, chan);
	return TCL_ERROR;
    }

    result = CommonWriteGIF(interp, chan, WriteToChannel, format, metadataInObj,
    result = CommonWriteGIF(interp, chan, WriteToChannel, format, blockPtr);
	    blockPtr);

    if (Tcl_Close(interp, chan) == TCL_ERROR) {
	return TCL_ERROR;
    }
    return result;
}

static int
StringWriteGIF(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors and
				 * returning the GIF data. */
    Tcl_Obj *format,
    Tcl_Obj *metadataInObj,
    Tk_PhotoImageBlock *blockPtr)
{
    int result;
    Tcl_Obj *objPtr = Tcl_NewObj();

    Tcl_IncrRefCount(objPtr);
    result = CommonWriteGIF(interp, objPtr, WriteToByteArray, format,
	    metadataInObj, blockPtr);
	    blockPtr);
    if (result == TCL_OK) {
	Tcl_SetObjResult(interp, objPtr);
    }
    Tcl_DecrRefCount(objPtr);
    return result;
}

static Tcl_Size
static int
WriteToChannel(
    void *clientData,
    ClientData clientData,
    const char *bytes,
    Tcl_Size byteCount)
    int byteCount)
{
    Tcl_Channel handle = (Tcl_Channel)clientData;
    Tcl_Channel handle = clientData;

    return Tcl_Write(handle, bytes, byteCount);
}

static Tcl_Size
static int
WriteToByteArray(
    void *clientData,
    ClientData clientData,
    const char *bytes,
    Tcl_Size byteCount)
    int byteCount)
{
    Tcl_Obj *objPtr = (Tcl_Obj *)clientData;
    Tcl_Obj *objPtr = clientData;
    Tcl_Obj *tmpObj = Tcl_NewByteArrayObj((unsigned char *) bytes, byteCount);

    Tcl_IncrRefCount(tmpObj);
    Tcl_AppendObjToObj(objPtr, tmpObj);
    Tcl_DecrRefCount(tmpObj);
    return byteCount;
}

static int
CommonWriteGIF(
    Tcl_Interp *interp,
    void *handle,
    ClientData handle,
    WriteBytesFunc *writeProc,
    TCL_UNUSED(Tcl_Obj *),
    Tcl_Obj *metadataInObj,
    Tcl_Obj *format,
    Tk_PhotoImageBlock *blockPtr)
{
    GifWriterState state;
    int resolution;
    long width, height, x;
    unsigned char c;
    unsigned int top, left;
2024
2025
2026
2027
2028
2029
2030
2031

2032
2033
2034
2035
2036
2037
2038
1725
1726
1727
1728
1729
1730
1731

1732
1733
1734
1735
1736
1737
1738
1739







-
+








    width = blockPtr->width;
    height = blockPtr->height;
    state.pixelOffset = blockPtr->pixelPtr + blockPtr->offset[0];
    state.pixelPitch = blockPtr->pitch;
    SaveMap(&state, blockPtr);
    if (state.num >= MAXCOLORMAPSIZE) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("too many colors", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("too many colors", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "GIF", "COLORFUL", NULL);
	return TCL_ERROR;
    }
    if (state.num<2) {
	state.num = 2;
    }
    c = LSB(width);
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
1814
1815
1816
1817
1818
1819
1820












































1821
1822
1823
1824
1825
1826
1827







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    state.ssize = state.rsize = blockPtr->width;
    state.csize = blockPtr->height;
    Compress(resolution+1, handle, writeProc, ReadValue, &state);

    c = 0;
    writeProc(handle, (char *) &c, 1);
    /*
     * Check for metadata keys to add to file
     */
    if (NULL != metadataInObj) {
	Tcl_Obj *itemData;

	/*
	 * Check and code comment block
	 */

	if (TCL_ERROR == Tcl_DictObjGet(interp, metadataInObj,
		Tcl_NewStringObj("comment",-1),
		&itemData)) {
	    return TCL_ERROR;
	}
	if (itemData != NULL) {
	    Tcl_Size length;
	    unsigned char *comment;
	    comment = Tcl_GetByteArrayFromObj(itemData, &length);
	    if (length > 0) {
		/* write comment header */
		writeProc(handle, (char *) "\x21\xfe", 2);
		/* write comment blocks */
		for (;length > 0;) {
		    int blockLength;
		    unsigned char blockLengthChar;
		    if (length > 255) {
			length -=255;
			blockLength = 255;
		    } else {
			blockLength = length;
			length = 0;
		    }
		    blockLengthChar = (unsigned char) blockLength;
		    writeProc(handle, (char *) &blockLengthChar, 1);
		    writeProc(handle, (char *) comment, blockLength);
		    comment += blockLength;
		}
		/* Block terminator */
		c = 0;
		writeProc(handle, (char *) &c, 1);
	    }
	}
    }
    c = GIF_TERMINATOR;
    writeProc(handle, (char *) &c, 1);

    return TCL_OK;
}

static int
2281
2282
2283
2284
2285
2286
2287
2288

2289
2290
2291
2292
2293
2294
2295
1938
1939
1940
1941
1942
1943
1944

1945
1946
1947
1948
1949
1950
1951
1952







-
+







 *              James A. Woods          (decvax!ihnp4!ames!jaw)
 *              Joe Orost               (decvax!vax135!petsd!joe)
 */

static void
Compress(
    int initialBits,
    void *handle,
    ClientData handle,
    WriteBytesFunc *writeProc,
    ifunptr readValue,
    GifWriterState *statePtr)
{
    long fcode, ent, disp, hSize, i = 0;
    int c, hshift;
    GIFState_t state;
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489



2490
2491
2492
2493
2494
2495
2496
2137
2138
2139
2140
2141
2142
2143



2144
2145
2146
2147
2148
2149
2150
2151
2152
2153







-
-
-
+
+
+







}

static void
ClearHashTable(			/* Reset code table. */
    GIFState_t *statePtr,
    int hSize)
{
    int *hashTablePtr = statePtr->hashTable + hSize;
    long i;
    long m1 = -1;
    register int *hashTablePtr = statePtr->hashTable + hSize;
    register long i;
    register long m1 = -1;

    i = hSize - 16;
    do {			/* might use Sys V memset(3) here */
	*(hashTablePtr-16) = m1;
	*(hashTablePtr-15) = m1;
	*(hashTablePtr-14) = m1;
	*(hashTablePtr-13) = m1;

Changes to generic/tkImgListFormat.c.

1
2
3
4
5
6
7
8
9
10

11
12

13
14
15
16
17
18




19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
1
2
3
4
5
6
7
8
9

10
11

12
13
14




15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33




34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54









-
+

-
+


-
-
-
-
+
+
+
+




-
+










-
-
-
-













-
+







/*
 * tkImgListFormat.c --
 *
 *      Implements the default image data format. I.e. the format used for
 *      [imageName data] and [imageName put] if no other format is specified.
 *
 *      The default format consits of a list of scan lines (rows) with each
 *      list element being itself a list of pixels (or columns). For details,
 *      see the manpage photo.n
 *
 * 
 *      This image format cannot read/write files, it is meant for string
 *      data only.
 *      data only. 
 *
 *
 * Copyright © 1994 The Australian National University.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2002-2003 Donal K. Fellows
 * Copyright © 2003 ActiveState Corporation.
 * Copyright (c) 1994 The Australian National University.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2002-2003 Donal K. Fellows
 * Copyright (c) 2003 ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * Authors:
 * Authors: 
 *      Paul Mackerras ([email protected]),
 *              Department of Computer Science,
 *              Australian National University.
 *
 *      Simon Bachmann ([email protected])
 */


#include "tkImgPhoto.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Message to generate when an attempt to allocate memory for an image fails.
 */

#define TK_PHOTO_ALLOC_FAILURE_MESSAGE \
        "not enough free memory for image buffer"


/*
 * Color name length limit: do not attempt to parse as color strings that are
 * longer than this limit
 */

#define TK_PHOTO_MAX_COLOR_LENGTH 99
#define TK_PHOTO_MAX_COLOR_CHARS 99

/*
 * Symbols for the different formats of a color string.
 */

enum ColorFormatType {
    COLORFORMAT_TKCOLOR,
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99







-
+







    int options;         /* Individual bits indicate which options were
                          * specified - see below. */
    Tcl_Obj *formatName; /* Name specified without an option. */
    enum ColorFormatType colorFormat;
                         /* The color format type given with the
                          * -colorformat option */
};

    
/*
 * Bit definitions for use with ParseFormatOptions: each bit is set in the
 * allowedOptions parameter on a call to ParseFormatOptions if that option
 * is allowed for the current photo image subcommand. On return, the bit is
 * set in the options field of the FormatOptions structure if that option
 * was specified.
 *
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140


141
142
143
144
145
146
147
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144







-
+















-
+
+







};

/*
 * Forward declarations
 */

static int      ParseFormatOptions(Tcl_Interp *interp, int allowedOptions,
                    Tcl_Size objc, Tcl_Obj *const objv[], Tcl_Size *indexPtr,
                    int objc, Tcl_Obj *const objv[], int *indexPtr,
                    struct FormatOptions *optPtr);
static Tcl_Obj  *GetBadOptMsg(const char *badValue, int allowedOpts);
static int      StringMatchDef(Tcl_Obj *data, Tcl_Obj *formatString,
                    int *widthPtr, int *heightPtr, Tcl_Interp *interp);
static int      StringReadDef(Tcl_Interp *interp, Tcl_Obj *data,
                    Tcl_Obj *formatString, Tk_PhotoHandle imageHandle,
                    int destX, int destY, int width, int height,
                    int srcX, int srcY);
static int      StringWriteDef(Tcl_Interp *interp,
                    Tcl_Obj *formatString,
                    Tk_PhotoImageBlock *blockPtr);
static int      ParseColor(Tcl_Interp *interp, Tcl_Obj *specObj,
                    Display *display, Colormap colormap, unsigned char *redPtr,
                    unsigned char *greenPtr, unsigned char *bluePtr,
                    unsigned char *alphaPtr);
static int      ParseColorAsList(const char *colorString, unsigned char *redPtr,
static int      ParseColorAsList(Tcl_Interp *interp, const char *colorString,
                    int colorStrLen, unsigned char *redPtr,
                    unsigned char *greenPtr, unsigned char *bluePtr,
                    unsigned char *alphaPtr);
static int      ParseColorAsHex(Tcl_Interp *interp, const char *colorString,
                    int colorStrLen, Display *display, Colormap colormap,
                    unsigned char *redPtr, unsigned char *greenPtr,
                    unsigned char *bluePtr, unsigned char *alphaPtr);
static int      ParseColorAsStandard(Tcl_Interp *interp,
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178

179
180
181

182
183

184
185
186
187
188
189
190
191
192
193

194
195

196
197
198
199
200

201
202

203
204
205
206
207
208
209
210
154
155
156
157
158
159
160

161

162
163
164
165
166
167
168
169
170
171
172
173

174
175
176

177
178

179
180
181
182
183
184
185
186
187
188

189
190

191
192
193
194
195

196
197

198

199
200
201
202
203
204
205







-
+
-












-
+


-
+

-
+









-
+

-
+




-
+

-
+
-







Tk_PhotoImageFormat tkImgFmtDefault = {
    "default",      /* name */
    NULL,           /* fileMatchProc: format doesn't support file ops */
    StringMatchDef, /* stringMatchProc */
    NULL,           /* fileReadProc: format doesn't support file read */
    StringReadDef,  /* stringReadProc */
    NULL,           /* fileWriteProc: format doesn't support file write */
    StringWriteDef, /* stringWriteProc */
    StringWriteDef  /* stringWriteProc */
    NULL            /* nextPtr */
};

/*
 *----------------------------------------------------------------------
 *
 * ParseFormatOptions --
 *
 *      Parse the options passed to the image format handler.
 *
 * Results:
 *      On success, the structure pointed to by optPtr is filled with the
 *      values passed or with the defaults and TCL_OK returned.
 *      If an error occurs, leaves an error message in interp and returns
 *      If an error occurs, leaves an error message in interp and returns 
 *      TCL_ERROR.
 *
 * Side effects:
 * Side effects: 
 *      The value in *indexPtr is updated to the index of the fist
 *      element in argv[] that does not look like an option/value, or to
 *      element in argv[] that does not look like an option/value, or to 
 *      argc if parsing reached the end of argv[].
 *
 *----------------------------------------------------------------------
 */
static int
ParseFormatOptions(
    Tcl_Interp *interp,               /* For error messages */
    int allowedOptions,               /* Bitfield specifying which options are
                                       * to be considered allowed */
    Tcl_Size objc,                         /* Number of elements in argv[] */
    int objc,                         /* Number of elements in argv[] */
    Tcl_Obj *const objv[],            /* The arguments to parse */
    Tcl_Size *indexPtr,                    /* Index giving the first element to
    int *indexPtr,                    /* Index giving the first element to 
                                       * parse. The value is updated to the
                                       * index where parsing ended */
    struct FormatOptions *optPtr)     /* Parsed option values are written to
                                       * this struct */

   
{
    Tcl_Size optIndex, index;
    int index, optIndex, typeIndex, first;
    int first, typeIndex;
    const char *option;

    first = 1;

    /*
     * Fill in default values
     */
225
226
227
228
229
230
231
232
233


234
235
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
220
221
222
223
224
225
226


227
228
229
230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254







-
-
+
+


-
+















-
+







                first = 0;
                continue;
            } else {
                break;
            }
        }
        first = 0;

        /*
        
        /* 
         * Check if option is known and allowed
         */

        
        optionExists = 1;
        if (Tcl_GetIndexFromObj(NULL, objv[index], formatOptionNames,
                "format option", 0, &optIndex) != TCL_OK) {
            optionExists = 0;
        }
        if (!optionExists || !((1 << optIndex) & allowedOptions)) {
            Tcl_SetObjResult(interp, GetBadOptMsg(Tcl_GetString(objv[index]),
                    allowedOptions));
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION", NULL);
            return TCL_ERROR;
        }

        /*
         * Option-specific checks
         */

        
        switch (1 << optIndex) {
        case OPT_COLORFORMAT:
            *indexPtr = ++index;
            if (index >= objc) {
                Tcl_SetObjResult(interp, Tcl_ObjPrintf("the \"%s\" option "
                        "requires a value", Tcl_GetString(objv[index - 1])));
                Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316

317
318
319
320
321

322
323
324
325
326
327
328

329
330

331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352


353
354
355


356
357
358
359
360
361
362
363
364
365

366
367
368
369
370

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385


386
387
388


389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432

433
434
435

436
437

438
439

440
441
442
443
444
445
446
447
448
449
450
451
452

453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474

475
476

477
478
479
480
481
482


483
484

485
486
487
488
489
490
491
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310

311
312
313
314
315

316
317
318
319
320
321
322

323
324

325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340

341
342
343
344
345


346
347
348


349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378


379
380
381


382
383
384
385
386
387
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412


413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428

429
430

431
432

433
434
435
436
437
438
439
440
441
442
443
444
445

446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

464
465
466
467

468
469

470
471
472
473
474


475
476
477

478
479
480
481
482
483
484
485







-
+










-
+












-
+














-
+

-
+




-
+






-
+

-
+


-
+












-
+




-
-
+
+

-
-
+
+









-
+




-
+













-
-
+
+

-
-
+
+












-
+
















-
-
+












-
+


-
+

-
+

-
+












-
+

-
+















-
+



-
+

-
+




-
-
+
+

-
+







                Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad color format "
                        "\"%s\": must be rgb, rgba, or list",
                        Tcl_GetString(objv[index])));
                Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
                        "BAD_COLOR_FORMAT", NULL);
                return TCL_ERROR;
            }
            optPtr->colorFormat = (enum ColorFormatType)typeIndex;
            optPtr->colorFormat = typeIndex;
            break;
        default:
            Tcl_Panic("ParseFormatOptions: unexpected switch fallthrough");
        }

        /*
         * Add option to bitfield in optPtr
         */
        optPtr->options |= (1 << optIndex);
    }

    
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 *  GetBadOptMsg --
 *
 *      Build a Tcl_Obj containing an error message in the form "bad option
 *      "xx": must be y, or z", based on the bits set in allowedOpts.
 *
 * Results:
 *      A Tcl Object containig the error message.
 *      A Tcl Object containig the error message. 
 *
 * Side effects:
 *      None
 *----------------------------------------------------------------------
 */
static Tcl_Obj *
GetBadOptMsg(
    const char *badValue,   /* the erroneous option */
    int allowedOpts)        /* bitfield specifying the allowed options */
{
    int i, bit;
    Tcl_Obj *resObj = Tcl_ObjPrintf("bad format option \"%s\": ", badValue);

    if (allowedOpts == 0) {
        Tcl_AppendToObj(resObj, "no options allowed", TCL_INDEX_NONE);
        Tcl_AppendToObj(resObj, "no options allowed", -1);
    } else {
        Tcl_AppendToObj(resObj, "must be ", TCL_INDEX_NONE);
        Tcl_AppendToObj(resObj, "must be ", -1);
        bit = 1;
        for (i = 0; formatOptionNames[i] != NULL; i++) {
            if (allowedOpts & bit) {
                if (allowedOpts & (bit -1)) {
                    /*
                    /* 
                     * not the first option
                     */
                    if (allowedOpts & ~((bit << 1) - 1)) {
                        /*
                         * not the last option
                         */
                        Tcl_AppendToObj(resObj, ", ", TCL_INDEX_NONE);
                        Tcl_AppendToObj(resObj, ", ", -1);
                    } else {
                        Tcl_AppendToObj(resObj, ", or ", TCL_INDEX_NONE);
                        Tcl_AppendToObj(resObj, ", or ", -1);
                    }
                }
                Tcl_AppendToObj(resObj, formatOptionNames[i], TCL_INDEX_NONE);
                Tcl_AppendToObj(resObj, formatOptionNames[i], -1);
            }
            bit <<=1;
        }
    }
    return resObj;
}

/*
 *----------------------------------------------------------------------
 *
 * StringMatchDef --
 *
 *      Default string match function. Test if image data in string form
 *      Default string match function. Test if image data in string form 
 *      appears to be in the default list-of-list-of-pixel-data format
 *      accepted by the "<img> put" command.
 *
 * Results:
 *      If thte data is in the default format, writes the size of the image
 *      to widthPtr and heightPtr and returns 1. Otherwise, leaves an error
 *      If thte data is in the default format, writes the size of the image 
 *      to widthPtr and heightPtr and returns 1. Otherwise, leaves an error 
 *      message in interp (if not NULL) and returns 0.
 *      Note that this function does not parse all data points. A return
 *      value of 1 does not guarantee that the data can be read without
 *      Note that this function does not parse all data points. A return 
 *      value of 1 does not guarantee that the data can be read without 
 *      errors.
 *
 * Side effects:
 *      None
 *----------------------------------------------------------------------
 */
static int
StringMatchDef(
    Tcl_Obj *data,          /* The data to check */
    TCL_UNUSED(Tcl_Obj *),  /* Value of the -format option, not used here */
    Tcl_Obj *formatString,  /* Value of the -format option, not used here */
    int *widthPtr,          /* Width of image is written to this location */
    int *heightPtr,         /* Height of image is written to this location */
    Tcl_Interp *interp)     /* Error messages are left in this interpreter */
{
    Tcl_Size y, rowCount, colCount, curColCount;
    int y, rowCount, colCount, curColCount;
    unsigned char dummy;
    Tcl_Obj **rowListPtr, *pixelData;

    /*
     * See if data can be parsed as a list, if every element is itself a valid
     * list and all sublists have the same length.
     */

    if (Tcl_ListObjGetElements(interp, data, &rowCount, &rowListPtr)
            != TCL_OK) {
        return 0;
    }
    if (rowCount == 0) {
        /*
         * empty list is valid data
        /* 
         * empty list is valid data 
         */

        *widthPtr = 0;
        
        *widthPtr = 0; 
        *heightPtr = 0;
        return 1;
    }
    colCount = -1;
    for (y = 0; y < rowCount; y++) {
        if (Tcl_ListObjLength(interp, rowListPtr[y], &curColCount) != TCL_OK) {
            return 0;
        }
        if (colCount < 0) {
            colCount = curColCount;
        } else if (curColCount != colCount) {
            if (interp != NULL) {
                Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid row # %" TCL_SIZE_MODIFIER "d: "
                Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid row # %d: "
                        "all rows must have the same number of elements", y));
                Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
                        "INVALID_DATA", NULL);
            }
            return 0;
        }
    }

    /*
     * Data in base64 encoding (or even binary data), might actually pass
     * these tests. To avoid parsing it as list of lists format, check one
     * pixel for validity.
     */
    if (Tcl_ListObjIndex(interp, rowListPtr[0], 0, &pixelData) != TCL_OK) {
        return 0;
    }
    (void)Tcl_GetString(pixelData);
    if (pixelData->length > TK_PHOTO_MAX_COLOR_LENGTH) {
    if (Tcl_GetCharLength(pixelData) > TK_PHOTO_MAX_COLOR_CHARS) {
        return 0;
    }
    if (ParseColor(interp, pixelData, Tk_Display(Tk_MainWindow(interp)),
            Tk_Colormap(Tk_MainWindow(interp)), &dummy, &dummy, &dummy, &dummy)
            != TCL_OK) {
        return 0;
    }

    /*
     * Looks like we have valid data for this format.
     * We do not check any pixel values - that's the job of ImgStringRead()
     */

    
    *widthPtr = colCount;
    *heightPtr = rowCount;

    
    return 1;

    
}

 
/*
 *----------------------------------------------------------------------
 *
 * StringReadDef --
 *
 *      String read function for default format. (see manpage for details on
 *      the format).
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      If the data has valid format, write it to the image identified by
 *      If the data has valid format, write it to the image identified by 
 *      imageHandle.
 *      If the image data cannot be parsed, an error message is left in
 *      If the image data cannot be parsed, an error message is left in 
 *      interp.
 *
 *----------------------------------------------------------------------
*/

static int
StringReadDef(
    Tcl_Interp *interp,         /* leave error messages here */
    Tcl_Obj *data,              /* the data to parse */
    Tcl_Obj *formatString,      /* value of the -format option */
    Tk_PhotoHandle imageHandle, /* write data to this image */
    int destX, int destY,       /* start writing data at this point
                                 * in destination image*/
    int width, int height,      /* dimensions of area to write to */
    int srcX, int srcY)         /* start reading source data at these
                                 * coordinates */
                                 * coordinates */ 
{
    Tcl_Obj **rowListPtr, **colListPtr;
    Tcl_Obj **objv;
    Tcl_Size objc, rowCount, colCount, curColCount;
    int objc;
    unsigned char *curPixelPtr;
    int x, y;
    int x, y, rowCount, colCount, curColCount;
    Tk_PhotoImageBlock srcBlock;
    Display *display;
    Colormap colormap;
    struct FormatOptions opts;
    Tcl_Size optIndex;

    int optIndex;
    
    /*
     * Parse format suboptions
     * Parse format suboptions 
     * We don't use any format suboptions, but we still need to provide useful
     * error messages if suboptions were specified.
     */

    memset(&opts, 0, sizeof(opts));
    if (formatString != NULL) {
        if (Tcl_ListObjGetElements(interp, formatString, &objc, &objv)
525
526
527
528
529
530
531
532

533
534
535
536
537

538
539
540
541
542
543
544
545

546
547
548
549

550
551
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573


574
575
576
577
578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598

599
600
601

602
603
604

605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631

632
633

634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
661

662
663
664
665
666
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

689
690

691
692
693
694
695
696
697
698

699
700

701
702
703

704
705
706

707
708
709
710

711
712

713
714

715
716

717
718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737

738
739
740
741
742

743
744
745
746
747
748
749
750
751
752
753


754
755
756
757
758
759
760




761
762
763
764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782


783
784
785
786
787
788
789




790
791
792
793
794

795
796
797
798
799
800
801

802
803
804

805
806
807
808
809
810
811
812
813

814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831



832
833
834




835

836
837
838
839
840

841

842
843
844
845
846

847

848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865

866
867
868
869
870
871
872
873

874
875
876
877
878
879
880
881
882
883
884
885

886
887
888
889
890

891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906



907
908
909
910
911
912
913
519
520
521
522
523
524
525

526
527
528
529
530

531
532
533
534
535
536
537
538

539
540
541
542

543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559
560
561
562
563
564
565


566
567
568
569
570
571
572
573
574
575
576
577
578
579

580
581
582
583
584
585
586
587
588
589
590
591

592
593
594

595
596
597

598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

625
626

627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654

655
656
657
658
659
660

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681

682
683

684
685
686
687
688
689
690
691

692
693

694
695
696

697
698
699

700
701
702
703

704
705

706
707

708
709

710
711
712
713
714
715
716
717
718
719
720
721
722
723

724
725
726
727
728
729
730

731
732
733
734
735

736
737
738
739
740
741
742
743
744
745


746
747
748
749
750




751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767

768
769
770
771
772
773
774


775
776
777
778
779




780
781
782
783
784
785
786
787

788
789
790
791
792
793
794

795
796
797

798
799
800
801
802
803
804
805
806

807
808

809
810
811
812
813
814
815
816
817
818
819
820
821
822



823
824
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865

866
867
868
869
870
871
872
873

874
875
876
877
878
879
880
881
882
883
884
885

886
887
888
889
890

891
892
893
894
895
896
897
898
899
900
901
902
903
904



905
906
907
908
909
910
911
912
913
914







-
+




-
+







-
+



-
+








-
+













-
-
+
+












-
+











-
+


-
+


-
+









-
+
















-
+

-
+



















-
+







-
+





-
+




















-
+

-
+







-
+

-
+


-
+


-
+



-
+

-
+

-
+

-
+













-
+






-
+




-
+









-
-
+
+



-
-
-
-
+
+
+
+













-
+






-
-
+
+



-
-
-
-
+
+
+
+




-
+






-
+


-
+








-
+

-
+













-
-
-
+
+
+



+
+
+
+
-
+





+

+





+
-
+














-
+


-
+







-
+











-
+




-
+













-
-
-
+
+
+







        return TCL_OK;
    }
    if (srcX < 0 || srcY < 0 || srcX >= rowCount || srcY >= colCount) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf("source coordinates out of range"));
        Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "COORDINATES", NULL);
        return TCL_ERROR;
    }

    
    /*
     * Memory allocation overflow protection.
     * May not be able to trigger/ demo / test this.
     */

    
    if (colCount > (int)(UINT_MAX / 4 / rowCount)) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                        "photo image dimensions exceed Tcl memory limits"));
        Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
                "OVERFLOW", NULL);
        return TCL_OK;
    }

    
    /*
     * Read data and put it to imageHandle
     */

    
    srcBlock.width = colCount - srcX;
    srcBlock.height = rowCount - srcY;
    srcBlock.pixelSize = 4;
    srcBlock.pitch = srcBlock.width * 4;
    srcBlock.offset[0] = 0;
    srcBlock.offset[1] = 1;
    srcBlock.offset[2] = 2;
    srcBlock.offset[3] = 3;
    srcBlock.pixelPtr = (unsigned char *)attemptckalloc(srcBlock.pitch * srcBlock.height);
    srcBlock.pixelPtr = attemptckalloc(srcBlock.pitch * srcBlock.height);
    if (srcBlock.pixelPtr == NULL) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf(TK_PHOTO_ALLOC_FAILURE_MESSAGE));
        Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
        return TCL_ERROR;
    }
    curPixelPtr = srcBlock.pixelPtr;
    display = Tk_Display(Tk_MainWindow(interp));
    colormap = Tk_Colormap(Tk_MainWindow(interp));
    for (y = srcY; y < rowCount; y++) {
        /*
         * We don't test the length of row, as that's been done in
         * ImgStringMatch()
         */

        if (Tcl_ListObjGetElements(interp, rowListPtr[y], &curColCount,
        
        if (Tcl_ListObjGetElements(interp, rowListPtr[y], &curColCount, 
                &colListPtr) != TCL_OK) {
            goto errorExit;
        }
        for (x = srcX; x < colCount; x++) {
            if (ParseColor(interp, colListPtr[x], display, colormap,
                    curPixelPtr, curPixelPtr + 1, curPixelPtr + 2,
                    curPixelPtr + 3) != TCL_OK) {
                goto errorExit;
            }
            curPixelPtr += 4;
        }
    }

    
    /*
     * Write image data to destHandle
     */
    if (Tk_PhotoPutBlock(interp, imageHandle, &srcBlock, destX, destY,
            width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
        goto errorExit;
    }

    ckfree(srcBlock.pixelPtr);

    return TCL_OK;

    
  errorExit:
    ckfree(srcBlock.pixelPtr);

    
    return TCL_ERROR;
}

 
/*
 *----------------------------------------------------------------------
 *
 * StringWriteDef --
 *
 *      String write function for default image data format. See the user
 *      documentation for details.
 *
 * Results:
 *      The converted data is set as the result of interp. Returns a standard
 *      The converted data is set as the result of interp. Returns a standard 
 *      Tcl result.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

static int
StringWriteDef(
    Tcl_Interp *interp,                 /* For the result and errors */
    Tcl_Obj *formatString,              /* The value of the -format option */
    Tk_PhotoImageBlock *blockPtr)       /* The image data to convert */
{
    int greenOffset, blueOffset, alphaOffset, hasAlpha;
    Tcl_Obj *result, **objv = NULL;
    Tcl_Size objc, allowedOpts, optIndex;
    int objc, allowedOpts, optIndex;
    struct FormatOptions opts;

    
    /*
     * Parse format suboptions
     */
    if (Tcl_ListObjGetElements(interp, formatString, &objc, &objv)
            != TCL_OK) {
        return TCL_ERROR;
    }
    allowedOpts = OPT_COLORFORMAT;
    optIndex = 0;
    if (ParseFormatOptions(interp, allowedOpts, objc, objv, &optIndex, &opts)
            != TCL_OK) {
        return TCL_ERROR;
    }
    if (optIndex < objc) {
        Tcl_SetObjResult(interp,
                GetBadOptMsg(Tcl_GetString(objv[optIndex]), allowedOpts));
        Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION", NULL);
        return TCL_ERROR;
    }

    
    greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
    blueOffset = blockPtr->offset[2] - blockPtr->offset[0];

    /*
     * A negative alpha offset signals that the image is fully opaque.
     * That's not really documented anywhere, but it's the way it is!
     */

    
    if (blockPtr->offset[3] < 0) {
        hasAlpha = 0;
        alphaOffset = 0;
    } else {
        hasAlpha = 1;
        alphaOffset = blockPtr->offset[3] - blockPtr->offset[0];
        alphaOffset = blockPtr->offset[3] - blockPtr->offset[0];        
    }

    if ((blockPtr->width > 0) && (blockPtr->height > 0)) {
        int row, col;
        Tcl_DString data, line;
        char colorBuf[11];
        unsigned char *pixelPtr;
        unsigned char alphaVal = 255;

        Tcl_DStringInit(&data);
        for (row=0; row<blockPtr->height; row++) {
            pixelPtr = blockPtr->pixelPtr + blockPtr->offset[0]
                    + row * blockPtr->pitch;
            Tcl_DStringInit(&line);
            for (col=0; col<blockPtr->width; col++) {
                if (hasAlpha) {
                    alphaVal = pixelPtr[alphaOffset];
                }

                /*
                 * We don't build lines as a list for #RGBA and #RGB. Since
                 * We don't build lines as a list for #RGBA and #RGB. Since 
                 * these color formats look like comments, the first element
                 * of the list would get quoted with an additional {} .
                 * of the list would get quoted with an additional {} . 
                 * While this is not a problem if the data is used as
                 * a list, it would cause problems if someone decides to parse
                 * it as a string (and it looks kinda strange)
                 */

                switch (opts.colorFormat) {
                case COLORFORMAT_RGB2:
                    snprintf(colorBuf, sizeof(colorBuf), "#%02x%02x%02x ",  pixelPtr[0],
                    sprintf(colorBuf, "#%02x%02x%02x ",  pixelPtr[0],
                            pixelPtr[greenOffset], pixelPtr[blueOffset]);
                    Tcl_DStringAppend(&line, colorBuf, TCL_INDEX_NONE);
                    Tcl_DStringAppend(&line, colorBuf, -1);
                    break;
                case COLORFORMAT_RGBA2:
                    snprintf(colorBuf, sizeof(colorBuf), "#%02x%02x%02x%02x ",
                    sprintf(colorBuf, "#%02x%02x%02x%02x ",
                            pixelPtr[0], pixelPtr[greenOffset],
                            pixelPtr[blueOffset], alphaVal);
                    Tcl_DStringAppend(&line, colorBuf, TCL_INDEX_NONE);
                    Tcl_DStringAppend(&line, colorBuf, -1);
                    break;
                case COLORFORMAT_LIST:
                    Tcl_DStringStartSublist(&line);
                    snprintf(colorBuf, sizeof(colorBuf), "%d", pixelPtr[0]);
                    sprintf(colorBuf, "%d", pixelPtr[0]);
                    Tcl_DStringAppendElement(&line, colorBuf);
                    snprintf(colorBuf, sizeof(colorBuf), "%d", pixelPtr[greenOffset]);
                    sprintf(colorBuf, "%d", pixelPtr[greenOffset]);
                    Tcl_DStringAppendElement(&line, colorBuf);
                    snprintf(colorBuf, sizeof(colorBuf), "%d", pixelPtr[blueOffset]);
                    sprintf(colorBuf, "%d", pixelPtr[blueOffset]);
                    Tcl_DStringAppendElement(&line, colorBuf);
                    snprintf(colorBuf, sizeof(colorBuf), "%d", alphaVal);
                    sprintf(colorBuf, "%d", alphaVal);
                    Tcl_DStringAppendElement(&line, colorBuf);
                    Tcl_DStringEndSublist(&line);
                    break;
                default:
                    Tcl_Panic("unexpected switch fallthrough");
                }
                pixelPtr += blockPtr->pixelSize;
            }
            if (opts.colorFormat != COLORFORMAT_LIST) {
                /*
                 * For the #XXX formats, we need to remove the last
                 * whitespace.
                 */

                
                *(Tcl_DStringValue(&line) + Tcl_DStringLength(&line) - 1)
                        = '\0';
            }
            Tcl_DStringAppendElement(&data, Tcl_DStringValue(&line));
            Tcl_DStringFree(&line);
        }
        result = Tcl_NewStringObj(Tcl_DStringValue(&data), TCL_INDEX_NONE);
        result = Tcl_NewStringObj(Tcl_DStringValue(&data), -1);
        Tcl_DStringFree(&data);
    } else {
        result = Tcl_NewObj();
    }

    
    Tcl_SetObjResult(interp, result);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ParseColor --
 *
 *      This function extracts color and alpha values from a string. It
 *      understands standard Tk color formats, alpha suffixes and the color
 *      This function extracts color and alpha values from a string. It 
 *      understands standard Tk color formats, alpha suffixes and the color 
 *      formats specific to photo images, which include alpha data.
 *
 * Results:
 *      On success, writes red, green, blue and alpha values to the
 *      corresponding pointers. If the color spec contains no alpha
 *      information, 255 is taken as transparency value.
 *      If the input cannot be parsed, leaves an error message in
 *      On success, writes red, green, blue and alpha values to the 
 *      corresponding pointers. If the color spec contains no alpha 
 *      information, 255 is taken as transparency value. 
 *      If the input cannot be parsed, leaves an error message in 
 *      interp. Returns a standard Tcl result.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static int
ParseColor(
    Tcl_Interp *interp,         /* error messages go there */
    Tcl_Obj *specObj,           /* the color data to parse */
    Display *display,           /* display of main window, needed to parse
                                 * standard Tk colors */
    Colormap colormap,          /* colormap of current display */
    Colormap colormap,          /* colormap of current display */ 
    unsigned char *redPtr,      /* the result is written to these pointers */
    unsigned char *greenPtr,
    unsigned char *bluePtr,
    unsigned char *alphaPtr)
{
    const char *specString;
    Tcl_Size length;

    int charCount;
    
    /*
     * Find out which color format we have
     */

    specString = Tcl_GetStringFromObj(specObj, &length);

    if (length == 0) {
    
    specString = Tcl_GetStringFromObj(specObj, &charCount);
    
    if (charCount == 0) {
        /* Empty string */
        *redPtr = *greenPtr = *bluePtr = *alphaPtr = 0;
        return TCL_OK;
    }
    if (length > TK_PHOTO_MAX_COLOR_LENGTH) {
    if (charCount > TK_PHOTO_MAX_COLOR_CHARS) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid color"));
        Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
                "INVALID_COLOR", NULL);
        return TCL_ERROR;
    }
    if (specString[0] == '#') {
        return ParseColorAsHex(interp, specString, length, display,
        return ParseColorAsHex(interp, specString, charCount, display,
                colormap, redPtr, greenPtr, bluePtr, alphaPtr);
    }
    if (ParseColorAsList(specString,
    if (ParseColorAsList(interp, specString, charCount,
            redPtr, greenPtr, bluePtr, alphaPtr) == TCL_OK) {
        return TCL_OK;
    }

    /*
     * Parsing the color as standard Tk color always is the last option tried
     * because TkParseColor() is very slow with values it cannot parse.
     */

    
    Tcl_ResetResult(interp);
    return ParseColorAsStandard(interp, specString, length, display,
    return ParseColorAsStandard(interp, specString, charCount, display,
            colormap, redPtr, greenPtr, bluePtr, alphaPtr);

}

/*
 *----------------------------------------------------------------------
 *
 * ParseColorAsList --
 *
 *      This function extracts color and alpha values from a list of 3 or 4
 *      integers (the list color format).
 *
 * Results:
 *      On success, writes red, green, blue and alpha values to the
 *      corresponding pointers. If the color spec contains no alpha
 *      information, 255 is taken as transparency value.
 *      On success, writes red, green, blue and alpha values to the 
 *      corresponding pointers. If the color spec contains no alpha 
 *      information, 255 is taken as transparency value. 
 *      Returns a standard Tcl result.
 *
 * Side effects:
 *      Does *not* leave error messages in interp. The reason is that
 *      it is not always possible to tell if the list format was even
 *      intended and thus it is hard to return meaningful messages.
 *      A general error message from the caller is probably the best 
 *      None
 *      alternative.
 *
 *----------------------------------------------------------------------
 */
static int
ParseColorAsList(
    Tcl_Interp *interp,         /* not used */
    const char *colorString,    /* the color data to parse */
    int colorStrLen,            /* length of the color string */
    unsigned char *redPtr,      /* the result is written to these pointers */
    unsigned char *greenPtr,
    unsigned char *bluePtr,
    unsigned char *alphaPtr)
{
    
    /*
    /* 
     * This is kinda ugly. The code would be certainly nicer if it
     * used Tcl_ListObjGetElements() and Tcl_GetIntFromObj(). But with
     * strtol() it's *much* faster.
     */

    const char *curPos;
    int values[4];
    int i;

    curPos = colorString;
    i = 0;

    /*
     * strtol can give false positives with a sequence of space chars.
     * To avoid that, advance the pointer to the next non-blank char.
     * To avoid that, avance the pointer to the next non-blank char.
     */

    while(isspace(UCHAR(*curPos))) {
    while(isspace(*curPos)) {
        ++curPos;
    }
    while (i < 4 && *curPos != '\0') {
        values[i] = strtol(curPos, (char **)&curPos, 0);
        if (values[i] < 0 || values[i] > 255) {
            return TCL_ERROR;
        }
        while(isspace(UCHAR(*curPos))) {
        while(isspace(*curPos)) {
            ++curPos;
        }
        ++i;
    }

    if (i < 3 || *curPos != '\0') {
        return TCL_ERROR;
    }
    if (i < 4) {
        values[3] = 255;
    }

    
    *redPtr = (unsigned char) values[0];
    *greenPtr = (unsigned char) values[1];
    *bluePtr = (unsigned char) values[2];
    *alphaPtr = (unsigned char) values[3];

    
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ParseColorAsHex --
 *
 *      This function extracts color and alpha values from a string
 *      starting with '#', followed by hex digits. It undestands both
 *      the #RGBA form and the #RBG (with optional suffix)
 *
 * Results:
 *      On success, writes red, green, blue and alpha values to the
 *      corresponding pointers. If the color spec contains no alpha
 *      information, 255 is taken as transparency value.
 *      On success, writes red, green, blue and alpha values to the 
 *      corresponding pointers. If the color spec contains no alpha 
 *      information, 255 is taken as transparency value. 
 *      Returns a standard Tcl result.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936
937
938
939

940
941
942
943
944

945
946
947
948
949
950
951
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936
937
938
939

940
941
942
943
944

945
946
947
948
949
950
951
952







-
+










-
+




-
+







    unsigned char *redPtr,      /* the result is written to these pointers */
    unsigned char *greenPtr,
    unsigned char *bluePtr,
    unsigned char *alphaPtr)
{
    int i;
    unsigned long int colorValue = 0;

        
    if (colorStrLen - 1 != 4 && colorStrLen - 1 != 8) {
        return ParseColorAsStandard(interp, colorString, colorStrLen,
                display, colormap, redPtr, greenPtr, bluePtr, alphaPtr);
    }
    for (i = 1; i < colorStrLen; i++) {
        if (!isxdigit(UCHAR(colorString[i]))) {
            /*
             * There still is a chance that this is a Tk color with
             * an alpha suffix
             */

            
            return ParseColorAsStandard(interp, colorString, colorStrLen,
                    display, colormap, redPtr, greenPtr, bluePtr, alphaPtr);
        }
    }

    
    colorValue = strtoul(colorString + 1, NULL, 16);
    switch (colorStrLen - 1) {
    case 4:
        /* #RGBA format */
        *redPtr = (unsigned char) ((colorValue >> 12) * 0x11);
        *greenPtr = (unsigned char) (((colorValue >> 8) & 0xf) * 0x11);
        *bluePtr = (unsigned char) (((colorValue >> 4) & 0xf) * 0x11);
972
973
974
975
976
977
978
979
980
981



982
983
984
985
986
987
988
973
974
975
976
977
978
979



980
981
982
983
984
985
986
987
988
989







-
-
-
+
+
+







 * ParseColorAsStandard --
 *
 *      This function tries to split a color stirng in a color and a
 *      suffix part and to extract color and alpha values from them. The
 *      color part is treated as regular Tk color.
 *
 * Results:
 *      On success, writes red, green, blue and alpha values to the
 *      corresponding pointers. If the color spec contains no alpha
 *      information, 255 is taken as transparency value.
 *      On success, writes red, green, blue and alpha values to the 
 *      corresponding pointers. If the color spec contains no alpha 
 *      information, 255 is taken as transparency value. 
 *      Returns a standard Tcl result.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
996
997
998
999
1000
1001
1002
1003


1004
1005
1006
1007

1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028

1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039

1040
1041
1042
1043
1044
1045

1046
1047
1048
1049


1050
1051

1052
1053

1054
1055
1056
1057
1058
1059


1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008

1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029

1030
1031
1032
1033
1034
1035
1036

1037
1038
1039
1040

1041
1042
1043
1044
1045
1046

1047
1048
1049
1050

1051
1052
1053

1054
1055

1056
1057
1058
1059
1060


1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081







-
+
+



-
+



-
+













-
+


-
+






-
+



-
+





-
+



-
+
+

-
+

-
+




-
-
+
+











-
+







    unsigned char *redPtr,      /* the result is written to these pointers */
    unsigned char *greenPtr,
    unsigned char *bluePtr,
    unsigned char *alphaPtr)
{
    XColor parsedColor;
    const char *suffixString, *colorString;
    char colorBuffer[TK_PHOTO_MAX_COLOR_LENGTH + 1];
    char colorBuffer[TK_PHOTO_MAX_COLOR_CHARS + 1];
    char *tmpString;
    double fracAlpha;
    unsigned int suffixAlpha;
    int i;

        
    /*
     * Split color data string in color and suffix parts
     */

 
    if ((suffixString = strrchr(specString, '@')) == NULL
            && ((suffixString = strrchr(specString, '#')) == NULL
                    || suffixString == specString)) {
        suffixString = specString + specStrLen;
        colorString = specString;
    } else {
        strncpy(colorBuffer, specString, suffixString - specString);
        colorBuffer[suffixString - specString] = '\0';
        colorString = (const char*)colorBuffer;
    }

    /*
     * Try to parse as standard Tk color.
     *
     * 
     * We don't use Tk_GetColor() et al. here, as those functions
     * migth return a color that does not exaxtly match the given name
     * if the colormap is full. Also, we don't really want the color to be
     * if the colormap is full. Also, we don't really want the color to be 
     * added to the colormap.
     */

    if ( ! TkParseColor(display, colormap, colorString, &parsedColor)) {
         Tcl_SetObjResult(interp, Tcl_ObjPrintf(
            "invalid color name \"%s\"", specString));
         Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
         Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", 
                 "INVALID_COLOR", NULL);
         return TCL_ERROR;
    }

        
    /*
     * parse the Suffix
     */

    switch (suffixString[0]) {
    case '\0':
    case '\0': 
        suffixAlpha = 255;
        break;
    case '@':
        if (Tcl_GetDouble(NULL, suffixString + 1, &fracAlpha) != TCL_OK) {
        fracAlpha = strtod(suffixString + 1, &tmpString);
        if (*tmpString != '\0') {
            Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid alpha "
                    "suffix \"%s\": expected floating-point value",
                    "suffix \"%s\": expected floating-point value", 
                    suffixString));
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", 
                    "INVALID COLOR", NULL);
            return TCL_ERROR;
        }
        if (fracAlpha < 0 || fracAlpha > 1) {
            Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid alpha suffix"
                    " \"%s\": value must be in the range from 0 to 1",
            Tcl_SetObjResult(interp, Tcl_ObjPrintf("invalid alpha suffix" 
                    " \"%s\": value must be in the range from 0 to 1", 
                    suffixString));
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
                    "INVALID_COLOR", NULL);
            return TCL_ERROR;
        }
        suffixAlpha = (unsigned int) floor(fracAlpha * 255 + 0.5);
        break;
    case '#':
        if (strlen(suffixString + 1) < 1 || strlen(suffixString + 1)> 2) {
            Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                    "invalid alpha suffix \"%s\"", suffixString));
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
            Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", 
                    "INVALID_COLOR", NULL);
            return TCL_ERROR;
        }
        for (i = 1; i <= (int)strlen(suffixString + 1); i++) {
            if ( ! isxdigit(UCHAR(suffixString[i]))) {
                Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                        "invalid alpha suffix \"%s\": expected hex digit",
1088
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104
1105







-
+







        } else {
            sscanf(suffixString, "#%2x", &suffixAlpha);
        }
        break;
    default:
        Tcl_Panic("unexpected switch fallthrough");
    }

    
    *redPtr = (unsigned char) (parsedColor.red >> 8);
    *greenPtr = (unsigned char) (parsedColor.green >> 8);
    *bluePtr = (unsigned char) (parsedColor.blue >> 8);
    *alphaPtr = (unsigned char) suffixAlpha;

    return TCL_OK;
}
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141







-
+












 */
int
TkDebugPhotoStringMatchDef(
    Tcl_Interp *interp,     /* Error messages are left in this interpreter */
    Tcl_Obj *data,          /* The data to check */
    Tcl_Obj *formatString,  /* Value of the -format option, not used here */
    int *widthPtr,          /* Width of image is written to this location */
    int *heightPtr)         /* Height of image is written to this location */
    int *heightPtr)         /* Height of image is written to this location */    
{
    return StringMatchDef(data, formatString, widthPtr, heightPtr, interp);
}


/* Local Variables: */
/* mode: c */
/* fill-column: 78 */
/* c-basic-offset: 4 */
/* tab-width: 8 */
/* indent-tabs-mode: nil */
/* End: */

Changes to generic/tkImgPNG.c.

1
2
3
4
5
6
7


8
9
10
11
12

13
14
15
16


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51




52
53
54
55
56
57
58






59
60
61
62


63
64

65
66
67
68



69
70

71
72

73
74
75
76



77
78
79
80
81
82
83
1
2
3
4
5


6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48




49
50
51
52
53






54
55
56
57
58
59
60
61


62
63
64

65
66



67
68
69
70

71
72

73
74



75
76
77
78
79
80
81
82
83
84





-
-
+
+





+


-
-
+
+




















-
+










-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+


-
-
+
+

-
+

-
-
-
+
+
+

-
+

-
+

-
-
-
+
+
+







/*
 * tkImgPNG.c --
 *
 *	A Tk photo image file handler for PNG files.
 *
 * Copyright © 2006-2008 Muonics, Inc.
 * Copyright © 2008 Donal K. Fellows
 * Copyright (c) 2006-2008 Muonics, Inc.
 * Copyright (c) 2008 Donal K. Fellows
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "assert.h"
#include "tkInt.h"

#define	PNG_UINT32(a,b,c,d)	\
	(((unsigned long)(a) << 24) | ((unsigned long)(b) << 16) | ((unsigned long)(c) << 8) | (unsigned long)(d))
#define	PNG_INT32(a,b,c,d)	\
	(((long)(a) << 24) | ((long)(b) << 16) | ((long)(c) << 8) | (long)(d))
#define	PNG_BLOCK_SZ	1024		/* Process up to 1k at a time. */
#define PNG_MIN(a, b) (((a) < (b)) ? (a) : (b))

/*
 * Every PNG image starts with the following 8-byte signature.
 */

#define PNG_SIG_SZ	8
static const unsigned char pngSignature[] = {
    137, 80, 78, 71, 13, 10, 26, 10
};

static const int startLine[8] = {
    0, 0, 0, 4, 0, 2, 0, 1
};

/*
 * Chunk type flags.
 */

#define PNG_CF_ANCILLARY 0x20000000L	/* Non-critical chunk (can ignore). */
#define PNG_CF_ANCILLARY 0x10000000L	/* Non-critical chunk (can ignore). */
#define PNG_CF_PRIVATE   0x00100000L	/* Application-specific chunk. */
#define PNG_CF_RESERVED  0x00001000L	/* Not used. */
#define PNG_CF_COPYSAFE  0x00000010L	/* Opaque data safe for copying. */

/*
 * Chunk types, not all of which have support implemented. Note that there are
 * others in the official extension set which we will never support (as they
 * are officially deprecated).
 */

#define CHUNK_IDAT	PNG_UINT32('I','D','A','T')	/* Pixel data. */
#define CHUNK_IEND	PNG_UINT32('I','E','N','D')	/* End of Image. */
#define CHUNK_IHDR	PNG_UINT32('I','H','D','R')	/* Header. */
#define CHUNK_PLTE	PNG_UINT32('P','L','T','E')	/* Palette. */
#define CHUNK_IDAT	PNG_INT32('I','D','A','T')	/* Pixel data. */
#define CHUNK_IEND	PNG_INT32('I','E','N','D')	/* End of Image. */
#define CHUNK_IHDR	PNG_INT32('I','H','D','R')	/* Header. */
#define CHUNK_PLTE	PNG_INT32('P','L','T','E')	/* Palette. */

#define CHUNK_bKGD	PNG_UINT32('b','K','G','D')	/* Background Color */
#define CHUNK_cHRM	PNG_UINT32('c','H','R','M')	/* Chroma values. */
#define CHUNK_gAMA	PNG_UINT32('g','A','M','A')	/* Gamma. */
#define CHUNK_hIST	PNG_UINT32('h','I','S','T')	/* Histogram. */
#define CHUNK_iCCP	PNG_UINT32('i','C','C','P')	/* Color profile. */
#define CHUNK_iTXt	PNG_UINT32('i','T','X','t')	/* Internationalized
#define CHUNK_bKGD	PNG_INT32('b','K','G','D')	/* Background Color */
#define CHUNK_cHRM	PNG_INT32('c','H','R','M')	/* Chroma values. */
#define CHUNK_gAMA	PNG_INT32('g','A','M','A')	/* Gamma. */
#define CHUNK_hIST	PNG_INT32('h','I','S','T')	/* Histogram. */
#define CHUNK_iCCP	PNG_INT32('i','C','C','P')	/* Color profile. */
#define CHUNK_iTXt	PNG_INT32('i','T','X','t')	/* Internationalized
							 * text (comments,
							 * etc.) */
#define CHUNK_oFFs	PNG_UINT32('o','F','F','s')	/* Image offset. */
#define CHUNK_pCAL	PNG_UINT32('p','C','A','L')	/* Pixel calibration
#define CHUNK_oFFs	PNG_INT32('o','F','F','s')	/* Image offset. */
#define CHUNK_pCAL	PNG_INT32('p','C','A','L')	/* Pixel calibration
							 * data. */
#define CHUNK_pHYs	PNG_UINT32('p','H','Y','s')	/* Physical pixel
#define CHUNK_pHYs	PNG_INT32('p','H','Y','s')	/* Physical pixel
							 * dimensions. */
#define CHUNK_sBIT	PNG_UINT32('s','B','I','T')	/* Significant bits */
#define CHUNK_sCAL	PNG_UINT32('s','C','A','L')	/* Physical scale. */
#define CHUNK_sPLT	PNG_UINT32('s','P','L','T')	/* Suggested
#define CHUNK_sBIT	PNG_INT32('s','B','I','T')	/* Significant bits */
#define CHUNK_sCAL	PNG_INT32('s','C','A','L')	/* Physical scale. */
#define CHUNK_sPLT	PNG_INT32('s','P','L','T')	/* Suggested
							 * palette. */
#define CHUNK_sRGB	PNG_UINT32('s','R','G','B')	/* Standard RGB space
#define CHUNK_sRGB	PNG_INT32('s','R','G','B')	/* Standard RGB space
							 * declaration. */
#define CHUNK_tEXt	PNG_UINT32('t','E','X','t')	/* Plain Latin-1
#define CHUNK_tEXt	PNG_INT32('t','E','X','t')	/* Plain Latin-1
							 * text. */
#define CHUNK_tIME	PNG_UINT32('t','I','M','E')	/* Time stamp. */
#define CHUNK_tRNS	PNG_UINT32('t','R','N','S')	/* Transparency. */
#define CHUNK_zTXt	PNG_UINT32('z','T','X','t')	/* Compressed Latin-1
#define CHUNK_tIME	PNG_INT32('t','I','M','E')	/* Time stamp. */
#define CHUNK_tRNS	PNG_INT32('t','R','N','S')	/* Transparency. */
#define CHUNK_zTXt	PNG_INT32('z','T','X','t')	/* Compressed Latin-1
							 * text. */

/*
 * Color flags.
 */

#define PNG_COLOR_INDEXED	1
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







    /*
     * PNG data source/destination channel/object/byte array.
     */

    Tcl_Channel channel;	/* Channel for from-file reads. */
    Tcl_Obj *objDataPtr;
    unsigned char *strDataBuf;	/* Raw source data for from-string reads. */
    Tcl_Size strDataLen;		/* Length of source data. */
    int strDataLen;		/* Length of source data. */
    unsigned char *base64Data;	/* base64 encoded string data. */
    unsigned char base64Bits;	/* Remaining bits from last base64 read. */
    unsigned char base64State;	/* Current state of base64 decoder. */
    double alpha;		/* Alpha from -format option. */

    /*
     * Image header information.
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
172
173
174
175
176
177
178









179
180
181
182
183
184
185







-
-
-
-
-
-
-
-
-








    Tcl_ZlibStream stream;	/* Inflating or deflating stream; this one is
				 * not bound to a Tcl command. */
    Tcl_Obj *lastLineObj;	/* Last line of pixels, for unfiltering. */
    Tcl_Obj *thisLineObj;	/* Current line of pixels to process. */
    int lineSize;		/* Number of bytes in a PNG line. */
    int phaseSize;		/* Number of bytes/line in current phase. */


    /*
     * Physical size: pHYS chunks.
     */

    double DPI;
    double aspect;

} PNGImage;

/*
 * Maximum size of various chunks.
 */

#define	PNG_PLTE_MAXSZ 768	/* 3 bytes/RGB entry, 256 entries max */
203
204
205
206
207
208
209
210

211
212
213
214



215
216
217
218
219


220
221
222
223

224
225
226
227
228
229
230

231
232
233

234
235
236

237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256


257
258

259
260

261
262
263
264
265
266
267
268
269
270

271
272

273
274
275

276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
195
196
197
198
199
200
201

202




203
204
205

206
207


208
209

210


211
212
213
214
215
216
217

218
219
220

221
222
223

224
225
226

227
228
229
230
231
232
233
234
235
236
237
238
239

240

241


242
243


244
245

246

247

248
249
250
251
252
253

254
255

256
257
258

259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278







-
+
-
-
-
-
+
+
+
-


-
-
+
+
-

-
-
+






-
+


-
+


-
+


-
+












-
+
-

-
-
+
+
-
-
+

-
+
-

-






-
+

-
+


-
+











-
+







			    unsigned long calculated);
static void		CleanupPNGImage(PNGImage *pngPtr);
static int		DecodeLine(Tcl_Interp *interp, PNGImage *pngPtr);
static int		DecodePNG(Tcl_Interp *interp, PNGImage *pngPtr,
			    Tcl_Obj *fmtObj, Tk_PhotoHandle imageHandle,
			    int destX, int destY);
static int		EncodePNG(Tcl_Interp *interp,
			    Tk_PhotoImageBlock *blockPtr, PNGImage *pngPtr,
			    Tk_PhotoImageBlock *blockPtr, PNGImage *pngPtr);
			    Tcl_Obj *metadataInObj);
static int		FileMatchPNG(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *fmtObj,
			    Tcl_Obj *metadataInObj, int *widthPtr,
static int		FileMatchPNG(Tcl_Channel chan, const char *fileName,
			    Tcl_Obj *fmtObj, int *widthPtr, int *heightPtr,
			    Tcl_Interp *interp);
			    int *heightPtr, Tcl_Obj *metadataOut);
static int		FileReadPNG(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *fmtObj,
			    Tcl_Obj *metadataInObj, Tk_PhotoHandle imageHandle,
			    int destX, int destY, int width, int height,
			    Tk_PhotoHandle imageHandle, int destX, int destY,
			    int width, int height, int srcX, int srcY);
			    int srcX, int srcY, Tcl_Obj *metadataOutPtr);
static int		FileWritePNG(Tcl_Interp *interp, const char *filename,
			    Tcl_Obj *fmtObj, Tcl_Obj *metadataInObj,
			    Tk_PhotoImageBlock *blockPtr);
			    Tcl_Obj *fmtObj, Tk_PhotoImageBlock *blockPtr);
static int		InitPNGImage(Tcl_Interp *interp, PNGImage *pngPtr,
			    Tcl_Channel chan, Tcl_Obj *objPtr, int dir);
static inline unsigned char Paeth(int a, int b, int c);
static int		ParseFormat(Tcl_Interp *interp, Tcl_Obj *fmtObj,
			    PNGImage *pngPtr);
static int		ReadBase64(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned char *destPtr, Tcl_Size destSz,
			    unsigned char *destPtr, int destSz,
			    unsigned long *crcPtr);
static int		ReadByteArray(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned char *destPtr, Tcl_Size destSz,
			    unsigned char *destPtr, int destSz,
			    unsigned long *crcPtr);
static int		ReadData(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned char *destPtr, Tcl_Size destSz,
			    unsigned char *destPtr, int destSz,
			    unsigned long *crcPtr);
static int		ReadChunkHeader(Tcl_Interp *interp, PNGImage *pngPtr,
			    Tcl_Size *sizePtr, unsigned long *typePtr,
			    int *sizePtr, unsigned long *typePtr,
			    unsigned long *crcPtr);
static int		ReadIDAT(Tcl_Interp *interp, PNGImage *pngPtr,
			    int chunkSz, unsigned long crc);
static int		ReadIHDR(Tcl_Interp *interp, PNGImage *pngPtr);
static inline int	ReadInt32(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned long *resultPtr, unsigned long *crcPtr);
static int		ReadPLTE(Tcl_Interp *interp, PNGImage *pngPtr,
			    int chunkSz, unsigned long crc);
static int		ReadTRNS(Tcl_Interp *interp, PNGImage *pngPtr,
			    int chunkSz, unsigned long crc);
static int		SkipChunk(Tcl_Interp *interp, PNGImage *pngPtr,
			    int chunkSz, unsigned long crc);
static int		StringMatchPNG(Tcl_Interp *interp, Tcl_Obj *pObjData,
static int		StringMatchPNG(Tcl_Obj *dataObj, Tcl_Obj *fmtObj,
			    Tcl_Obj *fmtObj, Tcl_Obj *metadataInObj,
			    int *widthPtr, int *heightPtr,
			    Tcl_Obj *metadataOutObj);
static int		StringReadPNG(Tcl_Interp *interp, Tcl_Obj *pObjData,
			    Tcl_Interp *interp);
static int		StringReadPNG(Tcl_Interp *interp, Tcl_Obj *dataObj,
			    Tcl_Obj *fmtObj, Tcl_Obj *metadataInObj,
			    Tk_PhotoHandle imageHandle,
			    Tcl_Obj *fmtObj, Tk_PhotoHandle imageHandle,
			    int destX, int destY, int width, int height,
			    int srcX, int srcY, Tcl_Obj *metadataOutObj);
			    int srcX, int srcY);

static int		StringWritePNG(Tcl_Interp *interp, Tcl_Obj *fmtObj,
			    Tcl_Obj *metadataInObj,
			    Tk_PhotoImageBlock *blockPtr);
static int		UnfilterLine(Tcl_Interp *interp, PNGImage *pngPtr);
static inline int	WriteByte(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned char c, unsigned long *crcPtr);
static inline int	WriteChunk(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned long chunkType,
			    const unsigned char *dataPtr, Tcl_Size dataSize);
			    const unsigned char *dataPtr, int dataSize);
static int		WriteData(Tcl_Interp *interp, PNGImage *pngPtr,
			    const unsigned char *srcPtr, Tcl_Size srcSz,
			    const unsigned char *srcPtr, int srcSz,
			    unsigned long *crcPtr);
static int		WriteExtraChunks(Tcl_Interp *interp,
			    PNGImage *pngPtr, Tcl_Obj *metadataInObj);
			    PNGImage *pngPtr);
static int		WriteIHDR(Tcl_Interp *interp, PNGImage *pngPtr,
			    Tk_PhotoImageBlock *blockPtr);
static int		WriteIDAT(Tcl_Interp *interp, PNGImage *pngPtr,
			    Tk_PhotoImageBlock *blockPtr);
static inline int	WriteInt32(Tcl_Interp *interp, PNGImage *pngPtr,
			    unsigned long l, unsigned long *crcPtr);

/*
 * The format record for the PNG file format:
 */

Tk_PhotoImageFormatVersion3 tkImgFmtPNG = {
Tk_PhotoImageFormat tkImgFmtPNG = {
    "png",			/* name */
    FileMatchPNG,		/* fileMatchProc */
    StringMatchPNG,		/* stringMatchProc */
    FileReadPNG,		/* fileReadProc */
    StringReadPNG,		/* stringReadProc */
    FileWritePNG,		/* fileWriteProc */
    StringWritePNG,		/* stringWriteProc */
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348







349
350
351
352
353
354
355







-
+








-
-
-
-
-
-
-







     * Initialize Zlib inflate/deflate stream.
     */

    if (Tcl_ZlibStreamInit(NULL, dir, TCL_ZLIB_FORMAT_ZLIB,
	    TCL_ZLIB_COMPRESS_DEFAULT, NULL, &pngPtr->stream) != TCL_OK) {
	if (interp) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "zlib initialization failed", TCL_INDEX_NONE));
		    "zlib initialization failed", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "ZLIB_INIT", NULL);
	}
	if (objPtr) {
	    Tcl_DecrRefCount(objPtr);
	}
	return TCL_ERROR;
    }

    /*
     * Initialize physical size pHYS values
     */

    pngPtr->DPI = -1;
    pngPtr->aspect = -1;

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * CleanupPNGImage --
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
427
428
429
430
431
432
433

434
435
436
437
438
439
440
441







-
+







 */

static int
ReadBase64(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned char *destPtr,
    Tcl_Size destSz,
    int destSz,
    unsigned long *crcPtr)
{
    static const unsigned char from64[] = {
	0x82, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x80, 0x80,
	0x83, 0x80, 0x80, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x80,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x3e,
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468







-
+







	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83,
	0x83, 0x83, 0x83
	0x83, 0x83
    };

    /*
     * Definitions for the base-64 decoder.
     */

#define PNG64_SPECIAL	0x80	/* Flag bit */
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
517
518
519
520
521
522
523

524
525
526
527
528
529
530
531







-
+







	if (c64 & PNG64_SPECIAL) {
	    break;
	}
    }

    if (destSz) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"unexpected end of image data", TCL_INDEX_NONE));
		"unexpected end of image data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EARLY_END", NULL);
	return TCL_ERROR;
    }

    return TCL_OK;
}

575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591

592
593
594
595
596
597

598
599
600
601
602
603
604
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566
567

568
569
570
571
572
573

574
575
576
577
578
579
580
581







-
+








-
+





-
+







 */

static int
ReadByteArray(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned char *destPtr,
    Tcl_Size destSz,
    int destSz,
    unsigned long *crcPtr)
{
    /*
     * Check to make sure the number of requested bytes are available.
     */

    if (pngPtr->strDataLen < destSz) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"unexpected end of image data", TCL_INDEX_NONE));
		"unexpected end of image data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EARLY_END", NULL);
	return TCL_ERROR;
    }

    while (destSz) {
	Tcl_Size blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);
	int blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);

	memcpy(destPtr, pngPtr->strDataBuf, blockSz);

	pngPtr->strDataBuf += blockSz;
	pngPtr->strDataLen -= blockSz;

	if (crcPtr) {
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648
649
650

651
652
653

654
655
656
657
658
659
660
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626

627
628
629

630
631
632
633
634
635
636
637







-
+









-
+


-
+







 */

static int
ReadData(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned char *destPtr,
    Tcl_Size destSz,
    int destSz,
    unsigned long *crcPtr)
{
    if (pngPtr->base64Data) {
	return ReadBase64(interp, pngPtr, destPtr, destSz, crcPtr);
    } else if (pngPtr->strDataBuf) {
	return ReadByteArray(interp, pngPtr, destPtr, destSz, crcPtr);
    }

    while (destSz) {
	Tcl_Size blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);
	int blockSz = PNG_MIN(destSz, PNG_BLOCK_SZ);

	blockSz = Tcl_Read(pngPtr->channel, (char *)destPtr, blockSz);
	if (blockSz == TCL_IO_FAILURE) {
	if (blockSz < 0) {
	    /* TODO: failure info... */
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "channel read failed: %s", Tcl_PosixError(interp)));
	    return TCL_ERROR;
	}

	/*
672
673
674
675
676
677
678
679

680
681
682
683
684
685
686
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663







-
+








	/*
	 * Check for EOF before all desired data was read.
	 */

	if (destSz && Tcl_Eof(pngPtr->channel)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "unexpected end of file", TCL_INDEX_NONE));
		    "unexpected end of file", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EOF", NULL);
	    return TCL_ERROR;
	}
    }

    return TCL_OK;
}
714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705







-
+







{
    unsigned char p[4];

    if (ReadData(interp, pngPtr, p, 4, crcPtr) == TCL_ERROR) {
	return TCL_ERROR;
    }

    *resultPtr = PNG_UINT32(p[0], p[1], p[2], p[3]);
    *resultPtr = PNG_INT32(p[0], p[1], p[2], p[3]);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749







-
+







    }

    /*
     * Compare the read CRC to what we calculate to make sure they match.
     */

    if (calculated != chunked) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("CRC check failed", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("CRC check failed", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "CRC", NULL);
	return TCL_ERROR;
    }

    return TCL_OK;
}

878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
855
856
857
858
859
860
861

862
863
864
865
866
867
868
869







-
+







 *----------------------------------------------------------------------
 */

static int
ReadChunkHeader(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    Tcl_Size *sizePtr,
    int *sizePtr,
    unsigned long *typePtr,
    unsigned long *crcPtr)
{
    unsigned long chunkType = 0;
    int chunkSz = 0;
    unsigned long crc = 0;

906
907
908
909
910
911
912
913

914
915
916
917
918
919
920
883
884
885
886
887
888
889

890
891
892
893
894
895
896
897







-
+







	 * maximum size for Tcl_Read, Tcl_GetByteArrayFromObj, etc.
	 */

	if (ReadData(interp, pngPtr, pc, 4, NULL) == TCL_ERROR) {
	    return TCL_ERROR;
	}

	temp = PNG_UINT32(pc[0], pc[1], pc[2], pc[3]);
	temp = PNG_INT32(pc[0], pc[1], pc[2], pc[3]);

	if (temp > INT_MAX) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "chunk size is out of supported range on this architecture",
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "OUTSIZE", NULL);
	    return TCL_ERROR;
931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
908
909
910
911
912
913
914

915
916
917
918
919
920
921
922







-
+







	    return TCL_ERROR;
	}

	/*
	 * Convert it to a host-order integer for simple comparison.
	 */

	chunkType = PNG_UINT32(pc[0], pc[1], pc[2], pc[3]);
	chunkType = PNG_INT32(pc[0], pc[1], pc[2], pc[3]);

	/*
	 * Check to see if this is a known/supported chunk type. Note that the
	 * PNG specs require non-critical (i.e., ancillary) chunk types that
	 * are not recognized to be ignored, rather than be treated as an
	 * error. It does, however, recommend that an unknown critical chunk
	 * type be treated as a failure.
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
930
931
932
933
934
935
936

937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962







-


















+







	    /*
	     * These chunk types are required and/or supported.
	     */

	case CHUNK_IDAT:
	case CHUNK_IEND:
	case CHUNK_IHDR:
	case CHUNK_pHYs:
	case CHUNK_PLTE:
	case CHUNK_tRNS:
	    break;

	    /*
	     * These chunk types are part of the standard, but are not used by
	     * this implementation (at least not yet). Note that these are all
	     * ancillary chunks (lowercase first letter).
	     */

	case CHUNK_bKGD:
	case CHUNK_cHRM:
	case CHUNK_gAMA:
	case CHUNK_hIST:
	case CHUNK_iCCP:
	case CHUNK_iTXt:
	case CHUNK_oFFs:
	case CHUNK_pCAL:
	case CHUNK_pHYs:
	case CHUNK_sBIT:
	case CHUNK_sCAL:
	case CHUNK_sPLT:
	case CHUNK_sRGB:
	case CHUNK_tEXt:
	case CHUNK_tIME:
	case CHUNK_zTXt:
996
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
973
974
975
976
977
978
979

980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1021







-
+






-
+










-
+















-
+








	default:
	    /*
	     * Unknown chunk type. If it's critical, we can't continue.
	     */

	    if (!(chunkType & PNG_CF_ANCILLARY)) {
		if (chunkType & PNG_UINT32(128,128,128,128)) {
		if (chunkType & PNG_INT32(128,128,128,128)) {
		    /*
		     * No nice ASCII conversion; shouldn't happen either, but
		     * we'll be doubly careful.
		     */

		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "encountered an unsupported critical chunk type",
			    "encountered an unsupported criticial chunk type",
			    -1));
		} else {
		    char typeString[5];

		    typeString[0] = (char) ((chunkType >> 24) & 255);
		    typeString[1] = (char) ((chunkType >> 16) & 255);
		    typeString[2] = (char) ((chunkType >> 8) & 255);
		    typeString[3] = (char) (chunkType & 255);
		    typeString[4] = '\0';
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "encountered an unsupported critical chunk type"
			    "encountered an unsupported criticial chunk type"
			    " \"%s\"", typeString));
		}
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG",
			"UNSUPPORTED_CRITICAL", NULL);
		return TCL_ERROR;
	    }

	    /*
	     * Check to see if the chunk type has legal bytes.
	     */

	    for (i=0 ; i<4 ; i++) {
		if ((pc[i] < 65) || (pc[i] > 122) ||
			((pc[i] > 90) && (pc[i] < 97))) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "invalid chunk type", TCL_INDEX_NONE));
			    "invalid chunk type", -1));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG",
			    "INVALID_CHUNK", NULL);
		    return TCL_ERROR;
		}
	    }

	    /*
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1108
1109
1110
1111
1112
1113
1114

1115
1116
1117
1118
1119
1120
1121
1122







-
+







	break;

    case PNG_COLOR_RGBA:
	pngPtr->numChannels = 4;
	if ((8 != pngPtr->bitDepth) && (16 != pngPtr->bitDepth)) {
	unsupportedDepth:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "bit depth is not allowed for given color type", TCL_INDEX_NONE));
		    "bit depth is not allowed for given color type", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_DEPTH", NULL);
	    return TCL_ERROR;
	}
	break;

    default:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
1259
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250







-
+







static int
ReadIHDR(
    Tcl_Interp *interp,
    PNGImage *pngPtr)
{
    unsigned char sigBuf[PNG_SIG_SZ];
    unsigned long chunkType;
    Tcl_Size chunkSz;
    int chunkSz;
    unsigned long crc;
    unsigned long width, height;
    int mismatch;

    /*
     * Read the appropriate number of bytes for the PNG signature.
     */
1296
1297
1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297

1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308
1309
1310
1311
1312







-
+

















-
+






-
+







	}

	mismatch = memcmp(sigBuf, pngSignature, PNG_SIG_SZ);
    }

    if (mismatch) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"data stream does not have a PNG signature", TCL_INDEX_NONE));
		"data stream does not have a PNG signature", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "NO_SIG", NULL);
	return TCL_ERROR;
    }

    if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
	    &crc) == TCL_ERROR) {
	return TCL_ERROR;
    }

    /*
     * Read in the IHDR (header) chunk for width, height, etc.
     *
     * The first chunk in the file must be the IHDR (headr) chunk.
     */

    if (chunkType != CHUNK_IHDR) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"expected IHDR chunk type", TCL_INDEX_NONE));
		"expected IHDR chunk type", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "NO_IHDR", NULL);
	return TCL_ERROR;
    }

    if (chunkSz != 13) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"invalid IHDR chunk size", TCL_INDEX_NONE));
		"invalid IHDR chunk size", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_IHDR", NULL);
	return TCL_ERROR;
    }

    /*
     * Read and verify the image width and height to be sure Tk can handle its
     * dimensions. The PNG specification does not permit zero-width or
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489

1490
1491
1492
1493
1494
1495
1496
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465

1466
1467
1468
1469
1470
1471
1472
1473







-
+
















-
+







     * This chunk is mandatory for color type 3 and forbidden for 2 and 6.
     */

    switch (pngPtr->colorType) {
    case PNG_COLOR_GRAY:
    case PNG_COLOR_GRAYALPHA:
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"PLTE chunk type forbidden for grayscale", TCL_INDEX_NONE));
		"PLTE chunk type forbidden for grayscale", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "PLTE_UNEXPECTED",
		NULL);
	return TCL_ERROR;

    default:
	break;
    }

    /*
     * The palette chunk contains from 1 to 256 palette entries. Each entry
     * consists of a 3-byte RGB value. It must therefore contain a non-zero
     * multiple of 3 bytes, up to 768.
     */

    if (!chunkSz || (chunkSz > PNG_PLTE_MAXSZ) || (chunkSz % 3)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"invalid palette chunk size", TCL_INDEX_NONE));
		"invalid palette chunk size", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_PLTE", NULL);
	return TCL_ERROR;
    }

    /*
     * Read the palette contents and stash them for later, possibly.
     */
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550







-
+







    /*
     * For indexed color, there is up to one single-byte transparency value
     * per palette entry (thus a max of 256).
     */

    if (chunkSz > PNG_TRNS_MAXSZ) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"invalid tRNS chunk size", TCL_INDEX_NONE));
		"invalid tRNS chunk size", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_TRNS", NULL);
	return TCL_ERROR;
    }

    /*
     * Read in the raw transparency information.
     */
1590
1591
1592
1593
1594
1595
1596
1597

1598
1599
1600
1601
1602
1603
1604
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581







-
+







	 * The number of tRNS entries must be less than or equal to the number
	 * of PLTE entries, and consists of a single-byte alpha level for the
	 * corresponding PLTE entry.
	 */

	if (chunkSz > pngPtr->paletteLen) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "size of tRNS chunk is too large for the palette", TCL_INDEX_NONE));
		    "size of tRNS chunk is too large for the palette", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "TRNS_SIZE", NULL);
	    return TCL_ERROR;
	}

	for (i=0 ; i<chunkSz ; i++) {
	    pngPtr->palette[i].alpha = buffer[i];
	}
1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623
1624
1625
1626







-
+







    case PNG_COLOR_RGB:
	/*
	 * TrueColor uses a single RRGGBB triplet.
	 */

	if (chunkSz != 6) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "invalid tRNS chunk size - must 6 bytes for RGB", TCL_INDEX_NONE));
		    "invalid tRNS chunk size - must 6 bytes for RGB", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_TRNS", NULL);
	    return TCL_ERROR;
	}

	/*
	 * According to the PNG specs, if the bit depth is less than 16, then
	 * only the lower byte is used. But the tRNS chunk still contains two
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
1637
1638
1639
1640
1641
1642
1643














































































1644
1645
1646
1647
1648
1649
1650







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	pngPtr->useTRNS = 1;
	break;
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ReadPHYS --
 *
 *	This function reads the PHYS (physical size) chunk data from
 *	the PNG file and populates the fields in the PNGImage
 *	structure.
 *
 * Results:
 *	TCL_OK, or TCL_ERROR if an I/O error occurs or the PHYS chunk is
 *	invalid.
 *
 * Side effects:
 *	The access position in f advances.
 *
 *----------------------------------------------------------------------
 */

static int
ReadPHYS(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    int chunkSz,
    unsigned long crc)
{
    unsigned long PPUx, PPUy;
    char unitSpecifier;

    /*
     * Check chunk size equal 9 bytes
     */

    if (chunkSz != 9) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"invalid physical chunk size", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_PHYS", NULL);
	return TCL_ERROR;
    }

    /*
     * Read the chunk data
     * 4 bytes: Pixels per unit, x axis
     * 4 bytes: Pixels per unit, y axis
     * 1 byte: unit specifier
     */

    if (ReadInt32(interp, pngPtr, &PPUx, &crc) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (ReadInt32(interp, pngPtr, &PPUy, &crc) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (ReadData(interp, pngPtr, (unsigned char *)&unitSpecifier, 1, &crc) == TCL_ERROR) {
	return TCL_ERROR;
    }

    if (CheckCRC(interp, pngPtr, crc) == TCL_ERROR) {
	return TCL_ERROR;
    }

    if ( PPUx > 2147483647 || PPUy > 2147483647
	    || unitSpecifier > 1 ) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"invalid physical size value", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_PHYS", NULL);
	return TCL_ERROR;
    }

    if (PPUx > 0) {
	pngPtr->aspect = ((double) PPUy) / ((double) PPUx);
    }
    if (1 == unitSpecifier) {
	pngPtr->DPI = ((double) PPUx) * 0.0254;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Paeth --
 *
 *	Utility function for applying the Paeth filter to a pixel. The Paeth
 *	filter is a linear function of the pixel to be filtered and the pixels
1806
1807
1808
1809
1810
1811
1812
1813

1814
1815

1816
1817
1818
1819
1820
1821
1822
1705
1706
1707
1708
1709
1710
1711

1712
1713

1714
1715
1716
1717
1718
1719
1720
1721







-
+

-
+








static int
UnfilterLine(
    Tcl_Interp *interp,
    PNGImage *pngPtr)
{
    unsigned char *thisLine =
	    Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, (Tcl_Size *)NULL);
	    Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, NULL);
    unsigned char *lastLine =
	    Tcl_GetByteArrayFromObj(pngPtr->lastLineObj, (Tcl_Size *)NULL);
	    Tcl_GetByteArrayFromObj(pngPtr->lastLineObj, NULL);

#define	PNG_FILTER_NONE		0
#define	PNG_FILTER_SUB		1
#define	PNG_FILTER_UP		2
#define	PNG_FILTER_AVG		3
#define	PNG_FILTER_PAETH	4

1938
1939
1940
1941
1942
1943
1944
1945

1946
1947
1948
1949
1950
1951
1952
1837
1838
1839
1840
1841
1842
1843

1844
1845
1846
1847
1848
1849
1850
1851







-
+







    int haveBits = 0;		/* Number of bits remaining in current byte */
    unsigned char pixBits = 0;	/* Extracted bits for current channel */
    int shifts = 0;		/* Number of channels extracted from byte */
    int offset = 0;		/* Current offset into pixelPtr */
    int colStep = 1;		/* Column increment each pass */
    int pixStep = 0;		/* extra pixelPtr increment each pass */
    unsigned char lastPixel[6];
    unsigned char *p = Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, (Tcl_Size *)NULL);
    unsigned char *p = Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, NULL);

    p++;
    if (UnfilterLine(interp, pngPtr) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (pngPtr->currentLine >= pngPtr->block.height) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
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
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







-
+
















-
+







    unsigned long crc)
{
    /*
     * Process IDAT contents until there is no more in this chunk.
     */

    while (chunkSz && !Tcl_ZlibStreamEof(pngPtr->stream)) {
	Tcl_Size len1, len2;
	int len1, len2;

	/*
	 * Read another block of input into the zlib stream if data remains.
	 */

	if (chunkSz) {
	    Tcl_Obj *inputObj = NULL;
	    int blockSz = PNG_MIN(chunkSz, PNG_BLOCK_SZ);
	    unsigned char *inputPtr = NULL;

	    /*
	     * Check for end of zlib stream.
	     */

	    if (Tcl_ZlibStreamEof(pngPtr->stream)) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"extra data after end of zlib stream", TCL_INDEX_NONE));
			"extra data after end of zlib stream", -1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EXTRA_DATA",
			NULL);
		return TCL_ERROR;
	    }

	    inputObj = Tcl_NewObj();
	    Tcl_IncrRefCount(inputObj);
2251
2252
2253
2254
2255
2256
2257
2258

2259
2260
2261
2262
2263
2264
2265
2150
2151
2152
2153
2154
2155
2156

2157
2158
2159
2160
2161
2162
2163
2164







-
+







	Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, &len1);
	if (Tcl_ZlibStreamGet(pngPtr->stream, pngPtr->thisLineObj,
		pngPtr->phaseSize - len1) == TCL_ERROR) {
	    return TCL_ERROR;
	}
	Tcl_GetByteArrayFromObj(pngPtr->thisLineObj, &len2);

	if (len2 == (Tcl_Size)pngPtr->phaseSize) {
	if (len2 == pngPtr->phaseSize) {
	    if (pngPtr->phase > 7) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"extra data after final scan line of final phase",
			-1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EXTRA_DATA",
			NULL);
		return TCL_ERROR;
2304
2305
2306
2307
2308
2309
2310
2311

2312
2313
2314
2315
2316
2317
2318
2203
2204
2205
2206
2207
2208
2209

2210
2211
2212
2213
2214
2215
2216
2217







-
+







     * Ensure that if we've got to the end of the compressed data, we've
     * also got to the end of the compressed stream. This sanity check is
     * enforced by most PNG readers.
     */

    if (chunkSz != 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"compressed data after stream finalize in PNG data", TCL_INDEX_NONE));
		"compressed data after stream finalize in PNG data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EXTRA_DATA", NULL);
	return TCL_ERROR;
    }

    return CheckCRC(interp, pngPtr, crc);
}

2335
2336
2337
2338
2339
2340
2341
2342

2343
2344
2345
2346
2347
2348
2349

2350
2351
2352
2353
2354
2355
2356
2234
2235
2236
2237
2238
2239
2240

2241
2242
2243
2244
2245
2246
2247

2248
2249
2250
2251
2252
2253
2254
2255







-
+






-
+







 */

static void
ApplyAlpha(
    PNGImage *pngPtr)
{
    if (pngPtr->alpha != 1.0) {
	unsigned char *p = pngPtr->block.pixelPtr;
	register unsigned char *p = pngPtr->block.pixelPtr;
	unsigned char *endPtr = p + pngPtr->blockLen;
	int offset = pngPtr->block.offset[3];

	p += offset;

	if (16 == pngPtr->bitDepth) {
	    unsigned int channel;
	    register unsigned int channel;

	    while (p < endPtr) {
		channel = (unsigned int)
			(((p[0] << 8) | p[1]) * pngPtr->alpha);

		*p++ = (unsigned char) (channel >> 8);
		*p++ = (unsigned char) (channel & 0xff);
2389
2390
2391
2392
2393
2394
2395
2396

2397
2398
2399
2400

2401
2402
2403
2404
2405
2406
2407
2288
2289
2290
2291
2292
2293
2294

2295
2296
2297
2298

2299
2300
2301
2302
2303
2304
2305
2306







-
+



-
+







static int
ParseFormat(
    Tcl_Interp *interp,
    Tcl_Obj *fmtObj,
    PNGImage *pngPtr)
{
    Tcl_Obj **objv = NULL;
    Tcl_Size objc = 0;
    int objc = 0;
    static const char *const fmtOptions[] = {
	"-alpha", NULL
    };
    enum fmtOptionsEnum {
    enum fmtOptions {
	OPT_ALPHA
    };

    /*
     * Extract elements of format specification as a list.
     */

2430
2431
2432
2433
2434
2435
2436
2437

2438
2439
2440
2441
2442
2443
2444
2445
2446

2447
2448
2449
2450
2451
2452
2453
2329
2330
2331
2332
2333
2334
2335

2336
2337
2338
2339
2340
2341
2342
2343
2344

2345
2346
2347
2348
2349
2350
2351
2352







-
+








-
+







	    Tcl_WrongNumArgs(interp, 1, objv, "value");
	    return TCL_ERROR;
	}

	objc--;
	objv++;

	switch ((enum fmtOptionsEnum) optIndex) {
	switch ((enum fmtOptions) optIndex) {
	case OPT_ALPHA:
	    if (Tcl_GetDoubleFromObj(interp, objv[0],
		    &pngPtr->alpha) == TCL_ERROR) {
		return TCL_ERROR;
	    }

	    if ((pngPtr->alpha < 0.0) || (pngPtr->alpha > 1.0)) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"-alpha value must be between 0.0 and 1.0", TCL_INDEX_NONE));
			"-alpha value must be between 0.0 and 1.0", -1));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_ALPHA",
			NULL);
		return TCL_ERROR;
	    }
	    break;
	}
    }
2480
2481
2482
2483
2484
2485
2486
2487

2488
2489
2490
2491
2492
2493
2494
2379
2380
2381
2382
2383
2384
2385

2386
2387
2388
2389
2390
2391
2392
2393







-
+







    PNGImage *pngPtr,
    Tcl_Obj *fmtObj,
    Tk_PhotoHandle imageHandle,
    int destX,
    int destY)
{
    unsigned long chunkType;
    Tcl_Size chunkSz;
    int chunkSz;
    unsigned long crc;

    /*
     * Parse the PNG signature and IHDR (header) chunk.
     */

    if (ReadIHDR(interp, pngPtr) == TCL_ERROR) {
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
+







     */

    if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
	    &crc) == TCL_ERROR) {
	return TCL_ERROR;
    }

    /*
     * Physical header may be present here so try to parse it
     */

    if (CHUNK_pHYs == chunkType) {
	/*
	 * Finish parsing the PHYS chunk.
	 */

	if (ReadPHYS(interp, pngPtr, chunkSz, crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}

	/*
	 * Begin the next chunk.
	 */

	if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
		&crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    }

    if (CHUNK_PLTE == chunkType) {
	/*
	 * Finish parsing the PLTE chunk.
	 */

	if (ReadPLTE(interp, pngPtr, chunkSz, crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}

	/*
	 * Begin the next chunk.
	 */

	if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
		&crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    } else if (PNG_COLOR_PLTE == pngPtr->colorType) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"PLTE chunk required for indexed color", TCL_INDEX_NONE));
		"PLTE chunk required for indexed color", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "NEED_PLTE", NULL);
	return TCL_ERROR;
    }

    /*
     * The next chunk may be a tRNS (palette transparency) chunk, depending on
     * the color type. It must come after the PLTE chunk and before the IDAT
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
2462
2463
2464
2465
2466
2467
2468























2469
2470
2471
2472
2473
2474
2475

2476
2477
2478
2479
2480
2481
2482
2483







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+








	if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
		&crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    }

    /*
     * Physical header may be present here so try to parse it
     */

    if (CHUNK_pHYs == chunkType) {
	/*
	 * Finish parsing the PHYS chunk.
	 */

	if (ReadPHYS(interp, pngPtr, chunkSz, crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}

	/*
	 * Begin the next chunk.
	 */

	if (ReadChunkHeader(interp, pngPtr, &chunkSz, &chunkType,
		&crc) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    }

    /*
     * Other ancillary chunk types could appear here, but for now we're only
     * interested in IDAT. The others should have been skipped.
     */

    if (chunkType != CHUNK_IDAT) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"at least one IDAT chunk is required", TCL_INDEX_NONE));
		"at least one IDAT chunk is required", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "NEED_IDAT", NULL);
	return TCL_ERROR;
    }

    /*
     * Expand the photo size (if not set by the user) to provide enough space
     * for the image being parsed. It does not matter if width or height wrap
2664
2665
2666
2667
2668
2669
2670
2671

2672
2673
2674

2675
2676
2677
2678
2679
2680
2681
2517
2518
2519
2520
2521
2522
2523

2524
2525
2526

2527
2528
2529
2530
2531
2532
2533
2534







-
+


-
+







     */

    pngPtr->lastLineObj = Tcl_NewObj();
    Tcl_IncrRefCount(pngPtr->lastLineObj);
    pngPtr->thisLineObj = Tcl_NewObj();
    Tcl_IncrRefCount(pngPtr->thisLineObj);

    pngPtr->block.pixelPtr = (unsigned char *)attemptckalloc(pngPtr->blockLen);
    pngPtr->block.pixelPtr = attemptckalloc(pngPtr->blockLen);
    if (!pngPtr->block.pixelPtr) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"memory allocation failed", TCL_INDEX_NONE));
		"memory allocation failed", -1));
	Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	return TCL_ERROR;
    }

    /*
     * Determine size of the first phase if interlaced. Phase size should
     * always be <= line size, so probably not necessary to check for
2719
2720
2721
2722
2723
2724
2725
2726

2727
2728
2729
2730
2731
2732
2733
2572
2573
2574
2575
2576
2577
2578

2579
2580
2581
2582
2583
2584
2585
2586







-
+







     * Ensure that we've got to the end of the compressed stream now that
     * there are no more IDAT segments. This sanity check is enforced by most
     * PNG readers.
     */

    if (!Tcl_ZlibStreamEof(pngPtr->stream)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"unfinalized data stream in PNG data", TCL_INDEX_NONE));
		"unfinalized data stream in PNG data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "EXTRA_DATA", NULL);
	return TCL_ERROR;
    }

    /*
     * Now skip the remaining chunks which we're also not interested in.
     */
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
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







-
+




















-
+








    /*
     * Got the IEND (end of image) chunk. Do some final checks...
     */

    if (chunkSz) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"IEND chunk contents must be empty", TCL_INDEX_NONE));
		"IEND chunk contents must be empty", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_IEND", NULL);
	return TCL_ERROR;
    }

    /*
     * Check the CRC on the IEND chunk.
     */

    if (CheckCRC(interp, pngPtr, crc) == TCL_ERROR) {
	return TCL_ERROR;
    }

    /*
     * TODO: verify that nothing else comes after the IEND chunk, or do we
     * really care?
     */

#if 0
    if (ReadData(interp, pngPtr, &c, 1, NULL) != TCL_ERROR) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"extra data following IEND chunk", TCL_INDEX_NONE));
		"extra data following IEND chunk", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "BAD_IEND", NULL);
	return TCL_ERROR;
    }
#endif

    /*
     * Apply overall image alpha if specified.
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820


2821
2822
2823


2824
2825
2826


2827
2828
2829
2830
2831
2832
2833
2664
2665
2666
2667
2668
2669
2670



2671
2672



2673
2674



2675
2676
2677
2678
2679
2680
2681
2682
2683







-
-
-
+
+
-
-
-
+
+
-
-
-
+
+







 *	The access position in f may change.
 *
 *----------------------------------------------------------------------
 */

static int
FileMatchPNG(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Channel chan,		/* The image file, open for reading. */
    TCL_UNUSED(const char *),	/* The name of the image file. */
    Tcl_Channel chan,
    const char *fileName,
    TCL_UNUSED(Tcl_Obj *),	/* User-specified format object, or NULL. */
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    int *widthPtr, int *heightPtr,
    Tcl_Obj *fmtObj,
    int *widthPtr,
				/* The dimensions of the image are returned
				 * here if the file is a valid raw GIF file. */
    TCL_UNUSED(Tcl_Obj *))	/* metadata return dict, may be NULL */
    int *heightPtr,
    Tcl_Interp *interp)
{
    PNGImage png;
    int match = 0;

    InitPNGImage(NULL, &png, chan, NULL, TCL_ZLIB_STREAM_INFLATE);

    if (ReadIHDR(interp, &png) == TCL_OK) {
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
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







-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
+
+
-










-
-
-
-
-
-
-
-
-
-
-
-







 *	image given by imageHandle.
 *
 *----------------------------------------------------------------------
 */

static int
FileReadPNG(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Channel chan,		/* The image file, open for reading. */
    TCL_UNUSED(const char *),	/* The name of the image file. */
    Tcl_Obj *fmtObj,		/* User-specified format object, or NULL. */
    Tcl_Interp *interp,
    Tcl_Channel chan,
    const char *fileName,
    Tcl_Obj *fmtObj,
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    Tk_PhotoHandle imageHandle,	/* The photo image to write into. */
    int destX, int destY,	/* Coordinates of top-left pixel in photo
    Tk_PhotoHandle imageHandle,
    int destX,
				 * image to be written to. */
    TCL_UNUSED(int),		/* Dimensions of block of photo image to be
				 * written to. */
    TCL_UNUSED(int),
    int destY,
    int width,
    int height,
    TCL_UNUSED(int),		/* Coordinates of top-left pixel to be used in
				 * image being read. */
    TCL_UNUSED(int),
    int srcX,
    int srcY)
    Tcl_Obj *metadataOutObj)	/* metadata return dict, may be NULL */
{
    PNGImage png;
    int result = TCL_ERROR;

    result = InitPNGImage(interp, &png, chan, NULL, TCL_ZLIB_STREAM_INFLATE);

    if (TCL_OK == result) {
	result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
    }

    if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
	result = Tcl_DictObjPut(NULL, metadataOutObj,
		Tcl_NewStringObj("DPI",-1),
		Tcl_NewDoubleObj(png.DPI));
    }

    if (TCL_OK == result && metadataOutObj != NULL && png.aspect != -1) {
	result = Tcl_DictObjPut(NULL, metadataOutObj,
		Tcl_NewStringObj("aspect",-1),
		Tcl_NewDoubleObj(png.aspect));
    }

    CleanupPNGImage(&png);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
2919
2920
2921
2922
2923
2924
2925
2926
2927

2928
2929
2930
2931
2932




2933
2934
2935
2936
2937
2938
2939
2753
2754
2755
2756
2757
2758
2759


2760





2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771







-
-
+
-
-
-
-
-
+
+
+
+







 *	The size of the image is placed in widthPre and heightPtr.
 *
 *----------------------------------------------------------------------
 */

static int
StringMatchPNG(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Obj *pObjData,		/* the object containing the image data */
    Tcl_Obj *pObjData,
    TCL_UNUSED(Tcl_Obj *),	/* the image format object, or NULL */
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    int *widthPtr,		/* where to put the string width */
    int *heightPtr,		/* where to put the string height */
    TCL_UNUSED(Tcl_Obj *))	/* metadata return dict, may be NULL */
    Tcl_Obj *fmtObj,
    int *widthPtr,
    int *heightPtr,
    Tcl_Interp *interp)
{
    PNGImage png;
    int match = 0;

    InitPNGImage(NULL, &png, NULL, pObjData, TCL_ZLIB_STREAM_INFLATE);

    png.strDataBuf = Tcl_GetByteArrayFromObj(pObjData, &png.strDataLen);
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
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







-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-











-
-
-
-
-
-
-
-
-
-
-
-







 *	New data is added to the image given by imageHandle.
 *
 *----------------------------------------------------------------------
 */

static int
StringReadPNG(
    Tcl_Interp *interp,		/* interpreter for reporting errors in */
    Tcl_Obj *pObjData,		/* object containing the image */
    Tcl_Obj *fmtObj,		/* format object, or NULL */
    Tcl_Interp *interp,
    Tcl_Obj *pObjData,
    Tcl_Obj *fmtObj,
    TCL_UNUSED(Tcl_Obj *),	/* metadata input, may be NULL */
    Tk_PhotoHandle imageHandle,	/* the image to write this data into */
    int destX, int destY,	/* The rectangular region of the */
    TCL_UNUSED(int),		/* image to copy */
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    Tk_PhotoHandle imageHandle,
    int destX,
    int destY,
    int width,
    int height,
    int srcX,
    int srcY)
    Tcl_Obj *metadataOutObj)	/* metadata return dict, may be NULL */
{
    PNGImage png;
    int result = TCL_ERROR;

    result = InitPNGImage(interp, &png, NULL, pObjData,
	    TCL_ZLIB_STREAM_INFLATE);

    if (TCL_OK == result) {
	result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
    }

    if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
	result = Tcl_DictObjPut(NULL, metadataOutObj,
		Tcl_NewStringObj("DPI",-1),
		Tcl_NewDoubleObj(png.DPI));
    }

    if (TCL_OK == result && metadataOutObj != NULL && png.aspect != -1) {
	result = Tcl_DictObjPut(NULL, metadataOutObj,
		Tcl_NewStringObj("aspect",-1),
		Tcl_NewDoubleObj(png.aspect));
    }

    CleanupPNGImage(&png);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+


-
+













-
+




-
+

-
+








-
+





-
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 */

static int
WriteData(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    const unsigned char *srcPtr,
    Tcl_Size srcSz,
    int srcSz,
    unsigned long *crcPtr)
{
    if (!srcPtr || srcSz <= 0) {
    if (!srcPtr || !srcSz) {
	return TCL_OK;
    }

    if (crcPtr) {
	*crcPtr = Tcl_ZlibCRC32(*crcPtr, srcPtr, srcSz);
    }

    /*
     * TODO: is Tcl_AppendObjToObj faster here? i.e., does Tcl join the
     * objects immediately or store them in a multi-object rep?
     */

    if (pngPtr->objDataPtr) {
	Tcl_Size objSz;
	int objSz;
	unsigned char *destPtr;

	Tcl_GetByteArrayFromObj(pngPtr->objDataPtr, &objSz);

	if (objSz + srcSz > INT_MAX) {
	if (objSz > INT_MAX - srcSz) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "image too large to store completely in byte array", TCL_INDEX_NONE));
		    "image too large to store completely in byte array", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "TOO_LARGE", NULL);
	    return TCL_ERROR;
	}

	destPtr = Tcl_SetByteArrayLength(pngPtr->objDataPtr, objSz + srcSz);

	if (!destPtr) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "memory allocation failed", TCL_INDEX_NONE));
		    "memory allocation failed", -1));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    return TCL_ERROR;
	}

	memcpy(destPtr+objSz, srcPtr, srcSz);
    } else if (Tcl_Write(pngPtr->channel, (const char *) srcPtr, srcSz) == TCL_IO_FAILURE) {
    } else if (Tcl_Write(pngPtr->channel, (const char *) srcPtr, srcSz) < 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"write to channel failed: %s", Tcl_PosixError(interp)));
	return TCL_ERROR;
    }

    return TCL_OK;
}

static inline int
WriteByte(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned char c,
    unsigned long *crcPtr)
{
    return WriteData(interp, pngPtr, &c, 1, crcPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * LongToInt32 --
 *
 *	This function transforms to a 32-bit integer value as
 *	four bytes in network byte order.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	Buffer will be modified.
 *
 *----------------------------------------------------------------------
 */

static inline void
LongToInt32(
    unsigned long l,
    unsigned char *pc)
{
    pc[0] = (unsigned char) ((l & 0xff000000) >> 24);
    pc[1] = (unsigned char) ((l & 0x00ff0000) >> 16);
    pc[2] = (unsigned char) ((l & 0x0000ff00) >> 8);
    pc[3] = (unsigned char) ((l & 0x000000ff) >> 0);
}

/*
 *----------------------------------------------------------------------
 *
 * WriteInt32 --
 *
 *	This function writes a 32-bit integer value out to the PNG image as
3134
3135
3136
3137
3138
3139
3140
3141






3142
3143
3144
3145
3146
3147
3148
2925
2926
2927
2928
2929
2930
2931

2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944







-
+
+
+
+
+
+







WriteInt32(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned long l,
    unsigned long *crcPtr)
{
    unsigned char pc[4];
    LongToInt32(l,pc);

    pc[0] = (unsigned char) ((l & 0xff000000) >> 24);
    pc[1] = (unsigned char) ((l & 0x00ff0000) >> 16);
    pc[2] = (unsigned char) ((l & 0x0000ff00) >> 8);
    pc[3] = (unsigned char) ((l & 0x000000ff) >> 0);

    return WriteData(interp, pngPtr, pc, 4, crcPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * WriteChunk --
3161
3162
3163
3164
3165
3166
3167
3168

3169
3170
3171
3172
3173
3174
3175
2957
2958
2959
2960
2961
2962
2963

2964
2965
2966
2967
2968
2969
2970
2971







-
+








static inline int
WriteChunk(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    unsigned long chunkType,
    const unsigned char *dataPtr,
    Tcl_Size dataSize)
    int dataSize)
{
    unsigned long crc = Tcl_ZlibCRC32(0, NULL, 0);
    int result = TCL_OK;

    /*
     * Write the length field for the chunk.
     */
3332
3333
3334
3335
3336
3337
3338
3339

3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3128
3129
3130
3131
3132
3133
3134

3135
3136
3137

3138
3139
3140
3141
3142
3143
3144







-
+


-








static int
WriteIDAT(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    Tk_PhotoImageBlock *blockPtr)
{
    int rowNum, flush = TCL_ZLIB_NO_FLUSH, result;
    int rowNum, flush = TCL_ZLIB_NO_FLUSH, outputSize, result;
    Tcl_Obj *outputObj;
    unsigned char *outputBytes;
    Tcl_Size outputSize;

    /*
     * Filter and compress each row one at a time.
     */

    for (rowNum=0 ; rowNum < blockPtr->height ; rowNum++) {
	int colNum;
3404
3405
3406
3407
3408
3409
3410
3411

3412
3413
3414
3415
3416
3417
3418
3199
3200
3201
3202
3203
3204
3205

3206
3207
3208
3209
3210
3211
3212
3213







-
+








	if (rowNum + 1 == blockPtr->height) {
	    flush = TCL_ZLIB_FINALIZE;
	}
	if (Tcl_ZlibStreamPut(pngPtr->stream, pngPtr->thisLineObj,
		flush) != TCL_OK) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "deflate() returned error", TCL_INDEX_NONE));
		    "deflate() returned error", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "DEFLATE", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Swap line buffers to keep the last around for filtering next.
	 */
3426
3427
3428
3429
3430
3431
3432
3433

3434
3435
3436
3437
3438
3439
3440
3221
3222
3223
3224
3225
3226
3227

3228
3229
3230
3231
3232
3233
3234
3235







-
+







    }

    /*
     * Now get the compressed data and write it as one big IDAT chunk.
     */

    outputObj = Tcl_NewObj();
    (void) Tcl_ZlibStreamGet(pngPtr->stream, outputObj, TCL_INDEX_NONE);
    (void) Tcl_ZlibStreamGet(pngPtr->stream, outputObj, -1);
    outputBytes = Tcl_GetByteArrayFromObj(outputObj, &outputSize);
    result = WriteChunk(interp, pngPtr, CHUNK_IDAT, outputBytes, outputSize);
    Tcl_DecrRefCount(outputObj);
    return result;
}

/*
3453
3454
3455
3456
3457
3458
3459
3460

3461
3462
3463
3464
3465
3466
3467
3468
3248
3249
3250
3251
3252
3253
3254

3255

3256
3257
3258
3259
3260
3261
3262







-
+
-







 *
 *----------------------------------------------------------------------
 */

static int
WriteExtraChunks(
    Tcl_Interp *interp,
    PNGImage *pngPtr,
    PNGImage *pngPtr)
    Tcl_Obj *metadataInObj)
{
    static const unsigned char sBIT_contents[] = {
	8, 8, 8, 8
    };
    int sBIT_length = 4;
    Tcl_DString buf;

3496
3497
3498
3499
3500
3501
3502
3503
3504


3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3290
3291
3292
3293
3294
3295
3296


3297
3298
3299
3300
3301
3302
3303
3304
3305
3306









































































3307
3308
3309
3310
3311
3312
3313







-
-
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







     * Say that it is Tk that made the PNG. Note that we *need* the NUL at the
     * end of "Software" to be transferred; do *not* change the length
     * parameter to -1 there!
     */

    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, "Software", 9);
    Tcl_DStringAppend(&buf, "Tk Toolkit v", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, TK_PATCH_LEVEL, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, "Tk Toolkit v", -1);
    Tcl_DStringAppend(&buf, TK_PATCH_LEVEL, -1);
    if (WriteChunk(interp, pngPtr, CHUNK_tEXt,
	    (unsigned char *) Tcl_DStringValue(&buf),
	    Tcl_DStringLength(&buf)) != TCL_OK) {
	Tcl_DStringFree(&buf);
	return TCL_ERROR;
    }
    Tcl_DStringFree(&buf);

    /*
     * Add a pHYs chunk if there is metadata for DPI and/or aspect
     * aspect = PPUy / PPUx
     * DPI = PPUx * 0.0254
     * The physical chunk consists of:
     * - Points per meter in x direction (32 bit)
     * - Points per meter in x direction (32 bit)
     * - Unit specifier: 0: no unit (only aspect), 1: Points per meter
     */

    if (metadataInObj != NULL) {

	Tcl_Obj *aspectObj, *DPIObj;
	double aspectValue=-1, DPIValue=-1;
	unsigned long PPUx = 65536, PPUy = 65536;
	char unitSpecifier;

	if (TCL_ERROR == Tcl_DictObjGet(interp, metadataInObj,
		Tcl_NewStringObj("aspect",-1),
		&aspectObj) ||
	    TCL_ERROR == Tcl_DictObjGet(interp, metadataInObj,
		Tcl_NewStringObj("DPI",-1),
		&DPIObj) ) {
	    return TCL_ERROR;
	}
	if (DPIObj != NULL) {
	    if (TCL_ERROR == Tcl_GetDoubleFromObj(interp, DPIObj, &DPIValue))
	    {
		return TCL_ERROR;
	    }
	    PPUx = (unsigned long)floor(DPIValue / 0.0254+0.5);
	    if (aspectObj == NULL) {
		PPUy = PPUx;
	    }
	    unitSpecifier = 1;
	}
	if (aspectObj != NULL) {
	    if (TCL_ERROR == Tcl_GetDoubleFromObj(interp, aspectObj,
		    &aspectValue)) {
		return TCL_ERROR;
	    }

	    /*
	     * aspect = PPUy / PPUx
	     */

	    if (DPIObj == NULL) {
		unitSpecifier = 0;
		PPUx = 65536;
		PPUy = (unsigned long)floor(65536.0 * aspectValue+0.5);
	    } else {
		PPUy = (unsigned long)floor(DPIValue * aspectValue / 0.0254+0.5);
	    }
	}
	if (DPIObj != NULL || aspectObj != NULL) {
	    unsigned char buffer[9];

	    if ( PPUx > 2147483647 || PPUy > 2147483647 ) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"DPI or aspect out of range", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "PHYS", NULL);
		return TCL_ERROR;
	    }

	    LongToInt32(PPUx, buffer);
	    LongToInt32(PPUy, buffer+4);
	    buffer[8] = unitSpecifier;
	    if (WriteChunk(interp, pngPtr, CHUNK_pHYs, buffer, 9)
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * EncodePNG --
3604
3605
3606
3607
3608
3609
3610
3611

3612
3613
3614
3615
3616
3617
3618
3619
3325
3326
3327
3328
3329
3330
3331

3332

3333
3334
3335
3336
3337
3338
3339







-
+
-







 *----------------------------------------------------------------------
 */

static int
EncodePNG(
    Tcl_Interp *interp,
    Tk_PhotoImageBlock *blockPtr,
    PNGImage *pngPtr,
    PNGImage *pngPtr)
    Tcl_Obj *metadataInObj)
{
    int greenOffset, blueOffset, alphaOffset;

    /*
     * Determine appropriate color type based on color usage (e.g., only red
     * and maybe alpha channel = grayscale).
     *
3655
3656
3657
3658
3659
3660
3661
3662

3663
3664
3665
3666
3667
3668
3669
3375
3376
3377
3378
3379
3380
3381

3382
3383
3384
3385
3386
3387
3388
3389







-
+








    pngPtr->lineSize = 1 + (pngPtr->bytesPerPixel * blockPtr->width);
    pngPtr->blockLen = pngPtr->lineSize * blockPtr->height;

    if ((blockPtr->width > (INT_MAX - 1) / (pngPtr->bytesPerPixel)) ||
	    (blockPtr->height > INT_MAX / pngPtr->lineSize)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"image is too large to encode pixel data", TCL_INDEX_NONE));
		"image is too large to encode pixel data", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "TOO_LARGE", NULL);
	return TCL_ERROR;
    }

    pngPtr->lastLineObj = Tcl_NewObj();
    Tcl_IncrRefCount(pngPtr->lastLineObj);
    pngPtr->thisLineObj = Tcl_NewObj();
3688
3689
3690
3691
3692
3693
3694
3695

3696
3697
3698
3699
3700
3701
3702
3408
3409
3410
3411
3412
3413
3414

3415
3416
3417
3418
3419
3420
3421
3422







-
+







    }

    /*
     * Write out the extra chunks containing metadata that is of interest to
     * other programs more than us.
     */

    if (WriteExtraChunks(interp, pngPtr, metadataInObj) == TCL_ERROR) {
    if (WriteExtraChunks(interp, pngPtr) == TCL_ERROR) {
	return TCL_ERROR;
    }

    /*
     * Write out the image pixels in the IDAT (data) chunk.
     */

3729
3730
3731
3732
3733
3734
3735
3736
3737

3738
3739
3740
3741
3742
3743
3744
3449
3450
3451
3452
3453
3454
3455


3456
3457
3458
3459
3460
3461
3462
3463







-
-
+







 *----------------------------------------------------------------------
 */

static int
FileWritePNG(
    Tcl_Interp *interp,
    const char *filename,
    TCL_UNUSED(Tcl_Obj *),
    Tcl_Obj *metadataInObj,
    Tcl_Obj *fmtObj,
    Tk_PhotoImageBlock *blockPtr)
{
    Tcl_Channel chan;
    PNGImage png;
    int result = TCL_ERROR;

    /*
3771
3772
3773
3774
3775
3776
3777
3778

3779
3780
3781
3782
3783
3784
3785
3490
3491
3492
3493
3494
3495
3496

3497
3498
3499
3500
3501
3502
3503
3504







-
+







	goto cleanup;
    }

    /*
     * Write the raw PNG data out to the file.
     */

    result = EncodePNG(interp, blockPtr, &png, metadataInObj);
    result = EncodePNG(interp, blockPtr, &png);

  cleanup:
    Tcl_Close(interp, chan);
    CleanupPNGImage(&png);
    return result;
}

3800
3801
3802
3803
3804
3805
3806
3807
3808

3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829

3830
3831
3832
3833
3834
3835
3836
3519
3520
3521
3522
3523
3524
3525


3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546

3547
3548
3549
3550
3551
3552
3553
3554







-
-
+




















-
+







 *
 *----------------------------------------------------------------------
 */

static int
StringWritePNG(
    Tcl_Interp *interp,
    TCL_UNUSED(Tcl_Obj *),
    Tcl_Obj *metadataInObj,
    Tcl_Obj *fmtObj,
    Tk_PhotoImageBlock *blockPtr)
{
    Tcl_Obj *resultObj = Tcl_NewObj();
    PNGImage png;
    int result = TCL_ERROR;

    /*
     * Initalize PNGImage instance for encoding.
     */

    if (InitPNGImage(interp, &png, NULL, resultObj,
	    TCL_ZLIB_STREAM_DEFLATE) == TCL_ERROR) {
	goto cleanup;
    }

    /*
     * Write the raw PNG data into the prepared Tcl_Obj buffer. Set the result
     * back to the interpreter if successful.
     */

    result = EncodePNG(interp, blockPtr, &png, metadataInObj);
    result = EncodePNG(interp, blockPtr, &png);

    if (TCL_OK == result) {
	Tcl_SetObjResult(interp, png.objDataPtr);
    }

  cleanup:
    CleanupPNGImage(&png);

Changes to generic/tkImgPPM.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18




19
20
21
22
23
24
25





-
-
+
+











-
-
-
-







/*
 * tkImgPPM.c --
 *
 *	A photo image file handler for PPM (Portable PixMap) files.
 *
 * Copyright © 1994 The Australian National University.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1994 The Australian National University.
 * 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.
 *
 * Author: Paul Mackerras ([email protected]),
 *	Department of Computer Science,
 *	Australian National University.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The maximum amount of memory to allocate for data read from the file. If we
 * need more than this, we do it in pieces.
 */

#define MAX_MEMORY	10000		/* don't allocate > 10KB */

94
95
96
97
98
99
100
101
102


103
104
105
106
107

108
109
110
111
112
113
114
90
91
92
93
94
95
96


97
98
99
100
101
102

103
104
105
106
107
108
109
110







-
-
+
+




-
+







 *
 *----------------------------------------------------------------------
 */

static int
FileMatchPPM(
    Tcl_Channel chan,		/* The image file, open for reading. */
    TCL_UNUSED(const char *),	/* The name of the image file. */
    TCL_UNUSED(Tcl_Obj *),		/* User-specified format string, or NULL. */
    const char *fileName,	/* The name of the image file. */
    Tcl_Obj *format,		/* User-specified format string, or NULL. */
    int *widthPtr, int *heightPtr,
				/* The dimensions of the image are returned
				 * here if the file is a valid raw PPM
				 * file. */
    TCL_UNUSED(Tcl_Interp *))		/* unused */
    Tcl_Interp *interp)		/* unused */
{
    int dummy;

    return ReadPPMFileHeader(chan, widthPtr, heightPtr, &dummy);
}

/*
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143

144

145
146
147
148
149
150
151







-
+









-
+
-







 */

static int
FileReadPPM(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Channel chan,		/* The image file, open for reading. */
    const char *fileName,	/* The name of the image file. */
    TCL_UNUSED(Tcl_Obj *),		/* User-specified format string, or NULL. */
    Tcl_Obj *format,		/* User-specified format string, or NULL. */
    Tk_PhotoHandle imageHandle,	/* The photo image to write into. */
    int destX, int destY,	/* Coordinates of top-left pixel in photo
				 * image to be written to. */
    int width, int height,	/* Dimensions of block of photo image to be
				 * written to. */
    int srcX, int srcY)		/* Coordinates of top-left pixel to be used in
				 * image being read. */
{
    int fileWidth, fileHeight, maxIntensity;
    int nLines, h, type, bytesPerChannel = 1;
    int nLines, nBytes, h, type, count, bytesPerChannel = 1;
    size_t nBytes, count;
    unsigned char *pixelPtr;
    Tk_PhotoImageBlock block;

    type = ReadPPMFileHeader(chan, &fileWidth, &fileHeight, &maxIntensity);
    if (type == 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't read raw PPM header from file \"%s\"", fileName));
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+










-
+








    if (Tk_PhotoExpand(interp, imageHandle,
	    destX + width, destY + height) != TCL_OK) {
	return TCL_ERROR;
    }

    if (srcY > 0) {
	Tcl_Seek(chan, (long long)srcY * block.pitch, SEEK_CUR);
	Tcl_Seek(chan, (Tcl_WideInt)(srcY * block.pitch), SEEK_CUR);
    }

    nLines = (MAX_MEMORY + block.pitch - 1) / block.pitch;
    if (nLines > height) {
	nLines = height;
    }
    if (nLines <= 0) {
	nLines = 1;
    }
    nBytes = nLines * block.pitch;
    pixelPtr = (unsigned char *)ckalloc(nBytes);
    pixelPtr = ckalloc(nBytes);
    block.pixelPtr = pixelPtr + srcX * block.pixelSize;

    for (h = height; h > 0; h -= nLines) {
	if (nLines > h) {
	    nLines = h;
	    nBytes = nLines * block.pitch;
	}
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250







-
+







	    for (p = pixelPtr; count > 0; count--, p++) {
		*p = (((int) *p) * 255)/maxIntensity;
	    }
	} else if (maxIntensity > 0x00ff) {
	    unsigned char *p;
	    unsigned int value;

	    for (p = pixelPtr; count > 0; count -= 2, p += 2) {
	    for (p = pixelPtr; count > 0; count--, p += 2) {
		value = ((unsigned int) p[0]) * 256 + ((unsigned int) p[1]);
		value = value * 255 / maxIntensity;
		p[0] = p[1] = (unsigned char) value;
	    }
	}
	block.height = nLines;
	if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
282
283
284
285
286
287
288
289

290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315


316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333



334
335
336
337
338
339
340
277
278
279
280
281
282
283

284
285
286
287

288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307


308
309
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324



325
326
327
328
329
330
331
332
333
334







-
+



-
+
-



















-
-
+
+








-
+






-
-
-
+
+
+







 *----------------------------------------------------------------------
 */

static int
FileWritePPM(
    Tcl_Interp *interp,
    const char *fileName,
    TCL_UNUSED(Tcl_Obj *),
    Tcl_Obj *format,
    Tk_PhotoImageBlock *blockPtr)
{
    Tcl_Channel chan;
    int w, h, greenOffset, blueOffset;
    int w, h, greenOffset, blueOffset, nBytes;
    size_t nBytes;
    unsigned char *pixelPtr, *pixLinePtr;
    char header[16 + TCL_INTEGER_SPACE * 2];

    chan = Tcl_OpenFileChannel(interp, fileName, "w", 0666);
    if (chan == NULL) {
	return TCL_ERROR;
    }

    if (Tcl_SetChannelOption(interp, chan, "-translation", "binary")
	    != TCL_OK) {
	Tcl_Close(NULL, chan);
	return TCL_ERROR;
    }
    if (Tcl_SetChannelOption(interp, chan, "-encoding", "binary")
	    != TCL_OK) {
	Tcl_Close(NULL, chan);
	return TCL_ERROR;
    }

    snprintf(header, sizeof(header), "P6\n%d %d\n255\n", blockPtr->width, blockPtr->height);
    Tcl_Write(chan, header, TCL_INDEX_NONE);
    sprintf(header, "P6\n%d %d\n255\n", blockPtr->width, blockPtr->height);
    Tcl_Write(chan, header, -1);

    pixLinePtr = blockPtr->pixelPtr + blockPtr->offset[0];
    greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
    blueOffset = blockPtr->offset[2] - blockPtr->offset[0];

    if ((greenOffset == 1) && (blueOffset == 2) && (blockPtr->pixelSize == 3)
	    && (blockPtr->pitch == (blockPtr->width * 3))) {
	nBytes = blockPtr->height * blockPtr->pitch;
	if ((size_t)Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) {
	if (Tcl_Write(chan, (char *) pixLinePtr, nBytes) != nBytes) {
	    goto writeerror;
	}
    } else {
	for (h = blockPtr->height; h > 0; h--) {
	    pixelPtr = pixLinePtr;
	    for (w = blockPtr->width; w > 0; w--) {
		if (Tcl_Write(chan,(char *)&pixelPtr[0], 1) == TCL_IO_FAILURE ||
			Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1) == TCL_IO_FAILURE ||
			Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) == TCL_IO_FAILURE) {
		if (    Tcl_Write(chan,(char *)&pixelPtr[0], 1) == -1 ||
			Tcl_Write(chan,(char *)&pixelPtr[greenOffset],1)==-1 ||
			Tcl_Write(chan,(char *)&pixelPtr[blueOffset],1) ==-1) {
		    goto writeerror;
		}
		pixelPtr += blockPtr->pixelSize;
	    }
	    pixLinePtr += blockPtr->pitch;
	}
    }
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385

386
387
388
389
390
391
392
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+







-
+







 *
 *----------------------------------------------------------------------
 */

static int
StringWritePPM(
    Tcl_Interp *interp,
    TCL_UNUSED(Tcl_Obj *),
    Tcl_Obj *format,
    Tk_PhotoImageBlock *blockPtr)
{
    int w, h, size, greenOffset, blueOffset;
    unsigned char *pixLinePtr, *byteArray;
    char header[16 + TCL_INTEGER_SPACE * 2];
    Tcl_Obj *byteArrayObj;

    snprintf(header, sizeof(header), "P6\n%d %d\n255\n", blockPtr->width, blockPtr->height);
    sprintf(header, "P6\n%d %d\n255\n", blockPtr->width, blockPtr->height);

    /*
     * Construct a byte array of the right size with the header and
     * get a pointer to the data part of it.
     */

    size = strlen(header);
446
447
448
449
450
451
452
453

454
455
456
457
458

459
460
461
462
463
464
465
440
441
442
443
444
445
446

447
448
449
450
451

452
453
454
455
456
457
458
459







-
+




-
+







 *
 *----------------------------------------------------------------------
 */

static int
StringMatchPPM(
    Tcl_Obj *dataObj,		/* The image data. */
    TCL_UNUSED(Tcl_Obj *),		/* User-specified format string, or NULL. */
    Tcl_Obj *format,		/* User-specified format string, or NULL. */
    int *widthPtr, int *heightPtr,
				/* The dimensions of the image are returned
				 * here if the file is a valid raw PPM
				 * file. */
    TCL_UNUSED(Tcl_Interp *))		/* unused */
    Tcl_Interp *interp)		/* unused */
{
    int dummy;

    return ReadPPMStringHeader(dataObj, widthPtr, heightPtr,
	    &dummy, NULL, NULL);
}

481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512

513
514
515
516
517
518
519
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505

506
507
508
509
510
511
512
513







-
+

















-
+





-
+







 *----------------------------------------------------------------------
 */

static int
StringReadPPM(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Obj *dataObj,		/* The image data. */
    TCL_UNUSED(Tcl_Obj *),		/* User-specified format string, or NULL. */
    Tcl_Obj *format,		/* User-specified format string, or NULL. */
    Tk_PhotoHandle imageHandle,	/* The photo image to write into. */
    int destX, int destY,	/* Coordinates of top-left pixel in photo
				 * image to be written to. */
    int width, int height,	/* Dimensions of block of photo image to be
				 * written to. */
    int srcX, int srcY)		/* Coordinates of top-left pixel to be used in
				 * image being read. */
{
    int fileWidth, fileHeight, maxIntensity;
    int nLines, nBytes, h, type, count, dataSize, bytesPerChannel = 1;
    unsigned char *pixelPtr, *dataBuffer;
    Tk_PhotoImageBlock block;

    type = ReadPPMStringHeader(dataObj, &fileWidth, &fileHeight,
	    &maxIntensity, &dataBuffer, &dataSize);
    if (type == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"couldn't read raw PPM header from string", TCL_INDEX_NONE));
		"couldn't read raw PPM header from string", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "NO_HEADER", NULL);
	return TCL_ERROR;
    }
    if ((fileWidth <= 0) || (fileHeight <= 0)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"PPM image data has dimension(s) <= 0", TCL_INDEX_NONE));
		"PPM image data has dimension(s) <= 0", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "DIMENSIONS", NULL);
	return TCL_ERROR;
    }
    if ((maxIntensity <= 0) || (maxIntensity > 0xffff)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"PPM image data has bad maximum intensity value %d",
		maxIntensity));
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
551
552
553
554
555
556
557

558
559
560
561
562
563
564
565







-
+







    if (maxIntensity == 0x00ff) {
	/*
	 * We have all the data in memory, so write everything in one go.
	 */

	if (block.pitch*height > dataSize) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "truncated PPM data", TCL_INDEX_NONE));
		    "truncated PPM data", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "TRUNCATED", NULL);
	    return TCL_ERROR;
	}
	block.pixelPtr = dataBuffer + srcX * block.pixelSize;
	block.height = height;
	return Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
		width, height, TK_PHOTO_COMPOSITE_SET);
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608

609
610
611
612


613
614
615
616
617
618
619
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605


606
607
608
609
610
611
612
613
614







-
+












-
+








+


-
-
+
+







    if (nLines > height) {
	nLines = height;
    }
    if (nLines <= 0) {
	nLines = 1;
    }
    nBytes = nLines * block.pitch;
    pixelPtr = (unsigned char *)ckalloc(nBytes);
    pixelPtr = ckalloc(nBytes);
    block.pixelPtr = pixelPtr + srcX * block.pixelSize;

    for (h = height; h > 0; h -= nLines) {
	unsigned char *p;

	if (nLines > h) {
	    nLines = h;
	    nBytes = nLines * block.pitch;
	}
	if (dataSize < nBytes) {
	    ckfree(pixelPtr);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "truncated PPM data", TCL_INDEX_NONE));
		    "truncated PPM data", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "TRUNCATED", NULL);
	    return TCL_ERROR;
	}
	if (maxIntensity < 0x00ff) {
	    for (p=pixelPtr,count=nBytes ; count>0 ; count--,p++,dataBuffer++) {
		*p = (((int) *dataBuffer) * 255)/maxIntensity;
	    }
	} else {
	    unsigned char *p;
	    unsigned int value;

	    for (p = pixelPtr,count=nBytes; count > 1; count-=2, p += 2, dataBuffer += 2) {
		value = ((unsigned int)dataBuffer[0]) * 256 + ((unsigned int)dataBuffer[1]);
	    for (p = pixelPtr,count=nBytes; count > 1; count-=2, p += 2) {
		value = ((unsigned int) p[0]) * 256 + ((unsigned int) p[1]);
		value = value * 255 / maxIntensity;
		p[0] = p[1] = (unsigned char) value;
	    }
	}
	dataSize -= nBytes;
	block.height = nLines;
	if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
778
758
759
760
761
762
763
764

765

766
767
768
769
770
771
772







-
+
-







    int *maxIntensityPtr,	/* The maximum intensity value for the image
				 * is stored here. */
    unsigned char **dataBufferPtr,
    int *dataSizePtr)
{
#define BUFFER_SIZE 1000
    char buffer[BUFFER_SIZE], c;
    int i, numFields, type = 0;
    int i, numFields, dataSize, type = 0;
    Tcl_Size dataSize;
    unsigned char *dataBuffer;

    dataBuffer = Tcl_GetByteArrayFromObj(dataPtr, &dataSize);

    /*
     * Read 4 space-separated fields from the string, ignoring comments (any
     * line that starts with "#").

Changes to generic/tkImgPhInstance.c.

1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98

99
100

101
102
103
104
105



106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
1
2
3
4
5
6
7




8
9
10
11
12
13
14
15
16
17
18
19
20
21





22
23
24
25

26



27




28
29
30
31
32

33
34

35
36

37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83

84
85

86
87
88



89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
-
-
-
+
+
+
+










-
-
-
-
-




-
+
-
-
-

-
-
-
-





-


-


-
+



-
+

















-
-
+
+
















-
+






-
+

-
+


-
-
-
+
+
+



-
+

















-
+







/*
 * tkImgPhInstance.c --
 *
 *	Implements the rendering of images of type "photo" for Tk. Photo
 *	images are stored in full color (32 bits per pixel including alpha
 *	channel) and displayed using dithering if necessary.
 *
 * Copyright © 1994 The Australian National University.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2002-2008 Donal K. Fellows
 * Copyright © 2003 ActiveState Corporation.
 * Copyright (c) 1994 The Australian National University.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2002-2008 Donal K. Fellows
 * Copyright (c) 2003 ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * Author: Paul Mackerras ([email protected]),
 *	   Department of Computer Science,
 *	   Australian National University.
 */

#include "tkImgPhoto.h"
#include "tkPort.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Declaration for internal Xlib function used here:
 */
#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TK)

#ifdef __cplusplus
extern "C" {
#endif
extern int		_XInitImageFuncPtrs(XImage *image);
#ifdef __cplusplus
}
#endif
#endif

/*
 * Forward declarations
 */

#ifndef TK_CAN_RENDER_RGBA
static void		BlendComplexAlpha(XImage *bgImg, PhotoInstance *iPtr,
			    int xOffset, int yOffset, int width, int height);
#endif
static int		IsValidPalette(PhotoInstance *instancePtr,
			    const char *palette);
static int		CountBits(unsigned mask);
static int		CountBits(pixel mask);
static void		GetColorTable(PhotoInstance *instancePtr);
static void		FreeColorTable(ColorTable *colorPtr, int force);
static void		AllocateColors(ColorTable *colorPtr);
static void		DisposeColorTable(void *clientData);
static void		DisposeColorTable(ClientData clientData);
static int		ReclaimColors(ColorTableId *id, int numColors);

/*
 * Hash table used to hash from (display, colormap, palette, gamma) to
 * ColorTable address.
 */

static Tcl_HashTable imgPhotoColorHash;
static int imgPhotoColorHashInitialized;
#define N_COLOR_HASH	(sizeof(ColorTableId) / sizeof(int))

/*
 *----------------------------------------------------------------------
 *
 * TkImgPhotoConfigureInstance --
 *
 *	This function is called to create displaying information for a photo
 *	image instance based on the configuration information in the model.
 *	It is invoked both when new instances are created and when the model
 *	image instance based on the configuration information in the master.
 *	It is invoked both when new instances are created and when the master
 *	is reconfigured.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Generates errors via Tcl_BackgroundException if there are problems in
 *	setting up the instance.
 *
 *----------------------------------------------------------------------
 */

void
TkImgPhotoConfigureInstance(
    PhotoInstance *instancePtr)	/* Instance to reconfigure. */
{
    PhotoModel *modelPtr = instancePtr->modelPtr;
    PhotoMaster *masterPtr = instancePtr->masterPtr;
    XImage *imagePtr;
    int bitsPerPixel;
    ColorTable *colorTablePtr;
    XRectangle validBox;

    /*
     * If the -palette configuration option has been set for the model, use
     * If the -palette configuration option has been set for the master, use
     * the value specified for our palette, but only if it is a valid palette
     * for our windows. Use the gamma value specified the model.
     * for our windows. Use the gamma value specified the master.
     */

    if ((modelPtr->palette && modelPtr->palette[0])
	    && IsValidPalette(instancePtr, modelPtr->palette)) {
	instancePtr->palette = modelPtr->palette;
    if ((masterPtr->palette && masterPtr->palette[0])
	    && IsValidPalette(instancePtr, masterPtr->palette)) {
	instancePtr->palette = masterPtr->palette;
    } else {
	instancePtr->palette = instancePtr->defaultPalette;
    }
    instancePtr->gamma = modelPtr->gamma;
    instancePtr->gamma = masterPtr->gamma;

    /*
     * If we don't currently have a color table, or if the one we have no
     * longer applies (e.g. because our palette or gamma has changed), get a
     * new one.
     */

    colorTablePtr = instancePtr->colorTablePtr;
    if ((colorTablePtr == NULL)
	    || (instancePtr->colormap != colorTablePtr->id.colormap)
	    || (instancePtr->palette != colorTablePtr->id.palette)
	    || (instancePtr->gamma != colorTablePtr->id.gamma)) {
	/*
	 * Free up our old color table, and get a new one.
	 */

	if (colorTablePtr != NULL) {
	    colorTablePtr->liveRefCount--;
	    colorTablePtr->liveRefCount -= 1;
	    FreeColorTable(colorTablePtr, 0);
	}
	GetColorTable(instancePtr);

	/*
	 * Create a new XImage structure for sending data to the X server, if
	 * necessary.
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181


182
183
184
185
186
187
188
189

190
191

192
193
194
195
196
197
198
152
153
154
155
156
157
158

159
160
161
162
163
164
165


166
167
168
169
170
171
172
173
174

175
176

177
178
179
180
181
182
183
184







-
+






-
-
+
+







-
+

-
+







#endif
		_XInitImageFuncPtrs(imagePtr);
	    }
	}
    }

    /*
     * If the user has specified a width and/or height for the model which is
     * If the user has specified a width and/or height for the master which is
     * different from our current width/height, set the size to the values
     * specified by the user. If we have no pixmap, we do this also, since it
     * has the side effect of allocating a pixmap for us.
     */

    if ((instancePtr->pixels == None) || (instancePtr->error == NULL)
	    || (instancePtr->width != modelPtr->width)
	    || (instancePtr->height != modelPtr->height)) {
	    || (instancePtr->width != masterPtr->width)
	    || (instancePtr->height != masterPtr->height)) {
	TkImgPhotoInstanceSetSize(instancePtr);
    }

    /*
     * Redither this instance if necessary.
     */

    if ((modelPtr->flags & IMAGE_CHANGED)
    if ((masterPtr->flags & IMAGE_CHANGED)
	    || (instancePtr->colorTablePtr != colorTablePtr)) {
	TkClipBox(modelPtr->validRegion, &validBox);
	TkClipBox(masterPtr->validRegion, &validBox);
	if ((validBox.width > 0) && (validBox.height > 0)) {
	    TkImgDitherInstance(instancePtr, validBox.x, validBox.y,
		    validBox.width, validBox.height);
	}
    }
}

214
215
216
217
218
219
220
221

222
223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
200
201
202
203
204
205
206

207
208
209

210
211
212
213
214
215
216
217



218
219
220
221
222
223
224







-
+


-
+







-
-
-







 *----------------------------------------------------------------------
 */

ClientData
TkImgPhotoGet(
    Tk_Window tkwin,		/* Window in which the instance will be
				 * used. */
    void *modelData)	/* Pointer to our model structure for the
    ClientData masterData)	/* Pointer to our master structure for the
				 * image. */
{
    PhotoModel *modelPtr = (PhotoModel *)modelData;
    PhotoMaster *masterPtr = masterData;
    PhotoInstance *instancePtr;
    Colormap colormap;
    int mono, nRed, nGreen, nBlue, numVisuals;
    XVisualInfo visualInfo, *visInfoPtr;
    char buf[TCL_INTEGER_SPACE * 3];
    XColor *white, *black;
    XGCValues gcValues;
#if (!defined(_WIN32) && !defined(MAC_OSX_TK))
    int gcmask;
#endif

    /*
     * Table of "best" choices for palette for PseudoColor displays with
     * between 3 and 15 bits/pixel.
     */

    static const int paletteChoice[13][3] = {
257
258
259
260
261
262
263
264

265
266
267

268
269
270
271
272
273
274
275
276
277
278
240
241
242
243
244
245
246

247
248
249

250




251
252
253
254
255
256
257







-
+


-
+
-
-
-
-








    /*
     * See if there is already an instance for windows using the same
     * colormap. If so then just re-use it.
     */

    colormap = Tk_Colormap(tkwin);
    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	if ((colormap == instancePtr->colormap)
	    && (Tk_Display(tkwin) == instancePtr->display)
		&& (Tk_Display(tkwin) == instancePtr->display)) {
#if (!defined(_WIN32) && !defined(MAC_OSX_TK))
	    && (Tk_Visual(tkwin) == instancePtr->visualInfo.visual)
#endif
	    ) {
	    /*
	     * Re-use this instance.
	     */

	    if (instancePtr->refCount == 0) {
		/*
		 * We are resurrecting this instance.
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
307
308
309
310


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
269
270
271
272
273
274
275


276
277
278
279
280
281
282
283
284
285
286
287


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306





307
308
309
310
311
312
313








314
315
316
317
318
319
320







-
-
+
+










-
-
+
+

















-
-
-
-
-
+






-
-
-
-
-
-
-
-







    }

    /*
     * The image isn't already in use in a window with the same colormap. Make
     * a new instance of the image.
     */

    instancePtr = (PhotoInstance *)ckalloc(sizeof(PhotoInstance));
    instancePtr->modelPtr = modelPtr;
    instancePtr = ckalloc(sizeof(PhotoInstance));
    instancePtr->masterPtr = masterPtr;
    instancePtr->display = Tk_Display(tkwin);
    instancePtr->colormap = Tk_Colormap(tkwin);
    Tk_PreserveColormap(instancePtr->display, instancePtr->colormap);
    instancePtr->refCount = 1;
    instancePtr->colorTablePtr = NULL;
    instancePtr->pixels = None;
    instancePtr->error = NULL;
    instancePtr->width = 0;
    instancePtr->height = 0;
    instancePtr->imagePtr = 0;
    instancePtr->nextPtr = modelPtr->instancePtr;
    modelPtr->instancePtr = instancePtr;
    instancePtr->nextPtr = masterPtr->instancePtr;
    masterPtr->instancePtr = instancePtr;

    /*
     * Obtain information about the visual and decide on the default palette.
     */

    visualInfo.screen = Tk_ScreenNumber(tkwin);
    visualInfo.visualid = XVisualIDFromVisual(Tk_Visual(tkwin));
    visInfoPtr = XGetVisualInfo(Tk_Display(tkwin),
	    VisualScreenMask | VisualIDMask, &visualInfo, &numVisuals);
    if (visInfoPtr == NULL) {
	Tcl_Panic("TkImgPhotoGet couldn't find visual for window");
    }

    nRed = 2;
    nGreen = nBlue = 0;
    mono = 1;
    instancePtr->visualInfo = *visInfoPtr;
#if (!defined(_WIN32) && !defined(MAC_OSX_TK))
    gcmask = 0;
    instancePtr->visualInfo.visual = Tk_Visual(tkwin);
#endif
    switch (visInfoPtr->c_class) {
    switch (visInfoPtr->class) {
    case DirectColor:
    case TrueColor:
	nRed = 1 << CountBits(visInfoPtr->red_mask);
	nGreen = 1 << CountBits(visInfoPtr->green_mask);
	nBlue = 1 << CountBits(visInfoPtr->blue_mask);
	mono = 0;
#if (!defined(_WIN32) && !defined(MAC_OSX_TK))
	if (visInfoPtr->depth > 24) {
	    gcValues.plane_mask = visInfoPtr->red_mask
		    | visInfoPtr->green_mask
		    | visInfoPtr->blue_mask;
	    gcmask = GCPlaneMask;
	}
#endif
	break;
    case PseudoColor:
    case StaticColor:
	if (visInfoPtr->depth > 15) {
	    nRed = 32;
	    nGreen = 32;
	    nBlue = 32;
362
363
364
365
366
367
368
369

370
371
372

373
374

375
376
377
378
379
380
381
382
383


384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412


413
414
415
416
417
418
419
329
330
331
332
333
334
335

336
337
338

339
340

341
342
343
344
345
346
347
348


349
350
351
352
353
354
355
356
357

358




359

360
361
362
363
364
365
366
367
368
369
370
371
372


373
374
375
376
377
378
379
380
381







-
+


-
+

-
+







-
-
+
+







-

-
-
-
-
+
-













-
-
+
+







	}
	break;
    case GrayScale:
    case StaticGray:
	nRed = 1 << visInfoPtr->depth;
	break;
    }
    XFree(visInfoPtr);
    XFree((char *) visInfoPtr);

    if (mono) {
	snprintf(buf, sizeof(buf), "%d", nRed);
	sprintf(buf, "%d", nRed);
    } else {
	snprintf(buf, sizeof(buf), "%d/%d/%d", nRed, nGreen, nBlue);
	sprintf(buf, "%d/%d/%d", nRed, nGreen, nBlue);
    }
    instancePtr->defaultPalette = Tk_GetUid(buf);

    /*
     * Make a GC with background = black and foreground = white.
     */

    white = Tk_GetColor(modelPtr->interp, tkwin, "white");
    black = Tk_GetColor(modelPtr->interp, tkwin, "black");
    white = Tk_GetColor(masterPtr->interp, tkwin, "white");
    black = Tk_GetColor(masterPtr->interp, tkwin, "black");
    gcValues.foreground = (white != NULL)? white->pixel:
	    WhitePixelOfScreen(Tk_Screen(tkwin));
    gcValues.background = (black != NULL)? black->pixel:
	    BlackPixelOfScreen(Tk_Screen(tkwin));
    Tk_FreeColor(white);
    Tk_FreeColor(black);
    gcValues.graphics_exposures = False;
#if (!defined(_WIN32) && !defined(MAC_OSX_TK))
    instancePtr->gc = Tk_GetGC(tkwin,
	gcmask|GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
#else
    instancePtr->gc = Tk_GetGC(tkwin,
	GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
	    GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
#endif

    /*
     * Set configuration options and finish the initialization of the
     * instance. This will also dither the image if necessary.
     */

    TkImgPhotoConfigureInstance(instancePtr);

    /*
     * If this is the first instance, must set the size of the image.
     */

    if (instancePtr->nextPtr == NULL) {
	Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0,
		modelPtr->width, modelPtr->height);
	Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0,
		masterPtr->width, masterPtr->height);
    }

    return instancePtr;
}

/*
 *----------------------------------------------------------------------
438
439
440
441
442
443
444



445
446
447

448
449
450
451
452
453
454
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419







+
+
+


-
+







 *	This should work on all platforms that set mask and shift data
 *	properly from the visualInfo. RGB is really only a 24+ bpp version
 *	whereas RGB15 is the correct version and works for 15bpp+, but it
 *	slower, so it's only used for 15bpp+.
 *
 *	Note that Win32 pre-defines those operations that we really need.
 *
 *	Note that on MacOS, if the background comes from a Retina display
 *	then it will be twice as wide and twice as high as the photoimage.
 *
 *----------------------------------------------------------------------
 */
#ifndef TK_CAN_RENDER_RGBA

#ifndef _WIN32
#define GetRValue(rgb)	(UCHAR(((rgb) & red_mask) >> red_shift))
#define GetGValue(rgb)	(UCHAR(((rgb) & green_mask) >> green_shift))
#define GetBValue(rgb)	(UCHAR(((rgb) & blue_mask) >> blue_shift))
#define RGB(r, g, b)	((unsigned)( \
	(UCHAR(r) << red_shift)   | \
	(UCHAR(g) << green_shift) | \
465
466
467
468
469
470
471
472
473
474












475
476
477
478
479
480
481
430
431
432
433
434
435
436



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455







-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







    PhotoInstance *iPtr,	/* Image instance to draw. */
    int xOffset, int yOffset,	/* X & Y offset into image instance to
				 * draw. */
    int width, int height)	/* Width & height of image to draw. */
{
    int x, y, line;
    unsigned long pixel;
    unsigned char r, g, b, alpha, unalpha, *modelPtr;
    unsigned char *alphaAr = iPtr->modelPtr->pix32;

    unsigned char r, g, b, alpha, unalpha, *masterPtr;
    unsigned char *alphaAr = iPtr->masterPtr->pix32;
#if defined(MAC_OSX_TK)
    /* Background "pixels" are actually 2^pp x 2^pp blocks of subpixels.  Each
     * block gets blended with the color of one image pixel.  Since we iterate
     * over the background subpixels, we reset the width and height to the
     * subpixel dimensions of the background image we are using.
     */
    int pp = bgImg->pixelpower;
    width = width << pp;
    height = height << pp;
#endif
    /*
     * This blending is an integer version of the Source-Over compositing rule
     * (see Porter&Duff, "Compositing Digital Images", proceedings of SIGGRAPH
     * 1984) that has been hard-coded (for speed) to work with targetting a
     * solid surface.
     *
     * The 'unalpha' field must be 255-alpha; it is separated out to encourage
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530

531
532
533


534
535
536
537
538
539
540
541
542
543
544
545
546
547



548
549
550
551
552
553
554
489
490
491
492
493
494
495

496
497
498
499
500
501
502
503

504
505


506
507
508
509
510
511
512
513
514
515
516
517
518



519
520
521
522
523
524
525
526
527
528







-
+







-
+

-
-
+
+











-
-
-
+
+
+








    /*
     * Only UNIX requires the special case for <24bpp. It varies with 3 extra
     * shifts and uses RGB15. The 24+bpp version could also then be further
     * optimized.
     */

#if !defined(_WIN32)
#if !(defined(_WIN32) || defined(MAC_OSX_TK))
    if (bgImg->depth < 24) {
	unsigned char red_mlen, green_mlen, blue_mlen;

	red_mlen = 8 - CountBits(red_mask >> red_shift);
	green_mlen = 8 - CountBits(green_mask >> green_shift);
	blue_mlen = 8 - CountBits(blue_mask >> blue_shift);
	for (y = 0; y < height; y++) {
	    line = (y + yOffset) * iPtr->modelPtr->width;
	    line = (y + yOffset) * iPtr->masterPtr->width;
	    for (x = 0; x < width; x++) {
		modelPtr = alphaAr + ((line + x + xOffset) * 4);
		alpha = modelPtr[3];
		masterPtr = alphaAr + ((line + x + xOffset) * 4);
		alpha = masterPtr[3];

		/*
		 * Ignore pixels that are fully transparent
		 */

		if (alpha) {
		    /*
		     * We could perhaps be more efficient than XGetPixel for
		     * 24 and 32 bit displays, but this seems "fast enough".
		     */

		    r = modelPtr[0];
		    g = modelPtr[1];
		    b = modelPtr[2];
		    r = masterPtr[0];
		    g = masterPtr[1];
		    b = masterPtr[2];
		    if (alpha != 255) {
			/*
			 * Only blend pixels that have some transparency
			 */

			unsigned char ra, ga, ba;

563
564
565
566
567
568
569
570

571
572

573

574
575
576








577
578
579
580
581
582
583
584
585
586
587
588
589
590



591
592
593
594
595
596
597
537
538
539
540
541
542
543

544
545
546
547

548
549


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568



569
570
571
572
573
574
575
576
577
578







-
+


+
-
+

-
-
+
+
+
+
+
+
+
+











-
-
-
+
+
+







		    }
		    XPutPixel(bgImg, x, y, RGB15(r, g, b));
		}
	    }
	}
	return;
    }
#endif /* !_WIN32 */
#endif /* !_WIN32 && !MAC_OSX_TK */

    for (y = 0; y < height; y++) {
# if !defined(MAC_OSX_TK)
	line = (y + yOffset) * iPtr->modelPtr->width;
	line = (y + yOffset) * iPtr->masterPtr->width;
	for (x = 0; x < width; x++) {
	    modelPtr = alphaAr + ((line + x + xOffset) * 4);
	    alpha = modelPtr[3];
	    masterPtr = alphaAr + ((line + x + xOffset) * 4);
#else
	/* Repeat each image row and column 2^pp times. */
	line = ((y>>pp) + yOffset) * iPtr->masterPtr->width;
	for (x = 0; x < width; x++) {
	    masterPtr = alphaAr + ((line + (x>>pp) + xOffset) * 4);
#endif
	    alpha = masterPtr[3];

	    /*
	     * Ignore pixels that are fully transparent
	     */

	    if (alpha) {
		/*
		 * We could perhaps be more efficient than XGetPixel for 24
		 * and 32 bit displays, but this seems "fast enough".
		 */

		r = modelPtr[0];
		g = modelPtr[1];
		b = modelPtr[2];
		r = masterPtr[0];
		g = masterPtr[1];
		b = masterPtr[2];
		if (alpha != 255) {
		    /*
		     * Only blend pixels that have some transparency
		     */

		    unsigned char ra, ga, ba;

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678

679
680

681
682
683
684
685
686
687
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
623

624

625

626
627
628
629
630
631
632
633
634
635





















636
637

638
639
640
641
642
643
644
645







-



















-
+










-
+
-

-










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
+







		}
		XPutPixel(bgImg, x, y, RGB(r, g, b));
	    }
	}
    }
#undef ALPHA_BLEND
}
#endif /* TK_CAN_RENDER_RGBA */

/*
 *----------------------------------------------------------------------
 *
 * TkImgPhotoDisplay --
 *
 *	This function is invoked to draw a photo image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A portion of the image gets rendered in a pixmap or window.
 *
 *----------------------------------------------------------------------
 */

void
TkImgPhotoDisplay(
    void *clientData,	/* Pointer to PhotoInstance structure for
    ClientData clientData,	/* Pointer to PhotoInstance structure for
				 * instance to be displayed. */
    Display *display,		/* Display on which to draw image. */
    Drawable drawable,		/* Pixmap or window in which to draw image. */
    int imageX, int imageY,	/* Upper-left corner of region within image to
				 * draw. */
    int width, int height,	/* Dimensions of region within image to
				 * draw. */
    int drawableX,int drawableY)/* Coordinates within drawable that correspond
				 * to imageX and imageY. */
{
    PhotoInstance *instancePtr = (PhotoInstance *)clientData;
    PhotoInstance *instancePtr = clientData;
#ifndef TK_CAN_RENDER_RGBA
    XVisualInfo visInfo = instancePtr->visualInfo;
#endif

    /*
     * If there's no pixmap, it means that an error occurred while creating
     * the image instance so it can't be displayed.
     */

    if (instancePtr->pixels == None) {
	return;
    }

#ifdef TK_CAN_RENDER_RGBA

    /*
     * We can use TkpPutRGBAImage to render RGBA Ximages directly so there is
     * no need to call XGetImage or to do the Porter-Duff compositing by hand.
     */

    unsigned char *rgbaPixels = instancePtr->modelPtr->pix32;
    XImage *photo = XCreateImage(display, NULL, 32, ZPixmap, 0, (char*)rgbaPixels,
				 (unsigned int)instancePtr->width,
				 (unsigned int)instancePtr->height,
				 0, (unsigned int)(4 * instancePtr->width));
    TkpPutRGBAImage(display, drawable, instancePtr->gc,
	       photo, imageX, imageY, drawableX, drawableY,
	       (unsigned int) width, (unsigned int) height);
    photo->data = NULL;
    XDestroyImage(photo);

#else

    if ((instancePtr->modelPtr->flags & COMPLEX_ALPHA)
    if ((instancePtr->masterPtr->flags & COMPLEX_ALPHA)
	    && visInfo.depth >= 15
	    && (visInfo.c_class == DirectColor || visInfo.c_class == TrueColor)) {
	    && (visInfo.class == DirectColor || visInfo.class == TrueColor)) {
	Tk_ErrorHandler handler;
	XImage *bgImg = NULL;

	/*
	 * Create an error handler to suppress the case where the input was
	 * not properly constrained, which can cause an X error. [Bug 979239]
	 */
712
713
714
715
716
717
718
719

720
721
722
723
724
725
726

727
728
729
730
731
732
733
734
735

736
737
738
739
740
741
742
743
670
671
672
673
674
675
676

677
678
679
680
681
682
683

684
685
686
687
688
689
690
691
692

693

694
695
696
697
698
699
700







-
+






-
+








-
+
-







	TkPutImage(NULL, 0, display, drawable, instancePtr->gc,
		bgImg, 0, 0, drawableX, drawableY,
		(unsigned int) width, (unsigned int) height);
	XDestroyImage(bgImg);
	Tk_DeleteErrorHandler(handler);
    } else {
	/*
	 * modelPtr->validRegion describes which parts of the image contain valid
	 * masterPtr->region describes which parts of the image contain valid
	 * data. We set this region as the clip mask for the gc, setting its
	 * origin appropriately, and use it when drawing the image.
	 */

    fallBack:
	TkSetRegion(display, instancePtr->gc,
		instancePtr->modelPtr->validRegion);
		instancePtr->masterPtr->validRegion);
	XSetClipOrigin(display, instancePtr->gc, drawableX - imageX,
		drawableY - imageY);
	XCopyArea(display, instancePtr->pixels, drawable, instancePtr->gc,
		imageX, imageY, (unsigned) width, (unsigned) height,
		drawableX, drawableY);
	XSetClipMask(display, instancePtr->gc, None);
	XSetClipOrigin(display, instancePtr->gc, 0, 0);
    }
    (void)XFlush(display);
    XFlush(display);
#endif
}

/*
 *----------------------------------------------------------------------
 *
 * TkImgPhotoFree --
 *
752
753
754
755
756
757
758
759

760
761

762
763
764

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

781
782
783
784
785
786
787
709
710
711
712
713
714
715

716
717

718
719
720

721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744







-
+

-
+


-
+















-
+







 *	Internal data structures get cleaned up, later.
 *
 *----------------------------------------------------------------------
 */

void
TkImgPhotoFree(
    void *clientData,	/* Pointer to PhotoInstance structure for
    ClientData clientData,	/* Pointer to PhotoInstance structure for
				 * instance to be displayed. */
    TCL_UNUSED(Display *))	/* Display containing window that used
    Display *display)		/* Display containing window that used
				 * image. */
{
    PhotoInstance *instancePtr = (PhotoInstance *)clientData;
    PhotoInstance *instancePtr = clientData;
    ColorTable *colorPtr;

    if (instancePtr->refCount-- > 1) {
	return;
    }

    /*
     * There are no more uses of the image within this widget. Decrement the
     * count of live uses of its color table, so that its colors can be
     * reclaimed if necessary, and set up an idle call to free the instance
     * structure.
     */

    colorPtr = instancePtr->colorTablePtr;
    if (colorPtr != NULL) {
	colorPtr->liveRefCount--;
	colorPtr->liveRefCount -= 1;
    }

    Tcl_DoWhenIdle(TkImgDisposeInstance, instancePtr);
}

/*
 *----------------------------------------------------------------------
801
802
803
804
805
806
807
808

809
810
811
812
813
814
815


816
817
818


819
820
821
822
823
824


825
826
827
828
829
830
831
758
759
760
761
762
763
764

765
766
767
768
769
770


771
772
773


774
775
776
777
778
779


780
781
782
783
784
785
786
787
788







-
+





-
-
+
+

-
-
+
+




-
-
+
+







 *----------------------------------------------------------------------
 */

void
TkImgPhotoInstanceSetSize(
    PhotoInstance *instancePtr)	/* Instance whose size is to be changed. */
{
    PhotoModel *modelPtr;
    PhotoMaster *masterPtr;
    schar *newError, *errSrcPtr, *errDestPtr;
    int h, offset;
    XRectangle validBox;
    Pixmap newPixmap;

    modelPtr = instancePtr->modelPtr;
    TkClipBox(modelPtr->validRegion, &validBox);
    masterPtr = instancePtr->masterPtr;
    TkClipBox(masterPtr->validRegion, &validBox);

    if ((instancePtr->width != modelPtr->width)
	    || (instancePtr->height != modelPtr->height)
    if ((instancePtr->width != masterPtr->width)
	    || (instancePtr->height != masterPtr->height)
	    || (instancePtr->pixels == None)) {
	newPixmap = Tk_GetPixmap(instancePtr->display,
		RootWindow(instancePtr->display,
			instancePtr->visualInfo.screen),
		(modelPtr->width > 0) ? modelPtr->width: 1,
		(modelPtr->height > 0) ? modelPtr->height: 1,
		(masterPtr->width > 0) ? masterPtr->width: 1,
		(masterPtr->height > 0) ? masterPtr->height: 1,
		instancePtr->visualInfo.depth);
	if (!newPixmap) {
	    Tcl_Panic("Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize");
	}

	/*
	 * The following is a gross hack needed to properly support colormaps
847
848
849
850
851
852
853
854
855


856
857

858
859
860
861
862
863
864

865
866
867
868
869
870
871
872
873
874


875
876
877

878
879
880
881
882
883




884
885
886
887

888
889
890
891
892
893
894
895
896
897
898
899
900


901
902
903


904
905
906
907

908
909
910
911
912
913
914

915
916
917
918
919
920
921
922
923
924
925


926
927
928
929
930
931
932
804
805
806
807
808
809
810


811
812
813

814
815
816
817
818
819
820

821
822
823
824
825
826
827
828
829


830
831
832
833

834
835
836




837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855


856
857
858


859
860
861
862
863

864
865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880


881
882
883
884
885
886
887
888
889







-
-
+
+

-
+






-
+








-
-
+
+


-
+


-
-
-
-
+
+
+
+



-
+











-
-
+
+

-
-
+
+



-
+






-
+









-
-
+
+







		    instancePtr->gc, validBox.x, validBox.y,
		    validBox.width, validBox.height, validBox.x, validBox.y);
	    Tk_FreePixmap(instancePtr->display, instancePtr->pixels);
	}
	instancePtr->pixels = newPixmap;
    }

    if ((instancePtr->width != modelPtr->width)
	    || (instancePtr->height != modelPtr->height)
    if ((instancePtr->width != masterPtr->width)
	    || (instancePtr->height != masterPtr->height)
	    || (instancePtr->error == NULL)) {
	if (modelPtr->height > 0 && modelPtr->width > 0) {
	if (masterPtr->height > 0 && masterPtr->width > 0) {
	    /*
	     * TODO: use attemptckalloc() here once there is a strategy that
	     * will allow us to recover from failure. Right now, there's no
	     * such possibility.
	     */

	    newError = (schar *)ckalloc(modelPtr->height * modelPtr->width
	    newError = ckalloc(masterPtr->height * masterPtr->width
		    * 3 * sizeof(schar));

	    /*
	     * Zero the new array so that we don't get bogus error values
	     * propagating into areas we dither later.
	     */

	    if ((instancePtr->error != NULL)
		    && ((instancePtr->width == modelPtr->width)
		    || (validBox.width == modelPtr->width))) {
		    && ((instancePtr->width == masterPtr->width)
		    || (validBox.width == masterPtr->width))) {
		if (validBox.y > 0) {
		    memset(newError, 0, (size_t)
			    validBox.y * modelPtr->width * 3 * sizeof(schar));
			    validBox.y * masterPtr->width * 3 * sizeof(schar));
		}
		h = validBox.y + validBox.height;
		if (h < modelPtr->height) {
		    memset(newError + h*modelPtr->width*3, 0,
			    (size_t) (modelPtr->height - h)
			    * modelPtr->width * 3 * sizeof(schar));
		if (h < masterPtr->height) {
		    memset(newError + h*masterPtr->width*3, 0,
			    (size_t) (masterPtr->height - h)
			    * masterPtr->width * 3 * sizeof(schar));
		}
	    } else {
		memset(newError, 0, (size_t)
			modelPtr->height * modelPtr->width *3*sizeof(schar));
			masterPtr->height * masterPtr->width *3*sizeof(schar));
	    }
	} else {
	    newError = NULL;
	}

	if (instancePtr->error != NULL) {
	    /*
	     * Copy the common area over to the new array and free the old
	     * array.
	     */

	    if (modelPtr->width == instancePtr->width) {
		offset = validBox.y * modelPtr->width * 3;
	    if (masterPtr->width == instancePtr->width) {
		offset = validBox.y * masterPtr->width * 3;
		memcpy(newError + offset, instancePtr->error + offset,
			(size_t) validBox.height
			* modelPtr->width * 3 * sizeof(schar));
			(size_t) (validBox.height
			* masterPtr->width * 3 * sizeof(schar)));

	    } else if (validBox.width > 0 && validBox.height > 0) {
		errDestPtr = newError +
			(validBox.y * modelPtr->width + validBox.x) * 3;
			(validBox.y * masterPtr->width + validBox.x) * 3;
		errSrcPtr = instancePtr->error +
			(validBox.y * instancePtr->width + validBox.x) * 3;

		for (h = validBox.height; h > 0; --h) {
		    memcpy(errDestPtr, errSrcPtr,
			    validBox.width * 3 * sizeof(schar));
		    errDestPtr += modelPtr->width * 3;
		    errDestPtr += masterPtr->width * 3;
		    errSrcPtr += instancePtr->width * 3;
		}
	    }
	    ckfree(instancePtr->error);
	}

	instancePtr->error = newError;
    }

    instancePtr->width = modelPtr->width;
    instancePtr->height = modelPtr->height;
    instancePtr->width = masterPtr->width;
    instancePtr->height = masterPtr->height;
}

/*
 *----------------------------------------------------------------------
 *
 * IsValidPalette --
 *
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
933
934
935
936
937
938
939

940
941
942
943
944
945
946
947







-
+







	if ((endp == palette) || (*endp != 0) || (nBlue < 2)
		|| (nBlue > 256)) {
	    return 0;
	}
	mono = 0;
    }

    switch (instancePtr->visualInfo.c_class) {
    switch (instancePtr->visualInfo.class) {
    case DirectColor:
    case TrueColor:
	if ((nRed > (1 << CountBits(instancePtr->visualInfo.red_mask)))
		|| (nGreen>(1<<CountBits(instancePtr->visualInfo.green_mask)))
		|| (nBlue>(1<<CountBits(instancePtr->visualInfo.blue_mask)))) {
	    return 0;
	}
1024
1025
1026
1027
1028
1029
1030
1031

1032
1033
1034
1035
1036
1037
1038
981
982
983
984
985
986
987

988
989
990
991
992
993
994
995







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
CountBits(
    unsigned mask)			/* Value to count the 1 bits in. */
    pixel mask)			/* Value to count the 1 bits in. */
{
    int n;

    for (n=0 ; mask!=0 ; mask&=mask-1) {
	n++;
    }
    return n;
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063







-
+





-
+







    entry = Tcl_CreateHashEntry(&imgPhotoColorHash, (char *) &id, &isNew);

    if (!isNew) {
	/*
	 * Re-use the existing entry.
	 */

	colorPtr = (ColorTable *)Tcl_GetHashValue(entry);
	colorPtr = Tcl_GetHashValue(entry);
    } else {
	/*
	 * No color table currently available; need to make one.
	 */

	colorPtr = (ColorTable *)ckalloc(sizeof(ColorTable));
	colorPtr = ckalloc(sizeof(ColorTable));

	/*
	 * The following line of code should not normally be needed due to the
	 * assignment in the following line. However, it compensates for bugs
	 * in some compilers (HP, for example) where sizeof(ColorTable) is 24
	 * but the assignment only copies 20 bytes, leaving 4 bytes
	 * uninitialized; these cause problems when using the id for lookups
1156
1157
1158
1159
1160
1161
1162

1163

1164
1165
1166
1167
1168
1169
1170
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128







+
-
+








static void
FreeColorTable(
    ColorTable *colorPtr,	/* Pointer to the color table which is no
				 * longer required by an instance. */
    int force)			/* Force free to happen immediately. */
{
    colorPtr->refCount--;
    if (colorPtr->refCount-- > 1) {
    if (colorPtr->refCount > 0) {
	return;
    }

    if (force) {
	if (colorPtr->flags & DISPOSE_PENDING) {
	    Tcl_CancelIdleCall(DisposeColorTable, colorPtr);
	    colorPtr->flags &= ~DISPOSE_PENDING;
1240
1241
1242
1243
1244
1245
1246
1247
1248


1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1198
1199
1200
1201
1202
1203
1204


1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243
1244
1245







-
-
+
+











-
+



















-
+







	}

	/*
	 * Calculate the RGB coordinates of the colors we want to allocate and
	 * store them in *colors.
	 */

	if ((colorPtr->visualInfo.c_class == DirectColor)
		|| (colorPtr->visualInfo.c_class == TrueColor)) {
	if ((colorPtr->visualInfo.class == DirectColor)
		|| (colorPtr->visualInfo.class == TrueColor)) {

	    /*
	     * Direct/True Color: allocate shades of red, green, blue
	     * independently.
	     */

	    if (mono) {
		numColors = nGreen = nBlue = nRed;
	    } else {
		numColors = MAX(MAX(nRed, nGreen), nBlue);
	    }
	    colors = (XColor *)ckalloc(numColors * sizeof(XColor));
	    colors = ckalloc(numColors * sizeof(XColor));

	    for (i = 0; i < numColors; ++i) {
		if (igam == 1.0) {
		    colors[i].red = CFRAC(i, nRed - 1);
		    colors[i].green = CFRAC(i, nGreen - 1);
		    colors[i].blue = CFRAC(i, nBlue - 1);
		} else {
		    colors[i].red = CGFRAC(i, nRed - 1, igam);
		    colors[i].green = CGFRAC(i, nGreen - 1, igam);
		    colors[i].blue = CGFRAC(i, nBlue - 1, igam);
		}
	    }
	} else {
	    /*
	     * PseudoColor, StaticColor, GrayScale or StaticGray visual: we
	     * have to allocate each color in the color cube separately.
	     */

	    numColors = (mono) ? nRed: (nRed * nGreen * nBlue);
	    colors = (XColor *)ckalloc(numColors * sizeof(XColor));
	    colors = ckalloc(numColors * sizeof(XColor));

	    if (!mono) {
		/*
		 * Color display using a PseudoColor or StaticColor visual.
		 */

		i = 0;
1317
1318
1319
1320
1321
1322
1323
1324

1325
1326
1327
1328
1329
1330
1331
1275
1276
1277
1278
1279
1280
1281

1282
1283
1284
1285
1286
1287
1288
1289







-
+







	    }
	}

	/*
	 * Now try to allocate the colors we've calculated.
	 */

	pixels = (unsigned long *)ckalloc(numColors * sizeof(unsigned long));
	pixels = ckalloc(numColors * sizeof(unsigned long));
	for (i = 0; i < numColors; ++i) {
	    if (!XAllocColor(colorPtr->id.display, colorPtr->id.colormap,
		    &colors[i])) {
		/*
		 * Can't get all the colors we want in the default colormap;
		 * first try freeing colors from other unused color tables.
		 */
1395
1396
1397
1398
1399
1400
1401
1402
1403


1404
1405
1406
1407
1408
1409
1410
1353
1354
1355
1356
1357
1358
1359


1360
1361
1362
1363
1364
1365
1366
1367
1368







-
-
+
+







	 * The following is a hairy hack. We only want to index into the
	 * pixelMap on colormap displays. However, if the display is on
	 * Windows, then we actually want to store the index not the value
	 * since we will be passing the color table into the TkPutImage call.
	 */

#ifndef _WIN32
	if ((colorPtr->visualInfo.c_class != DirectColor)
		&& (colorPtr->visualInfo.c_class != TrueColor)) {
	if ((colorPtr->visualInfo.class != DirectColor)
		&& (colorPtr->visualInfo.class != TrueColor)) {
	    colorPtr->flags |= MAP_COLORS;
	}
#endif /* _WIN32 */
    }

    colorPtr->numColors = numColors;
    colorPtr->pixelMap = pixels;
1422
1423
1424
1425
1426
1427
1428
1429
1430


1431
1432
1433
1434
1435
1436
1437
1380
1381
1382
1383
1384
1385
1386


1387
1388
1389
1390
1391
1392
1393
1394
1395







-
-
+
+







		fr = pow(fr, colorPtr->id.gamma);
	    }
	    colorPtr->colorQuant[0][i] = (int)(fr * 255.99);
	    colorPtr->redValues[i] = colors[r].pixel;
	} else {
	    g = (i * (nGreen - 1) + 127) / 255;
	    b = (i * (nBlue - 1) + 127) / 255;
	    if ((colorPtr->visualInfo.c_class == DirectColor)
		    || (colorPtr->visualInfo.c_class == TrueColor)) {
	    if ((colorPtr->visualInfo.class == DirectColor)
		    || (colorPtr->visualInfo.class == TrueColor)) {
		colorPtr->redValues[i] =
			colors[r].pixel & colorPtr->visualInfo.red_mask;
		colorPtr->greenValues[i] =
			colors[g].pixel & colorPtr->visualInfo.green_mask;
		colorPtr->blueValues[i] =
			colors[b].pixel & colorPtr->visualInfo.blue_mask;
	    } else {
1474
1475
1476
1477
1478
1479
1480
1481

1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441

1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1461







-
+


-
+











-
+







 *	which is used to locate color tables.
 *
 *----------------------------------------------------------------------
 */

static void
DisposeColorTable(
    void *clientData)	/* Pointer to the ColorTable whose
    ClientData clientData)	/* Pointer to the ColorTable whose
				 * colors are to be released. */
{
    ColorTable *colorPtr = (ColorTable *)clientData;
    ColorTable *colorPtr = clientData;
    Tcl_HashEntry *entry;

    if (colorPtr->pixelMap != NULL) {
	if (colorPtr->numColors > 0) {
	    XFreeColors(colorPtr->id.display, colorPtr->id.colormap,
		    colorPtr->pixelMap, colorPtr->numColors, 0);
	    Tk_FreeColormap(colorPtr->id.display, colorPtr->id.colormap);
	}
	ckfree(colorPtr->pixelMap);
    }

    entry = Tcl_FindHashEntry(&imgPhotoColorHash, &colorPtr->id);
    entry = Tcl_FindHashEntry(&imgPhotoColorHash, (char *) &colorPtr->id);
    if (entry == NULL) {
	Tcl_Panic("DisposeColorTable couldn't find hash entry");
    }
    Tcl_DeleteHashEntry(entry);

    ckfree(colorPtr);
}
1537
1538
1539
1540
1541
1542
1543
1544

1545
1546
1547
1548
1549
1550
1551
1495
1496
1497
1498
1499
1500
1501

1502
1503
1504
1505
1506
1507
1508
1509







-
+







    /*
     * First scan through the color hash table to get an upper bound on how
     * many colors we might be able to free.
     */

    entry = Tcl_FirstHashEntry(&imgPhotoColorHash, &srch);
    while (entry != NULL) {
	colorPtr = (ColorTable *)Tcl_GetHashValue(entry);
	colorPtr = Tcl_GetHashValue(entry);
	if ((colorPtr->id.display == id->display)
		&& (colorPtr->id.colormap == id->colormap)
		&& (colorPtr->liveRefCount == 0 )&& (colorPtr->numColors != 0)
		&& ((colorPtr->id.palette != id->palette)
			|| (colorPtr->id.gamma != id->gamma))) {
	    /*
	     * We could take this guy's colors off him.
1566
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538







-
+








    /*
     * Scan through a second time freeing colors.
     */

    entry = Tcl_FirstHashEntry(&imgPhotoColorHash, &srch);
    while ((entry != NULL) && (numColors > 0)) {
	colorPtr = (ColorTable *)Tcl_GetHashValue(entry);
	colorPtr = Tcl_GetHashValue(entry);
	if ((colorPtr->id.display == id->display)
		&& (colorPtr->id.colormap == id->colormap)
		&& (colorPtr->liveRefCount == 0) && (colorPtr->numColors != 0)
		&& ((colorPtr->id.palette != id->palette)
			|| (colorPtr->id.gamma != id->gamma))) {
	    /*
	     * Free the colors that this ColorTable has.
1608
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618

1619
1620
1621
1622
1623
1624

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638


1639
1640

1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656

1657
1658
1659
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
1566
1567
1568
1569
1570
1571
1572

1573
1574
1575

1576
1577
1578
1579
1580
1581

1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594


1595
1596
1597

1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613

1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637
1638

1639
1640
1641
1642
1643
1644
1645


1646
1647
1648
1649
1650
1651
1652
1653
1654







-
+


-
+





-
+












-
-
+
+

-
+















-
+

















-
+






-
+






-
-
+
+







 *	The instance data structure and the resources it references are freed.
 *
 *----------------------------------------------------------------------
 */

void
TkImgDisposeInstance(
    void *clientData)	/* Pointer to the instance whose resources are
    ClientData clientData)	/* Pointer to the instance whose resources are
				 * to be released. */
{
    PhotoInstance *instancePtr = (PhotoInstance *)clientData;
    PhotoInstance *instancePtr = clientData;
    PhotoInstance *prevPtr;

    if (instancePtr->pixels != None) {
	Tk_FreePixmap(instancePtr->display, instancePtr->pixels);
    }
    if (instancePtr->gc != NULL) {
    if (instancePtr->gc != None) {
	Tk_FreeGC(instancePtr->display, instancePtr->gc);
    }
    if (instancePtr->imagePtr != NULL) {
	XDestroyImage(instancePtr->imagePtr);
    }
    if (instancePtr->error != NULL) {
	ckfree(instancePtr->error);
    }
    if (instancePtr->colorTablePtr != NULL) {
	FreeColorTable(instancePtr->colorTablePtr, 1);
    }

    if (instancePtr->modelPtr->instancePtr == instancePtr) {
	instancePtr->modelPtr->instancePtr = instancePtr->nextPtr;
    if (instancePtr->masterPtr->instancePtr == instancePtr) {
	instancePtr->masterPtr->instancePtr = instancePtr->nextPtr;
    } else {
	for (prevPtr = instancePtr->modelPtr->instancePtr;
	for (prevPtr = instancePtr->masterPtr->instancePtr;
		prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) {
	    /* Empty loop body. */
	}
	prevPtr->nextPtr = instancePtr->nextPtr;
    }
    Tk_FreeColormap(instancePtr->display, instancePtr->colormap);
    ckfree(instancePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkImgDitherInstance --
 *
 *	This function is called to update an area of an instance's pixmap by
 *	dithering the corresponding area of the model.
 *	dithering the corresponding area of the master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The instance's pixmap gets updated.
 *
 *----------------------------------------------------------------------
 */

void
TkImgDitherInstance(
    PhotoInstance *instancePtr,	/* The instance to be updated. */
    int xStart, int yStart,	/* Coordinates of the top-left pixel in the
				 * block to be dithered. */
    int width, int height)	/* Dimensions of the block to be dithered. */
{
    PhotoModel *modelPtr = instancePtr->modelPtr;
    PhotoMaster *masterPtr = instancePtr->masterPtr;
    ColorTable *colorPtr = instancePtr->colorTablePtr;
    XImage *imagePtr;
    int nLines, bigEndian, i, c, x, y, xEnd, doDithering = 1;
    int bitsPerPixel, bytesPerLine, lineLength;
    unsigned char *srcLinePtr;
    schar *errLinePtr;
    unsigned firstBit, word, mask;
    pixel firstBit, word, mask;

    /*
     * Turn dithering off in certain cases where it is not needed (TrueColor,
     * DirectColor with many colors).
     */

    if ((colorPtr->visualInfo.c_class == DirectColor)
	    || (colorPtr->visualInfo.c_class == TrueColor)) {
    if ((colorPtr->visualInfo.class == DirectColor)
	    || (colorPtr->visualInfo.class == TrueColor)) {
	int nRed, nGreen, nBlue, result;

	result = sscanf(colorPtr->id.palette, "%d/%d/%d", &nRed,
		&nGreen, &nBlue);
	if ((nRed >= 256)
		&& ((result == 1) || ((nGreen >= 256) && (nBlue >= 256)))) {
	    doDithering = 0;
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
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







-
+



-
-
+
+




















-
+







    imagePtr->bytes_per_line = bytesPerLine;

    /*
     * TODO: use attemptckalloc() here once we have some strategy for
     * recovering from the failure.
     */

    imagePtr->data = (char *)ckalloc(imagePtr->bytes_per_line * nLines);
    imagePtr->data = ckalloc(imagePtr->bytes_per_line * nLines);
    bigEndian = imagePtr->bitmap_bit_order == MSBFirst;
    firstBit = bigEndian? (1 << (imagePtr->bitmap_unit - 1)): 1;

    lineLength = modelPtr->width * 3;
    srcLinePtr = modelPtr->pix32 + (yStart * modelPtr->width + xStart) * 4;
    lineLength = masterPtr->width * 3;
    srcLinePtr = masterPtr->pix32 + (yStart * masterPtr->width + xStart) * 4;
    errLinePtr = instancePtr->error + yStart * lineLength + xStart * 3;
    xEnd = xStart + width;

    /*
     * Loop over the image, doing at most nLines lines before updating the
     * screen image.
     */

    for (; height > 0; height -= nLines) {
	unsigned char *dstLinePtr = (unsigned char *) imagePtr->data;
	int yEnd;

	if (nLines > height) {
	    nLines = height;
	}
	yEnd = yStart + nLines;
	for (y = yStart; y < yEnd; ++y) {
	    unsigned char *srcPtr = srcLinePtr;
	    schar *errPtr = errLinePtr;
	    unsigned char *destBytePtr = dstLinePtr;
	    unsigned *destLongPtr = (unsigned *) dstLinePtr;
	    pixel *destLongPtr = (pixel *) dstLinePtr;

	    if (colorPtr->flags & COLOR_WINDOW) {
		/*
		 * Color window. We dither the three components independently,
		 * using Floyd-Steinberg dithering, which propagates errors
		 * from the quantization of pixels to the pixels below and to
		 * the right.
1781
1782
1783
1784
1785
1786
1787
1788

1789
1790
1791
1792
1793
1794
1795
1739
1740
1741
1742
1743
1744
1745

1746
1747
1748
1749
1750
1751
1752
1753







-
+








			    c = (x > 0) ? errPtr[-3] * 7: 0;
			    if (y > 0) {
				if (x > 0) {
				    c += errPtr[-lineLength-3];
				}
				c += errPtr[-lineLength] * 5;
				if ((x + 1) < modelPtr->width) {
				if ((x + 1) < masterPtr->width) {
				    c += errPtr[-lineLength+3] * 3;
				}
			    }

			    /*
			     * Add the propagated error to the value of this
			     * component, quantize it, and store the
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
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







-
+













-
+











-
+





-
+







			 * image format is different from the pixel format in
			 * Win32. Eventually we need to fix the image code in
			 * Tk to use the Windows native image ordering. This
			 * would speed up the image code for all of the common
			 * sizes.
			 */

		    case NBBY * sizeof(unsigned):
		    case NBBY * sizeof(pixel):
			*destLongPtr++ = i;
			break;
#endif
		    default:
			XPutPixel(imagePtr, x - xStart, y - yStart,
				(unsigned) i);
		    }
		}

	    } else if (bitsPerPixel > 1) {
		/*
		 * Multibit monochrome window. The operation here is similar
		 * to the color window case above, except that there is only
		 * one component. If the model image is in color, use the
		 * one component. If the master image is in color, use the
		 * luminance computed as
		 *	0.344 * red + 0.5 * green + 0.156 * blue.
		 */

		for (x = xStart; x < xEnd; ++x) {
		    c = (x > 0) ? errPtr[-1] * 7: 0;
		    if (y > 0) {
			if (x > 0) {
			    c += errPtr[-lineLength-1];
			}
			c += errPtr[-lineLength] * 5;
			if (x + 1 < modelPtr->width) {
			if (x + 1 < masterPtr->width) {
			    c += errPtr[-lineLength+1] * 3;
			}
		    }
		    c = ((c + 2056) >> 4) - 128;

		    if (modelPtr->flags & COLOR_IMAGE) {
		    if (masterPtr->flags & COLOR_IMAGE) {
			c += (unsigned) (srcPtr[0] * 11 + srcPtr[1] * 16
				+ srcPtr[2] * 5 + 16) >> 5;
		    } else {
			c += srcPtr[0];
		    }
		    srcPtr += 4;

1900
1901
1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
1858
1859
1860
1861
1862
1863
1864

1865
1866
1867
1868
1869
1870
1871
1872







-
+







			 * image format is different from the pixel format in
			 * Win32. Eventually we need to fix the image code in
			 * Tk to use the Windows native image ordering. This
			 * would speed up the image code for all of the common
			 * sizes.
			 */

		    case NBBY * sizeof(unsigned):
		    case NBBY * sizeof(pixel):
			*destLongPtr++ = i;
			break;
#endif
		    default:
			XPutPixel(imagePtr, x - xStart, y - yStart,
				(unsigned) i);
		    }
1937
1938
1939
1940
1941
1942
1943
1944

1945
1946
1947
1948
1949
1950

1951
1952
1953
1954
1955
1956
1957
1895
1896
1897
1898
1899
1900
1901

1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
1915







-
+





-
+








		    c = (x > 0) ? errPtr[-1] * 7: 0;
		    if (y > 0) {
			if (x > 0) {
			    c += errPtr[-lineLength-1];
			}
			c += errPtr[-lineLength] * 5;
			if (x + 1 < modelPtr->width) {
			if (x + 1 < masterPtr->width) {
			    c += errPtr[-lineLength+1] * 3;
			}
		    }
		    c = ((c + 2056) >> 4) - 128;

		    if (modelPtr->flags & COLOR_IMAGE) {
		    if (masterPtr->flags & COLOR_IMAGE) {
			c += (unsigned)(srcPtr[0] * 11 + srcPtr[1] * 16
				+ srcPtr[2] * 5 + 16) >> 5;
		    } else {
			c += srcPtr[0];
		    }
		    srcPtr += 4;

1966
1967
1968
1969
1970
1971
1972
1973

1974
1975
1976
1977
1978
1979
1980
1924
1925
1926
1927
1928
1929
1930

1931
1932
1933
1934
1935
1936
1937
1938







-
+







		    } else {
			*errPtr++ = c;
		    }
		    mask = bigEndian? (mask >> 1): (mask << 1);
		}
		*destLongPtr = word;
	    }
	    srcLinePtr += modelPtr->width * 4;
	    srcLinePtr += masterPtr->width * 4;
	    errLinePtr += lineLength;
	    dstLinePtr += bytesPerLine;
	}

	/*
	 * Update the pixmap for this instance with the block of pixels that
	 * we have just computed.
2010
2011
2012
2013
2014
2015
2016
2017
2018


2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
1968
1969
1970
1971
1972
1973
1974


1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986







-
-
+
+











void
TkImgResetDither(
    PhotoInstance *instancePtr)
{
    if (instancePtr->error) {
	memset(instancePtr->error, 0,
		(size_t) instancePtr->modelPtr->width
		* instancePtr->modelPtr->height * 3 * sizeof(schar));
	       /*(size_t)*/ (instancePtr->masterPtr->width
		* instancePtr->masterPtr->height * 3 * sizeof(schar)));
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkImgPhoto.c.

1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
1
2
3
4
5
6
7




8
9
10
11
12
13
14
15
16
17
18







-
-
-
-
+
+
+
+







/*
 * tkImgPhoto.c --
 *
 *	Implements images of type "photo" for Tk. Photo images are stored in
 *	full color (32 bits per pixel including alpha channel) and displayed
 *	using dithering if necessary.
 *
 * Copyright © 1994 The Australian National University.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2002-2003 Donal K. Fellows
 * Copyright © 2003 ActiveState Corporation.
 * Copyright (c) 1994 The Australian National University.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2002-2003 Donal K. Fellows
 * Copyright (c) 2003 ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * Author: Paul Mackerras ([email protected]),
 *	   Department of Computer Science,
 *	   Australian National University.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77





78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69






70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94







-















-













-
-
-
-
-
-
+
+
+
+
+













-







    int toX2, toY2;		/* Second coordinate pair for -to option. */
    int zoomX, zoomY;		/* Values specified for -zoom option. */
    int subsampleX, subsampleY;	/* Values specified for -subsample option. */
    Tcl_Obj *format;		/* Value specified for -format option. */
    XColor *background;		/* Value specified for -background option. */
    int compositingRule;	/* Value specified for -compositingrule
				 * option. */
    Tcl_Obj *metadata;		/* Value specified for -metadata option. */
};

/*
 * Bit definitions for use with ParseSubcommandOptions: each bit is set in the
 * allowedOptions parameter on a call to ParseSubcommandOptions if that option
 * is allowed for the current photo image subcommand. On return, the bit is
 * set in the options field of the SubcommandOptions structure if that option
 * was specified.
 *
 * OPT_ALPHA:			Set if -alpha option allowed/specified.
 * OPT_BACKGROUND:		Set if -format option allowed/specified.
 * OPT_COMPOSITE:		Set if -compositingrule option allowed/spec'd.
 * OPT_FORMAT:			Set if -format option allowed/specified.
 * OPT_FROM:			Set if -from option allowed/specified.
 * OPT_GRAYSCALE:		Set if -grayscale option allowed/specified.
 * OPT_METADATA:		Set if -metadata option allowed/specified.
 * OPT_SHRINK:			Set if -shrink option allowed/specified.
 * OPT_SUBSAMPLE:		Set if -subsample option allowed/spec'd.
 * OPT_TO:			Set if -to option allowed/specified.
 * OPT_WITHALPHA:		Set if -withalpha option allowed/specified.
 * OPT_ZOOM:			Set if -zoom option allowed/specified.
 */

#define OPT_ALPHA	1
#define OPT_BACKGROUND	2
#define OPT_COMPOSITE	4
#define OPT_FORMAT	8
#define OPT_FROM	0x10
#define OPT_GRAYSCALE	0x20
#define OPT_METADATA	0x40
#define OPT_SHRINK	0x80
#define OPT_SUBSAMPLE	0x100
#define OPT_TO		0x200
#define OPT_WITHALPHA	0x400
#define OPT_ZOOM	0x800
#define OPT_SHRINK	0x40
#define OPT_SUBSAMPLE	0x80
#define OPT_TO		0x100
#define OPT_WITHALPHA	0x200
#define OPT_ZOOM	0x400

/*
 * List of option names. The order here must match the order of declarations
 * of the OPT_* constants above.
 */

static const char *const optionNames[] = {
    "-alpha",
    "-background",
    "-compositingrule",
    "-format",
    "-from",
    "-grayscale",
    "-metadata",
    "-shrink",
    "-subsample",
    "-to",
    "-withalpha",
    "-zoom",
    NULL
};
106
107
108
109
110
111
112
113
114
115
116
117





118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142

143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171

172
173

174
175
176
177

178
179

180
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196




197
198
199


200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
102
103
104
105
106
107
108





109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137

138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159


160

161


162

163
164

165


166

167
168

169
170
171
172
173
174
175
176


177
178
179
180
181
182




183
184
185
186
187


188
189
190

191
192
193
194
195


196

197
198
199


200

201
202
203
204
205
206
207







-
-
-
-
-
+
+
+
+
+




















-
+



-
+

-
+



















-
-

-
+
-
-

-
+

-
+
-
-

-
+

-
+







-
-
+
+




-
-
-
-
+
+
+
+

-
-
+
+

-
+




-
-

-



-
-

-







	"not enough free memory for image buffer"

/*
 * Functions used in the type record for photo images.
 */

static int		ImgPhotoCreate(Tcl_Interp *interp, const char *name,
			    Tcl_Size objc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageModel model,
			    void **clientDataPtr);
static void		ImgPhotoDelete(void *clientData);
static int		ImgPhotoPostscript(void *clientData,
			    int objc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageMaster master,
			    ClientData *clientDataPtr);
static void		ImgPhotoDelete(ClientData clientData);
static int		ImgPhotoPostscript(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_PostscriptInfo psInfo, int x, int y, int width,
			    int height, int prepass);

/*
 * The type record itself for photo images:
 */

Tk_ImageType tkPhotoImageType = {
    "photo",			/* name */
    ImgPhotoCreate,		/* createProc */
    TkImgPhotoGet,		/* getProc */
    TkImgPhotoDisplay,		/* displayProc */
    TkImgPhotoFree,		/* freeProc */
    ImgPhotoDelete,		/* deleteProc */
    ImgPhotoPostscript,		/* postscriptProc */
    NULL,			/* nextPtr */
    NULL
};

typedef struct {
typedef struct ThreadSpecificData {
    Tk_PhotoImageFormat *formatList;
				/* Pointer to the first in the list of known
				 * photo image formats.*/
    Tk_PhotoImageFormatVersion3 *formatListVersion3;
    Tk_PhotoImageFormat *oldFormatList;
				/* Pointer to the first in the list of known
				 * photo image formats in Version3 format.*/
				 * photo image formats.*/
    int initialized;		/* Set to 1 if we've initialized the
				 * structure. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Default configuration
 */

#define DEF_PHOTO_GAMMA		"1"
#define DEF_PHOTO_HEIGHT	"0"
#define DEF_PHOTO_PALETTE	""
#define DEF_PHOTO_WIDTH		"0"

/*
 * Information used for parsing configuration specifications:
 */

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_STRING, "-data", NULL, NULL,
	 NULL, TCL_INDEX_NONE, TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_STRING, "-file", NULL, NULL,
	 NULL, offsetof(PhotoModel, fileString), TK_CONFIG_NULL_OK, NULL},
	 NULL, Tk_Offset(PhotoMaster, fileString), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_STRING, "-format", NULL, NULL,
	 NULL, TCL_INDEX_NONE, TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_DOUBLE, "-gamma", NULL, NULL,
	 DEF_PHOTO_GAMMA, offsetof(PhotoModel, gamma), 0, NULL},
	 DEF_PHOTO_GAMMA, Tk_Offset(PhotoMaster, gamma), 0, NULL},
    {TK_CONFIG_INT, "-height", NULL, NULL,
	 DEF_PHOTO_HEIGHT, offsetof(PhotoModel, userHeight), 0, NULL},
	 DEF_PHOTO_HEIGHT, Tk_Offset(PhotoMaster, userHeight), 0, NULL},
    {TK_CONFIG_STRING, "-metadata", NULL, NULL,
	 NULL, TCL_INDEX_NONE, TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_UID, "-palette", NULL, NULL,
	 DEF_PHOTO_PALETTE, offsetof(PhotoModel, palette), 0, NULL},
	 DEF_PHOTO_PALETTE, Tk_Offset(PhotoMaster, palette), 0, NULL},
    {TK_CONFIG_INT, "-width", NULL, NULL,
	 DEF_PHOTO_WIDTH, offsetof(PhotoModel, userWidth), 0, NULL},
	 DEF_PHOTO_WIDTH, Tk_Offset(PhotoMaster, userWidth), 0, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Forward declarations
 */

static void		PhotoFormatThreadExitProc(void *clientData);
static int		ImgPhotoCmd(void *clientData, Tcl_Interp *interp,
static void		PhotoFormatThreadExitProc(ClientData clientData);
static int		ImgPhotoCmd(ClientData clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		ParseSubcommandOptions(
			    struct SubcommandOptions *optPtr,
			    Tcl_Interp *interp, int allowedOptions,
			    Tcl_Size *indexPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
static void		ImgPhotoCmdDeletedProc(void *clientData);
static int		ImgPhotoConfigureModel(Tcl_Interp *interp,
			    PhotoModel *modelPtr, Tcl_Size objc,
			    int *indexPtr, int objc, Tcl_Obj *const objv[]);
static void		ImgPhotoCmdDeletedProc(ClientData clientData);
static int		ImgPhotoConfigureMaster(Tcl_Interp *interp,
			    PhotoMaster *masterPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static int		ToggleComplexAlphaIfNeeded(PhotoModel *mPtr);
static int		ImgPhotoSetSize(PhotoModel *modelPtr, int width,
static int		ToggleComplexAlphaIfNeeded(PhotoMaster *mPtr);
static int		ImgPhotoSetSize(PhotoMaster *masterPtr, int width,
			    int height);
static char *		ImgGetPhoto(PhotoModel *modelPtr,
static char *		ImgGetPhoto(PhotoMaster *masterPtr,
			    Tk_PhotoImageBlock *blockPtr,
			    struct SubcommandOptions *optPtr);
static int		MatchFileFormat(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *formatString,
			    Tcl_Obj *metadataInObj,
			    Tcl_Obj *metadataOutObj,
			    Tk_PhotoImageFormat **imageFormatPtr,
			    Tk_PhotoImageFormatVersion3 **imageFormatVersion3Ptr,
			    int *widthPtr, int *heightPtr, int *oldformat);
static int		MatchStringFormat(Tcl_Interp *interp, Tcl_Obj *data,
			    Tcl_Obj *formatString,
			    Tcl_Obj *metadataInObj,
			    Tcl_Obj *metadataOutObj,
			    Tk_PhotoImageFormat **imageFormatPtr,
			    Tk_PhotoImageFormatVersion3 **imageFormatVersion3Ptr,
			    int *widthPtr, int *heightPtr, int *oldformat);
static const char *	GetExtension(const char *path);

/*
 *----------------------------------------------------------------------
 *
 * PhotoFormatThreadExitProc --
231
232
233
234
235
236
237
238

239
240
241
242

243
244





245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277





















278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294

295
296




297
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
215
216
217
218
219
220
221

222
223
224


225
226
227
228
229
230
231
232
233
234
235

236
237
238






239
240
241
242
243

244

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295

296
297

298
299
300
301
302

303
304
305
306
307
308
309


























310
311
312
313
314
315
316







-
+


-
-
+


+
+
+
+
+



-
+


-
-
-
-
-
-





-
+
-














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+






-
+

-
+
+
+
+

-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	The thread's linked lists of photo image formats is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
PhotoFormatThreadExitProc(
    TCL_UNUSED(void *))	/* not used */
    ClientData clientData)	/* not used */
{
    Tk_PhotoImageFormat *freePtr;
    Tk_PhotoImageFormatVersion3 *freePtrVersion3;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    while (tsdPtr->oldFormatList != NULL) {
	freePtr = tsdPtr->oldFormatList;
	tsdPtr->oldFormatList = tsdPtr->oldFormatList->nextPtr;
	ckfree(freePtr);
    }
    while (tsdPtr->formatList != NULL) {
	freePtr = tsdPtr->formatList;
	tsdPtr->formatList = tsdPtr->formatList->nextPtr;
	ckfree((void *)freePtr->name);
	ckfree((char *)freePtr->name);
	ckfree(freePtr);
    }
    while (tsdPtr->formatListVersion3 != NULL) {
	freePtrVersion3 = tsdPtr->formatListVersion3;
	tsdPtr->formatListVersion3 = tsdPtr->formatListVersion3->nextPtr;
	ckfree((void *)freePtrVersion3->name);
	ckfree(freePtrVersion3);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_CreatePhotoImageFormat,
 * Tk_CreateOldPhotoImageFormat, Tk_CreatePhotoImageFormat --
 * Tk_CreatePhotoImageFormatVersion3 --
 *
 *	This function is invoked by an image file handler to register a new
 *	photo image format and the functions that handle the new format. The
 *	function is typically invoked during Tcl_AppInit.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The new image file format is entered into a table used in the photo
 *	image "read" and "write" subcommands.
 *
 *----------------------------------------------------------------------
 */

void
Tk_CreateOldPhotoImageFormat(
    const Tk_PhotoImageFormat *formatPtr)
				/* Structure describing the format. All of the
				 * fields except "nextPtr" must be filled in
				 * by caller. */
{
    Tk_PhotoImageFormat *copyPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	Tcl_CreateThreadExitHandler(PhotoFormatThreadExitProc, NULL);
    }
    copyPtr = ckalloc(sizeof(Tk_PhotoImageFormat));
    *copyPtr = *formatPtr;
    copyPtr->nextPtr = tsdPtr->oldFormatList;
    tsdPtr->oldFormatList = copyPtr;
}

void
Tk_CreatePhotoImageFormat(
    const Tk_PhotoImageFormat *formatPtr)
				/* Structure describing the format. All of the
				 * fields except "nextPtr" must be filled in
				 * by caller. */
{
    Tk_PhotoImageFormat *copyPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	Tcl_CreateThreadExitHandler(PhotoFormatThreadExitProc, NULL);
    }
    copyPtr = (Tk_PhotoImageFormat *)ckalloc(sizeof(Tk_PhotoImageFormat));
    copyPtr = ckalloc(sizeof(Tk_PhotoImageFormat));
    *copyPtr = *formatPtr;
    {
    if (isupper((unsigned char) *formatPtr->name)) {
	copyPtr->nextPtr = tsdPtr->oldFormatList;
	tsdPtr->oldFormatList = copyPtr;
    } else {
	/* for compatibility with aMSN: make a copy of formatPtr->name */
	char *name = (char *)ckalloc(strlen(formatPtr->name) + 1);
	char *name = ckalloc(strlen(formatPtr->name) + 1);
	strcpy(name, formatPtr->name);
	copyPtr->name = name;
	copyPtr->nextPtr = tsdPtr->formatList;
	tsdPtr->formatList = copyPtr;
    }
}
void
Tk_CreatePhotoImageFormatVersion3(
    const Tk_PhotoImageFormatVersion3 *formatPtr)
				/* Structure describing the format. All of the
				 * fields except "nextPtr" must be filled in
				 * by caller. */
{
    Tk_PhotoImageFormatVersion3 *copyPtr;
    char *name;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	Tcl_CreateThreadExitHandler(PhotoFormatThreadExitProc, NULL);
    }
    copyPtr = (Tk_PhotoImageFormatVersion3 *)
	    ckalloc(sizeof(Tk_PhotoImageFormatVersion3));
    *copyPtr = *formatPtr;
    /* for compatibility with aMSN: make a copy of formatPtr->name */
    name = (char *)ckalloc(strlen(formatPtr->name) + 1);
    strcpy(name, formatPtr->name);
    copyPtr->name = name;
    copyPtr->nextPtr = tsdPtr->formatListVersion3;
    tsdPtr->formatListVersion3 = copyPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoCreate --
 *
 *	This function is called by the Tk image code to create a new photo
347
348
349
350
351
352
353
354

355
356
357
358


359
360

361
362
363

364
365
366

367
368
369
370
371
372
373
374
375
376
377
378










379
380
381
382
383
384
385


386
387
388
389

390
391
392
393
394
395
396
326
327
328
329
330
331
332

333
334
335


336
337
338

339
340
341

342
343
344

345
346
347










348
349
350
351
352
353
354
355
356
357
358
359
360
361
362


363
364
365
366
367

368
369
370
371
372
373
374
375







-
+


-
-
+
+

-
+


-
+


-
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+





-
-
+
+



-
+







 */

static int
ImgPhotoCreate(
    Tcl_Interp *interp,		/* Interpreter for application containing
				 * image. */
    const char *name,		/* Name to use for image. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects for options (doesn't
				 * include image name or type). */
    TCL_UNUSED(const Tk_ImageType *),/* Pointer to our type record (not used). */
    Tk_ImageModel model,	/* Token for image, to be used by us in later
    const Tk_ImageType *typePtr,/* Pointer to our type record (not used). */
    Tk_ImageMaster master,	/* Token for image, to be used by us in later
				 * callbacks. */
    void **clientDataPtr)	/* Store manager's token for image here; it
    ClientData *clientDataPtr)	/* Store manager's token for image here; it
				 * will be returned in later callbacks. */
{
    PhotoModel *modelPtr;
    PhotoMaster *masterPtr;

    /*
     * Allocate and initialize the photo image model record.
     * Allocate and initialize the photo image master record.
     */

    modelPtr = (PhotoModel *)ckalloc(sizeof(PhotoModel));
    memset(modelPtr, 0, sizeof(PhotoModel));
    modelPtr->tkModel = model;
    modelPtr->interp = interp;
    modelPtr->imageCmd = Tcl_CreateObjCommand(interp, name, ImgPhotoCmd,
	    modelPtr, ImgPhotoCmdDeletedProc);
    modelPtr->palette = NULL;
    modelPtr->pix32 = NULL;
    modelPtr->instancePtr = NULL;
    modelPtr->validRegion = TkCreateRegion();
    masterPtr = ckalloc(sizeof(PhotoMaster));
    memset(masterPtr, 0, sizeof(PhotoMaster));
    masterPtr->tkMaster = master;
    masterPtr->interp = interp;
    masterPtr->imageCmd = Tcl_CreateObjCommand(interp, name, ImgPhotoCmd,
	    masterPtr, ImgPhotoCmdDeletedProc);
    masterPtr->palette = NULL;
    masterPtr->pix32 = NULL;
    masterPtr->instancePtr = NULL;
    masterPtr->validRegion = TkCreateRegion();

    /*
     * Process configuration options given in the image create command.
     */

    if (ImgPhotoConfigureModel(interp, modelPtr, objc, objv, 0) != TCL_OK) {
	ImgPhotoDelete(modelPtr);
    if (ImgPhotoConfigureMaster(interp, masterPtr, objc, objv, 0) != TCL_OK) {
	ImgPhotoDelete(masterPtr);
	return TCL_ERROR;
    }

    *clientDataPtr = modelPtr;
    *clientDataPtr = masterPtr;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoCmd --
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429


430
431
432
433
434
435
436

437
438
439
440

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471
472
473
474


475
476
477


478
479
480
481


482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503

504
505
506
507
508
509
510


511
512

513
514
515
516
517


518
519

520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

535

536
537
538


539
540
541
542
543
544

545
546

547
548
549
550
551
552


553
554
555
556
557
558

559
560

561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579

580
581
582

583
584
585
586
587
588
589
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406


407
408

409
410
411
412


413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450

451
452
453


454
455
456
457


458
459




460
461
462

463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482


483
484
485

486
487
488
489


490
491
492

493







494
495
496
497
498
499
500

501
502
503
504


505
506
507
508
509
510
511

512
513

514
515
516
517
518


519
520
521
522
523
524
525

526
527

528
529
530











531




532

533
534
535

536
537
538
539
540
541
542
543







-
+














-
-
+
+
-




-
-
+



-
+



















-
+













-
+
+

-
-
+
+


-
-
+
+
-
-
-
-



-
+













-
+





-
-
+
+

-
+



-
-
+
+

-
+
-
-
-
-
-
-
-







-
+

+

-
-
+
+





-
+

-
+




-
-
+
+





-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-

-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ImgPhotoCmd(
    void *clientData,	/* Information about photo model. */
    ClientData clientData,	/* Information about photo master. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const photoOptions[] = {
	"blank", "cget", "configure", "copy", "data", "get", "put",
	"read", "redither", "transparency", "write", NULL
    };
    enum PhotoOptions {
	PHOTO_BLANK, PHOTO_CGET, PHOTO_CONFIGURE, PHOTO_COPY, PHOTO_DATA,
	PHOTO_GET, PHOTO_PUT, PHOTO_READ, PHOTO_REDITHER, PHOTO_TRANS,
	PHOTO_WRITE
    };

    PhotoModel *modelPtr = (PhotoModel *)clientData;
    int result, x, y, width, height;
    PhotoMaster *masterPtr = clientData;
    int result, index, x, y, width, height;
    Tcl_Size index;
    struct SubcommandOptions options;
    unsigned char *pixelPtr;
    Tk_PhotoImageBlock block;
    Tk_PhotoImageFormat *imageFormat;
    Tk_PhotoImageFormatVersion3 *imageFormatVersion3;
    Tcl_Size length;
    size_t length;
    int imageWidth, imageHeight, matched, oldformat = 0;
    Tcl_Channel chan;
    Tk_PhotoHandle srcHandle;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], photoOptions, "option", 0,
	    &index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum PhotoOptions) index) {
    case PHOTO_BLANK:
	/*
	 * photo blank command - just call Tk_PhotoBlank.
	 */

	if (objc == 2) {
	    Tk_PhotoBlank(modelPtr);
	    Tk_PhotoBlank(masterPtr);
	    return TCL_OK;
	} else {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}

    case PHOTO_CGET: {
	const char *arg;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    return TCL_ERROR;
	}
	arg = Tcl_GetStringFromObj(objv[2], &length);
	arg = Tcl_GetString(objv[2]);
	length = objv[2]->length;
	if (strncmp(arg,"-data", length) == 0) {
	    if (modelPtr->dataString) {
		Tcl_SetObjResult(interp, modelPtr->dataString);
	    if (masterPtr->dataString) {
		Tcl_SetObjResult(interp, masterPtr->dataString);
	    }
	} else if (strncmp(arg,"-format", length) == 0) {
	    if (modelPtr->format) {
		Tcl_SetObjResult(interp, modelPtr->format);
	    if (masterPtr->format) {
		Tcl_SetObjResult(interp, masterPtr->format);
	    }
	} else if (strncmp(arg, "-metadata", length) == 0) {
	    if (modelPtr->metadata) {
		Tcl_SetObjResult(interp, modelPtr->metadata);
	    }
	} else {
	    Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs,
		    modelPtr, Tcl_GetString(objv[2]), 0);
		    (char *) masterPtr, Tcl_GetString(objv[2]), 0);
	}
	return TCL_OK;
    }

    case PHOTO_CONFIGURE:
	/*
	 * photo configure command - handle this in the standard way.
	 */

	if (objc == 2) {
	    Tcl_Obj *obj, *subobj;

	    result = Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
		    configSpecs, modelPtr, NULL, 0);
		    configSpecs, (char *) masterPtr, NULL, 0);
	    if (result != TCL_OK) {
		return result;
	    }
	    obj = Tcl_NewObj();
	    subobj = Tcl_NewStringObj("-data {} {} {}", 14);
	    if (modelPtr->dataString) {
		Tcl_ListObjAppendElement(NULL, subobj, modelPtr->dataString);
	    if (masterPtr->dataString) {
		Tcl_ListObjAppendElement(NULL, subobj, masterPtr->dataString);
	    } else {
		Tcl_AppendStringsToObj(subobj, " {}", (char *)NULL);
		Tcl_AppendStringsToObj(subobj, " {}", NULL);
	    }
	    Tcl_ListObjAppendElement(interp, obj, subobj);
	    subobj = Tcl_NewStringObj("-format {} {} {}", 16);
	    if (modelPtr->format) {
		Tcl_ListObjAppendElement(NULL, subobj, modelPtr->format);
	    if (masterPtr->format) {
		Tcl_ListObjAppendElement(NULL, subobj, masterPtr->format);
	    } else {
		Tcl_AppendStringsToObj(subobj, " {}", (char *)NULL);
		Tcl_AppendStringsToObj(subobj, " {}", NULL);
	    }
	    Tcl_ListObjAppendElement(interp, obj, subobj);
	    subobj = Tcl_NewStringObj("-metadata {} {} {}", 18);
	    if (modelPtr->metadata) {
		Tcl_ListObjAppendElement(NULL, subobj, modelPtr->metadata);
	    } else {
		Tcl_AppendStringsToObj(subobj, " {}", (char *)NULL);
	    }
	    Tcl_ListObjAppendElement(interp, obj, subobj);
	    Tcl_ListObjAppendList(interp, obj, Tcl_GetObjResult(interp));
	    Tcl_SetObjResult(interp, obj);
	    return TCL_OK;

	} else if (objc == 3) {
	    const char *arg = Tcl_GetStringFromObj(objv[2], &length);
	    const char *arg = Tcl_GetString(objv[2]);

	    length = objv[2]->length;
	    if (length > 1 && !strncmp(arg, "-data", length)) {
		Tcl_AppendResult(interp, "-data {} {} {}", (char *)NULL);
		if (modelPtr->dataString) {
		Tcl_AppendResult(interp, "-data {} {} {}", NULL);
		if (masterPtr->dataString) {
		    /*
		     * TODO: Modifying result is bad!
		     */

		    Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp),
			    modelPtr->dataString);
			    masterPtr->dataString);
		} else {
		    Tcl_AppendResult(interp, " {}", (char *)NULL);
		    Tcl_AppendResult(interp, " {}", NULL);
		}
		return TCL_OK;
	    } else if (length > 1 &&
		    !strncmp(arg, "-format", length)) {
		Tcl_AppendResult(interp, "-format {} {} {}", (char *)NULL);
		if (modelPtr->format) {
		Tcl_AppendResult(interp, "-format {} {} {}", NULL);
		if (masterPtr->format) {
		    /*
		     * TODO: Modifying result is bad!
		     */

		    Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp),
			    modelPtr->format);
			    masterPtr->format);
		} else {
		    Tcl_AppendResult(interp, " {}", (char *)NULL);
		    Tcl_AppendResult(interp, " {}", NULL);
		}
		return TCL_OK;
	    } else if (length > 1 &&
		!strncmp(arg, "-metadata", length)) {
		Tcl_AppendResult(interp, "-metadata {} {} {}", (char *)NULL);
		if (modelPtr->metadata) {
		    /*
		     * TODO: Modifying result is bad!
		     */

		    Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp),
			modelPtr->metadata);
		} else {
	    } else {
		    Tcl_AppendResult(interp, " {}", (char *)NULL);
		}
		return TCL_OK;
	    } else {
		return Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
			configSpecs, modelPtr, arg, 0);
			configSpecs, (char *) masterPtr, arg, 0);
	    }
	} else {
	    return ImgPhotoConfigureModel(interp, modelPtr, objc-2, objv+2,
	    return ImgPhotoConfigureMaster(interp, masterPtr, objc-2, objv+2,
		    TK_CONFIG_ARGV_ONLY);
	}

    case PHOTO_COPY:
	/*
	 * photo copy command - first parse options.
	 */
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
599







-
+









-
+








-
+








	srcHandle = Tk_FindPhoto(interp, Tcl_GetString(options.name));
	if (srcHandle == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "image \"%s\" doesn't exist or is not a photo image",
		    Tcl_GetString(options.name)));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO",
		    Tcl_GetString(options.name), (char *)NULL);
		    Tcl_GetString(options.name), NULL);
	    return TCL_ERROR;
	}
	Tk_PhotoGetImage(srcHandle, &block);
	if ((options.fromX2 > block.width) || (options.fromY2 > block.height)
		|| (options.fromX2 > block.width)
		|| (options.fromY2 > block.height)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "coordinates for -from option extend outside source image",
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Hack to pass through the message that the place we're coming from
	 * has a simple alpha channel.
	 */

	if (!(((PhotoModel *) srcHandle)->flags & COMPLEX_ALPHA)) {
	if (!(((PhotoMaster *) srcHandle)->flags & COMPLEX_ALPHA)) {
	    options.compositingRule |= SOURCE_IS_SIMPLE_ALPHA_PHOTO;
	}

	/*
	 * Fill in default values for unspecified parameters.
	 */

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700

701
702
703
704


705
706
707
708

709
710
711
712













713
714
715
716


717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744
745
746
747
748
749




750
751
752


753
754
755
756
757
758
759
760
761
762
763
764
765


766
767
768
769


770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795






796
797
798
799
800
801



802
803
804
805
806
807
808






809
810
811
812



813
814
815

816
817
818
819



820
821

822
823
824
825
826
827
828
829

830
831
832
833
834

835
836
837
838
839
840
841

842
843
844
845
846
847
848
849
850


851
852
853


854
855
856
857
858
859
860
861
862
863



864
865
866
867

868
869
870
871
872
873
874
875



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894










895
896
897
898
899
900
901




902
903
904
905
906
907


908
909
910
911
912

913
914
915
916
917
918
919
920
921
922



923


924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940

941
942
943
944
945
946
947
948
949
950
951
952
953
954


955
956

957
958
959
960
961
962
963
964
621
622
623
624
625
626
627
628


















629



630
631
632

633
634
635


636
637
638
639
640

641




642
643
644
645
646
647
648
649
650
651
652
653
654
655
656


657
658

659
660
661
662
663
664

665
666
667
668
669

670
671
672

673

674
675
676
677
678



679
680




681
682
683
684
685


686
687



688
689
690
691
692
693
694
695


696
697
698
699


700
701










702
703
704
705
706
707
708
709

710
711






712
713
714
715
716
717
718
719
720



721
722
723







724
725
726
727
728
729




730
731
732
733
734

735
736



737
738
739
740

741
742
743
744
745
746
747
748

749
750




751
752
753
754
755
756
757

758
759
760
761
762
763
764
765
766

767
768
769


770
771
772
773
774
775
776
777
778



779
780
781
782
783
784

785
786
787
788
789
790



791
792
793
794
795
796
797
798
799
800
801
802










803
804
805
806
807
808
809
810
811
812
813
814
815




816
817
818
819
820
821
822
823


824
825
826
827
828
829

830
831
832
833
834
835
836
837



838
839
840

841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857


858

859
860
861
862
863
864
865
866
867
868
869


870
871


872

873
874
875
876
877
878
879








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-



-
+


-
-
+
+



-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+
-






-





-



-
+
-





-
-
-


-
-
-
-
+
+
+
+

-
-
+
+
-
-
-








-
-
+
+


-
-
+
+
-
-
-
-
-
-
-
-
-
-








-
+

-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+


-
+

-
-
-
+
+
+

-
+







-
+

-
-
-
-
+






-
+








-
+
+

-
-
+
+







-
-
-
+
+
+



-
+





-
-
-
+
+
+









-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
-
+
+
+
+




-
-
+
+




-
+







-
-
-
+
+
+
-
+
+















-
-
+
-











-
-
+
+
-
-
+
-







	    } else {
		height = (height - options.subsampleY - 1)
			/ -options.subsampleY;
	    }
	    options.toY2 = options.toY + height * options.zoomY;
	}

	/*
	 * Copy the image data over using Tk_PhotoPutZoomedBlock.
	 */

	if (block.pixelPtr) {
	    block.pixelPtr += options.fromX * block.pixelSize
		    + options.fromY * block.pitch;
	    block.width = options.fromX2 - options.fromX;
	    block.height = options.fromY2 - options.fromY;
	    result = Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) modelPtr,
		    &block, options.toX, options.toY, options.toX2 - options.toX,
		    options.toY2 - options.toY, options.zoomX, options.zoomY,
		    options.subsampleX, options.subsampleY,
		    options.compositingRule);
	} else {
	    result = TCL_OK;
	}

	/*
	 * Set the destination image size if the -shrink option was specified.
	 * This has to be done _after_ copying the data. Otherwise, if source
	 * and destination are the same image, block.pixelPtr would point to
	 * an invalid memory block (bug [5239fd749b]).
	 */

	if (options.options & OPT_SHRINK) {
	    if (ImgPhotoSetSize(modelPtr, options.toX2,
	    if (ImgPhotoSetSize(masterPtr, options.toX2,
		    options.toY2) != TCL_OK) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
		return TCL_ERROR;
	    }
	}
	if (block.pixelPtr || (options.options & OPT_SHRINK)) {

	    Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0,
		    modelPtr->width, modelPtr->height);
	}
	return result;
	/*
	 * Copy the image data over using Tk_PhotoPutZoomedBlock.
	 */

	block.pixelPtr += options.fromX * block.pixelSize
		+ options.fromY * block.pitch;
	block.width = options.fromX2 - options.fromX;
	block.height = options.fromY2 - options.fromY;
	return Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) masterPtr,
		&block, options.toX, options.toY, options.toX2 - options.toX,
		options.toY2 - options.toY, options.zoomX, options.zoomY,
		options.subsampleX, options.subsampleY,
		options.compositingRule);

    case PHOTO_DATA: {
	char *data = NULL;
	Tcl_Obj *freeObj = NULL;
        char *data = NULL;
        Tcl_Obj *freeObj = NULL;
	Tcl_Obj *metadataIn;

	/*
	 * photo data command - first parse and check any options given.
	 */

	Tk_ImageStringWriteProc *stringWriteProc = NULL;
	Tk_ImageStringWriteProcVersion3 *stringWriteProcVersion3 = NULL;

	index = 1;
	memset(&options, 0, sizeof(options));
	options.name = NULL;
	options.format = NULL;
	options.metadata = NULL;
	options.fromX = 0;
	options.fromY = 0;
	if (ParseSubcommandOptions(&options, interp,
		OPT_FORMAT | OPT_FROM | OPT_GRAYSCALE | OPT_BACKGROUND
		OPT_FORMAT | OPT_FROM | OPT_GRAYSCALE | OPT_BACKGROUND,
		| OPT_METADATA,
		&index, objc, objv) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((options.name == NULL) || (index < objc)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-option value ...?");
	    if (options.background) {
		Tk_FreeColor(options.background);
	    }
	    return TCL_ERROR;
	}
	if ((options.fromX > modelPtr->width)
		|| (options.fromY > modelPtr->height)
		|| (options.fromX2 > modelPtr->width)
		|| (options.fromY2 > modelPtr->height)) {
	if ((options.fromX > masterPtr->width)
		|| (options.fromY > masterPtr->height)
		|| (options.fromX2 > masterPtr->width)
		|| (options.fromY2 > masterPtr->height)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "coordinates for -from option extend outside image", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", (char *)NULL);
		    "coordinates for -from option extend outside image", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", NULL);
	    if (options.background) {
		Tk_FreeColor(options.background);
	    }
	    return TCL_ERROR;
	}

	/*
	 * Fill in default values for unspecified parameters.
	 */

	if (!(options.options & OPT_FROM) || (options.fromX2 < 0)) {
	    options.fromX2 = modelPtr->width;
	    options.fromY2 = modelPtr->height;
	    options.fromX2 = masterPtr->width;
	    options.fromY2 = masterPtr->height;
	}
	if (!(options.options & OPT_FORMAT)) {
	    options.format = Tcl_NewStringObj("default", TCL_INDEX_NONE);
	    freeObj = options.format;
            options.format = Tcl_NewStringObj("default", -1);
            freeObj = options.format;
	}

	/*
	 * Use argument metadata if specified, otherwise the master metadata
	 */

	if (NULL != options.metadata) {
	    metadataIn = options.metadata;
	} else {
	    metadataIn = modelPtr->metadata;
	}

	/*
	 * Search for an appropriate image string format handler.
	 */

	matched = 0;
	for (imageFormat = tsdPtr->formatList; imageFormat != NULL;
		imageFormat = imageFormat->nextPtr) {
                imageFormat = imageFormat->nextPtr) {
	    if ((strncasecmp(Tcl_GetString(options.format),
		    imageFormat->name, strlen(imageFormat->name)) == 0)) {
		matched = 1;
		if (imageFormat->stringWriteProc != NULL) {
		    stringWriteProc = imageFormat->stringWriteProc;
		    break;
		}
                    imageFormat->name, strlen(imageFormat->name)) == 0)) {
                matched = 1;
                if (imageFormat->stringWriteProc != NULL) {
                    stringWriteProc = imageFormat->stringWriteProc;
                    break;
                }
	    }
	}
	if (stringWriteProc == NULL) {
	    oldformat = 0;
	    for (imageFormatVersion3 = tsdPtr->formatListVersion3;
		    imageFormatVersion3 != NULL;
	    oldformat = 1;
	    for (imageFormat = tsdPtr->oldFormatList; imageFormat != NULL;
                    imageFormat = imageFormat->nextPtr) {
		    imageFormatVersion3 = imageFormatVersion3->nextPtr) {
		if ((strncasecmp(Tcl_GetString(options.format),
			imageFormatVersion3->name,
			strlen(imageFormatVersion3->name)) == 0)) {
		    matched = 1;
		    if (imageFormatVersion3->stringWriteProc != NULL) {
			stringWriteProcVersion3 =
                if ((strncasecmp(Tcl_GetString(options.format),
                        imageFormat->name,
                        strlen(imageFormat->name)) == 0)) {
                    matched = 1;
                    if (imageFormat->stringWriteProc != NULL) {
                        stringWriteProc = imageFormat->stringWriteProc;
				imageFormatVersion3->stringWriteProc;
			break;
		    }
		}
                        break;
                    }
                }
	    }
	}
	if (stringWriteProc == NULL && stringWriteProcVersion3 == NULL) {
	if (stringWriteProc == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "image string format \"%s\" is %s",
		    Tcl_GetString(options.format),
		    (matched ? "not supported" : "unknown")));
                    "image string format \"%s\" is %s",
                    Tcl_GetString(options.format),
                    (matched ? "not supported" : "unknown")));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
		    Tcl_GetString(options.format), (char *)NULL);
                    Tcl_GetString(options.format), NULL);
	    goto dataErrorExit;
	}

	/*
	 * Call the handler's string write function to write out the image.
	 */

	data = ImgGetPhoto(modelPtr, &block, &options);
	data = ImgGetPhoto(masterPtr, &block, &options);

	if (stringWriteProc == NULL) {
	    result = (stringWriteProcVersion3)(interp,
		    options.format, metadataIn, &block);
	} else if (oldformat) {
	if (oldformat) {
	    Tcl_DString buffer;
	    typedef int (*OldStringWriteProc)(Tcl_Interp *interp,
		    Tcl_DString *dataPtr, const char *formatString,
		    Tk_PhotoImageBlock *blockPtr);

	    Tcl_DStringInit(&buffer);
	    result = ((OldStringWriteProc)(void *)stringWriteProc)(interp, &buffer,
	    result = ((OldStringWriteProc) stringWriteProc)(interp, &buffer,
		    Tcl_GetString(options.format), &block);
	    if (result == TCL_OK) {
		Tcl_DStringResult(interp, &buffer);
	    } else {
		Tcl_DStringFree(&buffer);
	    }
	} else {
	    typedef int (*NewStringWriteProc)(Tcl_Interp *interp,
		    Tcl_Obj *formatString, Tk_PhotoImageBlock *blockPtr);
		    Tcl_Obj *formatString, Tk_PhotoImageBlock *blockPtr,
		    void *dummy);

	    result = ((NewStringWriteProc)(void *)stringWriteProc)(interp,
		    options.format, &block);
	    result = ((NewStringWriteProc) stringWriteProc)(interp,
		    options.format, &block, NULL);
	}
	if (options.background) {
	    Tk_FreeColor(options.background);
	}
	if (data) {
	    ckfree(data);
	}
	if (freeObj != NULL) {
	    Tcl_DecrRefCount(freeObj);
	}
        if (freeObj != NULL) {
            Tcl_DecrRefCount(freeObj);
        }
	return result;

      dataErrorExit:
	if (options.background) {
        if (options.background) {
	    Tk_FreeColor(options.background);
	}
	if (data) {
	    ckfree(data);
	}
	if (freeObj != NULL) {
	    Tcl_DecrRefCount(freeObj);
	}
        if (freeObj != NULL) {
            Tcl_DecrRefCount(freeObj);
        }
	return TCL_ERROR;
    }

    case PHOTO_GET: {
	/*
	 * photo get command - first parse and check parameters.
	 */

	Tcl_Obj *channels[4];
	int i, channelCount = 3;

	index = 3;
	memset(&options, 0, sizeof(options));
	options.name = NULL;
	if (ParseSubcommandOptions(&options, interp, OPT_WITHALPHA,
		&index, objc, objv) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (options.name == NULL || index < objc) {
	int channelCount = 3;
    
        index = 3;
        memset(&options, 0, sizeof(options));
        options.name = NULL;
        if (ParseSubcommandOptions(&options, interp, OPT_WITHALPHA,
                &index, objc, objv) != TCL_OK) {
            return TCL_ERROR;
        }
        if (options.name == NULL || index < objc) {
	    Tcl_WrongNumArgs(interp, 2, objv, "x y ?-withalpha?");
	    return TCL_ERROR;
	}
	if (options.options & OPT_WITHALPHA) {
	    channelCount = 4;
	}

        if (options.options & OPT_WITHALPHA) {
            channelCount = 4;
        }
 
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	    return TCL_ERROR;
	}
	if ((x < 0) || (x >= modelPtr->width)
		|| (y < 0) || (y >= modelPtr->height)) {
	if ((x < 0) || (x >= masterPtr->width)
		|| (y < 0) || (y >= masterPtr->height)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "%s get: coordinates out of range",
		    Tcl_GetString(objv[0])));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "COORDINATES",
		    (char *)NULL);
		    NULL);
	    return TCL_ERROR;
	}

	/*
	 * Extract the value of the desired pixel and format it as a list.
	 */

	pixelPtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
	for (i = 0; i < channelCount; i++) {
	    channels[i] = Tcl_NewWideIntObj(pixelPtr[i]);
	pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
	channels[0] = Tcl_NewIntObj(pixelPtr[0]);
	channels[1] = Tcl_NewIntObj(pixelPtr[1]);
	}
	channels[2] = Tcl_NewIntObj(pixelPtr[2]);
	channels[3] = Tcl_NewIntObj(pixelPtr[3]);
	Tcl_SetObjResult(interp, Tcl_NewListObj(channelCount, channels));
	return TCL_OK;
    }

    case PHOTO_PUT: {
	Tcl_Obj *format, *data;

	/*
	 * photo put command - first parse the options.
	 */

	index = 2;
	memset(&options, 0, sizeof(options));
	options.name = NULL;
	options.format = NULL;
	options.metadata = NULL;
	if (ParseSubcommandOptions(&options, interp,
	if (ParseSubcommandOptions(&options, interp, OPT_TO|OPT_FORMAT,
		OPT_TO|OPT_FORMAT|OPT_METADATA,
		&index, objc, objv) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((options.name == NULL) || (index < objc)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "data ?-option value ...?");
	    return TCL_ERROR;
	}

	/*
	 * See if there's a format that can read the data
	 */

	if (MatchStringFormat(interp, objv[2], options.format,
	
	if (MatchStringFormat(interp, objv[2], options.format, &imageFormat,
		options.metadata, NULL, &imageFormat,
		&imageFormatVersion3, &imageWidth, &imageHeight, &oldformat)
		&imageWidth, &imageHeight, &oldformat) != TCL_OK) {
		!= TCL_OK) {
	    return TCL_ERROR;
	}

	if (!(options.options & OPT_TO) || (options.toX2 < 0)) {
	    options.toX2 = options.toX + imageWidth;
	    options.toY2 = options.toY + imageHeight;
	}
973
974
975
976
977
978
979
980
981
982
983
984
985
986






987
988
989
990
991
992
993
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006


1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038


1039
1040
1041
1042
1043
1044
1045
888
889
890
891
892
893
894







895
896
897
898
899
900












901

902
903
904
905
906


907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922

923
924
925
926
927
928
929
930
931
932
933
934
935
936
937


938
939
940
941
942
943
944
945
946







-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-

-
+




-
-
+
+













-

-
+














-
-
+
+







	if (oldformat) {
	    if (format) {
		format = (Tcl_Obj *) Tcl_GetString(format);
	    }
	    data = (Tcl_Obj *) Tcl_GetString(data);
	}

	if (imageFormat != NULL) {
	    if (imageFormat->stringReadProc(interp, data, format,
		    (Tk_PhotoHandle) modelPtr, options.toX, options.toY,
		    options.toX2 - options.toX,
		    options.toY2 - options.toY, 0, 0) != TCL_OK) {
		return TCL_ERROR;
	    }
	if (imageFormat->stringReadProc(interp, data, format,
		(Tk_PhotoHandle) masterPtr, options.toX, options.toY,
		options.toX2 - options.toX, 
		options.toY2 - options.toY, 0, 0) != TCL_OK) {
	    return TCL_ERROR;
	}
	} else {
	    if (imageFormatVersion3->stringReadProc(interp, data, format,
		    options.metadata,
		    (Tk_PhotoHandle) modelPtr, options.toX, options.toY,
		    options.toX2 - options.toX,
		    options.toY2 - options.toY, 0, 0,
		    NULL)
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	}

	/*
	 * SB: is the next line really needed? The stringReadProc
	 * SB: is the next line really needed? The stringReadProc 
	 * writes image data with Tk_PhotoPutBlock(), which in turn
	 * takes care to notify the changed image and to set/unset the
	 * IMAGE_CHANGED bit.
	 */
	modelPtr->flags |= IMAGE_CHANGED;

	masterPtr->flags |= IMAGE_CHANGED;
       
	return TCL_OK;
    }
    case PHOTO_READ: {
	Tcl_Obj *format;

	/*
	 * photo read command - first parse the options specified.
	 */

	index = 2;
	memset(&options, 0, sizeof(options));
	options.name = NULL;
	options.format = NULL;
	options.metadata = NULL;
	if (ParseSubcommandOptions(&options, interp,
		OPT_FORMAT | OPT_FROM | OPT_TO | OPT_SHRINK | OPT_METADATA,
		OPT_FORMAT | OPT_FROM | OPT_TO | OPT_SHRINK,
		&index, objc, objv) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((options.name == NULL) || (index < objc)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "fileName ?-option value ...?");
	    return TCL_ERROR;
	}

	/*
	 * Prevent file system access in safe interpreters.
	 */

	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't get image from a file in a safe interpreter", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", (char *)NULL);
		    "can't get image from a file in a safe interpreter", -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Open the image file and look for a handler for it.
	 */

1056
1057
1058
1059
1060
1061
1062
1063

1064
1065

1066
1067


1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122




1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152





1153
1154

1155
1156
1157
1158



1159
1160
1161

1162
1163
1164
1165
1166
1167
1168



1169
1170
1171
1172
1173
1174
1175
957
958
959
960
961
962
963

964


965


966
967

968
969
970
971
972
973
974
975
976
977
978
979


980
981
982

983
984
985
986
987
988
989
990
991
992
993
994
995
996

997
998
999
1000



1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015





1016
1017
1018
1019








1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036





1037
1038
1039
1040
1041
1042

1043
1044



1045
1046
1047
1048
1049

1050
1051
1052
1053
1054



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064







-
+
-
-
+
-
-
+
+
-












-
-
+
+
+
-














-
+



-
-
-
+
+
+
-












-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-

















-
-
-
-
-
+
+
+
+
+

-
+

-
-
-
+
+
+


-
+




-
-
-
+
+
+







	if (Tcl_SetChannelOption(interp, chan, "-encoding", "binary")
		!= TCL_OK) {
	    Tcl_Close(NULL, chan);
	    return TCL_ERROR;
	}

	if (MatchFileFormat(interp, chan,
		Tcl_GetString(options.name), options.format,
		Tcl_GetString(options.name), options.format, &imageFormat,
		options.metadata, NULL, &imageFormat,
		&imageFormatVersion3, &imageWidth, &imageHeight, &oldformat)
		&imageWidth, &imageHeight, &oldformat) != TCL_OK) {
		!= TCL_OK) {
	    result = TCL_ERROR;
	    Tcl_Close(NULL, chan);
	    return TCL_ERROR;
	    goto readCleanup;
	}

	/*
	 * Check the values given for the -from option.
	 */

	if ((options.fromX > imageWidth) || (options.fromY > imageHeight)
		|| (options.fromX2 > imageWidth)
		|| (options.fromY2 > imageHeight)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "coordinates for -from option extend outside source image",
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", (char *)NULL);
	    result = TCL_ERROR;
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", NULL);
	    Tcl_Close(NULL, chan);
	    return TCL_ERROR;
	    goto readCleanup;
	}
	if (!(options.options & OPT_FROM) || (options.fromX2 < 0)) {
	    width = imageWidth - options.fromX;
	    height = imageHeight - options.fromY;
	} else {
	    width = options.fromX2 - options.fromX;
	    height = options.fromY2 - options.fromY;
	}

	/*
	 * If the -shrink option was specified, set the size of the image.
	 */

	if (options.options & OPT_SHRINK) {
	    if (ImgPhotoSetSize(modelPtr, options.toX + width,
	    if (ImgPhotoSetSize(masterPtr, options.toX + width,
		    options.toY + height) != TCL_OK) {
		Tcl_ResetResult(interp);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
		result = TCL_ERROR;
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
		return TCL_ERROR;
		goto readCleanup;
	    }
	}

	/*
	 * Call the handler's file read function to read the data into the
	 * image.
	 */

	format = options.format;
	if (oldformat && format) {
	    format = (Tcl_Obj *) Tcl_GetString(format);
	}
	if (imageFormat != NULL) {
	    result = imageFormat->fileReadProc(interp, chan,
		    Tcl_GetString(options.name),
		    format, (Tk_PhotoHandle) modelPtr, options.toX,
		    options.toY, width, height, options.fromX, options.fromY);
	result = imageFormat->fileReadProc(interp, chan,
		Tcl_GetString(options.name),
		format, (Tk_PhotoHandle) masterPtr, options.toX,
		options.toY, width, height, options.fromX, options.fromY);
	} else {
	    result = imageFormatVersion3->fileReadProc(interp, chan,
		    Tcl_GetString(options.name),
		    format, options.metadata, (Tk_PhotoHandle) modelPtr,
		    options.toX, options.toY, width, height, options.fromX,
		    options.fromY, NULL);
	}
readCleanup:
	if (chan != NULL) {
	    Tcl_Close(NULL, chan);
	}
	return result;
    }

    case PHOTO_REDITHER:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    return TCL_ERROR;
	}

	/*
	 * Call Dither if any part of the image is not correctly dithered at
	 * present.
	 */

	x = modelPtr->ditherX;
	y = modelPtr->ditherY;
	if (modelPtr->ditherX != 0) {
	    Tk_DitherPhoto((Tk_PhotoHandle) modelPtr, x, y,
		    modelPtr->width - x, 1);
	x = masterPtr->ditherX;
	y = masterPtr->ditherY;
	if (masterPtr->ditherX != 0) {
	    Tk_DitherPhoto((Tk_PhotoHandle) masterPtr, x, y,
		    masterPtr->width - x, 1);
	}
	if (modelPtr->ditherY < modelPtr->height) {
	if (masterPtr->ditherY < masterPtr->height) {
	    x = 0;
	    Tk_DitherPhoto((Tk_PhotoHandle)modelPtr, 0,
		    modelPtr->ditherY, modelPtr->width,
		    modelPtr->height - modelPtr->ditherY);
	    Tk_DitherPhoto((Tk_PhotoHandle)masterPtr, 0,
		    masterPtr->ditherY, masterPtr->width,
		    masterPtr->height - masterPtr->ditherY);
	}

	if (y < modelPtr->height) {
	if (y < masterPtr->height) {
	    /*
	     * Tell the core image code that part of the image has changed.
	     */

	    Tk_ImageChanged(modelPtr->tkModel, x, y,
		    (modelPtr->width - x), (modelPtr->height - y),
		    modelPtr->width, modelPtr->height);
	    Tk_ImageChanged(masterPtr->tkMaster, x, y,
		    (masterPtr->width - x), (masterPtr->height - y),
		    masterPtr->width, masterPtr->height);
	}
	return TCL_OK;

    case PHOTO_TRANS: {
	static const char *const photoTransOptions[] = {
	    "get", "set", NULL
	};
1189
1190
1191
1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225
1226


1227
1228
1229
1230
1231

1232
1233
1234
1235

1236
1237
1238

1239
1240

1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
1284
1285


1286
1287
1288
1289
1290

1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310
1311

1312
1313
1314
1315
1316


1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335


1336
1337
1338


1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360

1361
1362
1363
1364
1365
1366
1367
1368
1369
1370


1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399




1400
1401
1402


1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417


1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460



1461
1462
1463
1464


1465
1466

1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483

1484
1485
1486
1487

1488
1489
1490
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508

1509
1510
1511
1512
1513
1514
1515


1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113


1114
1115
1116
1117
1118
1119

1120
1121
1122
1123

1124
1125
1126

1127
1128

1129
1130

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171
1172


1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199

1200
1201
1202
1203


1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222


1223
1224
1225


1226
1227
1228
1229
1230
1231
1232
1233
1234
1235



1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248

1249
1250
1251
1252
1253
1254
1255
1256
1257


1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270

1271

1272

1273
1274
1275
1276
1277



1278
1279




1280
1281
1282
1283
1284


1285
1286



1287
1288
1289
1290
1291
1292
1293
1294
1295
1296


1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307











1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326



1327
1328
1329

1330


1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350

1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365



1366
1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377



1378
1379





1380
1381
1382
1383
1384
1385
1386







-
+




















-
+







-
-
+
+




-
+



-
+


-
+

-
+

-
+









-
+


-
+




















-
+







-
-
+
+




-
+
















-
+



-
+



-
-
+
+





-
+











-
-
+
+

-
-
+
+








-
-
-
+
+
+










-
+








-
-
+
+











-

-
+
-





-
-
-


-
-
-
-
+
+
+
+

-
-
+
+
-
-
-










-
-
+
+









-
-
-
-
-
-
-
-
-
-
-







-












-
-
-
+
+
+
-

-
-
+
+

-
+
















-
+



-
+









-
+
-
-
-







-
+




-
-
-
+
+
-
-
-
-
-







	switch ((enum transOptions) index) {
	case PHOTO_TRANS_GET: {
	    int boolMode;

	    /*
	     * parse fixed args and option
	     */

	    
	    if (objc > 6 || objc < 5) {
		Tcl_WrongNumArgs(interp, 3, objv, "x y ?-option?");
		return TCL_ERROR;
	    }
	    if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
		    || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
		return TCL_ERROR;
	    }

	    index = 4;
	    memset(&options, 0, sizeof(options));
	    if (ParseSubcommandOptions(&options, interp,
		    OPT_ALPHA, &index, objc, objv) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (index < objc) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"unknown option \"%s\": must be -alpha",
			Tcl_GetString(objv[index])));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	    boolMode = 1;
	    if (options.options & OPT_ALPHA) {
		boolMode = 0;
	    }

	    if ((x < 0) || (x >= modelPtr->width)
		    || (y < 0) || (y >= modelPtr->height)) {
	    if ((x < 0) || (x >= masterPtr->width)
		    || (y < 0) || (y >= masterPtr->height)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"%s transparency get: coordinates out of range",
			Tcl_GetString(objv[0])));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "COORDINATES",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }

	    /*
	    /* 
	     * Extract and return the desired value
	     */
	    pixelPtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
	    pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
	    if (boolMode) {
		Tcl_SetObjResult(interp, Tcl_NewBooleanObj(pixelPtr[3] == 0));
		Tcl_SetObjResult(interp, Tcl_NewBooleanObj( ! pixelPtr[3]));
	    } else {
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pixelPtr[3]));
		Tcl_SetObjResult(interp, Tcl_NewIntObj(pixelPtr[3]));
	    }
	    return TCL_OK;
	}

	case PHOTO_TRANS_SET: {
	    int newVal, boolMode;
	    XRectangle setBox;
	    TkRegion modRegion;

	    /*
	    /* 
	     * Parse args and option, check for valid values
	     */

	    
	    if (objc < 6 || objc > 7) {
		Tcl_WrongNumArgs(interp, 3, objv, "x y newVal ?-option?");
		return TCL_ERROR;
	    }
	    if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
		    || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
		return TCL_ERROR;
	    }

	    index = 5;
	    memset(&options, 0, sizeof(options));
	    if (ParseSubcommandOptions(&options, interp,
		    OPT_ALPHA, &index, objc, objv) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (index < objc) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"unknown option \"%s\": must be -alpha",
			Tcl_GetString(objv[index])));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	    boolMode = 1;
	    if (options.options & OPT_ALPHA) {
		boolMode = 0;
	    }

	    if ((x < 0) || (x >= modelPtr->width)
		|| (y < 0) || (y >= modelPtr->height)) {
	    if ((x < 0) || (x >= masterPtr->width)
		|| (y < 0) || (y >= masterPtr->height)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"%s transparency set: coordinates out of range",
			Tcl_GetString(objv[0])));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "COORDINATES",
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }

	    if (boolMode) {
		if (Tcl_GetBooleanFromObj(interp, objv[5], &newVal) != TCL_OK) {
		    return TCL_ERROR;
		}
	    } else {
		if (Tcl_GetIntFromObj(interp, objv[5], &newVal) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (newVal < 0 || newVal > 255) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "invalid alpha value \"%d\": "
			    "must be integer between 0 and 255", newVal));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			    "BAD_VALUE", (char *)NULL);
			    "BAD_VALUE", NULL);
		    return TCL_ERROR;
		}
	    }

	   
	    /*
	     * Set new alpha value for the pixel
	     */

	    pixelPtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
	    
	    pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
	    if (boolMode) {
		pixelPtr[3] = newVal ? 0 : 255;
	    } else {
		pixelPtr[3] = newVal;
	    }

	    
	    /*
	     * Update the validRegion of the image
	     */

	    setBox.x = x;
	    setBox.y = y;
	    setBox.width = 1;
	    setBox.height = 1;
	    modRegion = TkCreateRegion();
	    TkUnionRectWithRegion(&setBox, modRegion, modRegion);
	    if (pixelPtr[3]) {
		TkUnionRectWithRegion(&setBox, modelPtr->validRegion,
			modelPtr->validRegion);
		TkUnionRectWithRegion(&setBox, masterPtr->validRegion,
			masterPtr->validRegion);
	    } else {
		TkSubtractRegion(modelPtr->validRegion, modRegion,
			modelPtr->validRegion);
		TkSubtractRegion(masterPtr->validRegion, modRegion,
			masterPtr->validRegion);
	    }
	    TkDestroyRegion(modRegion);

	    /*
	     * Inform the generic image code that the image
	     * has (potentially) changed.
	     */

	    Tk_ImageChanged(modelPtr->tkModel, x, y, 1, 1,
		    modelPtr->width, modelPtr->height);
	    modelPtr->flags &= ~IMAGE_CHANGED;
	    Tk_ImageChanged(masterPtr->tkMaster, x, y, 1, 1,
		    masterPtr->width, masterPtr->height);
	    masterPtr->flags &= ~IMAGE_CHANGED;
	    return TCL_OK;
	}

	}
	Tcl_Panic("unexpected fallthrough");
    }

    case PHOTO_WRITE: {
	char *data;
	const char *fmtString;
	Tcl_Obj *format, *metadataIn;
	Tcl_Obj *format;
	int usedExt;

	/*
	 * Prevent file system access in safe interpreters.
	 */

	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't write image to a file in a safe interpreter", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", (char *)NULL);
		    "can't write image to a file in a safe interpreter", -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", NULL);
	    return TCL_ERROR;
	}

	/*
	 * photo write command - first parse and check any options given.
	 */

	index = 2;
	memset(&options, 0, sizeof(options));
	options.name = NULL;
	options.format = NULL;
	options.metadata = NULL;
	if (ParseSubcommandOptions(&options, interp,
		OPT_FORMAT | OPT_FROM | OPT_GRAYSCALE | OPT_BACKGROUND
		OPT_FORMAT | OPT_FROM | OPT_GRAYSCALE | OPT_BACKGROUND,
		| OPT_METADATA,
		&index, objc, objv) != TCL_OK) {
	    return TCL_ERROR;
	}
	if ((options.name == NULL) || (index < objc)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "fileName ?-option value ...?");
	    if (options.background) {
		Tk_FreeColor(options.background);
	    }
	    return TCL_ERROR;
	}
	if ((options.fromX > modelPtr->width)
		|| (options.fromY > modelPtr->height)
		|| (options.fromX2 > modelPtr->width)
		|| (options.fromY2 > modelPtr->height)) {
	if ((options.fromX > masterPtr->width)
		|| (options.fromY > masterPtr->height)
		|| (options.fromX2 > masterPtr->width)
		|| (options.fromY2 > masterPtr->height)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "coordinates for -from option extend outside image", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", (char *)NULL);
		    "coordinates for -from option extend outside image", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", NULL);
	    if (options.background) {
		Tk_FreeColor(options.background);
	    }
	    return TCL_ERROR;
	}

	/*
	 * Fill in default values for unspecified parameters. Note that a
	 * missing -format flag results in us having a guess from the file
	 * extension. [Bug 2983824]
	 */

	if (!(options.options & OPT_FROM) || (options.fromX2 < 0)) {
	    options.fromX2 = modelPtr->width;
	    options.fromY2 = modelPtr->height;
	    options.fromX2 = masterPtr->width;
	    options.fromY2 = masterPtr->height;
	}
	if (options.format == NULL) {
	    fmtString = GetExtension(Tcl_GetString(options.name));
	    usedExt = (fmtString != NULL);
	} else {
	    fmtString = Tcl_GetString(options.format);
	    usedExt = 0;
	}


	/*
	 * Use argument metadata if specified, otherwise the master metadata
	 */

	if (NULL != options.metadata) {
	    metadataIn = options.metadata;
	} else {
	    metadataIn = modelPtr->metadata;
	}

	/*
	 * Search for an appropriate image file format handler, and give an
	 * error if none is found.
	 */

	matched = 0;
    redoFormatLookup:
	imageFormatVersion3 = NULL;
	for (imageFormat = tsdPtr->formatList; imageFormat != NULL;
		imageFormat = imageFormat->nextPtr) {
	    if ((fmtString == NULL)
		    || (strncasecmp(fmtString, imageFormat->name,
			    strlen(imageFormat->name)) == 0)) {
		matched = 1;
		if (imageFormat->fileWriteProc != NULL) {
		    break;
		}
	    }
	}
	if (imageFormat == NULL) {
	    oldformat = 0;
	    for (imageFormatVersion3 = tsdPtr->formatListVersion3;
		    imageFormatVersion3 != NULL;
	    oldformat = 1;
	    for (imageFormat = tsdPtr->oldFormatList; imageFormat != NULL;
		    imageFormat = imageFormat->nextPtr) {
		    imageFormatVersion3 = imageFormatVersion3->nextPtr) {
		if ((fmtString == NULL)
			|| (strncasecmp(fmtString, imageFormatVersion3->name,
				strlen(imageFormatVersion3->name)) == 0)) {
			|| (strncasecmp(fmtString, imageFormat->name,
				strlen(imageFormat->name)) == 0)) {
		    matched = 1;
		    if (imageFormatVersion3->fileWriteProc != NULL) {
		    if (imageFormat->fileWriteProc != NULL) {
			break;
		    }
		}
	    }
	}
	if (usedExt && !matched) {
	    /*
	     * If we didn't find one and we're using file extensions as the
	     * basis for the guessing, go back and look again without
	     * prejudice. Supports old broken code.
	     */

	    usedExt = 0;
	    fmtString = NULL;
	    goto redoFormatLookup;
	}
	if (imageFormat == NULL && imageFormatVersion3 == NULL) {
	if (imageFormat == NULL) {
	    if (fmtString == NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"no available image file format has file writing"
			" capability", TCL_INDEX_NONE));
			" capability", -1));
	    } else if (!matched) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"image file format \"%s\" is unknown", fmtString));
	    } else {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"image file format \"%s\" has no file writing capability",
			fmtString));
	    }
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
		    fmtString, (char *)NULL);
		    fmtString, NULL);
	    if (options.background) {
		Tk_FreeColor(options.background);
	    }
	    return TCL_ERROR;
	}

	/*
	 * Call the handler's file write function to write out the image.
	 */

	data = ImgGetPhoto(modelPtr, &block, &options);
	data = ImgGetPhoto(masterPtr, &block, &options);
	format = options.format;
	if (oldformat && format) {
	    format = (Tcl_Obj *) Tcl_GetString(options.format);
	}
	if (imageFormat != NULL) {
	    result = imageFormat->fileWriteProc(interp,
		    Tcl_GetString(options.name), format, &block);
	result = imageFormat->fileWriteProc(interp,
		Tcl_GetString(options.name), format, &block);
	} else {
	    result = imageFormatVersion3->fileWriteProc(interp,
		    Tcl_GetString(options.name), format, metadataIn,
		    &block);
	}
	if (options.background) {
	    Tk_FreeColor(options.background);
	}
	if (data) {
	    ckfree(data);
	}
	return result;
1565
1566
1567
1568
1569
1570
1571
1572
1573


1574
1575
1576
1577
1578
1579
1580
1424
1425
1426
1427
1428
1429
1430


1431
1432
1433
1434
1435
1436
1437
1438
1439







-
-
+
+







/*
 *----------------------------------------------------------------------
 *
 * ParseSubcommandOptions --
 *
 *	This function is invoked to process one of the options which may be
 *	specified for the photo image subcommands, namely, -from, -to, -zoom,
 *	-subsample, -format, -shrink, -compositingrule, -alpha, -boolean,
 *	-withalpha and -metadata.
 *	-subsample, -format, -shrink, -compositingrule, -alpha, -boolean and
 *	-withalpha.
 *	Parsing starts at the index in *optIndexPtr and stops at the end of
 *	objv[] or at the first value that does not belong to an option.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
1589
1590
1591
1592
1593
1594
1595
1596

1597
1598
1599

1600
1601
1602
1603
1604
1605
1606
1607
1608
1609



1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620


1621
1622
1623
1624
1625
1626
1627
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465



1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1486
1487







-
+


-
+







-
-
-
+
+
+










-
+
+







ParseSubcommandOptions(
    struct SubcommandOptions *optPtr,
				/* Information about the options specified and
				 * the values given is returned here. */
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    int allowedOptions,		/* Indicates which options are valid for the
				 * current command. */
    Tcl_Size *optIndexPtr,		/* Points to a variable containing the current
    int *optIndexPtr,		/* Points to a variable containing the current
				 * index in objv; this variable is updated by
				 * this function. */
    Tcl_Size objc,			/* Number of arguments in objv[]. */
    int objc,			/* Number of arguments in objv[]. */
    Tcl_Obj *const objv[])	/* Arguments to be parsed. */
{
    static const char *const compositingRules[] = {
	"overlay", "set",	/* Note that these must match the
				 * TK_PHOTO_COMPOSITE_* constants. */
	NULL
    };
    Tcl_Size index, length, argIndex;
    int c, bit, currentBit;
    int values[4], numValues, maxValues;
    size_t length;
    int index, c, bit, currentBit;
    int values[4], numValues, maxValues, argIndex;
    const char *option, *expandedOption, *needed;
    const char *const *listPtr;
    Tcl_Obj *msgObj;

    for (index = *optIndexPtr; index < objc; *optIndexPtr = ++index) {
	/*
	 * We can have one value specified without an option; it goes into
	 * optPtr->name.
	 */

	expandedOption = option = Tcl_GetStringFromObj(objv[index], &length);
	expandedOption = option = Tcl_GetString(objv[index]);
	length = objv[index]->length;
	if (option[0] != '-') {
	    if (optPtr->name == NULL) {
		optPtr->name = objv[index];
		continue;
	    }
	    break;
	}
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
1544
1545
1546
1547
1548
1549
1550











1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574







-
-
-
-
-
-
-
-
-
-
-
















-
+







	     */

	    if (index + 1 >= objc) {
		goto oneValueRequired;
	    }
	    *optIndexPtr = ++index;
	    optPtr->format = objv[index];
	} else if (bit == OPT_METADATA) {
	    /*
	    * The -metadata option takes a single dict value. Note that
	    * parsing this is outside the scope of this function.
	    */

	    if (index + 1 >= objc) {
		goto oneValueRequired;
	    }
	    *optIndexPtr = ++index;
	    optPtr->metadata = objv[index];
	} else if (bit == OPT_COMPOSITE) {
	    /*
	     * The -compositingrule option takes a single value from a
	     * well-known set.
	     */

	    if (index + 1 >= objc) {
		goto oneValueRequired;
	    }
	    index++;
	    if (Tcl_GetIndexFromObj(interp, objv[index], compositingRules,
		    "compositing rule", 0, &optPtr->compositingRule)
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	    *optIndexPtr = index;
	} else if (bit == OPT_TO || bit == OPT_FROM
	} else if (bit == OPT_TO || bit == OPT_FROM 
		|| bit == OPT_SUBSAMPLE || bit == OPT_ZOOM) {
	    const char *val;

	    maxValues = ((bit == OPT_FROM) || (bit == OPT_TO)) ? 4 : 2;
	    argIndex = index + 1;
	    for (numValues = 0; numValues < maxValues; ++numValues) {
		if (argIndex >= objc) {
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
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







-
+






-
+





-
+









-
+

-
+


-
+




-
+






-
+







-
+









-
+

-
+

-
+






-
+
-

-
-
+
+



-
+

+
-
-
-
-
-
+
+
+
+
+
+


+

+

-
+

-
+


-
-
+
+


+

+

-
+

-
+
-
-
-
-
-
-
-
-
-
-
-













-
+

-
+






-
+



-
-
+
+






-
+
+


+


-
+


-
-
-
+
+
+






-
+







-
-
+
+

-
+













-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+
+

-
-
+
+








-
-
-
+
+
+









-
+



-
+




-
-
-
-
-
-
-






-
+
-
-
-
+
+



-
+



-
-
+
+


-
+



-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-






-
+


-
-
-
+
+
+

-
-
-
-
-
-
-
-
+
-
-
+



-
+

-
-
+
+


-
-
+
+






-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
-
-

-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
+
+


-
-
-
+
+
+








-
+








-
-
-
+
+
+







-
-
-
+
-
-
+










-
-
-
















-
+






-
+




-
+










-















-
+













-
+


-
+


-
+






-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
-
-
-
+
+







    /*
     * Exception generation.
     */

  oneValueRequired:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "the \"%s\" option requires a value", expandedOption));
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "MISSING_VALUE", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "MISSING_VALUE", NULL);
    return TCL_ERROR;

  manyValuesRequired:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "the \"%s\" option requires one %s integer values",
	    expandedOption, (maxValues == 2) ? "or two": "to four"));
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "MISSING_VALUE", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "MISSING_VALUE", NULL);
    return TCL_ERROR;

  numberOutOfRange:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "value(s) for the %s option must be %s", expandedOption, needed));
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_VALUE", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_VALUE", NULL);
    return TCL_ERROR;

  unknownOrAmbiguousOption:
    msgObj = Tcl_ObjPrintf("unrecognized option \"%s\": must be ", option);
    bit = 1;
    for (listPtr = optionNames; *listPtr != NULL; ++listPtr) {
	if (allowedOptions & bit) {
	    if (allowedOptions & (bit - 1)) {
		if (allowedOptions & ~((bit << 1) - 1)) {
		    Tcl_AppendToObj(msgObj, ", ", TCL_INDEX_NONE);
		    Tcl_AppendToObj(msgObj, ", ", -1);
		} else {
		    Tcl_AppendToObj(msgObj, ", or ", TCL_INDEX_NONE);
		    Tcl_AppendToObj(msgObj, ", or ", -1);
		}
	    }
	    Tcl_AppendToObj(msgObj, *listPtr, TCL_INDEX_NONE);
	    Tcl_AppendToObj(msgObj, *listPtr, -1);
	}
	bit <<= 1;
    }
    Tcl_SetObjResult(interp, msgObj);
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoConfigureModel --
 * ImgPhotoConfigureMaster --
 *
 *	This function is called when a photo image is created or reconfigured.
 *	It processes configuration options and resets any instances of the
 *	image.
 *
 * Results:
 *	A standard Tcl return value. If TCL_ERROR is returned then an error
 *	message is left in the modelPtr->interp's result.
 *	message is left in the masterPtr->interp's result.
 *
 * Side effects:
 *	Existing instances of the image will be redisplayed to match the new
 *	configuration options.
 *
 *----------------------------------------------------------------------
 */

static int
ImgPhotoConfigureModel(
ImgPhotoConfigureMaster(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    PhotoModel *modelPtr,	/* Pointer to data structure describing
    PhotoMaster *masterPtr,	/* Pointer to data structure describing
				 * overall photo image to (re)configure. */
    Tcl_Size objc,			/* Number of entries in objv. */
    int objc,			/* Number of entries in objv. */
    Tcl_Obj *const objv[],	/* Pairs of configuration options for image. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget, such
				 * as TK_CONFIG_ARGV_ONLY. */
{
    PhotoInstance *instancePtr;
    const char *oldFileString, *oldPaletteString;
    Tcl_Obj *oldData, *data = NULL, *oldFormat, *format = NULL,
    Tcl_Obj *oldData, *data = NULL, *oldFormat, *format = NULL;
	    *metadataInObj = NULL, *metadataOutObj = NULL;
    Tcl_Obj *tempdata, *tempformat;
    Tcl_Size i, length;
    int result, imageWidth, imageHeight, oldformat;
    size_t length;
    int i, j, result, imageWidth, imageHeight, oldformat;
    double oldGamma;
    Tcl_Channel chan;
    Tk_PhotoImageFormat *imageFormat;
    Tk_PhotoImageFormatVersion3 *imageFormatVersion3;
    const char **args;

    args = ckalloc((objc + 1) * sizeof(char *));
    for (i = 0; i < objc; i++) {
	const char *arg = Tcl_GetStringFromObj(objv[i], &length);
	if ((length > 1) && (arg[0] == '-')) {
	    if ((arg[1] == 'd') &&
		    !strncmp(arg, "-data", length)) {
    for (i = 0, j = 0; i < objc; i++,j++) {
	args[j] = Tcl_GetString(objv[i]);
	length = objv[i]->length;
	if ((length > 1) && (args[j][0] == '-')) {
	    if ((args[j][1] == 'd') &&
		    !strncmp(args[j], "-data", length)) {
		if (++i < objc) {
		    data = objv[i];
		    j--;
		} else {
		    ckfree(args);
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "value for \"-data\" missing", TCL_INDEX_NONE));
			    "value for \"-data\" missing", -1));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			    "MISSING_VALUE", (char *)NULL);
			    "MISSING_VALUE", NULL);
		    return TCL_ERROR;
		}
	    } else if ((arg[1] == 'f') &&
		    !strncmp(arg, "-format", length)) {
	    } else if ((args[j][1] == 'f') &&
		    !strncmp(args[j], "-format", length)) {
		if (++i < objc) {
		    format = objv[i];
		    j--;
		} else {
		    ckfree(args);
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "value for \"-format\" missing", TCL_INDEX_NONE));
			    "value for \"-format\" missing", -1));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			    "MISSING_VALUE", (char *)NULL);
			    "MISSING_VALUE", NULL);
		    return TCL_ERROR;
		}
	    } else if ((arg[1] == 'm') &&
		!strncmp(arg, "-metadata", length)) {
		if (++i < objc) {
		    metadataInObj = objv[i];
		} else {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"value for \"-metadata\" missing", TCL_INDEX_NONE));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			"MISSING_VALUE", (char *)NULL);
		    return TCL_ERROR;
		}
	    }
	}
    }

    /*
     * Save the current values for fileString and dataString, so we can tell
     * if the user specifies them anew. IMPORTANT: if the format changes we
     * have to interpret "-file" and "-data" again as well! It might be that
     * the format string influences how "-data" or "-file" is interpreted.
     */

    oldFileString = modelPtr->fileString;
    oldFileString = masterPtr->fileString;
    if (oldFileString == NULL) {
	oldData = modelPtr->dataString;
	oldData = masterPtr->dataString;
	if (oldData != NULL) {
	    Tcl_IncrRefCount(oldData);
	}
    } else {
	oldData = NULL;
    }
    oldFormat = modelPtr->format;
    oldFormat = masterPtr->format;
    if (oldFormat != NULL) {
	Tcl_IncrRefCount(oldFormat);
    }
    oldPaletteString = modelPtr->palette;
    oldGamma = modelPtr->gamma;
    oldPaletteString = masterPtr->palette;
    oldGamma = masterPtr->gamma;

    /*
     * Process the configuration options specified.
     */

    if (Tk_ConfigureWidget(interp, Tk_MainWindow(interp), configSpecs,
	    objc, objv, modelPtr, flags) != TCL_OK) {
	    j, args, (char *) masterPtr, flags) != TCL_OK) {
	ckfree(args);
	goto errorExit;
    }
    ckfree(args);

    /*
     * Regard the empty string for -file, -data, -format or -metadata as the null value.
     * Regard the empty string for -file, -data or -format as the null value.
     */

    if ((modelPtr->fileString != NULL) && (modelPtr->fileString[0] == 0)) {
	ckfree(modelPtr->fileString);
	modelPtr->fileString = NULL;
    if ((masterPtr->fileString != NULL) && (masterPtr->fileString[0] == 0)) {
	ckfree(masterPtr->fileString);
	masterPtr->fileString = NULL;
    }
    if (data) {
	/*
	 * Force into ByteArray format, which most (all) image handlers will
	 * use anyway. Empty length means ignore the -data option.
	 */
	Tcl_Size bytesize;
	int bytesize;

	(void) Tcl_GetByteArrayFromObj(data, &bytesize);
	if (bytesize) {
	    Tcl_IncrRefCount(data);
	} else {
	    data = NULL;
	}
	if (modelPtr->dataString) {
	    Tcl_DecrRefCount(modelPtr->dataString);
	if (masterPtr->dataString) {
	    Tcl_DecrRefCount(masterPtr->dataString);
	}
	modelPtr->dataString = data;
	masterPtr->dataString = data;
    }
    if (format) {
	/*
	 * Stringify to ignore -format "". It may come in as a list or other
	 * object.
	 */

	(void) Tcl_GetString(format);
	if (format->length) {
	    Tcl_IncrRefCount(format);
	} else {
	    format = NULL;
	}
	if (modelPtr->format) {
	    Tcl_DecrRefCount(modelPtr->format);
	if (masterPtr->format) {
	    Tcl_DecrRefCount(masterPtr->format);
	}
	modelPtr->format = format;
	masterPtr->format = format;
    }
    if (metadataInObj) {
	/*
	 * Make -metadata a dict.
	 * Take also empty metadatas as this may be a sign to replace
	 * existing metadata.
	 */
	Tcl_Size dictSize;

	if (TCL_OK != Tcl_DictObjSize(interp,metadataInObj, &dictSize)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "value for \"-metadata\" not a dict", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
		    "UNRECOGNIZED_DATA", (char *)NULL);
	    return TCL_ERROR;
	}

	if (dictSize > 0) {
	    Tcl_IncrRefCount(metadataInObj);
	} else {
	    metadataInObj = NULL;
	}
	if (modelPtr->metadata) {
	    Tcl_DecrRefCount(modelPtr->metadata);
	}
	modelPtr->metadata = metadataInObj;
    }
    /*
     * Set the image to the user-requested size, if any, and make sure storage
     * is correctly allocated for this image.
     */

    if (ImgPhotoSetSize(modelPtr, modelPtr->width,
	    modelPtr->height) != TCL_OK) {
    if (ImgPhotoSetSize(masterPtr, masterPtr->width,
	    masterPtr->height) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
		TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
	Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	goto errorExit;
    }

    /*
     * Read in the image from the file or string if the user has specified the
     * -file or -data option.
     */

    if ((modelPtr->fileString != NULL)
	    && ((modelPtr->fileString != oldFileString)
	    || (modelPtr->format != oldFormat))) {
    if ((masterPtr->fileString != NULL)
	    && ((masterPtr->fileString != oldFileString)
	    || (masterPtr->format != oldFormat))) {
	/*
	 * Prevent file system access in a safe interpreter.
	 */

	if (Tcl_IsSafe(interp)) {
	    Tcl_ResetResult(interp);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't get image from a file in a safe interpreter",
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "PHOTO_FILE", NULL);
	    goto errorExit;
	}

	chan = Tcl_OpenFileChannel(interp, modelPtr->fileString, "r", 0);
	chan = Tcl_OpenFileChannel(interp, masterPtr->fileString, "r", 0);
	if (chan == NULL) {
	    goto errorExit;
	}

	/*
	 * Flag that we want the metadata result dict
	 */

	metadataOutObj = Tcl_NewDictObj();
	Tcl_IncrRefCount(metadataOutObj);

	/*
	 * -translation binary also sets -encoding binary
	 */

	if ((Tcl_SetChannelOption(interp, chan,
		"-translation", "binary") != TCL_OK) ||
		(MatchFileFormat(interp, chan, modelPtr->fileString,
		(MatchFileFormat(interp, chan, masterPtr->fileString,
			modelPtr->format, modelPtr->metadata, metadataOutObj,
			&imageFormat, &imageFormatVersion3,
			&imageWidth, &imageHeight, &oldformat) != TCL_OK)) {
			masterPtr->format, &imageFormat, &imageWidth,
			&imageHeight, &oldformat) != TCL_OK)) {
	    Tcl_Close(NULL, chan);
	    goto errorExit;
	}
	result = ImgPhotoSetSize(modelPtr, imageWidth, imageHeight);
	result = ImgPhotoSetSize(masterPtr, imageWidth, imageHeight);
	if (result != TCL_OK) {
	    Tcl_Close(NULL, chan);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    goto errorExit;
	}
	tempformat = modelPtr->format;
	tempformat = masterPtr->format;
	if (oldformat && tempformat) {
	    tempformat = (Tcl_Obj *) Tcl_GetString(tempformat);
	}
	if (imageFormat != NULL) {
	    result = imageFormat->fileReadProc(interp, chan,
		    modelPtr->fileString, tempformat,
	result = imageFormat->fileReadProc(interp, chan,
		masterPtr->fileString, tempformat, (Tk_PhotoHandle) masterPtr,
		    (Tk_PhotoHandle) modelPtr,
		    0, 0, imageWidth, imageHeight, 0, 0);
		0, 0, imageWidth, imageHeight, 0, 0);
	} else {
	    result = imageFormatVersion3->fileReadProc(interp, chan,
		    modelPtr->fileString, tempformat, modelPtr->metadata,
		    (Tk_PhotoHandle) modelPtr,
		    0, 0, imageWidth, imageHeight, 0, 0,
		    metadataOutObj);
	}

	Tcl_Close(NULL, chan);
	if (result != TCL_OK) {
	    goto errorExit;
	}

	Tcl_ResetResult(interp);
	modelPtr->flags |= IMAGE_CHANGED;
	masterPtr->flags |= IMAGE_CHANGED;
    }

    if ((modelPtr->fileString == NULL) && (modelPtr->dataString != NULL)
	    && ((modelPtr->dataString != oldData)
		    || (modelPtr->format != oldFormat))) {
    if ((masterPtr->fileString == NULL) && (masterPtr->dataString != NULL)
	    && ((masterPtr->dataString != oldData)
		    || (masterPtr->format != oldFormat))) {

	/*
	 * Flag that we want the metadata result dict
	 */

	metadataOutObj = Tcl_NewDictObj();
	Tcl_IncrRefCount(metadataOutObj);

	if (MatchStringFormat(interp, modelPtr->dataString,
	if (MatchStringFormat(interp, masterPtr->dataString,
		modelPtr->format, modelPtr->metadata, metadataOutObj,
		&imageFormat, &imageFormatVersion3, &imageWidth,
		masterPtr->format, &imageFormat, &imageWidth,
		&imageHeight, &oldformat) != TCL_OK) {
	    goto errorExit;
	}
	if (ImgPhotoSetSize(modelPtr, imageWidth, imageHeight) != TCL_OK) {
	if (ImgPhotoSetSize(masterPtr, imageWidth, imageHeight) != TCL_OK) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    goto errorExit;
	}
	tempformat = modelPtr->format;
	tempdata = modelPtr->dataString;
	tempformat = masterPtr->format;
	tempdata = masterPtr->dataString;
	if (oldformat) {
	    if (tempformat) {
		tempformat = (Tcl_Obj *) Tcl_GetString(tempformat);
	    }
	    tempdata = (Tcl_Obj *) Tcl_GetString(tempdata);
	}
	if (imageFormat != NULL) {
	    if (imageFormat->stringReadProc(interp, tempdata, tempformat,
		    (Tk_PhotoHandle) modelPtr, 0, 0, imageWidth, imageHeight,
		    0, 0) != TCL_OK) {
		goto errorExit;
	    }
	if (imageFormat->stringReadProc(interp, tempdata, tempformat,
		(Tk_PhotoHandle) masterPtr, 0, 0, imageWidth, imageHeight,
		0, 0) != TCL_OK) {
	    goto errorExit;
	}
	} else {
	    if (imageFormatVersion3->stringReadProc(interp, tempdata, tempformat,
		    modelPtr->metadata, (Tk_PhotoHandle) modelPtr, 0, 0,
		    imageWidth, imageHeight, 0, 0, metadataOutObj) != TCL_OK) {
		goto errorExit;
	    }

	}

	Tcl_ResetResult(interp);
	modelPtr->flags |= IMAGE_CHANGED;
	masterPtr->flags |= IMAGE_CHANGED;
    }

    /*
     * Merge driver returned metadata and master metadata
     */
    if (metadataOutObj != NULL) {
	Tcl_Size dictSize;
	if (TCL_OK != Tcl_DictObjSize(interp,metadataOutObj, &dictSize)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "driver metadata not a dict", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
		    "UNRECOGNIZED_DATA", (char *)NULL);
	    goto errorExit;
	}
	if (dictSize > 0) {

	    /*
	     * We have driver return metadata
	     */

	    if (modelPtr->metadata == NULL) {
		modelPtr->metadata = metadataOutObj;
		metadataOutObj = NULL;
	    } else {
		Tcl_DictSearch search;
		Tcl_Obj *key, *value;
		int done;

		if (Tcl_IsShared(modelPtr->metadata)) {
		    Tcl_DecrRefCount(modelPtr->metadata);
		    modelPtr->metadata = Tcl_DuplicateObj(modelPtr->metadata);
		    Tcl_IncrRefCount(modelPtr->metadata);
		}

		if (Tcl_DictObjFirst(interp, metadataOutObj, &search, &key,
			&value, &done) != TCL_OK) {
		    goto errorExit;
		}
		for (; !done ; Tcl_DictObjNext(&search, &key, &value, &done)) {
		    Tcl_DictObjPut(interp, modelPtr->metadata, key, value);
		}
	    }
	}
    }

    /*
     * Enforce a reasonable value for gamma.
     */

    if (modelPtr->gamma <= 0) {
	modelPtr->gamma = 1.0;
    if (masterPtr->gamma <= 0) {
	masterPtr->gamma = 1.0;
    }

    if ((modelPtr->gamma != oldGamma)
	    || (modelPtr->palette != oldPaletteString)) {
	modelPtr->flags |= IMAGE_CHANGED;
    if ((masterPtr->gamma != oldGamma)
	    || (masterPtr->palette != oldPaletteString)) {
	masterPtr->flags |= IMAGE_CHANGED;
    }

    /*
     * Cycle through all of the instances of this image, regenerating the
     * information for each instance. Then force the image to be redisplayed
     * everywhere that it is used.
     */

    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	TkImgPhotoConfigureInstance(instancePtr);
    }

    /*
     * Inform the generic image code that the image has (potentially) changed.
     */

    Tk_ImageChanged(modelPtr->tkModel, 0, 0, modelPtr->width,
	    modelPtr->height, modelPtr->width, modelPtr->height);
    modelPtr->flags &= ~IMAGE_CHANGED;
    Tk_ImageChanged(masterPtr->tkMaster, 0, 0, masterPtr->width,
	    masterPtr->height, masterPtr->width, masterPtr->height);
    masterPtr->flags &= ~IMAGE_CHANGED;

    if (oldData != NULL) {
	Tcl_DecrRefCount(oldData);
    }
    if (oldFormat != NULL) {
	Tcl_DecrRefCount(oldFormat);
    }
    if (metadataOutObj != NULL) {
	Tcl_DecrRefCount(metadataOutObj);
    }


    ToggleComplexAlphaIfNeeded(modelPtr);
    ToggleComplexAlphaIfNeeded(masterPtr);

    return TCL_OK;

  errorExit:
    if (oldData != NULL) {
	Tcl_DecrRefCount(oldData);
    }
    if (oldFormat != NULL) {
	Tcl_DecrRefCount(oldFormat);
    }
    if (metadataOutObj != NULL) {
	Tcl_DecrRefCount(metadataOutObj);
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * ToggleComplexAlphaIfNeeded --
 *
 *	This function is called when an image is modified to check if any
 *	partially transparent pixels exist, which requires blending instead of
 *	straight copy.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	(Re)sets COMPLEX_ALPHA flag of model.
 *	(Re)sets COMPLEX_ALPHA flag of master.
 *
 *----------------------------------------------------------------------
 */

static int
ToggleComplexAlphaIfNeeded(
    PhotoModel *mPtr)
    PhotoMaster *mPtr)
{
    size_t len = (size_t)MAX(mPtr->userWidth, mPtr->width) *
	    (size_t)MAX(mPtr->userHeight, mPtr->height) * 4;
    unsigned char *c = mPtr->pix32;
    unsigned char *end;
    unsigned char *end = c + len;

    /*
     * Set the COMPLEX_ALPHA flag if we have an image with partially
     * transparent bits.
     */

    mPtr->flags &= ~COMPLEX_ALPHA;
    if (c == NULL) {
	return 0;
    }
    end = c + len;
    c += 3;			/* Start at first alpha byte. */
    for (; c < end; c += 4) {
	if (*c && *c != 255) {
     	    mPtr->flags |= COMPLEX_ALPHA;
	    break;
	}
    }
    return (mPtr->flags & COMPLEX_ALPHA);
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoDelete --
 *
 *	This function is called by the image code to delete the model
 *	This function is called by the image code to delete the master
 *	structure for an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Resources associated with the image get freed.
 *
 *----------------------------------------------------------------------
 */

static void
ImgPhotoDelete(
    void *modelData)	/* Pointer to PhotoModel structure for image.
    ClientData masterData)	/* Pointer to PhotoMaster structure for image.
				 * Must not have any more instances. */
{
    PhotoModel *modelPtr = (PhotoModel *)modelData;
    PhotoMaster *masterPtr = masterData;
    PhotoInstance *instancePtr;

    while ((instancePtr = modelPtr->instancePtr) != NULL) {
    while ((instancePtr = masterPtr->instancePtr) != NULL) {
	if (instancePtr->refCount > 0) {
	    Tcl_Panic("tried to delete photo image when instances still exist");
	}
	Tcl_CancelIdleCall(TkImgDisposeInstance, instancePtr);
	TkImgDisposeInstance(instancePtr);
    }
    modelPtr->tkModel = NULL;
    if (modelPtr->imageCmd != NULL) {
	Tcl_DeleteCommandFromToken(modelPtr->interp, modelPtr->imageCmd);
    masterPtr->tkMaster = NULL;
    if (masterPtr->imageCmd != NULL) {
	Tcl_DeleteCommandFromToken(masterPtr->interp, masterPtr->imageCmd);
    }
    if (modelPtr->pix32 != NULL) {
	ckfree(modelPtr->pix32);
    if (masterPtr->pix32 != NULL) {
	ckfree(masterPtr->pix32);
    }
    if (modelPtr->validRegion != NULL) {
	TkDestroyRegion(modelPtr->validRegion);
    if (masterPtr->validRegion != NULL) {
	TkDestroyRegion(masterPtr->validRegion);
    }
    if (modelPtr->dataString != NULL) {
	Tcl_DecrRefCount(modelPtr->dataString);
    if (masterPtr->dataString != NULL) {
	Tcl_DecrRefCount(masterPtr->dataString);
    }
    if (modelPtr->format != NULL) {
	Tcl_DecrRefCount(modelPtr->format);
    if (masterPtr->format != NULL) {
	Tcl_DecrRefCount(masterPtr->format);
    }
    if (modelPtr->metadata != NULL) {
	Tcl_DecrRefCount(modelPtr->metadata);
    }
    Tk_FreeOptions(configSpecs, modelPtr, NULL, 0);
    ckfree(modelPtr);
    Tk_FreeOptions(configSpecs, (char *) masterPtr, NULL, 0);
    ckfree(masterPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoCmdDeletedProc --
 *
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
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







-
+


-
+

-
-
-
+
+
+

















-
+






-
+









-
-
+
+

-
-
+
+













-
-
+
+














-
+











-
+








-
-
+
+

-
+















-
-
+
+











-
+





-
+






-
+








-
+




-
+



-
+


-
-
-
+
+
+







-
-
+
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+



-
+





-
+



















-
-
-
+
+
+













-
-


-
+
-
-
-
-
-





-
+
-

-
-
+







 *	The image is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ImgPhotoCmdDeletedProc(
    void *clientData)	/* Pointer to PhotoModel structure for
    ClientData clientData)	/* Pointer to PhotoMaster structure for
				 * image. */
{
    PhotoModel *modelPtr = (PhotoModel *)clientData;
    PhotoMaster *masterPtr = clientData;

    modelPtr->imageCmd = NULL;
    if (modelPtr->tkModel != NULL) {
	Tk_DeleteImage(modelPtr->interp, Tk_NameOfImage(modelPtr->tkModel));
    masterPtr->imageCmd = NULL;
    if (masterPtr->tkMaster != NULL) {
	Tk_DeleteImage(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster));
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ImgPhotoSetSize --
 *
 *	This function reallocates the image storage and instance pixmaps for a
 *	photo image, as necessary, to change the image's size to `width' x
 *	`height' pixels.
 *
 * Results:
 *	TCL_OK if successful, TCL_ERROR if failure occurred (currently just
 *	with memory allocation.)
 *
 * Side effects:
 *	Storage gets reallocated, for the model and all its instances.
 *	Storage gets reallocated, for the master and all its instances.
 *
 *----------------------------------------------------------------------
 */

static int
ImgPhotoSetSize(
    PhotoModel *modelPtr,
    PhotoMaster *masterPtr,
    int width, int height)
{
    unsigned char *newPix32 = NULL;
    int h, offset, pitch;
    unsigned char *srcPtr, *destPtr;
    XRectangle validBox, clipBox;
    TkRegion clipRegion;
    PhotoInstance *instancePtr;

    if (modelPtr->userWidth > 0) {
	width = modelPtr->userWidth;
    if (masterPtr->userWidth > 0) {
	width = masterPtr->userWidth;
    }
    if (modelPtr->userHeight > 0) {
	height = modelPtr->userHeight;
    if (masterPtr->userHeight > 0) {
	height = masterPtr->userHeight;
    }

    if (width > INT_MAX / 4) {
	/* Pitch overflows int */
	return TCL_ERROR;
    }
    pitch = width * 4;

    /*
     * Test if we're going to (re)allocate the main buffer now, so that any
     * failures will leave the photo unchanged.
     */

    if ((width != modelPtr->width) || (height != modelPtr->height)
	    || (modelPtr->pix32 == NULL)) {
    if ((width != masterPtr->width) || (height != masterPtr->height)
	    || (masterPtr->pix32 == NULL)) {
	unsigned newPixSize;

	if (pitch && height > (int)(UINT_MAX / pitch)) {
	    return TCL_ERROR;
	}
	newPixSize = height * pitch;

	/*
	 * Some mallocs() really hate allocating zero bytes. [Bug 619544]
	 */

	if (newPixSize == 0) {
	    newPix32 = NULL;
	} else {
	    newPix32 = (unsigned char *)attemptckalloc(newPixSize);
	    newPix32 = attemptckalloc(newPixSize);
	    if (newPix32 == NULL) {
		return TCL_ERROR;
	    }
	}
    }

    /*
     * We have to trim the valid region if it is currently larger than the new
     * image size.
     */

    TkClipBox(modelPtr->validRegion, &validBox);
    TkClipBox(masterPtr->validRegion, &validBox);
    if ((validBox.x + validBox.width > width)
	    || (validBox.y + validBox.height > height)) {
	clipBox.x = 0;
	clipBox.y = 0;
	clipBox.width = width;
	clipBox.height = height;
	clipRegion = TkCreateRegion();
	TkUnionRectWithRegion(&clipBox, clipRegion, clipRegion);
	TkIntersectRegion(modelPtr->validRegion, clipRegion,
		modelPtr->validRegion);
	TkIntersectRegion(masterPtr->validRegion, clipRegion,
		masterPtr->validRegion);
	TkDestroyRegion(clipRegion);
	TkClipBox(modelPtr->validRegion, &validBox);
	TkClipBox(masterPtr->validRegion, &validBox);
    }

    /*
     * Use the reallocated storage (allocation above) for the 32-bit image and
     * copy over valid regions. Note that this test is true precisely when the
     * allocation has already been done.
     */

    if (newPix32 != NULL) {
	/*
	 * Zero the new array. The dithering code shouldn't read the areas
	 * outside validBox, but they might be copied to another photo image
	 * or written to a file.
	 */

	if ((modelPtr->pix32 != NULL)
	    && ((width == modelPtr->width) || (width == validBox.width))) {
	if ((masterPtr->pix32 != NULL)
	    && ((width == masterPtr->width) || (width == validBox.width))) {
	    if (validBox.y > 0) {
		memset(newPix32, 0, ((size_t) validBox.y * pitch));
	    }
	    h = validBox.y + validBox.height;
	    if (h < height) {
		memset(newPix32 + h*pitch, 0, ((size_t) (height - h) * pitch));
	    }
	} else {
	    memset(newPix32, 0, ((size_t)height * pitch));
	}

	if (modelPtr->pix32 != NULL) {
	if (masterPtr->pix32 != NULL) {
	    /*
	     * Copy the common area over to the new array array and free the
	     * old array.
	     */

	    if (width == modelPtr->width) {
	    if (width == masterPtr->width) {

		/*
		 * The region to be copied is contiguous.
		 */

		offset = validBox.y * pitch;
		memcpy(newPix32 + offset, modelPtr->pix32 + offset,
		memcpy(newPix32 + offset, masterPtr->pix32 + offset,
			((size_t)validBox.height * pitch));

	    } else if ((validBox.width > 0) && (validBox.height > 0)) {
		/*
		 * Area to be copied is not contiguous - copy line by line.
		 */

		destPtr = newPix32 + (validBox.y * width + validBox.x) * 4;
		srcPtr = modelPtr->pix32 + (validBox.y * modelPtr->width
		srcPtr = masterPtr->pix32 + (validBox.y * masterPtr->width
			+ validBox.x) * 4;
		for (h = validBox.height; h > 0; h--) {
		    memcpy(destPtr, srcPtr, ((size_t)validBox.width * 4));
		    destPtr += width * 4;
		    srcPtr += modelPtr->width * 4;
		    srcPtr += masterPtr->width * 4;
		}
	    }

	    ckfree(modelPtr->pix32);
	    ckfree(masterPtr->pix32);
	}

	modelPtr->pix32 = newPix32;
	modelPtr->width = width;
	modelPtr->height = height;
	masterPtr->pix32 = newPix32;
	masterPtr->width = width;
	masterPtr->height = height;

	/*
	 * Dithering will be correct up to the end of the last pre-existing
	 * complete scanline.
	 */

	if ((validBox.x > 0) || (validBox.y > 0)) {
	    modelPtr->ditherX = 0;
	    modelPtr->ditherY = 0;
	    masterPtr->ditherX = 0;
	    masterPtr->ditherY = 0;
	} else if (validBox.width == width) {
	    if ((int) validBox.height < modelPtr->ditherY) {
		modelPtr->ditherX = 0;
		modelPtr->ditherY = validBox.height;
	    if ((int) validBox.height < masterPtr->ditherY) {
		masterPtr->ditherX = 0;
		masterPtr->ditherY = validBox.height;
	    }
	} else if ((modelPtr->ditherY > 0)
		|| ((int) validBox.width < modelPtr->ditherX)) {
	    modelPtr->ditherX = validBox.width;
	    modelPtr->ditherY = 0;
	} else if ((masterPtr->ditherY > 0)
		|| ((int) validBox.width < masterPtr->ditherX)) {
	    masterPtr->ditherX = validBox.width;
	    masterPtr->ditherY = 0;
	}
    }

    ToggleComplexAlphaIfNeeded(modelPtr);
    ToggleComplexAlphaIfNeeded(masterPtr);

    /*
     * Now adjust the sizes of the pixmaps for all of the instances.
     */

    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	TkImgPhotoInstanceSetSize(instancePtr);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * MatchFileFormat --
 *
 *	This function is called to find a photo image file format handler
 *	which can parse the image data in the given file. If a user-specified
 *	format string is provided, only handlers whose names match a prefix of
 *	the format string are tried.
 *
 * Results:
 *	A standard TCL return value. If the return value is TCL_OK, a pointer
 *	to the image format record is returned in *imageFormatPtr or
 *	*imageFormatVersion3Ptr, and the width and height of the image are
 *	returned in *widthPtr and *heightPtr.
 *	to the image format record is returned in *imageFormatPtr, and the
 *	width and height of the image are returned in *widthPtr and
 *	*heightPtr.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
MatchFileFormat(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Channel chan,		/* The image file, open for reading. */
    const char *fileName,	/* The name of the image file. */
    Tcl_Obj *formatObj,		/* User-specified format string, or NULL. */
    Tcl_Obj *metadataInObj,	/* User-specified metadata, may be NULL */
    Tcl_Obj *metadataOutObj,	/* metadata to return, may be NULL */
    Tk_PhotoImageFormat **imageFormatPtr,
				/* A pointer to the photo image format record
				 * is returned here. For formatVersion3, this is
				 * is returned here. */
				 * set to NULL */
    Tk_PhotoImageFormatVersion3 **imageFormatVersion3Ptr,
				/* A pointer to the photo image formatVersion3
				 * record is returned here. For non
				 * formatVersion3, this is set to NULL*/
    int *widthPtr, int *heightPtr,
				/* The dimensions of the image are returned
				 * here. */
    int *oldformat)		/* Returns 1 if the old image API is used. */
{
    int matched = 0;
    int matched = 0, useoldformat = 0;
    int useoldformat = 0;
    Tk_PhotoImageFormat *formatPtr;
    Tk_PhotoImageFormatVersion3 *formatVersion3Ptr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    const char *formatString = NULL;

    if (formatObj) {
	formatString = Tcl_GetString(formatObj);
    }

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
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







-
+


















-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
-
-
+
+
+












-
-


-
+
-
-
-
-
-







-
-
+







	    }
	    matched = 1;
	    if (formatPtr->fileMatchProc == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"-file option isn't supported for %s images",
			formatString));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			"NOT_FILE_FORMAT", (char *)NULL);
			"NOT_FILE_FORMAT", NULL);
		return TCL_ERROR;
	    }
	}
	if (formatPtr->fileMatchProc != NULL) {
	    (void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);

	    if (formatPtr->fileMatchProc(chan, fileName, formatObj,
		    widthPtr, heightPtr, interp)) {
		if (*widthPtr < 1) {
		    *widthPtr = 1;
		}
		if (*heightPtr < 1) {
		    *heightPtr = 1;
		}
		break;
	    }
	}
    }

    /*
     * For old and not version 3 format, exit now with success
     */

    if (formatPtr != NULL) {
    if (formatPtr == NULL) {
	*imageFormatPtr = formatPtr;
	*imageFormatVersion3Ptr = NULL;
	*oldformat = useoldformat;
	useoldformat = 1;
	(void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);
	return TCL_OK;
    }

	for (formatPtr = tsdPtr->oldFormatList; formatPtr != NULL;
    /*
     * Scan through the table of file format version 3 handlers to find one
     * which can handle the image.
     */

		formatPtr = formatPtr->nextPtr) {
    for (formatVersion3Ptr = tsdPtr->formatListVersion3;
	    formatVersion3Ptr != NULL;
	    formatVersion3Ptr = formatVersion3Ptr->nextPtr) {
	if (formatObj != NULL) {
	    if (strncasecmp(formatString,
		    formatVersion3Ptr->name, strlen(formatVersion3Ptr->name))
	    if (formatString != NULL) {
		if (strncasecmp(formatString,
			formatPtr->name, strlen(formatPtr->name)) != 0) {
		    != 0) {
		continue;
	    }
	    matched = 1;
	    if (formatVersion3Ptr->fileMatchProc == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"-file option isn't supported for %s images",
			formatString));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			"NOT_FILE_FORMAT", (char *)NULL);
		return TCL_ERROR;
	    }
	}
	if (formatVersion3Ptr->fileMatchProc != NULL) {
	    (void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);

		    continue;
		}
		matched = 1;
		if (formatPtr->fileMatchProc == NULL) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "-file option isn't supported for %s images",
			    formatString));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			    "NOT_FILE_FORMAT", NULL);
		    return TCL_ERROR;
		}
	    }
	    if (formatPtr->fileMatchProc != NULL) {
		(void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);
		if (formatPtr->fileMatchProc(chan, fileName, (Tcl_Obj *)
	    if (formatVersion3Ptr->fileMatchProc(interp, chan, fileName,
		    formatObj, metadataInObj, widthPtr, heightPtr,
			formatString, widthPtr, heightPtr, interp)) {
		    metadataOutObj)) {
		if (*widthPtr < 1) {
		    *widthPtr = 1;
		}
		if (*heightPtr < 1) {
		    *heightPtr = 1;
		}
		    if (*widthPtr < 1) {
			*widthPtr = 1;
		    }
		    if (*heightPtr < 1) {
			*heightPtr = 1;
		    }
		*imageFormatVersion3Ptr = formatVersion3Ptr;
		*imageFormatPtr = NULL;
		*oldformat = 0;
		(void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);
		return TCL_OK;
	    }

		    break;
	    /*
	     * Check if driver has shared or changed the metadata Tcl object.
	     * In this case, release and recreate it.
	     */

		}
	    if (metadataOutObj != NULL) {
		Tcl_Size dictSize;
		if (Tcl_IsShared(metadataOutObj)
			|| TCL_OK != Tcl_DictObjSize(interp,metadataOutObj, &dictSize)
			|| dictSize > 0) {
		    Tcl_DecrRefCount(metadataOutObj);
		    metadataOutObj = Tcl_NewDictObj();
		    Tcl_IncrRefCount(metadataOutObj);
		}
	    }
	}
    }

	    }
	}
    }

    if (formatPtr == NULL) {
    /*
     * No matching format found
     */

    if ((formatObj != NULL) && !matched) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"image file format \"%s\" is not supported",
		formatString));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
		formatString, (char *)NULL);
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't recognize data in image file \"%s\"",
		fileName));
	Tcl_SetErrorCode(interp, "TK", "PHOTO", "IMAGE",
		"UNRECOGNIZED_DATA", (char *)NULL);
    }
    return TCL_ERROR;
	if ((formatObj != NULL) && !matched) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "image file format \"%s\" is not supported",
		    formatString));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
		    formatString, NULL);
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "couldn't recognize data in image file \"%s\"",
		    fileName));
	    Tcl_SetErrorCode(interp, "TK", "PHOTO", "IMAGE",
		    "UNRECOGNIZED_DATA", NULL);
	}
	return TCL_ERROR;
    }

    *imageFormatPtr = formatPtr;
    *oldformat = useoldformat;
    (void) Tcl_Seek(chan, Tcl_LongAsWide(0L), SEEK_SET);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * MatchStringFormat --
 *
 *	This function is called to find a photo image file format handler
 *	which can parse the image data in the given string. If a
 *	user-specified format string is provided, only handlers whose names
 *	match a prefix of the format string are tried.
 *
 * Results:
 *	A standard TCL return value. If the return value is TCL_OK, a pointer
 *	to the image format record is returned in *imageFormatPtr or
 *	*imageFormatVersion3Ptr, and the width and height of the image are
 *	returned in *widthPtr and *heightPtr.
 *	to the image format record is returned in *imageFormatPtr, and the
 *	width and height of the image are returned in *widthPtr and
 *	*heightPtr.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
MatchStringFormat(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tcl_Obj *data,		/* Object containing the image data. */
    Tcl_Obj *formatObj,		/* User-specified format string, or NULL. */
    Tcl_Obj *metadataInObj,	/* User-specified metadata, may be NULL */
    Tcl_Obj *metadataOutObj,	/* metadata output dict, may be NULL */
    Tk_PhotoImageFormat **imageFormatPtr,
				/* A pointer to the photo image format record
				 * is returned here. For formatVersion3, this is
				 * is returned here. */
				 * set to NULL*/
    Tk_PhotoImageFormatVersion3 **imageFormatVersion3Ptr,
				/* A pointer to the photo image formatVersion3
				 * record is returned here. For non
				 * formatVersion3, this is set to NULL*/
    int *widthPtr, int *heightPtr,
				/* The dimensions of the image are returned
				 * here. */
    int *oldformat)		/* Returns 1 if the old image API is used. */
{
    int matched = 0, useoldformat = 0;
    Tk_PhotoImageFormat *formatPtr, *defaultFormatPtr = NULL;
    Tk_PhotoImageFormatVersion3 *formatVersion3Ptr = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    const char *formatString = NULL;

    if (formatObj) {
	formatString = Tcl_GetString(formatObj);
    }

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
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







-
+











-
+



-
+




-
+













-
-
+
+
-
-
+


-
+
-



-
+




-
+



-
-
-
-
+
+
+
+
+
+
-


-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+







-
+










-
+


-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-





-

-
+














-
+




















-
-
+
+







	 * list-of-lists string format is checked last. Remember its position.
	 */

	if (strncasecmp("default", formatPtr->name, strlen(formatPtr->name))
		== 0) {
	    defaultFormatPtr = formatPtr;
	}

      
	if (formatObj != NULL) {
	    if (strncasecmp(formatString,
		    formatPtr->name, strlen(formatPtr->name)) != 0) {
		continue;
	    }
	    matched = 1;
	    if (formatPtr->stringMatchProc == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"-data option isn't supported for %s images",
			formatString));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			"NOT_DATA_FORMAT", (char *)NULL);
			"NOT_DATA_FORMAT", NULL);
		return TCL_ERROR;
	    }
	}

	
	/*
	 * If this is the default format, and it was not passed as -format
	 * option, skip the stringMatchProc test. It'll be done later
	 */

	
	if (formatObj == NULL && formatPtr == defaultFormatPtr) {
	    continue;
	}

	if ((formatPtr->stringMatchProc != NULL)
		&& (formatPtr->stringReadProc != NULL)
		&& formatPtr->stringMatchProc(data, formatObj,
			widthPtr, heightPtr, interp)) {
	    break;
	}
    }

    if (formatPtr == NULL) {
	useoldformat = 0;
	for (formatVersion3Ptr = tsdPtr->formatListVersion3;
	useoldformat = 1;
	for (formatPtr = tsdPtr->oldFormatList; formatPtr != NULL;
		formatVersion3Ptr != NULL;
		formatVersion3Ptr = formatVersion3Ptr->nextPtr) {
		formatPtr = formatPtr->nextPtr) {
	    if (formatObj != NULL) {
		if (strncasecmp(formatString,
			formatVersion3Ptr->name, strlen(formatVersion3Ptr->name)
			formatPtr->name, strlen(formatPtr->name)) != 0) {
			) != 0) {
		    continue;
		}
		matched = 1;
		if (formatVersion3Ptr->stringMatchProc == NULL) {
		if (formatPtr->stringMatchProc == NULL) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "-data option isn't supported for %s images",
			    formatString));
		    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			    "NOT_DATA_FORMAT", (char *)NULL);
			    "NOT_DATA_FORMAT", NULL);
		    return TCL_ERROR;
		}
	    }
	    if ((formatVersion3Ptr->stringMatchProc != NULL)
		    && (formatVersion3Ptr->stringReadProc != NULL)
		    && formatVersion3Ptr->stringMatchProc(interp, data,
			    formatObj, metadataInObj, widthPtr, heightPtr,
	    if ((formatPtr->stringMatchProc != NULL)
		    && (formatPtr->stringReadProc != NULL)
		    && formatPtr->stringMatchProc(
			    (Tcl_Obj *) Tcl_GetString(data),
			    (Tcl_Obj *) formatString,
			    widthPtr, heightPtr, interp)) {
			    metadataOutObj)) {
		break;
	    }

	}
	    /*
	     * Check if driver has shared or changed the metadata tcl object.
	     * In this case, release and recreate it.
	     */

    }
	    if (metadataOutObj != NULL) {
		Tcl_Size dictSize;
		if (Tcl_IsShared(metadataOutObj)
			|| TCL_OK != Tcl_DictObjSize(interp,metadataOutObj, &dictSize)
			|| dictSize > 0) {
		    Tcl_DecrRefCount(metadataOutObj);
		    metadataOutObj = Tcl_NewDictObj();
		    Tcl_IncrRefCount(metadataOutObj);
		}
    
	    }
	}
    }

    if (formatPtr == NULL && formatVersion3Ptr == NULL) {
	/*
    if (formatPtr == NULL) {
	/* 
	 * Try the default format as last resort (only if no -format option
	 * was passed).
	 */

	if ( formatObj == NULL && defaultFormatPtr == NULL) {
	    Tcl_Panic("default image format handler not registered");
	}
	if ( formatObj == NULL
	if ( formatObj == NULL 
		&& defaultFormatPtr->stringMatchProc != NULL
		&& defaultFormatPtr->stringReadProc != NULL
		&& defaultFormatPtr->stringMatchProc(data, formatObj,
		widthPtr, heightPtr, interp) != 0) {
	    useoldformat = 0;
	    formatPtr = defaultFormatPtr;
	} else if ((formatObj != NULL) && !matched) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "image format \"%s\" is not supported", formatString));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
		    formatString, (char *)NULL);
		    formatString, NULL);
	    return TCL_ERROR;
	} else {

	    /*
	     * Some lower level routine (stringMatchProc) may have already set
	     * a specific error message, so just return this. Otherwise return
	     * a generic image data error.
	     */

	    if (Tcl_GetString(Tcl_GetObjResult(interp))[0] == '\0') {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"couldn't recognize image data", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
			"UNRECOGNIZED_DATA", (char *)NULL);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "couldn't recognize image data", -1));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
		    "UNRECOGNIZED_DATA", NULL);
	    }
	    return TCL_ERROR;
	}
    }

    *imageFormatPtr = formatPtr;
    *imageFormatVersion3Ptr = formatVersion3Ptr;
    *oldformat = useoldformat;

    
    /*
     * Some stringMatchProc might have left error messages and error codes in
     * interp.	Clear them before return.
     */
    Tcl_ResetResult(interp);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_FindPhoto --
 *
 *	This function is called to get an opaque handle (actually a
 *	PhotoModel *) for a given image, which can be used in subsequent
 *	PhotoMaster *) for a given image, which can be used in subsequent
 *	calls to Tk_PhotoPutBlock, etc. The `name' parameter is the name of
 *	the image.
 *
 * Results:
 *	The handle for the photo image, or NULL if there is no photo image
 *	with the name given.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_PhotoHandle
Tk_FindPhoto(
    Tcl_Interp *interp,		/* Interpreter (application) in which image
				 * exists. */
    const char *imageName)	/* Name of the desired photo image. */
{
    const Tk_ImageType *typePtr;
    void *clientData =
	    Tk_GetImageModelData(interp, imageName, &typePtr);
    ClientData clientData =
	    Tk_GetImageMasterData(interp, imageName, &typePtr);

    if ((typePtr == NULL) || (typePtr->name != tkPhotoImageType.name)) {
	return NULL;
    }
    return clientData;
}

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
3171


3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189

3190
3191
3192
3193
3194
3195
3196
3197
3198


3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209

3210
3211
3212
3213
3214
3215
3216
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







-
+


















-
-
+
+

-
-
-
+
+
+




















-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-



-
-
+
+




-
+
+





-
-
-
+
+
+


-
-
+
+





-
-
+
+




-
-
+
+

















-
+







-
-
+
+










-
+







    int x, int y,		/* Coordinates of the top-left pixel to be
				 * updated in the image. */
    int width, int height,	/* Dimensions of the area of the image to be
				 * updated. */
    int compRule)		/* Compositing rule to use when processing
				 * transparent pixels. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    register PhotoMaster *masterPtr = (PhotoMaster *) handle;
    Tk_PhotoImageBlock sourceBlock;
    unsigned char *memToFree;
    int xEnd, yEnd, greenOffset, blueOffset, alphaOffset;
    int wLeft, hLeft, wCopy, hCopy, pitch;
    unsigned char *srcPtr, *srcLinePtr, *destPtr, *destLinePtr;
    int sourceIsSimplePhoto = compRule & SOURCE_IS_SIMPLE_ALPHA_PHOTO;
    XRectangle rect;

    /*
     * Zero-sized blocks never cause any changes. [Bug 3078902]
     */

    if (blockPtr->height == 0 || blockPtr->width == 0) {
	return TCL_OK;
    }

    compRule &= ~SOURCE_IS_SIMPLE_ALPHA_PHOTO;

    if ((modelPtr->userWidth != 0) && ((x + width) > modelPtr->userWidth)) {
	width = modelPtr->userWidth - x;
    if ((masterPtr->userWidth != 0) && ((x + width) > masterPtr->userWidth)) {
	width = masterPtr->userWidth - x;
    }
    if ((modelPtr->userHeight != 0)
	    && ((y + height) > modelPtr->userHeight)) {
	height = modelPtr->userHeight - y;
    if ((masterPtr->userHeight != 0)
	    && ((y + height) > masterPtr->userHeight)) {
	height = masterPtr->userHeight - y;
    }
    if ((width <= 0) || (height <= 0)) {
	return TCL_OK;
    }

    /*
     * Fix for bug e4336bef5d:
     *
     * Make a local copy of *blockPtr, as we might have to change some
     * of its fields and don't want to interfere with the caller's data.
     *
     * If source and destination are the same image, create a copy  of the
     * source data in our local sourceBlock.
     *
     * To find out, just comparing the pointers is not enough - they might have
     * different values and still point to the same block of memory. (e.g.
     * if the -from option was passed to [imageName copy])
     */
    sourceBlock = *blockPtr;
    memToFree = NULL;
    if (modelPtr->pix32 && (sourceBlock.pixelPtr >= modelPtr->pix32)
	    && (sourceBlock.pixelPtr < modelPtr->pix32 + modelPtr->width
	    * modelPtr->height * 4)) {
    if (sourceBlock.pixelPtr >= masterPtr->pix32
	    && sourceBlock.pixelPtr <= masterPtr->pix32 + masterPtr->width
	    * masterPtr->height * 4) {
	/*
	 * Fix 5c51be6411: avoid reading
	 *
	 *	(sourceBlock.pitch - sourceBlock.width * sourceBlock.pixelSize)
	sourceBlock.pixelPtr = attemptckalloc(sourceBlock.height
	 *
	 * bytes past the end of modelPtr->pix32[] when
	 *
	 *	blockPtr->pixelPtr > (modelPtr->pix32 +
	 *		4 * modelPtr->width * modelPtr->height -
	 *		sourceBlock.height * sourceBlock.pitch)
		* sourceBlock.pitch);
	 */
	unsigned int cpyLen = (sourceBlock.height - 1) * sourceBlock.pitch +
		sourceBlock.width * sourceBlock.pixelSize;

	sourceBlock.pixelPtr = (unsigned char *)attemptckalloc(cpyLen);
	if (sourceBlock.pixelPtr == NULL) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    }
	    return TCL_ERROR;
	}
	memToFree = sourceBlock.pixelPtr;
	memcpy(sourceBlock.pixelPtr, blockPtr->pixelPtr, cpyLen);
	memcpy(sourceBlock.pixelPtr, blockPtr->pixelPtr, sourceBlock.height
	    * sourceBlock.pitch);
    }


    xEnd = x + width;
    yEnd = y + height;
    if ((xEnd > modelPtr->width) || (yEnd > modelPtr->height)) {
	if (ImgPhotoSetSize(modelPtr, MAX(xEnd, modelPtr->width),
		MAX(yEnd, modelPtr->height)) == TCL_ERROR) {
    if ((xEnd > masterPtr->width) || (yEnd > masterPtr->height)) {
	if (ImgPhotoSetSize(masterPtr, MAX(xEnd, masterPtr->width),
		MAX(yEnd, masterPtr->height)) == TCL_ERROR) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    }
	    goto errorExit;
	}
    }

    if ((y < modelPtr->ditherY) || ((y == modelPtr->ditherY)
	    && (x < modelPtr->ditherX))) {
    if ((y < masterPtr->ditherY) || ((y == masterPtr->ditherY)
	    && (x < masterPtr->ditherX))) {
	/*
	 * The dithering isn't correct past the start of this block.
	 */

	modelPtr->ditherX = x;
	modelPtr->ditherY = y;
	masterPtr->ditherX = x;
	masterPtr->ditherY = y;
    }

    /*
     * If this image block could have different red, green and blue
     * components, mark it as a color image.
     */

    greenOffset = sourceBlock.offset[1] - sourceBlock.offset[0];
    blueOffset = sourceBlock.offset[2] - sourceBlock.offset[0];
    alphaOffset = sourceBlock.offset[3];
    if ((alphaOffset >= sourceBlock.pixelSize) || (alphaOffset < 0)) {
	alphaOffset = 0;
	sourceIsSimplePhoto = 1;
    } else {
	alphaOffset -= sourceBlock.offset[0];
    }
    if ((greenOffset != 0) || (blueOffset != 0)) {
	modelPtr->flags |= COLOR_IMAGE;
	masterPtr->flags |= COLOR_IMAGE;
    }

    /*
     * Copy the data into our local 32-bit/pixel array. If we can do it with a
     * single memmove, we do.
     */

    destLinePtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
    pitch = modelPtr->width * 4;
    destLinePtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
    pitch = masterPtr->width * 4;

    /*
     * Test to see if we can do the whole write in a single copy. This test is
     * probably too restrictive. We should also be able to do a memmove if
     * pixelSize == 3 and alphaOffset == 0. Maybe other cases too.
     */

    if ((sourceBlock.pixelSize == 4)
	    && (greenOffset == 1) && (blueOffset == 2) && (alphaOffset == 3)
	    && (width <= sourceBlock.width) && (height <= sourceBlock.height)
	    && ((height == 1) || ((x == 0) && (width == modelPtr->width)
	    && ((height == 1) || ((x == 0) && (width == masterPtr->width)
		&& (sourceBlock.pitch == pitch)))
	    && (compRule == TK_PHOTO_COMPOSITE_SET)) {
	memmove(destLinePtr, sourceBlock.pixelPtr + sourceBlock.offset[0],
		((size_t)height * width * 4));

	/*
	 * We know there's an alpha offset and we're setting the data, so skip
3352
3353
3354
3355
3356
3357
3358
3359

3360
3361
3362
3363
3364
3365
3366
2992
2993
2994
2995
2996
2997
2998

2999
3000
3001
3002
3003
3004
3005
3006







-
+







    /*
     * Add this new block to the region which specifies which data is valid.
     */

    if (alphaOffset) {
	/*
	 * This block is grossly inefficient. For each row in the image, it
	 * finds each contiguous string of nontransparent pixels, then marks
	 * finds each continguous string of nontransparent pixels, then marks
	 * those areas as valid in the validRegion mask. This makes drawing
	 * very efficient, because of the way we use X: we just say, here's
	 * your mask, and here's your data. We need not worry about the
	 * current background color, etc. But this costs us a lot on the image
	 * setup. Still, image setup only happens once, whereas the drawing
	 * happens many times, so this might be the best way to go.
	 *
3384
3385
3386
3387
3388
3389
3390
3391
3392


3393
3394
3395
3396
3397
3398
3399
3400
3401

3402
3403
3404


3405
3406
3407
3408
3409
3410
3411


3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427


3428
3429
3430

3431
3432

3433
3434
3435

3436
3437
3438
3439
3440

3441
3442
3443
3444
3445
3446
3447
3448

3449
3450
3451
3452
3453
3454
3455

3456
3457
3458
3459
3460
3461
3462


3463
3464
3465
3466
3467
3468
3469
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







-
-
+
+








-
+

-
-
+
+





-
-
+
+














-
-
+
+


-
+

-
+


-
+




-
+







-
+






-
+





-
-
+
+







	recalculateValidRegion:
	    workRgn = TkCreateRegion();
	    rect.x = x;
	    rect.y = y;
	    rect.width = width;
	    rect.height = height;
	    TkUnionRectWithRegion(&rect, workRgn, workRgn);
	    TkSubtractRegion(modelPtr->validRegion, workRgn,
		    modelPtr->validRegion);
	    TkSubtractRegion(masterPtr->validRegion, workRgn,
		    masterPtr->validRegion);
	    TkDestroyRegion(workRgn);
	}

	/*
	 * Factorize out the main part of the building of the region data to
	 * allow for more efficient per-platform implementations. [Bug 919066]
	 */

	TkpBuildRegionFromAlphaData(modelPtr->validRegion, (unsigned) x,
	TkpBuildRegionFromAlphaData(masterPtr->validRegion, (unsigned) x,
		(unsigned) y, (unsigned) width, (unsigned) height,
		modelPtr->pix32 + (y * modelPtr->width + x) * 4 + 3,
		4, (unsigned) modelPtr->width * 4);
		masterPtr->pix32 + (y * masterPtr->width + x) * 4 + 3,
		4, (unsigned) masterPtr->width * 4);
    } else {
	rect.x = x;
	rect.y = y;
	rect.width = width;
	rect.height = height;
	TkUnionRectWithRegion(&rect, modelPtr->validRegion,
		modelPtr->validRegion);
	TkUnionRectWithRegion(&rect, masterPtr->validRegion,
		masterPtr->validRegion);
    }

    /*
     * Check if display code needs alpha blending...
     */

    if (!sourceIsSimplePhoto && (height == 1)) {
	/*
	 * Optimize the single span case if we can. This speeds up code that
	 * builds up large simple-alpha images by scan-lines or individual
	 * pixels. We don't negate COMPLEX_ALPHA in this case. [Bug 1409140]
	 * [Patch 1539990]
	 */

	if (!(modelPtr->flags & COMPLEX_ALPHA)) {
	    int x1;
	if (!(masterPtr->flags & COMPLEX_ALPHA)) {
	    register int x1;

	    for (x1=x ; x1<x+width ; x1++) {
		unsigned char newAlpha;
		register unsigned char newAlpha;

		destLinePtr = modelPtr->pix32 + (y*modelPtr->width + x1)*4;
		destLinePtr = masterPtr->pix32 + (y*masterPtr->width + x1)*4;
		newAlpha = destLinePtr[3];
		if (newAlpha && newAlpha != 255) {
		    modelPtr->flags |= COMPLEX_ALPHA;
		    masterPtr->flags |= COMPLEX_ALPHA;
		    break;
		}
	    }
	}
    } else if ((alphaOffset != 0) || (modelPtr->flags & COMPLEX_ALPHA)) {
    } else if ((alphaOffset != 0) || (masterPtr->flags & COMPLEX_ALPHA)) {
	/*
	 * Check for partial transparency if alpha pixels are specified, or
	 * rescan if we already knew such pixels existed. To restrict this
	 * Toggle to only checking the changed pixels requires knowing where
	 * the alpha pixels are.
	 */

	ToggleComplexAlphaIfNeeded(modelPtr);
	ToggleComplexAlphaIfNeeded(masterPtr);
    }

    /*
     * Update each instance.
     */

    Tk_DitherPhoto((Tk_PhotoHandle)modelPtr, x, y, width, height);
    Tk_DitherPhoto((Tk_PhotoHandle)masterPtr, x, y, width, height);

    /*
     * Tell the core image code that this image has changed.
     */

    Tk_ImageChanged(modelPtr->tkModel, x, y, width, height,
	    modelPtr->width, modelPtr->height);
    Tk_ImageChanged(masterPtr->tkMaster, x, y, width, height,
	    masterPtr->width, masterPtr->height);

    if (memToFree) ckfree(memToFree);

    return TCL_OK;

  errorExit:
    if (memToFree) ckfree(memToFree);
3505
3506
3507
3508
3509
3510
3511
3512
3513


3514
3515
3516
3517
3518
3519
3520
3145
3146
3147
3148
3149
3150
3151


3152
3153
3154
3155
3156
3157
3158
3159
3160







-
-
+
+







    int zoomX, int zoomY,	/* Zoom factors for the X and Y axes. */
    int subsampleX, int subsampleY,
				/* Subsampling factors for the X and Y
				 * axes. */
    int compRule)		/* Compositing rule to use when processing
				 * transparent pixels. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    Tk_PhotoImageBlock sourceBlock;
    register PhotoMaster *masterPtr = (PhotoMaster *) handle;
    register Tk_PhotoImageBlock sourceBlock;
    unsigned char *memToFree;
    int xEnd, yEnd, greenOffset, blueOffset, alphaOffset;
    int wLeft, hLeft, wCopy, hCopy, blockWid, blockHt;
    unsigned char *srcPtr, *srcLinePtr, *srcOrigPtr, *destPtr, *destLinePtr;
    int pitch, xRepeat, yRepeat, blockXSkip, blockYSkip, sourceIsSimplePhoto;
    XRectangle rect;

3533
3534
3535
3536
3537
3538
3539
3540
3541


3542
3543
3544
3545



3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567



3568
3569
3570
3571

3572
3573
3574
3575
3576
3577

3578
3579
3580
3581
3582
3583
3584
3585
3586
3587


3588
3589
3590
3591
3592


3593
3594
3595
3596
3597
3598
3599



3600
3601
3602
3603


3604
3605
3606
3607
3608
3609
3610


3611
3612
3613
3614
3615
3616


3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634

3635
3636
3637
3638
3639
3640
3641
3173
3174
3175
3176
3177
3178
3179


3180
3181
3182



3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204



3205
3206
3207




3208






3209





3210
3211
3212


3213
3214
3215
3216
3217
3218

3219
3220
3221
3222
3223
3224



3225
3226
3227
3228
3229


3230
3231
3232
3233
3234
3235
3236


3237
3238
3239
3240
3241
3242


3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261

3262
3263
3264
3265
3266
3267
3268
3269







-
-
+
+

-
-
-
+
+
+



















-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-



-
-
+
+




-
+
+




-
-
-
+
+
+


-
-
+
+





-
-
+
+




-
-
+
+

















-
+








    sourceIsSimplePhoto = compRule & SOURCE_IS_SIMPLE_ALPHA_PHOTO;
    compRule &= ~SOURCE_IS_SIMPLE_ALPHA_PHOTO;

    if (zoomX <= 0 || zoomY <= 0) {
	return TCL_OK;
    }
    if ((modelPtr->userWidth != 0) && ((x + width) > modelPtr->userWidth)) {
	width = modelPtr->userWidth - x;
    if ((masterPtr->userWidth != 0) && ((x + width) > masterPtr->userWidth)) {
	width = masterPtr->userWidth - x;
    }
    if ((modelPtr->userHeight != 0)
	    && ((y + height) > modelPtr->userHeight)) {
	height = modelPtr->userHeight - y;
    if ((masterPtr->userHeight != 0)
	    && ((y + height) > masterPtr->userHeight)) {
	height = masterPtr->userHeight - y;
    }
    if (width <= 0 || height <= 0) {
	return TCL_OK;
    }

    /*
     * Fix for Bug e4336bef5d:
     * Make a local copy of *blockPtr, as we might have to change some
     * of its fields and don't want to interfere with the caller's data.
     *
     * If source and destination are the same image, create a copy  of the
     * source data in our local sourceBlock.
     *
     * To find out, just comparing the pointers is not enough - they might have
     * different values and still point to the same block of memory. (e.g.
     * if the -from option was passed to [imageName copy])
     */
    sourceBlock = *blockPtr;
    memToFree = NULL;
    if (modelPtr->pix32 && (sourceBlock.pixelPtr >= modelPtr->pix32)
	    && (sourceBlock.pixelPtr < modelPtr->pix32 + modelPtr->width
	    * modelPtr->height * 4)) {
    if (sourceBlock.pixelPtr >= masterPtr->pix32
	    && sourceBlock.pixelPtr <= masterPtr->pix32 + masterPtr->width
	    * masterPtr->height * 4) {
	/*
	 * Fix 5c51be6411: avoid reading
	 *
	 *	(sourceBlock.pitch - sourceBlock.width * sourceBlock.pixelSize)
	sourceBlock.pixelPtr = attemptckalloc(sourceBlock.height
	 *
	 * bytes past the end of modelPtr->pix32[] when
	 *
	 *	blockPtr->pixelPtr > (modelPtr->pix32 +
	 *		4 * modelPtr->width * modelPtr->height -
	 *		sourceBlock.height * sourceBlock.pitch)
		* sourceBlock.pitch);
	 */
	unsigned int cpyLen = (sourceBlock.height - 1) * sourceBlock.pitch +
		sourceBlock.width * sourceBlock.pixelSize;

	sourceBlock.pixelPtr = (unsigned char *)attemptckalloc(cpyLen);
	if (sourceBlock.pixelPtr == NULL) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    }
	    return TCL_ERROR;
	}
	memToFree = sourceBlock.pixelPtr;
	memcpy(sourceBlock.pixelPtr, blockPtr->pixelPtr, cpyLen);
	memcpy(sourceBlock.pixelPtr, blockPtr->pixelPtr, sourceBlock.height
	    * sourceBlock.pitch);
    }

    xEnd = x + width;
    yEnd = y + height;
    if ((xEnd > modelPtr->width) || (yEnd > modelPtr->height)) {
	if (ImgPhotoSetSize(modelPtr, MAX(xEnd, modelPtr->width),
		MAX(yEnd, modelPtr->height)) == TCL_ERROR) {
    if ((xEnd > masterPtr->width) || (yEnd > masterPtr->height)) {
	if (ImgPhotoSetSize(masterPtr, MAX(xEnd, masterPtr->width),
		MAX(yEnd, masterPtr->height)) == TCL_ERROR) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    }
	    goto errorExit;
	}
    }

    if ((y < modelPtr->ditherY) || ((y == modelPtr->ditherY)
	    && (x < modelPtr->ditherX))) {
    if ((y < masterPtr->ditherY) || ((y == masterPtr->ditherY)
	    && (x < masterPtr->ditherX))) {
	/*
	 * The dithering isn't correct past the start of this block.
	 */

	modelPtr->ditherX = x;
	modelPtr->ditherY = y;
	masterPtr->ditherX = x;
	masterPtr->ditherY = y;
    }

    /*
     * If this image block could have different red, green and blue
     * components, mark it as a color image.
     */

    greenOffset = sourceBlock.offset[1] - sourceBlock.offset[0];
    blueOffset = sourceBlock.offset[2] - sourceBlock.offset[0];
    alphaOffset = sourceBlock.offset[3];
    if ((alphaOffset >= sourceBlock.pixelSize) || (alphaOffset < 0)) {
	alphaOffset = 0;
	sourceIsSimplePhoto = 1;
    } else {
	alphaOffset -= sourceBlock.offset[0];
    }
    if ((greenOffset != 0) || (blueOffset != 0)) {
	modelPtr->flags |= COLOR_IMAGE;
	masterPtr->flags |= COLOR_IMAGE;
    }

    /*
     * Work out what area the pixel data in the block expands to after
     * subsampling and zooming.
     */

3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666
3667
3668
3669
3670
3671
3672

3673
3674
3675
3676
3677
3678
3679
3284
3285
3286
3287
3288
3289
3290

3291
3292
3293
3294
3295
3296
3297
3298
3299

3300
3301
3302
3303
3304
3305
3306
3307







-
+








-
+







	blockHt = ((sourceBlock.height - subsampleY - 1) / -subsampleY) * zoomY;
    }

    /*
     * Copy the data into our local 32-bit/pixel array.
     */

    destLinePtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
    destLinePtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
    srcOrigPtr = sourceBlock.pixelPtr + sourceBlock.offset[0];
    if (subsampleX < 0) {
	srcOrigPtr += (sourceBlock.width - 1) * sourceBlock.pixelSize;
    }
    if (subsampleY < 0) {
	srcOrigPtr += (sourceBlock.height - 1) * sourceBlock.pitch;
    }

    pitch = modelPtr->width * 4;
    pitch = masterPtr->width * 4;
    for (hLeft = height; hLeft > 0; ) {
	hCopy = MIN(hLeft, blockHt);
	hLeft -= hCopy;
	yRepeat = zoomY;
	srcLinePtr = srcOrigPtr;
	for (; hCopy > 0; --hCopy) {
	    destPtr = destLinePtr;
3752
3753
3754
3755
3756
3757
3758
3759
3760


3761
3762
3763
3764

3765
3766
3767


3768
3769
3770
3771
3772
3773
3774


3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787

3788
3789
3790

3791
3792
3793
3794

3795
3796
3797

3798
3799
3800
3801
3802
3803
3804

3805
3806
3807
3808
3809
3810
3811

3812
3813
3814
3815
3816
3817
3818


3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836

3837
3838
3839
3840
3841
3842
3843

3844
3845
3846
3847
3848
3849
3850
3851

3852
3853
3854
3855
3856
3857

3858
3859
3860
3861
3862
3863
3864

3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876



3877
3878
3879
3880

3881
3882
3883

3884
3885
3886
3887
3888
3889
3890


3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902





3903
3904
3905
3906
3907
3908
3909
3380
3381
3382
3383
3384
3385
3386


3387
3388
3389
3390
3391

3392
3393


3394
3395
3396
3397
3398
3399
3400


3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414

3415
3416
3417

3418
3419
3420
3421

3422
3423
3424

3425
3426
3427
3428
3429
3430
3431

3432
3433
3434
3435
3436
3437
3438

3439
3440
3441
3442
3443
3444


3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463

3464
3465
3466
3467
3468
3469
3470

3471
3472
3473
3474
3475
3476
3477
3478

3479
3480
3481
3482
3483
3484

3485
3486
3487
3488
3489
3490
3491

3492
3493
3494
3495
3496
3497
3498
3499
3500
3501



3502
3503
3504
3505
3506
3507

3508
3509
3510

3511
3512
3513
3514
3515
3516


3517
3518
3519
3520
3521
3522
3523
3524
3525





3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537







-
-
+
+



-
+

-
-
+
+





-
-
+
+












-
+


-
+



-
+


-
+






-
+






-
+





-
-
+
+

















-
+






-
+







-
+





-
+






-
+









-
-
-
+
+
+



-
+


-
+





-
-
+
+







-
-
-
-
-
+
+
+
+
+







	    TkRegion workRgn = TkCreateRegion();

	    rect.x = x;
	    rect.y = y;
	    rect.width = width;
	    rect.height = 1;
	    TkUnionRectWithRegion(&rect, workRgn, workRgn);
	    TkSubtractRegion(modelPtr->validRegion, workRgn,
		    modelPtr->validRegion);
	    TkSubtractRegion(masterPtr->validRegion, workRgn,
		    masterPtr->validRegion);
	    TkDestroyRegion(workRgn);
	}

	TkpBuildRegionFromAlphaData(modelPtr->validRegion,
	TkpBuildRegionFromAlphaData(masterPtr->validRegion,
		(unsigned)x, (unsigned)y, (unsigned)width, (unsigned)height,
		&modelPtr->pix32[(y * modelPtr->width + x) * 4 + 3], 4,
		(unsigned) modelPtr->width * 4);
		&masterPtr->pix32[(y * masterPtr->width + x) * 4 + 3], 4,
		(unsigned) masterPtr->width * 4);
    } else {
	rect.x = x;
	rect.y = y;
	rect.width = width;
	rect.height = height;
	TkUnionRectWithRegion(&rect, modelPtr->validRegion,
		modelPtr->validRegion);
	TkUnionRectWithRegion(&rect, masterPtr->validRegion,
		masterPtr->validRegion);
    }

    /*
     * Check if display code needs alpha blending...
     */

    if (!sourceIsSimplePhoto && (width == 1) && (height == 1)) {
	/*
	 * Optimize the single pixel case if we can. This speeds up code that
	 * builds up large simple-alpha images by single pixels. We don't
	 * negate COMPLEX_ALPHA in this case. [Bug 1409140]
	 */
	if (!(modelPtr->flags & COMPLEX_ALPHA)) {
	if (!(masterPtr->flags & COMPLEX_ALPHA)) {
	    unsigned char newAlpha;

	    destLinePtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4;
	    destLinePtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
	    newAlpha = destLinePtr[3];

	    if (newAlpha && newAlpha != 255) {
		modelPtr->flags |= COMPLEX_ALPHA;
		masterPtr->flags |= COMPLEX_ALPHA;
	    }
	}
    } else if ((alphaOffset != 0) || (modelPtr->flags & COMPLEX_ALPHA)) {
    } else if ((alphaOffset != 0) || (masterPtr->flags & COMPLEX_ALPHA)) {
	/*
	 * Check for partial transparency if alpha pixels are specified, or
	 * rescan if we already knew such pixels existed. To restrict this
	 * Toggle to only checking the changed pixels requires knowing where
	 * the alpha pixels are.
	 */
	ToggleComplexAlphaIfNeeded(modelPtr);
	ToggleComplexAlphaIfNeeded(masterPtr);
    }

    /*
     * Update each instance.
     */

    Tk_DitherPhoto((Tk_PhotoHandle) modelPtr, x, y, width, height);
    Tk_DitherPhoto((Tk_PhotoHandle) masterPtr, x, y, width, height);

    /*
     * Tell the core image code that this image has changed.
     */

    Tk_ImageChanged(modelPtr->tkModel, x, y, width, height, modelPtr->width,
	    modelPtr->height);
    Tk_ImageChanged(masterPtr->tkMaster, x, y, width, height, masterPtr->width,
	    masterPtr->height);

    if (memToFree) ckfree(memToFree);

    return TCL_OK;

  errorExit:
    if (memToFree) ckfree(memToFree);

    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DitherPhoto --
 *
 *	This function is called to update an area of each instance's pixmap by
 *	dithering the corresponding area of the image model.
 *	dithering the corresponding area of the image master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The pixmap of each instance of this image gets updated. The fields in
 *	*modelPtr indicating which area of the image is correctly dithered
 *	*masterPtr indicating which area of the image is correctly dithered
 *	get updated.
 *
 *----------------------------------------------------------------------
 */

void
Tk_DitherPhoto(
    Tk_PhotoHandle photo,	/* Image model whose instances are to be
    Tk_PhotoHandle photo,	/* Image master whose instances are to be
				 * updated. */
    int x, int y,		/* Coordinates of the top-left pixel in the
				 * area to be dithered. */
    int width, int height)	/* Dimensions of the area to be dithered. */
{
    PhotoModel *modelPtr = (PhotoModel *) photo;
    PhotoMaster *masterPtr = (PhotoMaster *) photo;
    PhotoInstance *instancePtr;

    if ((width <= 0) || (height <= 0)) {
	return;
    }

    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	TkImgDitherInstance(instancePtr, x, y, width, height);
    }

    /*
     * Work out whether this block will be correctly dithered and whether it
     * will extend the correctly dithered region.
     */

    if (((y < modelPtr->ditherY)
	    || ((y == modelPtr->ditherY) && (x <= modelPtr->ditherX)))
	    && ((y + height) > (modelPtr->ditherY))) {
    if (((y < masterPtr->ditherY)
	    || ((y == masterPtr->ditherY) && (x <= masterPtr->ditherX)))
	    && ((y + height) > (masterPtr->ditherY))) {
	/*
	 * This block starts inside (or immediately after) the correctly
	 * dithered region, so the first scan line at least will be right.
	 * Furthermore this block extends into scanline modelPtr->ditherY.
	 * Furthermore this block extends into scanline masterPtr->ditherY.
	 */

	if ((x == 0) && (width == modelPtr->width)) {
	if ((x == 0) && (width == masterPtr->width)) {
	    /*
	     * We are doing the full width, therefore the dithering will be
	     * correct to the end.
	     */

	    modelPtr->ditherX = 0;
	    modelPtr->ditherY = y + height;
	    masterPtr->ditherX = 0;
	    masterPtr->ditherY = y + height;
	} else {
	    /*
	     * We are doing partial scanlines, therefore the
	     * correctly-dithered region will be extended by at most one scan
	     * line.
	     */

	    if (x <= modelPtr->ditherX) {
		modelPtr->ditherX = x + width;
		if (modelPtr->ditherX >= modelPtr->width) {
		    modelPtr->ditherX = 0;
		    modelPtr->ditherY++;
	    if (x <= masterPtr->ditherX) {
		masterPtr->ditherX = x + width;
		if (masterPtr->ditherX >= masterPtr->width) {
		    masterPtr->ditherX = 0;
		    masterPtr->ditherY++;
		}
	    }
	}
    }
}

/*
3923
3924
3925
3926
3927
3928
3929
3930

3931
3932
3933
3934


3935
3936
3937
3938
3939
3940
3941


3942
3943

3944
3945
3946
3947
3948
3949
3950
3951
3952


3953
3954

3955
3956
3957
3958
3959
3960
3961
3962
3963
3964


3965
3966
3967
3968
3969
3970
3971
3551
3552
3553
3554
3555
3556
3557

3558
3559
3560


3561
3562
3563
3564
3565
3566
3567


3568
3569
3570

3571
3572
3573
3574
3575
3576
3577



3578
3579


3580
3581
3582
3583
3584
3585
3586
3587
3588


3589
3590
3591
3592
3593
3594
3595
3596
3597







-
+


-
-
+
+





-
-
+
+

-
+






-
-
-
+
+
-
-
+








-
-
+
+







 *----------------------------------------------------------------------
 */

void
Tk_PhotoBlank(
    Tk_PhotoHandle handle)	/* Handle for the image to be blanked. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;
    PhotoInstance *instancePtr;

    modelPtr->ditherX = modelPtr->ditherY = 0;
    modelPtr->flags = 0;
    masterPtr->ditherX = masterPtr->ditherY = 0;
    masterPtr->flags = 0;

    /*
     * The image has valid data nowhere.
     */

    if (modelPtr->validRegion != NULL) {
	TkDestroyRegion(modelPtr->validRegion);
    if (masterPtr->validRegion != NULL) {
	TkDestroyRegion(masterPtr->validRegion);
    }
    modelPtr->validRegion = TkCreateRegion();
    masterPtr->validRegion = TkCreateRegion();

    /*
     * Clear out the 32-bit pixel storage array. Clear out the dithering error
     * arrays for each instance.
     */

    if (modelPtr->pix32) {
	memset(modelPtr->pix32, 0,
		((size_t)modelPtr->width * modelPtr->height * 4));
    memset(masterPtr->pix32, 0,
	    ((size_t)masterPtr->width * masterPtr->height * 4));
    }
    for (instancePtr = modelPtr->instancePtr; instancePtr != NULL;
    for (instancePtr = masterPtr->instancePtr; instancePtr != NULL;
	    instancePtr = instancePtr->nextPtr) {
	TkImgResetDither(instancePtr);
    }

    /*
     * Tell the core image code that this image has changed.
     */

    Tk_ImageChanged(modelPtr->tkModel, 0, 0, modelPtr->width,
	    modelPtr->height, modelPtr->width, modelPtr->height);
    Tk_ImageChanged(masterPtr->tkMaster, 0, 0, masterPtr->width,
	    masterPtr->height, masterPtr->width, masterPtr->height);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PhotoExpand --
 *
3987
3988
3989
3990
3991
3992
3993
3994

3995
3996
3997


3998
3999
4000


4001
4002
4003
4004



4005
4006
4007
4008


4009
4010
4011
4012
4013


4014
4015
4016
4017
4018
4019
4020
3613
3614
3615
3616
3617
3618
3619

3620
3621


3622
3623
3624


3625
3626
3627



3628
3629
3630
3631
3632


3633
3634
3635
3636
3637


3638
3639
3640
3641
3642
3643
3644
3645
3646







-
+

-
-
+
+

-
-
+
+

-
-
-
+
+
+


-
-
+
+



-
-
+
+







int
Tk_PhotoExpand(
    Tcl_Interp *interp,		/* Interpreter for passing back error
				 * messages, or NULL. */
    Tk_PhotoHandle handle,	/* Handle for the image to be expanded. */
    int width, int height)	/* Desired minimum dimensions of the image. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;

    if (width <= modelPtr->width) {
	width = modelPtr->width;
    if (width <= masterPtr->width) {
	width = masterPtr->width;
    }
    if (height <= modelPtr->height) {
	height = modelPtr->height;
    if (height <= masterPtr->height) {
	height = masterPtr->height;
    }
    if ((width != modelPtr->width) || (height != modelPtr->height)) {
	if (ImgPhotoSetSize(modelPtr, MAX(width, modelPtr->width),
		MAX(height, modelPtr->height)) == TCL_ERROR) {
    if ((width != masterPtr->width) || (height != masterPtr->height)) {
	if (ImgPhotoSetSize(masterPtr, MAX(width, masterPtr->width),
		MAX(height, masterPtr->height)) == TCL_ERROR) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
			TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
		Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	    }
	    return TCL_ERROR;
	}
	Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0, modelPtr->width,
		modelPtr->height);
	Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, masterPtr->width,
		masterPtr->height);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
4035
4036
4037
4038
4039
4040
4041
4042

4043
4044
4045


4046
4047
4048
4049
4050
4051
4052
3661
3662
3663
3664
3665
3666
3667

3668
3669


3670
3671
3672
3673
3674
3675
3676
3677
3678







-
+

-
-
+
+







Tk_PhotoGetSize(
    Tk_PhotoHandle handle,	/* Handle for the image whose dimensions are
				 * requested. */
    int *widthPtr, int *heightPtr)
				/* The dimensions of the image are returned
				 * here. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;

    *widthPtr = modelPtr->width;
    *heightPtr = modelPtr->height;
    *widthPtr = masterPtr->width;
    *heightPtr = masterPtr->height;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PhotoSetSize --
 *
4067
4068
4069
4070
4071
4072
4073
4074

4075
4076
4077
4078
4079




4080
4081
4082
4083


4084
4085
4086
4087
4088


4089
4090
4091
4092
4093
4094
4095
3693
3694
3695
3696
3697
3698
3699

3700
3701




3702
3703
3704
3705
3706
3707


3708
3709
3710
3711
3712


3713
3714
3715
3716
3717
3718
3719
3720
3721







-
+

-
-
-
-
+
+
+
+


-
-
+
+



-
-
+
+







Tk_PhotoSetSize(
    Tcl_Interp *interp,		/* Interpreter for passing back error
				 * messages, or NULL. */
    Tk_PhotoHandle handle,	/* Handle for the image whose size is to be
				 * set. */
    int width, int height)	/* New dimensions for the image. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;

    modelPtr->userWidth = width;
    modelPtr->userHeight = height;
    if (ImgPhotoSetSize(modelPtr, ((width > 0) ? width: modelPtr->width),
	    ((height > 0) ? height: modelPtr->height)) == TCL_ERROR) {
    masterPtr->userWidth = width;
    masterPtr->userHeight = height;
    if (ImgPhotoSetSize(masterPtr, ((width > 0) ? width: masterPtr->width),
	    ((height > 0) ? height: masterPtr->height)) == TCL_ERROR) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
		    TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1));
	    Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
	}
	return TCL_ERROR;
    }
    Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0,
	    modelPtr->width, modelPtr->height);
    Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0,
	    masterPtr->width, masterPtr->height);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetPhotoValidRegion --
4110
4111
4112
4113
4114
4115
4116
4117

4118
4119

4120
4121
4122
4123
4124
4125
4126
3736
3737
3738
3739
3740
3741
3742

3743
3744

3745
3746
3747
3748
3749
3750
3751
3752







-
+

-
+







 */

TkRegion
TkPhotoGetValidRegion(
    Tk_PhotoHandle handle)	/* Handle for the image whose valid region is
				 * to obtained. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;

    return modelPtr->validRegion;
    return masterPtr->validRegion;
}

/*
 *----------------------------------------------------------------------
 *
 * ImgGetPhoto --
 *
4138
4139
4140
4141
4142
4143
4144
4145

4146
4147
4148
4149
4150
4151
4152
4153
4154
4155

4156
4157
4158
4159
4160
4161

4162
4163
4164
4165
4166
4167
4168
3764
3765
3766
3767
3768
3769
3770

3771
3772
3773
3774
3775
3776
3777
3778
3779
3780

3781
3782
3783
3784
3785
3786

3787
3788
3789
3790
3791
3792
3793
3794







-
+









-
+





-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static char *
ImgGetPhoto(
    PhotoModel *modelPtr,	/* Handle for the photo image from which image
    PhotoMaster *masterPtr,	/* Handle for the photo image from which image
				 * data is desired. */
    Tk_PhotoImageBlock *blockPtr,
				/* Information about the address and layout of
				 * the image data is returned here. */
    struct SubcommandOptions *optPtr)
{
    unsigned char *pixelPtr;
    int x, y, greenOffset, blueOffset, alphaOffset;

    Tk_PhotoGetImage((Tk_PhotoHandle) modelPtr, blockPtr);
    Tk_PhotoGetImage((Tk_PhotoHandle) masterPtr, blockPtr);
    blockPtr->pixelPtr += optPtr->fromY * blockPtr->pitch
	    + optPtr->fromX * blockPtr->pixelSize;
    blockPtr->width = optPtr->fromX2 - optPtr->fromX;
    blockPtr->height = optPtr->fromY2 - optPtr->fromY;

    if (!(modelPtr->flags & COLOR_IMAGE) &&
    if (!(masterPtr->flags & COLOR_IMAGE) &&
	    (!(optPtr->options & OPT_BACKGROUND)
	    || ((optPtr->background->red == optPtr->background->green)
	    && (optPtr->background->red == optPtr->background->blue)))) {
	blockPtr->offset[0] = blockPtr->offset[1] = blockPtr->offset[2];
    }
    alphaOffset = 0;
    for (y = 0; y < blockPtr->height; y++) {
4182
4183
4184
4185
4186
4187
4188
4189

4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202

4203
4204
4205
4206
4207
4208
4209
3808
3809
3810
3811
3812
3813
3814

3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827

3828
3829
3830
3831
3832
3833
3834
3835







-
+












-
+







    if (!alphaOffset) {
	blockPtr->offset[3]= -1; /* Tell caller alpha need not be read */
    }
    greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
    blueOffset = blockPtr->offset[2] - blockPtr->offset[0];
    if (((optPtr->options & OPT_BACKGROUND) && alphaOffset) ||
	    ((optPtr->options & OPT_GRAYSCALE) && (greenOffset||blueOffset))) {
	int newPixelSize;
	int newPixelSize,x,y;
	unsigned char *srcPtr, *destPtr;
	char *data;

	newPixelSize = (!(optPtr->options & OPT_BACKGROUND) && alphaOffset)
		? 2 : 1;
	if ((greenOffset||blueOffset) && !(optPtr->options & OPT_GRAYSCALE)) {
	    newPixelSize += 2;
	}

	if (blockPtr->height > (int)((UINT_MAX/newPixelSize)/blockPtr->width)) {
	    return NULL;
	}
	data = (char *)attemptckalloc(newPixelSize*blockPtr->width*blockPtr->height);
	data = attemptckalloc(newPixelSize*blockPtr->width*blockPtr->height);
	if (data == NULL) {
	    return NULL;
	}
	srcPtr = blockPtr->pixelPtr + blockPtr->offset[0];
	destPtr = (unsigned char *) data;
	if (!greenOffset && !blueOffset) {
	    for (y = blockPtr->height; y > 0; y--) {
4335
4336
4337
4338
4339
4340
4341
4342

4343
4344
4345
4346
4347




4348
4349
4350
4351
4352
4353
4354
3961
3962
3963
3964
3965
3966
3967

3968
3969




3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980







-
+

-
-
-
-
+
+
+
+







Tk_PhotoGetImage(
    Tk_PhotoHandle handle,	/* Handle for the photo image from which image
				 * data is desired. */
    Tk_PhotoImageBlock *blockPtr)
				/* Information about the address and layout of
				 * the image data is returned here. */
{
    PhotoModel *modelPtr = (PhotoModel *) handle;
    PhotoMaster *masterPtr = (PhotoMaster *) handle;

    blockPtr->pixelPtr = modelPtr->pix32;
    blockPtr->width = modelPtr->width;
    blockPtr->height = modelPtr->height;
    blockPtr->pitch = modelPtr->width * 4;
    blockPtr->pixelPtr = masterPtr->pix32;
    blockPtr->width = masterPtr->width;
    blockPtr->height = masterPtr->height;
    blockPtr->pitch = masterPtr->width * 4;
    blockPtr->pixelSize = 4;
    blockPtr->offset[0] = 0;
    blockPtr->offset[1] = 1;
    blockPtr->offset[2] = 2;
    blockPtr->offset[3] = 3;
    return 1;
}
4368
4369
4370
4371
4372
4373
4374
4375

4376
4377

4378
4379
4380
4381

4382
4383
4384
4385
4386
4387
4388
4389
4390





































































































4391
4392
4393
4394
4395
4396
4397
4398
3994
3995
3996
3997
3998
3999
4000

4001
4002

4003
4004
4005
4006

4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125







-
+

-
+



-
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








 *	None.
 *
 *--------------------------------------------------------------
 */

static int
ImgPhotoPostscript(
    void *clientData,	/* Handle for the photo image. */
    ClientData clientData,	/* Handle for the photo image. */
    Tcl_Interp *interp,		/* Interpreter. */
    TCL_UNUSED(Tk_Window),		/* (unused) */
    Tk_Window tkwin,		/* (unused) */
    Tk_PostscriptInfo psInfo,	/* Postscript info. */
    int x, int y,		/* First pixel to output. */
    int width, int height,	/* Width and height of area. */
    TCL_UNUSED(int))		/* (unused) */
    int prepass)		/* (unused) */
{
    Tk_PhotoImageBlock block;

    Tk_PhotoGetImage(clientData, &block);
    block.pixelPtr += y * block.pitch + x * block.pixelSize;

    return Tk_PostscriptPhoto(interp, &block, psInfo, width, height);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PhotoPutBlock_NoComposite, Tk_PhotoPutZoomedBlock_NoComposite --
 *
 * These backward-compatability functions just exist to fill slots in stubs
 * table. For the behaviour of *_NoComposite, refer to the corresponding
 * function without the extra suffix, except that the compositing rule is
 * always "overlay" and the function always panics on memory-allocation
 * failure.
 *
 *----------------------------------------------------------------------
 */
#ifndef TK_NO_DEPRECATED
void
Tk_PhotoPutBlock_NoComposite(
    Tk_PhotoHandle handle,
    Tk_PhotoImageBlock *blockPtr,
    int x, int y, int width, int height)
{
    if (Tk_PhotoPutBlock(NULL, handle, blockPtr, x, y, width, height,
	    TK_PHOTO_COMPOSITE_OVERLAY) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}

void
Tk_PhotoPutZoomedBlock_NoComposite(
    Tk_PhotoHandle handle,
    Tk_PhotoImageBlock *blockPtr,
    int x, int y, int width, int height,
    int zoomX, int zoomY, int subsampleX, int subsampleY)
{
    if (Tk_PhotoPutZoomedBlock(NULL, handle, blockPtr, x, y, width, height,
	    zoomX, zoomY, subsampleX, subsampleY,
	    TK_PHOTO_COMPOSITE_OVERLAY) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PhotoExpand_Panic, Tk_PhotoPutBlock_Panic,
 * Tk_PhotoPutZoomedBlock_Panic, Tk_PhotoSetSize_Panic
 *
 * Backward compatability functions for preserving the old behaviour (i.e.
 * panic on memory allocation failure) so that extensions do not need to be
 * significantly updated to take account of TIP #116. These call the new
 * interface (i.e. the interface without the extra suffix), but panic if an
 * error condition is returned.
 *
 *----------------------------------------------------------------------
 */

void
Tk_PhotoExpand_Panic(
    Tk_PhotoHandle handle,
    int width, int height)
{
    if (Tk_PhotoExpand(NULL, handle, width, height) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}

void
Tk_PhotoPutBlock_Panic(
    Tk_PhotoHandle handle,
    Tk_PhotoImageBlock *blockPtr,
    int x, int y, int width, int height, int compRule)
{
    if (Tk_PhotoPutBlock(NULL, handle, blockPtr, x, y, width, height,
	    compRule) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}

void
Tk_PhotoPutZoomedBlock_Panic(
    Tk_PhotoHandle handle, Tk_PhotoImageBlock *blockPtr,
    int x, int y, int width, int height,
    int zoomX, int zoomY, int subsampleX, int subsampleY,
    int compRule)
{
    if (Tk_PhotoPutZoomedBlock(NULL, handle, blockPtr, x, y, width, height,
	    zoomX, zoomY, subsampleX, subsampleY, compRule) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}

void
Tk_PhotoSetSize_Panic(
    Tk_PhotoHandle handle,
    int width, int height)
{
    if (Tk_PhotoSetSize(NULL, handle, width, height) != TCL_OK) {
	Tcl_Panic(TK_PHOTO_ALLOC_FAILURE_MESSAGE);
    }
}
#endif /* TK_NO_DEPRECATED */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * tab-width: 8
 * End:
 */

Changes to generic/tkImgPhoto.h.

1
2
3
4
5
6
7
8
9




10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51







52
53
54
55
56
57
58
1
2
3
4
5




6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64





-
-
-
-
+
+
+
+




















-



-
+

















+
+
+
+
+
+
+







/*
 * tkImgPhoto.h --
 *
 *	Declarations for images of type "photo" for Tk.
 *
 * Copyright © 1994 The Australian National University.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2002-2008 Donal K. Fellows
 * Copyright © 2003 ActiveState Corporation.
 * Copyright (c) 1994 The Australian National University.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2002-2008 Donal K. Fellows
 * Copyright (c) 2003 ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * Author: Paul Mackerras ([email protected]),
 *	   Department of Computer Science,
 *	   Australian National University.
 */

#include "tkInt.h"
#ifdef _WIN32
#include "tkWinInt.h"
#elif defined(__CYGWIN__)
#include "tkUnixInt.h"
#endif

/*
 * Forward declarations of the structures we define.
 */

#define PhotoMaster PhotoModel
typedef struct ColorTableId	ColorTableId;
typedef struct ColorTable	ColorTable;
typedef struct PhotoInstance	PhotoInstance;
typedef struct PhotoModel	PhotoModel;
typedef struct PhotoMaster	PhotoMaster;

/*
 * A signed 8-bit integral type. If chars are unsigned and the compiler isn't
 * an ANSI one, then we have to use short instead (which wastes space) to get
 * signed behavior.
 */

#if defined(__STDC__) || defined(_AIX)
    typedef signed char schar;
#else
#   ifndef __CHAR_UNSIGNED__
	typedef char schar;
#   else
	typedef short schar;
#   endif
#endif

/*
 * An unsigned 32-bit integral type, used for pixel values. We use int rather
 * than long here to accommodate those systems where longs are 64 bits.
 */

typedef unsigned int pixel;

/*
 * The maximum number of pixels to transmit to the server in a single
 * XPutImage call.
 */

#define MAX_PIXELS 65536

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


99
100
101
102
103
104
105
106

107
108
109


110
111
112
113
114
115
116
89
90
91
92
93
94
95




96




97
98
99

100
101
102
103
104

105
106


107
108
109
110
111
112
113
114
115







-
-
-
-

-
-
-
-
+
+

-





-
+

-
-
+
+







 * structure of the following type is used to store the allocated pixel values
 * and other information:
 */

struct ColorTable {
    ColorTableId id;		/* Information used in selecting this color
				 * table. */
#if TCL_MAJOR_VERSION > 8
    size_t	refCount;		/* Number of instances using this map. */
    size_t liveRefCount;		/* Number of instances which are actually in
				 * use, using this map. */
    int	flags;			/* See below. */
#else
    int	flags;			/* See below. */
    unsigned int	refCount;		/* Number of instances using this map. */
    unsigned int liveRefCount;		/* Number of instances which are actually in
    int	refCount;		/* Number of instances using this map. */
    int liveRefCount;		/* Number of instances which are actually in
				 * use, using this map. */
#endif
    int	numColors;		/* Number of colors allocated for this map. */

    XVisualInfo	visualInfo;	/* Information about the visual for windows
				 * using this color table. */

    unsigned redValues[256];	/* Maps 8-bit values of red intensity to a
    pixel redValues[256];	/* Maps 8-bit values of red intensity to a
				 * pixel value or index in pixelMap. */
    unsigned greenValues[256];	/* Ditto for green intensity. */
    unsigned blueValues[256];	/* Ditto for blue intensity. */
    pixel greenValues[256];	/* Ditto for green intensity. */
    pixel blueValues[256];	/* Ditto for blue intensity. */
    unsigned long *pixelMap;	/* Actual pixel values allocated. */

    unsigned char colorQuant[3][256];
				/* Maps 8-bit intensities to quantized
				 * intensities. The first index is 0 for red,
				 * 1 for green, 2 for blue. */
};
134
135
136
137
138
139
140
141

142
143
144
145


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174

175
176
177
178
179
180
181
133
134
135
136
137
138
139

140
141
142


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160


161
162
163
164
165
166

167
168
169
170

171
172
173
174
175
176
177
178







-
+


-
-
+
+
















-
-






-
+



-
+








#define BLACK_AND_WHITE		1
#define COLOR_WINDOW		2
#define DISPOSE_PENDING		4
#define MAP_COLORS		8

/*
 * Definition of the data associated with each photo image model.
 * Definition of the data associated with each photo image master.
 */

struct PhotoModel {
    Tk_ImageModel tkModel;	/* Tk's token for image model. NULL means the
struct PhotoMaster {
    Tk_ImageMaster tkMaster;	/* Tk's token for image master. NULL means the
				 * image is being deleted. */
    Tcl_Interp *interp;		/* Interpreter associated with the application
				 * using this image. */
    Tcl_Command imageCmd;	/* Token for image command (used to delete it
				 * when the image goes away). NULL means the
				 * image command has already been deleted. */
    int	flags;			/* Sundry flags, defined below. */
    int	width, height;		/* Dimensions of image. */
    int userWidth, userHeight;	/* User-declared image dimensions. */
    Tk_Uid palette;		/* User-specified default palette for
				 * instances of this image. */
    double gamma;		/* Display gamma value to correct for. */
    char *fileString;		/* Name of file to read into image. */
    Tcl_Obj *dataString;	/* Object to use as contents of image. */
    Tcl_Obj *format;		/* User-specified format of data in image file
				 * or string value. */
    Tcl_Obj *metadata;		/* User-specified metadata dict or read from
				 * image file */
    unsigned char *pix32;	/* Local storage for 32-bit image. */
    int ditherX, ditherY;	/* Location of first incorrectly dithered
				 * pixel in image. */
    TkRegion validRegion;	/* Tk region indicating which parts of the
				 * image have valid image data. */
    PhotoInstance *instancePtr;	/* First in the list of instances associated
				 * with this model. */
				 * with this master. */
};

/*
 * Bit definitions for the flags field of a PhotoModel.
 * Bit definitions for the flags field of a PhotoMaster.
 * COLOR_IMAGE:			1 means that the image has different color
 *				components.
 * IMAGE_CHANGED:		1 means that the instances of this image need
 *				to be redithered.
 * COMPLEX_ALPHA:		1 means that the instances of this image have
 *				alpha values that aren't 0 or 255, and so need
 *				the copy-merge-replace renderer .
194
195
196
197
198
199
200
201

202
203
204
205
206

207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
191
192
193
194
195
196
197

198
199
200
201
202

203

204



205
206
207

208
209
210
211
212
213
214
215







-
+




-
+
-

-
-
-



-
+








/*
 * The following data structure represents all of the instances of a photo
 * image in windows on a given screen that are using the same colormap.
 */

struct PhotoInstance {
    PhotoModel *modelPtr;	/* Pointer to model for image. */
    PhotoMaster *masterPtr;	/* Pointer to master for image. */
    Display *display;		/* Display for windows using this instance. */
    Colormap colormap;		/* The image may only be used in windows with
				 * this particular colormap. */
    PhotoInstance *nextPtr;	/* Pointer to the next instance in the list of
				 * instances associated with this model. */
				 * instances associated with this master. */
#if TCL_MAJOR_VERSION > 8
    size_t refCount;		/* Number of instances using this structure. */
#else
    unsigned int refCount;	/* Number of instances using this structure. */
#endif
    Tk_Uid palette;		/* Palette for these particular instances. */
    double gamma;		/* Gamma value for these instances. */
    Tk_Uid defaultPalette;	/* Default palette to use if a palette is not
				 * specified for the model. */
				 * specified for the master. */
    ColorTable *colorTablePtr;	/* Pointer to information about colors
				 * allocated for image display in windows like
				 * this one. */
    Pixmap pixels;		/* X pixmap containing dithered image. */
    int width, height;		/* Dimensions of the pixmap. */
    schar *error;		/* Error image, used in dithering. */
    XImage *imagePtr;		/* Image structure for converted pixels. */
243
244
245
246
247
248
249
250

251
252

253
254
255

256
257
258
259

260
261
262
263
264
265
266
267
268
269
236
237
238
239
240
241
242

243
244

245
246
247

248
249
250
251

252
253
254
255
256
257
258
259
260
261
262







-
+

-
+


-
+



-
+










/*
 * Declarations of functions shared between the different parts of the
 * photo image implementation.
 */

MODULE_SCOPE void	TkImgPhotoConfigureInstance(
			    PhotoInstance *instancePtr);
MODULE_SCOPE void	TkImgDisposeInstance(void *clientData);
MODULE_SCOPE void	TkImgDisposeInstance(ClientData clientData);
MODULE_SCOPE void	TkImgPhotoInstanceSetSize(PhotoInstance *instancePtr);
MODULE_SCOPE void *TkImgPhotoGet(Tk_Window tkwin, void *clientData);
MODULE_SCOPE ClientData	TkImgPhotoGet(Tk_Window tkwin, ClientData clientData);
MODULE_SCOPE void	TkImgDitherInstance(PhotoInstance *instancePtr, int x,
			    int y, int width, int height);
MODULE_SCOPE void	TkImgPhotoDisplay(void *clientData,
MODULE_SCOPE void	TkImgPhotoDisplay(ClientData clientData,
			    Display *display, Drawable drawable,
			    int imageX, int imageY, int width, int height,
			    int drawableX, int drawableY);
MODULE_SCOPE void	TkImgPhotoFree(void *clientData,
MODULE_SCOPE void	TkImgPhotoFree(ClientData clientData,
			    Display *display);
MODULE_SCOPE void	TkImgResetDither(PhotoInstance *instancePtr);

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted generic/tkImgSVGnano.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876












































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkImgSVGnano.c
 *
 *	A photo file handler for SVG files.
 *
 * Copyright © 2013-14 Mikko Mononen [email protected]
 * Copyright © 2018 Christian Gollwitzer [email protected]
 * Copyright © 2018 Christian Werner https://www.androwish.org/
 * Copyright © 2018 Rene Zaumseil [email protected]
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * This handler is build using the original nanosvg library files from
 * https://github.com/memononen/nanosvg
 *
 */

#include "tkInt.h"
#define NANOSVG_malloc	ckalloc
#define NANOSVG_realloc	ckrealloc
#define NANOSVG_free	ckfree
#define NANOSVG_SCOPE MODULE_SCOPE
#define NANOSVG_ALL_COLOR_KEYWORDS
#define NANOSVG_IMPLEMENTATION
#include "nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvgrast.h"

/* Additional parameters to nsvgRasterize() */

typedef struct {
    double scale;
    int scaleToHeight;
    int scaleToWidth;
} RastOpts;

/*
 * Per interp cache of last NSVGimage which was matched to
 * be immediately rasterized after the match. This helps to
 * eliminate double parsing of the SVG file/string.
 */

typedef struct {
    /* A poiner to remember if it is the same svn image (data)
     * It is a Tcl_Channel if image created by -file option
     * or a Tcl_Obj, if image is created with the -data option
     */
    void *dataOrChan;
    Tcl_DString formatString;
    NSVGimage *nsvgImage;
    RastOpts ropts;
} NSVGcache;

static const void *	MemMem(const void *haystack, size_t haysize,
			       const void *needle, size_t needlen);
static int		FileMatchSVG(Tcl_Channel chan, const char *fileName,
			    Tcl_Obj *format, int *widthPtr, int *heightPtr,
			    Tcl_Interp *interp);
static int		FileReadSVG(Tcl_Interp *interp, Tcl_Channel chan,
			    const char *fileName, Tcl_Obj *format,
			    Tk_PhotoHandle imageHandle, int destX, int destY,
			    int width, int height, int srcX, int srcY);
static int		StringMatchSVG(Tcl_Obj *dataObj, Tcl_Obj *format,
			    int *widthPtr, int *heightPtr, Tcl_Interp *interp);
static int		StringReadSVG(Tcl_Interp *interp, Tcl_Obj *dataObj,
			    Tcl_Obj *format, Tk_PhotoHandle imageHandle,
			    int destX, int destY, int width, int height,
			    int srcX, int srcY);
static NSVGimage *	ParseSVGWithOptions(Tcl_Interp *interp,
			    const char *input, Tcl_Size length, Tcl_Obj *format,
			    RastOpts *ropts);
static int		RasterizeSVG(Tcl_Interp *interp,
			    Tk_PhotoHandle imageHandle, NSVGimage *nsvgImage,
			    int destX, int destY, int width, int height,
			    int srcX, int srcY, RastOpts *ropts);
static double		GetScaleFromParameters(NSVGimage *nsvgImage,
			    RastOpts *ropts, int *widthPtr, int *heightPtr);
static NSVGcache *	GetCachePtr(Tcl_Interp *interp);
static int		CacheSVG(Tcl_Interp *interp, void *dataOrChan,
			    Tcl_Obj *formatObj, NSVGimage *nsvgImage,
			    RastOpts *ropts);
static NSVGimage *	GetCachedSVG(Tcl_Interp *interp, void *dataOrChan,
			    Tcl_Obj *formatObj, RastOpts *ropts);
static void		CleanCache(Tcl_Interp *interp);
static void		FreeCache(void *clientData, Tcl_Interp *interp);

/*
 * The format record for the SVG nano file format:
 */

Tk_PhotoImageFormat tkImgFmtSVGnano = {
    "svg",			/* name */
    FileMatchSVG,		/* fileMatchProc */
    StringMatchSVG,		/* stringMatchProc */
    FileReadSVG,		/* fileReadProc */
    StringReadSVG,		/* stringReadProc */
    NULL,			/* fileWriteProc */
    NULL,			/* stringWriteProc */
    NULL
};

/*
 *----------------------------------------------------------------------
 *
 * MemMem --
 *
 *	Like strstr() but operating on memory buffers with sizes.
 *
 *----------------------------------------------------------------------
 */

static const void *
MemMem(const void *haystack, size_t haylen,
       const void *needle, size_t needlen)
{
    const void *hayend, *second, *p;
    unsigned char first;

    if ((needlen <= 0) || (haylen < needlen)) {
	return NULL;
    }
    hayend = (const void *) ((char *) haystack + haylen - needlen);
    first = ((char *) needle)[0];
    second = (const void *) ((char *) needle + 1);
    needlen -= 1;
    while (haystack < hayend) {
	p = memchr(haystack, first, (char *) hayend - (char *) haystack);
	if (p == NULL) {
	    break;
	}
	if (needlen == 0) {
	    return p;
	}
	haystack = (const void *) ((char *) p + 1);
	if (memcmp(second, haystack, needlen) == 0) {
	    return p;
	}
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * FileMatchSVG --
 *
 *	This function is invoked by the photo image type to see if a file
 *	contains image data in SVG format.
 *
 * Results:
 *	The return value is >0 if the file can be successfully parsed,
 *	and 0 otherwise.
 *
 * Side effects:
 *	The file is saved in the internal cache for further use.
 *
 *----------------------------------------------------------------------
 */

static int
FileMatchSVG(
    Tcl_Channel chan,
    TCL_UNUSED(const char *),
    Tcl_Obj *formatObj,
    int *widthPtr, int *heightPtr,
    Tcl_Interp *interp)
{
    Tcl_Size length;
    Tcl_Obj *dataObj = Tcl_NewObj();
    const char *data;
    RastOpts ropts;
    NSVGimage *nsvgImage;

    CleanCache(interp);
    if (Tcl_ReadChars(chan, dataObj, 4096, 0) == TCL_IO_FAILURE) {
	/* in case of an error reading the file */
	Tcl_DecrRefCount(dataObj);
	return 0;
    }
    data = Tcl_GetStringFromObj(dataObj, &length);
    /* should have a '<svg' and a '>' in the first 4k */
    if ((memchr(data, '>', length) == NULL) ||
	(MemMem(data, length, "<svg", 4) == NULL)) {
	Tcl_DecrRefCount(dataObj);
	return 0;
    }
    if (!Tcl_Eof(chan) && (Tcl_ReadChars(chan, dataObj, TCL_INDEX_NONE, 1) == TCL_IO_FAILURE)) {
	/* in case of an error reading the file */
	Tcl_DecrRefCount(dataObj);
	return 0;
    }
    data = Tcl_GetStringFromObj(dataObj, &length);
    nsvgImage = ParseSVGWithOptions(interp, data, length, formatObj, &ropts);
    Tcl_DecrRefCount(dataObj);
    if (nsvgImage != NULL) {
        GetScaleFromParameters(nsvgImage, &ropts, widthPtr, heightPtr);
        if ((*widthPtr <= 0.0) || (*heightPtr <= 0.0)) {
	    nsvgDelete(nsvgImage);
	    return 0;
        }
        if (!CacheSVG(interp, chan, formatObj, nsvgImage, &ropts)) {
	    nsvgDelete(nsvgImage);
        }
        return 1;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * FileReadSVG --
 *
 *	This function is called by the photo image type to read SVG format
 *	data from a file and write it into a given photo image.
 *
 * Results:
 *	A standard TCL completion code. If TCL_ERROR is returned then an error
 *	message is left in the interp's result.
 *
 * Side effects:
 *	The access position in file f is changed, and new data is added to the
 *	image given by imageHandle.
 *
 *----------------------------------------------------------------------
 */

static int
FileReadSVG(
    Tcl_Interp *interp,
    Tcl_Channel chan,
    TCL_UNUSED(const char *),
    Tcl_Obj *formatObj,
    Tk_PhotoHandle imageHandle,
    int destX, int destY,
    int width, int height,
    int srcX, int srcY)
{
    Tcl_Size length;
    const char *data;
    RastOpts ropts;
    NSVGimage *nsvgImage = GetCachedSVG(interp, chan, formatObj, &ropts);

    if (nsvgImage == NULL) {
        Tcl_Obj *dataObj = Tcl_NewObj();

	if (Tcl_ReadChars(chan, dataObj, TCL_INDEX_NONE, 0) == TCL_IO_FAILURE) {
	    /* in case of an error reading the file */
	    Tcl_DecrRefCount(dataObj);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("read error", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "READ_ERROR", NULL);
	    return TCL_ERROR;
	}
	data = Tcl_GetStringFromObj(dataObj, &length);
	nsvgImage = ParseSVGWithOptions(interp, data, length, formatObj,
			    &ropts);
	Tcl_DecrRefCount(dataObj);
	if (nsvgImage == NULL) {
	    return TCL_ERROR;
	}
    }
    return RasterizeSVG(interp, imageHandle, nsvgImage, destX, destY,
		width, height, srcX, srcY, &ropts);
}

/*
 *----------------------------------------------------------------------
 *
 * StringMatchSVG --
 *
 *	This function is invoked by the photo image type to see if a string
 *	contains image data in SVG format.
 *
 * Results:
 *	The return value is >0 if the file can be successfully parsed,
 *	and 0 otherwise.
 *
 * Side effects:
 *	The file is saved in the internal cache for further use.
 *
 *----------------------------------------------------------------------
 */

static int
StringMatchSVG(
    Tcl_Obj *dataObj,
    Tcl_Obj *formatObj,
    int *widthPtr, int *heightPtr,
    Tcl_Interp *interp)
{
    Tcl_Size length, testLength;
    const char *data;
    RastOpts ropts;
    NSVGimage *nsvgImage;

    CleanCache(interp);
    data = Tcl_GetStringFromObj(dataObj, &length);
    /* should have a '<svg' and a '>' in the first 4k */
    testLength = (length > 4096) ? 4096 : length;
    if ((memchr(data, '>', testLength) == NULL) ||
	(MemMem(data, testLength, "<svg", 4) == NULL)) {
	return 0;
    }
    nsvgImage = ParseSVGWithOptions(interp, data, length, formatObj, &ropts);
    if (nsvgImage != NULL) {
        GetScaleFromParameters(nsvgImage, &ropts, widthPtr, heightPtr);
        if ((*widthPtr <= 0.0) || (*heightPtr <= 0.0)) {
	    nsvgDelete(nsvgImage);
	    return 0;
        }
        if (!CacheSVG(interp, dataObj, formatObj, nsvgImage, &ropts)) {
	    nsvgDelete(nsvgImage);
        }
        return 1;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * StringReadSVG --
 *
 *	This function is called by the photo image type to read SVG format
 *	data from a string and write it into a given photo image.
 *
 * Results:
 *	A standard TCL completion code. If TCL_ERROR is returned then an error
 *	message is left in the interp's result.
 *
 * Side effects:
 *	New data is added to the image given by imageHandle.
 *
 *----------------------------------------------------------------------
 */

static int
StringReadSVG(
    Tcl_Interp *interp,
    Tcl_Obj *dataObj,
    Tcl_Obj *formatObj,
    Tk_PhotoHandle imageHandle,
    int destX, int destY,
    int width, int height,
    int srcX, int srcY)
{
    Tcl_Size length;
    const char *data;
    RastOpts ropts;
    NSVGimage *nsvgImage = GetCachedSVG(interp, dataObj, formatObj, &ropts);

    if (nsvgImage == NULL) {
	data = Tcl_GetStringFromObj(dataObj, &length);
	nsvgImage = ParseSVGWithOptions(interp, data, length, formatObj,
			    &ropts);
    }
    if (nsvgImage == NULL) {
	return TCL_ERROR;
    }
    return RasterizeSVG(interp, imageHandle, nsvgImage, destX, destY,
		width, height, srcX, srcY, &ropts);
}

/*
 *----------------------------------------------------------------------
 *
 * ParseSVGWithOptions --
 *
 *	This function is called to parse the given input string as SVG.
 *
 * Results:
 *	Return a newly create NSVGimage on success, and NULL otherwise.
 *
 * Side effects:
 *
 *----------------------------------------------------------------------
 */

static NSVGimage *
ParseSVGWithOptions(
    Tcl_Interp *interp,
    const char *input,
    Tcl_Size length,
    Tcl_Obj *formatObj,
    RastOpts *ropts)
{
    Tcl_Obj **objv = NULL;
    Tcl_Size objc = 0;
    double dpi = 96.0;
    char *inputCopy = NULL;
    NSVGimage *nsvgImage;
    int parameterScaleSeen = 0;
    static const char *const fmtOptions[] = {
        "-dpi", "-scale", "-scaletoheight", "-scaletowidth", NULL
    };
    enum fmtOptionsEnum {
	OPT_DPI, OPT_SCALE, OPT_SCALE_TO_HEIGHT, OPT_SCALE_TO_WIDTH
    };

    /*
     * The parser destroys the original input string,
     * therefore first duplicate.
     */

    inputCopy = (char *)attemptckalloc(length+1);
    if (inputCopy == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot alloc data buffer", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "OUT_OF_MEMORY", NULL);
	goto error;
    }
    memcpy(inputCopy, input, length);
    inputCopy[length] = '\0';

    /*
     * Process elements of format specification as a list.
     */

    ropts->scale = 1.0;
    ropts->scaleToHeight = 0;
    ropts->scaleToWidth = 0;
    if ((formatObj != NULL) &&
	    Tcl_ListObjGetElements(interp, formatObj, &objc, &objv) != TCL_OK) {
        goto error;
    }
    for (; objc > 0 ; objc--, objv++) {
	int optIndex;

	/*
	 * Ignore the "svg" part of the format specification.
	 */

	if (!strcasecmp(Tcl_GetString(objv[0]), "svg")) {
	    continue;
	}

	if (Tcl_GetIndexFromObjStruct(interp, objv[0], fmtOptions,
		sizeof(char *), "option", 0, &optIndex) == TCL_ERROR) {
	    goto error;
	}

	if (objc < 2) {
	    ckfree(inputCopy);
	    inputCopy = NULL;
	    Tcl_WrongNumArgs(interp, 1, objv, "value");
	    goto error;
	}

	objc--;
	objv++;

	/*
	 * check that only one scale option is given
	 */
	switch ((enum fmtOptionsEnum)optIndex) {
	case OPT_SCALE:
	case OPT_SCALE_TO_HEIGHT:
	case OPT_SCALE_TO_WIDTH:
	    if ( parameterScaleSeen ) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"only one of -scale, -scaletoheight, -scaletowidth may be given", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "BAD_SCALE",
			NULL);
		goto error;
	    }
	    parameterScaleSeen = 1;
	    break;
	default:
	    break;
	}

	/*
	 * Decode parameters
	 */
	switch ((enum fmtOptionsEnum) optIndex) {
	case OPT_DPI:
	    if (Tcl_GetDoubleFromObj(interp, objv[0], &dpi) == TCL_ERROR) {
	        goto error;
	    }
	    if (dpi < 0.0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"-dpi value must be positive", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "BAD_DPI",
			NULL);
		goto error;
	    }
	    break;
	case OPT_SCALE:
	    if (Tcl_GetDoubleFromObj(interp, objv[0], &ropts->scale) ==
		TCL_ERROR) {
	        goto error;
	    }
	    if (ropts->scale <= 0.0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"-scale value must be positive", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "BAD_SCALE",
			NULL);
		goto error;
	    }
	    break;
	case OPT_SCALE_TO_HEIGHT:
	    if (Tcl_GetIntFromObj(interp, objv[0], &ropts->scaleToHeight) ==
		TCL_ERROR) {
	        goto error;
	    }
	    if (ropts->scaleToHeight <= 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"-scaletoheight value must be positive", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "BAD_SCALE",
			NULL);
		goto error;
	    }
	    break;
	case OPT_SCALE_TO_WIDTH:
	    if (Tcl_GetIntFromObj(interp, objv[0], &ropts->scaleToWidth) ==
		TCL_ERROR) {
	        goto error;
	    }
	    if (ropts->scaleToWidth <= 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"-scaletowidth value must be positive", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "BAD_SCALE",
			NULL);
		goto error;
	    }
	    break;
	}
    }

    nsvgImage = nsvgParse(inputCopy, "px", (float) dpi);
    if (nsvgImage == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot parse SVG image", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "PARSE_ERROR", NULL);
	goto error;
    }
    ckfree(inputCopy);
    return nsvgImage;

error:
    if (inputCopy != NULL) {
        ckfree(inputCopy);
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RasterizeSVG --
 *
 *	This function is called to rasterize the given nsvgImage and
 *	fill the imageHandle with data.
 *
 * Results:
 *	A standard TCL completion code. If TCL_ERROR is returned then an error
 *	message is left in the interp's result.
 *
 *
 * Side effects:
 *	On error the given nsvgImage will be deleted.
 *
 *----------------------------------------------------------------------
 */

static int
RasterizeSVG(
    Tcl_Interp *interp,
    Tk_PhotoHandle imageHandle,
    NSVGimage *nsvgImage,
    int destX, int destY,
    int width, int height,
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    RastOpts *ropts)
{
    int w, h, c;
    NSVGrasterizer *rast;
    unsigned char *imgData;
    Tk_PhotoImageBlock svgblock;
    double scale;
    Tcl_WideUInt wh;

    scale = GetScaleFromParameters(nsvgImage, ropts, &w, &h);

    rast = nsvgCreateRasterizer();
    if (rast == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot initialize rasterizer", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "RASTERIZER_ERROR",
		NULL);
	goto cleanAST;
    }

    /* Tk Ticket [822330269b] Check potential int overflow in following ckalloc */
    wh = (Tcl_WideUInt)w * (Tcl_WideUInt)h;
    if ( w < 0 || h < 0 || wh > INT_MAX / 4) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("image size overflow", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "IMAGE_SIZE_OVERFLOW", NULL);
	goto cleanRAST;
    }

    imgData = (unsigned char *)attemptckalloc(wh * 4);
    if (imgData == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot alloc image buffer", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "OUT_OF_MEMORY", NULL);
	goto cleanRAST;
    }
    nsvgRasterize(rast, nsvgImage, 0, 0,
	    (float) scale, imgData, w, h, w * 4);
    /* transfer the data to a photo block */
    svgblock.pixelPtr = imgData;
    svgblock.width = w;
    svgblock.height = h;
    svgblock.pitch = w * 4;
    svgblock.pixelSize = 4;
    for (c = 0; c <= 3; c++) {
	svgblock.offset[c] = c;
    }
    if (Tk_PhotoExpand(interp, imageHandle,
		destX + width, destY + height) != TCL_OK) {
	goto cleanRAST;
    }
    if (Tk_PhotoPutBlock(interp, imageHandle, &svgblock, destX, destY,
		width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
	goto cleanimg;
    }
    ckfree(imgData);
    nsvgDeleteRasterizer(rast);
    nsvgDelete(nsvgImage);
    return TCL_OK;

cleanimg:
    ckfree(imgData);

cleanRAST:
    nsvgDeleteRasterizer(rast);

cleanAST:
    nsvgDelete(nsvgImage);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * GetScaleFromParameters --
 *
 *	Get the scale value from the already parsed parameters -scale,
 *	-scaletoheight and -scaletowidth.
 *
 *	The image width and height is also returned.
 *
 * Results:
 *	The evaluated or configured scale value, or 0.0 on failure
 *
 * Side effects:
 *	heightPtr and widthPtr are set to height and width of the image.
 *
 *----------------------------------------------------------------------
 */

static double
GetScaleFromParameters(
    NSVGimage *nsvgImage,
    RastOpts *ropts,
    int *widthPtr,
    int *heightPtr)
{
    double scale;
    int width, height;

    if ((nsvgImage->width == 0.0) || (nsvgImage->height == 0.0)) {
        width = height = 0;
        scale = 1.0;
    } else if (ropts->scaleToHeight > 0) {
	/*
	 * Fixed height
	 */
	height = ropts->scaleToHeight;
	scale = height / nsvgImage->height;
	width = (int) ceil(nsvgImage->width * scale);
    } else if (ropts->scaleToWidth > 0) {
	/*
	 * Fixed width
	 */
	width = ropts->scaleToWidth;
	scale = width / nsvgImage->width;
	height = (int) ceil(nsvgImage->height * scale);
    } else {
	/*
	 * Scale factor
	 */
	scale = ropts->scale;
	width = (int) ceil(nsvgImage->width * scale);
	height = (int) ceil(nsvgImage->height * scale);
    }

    *heightPtr = height;
    *widthPtr = width;
    return scale;
}

/*
 *----------------------------------------------------------------------
 *
 * GetCachePtr --
 *
 *	This function is called to get the per interpreter used
 *	svg image cache.
 *
 * Results:
 * 	Return a pointer to the used cache.
 *
 * Side effects:
 *	Initialize the cache on the first call.
 *
 *----------------------------------------------------------------------
 */

static NSVGcache *
GetCachePtr(
    Tcl_Interp *interp
) {
    NSVGcache *cachePtr = (NSVGcache *)Tcl_GetAssocData(interp, "tksvgnano", NULL);
    if (cachePtr == NULL) {
	cachePtr = (NSVGcache *)ckalloc(sizeof(NSVGcache));
	cachePtr->dataOrChan = NULL;
	Tcl_DStringInit(&cachePtr->formatString);
	cachePtr->nsvgImage = NULL;
	Tcl_SetAssocData(interp, "tksvgnano", FreeCache, cachePtr);
    }
    return cachePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * CacheSVG --
 *
 *	Add the given svg image informations to the cache for further usage.
 *
 * Results:
 *	Return 1 on success, and 0 otherwise.
 *
 * Side effects:
 *
 *----------------------------------------------------------------------
 */

static int
CacheSVG(
    Tcl_Interp *interp,
    void *dataOrChan,
    Tcl_Obj *formatObj,
    NSVGimage *nsvgImage,
    RastOpts *ropts)
{
    Tcl_Size length;
    const char *data;
    NSVGcache *cachePtr = GetCachePtr(interp);

    if (cachePtr != NULL) {
        cachePtr->dataOrChan = dataOrChan;
	if (formatObj != NULL) {
	    data = Tcl_GetStringFromObj(formatObj, &length);
	    Tcl_DStringAppend(&cachePtr->formatString, data, length);
	}
	cachePtr->nsvgImage = nsvgImage;
	cachePtr->ropts = *ropts;
	return 1;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * GetCachedSVG --
 *
 *	Try to get the NSVGimage from the internal cache.
 *
 * Results:
 *	Return the found NSVGimage on success, and NULL otherwise.
 *
 * Side effects:
 *	Calls the CleanCache() function.
 *
 *----------------------------------------------------------------------
 */

static NSVGimage *
GetCachedSVG(
    Tcl_Interp *interp,
    void *dataOrChan,
    Tcl_Obj *formatObj,
    RastOpts *ropts)
{
    Tcl_Size length;
    const char *data;
    NSVGcache *cachePtr = GetCachePtr(interp);
    NSVGimage *nsvgImage = NULL;

    if ((cachePtr != NULL) && (cachePtr->nsvgImage != NULL) &&
	(cachePtr->dataOrChan == dataOrChan)) {
        if (formatObj != NULL) {
	    data = Tcl_GetStringFromObj(formatObj, &length);
	    if (strcmp(data, Tcl_DStringValue(&cachePtr->formatString)) == 0) {
	        nsvgImage = cachePtr->nsvgImage;
		*ropts = cachePtr->ropts;
		cachePtr->nsvgImage = NULL;
	    }
	} else if (Tcl_DStringLength(&cachePtr->formatString) == 0) {
	    nsvgImage = cachePtr->nsvgImage;
	    *ropts = cachePtr->ropts;
	    cachePtr->nsvgImage = NULL;
	}
    }
    CleanCache(interp);
    return nsvgImage;
}

/*
 *----------------------------------------------------------------------
 *
 * CleanCache --
 *
 *	Reset the cache and delete the saved image in it.
 *
 * Results:
 *
 * Side effects:
 *
 *----------------------------------------------------------------------
 */

static void
CleanCache(Tcl_Interp *interp)
{
    NSVGcache *cachePtr = GetCachePtr(interp);

    if (cachePtr != NULL) {
        cachePtr->dataOrChan = NULL;
        Tcl_DStringSetLength(&cachePtr->formatString, 0);
	if (cachePtr->nsvgImage != NULL) {
	    nsvgDelete(cachePtr->nsvgImage);
	    cachePtr->nsvgImage = NULL;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * FreeCache --
 *
 *	This function is called to clean up the internal cache data.
 *
 * Results:
 *
 * Side effects:
 *	Existing image data in the cache and the cache will be deleted.
 *
 *----------------------------------------------------------------------
 */

static void
FreeCache(void *clientData, TCL_UNUSED(Tcl_Interp *))
{
    NSVGcache *cachePtr = (NSVGcache *)clientData;

    Tcl_DStringFree(&cachePtr->formatString);
    if (cachePtr->nsvgImage != NULL) {
        nsvgDelete(cachePtr->nsvgImage);
    }
    ckfree(cachePtr);
}

Changes to generic/tkImgUtil.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
1
2
3
4
5

6
7
8
9
10
11
12
13

14


15
16
17
18
19
20
21





-
+







-
+
-
-







/*
 * tkImgUtil.c --
 *
 *	This file contains image related utility functions.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "xbytes.h"
#ifdef _WIN32

#   include "tkWinInt.h"
#endif

/*
 *----------------------------------------------------------------------
 *
 * TkAlignImageData --
 *
 *	This function takes an image and copies the data into an aligned
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







-
+







     */

    dataWidth = image->bytes_per_line;
    if (dataWidth % alignment) {
	dataWidth += (alignment - (dataWidth % alignment));
    }

    data = (char *)ckalloc(dataWidth * image->height);
    data = ckalloc(dataWidth * image->height);

    destPtr = data;
    for (i = 0; i < image->height; i++) {
	srcPtr = &image->data[i * image->bytes_per_line];
	for (j = 0; j < dataWidth; j++) {
	    if (j >= image->bytes_per_line) {
		*destPtr = 0;

Changes to generic/tkInt.decls.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







# tkInt.decls --
#
#	This file contains the declarations for all unsupported functions that
#	are exported by the Tk library. This file is used to generate the
#	tkIntDecls.h, tkIntPlatDecls.h, tkIntStub.c, and tkPlatStub.c files.
#
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2007 Daniel A. Steffen <[email protected]>
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2007 Daniel A. Steffen <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

library tk

##############################################################################
63
64
65
66
67
68
69
70
71


72
73
74
75
76
77
78
63
64
65
66
67
68
69


70
71
72
73
74
75
76
77
78







-
-
+
+







#
declare 12 {
    TkCursor *TkCreateCursorFromData(Tk_Window tkwin,
	    const char *source, const char *mask, int width, int height,
	    int xHot, int yHot, XColor fg, XColor bg)
}
declare 13 {
    int TkCreateFrame(void *clientData, Tcl_Interp *interp,
	    Tcl_Size objc, Tcl_Obj *const objv[], int type, const char *appName)
    int TkCreateFrame(ClientData clientData, Tcl_Interp *interp,
	    int argc, const char *const *argv, int toplevel, const char *appName)
}
declare 14 {
    Tk_Window TkCreateMainWindow(Tcl_Interp *interp,
	    const char *screenName, const char *baseName)
}
declare 15 {
    Time TkCurrentTime(TkDisplay *dispPtr)
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109







-
+







	    Display *display, Drawable drawable, GC gc, GC outlineGC)
}
declare 21 {
    int TkFindStateNum(Tcl_Interp *interp, const char *option,
	    const TkStateMap *mapPtr, const char *strKey)
}
declare 22 {
    const char *TkFindStateString(const TkStateMap *mapPtr, int numKey)
    CONST86 char *TkFindStateString(const TkStateMap *mapPtr, int numKey)
}
declare 23 {
    void TkFocusDeadWindow(TkWindow *winPtr)
}
declare 24 {
    int TkFocusFilterEvent(TkWindow *winPtr, XEvent *eventPtr)
}
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155







-
+







    const char *TkGetDefaultScreenName(Tcl_Interp *interp,
	    const char *screenName)
}
declare 34 {
    TkDisplay *TkGetDisplay(Display *display)
}
declare 35 {
    Tcl_Size TkGetDisplayOf(Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[],
    int TkGetDisplayOf(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[],
	    Tk_Window *tkwinPtr)
}
declare 36 {
    TkWindow *TkGetFocusWin(TkWindow *winPtr)
}
declare 37 {
    int TkGetInterpNames(Tcl_Interp *interp, Tk_Window tkwin)
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192







-
+







	    TkWindow *destPtr, int leaveType, int enterType,
	    Tcl_QueuePosition position)
}
declare 45 {
    void TkInstallFrameMenu(Tk_Window tkwin)
}
declare 46 {
    const char *TkKeysymToString(KeySym keysym)
    CONST86 char *TkKeysymToString(KeySym keysym)
}
declare 47 {
    int TkLineToArea(double end1Ptr[], double end2Ptr[], double rectPtr[])
}
declare 48 {
    double TkLineToPoint(double end1Ptr[], double end2Ptr[], double pointPtr[])
}
222
223
224
225
226
227
228



229
230
231
232
233
234
235
236
237
238



239
240
241



242
243
244
245
246
247
248
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257







+
+
+










+
+
+



+
+
+







}
declare 58 {
    void TkpDisplayWarning(const char *msg, const char *title)
}
declare 59 {
    void TkpGetAppName(Tcl_Interp *interp, Tcl_DString *name)
}
declare 60 {
    TkWindow *TkpGetOtherWindow(TkWindow *winPtr)
}
declare 61 {
    TkWindow *TkpGetWrapperWindow(TkWindow *winPtr)
}
declare 62 {
    int TkpInit(Tcl_Interp *interp)
}
declare 63 {
    void TkpInitializeMenuBindings(Tcl_Interp *interp,
	    Tk_BindingTable bindingTable)
}
declare 64 {
    void TkpMakeContainer(Tk_Window tkwin)
}
declare 65 {
    void TkpMakeMenuWindow(Tk_Window tkwin, int transient)
}
declare 66 {
    Window TkpMakeWindow(TkWindow *winPtr, Window parent)
}
declare 67 {
    void TkpMenuNotifyToplevelCreate(Tcl_Interp *interp, const char *menuName)
}
declare 68 {
    TkDisplay *TkpOpenDisplay(const char *display_name)
}
declare 69 {
256
257
258
259
260
261
262









263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286










287
288
289
290
291
292
293
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321







+
+
+
+
+
+
+
+
+










-
+













+
+
+
+
+
+
+
+
+
+







}
declare 72 {
    int TkPositionInTree(TkWindow *winPtr, TkWindow *treePtr)
}
declare 73 {
    void TkpRedirectKeyEvent(TkWindow *winPtr, XEvent *eventPtr)
}
declare 74 {
    void TkpSetMainMenubar(Tcl_Interp *interp, Tk_Window tkwin, const char *menuName)
}
declare 75 {
    int TkpUseWindow(Tcl_Interp *interp, Tk_Window tkwin, const char *string)
}
#
# Slot 76 unused (WAS: TkpWindowWasRecentlyDeleted)
#
declare 77 {
    void TkQueueEventForAllChildren(TkWindow *winPtr, XEvent *eventPtr)
}
declare 78 {
    int TkReadBitmapFile(Display *display, Drawable d, const char *filename,
	    unsigned int *width_return, unsigned int *height_return,
	    Pixmap *bitmap_return, int *x_hot_return, int *y_hot_return)
}
declare 79 {
    int TkScrollWindow(Tk_Window tkwin, GC gc, int x, int y,
	    int width, int height, int dx, int dy, Region damageRgn)
	    int width, int height, int dx, int dy, TkRegion damageRgn)
}
declare 80 {
    void TkSelDeadWindow(TkWindow *winPtr)
}
declare 81 {
    void TkSelEventProc(Tk_Window tkwin, XEvent *eventPtr)
}
declare 82 {
    void TkSelInit(Tk_Window tkwin)
}
declare 83 {
    void TkSelPropProc(XEvent *eventPtr)
}

# Exported publically as Tk_SetClassProcs in 8.4a2
#declare 84 {
#    void TkSetClassProcs(Tk_Window tkwin,
#	    TkClassProcs *procs, ClientData instanceData)
#}
declare 85 {
    void TkSetWindowMenuBar(Tcl_Interp *interp, Tk_Window tkwin,
	    const char *oldMenuName, const char *menuName)
}
declare 86 {
    KeySym TkStringToKeysym(const char *name)
}
declare 87 {
    int TkThickPolyLineToArea(double *coordPtr, int numPoints,
	    double width, int capStyle, int joinStyle, double *rectPtr)
}
357
358
359
360
361
362
363
364

365
366
367
368




369
370
371
372
373

374
375
376

377
378
379

380
381
382

383
384
385

386
387
388
389

390
391
392
393


394
395

396
397
398

399
400
401

402
403
404




405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407

408
409
410

411
412
413

414
415
416

417
418
419
420

421
422
423


424
425
426

427
428
429

430
431
432

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477







-
+




+
+
+
+




-
+


-
+


-
+


-
+


-
+



-
+


-
-
+
+

-
+


-
+


-
+



+
+
+
+














-
+














-
+







    TkMainInfo *TkGetMainInfoList(void)
}
declare 108 {
    int TkGetWindowFromObj(Tcl_Interp *interp, Tk_Window tkwin,
	    Tcl_Obj *objPtr, Tk_Window *windowPtr)
}
declare 109 {
    const char *TkpGetString(TkWindow *winPtr, XEvent *eventPtr, Tcl_DString *dsPtr)
    CONST86 char *TkpGetString(TkWindow *winPtr, XEvent *eventPtr, Tcl_DString *dsPtr)
}
declare 110 {
    void TkpGetSubFonts(Tcl_Interp *interp, Tk_Font tkfont)
}
declare 111 {
    Tcl_Obj *TkpGetSystemDefault(Tk_Window tkwin,
	    const char *dbName, const char *className)
}
declare 112 {
    void TkpMenuThreadInit(void)
}
declare 113 {
    int XClipBox(Region rgn, XRectangle *rect_return)
    void TkClipBox(TkRegion rgn, XRectangle *rect_return)
}
declare 114 {
    Region XCreateRegion(void)
    TkRegion TkCreateRegion(void)
}
declare 115 {
    int XDestroyRegion(Region rgn)
    void TkDestroyRegion(TkRegion rgn)
}
declare 116 {
    int XIntersectRegion(Region sra, Region srcb, Region dr_return)
    void TkIntersectRegion(TkRegion sra, TkRegion srcb, TkRegion dr_return)
}
declare 117 {
    int XRectInRegion(Region rgn, int x, int y, unsigned int width,
    int TkRectInRegion(TkRegion rgn, int x, int y, unsigned int width,
	    unsigned int height)
}
declare 118 {
    int XSetRegion(Display *display, GC gc, Region rgn)
    void TkSetRegion(Display *display, GC gc, TkRegion rgn)
}
declare 119 {
    int XUnionRectWithRegion(XRectangle *rect,
	    Region src, Region dr_return)
    void TkUnionRectWithRegion(XRectangle *rect,
	    TkRegion src, TkRegion dr_return)
}
declare 121 {
declare 121 aqua {
    Pixmap TkpCreateNativeBitmap(Display *display, const void *source)
}
declare 122 {
declare 122 aqua {
    void TkpDefineNativeBitmaps(void)
}
declare 124 {
declare 124 aqua {
    Pixmap TkpGetNativeAppBitmap(Display *display,
	    const char *name, int *width, int *height)
}
declare 135 {
    void TkpDrawHighlightBorder(Tk_Window tkwin, GC fgGC, GC bgGC,
        int highlightWidth, Drawable drawable)
}
declare 136 {
    void TkSetFocusWin(TkWindow *winPtr, int force)
}
declare 137 {
    void TkpSetKeycodeAndState(Tk_Window tkwin, KeySym keySym,
            XEvent *eventPtr)
}
declare 138 {
    KeySym TkpGetKeySym(TkDisplay *dispPtr, XEvent *eventPtr)
}
declare 139 {
    void TkpInitKeymapInfo(TkDisplay *dispPtr)
}
declare 140 {
    Region TkPhotoGetValidRegion(Tk_PhotoHandle handle)
    TkRegion TkPhotoGetValidRegion(Tk_PhotoHandle handle)
}
declare 141 {
    TkWindow **TkWmStackorderToplevel(TkWindow *parentPtr)
}
declare 142 {
    void TkFocusFree(TkMainInfo *mainPtr)
}
declare 143 {
    void TkClipCleanup(TkDisplay *dispPtr)
}
declare 144 {
    void TkGCCleanup(TkDisplay *dispPtr)
}
declare 145 {
    int XSubtractRegion(Region sra, Region srcb, Region dr_return)
    void TkSubtractRegion(TkRegion sra, TkRegion srcb, TkRegion dr_return)
}
declare 146 {
    void TkStylePkgInit(TkMainInfo *mainPtr)
}
declare 147 {
    void TkStylePkgFree(TkMainInfo *mainPtr)
}
458
459
460
461
462
463
464
465

466
467
468

469
470
471
472
473

474
475
476
477

478
479
480
481
482
483

484
485
486
487
488
489
490
491

492
493
494
495
496

497
498
499
500
501
502

503
504
505

506
507
508
509
510
511
512
513
514

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534


535
536
537
538


539
540
541
542


543
544
545
546


547
548
549
550


551
552
553
554


555
556
557
558


559
560
561
562


563
564
565
566


567
568
569
570


571
572
573
574


575
576
577
578


579
580
581
582
583
584
585


586
587
588
589
590
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
606
607
608
609
610
611
612


613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629




630
631








632
633






634
635
636
637
638
639
640
641
642
643
644

645
646

647
648
649
650
651
652
653
654
655
656

657



658

659

660
661
662
663


664
665
666
667
668
669
670
671

672
673
674
675
676
677
678
494
495
496
497
498
499
500

501
502
503

504
505
506
507
508

509
510
511
512

513
514
515
516
517
518

519
520
521
522
523
524
525
526

527
528
529
530
531

532
533
534
535
536
537

538
539
540

541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568


569
570
571
572


573
574
575
576


577
578
579
580


581
582
583
584


585
586
587
588


589
590
591
592


593
594
595
596


597
598
599
600


601
602
603
604


605
606
607
608


609
610
611
612


613
614
615
616
617
618
619


620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637








638


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661


662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680








681
682

683










684
685
686
687
688

689

690
691
692


693
694
695
696
697
698
699
700
701

702
703
704
705
706
707
708
709







-
+


-
+




-
+



-
+





-
+







-
+




-
+





-
+


-
+








-
+


















-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+





-
-
+
+












-
+



-
-
-
-
-
-
-
-

-
-
+
+

















+
+
+
+
-
-
+
+
+
+
+
+
+
+


+
+
+
+
+
+



-
-
-
-
-
-
-
-
+

-
+
-
-
-
-
-
-
-
-
-
-
+

+
+
+
-
+
-
+


-
-
+
+







-
+







	    Tk_Canvas canvas, double *pointPtr, int numPoints)
}
declare 152 {
    void TkpDrawFrame(Tk_Window tkwin, Tk_3DBorder border,
	    int highlightWidth, int borderWidth, int relief)
}
declare 153 {
    void TkCreateThreadExitHandler(Tcl_ExitProc *proc, void *clientData)
    void TkCreateThreadExitHandler(Tcl_ExitProc *proc, ClientData clientData)
}
declare 154 {
    void TkDeleteThreadExitHandler(Tcl_ExitProc *proc, void *clientData)
    void TkDeleteThreadExitHandler(Tcl_ExitProc *proc, ClientData clientData)
}

# entries needed only by tktest:
declare 156 {
    int TkpTestembedCmd(void *clientData, Tcl_Interp *interp, Tcl_Size objc,
    int TkpTestembedCmd(ClientData clientData, Tcl_Interp *interp, int objc,
	    Tcl_Obj *const objv[])
}
declare 157 {
    int TkpTesttextCmd(void *dummy, Tcl_Interp *interp, Tcl_Size objc,
    int TkpTesttextCmd(ClientData dummy, Tcl_Interp *interp, int objc,
	    Tcl_Obj *const objv[])
}
declare 158 {
    int TkSelGetSelection(Tcl_Interp *interp, Tk_Window tkwin,
	    Atom selection, Atom target, Tk_GetSelProc *proc,
	    void *clientData)
	    ClientData clientData)
}
declare 159 {
    int TkTextGetIndex(Tcl_Interp *interp, struct TkText *textPtr,
	    const char *string, struct TkTextIndex *indexPtr)
}
declare 160 {
    int TkTextIndexBackBytes(const struct TkText *textPtr,
	    const struct TkTextIndex *srcPtr, Tcl_Size count,
	    const struct TkTextIndex *srcPtr, int count,
	    struct TkTextIndex *dstPtr)
}
declare 161 {
    int TkTextIndexForwBytes(const struct TkText *textPtr,
	    const struct TkTextIndex *srcPtr, Tcl_Size count,
	    const struct TkTextIndex *srcPtr, int count,
	    struct TkTextIndex *dstPtr)
}
declare 162 {
    struct TkTextIndex *TkTextMakeByteIndex(TkTextBTree tree,
	    const struct TkText *textPtr, int lineIndex,
	    Tcl_Size byteIndex, struct TkTextIndex *indexPtr)
	    int byteIndex, struct TkTextIndex *indexPtr)
}
declare 163 {
    Tcl_Size TkTextPrintIndex(const struct TkText *textPtr,
    int TkTextPrintIndex(const struct TkText *textPtr,
	    const struct TkTextIndex *indexPtr, char *string)
}
declare 164 {
    struct TkTextSegment *TkTextSetMark(struct TkText *textPtr,
	    const char *name, struct TkTextIndex *indexPtr)
}
declare 165 {
    int TkTextXviewCmd(struct TkText *textPtr, Tcl_Interp *interp,
	    Tcl_Size objc, Tcl_Obj *const objv[])
	    int objc, Tcl_Obj *const objv[])
}
declare 166 {
    void TkTextChanged(struct TkSharedText *sharedTextPtr,
	    struct TkText *textPtr, const struct TkTextIndex *index1Ptr,
	    const struct TkTextIndex *index2Ptr)
}
declare 167 {
    int	TkBTreeNumLines(TkTextBTree tree,
	    const struct TkText *textPtr)
}
declare 168 {
    void TkTextInsertDisplayProc(struct TkText *textPtr,
	    struct TkTextDispChunk *chunkPtr, int x, int y,
	    int height, int baseline, Display *display,
	    Drawable dst, int screenY)
}
# Next group of functions exposed due to [Bug 2768945].
declare 169 {
    int TkStateParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkStateParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 170 {
    const char *TkStatePrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkStatePrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 171 {
    int TkCanvasDashParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkCanvasDashParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 172 {
    const char *TkCanvasDashPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkCanvasDashPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 173 {
    int TkOffsetParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkOffsetParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 174 {
    const char *TkOffsetPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkOffsetPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 175 {
    int TkPixelParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkPixelParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 176 {
    const char *TkPixelPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkPixelPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 177 {
    int TkOrientParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkOrientParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 178 {
    const char *TkOrientPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkOrientPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}
declare 179 {
    int TkSmoothParseProc(void *clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset)
    int TkSmoothParseProc(ClientData clientData, Tcl_Interp *interp,
	    Tk_Window tkwin, const char *value, char *widgRec, int offset)
}
declare 180 {
    const char *TkSmoothPrintProc(void *clientData, Tk_Window tkwin,
	    char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr)
    CONST86 char *TkSmoothPrintProc(ClientData clientData, Tk_Window tkwin,
	    char *widgRec, int offset, Tcl_FreeProc **freeProcPtr)
}

# Angled text API, exposed for Emiliano Gavilán's RBC work.
declare 181 {
    void TkDrawAngledTextLayout(Display *display, Drawable drawable, GC gc,
	    Tk_TextLayout layout, int x, int y, double angle, Tcl_Size firstChar,
	    Tcl_Size lastChar)
	    Tk_TextLayout layout, int x, int y, double angle, int firstChar,
	    int lastChar)
}
declare 182 {
    void TkUnderlineAngledTextLayout(Display *display, Drawable drawable,
	    GC gc, Tk_TextLayout layout, int x, int y, double angle,
	    int underline)
}
declare 183 {
    int TkIntersectAngledTextLayout(Tk_TextLayout layout, int x, int y,
	    int width, int height, double angle)
}
declare 184 {
    void TkDrawAngledChars(Display *display,Drawable drawable, GC gc,
	    Tk_Font tkfont, const char *source, Tcl_Size numBytes, double x,
	    Tk_Font tkfont, const char *source, int numBytes, double x,
	    double y, double angle)
}

# Support for aqua's inability to draw outside [NSView drawRect:]
declare 185 {
    void TkpRedrawWidget(Tk_Window tkwin)
}
declare 186 {
    int TkpWillDrawWidget(Tk_Window tkwin)
}

# Debugging / testing functions for photo images
declare 187 {
    int TkDebugPhotoStringMatchDef(Tcl_Interp *inter, Tcl_Obj *data,
declare 185 {
    int TkDebugPhotoStringMatchDef(Tcl_Interp *inter, Tcl_Obj *data, 
            Tcl_Obj *formatString, int *widthPtr, int *heightPtr)
}


##############################################################################

# Define the platform specific internal Tcl interface. These functions are
# only available on the designated platform.

interface tkIntPlat

################################
# Unix specific functions

declare 0 x11 {
    void TkCreateXEventSource(void)
}
#
# Slot 1 unused (WAS: TkFreeWindowId)
# Slot 2 unused (WAS: TkInitXId)
#
declare 2 x11 {
    void TkGenerateActivateEvents(TkWindow *winPtr, int active)
declare 3 x11 {
    int TkpCmapStressed(Tk_Window tkwin, Colormap colormap)
}
declare 4 x11 {
    void TkpSync(Display *display)
}
declare 5 x11 {
    Window TkUnixContainerId(TkWindow *winPtr)
}
declare 6 x11 {
    int TkUnixDoOneXEvent(Tcl_Time *timePtr)
}
declare 7 x11 {
    void TkUnixSetMenubar(Tk_Window tkwin, Tk_Window menubar)
}
declare 8 x11 {
    int TkpScanWindowId(Tcl_Interp *interp, const char *string, Window *idPtr)
}
declare 9 x11 {
    int TkpWmSetState(TkWindow *winPtr, int state)
}
# only needed by tktest:
declare 38 x11 {
    int TkpCmapStressed(Tk_Window tkwin, Colormap colormap)
}
declare 39 x11 {
    void TkpSync(Display *display)
    void TkWmCleanup(TkDisplay *dispPtr)
}
declare 40 x11 {
declare 10 x11 {
    Window TkUnixContainerId(TkWindow *winPtr)
}
declare 41 x11 {
    int TkUnixDoOneXEvent(Tcl_Time *timePtr)
}
declare 42 x11 {
    void TkUnixSetMenubar(Tk_Window tkwin, Tk_Window menubar)
}
declare 43 x11 {
    void TkWmCleanup(TkDisplay *dispPtr)
    void TkSendCleanup(TkDisplay *dispPtr)
}
#
# Slot 11 unused (WAS: TkFreeXId)
#
declare 44 x11 {
declare 12 x11 {
    void TkSendCleanup(TkDisplay *dispPtr)
    int TkpWmSetState(TkWindow *winPtr, int state)
}
# only needed by tktest:
declare 45 x11 {
    int TkpTestsendCmd(void *clientData, Tcl_Interp *interp, Tcl_Size objc,
declare 13 x11 {
    int TkpTestsendCmd(ClientData clientData, Tcl_Interp *interp, int objc,
	    Tcl_Obj *const objv[])
}

################################
# Windows specific functions

declare 0 win {
    void TkCreateXEventSource(void)
    char *TkAlignImageData(XImage *image, int alignment, int bitOrder)
}
declare 2 win {
    void TkGenerateActivateEvents(TkWindow *winPtr, int active)
}
declare 3 win {
    unsigned long TkpGetMS(void)
}
748
749
750
751
752
753
754
755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792




793
794
795
796
797
798
799
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834







-
+


















-
+


















+
+
+
+







declare 26 win {
    void TkWinSetWindowPos(HWND hwnd, HWND siblingHwnd, int pos)
}
declare 27 win {
    void TkWinWmCleanup(HINSTANCE hInstance)
}
declare 28 win {
    void TkWinXCleanup(void *clientData)
    void TkWinXCleanup(ClientData clientData)
}
declare 29 win {
    void TkWinXInit(HINSTANCE hInstance)
}

# new for 8.1

declare 30 win {
    void TkWinSetForegroundWindow(TkWindow *winPtr)
}
declare 31 win {
    void TkWinDialogDebug(int debug)
}
declare 32 win {
    Tcl_Obj *TkWinGetMenuSystemDefault(Tk_Window tkwin,
	    const char *dbName, const char *className)
}
declare 33 win {
    char *TkAlignImageData(XImage *image, int alignment, int bitOrder)
    int TkWinGetPlatformId(void)
}

# new for 8.4.1

declare 34 win {
    void TkWinSetHINSTANCE(HINSTANCE hInstance)
}
declare 35 win {
    int TkWinGetPlatformTheme(void)
}

# Exported through stub table since Tk 8.4.20/8.5.9

declare 36 win {
    LRESULT __stdcall TkWinChildProc(HWND hwnd,
	    UINT message, WPARAM wParam, LPARAM lParam)
}

# new for 8.4.20+/8.5.12+, Cygwin only
declare 37 win {
    void TkCreateXEventSource(void)
}
declare 38 win {
    int TkpCmapStressed(Tk_Window tkwin, Colormap colormap)
}
declare 39 win {
    void TkpSync(Display *display)
}
declare 40 win {
809
810
811
812
813
814
815
816

817
818
819
820
821
822
823
824
825
826
827


828






829
830
831




832
833

834
835
836

837
838
839
840
841
842

843
844
845

846
847
848
849
850
851
852
853
854
855
856
857

858
859
860
861






862
863
864






865
866
867
868
869
870
871
872
873
874










875
876
877



878
879
880
881
882
883
884
885
886



887
888
889
890
891
892
893
894
895



896
897
898
899
900
901



902
903
904
905
906

907
908
909
910
911
912
913
914
915
916
917
918
919



920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940

941
942
943

944
945
946
947
948
949
950
951
952
953
954
955
956





957












958
959
960
961
962
963
964
844
845
846
847
848
849
850

851
852
853



854
855
856
857


858
859
860
861
862
863
864
865
866



867
868
869
870
871

872
873
874

875
876
877
878
879
880

881
882
883

884
885
886
887
888
889
890
891
892
893
894
895

896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029



1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054







-
+


-
-
-




-
-
+
+

+
+
+
+
+
+
-
-
-
+
+
+
+

-
+


-
+





-
+


-
+











-
+




+
+
+
+
+
+



+
+
+
+
+
+










+
+
+
+
+
+
+
+
+
+



+
+
+









+
+
+









+
+
+






+
+
+




-
+













+
+
+




















-
+


-
+










-
-
-
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+







    void TkWmCleanup(TkDisplay *dispPtr)
}
declare 44 win {
    void TkSendCleanup(TkDisplay *dispPtr)
}
# only needed by tktest:
declare 45 win {
    int TkpTestsendCmd(void *clientData, Tcl_Interp *interp, Tcl_Size objc,
    int TkpTestsendCmd(ClientData clientData, Tcl_Interp *interp, int objc,
	    Tcl_Obj *const objv[])
}
declare 47 win {
    Tk_Window TkpGetCapture(void)
}

################################
# Aqua specific functions

declare 1 aqua {
    void TkAboutDlg(void)
declare 0 aqua {
    void TkGenerateActivateEvents(TkWindow *winPtr, int active)
}

# removed duplicates from tkInt table
#declare 1 aqua {
#    Pixmap TkpCreateNativeBitmap(Display *display, const void *source)
#}
#
declare 2 aqua {
    void TkGenerateActivateEvents(TkWindow *winPtr, int active)
}
#declare 2 aqua {
#    void TkpDefineNativeBitmaps(void)
#}

declare 3 aqua {
    unsigned long TkpGetMS(void)
    void TkPointerDeadWindow(TkWindow *winPtr)
}
declare 4 aqua {
    void TkPointerDeadWindow(TkWindow *winPtr)
    void TkpSetCapture(TkWindow *winPtr)
}
declare 5 aqua {
    void TkpSetCursor(TkpCursor cursor)
}
declare 6 aqua {
    int TkpScanWindowId(Tcl_Interp *interp, const char *string, Window *idPtr)
    void TkpWmSetState(TkWindow *winPtr, int state)
}
declare 7 aqua {
    int TkpWmSetState(TkWindow *winPtr, int state)
    void TkAboutDlg(void)
}
declare 8 aqua {
    unsigned int TkMacOSXButtonKeyState(void)
}
declare 9 aqua {
    void TkMacOSXClearMenubarActive(void)
}
declare 10 aqua {
    int TkMacOSXDispatchMenuEvent(int menuID, int index)
}
declare 11 aqua {
    void TkpSetCapture(TkWindow *winPtr)
    void TkMacOSXInstallCursor(int resizeOverride)
}
declare 12 aqua {
    void TkMacOSXHandleTearoffMenu(void)
}

# removed duplicate from tkPlat table(tk.decls)
#declare 13 aqua {
#    void TkMacOSXInvalClipRgns(TkWindow *winPtr)
#}

declare 14 aqua {
    int TkMacOSXDoHLEvent(void *theEvent)
}

# removed duplicate from tkPlat table(tk.decls)
#declare 15 aqua {
#    void *TkMacOSXGetDrawablePort(Drawable drawable)
#}

declare 16 aqua {
    Window TkMacOSXGetXWindow(void *macWinPtr)
}
declare 17 aqua {
    int TkMacOSXGrowToplevel(void *whichWindow, XPoint start)
}
declare 18 aqua {
    void TkMacOSXHandleMenuSelect(short theMenu, unsigned short theItem,
	    int optionKeyPressed)
}

# removed duplicates from tkPlat table(tk.decls)
#declare 19 aqua {
#    void TkMacOSXInitAppleEvents(Tcl_Interp *interp)
#}
#
#declare 20 aqua {
#    void TkMacOSXInitMenus(Tcl_Interp *interp)
#}

declare 21 aqua {
    void TkMacOSXInvalidateWindow(MacDrawable *macWin, int flag)
}
declare 22 aqua {
    int TkMacOSXIsCharacterMissing(Tk_Font tkfont, unsigned int searchChar)
}
declare 23 aqua {
    void TkMacOSXMakeRealWindowExist(TkWindow *winPtr)
}
declare 24 aqua {
    void *TkMacOSXMakeStippleMap(Drawable d1, Drawable d2)
}
declare 25 aqua {
    void TkMacOSXMenuClick(void)
}
declare 26 aqua {
    void TkMacOSXRegisterOffScreenWindow(Window window, void *portPtr)
}
declare 27 aqua {
    int TkMacOSXResizable(TkWindow *winPtr)
}
declare 28 aqua {
    void TkMacOSXSetHelpMenuItemCount(void)
}
declare 29 aqua {
    void TkMacOSXSetScrollbarGrow(TkWindow *winPtr, int flag)
}
declare 30 aqua {
    void TkMacOSXSetUpClippingRgn(Drawable drawable)
}
declare 31 aqua {
    void TkMacOSXSetUpGraphicsPort(GC gc, void *destPort)
}
declare 32 aqua {
    void TkMacOSXUpdateClipRgn(TkWindow *winPtr)
}
declare 33 aqua {
    void TkMacOSXUnregisterMacWindow(void *portPtr)
}
declare 34 aqua {
    int TkMacOSXUseMenuID(short macID)
}
declare 35 aqua {
    Region TkMacOSXVisableClipRgn(TkWindow *winPtr)
    TkRegion TkMacOSXVisableClipRgn(TkWindow *winPtr)
}
declare 36 aqua {
    void TkMacOSXWinBounds(TkWindow *winPtr, void *geometry)
}
declare 37 aqua {
    void TkMacOSXWindowOffset(void *wRef, int *xOffset, int *yOffset)
}
declare 38 aqua {
    int TkSetMacColor(unsigned long pixel, void *macColor)
}
declare 39 aqua {
    void TkSetWMName(TkWindow *winPtr, Tk_Uid titleUid)
}
declare 40 aqua {
    void TkSuspendClipboard(void)
}
declare 41 aqua {
    int TkMacOSXZoomToplevel(void *whichWindow, short zoomPart)
}
declare 42 aqua {
    Tk_Window Tk_TopCoordsToWindow(Tk_Window tkwin, int rootX, int rootY,
	    int *newX, int *newY)
}
declare 43 aqua {
    MacDrawable *TkMacOSXContainerId(TkWindow *winPtr)
}
declare 44 aqua {
    MacDrawable *TkMacOSXGetHostToplevel(TkWindow *winPtr)
}
declare 45 aqua {
    void TkMacOSXPreprocessMenu(void)
}
declare 46 aqua {
    int TkpIsWindowFloating(void *window)
}
declare 47 aqua {
    Tk_Window TkpGetCapture(void)
    Tk_Window TkMacOSXGetCapture(void)
}
declare 49 aqua {
    Tk_Window TkMacOSXGetContainer(TkWindow *winPtr)
    Window TkGetTransientMaster(TkWindow *winPtr)
}
declare 50 aqua {
    int TkGenerateButtonEvent(int x, int y, Window window, unsigned int state)
}
declare 51 aqua {
    void TkGenWMDestroyEvent(Tk_Window tkwin)
}
declare 52 aqua {
    void TkMacOSXSetDrawingEnabled(TkWindow *winPtr, int flag)
}
# Made public as Tk_MacOSXGetNSWindowForDrawable
#declare 54 aqua {
#    void *TkMacOSXDrawable(Drawable drawable)

# removed duplicate from tkPlat table (tk.decls)
#declare 52 aqua {
#    void TkGenWMConfigureEvent(Tk_Window tkwin, int x, int y,
# 	    int width, int height, int flags)
#}

declare 53 aqua {
    unsigned long TkpGetMS(void)
}

# For Canvas3d, requested by Sean Woods
declare 54 aqua {
    void *TkMacOSXDrawable(Drawable drawable)
}
declare 55 aqua {
    int TkpScanWindowId(Tcl_Interp *interp, const char *string, Window *idPtr)
}

##############################################################################

# Define the platform specific internal Xlib interfaces. These functions are
# only available on the designated platform.

interface tkIntXlib
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249





1250
1251
1252
1253
1254
1255
1256
1329
1330
1331
1332
1333
1334
1335
1336




1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348







+
-
-
-
-
+
+
+
+
+







	    KeySym *k, Status *s)
}
declare 80 win {
    int TkPutImage(unsigned long *colors, int ncolors, Display *display,
	    Drawable d, GC gc, XImage *image, int src_x, int src_y,
	    int dest_x, int dest_y, unsigned int width, unsigned int height)
}
# This slot is reserved for use by the clipping rectangle patch:
declare 81 win {
    int XSetClipRectangles(Display *display, GC gc, int clip_x_origin,
	    int clip_y_origin, XRectangle rectangles[], int n, int ordering)
}
#  declare 81 win {
#      XSetClipRectangles(Display *display, GC gc, int clip_x_origin,
#  	    int clip_y_origin, XRectangle rectangles[], int n, int ordering)
#  }

declare 82 win {
    Status XParseColor(Display *display, Colormap map,
          _Xconst char *spec, XColor *colorPtr)
}
declare 83 win {
    GC XCreateGC(Display *display, Drawable d,
	    unsigned long valuemask, XGCValues *values)
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473

1474
1475

1476
1477
1478
1479

1480
1481
1482

1483
1484
1485
1486
1487

1488
1489
1490
1491

1492
1493
1494

1495
1496
1497

1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517

1518
1519

1520
1521
1522

1523
1524
1525

1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544


1545
1546
1547
1548


1549
1550
1551

1552
1553
1554
1555

1556
1557
1558
1559


1560
1561
1562
1563
1564
1565




1566
1567

1568
1569
1570
1571

1572
1573
1574

1575
1576
1577
1578

1579
1580
1581


1582
1583
1584

1585
1586
1587
1588


1589
1590
1591
1592


1593
1594
1595
1596


1597
1598
1599

1600
1601
1602

1603
1604
1605
1606
1607
1608

1609
1610
1611
1612

1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623

1624
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637

1638
1639
1640
1641

1642
1643
1644

1645
1646
1647
1648
1649

1650
1651
1652


1653
1654
1655
1656


1657
1658

1659
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
1496
1497
1498
1499
1500
1501
1502



1503


























































1504

1505
1506

1507
1508
1509
1510

1511
1512
1513

1514
1515
1516
1517
1518

1519
1520
1521
1522

1523
1524
1525

1526
1527
1528

1529
1530
1531

1532









1533
1534

1535





1536
1537

1538
1539
1540

1541
1542
1543

1544
1545
1546

1547









1548
1549

1550
1551
1552


1553
1554
1555
1556


1557
1558
1559
1560

1561




1562
1563
1564


1565
1566
1567
1568




1569
1570
1571
1572
1573

1574
1575
1576
1577

1578
1579
1580

1581




1582
1583


1584
1585
1586
1587

1588
1589
1590


1591
1592
1593
1594


1595
1596
1597
1598


1599
1600
1601
1602

1603
1604
1605

1606



1607
1608

1609
1610
1611
1612

1613



1614
1615

1616
1617
1618
1619
1620

1621



1622
1623
1624
1625

1626



1627
1628

1629
1630
1631
1632

1633
1634
1635

1636





1637
1638


1639
1640
1641
1642


1643
1644
1645

1646









1647
1648
1649

1650





1651
1652


1653
1654
1655


1656
1657
1658
1659


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







-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+



-
+


-
+




-
+



-
+


-
+


-
+


-
+
-
-
-
-
-
-
-
-
-


-
+
-
-
-
-
-
+

-
+


-
+


-
+


-
+
-
-
-
-
-
-
-
-
-


-
+


-
-
+
+


-
-
+
+


-
+
-
-
-
-
+


-
-
+
+


-
-
-
-
+
+
+
+

-
+



-
+


-
+
-
-
-
-
+

-
-
+
+


-
+


-
-
+
+


-
-
+
+


-
-
+
+


-
+


-
+
-
-
-


-
+



-
+
-
-
-


-
+




-
+
-
-
-




-
+
-
-
-


-
+



-
+


-
+
-
-
-
-
-
+

-
-
+
+


-
-
+
+

-
+
-
-
-
-
-
-
-
-
-



-
+
-
-
-
-
-
+

-
-
+
+

-
-
+
+


-
-
+
+

-
+


-
+
-
-
-
-
+

-
-
+
+

-
+


-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
+
-
-
-
-
-
+

-
+


-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+
-
-
-
-



-
+



-
+


-
+



-
+


-
+


-
+


-
+



-
+



-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+



-
+


-
-
+
+

-
+



-
+



-
+



-
+
+
+
+
+
+
+
+



-
+
-
-
-
-



-
-
-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
+

-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-

-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
+
+
-





    int XReparentWindow(Display *d, Window w, Window p, int x, int y)
}
declare 137 win {
    int XPutImage(Display *d, Drawable dr, GC gc, XImage *im,
	    int sx, int sy, int dx, int dy,
	    unsigned int w, unsigned int h)
}
declare 138 win {
    Region XPolygonRegion(XPoint *pts, int n, int rule)
}

declare 139 win {
    int XPointInRegion(Region rgn, int x, int y)
}
# For XIM
declare 140 win {
    XVaNestedList XVaCreateNestedList(int dummy, ...)
}
declare 141 win {
    char *XSetICValues(XIC xic, ...)
}
declare 142 win {
    char *XGetICValues(XIC xic, ...)
}
declare 143 win {
    void XSetICFocus(XIC xic)
}
declare 147 win {
    void XFreeFontSet(Display *display, XFontSet fontset)
}
declare 148 win {
    int XCloseIM(XIM im)
}
declare 149 win {
    Bool XRegisterIMInstantiateCallback(Display *dpy, struct _XrmHashBucketRec *rbd,
	    char *res_name, char *res_class, XIDProc callback, XPointer client_data)
}
declare 150 win {
    Bool XUnregisterIMInstantiateCallback(Display *dpy, struct _XrmHashBucketRec *rbd,
	    char *res_name, char *res_class, XIDProc callback, XPointer client_data)
}
declare 151 win {
    char *XSetLocaleModifiers(const char *modifier_list)
}
declare 152 win {
    XIM XOpenIM(Display *dpy, struct _XrmHashBucketRec *rdb, char *res_name,
	    char *res_class)
}
declare 153 win {
    char *XGetIMValues(XIM im, ...)
}
declare 154 win {
    char *XSetIMValues(XIM im, ...)
}
declare 155 win {
    XFontSet XCreateFontSet(Display *display, _Xconst char *base_font_name_list,
	    char ***missing_charset_list, int *missing_charset_count, char **def_string)
}
declare 156 win {
    void XFreeStringList(char **list)
}
declare 157 win {
    KeySym XkbKeycodeToKeysym(Display *d, unsigned int k, int g, int i)
}
declare 158 win {
    Display *XkbOpenDisplay(const char *name, int *ev_rtrn, int *err_rtrn,
	    int *major_rtrn, int *minor_rtrn, int *reason)
}

################################
# X functions for MacOSX
# X functions for Aqua

declare 0 macosx {
declare 0 aqua {
    int XSetDashes(Display *display, GC gc, int dash_offset,
	    _Xconst char *dash_list, int n)
}
declare 1 macosx {
declare 1 aqua {
    XModifierKeymap *XGetModifierMapping(Display *d)
}
declare 2 macosx {
declare 2 aqua {
    XImage *XCreateImage(Display *d, Visual *v, unsigned int ui1, int i1,
	    int i2, char *cp, unsigned int ui2, unsigned int ui3, int i3,
	    int i4)
}
declare 3 macosx {
declare 3 aqua {
    XImage *XGetImage(Display *d, Drawable dr, int i1, int i2,
	    unsigned int ui1, unsigned int ui2, unsigned long ul, int i3)
}
declare 4 macosx {
declare 4 aqua {
    char *XGetAtomName(Display *d, Atom a)
}
declare 5 macosx {
declare 5 aqua {
    char *XKeysymToString(KeySym k)
}
declare 6 macosx {
declare 6 aqua {
    Colormap XCreateColormap(Display *d, Window w, Visual *v, int i)
}
declare 7 macosx {
declare 7 aqua {
    Cursor XCreatePixmapCursor(Display *d, Pixmap p1, Pixmap p2,
	    XColor *x1, XColor *x2, unsigned int ui1, unsigned int ui2)
}
declare 8 macosx {
    Cursor XCreateGlyphCursor(Display *d, Font f1, Font f2,
	    unsigned int ui1, unsigned int ui2, XColor _Xconst *x1,
	    XColor _Xconst *x2)
}
declare 9 macosx {
    GContext XGContextFromGC(GC g)
}
declare 10 macosx {
declare 8 aqua {
    XHostAddress *XListHosts(Display *d, int *i, Bool *b)
}
# second parameter was of type KeyCode
declare 11 macosx {
    KeySym XKeycodeToKeysym(Display *d, unsigned int k, int i)
    KeySym XKeycodeToKeysym(Display *d, KeyCode k, int i)
}
declare 12 macosx {
declare 9 aqua {
    KeySym XStringToKeysym(_Xconst char *c)
}
declare 13 macosx {
declare 10 aqua {
    Window XRootWindow(Display *d, int i)
}
declare 14 macosx {
declare 11 aqua {
    XErrorHandler XSetErrorHandler(XErrorHandler x)
}
declare 15 macosx {
declare 12 aqua {
    Status XIconifyWindow(Display *d, Window w, int i)
}
declare 16 macosx {
    Status XWithdrawWindow(Display *d, Window w, int i)
}
declare 17 macosx {
    Status XGetWMColormapWindows(Display *d, Window w, Window **wpp, int *ip)
}
declare 18 macosx {
    Status XAllocColor(Display *d, Colormap c, XColor *xp)
}
declare 19 macosx {
declare 13 aqua {
    int XBell(Display *d, int i)
}
declare 20 macosx {
    int XChangeProperty(Display *d, Window w, Atom a1, Atom a2, int i1,
declare 14 aqua {
    void XChangeProperty(Display *d, Window w, Atom a1, Atom a2, int i1,
	    int i2, _Xconst unsigned char *c, int i3)
}
declare 21 macosx {
    int XChangeWindowAttributes(Display *d, Window w, unsigned long ul,
declare 15 aqua {
    void XChangeWindowAttributes(Display *d, Window w, unsigned long ul,
	    XSetWindowAttributes *x)
}
declare 22 macosx {
declare 16 aqua {
    int XClearWindow(Display *d, Window w)
}
declare 23 macosx {
    int XConfigureWindow(Display *d, Window w, unsigned int i,
    void XConfigureWindow(Display *d, Window w, unsigned int i,
	    XWindowChanges *x)
}
declare 24 macosx {
    int XCopyArea(Display *d, Drawable dr1, Drawable dr2, GC g, int i1,
declare 17 aqua {
    void XCopyArea(Display *d, Drawable dr1, Drawable dr2, GC g, int i1,
	    int i2, unsigned int ui1, unsigned int ui2, int i3, int i4)
}
declare 25 macosx {
    int XCopyPlane(Display *d, Drawable dr1, Drawable dr2, GC g, int i1,
	    int i2, unsigned int ui1, unsigned int ui2,
	    int i3, int i4, unsigned long ul)
declare 18 aqua {
    void XCopyPlane(Display *d, Drawable dr1, Drawable dr2, GC g, int i1,
	    int i2, unsigned int ui1,
	    unsigned int ui2, int i3, int i4, unsigned long ul)
}
declare 26 macosx {
declare 19 aqua {
    Pixmap XCreateBitmapFromData(Display *display, Drawable d,
	    _Xconst char *data, unsigned int width, unsigned int height)
}
declare 27 macosx {
declare 20 aqua {
    int XDefineCursor(Display *d, Window w, Cursor c)
}
declare 28 macosx {
declare 21 aqua {
    int XDeleteProperty(Display *d, Window w, Atom a)
}
declare 29 macosx {
    int XDestroyWindow(Display *d, Window w)
    void XDestroyWindow(Display *d, Window w)
}
declare 30 macosx {
    int XDrawArc(Display *d, Drawable dr, GC g, int i1, int i2,
declare 22 aqua {
    void XDrawArc(Display *d, Drawable dr, GC g, int i1, int i2,
	    unsigned int ui1, unsigned int ui2, int i3, int i4)
}
declare 31 macosx {
declare 23 aqua {
    int XDrawLines(Display *d, Drawable dr, GC g, XPoint *x, int i1, int i2)
}
declare 32 macosx {
    int XDrawRectangle(Display *d, Drawable dr, GC g, int i1, int i2,
declare 24 aqua {
    void XDrawRectangle(Display *d, Drawable dr, GC g, int i1, int i2,
	    unsigned int ui1, unsigned int ui2)
}
declare 33 macosx {
    int XFillArc(Display *d, Drawable dr, GC g, int i1, int i2,
declare 25 aqua {
    void XFillArc(Display *d, Drawable dr, GC g, int i1, int i2,
	    unsigned int ui1, unsigned int ui2, int i3, int i4)
}
declare 34 macosx {
    int XFillPolygon(Display *d, Drawable dr, GC g, XPoint *x,
declare 26 aqua {
    void XFillPolygon(Display *d, Drawable dr, GC g, XPoint *x,
	    int i1, int i2, int i3)
}
declare 35 macosx {
declare 27 aqua {
    int XFillRectangles(Display *d, Drawable dr, GC g, XRectangle *x, int i)
}
declare 36 macosx {
declare 28 aqua {
    int XForceScreenSaver(Display *d, int i)
}
declare 37 macosx {
    int XFreeColormap(Display *d, Colormap c)
}
declare 38 macosx {
declare 29 aqua {
    int XFreeColors(Display *d, Colormap c,
	    unsigned long *ulp, int i, unsigned long ul)
}
declare 39 macosx {
declare 30 aqua {
    int XFreeCursor(Display *d, Cursor c)
}
declare 40 macosx {
    int XFreeModifiermap(XModifierKeymap *x)
}
declare 41 macosx {
declare 31 aqua {
    Status XGetGeometry(Display *d, Drawable dr, Window *w, int *i1,
	    int *i2, unsigned int *ui1, unsigned int *ui2, unsigned int *ui3,
	    unsigned int *ui4)
}
declare 42 macosx {
declare 32 aqua {
    int XGetInputFocus(Display *d, Window *w, int *i)
}
declare 43 macosx {
    int XGetWindowProperty(Display *d, Window w, Atom a1, long l1, long l2,
	    Bool b, Atom a2, Atom *ap, int *ip, unsigned long *ulp1,
	    unsigned long *ulp2, unsigned char **cpp)
}
declare 44 macosx {
declare 33 aqua {
    Status XGetWindowAttributes(Display *d, Window w, XWindowAttributes *x)
}
declare 45 macosx {
    int XGrabKeyboard(Display *d, Window w, Bool b, int i1, int i2, Time t)
}
declare 46 macosx {
declare 34 aqua {
    int XGrabPointer(Display *d, Window w1, Bool b, unsigned int ui,
	    int i1, int i2, Window w2, Cursor c, Time t)
}
declare 47 macosx {
declare 35 aqua {
    KeyCode XKeysymToKeycode(Display *d, KeySym k)
}
declare 48 macosx {
declare 36 aqua {
    Status XLookupColor(Display *d, Colormap c1, _Xconst char *c2,
	    XColor *x1, XColor *x2)
}
declare 49 macosx {
    int XMapWindow(Display *d, Window w)
    void XMapWindow(Display *d, Window w)
}
declare 50 macosx {
    int XMoveResizeWindow(Display *d, Window w, int i1, int i2,
declare 37 aqua {
    void XMoveResizeWindow(Display *d, Window w, int i1, int i2,
	    unsigned int ui1, unsigned int ui2)
}
declare 51 macosx {
    int XMoveWindow(Display *d, Window w, int i1, int i2)
declare 38 aqua {
    void XMoveWindow(Display *d, Window w, int i1, int i2)
}
declare 52 macosx {
declare 39 aqua {
    int XNextEvent(Display *d, XEvent *x)
}
declare 53 macosx {
    int XPutBackEvent(Display *d, XEvent *x)
}
declare 54 macosx {
    int XQueryColors(Display *d, Colormap c, XColor *x, int i)
}
declare 55 macosx {
    Bool XQueryPointer(Display *d, Window w1, Window *w2, Window *w3,
	    int *i1, int *i2, int *i3, int *i4, unsigned int *ui)
}
declare 56 macosx {
declare 40 aqua {
    Status XQueryTree(Display *d, Window w1, Window *w2, Window *w3,
	    Window **w4, unsigned int *ui)
}
declare 57 macosx {
    int XRaiseWindow(Display *d, Window w)
    void XRaiseWindow(Display *d, Window w)
}
declare 58 macosx {
    int XRefreshKeyboardMapping(XMappingEvent *x)
declare 41 aqua {
    void XRefreshKeyboardMapping(XMappingEvent *x)
}
declare 59 macosx {
    int XResizeWindow(Display *d, Window w, unsigned int ui1,
declare 42 aqua {
    void XResizeWindow(Display *d, Window w, unsigned int ui1,
	    unsigned int ui2)
}
declare 60 macosx {
    int XSelectInput(Display *d, Window w, long l)
declare 43 aqua {
    void XSelectInput(Display *d, Window w, long l)
}
declare 61 macosx {
declare 44 aqua {
    Status XSendEvent(Display *d, Window w, Bool b, long l, XEvent *x)
}
declare 62 macosx {
declare 45 aqua {
    int XSetCommand(Display *d, Window w, char **c, int i)
}
declare 63 macosx {
    int XSetIconName(Display *d, Window w, _Xconst char *c)
    void XSetIconName(Display *d, Window w, _Xconst char *c)
}
declare 64 macosx {
    int XSetInputFocus(Display *d, Window w, int i, Time t)
declare 46 aqua {
    void XSetInputFocus(Display *d, Window w, int i, Time t)
}
declare 65 macosx {
declare 47 aqua {
    int XSetSelectionOwner(Display *d, Atom a, Window w, Time t)
}
declare 66 macosx {
    int XSetWindowBackground(Display *d, Window w, unsigned long ul)
declare 48 aqua {
    void XSetWindowBackground(Display *d, Window w, unsigned long ul)
}
declare 67 macosx {
    int XSetWindowBackgroundPixmap(Display *d, Window w, Pixmap p)
declare 49 aqua {
    void XSetWindowBackgroundPixmap(Display *d, Window w, Pixmap p)
}
declare 68 macosx {
    int XSetWindowBorder(Display *d, Window w, unsigned long ul)
declare 50 aqua {
    void XSetWindowBorder(Display *d, Window w, unsigned long ul)
}
declare 69 macosx {
    int XSetWindowBorderPixmap(Display *d, Window w, Pixmap p)
declare 51 aqua {
    void XSetWindowBorderPixmap(Display *d, Window w, Pixmap p)
}
declare 70 macosx {
    int XSetWindowBorderWidth(Display *d, Window w, unsigned int ui)
declare 52 aqua {
    void XSetWindowBorderWidth(Display *d, Window w, unsigned int ui)
}
declare 71 macosx {
    int XSetWindowColormap(Display *d, Window w, Colormap c)
declare 53 aqua {
    void XSetWindowColormap(Display *d, Window w, Colormap c)
}
declare 72 macosx {
declare 54 aqua {
    Bool XTranslateCoordinates(Display *d, Window w1, Window w2, int i1,
	    int i2, int *i3, int *i4, Window *w3)
}
declare 73 macosx {
    int XUngrabKeyboard(Display *d, Time t)
    void XUngrabKeyboard(Display *d, Time t)
}
declare 74 macosx {
declare 55 aqua {
    int XUngrabPointer(Display *d, Time t)
}
declare 75 macosx {
    int XUnmapWindow(Display *d, Window w)
declare 56 aqua {
    void XUnmapWindow(Display *d, Window w)
}
declare 76 macosx {
declare 57 aqua {
    int XWindowEvent(Display *d, Window w, long l, XEvent *x)
}
declare 77 macosx {
    void XDestroyIC(XIC x)
}
declare 78 macosx {
    Bool XFilterEvent(XEvent *x, Window w)
}
declare 79 macosx {
    int XmbLookupString(XIC xi, XKeyPressedEvent *xk, char *c, int i,
	    KeySym *k, Status *s)
}
declare 80 macosx {
    int TkPutImage(unsigned long *colors, int ncolors, Display *display,
	    Drawable d, GC gc, XImage *image, int src_x, int src_y,
	    int dest_x, int dest_y, unsigned int width, unsigned int height)
}
declare 81 macosx {
declare 58 aqua {
    int XSetClipRectangles(Display *display, GC gc, int clip_x_origin,
	    int clip_y_origin, XRectangle rectangles[], int n, int ordering)
}
declare 82 macosx {
    Status XParseColor(Display *display, Colormap map,
          _Xconst char *spec, XColor *colorPtr)
}
declare 83 macosx {
declare 59 aqua {
    GC XCreateGC(Display *display, Drawable d,
	    unsigned long valuemask, XGCValues *values)
}
declare 84 macosx {
declare 60 aqua {
    int XFreeGC(Display *display, GC gc)
}
declare 85 macosx {
declare 61 aqua {
    Atom XInternAtom(Display *display, _Xconst char *atom_name,
	    Bool only_if_exists)
}
declare 86 macosx {
declare 62 aqua {
    int XSetBackground(Display *display, GC gc, unsigned long foreground)
}
declare 87 macosx {
declare 63 aqua {
    int XSetForeground(Display *display, GC gc, unsigned long foreground)
}
declare 88 macosx {
declare 64 aqua {
    int XSetClipMask(Display *display, GC gc, Pixmap pixmap)
}
declare 89 macosx {
declare 65 aqua {
    int XSetClipOrigin(Display *display, GC gc,
	    int clip_x_origin, int clip_y_origin)
}
declare 90 macosx {
declare 66 aqua {
    int XSetTSOrigin(Display *display, GC gc,
	    int ts_x_origin, int ts_y_origin)
}
declare 91 macosx {
declare 67 aqua {
    int XChangeGC(Display *d, GC gc, unsigned long mask, XGCValues *values)
}
declare 92 macosx {
declare 68 aqua {
    int XSetFont(Display *display, GC gc, Font font)
}
declare 93 macosx {
declare 69 aqua {
    int XSetArcMode(Display *display, GC gc, int arc_mode)
}
declare 94 macosx {
declare 70 aqua {
    int XSetStipple(Display *display, GC gc, Pixmap stipple)
}
declare 95 macosx {
declare 71 aqua {
    int XSetFillRule(Display *display, GC gc, int fill_rule)
}
declare 96 macosx {
declare 72 aqua {
    int XSetFillStyle(Display *display, GC gc, int fill_style)
}
declare 97 macosx {
declare 73 aqua {
    int XSetFunction(Display *display, GC gc, int function)
}
declare 98 macosx {
declare 74 aqua {
    int XSetLineAttributes(Display *display, GC gc, unsigned int line_width,
	    int line_style, int cap_style, int join_style)
}
declare 99 macosx {
declare 75 aqua {
    int _XInitImageFuncPtrs(XImage *image)
}
declare 100 macosx {
    XIC XCreateIC(XIM xim, ...)
declare 76 aqua {
    XIC XCreateIC(void)
}
declare 101 macosx {
declare 77 aqua {
    XVisualInfo *XGetVisualInfo(Display *display, long vinfo_mask,
	    XVisualInfo *vinfo_template, int *nitems_return)
}
declare 102 macosx {
declare 78 aqua {
    void XSetWMClientMachine(Display *display, Window w,
	    XTextProperty *text_prop)
}
declare 103 macosx {
declare 79 aqua {
    Status XStringListToTextProperty(char **list, int count,
	    XTextProperty *text_prop_return)
}
declare 104 macosx {
declare 80 aqua {
    int XDrawSegments(Display *display, Drawable d, GC gc,
	    XSegment *segments, int nsegments)
}
declare 81 aqua {
    void XForceScreenSaver(Display *display, int mode)
}
declare 82 aqua {
    int XDrawLine(Display *d, Drawable dr, GC g, int x1, int y1,
	    int x2, int y2)
}
declare 105 macosx {
declare 83 aqua {
    int XWarpPointer(Display *d, Window s, Window dw, int sx, int sy,
	    unsigned int sw, unsigned int sh, int dx, int dy)
}
declare 106 macosx {
    int XFillRectangle(Display *display, Drawable d, GC gc,
	    int x, int y, unsigned int width, unsigned int height)
}

# New in Tk 8.6
declare 107 macosx {
    int XFlush(Display *display)
declare 84 aqua {
    void XClearWindow(Display *d, Window w)
}
declare 108 macosx {
declare 85 aqua {
    int XGrabServer(Display *display)
}
declare 109 macosx {
    int XUngrabServer(Display *display)
}
declare 110 macosx {
    int XFree(void *data)
}
declare 111 macosx {
    int XNoOp(Display *display)
    int XDrawPoint(Display *display, Drawable d, GC gc, int x, int y)
}
declare 112 macosx {
declare 86 aqua {
    XAfterFunction XSynchronize(Display *display, Bool onoff)
}
declare 113 macosx {
    int XSync(Display *display, Bool discard)
    int XDrawPoints(Display *display, Drawable d, GC gc, XPoint *points,
}
declare 114 macosx {
    VisualID XVisualIDFromVisual(Visual *visual)
}

	    int npoints, int mode)
# For tktreectrl
declare 120 macosx {
    int XOffsetRegion(Region rgn, int dx, int dy)
}
declare 121 macosx {
declare 87 aqua {
    int XUnionRegion(Region srca, Region srcb, Region dr_return)
}

# For 3dcanvas
declare 122 macosx {
    Window XCreateWindow(Display *display, Window parent, int x, int y,
	    unsigned int width, unsigned int height,
    int XWarpPointer(Display *display, Window src_w, Window dest_w,
	    int src_x, int src_y, unsigned int src_width,
	    unsigned int border_width, int depth, unsigned int clazz,
	    Visual *visual, unsigned long value_mask,
	    XSetWindowAttributes *attributes)
}

	    unsigned int src_height, int dest_x, int dest_y)
# Various, e.g. for stub-enabled BLT
declare 129 macosx {
    int XLowerWindow(Display *d, Window w)
}
declare 130 macosx {
    int XFillArcs(Display *d, Drawable dr, GC gc, XArc *a, int n)
}
declare 131 macosx {
    int XDrawArcs(Display *d, Drawable dr, GC gc, XArc *a, int n)
}
declare 132 macosx {
    int XDrawRectangles(Display *d, Drawable dr, GC gc, XRectangle *r, int n)
}
declare 133 macosx {
    int XDrawSegments(Display *d, Drawable dr, GC gc, XSegment *s, int n)
}
declare 134 macosx {
    int XDrawPoint(Display *d, Drawable dr, GC gc, int x, int y)
}
declare 135 macosx {
    int XDrawPoints(Display *d, Drawable dr, GC gc, XPoint *p, int n, int m)
}
declare 136 macosx {
declare 88 aqua {
    int XReparentWindow(Display *d, Window w, Window p, int x, int y)
}
declare 137 macosx {
    int XPutImage(Display *d, Drawable dr, GC gc, XImage *im,
    void XQueryColor(Display *display, Colormap colormap, XColor *def_in_out)
	    int sx, int sy, int dx, int dy,
	    unsigned int w, unsigned int h)
}
declare 138 macosx {
declare 89 aqua {
    Region XPolygonRegion(XPoint *pts, int n, int rule)
}
declare 139 macosx {
    int XPointInRegion(Region rgn, int x, int y)
}
# For XIM
declare 140 macosx {
    XVaNestedList XVaCreateNestedList(int dummy, ...)
}
declare 141 macosx {
    char *XSetICValues(XIC xic, ...)
}
declare 142 macosx {
    char *XGetICValues(XIC xic, ...)
}
declare 143 macosx {
    void XSetICFocus(XIC xic)
}
declare 147 macosx {
    void XFreeFontSet(Display *display, XFontSet fontset)
    void XQueryColors(Display *display, Colormap colormap,
}
declare 148 macosx {
    int XCloseIM(XIM im)
	    XColor *defs_in_out, int ncolors)
}
declare 149 macosx {
declare 90 aqua {
    Bool XRegisterIMInstantiateCallback(Display *dpy, struct _XrmHashBucketRec *rbd,
	    char *res_name, char *res_class, XIDProc callback, XPointer client_data)
}
declare 150 macosx {
    Bool XUnregisterIMInstantiateCallback(Display *dpy, struct _XrmHashBucketRec *rbd,
	    char *res_name, char *res_class, XIDProc callback, XPointer client_data)
}
declare 151 macosx {
    char *XSetLocaleModifiers(const char *modifier_list)
}
declare 152 macosx {
    XIM XOpenIM(Display *dpy, struct _XrmHashBucketRec *rdb, char *res_name,
    Status XQueryTree(Display *d, Window w1, Window *w2, Window *w3,
	    char *res_class)
}
declare 153 macosx {
    char *XGetIMValues(XIM im, ...)
}
declare 154 macosx {
    char *XSetIMValues(XIM im, ...)
}
declare 155 macosx {
    XFontSet XCreateFontSet(Display *display, _Xconst char *base_font_name_list,
	    char ***missing_charset_list, int *missing_charset_count, char **def_string)
}
declare 156 macosx {
    void XFreeStringList(char **list)
}
declare 157 macosx {
    KeySym XkbKeycodeToKeysym(Display *d, unsigned int k, int g, int i)
	    Window **w4, unsigned int *ui)
}
declare 158 macosx {
    Display *XkbOpenDisplay(const char *name, int *ev_rtrn, int *err_rtrn,
declare 91 aqua {
    int XSync(Display *display, Bool flag)
	    int *major_rtrn, int *minor_rtrn, int *reason)
}

# Local Variables:
# mode: tcl
# End:

Changes to generic/tkInt.h.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


35
36
37
38
39
40
41








-
+


















+






-
-







/*
 * tkInt.h --
 *
 *	Declarations for things used internally by the Tk functions but not
 *	exported outside the module.
 *
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998 Scriptics Corporation.
 * Copyright (c) 1998 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKINT
#define _TKINT

#ifndef _TKPORT
#include "tkPort.h"
#endif

/*
 * Ensure WORDS_BIGENDIAN is defined correctly:
 * Needs to happen here in addition to configure to work with fat compiles on
 * Darwin (where configure runs only once for multiple architectures).
 */

#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
#    include <sys/types.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#    include <sys/param.h>
#endif
#include <stdint.h>
#include <stdlib.h>
#ifdef BYTE_ORDER
#    ifdef BIG_ENDIAN
#	 if BYTE_ORDER == BIG_ENDIAN
#	     undef WORDS_BIGENDIAN
#	     define WORDS_BIGENDIAN 1
#	 endif
#    endif
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



94
95
96
97


98
99

100
101
102
103


104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119


120
121

122
123


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
55
56
57
58
59
60
61























62
63
64
65
66
67


68
69
70




71
72


73




74
75








76

77






78
79


80
81

82
83
84










85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+
+
+
-
-
-
-
+
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
+
+
-
-
+

-
+
+

-
-
-
-
-
-
-
-
-
-










-
+














-
+








-
+







#   ifdef __cplusplus
#	define MODULE_SCOPE extern "C"
#   else
#	define MODULE_SCOPE extern
#   endif
#endif

#ifndef JOIN
#  define JOIN(a,b) JOIN1(a,b)
#  define JOIN1(a,b) a##b
#endif

#ifndef TCL_UNUSED
#   if defined(__cplusplus)
#	define TCL_UNUSED(T) T
#   elif defined(__GNUC__) && (__GNUC__ > 2)
#	define TCL_UNUSED(T) T JOIN(dummy, __LINE__) __attribute__((unused))
#   else
#	define TCL_UNUSED(T) T JOIN(dummy, __LINE__)
#   endif
#endif

#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#   define TKFLEXARRAY
#elif defined(__GNUC__) && (__GNUC__ > 2)
#   define TKFLEXARRAY 0
#else
#   define TKFLEXARRAY 1
#endif

/*
 * Macros used to cast between pointers and integers (e.g. when storing an int
 * in ClientData), on 64-bit architectures they avoid gcc warning about "cast
 * to/from pointer from/to integer of different size".
 */

#if !defined(INT2PTR)
#   define INT2PTR(p) ((void *)(ptrdiff_t)(p))
#if !defined(INT2PTR) && !defined(PTR2INT)
#   if defined(HAVE_INTPTR_T) || defined(intptr_t)
#	define INT2PTR(p) ((void*)(intptr_t)(p))
#endif
#if !defined(PTR2INT)
#   define PTR2INT(p) ((ptrdiff_t)(p))
#endif
#	define PTR2INT(p) ((int)(intptr_t)(p))
#   else
#if !defined(UINT2PTR)
#   define UINT2PTR(p) ((void *)(size_t)(p))
#	define INT2PTR(p) ((void*)(p))
#endif
#if !defined(PTR2UINT)
#   define PTR2UINT(p) ((size_t)(p))
#endif
#	define PTR2INT(p) ((int)(p))
#   endif

/*
 * Fallback in case Tk is linked against a Tcl version not having TIP #585
 * (TCL_INDEX_TEMP_TABLE) or TIP #613/#618 (TCL_NULL_OK)
 */

#ifndef TCL_NULL_OK
#   define TCL_NULL_OK 32
#endif
#if !defined(TCL_INDEX_TEMP_TABLE)
#if !defined(UINT2PTR) && !defined(PTR2UINT)
#   define TCL_INDEX_TEMP_TABLE 64
#endif

#ifndef TCL_Z_MODIFIER
#   if defined(_WIN64)
#	define TCL_Z_MODIFIER	"I"
#   if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
#	define UINT2PTR(p) ((void*)(uintptr_t)(p))
#   elif defined(__GNUC__) && !defined(_WIN32)
#	define TCL_Z_MODIFIER	"z"
#	define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
#   else
#	define TCL_Z_MODIFIER	""
#	define UINT2PTR(p) ((void*)(p))
#	define PTR2UINT(p) ((unsigned int)(p))
#   endif
#endif /* !TCL_Z_MODIFIER */
#undef TCL_LL_MODIFIER
#if defined(_WIN32) && (!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO)
#   define TCL_LL_MODIFIER	"I64"
#else
#   define TCL_LL_MODIFIER	"ll"
#endif

#if !defined(TCL_SIZE_MODIFIER)
#   define TCL_SIZE_MODIFIER ""
#endif

/*
 * Opaque type declarations:
 */

typedef struct TkColormap TkColormap;
typedef struct TkFontAttributes TkFontAttributes;
typedef struct TkGrabEvent TkGrabEvent;
typedef struct TkpCursor_ *TkpCursor;
#define TkRegion Region
typedef struct TkRegion_ *TkRegion;
typedef struct TkStressedCmap TkStressedCmap;
typedef struct TkBindInfo_ *TkBindInfo;
typedef struct Busy *TkBusy;

/*
 * One of the following structures is maintained for each cursor in use in the
 * system. This structure is used by tkCursor.c and the various system-
 * specific cursor files.
 */

typedef struct TkCursor {
    Tk_Cursor cursor;		/* System specific identifier for cursor. */
    Display *display;		/* Display containing cursor. Needed for
				 * disposal and retrieval of cursors. */
    Tcl_Size resourceRefCount;	/* Number of active uses of this cursor (each
    int resourceRefCount;	/* Number of active uses of this cursor (each
				 * active use corresponds to a call to
				 * Tk_AllocPreserveFromObj or Tk_Preserve). If
				 * this count is 0, then this structure is no
				 * longer valid and it isn't present in a hash
				 * table: it is being kept around only because
				 * there are objects referring to it. The
				 * structure is freed when resourceRefCount
				 * and objRefCount are both 0. */
    Tcl_Size objRefCount;		/* Number of Tcl objects that reference this
    int objRefCount;		/* Number of Tcl objects that reference this
				 * structure.. */
    Tcl_HashTable *otherTable;	/* Second table (other than idTable) used to
				 * index this entry. */
    Tcl_HashEntry *hashPtr;	/* Entry in otherTable for this structure
				 * (needed when deleting). */
    Tcl_HashEntry *idHashPtr;	/* Entry in idTable for this structure (needed
				 * when deleting). */
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
147
148
149
150
151
152
153


154
155
156
157
158
159
160







-
-








/*
 * One of the following structures is maintained for each display containing a
 * window managed by Tk. In part, the structure is used to store thread-
 * specific data, since each thread will have its own TkDisplay structure.
 */

typedef enum TkLockUsage {LU_IGNORE, LU_CAPS, LU_SHIFT} TkLockUsage;

typedef struct TkDisplay {
    Display *display;		/* Xlib's info about display. */
    struct TkDisplay *nextPtr;	/* Next in list of all displays. */
    char *name;			/* Name of display (with any screen identifier
				 * removed). Malloc-ed. */
    Time lastEventTime;		/* Time of last event received for this
				 * display. */
240
241
242
243
244
245
246
247

248
249
250

251
252
253
254
255
256
257
188
189
190
191
192
193
194

195
196
197

198
199
200
201
202
203
204
205







-
+


-
+







				 * modifier, than this is zero. */
    unsigned int metaModMask;	/* Has one bit set to indicate the modifier
				 * corresponding to the "Meta" key. If no such
				 * modifier, then this is zero. */
    unsigned int altModMask;	/* Has one bit set to indicate the modifier
				 * corresponding to the "Meta" key. If no such
				 * modifier, then this is zero. */
    TkLockUsage lockUsage;
    enum {LU_IGNORE, LU_CAPS, LU_SHIFT} lockUsage;
				/* Indicates how to interpret lock
				 * modifier. */
    Tcl_Size numModKeyCodes;		/* Number of entries in modKeyCodes array
    int numModKeyCodes;		/* Number of entries in modKeyCodes array
				 * below. */
    KeyCode *modKeyCodes;	/* Pointer to an array giving keycodes for all
				 * of the keys that have modifiers associated
				 * with them. Malloc'ed, but may be NULL. */

    /*
     * Information used by tkBitmap.c only:
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276







-
+







     * Information used by tkError.c only:
     */

    struct TkErrorHandler *errorPtr;
				/* First in list of error handlers for this
				 * display. NULL means no handlers exist at
				 * present. */
    Tcl_Size deleteCount;		/* Counts # of handlers deleted since last
    int deleteCount;		/* Counts # of handlers deleted since last
				 * time inactive handlers were garbage-
				 * collected. When this number gets big,
				 * handlers get cleaned up. */

    /*
     * Used by tkEvent.c only:
     */
366
367
368
369
370
371
372
373
374
375



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
314
315
316
317
318
319
320



321
322
323
324
325









326
327
328
329
330
331
332







-
-
-
+
+
+


-
-
-
-
-
-
-
-
-







				 * initializing. */

    /*
     * Information used by tkGeometry.c only:
     */

    Tcl_HashTable maintainHashTable;
				/* Hash table that maps from a container's
				 * Tk_Window token to a list of windows managed
				 * by that container. */
				/* Hash table that maps from a master's
				 * Tk_Window token to a list of slaves managed
				 * by that master. */
    int geomInit;

    /*
     * Information used by tkGrid.c, tkPack.c, tkPlace.c, tkPointer.c,
     * and ttkMacOSXTheme.c:
     */

#define TkGetContainer(tkwin) (Tk_TopWinHierarchy((TkWindow *)tkwin) ? NULL : \
	(((TkWindow *)tkwin)->maintainerPtr != NULL ? \
	 ((TkWindow *)tkwin)->maintainerPtr : ((TkWindow *)tkwin)->parentPtr))

    /*
     * Information used by tkGet.c only:
     */

    Tcl_HashTable uidTable;	/* Stores all Tk_Uid used in a thread. */
    int uidInit;		/* 0 means uidTable needs initializing. */

455
456
457
458
459
460
461
462

463
464

465
466
467
468
469
470
471
394
395
396
397
398
399
400

401
402

403
404
405
406
407
408
409
410







-
+

-
+







				 * Packer structures. */

    /*
     * Information used by tkPlace.c only.
     */

    int placeInit;		/* 0 means tables below need initializing. */
    Tcl_HashTable containerTable;	/* Maps from Tk_Window token to the Container
    Tcl_HashTable masterTable;	/* Maps from Tk_Window toke to the Master
				 * structure for the window, if it exists. */
    Tcl_HashTable contentTable;	/* Maps from Tk_Window token to the Content
    Tcl_HashTable slaveTable;	/* Maps from Tk_Window toke to the Slave
				 * structure for the window, if it exists. */

    /*
     * Information used by tkSelect.c and tkClipboard.c only:
     */

    struct TkSelectionInfo *selectionInfoPtr;
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
419
420
421
422
423
424
425

426
427
428
429
430
431
432







-







    Atom timestampAtom;		/* Atom for TIMESTAMP. */
    Atom textAtom;		/* Atom for TEXT. */
    Atom compoundTextAtom;	/* Atom for COMPOUND_TEXT. */
    Atom applicationAtom;	/* Atom for TK_APPLICATION. */
    Atom windowAtom;		/* Atom for TK_WINDOW. */
    Atom clipboardAtom;		/* Atom for CLIPBOARD. */
    Atom utf8Atom;		/* Atom for UTF8_STRING. */
    Atom atomPairAtom;          /* Atom for ATOM_PAIR. */

    Tk_Window clipWindow;	/* Window used for clipboard ownership and to
				 * retrieve selections between processes. NULL
				 * means clipboard info hasn't been
				 * initialized. */
    int clipboardActive;	/* 1 means we currently own the clipboard
				 * selection, 0 means we don't. */
529
530
531
532
533
534
535
536

537
538
539
540
541
542
543

544
545
546
547








548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580


581
582
583
584
585


586
587
588
589
590
591
592
467
468
469
470
471
472
473

474
475
476
477
478
479
480

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512




513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539







-
+






-
+




+
+
+
+
+
+
+
+

















+

-
-
-
-











+
+





+
+







    TkColormap *cmapPtr;	/* First in list of all non-default colormaps
				 * allocated for this display. */

    /*
     * Miscellaneous information:
     */

#if defined(TK_USE_INPUT_METHODS) || (TCL_MAJOR_VERSION > 8)
#ifdef TK_USE_INPUT_METHODS
    XIM inputMethod;		/* Input method for this display. */
    XIMStyle inputStyle;	/* Input style selected for this display. */
    XFontSet inputXfs;		/* XFontSet cached for over-the-spot XIM. */
#endif /* TK_USE_INPUT_METHODS */
    Tcl_HashTable winTable;	/* Maps from X window ids to TkWindow ptrs. */

    Tcl_Size refCount;		/* Reference count of how many Tk applications
    size_t refCount;		/* Reference count of how many Tk applications
				 * are using this display. Used to clean up
				 * the display when we no longer have any Tk
				 * applications using it. */

    /*
     * The following field were all added for Tk8.3
     */

    int mouseButtonState;	/* Current mouse button state for this
				 * display. */
    Window mouseButtonWindow;	/* Window the button state was set in, added
				 * in Tk 8.4. */
    Tk_Window warpWindow;
    Tk_Window warpMainwin;	/* For finding the root window for warping
				 * purposes. */
    int warpX;
    int warpY;

    /*
     * The following field(s) were all added for Tk8.4
     */

    unsigned int flags;		/* Various flag values: these are all defined
				 * in below. */
    TkCaret caret;		/* Information about the caret for this
				 * display. This is not a pointer. */

    int iconDataSize;		/* Size of default iconphoto image data. */
    unsigned char *iconDataPtr;	/* Default iconphoto image data, if set. */
#ifdef TK_USE_INPUT_METHODS
    int ximGeneration;          /* Used to invalidate XIC */
#if !defined(TK_USE_INPUT_METHODS) && (TCL_MAJOR_VERSION < 9)
    XIM inputMethod;		/* Input method for this display. */
    XIMStyle inputStyle;	/* Input style selected for this display. */
    XFontSet inputXfs;		/* XFontSet cached for over-the-spot XIM. */
#endif /* TK_USE_INPUT_METHODS */
} TkDisplay;

/*
 * Flag values for TkDisplay flags.
 *  TK_DISPLAY_COLLAPSE_MOTION_EVENTS:	(default on)
 *	Indicates that we should collapse motion events on this display
 *  TK_DISPLAY_USE_IM:			(default on, set via tk.tcl)
 *	Whether to use input methods for this display
 *  TK_DISPLAY_WM_TRACING:		(default off)
 *	Whether we should do wm tracing on this display.
 *  TK_DISPLAY_IN_WARP:			(default off)
 *	Indicates that we are in a pointer warp
 */

#define TK_DISPLAY_COLLAPSE_MOTION_EVENTS	(1 << 0)
#define TK_DISPLAY_USE_IM			(1 << 1)
#define TK_DISPLAY_WM_TRACING			(1 << 3)
#define TK_DISPLAY_IN_WARP			(1 << 4)
#define TK_DISPLAY_USE_XKB			(1 << 5)

/*
 * One of the following structures exists for each error handler created by a
 * call to Tk_CreateErrorHandler. The structure is managed by tkError.c.
 */

typedef struct TkErrorHandler {
603
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
658
659
660
550
551
552
553
554
555
556

557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592
593
594
595


596



597
598
599
600
601
602
603







-
+














-
+












-
+










-
-
+
-
-
-







				 * request code (-1 means consider all major
				 * codes). */
    int minorCode;		/* Consider only errors with this minor
				 * request code (-1 means consider all minor
				 * codes). */
    Tk_ErrorProc *errorProc;	/* Function to invoke when a matching error
				 * occurs. NULL means just ignore errors. */
    void *clientData;	/* Arbitrary value to pass to errorProc. */
    ClientData clientData;	/* Arbitrary value to pass to errorProc. */
    struct TkErrorHandler *nextPtr;
				/* Pointer to next older handler for this
				 * display, or NULL for end of list. */
} TkErrorHandler;

/*
 * One of the following structures exists for each event handler created by
 * calling Tk_CreateEventHandler. This information is used by tkEvent.c only.
 */

typedef struct TkEventHandler {
    unsigned long mask;		/* Events for which to invoke proc. */
    Tk_EventProc *proc;		/* Function to invoke when an event in mask
				 * occurs. */
    void *clientData;	/* Argument to pass to proc. */
    ClientData clientData;	/* Argument to pass to proc. */
    struct TkEventHandler *nextPtr;
				/* Next in list of handlers associated with
				 * window (NULL means end of list). */
} TkEventHandler;

/*
 * Tk keeps one of the following data structures for each main window (created
 * by a call to TkCreateMainWindow). It stores information that is shared by
 * all of the windows associated with a particular main window.
 */

typedef struct TkMainInfo {
    Tcl_Size refCount;		/* Number of windows whose "mainPtr" fields
    size_t refCount;		/* Number of windows whose "mainPtr" fields
				 * point here. When this becomes zero, can
				 * free up the structure (the reference count
				 * is zero because windows can get deleted in
				 * almost any order; the main window isn't
				 * necessarily the last one deleted). */
    struct TkWindow *winPtr;	/* Pointer to main window. */
    Tcl_Interp *interp;		/* Interpreter associated with application. */
    Tcl_HashTable nameTable;	/* Hash table mapping path names to TkWindow
				 * structs for all windows related to this
				 * main window. Managed by tkWindow.c. */
#if TCL_MAJOR_VERSION > 8
    size_t deletionEpoch;		/* Incremented by window deletions. */
    long deletionEpoch;		/* Incremented by window deletions. */
#else
    long deletionEpoch;
#endif
    Tk_BindingTable bindingTable;
				/* Used in conjunction with "bind" command to
				 * bind events to Tcl commands. */
    TkBindInfo bindInfo;	/* Information used by tkBind.c on a per
				 * application basis. */
    struct TkFontInfo *fontInfoPtr;
				/* Information used by tkFont.c on a per
674
675
676
677
678
679
680
681

682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
617
618
619
620
621
622
623

624
625
626
627
628
629
630
631
632












633
634
635
636
637
638
639







-
+








-
-
-
-
-
-
-
-
-
-
-
-







				 * application has ever used. Used only by
				 * tkFocus.c. */

    struct ElArray *optionRootPtr;
				/* Top level of option hierarchy for this main
				 * window. NULL means uninitialized. Managed
				 * by tkOption.c. */
    Tcl_HashTable imageTable;	/* Maps from image names to Tk_ImageModel
    Tcl_HashTable imageTable;	/* Maps from image names to Tk_ImageMaster
				 * structures. Managed by tkImage.c. */
    int strictMotif;		/* This is linked to the tk_strictMotif global
				 * variable. */
    int alwaysShowSelection;	/* This is linked to the
				 * ::tk::AlwaysShowSelection variable. */
    struct TkMainInfo *nextPtr;	/* Next in list of all main windows managed by
				 * this process. */
    Tcl_HashTable busyTable;	/* Information used by [tk busy] command. */
    Tcl_ObjCmdProc *tclUpdateObjProc;
				/* Saved Tcl [update] command, used to restore
				 * Tcl's version of [update] after Tk is shut
				 * down */
#if TCL_MAJOR_VERSION > 8
    Tcl_ObjCmdProc2 *tclUpdateObjProc2;
				/* Saved Tcl [update] command, used to restore
				 * Tcl's version of [update] after Tk is shut
				 * down, in case it's a Tcl_ObjCmdProc2 */
#endif
    unsigned int ttkNbTabsStickBit;
    				/* Information used by ttk::notebook. */
} TkMainInfo;

/*
 * Tk keeps the following data structure for each of it's builtin bitmaps.
 * This structure is only used by tkBitmap.c and other platform specific
 * bitmap files.
 */
733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
664
665
666
667
668
669
670

671
672
673
674
675
676
677
678







-
+







    TkDisplay *dispPtr;		/* Tk's information about display for
				 * window. */
    int screenNum;		/* Index of screen for window, among all those
				 * for dispPtr. */
    Visual *visual;		/* Visual to use for window. If not default,
				 * MUST be set before X window is created. */
    int depth;			/* Number of bits/pixel. */
    Window window;		/* X's id for window. None means window hasn't
    Window window;		/* X's id for window. NULL means window hasn't
				 * actually been created yet, or it's been
				 * deleted. */
    struct TkWindow *childList;	/* First in list of child windows, or NULL if
				 * no children. List is in stacking order,
				 * lowest window first.*/
    struct TkWindow *lastChildPtr;
				/* Last in list of child windows (highest in
795
796
797
798
799
800
801
802

803
804
805
806
807
808
809
810
811

812
813
814

815
816
817
818
819
820

821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839

840
841
842
843
844
845
846
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741

742
743
744

745
746
747
748
749
750

751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769

770
771
772
773
774
775
776
777







-
+








-
+


-
+





-
+


















-
+








    /*
     * Information kept by the event manager (tkEvent.c):
     */

    TkEventHandler *handlerList;/* First in list of event handlers declared
				 * for this window, or NULL if none. */
#if defined(TK_USE_INPUT_METHODS) || (TCL_MAJOR_VERSION > 8)
#ifdef TK_USE_INPUT_METHODS
    XIC inputContext;		/* XIM input context. */
#endif /* TK_USE_INPUT_METHODS */

    /*
     * Information used for event bindings (see "bind" and "bindtags" commands
     * in tkCmds.c):
     */

    void **tagPtr;		/* Points to array of tags used for bindings
    ClientData *tagPtr;		/* Points to array of tags used for bindings
				 * on this window. Each tag is a Tk_Uid.
				 * Malloc'ed. NULL means no tags. */
    Tcl_Size numTags;		/* Number of tags at *tagPtr. */
    int numTags;		/* Number of tags at *tagPtr. */

    /*
     * Information used by tkOption.c to manage options for the window.
     */

    Tcl_Size optionLevel;		/* TCL_INDEX_NONE means no option information is currently
    int optionLevel;		/* -1 means no option information is currently
				 * cached for this window. Otherwise this
				 * gives the level in the option stack at
				 * which info is cached. */
    /*
     * Information used by tkSelect.c to manage the selection.
     */

    struct TkSelHandler *selHandlerList;
				/* First in list of handlers for returning the
				 * selection in various forms. */

    /*
     * Information used by tkGeometry.c for geometry management.
     */

    const Tk_GeomMgr *geomMgrPtr;
				/* Information about geometry manager for this
				 * window. */
    void *geomData;	/* Argument for geometry manager functions. */
    ClientData geomData;	/* Argument for geometry manager functions. */
    int reqWidth, reqHeight;	/* Arguments from last call to
				 * Tk_GeometryRequest, or 0's if
				 * Tk_GeometryRequest hasn't been called. */
    int internalBorderLeft;	/* Width of internal border of window (0 means
				 * no internal border). Geometry managers
				 * should not normally place children on top
				 * of the border. Fields for the other three
857
858
859
860
861
862
863
864

865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883

884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960
788
789
790
791
792
793
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813

814


815







816
817
818
819










820
821
822
823
824
825
826








827
828
829
830
831

832
833
834
835

836
837
838
839
840
841
842
843
844
845
846
847
848
849
850




851
852

853
854
855
856
857
858
859
860







-
+


















-
+
-
-
+
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-







-
-
-
-
-
-
-
-





-
+



-















-
-
-
-


-
+







				 * NULL. */

    /*
     * Information used by widget classes.
     */

    const Tk_ClassProcs *classProcsPtr;
    void *instanceData;
    ClientData instanceData;

    /*
     * Platform specific information private to each port.
     */

    struct TkWindowPrivate *privatePtr;

    /*
     * More information used by tkGeometry.c for geometry management.
     */

    /* The remaining fields of internal border. */
    int internalBorderRight;
    int internalBorderTop;
    int internalBorderBottom;

    int minReqWidth;		/* Minimum requested width. */
    int minReqHeight;		/* Minimum requested height. */
#if defined(TK_USE_INPUT_METHODS) || (TCL_MAJOR_VERSION > 8)
    char *geometryMaster;
    int ximGeneration;          /* Used to invalidate XIC */
#endif /* TK_USE_INPUT_METHODS */
#ifdef TK_USE_INPUT_METHODS
    char *geomMgrName;          /* Records the name of the geometry manager. */
    struct TkWindow *maintainerPtr;
				/* The geometry container for this window. The
				 * value is NULL if the window has no container or
				 * if its container is its parent. */
#if !defined(TK_USE_INPUT_METHODS) && (TCL_MAJOR_VERSION < 9)
    XIC inputContext;		/* XIM input context. */
    int ximGeneration;          /* Used to invalidate XIC */
#endif /* TK_USE_INPUT_METHODS */
} TkWindow;

/*
 * String tables:
 */

MODULE_SCOPE const char *const tkStateStrings[];
MODULE_SCOPE const char *const tkCompoundStrings[];
MODULE_SCOPE const char *const tkAnchorStrings[];
MODULE_SCOPE const char *const tkReliefStrings[];
MODULE_SCOPE const char *const tkJustifyStrings[];

/*
 * Real definition of some events. Note that these events come from outside
 * but have internally generated pieces added to them.
 */

typedef struct {
    XKeyEvent keyEvent;		/* The real event from X11. */
#ifdef _WIN32
#   ifndef XMaxTransChars
#	define XMaxTransChars 7
#   endif
    char trans_chars[XMaxTransChars];
                            /* translated characters */
    unsigned char nbytes;
#elif !defined(MAC_OSX_TK)
    char *charValuePtr;		/* A pointer to a string that holds the key's
				 * %A substitution text (before backslash
				 * adding), or NULL if that has not been
				 * computed yet. If non-NULL, this string was
				 * allocated with ckalloc(). */
    Tcl_Size charValueLen;	/* Length of string in charValuePtr when that
    int charValueLen;		/* Length of string in charValuePtr when that
				 * is non-NULL. */
    KeySym keysym;		/* Key symbol computed after input methods
				 * have been invoked */
#endif
} TkKeyEvent;

/*
 * Flags passed to TkpMakeMenuWindow's 'transient' argument.
 */

#define TK_MAKE_MENU_TEAROFF	0	/* Only non-transient case. */
#define TK_MAKE_MENU_POPUP	1
#define TK_MAKE_MENU_DROPDOWN	2

/*
 * The following structure is used with TkMakeEnsemble to create ensemble
 * commands and optionally to create sub-ensembles.
 */

#if (TCL_MAJOR_VERSION < 9) && !defined(Tcl_ObjCmdProc2)
#define Tcl_ObjCmdProc2 Tcl_ObjCmdProc
#endif

typedef struct TkEnsemble {
    const char *name;
    Tcl_ObjCmdProc2 *proc;
    Tcl_ObjCmdProc *proc;
    const struct TkEnsemble *subensemble;
} TkEnsemble;

/*
 * The following structure is used as a two way map between integers and
 * strings, usually to map between an internal C representation and the
 * strings used in Tcl.
970
971
972
973
974
975
976
977

978
979
980
981
982
983
984
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884







-
+







 * representation of a clip_mask in a GC.
 */

typedef struct TkpClipMask {
    int type;			/* TKP_CLIP_PIXMAP or TKP_CLIP_REGION. */
    union {
	Pixmap pixmap;
	Region region;
	TkRegion region;
    } value;
} TkpClipMask;

#define TKP_CLIP_PIXMAP 0
#define TKP_CLIP_REGION 1

/*
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081







1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116

1117
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150

1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206












































































































































1207



1208
1209
1210
1211




1212
1213
1214
1215


1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227

1228
1229

1230
1231
1232

1233
1234
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246


1247
1248
1249
1250
1251
1252
1253


1254
1255
1256
1257
1258


1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272



1273
1274
1275

1276
1277
1278

1279
1280

1281
1282
1283
1284
1285

1286
1287
1288
1289


1290
1291
1292

1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324

1325
1326
1327
1328
1329
1330
1331
1332





1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343



1344
1345
1346
1347
1348




1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
918
919
920
921
922
923
924
925
926



































927
928
929
930
















931
932
933
934
935
936
937
938
939
940
941
942
943
944
945

946
947
948

949
950

951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970

971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000




1001

1002
1003
1004
1005

1006
1007
1008
1009
1010
1011














































1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155




1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177

1178
1179
1180

1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194


1195
1196




1197


1198
1199
1200
1201
1202


1203
1204
1205
1206

1207


1208
1209
1210
1211
1212
1213
1214
1215

1216
1217
1218
1219
1220

1221

1222

1223
1224

1225



1226

1227




1228
1229



1230
1231
1232
1233
1234
1235
1236
1237
1238






















1239

1240
1241
1242






1243
1244
1245
1246
1247


1248
1249
1250


1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269




1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+








-
+


-
+

-




















-
+








+




















-
-
-
-

-
+



-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
-
-
-
-
+
+
+
+



-
+
+











-
+

-
+


-
+










+


-
-
+
+
-
-
-
-

-
-
+
+



-
-
+
+


-
+
-
-








-
+
+
+


-
+
-

-
+

-
+
-
-
-

-
+
-
-
-
-
+
+
-
-
-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+


-
-
-
-
-
-
+
+
+
+
+
-
-
+


-
-




-
+
+
+




-
+
+
+
+




-
-
-
-











 * modifiers such as Meta and Alt that may float among the actual modifier
 * bits.
 */

#define META_MASK	(AnyModifier<<1)
#define ALT_MASK	(AnyModifier<<2)
#define EXTENDED_MASK	(AnyModifier<<3)

/*
 * Buttons 8 and 9 are the Xbuttons (left and right side-buttons). On Windows/Mac, those
 * are known as Buttons 4 and 5. At script level, they also get the numbers 4 and 5.
 */

#ifndef Button8
# define Button8 8
#endif
#ifndef Button9
# define Button9 9
#endif

#ifndef Button6Mask
# define Button6Mask (1<<13)
#endif
#ifndef Button7Mask
# define Button7Mask (1<<14)
#endif
#ifndef Button8Mask
# define Button8Mask (AnyModifier<<4)
#endif
#ifndef Button9Mask
# define Button9Mask (AnyModifier<<5)
#endif

/*
 * Mask that selects any of the state bits corresponding to buttons, plus
 * masks that select individual buttons' bits:
 */

#define ALL_BUTTONS \
	(Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask \
		|Button6Mask|Button7Mask|Button8Mask|Button9Mask)


/*
 * Object types not declared in tkObj.c need to be mentioned here so they can
 * be properly registered with Tcl:
 */

typedef struct {
    Tcl_ObjType objType;
    size_t version;
} TkObjType;

#ifndef TCL_OBJTYPE_V0
#   define TCL_OBJTYPE_V0 /* just empty */
#endif

MODULE_SCOPE const TkObjType tkBorderObjType;
MODULE_SCOPE const TkObjType tkBitmapObjType;
MODULE_SCOPE const TkObjType tkColorObjType;
MODULE_SCOPE const TkObjType tkCursorObjType;
MODULE_SCOPE const TkObjType tkFontObjType;
MODULE_SCOPE const TkObjType tkStateKeyObjType;
MODULE_SCOPE const TkObjType tkTextIndexType;
MODULE_SCOPE const Tcl_ObjType tkBorderObjType;
MODULE_SCOPE const Tcl_ObjType tkBitmapObjType;
MODULE_SCOPE const Tcl_ObjType tkColorObjType;
MODULE_SCOPE const Tcl_ObjType tkCursorObjType;
MODULE_SCOPE const Tcl_ObjType tkFontObjType;
MODULE_SCOPE const Tcl_ObjType tkStateKeyObjType;
MODULE_SCOPE const Tcl_ObjType tkTextIndexType;

/*
 * Miscellaneous variables shared among Tk modules but not exported to the
 * outside world:
 */

MODULE_SCOPE const Tk_SmoothMethod tkBezierSmoothMethod;
MODULE_SCOPE Tk_ImageType	tkBitmapImageType;
MODULE_SCOPE Tk_PhotoImageFormatVersion3 tkImgFmtGIF;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtGIF;
MODULE_SCOPE void		(*tkHandleEventProc) (XEvent* eventPtr);
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtDefault;
MODULE_SCOPE Tk_PhotoImageFormatVersion3 tkImgFmtPNG;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtPNG;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtPPM;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtSVGnano;
MODULE_SCOPE TkMainInfo		*tkMainWindowList;
MODULE_SCOPE Tk_ImageType	tkPhotoImageType;
MODULE_SCOPE Tcl_HashTable	tkPredefBitmapTable;

MODULE_SCOPE const char *const tkWebColors[20];

/*
 * The definition of pi, at least from the perspective of double-precision
 * floats.
 */

#ifndef PI
#ifdef M_PI
#define PI	M_PI
#else
#define PI	3.14159265358979323846
#endif
#endif

/*
 * Support for Clang Static Analyzer <https://clang-analyzer.llvm.org/>
 * Support for Clang Static Analyzer <http://clang-analyzer.llvm.org>
 */

#if defined(PURIFY) && defined(__clang__)
#if __has_feature(attribute_analyzer_noreturn) && \
	!defined(Tcl_Panic) && defined(Tcl_Panic_TCL_DECLARED)
void Tcl_Panic(const char *, ...) __attribute__((analyzer_noreturn));
#endif
#if !defined(CLANG_ASSERT)
#include <assert.h>
#define CLANG_ASSERT(x) assert(x)
#endif
#elif !defined(CLANG_ASSERT)
#define CLANG_ASSERT(x)
#endif /* PURIFY && __clang__ */

/*
 * The following magic value is stored in the "send_event" field of FocusIn
 * and FocusOut events. This allows us to separate "real" events coming from
 * the server from those that we generated.
 */

#define GENERATED_FOCUS_EVENT_MAGIC	((Bool) 0x547321ac)

/*
 * Exported internals.
 */

#include "tkIntDecls.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Themed widget set init function, and handler called when Tk is destroyed.
 * Themed widget set init function:
 */

MODULE_SCOPE int	Ttk_Init(Tcl_Interp *interp);
MODULE_SCOPE void	Ttk_TkDestroyedHandler(Tcl_Interp *interp);

/*
 * Internal functions shared among Tk modules but not exported to the outside
 * world:
 */

MODULE_SCOPE Tcl_ObjCmdProc Tk_BellObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_BindObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_BindtagsObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc2 Tk_BusyObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ButtonObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_CanvasObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_CheckbuttonObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ClipboardObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ChooseColorObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ChooseDirectoryObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_DestroyObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_EntryObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_EventObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_FrameObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_FocusObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_FontObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_GetOpenFileObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_GetSaveFileObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_GrabObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_GridObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ImageObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_LabelObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_LabelframeObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ListboxObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_LowerObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_MenuObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_MenubuttonObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_MessageBoxObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_MessageObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_PanedWindowObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_OptionObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_PackObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_PlaceObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_RadiobuttonObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_RaiseObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ScaleObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ScrollbarObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_SelectionObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_SendObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_SpinboxObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_TextObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_TkwaitObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_ToplevelObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_UpdateObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_WinfoObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc Tk_WmObjCmd;
MODULE_SCOPE int	Tk_BellObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_BindObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_BindtagsObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_BusyObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ButtonObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_CanvasObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int argc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_CheckbuttonObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ClipboardObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ChooseColorObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ChooseDirectoryObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_DestroyObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_EntryObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_EventObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_FrameObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_FocusObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_FontObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_GetOpenFileObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_GetSaveFileObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_GrabObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_GridObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ImageObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_LabelObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_LabelframeObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ListboxObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_LowerObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_MenuObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_MenubuttonObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_MessageBoxObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_MessageObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_PanedWindowObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_OptionObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_PackObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_PlaceObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_RadiobuttonObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_RaiseObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ScaleObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ScrollbarObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_SelectionObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_SendObjCmd(ClientData clientData,
			    Tcl_Interp *interp,int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_SendObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_SpinboxObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_TextObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_TkwaitObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_ToplevelObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_UpdateObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_WinfoObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	Tk_WmObjCmd(ClientData clientData, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);

MODULE_SCOPE int	Tk_GetDoublePixelsFromObj(Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Obj *objPtr,
			    double *doublePtr);
MODULE_SCOPE int	TkSetGeometryContainer(Tcl_Interp *interp,
			    Tk_Window tkwin, const char *name);
MODULE_SCOPE void	TkFreeGeometryContainer(Tk_Window tkwin,
			    const char *name);
MODULE_SCOPE int	TkSetGeometryMaster(Tcl_Interp *interp,
			    Tk_Window tkwin, const char *master);
MODULE_SCOPE void	TkFreeGeometryMaster(Tk_Window tkwin,
			    const char *master);

MODULE_SCOPE void	TkEventInit(void);
MODULE_SCOPE void	TkRegisterObjTypes(void);
MODULE_SCOPE Tcl_ObjCmdProc TkDeadAppObjCmd;
MODULE_SCOPE int	TkDeadAppObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc, Tcl_Obj *const argv[]);
MODULE_SCOPE int	TkCanvasGetCoordObj(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tcl_Obj *obj,
			    double *doublePtr);
MODULE_SCOPE int	TkGetDoublePixels(Tcl_Interp *interp, Tk_Window tkwin,
			    const char *string, double *doublePtr);
MODULE_SCOPE int	TkPostscriptImage(Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_PostscriptInfo psInfo, XImage *ximage,
			    int x, int y, int width, int height);
MODULE_SCOPE void       TkMapTopFrame(Tk_Window tkwin);
MODULE_SCOPE XEvent *	TkpGetBindingXEvent(Tcl_Interp *interp);
MODULE_SCOPE void	TkCreateExitHandler(Tcl_ExitProc *proc,
			    void *clientData);
			    ClientData clientData);
MODULE_SCOPE void	TkDeleteExitHandler(Tcl_ExitProc *proc,
			    void *clientData);
			    ClientData clientData);
MODULE_SCOPE Tcl_ExitProc	TkFinalize;
MODULE_SCOPE Tcl_ExitProc	TkFinalizeThread;
MODULE_SCOPE void	TkpBuildRegionFromAlphaData(Region region,
MODULE_SCOPE void	TkpBuildRegionFromAlphaData(TkRegion region,
			    unsigned x, unsigned y, unsigned width,
			    unsigned height, unsigned char *dataPtr,
			    unsigned pixelStride, unsigned lineStride);
MODULE_SCOPE void	TkAppendPadAmount(Tcl_Obj *bufferObj,
			    const char *buffer, int pad1, int pad2);
MODULE_SCOPE int	TkParsePadAmount(Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Obj *objPtr,
			    int *pad1Ptr, int *pad2Ptr);
MODULE_SCOPE void       TkFocusSplit(TkWindow *winPtr);
MODULE_SCOPE void       TkFocusJoin(TkWindow *winPtr);
MODULE_SCOPE int	TkpAlwaysShowSelection(Tk_Window tkwin);
MODULE_SCOPE void	TkpDrawCharsInContext(Display * display,
			    Drawable drawable, GC gc, Tk_Font tkfont,
			    const char *source, Tcl_Size numBytes, Tcl_Size rangeStart,
			    Tcl_Size rangeLength, int x, int y);
			    const char *source, int numBytes, int rangeStart,
			    int rangeLength, int x, int y);
MODULE_SCOPE void	TkpDrawAngledCharsInContext(Display * display,
			    Drawable drawable, GC gc, Tk_Font tkfont,
			    const char *source, Tcl_Size numBytes, Tcl_Size rangeStart,
			    Tcl_Size rangeLength, double x, double y, double angle);
MODULE_SCOPE int	TkpMeasureCharsInContext(Tk_Font tkfont,
			    const char *source, Tcl_Size numBytes, Tcl_Size rangeStart,
			    Tcl_Size rangeLength, int maxLength, int flags,
			    const char *source, int numBytes, int rangeStart,
			    int rangeLength, int maxLength, int flags,
			    int *lengthPtr);
MODULE_SCOPE void	TkUnderlineCharsInContext(Display *display,
			    Drawable drawable, GC gc, Tk_Font tkfont,
			    const char *string, Tcl_Size numBytes, int x, int y,
			    Tcl_Size firstByte, Tcl_Size lastByte);
			    const char *string, int numBytes, int x, int y,
			    int firstByte, int lastByte);
MODULE_SCOPE void	TkpGetFontAttrsForChar(Tk_Window tkwin, Tk_Font tkfont,
			    int c, struct TkFontAttributes *faPtr);
MODULE_SCOPE void	TkpDrawFrameEx(Tk_Window tkwin, Drawable drawable,
MODULE_SCOPE Tcl_Obj *	TkNewWindowObj(Tk_Window tkwin);
			    Tk_3DBorder border, int highlightWidth,
			    int borderWidth, int relief);
MODULE_SCOPE void	TkpShowBusyWindow(TkBusy busy);
MODULE_SCOPE void	TkpHideBusyWindow(TkBusy busy);
MODULE_SCOPE void	TkpMakeTransparentWindowExist(Tk_Window tkwin,
			    Window parent);
MODULE_SCOPE void	TkpCreateBusy(Tk_FakeWin *winPtr, Tk_Window tkRef,
			    Window *parentPtr, Tk_Window tkParent,
			    TkBusy busy);
MODULE_SCOPE int	TkBackgroundEvalObjv(Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const *objv, int flags);
			    int objc, Tcl_Obj *const *objv, int flags);
MODULE_SCOPE void	TkSendVirtualEvent(Tk_Window tgtWin,
			    const char *eventName, Tcl_Obj *detail);
MODULE_SCOPE Tcl_Command TkMakeEnsemble(Tcl_Interp *interp,
			    const char *nsname, const char *name,
			    void *clientData, const TkEnsemble *map);
			    ClientData clientData, const TkEnsemble *map);
MODULE_SCOPE double	TkScalingLevel(Tk_Window tkwin);
MODULE_SCOPE int	TkInitTkCmd(Tcl_Interp *interp,
			    void *clientData);
			    ClientData clientData);
MODULE_SCOPE int	TkInitFontchooser(Tcl_Interp *interp,
			    void *clientData);
			    ClientData clientData);
MODULE_SCOPE void	TkInitEmbeddedConfigurationInformation(
			    Tcl_Interp *interp);
MODULE_SCOPE void	TkDoWarpWrtWin(TkDisplay *dispPtr);
MODULE_SCOPE void	TkpWarpPointer(TkDisplay *dispPtr);
MODULE_SCOPE void	TkRotatePoint(double originX, double originY,
MODULE_SCOPE void	TkpCancelWarp(TkDisplay *dispPtr);
			    double sine, double cosine, double *xPtr,
			    double *yPtr);
MODULE_SCOPE int TkGetIntForIndex(Tcl_Obj *, Tcl_Size, int lastOK, Tcl_Size*);

MODULE_SCOPE int	TkListCreateFrame(ClientData clientData,
			    Tcl_Interp *interp, Tcl_Obj *listObj,
#define TkNewIndexObj(value) (((Tcl_Size)(value) == TCL_INDEX_NONE) ? Tcl_NewObj() : Tcl_NewWideIntObj((Tcl_WideInt)(value)))
#define TK_OPTION_UNDERLINE_DEF(type, field) NULL, TCL_INDEX_NONE, offsetof(type, field), TK_OPTION_NULL_OK, NULL

			    int toplevel, Tcl_Obj *nameObj);

#ifdef _WIN32
#define TkParseColor XParseColor
#else
MODULE_SCOPE Status TkParseColor (Display * display,
				Colormap map, const char* spec,
				XColor * colorPtr);
#endif
#if !defined(_WIN32) && !defined(__CYGWIN__) /* UNIX and MacOSX */
#undef TkPutImage
#define TkPutImage(colors, ncolors, display, pixels, gc, image, srcx, srcy, destx, desty, width, height) \
	XPutImage(display, pixels, gc, image, srcx, srcy, destx, desty, width, height);
#else
#undef XPutImage
#define XPutImage(display, pixels, gc, image, srcx, srcy, destx, desty, width, height) \
	TkPutImage(NULL, 0, display, pixels, gc, image, srcx, srcy, destx, desty, width, height);
#endif

/*
 * These macros are just wrappers for the equivalent X Region calls.
 */
#define TkClipBox XClipBox
#define TkCreateRegion XCreateRegion
#define TkDestroyRegion XDestroyRegion
#define TkIntersectRegion XIntersectRegion
#define TkRectInRegion XRectInRegion
#define TkSetRegion XSetRegion
#define TkSubtractRegion XSubtractRegion
#define TkUnionRectWithRegion XUnionRectWithRegion

#ifdef HAVE_XFT
MODULE_SCOPE void	TkUnixSetXftClipRegion(Region clipRegion);
MODULE_SCOPE void	TkUnixSetXftClipRegion(TkRegion clipRegion);
#endif

MODULE_SCOPE void	TkpCopyRegion(TkRegion dst, TkRegion src);

#if !defined(__cplusplus) && !defined(c_plusplus)
# define c_class class
#endif

#if TCL_UTF_MAX > 4
#   define TkUtfToUniChar Tcl_UtfToUniChar
#   define TkUniCharToUtf Tcl_UniCharToUtf
#else
    MODULE_SCOPE int TkUtfToUniChar(const char *, int *);
#if defined(_WIN32) && !defined(STATIC_BUILD) && TCL_MAJOR_VERSION < 9
#   define tcl_CreateFileHandler reserved9
    MODULE_SCOPE int TkUniCharToUtf(int, char *);
#endif

MODULE_SCOPE  void       Icu_Init(Tcl_Interp* interp);

/*
 * Unsupported commands.
 */

MODULE_SCOPE Tcl_ObjCmdProc TkUnsupported1ObjCmd;
MODULE_SCOPE int	TkUnsupported1ObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);

/*
 * For Tktest.
 */
MODULE_SCOPE Tcl_ObjCmdProc SquareObjCmd;
MODULE_SCOPE int SquareObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
MODULE_SCOPE int	TkOldTestInit(Tcl_Interp *interp);
#if !(defined(_WIN32) || defined(MAC_OSX_TK))
#define TkplatformtestInit(x) TCL_OK
#else
MODULE_SCOPE int	TkplatformtestInit(Tcl_Interp *interp);
#endif

#ifdef __cplusplus
}
#endif

#endif /* _TKINT */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkIntDecls.h.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17


18
19
20
21
22
23
24








-
+








-
-







/*
 * tkIntDecls.h --
 *
 *	This file contains the declarations for all unsupported
 *	functions that are exported by the Tk library.  These
 *	interfaces are not guaranteed to remain the same between
 *	versions.  Use at your own risk.
 *
 * Copyright (c) 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKINTDECLS
#define _TKINTDECLS

#include "X11/Xutil.h"

#ifdef BUILD_tk
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT
#endif

struct TkText;
typedef struct TkTextBTree_ *TkTextBTree;
75
76
77
78
79
80
81
82
83
84




85
86
87
88
89
90
91
73
74
75
76
77
78
79



80
81
82
83
84
85
86
87
88
89
90







-
-
-
+
+
+
+







/* Slot 11 is reserved */
/* 12 */
EXTERN TkCursor *	TkCreateCursorFromData(Tk_Window tkwin,
				const char *source, const char *mask,
				int width, int height, int xHot, int yHot,
				XColor fg, XColor bg);
/* 13 */
EXTERN int		TkCreateFrame(void *clientData, Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[],
				int type, const char *appName);
EXTERN int		TkCreateFrame(ClientData clientData,
				Tcl_Interp *interp, int argc,
				const char *const *argv, int toplevel,
				const char *appName);
/* 14 */
EXTERN Tk_Window	TkCreateMainWindow(Tcl_Interp *interp,
				const char *screenName, const char *baseName);
/* 15 */
EXTERN Time		TkCurrentTime(TkDisplay *dispPtr);
/* 16 */
EXTERN void		TkDeleteAllImages(TkMainInfo *mainPtr);
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114







-
+







				int numPoints, Display *display,
				Drawable drawable, GC gc, GC outlineGC);
/* 21 */
EXTERN int		TkFindStateNum(Tcl_Interp *interp,
				const char *option, const TkStateMap *mapPtr,
				const char *strKey);
/* 22 */
EXTERN const char *	TkFindStateString(const TkStateMap *mapPtr,
EXTERN CONST86 char *	TkFindStateString(const TkStateMap *mapPtr,
				int numKey);
/* 23 */
EXTERN void		TkFocusDeadWindow(TkWindow *winPtr);
/* 24 */
EXTERN int		TkFocusFilterEvent(TkWindow *winPtr,
				XEvent *eventPtr);
/* 25 */
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149







-
+







				Tk_Window tkwin, Tk_Uid string);
/* 33 */
EXTERN const char *	TkGetDefaultScreenName(Tcl_Interp *interp,
				const char *screenName);
/* 34 */
EXTERN TkDisplay *	TkGetDisplay(Display *display);
/* 35 */
EXTERN Tcl_Size		TkGetDisplayOf(Tcl_Interp *interp, Tcl_Size objc,
EXTERN int		TkGetDisplayOf(Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[], Tk_Window *tkwinPtr);
/* 36 */
EXTERN TkWindow *	TkGetFocusWin(TkWindow *winPtr);
/* 37 */
EXTERN int		TkGetInterpNames(Tcl_Interp *interp, Tk_Window tkwin);
/* 38 */
EXTERN int		TkGetMiterPoints(double p1[], double p2[],
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177







-
+







/* 44 */
EXTERN void		TkInOutEvents(XEvent *eventPtr, TkWindow *sourcePtr,
				TkWindow *destPtr, int leaveType,
				int enterType, Tcl_QueuePosition position);
/* 45 */
EXTERN void		TkInstallFrameMenu(Tk_Window tkwin);
/* 46 */
EXTERN const char *	TkKeysymToString(KeySym keysym);
EXTERN CONST86 char *	TkKeysymToString(KeySym keysym);
/* 47 */
EXTERN int		TkLineToArea(double end1Ptr[], double end2Ptr[],
				double rectPtr[]);
/* 48 */
EXTERN double		TkLineToPoint(double end1Ptr[], double end2Ptr[],
				double pointPtr[]);
/* 49 */
198
199
200
201
202
203
204
205


206
207
208
209
210
211
212
213


214
215
216


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236






237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261




262
263
264
265
266
267
268
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212

213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277







-
+
+







-
+
+


-
+
+


















-
-
+
+
+
+
+
+














-
+









-
+
+
+
+







EXTERN void		TkpCloseDisplay(TkDisplay *dispPtr);
/* 57 */
EXTERN void		TkpClaimFocus(TkWindow *topLevelPtr, int force);
/* 58 */
EXTERN void		TkpDisplayWarning(const char *msg, const char *title);
/* 59 */
EXTERN void		TkpGetAppName(Tcl_Interp *interp, Tcl_DString *name);
/* Slot 60 is reserved */
/* 60 */
EXTERN TkWindow *	TkpGetOtherWindow(TkWindow *winPtr);
/* 61 */
EXTERN TkWindow *	TkpGetWrapperWindow(TkWindow *winPtr);
/* 62 */
EXTERN int		TkpInit(Tcl_Interp *interp);
/* 63 */
EXTERN void		TkpInitializeMenuBindings(Tcl_Interp *interp,
				Tk_BindingTable bindingTable);
/* Slot 64 is reserved */
/* 64 */
EXTERN void		TkpMakeContainer(Tk_Window tkwin);
/* 65 */
EXTERN void		TkpMakeMenuWindow(Tk_Window tkwin, int transient);
/* Slot 66 is reserved */
/* 66 */
EXTERN Window		TkpMakeWindow(TkWindow *winPtr, Window parent);
/* 67 */
EXTERN void		TkpMenuNotifyToplevelCreate(Tcl_Interp *interp,
				const char *menuName);
/* 68 */
EXTERN TkDisplay *	TkpOpenDisplay(const char *display_name);
/* 69 */
EXTERN int		TkPointerEvent(XEvent *eventPtr, TkWindow *winPtr);
/* 70 */
EXTERN int		TkPolygonToArea(double *polyPtr, int numPoints,
				double *rectPtr);
/* 71 */
EXTERN double		TkPolygonToPoint(double *polyPtr, int numPoints,
				double *pointPtr);
/* 72 */
EXTERN int		TkPositionInTree(TkWindow *winPtr, TkWindow *treePtr);
/* 73 */
EXTERN void		TkpRedirectKeyEvent(TkWindow *winPtr,
				XEvent *eventPtr);
/* Slot 74 is reserved */
/* Slot 75 is reserved */
/* 74 */
EXTERN void		TkpSetMainMenubar(Tcl_Interp *interp,
				Tk_Window tkwin, const char *menuName);
/* 75 */
EXTERN int		TkpUseWindow(Tcl_Interp *interp, Tk_Window tkwin,
				const char *string);
/* Slot 76 is reserved */
/* 77 */
EXTERN void		TkQueueEventForAllChildren(TkWindow *winPtr,
				XEvent *eventPtr);
/* 78 */
EXTERN int		TkReadBitmapFile(Display *display, Drawable d,
				const char *filename,
				unsigned int *width_return,
				unsigned int *height_return,
				Pixmap *bitmap_return, int *x_hot_return,
				int *y_hot_return);
/* 79 */
EXTERN int		TkScrollWindow(Tk_Window tkwin, GC gc, int x, int y,
				int width, int height, int dx, int dy,
				Region damageRgn);
				TkRegion damageRgn);
/* 80 */
EXTERN void		TkSelDeadWindow(TkWindow *winPtr);
/* 81 */
EXTERN void		TkSelEventProc(Tk_Window tkwin, XEvent *eventPtr);
/* 82 */
EXTERN void		TkSelInit(Tk_Window tkwin);
/* 83 */
EXTERN void		TkSelPropProc(XEvent *eventPtr);
/* Slot 84 is reserved */
/* Slot 85 is reserved */
/* 85 */
EXTERN void		TkSetWindowMenuBar(Tcl_Interp *interp,
				Tk_Window tkwin, const char *oldMenuName,
				const char *menuName);
/* 86 */
EXTERN KeySym		TkStringToKeysym(const char *name);
/* 87 */
EXTERN int		TkThickPolyLineToArea(double *coordPtr,
				int numPoints, double width, int capStyle,
				int joinStyle, double *rectPtr);
/* 88 */
311
312
313
314
315
316
317
318

319
320
321
322



323
324
325
326

327
328

329
330

331
332
333


334
335

336
337
338

339
340
341


342

343
344
345


346
347

348

349
350
351

352
353
354
355
356
357
358
359
360
361
362




363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
384


385
386
387
388
389
390
391
320
321
322
323
324
325
326

327
328
329
330

331
332
333
334
335
336

337
338

339
340

341
342


343
344
345

346
347
348

349
350


351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402


403
404
405
406
407
408
409
410
411







-
+



-
+
+
+



-
+

-
+

-
+

-
-
+
+

-
+


-
+

-
-
+
+

+



+
+


+

+



+










-
+
+
+
+










-
+









-
-
+
+







/* 107 */
EXTERN TkMainInfo *	TkGetMainInfoList(void);
/* 108 */
EXTERN int		TkGetWindowFromObj(Tcl_Interp *interp,
				Tk_Window tkwin, Tcl_Obj *objPtr,
				Tk_Window *windowPtr);
/* 109 */
EXTERN const char *	TkpGetString(TkWindow *winPtr, XEvent *eventPtr,
EXTERN CONST86 char *	TkpGetString(TkWindow *winPtr, XEvent *eventPtr,
				Tcl_DString *dsPtr);
/* 110 */
EXTERN void		TkpGetSubFonts(Tcl_Interp *interp, Tk_Font tkfont);
/* Slot 111 is reserved */
/* 111 */
EXTERN Tcl_Obj *	TkpGetSystemDefault(Tk_Window tkwin,
				const char *dbName, const char *className);
/* 112 */
EXTERN void		TkpMenuThreadInit(void);
/* 113 */
EXTERN int		XClipBox(Region rgn, XRectangle *rect_return);
EXTERN void		TkClipBox(TkRegion rgn, XRectangle *rect_return);
/* 114 */
EXTERN Region		XCreateRegion(void);
EXTERN TkRegion		TkCreateRegion(void);
/* 115 */
EXTERN int		XDestroyRegion(Region rgn);
EXTERN void		TkDestroyRegion(TkRegion rgn);
/* 116 */
EXTERN int		XIntersectRegion(Region sra, Region srcb,
				Region dr_return);
EXTERN void		TkIntersectRegion(TkRegion sra, TkRegion srcb,
				TkRegion dr_return);
/* 117 */
EXTERN int		XRectInRegion(Region rgn, int x, int y,
EXTERN int		TkRectInRegion(TkRegion rgn, int x, int y,
				unsigned int width, unsigned int height);
/* 118 */
EXTERN int		XSetRegion(Display *display, GC gc, Region rgn);
EXTERN void		TkSetRegion(Display *display, GC gc, TkRegion rgn);
/* 119 */
EXTERN int		XUnionRectWithRegion(XRectangle *rect, Region src,
				Region dr_return);
EXTERN void		TkUnionRectWithRegion(XRectangle *rect, TkRegion src,
				TkRegion dr_return);
/* Slot 120 is reserved */
#ifdef MAC_OSX_TK /* AQUA */
/* 121 */
EXTERN Pixmap		TkpCreateNativeBitmap(Display *display,
				const void *source);
#endif /* AQUA */
#ifdef MAC_OSX_TK /* AQUA */
/* 122 */
EXTERN void		TkpDefineNativeBitmaps(void);
#endif /* AQUA */
/* Slot 123 is reserved */
#ifdef MAC_OSX_TK /* AQUA */
/* 124 */
EXTERN Pixmap		TkpGetNativeAppBitmap(Display *display,
				const char *name, int *width, int *height);
#endif /* AQUA */
/* Slot 125 is reserved */
/* Slot 126 is reserved */
/* Slot 127 is reserved */
/* Slot 128 is reserved */
/* Slot 129 is reserved */
/* Slot 130 is reserved */
/* Slot 131 is reserved */
/* Slot 132 is reserved */
/* Slot 133 is reserved */
/* Slot 134 is reserved */
/* Slot 135 is reserved */
/* 135 */
EXTERN void		TkpDrawHighlightBorder(Tk_Window tkwin, GC fgGC,
				GC bgGC, int highlightWidth,
				Drawable drawable);
/* 136 */
EXTERN void		TkSetFocusWin(TkWindow *winPtr, int force);
/* 137 */
EXTERN void		TkpSetKeycodeAndState(Tk_Window tkwin, KeySym keySym,
				XEvent *eventPtr);
/* 138 */
EXTERN KeySym		TkpGetKeySym(TkDisplay *dispPtr, XEvent *eventPtr);
/* 139 */
EXTERN void		TkpInitKeymapInfo(TkDisplay *dispPtr);
/* 140 */
EXTERN Region		TkPhotoGetValidRegion(Tk_PhotoHandle handle);
EXTERN TkRegion		TkPhotoGetValidRegion(Tk_PhotoHandle handle);
/* 141 */
EXTERN TkWindow **	TkWmStackorderToplevel(TkWindow *parentPtr);
/* 142 */
EXTERN void		TkFocusFree(TkMainInfo *mainPtr);
/* 143 */
EXTERN void		TkClipCleanup(TkDisplay *dispPtr);
/* 144 */
EXTERN void		TkGCCleanup(TkDisplay *dispPtr);
/* 145 */
EXTERN int		XSubtractRegion(Region sra, Region srcb,
				Region dr_return);
EXTERN void		TkSubtractRegion(TkRegion sra, TkRegion srcb,
				TkRegion dr_return);
/* 146 */
EXTERN void		TkStylePkgInit(TkMainInfo *mainPtr);
/* 147 */
EXTERN void		TkStylePkgFree(TkMainInfo *mainPtr);
/* 148 */
EXTERN Tk_Window	TkToplevelWindowForCommand(Tcl_Interp *interp,
				const char *cmdName);
402
403
404
405
406
407
408
409

410
411
412

413
414
415
416



417
418
419


420
421
422
423

424
425
426
427
428
429
430
431


432
433
434
435


436
437
438
439
440

441
442

443
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

468
469

470
471
472
473


474
475
476

477
478

479
480
481
482
483



484
485

486
487

488
489
490
491


492
493
494

495
496

497
498
499
500


501
502
503

504
505

506
507
508
509


510
511
512

513
514

515
516
517
518


519
520
521
522
523
524

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539


540
541
542
543
544
545
546
547
548
549
550
551
422
423
424
425
426
427
428

429
430
431

432
433
434


435
436
437
438


439
440
441
442
443

444
445
446
447
448
449
450


451
452
453
454


455
456
457
458
459


460
461

462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488

489

490


491
492
493
494

495
496

497

498



499
500
501
502

503
504

505

506


507
508
509
510

511
512

513

514


515
516
517
518

519
520

521

522


523
524
525
526

527
528

529

530


531
532
533
534
535
536
537

538

539
540
541
542
543
544
545
546
547
548
549
550


551
552
553




554
555
556
557
558
559
560







-
+


-
+


-
-
+
+
+

-
-
+
+



-
+






-
-
+
+


-
-
+
+



-
-
+

-
+








-
+















-
+

-
+
-

-
-
+
+


-
+

-
+
-

-
-
-
+
+
+

-
+

-
+
-

-
-
+
+


-
+

-
+
-

-
-
+
+


-
+

-
+
-

-
-
+
+


-
+

-
+
-

-
-
+
+





-
+
-












-
-
+
+

-
-
-
-







				int numPoints);
/* 152 */
EXTERN void		TkpDrawFrame(Tk_Window tkwin, Tk_3DBorder border,
				int highlightWidth, int borderWidth,
				int relief);
/* 153 */
EXTERN void		TkCreateThreadExitHandler(Tcl_ExitProc *proc,
				void *clientData);
				ClientData clientData);
/* 154 */
EXTERN void		TkDeleteThreadExitHandler(Tcl_ExitProc *proc,
				void *clientData);
				ClientData clientData);
/* Slot 155 is reserved */
/* 156 */
EXTERN int		TkpTestembedCmd(void *clientData, Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[]);
EXTERN int		TkpTestembedCmd(ClientData clientData,
				Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[]);
/* 157 */
EXTERN int		TkpTesttextCmd(void *dummy, Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[]);
EXTERN int		TkpTesttextCmd(ClientData dummy, Tcl_Interp *interp,
				int objc, Tcl_Obj *const objv[]);
/* 158 */
EXTERN int		TkSelGetSelection(Tcl_Interp *interp,
				Tk_Window tkwin, Atom selection, Atom target,
				Tk_GetSelProc *proc, void *clientData);
				Tk_GetSelProc *proc, ClientData clientData);
/* 159 */
EXTERN int		TkTextGetIndex(Tcl_Interp *interp,
				struct TkText *textPtr, const char *string,
				struct TkTextIndex *indexPtr);
/* 160 */
EXTERN int		TkTextIndexBackBytes(const struct TkText *textPtr,
				const struct TkTextIndex *srcPtr,
				Tcl_Size count, struct TkTextIndex *dstPtr);
				const struct TkTextIndex *srcPtr, int count,
				struct TkTextIndex *dstPtr);
/* 161 */
EXTERN int		TkTextIndexForwBytes(const struct TkText *textPtr,
				const struct TkTextIndex *srcPtr,
				Tcl_Size count, struct TkTextIndex *dstPtr);
				const struct TkTextIndex *srcPtr, int count,
				struct TkTextIndex *dstPtr);
/* 162 */
EXTERN struct TkTextIndex * TkTextMakeByteIndex(TkTextBTree tree,
				const struct TkText *textPtr, int lineIndex,
				Tcl_Size byteIndex,
				struct TkTextIndex *indexPtr);
				int byteIndex, struct TkTextIndex *indexPtr);
/* 163 */
EXTERN Tcl_Size		TkTextPrintIndex(const struct TkText *textPtr,
EXTERN int		TkTextPrintIndex(const struct TkText *textPtr,
				const struct TkTextIndex *indexPtr,
				char *string);
/* 164 */
EXTERN struct TkTextSegment * TkTextSetMark(struct TkText *textPtr,
				const char *name,
				struct TkTextIndex *indexPtr);
/* 165 */
EXTERN int		TkTextXviewCmd(struct TkText *textPtr,
				Tcl_Interp *interp, Tcl_Size objc,
				Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[]);
/* 166 */
EXTERN void		TkTextChanged(struct TkSharedText *sharedTextPtr,
				struct TkText *textPtr,
				const struct TkTextIndex *index1Ptr,
				const struct TkTextIndex *index2Ptr);
/* 167 */
EXTERN int		TkBTreeNumLines(TkTextBTree tree,
				const struct TkText *textPtr);
/* 168 */
EXTERN void		TkTextInsertDisplayProc(struct TkText *textPtr,
				struct TkTextDispChunk *chunkPtr, int x,
				int y, int height, int baseline,
				Display *display, Drawable dst, int screenY);
/* 169 */
EXTERN int		TkStateParseProc(void *clientData,
EXTERN int		TkStateParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 170 */
EXTERN const char *	TkStatePrintProc(void *clientData, Tk_Window tkwin,
				char *widgRec, Tcl_Size offset,
EXTERN CONST86 char *	TkStatePrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 171 */
EXTERN int		TkCanvasDashParseProc(void *clientData,
EXTERN int		TkCanvasDashParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 172 */
EXTERN const char *	TkCanvasDashPrintProc(void *clientData,
				Tk_Window tkwin, char *widgRec,
				Tcl_Size offset, Tcl_FreeProc **freeProcPtr);
EXTERN CONST86 char *	TkCanvasDashPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 173 */
EXTERN int		TkOffsetParseProc(void *clientData,
EXTERN int		TkOffsetParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 174 */
EXTERN const char *	TkOffsetPrintProc(void *clientData, Tk_Window tkwin,
				char *widgRec, Tcl_Size offset,
EXTERN CONST86 char *	TkOffsetPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 175 */
EXTERN int		TkPixelParseProc(void *clientData,
EXTERN int		TkPixelParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 176 */
EXTERN const char *	TkPixelPrintProc(void *clientData, Tk_Window tkwin,
				char *widgRec, Tcl_Size offset,
EXTERN CONST86 char *	TkPixelPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 177 */
EXTERN int		TkOrientParseProc(void *clientData,
EXTERN int		TkOrientParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 178 */
EXTERN const char *	TkOrientPrintProc(void *clientData, Tk_Window tkwin,
				char *widgRec, Tcl_Size offset,
EXTERN CONST86 char *	TkOrientPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 179 */
EXTERN int		TkSmoothParseProc(void *clientData,
EXTERN int		TkSmoothParseProc(ClientData clientData,
				Tcl_Interp *interp, Tk_Window tkwin,
				const char *value, char *widgRec,
				const char *value, char *widgRec, int offset);
				Tcl_Size offset);
/* 180 */
EXTERN const char *	TkSmoothPrintProc(void *clientData, Tk_Window tkwin,
				char *widgRec, Tcl_Size offset,
EXTERN CONST86 char *	TkSmoothPrintProc(ClientData clientData,
				Tk_Window tkwin, char *widgRec, int offset,
				Tcl_FreeProc **freeProcPtr);
/* 181 */
EXTERN void		TkDrawAngledTextLayout(Display *display,
				Drawable drawable, GC gc,
				Tk_TextLayout layout, int x, int y,
				double angle, Tcl_Size firstChar,
				double angle, int firstChar, int lastChar);
				Tcl_Size lastChar);
/* 182 */
EXTERN void		TkUnderlineAngledTextLayout(Display *display,
				Drawable drawable, GC gc,
				Tk_TextLayout layout, int x, int y,
				double angle, int underline);
/* 183 */
EXTERN int		TkIntersectAngledTextLayout(Tk_TextLayout layout,
				int x, int y, int width, int height,
				double angle);
/* 184 */
EXTERN void		TkDrawAngledChars(Display *display,
				Drawable drawable, GC gc, Tk_Font tkfont,
				const char *source, Tcl_Size numBytes,
				double x, double y, double angle);
				const char *source, int numBytes, double x,
				double y, double angle);
/* 185 */
EXTERN void		TkpRedrawWidget(Tk_Window tkwin);
/* 186 */
EXTERN int		TkpWillDrawWidget(Tk_Window tkwin);
/* 187 */
EXTERN int		TkDebugPhotoStringMatchDef(Tcl_Interp *inter,
				Tcl_Obj *data, Tcl_Obj *formatString,
				int *widthPtr, int *heightPtr);

typedef struct TkIntStubs {
    int magic;
    void *hooks;
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613

614
615
616
617

618
619

620
621
622
623
624
625
626
627
628


629
630
631
632

633
634
635
636
637
638

639
640
641
642
643
644
645
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618
619
620
621

622
623
624
625

626
627

628
629
630
631
632
633
634
635


636
637
638
639
640

641
642
643
644
645
646

647
648
649
650
651
652
653
654







-
+








-
+












-
+










-
+













-
+



-
+

-
+







-
-
+
+



-
+





-
+







    void (*tkBindInit) (TkMainInfo *mainPtr); /* 6 */
    void (*tkChangeEventWindow) (XEvent *eventPtr, TkWindow *winPtr); /* 7 */
    int (*tkClipInit) (Tcl_Interp *interp, TkDisplay *dispPtr); /* 8 */
    void (*tkComputeAnchor) (Tk_Anchor anchor, Tk_Window tkwin, int padX, int padY, int innerWidth, int innerHeight, int *xPtr, int *yPtr); /* 9 */
    void (*reserved10)(void);
    void (*reserved11)(void);
    TkCursor * (*tkCreateCursorFromData) (Tk_Window tkwin, const char *source, const char *mask, int width, int height, int xHot, int yHot, XColor fg, XColor bg); /* 12 */
    int (*tkCreateFrame) (void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], int type, const char *appName); /* 13 */
    int (*tkCreateFrame) (ClientData clientData, Tcl_Interp *interp, int argc, const char *const *argv, int toplevel, const char *appName); /* 13 */
    Tk_Window (*tkCreateMainWindow) (Tcl_Interp *interp, const char *screenName, const char *baseName); /* 14 */
    Time (*tkCurrentTime) (TkDisplay *dispPtr); /* 15 */
    void (*tkDeleteAllImages) (TkMainInfo *mainPtr); /* 16 */
    void (*tkDoConfigureNotify) (TkWindow *winPtr); /* 17 */
    void (*tkDrawInsetFocusHighlight) (Tk_Window tkwin, GC gc, int width, Drawable drawable, int padding); /* 18 */
    void (*tkEventDeadWindow) (TkWindow *winPtr); /* 19 */
    void (*tkFillPolygon) (Tk_Canvas canvas, double *coordPtr, int numPoints, Display *display, Drawable drawable, GC gc, GC outlineGC); /* 20 */
    int (*tkFindStateNum) (Tcl_Interp *interp, const char *option, const TkStateMap *mapPtr, const char *strKey); /* 21 */
    const char * (*tkFindStateString) (const TkStateMap *mapPtr, int numKey); /* 22 */
    CONST86 char * (*tkFindStateString) (const TkStateMap *mapPtr, int numKey); /* 22 */
    void (*tkFocusDeadWindow) (TkWindow *winPtr); /* 23 */
    int (*tkFocusFilterEvent) (TkWindow *winPtr, XEvent *eventPtr); /* 24 */
    TkWindow * (*tkFocusKeyEvent) (TkWindow *winPtr, XEvent *eventPtr); /* 25 */
    void (*tkFontPkgInit) (TkMainInfo *mainPtr); /* 26 */
    void (*tkFontPkgFree) (TkMainInfo *mainPtr); /* 27 */
    void (*tkFreeBindingTags) (TkWindow *winPtr); /* 28 */
    void (*tkpFreeCursor) (TkCursor *cursorPtr); /* 29 */
    char * (*tkGetBitmapData) (Tcl_Interp *interp, const char *string, const char *fileName, int *widthPtr, int *heightPtr, int *hotXPtr, int *hotYPtr); /* 30 */
    void (*tkGetButtPoints) (double p1[], double p2[], double width, int project, double m1[], double m2[]); /* 31 */
    TkCursor * (*tkGetCursorByName) (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid string); /* 32 */
    const char * (*tkGetDefaultScreenName) (Tcl_Interp *interp, const char *screenName); /* 33 */
    TkDisplay * (*tkGetDisplay) (Display *display); /* 34 */
    Tcl_Size (*tkGetDisplayOf) (Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], Tk_Window *tkwinPtr); /* 35 */
    int (*tkGetDisplayOf) (Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], Tk_Window *tkwinPtr); /* 35 */
    TkWindow * (*tkGetFocusWin) (TkWindow *winPtr); /* 36 */
    int (*tkGetInterpNames) (Tcl_Interp *interp, Tk_Window tkwin); /* 37 */
    int (*tkGetMiterPoints) (double p1[], double p2[], double p3[], double width, double m1[], double m2[]); /* 38 */
    void (*tkGetPointerCoords) (Tk_Window tkwin, int *xPtr, int *yPtr); /* 39 */
    void (*tkGetServerInfo) (Tcl_Interp *interp, Tk_Window tkwin); /* 40 */
    void (*tkGrabDeadWindow) (TkWindow *winPtr); /* 41 */
    int (*tkGrabState) (TkWindow *winPtr); /* 42 */
    void (*tkIncludePoint) (Tk_Item *itemPtr, double *pointPtr); /* 43 */
    void (*tkInOutEvents) (XEvent *eventPtr, TkWindow *sourcePtr, TkWindow *destPtr, int leaveType, int enterType, Tcl_QueuePosition position); /* 44 */
    void (*tkInstallFrameMenu) (Tk_Window tkwin); /* 45 */
    const char * (*tkKeysymToString) (KeySym keysym); /* 46 */
    CONST86 char * (*tkKeysymToString) (KeySym keysym); /* 46 */
    int (*tkLineToArea) (double end1Ptr[], double end2Ptr[], double rectPtr[]); /* 47 */
    double (*tkLineToPoint) (double end1Ptr[], double end2Ptr[], double pointPtr[]); /* 48 */
    int (*tkMakeBezierCurve) (Tk_Canvas canvas, double *pointPtr, int numPoints, int numSteps, XPoint xPoints[], double dblPoints[]); /* 49 */
    void (*tkMakeBezierPostscript) (Tcl_Interp *interp, Tk_Canvas canvas, double *pointPtr, int numPoints); /* 50 */
    void (*tkOptionClassChanged) (TkWindow *winPtr); /* 51 */
    void (*tkOptionDeadWindow) (TkWindow *winPtr); /* 52 */
    int (*tkOvalToArea) (double *ovalPtr, double *rectPtr); /* 53 */
    double (*tkOvalToPoint) (double ovalPtr[], double width, int filled, double pointPtr[]); /* 54 */
    int (*tkpChangeFocus) (TkWindow *winPtr, int force); /* 55 */
    void (*tkpCloseDisplay) (TkDisplay *dispPtr); /* 56 */
    void (*tkpClaimFocus) (TkWindow *topLevelPtr, int force); /* 57 */
    void (*tkpDisplayWarning) (const char *msg, const char *title); /* 58 */
    void (*tkpGetAppName) (Tcl_Interp *interp, Tcl_DString *name); /* 59 */
    void (*reserved60)(void);
    TkWindow * (*tkpGetOtherWindow) (TkWindow *winPtr); /* 60 */
    TkWindow * (*tkpGetWrapperWindow) (TkWindow *winPtr); /* 61 */
    int (*tkpInit) (Tcl_Interp *interp); /* 62 */
    void (*tkpInitializeMenuBindings) (Tcl_Interp *interp, Tk_BindingTable bindingTable); /* 63 */
    void (*reserved64)(void);
    void (*tkpMakeContainer) (Tk_Window tkwin); /* 64 */
    void (*tkpMakeMenuWindow) (Tk_Window tkwin, int transient); /* 65 */
    void (*reserved66)(void);
    Window (*tkpMakeWindow) (TkWindow *winPtr, Window parent); /* 66 */
    void (*tkpMenuNotifyToplevelCreate) (Tcl_Interp *interp, const char *menuName); /* 67 */
    TkDisplay * (*tkpOpenDisplay) (const char *display_name); /* 68 */
    int (*tkPointerEvent) (XEvent *eventPtr, TkWindow *winPtr); /* 69 */
    int (*tkPolygonToArea) (double *polyPtr, int numPoints, double *rectPtr); /* 70 */
    double (*tkPolygonToPoint) (double *polyPtr, int numPoints, double *pointPtr); /* 71 */
    int (*tkPositionInTree) (TkWindow *winPtr, TkWindow *treePtr); /* 72 */
    void (*tkpRedirectKeyEvent) (TkWindow *winPtr, XEvent *eventPtr); /* 73 */
    void (*reserved74)(void);
    void (*reserved75)(void);
    void (*tkpSetMainMenubar) (Tcl_Interp *interp, Tk_Window tkwin, const char *menuName); /* 74 */
    int (*tkpUseWindow) (Tcl_Interp *interp, Tk_Window tkwin, const char *string); /* 75 */
    void (*reserved76)(void);
    void (*tkQueueEventForAllChildren) (TkWindow *winPtr, XEvent *eventPtr); /* 77 */
    int (*tkReadBitmapFile) (Display *display, Drawable d, const char *filename, unsigned int *width_return, unsigned int *height_return, Pixmap *bitmap_return, int *x_hot_return, int *y_hot_return); /* 78 */
    int (*tkScrollWindow) (Tk_Window tkwin, GC gc, int x, int y, int width, int height, int dx, int dy, Region damageRgn); /* 79 */
    int (*tkScrollWindow) (Tk_Window tkwin, GC gc, int x, int y, int width, int height, int dx, int dy, TkRegion damageRgn); /* 79 */
    void (*tkSelDeadWindow) (TkWindow *winPtr); /* 80 */
    void (*tkSelEventProc) (Tk_Window tkwin, XEvent *eventPtr); /* 81 */
    void (*tkSelInit) (Tk_Window tkwin); /* 82 */
    void (*tkSelPropProc) (XEvent *eventPtr); /* 83 */
    void (*reserved84)(void);
    void (*reserved85)(void);
    void (*tkSetWindowMenuBar) (Tcl_Interp *interp, Tk_Window tkwin, const char *oldMenuName, const char *menuName); /* 85 */
    KeySym (*tkStringToKeysym) (const char *name); /* 86 */
    int (*tkThickPolyLineToArea) (double *coordPtr, int numPoints, double width, int capStyle, int joinStyle, double *rectPtr); /* 87 */
    void (*tkWmAddToColormapWindows) (TkWindow *winPtr); /* 88 */
    void (*tkWmDeadWindow) (TkWindow *winPtr); /* 89 */
    TkWindow * (*tkWmFocusToplevel) (TkWindow *winPtr); /* 90 */
    void (*tkWmMapWindow) (TkWindow *winPtr); /* 91 */
    void (*tkWmNewWindow) (TkWindow *winPtr); /* 92 */
655
656
657
658
659
660
661
662

663
664

665
666
667
668
669
670
671
672







673








674









675

676








677

678
679
680
681
682
683
684
685
686
687
688

689
690
691
692
693

694
695
696
697
698

699
700
701
702
703
704
705
706
707


708
709
710
711



712
713
714
715
716




717
718

719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734













735
736
737

738
739
740

741
742
743
744
745
746
747
664
665
666
667
668
669
670

671
672

673
674







675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723

724
725
726
727
728

729
730
731
732
733

734
735
736
737
738
739
740
741


742
743
744



745
746
747
748




749
750
751
752
753

754
755
756
757













758
759
760
761
762
763
764
765
766
767
768
769
770
771
772

773



774
775
776
777
778
779
780
781







-
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+

+

+
+
+
+
+
+
+
+

+










-
+




-
+




-
+







-
-
+
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-
+







    Tcl_Obj * (*tkDebugConfig) (Tcl_Interp *interp, Tk_OptionTable table); /* 102 */
    Tcl_Obj * (*tkDebugFont) (Tk_Window tkwin, const char *name); /* 103 */
    int (*tkFindStateNumObj) (Tcl_Interp *interp, Tcl_Obj *optionPtr, const TkStateMap *mapPtr, Tcl_Obj *keyPtr); /* 104 */
    Tcl_HashTable * (*tkGetBitmapPredefTable) (void); /* 105 */
    TkDisplay * (*tkGetDisplayList) (void); /* 106 */
    TkMainInfo * (*tkGetMainInfoList) (void); /* 107 */
    int (*tkGetWindowFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, Tk_Window *windowPtr); /* 108 */
    const char * (*tkpGetString) (TkWindow *winPtr, XEvent *eventPtr, Tcl_DString *dsPtr); /* 109 */
    CONST86 char * (*tkpGetString) (TkWindow *winPtr, XEvent *eventPtr, Tcl_DString *dsPtr); /* 109 */
    void (*tkpGetSubFonts) (Tcl_Interp *interp, Tk_Font tkfont); /* 110 */
    void (*reserved111)(void);
    Tcl_Obj * (*tkpGetSystemDefault) (Tk_Window tkwin, const char *dbName, const char *className); /* 111 */
    void (*tkpMenuThreadInit) (void); /* 112 */
    int (*xClipBox) (Region rgn, XRectangle *rect_return); /* 113 */
    Region (*xCreateRegion) (void); /* 114 */
    int (*xDestroyRegion) (Region rgn); /* 115 */
    int (*xIntersectRegion) (Region sra, Region srcb, Region dr_return); /* 116 */
    int (*xRectInRegion) (Region rgn, int x, int y, unsigned int width, unsigned int height); /* 117 */
    int (*xSetRegion) (Display *display, GC gc, Region rgn); /* 118 */
    int (*xUnionRectWithRegion) (XRectangle *rect, Region src, Region dr_return); /* 119 */
    void (*tkClipBox) (TkRegion rgn, XRectangle *rect_return); /* 113 */
    TkRegion (*tkCreateRegion) (void); /* 114 */
    void (*tkDestroyRegion) (TkRegion rgn); /* 115 */
    void (*tkIntersectRegion) (TkRegion sra, TkRegion srcb, TkRegion dr_return); /* 116 */
    int (*tkRectInRegion) (TkRegion rgn, int x, int y, unsigned int width, unsigned int height); /* 117 */
    void (*tkSetRegion) (Display *display, GC gc, TkRegion rgn); /* 118 */
    void (*tkUnionRectWithRegion) (XRectangle *rect, TkRegion src, TkRegion dr_return); /* 119 */
    void (*reserved120)(void);
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    void (*reserved121)(void);
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    void (*reserved121)(void);
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    void (*reserved121)(void); /* Dummy entry for stubs table backwards compatibility */
    Pixmap (*tkpCreateNativeBitmap) (Display *display, const void *source); /* 121 */
#endif /* AQUA */
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    void (*reserved122)(void);
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    void (*reserved122)(void);
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    void (*reserved122)(void); /* Dummy entry for stubs table backwards compatibility */
    void (*tkpDefineNativeBitmaps) (void); /* 122 */
#endif /* AQUA */
    void (*reserved123)(void);
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    void (*reserved124)(void);
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    void (*reserved124)(void);
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    void (*reserved124)(void); /* Dummy entry for stubs table backwards compatibility */
    Pixmap (*tkpGetNativeAppBitmap) (Display *display, const char *name, int *width, int *height); /* 124 */
#endif /* AQUA */
    void (*reserved125)(void);
    void (*reserved126)(void);
    void (*reserved127)(void);
    void (*reserved128)(void);
    void (*reserved129)(void);
    void (*reserved130)(void);
    void (*reserved131)(void);
    void (*reserved132)(void);
    void (*reserved133)(void);
    void (*reserved134)(void);
    void (*reserved135)(void);
    void (*tkpDrawHighlightBorder) (Tk_Window tkwin, GC fgGC, GC bgGC, int highlightWidth, Drawable drawable); /* 135 */
    void (*tkSetFocusWin) (TkWindow *winPtr, int force); /* 136 */
    void (*tkpSetKeycodeAndState) (Tk_Window tkwin, KeySym keySym, XEvent *eventPtr); /* 137 */
    KeySym (*tkpGetKeySym) (TkDisplay *dispPtr, XEvent *eventPtr); /* 138 */
    void (*tkpInitKeymapInfo) (TkDisplay *dispPtr); /* 139 */
    Region (*tkPhotoGetValidRegion) (Tk_PhotoHandle handle); /* 140 */
    TkRegion (*tkPhotoGetValidRegion) (Tk_PhotoHandle handle); /* 140 */
    TkWindow ** (*tkWmStackorderToplevel) (TkWindow *parentPtr); /* 141 */
    void (*tkFocusFree) (TkMainInfo *mainPtr); /* 142 */
    void (*tkClipCleanup) (TkDisplay *dispPtr); /* 143 */
    void (*tkGCCleanup) (TkDisplay *dispPtr); /* 144 */
    int (*xSubtractRegion) (Region sra, Region srcb, Region dr_return); /* 145 */
    void (*tkSubtractRegion) (TkRegion sra, TkRegion srcb, TkRegion dr_return); /* 145 */
    void (*tkStylePkgInit) (TkMainInfo *mainPtr); /* 146 */
    void (*tkStylePkgFree) (TkMainInfo *mainPtr); /* 147 */
    Tk_Window (*tkToplevelWindowForCommand) (Tcl_Interp *interp, const char *cmdName); /* 148 */
    const Tk_OptionSpec * (*tkGetOptionSpec) (const char *name, Tk_OptionTable optionTable); /* 149 */
    int (*tkMakeRawCurve) (Tk_Canvas canvas, double *pointPtr, int numPoints, int numSteps, XPoint xPoints[], double dblPoints[]); /* 150 */
    void (*tkMakeRawCurvePostscript) (Tcl_Interp *interp, Tk_Canvas canvas, double *pointPtr, int numPoints); /* 151 */
    void (*tkpDrawFrame) (Tk_Window tkwin, Tk_3DBorder border, int highlightWidth, int borderWidth, int relief); /* 152 */
    void (*tkCreateThreadExitHandler) (Tcl_ExitProc *proc, void *clientData); /* 153 */
    void (*tkDeleteThreadExitHandler) (Tcl_ExitProc *proc, void *clientData); /* 154 */
    void (*tkCreateThreadExitHandler) (Tcl_ExitProc *proc, ClientData clientData); /* 153 */
    void (*tkDeleteThreadExitHandler) (Tcl_ExitProc *proc, ClientData clientData); /* 154 */
    void (*reserved155)(void);
    int (*tkpTestembedCmd) (void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 156 */
    int (*tkpTesttextCmd) (void *dummy, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 157 */
    int (*tkSelGetSelection) (Tcl_Interp *interp, Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc *proc, void *clientData); /* 158 */
    int (*tkpTestembedCmd) (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* 156 */
    int (*tkpTesttextCmd) (ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* 157 */
    int (*tkSelGetSelection) (Tcl_Interp *interp, Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc *proc, ClientData clientData); /* 158 */
    int (*tkTextGetIndex) (Tcl_Interp *interp, struct TkText *textPtr, const char *string, struct TkTextIndex *indexPtr); /* 159 */
    int (*tkTextIndexBackBytes) (const struct TkText *textPtr, const struct TkTextIndex *srcPtr, Tcl_Size count, struct TkTextIndex *dstPtr); /* 160 */
    int (*tkTextIndexForwBytes) (const struct TkText *textPtr, const struct TkTextIndex *srcPtr, Tcl_Size count, struct TkTextIndex *dstPtr); /* 161 */
    struct TkTextIndex * (*tkTextMakeByteIndex) (TkTextBTree tree, const struct TkText *textPtr, int lineIndex, Tcl_Size byteIndex, struct TkTextIndex *indexPtr); /* 162 */
    Tcl_Size (*tkTextPrintIndex) (const struct TkText *textPtr, const struct TkTextIndex *indexPtr, char *string); /* 163 */
    int (*tkTextIndexBackBytes) (const struct TkText *textPtr, const struct TkTextIndex *srcPtr, int count, struct TkTextIndex *dstPtr); /* 160 */
    int (*tkTextIndexForwBytes) (const struct TkText *textPtr, const struct TkTextIndex *srcPtr, int count, struct TkTextIndex *dstPtr); /* 161 */
    struct TkTextIndex * (*tkTextMakeByteIndex) (TkTextBTree tree, const struct TkText *textPtr, int lineIndex, int byteIndex, struct TkTextIndex *indexPtr); /* 162 */
    int (*tkTextPrintIndex) (const struct TkText *textPtr, const struct TkTextIndex *indexPtr, char *string); /* 163 */
    struct TkTextSegment * (*tkTextSetMark) (struct TkText *textPtr, const char *name, struct TkTextIndex *indexPtr); /* 164 */
    int (*tkTextXviewCmd) (struct TkText *textPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 165 */
    int (*tkTextXviewCmd) (struct TkText *textPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* 165 */
    void (*tkTextChanged) (struct TkSharedText *sharedTextPtr, struct TkText *textPtr, const struct TkTextIndex *index1Ptr, const struct TkTextIndex *index2Ptr); /* 166 */
    int (*tkBTreeNumLines) (TkTextBTree tree, const struct TkText *textPtr); /* 167 */
    void (*tkTextInsertDisplayProc) (struct TkText *textPtr, struct TkTextDispChunk *chunkPtr, int x, int y, int height, int baseline, Display *display, Drawable dst, int screenY); /* 168 */
    int (*tkStateParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 169 */
    const char * (*tkStatePrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 170 */
    int (*tkCanvasDashParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 171 */
    const char * (*tkCanvasDashPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 172 */
    int (*tkOffsetParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 173 */
    const char * (*tkOffsetPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 174 */
    int (*tkPixelParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 175 */
    const char * (*tkPixelPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 176 */
    int (*tkOrientParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 177 */
    const char * (*tkOrientPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 178 */
    int (*tkSmoothParseProc) (void *clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, Tcl_Size offset); /* 179 */
    const char * (*tkSmoothPrintProc) (void *clientData, Tk_Window tkwin, char *widgRec, Tcl_Size offset, Tcl_FreeProc **freeProcPtr); /* 180 */
    void (*tkDrawAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, Tcl_Size firstChar, Tcl_Size lastChar); /* 181 */
    int (*tkStateParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 169 */
    CONST86 char * (*tkStatePrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 170 */
    int (*tkCanvasDashParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 171 */
    CONST86 char * (*tkCanvasDashPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 172 */
    int (*tkOffsetParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 173 */
    CONST86 char * (*tkOffsetPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 174 */
    int (*tkPixelParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 175 */
    CONST86 char * (*tkPixelPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 176 */
    int (*tkOrientParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 177 */
    CONST86 char * (*tkOrientPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 178 */
    int (*tkSmoothParseProc) (ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, const char *value, char *widgRec, int offset); /* 179 */
    CONST86 char * (*tkSmoothPrintProc) (ClientData clientData, Tk_Window tkwin, char *widgRec, int offset, Tcl_FreeProc **freeProcPtr); /* 180 */
    void (*tkDrawAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int firstChar, int lastChar); /* 181 */
    void (*tkUnderlineAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int underline); /* 182 */
    int (*tkIntersectAngledTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height, double angle); /* 183 */
    void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, Tcl_Size numBytes, double x, double y, double angle); /* 184 */
    void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); /* 184 */
    void (*tkpRedrawWidget) (Tk_Window tkwin); /* 185 */
    int (*tkpWillDrawWidget) (Tk_Window tkwin); /* 186 */
    int (*tkDebugPhotoStringMatchDef) (Tcl_Interp *inter, Tcl_Obj *data, Tcl_Obj *formatString, int *widthPtr, int *heightPtr); /* 187 */
    int (*tkDebugPhotoStringMatchDef) (Tcl_Interp *inter, Tcl_Obj *data, Tcl_Obj *formatString, int *widthPtr, int *heightPtr); /* 185 */
} TkIntStubs;

extern const TkIntStubs *tkIntStubsPtr;

#ifdef __cplusplus
}
#endif
865
866
867
868
869
870
871
872


873
874
875
876
877
878
879


880
881
882


883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898




899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915


916
917
918
919
920
921
922
899
900
901
902
903
904
905

906
907
908
909
910
911
912
913

914
915
916
917

918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933


934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960
961
962







-
+
+






-
+
+


-
+
+














-
-
+
+
+
+
















-
+
+







	(tkIntStubsPtr->tkpCloseDisplay) /* 56 */
#define TkpClaimFocus \
	(tkIntStubsPtr->tkpClaimFocus) /* 57 */
#define TkpDisplayWarning \
	(tkIntStubsPtr->tkpDisplayWarning) /* 58 */
#define TkpGetAppName \
	(tkIntStubsPtr->tkpGetAppName) /* 59 */
/* Slot 60 is reserved */
#define TkpGetOtherWindow \
	(tkIntStubsPtr->tkpGetOtherWindow) /* 60 */
#define TkpGetWrapperWindow \
	(tkIntStubsPtr->tkpGetWrapperWindow) /* 61 */
#define TkpInit \
	(tkIntStubsPtr->tkpInit) /* 62 */
#define TkpInitializeMenuBindings \
	(tkIntStubsPtr->tkpInitializeMenuBindings) /* 63 */
/* Slot 64 is reserved */
#define TkpMakeContainer \
	(tkIntStubsPtr->tkpMakeContainer) /* 64 */
#define TkpMakeMenuWindow \
	(tkIntStubsPtr->tkpMakeMenuWindow) /* 65 */
/* Slot 66 is reserved */
#define TkpMakeWindow \
	(tkIntStubsPtr->tkpMakeWindow) /* 66 */
#define TkpMenuNotifyToplevelCreate \
	(tkIntStubsPtr->tkpMenuNotifyToplevelCreate) /* 67 */
#define TkpOpenDisplay \
	(tkIntStubsPtr->tkpOpenDisplay) /* 68 */
#define TkPointerEvent \
	(tkIntStubsPtr->tkPointerEvent) /* 69 */
#define TkPolygonToArea \
	(tkIntStubsPtr->tkPolygonToArea) /* 70 */
#define TkPolygonToPoint \
	(tkIntStubsPtr->tkPolygonToPoint) /* 71 */
#define TkPositionInTree \
	(tkIntStubsPtr->tkPositionInTree) /* 72 */
#define TkpRedirectKeyEvent \
	(tkIntStubsPtr->tkpRedirectKeyEvent) /* 73 */
/* Slot 74 is reserved */
/* Slot 75 is reserved */
#define TkpSetMainMenubar \
	(tkIntStubsPtr->tkpSetMainMenubar) /* 74 */
#define TkpUseWindow \
	(tkIntStubsPtr->tkpUseWindow) /* 75 */
/* Slot 76 is reserved */
#define TkQueueEventForAllChildren \
	(tkIntStubsPtr->tkQueueEventForAllChildren) /* 77 */
#define TkReadBitmapFile \
	(tkIntStubsPtr->tkReadBitmapFile) /* 78 */
#define TkScrollWindow \
	(tkIntStubsPtr->tkScrollWindow) /* 79 */
#define TkSelDeadWindow \
	(tkIntStubsPtr->tkSelDeadWindow) /* 80 */
#define TkSelEventProc \
	(tkIntStubsPtr->tkSelEventProc) /* 81 */
#define TkSelInit \
	(tkIntStubsPtr->tkSelInit) /* 82 */
#define TkSelPropProc \
	(tkIntStubsPtr->tkSelPropProc) /* 83 */
/* Slot 84 is reserved */
/* Slot 85 is reserved */
#define TkSetWindowMenuBar \
	(tkIntStubsPtr->tkSetWindowMenuBar) /* 85 */
#define TkStringToKeysym \
	(tkIntStubsPtr->tkStringToKeysym) /* 86 */
#define TkThickPolyLineToArea \
	(tkIntStubsPtr->tkThickPolyLineToArea) /* 87 */
#define TkWmAddToColormapWindows \
	(tkIntStubsPtr->tkWmAddToColormapWindows) /* 88 */
#define TkWmDeadWindow \
959
960
961
962
963
964
965

966

967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982














983

984
985


986
987

988

989
990

991
992
993
994
995
996
997
998
999
1000

1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021


1022
1023
1024
1025
1026
1027
1028
999
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009














1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067


1068
1069
1070
1071
1072
1073
1074
1075
1076







+
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+


+
+


+

+


+










+
-
+


















-
-
+
+







	(tkIntStubsPtr->tkGetMainInfoList) /* 107 */
#define TkGetWindowFromObj \
	(tkIntStubsPtr->tkGetWindowFromObj) /* 108 */
#define TkpGetString \
	(tkIntStubsPtr->tkpGetString) /* 109 */
#define TkpGetSubFonts \
	(tkIntStubsPtr->tkpGetSubFonts) /* 110 */
#define TkpGetSystemDefault \
/* Slot 111 is reserved */
	(tkIntStubsPtr->tkpGetSystemDefault) /* 111 */
#define TkpMenuThreadInit \
	(tkIntStubsPtr->tkpMenuThreadInit) /* 112 */
#define XClipBox \
	(tkIntStubsPtr->xClipBox) /* 113 */
#define XCreateRegion \
	(tkIntStubsPtr->xCreateRegion) /* 114 */
#define XDestroyRegion \
	(tkIntStubsPtr->xDestroyRegion) /* 115 */
#define XIntersectRegion \
	(tkIntStubsPtr->xIntersectRegion) /* 116 */
#define XRectInRegion \
	(tkIntStubsPtr->xRectInRegion) /* 117 */
#define XSetRegion \
	(tkIntStubsPtr->xSetRegion) /* 118 */
#define XUnionRectWithRegion \
	(tkIntStubsPtr->xUnionRectWithRegion) /* 119 */
#define TkClipBox \
	(tkIntStubsPtr->tkClipBox) /* 113 */
#define TkCreateRegion \
	(tkIntStubsPtr->tkCreateRegion) /* 114 */
#define TkDestroyRegion \
	(tkIntStubsPtr->tkDestroyRegion) /* 115 */
#define TkIntersectRegion \
	(tkIntStubsPtr->tkIntersectRegion) /* 116 */
#define TkRectInRegion \
	(tkIntStubsPtr->tkRectInRegion) /* 117 */
#define TkSetRegion \
	(tkIntStubsPtr->tkSetRegion) /* 118 */
#define TkUnionRectWithRegion \
	(tkIntStubsPtr->tkUnionRectWithRegion) /* 119 */
/* Slot 120 is reserved */
#ifdef MAC_OSX_TK /* AQUA */
#define TkpCreateNativeBitmap \
	(tkIntStubsPtr->tkpCreateNativeBitmap) /* 121 */
#endif /* AQUA */
#ifdef MAC_OSX_TK /* AQUA */
#define TkpDefineNativeBitmaps \
	(tkIntStubsPtr->tkpDefineNativeBitmaps) /* 122 */
#endif /* AQUA */
/* Slot 123 is reserved */
#ifdef MAC_OSX_TK /* AQUA */
#define TkpGetNativeAppBitmap \
	(tkIntStubsPtr->tkpGetNativeAppBitmap) /* 124 */
#endif /* AQUA */
/* Slot 125 is reserved */
/* Slot 126 is reserved */
/* Slot 127 is reserved */
/* Slot 128 is reserved */
/* Slot 129 is reserved */
/* Slot 130 is reserved */
/* Slot 131 is reserved */
/* Slot 132 is reserved */
/* Slot 133 is reserved */
/* Slot 134 is reserved */
#define TkpDrawHighlightBorder \
/* Slot 135 is reserved */
	(tkIntStubsPtr->tkpDrawHighlightBorder) /* 135 */
#define TkSetFocusWin \
	(tkIntStubsPtr->tkSetFocusWin) /* 136 */
#define TkpSetKeycodeAndState \
	(tkIntStubsPtr->tkpSetKeycodeAndState) /* 137 */
#define TkpGetKeySym \
	(tkIntStubsPtr->tkpGetKeySym) /* 138 */
#define TkpInitKeymapInfo \
	(tkIntStubsPtr->tkpInitKeymapInfo) /* 139 */
#define TkPhotoGetValidRegion \
	(tkIntStubsPtr->tkPhotoGetValidRegion) /* 140 */
#define TkWmStackorderToplevel \
	(tkIntStubsPtr->tkWmStackorderToplevel) /* 141 */
#define TkFocusFree \
	(tkIntStubsPtr->tkFocusFree) /* 142 */
#define TkClipCleanup \
	(tkIntStubsPtr->tkClipCleanup) /* 143 */
#define TkGCCleanup \
	(tkIntStubsPtr->tkGCCleanup) /* 144 */
#define XSubtractRegion \
	(tkIntStubsPtr->xSubtractRegion) /* 145 */
#define TkSubtractRegion \
	(tkIntStubsPtr->tkSubtractRegion) /* 145 */
#define TkStylePkgInit \
	(tkIntStubsPtr->tkStylePkgInit) /* 146 */
#define TkStylePkgFree \
	(tkIntStubsPtr->tkStylePkgFree) /* 147 */
#define TkToplevelWindowForCommand \
	(tkIntStubsPtr->tkToplevelWindowForCommand) /* 148 */
#define TkGetOptionSpec \
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1112




1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124























1125
1126

1140
1141
1142
1143
1144
1145
1146




1147

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160












1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186







-
-
-
-

-
+








+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
	(tkIntStubsPtr->tkDrawAngledTextLayout) /* 181 */
#define TkUnderlineAngledTextLayout \
	(tkIntStubsPtr->tkUnderlineAngledTextLayout) /* 182 */
#define TkIntersectAngledTextLayout \
	(tkIntStubsPtr->tkIntersectAngledTextLayout) /* 183 */
#define TkDrawAngledChars \
	(tkIntStubsPtr->tkDrawAngledChars) /* 184 */
#define TkpRedrawWidget \
	(tkIntStubsPtr->tkpRedrawWidget) /* 185 */
#define TkpWillDrawWidget \
	(tkIntStubsPtr->tkpWillDrawWidget) /* 186 */
#define TkDebugPhotoStringMatchDef \
	(tkIntStubsPtr->tkDebugPhotoStringMatchDef) /* 187 */
	(tkIntStubsPtr->tkDebugPhotoStringMatchDef) /* 185 */

#endif /* defined(USE_TK_STUBS) */

/* !END!: Do not edit above this line. */

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

/*
 * On X11, these macros are just wrappers for the equivalent X Region calls.
 */
#if !(defined(_WIN32) || defined(__CYGWIN__) || defined(MAC_OSX_TK)) /* X11 */
#if !defined(MAC_OSX_TK) && !defined(USE_TK_STUBS)
#   undef TkpWillDrawWidget
#   undef TkpRedrawWidget
#   undef TkpDefineNativeBitmaps
#   undef TkpCreateNativeBitmap
#   undef TkpGetNativeAppBitmap
#   define TkpWillDrawWidget(w) 0
#   define TkpRedrawWidget(w)
#   define TkpDefineNativeBitmaps()
#   define TkpCreateNativeBitmap(display, source) None
#   define TkpGetNativeAppBitmap(display, name, w, h) None
#endif

#undef TkClipBox
#undef TkCreateRegion
#undef TkDestroyRegion
#undef TkIntersectRegion
#undef TkRectInRegion
#undef TkSetRegion
#undef TkSubtractRegion
#undef TkUnionRectWithRegion

#define TkClipBox(rgn, rect) XClipBox((Region) rgn, rect)
#define TkCreateRegion() (TkRegion) XCreateRegion()
#define TkDestroyRegion(rgn) XDestroyRegion((Region) rgn)
#define TkIntersectRegion(a, b, r) XIntersectRegion((Region) a, \
	(Region) b, (Region) r)
#define TkRectInRegion(r, x, y, w, h) XRectInRegion((Region) r, x, y, w, h)
#define TkSetRegion(d, gc, rgn) XSetRegion(d, gc, (Region) rgn)
#define TkSubtractRegion(a, b, r) XSubtractRegion((Region) a, \
	(Region) b, (Region) r)
#define TkUnionRectWithRegion(rect, src, ret) XUnionRectWithRegion(rect, \
	(Region) src, (Region) ret)

#endif /* UNIX */

#endif /* _TKINTDECLS */

Changes to generic/tkIntPlatDecls.h.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 * tkIntPlatDecls.h --
 *
 *	This file contains the declarations for all platform dependent
 *	unsupported functions that are exported by the Tk library.  These
 *	interfaces are not guaranteed to remain the same between
 *	versions.  Use at your own risk.
 *
 * Copyright (c) 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 * All rights reserved.
 */

#ifndef _TKINTPLATDECLS
#define _TKINTPLATDECLS

#ifdef BUILD_tk
32
33
34
35
36
37
38
39


40
41
42
43
44
45
46
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47







-
+
+








/*
 * Exported function declarations:
 */

#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
/* 0 */
EXTERN void		TkCreateXEventSource(void);
EXTERN char *		TkAlignImageData(XImage *image, int alignment,
				int bitOrder);
/* Slot 1 is reserved */
/* 2 */
EXTERN void		TkGenerateActivateEvents(TkWindow *winPtr,
				int active);
/* 3 */
EXTERN unsigned long	TkpGetMS(void);
/* 4 */
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142



143
144
145
146
147
148
149

150
151
152
153


154
155

156
157

158
159
160
161

162
163
164

165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191



192
193
194
195
196
197
198



199
200
201
202
203
204
205


206
207
208
209
210


211
212
213
214

215
216
217
218
219
220
221
222
223
224


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243

244
245
246
247
248
249
250







251
252
253
254
255

256
257


258
259
260
261




262




263
264
265
266
267
268
269



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303


304
305
306
307
308
309
310
311
312
313



314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116

117

118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141


142
143
144



145
146


147


148
149
150
151
152

153
154

155
156
157
158

159

160

161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205

206
207
208
209
210
211

212
213
214
215
216

217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267


268
269




270
271
272
273
274
275
276
277
278
279
280


281


282
283
284
285



























286






287
288










289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306







-
+










-
+
-







-
+
+















-
-
+
+
+
-
-
-


-
-
+
-
-


+
+

-
+

-
+



-
+
-

-
+







-
+


















-
+
+
+






-
+
+
+






-
+
+




-
+
+



-
+









-
+
+















-
+


-
+







+
+
+
+
+
+
+





+
-
-
+
+
-
-
-
-
+
+
+
+

+
+
+
+


-
-

-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+







-
+







EXTERN void		TkWinSetMenu(Tk_Window tkwin, HMENU hMenu);
/* 26 */
EXTERN void		TkWinSetWindowPos(HWND hwnd, HWND siblingHwnd,
				int pos);
/* 27 */
EXTERN void		TkWinWmCleanup(HINSTANCE hInstance);
/* 28 */
EXTERN void		TkWinXCleanup(void *clientData);
EXTERN void		TkWinXCleanup(ClientData clientData);
/* 29 */
EXTERN void		TkWinXInit(HINSTANCE hInstance);
/* 30 */
EXTERN void		TkWinSetForegroundWindow(TkWindow *winPtr);
/* 31 */
EXTERN void		TkWinDialogDebug(int debug);
/* 32 */
EXTERN Tcl_Obj *	TkWinGetMenuSystemDefault(Tk_Window tkwin,
				const char *dbName, const char *className);
/* 33 */
EXTERN char *		TkAlignImageData(XImage *image, int alignment,
EXTERN int		TkWinGetPlatformId(void);
				int bitOrder);
/* 34 */
EXTERN void		TkWinSetHINSTANCE(HINSTANCE hInstance);
/* 35 */
EXTERN int		TkWinGetPlatformTheme(void);
/* 36 */
EXTERN LRESULT __stdcall TkWinChildProc(HWND hwnd, UINT message,
				WPARAM wParam, LPARAM lParam);
/* Slot 37 is reserved */
/* 37 */
EXTERN void		TkCreateXEventSource(void);
/* 38 */
EXTERN int		TkpCmapStressed(Tk_Window tkwin, Colormap colormap);
/* 39 */
EXTERN void		TkpSync(Display *display);
/* 40 */
EXTERN Window		TkUnixContainerId(TkWindow *winPtr);
/* 41 */
EXTERN int		TkUnixDoOneXEvent(Tcl_Time *timePtr);
/* 42 */
EXTERN void		TkUnixSetMenubar(Tk_Window tkwin, Tk_Window menubar);
/* 43 */
EXTERN void		TkWmCleanup(TkDisplay *dispPtr);
/* 44 */
EXTERN void		TkSendCleanup(TkDisplay *dispPtr);
/* 45 */
EXTERN int		TkpTestsendCmd(void *clientData, Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[]);
EXTERN int		TkpTestsendCmd(ClientData clientData,
				Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[]);
/* Slot 46 is reserved */
/* 47 */
EXTERN Tk_Window	TkpGetCapture(void);
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
/* Slot 0 is reserved */
/* 1 */
/* 0 */
EXTERN void		TkAboutDlg(void);
/* 2 */
EXTERN void		TkGenerateActivateEvents(TkWindow *winPtr,
				int active);
/* Slot 1 is reserved */
/* Slot 2 is reserved */
/* 3 */
EXTERN unsigned long	TkpGetMS(void);
EXTERN void		TkPointerDeadWindow(TkWindow *winPtr);
/* 4 */
EXTERN void		TkPointerDeadWindow(TkWindow *winPtr);
EXTERN void		TkpSetCapture(TkWindow *winPtr);
/* 5 */
EXTERN void		TkpSetCursor(TkpCursor cursor);
/* 6 */
EXTERN int		TkpScanWindowId(Tcl_Interp *interp,
EXTERN void		TkpWmSetState(TkWindow *winPtr, int state);
				const char *string, Window *idPtr);
/* 7 */
EXTERN int		TkpWmSetState(TkWindow *winPtr, int state);
EXTERN void		TkAboutDlg(void);
/* 8 */
EXTERN unsigned int	TkMacOSXButtonKeyState(void);
/* 9 */
EXTERN void		TkMacOSXClearMenubarActive(void);
/* 10 */
EXTERN int		TkMacOSXDispatchMenuEvent(int menuID, int index);
/* 11 */
EXTERN void		TkpSetCapture(TkWindow *winPtr);
EXTERN void		TkMacOSXInstallCursor(int resizeOverride);
/* 12 */
EXTERN void		TkMacOSXHandleTearoffMenu(void);
/* Slot 13 is reserved */
/* 14 */
EXTERN int		TkMacOSXDoHLEvent(void *theEvent);
/* Slot 15 is reserved */
/* 16 */
EXTERN Window		TkMacOSXGetXWindow(void *macWinPtr);
/* 17 */
EXTERN int		TkMacOSXGrowToplevel(void *whichWindow, XPoint start);
/* 18 */
EXTERN void		TkMacOSXHandleMenuSelect(short theMenu,
				unsigned short theItem, int optionKeyPressed);
/* Slot 19 is reserved */
/* Slot 20 is reserved */
/* 21 */
EXTERN void		TkMacOSXInvalidateWindow(MacDrawable *macWin,
				int flag);
/* Slot 22 is reserved */
/* 22 */
EXTERN int		TkMacOSXIsCharacterMissing(Tk_Font tkfont,
				unsigned int searchChar);
/* 23 */
EXTERN void		TkMacOSXMakeRealWindowExist(TkWindow *winPtr);
/* 24 */
EXTERN void *		TkMacOSXMakeStippleMap(Drawable d1, Drawable d2);
/* 25 */
EXTERN void		TkMacOSXMenuClick(void);
/* Slot 26 is reserved */
/* 26 */
EXTERN void		TkMacOSXRegisterOffScreenWindow(Window window,
				void *portPtr);
/* 27 */
EXTERN int		TkMacOSXResizable(TkWindow *winPtr);
/* 28 */
EXTERN void		TkMacOSXSetHelpMenuItemCount(void);
/* 29 */
EXTERN void		TkMacOSXSetScrollbarGrow(TkWindow *winPtr, int flag);
/* Slot 30 is reserved */
/* 30 */
EXTERN void		TkMacOSXSetUpClippingRgn(Drawable drawable);
/* 31 */
EXTERN void		TkMacOSXSetUpGraphicsPort(GC gc, void *destPort);
/* 32 */
EXTERN void		TkMacOSXUpdateClipRgn(TkWindow *winPtr);
/* Slot 33 is reserved */
/* 33 */
EXTERN void		TkMacOSXUnregisterMacWindow(void *portPtr);
/* 34 */
EXTERN int		TkMacOSXUseMenuID(short macID);
/* 35 */
EXTERN Region		TkMacOSXVisableClipRgn(TkWindow *winPtr);
EXTERN TkRegion		TkMacOSXVisableClipRgn(TkWindow *winPtr);
/* 36 */
EXTERN void		TkMacOSXWinBounds(TkWindow *winPtr, void *geometry);
/* 37 */
EXTERN void		TkMacOSXWindowOffset(void *wRef, int *xOffset,
				int *yOffset);
/* 38 */
EXTERN int		TkSetMacColor(unsigned long pixel, void *macColor);
/* 39 */
EXTERN void		TkSetWMName(TkWindow *winPtr, Tk_Uid titleUid);
/* Slot 40 is reserved */
/* 40 */
EXTERN void		TkSuspendClipboard(void);
/* 41 */
EXTERN int		TkMacOSXZoomToplevel(void *whichWindow,
				short zoomPart);
/* 42 */
EXTERN Tk_Window	Tk_TopCoordsToWindow(Tk_Window tkwin, int rootX,
				int rootY, int *newX, int *newY);
/* 43 */
EXTERN MacDrawable *	TkMacOSXContainerId(TkWindow *winPtr);
/* 44 */
EXTERN MacDrawable *	TkMacOSXGetHostToplevel(TkWindow *winPtr);
/* 45 */
EXTERN void		TkMacOSXPreprocessMenu(void);
/* 46 */
EXTERN int		TkpIsWindowFloating(void *window);
/* 47 */
EXTERN Tk_Window	TkpGetCapture(void);
EXTERN Tk_Window	TkMacOSXGetCapture(void);
/* Slot 48 is reserved */
/* 49 */
EXTERN Tk_Window	TkMacOSXGetContainer(TkWindow *winPtr);
EXTERN Window		TkGetTransientMaster(TkWindow *winPtr);
/* 50 */
EXTERN int		TkGenerateButtonEvent(int x, int y, Window window,
				unsigned int state);
/* 51 */
EXTERN void		TkGenWMDestroyEvent(Tk_Window tkwin);
/* 52 */
EXTERN void		TkMacOSXSetDrawingEnabled(TkWindow *winPtr, int flag);
/* 53 */
EXTERN unsigned long	TkpGetMS(void);
/* 54 */
EXTERN void *		TkMacOSXDrawable(Drawable drawable);
/* 55 */
EXTERN int		TkpScanWindowId(Tcl_Interp *interp,
				const char *string, Window *idPtr);
#endif /* AQUA */
#if !(defined(_WIN32) || defined(__CYGWIN__) || defined(MAC_OSX_TK)) /* X11 */
/* 0 */
EXTERN void		TkCreateXEventSource(void);
/* Slot 1 is reserved */
/* Slot 2 is reserved */
/* 2 */
EXTERN void		TkGenerateActivateEvents(TkWindow *winPtr,
/* 3 */
EXTERN int		TkpCmapStressed(Tk_Window tkwin, Colormap colormap);
				int active);
/* Slot 3 is reserved */
/* Slot 4 is reserved */
/* Slot 5 is reserved */
/* 4 */
EXTERN void		TkpSync(Display *display);
/* 5 */
EXTERN Window		TkUnixContainerId(TkWindow *winPtr);
/* 6 */
EXTERN int		TkUnixDoOneXEvent(Tcl_Time *timePtr);
/* 7 */
EXTERN void		TkUnixSetMenubar(Tk_Window tkwin, Tk_Window menubar);
/* 8 */
EXTERN int		TkpScanWindowId(Tcl_Interp *interp,
				const char *string, Window *idPtr);
/* Slot 7 is reserved */
/* Slot 8 is reserved */
/* 9 */
EXTERN int		TkpWmSetState(TkWindow *winPtr, int state);
/* Slot 10 is reserved */
EXTERN void		TkWmCleanup(TkDisplay *dispPtr);
/* 10 */
EXTERN void		TkSendCleanup(TkDisplay *dispPtr);
/* Slot 11 is reserved */
/* Slot 12 is reserved */
/* Slot 13 is reserved */
/* Slot 14 is reserved */
/* Slot 15 is reserved */
/* Slot 16 is reserved */
/* Slot 17 is reserved */
/* Slot 18 is reserved */
/* Slot 19 is reserved */
/* Slot 20 is reserved */
/* Slot 21 is reserved */
/* Slot 22 is reserved */
/* Slot 23 is reserved */
/* Slot 24 is reserved */
/* Slot 25 is reserved */
/* Slot 26 is reserved */
/* Slot 27 is reserved */
/* Slot 28 is reserved */
/* Slot 29 is reserved */
/* Slot 30 is reserved */
/* Slot 31 is reserved */
/* Slot 32 is reserved */
/* Slot 33 is reserved */
/* Slot 34 is reserved */
/* Slot 35 is reserved */
/* Slot 36 is reserved */
/* Slot 37 is reserved */
/* 38 */
/* 12 */
EXTERN int		TkpCmapStressed(Tk_Window tkwin, Colormap colormap);
/* 39 */
EXTERN void		TkpSync(Display *display);
/* 40 */
EXTERN Window		TkUnixContainerId(TkWindow *winPtr);
/* 41 */
EXTERN int		TkpWmSetState(TkWindow *winPtr, int state);
/* 13 */
EXTERN int		TkUnixDoOneXEvent(Tcl_Time *timePtr);
/* 42 */
EXTERN void		TkUnixSetMenubar(Tk_Window tkwin, Tk_Window menubar);
/* 43 */
EXTERN void		TkWmCleanup(TkDisplay *dispPtr);
/* 44 */
EXTERN void		TkSendCleanup(TkDisplay *dispPtr);
/* 45 */
EXTERN int		TkpTestsendCmd(void *clientData, Tcl_Interp *interp,
				Tcl_Size objc, Tcl_Obj *const objv[]);
EXTERN int		TkpTestsendCmd(ClientData clientData,
				Tcl_Interp *interp, int objc,
				Tcl_Obj *const objv[]);
#endif /* X11 */

typedef struct TkIntPlatStubs {
    int magic;
    void *hooks;

#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
    void (*tkCreateXEventSource) (void); /* 0 */
    char * (*tkAlignImageData) (XImage *image, int alignment, int bitOrder); /* 0 */
    void (*reserved1)(void);
    void (*tkGenerateActivateEvents) (TkWindow *winPtr, int active); /* 2 */
    unsigned long (*tkpGetMS) (void); /* 3 */
    void (*tkPointerDeadWindow) (TkWindow *winPtr); /* 4 */
    void (*tkpPrintWindowId) (char *buf, Window window); /* 5 */
    int (*tkpScanWindowId) (Tcl_Interp *interp, const char *string, Window *idPtr); /* 6 */
    void (*tkpSetCapture) (TkWindow *winPtr); /* 7 */
342
343
344
345
346
347
348
349

350
351
352
353
354

355
356
357
358

359
360
361
362
363
364
365
366

367
368
369
370

371
372


373
374
375


376
377
378


379
380
381
382

383
384
385
386
387
388
389
390
391
392
393

394
395
396
397

398
399
400
401

402
403
404

405
406

407
408
409
410
411

412
413
414
415
416
417
418

419
420

421
422
423



424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471











472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489


490
491
492
493
494
495
496
320
321
322
323
324
325
326

327
328
329
330
331

332
333
334
335

336
337
338
339
340
341
342
343

344


345
346
347


348
349



350
351
352


353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368

369
370
371
372

373
374
375
376

377
378
379

380
381

382
383
384
385
386

387
388
389
390
391
392
393

394
395

396
397
398
399
400
401
402
403
404
405
406


407










































408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434


435
436
437
438
439
440
441
442
443







-
+




-
+



-
+







-
+
-
-


+
-
-
+
+
-
-
-
+
+

-
-
+
+



-
+










-
+



-
+



-
+


-
+

-
+




-
+






-
+

-
+



+
+
+




-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
















-
-
+
+







    int (*tkWinIndexOfColor) (XColor *colorPtr); /* 21 */
    void (*tkWinReleaseDrawableDC) (Drawable d, HDC hdc, TkWinDCState *state); /* 22 */
    LRESULT (*tkWinResendEvent) (WNDPROC wndproc, HWND hwnd, XEvent *eventPtr); /* 23 */
    HPALETTE (*tkWinSelectPalette) (HDC dc, Colormap colormap); /* 24 */
    void (*tkWinSetMenu) (Tk_Window tkwin, HMENU hMenu); /* 25 */
    void (*tkWinSetWindowPos) (HWND hwnd, HWND siblingHwnd, int pos); /* 26 */
    void (*tkWinWmCleanup) (HINSTANCE hInstance); /* 27 */
    void (*tkWinXCleanup) (void *clientData); /* 28 */
    void (*tkWinXCleanup) (ClientData clientData); /* 28 */
    void (*tkWinXInit) (HINSTANCE hInstance); /* 29 */
    void (*tkWinSetForegroundWindow) (TkWindow *winPtr); /* 30 */
    void (*tkWinDialogDebug) (int debug); /* 31 */
    Tcl_Obj * (*tkWinGetMenuSystemDefault) (Tk_Window tkwin, const char *dbName, const char *className); /* 32 */
    char * (*tkAlignImageData) (XImage *image, int alignment, int bitOrder); /* 33 */
    int (*tkWinGetPlatformId) (void); /* 33 */
    void (*tkWinSetHINSTANCE) (HINSTANCE hInstance); /* 34 */
    int (*tkWinGetPlatformTheme) (void); /* 35 */
    LRESULT (__stdcall *tkWinChildProc) (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); /* 36 */
    void (*reserved37)(void);
    void (*tkCreateXEventSource) (void); /* 37 */
    int (*tkpCmapStressed) (Tk_Window tkwin, Colormap colormap); /* 38 */
    void (*tkpSync) (Display *display); /* 39 */
    Window (*tkUnixContainerId) (TkWindow *winPtr); /* 40 */
    int (*tkUnixDoOneXEvent) (Tcl_Time *timePtr); /* 41 */
    void (*tkUnixSetMenubar) (Tk_Window tkwin, Tk_Window menubar); /* 42 */
    void (*tkWmCleanup) (TkDisplay *dispPtr); /* 43 */
    void (*tkSendCleanup) (TkDisplay *dispPtr); /* 44 */
    int (*tkpTestsendCmd) (void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 45 */
    int (*tkpTestsendCmd) (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* 45 */
    void (*reserved46)(void);
    Tk_Window (*tkpGetCapture) (void); /* 47 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    void (*tkGenerateActivateEvents) (TkWindow *winPtr, int active); /* 0 */
    void (*reserved0)(void);
    void (*tkAboutDlg) (void); /* 1 */
    void (*reserved1)(void);
    void (*reserved2)(void);
    void (*tkGenerateActivateEvents) (TkWindow *winPtr, int active); /* 2 */
    unsigned long (*tkpGetMS) (void); /* 3 */
    void (*tkPointerDeadWindow) (TkWindow *winPtr); /* 4 */
    void (*tkPointerDeadWindow) (TkWindow *winPtr); /* 3 */
    void (*tkpSetCapture) (TkWindow *winPtr); /* 4 */
    void (*tkpSetCursor) (TkpCursor cursor); /* 5 */
    int (*tkpScanWindowId) (Tcl_Interp *interp, const char *string, Window *idPtr); /* 6 */
    int (*tkpWmSetState) (TkWindow *winPtr, int state); /* 7 */
    void (*tkpWmSetState) (TkWindow *winPtr, int state); /* 6 */
    void (*tkAboutDlg) (void); /* 7 */
    unsigned int (*tkMacOSXButtonKeyState) (void); /* 8 */
    void (*tkMacOSXClearMenubarActive) (void); /* 9 */
    int (*tkMacOSXDispatchMenuEvent) (int menuID, int index); /* 10 */
    void (*tkpSetCapture) (TkWindow *winPtr); /* 11 */
    void (*tkMacOSXInstallCursor) (int resizeOverride); /* 11 */
    void (*tkMacOSXHandleTearoffMenu) (void); /* 12 */
    void (*reserved13)(void);
    int (*tkMacOSXDoHLEvent) (void *theEvent); /* 14 */
    void (*reserved15)(void);
    Window (*tkMacOSXGetXWindow) (void *macWinPtr); /* 16 */
    int (*tkMacOSXGrowToplevel) (void *whichWindow, XPoint start); /* 17 */
    void (*tkMacOSXHandleMenuSelect) (short theMenu, unsigned short theItem, int optionKeyPressed); /* 18 */
    void (*reserved19)(void);
    void (*reserved20)(void);
    void (*tkMacOSXInvalidateWindow) (MacDrawable *macWin, int flag); /* 21 */
    void (*reserved22)(void);
    int (*tkMacOSXIsCharacterMissing) (Tk_Font tkfont, unsigned int searchChar); /* 22 */
    void (*tkMacOSXMakeRealWindowExist) (TkWindow *winPtr); /* 23 */
    void * (*tkMacOSXMakeStippleMap) (Drawable d1, Drawable d2); /* 24 */
    void (*tkMacOSXMenuClick) (void); /* 25 */
    void (*reserved26)(void);
    void (*tkMacOSXRegisterOffScreenWindow) (Window window, void *portPtr); /* 26 */
    int (*tkMacOSXResizable) (TkWindow *winPtr); /* 27 */
    void (*tkMacOSXSetHelpMenuItemCount) (void); /* 28 */
    void (*tkMacOSXSetScrollbarGrow) (TkWindow *winPtr, int flag); /* 29 */
    void (*reserved30)(void);
    void (*tkMacOSXSetUpClippingRgn) (Drawable drawable); /* 30 */
    void (*tkMacOSXSetUpGraphicsPort) (GC gc, void *destPort); /* 31 */
    void (*tkMacOSXUpdateClipRgn) (TkWindow *winPtr); /* 32 */
    void (*reserved33)(void);
    void (*tkMacOSXUnregisterMacWindow) (void *portPtr); /* 33 */
    int (*tkMacOSXUseMenuID) (short macID); /* 34 */
    Region (*tkMacOSXVisableClipRgn) (TkWindow *winPtr); /* 35 */
    TkRegion (*tkMacOSXVisableClipRgn) (TkWindow *winPtr); /* 35 */
    void (*tkMacOSXWinBounds) (TkWindow *winPtr, void *geometry); /* 36 */
    void (*tkMacOSXWindowOffset) (void *wRef, int *xOffset, int *yOffset); /* 37 */
    int (*tkSetMacColor) (unsigned long pixel, void *macColor); /* 38 */
    void (*tkSetWMName) (TkWindow *winPtr, Tk_Uid titleUid); /* 39 */
    void (*reserved40)(void);
    void (*tkSuspendClipboard) (void); /* 40 */
    int (*tkMacOSXZoomToplevel) (void *whichWindow, short zoomPart); /* 41 */
    Tk_Window (*tk_TopCoordsToWindow) (Tk_Window tkwin, int rootX, int rootY, int *newX, int *newY); /* 42 */
    MacDrawable * (*tkMacOSXContainerId) (TkWindow *winPtr); /* 43 */
    MacDrawable * (*tkMacOSXGetHostToplevel) (TkWindow *winPtr); /* 44 */
    void (*tkMacOSXPreprocessMenu) (void); /* 45 */
    int (*tkpIsWindowFloating) (void *window); /* 46 */
    Tk_Window (*tkpGetCapture) (void); /* 47 */
    Tk_Window (*tkMacOSXGetCapture) (void); /* 47 */
    void (*reserved48)(void);
    Tk_Window (*tkMacOSXGetContainer) (TkWindow *winPtr); /* 49 */
    Window (*tkGetTransientMaster) (TkWindow *winPtr); /* 49 */
    int (*tkGenerateButtonEvent) (int x, int y, Window window, unsigned int state); /* 50 */
    void (*tkGenWMDestroyEvent) (Tk_Window tkwin); /* 51 */
    void (*tkMacOSXSetDrawingEnabled) (TkWindow *winPtr, int flag); /* 52 */
    unsigned long (*tkpGetMS) (void); /* 53 */
    void * (*tkMacOSXDrawable) (Drawable drawable); /* 54 */
    int (*tkpScanWindowId) (Tcl_Interp *interp, const char *string, Window *idPtr); /* 55 */
#endif /* AQUA */
#if !(defined(_WIN32) || defined(__CYGWIN__) || defined(MAC_OSX_TK)) /* X11 */
    void (*tkCreateXEventSource) (void); /* 0 */
    void (*reserved1)(void);
    void (*tkGenerateActivateEvents) (TkWindow *winPtr, int active); /* 2 */
    void (*reserved3)(void);
    void (*reserved2)(void);
    void (*reserved4)(void);
    void (*reserved5)(void);
    int (*tkpScanWindowId) (Tcl_Interp *interp, const char *string, Window *idPtr); /* 6 */
    void (*reserved7)(void);
    void (*reserved8)(void);
    int (*tkpWmSetState) (TkWindow *winPtr, int state); /* 9 */
    void (*reserved10)(void);
    void (*reserved11)(void);
    void (*reserved12)(void);
    void (*reserved13)(void);
    void (*reserved14)(void);
    void (*reserved15)(void);
    void (*reserved16)(void);
    void (*reserved17)(void);
    void (*reserved18)(void);
    void (*reserved19)(void);
    void (*reserved20)(void);
    void (*reserved21)(void);
    void (*reserved22)(void);
    void (*reserved23)(void);
    void (*reserved24)(void);
    void (*reserved25)(void);
    void (*reserved26)(void);
    void (*reserved27)(void);
    void (*reserved28)(void);
    void (*reserved29)(void);
    void (*reserved30)(void);
    void (*reserved31)(void);
    void (*reserved32)(void);
    void (*reserved33)(void);
    void (*reserved34)(void);
    void (*reserved35)(void);
    void (*reserved36)(void);
    void (*reserved37)(void);
    int (*tkpCmapStressed) (Tk_Window tkwin, Colormap colormap); /* 38 */
    void (*tkpSync) (Display *display); /* 39 */
    Window (*tkUnixContainerId) (TkWindow *winPtr); /* 40 */
    int (*tkUnixDoOneXEvent) (Tcl_Time *timePtr); /* 41 */
    void (*tkUnixSetMenubar) (Tk_Window tkwin, Tk_Window menubar); /* 42 */
    void (*tkWmCleanup) (TkDisplay *dispPtr); /* 43 */
    void (*tkSendCleanup) (TkDisplay *dispPtr); /* 44 */
    int (*tkpTestsendCmd) (void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 45 */
    int (*tkpCmapStressed) (Tk_Window tkwin, Colormap colormap); /* 3 */
    void (*tkpSync) (Display *display); /* 4 */
    Window (*tkUnixContainerId) (TkWindow *winPtr); /* 5 */
    int (*tkUnixDoOneXEvent) (Tcl_Time *timePtr); /* 6 */
    void (*tkUnixSetMenubar) (Tk_Window tkwin, Tk_Window menubar); /* 7 */
    int (*tkpScanWindowId) (Tcl_Interp *interp, const char *string, Window *idPtr); /* 8 */
    void (*tkWmCleanup) (TkDisplay *dispPtr); /* 9 */
    void (*tkSendCleanup) (TkDisplay *dispPtr); /* 10 */
    void (*reserved11)(void);
    int (*tkpWmSetState) (TkWindow *winPtr, int state); /* 12 */
    int (*tkpTestsendCmd) (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* 13 */
#endif /* X11 */
} TkIntPlatStubs;

extern const TkIntPlatStubs *tkIntPlatStubsPtr;

#ifdef __cplusplus
}
#endif

#if defined(USE_TK_STUBS)

/*
 * Inline function declarations:
 */

#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
#define TkCreateXEventSource \
	(tkIntPlatStubsPtr->tkCreateXEventSource) /* 0 */
#define TkAlignImageData \
	(tkIntPlatStubsPtr->tkAlignImageData) /* 0 */
/* Slot 1 is reserved */
#define TkGenerateActivateEvents \
	(tkIntPlatStubsPtr->tkGenerateActivateEvents) /* 2 */
#define TkpGetMS \
	(tkIntPlatStubsPtr->tkpGetMS) /* 3 */
#define TkPointerDeadWindow \
	(tkIntPlatStubsPtr->tkPointerDeadWindow) /* 4 */
546
547
548
549
550
551
552
553
554


555
556
557
558
559
560
561


562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589


590
591
592
593
594
595





596
597



598
599
600
601
602
603
604
605


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622


623
624
625
626
627
628
629


630
631
632
633
634
635
636


637
638
639
640
641


642
643
644
645
646
647
648
649
650
651
652
653
654


655
656
657
658
659
660
661
662
663
664
665
666
667
668


669
670
671


672
673
674
675
676
677






678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723

724
725

726
727

728
729

730
731



732
733

734
735




736
737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
493
494
495
496
497
498
499


500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525



526
527



528

529


530
531
532





533
534
535
536
537
538

539
540
541
542
543
544
545
546
547


548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581

582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609
610
611
612
613
614
615


616
617
618


619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637














638

























639

640
641

642
643

644
645

646
647

648
649
650
651

652
653

654
655
656
657
658

659
660
661
662
663
664
665




666
667
668
669







-
-
+
+






-
+
+
















-
-
-


-
-
-

-
+
-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
+
+
+






-
-
+
+
















-
+
+






-
+
+






-
+
+




-
+
+












-
+
+












-
-
+
+

-
-
+
+






+
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+

-
+

-
+

-
+
+
+

-
+

-
+
+
+
+

-
+






-
-
-
-




	(tkIntPlatStubsPtr->tkWinXInit) /* 29 */
#define TkWinSetForegroundWindow \
	(tkIntPlatStubsPtr->tkWinSetForegroundWindow) /* 30 */
#define TkWinDialogDebug \
	(tkIntPlatStubsPtr->tkWinDialogDebug) /* 31 */
#define TkWinGetMenuSystemDefault \
	(tkIntPlatStubsPtr->tkWinGetMenuSystemDefault) /* 32 */
#define TkAlignImageData \
	(tkIntPlatStubsPtr->tkAlignImageData) /* 33 */
#define TkWinGetPlatformId \
	(tkIntPlatStubsPtr->tkWinGetPlatformId) /* 33 */
#define TkWinSetHINSTANCE \
	(tkIntPlatStubsPtr->tkWinSetHINSTANCE) /* 34 */
#define TkWinGetPlatformTheme \
	(tkIntPlatStubsPtr->tkWinGetPlatformTheme) /* 35 */
#define TkWinChildProc \
	(tkIntPlatStubsPtr->tkWinChildProc) /* 36 */
/* Slot 37 is reserved */
#define TkCreateXEventSource \
	(tkIntPlatStubsPtr->tkCreateXEventSource) /* 37 */
#define TkpCmapStressed \
	(tkIntPlatStubsPtr->tkpCmapStressed) /* 38 */
#define TkpSync \
	(tkIntPlatStubsPtr->tkpSync) /* 39 */
#define TkUnixContainerId \
	(tkIntPlatStubsPtr->tkUnixContainerId) /* 40 */
#define TkUnixDoOneXEvent \
	(tkIntPlatStubsPtr->tkUnixDoOneXEvent) /* 41 */
#define TkUnixSetMenubar \
	(tkIntPlatStubsPtr->tkUnixSetMenubar) /* 42 */
#define TkWmCleanup \
	(tkIntPlatStubsPtr->tkWmCleanup) /* 43 */
#define TkSendCleanup \
	(tkIntPlatStubsPtr->tkSendCleanup) /* 44 */
#define TkpTestsendCmd \
	(tkIntPlatStubsPtr->tkpTestsendCmd) /* 45 */
/* Slot 46 is reserved */
#define TkpGetCapture \
	(tkIntPlatStubsPtr->tkpGetCapture) /* 47 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
/* Slot 0 is reserved */
#define TkAboutDlg \
	(tkIntPlatStubsPtr->tkAboutDlg) /* 1 */
#define TkGenerateActivateEvents \
	(tkIntPlatStubsPtr->tkGenerateActivateEvents) /* 2 */
	(tkIntPlatStubsPtr->tkGenerateActivateEvents) /* 0 */
#define TkpGetMS \
	(tkIntPlatStubsPtr->tkpGetMS) /* 3 */
/* Slot 1 is reserved */
/* Slot 2 is reserved */
#define TkPointerDeadWindow \
	(tkIntPlatStubsPtr->tkPointerDeadWindow) /* 4 */
#define TkpSetCursor \
	(tkIntPlatStubsPtr->tkpSetCursor) /* 5 */
#define TkpScanWindowId \
	(tkIntPlatStubsPtr->tkpScanWindowId) /* 6 */
	(tkIntPlatStubsPtr->tkPointerDeadWindow) /* 3 */
#define TkpSetCapture \
	(tkIntPlatStubsPtr->tkpSetCapture) /* 4 */
#define TkpSetCursor \
	(tkIntPlatStubsPtr->tkpSetCursor) /* 5 */
#define TkpWmSetState \
	(tkIntPlatStubsPtr->tkpWmSetState) /* 7 */
	(tkIntPlatStubsPtr->tkpWmSetState) /* 6 */
#define TkAboutDlg \
	(tkIntPlatStubsPtr->tkAboutDlg) /* 7 */
#define TkMacOSXButtonKeyState \
	(tkIntPlatStubsPtr->tkMacOSXButtonKeyState) /* 8 */
#define TkMacOSXClearMenubarActive \
	(tkIntPlatStubsPtr->tkMacOSXClearMenubarActive) /* 9 */
#define TkMacOSXDispatchMenuEvent \
	(tkIntPlatStubsPtr->tkMacOSXDispatchMenuEvent) /* 10 */
#define TkpSetCapture \
	(tkIntPlatStubsPtr->tkpSetCapture) /* 11 */
#define TkMacOSXInstallCursor \
	(tkIntPlatStubsPtr->tkMacOSXInstallCursor) /* 11 */
#define TkMacOSXHandleTearoffMenu \
	(tkIntPlatStubsPtr->tkMacOSXHandleTearoffMenu) /* 12 */
/* Slot 13 is reserved */
#define TkMacOSXDoHLEvent \
	(tkIntPlatStubsPtr->tkMacOSXDoHLEvent) /* 14 */
/* Slot 15 is reserved */
#define TkMacOSXGetXWindow \
	(tkIntPlatStubsPtr->tkMacOSXGetXWindow) /* 16 */
#define TkMacOSXGrowToplevel \
	(tkIntPlatStubsPtr->tkMacOSXGrowToplevel) /* 17 */
#define TkMacOSXHandleMenuSelect \
	(tkIntPlatStubsPtr->tkMacOSXHandleMenuSelect) /* 18 */
/* Slot 19 is reserved */
/* Slot 20 is reserved */
#define TkMacOSXInvalidateWindow \
	(tkIntPlatStubsPtr->tkMacOSXInvalidateWindow) /* 21 */
/* Slot 22 is reserved */
#define TkMacOSXIsCharacterMissing \
	(tkIntPlatStubsPtr->tkMacOSXIsCharacterMissing) /* 22 */
#define TkMacOSXMakeRealWindowExist \
	(tkIntPlatStubsPtr->tkMacOSXMakeRealWindowExist) /* 23 */
#define TkMacOSXMakeStippleMap \
	(tkIntPlatStubsPtr->tkMacOSXMakeStippleMap) /* 24 */
#define TkMacOSXMenuClick \
	(tkIntPlatStubsPtr->tkMacOSXMenuClick) /* 25 */
/* Slot 26 is reserved */
#define TkMacOSXRegisterOffScreenWindow \
	(tkIntPlatStubsPtr->tkMacOSXRegisterOffScreenWindow) /* 26 */
#define TkMacOSXResizable \
	(tkIntPlatStubsPtr->tkMacOSXResizable) /* 27 */
#define TkMacOSXSetHelpMenuItemCount \
	(tkIntPlatStubsPtr->tkMacOSXSetHelpMenuItemCount) /* 28 */
#define TkMacOSXSetScrollbarGrow \
	(tkIntPlatStubsPtr->tkMacOSXSetScrollbarGrow) /* 29 */
/* Slot 30 is reserved */
#define TkMacOSXSetUpClippingRgn \
	(tkIntPlatStubsPtr->tkMacOSXSetUpClippingRgn) /* 30 */
#define TkMacOSXSetUpGraphicsPort \
	(tkIntPlatStubsPtr->tkMacOSXSetUpGraphicsPort) /* 31 */
#define TkMacOSXUpdateClipRgn \
	(tkIntPlatStubsPtr->tkMacOSXUpdateClipRgn) /* 32 */
/* Slot 33 is reserved */
#define TkMacOSXUnregisterMacWindow \
	(tkIntPlatStubsPtr->tkMacOSXUnregisterMacWindow) /* 33 */
#define TkMacOSXUseMenuID \
	(tkIntPlatStubsPtr->tkMacOSXUseMenuID) /* 34 */
#define TkMacOSXVisableClipRgn \
	(tkIntPlatStubsPtr->tkMacOSXVisableClipRgn) /* 35 */
#define TkMacOSXWinBounds \
	(tkIntPlatStubsPtr->tkMacOSXWinBounds) /* 36 */
#define TkMacOSXWindowOffset \
	(tkIntPlatStubsPtr->tkMacOSXWindowOffset) /* 37 */
#define TkSetMacColor \
	(tkIntPlatStubsPtr->tkSetMacColor) /* 38 */
#define TkSetWMName \
	(tkIntPlatStubsPtr->tkSetWMName) /* 39 */
/* Slot 40 is reserved */
#define TkSuspendClipboard \
	(tkIntPlatStubsPtr->tkSuspendClipboard) /* 40 */
#define TkMacOSXZoomToplevel \
	(tkIntPlatStubsPtr->tkMacOSXZoomToplevel) /* 41 */
#define Tk_TopCoordsToWindow \
	(tkIntPlatStubsPtr->tk_TopCoordsToWindow) /* 42 */
#define TkMacOSXContainerId \
	(tkIntPlatStubsPtr->tkMacOSXContainerId) /* 43 */
#define TkMacOSXGetHostToplevel \
	(tkIntPlatStubsPtr->tkMacOSXGetHostToplevel) /* 44 */
#define TkMacOSXPreprocessMenu \
	(tkIntPlatStubsPtr->tkMacOSXPreprocessMenu) /* 45 */
#define TkpIsWindowFloating \
	(tkIntPlatStubsPtr->tkpIsWindowFloating) /* 46 */
#define TkpGetCapture \
	(tkIntPlatStubsPtr->tkpGetCapture) /* 47 */
#define TkMacOSXGetCapture \
	(tkIntPlatStubsPtr->tkMacOSXGetCapture) /* 47 */
/* Slot 48 is reserved */
#define TkMacOSXGetContainer \
	(tkIntPlatStubsPtr->tkMacOSXGetContainer) /* 49 */
#define TkGetTransientMaster \
	(tkIntPlatStubsPtr->tkGetTransientMaster) /* 49 */
#define TkGenerateButtonEvent \
	(tkIntPlatStubsPtr->tkGenerateButtonEvent) /* 50 */
#define TkGenWMDestroyEvent \
	(tkIntPlatStubsPtr->tkGenWMDestroyEvent) /* 51 */
#define TkMacOSXSetDrawingEnabled \
	(tkIntPlatStubsPtr->tkMacOSXSetDrawingEnabled) /* 52 */
#define TkpGetMS \
	(tkIntPlatStubsPtr->tkpGetMS) /* 53 */
#define TkMacOSXDrawable \
	(tkIntPlatStubsPtr->tkMacOSXDrawable) /* 54 */
#define TkpScanWindowId \
	(tkIntPlatStubsPtr->tkpScanWindowId) /* 55 */
#endif /* AQUA */
#if !(defined(_WIN32) || defined(__CYGWIN__) || defined(MAC_OSX_TK)) /* X11 */
#define TkCreateXEventSource \
	(tkIntPlatStubsPtr->tkCreateXEventSource) /* 0 */
/* Slot 1 is reserved */
#define TkGenerateActivateEvents \
	(tkIntPlatStubsPtr->tkGenerateActivateEvents) /* 2 */
/* Slot 3 is reserved */
/* Slot 4 is reserved */
/* Slot 5 is reserved */
#define TkpScanWindowId \
	(tkIntPlatStubsPtr->tkpScanWindowId) /* 6 */
/* Slot 7 is reserved */
/* Slot 8 is reserved */
#define TkpWmSetState \
	(tkIntPlatStubsPtr->tkpWmSetState) /* 9 */
/* Slot 10 is reserved */
/* Slot 11 is reserved */
/* Slot 12 is reserved */
/* Slot 2 is reserved */
/* Slot 13 is reserved */
/* Slot 14 is reserved */
/* Slot 15 is reserved */
/* Slot 16 is reserved */
/* Slot 17 is reserved */
/* Slot 18 is reserved */
/* Slot 19 is reserved */
/* Slot 20 is reserved */
/* Slot 21 is reserved */
/* Slot 22 is reserved */
/* Slot 23 is reserved */
/* Slot 24 is reserved */
/* Slot 25 is reserved */
/* Slot 26 is reserved */
/* Slot 27 is reserved */
/* Slot 28 is reserved */
/* Slot 29 is reserved */
/* Slot 30 is reserved */
/* Slot 31 is reserved */
/* Slot 32 is reserved */
/* Slot 33 is reserved */
/* Slot 34 is reserved */
/* Slot 35 is reserved */
/* Slot 36 is reserved */
/* Slot 37 is reserved */
#define TkpCmapStressed \
	(tkIntPlatStubsPtr->tkpCmapStressed) /* 38 */
	(tkIntPlatStubsPtr->tkpCmapStressed) /* 3 */
#define TkpSync \
	(tkIntPlatStubsPtr->tkpSync) /* 39 */
	(tkIntPlatStubsPtr->tkpSync) /* 4 */
#define TkUnixContainerId \
	(tkIntPlatStubsPtr->tkUnixContainerId) /* 40 */
	(tkIntPlatStubsPtr->tkUnixContainerId) /* 5 */
#define TkUnixDoOneXEvent \
	(tkIntPlatStubsPtr->tkUnixDoOneXEvent) /* 41 */
	(tkIntPlatStubsPtr->tkUnixDoOneXEvent) /* 6 */
#define TkUnixSetMenubar \
	(tkIntPlatStubsPtr->tkUnixSetMenubar) /* 42 */
	(tkIntPlatStubsPtr->tkUnixSetMenubar) /* 7 */
#define TkpScanWindowId \
	(tkIntPlatStubsPtr->tkpScanWindowId) /* 8 */
#define TkWmCleanup \
	(tkIntPlatStubsPtr->tkWmCleanup) /* 43 */
	(tkIntPlatStubsPtr->tkWmCleanup) /* 9 */
#define TkSendCleanup \
	(tkIntPlatStubsPtr->tkSendCleanup) /* 44 */
	(tkIntPlatStubsPtr->tkSendCleanup) /* 10 */
/* Slot 11 is reserved */
#define TkpWmSetState \
	(tkIntPlatStubsPtr->tkpWmSetState) /* 12 */
#define TkpTestsendCmd \
	(tkIntPlatStubsPtr->tkpTestsendCmd) /* 45 */
	(tkIntPlatStubsPtr->tkpTestsendCmd) /* 13 */
#endif /* X11 */

#endif /* defined(USE_TK_STUBS) */

/* !END!: Do not edit above this line. */

#ifndef TK_NO_DEPRECATED
#   define TkMacOSXDrawable Tk_MacOSXGetNSWindowForDrawable
#endif

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

#endif /* _TKINTPLATDECLS */

Changes to generic/tkIntXlibDecls.h.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29




30


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46




47
48
49
50
51
52
53








-
+




















+
+
+
+

+
+










-
-
-
-







/*
 * tkIntXlibDecls.h --
 *
 *	This file contains the declarations for all platform dependent
 *	unsupported functions that are exported by the Tk library.  These
 *	interfaces are not guaranteed to remain the same between
 *	versions.  Use at your own risk.
 *
 * Copyright (c) 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 * All rights reserved.
 */

#ifndef _TKINTXLIBDECLS
#define _TKINTXLIBDECLS

/*
 * WARNING: This file is automatically generated by the tools/genStubs.tcl
 * script.  Any modifications to the function declarations below should be made
 * in the generic/tkInt.decls script.
 */

#ifndef _TCL
#   include <tcl.h>
#endif

#ifndef EXTERN
#   define EXTERN extern TCL_STORAGE_CLASS
#endif

/* Some (older) versions of X11/Xutil.h have a wrong signature of those
   two functions, so move them out of the way temporarly. */
#define XOffsetRegion _XOffsetRegion
#define XUnionRegion _XUnionRegion
#include "X11/Xutil.h"
#undef XOffsetRegion
#undef XUnionRegion

#ifdef BUILD_tk
#  undef TCL_STORAGE_CLASS
#  define TCL_STORAGE_CLASS DLLEXPORT
#else
#  ifndef TCL_STORAGE_CLASS
#    define TCL_STORAGE_CLASS DLLIMPORT
#  endif
#endif

#if defined(MAC_OSX_TK) && !defined(MAC_OSX_TCL)
#  define MAC_OSX_TCL 1
#endif

typedef int (*XAfterFunction) (	    /* WARNING, this type not in Xlib spec */
    Display*		/* display */
);

/* !BEGIN!: Do not edit below this line. */

#ifdef __cplusplus
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294
279
280
281
282
283
284
285

286



287
288
289
290
291
292
293







-
+
-
-
-







				char *c, int i, KeySym *k, Status *s);
/* 80 */
EXTERN int		TkPutImage(unsigned long *colors, int ncolors,
				Display *display, Drawable d, GC gc,
				XImage *image, int src_x, int src_y,
				int dest_x, int dest_y, unsigned int width,
				unsigned int height);
/* 81 */
/* Slot 81 is reserved */
EXTERN int		XSetClipRectangles(Display *display, GC gc,
				int clip_x_origin, int clip_y_origin,
				XRectangle rectangles[], int n, int ordering);
/* 82 */
EXTERN Status		XParseColor(Display *display, Colormap map,
				_Xconst char *spec, XColor *colorPtr);
/* 83 */
EXTERN GC		XCreateGC(Display *display, Drawable d,
				unsigned long valuemask, XGCValues *values);
/* 84 */
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486
417
418
419
420
421
422
423





















































424

425
426
427
428
429
430
431
432







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







/* 136 */
EXTERN int		XReparentWindow(Display *d, Window w, Window p,
				int x, int y);
/* 137 */
EXTERN int		XPutImage(Display *d, Drawable dr, GC gc, XImage *im,
				int sx, int sy, int dx, int dy,
				unsigned int w, unsigned int h);
/* 138 */
EXTERN Region		XPolygonRegion(XPoint *pts, int n, int rule);
/* 139 */
EXTERN int		XPointInRegion(Region rgn, int x, int y);
/* 140 */
EXTERN XVaNestedList	XVaCreateNestedList(int dummy, ...);
/* 141 */
EXTERN char *		XSetICValues(XIC xic, ...);
/* 142 */
EXTERN char *		XGetICValues(XIC xic, ...);
/* 143 */
EXTERN void		XSetICFocus(XIC xic);
/* Slot 144 is reserved */
/* Slot 145 is reserved */
/* Slot 146 is reserved */
/* 147 */
EXTERN void		XFreeFontSet(Display *display, XFontSet fontset);
/* 148 */
EXTERN int		XCloseIM(XIM im);
/* 149 */
EXTERN Bool		XRegisterIMInstantiateCallback(Display *dpy,
				struct _XrmHashBucketRec *rbd,
				char *res_name, char *res_class,
				XIDProc callback, XPointer client_data);
/* 150 */
EXTERN Bool		XUnregisterIMInstantiateCallback(Display *dpy,
				struct _XrmHashBucketRec *rbd,
				char *res_name, char *res_class,
				XIDProc callback, XPointer client_data);
/* 151 */
EXTERN char *		XSetLocaleModifiers(const char *modifier_list);
/* 152 */
EXTERN XIM		XOpenIM(Display *dpy, struct _XrmHashBucketRec *rdb,
				char *res_name, char *res_class);
/* 153 */
EXTERN char *		XGetIMValues(XIM im, ...);
/* 154 */
EXTERN char *		XSetIMValues(XIM im, ...);
/* 155 */
EXTERN XFontSet		XCreateFontSet(Display *display,
				_Xconst char *base_font_name_list,
				char ***missing_charset_list,
				int *missing_charset_count,
				char **def_string);
/* 156 */
EXTERN void		XFreeStringList(char **list);
/* 157 */
EXTERN KeySym		XkbKeycodeToKeysym(Display *d, unsigned int k, int g,
				int i);
/* 158 */
EXTERN Display *	XkbOpenDisplay(const char *name, int *ev_rtrn,
				int *err_rtrn, int *major_rtrn,
				int *minor_rtrn, int *reason);
#endif /* WIN */
#ifdef MAC_OSX_TCL /* MACOSX */
#ifdef MAC_OSX_TK /* AQUA */
/* 0 */
EXTERN int		XSetDashes(Display *display, GC gc, int dash_offset,
				_Xconst char *dash_list, int n);
/* 1 */
EXTERN XModifierKeymap * XGetModifierMapping(Display *d);
/* 2 */
EXTERN XImage *		XCreateImage(Display *d, Visual *v, unsigned int ui1,
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510

511
512
513
514


515
516

517
518

519
520

521
522
523
524
525
526
527
528
529

530
531
532


533
534
535
536


537
538

539
540
541

542
543
544


545
546
547
548


549
550
551
552

553
554
555
556

557
558

559
560
561
562
563



564
565
566

567
568
569
570


571
572
573


574
575
576
577


578
579

580
581
582

583
584
585
586

587
588
589

590
591
592
593

594
595
596
597
598

599
600
601
602
603
604
605

606
607
608
609
610
611

612
613
614
615

616
617

618
619
620
621
622
623



624
625
626
627



628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646





647
648
649
650



651
652
653

654
655
656
657
658
659




660
661
662
663


664
665
666


667
668
669


670
671
672


673
674
675


676
677
678
679



680
681
682
683
684
685


686
687
688
689



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711

712
713
714

715
716

717
718
719

720
721
722

723
724
725

726
727

728
729
730

731
732
733

734
735
736

737
738

739
740

741
742

743
744

745
746
747

748
749

750
751
752
753

754
755
756
757



758
759
760
761

762
763
764

765
766
767






768
769
770

771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820


821
822
823
824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844







845
846
847
848

849
850
851


852
853
854
855
856
857
858
859
860
861
862


863
864

865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

885
886
887
888
889
890



891
892

893
894
895


896
897
898

899
900
901
902
903
904
905
440
441
442
443
444
445
446








447

448




449
450
451

452
453

454
455

456







457

458
459


460
461
462
463


464
465
466

467



468
469


470
471
472
473


474
475
476
477
478

479
480
481
482

483
484

485





486
487
488
489
490

491
492
493


494
495
496


497
498
499
500


501
502
503

504
505
506

507


508

509
510
511

512


513

514
515
516
517
518

519


520
521
522
523

524



525
526

527
528
529
530

531
532

533






534
535
536
537



538
539
540







541
542
543

544








545
546
547
548
549
550



551
552
553
554
555

556






557
558
559
560
561
562


563
564
565


566
567
568


569
570
571


572
573
574


575
576
577



578
579
580






581
582
583



584
585
586









587
588
589
590
591

592




593
594

595
596
597

598
599

600
601
602

603
604
605

606
607
608

609
610

611
612
613

614
615
616

617
618
619

620
621

622
623

624
625

626
627

628
629
630

631
632

633
634
635
636

637
638



639
640
641
642
643
644

645
646
647

648
649
650

651
652
653
654
655
656
657
658

659




660
661
662

663










































664
665













666






667




668
669
670
671
672
673
674




675



676
677











678
679


680




















681






682
683
684


685



686
687



688
689
690
691
692
693
694
695







-
-
-
-
-
-
-
-

-
+
-
-
-
-
+
+

-
+

-
+

-
+
-
-
-
-
-
-
-

-
+

-
-
+
+


-
-
+
+

-
+
-
-
-
+

-
-
+
+


-
-
+
+



-
+



-
+

-
+
-
-
-
-
-
+
+
+


-
+


-
-
+
+

-
-
+
+


-
-
+
+

-
+


-
+
-
-

-
+


-
+
-
-

-
+




-
+
-
-




-
+
-
-
-


-
+



-
+

-
+
-
-
-
-
-
-
+
+
+

-
-
-
+
+
+
-
-
-
-
-
-
-



-
+
-
-
-
-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+


-
+
-
-
-
-
-
-
+
+
+
+


-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
-
+
+
+
-
-
-
-
-
-
+
+

-
-
-
+
+
+
-
-
-
-
-
-
-
-
-





-
+
-
-
-
-


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+

-
+

-
+

-
+


-
+

-
+



-
+

-
-
-
+
+
+



-
+


-
+


-
+
+
+
+
+
+


-
+
-
-
-
-



-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-

-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
+
+
-
-
-
+







EXTERN char *		XGetAtomName(Display *d, Atom a);
/* 5 */
EXTERN char *		XKeysymToString(KeySym k);
/* 6 */
EXTERN Colormap		XCreateColormap(Display *d, Window w, Visual *v,
				int i);
/* 7 */
EXTERN Cursor		XCreatePixmapCursor(Display *d, Pixmap p1, Pixmap p2,
				XColor *x1, XColor *x2, unsigned int ui1,
				unsigned int ui2);
/* 8 */
EXTERN Cursor		XCreateGlyphCursor(Display *d, Font f1, Font f2,
				unsigned int ui1, unsigned int ui2,
				XColor _Xconst *x1, XColor _Xconst *x2);
/* 9 */
EXTERN GContext		XGContextFromGC(GC g);
/* 10 */
/* 8 */
EXTERN XHostAddress *	XListHosts(Display *d, int *i, Bool *b);
/* 11 */
EXTERN KeySym		XKeycodeToKeysym(Display *d, unsigned int k, int i);
/* 12 */
EXTERN KeySym		XKeycodeToKeysym(Display *d, KeyCode k, int i);
/* 9 */
EXTERN KeySym		XStringToKeysym(_Xconst char *c);
/* 13 */
/* 10 */
EXTERN Window		XRootWindow(Display *d, int i);
/* 14 */
/* 11 */
EXTERN XErrorHandler	XSetErrorHandler(XErrorHandler x);
/* 15 */
/* 12 */
EXTERN Status		XIconifyWindow(Display *d, Window w, int i);
/* 16 */
EXTERN Status		XWithdrawWindow(Display *d, Window w, int i);
/* 17 */
EXTERN Status		XGetWMColormapWindows(Display *d, Window w,
				Window **wpp, int *ip);
/* 18 */
EXTERN Status		XAllocColor(Display *d, Colormap c, XColor *xp);
/* 19 */
/* 13 */
EXTERN int		XBell(Display *d, int i);
/* 20 */
EXTERN int		XChangeProperty(Display *d, Window w, Atom a1,
/* 14 */
EXTERN void		XChangeProperty(Display *d, Window w, Atom a1,
				Atom a2, int i1, int i2,
				_Xconst unsigned char *c, int i3);
/* 21 */
EXTERN int		XChangeWindowAttributes(Display *d, Window w,
/* 15 */
EXTERN void		XChangeWindowAttributes(Display *d, Window w,
				unsigned long ul, XSetWindowAttributes *x);
/* 22 */
/* 16 */
EXTERN int		XClearWindow(Display *d, Window w);
/* 23 */
EXTERN int		XConfigureWindow(Display *d, Window w,
EXTERN void		XConfigureWindow(Display *d, Window w,
				unsigned int i, XWindowChanges *x);
/* 24 */
EXTERN int		XCopyArea(Display *d, Drawable dr1, Drawable dr2,
/* 17 */
EXTERN void		XCopyArea(Display *d, Drawable dr1, Drawable dr2,
				GC g, int i1, int i2, unsigned int ui1,
				unsigned int ui2, int i3, int i4);
/* 25 */
EXTERN int		XCopyPlane(Display *d, Drawable dr1, Drawable dr2,
/* 18 */
EXTERN void		XCopyPlane(Display *d, Drawable dr1, Drawable dr2,
				GC g, int i1, int i2, unsigned int ui1,
				unsigned int ui2, int i3, int i4,
				unsigned long ul);
/* 26 */
/* 19 */
EXTERN Pixmap		XCreateBitmapFromData(Display *display, Drawable d,
				_Xconst char *data, unsigned int width,
				unsigned int height);
/* 27 */
/* 20 */
EXTERN int		XDefineCursor(Display *d, Window w, Cursor c);
/* 28 */
/* 21 */
EXTERN int		XDeleteProperty(Display *d, Window w, Atom a);
/* 29 */
EXTERN int		XDestroyWindow(Display *d, Window w);
/* 30 */
EXTERN int		XDrawArc(Display *d, Drawable dr, GC g, int i1,
EXTERN void		XDestroyWindow(Display *d, Window w);
/* 22 */
EXTERN void		XDrawArc(Display *d, Drawable dr, GC g, int i1,
				int i2, unsigned int ui1, unsigned int ui2,
				int i3, int i4);
/* 31 */
/* 23 */
EXTERN int		XDrawLines(Display *d, Drawable dr, GC g, XPoint *x,
				int i1, int i2);
/* 32 */
EXTERN int		XDrawRectangle(Display *d, Drawable dr, GC g, int i1,
/* 24 */
EXTERN void		XDrawRectangle(Display *d, Drawable dr, GC g, int i1,
				int i2, unsigned int ui1, unsigned int ui2);
/* 33 */
EXTERN int		XFillArc(Display *d, Drawable dr, GC g, int i1,
/* 25 */
EXTERN void		XFillArc(Display *d, Drawable dr, GC g, int i1,
				int i2, unsigned int ui1, unsigned int ui2,
				int i3, int i4);
/* 34 */
EXTERN int		XFillPolygon(Display *d, Drawable dr, GC g,
/* 26 */
EXTERN void		XFillPolygon(Display *d, Drawable dr, GC g,
				XPoint *x, int i1, int i2, int i3);
/* 35 */
/* 27 */
EXTERN int		XFillRectangles(Display *d, Drawable dr, GC g,
				XRectangle *x, int i);
/* 36 */
/* 28 */
EXTERN int		XForceScreenSaver(Display *d, int i);
/* 37 */
EXTERN int		XFreeColormap(Display *d, Colormap c);
/* 38 */
/* 29 */
EXTERN int		XFreeColors(Display *d, Colormap c,
				unsigned long *ulp, int i, unsigned long ul);
/* 39 */
/* 30 */
EXTERN int		XFreeCursor(Display *d, Cursor c);
/* 40 */
EXTERN int		XFreeModifiermap(XModifierKeymap *x);
/* 41 */
/* 31 */
EXTERN Status		XGetGeometry(Display *d, Drawable dr, Window *w,
				int *i1, int *i2, unsigned int *ui1,
				unsigned int *ui2, unsigned int *ui3,
				unsigned int *ui4);
/* 42 */
/* 32 */
EXTERN int		XGetInputFocus(Display *d, Window *w, int *i);
/* 43 */
EXTERN int		XGetWindowProperty(Display *d, Window w, Atom a1,
				long l1, long l2, Bool b, Atom a2, Atom *ap,
				int *ip, unsigned long *ulp1,
				unsigned long *ulp2, unsigned char **cpp);
/* 44 */
/* 33 */
EXTERN Status		XGetWindowAttributes(Display *d, Window w,
				XWindowAttributes *x);
/* 45 */
EXTERN int		XGrabKeyboard(Display *d, Window w, Bool b, int i1,
				int i2, Time t);
/* 46 */
/* 34 */
EXTERN int		XGrabPointer(Display *d, Window w1, Bool b,
				unsigned int ui, int i1, int i2, Window w2,
				Cursor c, Time t);
/* 47 */
/* 35 */
EXTERN KeyCode		XKeysymToKeycode(Display *d, KeySym k);
/* 48 */
/* 36 */
EXTERN Status		XLookupColor(Display *d, Colormap c1,
				_Xconst char *c2, XColor *x1, XColor *x2);
/* 49 */
EXTERN int		XMapWindow(Display *d, Window w);
/* 50 */
EXTERN int		XMoveResizeWindow(Display *d, Window w, int i1,
EXTERN void		XMapWindow(Display *d, Window w);
/* 37 */
EXTERN void		XMoveResizeWindow(Display *d, Window w, int i1,
				int i2, unsigned int ui1, unsigned int ui2);
/* 51 */
EXTERN int		XMoveWindow(Display *d, Window w, int i1, int i2);
/* 52 */
/* 38 */
EXTERN void		XMoveWindow(Display *d, Window w, int i1, int i2);
/* 39 */
EXTERN int		XNextEvent(Display *d, XEvent *x);
/* 53 */
EXTERN int		XPutBackEvent(Display *d, XEvent *x);
/* 54 */
EXTERN int		XQueryColors(Display *d, Colormap c, XColor *x,
				int i);
/* 55 */
EXTERN Bool		XQueryPointer(Display *d, Window w1, Window *w2,
				Window *w3, int *i1, int *i2, int *i3,
				int *i4, unsigned int *ui);
/* 56 */
/* 40 */
EXTERN Status		XQueryTree(Display *d, Window w1, Window *w2,
				Window *w3, Window **w4, unsigned int *ui);
/* 57 */
EXTERN int		XRaiseWindow(Display *d, Window w);
/* 58 */
EXTERN int		XRefreshKeyboardMapping(XMappingEvent *x);
/* 59 */
EXTERN int		XResizeWindow(Display *d, Window w, unsigned int ui1,
EXTERN void		XRaiseWindow(Display *d, Window w);
/* 41 */
EXTERN void		XRefreshKeyboardMapping(XMappingEvent *x);
/* 42 */
EXTERN void		XResizeWindow(Display *d, Window w, unsigned int ui1,
				unsigned int ui2);
/* 60 */
EXTERN int		XSelectInput(Display *d, Window w, long l);
/* 61 */
/* 43 */
EXTERN void		XSelectInput(Display *d, Window w, long l);
/* 44 */
EXTERN Status		XSendEvent(Display *d, Window w, Bool b, long l,
				XEvent *x);
/* 62 */
/* 45 */
EXTERN int		XSetCommand(Display *d, Window w, char **c, int i);
/* 63 */
EXTERN int		XSetIconName(Display *d, Window w, _Xconst char *c);
/* 64 */
EXTERN int		XSetInputFocus(Display *d, Window w, int i, Time t);
/* 65 */
EXTERN void		XSetIconName(Display *d, Window w, _Xconst char *c);
/* 46 */
EXTERN void		XSetInputFocus(Display *d, Window w, int i, Time t);
/* 47 */
EXTERN int		XSetSelectionOwner(Display *d, Atom a, Window w,
				Time t);
/* 66 */
EXTERN int		XSetWindowBackground(Display *d, Window w,
/* 48 */
EXTERN void		XSetWindowBackground(Display *d, Window w,
				unsigned long ul);
/* 67 */
EXTERN int		XSetWindowBackgroundPixmap(Display *d, Window w,
/* 49 */
EXTERN void		XSetWindowBackgroundPixmap(Display *d, Window w,
				Pixmap p);
/* 68 */
EXTERN int		XSetWindowBorder(Display *d, Window w,
/* 50 */
EXTERN void		XSetWindowBorder(Display *d, Window w,
				unsigned long ul);
/* 69 */
EXTERN int		XSetWindowBorderPixmap(Display *d, Window w,
/* 51 */
EXTERN void		XSetWindowBorderPixmap(Display *d, Window w,
				Pixmap p);
/* 70 */
EXTERN int		XSetWindowBorderWidth(Display *d, Window w,
/* 52 */
EXTERN void		XSetWindowBorderWidth(Display *d, Window w,
				unsigned int ui);
/* 71 */
EXTERN int		XSetWindowColormap(Display *d, Window w, Colormap c);
/* 72 */
/* 53 */
EXTERN void		XSetWindowColormap(Display *d, Window w, Colormap c);
/* 54 */
EXTERN Bool		XTranslateCoordinates(Display *d, Window w1,
				Window w2, int i1, int i2, int *i3, int *i4,
				Window *w3);
/* 73 */
EXTERN int		XUngrabKeyboard(Display *d, Time t);
/* 74 */
EXTERN void		XUngrabKeyboard(Display *d, Time t);
/* 55 */
EXTERN int		XUngrabPointer(Display *d, Time t);
/* 75 */
EXTERN int		XUnmapWindow(Display *d, Window w);
/* 76 */
/* 56 */
EXTERN void		XUnmapWindow(Display *d, Window w);
/* 57 */
EXTERN int		XWindowEvent(Display *d, Window w, long l, XEvent *x);
/* 77 */
EXTERN void		XDestroyIC(XIC x);
/* 78 */
EXTERN Bool		XFilterEvent(XEvent *x, Window w);
/* 79 */
EXTERN int		XmbLookupString(XIC xi, XKeyPressedEvent *xk,
				char *c, int i, KeySym *k, Status *s);
/* 80 */
EXTERN int		TkPutImage(unsigned long *colors, int ncolors,
				Display *display, Drawable d, GC gc,
				XImage *image, int src_x, int src_y,
				int dest_x, int dest_y, unsigned int width,
				unsigned int height);
/* 81 */
/* 58 */
EXTERN int		XSetClipRectangles(Display *display, GC gc,
				int clip_x_origin, int clip_y_origin,
				XRectangle rectangles[], int n, int ordering);
/* 82 */
EXTERN Status		XParseColor(Display *display, Colormap map,
				_Xconst char *spec, XColor *colorPtr);
/* 83 */
/* 59 */
EXTERN GC		XCreateGC(Display *display, Drawable d,
				unsigned long valuemask, XGCValues *values);
/* 84 */
/* 60 */
EXTERN int		XFreeGC(Display *display, GC gc);
/* 85 */
/* 61 */
EXTERN Atom		XInternAtom(Display *display,
				_Xconst char *atom_name, Bool only_if_exists);
/* 86 */
/* 62 */
EXTERN int		XSetBackground(Display *display, GC gc,
				unsigned long foreground);
/* 87 */
/* 63 */
EXTERN int		XSetForeground(Display *display, GC gc,
				unsigned long foreground);
/* 88 */
/* 64 */
EXTERN int		XSetClipMask(Display *display, GC gc, Pixmap pixmap);
/* 89 */
/* 65 */
EXTERN int		XSetClipOrigin(Display *display, GC gc,
				int clip_x_origin, int clip_y_origin);
/* 90 */
/* 66 */
EXTERN int		XSetTSOrigin(Display *display, GC gc,
				int ts_x_origin, int ts_y_origin);
/* 91 */
/* 67 */
EXTERN int		XChangeGC(Display *d, GC gc, unsigned long mask,
				XGCValues *values);
/* 92 */
/* 68 */
EXTERN int		XSetFont(Display *display, GC gc, Font font);
/* 93 */
/* 69 */
EXTERN int		XSetArcMode(Display *display, GC gc, int arc_mode);
/* 94 */
/* 70 */
EXTERN int		XSetStipple(Display *display, GC gc, Pixmap stipple);
/* 95 */
/* 71 */
EXTERN int		XSetFillRule(Display *display, GC gc, int fill_rule);
/* 96 */
/* 72 */
EXTERN int		XSetFillStyle(Display *display, GC gc,
				int fill_style);
/* 97 */
/* 73 */
EXTERN int		XSetFunction(Display *display, GC gc, int function);
/* 98 */
/* 74 */
EXTERN int		XSetLineAttributes(Display *display, GC gc,
				unsigned int line_width, int line_style,
				int cap_style, int join_style);
/* 99 */
/* 75 */
EXTERN int		_XInitImageFuncPtrs(XImage *image);
/* 100 */
EXTERN XIC		XCreateIC(XIM xim, ...);
/* 101 */
/* 76 */
EXTERN XIC		XCreateIC(void);
/* 77 */
EXTERN XVisualInfo *	XGetVisualInfo(Display *display, long vinfo_mask,
				XVisualInfo *vinfo_template,
				int *nitems_return);
/* 102 */
/* 78 */
EXTERN void		XSetWMClientMachine(Display *display, Window w,
				XTextProperty *text_prop);
/* 103 */
/* 79 */
EXTERN Status		XStringListToTextProperty(char **list, int count,
				XTextProperty *text_prop_return);
/* 104 */
/* 80 */
EXTERN int		XDrawSegments(Display *display, Drawable d, GC gc,
				XSegment *segments, int nsegments);
/* 81 */
EXTERN void		XForceScreenSaver(Display *display, int mode);
/* 82 */
EXTERN int		XDrawLine(Display *d, Drawable dr, GC g, int x1,
				int y1, int x2, int y2);
/* 105 */
/* 83 */
EXTERN int		XWarpPointer(Display *d, Window s, Window dw, int sx,
				int sy, unsigned int sw, unsigned int sh,
				int dx, int dy);
/* 106 */
EXTERN int		XFillRectangle(Display *display, Drawable d, GC gc,
				int x, int y, unsigned int width,
				unsigned int height);
/* 107 */
/* 84 */
EXTERN int		XFlush(Display *display);
/* 108 */
EXTERN int		XGrabServer(Display *display);
/* 109 */
EXTERN int		XUngrabServer(Display *display);
/* 110 */
EXTERN int		XFree(void *data);
/* 111 */
EXTERN int		XNoOp(Display *display);
/* 112 */
EXTERN XAfterFunction	XSynchronize(Display *display, Bool onoff);
/* 113 */
EXTERN int		XSync(Display *display, Bool discard);
/* 114 */
EXTERN VisualID		XVisualIDFromVisual(Visual *visual);
/* Slot 115 is reserved */
/* Slot 116 is reserved */
/* Slot 117 is reserved */
/* Slot 118 is reserved */
/* Slot 119 is reserved */
/* 120 */
EXTERN int		XOffsetRegion(Region rgn, int dx, int dy);
/* 121 */
EXTERN int		XUnionRegion(Region srca, Region srcb,
				Region dr_return);
/* 122 */
EXTERN Window		XCreateWindow(Display *display, Window parent, int x,
				int y, unsigned int width,
				unsigned int height,
				unsigned int border_width, int depth,
				unsigned int clazz, Visual *visual,
				unsigned long value_mask,
				XSetWindowAttributes *attributes);
/* Slot 123 is reserved */
/* Slot 124 is reserved */
/* Slot 125 is reserved */
/* Slot 126 is reserved */
/* Slot 127 is reserved */
/* Slot 128 is reserved */
/* 129 */
EXTERN int		XLowerWindow(Display *d, Window w);
/* 130 */
EXTERN void		XClearWindow(Display *d, Window w);
/* 85 */
EXTERN int		XFillArcs(Display *d, Drawable dr, GC gc, XArc *a,
				int n);
/* 131 */
EXTERN int		XDrawArcs(Display *d, Drawable dr, GC gc, XArc *a,
				int n);
/* 132 */
EXTERN int		XDrawRectangles(Display *d, Drawable dr, GC gc,
				XRectangle *r, int n);
/* 133 */
EXTERN int		XDrawSegments(Display *d, Drawable dr, GC gc,
				XSegment *s, int n);
/* 134 */
EXTERN int		XDrawPoint(Display *d, Drawable dr, GC gc, int x,
EXTERN int		XDrawPoint(Display *display, Drawable d, GC gc,
				int y);
/* 135 */
EXTERN int		XDrawPoints(Display *d, Drawable dr, GC gc,
				XPoint *p, int n, int m);
/* 136 */
EXTERN int		XReparentWindow(Display *d, Window w, Window p,
				int x, int y);
/* 137 */
EXTERN int		XPutImage(Display *d, Drawable dr, GC gc, XImage *im,
				int sx, int sy, int dx, int dy,
				unsigned int w, unsigned int h);
/* 86 */
EXTERN int		XDrawPoints(Display *display, Drawable d, GC gc,
				XPoint *points, int npoints, int mode);
/* 87 */
EXTERN int		XWarpPointer(Display *display, Window src_w,
				Window dest_w, int src_x, int src_y,
				unsigned int src_width,
/* 138 */
EXTERN Region		XPolygonRegion(XPoint *pts, int n, int rule);
/* 139 */
EXTERN int		XPointInRegion(Region rgn, int x, int y);
				unsigned int src_height, int dest_x,
/* 140 */
EXTERN XVaNestedList	XVaCreateNestedList(int dummy, ...);
/* 141 */
				int dest_y);
/* 88 */
EXTERN char *		XSetICValues(XIC xic, ...);
/* 142 */
EXTERN char *		XGetICValues(XIC xic, ...);
/* 143 */
EXTERN void		XSetICFocus(XIC xic);
/* Slot 144 is reserved */
/* Slot 145 is reserved */
/* Slot 146 is reserved */
/* 147 */
EXTERN void		XFreeFontSet(Display *display, XFontSet fontset);
/* 148 */
EXTERN void		XQueryColor(Display *display, Colormap colormap,
				XColor *def_in_out);
EXTERN int		XCloseIM(XIM im);
/* 149 */
/* 89 */
EXTERN Bool		XRegisterIMInstantiateCallback(Display *dpy,
				struct _XrmHashBucketRec *rbd,
				char *res_name, char *res_class,
				XIDProc callback, XPointer client_data);
/* 150 */
EXTERN Bool		XUnregisterIMInstantiateCallback(Display *dpy,
				struct _XrmHashBucketRec *rbd,
				char *res_name, char *res_class,
				XIDProc callback, XPointer client_data);
/* 151 */
EXTERN char *		XSetLocaleModifiers(const char *modifier_list);
/* 152 */
EXTERN XIM		XOpenIM(Display *dpy, struct _XrmHashBucketRec *rdb,
				char *res_name, char *res_class);
/* 153 */
EXTERN char *		XGetIMValues(XIM im, ...);
/* 154 */
EXTERN char *		XSetIMValues(XIM im, ...);
/* 155 */
EXTERN XFontSet		XCreateFontSet(Display *display,
EXTERN void		XQueryColors(Display *display, Colormap colormap,
				_Xconst char *base_font_name_list,
				char ***missing_charset_list,
				int *missing_charset_count,
				char **def_string);
/* 156 */
EXTERN void		XFreeStringList(char **list);
				XColor *defs_in_out, int ncolors);
/* 90 */
EXTERN Status		XQueryTree(Display *d, Window w1, Window *w2,
/* 157 */
EXTERN KeySym		XkbKeycodeToKeysym(Display *d, unsigned int k, int g,
				Window *w3, Window **w4, unsigned int *ui);
				int i);
/* 158 */
EXTERN Display *	XkbOpenDisplay(const char *name, int *ev_rtrn,
/* 91 */
EXTERN int		XSync(Display *display, Bool flag);
				int *err_rtrn, int *major_rtrn,
				int *minor_rtrn, int *reason);
#endif /* MACOSX */
#endif /* AQUA */

typedef struct TkIntXlibStubs {
    int magic;
    void *hooks;

#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
    int (*xSetDashes) (Display *display, GC gc, int dash_offset, _Xconst char *dash_list, int n); /* 0 */
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
769
770
771
772
773
774
775

776
777
778
779
780
781
782
783







-
+







    int (*xUngrabPointer) (Display *d, Time t); /* 74 */
    int (*xUnmapWindow) (Display *d, Window w); /* 75 */
    int (*xWindowEvent) (Display *d, Window w, long l, XEvent *x); /* 76 */
    void (*xDestroyIC) (XIC x); /* 77 */
    Bool (*xFilterEvent) (XEvent *x, Window w); /* 78 */
    int (*xmbLookupString) (XIC xi, XKeyPressedEvent *xk, char *c, int i, KeySym *k, Status *s); /* 79 */
    int (*tkPutImage) (unsigned long *colors, int ncolors, Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); /* 80 */
    int (*xSetClipRectangles) (Display *display, GC gc, int clip_x_origin, int clip_y_origin, XRectangle rectangles[], int n, int ordering); /* 81 */
    void (*reserved81)(void);
    Status (*xParseColor) (Display *display, Colormap map, _Xconst char *spec, XColor *colorPtr); /* 82 */
    GC (*xCreateGC) (Display *display, Drawable d, unsigned long valuemask, XGCValues *values); /* 83 */
    int (*xFreeGC) (Display *display, GC gc); /* 84 */
    Atom (*xInternAtom) (Display *display, _Xconst char *atom_name, Bool only_if_exists); /* 85 */
    int (*xSetBackground) (Display *display, GC gc, unsigned long foreground); /* 86 */
    int (*xSetForeground) (Display *display, GC gc, unsigned long foreground); /* 87 */
    int (*xSetClipMask) (Display *display, GC gc, Pixmap pixmap); /* 88 */
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075

1076
1077
1078
1079
1080




1081
1082
1083
1084
1085
1086
1087




1088
1089
1090
1091
1092
1093





1094
1095
1096
1097
1098
1099
1100
1101







1102
1103
1104


1105
1106
1107


1108
1109

1110
1111
1112
1113



1114
1115
1116
1117



1118
1119
1120
1121

1122
1123
1124
1125
1126
1127





1128
1129
1130
1131
1132
1133
1134
1135
1136
1137









1138
1139
1140
1141



1142
1143
1144
1145
1146

1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166



















1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189



1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202








1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213

1214
1215
1216
1217
1218

1219
1220
1221

1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
826
827
828
829
830
831
832





















833

834
835
836
837
838
839
840
841



842





843
844
845
846







847
848
849
850






851
852
853
854
855








856
857
858
859
860
861
862



863
864



865
866


867




868
869
870




871
872
873




874






875
876
877
878
879










880
881
882
883
884
885
886
887
888




889
890
891





892




















893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911























912
913
914













915
916
917
918
919
920
921
922







923




924





925



926




927
928
929
930
931
932
933
934







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







-
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+







    int (*xDrawArcs) (Display *d, Drawable dr, GC gc, XArc *a, int n); /* 131 */
    int (*xDrawRectangles) (Display *d, Drawable dr, GC gc, XRectangle *r, int n); /* 132 */
    int (*xDrawSegments) (Display *d, Drawable dr, GC gc, XSegment *s, int n); /* 133 */
    int (*xDrawPoint) (Display *d, Drawable dr, GC gc, int x, int y); /* 134 */
    int (*xDrawPoints) (Display *d, Drawable dr, GC gc, XPoint *p, int n, int m); /* 135 */
    int (*xReparentWindow) (Display *d, Window w, Window p, int x, int y); /* 136 */
    int (*xPutImage) (Display *d, Drawable dr, GC gc, XImage *im, int sx, int sy, int dx, int dy, unsigned int w, unsigned int h); /* 137 */
    Region (*xPolygonRegion) (XPoint *pts, int n, int rule); /* 138 */
    int (*xPointInRegion) (Region rgn, int x, int y); /* 139 */
    XVaNestedList (*xVaCreateNestedList) (int dummy, ...); /* 140 */
    char * (*xSetICValues) (XIC xic, ...); /* 141 */
    char * (*xGetICValues) (XIC xic, ...); /* 142 */
    void (*xSetICFocus) (XIC xic); /* 143 */
    void (*reserved144)(void);
    void (*reserved145)(void);
    void (*reserved146)(void);
    void (*xFreeFontSet) (Display *display, XFontSet fontset); /* 147 */
    int (*xCloseIM) (XIM im); /* 148 */
    Bool (*xRegisterIMInstantiateCallback) (Display *dpy, struct _XrmHashBucketRec *rbd, char *res_name, char *res_class, XIDProc callback, XPointer client_data); /* 149 */
    Bool (*xUnregisterIMInstantiateCallback) (Display *dpy, struct _XrmHashBucketRec *rbd, char *res_name, char *res_class, XIDProc callback, XPointer client_data); /* 150 */
    char * (*xSetLocaleModifiers) (const char *modifier_list); /* 151 */
    XIM (*xOpenIM) (Display *dpy, struct _XrmHashBucketRec *rdb, char *res_name, char *res_class); /* 152 */
    char * (*xGetIMValues) (XIM im, ...); /* 153 */
    char * (*xSetIMValues) (XIM im, ...); /* 154 */
    XFontSet (*xCreateFontSet) (Display *display, _Xconst char *base_font_name_list, char ***missing_charset_list, int *missing_charset_count, char **def_string); /* 155 */
    void (*xFreeStringList) (char **list); /* 156 */
    KeySym (*xkbKeycodeToKeysym) (Display *d, unsigned int k, int g, int i); /* 157 */
    Display * (*xkbOpenDisplay) (const char *name, int *ev_rtrn, int *err_rtrn, int *major_rtrn, int *minor_rtrn, int *reason); /* 158 */
#endif /* WIN */
#ifdef MAC_OSX_TCL /* MACOSX */
#ifdef MAC_OSX_TK /* AQUA */
    int (*xSetDashes) (Display *display, GC gc, int dash_offset, _Xconst char *dash_list, int n); /* 0 */
    XModifierKeymap * (*xGetModifierMapping) (Display *d); /* 1 */
    XImage * (*xCreateImage) (Display *d, Visual *v, unsigned int ui1, int i1, int i2, char *cp, unsigned int ui2, unsigned int ui3, int i3, int i4); /* 2 */
    XImage * (*xGetImage) (Display *d, Drawable dr, int i1, int i2, unsigned int ui1, unsigned int ui2, unsigned long ul, int i3); /* 3 */
    char * (*xGetAtomName) (Display *d, Atom a); /* 4 */
    char * (*xKeysymToString) (KeySym k); /* 5 */
    Colormap (*xCreateColormap) (Display *d, Window w, Visual *v, int i); /* 6 */
    Cursor (*xCreatePixmapCursor) (Display *d, Pixmap p1, Pixmap p2, XColor *x1, XColor *x2, unsigned int ui1, unsigned int ui2); /* 7 */
    Cursor (*xCreateGlyphCursor) (Display *d, Font f1, Font f2, unsigned int ui1, unsigned int ui2, XColor _Xconst *x1, XColor _Xconst *x2); /* 8 */
    GContext (*xGContextFromGC) (GC g); /* 9 */
    GContext (*xGContextFromGC) (GC g); /* 7 */
    XHostAddress * (*xListHosts) (Display *d, int *i, Bool *b); /* 10 */
    KeySym (*xKeycodeToKeysym) (Display *d, unsigned int k, int i); /* 11 */
    KeySym (*xStringToKeysym) (_Xconst char *c); /* 12 */
    Window (*xRootWindow) (Display *d, int i); /* 13 */
    XErrorHandler (*xSetErrorHandler) (XErrorHandler x); /* 14 */
    KeySym (*xKeycodeToKeysym) (Display *d, KeyCode k, int i); /* 8 */
    KeySym (*xStringToKeysym) (_Xconst char *c); /* 9 */
    Window (*xRootWindow) (Display *d, int i); /* 10 */
    XErrorHandler (*xSetErrorHandler) (XErrorHandler x); /* 11 */
    Status (*xIconifyWindow) (Display *d, Window w, int i); /* 15 */
    Status (*xWithdrawWindow) (Display *d, Window w, int i); /* 16 */
    Status (*xGetWMColormapWindows) (Display *d, Window w, Window **wpp, int *ip); /* 17 */
    Status (*xAllocColor) (Display *d, Colormap c, XColor *xp); /* 18 */
    int (*xBell) (Display *d, int i); /* 19 */
    int (*xChangeProperty) (Display *d, Window w, Atom a1, Atom a2, int i1, int i2, _Xconst unsigned char *c, int i3); /* 20 */
    int (*xChangeWindowAttributes) (Display *d, Window w, unsigned long ul, XSetWindowAttributes *x); /* 21 */
    Status (*xAllocColor) (Display *d, Colormap c, XColor *xp); /* 12 */
    int (*xBell) (Display *d, int i); /* 13 */
    void (*xChangeProperty) (Display *d, Window w, Atom a1, Atom a2, int i1, int i2, _Xconst unsigned char *c, int i3); /* 14 */
    void (*xChangeWindowAttributes) (Display *d, Window w, unsigned long ul, XSetWindowAttributes *x); /* 15 */
    int (*xClearWindow) (Display *d, Window w); /* 22 */
    int (*xConfigureWindow) (Display *d, Window w, unsigned int i, XWindowChanges *x); /* 23 */
    int (*xCopyArea) (Display *d, Drawable dr1, Drawable dr2, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 24 */
    int (*xCopyPlane) (Display *d, Drawable dr1, Drawable dr2, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4, unsigned long ul); /* 25 */
    Pixmap (*xCreateBitmapFromData) (Display *display, Drawable d, _Xconst char *data, unsigned int width, unsigned int height); /* 26 */
    int (*xDefineCursor) (Display *d, Window w, Cursor c); /* 27 */
    void (*xConfigureWindow) (Display *d, Window w, unsigned int i, XWindowChanges *x); /* 16 */
    void (*xCopyArea) (Display *d, Drawable dr1, Drawable dr2, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 17 */
    void (*xCopyPlane) (Display *d, Drawable dr1, Drawable dr2, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4, unsigned long ul); /* 18 */
    Pixmap (*xCreateBitmapFromData) (Display *display, Drawable d, _Xconst char *data, unsigned int width, unsigned int height); /* 19 */
    int (*xDefineCursor) (Display *d, Window w, Cursor c); /* 20 */
    int (*xDeleteProperty) (Display *d, Window w, Atom a); /* 28 */
    int (*xDestroyWindow) (Display *d, Window w); /* 29 */
    int (*xDrawArc) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 30 */
    int (*xDrawLines) (Display *d, Drawable dr, GC g, XPoint *x, int i1, int i2); /* 31 */
    int (*xDrawRectangle) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2); /* 32 */
    int (*xFillArc) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 33 */
    int (*xFillPolygon) (Display *d, Drawable dr, GC g, XPoint *x, int i1, int i2, int i3); /* 34 */
    int (*xFillRectangles) (Display *d, Drawable dr, GC g, XRectangle *x, int i); /* 35 */
    void (*xDestroyWindow) (Display *d, Window w); /* 21 */
    void (*xDrawArc) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 22 */
    int (*xDrawLines) (Display *d, Drawable dr, GC g, XPoint *x, int i1, int i2); /* 23 */
    void (*xDrawRectangle) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2); /* 24 */
    void (*xFillArc) (Display *d, Drawable dr, GC g, int i1, int i2, unsigned int ui1, unsigned int ui2, int i3, int i4); /* 25 */
    void (*xFillPolygon) (Display *d, Drawable dr, GC g, XPoint *x, int i1, int i2, int i3); /* 26 */
    int (*xFillRectangles) (Display *d, Drawable dr, GC g, XRectangle *x, int i); /* 27 */
    int (*xForceScreenSaver) (Display *d, int i); /* 36 */
    int (*xFreeColormap) (Display *d, Colormap c); /* 37 */
    int (*xFreeColors) (Display *d, Colormap c, unsigned long *ulp, int i, unsigned long ul); /* 38 */
    int (*xFreeColormap) (Display *d, Colormap c); /* 28 */
    int (*xFreeColors) (Display *d, Colormap c, unsigned long *ulp, int i, unsigned long ul); /* 29 */
    int (*xFreeCursor) (Display *d, Cursor c); /* 39 */
    int (*xFreeModifiermap) (XModifierKeymap *x); /* 40 */
    Status (*xGetGeometry) (Display *d, Drawable dr, Window *w, int *i1, int *i2, unsigned int *ui1, unsigned int *ui2, unsigned int *ui3, unsigned int *ui4); /* 41 */
    int (*xFreeModifiermap) (XModifierKeymap *x); /* 30 */
    Status (*xGetGeometry) (Display *d, Drawable dr, Window *w, int *i1, int *i2, unsigned int *ui1, unsigned int *ui2, unsigned int *ui3, unsigned int *ui4); /* 31 */
    int (*xGetInputFocus) (Display *d, Window *w, int *i); /* 42 */
    int (*xGetWindowProperty) (Display *d, Window w, Atom a1, long l1, long l2, Bool b, Atom a2, Atom *ap, int *ip, unsigned long *ulp1, unsigned long *ulp2, unsigned char **cpp); /* 43 */
    int (*xGetWindowProperty) (Display *d, Window w, Atom a1, long l1, long l2, Bool b, Atom a2, Atom *ap, int *ip, unsigned long *ulp1, unsigned long *ulp2, unsigned char **cpp); /* 32 */
    Status (*xGetWindowAttributes) (Display *d, Window w, XWindowAttributes *x); /* 44 */
    int (*xGrabKeyboard) (Display *d, Window w, Bool b, int i1, int i2, Time t); /* 45 */
    int (*xGrabPointer) (Display *d, Window w1, Bool b, unsigned int ui, int i1, int i2, Window w2, Cursor c, Time t); /* 46 */
    KeyCode (*xKeysymToKeycode) (Display *d, KeySym k); /* 47 */
    int (*xGrabKeyboard) (Display *d, Window w, Bool b, int i1, int i2, Time t); /* 33 */
    int (*xGrabPointer) (Display *d, Window w1, Bool b, unsigned int ui, int i1, int i2, Window w2, Cursor c, Time t); /* 34 */
    KeyCode (*xKeysymToKeycode) (Display *d, KeySym k); /* 35 */
    Status (*xLookupColor) (Display *d, Colormap c1, _Xconst char *c2, XColor *x1, XColor *x2); /* 48 */
    int (*xMapWindow) (Display *d, Window w); /* 49 */
    int (*xMoveResizeWindow) (Display *d, Window w, int i1, int i2, unsigned int ui1, unsigned int ui2); /* 50 */
    int (*xMoveWindow) (Display *d, Window w, int i1, int i2); /* 51 */
    void (*xMapWindow) (Display *d, Window w); /* 36 */
    void (*xMoveResizeWindow) (Display *d, Window w, int i1, int i2, unsigned int ui1, unsigned int ui2); /* 37 */
    void (*xMoveWindow) (Display *d, Window w, int i1, int i2); /* 38 */
    int (*xNextEvent) (Display *d, XEvent *x); /* 52 */
    int (*xPutBackEvent) (Display *d, XEvent *x); /* 53 */
    int (*xQueryColors) (Display *d, Colormap c, XColor *x, int i); /* 54 */
    Bool (*xQueryPointer) (Display *d, Window w1, Window *w2, Window *w3, int *i1, int *i2, int *i3, int *i4, unsigned int *ui); /* 55 */
    Bool (*xQueryPointer) (Display *d, Window w1, Window *w2, Window *w3, int *i1, int *i2, int *i3, int *i4, unsigned int *ui); /* 39 */
    Status (*xQueryTree) (Display *d, Window w1, Window *w2, Window *w3, Window **w4, unsigned int *ui); /* 56 */
    int (*xRaiseWindow) (Display *d, Window w); /* 57 */
    int (*xRefreshKeyboardMapping) (XMappingEvent *x); /* 58 */
    int (*xResizeWindow) (Display *d, Window w, unsigned int ui1, unsigned int ui2); /* 59 */
    int (*xSelectInput) (Display *d, Window w, long l); /* 60 */
    Status (*xSendEvent) (Display *d, Window w, Bool b, long l, XEvent *x); /* 61 */
    void (*xRaiseWindow) (Display *d, Window w); /* 40 */
    void (*xRefreshKeyboardMapping) (XMappingEvent *x); /* 41 */
    void (*xResizeWindow) (Display *d, Window w, unsigned int ui1, unsigned int ui2); /* 42 */
    void (*xSelectInput) (Display *d, Window w, long l); /* 43 */
    Status (*xSendEvent) (Display *d, Window w, Bool b, long l, XEvent *x); /* 44 */
    int (*xSetCommand) (Display *d, Window w, char **c, int i); /* 62 */
    int (*xSetIconName) (Display *d, Window w, _Xconst char *c); /* 63 */
    int (*xSetInputFocus) (Display *d, Window w, int i, Time t); /* 64 */
    int (*xSetSelectionOwner) (Display *d, Atom a, Window w, Time t); /* 65 */
    int (*xSetWindowBackground) (Display *d, Window w, unsigned long ul); /* 66 */
    int (*xSetWindowBackgroundPixmap) (Display *d, Window w, Pixmap p); /* 67 */
    int (*xSetWindowBorder) (Display *d, Window w, unsigned long ul); /* 68 */
    int (*xSetWindowBorderPixmap) (Display *d, Window w, Pixmap p); /* 69 */
    int (*xSetWindowBorderWidth) (Display *d, Window w, unsigned int ui); /* 70 */
    int (*xSetWindowColormap) (Display *d, Window w, Colormap c); /* 71 */
    void (*xSetIconName) (Display *d, Window w, _Xconst char *c); /* 45 */
    void (*xSetInputFocus) (Display *d, Window w, int i, Time t); /* 46 */
    int (*xSetSelectionOwner) (Display *d, Atom a, Window w, Time t); /* 47 */
    void (*xSetWindowBackground) (Display *d, Window w, unsigned long ul); /* 48 */
    void (*xSetWindowBackgroundPixmap) (Display *d, Window w, Pixmap p); /* 49 */
    void (*xSetWindowBorder) (Display *d, Window w, unsigned long ul); /* 50 */
    void (*xSetWindowBorderPixmap) (Display *d, Window w, Pixmap p); /* 51 */
    void (*xSetWindowBorderWidth) (Display *d, Window w, unsigned int ui); /* 52 */
    void (*xSetWindowColormap) (Display *d, Window w, Colormap c); /* 53 */
    Bool (*xTranslateCoordinates) (Display *d, Window w1, Window w2, int i1, int i2, int *i3, int *i4, Window *w3); /* 72 */
    int (*xUngrabKeyboard) (Display *d, Time t); /* 73 */
    int (*xUngrabPointer) (Display *d, Time t); /* 74 */
    int (*xUnmapWindow) (Display *d, Window w); /* 75 */
    void (*xUngrabKeyboard) (Display *d, Time t); /* 54 */
    int (*xUngrabPointer) (Display *d, Time t); /* 55 */
    void (*xUnmapWindow) (Display *d, Window w); /* 56 */
    int (*xWindowEvent) (Display *d, Window w, long l, XEvent *x); /* 76 */
    void (*xDestroyIC) (XIC x); /* 77 */
    Bool (*xFilterEvent) (XEvent *x, Window w); /* 78 */
    int (*xmbLookupString) (XIC xi, XKeyPressedEvent *xk, char *c, int i, KeySym *k, Status *s); /* 79 */
    int (*tkPutImage) (unsigned long *colors, int ncolors, Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); /* 80 */
    int (*tkPutImage) (unsigned long *colors, int ncolors, Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); /* 57 */
    int (*xSetClipRectangles) (Display *display, GC gc, int clip_x_origin, int clip_y_origin, XRectangle rectangles[], int n, int ordering); /* 81 */
    Status (*xParseColor) (Display *display, Colormap map, _Xconst char *spec, XColor *colorPtr); /* 82 */
    GC (*xCreateGC) (Display *display, Drawable d, unsigned long valuemask, XGCValues *values); /* 83 */
    int (*xFreeGC) (Display *display, GC gc); /* 84 */
    Atom (*xInternAtom) (Display *display, _Xconst char *atom_name, Bool only_if_exists); /* 85 */
    int (*xSetBackground) (Display *display, GC gc, unsigned long foreground); /* 86 */
    int (*xSetForeground) (Display *display, GC gc, unsigned long foreground); /* 87 */
    int (*xSetClipMask) (Display *display, GC gc, Pixmap pixmap); /* 88 */
    int (*xSetClipOrigin) (Display *display, GC gc, int clip_x_origin, int clip_y_origin); /* 89 */
    int (*xSetTSOrigin) (Display *display, GC gc, int ts_x_origin, int ts_y_origin); /* 90 */
    int (*xChangeGC) (Display *d, GC gc, unsigned long mask, XGCValues *values); /* 91 */
    int (*xSetFont) (Display *display, GC gc, Font font); /* 92 */
    int (*xSetArcMode) (Display *display, GC gc, int arc_mode); /* 93 */
    int (*xSetStipple) (Display *display, GC gc, Pixmap stipple); /* 94 */
    int (*xSetFillRule) (Display *display, GC gc, int fill_rule); /* 95 */
    int (*xSetFillStyle) (Display *display, GC gc, int fill_style); /* 96 */
    int (*xSetFunction) (Display *display, GC gc, int function); /* 97 */
    int (*xSetLineAttributes) (Display *display, GC gc, unsigned int line_width, int line_style, int cap_style, int join_style); /* 98 */
    int (*_XInitImageFuncPtrs) (XImage *image); /* 99 */
    XIC (*xCreateIC) (XIM xim, ...); /* 100 */
    Status (*xParseColor) (Display *display, Colormap map, _Xconst char *spec, XColor *colorPtr); /* 58 */
    GC (*xCreateGC) (Display *display, Drawable d, unsigned long valuemask, XGCValues *values); /* 59 */
    int (*xFreeGC) (Display *display, GC gc); /* 60 */
    Atom (*xInternAtom) (Display *display, _Xconst char *atom_name, Bool only_if_exists); /* 61 */
    int (*xSetBackground) (Display *display, GC gc, unsigned long foreground); /* 62 */
    int (*xSetForeground) (Display *display, GC gc, unsigned long foreground); /* 63 */
    int (*xSetClipMask) (Display *display, GC gc, Pixmap pixmap); /* 64 */
    int (*xSetClipOrigin) (Display *display, GC gc, int clip_x_origin, int clip_y_origin); /* 65 */
    int (*xSetTSOrigin) (Display *display, GC gc, int ts_x_origin, int ts_y_origin); /* 66 */
    int (*xChangeGC) (Display *d, GC gc, unsigned long mask, XGCValues *values); /* 67 */
    int (*xSetFont) (Display *display, GC gc, Font font); /* 68 */
    int (*xSetArcMode) (Display *display, GC gc, int arc_mode); /* 69 */
    int (*xSetStipple) (Display *display, GC gc, Pixmap stipple); /* 70 */
    int (*xSetFillRule) (Display *display, GC gc, int fill_rule); /* 71 */
    int (*xSetFillStyle) (Display *display, GC gc, int fill_style); /* 72 */
    int (*xSetFunction) (Display *display, GC gc, int function); /* 73 */
    int (*xSetLineAttributes) (Display *display, GC gc, unsigned int line_width, int line_style, int cap_style, int join_style); /* 74 */
    int (*_XInitImageFuncPtrs) (XImage *image); /* 75 */
    XIC (*xCreateIC) (void); /* 76 */
    XVisualInfo * (*xGetVisualInfo) (Display *display, long vinfo_mask, XVisualInfo *vinfo_template, int *nitems_return); /* 101 */
    void (*xSetWMClientMachine) (Display *display, Window w, XTextProperty *text_prop); /* 102 */
    Status (*xStringListToTextProperty) (char **list, int count, XTextProperty *text_prop_return); /* 103 */
    int (*xDrawLine) (Display *d, Drawable dr, GC g, int x1, int y1, int x2, int y2); /* 104 */
    int (*xWarpPointer) (Display *d, Window s, Window dw, int sx, int sy, unsigned int sw, unsigned int sh, int dx, int dy); /* 105 */
    int (*xFillRectangle) (Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); /* 106 */
    int (*xFlush) (Display *display); /* 107 */
    int (*xGrabServer) (Display *display); /* 108 */
    int (*xUngrabServer) (Display *display); /* 109 */
    int (*xFree) (void *data); /* 110 */
    int (*xNoOp) (Display *display); /* 111 */
    XAfterFunction (*xSynchronize) (Display *display, Bool onoff); /* 112 */
    int (*xSync) (Display *display, Bool discard); /* 113 */
    VisualID (*xVisualIDFromVisual) (Visual *visual); /* 114 */
    void (*reserved115)(void);
    void (*reserved116)(void);
    void (*reserved117)(void);
    void (*reserved118)(void);
    void (*reserved119)(void);
    int (*xOffsetRegion) (Region rgn, int dx, int dy); /* 120 */
    int (*xUnionRegion) (Region srca, Region srcb, Region dr_return); /* 121 */
    Window (*xCreateWindow) (Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth, unsigned int clazz, Visual *visual, unsigned long value_mask, XSetWindowAttributes *attributes); /* 122 */
    void (*reserved123)(void);
    XVisualInfo * (*xGetVisualInfo) (Display *display, long vinfo_mask, XVisualInfo *vinfo_template, int *nitems_return); /* 77 */
    void (*xSetWMClientMachine) (Display *display, Window w, XTextProperty *text_prop); /* 78 */
    Status (*xStringListToTextProperty) (char **list, int count, XTextProperty *text_prop_return); /* 79 */
    void (*reserved124)(void);
    void (*reserved125)(void);
    void (*reserved126)(void);
    void (*reserved127)(void);
    void (*reserved128)(void);
    int (*xLowerWindow) (Display *d, Window w); /* 129 */
    int (*xFillArcs) (Display *d, Drawable dr, GC gc, XArc *a, int n); /* 130 */
    int (*xDrawArcs) (Display *d, Drawable dr, GC gc, XArc *a, int n); /* 131 */
    int (*xDrawRectangles) (Display *d, Drawable dr, GC gc, XRectangle *r, int n); /* 132 */
    int (*xDrawSegments) (Display *d, Drawable dr, GC gc, XSegment *s, int n); /* 133 */
    int (*xDrawPoint) (Display *d, Drawable dr, GC gc, int x, int y); /* 134 */
    int (*xDrawPoints) (Display *d, Drawable dr, GC gc, XPoint *p, int n, int m); /* 135 */
    int (*xReparentWindow) (Display *d, Window w, Window p, int x, int y); /* 136 */
    int (*xDrawSegments) (Display *display, Drawable d, GC gc, XSegment *segments, int nsegments); /* 80 */
    void (*xForceScreenSaver) (Display *display, int mode); /* 81 */
    int (*xDrawLine) (Display *d, Drawable dr, GC g, int x1, int y1, int x2, int y2); /* 82 */
    int (*xFillRectangle) (Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); /* 83 */
    void (*xClearWindow) (Display *d, Window w); /* 84 */
    int (*xDrawPoint) (Display *display, Drawable d, GC gc, int x, int y); /* 85 */
    int (*xDrawPoints) (Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode); /* 86 */
    int (*xWarpPointer) (Display *display, Window src_w, Window dest_w, int src_x, int src_y, unsigned int src_width, unsigned int src_height, int dest_x, int dest_y); /* 87 */
    int (*xPutImage) (Display *d, Drawable dr, GC gc, XImage *im, int sx, int sy, int dx, int dy, unsigned int w, unsigned int h); /* 137 */
    Region (*xPolygonRegion) (XPoint *pts, int n, int rule); /* 138 */
    int (*xPointInRegion) (Region rgn, int x, int y); /* 139 */
    XVaNestedList (*xVaCreateNestedList) (int dummy, ...); /* 140 */
    char * (*xSetICValues) (XIC xic, ...); /* 141 */
    char * (*xGetICValues) (XIC xic, ...); /* 142 */
    void (*xSetICFocus) (XIC xic); /* 143 */
    void (*xQueryColor) (Display *display, Colormap colormap, XColor *def_in_out); /* 88 */
    void (*reserved144)(void);
    void (*reserved145)(void);
    void (*reserved146)(void);
    void (*xFreeFontSet) (Display *display, XFontSet fontset); /* 147 */
    void (*xQueryColors) (Display *display, Colormap colormap, XColor *defs_in_out, int ncolors); /* 89 */
    int (*xCloseIM) (XIM im); /* 148 */
    Bool (*xRegisterIMInstantiateCallback) (Display *dpy, struct _XrmHashBucketRec *rbd, char *res_name, char *res_class, XIDProc callback, XPointer client_data); /* 149 */
    Bool (*xUnregisterIMInstantiateCallback) (Display *dpy, struct _XrmHashBucketRec *rbd, char *res_name, char *res_class, XIDProc callback, XPointer client_data); /* 150 */
    char * (*xSetLocaleModifiers) (const char *modifier_list); /* 151 */
    XIM (*xOpenIM) (Display *dpy, struct _XrmHashBucketRec *rdb, char *res_name, char *res_class); /* 152 */
    Status (*xQueryTree) (Display *d, Window w1, Window *w2, Window *w3, Window **w4, unsigned int *ui); /* 90 */
    char * (*xGetIMValues) (XIM im, ...); /* 153 */
    char * (*xSetIMValues) (XIM im, ...); /* 154 */
    XFontSet (*xCreateFontSet) (Display *display, _Xconst char *base_font_name_list, char ***missing_charset_list, int *missing_charset_count, char **def_string); /* 155 */
    int (*xSync) (Display *display, Bool flag); /* 91 */
    void (*xFreeStringList) (char **list); /* 156 */
    KeySym (*xkbKeycodeToKeysym) (Display *d, unsigned int k, int g, int i); /* 157 */
    Display * (*xkbOpenDisplay) (const char *name, int *ev_rtrn, int *err_rtrn, int *major_rtrn, int *minor_rtrn, int *reason); /* 158 */
#endif /* MACOSX */
#endif /* AQUA */
} TkIntXlibStubs;

extern const TkIntXlibStubs *tkIntXlibStubsPtr;

#ifdef __cplusplus
}
#endif
1396
1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1411
1098
1099
1100
1101
1102
1103
1104

1105

1106
1107
1108
1109
1110
1111
1112







-
+
-







	(tkIntXlibStubsPtr->xDestroyIC) /* 77 */
#define XFilterEvent \
	(tkIntXlibStubsPtr->xFilterEvent) /* 78 */
#define XmbLookupString \
	(tkIntXlibStubsPtr->xmbLookupString) /* 79 */
#define TkPutImage \
	(tkIntXlibStubsPtr->tkPutImage) /* 80 */
#define XSetClipRectangles \
/* Slot 81 is reserved */
	(tkIntXlibStubsPtr->xSetClipRectangles) /* 81 */
#define XParseColor \
	(tkIntXlibStubsPtr->xParseColor) /* 82 */
#define XCreateGC \
	(tkIntXlibStubsPtr->xCreateGC) /* 83 */
#define XFreeGC \
	(tkIntXlibStubsPtr->xFreeGC) /* 84 */
#define XInternAtom \
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546

1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570

1571
1572

1573
1574

1575
1576

1577
1578
1579
1580
1581
1582
1583
1584

1585
1586

1587
1588

1589
1590

1591
1592
1593
1594

1595
1596

1597
1598

1599
1600

1601
1602

1603
1604
1605
1606

1607
1608

1609
1610

1611
1612

1613
1614

1615
1616

1617
1618

1619
1620
1621
1622

1623
1624

1625
1626
1627
1628

1629
1630

1631
1632
1633
1634

1635
1636
1637
1638

1639
1640

1641
1642

1643
1644
1645
1646

1647
1648

1649
1650

1651
1652
1653
1654
1655
1656
1657
1658

1659
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
1200
1201
1202
1203
1204
1205
1206







































1207

1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222




1223

1224


1225

1226
1227

1228
1229

1230
1231

1232






1233

1234
1235

1236
1237

1238
1239

1240


1241

1242
1243

1244
1245

1246
1247

1248
1249

1250


1251

1252
1253

1254
1255

1256
1257

1258
1259

1260
1261

1262
1263

1264


1265

1266
1267

1268


1269

1270
1271

1272


1273

1274


1275

1276
1277

1278
1279

1280


1281

1282
1283

1284
1285

1286






1287

1288


1289

1290
1291

1292
1293

1294
1295

1296
1297

1298


1299

1300
1301

1302
1303

1304
1305

1306
1307

1308
1309

1310
1311

1312
1313

1314
1315

1316


1317

1318
1319

1320
1321

1322








1323

1324


1325

1326
1327

1328
1329

1330
1331

1332
1333

1334
1335

1336
1337

1338
1339

1340
1341

1342
1343

1344
1345

1346
1347

1348
1349

1350
1351

1352
1353

1354
1355

1356
1357

1358
1359

1360
1361

1362
1363

1364
1365

1366
1367





1368
1369
1370
1371
1372
1373
1374
1375













1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391

1392













































































1393
1394
1395
1396
1397
1398




1399
1400
1401
1402







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+














-
-
-
-

-
+
-
-

-
+

-
+

-
+

-
+
-
-
-
-
-
-

-
+

-
+

-
+

-
+
-
-

-
+

-
+

-
+

-
+

-
+
-
-

-
+

-
+

-
+

-
+

-
+

-
+

-
+
-
-

-
+

-
+
-
-

-
+

-
+
-
-

-
+
-
-

-
+

-
+

-
+
-
-

-
+

-
+

-
+
-
-
-
-
-
-

-
+
-
-

-
+

-
+

-
+

-
+

-
+
-
-

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+
-
-

-
+

-
+

-
+
-
-
-
-
-
-
-
-

-
+
-
-

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+





-
-
-
-




	(tkIntXlibStubsPtr->xDrawPoint) /* 134 */
#define XDrawPoints \
	(tkIntXlibStubsPtr->xDrawPoints) /* 135 */
#define XReparentWindow \
	(tkIntXlibStubsPtr->xReparentWindow) /* 136 */
#define XPutImage \
	(tkIntXlibStubsPtr->xPutImage) /* 137 */
#define XPolygonRegion \
	(tkIntXlibStubsPtr->xPolygonRegion) /* 138 */
#define XPointInRegion \
	(tkIntXlibStubsPtr->xPointInRegion) /* 139 */
#define XVaCreateNestedList \
	(tkIntXlibStubsPtr->xVaCreateNestedList) /* 140 */
#define XSetICValues \
	(tkIntXlibStubsPtr->xSetICValues) /* 141 */
#define XGetICValues \
	(tkIntXlibStubsPtr->xGetICValues) /* 142 */
#define XSetICFocus \
	(tkIntXlibStubsPtr->xSetICFocus) /* 143 */
/* Slot 144 is reserved */
/* Slot 145 is reserved */
/* Slot 146 is reserved */
#define XFreeFontSet \
	(tkIntXlibStubsPtr->xFreeFontSet) /* 147 */
#define XCloseIM \
	(tkIntXlibStubsPtr->xCloseIM) /* 148 */
#define XRegisterIMInstantiateCallback \
	(tkIntXlibStubsPtr->xRegisterIMInstantiateCallback) /* 149 */
#define XUnregisterIMInstantiateCallback \
	(tkIntXlibStubsPtr->xUnregisterIMInstantiateCallback) /* 150 */
#define XSetLocaleModifiers \
	(tkIntXlibStubsPtr->xSetLocaleModifiers) /* 151 */
#define XOpenIM \
	(tkIntXlibStubsPtr->xOpenIM) /* 152 */
#define XGetIMValues \
	(tkIntXlibStubsPtr->xGetIMValues) /* 153 */
#define XSetIMValues \
	(tkIntXlibStubsPtr->xSetIMValues) /* 154 */
#define XCreateFontSet \
	(tkIntXlibStubsPtr->xCreateFontSet) /* 155 */
#define XFreeStringList \
	(tkIntXlibStubsPtr->xFreeStringList) /* 156 */
#define XkbKeycodeToKeysym \
	(tkIntXlibStubsPtr->xkbKeycodeToKeysym) /* 157 */
#define XkbOpenDisplay \
	(tkIntXlibStubsPtr->xkbOpenDisplay) /* 158 */
#endif /* WIN */
#ifdef MAC_OSX_TCL /* MACOSX */
#ifdef MAC_OSX_TK /* AQUA */
#define XSetDashes \
	(tkIntXlibStubsPtr->xSetDashes) /* 0 */
#define XGetModifierMapping \
	(tkIntXlibStubsPtr->xGetModifierMapping) /* 1 */
#define XCreateImage \
	(tkIntXlibStubsPtr->xCreateImage) /* 2 */
#define XGetImage \
	(tkIntXlibStubsPtr->xGetImage) /* 3 */
#define XGetAtomName \
	(tkIntXlibStubsPtr->xGetAtomName) /* 4 */
#define XKeysymToString \
	(tkIntXlibStubsPtr->xKeysymToString) /* 5 */
#define XCreateColormap \
	(tkIntXlibStubsPtr->xCreateColormap) /* 6 */
#define XCreatePixmapCursor \
	(tkIntXlibStubsPtr->xCreatePixmapCursor) /* 7 */
#define XCreateGlyphCursor \
	(tkIntXlibStubsPtr->xCreateGlyphCursor) /* 8 */
#define XGContextFromGC \
	(tkIntXlibStubsPtr->xGContextFromGC) /* 9 */
	(tkIntXlibStubsPtr->xGContextFromGC) /* 7 */
#define XListHosts \
	(tkIntXlibStubsPtr->xListHosts) /* 10 */
#define XKeycodeToKeysym \
	(tkIntXlibStubsPtr->xKeycodeToKeysym) /* 11 */
	(tkIntXlibStubsPtr->xKeycodeToKeysym) /* 8 */
#define XStringToKeysym \
	(tkIntXlibStubsPtr->xStringToKeysym) /* 12 */
	(tkIntXlibStubsPtr->xStringToKeysym) /* 9 */
#define XRootWindow \
	(tkIntXlibStubsPtr->xRootWindow) /* 13 */
	(tkIntXlibStubsPtr->xRootWindow) /* 10 */
#define XSetErrorHandler \
	(tkIntXlibStubsPtr->xSetErrorHandler) /* 14 */
	(tkIntXlibStubsPtr->xSetErrorHandler) /* 11 */
#define XIconifyWindow \
	(tkIntXlibStubsPtr->xIconifyWindow) /* 15 */
#define XWithdrawWindow \
	(tkIntXlibStubsPtr->xWithdrawWindow) /* 16 */
#define XGetWMColormapWindows \
	(tkIntXlibStubsPtr->xGetWMColormapWindows) /* 17 */
#define XAllocColor \
	(tkIntXlibStubsPtr->xAllocColor) /* 18 */
	(tkIntXlibStubsPtr->xAllocColor) /* 12 */
#define XBell \
	(tkIntXlibStubsPtr->xBell) /* 19 */
	(tkIntXlibStubsPtr->xBell) /* 13 */
#define XChangeProperty \
	(tkIntXlibStubsPtr->xChangeProperty) /* 20 */
	(tkIntXlibStubsPtr->xChangeProperty) /* 14 */
#define XChangeWindowAttributes \
	(tkIntXlibStubsPtr->xChangeWindowAttributes) /* 21 */
	(tkIntXlibStubsPtr->xChangeWindowAttributes) /* 15 */
#define XClearWindow \
	(tkIntXlibStubsPtr->xClearWindow) /* 22 */
#define XConfigureWindow \
	(tkIntXlibStubsPtr->xConfigureWindow) /* 23 */
	(tkIntXlibStubsPtr->xConfigureWindow) /* 16 */
#define XCopyArea \
	(tkIntXlibStubsPtr->xCopyArea) /* 24 */
	(tkIntXlibStubsPtr->xCopyArea) /* 17 */
#define XCopyPlane \
	(tkIntXlibStubsPtr->xCopyPlane) /* 25 */
	(tkIntXlibStubsPtr->xCopyPlane) /* 18 */
#define XCreateBitmapFromData \
	(tkIntXlibStubsPtr->xCreateBitmapFromData) /* 26 */
	(tkIntXlibStubsPtr->xCreateBitmapFromData) /* 19 */
#define XDefineCursor \
	(tkIntXlibStubsPtr->xDefineCursor) /* 27 */
	(tkIntXlibStubsPtr->xDefineCursor) /* 20 */
#define XDeleteProperty \
	(tkIntXlibStubsPtr->xDeleteProperty) /* 28 */
#define XDestroyWindow \
	(tkIntXlibStubsPtr->xDestroyWindow) /* 29 */
	(tkIntXlibStubsPtr->xDestroyWindow) /* 21 */
#define XDrawArc \
	(tkIntXlibStubsPtr->xDrawArc) /* 30 */
	(tkIntXlibStubsPtr->xDrawArc) /* 22 */
#define XDrawLines \
	(tkIntXlibStubsPtr->xDrawLines) /* 31 */
	(tkIntXlibStubsPtr->xDrawLines) /* 23 */
#define XDrawRectangle \
	(tkIntXlibStubsPtr->xDrawRectangle) /* 32 */
	(tkIntXlibStubsPtr->xDrawRectangle) /* 24 */
#define XFillArc \
	(tkIntXlibStubsPtr->xFillArc) /* 33 */
	(tkIntXlibStubsPtr->xFillArc) /* 25 */
#define XFillPolygon \
	(tkIntXlibStubsPtr->xFillPolygon) /* 34 */
	(tkIntXlibStubsPtr->xFillPolygon) /* 26 */
#define XFillRectangles \
	(tkIntXlibStubsPtr->xFillRectangles) /* 35 */
	(tkIntXlibStubsPtr->xFillRectangles) /* 27 */
#define XForceScreenSaver \
	(tkIntXlibStubsPtr->xForceScreenSaver) /* 36 */
#define XFreeColormap \
	(tkIntXlibStubsPtr->xFreeColormap) /* 37 */
	(tkIntXlibStubsPtr->xFreeColormap) /* 28 */
#define XFreeColors \
	(tkIntXlibStubsPtr->xFreeColors) /* 38 */
	(tkIntXlibStubsPtr->xFreeColors) /* 29 */
#define XFreeCursor \
	(tkIntXlibStubsPtr->xFreeCursor) /* 39 */
#define XFreeModifiermap \
	(tkIntXlibStubsPtr->xFreeModifiermap) /* 40 */
	(tkIntXlibStubsPtr->xFreeModifiermap) /* 30 */
#define XGetGeometry \
	(tkIntXlibStubsPtr->xGetGeometry) /* 41 */
	(tkIntXlibStubsPtr->xGetGeometry) /* 31 */
#define XGetInputFocus \
	(tkIntXlibStubsPtr->xGetInputFocus) /* 42 */
#define XGetWindowProperty \
	(tkIntXlibStubsPtr->xGetWindowProperty) /* 43 */
	(tkIntXlibStubsPtr->xGetWindowProperty) /* 32 */
#define XGetWindowAttributes \
	(tkIntXlibStubsPtr->xGetWindowAttributes) /* 44 */
#define XGrabKeyboard \
	(tkIntXlibStubsPtr->xGrabKeyboard) /* 45 */
	(tkIntXlibStubsPtr->xGrabKeyboard) /* 33 */
#define XGrabPointer \
	(tkIntXlibStubsPtr->xGrabPointer) /* 46 */
	(tkIntXlibStubsPtr->xGrabPointer) /* 34 */
#define XKeysymToKeycode \
	(tkIntXlibStubsPtr->xKeysymToKeycode) /* 47 */
	(tkIntXlibStubsPtr->xKeysymToKeycode) /* 35 */
#define XLookupColor \
	(tkIntXlibStubsPtr->xLookupColor) /* 48 */
#define XMapWindow \
	(tkIntXlibStubsPtr->xMapWindow) /* 49 */
	(tkIntXlibStubsPtr->xMapWindow) /* 36 */
#define XMoveResizeWindow \
	(tkIntXlibStubsPtr->xMoveResizeWindow) /* 50 */
	(tkIntXlibStubsPtr->xMoveResizeWindow) /* 37 */
#define XMoveWindow \
	(tkIntXlibStubsPtr->xMoveWindow) /* 51 */
	(tkIntXlibStubsPtr->xMoveWindow) /* 38 */
#define XNextEvent \
	(tkIntXlibStubsPtr->xNextEvent) /* 52 */
#define XPutBackEvent \
	(tkIntXlibStubsPtr->xPutBackEvent) /* 53 */
#define XQueryColors \
	(tkIntXlibStubsPtr->xQueryColors) /* 54 */
#define XQueryPointer \
	(tkIntXlibStubsPtr->xQueryPointer) /* 55 */
	(tkIntXlibStubsPtr->xQueryPointer) /* 39 */
#define XQueryTree \
	(tkIntXlibStubsPtr->xQueryTree) /* 56 */
#define XRaiseWindow \
	(tkIntXlibStubsPtr->xRaiseWindow) /* 57 */
	(tkIntXlibStubsPtr->xRaiseWindow) /* 40 */
#define XRefreshKeyboardMapping \
	(tkIntXlibStubsPtr->xRefreshKeyboardMapping) /* 58 */
	(tkIntXlibStubsPtr->xRefreshKeyboardMapping) /* 41 */
#define XResizeWindow \
	(tkIntXlibStubsPtr->xResizeWindow) /* 59 */
	(tkIntXlibStubsPtr->xResizeWindow) /* 42 */
#define XSelectInput \
	(tkIntXlibStubsPtr->xSelectInput) /* 60 */
	(tkIntXlibStubsPtr->xSelectInput) /* 43 */
#define XSendEvent \
	(tkIntXlibStubsPtr->xSendEvent) /* 61 */
	(tkIntXlibStubsPtr->xSendEvent) /* 44 */
#define XSetCommand \
	(tkIntXlibStubsPtr->xSetCommand) /* 62 */
#define XSetIconName \
	(tkIntXlibStubsPtr->xSetIconName) /* 63 */
	(tkIntXlibStubsPtr->xSetIconName) /* 45 */
#define XSetInputFocus \
	(tkIntXlibStubsPtr->xSetInputFocus) /* 64 */
	(tkIntXlibStubsPtr->xSetInputFocus) /* 46 */
#define XSetSelectionOwner \
	(tkIntXlibStubsPtr->xSetSelectionOwner) /* 65 */
	(tkIntXlibStubsPtr->xSetSelectionOwner) /* 47 */
#define XSetWindowBackground \
	(tkIntXlibStubsPtr->xSetWindowBackground) /* 66 */
	(tkIntXlibStubsPtr->xSetWindowBackground) /* 48 */
#define XSetWindowBackgroundPixmap \
	(tkIntXlibStubsPtr->xSetWindowBackgroundPixmap) /* 67 */
	(tkIntXlibStubsPtr->xSetWindowBackgroundPixmap) /* 49 */
#define XSetWindowBorder \
	(tkIntXlibStubsPtr->xSetWindowBorder) /* 68 */
	(tkIntXlibStubsPtr->xSetWindowBorder) /* 50 */
#define XSetWindowBorderPixmap \
	(tkIntXlibStubsPtr->xSetWindowBorderPixmap) /* 69 */
	(tkIntXlibStubsPtr->xSetWindowBorderPixmap) /* 51 */
#define XSetWindowBorderWidth \
	(tkIntXlibStubsPtr->xSetWindowBorderWidth) /* 70 */
	(tkIntXlibStubsPtr->xSetWindowBorderWidth) /* 52 */
#define XSetWindowColormap \
	(tkIntXlibStubsPtr->xSetWindowColormap) /* 71 */
	(tkIntXlibStubsPtr->xSetWindowColormap) /* 53 */
#define XTranslateCoordinates \
	(tkIntXlibStubsPtr->xTranslateCoordinates) /* 72 */
#define XUngrabKeyboard \
	(tkIntXlibStubsPtr->xUngrabKeyboard) /* 73 */
	(tkIntXlibStubsPtr->xUngrabKeyboard) /* 54 */
#define XUngrabPointer \
	(tkIntXlibStubsPtr->xUngrabPointer) /* 74 */
	(tkIntXlibStubsPtr->xUngrabPointer) /* 55 */
#define XUnmapWindow \
	(tkIntXlibStubsPtr->xUnmapWindow) /* 75 */
	(tkIntXlibStubsPtr->xUnmapWindow) /* 56 */
#define XWindowEvent \
	(tkIntXlibStubsPtr->xWindowEvent) /* 76 */
#define XDestroyIC \
	(tkIntXlibStubsPtr->xDestroyIC) /* 77 */
#define XFilterEvent \
	(tkIntXlibStubsPtr->xFilterEvent) /* 78 */
#define XmbLookupString \
	(tkIntXlibStubsPtr->xmbLookupString) /* 79 */
#define TkPutImage \
	(tkIntXlibStubsPtr->tkPutImage) /* 80 */
	(tkIntXlibStubsPtr->tkPutImage) /* 57 */
#define XSetClipRectangles \
	(tkIntXlibStubsPtr->xSetClipRectangles) /* 81 */
#define XParseColor \
	(tkIntXlibStubsPtr->xParseColor) /* 82 */
	(tkIntXlibStubsPtr->xParseColor) /* 58 */
#define XCreateGC \
	(tkIntXlibStubsPtr->xCreateGC) /* 83 */
	(tkIntXlibStubsPtr->xCreateGC) /* 59 */
#define XFreeGC \
	(tkIntXlibStubsPtr->xFreeGC) /* 84 */
	(tkIntXlibStubsPtr->xFreeGC) /* 60 */
#define XInternAtom \
	(tkIntXlibStubsPtr->xInternAtom) /* 85 */
	(tkIntXlibStubsPtr->xInternAtom) /* 61 */
#define XSetBackground \
	(tkIntXlibStubsPtr->xSetBackground) /* 86 */
	(tkIntXlibStubsPtr->xSetBackground) /* 62 */
#define XSetForeground \
	(tkIntXlibStubsPtr->xSetForeground) /* 87 */
	(tkIntXlibStubsPtr->xSetForeground) /* 63 */
#define XSetClipMask \
	(tkIntXlibStubsPtr->xSetClipMask) /* 88 */
	(tkIntXlibStubsPtr->xSetClipMask) /* 64 */
#define XSetClipOrigin \
	(tkIntXlibStubsPtr->xSetClipOrigin) /* 89 */
	(tkIntXlibStubsPtr->xSetClipOrigin) /* 65 */
#define XSetTSOrigin \
	(tkIntXlibStubsPtr->xSetTSOrigin) /* 90 */
	(tkIntXlibStubsPtr->xSetTSOrigin) /* 66 */
#define XChangeGC \
	(tkIntXlibStubsPtr->xChangeGC) /* 91 */
	(tkIntXlibStubsPtr->xChangeGC) /* 67 */
#define XSetFont \
	(tkIntXlibStubsPtr->xSetFont) /* 92 */
	(tkIntXlibStubsPtr->xSetFont) /* 68 */
#define XSetArcMode \
	(tkIntXlibStubsPtr->xSetArcMode) /* 93 */
	(tkIntXlibStubsPtr->xSetArcMode) /* 69 */
#define XSetStipple \
	(tkIntXlibStubsPtr->xSetStipple) /* 94 */
	(tkIntXlibStubsPtr->xSetStipple) /* 70 */
#define XSetFillRule \
	(tkIntXlibStubsPtr->xSetFillRule) /* 95 */
	(tkIntXlibStubsPtr->xSetFillRule) /* 71 */
#define XSetFillStyle \
	(tkIntXlibStubsPtr->xSetFillStyle) /* 96 */
	(tkIntXlibStubsPtr->xSetFillStyle) /* 72 */
#define XSetFunction \
	(tkIntXlibStubsPtr->xSetFunction) /* 97 */
	(tkIntXlibStubsPtr->xSetFunction) /* 73 */
#define XSetLineAttributes \
	(tkIntXlibStubsPtr->xSetLineAttributes) /* 98 */
	(tkIntXlibStubsPtr->xSetLineAttributes) /* 74 */
#define _XInitImageFuncPtrs \
	(tkIntXlibStubsPtr->_XInitImageFuncPtrs) /* 99 */
	(tkIntXlibStubsPtr->_XInitImageFuncPtrs) /* 75 */
#define XCreateIC \
	(tkIntXlibStubsPtr->xCreateIC) /* 100 */
	(tkIntXlibStubsPtr->xCreateIC) /* 76 */
#define XGetVisualInfo \
	(tkIntXlibStubsPtr->xGetVisualInfo) /* 101 */
	(tkIntXlibStubsPtr->xGetVisualInfo) /* 77 */
#define XSetWMClientMachine \
	(tkIntXlibStubsPtr->xSetWMClientMachine) /* 102 */
	(tkIntXlibStubsPtr->xSetWMClientMachine) /* 78 */
#define XStringListToTextProperty \
	(tkIntXlibStubsPtr->xStringListToTextProperty) /* 103 */
#define XDrawLine \
	(tkIntXlibStubsPtr->xDrawLine) /* 104 */
#define XWarpPointer \
	(tkIntXlibStubsPtr->xWarpPointer) /* 105 */
	(tkIntXlibStubsPtr->xStringListToTextProperty) /* 79 */
#define XDrawSegments \
	(tkIntXlibStubsPtr->xDrawSegments) /* 80 */
#define XForceScreenSaver \
	(tkIntXlibStubsPtr->xForceScreenSaver) /* 81 */
#define XDrawLine \
	(tkIntXlibStubsPtr->xDrawLine) /* 82 */
#define XFillRectangle \
	(tkIntXlibStubsPtr->xFillRectangle) /* 106 */
#define XFlush \
	(tkIntXlibStubsPtr->xFlush) /* 107 */
#define XGrabServer \
	(tkIntXlibStubsPtr->xGrabServer) /* 108 */
#define XUngrabServer \
	(tkIntXlibStubsPtr->xUngrabServer) /* 109 */
#define XFree \
	(tkIntXlibStubsPtr->xFree) /* 110 */
#define XNoOp \
	(tkIntXlibStubsPtr->xNoOp) /* 111 */
#define XSynchronize \
	(tkIntXlibStubsPtr->xSynchronize) /* 112 */
	(tkIntXlibStubsPtr->xFillRectangle) /* 83 */
#define XClearWindow \
	(tkIntXlibStubsPtr->xClearWindow) /* 84 */
#define XDrawPoint \
	(tkIntXlibStubsPtr->xDrawPoint) /* 85 */
#define XDrawPoints \
	(tkIntXlibStubsPtr->xDrawPoints) /* 86 */
#define XWarpPointer \
	(tkIntXlibStubsPtr->xWarpPointer) /* 87 */
#define XQueryColor \
	(tkIntXlibStubsPtr->xQueryColor) /* 88 */
#define XQueryColors \
	(tkIntXlibStubsPtr->xQueryColors) /* 89 */
#define XQueryTree \
	(tkIntXlibStubsPtr->xQueryTree) /* 90 */
#define XSync \
	(tkIntXlibStubsPtr->xSync) /* 113 */
	(tkIntXlibStubsPtr->xSync) /* 91 */
#define XVisualIDFromVisual \
	(tkIntXlibStubsPtr->xVisualIDFromVisual) /* 114 */
/* Slot 115 is reserved */
/* Slot 116 is reserved */
/* Slot 117 is reserved */
/* Slot 118 is reserved */
/* Slot 119 is reserved */
#define XOffsetRegion \
	(tkIntXlibStubsPtr->xOffsetRegion) /* 120 */
#define XUnionRegion \
	(tkIntXlibStubsPtr->xUnionRegion) /* 121 */
#define XCreateWindow \
	(tkIntXlibStubsPtr->xCreateWindow) /* 122 */
/* Slot 123 is reserved */
/* Slot 124 is reserved */
/* Slot 125 is reserved */
/* Slot 126 is reserved */
/* Slot 127 is reserved */
/* Slot 128 is reserved */
#define XLowerWindow \
	(tkIntXlibStubsPtr->xLowerWindow) /* 129 */
#define XFillArcs \
	(tkIntXlibStubsPtr->xFillArcs) /* 130 */
#define XDrawArcs \
	(tkIntXlibStubsPtr->xDrawArcs) /* 131 */
#define XDrawRectangles \
	(tkIntXlibStubsPtr->xDrawRectangles) /* 132 */
#define XDrawSegments \
	(tkIntXlibStubsPtr->xDrawSegments) /* 133 */
#define XDrawPoint \
	(tkIntXlibStubsPtr->xDrawPoint) /* 134 */
#define XDrawPoints \
	(tkIntXlibStubsPtr->xDrawPoints) /* 135 */
#define XReparentWindow \
	(tkIntXlibStubsPtr->xReparentWindow) /* 136 */
#define XPutImage \
	(tkIntXlibStubsPtr->xPutImage) /* 137 */
#define XPolygonRegion \
	(tkIntXlibStubsPtr->xPolygonRegion) /* 138 */
#define XPointInRegion \
	(tkIntXlibStubsPtr->xPointInRegion) /* 139 */
#define XVaCreateNestedList \
	(tkIntXlibStubsPtr->xVaCreateNestedList) /* 140 */
#define XSetICValues \
	(tkIntXlibStubsPtr->xSetICValues) /* 141 */
#define XGetICValues \
	(tkIntXlibStubsPtr->xGetICValues) /* 142 */
#define XSetICFocus \
	(tkIntXlibStubsPtr->xSetICFocus) /* 143 */
/* Slot 144 is reserved */
/* Slot 145 is reserved */
/* Slot 146 is reserved */
#define XFreeFontSet \
	(tkIntXlibStubsPtr->xFreeFontSet) /* 147 */
#define XCloseIM \
	(tkIntXlibStubsPtr->xCloseIM) /* 148 */
#define XRegisterIMInstantiateCallback \
	(tkIntXlibStubsPtr->xRegisterIMInstantiateCallback) /* 149 */
#define XUnregisterIMInstantiateCallback \
	(tkIntXlibStubsPtr->xUnregisterIMInstantiateCallback) /* 150 */
#define XSetLocaleModifiers \
	(tkIntXlibStubsPtr->xSetLocaleModifiers) /* 151 */
#define XOpenIM \
	(tkIntXlibStubsPtr->xOpenIM) /* 152 */
#define XGetIMValues \
	(tkIntXlibStubsPtr->xGetIMValues) /* 153 */
#define XSetIMValues \
	(tkIntXlibStubsPtr->xSetIMValues) /* 154 */
#define XCreateFontSet \
	(tkIntXlibStubsPtr->xCreateFontSet) /* 155 */
#define XFreeStringList \
	(tkIntXlibStubsPtr->xFreeStringList) /* 156 */
#define XkbKeycodeToKeysym \
	(tkIntXlibStubsPtr->xkbKeycodeToKeysym) /* 157 */
#define XkbOpenDisplay \
	(tkIntXlibStubsPtr->xkbOpenDisplay) /* 158 */
#endif /* MACOSX */
#endif /* AQUA */

#endif /* defined(USE_TK_STUBS) */

/* !END!: Do not edit above this line. */

#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TCL) /* X11, Except MacOS/Cygwin */
EXTERN Display *XkbOpenDisplay(const char *, int *, int *, int *, int *, int *);
#endif

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

#endif /* _TKINTXLIBDECLS */

Changes to generic/tkListbox.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7


8
9
10
11
12
13
14


15
16
17
18
19
20
21
22
23







-
-
+
+





-
-
+
+







/*
 * tkListbox.c --
 *
 *	This module implements listbox widgets for the Tk toolkit. A listbox
 *	displays a collection of strings, one per line, and provides scrolling
 *	and selection.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

typedef struct {
    Tk_OptionTable listboxOptionTable;
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60







-
+







    Tk_OptionTable optionTable;	/* Table that defines configuration options
				 * available for this widget. */
    Tk_OptionTable itemAttrOptionTable;
				/* Table that defines configuration options
				 * available for listbox items. */
    char *listVarName;		/* List variable name */
    Tcl_Obj *listObj;		/* Pointer to the list object being used */
    Tcl_Size nElements;		/* Holds the current count of elements */
    int nElements;		/* Holds the current count of elements */
    Tcl_HashTable *selection;	/* Tracks selection */
    Tcl_HashTable *itemAttrTable;
				/* Tracks item attributes */

    /*
     * Information used when displaying widget:
     */
215
216
217
218
219
220
221




222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

239
240
241

242
243
244

245
246

247
248

249
250
251

252
253
254
255


256
257
258


259
260

261
262

263
264

265
266

267
268
269


270
271

272
273
274
275


276
277

278
279

280
281

282
283
284
285


286
287

288
289
290

291
292
293

294
295
296


297
298

299
300
301

302
303

304
305
306

307
308
309

310
311

312
313
314
315
316
317
318
319
320
321
322




323
324

325
326
327
328
329
330
331
332
333
334
335
336













337
338
339
340
341
342
343
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244

245
246
247

248
249

250
251

252
253
254

255
256
257


258
259
260


261
262
263

264
265

266
267

268
269

270
271


272
273
274

275
276
277


278
279
280

281
282

283
284

285
286
287


288
289
290

291
292
293

294
295
296

297
298


299
300
301

302
303
304

305
306

307
308
309

310
311
312

313
314

315
316
317
318
319
320
321
322
323



324
325
326
327
328

329
330











331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350







+
+
+
+
















-
+


-
+


-
+

-
+

-
+


-
+


-
-
+
+

-
-
+
+

-
+

-
+

-
+

-
+

-
-
+
+

-
+


-
-
+
+

-
+

-
+

-
+


-
-
+
+

-
+


-
+


-
+

-
-
+
+

-
+


-
+

-
+


-
+


-
+

-
+








-
-
-
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







 * Listbox widget. These values are used as indices into the string table
 * below.
 */

enum state {
    STATE_DISABLED, STATE_NORMAL
};

static const char *const stateStrings[] = {
    "disabled", "normal", NULL
};

enum activeStyle {
    ACTIVE_STYLE_DOTBOX, ACTIVE_STYLE_NONE, ACTIVE_STYLE_UNDERLINE
};

static const char *const activeStyleStrings[] = {
    "dotbox", "none", "underline", NULL
};

/*
 * The optionSpecs table defines the valid configuration options for the
 * listbox widget.
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_STRING_TABLE, "-activestyle", "activeStyle", "ActiveStyle",
	DEF_LISTBOX_ACTIVE_STYLE, TCL_INDEX_NONE, offsetof(Listbox, activeStyle),
	DEF_LISTBOX_ACTIVE_STYLE, -1, Tk_Offset(Listbox, activeStyle),
	0, activeStyleStrings, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	 DEF_LISTBOX_BG_COLOR, TCL_INDEX_NONE, offsetof(Listbox, normalBorder),
	 DEF_LISTBOX_BG_COLOR, -1, Tk_Offset(Listbox, normalBorder),
	 0, DEF_LISTBOX_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	 NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	 NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	 NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	 NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	 DEF_LISTBOX_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Listbox, borderWidth),
	 DEF_LISTBOX_BORDER_WIDTH, -1, Tk_Offset(Listbox, borderWidth),
	 0, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	 DEF_LISTBOX_CURSOR, TCL_INDEX_NONE, offsetof(Listbox, cursor),
	 DEF_LISTBOX_CURSOR, -1, Tk_Offset(Listbox, cursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	 "DisabledForeground", DEF_LISTBOX_DISABLED_FG, TCL_INDEX_NONE,
	 offsetof(Listbox, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
	 "DisabledForeground", DEF_LISTBOX_DISABLED_FG, -1,
	 Tk_Offset(Listbox, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
	 "ExportSelection", DEF_LISTBOX_EXPORT_SELECTION, TCL_INDEX_NONE,
	 offsetof(Listbox, exportSelection), 0, 0, 0},
	 "ExportSelection", DEF_LISTBOX_EXPORT_SELECTION, -1,
	 Tk_Offset(Listbox, exportSelection), 0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	 NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	 NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	 DEF_LISTBOX_FONT, TCL_INDEX_NONE, offsetof(Listbox, tkfont), 0, 0, 0},
	 DEF_LISTBOX_FONT, -1, Tk_Offset(Listbox, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	 DEF_LISTBOX_FG, TCL_INDEX_NONE, offsetof(Listbox, fgColorPtr), 0, 0, 0},
	 DEF_LISTBOX_FG, -1, Tk_Offset(Listbox, fgColorPtr), 0, 0, 0},
    {TK_OPTION_INT, "-height", "height", "Height",
	 DEF_LISTBOX_HEIGHT, TCL_INDEX_NONE, offsetof(Listbox, height), 0, 0, 0},
	 DEF_LISTBOX_HEIGHT, -1, Tk_Offset(Listbox, height), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	 "HighlightBackground", DEF_LISTBOX_HIGHLIGHT_BG, TCL_INDEX_NONE,
	 offsetof(Listbox, highlightBgColorPtr), 0, 0, 0},
	 "HighlightBackground", DEF_LISTBOX_HIGHLIGHT_BG, -1,
	 Tk_Offset(Listbox, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	 DEF_LISTBOX_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Listbox, highlightColorPtr),
	 DEF_LISTBOX_HIGHLIGHT, -1, Tk_Offset(Listbox, highlightColorPtr),
	 0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	 "HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	 offsetof(Listbox, highlightWidth), 0, 0, 0},
	 "HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH, -1,
	 Tk_Offset(Listbox, highlightWidth), 0, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_LISTBOX_JUSTIFY, TCL_INDEX_NONE, offsetof(Listbox, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_LISTBOX_JUSTIFY, -1, Tk_Offset(Listbox, justify), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	 DEF_LISTBOX_RELIEF, TCL_INDEX_NONE, offsetof(Listbox, relief), 0, 0, 0},
	 DEF_LISTBOX_RELIEF, -1, Tk_Offset(Listbox, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
	 DEF_LISTBOX_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Listbox, selBorder),
	 DEF_LISTBOX_SELECT_COLOR, -1, Tk_Offset(Listbox, selBorder),
	 0, DEF_LISTBOX_SELECT_MONO, 0},
    {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
	 "BorderWidth", DEF_LISTBOX_SELECT_BD, TCL_INDEX_NONE,
	 offsetof(Listbox, selBorderWidth), 0, 0, 0},
	 "BorderWidth", DEF_LISTBOX_SELECT_BD, -1,
	 Tk_Offset(Listbox, selBorderWidth), 0, 0, 0},
    {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
	 DEF_LISTBOX_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(Listbox, selFgColorPtr),
	 DEF_LISTBOX_SELECT_FG_COLOR, -1, Tk_Offset(Listbox, selFgColorPtr),
	 TK_OPTION_NULL_OK, DEF_LISTBOX_SELECT_FG_MONO, 0},
    {TK_OPTION_STRING, "-selectmode", "selectMode", "SelectMode",
	 DEF_LISTBOX_SELECT_MODE, TCL_INDEX_NONE, offsetof(Listbox, selectMode),
	 DEF_LISTBOX_SELECT_MODE, -1, Tk_Offset(Listbox, selectMode),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-setgrid", "setGrid", "SetGrid",
	 DEF_LISTBOX_SET_GRID, TCL_INDEX_NONE, offsetof(Listbox, setGrid), 0, 0, 0},
	 DEF_LISTBOX_SET_GRID, -1, Tk_Offset(Listbox, setGrid), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_LISTBOX_STATE, TCL_INDEX_NONE, offsetof(Listbox, state),
	0, &tkStateStrings[1], 0},
	DEF_LISTBOX_STATE, -1, Tk_Offset(Listbox, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	 DEF_LISTBOX_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(Listbox, takeFocus),
	 DEF_LISTBOX_TAKE_FOCUS, -1, Tk_Offset(Listbox, takeFocus),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INT, "-width", "width", "Width",
	 DEF_LISTBOX_WIDTH, TCL_INDEX_NONE, offsetof(Listbox, width), 0, 0, 0},
	 DEF_LISTBOX_WIDTH, -1, Tk_Offset(Listbox, width), 0, 0, 0},
    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	 DEF_LISTBOX_SCROLL_COMMAND, TCL_INDEX_NONE, offsetof(Listbox, xScrollCmd),
	 DEF_LISTBOX_SCROLL_COMMAND, -1, Tk_Offset(Listbox, xScrollCmd),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
	 DEF_LISTBOX_SCROLL_COMMAND, TCL_INDEX_NONE, offsetof(Listbox, yScrollCmd),
	 DEF_LISTBOX_SCROLL_COMMAND, -1, Tk_Offset(Listbox, yScrollCmd),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-listvariable", "listVariable", "Variable",
	 DEF_LISTBOX_LIST_VARIABLE, TCL_INDEX_NONE, offsetof(Listbox, listVarName),
	 DEF_LISTBOX_LIST_VARIABLE, -1, Tk_Offset(Listbox, listVarName),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * The itemAttrOptionSpecs table defines the valid configuration options for
 * listbox items.
 */

static const Tk_OptionSpec itemAttrOptionSpecs[] = {
    {TK_OPTION_BORDER, "-background", NULL, NULL,
     NULL, TCL_INDEX_NONE, offsetof(ItemAttr, border),
     TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
     NULL, -1, Tk_Offset(ItemAttr, border),
     TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT,
     DEF_LISTBOX_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
     NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
     NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
     NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
    {TK_OPTION_COLOR, "-foreground", NULL, NULL,
     NULL, TCL_INDEX_NONE, offsetof(ItemAttr, fgColor),
     TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BORDER, "-selectbackground", NULL, NULL,
     NULL, TCL_INDEX_NONE, offsetof(ItemAttr, selBorder),
     TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_COLOR, "-selectforeground", NULL, NULL,
     NULL, TCL_INDEX_NONE, offsetof(ItemAttr, selFgColor),
     TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, NULL, 0}
     NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
     NULL, -1, Tk_Offset(ItemAttr, fgColor),
     TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
     NULL, -1, Tk_Offset(ItemAttr, selBorder),
     TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT,
     DEF_LISTBOX_SELECT_MONO, 0},
    {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
     NULL, -1, Tk_Offset(ItemAttr, selFgColor),
     TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT,
     DEF_LISTBOX_SELECT_FG_MONO, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * The following tables define the listbox widget commands (and sub-commands)
 * and map the indexes into the string tables into enumerated types used to
 * dispatch the listbox widget command.
 */
359
360
361
362
363
364
365
366

367
368
369

370
371
372
373

374
375
376

377
378
379
380
381
382
383
384
385
386

387
388
389


390
391
392
393


394
395

396
397

398
399
400


401
402
403

404
405
406
407



408
409
410

411
412
413
414
415
416



417
418
419
420

421
422

423
424

425
426
427

428
429

430
431
432
433

434
435
436
437
438
439
440
366
367
368
369
370
371
372

373
374
375

376
377
378
379

380
381
382

383
384
385
386
387
388
389
390
391
392

393
394


395
396
397
398


399
400
401

402
403

404
405


406
407
408
409

410
411



412
413
414
415
416

417
418
419
420
421
422

423
424
425
426
427
428

429
430

431
432

433
434
435

436
437

438
439
440
441

442
443
444
445
446
447
448
449







-
+


-
+



-
+


-
+









-
+

-
-
+
+


-
-
+
+

-
+

-
+

-
-
+
+


-
+

-
-
-
+
+
+


-
+





-
+
+
+



-
+

-
+

-
+


-
+

-
+



-
+







    "anchor", "clear", "includes", "set", NULL
};
enum selcommand {
    SELECTION_ANCHOR, SELECTION_CLEAR, SELECTION_INCLUDES, SELECTION_SET
};

static const char *const scanCommandNames[] = {
    "dragto", "mark", NULL
    "mark", "dragto", NULL
};
enum scancommand {
    SCAN_DRAGTO, SCAN_MARK
    SCAN_MARK, SCAN_DRAGTO
};

static const char *const indexNames[] = {
    "active", "anchor", NULL
    "active", "anchor", "end", NULL
};
enum indices {
    INDEX_ACTIVE, INDEX_ANCHOR
    INDEX_ACTIVE, INDEX_ANCHOR, INDEX_END
};

/*
 * Declarations for procedures defined later in this file.
 */

static void		ChangeListboxOffset(Listbox *listPtr, int offset);
static void		ChangeListboxView(Listbox *listPtr, int index);
static int		ConfigureListbox(Tcl_Interp *interp, Listbox *listPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		ConfigureListboxItem(Tcl_Interp *interp,
			    Listbox *listPtr, ItemAttr *attrs, Tcl_Size objc,
			    Tcl_Obj *const objv[], Tcl_Size index);
			    Listbox *listPtr, ItemAttr *attrs, int objc,
			    Tcl_Obj *const objv[], int index);
static int		ListboxDeleteSubCmd(Listbox *listPtr,
			    int first, int last);
static Tcl_FreeProc	DestroyListbox;
static void		DestroyListboxOptionTables(void *clientData,
static void		DestroyListbox(void *memPtr);
static void		DestroyListboxOptionTables(ClientData clientData,
			    Tcl_Interp *interp);
static void		DisplayListbox(void *clientData);
static void		DisplayListbox(ClientData clientData);
static int		GetListboxIndex(Tcl_Interp *interp, Listbox *listPtr,
			    Tcl_Obj *index, int endIsSize, Tcl_Size *indexPtr);
			    Tcl_Obj *index, int endIsSize, int *indexPtr);
static int		ListboxInsertSubCmd(Listbox *listPtr,
			    Tcl_Size index, Tcl_Size objc, Tcl_Obj *const objv[]);
static void		ListboxCmdDeletedProc(void *clientData);
			    int index, int objc, Tcl_Obj *const objv[]);
static void		ListboxCmdDeletedProc(ClientData clientData);
static void		ListboxComputeGeometry(Listbox *listPtr,
			    int fontChanged, int maxIsStale, int updateGrid);
static void		ListboxEventProc(void *clientData,
static void		ListboxEventProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_Size	ListboxFetchSelection(void *clientData,
			    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
static void		ListboxLostSelection(void *clientData);
static int		ListboxFetchSelection(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static void		ListboxLostSelection(ClientData clientData);
static void		GenerateListboxSelectEvent(Listbox *listPtr);
static void		EventuallyRedrawRange(Listbox *listPtr,
			    Tcl_Size first, Tcl_Size last);
			    int first, int last);
static void		ListboxScanTo(Listbox *listPtr, int x, int y);
static int		ListboxSelect(Listbox *listPtr,
			    int first, int last, int select);
static void		ListboxUpdateHScrollbar(Listbox *listPtr);
static void		ListboxUpdateVScrollbar(Listbox *listPtr);
static Tcl_ObjCmdProc ListboxWidgetObjCmd;
static int		ListboxWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		ListboxBboxSubCmd(Tcl_Interp *interp,
			    Listbox *listPtr, int index);
static int		ListboxSelectionSubCmd(Tcl_Interp *interp,
			    Listbox *listPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Listbox *listPtr, int objc, Tcl_Obj *const objv[]);
static int		ListboxXviewSubCmd(Tcl_Interp *interp,
			    Listbox *listPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Listbox *listPtr, int objc, Tcl_Obj *const objv[]);
static int		ListboxYviewSubCmd(Tcl_Interp *interp,
			    Listbox *listPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Listbox *listPtr, int objc, Tcl_Obj *const objv[]);
static ItemAttr *	ListboxGetItemAttributes(Tcl_Interp *interp,
			    Listbox *listPtr, int index);
static void		ListboxWorldChanged(void *instanceData);
static void		ListboxWorldChanged(ClientData instanceData);
static int		NearestListboxElement(Listbox *listPtr, int y);
static char *		ListboxListVarProc(void *clientData,
static char *		ListboxListVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static void		MigrateHashEntries(Tcl_HashTable *table,
			    Tcl_Size first, Tcl_Size last, Tcl_Size offset);
			    int first, int last, int offset);
static int		GetMaxOffset(Listbox *listPtr);

/*
 * The structure below defines button class behavior by means of procedures
 * that can be invoked from generic window code.
 */

460
461
462
463
464
465
466
467

468
469
470
471
472

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487

488
489
490
491

492
493
494
495

496
497
498
499
500
501
502
469
470
471
472
473
474
475

476
477
478
479
480

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495

496
497
498
499

500
501
502
503

504
505
506
507
508
509
510
511







-
+




-
+














-
+



-
+



-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_ListboxObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Listbox *listPtr;
    register Listbox *listPtr;
    Tk_Window tkwin;
    ListboxOptionTables *optionTables;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

    tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
	    Tcl_GetString(objv[1]), NULL);
    if (tkwin == NULL) {
	return TCL_ERROR;
    }

    optionTables = (ListboxOptionTables *)Tcl_GetAssocData(interp, "ListboxOptionTables", NULL);
    optionTables = Tcl_GetAssocData(interp, "ListboxOptionTables", NULL);
    if (optionTables == NULL) {
	/*
	 * We haven't created the option tables for this widget class yet. Do
	 * it now and save the a pointer to them as the void *for the
	 * it now and save the a pointer to them as the ClientData for the
	 * command, so future invocations will have access to it.
	 */

	optionTables = (ListboxOptionTables *)ckalloc(sizeof(ListboxOptionTables));
	optionTables = ckalloc(sizeof(ListboxOptionTables));

	/*
	 * Set up an exit handler to free the optionTables struct.
	 */

	Tcl_SetAssocData(interp, "ListboxOptionTables",
		DestroyListboxOptionTables, optionTables);
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528
529
530
531

532
533

534
535
536
537
538



539
540
541
542

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579
522
523
524
525
526
527
528

529
530
531
532
533
534
535
536
537
538
539

540
541

542
543
544



545
546
547
548
549
550

551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588







-
+










-
+

-
+


-
-
-
+
+
+



-
+


















-
+










-
+








    /*
     * Initialize the fields of the structure that won't be initialized by
     * ConfigureListbox, or that ConfigureListbox requires to be initialized
     * already (e.g. resource pointers).
     */

    listPtr			 = (Listbox *)ckalloc(sizeof(Listbox));
    listPtr			 = ckalloc(sizeof(Listbox));
    memset(listPtr, 0, sizeof(Listbox));

    listPtr->tkwin		 = tkwin;
    listPtr->display		 = Tk_Display(tkwin);
    listPtr->interp		 = interp;
    listPtr->widgetCmd		 = Tcl_CreateObjCommand(interp,
	    Tk_PathName(listPtr->tkwin), ListboxWidgetObjCmd, listPtr,
	    ListboxCmdDeletedProc);
    listPtr->optionTable	 = optionTables->listboxOptionTable;
    listPtr->itemAttrOptionTable = optionTables->itemAttrOptionTable;
    listPtr->selection		 = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
    listPtr->selection		 = ckalloc(sizeof(Tcl_HashTable));
    Tcl_InitHashTable(listPtr->selection, TCL_ONE_WORD_KEYS);
    listPtr->itemAttrTable	 = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
    listPtr->itemAttrTable	 = ckalloc(sizeof(Tcl_HashTable));
    Tcl_InitHashTable(listPtr->itemAttrTable, TCL_ONE_WORD_KEYS);
    listPtr->relief		 = TK_RELIEF_RAISED;
    listPtr->textGC		 = NULL;
    listPtr->selFgColorPtr	 = NULL;
    listPtr->selTextGC		 = NULL;
    listPtr->textGC		 = None;
    listPtr->selFgColorPtr	 = None;
    listPtr->selTextGC		 = None;
    listPtr->fullLines		 = 1;
    listPtr->xScrollUnit	 = 1;
    listPtr->exportSelection	 = 1;
    listPtr->cursor		 = NULL;
    listPtr->cursor		 = None;
    listPtr->state		 = STATE_NORMAL;
    listPtr->gray		 = None;
    listPtr->justify             = TK_JUSTIFY_LEFT;

    /*
     * Keep a hold of the associated tkwin until we destroy the listbox,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(listPtr->tkwin);

    Tk_SetClass(listPtr->tkwin, "Listbox");
    Tk_SetClassProcs(listPtr->tkwin, &listboxClass, listPtr);
    Tk_CreateEventHandler(listPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    ListboxEventProc, listPtr);
    Tk_CreateSelHandler(listPtr->tkwin, XA_PRIMARY, XA_STRING,
	    ListboxFetchSelection, listPtr, XA_STRING);
    if (Tk_InitOptions(interp, listPtr,
    if (Tk_InitOptions(interp, (char *)listPtr,
	    optionTables->listboxOptionTable, tkwin) != TCL_OK) {
	Tk_DestroyWindow(listPtr->tkwin);
	return TCL_ERROR;
    }

    if (ConfigureListbox(interp, listPtr, objc-2, objv+2) != TCL_OK) {
	Tk_DestroyWindow(listPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(listPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(listPtr->tkwin));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ListboxWidgetObjCmd --
589
590
591
592
593
594
595
596

597
598
599
600
601
602


603
604
605
606
607
608
609
610
598
599
600
601
602
603
604

605
606
607
608
609


610
611

612
613
614
615
616
617
618







-
+




-
-
+
+
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ListboxWidgetObjCmd(
    void *clientData,	/* Information about listbox widget. */
    ClientData clientData,	/* Information about listbox widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Arguments as Tcl_Obj's. */
{
    Listbox *listPtr = (Listbox *)clientData;
    int cmdIndex;
    register Listbox *listPtr = clientData;
    int cmdIndex, index;
    Tcl_Size index;
    int result = TCL_OK;
    Tcl_Obj *objPtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704







-
+











-
+







    case COMMAND_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    break;
	}

	objPtr = Tk_GetOptionValue(interp, listPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) listPtr,
		listPtr->optionTable, objv[2], listPtr->tkwin);
	if (objPtr == NULL) {
	    result = TCL_ERROR;
	    break;
	}
	Tcl_SetObjResult(interp, objPtr);
	result = TCL_OK;
	break;

    case COMMAND_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, listPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) listPtr,
		    listPtr->optionTable,
		    (objc == 3) ? objv[2] : NULL, listPtr->tkwin);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
		break;
	    }
	    Tcl_SetObjResult(interp, objPtr);
714
715
716
717
718
719
720
721

722
723

724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793

794
795
796
797

798
799
800
801
802
803
804
722
723
724
725
726
727
728

729
730

731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
778
779
780
781

782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800

801
802
803
804

805
806
807
808
809
810
811
812







-
+

-
+








-
+
















-
+













-
+










-
+


















-
+



-
+







	 * search functions (Tcl_FirstHashEntry, Tcl_NextHashEntry), but then
	 * the result wouldn't be in sorted order. So instead we loop through
	 * the indices in order, adding them to the result if they are
	 * selected.
	 */

	objPtr = Tcl_NewObj();
	for (i = 0; i < (int)listPtr->nElements; i++) {
	for (i = 0; i < listPtr->nElements; i++) {
	    if (Tcl_FindHashEntry(listPtr->selection, KEY(i))) {
		Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewWideIntObj(i));
		Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewIntObj(i));
	    }
	}
	Tcl_SetObjResult(interp, objPtr);
	result = TCL_OK;
	break;
    }

    case COMMAND_DELETE: {
	Tcl_Size first, last;
	int first, last;

	if ((objc < 3) || (objc > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?");
	    result = TCL_ERROR;
	    break;
	}

	result = GetListboxIndex(interp, listPtr, objv[2], 0, &first);
	if (result != TCL_OK) {
	    break;
	}

	if (!(listPtr->state & STATE_NORMAL)) {
	    break;
	}

	if (first < (int)listPtr->nElements) {
	if (first < listPtr->nElements) {
	    /*
	     * if a "last index" was given, get it now; otherwise, use the
	     * first index as the last index.
	     */

	    if (objc == 4) {
		result = GetListboxIndex(interp, listPtr, objv[3], 0, &last);
		if (result != TCL_OK) {
		    break;
		}
	    } else {
		last = first;
	    }
	    if (last >= (int)listPtr->nElements) {
	    if (last >= listPtr->nElements) {
		last = listPtr->nElements - 1;
	    }
	    result = ListboxDeleteSubCmd(listPtr, first, last);
	} else {
	    result = TCL_OK;
	}
	break;
    }

    case COMMAND_GET: {
	Tcl_Size listLen, first, last;
	int first, last, listLen;
	Tcl_Obj **elemPtrs;

	if (objc != 3 && objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?");
	    result = TCL_ERROR;
	    break;
	}
	result = GetListboxIndex(interp, listPtr, objv[2], 0, &first);
	if (result != TCL_OK) {
	    break;
	}
	last = first;
	if (objc == 4) {
	    result = GetListboxIndex(interp, listPtr, objv[3], 0, &last);
	    if (result != TCL_OK) {
		break;
	    }
	}
	if (first >= (int)listPtr->nElements) {
	if (first >= listPtr->nElements) {
	    result = TCL_OK;
	    break;
	}
	if (last >= (int)listPtr->nElements) {
	if (last >= listPtr->nElements) {
	    last = listPtr->nElements - 1;
	}
	if (first < 0) {
	    first = 0;
	}
	if (first > last) {
	    result = TCL_OK;
829
830
831
832
833
834
835
836

837
838
839
840
841
842
843
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851







-
+







	    result = TCL_ERROR;
	    break;
	}
	result = GetListboxIndex(interp, listPtr, objv[2], 1, &index);
	if (result != TCL_OK) {
	    break;
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	result = TCL_OK;
	break;

    case COMMAND_INSERT:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index ?element ...?");
	    result = TCL_ERROR;
866
867
868
869
870
871
872
873

874
875
876
877
878
879
880
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888







-
+







	}

	result = GetListboxIndex(interp, listPtr, objv[2], 0, &index);
	if (result != TCL_OK) {
	    break;
	}

	if (index < 0 || index >= (int)listPtr->nElements) {
	if (index < 0 || index >= listPtr->nElements) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "item number \"%s\" out of range",
		    Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "LISTBOX", "ITEM_INDEX", NULL);
	    result = TCL_ERROR;
	    break;
	}
893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921

922
923
924
925
926
927
928
901
902
903
904
905
906
907

908
909
910
911
912
913
914
915
916
917

918
919
920
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936







-
+









-
+










-
+







    }

    case COMMAND_ITEMCONFIGURE: {
	ItemAttr *attrPtr;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "index ?-option value ...?");
		    "index ?-option? ?value? ?-option value ...?");
	    result = TCL_ERROR;
	    break;
	}

	result = GetListboxIndex(interp, listPtr, objv[2], 0, &index);
	if (result != TCL_OK) {
	    break;
	}

	if (index < 0 || index >= (int)listPtr->nElements) {
	if (index < 0 || index >= listPtr->nElements) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "item number \"%s\" out of range",
		    Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "LISTBOX", "ITEM_INDEX", NULL);
	    result = TCL_ERROR;
	    break;
	}

	attrPtr = ListboxGetItemAttributes(interp, listPtr, index);
	if (objc <= 4) {
	    objPtr = Tk_GetOptionInfo(interp, attrPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) attrPtr,
		    listPtr->itemAttrOptionTable,
		    (objc == 4) ? objv[3] : NULL, listPtr->tkwin);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
		break;
	    }
	    Tcl_SetObjResult(interp, objPtr);
944
945
946
947
948
949
950
951

952
953
954
955
956
957
958
952
953
954
955
956
957
958

959
960
961
962
963
964
965
966







-
+







	}

	result = Tcl_GetIntFromObj(interp, objv[2], &y);
	if (result != TCL_OK) {
	    break;
	}
	index = NearestListboxElement(listPtr, y);
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	result = TCL_OK;
	break;
    }

    case COMMAND_SCAN: {
	int x, y, scanCmdIndex;

996
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018







-
+







	    result = TCL_ERROR;
	    break;
	}
	result = GetListboxIndex(interp, listPtr, objv[2], 0, &index);
	if (result != TCL_OK) {
	    break;
	}
	if (index >= (int)listPtr->nElements) {
	if (index >= listPtr->nElements) {
	    index = listPtr->nElements - 1;
	}
	if (index < 0) {
	    index = 0;
	}
	diff = listPtr->topIndex - index;
	if (diff > 0) {
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054







-
+







	break;
    case COMMAND_SIZE:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    result = TCL_ERROR;
	    break;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(listPtr->nElements));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(listPtr->nElements));
	result = TCL_OK;
	break;
    case COMMAND_XVIEW:
	result = ListboxXviewSubCmd(interp, listPtr, objc, objv);
	break;
    case COMMAND_YVIEW:
	result = ListboxYviewSubCmd(interp, listPtr, objc, objv);
1070
1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104
1105
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105

1106
1107
1108
1109
1110
1111
1112







-
+








-
+










-
+
-








static int
ListboxBboxSubCmd(
    Tcl_Interp *interp,		/* Pointer to the calling Tcl interpreter */
    Listbox *listPtr,		/* Information about the listbox */
    int index)			/* Index of the element to get bbox info on */
{
    Tk_Window tkwin = listPtr->tkwin;
    register Tk_Window tkwin = listPtr->tkwin;
    int lastVisibleIndex;

    /*
     * Determine the index of the last visible item in the listbox.
     */

    lastVisibleIndex = listPtr->topIndex + listPtr->fullLines
	    + listPtr->partialLine;
    if ((int)listPtr->nElements < lastVisibleIndex) {
    if (listPtr->nElements < lastVisibleIndex) {
	lastVisibleIndex = listPtr->nElements;
    }

    /*
     * Only allow bbox requests for indices that are visible.
     */

    if ((listPtr->topIndex <= index) && (index < lastVisibleIndex)) {
	Tcl_Obj *el, *results[4];
	const char *stringRep;
	int pixelWidth, x, y, result;
	int pixelWidth, stringLen, x, y, result;
	Tcl_Size stringLen;
	Tk_FontMetrics fm;

	/*
	 * Compute the pixel width of the requested element.
	 */

	result = Tcl_ListObjIndex(interp, listPtr->listObj, index, &el);
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128




1129
1130
1131
1132
1133
1134
1135
1125
1126
1127
1128
1129
1130
1131




1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142







-
-
-
-
+
+
+
+







                    - pixelWidth - listPtr->xOffset + GetMaxOffset(listPtr);
        } else {
            x = (Tk_Width(tkwin) - pixelWidth)/2
                    - listPtr->xOffset + GetMaxOffset(listPtr)/2;
        }
	y = ((index - listPtr->topIndex)*listPtr->lineHeight)
		+ listPtr->inset + listPtr->selBorderWidth;
	results[0] = Tcl_NewWideIntObj(x);
	results[1] = Tcl_NewWideIntObj(y);
	results[2] = Tcl_NewWideIntObj(pixelWidth);
	results[3] = Tcl_NewWideIntObj(fm.linespace);
	results[0] = Tcl_NewIntObj(x);
	results[1] = Tcl_NewIntObj(y);
	results[2] = Tcl_NewIntObj(pixelWidth);
	results[3] = Tcl_NewIntObj(fm.linespace);
	Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164

1165

1166
1167
1168
1169
1170
1171
1172







-
+


-
+
-







 *----------------------------------------------------------------------
 */

static int
ListboxSelectionSubCmd(
    Tcl_Interp *interp,		/* Pointer to the calling Tcl interpreter */
    Listbox *listPtr,		/* Information about the listbox */
    Tcl_Size objc,			/* Number of arguments in the objv array */
    int objc,			/* Number of arguments in the objv array */
    Tcl_Obj *const objv[])	/* Array of arguments to the procedure */
{
    int selCmdIndex;
    int selCmdIndex, first, last;
    Tcl_Size first, last;
    int result = TCL_OK;

    if (objc != 4 && objc != 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "option index ?index?");
	return TCL_ERROR;
    }
    result = GetListboxIndex(interp, listPtr, objv[3], 0, &first);
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211







-
+








    switch (selCmdIndex) {
    case SELECTION_ANCHOR:
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 3, objv, "index");
	    return TCL_ERROR;
	}
	if (first >= (int)listPtr->nElements) {
	if (first >= listPtr->nElements) {
	    first = listPtr->nElements - 1;
	}
	if (first < 0) {
	    first = 0;
	}
	listPtr->selectAnchor = first;
	result = TCL_OK;
1239
1240
1241
1242
1243
1244
1245
1246

1247
1248
1249
1250
1251
1252
1253
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259







-
+







 *----------------------------------------------------------------------
 */

static int
ListboxXviewSubCmd(
    Tcl_Interp *interp,		/* Pointer to the calling Tcl interpreter */
    Listbox *listPtr,		/* Information about the listbox */
    Tcl_Size objc,			/* Number of arguments in the objv array */
    int objc,			/* Number of arguments in the objv array */
    Tcl_Obj *const objv[])	/* Array of arguments to the procedure */
{
    int index, count, windowWidth, windowUnits;
    int offset = 0;		/* Initialized to stop gcc warnings. */
    double fraction;

    windowWidth = Tk_Width(listPtr->tkwin)
1274
1275
1276
1277
1278
1279
1280


1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303


1304
1305
1306
1307
1308
1309
1310







+
+















-
-







    } else if (objc == 3) {
	if (Tcl_GetIntFromObj(interp, objv[2], &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	ChangeListboxOffset(listPtr, index*listPtr->xScrollUnit);
    } else {
	switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count)) {
	case TK_SCROLL_ERROR:
	    return TCL_ERROR;
	case TK_SCROLL_MOVETO:
	    offset = (int) (fraction*listPtr->maxWidth + 0.5);
	    break;
	case TK_SCROLL_PAGES:
	    windowUnits = windowWidth / listPtr->xScrollUnit;
	    if (windowUnits > 2) {
		offset = listPtr->xOffset
			+ count*listPtr->xScrollUnit*(windowUnits-2);
	    } else {
		offset = listPtr->xOffset + count*listPtr->xScrollUnit;
	    }
	    break;
	case TK_SCROLL_UNITS:
	    offset = listPtr->xOffset + count*listPtr->xScrollUnit;
	    break;
	default:
	    return TCL_ERROR;
	}
	ChangeListboxOffset(listPtr, offset);
    }
    return TCL_OK;
}

/*
1317
1318
1319
1320
1321
1322
1323
1324

1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1323
1324
1325
1326
1327
1328
1329

1330
1331
1332


1333
1334
1335
1336
1337
1338
1339
1340







-
+


-
-
+







 *----------------------------------------------------------------------
 */

static int
ListboxYviewSubCmd(
    Tcl_Interp *interp,		/* Pointer to the calling Tcl interpreter */
    Listbox *listPtr,		/* Information about the listbox */
    Tcl_Size objc,			/* Number of arguments in the objv array */
    int objc,			/* Number of arguments in the objv array */
    Tcl_Obj *const objv[])	/* Array of arguments to the procedure */
{
    Tcl_Size index;
    int count;
    int index, count;
    double fraction;

    if (objc == 2) {
	Tcl_Obj *results[2];

	if (listPtr->nElements == 0) {
	    results[0] = Tcl_NewDoubleObj(0.0);
1350
1351
1352
1353
1354
1355
1356
1357

1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381







-
+











+







	if (GetListboxIndex(interp, listPtr, objv[2], 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	ChangeListboxView(listPtr, index);
    } else {
	switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count)) {
	case TK_SCROLL_MOVETO:
	    index = (Tcl_Size)(listPtr->nElements*fraction + 0.5);
	    index = (int) (listPtr->nElements*fraction + 0.5);
	    break;
	case TK_SCROLL_PAGES:
	    if (listPtr->fullLines > 2) {
		index = listPtr->topIndex + count*(listPtr->fullLines-2);
	    } else {
		index = listPtr->topIndex + count;
	    }
	    break;
	case TK_SCROLL_UNITS:
	    index = listPtr->topIndex + count;
	    break;
	case TK_SCROLL_ERROR:
	default:
	    return TCL_ERROR;
	}
	ChangeListboxView(listPtr, index);
    }
    return TCL_OK;
}
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412

1413
1414
1415
1416

1417
1418
1419
1420
1421
1422
1423
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417

1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429







-
+




-
+



-
+







{
    int isNew;
    Tcl_HashEntry *entry;
    ItemAttr *attrs;

    entry = Tcl_CreateHashEntry(listPtr->itemAttrTable, KEY(index), &isNew);
    if (isNew) {
	attrs = (ItemAttr *)ckalloc(sizeof(ItemAttr));
	attrs = ckalloc(sizeof(ItemAttr));
	attrs->border = NULL;
	attrs->selBorder = NULL;
	attrs->fgColor = NULL;
	attrs->selFgColor = NULL;
	Tk_InitOptions(interp, attrs, listPtr->itemAttrOptionTable,
	Tk_InitOptions(interp, (char *)attrs, listPtr->itemAttrOptionTable,
		listPtr->tkwin);
	Tcl_SetHashValue(entry, attrs);
    } else {
	attrs = (ItemAttr *)Tcl_GetHashValue(entry);
	attrs = Tcl_GetHashValue(entry);
    }
    return attrs;
}

/*
 *----------------------------------------------------------------------
 *
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1440
1441
1442
1443
1444
1445
1446

1447



1448

1449
1450
1451
1452
1453
1454
1455
1456







-

-
-
-

-
+







 *	Everything associated with the listbox is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyListbox(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about listbox widget. */
#else
    char *memPtr)
#endif
{
    Listbox *listPtr = (Listbox *)memPtr;
    register Listbox *listPtr = memPtr;
    Tcl_HashEntry *entry;
    Tcl_HashSearch search;

    /*
     * If we have an internal list object, free it.
     */

1482
1483
1484
1485
1486
1487
1488
1489

1490
1491
1492

1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1484
1485
1486
1487
1488
1489
1490

1491
1492
1493

1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508







-
+


-
+






-
+







    ckfree(listPtr->itemAttrTable);

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeOptions handle all the standard option-related stuff.
     */

    if (listPtr->textGC != NULL) {
    if (listPtr->textGC != None) {
	Tk_FreeGC(listPtr->display, listPtr->textGC);
    }
    if (listPtr->selTextGC != NULL) {
    if (listPtr->selTextGC != None) {
	Tk_FreeGC(listPtr->display, listPtr->selTextGC);
    }
    if (listPtr->gray != None) {
	Tk_FreeBitmap(Tk_Display(listPtr->tkwin), listPtr->gray);
    }

    Tk_FreeConfigOptions(listPtr, listPtr->optionTable,
    Tk_FreeConfigOptions((char *) listPtr, listPtr->optionTable,
	    listPtr->tkwin);
    Tcl_Release(listPtr->tkwin);
    listPtr->tkwin = NULL;
    ckfree(listPtr);
}

/*
1519
1520
1521
1522
1523
1524
1525
1526
1527


1528
1529
1530
1531
1532
1533
1534
1521
1522
1523
1524
1525
1526
1527


1528
1529
1530
1531
1532
1533
1534
1535
1536







-
-
+
+







 *	Frees memory.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyListboxOptionTables(
    void *clientData,	/* Pointer to the OptionTables struct */
    TCL_UNUSED(Tcl_Interp *))		/* Pointer to the calling interp */
    ClientData clientData,	/* Pointer to the OptionTables struct */
    Tcl_Interp *interp)		/* Pointer to the calling interp */
{
    ckfree(clientData);
    return;
}

/*
 *----------------------------------------------------------------------
1549
1550
1551
1552
1553
1554
1555
1556

1557
1558

1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1551
1552
1553
1554
1555
1556
1557

1558
1559

1560
1561
1562
1563
1564
1565
1566
1567

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580

1581
1582
1583
1584
1585
1586
1587
1588







-
+

-
+







-
+












-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureListbox(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Listbox *listPtr,	/* Information about widget; may or may not
    register Listbox *listPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    Tk_SavedOptions savedOptions;
    Tcl_Obj *oldListObj = NULL;
    Tcl_Obj *errorResult = NULL;
    int oldExport, error;

    oldExport = (listPtr->exportSelection) && (!Tcl_IsSafe(listPtr->interp));
    oldExport = listPtr->exportSelection;
    if (listPtr->listVarName != NULL) {
	Tcl_UntraceVar2(interp, listPtr->listVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		ListboxListVarProc, listPtr);
    }

    for (error = 0; error <= 1; error++) {
	if (!error) {
	    /*
	     * First pass: set options to new values.
	     */

	    if (Tk_SetOptions(interp, listPtr,
	    if (Tk_SetOptions(interp, (char *) listPtr,
		    listPtr->optionTable, objc, objv,
		    listPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
		continue;
	    }
	} else {
	    /*
	     * Second pass: restore options to old values.
1601
1602
1603
1604
1605
1606
1607
1608

1609
1610
1611

1612
1613
1614
1615
1616
1617
1618
1619
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612

1613

1614
1615
1616
1617
1618
1619
1620







-
+


-
+
-







	if (listPtr->highlightWidth < 0) {
	    listPtr->highlightWidth = 0;
	}
	listPtr->inset = listPtr->highlightWidth + listPtr->borderWidth;

	/*
	 * Claim the selection if we've suddenly started exporting it and
	 * there is a selection to export and this interp is unsafe.
	 * there is a selection to export.
	 */

	if (listPtr->exportSelection && (!oldExport)
	if (listPtr->exportSelection && !oldExport
		&& (!Tcl_IsSafe(listPtr->interp))
		&& (listPtr->numSelected != 0)) {
	    Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY,
		    ListboxLostSelection, listPtr);
	}

	/*
	 * Verify the current status of the list var.
1632
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
1647







-
+







	 * no listvar     | no listvar | no special action
	 */

	oldListObj = listPtr->listObj;
	if (listPtr->listVarName != NULL) {
	    Tcl_Obj *listVarObj = Tcl_GetVar2Ex(interp, listPtr->listVarName,
		    NULL, TCL_GLOBAL_ONLY);
	    Tcl_Size dummy;
	    int dummy;

	    if (listVarObj == NULL) {
		listVarObj = (oldListObj ? oldListObj : Tcl_NewObj());
		if (Tcl_SetVar2Ex(interp, listPtr->listVarName, NULL,
			listVarObj, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG)
			== NULL) {
		    continue;
1709
1710
1711
1712
1713
1714
1715
1716

1717
1718
1719

1720
1721

1722
1723
1724
1725

1726
1727
1728
1729
1730
1731
1732
1710
1711
1712
1713
1714
1715
1716

1717
1718
1719

1720
1721

1722
1723
1724
1725

1726
1727
1728
1729
1730
1731
1732
1733







-
+


-
+

-
+



-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureListboxItem(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Listbox *listPtr,	/* Information about widget; may or may not
    register Listbox *listPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    ItemAttr *attrs,		/* Information about the item to configure */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[],	/* Arguments. */
    Tcl_Size index)			/* Index of the listbox item being configure */
    int index)			/* Index of the listbox item being configure */
{
    Tk_SavedOptions savedOptions;

    if (Tk_SetOptions(interp, attrs,
    if (Tk_SetOptions(interp, (char *)attrs,
	    listPtr->itemAttrOptionTable, objc, objv, listPtr->tkwin,
	    &savedOptions, NULL) != TCL_OK) {
	Tk_RestoreSavedOptions(&savedOptions);
	return TCL_ERROR;
    }
    Tk_FreeSavedOptions(&savedOptions);

1755
1756
1757
1758
1759
1760
1761
1762

1763
1764
1765
1766
1767

1768
1769
1770
1771
1772
1773
1774
1756
1757
1758
1759
1760
1761
1762

1763
1764
1765
1766
1767

1768
1769
1770
1771
1772
1773
1774
1775







-
+




-
+







 *	Listbox will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
ListboxWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC gc;
    unsigned long mask;
    Listbox *listPtr = (Listbox *)instanceData;
    Listbox *listPtr = instanceData;

    if (listPtr->state & STATE_NORMAL) {
	gcValues.foreground = listPtr->fgColorPtr->pixel;
	gcValues.graphics_exposures = False;
	mask = GCForeground | GCFont | GCGraphicsExposures;
    } else if (listPtr->dfgColorPtr != NULL) {
	gcValues.foreground = listPtr->dfgColorPtr->pixel;
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
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







-
+










-
+







	    gcValues.stipple = listPtr->gray;
	    mask |= GCFillStyle | GCStipple;
	}
    }

    gcValues.font = Tk_FontId(listPtr->tkfont);
    gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues);
    if (listPtr->textGC != NULL) {
    if (listPtr->textGC != None) {
	Tk_FreeGC(listPtr->display, listPtr->textGC);
    }
    listPtr->textGC = gc;

    if (listPtr->selFgColorPtr != NULL) {
	gcValues.foreground = listPtr->selFgColorPtr->pixel;
    }
    gcValues.font = Tk_FontId(listPtr->tkfont);
    mask = GCForeground | GCFont;
    gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues);
    if (listPtr->selTextGC != NULL) {
    if (listPtr->selTextGC != None) {
	Tk_FreeGC(listPtr->display, listPtr->selTextGC);
    }
    listPtr->selTextGC = gc;

    /*
     * Register the desired geometry for the window and arrange for the window
     * to be redisplayed.
1829
1830
1831
1832
1833
1834
1835
1836

1837
1838
1839


1840
1841

1842
1843
1844
1845
1846
1847
1848
1849
1830
1831
1832
1833
1834
1835
1836

1837
1838


1839
1840
1841

1842

1843
1844
1845
1846
1847
1848
1849







-
+

-
-
+
+

-
+
-







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayListbox(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    Listbox *listPtr = (Listbox *)clientData;
    Tk_Window tkwin = listPtr->tkwin;
    register Listbox *listPtr = clientData;
    register Tk_Window tkwin = listPtr->tkwin;
    GC gc;
    int i, limit, x, y, prevSelected, freeGC;
    int i, limit, x, y, prevSelected, freeGC, stringLen;
    Tcl_Size stringLen;
    Tk_FontMetrics fm;
    Tcl_Obj *curElement;
    Tcl_HashEntry *entry;
    const char *stringRep;
    ItemAttr *attrs;
    Tk_3DBorder selectedBg;
    XGCValues gcValues;
1901
1902
1903
1904
1905
1906
1907
1908

1909
1910
1911
1912
1913
1914
1915
1901
1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
1915







-
+







	    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);

    /*
     * Display each item in the listbox.
     */

    limit = listPtr->topIndex + listPtr->fullLines + listPtr->partialLine - 1;
    if (limit >= (int)listPtr->nElements) {
    if (limit >= listPtr->nElements) {
	limit = listPtr->nElements-1;
    }
    left = right = 0;
    if (listPtr->xOffset > 0) {
	left = listPtr->selBorderWidth+1;
    }
    if ((listPtr->maxWidth - listPtr->xOffset) > (Tk_Width(listPtr->tkwin)
1951
1952
1953
1954
1955
1956
1957
1958

1959
1960
1961
1962
1963
1964
1965
1951
1952
1953
1954
1955
1956
1957

1958
1959
1960
1961
1962
1963
1964
1965







-
+








		/*
		 * If there is attribute information for this item, adjust the
		 * drawing accordingly.
		 */

		if (entry != NULL) {
		    attrs = (ItemAttr *)Tcl_GetHashValue(entry);
		    attrs = Tcl_GetHashValue(entry);

		    /*
		     * Default GC has the values from the widget at large.
		     */

		    if (listPtr->selFgColorPtr) {
			gcValues.foreground = listPtr->selFgColorPtr->pixel;
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
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







-
+














-
+







		if (!prevSelected) {
		    Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg,
			    x-left, y, width+left+right,
			    listPtr->selBorderWidth,
			    1, 1, 1, TK_RELIEF_RAISED);
		}
		/* Draw bottom bevel */
		if (i + 1 == (int)listPtr->nElements ||
		if (i + 1 == listPtr->nElements ||
			!Tcl_FindHashEntry(listPtr->selection, KEY(i + 1))) {
		    Tk_3DHorizontalBevel(tkwin, pixmap, selectedBg, x-left,
			    y + listPtr->lineHeight - listPtr->selBorderWidth,
			    width+left+right, listPtr->selBorderWidth, 0, 0, 0,
			    TK_RELIEF_RAISED);
		}
		prevSelected = 1;
	    } else {
		/*
		 * If there is an item attributes record for this item, draw
		 * the background box and set the foreground color accordingly.
		 */

		if (entry != NULL) {
		    attrs = (ItemAttr *)Tcl_GetHashValue(entry);
		    attrs = Tcl_GetHashValue(entry);
		    gcValues.foreground = listPtr->fgColorPtr->pixel;
		    gcValues.font = Tk_FontId(listPtr->tkfont);
		    gcValues.graphics_exposures = False;
		    mask = GCForeground | GCFont | GCGraphicsExposures;

		    /*
		     * If the item has its own background color, draw it now.
2182
2183
2184
2185
2186
2187
2188
2189

2190
2191
2192

2193
2194
2195
2196
2197
2198
2199
2182
2183
2184
2185
2186
2187
2188

2189
2190
2191

2192
2193
2194
2195
2196
2197
2198
2199







-
+


-
+







	    listPtr->borderWidth, listPtr->relief);
    if (listPtr->highlightWidth > 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(listPtr->highlightBgColorPtr, pixmap);
	if (listPtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(listPtr->highlightColorPtr, pixmap);
	    Tk_DrawHighlightBorder(tkwin, fgGC, bgGC,
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC,
		    listPtr->highlightWidth, pixmap);
	} else {
	    Tk_DrawHighlightBorder(tkwin, bgGC, bgGC,
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC,
		    listPtr->highlightWidth, pixmap);
	}
    }
#ifndef TK_NO_DOUBLE_BUFFERING
    XCopyArea(listPtr->display, pixmap, Tk_WindowId(tkwin),
	    listPtr->textGC, 0, 0, (unsigned) Tk_Width(tkwin),
	    (unsigned) Tk_Height(tkwin), 0, 0);
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
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







-
+
-










-
+







				 * longer be up-to-date and must be
				 * recomputed. If fontChanged is 1 then this
				 * must be 1. */
    int updateGrid)		/* Non-zero means call Tk_SetGrid or
				 * Tk_UnsetGrid to update gridding for the
				 * window. */
{
    int width, height, pixelWidth, pixelHeight, i, result;
    int width, height, pixelWidth, pixelHeight, textLength, i, result;
    Tcl_Size textLength;
    Tk_FontMetrics fm;
    Tcl_Obj *element;
    const char *text;

    if (fontChanged || maxIsStale) {
	listPtr->xScrollUnit = Tk_TextWidth(listPtr->tkfont, "0", 1);
	if (listPtr->xScrollUnit == 0) {
	    listPtr->xScrollUnit = 1;
	}
	listPtr->maxWidth = 0;
	for (i = 0; i < (int)listPtr->nElements; i++) {
	for (i = 0; i < listPtr->nElements; i++) {
	    /*
	     * Compute the pixel width of the current element.
	     */

	    result = Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i,
		    &element);
	    if (result != TCL_OK) {
2276
2277
2278
2279
2280
2281
2282
2283

2284
2285
2286
2287
2288
2289
2290
2275
2276
2277
2278
2279
2280
2281

2282
2283
2284
2285
2286
2287
2288
2289







-
+







	    width = 1;
	}
    }
    pixelWidth = width*listPtr->xScrollUnit + 2*listPtr->inset
	    + 2*listPtr->selBorderWidth;
    height = listPtr->height;
    if (listPtr->height <= 0) {
	height = (int)listPtr->nElements;
	height = listPtr->nElements;
	if (height < 1) {
	    height = 1;
	}
    }
    pixelHeight = height*listPtr->lineHeight + 2*listPtr->inset;
    Tk_GeometryRequest(listPtr->tkwin, pixelWidth, pixelHeight);
    Tk_SetInternalBorder(listPtr->tkwin, listPtr->inset);
2313
2314
2315
2316
2317
2318
2319
2320
2321


2322
2323

2324
2325
2326

2327
2328
2329
2330
2331
2332
2333
2334
2312
2313
2314
2315
2316
2317
2318


2319
2320
2321

2322
2323
2324

2325

2326
2327
2328
2329
2330
2331
2332







-
-
+
+

-
+


-
+
-







 *	callback is registered for the listbox.
 *
 *----------------------------------------------------------------------
 */

static int
ListboxInsertSubCmd(
    Listbox *listPtr,	/* Listbox that is to get the new elements. */
    Tcl_Size index,		/* Add the new elements before this
    register Listbox *listPtr,	/* Listbox that is to get the new elements. */
    int index,			/* Add the new elements before this
				 * element. */
    Tcl_Size objc,			/* Number of new elements to add. */
    int objc,			/* Number of new elements to add. */
    Tcl_Obj *const objv[])	/* New elements (one per entry). */
{
    int oldMaxWidth, pixelWidth, result;
    int i, oldMaxWidth, pixelWidth, result, length;
    Tcl_Size i, length;
    Tcl_Obj *newListObj;
    const char *stringRep;

    oldMaxWidth = listPtr->maxWidth;
    for (i = 0; i < objc; i++) {
	/*
	 * Check if any of the new elements are wider than the current widest;
2397
2398
2399
2400
2401
2402
2403
2404
2405


2406
2407
2408
2409
2410
2411
2412
2395
2396
2397
2398
2399
2400
2401


2402
2403
2404
2405
2406
2407
2408
2409
2410







-
-
+
+







	listPtr->selectAnchor += objc;
    }
    if (index < listPtr->topIndex) {
	listPtr->topIndex += objc;
    }
    if (index <= listPtr->active) {
	listPtr->active += objc;
	if ((listPtr->active >= (int)listPtr->nElements) &&
		((int)listPtr->nElements > 0)) {
	if ((listPtr->active >= listPtr->nElements) &&
		(listPtr->nElements > 0)) {
	    listPtr->active = listPtr->nElements-1;
	}
    }
    listPtr->flags |= UPDATE_V_SCROLLBAR;
    if (listPtr->maxWidth != oldMaxWidth) {
	listPtr->flags |= UPDATE_H_SCROLLBAR;
    }
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
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







-
+



-
+
-












-
+







 *	The listbox will be modified and (eventually) redisplayed.
 *
 *----------------------------------------------------------------------
 */

static int
ListboxDeleteSubCmd(
    Listbox *listPtr,	/* Listbox widget to modify. */
    register Listbox *listPtr,	/* Listbox widget to modify. */
    int first,			/* Index of first element to delete. */
    int last)			/* Index of last element to delete. */
{
    int count, i, widthChanged, result, pixelWidth;
    int count, i, widthChanged, length, result, pixelWidth;
    Tcl_Size length;
    Tcl_Obj *newListObj, *element;
    const char *stringRep;
    Tcl_HashEntry *entry;

    /*
     * Adjust the range to fit within the existing elements of the listbox,
     * and make sure there's something to delete.
     */

    if (first < 0) {
	first = 0;
    }
    if (last >= (int)listPtr->nElements) {
    if (last >= listPtr->nElements) {
	last = listPtr->nElements-1;
    }
    count = last + 1 - first;
    if (count <= 0) {
	return TCL_OK;
    }

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
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







-
+









-
-
+
+







    }
    if (first <= listPtr->topIndex) {
	listPtr->topIndex -= count;
	if (listPtr->topIndex < first) {
	    listPtr->topIndex = first;
	}
    }
    if (listPtr->topIndex > ((int)listPtr->nElements - listPtr->fullLines)) {
    if (listPtr->topIndex > (listPtr->nElements - listPtr->fullLines)) {
	listPtr->topIndex = listPtr->nElements - listPtr->fullLines;
	if (listPtr->topIndex < 0) {
	    listPtr->topIndex = 0;
	}
    }
    if (listPtr->active > last) {
	listPtr->active -= count;
    } else if (listPtr->active >= first) {
	listPtr->active = first;
	if ((listPtr->active >= (int)listPtr->nElements) &&
		((int)listPtr->nElements > 0)) {
	if ((listPtr->active >= listPtr->nElements) &&
		(listPtr->nElements > 0)) {
	    listPtr->active = listPtr->nElements-1;
	}
    }
    listPtr->flags |= UPDATE_V_SCROLLBAR;
    ListboxComputeGeometry(listPtr, 0, widthChanged, 0);
    if (widthChanged) {
	listPtr->flags |= UPDATE_H_SCROLLBAR;
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
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







-
+


-
+
















-
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ListboxEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    Listbox *listPtr = (Listbox *)clientData;
    Listbox *listPtr = clientData;

    if (eventPtr->type == Expose) {
	EventuallyRedrawRange(listPtr,
		NearestListboxElement(listPtr, eventPtr->xexpose.y),
		NearestListboxElement(listPtr, eventPtr->xexpose.y
		+ eventPtr->xexpose.height));
    } else if (eventPtr->type == DestroyNotify) {
	if (!(listPtr->flags & LISTBOX_DELETED)) {
	    listPtr->flags |= LISTBOX_DELETED;
	    Tcl_DeleteCommandFromToken(listPtr->interp, listPtr->widgetCmd);
	    if (listPtr->setGrid) {
		Tk_UnsetGrid(listPtr->tkwin);
	    }
	    if (listPtr->flags & REDRAW_PENDING) {
		Tcl_CancelIdleCall(DisplayListbox, clientData);
	    }
	    Tcl_EventuallyFree(clientData, DestroyListbox);
	    Tcl_EventuallyFree(clientData, (Tcl_FreeProc *) DestroyListbox);
	}
    } else if (eventPtr->type == ConfigureNotify) {
	int vertSpace;

	vertSpace = Tk_Height(listPtr->tkwin) - 2*listPtr->inset;
	listPtr->fullLines = vertSpace / listPtr->lineHeight;
	if ((listPtr->fullLines*listPtr->lineHeight) < vertSpace) {
2681
2682
2683
2684
2685
2686
2687
2688

2689
2690

2691
2692
2693
2694
2695
2696
2697
2678
2679
2680
2681
2682
2683
2684

2685
2686

2687
2688
2689
2690
2691
2692
2693
2694







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
ListboxCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    Listbox *listPtr = (Listbox *)clientData;
    Listbox *listPtr = clientData;

    /*
     * This procedure could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this procedure destroys the
     * widget.
     */
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
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







-
+


-
+

-
+
-
-
+
-
-
-
-
-
-
-
-
-















+
+
+
+
+
+
+
+

















-
-
+
+


-
-
+
+


-
-
-
-
-
-
-
-
+
+
+





+
+
+
+
+
+
+
+








-
+








static int
GetListboxIndex(
    Tcl_Interp *interp,		/* For error messages. */
    Listbox *listPtr,		/* Listbox for which the index is being
				 * specified. */
    Tcl_Obj *indexObj,		/* Specifies an element in the listbox. */
    int lastOK,		/* If 1, "end" refers to the number of entries
    int endIsSize,		/* If 1, "end" refers to the number of entries
				 * in the listbox. If 0, "end" refers to 1
				 * less than the number of entries. */
    Tcl_Size *indexPtr)		/* Where to store converted index. */
    int *indexPtr)		/* Where to store converted index. */
{
    int result;
    int result, index;
    Tcl_Size idx, index;
    char *stringRep;
    const char *stringRep;

    result = TkGetIntForIndex(indexObj, listPtr->nElements - 1, lastOK, &idx);
    if (result == TCL_OK) {
    	if ((idx != TCL_INDEX_NONE) && (idx > listPtr->nElements)) {
    	    idx = listPtr->nElements;
    	}
    	*indexPtr = idx;
    	return TCL_OK;
    }

    /*
     * First see if the index is one of the named indices.
     */

    result = Tcl_GetIndexFromObj(NULL, indexObj, indexNames, "", 0, &index);
    if (result == TCL_OK) {
	switch (index) {
	case INDEX_ACTIVE:
	    /* "active" index */
	    *indexPtr = listPtr->active;
	    break;
	case INDEX_ANCHOR:
	    /* "anchor" index */
	    *indexPtr = listPtr->selectAnchor;
	    break;
	case INDEX_END:
	    /* "end" index */
	    if (endIsSize) {
		*indexPtr = listPtr->nElements;
	    } else {
		*indexPtr = listPtr->nElements - 1;
	    }
	    break;
	}
	return TCL_OK;
    }

    /*
     * The index didn't match any of the named indices; maybe it's an @x,y
     */

    stringRep = Tcl_GetString(indexObj);
    if (stringRep[0] == '@') {

        /*
         * @x,y index
         */

	int y;
	char *start;
	char *rest;
	const char *start;
	char *end;

	start = stringRep + 1;
	rest = strchr(start, ',');
	if (!rest) {
	y = strtol(start, &end, 0);
	if ((start == end) || (*end != ',')) {
	    goto badIndex;
	}
	*rest = '\0';
	if (Tcl_GetInt(NULL, start, &y) != TCL_OK) {
	    *rest = ',';
	    goto badIndex;
	}
	*rest = ',';
	start = rest+1;
	if (Tcl_GetInt(NULL, start, &y) != TCL_OK) {
	start = end+1;
	y = strtol(start, &end, 0);
	if ((start == end) || (*end != '\0')) {
	    goto badIndex;
	}
	*indexPtr = NearestListboxElement(listPtr, y);
	return TCL_OK;
    }

    /*
     * Maybe the index is just an integer.
     */

    if (Tcl_GetIntFromObj(interp, indexObj, indexPtr) == TCL_OK) {
	return TCL_OK;
    }

    /*
     * Everything failed, nothing matched. Throw up an error message.
     */

  badIndex:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad listbox index \"%s\": must be active, anchor, end, @x,y,"
	    " or an index", Tcl_GetString(indexObj)));
	    " or a number", Tcl_GetString(indexObj)));
    Tcl_SetErrorCode(interp, "TK", "VALUE", "LISTBOX_INDEX", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
2825
2826
2827
2828
2829
2830
2831
2832

2833
2834
2835
2836

2837
2838
2839
2840
2841
2842
2843
2823
2824
2825
2826
2827
2828
2829

2830
2831
2832
2833

2834
2835
2836
2837
2838
2839
2840
2841







-
+



-
+







 *	change its display too.
 *
 *----------------------------------------------------------------------
 */

static void
ChangeListboxView(
    Listbox *listPtr,	/* Information about widget. */
    register Listbox *listPtr,	/* Information about widget. */
    int index)			/* Index of element in listPtr that should now
				 * appear at the top of the listbox. */
{
    if (index >= ((int)listPtr->nElements - listPtr->fullLines)) {
    if (index >= (listPtr->nElements - listPtr->fullLines)) {
	index = listPtr->nElements - listPtr->fullLines;
    }
    if (index < 0) {
	index = 0;
    }
    if (listPtr->topIndex != index) {
	listPtr->topIndex = index;
2860
2861
2862
2863
2864
2865
2866
2867

2868
2869
2870
2871
2872
2873
2874
2858
2859
2860
2861
2862
2863
2864

2865
2866
2867
2868
2869
2870
2871
2872







-
+







 *	The listbox may be redrawn to reflect its new horizontal offset.
 *
 *----------------------------------------------------------------------
 */

static void
ChangeListboxOffset(
    Listbox *listPtr,	/* Information about widget. */
    register Listbox *listPtr,	/* Information about widget. */
    int offset)			/* Desired new "xOffset" for listbox. */
{
    int maxOffset;

    /*
     * Make sure that the new offset is within the allowable range, and round
     * it off to an even multiple of xScrollUnit.
2908
2909
2910
2911
2912
2913
2914
2915

2916
2917
2918
2919
2920
2921
2922
2906
2907
2908
2909
2910
2911
2912

2913
2914
2915
2916
2917
2918
2919
2920







-
+







 *	The view in the window may change.
 *
 *----------------------------------------------------------------------
 */

static void
ListboxScanTo(
    Listbox *listPtr,	/* Information about widget. */
    register Listbox *listPtr,	/* Information about widget. */
    int x,			/* X-coordinate to use for scan operation. */
    int y)			/* Y-coordinate to use for scan operation. */
{
    int newTopIndex, newOffset, maxIndex, maxOffset;

    maxIndex = listPtr->nElements - listPtr->fullLines;
    maxOffset = GetMaxOffset(listPtr);
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
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







-
+












-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
NearestListboxElement(
    Listbox *listPtr,	/* Information about widget. */
    register Listbox *listPtr,	/* Information about widget. */
    int y)			/* Y-coordinate in listPtr's window. */
{
    int index;

    index = (y - listPtr->inset) / listPtr->lineHeight;
    if (index >= (listPtr->fullLines + listPtr->partialLine)) {
	index = listPtr->fullLines + listPtr->partialLine - 1;
    }
    if (index < 0) {
	index = 0;
    }
    index += listPtr->topIndex;
    if (index >= (int)listPtr->nElements) {
    if (index >= listPtr->nElements) {
	index = listPtr->nElements-1;
    }
    return index;
}

/*
 *----------------------------------------------------------------------
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
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







-
+















-
+





-
+







 *	non-zero.
 *
 *----------------------------------------------------------------------
 */

static int
ListboxSelect(
    Listbox *listPtr,	/* Information about widget. */
    register Listbox *listPtr,	/* Information about widget. */
    int first,			/* Index of first element to select or
				 * deselect. */
    int last,			/* Index of last element to select or
				 * deselect. */
    int select)			/* 1 means select items, 0 means deselect
				 * them. */
{
    int i, firstRedisplay, oldCount, isNew;
    Tcl_HashEntry *entry;

    if (last < first) {
	i = first;
	first = last;
	last = i;
    }
    if ((last < 0) || (first >= (int)listPtr->nElements)) {
    if ((last < 0) || (first >= listPtr->nElements)) {
	return TCL_OK;
    }
    if (first < 0) {
	first = 0;
    }
    if (last >= (int)listPtr->nElements) {
    if (last >= listPtr->nElements) {
	last = listPtr->nElements - 1;
    }
    oldCount = listPtr->numSelected;
    firstRedisplay = -1;

    /*
     * For each index in the range, find it in our selection hash table. If
3077
3078
3079
3080
3081
3082
3083
3084

3085
3086
3087
3088
3089
3090
3091
3092
3075
3076
3077
3078
3079
3080
3081

3082

3083
3084
3085
3086
3087
3088
3089







-
+
-







	}
    }

    if (firstRedisplay >= 0) {
	EventuallyRedrawRange(listPtr, first, last);
    }
    if ((oldCount == 0) && (listPtr->numSelected > 0)
	    && (listPtr->exportSelection)
	    && listPtr->exportSelection) {
	    && (!Tcl_IsSafe(listPtr->interp))) {
	Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY,
		ListboxLostSelection, listPtr);
    }
    return TCL_OK;
}

/*
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
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







-
+

-
-
+
+


-
+



-
+

-
+
-




-
+









-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
ListboxFetchSelection(
    void *clientData,	/* Information about listbox widget. */
    Tcl_Size offset,			/* Offset within selection of first byte to be
    ClientData clientData,	/* Information about listbox widget. */
    int offset,			/* Offset within selection of first byte to be
				 * returned. */
    char *buffer,		/* Location in which to place selection. */
    Tcl_Size maxBytes)		/* Maximum number of bytes to place at buffer,
    int maxBytes)		/* Maximum number of bytes to place at buffer,
				 * not including terminating NULL
				 * character. */
{
    Listbox *listPtr = (Listbox *)clientData;
    register Listbox *listPtr = clientData;
    Tcl_DString selection;
    int count, needNewline, i;
    int length, count, needNewline, stringLen, i;
    Tcl_Size length, stringLen;
    Tcl_Obj *curElement;
    const char *stringRep;
    Tcl_HashEntry *entry;

    if ((!listPtr->exportSelection) || Tcl_IsSafe(listPtr->interp)) {
    if (!listPtr->exportSelection) {
	return -1;
    }

    /*
     * Use a dynamic string to accumulate the contents of the selection.
     */

    needNewline = 0;
    Tcl_DStringInit(&selection);
    for (i = 0; i < (int)listPtr->nElements; i++) {
    for (i = 0; i < listPtr->nElements; i++) {
	entry = Tcl_FindHashEntry(listPtr->selection, KEY(i));
	if (entry != NULL) {
	    if (needNewline) {
		Tcl_DStringAppend(&selection, "\n", 1);
	    }
	    Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i,
		    &curElement);
3158
3159
3160
3161
3162
3163
3164
3165


3166
3167
3168
3169
3170


3171
3172

3173
3174
3175
3176
3177
3178
3179
3154
3155
3156
3157
3158
3159
3160

3161
3162
3163
3164



3165
3166
3167

3168
3169
3170
3171
3172
3173
3174
3175







-
+
+


-
-
-
+
+

-
+







	return -1;
    }

    /*
     * Copy the requested portion of the selection to the buffer.
     */

    if (length <= offset) {
    count = length - offset;
    if (count <= 0) {
	count = 0;
    } else {
	count = length - offset;
	if (count > (int)maxBytes) {
	    count = (int)maxBytes;
	if (count > maxBytes) {
	    count = maxBytes;
	}
	memcpy(buffer, Tcl_DStringValue(&selection) + offset, count);
	memcpy(buffer, Tcl_DStringValue(&selection) + offset, (size_t) count);
    }
    buffer[count] = '\0';
    Tcl_DStringFree(&selection);
    return count;
}

/*
3192
3193
3194
3195
3196
3197
3198
3199

3200
3201

3202
3203

3204
3205
3206
3207
3208
3209
3210
3211
3188
3189
3190
3191
3192
3193
3194

3195
3196

3197
3198

3199

3200
3201
3202
3203
3204
3205
3206







-
+

-
+

-
+
-







 *	not containing a selection.
 *
 *----------------------------------------------------------------------
 */

static void
ListboxLostSelection(
    void *clientData)	/* Information about listbox widget. */
    ClientData clientData)	/* Information about listbox widget. */
{
    Listbox *listPtr = (Listbox *)clientData;
    register Listbox *listPtr = clientData;

    if ((listPtr->exportSelection) && (!Tcl_IsSafe(listPtr->interp))
    if ((listPtr->exportSelection) && (listPtr->nElements > 0)) {
	    && (listPtr->nElements > 0)) {
	ListboxSelect(listPtr, 0, listPtr->nElements-1, 0);
        GenerateListboxSelectEvent(listPtr);
    }
}

/*
 *----------------------------------------------------------------------
3224
3225
3226
3227
3228
3229
3230
3231

3232
3233
3234
3235
3236
3237
3238
3219
3220
3221
3222
3223
3224
3225

3226
3227
3228
3229
3230
3231
3232
3233







-
+







 *----------------------------------------------------------------------
 */

static void
GenerateListboxSelectEvent(
    Listbox *listPtr)		/* Information about widget. */
{
    Tk_SendVirtualEvent(listPtr->tkwin, "ListboxSelect", NULL);
    TkSendVirtualEvent(listPtr->tkwin, "ListboxSelect", NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * EventuallyRedrawRange --
 *
3246
3247
3248
3249
3250
3251
3252
3253
3254


3255
3256

3257
3258
3259
3260
3261
3262
3263
3241
3242
3243
3244
3245
3246
3247


3248
3249
3250

3251
3252
3253
3254
3255
3256
3257
3258







-
-
+
+

-
+







 *	Information gets redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
EventuallyRedrawRange(
    Listbox *listPtr,	/* Information about widget. */
    TCL_UNUSED(Tcl_Size),			/* Index of first element in list that needs
    register Listbox *listPtr,	/* Information about widget. */
    int first,			/* Index of first element in list that needs
				 * to be redrawn. */
    TCL_UNUSED(Tcl_Size))			/* Index of last element in list that needs to
    int last)			/* Index of last element in list that needs to
				 * be redrawn. May be less than first; these
				 * just bracket a range. */
{
    /*
     * We don't have to register a redraw callback if one is already pending,
     * or if the window doesn't exist, or if the window isn't mapped.
     */
3289
3290
3291
3292
3293
3294
3295
3296

3297
3298
3299
3300
3301
3302
3303
3284
3285
3286
3287
3288
3289
3290

3291
3292
3293
3294
3295
3296
3297
3298







-
+







 *	process errors in the command.
 *
 *----------------------------------------------------------------------
 */

static void
ListboxUpdateVScrollbar(
    Listbox *listPtr)	/* Information about widget. */
    register Listbox *listPtr)	/* Information about widget. */
{
    char firstStr[TCL_DOUBLE_SPACE], lastStr[TCL_DOUBLE_SPACE];
    double first, last;
    int result;
    Tcl_Interp *interp;
    Tcl_DString buf;

3316
3317
3318
3319
3320
3321
3322
3323

3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334






3335
3336
3337
3338
3339
3340
3341
3311
3312
3313
3314
3315
3316
3317

3318
3319
3320
3321
3322
3323






3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336







-
+





-
-
-
-
-
-
+
+
+
+
+
+







	}
    }
    Tcl_PrintDouble(NULL, first, firstStr);
    Tcl_PrintDouble(NULL, last, lastStr);

    /*
     * We must hold onto the interpreter from the listPtr because the data at
     * listPtr might be freed as a result of the Tcl_EvalEx.
     * listPtr might be freed as a result of the Tcl_VarEval.
     */

    interp = listPtr->interp;
    Tcl_Preserve(interp);
    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, listPtr->yScrollCmd, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, firstStr, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, lastStr, TCL_INDEX_NONE);
    result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
    Tcl_DStringAppend(&buf, listPtr->yScrollCmd, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, firstStr, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, lastStr, -1);
    result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
    Tcl_DStringFree(&buf);
    if (result != TCL_OK) {
	Tcl_AddErrorInfo(interp,
		"\n    (vertical scrolling command executed by listbox)");
	Tcl_BackgroundException(interp, result);
    }
    Tcl_Release(interp);
3359
3360
3361
3362
3363
3364
3365
3366

3367
3368
3369
3370
3371
3372
3373
3354
3355
3356
3357
3358
3359
3360

3361
3362
3363
3364
3365
3366
3367
3368







-
+







 *	process errors in the command.
 *
 *----------------------------------------------------------------------
 */

static void
ListboxUpdateHScrollbar(
    Listbox *listPtr)	/* Information about widget. */
    register Listbox *listPtr)	/* Information about widget. */
{
    char firstStr[TCL_DOUBLE_SPACE], lastStr[TCL_DOUBLE_SPACE];
    int result, windowWidth;
    double first, last;
    Tcl_Interp *interp;
    Tcl_DString buf;

3388
3389
3390
3391
3392
3393
3394
3395

3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406






3407
3408
3409
3410
3411
3412
3413
3383
3384
3385
3386
3387
3388
3389

3390
3391
3392
3393
3394
3395






3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408







-
+





-
-
-
-
-
-
+
+
+
+
+
+







	}
    }
    Tcl_PrintDouble(NULL, first, firstStr);
    Tcl_PrintDouble(NULL, last, lastStr);

    /*
     * We must hold onto the interpreter because the data referred to at
     * listPtr might be freed as a result of the call to Tcl_EvalEx.
     * listPtr might be freed as a result of the call to Tcl_VarEval.
     */

    interp = listPtr->interp;
    Tcl_Preserve(interp);
    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, listPtr->xScrollCmd, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, firstStr, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, lastStr, TCL_INDEX_NONE);
    result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
    Tcl_DStringAppend(&buf, listPtr->xScrollCmd, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, firstStr, -1);
    Tcl_DStringAppend(&buf, " ", -1);
    Tcl_DStringAppend(&buf, lastStr, -1);
    result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
    Tcl_DStringFree(&buf);
    if (result != TCL_OK) {
	Tcl_AddErrorInfo(interp,
		"\n    (horizontal scrolling command executed by listbox)");
	Tcl_BackgroundException(interp, result);
    }
    Tcl_Release(interp);
3427
3428
3429
3430
3431
3432
3433
3434

3435
3436
3437


3438
3439
3440

3441
3442

3443
3444
3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3422
3423
3424
3425
3426
3427
3428

3429
3430


3431
3432
3433
3434

3435
3436

3437
3438
3439
3440
3441
3442
3443
3444

3445





















3446
3447
3448
3449
3450
3451
3452







-
+

-
-
+
+


-
+

-
+







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

static char *
ListboxListVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),
    TCL_UNUSED(const char *),
    const char *name1,		/* Not used. */
    const char *name2,		/* Not used. */
    int flags)			/* Information about what happened. */
{
    Listbox *listPtr = (Listbox *)clientData;
    Listbox *listPtr = clientData;
    Tcl_Obj *oldListObj, *varListObj;
    Tcl_Size oldLength, i;
    int oldLength, i;
    Tcl_HashEntry *entry;

    /*
     * Bwah hahahaha! Puny mortal, you can't unset a -listvar'd variable!
     */

    if (flags & TCL_TRACE_UNSETS) {

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
        if (!Tcl_InterpDeleted(interp) && listPtr->listVarName) {
            void *probe = NULL;

            do {
                probe = Tcl_VarTraceInfo(interp,
                        listPtr->listVarName,
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        ListboxListVarProc, probe);
                if (probe == (void *)listPtr) {
                    break;
                }
            } while (probe);
            if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * listVarName, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
                return NULL;
            }
	    Tcl_SetVar2Ex(interp, listPtr->listVarName, NULL,
		    listPtr->listObj, TCL_GLOBAL_ONLY);
	    Tcl_TraceVar2(interp, listPtr->listVarName,
		    NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    ListboxListVarProc, clientData);
	    return NULL;
	}
3537
3538
3539
3540
3541
3542
3543
3544

3545
3546
3547
3548
3549
3550
3551
3511
3512
3513
3514
3515
3516
3517

3518
3519
3520
3521
3522
3523
3524
3525







-
+







		Tcl_DeleteHashEntry(entry);
	    }
	}
    }

    if (oldLength != listPtr->nElements) {
	listPtr->flags |= UPDATE_V_SCROLLBAR;
	if (listPtr->topIndex > ((int)listPtr->nElements - listPtr->fullLines)) {
	if (listPtr->topIndex > (listPtr->nElements - listPtr->fullLines)) {
	    listPtr->topIndex = listPtr->nElements - listPtr->fullLines;
	    if (listPtr->topIndex < 0) {
		listPtr->topIndex = 0;
	    }
	}
    }

3581
3582
3583
3584
3585
3586
3587
3588
3589
3590



3591
3592
3593

3594
3595

3596
3597
3598
3599
3600
3601
3602
3555
3556
3557
3558
3559
3560
3561



3562
3563
3564
3565


3566
3567

3568
3569
3570
3571
3572
3573
3574
3575







-
-
-
+
+
+

-
-
+

-
+







 *
 *----------------------------------------------------------------------
 */

static void
MigrateHashEntries(
    Tcl_HashTable *table,
    Tcl_Size first,
    Tcl_Size last,
    Tcl_Size offset)
    int first,
    int last,
    int offset)
{
    Tcl_Size i;
    int isNew;
    int i, isNew;
    Tcl_HashEntry *entry;
    void *clientData;
    ClientData clientData;

    if (offset == 0) {
	return;
    }

    /*
     * It's more efficient to do one if/else and nest the for loops inside,
3641
3642
3643
3644
3645
3646
3647
3648

3649
3650
3651
3652
3653
3654
3655
3614
3615
3616
3617
3618
3619
3620

3621
3622
3623
3624
3625
3626
3627
3628







-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
*/
static int GetMaxOffset(
    Listbox *listPtr)
    register Listbox *listPtr)
{
    int maxOffset;

    maxOffset = listPtr->maxWidth -
            (Tk_Width(listPtr->tkwin) - 2*listPtr->inset -
            2*listPtr->selBorderWidth) + listPtr->xScrollUnit - 1;
    if (maxOffset < 0) {

Changes to generic/tkMacWinMenu.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23






-
+








-
+







/*
 * tkMacWinMenu.c --
 *
 *	This module implements the common elements of the Mac and Windows
 *	specific features of menus. This file is not used for UNIX.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkMenu.h"

typedef struct {
typedef struct ThreadSpecificData {
    int postCommandGeneration;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

static int		PreprocessMenu(TkMenu *menuPtr);

/*
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







 */

static int
PreprocessMenu(
    TkMenu *menuPtr)
{
    int index, result, finished;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    Tcl_Preserve(menuPtr);

    /*
     * First, let's process the post command on ourselves. If this command
     * destroys this menu, or if there was an error, we are done.
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







     * structure is changing, we stop after we do one command, and start over.
     * When we get through without doing any, we are done.
     */

    do {
	finished = 1;
	for (index = 0; index < menuPtr->numEntries; index++) {
	    TkMenuEntry *entryPtr = menuPtr->entries[index];
	    register TkMenuEntry *entryPtr = menuPtr->entries[index];

	    if ((entryPtr->type == CASCADE_ENTRY)
		    && (entryPtr->namePtr != NULL)
		    && (entryPtr->childMenuRefPtr != NULL)
		    && (entryPtr->childMenuRefPtr->menuPtr != NULL)) {
		TkMenu *cascadeMenuPtr = entryPtr->childMenuRefPtr->menuPtr;

125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139







-
+







 *----------------------------------------------------------------------
 */

int
TkPreprocessMenu(
    TkMenu *menuPtr)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    tsdPtr->postCommandGeneration++;
    menuPtr->postCommandGeneration = tsdPtr->postCommandGeneration;
    return PreprocessMenu(menuPtr);
}


Changes to generic/tkMain.c.

10
11
12
13
14
15
16















17








18
19
20

21
22
23
24
25
26
27

28
29
30
31
32
33
34





35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68









69
70
71


72
73
74
75
76
77
78
79

80
81
82
83



84

85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


42

43
44
45
46
47

48

49
50




51
52
53
54
55
56
57



58
59
60

61
62
63
64
65
66
67



68
69
70
71
72
73
74
75
76
77
78
79
80



81
82
83
84
85
86
87
88
89



90
91








92




93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

-
-
+
-





-
+
-


-
-
-
-
+
+
+
+
+


-
-
-



-
+






-
-
-













-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+

+



-
+


















-
+

















-
+



















-
+







 * Copyright (c) 1990-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.
 */

/**
 * On Windows, this file needs to be compiled twice, once with
 * TK_ASCII_MAIN defined. This way both Tk_MainEx and Tk_MainExW
 * can be implemented, sharing the same source code.
 */
#if defined(TK_ASCII_MAIN)
#   ifdef UNICODE
#	undef UNICODE
#	undef _UNICODE
#   else
#	define UNICODE
#	define _UNICODE
#   endif
#endif

#include "tkInt.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#ifdef NO_STDLIB_H
#   include "../compat/stdlib.h"
#else
#   include <stdlib.h>
#endif

#if defined(_WIN32) && !defined(UNICODE) && !defined(STATIC_BUILD)
MODULE_SCOPE void TkCygwinMainEx(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *);
extern int TkCygwinMainEx(int, char **, Tcl_AppInitProc *, Tcl_Interp *);
#endif

/*
 * The default prompt used when the user has not overridden it.
 */

static const char DEFAULT_PRIMARY_PROMPT[] = "% ";
#define DEFAULT_PRIMARY_PROMPT	"% "
static const char ENCODING_ERROR[] = "\n\t(encoding error in stderr)";

/*
 * This file can be compiled on Windows in UNICODE mode, as well as on all
 * other platforms using the native encoding. This is done by using the normal
 * Windows functions like _tcscmp, but on platforms which don't have <tchar.h>
 * we have to translate that to strcmp here.
 * This file can be compiled on Windows in UNICODE mode, as well as
 * on all other platforms using the native encoding. This is done
 * by using the normal Windows functions like _tcscmp, but on
 * platforms which don't have <tchar.h> we have to translate that
 * to strcmp here.
 */
#ifdef _WIN32
#ifdef __cplusplus
extern "C" {
#endif
/*  Little hack to eliminate the need for "tclInt.h" here:
    Just copy a small portion of TclIntPlatStubs, just
    enough to make it work. See [600b72bfbc] */
typedef struct TclIntPlatStubs {
typedef struct {
    int magic;
    void *hooks;
    void (*dummy[16]) (void); /* dummy entries 0-15, not used */
    int (*tclpIsAtty) (int fd); /* 16 */
} TclIntPlatStubs;
extern const TclIntPlatStubs *tclIntPlatStubsPtr;
#ifdef __cplusplus
}
#endif
#   include "tkWinInt.h"
#else
#   define TCHAR char
#   define TEXT(arg) arg
#   define _tcscmp strcmp
#   define _tcslen strlen
#   define _tcsncmp strncmp
#endif

#ifdef MAC_OSX_TK
#include "tkMacOSXInt.h"
#endif

static inline Tcl_Obj *
NewNativeObj(
    TCHAR *string)
/*
 * Further on, in UNICODE mode, we need to use Tcl_NewUnicodeObj,
 * while otherwise NewNativeObj is needed (which provides proper
 * conversion from native encoding to UTF-8).
 */
#ifdef UNICODE
#   define NewNativeObj Tcl_NewUnicodeObj
#else /* !UNICODE */
    static Tcl_Obj *NewNativeObj(char *string, int length) {
{
    Tcl_Obj *obj;
    Tcl_DString ds;
	Tcl_Obj *obj;
	Tcl_DString ds;
    const char *str;

#if defined(_WIN32) && defined(UNICODE)
    Tcl_DStringInit(&ds);
    Tcl_WCharToUtfDString(string, wcslen(string), &ds);
    str = Tcl_DStringValue(&ds);
#else
    str = Tcl_ExternalToUtfDString(NULL, (char *)string, strlen(string), &ds);
	Tcl_ExternalToUtfDString(NULL, string, length, &ds);
#endif
    obj = Tcl_NewStringObj(str, Tcl_DStringLength(&ds));
    Tcl_DStringFree(&ds);
    return obj;
	obj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
	Tcl_DStringFree(&ds);
	return obj;
}
#endif /* !UNICODE */

/*
 * Declarations for various library functions and variables (don't want to
 * include tclInt.h or tclPort.h here, because people might copy this file out
 * include tkInt.h or tkPort.h here, because people might copy this file out
 * of the Tk source directory to make their own modified versions). Note: do
 * not declare "exit" here even though a declaration is really needed, because
 * it will conflict with a declaration elsewhere on some systems.
 */

#if defined(_WIN32)
#define isatty WinIsTty
static int WinIsTty(int fd) {
    HANDLE handle;

    /*
     * For now, under Windows, we assume we are not running as a console mode
     * app, so we need to use the GUI console. In order to enable this, we
     * always claim to be running on a tty. This probably isn't the right way
     * to do it.
     */

#if !defined(STATIC_BUILD)
	if (tclStubsPtr->tcl_CreateFileHandler && tclIntPlatStubsPtr->tclpIsAtty) {
	if (tclStubsPtr->reserved9 && tclIntPlatStubsPtr->tclpIsAtty) {
	    /* We are running on Cygwin */
	    return tclIntPlatStubsPtr->tclpIsAtty(fd);
	}
#endif
    handle = GetStdHandle(STD_INPUT_HANDLE + fd);
	/*
	 * If it's a bad or closed handle, then it's been connected to a wish
	 * console window. A character file handle is a tty by definition.
	 */
    return (handle == INVALID_HANDLE_VALUE) || (handle == 0)
	     || (GetFileType(handle) == FILE_TYPE_UNKNOWN)
	     || (GetFileType(handle) == FILE_TYPE_CHAR);
}
#else
extern int		isatty(int fd);
#endif

typedef struct {
typedef struct InteractiveState {
    Tcl_Channel input;		/* The standard input channel from which lines
				 * are read. */
    int tty;			/* Non-zero means standard input is a
				 * terminal-like device. Zero means it's a
				 * file. */
    Tcl_DString command;	/* Used to assemble lines of terminal input
				 * into Tcl commands. */
    Tcl_DString line;		/* Used to read the next line from the
				 * terminal input. */
    int gotPartial;
    Tcl_Interp *interp;		/* Interpreter that evaluates interactive
				 * commands. */
} InteractiveState;

/*
 * Forward declarations for functions defined later in this file.
 */

static void		Prompt(Tcl_Interp *interp, InteractiveState *isPtr);
static void		StdinProc(void *clientData, int mask);
static void		StdinProc(ClientData clientData, int mask);

/*
 *----------------------------------------------------------------------
 *
 * Tk_MainEx --
 *
 *	Main program for Wish and most other Tk-based applications.
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202

203
204
205
206

207
208
209
210




211
212

213
214
215


216
217
218
219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257

258
259
260
261
262
263
264




265
266
267
268
269
270



271
272







273
274
275
276
277
278

279
280
281
282


283
284

285
286
287
288

289
290
291
292
293
294
295
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188

189
190
191
192
193
194





195
196
197
198

199
200
201
202
203
204
205
206
207
208

209
210
211
212

213
214
215


216
217
218
219
220

221
222


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238




239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265





266
267
268
269

270
271



272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295

296
297
298
299

300
301
302
303
304
305
306
307







-
+







-






-
-
-
-
-




-
+









-
+



-
+


-
-
+
+
+
+

-
+

-
-
+
+













-
+
-
-
-
-
















+







-
+


-
-
-
-
-
+
+
+
+
-


-
-
-
+
+
+

-
+
+
+
+
+
+
+





-
+




+
+

-
+



-
+







 *	interpreted.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MainEx(
    Tcl_Size argc,			/* Number of arguments. */
    int argc,			/* Number of arguments. */
    TCHAR **argv,		/* Array of argument strings. */
    Tcl_AppInitProc *appInitProc,
				/* Application-specific initialization
				 * function to call after most initialization
				 * but before starting to execute commands. */
    Tcl_Interp *interp)
{
    int i=0;			/* argv[i] index */
    Tcl_Obj *path, *argvPtr, *appName;
    const char *encodingName;
    int code, nullStdin = 0;
    Tcl_Channel chan;
    InteractiveState is;

    if (0 < argc) {
	--argc;			/* "consume" argv[0] */
	++i;
    }

    /*
     * Ensure that we are getting a compatible version of Tcl.
     */

    if (Tcl_InitStubs(interp, "8.7-", 0) == NULL) {
    if (Tcl_InitStubs(interp, "8.6-", 0) == NULL) {
	if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
	    abort();
	} else {
	    Tcl_Panic("%s", Tcl_GetString(Tcl_GetObjResult(interp)));
	}
    }

#if defined(_WIN32) && !defined(UNICODE) && !defined(STATIC_BUILD)

    if (tclStubsPtr->tcl_CreateFileHandler) {
    if (tclStubsPtr->reserved9) {
	/* We are running win32 Tk under Cygwin, so let's check
	 * whether the env("DISPLAY") variable or the -display
	 * argument is set. If so, we really want to run the
	 * Tk_MainEx function of libtcl9tk9.?.dll, not this one. */
	 * Tk_MainEx function of libtk8.?.dll, not this one. */
	if (Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY)) {
	loadCygwinTk:
	    TkCygwinMainEx(argc, argv, appInitProc, interp);
	    /* Only returns when Tk_MainEx() was not found */
	    if (TkCygwinMainEx(argc, argv, appInitProc, interp)) {
		/* Should never reach here. */
		return;
	    }
	} else {
	    Tcl_Size j;
	    int i;

	    for (j = 1; j < argc; ++j) {
		if (!strcmp(argv[j], "-display")) {
	    for (i = 1; i < argc; ++i) {
		if (!_tcscmp(argv[i], TEXT("-display"))) {
		    goto loadCygwinTk;
		}
	    }
	}
    }
#endif

    Tcl_InitMemory(interp);

    is.interp = interp;
    is.gotPartial = 0;
    Tcl_Preserve(interp);

#if defined(_WIN32)
#if defined(_WIN32) && !defined(__CYGWIN__)
#if !defined(STATIC_BUILD)
    /* If compiled for Win32 but running on Cygwin, don't use console */
    if (!tclStubsPtr->tcl_CreateFileHandler)
#endif
    Tk_InitConsoleChannels(interp);
#endif

#ifdef MAC_OSX_TK
    if (Tcl_GetStartupScript(NULL) == NULL) {
	TkMacOSXDefaultStartupScript();
    }
#endif

    /*
     * If the application has not already set a startup script, parse the
     * first few command line arguments to determine the script path and
     * encoding.
     */

    if (NULL == Tcl_GetStartupScript(NULL)) {
	size_t length;

	/*
	 * Check whether first 3 args (argv[1] - argv[3]) look like
	 *  -encoding ENCODING FILENAME
	 * or like
	 *  FILENAME
	 * or like
	 *  -file FILENAME (ancient history support only, removed with Tcl 9.0)
	 *  -file FILENAME		(ancient history support only)
	 */

	/* mind argc is being adjusted as we proceed */
	if ((argc >= 3) && (0 == _tcscmp(TEXT("-encoding"), argv[1]))
		&& ('-' != argv[3][0])) {
	    Tcl_Obj *value = NewNativeObj(argv[2]);
	    Tcl_SetStartupScript(NewNativeObj(argv[3]),
	if ((argc > 3) && (0 == _tcscmp(TEXT("-encoding"), argv[1]))
		&& (TEXT('-') != argv[3][0])) {
		Tcl_Obj *value = NewNativeObj(argv[2], -1);
	    Tcl_SetStartupScript(NewNativeObj(argv[3], -1), Tcl_GetString(value));
		    Tcl_GetString(value));
	    Tcl_DecrRefCount(value);
	    argc -= 3;
	    i += 3;
	} else if ((argc >= 1) && ('-' != argv[1][0])) {
	    Tcl_SetStartupScript(NewNativeObj(argv[1]), NULL);
	    argv += 3;
	} else if ((argc > 1) && (TEXT('-') != argv[1][0])) {
	    Tcl_SetStartupScript(NewNativeObj(argv[1], -1), NULL);
	    argc--;
	    i++;
	    argv++;
	} else if ((argc > 2) && (length = _tcslen(argv[1]))
		&& (length > 1) && (0 == _tcsncmp(TEXT("-file"), argv[1], length))
		&& (TEXT('-') != argv[2][0])) {
	    Tcl_SetStartupScript(NewNativeObj(argv[2], -1), NULL);
	    argc -= 2;
	    argv += 2;
	}
    }

    path = Tcl_GetStartupScript(&encodingName);
    if (path == NULL) {
	appName = NewNativeObj(argv[0]);
	appName = NewNativeObj(argv[0], -1);
    } else {
	appName = path;
    }
    Tcl_SetVar2Ex(interp, "argv0", NULL, appName, TCL_GLOBAL_ONLY);
    argc--;
    argv++;

    Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewWideIntObj((Tcl_WideInt)argc), TCL_GLOBAL_ONLY);
    Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(argc), TCL_GLOBAL_ONLY);

    argvPtr = Tcl_NewListObj(0, NULL);
    while (argc--) {
	Tcl_ListObjAppendElement(NULL, argvPtr, NewNativeObj(argv[i++]));
	Tcl_ListObjAppendElement(NULL, argvPtr, NewNativeObj(*argv++, -1));
    }
    Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY);

    /*
     * Set the "tcl_interactive" variable.
     */

304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330







-
+







    if (!is.tty) {
	struct stat st;

	nullStdin = fstat(0, &st) || (S_ISCHR(st.st_mode) && !st.st_blocks);
    }
#endif
    Tcl_SetVar2Ex(interp, "tcl_interactive", NULL,
	    Tcl_NewWideIntObj(!path && (is.tty || nullStdin)), TCL_GLOBAL_ONLY);
	    Tcl_NewIntObj(!path && (is.tty || nullStdin)), TCL_GLOBAL_ONLY);

    /*
     * Invoke application-specific initialization.
     */

    if (appInitProc(interp) != TCL_OK) {
	TkpDisplayWarning(Tcl_GetString(Tcl_GetObjResult(interp)),
397
398
399
400
401
402
403

404
405
406
407


408
409
410

411
412

413
414
415
416

417
418

419
420
421
422
423
424
425
426
427
428



429
430
431
432
433


434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449

450
451
452



453
454

455
456


457
458
459


460
461
462
463


464
465
466
467

468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
409
410
411
412
413
414
415
416
417
418


419
420
421
422

423


424
425
426
427

428
429

430
431






432


433
434
435
436
437
438


439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457



458
459
460
461
462
463


464
465



466
467




468
469




470









471
472
473
474
475
476
477







+


-
-
+
+


-
+
-
-
+



-
+

-
+

-
-
-
-
-
-

-
-
+
+
+



-
-
+
+
















+
-
-
-
+
+
+


+
-
-
+
+
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-







 *
 * Side effects:
 *	Could be almost arbitrary, depending on the command that's typed.
 *
 *----------------------------------------------------------------------
 */

    /* ARGSUSED */
static void
StdinProc(
    void *clientData,	/* The state of interactive cmd line */
    TCL_UNUSED(int) /*mask*/)
    ClientData clientData,	/* The state of interactive cmd line */
    int mask)			/* Not used. */
{
    char *cmd;
    int code;
    int code, count;
    Tcl_Size length;
    InteractiveState *isPtr = (InteractiveState *)clientData;
    InteractiveState *isPtr = clientData;
    Tcl_Channel chan = isPtr->input;
    Tcl_Interp *interp = isPtr->interp;

    length = Tcl_Gets(chan, &isPtr->line);
    count = Tcl_Gets(chan, &isPtr->line);

    if ((length < 0) && !isPtr->gotPartial) {
    if (count < 0 && !isPtr->gotPartial) {
	if (isPtr->tty) {
	    /*
	     * Would be better to find a way to exit the mainLoop? Or perhaps
	     * evaluate [exit]? Leaving as is for now due to compatibility
	     * concerns.
	     */

	    Tcl_Exit(0);
	}
	Tcl_DeleteChannelHandler(chan, StdinProc, isPtr);
	} else {
	    Tcl_DeleteChannelHandler(chan, StdinProc, isPtr);
	}
	return;
    }

    Tcl_DStringAppend(&isPtr->command, Tcl_DStringValue(&isPtr->line), TCL_INDEX_NONE);
    cmd = Tcl_DStringAppend(&isPtr->command, "\n", TCL_INDEX_NONE);
    Tcl_DStringAppend(&isPtr->command, Tcl_DStringValue(&isPtr->line), -1);
    cmd = Tcl_DStringAppend(&isPtr->command, "\n", -1);
    Tcl_DStringFree(&isPtr->line);
    if (!Tcl_CommandComplete(cmd)) {
	isPtr->gotPartial = 1;
	goto prompt;
    }
    isPtr->gotPartial = 0;

    /*
     * Disable the stdin channel handler while evaluating the command;
     * otherwise if the command re-enters the event loop we might process
     * commands from stdin before the current command is finished. Among other
     * things, this will trash the text of the command being evaluated.
     */

    Tcl_CreateChannelHandler(chan, 0, StdinProc, isPtr);
    code = Tcl_RecordAndEval(interp, cmd, TCL_EVAL_GLOBAL);

    isPtr->input = chan = Tcl_GetStdChannel(TCL_STDIN);
    if (chan != NULL) {
	Tcl_CreateChannelHandler(chan, TCL_READABLE, StdinProc, isPtr);
    isPtr->input = Tcl_GetStdChannel(TCL_STDIN);
    if (isPtr->input) {
	Tcl_CreateChannelHandler(isPtr->input, TCL_READABLE, StdinProc, isPtr);
    }
    Tcl_DStringFree(&isPtr->command);
    if (Tcl_GetString(Tcl_GetObjResult(interp))[0] != '\0') {
    if (code != TCL_OK) {
	chan = Tcl_GetStdChannel(TCL_STDERR);
	if ((code != TCL_OK) || (isPtr->tty)) {
	    chan = Tcl_GetStdChannel((code != TCL_OK) ? TCL_STDERR : TCL_STDOUT);

	if (chan != NULL) {
	    if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
	    if (chan) {
		Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
		Tcl_WriteChars(chan, ENCODING_ERROR, -1);
	    }
	    Tcl_WriteChars(chan, "\n", 1);
	}
		Tcl_WriteChars(chan, "\n", 1);
	    }
    } else if (isPtr->tty) {
	Tcl_Obj *resultPtr = Tcl_GetObjResult(interp);
	chan = Tcl_GetStdChannel(TCL_STDOUT);

	}
	Tcl_IncrRefCount(resultPtr);
	(void)Tcl_GetStringFromObj(resultPtr, &length);
	if ((length > 0) && (chan != NULL)) {
	    if (Tcl_WriteObj(chan, resultPtr) < 0) {
		Tcl_WriteChars(chan, "\n\t(encoding error in stdout)", -1);
	    }
	    Tcl_WriteChars(chan, "\n", 1);
	}
	Tcl_DecrRefCount(resultPtr);
    }

    /*
     * If a tty stdin is still around, output a prompt.
     */

  prompt:
517
518
519
520
521
522
523
524

525
526
527
528
529
530
531

532
533
534
535
536





537
538
539
540
541
542
543
544
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526





527
528
529
530
531

532
533
534
535
536
537
538







-
+







+
-
-
-
-
-
+
+
+
+
+
-







	isPtr->gotPartial ? "tcl_prompt2" : "tcl_prompt1", NULL, TCL_GLOBAL_ONLY);
    if (promptCmdPtr == NULL) {
    defaultPrompt:
	if (!isPtr->gotPartial) {
	    chan = Tcl_GetStdChannel(TCL_STDOUT);
	    if (chan != NULL) {
		Tcl_WriteChars(chan, DEFAULT_PRIMARY_PROMPT,
			sizeof(DEFAULT_PRIMARY_PROMPT) - 1);
			strlen(DEFAULT_PRIMARY_PROMPT));
	    }
	}
    } else {
	code = Tcl_EvalObjEx(interp, promptCmdPtr, TCL_EVAL_GLOBAL);
	if (code != TCL_OK) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (script that generates prompt)");
	    if (Tcl_GetString(Tcl_GetObjResult(interp))[0] != '\0') {
	    chan = Tcl_GetStdChannel(TCL_STDERR);
	    if (chan != NULL) {
	    if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
		Tcl_WriteChars(chan, ENCODING_ERROR, -1);
	    }
		chan = Tcl_GetStdChannel(TCL_STDERR);
		if (chan != NULL) {
		    Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
		    Tcl_WriteChars(chan, "\n", 1);
		}
		Tcl_WriteChars(chan, "\n", 1);
	    }
	    goto defaultPrompt;
	}
    }

    chan = Tcl_GetStdChannel(TCL_STDOUT);
    if (chan != NULL) {

Changes to generic/tkMenu.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17








-
-
+
+







/*
 * tkMenu.c --
 *
 * This file contains most of the code for implementing menus in Tk. It takes
 * care of all of the generic (platform-independent) parts of menus, and is
 * supplemented by platform-specific files. The geometry calculation and
 * drawing code for menus is in the file tkMenuDraw.c
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Notes on implementation of menus:
35
36
37
38
39
40
41
42

43
44
45
46
47

48
49
50
51
52
53
54
35
36
37
38
39
40
41

42
43
44
45
46

47
48
49
50
51
52
53
54







-
+




-
+







 * menu bar must have a title that matches the label for the cascade menu.
 *
 * To handle all of the constraints, Tk menubars and tearoff menus are
 * implemented using menu clones. Menu clones are full menus in their own
 * right; they have a Tk window and pathname associated with them; they have a
 * TkMenu structure and array of entries. However, they are linked with the
 * original menu that they were cloned from. They reflect the attributes of the
 * original, or "main", menu. So if an item is added to a menu, and that
 * original, or "master", menu. So if an item is added to a menu, and that
 * menu has clones, then the item must be added to all of its clones also.
 * Menus are cloned when a menu is torn-off or when a menu is assigned as a
 * menubar using the "-menu" option of the toplevel's pathname configure
 * subcommand. When a clone is destroyed, only the clone is destroyed, but
 * when the main menu is destroyed, all clones are also destroyed. This
 * when the master menu is destroyed, all clones are also destroyed. This
 * allows the developer to just deal with one set of menus when creating and
 * destroying.
 *
 * Clones are rather tricky when a menu with cascade entries is cloned (such
 * as a menubar). Not only does the menu have to be cloned, but each cascade
 * entry's corresponding menu must also be cloned. This maintains the pathname
 * parent-child hierarchy necessary for menubars and toplevels to work. This
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103


104
105
106









107
108
109
110

111
112
113
114

115
116
117

118
119
120

121
122
123

124
125
126

127
128
129

130
131
132


133
134
135

136
137
138

139
140
141

142
143
144

145
146
147

148
149
150
151
152
153




154
155
156
157
158
159
160

161
162
163
164
165
166
167

168
169
170

171
172
173

174
175
176

177
178
179

180
181
182

183
184

185
186
187
188
189
190

191
192
193

194
195
196

197
198
199

200
201
202

203
204

205
206
207
208
209
210

211
212

213
214
215
216
217
218

219
220
221


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243


244
245
246

247
248
249
250


251
252
253
254
255
256


257
258

259
260

261
262
263

264
265
266

267
268
269
270


271
272

273
274

275
276

277
278
279

280
281

282
283
284


285
286
287

288
289

290
291
292

293
294

295
296
297
298


299
300
301
302
303
304
305
306
307
308
309

310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
327
328




329
330

331
332
333

334
335
336
337


338
339

340
341
342
343
344
345

346
347
348
349



350
351
352
353




354
355
356
357

358
359
360
361
362
363
364
365
366
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124

125
126
127

128
129
130

131
132
133

134
135
136

137
138
139

140
141


142
143
144
145

146
147
148

149
150
151

152
153
154

155
156
157

158
159
160




161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177

178
179
180

181
182
183

184
185
186

187
188
189

190
191
192

193
194

195
196
197
198
199
200

201
202
203

204
205
206

207
208
209

210
211
212

213
214

215
216
217
218
219
220

221
222

223
224
225
226
227
228

229
230


231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252


253
254
255
256

257
258
259


260
261



262


263
264
265

266
267

268
269
270

271
272
273

274
275
276


277
278
279

280
281

282
283

284
285
286

287
288

289
290


291
292
293
294

295
296

297
298
299

300
301

302
303
304


305
306
307
308
309
310
311
312
313
314
315
316

317
318
319
320
321

322
323
324
325
326
327
328
329
330
331
332
333



334
335
336
337
338

339
340
341

342
343
344


345
346
347

348
349
350
351
352
353

354
355



356
357
358
359
360


361
362
363
364
365
366
367

368


369
370
371
372
373
374
375







-
+












-
+










+
+



+
+
+
+
+
+
+
+
+



-
+



-
+


-
+


-
+


-
+


-
+


-
+

-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
-
-
-
+
+
+
+






-
+






-
+


-
+


-
+


-
+


-
+


-
+

-
+





-
+


-
+


-
+


-
+


-
+

-
+





-
+

-
+





-
+

-
-
+
+














-
+





-
-
+
+


-
+


-
-
+
+
-
-
-

-
-
+
+

-
+

-
+


-
+


-
+


-
-
+
+

-
+

-
+

-
+


-
+

-
+

-
-
+
+


-
+

-
+


-
+

-
+


-
-
+
+










-
+




-
+











-
-
-
+
+
+
+

-
+


-
+


-
-
+
+

-
+





-
+

-
-
-
+
+
+


-
-
+
+
+
+



-
+
-
-







#endif

#include "tkInt.h"
#include "tkMenu.h"

#define MENU_HASH_KEY "tkMenus"

typedef struct {
typedef struct ThreadSpecificData {
    int menusInitialized;	/* Flag indicates whether thread-specific
				 * elements of the Windows Menu module have
				 * been initialized. */
    Tk_OptionTable menuOptionTable;
				/* The option table for menus. */
    Tk_OptionTable entryOptionTables[6];
				/* The tables for menu entries. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * The following flag indicates whether the process-wide state for the Menu
 * module has been initialized. The Mutex protects access to that flag.
 * module has been intialized. The Mutex protects access to that flag.
 */

static int menusInitialized;
TCL_DECLARE_MUTEX(menuMutex)

/*
 * Configuration specs for individual menu entries. If this changes, be sure
 * to update code in TkpMenuInit that changes the font string entry.
 */

static const char *const menuStateStrings[] = {"active", "normal", "disabled", NULL};

static const char *const menuEntryTypeStrings[] = {
    "cascade", "checkbutton", "command", "radiobutton", "separator", NULL
};

/*
 * The following table defines the legal values for the -compound option. It
 * is used with the "enum compound" declaration in tkMenu.h
 */

static const char *const compoundStrings[] = {
    "bottom", "center", "left", "none", "right", "top", NULL
};

static const Tk_OptionSpec tkBasicMenuEntryConfigSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", NULL, NULL,
	DEF_MENU_ENTRY_ACTIVE_BG, offsetof(TkMenuEntry, activeBorderPtr), TCL_INDEX_NONE,
	DEF_MENU_ENTRY_ACTIVE_BG, Tk_Offset(TkMenuEntry, activeBorderPtr), -1,
	TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_COLOR, "-activeforeground", NULL, NULL,
	DEF_MENU_ENTRY_ACTIVE_FG,
	offsetof(TkMenuEntry, activeFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, activeFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-accelerator", NULL, NULL,
	DEF_MENU_ENTRY_ACCELERATOR,
	offsetof(TkMenuEntry, accelPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, accelPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BORDER, "-background", NULL, NULL,
	DEF_MENU_ENTRY_BG,
	offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BITMAP, "-bitmap", NULL, NULL,
	DEF_MENU_ENTRY_BITMAP,
	offsetof(TkMenuEntry, bitmapPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, bitmapPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BOOLEAN, "-columnbreak", NULL, NULL,
	DEF_MENU_ENTRY_COLUMN_BREAK,
	TCL_INDEX_NONE, offsetof(TkMenuEntry, columnBreak), 0, NULL, 0},
	-1, Tk_Offset(TkMenuEntry, columnBreak), 0, NULL, 0},
    {TK_OPTION_STRING, "-command", NULL, NULL,
	DEF_MENU_ENTRY_COMMAND,
	offsetof(TkMenuEntry, commandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, commandPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_MENU_ENTRY_COMPOUND, TCL_INDEX_NONE, offsetof(TkMenuEntry, compound), 0,
	tkCompoundStrings, 0},
	DEF_MENU_ENTRY_COMPOUND, -1, Tk_Offset(TkMenuEntry, compound), 0,
	(ClientData) compoundStrings, 0},
    {TK_OPTION_FONT, "-font", NULL, NULL,
	DEF_MENU_ENTRY_FONT,
	offsetof(TkMenuEntry, fontPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, fontPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_COLOR, "-foreground", NULL, NULL,
	DEF_MENU_ENTRY_FG,
	offsetof(TkMenuEntry, fgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, fgPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BOOLEAN, "-hidemargin", NULL, NULL,
	DEF_MENU_ENTRY_HIDE_MARGIN,
	TCL_INDEX_NONE, offsetof(TkMenuEntry, hideMargin), 0, NULL, 0},
	-1, Tk_Offset(TkMenuEntry, hideMargin), 0, NULL, 0},
    {TK_OPTION_STRING, "-image", NULL, NULL,
	DEF_MENU_ENTRY_IMAGE,
	offsetof(TkMenuEntry, imagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, imagePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-label", NULL, NULL,
	DEF_MENU_ENTRY_LABEL,
	offsetof(TkMenuEntry, labelPtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenuEntry, labelPtr), -1, 0, NULL, 0},
    {TK_OPTION_STRING_TABLE, "-state", NULL, NULL,
	DEF_MENU_ENTRY_STATE,
	TCL_INDEX_NONE, offsetof(TkMenuEntry, state),
	0, tkStateStrings, 0},
    {TK_OPTION_INDEX, "-underline", NULL, NULL,
	TK_OPTION_UNDERLINE_DEF(TkMenuEntry, underline), 0},
	-1, Tk_Offset(TkMenuEntry, state), 0,
	(ClientData) menuStateStrings, 0},
    {TK_OPTION_INT, "-underline", NULL, NULL,
	DEF_MENU_ENTRY_UNDERLINE, -1, Tk_Offset(TkMenuEntry, underline), 0, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0}
};

static const Tk_OptionSpec tkSeparatorEntryConfigSpecs[] = {
    {TK_OPTION_BORDER, "-background", NULL, NULL,
	DEF_MENU_ENTRY_BG,
	offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0}
};

static const Tk_OptionSpec tkCheckButtonEntryConfigSpecs[] = {
    {TK_OPTION_BOOLEAN, "-indicatoron", NULL, NULL,
	DEF_MENU_ENTRY_INDICATOR,
	TCL_INDEX_NONE, offsetof(TkMenuEntry, indicatorOn), 0, NULL, 0},
	-1, Tk_Offset(TkMenuEntry, indicatorOn), 0, NULL, 0},
    {TK_OPTION_STRING, "-offvalue", NULL, NULL,
	DEF_MENU_ENTRY_OFF_VALUE,
	offsetof(TkMenuEntry, offValuePtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenuEntry, offValuePtr), -1, 0, NULL, 0},
    {TK_OPTION_STRING, "-onvalue", NULL, NULL,
	DEF_MENU_ENTRY_ON_VALUE,
	offsetof(TkMenuEntry, onValuePtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenuEntry, onValuePtr), -1, 0, NULL, 0},
    {TK_OPTION_COLOR, "-selectcolor", NULL, NULL,
	DEF_MENU_ENTRY_SELECT,
	offsetof(TkMenuEntry, indicatorFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, indicatorFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-selectimage", NULL, NULL,
	DEF_MENU_ENTRY_SELECT_IMAGE,
	offsetof(TkMenuEntry, selectImagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, selectImagePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-variable", NULL, NULL,
	DEF_MENU_ENTRY_CHECK_VARIABLE,
	offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, namePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0}
	NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0}
};

static const Tk_OptionSpec tkRadioButtonEntryConfigSpecs[] = {
    {TK_OPTION_BOOLEAN, "-indicatoron", NULL, NULL,
	DEF_MENU_ENTRY_INDICATOR,
	TCL_INDEX_NONE, offsetof(TkMenuEntry, indicatorOn), 0, NULL, 0},
	-1, Tk_Offset(TkMenuEntry, indicatorOn), 0, NULL, 0},
    {TK_OPTION_COLOR, "-selectcolor", NULL, NULL,
	DEF_MENU_ENTRY_SELECT,
	offsetof(TkMenuEntry, indicatorFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, indicatorFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-selectimage", NULL, NULL,
	DEF_MENU_ENTRY_SELECT_IMAGE,
	offsetof(TkMenuEntry, selectImagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, selectImagePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-value", NULL, NULL,
	DEF_MENU_ENTRY_VALUE,
	offsetof(TkMenuEntry, onValuePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, onValuePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-variable", NULL, NULL,
	DEF_MENU_ENTRY_RADIO_VARIABLE,
	offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenuEntry, namePtr), -1, 0, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0}
	NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0}
};

static const Tk_OptionSpec tkCascadeEntryConfigSpecs[] = {
    {TK_OPTION_STRING, "-menu", NULL, NULL,
	DEF_MENU_ENTRY_MENU,
	offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, namePtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0}
	NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0}
};

static const Tk_OptionSpec tkTearoffEntryConfigSpecs[] = {
    {TK_OPTION_BORDER, "-background", NULL, NULL,
	DEF_MENU_ENTRY_BG,
	offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING_TABLE, "-state", NULL, NULL,
	DEF_MENU_ENTRY_STATE, TCL_INDEX_NONE, offsetof(TkMenuEntry, state),
	0, tkStateStrings, 0},
	DEF_MENU_ENTRY_STATE, -1, Tk_Offset(TkMenuEntry, state), 0,
	(ClientData) menuStateStrings, 0},
    {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0}
};

static const Tk_OptionSpec *specsArray[] = {
    tkCascadeEntryConfigSpecs, tkCheckButtonEntryConfigSpecs,
    tkBasicMenuEntryConfigSpecs, tkRadioButtonEntryConfigSpecs,
    tkSeparatorEntryConfigSpecs, tkTearoffEntryConfigSpecs
};

/*
 * Menu type strings for use with Tcl_GetIndexFromObj.
 */

static const char *const menuTypeStrings[] = {
    "menubar", "normal", "tearoff", NULL
    "normal", "tearoff", "menubar", NULL
};

static const Tk_OptionSpec tkMenuConfigSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground",
	"Foreground", DEF_MENU_ACTIVE_BG_COLOR,
	offsetof(TkMenu, activeBorderPtr), TCL_INDEX_NONE, 0,
	DEF_MENU_ACTIVE_BG_MONO, 0},
	Tk_Offset(TkMenu, activeBorderPtr), -1, 0,
	(ClientData) DEF_MENU_ACTIVE_BG_MONO, 0},
    {TK_OPTION_PIXELS, "-activeborderwidth", "activeBorderWidth",
	"BorderWidth", DEF_MENU_ACTIVE_BORDER_WIDTH,
	offsetof(TkMenu, activeBorderWidthPtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenu, activeBorderWidthPtr), -1, 0, NULL, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground",
	"Background", DEF_MENU_ACTIVE_FG_COLOR,
	offsetof(TkMenu, activeFgPtr), TCL_INDEX_NONE, 0,
	DEF_MENU_ACTIVE_FG_MONO, 0},
	Tk_Offset(TkMenu, activeFgPtr), -1, 0,
	(ClientData) DEF_MENU_ACTIVE_FG_MONO, 0},
    {TK_OPTION_RELIEF, "-activerelief", "activeRelief", "Relief",
	DEF_MENU_ACTIVE_RELIEF, offsetof(TkMenu, activeReliefPtr),
	TCL_INDEX_NONE, 0, NULL, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_MENU_BG_COLOR, offsetof(TkMenu, borderPtr), TCL_INDEX_NONE, 0,
	DEF_MENU_BG_MONO, 0},
	DEF_MENU_BG_COLOR, Tk_Offset(TkMenu, borderPtr), -1, 0,
	(ClientData) DEF_MENU_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_MENU_BORDER_WIDTH,
	offsetof(TkMenu, borderWidthPtr), TCL_INDEX_NONE, 0, NULL, 0},
	Tk_Offset(TkMenu, borderWidthPtr), -1, 0, NULL, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_MENU_CURSOR,
	offsetof(TkMenu, cursorPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenu, cursorPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_MENU_DISABLED_FG_COLOR,
	offsetof(TkMenu, disabledFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK,
	DEF_MENU_DISABLED_FG_MONO, 0},
	Tk_Offset(TkMenu, disabledFgPtr), -1, TK_OPTION_NULL_OK,
	(ClientData) DEF_MENU_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_MENU_FONT, offsetof(TkMenu, fontPtr), TCL_INDEX_NONE, 0, NULL, 0},
	DEF_MENU_FONT, Tk_Offset(TkMenu, fontPtr), -1, 0, NULL, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_MENU_FG, offsetof(TkMenu, fgPtr), TCL_INDEX_NONE, 0, NULL, 0},
	DEF_MENU_FG, Tk_Offset(TkMenu, fgPtr), -1, 0, NULL, 0},
    {TK_OPTION_STRING, "-postcommand", "postCommand", "Command",
	DEF_MENU_POST_COMMAND,
	offsetof(TkMenu, postCommandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenu, postCommandPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_MENU_RELIEF, TCL_INDEX_NONE, offsetof(TkMenu, relief), 0, NULL, 0},
	DEF_MENU_RELIEF, Tk_Offset(TkMenu, reliefPtr), -1, 0, NULL, 0},
    {TK_OPTION_COLOR, "-selectcolor", "selectColor", "Background",
	DEF_MENU_SELECT_COLOR, offsetof(TkMenu, indicatorFgPtr), TCL_INDEX_NONE, 0,
	DEF_MENU_SELECT_MONO, 0},
	DEF_MENU_SELECT_COLOR, Tk_Offset(TkMenu, indicatorFgPtr), -1, 0,
	(ClientData) DEF_MENU_SELECT_MONO, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_MENU_TAKE_FOCUS,
	offsetof(TkMenu, takeFocusPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenu, takeFocusPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_BOOLEAN, "-tearoff", "tearOff", "TearOff",
	DEF_MENU_TEAROFF, TCL_INDEX_NONE, offsetof(TkMenu, tearoff), 0, NULL, 0},
	DEF_MENU_TEAROFF, -1, Tk_Offset(TkMenu, tearoff), 0, NULL, 0},
    {TK_OPTION_STRING, "-tearoffcommand", "tearOffCommand",
	"TearOffCommand", DEF_MENU_TEAROFF_CMD,
	offsetof(TkMenu, tearoffCommandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0},
	Tk_Offset(TkMenu, tearoffCommandPtr), -1, TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING, "-title", "title", "Title",
	DEF_MENU_TITLE,	 offsetof(TkMenu, titlePtr), TCL_INDEX_NONE,
	DEF_MENU_TITLE,	 Tk_Offset(TkMenu, titlePtr), -1,
	TK_OPTION_NULL_OK, NULL, 0},
    {TK_OPTION_STRING_TABLE, "-type", "type", "Type",
	DEF_MENU_TYPE, offsetof(TkMenu, menuTypePtr), TCL_INDEX_NONE,
	0, menuTypeStrings, 0},
	DEF_MENU_TYPE, Tk_Offset(TkMenu, menuTypePtr), -1, TK_OPTION_NULL_OK,
	(ClientData) menuTypeStrings, 0},
    {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0}
};

/*
 * Command line options. Put here because MenuCmd has to look at them along
 * with MenuWidgetObjCmd.
 */

static const char *const menuOptions[] = {
    "activate", "add", "cget", "clone", "configure", "delete", "entrycget",
    "entryconfigure", "id", "index", "insert", "invoke", "post", "postcascade",
    "entryconfigure", "index", "insert", "invoke", "post", "postcascade",
    "type", "unpost", "xposition", "yposition", NULL
};
enum options {
    MENU_ACTIVATE, MENU_ADD, MENU_CGET, MENU_CLONE, MENU_CONFIGURE,
    MENU_DELETE, MENU_ENTRYCGET, MENU_ENTRYCONFIGURE, MENU_ID, MENU_INDEX,
    MENU_DELETE, MENU_ENTRYCGET, MENU_ENTRYCONFIGURE, MENU_INDEX,
    MENU_INSERT, MENU_INVOKE, MENU_POST, MENU_POSTCASCADE, MENU_TYPE,
    MENU_UNPOST, MENU_XPOSITION, MENU_YPOSITION
};

/*
 * Prototypes for static functions in this file:
 */

static int		CloneMenu(TkMenu *menuPtr, Tcl_Obj *newMenuName,
			    Tcl_Obj *newMenuTypeString);
static int		ConfigureMenu(Tcl_Interp *interp, TkMenu *menuPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static int		ConfigureMenuCloneEntries(TkMenu *menuPtr, int index,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		ConfigureMenuCloneEntries(Tcl_Interp *interp,
			    TkMenu *menuPtr, int index,
			    int objc, Tcl_Obj *const objv[]);
static int		ConfigureMenuEntry(TkMenuEntry *mePtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static void		DeleteMenuCloneEntries(TkMenu *menuPtr,
			    int first, int last);
static void		DestroyMenuHashTable(void *clientData,
static void		DestroyMenuHashTable(ClientData clientData,
			    Tcl_Interp *interp);
static void		DestroyMenuInstance(TkMenu *menuPtr);
static Tcl_FreeProc	DestroyMenuEntry;
static Tcl_Size	GetIndexFromCoords(Tcl_Interp *interp,
static void		DestroyMenuEntry(void *memPtr);
static int		GetIndexFromCoords(Tcl_Interp *interp,
			    TkMenu *menuPtr, const char *string,
			    Tcl_Size *indexPtr);
			    int *indexPtr);
static int		MenuDoYPosition(Tcl_Interp *interp,
			    TkMenu *menuPtr, Tcl_Obj *objPtr);
static int		MenuDoXPosition(Tcl_Interp *interp,
			    TkMenu *menuPtr, Tcl_Obj *objPtr);
static int		MenuAddOrInsert(Tcl_Interp *interp,
			    TkMenu *menuPtr, Tcl_Obj *indexPtr, Tcl_Size objc,
			    TkMenu *menuPtr, Tcl_Obj *indexPtr, int objc,
			    Tcl_Obj *const objv[]);
static void		MenuCmdDeletedProc(void *clientData);
static TkMenuEntry *	MenuNewEntry(TkMenu *menuPtr, Tcl_Size index, int type);
static char *		MenuVarProc(void *clientData,
static void		MenuCmdDeletedProc(ClientData clientData);
static TkMenuEntry *	MenuNewEntry(TkMenu *menuPtr, int index, int type);
static char *		MenuVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static Tcl_ObjCmdProc MenuWidgetObjCmd;
static void		MenuWorldChanged(void *instanceData);
static int		MenuWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		MenuWorldChanged(ClientData instanceData);
static int		PostProcessEntry(TkMenuEntry *mePtr);
static void		RecursivelyDeleteMenu(TkMenu *menuPtr);
static void		UnhookCascadeEntry(TkMenuEntry *mePtr);
static void		MenuCleanup(void *unused);
static void		TkMenuCleanup(ClientData unused);
static int		GetMenuIndex(Tcl_Interp *interp, TkMenu *menuPtr,
			    Tcl_Obj *objPtr, int lastOK, Tcl_Size *indexPtr);

/*
 * The structure below is a list of procs that respond to certain window
 * manager events. One of these includes a font change, which forces the
 * geometry proc to be called.
 */

386
387
388
389
390
391
392
393

394
395
396
397
398

399
400

401
402
403

404
405
406

407
408
409
410
411
412
413
395
396
397
398
399
400
401

402
403
404
405
406

407
408

409
410


411
412
413

414
415
416
417
418
419
420
421







-
+




-
+

-
+

-
-
+


-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_MenuObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    Tk_Window newWin;
    TkMenu *menuPtr;
    register TkMenu *menuPtr;
    TkMenuReferences *menuRefPtr;
    Tcl_Size i;
    int index, toplevel;
    int i, index, toplevel;
    const char *windowName;
    static const char *const typeStringList[] = {"-type", NULL};
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450
451



452
453
454
455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456



457
458
459
460


461
462
463
464
465
466
467

468
469
470
471
472
473
474
475







-
+







-
-
-
+
+
+

-
-







-
+








    /*
     * Initialize the data structure for the menu. Note that the menuPtr is
     * eventually freed in 'TkMenuEventProc' in tkMenuDraw.c, when
     * Tcl_EventuallyFree is called.
     */

    menuPtr = (TkMenu *)ckalloc(sizeof(TkMenu));
    menuPtr = ckalloc(sizeof(TkMenu));
    memset(menuPtr, 0, sizeof(TkMenu));
    menuPtr->tkwin = newWin;
    menuPtr->display = Tk_Display(newWin);
    menuPtr->interp = interp;
    menuPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(menuPtr->tkwin), MenuWidgetObjCmd, menuPtr,
	    MenuCmdDeletedProc);
    menuPtr->active = TCL_INDEX_NONE;
    menuPtr->cursorPtr = NULL;
    menuPtr->mainMenuPtr = menuPtr;
    menuPtr->active = -1;
    menuPtr->cursorPtr = None;
    menuPtr->masterMenuPtr = menuPtr;
    menuPtr->menuType = UNKNOWN_TYPE;
    Tcl_InitHashTable(&menuPtr->items, TCL_STRING_KEYS);
    menuPtr->serial = 0;
    TkMenuInitializeDrawingFields(menuPtr);

    Tk_SetClass(menuPtr->tkwin, "Menu");
    Tk_SetClassProcs(menuPtr->tkwin, &menuClass, menuPtr);
    Tk_CreateEventHandler(newWin,
	    ExposureMask|StructureNotifyMask|ActivateMask,
	    TkMenuEventProc, menuPtr);
    if (Tk_InitOptions(interp, menuPtr,
    if (Tk_InitOptions(interp, (char *) menuPtr,
	    tsdPtr->menuOptionTable, menuPtr->tkwin)
	    != TCL_OK) {
    	Tk_DestroyWindow(menuPtr->tkwin);
    	return TCL_ERROR;
    }


503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518
519
520



521
522

523
524
525
526
527
528
529
530

531
532

533
534
535
536
537
538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523



524
525
526
527

528
529
530
531
532
533
534
535

536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559







-
+







-
-
-
+
+
+

-
+







-
+

-
+













-
+







	TkMenuEntry *nextCascadePtr;
	Tcl_Obj *newMenuName, *newObjv[2];

	while (cascadeListPtr != NULL) {
	    nextCascadePtr = cascadeListPtr->nextCascadePtr;

     	    /*
	     * If we have a new main menu, and an existing cloned menu
	     * If we have a new master menu, and an existing cloned menu
	     * points to this menu in a cascade entry, we have to clone the
	     * new menu and point the entry to the clone instead of the menu
	     * we are creating. Otherwise, ConfigureMenuEntry will hook up the
	     * platform-specific cascade linkages now that the menu we are
	     * creating exists.
     	     */

     	    if ((menuPtr->mainMenuPtr != menuPtr)
     	    	    || ((menuPtr->mainMenuPtr == menuPtr)
     	    	    && ((cascadeListPtr->menuPtr->mainMenuPtr
     	    if ((menuPtr->masterMenuPtr != menuPtr)
     	    	    || ((menuPtr->masterMenuPtr == menuPtr)
     	    	    && ((cascadeListPtr->menuPtr->masterMenuPtr
		    == cascadeListPtr->menuPtr)))) {
		newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
		newObjv[0] = Tcl_NewStringObj("-menu", -1);
		newObjv[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin),-1);
		Tcl_IncrRefCount(newObjv[0]);
		Tcl_IncrRefCount(newObjv[1]);
     	    	ConfigureMenuEntry(cascadeListPtr, 2, newObjv);
		Tcl_DecrRefCount(newObjv[0]);
		Tcl_DecrRefCount(newObjv[1]);
     	    } else {
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE);
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1);
		Tcl_Obj *windowNamePtr = Tcl_NewStringObj(
			Tk_PathName(cascadeListPtr->menuPtr->tkwin), TCL_INDEX_NONE);
			Tk_PathName(cascadeListPtr->menuPtr->tkwin), -1);

		Tcl_IncrRefCount(normalPtr);
		Tcl_IncrRefCount(windowNamePtr);
		newMenuName = TkNewMenuName(menuPtr->interp,
     	    		windowNamePtr, menuPtr);
		Tcl_IncrRefCount(newMenuName);
		CloneMenu(menuPtr, newMenuName, normalPtr);

		/*
		 * Now we can set the new menu instance to be the cascade
		 * entry of the parent's instance.
		 */

		newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
		newObjv[0] = Tcl_NewStringObj("-menu", -1);
		newObjv[1] = newMenuName;
		Tcl_IncrRefCount(newObjv[0]);
		ConfigureMenuEntry(cascadeListPtr, 2, newObjv);
		Tcl_DecrRefCount(normalPtr);
		Tcl_DecrRefCount(newObjv[0]);
		Tcl_DecrRefCount(newObjv[1]);
		Tcl_DecrRefCount(windowNamePtr);
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579

580
581
582
583
584
585

586
587
588
589
590
591
592
571
572
573
574
575
576
577

578
579
580
581
582
583
584

585
586
587
588
589
590

591
592
593
594
595
596
597
598







-
+






-
+





-
+







    if (menuRefPtr->topLevelListPtr != NULL) {
    	TkMenuTopLevelList *topLevelListPtr = menuRefPtr->topLevelListPtr;
    	TkMenuTopLevelList *nextPtr;
    	Tk_Window listtkwin;

	while (topLevelListPtr != NULL) {
    	    /*
    	     * Need to get the next pointer first. Tk_SetWindowMenubar changes
    	     * Need to get the next pointer first. TkSetWindowMenuBar changes
    	     * the list, so that the next pointer is different after calling
    	     * it.
    	     */

    	    nextPtr = topLevelListPtr->nextPtr;
    	    listtkwin = topLevelListPtr->tkwin;
    	    Tk_SetWindowMenubar(menuPtr->interp, listtkwin,
    	    TkSetWindowMenuBar(menuPtr->interp, listtkwin,
    	    	    Tk_PathName(menuPtr->tkwin), Tk_PathName(menuPtr->tkwin));
    	    topLevelListPtr = nextPtr;
    	}
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(menuPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(menuPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * MenuWidgetObjCmd --
602
603
604
605
606
607
608
609

610
611
612
613
614
615


616
617
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639

640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
608
609
610
611
612
613
614

615
616
617
618
619


620
621
622
623

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644

645
646
647
648
649
650
651
652

653
654
655
656
657
658
659
660







-
+




-
-
+
+


-
+














-
+





-
+







-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
MenuWidgetObjCmd(
    void *clientData,	/* Information about menu widget. */
    ClientData clientData,	/* Information about menu widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenuEntry *mePtr;
    register TkMenu *menuPtr = clientData;
    register TkMenuEntry *mePtr;
    int result = TCL_OK;
    int option;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], menuOptions,
	    sizeof(char *), "option", 0, &option) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_Preserve(menuPtr);

    switch ((enum options) option) {
    case MENU_ACTIVATE: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (menuPtr->active == index) {
	    goto done;
	}
	if ((index >= 0) && ((menuPtr->entries[index]->type==SEPARATOR_ENTRY)
		|| (menuPtr->entries[index]->state == ENTRY_DISABLED))) {
	    index = TCL_INDEX_NONE;
	    index = -1;
	}
	result = TkActivateMenuEntry(menuPtr, index);
	break;
    }
    case MENU_ADD:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "type ?-option value ...?");
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717

718
719
720
721
722
723
724
725
726
727
728
729
730
731

732
733
734
735
736

737
738
739
740
741

742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767

768
769
770
771
772
773
774
775

776
777
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792

793
794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
809
810

811
812
813
814
815
816
817
818
819

820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848

849
850
851
852
853
854

855
856
857
858

859
860

861
862
863
864
865
866
867
868
869
870
871
872
873
874
875

876
877
878
879
880
881

882
883
884
885
886
887
888
889
890
891
892
893
894
895


896
897
898
899
900
901
902
903
904
905

906
907
908
909
910
911
912
913





914
915
916
917
918
919
920

921
922

923
924
925
926
927

928
929
930
931
932
933
934

935
936
937
938
939
940
941
942
943
944
945

946
947
948
949
950
951
952

953
954
955
956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722

723

724
725
726
727
728
729
730
731
732
733
734
735

736

737
738
739

740
741
742
743
744

745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770

771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795

796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822

823
824
825
826
827
828






















829

830
831
832
833
834
835

836
837
838
839

840
841

842
843
844
845
846
847
848
849
850
851
852
853
854
855
856

857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873

874


875
876
877
878
879
880
881
882




883


884





885
886
887
888
889
890
891
892
893
894
895

896
897

898
899
900
901
902

903
904
905
906
907
908
909

910
911
912
913
914
915
916
917
918
919
920

921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946







-
+



















-
+









-
+

















-
+
-












-
+
-



-
+




-
+


















-
+






-
+







-
+









-
+






-
+








-
+








-
+








-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+





-
+



-
+

-
+














-
+





-
+










-

-
-
+
+






-
-
-
-
+
-
-

-
-
-
-
-
+
+
+
+
+






-
+

-
+




-
+






-
+










-
+






-
+










-
+







    case MENU_CGET: {
	Tcl_Obj *resultPtr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    goto error;
	}
	resultPtr = Tk_GetOptionValue(interp, menuPtr,
	resultPtr = Tk_GetOptionValue(interp, (char *) menuPtr,
		tsdPtr->menuOptionTable, objv[2],
		menuPtr->tkwin);
	if (resultPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, resultPtr);
	break;
    }
    case MENU_CLONE:
	if ((objc < 3) || (objc > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "newMenuName ?menuType?");
	    goto error;
	}
	result = CloneMenu(menuPtr, objv[2], (objc == 3) ? NULL : objv[3]);
	break;
    case MENU_CONFIGURE: {
	Tcl_Obj *resultPtr;

	if (objc == 2) {
	    resultPtr = Tk_GetOptionInfo(interp, menuPtr,
	    resultPtr = Tk_GetOptionInfo(interp, (char *) menuPtr,
		    tsdPtr->menuOptionTable, NULL,
		    menuPtr->tkwin);
	    if (resultPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		result = TCL_OK;
		Tcl_SetObjResult(interp, resultPtr);
	    }
	} else if (objc == 3) {
	    resultPtr = Tk_GetOptionInfo(interp, menuPtr,
	    resultPtr = Tk_GetOptionInfo(interp, (char *) menuPtr,
		    tsdPtr->menuOptionTable, objv[2],
		    menuPtr->tkwin);
	    if (resultPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		result = TCL_OK;
		Tcl_SetObjResult(interp, resultPtr);
	    }
	} else {
	    result = ConfigureMenu(interp, menuPtr, objc - 2, objv + 2);
	}
	if (result != TCL_OK) {
	    goto error;
	}
	break;
    }
    case MENU_DELETE: {
	Tcl_Size first, last;
	int first, last;
	Tcl_WideInt w;

	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "first ?last?");
	    goto error;
	}

	/*
	 * If 'first' explicitly refers to past the end of the menu, we don't
	 * do anything. [Bug 220950]
	 */

	if (isdigit(UCHAR(Tcl_GetString(objv[2])[0]))
		&& Tcl_GetWideIntFromObj(NULL, objv[2], &w) == TCL_OK) {
		&& Tcl_GetIntFromObj(NULL, objv[2], &first) == TCL_OK) {
	    first = w;
	    if (first >= menuPtr->numEntries) {
		goto done;
	    }
	} else if (GetMenuIndex(interp,menuPtr,objv[2],0,&first) != TCL_OK){
	} else if (TkGetMenuIndex(interp,menuPtr,objv[2],0,&first) != TCL_OK){
	    goto error;
	}
	if (objc == 3) {
	    last = first;
	} else if (GetMenuIndex(interp,menuPtr,objv[3],0,&last) != TCL_OK) {
	} else if (TkGetMenuIndex(interp,menuPtr,objv[3],0,&last) != TCL_OK) {
	    goto error;
	}

	if (menuPtr->tearoff && (first == 0)) {
	    /*
	     * Sorry, can't delete the tearoff entry; must reconfigure the
	     * menu.
	     */

	    first = 1;
	}
	if ((first < 0) || (last < first)) {
	    goto done;
	}
	DeleteMenuCloneEntries(menuPtr, first, last);
	break;
    }
    case MENU_ENTRYCGET: {
	Tcl_Size index;
	int index;
	Tcl_Obj *resultPtr;

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index option");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    goto done;
	}
	mePtr = menuPtr->entries[index];
	Tcl_Preserve(mePtr);
	resultPtr = Tk_GetOptionValue(interp, mePtr,
	resultPtr = Tk_GetOptionValue(interp, (char *) mePtr,
		mePtr->optionTable, objv[3], menuPtr->tkwin);
	Tcl_Release(mePtr);
	if (resultPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, resultPtr);
	break;
    }
    case MENU_ENTRYCONFIGURE: {
	Tcl_Size index;
	int index;
	Tcl_Obj *resultPtr;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index ?-option value ...?");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    goto done;
	}
	mePtr = menuPtr->entries[index];
	Tcl_Preserve(mePtr);
	if (objc == 3) {
	    resultPtr = Tk_GetOptionInfo(interp, mePtr,
	    resultPtr = Tk_GetOptionInfo(interp, (char *) mePtr,
		    mePtr->optionTable, NULL, menuPtr->tkwin);
	    if (resultPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		result = TCL_OK;
		Tcl_SetObjResult(interp, resultPtr);
	    }
	} else if (objc == 4) {
	    resultPtr = Tk_GetOptionInfo(interp, mePtr,
	    resultPtr = Tk_GetOptionInfo(interp, (char *) mePtr,
		    mePtr->optionTable, objv[3], menuPtr->tkwin);
	    if (resultPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		result = TCL_OK;
		Tcl_SetObjResult(interp, resultPtr);
	    }
	} else {
	    result = ConfigureMenuCloneEntries(menuPtr, index,
	    result = ConfigureMenuCloneEntries(interp, menuPtr, index,
		    objc-3, objv+3);
	}
	Tcl_Release(mePtr);
	break;
    }
    case MENU_ID: {
	Tcl_Size index;
	const char *idStr;
	Tcl_HashEntry *entryPtr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    goto done;
	}
	entryPtr = menuPtr->entries[index]->entryPtr;
	if (entryPtr) {
	    idStr = (const char *)Tcl_GetHashKey(&menuPtr->items, entryPtr);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(idStr, TCL_INDEX_NONE));
	}
	break;
    }
    case MENU_INDEX: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "string");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewObj());
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("none", -1));
	} else {
	    Tcl_SetObjResult(interp, TkNewIndexObj(index));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	}
	break;
    }
    case MENU_INSERT:
	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "index type ?-option value ...?");
	    goto error;
	}
	if (MenuAddOrInsert(interp,menuPtr,objv[2],objc-3,objv+3) != TCL_OK) {
	    goto error;
	}
	break;
    case MENU_INVOKE: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    goto done;
	}
	result = TkInvokeMenu(interp, menuPtr, index);
	break;
    }
    case MENU_POST: {
	int x, y;
	Tcl_Size index = TCL_INDEX_NONE;

	if (objc != 4 && objc != 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "x y ?index?");
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "x y");
	    goto error;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	    goto error;
	}
	if (objc == 5) {
            if (GetMenuIndex(interp, menuPtr, objv[4], 0, &index) != TCL_OK) {
                goto error;
            }

	}

	/*
	 * Tearoff menus are the same as ordinary menus on the Mac and are
	 * posted differently on Windows than non-tearoffs. TkpPostMenu
	 * does not actually map the menu's window on those platforms, and
	 * popup menus have to be handled specially.  Also, menubar menus are
	 * not intended to be posted (bug 1567681, 2160206).
	 * Tearoff menus are posted differently on Mac and Windows than
	 * non-tearoffs. TkpPostMenu does not actually map the menu's window
	 * on those platforms, and popup menus have to be handled specially.
         * Also, menubar menues are not intended to be posted (bug 1567681,
         * 2160206).
	 */

	if (menuPtr->menuType == MENUBAR) {
            Tcl_AppendResult(interp, "a menubar menu cannot be posted", NULL);
            return TCL_ERROR;
        } else if (menuPtr->menuType != TEAROFF_MENU) {
	    result = TkpPostMenu(interp, menuPtr, x, y, index);
	    result = TkpPostMenu(interp, menuPtr, x, y);
	} else {
	    result = TkpPostTearoffMenu(interp, menuPtr, x, y, index);
	    result = TkPostTearoffMenu(interp, menuPtr, x, y);
	}
	break;
    }
    case MENU_POSTCASCADE: {
	Tcl_Size index;
	int index;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}

	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if ((index < 0) || (menuPtr->entries[index]->type != CASCADE_ENTRY)) {
	    result = TkPostSubmenu(interp, menuPtr, NULL);
	} else {
	    result = TkPostSubmenu(interp, menuPtr, menuPtr->entries[index]);
	}
	break;
    }
    case MENU_TYPE: {
	Tcl_Size index;
	int index;
	const char *typeStr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    goto error;
	}
	if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) {
	    goto error;
	}
	if (index < 0) {
	    goto done;
	}
	if (menuPtr->entries[index]->type == TEAROFF_ENTRY) {
	    typeStr = "tearoff";
	} else {
	    typeStr = menuEntryTypeStrings[menuPtr->entries[index]->type];
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, -1));
	break;
    }
    case MENU_UNPOST:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	    goto error;
	}
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041



1042
1043
1044
1045
1046
1047
1048
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024







-
+


















-
-
-
+
+
+







 *----------------------------------------------------------------------
 */

int
TkInvokeMenu(
    Tcl_Interp *interp,		/* The interp that the menu lives in. */
    TkMenu *menuPtr,		/* The menu we are invoking. */
    Tcl_Size index)			/* The zero based index of the item we are
    int index)			/* The zero based index of the item we are
    				 * invoking. */
{
    int result = TCL_OK;
    TkMenuEntry *mePtr;

    if (index < 0) {
    	goto done;
    }
    mePtr = menuPtr->entries[index];
    if (mePtr->state == ENTRY_DISABLED) {
	goto done;
    }

    Tcl_Preserve(mePtr);
    if (mePtr->type == TEAROFF_ENTRY) {
	Tcl_DString ds;

	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, "tk::TearOffMenu ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&ds, Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&ds), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&ds, "tk::TearOffMenu ", -1);
	Tcl_DStringAppend(&ds, Tk_PathName(menuPtr->tkwin), -1);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&ds), -1, 0);
	Tcl_DStringFree(&ds);
    } else if ((mePtr->type == CHECK_BUTTON_ENTRY)
	    && (mePtr->namePtr != NULL)) {
	Tcl_Obj *valuePtr;

	if (mePtr->entryFlags & ENTRY_SELECTED) {
	    valuePtr = mePtr->offValuePtr;
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124



1125
1126
1127
1128
1129
1130
1131
1132
1133


1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155


1156
1157
1158
1159



1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181


1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243

1244
1245
1246
1247




1248
1249
1250
1251
1252
1253
1254
1091
1092
1093
1094
1095
1096
1097



1098
1099
1100
1101
1102
1103
1104
1105
1106
1107


1108
1109
1110
1111

1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129


1130
1131
1132



1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155


1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171
1172
1173
1174
1175











1176
1177
1178
1179
1180
1181
1182


1183
1184
1185

1186
1187

1188

1189

1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205




1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216







-
-
-
+
+
+







-
-
+
+


-
+

















-
-
+
+

-
-
-
+
+
+

-
+


















-
-
+
+









-
+








-
-
-
-
-
-
-
-
-
-
-







-
-
+


-


-

-

-
+














+
-
-
-
-
+
+
+
+







DestroyMenuInstance(
    TkMenu *menuPtr)		/* Info about menu widget. */
{
    int i;
    TkMenu *menuInstancePtr;
    TkMenuEntry *cascadePtr, *nextCascadePtr;
    Tcl_Obj *newObjv[2];
    TkMenu *parentMainMenuPtr;
    TkMenuEntry *parentMainEntryPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    TkMenu *parentMasterMenuPtr;
    TkMenuEntry *parentMasterEntryPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * If the menu has any cascade menu entries pointing to it, the cascade
     * entries need to be told that the menu is going away. We need to clear
     * the menu ptr field in the menu reference at this point in the code so
     * that everything else can forget about this menu properly. We also need
     * to reset -menu field of all entries that are not main menus back to
     * this entry name if this is a main menu pointed to by another main
     * to reset -menu field of all entries that are not master menus back to
     * this entry name if this is a master menu pointed to by another master
     * menu. If there is a clone menu that points to this menu, then this menu
     * is itself a clone, so when this menu goes away, the -menu field of the
     * pointing entry must be set back to this menu's main menu name so that
     * pointing entry must be set back to this menu's master menu name so that
     * later if another menu is created the cascade hierarchy can be
     * maintained.
     */

    TkpDestroyMenu(menuPtr);
    if (menuPtr->menuRefPtr == NULL) {
	return;
    }
    cascadePtr = menuPtr->menuRefPtr->parentEntryPtr;
    menuPtr->menuRefPtr->menuPtr = NULL;
    if (TkFreeMenuReferences(menuPtr->menuRefPtr)) {
	menuPtr->menuRefPtr = NULL;
    }

    for (; cascadePtr != NULL; cascadePtr = nextCascadePtr) {
    	nextCascadePtr = cascadePtr->nextCascadePtr;

    	if (menuPtr->mainMenuPtr != menuPtr) {
	    Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
    	if (menuPtr->masterMenuPtr != menuPtr) {
	    Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", -1);

	    parentMainMenuPtr = cascadePtr->menuPtr->mainMenuPtr;
	    parentMainEntryPtr =
		    parentMainMenuPtr->entries[cascadePtr->index];
	    parentMasterMenuPtr = cascadePtr->menuPtr->masterMenuPtr;
	    parentMasterEntryPtr =
		    parentMasterMenuPtr->entries[cascadePtr->index];
	    newObjv[0] = menuNamePtr;
	    newObjv[1] = parentMainEntryPtr->namePtr;
	    newObjv[1] = parentMasterEntryPtr->namePtr;

	    /*
	     * It is possible that the menu info is out of sync, and these
	     * things point to NULL, so verify existence [Bug: 3402]
	     */

	    if (newObjv[0] && newObjv[1]) {
		Tcl_IncrRefCount(newObjv[0]);
		Tcl_IncrRefCount(newObjv[1]);
		ConfigureMenuEntry(cascadePtr, 2, newObjv);
		Tcl_DecrRefCount(newObjv[0]);
		Tcl_DecrRefCount(newObjv[1]);
	    }
    	} else {
    	    ConfigureMenuEntry(cascadePtr, 0, NULL);
    	}
    }

    if (menuPtr->mainMenuPtr != menuPtr) {
	for (menuInstancePtr = menuPtr->mainMenuPtr;
    if (menuPtr->masterMenuPtr != menuPtr) {
	for (menuInstancePtr = menuPtr->masterMenuPtr;
		menuInstancePtr != NULL;
		menuInstancePtr = menuInstancePtr->nextInstancePtr) {
	    if (menuInstancePtr->nextInstancePtr == menuPtr) {
		menuInstancePtr->nextInstancePtr =
			menuInstancePtr->nextInstancePtr->nextInstancePtr;
		break;
	    }
	}
    } else if (menuPtr->nextInstancePtr != NULL) {
	Tcl_Panic("Attempting to delete main menu when there are still clones");
	Tcl_Panic("Attempting to delete master menu when there are still clones");
    }

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeConfigOptions handle all the standard option-related stuff.
     */

    for (i = menuPtr->numEntries; --i >= 0; ) {
        /*
         * Clean up the hash entry for the menu item ID.
         * This cannot be postponed until the entry is eventually freed,
         * because the hash table may already have been deleted by then.
         */

        if (menuPtr->entries[i]->entryPtr) {
            Tcl_DeleteHashEntry(menuPtr->entries[i]->entryPtr);
            menuPtr->entries[i]->entryPtr = NULL;
        }

	/*
	 * As each menu entry is deleted from the end of the array of entries,
	 * decrement menuPtr->numEntries. Otherwise, the act of deleting menu
	 * entry i will dereference freed memory attempting to queue a redraw
	 * for menu entries (i+1)...numEntries.
	 */

	Tcl_EventuallyFree(menuPtr->entries[i],
		DestroyMenuEntry);
	DestroyMenuEntry(menuPtr->entries[i]);
	menuPtr->numEntries = i;
    }
    menuPtr->active = -1;
    if (menuPtr->entries != NULL) {
	ckfree(menuPtr->entries);
	menuPtr->entries = NULL;
    }
    Tcl_DeleteHashTable(&menuPtr->items);
    TkMenuFreeDrawOptions(menuPtr);
    Tk_FreeConfigOptions(menuPtr,
    Tk_FreeConfigOptions((char *) menuPtr,
	    tsdPtr->menuOptionTable, menuPtr->tkwin);
    if (menuPtr->tkwin != NULL) {
	Tk_Window tkwin = menuPtr->tkwin;

	menuPtr->tkwin = NULL;
	Tk_DestroyWindow(tkwin);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkDestroyMenu --
 *
 *	This function is invoked by Tcl_EventuallyFree or Tcl_Release to clean
 *	This function is invoked to clean up the internal structure of a menu
 *	at a safe time (when no-one is using it anymore). If called on a main
 *	instance, destroys all of the instances. If called on a non-main
 *	instance, just destroys that instance.
 *	up the internal structure of a menu at a safe time (when no-one is
 *	using it anymore). If called on a master instance, destroys all of the
 *	slave instances. If called on a non-master instance, just destroys
 *	that instance.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the menu is freed up.
 *
1285
1286
1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297
1298
1299
1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1261







-
+







	topLevelListPtr = menuPtr->menuRefPtr->topLevelListPtr;
	while (topLevelListPtr != NULL) {
	    nextTopLevelPtr = topLevelListPtr->nextPtr;
	    TkpSetWindowMenuBar(topLevelListPtr->tkwin, NULL);
	    topLevelListPtr = nextTopLevelPtr;
	}
    }
    if (menuPtr->mainMenuPtr == menuPtr) {
    if (menuPtr->masterMenuPtr == menuPtr) {
	while (menuPtr->nextInstancePtr != NULL) {
	    menuInstancePtr = menuPtr->nextInstancePtr;
	    menuPtr->nextInstancePtr = menuInstancePtr->nextInstancePtr;
    	    if (menuInstancePtr->tkwin != NULL) {
		Tk_Window tkwin = menuInstancePtr->tkwin;

		/*
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1374
1375
1376
1377
1378
1379
1380

1381



1382

1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429







-

-
-
-

-
+


















-
+



















-
+







 *	Everything associated with the menu entry is freed.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyMenuEntry(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Pointer to entry to be freed. */
#else
    char *memPtr)
#endif
{
    TkMenuEntry *mePtr = (TkMenuEntry *)memPtr;
    register TkMenuEntry *mePtr = memPtr;
    TkMenu *menuPtr = mePtr->menuPtr;

    if (menuPtr->postedCascade == mePtr) {
    	/*
	 * Ignore errors while unposting the menu, since it's possible that
	 * the menu has already been deleted and the unpost will generate an
	 * error.
	 */

	TkPostSubmenu(menuPtr->interp, menuPtr, NULL);
    }

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeConfigOptions handle all the standard option-related stuff.
     */

    if (mePtr->type == CASCADE_ENTRY) {
	if (menuPtr->mainMenuPtr != menuPtr) {
	if (menuPtr->masterMenuPtr != menuPtr) {
	    TkMenu *destroyThis = NULL;
	    TkMenuReferences *menuRefPtr = mePtr->childMenuRefPtr;

	    /*
	     * The menu as a whole is a clone. We must delete the clone of the
	     * cascaded menu for the particular entry we are destroying.
	     */

	    if (menuRefPtr != NULL) {
		destroyThis = menuRefPtr->menuPtr;

		/*
		 * But only if it is a clone. What can happen is that we are
		 * in the middle of deleting a menu and this menu pointer has
		 * already been reset to point to the original menu. In that
		 * case we have nothing special to do.
		 */

		if ((destroyThis != NULL)
			&& (destroyThis->mainMenuPtr == destroyThis)) {
			&& (destroyThis->masterMenuPtr == destroyThis)) {
		    destroyThis = NULL;
		}
	    }
	    UnhookCascadeEntry(mePtr);
	    menuRefPtr = mePtr->childMenuRefPtr;
	    if (menuRefPtr != NULL) {
		if (menuRefPtr->menuPtr == destroyThis) {
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1448
1449
1450
1451
1452
1453
1454




1455
1456

1457
1458
1459
1460
1461
1462
1463
1464







-
-
-
-


-
+







	    && (mePtr->namePtr != NULL)) {
	const char *varName = Tcl_GetString(mePtr->namePtr);

	Tcl_UntraceVar2(menuPtr->interp, varName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MenuVarProc, mePtr);
    }
    if (mePtr->entryPtr) {
        Tcl_DeleteHashEntry(mePtr->entryPtr);
        mePtr->entryPtr = NULL;
    }
    TkpDestroyMenuEntry(mePtr);
    TkMenuEntryFreeDrawOptions(mePtr);
    Tk_FreeConfigOptions(mePtr, mePtr->optionTable, menuPtr->tkwin);
    Tk_FreeConfigOptions((char *) mePtr, mePtr->optionTable, menuPtr->tkwin);
    ckfree(mePtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * MenuWorldChanged --
1520
1521
1522
1523
1524
1525
1526
1527

1528
1529
1530


1531
1532
1533
1534
1535
1536
1537
1474
1475
1476
1477
1478
1479
1480

1481
1482


1483
1484
1485
1486
1487
1488
1489
1490
1491







-
+

-
-
+
+







 *	Menu will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
MenuWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    TkMenu *menuPtr = (TkMenu *)instanceData;
    Tcl_Size i;
    TkMenu *menuPtr = instanceData;
    int i;

    TkMenuConfigureDrawOptions(menuPtr);
    for (i = 0; i < menuPtr->numEntries; i++) {
    	TkMenuConfigureEntryDrawOptions(menuPtr->entries[i],
		menuPtr->entries[i]->index);
	TkpConfigureMenuEntry(menuPtr->entries[i]);
    }
1556
1557
1558
1559
1560
1561
1562
1563

1564
1565

1566
1567
1568
1569
1570
1571

1572
1573
1574

1575
1576
1577


1578
1579
1580
1581

1582
1583
1584
1585
1586
1587
1588
1510
1511
1512
1513
1514
1515
1516

1517
1518

1519
1520
1521
1522
1523
1524

1525
1526
1527

1528
1529


1530
1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541
1542







-
+

-
+





-
+


-
+

-
-
+
+



-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureMenu(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkMenu *menuPtr,	/* Information about widget; may or may not
    register TkMenu *menuPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    int i;
    TkMenu *menuListPtr, *cleanupPtr;
    int result;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL;
    for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL;
	    menuListPtr = menuListPtr->nextInstancePtr) {
	menuListPtr->errorStructPtr = (Tk_SavedOptions *)ckalloc(sizeof(Tk_SavedOptions));
	result = Tk_SetOptions(interp, menuListPtr,
	menuListPtr->errorStructPtr = ckalloc(sizeof(Tk_SavedOptions));
	result = Tk_SetOptions(interp, (char *) menuListPtr,
		tsdPtr->menuOptionTable, objc, objv,
		menuListPtr->tkwin, menuListPtr->errorStructPtr, NULL);
	if (result != TCL_OK) {
	    for (cleanupPtr = menuPtr->mainMenuPtr;
	    for (cleanupPtr = menuPtr->masterMenuPtr;
		    cleanupPtr != menuListPtr;
		    cleanupPtr = cleanupPtr->nextInstancePtr) {
		Tk_RestoreSavedOptions(cleanupPtr->errorStructPtr);
		ckfree(cleanupPtr->errorStructPtr);
		cleanupPtr->errorStructPtr = NULL;
	    }
	    if (menuListPtr->errorStructPtr != NULL) {
1608
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620
1621
1622
1562
1563
1564
1565
1566
1567
1568

1569
1570
1571
1572
1573
1574
1575
1576







-
+







	     * Configure the new window to be either a pop-up menu or a
	     * tear-off menu. We don't do this for menubars since they are not
	     * toplevel windows. Also, since this gets called before CloneMenu
	     * has a chance to set the menuType field, we have to look at the
	     * menuTypeName field to tell that this is a menu bar.
	     */

	    if (menuListPtr->menuType == MAIN_MENU) {
	    if (menuListPtr->menuType == MASTER_MENU) {
		int typeFlag = TK_MAKE_MENU_POPUP;
		Tk_Window tkwin = menuPtr->tkwin;

		/*
		 * Work out if we are the child of a menubar or a popup.
		 */

1643
1644
1645
1646
1647
1648
1649
1650

1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666

1667
1668

1669
1670
1671
1672
1673

1674

1675
1676
1677
1678
1679
1680
1681
1597
1598
1599
1600
1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633
1634
1635
1636
1637







-
+
















+

-
+





+
-
+







	 * an initial tear-off entry at the beginning of the menu.
	 */

	if (menuListPtr->tearoff) {
	    if ((menuListPtr->numEntries == 0)
		    || (menuListPtr->entries[0]->type != TEAROFF_ENTRY)) {
		if (MenuNewEntry(menuListPtr, 0, TEAROFF_ENTRY) == NULL) {
		    for (cleanupPtr = menuPtr->mainMenuPtr;
		    for (cleanupPtr = menuPtr->masterMenuPtr;
			    cleanupPtr != menuListPtr;
			    cleanupPtr = cleanupPtr->nextInstancePtr) {
			Tk_RestoreSavedOptions(cleanupPtr->errorStructPtr);
			ckfree(cleanupPtr->errorStructPtr);
			cleanupPtr->errorStructPtr = NULL;
		    }
		    if (menuListPtr->errorStructPtr != NULL) {
			Tk_RestoreSavedOptions(menuListPtr->errorStructPtr);
			ckfree(menuListPtr->errorStructPtr);
			menuListPtr->errorStructPtr = NULL;
		    }
		    return TCL_ERROR;
		}
	    }
	} else if ((menuListPtr->numEntries > 0)
		&& (menuListPtr->entries[0]->type == TEAROFF_ENTRY)) {
	    int i;

	    Tcl_EventuallyFree(menuListPtr->entries[0], DestroyMenuEntry);
	    Tcl_EventuallyFree(menuListPtr->entries[0], (Tcl_FreeProc *) DestroyMenuEntry);

	    for (i = 0; i < menuListPtr->numEntries - 1; i++) {
		menuListPtr->entries[i] = menuListPtr->entries[i + 1];
		menuListPtr->entries[i]->index = i;
	    }
	    menuListPtr->numEntries--;
	    if (--menuListPtr->numEntries == 0) {
	    if (menuListPtr->numEntries == 0) {
		ckfree(menuListPtr->entries);
		menuListPtr->entries = NULL;
	    }
	}

	TkMenuConfigureDrawOptions(menuListPtr);

1692
1693
1694
1695
1696
1697
1698
1699

1700
1701
1702
1703
1704
1705
1706
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1662







-
+







	    mePtr = menuListPtr->entries[i];
	    ConfigureMenuEntry(mePtr, 0, NULL);
	}

	TkEventuallyRecomputeMenu(menuListPtr);
    }

    for (cleanupPtr = menuPtr->mainMenuPtr; cleanupPtr != NULL;
    for (cleanupPtr = menuPtr->masterMenuPtr; cleanupPtr != NULL;
	    cleanupPtr = cleanupPtr->nextInstancePtr) {
	Tk_FreeSavedOptions(cleanupPtr->errorStructPtr);
	ckfree(cleanupPtr->errorStructPtr);
	cleanupPtr->errorStructPtr = NULL;
    }

    return TCL_OK;
1772
1773
1774
1775
1776
1777
1778
1779

1780
1781
1782
1783
1784
1785
1786
1728
1729
1730
1731
1732
1733
1734

1735
1736
1737
1738
1739
1740
1741
1742







-
+







	 * the list of entries pointing to the new menu.
	 *
	 * BUG: We are not recloning for special case #3 yet.
	 */

	name = Tcl_GetString(mePtr->namePtr);
	if (mePtr->childMenuRefPtr != NULL) {
	    oldHashKey = (char *)Tcl_GetHashKey(TkGetMenuHashTable(menuPtr->interp),
	    oldHashKey = Tcl_GetHashKey(TkGetMenuHashTable(menuPtr->interp),
		    mePtr->childMenuRefPtr->hashEntryPtr);
	    if (strcmp(oldHashKey, name) != 0) {
		UnhookCascadeEntry(mePtr);
	    }
	}

	if ((mePtr->childMenuRefPtr == NULL)
1854
1855
1856
1857
1858
1859
1860

1861
1862
1863
1864
1865
1866
1867
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824







+







	Tk_FreeImage(mePtr->selectImage);
    }
    mePtr->selectImage = image;

    if ((mePtr->type == CHECK_BUTTON_ENTRY)
	    || (mePtr->type == RADIO_BUTTON_ENTRY)) {
	Tcl_Obj *valuePtr;
	const char *name;

	if (mePtr->namePtr == NULL) {
	    if (mePtr->labelPtr == NULL) {
		mePtr->namePtr = NULL;
	    } else {
		mePtr->namePtr = Tcl_DuplicateObj(mePtr->labelPtr);
		Tcl_IncrRefCount(mePtr->namePtr);
1937
1938
1939
1940
1941
1942
1943
1944

1945
1946

1947
1948
1949
1950
1951
1952
1953
1894
1895
1896
1897
1898
1899
1900

1901
1902

1903
1904
1905
1906
1907
1908
1909
1910







-
+

-
+







 *	mePtr; old resources get freed, if there were any.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureMenuEntry(
    TkMenuEntry *mePtr,/* Information about menu entry; may or may
    register TkMenuEntry *mePtr,/* Information about menu entry; may or may
				 * not already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    TkMenu *menuPtr = mePtr->menuPtr;
    Tk_SavedOptions errorStruct;
    int result;

    /*
1963
1964
1965
1966
1967
1968
1969
1970

1971
1972
1973
1974
1975
1976
1977
1920
1921
1922
1923
1924
1925
1926

1927
1928
1929
1930
1931
1932
1933
1934







-
+







	Tcl_UntraceVar2(menuPtr->interp, name, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MenuVarProc, mePtr);
    }

    result = TCL_OK;
    if (menuPtr->tkwin != NULL) {
	if (Tk_SetOptions(menuPtr->interp, mePtr,
	if (Tk_SetOptions(menuPtr->interp, (char *) mePtr,
		mePtr->optionTable, objc, objv, menuPtr->tkwin,
		&errorStruct, NULL) != TCL_OK) {
	    return TCL_ERROR;
	}
	result = PostProcessEntry(mePtr);
	if (result != TCL_OK) {
	    Tk_RestoreSavedOptions(&errorStruct);
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
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







-
+
+










+


-
+











-
+






-
+







 *----------------------------------------------------------------------
 *
 * ConfigureMenuCloneEntries --
 *
 *	Calls ConfigureMenuEntry for each menu in the clone chain.
 *
 * Results:
 *	The return value is a standard Tcl result.
 *	The return value is a standard Tcl result. If TCL_ERROR is returned,
 *	then the interp's result contains an error message.
 *
 * Side effects:
 *	Configuration information such as label and accelerator get set for
 *	mePtr; old resources get freed, if there were any.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureMenuCloneEntries(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkMenu *menuPtr,		/* Information about whole menu. */
    int index,			/* Index of mePtr within menuPtr's entries. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    TkMenuEntry *mePtr;
    TkMenu *menuListPtr;
    int cascadeEntryChanged = 0;
    TkMenuReferences *oldCascadeMenuRefPtr, *cascadeMenuRefPtr = NULL;
    Tcl_Obj *oldCascadePtr = NULL;
    const char *newCascadeName;

    /*
     * Cascades are kind of tricky here. This is special case #3 in the
     * comment at the top of this file. Basically, if a menu is the main
     * comment at the top of this file. Basically, if a menu is the master
     * menu of a clone chain, and has an entry with a cascade menu, the clones
     * of the menu will point to clones of the cascade menu. We have to
     * destroy the clones of the cascades, clone the new cascade menu, and
     * configure the entry to point to the new clone.
     */

    mePtr = menuPtr->mainMenuPtr->entries[index];
    mePtr = menuPtr->masterMenuPtr->entries[index];
    if (mePtr->type == CASCADE_ENTRY) {
	oldCascadePtr = mePtr->namePtr;
	if (oldCascadePtr != NULL) {
	    Tcl_IncrRefCount(oldCascadePtr);
	}
    }

2066
2067
2068
2069
2070
2071
2072
2073

2074
2075
2076
2077
2078
2079
2080
2025
2026
2027
2028
2029
2030
2031

2032
2033
2034
2035
2036
2037
2038
2039







-
+







	if (mePtr->namePtr != NULL) {
	    newCascadeName = Tcl_GetString(mePtr->namePtr);
	    cascadeMenuRefPtr = TkFindMenuReferences(menuPtr->interp,
		    newCascadeName);
	}
    }

    for (menuListPtr = menuPtr->mainMenuPtr->nextInstancePtr;
    for (menuListPtr = menuPtr->masterMenuPtr->nextInstancePtr;
    	    menuListPtr != NULL;
	    menuListPtr = menuListPtr->nextInstancePtr) {

    	mePtr = menuListPtr->entries[index];

	if (cascadeEntryChanged && (mePtr->namePtr != NULL)) {
	    oldCascadeMenuRefPtr = TkFindMenuReferencesObj(menuPtr->interp,
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100



2101
2102
2103
2104
2105
2106
2107
2050
2051
2052
2053
2054
2055
2056



2057
2058
2059
2060
2061
2062
2063
2064
2065
2066







-
-
-
+
+
+







    	}

	if (cascadeEntryChanged && (mePtr->namePtr != NULL)) {
	    if (cascadeMenuRefPtr && cascadeMenuRefPtr->menuPtr != NULL) {
		Tcl_Obj *newObjv[2];
		Tcl_Obj *newCloneNamePtr;
		Tcl_Obj *pathNamePtr = Tcl_NewStringObj(
			Tk_PathName(menuListPtr->tkwin), TCL_INDEX_NONE);
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE);
		Tcl_Obj *menuObjPtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
			Tk_PathName(menuListPtr->tkwin), -1);
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1);
		Tcl_Obj *menuObjPtr = Tcl_NewStringObj("-menu", -1);

		Tcl_IncrRefCount(pathNamePtr);
		newCloneNamePtr = TkNewMenuName(menuPtr->interp,
			pathNamePtr,
			cascadeMenuRefPtr->menuPtr);
		Tcl_IncrRefCount(newCloneNamePtr);
		Tcl_IncrRefCount(normalPtr);
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
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







-
+

















-
+







-
+

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+


-
+
+

-
+


-
-
-
-
-

-
+
-
+

-




-
+



+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+






-
+

-
+







+
+
+







    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * GetMenuIndex --
 * TkGetMenuIndex --
 *
 *	Parse a textual index into a menu and return the numerical index of
 *	the indicated entry.
 *
 * Results:
 *	A standard Tcl result. If all went well, then *indexPtr is filled in
 *	with the entry index corresponding to string (ranges from -1 to the
 *	number of entries in the menu minus one). Otherwise an error message
 *	is left in the interp's result.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
GetMenuIndex(
TkGetMenuIndex(
    Tcl_Interp *interp,		/* For error messages. */
    TkMenu *menuPtr,		/* Menu for which the index is being
				 * specified. */
    Tcl_Obj *objPtr,		/* Specification of an entry in menu. See
				 * manual entry for valid .*/
    int lastOK,			/* Non-zero means its OK to return index just
				 * *after* last entry. */
    Tcl_Size *indexPtr)		/* Where to store converted index. */
    int *indexPtr)		/* Where to store converted index. */
{
    Tcl_Size i;
    const char *string;
    int i;
    const char *string = Tcl_GetString(objPtr);
    Tcl_HashEntry *entryPtr;

    if (TkGetIntForIndex(objPtr, menuPtr->numEntries - 1, lastOK, indexPtr) == TCL_OK) {
	/* TCL_INDEX_NONE is only accepted if it does not result from a negative number */
	if (*indexPtr >= 0 || Tcl_GetString(objPtr)[0] != '-') {
	    if (*indexPtr >= menuPtr->numEntries) {
		*indexPtr = menuPtr->numEntries - ((lastOK) ? 0 : 1);
	    }
	    return TCL_OK;
	}
    }

    string = Tcl_GetString(objPtr);

    if ((string[0] == 'a') && (strcmp(string, "active") == 0)) {
	*indexPtr = menuPtr->active;
	return TCL_OK;
	goto success;
    }

    if ((string[0] == 'l') && (strcmp(string, "last") == 0)) {
    if (((string[0] == 'l') && (strcmp(string, "last") == 0))
	    || ((string[0] == 'e') && (strcmp(string, "end") == 0))) {
	*indexPtr = menuPtr->numEntries - ((lastOK) ? 0 : 1);
	return TCL_OK;
	goto success;
    }

    if (string[0] == 0) {
	*indexPtr = TCL_INDEX_NONE;
	return TCL_OK;
    }
#if !defined(TK_NO_DEPRECATED)
    if ((string[0] == 'n') && (strcmp(string, "none") == 0)) {
	*indexPtr = TCL_INDEX_NONE;
	*indexPtr = -1;
	return TCL_OK;
	goto success;
    }
#endif

    if (string[0] == '@') {
	if (GetIndexFromCoords(interp, menuPtr, string, indexPtr)
		== TCL_OK) {
	    return TCL_OK;
	    goto success;
	}
    }

    if (isdigit(UCHAR(string[0]))) {
	if (Tcl_GetInt(interp, string, &i) == TCL_OK) {
    entryPtr = Tcl_FindHashEntry(&menuPtr->items, string);
    if (entryPtr) {
	    if (i >= menuPtr->numEntries) {
		if (lastOK) {
        TkMenuEntry *mePtr = (TkMenuEntry *)Tcl_GetHashValue(entryPtr);
        *indexPtr = mePtr->index;
        return TCL_OK;
		    i = menuPtr->numEntries;
		} else {
		    i = menuPtr->numEntries-1;
		}
	    } else if (i < 0) {
		i = -1;
	    }
	    *indexPtr = i;
	    goto success;
	}
	Tcl_ResetResult(interp);
    }

    for (i = 0; i < menuPtr->numEntries; i++) {
	Tcl_Obj *labelPtr = menuPtr->entries[i]->labelPtr;
	const char *label = (labelPtr == NULL) ? NULL : Tcl_GetString(labelPtr);

	if ((label != NULL) && (Tcl_StringCaseMatch(label, string, 0))) {
	if ((label != NULL) && (Tcl_StringMatch(label, string))) {
	    *indexPtr = i;
	    return TCL_OK;
	    goto success;
	}
    }

    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad menu entry index \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "MENU", "INDEX", NULL);
    return TCL_ERROR;

  success:
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * MenuCmdDeletedProc --
 *
2236
2237
2238
2239
2240
2241
2242
2243

2244
2245

2246
2247
2248
2249
2250
2251
2252
2190
2191
2192
2193
2194
2195
2196

2197
2198

2199
2200
2201
2202
2203
2204
2205
2206







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
MenuCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenu *menuPtr = clientData;
    Tk_Window tkwin = menuPtr->tkwin;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.
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
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







-
+





-
-
+
+






-
+












-
+






-
+







 *
 *----------------------------------------------------------------------
 */

static TkMenuEntry *
MenuNewEntry(
    TkMenu *menuPtr,		/* Menu that will hold the new entry. */
    Tcl_Size index,			/* Where in the menu the new entry is to
    int index,			/* Where in the menu the new entry is to
				 * go. */
    int type)			/* The type of the new entry. */
{
    TkMenuEntry *mePtr;
    TkMenuEntry **newEntries;
    Tcl_Size i;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    int i;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Create a new array of entries with an empty slot for the new entry.
     */

    newEntries = (TkMenuEntry **)ckalloc((menuPtr->numEntries+1) * sizeof(TkMenuEntry *));
    newEntries = ckalloc((menuPtr->numEntries+1) * sizeof(TkMenuEntry *));
    for (i = 0; i < index; i++) {
	newEntries[i] = menuPtr->entries[i];
    }
    for (; i < menuPtr->numEntries; i++) {
	newEntries[i+1] = menuPtr->entries[i];
	newEntries[i+1]->index = i + 1;
    }
    if (menuPtr->numEntries != 0) {
	ckfree(menuPtr->entries);
    }
    menuPtr->entries = newEntries;
    menuPtr->numEntries++;
    mePtr = (TkMenuEntry *)ckalloc(sizeof(TkMenuEntry));
    mePtr = ckalloc(sizeof(TkMenuEntry));
    menuPtr->entries[index] = mePtr;
    mePtr->type = type;
    mePtr->optionTable = tsdPtr->entryOptionTables[type];
    mePtr->menuPtr = menuPtr;
    mePtr->labelPtr = NULL;
    mePtr->labelLength = 0;
    mePtr->underline = INT_MIN;
    mePtr->underline = -1;
    mePtr->bitmapPtr = NULL;
    mePtr->imagePtr = NULL;
    mePtr->image = NULL;
    mePtr->selectImagePtr = NULL;
    mePtr->selectImage = NULL;
    mePtr->accelPtr = NULL;
    mePtr->accelLength = 0;
2340
2341
2342
2343
2344
2345
2346
2347

2348
2349
2350
2351
2352
2353
2354
2355

2356
2357
2358
2359
2360
2361
2362
2294
2295
2296
2297
2298
2299
2300

2301
2302
2303
2304
2305

2306
2307

2308
2309
2310
2311
2312
2313
2314
2315







-
+




-


-
+







    mePtr->namePtr = NULL;
    mePtr->childMenuRefPtr = NULL;
    mePtr->onValuePtr = NULL;
    mePtr->offValuePtr = NULL;
    mePtr->entryFlags = 0;
    mePtr->index = index;
    mePtr->nextCascadePtr = NULL;
    if (Tk_InitOptions(menuPtr->interp, mePtr,
    if (Tk_InitOptions(menuPtr->interp, (char *) mePtr,
	    mePtr->optionTable, menuPtr->tkwin) != TCL_OK) {
	ckfree(mePtr);
	return NULL;
    }
    mePtr->entryPtr = NULL;
    TkMenuInitializeEntryDrawingFields(mePtr);
    if (TkpMenuNewEntry(mePtr) != TCL_OK) {
	Tk_FreeConfigOptions(mePtr, mePtr->optionTable,
	Tk_FreeConfigOptions((char *) mePtr, mePtr->optionTable,
		menuPtr->tkwin);
    	ckfree(mePtr);
    	return NULL;
    }

    return mePtr;
}
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
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







-
+



-
+
-


-
-
-
-


-
+







-
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




+
-
+






-
+

-
+

-
+



-
+




+
-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+








-
+

-
+

-
-
+
+








static int
MenuAddOrInsert(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkMenu *menuPtr,		/* Widget in which to create new entry. */
    Tcl_Obj *indexPtr,		/* Object describing index at which to insert.
				 * NULL means insert at end. */
    Tcl_Size objc,			/* Number of elements in objv. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[])	/* Arguments to command: first arg is type of
				 * entry, others are config options. */
{
    int type;
    int type, index;
    Tcl_Size index;
    TkMenuEntry *mePtr;
    TkMenu *menuListPtr;
    Tcl_HashEntry *entryPtr;
    Tcl_Obj *idPtr = NULL;
    int isNew;
    int offs;

    if (indexPtr != NULL) {
	if (GetMenuIndex(interp, menuPtr, indexPtr, 1, &index) != TCL_OK) {
	if (TkGetMenuIndex(interp, menuPtr, indexPtr, 1, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	index = menuPtr->numEntries;
    }
    if (index < 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad menu entry index \"%s\"", Tcl_GetString(indexPtr)));
		"bad index \"%s\"", Tcl_GetString(indexPtr)));
	Tcl_SetErrorCode(interp, "TK", "MENU", "INDEX", NULL);
	return TCL_ERROR;
    }
    if (menuPtr->tearoff && (index == 0)) {
	index = 1;
    }

    /*
     * Figure out the type of the new entry.
     */

    if (Tcl_GetIndexFromObjStruct(interp, objv[0], menuEntryTypeStrings,
	    sizeof(char *), "menu entry type", 0, &type) != TCL_OK) {
	return TCL_ERROR;
    }
    offs = 1;

    /*
     * Check for a user supplied id
     */

    if (objc % 2 == 0) {
        idPtr = objv[offs];
        if (Tcl_FindHashEntry(&menuPtr->items, Tcl_GetString(idPtr))) {
            Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "entry \"%s\" already exists", Tcl_GetString(idPtr)));
            Tcl_SetErrorCode(interp, "TK", "MENU", "ENTRY_EXISTS", NULL);
            return TCL_ERROR;
        }
        offs++;
    }

    /*
     * Now we have to add an entry for every instance related to this menu.
     */

    for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL;
    for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL;
    	    menuListPtr = menuListPtr->nextInstancePtr) {

    	mePtr = MenuNewEntry(menuListPtr, index, type);
    	if (mePtr == NULL) {
    	    return TCL_ERROR;
    	}
    	if (ConfigureMenuEntry(mePtr, objc - offs, objv + offs) != TCL_OK) {
    	if (ConfigureMenuEntry(mePtr, objc - 1, objv + 1) != TCL_OK) {
	    TkMenu *errorMenuPtr;
	    Tcl_Size i;
	    int i;

	    for (errorMenuPtr = menuPtr->mainMenuPtr;
	    for (errorMenuPtr = menuPtr->masterMenuPtr;
		    errorMenuPtr != NULL;
		    errorMenuPtr = errorMenuPtr->nextInstancePtr) {
    		Tcl_EventuallyFree(errorMenuPtr->entries[index],
    	    		DestroyMenuEntry);
    	    		(Tcl_FreeProc *) DestroyMenuEntry);
		for (i = index; i < errorMenuPtr->numEntries - 1; i++) {
		    errorMenuPtr->entries[i] = errorMenuPtr->entries[i + 1];
		    errorMenuPtr->entries[i]->index = i;
		}
		errorMenuPtr->numEntries--;
		if (--errorMenuPtr->numEntries == 0) {
		if (errorMenuPtr->numEntries == 0) {
		    ckfree(errorMenuPtr->entries);
		    errorMenuPtr->entries = NULL;
		}
		if (errorMenuPtr == menuListPtr) {
		    break;
		}
	    }
    	    return TCL_ERROR;
    	}

        if (idPtr == NULL) {
            char idbuf[16];
            /* Generate an id for the new entry on the main menu */
            do {
                snprintf(idbuf, sizeof(idbuf), "e%03X", ++menuPtr->serial);
                entryPtr = Tcl_CreateHashEntry(
			&menuListPtr->items, idbuf, &isNew);
            } while (!isNew);
            idPtr = Tcl_NewStringObj(idbuf, TCL_INDEX_NONE);
        } else {
            /* Reuse the specified or previously generated id on all clones */
            entryPtr = Tcl_CreateHashEntry(
		    &menuListPtr->items, Tcl_GetString(idPtr), &isNew);
        }
        Tcl_SetHashValue(entryPtr, mePtr);
        mePtr->entryPtr = entryPtr;

    	/*
	 * If a menu has cascades, then every instance of the menu has to have
	 * its own parallel cascade structure. So adding an entry to a menu
	 * with clones means that the menu that the entry points to has to be
	 * cloned for every clone the main menu has. This is special case #2
	 * cloned for every clone the master menu has. This is special case #2
	 * in the comment at the top of this file.
    	 */

    	if ((menuPtr != menuListPtr) && (type == CASCADE_ENTRY)) {
    	    if ((mePtr->namePtr != NULL)
		    && (mePtr->childMenuRefPtr != NULL)
    	    	    && (mePtr->childMenuRefPtr->menuPtr != NULL)) {
		TkMenu *cascadeMenuPtr =
			mePtr->childMenuRefPtr->menuPtr->mainMenuPtr;
			mePtr->childMenuRefPtr->menuPtr->masterMenuPtr;
		Tcl_Obj *newCascadePtr, *newObjv[2];
		Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
		Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", -1);
		Tcl_Obj *windowNamePtr =
			Tcl_NewStringObj(Tk_PathName(menuListPtr->tkwin), TCL_INDEX_NONE);
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE);
			Tcl_NewStringObj(Tk_PathName(menuListPtr->tkwin), -1);
		Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1);
		TkMenuReferences *menuRefPtr;

		Tcl_IncrRefCount(windowNamePtr);
		newCascadePtr = TkNewMenuName(menuListPtr->interp,
			windowNamePtr, cascadeMenuPtr);
		Tcl_IncrRefCount(newCascadePtr);
		Tcl_IncrRefCount(normalPtr);
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2448
2449
2450
2451
2452
2453
2454


2455
2456
2457
2458
2459
2460
2461







-
-







		Tcl_DecrRefCount(newCascadePtr);
		Tcl_DecrRefCount(menuNamePtr);
		Tcl_DecrRefCount(windowNamePtr);
		Tcl_DecrRefCount(normalPtr);
    	    }
    	}
    }

    Tcl_SetObjResult(interp, idPtr);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * MenuVarProc --
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
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







-
+

-
-
+
+


-
+




-
+

-
+
-






-
-
-
-
-







-

-
+
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	The menu entry may become selected or deselected.
 *
 *--------------------------------------------------------------
 */

static char *
MenuVarProc(
    void *clientData,	/* Information about menu entry. */
    ClientData clientData,	/* Information about menu entry. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),	/* First part of variable's name. */
    TCL_UNUSED(const char *),	/* Second part of variable's name. */
    const char *name1,		/* First part of variable's name. */
    const char *name2,		/* Second part of variable's name. */
    int flags)			/* Describes what just happened. */
{
    TkMenuEntry *mePtr = (TkMenuEntry *)clientData;
    TkMenuEntry *mePtr = clientData;
    TkMenu *menuPtr;
    const char *value;
    const char *name, *onValue;

    if (Tcl_InterpDeleted(interp) || (mePtr->namePtr == NULL)) {
    if (flags & TCL_INTERP_DESTROYED) {
	/*
	 * Do nothing if the interpreter is going away or we have
	 * Do nothing if the interpreter is going away.
	 * no variable name.
	 */

    	return NULL;
    }

    menuPtr = mePtr->menuPtr;

    if (menuPtr->menuFlags & MENU_DELETION_PENDING) {
    	return NULL;
    }

    name = Tcl_GetString(mePtr->namePtr);

    /*
     * If the variable is being unset, then re-establish the trace.
     */

    if (flags & TCL_TRACE_UNSETS) {
        void *probe = NULL;
	mePtr->entryFlags &= ~ENTRY_SELECTED;

	if (flags & TCL_TRACE_DESTROYED) {
        do {
                probe = Tcl_VarTraceInfo(interp, name,
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        MenuVarProc, probe);
	    Tcl_TraceVar2(interp, name, NULL,
		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    MenuVarProc, clientData);
                if (probe == (void *)mePtr) {
                    break;
                }
	}
        } while (probe);
        if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * namePtr, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
		return NULL;
        }
	Tcl_TraceVar2(interp, name, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MenuVarProc, clientData);
	TkpConfigureMenuEntry(mePtr);
	TkEventuallyRedrawMenu(menuPtr, NULL);
	return NULL;
    }

    /*
     * Use the value of the variable to update the selected status of the menu
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676



2677
2678

2679
2680
2681
2682
2683
2684
2685
2559
2560
2561
2562
2563
2564
2565



2566
2567
2568
2569

2570
2571
2572
2573
2574
2575
2576
2577







-
-
-
+
+
+

-
+







 *	may get posted and unposted.
 *
 *----------------------------------------------------------------------
 */

int
TkActivateMenuEntry(
    TkMenu *menuPtr,	/* Menu in which to activate. */
    Tcl_Size index)			/* Index of entry to activate, or
				 * TCL_INDEX_NONE to deactivate all entries. */
    register TkMenu *menuPtr,	/* Menu in which to activate. */
    int index)			/* Index of entry to activate, or -1 to
				 * deactivate all entries. */
{
    TkMenuEntry *mePtr;
    register TkMenuEntry *mePtr;
    int result = TCL_OK;

    if (menuPtr->active >= 0) {
	mePtr = menuPtr->entries[menuPtr->active];

	/*
	 * Don't change the state unless it's currently active (state might
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
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







-
+
-




-
+







-
-
+
+


-
+







CloneMenu(
    TkMenu *menuPtr,		/* The menu we are going to clone. */
    Tcl_Obj *newMenuNamePtr,	/* The name to give the new menu. */
    Tcl_Obj *newMenuTypePtr)	/* What kind of menu is this, a normal menu a
    				 * menubar, or a tearoff? */
{
    int returnResult;
    int menuType;
    int menuType, i;
    Tcl_Size i;
    TkMenuReferences *menuRefPtr;
    Tcl_Obj *menuDupCommandArray[4];

    if (newMenuTypePtr == NULL) {
	menuType = MAIN_MENU;
	menuType = MASTER_MENU;
    } else {
	if (Tcl_GetIndexFromObjStruct(menuPtr->interp, newMenuTypePtr,
		menuTypeStrings, sizeof(char *), "menu type", 0, &menuType) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    menuDupCommandArray[0] = Tcl_NewStringObj("tk::MenuDup", TCL_INDEX_NONE);
    menuDupCommandArray[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE);
    menuDupCommandArray[0] = Tcl_NewStringObj("tk::MenuDup", -1);
    menuDupCommandArray[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), -1);
    menuDupCommandArray[2] = newMenuNamePtr;
    if (newMenuTypePtr == NULL) {
	menuDupCommandArray[3] = Tcl_NewStringObj("normal", TCL_INDEX_NONE);
	menuDupCommandArray[3] = Tcl_NewStringObj("normal", -1);
    } else {
	menuDupCommandArray[3] = newMenuTypePtr;
    }
    for (i = 0; i < 4; i++) {
	Tcl_IncrRefCount(menuDupCommandArray[i]);
    }
    Tcl_Preserve(menuPtr);
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
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







-
+








-
+

-
+

-
-
-
-
+
+
+
+



-
+





-
-
+
+


















-
+








    if ((returnResult == TCL_OK) &&
	    ((menuRefPtr = TkFindMenuReferencesObj(menuPtr->interp,
	    newMenuNamePtr)) != NULL)
	    && (menuPtr->numEntries == menuRefPtr->menuPtr->numEntries)) {
	TkMenu *newMenuPtr = menuRefPtr->menuPtr;
	Tcl_Obj *newObjv[3];
	Tcl_Size numElements;
	int i, numElements;

	/*
	 * Now put this newly created menu into the parent menu's instance
	 * chain.
	 */

	if (menuPtr->nextInstancePtr == NULL) {
	    menuPtr->nextInstancePtr = newMenuPtr;
	    newMenuPtr->mainMenuPtr = menuPtr->mainMenuPtr;
	    newMenuPtr->masterMenuPtr = menuPtr->masterMenuPtr;
	} else {
	    TkMenu *mainMenuPtr;
	    TkMenu *masterMenuPtr;

	    mainMenuPtr = menuPtr->mainMenuPtr;
	    newMenuPtr->nextInstancePtr = mainMenuPtr->nextInstancePtr;
	    mainMenuPtr->nextInstancePtr = newMenuPtr;
	    newMenuPtr->mainMenuPtr = mainMenuPtr;
	    masterMenuPtr = menuPtr->masterMenuPtr;
	    newMenuPtr->nextInstancePtr = masterMenuPtr->nextInstancePtr;
	    masterMenuPtr->nextInstancePtr = newMenuPtr;
	    newMenuPtr->masterMenuPtr = masterMenuPtr;
	}

	/*
	 * Add the main menu's window to the bind tags for this window after
	 * Add the master menu's window to the bind tags for this window after
	 * this window's tag. This is so the user can bind to either this
	 * clone (which may not be easy to do) or the entire menu clone
	 * structure.
	 */

	newObjv[0] = Tcl_NewStringObj("bindtags", TCL_INDEX_NONE);
	newObjv[1] = Tcl_NewStringObj(Tk_PathName(newMenuPtr->tkwin), TCL_INDEX_NONE);
	newObjv[0] = Tcl_NewStringObj("bindtags", -1);
	newObjv[1] = Tcl_NewStringObj(Tk_PathName(newMenuPtr->tkwin), -1);
	Tcl_IncrRefCount(newObjv[0]);
	Tcl_IncrRefCount(newObjv[1]);
	if (Tk_BindtagsObjCmd(newMenuPtr->tkwin, newMenuPtr->interp, 2,
		newObjv) == TCL_OK) {
	    const char *windowName;
	    Tcl_Obj *bindingsPtr =
		    Tcl_DuplicateObj(Tcl_GetObjResult(newMenuPtr->interp));
	    Tcl_Obj *elementPtr;

	    Tcl_IncrRefCount(bindingsPtr);
	    Tcl_ListObjLength(newMenuPtr->interp, bindingsPtr, &numElements);
	    for (i = 0; i < numElements; i++) {
		Tcl_ListObjIndex(newMenuPtr->interp, bindingsPtr, i,
			&elementPtr);
		windowName = Tcl_GetString(elementPtr);
		if (strcmp(windowName, Tk_PathName(newMenuPtr->tkwin))
			== 0) {
		    Tcl_Obj *newElementPtr = Tcl_NewStringObj(
			    Tk_PathName(newMenuPtr->mainMenuPtr->tkwin), TCL_INDEX_NONE);
			    Tk_PathName(newMenuPtr->masterMenuPtr->tkwin), -1);

		    /*
		     * The newElementPtr will have its refCount incremented
		     * here, so we don't need to worry about it any more.
		     */

		    Tcl_ListObjReplace(menuPtr->interp, bindingsPtr,
2903
2904
2905
2906
2907
2908
2909
2910

2911
2912
2913
2914
2915
2916
2917
2794
2795
2796
2797
2798
2799
2800

2801
2802
2803
2804
2805
2806
2807
2808







-
+








		    Tcl_IncrRefCount(windowNamePtr);
		    newCascadePtr = TkNewMenuName(menuPtr->interp,
			    windowNamePtr, oldCascadePtr);
		    Tcl_IncrRefCount(newCascadePtr);
		    CloneMenu(oldCascadePtr, newCascadePtr, NULL);

		    newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE);
		    newObjv[0] = Tcl_NewStringObj("-menu", -1);
		    newObjv[1] = newCascadePtr;
		    Tcl_IncrRefCount(newObjv[0]);
		    ConfigureMenuEntry(newMenuPtr->entries[i], 2, newObjv);
		    Tcl_DecrRefCount(newObjv[0]);
		    Tcl_DecrRefCount(newCascadePtr);
		    Tcl_DecrRefCount(windowNamePtr);
		}
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
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







-
+


-
+




-
+

-
+








static int
MenuDoXPosition(
    Tcl_Interp *interp,
    TkMenu *menuPtr,
    Tcl_Obj *objPtr)
{
    Tcl_Size index;
    int index;

    TkRecomputeMenu(menuPtr);
    if (GetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) {
    if (TkGetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_ResetResult(interp);
    if (index < 0) {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(0));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
    } else {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(menuPtr->entries[index]->x));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(menuPtr->entries[index]->x));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+


-
+




-
+

-
+








static int
MenuDoYPosition(
    Tcl_Interp *interp,
    TkMenu *menuPtr,
    Tcl_Obj *objPtr)
{
    Tcl_Size index;
    int index;

    TkRecomputeMenu(menuPtr);
    if (GetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) {
    if (TkGetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) {
	goto error;
    }
    Tcl_ResetResult(interp);
    if (index < 0) {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(0));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
    } else {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(menuPtr->entries[index]->y));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(menuPtr->entries[index]->y));
    }

    return TCL_OK;

  error:
    return TCL_ERROR;
}
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
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







-
+




-
+

-
+
-

-
+




+
+
+
+
-
-
+
+
-
-
-
+
+
-
-
-
-
+
+
+




-

-
-
-
-







 *
 * Side effects:
 *	If int is invalid, interp's result will be set to NULL.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
GetIndexFromCoords(
    Tcl_Interp *interp,		/* Interpreter of menu. */
    TkMenu *menuPtr,		/* The menu we are searching. */
    const char *string,		/* The @string we are parsing. */
    Tcl_Size *indexPtr)		/* The index of the item that matches. */
    int *indexPtr)		/* The index of the item that matches. */
{
    int x, y;
    int x, y, i;
    Tcl_Size i;
    const char *p;
    const char *rest;
    char *end;
    int x2, borderwidth, max;

    TkRecomputeMenu(menuPtr);
    p = string + 1;
    y = strtol(p, &end, 0);
    if (end == p) {
	goto error;
    }
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
	    menuPtr->borderWidthPtr, &borderwidth);
    Tk_GetPixelsFromObj(interp, menuPtr->tkwin,
	menuPtr->borderWidthPtr, &borderwidth);
    rest = strchr(p, ',');
    if (rest) {
	Tcl_DString ds;
    if (*end == ',') {
	x = y;
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, p, rest - p);

	if (Tcl_GetInt(NULL, Tcl_DStringValue(&ds), &x) != TCL_OK) {
	p = end + 1;
	y = strtol(p, &end, 0);
	if (end == p) {
	    goto error;
	}
    } else {
	x = borderwidth;
	rest = string;
    }
    p = rest + 1;
    if (Tcl_GetInt(NULL, p, &y) != TCL_OK) {
	    goto error;
	}

    *indexPtr = -1;

    /* set the width of the final column to the remainder of the window
     * being aware of windows that may not be mapped yet.
     */
    max = Tk_IsMapped(menuPtr->tkwin)
3106
3107
3108
3109
3110
3111
3112
3113

3114
3115
3116
3117
3118
3119
3120
2993
2994
2995
2996
2997
2998
2999

3000
3001
3002
3003
3004
3005
3006
3007







-
+







 *----------------------------------------------------------------------
 */

static void
RecursivelyDeleteMenu(
    TkMenu *menuPtr)		/* The menubar instance we are deleting. */
{
    Tcl_Size i;
    int i;
    TkMenuEntry *mePtr;

    /*
     * It is not 100% clear that this preserve/release pair is required, but
     * we have added them for safety in this very complex code.
     */

3169
3170
3171
3172
3173
3174
3175
3176

3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188

3189
3190
3191
3192
3193
3194
3195
3196
3197

3198
3199
3200

3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218

3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234

3235
3236
3237
3238
3239
3240
3241
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







-
+











-
+








-
+


-
+

















-
+















-
+








    if (winPtr->mainPtr != NULL) {
	nameTablePtr = &(winPtr->mainPtr->nameTable);
    }

    doDot = parentName[strlen(parentName) - 1] != '.';

    childPtr = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE);
    childPtr = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), -1);
    for (destString = Tcl_GetString(childPtr);
    	    *destString != '\0'; destString++) {
    	if (*destString == '.') {
    	    *destString = '#';
    	}
    }

    for (i = 0; ; i++) {
    	if (i == 0) {
	    resultPtr = Tcl_DuplicateObj(parentPtr);
    	    if (doDot) {
		Tcl_AppendToObj(resultPtr, ".", TCL_INDEX_NONE);
		Tcl_AppendToObj(resultPtr, ".", -1);
    	    }
	    Tcl_AppendObjToObj(resultPtr, childPtr);
    	} else {
	    Tcl_Obj *intPtr;

	    Tcl_DecrRefCount(resultPtr);
	    resultPtr = Tcl_DuplicateObj(parentPtr);
	    if (doDot) {
		Tcl_AppendToObj(resultPtr, ".", TCL_INDEX_NONE);
		Tcl_AppendToObj(resultPtr, ".", -1);
	    }
	    Tcl_AppendObjToObj(resultPtr, childPtr);
	    intPtr = Tcl_NewWideIntObj(i);
	    intPtr = Tcl_NewIntObj(i);
	    Tcl_AppendObjToObj(resultPtr, intPtr);
	    Tcl_DecrRefCount(intPtr);
    	}
	destString = Tcl_GetString(resultPtr);
    	if ((Tcl_FindCommand(interp, destString, NULL, 0) == NULL)
		&& ((nameTablePtr == NULL)
		|| (Tcl_FindHashEntry(nameTablePtr, destString) == NULL))) {
    	    break;
    	}
    }
    Tcl_DecrRefCount(childPtr);
    return resultPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetWindowMenubar --
 * TkSetWindowMenuBar --
 *
 *	Associates a menu with a window. Called by ConfigureFrame in in
 *	response to a "-menu .foo" configuration option for a top level.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The old menu clones for the menubar are thrown away, and a handler is
 *	set up to allocate the new ones.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetWindowMenubar(
TkSetWindowMenuBar(
    Tcl_Interp *interp,		/* The interpreter the toplevel lives in. */
    Tk_Window tkwin,		/* The toplevel window. */
    const char *oldMenuName, /* The name of the menubar previously set in
    				 * this toplevel. NULL means no menu was set
    				 * previously. */
    const char *menuName)	/* The name of the new menubar that the
				 * toplevel needs to be set to. NULL means
3259
3260
3261
3262
3263
3264
3265
3266

3267
3268
3269
3270
3271
3272
3273
3146
3147
3148
3149
3150
3151
3152

3153
3154
3155
3156
3157
3158
3159
3160







-
+







	     */

	    if (menuRefPtr->menuPtr != NULL) {
		TkMenu *instancePtr;

		menuPtr = menuRefPtr->menuPtr;

		for (instancePtr = menuPtr->mainMenuPtr;
		for (instancePtr = menuPtr->masterMenuPtr;
			instancePtr != NULL;
			instancePtr = instancePtr->nextInstancePtr) {
		    if (instancePtr->menuType == MENUBAR
			    && instancePtr->parentTopLevelPtr == tkwin) {
			RecursivelyDeleteMenu(instancePtr);
			break;
		    }
3318
3319
3320
3321
3322
3323
3324
3325

3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341

3342
3343
3344
3345
3346
3347
3348
3205
3206
3207
3208
3209
3210
3211

3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227

3228
3229
3230
3231
3232
3233
3234
3235







-
+















-
+







	menuPtr = menuRefPtr->menuPtr;
	if (menuPtr != NULL) {
	    Tcl_Obj *cloneMenuPtr;
	    TkMenuReferences *cloneMenuRefPtr;
	    Tcl_Obj *newObjv[4];
	    Tcl_Obj *windowNamePtr = Tcl_NewStringObj(Tk_PathName(tkwin),
		    -1);
	    Tcl_Obj *menubarPtr = Tcl_NewStringObj("menubar", TCL_INDEX_NONE);
	    Tcl_Obj *menubarPtr = Tcl_NewStringObj("menubar", -1);

	    /*
	     * Clone the menu and all of the cascades underneath it.
	     */

	    Tcl_IncrRefCount(windowNamePtr);
	    cloneMenuPtr = TkNewMenuName(interp, windowNamePtr,
		    menuPtr);
	    Tcl_IncrRefCount(cloneMenuPtr);
	    Tcl_IncrRefCount(menubarPtr);
	    CloneMenu(menuPtr, cloneMenuPtr, menubarPtr);

	    cloneMenuRefPtr = TkFindMenuReferencesObj(interp, cloneMenuPtr);
	    if ((cloneMenuRefPtr != NULL)
		    && (cloneMenuRefPtr->menuPtr != NULL)) {
		Tcl_Obj *cursorPtr = Tcl_NewStringObj("-cursor", TCL_INDEX_NONE);
		Tcl_Obj *cursorPtr = Tcl_NewStringObj("-cursor", -1);
		Tcl_Obj *nullPtr = Tcl_NewObj();

		cloneMenuRefPtr->menuPtr->parentTopLevelPtr = tkwin;
		menuBarPtr = cloneMenuRefPtr->menuPtr;
		newObjv[0] = cursorPtr;
		newObjv[1] = nullPtr;
		Tcl_IncrRefCount(cursorPtr);
3362
3363
3364
3365
3366
3367
3368
3369

3370
3371
3372
3373
3374
3375
3376

3377
3378
3379
3380
3381
3382
3383
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258
3259
3260
3261
3262

3263
3264
3265
3266
3267
3268
3269
3270







-
+






-
+







	}

	/*
	 * Add this window to the menu's list of windows that refer to this
	 * menu.
	 */

	topLevelListPtr = (TkMenuTopLevelList *)ckalloc(sizeof(TkMenuTopLevelList));
	topLevelListPtr = ckalloc(sizeof(TkMenuTopLevelList));
	topLevelListPtr->tkwin = tkwin;
	topLevelListPtr->nextPtr = menuRefPtr->topLevelListPtr;
	menuRefPtr->topLevelListPtr = topLevelListPtr;
    } else {
	TkpSetWindowMenuBar(tkwin, NULL);
    }
    Tk_SetMainMenubar(interp, tkwin, menuName);
    TkpSetMainMenubar(interp, tkwin, menuName);
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyMenuHashTable --
 *
3391
3392
3393
3394
3395
3396
3397
3398
3399


3400
3401

3402
3403
3404
3405
3406
3407
3408
3278
3279
3280
3281
3282
3283
3284


3285
3286
3287

3288
3289
3290
3291
3292
3293
3294
3295







-
-
+
+

-
+







 *	The hash table is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyMenuHashTable(
    void *clientData,	/* The menu hash table we are destroying. */
    TCL_UNUSED(Tcl_Interp *))		/* The interpreter we are destroying. */
    ClientData clientData,	/* The menu hash table we are destroying. */
    Tcl_Interp *interp)		/* The interpreter we are destroying. */
{
    Tcl_DeleteHashTable((Tcl_HashTable *)clientData);
    Tcl_DeleteHashTable(clientData);
    ckfree(clientData);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetMenuHashTable --
3420
3421
3422
3423
3424
3425
3426
3427

3428
3429
3430
3431

3432
3433
3434
3435
3436
3437
3438
3307
3308
3309
3310
3311
3312
3313

3314
3315
3316
3317

3318
3319
3320
3321
3322
3323
3324
3325







-
+



-
+







 *----------------------------------------------------------------------
 */

Tcl_HashTable *
TkGetMenuHashTable(
    Tcl_Interp *interp)		/* The interp we need the hash table in.*/
{
    Tcl_HashTable *menuTablePtr = (Tcl_HashTable *)
    Tcl_HashTable *menuTablePtr =
	    Tcl_GetAssocData(interp, MENU_HASH_KEY, NULL);

    if (menuTablePtr == NULL) {
	menuTablePtr = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
	menuTablePtr = ckalloc(sizeof(Tcl_HashTable));
	Tcl_InitHashTable(menuTablePtr, TCL_STRING_KEYS);
	Tcl_SetAssocData(interp, MENU_HASH_KEY, DestroyMenuHashTable,
		menuTablePtr);
    }
    return menuTablePtr;
}

3465
3466
3467
3468
3469
3470
3471
3472

3473
3474
3475
3476
3477
3478
3479

3480
3481
3482
3483
3484
3485
3486
3352
3353
3354
3355
3356
3357
3358

3359
3360
3361
3362
3363
3364
3365

3366
3367
3368
3369
3370
3371
3372
3373







-
+






-
+







    Tcl_HashEntry *hashEntryPtr;
    TkMenuReferences *menuRefPtr;
    int newEntry;
    Tcl_HashTable *menuTablePtr = TkGetMenuHashTable(interp);

    hashEntryPtr = Tcl_CreateHashEntry(menuTablePtr, pathName, &newEntry);
    if (newEntry) {
    	menuRefPtr = (TkMenuReferences *)ckalloc(sizeof(TkMenuReferences));
    	menuRefPtr = ckalloc(sizeof(TkMenuReferences));
    	menuRefPtr->menuPtr = NULL;
    	menuRefPtr->topLevelListPtr = NULL;
    	menuRefPtr->parentEntryPtr = NULL;
    	menuRefPtr->hashEntryPtr = hashEntryPtr;
    	Tcl_SetHashValue(hashEntryPtr, menuRefPtr);
    } else {
    	menuRefPtr = (TkMenuReferences *)Tcl_GetHashValue(hashEntryPtr);
    	menuRefPtr = Tcl_GetHashValue(hashEntryPtr);
    }
    return menuRefPtr;
}

/*
 *----------------------------------------------------------------------
 *
3509
3510
3511
3512
3513
3514
3515
3516

3517
3518
3519
3520
3521
3522
3523
3396
3397
3398
3399
3400
3401
3402

3403
3404
3405
3406
3407
3408
3409
3410







-
+







    Tcl_HashEntry *hashEntryPtr;
    TkMenuReferences *menuRefPtr = NULL;
    Tcl_HashTable *menuTablePtr;

    menuTablePtr = TkGetMenuHashTable(interp);
    hashEntryPtr = Tcl_FindHashEntry(menuTablePtr, pathName);
    if (hashEntryPtr != NULL) {
    	menuRefPtr = (TkMenuReferences *)Tcl_GetHashValue(hashEntryPtr);
    	menuRefPtr = Tcl_GetHashValue(hashEntryPtr);
    }
    return menuRefPtr;
}

/*
 *----------------------------------------------------------------------
 *
3602
3603
3604
3605
3606
3607
3608
3609

3610
3611
3612

3613
3614
3615

3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628


3629
3630

3631
3632
3633
3634
3635
3636
3637
3638
3639
3640

3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656


3657
3658
3659
3660
3661
3662
3663
3489
3490
3491
3492
3493
3494
3495

3496
3497
3498

3499
3500
3501

3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513


3514
3515
3516

3517
3518
3519
3520
3521
3522
3523
3524
3525
3526

3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541


3542
3543
3544
3545
3546
3547
3548
3549
3550







-
+


-
+


-
+











-
-
+
+

-
+









-
+














-
-
+
+







DeleteMenuCloneEntries(
    TkMenu *menuPtr,		/* The menu the command was issued with. */
    int	first,			/* The zero-based first entry in the set of
				 * entries to delete. */
    int last)			/* The zero-based last entry. */
{
    TkMenu *menuListPtr;
    Tcl_Size numDeleted, i, j;
    int numDeleted, i, j;

    numDeleted = last + 1 - first;
    for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL;
    for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL;
	    menuListPtr = menuListPtr->nextInstancePtr) {
	for (i = last; i >= first; i--) {
	    Tcl_EventuallyFree(menuListPtr->entries[i], DestroyMenuEntry);
	    Tcl_EventuallyFree(menuListPtr->entries[i], (Tcl_FreeProc *) DestroyMenuEntry);
	}
	for (i = last + 1; i < menuListPtr->numEntries; i++) {
	    j = i - numDeleted;
	    menuListPtr->entries[j] = menuListPtr->entries[i];
	    menuListPtr->entries[j]->index = j;
	}
	menuListPtr->numEntries -= numDeleted;
	if (menuListPtr->numEntries == 0) {
	    ckfree(menuListPtr->entries);
	    menuListPtr->entries = NULL;
	}
	if (((int)menuListPtr->active >= first)
		&& ((int)menuListPtr->active <= last)) {
	if ((menuListPtr->active >= first)
		&& (menuListPtr->active <= last)) {
	    menuListPtr->active = -1;
	} else if ((int)menuListPtr->active > last) {
	} else if (menuListPtr->active > last) {
	    menuListPtr->active -= numDeleted;
	}
	TkEventuallyRecomputeMenu(menuListPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MenuCleanup --
 * TkMenuCleanup --
 *
 *	Resets menusInitialized to allow Tk to be finalized and reused without
 *	the DLL being unloaded.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
MenuCleanup(
    TCL_UNUSED(void *))
TkMenuCleanup(
    ClientData unused)
{
    menusInitialized = 0;
}

/*
 *----------------------------------------------------------------------
 *
3674
3675
3676
3677
3678
3679
3680
3681

3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695

3696
3697
3698
3699
3700
3701
3702
3561
3562
3563
3564
3565
3566
3567

3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581

3582
3583
3584
3585
3586
3587
3588
3589







-
+













-
+







 *
 *----------------------------------------------------------------------
 */

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

    if (!menusInitialized) {
	Tcl_MutexLock(&menuMutex);
	if (!menusInitialized) {
	    TkpMenuInit();
	    menusInitialized = 1;
	}

	/*
	 * Make sure we cleanup on finalize.
	 */

	TkCreateExitHandler((Tcl_ExitProc *) MenuCleanup, NULL);
	TkCreateExitHandler((Tcl_ExitProc *) TkMenuCleanup, NULL);
	Tcl_MutexUnlock(&menuMutex);
    }
    if (!tsdPtr->menusInitialized) {
	TkpMenuThreadInit();
	tsdPtr->menuOptionTable =
		Tk_CreateOptionTable(NULL, tkMenuConfigSpecs);
	tsdPtr->entryOptionTables[TEAROFF_ENTRY] =

Changes to generic/tkMenu.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14




15
16
17
18
19
20
21
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25






-
+







+
+
+
+







/*
 * tkMenu.h --
 *
 *	Declarations shared among all of the files that implement menu
 *	widgets.
 *
 * Copyright © 1996-1998 Sun Microsystems, Inc.
 * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMENU
#define _TKMENU

#ifndef _TK
#include "tk.h"
#endif

#ifndef _TKINT
#include "tkInt.h"
#endif

#ifndef _DEFAULT
#include "default.h"
60
61
62
63
64
65
66
67

68
69
70
71

72
73
74
75


76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
64
65
66
67
68
69
70

71
72
73
74

75
76
77


78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99







-
+



-
+


-
-
+
+












-
+







    int type;			/* Type of menu entry; see below for valid
				 * types. */
    struct TkMenu *menuPtr;	/* Menu with which this entry is
				 * associated. */
    Tk_OptionTable optionTable;	/* Option table for this menu entry. */
    Tcl_Obj *labelPtr;		/* Main text label displayed in entry (NULL if
				 * no label). */
    Tcl_Size labelLength;	/* Number of non-NULL characters in label. */
    int labelLength;		/* Number of non-NULL characters in label. */
    int state;			/* State of button for display purposes:
				 * normal, active, or disabled. */
    int underline;		/* Value of -underline option: specifies index
				 * of character to underline (-1 means don't
				 * of character to underline (<0 means don't
				 * underline anything). */
    Tcl_Obj *underlinePtr;	/* Index of character to underline. */
    Tcl_Obj *bitmapPtr;		/* Bitmap to display in menu entry, or NULL.
				 * If not NULL then label is ignored. */
    Tcl_Obj *bitmapPtr;		/* Bitmap to display in menu entry, or None.
				 * If not None then label is ignored. */
    Tcl_Obj *imagePtr;		/* Name of image to display, or NULL. If not
				 * NULL, bitmap, text, and textVarName are
				 * ignored. */
    Tk_Image image;		/* Image to display in menu entry, or NULL if
				 * none. */
    Tcl_Obj *selectImagePtr;	/* Name of image to display when selected, or
				 * NULL. */
    Tk_Image selectImage;	/* Image to display in entry when selected, or
				 * NULL if none. Ignored if image is NULL. */
    Tcl_Obj *accelPtr;		/* Accelerator string displayed at right of
				 * menu entry. NULL means no such accelerator.
				 * Malloc'ed. */
    Tcl_Size accelLength;	/* Number of non-NULL characters in
    int accelLength;		/* Number of non-NULL characters in
				 * accelerator. */
    int indicatorOn;		/* True means draw indicator, false means
				 * don't draw it. This field is ignored unless
				 * the entry is a radio or check button. */
    /*
     * Display attributes
     */
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130







-
+







				 * overall font for menu. */
    int columnBreak;		/* If this is 0, this item appears below the
				 * item in front of it. If this is 1, this
				 * item starts a new column. This field is
				 * always 0 for tearoff and separator
				 * entries. */
    int hideMargin;		/* If this is 0, then the item has enough
    				 * margin to accommodate a standard check mark
    				 * margin to accomodate a standard check mark
    				 * and a default right margin. If this is 1,
    				 * then the item has no such margins, and
    				 * checkbuttons and radiobuttons with this set
    				 * will have a rectangle drawn in the
    				 * indicator around the item if the item is
    				 * checked. This is useful for palette menus.
    				 * This field is ignored for separators and
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189

190
191

192
193
194
195
196
197
198
199







-
+











-


-
+







    GC activeGC;		/* GC for drawing text in entry when active.
				 * NULL means use overall activeGC for
				 * menu. */
    GC disabledGC;		/* Used to produce disabled effect for entry.
				 * NULL means use overall disabledGC from menu
				 * structure. See comments for disabledFg in
				 * menu structure for more information. */
    GC indicatorGC;		/* For drawing indicators. NULL means use GC
    GC indicatorGC;		/* For drawing indicators. None means use GC
				 * from menu. */

    /*
     * Miscellaneous fields.
     */

    int entryFlags;		/* Various flags. See below for
				 * definitions. */
    int index;			/* Need to know which index we are. This is
    				 * zero-based. This is the top-left entry of
    				 * the menu. */
    Tcl_HashEntry *entryPtr;	/* Back-pointer to hash table entry */

    /*
     * Bookeeping for main menus and cascade menus.
     * Bookeeping for master menus and cascade menus.
     */

    struct TkMenuReferences *childMenuRefPtr;
    				/* A pointer to the hash table entry for the
    				 * child menu. Stored here when the menu entry
    				 * is configured so that a hash lookup is not
    				 * necessary later.*/
241
242
243
244
245
246
247
248
249


250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270




271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
244
245
246
247
248
249
250


251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269




270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297







-
-
+
+

















-
-
-
-
+
+
+
+
















-
+







#define TEAROFF_ENTRY 5

/*
 * Menu states
 */

#define ENTRY_ACTIVE 0
#define ENTRY_DISABLED 1
#define ENTRY_NORMAL 2
#define ENTRY_NORMAL 1
#define ENTRY_DISABLED 2

/*
 * A data structure of the following type is kept for each menu widget:
 */

typedef struct TkMenu {
    Tk_Window tkwin;		/* Window that embodies the pane. NULL means
				 * that the window has been destroyed but the
				 * data structures haven't yet been cleaned
				 * up. */
    Display *display;		/* Display containing widget. Needed, among
				 * other things, so that resources can be
				 * freed up even after tkwin has gone away. */
    Tcl_Interp *interp;		/* Interpreter associated with menu. */
    Tcl_Command widgetCmd;	/* Token for menu's widget command. */
    TkMenuEntry **entries;	/* Array of pointers to all the entries in the
				 * menu. NULL means no entries. */
    Tcl_Size numEntries;		/* Number of elements in entries. */
    Tcl_Size active;			/* Index of active entry. TCL_INDEX_NONE means
				 * nothing active. */
    int menuType;		/* MAIN_MENU, TEAROFF_MENU, or MENUBAR. See
    int numEntries;		/* Number of elements in entries. */
    int active;			/* Index of active entry. -1 means nothing
				 * active. */
    int menuType;		/* MASTER_MENU, TEAROFF_MENU, or MENUBAR. See
    				 * below for definitions. */
    Tcl_Obj *menuTypePtr;	/* Used to control whether created tkwin is a
				 * toplevel or not. "normal", "menubar", or
				 * "toplevel" */

    /*
     * Information used when displaying widget:
     */

    Tcl_Obj *borderPtr;		/* Structure used to draw 3-D border and
				 * background for menu. */
    Tcl_Obj *borderWidthPtr;	/* Width of border around whole menu. */
    Tcl_Obj *activeBorderPtr;	/* Used to draw background and border for
				 * active element (if any). */
    Tcl_Obj *activeBorderWidthPtr;
				/* Width of border around active element. */
    int relief;		/* 3-d effect: TK_RELIEF_RAISED, etc. */
    Tcl_Obj *reliefPtr;		/* 3-d effect: TK_RELIEF_RAISED, etc. */
    Tcl_Obj *fontPtr;		/* Text font for menu entries. */
    Tcl_Obj *fgPtr;		/* Foreground color for entries. */
    Tcl_Obj *disabledFgPtr;	/* Foreground color when disabled. NULL means
				 * use normalFg with a 50% stipple instead. */
    Tcl_Obj *activeFgPtr;	/* Foreground color for active entry. */
    Tcl_Obj *indicatorFgPtr;	/* Color for indicators in radio and check
				 * button entries. */
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

356
357
358

359
360
361
362
363
364
365
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359
360

361
362
363
364
365
366
367
368







-
+














-
+


-
+







    				 * off. If this is NULL, a default scheme will
    				 * be used to generate a title for tearoff. */
    Tcl_Obj *tearoffCommandPtr;	/* If non-NULL, points to a command to run
				 * whenever the menu is torn-off. */
    Tcl_Obj *takeFocusPtr;	/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    Tcl_Obj *cursorPtr;		/* Current cursor for window, or NULL. */
    Tcl_Obj *cursorPtr;		/* Current cursor for window, or None. */
    Tcl_Obj *postCommandPtr;	/* Used to detect cycles in cascade hierarchy
    				 * trees when preprocessing postcommands on
    				 * some platforms. See PostMenu for more
    				 * details. */
    int postCommandGeneration;	/* Need to do pre-invocation post command
				 * traversal. */
    int menuFlags;		/* Flags for use by X; see below for
				 * definition. */
    TkMenuEntry *postedCascade;	/* Points to menu entry for cascaded submenu
				 * that is currently posted or NULL if no
				 * submenu posted. */
    struct TkMenu *nextInstancePtr;
    				/* The next instance of this menu in the
    				 * chain. */
    struct TkMenu *mainMenuPtr;
    struct TkMenu *masterMenuPtr;
    				/* A pointer to the original menu for this
    				 * clone chain. Points back to this structure
    				 * if this menu is a main menu. */
    				 * if this menu is a master menu. */
    void *reserved1; /* not used any more. */
    Tk_Window parentTopLevelPtr;/* If this menu is a menubar, this is the
    				 * toplevel that owns the menu. Only
    				 * applicable for menubar clones. */
    struct TkMenuReferences *menuRefPtr;
    				/* Each menu is hashed into a table with the
    				 * name of the menu's window as the key. The
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
378
379
380
381
382
383
384



385
386
387
388
389
390
391







-
-
-







				 * of options are in this structure. */
    Tk_OptionSpec *extensionPtr;/* Needed by the configuration package for
				 * this widget to be extended. */
    Tk_SavedOptions *errorStructPtr;
				/* We actually have to allocate these because
				 * multiple menus get changed during one
				 * ConfigureMenu call. */
    Tcl_Obj *activeReliefPtr;	/* 3-d effect for active element. */
    Tcl_HashTable items;	/* Map: id -> entry */
    int serial;			/* Next item # for autogenerated ids */
} TkMenu;

/*
 * When the toplevel configure -menu command is executed, the menu may not
 * exist yet. We need to keep a linked list of windows that reference a
 * particular menu.
 */
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461

462
463
464
465
466
467
468
469



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496


497
498
499
500

501
502
503

504
505
506

507
508

509
510
511
512

513
514
515
516
517
518
519
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

458
459
460

461
462
463
464
465
466



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504

505
506
507

508
509

510
511
512
513

514
515
516
517
518
519
520
521







-
+

















-
+


-
+





-
-
-
+
+
+














-
+












+
+



-
+


-
+


-
+

-
+



-
+







 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler has
 *				already been queued to redraw this window.
 * RESIZE_PENDING:		Non-zero means a call to ComputeMenuGeometry
 *				has already been scheduled.
 * MENU_DELETION_PENDING	Non-zero means that we are currently
 *				destroying this menu's internal structures.
 *				This is useful when we are in the middle of
 *				cleaning this main menu's chain of menus up
 *				cleaning this master menu's chain of menus up
 *				when TkDestroyMenu was called again on this
 *				menu (via a destroy binding or somesuch).
 * MENU_WIN_DESTRUCTION_PENDING Non-zero means we are in the middle of
 *				destroying this menu's Tk_Window.
 * MENU_PLATFORM_FLAG1...	Reserved for use by the platform-specific menu
 *				code.
 */

#define REDRAW_PENDING			1
#define RESIZE_PENDING			2
#define MENU_DELETION_PENDING		4
#define MENU_WIN_DESTRUCTION_PENDING	8
#define MENU_PLATFORM_FLAG1	(1 << 30)
#define MENU_PLATFORM_FLAG2	(1 << 29)
#define MENU_PLATFORM_FLAG3	(1 << 28)

/*
 * Each menu created by the user is a MAIN_MENU. When a menu is torn off, a
 * Each menu created by the user is a MASTER_MENU. When a menu is torn off, a
 * TEAROFF_MENU instance is created. When a menu is assigned to a toplevel as
 * a menu bar, a MENUBAR instance is created. All instances have the same
 * configuration information. If the main instance is deleted, all instances
 * configuration information. If the master instance is deleted, all instances
 * are deleted. If one of the other instances is deleted, only that instance
 * is deleted.
 */

#define UNKNOWN_TYPE		-1
#define MENUBAR 		0
#define MAIN_MENU 		1
#define TEAROFF_MENU 		2
#define MASTER_MENU 		0
#define TEAROFF_MENU 		1
#define MENUBAR 		2

/*
 * Various geometry definitions:
 */

#define CASCADE_ARROW_HEIGHT	10
#define CASCADE_ARROW_WIDTH	8
#define DECORATION_BORDER_WIDTH	2

/*
 * Menu-related functions that are shared among Tk modules but not exported to
 * the outside world:
 */

MODULE_SCOPE int	TkActivateMenuEntry(TkMenu *menuPtr, Tcl_Size index);
MODULE_SCOPE int	TkActivateMenuEntry(TkMenu *menuPtr, int index);
MODULE_SCOPE void	TkBindMenu(Tk_Window tkwin, TkMenu *menuPtr);
MODULE_SCOPE TkMenuReferences*TkCreateMenuReferences(Tcl_Interp *interp,
			    const char *name);
MODULE_SCOPE void	TkDestroyMenu(TkMenu *menuPtr);
MODULE_SCOPE void	TkEventuallyRecomputeMenu(TkMenu *menuPtr);
MODULE_SCOPE void	TkEventuallyRedrawMenu(TkMenu *menuPtr,
			    TkMenuEntry *mePtr);
MODULE_SCOPE TkMenuReferences*TkFindMenuReferences(Tcl_Interp *interp, const char *name);
MODULE_SCOPE TkMenuReferences*TkFindMenuReferencesObj(Tcl_Interp *interp,
			    Tcl_Obj *namePtr);
MODULE_SCOPE int	TkFreeMenuReferences(TkMenuReferences *menuRefPtr);
MODULE_SCOPE Tcl_HashTable *TkGetMenuHashTable(Tcl_Interp *interp);
MODULE_SCOPE int	TkGetMenuIndex(Tcl_Interp *interp, TkMenu *menuPtr,
			    Tcl_Obj *objPtr, int lastOK, int *indexPtr);
MODULE_SCOPE void	TkMenuInitializeDrawingFields(TkMenu *menuPtr);
MODULE_SCOPE void	TkMenuInitializeEntryDrawingFields(TkMenuEntry *mePtr);
MODULE_SCOPE int	TkInvokeMenu(Tcl_Interp *interp, TkMenu *menuPtr,
			    Tcl_Size index);
			    int index);
MODULE_SCOPE void	TkMenuConfigureDrawOptions(TkMenu *menuPtr);
MODULE_SCOPE int	TkMenuConfigureEntryDrawOptions(
			    TkMenuEntry *mePtr, Tcl_Size index);
			    TkMenuEntry *mePtr, int index);
MODULE_SCOPE void	TkMenuFreeDrawOptions(TkMenu *menuPtr);
MODULE_SCOPE void	TkMenuEntryFreeDrawOptions(TkMenuEntry *mePtr);
MODULE_SCOPE void	TkMenuEventProc(void *clientData,
MODULE_SCOPE void	TkMenuEventProc(ClientData clientData,
    			    XEvent *eventPtr);
MODULE_SCOPE void	TkMenuImageProc(void *clientData, int x, int y,
MODULE_SCOPE void	TkMenuImageProc(ClientData clientData, int x, int y,
			    int width, int height, int imgWidth,
			    int imgHeight);
MODULE_SCOPE void	TkMenuInit(void);
MODULE_SCOPE void	TkMenuSelectImageProc(void *clientData, int x,
MODULE_SCOPE void	TkMenuSelectImageProc(ClientData clientData, int x,
			    int y, int width, int height, int imgWidth,
			    int imgHeight);
MODULE_SCOPE Tcl_Obj *	TkNewMenuName(Tcl_Interp *interp,
			    Tcl_Obj *parentNamePtr, TkMenu *menuPtr);
MODULE_SCOPE int	TkPostCommand(TkMenu *menuPtr);
MODULE_SCOPE int	TkPostSubmenu(Tcl_Interp *interp, TkMenu *menuPtr,
			    TkMenuEntry *mePtr);
537
538
539
540
541
542
543
544

545
546
547
548
549
539
540
541
542
543
544
545

546


547
548
549







-
+
-
-



			    const Tk_FontMetrics *menuMetricsPtr, int x,
			    int y, int width, int height, int strictMotif,
			    int drawingParameters);
MODULE_SCOPE void	TkpMenuInit(void);
MODULE_SCOPE int	TkpMenuNewEntry(TkMenuEntry *mePtr);
MODULE_SCOPE int	TkpNewMenu(TkMenu *menuPtr);
MODULE_SCOPE int	TkpPostMenu(Tcl_Interp *interp, TkMenu *menuPtr,
			    int x, int y, Tcl_Size index);
			    int x, int y);
MODULE_SCOPE int	TkpPostTearoffMenu(Tcl_Interp *interp, TkMenu *menuPtr,
			    int x, int y, Tcl_Size index);
MODULE_SCOPE void	TkpSetWindowMenuBar(Tk_Window tkwin, TkMenu *menuPtr);

#endif /* _TKMENU */

Changes to generic/tkMenuDraw.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30






-
+














-
-
+
+







/*
 * tkMenuDraw.c --
 *
 *	This module implements the platform-independent drawing and geometry
 *	calculations of menu widgets.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkMenu.h"

/*
 * Forward declarations for functions defined later in this file:
 */

static void		AdjustMenuCoords(TkMenu *menuPtr, TkMenuEntry *mePtr,
			    int *xPtr, int *yPtr);
static void		ComputeMenuGeometry(void *clientData);
static void		DisplayMenu(void *clientData);
static void		ComputeMenuGeometry(ClientData clientData);
static void		DisplayMenu(ClientData clientData);

/*
 *----------------------------------------------------------------------
 *
 * TkMenuInitializeDrawingFields --
 *
 *	Fills in drawing fields of a new menu. Called when new menu is created
39
40
41
42
43
44
45
46

47
48
49
50
51




52
53
54
55
56
57
58
39
40
41
42
43
44
45

46
47




48
49
50
51
52
53
54
55
56
57
58







-
+

-
-
-
-
+
+
+
+







 *----------------------------------------------------------------------
 */

void
TkMenuInitializeDrawingFields(
    TkMenu *menuPtr)		/* The menu we are initializing. */
{
    menuPtr->textGC = NULL;
    menuPtr->textGC = None;
    menuPtr->gray = None;
    menuPtr->disabledGC = NULL;
    menuPtr->activeGC = NULL;
    menuPtr->indicatorGC = NULL;
    menuPtr->disabledImageGC = NULL;
    menuPtr->disabledGC = None;
    menuPtr->activeGC = None;
    menuPtr->indicatorGC = None;
    menuPtr->disabledImageGC = None;
    menuPtr->totalWidth = menuPtr->totalHeight = 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMenuInitializeEntryDrawingFields --
75
76
77
78
79
80
81
82
83
84
85




86
87
88
89
90
91
92
75
76
77
78
79
80
81




82
83
84
85
86
87
88
89
90
91
92







-
-
-
-
+
+
+
+







{
    mePtr->width = 0;
    mePtr->height = 0;
    mePtr->x = 0;
    mePtr->y = 0;
    mePtr->indicatorSpace = 0;
    mePtr->labelWidth = 0;
    mePtr->textGC = NULL;
    mePtr->activeGC = NULL;
    mePtr->disabledGC = NULL;
    mePtr->indicatorGC = NULL;
    mePtr->textGC = None;
    mePtr->activeGC = None;
    mePtr->disabledGC = None;
    mePtr->indicatorGC = None;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMenuFreeDrawOptions --
 *
102
103
104
105
106
107
108
109

110
111
112

113
114
115
116
117
118

119
120
121

122
123
124

125
126
127
128
129
130
131
102
103
104
105
106
107
108

109
110
111

112
113
114
115
116
117

118
119
120

121
122
123

124
125
126
127
128
129
130
131







-
+


-
+





-
+


-
+


-
+







 *----------------------------------------------------------------------
 */

void
TkMenuFreeDrawOptions(
    TkMenu *menuPtr)
{
    if (menuPtr->textGC != NULL) {
    if (menuPtr->textGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->textGC);
    }
    if (menuPtr->disabledImageGC != NULL) {
    if (menuPtr->disabledImageGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->disabledImageGC);
    }
    if (menuPtr->gray != None) {
	Tk_FreeBitmap(menuPtr->display, menuPtr->gray);
    }
    if (menuPtr->disabledGC != NULL) {
    if (menuPtr->disabledGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->disabledGC);
    }
    if (menuPtr->activeGC != NULL) {
    if (menuPtr->activeGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->activeGC);
    }
    if (menuPtr->indicatorGC != NULL) {
    if (menuPtr->indicatorGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->indicatorGC);
    }
}

/*
 *----------------------------------------------------------------------
 *
143
144
145
146
147
148
149
150

151
152
153

154
155
156

157
158
159

160
161
162
163
164
165
166
143
144
145
146
147
148
149

150
151
152

153
154
155

156
157
158

159
160
161
162
163
164
165
166







-
+


-
+


-
+


-
+







 *----------------------------------------------------------------------
 */

void
TkMenuEntryFreeDrawOptions(
    TkMenuEntry *mePtr)
{
    if (mePtr->textGC != NULL) {
    if (mePtr->textGC != None) {
	Tk_FreeGC(mePtr->menuPtr->display, mePtr->textGC);
    }
    if (mePtr->disabledGC != NULL) {
    if (mePtr->disabledGC != None) {
	Tk_FreeGC(mePtr->menuPtr->display, mePtr->disabledGC);
    }
    if (mePtr->activeGC != NULL) {
    if (mePtr->activeGC != None) {
	Tk_FreeGC(mePtr->menuPtr->display, mePtr->activeGC);
    }
    if (mePtr->indicatorGC != NULL) {
    if (mePtr->indicatorGC != None) {
	Tk_FreeGC(mePtr->menuPtr->display, mePtr->indicatorGC);
    }
}

/*
 *----------------------------------------------------------------------
 *
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215







-
+







    tkfont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
    gcValues.font = Tk_FontId(tkfont);
    fg = Tk_GetColorFromObj(menuPtr->tkwin, menuPtr->fgPtr);
    gcValues.foreground = fg->pixel;
    gcValues.background = Tk_3DBorderColor(border)->pixel;
    newGC = Tk_GetGC(menuPtr->tkwin, GCForeground|GCBackground|GCFont,
	    &gcValues);
    if (menuPtr->textGC != NULL) {
    if (menuPtr->textGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->textGC);
    }
    menuPtr->textGC = newGC;

    gcValues.font = Tk_FontId(tkfont);
    gcValues.background = Tk_3DBorderColor(border)->pixel;
    if (menuPtr->disabledFgPtr != NULL) {
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283







-
+















-
+












-
+










-
+







	if (menuPtr->gray != None) {
	    gcValues.fill_style = FillStippled;
	    gcValues.stipple = menuPtr->gray;
	    mask = GCForeground|GCFillStyle|GCStipple;
	}
    }
    newGC = Tk_GetGC(menuPtr->tkwin, mask, &gcValues);
    if (menuPtr->disabledGC != NULL) {
    if (menuPtr->disabledGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->disabledGC);
    }
    menuPtr->disabledGC = newGC;

    gcValues.foreground = Tk_3DBorderColor(border)->pixel;
    if (menuPtr->gray == None) {
	menuPtr->gray = Tk_GetBitmap(menuPtr->interp, menuPtr->tkwin,
		"gray50");
    }
    if (menuPtr->gray != None) {
	gcValues.fill_style = FillStippled;
	gcValues.stipple = menuPtr->gray;
	newGC = Tk_GetGC(menuPtr->tkwin,
	    GCForeground|GCFillStyle|GCStipple, &gcValues);
    }
    if (menuPtr->disabledImageGC != NULL) {
    if (menuPtr->disabledImageGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->disabledImageGC);
    }
    menuPtr->disabledImageGC = newGC;

    gcValues.font = Tk_FontId(tkfont);
    activeFg = Tk_GetColorFromObj(menuPtr->tkwin, menuPtr->activeFgPtr);
    gcValues.foreground = activeFg->pixel;
    activeBorder = Tk_Get3DBorderFromObj(menuPtr->tkwin,
	    menuPtr->activeBorderPtr);
    gcValues.background = Tk_3DBorderColor(activeBorder)->pixel;
    newGC = Tk_GetGC(menuPtr->tkwin, GCForeground|GCBackground|GCFont,
	    &gcValues);
    if (menuPtr->activeGC != NULL) {
    if (menuPtr->activeGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->activeGC);
    }
    menuPtr->activeGC = newGC;

    indicatorFg = Tk_GetColorFromObj(menuPtr->tkwin,
	    menuPtr->indicatorFgPtr);
    gcValues.foreground = indicatorFg->pixel;
    gcValues.background = Tk_3DBorderColor(border)->pixel;
    newGC = Tk_GetGC(menuPtr->tkwin, GCForeground|GCBackground|GCFont,
	    &gcValues);
    if (menuPtr->indicatorGC != NULL) {
    if (menuPtr->indicatorGC != None) {
	Tk_FreeGC(menuPtr->display, menuPtr->indicatorGC);
    }
    menuPtr->indicatorGC = newGC;
}

/*
 *----------------------------------------------------------------------
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325







-
+
















-
+







 *
 *----------------------------------------------------------------------
 */

int
TkMenuConfigureEntryDrawOptions(
    TkMenuEntry *mePtr,
    Tcl_Size index)
    int index)
{
    XGCValues gcValues;
    GC newGC, newActiveGC, newDisabledGC, newIndicatorGC;
    unsigned long mask;
    Tk_Font tkfont;
    TkMenu *menuPtr = mePtr->menuPtr;

    tkfont = Tk_GetFontFromObj(menuPtr->tkwin,
	    (mePtr->fontPtr != NULL) ? mePtr->fontPtr : menuPtr->fontPtr);

    if (mePtr->state == ENTRY_ACTIVE) {
	if (index != menuPtr->active) {
	    TkActivateMenuEntry(menuPtr, index);
	}
    } else {
	if (index == menuPtr->active) {
	    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
	    TkActivateMenuEntry(menuPtr, -1);
	}
    }

    if ((mePtr->fontPtr != NULL)
	    || (mePtr->borderPtr != NULL)
	    || (mePtr->fgPtr != NULL)
	    || (mePtr->activeBorderPtr != NULL)
381
382
383
384
385
386
387
388
389
390
391




392
393

394
395
396
397

398
399
400
401

402
403
404
405

406
407
408
409
410
411
412
381
382
383
384
385
386
387




388
389
390
391
392

393
394
395
396

397
398
399
400

401
402
403
404

405
406
407
408
409
410
411
412







-
-
-
-
+
+
+
+

-
+



-
+



-
+



-
+








	gcValues.foreground = activeFg->pixel;
	gcValues.background = Tk_3DBorderColor(activeBorder)->pixel;
	newActiveGC = Tk_GetGC(menuPtr->tkwin,
		GCForeground|GCBackground|GCFont|GCGraphicsExposures,
		&gcValues);
    } else {
	newGC = NULL;
	newActiveGC = NULL;
	newDisabledGC = NULL;
	newIndicatorGC = NULL;
	newGC = None;
	newActiveGC = None;
	newDisabledGC = None;
	newIndicatorGC = None;
    }
    if (mePtr->textGC != NULL) {
    if (mePtr->textGC != None) {
	Tk_FreeGC(menuPtr->display, mePtr->textGC);
    }
    mePtr->textGC = newGC;
    if (mePtr->activeGC != NULL) {
    if (mePtr->activeGC != None) {
	Tk_FreeGC(menuPtr->display, mePtr->activeGC);
    }
    mePtr->activeGC = newActiveGC;
    if (mePtr->disabledGC != NULL) {
    if (mePtr->disabledGC != None) {
	Tk_FreeGC(menuPtr->display, mePtr->disabledGC);
    }
    mePtr->disabledGC = newDisabledGC;
    if (mePtr->indicatorGC != NULL) {
    if (mePtr->indicatorGC != None) {
	Tk_FreeGC(menuPtr->display, mePtr->indicatorGC);
    }
    mePtr->indicatorGC = newIndicatorGC;
    return TCL_OK;
}

/*
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487


488
489
490

491
492
493
494
495
496
497
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485


486
487
488
489

490
491
492
493
494
495
496
497







-
+







-
-
+
+


-
+







 *	Arrange for an entry of a menu, or the whole menu, to be redisplayed
 *	at some point in the future.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A when-idle handler is scheduled to do the redisplay, if there isn't
 *	A when-idle hander is scheduled to do the redisplay, if there isn't
 *	one already scheduled.
 *
 *----------------------------------------------------------------------
 */

void
TkEventuallyRedrawMenu(
    TkMenu *menuPtr,	/* Information about menu to redraw. */
    TkMenuEntry *mePtr)/* Entry to redraw. NULL means redraw all the
    register TkMenu *menuPtr,	/* Information about menu to redraw. */
    register TkMenuEntry *mePtr)/* Entry to redraw. NULL means redraw all the
				 * entries in the menu. */
{
    Tcl_Size i;
    int i;

    if (menuPtr->tkwin == NULL) {
	return;
    }
    if (mePtr != NULL) {
	mePtr->entryFlags |= ENTRY_NEEDS_REDISPLAY;
    } else {
524
525
526
527
528
529
530
531

532
533

534
535
536
537
538
539
540
524
525
526
527
528
529
530

531
532

533
534
535
536
537
538
539
540







-
+

-
+







 *	and the size of the menu window itself may be changed.
 *
 *--------------------------------------------------------------
 */

static void
ComputeMenuGeometry(
    void *clientData)	/* Structure describing menu. */
    ClientData clientData)	/* Structure describing menu. */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenu *menuPtr = clientData;

    if (menuPtr->tkwin == NULL) {
	return;
    }

    if (menuPtr->menuType == MENUBAR) {
	TkpComputeMenubarGeometry(menuPtr);
575
576
577
578
579
580
581
582
583
584
585
586





587
588

589
590

591
592
593
594
595
596
597
575
576
577
578
579
580
581





582
583
584
585
586


587
588

589
590
591
592
593
594
595
596







-
-
-
-
-
+
+
+
+
+
-
-
+

-
+







 *	Arranges for the menu to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

void
TkMenuSelectImageProc(
    void *clientData,	/* Pointer to widget record. */
    TCL_UNUSED(int), /* Upper left pixel (within image) that must */
    TCL_UNUSED(int), /* be redisplayed. */
    TCL_UNUSED(int), /* Dimensions of area to redisplay (may be */
    TCL_UNUSED(int), /* <= 0). */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (may be
				 * <=0). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))/* New dimensions of image. */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    TkMenuEntry *mePtr = (TkMenuEntry *)clientData;
    register TkMenuEntry *mePtr = clientData;

    if ((mePtr->entryFlags & ENTRY_SELECTED)
	    && !(mePtr->menuPtr->menuFlags & REDRAW_PENDING)) {
	mePtr->menuPtr->menuFlags |= REDRAW_PENDING;
	Tcl_DoWhenIdle(DisplayMenu, mePtr->menuPtr);
    }
}
610
611
612
613
614
615
616
617

618
619
620
621



622
623

624
625
626
627
628


629
630
631
632
633
634
635
636
637
638


639
640
641
642
643
644
645
609
610
611
612
613
614
615

616
617



618
619
620


621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647







-
+

-
-
-
+
+
+
-
-
+





+
+










+
+







 *	Commands are output to X to display the menu in its current mode.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayMenu(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenuEntry *mePtr;
    Tk_Window tkwin = menuPtr->tkwin;
    register TkMenu *menuPtr = clientData;
    register TkMenuEntry *mePtr;
    register Tk_Window tkwin = menuPtr->tkwin;
    Tcl_Size index;
    int strictMotif;
    int index, strictMotif;
    Tk_Font tkfont;
    Tk_FontMetrics menuMetrics;
    int width;
    int borderWidth;
    Tk_3DBorder border;
    int activeBorderWidth;
    int relief;


    menuPtr->menuFlags &= ~REDRAW_PENDING;
    if ((menuPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
	    &borderWidth);
    border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
	    menuPtr->activeBorderWidthPtr, &activeBorderWidth);

    if (menuPtr->menuType == MENUBAR) {
	Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, borderWidth,
		borderWidth, Tk_Width(tkwin) - 2 * borderWidth,
		Tk_Height(tkwin) - 2 * borderWidth, 0, TK_RELIEF_FLAT);
    }

662
663
664
665
666
667
668
669
670


671
672
673
674



675
676
677
678
679

680
681


682
683
684
685





686
687
688
689
690
691
692
693
694
695
696
697





698
699
700
701
702
703
704
705
706
707


708
709
710
711
712
713
714
715
716
717
718



719
720
721
722


723
724
725
726
727
728
729
730
731
732
733

734
735
736

737
738
739
740
741
742
743
664
665
666
667
668
669
670


671
672




673
674
675





676


677
678




679
680
681
682
683
684
685





686
687



688
689
690
691
692
693
694
695
696
697
698
699
700


701
702
703
704





705
706


707
708
709
710
711


712
713
714






715
716
717
718
719
720
721

722
723
724
725
726
727
728
729







-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
-
-
+
+
-
-
-
-
+
+
+
+
+


-
-
-
-
-


-
-
-
+
+
+
+
+








-
-
+
+


-
-
-
-
-


-
-
+
+
+


-
-
+
+

-
-
-
-
-
-




+


-
+







	if (menuPtr->menuType != MENUBAR) {
	    if (!(mePtr->entryFlags & ENTRY_NEEDS_REDISPLAY)) {
		continue;
	    }
	}
	mePtr->entryFlags &= ~ENTRY_NEEDS_REDISPLAY;

	TkpDrawMenuEntry(mePtr, Tk_WindowId(menuPtr->tkwin), tkfont,
		&menuMetrics, mePtr->x, mePtr->y, mePtr->width,
	if (menuPtr->menuType == MENUBAR) {
	    width = mePtr->width;
		mePtr->height, strictMotif, 1);

        if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {

	} else {
	    if (mePtr->entryFlags & ENTRY_LAST_COLUMN) {
		width = Tk_Width(menuPtr->tkwin) - mePtr->x
            /*
             * Paint the area at the right of an entry in the last column.
             * This has zero width except after menu resizing.
             */

			- activeBorderWidth;
            Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border,
                    mePtr->x + mePtr->width, mePtr->y,
	    } else {
		width = mePtr->width + borderWidth;
                    Tk_Width(tkwin) - mePtr->x - mePtr->width - borderWidth,
                    mePtr->height, 0, TK_RELIEF_FLAT);
        }

	    }
	}
	TkpDrawMenuEntry(mePtr, Tk_WindowId(menuPtr->tkwin), tkfont,
		&menuMetrics, mePtr->x, mePtr->y, width,
		mePtr->height, strictMotif, 1);
	if ((index > 0) && (menuPtr->menuType != MENUBAR)
		&& mePtr->columnBreak) {

            /*
             * Paint the area under the last entry in a column.
             */

	    mePtr = menuPtr->entries[index - 1];
	    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border,
		mePtr->x, mePtr->y + mePtr->height, mePtr->width,
		Tk_Height(tkwin) - mePtr->y - mePtr->height - borderWidth,
		0, TK_RELIEF_FLAT);
		mePtr->x, mePtr->y + mePtr->height,
		mePtr->width,
		Tk_Height(tkwin) - mePtr->y - mePtr->height -
		activeBorderWidth, 0,
		TK_RELIEF_FLAT);
	}
    }

    if (menuPtr->menuType != MENUBAR) {
	int x, y, height;

	if (menuPtr->numEntries == 0) {
	    x = y = borderWidth;
	    width = Tk_Width(tkwin) - 2 * borderWidth;
	    height = Tk_Height(tkwin) - 2 * borderWidth;
	    width = Tk_Width(tkwin) - 2 * activeBorderWidth;
	    height = Tk_Height(tkwin) - 2 * activeBorderWidth;
	} else {
	    mePtr = menuPtr->entries[menuPtr->numEntries - 1];

            /*
             * Paint the area under the last entry of the menu.
             */

	    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
		border, mePtr->x, mePtr->y + mePtr->height, mePtr->width,
		Tk_Height(tkwin) - mePtr->y - mePtr->height - borderWidth,
		0, TK_RELIEF_FLAT);
		Tk_Height(tkwin) - mePtr->y - mePtr->height
		- activeBorderWidth, 0,
		TK_RELIEF_FLAT);
	    x = mePtr->x + mePtr->width;
	    y = mePtr->y + mePtr->height;
	    width = Tk_Width(tkwin) - x - borderWidth;
	    height = Tk_Height(tkwin) - y - borderWidth;
	    width = Tk_Width(tkwin) - x - activeBorderWidth;
	    height = Tk_Height(tkwin) - y - activeBorderWidth;
	}

        /*
         * Paint the area at the bottom right of the last entry.
         * This has zero width except after menu resizing.
         */

	Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, x, y,
		width, height, 0, TK_RELIEF_FLAT);
    }

    Tk_GetReliefFromObj(NULL, menuPtr->reliefPtr, &relief);
    Tk_Draw3DRectangle(menuPtr->tkwin, Tk_WindowId(tkwin),
	    border, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), borderWidth,
	    menuPtr->relief);
	    relief);
}

/*
 *--------------------------------------------------------------
 *
 * TkMenuEventProc --
 *
752
753
754
755
756
757
758
759

760
761
762

763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
738
739
740
741
742
743
744

745
746
747

748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764







-
+


-
+








-
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

void
TkMenuEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenu *menuPtr = clientData;

    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	TkEventuallyRedrawMenu(menuPtr, NULL);
    } else if (eventPtr->type == ConfigureNotify) {
	TkEventuallyRecomputeMenu(menuPtr);
	TkEventuallyRedrawMenu(menuPtr, NULL);
    } else if (eventPtr->type == ActivateNotify) {
	if (menuPtr->menuType == TEAROFF_MENU) {
	    Tk_SetMainMenubar(menuPtr->interp, menuPtr->tkwin, NULL);
	    TkpSetMainMenubar(menuPtr->interp, menuPtr->tkwin, NULL);
	}
    } else if (eventPtr->type == DestroyNotify) {
	if (menuPtr->tkwin != NULL) {
	    if (!(menuPtr->menuFlags & MENU_DELETION_PENDING)) {
		TkDestroyMenu(menuPtr);
	    }
	    menuPtr->tkwin = NULL;
813
814
815
816
817
818
819
820
821
822
823
824
825






826
827
828

829
830
831
832
833
834
835
836
837
838
839
840

841
842


843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
















860










































861
862
863
864
865
866
867
799
800
801
802
803
804
805






806
807
808
809
810
811

812

813
814
815
816
817
818
819
820
821
822
823
824
825
826


827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861

862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910







-
-
-
-
-
-
+
+
+
+
+
+
-

-
+












+
-
-
+
+

















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	Arranges for the menu to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

void
TkMenuImageProc(
    void *clientData,/* Pointer to widget record. */
    TCL_UNUSED(int), /* Upper left pixel (within image) that must */
    TCL_UNUSED(int), /*		 * be redisplayed. */
    TCL_UNUSED(int), /* Dimensions of area to redisplay (may be */
    TCL_UNUSED(int), /* <=0). */
    TCL_UNUSED(int), /* New dimensions of image. */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (may be
				 * <=0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
    TCL_UNUSED(int))
{
    TkMenu *menuPtr = (TkMenu *)((TkMenuEntry *) clientData)->menuPtr;
    register TkMenu *menuPtr = ((TkMenuEntry *) clientData)->menuPtr;

    if ((menuPtr->tkwin != NULL) && !(menuPtr->menuFlags & RESIZE_PENDING)) {
	menuPtr->menuFlags |= RESIZE_PENDING;
	Tcl_DoWhenIdle(ComputeMenuGeometry, menuPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkPostTearoffMenu --
 *
 *	Posts a menu on the screen. Used to post tearoff menus. On Unix, all
 *	Posts a tearoff menu on the screen. Adjusts the menu's position so
 *	that it fits on the screen, and maps and raises the menu.
 *	menus are posted this way. Adjusts the menu's position so that it fits
 *	on the screen, and maps and raises the menu.
 *
 * Results:
 *	Returns a standard Tcl Error.
 *
 * Side effects:
 *	The menu is posted.
 *
 *----------------------------------------------------------------------
 */

int
TkPostTearoffMenu(
    Tcl_Interp *interp,		/* The interpreter of the menu */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y)		/* The root X,Y coordinates where we are
				 * posting */
{
    int vRootX, vRootY, vRootWidth, vRootHeight;
    int result;

    TkActivateMenuEntry(menuPtr, -1);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }

    /*
     * The post commands could have deleted the menu, which means we are dead
     * and should go away.
     */

    if (menuPtr->tkwin == NULL) {
    return TkpPostTearoffMenu(interp, menuPtr, x, y, -1);
    	return TCL_OK;
    }

    /*
     * Adjust the position of the menu if necessary to keep it visible on the
     * screen. There are two special tricks to make this work right:
     *
     * 1. If a virtual root window manager is being used then the coordinates
     *    are in the virtual root window of menuPtr's parent; since the menu
     *    uses override-redirect mode it will be in the *real* root window for
     *    the screen, so we have to map the coordinates from the virtual root
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.
     */

    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);
    vRootWidth -= Tk_ReqWidth(menuPtr->tkwin);
    if (x > vRootX + vRootWidth) {
	x = vRootX + vRootWidth;
    }
    if (x < vRootX) {
	x = vRootX;
    }
    vRootHeight -= Tk_ReqHeight(menuPtr->tkwin);
    if (y > vRootY + vRootHeight) {
	y = vRootY + vRootHeight;
    }
    if (y < vRootY) {
	y = vRootY;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * TkPostSubmenu --
 *
879
880
881
882
883
884
885
886
887


888
889
890
891
892
893
894
922
923
924
925
926
927
928


929
930
931
932
933
934
935
936
937







-
-
+
+







 *--------------------------------------------------------------
 */

int
TkPostSubmenu(
    Tcl_Interp *interp,		/* Used for invoking sub-commands and
				 * reporting errors. */
    TkMenu *menuPtr,	/* Information about menu as a whole. */
    TkMenuEntry *mePtr)/* Info about submenu that is to be posted.
    register TkMenu *menuPtr,	/* Information about menu as a whole. */
    register TkMenuEntry *mePtr)/* Info about submenu that is to be posted.
				 * NULL means make sure that no submenu is
				 * posted. */
{
    int result, x, y;
    Tcl_Obj *subary[4];

    if (mePtr == menuPtr->postedCascade) {
908
909
910
911
912
913
914
915

916
917
918
919
920
921
922
951
952
953
954
955
956
957

958
959
960
961
962
963
964
965







-
+







	 *     posted, in which case the saved information is no longer
	 *     correct.
	 * The simplest solution is just force a complete redisplay of the
	 * parent.
	 */

	subary[0] = menuPtr->postedCascade->namePtr;
	subary[1] = Tcl_NewStringObj("unpost", TCL_INDEX_NONE);
	subary[1] = Tcl_NewStringObj("unpost", -1);
	Tcl_IncrRefCount(subary[1]);
	TkEventuallyRedrawMenu(menuPtr, NULL);
	result = Tcl_EvalObjv(interp, 2, subary, 0);
	Tcl_DecrRefCount(subary[1]);
	menuPtr->postedCascade = NULL;
	if (result != TCL_OK) {
	    return result;
937
938
939
940
941
942
943
944
945
946



947
948
949
950
951
952
953
980
981
982
983
984
985
986



987
988
989
990
991
992
993
994
995
996







-
-
-
+
+
+







	 */

	Tk_GetRootCoords(menuPtr->tkwin, &x, &y);
	AdjustMenuCoords(menuPtr, mePtr, &x, &y);

	menuPtr->postedCascade = mePtr;
	subary[0] = mePtr->namePtr;
	subary[1] = Tcl_NewStringObj("post", TCL_INDEX_NONE);
	subary[2] = Tcl_NewWideIntObj(x);
	subary[3] = Tcl_NewWideIntObj(y);
	subary[1] = Tcl_NewStringObj("post", -1);
	subary[2] = Tcl_NewIntObj(x);
	subary[3] = Tcl_NewIntObj(y);
	Tcl_IncrRefCount(subary[1]);
	Tcl_IncrRefCount(subary[2]);
	Tcl_IncrRefCount(subary[3]);
	result = Tcl_EvalObjv(interp, 4, subary, 0);
	Tcl_DecrRefCount(subary[1]);
	Tcl_DecrRefCount(subary[2]);
	Tcl_DecrRefCount(subary[3]);

Changes to generic/tkMenubutton.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15

16
17
18
19
20
21
22
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23






-
-
+
+







+







/*
 * tkMenubutton.c --
 *
 *	This module implements button-like widgets that are used to invoke
 *	pull-down menus.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "tkMenubutton.h"
#include "default.h"

/*
 * The structure below defines menubutton class behavior by means of
 * procedures that can be invoked from generic window code.
 */

static const Tk_ClassProcs menubuttonClass = {
31
32
33
34
35
36
37


















38
39
40
41
42
43
44
45
46



47
48
49
50



51
52
53


54
55

56
57
58
59
60




61
62

63
64
65
66


67
68

69
70
71
72


73
74
75
76
77
78




79
80

81
82

83
84

85
86
87
88

89
90
91


92
93
94

95
96

97
98
99

100
101
102

103
104

105
106
107

108
109
110

111
112
113

114
115
116
117


118
119
120


121
122
123


124
125

126
127
128
129
130





131
132

133
134
135

136
137
138
139
140
141
142
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62



63
64
65
66



67
68
69
70


71
72
73

74
75




76
77
78
79
80

81
82
83


84
85
86

87
88
89


90
91
92
93




94
95
96
97
98

99
100

101
102

103
104
105
106

107
108


109
110
111
112

113
114

115
116
117

118
119
120

121
122

123
124
125

126
127
128

129
130
131

132
133
134


135
136
137


138
139
140


141
142
143

144
145




146
147
148
149
150
151

152
153
154

155
156
157
158
159
160
161
162







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
-
-
+
+
+

-
-
-
+
+
+

-
-
+
+

-
+

-
-
-
-
+
+
+
+

-
+


-
-
+
+

-
+


-
-
+
+


-
-
-
-
+
+
+
+

-
+

-
+

-
+



-
+

-
-
+
+


-
+

-
+


-
+


-
+

-
+


-
+


-
+


-
+


-
-
+
+

-
-
+
+

-
-
+
+

-
+

-
-
-
-
+
+
+
+
+

-
+


-
+







 * is used together with the "enum direction" declaration in tkMenubutton.h.
 */

static const char *const directionStrings[] = {
    "above", "below", "flush", "left", "right", NULL
};

/*
 * The following table defines the legal values for the -state option. It is
 * used together with the "enum state" declaration in tkMenubutton.h.
 */

static const char *const stateStrings[] = {
    "active", "disabled", "normal", NULL
};

/*
 * The following table defines the legal values for the -compound option. It
 * is used with the "enum compound" declaration in tkMenuButton.h
 */

static const char *const compoundStrings[] = {
    "bottom", "center", "left", "none", "right", "top", NULL
};

/*
 * Information used for parsing configuration specs:
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_MENUBUTTON_ACTIVE_BG_COLOR, TCL_INDEX_NONE,
	offsetof(TkMenuButton, activeBorder), 0,
	DEF_MENUBUTTON_ACTIVE_BG_MONO, 0},
	DEF_MENUBUTTON_ACTIVE_BG_COLOR, -1,
	Tk_Offset(TkMenuButton, activeBorder), 0,
	(ClientData) DEF_MENUBUTTON_ACTIVE_BG_MONO, 0},
    {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background",
	DEF_MENUBUTTON_ACTIVE_FG_COLOR, TCL_INDEX_NONE,
	offsetof(TkMenuButton, activeFg),
	0, DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
	DEF_MENUBUTTON_ACTIVE_FG_COLOR, -1,
	 Tk_Offset(TkMenuButton, activeFg),
	 0, DEF_MENUBUTTON_ACTIVE_FG_MONO, 0},
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	DEF_MENUBUTTON_ANCHOR, TCL_INDEX_NONE,
	offsetof(TkMenuButton, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_MENUBUTTON_ANCHOR, -1,
	Tk_Offset(TkMenuButton, anchor), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_MENUBUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(TkMenuButton, normalBorder),
	DEF_MENUBUTTON_BG_COLOR, -1, Tk_Offset(TkMenuButton, normalBorder),
	0, DEF_MENUBUTTON_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL, 0, TCL_INDEX_NONE,
	0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, TCL_INDEX_NONE,
	0, "-background", 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL, 0, -1, 0,
	(ClientData) "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, -1, 0,
	(ClientData) "-background", 0},
    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap",
	DEF_MENUBUTTON_BITMAP, TCL_INDEX_NONE, offsetof(TkMenuButton, bitmap),
	DEF_MENUBUTTON_BITMAP, -1, Tk_Offset(TkMenuButton, bitmap),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_MENUBUTTON_BORDER_WIDTH, TCL_INDEX_NONE,
	offsetof(TkMenuButton, borderWidth), 0, 0, 0},
	DEF_MENUBUTTON_BORDER_WIDTH, -1,
	Tk_Offset(TkMenuButton, borderWidth), 0, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_MENUBUTTON_CURSOR, TCL_INDEX_NONE, offsetof(TkMenuButton, cursor),
	DEF_MENUBUTTON_CURSOR, -1, Tk_Offset(TkMenuButton, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-direction", "direction", "Direction",
	DEF_MENUBUTTON_DIRECTION, TCL_INDEX_NONE, offsetof(TkMenuButton, direction),
	TK_OPTION_ENUM_VAR, directionStrings, 0},
	DEF_MENUBUTTON_DIRECTION, -1, Tk_Offset(TkMenuButton, direction),
	0, directionStrings, 0},
    {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
	"DisabledForeground", DEF_MENUBUTTON_DISABLED_FG_COLOR,
	TCL_INDEX_NONE, offsetof(TkMenuButton, disabledFg), TK_OPTION_NULL_OK,
	DEF_MENUBUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL, NULL, 0, TCL_INDEX_NONE,
	0, "-foreground", 0},
	-1, Tk_Offset(TkMenuButton, disabledFg), TK_OPTION_NULL_OK,
	(ClientData) DEF_MENUBUTTON_DISABLED_FG_MONO, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL, NULL, 0, -1, 0,
	(ClientData) "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_MENUBUTTON_FONT, TCL_INDEX_NONE, offsetof(TkMenuButton, tkfont), 0, 0, 0},
	DEF_MENUBUTTON_FONT, -1, Tk_Offset(TkMenuButton, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_MENUBUTTON_FG, TCL_INDEX_NONE, offsetof(TkMenuButton, normalFg), 0, 0, 0},
	DEF_MENUBUTTON_FG, -1, Tk_Offset(TkMenuButton, normalFg), 0, 0, 0},
    {TK_OPTION_STRING, "-height", "height", "Height",
	DEF_MENUBUTTON_HEIGHT, TCL_INDEX_NONE, offsetof(TkMenuButton, heightString),
	DEF_MENUBUTTON_HEIGHT, -1, Tk_Offset(TkMenuButton, heightString),
	0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkMenuButton, highlightBgColorPtr), 0, 0, 0},
	-1, Tk_Offset(TkMenuButton, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_MENUBUTTON_HIGHLIGHT, TCL_INDEX_NONE,
	offsetof(TkMenuButton, highlightColorPtr),	0, 0, 0},
	DEF_MENUBUTTON_HIGHLIGHT, -1,
	Tk_Offset(TkMenuButton, highlightColorPtr),	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_MENUBUTTON_HIGHLIGHT_WIDTH,
	TCL_INDEX_NONE, offsetof(TkMenuButton, highlightWidth), 0, 0, 0},
	-1, Tk_Offset(TkMenuButton, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-image", "image", "Image",
	DEF_MENUBUTTON_IMAGE, TCL_INDEX_NONE, offsetof(TkMenuButton, imageString),
	DEF_MENUBUTTON_IMAGE, -1, Tk_Offset(TkMenuButton, imageString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-indicatoron", "indicatorOn", "IndicatorOn",
	DEF_MENUBUTTON_INDICATOR, TCL_INDEX_NONE, offsetof(TkMenuButton, indicatorOn),
	DEF_MENUBUTTON_INDICATOR, -1, Tk_Offset(TkMenuButton, indicatorOn),
	0, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_MENUBUTTON_JUSTIFY, TCL_INDEX_NONE, offsetof(TkMenuButton, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_MENUBUTTON_JUSTIFY, -1, Tk_Offset(TkMenuButton, justify), 0, 0, 0},
    {TK_OPTION_STRING, "-menu", "menu", "Menu",
	DEF_MENUBUTTON_MENU, TCL_INDEX_NONE, offsetof(TkMenuButton, menuName),
	DEF_MENUBUTTON_MENU, -1, Tk_Offset(TkMenuButton, menuName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	DEF_MENUBUTTON_PADX, TCL_INDEX_NONE, offsetof(TkMenuButton, padX),
	DEF_MENUBUTTON_PADX, -1, Tk_Offset(TkMenuButton, padX),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	DEF_MENUBUTTON_PADY, TCL_INDEX_NONE, offsetof(TkMenuButton, padY),
	DEF_MENUBUTTON_PADY, -1, Tk_Offset(TkMenuButton, padY),
	0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_MENUBUTTON_RELIEF, TCL_INDEX_NONE, offsetof(TkMenuButton, relief),
	DEF_MENUBUTTON_RELIEF, -1, Tk_Offset(TkMenuButton, relief),
	0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	DEF_BUTTON_COMPOUND, TCL_INDEX_NONE, offsetof(TkMenuButton, compound),
	0, tkCompoundStrings, 0},
	 DEF_BUTTON_COMPOUND, -1, Tk_Offset(TkMenuButton, compound), 0,
	 compoundStrings, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_MENUBUTTON_STATE, TCL_INDEX_NONE, offsetof(TkMenuButton, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_MENUBUTTON_STATE, -1, Tk_Offset(TkMenuButton, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_MENUBUTTON_TAKE_FOCUS, TCL_INDEX_NONE,
	offsetof(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0},
	DEF_MENUBUTTON_TAKE_FOCUS, -1,
	Tk_Offset(TkMenuButton, takeFocus), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_MENUBUTTON_TEXT, TCL_INDEX_NONE, offsetof(TkMenuButton, text), 0, 0, 0},
	DEF_MENUBUTTON_TEXT, -1, Tk_Offset(TkMenuButton, text), 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_MENUBUTTON_TEXT_VARIABLE, TCL_INDEX_NONE,
	offsetof(TkMenuButton, textVarName), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TK_OPTION_UNDERLINE_DEF(TkMenuButton, underline), 0},
	DEF_MENUBUTTON_TEXT_VARIABLE, -1,
	Tk_Offset(TkMenuButton, textVarName), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	DEF_MENUBUTTON_UNDERLINE, -1, Tk_Offset(TkMenuButton, underline),
	 0, 0, 0},
    {TK_OPTION_STRING, "-width", "width", "Width",
	DEF_MENUBUTTON_WIDTH, TCL_INDEX_NONE, offsetof(TkMenuButton, widthString),
	DEF_MENUBUTTON_WIDTH, -1, Tk_Offset(TkMenuButton, widthString),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	DEF_MENUBUTTON_WRAP_LENGTH, TCL_INDEX_NONE, offsetof(TkMenuButton, wrapLength),
	DEF_MENUBUTTON_WRAP_LENGTH, -1, Tk_Offset(TkMenuButton, wrapLength),
	0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
};

/*
 * The following tables define the menubutton widget commands and map the
 * indexes into the string tables into a single enumerated type used to
151
152
153
154
155
156
157
158
159


160
161

162
163
164

165
166
167



168
169
170
171

172
173
174
175
176
177
178
171
172
173
174
175
176
177


178
179
180

181
182
183

184
185
186

187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
-
+
+

-
+


-
+


-
+
+
+



-
+







    COMMAND_CGET, COMMAND_CONFIGURE
};

/*
 * Forward declarations for functions defined later in this file:
 */

static void		MenuButtonCmdDeletedProc(void *clientData);
static void		MenuButtonEventProc(void *clientData,
static void		MenuButtonCmdDeletedProc(ClientData clientData);
static void		MenuButtonEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		MenuButtonImageProc(void *clientData,
static void		MenuButtonImageProc(ClientData clientData,
			    int x, int y, int width, int height, int imgWidth,
			    int imgHeight);
static char *		MenuButtonTextVarProc(void *clientData,
static char *		MenuButtonTextVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static Tcl_ObjCmdProc MenuButtonWidgetObjCmd;
static int		MenuButtonWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		ConfigureMenuButton(Tcl_Interp *interp,
			    TkMenuButton *mbPtr, int objc,
			    Tcl_Obj *const objv[]);
static void		DestroyMenuButton(void *memPtr);
static void		DestroyMenuButton(char *memPtr);

/*
 *--------------------------------------------------------------
 *
 * Tk_MenubuttonObjCmd --
 *
 *	This function is invoked to process the "button", "label",
186
187
188
189
190
191
192
193

194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
208
209
210
211
212
213
214

215
216
217
218
219

220
221
222

223
224
225
226
227
228
229







-
+




-
+


-







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_MenubuttonObjCmd(
    void *dummy,	/* NULL. */
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkMenuButton *mbPtr;
    register TkMenuButton *mbPtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;
    (void)dummy;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

    /*
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262


263
264
265


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281


282
283
284


285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328







-
+

















-
-
+
+

-
-
+
+
















-
+







-
+









-
+







    mbPtr->interp = interp;
    mbPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(mbPtr->tkwin), MenuButtonWidgetObjCmd, mbPtr,
	    MenuButtonCmdDeletedProc);
    mbPtr->optionTable = optionTable;
    mbPtr->menuName = NULL;
    mbPtr->text = NULL;
    mbPtr->underline = INT_MIN;
    mbPtr->underline = -1;
    mbPtr->textVarName = NULL;
    mbPtr->bitmap = None;
    mbPtr->imageString = NULL;
    mbPtr->image = NULL;
    mbPtr->state = STATE_NORMAL;
    mbPtr->normalBorder = NULL;
    mbPtr->activeBorder = NULL;
    mbPtr->borderWidth = 0;
    mbPtr->relief = TK_RELIEF_FLAT;
    mbPtr->highlightWidth = 0;
    mbPtr->highlightBgColorPtr = NULL;
    mbPtr->highlightColorPtr = NULL;
    mbPtr->inset = 0;
    mbPtr->tkfont = NULL;
    mbPtr->normalFg = NULL;
    mbPtr->activeFg = NULL;
    mbPtr->disabledFg = NULL;
    mbPtr->normalTextGC = NULL;
    mbPtr->activeTextGC = NULL;
    mbPtr->normalTextGC = None;
    mbPtr->activeTextGC = None;
    mbPtr->gray = None;
    mbPtr->disabledGC = NULL;
    mbPtr->stippleGC = NULL;
    mbPtr->disabledGC = None;
    mbPtr->stippleGC = None;
    mbPtr->leftBearing = 0;
    mbPtr->rightBearing = 0;
    mbPtr->widthString = NULL;
    mbPtr->heightString = NULL;
    mbPtr->width = 0;
    mbPtr->width = 0;
    mbPtr->wrapLength = 0;
    mbPtr->padX = 0;
    mbPtr->padY = 0;
    mbPtr->anchor = TK_ANCHOR_CENTER;
    mbPtr->justify = TK_JUSTIFY_CENTER;
    mbPtr->textLayout = NULL;
    mbPtr->indicatorOn = 0;
    mbPtr->indicatorWidth = 0;
    mbPtr->indicatorHeight = 0;
    mbPtr->direction = DIRECTION_FLUSH;
    mbPtr->cursor = NULL;
    mbPtr->cursor = None;
    mbPtr->takeFocus = NULL;
    mbPtr->flags = 0;

    Tk_CreateEventHandler(mbPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    MenuButtonEventProc, mbPtr);

    if (Tk_InitOptions(interp, mbPtr, optionTable, tkwin) != TCL_OK) {
    if (Tk_InitOptions(interp, (char *) mbPtr, optionTable, tkwin) != TCL_OK) {
	Tk_DestroyWindow(mbPtr->tkwin);
	return TCL_ERROR;
    }

    if (ConfigureMenuButton(interp, mbPtr, objc-2, objv+2) != TCL_OK) {
	Tk_DestroyWindow(mbPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(mbPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(mbPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * MenuButtonWidgetObjCmd --
317
318
319
320
321
322
323
324

325
326
327
328
329

330
331
332
333
334
335
336
338
339
340
341
342
343
344

345
346
347
348
349

350
351
352
353
354
355
356
357







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
MenuButtonWidgetObjCmd(
    void *clientData,	/* Information about button widget. */
    ClientData clientData,	/* Information about button widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    register TkMenuButton *mbPtr = clientData;
    int result, index;
    Tcl_Obj *objPtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389







-
+









-
+







    switch (index) {
    case COMMAND_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "cget option");
	    goto error;
	}

	objPtr = Tk_GetOptionValue(interp, mbPtr,
	objPtr = Tk_GetOptionValue(interp, (char *) mbPtr,
		mbPtr->optionTable, objv[2], mbPtr->tkwin);
	if (objPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;

    case COMMAND_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, mbPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) mbPtr,
		    mbPtr->optionTable, (objc == 3) ? objv[2] : NULL,
		    mbPtr->tkwin);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
395
396
397
398
399
400
401
402

403
404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428

429
430
431

432
433
434

435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
416
417
418
419
420
421
422

423
424

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448

449
450
451

452
453
454

455
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471







-
+

-
+




















-
+


-
+


-
+


-
+








-
+







 *	Everything associated with the widget is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyMenuButton(
    void *memPtr)		/* Info about button widget. */
    char *memPtr)		/* Info about button widget. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)memPtr;
    register TkMenuButton *mbPtr = (TkMenuButton *) memPtr;
    TkpDestroyMenuButton(mbPtr);

    if (mbPtr->flags & REDRAW_PENDING) {
	Tcl_CancelIdleCall(TkpDisplayMenuButton, mbPtr);
    }

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeOptions handle all the standard option-related stuff.
     */

    Tcl_DeleteCommandFromToken(mbPtr->interp, mbPtr->widgetCmd);
    if (mbPtr->textVarName != NULL) {
	Tcl_UntraceVar2(mbPtr->interp, mbPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MenuButtonTextVarProc, mbPtr);
    }
    if (mbPtr->image != NULL) {
	Tk_FreeImage(mbPtr->image);
    }
    if (mbPtr->normalTextGC != NULL) {
    if (mbPtr->normalTextGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->normalTextGC);
    }
    if (mbPtr->activeTextGC != NULL) {
    if (mbPtr->activeTextGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->activeTextGC);
    }
    if (mbPtr->disabledGC != NULL) {
    if (mbPtr->disabledGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->disabledGC);
    }
    if (mbPtr->stippleGC != NULL) {
    if (mbPtr->stippleGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->stippleGC);
    }
    if (mbPtr->gray != None) {
	Tk_FreeBitmap(mbPtr->display, mbPtr->gray);
    }
    if (mbPtr->textLayout != NULL) {
	Tk_FreeTextLayout(mbPtr->textLayout);
    }
    Tk_FreeConfigOptions(mbPtr, mbPtr->optionTable, mbPtr->tkwin);
    Tk_FreeConfigOptions((char *) mbPtr, mbPtr->optionTable, mbPtr->tkwin);
    mbPtr->tkwin = NULL;
    Tcl_EventuallyFree(mbPtr, TCL_DYNAMIC);
}

/*
 *----------------------------------------------------------------------
 *
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500







-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureMenuButton(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkMenuButton *mbPtr,
    register TkMenuButton *mbPtr,
				/* Information about widget; may or may not
				 * already have values for some fields. */
    int objc,			/* Number of valid entries in objv. */
    Tcl_Obj *const objv[])	/* Arguments. */
{
    Tk_SavedOptions savedOptions;
    Tcl_Obj *errorResult = NULL;
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534







-
+








    for (error = 0; error <= 1; error++) {
	if (!error) {
	    /*
	     * First pass: set options to new values.
	     */

	    if (Tk_SetOptions(interp, mbPtr,
	    if (Tk_SetOptions(interp, (char *) mbPtr,
		    mbPtr->optionTable, objc, objv,
		    mbPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
		continue;
	    }
	} else {
	    /*
	     * Second pass: restore options to old values.
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643







-
+







	if (value == NULL) {
	    Tcl_SetVar2(interp, mbPtr->textVarName, NULL, mbPtr->text,
		    TCL_GLOBAL_ONLY);
	} else {
	    if (mbPtr->text != NULL) {
		ckfree(mbPtr->text);
	    }
	    mbPtr->text = (char *)ckalloc(strlen(value) + 1);
	    mbPtr->text = ckalloc(strlen(value) + 1);
	    strcpy(mbPtr->text, value);
	}
	Tcl_TraceVar2(interp, mbPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MenuButtonTextVarProc, mbPtr);
    }

645
646
647
648
649
650
651
652

653
654
655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681

682
683
684
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
666
667
668
669
670
671
672

673
674
675
676
677

678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711
712

713
714
715
716
717
718
719
720







-
+




-
+














-
+








-
+










-
+







 *	TkMenuButton will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

void
TkMenuButtonWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC gc;
    unsigned long mask;
    TkMenuButton *mbPtr = (TkMenuButton *)instanceData;
    TkMenuButton *mbPtr = instanceData;

    gcValues.font = Tk_FontId(mbPtr->tkfont);
    gcValues.foreground = mbPtr->normalFg->pixel;
    gcValues.background = Tk_3DBorderColor(mbPtr->normalBorder)->pixel;

    /*
     * Note: GraphicsExpose events are disabled in GC's because they're used
     * to copy stuff from an off-screen pixmap onto the screen (we know that
     * there's no problem with obscured areas).
     */

    gcValues.graphics_exposures = False;
    mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
    gc = Tk_GetGC(mbPtr->tkwin, mask, &gcValues);
    if (mbPtr->normalTextGC != NULL) {
    if (mbPtr->normalTextGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->normalTextGC);
    }
    mbPtr->normalTextGC = gc;

    gcValues.foreground = mbPtr->activeFg->pixel;
    gcValues.background = Tk_3DBorderColor(mbPtr->activeBorder)->pixel;
    mask = GCForeground | GCBackground | GCFont;
    gc = Tk_GetGC(mbPtr->tkwin, mask, &gcValues);
    if (mbPtr->activeTextGC != NULL) {
    if (mbPtr->activeTextGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->activeTextGC);
    }
    mbPtr->activeTextGC = gc;

    gcValues.background = Tk_3DBorderColor(mbPtr->normalBorder)->pixel;

    /*
     * Create the GC that can be used for stippling
     */

    if (mbPtr->stippleGC == NULL) {
    if (mbPtr->stippleGC == None) {
	gcValues.foreground = gcValues.background;
	mask = GCForeground;
	if (mbPtr->gray == None) {
	    mbPtr->gray = Tk_GetBitmap(NULL, mbPtr->tkwin, "gray50");
	}
	if (mbPtr->gray != None) {
	    gcValues.fill_style = FillStippled;
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746







-
+







    mask = GCForeground | GCBackground | GCFont;
    if (mbPtr->disabledFg != NULL) {
	gcValues.foreground = mbPtr->disabledFg->pixel;
    } else {
	gcValues.foreground = gcValues.background;
    }
    gc = Tk_GetGC(mbPtr->tkwin, mask, &gcValues);
    if (mbPtr->disabledGC != NULL) {
    if (mbPtr->disabledGC != None) {
	Tk_FreeGC(mbPtr->display, mbPtr->disabledGC);
    }
    mbPtr->disabledGC = gc;

    TkpComputeMenuButtonGeometry(mbPtr);

    /*
748
749
750
751
752
753
754
755

756
757
758

759
760
761
762
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
769
770
771
772
773
774
775

776
777
778

779
780
781
782
783
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798







-
+


-
+











-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
MenuButtonEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    TkMenuButton *mbPtr = clientData;

    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	goto redraw;
    } else if (eventPtr->type == ConfigureNotify) {
	/*
	 * Must redraw after size changes, since layout could have changed and
	 * borders will need to be redrawn.
	 */

	goto redraw;
    } else if (eventPtr->type == DestroyNotify) {
	DestroyMenuButton(mbPtr);
	DestroyMenuButton((char *) mbPtr);
    } else if (eventPtr->type == FocusIn) {
	if (eventPtr->xfocus.detail != NotifyInferior) {
	    mbPtr->flags |= GOT_FOCUS;
	    if (mbPtr->highlightWidth > 0) {
		goto redraw;
	    }
	}
808
809
810
811
812
813
814
815

816
817

818
819
820
821
822
823
824
829
830
831
832
833
834
835

836
837

838
839
840
841
842
843
844
845







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
MenuButtonCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    TkMenuButton *mbPtr = clientData;
    Tk_Window tkwin = mbPtr->tkwin;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.
843
844
845
846
847
848
849

850
851
852

853
854
855
856
857
858

859
860

861
862
863
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908


909
910
911
912
913
914
915
864
865
866
867
868
869
870
871
872
873

874
875
876
877
878
879

880
881

882


883
884
885
886
887
888
889



890


















891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906


907
908
909
910
911
912
913
914
915







+


-
+





-
+

-
+
-
-







-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















-
-
+
+







 * Side effects:
 *	The text displayed in the menu button will change to match the
 *	variable.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static char *
MenuButtonTextVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    const char *name1,		/* Name of variable. */
    const char *name2,		/* Second part of variable name. */
    int flags)			/* Information about what happened. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    register TkMenuButton *mbPtr = clientData;
    const char *value;
    size_t len;
    unsigned len;
    (void)name1;
    (void)name2;

    /*
     * If the variable is unset, then immediately recreate it unless the whole
     * interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
        if (!Tcl_InterpDeleted(interp) && mbPtr->textVarName) {
            void *probe = NULL;

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
            do {
                probe = Tcl_VarTraceInfo(interp,
                        mbPtr->textVarName,
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        MenuButtonTextVarProc, probe);
                if (probe == (void *)mbPtr) {
                    break;
                }
            } while (probe);
            if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * textVarName, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
                return NULL;
            }
	    Tcl_SetVar2(interp, mbPtr->textVarName, NULL, mbPtr->text,
		    TCL_GLOBAL_ONLY);
	    Tcl_TraceVar2(interp, mbPtr->textVarName, NULL,
		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    MenuButtonTextVarProc, clientData);
	}
	return NULL;
    }

    value = Tcl_GetVar2(interp, mbPtr->textVarName, NULL, TCL_GLOBAL_ONLY);
    if (value == NULL) {
	value = "";
    }
    if (mbPtr->text != NULL) {
	ckfree(mbPtr->text);
    }
    len = 1 + strlen(value);
    mbPtr->text = (char *)ckalloc(len);
    len = 1 + (unsigned) strlen(value);
    mbPtr->text = ckalloc(len);
    memcpy(mbPtr->text, value, len);
    TkpComputeMenuButtonGeometry(mbPtr);

    if ((mbPtr->tkwin != NULL) && Tk_IsMapped(mbPtr->tkwin)
	    && !(mbPtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
	mbPtr->flags |= REDRAW_PENDING;
933
934
935
936
937
938
939
940

941
942
943
944
945
946
947

948
949
950
951
952
953
954
955
956
957
958
959
960
933
934
935
936
937
938
939

940
941
942
943
944
945
946

947






948
949
950
951
952
953
954







-
+






-
+
-
-
-
-
-
-







 *	Arranges for the button to get redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
MenuButtonImageProc(
    void *clientData,	/* Pointer to widget record. */
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    int width, int height,	/* Dimensions of area to redisplay (may be <=
				 * 0). */
    int imgWidth, int imgHeight)/* New dimensions of image. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    register TkMenuButton *mbPtr = clientData;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
    (void)imgWidth;
    (void)imgHeight;

    if (mbPtr->tkwin != NULL) {
	TkpComputeMenuButtonGeometry(mbPtr);
	if (Tk_IsMapped(mbPtr->tkwin) && !(mbPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(TkpDisplayMenuButton, mbPtr);
	    mbPtr->flags |= REDRAW_PENDING;
	}

Changes to generic/tkMenubutton.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkMenubutton.h --
 *
 *	Declarations of types and functions used to implement the menubutton
 *	widget.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMENUBUTTON
#define _TKMENUBUTTON
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74







-
+








    /*
     * Information about what's displayed in the menu button:
     */

    char *text;			/* Text to display in button (malloc'ed) or
				 * NULL. */
    int underline;		/* Index of character to underline. INT_MIN means no underline */
    int underline;		/* Index of character to underline. */
    char *textVarName;		/* Name of variable (malloc'ed) or NULL. If
				 * non-NULL, button displays the contents of
				 * this variable. */
    Pixmap bitmap;		/* Bitmap to display or None. If not None then
				 * text and textVar and underline are
				 * ignored. */
    char *imageString;		/* Name of image to display (malloc'ed), or
157
158
159
160
161
162
163
164
165
166





167
168
169
170
171
172
173

174
175
176
177
178
179
180
157
158
159
160
161
162
163



164
165
166
167
168
169


170
171
172

173
174
175
176
177
178
179
180







-
-
-
+
+
+
+
+

-
-



-
+







     * Miscellaneous information:
     */

    int compound;		/* Value of -compound option; specifies
				 * whether the menubutton should show both an
				 * image and text, and, if so, how. */
    enum direction direction;	/* Direction for where to pop the menu. Valid
    				 * directions are "above", "below", "flush",
    				 * "left", and "right". "above" and "below"
    				 * will attempt to pop the menu completely
    				 * directions are "above", "below", "left",
    				 * "right", and "flush". "flush" means that
    				 * the upper left corner of the menubutton is
    				 * where the menu pops up. "above" and "below"
    				 * will attempt to pop the menu compleletly
    				 * above or below the menu respectively.
    				 * "flush" means that the upper left corner
    				 * of the menubutton is where the menu pops up.
    				 * "left" and "right" will pop the menu left
    				 * or right, and the active item will be next
    				 * to the button. */
    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    char *takeFocus;		/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    int flags;			/* Various flags; see below for
				 * definitions. */
} TkMenuButton;

205
206
207
208
209
210
211
212

213
214

215
216
205
206
207
208
209
210
211

212
213

214
215
216







-
+

-
+



/*
 * Declaration of procedures used in the implementation of the button widget.
 */

MODULE_SCOPE void	TkpComputeMenuButtonGeometry(TkMenuButton *mbPtr);
MODULE_SCOPE TkMenuButton *TkpCreateMenuButton(Tk_Window tkwin);
MODULE_SCOPE void	TkpDisplayMenuButton(void *clientData);
MODULE_SCOPE void	TkpDisplayMenuButton(ClientData clientData);
MODULE_SCOPE void 	TkpDestroyMenuButton(TkMenuButton *mbPtr);
MODULE_SCOPE void	TkMenuButtonWorldChanged(void *instanceData);
MODULE_SCOPE void	TkMenuButtonWorldChanged(ClientData instanceData);

#endif /* _TKMENUBUTTON */

Changes to generic/tkMessage.c.

1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17


18
19
20
21
22
23
24
1
2
3
4
5
6
7



8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24







-
-
-
+
+
+





-
-
+
+







/*
 * tkMessage.c --
 *
 *	This module implements a message widgets for the Tk toolkit. A message
 *	widget displays a multi-line string in a window according to a
 *	particular aspect ratio.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Ajuba Solutions.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Ajuba Solutions.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"

/*
 * A data structure of the following type is kept for each message widget
 * managed by this file:
 */

typedef struct {
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-
+







    Tcl_Command widgetCmd;	/* Token for message's widget command. */

    /*
     * Information used when displaying widget:
     */

    char *string;		/* String displayed in message. */
    Tcl_Size numChars;		/* Number of characters in string, not
    int numChars;		/* Number of characters in string, not
				 * including terminating NULL. */
    char *textVarName;		/* Name of variable (malloc'ed) or NULL.
				 * If non-NULL, message displays the contents
				 * of this variable. */
    Tk_3DBorder border;		/* Structure used to draw 3-D border and
				 * background. NULL means a border hasn't been
				 * created yet. */
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
82
83
84
85
86
87
88





89
90
91
92
93
94
95







-
-
-
-
-








    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    char *takeFocus;		/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    int flags;			/* Various flags; see below for
				 * definitions. */
    Tcl_Obj *borderWidthObj;		/* Width of border. */
    Tcl_Obj *highlightWidthObj;		/* Width in pixels of highlight to draw
	     * around widget when it has the focus. <= 0 means don't draw a highlight. */
    Tcl_Obj *widthObj;			/* User-requested width, in pixels. 0 means
				 * compute width using aspect ratio. */
} Message;

/*
 * Flag bits for messages:
 *
 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler
 *				has already been queued to redraw
110
111
112
113
114
115
116
117

118
119

120
121

122
123
124

125
126

127
128
129


130
131

132
133
134

135
136

137
138

139
140
141


142
143

144
145
146
147


148
149

150
151
152


153
154
155


156
157

158
159

160
161
162

163
164

165
166
167

168
169
170
171
172
173
174
175
176


177
178

179
180
181
182




183
184
185
186
187


188
189
190
191
192
193
194
105
106
107
108
109
110
111

112
113

114
115

116
117
118

119
120

121
122


123
124
125

126
127
128

129
130

131
132

133
134


135
136
137

138
139
140


141
142
143

144
145


146
147
148


149
150
151

152
153

154
155
156

157
158

159
160
161

162
163
164
165
166
167
168
169


170
171
172

173
174
175


176
177
178
179
180
181
182


183
184
185
186
187
188
189
190
191







-
+

-
+

-
+


-
+

-
+

-
-
+
+

-
+


-
+

-
+

-
+

-
-
+
+

-
+


-
-
+
+

-
+

-
-
+
+

-
-
+
+

-
+

-
+


-
+

-
+


-
+







-
-
+
+

-
+


-
-
+
+
+
+



-
-
+
+








/*
 * Information used for argv parsing.
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", DEF_MESSAGE_ANCHOR,
	 TCL_INDEX_NONE, offsetof(Message, anchor), TK_OPTION_ENUM_VAR, 0, 0},
	 -1, Tk_Offset(Message, anchor), 0, 0, 0},
    {TK_OPTION_INT, "-aspect", "aspect", "Aspect", DEF_MESSAGE_ASPECT,
	 TCL_INDEX_NONE, offsetof(Message, aspect), 0, 0, 0},
	 -1, Tk_Offset(Message, aspect), 0, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	 DEF_MESSAGE_BG_COLOR, TCL_INDEX_NONE, offsetof(Message, border), 0,
	 DEF_MESSAGE_BG_COLOR, -1, Tk_Offset(Message, border), 0,
	 DEF_MESSAGE_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL,
	 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL,
	 0, TCL_INDEX_NONE, 0, "-background", 0},
	 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	 DEF_MESSAGE_BORDER_WIDTH, offsetof(Message, borderWidthObj),
	 offsetof(Message, borderWidth), 0, 0, 0},
	 DEF_MESSAGE_BORDER_WIDTH, -1,
	 Tk_Offset(Message, borderWidth), 0, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	 DEF_MESSAGE_CURSOR, TCL_INDEX_NONE, offsetof(Message, cursor),
	 DEF_MESSAGE_CURSOR, -1, Tk_Offset(Message, cursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL,
	 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_MESSAGE_FONT, TCL_INDEX_NONE, offsetof(Message, tkfont), 0, 0, 0},
	DEF_MESSAGE_FONT, -1, Tk_Offset(Message, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_MESSAGE_FG, TCL_INDEX_NONE, offsetof(Message, fgColorPtr), 0, 0, 0},
	DEF_MESSAGE_FG, -1, Tk_Offset(Message, fgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	 "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, TCL_INDEX_NONE,
	 offsetof(Message, highlightBgColorPtr), 0, 0, 0},
	 "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, -1,
	 Tk_Offset(Message, highlightBgColorPtr), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	 DEF_MESSAGE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Message, highlightColorPtr),
	 DEF_MESSAGE_HIGHLIGHT, -1, Tk_Offset(Message, highlightColorPtr),
	 0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_MESSAGE_HIGHLIGHT_WIDTH, offsetof(Message, highlightWidthObj),
	 offsetof(Message, highlightWidth), 0, 0, 0},
	"HighlightThickness", DEF_MESSAGE_HIGHLIGHT_WIDTH, -1,
	 Tk_Offset(Message, highlightWidth), 0, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	DEF_MESSAGE_JUSTIFY, TCL_INDEX_NONE, offsetof(Message, justify), TK_OPTION_ENUM_VAR, 0, 0},
	DEF_MESSAGE_JUSTIFY, -1, Tk_Offset(Message, justify), 0, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	 DEF_MESSAGE_PADX, offsetof(Message, padXPtr),
	 offsetof(Message, padX), TK_OPTION_NULL_OK, 0, 0},
	 DEF_MESSAGE_PADX, Tk_Offset(Message, padXPtr),
	 Tk_Offset(Message, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	 DEF_MESSAGE_PADY, offsetof(Message, padYPtr),
	 offsetof(Message, padY), TK_OPTION_NULL_OK, 0, 0},
	 DEF_MESSAGE_PADY, Tk_Offset(Message, padYPtr),
	 Tk_Offset(Message, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_MESSAGE_RELIEF, TCL_INDEX_NONE, offsetof(Message, relief), 0, 0, 0},
	DEF_MESSAGE_RELIEF, -1, Tk_Offset(Message, relief), 0, 0, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_MESSAGE_TAKE_FOCUS, TCL_INDEX_NONE, offsetof(Message, takeFocus),
	DEF_MESSAGE_TAKE_FOCUS, -1, Tk_Offset(Message, takeFocus),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-text", "text", "Text",
	DEF_MESSAGE_TEXT, TCL_INDEX_NONE, offsetof(Message, string), 0, 0, 0},
	DEF_MESSAGE_TEXT, -1, Tk_Offset(Message, string), 0, 0, 0},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	DEF_MESSAGE_TEXT_VARIABLE, TCL_INDEX_NONE, offsetof(Message, textVarName),
	DEF_MESSAGE_TEXT_VARIABLE, -1, Tk_Offset(Message, textVarName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-width", "width", "Width",
	DEF_MESSAGE_WIDTH, offsetof(Message, widthObj), offsetof(Message, width), 0, 0 ,0},
	DEF_MESSAGE_WIDTH, -1, Tk_Offset(Message, width), 0, 0 ,0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 * Forward declarations for functions defined later in this file:
 */

static void		MessageCmdDeletedProc(void *clientData);
static void		MessageEventProc(void *clientData,
static void		MessageCmdDeletedProc(ClientData clientData);
static void		MessageEventProc(ClientData clientData,
			    XEvent *eventPtr);
static char *		MessageTextVarProc(void *clientData,
static char *		MessageTextVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static Tcl_ObjCmdProc MessageWidgetObjCmd;
static void		MessageWorldChanged(void *instanceData);
static int		MessageWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		MessageWorldChanged(ClientData instanceData);
static void		ComputeMessageGeometry(Message *msgPtr);
static int		ConfigureMessage(Tcl_Interp *interp, Message *msgPtr,
			    int objc, Tcl_Obj *const objv[], int flags);
static void		DestroyMessage(void *memPtr);
static void		DisplayMessage(void *clientData);
static void		DestroyMessage(char *memPtr);
static void		DisplayMessage(ClientData clientData);

/*
 * The structure below defines message class behavior by means of functions
 * that can be invoked from generic window code.
 */

static const Tk_ClassProcs messageClass = {
213
214
215
216
217
218
219
220

221
222
223
224
225

226
227
228
229
230
231
232
210
211
212
213
214
215
216

217
218
219
220
221

222
223
224
225
226
227
228
229







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_MessageObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    Message *msgPtr;
    register Message *msgPtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }
240
241
242
243
244
245
246
247
248


249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265
266

267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
237
238
239
240
241
242
243


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260
261
262

263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287







-
-
+
+













-
+



-
+






-
+









-
+







    /*
     * Create the option table for this widget class. If it has already been
     * created, the cached pointer will be returned.
     */

    optionTable = Tk_CreateOptionTable(interp, optionSpecs);

    msgPtr = (Message *)ckalloc(sizeof(Message));
    memset(msgPtr, 0, sizeof(Message));
    msgPtr = ckalloc(sizeof(Message));
    memset(msgPtr, 0, (size_t) sizeof(Message));

    /*
     * Set values for those fields that don't take a 0 or NULL value.
     */

    msgPtr->tkwin = tkwin;
    msgPtr->display = Tk_Display(tkwin);
    msgPtr->interp = interp;
    msgPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(msgPtr->tkwin), MessageWidgetObjCmd, msgPtr,
	    MessageCmdDeletedProc);
    msgPtr->optionTable = optionTable;
    msgPtr->relief = TK_RELIEF_FLAT;
    msgPtr->textGC = NULL;
    msgPtr->textGC = None;
    msgPtr->anchor = TK_ANCHOR_CENTER;
    msgPtr->aspect = 150;
    msgPtr->justify = TK_JUSTIFY_LEFT;
    msgPtr->cursor = NULL;
    msgPtr->cursor = None;

    Tk_SetClass(msgPtr->tkwin, "Message");
    Tk_SetClassProcs(msgPtr->tkwin, &messageClass, msgPtr);
    Tk_CreateEventHandler(msgPtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    MessageEventProc, msgPtr);
    if (Tk_InitOptions(interp, msgPtr, optionTable, tkwin) != TCL_OK) {
    if (Tk_InitOptions(interp, (char *)msgPtr, optionTable, tkwin) != TCL_OK) {
	Tk_DestroyWindow(msgPtr->tkwin);
	return TCL_ERROR;
    }

    if (ConfigureMessage(interp, msgPtr, objc-2, objv+2, 0) != TCL_OK) {
	Tk_DestroyWindow(msgPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(msgPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(msgPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * MessageWidgetObjCmd --
300
301
302
303
304
305
306
307

308
309
310
311
312

313
314
315
316
317
318
319
297
298
299
300
301
302
303

304
305
306
307
308

309
310
311
312
313
314
315
316







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
MessageWidgetObjCmd(
    void *clientData,	/* Information about message widget. */
    ClientData clientData,	/* Information about message widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    Message *msgPtr = (Message *)clientData;
    register Message *msgPtr = clientData;
    static const char *const optionStrings[] = { "cget", "configure", NULL };
    enum options { MESSAGE_CGET, MESSAGE_CONFIGURE };
    int index;
    int result = TCL_OK;
    Tcl_Obj *objPtr;

    if (objc < 2) {
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353







-
+











-
+








    switch ((enum options) index) {
    case MESSAGE_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	} else {
	    objPtr = Tk_GetOptionValue(interp, msgPtr,
	    objPtr = Tk_GetOptionValue(interp, (char *) msgPtr,
		    msgPtr->optionTable, objv[2], msgPtr->tkwin);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, objPtr);
		result = TCL_OK;
	    }
	}
	break;
    case MESSAGE_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, msgPtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) msgPtr,
		    msgPtr->optionTable, (objc == 3) ? objv[2] : NULL,
		    msgPtr->tkwin);
	    if (objPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, objPtr);
		result = TCL_OK;
381
382
383
384
385
386
387
388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
378
379
380
381
382
383
384

385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419







-
+

-
+













-
+










-
+







 *	Everything associated with the message is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyMessage(
    void *memPtr)		/* Info about message widget. */
    char *memPtr)		/* Info about message widget. */
{
    Message *msgPtr = (Message *) memPtr;
    register Message *msgPtr = (Message *) memPtr;

    msgPtr->flags |= MESSAGE_DELETED;

    Tcl_DeleteCommandFromToken(msgPtr->interp, msgPtr->widgetCmd);
    if (msgPtr->flags & REDRAW_PENDING) {
	Tcl_CancelIdleCall(DisplayMessage, msgPtr);
    }

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeConfigOptions handle all the standard option-related stuff.
     */

    if (msgPtr->textGC != NULL) {
    if (msgPtr->textGC != None) {
	Tk_FreeGC(msgPtr->display, msgPtr->textGC);
    }
    if (msgPtr->textLayout != NULL) {
	Tk_FreeTextLayout(msgPtr->textLayout);
    }
    if (msgPtr->textVarName != NULL) {
	Tcl_UntraceVar2(msgPtr->interp, msgPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MessageTextVarProc, msgPtr);
    }
    Tk_FreeConfigOptions(msgPtr, msgPtr->optionTable, msgPtr->tkwin);
    Tk_FreeConfigOptions((char *) msgPtr, msgPtr->optionTable, msgPtr->tkwin);
    msgPtr->tkwin = NULL;
    ckfree(msgPtr);
}

/*
 *----------------------------------------------------------------------
 *
436
437
438
439
440
441
442
443

444
445
446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
433
434
435
436
437
438
439

440
441
442
443

444
445
446
447
448
449
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+



-
+













-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureMessage(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Message *msgPtr,	/* Information about widget; may or may not
    register Message *msgPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[],	/* Arguments. */
    TCL_UNUSED(int))			/* Flags to pass to Tk_ConfigureWidget. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    Tk_SavedOptions savedOptions;

    /*
     * Eliminate any existing trace on a variable monitored by the message.
     */

    if (msgPtr->textVarName != NULL) {
	Tcl_UntraceVar2(interp, msgPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MessageTextVarProc, msgPtr);
    }

    if (Tk_SetOptions(interp, msgPtr, msgPtr->optionTable, objc, objv,
    if (Tk_SetOptions(interp, (char *) msgPtr, msgPtr->optionTable, objc, objv,
	    msgPtr->tkwin, &savedOptions, NULL) != TCL_OK) {
	Tk_RestoreSavedOptions(&savedOptions);
	return TCL_ERROR;
    }

    /*
     * If the message is to display the value of a variable, then set up a
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
474
475
476
477
478
479
480

481
482
483
484
485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501







-
+












-
+







	if (value == NULL) {
	    Tcl_SetVar2(interp, msgPtr->textVarName, NULL, msgPtr->string,
		    TCL_GLOBAL_ONLY);
	} else {
	    if (msgPtr->string != NULL) {
		ckfree(msgPtr->string);
	    }
	    msgPtr->string = strcpy((char *)ckalloc(strlen(value) + 1), value);
	    msgPtr->string = strcpy(ckalloc(strlen(value) + 1), value);
	}
	Tcl_TraceVar2(interp, msgPtr->textVarName, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		MessageTextVarProc, msgPtr);
    }

    /*
     * A few other options need special processing, such as setting the
     * background from a 3-D border or handling special defaults that couldn't
     * be specified to Tk_ConfigureWidget.
     */

    msgPtr->numChars = Tcl_NumUtfChars(msgPtr->string, TCL_INDEX_NONE);
    msgPtr->numChars = Tcl_NumUtfChars(msgPtr->string, -1);

    if (msgPtr->highlightWidth < 0) {
	msgPtr->highlightWidth = 0;
    }

    Tk_FreeSavedOptions(&savedOptions);
    MessageWorldChanged(msgPtr);
521
522
523
524
525
526
527
528

529
530
531

532
533

534
535
536
537
538
539
540
541
542

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
518
519
520
521
522
523
524

525
526
527

528
529

530
531
532
533
534
535
536
537
538

539
540
541
542
543
544
545
546




547
548
549




550
551
552
553
554
555
556







-
+


-
+

-
+








-
+







-
-
-
-



-
-
-
-







 *	Message will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
MessageWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC gc = NULL;
    GC gc = None;
    Tk_FontMetrics fm;
    Message *msgPtr = (Message *)instanceData;
    Message *msgPtr = instanceData;

    if (msgPtr->border != NULL) {
	Tk_SetBackgroundFromBorder(msgPtr->tkwin, msgPtr->border);
    }

    gcValues.font = Tk_FontId(msgPtr->tkfont);
    gcValues.foreground = msgPtr->fgColorPtr->pixel;
    gc = Tk_GetGC(msgPtr->tkwin, GCForeground | GCFont, &gcValues);
    if (msgPtr->textGC != NULL) {
    if (msgPtr->textGC != None) {
	Tk_FreeGC(msgPtr->display, msgPtr->textGC);
    }
    msgPtr->textGC = gc;

    Tk_GetFontMetrics(msgPtr->tkfont, &fm);
    if (msgPtr->padX < 0) {
	msgPtr->padX = fm.ascent / 2;
	if (msgPtr->padXPtr) {
	    Tcl_DecrRefCount(msgPtr->padXPtr);
	    msgPtr->padXPtr = NULL;
	}
    }
    if (msgPtr->padY == -1) {
	msgPtr->padY = fm.ascent / 4;
	if (msgPtr->padYPtr) {
	    Tcl_DecrRefCount(msgPtr->padYPtr);
	    msgPtr->padYPtr = NULL;
	}
    }

    /*
     * Recompute the desired geometry for the window, and arrange for the
     * window to be redisplayed.
     */

589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592







-
+







 *	desired geometry for this window.
 *
 *--------------------------------------------------------------
 */

static void
ComputeMessageGeometry(
    Message *msgPtr)	/* Information about window. */
    register Message *msgPtr)	/* Information about window. */
{
    int width, inc, height;
    int thisWidth, thisHeight, maxWidth;
    int aspect, lowerBound, upperBound, inset;

    Tk_FreeTextLayout(msgPtr->textLayout);

671
672
673
674
675
676
677
678

679
680
681


682
683
684
685
686
687
688
660
661
662
663
664
665
666

667
668


669
670
671
672
673
674
675
676
677







-
+

-
-
+
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayMessage(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    Message *msgPtr = (Message *)clientData;
    Tk_Window tkwin = msgPtr->tkwin;
    register Message *msgPtr = clientData;
    register Tk_Window tkwin = msgPtr->tkwin;
    int x, y;
    int borderWidth = msgPtr->highlightWidth;

    msgPtr->flags &= ~REDRAW_PENDING;
    if ((msgPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }
717
718
719
720
721
722
723
724

725
726
727

728
729
730
731
732
733
734
706
707
708
709
710
711
712

713
714
715

716
717
718
719
720
721
722
723







-
+


-
+







    }
    if (msgPtr->highlightWidth != 0) {
	GC fgGC, bgGC;

	bgGC = Tk_GCForColor(msgPtr->highlightBgColorPtr, Tk_WindowId(tkwin));
	if (msgPtr->flags & GOT_FOCUS) {
	    fgGC = Tk_GCForColor(msgPtr->highlightColorPtr,Tk_WindowId(tkwin));
	    Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, msgPtr->highlightWidth,
	    TkpDrawHighlightBorder(tkwin, fgGC, bgGC, msgPtr->highlightWidth,
		    Tk_WindowId(tkwin));
	} else {
	    Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, msgPtr->highlightWidth,
	    TkpDrawHighlightBorder(tkwin, bgGC, bgGC, msgPtr->highlightWidth,
		    Tk_WindowId(tkwin));
	}
    }
}

/*
 *--------------------------------------------------------------
746
747
748
749
750
751
752
753

754
755
756

757
758
759
760
761
762
763
735
736
737
738
739
740
741

742
743
744

745
746
747
748
749
750
751
752







-
+


-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
MessageEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    Message *msgPtr = (Message *)clientData;
    Message *msgPtr = clientData;

    if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0))
	    || (eventPtr->type == ConfigureNotify)) {
	goto redraw;
    } else if (eventPtr->type == DestroyNotify) {
	DestroyMessage(clientData);
    } else if (eventPtr->type == FocusIn) {
800
801
802
803
804
805
806
807

808
809

810
811
812
813
814
815
816
789
790
791
792
793
794
795

796
797

798
799
800
801
802
803
804
805







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
MessageCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    Message *msgPtr = (Message *)clientData;
    Message *msgPtr = clientData;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.
     */
833
834
835
836
837
838
839

840
841
842

843
844
845


846
847
848

849
850
851
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895


896
897
898
899
900
901
902
822
823
824
825
826
827
828
829
830
831

832
833


834
835
836
837

838
839
840
841
842
843
844
845
846



847


















848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863


864
865
866
867
868
869
870
871
872







+


-
+

-
-
+
+


-
+








-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















-
-
+
+







 *
 * Side effects:
 *	The text displayed in the message will change to match the variable.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static char *
MessageTextVarProc(
    void *clientData,	/* Information about message. */
    ClientData clientData,	/* Information about message. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),	/* Name of variable. */
    TCL_UNUSED(const char *),	/* Second part of variable name. */
    const char *name1,		/* Name of variable. */
    const char *name2,		/* Second part of variable name. */
    int flags)			/* Information about what happened. */
{
    Message *msgPtr = (Message *)clientData;
    register Message *msgPtr = clientData;
    const char *value;

    /*
     * If the variable is unset, then immediately recreate it unless the whole
     * interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
        if (!Tcl_InterpDeleted(interp) && msgPtr->textVarName) {
            void *probe = NULL;

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
            do {
                probe = Tcl_VarTraceInfo(interp,
                        msgPtr->textVarName,
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        MessageTextVarProc, probe);
                if (probe == (void *)msgPtr) {
                    break;
                }
            } while (probe);
            if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * textVarName, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
                return NULL;
            }
	    Tcl_SetVar2(interp, msgPtr->textVarName, NULL, msgPtr->string,
		    TCL_GLOBAL_ONLY);
	    Tcl_TraceVar2(interp, msgPtr->textVarName, NULL,
		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    MessageTextVarProc, clientData);
	}
	return NULL;
    }

    value = Tcl_GetVar2(interp, msgPtr->textVarName, NULL, TCL_GLOBAL_ONLY);
    if (value == NULL) {
	value = "";
    }
    if (msgPtr->string != NULL) {
	ckfree(msgPtr->string);
    }
    msgPtr->numChars = Tcl_NumUtfChars(value, TCL_INDEX_NONE);
    msgPtr->string = (char *)ckalloc(strlen(value) + 1);
    msgPtr->numChars = Tcl_NumUtfChars(value, -1);
    msgPtr->string = ckalloc(strlen(value) + 1);
    strcpy(msgPtr->string, value);
    ComputeMessageGeometry(msgPtr);

    if ((msgPtr->tkwin != NULL) && Tk_IsMapped(msgPtr->tkwin)
	    && !(msgPtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(DisplayMessage, msgPtr);
	msgPtr->flags |= REDRAW_PENDING;

Changes to generic/tkObj.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkObj.c --
 *
 *	This file contains functions that implement the common Tk object types
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"

43
44
45
46
47
48
49
50

51

52
53
54
55
56
57
58
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59







-
+

+







 * One of these structures is created per thread to store thread-specific
 * data. In this case, it is used to contain references to selected
 * Tcl_ObjTypes that we can use as screen distances without conversion. The
 * "dataKey" below is used to locate the ThreadSpecificData for the current
 * thread.
 */

typedef struct {
typedef struct ThreadSpecificData {
    const Tcl_ObjType *doubleTypePtr;
    const Tcl_ObjType *intTypePtr;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * The following structure is the internal representation for mm objects.
 */

68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
69
70
71
72
73
74
75


76
77



78
79
80
81
82
83
84







-
-
+

-
-
-







 * A WindowRep caches name-to-window lookups. The cache is invalid if tkwin is
 * NULL or if mainPtr->deletionEpoch does not match epoch.
 */

typedef struct WindowRep {
    Tk_Window tkwin;		/* Cached window; NULL if not found. */
    TkMainInfo *mainPtr;	/* MainWindow associated with tkwin. */
#if TCL_MAJOR_VERSION > 8
    size_t epoch;			/* Value of mainPtr->deletionEpoch at last
    long epoch;			/* Value of mainPtr->deletionEpoch at last
				 * successful lookup. */
#else
    long epoch;
#endif
} WindowRep;

/*
 * Prototypes for functions defined later in this file:
 */

static void		DupMMInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr);
95
96
97
98
99
100
101
102

103
104
105
106


107
108
109
110

111
112
113
114
115
116
117
118

119
120
121
122


123
124
125
126

127
128
129
130
131
132
133
134
135
136
137


138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165

166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201

202
203
204
205
206

207
208
209

210
211

212
213
214

215
216

217
218
219
220
221
222
223
92
93
94
95
96
97
98

99
100
101


102
103
104
105
106

107


108
109
110
111
112

113
114
115


116
117
118
119
120

121


122
123
124
125
126
127
128


129
130
131
132
133

134


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155

156
157
158
159
160
161
162
163




164

















165








166





167



168


169



170
171

172
173
174
175
176
177
178
179







-
+


-
-
+
+



-
+
-
-





-
+


-
-
+
+



-
+
-
-







-
-
+
+



-
+
-
-

















-
+



-
+







-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
+

-
+







static int		SetMMFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static int		SetPixelFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static int		SetWindowFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);

/*
 * The following structure defines the implementation of the "pixel" Tcl
 * object, used for measuring distances. The pixel object remembers its
 * initial display-independent settings.
 * initial display-independant settings.
 */

static const TkObjType pixelObjType = {
    {"pixel",			/* name */
static const Tcl_ObjType pixelObjType = {
    "pixel",			/* name */
    FreePixelInternalRep,	/* freeIntRepProc */
    DupPixelInternalRep,	/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    SetPixelFromAny		/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 * The following structure defines the implementation of the "pixel" Tcl
 * object, used for measuring distances. The pixel object remembers its
 * initial display-independent settings.
 * initial display-independant settings.
 */

static const TkObjType mmObjType = {
    {"mm",			/* name */
static const Tcl_ObjType mmObjType = {
    "mm",			/* name */
    FreeMMInternalRep,		/* freeIntRepProc */
    DupMMInternalRep,		/* dupIntRepProc */
    UpdateStringOfMM,		/* updateStringProc */
    NULL,			/* setFromAnyProc */
    SetMMFromAny		/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 * The following structure defines the implementation of the "window"
 * Tcl object.
 */

static const TkObjType windowObjType = {
    {"window",			/* name */
static const Tcl_ObjType windowObjType = {
    "window",			/* name */
    FreeWindowInternalRep,	/* freeIntRepProc */
    DupWindowInternalRep,	/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    SetWindowFromAny		/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *----------------------------------------------------------------------
 *
 * GetTypeCache --
 *
 *	Get (and build if necessary) the cache of useful Tcl object types for
 *	comparisons in the conversion functions.  This allows optimized checks
 *	for standard cases.
 *
 *----------------------------------------------------------------------
 */

static ThreadSpecificData *
GetTypeCache(void)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->doubleTypePtr == NULL) {
	/* Smart initialization of doubleTypePtr without
	/* Smart initialization of doubleTypePtr/intTypePtr without
	 * hash-table lookup or creating complete Tcl_Obj's */
	Tcl_Obj obj;
	obj.length = 3;
	obj.bytes = (char *)"0.0";
	obj.typePtr = NULL;
	Tcl_GetDoubleFromObj(NULL, &obj, &obj.internalRep.doubleValue);
	tsdPtr->doubleTypePtr = obj.typePtr;
    }
    return tsdPtr;
}

	obj.bytes += 2;
/*
 *----------------------------------------------------------------------
 *
 * TkGetIntForIndex --
 *
 *	Almost the same as Tcl_GetIntForIndex, but it retrieves an int. Accepts
 *	"" (empty string) as well.
 *
 * Results:
 *	The return value is a standard Tcl object result.
 *
 * Side effects:
 *	None
 *
 *----------------------------------------------------------------------
 */

	obj.length = 1;
int
TkGetIntForIndex(
    Tcl_Obj *indexObj,
    Tcl_Size end,
    int lastOK,
    Tcl_Size *indexPtr)
{
    if (indexObj == NULL) {
	obj.typePtr = NULL;
	*indexPtr = TCL_INDEX_NONE;
	return TCL_OK;
    }
    if (Tcl_GetIntForIndex(NULL, indexObj, end + lastOK, indexPtr) != TCL_OK) {
	const char *value = Tcl_GetString(indexObj);
	Tcl_GetLongFromObj(NULL, &obj, &obj.internalRep.longValue);
	if (!*value) {
	    /* empty string */
	    *indexPtr = (end == -1) ? -1 - TCL_SIZE_MAX : TCL_INDEX_NONE;
	tsdPtr->intTypePtr = obj.typePtr;
	    return TCL_OK;
	}
    }
	return TCL_ERROR;
    }
    return TCL_OK;
    return tsdPtr;
}


/*
 *----------------------------------------------------------------------
 *
 * GetPixelsFromObjEx --
 *
 *	Attempt to return a pixel value from the Tcl object "objPtr". If the
 *	object is not already a pixel value, an attempt will be made to
247
248
249
250
251
252
253







254


255

256

257
258
259
260
261






262
263
264
265
266

267
268
269
270
271
272
273
203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244







+
+
+
+
+
+
+
-
+
+

+
-
+





+
+
+
+
+
+




-
+







    int result, fresh;
    double d;
    PixelRep *pixelPtr;
    static const double bias[] = {
	1.0,	10.0,	25.4,	0.35278 /*25.4 / 72.0*/
    };

    /*
     * Special hacks where the type of the object is known to be something
     * that is just numeric and cannot require distance conversion. This pokes
     * holes in Tcl's abstractions, but they are just for optimization, not
     * semantics.
     */

    if (objPtr->typePtr != &pixelObjType.objType) {
    if (objPtr->typePtr != &pixelObjType) {
	ThreadSpecificData *typeCache = GetTypeCache();

	if (objPtr->typePtr == typeCache->doubleTypePtr) {
	if (Tcl_GetDoubleFromObj(NULL, objPtr, &d) == TCL_OK) {
	    (void) Tcl_GetDoubleFromObj(interp, objPtr, &d);
	    if (dblPtr != NULL) {
		*dblPtr = d;
	    }
	    *intPtr = (int) (d<0 ? d-0.5 : d+0.5);
	    return TCL_OK;
	} else if (objPtr->typePtr == typeCache->intTypePtr) {
	    (void) Tcl_GetIntFromObj(interp, objPtr, intPtr);
	    if (dblPtr) {
		*dblPtr = (double) (*intPtr);
	    }
	    return TCL_OK;
	}
    }

 retry:
    fresh = (objPtr->typePtr != &pixelObjType.objType);
    fresh = (objPtr->typePtr != &pixelObjType);
    if (fresh) {
	result = SetPixelFromAny(interp, objPtr);
	if (result != TCL_OK) {
	    return result;
	}
    }

366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+







    double d;
    int result, val;

    result = GetPixelsFromObjEx(interp, tkwin, objPtr, &val, &d);
    if (result != TCL_OK) {
	return result;
    }
    if (objPtr->typePtr == &pixelObjType.objType && !SIMPLE_PIXELREP(objPtr)) {
    if (objPtr->typePtr == &pixelObjType && !SIMPLE_PIXELREP(objPtr)) {
	PixelRep *pixelPtr = GET_COMPLEXPIXEL(objPtr);

	if (pixelPtr->units >= 0) {
	    /*
	     * Internally "shimmer" to pixel units.
	     */

433
434
435
436
437
438
439
440
441


442
443
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
404
405
406
407
408
409
410


411
412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429







-
-
+
+









-
+







 *	internal rep.
 *
 *----------------------------------------------------------------------
 */

static void
DupPixelInternalRep(
    Tcl_Obj *srcPtr,	/* Object with internal rep to copy. */
    Tcl_Obj *copyPtr)	/* Object with internal rep to set. */
    register Tcl_Obj *srcPtr,	/* Object with internal rep to copy. */
    register Tcl_Obj *copyPtr)	/* Object with internal rep to set. */
{
    copyPtr->typePtr = srcPtr->typePtr;

    if (SIMPLE_PIXELREP(srcPtr)) {
	SET_SIMPLEPIXEL(copyPtr, GET_SIMPLEPIXEL(srcPtr));
    } else {
	PixelRep *oldPtr, *newPtr;

	oldPtr = GET_COMPLEXPIXEL(srcPtr);
	newPtr = (PixelRep *)ckalloc(sizeof(PixelRep));
	newPtr = ckalloc(sizeof(PixelRep));
	newPtr->value = oldPtr->value;
	newPtr->units = oldPtr->units;
	newPtr->tkwin = oldPtr->tkwin;
	newPtr->returnValue = oldPtr->returnValue;
	SET_COMPLEXPIXEL(copyPtr, newPtr);
    }
}
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507

508
509

510
511
512
513
514
515
516
517


518
519
520
521
522
523
524




525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540


















541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565
566

567
568
569
570
571
572
573
574








575
576
577
578
579
580
581
448
449
450
451
452
453
454

455

456
457
458
459
460

















461
462

463








464
465







466
467
468
469
470















471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488








489
490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529







-

-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-











-
+





-
+








+
+
+
+
+
+
+
+







 */

static int
SetPixelFromAny(
    Tcl_Interp *interp,		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr)		/* The object to convert. */
{
    ThreadSpecificData *typeCache = GetTypeCache();
    const Tcl_ObjType *typePtr;
    char *string;
    const char *string;
    char *rest;
    double d;
    int i, units;

    if (objPtr->typePtr != typeCache->doubleTypePtr
	    && Tcl_GetIntFromObj(NULL, objPtr, &units) == TCL_OK) {
	d = (double) units;
	units = -1;

	/*
	 * In the case of ints, we need to ensure that a valid string exists
	 * in order for int-but-not-string objects to be converted back to
	 * ints again from pixel obj types.
	 */

	(void) Tcl_GetString(objPtr);
    } else if (Tcl_GetDoubleFromObj(NULL, objPtr, &d) == TCL_OK) {
	units = -1;
    } else {
	char savechar;
	string = Tcl_GetString(objPtr);
    string = Tcl_GetString(objPtr);

	rest = string + strlen(string);
    d = strtod(string, &rest);
	while ((rest > string) && isspace(UCHAR(rest[-1]))) {
	    --rest; /* skip all spaces at the end */
	}
	if (rest > string) {
	    --rest; /* point to the character just before the last space */
	}
	if (rest == string) {
	error:
    if (rest == string) {
	goto error;
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"expected screen distance but got \"%.50s\"", string));
		Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
	    }
	    return TCL_ERROR;
	}
    }
    while ((*rest != '\0') && isspace(UCHAR(*rest))) {
	rest++;
    }

	switch (*rest) {
	case 'm':
	    units = 0;
	    break;
	case 'c':
	    units = 1;
	    break;
	case 'i':
	    units = 2;
	    break;
	case 'p':
	    units = 3;
	    break;
	default:
	    goto error;
    switch (*rest) {
    case '\0':
	units = -1;
	break;
    case 'm':
	units = 0;
	break;
    case 'c':
	units = 1;
	break;
    case 'i':
	units = 2;
	break;
    case 'p':
	units = 3;
	break;
    default:
	goto error;
	}
	savechar = *rest;
	*rest = '\0';
	if (Tcl_GetDouble(NULL, string, &d) != TCL_OK) {
	    *rest = savechar;
	    goto error;
	}
	*rest = savechar;
    }

    /*
     * Free the old internalRep before setting the new one.
     */

    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }

    objPtr->typePtr = &pixelObjType.objType;
    objPtr->typePtr = &pixelObjType;

    i = (int) d;
    if ((units < 0) && (i == d)) {
	SET_SIMPLEPIXEL(objPtr, i);
    } else {
	PixelRep *pixelPtr = (PixelRep *)ckalloc(sizeof(PixelRep));
	PixelRep *pixelPtr = ckalloc(sizeof(PixelRep));

	pixelPtr->value = d;
	pixelPtr->units = units;
	pixelPtr->tkwin = NULL;
	pixelPtr->returnValue = i;
	SET_COMPLEXPIXEL(objPtr, pixelPtr);
    }
    return TCL_OK;

  error:
    if (interp != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad screen distance \"%.50s\"", string));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetMMFromObj --
 *
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619

620
621
622
623
624
625
626
553
554
555
556
557
558
559

560
561
562
563
564
565
566

567
568
569
570
571
572
573
574







-
+






-
+







    int result;
    double d;
    MMRep *mmPtr;
    static const double bias[] = {
	10.0,	25.4,	1.0,	0.35278 /*25.4 / 72.0*/
    };

    if (objPtr->typePtr != &mmObjType.objType) {
    if (objPtr->typePtr != &mmObjType) {
	result = SetMMFromAny(interp, objPtr);
	if (result != TCL_OK) {
	    return result;
	}
    }

    mmPtr = (MMRep *)objPtr->internalRep.twoPtrValue.ptr1;
    mmPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if (mmPtr->tkwin != tkwin) {
	d = mmPtr->value;
	if (mmPtr->units == -1) {
	    d /= WidthOfScreen(Tk_Screen(tkwin));
	    d *= WidthMMOfScreen(Tk_Screen(tkwin));
	} else {
	    d *= bias[mmPtr->units];
676
677
678
679
680
681
682
683
684


685
686
687
688
689
690


691
692
693
694
695
696
697
624
625
626
627
628
629
630


631
632
633
634
635
636


637
638
639
640
641
642
643
644
645







-
-
+
+




-
-
+
+







 *	internal rep.
 *
 *----------------------------------------------------------------------
 */

static void
DupMMInternalRep(
    Tcl_Obj *srcPtr,	/* Object with internal rep to copy. */
    Tcl_Obj *copyPtr)	/* Object with internal rep to set. */
    register Tcl_Obj *srcPtr,	/* Object with internal rep to copy. */
    register Tcl_Obj *copyPtr)	/* Object with internal rep to set. */
{
    MMRep *oldPtr, *newPtr;

    copyPtr->typePtr = srcPtr->typePtr;
    oldPtr = (MMRep *)srcPtr->internalRep.twoPtrValue.ptr1;
    newPtr = (MMRep *)ckalloc(sizeof(MMRep));
    oldPtr = srcPtr->internalRep.twoPtrValue.ptr1;
    newPtr = ckalloc(sizeof(MMRep));
    newPtr->value = oldPtr->value;
    newPtr->units = oldPtr->units;
    newPtr->tkwin = oldPtr->tkwin;
    newPtr->returnValue = oldPtr->returnValue;
    copyPtr->internalRep.twoPtrValue.ptr1 = newPtr;
}

712
713
714
715
716
717
718
719

720
721
722
723

724
725

726
727
728
729
730
731
732

733
734

735
736
737
738
739
740
741
660
661
662
663
664
665
666

667
668
669
670

671
672

673
674
675
676
677
678
679

680
681

682
683
684
685
686
687
688
689







-
+



-
+

-
+






-
+

-
+







 *	double-to-string conversion.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateStringOfMM(
    Tcl_Obj *objPtr)   /* pixel obj with string rep to update. */
    register Tcl_Obj *objPtr)   /* pixel obj with string rep to update. */
{
    MMRep *mmPtr;
    char buffer[TCL_DOUBLE_SPACE];
    size_t len;
    register int len;

    mmPtr = (MMRep *)objPtr->internalRep.twoPtrValue.ptr1;
    mmPtr = objPtr->internalRep.twoPtrValue.ptr1;
    /* assert( mmPtr->units == -1 && objPtr->bytes == NULL ); */
    if ((mmPtr->units != -1) || (objPtr->bytes != NULL)) {
	Tcl_Panic("UpdateStringOfMM: false precondition");
    }

    Tcl_PrintDouble(NULL, mmPtr->value, buffer);
    len = strlen(buffer);
    len = (int)strlen(buffer);

    objPtr->bytes = (char *)ckalloc(len + 1);
    objPtr->bytes = ckalloc(len + 1);
    strcpy(objPtr->bytes, buffer);
    objPtr->length = len;
}

/*
 *----------------------------------------------------------------------
 *
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772





773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794

795
796
797
798
799
800






801
802
803
804
805


806
807




808



809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842

843
844

845
846
847
848
849
850
851
706
707
708
709
710
711
712

713
714
715
716
717
718


719
720
721
722
723
724
725
726
727
728
729
730
731
732
733


734


735
736
737
738
739
740

741






742
743
744
745
746
747

748
749


750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776







777
778
779
780
781
782
783
784
785
786
787

788
789

790
791
792
793
794
795
796
797







-
+





-
-
+
+
+
+
+










-
-

-
-






-
+
-
-
-
-
-
-
+
+
+
+
+
+
-


-
-
+
+


+
+
+
+

+
+
+















-
-
-
-
-
-
-











-
+

-
+







static int
SetMMFromAny(
    Tcl_Interp *interp,		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr)		/* The object to convert. */
{
    ThreadSpecificData *typeCache = GetTypeCache();
    const Tcl_ObjType *typePtr;
    char *string;
    const char *string;
    char *rest;
    double d;
    int units;
    MMRep *mmPtr;

    if (objPtr->typePtr != typeCache->doubleTypePtr
	    && Tcl_GetIntFromObj(NULL, objPtr, &units) == TCL_OK) {
    if (objPtr->typePtr == typeCache->doubleTypePtr) {
	Tcl_GetDoubleFromObj(interp, objPtr, &d);
	units = -1;
    } else if (objPtr->typePtr == typeCache->intTypePtr) {
	Tcl_GetIntFromObj(interp, objPtr, &units);
	d = (double) units;
	units = -1;

	/*
	 * In the case of ints, we need to ensure that a valid string exists
	 * in order for int-but-not-string objects to be converted back to
	 * ints again from mm obj types.
	 */

	(void) Tcl_GetString(objPtr);
    } else if (Tcl_GetDoubleFromObj(NULL, objPtr, &d) == TCL_OK) {
	units = -1;
    } else {
	char savechar;

	/*
	 * It wasn't a known int or double, so parse it.
	 */

	string = Tcl_GetString(objPtr);

	rest = string + strlen(string);
	d = strtod(string, &rest);
	while ((rest > string) && isspace(UCHAR(rest[-1]))) {
	    --rest; /* skip all spaces at the end */
	}
	if (rest > string) {
	    --rest; /* point to the character just before the last space */
	}
	if (rest == string) {
	    /*
	     * Must copy string before resetting the result in case a caller
	     * is trying to convert the interpreter's result to mms.
	     */

	if (rest == string) {
	error:
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "expected screen distance but got \"%.50s\"", string));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
		    "bad screen distance \"%s\"", string));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "DISTANCE", NULL);
	    return TCL_ERROR;
	}
	while ((*rest != '\0') && isspace(UCHAR(*rest))) {
	    rest++;
	}

	switch (*rest) {
	case '\0':
	    units = -1;
	    break;
	case 'c':
	    units = 0;
	    break;
	case 'i':
	    units = 1;
	    break;
	case 'm':
	    units = 2;
	    break;
	case 'p':
	    units = 3;
	    break;
	default:
	    goto error;
	}
	savechar = *rest;
	*rest = '\0';
	if (Tcl_GetDouble(NULL, string, &d) != TCL_OK) {
	    *rest = savechar;
	    goto error;
	}
	*rest = savechar;
    }

    /*
     * Free the old internalRep before setting the new one.
     */

    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }

    objPtr->typePtr = &mmObjType.objType;
    objPtr->typePtr = &mmObjType;

    mmPtr = (MMRep *)ckalloc(sizeof(MMRep));
    mmPtr = ckalloc(sizeof(MMRep));
    mmPtr->value = d;
    mmPtr->units = units;
    mmPtr->tkwin = NULL;
    mmPtr->returnValue	= d;

    objPtr->internalRep.twoPtrValue.ptr1 = mmPtr;

877
878
879
880
881
882
883
884

885
886

887
888
889
890
891
892
893

894
895
896
897
898
899
900
823
824
825
826
827
828
829

830
831

832
833
834
835
836
837
838

839
840
841
842
843
844
845
846







-
+

-
+






-
+







TkGetWindowFromObj(
    Tcl_Interp *interp, 	/* Used for error reporting if not NULL. */
    Tk_Window tkwin,		/* A token to get the main window from. */
    Tcl_Obj *objPtr,		/* The object from which to get window. */
    Tk_Window *windowPtr)	/* Place to store resulting window. */
{
    TkMainInfo *mainPtr = ((TkWindow *) tkwin)->mainPtr;
    WindowRep *winPtr;
    register WindowRep *winPtr;

    if (objPtr->typePtr != &windowObjType.objType) {
    if (objPtr->typePtr != &windowObjType) {
	int result = SetWindowFromAny(interp, objPtr);
	if (result != TCL_OK) {
	    return result;
	}
    }

    winPtr = (WindowRep *)objPtr->internalRep.twoPtrValue.ptr1;
    winPtr = objPtr->internalRep.twoPtrValue.ptr1;
    if (winPtr->tkwin == NULL
	    || winPtr->mainPtr == NULL
	    || winPtr->mainPtr != mainPtr
	    || winPtr->epoch != mainPtr->deletionEpoch) {
	/*
	 * Cache is invalid.
	 */
932
933
934
935
936
937
938
939
940


941
942
943
944
945
946
947
948
949

950
951
952
953
954
955

956
957
958
959
960
961

962
963
964
965
966
967
968
878
879
880
881
882
883
884


885
886
887
888
889
890
891
892
893
894

895
896
897
898
899
900

901
902
903
904
905
906

907
908
909
910
911
912
913
914







-
-
+
+








-
+





-
+





-
+







 * 	TkGetWindowFromObj, which initializes the WindowRep cache.
 *
 *----------------------------------------------------------------------
 */

static int
SetWindowFromAny(
    TCL_UNUSED(Tcl_Interp *),
    Tcl_Obj *objPtr)	/* The object to convert. */
    Tcl_Interp *interp,		/* Used for error reporting if not NULL. */
    register Tcl_Obj *objPtr)	/* The object to convert. */
{
    const Tcl_ObjType *typePtr;
    WindowRep *winPtr;

    /*
     * Free the old internalRep before setting the new one.
     */

    Tcl_GetString(objPtr);
    (void)Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }

    winPtr = (WindowRep *)ckalloc(sizeof(WindowRep));
    winPtr = ckalloc(sizeof(WindowRep));
    winPtr->tkwin = NULL;
    winPtr->mainPtr = NULL;
    winPtr->epoch = 0;

    objPtr->internalRep.twoPtrValue.ptr1 = winPtr;
    objPtr->typePtr = &windowObjType.objType;
    objPtr->typePtr = &windowObjType;

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
979
980
981
982
983
984
985
986
987


988
989

990
991
992


993
994
995
996
997
998
999
925
926
927
928
929
930
931


932
933
934

935
936


937
938
939
940
941
942
943
944
945







-
-
+
+

-
+

-
-
+
+







 *	internal rep.
 *
 *----------------------------------------------------------------------
 */

static void
DupWindowInternalRep(
    Tcl_Obj *srcPtr,
    Tcl_Obj *copyPtr)
    register Tcl_Obj *srcPtr,
    register Tcl_Obj *copyPtr)
{
    WindowRep *oldPtr, *newPtr;
    register WindowRep *oldPtr, *newPtr;

    oldPtr = (WindowRep *)srcPtr->internalRep.twoPtrValue.ptr1;
    newPtr = (WindowRep *)ckalloc(sizeof(WindowRep));
    oldPtr = srcPtr->internalRep.twoPtrValue.ptr1;
    newPtr = ckalloc(sizeof(WindowRep));
    newPtr->tkwin = oldPtr->tkwin;
    newPtr->mainPtr = oldPtr->mainPtr;
    newPtr->epoch = oldPtr->epoch;
    copyPtr->internalRep.twoPtrValue.ptr1 = newPtr;
    copyPtr->typePtr = srcPtr->typePtr;
}

1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033


1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048

1049
1050

1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
969
970
971
972
973
974
975

976
977


978
979
980
981
982
983
984
985
986
987
988
989
990

991
992
993

994
995

996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007







-
+

-
-
+
+











-
+


-
+

-
+



-
+







    objPtr->internalRep.twoPtrValue.ptr1 = NULL;
    objPtr->typePtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_NewWindowObj --
 * TkNewWindowObj --
 *
 *	This function allocates a new Tcl_Obj that refers to a particular
 *	Tk window.
 *	This function allocates a new Tcl_Obj that refers to a particular to a
 *	particular Tk window.
 *
 * Results:
 *	A standard Tcl object reference, with refcount 0.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
Tk_NewWindowObj(
TkNewWindowObj(
    Tk_Window tkwin)
{
    Tcl_Obj *objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), TCL_INDEX_NONE);
    Tcl_Obj *objPtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
    TkMainInfo *mainPtr = ((TkWindow *) tkwin)->mainPtr;
    WindowRep *winPtr;
    register WindowRep *winPtr;

    SetWindowFromAny(NULL, objPtr);

    winPtr = (WindowRep *)objPtr->internalRep.twoPtrValue.ptr1;
    winPtr = objPtr->internalRep.twoPtrValue.ptr1;
    winPtr->tkwin = tkwin;
    winPtr->mainPtr = mainPtr;
    winPtr->epoch = mainPtr->deletionEpoch;
    return objPtr;
}

/*
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1032
1033
1034
1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054







-
+







-
+







    Tk_Window tkwin,		/* A window.  Needed by Tk_GetPixels() */
    Tcl_Obj *specObj,		/* The argument to "-padx", "-pady", "-ipadx",
				 * or "-ipady". The thing to be parsed. */
    int *halfPtr,		/* Write the left/top part of padding here */
    int *allPtr)		/* Write the total padding here */
{
    int firstInt, secondInt;    /* The two components of the padding */
    Tcl_Size objc;			/* The length of the list (should be 1 or 2) */
    int objc;			/* The length of the list (should be 1 or 2) */
    Tcl_Obj **objv;		/* The objects in the list */

    /*
     * Check for a common case where a single object would otherwise be
     * shimmered between a list and a pixel spec.
     */

    if (specObj->typePtr == &pixelObjType.objType) {
    if (specObj->typePtr == &pixelObjType) {
	if (Tk_GetPixelsFromObj(interp, tkwin, specObj, &firstInt) != TCL_OK){
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad pad value \"%s\": must be positive screen distance",
		    Tcl_GetString(specObj)));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "PADDING", "DIST", NULL);
	    return TCL_ERROR;
	}
1116
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1076







-
+







     */

    if (Tcl_ListObjGetElements(interp, specObj, &objc, &objv) != TCL_OK) {
	return TCL_ERROR;
    }
    if (objc != 1 && objc != 2) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"wrong number of parts to pad specification", TCL_INDEX_NONE));
		"wrong number of parts to pad specification", -1));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "PADDING", "PARTS", NULL);
	return TCL_ERROR;
    }

    /*
     * Parse the first part.
     */
1173
1174
1175
1176
1177
1178
1179
1180

1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198










1199
1200
1201
1202
1203
1204
1205
1206
1207
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132
1133
1134










1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153







-
+








-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+









 *
 *	Registers Tk's Tcl_ObjType structures with the Tcl run-time.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	All instances of Tcl_ObjType structures used in Tk are registered with
 *	All instances of Tcl_ObjType structues used in Tk are registered with
 *	Tcl.
 *
 *----------------------------------------------------------------------
 */

void
TkRegisterObjTypes(void)
{
    Tcl_RegisterObjType(&tkBorderObjType.objType);
    Tcl_RegisterObjType(&tkBitmapObjType.objType);
    Tcl_RegisterObjType(&tkColorObjType.objType);
    Tcl_RegisterObjType(&tkCursorObjType.objType);
    Tcl_RegisterObjType(&tkFontObjType.objType);
    Tcl_RegisterObjType(&mmObjType.objType);
    Tcl_RegisterObjType(&pixelObjType.objType);
    Tcl_RegisterObjType(&tkStateKeyObjType.objType);
    Tcl_RegisterObjType(&windowObjType.objType);
    Tcl_RegisterObjType(&tkTextIndexType.objType);
    Tcl_RegisterObjType(&tkBorderObjType);
    Tcl_RegisterObjType(&tkBitmapObjType);
    Tcl_RegisterObjType(&tkColorObjType);
    Tcl_RegisterObjType(&tkCursorObjType);
    Tcl_RegisterObjType(&tkFontObjType);
    Tcl_RegisterObjType(&mmObjType);
    Tcl_RegisterObjType(&pixelObjType);
    Tcl_RegisterObjType(&tkStateKeyObjType);
    Tcl_RegisterObjType(&windowObjType);
    Tcl_RegisterObjType(&tkTextIndexType);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkOldConfig.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20



21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42

43
44

45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81



82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25




26



27
28
29
30
31
32
33

34
35
36
37
38

39
40

41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75



76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106







-
-
+
+











+
+
+


-
-
-
-
+
-
-
-







-
+




-
+

-
+



-
+















-
+














-
-
-
+
+
+






-
+












-
-
+
+







/*
 * tkOldConfig.c --
 *
 *	This file contains the Tk_ConfigureWidget function. THIS FILE IS HERE
 *	FOR BACKWARD COMPATIBILITY; THE NEW CONFIGURATION PACKAGE SHOULD BE
 *	USED FOR NEW PROJECTS.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

/*
 * Values for "flags" field of Tk_ConfigSpec structures. Be sure to coordinate
 * these values with those defined in tk.h (TK_CONFIG_COLOR_ONLY, etc.) There
 * must not be overlap!
 *
 * INIT -		Non-zero means (char *) things have been converted to
 *			Tk_Uid's.
 */

#ifndef TK_CONFIG_OPTION_SPECIFIED
#  define TK_CONFIG_OPTION_SPECIFIED      (1 << 4)
#endif

#define INIT		0x20
#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Forward declarations for functions defined later in this file:
 */

static int		DoConfig(Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_ConfigSpec *specPtr, Tk_Uid value,
			    int valueIsUid, void *widgRec);
			    int valueIsUid, char *widgRec);
static Tk_ConfigSpec *	FindConfigSpec(Tcl_Interp *interp,
			    Tk_ConfigSpec *specs, const char *argvName,
			    int needFlags, int hateFlags);
static char *		FormatConfigInfo(Tcl_Interp *interp, Tk_Window tkwin,
			    const Tk_ConfigSpec *specPtr, void *widgRec);
			    const Tk_ConfigSpec *specPtr, char *widgRec);
static const char *	FormatConfigValue(Tcl_Interp *interp, Tk_Window tkwin,
			    const Tk_ConfigSpec *specPtr, void *widgRec,
			    const Tk_ConfigSpec *specPtr, char *widgRec,
			    char *buffer, Tcl_FreeProc **freeProcPtr);
static Tk_ConfigSpec *	GetCachedSpecs(Tcl_Interp *interp,
			    const Tk_ConfigSpec *staticSpecs);
static void		DeleteSpecCacheTable(void *clientData,
static void		DeleteSpecCacheTable(ClientData clientData,
			    Tcl_Interp *interp);

/*
 *--------------------------------------------------------------
 *
 * Tk_ConfigureWidget --
 *
 *	Process command-line options and database options to fill in fields of
 *	a widget record with resources and other parameters.
 *
 * Results:
 *	A standard Tcl return value. In case of an error, the interp's result
 *	will hold an error message.
 *
 * Side effects:
 *	The fields of widgRec get filled in with information from objc/objv
 *	The fields of widgRec get filled in with information from argc/argv
 *	and the option database. Old information in widgRec's fields gets
 *	recycled. A copy of the spec-table is taken with (some of) the char*
 *	fields converted into Tk_Uid fields; this copy will be released when
 *	the interpreter terminates.
 *
 *--------------------------------------------------------------
 */

int
Tk_ConfigureWidget(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Window containing widget (needed to set up
				 * X resources). */
    const Tk_ConfigSpec *specs,	/* Describes legal options. */
    Tcl_Size objc,			/* Number of elements in objv. */
    Tcl_Obj *const *objv,		/* Command-line options. */
    void *widgRec,		/* Record whose fields are to be modified.
    int argc,			/* Number of elements in argv. */
    const char **argv,		/* Command-line options. */
    char *widgRec,		/* Record whose fields are to be modified.
				 * Values must be properly initialized. */
    int flags)			/* Used to specify additional flags that must
				 * be present in config specs for them to be
				 * considered. Also, may have
				 * TK_CONFIG_ARGV_ONLY set. */
{
    Tk_ConfigSpec *specPtr, *staticSpecs;
    register Tk_ConfigSpec *specPtr, *staticSpecs;
    Tk_Uid value;		/* Value of option from database. */
    int needFlags;		/* Specs must contain this set of flags or
				 * else they are not considered. */
    int hateFlags;		/* If a spec contains any bits here, it's not
				 * considered. */

    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_SetObjResult(interp, Tcl_NewStringObj("NULL main window", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", (char *)NULL);
	Tcl_SetObjResult(interp, Tcl_NewStringObj("NULL main window", -1));
	Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", NULL);
	return TCL_ERROR;
    }

    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    if (Tk_Depth(tkwin) <= 1) {
	hateFlags = TK_CONFIG_COLOR_ONLY;
    } else {
121
122
123
124
125
126
127
128

129
130

131




132
133
134
135
136
137
138
139
140
141

142
143
144

145
146

147




148
149
150
151
152
153
154
118
119
120
121
122
123
124

125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144

145
146
147
148

149
150
151
152
153
154
155
156
157
158
159







-
+


+
-
+
+
+
+









-
+


-
+


+
-
+
+
+
+







    }

    /*
     * Pass one: scan through all of the arguments, processing those that
     * match entries in the specs.
     */

    for ( ; objc > 0; objc -= 2, objv += 2) {
    for ( ; argc > 0; argc -= 2, argv += 2) {
	const char *arg;

	if (flags & TK_CONFIG_OBJS) {
	arg = Tcl_GetString(*objv);
	    arg = Tcl_GetString((Tcl_Obj *) *argv);
	} else {
	    arg = *argv;
	}
	specPtr = FindConfigSpec(interp, staticSpecs, arg, needFlags, hateFlags);
	if (specPtr == NULL) {
	    return TCL_ERROR;
	}

	/*
	 * Process the entry.
	 */

	if (objc < 2) {
	if (argc < 2) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "value for \"%s\" missing", arg));
	    Tcl_SetErrorCode(interp, "TK", "VALUE_MISSING", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "VALUE_MISSING", NULL);
	    return TCL_ERROR;
	}
	if (flags & TK_CONFIG_OBJS) {
	arg = Tcl_GetString(objv[1]);
	    arg = Tcl_GetString((Tcl_Obj *) argv[1]);
	} else {
	    arg = argv[1];
	}
	if (DoConfig(interp, tkwin, specPtr, arg, 0, widgRec) != TCL_OK) {
	    Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
		    "\n    (processing \"%.40s\" option)",specPtr->argvName));
	    return TCL_ERROR;
	}
	if (!(flags & TK_CONFIG_ARGV_ONLY)) {
	    specPtr->specFlags |= TK_CONFIG_OPTION_SPECIFIED;
236
237
238
239
240
241
242
243
244


245
246
247
248
249
250
251
241
242
243
244
245
246
247


248
249
250
251
252
253
254
255
256







-
-
+
+







    const char *argvName,	/* Name (suitable for use in a "config"
				 * command) identifying particular option. */
    int needFlags,		/* Flags that must be present in matching
				 * entry. */
    int hateFlags)		/* Flags that must NOT be present in matching
				 * entry. */
{
    Tk_ConfigSpec *specPtr;
    char c;		/* First character of current argument. */
    register Tk_ConfigSpec *specPtr;
    register char c;		/* First character of current argument. */
    Tk_ConfigSpec *matchPtr;	/* Matching spec, or NULL. */
    size_t length;

    c = argvName[1];
    length = strlen(argvName);
    matchPtr = NULL;
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309







-
+








-
+

















-
+







	if (specPtr->argvName[length] == 0) {
	    matchPtr = specPtr;
	    goto gotMatch;
	}
	if (matchPtr != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "ambiguous option \"%s\"", argvName));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName,NULL);
	    return NULL;
	}
	matchPtr = specPtr;
    }

    if (matchPtr == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"unknown option \"%s\"", argvName));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, NULL);
	return NULL;
    }

    /*
     * Found a matching entry. If it's a synonym, then find the entry that
     * it's a synonym for.
     */

  gotMatch:
    specPtr = matchPtr;
    if (specPtr->type == TK_CONFIG_SYNONYM) {
	for (specPtr = specs; ; specPtr++) {
	    if (specPtr->type == TK_CONFIG_END) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"couldn't find synonym for option \"%s\"",
			argvName));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName,
			(char *)NULL);
			NULL);
		return NULL;
	    }
	    if ((specPtr->dbName == matchPtr->dbName)
		    && (specPtr->type != TK_CONFIG_SYNONYM)
		    && ((specPtr->specFlags & needFlags) == needFlags)
		    && !(specPtr->specFlags & hateFlags)) {
		break;
331
332
333
334
335
336
337
338

339
340
341

342
343
344
345
346

347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
336
337
338
339
340
341
342

343
344
345

346
347
348
349
350

351
352
353
354
355




356
357
358
359
360
361
362
363







-
+


-
+




-
+




-
-
-
-
+







    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Window containing widget (needed to set up
				 * X resources). */
    Tk_ConfigSpec *specPtr,	/* Specifier to apply. */
    Tk_Uid value,		/* Value to use to fill in widgRec. */
    int valueIsUid,		/* Non-zero means value is a Tk_Uid; zero
				 * means it's an ordinary string. */
    void *widgRec)		/* Record whose fields are to be modified.
    char *widgRec)		/* Record whose fields are to be modified.
				 * Values must be properly initialized. */
{
    void *ptr;
    char *ptr;
    Tk_Uid uid;
    int nullValue;

    nullValue = 0;
    if ((*value == 0) && (specPtr->specFlags & (TK_CONFIG_NULL_OK|TCL_NULL_OK))) {
    if ((*value == 0) && (specPtr->specFlags & TK_CONFIG_NULL_OK)) {
	nullValue = 1;
    }

    do {
	if (specPtr->offset < 0) {
	    break;
	}
	ptr = (char *)widgRec + specPtr->offset;
	ptr = widgRec + specPtr->offset;
	switch (specPtr->type) {
	case TK_CONFIG_BOOLEAN:
	    if (Tcl_GetBoolean(interp, value, (int *) ptr) != TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	case TK_CONFIG_INT:
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+







	    break;
	case TK_CONFIG_STRING: {
	    char *oldStr, *newStr;

	    if (nullValue) {
		newStr = NULL;
	    } else {
		newStr = (char *)ckalloc(strlen(value) + 1);
		newStr = ckalloc(strlen(value) + 1);
		strcpy(newStr, value);
	    }
	    oldStr = *((char **) ptr);
	    if (oldStr != NULL) {
		ckfree(oldStr);
	    }
	    *((char **) ptr) = newStr;
471
472
473
474
475
476
477
478

479
480
481
482

483
484
485
486
487

488
489
490
491
492
493
494
473
474
475
476
477
478
479

480
481
482
483

484
485
486
487
488

489
490
491
492
493
494
495
496







-
+



-
+




-
+







	    }
	    break;
	case TK_CONFIG_CURSOR:
	case TK_CONFIG_ACTIVE_CURSOR: {
	    Tk_Cursor newCursor, oldCursor;

	    if (nullValue) {
		newCursor = NULL;
		newCursor = None;
	    } else {
		uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
		newCursor = Tk_GetCursor(interp, tkwin, uid);
		if (newCursor == NULL) {
		if (newCursor == None) {
		    return TCL_ERROR;
		}
	    }
	    oldCursor = *((Tk_Cursor *) ptr);
	    if (oldCursor != NULL) {
	    if (oldCursor != None) {
		Tk_FreeCursor(Tk_Display(tkwin), oldCursor);
	    }
	    *((Tk_Cursor *) ptr) = newCursor;
	    if (specPtr->type == TK_CONFIG_ACTIVE_CURSOR) {
		Tk_DefineCursor(tkwin, newCursor);
	    }
	    break;
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554

555
556
557
558
559
560
561
542
543
544
545
546
547
548

549
550
551
552
553
554
555

556
557
558
559
560
561
562
563







-
+






-
+







		}
	    }
	    *((Tk_Window *) ptr) = tkwin2;
	    break;
	}
	case TK_CONFIG_CUSTOM:
	    if (specPtr->customPtr->parseProc(specPtr->customPtr->clientData,
		    interp, tkwin, value, (char *)widgRec, specPtr->offset)!=TCL_OK) {
		    interp, tkwin, value, widgRec, specPtr->offset)!=TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	default:
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad config table: unknown type %d", specPtr->type));
	    Tcl_SetErrorCode(interp, "TK", "BAD_CONFIG", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "BAD_CONFIG", NULL);
	    return TCL_ERROR;
	}
	specPtr++;
    } while ((specPtr->argvName == NULL) && (specPtr->type != TK_CONFIG_END));
    return TCL_OK;
}

588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603
604

605
606
607
608
609
610
611
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605

606
607
608
609
610
611
612
613







-
+








-
+







 */

int
Tk_ConfigureInfo(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Window corresponding to widgRec. */
    const Tk_ConfigSpec *specs, /* Describes legal options. */
    void *widgRec,		/* Record whose fields contain current values
    char *widgRec,		/* Record whose fields contain current values
				 * for options. */
    const char *argvName,	/* If non-NULL, indicates a single option
				 * whose info is to be returned. Otherwise
				 * info is returned for all options. */
    int flags)			/* Used to specify additional flags that must
				 * be present in config specs for them to be
				 * considered. */
{
    Tk_ConfigSpec *specPtr, *staticSpecs;
    register Tk_ConfigSpec *specPtr, *staticSpecs;
    int needFlags, hateFlags;
    char *list;
    const char *leader = "{";

    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    if (Tk_Depth(tkwin) <= 1) {
	hateFlags = TK_CONFIG_COLOR_ONLY;
628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653

654
655
656
657

658
659
660
661
662
663
664
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654

655
656
657
658

659
660
661
662
663
664
665
666







-
+

















-
+



-
+







    if (argvName != NULL) {
	specPtr = FindConfigSpec(interp, staticSpecs, argvName, needFlags,
		hateFlags);
	if (specPtr == NULL) {
	    return TCL_ERROR;
	}
	list = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
	Tcl_SetObjResult(interp, Tcl_NewStringObj(list, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(list, -1));
	ckfree(list);
	return TCL_OK;
    }

    /*
     * Loop through all the specs, creating a big list with all their
     * information.
     */

    for (specPtr = staticSpecs; specPtr->type != TK_CONFIG_END; specPtr++) {
	if ((argvName != NULL) && (specPtr->argvName != argvName)) {
	    continue;
	}
	if (((specPtr->specFlags & needFlags) != needFlags)
		|| (specPtr->specFlags & hateFlags)) {
	    continue;
	}
	if ((specPtr->argvName == NULL) || (specPtr->offset < 0)) {
	if (specPtr->argvName == NULL) {
	    continue;
	}
	list = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
	Tcl_AppendResult(interp, leader, list, "}", (char *)NULL);
	Tcl_AppendResult(interp, leader, list, "}", NULL);
	ckfree(list);
	leader = " {";
    }
    return TCL_OK;
}

/*
680
681
682
683
684
685
686
687

688
689
690

691
692
693
694
695
696
697
682
683
684
685
686
687
688

689
690
691

692
693
694
695
696
697
698
699







-
+


-
+







 */

static char *
FormatConfigInfo(
    Tcl_Interp *interp,		/* Interpreter to use for things like
				 * floating-point precision. */
    Tk_Window tkwin,		/* Window corresponding to widget. */
    const Tk_ConfigSpec *specPtr,
    register const Tk_ConfigSpec *specPtr,
				/* Pointer to information describing
				 * option. */
    void *widgRec)		/* Pointer to record holding current values of
    char *widgRec)		/* Pointer to record holding current values of
				 * info for widget. */
{
    const char *argv[6];
    char *result;
    char buffer[200];
    Tcl_FreeProc *freeProc = NULL;

714
715
716
717
718
719
720
721
722


723
724

725
726
727
728
729
730
731
716
717
718
719
720
721
722


723
724
725

726
727
728
729
730
731
732
733







-
-
+
+

-
+







	argv[3] = "";
    }
    if (argv[4] == NULL) {
	argv[4] = "";
    }
    result = Tcl_Merge(5, argv);
    if (freeProc != NULL) {
	if (freeProc == TCL_DYNAMIC) {
	    ckfree((char *)argv[4]);
	if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
	    ckfree((char *) argv[4]);
	} else {
	    freeProc((char *)argv[4]);
	    freeProc((char *) argv[4]);
	}
    }
    return result;
}

/*
 *----------------------------------------------------------------------
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765

766
767
768
769
770
771

772
773
774
775

776
777
778
779
780
781
782

783
784
785
786

787
788
789
790

791
792
793
794
795
796

797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
820

821
822
823
824
825
826
827
828

829
830
831
832
833
834
835
836

837
838
839
840

841
842

843
844
845
846
847
848

849
850
851

852
853
854

855
856
857

858
859
860

861
862
863
864

865
866
867


868

869
870
871
872
873
874
875
876

877
878
879
880
881
882
883
751
752
753
754
755
756
757

758
759
760
761
762
763
764
765


766
767
768




769
770
771
772

773
774
775
776
777
778
779

780
781
782
783

784
785
786
787

788
789
790
791
792
793

794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
809

810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825

826
827
828
829
830
831
832
833

834
835
836
837

838
839

840
841
842
843
844
845

846
847
848

849
850
851

852
853
854

855
856
857

858
859
860
861

862
863
864
865
866
867

868
869
870
871
872
873
874
875

876
877
878
879
880
881
882
883







-
+







-
-
+


-
-
-
-
+



-
+






-
+



-
+



-
+





-
+







-
+







-
+







-
+







-
+







-
+



-
+

-
+





-
+


-
+


-
+


-
+


-
+



-
+



+
+
-
+







-
+








static const char *
FormatConfigValue(
    Tcl_Interp *interp,		/* Interpreter for use in real conversions. */
    Tk_Window tkwin,		/* Window corresponding to widget. */
    const Tk_ConfigSpec *specPtr, /* Pointer to information describing option.
				 * Must not point to a synonym option. */
    void *widgRec,		/* Pointer to record holding current values of
    char *widgRec,		/* Pointer to record holding current values of
				 * info for widget. */
    char *buffer,		/* Static buffer to use for small values.
				 * Must have at least 200 bytes of storage. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to word to fill in with address of
				 * function to free the result, or NULL if
				 * result is static. */
{
    void *ptr;
    const char *result;
    const char *ptr, *result;

    *freeProcPtr = NULL;
    if (specPtr->offset < 0) {
	return NULL;
    }
    ptr = (char *)widgRec + specPtr->offset;
    ptr = widgRec + specPtr->offset;
    result = "";
    switch (specPtr->type) {
    case TK_CONFIG_BOOLEAN:
	if (*((int *)ptr) == 0) {
	if (*((int *) ptr) == 0) {
	    result = "0";
	} else {
	    result = "1";
	}
	break;
    case TK_CONFIG_INT:
	snprintf(buffer, 200, "%d", *((int *)ptr));
	sprintf(buffer, "%d", *((int *) ptr));
	result = buffer;
	break;
    case TK_CONFIG_DOUBLE:
	Tcl_PrintDouble(interp, *((double *)ptr), buffer);
	Tcl_PrintDouble(interp, *((double *) ptr), buffer);
	result = buffer;
	break;
    case TK_CONFIG_STRING:
	result = (*(char **)ptr);
	result = (*(char **) ptr);
	if (result == NULL) {
	    result = "";
	}
	break;
    case TK_CONFIG_UID: {
	Tk_Uid uid = *((Tk_Uid *)ptr);
	Tk_Uid uid = *((Tk_Uid *) ptr);

	if (uid != NULL) {
	    result = uid;
	}
	break;
    }
    case TK_CONFIG_COLOR: {
	XColor *colorPtr = *((XColor **)ptr);
	XColor *colorPtr = *((XColor **) ptr);

	if (colorPtr != NULL) {
	    result = Tk_NameOfColor(colorPtr);
	}
	break;
    }
    case TK_CONFIG_FONT: {
	Tk_Font tkfont = *((Tk_Font *)ptr);
	Tk_Font tkfont = *((Tk_Font *) ptr);

	if (tkfont != NULL) {
	    result = Tk_NameOfFont(tkfont);
	}
	break;
    }
    case TK_CONFIG_BITMAP: {
	Pixmap pixmap = *((Pixmap *)ptr);
	Pixmap pixmap = *((Pixmap *) ptr);

	if (pixmap != None) {
	    result = Tk_NameOfBitmap(Tk_Display(tkwin), pixmap);
	}
	break;
    }
    case TK_CONFIG_BORDER: {
	Tk_3DBorder border = *((Tk_3DBorder *)ptr);
	Tk_3DBorder border = *((Tk_3DBorder *) ptr);

	if (border != NULL) {
	    result = Tk_NameOf3DBorder(border);
	}
	break;
    }
    case TK_CONFIG_RELIEF:
	result = Tk_NameOfRelief(*((int *)ptr));
	result = Tk_NameOfRelief(*((int *) ptr));
	break;
    case TK_CONFIG_CURSOR:
    case TK_CONFIG_ACTIVE_CURSOR: {
	Tk_Cursor cursor = *((Tk_Cursor *)ptr);
	Tk_Cursor cursor = *((Tk_Cursor *) ptr);

	if (cursor != NULL) {
	if (cursor != None) {
	    result = Tk_NameOfCursor(Tk_Display(tkwin), cursor);
	}
	break;
    }
    case TK_CONFIG_JUSTIFY:
	result = Tk_NameOfJustify(*((Tk_Justify *)ptr));
	result = Tk_NameOfJustify(*((Tk_Justify *) ptr));
	break;
    case TK_CONFIG_ANCHOR:
	result = Tk_NameOfAnchor(*((Tk_Anchor *)ptr));
	result = Tk_NameOfAnchor(*((Tk_Anchor *) ptr));
	break;
    case TK_CONFIG_CAP_STYLE:
	result = Tk_NameOfCapStyle(*((int *)ptr));
	result = Tk_NameOfCapStyle(*((int *) ptr));
	break;
    case TK_CONFIG_JOIN_STYLE:
	result = Tk_NameOfJoinStyle(*((int *)ptr));
	result = Tk_NameOfJoinStyle(*((int *) ptr));
	break;
    case TK_CONFIG_PIXELS:
	snprintf(buffer, 200, "%d", *((int *)ptr));
	sprintf(buffer, "%d", *((int *) ptr));
	result = buffer;
	break;
    case TK_CONFIG_MM:
	Tcl_PrintDouble(interp, *((double *)ptr), buffer);
	Tcl_PrintDouble(interp, *((double *) ptr), buffer);
	result = buffer;
	break;
    case TK_CONFIG_WINDOW: {
	Tk_Window tkwin;

	tkwin = *((Tk_Window *)ptr);
	tkwin = *((Tk_Window *) ptr);
	if (tkwin != NULL) {
	    result = Tk_PathName(tkwin);
	}
	break;
    }
    case TK_CONFIG_CUSTOM:
	result = specPtr->customPtr->printProc(specPtr->customPtr->clientData,
		tkwin, (char *)widgRec, specPtr->offset, freeProcPtr);
		tkwin, widgRec, specPtr->offset, freeProcPtr);
	break;
    default:
	result = "?? unknown type ??";
    }
    return result;
}

902
903
904
905
906
907
908
909

910
911
912
913
914
915
916
902
903
904
905
906
907
908

909
910
911
912
913
914
915
916







-
+







 */

int
Tk_ConfigureValue(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Window corresponding to widgRec. */
    const Tk_ConfigSpec *specs, /* Describes legal options. */
    void *widgRec,		/* Record whose fields contain current values
    char *widgRec,		/* Record whose fields contain current values
				 * for options. */
    const char *argvName,	/* Gives the command-line name for the option
				 * whose value is to be returned. */
    int flags)			/* Used to specify additional flags that must
				 * be present in config specs for them to be
				 * considered. */
{
935
936
937
938
939
940
941
942

943
944
945


946
947

948
949
950
951
952
953
954
935
936
937
938
939
940
941

942
943


944
945
946

947
948
949
950
951
952
953
954







-
+

-
-
+
+

-
+








    specPtr = FindConfigSpec(interp, specPtr, argvName, needFlags, hateFlags);
    if (specPtr == NULL) {
	return TCL_ERROR;
    }
    result = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer,
	    &freeProc);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(result, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(result, -1));
    if (freeProc != NULL) {
	if (freeProc == TCL_DYNAMIC) {
	    ckfree((char *)result);
	if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
	    ckfree((char *) result);
	} else {
	    freeProc((char *)result);
	    freeProc((char *) result);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
967
968
969
970
971
972
973

974
975
976
977

978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
967
968
969
970
971
972
973
974
975
976
977

978
979
980
981
982
983
984
985

986
987
988
989
990
991
992




993
994
995
996
997
998
999
1000







+



-
+







-
+






-
-
-
-
+







 * Notes:
 *	Since this is not looking anything up, this uses the static version of
 *	the config specs.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
void
Tk_FreeOptions(
    const Tk_ConfigSpec *specs,	/* Describes legal options. */
    void *widgRec,		/* Record whose fields contain current values
    char *widgRec,		/* Record whose fields contain current values
				 * for options. */
    Display *display,		/* X display; needed for freeing some
				 * resources. */
    int needFlags)		/* Used to specify additional flags that must
				 * be present in config specs for them to be
				 * considered. */
{
    const Tk_ConfigSpec *specPtr;
    register const Tk_ConfigSpec *specPtr;
    char *ptr;

    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
	if ((specPtr->specFlags & needFlags) != needFlags) {
	    continue;
	}
	if (specPtr->offset < 0) {
	    continue;
	}
	ptr = (char *)widgRec + specPtr->offset;
	ptr = widgRec + specPtr->offset;
	switch (specPtr->type) {
	case TK_CONFIG_STRING:
	    if (*((char **) ptr) != NULL) {
		ckfree(*((char **) ptr));
		*((char **) ptr) = NULL;
	    }
	    break;
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029

1030
1031
1032
1033
1034
1035
1036
1018
1019
1020
1021
1022
1023
1024

1025
1026

1027
1028
1029
1030
1031
1032
1033
1034







-
+

-
+







	    if (*((Tk_3DBorder *) ptr) != NULL) {
		Tk_Free3DBorder(*((Tk_3DBorder *) ptr));
		*((Tk_3DBorder *) ptr) = NULL;
	    }
	    break;
	case TK_CONFIG_CURSOR:
	case TK_CONFIG_ACTIVE_CURSOR:
	    if (*((Tk_Cursor *) ptr) != NULL) {
	    if (*((Tk_Cursor *) ptr) != None) {
		Tk_FreeCursor(display, *((Tk_Cursor *) ptr));
		*((Tk_Cursor *) ptr) = NULL;
		*((Tk_Cursor *) ptr) = None;
	    }
	}
    }
}

/*
 *--------------------------------------------------------------
1069
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112

1113
1114
1115
1116
1117
1118
1119
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117







-
+


-
+













-
+















-
+


-
+








    /*
     * Get (or allocate if it doesn't exist) the hash table that the writable
     * copies of the widget specs are stored in. In effect, this is
     * self-initializing code.
     */

    specCacheTablePtr = (Tcl_HashTable *)
    specCacheTablePtr =
	    Tcl_GetAssocData(interp, "tkConfigSpec.threadTable", NULL);
    if (specCacheTablePtr == NULL) {
	specCacheTablePtr = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
	specCacheTablePtr = ckalloc(sizeof(Tcl_HashTable));
	Tcl_InitHashTable(specCacheTablePtr, TCL_ONE_WORD_KEYS);
	Tcl_SetAssocData(interp, "tkConfigSpec.threadTable",
		DeleteSpecCacheTable, specCacheTablePtr);
    }

    /*
     * Look up or create the hash entry that the constant specs are mapped to,
     * which will have the writable specs as its associated value.
     */

    entryPtr = Tcl_CreateHashEntry(specCacheTablePtr, (char *) staticSpecs,
	    &isNew);
    if (isNew) {
	size_t entrySpace = sizeof(Tk_ConfigSpec);
	unsigned int entrySpace = sizeof(Tk_ConfigSpec);
	const Tk_ConfigSpec *staticSpecPtr;
	Tk_ConfigSpec *specPtr;

	/*
	 * OK, no working copy in this interpreter so copy. Need to work out
	 * how much space to allocate first.
	 */

	for (staticSpecPtr=staticSpecs; staticSpecPtr->type!=TK_CONFIG_END;
		staticSpecPtr++) {
	    entrySpace += sizeof(Tk_ConfigSpec);
	}

	/*
	 * Now allocate our working copy's space and copy over the contents
	 * from the origin.
	 * from the master copy.
	 */

	cachedSpecs = (Tk_ConfigSpec *)ckalloc(entrySpace);
	cachedSpecs = ckalloc(entrySpace);
	memcpy(cachedSpecs, staticSpecs, entrySpace);
	Tcl_SetHashValue(entryPtr, cachedSpecs);

	/*
	 * Finally, go through and replace database names, database classes
	 * and default values with Tk_Uids. This is the bit that has to be
	 * per-thread.
1129
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1141







-
+







		}
		if (specPtr->defValue != NULL) {
		    specPtr->defValue = Tk_GetUid(specPtr->defValue);
		}
	    }
	}
    } else {
	cachedSpecs = (Tk_ConfigSpec *)Tcl_GetHashValue(entryPtr);
	cachedSpecs = Tcl_GetHashValue(entryPtr);
    }

    return cachedSpecs;
}

/*
 *--------------------------------------------------------------
1154
1155
1156
1157
1158
1159
1160
1161
1162


1163
1164

1165
1166
1167
1168
1169
1170
1171
1152
1153
1154
1155
1156
1157
1158


1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169







-
-
+
+

-
+







 *	None (does *not* use any Tk API).
 *
 *--------------------------------------------------------------
 */

static void
DeleteSpecCacheTable(
    void *clientData,
    TCL_UNUSED(Tcl_Interp *))
    ClientData clientData,
    Tcl_Interp *interp)
{
    Tcl_HashTable *tablePtr = (Tcl_HashTable *)clientData;
    Tcl_HashTable *tablePtr = clientData;
    Tcl_HashEntry *entryPtr;
    Tcl_HashSearch search;

    for (entryPtr = Tcl_FirstHashEntry(tablePtr,&search); entryPtr != NULL;
	    entryPtr = Tcl_NextHashEntry(&search)) {
	/*
	 * Someone else deallocates the Tk_Uids themselves.

Added generic/tkOldTest.c.



























































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * tkOldTest.c --
 *
 *	This file contains C command functions for additional Tcl
 *	commands that are used to test Tk's support for legacy
 *	interfaces.  These commands are not normally included in Tcl/Tk
 *	applications; they're only used for testing.
 *
 * Copyright (c) 1993-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 * Contributions by Don Porter, NIST, 2007.  (not subject to US copyright)
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#define USE_OLD_IMAGE
#ifndef USE_TCL_STUBS
#   define USE_TCL_STUBS
#endif
#ifndef USE_TK_STUBS
#   define USE_TK_STUBS
#endif
#include "tkInt.h"

/*
 * The following data structure represents the master for a test image:
 */

typedef struct TImageMaster {
    Tk_ImageMaster master;      /* Tk's token for image master. */
    Tcl_Interp *interp;         /* Interpreter for application. */
    int width, height;          /* Dimensions of image. */
    char *imageName;            /* Name of image (malloc-ed). */
    char *varName;              /* Name of variable in which to log events for
                                 * image (malloc-ed). */
} TImageMaster;

/*
 * The following data structure represents a particular use of a particular
 * test image.
 */

typedef struct TImageInstance {
    TImageMaster *masterPtr;    /* Pointer to master for image. */
    XColor *fg;                 /* Foreground color for drawing in image. */
    GC gc;                      /* Graphics context for drawing in image. */
} TImageInstance;

/*
 * The type record for test images:
 */

static int		ImageCreate(Tcl_Interp *interp,
			    char *name, int argc, char **argv,
			    Tk_ImageType *typePtr, Tk_ImageMaster master,
			    ClientData *clientDataPtr);
static ClientData	ImageGet(Tk_Window tkwin, ClientData clientData);
static void		ImageDisplay(ClientData clientData,
			    Display *display, Drawable drawable,
			    int imageX, int imageY, int width,
			    int height, int drawableX,
			    int drawableY);
static void		ImageFree(ClientData clientData, Display *display);
static void		ImageDelete(ClientData clientData);

static Tk_ImageType imageType = {
    "oldtest",			/* name */
    (Tk_ImageCreateProc *) ImageCreate, /* createProc */
    ImageGet,			/* getProc */
    ImageDisplay,		/* displayProc */
    ImageFree,			/* freeProc */
    ImageDelete,		/* deleteProc */
    NULL,			/* postscriptPtr */
    NULL,			/* nextPtr */
    NULL
};

/*
 * Forward declarations for functions defined later in this file:
 */

static int              ImageObjCmd(ClientData dummy,
                            Tcl_Interp *interp, int objc,
            			    Tcl_Obj * const objv[]);


/*
 *----------------------------------------------------------------------
 *
 * TkOldTestInit --
 *
 *	This function performs intialization for the Tk test suite
 *	extensions for testing support for legacy interfaces.
 *
 * Results:
 *	Returns a standard Tcl completion code, and leaves an error message in
 *	the interp's result if an error occurs.
 *
 * Side effects:
 *	Creates several test commands.
 *
 *----------------------------------------------------------------------
 */

int
TkOldTestInit(
    Tcl_Interp *interp)
{
    static int initialized = 0;

    if (!initialized) {
	initialized = 1;
	Tk_CreateImageType(&imageType);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageCreate --
 *
 *	This function is called by the Tk image code to create "oldtest" images.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	The data structure for a new image is allocated.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ImageCreate(
    Tcl_Interp *interp,		/* Interpreter for application containing
				 * image. */
    char *name,			/* Name to use for image. */
    int argc,			/* Number of arguments. */
    char **argv,		/* Argument strings for options (doesn't
				 * include image name or type). */
    Tk_ImageType *typePtr,	/* Pointer to our type record (not used). */
    Tk_ImageMaster master,	/* Token for image, to be used by us in later
				 * callbacks. */
    ClientData *clientDataPtr)	/* Store manager's token for image here; it
				 * will be returned in later callbacks. */
{
    TImageMaster *timPtr;
    const char *varName;
    int i;

    varName = "log";
    for (i = 0; i < argc; i += 2) {
	if (strcmp(argv[i], "-variable") != 0) {
	    Tcl_AppendResult(interp, "bad option name \"",
		    argv[i], "\"", NULL);
	    return TCL_ERROR;
	}
	if ((i+1) == argc) {
	    Tcl_AppendResult(interp, "no value given for \"",
		    argv[i], "\" option", NULL);
	    return TCL_ERROR;
	}
	varName = argv[i+1];
    }

    timPtr = ckalloc(sizeof(TImageMaster));
    timPtr->master = master;
    timPtr->interp = interp;
    timPtr->width = 30;
    timPtr->height = 15;
    timPtr->imageName = ckalloc((unsigned) (strlen(name) + 1));
    strcpy(timPtr->imageName, name);
    timPtr->varName = ckalloc((unsigned) (strlen(varName) + 1));
    strcpy(timPtr->varName, varName);
    Tcl_CreateObjCommand(interp, name, ImageObjCmd, timPtr, NULL);
    *clientDataPtr = timPtr;
    Tk_ImageChanged(master, 0, 0, 30, 15, 30, 15);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageObjCmd --
 *
 *	This function implements the commands corresponding to individual
 *	images.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	Forces windows to be created.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ImageObjCmd(
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    TImageMaster *timPtr = clientData;
    int x, y, width, height;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (strcmp(Tcl_GetString(objv[1]), "changed") == 0) {
	if (objc != 8) {
	    Tcl_WrongNumArgs(interp, 1, objv, "changed x y width height"
		    " imageWidth imageHeight");
	    return TCL_ERROR;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &width) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &height) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &timPtr->width) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[7], &timPtr->height) != TCL_OK)) {
	    return TCL_ERROR;
	}
	Tk_ImageChanged(timPtr->master, x, y, width, height, timPtr->width,
		timPtr->height);
    } else {
	Tcl_AppendResult(interp, "bad option \"", Tcl_GetString(objv[1]),
		"\": must be changed", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageGet --
 *
 *	This function is called by Tk to set things up for using a test image
 *	in a particular widget.
 *
 * Results:
 *	The return value is a token for the image instance, which is used in
 *	future callbacks to ImageDisplay and ImageFree.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static ClientData
ImageGet(
    Tk_Window tkwin,		/* Token for window in which image will be
				 * used. */
    ClientData clientData)	/* Pointer to TImageMaster for image. */
{
    TImageMaster *timPtr = clientData;
    TImageInstance *instPtr;
    char buffer[100];
    XGCValues gcValues;

    sprintf(buffer, "%s get", timPtr->imageName);
    Tcl_SetVar2(timPtr->interp, timPtr->varName, NULL, buffer,
	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);

    instPtr = ckalloc(sizeof(TImageInstance));
    instPtr->masterPtr = timPtr;
    instPtr->fg = Tk_GetColor(timPtr->interp, tkwin, "#ff0000");
    gcValues.foreground = instPtr->fg->pixel;
    instPtr->gc = Tk_GetGC(tkwin, GCForeground, &gcValues);
    return instPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageDisplay --
 *
 *	This function is invoked to redisplay part or all of an image in a
 *	given drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The image gets partially redrawn, as an "X" that shows the exact
 *	redraw area.
 *
 *----------------------------------------------------------------------
 */

static void
ImageDisplay(
    ClientData clientData,	/* Pointer to TImageInstance for image. */
    Display *display,		/* Display to use for drawing. */
    Drawable drawable,		/* Where to redraw image. */
    int imageX, int imageY,	/* Origin of area to redraw, relative to
				 * origin of image. */
    int width, int height,	/* Dimensions of area to redraw. */
    int drawableX, int drawableY)
				/* Coordinates in drawable corresponding to
				 * imageX and imageY. */
{
    TImageInstance *instPtr = clientData;
    char buffer[200 + TCL_INTEGER_SPACE * 6];

    sprintf(buffer, "%s display %d %d %d %d %d %d",
	    instPtr->masterPtr->imageName, imageX, imageY, width, height,
	    drawableX, drawableY);
    Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName, NULL,
	    buffer, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
    if (width > (instPtr->masterPtr->width - imageX)) {
	width = instPtr->masterPtr->width - imageX;
    }
    if (height > (instPtr->masterPtr->height - imageY)) {
	height = instPtr->masterPtr->height - imageY;
    }
    XDrawRectangle(display, drawable, instPtr->gc, drawableX, drawableY,
	    (unsigned) (width-1), (unsigned) (height-1));
    XDrawLine(display, drawable, instPtr->gc, drawableX, drawableY,
	    (int) (drawableX + width - 1), (int) (drawableY + height - 1));
    XDrawLine(display, drawable, instPtr->gc, drawableX,
	    (int) (drawableY + height - 1),
	    (int) (drawableX + width - 1), drawableY);
}

/*
 *----------------------------------------------------------------------
 *
 * ImageFree --
 *
 *	This function is called when an instance of an image is no longer
 *	used.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information related to the instance is freed.
 *
 *----------------------------------------------------------------------
 */

static void
ImageFree(
    ClientData clientData,	/* Pointer to TImageInstance for instance. */
    Display *display)		/* Display where image was to be drawn. */
{
    TImageInstance *instPtr = clientData;
    char buffer[200];

    sprintf(buffer, "%s free", instPtr->masterPtr->imageName);
    Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName, NULL,
	    buffer, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
    Tk_FreeColor(instPtr->fg);
    Tk_FreeGC(display, instPtr->gc);
    ckfree(instPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ImageDelete --
 *
 *	This function is called to clean up a test image when an application
 *	goes away.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information about the image is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ImageDelete(
    ClientData clientData)	/* Pointer to TImageMaster for image. When
				 * this function is called, no more instances
				 * exist. */
{
    TImageMaster *timPtr = clientData;
    char buffer[100];

    sprintf(buffer, "%s delete", timPtr->imageName);
    Tcl_SetVar2(timPtr->interp, timPtr->varName, NULL, buffer,
	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);

    Tcl_DeleteCommand(timPtr->interp, timPtr->imageName);
    ckfree(timPtr->imageName);
    ckfree(timPtr->varName);
    ckfree(timPtr);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkOption.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







/*
 * tkOption.c --
 *
 *	This module contains functions to manage the option database, which
 *	allows various strings to be associated with windows either by name or
 *	by class or both.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
+







				 * level. */
    int bases[NUM_STACKS];	/* For each stack, index of first element on
				 * stack corresponding to this level (used to
				 * restore "numUsed" fields when popping out
				 * of a level. */
} StackLevel;

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;		/* 0 means the ThreadSpecific Data structure
				 * for the current thread needs to be
				 * initialized. */
    ElArray *stacks[NUM_STACKS];
    TkWindow *cachedWindow;	/* Lowest-level window currently loaded in
				 * stacks at present. NULL means stacks have
				 * never been used, or have been invalidated
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229







-
+







			    char *string, int priority);
static void		ClearOptionTree(ElArray *arrayPtr);
static ElArray *	ExtendArray(ElArray *arrayPtr, Element *elPtr);
static void		ExtendStacks(ElArray *arrayPtr, int leaf);
static int		GetDefaultOptions(Tcl_Interp *interp,
			    TkWindow *winPtr);
static ElArray *	NewArray(int numEls);
static void		OptionThreadExitProc(void *clientData);
static void		OptionThreadExitProc(ClientData clientData);
static void		OptionInit(TkMainInfo *mainPtr);
static int		ParsePriority(Tcl_Interp *interp, const char *string);
static int		ReadOptionFile(Tcl_Interp *interp, Tk_Window tkwin,
			    const char *fileName, int priority);
static void		SetupStacks(TkWindow *winPtr, int leaf);

/*
250
251
252
253
254
255
256
257
258


259
260

261
262
263

264
265
266

267
268
269
270
271
272
273
250
251
252
253
254
255
256


257
258
259

260
261
262

263
264
265

266
267
268
269
270
271
272
273







-
-
+
+

-
+


-
+


-
+







    const char *value,		/* String value for option. */
    int priority)		/* Overall priority level to use for this
				 * option, such as TK_USER_DEFAULT_PRIO or
				 * TK_INTERACTIVE_PRIO. Must be between 0 and
				 * TK_MAX_PRIO. */
{
    TkWindow *winPtr = ((TkWindow *) tkwin)->mainPtr->winPtr;
    ElArray **arrayPtrPtr;
    Element *elPtr;
    register ElArray **arrayPtrPtr;
    register Element *elPtr;
    Element newEl;
    const char *p;
    register const char *p;
    const char *field;
    int count, firstField;
    size_t length;
    ptrdiff_t length;
#define TMP_SIZE 100
    char tmp[TMP_SIZE+1];
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->mainPtr->optionRootPtr == NULL) {
	OptionInit(winPtr->mainPtr);
    }
    tsdPtr->cachedWindow = NULL;/* Invalidate the cache. */

307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321







-
+







	while ((*p != 0) && (*p != '.') && (*p != '*')) {
	    p++;
	}
	length = p - field;
	if (length > TMP_SIZE) {
	    length = TMP_SIZE;
	}
	strncpy(tmp, field, length);
	strncpy(tmp, field, (size_t) length);
	tmp[length] = 0;
	newEl.nameUid = Tk_GetUid(tmp);
	if (isupper(UCHAR(*field))) {
	    newEl.flags |= CLASS;
	}

	if (*p != 0) {
402
403
404
405
406
407
408
409
410
411



412
413
414

415
416
417
418
419
420
421
402
403
404
405
406
407
408



409
410
411
412
413

414
415
416
417
418
419
420
421







-
-
-
+
+
+


-
+







				 * with. */
    const char *name,		/* Name of option. */
    const char *className)	/* Class of option. NULL means there is no
				 * class for this option: just check for
				 * name. */
{
    Tk_Uid nameId, classId = NULL;
    const char *masqName;
    Element *elPtr, *bestPtr;
    int count;
    char *masqName;
    register Element *elPtr, *bestPtr;
    register int count;
    StackLevel *levelPtr;
    int stackDepth[NUM_STACKS];
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Note: no need to call OptionInit here: it will be done by the
     * SetupStacks call below (squeeze out those nanoseconds).
     */

517
518
519
520
521
522
523
524
525


526
527
528
529
530
531
532
533
534
535
536
537
538


539
540
541
542
543
544
545
517
518
519
520
521
522
523


524
525
526
527
528
529
530
531
532
533
534
535
536


537
538
539
540
541
542
543
544
545







-
-
+
+











-
-
+
+







     * option database is densely populated, or if the widget has many
     * masquerading options.
     */

    if (masqName != NULL) {
	char *masqClass;
	Tk_Uid nodeId, winClassId, winNameId;
	Tcl_Size classNameLength;
	Element *nodePtr, *leafPtr;
	unsigned int classNameLength;
	register Element *nodePtr, *leafPtr;
	static const int searchOrder[] = {
	    EXACT_NODE_NAME, WILDCARD_NODE_NAME, EXACT_NODE_CLASS,
	    WILDCARD_NODE_CLASS, -1
	};
	const int *currentPtr;
	int currentStack, leafCount;

	/*
	 * Extract the masquerade class name from the name field.
	 */

	classNameLength	= masqName - name;
	masqClass = (char *)ckalloc(classNameLength + 1);
	classNameLength	= (unsigned) (masqName - name);
	masqClass = ckalloc(classNameLength + 1);
	strncpy(masqClass, name, classNameLength);
	masqClass[classNameLength] = '\0';

	winClassId = Tk_GetUid(masqClass);
	ckfree(masqClass);
	winNameId = ((TkWindow *) tkwin)->nameUid;

606
607
608
609
610
611
612
613

614
615
616
617
618

619
620

621
622
623
624
625
626
627
606
607
608
609
610
611
612

613
614
615
616
617

618
619

620
621
622
623
624
625
626
627







-
+




-
+

-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_OptionObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of Tcl_Obj arguments. */
    Tcl_Obj *const objv[])	/* Tcl_Obj arguments. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    int index, result;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    static const char *const optionCmds[] = {
	"add", "clear", "get", "readfile", NULL
    };
    enum optionVals {
	OPTION_ADD, OPTION_CLEAR, OPTION_GET, OPTION_READFILE
    };
686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700







-
+







	window = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin);
	if (window == NULL) {
	    return TCL_ERROR;
	}
	value = Tk_GetOption(window, Tcl_GetString(objv[3]),
		Tcl_GetString(objv[4]));
	if (value != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(value, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(value, -1));
	}
	break;
    }

    case OPTION_READFILE: {
	int priority;

734
735
736
737
738
739
740
741

742
743

744
745
746
747
748
749
750
751
752
753
754

755
756
757
758

759
760
761
762
763
764
765
734
735
736
737
738
739
740

741
742

743
744
745
746
747
748
749
750
751
752
753

754
755
756
757

758
759
760
761
762
763
764
765







-
+

-
+










-
+



-
+







 *	Option-related resources are freed. See code below for details.
 *
 *--------------------------------------------------------------
 */

void
TkOptionDeadWindow(
    TkWindow *winPtr)	/* Window to be cleaned up. */
    register TkWindow *winPtr)	/* Window to be cleaned up. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * If this window is in the option stacks, then clear the stacks.
     *
     * XXX: OptionThreadExitProc will be invoked before DeleteWindowsExitProc
     * XXX: if it is thread-specific (which it should be), invalidating the
     * XXX: tsd. Tk shutdown needs to be verified to handle this correctly.
     */

    if (tsdPtr->initialized && (winPtr->optionLevel != TCL_INDEX_NONE)) {
    if (tsdPtr->initialized && (winPtr->optionLevel != -1)) {
	int i;

	for (i = 1; i <= tsdPtr->curLevel; i++) {
	    tsdPtr->levels[i].winPtr->optionLevel = TCL_INDEX_NONE;
	    tsdPtr->levels[i].winPtr->optionLevel = -1;
	}
	tsdPtr->curLevel = -1;
	tsdPtr->cachedWindow = NULL;
    }

    /*
     * If this window was a main window, then delete its option database.
792
793
794
795
796
797
798
799

800
801
802

803
804
805
806
807
808
809
810
811
812
813
814

815
816
817
818
819
820
821
792
793
794
795
796
797
798

799
800
801

802
803
804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821







-
+


-
+











-
+








void
TkOptionClassChanged(
    TkWindow *winPtr)		/* Window whose class changed. */
{
    int i, j, *basePtr;
    ElArray *arrayPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->optionLevel < 0) {
    if (winPtr->optionLevel == -1) {
	return;
    }

    /*
     * Find the lowest stack level that refers to this window, then flush all
     * of the levels above the matching one.
     */

    for (i = 1; i <= tsdPtr->curLevel; i++) {
	if (tsdPtr->levels[i].winPtr == winPtr) {
	    for (j = i; j <= tsdPtr->curLevel; j++) {
		tsdPtr->levels[j].winPtr->optionLevel = TCL_INDEX_NONE;
		tsdPtr->levels[j].winPtr->optionLevel = -1;
	    }
	    tsdPtr->curLevel = i-1;
	    basePtr = tsdPtr->levels[i].bases;
	    for (j = 0; j < NUM_STACKS; j++) {
		arrayPtr = tsdPtr->stacks[j];
		arrayPtr->numUsed = basePtr[j];
		arrayPtr->nextToUse = &arrayPtr->els[arrayPtr->numUsed];
918
919
920
921
922
923
924
925

926
927
928
929
930
931
932
918
919
920
921
922
923
924

925
926
927
928
929
930
931
932







-
+







				 * this window's main window. */
    char *string,		/* String containing option specifiers. */
    int priority)		/* Priority level to use for options in this
				 * string, such as TK_USER_DEFAULT_PRIO or
				 * TK_INTERACTIVE_PRIO. Must be between 0 and
				 * TK_MAX_PRIO. */
{
    char *src, *dst;
    register char *src, *dst;
    char *name, *value;
    int lineNum;

    src = string;
    lineNum = 1;
    while (1) {
	/*
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
992
993
994
995
996
997
998



999
1000
1001
1002
1003
1004
1005







-
-
-







	 * Skip white space between the name and the value.
	 */

	src++;
	while ((*src == ' ') || (*src == '\t')) {
	    src++;
	}
	if (*src == '\\' && (src[1] == '\t' || src[1] == ' ')) {
	    src++;
	}
	if (*src == '\0') {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "missing value on line %d", lineNum));
	    Tcl_SetErrorCode(interp, "TK", "OPTIONDB", "VALUE", NULL);
	    return TCL_ERROR;
	}

1024
1025
1026
1027
1028
1029
1030
1031

1032
1033
1034
1035
1036
1037
1038
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1035







-
+







		    src += 2;
		    lineNum++;
		    continue;
		} else if (src[1] == 'n') {
		    src += 2;
		    *dst++ = '\n';
		    continue;
		} else if (src[1] == '\\') {
		} else if (src[1] == '\t' || src[1] == ' ' || src[1] == '\\') {
		    ++src;
		} else if (src[1] >= '0' && src[1] <= '3' && src[2] >= '0' &&
			src[2] <= '9' && src[3] >= '0' && src[3] <= '9') {
		    *dst++ = ((src[1]&7)<<6) | ((src[2]&7)<<3) | (src[3]&7);
		    src += 4;
		    continue;
		}
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119


1120
1121
1122
1123
1124
1125
1126
1077
1078
1079
1080
1081
1082
1083

1084

1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113


1114
1115
1116
1117
1118
1119
1120
1121
1122







-
+
-









-
+



















-
-
+
+







    int priority)		/* Priority level to use for options in this
				 * file, such as TK_USER_DEFAULT_PRIO or
				 * TK_INTERACTIVE_PRIO. Must be between 0 and
				 * TK_MAX_PRIO. */
{
    const char *realName;
    Tcl_Obj *buffer;
    int result;
    int result, bufferSize;
    Tcl_Size bufferSize;
    Tcl_Channel chan;
    Tcl_DString newName;

    /*
     * Prevent file system access in a safe interpreter.
     */

    if (Tcl_IsSafe(interp)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't read options from a file in a safe interpreter", TCL_INDEX_NONE));
		"can't read options from a file in a safe interpreter", -1));
	Tcl_SetErrorCode(interp, "TK", "SAFE", "OPTION_FILE", NULL);
	return TCL_ERROR;
    }

    realName = Tcl_TranslateFileName(interp, fileName, &newName);
    if (realName == NULL) {
	return TCL_ERROR;
    }
    chan = Tcl_OpenFileChannel(interp, realName, "r", 0);
    Tcl_DStringFree(&newName);
    if (chan == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("couldn't open \"%s\": %s",
		fileName, Tcl_PosixError(interp)));
	return TCL_ERROR;
    }

    buffer = Tcl_NewObj();
    Tcl_IncrRefCount(buffer);
    Tcl_SetChannelOption(NULL, chan, "-encoding", "utf-8");
    bufferSize = Tcl_ReadChars(chan, buffer, TCL_INDEX_NONE, 0);
    if (bufferSize == TCL_IO_FAILURE) {
    bufferSize = Tcl_ReadChars(chan, buffer, -1, 0);
    if (bufferSize < 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"error reading file \"%s\": %s",
		fileName, Tcl_PosixError(interp)));
	Tcl_Close(NULL, chan);
	return TCL_ERROR;
    }
    Tcl_Close(NULL, chan);
1146
1147
1148
1149
1150
1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155
1156







-
+







 *--------------------------------------------------------------
 */

static ElArray *
NewArray(
    int numEls)			/* How many elements of space to allocate. */
{
    ElArray *arrayPtr = (ElArray *)ckalloc(EL_ARRAY_SIZE(numEls));
    register ElArray *arrayPtr = ckalloc(EL_ARRAY_SIZE(numEls));

    arrayPtr->arraySize = numEls;
    arrayPtr->numUsed = 0;
    arrayPtr->nextToUse = arrayPtr->els;
    return arrayPtr;
}

1173
1174
1175
1176
1177
1178
1179
1180
1181


1182
1183
1184
1185
1186
1187
1188

1189
1190

1191
1192
1193
1194
1195
1196
1197
1169
1170
1171
1172
1173
1174
1175


1176
1177
1178
1179
1180
1181
1182
1183

1184
1185

1186
1187
1188
1189
1190
1191
1192
1193







-
-
+
+






-
+

-
+







 *	Memory may be allocated or freed.
 *
 *--------------------------------------------------------------
 */

static ElArray *
ExtendArray(
    ElArray *arrayPtr,	/* Array to be extended. */
    Element *elPtr)	/* Element to be copied into array. */
    register ElArray *arrayPtr,	/* Array to be extended. */
    register Element *elPtr)	/* Element to be copied into array. */
{
    /*
     * If the current array has filled up, make it bigger.
     */

    if (arrayPtr->numUsed >= arrayPtr->arraySize) {
	int newSize = 2*arrayPtr->arraySize;
	register int newSize = 2*arrayPtr->arraySize;

	arrayPtr = (ElArray *)ckrealloc(arrayPtr, EL_ARRAY_SIZE(newSize));
	arrayPtr = ckrealloc(arrayPtr, EL_ARRAY_SIZE(newSize));
	arrayPtr->arraySize = newSize;
	arrayPtr->nextToUse = &arrayPtr->els[arrayPtr->numUsed];
    }

    *arrayPtr->nextToUse = *elPtr;
    arrayPtr->nextToUse++;
    arrayPtr->numUsed++;
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231



1232
1233
1234
1235
1236
1237
1238
1218
1219
1220
1221
1222
1223
1224



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234







-
-
-
+
+
+







				 * cached. */
    int leaf)			/* Non-zero means this is the leaf window
				 * being probed. Zero means this is an
				 * ancestor of the desired leaf. */
{
    int level, i;
    const int *iPtr;
    StackLevel *levelPtr;
    ElArray *arrayPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register StackLevel *levelPtr;
    register ElArray *arrayPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * The following array defines the order in which the current stacks are
     * searched to find matching entries to add to the stacks. Given the
     * current priority-based scheme, the order below is no longer relevant;
     * all that matters is that an element is on the list *somewhere*. The
1265
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1261
1262
1263
1264
1265
1266
1267

1268
1269
1270
1271
1272
1273
1274
1275







-
+







    /*
     * Step 2: pop extra unneeded information off the stacks and mark those
     * windows as no longer having cached information.
     */

    if (tsdPtr->curLevel >= level) {
	while (tsdPtr->curLevel >= level) {
	    tsdPtr->levels[tsdPtr->curLevel].winPtr->optionLevel = TCL_INDEX_NONE;
	    tsdPtr->levels[tsdPtr->curLevel].winPtr->optionLevel = -1;
	    tsdPtr->curLevel--;
	}
	levelPtr = &tsdPtr->levels[level];
	for (i = 0; i < NUM_STACKS; i++) {
	    arrayPtr = tsdPtr->stacks[i];
	    arrayPtr->numUsed = levelPtr->bases[i];
	    arrayPtr->nextToUse = &arrayPtr->els[arrayPtr->numUsed];
1301
1302
1303
1304
1305
1306
1307
1308

1309
1310
1311
1312
1313
1314
1315
1297
1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311







-
+







    /*
     * Step 4: create a new stack level; grow the level array if we've run out
     * of levels. Clear the stacks for EXACT_LEAF_NAME and EXACT_LEAF_CLASS
     * (anything that was there is of no use any more).
     */

    if (tsdPtr->curLevel >= tsdPtr->numLevels) {
	StackLevel *newLevels = (StackLevel *)
	StackLevel *newLevels =
		ckalloc(tsdPtr->numLevels * 2 * sizeof(StackLevel));

	memcpy(newLevels, tsdPtr->levels,
		tsdPtr->numLevels * sizeof(StackLevel));
	ckfree(tsdPtr->levels);
	tsdPtr->numLevels *= 2;
	tsdPtr->levels = newLevels;
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1338







-
+








    /*
     * Step 5: scan the current stack level looking for matches to this
     * window's name or class; where found, add new information to the stacks.
     */

    for (iPtr = searchOrder; *iPtr != -1; iPtr++) {
	Element *elPtr;
	register Element *elPtr;
	int count;
	Tk_Uid id;

	i = *iPtr;
	if (i & CLASS) {
	    id = winPtr->classUid;
	} else {
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392



1393
1394
1395
1396
1397
1398
1399
1379
1380
1381
1382
1383
1384
1385



1386
1387
1388
1389
1390
1391
1392
1393
1394
1395







-
-
-
+
+
+








static void
ExtendStacks(
    ElArray *arrayPtr,		/* Array of elements to copy onto stacks. */
    int leaf)			/* If zero, then don't copy exact leaf
				 * elements. */
{
    int count;
    Element *elPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register int count;
    register Element *elPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (elPtr = arrayPtr->els, count = arrayPtr->numUsed;
	    count > 0; elPtr++, count--) {
	if (!(elPtr->flags & (NODE|WILDCARD)) && !leaf) {
	    continue;
	}
1416
1417
1418
1419
1420
1421
1422
1423

1424
1425

1426
1427
1428
1429
1430
1431
1432
1412
1413
1414
1415
1416
1417
1418

1419
1420

1421
1422
1423
1424
1425
1426
1427
1428







-
+

-
+







 *	Option-related data structures get freed.
 *
 *--------------------------------------------------------------
 */

static void
OptionThreadExitProc(
    TCL_UNUSED(void *))
    ClientData clientData)	/* not used */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->initialized) {
	int i;

	for (i = 0; i < NUM_STACKS; i++) {
	    ckfree(tsdPtr->stacks[i]);
1450
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473

1474
1475
1476
1477
1478
1479
1480
1481







-
+





-
+














-
+







 *	Option-related data structures get initialized.
 *
 *--------------------------------------------------------------
 */

static void
OptionInit(
    TkMainInfo *mainPtr)
    register TkMainInfo *mainPtr)
				/* Top-level information about window that
				 * isn't initialized yet. */
{
    int i;
    Tcl_Interp *interp;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Element *defaultMatchPtr = &tsdPtr->defaultMatch;

    /*
     * First, once-only initialization.
     */

    if (tsdPtr->initialized == 0) {
	tsdPtr->initialized = 1;
	tsdPtr->cachedWindow = NULL;
	tsdPtr->numLevels = 5;
	tsdPtr->curLevel = -1;
	tsdPtr->serial = 0;

	tsdPtr->levels = (StackLevel *)ckalloc(5 * sizeof(StackLevel));
	tsdPtr->levels = ckalloc(5 * sizeof(StackLevel));
	for (i = 0; i < NUM_STACKS; i++) {
	    tsdPtr->stacks[i] = NewArray(10);
	    tsdPtr->levels[0].bases[i] = 0;
	}

	defaultMatchPtr->nameUid = NULL;
	defaultMatchPtr->child.valueUid = NULL;
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527
1528







-
+







 */

static void
ClearOptionTree(
    ElArray *arrayPtr)		/* Array of options; delete everything
				 * referred to recursively by this. */
{
    Element *elPtr;
    register Element *elPtr;
    int count;

    for (count = arrayPtr->numUsed, elPtr = arrayPtr->els;  count > 0;
	    count--, elPtr++) {
	if (elPtr->flags & NODE) {
	    ClearOptionTree(elPtr->child.arrayPtr);
	}

Changes to generic/tkPack.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16

17
18

19
20
21
22
23

24
25
26
27
28
29
30
31
32

33
34
35

36
37
38
39
40



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64

65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82
83
84
85
86
87

88
89
90
91



92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107


108
109
110
111
112
113

114
115
116
117
118
119
120
121


122
123

124




125

126
127
128
129


130
131
132
133
134
135
136
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15

16
17

18
19
20
21
22

23
24
25
26
27
28
29
30
31

32
33
34

35
36
37



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63

64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80

81
82
83
84
85
86

87
88



89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105


106
107
108
109
110
111
112

113
114
115
116
117
118
119


120
121
122

123
124
125
126
127
128

129
130
131


132
133
134
135
136
137
138
139
140






-
-
+
+







-
+

-
+




-
+








-
+


-
+


-
-
-
+
+
+

















-
+





-
+








-
+







-
+





-
+

-
-
-
+
+
+








-
+





-
-
+
+





-
+






-
-
+
+

-
+

+
+
+
+
-
+


-
-
+
+







/*
 * tkPack.c --
 *
 *	This file contains code to implement the "packer" geometry manager for
 *	Tk.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"

typedef enum {BOTTOM, LEFT, RIGHT, TOP} Side;
typedef enum {TOP, BOTTOM, LEFT, RIGHT} Side;
static const char *const sideNames[] = {
    "bottom", "left", "right", "top", NULL
    "top", "bottom", "left", "right", NULL
};

/*
 * For each window that the packer cares about (either because the window is
 * managed by the packer or because the window has content that are managed by
 * managed by the packer or because the window has slaves that are managed by
 * the packer), there is a structure of the following type:
 */

typedef struct Packer {
    Tk_Window tkwin;		/* Tk token for window. NULL means that the
				 * window has been deleted, but the packet
				 * hasn't had a chance to clean up yet because
				 * the structure is still in use. */
    struct Packer *containerPtr;	/* Container window within which this window is
    struct Packer *masterPtr;	/* Master window within which this window is
				 * packed (NULL means this window isn't
				 * managed by the packer). */
    struct Packer *nextPtr;	/* Next window packed within same container. List
    struct Packer *nextPtr;	/* Next window packed within same master. List
				 * is priority-ordered: first on list gets
				 * packed first. */
    struct Packer *contentPtr;	/* First in list of content packed inside this
				 * window (NULL means no packed content). */
    Side side;			/* Side of container against which this window is
    struct Packer *slavePtr;	/* First in list of slaves packed inside this
				 * window (NULL means no packed slaves). */
    Side side;			/* Side of master against which this window is
				 * packed. */
    Tk_Anchor anchor;		/* If frame allocated for window is larger
				 * than window needs, this indicates how where
				 * to position window in frame. */
    int padX, padY;		/* Total additional pixels to leave around the
				 * window. Some is of this space is on each
				 * side. This is space *outside* the window:
				 * we'll allocate extra space in frame but
				 * won't enlarge window). */
    int padLeft, padTop;	/* The part of padX or padY to use on the left
				 * or top of the widget, respectively. By
				 * default, this is half of padX or padY. */
    int iPadX, iPadY;		/* Total extra pixels to allocate inside the
				 * window (half of this amount will appear on
				 * each side). */
    int doubleBw;		/* Twice the window's last known border width.
				 * If this changes, the window must be
				 * repacked within its container. */
				 * repacked within its master. */
    int *abortPtr;		/* If non-NULL, it means that there is a
				 * nested call to ArrangePacking already
				 * working on this window. *abortPtr may be
				 * set to 1 to abort that nested call. This
				 * happens, for example, if tkwin or any of
				 * its content is deleted. */
				 * its slaves is deleted. */
    int flags;			/* Miscellaneous flags; see below for
				 * definitions. */
} Packer;

/*
 * Flag values for Packer structures:
 *
 * REQUESTED_REPACK:		1 means a Tcl_DoWhenIdle request has already
 *				been made to repack all the content of this
 *				been made to repack all the slaves of this
 *				window.
 * FILLX:			1 means if frame allocated for window is wider
 *				than window needs, expand window to fill
 *				frame. 0 means don't make window any larger
 *				than needed.
 * FILLY:			Same as FILLX, except for height.
 * EXPAND:			1 means this window's frame will absorb any
 *				extra space in the container window.
 *				extra space in the master window.
 * OLD_STYLE:			1 means this window is being managed with the
 *				old-style packer algorithms (before Tk version
 *				3.3). The main difference is that padding and
 *				filling are done differently.
 * DONT_PROPAGATE:		1 means don't set this window's requested
 *				size. 0 means if this window is a container then
 *				size. 0 means if this window is a master then
 *				Tk will set its requested size to fit the
 *				needs of its content.
 * ALLOCED_CONTAINER	1 means that Pack has allocated itself as
 *				geometry container for this window.
 *				needs of its slaves.
 * ALLOCED_MASTER               1 means that Pack has allocated itself as
 *                              geometry master for this window.
 */

#define REQUESTED_REPACK	1
#define FILLX			2
#define FILLY			4
#define EXPAND			8
#define OLD_STYLE		16
#define DONT_PROPAGATE		32
#define ALLOCED_CONTAINER	64
#define ALLOCED_MASTER		64

/*
 * The following structure is the official type record for the packer:
 */

static void		PackReqProc(void *clientData, Tk_Window tkwin);
static void		PackLostContentProc(void *clientData,
static void		PackReqProc(ClientData clientData, Tk_Window tkwin);
static void		PackLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);

static const Tk_GeomMgr packerType = {
    "pack",			/* name */
    PackReqProc,		/* requestProc */
    PackLostContentProc,		/* lostContentProc */
    PackLostSlaveProc,		/* lostSlaveProc */
};

/*
 * Forward declarations for functions defined later in this file:
 */

static void		ArrangePacking(void *clientData);
static int		ConfigureContent(Tcl_Interp *interp, Tk_Window tkwin,
static void		ArrangePacking(ClientData clientData);
static int		ConfigureSlaves(Tcl_Interp *interp, Tk_Window tkwin,
			    int objc, Tcl_Obj *const objv[]);
static Tcl_FreeProc	DestroyPacker;
static void		DestroyPacker(void *memPtr);
static Packer *		GetPacker(Tk_Window tkwin);
#ifndef TK_NO_DEPRECATED
static int		PackAfter(Tcl_Interp *interp, Packer *prevPtr,
			    Packer *masterPtr, int objc,Tcl_Obj *const objv[]);
#endif /* !TK_NO_DEPRECATED */
static void		PackStructureProc(void *clientData,
static void		PackStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		Unlink(Packer *packPtr);
static int		XExpansion(Packer *contentPtr, int cavityWidth);
static int		YExpansion(Packer *contentPtr, int cavityHeight);
static int		XExpansion(Packer *slavePtr, int cavityWidth);
static int		YExpansion(Packer *slavePtr, int cavityHeight);

/*
 *------------------------------------------------------------------------
 *
 * TkAppendPadAmount --
 *
 *	This function generates a text value that describes one of the -padx,
154
155
156
157
158
159
160
161
162


163
164
165
166



167
168
169
170
171
172
173
158
159
160
161
162
163
164


165
166
167



168
169
170
171
172
173
174
175
176
177







-
-
+
+

-
-
-
+
+
+







				 * "ipady" */
    int halfSpace,		/* The left or top padding amount */
    int allSpace)		/* The total amount of padding */
{
    Tcl_Obj *padding[2];

    if (halfSpace*2 == allSpace) {
	Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, TCL_INDEX_NONE),
		Tcl_NewWideIntObj(halfSpace));
	Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, -1),
		Tcl_NewIntObj(halfSpace));
    } else {
	padding[0] = Tcl_NewWideIntObj(halfSpace);
	padding[1] = Tcl_NewWideIntObj(allSpace - halfSpace);
	Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, TCL_INDEX_NONE),
	padding[0] = Tcl_NewIntObj(halfSpace);
	padding[1] = Tcl_NewIntObj(allSpace - halfSpace);
	Tcl_DictObjPut(NULL, bufferObj, Tcl_NewStringObj(switchName, -1),
		Tcl_NewListObj(2, padding));
    }
}

/*
 *------------------------------------------------------------------------
 *
183
184
185
186
187
188
189
190

191
192
193
194
195

196
197



198

199
200
201



202

203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218



219
220
221
222
223
224

225
226



227
228
229
230
231


































































232
233
234
235
236
237
238
239

240
241
242


243
244
245
246

247
248
249
250
251
252
253
254






255
256
257


258
259
260
261
262
263
264


265
266
267
268
269
270
271

272
273
274
275


276
277
278
279
280
281
282
283
284
285
286
287
288
289







290
291
292


293
294
295
296


297
298
299
300


301
302
303
304


305
306
307
308
309
310
311
312






313
314
315
316
317
318


319
320
321
322
323
324
325

326
327
328

329
330
331

332
333
334
335
336
337
338
339

340
341
342
343


344
345
346

347
348

349
350
351
352


353
354
355
356


357
358
359
360



361
362
363
364
365



366
367

368
369
370
371

372
373
374


375
376
377
378
379
380
381

382
383
384
385
386
387



388
389

390
391
392
393

























394
395
396
397
398
399
400
187
188
189
190
191
192
193

194
195
196
197
198

199
200
201
202
203
204

205


206
207
208
209

210
211
212
213
214
215
216

217
218
219
220
221
222
223
224


225
226
227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317


318
319
320
321
322

323
324
325






326
327
328
329
330
331
332


333
334
335
336
337
338
339


340
341
342
343
344
345
346
347

348
349
350


351
352
353
354
355
356
357
358
359







360
361
362
363
364
365
366
367


368
369
370
371


372
373
374
375


376
377
378
379


380
381
382
383






384
385
386
387
388
389
390
391
392
393


394
395
396
397
398
399
400
401

402
403
404

405
406
407

408
409
410
411
412
413
414
415

416
417
418


419
420
421
422

423
424

425
426
427


428
429
430
431


432
433
434



435
436
437
438
439



440
441
442
443

444
445
446
447

448



449
450
451
452
453
454
455
456

457
458
459
460



461
462
463
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501







-
+




-
+


+
+
+
-
+
-
-

+
+
+
-
+






-
+







-
-
+
+
+






+
-
-
+
+
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+

-
-
+
+



-
+


-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+





-
-
+
+






-
+


-
-
+
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+


-
-
+
+


-
-
+
+


-
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+




-
-
+
+






-
+


-
+


-
+







-
+


-
-
+
+


-
+

-
+


-
-
+
+


-
-
+
+

-
-
-
+
+
+


-
-
-
+
+
+

-
+



-
+
-
-
-
+
+






-
+



-
-
-
+
+
+

-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	See the user documentation.
 *
 *------------------------------------------------------------------------
 */

int
Tk_PackObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    const char *argv2;
    static const char *const optionStrings[] = {
#ifndef TK_NO_DEPRECATED
	"after", "append", "before", "unpack",
#endif /* !TK_NO_DEPRECATED */
	"configure", "content", "forget", "info", "propagate", "slaves", NULL };
	"configure", "forget", "info", "propagate", "slaves", NULL };
    static const char *const optionStringsNoDep[] = {
	"configure", "content", "forget", "info", "propagate", NULL };
    enum options {
#ifndef TK_NO_DEPRECATED
	PACK_AFTER, PACK_APPEND, PACK_BEFORE, PACK_UNPACK,
#endif /* !TK_NO_DEPRECATED */
	PACK_CONFIGURE, PACK_CONTENT, PACK_FORGET, PACK_INFO, PACK_PROPAGATE, PACK_SLAVES };
	PACK_CONFIGURE, PACK_FORGET, PACK_INFO, PACK_PROPAGATE, PACK_SLAVES };
    int index;

    if (objc >= 2) {
	const char *string = Tcl_GetString(objv[1]);

	if (string[0] == '.') {
	    return ConfigureContent(interp, tkwin, objc-1, objv+1);
	    return ConfigureSlaves(interp, tkwin, objc-1, objv+1);
	}
    }
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(NULL, objv[1], optionStrings,
	    "option", 0, &index) != TCL_OK) {
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
#ifndef TK_NO_DEPRECATED
	/*
	 * Call it again without the deprecated ones to get a proper error
	 * message. This works well since there can't be any ambiguity between
	 * deprecated and new options.
	 */

	Tcl_ResetResult(interp);
	Tcl_GetIndexFromObj(interp, objv[1], optionStringsNoDep,
		"option", 0, &index);
	Tcl_GetIndexFromObjStruct(interp, objv[1], &optionStrings[4],
		sizeof(char *), "option", 0, &index);
#endif /* TK_NO_DEPRECATED */
	return TCL_ERROR;
    }

    argv2 = Tcl_GetString(objv[2]);
    switch ((enum options) index) {
#ifndef TK_NO_DEPRECATED
    case PACK_AFTER: {
	Packer *prevPtr;
	Tk_Window tkwin2;

	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	prevPtr = GetPacker(tkwin2);
	if (prevPtr->masterPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" isn't packed", argv2));
	    Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL);
	    return TCL_ERROR;
	}
	return PackAfter(interp, prevPtr, prevPtr->masterPtr, objc-3, objv+3);
    }
    case PACK_APPEND: {
	Packer *masterPtr;
	register Packer *prevPtr;
	Tk_Window tkwin2;

	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	masterPtr = GetPacker(tkwin2);
	prevPtr = masterPtr->slavePtr;
	if (prevPtr != NULL) {
	    while (prevPtr->nextPtr != NULL) {
		prevPtr = prevPtr->nextPtr;
	    }
	}
	return PackAfter(interp, prevPtr, masterPtr, objc-3, objv+3);
    }
    case PACK_BEFORE: {
	Packer *packPtr, *masterPtr;
	register Packer *prevPtr;
	Tk_Window tkwin2;

	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	packPtr = GetPacker(tkwin2);
	if (packPtr->masterPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" isn't packed", argv2));
	    Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL);
	    return TCL_ERROR;
	}
	masterPtr = packPtr->masterPtr;
	prevPtr = masterPtr->slavePtr;
	if (prevPtr == packPtr) {
	    prevPtr = NULL;
	} else {
	    for ( ; ; prevPtr = prevPtr->nextPtr) {
		if (prevPtr == NULL) {
		    Tcl_Panic("\"pack before\" couldn't find predecessor");
		}
		if (prevPtr->nextPtr == packPtr) {
		    break;
		}
	    }
	}
	return PackAfter(interp, prevPtr, masterPtr, objc-3, objv+3);
    }
#endif /* !TK_NO_DEPRECATED */
    case PACK_CONFIGURE:
	if (argv2[0] != '.') {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad argument \"%s\": must be name of window", argv2));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "WINDOW_PATH", NULL);
	    return TCL_ERROR;
	}
	return ConfigureContent(interp, tkwin, objc-2, objv+2);
	return ConfigureSlaves(interp, tkwin, objc-2, objv+2);
    case PACK_FORGET: {
	Tk_Window content;
	Packer *contentPtr;
	Tk_Window slave;
	Packer *slavePtr;
	int i;

	for (i = 2; i < objc; i++) {
	    if (TkGetWindowFromObj(interp, tkwin, objv[i], &content) != TCL_OK) {
	    if (TkGetWindowFromObj(interp, tkwin, objv[i], &slave) != TCL_OK) {
		continue;
	    }
	    contentPtr = GetPacker(content);
	    if ((contentPtr != NULL) && (contentPtr->containerPtr != NULL)) {
		Tk_ManageGeometry(content, NULL, NULL);
		if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
		    Tk_UnmaintainGeometry(contentPtr->tkwin,
			    contentPtr->containerPtr->tkwin);
	    slavePtr = GetPacker(slave);
	    if ((slavePtr != NULL) && (slavePtr->masterPtr != NULL)) {
		Tk_ManageGeometry(slave, NULL, NULL);
		if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
		    Tk_UnmaintainGeometry(slavePtr->tkwin,
			    slavePtr->masterPtr->tkwin);
		}
		Unlink(contentPtr);
		Tk_UnmapWindow(contentPtr->tkwin);
		Unlink(slavePtr);
		Tk_UnmapWindow(slavePtr->tkwin);
	    }
	}
	break;
    }
    case PACK_INFO: {
	Packer *contentPtr;
	Tk_Window content;
	register Packer *slavePtr;
	Tk_Window slave;
	Tcl_Obj *infoObj;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &content) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &slave) != TCL_OK) {
	    return TCL_ERROR;
	}
	contentPtr = GetPacker(content);
	if (contentPtr->containerPtr == NULL) {
	slavePtr = GetPacker(slave);
	if (slavePtr->masterPtr == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" isn't packed", argv2));
	    Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED", NULL);
	    return TCL_ERROR;
	}

	infoObj = Tcl_NewObj();
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", TCL_INDEX_NONE),
		Tk_NewWindowObj(contentPtr->containerPtr->tkwin));
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-anchor", TCL_INDEX_NONE),
		Tcl_NewStringObj(Tk_NameOfAnchor(contentPtr->anchor), TCL_INDEX_NONE));
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-expand", TCL_INDEX_NONE),
		Tcl_NewBooleanObj(contentPtr->flags & EXPAND));
	switch (contentPtr->flags & (FILLX|FILLY)) {
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-in", -1),
		TkNewWindowObj(slavePtr->masterPtr->tkwin));
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-anchor", -1),
		Tcl_NewStringObj(Tk_NameOfAnchor(slavePtr->anchor), -1));
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-expand", -1),
		Tcl_NewBooleanObj(slavePtr->flags & EXPAND));
	switch (slavePtr->flags & (FILLX|FILLY)) {
	case 0:
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE),
		    Tcl_NewStringObj("none", TCL_INDEX_NONE));
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1),
		    Tcl_NewStringObj("none", -1));
	    break;
	case FILLX:
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE),
		    Tcl_NewStringObj("x", TCL_INDEX_NONE));
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1),
		    Tcl_NewStringObj("x", -1));
	    break;
	case FILLY:
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE),
		    Tcl_NewStringObj("y", TCL_INDEX_NONE));
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1),
		    Tcl_NewStringObj("y", -1));
	    break;
	case FILLX|FILLY:
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", TCL_INDEX_NONE),
		    Tcl_NewStringObj("both", TCL_INDEX_NONE));
	    Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-fill", -1),
		    Tcl_NewStringObj("both", -1));
	    break;
	}
	TkAppendPadAmount(infoObj, "-ipadx", contentPtr->iPadX/2, contentPtr->iPadX);
	TkAppendPadAmount(infoObj, "-ipady", contentPtr->iPadY/2, contentPtr->iPadY);
	TkAppendPadAmount(infoObj, "-padx", contentPtr->padLeft,contentPtr->padX);
	TkAppendPadAmount(infoObj, "-pady", contentPtr->padTop, contentPtr->padY);
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-side", TCL_INDEX_NONE),
		Tcl_NewStringObj(sideNames[contentPtr->side], TCL_INDEX_NONE));
	TkAppendPadAmount(infoObj, "-ipadx", slavePtr->iPadX/2, slavePtr->iPadX);
	TkAppendPadAmount(infoObj, "-ipady", slavePtr->iPadY/2, slavePtr->iPadY);
	TkAppendPadAmount(infoObj, "-padx", slavePtr->padLeft,slavePtr->padX);
	TkAppendPadAmount(infoObj, "-pady", slavePtr->padTop, slavePtr->padY);
	Tcl_DictObjPut(NULL, infoObj, Tcl_NewStringObj("-side", -1),
		Tcl_NewStringObj(sideNames[slavePtr->side], -1));
	Tcl_SetObjResult(interp, infoObj);
	break;
    }
    case PACK_PROPAGATE: {
	Tk_Window container;
	Packer *containerPtr;
	Tk_Window master;
	Packer *masterPtr;
	int propagate;

	if (objc > 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
	    return TCL_ERROR;
	}
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	    return TCL_ERROR;
	}
	containerPtr = GetPacker(container);
	masterPtr = GetPacker(master);
	if (objc == 3) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewBooleanObj(!(containerPtr->flags & DONT_PROPAGATE)));
		    Tcl_NewBooleanObj(!(masterPtr->flags & DONT_PROPAGATE)));
	    return TCL_OK;
	}
	if (Tcl_GetBooleanFromObj(interp, objv[3], &propagate) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (propagate) {
	    /*
	     * If we have content windows, we need to register as geometry container.
	     * If we have slaves, we need to register as geometry master.
	     */

	    if (containerPtr->contentPtr != NULL) {
		if (TkSetGeometryContainer(interp, container, "pack") != TCL_OK) {
	    if (masterPtr->slavePtr != NULL) {
		if (TkSetGeometryMaster(interp, master, "pack") != TCL_OK) {
		    return TCL_ERROR;
		}
		containerPtr->flags |= ALLOCED_CONTAINER;
		masterPtr->flags |= ALLOCED_MASTER;
	    }
	    containerPtr->flags &= ~DONT_PROPAGATE;
	    masterPtr->flags &= ~DONT_PROPAGATE;

	    /*
	     * Repack the container to allow new geometry information to
	     * propagate upwards to the container's container.
	     * Repack the master to allow new geometry information to
	     * propagate upwards to the master's master.
	     */

	    if (containerPtr->abortPtr != NULL) {
		*containerPtr->abortPtr = 1;
	    if (masterPtr->abortPtr != NULL) {
		*masterPtr->abortPtr = 1;
	    }
	    if (!(containerPtr->flags & REQUESTED_REPACK)) {
		containerPtr->flags |= REQUESTED_REPACK;
		Tcl_DoWhenIdle(ArrangePacking, containerPtr);
	    if (!(masterPtr->flags & REQUESTED_REPACK)) {
		masterPtr->flags |= REQUESTED_REPACK;
		Tcl_DoWhenIdle(ArrangePacking, masterPtr);
	    }
	} else {
	    if (containerPtr->flags & ALLOCED_CONTAINER) {
		TkFreeGeometryContainer(container, "pack");
		containerPtr->flags &= ~ALLOCED_CONTAINER;
	    if (masterPtr->flags & ALLOCED_MASTER) {
		TkFreeGeometryMaster(master, "pack");
		masterPtr->flags &= ~ALLOCED_MASTER;
	    }
	    containerPtr->flags |= DONT_PROPAGATE;
	    masterPtr->flags |= DONT_PROPAGATE;
	}
	break;
    }
    case PACK_SLAVES:
    case PACK_SLAVES: {
    case PACK_CONTENT: {
	Tk_Window container;
	Packer *containerPtr, *contentPtr;
	Tk_Window master;
	Packer *masterPtr, *slavePtr;
	Tcl_Obj *resultObj;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &container) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	    return TCL_ERROR;
	}
	resultObj = Tcl_NewObj();
	containerPtr = GetPacker(container);
	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	masterPtr = GetPacker(master);
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    Tk_NewWindowObj(contentPtr->tkwin));
		    TkNewWindowObj(slavePtr->tkwin));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;
    }
#ifndef TK_NO_DEPRECATED
    case PACK_UNPACK: {
	Tk_Window tkwin2;
	Packer *packPtr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	packPtr = GetPacker(tkwin2);
	if ((packPtr != NULL) && (packPtr->masterPtr != NULL)) {
	    Tk_ManageGeometry(tkwin2, NULL, NULL);
	    if (packPtr->masterPtr->tkwin != Tk_Parent(packPtr->tkwin)) {
		Tk_UnmaintainGeometry(packPtr->tkwin,
			packPtr->masterPtr->tkwin);
	    }
	    Unlink(packPtr);
	    Tk_UnmapWindow(packPtr->tkwin);
	}
	break;
    }
#endif /* !TK_NO_DEPRECATED */
    }

    return TCL_OK;
}

/*
 *------------------------------------------------------------------------
410
411
412
413
414
415
416

417
418
419

420
421

422
423
424

425
426

427
428
429
430
431
432
433
434
435
436

437
438
439

440
441
442
443
444
445

446
447
448
449

450
451
452


453
454

455
456

457
458
459


460
461
462


463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486

487
488
489
490


491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507

508
509

510

511
512
513
514
515

516
517
518
519
520
521
522
523
524
525
526


527
528

529
530

531
532
533

534
535
536
537

538
539

540
541
542
543
544




545
546
547
548
549
550
551
552
553
554
555
556
557









558
559
560
561
562


563
564
565


566
567
568
569
570


571
572
573
574
575
576
577
578
579
580
581


582
583
584


585
586
587
588

589
590
591

592
593
594
595
596
597
598
599






600
601
602
603
604

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622











623
624
625
626
627




628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646




647
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671

672
673
674
675
676
677
678



679
680

681
682
683
684
685



686
687
688
689
690
691



692
693
694
695

696
697
698
699
700
701
702
511
512
513
514
515
516
517
518
519
520

521
522

523
524
525

526
527

528
529
530
531
532
533
534
535
536
537

538
539
540

541
542
543
544
545
546

547
548
549
550
551
552
553


554
555
556

557
558

559
560


561
562
563


564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588

589
590
591


592
593
594
595
596

597
598
599
600
601
602
603
604
605
606
607
608
609

610
611
612
613

614


615
616

617
618
619
620
621
622
623
624
625
626


627
628
629

630
631

632
633
634

635
636
637
638

639
640

641
642




643
644
645
646
647
648
649
650









651
652
653
654
655
656
657
658
659
660
661
662


663
664
665


666
667
668
669
670


671
672
673
674
675
676
677
678
679
680
681


682
683
684


685
686
687
688
689

690
691
692

693
694
695






696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713











714
715
716
717
718
719
720
721
722
723
724
725




726
727
728
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744




745
746
747
748
749
750
751
752
753
754
755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772

773
774
775
776
777



778
779
780
781

782
783
784



785
786
787
788
789
790



791
792
793
794
795
796

797
798
799
800
801
802
803
804







+


-
+

-
+


-
+

-
+









-
+


-
+





-
+




+

-
-
+
+

-
+

-
+

-
-
+
+

-
-
+
+
















-
+






-
+


-
-
+
+



-
+












-
+


+
-
+
-
-


-
+









-
-
+
+

-
+

-
+


-
+



-
+

-
+

-
-
-
-
+
+
+
+




-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+



-
-
+
+

-
-
+
+



-
-
+
+









-
-
+
+

-
-
+
+



-
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+




-
+







-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+







-
+







-
-
-
-
+
+
+
+







-
+
















-
+




-
-
-
+
+
+

-
+


-
-
-
+
+
+



-
-
-
+
+
+



-
+







 * Side effects:
 *	Arranges for tkwin, and all its managed siblings, to be re-packed at
 *	the next idle point.
 *
 *------------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
PackReqProc(
    void *clientData,	/* Packer's information about window that got
    ClientData clientData,	/* Packer's information about window that got
				 * new preferred geometry.  */
    TCL_UNUSED(Tk_Window))		/* Other Tk-related information about the
    Tk_Window tkwin)		/* Other Tk-related information about the
				 * window. */
{
    Packer *packPtr = (Packer *)clientData;
    register Packer *packPtr = clientData;

    packPtr = packPtr->containerPtr;
    packPtr = packPtr->masterPtr;
    if (!(packPtr->flags & REQUESTED_REPACK)) {
	packPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, packPtr);
    }
}

/*
 *------------------------------------------------------------------------
 *
 * PackLostContentProc --
 * PackLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a content window that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all packer-related information about the content.
 *	Forgets all packer-related information about the slave.
 *
 *------------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
PackLostContentProc(
    void *clientData,	/* Packer structure for content window that was
PackLostSlaveProc(
    ClientData clientData,	/* Packer structure for slave window that was
				 * stolen away. */
    TCL_UNUSED(Tk_Window))		/* Tk's handle for the content window. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    Packer *contentPtr = (Packer *)clientData;
    register Packer *slavePtr = clientData;

    if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
	Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
    if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
	Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
    }
    Unlink(contentPtr);
    Tk_UnmapWindow(contentPtr->tkwin);
    Unlink(slavePtr);
    Tk_UnmapWindow(slavePtr->tkwin);
}

/*
 *------------------------------------------------------------------------
 *
 * ArrangePacking --
 *
 *	This function is invoked (using the Tcl_DoWhenIdle mechanism) to
 *	re-layout a set of windows managed by the packer. It is invoked at
 *	idle time so that a series of packer requests can be merged into a
 *	single layout operation.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The packed content of containerPtr may get resized or moved.
 *	The packed slaves of masterPtr may get resized or moved.
 *
 *------------------------------------------------------------------------
 */

static void
ArrangePacking(
    void *clientData)	/* Structure describing container whose content
    ClientData clientData)	/* Structure describing master whose slaves
				 * are to be re-layed out. */
{
    Packer *containerPtr = (Packer *)clientData;
    Packer *contentPtr;
    register Packer *masterPtr = clientData;
    register Packer *slavePtr;
    int cavityX, cavityY, cavityWidth, cavityHeight;
				/* These variables keep track of the
				 * as-yet-unallocated space remaining in the
				 * middle of the container window. */
				 * middle of the master window. */
    int frameX, frameY, frameWidth, frameHeight;
				/* These variables keep track of the frame
				 * allocated to the current window. */
    int x, y, width, height;	/* These variables are used to hold the actual
				 * geometry of the current window. */
    int abort;			/* May get set to non-zero to abort this
				 * repacking operation. */
    int borderX, borderY;
    int borderTop, borderBtm;
    int borderLeft, borderRight;
    int maxWidth, maxHeight, tmp;

    containerPtr->flags &= ~REQUESTED_REPACK;
    masterPtr->flags &= ~REQUESTED_REPACK;

    /*
     * If the master has no slaves anymore, then don't do anything at all:
     * If the container has no content anymore, then leave the container's size as-is.
     * just leave the master's size as-is.
     * Otherwise there is no way to "relinquish" control over the container
     * so another geometry manager can take over.
     */

    if (containerPtr->contentPtr == NULL) {
    if (masterPtr->slavePtr == NULL) {
	return;
    }

    /*
     * Abort any nested call to ArrangePacking for this window, since we'll do
     * everything necessary here, and set up so this call can be aborted if
     * necessary.
     */

    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    containerPtr->abortPtr = &abort;
    masterPtr->abortPtr = &abort;
    abort = 0;
    Tcl_Preserve(containerPtr);
    Tcl_Preserve(masterPtr);

    /*
     * Pass #1: scan all the content to figure out the total amount of space
     * Pass #1: scan all the slaves to figure out the total amount of space
     * needed. Two separate width and height values are computed:
     *
     * width -		Holds the sum of the widths (plus padding) of all the
     *			content seen so far that were packed LEFT or RIGHT.
     *			slaves seen so far that were packed LEFT or RIGHT.
     * height -		Holds the sum of the heights (plus padding) of all the
     *			content seen so far that were packed TOP or BOTTOM.
     *			slaves seen so far that were packed TOP or BOTTOM.
     *
     * maxWidth -	Gradually builds up the width needed by the container to
     *			just barely satisfy all the content's needs. For each
     *			content, the code computes the width needed for all the
     *			content so far and updates maxWidth if the new value is
     * maxWidth -	Gradually builds up the width needed by the master to
     *			just barely satisfy all the slave's needs. For each
     *			slave, the code computes the width needed for all the
     *			slaves so far and updates maxWidth if the new value is
     *			greater.
     * maxHeight -	Same as maxWidth, except keeps height info.
     */

    width = maxWidth = Tk_InternalBorderLeft(containerPtr->tkwin) +
	    Tk_InternalBorderRight(containerPtr->tkwin);
    height = maxHeight = Tk_InternalBorderTop(containerPtr->tkwin) +
	    Tk_InternalBorderBottom(containerPtr->tkwin);
    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	if ((contentPtr->side == TOP) || (contentPtr->side == BOTTOM)) {
	    tmp = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padX + contentPtr->iPadX + width;
    width = maxWidth = Tk_InternalBorderLeft(masterPtr->tkwin) +
	    Tk_InternalBorderRight(masterPtr->tkwin);
    height = maxHeight = Tk_InternalBorderTop(masterPtr->tkwin) +
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	if ((slavePtr->side == TOP) || (slavePtr->side == BOTTOM)) {
	    tmp = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padX + slavePtr->iPadX + width;
	    if (tmp > maxWidth) {
		maxWidth = tmp;
	    }
	    height += Tk_ReqHeight(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padY + contentPtr->iPadY;
	    height += Tk_ReqHeight(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padY + slavePtr->iPadY;
	} else {
	    tmp = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padY + contentPtr->iPadY + height;
	    tmp = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padY + slavePtr->iPadY + height;
	    if (tmp > maxHeight) {
		maxHeight = tmp;
	    }
	    width += Tk_ReqWidth(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padX + contentPtr->iPadX;
	    width += Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padX + slavePtr->iPadX;
	}
    }
    if (width > maxWidth) {
	maxWidth = width;
    }
    if (height > maxHeight) {
	maxHeight = height;
    }

    if (maxWidth < Tk_MinReqWidth(containerPtr->tkwin)) {
	maxWidth = Tk_MinReqWidth(containerPtr->tkwin);
    if (maxWidth < Tk_MinReqWidth(masterPtr->tkwin)) {
	maxWidth = Tk_MinReqWidth(masterPtr->tkwin);
    }
    if (maxHeight < Tk_MinReqHeight(containerPtr->tkwin)) {
	maxHeight = Tk_MinReqHeight(containerPtr->tkwin);
    if (maxHeight < Tk_MinReqHeight(masterPtr->tkwin)) {
	maxHeight = Tk_MinReqHeight(masterPtr->tkwin);
    }

    /*
     * If the total amount of space needed in the container window has changed,
     * If the total amount of space needed in the master window has changed,
     * and if we're propagating geometry information, then notify the next
     * geometry manager up and requeue ourselves to start again after the
     * container has had a chance to resize us.
     * master has had a chance to resize us.
     */

    if (((maxWidth != Tk_ReqWidth(containerPtr->tkwin))
	    || (maxHeight != Tk_ReqHeight(containerPtr->tkwin)))
	    && !(containerPtr->flags & DONT_PROPAGATE)) {
	Tk_GeometryRequest(containerPtr->tkwin, maxWidth, maxHeight);
	containerPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, containerPtr);
    if (((maxWidth != Tk_ReqWidth(masterPtr->tkwin))
	    || (maxHeight != Tk_ReqHeight(masterPtr->tkwin)))
	    && !(masterPtr->flags & DONT_PROPAGATE)) {
	Tk_GeometryRequest(masterPtr->tkwin, maxWidth, maxHeight);
	masterPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, masterPtr);
	goto done;
    }

    /*
     * Pass #2: scan the content a second time assigning new sizes. The
     * Pass #2: scan the slaves a second time assigning new sizes. The
     * "cavity" variables keep track of the unclaimed space in the cavity of
     * the window; this shrinks inward as we allocate windows around the
     * edges. The "frame" variables keep track of the space allocated to the
     * current window and its frame. The current window is then placed
     * somewhere inside the frame, depending on anchor.
     */

    cavityX = x = Tk_InternalBorderLeft(containerPtr->tkwin);
    cavityY = y = Tk_InternalBorderTop(containerPtr->tkwin);
    cavityWidth = Tk_Width(containerPtr->tkwin) -
	    Tk_InternalBorderLeft(containerPtr->tkwin) -
	    Tk_InternalBorderRight(containerPtr->tkwin);
    cavityHeight = Tk_Height(containerPtr->tkwin) -
	    Tk_InternalBorderTop(containerPtr->tkwin) -
	    Tk_InternalBorderBottom(containerPtr->tkwin);
    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
	    contentPtr = contentPtr->nextPtr) {
	if ((contentPtr->side == TOP) || (contentPtr->side == BOTTOM)) {
    cavityX = x = Tk_InternalBorderLeft(masterPtr->tkwin);
    cavityY = y = Tk_InternalBorderTop(masterPtr->tkwin);
    cavityWidth = Tk_Width(masterPtr->tkwin) -
	    Tk_InternalBorderLeft(masterPtr->tkwin) -
	    Tk_InternalBorderRight(masterPtr->tkwin);
    cavityHeight = Tk_Height(masterPtr->tkwin) -
	    Tk_InternalBorderTop(masterPtr->tkwin) -
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	if ((slavePtr->side == TOP) || (slavePtr->side == BOTTOM)) {
	    frameWidth = cavityWidth;
	    frameHeight = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padY + contentPtr->iPadY;
	    if (contentPtr->flags & EXPAND) {
		frameHeight += YExpansion(contentPtr, cavityHeight);
	    frameHeight = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padY + slavePtr->iPadY;
	    if (slavePtr->flags & EXPAND) {
		frameHeight += YExpansion(slavePtr, cavityHeight);
	    }
	    cavityHeight -= frameHeight;
	    if (cavityHeight < 0) {
		frameHeight += cavityHeight;
		cavityHeight = 0;
	    }
	    frameX = cavityX;
	    if (contentPtr->side == TOP) {
	    if (slavePtr->side == TOP) {
		frameY = cavityY;
		cavityY += frameHeight;
	    } else {
		frameY = cavityY + cavityHeight;
	    }
	} else {
	    frameHeight = cavityHeight;
	    frameWidth = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->doubleBw
		    + contentPtr->padX + contentPtr->iPadX;
	    if (contentPtr->flags & EXPAND) {
		frameWidth += XExpansion(contentPtr, cavityWidth);
	    frameWidth = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw
		    + slavePtr->padX + slavePtr->iPadX;
	    if (slavePtr->flags & EXPAND) {
		frameWidth += XExpansion(slavePtr, cavityWidth);
	    }
	    cavityWidth -= frameWidth;
	    if (cavityWidth < 0) {
		frameWidth += cavityWidth;
		cavityWidth = 0;
	    }
	    frameY = cavityY;
	    if (contentPtr->side == LEFT) {
	    if (slavePtr->side == LEFT) {
		frameX = cavityX;
		cavityX += frameWidth;
	    } else {
		frameX = cavityX + cavityWidth;
	    }
	}

	/*
	 * Now that we've got the size of the frame for the window, compute
	 * the window's actual size and location using the fill, padding, and
	 * frame factors. The variables "borderX" and "borderY" are used to
	 * handle the differences between old-style packing and the new style
	 * (in old-style, iPadX and iPadY are always zero and padding is
	 * completely ignored except when computing frame size).
	 */

	if (contentPtr->flags & OLD_STYLE) {
	if (slavePtr->flags & OLD_STYLE) {
	    borderX = borderY = 0;
	    borderTop = borderBtm = 0;
	    borderLeft = borderRight = 0;
	} else {
	    borderX = contentPtr->padX;
	    borderY = contentPtr->padY;
	    borderLeft = contentPtr->padLeft;
	    borderX = slavePtr->padX;
	    borderY = slavePtr->padY;
	    borderLeft = slavePtr->padLeft;
	    borderRight = borderX - borderLeft;
	    borderTop = contentPtr->padTop;
	    borderTop = slavePtr->padTop;
	    borderBtm = borderY - borderTop;
	}
	width = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->doubleBw
		+ contentPtr->iPadX;
	if ((contentPtr->flags & FILLX)
	width = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw
		+ slavePtr->iPadX;
	if ((slavePtr->flags & FILLX)
		|| (width > (frameWidth - borderX))) {
	    width = frameWidth - borderX;
	}
	height = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->doubleBw
		+ contentPtr->iPadY;
	if ((contentPtr->flags & FILLY)
	height = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->doubleBw
		+ slavePtr->iPadY;
	if ((slavePtr->flags & FILLY)
		|| (height > (frameHeight - borderY))) {
	    height = frameHeight - borderY;
	}
	switch (contentPtr->anchor) {
	switch (slavePtr->anchor) {
	case TK_ANCHOR_N:
	    x = frameX + (borderLeft + frameWidth - width - borderRight)/2;
	    y = frameY + borderTop;
	    break;
	case TK_ANCHOR_NE:
	    x = frameX + frameWidth - width - borderRight;
	    y = frameY + borderTop;
721
722
723
724
725
726
727
728

729
730
731


732
733
734


735
736
737
738

739
740
741
742

743
744

745
746
747
748
749
750





751
752
753
754
755
756
757
758


759
760
761
762


763
764
765
766
767
768


769
770

771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788


789
790
791
792
793
794
795
796

797
798
799
800
801
802
803
804
805
806
807
808
809
810
811

812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834




835
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877

878
879

880
881
882
883
884
885
886
887
888
889
890
891
892
893




894
895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
823
824
825
826
827
828
829

830
831
832
833
834
835
836


837
838
839
840
841

842
843
844
845

846
847

848
849





850
851
852
853
854
855
856
857
858
859
860


861
862
863
864


865
866
867
868
869
870


871
872
873

874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890


891
892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907
908
909
910
911
912
913
914

915
916

917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934




935
936
937
938
939
940
941
942
943
944
945
946

947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980

981
982

983
984
985
986
987
988
989
990
991
992
993




994
995
996
997
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013







-
+



+
+

-
-
+
+



-
+



-
+

-
+

-
-
-
-
-
+
+
+
+
+






-
-
+
+


-
-
+
+




-
-
+
+

-
+
















-
-
+
+







-
+














-
+

-
+

















-
-
-
-
+
+
+
+








-
+


















-
+














-
+

-
+










-
-
-
-
+
+
+
+








-
+







	    x = frameX + borderLeft;
	    y = frameY + (borderTop + frameHeight - height - borderBtm)/2;
	    break;
	case TK_ANCHOR_NW:
	    x = frameX + borderLeft;
	    y = frameY + borderTop;
	    break;
	default:
	case TK_ANCHOR_CENTER:
	    x = frameX + (borderLeft + frameWidth - width - borderRight)/2;
	    y = frameY + (borderTop + frameHeight - height - borderBtm)/2;
	    break;
	default:
	    Tcl_Panic("bad frame factor in ArrangePacking");
	}
	width -= contentPtr->doubleBw;
	height -= contentPtr->doubleBw;
	width -= slavePtr->doubleBw;
	height -= slavePtr->doubleBw;

	/*
	 * The final step is to set the position, size, and mapped/unmapped
	 * state of the content. If the content is a child of the container, then do
	 * state of the slave. If the slave is a child of the master, then do
	 * this here. Otherwise let Tk_MaintainGeometry do the work.
	 */

	if (containerPtr->tkwin == Tk_Parent(contentPtr->tkwin)) {
	if (masterPtr->tkwin == Tk_Parent(slavePtr->tkwin)) {
	    if ((width <= 0) || (height <= 0)) {
		Tk_UnmapWindow(contentPtr->tkwin);
		Tk_UnmapWindow(slavePtr->tkwin);
	    } else {
		if ((x != Tk_X(contentPtr->tkwin))
			|| (y != Tk_Y(contentPtr->tkwin))
			|| (width != Tk_Width(contentPtr->tkwin))
			|| (height != Tk_Height(contentPtr->tkwin))) {
		    Tk_MoveResizeWindow(contentPtr->tkwin, x, y, width, height);
		if ((x != Tk_X(slavePtr->tkwin))
			|| (y != Tk_Y(slavePtr->tkwin))
			|| (width != Tk_Width(slavePtr->tkwin))
			|| (height != Tk_Height(slavePtr->tkwin))) {
		    Tk_MoveResizeWindow(slavePtr->tkwin, x, y, width, height);
		}
		if (abort) {
		    goto done;
		}

		/*
		 * Don't map the content if the container isn't mapped: wait until
		 * the container gets mapped later.
		 * Don't map the slave if the master isn't mapped: wait until
		 * the master gets mapped later.
		 */

		if (Tk_IsMapped(containerPtr->tkwin)) {
		    Tk_MapWindow(contentPtr->tkwin);
		if (Tk_IsMapped(masterPtr->tkwin)) {
		    Tk_MapWindow(slavePtr->tkwin);
		}
	    }
	} else {
	    if ((width <= 0) || (height <= 0)) {
		Tk_UnmaintainGeometry(contentPtr->tkwin, containerPtr->tkwin);
		Tk_UnmapWindow(contentPtr->tkwin);
		Tk_UnmaintainGeometry(slavePtr->tkwin, masterPtr->tkwin);
		Tk_UnmapWindow(slavePtr->tkwin);
	    } else {
		Tk_MaintainGeometry(contentPtr->tkwin, containerPtr->tkwin,
		Tk_MaintainGeometry(slavePtr->tkwin, masterPtr->tkwin,
			x, y, width, height);
	    }
	}

	/*
	 * Changes to the window's structure could cause almost anything to
	 * happen, including deleting the parent or child. If this happens,
	 * we'll be told to abort.
	 */

	if (abort) {
	    goto done;
	}
    }

  done:
    containerPtr->abortPtr = NULL;
    Tcl_Release(containerPtr);
    masterPtr->abortPtr = NULL;
    Tcl_Release(masterPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * XExpansion --
 *
 *	Given a list of packed content, the first of which is packed on the
 *	Given a list of packed slaves, the first of which is packed on the
 *	left or right and is expandable, compute how much to expand the child.
 *
 * Results:
 *	The return value is the number of additional pixels to give to the
 *	child.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
XExpansion(
    Packer *contentPtr,	/* First in list of remaining content. */
    register Packer *slavePtr,	/* First in list of remaining slaves. */
    int cavityWidth)		/* Horizontal space left for all remaining
				 * content. */
				 * slaves. */
{
    int numExpand, minExpand, curExpand;
    int childWidth;

    /*
     * This function is tricky because windows packed top or bottom can be
     * interspersed among expandable windows packed left or right. Scan
     * through the list, keeping a running sum of the widths of all left and
     * right windows (actually, count the cavity space not allocated) and a
     * running count of all expandable left and right windows. At each top or
     * bottom window, and at the end of the list, compute the expansion factor
     * that seems reasonable at that point. Return the smallest factor seen at
     * any of these points.
     */

    minExpand = cavityWidth;
    numExpand = 0;
    for ( ; contentPtr != NULL; contentPtr = contentPtr->nextPtr) {
	childWidth = Tk_ReqWidth(contentPtr->tkwin) + contentPtr->doubleBw
		+ contentPtr->padX + contentPtr->iPadX;
	if ((contentPtr->side == TOP) || (contentPtr->side == BOTTOM)) {
    for ( ; slavePtr != NULL; slavePtr = slavePtr->nextPtr) {
	childWidth = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->doubleBw
		+ slavePtr->padX + slavePtr->iPadX;
	if ((slavePtr->side == TOP) || (slavePtr->side == BOTTOM)) {
	    if (numExpand) {
		curExpand = (cavityWidth - childWidth)/numExpand;
		if (curExpand < minExpand) {
		    minExpand = curExpand;
		}
	    }
	} else {
	    cavityWidth -= childWidth;
	    if (contentPtr->flags & EXPAND) {
	    if (slavePtr->flags & EXPAND) {
		numExpand++;
	    }
	}
    }
    if (numExpand) {
	curExpand = cavityWidth/numExpand;
	if (curExpand < minExpand) {
	    minExpand = curExpand;
	}
    }
    return (minExpand < 0) ? 0 : minExpand;
}

/*
 *----------------------------------------------------------------------
 *
 * YExpansion --
 *
 *	Given a list of packed content, the first of which is packed on the top
 *	Given a list of packed slaves, the first of which is packed on the top
 *	or bottom and is expandable, compute how much to expand the child.
 *
 * Results:
 *	The return value is the number of additional pixels to give to the
 *	child.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
YExpansion(
    Packer *contentPtr,	/* First in list of remaining content. */
    register Packer *slavePtr,	/* First in list of remaining slaves. */
    int cavityHeight)		/* Vertical space left for all remaining
				 * content. */
				 * slaves. */
{
    int numExpand, minExpand, curExpand;
    int childHeight;

    /*
     * See comments for XExpansion.
     */

    minExpand = cavityHeight;
    numExpand = 0;
    for ( ; contentPtr != NULL; contentPtr = contentPtr->nextPtr) {
	childHeight = Tk_ReqHeight(contentPtr->tkwin) + contentPtr->doubleBw
		+ contentPtr->padY + contentPtr->iPadY;
	if ((contentPtr->side == LEFT) || (contentPtr->side == RIGHT)) {
    for ( ; slavePtr != NULL; slavePtr = slavePtr->nextPtr) {
	childHeight = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->doubleBw
		+ slavePtr->padY + slavePtr->iPadY;
	if ((slavePtr->side == LEFT) || (slavePtr->side == RIGHT)) {
	    if (numExpand) {
		curExpand = (cavityHeight - childHeight)/numExpand;
		if (curExpand < minExpand) {
		    minExpand = curExpand;
		}
	    }
	} else {
	    cavityHeight -= childHeight;
	    if (contentPtr->flags & EXPAND) {
	    if (slavePtr->flags & EXPAND) {
		numExpand++;
	    }
	}
    }
    if (numExpand) {
	curExpand = cavityHeight/numExpand;
	if (curExpand < minExpand) {
933
934
935
936
937
938
939
940

941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

959
960

961
962

963
964

965
966
967
968
969
970
971
972
973
974
975
976
977
978

















































































































































































































































979
980
981
982
983
984

985
986
987
988
989
990

991
992
993
994
995
996
997

998
999

1000
1001
1002


1003
1004
1005
1006


1007
1008

1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020



1021
1022
1023


1024
1025
1026

1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037
1038



1039
1040
1041
1042
1043
1044
1045
1046
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

1062
1063

1064
1065

1066
1067

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341

1342
1343

1344
1345


1346
1347
1348
1349


1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1360
1361
1362



1363
1364
1365
1366


1367
1368
1369
1370

1371
1372
1373

1374
1375



1376
1377



1378
1379
1380

1381
1382
1383
1384
1385
1386
1387







-
+

















-
+

-
+

-
+

-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+





-
+






-
+

-
+

-
-
+
+


-
-
+
+

-
+









-
-
-
+
+
+

-
-
+
+


-
+


-
+

-
-
-


-
-
-
+
+
+
-







 */

static Packer *
GetPacker(
    Tk_Window tkwin)		/* Token for window for which packer structure
				 * is desired. */
{
    Packer *packPtr;
    register Packer *packPtr;
    Tcl_HashEntry *hPtr;
    int isNew;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (!dispPtr->packInit) {
	dispPtr->packInit = 1;
	Tcl_InitHashTable(&dispPtr->packerHashTable, TCL_ONE_WORD_KEYS);
    }

    /*
     * See if there's already packer for this window. If not, then create a
     * new one.
     */

    hPtr = Tcl_CreateHashEntry(&dispPtr->packerHashTable, (char *) tkwin,
	    &isNew);
    if (!isNew) {
	return (Packer *)Tcl_GetHashValue(hPtr);
	return Tcl_GetHashValue(hPtr);
    }
    packPtr = (Packer *)ckalloc(sizeof(Packer));
    packPtr = ckalloc(sizeof(Packer));
    packPtr->tkwin = tkwin;
    packPtr->containerPtr = NULL;
    packPtr->masterPtr = NULL;
    packPtr->nextPtr = NULL;
    packPtr->contentPtr = NULL;
    packPtr->slavePtr = NULL;
    packPtr->side = TOP;
    packPtr->anchor = TK_ANCHOR_CENTER;
    packPtr->padX = packPtr->padY = 0;
    packPtr->padLeft = packPtr->padTop = 0;
    packPtr->iPadX = packPtr->iPadY = 0;
    packPtr->doubleBw = 2*Tk_Changes(tkwin)->border_width;
    packPtr->abortPtr = NULL;
    packPtr->flags = 0;
    Tcl_SetHashValue(hPtr, packPtr);
    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
	    PackStructureProc, packPtr);
    return packPtr;
}

/*
 *------------------------------------------------------------------------
 *
 * PackAfter --
 *
 *	This function does most of the real work of adding one or more windows
 *	into the packing order for its master.
 *
 * Results:
 *	A standard Tcl return value.
 *
 * Side effects:
 *	The geometry of the specified windows may change, both now and again
 *	in the future.
 *
 *------------------------------------------------------------------------
 */

#ifndef TK_NO_DEPRECATED
static int
PackAfter(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Packer *prevPtr,		/* Pack windows in argv just after this
				 * window; NULL means pack as first child of
				 * masterPtr. */
    Packer *masterPtr,		/* Master in which to pack windows. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[])	/* Array of lists, each containing 2 elements:
				 * window name and side against which to
				 * pack. */
{
    register Packer *packPtr;
    Tk_Window tkwin, ancestor, parent;
    Tcl_Obj **options;
    int index, optionCount, c;

    /*
     * Iterate over all of the window specifiers, each consisting of two
     * arguments. The first argument contains the window name and the
     * additional arguments contain options such as "top" or "padx 20".
     */

    for ( ; objc > 0; objc -= 2, objv += 2, prevPtr = packPtr) {
	if (objc < 2) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "wrong # args: window \"%s\" should be followed by options",
		    Tcl_GetString(objv[0])));
	    Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Find the packer for the window to be packed, and make sure that the
	 * window in which it will be packed is either its or a descendant of
	 * its parent.
	 */

	if (TkGetWindowFromObj(interp, masterPtr->tkwin, objv[0], &tkwin)
		!= TCL_OK) {
	    return TCL_ERROR;
	}

	parent = Tk_Parent(tkwin);
	for (ancestor = masterPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == parent) {
		break;
	    }
	    if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) {
	    badWindow:
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't pack %s inside %s", Tcl_GetString(objv[0]),
			Tk_PathName(masterPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
		return TCL_ERROR;
	    }
	}
	if (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY) {
	    goto badWindow;
	}
	if (tkwin == masterPtr->tkwin) {
	    goto badWindow;
	}
	packPtr = GetPacker(tkwin);

	/*
	 * Process options for this window.
	 */

	if (Tcl_ListObjGetElements(interp, objv[1], &optionCount, &options)
		!= TCL_OK) {
	    return TCL_ERROR;
	}
	packPtr->side = TOP;
	packPtr->anchor = TK_ANCHOR_CENTER;
	packPtr->padX = packPtr->padY = 0;
	packPtr->padLeft = packPtr->padTop = 0;
	packPtr->iPadX = packPtr->iPadY = 0;
	packPtr->flags &= ~(FILLX|FILLY|EXPAND);
	packPtr->flags |= OLD_STYLE;
	for (index = 0 ; index < optionCount; index++) {
	    Tcl_Obj *curOptPtr = options[index];
	    const char *curOpt = Tcl_GetString(curOptPtr);
	    size_t length = curOptPtr->length;

	    c = curOpt[0];

	    if ((c == 't')
		    && (strncmp(curOpt, "top", length)) == 0) {
		packPtr->side = TOP;
	    } else if ((c == 'b')
		    && (strncmp(curOpt, "bottom", length)) == 0) {
		packPtr->side = BOTTOM;
	    } else if ((c == 'l')
		    && (strncmp(curOpt, "left", length)) == 0) {
		packPtr->side = LEFT;
	    } else if ((c == 'r')
		    && (strncmp(curOpt, "right", length)) == 0) {
		packPtr->side = RIGHT;
	    } else if ((c == 'e')
		    && (strncmp(curOpt, "expand", length)) == 0) {
		packPtr->flags |= EXPAND;
	    } else if ((c == 'f')
		    && (strcmp(curOpt, "fill")) == 0) {
		packPtr->flags |= FILLX|FILLY;
	    } else if ((length == 5) && (strcmp(curOpt, "fillx")) == 0) {
		packPtr->flags |= FILLX;
	    } else if ((length == 5) && (strcmp(curOpt, "filly")) == 0) {
		packPtr->flags |= FILLY;
	    } else if ((c == 'p') && (strcmp(curOpt, "padx")) == 0) {
		if (optionCount < (index+2)) {
		missingPad:
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "wrong # args: \"%s\" option must be"
			    " followed by screen distance", curOpt));
		    Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER",
			    NULL);
		    return TCL_ERROR;
		}
		if (TkParsePadAmount(interp, tkwin, options[index+1],
			&packPtr->padLeft, &packPtr->padX) != TCL_OK) {
		    return TCL_ERROR;
		}
		packPtr->padX /= 2;
		packPtr->padLeft /= 2;
		packPtr->iPadX = 0;
		index++;
	    } else if ((c == 'p') && (strcmp(curOpt, "pady")) == 0) {
		if (optionCount < (index+2)) {
		    goto missingPad;
		}
		if (TkParsePadAmount(interp, tkwin, options[index+1],
			&packPtr->padTop, &packPtr->padY) != TCL_OK) {
		    return TCL_ERROR;
		}
		packPtr->padY /= 2;
		packPtr->padTop /= 2;
		packPtr->iPadY = 0;
		index++;
	    } else if ((c == 'f') && (length > 1)
		    && (strncmp(curOpt, "frame", (size_t) length) == 0)) {
		if (optionCount < (index+2)) {
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
			    "wrong # args: \"frame\""
			    " option must be followed by anchor point", -1));
		    Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER",
			    NULL);
		    return TCL_ERROR;
		}
		if (Tk_GetAnchorFromObj(interp, options[index+1],
			&packPtr->anchor) != TCL_OK) {
		    return TCL_ERROR;
		}
		index++;
	    } else {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"bad option \"%s\": should be top, bottom, left,"
			" right, expand, fill, fillx, filly, padx, pady, or"
			" frame", curOpt));
		Tcl_SetErrorCode(interp, "TK", "OLDPACK", "BAD_PARAMETER",
			NULL);
		return TCL_ERROR;
	    }
	}

	if (packPtr != prevPtr) {
	    /*
	     * Unpack this window if it's currently packed.
	     */

	    if (packPtr->masterPtr != NULL) {
		if ((packPtr->masterPtr != masterPtr) &&
			(packPtr->masterPtr->tkwin
			!= Tk_Parent(packPtr->tkwin))) {
		    Tk_UnmaintainGeometry(packPtr->tkwin,
			    packPtr->masterPtr->tkwin);
		}
		Unlink(packPtr);
	    }

	    /*
	     * Add the window in the correct place in its master's packing
	     * order, then make sure that the window is managed by us.
	     */

	    packPtr->masterPtr = masterPtr;
	    if (prevPtr == NULL) {
		packPtr->nextPtr = masterPtr->slavePtr;
		masterPtr->slavePtr = packPtr;
	    } else {
		packPtr->nextPtr = prevPtr->nextPtr;
		prevPtr->nextPtr = packPtr;
	    }
	    Tk_ManageGeometry(tkwin, &packerType, packPtr);

	    if (!(masterPtr->flags & DONT_PROPAGATE)) {
		if (TkSetGeometryMaster(interp, masterPtr->tkwin, "pack")
			!= TCL_OK) {
		    Tk_ManageGeometry(tkwin, NULL, NULL);
		    Unlink(packPtr);
		    return TCL_ERROR;
		}
		masterPtr->flags |= ALLOCED_MASTER;
	    }
	}
    }

    /*
     * Arrange for the master to be re-packed at the first idle moment.
     */

    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    if (!(masterPtr->flags & REQUESTED_REPACK)) {
	masterPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, masterPtr);
    }
    return TCL_OK;
}
#endif /* !TK_NO_DEPRECATED */

/*
 *----------------------------------------------------------------------
 *
 * Unlink --
 *
 *	Remove a packer from its container's list of content.
 *	Remove a packer from its master's list of slaves.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The container will be scheduled for repacking.
 *	The master will be scheduled for repacking.
 *
 *----------------------------------------------------------------------
 */

static void
Unlink(
    Packer *packPtr)	/* Window to unlink. */
    register Packer *packPtr)	/* Window to unlink. */
{
    Packer *containerPtr, *packPtr2;
    register Packer *masterPtr, *packPtr2;

    containerPtr = packPtr->containerPtr;
    if (containerPtr == NULL) {
    masterPtr = packPtr->masterPtr;
    if (masterPtr == NULL) {
	return;
    }
    if (containerPtr->contentPtr == packPtr) {
	containerPtr->contentPtr = packPtr->nextPtr;
    if (masterPtr->slavePtr == packPtr) {
	masterPtr->slavePtr = packPtr->nextPtr;
    } else {
	for (packPtr2 = containerPtr->contentPtr; ; packPtr2 = packPtr2->nextPtr) {
	for (packPtr2 = masterPtr->slavePtr; ; packPtr2 = packPtr2->nextPtr) {
	    if (packPtr2 == NULL) {
		Tcl_Panic("Unlink couldn't find previous window");
	    }
	    if (packPtr2->nextPtr == packPtr) {
		packPtr2->nextPtr = packPtr->nextPtr;
		break;
	    }
	}
    }
    if (!(containerPtr->flags & REQUESTED_REPACK)) {
	containerPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, containerPtr);
    if (!(masterPtr->flags & REQUESTED_REPACK)) {
	masterPtr->flags |= REQUESTED_REPACK;
	Tcl_DoWhenIdle(ArrangePacking, masterPtr);
    }
    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }

    packPtr->containerPtr = NULL;
    packPtr->masterPtr = NULL;

    /*
     * If we have emptied this container from content it means we are no longer
     * If we have emptied this master from slaves it means we are no longer
     * handling it and should mark it as free.
     *
     * Send the event "NoManagedChild" to the container to inform it about there
     * being no managed children inside it.
     */

    if ((containerPtr->contentPtr == NULL) && (containerPtr->flags & ALLOCED_CONTAINER)) {
	TkFreeGeometryContainer(containerPtr->tkwin, "pack");
	containerPtr->flags &= ~ALLOCED_CONTAINER;
    if (masterPtr->slavePtr == NULL && masterPtr->flags & ALLOCED_MASTER) {
	TkFreeGeometryMaster(masterPtr->tkwin, "pack");
	masterPtr->flags &= ~ALLOCED_MASTER;
	Tk_SendVirtualEvent(containerPtr->tkwin, "NoManagedChild", NULL);
    }

}

/*
 *----------------------------------------------------------------------
 *
1057
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067

1068
1069
1070

1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091

1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102

1103
1104
1105

1106
1107
1108
1109
1110

1111
1112

1113
1114
1115


1116
1117
1118
1119

1120
1121

1122
1123
1124
1125
1126
1127
1128
1129
1130
1131







1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144

1145
1146
1147
1148


1149
1150
1151

1152
1153
1154
1155
1156
1157

1158
1159
1160

1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178


1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191

1192
1193
1194

1195
1196
1197
1198
1199
1200
1201
1202


1203
1204
1205
1206
1207
1208
1209
1210
1398
1399
1400
1401
1402
1403
1404


1405


1406

1407

1408
1409



1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432

1433
1434
1435
1436

1437
1438
1439

1440
1441
1442
1443
1444

1445
1446

1447
1448


1449
1450
1451
1452
1453

1454
1455

1456
1457
1458
1459







1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473
1474
1475
1476
1477
1478

1479
1480
1481


1482
1483
1484
1485

1486
1487
1488
1489
1490
1491

1492
1493
1494

1495
1496
1497
1498

1499
1500
1501
1502
1503
1504
1505
1506
1507
1508

1509
1510
1511


1512
1513
1514
1515
1516
1517
1518
1519

1520
1521
1522
1523
1524
1525

1526
1527
1528

1529
1530
1531
1532
1533
1534
1535


1536
1537

1538
1539
1540
1541
1542
1543
1544







-
-
+
-
-
+
-

-
+

-
-
-
















-
+






-
+



-
+


-
+




-
+

-
+

-
-
+
+



-
+

-
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+





-
+






-
+


-
-
+
+


-
+





-
+


-
+



-
+









-
+


-
-
+
+






-
+





-
+


-
+






-
-
+
+
-







 *	Everything associated with the packer is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyPacker(
#if TCL_MAJOR_VERSION > 8
    void *memPtr)		/* Info about packed window that is now dead. */
    void *memPtr)		/* Info about packed window that is now
#else
    char *memPtr)
				 * dead. */
#endif
{
    Packer *packPtr = (Packer *)memPtr;
    register Packer *packPtr = memPtr;

    if (packPtr->flags & REQUESTED_REPACK) {
	Tcl_CancelIdleCall(ArrangePacking, packPtr);
    }
    ckfree(packPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * PackStructureProc --
 *
 *	This function is invoked by the Tk event dispatcher in response to
 *	StructureNotify events.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	If a window was just deleted, clean up all its packer-related
 *	information. If it was just resized, repack its content, if any.
 *	information. If it was just resized, repack its slaves, if any.
 *
 *----------------------------------------------------------------------
 */

static void
PackStructureProc(
    void *clientData,	/* Our information about window referred to by
    ClientData clientData,	/* Our information about window referred to by
				 * eventPtr. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Packer *packPtr = (Packer *)clientData;
    register Packer *packPtr = clientData;

    if (eventPtr->type == ConfigureNotify) {
	if ((packPtr->contentPtr != NULL)
	if ((packPtr->slavePtr != NULL)
		&& !(packPtr->flags & REQUESTED_REPACK)) {
	    packPtr->flags |= REQUESTED_REPACK;
	    Tcl_DoWhenIdle(ArrangePacking, packPtr);
	}
	if ((packPtr->containerPtr != NULL)
	if ((packPtr->masterPtr != NULL)
	        && (packPtr->doubleBw != 2*Tk_Changes(packPtr->tkwin)->border_width)) {
	    if (!(packPtr->containerPtr->flags & REQUESTED_REPACK)) {
	    if (!(packPtr->masterPtr->flags & REQUESTED_REPACK)) {
		packPtr->doubleBw = 2*Tk_Changes(packPtr->tkwin)->border_width;
		packPtr->containerPtr->flags |= REQUESTED_REPACK;
		Tcl_DoWhenIdle(ArrangePacking, packPtr->containerPtr);
		packPtr->masterPtr->flags |= REQUESTED_REPACK;
		Tcl_DoWhenIdle(ArrangePacking, packPtr->masterPtr);
	    }
	}
    } else if (eventPtr->type == DestroyNotify) {
	Packer *contentPtr, *nextPtr;
	register Packer *slavePtr, *nextPtr;

	if (packPtr->containerPtr != NULL) {
	if (packPtr->masterPtr != NULL) {
	    Unlink(packPtr);
	}

	for (contentPtr = packPtr->contentPtr; contentPtr != NULL;
		contentPtr = nextPtr) {
	    Tk_ManageGeometry(contentPtr->tkwin, NULL, NULL);
	    Tk_UnmapWindow(contentPtr->tkwin);
	    contentPtr->containerPtr = NULL;
	    nextPtr = contentPtr->nextPtr;
	    contentPtr->nextPtr = NULL;
	for (slavePtr = packPtr->slavePtr; slavePtr != NULL;
		slavePtr = nextPtr) {
	    Tk_ManageGeometry(slavePtr->tkwin, NULL, NULL);
	    Tk_UnmapWindow(slavePtr->tkwin);
	    slavePtr->masterPtr = NULL;
	    nextPtr = slavePtr->nextPtr;
	    slavePtr->nextPtr = NULL;
	}

	if (packPtr->tkwin != NULL) {
	    TkDisplay *dispPtr = ((TkWindow *) packPtr->tkwin)->dispPtr;
            Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->packerHashTable,
		    packPtr->tkwin));
		    (char *) packPtr->tkwin));
	}

	if (packPtr->flags & REQUESTED_REPACK) {
	    Tcl_CancelIdleCall(ArrangePacking, packPtr);
	}
	packPtr->tkwin = NULL;
	Tcl_EventuallyFree(packPtr, DestroyPacker);
	Tcl_EventuallyFree(packPtr, (Tcl_FreeProc *) DestroyPacker);
    } else if (eventPtr->type == MapNotify) {
	/*
	 * When a container gets mapped, must redo the geometry computation so
	 * that all of its content get remapped.
	 * When a master gets mapped, must redo the geometry computation so
	 * that all of its slaves get remapped.
	 */

	if ((packPtr->contentPtr != NULL)
	if ((packPtr->slavePtr != NULL)
		&& !(packPtr->flags & REQUESTED_REPACK)) {
	    packPtr->flags |= REQUESTED_REPACK;
	    Tcl_DoWhenIdle(ArrangePacking, packPtr);
	}
    } else if (eventPtr->type == UnmapNotify) {
	Packer *packPtr2;
	register Packer *packPtr2;

	/*
	 * Unmap all of the content when the container gets unmapped, so that they
	 * Unmap all of the slaves when the master gets unmapped, so that they
	 * don't bother to keep redisplaying themselves.
	 */

	for (packPtr2 = packPtr->contentPtr; packPtr2 != NULL;
	for (packPtr2 = packPtr->slavePtr; packPtr2 != NULL;
	     packPtr2 = packPtr2->nextPtr) {
	    Tk_UnmapWindow(packPtr2->tkwin);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigureContent --
 * ConfigureSlaves --
 *
 *	This implements the guts of the "pack configure" command. Given a list
 *	of content and configuration options, it arranges for the packer to
 *	manage the content and sets the specified options.
 *	of slaves and configuration options, it arranges for the packer to
 *	manage the slaves and sets the specified options.
 *
 * Results:
 *	TCL_OK is returned if all went well. Otherwise, TCL_ERROR is returned
 *	and the interp's result is set to contain an error message.
 *
 * Side effects:
 *	Content windows get taken over by the packer.
 *	Slave windows get taken over by the packer.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureContent(
ConfigureSlaves(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Window tkwin,		/* Any window in application containing
				 * content. Used to look up content names. */
				 * slaves. Used to look up slave names. */
    int objc,			/* Number of elements in argv. */
    Tcl_Obj *const objv[])	/* Argument objects: contains one or more
				 * window names followed by any number of
				 * "option value" pairs. Caller must make sure
				 * that there is at least one window name. */
{
    Packer *containerPtr, *contentPtr, *prevPtr, *otherPtr;
    Tk_Window other, content, parent, ancestor;
    Packer *masterPtr, *slavePtr, *prevPtr, *otherPtr;
    Tk_Window other, slave, parent, ancestor;
    TkWindow *container;
    int i, j, numWindows, tmp, positionGiven;
    const char *string;
    static const char *const optionStrings[] = {
	"-after", "-anchor", "-before", "-expand", "-fill",
	"-in", "-ipadx", "-ipady", "-padx", "-pady", "-side", NULL };
    enum options {
	CONF_AFTER, CONF_ANCHOR, CONF_BEFORE, CONF_EXPAND, CONF_FILL,
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229




1230
1231
1232
1233
1234
1235

1236
1237
1238
1239

1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250


1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264







1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276


1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296
1297

1298
1299
1300
1301
1302

1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318


1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335

1336
1337
1338
1339
1340
1341

1342
1343

1344
1345

1346
1347

1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363


1364
1365
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396


1397
1398
1399
1400
1401
1402


1403
1404
1405
1406
1407
1408


1409
1410
1411

1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423


1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434


1435
1436
1437
1438
1439
1440

1441
1442
1443
1444
1445
1446


1447
1448
1449
1450
1451
1452
1453
1454
1455
1456


1457
1458
1459
1460
1461


1462
1463
1464
1465
1466
1467
1468


1469
1470
1471
1472
1473

1474
1475

1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1507
1508






1509
1510

1511
1512
1513

1514
1515
1516


1517
1518
1519


1520
1521
1522


1523
1524
1525


1526
1527
1528


1529
1530
1531

1532
1533
1534
1535

1536
1537
1538
1539
1540


1541
1542
1543
1544



1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1553
1554
1555
1556
1557
1558
1559




1560
1561
1562
1563
1564
1565
1566
1567
1568

1569
1570
1571
1572

1573
1574
1575

1576
1577
1578
1579
1580
1581
1582


1583
1584
1585
1586

1587
1588
1589
1590
1591







1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608


1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
1629
1630

1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647

1648
1649
1650


1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
-
-
-
+
+
+
+





-
+



-
+


-
+






-
-
+
+


-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+










-
-
+
+











-
+








-
+




-
+











-
+


-
-
+
+














-
+

-
+





-
+

-
+

-
+

-
+














-
-
+
+









-
+







-
+


-
+







-
+


-
-
+
+




-
-
+
+




-
-
+
+


-
+





-
+




-
-
+
+




-
+




-
-
+
+





-
+




-
-
+
+








-
-
+
+



-
-
+
+





-
-
+
+




-
+

-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+



-
-
-
-
-
-
+
+
+
+
+
+

-
+


-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+


-
+



-
+



-
-
+
+

-
-
-
+
+
+












	string = Tcl_GetString(objv[numWindows]);
	if (string[0] != '.') {
	    break;
	}
    }

    /*
     * Iterate over all of the content windows, parsing the configuration
     * options for each content. It's a bit wasteful to re-parse the options for
     * each content, but things get too messy if we try to parse the arguments
     * just once at the beginning. For example, if a content already is packed
     * Iterate over all of the slave windows, parsing the configuration
     * options for each slave. It's a bit wasteful to re-parse the options for
     * each slave, but things get too messy if we try to parse the arguments
     * just once at the beginning. For example, if a slave already is packed
     * we want to just change a few existing values without resetting
     * everything. If there are multiple windows, the -after, -before, and -in
     * options only get processed for the first window.
     */

    containerPtr = NULL;
    masterPtr = NULL;
    prevPtr = NULL;
    positionGiven = 0;
    for (j = 0; j < numWindows; j++) {
	if (TkGetWindowFromObj(interp, tkwin, objv[j], &content) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[j], &slave) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tk_TopWinHierarchy(content)) {
	if (Tk_TopWinHierarchy(slave)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't pack \"%s\": it's a top-level window",
		    Tcl_GetString(objv[j])));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", NULL);
	    return TCL_ERROR;
	}
	contentPtr = GetPacker(content);
	contentPtr->flags &= ~OLD_STYLE;
	slavePtr = GetPacker(slave);
	slavePtr->flags &= ~OLD_STYLE;

	/*
	 * If the content isn't currently packed, reset all of its configuration
	 * If the slave isn't currently packed, reset all of its configuration
	 * information to default values (there could be old values left from
	 * a previous packing).
	 */

	if (contentPtr->containerPtr == NULL) {
	    contentPtr->side = TOP;
	    contentPtr->anchor = TK_ANCHOR_CENTER;
	    contentPtr->padX = contentPtr->padY = 0;
	    contentPtr->padLeft = contentPtr->padTop = 0;
	    contentPtr->iPadX = contentPtr->iPadY = 0;
	    contentPtr->flags &= ~(FILLX|FILLY|EXPAND);
	if (slavePtr->masterPtr == NULL) {
	    slavePtr->side = TOP;
	    slavePtr->anchor = TK_ANCHOR_CENTER;
	    slavePtr->padX = slavePtr->padY = 0;
	    slavePtr->padLeft = slavePtr->padTop = 0;
	    slavePtr->iPadX = slavePtr->iPadY = 0;
	    slavePtr->flags &= ~(FILLX|FILLY|EXPAND);
	}

	for (i = numWindows; i < objc; i+=2) {
	    if ((i+2) > objc) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"extra option \"%s\" (option with no value?)",
			Tcl_GetString(objv[i])));
		Tcl_SetErrorCode(interp, "TK", "PACK", "BAD_PARAMETER", NULL);
		return TCL_ERROR;
	    }
	    if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings,
		    "option", 0, &index) != TCL_OK) {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
		    sizeof(char *), "option", 0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }

	    switch ((enum options) index) {
	    case CONF_AFTER:
		if (j == 0) {
		    if (TkGetWindowFromObj(interp, tkwin, objv[i+1], &other)
			    != TCL_OK) {
			return TCL_ERROR;
		    }
		    prevPtr = GetPacker(other);
		    if (prevPtr->containerPtr == NULL) {
		    if (prevPtr->masterPtr == NULL) {
		    notPacked:
			Tcl_SetObjResult(interp, Tcl_ObjPrintf(
				"window \"%s\" isn't packed",
				Tcl_GetString(objv[i+1])));
			Tcl_SetErrorCode(interp, "TK", "PACK", "NOT_PACKED",
				NULL);
			return TCL_ERROR;
		    }
		    containerPtr = prevPtr->containerPtr;
		    masterPtr = prevPtr->masterPtr;
		    positionGiven = 1;
		}
		break;
	    case CONF_ANCHOR:
		if (Tk_GetAnchorFromObj(interp, objv[i+1], &contentPtr->anchor)
		if (Tk_GetAnchorFromObj(interp, objv[i+1], &slavePtr->anchor)
			!= TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_BEFORE:
		if (j == 0) {
		    if (TkGetWindowFromObj(interp, tkwin, objv[i+1], &other)
			    != TCL_OK) {
			return TCL_ERROR;
		    }
		    otherPtr = GetPacker(other);
		    if (otherPtr->containerPtr == NULL) {
		    if (otherPtr->masterPtr == NULL) {
			goto notPacked;
		    }
		    containerPtr = otherPtr->containerPtr;
		    prevPtr = containerPtr->contentPtr;
		    masterPtr = otherPtr->masterPtr;
		    prevPtr = masterPtr->slavePtr;
		    if (prevPtr == otherPtr) {
			prevPtr = NULL;
		    } else {
			while (prevPtr->nextPtr != otherPtr) {
			    prevPtr = prevPtr->nextPtr;
			}
		    }
		    positionGiven = 1;
		}
		break;
	    case CONF_EXPAND:
		if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    return TCL_ERROR;
		}
		contentPtr->flags &= ~EXPAND;
		slavePtr->flags &= ~EXPAND;
		if (tmp) {
		    contentPtr->flags |= EXPAND;
		    slavePtr->flags |= EXPAND;
		}
		break;
	    case CONF_FILL:
		string = Tcl_GetString(objv[i+1]);
		if (strcmp(string, "none") == 0) {
		    contentPtr->flags &= ~(FILLX|FILLY);
		    slavePtr->flags &= ~(FILLX|FILLY);
		} else if (strcmp(string, "x") == 0) {
		    contentPtr->flags = (contentPtr->flags & ~FILLY) | FILLX;
		    slavePtr->flags = (slavePtr->flags & ~FILLY) | FILLX;
		} else if (strcmp(string, "y") == 0) {
		    contentPtr->flags = (contentPtr->flags & ~FILLX) | FILLY;
		    slavePtr->flags = (slavePtr->flags & ~FILLX) | FILLY;
		} else if (strcmp(string, "both") == 0) {
		    contentPtr->flags |= FILLX|FILLY;
		    slavePtr->flags |= FILLX|FILLY;
		} else {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad fill style \"%s\": must be "
			    "none, x, y, or both", string));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "FILL", NULL);
		    return TCL_ERROR;
		}
		break;
	    case CONF_IN:
		if (j == 0) {
		    if (TkGetWindowFromObj(interp, tkwin, objv[i+1], &other)
			    != TCL_OK) {
			return TCL_ERROR;
		    }
		    containerPtr = GetPacker(other);
		    prevPtr = containerPtr->contentPtr;
		    masterPtr = GetPacker(other);
		    prevPtr = masterPtr->slavePtr;
		    if (prevPtr != NULL) {
			while (prevPtr->nextPtr != NULL) {
			    prevPtr = prevPtr->nextPtr;
			}
		    }
		    positionGiven = 1;
		}
		break;
	    case CONF_IPADX:
		if ((Tk_GetPixelsFromObj(interp, content, objv[i+1], &tmp)
		if ((Tk_GetPixelsFromObj(interp, slave, objv[i+1], &tmp)
			!= TCL_OK) || (tmp < 0)) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad ipadx value \"%s\": must be positive screen"
			    " distance", Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL);
		    return TCL_ERROR;
		}
		contentPtr->iPadX = tmp * 2;
		slavePtr->iPadX = tmp * 2;
		break;
	    case CONF_IPADY:
		if ((Tk_GetPixelsFromObj(interp, content, objv[i+1], &tmp)
		if ((Tk_GetPixelsFromObj(interp, slave, objv[i+1], &tmp)
			!= TCL_OK) || (tmp < 0)) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "bad ipady value \"%s\": must be positive screen"
			    " distance", Tcl_GetString(objv[i+1])));
		    Tcl_SetErrorCode(interp, "TK", "VALUE", "INT_PAD", NULL);
		    return TCL_ERROR;
		}
		contentPtr->iPadY = tmp * 2;
		slavePtr->iPadY = tmp * 2;
		break;
	    case CONF_PADX:
		if (TkParsePadAmount(interp, content, objv[i+1],
			&contentPtr->padLeft, &contentPtr->padX) != TCL_OK) {
		if (TkParsePadAmount(interp, slave, objv[i+1],
			&slavePtr->padLeft, &slavePtr->padX) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_PADY:
		if (TkParsePadAmount(interp, content, objv[i+1],
			&contentPtr->padTop, &contentPtr->padY) != TCL_OK) {
		if (TkParsePadAmount(interp, slave, objv[i+1],
			&slavePtr->padTop, &slavePtr->padY) != TCL_OK) {
		    return TCL_ERROR;
		}
		break;
	    case CONF_SIDE:
		if (Tcl_GetIndexFromObj(interp, objv[i+1], sideNames,
			"side", TCL_EXACT, &side) != TCL_OK) {
		if (Tcl_GetIndexFromObjStruct(interp, objv[i+1], sideNames,
			sizeof(char *), "side", TCL_EXACT, &side) != TCL_OK) {
		    return TCL_ERROR;
		}
		contentPtr->side = (Side) side;
		slavePtr->side = (Side) side;
		break;
	    }
	}

	/*
	 * If no position in a packing list was specified and the content is
	 * If no position in a packing list was specified and the slave is
	 * already packed, then leave it in its current location in its
	 * current packing list.
	 */

	if (!positionGiven && (contentPtr->containerPtr != NULL)) {
	    containerPtr = contentPtr->containerPtr;
	if (!positionGiven && (slavePtr->masterPtr != NULL)) {
	    masterPtr = slavePtr->masterPtr;
	    goto scheduleLayout;
	}

	/*
	 * If the content is going to be put back after itself or the same -in
	 * If the slave is going to be put back after itself or the same -in
	 * window is passed in again, then just skip the whole operation,
	 * since it won't work anyway.
	 */

	if (prevPtr == contentPtr) {
	    containerPtr = contentPtr->containerPtr;
	if (prevPtr == slavePtr) {
	    masterPtr = slavePtr->masterPtr;
	    goto scheduleLayout;
	}

	/*
	 * If none of the "-in", "-before", or "-after" options has been
	 * specified, arrange for the content to go at the end of the order for
	 * specified, arrange for the slave to go at the end of the order for
	 * its parent.
	 */

	if (!positionGiven) {
	    containerPtr = GetPacker(Tk_Parent(content));
	    prevPtr = containerPtr->contentPtr;
	    masterPtr = GetPacker(Tk_Parent(slave));
	    prevPtr = masterPtr->slavePtr;
	    if (prevPtr != NULL) {
		while (prevPtr->nextPtr != NULL) {
		    prevPtr = prevPtr->nextPtr;
		}
	    }
	}

	/*
	 * Make sure that the content's parent is either the container or an
	 * ancestor of the container, and that the container and content aren't the
	 * Make sure that the slave's parent is either the master or an
	 * ancestor of the master, and that the master and slave aren't the
	 * same.
	 */

	parent = Tk_Parent(content);
	for (ancestor = containerPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	parent = Tk_Parent(slave);
	for (ancestor = masterPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == parent) {
		break;
	    }
	    if (Tk_TopWinHierarchy(ancestor)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't pack \"%s\" inside \"%s\"", Tcl_GetString(objv[j]),
			Tk_PathName(containerPtr->tkwin)));
			"can't pack %s inside %s", Tcl_GetString(objv[j]),
			Tk_PathName(masterPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
		return TCL_ERROR;
	    }
	}
	if (content == containerPtr->tkwin) {
	if (slave == masterPtr->tkwin) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't pack \"%s\" inside itself", Tcl_GetString(objv[j])));
		    "can't pack %s inside itself", Tcl_GetString(objv[j])));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "SELF", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Check for management loops.
	 */

	for (container = (TkWindow *)containerPtr->tkwin; container != NULL;
	     container = (TkWindow *)TkGetContainer(container)) {
	    if (container == (TkWindow *)content) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't put \"%s\" inside \"%s\": would cause management loop",
	            Tcl_GetString(objv[j]), Tk_PathName(containerPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL);
		return TCL_ERROR;
	    }
	}
	if (containerPtr->tkwin != Tk_Parent(content)) {
	    ((TkWindow *)content)->maintainerPtr = (TkWindow *)containerPtr->tkwin;
	}

	/*
	 * Unpack the content if it's currently packed, then position it after
	 * Unpack the slave if it's currently packed, then position it after
	 * prevPtr.
	 */

	if (contentPtr->containerPtr != NULL) {
	    if ((contentPtr->containerPtr != containerPtr) &&
		    (contentPtr->containerPtr->tkwin
		    != Tk_Parent(contentPtr->tkwin))) {
		Tk_UnmaintainGeometry(contentPtr->tkwin,
			contentPtr->containerPtr->tkwin);
	if (slavePtr->masterPtr != NULL) {
	    if ((slavePtr->masterPtr != masterPtr) &&
		    (slavePtr->masterPtr->tkwin
		    != Tk_Parent(slavePtr->tkwin))) {
		Tk_UnmaintainGeometry(slavePtr->tkwin,
			slavePtr->masterPtr->tkwin);
	    }
	    Unlink(contentPtr);
	    Unlink(slavePtr);
	}

	contentPtr->containerPtr = containerPtr;
	slavePtr->masterPtr = masterPtr;
	if (prevPtr == NULL) {
	    contentPtr->nextPtr = containerPtr->contentPtr;
	    containerPtr->contentPtr = contentPtr;
	    slavePtr->nextPtr = masterPtr->slavePtr;
	    masterPtr->slavePtr = slavePtr;
	} else {
	    contentPtr->nextPtr = prevPtr->nextPtr;
	    prevPtr->nextPtr = contentPtr;
	    slavePtr->nextPtr = prevPtr->nextPtr;
	    prevPtr->nextPtr = slavePtr;
	}
	Tk_ManageGeometry(content, &packerType, contentPtr);
	prevPtr = contentPtr;
	Tk_ManageGeometry(slave, &packerType, slavePtr);
	prevPtr = slavePtr;

	if (!(containerPtr->flags & DONT_PROPAGATE)) {
	    if (TkSetGeometryContainer(interp, containerPtr->tkwin, "pack")
	if (!(masterPtr->flags & DONT_PROPAGATE)) {
	    if (TkSetGeometryMaster(interp, masterPtr->tkwin, "pack")
		    != TCL_OK) {
		Tk_ManageGeometry(content, NULL, NULL);
		Unlink(contentPtr);
		Tk_ManageGeometry(slave, NULL, NULL);
		Unlink(slavePtr);
		return TCL_ERROR;
	    }
	    containerPtr->flags |= ALLOCED_CONTAINER;
	    masterPtr->flags |= ALLOCED_MASTER;
	}

	/*
	 * Arrange for the container to be re-packed at the first idle moment.
	 * Arrange for the master to be re-packed at the first idle moment.
	 */

    scheduleLayout:
	if (containerPtr->abortPtr != NULL) {
	    *containerPtr->abortPtr = 1;
	if (masterPtr->abortPtr != NULL) {
	    *masterPtr->abortPtr = 1;
	}
	if (!(containerPtr->flags & REQUESTED_REPACK)) {
	    containerPtr->flags |= REQUESTED_REPACK;
	    Tcl_DoWhenIdle(ArrangePacking, containerPtr);
	if (!(masterPtr->flags & REQUESTED_REPACK)) {
	    masterPtr->flags |= REQUESTED_REPACK;
	    Tcl_DoWhenIdle(ArrangePacking, masterPtr);
	}
    }
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkPanedWindow.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17


18
19
20
21
22
23
24
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24








-
-
+
+





-
-
+
+







/*
 * tkPanedWindow.c --
 *
 *	This module implements "paned window" widgets that are object based. A
 *	"paned window" is a widget that manages the geometry for some number
 *	of other widgets, placing a movable "sash" between them, which can be
 *	used to alter the relative sizes of adjacent widgets.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright © 2000 Ajuba Solutions.
 * Copyright (c) 1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Ajuba Solutions.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"

/*
 * Flag values for "sticky"ness. The 16 combinations subsume the packer's
 * notion of anchor and fill.
 *
 * STICK_NORTH  	This window sticks to the top of its cavity.
 * STICK_EAST		This window sticks to the right edge of its cavity.
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82
83
84
85

86
87

88
89
90

91
92
93


94
95
96
97

98
99
100
101
102
103

104
105

106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80

81
82
83
84

85
86

87
88
89

90
91


92
93
94
95
96

97
98
99
100
101
102

103
104

105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131







-
+







-
+



-
+

-
+


-
+

-
-
+
+



-
+





-
+

-
+



-
+














-
+







    (((stretch) == STRETCH_ALWAYS) ||				\
     ((stretch) == STRETCH_FIRST && (index) == (first)) ||	\
     ((stretch) == STRETCH_LAST && (index) == (last)) ||	\
     ((stretch) == STRETCH_MIDDLE && (index) != (first) && (index) != (last)))

typedef struct {
    Tk_OptionTable pwOptions;	/* Token for paned window option table. */
    Tk_OptionTable paneOpts;	/* Token for pane cget option table. */
    Tk_OptionTable slaveOpts;	/* Token for slave cget option table. */
} OptionTables;

/*
 * One structure of the following type is kept for each window
 * managed by a paned window widget.
 */

typedef struct Pane {
typedef struct Slave {
    Tk_Window tkwin;		/* Window being managed. */
    int minSize;		/* Minimum size of this pane, on the relevant
				 * axis, in pixels. */
    int padx;			/* Additional padding requested for pane, in
    int padx;			/* Additional padding requested for slave, in
				 * the x dimension. */
    int pady;			/* Additional padding requested for pane, in
    int pady;			/* Additional padding requested for slave, in
				 * the y dimension. */
    Tcl_Obj *widthPtr, *heightPtr;
				/* Tcl_Obj rep's of pane width/height, to
				/* Tcl_Obj rep's of slave width/height, to
				 * allow for null values. */
    int width;			/* Pane width. */
    int height;			/* Pane height. */
    int width;			/* Slave width. */
    int height;			/* Slave height. */
    int sticky;			/* Sticky string. */
    int x, y;			/* Coordinates of the widget. */
    int paneWidth, paneHeight;	/* Pane dimensions (may be different from
				 * pane width/height). */
				 * slave width/height). */
    int sashx, sashy;		/* Coordinates of the sash of the right or
				 * bottom of this pane. */
    int markx, marky;		/* Coordinates of the last mark set for the
				 * sash. */
    int handlex, handley;	/* Coordinates of the sash handle. */
    enum stretch stretch;	/* Controls how pane grows/shrinks */
    enum stretch stretch;	/* Controls how slave grows/shrinks */
    int hide;			/* Controls visibility of pane */
    struct PanedWindow *containerPtr;
    struct PanedWindow *masterPtr;
				/* Paned window managing the window. */
    Tk_Window after;		/* Placeholder for parsing options. */
    Tk_Window before;		/* Placeholder for parsing options. */
} Pane;
} Slave;

/*
 * A data structure of the following type is kept for each paned window widget
 * managed by this file:
 */

typedef struct PanedWindow {
    Tk_Window tkwin;		/* Window that embodies the paned window. */
    Tk_Window proxywin;		/* Window for the resizing proxy. */
    Display *display;		/* X's token for the window's display. */
    Tcl_Interp *interp;		/* Interpreter associated with widget. */
    Tcl_Command widgetCmd;	/* Token for square's widget command. */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
    Tk_OptionTable paneOpts;	/* Token for pane cget table. */
    Tk_OptionTable slaveOpts;	/* Token for slave cget table. */
    Tk_3DBorder background;	/* Background color. */
    int borderWidth;		/* Value of -borderwidth option. */
    int relief;			/* 3D border effect (TK_RELIEF_RAISED, etc) */
    Tcl_Obj *widthPtr;		/* Tcl_Obj rep for width. */
    Tcl_Obj *heightPtr;		/* Tcl_Obj rep for height. */
    int width, height;		/* Width and height of the widget. */
    enum orient orient;		/* Orientation of the widget. */
147
148
149
150
151
152
153
154
155
156



157
158
159
160
161
162
163
147
148
149
150
151
152
153



154
155
156
157
158
159
160
161
162
163







-
-
-
+
+
+







    GC gc;			/* Graphics context for copying from
				 * off-screen pixmap onto screen. */
    int proxyx, proxyy;		/* Proxy x,y coordinates. */
    Tk_3DBorder proxyBackground;/* Background color used to draw proxy. If NULL, use background. */
    Tcl_Obj *proxyBorderWidthPtr; /* Tcl_Obj rep for proxyBorderWidth */
    int proxyBorderWidth;	/* Borderwidth used to draw proxy. */
    int proxyRelief;		/* Relief used to draw proxy, if TK_RELIEF_NULL then use relief. */
    Pane **panes;		/* Pointer to array of Panes. */
    int numPanes;		/* Number of panes. */
    int sizeofPanes;		/* Number of elements in the panes array. */
    Slave **slaves;		/* Pointer to array of Slaves. */
    int numSlaves;		/* Number of slaves. */
    int sizeofSlaves;		/* Number of elements in the slaves array. */
    int flags;			/* Flags for widget; see below. */
} PanedWindow;

/*
 * Flags used for paned windows:
 *
 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler has been
179
180
181
182
183
184
185



186

187
188
189
190
191
192


193
194

195
196
197
198



199
200

201
202

203
204
205
206



207
208
209

210
211
212
213
214
215
216
217
218

219
220
221

222
223

224
225

226
227
228
229



230
231
232
233

234
235
236

237
238
239
240
241

242
243
244
245

246
247
248
249
250

251
252
253
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276


277
278

279
280

281
282
283


284
285
286


287
288
289


290
291
292


293
294
295


296
297
298


299
300
301


302
303
304


305
306
307


308
309
310


311
312

313
314
315


316
317
318


319
320
321


322
323
324


325
326
327


328
329
330


331
332
333
334

335
336
337


338
339
340


341
342
343


344
345

346
347

348
349

350
351

352
353
354


355
356
357


358
359
360


361
362
363
364
365
366
367
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193


194
195
196

197
198



199
200
201
202

203
204

205
206



207
208
209
210
211

212
213
214
215
216
217
218
219
220

221
222
223

224
225

226
227

228
229



230
231
232
233
234
235

236
237
238

239
240
241
242
243

244
245
246
247

248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277


278
279
280

281
282

283
284


285
286
287


288
289
290


291
292
293


294
295
296


297
298
299


300
301
302


303
304
305


306
307
308


309
310
311


312
313
314

315
316


317
318
319


320
321
322


323
324
325


326
327
328


329
330
331


332
333
334
335
336

337
338


339
340
341


342
343
344


345
346
347

348
349

350
351

352
353

354
355


356
357
358


359
360
361


362
363
364
365
366
367
368
369
370







+
+
+
-
+




-
-
+
+

-
+

-
-
-
+
+
+

-
+

-
+

-
-
-
+
+
+


-
+








-
+


-
+

-
+

-
+

-
-
-
+
+
+



-
+


-
+




-
+



-
+




-
+










-
+













-
-
+
+

-
+

-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+



-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
+

-
+

-
+

-
+

-
-
+
+

-
-
+
+

-
-
+
+







#define PROXY_REDRAW_PENDING	0x0010
#define RESIZE_PENDING		0x0020

/*
 * Forward declarations for functions defined later in this file:
 */

int			Tk_PanedWindowObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		PanedWindowCmdDeletedProc(void *clientData);
static void		PanedWindowCmdDeletedProc(ClientData clientData);
static int		ConfigurePanedWindow(Tcl_Interp *interp,
			    PanedWindow *pwPtr, int objc,
			    Tcl_Obj *const objv[]);
static void		DestroyPanedWindow(PanedWindow *pwPtr);
static void		DisplayPanedWindow(void *clientData);
static void		PanedWindowEventProc(void *clientData,
static void		DisplayPanedWindow(ClientData clientData);
static void		PanedWindowEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		ProxyWindowEventProc(void *clientData,
static void		ProxyWindowEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		DisplayProxyWindow(void *clientData);
static void		PanedWindowWorldChanged(void *instanceData);
static int		PanedWindowWidgetObjCmd(void *clientData,
static void		DisplayProxyWindow(ClientData clientData);
static void		PanedWindowWorldChanged(ClientData instanceData);
static int		PanedWindowWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *, int objc, Tcl_Obj * const objv[]);
static void		PanedWindowLostPaneProc(void *clientData,
static void		PanedWindowLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		PanedWindowReqProc(void *clientData,
static void		PanedWindowReqProc(ClientData clientData,
			    Tk_Window tkwin);
static void		ArrangePanes(void *clientData);
static void		Unlink(Pane *panePtr);
static Pane *		GetPane(PanedWindow *pwPtr, Tk_Window tkwin);
static void		ArrangePanes(ClientData clientData);
static void		Unlink(Slave *slavePtr);
static Slave *		GetPane(PanedWindow *pwPtr, Tk_Window tkwin);
static void		GetFirstLastVisiblePane(PanedWindow *pwPtr,
			    int *firstPtr, int *lastPtr);
static void		PaneStructureProc(void *clientData,
static void		SlaveStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static int		PanedWindowSashCommand(PanedWindow *pwPtr,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		PanedWindowProxyCommand(PanedWindow *pwPtr,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static void		ComputeGeometry(PanedWindow *pwPtr);
static int		ConfigurePanes(PanedWindow *pwPtr,
static int		ConfigureSlaves(PanedWindow *pwPtr,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static void		DestroyOptionTables(void *clientData,
static void		DestroyOptionTables(ClientData clientData,
			    Tcl_Interp *interp);
static int		SetSticky(void *clientData, Tcl_Interp *interp,
static int		SetSticky(ClientData clientData, Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Obj **value, char *recordPtr,
			    Tcl_Size internalOffset, char *oldInternalPtr,
			    int internalOffset, char *oldInternalPtr,
			    int flags);
static Tcl_Obj *	GetSticky(void *clientData, Tk_Window tkwin,
			    char *recordPtr, Tcl_Size internalOffset);
static void		RestoreSticky(void *clientData, Tk_Window tkwin,
static Tcl_Obj *	GetSticky(ClientData clientData, Tk_Window tkwin,
			    char *recordPtr, int internalOffset);
static void		RestoreSticky(ClientData clientData, Tk_Window tkwin,
			    char *internalPtr, char *oldInternalPtr);
static void		AdjustForSticky(int sticky, int cavityWidth,
			    int cavityHeight, int *xPtr, int *yPtr,
			    int *paneWidthPtr, int *paneHeightPtr);
			    int *slaveWidthPtr, int *slaveHeightPtr);
static void		MoveSash(PanedWindow *pwPtr, int sash, int diff);
static int		ObjectIsEmpty(Tcl_Obj *objPtr);
static void *	ComputeSlotAddress(void *recordPtr, Tcl_Size offset);
static char *		ComputeSlotAddress(char *recordPtr, int offset);
static int		PanedWindowIdentifyCoords(PanedWindow *pwPtr,
			    Tcl_Interp *interp, int x, int y);

/*
 * Sashes are between panes only, so there is one less sash than panes
 * Sashes are between panes only, so there is one less sash than slaves
 */

#define ValidSashIndex(pwPtr, sash) \
	(((sash) >= 0) && ((sash) < ((pwPtr)->numPanes-1)))
	(((sash) >= 0) && ((sash) < ((pwPtr)->numSlaves-1)))

static const Tk_GeomMgr panedWindowMgrType = {
    "panedwindow",		/* name */
    PanedWindowReqProc,		/* requestProc */
    PanedWindowLostPaneProc,	/* lostPaneProc */
    PanedWindowLostSlaveProc,	/* lostSlaveProc */
};

/*
 * Information used for objv parsing.
 */

#define GEOMETRY		0x0001

/*
 * The following structure contains pointers to functions used for processing
 * the custom "-sticky" option for panes.
 * the custom "-sticky" option for slave windows.
 */

static const Tk_ObjCustomOption stickyOption = {
    "sticky",			/* name */
    SetSticky,			/* setProc */
    GetSticky,			/* getProc */
    RestoreSticky,		/* restoreProc */
    NULL,			/* freeProc */
    0
};

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_PANEDWINDOW_BG_COLOR, TCL_INDEX_NONE, offsetof(PanedWindow, background), 0,
	DEF_PANEDWINDOW_BG_MONO, 0},
	 DEF_PANEDWINDOW_BG_COLOR, -1, Tk_Offset(PanedWindow, background), 0,
	 DEF_PANEDWINDOW_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	 NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	 NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_PANEDWINDOW_BORDERWIDTH, TCL_INDEX_NONE, offsetof(PanedWindow, borderWidth),
	0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_BORDERWIDTH, -1, Tk_Offset(PanedWindow, borderWidth),
	 0, 0, GEOMETRY},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_PANEDWINDOW_CURSOR, TCL_INDEX_NONE, offsetof(PanedWindow, cursor),
	TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_CURSOR, -1, Tk_Offset(PanedWindow, cursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-handlepad", "handlePad", "HandlePad",
	DEF_PANEDWINDOW_HANDLEPAD, TCL_INDEX_NONE, offsetof(PanedWindow, handlePad),
	0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_HANDLEPAD, -1, Tk_Offset(PanedWindow, handlePad),
	 0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-handlesize", "handleSize", "HandleSize",
	DEF_PANEDWINDOW_HANDLESIZE, offsetof(PanedWindow, handleSizePtr),
	offsetof(PanedWindow, handleSize), 0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_HANDLESIZE, Tk_Offset(PanedWindow, handleSizePtr),
	 Tk_Offset(PanedWindow, handleSize), 0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-height", "height", "Height",
	DEF_PANEDWINDOW_HEIGHT, offsetof(PanedWindow, heightPtr),
	offsetof(PanedWindow, height), TK_OPTION_NULL_OK, 0, GEOMETRY},
	 DEF_PANEDWINDOW_HEIGHT, Tk_Offset(PanedWindow, heightPtr),
	 Tk_Offset(PanedWindow, height), TK_OPTION_NULL_OK, 0, GEOMETRY},
    {TK_OPTION_BOOLEAN, "-opaqueresize", "opaqueResize", "OpaqueResize",
	DEF_PANEDWINDOW_OPAQUERESIZE, TCL_INDEX_NONE,
	offsetof(PanedWindow, resizeOpaque), 0, 0, 0},
	 DEF_PANEDWINDOW_OPAQUERESIZE, -1,
	 Tk_Offset(PanedWindow, resizeOpaque), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
	DEF_PANEDWINDOW_ORIENT, TCL_INDEX_NONE, offsetof(PanedWindow, orient),
	TK_OPTION_ENUM_VAR, orientStrings, GEOMETRY},
	 DEF_PANEDWINDOW_ORIENT, -1, Tk_Offset(PanedWindow, orient),
	 0, orientStrings, GEOMETRY},
    {TK_OPTION_BORDER, "-proxybackground", "proxyBackground", "ProxyBackground",
	0, TCL_INDEX_NONE, offsetof(PanedWindow, proxyBackground), TK_OPTION_NULL_OK,
	(void *)DEF_PANEDWINDOW_BG_MONO, 0},
	 0, -1, Tk_Offset(PanedWindow, proxyBackground), TK_OPTION_NULL_OK,
	 (ClientData) DEF_PANEDWINDOW_BG_MONO},
    {TK_OPTION_PIXELS, "-proxyborderwidth", "proxyBorderWidth", "ProxyBorderWidth",
	DEF_PANEDWINDOW_PROXYBORDER, offsetof(PanedWindow, proxyBorderWidthPtr),
	offsetof(PanedWindow, proxyBorderWidth), 0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_PROXYBORDER, Tk_Offset(PanedWindow, proxyBorderWidthPtr),
	 Tk_Offset(PanedWindow, proxyBorderWidth), 0, 0, GEOMETRY},
    {TK_OPTION_RELIEF, "-proxyrelief", "proxyRelief", "Relief",
	0, TCL_INDEX_NONE, offsetof(PanedWindow, proxyRelief),
	TK_OPTION_NULL_OK, 0, 0},
	 0, -1, Tk_Offset(PanedWindow, proxyRelief),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_PANEDWINDOW_RELIEF, TCL_INDEX_NONE, offsetof(PanedWindow, relief), 0, 0, 0},
	 DEF_PANEDWINDOW_RELIEF, -1, Tk_Offset(PanedWindow, relief), 0, 0, 0},
    {TK_OPTION_CURSOR, "-sashcursor", "sashCursor", "Cursor",
	DEF_PANEDWINDOW_SASHCURSOR, TCL_INDEX_NONE, offsetof(PanedWindow, sashCursor),
	TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_SASHCURSOR, -1, Tk_Offset(PanedWindow, sashCursor),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-sashpad", "sashPad", "SashPad",
	DEF_PANEDWINDOW_SASHPAD, TCL_INDEX_NONE, offsetof(PanedWindow, sashPad),
	0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_SASHPAD, -1, Tk_Offset(PanedWindow, sashPad),
	 0, 0, GEOMETRY},
    {TK_OPTION_RELIEF, "-sashrelief", "sashRelief", "Relief",
	DEF_PANEDWINDOW_SASHRELIEF, TCL_INDEX_NONE, offsetof(PanedWindow, sashRelief),
	0, 0, 0},
	 DEF_PANEDWINDOW_SASHRELIEF, -1, Tk_Offset(PanedWindow, sashRelief),
	 0, 0, 0},
    {TK_OPTION_PIXELS, "-sashwidth", "sashWidth", "Width",
	DEF_PANEDWINDOW_SASHWIDTH, offsetof(PanedWindow, sashWidthPtr),
	offsetof(PanedWindow, sashWidth), 0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_SASHWIDTH, Tk_Offset(PanedWindow, sashWidthPtr),
	 Tk_Offset(PanedWindow, sashWidth), 0, 0, GEOMETRY},
    {TK_OPTION_BOOLEAN, "-showhandle", "showHandle", "ShowHandle",
	DEF_PANEDWINDOW_SHOWHANDLE, TCL_INDEX_NONE, offsetof(PanedWindow, showHandle),
	0, 0, GEOMETRY},
	 DEF_PANEDWINDOW_SHOWHANDLE, -1, Tk_Offset(PanedWindow, showHandle),
	 0, 0, GEOMETRY},
    {TK_OPTION_PIXELS, "-width", "width", "Width",
	DEF_PANEDWINDOW_WIDTH, offsetof(PanedWindow, widthPtr),
	offsetof(PanedWindow, width), TK_OPTION_NULL_OK, 0, GEOMETRY},
	 DEF_PANEDWINDOW_WIDTH, Tk_Offset(PanedWindow, widthPtr),
	 Tk_Offset(PanedWindow, width), TK_OPTION_NULL_OK, 0, GEOMETRY},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

static const Tk_OptionSpec paneOptionSpecs[] = {
static const Tk_OptionSpec slaveOptionSpecs[] = {
    {TK_OPTION_WINDOW, "-after", NULL, NULL,
	DEF_PANEDWINDOW_PANE_AFTER, TCL_INDEX_NONE, offsetof(Pane, after),
	TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_PANE_AFTER, -1, Tk_Offset(Slave, after),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_WINDOW, "-before", NULL, NULL,
	DEF_PANEDWINDOW_PANE_BEFORE, TCL_INDEX_NONE, offsetof(Pane, before),
	TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_PANE_BEFORE, -1, Tk_Offset(Slave, before),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-height", NULL, NULL,
	DEF_PANEDWINDOW_PANE_HEIGHT, offsetof(Pane, heightPtr),
	offsetof(Pane, height), TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_PANE_HEIGHT, Tk_Offset(Slave, heightPtr),
	 Tk_Offset(Slave, height), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-hide", "hide", "Hide",
	DEF_PANEDWINDOW_PANE_HIDE, TCL_INDEX_NONE, offsetof(Pane, hide), 0,0,GEOMETRY},
	 DEF_PANEDWINDOW_PANE_HIDE, -1, Tk_Offset(Slave, hide), 0,0,GEOMETRY},
    {TK_OPTION_PIXELS, "-minsize", NULL, NULL,
	DEF_PANEDWINDOW_PANE_MINSIZE, TCL_INDEX_NONE, offsetof(Pane, minSize), 0, 0, 0},
	 DEF_PANEDWINDOW_PANE_MINSIZE, -1, Tk_Offset(Slave, minSize), 0, 0, 0},
    {TK_OPTION_PIXELS, "-padx", NULL, NULL,
	DEF_PANEDWINDOW_PANE_PADX, TCL_INDEX_NONE, offsetof(Pane, padx), 0, 0, 0},
	 DEF_PANEDWINDOW_PANE_PADX, -1, Tk_Offset(Slave, padx), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", NULL, NULL,
	DEF_PANEDWINDOW_PANE_PADY, TCL_INDEX_NONE, offsetof(Pane, pady), 0, 0, 0},
	 DEF_PANEDWINDOW_PANE_PADY, -1, Tk_Offset(Slave, pady), 0, 0, 0},
    {TK_OPTION_CUSTOM, "-sticky", NULL, NULL,
	DEF_PANEDWINDOW_PANE_STICKY, TCL_INDEX_NONE, offsetof(Pane, sticky),
	0, &stickyOption, 0},
	 DEF_PANEDWINDOW_PANE_STICKY, -1, Tk_Offset(Slave, sticky), 0,
	 &stickyOption, 0},
    {TK_OPTION_STRING_TABLE, "-stretch", "stretch", "Stretch",
	DEF_PANEDWINDOW_PANE_STRETCH, TCL_INDEX_NONE, offsetof(Pane, stretch),
	TK_OPTION_ENUM_VAR, stretchStrings, 0},
	DEF_PANEDWINDOW_PANE_STRETCH, -1, Tk_Offset(Slave, stretch), 0,
	(ClientData) stretchStrings, 0},
    {TK_OPTION_PIXELS, "-width", NULL, NULL,
	DEF_PANEDWINDOW_PANE_WIDTH, offsetof(Pane, widthPtr),
	offsetof(Pane, width), TK_OPTION_NULL_OK, 0, 0},
	 DEF_PANEDWINDOW_PANE_WIDTH, Tk_Offset(Slave, widthPtr),
	 Tk_Offset(Slave, width), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 *--------------------------------------------------------------
 *
 * Tk_PanedWindowObjCmd --
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393







-
+







 *	A new widget is created and configured.
 *
 *--------------------------------------------------------------
 */

int
Tk_PanedWindowObjCmd(
    TCL_UNUSED(void *),	/* NULL. */
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj * const objv[])	/* Argument objects. */
{
    PanedWindow *pwPtr;
    Tk_Window tkwin, parent;
    OptionTables *pwOpts;
403
404
405
406
407
408
409
410

411
412
413
414

415
416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
445
446

447
448
449
450



451
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
406
407
408
409
410
411
412

413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448

449
450



451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469
470
471
472
473

474
475
476
477
478
479
480
481







-
+



-
+













-
+








-
+








-
+

-
-
-
+
+
+








-
+











-
+








    pwOpts = (OptionTables *)
	    Tcl_GetAssocData(interp, "PanedWindowOptionTables", NULL);
    if (pwOpts == NULL) {
	/*
	 * The first time this function is invoked, the option tables will be
	 * NULL. We then create the option tables from the templates and store
	 * a pointer to the tables as the command's clientData so we'll have
	 * a pointer to the tables as the command's clinical so we'll have
	 * easy access to it in the future.
	 */

	pwOpts = (OptionTables *)ckalloc(sizeof(OptionTables));
	pwOpts = ckalloc(sizeof(OptionTables));

	/*
	 * Set up an exit handler to free the optionTables struct.
	 */

	Tcl_SetAssocData(interp, "PanedWindowOptionTables",
		DestroyOptionTables, pwOpts);

	/*
	 * Create the paned window option tables.
	 */

	pwOpts->pwOptions = Tk_CreateOptionTable(interp, optionSpecs);
	pwOpts->paneOpts = Tk_CreateOptionTable(interp, paneOptionSpecs);
	pwOpts->slaveOpts = Tk_CreateOptionTable(interp, slaveOptionSpecs);
    }

    Tk_SetClass(tkwin, "Panedwindow");

    /*
     * Allocate and initialize the widget record.
     */

    pwPtr = (PanedWindow *)ckalloc(sizeof(PanedWindow));
    pwPtr = ckalloc(sizeof(PanedWindow));
    memset((void *)pwPtr, 0, (sizeof(PanedWindow)));
    pwPtr->tkwin = tkwin;
    pwPtr->display = Tk_Display(tkwin);
    pwPtr->interp = interp;
    pwPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(pwPtr->tkwin), PanedWindowWidgetObjCmd, pwPtr,
	    PanedWindowCmdDeletedProc);
    pwPtr->optionTable = pwOpts->pwOptions;
    pwPtr->paneOpts = pwOpts->paneOpts;
    pwPtr->slaveOpts = pwOpts->slaveOpts;
    pwPtr->relief = TK_RELIEF_RAISED;
    pwPtr->gc = NULL;
    pwPtr->cursor = NULL;
    pwPtr->sashCursor = NULL;
    pwPtr->gc = None;
    pwPtr->cursor = None;
    pwPtr->sashCursor = None;

    /*
     * Keep a hold of the associated tkwin until we destroy the widget,
     * otherwise Tk might free it while we still need it.
     */

    Tcl_Preserve(pwPtr->tkwin);

    if (Tk_InitOptions(interp, pwPtr, pwOpts->pwOptions,
    if (Tk_InitOptions(interp, (char *) pwPtr, pwOpts->pwOptions,
	    tkwin) != TCL_OK) {
	Tk_DestroyWindow(pwPtr->tkwin);
	return TCL_ERROR;
    }

    Tk_CreateEventHandler(pwPtr->tkwin, ExposureMask|StructureNotifyMask,
	    PanedWindowEventProc, pwPtr);

    /*
     * Find the toplevel ancestor of the panedwindow, and make a proxy win as
     * a child of that window; this way the proxy can always float above
     * panes in the panedwindow.
     * slaves in the panedwindow.
     */

    parent = Tk_Parent(pwPtr->tkwin);
    while (!(Tk_IsTopLevel(parent))) {
	parent = Tk_Parent(parent);
	if (parent == NULL) {
	    parent = pwPtr->tkwin;
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516







-
+








    if (ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2) != TCL_OK) {
	Tk_DestroyWindow(pwPtr->proxywin);
	Tk_DestroyWindow(pwPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(pwPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(pwPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowWidgetObjCmd --
523
524
525
526
527
528
529
530

531
532
533
534
535

536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551

552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615

616
617
618

619
620
621
622


623
624
625
626
627
628
629






630
631
632
633
634
635
636
526
527
528
529
530
531
532

533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550

551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621

622
623
624


625
626
627






628
629
630
631
632
633
634
635
636
637
638
639
640







-
+




-
+












-
+


-
+

















-
+








-
+











-
+













+











-
+


-
+


-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
PanedWindowWidgetObjCmd(
    void *clientData,	/* Information about square widget. */
    ClientData clientData,	/* Information about square widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj * const objv[])	/* Argument objects. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    PanedWindow *pwPtr = clientData;
    int result = TCL_OK;
    static const char *const optionStrings[] = {
	"add", "cget", "configure", "forget", "identify", "panecget",
	"paneconfigure", "panes", "proxy", "sash", NULL
    };
    enum options {
	PW_ADD, PW_CGET, PW_CONFIGURE, PW_FORGET, PW_IDENTIFY, PW_PANECGET,
	PW_PANECONFIGURE, PW_PANES, PW_PROXY, PW_SASH
    };
    Tcl_Obj *resultObj;
    int index, count, i, x, y;
    Tk_Window tkwin;
    Pane *panePtr;
    Slave *slavePtr;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "command",
	    0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Tcl_Preserve(pwPtr);

    switch ((enum options) index) {
    case PW_ADD:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
	    result = TCL_ERROR;
	    break;
	}
	result = ConfigurePanes(pwPtr, interp, objc, objv);
	result = ConfigureSlaves(pwPtr, interp, objc, objv);
	break;

    case PW_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    break;
	}
	resultObj = Tk_GetOptionValue(interp, pwPtr,
	resultObj = Tk_GetOptionValue(interp, (char *) pwPtr,
		pwPtr->optionTable, objv[2], pwPtr->tkwin);
	if (resultObj == NULL) {
	    result = TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, resultObj);
	}
	break;

    case PW_CONFIGURE:
	resultObj = NULL;
	if (objc <= 3) {
	    resultObj = Tk_GetOptionInfo(interp, pwPtr,
	    resultObj = Tk_GetOptionInfo(interp, (char *) pwPtr,
		    pwPtr->optionTable,
		    (objc == 3) ? objv[2] : NULL, pwPtr->tkwin);
	    if (resultObj == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, resultObj);
	    }
	} else {
	    result = ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2);
	}
	break;

    case PW_FORGET: {
	int i;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
	    result = TCL_ERROR;
	    break;
	}

	/*
	 * Clean up each window named in the arg list.
	 */
	for (count = 0, i = 2; i < objc; i++) {
	    Tk_Window pane = Tk_NameToWindow(interp, Tcl_GetString(objv[i]),
	    Tk_Window slave = Tk_NameToWindow(interp, Tcl_GetString(objv[i]),
		    pwPtr->tkwin);

	    if (pane == NULL) {
	    if (slave == NULL) {
		continue;
	    }
	    panePtr = GetPane(pwPtr, pane);
	    if ((panePtr != NULL) && (panePtr->containerPtr != NULL)) {
	    slavePtr = GetPane(pwPtr, slave);
	    if ((slavePtr != NULL) && (slavePtr->masterPtr != NULL)) {
		count++;
		Tk_ManageGeometry(pane, NULL, NULL);
		Tk_UnmaintainGeometry(panePtr->tkwin, pwPtr->tkwin);
		Tk_DeleteEventHandler(panePtr->tkwin, StructureNotifyMask,
			PaneStructureProc, panePtr);
		Tk_UnmapWindow(panePtr->tkwin);
		Unlink(panePtr);
		Tk_ManageGeometry(slave, NULL, NULL);
		Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
		Tk_DeleteEventHandler(slavePtr->tkwin, StructureNotifyMask,
			SlaveStructureProc, slavePtr);
		Tk_UnmapWindow(slavePtr->tkwin);
		Unlink(slavePtr);
	    }
	    if (count != 0) {
		ComputeGeometry(pwPtr);
	    }
	}
	break;
    }
658
659
660
661
662
663
664
665
666


667
668

669
670
671
672
673

674
675

676
677
678
679
680
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706


707
708

709
710
711
712
713
714
715
716
717
718
719
720

721
722
723
724
725
726

727
728

729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748

749
750

751
752
753
754
755
756
757


758
759
760
761
762
763

764
765
766
767
768
769

770
771
772
773


774
775
776
777
778

779
780
781
782
783
784
785
662
663
664
665
666
667
668


669
670
671

672
673
674
675
676

677
678

679
680
681
682
683
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708


709
710
711

712
713
714
715
716
717
718
719
720
721
722
723

724
725
726
727
728
729

730
731

732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751

752
753

754
755
756
757
758
759


760
761
762
763
764
765
766

767
768
769
770
771
772

773
774
775


776
777
778
779
780
781

782
783
784
785
786
787
788
789







-
-
+
+

-
+




-
+

-
+












-
+
















-
-
+
+

-
+











-
+





-
+

-
+



















-
+

-
+





-
-
+
+





-
+





-
+


-
-
+
+




-
+







	}
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), pwPtr->tkwin);
	if (tkwin == NULL) {
	    result = TCL_ERROR;
	    break;
	}
	resultObj = NULL;
	for (i = 0; i < pwPtr->numPanes; i++) {
	    if (pwPtr->panes[i]->tkwin == tkwin) {
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    if (pwPtr->slaves[i]->tkwin == tkwin) {
		resultObj = Tk_GetOptionValue(interp,
			pwPtr->panes[i], pwPtr->paneOpts,
			(char *) pwPtr->slaves[i], pwPtr->slaveOpts,
			objv[3], tkwin);
	    }
	}
	if (resultObj == NULL) {
	    if (i == pwPtr->numPanes) {
	    if (i == pwPtr->numSlaves) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"not managed by this window", TCL_INDEX_NONE));
			"not managed by this window", -1));
		Tcl_SetErrorCode(interp, "TK", "PANEDWINDOW", "UNMANAGED",
			NULL);
	    }
	    result = TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, resultObj);
	}
	break;

    case PW_PANECONFIGURE:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "pane ?-option value ...?");
		    "pane ?option? ?value option value ...?");
	    result = TCL_ERROR;
	    break;
	}
	resultObj = NULL;
	if (objc <= 4) {
	    tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
		    pwPtr->tkwin);
            if (tkwin == NULL) {
                /*
                 * Just a plain old bad window; Tk_NameToWindow filled in an
                 * error message for us.
                 */

                result = TCL_ERROR;
                break;
            }
	    for (i = 0; i < pwPtr->numPanes; i++) {
		if (pwPtr->panes[i]->tkwin == tkwin) {
	    for (i = 0; i < pwPtr->numSlaves; i++) {
		if (pwPtr->slaves[i]->tkwin == tkwin) {
		    resultObj = Tk_GetOptionInfo(interp,
			    pwPtr->panes[i], pwPtr->paneOpts,
			    (char *) pwPtr->slaves[i], pwPtr->slaveOpts,
			    (objc == 4) ? objv[3] : NULL,
			    pwPtr->tkwin);
		    if (resultObj == NULL) {
			result = TCL_ERROR;
		    } else {
			Tcl_SetObjResult(interp, resultObj);
		    }
		    break;
		}
	    }
	} else {
	    result = ConfigurePanes(pwPtr, interp, objc, objv);
	    result = ConfigureSlaves(pwPtr, interp, objc, objv);
	}
	break;

    case PW_PANES:
	resultObj = Tcl_NewObj();
	for (i = 0; i < pwPtr->numPanes; i++) {
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    Tk_NewWindowObj(pwPtr->panes[i]->tkwin));
		    TkNewWindowObj(pwPtr->slaves[i]->tkwin));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;

    case PW_PROXY:
	result = PanedWindowProxyCommand(pwPtr, interp, objc, objv);
	break;

    case PW_SASH:
	result = PanedWindowSashCommand(pwPtr, interp, objc, objv);
	break;
    }
    Tcl_Release(pwPtr);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigurePanes --
 * ConfigureSlaves --
 *
 *	Add or alter the configuration options of a pane in a paned window.
 *	Add or alter the configuration options of a slave in a paned window.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	Depends on options; may add a pane to the paned window, may alter the
 *	geometry management options of a pane.
 *	Depends on options; may add a slave to the paned window, may alter the
 *	geometry management options of a slave.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigurePanes(
ConfigureSlaves(
    PanedWindow *pwPtr,		/* Information about paned window. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int i, firstOptionArg, j, found, doubleBw, index, numNewPanes, haveLoc;
    int i, firstOptionArg, j, found, doubleBw, index, numNewSlaves, haveLoc;
    int insertIndex;
    Tk_Window tkwin = NULL, ancestor, parent;
    Pane *panePtr, **inserts, **newPanes;
    Pane options;
    Slave *slavePtr, **inserts, **newSlaves;
    Slave options;
    const char *arg;

    /*
     * Find the non-window name arguments; these are the configure options for
     * the panes. Also validate that the window names given are legitimate
     * the slaves. Also validate that the window names given are legitimate
     * (ie, they are real windows, they are not the panedwindow itself, etc.).
     */

    for (i = 2; i < objc; i++) {
	arg = Tcl_GetString(objv[i]);
	if (arg[0] == '-') {
	    break;
809
810
811
812
813
814
815
816
817


818
819
820
821
822
823
824
813
814
815
816
817
818
819


820
821
822
823
824
825
826
827
828







-
-
+
+







		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't add toplevel %s to %s", arg,
			Tk_PathName(pwPtr->tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", NULL);
		return TCL_ERROR;
	    } else {
		/*
		 * Make sure the panedwindow is the parent of the pane,
		 * or a descendant of the pane's parent.
		 * Make sure the panedwindow is the parent of the slave,
		 * or a descendant of the slave's parent.
		 */

		parent = Tk_Parent(tkwin);
		for (ancestor = pwPtr->tkwin;;ancestor = Tk_Parent(ancestor)) {
		    if (ancestor == parent) {
			break;
		    }
839
840
841
842
843
844
845
846
847


848
849
850
851
852
853
854
855
856
857
858
859
860
861

862
863
864
865


866
867
868
869
870

871
872
873
874


875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

892
893
894
895
896
897

898
899
900
901
902

903
904
905
906

907
908
909


910
911
912

913
914
915
916
917
918
919
920
921
922
923
924
925




926
927
928


929
930
931
932
933

934
935
936
937
938
939


940
941
942
943
944
945
946
947
948
949
950

951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

966
967
968
969
970
971



972
973

974
975
976
977
978
979
980





981
982

983
984
985


986
987

988
989
990


991
992
993
994

995
996
997
998
999
1000
1001





1002
1003
1004
1005

1006
1007
1008
1009
1010



1011
1012
1013

1014
1015
1016
1017
1018
1019
1020


1021
1022
1023


1024
1025
1026

1027
1028

1029
1030

1031
1032
1033
1034
1035
1036


1037
1038
1039
1040
1041

1042
1043
1044
1045
1046



1047
1048
1049
1050
1051
1052
1053

1054
1055
1056

1057
1058

1059
1060
1061

1062
1063
1064

1065
1066

1067
1068
1069
1070
1071
1072
1073
843
844
845
846
847
848
849


850
851
852
853
854
855
856
857
858
859
860
861
862
863
864

865
866
867


868
869
870
871
872
873

874
875
876


877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894

895
896
897
898
899
900

901
902
903
904
905

906
907
908
909

910
911


912
913
914
915

916
917
918
919
920
921
922
923
924
925




926
927
928
929
930


931
932
933
934
935
936

937
938
939
940
941


942
943
944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960
961
962
963
964
965
966
967
968

969
970
971
972



973
974
975
976

977
978
979





980
981
982
983
984
985

986
987


988
989
990

991
992


993
994
995
996
997

998
999
1000





1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011



1012
1013
1014
1015
1016

1017
1018


1019



1020
1021



1022
1023
1024
1025

1026
1027

1028
1029

1030
1031
1032
1033
1034


1035
1036
1037
1038
1039
1040

1041
1042
1043



1044
1045
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055

1056
1057

1058
1059
1060

1061
1062
1063

1064
1065

1066
1067
1068
1069
1070
1071
1072
1073







-
-
+
+













-
+


-
-
+
+




-
+


-
-
+
+
















-
+





-
+




-
+



-
+

-
-
+
+


-
+









-
-
-
-
+
+
+
+

-
-
+
+




-
+




-
-
+
+










-
+














-
+



-
-
-
+
+
+

-
+


-
-
-
-
-
+
+
+
+
+

-
+

-
-
+
+

-
+

-
-
+
+



-
+


-
-
-
-
-
+
+
+
+
+



-
+


-
-
-
+
+
+


-
+

-
-

-
-
-
+
+
-
-
-
+
+


-
+

-
+

-
+




-
-
+
+




-
+


-
-
-
+
+
+






-
+


-
+

-
+


-
+


-
+

-
+







    /*
     * Pre-parse the configuration options, to get the before/after specifiers
     * into an easy-to-find location (a local variable). Also, check the
     * return from Tk_SetOptions once, here, so we can save a little bit of
     * extra testing in the for loop below.
     */

    memset((void *)&options, 0, sizeof(Pane));
    if (Tk_SetOptions(interp, &options, pwPtr->paneOpts,
    memset((void *)&options, 0, sizeof(Slave));
    if (Tk_SetOptions(interp, (char *) &options, pwPtr->slaveOpts,
	    objc - firstOptionArg, objv + firstOptionArg,
	    pwPtr->tkwin, NULL, NULL) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * If either -after or -before was given, find the numerical index that
     * corresponds to the given window. If both -after and -before are given,
     * the option precedence is: -after, then -before.
     */

    index = -1;
    haveLoc = 0;
    if (options.after != NULL) {
    if (options.after != None) {
	tkwin = options.after;
	haveLoc = 1;
	for (i = 0; i < pwPtr->numPanes; i++) {
	    if (options.after == pwPtr->panes[i]->tkwin) {
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    if (options.after == pwPtr->slaves[i]->tkwin) {
		index = i + 1;
		break;
	    }
	}
    } else if (options.before != NULL) {
    } else if (options.before != None) {
	tkwin = options.before;
	haveLoc = 1;
	for (i = 0; i < pwPtr->numPanes; i++) {
	    if (options.before == pwPtr->panes[i]->tkwin) {
	for (i = 0; i < pwPtr->numSlaves; i++) {
	    if (options.before == pwPtr->slaves[i]->tkwin) {
		index = i;
		break;
	    }
	}
    }

    /*
     * If a window was given for -after/-before, but it's not a window managed
     * by the panedwindow, throw an error
     */

    if (haveLoc && index == -1) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window \"%s\" is not managed by %s",
		Tk_PathName(tkwin), Tk_PathName(pwPtr->tkwin)));
	Tcl_SetErrorCode(interp, "TK", "PANEDWINDOW", "UNMANAGED", NULL);
	Tk_FreeConfigOptions(&options, pwPtr->paneOpts,
	Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts,
		pwPtr->tkwin);
	return TCL_ERROR;
    }

    /*
     * Allocate an array to hold, in order, the pointers to the pane
     * Allocate an array to hold, in order, the pointers to the slave
     * structures corresponding to the windows specified. Some of those
     * structures may already have existed, some may be new.
     */

    inserts = (Pane **)ckalloc(sizeof(Pane *) * (firstOptionArg - 2));
    inserts = ckalloc(sizeof(Slave *) * (firstOptionArg - 2));
    insertIndex = 0;

    /*
     * Populate the inserts array, creating new pane structures as necessary,
     * Populate the inserts array, creating new slave structures as necessary,
     * applying the options to each structure as we go, and, if necessary,
     * marking the spot in the original panes array as empty (for
     * pre-existing pane structures).
     * marking the spot in the original slaves array as empty (for
     * pre-existing slave structures).
     */

    for (i = 0, numNewPanes = 0; i < firstOptionArg - 2; i++) {
    for (i = 0, numNewSlaves = 0; i < firstOptionArg - 2; i++) {
	/*
	 * We don't check that tkwin is NULL here, because the pre-pass above
	 * guarantees that the input at this stage is good.
	 */

	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[i + 2]),
		pwPtr->tkwin);

	found = 0;
	for (j = 0; j < pwPtr->numPanes; j++) {
	    if (pwPtr->panes[j] != NULL && pwPtr->panes[j]->tkwin == tkwin) {
		Tk_SetOptions(interp, pwPtr->panes[j],
			pwPtr->paneOpts, objc - firstOptionArg,
	for (j = 0; j < pwPtr->numSlaves; j++) {
	    if (pwPtr->slaves[j] != NULL && pwPtr->slaves[j]->tkwin == tkwin) {
		Tk_SetOptions(interp, (char *) pwPtr->slaves[j],
			pwPtr->slaveOpts, objc - firstOptionArg,
			objv + firstOptionArg, pwPtr->tkwin, NULL, NULL);
		if (pwPtr->panes[j]->minSize < 0) {
		    pwPtr->panes[j]->minSize = 0;
		if (pwPtr->slaves[j]->minSize < 0) {
		    pwPtr->slaves[j]->minSize = 0;
		}
		found = 1;

		/*
		 * If the pane is supposed to move, add it to the inserts
		 * If the slave is supposed to move, add it to the inserts
		 * array now; otherwise, leave it where it is.
		 */

		if (index != -1) {
		    inserts[insertIndex++] = pwPtr->panes[j];
		    pwPtr->panes[j] = NULL;
		    inserts[insertIndex++] = pwPtr->slaves[j];
		    pwPtr->slaves[j] = NULL;
		}
		break;
	    }
	}

	if (found) {
	    continue;
	}

	/*
	 * Make sure this pane wasn't already put into the inserts array,
	 * Make sure this slave wasn't already put into the inserts array,
	 * i.e., when the user specifies the same window multiple times in a
	 * single add commaned.
	 */
	for (j = 0; j < insertIndex; j++) {
	    if (inserts[j]->tkwin == tkwin) {
		found = 1;
		break;
	    }
	}
	if (found) {
	    continue;
	}

	/*
	 * Create a new pane structure and initialize it. All panes start
	 * Create a new slave structure and initialize it. All slaves start
	 * out with their "natural" dimensions.
	 */

	panePtr = (Pane *)ckalloc(sizeof(Pane));
	memset(panePtr, 0, sizeof(Pane));
	Tk_InitOptions(interp, panePtr, pwPtr->paneOpts,
	slavePtr = ckalloc(sizeof(Slave));
	memset(slavePtr, 0, sizeof(Slave));
	Tk_InitOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
		pwPtr->tkwin);
	Tk_SetOptions(interp, panePtr, pwPtr->paneOpts,
	Tk_SetOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
		objc - firstOptionArg, objv + firstOptionArg,
		pwPtr->tkwin, NULL, NULL);
	panePtr->tkwin = tkwin;
	panePtr->containerPtr = pwPtr;
	doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
	if (panePtr->width > 0) {
	    panePtr->paneWidth = panePtr->width;
	slavePtr->tkwin = tkwin;
	slavePtr->masterPtr = pwPtr;
	doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
	if (slavePtr->width > 0) {
	    slavePtr->paneWidth = slavePtr->width;
	} else {
	    panePtr->paneWidth = Tk_ReqWidth(tkwin) + doubleBw;
	    slavePtr->paneWidth = Tk_ReqWidth(tkwin) + doubleBw;
	}
	if (panePtr->height > 0) {
	    panePtr->paneHeight = panePtr->height;
	if (slavePtr->height > 0) {
	    slavePtr->paneHeight = slavePtr->height;
	} else {
	    panePtr->paneHeight = Tk_ReqHeight(tkwin) + doubleBw;
	    slavePtr->paneHeight = Tk_ReqHeight(tkwin) + doubleBw;
	}
	if (panePtr->minSize < 0) {
	    panePtr->minSize = 0;
	if (slavePtr->minSize < 0) {
	    slavePtr->minSize = 0;
	}

	/*
	 * Set up the geometry management callbacks for this pane.
	 * Set up the geometry management callbacks for this slave.
	 */

	Tk_CreateEventHandler(panePtr->tkwin, StructureNotifyMask,
		PaneStructureProc, panePtr);
	Tk_ManageGeometry(panePtr->tkwin, &panedWindowMgrType, panePtr);
	inserts[insertIndex++] = panePtr;
	numNewPanes++;
	Tk_CreateEventHandler(slavePtr->tkwin, StructureNotifyMask,
		SlaveStructureProc, slavePtr);
	Tk_ManageGeometry(slavePtr->tkwin, &panedWindowMgrType, slavePtr);
	inserts[insertIndex++] = slavePtr;
	numNewSlaves++;
    }

    /*
     * Allocate the new panes array, then copy the panes into it, in order.
     * Allocate the new slaves array, then copy the slaves into it, in order.
     */

    i = sizeof(Pane *) * (pwPtr->numPanes + numNewPanes);
    newPanes = (Pane **)ckalloc(i);
    memset(newPanes, 0, i);
    i = sizeof(Slave *) * (pwPtr->numSlaves + numNewSlaves);
    newSlaves = ckalloc(i);
    memset(newSlaves, 0, (size_t) i);
    if (index == -1) {
	/*
	 * If none of the existing panes have to be moved, just copy the old
	 * If none of the existing slaves have to be moved, just copy the old
	 * and append the new.
	 * Be careful about the case pwPtr->numPanes == 0 since in this case
	 * pwPtr->panes is NULL, and the memcpy would have undefined behavior.
	 */
	if (pwPtr->numPanes) {
	    memcpy(newPanes, pwPtr->panes,
		    sizeof(Pane *) * pwPtr->numPanes);
	memcpy((void *)&(newSlaves[0]), pwPtr->slaves,
		sizeof(Slave *) * pwPtr->numSlaves);
	}
	memcpy(&newPanes[pwPtr->numPanes], inserts,
		sizeof(Pane *) * numNewPanes);
	memcpy((void *)&(newSlaves[pwPtr->numSlaves]), inserts,
		sizeof(Slave *) * numNewSlaves);
    } else {
	/*
	 * If some of the existing panes were moved, the old panes array
	 * If some of the existing slaves were moved, the old slaves array
	 * will be partially populated, with some valid and some invalid
	 * entries. Walk through it, copying valid entries to the new panes
	 * entries. Walk through it, copying valid entries to the new slaves
	 * array as we go; when we get to the insert location for the new
	 * panes, copy the inserts array over, then finish off the old panes
	 * slaves, copy the inserts array over, then finish off the old slaves
	 * array.
	 */

	for (i = 0, j = 0; i < index; i++) {
	    if (pwPtr->panes[i] != NULL) {
		newPanes[j] = pwPtr->panes[i];
	    if (pwPtr->slaves[i] != NULL) {
		newSlaves[j] = pwPtr->slaves[i];
		j++;
	    }
	}

	memcpy(&newPanes[j], inserts, sizeof(Pane *)*insertIndex);
	memcpy((void *)&(newSlaves[j]), inserts, sizeof(Slave *)*insertIndex);
	j += firstOptionArg - 2;

	for (i = index; i < pwPtr->numPanes; i++) {
	    if (pwPtr->panes[i] != NULL) {
		newPanes[j] = pwPtr->panes[i];
	for (i = index; i < pwPtr->numSlaves; i++) {
	    if (pwPtr->slaves[i] != NULL) {
		newSlaves[j] = pwPtr->slaves[i];
		j++;
	    }
	}
    }

    /*
     * Make the new panes array the paned window's pane array, and clean up.
     * Make the new slaves array the paned window's slave array, and clean up.
     */

    ckfree(pwPtr->panes);
    ckfree(pwPtr->slaves);
    ckfree(inserts);
    pwPtr->panes = newPanes;
    pwPtr->slaves = newSlaves;

    /*
     * Set the paned window's pane count to the new value.
     * Set the paned window's slave count to the new value.
     */

    pwPtr->numPanes += numNewPanes;
    pwPtr->numSlaves += numNewSlaves;

    Tk_FreeConfigOptions(&options, pwPtr->paneOpts, pwPtr->tkwin);
    Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts, pwPtr->tkwin);

    ComputeGeometry(pwPtr);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1111







-
+







	"coord", "dragto", "mark", "place", NULL
    };
    enum sashOptions {
	SASH_COORD, SASH_DRAGTO, SASH_MARK, SASH_PLACE
    };
    int index, sash, x, y, diff;
    Tcl_Obj *coords[2];
    Pane *panePtr;
    Slave *slavePtr;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[2], sashOptionStrings, "option", 0,
1122
1123
1124
1125
1126
1127
1128
1129

1130
1131
1132
1133

1134
1135
1136


1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167


1168
1169
1170


1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201

1202
1203
1204

1205
1206

1207
1208
1209
1210

1211
1212

1213
1214
1215
1216
1217
1218
1219
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132

1133
1134


1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165


1166
1167
1168


1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203

1204
1205

1206
1207
1208
1209

1210
1211

1212
1213
1214
1215
1216
1217
1218
1219







-
+



-
+

-
-
+
+















-
+













-
-
+
+

-
-
+
+

















-
+












-
+


-
+

-
+



-
+

-
+








	if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (!ValidSashIndex(pwPtr, sash)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "invalid sash index", TCL_INDEX_NONE));
		    "invalid sash index", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "SASH_INDEX", NULL);
	    return TCL_ERROR;
	}
	panePtr = pwPtr->panes[sash];
	slavePtr = pwPtr->slaves[sash];

	coords[0] = Tcl_NewWideIntObj(panePtr->sashx);
	coords[1] = Tcl_NewWideIntObj(panePtr->sashy);
	coords[0] = Tcl_NewIntObj(slavePtr->sashx);
	coords[1] = Tcl_NewIntObj(slavePtr->sashy);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, coords));
	break;

    case SASH_MARK:
	if (objc != 6 && objc != 4) {
	    Tcl_WrongNumArgs(interp, 3, objv, "index ?x y?");
	    return TCL_ERROR;
	}

	if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (!ValidSashIndex(pwPtr, sash)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "invalid sash index", TCL_INDEX_NONE));
		    "invalid sash index", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "SASH_INDEX", NULL);
	    return TCL_ERROR;
	}

	if (objc == 6) {
	    if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
		return TCL_ERROR;
	    }

	    if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
		return TCL_ERROR;
	    }

	    pwPtr->panes[sash]->markx = x;
	    pwPtr->panes[sash]->marky = y;
	    pwPtr->slaves[sash]->markx = x;
	    pwPtr->slaves[sash]->marky = y;
	} else {
	    coords[0] = Tcl_NewWideIntObj(pwPtr->panes[sash]->markx);
	    coords[1] = Tcl_NewWideIntObj(pwPtr->panes[sash]->marky);
	    coords[0] = Tcl_NewIntObj(pwPtr->slaves[sash]->markx);
	    coords[1] = Tcl_NewIntObj(pwPtr->slaves[sash]->marky);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, coords));
	}
	break;

    case SASH_DRAGTO:
    case SASH_PLACE:
	if (objc != 6) {
	    Tcl_WrongNumArgs(interp, 3, objv, "index x y");
	    return TCL_ERROR;
	}

	if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (!ValidSashIndex(pwPtr, sash)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "invalid sash index", TCL_INDEX_NONE));
		    "invalid sash index", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "SASH_INDEX", NULL);
	    return TCL_ERROR;
	}

	if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
	    return TCL_ERROR;
	}

	panePtr = pwPtr->panes[sash];
	slavePtr = pwPtr->slaves[sash];
	if (pwPtr->orient == ORIENT_HORIZONTAL) {
	    if (index == SASH_PLACE) {
		diff = x - pwPtr->panes[sash]->sashx;
		diff = x - pwPtr->slaves[sash]->sashx;
	    } else {
		diff = x - pwPtr->panes[sash]->markx;
		diff = x - pwPtr->slaves[sash]->markx;
	    }
	} else {
	    if (index == SASH_PLACE) {
		diff = y - pwPtr->panes[sash]->sashy;
		diff = y - pwPtr->slaves[sash]->sashy;
	    } else {
		diff = y - pwPtr->panes[sash]->marky;
		diff = y - pwPtr->slaves[sash]->marky;
	    }
	}

	MoveSash(pwPtr, sash, diff);
	ComputeGeometry(pwPtr);
    }
    return TCL_OK;
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259







-
+







    PanedWindow *pwPtr,		/* Information about widget. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    Tk_SavedOptions savedOptions;
    int typemask = 0;

    if (Tk_SetOptions(interp, pwPtr, pwPtr->optionTable, objc, objv,
    if (Tk_SetOptions(interp, (char *) pwPtr, pwPtr->optionTable, objc, objv,
	    pwPtr->tkwin, &savedOptions, &typemask) != TCL_OK) {
	Tk_RestoreSavedOptions(&savedOptions);
	return TCL_ERROR;
    }

    Tk_FreeSavedOptions(&savedOptions);

1287
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297

1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313
1314







-
+



-
+








-
+







 *	Paned window will be relayed out and redisplayed.
 *
 *----------------------------------------------------------------------
 */

static void
PanedWindowWorldChanged(
    void *instanceData)	/* Information about the paned window. */
    ClientData instanceData)	/* Information about the paned window. */
{
    XGCValues gcValues;
    GC newGC;
    PanedWindow *pwPtr = (PanedWindow *)instanceData;
    PanedWindow *pwPtr = instanceData;

    /*
     * Allocated a graphics context for drawing the paned window widget
     * elements (background, sashes, etc.) and set the window background.
     */

    gcValues.background = Tk_3DBorderColor(pwPtr->background)->pixel;
    newGC = Tk_GetGC(pwPtr->tkwin, GCBackground, &gcValues);
    if (pwPtr->gc != NULL) {
    if (pwPtr->gc != None) {
	Tk_FreeGC(pwPtr->display, pwPtr->gc);
    }
    pwPtr->gc = newGC;
    Tk_SetWindowBackground(pwPtr->tkwin, gcValues.background);

    /*
     * Issue geometry size requests to Tk.
1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355

1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374



1375
1376
1377
1378
1379
1380



1381
1382
1383
1384
1385
1386
1387
1345
1346
1347
1348
1349
1350
1351

1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371



1372
1373
1374
1375
1376
1377



1378
1379
1380
1381
1382
1383
1384
1385
1386
1387







-
+


-
+
















-
-
-
+
+
+



-
-
-
+
+
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
PanedWindowEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    PanedWindow *pwPtr = clientData;
    int i;

    if (eventPtr->type == Expose) {
	if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayPanedWindow, pwPtr);
	    pwPtr->flags |= REDRAW_PENDING;
	}
    } else if (eventPtr->type == ConfigureNotify) {
	pwPtr->flags |= REQUESTED_RELAYOUT;
	if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayPanedWindow, pwPtr);
	    pwPtr->flags |= REDRAW_PENDING;
	}
    } else if (eventPtr->type == DestroyNotify) {
	DestroyPanedWindow(pwPtr);
    } else if (eventPtr->type == UnmapNotify) {
        for (i = 0; i < pwPtr->numPanes; i++) {
            if (!pwPtr->panes[i]->hide) {
                Tk_UnmapWindow(pwPtr->panes[i]->tkwin);
        for (i = 0; i < pwPtr->numSlaves; i++) {
            if (!pwPtr->slaves[i]->hide) {
                Tk_UnmapWindow(pwPtr->slaves[i]->tkwin);
            }
        }
    } else if (eventPtr->type == MapNotify) {
        for (i = 0; i < pwPtr->numPanes; i++) {
            if (!pwPtr->panes[i]->hide) {
                Tk_MapWindow(pwPtr->panes[i]->tkwin);
        for (i = 0; i < pwPtr->numSlaves; i++) {
            if (!pwPtr->slaves[i]->hide) {
                Tk_MapWindow(pwPtr->slaves[i]->tkwin);
            }
        }
    }
}

/*
 *----------------------------------------------------------------------
1399
1400
1401
1402
1403
1404
1405
1406

1407
1408

1409
1410
1411
1412
1413
1414
1415
1399
1400
1401
1402
1403
1404
1405

1406
1407

1408
1409
1410
1411
1412
1413
1414
1415







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
PanedWindowCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    PanedWindow *pwPtr = clientData;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted or because the command was deleted,
     * and then this function destroys the widget. The WIDGET_DELETED flag
     * distinguishes these cases.
     */
1436
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446


1447
1448
1449
1450
1451
1452
1453
1436
1437
1438
1439
1440
1441
1442

1443
1444


1445
1446
1447
1448
1449
1450
1451
1452
1453







-
+

-
-
+
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayPanedWindow(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    Pane *panePtr;
    PanedWindow *pwPtr = clientData;
    Slave *slavePtr;
    Pixmap pixmap;
    Tk_Window tkwin = pwPtr->tkwin;
    int i, sashWidth, sashHeight;
    const int horizontal = (pwPtr->orient == ORIENT_HORIZONTAL);
    int first, last;

    pwPtr->flags &= ~REDRAW_PENDING;
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501



1502
1503
1504
1505
1506

1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1492
1493
1494
1495
1496
1497
1498



1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510

1511
1512
1513
1514
1515
1516
1517
1518







-
-
-
+
+
+




-
+




-
+







    }

    /*
     * Draw the sashes.
     */

    GetFirstLastVisiblePane(pwPtr, &first, &last);
    for (i = 0; i < pwPtr->numPanes - 1; i++) {
	panePtr = pwPtr->panes[i];
	if (panePtr->hide || i == last) {
    for (i = 0; i < pwPtr->numSlaves - 1; i++) {
	slavePtr = pwPtr->slaves[i];
	if (slavePtr->hide || i == last) {
	    continue;
	}
	if (sashWidth > 0 && sashHeight > 0) {
	    Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
		    panePtr->sashx, panePtr->sashy, sashWidth, sashHeight,
		    slavePtr->sashx, slavePtr->sashy, sashWidth, sashHeight,
		    1, pwPtr->sashRelief);
	}
	if (pwPtr->showHandle) {
	    Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
		    panePtr->handlex, panePtr->handley,
		    slavePtr->handlex, slavePtr->handley,
		    pwPtr->handleSize, pwPtr->handleSize, 1,
		    TK_RELIEF_RAISED);
	}
    }

#ifndef TK_NO_DOUBLE_BUFFERING
    /*
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575




1576
1577
1578
1579
1580
1581
1582





1583
1584
1585


1586
1587
1588


1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1565
1566
1567
1568
1569
1570
1571




1572
1573
1574
1575
1576
1577





1578
1579
1580
1581
1582
1583


1584
1585
1586


1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
1608







-
-
-
-
+
+
+
+


-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
+
+












-
+







	Tcl_CancelIdleCall(DisplayPanedWindow, pwPtr);
    }
    if (pwPtr->flags & RESIZE_PENDING) {
	Tcl_CancelIdleCall(ArrangePanes, pwPtr);
    }

    /*
     * Clean up the pane list; foreach pane:
     *  o  Cancel the pane's structure notification callback
     *  o  Cancel geometry management for the pane.
     *  o  Free memory for the pane
     * Clean up the slave list; foreach slave:
     *  o  Cancel the slave's structure notification callback
     *  o  Cancel geometry management for the slave.
     *  o  Free memory for the slave
     */

    for (i = 0; i < pwPtr->numPanes; i++) {
	Tk_DeleteEventHandler(pwPtr->panes[i]->tkwin, StructureNotifyMask,
		PaneStructureProc, pwPtr->panes[i]);
	Tk_ManageGeometry(pwPtr->panes[i]->tkwin, NULL, NULL);
	Tk_FreeConfigOptions(pwPtr->panes[i], pwPtr->paneOpts,
    for (i = 0; i < pwPtr->numSlaves; i++) {
	Tk_DeleteEventHandler(pwPtr->slaves[i]->tkwin, StructureNotifyMask,
		SlaveStructureProc, pwPtr->slaves[i]);
	Tk_ManageGeometry(pwPtr->slaves[i]->tkwin, NULL, NULL);
	Tk_FreeConfigOptions((char *) pwPtr->slaves[i], pwPtr->slaveOpts,
		pwPtr->tkwin);
	ckfree(pwPtr->panes[i]);
	pwPtr->panes[i] = NULL;
	ckfree(pwPtr->slaves[i]);
	pwPtr->slaves[i] = NULL;
    }
    if (pwPtr->panes) {
	ckfree(pwPtr->panes);
    if (pwPtr->slaves) {
	ckfree(pwPtr->slaves);
    }

    /*
     * Remove the widget command from the interpreter.
     */

    Tcl_DeleteCommandFromToken(pwPtr->interp, pwPtr->widgetCmd);

    /*
     * Let Tk_FreeConfigOptions clean up the rest.
     */

    Tk_FreeConfigOptions(pwPtr, pwPtr->optionTable, pwPtr->tkwin);
    Tk_FreeConfigOptions((char *) pwPtr, pwPtr->optionTable, pwPtr->tkwin);
    Tcl_Release(pwPtr->tkwin);
    pwPtr->tkwin = NULL;

    Tcl_EventuallyFree(pwPtr, TCL_DYNAMIC);
}

/*
1621
1622
1623
1624
1625
1626
1627
1628

1629
1630

1631
1632
1633
1634


1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645


1646
1647
1648


1649
1650
1651
1652
1653
1654
1655
1656
1657

1658
1659
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
1621
1622
1623
1624
1625
1626
1627

1628
1629

1630
1631
1632


1633
1634
1635
1636
1637
1638
1639
1640
1641

1642
1643


1644
1645
1646


1647
1648
1649
1650
1651
1652
1653
1654
1655
1656

1657
1658
1659

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







-
+

-
+


-
-
+
+







-
+

-
-
+
+

-
-
+
+








-
+


-
+





-
+






-
-
+
+

-
+

-
-
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+

















-
+






-
+


-
-
-
+
+
+














-
+





-
+







 *	the next idle point.
 *
 *--------------------------------------------------------------
 */

static void
PanedWindowReqProc(
    void *clientData,	/* Paned window's information about window
    ClientData clientData,	/* Paned window's information about window
				 * that got new preferred geometry. */
    TCL_UNUSED(Tk_Window))		/* Other Tk-related information about the
    Tk_Window tkwin)		/* Other Tk-related information about the
				 * window. */
{
    Pane *panePtr = (Pane *)clientData;
    PanedWindow *pwPtr = (PanedWindow *) panePtr->containerPtr;
    Slave *slavePtr = clientData;
    PanedWindow *pwPtr = (PanedWindow *) slavePtr->masterPtr;

    if (Tk_IsMapped(pwPtr->tkwin)) {
	if (!(pwPtr->flags & RESIZE_PENDING)) {
	    pwPtr->flags |= RESIZE_PENDING;
	    Tcl_DoWhenIdle(ArrangePanes, pwPtr);
	}
    } else {
	int doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
	int doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;

	if (panePtr->width <= 0) {
	    panePtr->paneWidth = Tk_ReqWidth(panePtr->tkwin) + doubleBw;
	if (slavePtr->width <= 0) {
	    slavePtr->paneWidth = Tk_ReqWidth(slavePtr->tkwin) + doubleBw;
	}
	if (panePtr->height <= 0) {
	    panePtr->paneHeight = Tk_ReqHeight(panePtr->tkwin) + doubleBw;
	if (slavePtr->height <= 0) {
	    slavePtr->paneHeight = Tk_ReqHeight(slavePtr->tkwin) + doubleBw;
	}
	ComputeGeometry(pwPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * PanedWindowLostPaneProc --
 * PanedWindowLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a pane that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all information about the pane. Causes geometry to be
 *	Forgets all information about the slave. Causes geometry to be
 *	recomputed for the panedwindow.
 *
 *--------------------------------------------------------------
 */

static void
PanedWindowLostPaneProc(
    void *clientData,	/* Grid structure for the pane that was
PanedWindowLostSlaveProc(
    ClientData clientData,	/* Grid structure for slave window that was
				 * stolen away. */
    TCL_UNUSED(Tk_Window))		/* Tk's handle for the pane. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    Pane *panePtr = (Pane *)clientData;
    PanedWindow *pwPtr = (PanedWindow *) panePtr->containerPtr;
    register Slave *slavePtr = clientData;
    PanedWindow *pwPtr = (PanedWindow *) slavePtr->masterPtr;

    if (pwPtr->tkwin != Tk_Parent(panePtr->tkwin)) {
	Tk_UnmaintainGeometry(panePtr->tkwin, pwPtr->tkwin);
    if (pwPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
	Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
    }
    Unlink(panePtr);
    Tk_DeleteEventHandler(panePtr->tkwin, StructureNotifyMask,
	    PaneStructureProc, panePtr);
    Tk_UnmapWindow(panePtr->tkwin);
    panePtr->tkwin = NULL;
    ckfree(panePtr);
    Unlink(slavePtr);
    Tk_DeleteEventHandler(slavePtr->tkwin, StructureNotifyMask,
	    SlaveStructureProc, slavePtr);
    Tk_UnmapWindow(slavePtr->tkwin);
    slavePtr->tkwin = NULL;
    ckfree(slavePtr);
    ComputeGeometry(pwPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ArrangePanes --
 *
 *	This function is invoked (using the Tcl_DoWhenIdle mechanism) to
 *	re-layout a set of windows managed by a paned window. It is invoked at
 *	idle time so that a series of pane requests can be merged into a
 *	single layout operation.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The panes of containerPtr may get resized or moved.
 *	The slaves of masterPtr may get resized or moved.
 *
 *--------------------------------------------------------------
 */

static void
ArrangePanes(
    void *clientData)	/* Structure describing parent whose panes
    ClientData clientData)	/* Structure describing parent whose slaves
				 * are to be re-layed out. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    Pane *panePtr;
    int i, newPaneWidth, newPaneHeight, paneX, paneY;
    register PanedWindow *pwPtr = clientData;
    register Slave *slavePtr;
    int i, slaveWidth, slaveHeight, slaveX, slaveY;
    int paneWidth, paneHeight, paneSize, paneMinSize;
    int doubleBw;
    int x, y;
    int sashWidth, sashOffset, sashCount, handleOffset;
    int sashReserve, sxReserve, syReserve;
    int internalBW;
    int paneDynSize, paneDynMinSize, pwHeight, pwWidth, pwSize;
    int first, last;
    int stretchReserve, stretchAmount;
    const int horizontal = (pwPtr->orient == ORIENT_HORIZONTAL);

    pwPtr->flags &= ~(REQUESTED_RELAYOUT|RESIZE_PENDING);

    /*
     * If the parent has no panes anymore, then don't do anything at all:
     * If the parent has no slaves anymore, then don't do anything at all:
     * just leave the parent's size as-is. Otherwise there is no way to
     * "relinquish" control over the parent so another geometry manager can
     * take over.
     */

    if (pwPtr->numPanes == 0) {
    if (pwPtr->numSlaves == 0) {
	return;
    }

    Tcl_Preserve(pwPtr);

    /*
     * Find index of first and last visible panes.
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
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







-
-
+
+

-
+




-
+




-
-
+
+

-
+

-
+

-
-
+
+

-
+

-
+

-
+


-
+











-
-
+
+

-
-
-
+
+
+




-
+



-
+





-
-
-
-
-
-
+
+
+
+
+
+






-
-
+
+

-
+



-
-
+
+

-
+



-
+









-
+







		+ pwPtr->sashPad;
    } else {
	sashWidth = (2 * pwPtr->sashPad) + pwPtr->sashWidth;
	handleOffset = ((pwPtr->sashWidth - pwPtr->handleSize) / 2)
		+ pwPtr->sashPad;
    }

    for (i = sashCount = 0; i < pwPtr->numPanes; i++) {
	panePtr = pwPtr->panes[i];
    for (i = sashCount = 0; i < pwPtr->numSlaves; i++) {
	slavePtr = pwPtr->slaves[i];

	if (panePtr->hide) {
	if (slavePtr->hide) {
	    continue;
	}

	/*
	 * Compute the total size needed by all the panes and the left-over,
	 * Compute the total size needed by all the slaves and the left-over,
	 * or shortage of space available.
	 */

	if (horizontal) {
            if (panePtr->width > 0) {
                paneSize = panePtr->width;
            if (slavePtr->width > 0) {
                paneSize = slavePtr->width;
            } else {
                paneSize = panePtr->paneWidth;
                paneSize = slavePtr->paneWidth;
            }
	    stretchReserve -= paneSize + (2 * panePtr->padx);
	    stretchReserve -= paneSize + (2 * slavePtr->padx);
	} else {
            if (panePtr->height > 0) {
                paneSize = panePtr->height;
            if (slavePtr->height > 0) {
                paneSize = slavePtr->height;
            } else {
                paneSize = panePtr->paneHeight;
                paneSize = slavePtr->paneHeight;
            }
	    stretchReserve -= paneSize + (2 * panePtr->pady);
	    stretchReserve -= paneSize + (2 * slavePtr->pady);
	}
	if (IsStretchable(panePtr->stretch,i,first,last)
	if (IsStretchable(slavePtr->stretch,i,first,last)
		&& Tk_IsMapped(pwPtr->tkwin)) {
	    paneDynSize += paneSize;
	    paneDynMinSize += panePtr->minSize;
	    paneDynMinSize += slavePtr->minSize;
	}
	if (i != last) {
	    stretchReserve -= sashWidth;
	    sashCount++;
	}
    }

    /*
     * Second pass; adjust/arrange panes.
     */

    for (i = 0; i < pwPtr->numPanes; i++) {
	panePtr = pwPtr->panes[i];
    for (i = 0; i < pwPtr->numSlaves; i++) {
	slavePtr = pwPtr->slaves[i];

	if (panePtr->hide) {
	    Tk_UnmaintainGeometry(panePtr->tkwin, pwPtr->tkwin);
	    Tk_UnmapWindow(panePtr->tkwin);
	if (slavePtr->hide) {
	    Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
	    Tk_UnmapWindow(slavePtr->tkwin);
	    continue;
	}

	/*
	 * Compute the size of this pane. The algorithm (assuming a
	 * Compute the size of this slave. The algorithm (assuming a
	 * horizontal paned window) is:
	 *
	 * 1.  Get "base" dimensions. If a width or height is specified for
	 *     this pane, use those values; else use the ReqWidth/ReqHeight.
	 *     this slave, use those values; else use the ReqWidth/ReqHeight.
	 * 2.  Using base dimensions, pane dimensions, and sticky values,
	 *     determine the x and y, and actual width and height of the
	 *     widget.
	 */

	doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
	newPaneWidth = (panePtr->width > 0 ? panePtr->width :
		Tk_ReqWidth(panePtr->tkwin) + doubleBw);
	newPaneHeight = (panePtr->height > 0 ? panePtr->height :
		Tk_ReqHeight(panePtr->tkwin) + doubleBw);
	paneMinSize = panePtr->minSize;
	doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
	slaveWidth = (slavePtr->width > 0 ? slavePtr->width :
		Tk_ReqWidth(slavePtr->tkwin) + doubleBw);
	slaveHeight = (slavePtr->height > 0 ? slavePtr->height :
		Tk_ReqHeight(slavePtr->tkwin) + doubleBw);
	paneMinSize = slavePtr->minSize;

	/*
	 * Calculate pane width and height.
	 */

	if (horizontal) {
            if (panePtr->width > 0) {
                paneSize = panePtr->width;
            if (slavePtr->width > 0) {
                paneSize = slavePtr->width;
            } else {
                paneSize = panePtr->paneWidth;
                paneSize = slavePtr->paneWidth;
            }
	    pwSize = pwWidth;
	} else {
            if (panePtr->height > 0) {
                paneSize = panePtr->height;
            if (slavePtr->height > 0) {
                paneSize = slavePtr->height;
            } else {
                paneSize = panePtr->paneHeight;
                paneSize = slavePtr->paneHeight;
            }
	    pwSize = pwHeight;
	}
	if (IsStretchable(panePtr->stretch, i, first, last)) {
	if (IsStretchable(slavePtr->stretch, i, first, last)) {
	    double frac;

	    if (paneDynSize > 0) {
		frac = (double)paneSize / (double)paneDynSize;
	    } else {
		frac = (double)paneSize / (double)pwSize;
	    }

	    paneDynSize -= paneSize;
	    paneDynMinSize -= panePtr->minSize;
	    paneDynMinSize -= slavePtr->minSize;
	    stretchAmount = (int) (frac * stretchReserve);
	    if (paneSize + stretchAmount >= paneMinSize) {
		stretchReserve -= stretchAmount;
		paneSize += stretchAmount;
	    } else {
		stretchReserve += paneSize - paneMinSize;
		paneSize = paneMinSize;
1895
1896
1897
1898
1899
1900
1901
1902

1903
1904

1905
1906
1907
1908
1909
1910
1911
1895
1896
1897
1898
1899
1900
1901

1902
1903

1904
1905
1906
1907
1908
1909
1910
1911







-
+

-
+







	    } else {
		paneSize += paneDynSize - paneDynMinSize + stretchReserve;
		stretchReserve = paneDynMinSize - paneDynSize;
	    }
	}
	if (horizontal) {
	    paneWidth = paneSize;
	    paneHeight = pwHeight - (2 * panePtr->pady);
	    paneHeight = pwHeight - (2 * slavePtr->pady);
	} else {
	    paneWidth = pwWidth - (2 * panePtr->padx);
	    paneWidth = pwWidth - (2 * slavePtr->padx);
	    paneHeight = paneSize;
	}

	/*
	 * Adjust for area reserved for sashes.
	 */

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
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







-
-
+
+

-
-
+
+


-
-
+
+







-
+



-
-
-
-
+
+
+
+


-
+



-
-
-
-
+
+
+
+




-
+


-
-
-
-
+
+
+
+

-
-
+
+





-
-
-
-
-
+
+
+
+
+

-
-
+
+











-
+












-
+

-
+


-
-
+
+




-
+



-
-
-
-
+
+
+
+






-
+


-
-
-
+
+
+

-
-
+
+



-
-
-
-
+
+
+
+



-
+



-
+

-
+











-
+








-
+






-
-
-
+
+
+







	if (pwWidth - sxReserve < x + paneWidth - internalBW) {
	    paneWidth = pwWidth - sxReserve - x + internalBW;
	}
	if (pwHeight - syReserve < y + paneHeight - internalBW) {
	    paneHeight = pwHeight - syReserve - y + internalBW;
	}

	if (newPaneWidth > paneWidth) {
	    newPaneWidth = paneWidth;
	if (slaveWidth > paneWidth) {
	    slaveWidth = paneWidth;
	}
	if (newPaneHeight > paneHeight) {
	    newPaneHeight = paneHeight;
	if (slaveHeight > paneHeight) {
	    slaveHeight = paneHeight;
	}

	panePtr->x = x;
	panePtr->y = y;
	slavePtr->x = x;
	slavePtr->y = y;

	/*
	 * Compute the location of the sash at the right or bottom of the
	 * parcel and the location of the next parcel.
	 */

	if (horizontal) {
	    x += paneWidth + (2 * panePtr->padx);
	    x += paneWidth + (2 * slavePtr->padx);
	    if (x < internalBW) {
		x = internalBW;
	    }
	    panePtr->sashx = x + sashOffset;
	    panePtr->sashy = y;
	    panePtr->handlex = x + handleOffset;
	    panePtr->handley = y + pwPtr->handlePad;
	    slavePtr->sashx = x + sashOffset;
	    slavePtr->sashy = y;
	    slavePtr->handlex = x + handleOffset;
	    slavePtr->handley = y + pwPtr->handlePad;
	    x += sashWidth;
	} else {
	    y += paneHeight + (2 * panePtr->pady);
	    y += paneHeight + (2 * slavePtr->pady);
	    if (y < internalBW) {
		y = internalBW;
	    }
	    panePtr->sashx = x;
	    panePtr->sashy = y + sashOffset;
	    panePtr->handlex = x + pwPtr->handlePad;
	    panePtr->handley = y + handleOffset;
	    slavePtr->sashx = x;
	    slavePtr->sashy = y + sashOffset;
	    slavePtr->handlex = x + pwPtr->handlePad;
	    slavePtr->handley = y + handleOffset;
	    y += sashWidth;
	}

	/*
	 * Compute the actual dimensions of the pane in the pane.
	 * Compute the actual dimensions of the slave in the pane.
	 */

	paneX = panePtr->x;
	paneY = panePtr->y;
	AdjustForSticky(panePtr->sticky, paneWidth, paneHeight,
		&paneX, &paneY, &newPaneWidth, &newPaneHeight);
	slaveX = slavePtr->x;
	slaveY = slavePtr->y;
	AdjustForSticky(slavePtr->sticky, paneWidth, paneHeight,
		&slaveX, &slaveY, &slaveWidth, &slaveHeight);

	paneX += panePtr->padx;
	paneY += panePtr->pady;
	slaveX += slavePtr->padx;
	slaveY += slavePtr->pady;

	/*
	 * Now put the window in the proper spot.
	 */

	if (newPaneWidth <= 0 || newPaneHeight <= 0 ||
		(horizontal ? paneX - internalBW > pwWidth :
		paneY - internalBW > pwHeight)) {
	    Tk_UnmaintainGeometry(panePtr->tkwin, pwPtr->tkwin);
	    Tk_UnmapWindow(panePtr->tkwin);
	if (slaveWidth <= 0 || slaveHeight <= 0 ||
		(horizontal ? slaveX - internalBW > pwWidth :
		slaveY - internalBW > pwHeight)) {
	    Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
	    Tk_UnmapWindow(slavePtr->tkwin);
	} else {
	    Tk_MaintainGeometry(panePtr->tkwin, pwPtr->tkwin,
		    paneX, paneY, newPaneWidth, newPaneHeight);
	    Tk_MaintainGeometry(slavePtr->tkwin, pwPtr->tkwin,
		    slaveX, slaveY, slaveWidth, slaveHeight);
	}
	sashCount--;
    }
    Tcl_Release(pwPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Unlink --
 *
 *	Remove a pane from a paned window.
 *	Remove a slave from a paned window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The paned window will be scheduled for re-arranging and redrawing.
 *
 *----------------------------------------------------------------------
 */

static void
Unlink(
    Pane *panePtr)		/* Window to unlink. */
    register Slave *slavePtr)		/* Window to unlink. */
{
    PanedWindow *containerPtr;
    register PanedWindow *masterPtr;
    int i, j;

    containerPtr = panePtr->containerPtr;
    if (containerPtr == NULL) {
    masterPtr = slavePtr->masterPtr;
    if (masterPtr == NULL) {
	return;
    }

    /*
     * Find the specified pane in the panedwindow's list of panes, then
     * Find the specified slave in the panedwindow's list of slaves, then
     * remove it from that list.
     */

    for (i = 0; i < containerPtr->numPanes; i++) {
	if (containerPtr->panes[i] == panePtr) {
	    for (j = i; j < containerPtr->numPanes - 1; j++) {
		containerPtr->panes[j] = containerPtr->panes[j + 1];
    for (i = 0; i < masterPtr->numSlaves; i++) {
	if (masterPtr->slaves[i] == slavePtr) {
	    for (j = i; j < masterPtr->numSlaves - 1; j++) {
		masterPtr->slaves[j] = masterPtr->slaves[j + 1];
	    }
	    break;
	}
    }

    /*
     * Clean out any -after or -before references to this pane
     * Clean out any -after or -before references to this slave
     */

    for (i = 0; i < containerPtr->numPanes; i++) {
	if (containerPtr->panes[i]->before == panePtr->tkwin) {
	    containerPtr->panes[i]->before = NULL;
    for (i = 0; i < masterPtr->numSlaves; i++) {
	if (masterPtr->slaves[i]->before == slavePtr->tkwin) {
	    masterPtr->slaves[i]->before = None;
	}
	if (containerPtr->panes[i]->after == panePtr->tkwin) {
	    containerPtr->panes[i]->after = NULL;
	if (masterPtr->slaves[i]->after == slavePtr->tkwin) {
	    masterPtr->slaves[i]->after = None;
	}
    }

    containerPtr->flags |= REQUESTED_RELAYOUT;
    if (!(containerPtr->flags & REDRAW_PENDING)) {
	containerPtr->flags |= REDRAW_PENDING;
	Tcl_DoWhenIdle(DisplayPanedWindow, containerPtr);
    masterPtr->flags |= REQUESTED_RELAYOUT;
    if (!(masterPtr->flags & REDRAW_PENDING)) {
	masterPtr->flags |= REDRAW_PENDING;
	Tcl_DoWhenIdle(DisplayPanedWindow, masterPtr);
    }

    /*
     * Set the pane's containerPtr to NULL, so that we can tell that the pane
     * Set the slave's masterPtr to NULL, so that we can tell that the slave
     * is no longer attached to any panedwindow.
     */

    panePtr->containerPtr = NULL;
    slavePtr->masterPtr = NULL;

    containerPtr->numPanes--;
    masterPtr->numSlaves--;
}

/*
 *----------------------------------------------------------------------
 *
 * GetPane --
 *
 *	Given a token to a Tk window, find the pane that corresponds to that
 *	token in a given paned window.
 *
 * Results:
 *	Pointer to the pane structure, or NULL if the window is not managed
 *	Pointer to the slave structure, or NULL if the window is not managed
 *	by this paned window.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Pane *
static Slave *
GetPane(
    PanedWindow *pwPtr,		/* Pointer to the paned window info. */
    Tk_Window tkwin)		/* Window to search for. */
{
    int i;

    for (i = 0; i < pwPtr->numPanes; i++) {
	if (pwPtr->panes[i]->tkwin == tkwin) {
	    return pwPtr->panes[i];
    for (i = 0; i < pwPtr->numSlaves; i++) {
	if (pwPtr->slaves[i]->tkwin == tkwin) {
	    return pwPtr->slaves[i];
	}
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
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
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







-
-
+
+











-
+









-
-
+
+






-
-
+
+


-
-
+
+


-
-
-
+
+
+










-
+

















-
+







GetFirstLastVisiblePane(
    PanedWindow *pwPtr,		/* Pointer to the paned window info. */
    int *firstPtr, 		/* Returned index for first. */
    int *lastPtr)  		/* Returned index for last. */
{
    int i;

    for (i = 0, *lastPtr = 0, *firstPtr = -1; i < pwPtr->numPanes; i++) {
	if (pwPtr->panes[i]->hide == 0) {
    for (i = 0, *lastPtr = 0, *firstPtr = -1; i < pwPtr->numSlaves; i++) {
	if (pwPtr->slaves[i]->hide == 0) {
	    if (*firstPtr < 0) {
		*firstPtr = i;
	    }
	    *lastPtr = i;
	}
    }
}

/*
 *--------------------------------------------------------------
 *
 * PaneStructureProc --
 * SlaveStructureProc --
 *
 *	This function is invoked whenever StructureNotify events occur for a
 *	window that's managed by a paned window. This function's only purpose
 *	is to clean up when windows are deleted.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The paned window pane structure associated with the window
 *	is freed, and the pane is disassociated from the paned
 *	The paned window slave structure associated with the window
 *	is freed, and the slave is disassociated from the paned
 *	window which managed it.
 *
 *--------------------------------------------------------------
 */

static void
PaneStructureProc(
    void *clientData,	/* Pointer to record describing window item. */
SlaveStructureProc(
    ClientData clientData,	/* Pointer to record describing window item. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Pane *panePtr = (Pane *)clientData;
    PanedWindow *pwPtr = panePtr->containerPtr;
    Slave *slavePtr = clientData;
    PanedWindow *pwPtr = slavePtr->masterPtr;

    if (eventPtr->type == DestroyNotify) {
	Unlink(panePtr);
	panePtr->tkwin = NULL;
	ckfree(panePtr);
	Unlink(slavePtr);
	slavePtr->tkwin = NULL;
	ckfree(slavePtr);
	ComputeGeometry(pwPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ComputeGeometry --
 *
 *	Compute geometry for the paned window, including coordinates of all
 *	panes and each sash.
 *	slave windows and each sash.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Recomputes geometry information for a paned window.
 *
 *----------------------------------------------------------------------
 */

static void
ComputeGeometry(
    PanedWindow *pwPtr)		/* Pointer to the Paned Window structure. */
{
    int i, x, y, doubleBw, internalBw;
    int sashWidth, sashOffset, handleOffset;
    int reqWidth, reqHeight, dim;
    Pane *panePtr;
    Slave *slavePtr;
    const int horizontal = (pwPtr->orient == ORIENT_HORIZONTAL);

    pwPtr->flags |= REQUESTED_RELAYOUT;

    x = y = internalBw = Tk_InternalBorderLeft(pwPtr->tkwin);
    reqWidth = reqHeight = 0;

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
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







-
-
+
+

-
+




-
+



-
-
+
+








-
-
+
+


-
-
+
+









-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+




-
+





-
-
+
+


-
-
+
+

-
-
+
+

-
+





-
-
+
+


-
-
+
+

-
-
+
+

-
+

















-
+







		+ pwPtr->sashPad;
    } else {
	sashWidth = (2 * pwPtr->sashPad) + pwPtr->sashWidth;
	handleOffset = ((pwPtr->sashWidth - pwPtr->handleSize) / 2)
		+ pwPtr->sashPad;
    }

    for (i = 0; i < pwPtr->numPanes; i++) {
	panePtr = pwPtr->panes[i];
    for (i = 0; i < pwPtr->numSlaves; i++) {
	slavePtr = pwPtr->slaves[i];

	if (panePtr->hide) {
	if (slavePtr->hide) {
	    continue;
	}

	/*
	 * First set the coordinates for the top left corner of the pane's
	 * First set the coordinates for the top left corner of the slave's
	 * parcel.
	 */

	panePtr->x = x;
	panePtr->y = y;
	slavePtr->x = x;
	slavePtr->y = y;

	/*
	 * Make sure the pane's paned dimension is at least minsize. This
	 * check may be redundant, since the only way to change a pane's size
	 * is by moving a sash, and that code checks the minsize.
	 */

	if (horizontal) {
	    if (panePtr->paneWidth < panePtr->minSize) {
		panePtr->paneWidth = panePtr->minSize;
	    if (slavePtr->paneWidth < slavePtr->minSize) {
		slavePtr->paneWidth = slavePtr->minSize;
	    }
	} else {
	    if (panePtr->paneHeight < panePtr->minSize) {
		panePtr->paneHeight = panePtr->minSize;
	    if (slavePtr->paneHeight < slavePtr->minSize) {
		slavePtr->paneHeight = slavePtr->minSize;
	    }
	}

	/*
	 * Compute the location of the sash at the right or bottom of the
	 * parcel.
	 */

	if (horizontal) {
	    x += panePtr->paneWidth + (2 * panePtr->padx);
	    panePtr->sashx = x + sashOffset;
	    panePtr->sashy = y;
	    panePtr->handlex = x + handleOffset;
	    panePtr->handley = y + pwPtr->handlePad;
	    x += slavePtr->paneWidth + (2 * slavePtr->padx);
	    slavePtr->sashx = x + sashOffset;
	    slavePtr->sashy = y;
	    slavePtr->handlex = x + handleOffset;
	    slavePtr->handley = y + pwPtr->handlePad;
	    x += sashWidth;
	} else {
	    y += panePtr->paneHeight + (2 * panePtr->pady);
	    panePtr->sashx = x;
	    panePtr->sashy = y + sashOffset;
	    panePtr->handlex = x + pwPtr->handlePad;
	    panePtr->handley = y + handleOffset;
	    y += slavePtr->paneHeight + (2 * slavePtr->pady);
	    slavePtr->sashx = x;
	    slavePtr->sashy = y + sashOffset;
	    slavePtr->handlex = x + pwPtr->handlePad;
	    slavePtr->handley = y + handleOffset;
	    y += sashWidth;
	}

	/*
	 * Find the maximum height/width of the panes, for computing the
	 * Find the maximum height/width of the slaves, for computing the
	 * requested height/width of the paned window.
	 */

	if (horizontal) {
	    /*
	     * If the pane has an explicit height set, use that; otherwise,
	     * use the pane's requested height.
	     * If the slave has an explicit height set, use that; otherwise,
	     * use the slave's requested height.
	     */

	    if (panePtr->height > 0) {
		dim = panePtr->height;
	    if (slavePtr->height > 0) {
		dim = slavePtr->height;
	    } else {
		doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
		dim = Tk_ReqHeight(panePtr->tkwin) + doubleBw;
		doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
		dim = Tk_ReqHeight(slavePtr->tkwin) + doubleBw;
	    }
	    dim += 2 * panePtr->pady;
	    dim += 2 * slavePtr->pady;
	    if (dim > reqHeight) {
		reqHeight = dim;
	    }
	} else {
	    /*
	     * If the pane has an explicit width set use that; otherwise, use
	     * the pane's requested width.
	     * If the slave has an explicit width set use that; otherwise, use
	     * the slave's requested width.
	     */

	    if (panePtr->width > 0) {
		dim = panePtr->width;
	    if (slavePtr->width > 0) {
		dim = slavePtr->width;
	    } else {
		doubleBw = 2 * Tk_Changes(panePtr->tkwin)->border_width;
		dim = Tk_ReqWidth(panePtr->tkwin) + doubleBw;
		doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
		dim = Tk_ReqWidth(slavePtr->tkwin) + doubleBw;
	    }
	    dim += 2 * panePtr->padx;
	    dim += 2 * slavePtr->padx;
	    if (dim > reqWidth) {
		reqWidth = dim;
	    }
	}
    }

    /*
     * The loop above should have left x (or y) equal to the sum of the widths
     * (or heights) of the widgets, plus the size of one sash and the sash
     * padding for each widget, plus the width of the left (or top) border of
     * the paned window.
     *
     * The requested width (or height) is therefore x (or y) minus the size of
     * one sash and padding, plus the width of the right (or bottom) border of
     * the paned window.
     *
     * The height (or width) is equal to the maximum height (or width) of the
     * panes, plus the width of the border of the top and bottom (or left and
     * slaves, plus the width of the border of the top and bottom (or left and
     * right) of the paned window.
     *
     * If the panedwindow has an explicit width/height set use that;
     * otherwise, use the requested width/height.
     */

    if (horizontal) {
2365
2366
2367
2368
2369
2370
2371
2372
2373


2374
2375
2376
2377
2378
2379
2380
2365
2366
2367
2368
2369
2370
2371


2372
2373
2374
2375
2376
2377
2378
2379
2380







-
-
+
+







 *	Frees memory.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyOptionTables(
    void *clientData,	/* Pointer to the OptionTables struct */
    TCL_UNUSED(Tcl_Interp *))		/* Pointer to the calling interp */
    ClientData clientData,	/* Pointer to the OptionTables struct */
    Tcl_Interp *interp)		/* Pointer to the calling interp */
{
    ckfree(clientData);
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
-
+
+

-
+




















-
+







 *	Creates a new Tcl_Obj.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetSticky(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *recordPtr,		/* Pointer to widget record. */
    Tcl_Size internalOffset)		/* Offset within *recordPtr containing the
    int internalOffset)		/* Offset within *recordPtr containing the
				 * sticky value. */
{
    int sticky = *(int *)(recordPtr + internalOffset);
    char buffer[5];
    char *p = &buffer[0];

    if (sticky & STICK_NORTH) {
	*p++ = 'n';
    }
    if (sticky & STICK_EAST) {
	*p++ = 'e';
    }
    if (sticky & STICK_SOUTH) {
	*p++ = 's';
    }
    if (sticky & STICK_WEST) {
	*p++ = 'w';
    }
    *p = '\0';

    return Tcl_NewStringObj(buffer, TCL_INDEX_NONE);
    return Tcl_NewStringObj(buffer, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * SetSticky --
 *
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
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







-
+

-
+




-
+





-
-
+







 *	specified string was empty and that is acceptable.
 *
 *----------------------------------------------------------------------
 */

static int
SetSticky(
    TCL_UNUSED(void *),
    ClientData clientData,
    Tcl_Interp *interp,		/* Current interp; may be used for errors. */
    TCL_UNUSED(Tk_Window),	/* Window for which option is being set. */
    Tk_Window tkwin,		/* Window for which option is being set. */
    Tcl_Obj **value,		/* Pointer to the pointer to the value object.
				 * We use a pointer to the pointer because we
				 * may need to return a value (NULL). */
    char *recordPtr,		/* Pointer to storage for the widget record. */
    Tcl_Size internalOffset,		/* Offset within *recordPtr at which the
    int internalOffset,		/* Offset within *recordPtr at which the
				 * internal value is to be stored. */
    char *oldInternalPtr,	/* Pointer to storage for the old value. */
    int flags)			/* Flags for the option, set Tk_SetOptions. */
{
    int sticky = 0;
    char c;
    void *internalPtr;
    char c, *internalPtr;
    const char *string;

    internalPtr = ComputeSlotAddress(recordPtr, internalOffset);

    if (flags & TK_OPTION_NULL_OK && ObjectIsEmpty(*value)) {
	*value = NULL;
    } else {
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
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







-
-
+
+












-
-
+
+


-
+
















-
-
-
+
+
+

-
-
+
+

-
-
+
+


-
-
+
+



-
+


-
+







 *	Restores the old value.
 *
 *----------------------------------------------------------------------
 */

static void
RestoreSticky(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *internalPtr,		/* Pointer to storage for value. */
    char *oldInternalPtr)	/* Pointer to old value. */
{
    *(int *)internalPtr = *(int *)oldInternalPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * AdjustForSticky --
 *
 *	Given the x,y coords of the top-left corner of a pane, the dimensions
 *	of that pane, and the dimensions of a pane, compute the x,y coords
 *	and actual dimensions of the pane based on the pane's sticky value.
 *	of that pane, and the dimensions of a slave, compute the x,y coords
 *	and actual dimensions of the slave based on the slave's sticky value.
 *
 * Results:
 *	No direct return; sets the x, y, paneWidth and paneHeight to correct
 *	No direct return; sets the x, y, slaveWidth and slaveHeight to correct
 *	values.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
AdjustForSticky(
    int sticky,			/* Sticky value; see top of file for
				 * definition. */
    int cavityWidth,		/* Width of the cavity. */
    int cavityHeight,		/* Height of the cavity. */
    int *xPtr, int *yPtr,	/* Initially, coordinates of the top-left
				 * corner of cavity; also return values for
				 * actual x, y coords of pane. */
    int *paneWidthPtr,		/* Pane width. */
    int *paneHeightPtr)	/* Pane height. */
				 * actual x, y coords of slave. */
    int *slaveWidthPtr,		/* Slave width. */
    int *slaveHeightPtr)	/* Slave height. */
{
    int diffx = 0;		/* Cavity width - pane width. */
    int diffy = 0;		/* Cavity hight - pane height. */
    int diffx = 0;		/* Cavity width - slave width. */
    int diffy = 0;		/* Cavity hight - slave height. */

    if (cavityWidth > *paneWidthPtr) {
	diffx = cavityWidth - *paneWidthPtr;
    if (cavityWidth > *slaveWidthPtr) {
	diffx = cavityWidth - *slaveWidthPtr;
    }

    if (cavityHeight > *paneHeightPtr) {
	diffy = cavityHeight - *paneHeightPtr;
    if (cavityHeight > *slaveHeightPtr) {
	diffy = cavityHeight - *slaveHeightPtr;
    }

    if ((sticky & STICK_EAST) && (sticky & STICK_WEST)) {
	*paneWidthPtr += diffx;
	*slaveWidthPtr += diffx;
    }
    if ((sticky & STICK_NORTH) && (sticky & STICK_SOUTH)) {
	*paneHeightPtr += diffy;
	*slaveHeightPtr += diffy;
    }
    if (!(sticky & STICK_WEST)) {
	*xPtr += (sticky & STICK_EAST) ? diffx : diffx/2;
    }
    if (!(sticky & STICK_NORTH)) {
	*yPtr += (sticky & STICK_SOUTH) ? diffy : diffy/2;
    }
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
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







-
-
+
+








-
+








-
-
-
+
+
+



-
-
+
+

-
-
+
+









-
+










-
+















-
-
+
+



-
+

-
+













-
+

-
+

-
+







-
-
+
+



-
+

-
+

-
-
-
+
+
+

-
+



-
+

-
+







static void
MoveSash(
    PanedWindow *pwPtr,
    int sash,
    int diff)
{
    int i;
    int expandPane, reduceFirst, reduceLast, reduceIncr, paneSize, sashOffset;
    Pane *panePtr;
    int expandPane, reduceFirst, reduceLast, reduceIncr, slaveSize, sashOffset;
    Slave *slavePtr;
    int stretchReserve = 0;
    int nextSash = sash + 1;
    const int horizontal = (pwPtr->orient == ORIENT_HORIZONTAL);

    if (diff == 0)
	return;

    /*
     * Update the pane sizes with their real sizes.
     * Update the slave sizes with their real sizes.
     */

    if (pwPtr->showHandle && pwPtr->handleSize > pwPtr->sashWidth) {
	sashOffset = ((pwPtr->handleSize - pwPtr->sashWidth) / 2)
		+ pwPtr->sashPad;
    } else {
	sashOffset = pwPtr->sashPad;
    }
    for (i = 0; i < pwPtr->numPanes; i++) {
	panePtr = pwPtr->panes[i];
	if (panePtr->hide) {
    for (i = 0; i < pwPtr->numSlaves; i++) {
	slavePtr = pwPtr->slaves[i];
	if (slavePtr->hide) {
	    continue;
	}
	if (horizontal) {
	    panePtr->paneWidth = panePtr->width = panePtr->sashx
		    - sashOffset - panePtr->x - (2 * panePtr->padx);
	    slavePtr->paneWidth = slavePtr->width = slavePtr->sashx
		    - sashOffset - slavePtr->x - (2 * slavePtr->padx);
	} else {
	    panePtr->paneHeight = panePtr->height = panePtr->sashy
		    - sashOffset - panePtr->y - (2 * panePtr->pady);
	    slavePtr->paneHeight = slavePtr->height = slavePtr->sashy
		    - sashOffset - slavePtr->y - (2 * slavePtr->pady);
	}
    }

    /*
     * There must be a next sash since it is only possible to enter this
     * routine when moving an actual sash which implies there exists a visible
     * pane to either side of the sash.
     */

    while (nextSash < pwPtr->numPanes-1 && pwPtr->panes[nextSash]->hide) {
    while (nextSash < pwPtr->numSlaves-1 && pwPtr->slaves[nextSash]->hide) {
	nextSash++;
    }

    /*
     * Consolidate +/-diff variables to reduce duplicate code.
     */

    if (diff > 0) {
	expandPane = sash;
	reduceFirst = nextSash;
	reduceLast = pwPtr->numPanes;
	reduceLast = pwPtr->numSlaves;
	reduceIncr = 1;
    } else {
	diff = abs(diff);
	expandPane = nextSash;
	reduceFirst = sash;
	reduceLast = -1;
	reduceIncr = -1;
    }

    /*
     * Calculate how much room we have to stretch in and adjust diff value
     * accordingly.
     */

    for (i = reduceFirst; i != reduceLast; i += reduceIncr) {
	panePtr = pwPtr->panes[i];
	if (panePtr->hide) {
	slavePtr = pwPtr->slaves[i];
	if (slavePtr->hide) {
	    continue;
	}
	if (horizontal) {
	    stretchReserve += panePtr->width - panePtr->minSize;
	    stretchReserve += slavePtr->width - slavePtr->minSize;
	} else {
	    stretchReserve += panePtr->height - panePtr->minSize;
	    stretchReserve += slavePtr->height - slavePtr->minSize;
	}
    }
    if (stretchReserve <= 0) {
	return;
    }
    if (diff > stretchReserve) {
	diff = stretchReserve;
    }

    /*
     * Expand pane by diff amount.
     */

    panePtr = pwPtr->panes[expandPane];
    slavePtr = pwPtr->slaves[expandPane];
    if (horizontal) {
	panePtr->paneWidth = panePtr->width += diff;
	slavePtr->paneWidth = slavePtr->width += diff;
    } else {
	panePtr->paneHeight = panePtr->height += diff;
	slavePtr->paneHeight = slavePtr->height += diff;
    }

    /*
     * Reduce panes, respecting minsize, until diff amount has been used.
     */

    for (i = reduceFirst; i != reduceLast; i += reduceIncr) {
	panePtr = pwPtr->panes[i];
	if (panePtr->hide) {
	slavePtr = pwPtr->slaves[i];
	if (slavePtr->hide) {
	    continue;
	}
	if (horizontal) {
	    paneSize = panePtr->width;
	    slaveSize = slavePtr->width;
	} else {
	    paneSize = panePtr->height;
	    slaveSize = slavePtr->height;
	}
	if (diff > (paneSize - panePtr->minSize)) {
	    diff -= paneSize - panePtr->minSize;
	    paneSize = panePtr->minSize;
	if (diff > (slaveSize - slavePtr->minSize)) {
	    diff -= slaveSize - slavePtr->minSize;
	    slaveSize = slavePtr->minSize;
	} else {
	    paneSize -= diff;
	    slaveSize -= diff;
	    i = reduceLast - reduceIncr;
	}
	if (horizontal) {
	    panePtr->paneWidth = panePtr->width = paneSize;
	    slavePtr->paneWidth = slavePtr->width = slaveSize;
	} else {
	    panePtr->paneHeight = panePtr->height = paneSize;
	    slavePtr->paneHeight = slavePtr->height = slaveSize;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
2748
2749
2750
2751
2752
2753
2754
2755

2756
2757
2758

2759
2760
2761
2762
2763
2764
2765
2747
2748
2749
2750
2751
2752
2753

2754
2755
2756

2757
2758
2759
2760
2761
2762
2763
2764







-
+


-
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ProxyWindowEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    PanedWindow *pwPtr = clientData;

    if (eventPtr->type == Expose) {
	if (pwPtr->proxywin != NULL &&!(pwPtr->flags & PROXY_REDRAW_PENDING)) {
	    Tcl_DoWhenIdle(DisplayProxyWindow, pwPtr);
	    pwPtr->flags |= PROXY_REDRAW_PENDING;
	}
    }
2781
2782
2783
2784
2785
2786
2787
2788

2789
2790

2791
2792
2793
2794
2795
2796
2797
2780
2781
2782
2783
2784
2785
2786

2787
2788

2789
2790
2791
2792
2793
2794
2795
2796







-
+

-
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
DisplayProxyWindow(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    PanedWindow *pwPtr = (PanedWindow *)clientData;
    PanedWindow *pwPtr = clientData;
    Pixmap pixmap;
    Tk_Window tkwin = pwPtr->proxywin;
    pwPtr->flags &= ~PROXY_REDRAW_PENDING;
    if ((tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

2873
2874
2875
2876
2877
2878
2879
2880
2881


2882
2883
2884
2885
2886
2887
2888
2872
2873
2874
2875
2876
2877
2878


2879
2880
2881
2882
2883
2884
2885
2886
2887







-
-
+
+







    switch ((enum options) index) {
    case PROXY_COORD:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}

	coords[0] = Tcl_NewWideIntObj(pwPtr->proxyx);
	coords[1] = Tcl_NewWideIntObj(pwPtr->proxyy);
	coords[0] = Tcl_NewIntObj(pwPtr->proxyx);
	coords[1] = Tcl_NewIntObj(pwPtr->proxyy);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, coords));
	break;

    case PROXY_FORGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
2946
2947
2948
2949
2950
2951
2952
2953

2954
2955

2956
2957
2958
2959
2960
2961
2962
2945
2946
2947
2948
2949
2950
2951

2952
2953

2954
2955
2956
2957
2958
2959
2960
2961







-
+

-
+







	 */

	pwPtr->proxyx = x;
	pwPtr->proxyy = y;

	/*
	 * Make sure the proxy window is higher in the stacking order than the
	 * panes, so that it will be visible when drawn. It would be more
	 * slaves, so that it will be visible when drawn. It would be more
	 * correct to push the proxy window just high enough to appear above
	 * the highest pane, but it's much easier to just force it all the
	 * the highest slave, but it's much easier to just force it all the
	 * way to the top of the stacking order.
	 */

	Tk_RestackWindow(pwPtr->proxywin, Above, NULL);

	/*
	 * Let Tk_MaintainGeometry take care of placing the window at the
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
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







+
+



-
-
+
+

+
-
+




















-
+

-
-
+
+

-
-
+
+







 *----------------------------------------------------------------------
 */

static int
ObjectIsEmpty(
    Tcl_Obj *objPtr)		/* Object to test. May be NULL. */
{
    int length;

    if (objPtr == NULL) {
	return 1;
    }
    if (objPtr->bytes == NULL) {
	Tcl_GetString(objPtr);
    if (objPtr->bytes != NULL) {
	return (objPtr->length == 0);
    }
    (void)Tcl_GetStringFromObj(objPtr, &length);
    return (objPtr->length == 0);
    return (length == 0);
}

/*
 *----------------------------------------------------------------------
 *
 * ComputeInternalPointer --
 *
 *	Given a pointer to the start of a record and the offset of a slot
 *	within that record, compute the address of that slot.
 *
 * Results:
 *	If offset is non-negative, returns the computed address; else, returns
 *	NULL.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void *
static char *
ComputeSlotAddress(
    void *recordPtr,	/* Pointer to the start of a record. */
    Tcl_Size offset)		/* Offset of a slot within that record; may be TCL_INDEX_NONE. */
    char *recordPtr,	/* Pointer to the start of a record. */
    int offset)		/* Offset of a slot within that record; may be < 0. */
{
    if (offset != TCL_INDEX_NONE) {
	return (char *)recordPtr + offset;
    if (offset >= 0) {
	return recordPtr + offset;
    } else {
	return NULL;
    }
}

/*
 *----------------------------------------------------------------------
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
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







-
-
+
+


-
-
+
+










-
-
+
+







	sashWidth -= 2 * Tk_InternalBorderLeft(pwPtr->tkwin);
	lpad = rpad = 0;
    }

    GetFirstLastVisiblePane(pwPtr, &first, &last);
    isHandle = 0;
    found = -1;
    for (i = 0; i < pwPtr->numPanes - 1; i++) {
	if (pwPtr->panes[i]->hide || i == last) {
    for (i = 0; i < pwPtr->numSlaves - 1; i++) {
	if (pwPtr->slaves[i]->hide || i == last) {
	    continue;
	}
	thisx = pwPtr->panes[i]->sashx;
	thisy = pwPtr->panes[i]->sashy;
	thisx = pwPtr->slaves[i]->sashx;
	thisy = pwPtr->slaves[i]->sashy;

	if (((thisx - lpad) <= x && x <= (thisx + rpad + sashWidth)) &&
		((thisy - tpad) <= y && y <= (thisy + bpad + sashHeight))) {
	    found = i;

	    /*
	     * Determine if the point is over the handle or the sash.
	     */

	    if (pwPtr->showHandle) {
		thisx = pwPtr->panes[i]->handlex;
		thisy = pwPtr->panes[i]->handley;
		thisx = pwPtr->slaves[i]->handlex;
		thisy = pwPtr->slaves[i]->handley;
		if (pwPtr->orient == ORIENT_HORIZONTAL) {
		    if (thisy <= y && y <= (thisy + pwPtr->handleSize)) {
			isHandle = 1;
		    }
		} else {
		    if (thisx <= x && x <= (thisx + pwPtr->handleSize)) {
			isHandle = 1;
3138
3139
3140
3141
3142
3143
3144
3145
3146


3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3140
3141
3142
3143
3144
3145
3146


3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160







-
-
+
+












     * Set results. Note that the empty string is the default (this function
     * is called inside the implementation of a command).
     */

    if (found != -1) {
	Tcl_Obj *list[2];

	list[0] = Tcl_NewWideIntObj(found);
	list[1] = Tcl_NewStringObj((isHandle ? "handle" : "sash"), TCL_INDEX_NONE);
	list[0] = Tcl_NewIntObj(found);
	list[1] = Tcl_NewStringObj((isHandle ? "handle" : "sash"), -1);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, list));
    }
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted generic/tkPkgConfig.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116




















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkPkgConfig.c --
 *
 *	This file contains the configuration information to embed into the tcl
 *	binary library.
 *
 * Copyright © 2002 Andreas Kupries <[email protected]>
 * Copyright © 2017 Stuart Cassoff <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/* Note, the definitions in this module are influenced by the following C
 * preprocessor macros:
 *
 * - _WIN32 || __CYGWIN__	The value for the fontsytem key will be
 *   MAC_OSX_TK			chosen based on these macros/defines.
 *   HAVE_XFT			declares that xft font support was requested.
 *
 * - CFG_RUNTIME_*		Paths to various stuff at runtime.
 * - CFG_INSTALL_*		Paths to various stuff at installation time.
 *
 * - TCL_CFGVAL_ENCODING	string containing the encoding used for the
 *				configuration values.
 */

#include "tkInt.h"


#ifndef TCL_CFGVAL_ENCODING
#define TCL_CFGVAL_ENCODING "utf-8"
#endif

/*
 * Use C preprocessor statements to define the various values for the embedded
 * configuration information.
 */

#if defined(_WIN32)
#  define CFG_FONTSYSTEM	"gdi"
#elif defined(MAC_OSX_TK)
#  define CFG_FONTSYSTEM	"cocoa"
#elif defined(HAVE_XFT)
#  define CFG_FONTSYSTEM	"xft"
#else
#  define CFG_FONTSYSTEM	"x11"
#endif

static const Tcl_Config cfg[] = {
    {"fontsystem",		CFG_FONTSYSTEM},

    /* Runtime paths to various stuff */

#ifdef CFG_RUNTIME_LIBDIR
    {"libdir,runtime",		CFG_RUNTIME_LIBDIR},
#endif
#ifdef CFG_RUNTIME_BINDIR
    {"bindir,runtime",		CFG_RUNTIME_BINDIR},
#endif
#ifdef CFG_RUNTIME_SCRDIR
    {"scriptdir,runtime",	CFG_RUNTIME_SCRDIR},
#endif
#ifdef CFG_RUNTIME_INCDIR
    {"includedir,runtime",	CFG_RUNTIME_INCDIR},
#endif
#ifdef CFG_RUNTIME_DOCDIR
    {"docdir,runtime",		CFG_RUNTIME_DOCDIR},
#endif
#ifdef CFG_RUNTIME_DEMODIR
    {"demodir,runtime",		CFG_RUNTIME_DEMODIR},
#endif
#if !defined(STATIC_BUILD)
    {"dllfile,runtime",		CFG_RUNTIME_DLLFILE},
#endif

    /* Installation paths to various stuff */

#ifdef CFG_INSTALL_LIBDIR
    {"libdir,install",		CFG_INSTALL_LIBDIR},
#endif
#ifdef CFG_INSTALL_BINDIR
    {"bindir,install",		CFG_INSTALL_BINDIR},
#endif
#ifdef CFG_INSTALL_SCRDIR
    {"scriptdir,install",	CFG_INSTALL_SCRDIR},
#endif
#ifdef CFG_INSTALL_INCDIR
    {"includedir,install",	CFG_INSTALL_INCDIR},
#endif
#ifdef CFG_INSTALL_DOCDIR
    {"docdir,install",		CFG_INSTALL_DOCDIR},
#endif
#ifdef CFG_INSTALL_DEMODIR
    {"demodir,install",		CFG_INSTALL_DEMODIR},
#endif

    /* Last entry, closes the array */
    {NULL, NULL}
};

void
TkInitEmbeddedConfigurationInformation(
    Tcl_Interp *interp)		/* Interpreter the configuration command is
				 * registered in. */
{
    Tcl_RegisterConfig(interp, "tk", cfg, TCL_CFGVAL_ENCODING);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkPlace.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20

21
22
23


24
25
26
27
28

29
30
31

32
33
34
35
36
37
38

39
40
41

42
43
44

45
46
47


48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67

68
69
70
71
72
73




74
75
76
77
78
79
80
81
82
83
84
85
86
87
88







89
90
91

92
93
94

95
96
97
98
99
100
101
102
103
104
105
106











107
108
109














110

111
112
113
114
115
116
117




118
119
120
121
122

123
124
125

126
127
128

129
130
131
132
133
134
135
136
137
138
139
140

141
142

143
144
145
146
147
148

149
150
151
152
153
154
155

156
157

158
159
160
161
162
163
164
165
166






167
168
169


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195

196
197

198
199
200
201

202
203
204
205
206

207
208
209
210
211
212
213
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19

20
21


22
23
24
25
26
27

28
29
30

31
32
33
34
35
36
37

38
39
40

41
42
43

44
45


46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66

67
68
69
70
71


72
73
74
75
76
77
78
79
80
81
82
83







84
85
86
87
88
89
90
91
92

93
94
95

96
97











98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129




130
131
132
133
134
135
136
137

138
139
140

141
142
143

144
145
146
147
148
149
150
151
152
153
154
155

156
157

158
159
160
161
162
163

164
165
166
167
168
169
170

171
172

173
174
175
176






177
178
179
180
181
182
183


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209
210

211
212

213
214
215
216

217
218




219
220
221
222
223
224
225
226






-
-
+
+











-
+

-
-
+
+




-
+


-
+






-
+


-
+


-
+

-
-
+
+












-
+






-
+




-
-
+
+
+
+








-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+



-
-
-
-
+
+
+
+




-
+


-
+


-
+











-
+

-
+





-
+






-
+

-
+



-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+




















-
+




-
+

-
+



-
+

-
-
-
-
+







/*
 * tkPlace.c --
 *
 *	This file contains code to implement a simple geometry manager for Tk
 *	based on absolute placement or "rubber-sheet" placement.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"

/*
 * Border modes for relative placement:
 *
 * BM_INSIDE:		relative distances computed using area inside all
 *			borders of container window.
 *			borders of master window.
 * BM_OUTSIDE:		relative distances computed using outside area that
 *			includes all borders of container.
 * BM_IGNORE:		border issues are ignored: place relative to container's
 *			includes all borders of master.
 * BM_IGNORE:		border issues are ignored: place relative to master's
 *			actual window size.
 */

static const char *const borderModeStrings[] = {
    "inside", "ignore", "outside", NULL
    "inside", "outside", "ignore", NULL
};

typedef enum {BM_INSIDE, BM_IGNORE, BM_OUTSIDE} BorderMode;
typedef enum {BM_INSIDE, BM_OUTSIDE, BM_IGNORE} BorderMode;

/*
 * For each window whose geometry is managed by the placer there is a
 * structure of the following type:
 */

typedef struct Content {
typedef struct Slave {
    Tk_Window tkwin;		/* Tk's token for window. */
    Tk_Window inTkwin;		/* Token for the -in window. */
    struct Container *containerPtr;	/* Pointer to information for window relative
    struct Master *masterPtr;	/* Pointer to information for window relative
				 * to which tkwin is placed. This isn't
				 * necessarily the logical parent of tkwin.
				 * NULL means the container was deleted or never
				 * NULL means the master was deleted or never
				 * assigned. */
    struct Content *nextPtr;	/* Next in list of windows placed relative to
				 * same container (NULL for end of list). */
    struct Slave *nextPtr;	/* Next in list of windows placed relative to
				 * same master (NULL for end of list). */
    Tk_OptionTable optionTable;	/* Table that defines configuration options
				 * available for this command. */
    /*
     * Geometry information for window; where there are both relative and
     * absolute values for the same attribute (e.g. x and relX) only one of
     * them is actually used, depending on flags.
     */

    int x, y;			/* X and Y pixel coordinates for tkwin. */
    Tcl_Obj *xPtr, *yPtr;	/* Tcl_Obj rep's of x, y coords, to keep pixel
				 * spec. information. */
    double relX, relY;		/* X and Y coordinates relative to size of
				 * container. */
				 * master. */
    int width, height;		/* Absolute dimensions for tkwin. */
    Tcl_Obj *widthPtr;		/* Tcl_Obj rep of width, to keep pixel
				 * spec. */
    Tcl_Obj *heightPtr;		/* Tcl_Obj rep of height, to keep pixel
				 * spec. */
    double relWidth, relHeight;	/* Dimensions for tkwin relative to size of
				 * container. */
				 * master. */
    Tcl_Obj *relWidthPtr;
    Tcl_Obj *relHeightPtr;
    Tk_Anchor anchor;		/* Which point on tkwin is placed at the given
				 * position. */
    BorderMode borderMode;	/* How to treat borders of container window. */
} Content;
    BorderMode borderMode;	/* How to treat borders of master window. */
    int flags;			/* Various flags; see below for bit
				 * definitions. */
} Slave;

/*
 * Type masks for options:
 */

#define IN_MASK		1

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_ANCHOR, "-anchor", NULL, NULL, "nw", TCL_INDEX_NONE,
	 offsetof(Content, anchor), TK_OPTION_ENUM_VAR, 0, 0},
    {TK_OPTION_STRING_TABLE, "-bordermode", NULL, NULL, "inside", TCL_INDEX_NONE,
	 offsetof(Content, borderMode), TK_OPTION_ENUM_VAR, borderModeStrings, 0},
    {TK_OPTION_PIXELS, "-height", NULL, NULL, "", offsetof(Content, heightPtr),
	 offsetof(Content, height), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_WINDOW, "-in", NULL, NULL, "", TCL_INDEX_NONE, offsetof(Content, inTkwin),
    {TK_OPTION_ANCHOR, "-anchor", NULL, NULL, "nw", -1,
	 Tk_Offset(Slave, anchor), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-bordermode", NULL, NULL, "inside", -1,
	 Tk_Offset(Slave, borderMode), 0, borderModeStrings, 0},
    {TK_OPTION_PIXELS, "-height", NULL, NULL, "", Tk_Offset(Slave, heightPtr),
	 Tk_Offset(Slave, height), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_WINDOW, "-in", NULL, NULL, "", -1, Tk_Offset(Slave, inTkwin),
	 0, 0, IN_MASK},
    {TK_OPTION_DOUBLE, "-relheight", NULL, NULL, "",
	 offsetof(Content, relHeightPtr), offsetof(Content, relHeight),
	 Tk_Offset(Slave, relHeightPtr), Tk_Offset(Slave, relHeight),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_DOUBLE, "-relwidth", NULL, NULL, "",
	 offsetof(Content, relWidthPtr), offsetof(Content, relWidth),
	 Tk_Offset(Slave, relWidthPtr), Tk_Offset(Slave, relWidth),
	 TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_DOUBLE, "-relx", NULL, NULL, "0.0", TCL_INDEX_NONE,
	 offsetof(Content, relX), 0, 0, 0},
    {TK_OPTION_DOUBLE, "-rely", NULL, NULL, "0.0", TCL_INDEX_NONE,
	 offsetof(Content, relY), 0, 0, 0},
    {TK_OPTION_PIXELS, "-width", NULL, NULL, "", offsetof(Content, widthPtr),
	 offsetof(Content, width), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-x", NULL, NULL, "0", offsetof(Content, xPtr),
	 offsetof(Content, x), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-y", NULL, NULL, "0", offsetof(Content, yPtr),
	 offsetof(Content, y), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
    {TK_OPTION_DOUBLE, "-relx", NULL, NULL, "0", -1,
	 Tk_Offset(Slave, relX), 0, 0, 0},
    {TK_OPTION_DOUBLE, "-rely", NULL, NULL, "0", -1,
	 Tk_Offset(Slave, relY), 0, 0, 0},
    {TK_OPTION_PIXELS, "-width", NULL, NULL, "", Tk_Offset(Slave, widthPtr),
	 Tk_Offset(Slave, width), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-x", NULL, NULL, "0", Tk_Offset(Slave, xPtr),
	 Tk_Offset(Slave, x), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-y", NULL, NULL, "0", Tk_Offset(Slave, yPtr),
	 Tk_Offset(Slave, y), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * Flag definitions for Slave structures:
 *
 * CHILD_WIDTH -		1 means -width was specified;
 * CHILD_REL_WIDTH -		1 means -relwidth was specified.
 * CHILD_HEIGHT -		1 means -height was specified;
 * CHILD_REL_HEIGHT -		1 means -relheight was specified.
 */

#define CHILD_WIDTH		1
#define CHILD_REL_WIDTH		2
#define CHILD_HEIGHT		4
#define CHILD_REL_HEIGHT	8

/*
 * For each container window that has a content managed by the placer there is a
 * For each master window that has a slave managed by the placer there is a
 * structure of the following form:
 */

typedef struct Container {
    Tk_Window tkwin;		/* Tk's token for container window. */
    struct Content *contentPtr;	/* First in linked list of content windowslaced
				 * relative to this container. */
typedef struct Master {
    Tk_Window tkwin;		/* Tk's token for master window. */
    struct Slave *slavePtr;	/* First in linked list of slaves placed
				 * relative to this master. */
    int *abortPtr;		/* If non-NULL, it means that there is a nested
				 * call to RecomputePlacement already working on
				 * this window.  *abortPtr may be set to 1 to
				 * abort that nested call.  This happens, for
				 * example, if tkwin or any of its content
				 * example, if tkwin or any of its slaves
				 * is deleted. */
    int flags;			/* See below for bit definitions. */
} Container;
} Master;

/*
 * Flag definitions for containers:
 * Flag definitions for masters:
 *
 * PARENT_RECONFIG_PENDING -	1 means that a call to RecomputePlacement is
 *				already pending via a Do_When_Idle handler.
 */

#define PARENT_RECONFIG_PENDING	1

/*
 * The following structure is the official type record for the placer:
 */

static void		PlaceRequestProc(void *clientData,
static void		PlaceRequestProc(ClientData clientData,
			    Tk_Window tkwin);
static void		PlaceLostContentProc(void *clientData,
static void		PlaceLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);

static const Tk_GeomMgr placerType = {
    "place",			/* name */
    PlaceRequestProc,		/* requestProc */
    PlaceLostContentProc,		/* lostContentProc */
    PlaceLostSlaveProc,		/* lostSlaveProc */
};

/*
 * Forward declarations for functions defined later in this file:
 */

static void		ContentStructureProc(void *clientData,
static void		SlaveStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static int		ConfigureContent(Tcl_Interp *interp, Tk_Window tkwin,
static int		ConfigureSlave(Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_OptionTable table, int objc,
			    Tcl_Obj *const objv[]);
static int		PlaceInfoCommand(Tcl_Interp *interp, Tk_Window tkwin);
static Content *		CreateContent(Tk_Window tkwin, Tk_OptionTable table);
static void		FreeContent(Content *contentPtr);
static Content *		FindContent(Tk_Window tkwin);
static Container *		CreateContainer(Tk_Window tkwin);
static Container *		FindContainer(Tk_Window tkwin);
static void		PlaceStructureProc(void *clientData,
static Slave *		CreateSlave(Tk_Window tkwin, Tk_OptionTable table);
static void		FreeSlave(Slave *slavePtr);
static Slave *		FindSlave(Tk_Window tkwin);
static Master *		CreateMaster(Tk_Window tkwin);
static Master *		FindMaster(Tk_Window tkwin);
static void		MasterStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		RecomputePlacement(void *clientData);
static void		UnlinkContent(Content *contentPtr);
static void		RecomputePlacement(ClientData clientData);
static void		UnlinkSlave(Slave *slavePtr);

/*
 *--------------------------------------------------------------
 *
 * Tk_PlaceObjCmd --
 *
 *	This function is invoked to process the "place" Tcl commands. See the
 *	user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_PlaceObjCmd(
    void *clientData,	/* Interpreter main window. */
    ClientData clientData,	/* Interpreter main window. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window main_win = (Tk_Window)clientData;
    Tk_Window main_win = clientData;
    Tk_Window tkwin;
    Content *contentPtr;
    Slave *slavePtr;
    TkDisplay *dispPtr;
    Tk_OptionTable optionTable;
    static const char *const optionStrings[] = {
	"configure", "content", "forget", "info", "slaves", NULL
	"configure", "forget", "info", "slaves", NULL
    };
    static const char *const optionStringsNoDep[] = {
	"configure", "content", "forget", "info", NULL
    };
    enum options { PLACE_CONFIGURE, PLACE_CONTENT, PLACE_FORGET, PLACE_INFO, PLACE_SLAVES };
    enum options { PLACE_CONFIGURE, PLACE_FORGET, PLACE_INFO, PLACE_SLAVES };
    int index;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option|pathName args");
	return TCL_ERROR;
    }

230
231
232
233
234
235
236
237
238


239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262


263
264
265
266
267
268
269
270
271
272
273
274
275


276
277
278
279
280
281
282
283
284
285


286
287
288

289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304


305
306
307
308
309



310
311
312
313
314
315





316
317
318

319
320
321
322
323
324
325
326
327
328

329
330

331
332
333
334
335
336
337


338
339
340
341


342
343

344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359

360
361
362
363

364
365
366

367
368
369
370
371
372
373



374
375
376
377

378
379
380
381

382
383

384
385
386
387

388
389
390
391
392
393
394
395
396






397
398
399
400
401
402
403
404
405





406
407
408
409
410
411

412
413

414
415
416
417
418
419
420
421
422
423
424
425
426


427
428
429
430
431
432
433



434
435
436
437
438
439

440
441

442
443
444
445
446

447
448
449
450
451
452
453
454
455
456



457
458

459
460
461

462
463
464
465

466
467
468
469
470
471

472
473
474


475
476
477
478
479
480

481
482
483
484
485
486
487


488
489
490


491
492
493


494
495
496
497


498
499

500
501

502
503
504


505
506
507
508
509
510
511


512
513

514
515
516
517
518
519

520
521

522
523
524
525

526
527
528

529
530
531
532
533
534
535



536
537
538

539
540
541
542

543
544
545
546
547
548
549
550
551








552
553

554
555

556
557
558
559
560
561

562
563

564
565
566
567
568

569
570
571
572
573
574
575
576
577
578
579



580
581

582
583
584

585
586
587
588

589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604

605
606
607
608
609
610
611

612
613
614
615
616
617
618

619
620
621
622


623
624
625
626
627
628
629
630
631
632
633

634
635
636


637
638
639





















640

641
642

643
644
645
646

647
648
649
650

651
652
653

654
655
656
657


658
659
660
661
662


663
664
665
666
667
668


669
670
671
672
673

674
675
676


677
678
679
680
681



682
683


684
685
686
687

688
689
690
691
692
693


694
695
696



697
698

699
700

701
702
703
704

705
706
707

708
709
710
711
712
713
714
715
716
717

718
719
720
721
722



723
724
725
726

727
728
729
730
731
732
733





734
735
736

737
738
739
740
741
742
743
744



745
746
747
748
749
750
751
243
244
245
246
247
248
249


250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273


274
275
276
277
278










279
280
281
282
283
284
285
286
287
288


289
290
291
292

293
294
295
296
297
298
299
300

301
302
303
304
305
306
307


308
309
310
311



312
313
314
315





316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332

333


334
335
336
337
338
339


340
341
342
343


344
345
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362

363
364
365
366

367
368
369

370
371
372
373
374



375
376
377
378
379
380

381
382
383
384

385
386

387
388
389
390

391
392
393
394






395
396
397
398
399
400









401
402
403
404
405
406
407
408
409
410

411
412

413
414
415
416
417
418
419
420
421
422
423
424


425
426
427






428
429
430
431
432
433
434
435

436
437

438
439
440
441
442

443
444
445
446
447
448
449
450



451
452
453
454

455
456
457

458
459
460
461

462
463
464
465
466
467

468
469


470
471
472
473
474
475
476

477
478
479
480
481
482


483
484
485


486
487
488


489
490
491
492


493
494
495

496
497

498
499


500
501
502
503
504
505
506


507
508
509

510
511
512
513
514
515

516
517

518
519
520
521

522
523
524

525
526
527
528
529



530
531
532
533
534

535
536
537
538

539
540








541
542
543
544
545
546
547
548
549

550
551

552
553
554
555
556
557

558
559

560
561
562
563
564

565
566
567
568
569
570
571
572
573



574
575
576
577

578
579
580

581
582
583
584

585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607

608
609
610
611
612
613
614

615
616
617


618
619

620
621
622
623
624
625
626
627
628

629
630


631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658

659
660
661
662

663
664
665
666

667
668
669

670
671
672


673
674
675
676
677


678
679
680
681
682
683


684
685
686
687
688
689

690
691


692
693
694
695
696


697
698
699


700
701
702



703






704
705



706
707
708
709

710


711




712



713








714

715
716
717



718
719
720
721
722
723

724
725
726





727
728
729
730
731
732
733

734
735
736
737
738
739



740
741
742
743
744
745
746
747
748
749







-
-
+
+



-
+


















-
-
+
+



-
-
-
-
-
-
-
-
-
-
+
+








-
-
+
+


-
+







-
+






-
-
+
+


-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+


-
+









-
+
-
-
+





-
-
+
+


-
-
+
+

-
+













-
+

-
+



-
+


-
+




-
-
-
+
+
+



-
+



-
+

-
+



-
+



-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+





-
+

-
+











-
-
+
+

-
-
-
-
-
-
+
+
+





-
+

-
+




-
+







-
-
-
+
+
+

-
+


-
+



-
+





-
+

-
-
+
+





-
+





-
-
+
+

-
-
+
+

-
-
+
+


-
-
+
+

-
+

-
+

-
-
+
+





-
-
+
+

-
+





-
+

-
+



-
+


-
+




-
-
-
+
+
+


-
+



-
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+

-
+





-
+

-
+




-
+








-
-
-
+
+
+

-
+


-
+



-
+





-
+









-
+






-
+






-
+


-
-
+
+
-









-
+

-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
+



-
+



-
+


-
+


-
-
+
+



-
-
+
+




-
-
+
+




-
+

-
-
+
+



-
-
+
+
+
-
-
+
+

-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
+
+
+

-
+
-
-
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-

-
+


-
-
-
+
+
+



-
+


-
-
-
-
-
+
+
+
+
+


-
+





-
-
-
+
+
+








	/*
	 * Initialize, if that hasn't been done yet.
	 */

	dispPtr = ((TkWindow *) tkwin)->dispPtr;
	if (!dispPtr->placeInit) {
	    Tcl_InitHashTable(&dispPtr->containerTable, TCL_ONE_WORD_KEYS);
	    Tcl_InitHashTable(&dispPtr->contentTable, TCL_ONE_WORD_KEYS);
	    Tcl_InitHashTable(&dispPtr->masterTable, TCL_ONE_WORD_KEYS);
	    Tcl_InitHashTable(&dispPtr->slaveTable, TCL_ONE_WORD_KEYS);
	    dispPtr->placeInit = 1;
	}

	return ConfigureContent(interp, tkwin, optionTable, objc-2, objv+2);
	return ConfigureSlave(interp, tkwin, optionTable, objc-2, objv+2);
    }

    /*
     * Handle more general case of option followed by window name followed by
     * possible additional arguments.
     */

    if (TkGetWindowFromObj(interp, main_win, objv[2],
	    &tkwin) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Initialize, if that hasn't been done yet.
     */

    dispPtr = ((TkWindow *) tkwin)->dispPtr;
    if (!dispPtr->placeInit) {
	Tcl_InitHashTable(&dispPtr->containerTable, TCL_ONE_WORD_KEYS);
	Tcl_InitHashTable(&dispPtr->contentTable, TCL_ONE_WORD_KEYS);
	Tcl_InitHashTable(&dispPtr->masterTable, TCL_ONE_WORD_KEYS);
	Tcl_InitHashTable(&dispPtr->slaveTable, TCL_ONE_WORD_KEYS);
	dispPtr->placeInit = 1;
    }

    if (Tcl_GetIndexFromObj(NULL, objv[1], optionStrings,
	    "option", 0, &index) != TCL_OK) {
	/*
	 * Call it again without the deprecated ones to get a proper error
	 * message. This works well since there can't be any ambiguity between
	 * deprecated and new options.
	 */

	Tcl_GetIndexFromObjStruct(interp, objv[1], optionStringsNoDep,
		sizeof(char *), "option", 0, &index);
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum options) index) {
    case PLACE_CONFIGURE:
	if (objc == 3 || objc == 4) {
	    Tcl_Obj *objPtr;

	    contentPtr = FindContent(tkwin);
	    if (contentPtr == NULL) {
	    slavePtr = FindSlave(tkwin);
	    if (slavePtr == NULL) {
		return TCL_OK;
	    }
	    objPtr = Tk_GetOptionInfo(interp, contentPtr, optionTable,
	    objPtr = Tk_GetOptionInfo(interp, (char *) slavePtr, optionTable,
		    (objc == 4) ? objv[3] : NULL, tkwin);
	    if (objPtr == NULL) {
		return TCL_ERROR;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    return TCL_OK;
	}
	return ConfigureContent(interp, tkwin, optionTable, objc-3, objv+3);
	return ConfigureSlave(interp, tkwin, optionTable, objc-3, objv+3);

    case PLACE_FORGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "pathName");
	    return TCL_ERROR;
	}
	contentPtr = FindContent(tkwin);
	if (contentPtr == NULL) {
	slavePtr = FindSlave(tkwin);
	if (slavePtr == NULL) {
	    return TCL_OK;
	}
	if ((contentPtr->containerPtr != NULL) &&
		(contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin))) {
	    Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
	if ((slavePtr->masterPtr != NULL) &&
		(slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin))) {
	    Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
	}
	UnlinkContent(contentPtr);
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->contentTable,
		tkwin));
	Tk_DeleteEventHandler(tkwin, StructureNotifyMask, ContentStructureProc,
		contentPtr);
	UnlinkSlave(slavePtr);
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable,
		(char *) tkwin));
	Tk_DeleteEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc,
		slavePtr);
	Tk_ManageGeometry(tkwin, NULL, NULL);
	Tk_UnmapWindow(tkwin);
	FreeContent(contentPtr);
	FreeSlave(slavePtr);
	break;

    case PLACE_INFO:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "pathName");
	    return TCL_ERROR;
	}
	return PlaceInfoCommand(interp, tkwin);

    case PLACE_SLAVES:
    case PLACE_SLAVES: {
    case PLACE_CONTENT: {
	Container *containerPtr;
	Master *masterPtr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "pathName");
	    return TCL_ERROR;
	}
	containerPtr = FindContainer(tkwin);
	if (containerPtr != NULL) {
	masterPtr = FindMaster(tkwin);
	if (masterPtr != NULL) {
	    Tcl_Obj *listPtr = Tcl_NewObj();

	    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		    contentPtr = contentPtr->nextPtr) {
	    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		    slavePtr = slavePtr->nextPtr) {
		Tcl_ListObjAppendElement(NULL, listPtr,
			Tk_NewWindowObj(contentPtr->tkwin));
			TkNewWindowObj(slavePtr->tkwin));
	    }
	    Tcl_SetObjResult(interp, listPtr);
	}
	break;
    }
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * CreateContent --
 * CreateSlave --
 *
 *	Given a Tk_Window token, find the Content structure corresponding to
 *	Given a Tk_Window token, find the Slave structure corresponding to
 *	that token, creating a new one if necessary.
 *
 * Results:
 *	Pointer to the Content structure.
 *	Pointer to the Slave structure.
 *
 * Side effects:
 *	A new Content structure may be created.
 *	A new Slave structure may be created.
 *
 *----------------------------------------------------------------------
 */

static Content *
CreateContent(
    Tk_Window tkwin,		/* Token for desired content. */
static Slave *
CreateSlave(
    Tk_Window tkwin,		/* Token for desired slave. */
    Tk_OptionTable table)
{
    Tcl_HashEntry *hPtr;
    Content *contentPtr;
    register Slave *slavePtr;
    int isNew;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    hPtr = Tcl_CreateHashEntry(&dispPtr->contentTable, (char *) tkwin, &isNew);
    hPtr = Tcl_CreateHashEntry(&dispPtr->slaveTable, (char *) tkwin, &isNew);
    if (!isNew) {
	return (Content *)Tcl_GetHashValue(hPtr);
	return Tcl_GetHashValue(hPtr);
    }

    /*
     * No preexisting content structure for that window, so make a new one and
     * No preexisting slave structure for that window, so make a new one and
     * populate it with some default values.
     */

    contentPtr = (Content *)ckalloc(sizeof(Content));
    memset(contentPtr, 0, sizeof(Content));
    contentPtr->tkwin = tkwin;
    contentPtr->inTkwin = NULL;
    contentPtr->anchor = TK_ANCHOR_NW;
    contentPtr->borderMode = BM_INSIDE;
    slavePtr = ckalloc(sizeof(Slave));
    memset(slavePtr, 0, sizeof(Slave));
    slavePtr->tkwin = tkwin;
    slavePtr->inTkwin = None;
    slavePtr->anchor = TK_ANCHOR_NW;
    slavePtr->borderMode = BM_INSIDE;
    contentPtr->width = INT_MIN;
    contentPtr->height = INT_MIN;
    contentPtr->relWidth = NAN;
    contentPtr->relHeight = NAN;
    contentPtr->optionTable = table;
    Tcl_SetHashValue(hPtr, contentPtr);
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, ContentStructureProc,
	    contentPtr);
    return contentPtr;
    slavePtr->optionTable = table;
    Tcl_SetHashValue(hPtr, slavePtr);
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc,
	    slavePtr);
    return slavePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeContent --
 * FreeSlave --
 *
 *	Frees the resources held by a Content structure.
 *	Frees the resources held by a Slave structure.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	Memory are freed.
 *
 *----------------------------------------------------------------------
 */

static void
FreeContent(
    Content *contentPtr)
FreeSlave(
    Slave *slavePtr)
{
    if (contentPtr->containerPtr && (contentPtr->containerPtr->flags & PARENT_RECONFIG_PENDING)) {
	Tcl_CancelIdleCall(RecomputePlacement, contentPtr->containerPtr);
    }
    Tk_FreeConfigOptions(contentPtr, contentPtr->optionTable,
	    contentPtr->tkwin);
    ckfree(contentPtr);
    Tk_FreeConfigOptions((char *) slavePtr, slavePtr->optionTable,
	    slavePtr->tkwin);
    ckfree(slavePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * FindContent --
 * FindSlave --
 *
 *	Given a Tk_Window token, find the Content structure corresponding to
 *	Given a Tk_Window token, find the Slave structure corresponding to
 *	that token. This is purely a lookup function; it will not create a
 *	record if one does not yet exist.
 *
 * Results:
 *	Pointer to Content structure; NULL if none exists.
 *	Pointer to Slave structure; NULL if none exists.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Content *
FindContent(
    Tk_Window tkwin)		/* Token for desired content. */
static Slave *
FindSlave(
    Tk_Window tkwin)		/* Token for desired slave. */
{
    Tcl_HashEntry *hPtr;
    register Tcl_HashEntry *hPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    hPtr = Tcl_FindHashEntry(&dispPtr->contentTable, tkwin);
    hPtr = Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin);
    if (hPtr == NULL) {
	return NULL;
    }
    return (Content *)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * UnlinkContent --
 * UnlinkSlave --
 *
 *	This function removes a content window from the chain of content windows in its
 *	container.
 *	This function removes a slave window from the chain of slaves in its
 *	master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The content list of contentPtr's container changes.
 *	The slave list of slavePtr's master changes.
 *
 *----------------------------------------------------------------------
 */

static void
UnlinkContent(
    Content *contentPtr)		/* Content structure to be unlinked. */
UnlinkSlave(
    Slave *slavePtr)		/* Slave structure to be unlinked. */
{
    Container *containerPtr;
    Content *prevPtr;
    register Master *masterPtr;
    register Slave *prevPtr;

    containerPtr = contentPtr->containerPtr;
    if (containerPtr == NULL) {
    masterPtr = slavePtr->masterPtr;
    if (masterPtr == NULL) {
	return;
    }
    if (containerPtr->contentPtr == contentPtr) {
	containerPtr->contentPtr = contentPtr->nextPtr;
    if (masterPtr->slavePtr == slavePtr) {
	masterPtr->slavePtr = slavePtr->nextPtr;
    } else {
	for (prevPtr = containerPtr->contentPtr; ; prevPtr = prevPtr->nextPtr) {
	for (prevPtr = masterPtr->slavePtr; ; prevPtr = prevPtr->nextPtr) {
	    if (prevPtr == NULL) {
		Tcl_Panic("UnlinkContent couldn't find content to unlink");
		Tcl_Panic("UnlinkSlave couldn't find slave to unlink");
	    }
	    if (prevPtr->nextPtr == contentPtr) {
		prevPtr->nextPtr = contentPtr->nextPtr;
	    if (prevPtr->nextPtr == slavePtr) {
		prevPtr->nextPtr = slavePtr->nextPtr;
		break;
	    }
	}
    }

    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    contentPtr->containerPtr = NULL;
    slavePtr->masterPtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * CreateContainer --
 * CreateMaster --
 *
 *	Given a Tk_Window token, find the Container structure corresponding to
 *	Given a Tk_Window token, find the Master structure corresponding to
 *	that token, creating a new one if necessary.
 *
 * Results:
 *	Pointer to the Container structure.
 *	Pointer to the Master structure.
 *
 * Side effects:
 *	A new Container structure may be created.
 *	A new Master structure may be created.
 *
 *----------------------------------------------------------------------
 */

static Container *
CreateContainer(
    Tk_Window tkwin)		/* Token for desired container. */
static Master *
CreateMaster(
    Tk_Window tkwin)		/* Token for desired master. */
{
    Tcl_HashEntry *hPtr;
    Container *containerPtr;
    register Master *masterPtr;
    int isNew;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    hPtr = Tcl_CreateHashEntry(&dispPtr->containerTable, (char *)tkwin, &isNew);
    hPtr = Tcl_CreateHashEntry(&dispPtr->masterTable, (char *) tkwin, &isNew);
    if (isNew) {
	containerPtr = (Container *)ckalloc(sizeof(Container));
	containerPtr->tkwin = tkwin;
	containerPtr->contentPtr = NULL;
	containerPtr->abortPtr = NULL;
	containerPtr->flags = 0;
	Tcl_SetHashValue(hPtr, containerPtr);
	Tk_CreateEventHandler(containerPtr->tkwin, StructureNotifyMask,
		PlaceStructureProc, containerPtr);
	masterPtr = ckalloc(sizeof(Master));
	masterPtr->tkwin = tkwin;
	masterPtr->slavePtr = NULL;
	masterPtr->abortPtr = NULL;
	masterPtr->flags = 0;
	Tcl_SetHashValue(hPtr, masterPtr);
	Tk_CreateEventHandler(masterPtr->tkwin, StructureNotifyMask,
		MasterStructureProc, masterPtr);
    } else {
	containerPtr = (Container *)Tcl_GetHashValue(hPtr);
	masterPtr = Tcl_GetHashValue(hPtr);
    }
    return containerPtr;
    return masterPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * FindContainer --
 * FindMaster --
 *
 *	Given a Tk_Window token, find the Container structure corresponding to
 *	Given a Tk_Window token, find the Master structure corresponding to
 *	that token. This is simply a lookup function; a new record will not be
 *	created if one does not already exist.
 *
 * Results:
 *	Pointer to the Container structure; NULL if one does not exist for the
 *	Pointer to the Master structure; NULL if one does not exist for the
 *	given Tk_Window token.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Container *
FindContainer(
    Tk_Window tkwin)		/* Token for desired container. */
static Master *
FindMaster(
    Tk_Window tkwin)		/* Token for desired master. */
{
    Tcl_HashEntry *hPtr;
    register Tcl_HashEntry *hPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    hPtr = Tcl_FindHashEntry(&dispPtr->containerTable, tkwin);
    hPtr = Tcl_FindHashEntry(&dispPtr->masterTable, (char *) tkwin);
    if (hPtr == NULL) {
	return NULL;
    }
    return (Container *)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * ConfigureContent --
 * ConfigureSlave --
 *
 *	This function is called to process an argv/argc list to reconfigure
 *	the placement of a window.
 *
 * Results:
 *	A standard Tcl result. If an error occurs then a message is left in
 *	the interp's result.
 *
 * Side effects:
 *	Information in contentPtr may change, and contentPtr's container is scheduled
 *	Information in slavePtr may change, and slavePtr's master is scheduled
 *	for reconfiguration.
 *
 *----------------------------------------------------------------------
 */

static int
ConfigureContent(
ConfigureSlave(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Window tkwin,		/* Token for the window to manipulate. */
    Tk_OptionTable table,	/* Token for option table. */
    int objc,			/* Number of config arguments. */
    Tcl_Obj *const objv[])	/* Object values for arguments. */
{
    Container *containerPtr;
    register Master *masterPtr;
    Tk_SavedOptions savedOptions;
    int mask;
    Content *contentPtr;
    Tk_Window containerWin = NULL;
    Slave *slavePtr;
    Tk_Window masterWin = (Tk_Window) NULL;
    TkWindow *container;

    if (Tk_TopWinHierarchy(tkwin)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't use placer on top-level window \"%s\"; use "
		"wm command instead", Tk_PathName(tkwin)));
	Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "TOPLEVEL", NULL);
	return TCL_ERROR;
    }

    contentPtr = CreateContent(tkwin, table);
    slavePtr = CreateSlave(tkwin, table);

    if (Tk_SetOptions(interp, contentPtr, table, objc, objv,
	    contentPtr->tkwin, &savedOptions, &mask) != TCL_OK) {
    if (Tk_SetOptions(interp, (char *) slavePtr, table, objc, objv,
	    slavePtr->tkwin, &savedOptions, &mask) != TCL_OK) {
	goto error;
    }

    /*
     * Set slave flags. First clear the field, then add bits as needed.
     */

    slavePtr->flags = 0;
    if (slavePtr->heightPtr) {
	slavePtr->flags |= CHILD_HEIGHT;
    }

    if (slavePtr->relHeightPtr) {
	slavePtr->flags |= CHILD_REL_HEIGHT;
    }

    if (slavePtr->relWidthPtr) {
	slavePtr->flags |= CHILD_REL_WIDTH;
    }

    if (slavePtr->widthPtr) {
	slavePtr->flags |= CHILD_WIDTH;
    }

    if (!(mask & IN_MASK) && (contentPtr->containerPtr != NULL)) {
    if (!(mask & IN_MASK) && (slavePtr->masterPtr != NULL)) {
	/*
	 * If no -in option was passed and the content is already placed then
	 * If no -in option was passed and the slave is already placed then
	 * just recompute the placement.
	 */

	containerPtr = contentPtr->containerPtr;
	masterPtr = slavePtr->masterPtr;
	goto scheduleLayout;
    } else if (mask & IN_MASK) {
	/* -in changed */
	Tk_Window win;
	Tk_Window tkwin;
	Tk_Window ancestor;

	win = contentPtr->inTkwin;
	tkwin = slavePtr->inTkwin;

	/*
	 * Make sure that the new container is either the logical parent of the
	 * content window or a descendant of that window, and that the container and content
	 * Make sure that the new master is either the logical parent of the
	 * slave or a descendant of that window, and that the master and slave
	 * aren't the same.
	 */

	for (ancestor = win; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == Tk_Parent(contentPtr->tkwin)) {
	for (ancestor = tkwin; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == Tk_Parent(slavePtr->tkwin)) {
		break;
	    }
	    if (Tk_TopWinHierarchy(ancestor)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't place \"%s\" relative to \"%s\"",
			Tk_PathName(contentPtr->tkwin), Tk_PathName(win)));
			"can't place %s relative to %s",
			Tk_PathName(slavePtr->tkwin), Tk_PathName(tkwin)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
		goto error;
	    }
	}
	if (contentPtr->tkwin == win) {
	if (slavePtr->tkwin == tkwin) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't place \"%s\" relative to itself",
		    Tk_PathName(contentPtr->tkwin)));
		    "can't place %s relative to itself",
		    Tk_PathName(slavePtr->tkwin)));
	    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL);
	    goto error;
	}

	/*
	if ((slavePtr->masterPtr != NULL)
		&& (slavePtr->masterPtr->tkwin == tkwin)) {
	    /*
	 * Check for management loops.
	 */
	     * Re-using same old master. Nothing to do.
	     */

	for (container = (TkWindow *)win; container != NULL;
	     container = (TkWindow *)TkGetContainer(container)) {
	    if (container == (TkWindow *)contentPtr->tkwin) {
	    masterPtr = slavePtr->masterPtr;
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't put \"%s\" inside \"%s\": would cause management loop",
	            Tk_PathName(contentPtr->tkwin), Tk_PathName(win)));
		Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "LOOP", NULL);
		goto error;
	    }
	    goto scheduleLayout;
	}
	}
	if (win != Tk_Parent(contentPtr->tkwin)) {
	    ((TkWindow *)contentPtr->tkwin)->maintainerPtr = (TkWindow *)win;
	if ((slavePtr->masterPtr != NULL) &&
		(slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin))) {
	    Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
	}

	UnlinkSlave(slavePtr);
	if ((contentPtr->containerPtr != NULL)
		&& (contentPtr->containerPtr->tkwin == win)) {
	masterWin = tkwin;
	    /*
	     * Re-using same old container. Nothing to do.
	     */

    }
	    containerPtr = contentPtr->containerPtr;
	    goto scheduleLayout;
	}

	if ((contentPtr->containerPtr != NULL) &&
		(contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin))) {
	    Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
	}
	UnlinkContent(contentPtr);
	containerWin = win;
    }

    /*
     * If there's no container specified for this content, use its Tk_Parent.
     * If there's no master specified for this slave, use its Tk_Parent.
     */

    if (containerWin == NULL) {
	containerWin = Tk_Parent(contentPtr->tkwin);
	contentPtr->inTkwin = containerWin;
    if (masterWin == NULL) {
	masterWin = Tk_Parent(slavePtr->tkwin);
	slavePtr->inTkwin = masterWin;
    }

    /*
     * Manage the content window in this container.
     * Manage the slave window in this master.
     */

    containerPtr = CreateContainer(containerWin);
    contentPtr->containerPtr = containerPtr;
    contentPtr->nextPtr = containerPtr->contentPtr;
    containerPtr->contentPtr = contentPtr;
    Tk_ManageGeometry(contentPtr->tkwin, &placerType, contentPtr);
    masterPtr = CreateMaster(masterWin);
    slavePtr->masterPtr = masterPtr;
    slavePtr->nextPtr = masterPtr->slavePtr;
    masterPtr->slavePtr = slavePtr;
    Tk_ManageGeometry(slavePtr->tkwin, &placerType, slavePtr);

    /*
     * Arrange for the container to be re-arranged at the first idle moment.
     * Arrange for the master to be re-arranged at the first idle moment.
     */

  scheduleLayout:
    Tk_FreeSavedOptions(&savedOptions);

    if (!(containerPtr->flags & PARENT_RECONFIG_PENDING)) {
	containerPtr->flags |= PARENT_RECONFIG_PENDING;
	Tcl_DoWhenIdle(RecomputePlacement, containerPtr);
    if (!(masterPtr->flags & PARENT_RECONFIG_PENDING)) {
	masterPtr->flags |= PARENT_RECONFIG_PENDING;
	Tcl_DoWhenIdle(RecomputePlacement, masterPtr);
    }
    return TCL_OK;

    /*
     * Error while processing some option, cleanup and return.
     */

773
774
775
776
777
778
779
780

781
782
783
784


785
786
787
788
789


790
791
792


793
794
795
796
797
798



799
800

801
802

803
804

805
806

807
808
809


810
811

812
813

814
815

816
817

818
819
820
821
822


823
824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844
845
846

847
848
849


850
851

852
853
854
855
856

857
858
859
860
861
862
863
864
865


866
867

868
869

870
871
872
873


874
875
876
877
878
879


880
881

882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897













898
899
900
901
902


903
904
905

906
907

908
909

910
911
912


913
914

915
916
917
918
919
920
921
922
923

924
925
926
927
928
929


930
931

932
933
934


935
936

937
938
939
940
941

942
943
944
945
946
947


948
949
950
951
952
953


954
955
956

957
958
959
960
961
962
963
771
772
773
774
775
776
777

778
779
780


781
782
783
784
785


786
787
788


789
790
791
792
793



794
795
796
797

798
799

800
801

802
803

804
805


806
807
808

809
810

811
812

813
814

815
816
817
818


819
820
821
822
823
824
825
826
827
828
829
830

831
832
833
834
835
836
837
838
839
840
841
842
843

844
845


846
847
848

849
850
851
852
853

854
855
856
857
858
859
860
861


862
863
864

865
866

867
868
869


870
871
872
873
874
875


876
877
878

879
880
881
882













883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898


899
900
901
902

903
904

905
906

907
908


909
910
911

912
913
914
915
916
917
918
919
920

921
922
923
924
925


926
927
928

929
930


931
932
933

934
935
936
937
938

939
940
941
942
943


944
945
946
947
948
949


950
951
952
953

954
955
956
957
958
959
960
961







-
+


-
-
+
+



-
-
+
+

-
-
+
+



-
-
-
+
+
+

-
+

-
+

-
+

-
+

-
-
+
+

-
+

-
+

-
+

-
+



-
-
+
+










-
+












-
+

-
-
+
+

-
+




-
+







-
-
+
+

-
+

-
+


-
-
+
+




-
-
+
+

-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+


-
+

-
+

-
+

-
-
+
+

-
+








-
+




-
-
+
+

-
+

-
-
+
+

-
+




-
+




-
-
+
+




-
-
+
+


-
+







 */

static int
PlaceInfoCommand(
    Tcl_Interp *interp,		/* Interp into which to place result. */
    Tk_Window tkwin)		/* Token for the window to get info on. */
{
    Content *contentPtr;
    Slave *slavePtr;
    Tcl_Obj *infoObj;

    contentPtr = FindContent(tkwin);
    if (contentPtr == NULL) {
    slavePtr = FindSlave(tkwin);
    if (slavePtr == NULL) {
	return TCL_OK;
    }
    infoObj = Tcl_NewObj();
    if (contentPtr->containerPtr != NULL) {
	Tcl_AppendToObj(infoObj, "-in", TCL_INDEX_NONE);
    if (slavePtr->masterPtr != NULL) {
	Tcl_AppendToObj(infoObj, "-in", -1);
	Tcl_ListObjAppendElement(NULL, infoObj,
		Tk_NewWindowObj(contentPtr->containerPtr->tkwin));
	Tcl_AppendToObj(infoObj, " ", TCL_INDEX_NONE);
		TkNewWindowObj(slavePtr->masterPtr->tkwin));
	Tcl_AppendToObj(infoObj, " ", -1);
    }
    Tcl_AppendPrintfToObj(infoObj,
	    "-x %d -relx %.4g -y %d -rely %.4g",
	    contentPtr->x, contentPtr->relX, contentPtr->y, contentPtr->relY);
    if (contentPtr->widthPtr) {
	Tcl_AppendPrintfToObj(infoObj, " -width %d", contentPtr->width);
	    slavePtr->x, slavePtr->relX, slavePtr->y, slavePtr->relY);
    if (slavePtr->flags & CHILD_WIDTH) {
	Tcl_AppendPrintfToObj(infoObj, " -width %d", slavePtr->width);
    } else {
	Tcl_AppendToObj(infoObj, " -width {}", TCL_INDEX_NONE);
	Tcl_AppendToObj(infoObj, " -width {}", -1);
    }
    if (contentPtr->relWidthPtr) {
    if (slavePtr->flags & CHILD_REL_WIDTH) {
	Tcl_AppendPrintfToObj(infoObj,
		" -relwidth %.4g", contentPtr->relWidth);
		" -relwidth %.4g", slavePtr->relWidth);
    } else {
	Tcl_AppendToObj(infoObj, " -relwidth {}", TCL_INDEX_NONE);
	Tcl_AppendToObj(infoObj, " -relwidth {}", -1);
    }
    if (contentPtr->heightPtr) {
	Tcl_AppendPrintfToObj(infoObj, " -height %d", contentPtr->height);
    if (slavePtr->flags & CHILD_HEIGHT) {
	Tcl_AppendPrintfToObj(infoObj, " -height %d", slavePtr->height);
    } else {
	Tcl_AppendToObj(infoObj, " -height {}", TCL_INDEX_NONE);
	Tcl_AppendToObj(infoObj, " -height {}", -1);
    }
    if (contentPtr->relHeightPtr) {
    if (slavePtr->flags & CHILD_REL_HEIGHT) {
	Tcl_AppendPrintfToObj(infoObj,
		" -relheight %.4g", contentPtr->relHeight);
		" -relheight %.4g", slavePtr->relHeight);
    } else {
	Tcl_AppendToObj(infoObj, " -relheight {}", TCL_INDEX_NONE);
	Tcl_AppendToObj(infoObj, " -relheight {}", -1);
    }

    Tcl_AppendPrintfToObj(infoObj, " -anchor %s -bordermode %s",
	    Tk_NameOfAnchor(contentPtr->anchor),
	    borderModeStrings[contentPtr->borderMode]);
	    Tk_NameOfAnchor(slavePtr->anchor),
	    borderModeStrings[slavePtr->borderMode]);
    Tcl_SetObjResult(interp, infoObj);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * RecomputePlacement --
 *
 *	This function is called as a when-idle handler. It recomputes the
 *	geometries of all the content of a given container.
 *	geometries of all the slaves of a given master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Windows may change size or shape.
 *
 *----------------------------------------------------------------------
 */

static void
RecomputePlacement(
    void *clientData)	/* Pointer to Container record. */
    ClientData clientData)	/* Pointer to Master record. */
{
    Container *containerPtr = (Container *)clientData;
    Content *contentPtr;
    register Master *masterPtr = clientData;
    register Slave *slavePtr;
    int x, y, width, height, tmp;
    int containerWidth, containerHeight, containerX, containerY;
    int masterWidth, masterHeight, masterX, masterY;
    double x1, y1, x2, y2;
    int abort;			/* May get set to non-zero to abort this
				 * placement operation. */

    containerPtr->flags &= ~PARENT_RECONFIG_PENDING;
    masterPtr->flags &= ~PARENT_RECONFIG_PENDING;

    /*
     * Abort any nested call to RecomputePlacement for this window, since
     * we'll do everything necessary here, and set up so this call can be
     * aborted if necessary.
     */

    if (containerPtr->abortPtr != NULL) {
	*containerPtr->abortPtr = 1;
    if (masterPtr->abortPtr != NULL) {
	*masterPtr->abortPtr = 1;
    }
    containerPtr->abortPtr = &abort;
    masterPtr->abortPtr = &abort;
    abort = 0;
    Tcl_Preserve(containerPtr);
    Tcl_Preserve(masterPtr);

    /*
     * Iterate over all the content windows for the container. Each content's geometry can
     * be computed independently of the other content. Changes to the window's
     * Iterate over all the slaves for the master. Each slave's geometry can
     * be computed independently of the other slaves. Changes to the window's
     * structure could cause almost anything to happen, including deleting the
     * parent or child. If this happens, we'll be told to abort.
     */

    for (contentPtr = containerPtr->contentPtr; contentPtr != NULL && !abort;
	    contentPtr = contentPtr->nextPtr) {
    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL && !abort;
	    slavePtr = slavePtr->nextPtr) {
	/*
	 * Step 1: compute size and borderwidth of container, taking into account
	 * Step 1: compute size and borderwidth of master, taking into account
	 * desired border mode.
	 */

	containerX = containerY = 0;
	containerWidth = Tk_Width(containerPtr->tkwin);
	containerHeight = Tk_Height(containerPtr->tkwin);
	if (contentPtr->borderMode == BM_INSIDE) {
	    containerX = Tk_InternalBorderLeft(containerPtr->tkwin);
	    containerY = Tk_InternalBorderTop(containerPtr->tkwin);
	    containerWidth -= containerX + Tk_InternalBorderRight(containerPtr->tkwin);
	    containerHeight -= containerY +
		    Tk_InternalBorderBottom(containerPtr->tkwin);
	} else if (contentPtr->borderMode == BM_OUTSIDE) {
	    containerX = containerY = -Tk_Changes(containerPtr->tkwin)->border_width;
	    containerWidth -= 2 * containerX;
	    containerHeight -= 2 * containerY;
	masterX = masterY = 0;
	masterWidth = Tk_Width(masterPtr->tkwin);
	masterHeight = Tk_Height(masterPtr->tkwin);
	if (slavePtr->borderMode == BM_INSIDE) {
	    masterX = Tk_InternalBorderLeft(masterPtr->tkwin);
	    masterY = Tk_InternalBorderTop(masterPtr->tkwin);
	    masterWidth -= masterX + Tk_InternalBorderRight(masterPtr->tkwin);
	    masterHeight -= masterY +
		    Tk_InternalBorderBottom(masterPtr->tkwin);
	} else if (slavePtr->borderMode == BM_OUTSIDE) {
	    masterX = masterY = -Tk_Changes(masterPtr->tkwin)->border_width;
	    masterWidth -= 2 * masterX;
	    masterHeight -= 2 * masterY;
	}

	/*
	 * Step 2: compute size of content (outside dimensions including border)
	 * and location of anchor point within container.
	 * Step 2: compute size of slave (outside dimensions including border)
	 * and location of anchor point within master.
	 */

	x1 = contentPtr->x + containerX + (contentPtr->relX*containerWidth);
	x1 = slavePtr->x + masterX + (slavePtr->relX*masterWidth);
	x = (int) (x1 + ((x1 > 0) ? 0.5 : -0.5));
	y1 = contentPtr->y + containerY + (contentPtr->relY*containerHeight);
	y1 = slavePtr->y + masterY + (slavePtr->relY*masterHeight);
	y = (int) (y1 + ((y1 > 0) ? 0.5 : -0.5));
	if ((contentPtr->widthPtr) || contentPtr->relWidthPtr) {
	if (slavePtr->flags & (CHILD_WIDTH|CHILD_REL_WIDTH)) {
	    width = 0;
	    if (contentPtr->widthPtr) {
		width += contentPtr->width;
	    if (slavePtr->flags & CHILD_WIDTH) {
		width += slavePtr->width;
	    }
	    if (contentPtr->relWidthPtr) {
	    if (slavePtr->flags & CHILD_REL_WIDTH) {
		/*
		 * The code below is a bit tricky. In order to round correctly
		 * when both relX and relWidth are specified, compute the
		 * location of the right edge and round that, then compute
		 * width. If we compute the width and round it, rounding
		 * errors in relX and relWidth accumulate.
		 */

		x2 = x1 + (contentPtr->relWidth*containerWidth);
		x2 = x1 + (slavePtr->relWidth*masterWidth);
		tmp = (int) (x2 + ((x2 > 0) ? 0.5 : -0.5));
		width += tmp - x;
	    }
	} else {
	    width = Tk_ReqWidth(contentPtr->tkwin)
		    + 2*Tk_Changes(contentPtr->tkwin)->border_width;
	    width = Tk_ReqWidth(slavePtr->tkwin)
		    + 2*Tk_Changes(slavePtr->tkwin)->border_width;
	}
	if (contentPtr->heightPtr || contentPtr->relHeightPtr) {
	if (slavePtr->flags & (CHILD_HEIGHT|CHILD_REL_HEIGHT)) {
	    height = 0;
	    if (contentPtr->heightPtr) {
		height += contentPtr->height;
	    if (slavePtr->flags & CHILD_HEIGHT) {
		height += slavePtr->height;
	    }
	    if (contentPtr->relHeightPtr) {
	    if (slavePtr->flags & CHILD_REL_HEIGHT) {
		/*
		 * See note above for rounding errors in width computation.
		 */

		y2 = y1 + (contentPtr->relHeight*containerHeight);
		y2 = y1 + (slavePtr->relHeight*masterHeight);
		tmp = (int) (y2 + ((y2 > 0) ? 0.5 : -0.5));
		height += tmp - y;
	    }
	} else {
	    height = Tk_ReqHeight(contentPtr->tkwin)
		    + 2*Tk_Changes(contentPtr->tkwin)->border_width;
	    height = Tk_ReqHeight(slavePtr->tkwin)
		    + 2*Tk_Changes(slavePtr->tkwin)->border_width;
	}

	/*
	 * Step 3: adjust the x and y positions so that the desired anchor
	 * point on the content appears at that position. Also adjust for the
	 * border mode and container's border.
	 * point on the slave appears at that position. Also adjust for the
	 * border mode and master's border.
	 */

	switch (contentPtr->anchor) {
	switch (slavePtr->anchor) {
	case TK_ANCHOR_N:
	    x -= width/2;
	    break;
	case TK_ANCHOR_NE:
	    x -= width;
	    break;
	case TK_ANCHOR_E:
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996


997
998
999
1000
1001
1002
1003
1004
1005
1006
1007



1008
1009
1010
1011
1012
1013
1014
1015
1016






1017
1018
1019
1020
1021
1022
1023
1024


1025
1026
1027
1028


1029
1030
1031
1032
1033


1034
1035

1036
1037
1038
1039
1040
1041
1042


1043
1044
1045
1046
1047
1048

1049
1050
1051

1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065


1066
1067
1068
1069
1070
1071



1072
1073
1074
1075
1076
1077
1078




1079
1080
1081
1082
1083
1084
1085
1086





1087
1088
1089
1090
1091




1092
1093
1094
1095



1096
1097

1098
1099
1100
1101
1102


1103
1104
1105
1106
1107
1108




1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119



1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144


1145
1146
1147
1148
1149


1150
1151
1152
1153


1154
1155
1156
1157



1158
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182


1183
1184
1185


1186
1187
1188

1189
1190
1191
1192
1193

1194
1195
1196
1197
1198


1199
1200
1201
1202
1203



1204
1205
1206
1207
1208
1209
1210

1211
1212
1213

1214
1215
1216
1217
1218
1219

1220
1221
1222
1223

1224
1225
1226


1227
1228

1229
1230
1231


1232
1233
1234


1235
1236
1237
1238
1239
1240
1241
1242






1243
1244
1245
1246
1247
1248
1249
1250
1251
974
975
976
977
978
979
980

981
982
983
984
985
986
987
988
989
990
991
992


993
994
995
996
997
998
999
1000
1001
1002



1003
1004
1005
1006
1007
1008






1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020


1021
1022
1023
1024


1025
1026
1027
1028
1029


1030
1031
1032

1033
1034
1035
1036
1037
1038


1039
1040
1041
1042
1043
1044
1045

1046
1047
1048

1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061


1062
1063
1064
1065
1066



1067
1068
1069
1070
1071
1072




1073
1074
1075
1076
1077
1078
1079





1080
1081
1082
1083
1084
1085




1086
1087
1088
1089
1090



1091
1092
1093
1094

1095
1096
1097
1098


1099
1100
1101
1102




1103
1104
1105
1106
1107
1108
1109
1110

1111
1112
1113
1114



1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140


1141
1142
1143
1144
1145


1146
1147
1148
1149


1150
1151
1152



1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179


1180
1181
1182


1183
1184
1185


1186





1187

1188
1189


1190
1191
1192
1193



1194
1195
1196
1197
1198
1199
1200
1201
1202

1203
1204
1205

1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218


1219
1220
1221

1222
1223


1224
1225
1226


1227
1228
1229
1230






1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245







-
+











-
-
+
+








-
-
-
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+






-
-
+
+


-
-
+
+



-
-
+
+

-
+





-
-
+
+





-
+


-
+






-
+





-
-
+
+



-
-
-
+
+
+



-
-
-
-
+
+
+
+



-
-
-
-
-
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
+



-
-
+
+


-
-
-
-
+
+
+
+




-
+



-
-
-
+
+
+








-
+


-
+











-
-
+
+



-
-
+
+


-
-
+
+

-
-
-
+
+
+








-
+












+


-
-
+
+

-
-
+
+

-
-
+
-
-
-
-
-
+
-


-
-
+
+


-
-
-
+
+
+






-
+


-
+





-
+




+

-
-
+
+

-
+

-
-
+
+

-
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+









	    y -= height;
	    break;
	case TK_ANCHOR_W:
	    y -= height/2;
	    break;
	case TK_ANCHOR_NW:
	    break;
	default:
	case TK_ANCHOR_CENTER:
	    x -= width/2;
	    y -= height/2;
	    break;
	}

	/*
	 * Step 4: adjust width and height again to reflect inside dimensions
	 * of window rather than outside. Also make sure that the width and
	 * height aren't zero.
	 */

	width -= 2*Tk_Changes(contentPtr->tkwin)->border_width;
	height -= 2*Tk_Changes(contentPtr->tkwin)->border_width;
	width -= 2*Tk_Changes(slavePtr->tkwin)->border_width;
	height -= 2*Tk_Changes(slavePtr->tkwin)->border_width;
	if (width <= 0) {
	    width = 1;
	}
	if (height <= 0) {
	    height = 1;
	}

	/*
	 * Step 5: reconfigure the window and map it if needed. If the content
	 * is a child of the container, we do this ourselves. If the content isn't
	 * a child of the container, let Tk_MaintainGeometry do the work (it will
	 * Step 5: reconfigure the window and map it if needed. If the slave
	 * is a child of the master, we do this ourselves. If the slave isn't
	 * a child of the master, let Tk_MaintainGeometry do the work (it will
	 * re-adjust things as relevant windows map, unmap, and move).
	 */

	if (containerPtr->tkwin == Tk_Parent(contentPtr->tkwin)) {
	    if ((x != Tk_X(contentPtr->tkwin))
		    || (y != Tk_Y(contentPtr->tkwin))
		    || (width != Tk_Width(contentPtr->tkwin))
		    || (height != Tk_Height(contentPtr->tkwin))) {
		Tk_MoveResizeWindow(contentPtr->tkwin, x, y, width, height);
	if (masterPtr->tkwin == Tk_Parent(slavePtr->tkwin)) {
	    if ((x != Tk_X(slavePtr->tkwin))
		    || (y != Tk_Y(slavePtr->tkwin))
		    || (width != Tk_Width(slavePtr->tkwin))
		    || (height != Tk_Height(slavePtr->tkwin))) {
		Tk_MoveResizeWindow(slavePtr->tkwin, x, y, width, height);
	    }
            if (abort) {
                break;
            }

	    /*
	     * Don't map the content unless the container is mapped: the content will
	     * get mapped later, when the container is mapped.
	     * Don't map the slave unless the master is mapped: the slave will
	     * get mapped later, when the master is mapped.
	     */

	    if (Tk_IsMapped(containerPtr->tkwin)) {
		Tk_MapWindow(contentPtr->tkwin);
	    if (Tk_IsMapped(masterPtr->tkwin)) {
		Tk_MapWindow(slavePtr->tkwin);
	    }
	} else {
	    if ((width <= 0) || (height <= 0)) {
		Tk_UnmaintainGeometry(contentPtr->tkwin, containerPtr->tkwin);
		Tk_UnmapWindow(contentPtr->tkwin);
		Tk_UnmaintainGeometry(slavePtr->tkwin, masterPtr->tkwin);
		Tk_UnmapWindow(slavePtr->tkwin);
	    } else {
		Tk_MaintainGeometry(contentPtr->tkwin, containerPtr->tkwin,
		Tk_MaintainGeometry(slavePtr->tkwin, masterPtr->tkwin,
			x, y, width, height);
	    }
	}
    }

    containerPtr->abortPtr = NULL;
    Tcl_Release(containerPtr);
    masterPtr->abortPtr = NULL;
    Tcl_Release(masterPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * PlaceStructureProc --
 * MasterStructureProc --
 *
 *	This function is invoked by the Tk event handler when StructureNotify
 *	events occur for a container window.
 *	events occur for a master window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Structures get cleaned up if the window was deleted. If the window was
 *	resized then content geometries get recomputed.
 *	resized then slave geometries get recomputed.
 *
 *----------------------------------------------------------------------
 */

static void
PlaceStructureProc(
    void *clientData,	/* Pointer to Container structure for window
MasterStructureProc(
    ClientData clientData,	/* Pointer to Master structure for window
				 * referred to by eventPtr. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Container *containerPtr = (Container *)clientData;
    Content *contentPtr, *nextPtr;
    TkDisplay *dispPtr = ((TkWindow *) containerPtr->tkwin)->dispPtr;
    register Master *masterPtr = clientData;
    register Slave *slavePtr, *nextPtr;
    TkDisplay *dispPtr = ((TkWindow *) masterPtr->tkwin)->dispPtr;

    switch (eventPtr->type) {
    case ConfigureNotify:
	if ((containerPtr->contentPtr != NULL)
		&& !(containerPtr->flags & PARENT_RECONFIG_PENDING)) {
	    containerPtr->flags |= PARENT_RECONFIG_PENDING;
	    Tcl_DoWhenIdle(RecomputePlacement, containerPtr);
	if ((masterPtr->slavePtr != NULL)
		&& !(masterPtr->flags & PARENT_RECONFIG_PENDING)) {
	    masterPtr->flags |= PARENT_RECONFIG_PENDING;
	    Tcl_DoWhenIdle(RecomputePlacement, masterPtr);
	}
	return;
    case DestroyNotify:
	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = nextPtr) {
	    contentPtr->containerPtr = NULL;
	    nextPtr = contentPtr->nextPtr;
	    contentPtr->nextPtr = NULL;
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = nextPtr) {
	    slavePtr->masterPtr = NULL;
	    nextPtr = slavePtr->nextPtr;
	    slavePtr->nextPtr = NULL;
	}
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->containerTable,
		containerPtr->tkwin));
	if (containerPtr->flags & PARENT_RECONFIG_PENDING) {
	    Tcl_CancelIdleCall(RecomputePlacement, containerPtr);
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->masterTable,
		(char *) masterPtr->tkwin));
	if (masterPtr->flags & PARENT_RECONFIG_PENDING) {
	    Tcl_CancelIdleCall(RecomputePlacement, masterPtr);
	}
	containerPtr->tkwin = NULL;
	if (containerPtr->abortPtr != NULL) {
	    *containerPtr->abortPtr = 1;
	masterPtr->tkwin = NULL;
	if (masterPtr->abortPtr != NULL) {
	    *masterPtr->abortPtr = 1;
	}
	Tcl_EventuallyFree(containerPtr, TCL_DYNAMIC);
	Tcl_EventuallyFree(masterPtr, TCL_DYNAMIC);
	return;
    case MapNotify:
	/*
	 * When a container gets mapped, must redo the geometry computation so
	 * that all of its content get remapped.
	 * When a master gets mapped, must redo the geometry computation so
	 * that all of its slaves get remapped.
	 */

	if ((containerPtr->contentPtr != NULL)
		&& !(containerPtr->flags & PARENT_RECONFIG_PENDING)) {
	    containerPtr->flags |= PARENT_RECONFIG_PENDING;
	    Tcl_DoWhenIdle(RecomputePlacement, containerPtr);
	if ((masterPtr->slavePtr != NULL)
		&& !(masterPtr->flags & PARENT_RECONFIG_PENDING)) {
	    masterPtr->flags |= PARENT_RECONFIG_PENDING;
	    Tcl_DoWhenIdle(RecomputePlacement, masterPtr);
	}
	return;
    case UnmapNotify:
	/*
	 * Unmap all of the content when the container gets unmapped, so that they
	 * Unmap all of the slaves when the master gets unmapped, so that they
	 * don't keep redisplaying themselves.
	 */

	for (contentPtr = containerPtr->contentPtr; contentPtr != NULL;
		contentPtr = contentPtr->nextPtr) {
	    Tk_UnmapWindow(contentPtr->tkwin);
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    Tk_UnmapWindow(slavePtr->tkwin);
	}
	return;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ContentStructureProc --
 * SlaveStructureProc --
 *
 *	This function is invoked by the Tk event handler when StructureNotify
 *	events occur for a content window.
 *	events occur for a slave window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Structures get cleaned up if the window was deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ContentStructureProc(
    void *clientData,	/* Pointer to Content structure for window
SlaveStructureProc(
    ClientData clientData,	/* Pointer to Slave structure for window
				 * referred to by eventPtr. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    Content *contentPtr = (Content *)clientData;
    TkDisplay *dispPtr = ((TkWindow *) contentPtr->tkwin)->dispPtr;
    register Slave *slavePtr = clientData;
    TkDisplay *dispPtr = ((TkWindow *) slavePtr->tkwin)->dispPtr;

    if (eventPtr->type == DestroyNotify) {
	if (contentPtr->containerPtr != NULL) {
	    UnlinkContent(contentPtr);
	if (slavePtr->masterPtr != NULL) {
	    UnlinkSlave(slavePtr);
	}
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->contentTable,
		contentPtr->tkwin));
	FreeContent(contentPtr);
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable,
		(char *) slavePtr->tkwin));
	FreeSlave(slavePtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PlaceRequestProc --
 *
 *	This function is invoked by Tk whenever a content managed by us changes
 *	This function is invoked by Tk whenever a slave managed by us changes
 *	its requested geometry.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window will get relayed out, if its requested size has anything to
 *	do with its actual size.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
PlaceRequestProc(
    void *clientData,	/* Pointer to our record for content. */
    TCL_UNUSED(Tk_Window))		/* Window that changed its desired size. */
    ClientData clientData,	/* Pointer to our record for slave. */
    Tk_Window tkwin)		/* Window that changed its desired size. */
{
    Content *contentPtr = (Content *)clientData;
    Container *containerPtr;
    Slave *slavePtr = clientData;
    Master *masterPtr;

    if ((contentPtr->widthPtr || contentPtr->relWidthPtr)
	    && (contentPtr->heightPtr || contentPtr->relHeightPtr)) {
    if ((slavePtr->flags & (CHILD_WIDTH|CHILD_REL_WIDTH))
        /*
         * Send a ConfigureNotify to indicate that the size change
         * request was rejected.
         */

	    && (slavePtr->flags & (CHILD_HEIGHT|CHILD_REL_HEIGHT))) {
        TkDoConfigureNotify((TkWindow *)(contentPtr->tkwin));
	return;
    }
    containerPtr = contentPtr->containerPtr;
    if (containerPtr == NULL) {
    masterPtr = slavePtr->masterPtr;
    if (masterPtr == NULL) {
	return;
    }
    if (!(containerPtr->flags & PARENT_RECONFIG_PENDING)) {
	containerPtr->flags |= PARENT_RECONFIG_PENDING;
	Tcl_DoWhenIdle(RecomputePlacement, containerPtr);
    if (!(masterPtr->flags & PARENT_RECONFIG_PENDING)) {
	masterPtr->flags |= PARENT_RECONFIG_PENDING;
	Tcl_DoWhenIdle(RecomputePlacement, masterPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * PlaceLostContentProc --
 * PlaceLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a content window that used to be managed by us.
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all placer-related information about the content window.
 *	Forgets all placer-related information about the slave.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
PlaceLostContentProc(
    void *clientData,	/* Content structure for content window that was
PlaceLostSlaveProc(
    ClientData clientData,	/* Slave structure for slave window that was
				 * stolen away. */
    Tk_Window tkwin)		/* Tk's handle for the content window. */
    Tk_Window tkwin)		/* Tk's handle for the slave window. */
{
    Content *contentPtr = (Content *)clientData;
    TkDisplay *dispPtr = ((TkWindow *) contentPtr->tkwin)->dispPtr;
    register Slave *slavePtr = clientData;
    TkDisplay *dispPtr = ((TkWindow *) slavePtr->tkwin)->dispPtr;

    if (contentPtr->containerPtr->tkwin != Tk_Parent(contentPtr->tkwin)) {
	Tk_UnmaintainGeometry(contentPtr->tkwin, contentPtr->containerPtr->tkwin);
    if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
	Tk_UnmaintainGeometry(slavePtr->tkwin, slavePtr->masterPtr->tkwin);
    }
    Tk_UnmapWindow(tkwin);
    UnlinkContent(contentPtr);
    Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->contentTable,
	    tkwin));
    Tk_DeleteEventHandler(tkwin, StructureNotifyMask, ContentStructureProc,
	    contentPtr);
    FreeContent(contentPtr);
    UnlinkSlave(slavePtr);
    Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable,
	    (char *) tkwin));
    Tk_DeleteEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc,
	    slavePtr);
    FreeSlave(slavePtr);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkPlatDecls.h.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkPlatDecls.h --
 *
 *	Declarations of functions in the platform-specific public Tcl API.
 *
 * Copyright (c) 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKPLATDECLS
#define _TKPLATDECLS
42
43
44
45
46
47
48






49
50
51
52
53
54













55
56
57



58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88


89
90

91
92
93



94
95
96

97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56




57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75
76

77
78
79
80
81
82
83
84











85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100



101
102
103

104

105
106

107
108
109
110






111
112
113
114
115
116
117







+
+
+
+
+
+


-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
+
+


-
+
+






-
-
-
-
-
-
-
-
-
-
-











+
+


+
-
-
-
+
+
+
-

-
+

-
+



-
-
-
-
-
-







EXTERN Window		Tk_AttachHWND(Tk_Window tkwin, HWND hwnd);
/* 1 */
EXTERN HINSTANCE	Tk_GetHINSTANCE(void);
/* 2 */
EXTERN HWND		Tk_GetHWND(Window window);
/* 3 */
EXTERN Tk_Window	Tk_HWNDToWindow(HWND hwnd);
/* 4 */
EXTERN void		Tk_PointerEvent(HWND hwnd, int x, int y);
/* 5 */
EXTERN int		Tk_TranslateWinEvent(HWND hwnd, UINT message,
				WPARAM wParam, LPARAM lParam,
				LRESULT *result);
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
/* Slot 0 is reserved */
/* Slot 1 is reserved */
/* Slot 2 is reserved */
/* Slot 3 is reserved */
/* 0 */
EXTERN void		Tk_MacOSXSetEmbedHandler(
				Tk_MacOSXEmbedRegisterWinProc *registerWinProcPtr,
				Tk_MacOSXEmbedGetGrafPortProc *getPortProcPtr,
				Tk_MacOSXEmbedMakeContainerExistProc *containerExistProcPtr,
				Tk_MacOSXEmbedGetClipProc *getClipProc,
				Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc);
/* 1 */
EXTERN void		Tk_MacOSXTurnOffMenus(void);
/* 2 */
EXTERN void		Tk_MacOSXTkOwnsCursor(int tkOwnsIt);
/* 3 */
EXTERN void		TkMacOSXInitMenus(Tcl_Interp *interp);
/* 4 */
EXTERN void		TkMacOSXInitAppleEvents(Tcl_Interp *interp);
/* Slot 5 is reserved */
/* 5 */
EXTERN void		TkGenWMConfigureEvent(Tk_Window tkwin, int x, int y,
				int width, int height, int flags);
/* 6 */
EXTERN void		TkMacOSXInvalClipRgns(Tk_Window tkwin);
/* Slot 7 is reserved */
/* 7 */
EXTERN void *		TkMacOSXGetDrawablePort(Drawable drawable);
/* 8 */
EXTERN void *		TkMacOSXGetRootControl(Drawable drawable);
/* 9 */
EXTERN void		Tk_MacOSXSetupTkNotifier(void);
/* 10 */
EXTERN int		Tk_MacOSXIsAppInFront(void);
/* 11 */
EXTERN Tk_Window	Tk_MacOSXGetTkWindow(void *w);
/* 12 */
EXTERN void *		Tk_MacOSXGetCGContextForDrawable(Drawable drawable);
/* 13 */
EXTERN void *		Tk_MacOSXGetNSWindowForDrawable(Drawable drawable);
/* Slot 14 is reserved */
/* Slot 15 is reserved */
/* 16 */
EXTERN void		TkGenWMConfigureEvent(Tk_Window tkwin, int x, int y,
				int width, int height, int flags);
#endif /* AQUA */

typedef struct TkPlatStubs {
    int magic;
    void *hooks;

#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
    Window (*tk_AttachHWND) (Tk_Window tkwin, HWND hwnd); /* 0 */
    HINSTANCE (*tk_GetHINSTANCE) (void); /* 1 */
    HWND (*tk_GetHWND) (Window window); /* 2 */
    Tk_Window (*tk_HWNDToWindow) (HWND hwnd); /* 3 */
    void (*tk_PointerEvent) (HWND hwnd, int x, int y); /* 4 */
    int (*tk_TranslateWinEvent) (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result); /* 5 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    void (*tk_MacOSXSetEmbedHandler) (Tk_MacOSXEmbedRegisterWinProc *registerWinProcPtr, Tk_MacOSXEmbedGetGrafPortProc *getPortProcPtr, Tk_MacOSXEmbedMakeContainerExistProc *containerExistProcPtr, Tk_MacOSXEmbedGetClipProc *getClipProc, Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc); /* 0 */
    void (*reserved0)(void);
    void (*reserved1)(void);
    void (*reserved2)(void);
    void (*tk_MacOSXTurnOffMenus) (void); /* 1 */
    void (*tk_MacOSXTkOwnsCursor) (int tkOwnsIt); /* 2 */
    void (*tkMacOSXInitMenus) (Tcl_Interp *interp); /* 3 */
    void (*reserved3)(void);
    void (*tkMacOSXInitAppleEvents) (Tcl_Interp *interp); /* 4 */
    void (*reserved5)(void);
    void (*tkGenWMConfigureEvent) (Tk_Window tkwin, int x, int y, int width, int height, int flags); /* 5 */
    void (*tkMacOSXInvalClipRgns) (Tk_Window tkwin); /* 6 */
    void (*reserved7)(void);
    void * (*tkMacOSXGetDrawablePort) (Drawable drawable); /* 7 */
    void * (*tkMacOSXGetRootControl) (Drawable drawable); /* 8 */
    void (*tk_MacOSXSetupTkNotifier) (void); /* 9 */
    int (*tk_MacOSXIsAppInFront) (void); /* 10 */
    Tk_Window (*tk_MacOSXGetTkWindow) (void *w); /* 11 */
    void * (*tk_MacOSXGetCGContextForDrawable) (Drawable drawable); /* 12 */
    void * (*tk_MacOSXGetNSWindowForDrawable) (Drawable drawable); /* 13 */
    void (*reserved14)(void);
    void (*reserved15)(void);
    void (*tkGenWMConfigureEvent) (Tk_Window tkwin, int x, int y, int width, int height, int flags); /* 16 */
#endif /* AQUA */
} TkPlatStubs;

extern const TkPlatStubs *tkPlatStubsPtr;

#ifdef __cplusplus
}
125
126
127
128
129
130
131




132
133
134
135
136
137








138
139
140


141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
128
129
130
131
132
133
134
135
136
137
138
139
140




141
142
143
144
145
146
147
148
149
150

151
152
153
154

155
156
157
158
159
160
161
162










163
164
165
166
167
168
169
170
171
172
173
174
175


176







+
+
+
+


-
-
-
-
+
+
+
+
+
+
+
+


-
+
+


-
+
+






-
-
-
-
-
-
-
-
-
-













-
-

	(tkPlatStubsPtr->tk_AttachHWND) /* 0 */
#define Tk_GetHINSTANCE \
	(tkPlatStubsPtr->tk_GetHINSTANCE) /* 1 */
#define Tk_GetHWND \
	(tkPlatStubsPtr->tk_GetHWND) /* 2 */
#define Tk_HWNDToWindow \
	(tkPlatStubsPtr->tk_HWNDToWindow) /* 3 */
#define Tk_PointerEvent \
	(tkPlatStubsPtr->tk_PointerEvent) /* 4 */
#define Tk_TranslateWinEvent \
	(tkPlatStubsPtr->tk_TranslateWinEvent) /* 5 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
/* Slot 0 is reserved */
/* Slot 1 is reserved */
/* Slot 2 is reserved */
/* Slot 3 is reserved */
#define Tk_MacOSXSetEmbedHandler \
	(tkPlatStubsPtr->tk_MacOSXSetEmbedHandler) /* 0 */
#define Tk_MacOSXTurnOffMenus \
	(tkPlatStubsPtr->tk_MacOSXTurnOffMenus) /* 1 */
#define Tk_MacOSXTkOwnsCursor \
	(tkPlatStubsPtr->tk_MacOSXTkOwnsCursor) /* 2 */
#define TkMacOSXInitMenus \
	(tkPlatStubsPtr->tkMacOSXInitMenus) /* 3 */
#define TkMacOSXInitAppleEvents \
	(tkPlatStubsPtr->tkMacOSXInitAppleEvents) /* 4 */
/* Slot 5 is reserved */
#define TkGenWMConfigureEvent \
	(tkPlatStubsPtr->tkGenWMConfigureEvent) /* 5 */
#define TkMacOSXInvalClipRgns \
	(tkPlatStubsPtr->tkMacOSXInvalClipRgns) /* 6 */
/* Slot 7 is reserved */
#define TkMacOSXGetDrawablePort \
	(tkPlatStubsPtr->tkMacOSXGetDrawablePort) /* 7 */
#define TkMacOSXGetRootControl \
	(tkPlatStubsPtr->tkMacOSXGetRootControl) /* 8 */
#define Tk_MacOSXSetupTkNotifier \
	(tkPlatStubsPtr->tk_MacOSXSetupTkNotifier) /* 9 */
#define Tk_MacOSXIsAppInFront \
	(tkPlatStubsPtr->tk_MacOSXIsAppInFront) /* 10 */
#define Tk_MacOSXGetTkWindow \
	(tkPlatStubsPtr->tk_MacOSXGetTkWindow) /* 11 */
#define Tk_MacOSXGetCGContextForDrawable \
	(tkPlatStubsPtr->tk_MacOSXGetCGContextForDrawable) /* 12 */
#define Tk_MacOSXGetNSWindowForDrawable \
	(tkPlatStubsPtr->tk_MacOSXGetNSWindowForDrawable) /* 13 */
/* Slot 14 is reserved */
/* Slot 15 is reserved */
#define TkGenWMConfigureEvent \
	(tkPlatStubsPtr->tkGenWMConfigureEvent) /* 16 */
#endif /* AQUA */

#endif /* defined(USE_TK_STUBS) */

/* !END!: Do not edit above this line. */

#ifdef __cplusplus
}
#endif

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT

#define Tk_MacOSXGetNSViewForDrawable TkMacOSXGetRootControl

#endif /* _TKPLATDECLS */

Changes to generic/tkPointer.c.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22

23
24












25

26
27
28

29
30
31
32
33
34
35
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40

41
42
43
44
45
46
47
48








-
+













+


+
+
+
+
+
+
+
+
+
+
+
+
-
+


-
+







/*
 * tkPointer.c --
 *
 *	This file contains functions for emulating the X server pointer and
 *	grab state machine. This file is used by the Mac and Windows platforms
 *	to generate appropriate enter/leave events, and to update the global
 *	grab window information.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

#if defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#define Cursor XCursor
#endif

/*
 * Mask that selects any of the state bits corresponding to buttons, plus
 * masks that select individual buttons' bits:
 */

#define ALL_BUTTONS \
	(Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask)
static const unsigned int buttonMasks[] = {
    Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask
};
#define ButtonMask(b) (buttonMasks[(b)-Button1])

typedef struct {
typedef struct ThreadSpecificData {
    TkWindow *grabWinPtr;	/* Window that defines the top of the grab
				 * tree in a global grab. */
    unsigned lastState;		/* Last known state flags. */
    int lastState;		/* Last known state flags. */
    XPoint lastPos;		/* Last reported mouse position. */
    TkWindow *lastWinPtr;	/* Last reported mouse window. */
    TkWindow *restrictWinPtr;	/* Window to which all mouse events will be
				 * reported. */
    TkWindow *cursorWinPtr;	/* Window that is currently controlling the
				 * global cursor. */
} ThreadSpecificData;
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148







-
+







static int
GenerateEnterLeave(
    TkWindow *winPtr,		/* Current Tk window (or NULL). */
    int x, int y,		/* Current mouse position in root coords. */
    int state)			/* State flags. */
{
    int crossed = 0;		/* 1 if mouse crossed a window boundary */
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    TkWindow *restrictWinPtr = tsdPtr->restrictWinPtr;
    TkWindow *lastWinPtr = tsdPtr->lastWinPtr;

    if (winPtr != tsdPtr->lastWinPtr) {
	if (restrictWinPtr) {
	    int newPos, oldPos;
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228


229
230
231
232
233
234
235
236
227
228
229
230
231
232
233

234
235
236
237
238
239


240
241

242
243
244
245
246
247
248







-
+





-
-
+
+
-







void
Tk_UpdatePointer(
    Tk_Window tkwin,		/* Window to which pointer event is reported.
				 * May be NULL. */
    int x, int y,		/* Pointer location in root coords. */
    int state)			/* Modifier state mask. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *targetWinPtr;
    XPoint pos;
    XEvent event;
    unsigned changes = (state ^ tsdPtr->lastState) & ALL_BUTTONS;
    int type, b;
    int changes = (state ^ tsdPtr->lastState) & ALL_BUTTONS;
    int type, b, mask;
    unsigned mask;

    pos.x = x;
    pos.y = y;

    /*
     * Use the current keyboard state, but the old mouse button state since we
     * haven't generated the button events yet.
250
251
252
253
254
255
256
257
258


259
260
261
262
263
264
265
262
263
264
265
266
267
268


269
270
271
272
273
274
275
276
277







-
-
+
+







    }

    /*
     * Generate ButtonPress/ButtonRelease events based on the differences
     * between the current button state and the last known button state.
     */

    for (b = Button1; b <= Button9; b++) {
	mask = Tk_GetButtonMask(b);
    for (b = Button1; b <= Button5; b++) {
	mask = ButtonMask(b);
	if (changes & mask) {
	    if (state & mask) {
		type = ButtonPress;

		/*
		 * ButtonPress - Set restrict window if we aren't grabbed, or
		 * if this is the first button down.
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
432
433
434
435
436
437
438

439
440







441

442
443
444
445
446
447
448
449







-
+

-
-
-
-
-
-
-

-
+







    unsigned int event_mask,
    int pointer_mode,
    int keyboard_mode,
    Window confine_to,
    Cursor cursor,
    Time time)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    (void)owner_events;
    (void)event_mask;
    (void)pointer_mode;
    (void)keyboard_mode;
    (void)confine_to;
    (void)cursor;
    (void)time;

    LastKnownRequestProcessed(display)++;
    display->request++;
    tsdPtr->grabWinPtr = (TkWindow *) Tk_IdToWindow(display, grab_window);
    tsdPtr->restrictWinPtr = NULL;
    TkpSetCapture(tsdPtr->grabWinPtr);
    if (TkPositionInTree(tsdPtr->lastWinPtr, tsdPtr->grabWinPtr)
	    != TK_GRAB_IN_TREE) {
	UpdateCursor(tsdPtr->grabWinPtr);
    }
462
463
464
465
466
467
468
469

470
471
472
473

474
475
476
477
478
479
480
467
468
469
470
471
472
473

474
475

476

477
478
479
480
481
482
483
484







-
+

-

-
+







 */

int
XUngrabPointer(
    Display *display,
    Time time)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    (void)time;

    LastKnownRequestProcessed(display)++;
    display->request++;
    tsdPtr->grabWinPtr = NULL;
    tsdPtr->restrictWinPtr = NULL;
    TkpSetCapture(NULL);
    UpdateCursor(tsdPtr->lastWinPtr);
    return Success;
}

494
495
496
497
498
499
500
501

502
503
504
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
529
498
499
500
501
502
503
504

505
506
507
508

509
510
511
512
513
514
515
516
517








518

519
520
521
522
523
524
525







-
+



-
+








-
-
-
-
-
-
-
-
+
-







 *----------------------------------------------------------------------
 */

void
TkPointerDeadWindow(
    TkWindow *winPtr)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr == tsdPtr->lastWinPtr) {
	tsdPtr->lastWinPtr = TkGetContainer(winPtr);
	tsdPtr->lastWinPtr = NULL;
    }
    if (winPtr == tsdPtr->grabWinPtr) {
	tsdPtr->grabWinPtr = NULL;
    }
    if (winPtr == tsdPtr->restrictWinPtr) {
	tsdPtr->restrictWinPtr = NULL;
    }
    if (!(tsdPtr->restrictWinPtr || tsdPtr->grabWinPtr)) {

        /*
         * Release mouse capture only if the dead window is the capturing
         * window.
         */

        if (winPtr == (TkWindow *)TkpGetCapture()) {
	    TkpSetCapture(NULL);
	TkpSetCapture(NULL);
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateCursor --
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
537
538
539
540
541
542
543

544
545
546
547
548
549
550
551







-
+







 */

static void
UpdateCursor(
    TkWindow *winPtr)
{
    Cursor cursor = None;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * A window inherits its cursor from its parent if it doesn't have one of
     * its own. Top level windows inherit the default cursor.
     */

587
588
589
590
591
592
593
594

595
596
597
598
599
600
601

602
603









































604
605
606
607
608
609
610
611
583
584
585
586
587
588
589

590
591

592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647







-
+

-




-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








int
XDefineCursor(
    Display *display,
    Window w,
    Cursor cursor)
{
    TkWindow *winPtr = (TkWindow *) Tk_IdToWindow(display, w);
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    (void)cursor;

    if (tsdPtr->cursorWinPtr == winPtr) {
	UpdateCursor(winPtr);
    }
    LastKnownRequestProcessed(display)++;
    display->request++;
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenerateActivateEvents --
 *
 *	This function is called by the Mac and Windows window manager routines
 *	when a toplevel window is activated or deactivated.
 *	Activate/Deactivate events will be sent to every subwindow of the
 *	toplevel followed by a FocusIn/FocusOut message.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Generates X events.
 *
 *----------------------------------------------------------------------
 */

void
TkGenerateActivateEvents(
    TkWindow *winPtr,		/* Toplevel to activate. */
    int active)			/* Non-zero if the window is being activated,
				 * else 0.*/
{
    XEvent event;

    /*
     * Generate Activate and Deactivate events. This event is sent to every
     * subwindow in a toplevel window.
     */

    event.xany.serial = winPtr->display->request++;
    event.xany.send_event = False;
    event.xany.display = winPtr->display;
    event.xany.window = winPtr->window;

    event.xany.type = active ? ActivateNotify : DeactivateNotify;
    TkQueueEventForAllChildren(winPtr, &event);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkRectOval.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5


6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21





-
-
+
+







-







/*
 * tkRectOval.c --
 *
 *	This file implements rectangle and oval items for canvas widgets.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1991-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
#include "default.h"

/*
 * The structure below defines the record for each rectangle/oval item.
 */

typedef struct RectOvalItem  {
    Tk_Item header;		/* Generic stuff that's the same for all
57
58
59
60
61
62
63
64

65
66
67

68
69

70
71

72
73
74

75
76

77
78
79

80
81
82

83
84
85

86
87
88

89
90

91
92
93

94
95
96
97
98



99
100
101

102
103

104
105
106

107
108

109
110
111

112
113

114
115

116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131

132
133
134

135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
56
57
58
59
60
61
62

63
64
65

66
67

68
69

70
71
72

73
74

75
76
77

78
79
80

81
82
83

84
85
86

87
88

89
90
91

92
93
94



95
96
97
98
99

100
101

102
103
104

105
106

107
108
109

110
111

112
113

114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129

130
131
132

133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182


183
184
185
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206


207
208
209
210
211
212
213
214







-
+


-
+

-
+

-
+


-
+

-
+


-
+


-
+


-
+


-
+

-
+


-
+


-
-
-
+
+
+


-
+

-
+


-
+

-
+


-
+

-
+

-
+



-
+











-
+


-
+










-
+






-
-




















-
+











-
-
+











-
+











-
-
+







};
static const Tk_CustomOption pixelOption = {
    TkPixelParseProc, TkPixelPrintProc, NULL
};

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.activeDash),
	NULL, Tk_Offset(RectOvalItem, outline.activeDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-activefill", NULL, NULL,
	NULL, offsetof(RectOvalItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, activeFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.activeStipple),
	NULL, Tk_Offset(RectOvalItem, outline.activeStipple),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL,
	"0.0", offsetof(RectOvalItem, outline.activeWidth),
	"0.0", Tk_Offset(RectOvalItem, outline.activeWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_CUSTOM, "-dash", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.dash),
	NULL, Tk_Offset(RectOvalItem, outline.dash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL,
	"0", offsetof(RectOvalItem, outline.offset),
	"0", Tk_Offset(RectOvalItem, outline.offset),
	TK_CONFIG_DONT_SET_DEFAULT, NULL},
    {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.disabledDash),
	NULL, Tk_Offset(RectOvalItem, outline.disabledDash),
	TK_CONFIG_NULL_OK, &dashOption},
    {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL,
	NULL, offsetof(RectOvalItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.disabledColor),
	NULL, Tk_Offset(RectOvalItem, outline.disabledColor),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.disabledStipple),
	NULL, Tk_Offset(RectOvalItem, outline.disabledStipple),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL,
	"0.0", offsetof(RectOvalItem, outline.disabledWidth),
	NULL, Tk_Offset(RectOvalItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-disabledwidth", NULL, NULL,
	"0.0", Tk_Offset(RectOvalItem, outline.disabledWidth),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_COLOR, "-fill", NULL, NULL,
	NULL, offsetof(RectOvalItem, fillColor), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, fillColor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-offset", NULL, NULL,
	"0,0", offsetof(RectOvalItem, tsoffset),
	"0,0", Tk_Offset(RectOvalItem, tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_COLOR, "-outline", NULL, NULL,
	DEF_CANVITEM_OUTLINE, offsetof(RectOvalItem, outline.color), TK_CONFIG_NULL_OK, NULL},
	"black", Tk_Offset(RectOvalItem, outline.color), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL,
	"0,0", offsetof(RectOvalItem, outline.tsoffset),
	"0,0", Tk_Offset(RectOvalItem, outline.tsoffset),
	TK_CONFIG_DONT_SET_DEFAULT, &offsetOption},
    {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, outline.stipple), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-state", NULL, NULL,
	NULL, offsetof(Tk_Item, state),TK_CONFIG_NULL_OK, &stateOption},
	NULL, Tk_Offset(Tk_Item, state),TK_CONFIG_NULL_OK, &stateOption},
    {TK_CONFIG_BITMAP, "-stipple", NULL, NULL,
	NULL, offsetof(RectOvalItem, fillStipple),TK_CONFIG_NULL_OK, NULL},
	NULL, Tk_Offset(RectOvalItem, fillStipple),TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_CUSTOM, "-tags", NULL, NULL,
	NULL, 0, TK_CONFIG_NULL_OK, &tagsOption},
    {TK_CONFIG_CUSTOM, "-width", NULL, NULL,
	"1.0", offsetof(RectOvalItem, outline.width),
	"1.0", Tk_Offset(RectOvalItem, outline.width),
	TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Prototypes for functions defined in this file:
 */

static void		ComputeRectOvalBbox(Tk_Canvas canvas,
			    RectOvalItem *rectOvalPtr);
static int		ConfigureRectOval(Tcl_Interp *interp, Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[],
			    Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[],
			    int flags);
static int		CreateRectOval(Tcl_Interp *interp, Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[]);
static void		DeleteRectOval(Tk_Canvas canvas, Tk_Item *itemPtr,
			    Display *display);
static void		DisplayRectOval(Tk_Canvas canvas, Tk_Item *itemPtr,
			    Display *display, Drawable dst, int x, int y,
			    int width, int height);
static int		OvalToArea(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double *areaPtr);
static double		OvalToPoint(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double *pointPtr);
static int		RectOvalCoords(Tcl_Interp *interp, Tk_Canvas canvas,
			    Tk_Item *itemPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[]);
static int		RectOvalToPostscript(Tcl_Interp *interp,
			    Tk_Canvas canvas, Tk_Item *itemPtr, int prepass);
static int		RectToArea(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double *areaPtr);
static double		RectToPoint(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double *pointPtr);
static void		RotateRectOval(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY, double angleRad);
static void		ScaleRectOval(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double originX, double originY,
			    double scaleX, double scaleY);
static void		TranslateRectOval(Tk_Canvas canvas, Tk_Item *itemPtr,
			    double deltaX, double deltaY);

/*
 * The structures below defines the rectangle and oval item types by means of
 * functions that can be invoked by generic item code.
 */

Tk_ItemType tkRectangleType = {
    "rectangle",		/* name */
    sizeof(RectOvalItem),	/* itemSize */
    CreateRectOval,		/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureRectOval,		/* configureProc */
    RectOvalCoords,		/* coordProc */
    DeleteRectOval,		/* deleteProc */
    DisplayRectOval,		/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    RectToPoint,		/* pointProc */
    RectToArea,			/* areaProc */
    RectOvalToPostscript,	/* postscriptProc */
    ScaleRectOval,		/* scaleProc */
    TranslateRectOval,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* icursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateRectOval,		/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

Tk_ItemType tkOvalType = {
    "oval",			/* name */
    sizeof(RectOvalItem),	/* itemSize */
    CreateRectOval,		/* createProc */
    configSpecs,		/* configSpecs */
    ConfigureRectOval,		/* configureProc */
    RectOvalCoords,		/* coordProc */
    DeleteRectOval,		/* deleteProc */
    DisplayRectOval,		/* displayProc */
    0,				/* flags */
    TK_CONFIG_OBJS,		/* flags */
    OvalToPoint,		/* pointProc */
    OvalToArea,			/* areaProc */
    RectOvalToPostscript,	/* postscriptProc */
    ScaleRectOval,		/* scaleProc */
    TranslateRectOval,		/* translateProc */
    NULL,			/* indexProc */
    NULL,			/* cursorProc */
    NULL,			/* selectionProc */
    NULL,			/* insertProc */
    NULL,			/* dTextProc */
    NULL,			/* nextPtr */
    RotateRectOval,		/* rotateProc */
    0, NULL, NULL
    NULL, 0, NULL, NULL
};

/*
 *--------------------------------------------------------------
 *
 * CreateRectOval --
 *
234
235
236
237
238
239
240
241

242
243
244
245

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
229
230
231
232
233
234
235

236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268







-
+



-
+




















-
+








static int
CreateRectOval(
    Tcl_Interp *interp,		/* For error reporting. */
    Tk_Canvas canvas,		/* Canvas to hold new item. */
    Tk_Item *itemPtr,		/* Record to hold new item; header has been
				 * initialized by caller. */
    Tcl_Size objc,			/* Number of arguments in objv. */
    int objc,			/* Number of arguments in objv. */
    Tcl_Obj *const objv[])	/* Arguments describing rectangle. */
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
    Tcl_Size i;
    int i;

    if (objc == 0) {
	Tcl_Panic("canvas did not pass any coords");
    }

    /*
     * Carry out initialization that is needed in order to clean up after
     * errors during the the remainder of this function.
     */

    Tk_CreateOutline(&(rectOvalPtr->outline));
    rectOvalPtr->tsoffset.flags = 0;
    rectOvalPtr->tsoffset.xoffset = 0;
    rectOvalPtr->tsoffset.yoffset = 0;
    rectOvalPtr->fillColor = NULL;
    rectOvalPtr->activeFillColor = NULL;
    rectOvalPtr->disabledFillColor = NULL;
    rectOvalPtr->fillStipple = None;
    rectOvalPtr->activeFillStipple = None;
    rectOvalPtr->disabledFillStipple = None;
    rectOvalPtr->fillGC = NULL;
    rectOvalPtr->fillGC = None;

    /*
     * Process the arguments to fill in the item record.
     */

    for (i = 1; i < objc; i++) {
	const char *arg = Tcl_GetString(objv[i]);
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318







-
+








static int
RectOvalCoords(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item whose coordinates are to be read or
				 * modified. */
    Tcl_Size objc,			/* Number of coordinates supplied in objv. */
    int objc,			/* Number of coordinates supplied in objv. */
    Tcl_Obj *const objv[])	/* Array of coordinates: x1,y1,x2,y2,... */
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;

    /*
     * If no coordinates, return the current coordinates (i.e. bounding box).
     */
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355







-
+








    /*
     * Better have four coordinates now. Spit out an error message otherwise.
     */

    if (objc != 4) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"wrong # coordinates: expected 0 or 4, got %" TCL_SIZE_MODIFIER "d", objc));
		"wrong # coordinates: expected 0 or 4, got %d", objc));
	Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS",
		(rectOvalPtr->header.typePtr == &tkRectangleType
			? "RECTANGLE" : "OVAL"), NULL);
	return TCL_ERROR;
    }

    /*
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421







-
+
















-
+







 */

static int
ConfigureRectOval(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Canvas canvas,		/* Canvas containing itemPtr. */
    Tk_Item *itemPtr,		/* Rectangle item to reconfigure. */
    Tcl_Size objc,			/* Number of elements in objv. */
    int objc,			/* Number of elements in objv. */
    Tcl_Obj *const objv[],	/* Arguments describing things to configure. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
    XGCValues gcValues;
    GC newGC;
    unsigned long mask;
    Tk_Window tkwin;
    Tk_TSOffset *tsoffset;
    XColor *color;
    Pixmap stipple;
    Tk_State state;

    tkwin = Tk_CanvasTkwin(canvas);

    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc,
	    objv, rectOvalPtr, flags)) {
	    (const char **)objv, (char *) rectOvalPtr, flags|TK_CONFIG_OBJS)) {
	return TCL_ERROR;
    }
    state = itemPtr->state;

    /*
     * A few of the options require additional processing, such as graphics
     * contexts.
467
468
469
470
471
472
473
474

475
476

477
478
479
480
481
482
483
462
463
464
465
466
467
468

469
470

471
472
473
474
475
476
477
478







-
+

-
+







    if (mask && \
	    rectOvalPtr->outline.width != 0 && \
	    rectOvalPtr->outline.color != NULL) {
	gcValues.cap_style = CapProjecting;
	mask |= GCCapStyle;
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    } else {
	newGC = NULL;
	newGC = None;
    }
    if (rectOvalPtr->outline.gc != NULL) {
    if (rectOvalPtr->outline.gc != None) {
	Tk_FreeGC(Tk_Display(tkwin), rectOvalPtr->outline.gc);
    }
    rectOvalPtr->outline.gc = newGC;

    if (state == TK_STATE_NULL) {
	state = Canvas(canvas)->canvas_state;
    }
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522

523

524
525
526
527
528
529

530
531
532
533
534
535
536
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

519
520
521
522
523
524

525
526
527
528
529
530
531
532







-
+














+
-
+





-
+







	}
	if (rectOvalPtr->disabledFillStipple!=None) {
	    stipple = rectOvalPtr->disabledFillStipple;
	}
    }

    if (color == NULL) {
	newGC = NULL;
	newGC = None;
    } else {
	gcValues.foreground = color->pixel;
	if (stipple != None) {
	    gcValues.stipple = stipple;
	    gcValues.fill_style = FillStippled;
	    mask = GCForeground|GCStipple|GCFillStyle;
	} else {
	    mask = GCForeground;
	}
#ifdef MAC_OSX_TK
	/*
	 * Mac OS X CG drawing needs access to the outline linewidth even for
	 * fills (as linewidth controls antialiasing).
	 */

	gcValues.line_width = rectOvalPtr->outline.gc != NULL ?
	gcValues.line_width = rectOvalPtr->outline.gc != None ?
		rectOvalPtr->outline.gc->line_width : 0;
	mask |= GCLineWidth;
#endif
	newGC = Tk_GetGC(tkwin, mask, &gcValues);
    }
    if (rectOvalPtr->fillGC != NULL) {
    if (rectOvalPtr->fillGC != None) {
	Tk_FreeGC(Tk_Display(tkwin), rectOvalPtr->fillGC);
    }
    rectOvalPtr->fillGC = newGC;

    tsoffset = &rectOvalPtr->tsoffset;
    flags = tsoffset->flags;
    if (flags & TK_OFFSET_LEFT) {
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580







-
+







 *	Resources associated with itemPtr are released.
 *
 *--------------------------------------------------------------
 */

static void
DeleteRectOval(
    TCL_UNUSED(Tk_Canvas),		/* Info about overall widget. */
    Tk_Canvas canvas,		/* Info about overall widget. */
    Tk_Item *itemPtr,		/* Item that is being deleted. */
    Display *display)		/* Display containing window for canvas. */
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;

    Tk_DeleteOutline(display, &(rectOvalPtr->outline));
    if (rectOvalPtr->fillColor != NULL) {
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605







-
+







    }
    if (rectOvalPtr->activeFillStipple != None) {
	Tk_FreeBitmap(display, rectOvalPtr->activeFillStipple);
    }
    if (rectOvalPtr->disabledFillStipple != None) {
	Tk_FreeBitmap(display, rectOvalPtr->disabledFillStipple);
    }
    if (rectOvalPtr->fillGC != NULL) {
    if (rectOvalPtr->fillGC != None) {
	Tk_FreeGC(display, rectOvalPtr->fillGC);
    }
}

/*
 *--------------------------------------------------------------
 *
617
618
619
620
621
622
623

624
625
626
627
628
629
630
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627







+







 *
 * Side effects:
 *	The fields x1, y1, x2, and y2 are updated in the header for itemPtr.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
ComputeRectOvalBbox(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    RectOvalItem *rectOvalPtr)	/* Item whose bbox is to be recomputed. */
{
    int bloat, tmp;
    double dtmp, width;
663
664
665
666
667
668
669
670

671
672
673
674
675
676
677
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674







-
+







    if (rectOvalPtr->bbox[0] > rectOvalPtr->bbox[2]) {
	double tmpX = rectOvalPtr->bbox[2];

	rectOvalPtr->bbox[2] = rectOvalPtr->bbox[0];
	rectOvalPtr->bbox[0] = tmpX;
    }

    if (rectOvalPtr->outline.gc == NULL) {
    if (rectOvalPtr->outline.gc == None) {
	/*
	 * The Win32 switch was added for 8.3 to solve a problem with ovals
	 * leaving traces on bottom and right of 1 pixel. This may not be the
	 * correct place to solve it, but it works.
	 */

#ifdef _WIN32
739
740
741
742
743
744
745

746
747


748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767


768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816


817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
736
737
738
739
740
741
742
743


744
745


746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761


762
763







764










































765
766














































767
768
769
770
771
772
773







+
-
-
+
+
-
-
















-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








static void
DisplayRectOval(
    Tk_Canvas canvas,		/* Canvas that contains item. */
    Tk_Item *itemPtr,		/* Item to be displayed. */
    Display *display,		/* Display on which to draw item. */
    Drawable drawable,		/* Pixmap or window in which to draw item. */
    int x, int y, int width, int height)
    TCL_UNUSED(int),/* Describes region of canvas that must be */
    TCL_UNUSED(int),/* redisplayed (not used). */
				/* Describes region of canvas that must be
				 * redisplayed (not used). */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
    short x1, y1, x2, y2;
    Pixmap fillStipple;
    Tk_State state = itemPtr->state;

    /*
     * Compute the screen coordinates of the bounding box for the item. Make
     * sure that the bbox is at least one pixel large, since some X servers
     * will die if it isn't.
     */

    Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1],
	    &x1, &y1);
    Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3],
	    &x2, &y2);
    if (x2 == x1) {

    if (x2 <= x1) {
	x2 = x1+1;
        /*
         * The width of the bounding box corresponds to less than one pixel
         * on screen. Adjustment is needed to avoid drawing attempts with zero
         * width items (which would draw nothing). The bounding box spans
         * either 1 or 2 pixels. Select which pixel will be drawn.
         */

    }
        short ix1 = (short) (rectOvalPtr->bbox[0]);
        short ix2 = (short) (rectOvalPtr->bbox[2]);

        if (ix1 == ix2) {

            /*
             * x1 and x2 are "within the same pixel". Use this pixel.
             * Note: the degenerated case (bbox[0]==bbox[2]) of a completely
             * flat box results in arbitrary selection of the pixel at the
             * right (with positive coordinate) or left (with negative
             * coordinate) of the box. There is no "best choice" here.
             */

            if (ix1 > 0) {
                x2 += 1;
            } else {
                x1 -= 1;
            }
        } else {

            /*
             * (x1,x2) span two pixels. Select the one with the larger
             * covered "area".
             */

            if (ix1 > 0) {
                if ((rectOvalPtr->bbox[2] - ix2) > (ix2 - rectOvalPtr->bbox[0])) {
                    x2 += 1;
                } else {
                    x1 -= 1;
                }
            } else {
                if ((rectOvalPtr->bbox[2] - ix1) > (ix1 - rectOvalPtr->bbox[0])) {
                    x2 += 1;
                } else {
                    x1 -= 1;
                }
            }
        }
    }
    if (y2 == y1) {

    if (y2 <= y1) {
	y2 = y1+1;
        /*
         * The height of the bounding box corresponds to less than one pixel
         * on screen. Adjustment is needed to avoid drawing attempts with zero
         * height items (which would draw nothing). The bounding box spans
         * either 1 or 2 pixels. Select which pixel will be drawn.
         */

        short iy1 = (short) (rectOvalPtr->bbox[1]);
        short iy2 = (short) (rectOvalPtr->bbox[3]);

        if (iy1 == iy2) {

            /*
             * y1 and y2 are "within the same pixel". Use this pixel.
             * Note: the degenerated case (bbox[1]==bbox[3]) of a completely
             * flat box results in arbitrary selection of the pixel below
             * (with positive coordinate) or above (with negative coordinate)
             * the box. There is no "best choice" here.
             */

            if (iy1 > 0) {
                y2 += 1;
            } else {
                y1 -= 1;
            }
        } else {

            /*
             * (y1,y2) span two pixels. Select the one with the larger
             * covered "area".
             */

            if (iy1 > 0) {
                if ((rectOvalPtr->bbox[3] - iy2) > (iy2 - rectOvalPtr->bbox[1])) {
                    y2 += 1;
                } else {
                    y1 -= 1;
                }
            } else {
                if ((rectOvalPtr->bbox[3] - iy1) > (iy1 - rectOvalPtr->bbox[1])) {
                    y2 += 1;
                } else {
                    y1 -= 1;
                }
            }
        }
    }

    /*
     * Display filled part first (if wanted), then outline. If we're
     * stippling, then modify the stipple offset in the GC. Be sure to reset
     * the offset when done, since the GC is supposed to be read-only.
     */
878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796







-
+







	}
    } else if (state == TK_STATE_DISABLED) {
	if (rectOvalPtr->disabledFillStipple != None) {
	    fillStipple = rectOvalPtr->disabledFillStipple;
	}
    }

    if (rectOvalPtr->fillGC != NULL) {
    if (rectOvalPtr->fillGC != None) {
	if (fillStipple != None) {
	    Tk_TSOffset *tsoffset;
	    int w = 0, h = 0;

	    tsoffset = &rectOvalPtr->tsoffset;
	    if (tsoffset) {
		int flags = tsoffset->flags;
922
923
924
925
926
927
928
929

930
931
932
933
934
935
936
826
827
828
829
830
831
832

833
834
835
836
837
838
839
840







-
+







		    0, 360*64);
	}
	if (fillStipple != None) {
	    XSetTSOrigin(display, rectOvalPtr->fillGC, 0, 0);
	}
    }

    if (rectOvalPtr->outline.gc != NULL) {
    if (rectOvalPtr->outline.gc != None) {
	Tk_ChangeOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline));
	if (rectOvalPtr->header.typePtr == &tkRectangleType) {
	    XDrawRectangle(display, drawable, rectOvalPtr->outline.gc,
		    x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1));
	} else {
	    XDrawArc(display, drawable, rectOvalPtr->outline.gc,
		    x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64);
957
958
959
960
961
962
963

964
965
966
967
968
969
970
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
RectToPoint(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    RectOvalItem *rectPtr = (RectOvalItem *) itemPtr;
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
897
898
899
900
901
902
903

904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
927







-
+















-
+







     * there is one.
     */

    x1 = rectPtr->bbox[0];
    y1 = rectPtr->bbox[1];
    x2 = rectPtr->bbox[2];
    y2 = rectPtr->bbox[3];
    if (rectPtr->outline.gc != NULL) {
    if (rectPtr->outline.gc != None) {
	inc = width/2.0;
	x1 -= inc;
	y1 -= inc;
	x2 += inc;
	y2 += inc;
    }

    /*
     * If the point is inside the rectangle, handle specially: distance is 0
     * if rectangle is filled, otherwise compute distance to nearest edge of
     * rectangle and subtract width of edge.
     */

    if ((pointPtr[0] >= x1) && (pointPtr[0] < x2)
	    && (pointPtr[1] >= y1) && (pointPtr[1] < y2)) {
	if ((rectPtr->fillGC != NULL) || (rectPtr->outline.gc == NULL)) {
	if ((rectPtr->fillGC != None) || (rectPtr->outline.gc == None)) {
	    return 0.0;
	}
	xDiff = pointPtr[0] - x1;
	tmp = x2 - pointPtr[0];
	if (tmp < xDiff) {
	    xDiff = tmp;
	}
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static double
OvalToPoint(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against point. */
    double *pointPtr)		/* Pointer to x and y coordinates. */
{
    RectOvalItem *ovalPtr = (RectOvalItem *) itemPtr;
1103
1104
1105
1106
1107
1108
1109
1110
1111


1112
1113
1114
1115
1116
1117
1118
1009
1010
1011
1012
1013
1014
1015


1016
1017
1018
1019
1020
1021
1022
1023
1024







-
-
+
+







    } else if (state == TK_STATE_DISABLED) {
	if (ovalPtr->outline.disabledWidth>0) {
	    width = (double) ovalPtr->outline.disabledWidth;
	}
    }


    filled = ovalPtr->fillGC != NULL;
    if (ovalPtr->outline.gc == NULL) {
    filled = ovalPtr->fillGC != None;
    if (ovalPtr->outline.gc == None) {
	width = 0.0;
	filled = 1;
    }
    return TkOvalToPoint(ovalPtr->bbox, width, filled, pointPtr);
}

/*
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
RectToArea(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against rectangle. */
    double *areaPtr)		/* Pointer to array of four coordinates (x1,
				 * y1, x2, y2) describing rectangular area. */
{
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089







-
+









-
+







    } else if (state == TK_STATE_DISABLED) {
	if (rectPtr->outline.disabledWidth > 0) {
	    width = rectPtr->outline.disabledWidth;
	}
    }

    halfWidth = width/2.0;
    if (rectPtr->outline.gc == NULL) {
    if (rectPtr->outline.gc == None) {
	halfWidth = 0.0;
    }

    if ((areaPtr[2] <= (rectPtr->bbox[0] - halfWidth))
	    || (areaPtr[0] >= (rectPtr->bbox[2] + halfWidth))
	    || (areaPtr[3] <= (rectPtr->bbox[1] - halfWidth))
	    || (areaPtr[1] >= (rectPtr->bbox[3] + halfWidth))) {
	return -1;
    }
    if ((rectPtr->fillGC == NULL) && (rectPtr->outline.gc != NULL)
    if ((rectPtr->fillGC == None) && (rectPtr->outline.gc != None)
	    && (areaPtr[0] >= (rectPtr->bbox[0] + halfWidth))
	    && (areaPtr[1] >= (rectPtr->bbox[1] + halfWidth))
	    && (areaPtr[2] <= (rectPtr->bbox[2] - halfWidth))
	    && (areaPtr[3] <= (rectPtr->bbox[3] - halfWidth))) {
	return -1;
    }
    if ((areaPtr[0] <= (rectPtr->bbox[0] - halfWidth))
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
OvalToArea(
    Tk_Canvas canvas,		/* Canvas containing item. */
    Tk_Item *itemPtr,		/* Item to check against oval. */
    double *areaPtr)		/* Pointer to array of four coordinates (x1,
				 * y1, x2, y2) describing rectangular area. */
{
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260


1261
1262
1263
1264
1265
1266
1267
1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166


1167
1168
1169
1170
1171
1172
1173
1174
1175







-
+
















-
-
+
+







    }

    /*
     * Expand the oval to include the width of the outline, if any.
     */

    halfWidth = width/2.0;
    if (ovalPtr->outline.gc == NULL) {
    if (ovalPtr->outline.gc == None) {
	halfWidth = 0.0;
    }
    oval[0] = ovalPtr->bbox[0] - halfWidth;
    oval[1] = ovalPtr->bbox[1] - halfWidth;
    oval[2] = ovalPtr->bbox[2] + halfWidth;
    oval[3] = ovalPtr->bbox[3] + halfWidth;

    result = TkOvalToArea(oval, areaPtr);

    /*
     * If the rectangle appears to overlap the oval and the oval isn't filled,
     * do one more check to see if perhaps all four of the rectangle's corners
     * are totally inside the oval's unfilled center, in which case we should
     * return "outside".
     */

    if ((result == 0) && (ovalPtr->outline.gc != NULL)
	    && (ovalPtr->fillGC == NULL)) {
    if ((result == 0) && (ovalPtr->outline.gc != None)
	    && (ovalPtr->fillGC == None)) {
	double centerX, centerY, height;
	double xDelta1, yDelta1, xDelta2, yDelta2;

	centerX = (ovalPtr->bbox[0] + ovalPtr->bbox[2])/2.0;
	centerY = (ovalPtr->bbox[1] + ovalPtr->bbox[3])/2.0;
	width = (ovalPtr->bbox[2] - ovalPtr->bbox[0])/2.0 - halfWidth;
	height = (ovalPtr->bbox[3] - ovalPtr->bbox[1])/2.0 - halfWidth;
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1186
1187
1188
1189
1190
1191
1192



















































1193
1194
1195
1196
1197
1198
1199







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		&& ((xDelta2 + yDelta1) < 1.0)
		&& ((xDelta2 + yDelta2) < 1.0)) {
	    return -1;
	}
    }
    return result;
}

/*
 *--------------------------------------------------------------
 *
 * RotateRectOval --
 *
 *	This function is invoked to rotate a rectangle or oval item's
 *	coordinates. It works by rotating a computed point in the centre of
 *	the bounding box, NOT by rotating the corners of the bounding box.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The position of the rectangle or oval is rotated by angleRad about
 *	(originX, originY), and the bounding box is updated in the generic
 *	part of the item structure.
 *
 *--------------------------------------------------------------
 */

static void
RotateRectOval(
    Tk_Canvas canvas,		/* Canvas containing rectangle. */
    Tk_Item *itemPtr,		/* Rectangle to be scaled. */
    double originX, double originY,
				/* Origin about which to rotate rect. */
    double angleRad)		/* Amount to scale in X direction. */
{
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
    double newX, newY, oldX, oldY;

    /*
     * Compute the centre of the box, then rotate that about the origin.
     */

    newX = oldX = (rectOvalPtr->bbox[0] + rectOvalPtr->bbox[2]) / 2.0;
    newY = oldY = (rectOvalPtr->bbox[1] + rectOvalPtr->bbox[3]) / 2.0;
    TkRotatePoint(originX, originY, sin(angleRad), cos(angleRad),
	    &newX, &newY);

    /*
     * Apply the translation to the box.
     */

    rectOvalPtr->bbox[0] += newX - oldX;
    rectOvalPtr->bbox[1] += newY - oldY;
    rectOvalPtr->bbox[2] += newX - oldX;
    rectOvalPtr->bbox[3] += newY - oldY;
    ComputeRectOvalBbox(canvas, rectOvalPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ScaleRectOval --
 *
 *	This function is invoked to rescale a rectangle or oval item.
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297







-
+







 */

static int
RectOvalToPostscript(
    Tcl_Interp *interp,		/* Interpreter for error reporting. */
    Tk_Canvas canvas,		/* Information about overall canvas. */
    Tk_Item *itemPtr,		/* Item for which Postscript is wanted. */
    TCL_UNUSED(int))		/* 1 means this is a prepass to collect font
    int prepass)		/* 1 means this is a prepass to collect font
				 * information; 0 means final Postscript is
				 * being created. */
{
    Tcl_Obj *pathObj, *psObj;
    RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr;
    double y1, y2;
    XColor *color;
1512
1513
1514
1515
1516
1517
1518
1519



1520
1521
1522
1523

1524
1525
1526



1527
1528
1529

1530
1531
1532

1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545




1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557






1558
1559
1560
1561
1562
1563
1564
1565
1566
1369
1370
1371
1372
1373
1374
1375

1376
1377
1378
1379
1380
1381

1382
1383
1384

1385
1386
1387
1388
1389

1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436







-
+
+
+



-
+


-
+
+
+


-
+


-
+









-
+


-
+
+
+
+












+
+
+
+
+
+









     * First draw the filled area of the rectangle.
     */

    if (fillColor != NULL) {
	Tcl_AppendObjToObj(psObj, pathObj);

	Tcl_ResetResult(interp);
	Tk_CanvasPsColor(interp, canvas, fillColor);
	if (Tk_CanvasPsColor(interp, canvas, fillColor) != TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));

	if (fillStipple != None) {
	    Tcl_AppendToObj(psObj, "clip ", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "clip ", -1);

	    Tcl_ResetResult(interp);
	    Tk_CanvasPsStipple(interp, canvas, fillStipple);
	    if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) {
		goto error;
	    }
	    Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
	    if (color != NULL) {
		Tcl_AppendToObj(psObj, "grestore gsave\n", TCL_INDEX_NONE);
		Tcl_AppendToObj(psObj, "grestore gsave\n", -1);
	    }
	} else {
	    Tcl_AppendToObj(psObj, "fill\n", TCL_INDEX_NONE);
	    Tcl_AppendToObj(psObj, "fill\n", -1);
	}
    }

    /*
     * Now draw the outline, if there is one.
     */

    if (color != NULL) {
	Tcl_AppendObjToObj(psObj, pathObj);
	Tcl_AppendToObj(psObj, "0 setlinejoin 2 setlinecap\n", TCL_INDEX_NONE);
	Tcl_AppendToObj(psObj, "0 setlinejoin 2 setlinecap\n", -1);

	Tcl_ResetResult(interp);
	Tk_CanvasPsOutline(canvas, itemPtr, &rectOvalPtr->outline);
	if (Tk_CanvasPsOutline(canvas, itemPtr,
		&rectOvalPtr->outline)!= TCL_OK) {
	    goto error;
	}
	Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp));
    }

    /*
     * Plug the accumulated postscript back into the result.
     */

    (void) Tcl_RestoreInterpState(interp, interpState);
    Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj);
    Tcl_DecrRefCount(psObj);
    Tcl_DecrRefCount(pathObj);
    return TCL_OK;

  error:
    Tcl_DiscardInterpState(interpState);
    Tcl_DecrRefCount(psObj);
    Tcl_DecrRefCount(pathObj);
    return TCL_ERROR;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkScale.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14



15
16
17
18
19
20
21


22
23
24
25

26
27
28
29
30
31
32
33
34
35









36
37
38
39

40
41
42

43
44
45

46
47
48

49
50

51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66

67
68
69
70
71




72
73
74

75
76
77

78
79
80
81


82
83

84
85
86

87
88
89


90
91

92
93

94
95
96

97
98
99

100
101
102

103
104
105

106
107
108

109
110
111
112


113
114

115
116
117

118
119
120

121
122

123
124
125

126
127
128
129


130
131
132
133
134
135
136
1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
19


20
21




22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46

47
48
49

50
51
52

53
54

55
56

57
58
59

60
61
62

63
64
65

66
67
68

69
70

71
72




73
74
75
76
77
78

79
80
81

82
83
84


85
86
87

88
89
90

91
92


93
94
95

96
97

98
99
100

101
102
103

104
105
106

107
108
109

110
111
112

113
114
115


116
117
118

119
120
121

122
123
124

125
126

127
128
129

130
131
132


133
134
135
136
137
138
139
140
141











-
-
-
+
+
+





-
-
+
+
-
-
-
-
+
-









+
+
+
+
+
+
+
+
+



-
+


-
+


-
+


-
+

-
+

-
+


-
+


-
+


-
+


-
+

-
+

-
-
-
-
+
+
+
+


-
+


-
+


-
-
+
+

-
+


-
+

-
-
+
+

-
+

-
+


-
+


-
+


-
+


-
+


-
+


-
-
+
+

-
+


-
+


-
+

-
+


-
+


-
-
+
+







/*
 * tkScale.c --
 *
 *	This module implements a scale widgets for the Tk toolkit. A scale
 *	displays a slider that can be adjusted to change a value; it also
 *	displays numeric labels and a textual label, if desired.
 *
 *	The modifications to use floating-point values are based on an
 *	implementation by Paul Mackerras. The -variable option is due to
 *	Henning Schulzrinne. All of these are used with permission.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkScale.h"
#include "default.h"
#include "tkInt.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#include "tkScale.h"
#endif

/*
 * The following table defines the legal values for the -orient option. It is
 * used together with the "enum orient" declaration in tkScale.h.
 */

static const char *const orientStrings[] = {
    "horizontal", "vertical", NULL
};

/*
 * The following table defines the legal values for the -state option. It is
 * used together with the "enum state" declaration in tkScale.h.
 */

static const char *const stateStrings[] = {
    "active", "disabled", "normal", NULL
};

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_SCALE_ACTIVE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkScale, activeBorder),
	DEF_SCALE_ACTIVE_BG_COLOR, -1, Tk_Offset(TkScale, activeBorder),
	0, DEF_SCALE_ACTIVE_BG_MONO, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_SCALE_BG_COLOR, TCL_INDEX_NONE, offsetof(TkScale, bgBorder),
	DEF_SCALE_BG_COLOR, -1, Tk_Offset(TkScale, bgBorder),
	0, DEF_SCALE_BG_MONO, 0},
    {TK_OPTION_DOUBLE, "-bigincrement", "bigIncrement", "BigIncrement",
	DEF_SCALE_BIG_INCREMENT, TCL_INDEX_NONE, offsetof(TkScale, bigIncrement),
	DEF_SCALE_BIG_INCREMENT, -1, Tk_Offset(TkScale, bigIncrement),
	0, 0, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
	NULL, 0, -1, 0, "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_SCALE_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, borderWidth),
	DEF_SCALE_BORDER_WIDTH, -1, Tk_Offset(TkScale, borderWidth),
	0, 0, 0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	DEF_SCALE_COMMAND, TCL_INDEX_NONE, offsetof(TkScale, command),
	DEF_SCALE_COMMAND, -1, Tk_Offset(TkScale, command),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_SCALE_CURSOR, TCL_INDEX_NONE, offsetof(TkScale, cursor),
	DEF_SCALE_CURSOR, -1, Tk_Offset(TkScale, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INT, "-digits", "digits", "Digits",
	DEF_SCALE_DIGITS, TCL_INDEX_NONE, offsetof(TkScale, digits),
	DEF_SCALE_DIGITS, -1, Tk_Offset(TkScale, digits),
	0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_SCALE_FONT, TCL_INDEX_NONE, offsetof(TkScale, tkfont), 0, 0, 0},
	DEF_SCALE_FONT, -1, Tk_Offset(TkScale, tkfont), 0, 0, 0},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_SCALE_FG_COLOR, TCL_INDEX_NONE, offsetof(TkScale, textColorPtr), 0,
	DEF_SCALE_FG_MONO, 0},
    {TK_OPTION_DOUBLE, "-from", "from", "From", DEF_SCALE_FROM, TCL_INDEX_NONE,
	offsetof(TkScale, fromValue), 0, 0, 0},
	DEF_SCALE_FG_COLOR, -1, Tk_Offset(TkScale, textColorPtr), 0,
	(ClientData) DEF_SCALE_FG_MONO, 0},
    {TK_OPTION_DOUBLE, "-from", "from", "From", DEF_SCALE_FROM, -1,
	Tk_Offset(TkScale, fromValue), 0, 0, 0},
    {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_SCALE_HIGHLIGHT_BG_COLOR,
	TCL_INDEX_NONE, offsetof(TkScale, highlightBorder),
	-1, Tk_Offset(TkScale, highlightBorder),
	0, DEF_SCALE_HIGHLIGHT_BG_MONO, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_SCALE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkScale, highlightColorPtr),
	DEF_SCALE_HIGHLIGHT, -1, Tk_Offset(TkScale, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	offsetof(TkScale, highlightWidth), 0, 0, 0},
	"HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, -1,
	Tk_Offset(TkScale, highlightWidth), 0, 0, 0},
    {TK_OPTION_STRING, "-label", "label", "Label",
	DEF_SCALE_LABEL, TCL_INDEX_NONE, offsetof(TkScale, label),
	DEF_SCALE_LABEL, -1, Tk_Offset(TkScale, label),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-length", "length", "Length",
	DEF_SCALE_LENGTH, TCL_INDEX_NONE, offsetof(TkScale, length), 0, 0, 0},
	DEF_SCALE_LENGTH, -1, Tk_Offset(TkScale, length), 0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
	DEF_SCALE_ORIENT, TCL_INDEX_NONE, offsetof(TkScale, orient),
	TK_OPTION_ENUM_VAR, orientStrings, 0},
	DEF_SCALE_ORIENT, -1, Tk_Offset(TkScale, orient),
	0, orientStrings, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_SCALE_RELIEF, TCL_INDEX_NONE, offsetof(TkScale, relief), 0, 0, 0},
	DEF_SCALE_RELIEF, -1, Tk_Offset(TkScale, relief), 0, 0, 0},
    {TK_OPTION_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
	DEF_SCALE_REPEAT_DELAY, TCL_INDEX_NONE, offsetof(TkScale, repeatDelay),
	DEF_SCALE_REPEAT_DELAY, -1, Tk_Offset(TkScale, repeatDelay),
	0, 0, 0},
    {TK_OPTION_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
	DEF_SCALE_REPEAT_INTERVAL, TCL_INDEX_NONE, offsetof(TkScale, repeatInterval),
	DEF_SCALE_REPEAT_INTERVAL, -1, Tk_Offset(TkScale, repeatInterval),
	0, 0, 0},
    {TK_OPTION_DOUBLE, "-resolution", "resolution", "Resolution",
	DEF_SCALE_RESOLUTION, TCL_INDEX_NONE, offsetof(TkScale, resolution),
	DEF_SCALE_RESOLUTION, -1, Tk_Offset(TkScale, resolution),
	0, 0, 0},
    {TK_OPTION_BOOLEAN, "-showvalue", "showValue", "ShowValue",
	DEF_SCALE_SHOW_VALUE, TCL_INDEX_NONE, offsetof(TkScale, showValue),
	DEF_SCALE_SHOW_VALUE, -1, Tk_Offset(TkScale, showValue),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-sliderlength", "sliderLength", "SliderLength",
	DEF_SCALE_SLIDER_LENGTH, TCL_INDEX_NONE, offsetof(TkScale, sliderLength),
	DEF_SCALE_SLIDER_LENGTH, -1, Tk_Offset(TkScale, sliderLength),
	0, 0, 0},
    {TK_OPTION_RELIEF, "-sliderrelief", "sliderRelief", "SliderRelief",
	DEF_SCALE_SLIDER_RELIEF, TCL_INDEX_NONE, offsetof(TkScale, sliderRelief),
	DEF_SCALE_SLIDER_RELIEF, -1, Tk_Offset(TkScale, sliderRelief),
	0, 0, 0},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_SCALE_STATE, TCL_INDEX_NONE, offsetof(TkScale, state),
	TK_OPTION_ENUM_VAR, tkStateStrings, 0},
	DEF_SCALE_STATE, -1, Tk_Offset(TkScale, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_SCALE_TAKE_FOCUS, offsetof(TkScale, takeFocusPtr), TCL_INDEX_NONE,
	DEF_SCALE_TAKE_FOCUS, Tk_Offset(TkScale, takeFocusPtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_DOUBLE, "-tickinterval", "tickInterval", "TickInterval",
	DEF_SCALE_TICK_INTERVAL, TCL_INDEX_NONE, offsetof(TkScale, tickInterval),
	DEF_SCALE_TICK_INTERVAL, -1, Tk_Offset(TkScale, tickInterval),
	0, 0, 0},
    {TK_OPTION_DOUBLE, "-to", "to", "To",
	DEF_SCALE_TO, TCL_INDEX_NONE, offsetof(TkScale, toValue), 0, 0, 0},
	DEF_SCALE_TO, -1, Tk_Offset(TkScale, toValue), 0, 0, 0},
    {TK_OPTION_COLOR, "-troughcolor", "troughColor", "Background",
	DEF_SCALE_TROUGH_COLOR, TCL_INDEX_NONE, offsetof(TkScale, troughColorPtr),
	DEF_SCALE_TROUGH_COLOR, -1, Tk_Offset(TkScale, troughColorPtr),
	0, DEF_SCALE_TROUGH_MONO, 0},
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	DEF_SCALE_VARIABLE, offsetof(TkScale, varNamePtr), TCL_INDEX_NONE,
	DEF_SCALE_VARIABLE, Tk_Offset(TkScale, varNamePtr), -1,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-width", "width", "Width",
	DEF_SCALE_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, width), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, 0, 0}
	DEF_SCALE_WIDTH, -1, Tk_Offset(TkScale, width), 0, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0}
};

/*
 * The following tables define the scale widget commands and map the indexes
 * into the string tables into a single enumerated type used to dispatch the
 * scale widget command.
 */
144
145
146
147
148
149
150
151

152
153
154
155

156
157
158
159


160
161

162
163
164
165




166
167
168
169
170
171
172
173
174
175
176
177


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245

246
247
248
249
250
251
252
149
150
151
152
153
154
155

156
157
158
159

160




161
162
163

164
165
166


167
168
169
170
171
172
173
174
175
176
177
178
179
180


181
182
183









































184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208

209
210
211
212
213
214
215
216







-
+



-
+
-
-
-
-
+
+

-
+


-
-
+
+
+
+










-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+




-
+







    COMMAND_IDENTIFY, COMMAND_SET
};

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

static void		ComputeFormat(TkScale *scalePtr, int forTicks);
static void		ComputeFormat(TkScale *scalePtr);
static void		ComputeScaleGeometry(TkScale *scalePtr);
static int		ConfigureScale(Tcl_Interp *interp, TkScale *scalePtr,
			    int objc, Tcl_Obj *const objv[]);
static void		DestroyScale(void *memPtr);
static void		DestroyScale(char *memPtr);
static double		MaxTickRoundingError(TkScale *scalePtr,
			    double tickResolution);
static void		ScaleCmdDeletedProc(void *clientData);
static void		ScaleEventProc(void *clientData,
static void		ScaleCmdDeletedProc(ClientData clientData);
static void		ScaleEventProc(ClientData clientData,
			    XEvent *eventPtr);
static char *		ScaleVarProc(void *clientData,
static char *		ScaleVarProc(ClientData clientData,
			    Tcl_Interp *interp, const char *name1,
			    const char *name2, int flags);
static Tcl_ObjCmdProc ScaleWidgetObjCmd;
static void		ScaleWorldChanged(void *instanceData);
static int		ScaleWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		ScaleWorldChanged(ClientData instanceData);
static void		ScaleSetVariable(TkScale *scalePtr);

/*
 * The structure below defines scale class behavior by means of procedures
 * that can be invoked from generic window code.
 */

static const Tk_ClassProcs scaleClass = {
    sizeof(Tk_ClassProcs),	/* size */
    ScaleWorldChanged,		/* worldChangedProc */
    NULL,			/* createProc */
    NULL			/* modalProc */
    NULL,					/* createProc */
    NULL					/* modalProc */
};

/*
 *--------------------------------------------------------------
 *
 * ScaleDigit, ScaleMax, ScaleMin, ScaleRound --
 *
 *	Simple math helper functions, designed to be automatically inlined by
 *	the compiler most of the time.
 *
 *--------------------------------------------------------------
 */

static inline int
ScaleDigit(
    double value)
{
    return (int) floor(log10(fabs(value)));
}

static inline double
ScaleMax(
    double a,
    double b)
{
    return (a > b) ? a : b;
}

static inline double
ScaleMin(
    double a,
    double b)
{
    return (a < b) ? a : b;
}

static inline int
ScaleRound(
    double value)
{
    return (int) floor(value + 0.5);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_ScaleObjCmd --
 *
 *	This procedure is invoked to process the "scale" Tcl command. See the
 *	user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_ScaleObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    TkScale *scalePtr;
    register TkScale *scalePtr;
    Tk_OptionTable optionTable;
    Tk_Window tkwin;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }
298
299
300
301
302
303
304
305
306


307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
262
263
264
265
266
267
268


269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319







-
-
+
+


-
+
















-
+








-
+












-
+







    scalePtr->labelLength	= 0;
    scalePtr->state		= STATE_NORMAL;
    scalePtr->borderWidth	= 0;
    scalePtr->bgBorder		= NULL;
    scalePtr->activeBorder	= NULL;
    scalePtr->sliderRelief	= TK_RELIEF_RAISED;
    scalePtr->troughColorPtr	= NULL;
    scalePtr->troughGC		= NULL;
    scalePtr->copyGC		= NULL;
    scalePtr->troughGC		= None;
    scalePtr->copyGC		= None;
    scalePtr->tkfont		= NULL;
    scalePtr->textColorPtr	= NULL;
    scalePtr->textGC		= NULL;
    scalePtr->textGC		= None;
    scalePtr->relief		= TK_RELIEF_FLAT;
    scalePtr->highlightWidth	= 0;
    scalePtr->highlightBorder	= NULL;
    scalePtr->highlightColorPtr	= NULL;
    scalePtr->inset		= 0;
    scalePtr->sliderLength	= 0;
    scalePtr->showValue		= 0;
    scalePtr->horizLabelY	= 0;
    scalePtr->horizValueY	= 0;
    scalePtr->horizTroughY	= 0;
    scalePtr->horizTickY	= 0;
    scalePtr->vertTickRightX	= 0;
    scalePtr->vertValueRightX	= 0;
    scalePtr->vertTroughX	= 0;
    scalePtr->vertLabelX	= 0;
    scalePtr->fontHeight	= 0;
    scalePtr->cursor		= NULL;
    scalePtr->cursor		= None;
    scalePtr->takeFocusPtr	= NULL;
    scalePtr->flags		= NEVER_SET;

    Tk_SetClassProcs(scalePtr->tkwin, &scaleClass, scalePtr);
    Tk_CreateEventHandler(scalePtr->tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    ScaleEventProc, scalePtr);

    if ((Tk_InitOptions(interp, scalePtr, optionTable, tkwin)
    if ((Tk_InitOptions(interp, (char *) scalePtr, optionTable, tkwin)
	    != TCL_OK) ||
	    (ConfigureScale(interp, scalePtr, objc - 2, objv + 2) != TCL_OK)) {
	Tk_DestroyWindow(scalePtr->tkwin);
	return TCL_ERROR;
    }

    /*
     * The widget was just created, no command callback must be invoked.
     */

    scalePtr->flags &= ~INVOKE_COMMAND;

    Tcl_SetObjResult(interp, Tk_NewWindowObj(scalePtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(scalePtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * ScaleWidgetObjCmd --
365
366
367
368
369
370
371
372

373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
329
330
331
332
333
334
335

336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378







-
+




-
+




















-
+








-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
ScaleWidgetObjCmd(
    void *clientData,	/* Information about scale widget. */
    ClientData clientData,	/* Information about scale widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    TkScale *scalePtr = (TkScale *)clientData;
    TkScale *scalePtr = clientData;
    Tcl_Obj *objPtr;
    int index, result;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    result = Tcl_GetIndexFromObjStruct(interp, objv[1], commandNames,
	    sizeof(char *), "option", 0, &index);
    if (result != TCL_OK) {
	return result;
    }
    Tcl_Preserve(scalePtr);

    switch (index) {
    case COMMAND_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "cget option");
	    goto error;
	}
	objPtr = Tk_GetOptionValue(interp, scalePtr,
	objPtr = Tk_GetOptionValue(interp, (char *) scalePtr,
		scalePtr->optionTable, objv[2], scalePtr->tkwin);
	if (objPtr == NULL) {
	    goto error;
	}
	Tcl_SetObjResult(interp, objPtr);
	break;
    case COMMAND_CONFIGURE:
	if (objc <= 3) {
	    objPtr = Tk_GetOptionInfo(interp, scalePtr,
	    objPtr = Tk_GetOptionInfo(interp, (char *) scalePtr,
		    scalePtr->optionTable,
		    (objc == 3) ? objv[2] : NULL, scalePtr->tkwin);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
436
437
438
439
440
441
442
443
444


445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
400
401
402
403
404
405
406


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456







-
-
+
+




















-
+



















-
+







		    + scalePtr->borderWidth;
	    y = TkScaleValueToPixel(scalePtr, value);
	} else {
	    x = TkScaleValueToPixel(scalePtr, value);
	    y = scalePtr->horizTroughY + scalePtr->width/2
		    + scalePtr->borderWidth;
	}
	coords[0] = Tcl_NewWideIntObj(x);
	coords[1] = Tcl_NewWideIntObj(y);
	coords[0] = Tcl_NewIntObj(x);
	coords[1] = Tcl_NewIntObj(y);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, coords));
	break;
    }
    case COMMAND_GET: {
	double value;
	int x, y;

	if ((objc != 2) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 1, objv, "get ?x y?");
	    goto error;
	}
	if (objc == 2) {
	    value = scalePtr->value;
	} else {
	    if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK) ||
		    (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
		goto error;
	    }
	    value = TkScalePixelToValue(scalePtr, x, y);
	}
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(scalePtr->valueFormat, value));
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(scalePtr->format, value));
	break;
    }
    case COMMAND_IDENTIFY: {
	int x, y;
	const char *zone = "";

	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 1, objv, "identify x y");
	    goto error;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	    goto error;
	}
	switch (TkpScaleElement(scalePtr, x, y)) {
	case TROUGH1:	zone = "trough1"; break;
	case SLIDER:	zone = "slider";  break;
	case TROUGH2:	zone = "trough2"; break;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
	break;
    }
    case COMMAND_SET: {
	double value;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "set value");
525
526
527
528
529
530
531
532

533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556

557
558
559

560
561
562

563
564
565
566
567
568
569
489
490
491
492
493
494
495

496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519

520
521
522

523
524
525

526
527
528
529
530
531
532
533







-
+

-
+


















-
+


-
+


-
+


-
+







 *	Everything associated with the scale is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyScale(
    void *memPtr)	/* Info about scale widget. */
    char *memPtr)	/* Info about scale widget. */
{
    TkScale *scalePtr = (TkScale *) memPtr;
    register TkScale *scalePtr = (TkScale *) memPtr;

    scalePtr->flags |= SCALE_DELETED;

    Tcl_DeleteCommandFromToken(scalePtr->interp, scalePtr->widgetCmd);
    if (scalePtr->flags & REDRAW_PENDING) {
	Tcl_CancelIdleCall(TkpDisplayScale, scalePtr);
    }

    /*
     * Free up all the stuff that requires special handling, then let
     * Tk_FreeOptions handle all the standard option-related stuff.
     */

    if (scalePtr->varNamePtr != NULL) {
	Tcl_UntraceVar2(scalePtr->interp, Tcl_GetString(scalePtr->varNamePtr),
		NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		ScaleVarProc, scalePtr);
    }
    if (scalePtr->troughGC != NULL) {
    if (scalePtr->troughGC != None) {
	Tk_FreeGC(scalePtr->display, scalePtr->troughGC);
    }
    if (scalePtr->copyGC != NULL) {
    if (scalePtr->copyGC != None) {
	Tk_FreeGC(scalePtr->display, scalePtr->copyGC);
    }
    if (scalePtr->textGC != NULL) {
    if (scalePtr->textGC != None) {
	Tk_FreeGC(scalePtr->display, scalePtr->textGC);
    }
    Tk_FreeConfigOptions(scalePtr, scalePtr->optionTable,
    Tk_FreeConfigOptions((char *) scalePtr, scalePtr->optionTable,
	    scalePtr->tkwin);
    scalePtr->tkwin = NULL;
    TkpDestroyScale(scalePtr);
}

/*
 *----------------------------------------------------------------------
584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562







-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureScale(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkScale *scalePtr,	/* Information about widget; may or may not
    register TkScale *scalePtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    int objc,			/* Number of valid entries in objv. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    Tk_SavedOptions savedOptions;
    Tcl_Obj *errorResult = NULL;
    int error;
610
611
612
613
614
615
616
617

618
619
620
621
622
623
624
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588







-
+








    for (error = 0; error <= 1; error++) {
	if (!error) {
	    /*
	     * First pass: set options to new values.
	     */

	    if (Tk_SetOptions(interp, scalePtr,
	    if (Tk_SetOptions(interp, (char *) scalePtr,
		    scalePtr->optionTable, objc, objv, scalePtr->tkwin,
		    &savedOptions, NULL) != TCL_OK) {
		continue;
	    }
	} else {
	    /*
	     * Second pass: restore options to old values.
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653




654


655
656


657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672

673
674
675
676
677
678
679
603
604
605
606
607
608
609

610
611
612
613




614
615
616
617
618
619
620


621
622
623
624
625
626
627
628
629
630
631
632
633
634

635

636

637
638
639
640
641
642
643
644







-
+



-
-
-
-
+
+
+
+

+
+
-
-
+
+












-
+
-

-
+







	    double value;
	    Tcl_Obj *valuePtr;

	    valuePtr = Tcl_ObjGetVar2(interp, scalePtr->varNamePtr, NULL,
		    TCL_GLOBAL_ONLY);
	    if ((valuePtr != NULL) &&
		    (Tcl_GetDoubleFromObj(NULL, valuePtr, &value) == TCL_OK)) {
		scalePtr->value = TkRoundValueToResolution(scalePtr, value);
		scalePtr->value = TkRoundToResolution(scalePtr, value);
	    }
	}

        /*
         * The fromValue shall not be rounded to the resolution, but the
         * toValue and tickInterval do.
         */
	/*
	 * Several options need special processing, such as parsing the
	 * orientation and creating GCs.
	 */

	scalePtr->fromValue = TkRoundToResolution(scalePtr,
		scalePtr->fromValue);
	scalePtr->toValue = TkRoundValueToResolution(scalePtr, scalePtr->toValue);
	scalePtr->tickInterval = TkRoundIntervalToResolution(scalePtr,
	scalePtr->toValue = TkRoundToResolution(scalePtr, scalePtr->toValue);
	scalePtr->tickInterval = TkRoundToResolution(scalePtr,
		scalePtr->tickInterval);

	/*
	 * Make sure that the tick interval has the right sign so that
	 * addition moves from fromValue to toValue.
	 */

	if ((scalePtr->tickInterval < 0)
		^ ((scalePtr->toValue - scalePtr->fromValue) < 0)) {
	    scalePtr->tickInterval = -scalePtr->tickInterval;
	}

	ComputeFormat(scalePtr, 0);
	ComputeFormat(scalePtr);
	ComputeFormat(scalePtr, 1);

	scalePtr->labelLength = scalePtr->label ? strlen(scalePtr->label) : 0;
	scalePtr->labelLength = scalePtr->label ? (int)strlen(scalePtr->label) : 0;

	Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder);

	if (scalePtr->highlightWidth < 0) {
	    scalePtr->highlightWidth = 0;
	}
	scalePtr->inset = scalePtr->highlightWidth + scalePtr->borderWidth;
708
709
710
711
712
713
714
715
716
717



718
719
720
721
722
723
724
673
674
675
676
677
678
679



680
681
682
683
684
685
686
687
688
689







-
-
-
+
+
+







		TCL_GLOBAL_ONLY);
	if ((valuePtr == NULL) || (Tcl_GetDoubleFromObj(NULL,
		valuePtr, &varValue) != TCL_OK)) {
	    ScaleSetVariable(scalePtr);
	} else {
	    char varString[TCL_DOUBLE_SPACE], scaleString[TCL_DOUBLE_SPACE];

            Tcl_PrintDouble(NULL, varValue, varString);
            Tcl_PrintDouble(NULL, scalePtr->value, scaleString);
            if (strcmp(varString, scaleString)) {
	    sprintf(varString, scalePtr->format, varValue);
	    sprintf(scaleString, scalePtr->format, scalePtr->value);
	    if (strcmp(varString, scaleString)) {
		ScaleSetVariable(scalePtr);
	    }
	}
	Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr),
		NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		ScaleVarProc, scalePtr);
    }
748
749
750
751
752
753
754
755

756
757
758
759

760
761
762
763

764
765
766
767
768
769
770
771

772
773
774
775
776

777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850



851
852
853
854

855

856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882

883
884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913






914
915

916
917
918
919
920
921
922
923
924
925









926
927
928
929
930
931
932
933







934
935
936
937
938
939
940
941
942
943
944
945
946
947













948
949
950
951
952
953
954
955
713
714
715
716
717
718
719

720
721
722
723

724
725
726
727

728
729
730
731
732
733
734
735

736
737
738
739
740

741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757



758
759
760


















































761
762



763
764
765
766
767
768
769
770

771
772
773
774
775
776
777

778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796

797
798


799




























800
801
802
803
804
805


806
807









808
809
810
811
812
813
814
815
816
817







818
819
820
821
822
823
824
825













826
827
828
829
830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845







-
+



-
+



-
+







-
+




-
+
















-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
+
+
+




+
-
+






-
+
-


















-
+

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-







 *	Scale will be relayed out and redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
ScaleWorldChanged(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    XGCValues gcValues;
    GC gc;
    TkScale *scalePtr = (TkScale *)instanceData;
    TkScale *scalePtr = instanceData;

    gcValues.foreground = scalePtr->troughColorPtr->pixel;
    gc = Tk_GetGC(scalePtr->tkwin, GCForeground, &gcValues);
    if (scalePtr->troughGC != NULL) {
    if (scalePtr->troughGC != None) {
	Tk_FreeGC(scalePtr->display, scalePtr->troughGC);
    }
    scalePtr->troughGC = gc;

    gcValues.font = Tk_FontId(scalePtr->tkfont);
    gcValues.foreground = scalePtr->textColorPtr->pixel;
    gc = Tk_GetGC(scalePtr->tkwin, GCForeground | GCFont, &gcValues);
    if (scalePtr->textGC != NULL) {
    if (scalePtr->textGC != None) {
	Tk_FreeGC(scalePtr->display, scalePtr->textGC);
    }
    scalePtr->textGC = gc;

    if (scalePtr->copyGC == NULL) {
    if (scalePtr->copyGC == None) {
	gcValues.graphics_exposures = False;
	scalePtr->copyGC = Tk_GetGC(scalePtr->tkwin, GCGraphicsExposures,
		&gcValues);
    }
    scalePtr->inset = scalePtr->highlightWidth + scalePtr->borderWidth;

    /*
     * Recompute display-related information, and let the geometry manager
     * know how much space is needed now.
     */

    ComputeScaleGeometry(scalePtr);

    TkEventuallyRedrawScale(scalePtr, REDRAW_ALL);
}

 /*
  *----------------------------------------------------------------------
  *
/*
 *----------------------------------------------------------------------
 *
  * MaxTickRoundingError --
  *
  *      Given the separation between values that can be displayed on ticks,
  *      this calculates the maximum magnitude of error for the displayed
  *      value. Tries to be clever by working out the increment in error
  *      between ticks rather than testing all of them, so may overestimate
  *      error if it is greater than 0.25 x the value separation.
  *
  * Results:
  *      Maximum error magnitude of tick numbers.
  *
  * Side effects:
  *      None.
  *
  *----------------------------------------------------------------------
  */

static double
MaxTickRoundingError(
    TkScale *scalePtr,		/* Information about scale widget. */
    double tickResolution)      /* Separation between displayable values. */
{
    double tickPosn, firstTickError, lastTickError, intervalError;
    int tickCount;

    /*
     * Compute the error for each tick-related measure.
     */

    tickPosn = scalePtr->fromValue / tickResolution;
    firstTickError = tickPosn - ScaleRound(tickPosn);

    tickPosn = scalePtr->tickInterval / tickResolution;
    intervalError = tickPosn - ScaleRound(tickPosn);

    tickCount = (int) ((scalePtr->toValue - scalePtr->fromValue) /
	    scalePtr->tickInterval);	/* not including first */
    lastTickError = ScaleMin(0.5,
	    fabs(firstTickError + tickCount * intervalError));

    /*
     * Compute the maximum cumulative rounding error.
     */

    return ScaleMax(fabs(firstTickError), lastTickError) * tickResolution;
}

/*
 *----------------------------------------------------------------------
 *
 * ComputeFormat --
 *
 *	This procedure is invoked to recompute the "valueFormat" or
 *	"tickFormat" field of a scale's widget record, which determines how
 *	the value of the scale or one of its ticks is converted to a string.
 *	This procedure is invoked to recompute the "format" field of a scale's
 *	widget record, which determines how the value of the scale is
 *	converted to a string.
 *
 * Results:
 *	None.
 *
 * Side effects:
 * Side effects: The valueFormat or tickFormat field of scalePtr is modified.
 *	The format field of scalePtr is modified.
 *
 *----------------------------------------------------------------------
 */

static void
ComputeFormat(
    TkScale *scalePtr,		/* Information about scale widget. */
    TkScale *scalePtr)		/* Information about scale widget. */
    int forTicks)               /* Do for ticks rather than value */
{
    double maxValue, x;
    int mostSigDigit, numDigits, leastSigDigit, afterDecimal;
    int eDigits, fDigits;

    /*
     * Compute the displacement from the decimal of the most significant digit
     * required for any number in the scale's range.
     */

    maxValue = fabs(scalePtr->fromValue);
    x = fabs(scalePtr->toValue);
    if (x > maxValue) {
	maxValue = x;
    }
    if (maxValue == 0) {
	maxValue = 1;
    }
    mostSigDigit = ScaleDigit(maxValue);
    mostSigDigit = (int) floor(log10(maxValue));

    if (forTicks) {
	/*
    /*
	 * Display only enough digits to ensure adjacent ticks have different
	 * values.
	 */

	if (scalePtr->tickInterval != 0) {
	    leastSigDigit = ScaleDigit(scalePtr->tickInterval);

	    /*
	     * Now add more digits until max error is less than
	     * TICK_VALUES_DISPLAY_ACCURACY intervals
	     */

	    while (MaxTickRoundingError(scalePtr, pow(10, leastSigDigit))
		    > fabs(TICK_VALUES_DISPLAY_ACCURACY * scalePtr->tickInterval)) {
		--leastSigDigit;
	    }
	    numDigits = 1 + mostSigDigit - leastSigDigit;
	} else {
	    numDigits = 1;
	}
    } else {
	/*
	 * If the number of significant digits wasn't specified explicitly,
	 * compute it. It's the difference between the most significant digit
	 * needed to represent any number on the scale and the most
	 * significant digit of the smallest difference between numbers on the
	 * scale. In other words, display enough digits so that at least one
	 * digit will be different between any two adjacent positions of the
     * If the number of significant digits wasn't specified explicitly,
     * compute it. It's the difference between the most significant digit
     * needed to represent any number on the scale and the most significant
     * digit of the smallest difference between numbers on the scale. In other
     * words, display enough digits so that at least one digit will be
     * different between any two adjacent positions of the scale.
	 * scale.
	 */
     */

	numDigits = scalePtr->digits;
	if (numDigits > TCL_MAX_PREC) {
	    numDigits = 0;
	}
	if (numDigits <= 0) {
	    if (scalePtr->resolution > 0) {
		/*
		 * A resolution was specified for the scale, so just use it.
		 */
    numDigits = scalePtr->digits;
    if (numDigits > TCL_MAX_PREC) {
	numDigits = 0;
    }
    if (numDigits <= 0) {
	if (scalePtr->resolution > 0) {
	    /*
	     * A resolution was specified for the scale, so just use it.
	     */

		leastSigDigit = ScaleDigit(scalePtr->resolution);
	    } else {
		/*
		 * No resolution was specified, so compute the difference in
		 * value between adjacent pixels and use it for the least
		 * significant digit.
		 */
	    leastSigDigit = (int) floor(log10(scalePtr->resolution));
	} else {
	    /*
	     * No resolution was specified, so compute the difference in value
	     * between adjacent pixels and use it for the least significant
	     * digit.
	     */

		x = fabs(scalePtr->fromValue - scalePtr->toValue);
		if (scalePtr->length > 0) {
		    x /= scalePtr->length;
		}
		if (x > 0) {
		    leastSigDigit = ScaleDigit(x);
		} else {
		    leastSigDigit = 0;
		}
	    }
	    numDigits = mostSigDigit - leastSigDigit + 1;
	    if (numDigits < 1) {
		numDigits = 1;
	    x = fabs(scalePtr->fromValue - scalePtr->toValue);
	    if (scalePtr->length > 0) {
		x /= scalePtr->length;
	    }
	    if (x > 0){
		leastSigDigit = (int) floor(log10(x));
	    } else {
		leastSigDigit = 0;
	    }
	}
	numDigits = mostSigDigit - leastSigDigit + 1;
	if (numDigits < 1) {
	    numDigits = 1;
	    }
	}
    }

    /*
     * Compute the number of characters required using "e" format and "f"
     * format, and then choose whichever one takes fewer characters.
     */
965
966
967
968
969
970
971
972
973
974
975
976
977




978
979
980
981
982
983
984
985
986
987
988
989
990
991
855
856
857
858
859
860
861






862
863
864
865







866
867
868
869
870
871
872







-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-







    fDigits = (mostSigDigit >= 0) ? mostSigDigit + afterDecimal : afterDecimal;
    if (afterDecimal > 0) {
	fDigits++;			/* Decimal point. */
    }
    if (mostSigDigit < 0) {
	fDigits++;			/* Zero to left of decimal point. */
    }

    if (forTicks) {
	if (fDigits <= eDigits) {
	    snprintf(scalePtr->tickFormat, sizeof(scalePtr->tickFormat), "%%.%df", afterDecimal);
	} else {
	    snprintf(scalePtr->tickFormat, sizeof(scalePtr->tickFormat), "%%.%de", numDigits - 1);
    if (fDigits <= eDigits) {
	sprintf(scalePtr->format, "%%.%df", afterDecimal);
    } else {
	sprintf(scalePtr->format, "%%.%de", numDigits-1);
	}
    } else {
	if (fDigits <= eDigits) {
	    snprintf(scalePtr->valueFormat, sizeof(scalePtr->valueFormat), "%%.%df", afterDecimal);
	} else {
	    snprintf(scalePtr->valueFormat, sizeof(scalePtr->valueFormat), "%%.%de", numDigits - 1);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ComputeScaleGeometry --
1002
1003
1004
1005
1006
1007
1008
1009

1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
883
884
885
886
887
888
889

890
891
892

893
894
895
896
897
898
899
900







-
+


-
+







 *	gets told about the window's preferred size.
 *
 *----------------------------------------------------------------------
 */

static void
ComputeScaleGeometry(
    TkScale *scalePtr)	/* Information about widget. */
    register TkScale *scalePtr)	/* Information about widget. */
{
    char valueString[TCL_DOUBLE_SPACE];
    int tmp, valuePixels, tickPixels, x, y, extraSpace;
    int tmp, valuePixels, x, y, extraSpace;
    Tk_FontMetrics fm;

    Tk_GetFontMetrics(scalePtr->tkfont, &fm);
    scalePtr->fontHeight = fm.linespace + SPACING;

    /*
     * Horizontal scales are simpler than vertical ones because all sizes are
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
932
933
934
935
936
937
938


939


940
941


942


943
944
945
946
947



















948
949
950
951
952
953
954

955
956
957
958
959

960
961
962
963
964
965
966
967







-
-
+
-
-


-
-
+
-
-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+




-
+








    /*
     * Vertical scale: compute the amount of space needed to display the
     * scales value by formatting strings for the two end points; use
     * whichever length is longer.
     */

    if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
            scalePtr->fromValue) < 0) {
    sprintf(valueString, scalePtr->format, scalePtr->fromValue);
        valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    valuePixels = Tk_TextWidth(scalePtr->tkfont, valueString, -1);

    if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
            scalePtr->toValue) < 0) {
    sprintf(valueString, scalePtr->format, scalePtr->toValue);
        valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    tmp = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
    if (valuePixels < tmp) {
	valuePixels = tmp;
    }

    /*
     * Now do the same thing for the tick values
     */

    if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
            scalePtr->fromValue) < 0) {
        valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    tickPixels = Tk_TextWidth(scalePtr->tkfont, valueString, -1);

    if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
            scalePtr->toValue) < 0) {
        valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    tmp = Tk_TextWidth(scalePtr->tkfont, valueString, -1);
    if (tickPixels < tmp) {
	tickPixels = tmp;
    }

    /*
     * Assign x-locations to the elements of the scale, working from left to
     * right.
     */

    x = scalePtr->inset;
    if ((scalePtr->tickInterval != 0) && (scalePtr->showValue)) {
	scalePtr->vertTickRightX = x + SPACING + tickPixels;
	scalePtr->vertTickRightX = x + SPACING + valuePixels;
	scalePtr->vertValueRightX = scalePtr->vertTickRightX + valuePixels
		+ fm.ascent/2;
	x = scalePtr->vertValueRightX + SPACING;
    } else if (scalePtr->tickInterval != 0) {
	scalePtr->vertTickRightX = x + SPACING + tickPixels;
	scalePtr->vertTickRightX = x + SPACING + valuePixels;
	scalePtr->vertValueRightX = scalePtr->vertTickRightX;
	x = scalePtr->vertTickRightX + SPACING;
    } else if (scalePtr->showValue) {
	scalePtr->vertTickRightX = x;
	scalePtr->vertValueRightX = x + SPACING + valuePixels;
	x = scalePtr->vertValueRightX + SPACING;
    } else {
1143
1144
1145
1146
1147
1148
1149
1150

1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
999
1000
1001
1002
1003
1004
1005

1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
1016







-
+


-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ScaleEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkScale *scalePtr = (TkScale *)clientData;
    TkScale *scalePtr = clientData;

    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	TkEventuallyRedrawScale(scalePtr, REDRAW_ALL);
    } else if (eventPtr->type == DestroyNotify) {
	DestroyScale(clientData);
    } else if (eventPtr->type == ConfigureNotify) {
	ComputeScaleGeometry(scalePtr);
1192
1193
1194
1195
1196
1197
1198
1199

1200
1201

1202
1203
1204
1205
1206
1207
1208
1048
1049
1050
1051
1052
1053
1054

1055
1056

1057
1058
1059
1060
1061
1062
1063
1064







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
ScaleCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkScale *scalePtr = (TkScale *)clientData;
    TkScale *scalePtr = clientData;
    Tk_Window tkwin = scalePtr->tkwin;

    /*
     * This procedure could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this procedure destroys the
     * widget.
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299



1300
1301
1302
1303



1304
1305
1306
1307
1308
1309
1310
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111

1112
1113
1114
1115




1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127









1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139



1140
1141
1142
1143



1144
1145
1146
1147
1148
1149
1150
1151
1152
1153







-
+

















-
+



-
-
-
-











-
+
-
-
-
-
-
-
-
-
-












-
-
-
+
+
+

-
-
-
+
+
+







 *	be redrawn.
 *
 *--------------------------------------------------------------
 */

void
TkEventuallyRedrawScale(
    TkScale *scalePtr,	/* Information about widget. */
    register TkScale *scalePtr,	/* Information about widget. */
    int what)			/* What to redraw: REDRAW_SLIDER or
				 * REDRAW_ALL. */
{
    if ((what == 0) || (scalePtr->tkwin == NULL)
	    || !Tk_IsMapped(scalePtr->tkwin)) {
	return;
    }
    if (!(scalePtr->flags & REDRAW_PENDING)) {
	scalePtr->flags |= REDRAW_PENDING;
	Tcl_DoWhenIdle(TkpDisplayScale, scalePtr);
    }
    scalePtr->flags |= what;
}

/*
 *--------------------------------------------------------------
 *
 * TkRoundValueToResolution, TkRoundIntervalToResolution --
 * TkRoundToResolution --
 *
 *	Round a given floating-point value to the nearest multiple of the
 *	scale's resolution.
 *	TkRoundValueToResolution rounds an absolute value based on the from
 *	value as a reference.
 *	TkRoundIntervalToResolution rounds a relative value without
 *	reference, i.e.	it rounds an interval.
 *
 * Results:
 *	The return value is the rounded result.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

double
TkRoundValueToResolution(
TkRoundToResolution(
    TkScale *scalePtr,		/* Information about scale widget. */
    double value)		/* Value to round. */
{
    return TkRoundIntervalToResolution(scalePtr, value - scalePtr->fromValue)
            + scalePtr->fromValue;
}

double
TkRoundIntervalToResolution(
    TkScale *scalePtr,		/* Information about scale widget. */
    double value)		/* Value to round. */
{
    double rem, rounded, tick;

    if (scalePtr->resolution <= 0) {
	return value;
    }
    tick = floor(value/scalePtr->resolution);
    rounded = scalePtr->resolution * tick;
    rem = value - rounded;
    if (rem < 0) {
        if (rem <= -scalePtr->resolution/2) {
            rounded = (tick - 1.0) * scalePtr->resolution;
        }
	if (rem <= -scalePtr->resolution/2) {
	    rounded = (tick - 1.0) * scalePtr->resolution;
	}
    } else {
        if (rem >= scalePtr->resolution/2) {
            rounded = (tick + 1.0) * scalePtr->resolution;
        }
	if (rem >= scalePtr->resolution/2) {
	    rounded = (tick + 1.0) * scalePtr->resolution;
	}
    }
    return rounded;
}

/*
 *----------------------------------------------------------------------
 *
1320
1321
1322
1323
1324
1325
1326

1327
1328
1329

1330
1331
1332


1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

1173
1174


1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190



1191


















1192
1193
1194
1195
1196
1197
1198







+


-
+

-
-
+
+


-
+











-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	The value displayed in the scale will change to match the variable's
 *	new value. If the variable has a bogus value then it is reset to the
 *	value of the scale.
 *
 *----------------------------------------------------------------------
 */

    /* ARGSUSED */
static char *
ScaleVarProc(
    void *clientData,	/* Information about button. */
    ClientData clientData,	/* Information about button. */
    Tcl_Interp *interp,		/* Interpreter containing variable. */
    TCL_UNUSED(const char *),	/* Name of variable. */
    TCL_UNUSED(const char *),	/* Second part of variable name. */
    const char *name1,		/* Name of variable. */
    const char *name2,		/* Second part of variable name. */
    int flags)			/* Information about what happened. */
{
    TkScale *scalePtr = (TkScale *)clientData;
    register TkScale *scalePtr = clientData;
    const char *resultStr;
    double value;
    Tcl_Obj *valuePtr;
    int result;

    /*
     * If the variable is unset, then immediately recreate it unless the whole
     * interpreter is going away.
     */

    if (flags & TCL_TRACE_UNSETS) {
        if (!Tcl_InterpDeleted(interp) && scalePtr->varNamePtr) {
            void *probe = NULL;

	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
            do {
                probe = Tcl_VarTraceInfo(interp,
                        Tcl_GetString(scalePtr->varNamePtr),
                        TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
                        ScaleVarProc, probe);
                if (probe == (void *)scalePtr) {
                    break;
                }
            } while (probe);
            if (probe) {
                /*
                 * We were able to fetch the unset trace for our
                 * varNamePtr, which means it is not unset and not
                 * the cause of this unset trace. Instead some outdated
                 * former variable must be, and we should ignore it.
                 */
                return NULL;
            }
	    Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr),
		    NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		    ScaleVarProc, clientData);
	    scalePtr->flags |= NEVER_SET;
	    TkScaleSetValue(scalePtr, scalePtr->value, 1, 0);
	}
	return NULL;
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225







-
+







    valuePtr = Tcl_ObjGetVar2(interp, scalePtr->varNamePtr, NULL,
	    TCL_GLOBAL_ONLY);
    result = Tcl_GetDoubleFromObj(interp, valuePtr, &value);
    if (result != TCL_OK) {
	resultStr = "can't assign non-numeric value to scale variable";
	ScaleSetVariable(scalePtr);
    } else {
	scalePtr->value = TkRoundValueToResolution(scalePtr, value);
	scalePtr->value = TkRoundToResolution(scalePtr, value);

	/*
	 * This code is a bit tricky because it sets the scale's value before
	 * calling TkScaleSetValue. This way, TkScaleSetValue won't bother to
	 * set the variable again or to invoke the -command. However, it also
	 * won't redisplay the scale, so we have to ask for that explicitly.
	 */
1423
1424
1425
1426
1427
1428
1429
1430

1431
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445
1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269







-
+







-
+







 *	may also be invoked. The scale's slider is redrawn.
 *
 *--------------------------------------------------------------
 */

void
TkScaleSetValue(
    TkScale *scalePtr,	/* Info about widget. */
    register TkScale *scalePtr,	/* Info about widget. */
    double value,		/* New value for scale. Gets adjusted if it's
				 * off the scale. */
    int setVar,			/* Non-zero means reflect new value through to
				 * associated variable, if any. */
    int invokeCommand)		/* Non-zero means invoked -command option to
				 * notify of new value, 0 means don't. */
{
    value = TkRoundValueToResolution(scalePtr, value);
    value = TkRoundToResolution(scalePtr, value);
    if ((value < scalePtr->fromValue)
	    ^ (scalePtr->toValue < scalePtr->fromValue)) {
	value = scalePtr->fromValue;
    }
    if ((value > scalePtr->toValue)
	    ^ (scalePtr->toValue < scalePtr->fromValue)) {
	value = scalePtr->toValue;
1481
1482
1483
1484
1485
1486
1487
1488

1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316


1317


1318
1319

1320
1321
1322
1323
1324
1325
1326
1327







-
+




-
-
+
-
-


-
+







 *	Other write traces on the variable will trigger.
 *
 *--------------------------------------------------------------
 */

static void
ScaleSetVariable(
    TkScale *scalePtr)	/* Info about widget. */
    register TkScale *scalePtr)	/* Info about widget. */
{
    if (scalePtr->varNamePtr != NULL) {
	char string[TCL_DOUBLE_SPACE];

        if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
                scalePtr->value) < 0) {
	sprintf(string, scalePtr->format, scalePtr->value);
            string[TCL_DOUBLE_SPACE - 1] = '\0';
        }
	scalePtr->flags |= SETTING_VAR;
	Tcl_ObjSetVar2(scalePtr->interp, scalePtr->varNamePtr, NULL,
		Tcl_NewStringObj(string, TCL_INDEX_NONE), TCL_GLOBAL_ONLY);
		Tcl_NewStringObj(string, -1), TCL_GLOBAL_ONLY);
	scalePtr->flags &= ~SETTING_VAR;
    }
}

/*
 *----------------------------------------------------------------------
 *
1517
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

double
TkScalePixelToValue(
    TkScale *scalePtr,	/* Information about widget. */
    register TkScale *scalePtr,	/* Information about widget. */
    int x, int y)		/* Coordinates of point within window. */
{
    double value, pixelRange;

    if (scalePtr->orient == ORIENT_VERTICAL) {
	pixelRange = Tk_Height(scalePtr->tkwin) - scalePtr->sliderLength
		- 2*scalePtr->inset - 2*scalePtr->borderWidth;
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385
1386







-
+







	value = 0;
    }
    if (value > 1) {
	value = 1;
    }
    value = scalePtr->fromValue +
		value * (scalePtr->toValue - scalePtr->fromValue);
    return TkRoundValueToResolution(scalePtr, value);
    return TkRoundToResolution(scalePtr, value);
}

/*
 *----------------------------------------------------------------------
 *
 * TkScaleValueToPixel --
 *
1575
1576
1577
1578
1579
1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596


1597
1598
1599
1600
1601
1602
1603
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415


1416
1417
1418
1419
1420
1421
1422
1423
1424







-
+












-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkScaleValueToPixel(
    TkScale *scalePtr,	/* Information about widget. */
    register TkScale *scalePtr,	/* Information about widget. */
    double value)		/* Reading of the widget. */
{
    int y, pixelRange;
    double valueRange;

    valueRange = scalePtr->toValue - scalePtr->fromValue;
    pixelRange = ((scalePtr->orient == ORIENT_VERTICAL)
	    ? Tk_Height(scalePtr->tkwin) : Tk_Width(scalePtr->tkwin))
	- scalePtr->sliderLength - 2*scalePtr->inset - 2*scalePtr->borderWidth;
    if (valueRange == 0) {
	y = 0;
    } else {
	y = ScaleRound((value - scalePtr->fromValue) * pixelRange
		/ valueRange);
	y = (int) ((value - scalePtr->fromValue) * pixelRange
		/ valueRange + 0.5);
	if (y < 0) {
	    y = 0;
	} else if (y > pixelRange) {
	    y = pixelRange;
	}
    }
    y += scalePtr->sliderLength/2 + scalePtr->inset + scalePtr->borderWidth;

Changes to generic/tkScale.h.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkScale.h --
 *
 *	Declarations of types and functions used to implement the scale
 *	widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 1999-2000 Scriptics Corporation.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright (c) 1999-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKSCALE
#define _TKSCALE
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
69
70
71
72
73
74
75

76
77


78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+

-
-










-
+







				 * display any tick marks. */
    double resolution;		/* If > 0, all values are rounded to an even
				 * multiple of this value. */
    int digits;			/* Number of significant digits to print in
				 * values. 0 means we get to choose the number
				 * based on resolution and/or the range of the
				 * scale. */
    char valueFormat[16];	/* Snprintf conversion specifier computed from
    char format[10];		/* Sprintf conversion specifier computed from
				 * digits and other information. */
    char tickFormat[16];	/* Snprintf conversion specifier computed from
				 * tick interval. */
    double bigIncrement;	/* Amount to use for large increments to scale
				 * value. (0 means we pick a value). */
    char *command;		/* Command prefix to use when invoking Tcl
				 * commands because the scale value changed.
				 * NULL means don't invoke commands. */
    int repeatDelay;		/* How long to wait before auto-repeating on
				 * scrolling actions (in ms). */
    int repeatInterval;		/* Interval between autorepeats (in ms). */
    char *label;		/* Label to display above or to right of
				 * scale; NULL means don't display a label. */
    Tcl_Size labelLength;	/* Number of non-NULL chars. in label. */
    int labelLength;		/* Number of non-NULL chars. in label. */
    enum state state;		/* Values are active, normal, or disabled.
				 * Value of scale cannot be changed when
				 * disabled. */

    /*
     * Information used when displaying widget:
     */
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161







-
+







    int vertLabelX;		/* X-location of origin of label. */

    /*
     * Miscellaneous information:
     */

    int fontHeight;		/* Height of scale font. */
    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    Tcl_Obj *takeFocusPtr;	/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. May be NULL. */
    int flags;			/* Various flags; see below for
				 * definitions. */
} TkScale;

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236

237
238
239
240
241
242
243
210
211
212
213
214
215
216








217
218
219
220
221

222

223
224

225
226
227
228
229
230
231
232







-
-
-
-
-
-
-
-





-
+
-


-
+







/*
 * Space to leave between scale area and text, and between text and edge of
 * window.
 */

#define SPACING 2

/*
 * The tick values are all displayed with the same number of decimal places.
 * This number of decimal places is such that the displayed values are all
 * accurate to within the following proportion of a tick interval.
 */

#define TICK_VALUES_DISPLAY_ACCURACY 0.2

/*
 * Declaration of procedures used in the implementation of the scale widget.
 */

MODULE_SCOPE void	TkEventuallyRedrawScale(TkScale *scalePtr, int what);
MODULE_SCOPE double	TkRoundValueToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE double	TkRoundToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE double	TkRoundIntervalToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE TkScale *	TkpCreateScale(Tk_Window tkwin);
MODULE_SCOPE void	TkpDestroyScale(TkScale *scalePtr);
MODULE_SCOPE void	TkpDisplayScale(void *clientData);
MODULE_SCOPE void	TkpDisplayScale(ClientData clientData);
MODULE_SCOPE int	TkpScaleElement(TkScale *scalePtr, int x, int y);
MODULE_SCOPE void	TkScaleSetValue(TkScale *scalePtr, double value,
			    int setVar, int invokeCommand);
MODULE_SCOPE double	TkScalePixelToValue(TkScale *scalePtr, int x, int y);
MODULE_SCOPE int	TkScaleValueToPixel(TkScale *scalePtr, double value);

#endif /* _TKSCALE */

Changes to generic/tkScrollbar.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







/*
 * tkScrollbar.c --
 *
 *	This module implements a scrollbar widgets for the Tk toolkit. A
 *	scrollbar displays a slider and two arrows; mouse clicks on features
 *	within the scrollbar cause scrolling commands to be invoked.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-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.
 */

#include "tkInt.h"
#include "tkScrollbar.h"
29
30
31
32
33
34
35
36

37
38
39

40
41
42

43
44

45
46
47

48
49
50
51
52

53
54

55
56
57

58
59
60

61
62
63

64
65
66

67
68
69

70
71

72
73

74
75
76

77
78

79
80

81
82

83
84
85

86
87
88

89
90
91

92
93
94
95
96
97
98
99
100

101
102
103



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130


131
132
133
134
135
136
137
29
30
31
32
33
34
35

36
37
38

39
40
41

42
43

44
45
46

47
48
49
50
51

52
53

54
55
56

57
58
59

60
61
62

63
64
65

66
67
68

69
70

71
72

73
74
75

76
77

78
79

80
81

82
83
84

85
86
87

88
89
90

91
92
93
94
95
96
97
98
99

100
101


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129


130
131
132
133
134
135
136
137
138







-
+


-
+


-
+

-
+


-
+




-
+

-
+


-
+


-
+


-
+


-
+


-
+

-
+

-
+


-
+

-
+

-
+

-
+


-
+


-
+


-
+








-
+

-
-
+
+
+




















-
+




-
-
+
+








/*
 * Information used for argv parsing.
 */

static const Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_SCROLLBAR_ACTIVE_BG_COLOR, offsetof(TkScrollbar, activeBorder),
	DEF_SCROLLBAR_ACTIVE_BG_COLOR, Tk_Offset(TkScrollbar, activeBorder),
	TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
	DEF_SCROLLBAR_ACTIVE_BG_MONO, offsetof(TkScrollbar, activeBorder),
	DEF_SCROLLBAR_ACTIVE_BG_MONO, Tk_Offset(TkScrollbar, activeBorder),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_RELIEF, "-activerelief", "activeRelief", "Relief",
	DEF_SCROLLBAR_ACTIVE_RELIEF, offsetof(TkScrollbar, activeRelief), 0, NULL},
	DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(TkScrollbar, activeRelief), 0, NULL},
    {TK_CONFIG_BORDER, "-background", "background", "Background",
	DEF_SCROLLBAR_BG_COLOR, offsetof(TkScrollbar, bgBorder),
	DEF_SCROLLBAR_BG_COLOR, Tk_Offset(TkScrollbar, bgBorder),
	TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_BORDER, "-background", "background", "Background",
	DEF_SCROLLBAR_BG_MONO, offsetof(TkScrollbar, bgBorder),
	DEF_SCROLLBAR_BG_MONO, Tk_Offset(TkScrollbar, bgBorder),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", NULL, NULL, 0, 0, NULL},
    {TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0, NULL},
    {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_SCROLLBAR_BORDER_WIDTH, offsetof(TkScrollbar, borderWidth), 0, NULL},
	DEF_SCROLLBAR_BORDER_WIDTH, Tk_Offset(TkScrollbar, borderWidth), 0, NULL},
    {TK_CONFIG_STRING, "-command", "command", "Command",
	DEF_SCROLLBAR_COMMAND, offsetof(TkScrollbar, command),
	DEF_SCROLLBAR_COMMAND, Tk_Offset(TkScrollbar, command),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_SCROLLBAR_CURSOR, offsetof(TkScrollbar, cursor), TK_CONFIG_NULL_OK, NULL},
	DEF_SCROLLBAR_CURSOR, Tk_Offset(TkScrollbar, cursor), TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth",
	"BorderWidth", DEF_SCROLLBAR_EL_BORDER_WIDTH,
	offsetof(TkScrollbar, elementBorderWidth), 0, NULL},
	Tk_Offset(TkScrollbar, elementBorderWidth), 0, NULL},
    {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG,
	offsetof(TkScrollbar, highlightBgColorPtr), 0, NULL},
	Tk_Offset(TkScrollbar, highlightBgColorPtr), 0, NULL},
    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_SCROLLBAR_HIGHLIGHT,
	offsetof(TkScrollbar, highlightColorPtr), 0, NULL},
	Tk_Offset(TkScrollbar, highlightColorPtr), 0, NULL},
    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness",
	DEF_SCROLLBAR_HIGHLIGHT_WIDTH, offsetof(TkScrollbar, highlightWidth), 0, NULL},
	DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(TkScrollbar, highlightWidth), 0, NULL},
    {TK_CONFIG_BOOLEAN, "-jump", "jump", "Jump",
	DEF_SCROLLBAR_JUMP, offsetof(TkScrollbar, jump), 0, NULL},
	DEF_SCROLLBAR_JUMP, Tk_Offset(TkScrollbar, jump), 0, NULL},
    {TK_CONFIG_CUSTOM, "-orient", "orient", "Orient",
	DEF_SCROLLBAR_ORIENT, offsetof(TkScrollbar, vertical), 0,
	DEF_SCROLLBAR_ORIENT, Tk_Offset(TkScrollbar, vertical), 0,
	&orientOption},
    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
	DEF_SCROLLBAR_RELIEF, offsetof(TkScrollbar, relief), 0, NULL},
	DEF_SCROLLBAR_RELIEF, Tk_Offset(TkScrollbar, relief), 0, NULL},
    {TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
	DEF_SCROLLBAR_REPEAT_DELAY, offsetof(TkScrollbar, repeatDelay), 0, NULL},
	DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(TkScrollbar, repeatDelay), 0, NULL},
    {TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
	DEF_SCROLLBAR_REPEAT_INTERVAL, offsetof(TkScrollbar, repeatInterval), 0, NULL},
	DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(TkScrollbar, repeatInterval), 0, NULL},
    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_SCROLLBAR_TAKE_FOCUS, offsetof(TkScrollbar, takeFocus),
	DEF_SCROLLBAR_TAKE_FOCUS, Tk_Offset(TkScrollbar, takeFocus),
	TK_CONFIG_NULL_OK, NULL},
    {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
	DEF_SCROLLBAR_TROUGH_COLOR, offsetof(TkScrollbar, troughColorPtr),
	DEF_SCROLLBAR_TROUGH_COLOR, Tk_Offset(TkScrollbar, troughColorPtr),
	TK_CONFIG_COLOR_ONLY, NULL},
    {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
	DEF_SCROLLBAR_TROUGH_MONO, offsetof(TkScrollbar, troughColorPtr),
	DEF_SCROLLBAR_TROUGH_MONO, Tk_Offset(TkScrollbar, troughColorPtr),
	TK_CONFIG_MONO_ONLY, NULL},
    {TK_CONFIG_PIXELS, "-width", "width", "Width",
	tkDefScrollbarWidth, offsetof(TkScrollbar, width), 0, NULL},
	tkDefScrollbarWidth, Tk_Offset(TkScrollbar, width), 0, NULL},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};

/*
 * Forward declarations for functions defined later in this file:
 */

static int		ConfigureScrollbar(Tcl_Interp *interp,
			    TkScrollbar *scrollPtr, Tcl_Size objc,
			    TkScrollbar *scrollPtr, int objc,
			    Tcl_Obj *const objv[], int flags);
static void		ScrollbarCmdDeletedProc(void *clientData);
static Tcl_ObjCmdProc ScrollbarWidgetObjCmd;
static void		ScrollbarCmdDeletedProc(ClientData clientData);
static int		ScrollbarWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *, int objc, Tcl_Obj *const objv[]);

/*
 *--------------------------------------------------------------
 *
 * Tk_ScrollbarObjCmd --
 *
 *	This function is invoked to process the "scrollbar" Tcl command. See
 *	the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_ScrollbarObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    TkScrollbar *scrollPtr;
    Tk_Window tkwin = clientData;
    register TkScrollbar *scrollPtr;
    Tk_Window newWin;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

174
175
176
177
178
179
180






181
182
183

184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206







+
+
+
+
+
+


-
+








-
+







    scrollPtr->inset = 0;
    scrollPtr->elementBorderWidth = -1;
    scrollPtr->arrowLength = 0;
    scrollPtr->sliderFirst = 0;
    scrollPtr->sliderLast = 0;
    scrollPtr->activeField = 0;
    scrollPtr->activeRelief = TK_RELIEF_RAISED;
#ifndef TK_NO_DEPRECATED
    scrollPtr->totalUnits = 0;
    scrollPtr->windowUnits = 0;
    scrollPtr->firstUnit = 0;
    scrollPtr->lastUnit = 0;
#endif /* TK_NO_DEPRECATED */
    scrollPtr->firstFraction = 0.0;
    scrollPtr->lastFraction = 0.0;
    scrollPtr->cursor = NULL;
    scrollPtr->cursor = None;
    scrollPtr->takeFocus = NULL;
    scrollPtr->flags = 0;

    if (ConfigureScrollbar(interp, scrollPtr, objc-2, objv+2, 0) != TCL_OK) {
	Tk_DestroyWindow(scrollPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(scrollPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(scrollPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * ScrollbarWidgetObjCmd --
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223



224
225
226
227
228
229
230
216
217
218
219
220
221
222

223
224
225
226
227



228
229
230
231
232
233
234
235
236
237







-
+




-
-
-
+
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
ScrollbarWidgetObjCmd(
    void *clientData,	/* Information about scrollbar widget. */
    ClientData clientData,	/* Information about scrollbar widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    int result = TCL_OK, cmdIndex, length;
    Tcl_Size len;
    register TkScrollbar *scrollPtr = clientData;
    int result = TCL_OK;
    int length, cmdIndex;
    static const char *const commandNames[] = {
        "activate", "cget", "configure", "delta", "fraction",
        "get", "identify", "set", NULL
    };
    enum command {
        COMMAND_ACTIVATE, COMMAND_CGET, COMMAND_CONFIGURE, COMMAND_DELTA,
        COMMAND_FRACTION, COMMAND_GET, COMMAND_IDENTIFY, COMMAND_SET
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267

268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295

296
297
298

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
260
261
262
263
264
265
266

267
268
269
270
271
272
273

274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297
298
299
300
301

302
303
304

305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320







-
+






-
+





-
+















-
+





-
+


-
+







-
+







	    const char *zone = "";

	    switch (scrollPtr->activeField) {
	    case TOP_ARROW:	zone = "arrow1"; break;
	    case SLIDER:	zone = "slider"; break;
	    case BOTTOM_ARROW:	zone = "arrow2"; break;
	    }
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
	    goto done;
	}
	if (objc != 3) {
		Tcl_WrongNumArgs(interp, 1, objv, "activate element");
	    goto error;
	}
	c = Tcl_GetStringFromObj(objv[2], &len)[0];
	c = Tcl_GetStringFromObj(objv[2], &length)[0];
	oldActiveField = scrollPtr->activeField;
	if ((c == 'a') && (strcmp(Tcl_GetString(objv[2]), "arrow1") == 0)) {
	    scrollPtr->activeField = TOP_ARROW;
	} else if ((c == 'a') && (strcmp(Tcl_GetString(objv[2]), "arrow2") == 0)) {
	    scrollPtr->activeField = BOTTOM_ARROW;
	} else if ((c == 's') && (strncmp(Tcl_GetString(objv[2]), "slider", len) == 0)) {
	} else if ((c == 's') && (strncmp(Tcl_GetString(objv[2]), "slider", length) == 0)) {
	    scrollPtr->activeField = SLIDER;
	} else {
	    scrollPtr->activeField = OUTSIDE;
	}
	if (oldActiveField != scrollPtr->activeField) {
	    TkScrollbarEventuallyRedraw(scrollPtr);
	}
	break;
    }
    case COMMAND_CGET: {
	if (objc != 3) {
		Tcl_WrongNumArgs(interp, 1, objv, "cget option");
	    goto error;
	}
	result = Tk_ConfigureValue(interp, scrollPtr->tkwin,
		configSpecs, scrollPtr, Tcl_GetString(objv[2]), 0);
		configSpecs, (char *) scrollPtr, Tcl_GetString(objv[2]), 0);
	break;
    }
    case COMMAND_CONFIGURE: {
	if (objc == 2) {
	    result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
		    configSpecs, scrollPtr, NULL, 0);
		    configSpecs, (char *) scrollPtr, NULL, 0);
	} else if (objc == 3) {
	    result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
		    configSpecs, scrollPtr, Tcl_GetString(objv[2]), 0);
		    configSpecs, (char *) scrollPtr, Tcl_GetString(objv[2]), 0);
	} else {
	    result = ConfigureScrollbar(interp, scrollPtr, objc-2,
		    objv+2, TK_CONFIG_ARGV_ONLY);
	}
	break;
    }
    case COMMAND_DELTA: {
	int xDelta, yDelta, pixels;
	int xDelta, yDelta, pixels, length;
	double fraction;

	if (objc != 4) {
		Tcl_WrongNumArgs(interp, 1, objv, "delta xDelta yDelta");
	    goto error;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &xDelta) != TCL_OK)
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349







-
+







	} else {
	    fraction = ((double) pixels / (double) length);
	}
	Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fraction));
	break;
    }
    case COMMAND_FRACTION: {
	int x, y, pos;
	int x, y, pos, length;
	double fraction;

	if (objc != 4) {
		Tcl_WrongNumArgs(interp, 1, objv, "fraction x y");
	    goto error;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
368
369
370
371
372
373
374



375
376
377












378
379
380
381
382
383
384
375
376
377
378
379
380
381
382
383
384



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403







+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







    case COMMAND_GET: {
	Tcl_Obj *resObjs[4];

	if (objc != 2) {
		Tcl_WrongNumArgs(interp, 1, objv, "get");
	    goto error;
	}
#ifndef TK_NO_DEPRECATED
	if (scrollPtr->flags & NEW_STYLE_COMMANDS) {
#endif /* TK_NO_DEPRECATED */
	resObjs[0] = Tcl_NewDoubleObj(scrollPtr->firstFraction);
	resObjs[1] = Tcl_NewDoubleObj(scrollPtr->lastFraction);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, resObjs));
	    resObjs[0] = Tcl_NewDoubleObj(scrollPtr->firstFraction);
	    resObjs[1] = Tcl_NewDoubleObj(scrollPtr->lastFraction);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, resObjs));
#ifndef TK_NO_DEPRECATED
	} else {
	    resObjs[0] = Tcl_NewIntObj(scrollPtr->totalUnits);
	    resObjs[1] = Tcl_NewIntObj(scrollPtr->windowUnits);
	    resObjs[2] = Tcl_NewIntObj(scrollPtr->firstUnit);
	    resObjs[3] = Tcl_NewIntObj(scrollPtr->lastUnit);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, resObjs));
	}
#endif /* TK_NO_DEPRECATED */
	break;
    }
    case COMMAND_IDENTIFY: {
	int x, y;
	const char *zone = "";

	if (objc != 4) {
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425







-
+







	switch (TkpScrollbarPosition(scrollPtr, x, y)) {
	case TOP_ARROW:		zone = "arrow1";  break;
	case TOP_GAP:		zone = "trough1"; break;
	case SLIDER:		zone = "slider";  break;
	case BOTTOM_GAP:	zone = "trough2"; break;
	case BOTTOM_ARROW:	zone = "arrow2";  break;
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
	break;
    }
    case COMMAND_SET: {
	if (objc == 4) {
	    double first, last;

	    if (Tcl_GetDoubleFromObj(interp, objv[2], &first) != TCL_OK) {
419
420
421
422
423
424
425










































426
427
428
429
430
431
432
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	    if (last < scrollPtr->firstFraction) {
		scrollPtr->lastFraction = scrollPtr->firstFraction;
	    } else if (last > 1.0) {
		scrollPtr->lastFraction = 1.0;
	    } else {
		scrollPtr->lastFraction = last;
	    }
#ifndef TK_NO_DEPRECATED
	    scrollPtr->flags |= NEW_STYLE_COMMANDS;
	} else if (objc == 6) {
	    int totalUnits, windowUnits, firstUnit, lastUnit;
	    if (Tcl_GetIntFromObj(interp, objv[2], &totalUnits) != TCL_OK) {
		goto error;
	    }
	    if (totalUnits < 0) {
		totalUnits = 0;
	    }
	    if (Tcl_GetIntFromObj(interp, objv[3], &windowUnits) != TCL_OK) {
		goto error;
	    }
	    if (windowUnits < 0) {
		windowUnits = 0;
	    }
	    if (Tcl_GetIntFromObj(interp, objv[4], &firstUnit) != TCL_OK) {
		goto error;
	    }
	    if (Tcl_GetIntFromObj(interp, objv[5], &lastUnit) != TCL_OK) {
		goto error;
	    }
	    if (totalUnits > 0) {
		if (lastUnit < firstUnit) {
		    lastUnit = firstUnit;
		}
	    } else {
		firstUnit = lastUnit = 0;
	    }
	    scrollPtr->totalUnits = totalUnits;
	    scrollPtr->windowUnits = windowUnits;
	    scrollPtr->firstUnit = firstUnit;
	    scrollPtr->lastUnit = lastUnit;
	    if (scrollPtr->totalUnits == 0) {
		scrollPtr->firstFraction = 0.0;
		scrollPtr->lastFraction = 1.0;
	    } else {
		scrollPtr->firstFraction = ((double) firstUnit)/totalUnits;
		scrollPtr->lastFraction = ((double) (lastUnit+1))/totalUnits;
	    }
	    scrollPtr->flags &= ~NEW_STYLE_COMMANDS;
#endif /* !TK_NO_DEPRECATED */
	} else {
		Tcl_WrongNumArgs(interp, 1, objv, "set firstFraction lastFraction");
	    goto error;
	}
	TkpComputeScrollbarGeometry(scrollPtr);
	TkScrollbarEventuallyRedraw(scrollPtr);
	break;
461
462
463
464
465
466
467
468

469
470
471

472
473
474
475
476

477
478
479
480
481
482
483
522
523
524
525
526
527
528

529
530
531

532
533
534
535
536

537
538
539
540
541
542
543
544







-
+


-
+




-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureScrollbar(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkScrollbar *scrollPtr,
    register TkScrollbar *scrollPtr,
				/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of valid entries in argv. */
    int objc,			/* Number of valid entries in argv. */
    Tcl_Obj *const objv[],		/* Arguments. */
    int flags)			/* Flags to pass to Tk_ConfigureWidget. */
{
    if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, configSpecs, objc,
	    objv, scrollPtr, flags) != TCL_OK) {
	    (const char **)objv, (char *) scrollPtr, flags|TK_CONFIG_OBJS) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * A few options need special processing, such as setting the background
     * from a 3-D border.
     */
521
522
523
524
525
526
527
528

529
530
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
582
583
584
585
586
587
588

589
590
591

592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618







-
+


-
+


















-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

void
TkScrollbarEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    TkScrollbar *scrollPtr = clientData;

    if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
	TkScrollbarEventuallyRedraw(scrollPtr);
    } else if (eventPtr->type == DestroyNotify) {
	TkpDestroyScrollbar(scrollPtr);
	if (scrollPtr->tkwin != NULL) {
	    scrollPtr->tkwin = NULL;
	    Tcl_DeleteCommandFromToken(scrollPtr->interp,
		    scrollPtr->widgetCmd);
	}
	if (scrollPtr->flags & REDRAW_PENDING) {
	    Tcl_CancelIdleCall(TkpDisplayScrollbar, scrollPtr);
	}
	/*
	 * Free up all the stuff that requires special handling, then let
	 * Tk_FreeOptions handle all the standard option-related stuff.
	 */

	Tk_FreeOptions(configSpecs, scrollPtr, scrollPtr->display, 0);
	Tk_FreeOptions(configSpecs, (char*) scrollPtr, scrollPtr->display, 0);
	Tcl_EventuallyFree(scrollPtr, TCL_DYNAMIC);
    } else if (eventPtr->type == ConfigureNotify) {
	TkpComputeScrollbarGeometry(scrollPtr);
	TkScrollbarEventuallyRedraw(scrollPtr);
    } else if (eventPtr->type == FocusIn) {
	if (eventPtr->xfocus.detail != NotifyInferior) {
	    scrollPtr->flags |= GOT_FOCUS;
587
588
589
590
591
592
593
594

595
596

597
598
599
600
601
602
603
648
649
650
651
652
653
654

655
656

657
658
659
660
661
662
663
664







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
ScrollbarCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    TkScrollbar *scrollPtr = clientData;
    Tk_Window tkwin = scrollPtr->tkwin;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this function destroys the
     * widget.

Changes to generic/tkScrollbar.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkScrollbar.h --
 *
 *	Declarations of types and functions used to implement the scrollbar
 *	widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKSCROLLBAR
#define _TKSCROLLBAR
89
90
91
92
93
94
95
96

97
98
















99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133







-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
+







    /*
     * Information describing the application related to the scrollbar. This
     * information is provided by the application by invoking the "set" widget
     * command. This information can now be provided in two ways: the "old"
     * form (totalUnits, windowUnits, firstUnit, and lastUnit), or the "new"
     * form (firstFraction and lastFraction). FirstFraction and lastFraction
     * will always be valid, but the old-style information is only valid if
     * the OLD_STYLE_COMMANDS flag is 1.
     * the NEW_STYLE_COMMANDS flag is 0.
     */

#ifndef TK_NO_DEPRECATED
    int totalUnits;		/* Total dimension of application, in units.
				 * Valid only if the NEW_STYLE_COMMANDS flag
				 * isn't set. */
    int windowUnits;		/* Maximum number of units that can be
				 * displayed in the window at once. Valid only
				 * if the NEW_STYLE_COMMANDS flag isn't set. */
    int firstUnit;		/* Number of last unit visible in
				 * application's window. Valid only if the
				 * NEW_STYLE_COMMANDS flag isn't set. */
    int lastUnit;		/* Index of last unit visible in window.
				 * Valid only if the NEW_STYLE_COMMANDS flag
				 * isn't set. */
#else
    int dummy1,dummy2,dummy3,dummy4; /* sizeof(TkScrollbar) should not depend on TK_NO_DEPRECATED */
#endif /* TK_NO_DEPRECATED */
    double firstFraction;	/* Position of first visible thing in window,
				 * specified as a fraction between 0 and
				 * 1.0. */
    double lastFraction;	/* Position of last visible thing in window,
				 * specified as a fraction between 0 and
				 * 1.0. */

    /*
     * Miscellaneous information:
     */

    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    char *takeFocus;		/* Value of -takefocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    int flags;			/* Various flags; see below for
				 * definitions. */
} TkScrollbar;

128
129
130
131
132
133
134
135

136
137
138


139
140
141
142
143



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165

166
167
168
169
170
144
145
146
147
148
149
150

151
152


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183

184
185
186
187
188
189







-
+

-
-
+
+





+
+
+















-
+





-
+





#define BOTTOM_ARROW	5

/*
 * Flag bits for scrollbars:
 *
 * REDRAW_PENDING:		Non-zero means a DoWhenIdle handler has
 *				already been queued to redraw this window.
 * OLD_STYLE_COMMANDS:		Non-zero means the old style of commands
 * NEW_STYLE_COMMANDS:		Non-zero means the new style of commands
 *				should be used to communicate with the widget:
 *				".t yview 40", instead of
 *				".t yview scroll 2 lines", for example.
 *				".t yview scroll 2 lines", instead of
 *				".t yview 40", for example.
 * GOT_FOCUS:			Non-zero means this window has the input
 *				focus.
 */

#define REDRAW_PENDING		1
#ifndef TK_NO_DEPRECATED
#define NEW_STYLE_COMMANDS	2
#endif /* TK_NO_DEPRECATED */
#define GOT_FOCUS		4

/*
 * Declaration of scrollbar class functions structure
 * and default scrollbar width, for use in configSpec.
 */

MODULE_SCOPE const Tk_ClassProcs tkpScrollbarProcs;
MODULE_SCOPE char tkDefScrollbarWidth[TCL_INTEGER_SPACE];

/*
 * Declaration of functions used in the implementation of the scrollbar
 * widget.
 */

MODULE_SCOPE void	TkScrollbarEventProc(void *clientData,
MODULE_SCOPE void	TkScrollbarEventProc(ClientData clientData,
			    XEvent *eventPtr);
MODULE_SCOPE void	TkScrollbarEventuallyRedraw(TkScrollbar *scrollPtr);
MODULE_SCOPE void	TkpComputeScrollbarGeometry(TkScrollbar *scrollPtr);
MODULE_SCOPE TkScrollbar *TkpCreateScrollbar(Tk_Window tkwin);
MODULE_SCOPE void 	TkpDestroyScrollbar(TkScrollbar *scrollPtr);
MODULE_SCOPE void	TkpDisplayScrollbar(void *clientData);
MODULE_SCOPE void	TkpDisplayScrollbar(ClientData clientData);
MODULE_SCOPE void	TkpConfigureScrollbar(TkScrollbar *scrollPtr);
MODULE_SCOPE int	TkpScrollbarPosition(TkScrollbar *scrollPtr,
			    int x, int y);

#endif /* _TKSCROLLBAR */

Changes to generic/tkSelect.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69




70
71
72
73
74
75
76
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16




17
18
19
20
21
22
23
24



25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61




62
63
64
65
66
67
68
69
70
71
72






-
-
+
+








-
-
-
-








-
-
-
+
+
+



-
+



















-
+










-
-
-
-
+
+
+
+







/*
 * tkSelect.c --
 *
 *	This file manages the selection for the Tk toolkit, translating
 *	between the standard X ICCCM conventions and Tcl commands.
 *
 * Copyright © 1990-1993 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-1993 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.
 */

#include "tkInt.h"
#include "tkSelect.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * When a selection handler is set up by invoking "selection handle", one of
 * the following data structures is set up to hold information about the
 * command to invoke and its interpreter.
 */

typedef struct {
    Tcl_Interp *interp;		/* Interpreter in which to invoke command. */
    Tcl_Size cmdLength;		/* # of non-NULL bytes in command. */
    Tcl_Size charOffset;		/* The offset of the next char to retrieve. */
    Tcl_Size byteOffset;	/* The expected byte offset of the next
    int cmdLength;		/* # of non-NULL bytes in command. */
    int charOffset;		/* The offset of the next char to retrieve. */
    int byteOffset;		/* The expected byte offset of the next
				 * chunk. */
    char buffer[4];		/* A buffer to hold part of a UTF character
				 * that is split across chunks. */
    char command[TKFLEXARRAY];		/* Command to invoke. Actual space is
    char command[1];		/* Command to invoke. Actual space is
				 * allocated as large as necessary. This must
				 * be the last entry in the structure. */
} CommandInfo;

/*
 * When selection ownership is claimed with the "selection own" Tcl command,
 * one of the following structures is created to record the Tcl command to be
 * executed when the selection is lost again.
 */

typedef struct LostCommand {
    Tcl_Interp *interp;		/* Interpreter in which to invoke command. */
    Tcl_Obj *cmdObj;		/* Reference to command to invoke. */
} LostCommand;

/*
 * The structure below is used to keep each thread's pending list separate.
 */

typedef struct {
typedef struct ThreadSpecificData {
    TkSelInProgress *pendingPtr;
				/* Topmost search in progress, or NULL if
				 * none. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Forward declarations for functions defined in this file:
 */

static Tcl_Size	HandleTclCommand(void *clientData,
			    Tcl_Size offset, char *buffer, Tcl_Size maxBytes);
static void		LostSelection(void *clientData);
static int		SelGetProc(void *clientData,
static int		HandleTclCommand(ClientData clientData,
			    int offset, char *buffer, int maxBytes);
static void		LostSelection(ClientData clientData);
static int		SelGetProc(ClientData clientData,
			    Tcl_Interp *interp, const char *portion);

/*
 *--------------------------------------------------------------
 *
 * Tk_CreateSelHandler --
 *
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98







-
+







 *	invoked to provide part or all of the selection in the given form. If
 *	there was already a handler declared for the given window, target and
 *	selection type, then it is replaced. Proc should have the following
 *	form:
 *
 *	int
 *	proc(
 *	    void *clientData,
 *	    ClientData clientData,
 *	    int offset,
 *	    char *buffer,
 *	    int maxBytes)
 *	{
 *	}
 *
 *	The clientData argument to proc will be the same as the clientData
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
114
115
116
117
118
119
120

121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149







-
+






-
+













-
+







    Tk_Window tkwin,		/* Token for window. */
    Atom selection,		/* Selection to be handled. */
    Atom target,		/* The kind of selection conversions that can
				 * be handled by proc, e.g. TARGETS or
				 * STRING. */
    Tk_SelectionProc *proc,	/* Function to invoke to convert selection to
				 * type "target". */
    void *clientData,	/* Value to pass to proc. */
    ClientData clientData,	/* Value to pass to proc. */
    Atom format)		/* Format in which the selection information
				 * should be returned to the requestor.
				 * XA_STRING is best by far, but anything
				 * listed in the ICCCM will be tolerated
				 * (blech). */
{
    TkSelHandler *selPtr;
    register TkSelHandler *selPtr;
    TkWindow *winPtr = (TkWindow *) tkwin;

    if (winPtr->dispPtr->multipleAtom == None) {
	TkSelInit(tkwin);
    }

    /*
     * See if there's already a handler for this target and selection on this
     * window. If so, re-use it. If not, create a new one.
     */

    for (selPtr = winPtr->selHandlerList; ; selPtr = selPtr->nextPtr) {
	if (selPtr == NULL) {
	    selPtr = (TkSelHandler *)ckalloc(sizeof(TkSelHandler));
	    selPtr = ckalloc(sizeof(TkSelHandler));
	    selPtr->nextPtr = winPtr->selHandlerList;
	    winPtr->selHandlerList = selPtr;
	    break;
	}
	if ((selPtr->selection == selection) && (selPtr->target == target)) {
	    /*
	     * Special case: when replacing handler created by "selection
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+












-
+







	 * If the user asked for a STRING handler and we understand
	 * UTF8_STRING, we implicitly create a UTF8_STRING handler for them.
	 */

	target = winPtr->dispPtr->utf8Atom;
	for (selPtr = winPtr->selHandlerList; ; selPtr = selPtr->nextPtr) {
	    if (selPtr == NULL) {
		selPtr = (TkSelHandler *)ckalloc(sizeof(TkSelHandler));
		selPtr = ckalloc(sizeof(TkSelHandler));
		selPtr->nextPtr = winPtr->selHandlerList;
		winPtr->selHandlerList = selPtr;
		selPtr->selection = selection;
		selPtr->target = target;
		selPtr->format = target; /* We want UTF8_STRING format */
		selPtr->proc = proc;
		if (selPtr->proc == HandleTclCommand) {
		    /*
		     * The clientData is selection controlled memory, so we
		     * should make a copy for this selPtr.
		     */

		    size_t cmdInfoLen = offsetof(CommandInfo, command) + 1 +
		    unsigned cmdInfoLen = Tk_Offset(CommandInfo, command) + 1 +
			    ((CommandInfo *)clientData)->cmdLength;

		    selPtr->clientData = ckalloc(cmdInfoLen);
		    memcpy(selPtr->clientData, clientData, cmdInfoLen);
		} else {
		    selPtr->clientData = clientData;
		}
239
240
241
242
243
244
245
246
247
248



249
250
251
252
253
254
255
235
236
237
238
239
240
241



242
243
244
245
246
247
248
249
250
251







-
-
-
+
+
+







    Tk_Window tkwin,		/* Token for window. */
    Atom selection,		/* The selection whose handler is to be
				 * removed. */
    Atom target)		/* The target whose selection handler is to be
				 * removed. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkSelHandler *selPtr, *prevPtr;
    TkSelInProgress *ipPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register TkSelHandler *selPtr, *prevPtr;
    register TkSelInProgress *ipPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Find the selection handler to be deleted, or return if it doesn't
     * exist.
     */

350
351
352
353
354
355
356
357

358
359
360

361
362
363
364

365
366
367
368
369
370
371
346
347
348
349
350
351
352

353
354
355

356
357
358
359

360
361
362
363
364
365
366
367







-
+


-
+



-
+








void
Tk_OwnSelection(
    Tk_Window tkwin,		/* Window to become new selection owner. */
    Atom selection,		/* Selection that window should own. */
    Tk_LostSelProc *proc,	/* Function to call when selection is taken
				 * away from tkwin. */
    void *clientData)	/* Arbitrary one-word argument to pass to
    ClientData clientData)	/* Arbitrary one-word argument to pass to
				 * proc. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    TkSelectionInfo *infoPtr;
    Tk_LostSelProc *clearProc = NULL;
    void *clearData = NULL;/* Initialization needed only to prevent
    ClientData clearData = NULL;/* Initialization needed only to prevent
				 * compiler warning. */

    if (dispPtr->multipleAtom == None) {
	TkSelInit(tkwin);
    }
    Tk_MakeWindowExist(tkwin);

382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
378
379
380
381
382
383
384

385
386
387
388
389
390
391
392







-
+







    for (infoPtr = dispPtr->selectionInfoPtr; infoPtr != NULL;
	    infoPtr = infoPtr->nextPtr) {
	if (infoPtr->selection == selection) {
	    break;
	}
    }
    if (infoPtr == NULL) {
	infoPtr = (TkSelectionInfo *)ckalloc(sizeof(TkSelectionInfo));
	infoPtr = ckalloc(sizeof(TkSelectionInfo));
	infoPtr->selection = selection;
	infoPtr->nextPtr = dispPtr->selectionInfoPtr;
	dispPtr->selectionInfoPtr = infoPtr;
    } else if (infoPtr->clearProc != NULL) {
	if (infoPtr->owner != tkwin) {
	    clearProc = infoPtr->clearProc;
	    clearData = infoPtr->clearData;
460
461
462
463
464
465
466
467

468
469
470
471
472
473

474
475
476
477
478
479
480
456
457
458
459
460
461
462

463
464
465
466
467
468

469
470
471
472
473
474
475
476







-
+





-
+







 */

void
Tk_ClearSelection(
    Tk_Window tkwin,		/* Window that selects a display. */
    Atom selection)		/* Selection to be cancelled. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    TkSelectionInfo *infoPtr;
    TkSelectionInfo *prevPtr;
    TkSelectionInfo *nextPtr;
    Tk_LostSelProc *clearProc = NULL;
    void *clearData = NULL;/* Initialization needed only to prevent
    ClientData clearData = NULL;/* Initialization needed only to prevent
				 * compiler warning. */

    if (dispPtr->multipleAtom == None) {
	TkSelInit(tkwin);
    }

    for (infoPtr = dispPtr->selectionInfoPtr, prevPtr = NULL;
520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







 *	The standard X11 protocols are used to retrieve the selection. When it
 *	arrives, it is passed to proc. If the selection is very large, it will
 *	be passed to proc in several pieces. Proc should have the following
 *	structure:
 *
 *	int
 *	proc(
 *	    void *clientData,
 *	    ClientData clientData,
 *	    Tcl_Interp *interp,
 *	    char *portion)
 *	{
 *	}
 *
 *	The interp and clientData arguments to proc will be the same as the
 *	corresponding arguments to Tk_GetSelection. The portion argument
551
552
553
554
555
556
557
558

559
560
561
562
563

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585


586
587
588
589
590
591
592
593
594
595
596
597
598
599
600



601
602
603
604
605
606
607
608
609
610
611
547
548
549
550
551
552
553

554
555
556
557
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579


580
581

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600


601
602
603
604
605
606
607







-
+




-
+




















-
-
+
+
-














+
+
+


-
-







				 * selection (determines display from which to
				 * retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection is to be
				 * returned. */
    Tk_GetSelProc *proc,	/* Function to call to process the selection,
				 * once it has been retrieved. */
    void *clientData)	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    TkSelectionInfo *infoPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (dispPtr->multipleAtom == None) {
	TkSelInit(tkwin);
    }

    /*
     * If the selection is owned by a window managed by this process, then
     * call the retrieval function directly, rather than going through the X
     * server (it's dangerous to go through the X server in this case because
     * it could result in deadlock if an INCR-style selection results).
     */

    for (infoPtr = dispPtr->selectionInfoPtr; infoPtr != NULL;
	    infoPtr = infoPtr->nextPtr) {
	if (infoPtr->selection == selection) {
	    break;
	}
    }
    if (infoPtr != NULL) {
	TkSelHandler *selPtr;
	Tcl_Size offset, count;
	register TkSelHandler *selPtr;
	int offset, result, count;
	int result;
	char buffer[TK_SEL_BYTES_AT_ONCE+1];
	TkSelInProgress ip;

	for (selPtr = ((TkWindow *) infoPtr->owner)->selHandlerList;
		selPtr != NULL; selPtr = selPtr->nextPtr) {
	    if (selPtr->target==target && selPtr->selection==selection) {
		break;
	    }
	}
	if (selPtr == NULL) {
	    Atom type;

	    count = TkSelDefaultSelection(infoPtr, target, buffer,
		    TK_SEL_BYTES_AT_ONCE, &type);
	    if (count > TK_SEL_BYTES_AT_ONCE) {
		Tcl_Panic("selection handler returned too many bytes");
	    }
	    if (count < 0) {
		goto cantget;
	    } else if (count > TK_SEL_BYTES_AT_ONCE) {
		Tcl_Panic("selection handler returned too many bytes");
	    }
	    buffer[count] = 0;
	    result = proc(clientData, interp, buffer);
	} else {
	    offset = 0;
	    result = TCL_OK;
	    ip.selPtr = selPtr;
664
665
666
667
668
669
670
671

672
673
674
675
676
677

678
679
680
681
682
683

684
685
686
687
688
689
690
660
661
662
663
664
665
666

667
668
669
670
671
672

673
674
675
676
677
678

679
680
681
682
683
684
685
686







-
+





-
+





-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_SelectionObjCmd(
    void *clientData,	/* Main window associated with
    ClientData clientData,	/* Main window associated with
				 * interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    const char *path = NULL;
    Atom selection;
    const char *selName = NULL;
    const char *string;
    int count, index;
    Tcl_Obj *const *objs;
    Tcl_Obj **objs;
    static const char *const optionStrings[] = {
	"clear", "get", "handle", "own", NULL
    };
    enum options {
	SELECTION_CLEAR, SELECTION_GET, SELECTION_HANDLE, SELECTION_OWN
    };

702
703
704
705
706
707
708
709

710
711
712
713
714
715
716
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712







-
+







    case SELECTION_CLEAR: {
	static const char *const clearOptionStrings[] = {
	    "-displayof", "-selection", NULL
	};
	enum clearOptions { CLEAR_DISPLAYOF, CLEAR_SELECTION };
	int clearIndex;

	for (count = objc-2, objs = objv+2; count > 0;
	for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count > 0;
		count-=2, objs+=2) {
	    string = Tcl_GetString(objs[0]);
	    if (string[0] != '-') {
		break;
	    }
	    if (count < 2) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
830
831
832
833
834
835
836
837
838


839
840
841
842
843
844
845
826
827
828
829
830
831
832


833
834
835
836
837
838
839
840
841







-
-
+
+







	return result;
    }

    case SELECTION_HANDLE: {
	Atom target, format;
	const char *targetName = NULL;
	const char *formatName = NULL;
	CommandInfo *cmdInfoPtr;
	Tcl_Size cmdLength;
	register CommandInfo *cmdInfoPtr;
	int cmdLength;
	static const char *const handleOptionStrings[] = {
	    "-format", "-selection", "-type", NULL
	};
	enum handleOptions {
	    HANDLE_FORMAT, HANDLE_SELECTION, HANDLE_TYPE
	};
	int handleIndex;
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

927
928
929
930
931
932
933
900
901
902
903
904
905
906

907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922
923
924
925
926
927
928
929







-
+














-
+







	} else {
	    format = XA_STRING;
	}
	string = Tcl_GetStringFromObj(objs[1], &cmdLength);
	if (cmdLength == 0) {
	    Tk_DeleteSelHandler(tkwin, selection, target);
	} else {
	    cmdInfoPtr = (CommandInfo *)ckalloc(offsetof(CommandInfo, command)
	    cmdInfoPtr = ckalloc(Tk_Offset(CommandInfo, command)
		    + 1 + cmdLength);
	    cmdInfoPtr->interp = interp;
	    cmdInfoPtr->charOffset = 0;
	    cmdInfoPtr->byteOffset = 0;
	    cmdInfoPtr->buffer[0] = '\0';
	    cmdInfoPtr->cmdLength = cmdLength;
	    memcpy(cmdInfoPtr->command, string, cmdLength + 1);
	    Tk_CreateSelHandler(tkwin, selection, target, HandleTclCommand,
		    cmdInfoPtr, format);
	}
	return TCL_OK;
    }

    case SELECTION_OWN: {
	LostCommand *lostPtr;
	register LostCommand *lostPtr;
	Tcl_Obj *commandObj = NULL;
	static const char *const ownOptionStrings[] = {
	    "-command", "-displayof", "-selection", NULL
	};
	enum ownOptions { OWN_COMMAND, OWN_DISPLAYOF, OWN_SELECTION };
	int ownIndex;

992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018







-
+















-
+








	    /*
	     * Ignore the internal clipboard window.
	     */

	    if ((infoPtr != NULL)
		    && (infoPtr->owner != winPtr->dispPtr->clipWindow)) {
		Tcl_SetObjResult(interp, Tk_NewWindowObj(infoPtr->owner));
		Tcl_SetObjResult(interp, TkNewWindowObj(infoPtr->owner));
	    }
	    return TCL_OK;
	}

	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objs[0]), tkwin);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	if (count == 2) {
	    commandObj = objs[1];
	}
	if (commandObj == NULL) {
	    Tk_OwnSelection(tkwin, selection, NULL, NULL);
	    return TCL_OK;
	}
	lostPtr = (LostCommand *)ckalloc(sizeof(LostCommand));
	lostPtr = ckalloc(sizeof(LostCommand));
	lostPtr->interp = interp;
	lostPtr->cmdObj = commandObj;
	Tcl_IncrRefCount(commandObj);
	Tk_OwnSelection(tkwin, selection, LostSelection, lostPtr);
	return TCL_OK;
    }
    }
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1050







-
+







 *
 *----------------------------------------------------------------------
 */

TkSelInProgress *
TkSelGetInProgress(void)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    return tsdPtr->pendingPtr;
}

/*
 *----------------------------------------------------------------------
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077







-
+







 *
 *----------------------------------------------------------------------
 */
void
TkSelSetInProgress(
    TkSelInProgress *pendingPtr)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    tsdPtr->pendingPtr = pendingPtr;
}

/*
 *----------------------------------------------------------------------
1092
1093
1094
1095
1096
1097
1098
1099

1100
1101
1102


1103
1104

1105
1106
1107
1108
1109
1110
1111
1088
1089
1090
1091
1092
1093
1094

1095
1096


1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1107







-
+

-
-
+
+

-
+







 *	Frees up memory associated with the selection.
 *
 *----------------------------------------------------------------------
 */

void
TkSelDeadWindow(
    TkWindow *winPtr)	/* Window that's being deleted. */
    register TkWindow *winPtr)	/* Window that's being deleted. */
{
    TkSelHandler *selPtr;
    TkSelInProgress *ipPtr;
    register TkSelHandler *selPtr;
    register TkSelInProgress *ipPtr;
    TkSelectionInfo *infoPtr, *prevPtr, *nextPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * While deleting all the handlers, be careful to check whether
     * ConvertSelection or TkSelPropProc are about to process one of the
     * deleted handlers.
     */
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1166
1167
1168
1169
1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187

1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200







-
+














-





-
+







 */

void
TkSelInit(
    Tk_Window tkwin)		/* Window token (used to find display to
				 * initialize). */
{
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    register TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    /*
     * Fetch commonly-used atoms.
     */

    dispPtr->multipleAtom	= Tk_InternAtom(tkwin, "MULTIPLE");
    dispPtr->incrAtom		= Tk_InternAtom(tkwin, "INCR");
    dispPtr->targetsAtom	= Tk_InternAtom(tkwin, "TARGETS");
    dispPtr->timestampAtom	= Tk_InternAtom(tkwin, "TIMESTAMP");
    dispPtr->textAtom		= Tk_InternAtom(tkwin, "TEXT");
    dispPtr->compoundTextAtom	= Tk_InternAtom(tkwin, "COMPOUND_TEXT");
    dispPtr->applicationAtom	= Tk_InternAtom(tkwin, "TK_APPLICATION");
    dispPtr->windowAtom		= Tk_InternAtom(tkwin, "TK_WINDOW");
    dispPtr->clipboardAtom	= Tk_InternAtom(tkwin, "CLIPBOARD");
    dispPtr->atomPairAtom	= Tk_InternAtom(tkwin, "ATOM_PAIR");

    /*
     * Using UTF8_STRING instead of the XA_UTF8_STRING macro allows us to
     * support older X servers that didn't have UTF8_STRING yet. This is
     * necessary on Unix systems. For more information, see:
     *	  https://www.cl.cam.ac.uk/~mgk25/unicode.html#x11
     *	  http://www.cl.cam.ac.uk/~mgk25/unicode.html#x11
     */

#if !defined(_WIN32)
    dispPtr->utf8Atom		= Tk_InternAtom(tkwin, "UTF8_STRING");
#else
    dispPtr->utf8Atom		= (Atom) 0;
#endif
1221
1222
1223
1224
1225
1226
1227
1228

1229
1230

1231
1232
1233
1234
1235
1236
1237
1216
1217
1218
1219
1220
1221
1222

1223
1224

1225
1226
1227
1228
1229
1230
1231
1232







-
+

-
+







 *
 *----------------------------------------------------------------------
 */

void
TkSelClearSelection(
    Tk_Window tkwin,		/* Window for which event was targeted. */
    XEvent *eventPtr)	/* X SelectionClear event. */
    register XEvent *eventPtr)	/* X SelectionClear event. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    TkSelectionInfo *infoPtr;
    TkSelectionInfo *prevPtr;

    /*
     * Invoke clear function for window that just lost the selection. This
     * code is a bit tricky, because any callbacks due to selection changes
1246
1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255







-
+







	if (infoPtr->selection == eventPtr->xselectionclear.selection) {
	    break;
	}
	prevPtr = infoPtr;
    }

    if (infoPtr != NULL && (infoPtr->owner == tkwin) &&
	    (eventPtr->xselectionclear.serial >= (unsigned long) infoPtr->serial)) {
	    (eventPtr->xselectionclear.serial >= (unsigned) infoPtr->serial)) {
	if (prevPtr == NULL) {
	    dispPtr->selectionInfoPtr = infoPtr->nextPtr;
	} else {
	    prevPtr->nextPtr = infoPtr->nextPtr;
	}

	/*
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294

1295
1296

1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289

1290
1291

1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303







+


-
+

-
+



-
+







 * Side effects:
 *	Bytes get appended to the dynamic string pointed to by the clientData
 *	argument.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
SelGetProc(
    void *clientData,	/* Dynamic string holding partially assembled
    ClientData clientData,	/* Dynamic string holding partially assembled
				 * selection. */
    TCL_UNUSED(Tcl_Interp *),	/* Interpreter used for error reporting (not
    Tcl_Interp *interp,		/* Interpreter used for error reporting (not
				 * used). */
    const char *portion)	/* New information to be appended. */
{
    Tcl_DStringAppend((Tcl_DString *)clientData, portion, TCL_INDEX_NONE);
    Tcl_DStringAppend(clientData, portion, -1);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * HandleTclCommand --
1317
1318
1319
1320
1321
1322
1323
1324

1325
1326
1327


1328
1329
1330

1331
1332
1333


1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344
1345
1346
1313
1314
1315
1316
1317
1318
1319

1320
1321


1322
1323
1324
1325

1326
1327


1328
1329
1330
1331
1332
1333


1334
1335
1336
1337
1338
1339
1340
1341







-
+

-
-
+
+


-
+

-
-
+
+




-
-
+







 *
 * Side effects:
 *	None except for things done by the Tcl command.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
HandleTclCommand(
    void *clientData,	/* Information about command to execute. */
    Tcl_Size offset,			/* Return selection bytes starting at this
    ClientData clientData,	/* Information about command to execute. */
    int offset,			/* Return selection bytes starting at this
				 * offset. */
    char *buffer,		/* Place to store converted selection. */
    Tcl_Size maxBytes)		/* Maximum # of bytes to store at buffer. */
    int maxBytes)		/* Maximum # of bytes to store at buffer. */
{
    CommandInfo *cmdInfoPtr = (CommandInfo *)clientData;
    Tcl_Size length;
    CommandInfo *cmdInfoPtr = clientData;
    int length;
    Tcl_Obj *command;
    const char *string;
    Tcl_Interp *interp = cmdInfoPtr->interp;
    Tcl_InterpState savedState;
    int code;
    Tcl_Size extraBytes, charOffset, numChars, count;
    int extraBytes, charOffset, count, numChars, code;
    const char *p;

    /*
     * We must also protect the interpreter and the command from being deleted
     * too soon.
     */

1368
1369
1370
1371
1372
1373
1374
1375

1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404

1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418

1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435

1436
1437
1438
1439
1440
1441
1442
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388

1389
1390
1391
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401

1402
1403
1404
1405

1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436







-
+


















-
+









-
+


-




-
+





-
+
















-
+







    }

    /*
     * First, generate a command by taking the command string and appending
     * the offset and maximum # of bytes.
     */

    command = Tcl_ObjPrintf("%s %" TCL_SIZE_MODIFIER "d %" TCL_SIZE_MODIFIER "d",
    command = Tcl_ObjPrintf("%s %d %d",
	    cmdInfoPtr->command, charOffset, maxBytes);
    Tcl_IncrRefCount(command);

    /*
     * Execute the command. Be sure to restore the state of the interpreter
     * after executing the command.
     */

    savedState = Tcl_SaveInterpState(interp, TCL_OK);
    code = Tcl_EvalObjEx(interp, command, TCL_EVAL_GLOBAL);
    Tcl_DecrRefCount(command);
    if (code == TCL_OK) {
	/*
	 * TODO: This assumes that bytes are characters; that's not true!
	 */

	string = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &length);
	count = (length > maxBytes) ? maxBytes : length;
	memcpy(buffer, string, count);
	memcpy(buffer, string, (size_t) count);
	buffer[count] = '\0';

	/*
	 * Update the partial character information for the next retrieval if
	 * the command has not been deleted.
	 */

	if (cmdInfoPtr->interp != NULL) {
	    if (length <= maxBytes) {
		cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, TCL_INDEX_NONE);
		cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, -1);
		cmdInfoPtr->buffer[0] = '\0';
	    } else {
		Tcl_UniChar ch = 0;
		p = string;
		string += count;
		numChars = 0;
		while (p < string) {
		    p += Tcl_UtfToUniChar(p, &ch);
		    p = Tcl_UtfNext(p);
		    numChars++;
		}
		cmdInfoPtr->charOffset += numChars;
		length = p - string;
		if (length > 0) {
		    strncpy(cmdInfoPtr->buffer, string, length);
		    strncpy(cmdInfoPtr->buffer, string, (size_t) length);
		}
		cmdInfoPtr->buffer[length] = '\0';
	    }
	    cmdInfoPtr->byteOffset += count + extraBytes;
	}
	count += extraBytes;
    } else {
	/*
	 * Something went wrong. Log errors as background errors, and silently
	 * drop everything else.
	 */

	if (code == TCL_ERROR) {
	    Tcl_AddErrorInfo(interp, "\n    (command handling selection)");
	    Tcl_BackgroundException(interp, code);
	}
	count = TCL_INDEX_NONE;
	count = -1;
    }
    (void) Tcl_RestoreInterpState(interp, savedState);

    Tcl_Release(clientData);
    Tcl_Release(interp);
    return count;
}
1453
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473

1474
1475
1476
1477

1478
1479
1480
1481
1482

1483
1484

1485
1486
1487
1488
1489
1490
1491


1492
1493
1494
1495

1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514

1515
1516

1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1536

1537
1538
1539
1540
1541

1542
1543
1544
1545
1546
1547
1548

1549
1550
1551
1552
1553
1554
1555
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466

1467
1468
1469
1470

1471
1472
1473
1474
1475

1476
1477

1478
1479
1480
1481
1482
1483


1484
1485
1486
1487
1488

1489
1490
1491
1492

1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509

1510
1511
1512
1513
1514
1515
1516

1517
1518
1519
1520
1521

1522
1523
1524
1525
1526
1527
1528
1529

1530
1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541

1542
1543
1544
1545
1546
1547
1548
1549







-
+







-
+




-
+



-
+




-
+

-
+





-
-
+
+



-
+



-
+














-
+

-
+






-
+




-
+







-
+




-
+






-
+







 * Results:
 *	If "target" is a standard target understood by this function, the
 *	selection is converted to that form and stored as a character string
 *	in buffer. The type of the selection (e.g. STRING or ATOM) is stored
 *	in *typePtr, and the return value is a count of the # of non-NULL
 *	bytes at buffer. If the target wasn't understood, or if there isn't
 *	enough space at buffer to hold the entire selection (no INCR-mode
 *	transfers for this stuff!), then TCL_INDEX_NONE is returned.
 *	transfers for this stuff!), then -1 is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_Size
int
TkSelDefaultSelection(
    TkSelectionInfo *infoPtr,	/* Info about selection being retrieved. */
    Atom target,		/* Desired form of selection. */
    char *buffer,		/* Place to put selection characters. */
    Tcl_Size maxBytes,		/* Maximum # of bytes to store at buffer. */
    int maxBytes,		/* Maximum # of bytes to store at buffer. */
    Atom *typePtr)		/* Store here the type of the selection, for
				 * use in converting to proper X format. */
{
    TkWindow *winPtr = (TkWindow *) infoPtr->owner;
    register TkWindow *winPtr = (TkWindow *) infoPtr->owner;
    TkDisplay *dispPtr = winPtr->dispPtr;

    if (target == dispPtr->timestampAtom) {
	if (maxBytes < 20) {
	    return TCL_INDEX_NONE;
	    return -1;
	}
	snprintf(buffer, maxBytes, "0x%x", (unsigned int) infoPtr->time);
	sprintf(buffer, "0x%x", (unsigned int) infoPtr->time);
	*typePtr = XA_INTEGER;
	return strlen(buffer);
    }

    if (target == dispPtr->targetsAtom) {
	TkSelHandler *selPtr;
	Tcl_Size length;
	register TkSelHandler *selPtr;
	int length;
	Tcl_DString ds;

	if (maxBytes < 50) {
	    return TCL_INDEX_NONE;
	    return -1;
	}
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds,
		"MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW", TCL_INDEX_NONE);
		"MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW", -1);
	for (selPtr = winPtr->selHandlerList; selPtr != NULL;
		selPtr = selPtr->nextPtr) {
	    if ((selPtr->selection == infoPtr->selection)
		    && (selPtr->target != dispPtr->applicationAtom)
		    && (selPtr->target != dispPtr->windowAtom)) {
		const char *atomString = Tk_GetAtomName((Tk_Window) winPtr,
			selPtr->target);

		Tcl_DStringAppendElement(&ds, atomString);
	    }
	}
	length = Tcl_DStringLength(&ds);
	if (length >= maxBytes) {
	    Tcl_DStringFree(&ds);
	    return TCL_INDEX_NONE;
	    return -1;
	}
	memcpy(buffer, Tcl_DStringValue(&ds), length + 1);
	memcpy(buffer, Tcl_DStringValue(&ds), (unsigned) (1+length));
	Tcl_DStringFree(&ds);
	*typePtr = XA_ATOM;
	return length;
    }

    if (target == dispPtr->applicationAtom) {
	Tcl_Size length;
	int length;
	Tk_Uid name = winPtr->mainPtr->winPtr->nameUid;

	length = strlen(name);
	if (maxBytes <= length) {
	    return TCL_INDEX_NONE;
	    return -1;
	}
	strcpy(buffer, name);
	*typePtr = XA_STRING;
	return length;
    }

    if (target == dispPtr->windowAtom) {
	Tcl_Size length;
	int length;
	char *name = winPtr->pathName;

	length = strlen(name);
	if (maxBytes <= length) {
	    return TCL_INDEX_NONE;
	    return -1;
	}
	strcpy(buffer, name);
	*typePtr = XA_STRING;
	return length;
    }

    return TCL_INDEX_NONE;
    return -1;
}

/*
 *----------------------------------------------------------------------
 *
 * LostSelection --
 *
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573

1574
1575
1576
1577
1578
1579
1580
1558
1559
1560
1561
1562
1563
1564

1565
1566

1567
1568
1569
1570
1571
1572
1573
1574







-
+

-
+







 *	A Tcl script is executed; it can do almost anything.
 *
 *----------------------------------------------------------------------
 */

static void
LostSelection(
    void *clientData)	/* Pointer to LostCommand structure. */
    ClientData clientData)	/* Pointer to LostCommand structure. */
{
    LostCommand *lostPtr = (LostCommand *)clientData;
    LostCommand *lostPtr = clientData;
    Tcl_Interp *interp = lostPtr->interp;
    Tcl_InterpState savedState;
    int code;

    Tcl_Preserve(interp);

    /*

Changes to generic/tkSelect.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31



32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63






-
+




















-
-
+



-
-
-



-
+



















-
-
+
+







/*
 * tkSelect.h --
 *
 *	Declarations of types shared among the files that implement selection
 *	support.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKSELECT
#define _TKSELECT

/*
 * When a selection is owned by a window on a given display, one of the
 * following structures is present on a list of current selections in the
 * display structure. The structure is used to record the current owner of a
 * selection for use in later retrieval requests. There is a list of such
 * structures because a display can have multiple different selections active
 * at the same time.
 */

typedef struct TkSelectionInfo {
    Atom selection;		/* Selection name, e.g. XA_PRIMARY. */
    Tk_Window owner;		/* Current owner of this selection. */
#if TCL_MAJOR_VERSION > 8
    unsigned long serial;	/* Serial number of last XSelectionSetOwner
    int serial;			/* Serial number of last XSelectionSetOwner
				 * request made to server for this selection
				 * (used to filter out redundant
				 * SelectionClear events). */
#else
    int serial;
#endif
    Time time;			/* Timestamp used to acquire selection. */
    Tk_LostSelProc *clearProc;	/* Procedure to call when owner loses
				 * selection. */
    void *clearData;	/* Info to pass to clearProc. */
    ClientData clearData;	/* Info to pass to clearProc. */
    struct TkSelectionInfo *nextPtr;
				/* Next in list of current selections on this
				 * display. NULL means end of list. */
} TkSelectionInfo;

/*
 * One of the following structures exists for each selection handler created
 * for a window by calling Tk_CreateSelHandler. The handlers are linked in a
 * list rooted in the TkWindow structure.
 */

typedef struct TkSelHandler {
    Atom selection;		/* Selection name, e.g. XA_PRIMARY. */
    Atom target;		/* Target type for selection conversion, such
				 * as TARGETS or STRING. */
    Atom format;		/* Format in which selection info will be
				 * returned, such as STRING or ATOM. */
    Tk_SelectionProc *proc;	/* Procedure to generate selection in this
				 * format. */
    void *clientData;	/* Argument to pass to proc. */
    Tcl_Size size;			/* Size of units returned by proc (8 for
    ClientData clientData;	/* Argument to pass to proc. */
    int size;			/* Size of units returned by proc (8 for
				 * STRING, 32 for almost anything else). */
    struct TkSelHandler *nextPtr;
				/* Next selection handler associated with same
				 * window (NULL for end of list). */
} TkSelHandler;

/*
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87







-
+







    Tcl_Interp *interp;		/* Interpreter for error reporting. */
    TkWindow *winPtr;		/* Window used as requestor for selection. */
    Atom selection;		/* Selection being requested. */
    Atom property;		/* Property where selection will appear. */
    Atom target;		/* Desired form for selection. */
    Tk_GetSelProc *proc;	/* Procedure to call to handle pieces of
				 * selection. */
    void *clientData;	/* Argument for proc. */
    ClientData clientData;	/* Argument for proc. */
    int result;			/* Initially -1. Set to a Tcl return value
				 * once the selection has been retrieved. */
    Tcl_TimerToken timeout;	/* Token for current timeout procedure. */
    int idleTime;		/* Number of seconds that have gone by without
				 * hearing anything from the selection
				 * owner. */
    Tcl_EncodingState encState;	/* Holds intermediate state during translations
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
+







 * CLIPBOARD selection is retrieved. All buffers of a given type on the same
 * clipboard must have the same format. The TkClipboardTarget structure is
 * used to record the information about a chain of buffers of the same type.
 */

typedef struct TkClipboardBuffer {
    char *buffer;		/* Null terminated data buffer. */
    Tcl_Size length;		/* Length of string in buffer. */
    long length;		/* Length of string in buffer. */
    struct TkClipboardBuffer *nextPtr;
				/* Next in list of buffers. NULL means end of
				 * list . */
} TkClipboardBuffer;

typedef struct TkClipboardTarget {
    Atom type;			/* Type conversion supported. */
156
157
158
159
160
161
162
163
164


165
166
167
168
169
170
171
152
153
154
155
156
157
158


159
160
161
162
163
164
165
166
167







-
-
+
+







 * Declarations for procedures that are used by the selection-related files
 * but shouldn't be used anywhere else in Tk (or by Tk clients):
 */

MODULE_SCOPE TkSelInProgress *TkSelGetInProgress(void);
MODULE_SCOPE void	TkSelSetInProgress(TkSelInProgress *pendingPtr);
MODULE_SCOPE void	TkSelClearSelection(Tk_Window tkwin, XEvent *eventPtr);
MODULE_SCOPE Tcl_Size TkSelDefaultSelection(TkSelectionInfo *infoPtr,
			    Atom target, char *buffer, Tcl_Size maxBytes,
MODULE_SCOPE int	TkSelDefaultSelection(TkSelectionInfo *infoPtr,
			    Atom target, char *buffer, int maxBytes,
			    Atom *typePtr);
#ifndef TkSelUpdateClipboard
MODULE_SCOPE void	TkSelUpdateClipboard(TkWindow *winPtr,
			    TkClipboardTarget *targetPtr);
#endif

#endif /* _TKSELECT */

Changes to generic/tkSquare.c.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32









-
+















-







/*
 * tkSquare.c --
 *
 *	This module implements "square" widgets that are object based. A
 *	"square" is a widget that displays a single square that can be moved
 *	around and resized. This file is intended as an example of how to
 *	build a widget; it isn't included in the normal wish, but it is
 *	included in "tktest".
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#if 0
#define __NO_OLD_CONFIG
#endif
#ifndef USE_TCL_STUBS
#   define USE_TCL_STUBS
#endif
#ifndef USE_TK_STUBS
#   define USE_TK_STUBS
#endif
#include "tkInt.h"
#include <stdbool.h>

/*
 * A data structure of the following type is kept for each square widget
 * managed by this file:
 */

typedef struct {
50
51
52
53
54
55
56
57
58


59
60

61
62
63
64
65
66
67
68
69
70

71
72

73
74

75
76
77

78
79
80


81
82
83

84
85
86

87
88

89
90

91
92

93
94
95
96
97
98
99
100

101

102

103
104

105
106


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
49
50
51
52
53
54
55


56
57
58

59
60
61
62
63
64
65
66
67
68

69
70

71
72

73
74
75

76
77


78
79
80
81

82
83
84

85
86

87
88

89
90

91
92
93
94
95
96
97
98

99
100
101

102
103

104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135







-
-
+
+

-
+









-
+

-
+

-
+


-
+

-
-
+
+


-
+


-
+

-
+

-
+

-
+







-
+

+
-
+

-
+

-
+
+




















-
+








    Tcl_Obj *borderWidthPtr;	/* Width of 3-D border around whole widget. */
    Tcl_Obj *bgBorderPtr;
    Tcl_Obj *fgBorderPtr;
    Tcl_Obj *reliefPtr;
    GC gc;			/* Graphics context for copying from
				 * off-screen pixmap onto screen. */
    bool doubleBuffer;	/* true means double-buffer redisplay with
				 * pixmap; false means draw straight onto the
    Tcl_Obj *doubleBufferPtr;	/* Non-zero means double-buffer redisplay with
				 * pixmap; zero means draw straight onto the
				 * display. */
    bool updatePending;		/* true means a call to SquareDisplay has
    int updatePending;		/* Non-zero means a call to SquareDisplay has
				 * already been scheduled. */
} Square;

/*
 * Information used for argv parsing.
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BORDER, "-background", "background", "Background",
	    "#d9d9d9", offsetof(Square, bgBorderPtr), TCL_INDEX_NONE, 0,
	    "#d9d9d9", Tk_Offset(Square, bgBorderPtr), -1, 0,
	    "white", 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0,
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL, 0, -1, 0,
	    "-borderwidth", 0},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0,
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL, 0, -1, 0,
	    "-background", 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	    "2", offsetof(Square, borderWidthPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    "2", Tk_Offset(Square, borderWidthPtr), -1, 0, NULL, 0},
    {TK_OPTION_BOOLEAN, "-dbl", "doubleBuffer", "DoubleBuffer",
	    "1", TCL_INDEX_NONE, offsetof(Square, doubleBuffer), TK_OPTION_VAR(bool) , NULL, 0},
    {TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0,
	    "1", Tk_Offset(Square, doubleBufferPtr), -1, 0 , NULL, 0},
    {TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL, 0, -1, 0,
	    "-foreground", 0},
    {TK_OPTION_BORDER, "-foreground", "foreground", "Foreground",
	    "#b03060", offsetof(Square, fgBorderPtr), TCL_INDEX_NONE, 0,
	    "#b03060", Tk_Offset(Square, fgBorderPtr), -1, 0,
	    "black", 0},
    {TK_OPTION_PIXELS, "-posx", "posx", "PosX", "0",
	    offsetof(Square, xPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    Tk_Offset(Square, xPtr), -1, 0, NULL, 0},
    {TK_OPTION_PIXELS, "-posy", "posy", "PosY", "0",
	    offsetof(Square, yPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    Tk_Offset(Square, yPtr), -1, 0, NULL, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	    "raised", offsetof(Square, reliefPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    "raised", Tk_Offset(Square, reliefPtr), -1, 0, NULL, 0},
    {TK_OPTION_PIXELS, "-size", "size", "Size", "20",
	    offsetof(Square, sizeObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    Tk_Offset(Square, sizeObjPtr), -1, 0, NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
};

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

static void		SquareDeletedProc(void *clientData);
static void		SquareDeletedProc(ClientData clientData);
static int		SquareConfigure(Tcl_Interp *interp, Square *squarePtr);
static void		SquareDestroy(void *memPtr);
static void		SquareDisplay(void *clientData);
static void		SquareDisplay(ClientData clientData);
static void		KeepInWindow(Square *squarePtr);
static void		SquareObjEventProc(void *clientData,
static void		SquareObjEventProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_ObjCmdProc SquareWidgetObjCmd;
static int		SquareWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *, int objc, Tcl_Obj * const objv[]);

/*
 *--------------------------------------------------------------
 *
 * SquareCmd --
 *
 *	This procedure is invoked to process the "square" Tcl command. It
 *	creates a new "square" widget.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	A new widget is created and configured.
 *
 *--------------------------------------------------------------
 */

int
SquareObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* NULL. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Square *squarePtr;
    Tk_Window tkwin;
    Tk_OptionTable optionTable;
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171

172
173
174

175
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171

172
173
174

175
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+








-
+


-
+








-
+








-
+







    optionTable = Tk_CreateOptionTable(interp, optionSpecs);

    /*
     * Allocate and initialize the widget record. The memset allows us to set
     * just the non-NULL/0 items.
     */

    squarePtr = (Square *)ckalloc(sizeof(Square));
    squarePtr = ckalloc(sizeof(Square));
    memset(squarePtr, 0, sizeof(Square));

    squarePtr->tkwin = tkwin;
    squarePtr->display = Tk_Display(tkwin);
    squarePtr->interp = interp;
    squarePtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(squarePtr->tkwin), SquareWidgetObjCmd, squarePtr,
	    SquareDeletedProc);
    squarePtr->gc = NULL;
    squarePtr->gc = None;
    squarePtr->optionTable = optionTable;

    if (Tk_InitOptions(interp, squarePtr, optionTable, tkwin)
    if (Tk_InitOptions(interp, (char *) squarePtr, optionTable, tkwin)
	    != TCL_OK) {
	Tk_DestroyWindow(squarePtr->tkwin);
	ckfree(squarePtr);
	return TCL_ERROR;
    }

    Tk_CreateEventHandler(squarePtr->tkwin, ExposureMask|StructureNotifyMask,
	    SquareObjEventProc, squarePtr);
    if (Tk_SetOptions(interp, squarePtr, optionTable, objc - 2,
    if (Tk_SetOptions(interp, (char *) squarePtr, optionTable, objc - 2,
	    objv + 2, tkwin, NULL, NULL) != TCL_OK) {
	goto error;
    }
    if (SquareConfigure(interp, squarePtr) != TCL_OK) {
	goto error;
    }

    Tcl_SetObjResult(interp,
	    Tcl_NewStringObj(Tk_PathName(squarePtr->tkwin), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tk_PathName(squarePtr->tkwin), -1));
    return TCL_OK;

  error:
    Tk_DestroyWindow(squarePtr->tkwin);
    return TCL_ERROR;
}

213
214
215
216
217
218
219
220

221
222
223
224
225

226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269

270
271
272
273
274
275

276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
214
215
216
217
218
219
220

221
222
223
224
225

226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269

270
271
272
273
274
275

276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







-
+




-
+









-
+
















-
+










-
+





-
+





-
+







-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
SquareWidgetObjCmd(
    void *clientData,	/* Information about square widget. */
    ClientData clientData,	/* Information about square widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj * const objv[])	/* Argument objects. */
{
    Square *squarePtr = (Square *)clientData;
    Square *squarePtr = clientData;
    int result = TCL_OK;
    static const char *const squareOptions[] = {"cget", "configure", NULL};
    enum {
	SQUARE_CGET, SQUARE_CONFIGURE
    };
    Tcl_Obj *resultObjPtr;
    int index;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], squareOptions,
	    sizeof(char *), "command", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Tcl_Preserve(squarePtr);

    switch (index) {
    case SQUARE_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    goto error;
	}
	resultObjPtr = Tk_GetOptionValue(interp, squarePtr,
	resultObjPtr = Tk_GetOptionValue(interp, (char *) squarePtr,
		squarePtr->optionTable, objv[2], squarePtr->tkwin);
	if (resultObjPtr == NULL) {
	    result = TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, resultObjPtr);
	}
	break;
    case SQUARE_CONFIGURE:
	resultObjPtr = NULL;
	if (objc == 2) {
	    resultObjPtr = Tk_GetOptionInfo(interp, squarePtr,
	    resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
		    squarePtr->optionTable, NULL, squarePtr->tkwin);
	    if (resultObjPtr == NULL) {
		result = TCL_ERROR;
	    }
	} else if (objc == 3) {
	    resultObjPtr = Tk_GetOptionInfo(interp, squarePtr,
	    resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
		    squarePtr->optionTable, objv[2], squarePtr->tkwin);
	    if (resultObjPtr == NULL) {
		result = TCL_ERROR;
	    }
	} else {
	    result = Tk_SetOptions(interp, squarePtr,
	    result = Tk_SetOptions(interp, (char *) squarePtr,
		    squarePtr->optionTable, objc - 2, objv + 2,
		    squarePtr->tkwin, NULL, NULL);
	    if (result == TCL_OK) {
		result = SquareConfigure(interp, squarePtr);
	    }
	    if (!squarePtr->updatePending) {
		Tcl_DoWhenIdle(SquareDisplay, squarePtr);
		squarePtr->updatePending = true;
		squarePtr->updatePending = 1;
	    }
	}
	if (resultObjPtr != NULL) {
	    Tcl_SetObjResult(interp, resultObjPtr);
	}
    }
    Tcl_Release(squarePtr);
313
314
315
316
317
318
319
320

321
322
323
324

325
326
327
328
329
330
331
332
333
334

335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364







-
+




+










+
-
+


















-
+







 *	for squarePtr; old resources get freed, if there were any.
 *
 *----------------------------------------------------------------------
 */

static int
SquareConfigure(
    TCL_UNUSED(Tcl_Interp *),		/* Used for error reporting. */
    Tcl_Interp *interp,		/* Used for error reporting. */
    Square *squarePtr)		/* Information about widget. */
{
    int borderWidth;
    Tk_3DBorder bgBorder;
    int doubleBuffer;

    /*
     * Set the background for the window and create a graphics context for use
     * during redisplay.
     */

    bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
	    squarePtr->bgBorderPtr);
    Tk_SetWindowBackground(squarePtr->tkwin,
	    Tk_3DBorderColor(bgBorder)->pixel);
    Tcl_GetBooleanFromObj(NULL, squarePtr->doubleBufferPtr, &doubleBuffer);
    if ((squarePtr->gc == NULL) && squarePtr->doubleBuffer) {
    if ((squarePtr->gc == None) && (doubleBuffer)) {
	XGCValues gcValues;
	gcValues.function = GXcopy;
	gcValues.graphics_exposures = False;
	squarePtr->gc = Tk_GetGC(squarePtr->tkwin,
		GCFunction|GCGraphicsExposures, &gcValues);
    }

    /*
     * Register the desired geometry for the window. Then arrange for the
     * window to be redisplayed.
     */

    Tk_GeometryRequest(squarePtr->tkwin, 200, 150);
    Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
	    &borderWidth);
    Tk_SetInternalBorder(squarePtr->tkwin, borderWidth);
    if (!squarePtr->updatePending) {
	Tcl_DoWhenIdle(SquareDisplay, squarePtr);
	squarePtr->updatePending = true;
	squarePtr->updatePending = 1;
    }
    KeepInWindow(squarePtr);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
373
374
375
376
377
378
379
380

381
382
383

384
385
386
387
388

389
390
391
392
393
394

395
396
397
398

399
400

401
402
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
376
377
378
379
380
381
382

383
384
385

386
387
388
389
390

391
392
393
394
395
396

397
398
399
400

401
402

403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420







-
+


-
+




-
+





-
+



-
+

-
+









-
+







 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
SquareObjEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    Square *squarePtr = (Square *)clientData;
    Square *squarePtr = clientData;

    if (eventPtr->type == Expose) {
	if (!squarePtr->updatePending) {
	    Tcl_DoWhenIdle(SquareDisplay, squarePtr);
	    squarePtr->updatePending = true;
	    squarePtr->updatePending = 1;
	}
    } else if (eventPtr->type == ConfigureNotify) {
	KeepInWindow(squarePtr);
	if (!squarePtr->updatePending) {
	    Tcl_DoWhenIdle(SquareDisplay, squarePtr);
	    squarePtr->updatePending = true;
	    squarePtr->updatePending = 1;
	}
    } else if (eventPtr->type == DestroyNotify) {
	if (squarePtr->tkwin != NULL) {
	    Tk_FreeConfigOptions(squarePtr, squarePtr->optionTable,
	    Tk_FreeConfigOptions((char *) squarePtr, squarePtr->optionTable,
		    squarePtr->tkwin);
	    if (squarePtr->gc != NULL) {
	    if (squarePtr->gc != None) {
		Tk_FreeGC(squarePtr->display, squarePtr->gc);
	    }
	    squarePtr->tkwin = NULL;
	    Tcl_DeleteCommandFromToken(squarePtr->interp,
		    squarePtr->widgetCmd);
	}
	if (squarePtr->updatePending) {
	    Tcl_CancelIdleCall(SquareDisplay, squarePtr);
	}
	Tcl_EventuallyFree(squarePtr, TCL_DYNAMIC);
	Tcl_EventuallyFree(squarePtr, (Tcl_FreeProc *) SquareDestroy);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * SquareDeletedProc --
427
428
429
430
431
432
433
434

435
436

437
438
439
440
441
442
443
430
431
432
433
434
435
436

437
438

439
440
441
442
443
444
445
446







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
SquareDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    Square *squarePtr = (Square *)clientData;
    Square *squarePtr = clientData;
    Tk_Window tkwin = squarePtr->tkwin;

    /*
     * This procedure could be invoked either because the window was destroyed
     * and the command was then deleted (in which case tkwin is NULL) or
     * because the command was deleted, and then this procedure destroys the
     * widget.
464
465
466
467
468
469
470
471

472
473

474
475
476
477
478

479
480

481
482
483
484
485
486
487
488

489

490
491
492
493
494
495
496
467
468
469
470
471
472
473

474
475

476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501







-
+

-
+





+

-
+








+
-
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

static void
SquareDisplay(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    Square *squarePtr = (Square *)clientData;
    Square *squarePtr = clientData;
    Tk_Window tkwin = squarePtr->tkwin;
    Pixmap pm = None;
    Drawable d;
    int borderWidth, size, relief;
    Tk_3DBorder bgBorder, fgBorder;
    int doubleBuffer;

    squarePtr->updatePending = false;
    squarePtr->updatePending = 0;
    if (!Tk_IsMapped(tkwin)) {
	return;
    }

    /*
     * Create a pixmap for double-buffering, if necessary.
     */

    Tcl_GetBooleanFromObj(NULL, squarePtr->doubleBufferPtr, &doubleBuffer);
    if (squarePtr->doubleBuffer) {
    if (doubleBuffer) {
	pm = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),
		Tk_Width(tkwin), Tk_Height(tkwin),
		DefaultDepthOfScreen(Tk_Screen(tkwin)));
	d = pm;
    } else {
	d = Tk_WindowId(tkwin);
    }
517
518
519
520
521
522
523
524

525
526
527
528
529
530



























531
532
533
534
535
536
537
522
523
524
525
526
527
528

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569







-
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    Tk_Fill3DRectangle(tkwin, d, fgBorder, squarePtr->x, squarePtr->y, size,
	    size, borderWidth, TK_RELIEF_RAISED);

    /*
     * If double-buffered, copy to the screen and release the pixmap.
     */

    if (squarePtr->doubleBuffer) {
    if (doubleBuffer) {
	XCopyArea(Tk_Display(tkwin), pm, Tk_WindowId(tkwin), squarePtr->gc,
		0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
		0, 0);
	Tk_FreePixmap(Tk_Display(tkwin), pm);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * SquareDestroy --
 *
 *	This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
 *	clean up the internal structure of a square at a safe time (when
 *	no-one is using it anymore).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the square is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
SquareDestroy(
    void *memPtr)		/* Info about square widget. */
{
    Square *squarePtr = memPtr;

    ckfree(squarePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * KeepInWindow --
 *
 *	Adjust the position of the square if necessary to keep it in the
545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591







-
+







 *	the square in the window.
 *
 *----------------------------------------------------------------------
 */

static void
KeepInWindow(
    Square *squarePtr)	/* Pointer to widget record. */
    register Square *squarePtr)	/* Pointer to widget record. */
{
    int i, bd, relief;
    int borderWidth, size;

    Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
	    &borderWidth);
    Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->xPtr,

Changes to generic/tkStubInit.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43


44
45
46











47
48
49
50
51
52

53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90



91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117









118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150


151
152
153
154














155
156

























157
158
159
160


161
162
163


164
165
166
167
168
169
170
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26



27
28
29
30
31
32
33
34
35
36
37
38
39


40
41
42


43
44
45
46
47
48
49
50
51
52
53
54
55
56

57

58








59

60
61
62
63
64
65
66



67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107



108



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123


124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150




151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198


199
200
201
202
203
204
205
206
207





-
+




















-
-
-






+






-
-
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+



-

-
+
-
-
-
-
-
-
-
-
+
-







-
-
-






-












+
+
+
-
-
+
+


















-
-
-

-
-
-
+
+
+
+
+
+
+
+
+






-
-








-
+
















+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




+
+

-
-
+
+







/*
 * tkStubInit.c --
 *
 *	This file contains the initializers for the Tk stub vectors.
 *
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#if !(defined(_WIN32) || defined(MAC_OSX_TK))
/* UNIX */
#define UNIX_TK
#include "tkUnixInt.h"
#endif

#ifdef _WIN32
#include "tkWinInt.h"
#endif

#if defined(MAC_OSX_TK)
/* we could have used _TKMACINT */
#include "tkMacOSXInt.h"
#include "tkMacOSXPrivate.h"
#else
#   define Tk_ClipDrawableToRect 0
#endif

/* TODO: These ought to come in some other way */
#include "tkPlatDecls.h"
#include "tkIntXlibDecls.h"

static const TkIntStubs tkIntStubs;
MODULE_SCOPE const TkStubs tkStubs;

/*
 * Remove macro that might interfere with the definition below.
 */

#undef TkPutImage
#undef XPutImage
#undef Tk_MainEx
#undef Tk_FreeXId

#if !defined(MAC_OSX_TK)
static int

#ifdef TK_NO_DEPRECATED
#define Tk_FreeXId 0
#define Tk_PhotoPutBlock_NoComposite 0
#define Tk_PhotoPutZoomedBlock_NoComposite 0
#define Tk_PhotoExpand_Panic 0
#define Tk_PhotoPutBlock_Panic 0
#define Tk_PhotoPutZoomedBlock_Panic 0
#define Tk_PhotoSetSize_Panic 0
#else
static void
doNothing(void)
{
    /* dummy implementation, no need to do anything */
    return 0;
}
#   undef TkpWillDrawWidget

#   undef TkpRedrawWidget
#   undef TkpDefineNativeBitmaps
#   undef TkpCreateNativeBitmap
#   undef TkpGetNativeAppBitmap
#   define TkpWillDrawWidget ((int (*)(Tk_Window))(void *)doNothing)
#   define TkpRedrawWidget ((void (*)(Tk_Window))(void *)doNothing)
#   define TkpDefineNativeBitmaps ((void (*)(void))(void *)doNothing)
#   define TkpCreateNativeBitmap ((Pixmap (*)(Display *, const void *))(void *)doNothing)
#define Tk_FreeXId ((void (*)(Display *, XID)) doNothing)
#   define TkpGetNativeAppBitmap ((Pixmap (*)(Display *, const char*, int *, int *))(void *)doNothing)
#endif

#ifdef _WIN32

int
TkpCmapStressed(Tk_Window tkwin, Colormap colormap)
{
    (void)tkwin;
    (void)colormap;

    /* dummy implementation, no need to do anything */
    return 0;
}
void
TkpSync(Display *display)
{
    (void)display;
    /* dummy implementation, no need to do anything */
}

void
TkCreateXEventSource(void)
{
    TkWinXInit(Tk_GetHINSTANCE());
}

#   define TkUnixContainerId 0
#   define TkUnixDoOneXEvent 0
#   define TkUnixSetMenubar 0
#   define XCreateWindow 0
#   define XOffsetRegion 0
#   define XUnionRegion 0
#   define TkWmCleanup (void (*)(TkDisplay *))(void *)TkpSync
#   define TkSendCleanup (void (*)(TkDisplay *))(void *)TkpSync
#   define TkWmCleanup (void (*)(TkDisplay *)) TkpSync
#   define TkSendCleanup (void (*)(TkDisplay *)) TkpSync
#   define TkpTestsendCmd 0

#else /* !_WIN32 */

/*
 * Make sure that extensions which call XParseColor through the stub
 * table, call TkParseColor instead. [Bug 3486474]
 */
#   define XParseColor	TkParseColor

#   ifdef __CYGWIN__

/*
 * Trick, so we don't have to include <windows.h> here, which in any
 * case lacks this function anyway.
 */

#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS	0x00000004
#ifdef __cplusplus
extern "C" {
#endif
int __stdcall GetModuleHandleExW(unsigned int, const char *, void *);
#ifdef __cplusplus
}
#endif

void *Tk_GetHINSTANCE()
{
    void *hInstance = NULL;

    GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
	    (const char *) &tkIntStubs, &hInstance);
    return hInstance;
}

void
TkSetPixmapColormap(
    Pixmap pixmap,
    Colormap colormap)
{
    (void)pixmap;
    (void)colormap;
}

void
TkpPrintWindowId(
    char *buf,			/* Pointer to string large enough to hold
				 * the hex representation of a pointer. */
    Window window)		/* Window to be printed into buffer. */
{
    snprintf(buf, TCL_INTEGER_SPACE, "0x%" TCL_Z_MODIFIER "x", (size_t)window);
    sprintf(buf, "%#08lx", (unsigned long) (window));
}

int
TkPutImage(
    unsigned long *colors,	/* Array of pixel values used by this image.
				 * May be NULL. */
    int ncolors,		/* Number of colors used, or 0. */
    Display *display,
    Drawable d,			/* Destination drawable. */
    GC gc,
    XImage *image,		/* Source image. */
    int src_x, int src_y,	/* Offset of subimage. */
    int dest_x, int dest_y,	/* Position of subimage origin in drawable. */
    unsigned int width, unsigned int height)
				/* Dimensions of subimage. */
{
    return XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height);
}
    (void)colors;
    (void)ncolors;

    return XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height);

TkRegion TkCreateRegion()
{
    return (TkRegion) XCreateRegion();
}

void TkDestroyRegion(TkRegion r)
{
    XDestroyRegion((Region)r);
}

void TkSetRegion(Display *d, GC g, TkRegion r)
{
    XSetRegion(d, g, (Region)r);
}

void TkUnionRectWithRegion(XRectangle *a, TkRegion b, TkRegion c)
{
    XUnionRectWithRegion(a, (Region) b, (Region) c);
}

void TkClipBox(TkRegion a, XRectangle *b)
{
    XClipBox((Region) a, b);
}

void TkIntersectRegion(TkRegion a, TkRegion b, TkRegion c)
{
    XIntersectRegion((Region) a, (Region) b, (Region) c);
}

int TkRectInRegion (TkRegion r, int a, int b, unsigned int c, unsigned int d)
{
    return XRectInRegion((Region) r, a, b, c, d);
}

void TkSubtractRegion (TkRegion a, TkRegion b, TkRegion c)
{
    XSubtractRegion((Region) a, (Region) b, (Region) c);
}

	/* TODO: To be implemented for Cygwin */
#	define Tk_AttachHWND 0
#	define Tk_GetHWND 0
#	define Tk_HWNDToWindow 0
#	define Tk_PointerEvent 0
#	define Tk_TranslateWinEvent 0
#	define TkAlignImageData 0
#	define TkpGetMS 0
#	define TkpGetCapture 0
#	define TkGenerateActivateEvents 0
#	define TkpGetMS 0
#	define TkPointerDeadWindow 0
#	define TkpSetCapture 0
#	define TkpSetCursor 0
#	define TkWinCancelMouseTimer 0
#	define TkWinClipboardRender 0
#	define TkWinEmbeddedEventProc 0
#	define TkWinFillRect 0
182
183
184
185
186
187
188

189
190
191
192
193

194
195
196
197
198
199





200
201
202
203
204

205
206
207
208
209
210
211
212
213
214







215
216
217
218






219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
219
220
221
222
223
224
225
226
227
228
229
230

231

232




233
234
235
236
237





238










239
240
241
242
243
244
245




246
247
248
249
250
251
252
253
254
255
256
257
258








259
260
261
262
263
264
265







+




-
+
-

-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+







-
-
-
-
-
-
-
-







#	define TkWinSetWindowPos 0
#	define TkWinWmCleanup 0
#	define TkWinXCleanup 0
#	define TkWinXInit 0
#	define TkWinSetForegroundWindow 0
#	define TkWinDialogDebug 0
#	define TkWinGetMenuSystemDefault 0
#	define TkWinGetPlatformId 0
#	define TkWinSetHINSTANCE 0
#	define TkWinGetPlatformTheme 0
#	define TkWinChildProc 0

#   endif
#   elif !defined(MAC_OSX_TK) /* UNIX */
#endif /* !_WIN32 */

#if defined(MAC_OSX_TCL)

int
TkPutImage(
#	undef TkClipBox
#	undef TkCreateRegion
#	undef TkDestroyRegion
#	undef TkIntersectRegion
#	undef TkRectInRegion
    unsigned long *colors,	/* Array of pixel values used by this image.
				 * May be NULL. */
    int ncolors,		/* Number of colors used, or 0. */
    Display *display,
    Drawable d,			/* Destination drawable. */
#	undef TkSetRegion
    GC gc,
    XImage *image,		/* Source image. */
    int src_x, int src_y,	/* Offset of subimage. */
    int dest_x, int dest_y,	/* Position of subimage origin in drawable. */
    unsigned int width, unsigned int height)
				/* Dimensions of subimage. */
{
	(void)colors;
	(void)ncolors;

#	undef TkUnionRectWithRegion
#	undef TkSubtractRegion

#	define TkClipBox (void (*) (TkRegion, XRectangle *)) XClipBox
#	define TkCreateRegion (TkRegion (*) ()) XCreateRegion
#	define TkDestroyRegion (void (*) (TkRegion)) XDestroyRegion
#	define TkIntersectRegion (void (*) (TkRegion, TkRegion, TkRegion)) XIntersectRegion
    return XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height);
}
#endif /* MAC_OSX_TCL */

#	define TkRectInRegion (int (*) (TkRegion, int, int, unsigned int, unsigned int)) XRectInRegion
#	define TkSetRegion (void (*) (Display *, GC, TkRegion)) XSetRegion
#	define TkUnionRectWithRegion (void (*) (XRectangle *, TkRegion, TkRegion)) XUnionRectWithRegion
#	define TkSubtractRegion (void (*) (TkRegion, TkRegion, TkRegion)) XSubtractRegion
#   endif
#endif /* !_WIN32 */

/*
 * WARNING: The contents of this file is automatically generated by the
 * tools/genStubs.tcl script. Any modifications to the function declarations
 * below should be made in the generic/tk.decls script.
 */

#ifdef __GNUC__
/*
 * The rest of this file shouldn't warn about deprecated functions; they're
 * there because we intend them to be so and know that this file is OK to
 * touch those fields.
 */
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
/* !BEGIN!: Do not edit below this line. */

static const TkIntStubs tkIntStubs = {
    TCL_STUB_MAGIC,
    0,
    TkAllocWindow, /* 0 */
    TkBezierPoints, /* 1 */
292
293
294
295
296
297
298
299

300
301
302
303

304
305

306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
317
318
319
320
321
322
323

324
325
326
327

328
329

330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+



-
+

-
+







-
-
+
+









-
+







    TkOvalToArea, /* 53 */
    TkOvalToPoint, /* 54 */
    TkpChangeFocus, /* 55 */
    TkpCloseDisplay, /* 56 */
    TkpClaimFocus, /* 57 */
    TkpDisplayWarning, /* 58 */
    TkpGetAppName, /* 59 */
    0, /* 60 */
    TkpGetOtherWindow, /* 60 */
    TkpGetWrapperWindow, /* 61 */
    TkpInit, /* 62 */
    TkpInitializeMenuBindings, /* 63 */
    0, /* 64 */
    TkpMakeContainer, /* 64 */
    TkpMakeMenuWindow, /* 65 */
    0, /* 66 */
    TkpMakeWindow, /* 66 */
    TkpMenuNotifyToplevelCreate, /* 67 */
    TkpOpenDisplay, /* 68 */
    TkPointerEvent, /* 69 */
    TkPolygonToArea, /* 70 */
    TkPolygonToPoint, /* 71 */
    TkPositionInTree, /* 72 */
    TkpRedirectKeyEvent, /* 73 */
    0, /* 74 */
    0, /* 75 */
    TkpSetMainMenubar, /* 74 */
    TkpUseWindow, /* 75 */
    0, /* 76 */
    TkQueueEventForAllChildren, /* 77 */
    TkReadBitmapFile, /* 78 */
    TkScrollWindow, /* 79 */
    TkSelDeadWindow, /* 80 */
    TkSelEventProc, /* 81 */
    TkSelInit, /* 82 */
    TkSelPropProc, /* 83 */
    0, /* 84 */
    0, /* 85 */
    TkSetWindowMenuBar, /* 85 */
    TkStringToKeysym, /* 86 */
    TkThickPolyLineToArea, /* 87 */
    TkWmAddToColormapWindows, /* 88 */
    TkWmDeadWindow, /* 89 */
    TkWmFocusToplevel, /* 90 */
    TkWmMapWindow, /* 91 */
    TkWmNewWindow, /* 92 */
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358







359








360









361

362








363

364
365
366
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
368
369
370
371
372
373
374

375
376







377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435

436
437
438
439
440
441
442
443







-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+

+

+
+
+
+
+
+
+
+

+










-
+









-
+







    TkFindStateNumObj, /* 104 */
    TkGetBitmapPredefTable, /* 105 */
    TkGetDisplayList, /* 106 */
    TkGetMainInfoList, /* 107 */
    TkGetWindowFromObj, /* 108 */
    TkpGetString, /* 109 */
    TkpGetSubFonts, /* 110 */
    0, /* 111 */
    TkpGetSystemDefault, /* 111 */
    TkpMenuThreadInit, /* 112 */
    XClipBox, /* 113 */
    XCreateRegion, /* 114 */
    XDestroyRegion, /* 115 */
    XIntersectRegion, /* 116 */
    XRectInRegion, /* 117 */
    XSetRegion, /* 118 */
    XUnionRectWithRegion, /* 119 */
    TkClipBox, /* 113 */
    TkCreateRegion, /* 114 */
    TkDestroyRegion, /* 115 */
    TkIntersectRegion, /* 116 */
    TkRectInRegion, /* 117 */
    TkSetRegion, /* 118 */
    TkUnionRectWithRegion, /* 119 */
    0, /* 120 */
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    0, /* 121 */
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    0, /* 121 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    0, /* 121 */ /* Dummy entry for stubs table backwards compatibility */
    TkpCreateNativeBitmap, /* 121 */
#endif /* AQUA */
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    0, /* 122 */
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    0, /* 122 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    0, /* 122 */ /* Dummy entry for stubs table backwards compatibility */
    TkpDefineNativeBitmaps, /* 122 */
#endif /* AQUA */
    0, /* 123 */
#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
    0, /* 124 */
#endif /* X11 */
#if defined(_WIN32) /* WIN */
    0, /* 124 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    0, /* 124 */ /* Dummy entry for stubs table backwards compatibility */
    TkpGetNativeAppBitmap, /* 124 */
#endif /* AQUA */
    0, /* 125 */
    0, /* 126 */
    0, /* 127 */
    0, /* 128 */
    0, /* 129 */
    0, /* 130 */
    0, /* 131 */
    0, /* 132 */
    0, /* 133 */
    0, /* 134 */
    0, /* 135 */
    TkpDrawHighlightBorder, /* 135 */
    TkSetFocusWin, /* 136 */
    TkpSetKeycodeAndState, /* 137 */
    TkpGetKeySym, /* 138 */
    TkpInitKeymapInfo, /* 139 */
    TkPhotoGetValidRegion, /* 140 */
    TkWmStackorderToplevel, /* 141 */
    TkFocusFree, /* 142 */
    TkClipCleanup, /* 143 */
    TkGCCleanup, /* 144 */
    XSubtractRegion, /* 145 */
    TkSubtractRegion, /* 145 */
    TkStylePkgInit, /* 146 */
    TkStylePkgFree, /* 147 */
    TkToplevelWindowForCommand, /* 148 */
    TkGetOptionSpec, /* 149 */
    TkMakeRawCurve, /* 150 */
    TkMakeRawCurvePostscript, /* 151 */
    TkpDrawFrame, /* 152 */
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433

434
435
436
437
438
439
440
469
470
471
472
473
474
475



476
477
478
479
480
481
482

483
484
485
486
487
488
489
490







-
-
-
+






-
+







    TkOrientPrintProc, /* 178 */
    TkSmoothParseProc, /* 179 */
    TkSmoothPrintProc, /* 180 */
    TkDrawAngledTextLayout, /* 181 */
    TkUnderlineAngledTextLayout, /* 182 */
    TkIntersectAngledTextLayout, /* 183 */
    TkDrawAngledChars, /* 184 */
    TkpRedrawWidget, /* 185 */
    TkpWillDrawWidget, /* 186 */
    TkDebugPhotoStringMatchDef, /* 187 */
    TkDebugPhotoStringMatchDef, /* 185 */
};

static const TkIntPlatStubs tkIntPlatStubs = {
    TCL_STUB_MAGIC,
    0,
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
    TkCreateXEventSource, /* 0 */
    TkAlignImageData, /* 0 */
    0, /* 1 */
    TkGenerateActivateEvents, /* 2 */
    TkpGetMS, /* 3 */
    TkPointerDeadWindow, /* 4 */
    TkpPrintWindowId, /* 5 */
    TkpScanWindowId, /* 6 */
    TkpSetCapture, /* 7 */
459
460
461
462
463
464
465
466

467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485



486
487


488
489
490


491
492
493
494

495
496
497
498
499
500
501
502
503
504
505

506
507
508
509

510
511
512
513

514
515
516

517
518
519
520
521
522
523

524
525
526
527
528
529
530

531
532

533
534
535



536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583











584
585
586
587
588
589
590
509
510
511
512
513
514
515

516
517
518
519

520
521
522
523
524
525
526
527
528


529
530



531
532
533


534
535
536


537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552

553
554
555
556

557
558
559
560

561
562
563

564
565
566
567
568
569
570

571
572
573
574
575
576
577

578
579

580
581
582
583
584
585
586
587
588
589
590


591










































592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609







-
+



-
+








-
-


-
-
-
+
+
+
-
-
+
+

-
-
+
+



-
+










-
+



-
+



-
+


-
+






-
+






-
+

-
+



+
+
+




-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







    TkWinSetWindowPos, /* 26 */
    TkWinWmCleanup, /* 27 */
    TkWinXCleanup, /* 28 */
    TkWinXInit, /* 29 */
    TkWinSetForegroundWindow, /* 30 */
    TkWinDialogDebug, /* 31 */
    TkWinGetMenuSystemDefault, /* 32 */
    TkAlignImageData, /* 33 */
    TkWinGetPlatformId, /* 33 */
    TkWinSetHINSTANCE, /* 34 */
    TkWinGetPlatformTheme, /* 35 */
    TkWinChildProc, /* 36 */
    0, /* 37 */
    TkCreateXEventSource, /* 37 */
    TkpCmapStressed, /* 38 */
    TkpSync, /* 39 */
    TkUnixContainerId, /* 40 */
    TkUnixDoOneXEvent, /* 41 */
    TkUnixSetMenubar, /* 42 */
    TkWmCleanup, /* 43 */
    TkSendCleanup, /* 44 */
    TkpTestsendCmd, /* 45 */
    0, /* 46 */
    TkpGetCapture, /* 47 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    0, /* 0 */
    TkAboutDlg, /* 1 */
    TkGenerateActivateEvents, /* 2 */
    TkGenerateActivateEvents, /* 0 */
    0, /* 1 */
    0, /* 2 */
    TkpGetMS, /* 3 */
    TkPointerDeadWindow, /* 4 */
    TkPointerDeadWindow, /* 3 */
    TkpSetCapture, /* 4 */
    TkpSetCursor, /* 5 */
    TkpScanWindowId, /* 6 */
    TkpWmSetState, /* 7 */
    TkpWmSetState, /* 6 */
    TkAboutDlg, /* 7 */
    TkMacOSXButtonKeyState, /* 8 */
    TkMacOSXClearMenubarActive, /* 9 */
    TkMacOSXDispatchMenuEvent, /* 10 */
    TkpSetCapture, /* 11 */
    TkMacOSXInstallCursor, /* 11 */
    TkMacOSXHandleTearoffMenu, /* 12 */
    0, /* 13 */
    TkMacOSXDoHLEvent, /* 14 */
    0, /* 15 */
    TkMacOSXGetXWindow, /* 16 */
    TkMacOSXGrowToplevel, /* 17 */
    TkMacOSXHandleMenuSelect, /* 18 */
    0, /* 19 */
    0, /* 20 */
    TkMacOSXInvalidateWindow, /* 21 */
    0, /* 22 */
    TkMacOSXIsCharacterMissing, /* 22 */
    TkMacOSXMakeRealWindowExist, /* 23 */
    TkMacOSXMakeStippleMap, /* 24 */
    TkMacOSXMenuClick, /* 25 */
    0, /* 26 */
    TkMacOSXRegisterOffScreenWindow, /* 26 */
    TkMacOSXResizable, /* 27 */
    TkMacOSXSetHelpMenuItemCount, /* 28 */
    TkMacOSXSetScrollbarGrow, /* 29 */
    0, /* 30 */
    TkMacOSXSetUpClippingRgn, /* 30 */
    TkMacOSXSetUpGraphicsPort, /* 31 */
    TkMacOSXUpdateClipRgn, /* 32 */
    0, /* 33 */
    TkMacOSXUnregisterMacWindow, /* 33 */
    TkMacOSXUseMenuID, /* 34 */
    TkMacOSXVisableClipRgn, /* 35 */
    TkMacOSXWinBounds, /* 36 */
    TkMacOSXWindowOffset, /* 37 */
    TkSetMacColor, /* 38 */
    TkSetWMName, /* 39 */
    0, /* 40 */
    TkSuspendClipboard, /* 40 */
    TkMacOSXZoomToplevel, /* 41 */
    Tk_TopCoordsToWindow, /* 42 */
    TkMacOSXContainerId, /* 43 */
    TkMacOSXGetHostToplevel, /* 44 */
    TkMacOSXPreprocessMenu, /* 45 */
    TkpIsWindowFloating, /* 46 */
    TkpGetCapture, /* 47 */
    TkMacOSXGetCapture, /* 47 */
    0, /* 48 */
    TkMacOSXGetContainer, /* 49 */
    TkGetTransientMaster, /* 49 */
    TkGenerateButtonEvent, /* 50 */
    TkGenWMDestroyEvent, /* 51 */
    TkMacOSXSetDrawingEnabled, /* 52 */
    TkpGetMS, /* 53 */
    TkMacOSXDrawable, /* 54 */
    TkpScanWindowId, /* 55 */
#endif /* AQUA */
#if !(defined(_WIN32) || defined(__CYGWIN__) || defined(MAC_OSX_TK)) /* X11 */
    TkCreateXEventSource, /* 0 */
    0, /* 1 */
    TkGenerateActivateEvents, /* 2 */
    0, /* 3 */
    0, /* 2 */
    0, /* 4 */
    0, /* 5 */
    TkpScanWindowId, /* 6 */
    0, /* 7 */
    0, /* 8 */
    TkpWmSetState, /* 9 */
    0, /* 10 */
    0, /* 11 */
    0, /* 12 */
    0, /* 13 */
    0, /* 14 */
    0, /* 15 */
    0, /* 16 */
    0, /* 17 */
    0, /* 18 */
    0, /* 19 */
    0, /* 20 */
    0, /* 21 */
    0, /* 22 */
    0, /* 23 */
    0, /* 24 */
    0, /* 25 */
    0, /* 26 */
    0, /* 27 */
    0, /* 28 */
    0, /* 29 */
    0, /* 30 */
    0, /* 31 */
    0, /* 32 */
    0, /* 33 */
    0, /* 34 */
    0, /* 35 */
    0, /* 36 */
    0, /* 37 */
    TkpCmapStressed, /* 38 */
    TkpSync, /* 39 */
    TkUnixContainerId, /* 40 */
    TkUnixDoOneXEvent, /* 41 */
    TkUnixSetMenubar, /* 42 */
    TkWmCleanup, /* 43 */
    TkSendCleanup, /* 44 */
    TkpTestsendCmd, /* 45 */
    TkpCmapStressed, /* 3 */
    TkpSync, /* 4 */
    TkUnixContainerId, /* 5 */
    TkUnixDoOneXEvent, /* 6 */
    TkUnixSetMenubar, /* 7 */
    TkpScanWindowId, /* 8 */
    TkWmCleanup, /* 9 */
    TkSendCleanup, /* 10 */
    0, /* 11 */
    TkpWmSetState, /* 12 */
    TkpTestsendCmd, /* 13 */
#endif /* X11 */
};

static const TkIntXlibStubs tkIntXlibStubs = {
    TCL_STUB_MAGIC,
    0,
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
684
685
686
687
688
689
690

691
692
693
694
695
696
697
698







-
+







    XUngrabPointer, /* 74 */
    XUnmapWindow, /* 75 */
    XWindowEvent, /* 76 */
    XDestroyIC, /* 77 */
    XFilterEvent, /* 78 */
    XmbLookupString, /* 79 */
    TkPutImage, /* 80 */
    XSetClipRectangles, /* 81 */
    0, /* 81 */
    XParseColor, /* 82 */
    XCreateGC, /* 83 */
    XFreeGC, /* 84 */
    XInternAtom, /* 85 */
    XSetBackground, /* 86 */
    XSetForeground, /* 87 */
    XSetClipMask, /* 88 */
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761

762
763
764
765
766




767
768
769
770
771
772
773




774
775
776
777
778
779





780
781
782
783
784
785
786
787







788
789
790


791
792
793


794
795

796
797
798
799



800
801
802
803



804
805
806
807

808
809
810
811
812
813





814
815
816
817
818
819
820
821
822
823









824
825
826
827



828
829
830
831
832

833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848















849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880








881
882
883
884
885
886
887






888
889

890
891
892
893
894
895
896
897
898




899
900
901
902
903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921


922
923
924
925
926
927




928
929

930
931

932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
741
742
743
744
745
746
747





















748

749
750
751
752
753
754
755
756



757





758
759
760
761







762
763
764
765






766
767
768
769
770








771
772
773
774
775
776
777



778
779



780
781


782




783
784
785




786
787
788




789






790
791
792
793
794










795
796
797
798
799
800
801
802
803




804
805
806





807
















808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
































823
824
825
826
827
828
829
830







831
832
833
834
835
836


837









838
839
840
841













842
843
844
845
846
847
848
849
850
851
852
853
854
855
856




857
858
859
860
861

862
863

864
865
866
867






868
869
870
871
872
873
874







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







-
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+










+
+


-
-
-
-
+
+
+
+

-
+

-
+



-
-
-
-
-
-







    XDrawArcs, /* 131 */
    XDrawRectangles, /* 132 */
    XDrawSegments, /* 133 */
    XDrawPoint, /* 134 */
    XDrawPoints, /* 135 */
    XReparentWindow, /* 136 */
    XPutImage, /* 137 */
    XPolygonRegion, /* 138 */
    XPointInRegion, /* 139 */
    XVaCreateNestedList, /* 140 */
    XSetICValues, /* 141 */
    XGetICValues, /* 142 */
    XSetICFocus, /* 143 */
    0, /* 144 */
    0, /* 145 */
    0, /* 146 */
    XFreeFontSet, /* 147 */
    XCloseIM, /* 148 */
    XRegisterIMInstantiateCallback, /* 149 */
    XUnregisterIMInstantiateCallback, /* 150 */
    XSetLocaleModifiers, /* 151 */
    XOpenIM, /* 152 */
    XGetIMValues, /* 153 */
    XSetIMValues, /* 154 */
    XCreateFontSet, /* 155 */
    XFreeStringList, /* 156 */
    XkbKeycodeToKeysym, /* 157 */
    XkbOpenDisplay, /* 158 */
#endif /* WIN */
#ifdef MAC_OSX_TCL /* MACOSX */
#ifdef MAC_OSX_TK /* AQUA */
    XSetDashes, /* 0 */
    XGetModifierMapping, /* 1 */
    XCreateImage, /* 2 */
    XGetImage, /* 3 */
    XGetAtomName, /* 4 */
    XKeysymToString, /* 5 */
    XCreateColormap, /* 6 */
    XCreatePixmapCursor, /* 7 */
    XCreateGlyphCursor, /* 8 */
    XGContextFromGC, /* 9 */
    XGContextFromGC, /* 7 */
    XListHosts, /* 10 */
    XKeycodeToKeysym, /* 11 */
    XStringToKeysym, /* 12 */
    XRootWindow, /* 13 */
    XSetErrorHandler, /* 14 */
    XKeycodeToKeysym, /* 8 */
    XStringToKeysym, /* 9 */
    XRootWindow, /* 10 */
    XSetErrorHandler, /* 11 */
    XIconifyWindow, /* 15 */
    XWithdrawWindow, /* 16 */
    XGetWMColormapWindows, /* 17 */
    XAllocColor, /* 18 */
    XBell, /* 19 */
    XChangeProperty, /* 20 */
    XChangeWindowAttributes, /* 21 */
    XAllocColor, /* 12 */
    XBell, /* 13 */
    XChangeProperty, /* 14 */
    XChangeWindowAttributes, /* 15 */
    XClearWindow, /* 22 */
    XConfigureWindow, /* 23 */
    XCopyArea, /* 24 */
    XCopyPlane, /* 25 */
    XCreateBitmapFromData, /* 26 */
    XDefineCursor, /* 27 */
    XConfigureWindow, /* 16 */
    XCopyArea, /* 17 */
    XCopyPlane, /* 18 */
    XCreateBitmapFromData, /* 19 */
    XDefineCursor, /* 20 */
    XDeleteProperty, /* 28 */
    XDestroyWindow, /* 29 */
    XDrawArc, /* 30 */
    XDrawLines, /* 31 */
    XDrawRectangle, /* 32 */
    XFillArc, /* 33 */
    XFillPolygon, /* 34 */
    XFillRectangles, /* 35 */
    XDestroyWindow, /* 21 */
    XDrawArc, /* 22 */
    XDrawLines, /* 23 */
    XDrawRectangle, /* 24 */
    XFillArc, /* 25 */
    XFillPolygon, /* 26 */
    XFillRectangles, /* 27 */
    XForceScreenSaver, /* 36 */
    XFreeColormap, /* 37 */
    XFreeColors, /* 38 */
    XFreeColormap, /* 28 */
    XFreeColors, /* 29 */
    XFreeCursor, /* 39 */
    XFreeModifiermap, /* 40 */
    XGetGeometry, /* 41 */
    XFreeModifiermap, /* 30 */
    XGetGeometry, /* 31 */
    XGetInputFocus, /* 42 */
    XGetWindowProperty, /* 43 */
    XGetWindowProperty, /* 32 */
    XGetWindowAttributes, /* 44 */
    XGrabKeyboard, /* 45 */
    XGrabPointer, /* 46 */
    XKeysymToKeycode, /* 47 */
    XGrabKeyboard, /* 33 */
    XGrabPointer, /* 34 */
    XKeysymToKeycode, /* 35 */
    XLookupColor, /* 48 */
    XMapWindow, /* 49 */
    XMoveResizeWindow, /* 50 */
    XMoveWindow, /* 51 */
    XMapWindow, /* 36 */
    XMoveResizeWindow, /* 37 */
    XMoveWindow, /* 38 */
    XNextEvent, /* 52 */
    XPutBackEvent, /* 53 */
    XQueryColors, /* 54 */
    XQueryPointer, /* 55 */
    XQueryPointer, /* 39 */
    XQueryTree, /* 56 */
    XRaiseWindow, /* 57 */
    XRefreshKeyboardMapping, /* 58 */
    XResizeWindow, /* 59 */
    XSelectInput, /* 60 */
    XSendEvent, /* 61 */
    XRaiseWindow, /* 40 */
    XRefreshKeyboardMapping, /* 41 */
    XResizeWindow, /* 42 */
    XSelectInput, /* 43 */
    XSendEvent, /* 44 */
    XSetCommand, /* 62 */
    XSetIconName, /* 63 */
    XSetInputFocus, /* 64 */
    XSetSelectionOwner, /* 65 */
    XSetWindowBackground, /* 66 */
    XSetWindowBackgroundPixmap, /* 67 */
    XSetWindowBorder, /* 68 */
    XSetWindowBorderPixmap, /* 69 */
    XSetWindowBorderWidth, /* 70 */
    XSetWindowColormap, /* 71 */
    XSetIconName, /* 45 */
    XSetInputFocus, /* 46 */
    XSetSelectionOwner, /* 47 */
    XSetWindowBackground, /* 48 */
    XSetWindowBackgroundPixmap, /* 49 */
    XSetWindowBorder, /* 50 */
    XSetWindowBorderPixmap, /* 51 */
    XSetWindowBorderWidth, /* 52 */
    XSetWindowColormap, /* 53 */
    XTranslateCoordinates, /* 72 */
    XUngrabKeyboard, /* 73 */
    XUngrabPointer, /* 74 */
    XUnmapWindow, /* 75 */
    XUngrabKeyboard, /* 54 */
    XUngrabPointer, /* 55 */
    XUnmapWindow, /* 56 */
    XWindowEvent, /* 76 */
    XDestroyIC, /* 77 */
    XFilterEvent, /* 78 */
    XmbLookupString, /* 79 */
    TkPutImage, /* 80 */
    TkPutImage, /* 57 */
    XSetClipRectangles, /* 81 */
    XParseColor, /* 82 */
    XCreateGC, /* 83 */
    XFreeGC, /* 84 */
    XInternAtom, /* 85 */
    XSetBackground, /* 86 */
    XSetForeground, /* 87 */
    XSetClipMask, /* 88 */
    XSetClipOrigin, /* 89 */
    XSetTSOrigin, /* 90 */
    XChangeGC, /* 91 */
    XSetFont, /* 92 */
    XSetArcMode, /* 93 */
    XSetStipple, /* 94 */
    XSetFillRule, /* 95 */
    XSetFillStyle, /* 96 */
    XParseColor, /* 58 */
    XCreateGC, /* 59 */
    XFreeGC, /* 60 */
    XInternAtom, /* 61 */
    XSetBackground, /* 62 */
    XSetForeground, /* 63 */
    XSetClipMask, /* 64 */
    XSetClipOrigin, /* 65 */
    XSetTSOrigin, /* 66 */
    XChangeGC, /* 67 */
    XSetFont, /* 68 */
    XSetArcMode, /* 69 */
    XSetStipple, /* 70 */
    XSetFillRule, /* 71 */
    XSetFillStyle, /* 72 */
    XSetFunction, /* 97 */
    XSetLineAttributes, /* 98 */
    _XInitImageFuncPtrs, /* 99 */
    XCreateIC, /* 100 */
    XGetVisualInfo, /* 101 */
    XSetWMClientMachine, /* 102 */
    XStringListToTextProperty, /* 103 */
    XDrawLine, /* 104 */
    XWarpPointer, /* 105 */
    XFillRectangle, /* 106 */
    XFlush, /* 107 */
    XGrabServer, /* 108 */
    XUngrabServer, /* 109 */
    XFree, /* 110 */
    XNoOp, /* 111 */
    XSynchronize, /* 112 */
    XSync, /* 113 */
    XVisualIDFromVisual, /* 114 */
    0, /* 115 */
    0, /* 116 */
    0, /* 117 */
    0, /* 118 */
    0, /* 119 */
    XOffsetRegion, /* 120 */
    XUnionRegion, /* 121 */
    XCreateWindow, /* 122 */
    0, /* 123 */
    0, /* 124 */
    0, /* 125 */
    0, /* 126 */
    0, /* 127 */
    0, /* 128 */
    XSetFunction, /* 73 */
    XSetLineAttributes, /* 74 */
    _XInitImageFuncPtrs, /* 75 */
    XCreateIC, /* 76 */
    XGetVisualInfo, /* 77 */
    XSetWMClientMachine, /* 78 */
    XStringListToTextProperty, /* 79 */
    XDrawSegments, /* 80 */
    XLowerWindow, /* 129 */
    XFillArcs, /* 130 */
    XDrawArcs, /* 131 */
    XDrawRectangles, /* 132 */
    XDrawSegments, /* 133 */
    XDrawPoint, /* 134 */
    XDrawPoints, /* 135 */
    XForceScreenSaver, /* 81 */
    XDrawLine, /* 82 */
    XFillRectangle, /* 83 */
    XClearWindow, /* 84 */
    XDrawPoint, /* 85 */
    XDrawPoints, /* 86 */
    XReparentWindow, /* 136 */
    XPutImage, /* 137 */
    XWarpPointer, /* 87 */
    XPolygonRegion, /* 138 */
    XPointInRegion, /* 139 */
    XVaCreateNestedList, /* 140 */
    XSetICValues, /* 141 */
    XGetICValues, /* 142 */
    XSetICFocus, /* 143 */
    0, /* 144 */
    0, /* 145 */
    0, /* 146 */
    XQueryColor, /* 88 */
    XQueryColors, /* 89 */
    XQueryTree, /* 90 */
    XSync, /* 91 */
    XFreeFontSet, /* 147 */
    XCloseIM, /* 148 */
    XRegisterIMInstantiateCallback, /* 149 */
    XUnregisterIMInstantiateCallback, /* 150 */
    XSetLocaleModifiers, /* 151 */
    XOpenIM, /* 152 */
    XGetIMValues, /* 153 */
    XSetIMValues, /* 154 */
    XCreateFontSet, /* 155 */
    XFreeStringList, /* 156 */
    XkbKeycodeToKeysym, /* 157 */
    XkbOpenDisplay, /* 158 */
#endif /* MACOSX */
#endif /* AQUA */
};

static const TkPlatStubs tkPlatStubs = {
    TCL_STUB_MAGIC,
    0,
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
    Tk_AttachHWND, /* 0 */
    Tk_GetHINSTANCE, /* 1 */
    Tk_GetHWND, /* 2 */
    Tk_HWNDToWindow, /* 3 */
    Tk_PointerEvent, /* 4 */
    Tk_TranslateWinEvent, /* 5 */
#endif /* WIN */
#ifdef MAC_OSX_TK /* AQUA */
    0, /* 0 */
    0, /* 1 */
    0, /* 2 */
    0, /* 3 */
    Tk_MacOSXSetEmbedHandler, /* 0 */
    Tk_MacOSXTurnOffMenus, /* 1 */
    Tk_MacOSXTkOwnsCursor, /* 2 */
    TkMacOSXInitMenus, /* 3 */
    TkMacOSXInitAppleEvents, /* 4 */
    0, /* 5 */
    TkGenWMConfigureEvent, /* 5 */
    TkMacOSXInvalClipRgns, /* 6 */
    0, /* 7 */
    TkMacOSXGetDrawablePort, /* 7 */
    TkMacOSXGetRootControl, /* 8 */
    Tk_MacOSXSetupTkNotifier, /* 9 */
    Tk_MacOSXIsAppInFront, /* 10 */
    Tk_MacOSXGetTkWindow, /* 11 */
    Tk_MacOSXGetCGContextForDrawable, /* 12 */
    Tk_MacOSXGetNSWindowForDrawable, /* 13 */
    0, /* 14 */
    0, /* 15 */
    TkGenWMConfigureEvent, /* 16 */
#endif /* AQUA */
};

static const TkStubHooks tkStubHooks = {
    &tkPlatStubs,
    &tkIntStubs,
    &tkIntPlatStubs,
1024
1025
1026
1027
1028
1029
1030
1031

1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072

1073
1074
1075
1076
1077
1078
1079
951
952
953
954
955
956
957

958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006







-
+




















-
+



















-
+







    Tk_FreeCursor, /* 70 */
    Tk_FreeFont, /* 71 */
    Tk_FreeGC, /* 72 */
    Tk_FreeImage, /* 73 */
    Tk_FreeOptions, /* 74 */
    Tk_FreePixmap, /* 75 */
    Tk_FreeTextLayout, /* 76 */
    0, /* 77 */
    Tk_FreeXId, /* 77 */
    Tk_GCForColor, /* 78 */
    Tk_GeometryRequest, /* 79 */
    Tk_Get3DBorder, /* 80 */
    Tk_GetAllBindings, /* 81 */
    Tk_GetAnchor, /* 82 */
    Tk_GetAtomName, /* 83 */
    Tk_GetBinding, /* 84 */
    Tk_GetBitmap, /* 85 */
    Tk_GetBitmapFromData, /* 86 */
    Tk_GetCapStyle, /* 87 */
    Tk_GetColor, /* 88 */
    Tk_GetColorByValue, /* 89 */
    Tk_GetColormap, /* 90 */
    Tk_GetCursor, /* 91 */
    Tk_GetCursorFromData, /* 92 */
    Tk_GetFont, /* 93 */
    Tk_GetFontFromObj, /* 94 */
    Tk_GetFontMetrics, /* 95 */
    Tk_GetGC, /* 96 */
    Tk_GetImage, /* 97 */
    Tk_GetImageModelData, /* 98 */
    Tk_GetImageMasterData, /* 98 */
    Tk_GetItemTypes, /* 99 */
    Tk_GetJoinStyle, /* 100 */
    Tk_GetJustify, /* 101 */
    Tk_GetNumMainWindows, /* 102 */
    Tk_GetOption, /* 103 */
    Tk_GetPixels, /* 104 */
    Tk_GetPixmap, /* 105 */
    Tk_GetRelief, /* 106 */
    Tk_GetRootCoords, /* 107 */
    Tk_GetScrollInfo, /* 108 */
    Tk_GetScreenMM, /* 109 */
    Tk_GetSelection, /* 110 */
    Tk_GetUid, /* 111 */
    Tk_GetVisual, /* 112 */
    Tk_GetVRootGeometry, /* 113 */
    Tk_Grab, /* 114 */
    Tk_HandleEvent, /* 115 */
    Tk_IdToWindow, /* 116 */
    Tk_ImageChanged, /* 117 */
    0, /* 118 */
    Tk_Init, /* 118 */
    Tk_InternAtom, /* 119 */
    Tk_IntersectTextLayout, /* 120 */
    Tk_MaintainGeometry, /* 121 */
    Tk_MainWindow, /* 122 */
    Tk_MakeWindowExist, /* 123 */
    Tk_ManageGeometry, /* 124 */
    Tk_MapWindow, /* 125 */
1091
1092
1093
1094
1095
1096
1097
1098
1099


1100
1101
1102

1103
1104

1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1018
1019
1020
1021
1022
1023
1024


1025
1026
1027
1028

1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1047







-
-
+
+


-
+

-
+








-
+







    Tk_NameOfImage, /* 137 */
    Tk_NameOfJoinStyle, /* 138 */
    Tk_NameOfJustify, /* 139 */
    Tk_NameOfRelief, /* 140 */
    Tk_NameToWindow, /* 141 */
    Tk_OwnSelection, /* 142 */
    Tk_ParseArgv, /* 143 */
    0, /* 144 */
    0, /* 145 */
    Tk_PhotoPutBlock_NoComposite, /* 144 */
    Tk_PhotoPutZoomedBlock_NoComposite, /* 145 */
    Tk_PhotoGetImage, /* 146 */
    Tk_PhotoBlank, /* 147 */
    0, /* 148 */
    Tk_PhotoExpand_Panic, /* 148 */
    Tk_PhotoGetSize, /* 149 */
    0, /* 150 */
    Tk_PhotoSetSize_Panic, /* 150 */
    Tk_PointToChar, /* 151 */
    Tk_PostscriptFontName, /* 152 */
    Tk_PreserveColormap, /* 153 */
    Tk_QueueWindowEvent, /* 154 */
    Tk_RedrawImage, /* 155 */
    Tk_ResizeWindow, /* 156 */
    Tk_RestackWindow, /* 157 */
    Tk_RestrictEvents, /* 158 */
    0, /* 159 */
    Tk_SafeInit, /* 159 */
    Tk_SetAppName, /* 160 */
    Tk_SetBackgroundFromBorder, /* 161 */
    Tk_SetClass, /* 162 */
    Tk_SetGrid, /* 163 */
    Tk_SetInternalBorder, /* 164 */
    Tk_SetWindowBackground, /* 165 */
    Tk_SetWindowBackgroundPixmap, /* 166 */
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103
1104







-
+



-
+







    Tk_GetOptionValue, /* 205 */
    Tk_GetJustifyFromObj, /* 206 */
    Tk_GetMMFromObj, /* 207 */
    Tk_GetPixelsFromObj, /* 208 */
    Tk_GetReliefFromObj, /* 209 */
    Tk_GetScrollInfoObj, /* 210 */
    Tk_InitOptions, /* 211 */
    0, /* 212 */
    Tk_MainEx, /* 212 */
    Tk_RestoreSavedOptions, /* 213 */
    Tk_SetOptions, /* 214 */
    Tk_InitConsoleChannels, /* 215 */
    0, /* 216 */
    Tk_CreateConsoleWindow, /* 216 */
    Tk_CreateSmoothMethod, /* 217 */
    0, /* 218 */
    0, /* 219 */
    Tk_GetDash, /* 220 */
    Tk_CreateOutline, /* 221 */
    Tk_DeleteOutline, /* 222 */
    Tk_ConfigOutlineGC, /* 223 */
1193
1194
1195
1196
1197
1198
1199
1200
1201


1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213


1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227


1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1120
1121
1122
1123
1124
1125
1126


1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138


1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152


1153
1154

















1155
1156
1157




















-
-
+
+










-
-
+
+












-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
    Tk_CreateClientMessageHandler, /* 239 */
    Tk_DeleteClientMessageHandler, /* 240 */
    Tk_CreateAnonymousWindow, /* 241 */
    Tk_SetClassProcs, /* 242 */
    Tk_SetInternalBorderEx, /* 243 */
    Tk_SetMinimumRequestSize, /* 244 */
    Tk_SetCaretPos, /* 245 */
    0, /* 246 */
    0, /* 247 */
    Tk_PhotoPutBlock_Panic, /* 246 */
    Tk_PhotoPutZoomedBlock_Panic, /* 247 */
    Tk_CollapseMotionEvents, /* 248 */
    Tk_RegisterStyleEngine, /* 249 */
    Tk_GetStyleEngine, /* 250 */
    Tk_RegisterStyledElement, /* 251 */
    Tk_GetElementId, /* 252 */
    Tk_CreateStyle, /* 253 */
    Tk_GetStyle, /* 254 */
    Tk_FreeStyle, /* 255 */
    Tk_NameOfStyle, /* 256 */
    Tk_AllocStyleFromObj, /* 257 */
    0, /* 258 */
    0, /* 259 */
    Tk_GetStyleFromObj, /* 258 */
    Tk_FreeStyleFromObj, /* 259 */
    Tk_GetStyledElement, /* 260 */
    Tk_GetElementSize, /* 261 */
    Tk_GetElementBox, /* 262 */
    Tk_GetElementBorderWidth, /* 263 */
    Tk_DrawElement, /* 264 */
    Tk_PhotoExpand, /* 265 */
    Tk_PhotoPutBlock, /* 266 */
    Tk_PhotoPutZoomedBlock, /* 267 */
    Tk_PhotoSetSize, /* 268 */
    Tk_GetUserInactiveTime, /* 269 */
    Tk_ResetUserInactiveTime, /* 270 */
    Tk_Interp, /* 271 */
    0, /* 272 */
    0, /* 273 */
    Tk_CreateOldImageType, /* 272 */
    Tk_CreateOldPhotoImageFormat, /* 273 */
    Tk_AlwaysShowSelection, /* 274 */
    Tk_GetButtonMask, /* 275 */
    Tk_GetDoublePixelsFromObj, /* 276 */
    Tk_NewWindowObj, /* 277 */
    Tk_SendVirtualEvent, /* 278 */
    Tk_FontGetDescription, /* 279 */
    Tk_CreatePhotoImageFormatVersion3, /* 280 */
    Tk_DrawHighlightBorder, /* 281 */
    Tk_SetMainMenubar, /* 282 */
    Tk_SetWindowMenubar, /* 283 */
    Tk_ClipDrawableToRect, /* 284 */
    Tk_GetSystemDefault, /* 285 */
    Tk_UseWindow, /* 286 */
    Tk_MakeContainer, /* 287 */
    Tk_GetOtherWindow, /* 288 */
    Tk_Get3DBorderColors, /* 289 */
    Tk_MakeWindow, /* 290 */
};

/* !END!: Do not edit above this line. */


#ifdef __CYGWIN__
void *Tk_GetHINSTANCE(void)
{
    void *hInstance = NULL;

    GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
	    (const char *) &tkIntStubs, &hInstance);
    return hInstance;
}
#endif

Changes to generic/tkStubLib.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkStubLib.c --
 *
 *	Stub object that will be statically linked into extensions that want
 *	to access Tk.
 *
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright © 1998 Paul Duffin.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 * Copyright (c) 1998 Paul Duffin.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

71
72
73
74
75
76
77
78

79
80

81
82

83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
71
72
73
74
75
76
77

78
79

80
81
82
83
84
85





86

87
88
89
90
91
92
93







-
+

-
+


+


-
-
-
-
-
+
-







#undef Tk_InitStubs
MODULE_SCOPE const char *
Tk_InitStubs(
    Tcl_Interp *interp,
    const char *version,
    int exact)
{
    const char *packageName = "tk";
    const char *packageName = "Tk";
    const char *errMsg = NULL;
    void *clientData = NULL;
    ClientData clientData = NULL;
    const char *actualVersion = tclStubsPtr->tcl_PkgRequireEx(interp,
	    packageName, version, 0, &clientData);
    const TkStubs *stubsPtr = clientData;

    if (actualVersion == NULL) {
	packageName = "Tk";
	actualVersion = tclStubsPtr->tcl_PkgRequireEx(interp,
    	    packageName, version, 0, &clientData);
	if (actualVersion == NULL) {
	    return NULL;
	return NULL;
	}
    }

    if (exact) {
	const char *p = version;
	int count = 0;

	while (*p) {
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128






129
130
131
132
133
134
135
109
110
111
112
113
114
115

116
117
118






119
120
121
122
123
124
125
126
127
128
129
130
131







-
+


-
-
-
-
-
-
+
+
+
+
+
+







	    actualVersion = tclStubsPtr->tcl_PkgRequireEx(interp, packageName,
		    version, 1, NULL);
	    if (actualVersion == NULL) {
		return NULL;
	    }
	}
    }
    if (clientData == NULL) {
    if (stubsPtr == NULL) {
	errMsg = "missing stub table pointer";
    } else {
	tkStubsPtr = (const TkStubs *)clientData;
	if (tkStubsPtr->hooks) {
	    tkPlatStubsPtr = tkStubsPtr->hooks->tkPlatStubs;
	    tkIntStubsPtr = tkStubsPtr->hooks->tkIntStubs;
	    tkIntPlatStubsPtr = tkStubsPtr->hooks->tkIntPlatStubs;
	    tkIntXlibStubsPtr = tkStubsPtr->hooks->tkIntXlibStubs;
	tkStubsPtr = stubsPtr;
	if (stubsPtr->hooks) {
	    tkPlatStubsPtr = stubsPtr->hooks->tkPlatStubs;
	    tkIntStubsPtr = stubsPtr->hooks->tkIntStubs;
	    tkIntPlatStubsPtr = stubsPtr->hooks->tkIntPlatStubs;
	    tkIntXlibStubsPtr = stubsPtr->hooks->tkIntXlibStubs;
	} else {
	    tkPlatStubsPtr = NULL;
	    tkIntStubsPtr = NULL;
	    tkIntPlatStubsPtr = NULL;
	    tkIntXlibStubsPtr = NULL;
	}
	return actualVersion;

Changes to generic/tkStyle.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkStyle.c --
 *
 *	This file implements the widget styles and themes support.
 *
 * Copyright © 1990-1993 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1990-1993 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.
 */

#include "tkInt.h"

94
95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154


155
156
157
158

159
160
161
162
163
164
165
166
167
94
95
96
97
98
99
100


101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152


153
154
155
156
157

158


159
160
161
162
163
164
165







-
-
+
+








-
+




















-
+




















-
-
+
+



-
+
-
-







				 * (by a derived element). */
} Element;

/*
 * Thread-local data.
 */

typedef struct {
    size_t nbInit;			/* Number of calls to the init proc. */
typedef struct ThreadSpecificData {
    int nbInit;			/* Number of calls to the init proc. */
    Tcl_HashTable engineTable;	/* Map a name to a style engine. Keys are
				 * strings, values are Tk_StyleEngine
				 * pointers. */
    StyleEngine *defaultEnginePtr;
				/* Default, core-defined style engine. Global
				 * fallback for all engines. */
    Tcl_HashTable styleTable;	/* Map a name to a style. Keys are strings,
				 * values are Tk_Style pointers.*/
    Tcl_Size nbElements;		/* Size of the below tables. */
    int nbElements;		/* Size of the below tables. */
    Tcl_HashTable elementTable;	/* Map a name to an element Id. Keys are
				 * strings, values are integer element IDs. */
    Element *elements;		/* Array of Elements. */
} ThreadSpecificData;

static Tcl_ThreadDataKey dataKey;

/*
 * Forward declarations for functions defined later in this file:
 */

static int		CreateElement(const char *name, int create);
static void		DupStyleObjProc(Tcl_Obj *srcObjPtr,
			    Tcl_Obj *dupObjPtr);
static void		FreeElement(Element *elementPtr);
static void		FreeStyledElement(StyledElement *elementPtr);
static void		FreeStyleEngine(StyleEngine *enginePtr);
static void		FreeStyleObjProc(Tcl_Obj *objPtr);
static void		FreeWidgetSpec(StyledWidgetSpec *widgetSpecPtr);
static StyledElement *	GetStyledElement(StyleEngine *enginePtr,
			    Tcl_Size elementId);
			    int elementId);
static StyledWidgetSpec*GetWidgetSpec(StyledElement *elementPtr,
			    Tk_OptionTable optionTable);
static void		InitElement(Element *elementPtr, const char *name,
			    int id, int genericId, int created);
static void		InitStyle(Style *stylePtr, const char *name,
			    StyleEngine *enginePtr, ClientData clientData);
static void		InitStyledElement(StyledElement *elementPtr);
static void		InitStyleEngine(StyleEngine *enginePtr,
			    const char *name, StyleEngine *parentPtr);
static void		InitWidgetSpec(StyledWidgetSpec *widgetSpecPtr,
			    StyledElement *elementPtr,
			    Tk_OptionTable optionTable);
static int		SetStyleFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);

/*
 * The following structure defines the implementation of the "style" Tcl
 * object, used for drawing. The internalRep.twoPtrValue.ptr1 field of each
 * style object points to the Style structure for the stylefont, or NULL.
 */

static const TkObjType styleObjType = {
    {"style",			/* name */
static const Tcl_ObjType styleObjType = {
    "style",			/* name */
    FreeStyleObjProc,		/* freeIntRepProc */
    DupStyleObjProc,		/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    SetStyleFromAny		/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *---------------------------------------------------------------------------
 *
 * TkStylePkgInit --
 *
176
177
178
179
180
181
182
183

184
185

186
187
188
189
190
191
192
174
175
176
177
178
179
180

181
182

183
184
185
186
187
188
189
190







-
+

-
+







 *	Memory allocated.
 *
 *---------------------------------------------------------------------------
 */

void
TkStylePkgInit(
    TCL_UNUSED(TkMainInfo *))	/* The application being created. */
    TkMainInfo *mainPtr)	/* The application being created. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->nbInit != 0) {
	return;
    }

    /*
231
232
233
234
235
236
237
238

239
240

241
242
243
244
245

246
247
248
249
250
251
252
229
230
231
232
233
234
235

236
237

238
239
240
241
242

243
244
245
246
247
248
249
250







-
+

-
+




-
+







 *	Memory freed.
 *
 *---------------------------------------------------------------------------
 */

void
TkStylePkgFree(
    TCL_UNUSED(TkMainInfo *))	/* The application being deleted. */
    TkMainInfo *mainPtr)	/* The application being deleted. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;
    StyleEngine *enginePtr;
    Tcl_Size i;
    int i;

    tsdPtr->nbInit--;
    if (tsdPtr->nbInit != 0) {
	return;
    }

    /*
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274







-
+








    /*
     * Free engines.
     */

    entryPtr = Tcl_FirstHashEntry(&tsdPtr->engineTable, &search);
    while (entryPtr != NULL) {
	enginePtr = (StyleEngine *)Tcl_GetHashValue(entryPtr);
	enginePtr = Tcl_GetHashValue(entryPtr);
	FreeStyleEngine(enginePtr);
	ckfree(enginePtr);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&tsdPtr->engineTable);

    /*
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317







-
+







Tk_StyleEngine
Tk_RegisterStyleEngine(
    const char *name,		/* Name of the engine to create. NULL or empty
				 * means the default system engine. */
    Tk_StyleEngine parent)	/* The engine's parent. NULL means the default
				 * system engine. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr;
    int newEntry;
    StyleEngine *enginePtr;

    /*
     * Attempt to create a new entry in the engine table.
329
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
327
328
329
330
331
332
333


334
335
336
337
338
339
340
341
342







-
-
+
+







	return NULL;
    }

    /*
     * Allocate and intitialize a new engine.
     */

    enginePtr = (StyleEngine *)ckalloc(sizeof(StyleEngine));
    InitStyleEngine(enginePtr, (const char *)Tcl_GetHashKey(&tsdPtr->engineTable, entryPtr),
    enginePtr = ckalloc(sizeof(StyleEngine));
    InitStyleEngine(enginePtr, Tcl_GetHashKey(&tsdPtr->engineTable, entryPtr),
	    (StyleEngine *) parent);
    Tcl_SetHashValue(entryPtr, enginePtr);

    return (Tk_StyleEngine) enginePtr;
}

/*
362
363
364
365
366
367
368
369

370
371

372
373
374
375
376
377
378
360
361
362
363
364
365
366

367
368

369
370
371
372
373
374
375
376







-
+

-
+







    StyleEngine *enginePtr,	/* Points to an uninitialized engine. */
    const char *name,		/* Name of the registered engine. NULL or empty
				 * means the default system engine. Usually
				 * points to the hash key. */
    StyleEngine *parentPtr)	/* The engine's parent. NULL means the default
				 * system engine. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_Size elementId;
    int elementId;

    if (name == NULL || *name == '\0') {
	/*
	 * This is the default style engine.
	 */

	enginePtr->parentPtr = NULL;
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399







-
+







    }

    /*
     * Allocate and initialize elements array.
     */

    if (tsdPtr->nbElements > 0) {
	enginePtr->elements = (StyledElement *)ckalloc(
	enginePtr->elements = ckalloc(
		sizeof(StyledElement) * tsdPtr->nbElements);
	for (elementId = 0; elementId < tsdPtr->nbElements; elementId++) {
	    InitStyledElement(enginePtr->elements+elementId);
	}
    } else {
	enginePtr->elements = NULL;
    }
417
418
419
420
421
422
423
424

425
426

427
428
429
430
431
432
433
415
416
417
418
419
420
421

422
423

424
425
426
427
428
429
430
431







-
+

-
+







 *---------------------------------------------------------------------------
 */

static void
FreeStyleEngine(
    StyleEngine *enginePtr)	/* The style engine to free. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_Size elementId;
    int elementId;

    /*
     * Free allocated elements.
     */

    for (elementId = 0; elementId < tsdPtr->nbElements; elementId++) {
	FreeStyledElement(enginePtr->elements+elementId);
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477







-
+












-
+







 */

Tk_StyleEngine
Tk_GetStyleEngine(
    const char *name)		/* Name of the engine to retrieve. NULL or
				 * empty means the default system engine. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr;

    if (name == NULL) {
	return (Tk_StyleEngine) tsdPtr->defaultEnginePtr;
    }

    entryPtr = Tcl_FindHashEntry(&tsdPtr->engineTable, (name!=NULL?name:""));
    if (!entryPtr) {
	return NULL;
    }

    return (Tk_StyleEngine)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * InitElement --
 *
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533
517
518
519
520
521
522
523

524
525
526
527
528
529
530
531







-
+







 *	Memory freed.
 *
 *---------------------------------------------------------------------------
 */

static void
FreeElement(
    TCL_UNUSED(Element *))	/* The element to free. */
    Element *elementPtr)	/* The element to free. */
{
    /* Nothing to do. */
}

/*
 *---------------------------------------------------------------------------
 *
602
603
604
605
606
607
608
609

610
611
612
613
614

615
616
617
618
619
620
621
600
601
602
603
604
605
606

607
608
609
610
611

612
613
614
615
616
617
618
619







-
+




-
+







static int
CreateElement(
    const char *name,		/* Name of the element. */
    int create)			/* Boolean, whether the element is being
				 * created explicitly (being registered) or
				 * implicitly (by a derived element). */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr, *engineEntryPtr;
    Tcl_HashSearch search;
    int newEntry, elementId, genericId = -1;
    const char *dot;
    char *dot;
    StyleEngine *enginePtr;

    /*
     * Find or create the element.
     */

    entryPtr = Tcl_CreateHashEntry(&tsdPtr->elementTable, name, &newEntry);
640
641
642
643
644
645
646
647

648
649
650

651
652
653
654
655
656
657
658
659

660
661

662
663
664
665
666
667
668
638
639
640
641
642
643
644

645
646
647

648
649
650
651
652
653
654
655
656

657
658

659
660
661
662
663
664
665
666







-
+


-
+








-
+

-
+







    elementId = tsdPtr->nbElements++;
    Tcl_SetHashValue(entryPtr, INT2PTR(elementId));

    /*
     * Reallocate element table.
     */

    tsdPtr->elements = (Element *)ckrealloc(tsdPtr->elements,
    tsdPtr->elements = ckrealloc(tsdPtr->elements,
	    sizeof(Element) * tsdPtr->nbElements);
    InitElement(tsdPtr->elements+elementId,
	    (const char *)Tcl_GetHashKey(&tsdPtr->elementTable, entryPtr), elementId,
	    Tcl_GetHashKey(&tsdPtr->elementTable, entryPtr), elementId,
	    genericId, create);

    /*
     * Reallocate style engines' element table.
     */

    engineEntryPtr = Tcl_FirstHashEntry(&tsdPtr->engineTable, &search);
    while (engineEntryPtr != NULL) {
	enginePtr = (StyleEngine *)Tcl_GetHashValue(engineEntryPtr);
	enginePtr = Tcl_GetHashValue(engineEntryPtr);

	enginePtr->elements = (StyledElement *)ckrealloc(enginePtr->elements,
	enginePtr->elements = ckrealloc(enginePtr->elements,
		sizeof(StyledElement) * tsdPtr->nbElements);
	InitStyledElement(enginePtr->elements+elementId);

	engineEntryPtr = Tcl_NextHashEntry(&search);
    }

    return elementId;
684
685
686
687
688
689
690
691

692
693
694
695

696
697
698
699
700
701
702
682
683
684
685
686
687
688

689
690
691
692

693
694
695
696
697
698
699
700







-
+



-
+







 *---------------------------------------------------------------------------
 */

int
Tk_GetElementId(
    const char *name)		/* Name of the element. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr;
    int genericId = -1;
    const char *dot;
    char *dot;

    /*
     * Find the element Id.
     */

    entryPtr = Tcl_FindHashEntry(&tsdPtr->elementTable, name);
    if (entryPtr) {
757
758
759
760
761
762
763
764

765
766
767
768
769
770
771
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769







-
+







    Tk_ElementSpec *templatePtr)/* Static template information about the
				 * element. */
{
    int elementId;
    StyledElement *elementPtr;
    Tk_ElementSpec *specPtr;
    int nbOptions;
    Tk_ElementOptionSpec *srcOptions, *dstOptions;
    register Tk_ElementOptionSpec *srcOptions, *dstOptions;

    if (templatePtr->version != TK_STYLE_VERSION_1) {
	/*
	 * Version mismatch. Do nothing.
	 */

	return -1;
784
785
786
787
788
789
790
791

792
793

794
795
796
797
798
799
800

801
802
803
804
805
806
807
808
809

810
811
812
813
814
815
816
782
783
784
785
786
787
788

789
790

791
792
793
794
795
796
797

798
799
800
801
802
803
804
805
806

807
808
809
810
811
812
813
814







-
+

-
+






-
+








-
+








    /*
     * Initialize the styled element.
     */

    elementPtr = ((StyleEngine *) engine)->elements+elementId;

    specPtr = (Tk_ElementSpec *)ckalloc(sizeof(Tk_ElementSpec));
    specPtr = ckalloc(sizeof(Tk_ElementSpec));
    specPtr->version = templatePtr->version;
    specPtr->name = (char *)ckalloc(strlen(templatePtr->name)+1);
    specPtr->name = ckalloc(strlen(templatePtr->name)+1);
    strcpy(specPtr->name, templatePtr->name);
    nbOptions = 0;
    for (nbOptions = 0, srcOptions = templatePtr->options;
	    srcOptions->name != NULL; nbOptions++, srcOptions++) {
	/* empty body */
    }
    specPtr->options = (Tk_ElementOptionSpec *)
    specPtr->options =
	    ckalloc(sizeof(Tk_ElementOptionSpec) * (nbOptions+1));
    for (srcOptions = templatePtr->options, dstOptions = specPtr->options;
	    /* End condition within loop */; srcOptions++, dstOptions++) {
	if (srcOptions->name == NULL) {
	    dstOptions->name = NULL;
	    break;
	}

	dstOptions->name = (char *)ckalloc(strlen(srcOptions->name)+1);
	dstOptions->name = ckalloc(strlen(srcOptions->name)+1);
	strcpy(dstOptions->name, srcOptions->name);
	dstOptions->type = srcOptions->type;
    }
    specPtr->getSize = templatePtr->getSize;
    specPtr->getBox = templatePtr->getBox;
    specPtr->getBorderWidth = templatePtr->getBorderWidth;
    specPtr->draw = templatePtr->draw;
839
840
841
842
843
844
845
846

847
848
849

850
851
852
853
854
855
856
857

858
859
860
861
862
863
864
837
838
839
840
841
842
843

844
845
846

847
848
849
850
851
852
853
854

855
856
857
858
859
860
861
862







-
+


-
+







-
+







 *---------------------------------------------------------------------------
 */

static StyledElement *
GetStyledElement(
    StyleEngine *enginePtr,	/* Style engine providing the implementation.
				 * NULL means the default system engine. */
    Tcl_Size elementId)		/* Unique element ID */
    int elementId)		/* Unique element ID */
{
    StyledElement *elementPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    StyleEngine *enginePtr2;

    if (enginePtr == NULL) {
	enginePtr = tsdPtr->defaultEnginePtr;
    }

    while (elementId != TCL_INDEX_NONE && elementId < tsdPtr->nbElements) {
    while (elementId >= 0 && elementId < tsdPtr->nbElements) {
	/*
	 * Look for an implemented element through the engine chain.
	 */

	enginePtr2 = enginePtr;
	do {
	    elementPtr = enginePtr2->elements+elementId;
922
923
924
925
926
927
928
929

930
931
932
933
934
935
936
920
921
922
923
924
925
926

927
928
929
930
931
932
933
934







-
+







    }

    /*
     * Build the widget option list.
     */

    widgetSpecPtr->optionsPtr =
	    (const Tk_OptionSpec **)ckalloc(sizeof(Tk_OptionSpec *) * nbOptions);
	    ckalloc(sizeof(Tk_OptionSpec *) * nbOptions);
    for (i = 0, elementOptionPtr = elementPtr->specPtr->options;
	    i < nbOptions; i++, elementOptionPtr++) {
	widgetOptionPtr = TkGetOptionSpec(elementOptionPtr->name, optionTable);

	/*
	 * Check that the widget option type is compatible with one of the
	 * element's required types.
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018







-
+







    }

    /*
     * Create and initialize a new widget spec.
     */

    i = elementPtr->nbWidgetSpecs++;
    elementPtr->widgetSpecs = (StyledWidgetSpec *)ckrealloc(elementPtr->widgetSpecs,
    elementPtr->widgetSpecs = ckrealloc(elementPtr->widgetSpecs,
	    sizeof(StyledWidgetSpec) * elementPtr->nbWidgetSpecs);
    widgetSpecPtr = elementPtr->widgetSpecs+i;
    InitWidgetSpec(widgetSpecPtr, elementPtr, optionTable);

    return widgetSpecPtr;
}

1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
1045







-
+







 *
 *---------------------------------------------------------------------------
 */

Tk_StyledElement
Tk_GetStyledElement(
    Tk_Style style,		/* The widget style. */
    Tcl_Size elementId,		/* Unique element ID. */
    int elementId,		/* Unique element ID. */
    Tk_OptionTable optionTable)	/* Option table for the widget. */
{
    Style *stylePtr = (Style *) style;
    StyledElement *elementPtr;

    /*
     * Get an element implementation and call corresponding hook.
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
1100







-
+













-
+







 */

void
Tk_GetElementSize(
    Tk_Style style,		/* The widget style. */
    Tk_StyledElement element,	/* The styled element, previously returned by
				 * Tk_GetStyledElement. */
    void *recordPtr,		/* The widget record. */
    char *recordPtr,		/* The widget record. */
    Tk_Window tkwin,		/* The widget window. */
    int width, int height,	/* Requested size. */
    int inner,			/* If TRUE, compute the outer size according
				 * to the requested minimum inner size. If
				 * FALSE, compute the inner size according to
				 * the requested maximum outer size. */
    int *widthPtr, int *heightPtr)
				/* Returned size. */
{
    Style *stylePtr = (Style *) style;
    StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element;

    widgetSpecPtr->elementPtr->specPtr->getSize(stylePtr->clientData,
	    (char *)recordPtr, widgetSpecPtr->optionsPtr, tkwin, width, height, inner,
	    recordPtr, widgetSpecPtr->optionsPtr, tkwin, width, height, inner,
	    widthPtr, heightPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_GetElementBox --
1115
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1113
1114
1115
1116
1117
1118
1119

1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143







-
+















-
+







 */

void
Tk_GetElementBox(
    Tk_Style style,		/* The widget style. */
    Tk_StyledElement element,	/* The styled element, previously returned by
				 * Tk_GetStyledElement. */
    void *recordPtr,		/* The widget record. */
    char *recordPtr,		/* The widget record. */
    Tk_Window tkwin,		/* The widget window. */
    int x, int y,		/* Top left corner of available area. */
    int width, int height,	/* Size of available area. */
    int inner,			/* Boolean. If TRUE, compute the bounding box
				 * according to the requested inscribed box
				 * size. If FALSE, compute the inscribed box
				 * according to the requested bounding box. */
    int *xPtr, int *yPtr,	/* Returned top left corner. */
    int *widthPtr, int *heightPtr)
				/* Returned size. */
{
    Style *stylePtr = (Style *) style;
    StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element;

    widgetSpecPtr->elementPtr->specPtr->getBox(stylePtr->clientData,
	    (char *)recordPtr, widgetSpecPtr->optionsPtr, tkwin, x, y, width, height,
	    recordPtr, widgetSpecPtr->optionsPtr, tkwin, x, y, width, height,
	    inner, xPtr, yPtr, widthPtr, heightPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_GetElementBorderWidth --
1157
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167
1168

1169
1170
1171
1172
1173
1174
1175
1176







-
+






-
+







 */

int
Tk_GetElementBorderWidth(
    Tk_Style style,		/* The widget style. */
    Tk_StyledElement element,	/* The styled element, previously returned by
				 * Tk_GetStyledElement. */
    void *recordPtr,		/* The widget record. */
    char *recordPtr,		/* The widget record. */
    Tk_Window tkwin)		/* The widget window. */
{
    Style *stylePtr = (Style *) style;
    StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element;

    return widgetSpecPtr->elementPtr->specPtr->getBorderWidth(
	    stylePtr->clientData, (char *)recordPtr, widgetSpecPtr->optionsPtr, tkwin);
	    stylePtr->clientData, recordPtr, widgetSpecPtr->optionsPtr, tkwin);
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_DrawElement --
 *
1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211







-
+










-
+







 */

void
Tk_DrawElement(
    Tk_Style style,		/* The widget style. */
    Tk_StyledElement element,	/* The styled element, previously returned by
				 * Tk_GetStyledElement. */
    void *recordPtr,		/* The widget record. */
    char *recordPtr,		/* The widget record. */
    Tk_Window tkwin,		/* The widget window. */
    Drawable d,			/* Where to draw element. */
    int x, int y,		/* Top left corner of element. */
    int width, int height,	/* Size of element. */
    int state)			/* Drawing state flags. */
{
    Style *stylePtr = (Style *) style;
    StyledWidgetSpec *widgetSpecPtr = (StyledWidgetSpec *) element;

    widgetSpecPtr->elementPtr->specPtr->draw(stylePtr->clientData,
	    (char *)recordPtr, widgetSpecPtr->optionsPtr, tkwin, d, x, y, width,
	    recordPtr, widgetSpecPtr->optionsPtr, tkwin, d, x, y, width,
	    height, state);
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_CreateStyle --
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
1239







-
+







Tk_Style
Tk_CreateStyle(
    const char *name,		/* Name of the style to create. NULL or empty
				 * means the default system style. */
    Tk_StyleEngine engine,	/* The style engine. */
    ClientData clientData)	/* Private data passed as is to engine code. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr;
    int newEntry;
    Style *stylePtr;

    /*
     * Attempt to create a new entry in the style table.
1251
1252
1253
1254
1255
1256
1257
1258
1259


1260
1261
1262
1263
1264
1265
1266
1249
1250
1251
1252
1253
1254
1255


1256
1257
1258
1259
1260
1261
1262
1263
1264







-
-
+
+







	return NULL;
    }

    /*
     * Allocate and intitialize a new style.
     */

    stylePtr = (Style *)ckalloc(sizeof(Style));
    InitStyle(stylePtr, (const char *)Tcl_GetHashKey(&tsdPtr->styleTable, entryPtr),
    stylePtr = ckalloc(sizeof(Style));
    InitStyle(stylePtr, Tcl_GetHashKey(&tsdPtr->styleTable, entryPtr),
	    (engine!=NULL ? (StyleEngine*) engine : tsdPtr->defaultEnginePtr),
	    clientData);
    Tcl_SetHashValue(entryPtr, stylePtr);

    return (Tk_Style) stylePtr;
}

1342
1343
1344
1345
1346
1347
1348
1349

1350
1351

1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365


1366

1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362

1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388
1389







-
+


+












-
+

+
+
-
+














-
+








Tk_Style
Tk_GetStyle(
    Tcl_Interp *interp,		/* Interp for error return. */
    const char *name)		/* Name of the style to retrieve. NULL or empty
				 * means the default system style. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashEntry *entryPtr;
    Style *stylePtr;

    /*
     * Search for a corresponding entry in the style table.
     */

    entryPtr = Tcl_FindHashEntry(&tsdPtr->styleTable, (name!=NULL?name:""));
    if (entryPtr == NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "style \"%s\" doesn't exist", name));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "STYLE", name, NULL);
	}
	return NULL;
	return (Tk_Style) NULL;
    }
    stylePtr = Tcl_GetHashValue(entryPtr);

    return (Tk_Style)Tcl_GetHashValue(entryPtr);
    return (Tk_Style) stylePtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_FreeStyle --
 *
 *	No-op. Present only for stubs compatibility.
 *
 *---------------------------------------------------------------------------
 */

void
Tk_FreeStyle(
    TCL_UNUSED(Tk_Style))
    Tk_Style style)
{
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_AllocStyleFromObj --
1400
1401
1402
1403
1404
1405
1406


1407
1408
1409
1410
1411
1412



















































1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425


1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457


1458
1459
1460
1461
1462
1463
1464
1401
1402
1403
1404
1405
1406
1407
1408
1409






1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471


1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487

1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498






1499
1500
1501
1502
1503
1504
1505
1506
1507







+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-
-
+
+














-











-
-
-
-
-
-
+
+








Tk_Style
Tk_AllocStyleFromObj(
    Tcl_Interp *interp,		/* Interp for error return. */
    Tcl_Obj *objPtr)		/* Object containing name of the style to
				 * retrieve. */
{
    Style *stylePtr;

    if (objPtr->typePtr != &styleObjType.objType) {
	if (SetStyleFromAny(interp, objPtr) != TCL_OK) {
	    return NULL;
	}
    }
    return (Tk_Style)objPtr->internalRep.twoPtrValue.ptr1;
    if (objPtr->typePtr != &styleObjType) {
	SetStyleFromAny(interp, objPtr);
    }
    stylePtr = objPtr->internalRep.twoPtrValue.ptr1;

    return (Tk_Style) stylePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetStyleFromObj --
 *
 *	Find the style that corresponds to a given object. The style must have
 *	already been created by Tk_CreateStyle.
 *
 * Results:
 *	The return value is a token for the style that matches objPtr, or NULL
 *	if none found.
 *
 * Side effects:
 *	If the object is not already a style ref, the conversion will free any
 *	old internal representation.
 *
 *----------------------------------------------------------------------
 */

Tk_Style
Tk_GetStyleFromObj(
    Tcl_Obj *objPtr)		/* The object from which to get the style. */
{
    if (objPtr->typePtr != &styleObjType) {
	SetStyleFromAny(NULL, objPtr);
    }

    return objPtr->internalRep.twoPtrValue.ptr1;
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_FreeStyleFromObj --
 *
 *	No-op. Present only for stubs compatibility.
 *
 *---------------------------------------------------------------------------
 */
void
Tk_FreeStyleFromObj(
    Tcl_Obj *objPtr)
{
}

/*
 *----------------------------------------------------------------------
 *
 * SetStyleFromAny --
 *
 *	Convert the internal representation of a Tcl object to the style
 *	internal form.
 *
 * Results:
 *	If an error occurs is returned (e.g. the style doesn't exist), an
 *	error message will be left in interp's result and TCL_ERROR is returned.
 *	Always returns TCL_OK. If an error occurs is returned (e.g. the style
 *	doesn't exist), an error message will be left in interp's result.
 *
 * Side effects:
 *	The object is left with its typePtr pointing to styleObjType.
 *
 *----------------------------------------------------------------------
 */

static int
SetStyleFromAny(
    Tcl_Interp *interp,		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr)		/* The object to convert. */
{
    const Tcl_ObjType *typePtr;
    const char *name;
    Tk_Style style;

    /*
     * Free the old internalRep before setting the new one.
     */

    name = Tcl_GetString(objPtr);
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
	typePtr->freeIntRepProc(objPtr);
    }

    style = Tk_GetStyle(interp, name);
    if (style == NULL) {
    	return TCL_ERROR;
    }
    objPtr->typePtr = &styleObjType.objType;
    objPtr->internalRep.twoPtrValue.ptr1 = style;
    objPtr->typePtr = &styleObjType;
    objPtr->internalRep.twoPtrValue.ptr1 = Tk_GetStyle(interp, name);

    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------
 *

Changes to generic/tkTest.c.

1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18








-
-
-
+
+
+







/*
 * tkTest.c --
 *
 *	This file contains C command functions for a bunch of additional Tcl
 *	commands that are used for testing out Tcl's C interfaces. These
 *	commands are not normally included in Tcl applications; they're only
 *	used for testing.
 *
 * Copyright © 1993-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1993-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#undef STATIC_BUILD
#ifndef USE_TCL_STUBS
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68


69
70
71
72
73
74

75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98





99
100
101
102
103
104


105
106
107
108
109
110
111
27
28
29
30
31
32
33



34
35
36
37
38
39
40
41
42
43
44
45
46
47



48








49

50
51
52


53
54
55
56
57
58
59

60
61
62
63
64
65
66
67

68
69
70


71
72
73
74
75
76
77





78
79
80
81
82
83
84
85
86


87
88
89
90
91
92
93
94
95







-
-
-














-
-
-

-
-
-
-
-
-
-
-

-
+


-
-
+
+





-
+







-
+


-
-







-
-
-
-
-
+
+
+
+
+




-
-
+
+







#ifdef _WIN32
#include "tkWinInt.h"
#endif

#if defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#include "tkScrollbar.h"
#define LOG_DISPLAY(drawable) TkTestLogDisplay(drawable)
#else
#define LOG_DISPLAY(drawable) 1
#endif

#ifdef __UNIX__
#include "tkUnixInt.h"
#endif

/*
 * TCL_STORAGE_CLASS is set unconditionally to DLLEXPORT because the
 * Tcltest_Init declaration is in the source file itself, which is only
 * accessed when we are building a library.
 */

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT
#ifdef __cplusplus
extern "C" {
#endif
EXTERN int		Tktest_Init(Tcl_Interp *interp);
#ifdef __cplusplus
}
#endif

#if TCL_MAJOR_VERSION < 9
#   undef Tcl_CreateObjCommand2
#   define Tcl_CreateObjCommand2 Tcl_CreateObjCommand
#endif
/*
 * The following data structure represents the model for a test image:
 * The following data structure represents the master for a test image:
 */

typedef struct TImageModel {
    Tk_ImageModel model;	/* Tk's token for image model. */
typedef struct TImageMaster {
    Tk_ImageMaster master;	/* Tk's token for image master. */
    Tcl_Interp *interp;		/* Interpreter for application. */
    int width, height;		/* Dimensions of image. */
    char *imageName;		/* Name of image (malloc-ed). */
    char *varName;		/* Name of variable in which to log events for
				 * image (malloc-ed). */
} TImageModel;
} TImageMaster;

/*
 * The following data structure represents a particular use of a particular
 * test image.
 */

typedef struct TImageInstance {
    TImageModel *modelPtr;	/* Pointer to model for image. */
    TImageMaster *masterPtr;	/* Pointer to master for image. */
    XColor *fg;			/* Foreground color for drawing in image. */
    GC gc;			/* Graphics context for drawing in image. */
    Bool displayFailed;         /* macOS display attempted out of drawRect. */
    char buffer[200 + TCL_INTEGER_SPACE * 6]; /* message to log on display. */
} TImageInstance;

/*
 * The type record for test images:
 */

static int		ImageCreate(Tcl_Interp *interp,
			    const char *name, Tcl_Size objc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageModel model,
			    void **clientDataPtr);
static void	*ImageGet(Tk_Window tkwin, void *clientData);
static void		ImageDisplay(void *clientData,
			    const char *name, int argc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageMaster master,
			    ClientData *clientDataPtr);
static ClientData	ImageGet(Tk_Window tkwin, ClientData clientData);
static void		ImageDisplay(ClientData clientData,
			    Display *display, Drawable drawable,
			    int imageX, int imageY, int width,
			    int height, int drawableX,
			    int drawableY);
static void		ImageFree(void *clientData, Display *display);
static void		ImageDelete(void *clientData);
static void		ImageFree(ClientData clientData, Display *display);
static void		ImageDelete(ClientData clientData);

static Tk_ImageType imageType = {
    "test",			/* name */
    ImageCreate,		/* createProc */
    ImageGet,			/* getProc */
    ImageDisplay,		/* displayProc */
    ImageFree,			/* freeProc */
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
























166
167



168
169
170




171


172
173
174
175
176
177
178




















179
180



181
182
183
184





185
186



187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228

229
230

231
232

233
234

235
236
237
238



239
240

241
242

243
244

245
246

247
248
249
250
251




252
253
254

255
256
257


258
259
260
261



262
263
264


265
266
267
268
269
270
271
272
273








274
275
276
277
278
279
280
135
136
137
138
139
140
141








142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170


171
172
173
174
175
176
177







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202



203
204
205
206
207
208

209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252

253
254

255
256

257
258

259
260



261
262
263
264

265
266

267
268

269
270

271
272




273
274
275
276
277
278

279
280


281
282
283



284
285
286
287


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
+
+

-
-
+
+
+
+

+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
+
+

-
-
-
+
+
+
+
+

-
+
+
+






-
+

















-
+










-
+





-
+

-
+

-
+

-
+

-
-
-
+
+
+

-
+

-
+

-
+

-
+

-
-
-
-
+
+
+
+


-
+

-
-
+
+

-
-
-
+
+
+

-
-
+
+









+
+
+
+
+
+
+
+







				 * this widget. */
} TrivialCommandHeader;

/*
 * Forward declarations for functions defined later in this file:
 */

static Tcl_ObjCmdProc ImageObjCmd;
static Tcl_ObjCmdProc TestbitmapObjCmd;
static Tcl_ObjCmdProc TestborderObjCmd;
static Tcl_ObjCmdProc TestcolorObjCmd;
static Tcl_ObjCmdProc TestcursorObjCmd;
static Tcl_ObjCmdProc TestdeleteappsObjCmd;
static Tcl_ObjCmdProc TestfontObjCmd;
static Tcl_ObjCmdProc TestmakeexistObjCmd;
static int		ImageObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestbitmapObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestborderObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestcolorObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestcursorObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestdeleteappsObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestfontObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		TestmakeexistObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
#if !(defined(_WIN32) || defined(MAC_OSX_TK) || defined(__CYGWIN__))
static Tcl_ObjCmdProc TestmenubarObjCmd;
static int		TestmenubarObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
#endif
#if defined(_WIN32)
static Tcl_ObjCmdProc TestmetricsObjCmd;
#if defined(_WIN32) || defined(MAC_OSX_TK)
static int		TestmetricsObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
#endif
static int		TestobjconfigObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
static Tcl_ObjCmdProc TestobjconfigObjCmd;
static Tk_CustomOptionSetProc CustomOptionSet;
static Tk_CustomOptionGetProc CustomOptionGet;
static Tk_CustomOptionRestoreProc CustomOptionRestore;
static Tk_CustomOptionFreeProc CustomOptionFree;
static Tcl_ObjCmdProc TestpropObjCmd;
static Tcl_ObjCmdProc TestprintfObjCmd;
			    Tcl_Obj * const objv[]);
static int		CustomOptionSet(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    Tcl_Obj **value, char *recordPtr,
			    int internalOffset, char *saveInternalPtr,
			    int flags);
static Tcl_Obj *	CustomOptionGet(ClientData clientData,
			    Tk_Window tkwin, char *recordPtr,
			    int internalOffset);
static void		CustomOptionRestore(ClientData clientData,
			    Tk_Window tkwin, char *internalPtr,
			    char *saveInternalPtr);
static void		CustomOptionFree(ClientData clientData,
			    Tk_Window tkwin, char *internalPtr);
static int		TestpropObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static int		TestprintfObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
#if !(defined(_WIN32) || defined(MAC_OSX_TK) || defined(__CYGWIN__))
static Tcl_ObjCmdProc TestwrapperObjCmd;
static int		TestwrapperObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
#endif
static void		TrivialCmdDeletedProc(void *clientData);
static Tcl_ObjCmdProc TrivialConfigObjCmd;
static void		TrivialEventProc(void *clientData,
static void		TrivialCmdDeletedProc(ClientData clientData);
static int		TrivialConfigObjCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj * const objv[]);
static void		TrivialEventProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_ObjCmdProc TestPhotoStringMatchCmd;
static int              TestPhotoStringMatchCmd(ClientData dummy,
                            Tcl_Interp *interp, int objc, 
                            Tcl_Obj * const objv[]);

/*
 *----------------------------------------------------------------------
 *
 * Tktest_Init --
 *
 *	This function performs initialization for the Tk test suite extensions.
 *	This function performs intialization for the Tk test suite exensions.
 *
 * Results:
 *	Returns a standard Tcl completion code, and leaves an error message in
 *	the interp's result if an error occurs.
 *
 * Side effects:
 *	Creates several test commands.
 *
 *----------------------------------------------------------------------
 */

int
Tktest_Init(
    Tcl_Interp *interp)		/* Interpreter for application. */
{
    static int initialized = 0;

    if (Tcl_InitStubs(interp, "8.7-", 0) == NULL) {
    if (Tcl_InitStubs(interp, "8.6-", 0) == NULL) {
	return TCL_ERROR;
    }
    if (Tk_InitStubs(interp, TK_VERSION, 0) == NULL) {
	return TCL_ERROR;
    }

    /*
     * Create additional commands for testing Tk.
     */

    if (Tcl_PkgProvideEx(interp, "tk::test", TK_PATCH_LEVEL, NULL) == TCL_ERROR) {
    if (Tcl_PkgProvideEx(interp, "Tktest", TK_PATCH_LEVEL, NULL) == TCL_ERROR) {
	return TCL_ERROR;
    }

    Tcl_CreateObjCommand(interp, "square", SquareObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "testbitmap", TestbitmapObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testborder", TestborderObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testcolor", TestcolorObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testcursor", TestcursorObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testdeleteapps", TestdeleteappsObjCmd,
	    Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand2(interp, "testembed", TkpTestembedCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testembed", TkpTestembedCmd,
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testobjconfig", TestobjconfigObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testfont", TestfontObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testmakeexist", TestmakeexistObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testprop", TestpropObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testprintf", TestprintfObjCmd, NULL, NULL);
    Tcl_CreateObjCommand2(interp, "testtext", TkpTesttextCmd,
	    Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testphotostringmatch",
            TestPhotoStringMatchCmd, Tk_MainWindow(interp),
    Tcl_CreateObjCommand(interp, "testtext", TkpTesttextCmd,
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testphotostringmatch", 
            TestPhotoStringMatchCmd, (ClientData) Tk_MainWindow(interp),
            NULL);

#if defined(_WIN32)
#if defined(_WIN32) || defined(MAC_OSX_TK)
    Tcl_CreateObjCommand(interp, "testmetrics", TestmetricsObjCmd,
	    Tk_MainWindow(interp), NULL);
#elif !defined(__CYGWIN__) && !defined(MAC_OSX_TK)
	    (ClientData) Tk_MainWindow(interp), NULL);
#elif !defined(__CYGWIN__)
    Tcl_CreateObjCommand(interp, "testmenubar", TestmenubarObjCmd,
	    Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand2(interp, "testsend", TkpTestsendCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testsend", TkpTestsendCmd,
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testwrapper", TestwrapperObjCmd,
	    Tk_MainWindow(interp), NULL);
#endif /* _WIN32 */
	    (ClientData) Tk_MainWindow(interp), NULL);
#endif /* _WIN32 || MAC_OSX_TK */

    /*
     * Create test image type.
     */

    if (!initialized) {
	initialized = 1;
	Tk_CreateImageType(&imageType);
    }

    /*
     *	Enable testing of legacy interfaces.
     */

    if (TkOldTestInit(interp) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * And finally add any platform specific test commands.
     */

    return TkplatformtestInit(interp);
}
292
293
294
295
296
297
298

299
300
301

302
303
304
305

306
307
308
309
310
311
312
325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342
343
344
345
346
347







+


-
+




+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestbitmapObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "bitmap");
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, TkDebugBitmap(Tk_MainWindow(interp),
	    Tcl_GetString(objv[1])));
    return TCL_OK;
325
326
327
328
329
330
331

332
333
334

335
336
337
338

339
340
341
342
343
344
345
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382







+


-
+




+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestborderObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "border");
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, TkDebugBorder(Tk_MainWindow(interp),
	    Tcl_GetString(objv[1])));
    return TCL_OK;
358
359
360
361
362
363
364

365
366
367

368
369
370
371
372
373
374
395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412







+


-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestcolorObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "color");
	return TCL_ERROR;
391
392
393
394
395
396
397

398
399
400

401
402
403
404
405
406
407
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446







+


-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestcursorObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "cursor");
	return TCL_ERROR;
425
426
427
428
429
430
431

432
433
434
435
436
437




438
439
440
441
442
443
444
464
465
466
467
468
469
470
471
472
473




474
475
476
477
478
479
480
481
482
483
484







+


-
-
-
-
+
+
+
+







 * Side effects:
 *	All the interpreters created by previous calls to "testnewapp" get
 *	deleted.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestdeleteappsObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    TCL_UNUSED(Tcl_Interp *),		/* Current interpreter. */
    TCL_UNUSED(int),			/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))		/* Argument strings. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    NewApp *nextPtr;

    while (newAppPtr != NULL) {
	nextPtr = newAppPtr->nextPtr;
	Tcl_DeleteInterp(newAppPtr->interp);
	ckfree(newAppPtr);
461
462
463
464
465
466
467

468
469
470

471
472
473
474
475
476
477
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518







+


-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestobjconfigObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const options[] = {
	"alltypes", "chain1", "chain2", "chain3", "configerror", "delete", "info",
	"internal", "new", "notenoughparams", "twowindows", NULL
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
513
514
515

516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563


564
565

566
567

568
569

570
571
572
573

574
575
576
577
578
579
580

581
582
583

584
585
586

587
588
589

590
591
592


593
594
595

596
597
598

599
600
601


602
603
604

605
606
607

608
609
610

611
612
613

614
615
616
617

618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

646
647
648
649
650

651
652
653


654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672

673
674
675
676
677
678
679
680
681

682
683
684
685
686
687

688
689

690
691
692

693
694
695
696
697
698

699
700

701
702
703
704
705
706
707
708
709
710
711

712
713

714
715

716
717
718
719
720



721

722
723
724

725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740

741
742

743
744
745

746
747
748
749
750
751

752
753

754
755
756
757
758
759
760

761
762
763
764
765
766

767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
530
531
532
533
534
535
536

537
538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553
554
555

556
557

558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597



598


599
600
601

602
603

604
605

606
607
608
609

610
611




612

613
614
615

616
617
618

619
620
621

622
623


624
625
626
627

628
629
630

631
632


633
634
635
636

637
638
639

640
641
642

643
644
645
646
647
648
649
650

651
652
653
654
655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676

677

678
679
680
681
682

683
684


685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713
714

715
716
717
718
719
720

721
722

723
724
725

726
727
728
729
730
731

732
733

734
735
736
737
738
739
740
741
742
743
744

745
746

747
748

749
750
751



752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767

768
769
770
771
772
773
774

775
776

777
778
779

780
781
782
783
784
785

786
787

788
789
790
791
792
793
794

795
796
797
798
799
800

801
802
803
804
805
806
807
808

809
810
811
812
813
814
815
816







-
+








-
+









-
+

-
+















-
+






-

















-
-
-

-
-
+
+

-
+

-
+

-
+



-
+

-
-
-
-

-
+


-
+


-
+


-
+

-
-
+
+


-
+


-
+

-
-
+
+


-
+


-
+


-
+



+



-
+






-
+


















-

-
+




-
+

-
-
+
+
















+


-
+








-
+





-
+

-
+


-
+





-
+

-
+










-
+

-
+

-
+


-
-
-
+
+
+

+


-
+








-
+






-
+

-
+


-
+





-
+

-
+






-
+





-
+







-
+







	"custom option",
	CustomOptionSet,
	CustomOptionGet,
	CustomOptionRestore,
	CustomOptionFree,
	INT2PTR(1)
    };
    Tk_Window mainWin = (Tk_Window)clientData;
    Tk_Window mainWin = (Tk_Window) clientData;
    Tk_Window tkwin;
    int index, result = TCL_OK;

    /*
     * Structures used by the "chain1" subcommand and also shared by the
     * "chain2" subcommand:
     */

    typedef struct {
    typedef struct ExtensionWidgetRecord {
	TrivialCommandHeader header;
	Tcl_Obj *base1ObjPtr;
	Tcl_Obj *base2ObjPtr;
	Tcl_Obj *extension3ObjPtr;
	Tcl_Obj *extension4ObjPtr;
	Tcl_Obj *extension5ObjPtr;
    } ExtensionWidgetRecord;
    static const Tk_OptionSpec baseSpecs[] = {
	{TK_OPTION_STRING, "-one", "one", "One", "one",
		offsetof(ExtensionWidgetRecord, base1ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(ExtensionWidgetRecord, base1ObjPtr), -1, 0, NULL, 0},
	{TK_OPTION_STRING, "-two", "two", "Two", "two",
		offsetof(ExtensionWidgetRecord, base2ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(ExtensionWidgetRecord, base2ObjPtr), -1, 0, NULL, 0},
	{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
    };

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "command");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
	    sizeof(char *), "command", 0, &index)!= TCL_OK) {
	return TCL_ERROR;
    }

    switch (index) {
    case ALL_TYPES: {
	typedef struct {
	typedef struct TypesRecord {
	    TrivialCommandHeader header;
	    Tcl_Obj *booleanPtr;
	    Tcl_Obj *integerPtr;
	    Tcl_Obj *doublePtr;
	    Tcl_Obj *stringPtr;
	    Tcl_Obj *stringTablePtr;
	    Tcl_Obj *stringTablePtr2;
	    Tcl_Obj *colorPtr;
	    Tcl_Obj *fontPtr;
	    Tcl_Obj *bitmapPtr;
	    Tcl_Obj *borderPtr;
	    Tcl_Obj *reliefPtr;
	    Tcl_Obj *cursorPtr;
	    Tcl_Obj *activeCursorPtr;
	    Tcl_Obj *justifyPtr;
	    Tcl_Obj *anchorPtr;
	    Tcl_Obj *pixelPtr;
	    Tcl_Obj *mmPtr;
	    Tcl_Obj *customPtr;
	} TypesRecord;
	TypesRecord *recordPtr;
	static const char *const stringTable[] = {
	    "one", "two", "three", "four", NULL
	};
	static const char *const stringTable2[] = {
	    "one", "two", NULL
	};
	static const Tk_OptionSpec typesSpecs[] = {
	    {TK_OPTION_BOOLEAN, "-boolean", "boolean", "Boolean", NULL,
		offsetof(TypesRecord, booleanPtr), TCL_INDEX_NONE, TK_CONFIG_NULL_OK, 0, 0x1},
	    {TK_OPTION_BOOLEAN, "-boolean", "boolean", "Boolean", "1",
		Tk_Offset(TypesRecord, booleanPtr), -1, 0, 0, 0x1},
	    {TK_OPTION_INT, "-integer", "integer", "Integer", "7",
		offsetof(TypesRecord, integerPtr), TCL_INDEX_NONE, 0, 0, 0x2},
		Tk_Offset(TypesRecord, integerPtr), -1, 0, 0, 0x2},
	    {TK_OPTION_DOUBLE, "-double", "double", "Double", "3.14159",
		offsetof(TypesRecord, doublePtr), TCL_INDEX_NONE, 0, 0, 0x4},
		Tk_Offset(TypesRecord, doublePtr), -1, 0, 0, 0x4},
	    {TK_OPTION_STRING, "-string", "string", "String",
		"foo", offsetof(TypesRecord, stringPtr), TCL_INDEX_NONE,
		"foo", Tk_Offset(TypesRecord, stringPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x8},
	    {TK_OPTION_STRING_TABLE,
		"-stringtable", "StringTable", "stringTable",
		"one", offsetof(TypesRecord, stringTablePtr), TCL_INDEX_NONE,
		"one", Tk_Offset(TypesRecord, stringTablePtr), -1,
		TK_CONFIG_NULL_OK, stringTable, 0x10},
	    {TK_OPTION_STRING_TABLE,
		"-stringtable2", "StringTable2", "stringTable2",
		"two", offsetof(TypesRecord, stringTablePtr2), TCL_INDEX_NONE,
		TK_CONFIG_NULL_OK, stringTable2, 0x10},
	    {TK_OPTION_COLOR, "-color", "color", "Color",
		"red", offsetof(TypesRecord, colorPtr), TCL_INDEX_NONE,
		"red", Tk_Offset(TypesRecord, colorPtr), -1,
		TK_CONFIG_NULL_OK, "black", 0x20},
	    {TK_OPTION_FONT, "-font", "font", "Font", "Helvetica 12",
		offsetof(TypesRecord, fontPtr), TCL_INDEX_NONE,
		Tk_Offset(TypesRecord, fontPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x40},
	    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap", "gray50",
		offsetof(TypesRecord, bitmapPtr), TCL_INDEX_NONE,
		Tk_Offset(TypesRecord, bitmapPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x80},
	    {TK_OPTION_BORDER, "-border", "border", "Border",
		"blue", offsetof(TypesRecord, borderPtr), TCL_INDEX_NONE,
		"blue", Tk_Offset(TypesRecord, borderPtr), -1,
		TK_CONFIG_NULL_OK, "white", 0x100},
	    {TK_OPTION_RELIEF, "-relief", "relief", "Relief", NULL,
		offsetof(TypesRecord, reliefPtr), TCL_INDEX_NONE,
	    {TK_OPTION_RELIEF, "-relief", "relief", "Relief", "raised",
		Tk_Offset(TypesRecord, reliefPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x200},
	    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", "xterm",
		offsetof(TypesRecord, cursorPtr), TCL_INDEX_NONE,
		Tk_Offset(TypesRecord, cursorPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x400},
	    {TK_OPTION_JUSTIFY, "-justify", NULL, NULL, "left",
		offsetof(TypesRecord, justifyPtr), TCL_INDEX_NONE,
		Tk_Offset(TypesRecord, justifyPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x800},
	    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", "center",
		offsetof(TypesRecord, anchorPtr), TCL_INDEX_NONE,
	    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", NULL,
		Tk_Offset(TypesRecord, anchorPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x1000},
	    {TK_OPTION_PIXELS, "-pixel", "pixel", "Pixel",
		"1", offsetof(TypesRecord, pixelPtr), TCL_INDEX_NONE,
		"1", Tk_Offset(TypesRecord, pixelPtr), -1,
		TK_CONFIG_NULL_OK, 0, 0x2000},
	    {TK_OPTION_CUSTOM, "-custom", NULL, NULL,
		"", offsetof(TypesRecord, customPtr), TCL_INDEX_NONE,
		"", Tk_Offset(TypesRecord, customPtr), -1,
		TK_CONFIG_NULL_OK, &CustomOption, 0x4000},
	    {TK_OPTION_SYNONYM, "-synonym", NULL, NULL,
		NULL, 0, TCL_INDEX_NONE, 0, "-color", 0x8000},
		NULL, 0, -1, 0, "-color", 0x8000},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};
	Tk_OptionTable optionTable;
	Tk_Window tkwin;

	optionTable = Tk_CreateOptionTable(interp, typesSpecs);
	tables[index] = optionTable;
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window)clientData,
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window) clientData,
		Tcl_GetString(objv[2]), NULL);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	Tk_SetClass(tkwin, "Test");

	recordPtr = (TypesRecord *)ckalloc(sizeof(TypesRecord));
	recordPtr = ckalloc(sizeof(TypesRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = optionTable;
	recordPtr->header.tkwin = tkwin;
	recordPtr->booleanPtr = NULL;
	recordPtr->integerPtr = NULL;
	recordPtr->doublePtr = NULL;
	recordPtr->stringPtr = NULL;
	recordPtr->colorPtr = NULL;
	recordPtr->fontPtr = NULL;
	recordPtr->bitmapPtr = NULL;
	recordPtr->borderPtr = NULL;
	recordPtr->reliefPtr = NULL;
	recordPtr->cursorPtr = NULL;
	recordPtr->justifyPtr = NULL;
	recordPtr->anchorPtr = NULL;
	recordPtr->pixelPtr = NULL;
	recordPtr->mmPtr = NULL;
	recordPtr->stringTablePtr = NULL;
	recordPtr->stringTablePtr2 = NULL;
	recordPtr->customPtr = NULL;
	result = Tk_InitOptions(interp, recordPtr, optionTable,
	result = Tk_InitOptions(interp, (char *) recordPtr, optionTable,
		tkwin);
	if (result == TCL_OK) {
	    recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
		    Tcl_GetString(objv[2]), TrivialConfigObjCmd,
		    recordPtr, TrivialCmdDeletedProc);
		    (ClientData) recordPtr, TrivialCmdDeletedProc);
	    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
		    TrivialEventProc, recordPtr);
	    result = Tk_SetOptions(interp, recordPtr, optionTable,
		    TrivialEventProc, (ClientData) recordPtr);
	    result = Tk_SetOptions(interp, (char *) recordPtr, optionTable,
		    objc-3, objv+3, tkwin, NULL, NULL);
	    if (result != TCL_OK) {
		Tk_DestroyWindow(tkwin);
	    }
	} else {
	    Tk_DestroyWindow(tkwin);
	    ckfree(recordPtr);
	}
	if (result == TCL_OK) {
	    Tcl_SetObjResult(interp, objv[2]);
	}
	break;
    }

    case CHAIN1: {
	ExtensionWidgetRecord *recordPtr;
	Tk_Window tkwin;
	Tk_OptionTable optionTable;

	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window)clientData,
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window) clientData,
		Tcl_GetString(objv[2]), NULL);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	Tk_SetClass(tkwin, "Test");
	optionTable = Tk_CreateOptionTable(interp, baseSpecs);
	tables[index] = optionTable;

	recordPtr = (ExtensionWidgetRecord *)ckalloc(sizeof(ExtensionWidgetRecord));
	recordPtr = ckalloc(sizeof(ExtensionWidgetRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = optionTable;
	recordPtr->header.tkwin = tkwin;
	recordPtr->base1ObjPtr = recordPtr->base2ObjPtr = NULL;
	recordPtr->extension3ObjPtr = recordPtr->extension4ObjPtr = NULL;
	result = Tk_InitOptions(interp, recordPtr, optionTable, tkwin);
	result = Tk_InitOptions(interp, (char *)recordPtr, optionTable, tkwin);
	if (result == TCL_OK) {
	    result = Tk_SetOptions(interp, recordPtr, optionTable,
	    result = Tk_SetOptions(interp, (char *) recordPtr, optionTable,
		    objc-3, objv+3, tkwin, NULL, NULL);
	    if (result != TCL_OK) {
		Tk_FreeConfigOptions(recordPtr, optionTable, tkwin);
		Tk_FreeConfigOptions((char *) recordPtr, optionTable, tkwin);
	    }
	}
	if (result == TCL_OK) {
	    recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
		    Tcl_GetString(objv[2]), TrivialConfigObjCmd,
		    recordPtr, TrivialCmdDeletedProc);
		    (ClientData) recordPtr, TrivialCmdDeletedProc);
	    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
		    TrivialEventProc, recordPtr);
		    TrivialEventProc, (ClientData) recordPtr);
	    Tcl_SetObjResult(interp, objv[2]);
	}
	break;
    }

    case CHAIN2:
    case CHAIN3: {
	ExtensionWidgetRecord *recordPtr;
	static const Tk_OptionSpec extensionSpecs[] = {
	    {TK_OPTION_STRING, "-three", "three", "Three", "three",
		offsetof(ExtensionWidgetRecord, extension3ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(ExtensionWidgetRecord, extension3ObjPtr), -1, 0, NULL, 0},
	    {TK_OPTION_STRING, "-four", "four", "Four", "four",
		offsetof(ExtensionWidgetRecord, extension4ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(ExtensionWidgetRecord, extension4ObjPtr), -1, 0, NULL, 0},
	    {TK_OPTION_STRING, "-two", "two", "Two", "two and a half",
		offsetof(ExtensionWidgetRecord, base2ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(ExtensionWidgetRecord, base2ObjPtr), -1, 0, NULL, 0},
	    {TK_OPTION_STRING,
		"-oneAgain", "oneAgain", "OneAgain", "one again",
		offsetof(ExtensionWidgetRecord, extension5ObjPtr), TCL_INDEX_NONE, 0, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0,
		baseSpecs, 0}
		Tk_Offset(ExtensionWidgetRecord, extension5ObjPtr), -1, 0, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0,
		(ClientData) baseSpecs, 0}
	};
	Tk_Window tkwin;
	Tk_OptionTable optionTable;

	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window)clientData,
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window) clientData,
		Tcl_GetString(objv[2]), NULL);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	Tk_SetClass(tkwin, "Test");
	optionTable = Tk_CreateOptionTable(interp, extensionSpecs);
	tables[index] = optionTable;

	recordPtr = (ExtensionWidgetRecord *)ckalloc(sizeof(ExtensionWidgetRecord));
	recordPtr = ckalloc(sizeof(ExtensionWidgetRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = optionTable;
	recordPtr->header.tkwin = tkwin;
	recordPtr->base1ObjPtr = recordPtr->base2ObjPtr = NULL;
	recordPtr->extension3ObjPtr = recordPtr->extension4ObjPtr = NULL;
	recordPtr->extension5ObjPtr = NULL;
	result = Tk_InitOptions(interp, recordPtr, optionTable, tkwin);
	result = Tk_InitOptions(interp, (char *)recordPtr, optionTable, tkwin);
	if (result == TCL_OK) {
	    result = Tk_SetOptions(interp, recordPtr, optionTable,
	    result = Tk_SetOptions(interp, (char *) recordPtr, optionTable,
		    objc-3, objv+3, tkwin, NULL, NULL);
	    if (result != TCL_OK) {
		Tk_FreeConfigOptions(recordPtr, optionTable, tkwin);
		Tk_FreeConfigOptions((char *) recordPtr, optionTable, tkwin);
	    }
	}
	if (result == TCL_OK) {
	    recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
		    Tcl_GetString(objv[2]), TrivialConfigObjCmd,
		    recordPtr, TrivialCmdDeletedProc);
		    (ClientData) recordPtr, TrivialCmdDeletedProc);
	    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
		    TrivialEventProc, recordPtr);
		    TrivialEventProc, (ClientData) recordPtr);
	    Tcl_SetObjResult(interp, objv[2]);
	}
	break;
    }

    case CONFIG_ERROR: {
	typedef struct {
	typedef struct ErrorWidgetRecord {
	    Tcl_Obj *intPtr;
	} ErrorWidgetRecord;
	ErrorWidgetRecord widgetRecord;
	static const Tk_OptionSpec errorSpecs[] = {
	    {TK_OPTION_INT, "-int", "integer", "Integer", "bogus",
		offsetof(ErrorWidgetRecord, intPtr), 0, TK_OPTION_NULL_OK, NULL, 0},
		Tk_Offset(ErrorWidgetRecord, intPtr), 0, 0, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};
	Tk_OptionTable optionTable;

	widgetRecord.intPtr = NULL;
	optionTable = Tk_CreateOptionTable(interp, errorSpecs);
	tables[index] = optionTable;
	return Tk_InitOptions(interp, &widgetRecord, optionTable,
	return Tk_InitOptions(interp, (char *) &widgetRecord, optionTable,
		(Tk_Window) NULL);
    }

    case DEL:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "tableName");
	    return TCL_ERROR;
807
808
809
810
811
812
813
814

815
816

817
818
819
820
821
822
823
842
843
844
845
846
847
848

849
850

851
852
853
854
855
856
857
858







-
+

-
+







    case INTERNAL: {
	/*
	 * This command is similar to the "alltypes" command except that it
	 * stores all the configuration options as internal forms instead of
	 * objects.
	 */

	typedef struct {
	typedef struct InternalRecord {
	    TrivialCommandHeader header;
	    int boolValue;
	    int boolean;
	    int integer;
	    double doubleValue;
	    char *string;
	    int index;
	    XColor *colorPtr;
	    Tk_Font tkfont;
	    Pixmap bitmap;
833
834
835
836
837
838
839
840

841
842

843
844

845
846

847
848
849
850

851
852
853

854
855
856

857
858
859

860
861
862

863
864
865


866
867
868

869
870
871
872
873
874
875





876
877

878
879
880

881
882
883

884
885
886

887
888
889

890
891
892
893

894
895
896
897
898
899
900

901
902
903
904

905
906
907
908
909
910
911
912
913
914
915
916

917
918
919
920
921

922
923
924
925
926
927
928
929

930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945

946
947
948
949
950
951
952
953
954
955
956

957
958

959
960

961
962

963
964

965
966
967
968
969
970
971
972
973

974
975
976
977
978
979
980
981
982

983
984
985

986
987
988
989
990
991

992
993

994
995
996
997
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010

1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023


1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038
1039



1040
1041

1042
1043
1044
1045


1046
1047
1048
1049
1050
1051
1052

1053
1054
1055

1056
1057
1058
1059
1060

1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
868
869
870
871
872
873
874

875
876

877
878

879
880

881
882
883
884

885
886
887

888
889
890

891
892
893

894
895
896

897
898


899
900
901
902

903
904
905





906
907
908
909
910
911

912
913
914

915
916
917

918
919
920

921
922
923
924
925
926
927
928

929
930
931
932
933
934
935

936
937
938
939

940
941
942
943
944
945
946
947
948
949
950
951

952
953
954
955
956

957
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980

981
982
983
984
985
986
987
988
989
990
991

992
993

994
995

996
997

998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
1016
1017

1018
1019
1020

1021
1022
1023
1024
1025
1026

1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045

1046
1047
1048

1049
1050
1051
1052
1053
1054
1055
1056
1057


1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072



1073
1074
1075
1076

1077
1078
1079


1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090

1091
1092
1093
1094
1095

1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117







-
+

-
+

-
+

-
+



-
+


-
+


-
+


-
+


-
+

-
-
+
+


-
+


-
-
-
-
-
+
+
+
+
+

-
+


-
+


-
+


-
+



+



-
+






-
+



-
+











-
+




-
+







-
+















-
+










-
+

-
+

-
+

-
+

-
+








-
+








-
+


-
+





-
+

-
+










-
+





-
+


-
+








-
-
+
+










-
+


-
-
-
+
+
+

-
+


-
-
+
+






-
+


-
+




-
+


-
+










-
+







	} InternalRecord;
	InternalRecord *recordPtr;
	static const char *const internalStringTable[] = {
	    "one", "two", "three", "four", NULL
	};
	static const Tk_OptionSpec internalSpecs[] = {
	    {TK_OPTION_BOOLEAN, "-boolean", "boolean", "Boolean", "1",
		TCL_INDEX_NONE, offsetof(InternalRecord, boolValue), TK_CONFIG_NULL_OK, 0, 0x1},
		-1, Tk_Offset(InternalRecord, boolean), 0, 0, 0x1},
	    {TK_OPTION_INT, "-integer", "integer", "Integer", "148962237",
		TCL_INDEX_NONE, offsetof(InternalRecord, integer), 0, 0, 0x2},
		-1, Tk_Offset(InternalRecord, integer), 0, 0, 0x2},
	    {TK_OPTION_DOUBLE, "-double", "double", "Double", "3.14159",
		TCL_INDEX_NONE, offsetof(InternalRecord, doubleValue), 0, 0, 0x4},
		-1, Tk_Offset(InternalRecord, doubleValue), 0, 0, 0x4},
	    {TK_OPTION_STRING, "-string", "string", "String", "foo",
		TCL_INDEX_NONE, offsetof(InternalRecord, string),
		-1, Tk_Offset(InternalRecord, string),
		TK_CONFIG_NULL_OK, 0, 0x8},
	    {TK_OPTION_STRING_TABLE,
		"-stringtable", "StringTable", "stringTable", "one",
		TCL_INDEX_NONE, offsetof(InternalRecord, index),
		-1, Tk_Offset(InternalRecord, index),
		TK_CONFIG_NULL_OK, internalStringTable, 0x10},
	    {TK_OPTION_COLOR, "-color", "color", "Color", "red",
		TCL_INDEX_NONE, offsetof(InternalRecord, colorPtr),
		-1, Tk_Offset(InternalRecord, colorPtr),
		TK_CONFIG_NULL_OK, "black", 0x20},
	    {TK_OPTION_FONT, "-font", "font", "Font", "Helvetica 12",
		TCL_INDEX_NONE, offsetof(InternalRecord, tkfont),
		-1, Tk_Offset(InternalRecord, tkfont),
		TK_CONFIG_NULL_OK, 0, 0x40},
	    {TK_OPTION_BITMAP, "-bitmap", "bitmap", "Bitmap", "gray50",
		TCL_INDEX_NONE, offsetof(InternalRecord, bitmap),
		-1, Tk_Offset(InternalRecord, bitmap),
		TK_CONFIG_NULL_OK, 0, 0x80},
	    {TK_OPTION_BORDER, "-border", "border", "Border", "blue",
		TCL_INDEX_NONE, offsetof(InternalRecord, border),
		-1, Tk_Offset(InternalRecord, border),
		TK_CONFIG_NULL_OK, "white", 0x100},
	    {TK_OPTION_RELIEF, "-relief", "relief", "Relief", NULL,
		TCL_INDEX_NONE, offsetof(InternalRecord, relief),
	    {TK_OPTION_RELIEF, "-relief", "relief", "Relief", "raised",
		-1, Tk_Offset(InternalRecord, relief),
		TK_CONFIG_NULL_OK, 0, 0x200},
	    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", "xterm",
		TCL_INDEX_NONE, offsetof(InternalRecord, cursor),
		-1, Tk_Offset(InternalRecord, cursor),
		TK_CONFIG_NULL_OK, 0, 0x400},
	    {TK_OPTION_JUSTIFY, "-justify", NULL, NULL, "left",
		TCL_INDEX_NONE, offsetof(InternalRecord, justify),
		TK_CONFIG_NULL_OK|TK_OPTION_ENUM_VAR, 0, 0x800},
	    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", "center",
		TCL_INDEX_NONE, offsetof(InternalRecord, anchor),
		TK_CONFIG_NULL_OK|TK_OPTION_ENUM_VAR, 0, 0x1000},
		-1, Tk_Offset(InternalRecord, justify),
		TK_CONFIG_NULL_OK, 0, 0x800},
	    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", NULL,
		-1, Tk_Offset(InternalRecord, anchor),
		TK_CONFIG_NULL_OK, 0, 0x1000},
	    {TK_OPTION_PIXELS, "-pixel", "pixel", "Pixel", "1",
		TCL_INDEX_NONE, offsetof(InternalRecord, pixels),
		-1, Tk_Offset(InternalRecord, pixels),
		TK_CONFIG_NULL_OK, 0, 0x2000},
	    {TK_OPTION_WINDOW, "-window", "window", "Window", NULL,
		TCL_INDEX_NONE, offsetof(InternalRecord, tkwin),
		-1, Tk_Offset(InternalRecord, tkwin),
		TK_CONFIG_NULL_OK, 0, 0},
	    {TK_OPTION_CUSTOM, "-custom", NULL, NULL, "",
		TCL_INDEX_NONE, offsetof(InternalRecord, custom),
		-1, Tk_Offset(InternalRecord, custom),
		TK_CONFIG_NULL_OK, &CustomOption, 0x4000},
	    {TK_OPTION_SYNONYM, "-synonym", NULL, NULL,
		NULL, TCL_INDEX_NONE, TCL_INDEX_NONE, 0, "-color", 0x8000},
		NULL, -1, -1, 0, "-color", 0x8000},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};
	Tk_OptionTable optionTable;
	Tk_Window tkwin;

	optionTable = Tk_CreateOptionTable(interp, internalSpecs);
	tables[index] = optionTable;
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window)clientData,
	tkwin = Tk_CreateWindowFromPath(interp, (Tk_Window) clientData,
		Tcl_GetString(objv[2]), NULL);
	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	Tk_SetClass(tkwin, "Test");

	recordPtr = (InternalRecord *)ckalloc(sizeof(InternalRecord));
	recordPtr = ckalloc(sizeof(InternalRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = optionTable;
	recordPtr->header.tkwin = tkwin;
	recordPtr->boolValue = 0;
	recordPtr->boolean = 0;
	recordPtr->integer = 0;
	recordPtr->doubleValue = 0.0;
	recordPtr->string = NULL;
	recordPtr->index = 0;
	recordPtr->colorPtr = NULL;
	recordPtr->tkfont = NULL;
	recordPtr->bitmap = None;
	recordPtr->border = NULL;
	recordPtr->relief = TK_RELIEF_FLAT;
	recordPtr->cursor = NULL;
	recordPtr->justify = TK_JUSTIFY_LEFT;
	recordPtr->anchor = TK_ANCHOR_CENTER;
	recordPtr->anchor = TK_ANCHOR_N;
	recordPtr->pixels = 0;
	recordPtr->mm = 0.0;
	recordPtr->tkwin = NULL;
	recordPtr->custom = NULL;
	result = Tk_InitOptions(interp, recordPtr, optionTable,
	result = Tk_InitOptions(interp, (char *) recordPtr, optionTable,
		tkwin);
	if (result == TCL_OK) {
	    recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
		    Tcl_GetString(objv[2]), TrivialConfigObjCmd,
		    recordPtr, TrivialCmdDeletedProc);
	    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
		    TrivialEventProc, recordPtr);
	    result = Tk_SetOptions(interp, recordPtr, optionTable,
	    result = Tk_SetOptions(interp, (char *) recordPtr, optionTable,
		    objc - 3, objv + 3, tkwin, NULL, NULL);
	    if (result != TCL_OK) {
		Tk_DestroyWindow(tkwin);
	    }
	} else {
	    Tk_DestroyWindow(tkwin);
	    ckfree(recordPtr);
	}
	if (result == TCL_OK) {
	    Tcl_SetObjResult(interp, objv[2]);
	}
	break;
    }

    case NEW: {
	typedef struct {
	typedef struct FiveRecord {
	    TrivialCommandHeader header;
	    Tcl_Obj *one;
	    Tcl_Obj *two;
	    Tcl_Obj *three;
	    Tcl_Obj *four;
	    Tcl_Obj *five;
	} FiveRecord;
	FiveRecord *recordPtr;
	static const Tk_OptionSpec smallSpecs[] = {
	    {TK_OPTION_INT, "-one", "one", "One", "1",
		offsetof(FiveRecord, one), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(FiveRecord, one), -1, 0, NULL, 0},
	    {TK_OPTION_INT, "-two", "two", "Two", "2",
		offsetof(FiveRecord, two), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(FiveRecord, two), -1, 0, NULL, 0},
	    {TK_OPTION_INT, "-three", "three", "Three", "3",
		offsetof(FiveRecord, three), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(FiveRecord, three), -1, 0, NULL, 0},
	    {TK_OPTION_INT, "-four", "four", "Four", "4",
		offsetof(FiveRecord, four), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(FiveRecord, four), -1, 0, NULL, 0},
	    {TK_OPTION_STRING, "-five", NULL, NULL, NULL,
		offsetof(FiveRecord, five), TCL_INDEX_NONE, 0, NULL, 0},
		Tk_Offset(FiveRecord, five), -1, 0, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "new name ?-option value ...?");
	    return TCL_ERROR;
	}

	recordPtr = (FiveRecord *)ckalloc(sizeof(FiveRecord));
	recordPtr = ckalloc(sizeof(FiveRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = Tk_CreateOptionTable(interp,
		smallSpecs);
	tables[index] = recordPtr->header.optionTable;
	recordPtr->header.tkwin = NULL;
	recordPtr->one = recordPtr->two = recordPtr->three = NULL;
	recordPtr->four = recordPtr->five = NULL;
	Tcl_SetObjResult(interp, objv[2]);
	result = Tk_InitOptions(interp, recordPtr,
	result = Tk_InitOptions(interp, (char *) recordPtr,
		recordPtr->header.optionTable, (Tk_Window) NULL);
	if (result == TCL_OK) {
	    result = Tk_SetOptions(interp, recordPtr,
	    result = Tk_SetOptions(interp, (char *) recordPtr,
		    recordPtr->header.optionTable, objc - 3, objv + 3,
		    (Tk_Window) NULL, NULL, NULL);
	    if (result == TCL_OK) {
		recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
			Tcl_GetString(objv[2]), TrivialConfigObjCmd,
			recordPtr, TrivialCmdDeletedProc);
			(ClientData) recordPtr, TrivialCmdDeletedProc);
	    } else {
		Tk_FreeConfigOptions(recordPtr,
		Tk_FreeConfigOptions((char *) recordPtr,
			recordPtr->header.optionTable, (Tk_Window) NULL);
	    }
	}
	if (result != TCL_OK) {
	    ckfree(recordPtr);
	}

	break;
    }
    case NOT_ENOUGH_PARAMS: {
	typedef struct {
	typedef struct NotEnoughRecord {
	    Tcl_Obj *fooObjPtr;
	} NotEnoughRecord;
	NotEnoughRecord record;
	static const Tk_OptionSpec errorSpecs[] = {
	    {TK_OPTION_INT, "-foo", "foo", "Foo", "0",
		offsetof(NotEnoughRecord, fooObjPtr), 0, 0, NULL, 0},
		Tk_Offset(NotEnoughRecord, fooObjPtr), 0, 0, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};
	Tcl_Obj *newObjPtr = Tcl_NewStringObj("-foo", TCL_INDEX_NONE);
	Tcl_Obj *newObjPtr = Tcl_NewStringObj("-foo", -1);
	Tk_OptionTable optionTable;

	record.fooObjPtr = NULL;

	tkwin = Tk_CreateWindowFromPath(interp, mainWin, ".config", NULL);
	Tk_SetClass(tkwin, "Config");
	optionTable = Tk_CreateOptionTable(interp, errorSpecs);
	tables[index] = optionTable;
	Tk_InitOptions(interp, &record, optionTable, tkwin);
	if (Tk_SetOptions(interp, &record, optionTable, 1,
	Tk_InitOptions(interp, (char *) &record, optionTable, tkwin);
	if (Tk_SetOptions(interp, (char *) &record, optionTable, 1,
		&newObjPtr, tkwin, NULL, NULL) != TCL_OK) {
	    result = TCL_ERROR;
	}
	Tcl_DecrRefCount(newObjPtr);
	Tk_FreeConfigOptions( (char *) &record, optionTable, tkwin);
	Tk_DestroyWindow(tkwin);
	return result;
    }

    case TWO_WINDOWS: {
	typedef struct {
	typedef struct SlaveRecord {
	    TrivialCommandHeader header;
	    Tcl_Obj *windowPtr;
	} ContentRecord;
	ContentRecord *recordPtr;
	static const Tk_OptionSpec contentSpecs[] = {
	} SlaveRecord;
	SlaveRecord *recordPtr;
	static const Tk_OptionSpec slaveSpecs[] = {
	    {TK_OPTION_WINDOW, "-window", "window", "Window", ".bar",
		offsetof(ContentRecord, windowPtr), TCL_INDEX_NONE, TK_CONFIG_NULL_OK, NULL, 0},
		Tk_Offset(SlaveRecord, windowPtr), -1, TK_CONFIG_NULL_OK, NULL, 0},
	    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0}
	};
	tkwin = Tk_CreateWindowFromPath(interp,
		(Tk_Window)clientData, Tcl_GetString(objv[2]), NULL);
	Tk_Window tkwin = Tk_CreateWindowFromPath(interp,
		(Tk_Window) clientData, Tcl_GetString(objv[2]), NULL);

	if (tkwin == NULL) {
	    return TCL_ERROR;
	}
	Tk_SetClass(tkwin, "Test");

	recordPtr = (ContentRecord *)ckalloc(sizeof(ContentRecord));
	recordPtr = ckalloc(sizeof(SlaveRecord));
	recordPtr->header.interp = interp;
	recordPtr->header.optionTable = Tk_CreateOptionTable(interp,
		contentSpecs);
		slaveSpecs);
	tables[index] = recordPtr->header.optionTable;
	recordPtr->header.tkwin = tkwin;
	recordPtr->windowPtr = NULL;

	result = Tk_InitOptions(interp, recordPtr,
	result = Tk_InitOptions(interp,  (char *) recordPtr,
		recordPtr->header.optionTable, tkwin);
	if (result == TCL_OK) {
	    result = Tk_SetOptions(interp, recordPtr,
	    result = Tk_SetOptions(interp, (char *) recordPtr,
		    recordPtr->header.optionTable, objc - 3, objv + 3,
		    tkwin, NULL, NULL);
	    if (result == TCL_OK) {
		recordPtr->header.widgetCmd = Tcl_CreateObjCommand(interp,
			Tcl_GetString(objv[2]), TrivialConfigObjCmd,
			recordPtr, TrivialCmdDeletedProc);
		Tk_CreateEventHandler(tkwin, StructureNotifyMask,
			TrivialEventProc, recordPtr);
		Tcl_SetObjResult(interp, objv[2]);
	    } else {
		Tk_FreeConfigOptions(recordPtr,
		Tk_FreeConfigOptions((char *) recordPtr,
			recordPtr->header.optionTable, tkwin);
	    }
	}
	if (result != TCL_OK) {
	    Tk_DestroyWindow(tkwin);
	    ckfree(recordPtr);
	}
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144

1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175

1176
1177
1178
1179
1180

1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157

1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180

1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207

1208
1209
1210
1211

1212
1213
1214
1215
1216

1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227
1228
1229







+


-
+













-
+




-
+

















-
+










-
+







-
+







-
+



-
+




-
+




-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TrivialConfigObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int result = TCL_OK;
    static const char *const options[] = {
	"cget", "configure", "csave", NULL
    };
    enum {
	CGET, CONFIGURE, CSAVE
    };
    Tcl_Obj *resultObjPtr;
    int index, mask;
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *)clientData;
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *) clientData;
    Tk_Window tkwin = headerPtr->tkwin;
    Tk_SavedOptions saved;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
	    sizeof(char *), "command", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Tcl_Preserve(clientData);

    switch (index) {
    case CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    goto done;
	}
	resultObjPtr = Tk_GetOptionValue(interp, clientData,
	resultObjPtr = Tk_GetOptionValue(interp, (char *) clientData,
		headerPtr->optionTable, objv[2], tkwin);
	if (resultObjPtr != NULL) {
	    Tcl_SetObjResult(interp, resultObjPtr);
	    result = TCL_OK;
	} else {
	    result = TCL_ERROR;
	}
	break;
    case CONFIGURE:
	if (objc == 2) {
	    resultObjPtr = Tk_GetOptionInfo(interp, clientData,
	    resultObjPtr = Tk_GetOptionInfo(interp, (char *) clientData,
		    headerPtr->optionTable, NULL, tkwin);
	    if (resultObjPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, resultObjPtr);
	    }
	} else if (objc == 3) {
	    resultObjPtr = Tk_GetOptionInfo(interp, clientData,
	    resultObjPtr = Tk_GetOptionInfo(interp, (char *) clientData,
		    headerPtr->optionTable, objv[2], tkwin);
	    if (resultObjPtr == NULL) {
		result = TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, resultObjPtr);
	    }
	} else {
	    result = Tk_SetOptions(interp, clientData,
	    result = Tk_SetOptions(interp, (char *) clientData,
		    headerPtr->optionTable, objc - 2, objv + 2,
		    tkwin, NULL, &mask);
	    if (result == TCL_OK) {
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj(mask));
		Tcl_SetObjResult(interp, Tcl_NewIntObj(mask));
	    }
	}
	break;
    case CSAVE:
	result = Tk_SetOptions(interp, clientData,
	result = Tk_SetOptions(interp, (char *) clientData,
		headerPtr->optionTable, objc - 2, objv + 2,
		tkwin, &saved, &mask);
	Tk_FreeSavedOptions(&saved);
	if (result == TCL_OK) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(mask));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(mask));
	}
	break;
    }
  done:
    Tcl_Release(clientData);
    return result;
}
1207
1208
1209
1210
1211
1212
1213
1214

1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229


1230
1231
1232
1233
1234
1235
1236
1244
1245
1246
1247
1248
1249
1250

1251
1252

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264


1265
1266
1267
1268
1269
1270
1271
1272
1273







-
+

-
+











-
-
+
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
TrivialCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *)clientData;
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *) clientData;
    Tk_Window tkwin = headerPtr->tkwin;

    if (tkwin != NULL) {
	Tk_DestroyWindow(tkwin);
    } else if (headerPtr->optionTable != NULL) {
	/*
	 * This is a "new" object, which doesn't have a window, so we can't
	 * depend on cleaning up in the event function. Free its resources
	 * here.
	 */

	Tk_FreeConfigOptions(clientData,
		headerPtr->optionTable, NULL);
	Tk_FreeConfigOptions((char *) clientData,
		headerPtr->optionTable, (Tk_Window) NULL);
	Tcl_EventuallyFree(clientData, TCL_DYNAMIC);
    }
}

/*
 *--------------------------------------------------------------
 *
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255

1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291

1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303







-
+


-
+



-
+







 *	When the window gets deleted, internal structures get cleaned up.
 *
 *--------------------------------------------------------------
 */

static void
TrivialEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *)clientData;
    TrivialCommandHeader *headerPtr = (TrivialCommandHeader *) clientData;

    if (eventPtr->type == DestroyNotify) {
	if (headerPtr->tkwin != NULL) {
	    Tk_FreeConfigOptions(clientData,
	    Tk_FreeConfigOptions((char *) clientData,
		    headerPtr->optionTable, headerPtr->tkwin);
	    headerPtr->optionTable = NULL;
	    headerPtr->tkwin = NULL;
	    Tcl_DeleteCommandFromToken(headerPtr->interp,
		    headerPtr->widgetCmd);
	}
	Tcl_EventuallyFree(clientData, TCL_DYNAMIC);
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1345







+


-
+










-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestfontObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const options[] = {"counts", "subfonts", NULL};
    enum option {COUNTS, SUBFONTS};
    int index;
    Tk_Window tkwin;
    Tk_Font tkfont;

    tkwin = (Tk_Window)clientData;
    tkwin = (Tk_Window) clientData;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option fontName");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350
1351

1352
1353
1354
1355


1356
1357

1358
1359
1360

1361
1362

1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380


1381
1382
1383
1384

1385
1386

1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413

1414
1415
1416
1417
1418

1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392


1393
1394
1395

1396
1397
1398

1399
1400

1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417


1418
1419
1420
1421
1422

1423
1424

1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1486







+





-
+


-
-
+
+

-
+


-
+

-
+





-
+




-
+





-
-
+
+



-
+

-
+



-
+




















+


-
+




-
+




















-
+







 *
 * Side effects:
 *	The data structure for a new image is allocated.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ImageCreate(
    Tcl_Interp *interp,		/* Interpreter for application containing
				 * image. */
    const char *name,			/* Name to use for image. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument strings for options (doesn't
				 * include image name or type). */
    TCL_UNUSED(const Tk_ImageType *),	/* Pointer to our type record (not used). */
	Tk_ImageModel model,	/* Token for image, to be used by us in later
    const Tk_ImageType *typePtr,	/* Pointer to our type record (not used). */
    Tk_ImageMaster master,	/* Token for image, to be used by us in later
				 * callbacks. */
    void **clientDataPtr)	/* Store manager's token for image here; it
    ClientData *clientDataPtr)	/* Store manager's token for image here; it
				 * will be returned in later callbacks. */
{
    TImageModel *timPtr;
    TImageMaster *timPtr;
    const char *varName;
    Tcl_Size i;
    int i;

    varName = "log";
    for (i = 0; i < objc; i += 2) {
	if (strcmp(Tcl_GetString(objv[i]), "-variable") != 0) {
	    Tcl_AppendResult(interp, "bad option name \"",
		    Tcl_GetString(objv[i]), "\"", (char *)NULL);
		    Tcl_GetString(objv[i]), "\"", NULL);
	    return TCL_ERROR;
	}
	if ((i+1) == objc) {
	    Tcl_AppendResult(interp, "no value given for \"",
		    Tcl_GetString(objv[i]), "\" option", (char *)NULL);
		    Tcl_GetString(objv[i]), "\" option", NULL);
	    return TCL_ERROR;
	}
	varName = Tcl_GetString(objv[i+1]);
    }

    timPtr = (TImageModel *)ckalloc(sizeof(TImageModel));
    timPtr->model = model;
    timPtr = ckalloc(sizeof(TImageMaster));
    timPtr->master = master;
    timPtr->interp = interp;
    timPtr->width = 30;
    timPtr->height = 15;
    timPtr->imageName = (char *)ckalloc(strlen(name) + 1);
    timPtr->imageName = ckalloc(strlen(name) + 1);
    strcpy(timPtr->imageName, name);
    timPtr->varName = (char *)ckalloc(strlen(varName) + 1);
    timPtr->varName = ckalloc(strlen(varName) + 1);
    strcpy(timPtr->varName, varName);
    Tcl_CreateObjCommand(interp, name, ImageObjCmd, timPtr, NULL);
    *clientDataPtr = timPtr;
    Tk_ImageChanged(model, 0, 0, 30, 15, 30, 15);
    Tk_ImageChanged(master, 0, 0, 30, 15, 30, 15);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageObjCmd --
 *
 *	This function implements the commands corresponding to individual
 *	images.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	Forces windows to be created.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
ImageObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    TImageModel *timPtr = (TImageModel *)clientData;
    TImageMaster *timPtr = (TImageMaster *) clientData;
    int x, y, width, height;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (strcmp(Tcl_GetString(objv[1]), "changed") == 0) {
	if (objc != 8) {
		Tcl_WrongNumArgs(interp, 1, objv, "changed x y width height"
			" imageWidth imageHeight");
	    return TCL_ERROR;
	}
	if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &width) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &height) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &timPtr->width) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[7], &timPtr->height) != TCL_OK)) {
	    return TCL_ERROR;
	}
	Tk_ImageChanged(timPtr->model, x, y, width, height, timPtr->width,
	Tk_ImageChanged(timPtr->master, x, y, width, height, timPtr->width,
		timPtr->height);
    } else {
	Tcl_AppendResult(interp, "bad option \"", Tcl_GetString(objv[1]),
		"\": must be changed", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471

1472
1473

1474
1475
1476
1477
1478

1479
1480
1481
1482
1483


1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1500
1501
1502
1503
1504
1505
1506

1507
1508
1509
1510

1511
1512

1513
1514
1515
1516
1517

1518
1519
1520
1521


1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532
1533







-
+



-
+

-
+




-
+



-
-
+
+



-







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void *
static ClientData
ImageGet(
    Tk_Window tkwin,		/* Token for window in which image will be
				 * used. */
    void *clientData)	/* Pointer to TImageModel for image. */
    ClientData clientData)	/* Pointer to TImageMaster for image. */
{
    TImageModel *timPtr = (TImageModel *)clientData;
    TImageMaster *timPtr = (TImageMaster *) clientData;
    TImageInstance *instPtr;
    char buffer[100];
    XGCValues gcValues;

    snprintf(buffer, sizeof(buffer), "%s get", timPtr->imageName);
    sprintf(buffer, "%s get", timPtr->imageName);
    Tcl_SetVar2(timPtr->interp, timPtr->varName, NULL, buffer,
	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);

    instPtr = (TImageInstance *)ckalloc(sizeof(TImageInstance));
    instPtr->modelPtr = timPtr;
    instPtr = ckalloc(sizeof(TImageInstance));
    instPtr->masterPtr = timPtr;
    instPtr->fg = Tk_GetColor(timPtr->interp, tkwin, "#ff0000");
    gcValues.foreground = instPtr->fg->pixel;
    instPtr->gc = Tk_GetGC(tkwin, GCForeground, &gcValues);
    instPtr->displayFailed = False;
    return instPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageDisplay --
1504
1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522


1523
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548


1549
1550


1551
1552

1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568


1569
1570
1571


1572
1573
1574
1575
1576
1577
1578
1579
1580
1543
1544
1545
1546
1547
1548
1549

1550
1551
1552
1553
1554
1555
1556
1557
1558
1559


1560
1561








1562


















1563
1564


1565
1566


1567
















1568
1569
1570


1571
1572
1573

1574
1575
1576
1577
1578
1579
1580







-
+









-
-
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
+
+

-







 *	redraw area.
 *
 *----------------------------------------------------------------------
 */

static void
ImageDisplay(
    void *clientData,	/* Pointer to TImageInstance for image. */
    ClientData clientData,	/* Pointer to TImageInstance for image. */
    Display *display,		/* Display to use for drawing. */
    Drawable drawable,		/* Where to redraw image. */
    int imageX, int imageY,	/* Origin of area to redraw, relative to
				 * origin of image. */
    int width, int height,	/* Dimensions of area to redraw. */
    int drawableX, int drawableY)
				/* Coordinates in drawable corresponding to
				 * imageX and imageY. */
{
    TImageInstance *instPtr = (TImageInstance *)clientData;

    TImageInstance *instPtr = (TImageInstance *) clientData;
    char buffer[200 + TCL_INTEGER_SPACE * 6];
    /*
     * The purpose of the test image type is to track the calls to an image
     * display proc and record the parameters passed in each call.  On macOS a
     * display proc must be run inside of the drawRect method of an NSView in
     * order for the graphics operations to have any effect.  To deal with
     * this, whenever a display proc is called outside of any drawRect method
     * it schedules a redraw of the NSView.
     *

     * In an attempt to work around this, each image instance maintains it own
     * copy of the log message which gets written on the first call to the
     * display proc.  This usually means that the message created on macOS is
     * the same as that created on other platforms.  However it is possible
     * for the messages to differ for other reasons, namely differences in
     * how damage regions are computed.
     */

    if (LOG_DISPLAY(drawable)) {
	if (instPtr->displayFailed == False) {

	    /*
	     * Drawing is possible on the first call to DisplayImage.
	     * Log the message.
	     */

	    snprintf(instPtr->buffer, sizeof(instPtr->buffer), "%s display %d %d %d %d",
	    instPtr->modelPtr->imageName, imageX, imageY, width, height);
    sprintf(buffer, "%s display %d %d %d %d %d %d",
	    instPtr->masterPtr->imageName, imageX, imageY, width, height,
	}
	Tcl_SetVar2(instPtr->modelPtr->interp, instPtr->modelPtr->varName,
	    drawableX, drawableY);
    Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName, NULL,
		    NULL, instPtr->buffer,
		    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
	    buffer, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
	instPtr->displayFailed = False;
    } else {

	/*
         * Drawing is not possible on the first call to DisplayImage.
	 * Save the message, but do not log it until the actual display.
	 */

	if (instPtr->displayFailed == False) {
	    snprintf(instPtr->buffer, sizeof(instPtr->buffer), "%s display %d %d %d %d",
		    instPtr->modelPtr->imageName, imageX, imageY, width, height);
	}
	instPtr->displayFailed = True;
    }
    if (width > (instPtr->modelPtr->width - imageX)) {
	width = instPtr->modelPtr->width - imageX;
    if (width > (instPtr->masterPtr->width - imageX)) {
	width = instPtr->masterPtr->width - imageX;
    }
    if (height > (instPtr->modelPtr->height - imageY)) {
	height = instPtr->modelPtr->height - imageY;
    if (height > (instPtr->masterPtr->height - imageY)) {
	height = instPtr->masterPtr->height - imageY;
    }

    XDrawRectangle(display, drawable, instPtr->gc, drawableX, drawableY,
	    (unsigned) (width-1), (unsigned) (height-1));
    XDrawLine(display, drawable, instPtr->gc, drawableX, drawableY,
	    (int) (drawableX + width - 1), (int) (drawableY + height - 1));
    XDrawLine(display, drawable, instPtr->gc, drawableX,
	    (int) (drawableY + height - 1),
	    (int) (drawableX + width - 1), drawableY);
1595
1596
1597
1598
1599
1600
1601
1602

1603
1604
1605

1606
1607
1608
1609


1610
1611
1612
1613
1614
1615
1616
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604

1605
1606
1607


1608
1609
1610
1611
1612
1613
1614
1615
1616







-
+


-
+


-
-
+
+







 *	Information related to the instance is freed.
 *
 *----------------------------------------------------------------------
 */

static void
ImageFree(
    void *clientData,	/* Pointer to TImageInstance for instance. */
    ClientData clientData,	/* Pointer to TImageInstance for instance. */
    Display *display)		/* Display where image was to be drawn. */
{
    TImageInstance *instPtr = (TImageInstance *)clientData;
    TImageInstance *instPtr = (TImageInstance *) clientData;
    char buffer[200];

    snprintf(buffer, sizeof(buffer), "%s free", instPtr->modelPtr->imageName);
    Tcl_SetVar2(instPtr->modelPtr->interp, instPtr->modelPtr->varName, NULL,
    sprintf(buffer, "%s free", instPtr->masterPtr->imageName);
    Tcl_SetVar2(instPtr->masterPtr->interp, instPtr->masterPtr->varName, NULL,
	    buffer, TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);
    Tk_FreeColor(instPtr->fg);
    Tk_FreeGC(display, instPtr->gc);
    ckfree(instPtr);
}

/*
1628
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639

1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638

1639
1640
1641

1642
1643
1644
1645
1646
1647
1648
1649







-
+



-
+


-
+







 *	Information about the image is deleted.
 *
 *----------------------------------------------------------------------
 */

static void
ImageDelete(
    void *clientData)	/* Pointer to TImageModel for image. When
    ClientData clientData)	/* Pointer to TImageMaster for image. When
				 * this function is called, no more instances
				 * exist. */
{
    TImageModel *timPtr = (TImageModel *)clientData;
    TImageMaster *timPtr = (TImageMaster *) clientData;
    char buffer[100];

    snprintf(buffer, sizeof(buffer), "%s delete", timPtr->imageName);
    sprintf(buffer, "%s delete", timPtr->imageName);
    Tcl_SetVar2(timPtr->interp, timPtr->varName, NULL, buffer,
	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT);

    Tcl_DeleteCommand(timPtr->interp, timPtr->imageName);
    ckfree(timPtr->imageName);
    ckfree(timPtr->varName);
    ckfree(timPtr);
1663
1664
1665
1666
1667
1668
1669

1670
1671
1672

1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672

1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1685







+


-
+




-
+







 *
 * Side effects:
 *	Forces windows to be created.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestmakeexistObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    Tk_Window mainWin = (Tk_Window)clientData;
    Tk_Window mainWin = (Tk_Window) clientData;
    int i;
    Tk_Window tkwin;

    for (i = 1; i < objc; i++) {
	tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[i]), mainWin);
	if (tkwin == NULL) {
	    return TCL_ERROR;
1703
1704
1705
1706
1707
1708
1709

1710
1711
1712
1713

1714
1715
1716
1717
1718
1719

1720
1721
1722
1723
1724
1725
1726
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







+



-
+





-
+







 *
 * Side effects:
 *	Changes menubar related stuff.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
#if !(defined(_WIN32) || defined(MAC_OSX_TK) || defined(__CYGWIN__))
static int
TestmenubarObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
#ifdef __UNIX__
    Tk_Window mainWin = (Tk_Window)clientData;
    Tk_Window mainWin = (Tk_Window) clientData;
    Tk_Window tkwin, menubar;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

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
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







-
+


-
+







+




+
+
+

+
+
+
+
+
+
+
+
+
+
+

+

+
+
+

+

+
+
+





-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#if defined(_WIN32)
#if defined(_WIN32) || defined(MAC_OSX_TK)
static int
TestmetricsObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    char buf[TCL_INTEGER_SPACE];
    int val;

#ifdef _WIN32
    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
#else
    Tk_Window tkwin = (Tk_Window) clientData;
    TkWindow *winPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option window");
	return TCL_ERROR;
    }

    winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }
#endif

    if (strcmp(Tcl_GetString(objv[1]), "cyvscroll") == 0) {
#ifdef _WIN32
	val = GetSystemMetrics(SM_CYVSCROLL);
#else
	val = ((TkScrollbar *) winPtr->instanceData)->width;
#endif
    } else  if (strcmp(Tcl_GetString(objv[1]), "cxhscroll") == 0) {
#ifdef _WIN32
	val = GetSystemMetrics(SM_CXHSCROLL);
#else
	val = ((TkScrollbar *) winPtr->instanceData)->width;
#endif
    } else {
	Tcl_AppendResult(interp, "bad option \"", Tcl_GetString(objv[1]),
		"\": must be cxhscroll or cyvscroll", NULL);
	return TCL_ERROR;
    }
    snprintf(buf, sizeof(buf), "%d", val);
    sprintf(buf, "%d", val);
    Tcl_AppendResult(interp, buf, NULL);
    return TCL_OK;
}
#endif

/*
 *----------------------------------------------------------------------
1817
1818
1819
1820
1821
1822
1823

1824
1825
1826

1827
1828
1829
1830
1831

1832
1833
1834
1835
1836
1837
1838
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851

1852
1853
1854
1855
1856

1857
1858
1859
1860
1861
1862
1863
1864







+


-
+




-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestpropObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    Tk_Window mainWin = (Tk_Window)clientData;
    Tk_Window mainWin = (Tk_Window) clientData;
    int result, actualFormat;
    unsigned long bytesAfter, length, value;
    Atom actualType, propName;
    unsigned char *property, *p;
    char *end;
    Window w;
    char buffer[30];
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
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







-
+












-
+







    if ((result == Success) && (actualType != None)) {
	if ((actualFormat == 8) && (actualType == XA_STRING)) {
	    for (p = property; ((unsigned long)(p-property)) < length; p++) {
		if (*p == 0) {
		    *p = '\n';
		}
	    }
	    Tcl_SetObjResult(interp, Tcl_NewStringObj((/*!unsigned*/char*)property, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj((/*!unsigned*/char*)property, -1));
	} else {
	    for (p = property; length > 0; length--) {
		if (actualFormat == 32) {
		    value = *((long *) p);
		    p += sizeof(long);
		} else if (actualFormat == 16) {
		    value = 0xffff & (*((short *) p));
		    p += sizeof(short);
		} else {
		    value = 0xff & *p;
		    p += 1;
		}
		snprintf(buffer, sizeof(buffer), "0x%lx", value);
		sprintf(buffer, "0x%lx", value);
		Tcl_AppendElement(interp, buffer);
	    }
	}
    }
    if (property != NULL) {
	XFree(property);
    }
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
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







+


-
+






+
+
+

+










-
+




-
+

-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestprintfObjCmd(
    TCL_UNUSED(void *),	/* Not used */
    ClientData clientData,	/* Not used */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    char buffer[256];
    Tcl_WideInt wideInt;
#ifdef _WIN32
    __int64 longLongInt;
#else
    long long longLongInt;
#endif

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "wideint");
	return TCL_ERROR;
    }
    if (Tcl_GetWideIntFromObj(interp, objv[1], &wideInt) != TCL_OK) {
	return TCL_ERROR;
    }
    longLongInt = wideInt;

    /* Just add a lot of arguments to snprintf. Reason: on AMD64, the first
    /* Just add a lot of arguments to sprintf. Reason: on AMD64, the first
     * 4 or 6 arguments (we assume 8, just in case) might be put in registers,
     * which still woudn't tell if the assumed size is correct: We want this
     * test-case to fail if the 64-bit value is printed as truncated to 32-bit.
     */
    snprintf(buffer, sizeof(buffer), "%s%s%s%s%s%s%s%s%" TCL_LL_MODIFIER "d %"
    sprintf(buffer, "%s%s%s%s%s%s%s%s%" TCL_LL_MODIFIER "d %"
	    TCL_LL_MODIFIER "u", "", "", "", "", "", "", "", "",
	    longLongInt, (unsigned long long)longLongInt);
	    (Tcl_WideInt)longLongInt, (Tcl_WideUInt)longLongInt);
    Tcl_AppendResult(interp, buffer, NULL);
    return TCL_OK;
}

#if !(defined(_WIN32) || defined(MAC_OSX_TK) || defined(__CYGWIN__))
/*
 *----------------------------------------------------------------------
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
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







+


-
+












-
+










-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestwrapperObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    TkWindow *winPtr, *wrapperPtr;
    Tk_Window tkwin;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "window");
	return TCL_ERROR;
    }

    tkwin = (Tk_Window)clientData;
    tkwin = (Tk_Window) clientData;
    winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[1]), tkwin);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }

    wrapperPtr = TkpGetWrapperWindow(winPtr);
    if (wrapperPtr != NULL) {
	char buf[TCL_INTEGER_SPACE];

	TkpPrintWindowId(buf, Tk_WindowId(wrapperPtr));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
    }
    return TCL_OK;
}
#endif

/*
 *----------------------------------------------------------------------
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
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







-
+
+






-
+

-
+


-
+








-
+







 *		CustomOptionFree	None.
 *
 * Side effects:
 *	Depends on the function.
 *		CustomOptionSet		Sets option value to new setting.
 *		CustomOptionGet		Creates a new Tcl_Obj.
 *		CustomOptionRestore	Resets option value to original value.
 *		CustomOptionFree	Free storage for internal rep of option.
 *		CustomOptionFree	Free storage for internal rep of
 *					option.
 *
 *----------------------------------------------------------------------
 */

static int
CustomOptionSet(
    TCL_UNUSED(void *),
    ClientData clientData,
    Tcl_Interp *interp,
    TCL_UNUSED(Tk_Window),
    Tk_Window tkwin,
    Tcl_Obj **value,
    char *recordPtr,
    Tcl_Size internalOffset,
    int internalOffset,
    char *saveInternalPtr,
    int flags)
{
    int objEmpty;
    char *newStr, *string, *internalPtr;

    objEmpty = 0;

    if (internalOffset != TCL_INDEX_NONE) {
    if (internalOffset >= 0) {
	internalPtr = recordPtr + internalOffset;
    } else {
	internalPtr = NULL;
    }

    /*
     * See if the object is empty.
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
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







-
+






-
+













-
-
+
+

-
+

-
+




-
-
+
+









-
-
+
+








    if ((flags & TK_OPTION_NULL_OK) && objEmpty) {
	*value = NULL;
    } else {
	string = Tcl_GetString(*value);
	Tcl_UtfToUpper(string);
	if (strcmp(string, "BAD") == 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("expected good value, got \"BAD\"", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("expected good value, got \"BAD\"", -1));
	    return TCL_ERROR;
	}
    }
    if (internalPtr != NULL) {
	if (*value != NULL) {
	    string = Tcl_GetString(*value);
	    newStr = (char *)ckalloc((*value)->length + 1);
	    newStr = ckalloc((*value)->length + 1);
	    strcpy(newStr, string);
	} else {
	    newStr = NULL;
	}
	*((char **) saveInternalPtr) = *((char **) internalPtr);
	*((char **) internalPtr) = newStr;
    }

    return TCL_OK;
}

static Tcl_Obj *
CustomOptionGet(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *recordPtr,
    Tcl_Size internalOffset)
    int internalOffset)
{
    return (Tcl_NewStringObj(*(char **)(recordPtr + internalOffset), TCL_INDEX_NONE));
    return (Tcl_NewStringObj(*(char **)(recordPtr + internalOffset), -1));
}

static void
CustomOptionRestore(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *internalPtr,
    char *saveInternalPtr)
{
    *(char **)internalPtr = *(char **)saveInternalPtr;
    return;
}

static void
CustomOptionFree(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *internalPtr)
{
    if (*(char **)internalPtr != NULL) {
	ckfree(*(char **)internalPtr);
    }
}
/*
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
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







+


-
+













-
-
+
+






-
-
+
+








 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static int
TestPhotoStringMatchCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    Tcl_Obj *dummy = NULL;
    Tcl_Obj *resultObj[2];
    int width, height;

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "imageData");
        return TCL_ERROR;
    }
    if (TkDebugPhotoStringMatchDef(interp, objv[1], dummy, &width, &height)) {
        resultObj[0] = Tcl_NewWideIntObj(width);
        resultObj[1] = Tcl_NewWideIntObj(height);
        resultObj[0] = Tcl_NewIntObj(width);
        resultObj[1] = Tcl_NewIntObj(height);
        Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObj));
        return TCL_OK;
    } else {
        return TCL_ERROR;
    }
}


            
    

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkText.c.

1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
19



20
21
22
23
24
25





26

27


28
29
30
31
32
33
34
35
36
37
38










39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16



17
18
19
20
21
22
23
24
25
26
27
28
29
30

31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78








-
-
-
+
+
+





-
-
-
+
+
+






+
+
+
+
+
-
+
-
+
+











+
+
+
+
+
+
+
+
+
+






-
+









-
+







/*
 * tkText.c --
 *
 *	This module provides a big chunk of the implementation of multi-line
 *	editable text widgets for Tk. Among other things, it provides the Tcl
 *	command interfaces to text widgets. The B-tree representation of text
 *	and its actual display are implemented elsewhere.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1996 Sun Microsystems, Inc.
 * Copyright © 1999 Scriptics Corporation.
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1996 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkUndo.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"
#include "tkUndo.h"

#if defined(MAC_OSX_TK)
#define Style TkStyle
#define DInfo TkDInfo
#endif

/*
 * For compatibility with Tk 4.0 through 8.4.x, we allow tabs to be
 * mis-specified with non-increasing values. These are converted into tabs
 * which are the equivalent of at least a character width apart.
 */
#ifdef _WIN32

#include "tkWinInt.h"
#if (TK_MAJOR_VERSION < 9)
#define _TK_ALLOW_DECREASING_TABS
#endif

#include "tkText.h"

/*
 * Used to avoid having to allocate and deallocate arrays on the fly for
 * commonly used functions. Must be > 0.
 */

#define PIXEL_CLIENTS 5

/*
 * The 'TkTextState' enum in tkText.h is used to define a type for the -state
 * option of the Text widget. These values are used as indices into the string
 * table below.
 */

static const char *const stateStrings[] = {
    "disabled", "normal", NULL
};

/*
 * The 'TkWrapMode' enum in tkText.h is used to define a type for the -wrap
 * option of the Text widget. These values are used as indices into the string
 * table below.
 */

const char *const tkTextWrapStrings[] = {
static const char *const wrapStrings[] = {
    "char", "none", "word", NULL
};

/*
 * The 'TkTextTabStyle' enum in tkText.h is used to define a type for the
 * -tabstyle option of the Text widget. These values are used as indices into
 * the string table below.
 */

const char *const tkTextTabStyleStrings[] = {
static const char *const tabStyleStrings[] = {
    "tabular", "wordprocessor", NULL
};

/*
 * The 'TkTextInsertUnfocussed' enum in tkText.h is used to define a type for
 * the -insertunfocussed option of the Text widget. These values are used as
 * indice into the string table below.
73
74
75
76
77
78
79
80

81
82
83

84
85

86
87
88


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109


110
111
112

113
114
115

116
117
118

119
120
121


122
123

124
125
126

127
128
129

130
131
132
133


134
135

136
137

138
139
140

141
142
143

144
145
146

147
148
149

150
151
152
153


154
155
156
157

158
159
160
161

162
163
164
165
166



167
168

169
170
171

172
173
174
175
176


177
178

179
180
181

182
183
184

185
186
187

188
189

190
191

192
193
194
195
196


197
198
199

200
201
202

203
204

205
206
207

208
209
210

211
212
213

214
215
216
217


218
219

220
221
222
223


224
225

226
227
228

229
230
231

232
233
234
235


236
237

238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266


267
268
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
89
90
91
92
93
94
95

96
97
98

99
100

101
102


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123


124
125
126
127

128
129
130

131
132
133

134
135


136
137
138

139
140
141

142
143
144

145
146
147


148
149
150

151
152

153
154
155

156
157
158

159
160
161

162
163
164

165
166
167


168
169
170
171
172

173
174
175
176

177
178
179



180
181
182
183

184
185
186

187
188
189
190


191
192
193

194
195
196

197
198
199

200
201
202

203
204

205
206

207
208
209
210


211
212
213
214

215
216
217

218
219

220
221
222

223
224
225

226
227
228

229
230
231


232
233
234

235
236
237


238
239
240

241
242
243

244
245
246

247
248
249


250
251
252

253
254
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280


281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302
303

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329







-
+


-
+

-
+

-
-
+
+



















-
-
+
+


-
+


-
+


-
+

-
-
+
+

-
+


-
+


-
+


-
-
+
+

-
+

-
+


-
+


-
+


-
+


-
+


-
-
+
+



-
+



-
+


-
-
-
+
+
+

-
+


-
+



-
-
+
+

-
+


-
+


-
+


-
+

-
+

-
+



-
-
+
+


-
+


-
+

-
+


-
+


-
+


-
+


-
-
+
+

-
+


-
-
+
+

-
+


-
+


-
+


-
-
+
+

-
+


-
+


















-
+





-
-
+
+


-
+















-
+


-
+

















-
+







 *
 * We do not need a 'freeProc' because all changes to these two options are
 * handled through the TK_TEXT_LINE_RANGE flag in the optionSpecs list, and
 * the internal storage is just a pointer, which therefore doesn't need
 * freeing.
 */

static int		SetLineStartEnd(void *clientData,
static int		SetLineStartEnd(ClientData clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    Tcl_Obj **value, char *recordPtr,
			    Tcl_Size internalOffset, char *oldInternalPtr,
			    int internalOffset, char *oldInternalPtr,
			    int flags);
static Tcl_Obj *	GetLineStartEnd(void *clientData,
static Tcl_Obj *	GetLineStartEnd(ClientData clientData,
			    Tk_Window tkwin, char *recordPtr,
			    Tcl_Size internalOffset);
static void		RestoreLineStartEnd(void *clientData,
			    int internalOffset);
static void		RestoreLineStartEnd(ClientData clientData,
			    Tk_Window tkwin, char *internalPtr,
			    char *oldInternalPtr);
static int		ObjectIsEmpty(Tcl_Obj *objPtr);

static const Tk_ObjCustomOption lineOption = {
    "line",			/* name */
    SetLineStartEnd,		/* setProc */
    GetLineStartEnd,		/* getProc */
    RestoreLineStartEnd,	/* restoreProc */
    NULL,			/* freeProc */
    0
};

/*
 * Information used to parse text configuration options:
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_BOOLEAN, "-autoseparators", "autoSeparators",
	"AutoSeparators", DEF_TEXT_AUTO_SEPARATORS, TCL_INDEX_NONE,
	offsetof(TkText, autoSeparators),
	"AutoSeparators", DEF_TEXT_AUTO_SEPARATORS, -1,
	Tk_Offset(TkText, autoSeparators),
	TK_OPTION_DONT_SET_DEFAULT, 0, 0},
    {TK_OPTION_BORDER, "-background", "background", "Background",
	DEF_TEXT_BG_COLOR, TCL_INDEX_NONE, offsetof(TkText, border),
	DEF_TEXT_BG_COLOR, -1, Tk_Offset(TkText, border),
	0, DEF_TEXT_BG_MONO, 0},
    {TK_OPTION_SYNONYM, "-bd", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth",
	NULL, 0, -1, 0, "-borderwidth",
	TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_SYNONYM, "-bg", NULL, NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
	NULL, 0, -1, 0, "-background", 0},
    {TK_OPTION_BOOLEAN, "-blockcursor", "blockCursor",
	"BlockCursor", DEF_TEXT_BLOCK_CURSOR, TCL_INDEX_NONE,
	offsetof(TkText, insertCursorType), 0, 0, 0},
	"BlockCursor", DEF_TEXT_BLOCK_CURSOR, -1,
	Tk_Offset(TkText, insertCursorType), 0, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	DEF_TEXT_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(TkText, borderWidth),
	DEF_TEXT_BORDER_WIDTH, -1, Tk_Offset(TkText, borderWidth),
	0, 0, TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
	DEF_TEXT_CURSOR, TCL_INDEX_NONE, offsetof(TkText, cursor),
	DEF_TEXT_CURSOR, -1, Tk_Offset(TkText, cursor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_CUSTOM, "-endline", NULL, NULL,
	 NULL, TCL_INDEX_NONE, offsetof(TkText, end), TK_OPTION_NULL_OK,
	 NULL, -1, Tk_Offset(TkText, end), TK_OPTION_NULL_OK,
	 &lineOption, TK_TEXT_LINE_RANGE},
    {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
	"ExportSelection", DEF_TEXT_EXPORT_SELECTION, TCL_INDEX_NONE,
	offsetof(TkText, exportSelection), 0, 0, 0},
	"ExportSelection", DEF_TEXT_EXPORT_SELECTION, -1,
	Tk_Offset(TkText, exportSelection), 0, 0, 0},
    {TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
	NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0},
	NULL, 0, -1, 0, "-foreground", 0},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_TEXT_FONT, TCL_INDEX_NONE, offsetof(TkText, tkfont), 0, 0,
	DEF_TEXT_FONT, -1, Tk_Offset(TkText, tkfont), 0, 0,
	TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
	DEF_TEXT_FG, TCL_INDEX_NONE, offsetof(TkText, fgColor), 0,
	DEF_TEXT_FG, -1, Tk_Offset(TkText, fgColor), 0,
	0, 0},
    {TK_OPTION_PIXELS, "-height", "height", "Height",
	DEF_TEXT_HEIGHT, TCL_INDEX_NONE, offsetof(TkText, height), 0, 0, 0},
	DEF_TEXT_HEIGHT, -1, Tk_Offset(TkText, height), 0, 0, 0},
    {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
	"HighlightBackground", DEF_TEXT_HIGHLIGHT_BG,
	TCL_INDEX_NONE, offsetof(TkText, highlightBgColorPtr),
	-1, Tk_Offset(TkText, highlightBgColorPtr),
	0, 0, 0},
    {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
	DEF_TEXT_HIGHLIGHT, TCL_INDEX_NONE, offsetof(TkText, highlightColorPtr),
	DEF_TEXT_HIGHLIGHT, -1, Tk_Offset(TkText, highlightColorPtr),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
	"HighlightThickness", DEF_TEXT_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
	offsetof(TkText, highlightWidth), 0, 0, TK_TEXT_LINE_GEOMETRY},
	"HighlightThickness", DEF_TEXT_HIGHLIGHT_WIDTH, -1,
	Tk_Offset(TkText, highlightWidth), 0, 0, TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_BORDER, "-inactiveselectbackground","inactiveSelectBackground",
	"Foreground",
	DEF_TEXT_INACTIVE_SELECT_COLOR,
	TCL_INDEX_NONE, offsetof(TkText, inactiveSelBorder),
	-1, Tk_Offset(TkText, inactiveSelBorder),
	TK_OPTION_NULL_OK, DEF_TEXT_SELECT_MONO, 0},
    {TK_OPTION_BORDER, "-insertbackground", "insertBackground", "Foreground",
	DEF_TEXT_INSERT_BG,
	TCL_INDEX_NONE, offsetof(TkText, insertBorder),
	-1, Tk_Offset(TkText, insertBorder),
	0, 0, 0},
    {TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth",
	"BorderWidth", DEF_TEXT_INSERT_BD_COLOR, TCL_INDEX_NONE,
	offsetof(TkText, insertBorderWidth), 0,
	DEF_TEXT_INSERT_BD_MONO, 0},
	"BorderWidth", DEF_TEXT_INSERT_BD_COLOR, -1,
	Tk_Offset(TkText, insertBorderWidth), 0,
	(ClientData) DEF_TEXT_INSERT_BD_MONO, 0},
    {TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime",
	DEF_TEXT_INSERT_OFF_TIME, TCL_INDEX_NONE, offsetof(TkText, insertOffTime),
	DEF_TEXT_INSERT_OFF_TIME, -1, Tk_Offset(TkText, insertOffTime),
	0, 0, 0},
    {TK_OPTION_INT, "-insertontime", "insertOnTime", "OnTime",
	DEF_TEXT_INSERT_ON_TIME, TCL_INDEX_NONE, offsetof(TkText, insertOnTime),
	DEF_TEXT_INSERT_ON_TIME, -1, Tk_Offset(TkText, insertOnTime),
	0, 0, 0},
    {TK_OPTION_STRING_TABLE,
	"-insertunfocussed", "insertUnfocussed", "InsertUnfocussed",
	DEF_TEXT_INSERT_UNFOCUSSED, TCL_INDEX_NONE, offsetof(TkText, insertUnfocussed),
	TK_OPTION_ENUM_VAR, insertUnfocussedStrings, 0},
	DEF_TEXT_INSERT_UNFOCUSSED, -1, Tk_Offset(TkText, insertUnfocussed),
	0, insertUnfocussedStrings, 0},
    {TK_OPTION_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
	DEF_TEXT_INSERT_WIDTH, TCL_INDEX_NONE, offsetof(TkText, insertWidth),
	DEF_TEXT_INSERT_WIDTH, -1, Tk_Offset(TkText, insertWidth),
	0, 0, 0},
    {TK_OPTION_INT, "-maxundo", "maxUndo", "MaxUndo",
	DEF_TEXT_MAX_UNDO, TCL_INDEX_NONE, offsetof(TkText, maxUndo),
	DEF_TEXT_MAX_UNDO, -1, Tk_Offset(TkText, maxUndo),
	TK_OPTION_DONT_SET_DEFAULT, 0, 0},
    {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
	DEF_TEXT_PADX, TCL_INDEX_NONE, offsetof(TkText, padX), 0, 0,
	DEF_TEXT_PADX, -1, Tk_Offset(TkText, padX), 0, 0,
	TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
	DEF_TEXT_PADY, TCL_INDEX_NONE, offsetof(TkText, padY), 0, 0, 0},
	DEF_TEXT_PADY, -1, Tk_Offset(TkText, padY), 0, 0, 0},
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	DEF_TEXT_RELIEF, TCL_INDEX_NONE, offsetof(TkText, relief), 0, 0, 0},
	DEF_TEXT_RELIEF, -1, Tk_Offset(TkText, relief), 0, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_TEXT_SELECT_COLOR, TCL_INDEX_NONE, offsetof(TkText, selBorder),
	DEF_TEXT_SELECT_COLOR, -1, Tk_Offset(TkText, selBorder),
	0, DEF_TEXT_SELECT_MONO, 0},
    {TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
	"BorderWidth", DEF_TEXT_SELECT_BD_COLOR,
	offsetof(TkText, selBorderWidthPtr),
	offsetof(TkText, selBorderWidth),
	Tk_Offset(TkText, selBorderWidthPtr),
	Tk_Offset(TkText, selBorderWidth),
	TK_OPTION_NULL_OK, DEF_TEXT_SELECT_BD_MONO, 0},
    {TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
	DEF_TEXT_SELECT_FG_COLOR, TCL_INDEX_NONE, offsetof(TkText, selFgColorPtr),
	DEF_TEXT_SELECT_FG_COLOR, -1, Tk_Offset(TkText, selFgColorPtr),
	TK_OPTION_NULL_OK, DEF_TEXT_SELECT_FG_MONO, 0},
    {TK_OPTION_BOOLEAN, "-setgrid", "setGrid", "SetGrid",
	DEF_TEXT_SET_GRID, TCL_INDEX_NONE, offsetof(TkText, setGrid), 0, 0, 0},
	DEF_TEXT_SET_GRID, -1, Tk_Offset(TkText, setGrid), 0, 0, 0},
    {TK_OPTION_PIXELS, "-spacing1", "spacing1", "Spacing",
	DEF_TEXT_SPACING1, TCL_INDEX_NONE, offsetof(TkText, spacing1),
	DEF_TEXT_SPACING1, -1, Tk_Offset(TkText, spacing1),
	0, 0 , TK_TEXT_LINE_GEOMETRY },
    {TK_OPTION_PIXELS, "-spacing2", "spacing2", "Spacing",
	DEF_TEXT_SPACING2, TCL_INDEX_NONE, offsetof(TkText, spacing2),
	DEF_TEXT_SPACING2, -1, Tk_Offset(TkText, spacing2),
	0, 0 , TK_TEXT_LINE_GEOMETRY },
    {TK_OPTION_PIXELS, "-spacing3", "spacing3", "Spacing",
	DEF_TEXT_SPACING3, TCL_INDEX_NONE, offsetof(TkText, spacing3),
	DEF_TEXT_SPACING3, -1, Tk_Offset(TkText, spacing3),
	0, 0 , TK_TEXT_LINE_GEOMETRY },
    {TK_OPTION_CUSTOM, "-startline", NULL, NULL,
	 NULL, TCL_INDEX_NONE, offsetof(TkText, start), TK_OPTION_NULL_OK,
	 NULL, -1, Tk_Offset(TkText, start), TK_OPTION_NULL_OK,
	 &lineOption, TK_TEXT_LINE_RANGE},
    {TK_OPTION_STRING_TABLE, "-state", "state", "State",
	DEF_TEXT_STATE, TCL_INDEX_NONE, offsetof(TkText, state),
	TK_OPTION_ENUM_VAR, &tkStateStrings[1], 0},
	DEF_TEXT_STATE, -1, Tk_Offset(TkText, state),
	0, stateStrings, 0},
    {TK_OPTION_STRING, "-tabs", "tabs", "Tabs",
	DEF_TEXT_TABS, offsetof(TkText, tabOptionPtr), TCL_INDEX_NONE,
	DEF_TEXT_TABS, Tk_Offset(TkText, tabOptionPtr), -1,
	TK_OPTION_NULL_OK, 0, TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_STRING_TABLE, "-tabstyle", "tabStyle", "TabStyle",
	DEF_TEXT_TABSTYLE, TCL_INDEX_NONE, offsetof(TkText, tabStyle),
	TK_OPTION_ENUM_VAR, tkTextTabStyleStrings, TK_TEXT_LINE_GEOMETRY},
	DEF_TEXT_TABSTYLE, -1, Tk_Offset(TkText, tabStyle),
	0, tabStyleStrings, TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_TEXT_TAKE_FOCUS, offsetof(TkText, takeFocusObj), TCL_INDEX_NONE,
	DEF_TEXT_TAKE_FOCUS, -1, Tk_Offset(TkText, takeFocus),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-undo", "undo", "Undo",
	DEF_TEXT_UNDO, TCL_INDEX_NONE, offsetof(TkText, undo),
	DEF_TEXT_UNDO, -1, Tk_Offset(TkText, undo),
	TK_OPTION_DONT_SET_DEFAULT, 0 , 0},
    {TK_OPTION_INT, "-width", "width", "Width",
	DEF_TEXT_WIDTH, TCL_INDEX_NONE, offsetof(TkText, width), 0, 0,
	DEF_TEXT_WIDTH, -1, Tk_Offset(TkText, width), 0, 0,
	TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_STRING_TABLE, "-wrap", "wrap", "Wrap",
	DEF_TEXT_WRAP, TCL_INDEX_NONE, offsetof(TkText, wrapMode),
	TK_OPTION_ENUM_VAR, tkTextWrapStrings, TK_TEXT_LINE_GEOMETRY},
	DEF_TEXT_WRAP, -1, Tk_Offset(TkText, wrapMode),
	0, wrapStrings, TK_TEXT_LINE_GEOMETRY},
    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	DEF_TEXT_XSCROLL_COMMAND, offsetof(TkText, xScrollCmdObj), TCL_INDEX_NONE,
	DEF_TEXT_XSCROLL_COMMAND, -1, Tk_Offset(TkText, xScrollCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
	DEF_TEXT_YSCROLL_COMMAND, offsetof(TkText, yScrollCmdObj), TCL_INDEX_NONE,
	DEF_TEXT_YSCROLL_COMMAND, -1, Tk_Offset(TkText, yScrollCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0}
};

/*
 * These three typedefs, the structure and the SearchPerform, SearchCore
 * functions below are used for line-based searches of the text widget, and,
 * in particular, to handle multi-line matching even though the text widget is
 * a single-line based data structure. They are completely abstracted away
 * from the Text widget internals, however, so could easily be re-used with
 * any line-based entity to provide multi-line matching.
 *
 * We have abstracted this code away from the text widget to try to keep Tk as
 * modular as possible.
 */

struct SearchSpec;	/* Forward declaration. */

typedef void *SearchAddLineProc(int lineNum,
typedef ClientData	SearchAddLineProc(int lineNum,
			    struct SearchSpec *searchSpecPtr,
			    Tcl_Obj *theLine, int *lenPtr,
			    int *extraLinesPtr);
typedef int		SearchMatchProc(int lineNum,
			    struct SearchSpec *searchSpecPtr,
			    void *clientData, Tcl_Obj *theLine,
			    Tcl_Size matchOffset, Tcl_Size matchLength);
			    ClientData clientData, Tcl_Obj *theLine,
			    int matchOffset, int matchLength);
typedef int		SearchLineIndexProc(Tcl_Interp *interp,
			    Tcl_Obj *objPtr, struct SearchSpec *searchSpecPtr,
			    int *linePosPtr, Tcl_Size *offsetPosPtr);
			    int *linePosPtr, int *offsetPosPtr);

typedef struct SearchSpec {
    int exact;			/* Whether search is exact or regexp. */
    int noCase;			/* Case-insenstivive? */
    int noLineStop;		/* If not set, a regexp search will use the
				 * TCL_REG_NLSTOP flag. */
    int overlap;		/* If set, results from multiple searches
				 * (-all) are allowed to overlap each
				 * other. */
    int strictLimits;		/* If set, matches must be completely inside
				 * the from,to range. Otherwise the limits
				 * only apply to the start of each match. */
    int all;			/* Whether all or the first match should be
				 * reported. */
    int startLine;		/* First line to examine. */
    Tcl_Size startOffset;		/* Index in first line to start at. */
    int startOffset;		/* Index in first line to start at. */
    int stopLine;		/* Last line to examine, or -1 when we search
				 * all available text. */
    Tcl_Size stopOffset;		/* Index to stop at, provided stopLine is not
    int stopOffset;		/* Index to stop at, provided stopLine is not
				 * -1. */
    int numLines;		/* Total lines which are available. */
    int backwards;		/* Searching forwards or backwards. */
    Tcl_Obj *varPtr;		/* If non-NULL, store length(s) of match(es)
				 * in this variable. */
    Tcl_Obj *countPtr;		/* Keeps track of currently found lengths. */
    Tcl_Obj *resPtr;		/* Keeps track of currently found locations */
    int searchElide;		/* Search in hidden text as well. */
    SearchAddLineProc *addLineProc;
				/* Function to call when we need to add
				 * another line to the search string so far */
    SearchMatchProc *foundMatchProc;
				/* Function to call when we have found a
				 * match. */
    SearchLineIndexProc *lineIndexProc;
				/* Function to call when we have found a
				 * match. */
    void *clientData;	/* Information about structure being searched,
    ClientData clientData;	/* Information about structure being searched,
				 * in this case a text widget. */
} SearchSpec;

/*
 * The text-widget-independent functions which actually perform the search,
 * handling both regexp and exact searches.
 */
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346


347
348
349
350


351
352
353


354
355
356
357
358

359
360
361
362
363

364
365

366
367
368
369
370








371
372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389
390
391
392
393
394


395
396

397
398
399
400
401
402
403
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356
357
358
359
360


361
362
363
364


365
366
367


368
369
370
371
372
373

374
375
376
377
378

379
380

381
382




383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413


414
415
416

417
418
419
420
421
422
423
424







-
+











-
-
+
+


-
-
+
+

-
-
+
+




-
+




-
+

-
+

-
-
-
-
+
+
+
+
+
+
+
+


-
+















+




-
-
+
+

-
+







int tkTextDebug = 0;

/*
 * Forward declarations for functions defined later in this file:
 */

static int		ConfigureText(Tcl_Interp *interp,
			    TkText *textPtr, Tcl_Size objc, Tcl_Obj *const objv[]);
			    TkText *textPtr, int objc, Tcl_Obj *const objv[]);
static int		DeleteIndexRange(TkSharedText *sharedPtr,
			    TkText *textPtr, const TkTextIndex *indexPtr1,
			    const TkTextIndex *indexPtr2, int viewUpdate);
static int		CountIndices(const TkText *textPtr,
			    const TkTextIndex *indexPtr1,
			    const TkTextIndex *indexPtr2,
			    TkTextCountType type);
static void		DestroyText(TkText *textPtr);
static int		InsertChars(TkSharedText *sharedTextPtr,
			    TkText *textPtr, TkTextIndex *indexPtr,
			    Tcl_Obj *stringPtr, int viewUpdate);
static void		TextBlinkProc(void *clientData);
static Tcl_CmdDeleteProc TextCmdDeletedProc;
static void		TextBlinkProc(ClientData clientData);
static void		TextCmdDeletedProc(ClientData clientData);
static int		CreateWidget(TkSharedText *sharedPtr, Tk_Window tkwin,
			    Tcl_Interp *interp, const TkText *parent,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static void		TextEventProc(void *clientData,
			    int objc, Tcl_Obj *const objv[]);
static void		TextEventProc(ClientData clientData,
			    XEvent *eventPtr);
static Tcl_Size	TextFetchSelection(void *clientData, Tcl_Size offset,
			    char *buffer, Tcl_Size maxBytes);
static int		TextFetchSelection(ClientData clientData, int offset,
			    char *buffer, int maxBytes);
static int		TextIndexSortProc(const void *first,
			    const void *second);
static int		TextInsertCmd(TkSharedText *sharedTextPtr,
			    TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[],
			    int objc, Tcl_Obj *const objv[],
			    const TkTextIndex *indexPtr, int viewUpdate);
static int		TextReplaceCmd(TkText *textPtr, Tcl_Interp *interp,
			    const TkTextIndex *indexFromPtr,
			    const TkTextIndex *indexToPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[], int viewUpdate);
			    int objc, Tcl_Obj *const objv[], int viewUpdate);
static int		TextSearchCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		TextEditCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static Tcl_ObjCmdProc TextWidgetObjCmd;
static Tcl_ObjCmdProc2 SharedTextObjCmd;
static void		TextWorldChangedCallback(void *instanceData);
			    int objc, Tcl_Obj *const objv[]);
static int		TextWidgetObjCmd(ClientData clientData,
			    Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		SharedTextObjCmd(ClientData clientData,
			    Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static void		TextWorldChangedCallback(ClientData instanceData);
static void		TextWorldChanged(TkText *textPtr, int mask);
static int		TextDumpCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		DumpLine(Tcl_Interp *interp, TkText *textPtr,
			    int what, TkTextLine *linePtr, int start, int end,
			    int lineno, Tcl_Obj *command);
static int		DumpSegment(TkText *textPtr, Tcl_Interp *interp,
			    const char *key, const char *value,
			    Tcl_Obj *command, const TkTextIndex *index,
			    int what);
static int		TextEditUndo(TkText *textPtr);
static int		TextEditRedo(TkText *textPtr);
static Tcl_Obj *	TextGetText(const TkText *textPtr,
			    const TkTextIndex *index1,
			    const TkTextIndex *index2, int visibleOnly);
static void		GenerateModifiedEvent(TkText *textPtr);
static void		GenerateUndoStackEvent(TkText *textPtr);
static void		UpdateDirtyFlag(TkSharedText *sharedPtr);
static void		RunAfterSyncCmd(ClientData clientData);
static void		TextPushUndoAction(TkText *textPtr,
			    Tcl_Obj *undoString, int insert,
			    const TkTextIndex *index1Ptr,
			    const TkTextIndex *index2Ptr);
static Tcl_Size		TextSearchIndexInLine(const SearchSpec *searchSpecPtr,
			    TkTextLine *linePtr, Tcl_Size byteIndex);
static int		TextSearchIndexInLine(const SearchSpec *searchSpecPtr,
			    TkTextLine *linePtr, int byteIndex);
static int		TextPeerCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static TkUndoProc	TextUndoRedoCallback;

/*
 * Declarations of the three search procs required by the multi-line search
 * routines.
 */

432
433
434
435
436
437
438
439

440
441
442
443
444

445
446
447
448
449
450
451
453
454
455
456
457
458
459

460
461
462
463
464

465
466
467
468
469
470
471
472







-
+




-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_TextObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

    return CreateWidget(NULL, tkwin, interp, NULL, objc, objv);
475
476
477
478
479
480
481
482

483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
496
497
498
499
500
501
502

503
504
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555

556
557
558
559
560
561
562







-
+


-
+




















-
+










-
+

















-







static int
CreateWidget(
    TkSharedText *sharedPtr,	/* Shared widget info, or NULL. */
    Tk_Window tkwin,		/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    const TkText *parent,	/* If non-NULL then take default start, end
				 * from this parent. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkText *textPtr;
    register TkText *textPtr;
    Tk_OptionTable optionTable;
    TkTextIndex startIndex;
    Tk_Window newWin;

    /*
     * Create the window.
     */

    newWin = Tk_CreateWindowFromPath(interp, tkwin, Tcl_GetString(objv[1]),
	    NULL);
    if (newWin == NULL) {
	return TCL_ERROR;
    }

    /*
     * Create the text widget and initialize everything to zero, then set the
     * necessary initial (non-NULL) values. It is important that the 'set' tag
     * and 'insert', 'current' mark pointers are all NULL to start.
     */

    textPtr = (TkText *)ckalloc(sizeof(TkText));
    textPtr = ckalloc(sizeof(TkText));
    memset(textPtr, 0, sizeof(TkText));

    textPtr->tkwin = newWin;
    textPtr->display = Tk_Display(newWin);
    textPtr->interp = interp;
    textPtr->widgetCmd = Tcl_CreateObjCommand(interp,
	    Tk_PathName(textPtr->tkwin), TextWidgetObjCmd,
	    textPtr, TextCmdDeletedProc);

    if (sharedPtr == NULL) {
	sharedPtr = (TkSharedText *)ckalloc(sizeof(TkSharedText));
	sharedPtr = ckalloc(sizeof(TkSharedText));
	memset(sharedPtr, 0, sizeof(TkSharedText));

	sharedPtr->refCount = 0;
	sharedPtr->peers = NULL;
	sharedPtr->tree = TkBTreeCreate(sharedPtr);

	Tcl_InitHashTable(&sharedPtr->tagTable, TCL_STRING_KEYS);
	Tcl_InitHashTable(&sharedPtr->markTable, TCL_STRING_KEYS);
	Tcl_InitHashTable(&sharedPtr->windowTable, TCL_STRING_KEYS);
	Tcl_InitHashTable(&sharedPtr->imageTable, TCL_STRING_KEYS);
	sharedPtr->undoStack = TkUndoInitStack(interp,0);
	sharedPtr->undo = 0;
	sharedPtr->isDirty = 0;
	sharedPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL;
	sharedPtr->autoSeparators = 1;
	sharedPtr->lastEditMode = TK_TEXT_EDIT_OTHER;
	sharedPtr->stateEpoch = 0;
	sharedPtr->imageCount = 0;
    }

    /*
     * Add the new widget to the shared list.
     */

    textPtr->sharedTextPtr = sharedPtr;
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597







-
+







    } else {
	textPtr->start = NULL;
	textPtr->end = NULL;
    }

    textPtr->state = TK_TEXT_STATE_NORMAL;
    textPtr->relief = TK_RELIEF_FLAT;
    textPtr->cursor = NULL;
    textPtr->cursor = None;
    textPtr->charWidth = 1;
    textPtr->charHeight = 10;
    textPtr->wrapMode = TEXT_WRAPMODE_CHAR;
    textPtr->prevWidth = Tk_Width(newWin);
    textPtr->prevHeight = Tk_Height(newWin);

    /*
609
610
611
612
613
614
615



616
617
618
619
620
621
622
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645







+
+
+








    /*
     * Note: it is important that textPtr->selTagPtr is NULL before this
     * initial call.
     */

    textPtr->selTagPtr = TkTextCreateTag(textPtr, "sel", NULL);
    textPtr->selTagPtr->reliefString =
	    ckalloc(sizeof(DEF_TEXT_SELECT_RELIEF));
    strcpy(textPtr->selTagPtr->reliefString, DEF_TEXT_SELECT_RELIEF);
    Tk_GetRelief(interp, DEF_TEXT_SELECT_RELIEF, &textPtr->selTagPtr->relief);
    textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &startIndex);
    textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &startIndex);

    /*
     * Create the option table for this widget class. If it has already been
     * created, the cached pointer will be returned.
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658
657
658
659
660
661
662
663

664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681







-
+









-
+







    Tk_CreateEventHandler(textPtr->tkwin, KeyPressMask|KeyReleaseMask
	    |ButtonPressMask|ButtonReleaseMask|EnterWindowMask
	    |LeaveWindowMask|PointerMotionMask|VirtualEventMask,
	    TkTextBindProc, textPtr);
    Tk_CreateSelHandler(textPtr->tkwin, XA_PRIMARY, XA_STRING,
	    TextFetchSelection, textPtr, XA_STRING);

    if (Tk_InitOptions(interp, textPtr, optionTable, textPtr->tkwin)
    if (Tk_InitOptions(interp, (char *) textPtr, optionTable, textPtr->tkwin)
	    != TCL_OK) {
	Tk_DestroyWindow(textPtr->tkwin);
	return TCL_ERROR;
    }
    if (ConfigureText(interp, textPtr, objc-2, objv+2) != TCL_OK) {
	Tk_DestroyWindow(textPtr->tkwin);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tk_NewWindowObj(textPtr->tkwin));
    Tcl_SetObjResult(interp, TkNewWindowObj(textPtr->tkwin));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * TextWidgetObjCmd --
668
669
670
671
672
673
674
675

676
677
678
679
680

681
682

683
684
685
686
687
688
689
691
692
693
694
695
696
697

698
699
700
701
702

703
704

705
706
707
708
709
710
711
712







-
+




-
+

-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
TextWidgetObjCmd(
    void *clientData,	/* Information about text widget. */
    ClientData clientData,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    int result = TCL_OK;
    int idx;
    int index;

    static const char *const optionStrings[] = {
	"bbox", "cget", "compare", "configure", "count", "debug", "delete",
	"dlineinfo", "dump", "edit", "get", "image", "index", "insert",
	"mark", "peer", "pendingsync", "replace", "scan", "search",
	"see", "sync", "tag", "window", "xview", "yview", NULL
    };
698
699
700
701
702
703
704
705

706
707
708
709
710

711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732




733
734
735
736
737
738
739
740
741
742
743
744

745
746
747
748
749
750
751
721
722
723
724
725
726
727

728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751




752
753
754
755
756
757
758
759
760
761
762
763
764
765
766

767
768
769
770
771
772
773
774







-
+




-
+


















-
-
-
-
+
+
+
+











-
+








    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &idx) != TCL_OK) {
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    textPtr->refCount++;

    switch ((enum options) idx) {
    switch ((enum options) index) {
    case TEXT_BBOX: {
	int x, y, width, height;
	const TkTextIndex *indexPtr;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index");
	    result = TCL_ERROR;
	    goto done;
	}
	indexPtr = TkTextGetIndexFromObj(interp, textPtr, objv[2]);
	if (indexPtr == NULL) {
	    result = TCL_ERROR;
	    goto done;
	}
	if (TkTextIndexBbox(textPtr, indexPtr, &x, &y, &width, &height,
		NULL) == 0) {
	    Tcl_Obj *listObj = Tcl_NewListObj(0, NULL);

	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(x));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(y));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(width));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(height));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(x));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(y));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(width));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(height));

	    Tcl_SetObjResult(interp, listObj);
	}
	break;
    }
    case TEXT_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    result = TCL_ERROR;
	    goto done;
	} else {
	    Tcl_Obj *objPtr = Tk_GetOptionValue(interp, textPtr,
	    Tcl_Obj *objPtr = Tk_GetOptionValue(interp, (char *) textPtr,
		    textPtr->optionTable, objv[2], textPtr->tkwin);

	    if (objPtr == NULL) {
		result = TCL_ERROR;
		goto done;
	    }
	    Tcl_SetObjResult(interp, objPtr);
794
795
796
797
798
799
800
801

802
803
804
805
806
807

808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823

824
825
826
827
828
829
830
817
818
819
820
821
822
823

824
825
826
827
828
829

830
831
832
833
834
835
836
837
838
839
840
841
842
843
844


845
846
847
848
849
850
851
852







-
+





-
+














-
-
+







	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(value));
	break;

    compareError:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad comparison operator \"%s\": must be"
		" <, <=, ==, >=, >, or !=", Tcl_GetString(objv[3])));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "COMPARISON", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "VALUE", "COMPARISON", NULL);
	result = TCL_ERROR;
	goto done;
    }
    case TEXT_CONFIGURE:
	if (objc <= 3) {
	    Tcl_Obj *objPtr = Tk_GetOptionInfo(interp, textPtr,
	    Tcl_Obj *objPtr = Tk_GetOptionInfo(interp, (char *) textPtr,
		    textPtr->optionTable, ((objc == 3) ? objv[2] : NULL),
		    textPtr->tkwin);

	    if (objPtr == NULL) {
		result = TCL_ERROR;
		goto done;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	} else {
	    result = ConfigureText(interp, textPtr, objc-2, objv+2);
	}
	break;
    case TEXT_COUNT: {
	const TkTextIndex *indexFromPtr, *indexToPtr;
	Tcl_Size i;
	int found = 0, update = 0;
	int i, found = 0, update = 0;
	Tcl_Obj *objPtr = NULL;

	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "?-option value ...? index1 index2");
	    result = TCL_ERROR;
	    goto done;
838
839
840
841
842
843
844
845

846
847

848
849

850
851
852
853
854

855
856
857
858

859
860
861
862

863
864
865
866

867
868
869
870
871
872
873
860
861
862
863
864
865
866

867


868
869
870
871
872
873
874
875

876
877
878
879

880
881
882
883

884
885
886
887

888
889
890
891
892
893
894
895







-
+
-
-
+


+




-
+



-
+



-
+



-
+







	indexToPtr = TkTextGetIndexFromObj(interp, textPtr, objv[objc-1]);
	if (indexToPtr == NULL) {
	    result = TCL_ERROR;
	    goto done;
	}

	for (i = 2; i < objc-2; i++) {
	    int value;
	    int value, length;
	    Tcl_Size length;
	    const char *option = Tcl_GetStringFromObj(objv[i], &length);
	    const char *option = Tcl_GetString(objv[i]);
	    char c;

	    length = objv[i]->length;
	    if (length < 2 || option[0] != '-') {
		goto badOption;
	    }
	    c = option[1];
	    if (c == 'c' && !strncmp("-chars", option, length)) {
	    if (c == 'c' && !strncmp("-chars", option, (unsigned) length)) {
		value = CountIndices(textPtr, indexFromPtr, indexToPtr,
			COUNT_CHARS);
	    } else if (c == 'd' && (length > 8)
		    && !strncmp("-displaychars", option, length)) {
		    && !strncmp("-displaychars", option, (unsigned) length)) {
		value = CountIndices(textPtr, indexFromPtr, indexToPtr,
			COUNT_DISPLAY_CHARS);
	    } else if (c == 'd' && (length > 8)
		    && !strncmp("-displayindices", option,length)) {
		    && !strncmp("-displayindices", option,(unsigned)length)) {
		value = CountIndices(textPtr, indexFromPtr, indexToPtr,
			COUNT_DISPLAY_INDICES);
	    } else if (c == 'd' && (length > 8)
		    && !strncmp("-displaylines", option, length)) {
		    && !strncmp("-displaylines", option, (unsigned) length)) {
		TkTextLine *fromPtr, *lastPtr;
		TkTextIndex index, index2;

		int compare = TkTextIndexCmp(indexFromPtr, indexToPtr);
		value = 0;

		if (compare == 0) {
957
958
959
960
961
962
963
964

965
966
967
968

969
970
971
972

973
974
975
976

977
978
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
1033

1034
1035
1036

1037
1038
1039
1040
1041
1042
1043
979
980
981
982
983
984
985

986
987
988
989

990
991
992
993

994
995
996
997

998
999
1000
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1065







-
+



-
+



-
+



-
+









-
+














-
+











-
+











-
+







-
+


-
+







		    }
		}

		if (compare > 0) {
		    value = -value;
		}
	    } else if (c == 'i'
		    && !strncmp("-indices", option, length)) {
		    && !strncmp("-indices", option, (unsigned) length)) {
		value = CountIndices(textPtr, indexFromPtr, indexToPtr,
			COUNT_INDICES);
	    } else if (c == 'l'
		    && !strncmp("-lines", option, length)) {
		    && !strncmp("-lines", option, (unsigned) length)) {
		value = TkBTreeLinesTo(textPtr, indexToPtr->linePtr)
			- TkBTreeLinesTo(textPtr, indexFromPtr->linePtr);
	    } else if (c == 'u'
		    && !strncmp("-update", option, length)) {
		    && !strncmp("-update", option, (unsigned) length)) {
		update = 1;
		continue;
	    } else if (c == 'x'
		    && !strncmp("-xpixels", option, length)) {
		    && !strncmp("-xpixels", option, (unsigned) length)) {
		int x1, x2;
		TkTextIndex index;

		index = *indexFromPtr;
		TkTextFindDisplayLineEnd(textPtr, &index, 0, &x1);
		index = *indexToPtr;
		TkTextFindDisplayLineEnd(textPtr, &index, 0, &x2);
		value = x2 - x1;
	    } else if (c == 'y'
		    && !strncmp("-ypixels", option, length)) {
		    && !strncmp("-ypixels", option, (unsigned) length)) {
		if (update) {
		    TkTextUpdateLineMetrics(textPtr,
			    TkBTreeLinesTo(textPtr, indexFromPtr->linePtr),
			    TkBTreeLinesTo(textPtr, indexToPtr->linePtr), -1);
		}
		value = TkTextIndexYPixels(textPtr, indexToPtr)
			- TkTextIndexYPixels(textPtr, indexFromPtr);
	    } else {
		goto badOption;
	    }

	countDone:
	    found++;
	    if (found == 1) {
		Tcl_SetObjResult(interp, Tcl_NewWideIntObj(value));
		Tcl_SetObjResult(interp, Tcl_NewIntObj(value));
	    } else {
		if (found == 2) {
		    /*
		     * Move the first item we put into the result into the
		     * first element of the list object.
		     */

		    objPtr = Tcl_NewObj();
		    Tcl_ListObjAppendElement(NULL, objPtr,
			    Tcl_GetObjResult(interp));
		}
		Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewWideIntObj(value));
		Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewIntObj(value));
	    }
	}

	if (found == 0) {
	    /*
	     * Use the default '-indices'.
	     */

	    int value = CountIndices(textPtr, indexFromPtr, indexToPtr,
		    COUNT_INDICES);

	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(value));
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(value));
	} else if (found > 1) {
	    Tcl_SetObjResult(interp, objPtr);
	}
	break;

    badOption:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad option \"%s\": must be -chars, -displaychars, "
		"bad option \"%s\" must be -chars, -displaychars, "
		"-displayindices, -displaylines, -indices, -lines, -update, "
		"-xpixels, or -ypixels", Tcl_GetString(objv[i])));
	Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_OPTION", (char *)NULL);
	Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_OPTION", NULL);
	result = TCL_ERROR;
	goto done;
    }
    case TEXT_DEBUG:
	if (objc > 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "boolean");
	    result = TCL_ERROR;
1056
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092







-
+







	break;
    case TEXT_DELETE:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "index1 ?index2 ...?");
	    result = TCL_ERROR;
	    goto done;
	}
	if (textPtr->state != TK_TEXT_STATE_DISABLED) {
	if (textPtr->state == TK_TEXT_STATE_NORMAL) {
	    if (objc < 5) {
		/*
		 * Simple case requires no predetermination of indices.
		 */

		const TkTextIndex *indexPtr1, *indexPtr2;

1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136







-
+



-
+







		 * in the exact (unshifted) text. It also needs to handle
		 * partial and fully overlapping ranges. We have to do this
		 * with multiple passes.
		 */

		TkTextIndex *indices, *ixStart, *ixEnd, *lastStart;
		char *useIdx;
		Tcl_Size i;
		int i;

		objc -= 2;
		objv += 2;
		indices = (TkTextIndex *)ckalloc((objc + 1) * sizeof(TkTextIndex));
		indices = ckalloc((objc + 1) * sizeof(TkTextIndex));

		/*
		 * First pass verifies that all indices are valid.
		 */

		for (i = 0; i < objc; i++) {
		    const TkTextIndex *indexPtr =
1128
1129
1130
1131
1132
1133
1134
1135
1136


1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1150
1151
1152
1153
1154
1155
1156


1157
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171
1172







-
-
+
+






-
+








		if (objc & 1) {
		    indices[i] = indices[i-1];
		    TkTextIndexForwChars(NULL, &indices[i], 1, &indices[i],
			    COUNT_INDICES);
		    objc++;
		}
		useIdx = (char *)ckalloc(objc);
		memset(useIdx, 0, objc);
		useIdx = ckalloc(objc);
		memset(useIdx, 0, (unsigned) objc);

		/*
		 * Do a decreasing order sort so that we delete the end ranges
		 * first to maintain index consistency.
		 */

		qsort(indices, (size_t) objc / 2,
		qsort(indices, (unsigned) objc / 2,
			2 * sizeof(TkTextIndex), TextIndexSortProc);
		lastStart = NULL;

		/*
		 * Second pass will handle bogus ranges (end < start) and
		 * overlapping ranges.
		 */
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225





1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258


1259
1260

1261
1262
1263


1264
1265
1266
1267
1268
1269
1270
1236
1237
1238
1239
1240
1241
1242





1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260


1261
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281

1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
1292
1293







-
-
-
-
-
+
+
+
+
+













-
-
+

-
+















-
+
+

-
+


-
+
+







	    result = TCL_ERROR;
	    goto done;
	}
	if (TkTextDLineInfo(textPtr, indexPtr, &x, &y, &width, &height,
		&base) == 0) {
	    Tcl_Obj *listObj = Tcl_NewListObj(0, NULL);

	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(x));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(y));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(width));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(height));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(base));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(x));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(y));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(width));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(height));
	    Tcl_ListObjAppendElement(interp, listObj, Tcl_NewIntObj(base));

	    Tcl_SetObjResult(interp, listObj);
	}
	break;
    }
    case TEXT_DUMP:
	result = TextDumpCmd(textPtr, interp, objc, objv);
	break;
    case TEXT_EDIT:
	result = TextEditCmd(textPtr, interp, objc, objv);
	break;
    case TEXT_GET: {
	Tcl_Obj *objPtr = NULL;
	Tcl_Size i;
	int found = 0, visible = 0;
	int i, found = 0, visible = 0;
	const char *name;
	Tcl_Size length;
	int length;

	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "?-displaychars? ?--? index1 ?index2 ...?");
	    result = TCL_ERROR;
	    goto done;
	}

	/*
	 * Simple, restrictive argument parsing. The only options are -- and
	 * -displaychars (or any unique prefix).
	 */

	i = 2;
	if (objc > 3) {
	    name = Tcl_GetStringFromObj(objv[i], &length);
	    name = Tcl_GetString(objv[i]);
	    length = objv[i]->length;
	    if (length > 1 && name[0] == '-') {
		if (strncmp("-displaychars", name, length) == 0) {
		if (strncmp("-displaychars", name, (unsigned) length) == 0) {
		    i++;
		    visible = 1;
		    name = Tcl_GetStringFromObj(objv[i], &length);
		    name = Tcl_GetString(objv[i]);
		    length = objv[i]->length;
		}
		if ((i < objc-1) && (length == 2) && !strcmp("--", name)) {
		    i++;
		}
	    }
	}

1359
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1382
1383
1384
1385
1386
1387
1388

1389
1390
1391
1392
1393
1394
1395
1396







-
+







	    goto done;
	}
	indexPtr = TkTextGetIndexFromObj(interp, textPtr, objv[2]);
	if (indexPtr == NULL) {
	    result = TCL_ERROR;
	    goto done;
	}
	if (textPtr->state != TK_TEXT_STATE_DISABLED) {
	if (textPtr->state == TK_TEXT_STATE_NORMAL) {
	    result = TextInsertCmd(NULL, textPtr, interp, objc-3, objv+3,
		    indexPtr, 1);
	}
	break;
    }
    case TEXT_MARK:
	result = TkTextMarkCmd(textPtr, interp, objc, objv);
1404
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416


1417
1418
1419
1420
1421
1422
1423
1424
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437


1438
1439

1440
1441
1442
1443
1444
1445
1446







-
+



-
-
+
+
-







	    result = TCL_ERROR;
	    goto done;
	}
	if (TkTextIndexCmp(indexFromPtr, indexToPtr) > 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "index \"%s\" before \"%s\" in the text",
		    Tcl_GetString(objv[3]), Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_ORDER", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_ORDER", NULL);
	    result = TCL_ERROR;
	    goto done;
	}
	if (textPtr->state != TK_TEXT_STATE_DISABLED) {
	    int lineNum;
	if (textPtr->state == TK_TEXT_STATE_NORMAL) {
	    int lineNum, byteIndex;
	    Tcl_Size byteIndex;
	    TkTextIndex index;

	    /*
	     * The 'replace' operation is quite complex to do correctly,
	     * because we want a number of criteria to hold:
	     *
	     * 1.  The insertion point shouldn't move, unless it is within the
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480

1481
1482
1483
1484
1485
1486
1487
1461
1462
1463
1464
1465
1466
1467

1468

1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485



1486
1487
1488
1489
1490
1491
1492
1493


1494



1495
1496
1497
1498
1499
1500
1501
1502







-
+
-

















-
-
-








-
-
+
-
-
-
+







		    && (TkTextIndexCmp(indexToPtr, &index) > 0)) {
		/*
		 * The insertion point is inside the range to be replaced, so
		 * we have to do some calculations to ensure it doesn't move
		 * unnecessarily.
		 */

		int deleteInsertOffset, insertLength, indexFromLine, indexFromByteOffset;
		int deleteInsertOffset, insertLength, j;
		Tcl_Size j;

		insertLength = 0;
		for (j = 4; j < objc; j += 2) {
		    insertLength += Tcl_GetCharLength(objv[j]);
		}

		/*
		 * Calculate 'deleteInsertOffset' as an offset we will apply
		 * to the insertion point after this operation.
		 */

		deleteInsertOffset = CountIndices(textPtr, indexFromPtr,
			&index, COUNT_CHARS);
		if (deleteInsertOffset > insertLength) {
		    deleteInsertOffset = insertLength;
		}

                indexFromLine = TkBTreeLinesTo(textPtr, indexFromPtr->linePtr);
                indexFromByteOffset = indexFromPtr->byteIndex;

		result = TextReplaceCmd(textPtr, interp, indexFromPtr,
			indexToPtr, objc, objv, 0);

		if (result == TCL_OK) {
		    /*
		     * Move the insertion position to the correct place.
		     */

                    TkTextIndex indexTmp;

                    indexFromPtr = TkTextGetIndexFromObj(interp, textPtr, objv[2]);
                    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, indexFromLine,
                            indexFromByteOffset, &indexTmp);
                    TkTextIndexForwChars(NULL, &indexTmp,
		    TkTextIndexForwChars(NULL, indexFromPtr,
			    deleteInsertOffset, &index, COUNT_INDICES);
		    TkBTreeUnlinkSegment(textPtr->insertMarkPtr,
			    textPtr->insertMarkPtr->body.mark.linePtr);
		    TkBTreeLinkSegment(textPtr->insertMarkPtr, &index);
		}
	    } else {
		result = TextReplaceCmd(textPtr, interp, indexFromPtr,
1509
1510
1511
1512
1513
1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546
1547
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554

1555
1556
1557
1558
1559
1560
1561
1562







-
+











-
+











-
+







	result = TkTextSeeCmd(textPtr, interp, objc, objv);
	break;
    case TEXT_SYNC: {
	if (objc == 4) {
	    Tcl_Obj *cmd = objv[3];
	    const char *option = Tcl_GetString(objv[2]);
	    if (strncmp(option, "-command", objv[2]->length)) {
		Tcl_AppendResult(interp, "wrong option \"", option, "\": should be \"-command\"", (char *)NULL);
		Tcl_AppendResult(interp, "wrong option \"", option, "\": should be \"-command\"", NULL);
		result = TCL_ERROR;
		goto done;
	    }
	    Tcl_IncrRefCount(cmd);
	    if (TkTextPendingsync(textPtr)) {
		if (textPtr->afterSyncCmd) {
		    Tcl_DecrRefCount(textPtr->afterSyncCmd);
		}
		textPtr->afterSyncCmd = cmd;
	    } else {
		textPtr->afterSyncCmd = cmd;
		Tcl_DoWhenIdle(TkTextRunAfterSyncCmd, textPtr);
		Tcl_DoWhenIdle(RunAfterSyncCmd, (ClientData) textPtr);
	    }
	    break;
	} else if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-command command?");
	    result = TCL_ERROR;
	    goto done;
	}
	if (textPtr->afterSyncCmd) {
	    Tcl_DecrRefCount(textPtr->afterSyncCmd);
	}
	textPtr->afterSyncCmd = NULL;
	TkTextUpdateLineMetrics(textPtr, 0,
	TkTextUpdateLineMetrics(textPtr, 1,
		TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr), -1);
	break;
    }
    case TEXT_TAG:
	result = TkTextTagCmd(textPtr, interp, objc, objv);
	break;
    case TEXT_WINDOW:
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589

1590
1591
1592

1593
1594
1595
1596
1597
1598
1599
1595
1596
1597
1598
1599
1600
1601

1602
1603

1604
1605
1606

1607
1608
1609
1610
1611
1612
1613
1614







-
+

-
+


-
+







 *	See the user documentation for "text".
 *
 *--------------------------------------------------------------
 */

static int
SharedTextObjCmd(
    void *clientData,	/* Information about shared test B-tree. */
    ClientData clientData,	/* Information about shared test B-tree. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkSharedText *sharedPtr = (TkSharedText *)clientData;
    register TkSharedText *sharedPtr = clientData;
    int result = TCL_OK;
    int index;

    static const char *const optionStrings[] = {
	"delete", "insert", NULL
    };
    enum options {
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







-
+







 *--------------------------------------------------------------
 */

static int
TextPeerCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = textPtr->tkwin;
    int index;

    static const char *const peerOptionStrings[] = {
	"create", "names", NULL
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







-
+







	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	peersObj = Tcl_NewObj();
	while (tPtr != NULL) {
	    if (tPtr != textPtr) {
		Tcl_ListObjAppendElement(NULL, peersObj,
			Tk_NewWindowObj(tPtr->tkwin));
			TkNewWindowObj(tPtr->tkwin));
	    }
	    tPtr = tPtr->next;
	}
	Tcl_SetObjResult(interp, peersObj);
    }
    }

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







-
+







TextReplaceCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    const TkTextIndex *indexFromPtr,
				/* Index from which to replace. */
    const TkTextIndex *indexToPtr,
				/* Index to which to replace. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    int viewUpdate)		/* Update vertical view if set. */
{
    /*
     * Perform the deletion and insertion, but ensure no undo-separator is
     * placed between the two operations. Since we are using the helper
     * functions 'DeleteIndexRange' and 'TextInsertCmd' we have to pretend
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







-
+







	/*
	 * Free up any embedded windows which belong to this widget.
	 */

	for (hPtr = Tcl_FirstHashEntry(&sharedTextPtr->windowTable, &search);
		hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    TkTextEmbWindowClient *loop;
	    TkTextSegment *ewPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	    TkTextSegment *ewPtr = Tcl_GetHashValue(hPtr);

	    loop = ewPtr->body.ew.clients;
	    if (loop->textPtr == textPtr) {
		ewPtr->body.ew.clients = loop->next;
		TkTextWinFreeClient(hPtr, loop);
	    } else {
		TkTextEmbWindowClient *client = ewPtr->body.ew.clients;
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







-
+







	 * everything in one go, more quickly.
	 */

	TkBTreeDestroy(sharedTextPtr->tree);

	for (hPtr = Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search);
		hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    tagPtr = (TkTextTag *)Tcl_GetHashValue(hPtr);
	    tagPtr = Tcl_GetHashValue(hPtr);

	    /*
	     * No need to use 'TkTextDeleteTag' since we've already removed
	     * the B-tree completely.
	     */

	    TkTextFreeTag(textPtr, tagPtr);
2053
2054
2055
2056
2057
2058
2059
2060

2061
2062

2063
2064
2065
2066

2067
2068
2069
2070
2071
2072
2073
2068
2069
2070
2071
2072
2073
2074

2075
2076

2077
2078
2079
2080

2081
2082
2083
2084
2085
2086
2087
2088







-
+

-
+



-
+







 *
 *----------------------------------------------------------------------
 */

static int
ConfigureText(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkText *textPtr,	/* Information about widget; may or may not
    register TkText *textPtr,	/* Information about widget; may or may not
				 * already have values for some fields. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_SavedOptions savedOptions;
    int oldExport = (textPtr->exportSelection) && (!Tcl_IsSafe(textPtr->interp));
    int oldExport = textPtr->exportSelection;
    int mask = 0;

    if (Tk_SetOptions(interp, (char *) textPtr, textPtr->optionTable,
	    objc, objv, textPtr->tkwin, &savedOptions, &mask) != TCL_OK) {
	return TCL_ERROR;
    }

2108
2109
2110
2111
2112
2113
2114
2115
2116


2117
2118
2119
2120
2121
2122
2123
2123
2124
2125
2126
2127
2128
2129


2130
2131
2132
2133
2134
2135
2136
2137
2138







-
-
+
+







	if (textPtr->end != NULL) {
	    end = TkBTreeLinesTo(NULL, textPtr->end);
	} else {
	    end = TkBTreeNumLines(textPtr->sharedTextPtr->tree, NULL);
	}
	if (start > end) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "-startline must be less than or equal to -endline", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_ORDER", (char *)NULL);
		    "-startline must be less than or equal to -endline", -1));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "INDEX_ORDER", NULL);
	    Tk_RestoreSavedOptions(&savedOptions);
	    return TCL_ERROR;
	}
	current = TkBTreeLinesTo(NULL, textPtr->topIndex.linePtr);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
		    &index1);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, end, 0,
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







-
+







     */

    if (textPtr->tabArrayPtr != NULL) {
	ckfree(textPtr->tabArrayPtr);
	textPtr->tabArrayPtr = NULL;
    }
    if (textPtr->tabOptionPtr != NULL) {
	textPtr->tabArrayPtr = TkTextGetTabs(interp, textPtr->tkwin,
	textPtr->tabArrayPtr = TkTextGetTabs(interp, textPtr,
		textPtr->tabOptionPtr);
	if (textPtr->tabArrayPtr == NULL) {
	    Tcl_AddErrorInfo(interp,"\n    (while processing -tabs option)");
	    Tk_RestoreSavedOptions(&savedOptions);
	    return TCL_ERROR;
	}
    }
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
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







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-






-
+




-
+

-
+












-
+







    if (textPtr->selTagPtr->selFgColor == NULL) {
	textPtr->selTagPtr->fgColor = textPtr->selFgColorPtr;
    } else {
	textPtr->selTagPtr->selFgColor = textPtr->selFgColorPtr;
    }
    textPtr->selTagPtr->affectsDisplay = 0;
    textPtr->selTagPtr->affectsDisplayGeometry = 0;
    if ((textPtr->selTagPtr->elide >= 0)
	    || (textPtr->selTagPtr->tkfont != NULL)
	    || (textPtr->selTagPtr->justify != TK_JUSTIFY_NULL)
	    || (textPtr->selTagPtr->lMargin1 != INT_MIN)
	    || (textPtr->selTagPtr->lMargin2 != INT_MIN)
	    || (textPtr->selTagPtr->offset != INT_MIN)
	    || (textPtr->selTagPtr->rMargin != INT_MIN)
	    || (textPtr->selTagPtr->spacing1 != INT_MIN)
	    || (textPtr->selTagPtr->spacing2 != INT_MIN)
	    || (textPtr->selTagPtr->spacing3 != INT_MIN)
    if ((textPtr->selTagPtr->elideString != NULL)
	    || (textPtr->selTagPtr->tkfont != None)
	    || (textPtr->selTagPtr->justifyString != NULL)
	    || (textPtr->selTagPtr->lMargin1String != NULL)
	    || (textPtr->selTagPtr->lMargin2String != NULL)
	    || (textPtr->selTagPtr->offsetString != NULL)
	    || (textPtr->selTagPtr->rMarginString != NULL)
	    || (textPtr->selTagPtr->spacing1String != NULL)
	    || (textPtr->selTagPtr->spacing2String != NULL)
	    || (textPtr->selTagPtr->spacing3String != NULL)
	    || (textPtr->selTagPtr->tabStringPtr != NULL)
	    || (textPtr->selTagPtr->tabStyle == TK_TEXT_TABSTYLE_TABULAR)
	    || (textPtr->selTagPtr->tabStyle == TK_TEXT_TABSTYLE_WORDPROCESSOR)
	    || (textPtr->selTagPtr->wrapMode != TEXT_WRAPMODE_NULL)) {
	textPtr->selTagPtr->affectsDisplay = 1;
	textPtr->selTagPtr->affectsDisplayGeometry = 1;
    }
    if ((textPtr->selTagPtr->border != NULL)
	    || (textPtr->selTagPtr->selBorder != NULL)
	    || (textPtr->selTagPtr->relief != TK_RELIEF_NULL)
	    || (textPtr->selTagPtr->reliefString != NULL)
	    || (textPtr->selTagPtr->bgStipple != None)
	    || (textPtr->selTagPtr->fgColor != NULL)
	    || (textPtr->selTagPtr->selFgColor != NULL)
	    || (textPtr->selTagPtr->fgStipple != None)
	    || (textPtr->selTagPtr->overstrike >= 0)
	    || (textPtr->selTagPtr->overstrikeString != NULL)
	    || (textPtr->selTagPtr->overstrikeColor != NULL)
	    || (textPtr->selTagPtr->underline >= 0)
	    || (textPtr->selTagPtr->underlineString != NULL)
	    || (textPtr->selTagPtr->underlineColor != NULL)
	    || (textPtr->selTagPtr->lMarginColor != NULL)
	    || (textPtr->selTagPtr->rMarginColor != NULL)) {
	textPtr->selTagPtr->affectsDisplay = 1;
    }
    TkTextRedrawTag(NULL, textPtr, NULL, NULL, textPtr->selTagPtr, 1);

    /*
     * Claim the selection if we've suddenly started exporting it and there
     * are tagged characters.
     */

    if (textPtr->exportSelection && (!oldExport) && (!Tcl_IsSafe(textPtr->interp))) {
    if (textPtr->exportSelection && (!oldExport)) {
	TkTextSearch search;
	TkTextIndex first, last;

	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, 0, 0,
		&first);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr,
		TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr),
2356
2357
2358
2359
2360
2361
2362
2363

2364
2365

2366
2367
2368
2369
2370
2371
2372
2369
2370
2371
2372
2373
2374
2375

2376
2377

2378
2379
2380
2381
2382
2383
2384
2385







-
+

-
+







 *	redisplayed.
 *
 *---------------------------------------------------------------------------
 */

static void
TextWorldChangedCallback(
    void *instanceData)	/* Information about widget. */
    ClientData instanceData)	/* Information about widget. */
{
    TkText *textPtr = (TkText *)instanceData;
    TkText *textPtr = instanceData;

    TextWorldChanged(textPtr, TK_TEXT_LINE_GEOMETRY);
}

/*
 *---------------------------------------------------------------------------
 *
2446
2447
2448
2449
2450
2451
2452
2453
2454


2455
2456

2457
2458
2459
2460
2461
2462
2463
2459
2460
2461
2462
2463
2464
2465


2466
2467
2468

2469
2470
2471
2472
2473
2474
2475
2476







-
-
+
+

-
+







 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
TextEventProc(
    void *clientData,	/* Information about window. */
    XEvent *eventPtr)	/* Information about event. */
    ClientData clientData,	/* Information about window. */
    register XEvent *eventPtr)	/* Information about event. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    TkTextIndex index, index2;

    if (eventPtr->type == Expose) {
	TkTextRedrawRegion(textPtr, eventPtr->xexpose.x,
		eventPtr->xexpose.y, eventPtr->xexpose.width,
		eventPtr->xexpose.height);
    } else if (eventPtr->type == ConfigureNotify) {
2486
2487
2488
2489
2490
2491
2492
2493

2494
2495
2496
2497
2498
2499
2500
2499
2500
2501
2502
2503
2504
2505

2506
2507
2508
2509
2510
2511
2512
2513







-
+







	textPtr->selBorderWidth = 0;
	textPtr->selFgColorPtr = NULL;
	if (textPtr->setGrid) {
	    Tk_UnsetGrid(textPtr->tkwin);
	    textPtr->setGrid = 0;
	}
	if (!(textPtr->flags & OPTIONS_FREED)) {
	    Tk_FreeConfigOptions(textPtr, textPtr->optionTable,
	    Tk_FreeConfigOptions((char *) textPtr, textPtr->optionTable,
		    textPtr->tkwin);
	    textPtr->flags |= OPTIONS_FREED;
	}
	textPtr->flags |= DESTROYED;

	/*
	 * Call 'DestroyTest' to handle the deletion for us. The actual
2556
2557
2558
2559
2560
2561
2562
2563

2564
2565

2566
2567
2568
2569
2570
2571
2572
2569
2570
2571
2572
2573
2574
2575

2576
2577

2578
2579
2580
2581
2582
2583
2584
2585







-
+

-
+







 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
TextCmdDeletedProc(
    void *clientData)	/* Pointer to widget record for widget. */
    ClientData clientData)	/* Pointer to widget record for widget. */
{
    TkText *textPtr = (TkText *)clientData;
    TkText *textPtr = clientData;
    Tk_Window tkwin = textPtr->tkwin;

    /*
     * This function could be invoked either because the window was destroyed
     * and the command was then deleted (in which this flag is already set) or
     * because the command was deleted, and then this function destroys the
     * widget.
2610
2611
2612
2613
2614
2615
2616
2617

2618
2619
2620
2621
2622
2623

2624

2625
2626
2627
2628
2629
2630
2631
2623
2624
2625
2626
2627
2628
2629

2630

2631
2632
2633
2634

2635
2636
2637
2638
2639
2640
2641
2642
2643
2644







-
+
-




-
+

+







    TkTextIndex *indexPtr,	/* Where to insert new characters. May be
				 * modified if the index is not valid for
				 * insertion (e.g. if at "end"). */
    Tcl_Obj *stringPtr,		/* Null-terminated string containing new
				 * information to add to text. */
    int viewUpdate)		/* Update the view if set. */
{
    int lineIndex;
    int lineIndex, length;
    Tcl_Size length;
    TkText *tPtr;
    int *lineAndByteIndex;
    int resetViewCount;
    int pixels[2*PIXEL_CLIENTS];
    const char *string = Tcl_GetStringFromObj(stringPtr, &length);
    const char *string = Tcl_GetString(stringPtr);

    length = stringPtr->length;
    if (sharedTextPtr == NULL) {
	sharedTextPtr = textPtr->sharedTextPtr;
    }

    /*
     * Don't allow insertions on the last (dummy) line of the text. This is
     * the only place in this function where the indexPtr is modified.
2643
2644
2645
2646
2647
2648
2649
2650

2651
2652
2653
2654
2655
2656
2657
2656
2657
2658
2659
2660
2661
2662

2663
2664
2665
2666
2667
2668
2669
2670







-
+







     * insertion. If the insertion occurs on the top line of the widget
     * (textPtr->topIndex), then we have to recompute topIndex after the
     * insertion, since the insertion could invalidate it.
     */

    resetViewCount = 0;
    if (sharedTextPtr->refCount > PIXEL_CLIENTS) {
	lineAndByteIndex = (int *)ckalloc(sizeof(int) * 2 * sharedTextPtr->refCount);
	lineAndByteIndex = ckalloc(sizeof(int) * 2 * sharedTextPtr->refCount);
    } else {
	lineAndByteIndex = pixels;
    }
    for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) {
	lineAndByteIndex[resetViewCount] = -1;
	if (indexPtr->linePtr == tPtr->topIndex.linePtr) {
	    lineAndByteIndex[resetViewCount] =
2709
2710
2711
2712
2713
2714
2715
2716

2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2722
2723
2724
2725
2726
2727
2728

2729

2730
2731
2732



2733
2734
2735
2736
2737
2738
2739







-
+
-



-
-
-







	resetViewCount += 2;
    }
    if (sharedTextPtr->refCount > PIXEL_CLIENTS) {
	ckfree(lineAndByteIndex);
    }

    /*
     * Invalidate any selection retrievals in progress, and send an event
     * Invalidate any selection retrievals in progress.
     * that the selection changed if that is the case.
     */

    for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) {
        if (TkBTreeCharTagged(indexPtr, tPtr->selTagPtr)) {
            TkTextSelectionEvent(tPtr);
        }
	tPtr->abortSelections = 1;
    }

    /*
     * For convenience, return the length of the string.
     */

2758
2759
2760
2761
2762
2763
2764
2765
2766
2767



2768
2769
2770
2771
2772
2773
2774
2767
2768
2769
2770
2771
2772
2773



2774
2775
2776
2777
2778
2779
2780
2781
2782
2783







-
-
-
+
+
+







    const TkTextIndex *index1Ptr,
				/* Index describing first location. */
    const TkTextIndex *index2Ptr)
				/* Index describing second location. */
{
    TkUndoSubAtom *iAtom, *dAtom;
    int canUndo, canRedo;
    char lMarkName[16 + TCL_INTEGER_SPACE] = "tk::undoMarkL";
    char rMarkName[16 + TCL_INTEGER_SPACE] = "tk::undoMarkR";
    char stringUndoMarkId[TCL_INTEGER_SPACE] = "";
    char lMarkName[20] = "tk::undoMarkL";
    char rMarkName[20] = "tk::undoMarkR";
    char stringUndoMarkId[7] = "";

    /*
     * Create the helpers.
     */

    Tcl_Obj *seeInsertObj = Tcl_NewObj();
    Tcl_Obj *markSet1InsertObj = Tcl_NewObj();
2792
2793
2794
2795
2796
2797
2798
2799

2800
2801
2802
2803
2804
2805

2806
2807
2808
2809
2810
2811
2812
2801
2802
2803
2804
2805
2806
2807

2808
2809
2810
2811
2812
2813

2814
2815
2816
2817
2818
2819
2820
2821







-
+





-
+







     */

    Tcl_IncrRefCount(seeInsertObj);
    Tcl_IncrRefCount(index1Obj);
    Tcl_IncrRefCount(index2Obj);

    Tcl_ListObjAppendElement(NULL, seeInsertObj,
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), -1));
    Tcl_ListObjAppendElement(NULL, seeInsertObj, Tcl_NewStringObj("see", 3));
    Tcl_ListObjAppendElement(NULL, seeInsertObj,
	    Tcl_NewStringObj("insert", 6));

    Tcl_ListObjAppendElement(NULL, markSet1InsertObj,
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), -1));
    Tcl_ListObjAppendElement(NULL, markSet1InsertObj,
	    Tcl_NewStringObj("mark", 4));
    Tcl_ListObjAppendElement(NULL, markSet1InsertObj,
	    Tcl_NewStringObj("set", 3));
    Tcl_ListObjAppendElement(NULL, markSet1InsertObj,
	    Tcl_NewStringObj("insert", 6));
    markSet2InsertObj = Tcl_DuplicateObj(markSet1InsertObj);
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
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







-
+






-
+



-
+

-
+




-
+






-
+

-
+








    Tcl_ListObjAppendElement(NULL, deleteCmdObj,
	    Tcl_NewStringObj("delete", 6));
    Tcl_ListObjAppendElement(NULL, deleteCmdObj, index1Obj);
    Tcl_ListObjAppendElement(NULL, deleteCmdObj, index2Obj);

    Tcl_ListObjAppendElement(NULL, markSetLUndoMarkCmdObj,
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), -1));
    Tcl_ListObjAppendElement(NULL, markSetLUndoMarkCmdObj,
	    Tcl_NewStringObj("mark", 4));
    Tcl_ListObjAppendElement(NULL, markSetLUndoMarkCmdObj,
	    Tcl_NewStringObj("set", 3));
    markSetRUndoMarkCmdObj = Tcl_DuplicateObj(markSetLUndoMarkCmdObj);
    textPtr->sharedTextPtr->undoMarkId++;
    snprintf(stringUndoMarkId, TCL_INTEGER_SPACE, "%" TCL_SIZE_MODIFIER "d", textPtr->sharedTextPtr->undoMarkId);
    sprintf(stringUndoMarkId, "%d", textPtr->sharedTextPtr->undoMarkId);
    strcat(lMarkName, stringUndoMarkId);
    strcat(rMarkName, stringUndoMarkId);
    Tcl_ListObjAppendElement(NULL, markSetLUndoMarkCmdObj,
	    Tcl_NewStringObj(lMarkName, TCL_INDEX_NONE));
	    Tcl_NewStringObj(lMarkName, -1));
    Tcl_ListObjAppendElement(NULL, markSetRUndoMarkCmdObj,
	    Tcl_NewStringObj(rMarkName, TCL_INDEX_NONE));
	    Tcl_NewStringObj(rMarkName, -1));
    Tcl_ListObjAppendElement(NULL, markSetLUndoMarkCmdObj, index1Obj);
    Tcl_ListObjAppendElement(NULL, markSetRUndoMarkCmdObj, index2Obj);

    Tcl_ListObjAppendElement(NULL, markGravityLUndoMarkCmdObj,
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), -1));
    Tcl_ListObjAppendElement(NULL, markGravityLUndoMarkCmdObj,
	    Tcl_NewStringObj("mark", 4));
    Tcl_ListObjAppendElement(NULL, markGravityLUndoMarkCmdObj,
	    Tcl_NewStringObj("gravity", 7));
    markGravityRUndoMarkCmdObj = Tcl_DuplicateObj(markGravityLUndoMarkCmdObj);
    Tcl_ListObjAppendElement(NULL, markGravityLUndoMarkCmdObj,
	    Tcl_NewStringObj(lMarkName, TCL_INDEX_NONE));
	    Tcl_NewStringObj(lMarkName, -1));
    Tcl_ListObjAppendElement(NULL, markGravityRUndoMarkCmdObj,
	    Tcl_NewStringObj(rMarkName, TCL_INDEX_NONE));
	    Tcl_NewStringObj(rMarkName, -1));
    Tcl_ListObjAppendElement(NULL, markGravityLUndoMarkCmdObj,
            Tcl_NewStringObj("left", 4));
    Tcl_ListObjAppendElement(NULL, markGravityRUndoMarkCmdObj,
            Tcl_NewStringObj("right", 5));

    /*
     * Note: we don't wish to use textPtr->widgetCmd in these callbacks
2936
2937
2938
2939
2940
2941
2942
2943

2944
2945
2946
2947
2948
2949


2950
2951
2952
2953
2954
2955
2956
2957
2945
2946
2947
2948
2949
2950
2951

2952
2953
2954
2955
2956


2957
2958

2959
2960
2961
2962
2963
2964
2965







-
+




-
-
+
+
-







 *
 *----------------------------------------------------------------------
 */

int
TextUndoRedoCallback(
    Tcl_Interp *interp,		/* Current interpreter. */
    void *clientData,	/* Passed from undo code, but contains our
    ClientData clientData,	/* Passed from undo code, but contains our
				 * shared text data structure. */
    Tcl_Obj *objPtr)		/* Arguments of a command to be handled by the
				 * shared text data structure. */
{
    TkSharedText *sharedPtr = (TkSharedText *)clientData;
    int res;
    TkSharedText *sharedPtr = clientData;
    int res, objc;
    Tcl_Size objc;
    Tcl_Obj **objv;
    TkText *textPtr;

    res = Tcl_ListObjGetElements(interp, objPtr, &objc, &objv);
    if (res != TCL_OK) {
	return res;
    }
2991
2992
2993
2994
2995
2996
2997
2998

2999
3000
3001
3002
3003
3004
3005
2999
3000
3001
3002
3003
3004
3005

3006
3007
3008
3009
3010
3011
3012
3013







-
+







	     *
	     * While such interception is not explicitly documented as
	     * supported, it does occur, and so until we can provide some
	     * alternative mechanism for such code to do what it needs, we
	     * allow it to take place here.
	     */

	    cmdNameObj = Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), TCL_INDEX_NONE);
	    cmdNameObj = Tcl_NewStringObj(Tk_PathName(textPtr->tkwin), -1);
	    Tcl_ListObjAppendElement(NULL, evalObj, cmdNameObj);
	    Tcl_ListObjAppendList(NULL, evalObj, objPtr);
	    res = Tcl_EvalObjEx(interp, evalObj, TCL_EVAL_GLOBAL);
	    Tcl_DecrRefCount(evalObj);
	    return res;
	}
	textPtr = textPtr->next;
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3114
3115
3116
3117
3118
3119
3120



3121
3122
3123
3124
3125
3126
3127







-
-
-







{
    int line1, line2;
    TkTextIndex index1, index2;
    TkText *tPtr;
    int *lineAndByteIndex;
    int resetViewCount;
    int pixels[2*PIXEL_CLIENTS];
    Tcl_HashSearch search;
    Tcl_HashEntry *hPtr;
    Tcl_Size i;

    if (sharedTextPtr == NULL) {
	sharedTextPtr = textPtr->sharedTextPtr;
    }

    /*
     * Prepare the starting and stopping indices.
3154
3155
3156
3157
3158
3159
3160
3161

3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179

3180
3181
3182
3183
3184





3185




3186
3187
3188
3189






3190
3191
3192
3193
3194




3195
3196
3197
3198
3199
3200
3201
3202
3203








3204
3205
3206
3207




3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222

3223
3224
3225
3226
3227
3228

3229
3230
3231
3232
3233
3234
3235
3159
3160
3161
3162
3163
3164
3165

3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185





3186
3187
3188
3189
3190
3191
3192
3193
3194
3195




3196
3197
3198
3199
3200
3201
3202




3203
3204
3205
3206
3207








3208
3209
3210
3211
3212
3213
3214
3215
3216



3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234

3235
3236
3237
3238
3239
3240

3241
3242
3243
3244
3245
3246
3247
3248







-
+


















+
-
-
-
-
-
+
+
+
+
+

+
+
+
+
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+














-
+





-
+







     * deleted but tags might be removed.
     */

    line1 = TkBTreeLinesTo(textPtr, index1.linePtr);
    line2 = TkBTreeLinesTo(textPtr, index2.linePtr);
    if (line2 == TkBTreeNumLines(sharedTextPtr->tree, textPtr)) {
	TkTextTag **arrayPtr;
	Tcl_Size arraySize;
	int arraySize, i;
	TkTextIndex oldIndex2;

	oldIndex2 = index2;
	TkTextIndexBackChars(NULL, &oldIndex2, 1, &index2, COUNT_INDICES);
	line2--;
	if ((index1.byteIndex == 0) && (line1 != 0)) {
	    TkTextIndexBackChars(NULL, &index1, 1, &index1, COUNT_INDICES);
	    line1--;
	}
	arrayPtr = TkBTreeGetTags(&index2, NULL, &arraySize);
	if (arrayPtr != NULL) {
	    for (i = 0; i < arraySize; i++) {
		TkBTreeTag(&index2, &oldIndex2, arrayPtr[i], 0);
	    }
	    ckfree(arrayPtr);
	}
    }

    if (line1 < line2) {
    /*
     * For speed, we remove all tags from the range first. If we don't
     * do this, the code below can (when there are many tags) grow
     * non-linearly in execution time.
     */
	/*
	 * We are deleting more than one line. For speed, we remove all tags
	 * from the range first. If we don't do this, the code below can (when
	 * there are many tags) grow non-linearly in execution time.
	 */

	Tcl_HashSearch search;
	Tcl_HashEntry *hPtr;
	int i;

    for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search);
	    hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) {
        TkBTreeTag(&index1, &index2, (TkTextTag *)Tcl_GetHashValue(hPtr), 0);
    }
	for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search);
		hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) {
	    TkTextTag *tagPtr = Tcl_GetHashValue(hPtr);

	    TkBTreeTag(&index1, &index2, tagPtr, 0);
	}

    /*
     * Special case for the sel tag which is not in the hash table. We
     * need to do this once for each peer text widget.
     */
	/*
	 * Special case for the sel tag which is not in the hash table. We
	 * need to do this once for each peer text widget.
	 */

    for (tPtr = sharedTextPtr->peers; tPtr != NULL ;
	    tPtr = tPtr->next) {
        if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) {
	    /*
	     * Send an event that the selection changed. This is
	     * equivalent to:
	     *	event generate $textWidget <<Selection>>
	     */
	for (tPtr = sharedTextPtr->peers; tPtr != NULL ;
		tPtr = tPtr->next) {
	    if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) {
		/*
		 * Send an event that the selection changed. This is
		 * equivalent to:
		 *	event generate $textWidget <<Selection>>
		 */

	    TkTextSelectionEvent(textPtr);
	    tPtr->abortSelections = 1;
        }
		TkTextSelectionEvent(textPtr);
		tPtr->abortSelections = 1;
	    }
	}
    }

    /*
     * Tell the display what's about to happen so it can discard obsolete
     * display information, then do the deletion. Also, if the deletion
     * involves the top line on the screen, then we have to reset the view
     * (the deletion will invalidate textPtr->topIndex). Compute what the new
     * first character will be, then do the deletion, then reset the view.
     */

    TkTextChanged(sharedTextPtr, NULL, &index1, &index2);

    resetViewCount = 0;
    if (sharedTextPtr->refCount > PIXEL_CLIENTS) {
	lineAndByteIndex = (int *)ckalloc(sizeof(int) * 2 * sharedTextPtr->refCount);
	lineAndByteIndex = ckalloc(sizeof(int) * 2 * sharedTextPtr->refCount);
    } else {
	lineAndByteIndex = pixels;
    }
    for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) {
	int line = 0;
	Tcl_Size byteIndex = 0;
	int byteIndex = 0;
	int resetView = 0;

	if (TkTextIndexCmp(&index2, &tPtr->topIndex) >= 0) {
	    if (TkTextIndexCmp(&index1, &tPtr->topIndex) <= 0) {
		/*
		 * Deletion range straddles topIndex: use the beginning of the
		 * range as the new topIndex.
3306
3307
3308
3309
3310
3311
3312
3313

3314
3315
3316

3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334

3335
3336
3337
3338
3339
3340
3341
3342
3343

3344
3345
3346



3347
3348








3349
3350
3351
3352
3353
3354
3355
3319
3320
3321
3322
3323
3324
3325

3326
3327
3328

3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346

3347
3348
3349
3350
3351
3352
3353
3354
3355

3356

3357
3358
3359
3360
3361


3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376







-
+


-
+

















-
+








-
+
-


+
+
+
-
-
+
+
+
+
+
+
+
+







	TkBTreeDeleteIndexRange(sharedTextPtr->tree, &index1, &index2);

    	UpdateDirtyFlag(sharedTextPtr);
    }

    resetViewCount = 0;
    for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) {
	Tcl_Size line = lineAndByteIndex[resetViewCount];
	int line = lineAndByteIndex[resetViewCount];

	if (line != -1) {
	    Tcl_Size byteIndex = lineAndByteIndex[resetViewCount+1];
	    int byteIndex = lineAndByteIndex[resetViewCount+1];
	    TkTextIndex indexTmp;

	    if (tPtr == textPtr) {
		if (viewUpdate) {
		    /*
		     * line cannot be before -startline of textPtr because
		     * this line corresponds to an index which is necessarily
		     * between "1.0" and "end" relative to textPtr.
		     * Therefore no need to clamp line to the -start/-end
		     * range.
		     */

		    TkTextMakeByteIndex(sharedTextPtr->tree, textPtr, line,
			    byteIndex, &indexTmp);
		    TkTextSetYView(tPtr, &indexTmp, 0);
		}
	    } else {
		TkTextMakeByteIndex(sharedTextPtr->tree, NULL, line,
		TkTextMakeByteIndex(sharedTextPtr->tree, tPtr, line,
			byteIndex, &indexTmp);
		/*
		 * line may be before -startline of tPtr and must be
		 * clamped to -startline before providing it to
		 * TkTextSetYView otherwise lines before -startline
		 * would be displayed.
		 * There is no need to worry about -endline however,
		 * because the view will only be reset if the deletion
		 * involves the TOP line of the screen. That said,
		 * involves the TOP line of the screen
		 * the following call adjusts to both.
		 */

		if (tPtr->start != NULL) {
		    int start;
		    TkTextIndex indexStart;
		TkTextIndexAdjustToStartEnd(tPtr, &indexTmp, 0);


		    start = TkBTreeLinesTo(NULL, tPtr->start);
		    TkTextMakeByteIndex(sharedTextPtr->tree, NULL, start,
			    0, &indexStart);
		    if (TkTextIndexCmp(&indexTmp, &indexStart) < 0) {
			indexTmp = indexStart;
		    }
		}
		TkTextSetYView(tPtr, &indexTmp, 0);
	    }
	}
	resetViewCount += 2;
    }
    if (sharedTextPtr->refCount > PIXEL_CLIENTS) {
	ckfree(lineAndByteIndex);
3386
3387
3388
3389
3390
3391
3392
3393

3394
3395
3396


3397
3398
3399

3400
3401
3402
3403

3404
3405

3406
3407
3408
3409

3410
3411
3412
3413
3414
3415
3416
3407
3408
3409
3410
3411
3412
3413

3414
3415


3416
3417
3418
3419

3420
3421
3422
3423

3424
3425

3426
3427
3428
3429

3430
3431
3432
3433
3434
3435
3436
3437







-
+

-
-
+
+


-
+



-
+

-
+



-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
TextFetchSelection(
    void *clientData,	/* Information about text widget. */
    Tcl_Size offset,			/* Offset within selection of first character
    ClientData clientData,	/* Information about text widget. */
    int offset,			/* Offset within selection of first character
				 * to be returned. */
    char *buffer,		/* Location in which to place selection. */
    Tcl_Size maxBytes)		/* Maximum number of bytes to place at buffer,
    int maxBytes)		/* Maximum number of bytes to place at buffer,
				 * not including terminating NULL
				 * character. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    TkTextIndex eof;
    Tcl_Size count, offsetInSeg, chunkSize;
    int count, chunkSize, offsetInSeg;
    TkTextSearch search;
    TkTextSegment *segPtr;

    if ((!textPtr->exportSelection) || Tcl_IsSafe(textPtr->interp)) {
    if (!textPtr->exportSelection) {
	return -1;
    }

    /*
     * Find the beginning of the next range of selected text. Note: if the
     * selection is being retrieved in multiple pieces (offset != 0) and some
     * modification has been made to the text that affects the selection then
3462
3463
3464
3465
3466
3467
3468
3469
3470


3471
3472
3473

3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487

3488
3489
3490
3491
3492
3493
3494
3483
3484
3485
3486
3487
3488
3489


3490
3491
3492
3493

3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507

3508
3509
3510
3511
3512
3513
3514
3515







-
-
+
+


-
+













-
+








	while (1) {
	    if (maxBytes == 0) {
		goto fetchDone;
	    }
	    segPtr = TkTextIndexToSeg(&textPtr->selIndex, &offsetInSeg);
	    chunkSize = segPtr->size - offsetInSeg;
	    if (chunkSize > (int)maxBytes) {
		chunkSize = (int)maxBytes;
	    if (chunkSize > maxBytes) {
		chunkSize = maxBytes;
	    }
	    if (textPtr->selIndex.linePtr == search.curIndex.linePtr) {
		Tcl_Size leftInRange;
		int leftInRange;

		leftInRange = search.curIndex.byteIndex
			- textPtr->selIndex.byteIndex;
		if (leftInRange < chunkSize) {
		    chunkSize = leftInRange;
		    if (chunkSize <= 0) {
			break;
		    }
		}
	    }
	    if ((segPtr->typePtr == &tkTextCharType)
		    && !TkTextIsElided(textPtr, &textPtr->selIndex, NULL)) {
		memcpy(buffer, segPtr->body.chars + offsetInSeg,
			chunkSize);
			(size_t) chunkSize);
		buffer += chunkSize;
		maxBytes -= chunkSize;
		count += chunkSize;
	    }
	    TkTextIndexForwBytes(textPtr, &textPtr->selIndex, chunkSize,
		    &textPtr->selIndex);
	}
3525
3526
3527
3528
3529
3530
3531
3532

3533
3534

3535
3536

3537
3538
3539

3540
3541
3542
3543
3544
3545
3546
3546
3547
3548
3549
3550
3551
3552

3553
3554

3555
3556

3557
3558
3559

3560
3561
3562
3563
3564
3565
3566
3567







-
+

-
+

-
+


-
+







 *	The "sel" tag is cleared from the window.
 *
 *----------------------------------------------------------------------
 */

void
TkTextLostSelection(
    void *clientData)	/* Information about text widget. */
    ClientData clientData)	/* Information about text widget. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;

    if (Tk_AlwaysShowSelection(textPtr->tkwin)) {
    if (TkpAlwaysShowSelection(textPtr->tkwin)) {
	TkTextIndex start, end;

	if ((!textPtr->exportSelection) || Tcl_IsSafe(textPtr->interp)) {
	if (!textPtr->exportSelection) {
	    return;
	}

	/*
	 * On Windows and Mac systems, we want to remember the selection for
	 * the next time the focus enters the window. On Unix, just remove the
	 * "sel" tag from everything in the widget.
3587
3588
3589
3590
3591
3592
3593
3594

3595
3596
3597
3598
3599
3600
3601
3608
3609
3610
3611
3612
3613
3614

3615
3616
3617
3618
3619
3620
3621
3622







-
+







    TkText *textPtr)
{
    /*
     * Send an event that the selection changed. This is equivalent to:
     *     event generate $textWidget <<Selection>>
     */

    Tk_SendVirtualEvent(textPtr->tkwin, "Selection", NULL);
    TkSendVirtualEvent(textPtr->tkwin, "Selection", NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * TextBlinkProc --
 *
3610
3611
3612
3613
3614
3615
3616
3617

3618
3619

3620
3621
3622
3623
3624
3625
3626
3631
3632
3633
3634
3635
3636
3637

3638
3639

3640
3641
3642
3643
3644
3645
3646
3647







-
+

-
+







 *	function reschedules itself.
 *
 *----------------------------------------------------------------------
 */

static void
TextBlinkProc(
    void *clientData)	/* Pointer to record describing text. */
    ClientData clientData)	/* Pointer to record describing text. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    TkTextIndex index;
    int x, y, w, h, charWidth;

    if ((textPtr->state == TK_TEXT_STATE_DISABLED) ||
	    !(textPtr->flags & GOT_FOCUS) || (textPtr->insertOffTime == 0)) {
	if (!(textPtr->flags & GOT_FOCUS) &&
		(textPtr->insertUnfocussed != TK_TEXT_INSERT_NOFOCUS_NONE)) {
3688
3689
3690
3691
3692
3693
3694
3695

3696
3697
3698
3699
3700
3701

3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716

3717
3718
3719
3720
3721
3722

3723
3724
3725
3726
3727

3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738

3739
3740
3741
3742
3743
3744
3745
3709
3710
3711
3712
3713
3714
3715

3716
3717
3718
3719
3720
3721

3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736

3737
3738
3739
3740
3741
3742

3743
3744
3745
3746
3747

3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758

3759
3760
3761
3762
3763
3764
3765
3766







-
+





-
+














-
+





-
+




-
+










-
+







 */

static int
TextInsertCmd(
    TkSharedText *sharedTextPtr,/* Shared portion of peer widgets. */
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    const TkTextIndex *indexPtr,/* Index at which to insert. */
    int viewUpdate)		/* Update the view if set. */
{
    TkTextIndex index1, index2;
    Tcl_Size j;
    int j;

    if (sharedTextPtr == NULL) {
	sharedTextPtr = textPtr->sharedTextPtr;
    }

    index1 = *indexPtr;
    for (j = 0; j < objc; j += 2) {
	/*
	 * Here we rely on this call to modify index1 if it is outside the
	 * acceptable range. In particular, if index1 is "end", it must be set
	 * to the last allowable index for insertion, otherwise subsequent tag
	 * insertions will fail.
	 */

	Tcl_Size length = InsertChars(sharedTextPtr, textPtr, &index1, objv[j],
	int length = InsertChars(sharedTextPtr, textPtr, &index1, objv[j],
		viewUpdate);

	if (objc > (j+1)) {
	    Tcl_Obj **tagNamePtrs;
	    TkTextTag **oldTagArrayPtr;
	    Tcl_Size numTags;
	    int numTags;

	    TkTextIndexForwBytes(textPtr, &index1, length, &index2);
	    oldTagArrayPtr = TkBTreeGetTags(&index1, NULL, &numTags);
	    if (oldTagArrayPtr != NULL) {
		Tcl_Size i;
		int i;

		for (i = 0; i < numTags; i++) {
		    TkBTreeTag(&index1, &index2, oldTagArrayPtr[i], 0);
		}
		ckfree(oldTagArrayPtr);
	    }
	    if (Tcl_ListObjGetElements(interp, objv[j+1], &numTags,
		    &tagNamePtrs) != TCL_OK) {
		return TCL_ERROR;
	    } else {
		Tcl_Size i;
		int i;

		for (i = 0; i < numTags; i++) {
		    const char *strTag = Tcl_GetString(tagNamePtrs[i]);

		    TkBTreeTag(&index1, &index2,
			    TkTextCreateTag(textPtr, strTag, NULL), 1);
		}
3767
3768
3769
3770
3771
3772
3773
3774

3775
3776
3777

3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790




3791
3792
3793
3794
3795
3796
3797
3788
3789
3790
3791
3792
3793
3794

3795
3796
3797

3798

3799
3800
3801
3802
3803
3804
3805
3806




3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817







-
+


-
+
-








-
-
-
-
+
+
+
+







 *----------------------------------------------------------------------
 */

static int
TextSearchCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tcl_Size i, argsLeft;
    int i, argsLeft, code;
    int code;
    SearchSpec searchSpec;

    static const char *const switchStrings[] = {
	"-hidden",
	"--", "-all", "-backwards", "-count", "-elide", "-exact", "-forwards",
	"-nocase", "-nolinestop", "-overlap", "-regexp", "-strictlimits", NULL
    };
    enum SearchSwitches {
	TK_TEXT_SEARCH_HIDDEN,
	TK_TEXT_SEARCH_END, TK_TEXT_SEARCH_ALL, TK_TEXT_SEARCH_BACK, TK_TEXT_SEARCH_COUNT, TK_TEXT_SEARCH_ELIDE,
	TK_TEXT_SEARCH_EXACT, TK_TEXT_SEARCH_FWD, TK_TEXT_SEARCH_NOCASE,
	TK_TEXT_SEARCH_NOLINESTOP, TK_TEXT_SEARCH_OVERLAP, TK_TEXT_SEARCH_REGEXP, TK_TEXT_SEARCH_STRICTLIMITS
	SEARCH_HIDDEN,
	SEARCH_END, SEARCH_ALL, SEARCH_BACK, SEARCH_COUNT, SEARCH_ELIDE,
	SEARCH_EXACT, SEARCH_FWD, SEARCH_NOCASE,
	SEARCH_NOLINESTOP, SEARCH_OVERLAP, SEARCH_REGEXP, SEARCH_STRICTLIMITS
    };

    /*
     * Set up the search specification, including the last 4 fields which are
     * text widget specific.
     */

3833
3834
3835
3836
3837
3838
3839
3840

3841
3842
3843

3844
3845
3846

3847
3848
3849
3850


3851
3852
3853


3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866


3867
3868
3869

3870
3871
3872

3873
3874
3875

3876
3877
3878

3879
3880
3881

3882
3883
3884

3885
3886
3887

3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907


3908
3909
3910
3911
3912
3913
3914
3915


3916
3917
3918
3919
3920
3921
3922
3853
3854
3855
3856
3857
3858
3859

3860
3861
3862

3863
3864
3865

3866
3867
3868


3869
3870
3871


3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884


3885
3886
3887
3888

3889
3890
3891

3892
3893
3894

3895
3896
3897

3898
3899
3900

3901
3902
3903

3904
3905
3906

3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925


3926
3927
3928
3929
3930
3931
3932
3933


3934
3935
3936
3937
3938
3939
3940
3941
3942







-
+


-
+


-
+


-
-
+
+

-
-
+
+











-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


















-
-
+
+






-
-
+
+








	    (void) Tcl_GetIndexFromObjStruct(interp, objv[i], switchStrings+1,
		    sizeof(char *), "switch", 0, &index);
	    return TCL_ERROR;
	}

	switch ((enum SearchSwitches) index) {
	case TK_TEXT_SEARCH_END:
	case SEARCH_END:
	    i++;
	    goto endOfSwitchProcessing;
	case TK_TEXT_SEARCH_ALL:
	case SEARCH_ALL:
	    searchSpec.all = 1;
	    break;
	case TK_TEXT_SEARCH_BACK:
	case SEARCH_BACK:
	    searchSpec.backwards = 1;
	    break;
	case TK_TEXT_SEARCH_COUNT:
	    if (i + 1 >= objc) {
	case SEARCH_COUNT:
	    if (i >= objc-1) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"no value given for \"-count\" option", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "TEXT", "VALUE", (char *)NULL);
			"no value given for \"-count\" option", -1));
		Tcl_SetErrorCode(interp, "TK", "TEXT", "VALUE", NULL);
		return TCL_ERROR;
	    }
	    i++;

	    /*
	     * Assumption objv[i] isn't going to disappear on us during this
	     * function, which is fair.
	     */

	    searchSpec.varPtr = objv[i];
	    break;
	case TK_TEXT_SEARCH_ELIDE:
	case TK_TEXT_SEARCH_HIDDEN:
	case SEARCH_ELIDE:
	case SEARCH_HIDDEN:
	    searchSpec.searchElide = 1;
	    break;
	case TK_TEXT_SEARCH_EXACT:
	case SEARCH_EXACT:
	    searchSpec.exact = 1;
	    break;
	case TK_TEXT_SEARCH_FWD:
	case SEARCH_FWD:
	    searchSpec.backwards = 0;
	    break;
	case TK_TEXT_SEARCH_NOCASE:
	case SEARCH_NOCASE:
	    searchSpec.noCase = 1;
	    break;
	case TK_TEXT_SEARCH_NOLINESTOP:
	case SEARCH_NOLINESTOP:
	    searchSpec.noLineStop = 1;
	    break;
	case TK_TEXT_SEARCH_OVERLAP:
	case SEARCH_OVERLAP:
	    searchSpec.overlap = 1;
	    break;
	case TK_TEXT_SEARCH_STRICTLIMITS:
	case SEARCH_STRICTLIMITS:
	    searchSpec.strictLimits = 1;
	    break;
	case TK_TEXT_SEARCH_REGEXP:
	case SEARCH_REGEXP:
	    searchSpec.exact = 0;
	    break;
	default:
	    Tcl_Panic("unexpected switch fallthrough");
	}
    }
  endOfSwitchProcessing:

    argsLeft = objc - (i+2);
    if ((argsLeft != 0) && (argsLeft != 1)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"?switches? pattern index ?stopIndex?");
	return TCL_ERROR;
    }

    if (searchSpec.noLineStop && searchSpec.exact) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"the \"-nolinestop\" option requires the \"-regexp\" option"
		" to be present", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "TEXT", "SEARCH_USAGE", (char *)NULL);
		" to be present", -1));
	Tcl_SetErrorCode(interp, "TK", "TEXT", "SEARCH_USAGE", NULL);
	return TCL_ERROR;
    }

    if (searchSpec.overlap && !searchSpec.all) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"the \"-overlap\" option requires the \"-all\" option"
		" to be present", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "TEXT", "SEARCH_USAGE", (char *)NULL);
		" to be present", -1));
	Tcl_SetErrorCode(interp, "TK", "TEXT", "SEARCH_USAGE", NULL);
	return TCL_ERROR;
    }

    /*
     * Scan through all of the lines of the text circularly, starting at the
     * given index. 'objv[i]' is the pattern which may be an exact string or a
     * regexp pattern depending on the flags set above.
3963
3964
3965
3966
3967
3968
3969
3970

3971
3972
3973
3974
3975
3976
3977
3983
3984
3985
3986
3987
3988
3989

3990
3991
3992
3993
3994
3995
3996
3997







-
+







/*
 *----------------------------------------------------------------------
 *
 * TextSearchGetLineIndex --
 *
 *	Extract a row, text offset index position from an objPtr
 *
 *	This means we ignore any embedded windows/images and elided text
 *	This means we ignore any embedded windows/images and elidden text
 *	(unless we are searching that).
 *
 * Results:
 *	Standard Tcl error code (with a message in the interpreter on error
 *	conditions).
 *
 *	The offset placed in offsetPosPtr is a utf-8 char* byte index for
3988
3989
3990
3991
3992
3993
3994
3995

3996
3997
3998
3999
4000

4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014

4015
4016
4017
4018
4019

4020
4021
4022
4023
4024
4025
4026
4027







-
+




-
+








static int
TextSearchGetLineIndex(
    Tcl_Interp *interp,		/* For error messages. */
    Tcl_Obj *objPtr,		/* Contains a textual index like "1.2" */
    SearchSpec *searchSpecPtr,	/* Contains other search parameters. */
    int *linePosPtr,		/* For returning the line number. */
    Tcl_Size *offsetPosPtr)		/* For returning the text offset in the
    int *offsetPosPtr)		/* For returning the text offset in the
				 * line. */
{
    const TkTextIndex *indexPtr;
    int line;
    TkText *textPtr = (TkText *)searchSpecPtr->clientData;
    TkText *textPtr = searchSpecPtr->clientData;

    indexPtr = TkTextGetIndexFromObj(interp, textPtr, objPtr);
    if (indexPtr == NULL) {
	return TCL_ERROR;
    }

    line = TkBTreeLinesTo(textPtr, indexPtr->linePtr);
4035
4036
4037
4038
4039
4040
4041
4042

4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055

4056
4057
4058
4059
4060

4061
4062
4063
4064
4065
4066


4067
4068
4069
4070
4071
4072
4073
4055
4056
4057
4058
4059
4060
4061

4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074

4075
4076
4077
4078
4079

4080
4081
4082
4083



4084
4085
4086
4087
4088
4089
4090
4091
4092







-
+












-
+




-
+



-
-
-
+
+







 *----------------------------------------------------------------------
 *
 * TextSearchIndexInLine --
 *
 *	Find textual index of 'byteIndex' in the searchable characters of
 *	'linePtr'.
 *
 *	This means we ignore any embedded windows/images and elided text
 *	This means we ignore any embedded windows/images and elidden text
 *	(unless we are searching that).
 *
 * Results:
 *	The returned index is a utf-8 char* byte index for exact searches, and
 *	a Unicode character index for regexp searches.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Size
static int
TextSearchIndexInLine(
    const SearchSpec *searchSpecPtr,
				/* Search parameters. */
    TkTextLine *linePtr,	/* The line we're looking at. */
    Tcl_Size byteIndex)		/* Index into the line. */
    int byteIndex)		/* Index into the line. */
{
    TkTextSegment *segPtr;
    TkTextIndex curIndex;
    Tcl_Size index;
    int leftToScan;
    TkText *textPtr = (TkText *)searchSpecPtr->clientData;
    int index, leftToScan;
    TkText *textPtr = searchSpecPtr->clientData;

    index = 0;
    curIndex.tree = textPtr->sharedTextPtr->tree;
    curIndex.linePtr = linePtr; curIndex.byteIndex = 0;
    for (segPtr = linePtr->segPtr, leftToScan = byteIndex;
	    leftToScan > 0;
	    curIndex.byteIndex += segPtr->size, segPtr = segPtr->nextPtr) {
4115
4116
4117
4118
4119
4120
4121
4122

4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136

4137
4138
4139
4140
4141
4142
4143
4134
4135
4136
4137
4138
4139
4140

4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154

4155
4156
4157
4158
4159
4160
4161
4162







-
+













-
+







 * Side effects:
 *	Memory may be allocated or re-allocated for theLine's string
 *	representation.
 *
 *----------------------------------------------------------------------
 */

static void *
static ClientData
TextSearchAddNextLine(
    int lineNum,		/* Line we must add. */
    SearchSpec *searchSpecPtr,	/* Search parameters. */
    Tcl_Obj *theLine,		/* Object to append to. */
    int *lenPtr,		/* For returning the total length. */
    int *extraLinesPtr)		/* If non-NULL, will have its value
				 * incremented by the number of additional
				 * logical lines which are merged into this
				 * one by newlines being elided. */
{
    TkTextLine *linePtr, *thisLinePtr;
    TkTextIndex curIndex;
    TkTextSegment *segPtr;
    TkText *textPtr = (TkText *)searchSpecPtr->clientData;
    TkText *textPtr = searchSpecPtr->clientData;
    int nothingYet = 1;

    /*
     * Extract the text from the line.
     */

    linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, textPtr, lineNum);
4201
4202
4203
4204
4205
4206
4207
4208

4209
4210
4211
4212
4213
4214
4215
4220
4221
4222
4223
4224
4225
4226

4227
4228
4229
4230
4231
4232
4233
4234







-
+








    if (searchSpecPtr->exact && searchSpecPtr->noCase) {
	Tcl_SetObjLength(theLine, Tcl_UtfToLower(Tcl_GetString(theLine)));
    }

    if (lenPtr != NULL) {
	if (searchSpecPtr->exact) {
	    Tcl_GetString(theLine);
	    (void)Tcl_GetString(theLine);
	    *lenPtr = theLine->length;
	} else {
	    *lenPtr = Tcl_GetCharLength(theLine);
	}
    }
    return linePtr;
}
4234
4235
4236
4237
4238
4239
4240
4241

4242
4243
4244
4245
4246
4247
4248

4249
4250

4251
4252
4253

4254
4255
4256
4257
4258

4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275

4276
4277
4278
4279
4280
4281
4282
4253
4254
4255
4256
4257
4258
4259

4260
4261
4262
4263
4264
4265
4266

4267
4268

4269
4270
4271

4272
4273
4274
4275
4276

4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293

4294
4295
4296
4297
4298
4299
4300
4301







-
+






-
+

-
+


-
+




-
+
















-
+







 *----------------------------------------------------------------------
 */

static int
TextSearchFoundMatch(
    int lineNum,		/* Line on which match was found. */
    SearchSpec *searchSpecPtr,	/* Search parameters. */
    void *clientData,	/* Token returned by the 'addNextLineProc',
    ClientData clientData,	/* Token returned by the 'addNextLineProc',
				 * TextSearchAddNextLine. May be NULL, in
				 * which we case we must generate it (from
				 * lineNum). */
    Tcl_Obj *theLine,		/* Text from current line, only accessed for
				 * exact searches, and is allowed to be NULL
				 * for regexp searches. */
    Tcl_Size matchOffset,		/* Offset of found item in utf-8 bytes for
    int matchOffset,		/* Offset of found item in utf-8 bytes for
				 * exact search, Unicode chars for regexp. */
    Tcl_Size matchLength)		/* Length also in bytes/chars as per search
    int matchLength)		/* Length also in bytes/chars as per search
				 * type. */
{
    Tcl_Size numChars;
    int numChars;
    int leftToScan;
    TkTextIndex curIndex, foundIndex;
    TkTextSegment *segPtr;
    TkTextLine *linePtr;
    TkText *textPtr = (TkText *)searchSpecPtr->clientData;
    TkText *textPtr = searchSpecPtr->clientData;

    if (lineNum == searchSpecPtr->stopLine) {
	/*
	 * If the current index is on the wrong side of the stopIndex, then
	 * the item we just found is actually outside the acceptable range,
	 * and the search is over.
	 */

	if (searchSpecPtr->backwards ^
		(matchOffset >= searchSpecPtr->stopOffset)) {
	    return 0;
	}
    }

    /*
     * Calculate the character count, which may need augmenting if there are
     * embedded windows or elided text.
     * embedded windows or elidden text.
     */

    if (searchSpecPtr->exact) {
	const char *startOfLine = Tcl_GetString(theLine);

	numChars = Tcl_NumUtfChars(startOfLine + matchOffset, matchLength);
    } else {
4302
4303
4304
4305
4306
4307
4308
4309

4310
4311
4312
4313
4314
4315
4316
4321
4322
4323
4324
4325
4326
4327

4328
4329
4330
4331
4332
4333
4334
4335







-
+







     * non-textual info. Scan through the line's segments again to adjust both
     * matchChar and matchCount.
     *
     * We will walk through the segments of this line until we have either
     * reached the end of the match or we have reached the end of the line.
     */

    linePtr = (TkTextLine *)clientData;
    linePtr = clientData;
    if (linePtr == NULL) {
	linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, textPtr,
		lineNum);
    }

    curIndex.tree = textPtr->sharedTextPtr->tree;

4337
4338
4339
4340
4341
4342
4343
4344

4345
4346
4347
4348
4349
4350
4351
4356
4357
4358
4359
4360
4361
4362

4363
4364
4365
4366
4367
4368
4369
4370







-
+







		if (searchSpecPtr->exact) {
		    matchOffset += segPtr->size;
		} else {
		    matchOffset += Tcl_NumUtfChars(segPtr->body.chars, -1);
		}
	    } else {
		if (searchSpecPtr->exact) {
		    leftToScan -= (int)segPtr->size;
		    leftToScan -= segPtr->size;
		} else {
		    leftToScan -= Tcl_NumUtfChars(segPtr->body.chars, -1);
		}
	    }
	    curIndex.byteIndex += segPtr->size;
	}
	if (segPtr == NULL && leftToScan >= 0) {
4439
4440
4441
4442
4443
4444
4445
4446

4447
4448
4449
4450
4451
4452
4453
4458
4459
4460
4461
4462
4463
4464

4465
4466
4467
4468
4469
4470
4471
4472







-
+







    }

    /*
     * Now store the count result, if it is wanted.
     */

    if (searchSpecPtr->varPtr != NULL) {
	Tcl_Obj *tmpPtr = Tcl_NewWideIntObj(numChars);
	Tcl_Obj *tmpPtr = Tcl_NewIntObj(numChars);
	if (searchSpecPtr->all) {
	    if (searchSpecPtr->countPtr == NULL) {
		searchSpecPtr->countPtr = Tcl_NewObj();
	    }
	    Tcl_ListObjAppendElement(NULL, searchSpecPtr->countPtr, tmpPtr);
	} else {
	    searchSpecPtr->countPtr = tmpPtr;
4474
4475
4476
4477
4478
4479
4480
4481

4482
4483
4484
4485

4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499

4500
4501
4502
4503

4504
4505
4506
4507
4508
4509
4510
4511







-
+



-
+







 *
 *----------------------------------------------------------------------
 */

TkTextTabArray *
TkTextGetTabs(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tk_Window tkwin,		/* Information about the window. */
    TkText *textPtr,		/* Information about the text widget. */
    Tcl_Obj *stringPtr)		/* Description of the tab stops. See the text
				 * manual entry for details. */
{
    Tcl_Size objc, i, count;
    int objc, i, count;
    Tcl_Obj **objv;
    TkTextTabArray *tabArrayPtr;
    TkTextTab *tabPtr;
    int ch;
    double prevStop, lastStop;
    /*
     * Map these strings to TkTextTabAlign values.
4512
4513
4514
4515
4516
4517
4518
4519
4520


4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532

4533
4534
4535
4536
4537
4538
4539
4540
4541

4542
4543
4544
4545
4546

4547
4548
4549
4550
4551
4552
4553
4554
4555
4556














4557
4558
4559
4560
4561

4562

4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581

4582
4583
4584
4585
4586
4587
4588
4531
4532
4533
4534
4535
4536
4537


4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550

4551
4552
4553
4554
4555
4556
4557
4558
4559

4560
4561
4562
4563
4564

4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593

4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614

4615
4616
4617
4618
4619
4620
4621
4622







-
-
+
+











-
+








-
+




-
+










+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

+


















-
+







	}
    }

    /*
     * Parse the elements of the list one at a time to fill in the array.
     */

    tabArrayPtr = (TkTextTabArray *)ckalloc(offsetof(TkTextTabArray, tabs)
	    + count * sizeof(TkTextTab));
    tabArrayPtr = ckalloc(sizeof(TkTextTabArray)
	    + (count - 1) * sizeof(TkTextTab));
    tabArrayPtr->numTabs = 0;
    prevStop = 0.0;
    lastStop = 0.0;
    for (i = 0, tabPtr = &tabArrayPtr->tabs[0]; i < objc; i++, tabPtr++) {
	int index;

	/*
	 * This will round fractional pixels above 0.5 upwards, and otherwise
	 * downwards, to find the right integer pixel position.
	 */

	if (Tk_GetPixelsFromObj(interp, tkwin, objv[i],
	if (Tk_GetPixelsFromObj(interp, textPtr->tkwin, objv[i],
		&tabPtr->location) != TCL_OK) {
	    goto error;
	}

	if (tabPtr->location <= 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "tab stop \"%s\" is not at a positive distance",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "TAB_STOP", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "TAB_STOP", NULL);
	    goto error;
	}

	prevStop = lastStop;
	if (Tk_GetDoublePixelsFromObj(interp, tkwin, objv[i],
	if (Tk_GetDoublePixelsFromObj(interp, textPtr->tkwin, objv[i],
		&lastStop) != TCL_OK) {
	    goto error;
	}

	if (i > 0 && (tabPtr->location <= (tabPtr-1)->location)) {
	    /*
	     * This tab is actually to the left of the previous one, which is
	     * illegal.
	     */

#ifdef _TK_ALLOW_DECREASING_TABS
	    /*
	     * Force the tab to be a typical character width to the right of
	     * the previous one, and update the 'lastStop' with the changed
	     * position.
	     */

	    if (textPtr->charWidth > 0) {
		tabPtr->location = (tabPtr-1)->location + textPtr->charWidth;
	    } else {
		tabPtr->location = (tabPtr-1)->location + 8;
	    }
	    lastStop = tabPtr->location;
#else
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "tabs must be monotonically increasing, but \"%s\" is "
		    "smaller than or equal to the previous tab",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "TAB_STOP", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "TAB_STOP", NULL);
	    goto error;
#endif /* _TK_ALLOW_DECREASING_TABS */
	}

	tabArrayPtr->numTabs++;

	/*
	 * See if there is an explicit alignment in the next list element.
	 * Otherwise just use "left".
	 */

	tabPtr->alignment = LEFT;
	if ((i+1) == objc) {
	    continue;
	}

	/*
	 * There may be a more efficient way of getting this.
	 */

	Tcl_UtfToUniChar(Tcl_GetString(objv[i+1]), &ch);
	TkUtfToUniChar(Tcl_GetString(objv[i+1]), &ch);
	if (!Tcl_UniCharIsAlpha(ch)) {
	    continue;
	}
	i += 1;

	if (Tcl_GetIndexFromObjStruct(interp, objv[i], tabOptionStrings,
		sizeof(char *), "tab alignment", 0, &index) != TCL_OK) {
4624
4625
4626
4627
4628
4629
4630
4631

4632
4633

4634
4635
4636
4637
4638
4639

4640
4641
4642
4643
4644
4645
4646
4658
4659
4660
4661
4662
4663
4664

4665
4666

4667
4668
4669
4670
4671
4672

4673
4674
4675
4676
4677
4678
4679
4680







-
+

-
+





-
+







 *	side effects).
 *
 *----------------------------------------------------------------------
 */

static int
TextDumpCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "dump". */
{
    TkTextIndex index1, index2;
    Tcl_Size arg;
    int arg;
    int lineno;			/* Current line number. */
    int what = 0;		/* bitfield to select segment types. */
    int atEnd;			/* True if dumping up to logical end. */
    TkTextLine *linePtr;
    Tcl_Obj *command = NULL;	/* Script callback to apply to segments. */
#define TK_DUMP_TEXT	0x1
#define TK_DUMP_MARK	0x2
4697
4698
4699
4700
4701
4702
4703
4704

4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718

4719
4720
4721
4722
4723
4724
4725



4726
4727
4728
4729
4730
4731
4732
4731
4732
4733
4734
4735
4736
4737

4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751

4752
4753
4754
4755
4756
4757


4758
4759
4760
4761
4762
4763
4764
4765
4766
4767







-
+













-
+





-
-
+
+
+







	}
    }
    if (arg >= objc || arg+2 < objc) {
    wrongArgs:
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Usage: %s dump ?-all -image -text -mark -tag -window? "
		"?-command script? index ?index2?", Tcl_GetString(objv[0])));
	Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", (char *)NULL);
	Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
	return TCL_ERROR;
    }
    if (what == 0) {
	what = TK_DUMP_ALL;
    }
    if (TkTextGetObjIndex(interp, textPtr, objv[arg], &index1) != TCL_OK) {
	return TCL_ERROR;
    }
    arg++;
    atEnd = 0;
    if (objc == arg) {
	TkTextIndexForwChars(NULL, &index1, 1, &index2, COUNT_INDICES);
    } else {
	Tcl_Size length;
	int length;
	const char *str;

	if (TkTextGetObjIndex(interp, textPtr, objv[arg], &index2) != TCL_OK) {
	    return TCL_ERROR;
	}
	str = Tcl_GetStringFromObj(objv[arg], &length);
	if (strncmp(str, "end", length) == 0) {
	str = Tcl_GetString(objv[arg]);
	length = objv[arg]->length;
	if (strncmp(str, "end", (unsigned) length) == 0) {
	    atEnd = 1;
	}
    }
    if (TkTextIndexCmp(&index1, &index2) >= 0) {
	return TCL_OK;
    }
    lineno = TkBTreeLinesTo(textPtr, index1.linePtr);
4861
4862
4863
4864
4865
4866
4867
4868

4869
4870
4871
4872
4873
4874
4875
4896
4897
4898
4899
4900
4901
4902

4903
4904
4905
4906
4907
4908
4909
4910







-
+







		 * To avoid modifying the string in place we copy over just
		 * the segment that we want. Since DumpSegment can modify the
		 * text, we could not confidently revert the modification
		 * here.
		 */

		int length = last - first;
		char *range = (char *)ckalloc(length + 1);
		char *range = ckalloc(length + 1);

		memcpy(range, segPtr->body.chars + first, length);
		range[length] = '\0';

		TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr,
			lineno, offset + first, &index);
		lineChanged = DumpSegment(textPtr, interp, "text", range,
4892
4893
4894
4895
4896
4897
4898
4899

4900
4901
4902
4903
4904
4905
4906
4927
4928
4929
4930
4931
4932
4933

4934
4935
4936
4937
4938
4939
4940
4941







-
+







		    name = "insert";
		} else if (segPtr == textPtr->currentMarkPtr) {
		    name = "current";
		} else if (markPtr->hPtr == NULL) {
		    name = NULL;
		    lineChanged = 0;
		} else {
		    name = (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable,
		    name = Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable,
			    markPtr->hPtr);
		}
		if (name != NULL) {
		    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr,
			    lineno, offset, &index);
		    lineChanged = DumpSegment(textPtr, interp, "mark", name,
			    command, &index, what);
4929
4930
4931
4932
4933
4934
4935
4936

4937
4938
4939
4940
4941
4942
4943
4964
4965
4966
4967
4968
4969
4970

4971
4972
4973
4974
4975
4976
4977
4978







-
+







		lineChanged = DumpSegment(textPtr, interp, "image", name,
			command, &index, what);
	    } else if ((what & TK_DUMP_WIN) &&
		    (segPtr->typePtr == &tkTextEmbWindowType)) {
		TkTextEmbWindow *ewPtr = &segPtr->body.ew;
		const char *pathname;

		if (ewPtr->tkwin == NULL) {
		if (ewPtr->tkwin == (Tk_Window) NULL) {
		    pathname = "";
		} else {
		    pathname = Tk_PathName(ewPtr->tkwin);
		}
		TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr,
			lineno, offset, &index);
		lineChanged = DumpSegment(textPtr, interp, "window", pathname,
5018
5019
5020
5021
5022
5023
5024
5025

5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040

5041
5042
5043
5044
5045
5046
5047
5048




5049
5050
5051
5052
5053
5054
5055
5053
5054
5055
5056
5057
5058
5059

5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074

5075
5076
5077
5078
5079




5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090







-
+














-
+




-
-
-
-
+
+
+
+







DumpSegment(
    TkText *textPtr,
    Tcl_Interp *interp,
    const char *key,		/* Segment type key. */
    const char *value,		/* Segment value. */
    Tcl_Obj *command,		/* Script callback. */
    const TkTextIndex *index,	/* index with line/byte position info. */
    TCL_UNUSED(int))		/* Look for TK_DUMP_INDEX bit. */
    int what)			/* Look for TK_DUMP_INDEX bit. */
{
    char buffer[TK_POS_CHARS];
    Tcl_Obj *values[3], *tuple;

    TkTextPrintIndex(textPtr, index, buffer);
    values[0] = Tcl_NewStringObj(key, -1);
    values[1] = Tcl_NewStringObj(value, -1);
    values[2] = Tcl_NewStringObj(buffer, -1);
    tuple = Tcl_NewListObj(3, values);
    if (command == NULL) {
	Tcl_ListObjAppendList(NULL, Tcl_GetObjResult(interp), tuple);
	Tcl_DecrRefCount(tuple);
	return 0;
    } else {
	Tcl_Size oldStateEpoch = TkBTreeEpoch(textPtr->sharedTextPtr->tree);
	int oldStateEpoch = TkBTreeEpoch(textPtr->sharedTextPtr->tree);
	Tcl_DString buf;
	int code;

	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, Tcl_GetString(command), TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, Tcl_GetString(tuple), TCL_INDEX_NONE);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, Tcl_GetString(command), -1);
	Tcl_DStringAppend(&buf, " ", -1);
	Tcl_DStringAppend(&buf, Tcl_GetString(tuple), -1);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	if (code != TCL_OK) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (segment dumping command executed by text)");
	    Tcl_BackgroundException(interp, code);
	}
	Tcl_DecrRefCount(tuple);
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5118
5119
5120
5121
5122
5123
5124




5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142




5143
5144
5145
5146
5147
5148
5149







-
-
-
-


















-
-
-
-







    Tcl_Obj *cmdObj;
    int code;

    if (!textPtr->sharedTextPtr->undo) {
	return TCL_OK;
    }

    if (textPtr->sharedTextPtr->autoSeparators) {
	TkUndoInsertUndoSeparator(textPtr->sharedTextPtr->undoStack);
    }

    /*
     * Turn off the undo feature while we revert a compound action, setting
     * the dirty handling mode to undo for the duration (unless it is
     * 'fixed').
     */

    textPtr->sharedTextPtr->undo = 0;
    if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) {
	textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_UNDO;
    }

    status = TkUndoRevert(textPtr->sharedTextPtr->undoStack);

    if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) {
	textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL;
    }
    textPtr->sharedTextPtr->undo = 1;

    if (textPtr->sharedTextPtr->autoSeparators) {
	TkUndoInsertUndoSeparator(textPtr->sharedTextPtr->undoStack);
    }

    /*
     * Convert undo/redo temporary marks set by TkUndoRevert() into
     * indices left in the interp result.
     */

    cmdObj = Tcl_ObjPrintf("::tk::TextUndoRedoProcessMarks %s",
            Tk_PathName(textPtr->tkwin));
5215
5216
5217
5218
5219
5220
5221
5222

5223
5224
5225
5226
5227
5228
5229
5242
5243
5244
5245
5246
5247
5248

5249
5250
5251
5252
5253
5254
5255
5256







-
+







 *----------------------------------------------------------------------
 */

static int
TextEditCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int index, setModified, oldModified;
    int canRedo = 0;
    int canUndo = 0;

    static const char *const editOptionStrings[] = {
5306
5307
5308
5309
5310
5311
5312
5313

5314
5315
5316
5317
5318
5319
5320
5333
5334
5335
5336
5337
5338
5339

5340
5341
5342
5343
5344
5345
5346
5347







-
+







	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack);
	if (TextEditRedo(textPtr)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("nothing to redo", -1));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_REDO", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_REDO", NULL);
	    return TCL_ERROR;
	}
	canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack);
	if (!canUndo || !canRedo) {
	    GenerateUndoStackEvent(textPtr);
	}
	break;
5341
5342
5343
5344
5345
5346
5347
5348

5349
5350
5351
5352
5353
5354
5355
5368
5369
5370
5371
5372
5373
5374

5375
5376
5377
5378
5379
5380
5381
5382







-
+







	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack);
	if (TextEditUndo(textPtr)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("nothing to undo", -1));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_UNDO", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_UNDO", NULL);
	    return TCL_ERROR;
	}
	canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack);
	if (!canRedo || !canUndo) {
	    GenerateUndoStackEvent(textPtr);
	}
	break;
5367
5368
5369
5370
5371
5372
5373





5374
5375
5376
5377
5378
5379
5380
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412







+
+
+
+
+







 *
 *	Since the amount of text may potentially be several megabytes (e.g.
 *	in text editors built on the text widget), efficiency is very
 *	important. We may want to investigate the efficiency of the
 *	Tcl_AppendToObj more carefully (e.g. if we know we are going to be
 *	appending several thousand lines, we could attempt to pre-allocate a
 *	larger space).
 *
 *	Also the result is built up as a utf-8 string, but, if we knew we
 *	wanted it as Unicode, we could potentially save a huge conversion by
 *	building it up as Unicode directly. This could be as simple as
 *	replacing Tcl_NewObj by Tcl_NewUnicodeObj.
 *
 * Results:
 *	Tcl_Obj of string type containing the specified text. If the
 *	visibleOnly flag is set to 1, then only those characters which are not
 *	elided will be returned. Otherwise (flag is 0) all characters in the
 *	given range are returned.
 *
5400
5401
5402
5403
5404
5405
5406
5407

5408
5409
5410
5411
5412
5413
5414
5432
5433
5434
5435
5436
5437
5438

5439
5440
5441
5442
5443
5444
5445
5446







-
+








    TkTextMakeByteIndex(indexPtr1->tree, textPtr,
	    TkBTreeLinesTo(textPtr, indexPtr1->linePtr),
	    indexPtr1->byteIndex, &tmpIndex);

    if (TkTextIndexCmp(indexPtr1, indexPtr2) < 0) {
	while (1) {
	    Tcl_Size offset;
	    int offset;
	    TkTextSegment *segPtr = TkTextIndexToSeg(&tmpIndex, &offset);
	    int last = segPtr->size, last2;

	    if (tmpIndex.linePtr == indexPtr2->linePtr) {
		/*
		 * The last line that was requested must be handled carefully,
		 * because we may need to break out of this loop in the middle
5455
5456
5457
5458
5459
5460
5461
5462

5463
5464
5465
5466
5467
5468
5469
5487
5488
5489
5490
5491
5492
5493

5494
5495
5496
5497
5498
5499
5500
5501







-
+







static void
GenerateModifiedEvent(
    TkText *textPtr)	/* Information about text widget. */
{
    for (textPtr = textPtr->sharedTextPtr->peers; textPtr != NULL;
	    textPtr = textPtr->next) {
	Tk_MakeWindowExist(textPtr->tkwin);
	Tk_SendVirtualEvent(textPtr->tkwin, "Modified", NULL);
	TkSendVirtualEvent(textPtr->tkwin, "Modified", NULL);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateUndoStackEvent --
5485
5486
5487
5488
5489
5490
5491
5492

5493
5494
5495
5496
5497
5498
5499
5517
5518
5519
5520
5521
5522
5523

5524
5525
5526
5527
5528
5529
5530
5531







-
+







static void
GenerateUndoStackEvent(
    TkText *textPtr)	/* Information about text widget. */
{
    for (textPtr = textPtr->sharedTextPtr->peers; textPtr != NULL;
	    textPtr = textPtr->next) {
	Tk_MakeWindowExist(textPtr->tkwin);
	Tk_SendVirtualEvent(textPtr->tkwin, "UndoStack", NULL);
	TkSendVirtualEvent(textPtr->tkwin, "UndoStack", NULL);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateDirtyFlag --
5547
5548
5549
5550
5551
5552
5553
5554

5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570



5571
5572

5573
5574
5575
5576
5577
5578
5579
5580
5581

5582
5583
5584
5585
5586

5587
5588
5589
5590

5591
5592

5593
5594
5595
5596
5597
5598
5599
5579
5580
5581
5582
5583
5584
5585

5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599



5600
5601
5602
5603

5604
5605
5606
5607
5608
5609
5610
5611
5612

5613
5614
5615
5616
5617

5618
5619
5620
5621

5622
5623

5624
5625
5626
5627
5628
5629
5630
5631







-
+













-
-
-
+
+
+

-
+








-
+




-
+



-
+

-
+







	GenerateModifiedEvent(sharedTextPtr->peers);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkTextRunAfterSyncCmd --
 * RunAfterSyncCmd --
 *
 *	This function is called by the event loop and executes the command
 *      scheduled by [.text sync -command $cmd].
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Anything may happen, depending on $cmd contents.
 *
 *----------------------------------------------------------------------
 */

void
TkTextRunAfterSyncCmd(
    void *clientData)		/* Information about text widget. */
static void
RunAfterSyncCmd(
    ClientData clientData)		/* Information about text widget. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = (TkText *) clientData;
    int code;

    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
	/*
	* The widget has been deleted. Don't do anything.
	*/

	if (textPtr->refCount-- <= 1) {
	    ckfree(textPtr);
	    ckfree((char *) textPtr);
	}
	return;
    }

    Tcl_Preserve(textPtr->interp);
    Tcl_Preserve((ClientData) textPtr->interp);
    code = Tcl_EvalObjEx(textPtr->interp, textPtr->afterSyncCmd, TCL_EVAL_GLOBAL);
    if (code == TCL_ERROR) {
	Tcl_AddErrorInfo(textPtr->interp, "\n    (text sync)");
	Tcl_BackgroundException(textPtr->interp, TCL_ERROR);
	Tcl_BackgroundError(textPtr->interp);
    }
    Tcl_Release(textPtr->interp);
    Tcl_Release((ClientData) textPtr->interp);
    Tcl_DecrRefCount(textPtr->afterSyncCmd);
    textPtr->afterSyncCmd = NULL;
}

/*
 *----------------------------------------------------------------------
 *
5639
5640
5641
5642
5643
5644
5645
5646

5647
5648
5649
5650
5651
5652
5653
5671
5672
5673
5674
5675
5676
5677

5678
5679
5680
5681
5682
5683
5684
5685







-
+








    /*
     * Find the optional end location, similarly.
     */

    if (toPtr != NULL) {
	const TkTextIndex *indexToPtr, *indexFromPtr;
	TkText *textPtr = (TkText *)searchSpecPtr->clientData;
	TkText *textPtr = searchSpecPtr->clientData;

	indexToPtr = TkTextGetIndexFromObj(interp, textPtr, toPtr);
	if (indexToPtr == NULL) {
	    return TCL_ERROR;
	}
	indexFromPtr = TkTextGetIndexFromObj(interp, textPtr, fromPtr);

5720
5721
5722
5723
5724
5725
5726
5727

5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751



5752
5753
5754
5755
5756
5757
5758
5752
5753
5754
5755
5756
5757
5758

5759

5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779



5780
5781
5782
5783
5784
5785
5786
5787
5788
5789







-
+
-




















-
-
-
+
+
+







				 * pattern. Must have a refCount > 0. */
{
    /*
     * For exact searches these are utf-8 char* offsets, for regexp searches
     * they are Unicode char offsets.
     */

    int firstOffset, lastOffset;
    int firstOffset, lastOffset, matchOffset, matchLength;
    Tcl_Size matchOffset,  matchLength;
    int passes;
    int lineNum = searchSpecPtr->startLine;
    int code = TCL_OK;
    Tcl_Obj *theLine;
    int alreadySearchOffset = -1;

    const char *pattern = NULL;	/* For exact searches only. */
    int firstNewLine = -1; 	/* For exact searches only. */
    Tcl_RegExp regexp = NULL;	/* For regexp searches only. */

    /*
     * These items are for backward regexp searches only. They are for two
     * purposes: to allow us to report backwards matches in the correct order,
     * even though the implementation uses repeated forward searches; and to
     * provide for overlap checking between backwards matches on different
     * text lines.
     */

#define LOTS_OF_MATCHES 20
    int matchNum = LOTS_OF_MATCHES;
    Tcl_Size smArray[2 * LOTS_OF_MATCHES];
    Tcl_Size *storeMatch = smArray;
    Tcl_Size *storeLength = smArray + LOTS_OF_MATCHES;
    int smArray[2 * LOTS_OF_MATCHES];
    int *storeMatch = smArray;
    int *storeLength = smArray + LOTS_OF_MATCHES;
    int lastBackwardsLineMatch = -1;
    int lastBackwardsMatchOffset = -1;

    if (searchSpecPtr->exact) {
	/*
	 * Convert the pattern to lower-case if we're supposed to ignore case.
	 */
5794
5795
5796
5797
5798
5799
5800
5801


5802
5803
5804
5805
5806
5807
5808
5825
5826
5827
5828
5829
5830
5831

5832
5833
5834
5835
5836
5837
5838
5839
5840







-
+
+








	/*
	 * We only need to set the matchLength once for exact searches, and we
	 * do it here. It is also used below as the actual pattern length, so
	 * it has dual purpose.
	 */

	pattern = Tcl_GetStringFromObj(patObj, &matchLength);
	pattern = Tcl_GetString(patObj);
	matchLength = patObj->length;
	nl = strchr(pattern, '\n');

	/*
	 * If there is no newline, or it is the very end of the string, then
	 * we don't need any special treatment, since single-line matching
	 * will work fine.
	 */
5826
5827
5828
5829
5830
5831
5832
5833

5834
5835
5836
5837
5838
5839
5840
5858
5859
5860
5861
5862
5863
5864

5865
5866
5867
5868
5869
5870
5871
5872







-
+







     * For building up the current line being checked.
     */

    theLine = Tcl_NewObj();
    Tcl_IncrRefCount(theLine);

    for (passes = 0; passes < 2; ) {
	void *lineInfo;
	ClientData lineInfo;
	int linesSearched = 1;
	int extraLinesSearched = 0;

	if (lineNum >= searchSpecPtr->numLines) {
	    /*
	     * Don't search the dummy last line of the text.
	     */
5864
5865
5866
5867
5868
5869
5870
5871

5872
5873
5874
5875
5876
5877
5878
5896
5897
5898
5899
5900
5901
5902

5903
5904
5905
5906
5907
5908
5909
5910







-
+








	if (lineNum == searchSpecPtr->stopLine && searchSpecPtr->backwards) {
	    firstOffset = searchSpecPtr->stopOffset;
	} else {
	    firstOffset = 0;
	}

	if (alreadySearchOffset >= 0) {
	if (alreadySearchOffset != -1) {
	    if (searchSpecPtr->backwards) {
		if (alreadySearchOffset < lastOffset) {
		    lastOffset = alreadySearchOffset;
		}
	    } else {
		if (alreadySearchOffset > firstOffset) {
		    firstOffset = alreadySearchOffset;
5919
5920
5921
5922
5923
5924
5925
5926

5927
5928
5929
5930
5931
5932
5933
5934
5935
5936

5937
5938
5939
5940
5941
5942
5943
5951
5952
5953
5954
5955
5956
5957

5958
5959
5960
5961
5962
5963
5964
5965
5966
5967

5968
5969
5970
5971
5972
5973
5974
5975







-
+









-
+







	 * Check for matches within the current line 'lineNum'. If so, and if
	 * we're searching backwards or for all matches, repeat the search
	 * until we find the last match in the line. The 'lastOffset' is one
	 * beyond the last position in the line at which a match is allowed to
	 * begin.
	 */

	matchOffset = TCL_INDEX_NONE;
	matchOffset = -1;

	if (searchSpecPtr->exact) {
	    int maxExtraLines = 0;
	    const char *startOfLine = Tcl_GetString(theLine);

	    CLANG_ASSERT(pattern);
	    do {
		int ch;
		const char *p;
		Tcl_Size lastFullLine = lastOffset;
		int lastFullLine = lastOffset;

		if (firstNewLine == -1) {
		    if (searchSpecPtr->strictLimits
			    && (firstOffset + matchLength > lastOffset)) {
			/*
			 * Not enough characters to match.
			 */
5953
5954
5955
5956
5957
5958
5959
5960

5961
5962

5963
5964
5965
5966
5967
5968
5969
5970


5971
5972
5973
5974
5975
5976
5977
5985
5986
5987
5988
5989
5990
5991

5992
5993

5994
5995
5996
5997
5998
5999
6000


6001
6002
6003
6004
6005
6006
6007
6008
6009







-
+

-
+






-
-
+
+







		    if (searchSpecPtr->backwards) {
			/*
			 * Search back either from the previous match or from
			 * 'startOfLine + lastOffset - 1' until we find a
			 * match.
			 */

			const char c = matchLength ? pattern[0] : '\0';
			const char c = pattern[0];

			if (alreadySearchOffset >= 0) {
			if (alreadySearchOffset != -1) {
			    p = startOfLine + alreadySearchOffset;
			    alreadySearchOffset = -1;
			} else {
			    p = startOfLine + lastOffset -1;
			}
			while (p >= startOfLine + firstOffset) {
			    if (matchLength == 0 || (p[0] == c && !strncmp(
				     p, pattern, matchLength))) {
			    if (p[0] == c && !strncmp(p, pattern,
				    (unsigned) matchLength)) {
				goto backwardsMatch;
			    }
			    p--;
			}
			break;
		    } else {
			p = strstr(startOfLine + firstOffset, pattern);
5992
5993
5994
5995
5996
5997
5998
5999

6000
6001
6002
6003
6004
6005
6006
6024
6025
6026
6027
6028
6029
6030

6031
6032
6033
6034
6035
6036
6037
6038







-
+







		} else {
		    /*
		     * Multi-line match has only one possible match position,
		     * because we know where the '\n' is.
		     */

		    p = startOfLine + lastOffset - firstNewLine - 1;
		    if (strncmp(p, pattern, firstNewLine + 1)) {
		    if (strncmp(p, pattern, (unsigned) firstNewLine + 1)) {
			/*
			 * No match.
			 */

			break;
		    } else {
			int extraLines = 1;
6051
6052
6053
6054
6055
6056
6057
6058

6059
6060
6061
6062
6063
6064
6065

6066
6067
6068
6069
6070
6071
6072
6083
6084
6085
6086
6087
6088
6089

6090
6091
6092
6093
6094
6095
6096

6097
6098
6099
6100
6101
6102
6103
6104







-
+






-
+







			    p = startOfLine + skipFirst;

			    /*
			     * Use the fact that 'matchLength = patLength' for
			     * exact searches.
			     */

			    if ((Tcl_Size)lastTotal - skipFirst >= matchLength) {
			    if ((lastTotal - skipFirst) >= matchLength) {
				/*
				 * We now have enough text to match, so we
				 * make a final test and break whatever the
				 * result.
				 */

				if (strncmp(p, pattern, matchLength)) {
				if (strncmp(p,pattern,(unsigned)matchLength)) {
				    p = NULL;
				}
				break;
			    } else {
				/*
				 * Not enough text yet, but check the prefix.
				 */
6126
6127
6128
6129
6130
6131
6132
6133

6134
6135
6136

6137
6138
6139

6140
6141
6142
6143
6144
6145
6146
6147
6158
6159
6160
6161
6162
6163
6164

6165



6166

6167

6168

6169
6170
6171
6172
6173
6174
6175







-
+
-
-
-
+
-

-
+
-








		if (!searchSpecPtr->overlap) {
		    if (searchSpecPtr->backwards) {
			alreadySearchOffset = p - startOfLine;
			if (firstNewLine != -1) {
			    break;
			} else {
			    alreadySearchOffset -= (matchLength ? matchLength : 1);
			    alreadySearchOffset -= matchLength;
                            if (alreadySearchOffset < 0) {
                                break;
                            }
			}
			}
		    } else {
                        firstOffset = matchLength ? p - startOfLine + matchLength
			firstOffset = p - startOfLine + matchLength;
                                                  : p - startOfLine + (Tcl_Size)1;
			if (firstOffset >= lastOffset) {
			    /*
			     * Now, we have to be careful not to find
			     * overlapping matches either on the same or
			     * following lines. Assume that if we did find
			     * something, it goes until the last extra line we
			     * added.
6161
6162
6163
6164
6165
6166
6167
6168

6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180

6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198

6199
6200

6201
6202
6203
6204
6205
6206
6207
6189
6190
6191
6192
6193
6194
6195

6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207

6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225

6226
6227

6228
6229
6230
6231
6232
6233
6234
6235







-
+











-
+

















-
+

-
+







		    if (searchSpecPtr->backwards) {
			alreadySearchOffset = p - startOfLine - 1;
			if (alreadySearchOffset < 0) {
			    break;
			}
		    } else {
			firstOffset = p - startOfLine +
				Tcl_UtfToUniChar(startOfLine+matchOffset,&ch);
				TkUtfToUniChar(startOfLine+matchOffset,&ch);
		    }
		}
	    } while (searchSpecPtr->all);
	} else {
	    int maxExtraLines = 0;
	    int matches = 0;
	    int lastNonOverlap = -1;

	    do {
		Tcl_RegExpInfo info;
		int match;
		Tcl_Size lastFullLine = lastOffset;
		int lastFullLine = lastOffset;

		match = Tcl_RegExpExecObj(interp, regexp, theLine,
			firstOffset, 1, (firstOffset>0 ? TCL_REG_NOTBOL : 0));
		if (match < 0) {
		    code = TCL_ERROR;
		    goto searchDone;
		}
		Tcl_RegExpGetInfo(regexp, &info);

		/*
		 * If we don't have a match, or if we do, but it extends to
		 * the end of the line, we must try to add more lines to get a
		 * full greedy match.
		 */

		if (!match ||
			((info.extendStart == info.matches[0].start)
			&& (info.matches[0].end == (Tcl_Size) (lastOffset - firstOffset)))) {
			&& (info.matches[0].end == lastOffset-firstOffset))) {
		    int extraLines = 0;
		    Tcl_Size prevFullLine;
		    int prevFullLine;

		    /*
		     * If we find a match that overlaps more than one line, we
		     * will use this value to determine the first allowed
		     * starting offset for the following search (to avoid
		     * overlapping results).
		     */
6306
6307
6308
6309
6310
6311
6312
6313
6314


6315
6316
6317
6318
6319
6320
6321
6334
6335
6336
6337
6338
6339
6340


6341
6342
6343
6344
6345
6346
6347
6348
6349







-
-
+
+







			 * This means we often add and search one more line
			 * than might be necessary if Tcl were able to give us
			 * a correct value of info.extendStart under all
			 * circumstances.
			 */

			if ((match &&
				firstOffset + info.matches[0].end != (Tcl_Size) lastTotal &&
				firstOffset + info.matches[0].end < prevFullLine)
				firstOffset+info.matches[0].end != lastTotal &&
				firstOffset+info.matches[0].end < prevFullLine)
				|| info.extendStart < 0) {
			    break;
			}

			/*
			 * If there is a match, but that match starts after
			 * the end of the first line, then we'll handle that
6376
6377
6378
6379
6380
6381
6382
6383
6384


6385
6386
6387
6388
6389
6390
6391
6404
6405
6406
6407
6408
6409
6410


6411
6412
6413
6414
6415
6416
6417
6418
6419







-
-
+
+







				    - info.matches[0].start;

			    if (lastNonOverlap != -1) {
				/*
				 * Possible overlap or enclosure.
				 */

				if ((Tcl_Size)thisOffset - lastNonOverlap >=
					lastBackwardsMatchOffset + matchLength + 1){
				if (thisOffset-lastNonOverlap >=
					lastBackwardsMatchOffset+matchLength){
				    /*
				     * Totally encloses previous match, so
				     * forget the previous match.
				     */

				    lastBackwardsLineMatch = -1;
				} else if ((thisOffset - lastNonOverlap)
6463
6464
6465
6466
6467
6468
6469
6470

6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490



6491
6492

6493
6494
6495
6496
6497
6498
6499
6491
6492
6493
6494
6495
6496
6497

6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515



6516
6517
6518
6519

6520
6521
6522
6523
6524
6525
6526
6527







-
+

















-
-
-
+
+
+

-
+







		 */

		if (matchOffset == -1 ||
			((searchSpecPtr->all || searchSpecPtr->backwards)
			&& ((firstOffset < matchOffset)
			|| ((firstOffset + info.matches[0].end
				- info.matches[0].start)
				> matchOffset + matchLength)))) {
				> (matchOffset + matchLength))))) {

		    matchOffset = firstOffset;
		    matchLength = info.matches[0].end - info.matches[0].start;

		    if (searchSpecPtr->backwards) {
			/*
			 * To get backwards searches in the correct order, we
			 * must store them away here.
			 */

			if (matches == matchNum) {
			    /*
			     * We've run out of space in our normal store, so
			     * we must allocate space for these backwards
			     * matches on the heap.
			     */

			    Tcl_Size *newArray = (Tcl_Size *)
				    ckalloc(4 * matchNum * sizeof(Tcl_Size));
			    memcpy(newArray, storeMatch, matchNum*sizeof(Tcl_Size));
			    int *newArray =
				    ckalloc(4 * matchNum * sizeof(int));
			    memcpy(newArray, storeMatch, matchNum*sizeof(int));
			    memcpy(newArray + 2*matchNum, storeLength,
				    matchNum * sizeof(Tcl_Size));
				    matchNum * sizeof(int));
			    if (storeMatch != smArray) {
				ckfree(storeMatch);
			    }
			    matchNum *= 2;
			    storeMatch = newArray;
			    storeLength = newArray + matchNum;
			}
6626
6627
6628
6629
6630
6631
6632
6633

6634
6635
6636
6637
6638
6639
6640
6654
6655
6656
6657
6658
6659
6660

6661
6662
6663
6664
6665
6666
6667
6668







-
+







	 * If the 'all' flag is set, we will already have stored all matches,
	 * so we just proceed to the next line.
	 *
	 * If not, and there is a match we need to store that information and
	 * we are done.
	 */

	if ((lastBackwardsLineMatch == -1) && (matchOffset != TCL_INDEX_NONE)
	if ((lastBackwardsLineMatch == -1) && (matchOffset >= 0)
		&& !searchSpecPtr->all) {
	    searchSpecPtr->foundMatchProc(lineNum, searchSpecPtr, lineInfo,
		    theLine, matchOffset, matchLength);
	    goto searchDone;
	}

	/*
6742
6743
6744
6745
6746
6747
6748
6749
6750


6751
6752

6753
6754
6755
6756
6757
6758
6759
6760

6761
6762
6763
6764
6765
6766
6767
6770
6771
6772
6773
6774
6775
6776


6777
6778
6779

6780
6781
6782
6783
6784
6785
6786
6787

6788
6789
6790
6791
6792
6793
6794
6795







-
-
+
+

-
+







-
+







 *	Creates a new Tcl_Obj.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetLineStartEnd(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *recordPtr,		/* Pointer to widget record. */
    Tcl_Size internalOffset)		/* Offset within *recordPtr containing the
    int internalOffset)		/* Offset within *recordPtr containing the
				 * line value. */
{
    TkTextLine *linePtr = *(TkTextLine **)(recordPtr + internalOffset);

    if (linePtr == NULL) {
	return Tcl_NewObj();
    }
    return Tcl_NewWideIntObj(1 + TkBTreeLinesTo(NULL, linePtr));
    return Tcl_NewIntObj(1 + TkBTreeLinesTo(NULL, linePtr));
}

/*
 *----------------------------------------------------------------------
 *
 * SetLineStartEnd --
 *
6777
6778
6779
6780
6781
6782
6783
6784

6785
6786

6787
6788
6789
6790
6791

6792
6793
6794
6795
6796
6797
6798
6799
6800
6801


6802
6803
6804
6805
6806
6807
6808
6805
6806
6807
6808
6809
6810
6811

6812
6813

6814
6815
6816
6817
6818

6819
6820
6821
6822
6823
6824
6825
6826
6827


6828
6829
6830
6831
6832
6833
6834
6835
6836







-
+

-
+




-
+








-
-
+
+







 *	that the specified string was empty and that is acceptable.
 *
 *----------------------------------------------------------------------
 */

static int
SetLineStartEnd(
    TCL_UNUSED(void *),
    ClientData clientData,
    Tcl_Interp *interp,		/* Current interp; may be used for errors. */
    TCL_UNUSED(Tk_Window),	/* Window for which option is being set. */
    Tk_Window tkwin,		/* Window for which option is being set. */
    Tcl_Obj **value,		/* Pointer to the pointer to the value object.
				 * We use a pointer to the pointer because we
				 * may need to return a value (NULL). */
    char *recordPtr,		/* Pointer to storage for the widget record. */
    Tcl_Size internalOffset,		/* Offset within *recordPtr at which the
    int internalOffset,		/* Offset within *recordPtr at which the
				 * internal value is to be stored. */
    char *oldInternalPtr,	/* Pointer to storage for the old value. */
    int flags)			/* Flags for the option, set Tk_SetOptions. */
{
    TkTextLine *linePtr = NULL;
    char *internalPtr;
    TkText *textPtr = (TkText *) recordPtr;

    if (internalOffset != TCL_INDEX_NONE) {
	internalPtr = (char *)recordPtr + internalOffset;
    if (internalOffset >= 0) {
	internalPtr = recordPtr + internalOffset;
    } else {
	internalPtr = NULL;
    }

    if (flags & TK_OPTION_NULL_OK && ObjectIsEmpty(*value)) {
	*value = NULL;
    } else {
6836
6837
6838
6839
6840
6841
6842
6843
6844


6845
6846
6847
6848
6849
6850
6851
6864
6865
6866
6867
6868
6869
6870


6871
6872
6873
6874
6875
6876
6877
6878
6879







-
-
+
+







 *	Restores the old value.
 *
 *----------------------------------------------------------------------
 */

static void
RestoreLineStartEnd(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tk_Window),
    ClientData clientData,
    Tk_Window tkwin,
    char *internalPtr,		/* Pointer to storage for value. */
    char *oldInternalPtr)	/* Pointer to old value. */
{
    *(TkTextLine **)internalPtr = *(TkTextLine **)oldInternalPtr;
}

/*
6869
6870
6871
6872
6873
6874
6875
6876
6877


6878

6879
6880
6881
6882
6883
6884
6885
6897
6898
6899
6900
6901
6902
6903


6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914







-
-
+
+

+







static int
ObjectIsEmpty(
    Tcl_Obj *objPtr)		/* Object to test. May be NULL. */
{
    if (objPtr == NULL) {
	return 1;
    }
    if (objPtr->bytes == NULL) {
	Tcl_GetString(objPtr);
    if (objPtr->bytes != NULL) {
	return (objPtr->length == 0);
    }
    (void)Tcl_GetString(objPtr);
    return (objPtr->length == 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpTesttextCmd --
6895
6896
6897
6898
6899
6900
6901
6902

6903
6904

6905
6906
6907
6908
6909


6910
6911
6912

6913
6914
6915
6916
6917
6918
6919
6920
6921
6922

6923
6924
6925
6926
6927
6928
6929
6930
6931
6932


6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945

6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956

6957
6958
6959
6960
6961
6962
6963
6964
6965
6966

6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6924
6925
6926
6927
6928
6929
6930

6931
6932

6933
6934
6935
6936


6937
6938

6939

6940
6941
6942
6943
6944
6945
6946
6947
6948
6949

6950
6951
6952
6953
6954
6955





6956
6957


6958
6959
6960
6961
6962
6963
6964
6965
6966
6967

6968


6969
6970
6971
6972
6973
6974
6975
6976

6977


6978
6979
6980
6981
6982
6983
6984

6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995







-
+

-
+



-
-
+
+
-

-
+









-
+





-
-
-
-
-
+
+
-
-










-
+
-
-








-
+
-
-







-
+










 *	Depends on option; see below.
 *
 *----------------------------------------------------------------------
 */

int
TkpTesttextCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    TkText *textPtr;
    Tcl_Size len;
    Tcl_WideInt lineIndex, byteIndex;
    size_t len;
    int lineIndex, byteIndex, byteOffset;
    Tcl_WideInt byteOffset;
    TkTextIndex index;
    char buf[TK_POS_CHARS];
    char buf[64];
    Tcl_CmdInfo info;

    if (objc < 3) {
	return TCL_ERROR;
    }

    if (Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &info) == 0) {
	return TCL_ERROR;
    }
    textPtr = (TkText *)info.objClientData;
    textPtr = info.objClientData;
    len = strlen(Tcl_GetString(objv[2]));
    if (strncmp(Tcl_GetString(objv[2]), "byteindex", len) == 0) {
	if (objc != 5) {
	    return TCL_ERROR;
	}
	if (Tcl_GetWideIntFromObj(interp, objv[3], &lineIndex)) {
	    return TCL_ERROR;
	}
	lineIndex--;
	if (Tcl_GetWideIntFromObj(interp, objv[4], &byteIndex)) {
	lineIndex = atoi(Tcl_GetString(objv[3])) - 1;
	byteIndex = atoi(Tcl_GetString(objv[4]));
	    return TCL_ERROR;
	}

	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, lineIndex,
		byteIndex, &index);
    } else if (strncmp(Tcl_GetString(objv[2]), "forwbytes", len) == 0) {
	if (objc != 5) {
	    return TCL_ERROR;
	}
	if (TkTextGetIndex(interp, textPtr, Tcl_GetString(objv[3]), &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tcl_GetWideIntFromObj(interp, objv[4], &byteOffset)) {
	byteOffset = atoi(Tcl_GetString(objv[4]));
	    return TCL_ERROR;
	}
	TkTextIndexForwBytes(textPtr, &index, byteOffset, &index);
    } else if (strncmp(Tcl_GetString(objv[2]), "backbytes", len) == 0) {
	if (objc != 5) {
	    return TCL_ERROR;
	}
	if (TkTextGetIndex(interp, textPtr, Tcl_GetString(objv[3]), &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tcl_GetWideIntFromObj(interp, objv[4], &byteOffset)) {
	byteOffset = atoi(Tcl_GetString(objv[4]));
	    return TCL_ERROR;
	}
	TkTextIndexBackBytes(textPtr, &index, byteOffset, &index);
    } else {
	return TCL_ERROR;
    }

    TkTextSetMark(textPtr, "insert", &index);
    TkTextPrintIndex(textPtr, &index, buf);
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s %" TCL_SIZE_MODIFIER "d", buf, index.byteIndex));
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s %d", buf, index.byteIndex));
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkText.h.

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
95
96
97
98
99
100
101




102
103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122







-
-
-
-













-
+







				 * window. */
    int displayed;		/* Non-zero means that the window has been
				 * displayed on the screen recently. */
    struct TkTextSegment *parent;
    struct TkTextEmbWindowClient *next;
} TkTextEmbWindowClient;

typedef enum {
    TK_ALIGN_BASELINE, TK_ALIGN_BOTTOM, TK_ALIGN_CENTER, TK_ALIGN_TOP
} TkAlignMode;

typedef struct TkTextEmbWindow {
    struct TkSharedText *sharedTextPtr;
				/* Information about the shared portion of the
				 * text widget. */
    Tk_Window tkwin;		/* Window for this segment. This is just a
				 * temporary value, copied from 'clients', to
				 * make option table updating easier. NULL
				 * means that the window hasn't been created
				 * yet. */
    TkTextLine *linePtr;	/* Line structure that contains this
				 * window. */
    char *create;		/* Script to create window on-demand. NULL
				 * means no such script. Malloc-ed. */
    TkAlignMode align;		/* How to align window in vertical space. See
    int align;			/* How to align window in vertical space. See
				 * definitions in tkTextWind.c. */
    int padX, padY;		/* Padding to leave around each side of
				 * window, in pixels. */
    int stretch;		/* Should window stretch to fill vertical
				 * space of line (except for pady)? 0 or 1. */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175

176
177
178
179
180
181
182
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170

171
172
173
174
175
176
177
178







-
+




















-
+


-
+







    char *imageName;		/* Name used by text widget to identify this
				 * image. May be unique-ified. */
    char *name;			/* Name used in the hash table. Used by
				 * "image names" to identify this instance of
				 * the image. */
    Tk_Image image;		/* Image for this segment. NULL means that the
				 * image hasn't been created yet. */
    TkAlignMode align;		/* How to align image in vertical space. See
    int align;			/* How to align image in vertical space. See
				 * definitions in tkTextImage.c. */
    int padX, padY;		/* Padding to leave around each side of image,
				 * in pixels. */
    int chunkCount;		/* Number of display chunks that refer to this
				 * image. */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
} TkTextEmbImage;

/*
 * The data structure below defines line segments.
 */

typedef struct TkTextSegment {
    const struct Tk_SegType *typePtr;
				/* Pointer to record describing segment's
				 * type. */
    struct TkTextSegment *nextPtr;
				/* Next in list of segments for this line, or
				 * NULL for end of list. */
    Tcl_Size size;			/* Size of this segment (# of bytes of index
    int size;			/* Size of this segment (# of bytes of index
				 * space it occupies). */
    union {
	char chars[4];	/* Characters that make up character info.
	char chars[2];		/* Characters that make up character info.
				 * Actual length varies to hold as many
				 * characters as needed.*/
	TkTextToggle toggle;	/* Information about tag toggle. */
	TkTextMark mark;	/* Information about mark. */
	TkTextEmbWindow ew;	/* Information about embedded window. */
	TkTextEmbImage ei;	/* Information about embedded image. */
    } body;
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

218
219

220
221
222
223
224
225
226
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214

215
216
217
218
219
220
221
222







-
+



















-
+

-
+







 * However, mods to marks or tags don't invalidate indices.
 */

typedef struct TkTextIndex {
    TkTextBTree tree;		/* Tree containing desired position. */
    TkTextLine *linePtr;	/* Pointer to line containing position of
				 * interest. */
    Tcl_Size byteIndex;		/* Index within line of desired character (0
    int byteIndex;		/* Index within line of desired character (0
				 * means first one). */
    struct TkText *textPtr;	/* May be NULL, but otherwise the text widget
				 * with which this index is associated. If not
				 * NULL, then we have a refCount on the
				 * widget. */
} TkTextIndex;

/*
 * Types for procedure pointers stored in TkTextDispChunk strutures:
 */

typedef struct TkTextDispChunk TkTextDispChunk;

typedef void 		Tk_ChunkDisplayProc(struct TkText *textPtr,
			    TkTextDispChunk *chunkPtr, int x, int y,
			    int height, int baseline, Display *display,
			    Drawable dst, int screenY);
typedef void		Tk_ChunkUndisplayProc(struct TkText *textPtr,
			    TkTextDispChunk *chunkPtr);
typedef Tcl_Size	Tk_ChunkMeasureProc(TkTextDispChunk *chunkPtr, int x);
typedef int		Tk_ChunkMeasureProc(TkTextDispChunk *chunkPtr, int x);
typedef void		Tk_ChunkBboxProc(struct TkText *textPtr,
			    TkTextDispChunk *chunkPtr, Tcl_Size index, int y,
			    TkTextDispChunk *chunkPtr, int index, int y,
			    int lineHeight, int baseline, int *xPtr,
			    int *yPtr, int *widthPtr, int *heightPtr);

/*
 * The structure below represents a chunk of stuff that is displayed together
 * on the screen. This structure is allocated and freed by generic display
 * code but most of its fields are filled in by segment-type-specific code.
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364


365
366
367

368
369
370
371
372
373

374
375

376
377
378
379
380
381
382



383
384
385
386
387
388
389
390
391
392
393
394

395

396
397
398
399
400



401
402
403
404
405
406
407
408
409
410


411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428

429
430
431
432
433
434

435
436

437
438
439

440
441
442
443


444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459



460
461
462
463
464
465




466
467
468
469
470
471


472
473
474
475
476
477
478
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273

274
275
276
277
278
279
280
281
282
283
284



285
286

287
288
















289
290
291
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324

325
326
327
328
329
330
331
332
333
334

335
336



337
338



339

340
341

342

343


344


345
346



347
348
349
350
351
352



353
354

355
356

357

358
359
360



361
362
363
364
365




366
367


368
369
370
371
372
373
374
375




376
377

378

379



380

381
382

383

384


385



386
387

388

389
390
391
392
393
394
395




396
397
398
399



400
401
402
403
404
405



406
407
408
409

410
411



412
413
414
415
416
417
418
419
420







-
+











-
+



-
+










-
-
-
+
+
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
+








-
+













-


-










-


-
-
-
+
+
-
-
-
+
-


-

-
+
-
-
+
-
-


-
-
-
+
+
+



-
-
-


-


-
+
-
+


-
-
-
+
+
+


-
-
-
-


-
-
+
+






-
-
-
-


-

-
+
-
-
-
+
-


-

-
+
-
-
+
-
-
-
+

-

-
+
+





-
-
-
-




-
-
-
+
+
+



-
-
-
+
+
+
+
-


-
-
-
+
+







				/* Procedure to invoke when segment ceases to
				 * be displayed on screen anymore. */
    Tk_ChunkMeasureProc *measureProc;
				/* Procedure to find character under a given
				 * x-location. */
    Tk_ChunkBboxProc *bboxProc;	/* Procedure to find bounding box of character
				 * in chunk. */
    Tcl_Size numBytes;		/* Number of bytes that will be displayed in
    int numBytes;		/* Number of bytes that will be displayed in
				 * the chunk. */
    int minAscent;		/* Minimum space above the baseline needed by
				 * this chunk. */
    int minDescent;		/* Minimum space below the baseline needed by
				 * this chunk. */
    int minHeight;		/* Minimum total line height needed by this
				 * chunk. */
    int width;			/* Width of this chunk, in pixels. Initially
				 * set by chunk-specific code, but may be
				 * increased to include tab or extra space at
				 * end of line. */
    Tcl_Size breakIndex;		/* Index within chunk of last acceptable
    int breakIndex;		/* Index within chunk of last acceptable
				 * position for a line (break just before this
				 * byte index). <= 0 means don't break during
				 * or immediately after this chunk. */
    void *clientData;	/* Additional information for use of
    ClientData clientData;	/* Additional information for use of
				 * displayProc and undisplayProc. */
};

/*
 * One data structure of the following type is used for each tag in a text
 * widget. These structures are kept in sharedTextPtr->tagTable and referred
 * to in other structures.
 */

typedef enum {
    TEXT_WRAPMODE_NULL = -1,
    TEXT_WRAPMODE_CHAR,
    TEXT_WRAPMODE_NONE,
    TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, TEXT_WRAPMODE_WORD,
    TEXT_WRAPMODE_NULL
    TEXT_WRAPMODE_WORD
} TkWrapMode;

/*
 * The following are the supported styles of tabbing, used for the -tabstyle
 * option of the text widget. The first element is only used for tag options.
 */

typedef enum {
    TK_TEXT_TABSTYLE_NULL = -1,
    TK_TEXT_TABSTYLE_TABULAR,
    TK_TEXT_TABSTYLE_WORDPROCESSOR
} TkTextTabStyle;

MODULE_SCOPE const char *const tkTextTabStyleStrings[];


MODULE_SCOPE const char *const tkTextWrapStrings[];

typedef struct TkTextTag {
    const char *name;		/* Name of this tag. This field is actually a
				 * pointer to the key from the entry in
				 * sharedTextPtr->tagTable, so it needn't be
				 * freed explicitly. For 'sel' tags this is
				 * just a static string, so again need not be
				 * freed. */
    const struct TkText *textPtr;
				/* If non-NULL, then this tag only applies to
				 * the given text widget (when there are peer
				 * widgets). */
    Tcl_Size priority;	/* Priority of this tag within widget. 0 means
    int priority;		/* Priority of this tag within widget. 0 means
				 * lowest priority. Exactly one tag has each
				 * integer value between 0 and numTags-1. */
    struct Node *tagRootPtr;	/* Pointer into the B-Tree at the lowest node
				 * that completely dominates the ranges of
				 * text occupied by the tag. At this node
				 * there is no information about the tag. One
				 * or more children of the node do contain
				 * information about the tag. */
    Tcl_Size toggleCount;	/* Total number of tag toggles. */
    int toggleCount;		/* Total number of tag toggles. */

    /*
     * Information for displaying text with this tag. The information belows
     * acts as an override on information specified by lower-priority tags.
     * If no value is specified, then the next-lower-priority tag on the text
     * determins the value. The text widget itself provides defaults if no tag
     * specifies an override.
     */

    Tk_3DBorder border;		/* Used for drawing background. NULL means no
				 * value specified here. */
    int borderWidth;		/* Width of 3-D border for background. */
    Tcl_Obj *borderWidthPtr;	/* Width of 3-D border for background. */
#if TK_MAJOR_VERSION < 9
    char *reliefString;		/* -relief option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int relief;			/* 3-D relief for background. */
    Pixmap bgStipple;		/* Stipple bitmap for background. None means
				 * no value specified here. */
    XColor *fgColor;		/* Foreground color for text. NULL means no
				 * value specified here. */
    Tk_Font tkfont;		/* Font for displaying text. NULL means no
				 * value specified here. */
    Pixmap fgStipple;		/* Stipple bitmap for text and other
				 * foreground stuff. None means no value
				 * specified here.*/
#if TK_MAJOR_VERSION < 9
    char *justifyString;	/* -justify option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    Tk_Justify justify;		/* How to justify text: TK_JUSTIFY_CENTER,
				 * TK_JUSTIFY_LEFT, or TK_JUSTIFY_RIGHT. */
    Tk_Justify justify;		/* How to justify text: TK_JUSTIFY_LEFT,
				 * TK_JUSTIFY_RIGHT, or TK_JUSTIFY_CENTER.
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *lMargin1Obj;	/* -lmargin1 option object. NULL
				 * means option not specified. */
				 * Only valid if justifyString is non-NULL. */
#else
    char *lMargin1String;	/* -lmargin1 option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int lMargin1;		/* Left margin for first display line of each
				 * text line, in pixels. INT_MIN means option not specified. */
				 * text line, in pixels. Only valid if
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *lMargin2Obj;	/* -lmargin2 option object. NULL
				 * lMargin1String is non-NULL. */
				 * means option not specified. */
#else
    char *lMargin2String;	/* -lmargin2 option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int lMargin2;		/* Left margin for second and later display lines
				 * of each text line, in pixels. INT_MIN means option not specified. */
    int lMargin2;		/* Left margin for second and later display
				 * lines of each text line, in pixels. Only
				 * valid if lMargin2String is non-NULL. */
    Tk_3DBorder lMarginColor;	/* Used for drawing background in left margins.
                                 * This is used for both lmargin1 and lmargin2.
				 * NULL means no value specified here. */
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *offsetObj;		/* -offset option. NULL means option not specified. */
#else
    char *offsetString;		/* -offset option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int offset;			/* Vertical offset of text's baseline from
				 * baseline of line. Used for superscripts and
				 * subscripts. INT_MIN means option not specified. */
				 * subscripts. Only valid if offsetString is
#if TK_MAJOR_VERSION < 9
				 * non-NULL. */
    char *overstrikeString;	/* -overstrike option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int overstrike;		/* > 0 means draw horizontal line through
				 * middle of text. -1 means not specified. */
    int overstrike;		/* Non-zero means draw horizontal line through
				 * middle of text. Only valid if
				 * overstrikeString is non-NULL. */
    XColor *overstrikeColor;    /* Color for the overstrike. NULL means same
                                 * color as foreground. */
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *rMarginObj;	/* -rmargin option object. NULL
				 * means option not specified. */
#else
    char *rMarginString;	/* -rmargin option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int rMargin;		/* Right margin for text, in pixels. INT_MIN means option not specified. */
    int rMargin;		/* Right margin for text, in pixels. Only
				 * valid if rMarginString is non-NULL. */
    Tk_3DBorder rMarginColor;	/* Used for drawing background in right margin.
				 * NULL means no value specified here. */
    Tk_3DBorder selBorder;	/* Used for drawing background for selected text.
				 * NULL means no value specified here. */
    XColor *selFgColor;		/* Foreground color for selected text. NULL means
				 * no value specified here. */
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *spacing1Obj;	/* -spacing1 option object. NULL
				 * means option not specified. */
#else
    char *spacing1String;	/* -spacing1 option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int spacing1;		/* Extra spacing above first display line for
				 * text line. INT_MIN means option not specified. */
				 * text line. Only valid if spacing1String is
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *spacing2Obj;	/* -spacing2 option object. NULL
				 * means option not specified. */
				 * non-NULL. */
#else
    char *spacing2String;	/* -spacing2 option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int spacing2;		/* Extra spacing between display lines for the
				 * same text line. INT_MIN means option not specified. */
				 * same text line. Only valid if
#if TK_MAJOR_VERSION > 8
    Tcl_Obj *spacing3Obj;	/* -spacing3 option object. NULL
				 * spacing2String is non-NULL. */
				 * means option not specified. */
#else
    char *spacing3String;	/* -spacing3 option string (malloc-ed). NULL
    char *spacing3String;	/* -spacing2 option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int spacing3;		/* Extra spacing below last display line for
				 * text line. INT_MIN means option not specified. */
				 * text line. Only valid if spacing3String is
				 * non-NULL. */
    Tcl_Obj *tabStringPtr;	/* -tabs option string. NULL means option not
				 * specified. */
    struct TkTextTabArray *tabArrayPtr;
				/* Info about tabs for tag (malloc-ed) or
				 * NULL. Corresponds to tabString. */
#if TK_MAJOR_VERSION > 8
    TkTextTabStyle tabStyle;	/* One of TK_TEXT_TABSTYLE_TABULAR or TK_TEXT_TABSTYLE_WORDPROCESSOR
				 * or TK_TEXT_TABSTYLE_NULL (if not specified). */
#else
    int tabStyle;		/* One of TABULAR or WORDPROCESSOR or NONE (if
				 * not specified). */
    char *underlineString;	/* -underline option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int underline;		/* > 0 means draw underline underneath
				 * text. -1 means not specified. */
    int underline;		/* Non-zero means draw underline underneath
				 * text. Only valid if underlineString is
				 * non-NULL. */
    XColor *underlineColor;     /* Color for the underline. NULL means same
                                 * color as foreground. */
    TkWrapMode wrapMode;	/* How to handle wrap-around for this tag.
				 * Must be TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_WORD,
				 * TEXT_WRAPMODE_NONE, or TEXT_WRAPMODE_NULL to
				 * use wrapmode for whole widget. */
				 * Must be TEXT_WRAPMODE_CHAR,
				 * TEXT_WRAPMODE_NONE, TEXT_WRAPMODE_WORD, or
				 * TEXT_WRAPMODE_NULL to use wrapmode for
				 * whole widget. */
#if TK_MAJOR_VERSION < 9
    char *elideString;		/* -elide option string (malloc-ed). NULL
				 * means option not specified. */
#endif
    int elide;			/* > 0 means that data under this tag
				 * should not be displayed. -1 means not specified. */
    int elide;			/* Non-zero means that data under this tag
				 * should not be displayed. */
    int affectsDisplay;		/* Non-zero means that this tag affects the
				 * way information is displayed on the screen
				 * (so need to redisplay if tag changes). */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
    int affectsDisplayGeometry;	/* Non-zero means that this tag affects the
				 * size with which information is displayed on
518
519
520
521
522
523
524











525
526
527
528
529
530
531
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499







+
+
+
+
+
+
+
+
+
+
+














-
+







/*
 * The following data structure describes a single tab stop. It must be kept
 * in sync with the 'tabOptionStrings' array in the function 'TkTextGetTabs'
 */

typedef enum {LEFT, RIGHT, CENTER, NUMERIC} TkTextTabAlign;

/*
 * The following are the supported styles of tabbing, used for the -tabstyle
 * option of the text widget. The last element is only used for tag options.
 */

typedef enum {
    TK_TEXT_TABSTYLE_TABULAR,
    TK_TEXT_TABSTYLE_WORDPROCESSOR,
    TK_TEXT_TABSTYLE_NONE
} TkTextTabStyle;

typedef struct TkTextTab {
    int location;		/* Offset in pixels of this tab stop from the
				 * left margin (lmargin2) of the text. */
    TkTextTabAlign alignment;	/* Where the tab stop appears relative to the
				 * text. */
} TkTextTab;

typedef struct TkTextTabArray {
    int numTabs;		/* Number of tab stops. */
    double lastTab;		/* The accurate fractional pixel position of
				 * the last tab. */
    double tabIncrement;	/* The accurate fractional pixel increment
				 * between interpolated tabs we have to create
				 * when we exceed numTabs. */
    TkTextTab tabs[TKFLEXARRAY];/* Array of tabs. The actual size will be
    TkTextTab tabs[1];		/* Array of tabs. The actual size will be
				 * numTabs. THIS FIELD MUST BE THE LAST IN THE
				 * STRUCTURE. */
} TkTextTabArray;

/*
 * Enumeration defining the edit modes of the widget.
 */
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590

591
592
593
594
595
596
597
529
530
531
532
533
534
535

536
537
538
539
540
541
542

543
544
545
546
547
548
549
550







-
+






-
+








/*
 * A data structure of the following type is shared between each text widget
 * that are peers.
 */

typedef struct TkSharedText {
    Tcl_Size refCount;		/* Reference count this shared object. */
    int refCount;		/* Reference count this shared object. */
    TkTextBTree tree;		/* B-tree representation of text and tags for
				 * widget. */
    Tcl_HashTable tagTable;	/* Hash table that maps from tag names to
				 * pointers to TkTextTag structures. The "sel"
				 * tag does not feature in this table, since
				 * there's one of those for each text peer. */
    Tcl_Size numTags;		/* Number of tags currently defined for
    int numTags;		/* Number of tags currently defined for
				 * widget; needed to keep track of
				 * priorities. */
    Tcl_HashTable markTable;	/* Hash table that maps from mark names to
				 * pointers to mark segments. The special
				 * "insert" and "current" marks are not stored
				 * in this table, but directly accessed as
				 * fields of textPtr. */
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630


631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
558
559
560
561
562
563
564

565
566
567
568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598



599
600
601
602
603
604
605







-
+




-













+
+














-
-
-







				 * image, there is no entry for it here. */
    Tk_BindingTable bindingTable;
				/* Table of all bindings currently defined for
				 * this widget. NULL means that no bindings
				 * exist, so the table hasn't been created.
				 * Each "object" used for this table is the
				 * name of a tag. */
    Tcl_Size stateEpoch;	/* This is incremented each time the B-tree's
    int stateEpoch;		/* This is incremented each time the B-tree's
				 * contents change structurally, or when the
				 * start/end limits change, and means that any
				 * cached TkTextIndex objects are no longer
				 * valid. */
    int imageCount;		/* Used for creating unique image names. */

    /*
     * Information related to the undo/redo functionality.
     */

    TkUndoRedoStack *undoStack;	/* The undo/redo stack. */
    int undo;			/* Non-zero means the undo/redo behaviour is
				 * enabled. */
    int maxUndo;		/* The maximum depth of the undo stack
				 * expressed as the maximum number of compound
				 * statements. */
    int autoSeparators;		/* Non-zero means the separators will be
				 * inserted automatically. */
    int undoMarkId;             /* Counts undo marks temporarily used during
                                   undo and redo operations. */
    int isDirty;		/* Flag indicating the 'dirtyness' of the
				 * text widget. If the flag is not zero,
				 * unsaved modifications have been applied to
				 * the text widget. */
    TkTextDirtyMode dirtyMode;	/* The nature of the dirtyness characterized
				 * by the isDirty flag. */
    TkTextEditMode lastEditMode;/* Keeps track of what the last edit mode
				 * was. */

    /*
     * Keep track of all the peers
     */

    struct TkText *peers;

    Tcl_Size undoMarkId;             /* Counts undo marks temporarily used during
                                   undo and redo operations. */
} TkSharedText;

/*
 * The following enum is used to define a type for the -insertunfocussed
 * option of the Text widget.
 */

692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657







-
+







				 * up.*/
    Display *display;		/* Display for widget. Needed, among other
				 * things, to allow resources to be freed even
				 * after tkwin has gone away. */
    Tcl_Interp *interp;		/* Interpreter associated with widget. Used to
				 * delete widget command. */
    Tcl_Command widgetCmd;	/* Token for text's widget command. */
    TkTextState state;		/* Either TK_TEXT_STATE_DISABLED or TK_TEXT_STATE_NORMAL. A
    int state;			/* Either STATE_NORMAL or STATE_DISABLED. A
				 * text widget is read-only when disabled. */

    /*
     * Default information for displaying (may be overridden by tags applied
     * to ranges of characters).
     */

714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
665
666
667
668
669
670
671

672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697

698

699
700
701
702
703
704
705







-
+

















-
+







-
+
-







    int highlightWidth;		/* Width in pixels of highlight to draw around
				 * widget when it has the focus. <= 0 means
				 * don't draw a highlight. */
    XColor *highlightBgColorPtr;
				/* Color for drawing traversal highlight area
				 * when highlight is off. */
    XColor *highlightColorPtr;	/* Color for drawing traversal highlight. */
    Tk_Cursor cursor;		/* Current cursor for window, or NULL. */
    Tk_Cursor cursor;		/* Current cursor for window, or None. */
    XColor *fgColor;		/* Default foreground color for text. */
    Tk_Font tkfont;		/* Default font for displaying text. */
    int charWidth;		/* Width of average character in default
				 * font. */
    int charHeight;		/* Height of average character in default
				 * font, including line spacing. */
    int spacing1;		/* Default extra spacing above first display
				 * line for each text line. */
    int spacing2;		/* Default extra spacing between display lines
				 * for the same text line. */
    int spacing3;		/* Default extra spacing below last display
				 * line for each text line. */
    Tcl_Obj *tabOptionPtr; 	/* Value of -tabs option string. */
    TkTextTabArray *tabArrayPtr;
				/* Information about tab stops (malloc'ed).
				 * NULL means perform default tabbing
				 * behavior. */
    TkTextTabStyle tabStyle;	/* One of TK_TEXT_TABSTYLE_TABULAR or TK_TEXT_TABSTYLE_WORDPROCESSOR. */
    int tabStyle;		/* One of TABULAR or WORDPROCESSOR. */

    /*
     * Additional information used for displaying:
     */

    TkWrapMode wrapMode;	/* How to handle wrap-around. Must be
				 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
				 * TEXT_WRAPMODE_WORD, or TEXT_WRAPMODE_NULL to
				 * TEXT_WRAPMODE_WORD. */
				 * use wrapmode for whole widget. */
    int width, height;		/* Desired dimensions for window, measured in
				 * characters. */
    int setGrid;		/* Non-zero means pass gridding information to
				 * window manager. */
    int prevWidth, prevHeight;	/* Last known dimensions of window; used to
				 * detect changes in size. */
    TkTextIndex topIndex;	/* Identifies first character in top display
818
819
820
821
822
823
824
825
826

827
828
829

830
831

832
833
834
835
836
837
838
839
840
841
842

843
844
845
846
847
848
849
768
769
770
771
772
773
774


775
776
777

778
779

780
781





782
783
784
785

786
787
788
789
790
791
792
793







-
-
+


-
+

-
+

-
-
-
-
-




-
+







    TkTextTag **curTagArrayPtr;	/* Pointer to array of tags for current mark,
				 * or NULL if none. */

    /*
     * Miscellaneous additional information:
     */

#if TK_MAJOR_VERSION > 8
    Tcl_Obj *takeFocusObj;		/* Value of -takeFocus option; not used in the
    char *takeFocus;		/* Value of -takeFocus option; not used in the
				 * C code, but used by keyboard traversal
				 * scripts. Malloc'ed, but may be NULL. */
    Tcl_Obj *xScrollCmdObj;		/* Prefix of command to issue to update
    char *xScrollCmd;		/* Prefix of command to issue to update
				 * horizontal scrollbar when view changes. */
    Tcl_Obj *yScrollCmdObj;		/* Prefix of command to issue to update
    char *yScrollCmd;		/* Prefix of command to issue to update
				 * vertical scrollbar when view changes. */
#else
    char *takeFocus;
    char *xScrollCmd;
    char *yScrollCmd;
#endif
    int flags;			/* Miscellaneous flags; see below for
				 * definitions. */
    Tk_OptionTable optionTable;	/* Token representing the configuration
				 * specifications. */
    Tcl_Size refCount;		/* Number of cached TkTextIndex objects
    int refCount;		/* Number of cached TkTextIndex objects
				 * refering to us. */
    int insertCursorType;	/* 0 = standard insertion cursor, 1 = block
				 * cursor. */

    /*
     * Copies of information from the shared section relating to the undo/redo
     * functonality
891
892
893
894
895
896
897
898

899
900
901
902
903
904
905
906
907
908


909
910
911
912
913
914
915
835
836
837
838
839
840
841

842
843
844
845
846
847
848
849
850


851
852
853
854
855
856
857
858
859







-
+








-
-
+
+








/*
 * Records of the following type define segment types in terms of a collection
 * of procedures that may be called to manipulate segments of that type.
 */

typedef TkTextSegment *	Tk_SegSplitProc(struct TkTextSegment *segPtr,
			    Tcl_Size index);
			    int index);
typedef int		Tk_SegDeleteProc(struct TkTextSegment *segPtr,
			    TkTextLine *linePtr, int treeGone);
typedef TkTextSegment *	Tk_SegCleanupProc(struct TkTextSegment *segPtr,
			    TkTextLine *linePtr);
typedef void		Tk_SegLineChangeProc(struct TkTextSegment *segPtr,
			    TkTextLine *linePtr);
typedef int		Tk_SegLayoutProc(struct TkText *textPtr,
			    struct TkTextIndex *indexPtr,
			    TkTextSegment *segPtr, Tcl_Size offset, int maxX,
			    Tcl_Size maxChars, int noCharsYet, TkWrapMode wrapMode,
			    TkTextSegment *segPtr, int offset, int maxX,
			    int maxChars, int noCharsYet, TkWrapMode wrapMode,
			    struct TkTextDispChunk *chunkPtr);
typedef void		Tk_SegCheckProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);

typedef struct Tk_SegType {
    const char *name;		/* Name of this kind of segment. */
    int leftGravity;		/* If a segment has zero size (e.g. a mark or
959
960
961
962
963
964
965
966

967
968

969
970
971
972
973
974
975
903
904
905
906
907
908
909

910
911

912
913
914
915
916
917
918
919







-
+

-
+







 * of different tag priorities, it is need for quick calculations of whether a
 * single index is elided, and to start at a given index and maintain a
 * correct elide state as we move or count forwards or backwards.
 */

#define LOTSA_TAGS 1000
typedef struct TkTextElideInfo {
    Tcl_Size numTags;		/* Total tags in widget. */
    int numTags;		/* Total tags in widget. */
    int elide;			/* Is the state currently elided. */
    Tcl_Size elidePriority;			/* Tag priority controlling elide state. */
    int elidePriority;		/* Tag priority controlling elide state. */
    TkTextSegment *segPtr;	/* Segment to look at next. */
    int segOffset;		/* Offset of segment within line. */
    int deftagCnts[LOTSA_TAGS];
    TkTextTag *deftagPtrs[LOTSA_TAGS];
    int *tagCnts;		/* 0 or 1 depending if the tag with that
				 * priority is on or off. */
    TkTextTag **tagPtrs;	/* Only filled with a tagPtr if the
991
992
993
994
995
996
997
998

999
1000
1001
1002


1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014



1015
1016
1017
1018
1019
1020
1021
1022
935
936
937
938
939
940
941

942
943
944


945
946
947
948

949
950
951
952
953
954




955
956
957

958
959
960
961
962
963
964







-
+


-
-
+
+


-
+





-
-
-
-
+
+
+
-







#define TK_POS_CHARS		30

/*
 * Mask used for those options which may impact the pixel height calculations
 * of individual lines displayed in the widget.
 */

#define TK_TEXT_LINE_GEOMETRY		(1 << 0)
#define TK_TEXT_LINE_GEOMETRY	1

/*
 * Mask used for those options which may impact the start and end lines
 * used in the widget.
 * Mask used for those options which may impact the start and end lines used
 * in the widget.
 */

#define TK_TEXT_LINE_RANGE		(1 << 1)
#define TK_TEXT_LINE_RANGE	2

/*
 * Used as 'action' values in calls to TkTextInvalidateLineMetrics
 */

typedef enum {
    TK_TEXT_INVALIDATE_ONLY,
    TK_TEXT_INVALIDATE_INSERT,
    TK_TEXT_INVALIDATE_DELETE
#define TK_TEXT_INVALIDATE_ONLY		0
#define TK_TEXT_INVALIDATE_INSERT	1
#define TK_TEXT_INVALIDATE_DELETE	2
} TkTextInvalidateAction;

/*
 * Used as special 'pickPlace' values in calls to TkTextSetYView. Zero or
 * positive values indicate a number of pixels.
 */

#define TK_TEXT_PICKPLACE	-1
1063
1064
1065
1066
1067
1068
1069
1070

1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







-
+






-
+







MODULE_SCOPE void	TkBTreeClientRangeChanged(TkText *textPtr,
			    int defaultHeight);
MODULE_SCOPE void	TkBTreeRemoveClient(TkTextBTree tree,
			    TkText *textPtr);
MODULE_SCOPE void	TkBTreeDestroy(TkTextBTree tree);
MODULE_SCOPE void	TkBTreeDeleteIndexRange(TkTextBTree tree,
			    TkTextIndex *index1Ptr, TkTextIndex *index2Ptr);
MODULE_SCOPE Tcl_Size	TkBTreeEpoch(TkTextBTree tree);
MODULE_SCOPE int	TkBTreeEpoch(TkTextBTree tree);
MODULE_SCOPE TkTextLine *TkBTreeFindLine(TkTextBTree tree,
			    const TkText *textPtr, int line);
MODULE_SCOPE TkTextLine *TkBTreeFindPixelLine(TkTextBTree tree,
			    const TkText *textPtr, int pixels,
			    int *pixelOffset);
MODULE_SCOPE TkTextTag **TkBTreeGetTags(const TkTextIndex *indexPtr,
			    const TkText *textPtr, Tcl_Size *numTagsPtr);
			    const TkText *textPtr, int *numTagsPtr);
MODULE_SCOPE void	TkBTreeInsertChars(TkTextBTree tree,
			    TkTextIndex *indexPtr, const char *string);
MODULE_SCOPE int	TkBTreeLinesTo(const TkText *textPtr,
			    TkTextLine *linePtr);
MODULE_SCOPE int	TkBTreePixelsTo(const TkText *textPtr,
			    TkTextLine *linePtr);
MODULE_SCOPE void	TkBTreeLinkSegment(TkTextSegment *segPtr,
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085







-
+







-
+



















-
+


-
+







			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
			    TkTextSearch *searchPtr);
MODULE_SCOPE int	TkBTreeTag(TkTextIndex *index1Ptr,
			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
			    int add);
MODULE_SCOPE void	TkBTreeUnlinkSegment(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
MODULE_SCOPE void	TkTextBindProc(void *clientData,
MODULE_SCOPE void	TkTextBindProc(ClientData clientData,
			    XEvent *eventPtr);
MODULE_SCOPE void	TkTextSelectionEvent(TkText *textPtr);
MODULE_SCOPE int	TkTextIndexBbox(TkText *textPtr,
			    const TkTextIndex *indexPtr, int *xPtr, int *yPtr,
			    int *widthPtr, int *heightPtr, int *charWidthPtr);
MODULE_SCOPE int	TkTextCharLayoutProc(TkText *textPtr,
			    TkTextIndex *indexPtr, TkTextSegment *segPtr,
			    Tcl_Size offset, int maxX, Tcl_Size maxChars, int noBreakYet,
			    int offset, int maxX, int maxChars, int noBreakYet,
			    TkWrapMode wrapMode, TkTextDispChunk *chunkPtr);
MODULE_SCOPE void	TkTextCreateDInfo(TkText *textPtr);
MODULE_SCOPE int	TkTextDLineInfo(TkText *textPtr,
			    const TkTextIndex *indexPtr, int *xPtr, int *yPtr,
			    int *widthPtr, int *heightPtr, int *basePtr);
MODULE_SCOPE void	TkTextEmbWinDisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, int x, int y,
			    int lineHeight, int baseline, Display *display,
			    Drawable dst, int screenY);
MODULE_SCOPE TkTextTag *TkTextCreateTag(TkText *textPtr,
			    const char *tagName, int *newTag);
MODULE_SCOPE void	TkTextFreeDInfo(TkText *textPtr);
MODULE_SCOPE void	TkTextDeleteTag(TkText *textPtr, TkTextTag *tagPtr);
MODULE_SCOPE void	TkTextFreeTag(TkText *textPtr, TkTextTag *tagPtr);
MODULE_SCOPE int	TkTextGetObjIndex(Tcl_Interp *interp, TkText *textPtr,
			    Tcl_Obj *idxPtr, TkTextIndex *indexPtr);
MODULE_SCOPE int	TkTextSharedGetObjIndex(Tcl_Interp *interp,
			    TkSharedText *sharedTextPtr, Tcl_Obj *idxPtr,
			    TkTextIndex *indexPtr);
MODULE_SCOPE const	TkTextIndex *TkTextGetIndexFromObj(Tcl_Interp *interp,
MODULE_SCOPE const TkTextIndex *TkTextGetIndexFromObj(Tcl_Interp *interp,
			    TkText *textPtr, Tcl_Obj *objPtr);
MODULE_SCOPE TkTextTabArray *TkTextGetTabs(Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Obj *stringPtr);
			    TkText *textPtr, Tcl_Obj *stringPtr);
MODULE_SCOPE void	TkTextFindDisplayLineEnd(TkText *textPtr,
			    TkTextIndex *indexPtr, int end, int *xOffset);
MODULE_SCOPE void	TkTextIndexBackChars(const TkText *textPtr,
			    const TkTextIndex *srcPtr, int count,
			    TkTextIndex *dstPtr, TkTextCountType type);
MODULE_SCOPE int	TkTextIndexCmp(const TkTextIndex *index1Ptr,
			    const TkTextIndex *index2Ptr);
1152
1153
1154
1155
1156
1157
1158
1159
1160


1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201

1202
1203
1204


1205
1206
1207
1208
1209

1210
1211

1212
1213
1214
1215

1216
1217
1218
1219

1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1094
1095
1096
1097
1098
1099
1100


1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

1143
1144


1145
1146
1147
1148
1149
1150

1151
1152

1153
1154
1155
1156

1157
1158
1159
1160

1161
1162
1163

1164


1165
1166
1167
1168
1169
1170
1171
1172
1173







-
-
+
+













-
+






-
+



















-
+

-
-
+
+




-
+

-
+



-
+



-
+


-
+
-
-









			    const TkTextIndex *srcPtr, int count,
			    TkTextIndex *dstPtr, TkTextCountType type);
MODULE_SCOPE void	TkTextIndexOfX(TkText *textPtr, int x,
			    TkTextIndex *indexPtr);
MODULE_SCOPE int	TkTextIndexYPixels(TkText *textPtr,
			    const TkTextIndex *indexPtr);
MODULE_SCOPE TkTextSegment *TkTextIndexToSeg(const TkTextIndex *indexPtr,
			    Tcl_Size *offsetPtr);
MODULE_SCOPE void	TkTextLostSelection(void *clientData);
			    int *offsetPtr);
MODULE_SCOPE void	TkTextLostSelection(ClientData clientData);
MODULE_SCOPE TkTextIndex *TkTextMakeCharIndex(TkTextBTree tree, TkText *textPtr,
			    int lineIndex, int charIndex,
			    TkTextIndex *indexPtr);
MODULE_SCOPE int	TkTextMeasureDown(TkText *textPtr,
			    TkTextIndex *srcPtr, int distance);
MODULE_SCOPE void	TkTextFreeElideInfo(TkTextElideInfo *infoPtr);
MODULE_SCOPE int	TkTextIsElided(const TkText *textPtr,
			    const TkTextIndex *indexPtr,
			    TkTextElideInfo *infoPtr);
MODULE_SCOPE int	TkTextMakePixelIndex(TkText *textPtr,
			    int pixelIndex, TkTextIndex *indexPtr);
MODULE_SCOPE void	TkTextInvalidateLineMetrics(
			    TkSharedText *sharedTextPtr, TkText *textPtr,
			    TkTextLine *linePtr, int lineCount, TkTextInvalidateAction action);
			    TkTextLine *linePtr, int lineCount, int action);
MODULE_SCOPE int	TkTextUpdateLineMetrics(TkText *textPtr, int lineNum,
			    int endLine, int doThisMuch);
MODULE_SCOPE int	TkTextUpdateOneLine(TkText *textPtr,
			    TkTextLine *linePtr, int pixelHeight,
			    TkTextIndex *indexPtr, int partialCalc);
MODULE_SCOPE int	TkTextMarkCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextMarkNameToIndex(TkText *textPtr,
			    const char *name, TkTextIndex *indexPtr);
MODULE_SCOPE void	TkTextMarkSegToIndex(TkText *textPtr,
			    TkTextSegment *markPtr, TkTextIndex *indexPtr);
MODULE_SCOPE void	TkTextEventuallyRepick(TkText *textPtr);
MODULE_SCOPE Bool	TkTextPendingsync(TkText *textPtr);
MODULE_SCOPE void	TkTextPickCurrent(TkText *textPtr, XEvent *eventPtr);
MODULE_SCOPE void	TkTextPixelIndex(TkText *textPtr, int x, int y,
			    TkTextIndex *indexPtr, int *nearest);
MODULE_SCOPE Tcl_Obj *	TkTextNewIndexObj(TkText *textPtr,
			    const TkTextIndex *indexPtr);
MODULE_SCOPE void	TkTextRedrawRegion(TkText *textPtr, int x, int y,
			    int width, int height);
MODULE_SCOPE void	TkTextRedrawTag(TkSharedText *sharedTextPtr,
			    TkText *textPtr, TkTextIndex *index1Ptr,
			    TkTextIndex *index2Ptr, TkTextTag *tagPtr,
			    int withTag);
MODULE_SCOPE void	TkTextRelayoutWindow(TkText *textPtr, int mask);
MODULE_SCOPE int	TkTextScanCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextSeeCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
MODULE_SCOPE Tcl_Size TkTextSegToOffset(const TkTextSegment *segPtr,
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextSegToOffset(const TkTextSegment *segPtr,
			    const TkTextLine *linePtr);
MODULE_SCOPE void	TkTextSetYView(TkText *textPtr,
			    TkTextIndex *indexPtr, int pickPlace);
MODULE_SCOPE int	TkTextTagCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextImageCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextImageIndex(TkText *textPtr,
			    const char *name, TkTextIndex *indexPtr);
MODULE_SCOPE int	TkTextWindowCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkTextWindowIndex(TkText *textPtr, const char *name,
			    TkTextIndex *indexPtr);
MODULE_SCOPE int	TkTextYviewCmd(TkText *textPtr, Tcl_Interp *interp,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE void	TkTextWinFreeClient(Tcl_HashEntry *hPtr,
			    TkTextEmbWindowClient *client);
MODULE_SCOPE void       TkTextRunAfterSyncCmd(void *clientData);

MODULE_SCOPE int        TkTextIndexAdjustToStartEnd(TkText *textPtr,
			    TkTextIndex *indexPtr, int err);
#endif /* _TKTEXT */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkTextBTree.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







/*
 * tkTextBTree.c --
 *
 *	This file contains code that manages the B-tree representation of text
 *	for Tk's text widget and implements character and toggle segment
 *	types.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkText.h"
40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+


















-
+







/*
 * The data structure below keeps summary information about one tag as part of
 * the tag information in a node.
 */

typedef struct Summary {
    TkTextTag *tagPtr;		/* Handle for tag. */
    Tcl_Size toggleCount;		/* Number of transitions into or out of this
    int toggleCount;		/* Number of transitions into or out of this
				 * tag that occur in the subtree rooted at
				 * this node. */
    struct Summary *nextPtr;	/* Next in list of all tags for same node, or
				 * NULL if at end of list. */
} Summary;

/*
 * The data structure below defines a node in the B-tree.
 */

typedef struct Node {
    struct Node *parentPtr;	/* Pointer to parent node, or NULL if this is
				 * the root. */
    struct Node *nextPtr;	/* Next in list of siblings with the same
				 * parent node, or NULL for end of list. */
    Summary *summaryPtr;	/* First in malloc-ed list of info about tags
				 * in this subtree (NULL if no tag info in the
				 * subtree). */
    Tcl_Size level;		/* Level of this node in the B-tree. 0 refers
    int level;			/* Level of this node in the B-tree. 0 refers
				 * to the bottom of the tree (children are
				 * lines, not nodes). */
    union {			/* First in linked list of children. */
	struct Node *nodePtr;	/* Used if level > 0. */
	TkTextLine *linePtr;	/* Used if level == 0. */
    } children;
    int numChildren;		/* Number of children of this node. */
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+







 */

typedef struct BTree {
    Node *rootPtr;		/* Pointer to root of B-tree. */
    int clients;		/* Number of clients of this B-tree. */
    int pixelReferences;	/* Number of clients of this B-tree which care
				 * about pixel heights. */
    Tcl_Size stateEpoch;	 /* Updated each time any aspect of the B-tree
    int stateEpoch;		/* Updated each time any aspect of the B-tree
				 * changes. */
    TkSharedText *sharedTextPtr;/* Used to find tagTable in consistency
				 * checking code, and to access list of all
				 * B-tree clients. */
    int startEndCount;
    TkTextLine **startEnd;
    TkText **startEndRef;
136
137
138
139
140
141
142
143
144
145
146




147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164

165
166
167
168
169
170
171
136
137
138
139
140
141
142




143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163

164
165
166
167
168
169
170
171







-
-
-
-
+
+
+
+










-
+






-
+








int tkBTreeDebug = 0;

/*
 * Macros that determine how much space to allocate for new segments:
 */

#define CSEG_SIZE(chars) (offsetof(TkTextSegment, body) \
	+ 1 + (chars))
#define TSEG_SIZE (offsetof(TkTextSegment, body) \
	+ sizeof(TkTextToggle))
#define CSEG_SIZE(chars) ((unsigned) (Tk_Offset(TkTextSegment, body) \
	+ 1 + (chars)))
#define TSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \
	+ sizeof(TkTextToggle)))

/*
 * Forward declarations for functions defined in this file:
 */

static int		AdjustPixelClient(BTree *treePtr, int defaultHeight,
			    Node *nodePtr, TkTextLine *start, TkTextLine *end,
			    int useReference, int newPixelReferences,
			    int *counting);
static void		ChangeNodeToggleCount(Node *nodePtr,
			    TkTextTag *tagPtr, Tcl_Size delta);
			    TkTextTag *tagPtr, int delta);
static void		CharCheckProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static int		CharDeleteProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr, int treeGone);
static TkTextSegment *	CharCleanupProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static TkTextSegment *	CharSplitProc(TkTextSegment *segPtr, Tcl_Size index);
static TkTextSegment *	CharSplitProc(TkTextSegment *segPtr, int index);
static void		CheckNodeConsistency(Node *nodePtr, int references);
static void		CleanupLine(TkTextLine *linePtr);
static void		DeleteSummaries(Summary *tagPtr);
static void		DestroyNode(Node *nodePtr);
static TkTextSegment *	FindTagEnd(TkTextBTree tree, TkTextTag *tagPtr,
			    TkTextIndex *indexPtr);
static void		IncCount(TkTextTag *tagPtr, int inc,
257
258
259
260
261
262
263
264
265
266
267




268
269
270
271
272
273
274
275
276
277
278



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
257
258
259
260
261
262
263




264
265
266
267
268
269
270
271
272
273
274
275



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324







-
-
-
-
+
+
+
+








-
-
-
+
+
+




















-
+









-
+







-
+







 *----------------------------------------------------------------------
 */

TkTextBTree
TkBTreeCreate(
    TkSharedText *sharedTextPtr)
{
    BTree *treePtr;
    Node *rootPtr;
    TkTextLine *linePtr, *linePtr2;
    TkTextSegment *segPtr;
    register BTree *treePtr;
    register Node *rootPtr;
    register TkTextLine *linePtr, *linePtr2;
    register TkTextSegment *segPtr;

    /*
     * The tree will initially have two empty lines. The second line isn't
     * actually part of the tree's contents, but its presence makes several
     * operations easier. The tree will have one node, which is also the root
     * of the tree.
     */

    rootPtr = (Node *)ckalloc(sizeof(Node));
    linePtr = (TkTextLine *)ckalloc(sizeof(TkTextLine));
    linePtr2 = (TkTextLine *)ckalloc(sizeof(TkTextLine));
    rootPtr = ckalloc(sizeof(Node));
    linePtr = ckalloc(sizeof(TkTextLine));
    linePtr2 = ckalloc(sizeof(TkTextLine));

    rootPtr->parentPtr = NULL;
    rootPtr->nextPtr = NULL;
    rootPtr->summaryPtr = NULL;
    rootPtr->level = 0;
    rootPtr->children.linePtr = linePtr;
    rootPtr->numChildren = 2;
    rootPtr->numLines = 2;

    /*
     * The tree currently has no registered clients, so all pixel count
     * pointers are simply NULL.
     */

    rootPtr->numPixels = NULL;
    linePtr->pixels = NULL;
    linePtr2->pixels = NULL;

    linePtr->parentPtr = rootPtr;
    linePtr->nextPtr = linePtr2;
    segPtr = (TkTextSegment *)ckalloc(CSEG_SIZE(1));
    segPtr = ckalloc(CSEG_SIZE(1));
    linePtr->segPtr = segPtr;
    segPtr->typePtr = &tkTextCharType;
    segPtr->nextPtr = NULL;
    segPtr->size = 1;
    segPtr->body.chars[0] = '\n';
    segPtr->body.chars[1] = 0;

    linePtr2->parentPtr = rootPtr;
    linePtr2->nextPtr = NULL;
    segPtr = (TkTextSegment *)ckalloc(CSEG_SIZE(1));
    segPtr = ckalloc(CSEG_SIZE(1));
    linePtr2->segPtr = segPtr;
    segPtr->typePtr = &tkTextCharType;
    segPtr->nextPtr = NULL;
    segPtr->size = 1;
    segPtr->body.chars[0] = '\n';
    segPtr->body.chars[1] = 0;

    treePtr = (BTree *)ckalloc(sizeof(BTree));
    treePtr = ckalloc(sizeof(BTree));
    treePtr->sharedTextPtr = sharedTextPtr;
    treePtr->rootPtr = rootPtr;
    treePtr->clients = 0;
    treePtr->stateEpoch = 0;
    treePtr->pixelReferences = 0;
    treePtr->startEndCount = 0;
    treePtr->startEnd = NULL;
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376







-
+







void
TkBTreeAddClient(
    TkTextBTree tree,		/* B-tree to add a client to. */
    TkText *textPtr,		/* Client to add. */
    int defaultHeight)		/* Default line height for the new client, or
				 * -1 if no pixel heights are to be kept. */
{
    BTree *treePtr = (BTree *) tree;
    register BTree *treePtr = (BTree *) tree;

    if (treePtr == NULL) {
	Tcl_Panic("NULL treePtr in TkBTreeAddClient");
    }

    if (textPtr->start != NULL || textPtr->end != NULL) {
	AdjustStartEndRefs(treePtr, textPtr, TEXT_ADD_REFS);
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511







-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tcl_Size
int
TkBTreeEpoch(
    TkTextBTree tree)		/* Tree to get epoch for. */
{
    BTree *treePtr = (BTree *) tree;
    return treePtr->stateEpoch;
}

610
611
612
613
614
615
616
617

618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639




640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

662
663

664
665
666
667
668
669
670
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634





635
636
637
638







639
640
641
642
643
644
645
646
647
648
649
650
651
652

653
654

655
656
657
658
659
660
661
662







-
+

















-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-














-
+

-
+







 *----------------------------------------------------------------------
 */

static void
AdjustStartEndRefs(
    BTree *treePtr,		/* The entire B-tree. */
    TkText *textPtr,		/* The text widget for which we want to adjust
				 * its start and end cache. */
				 * it's start and end cache. */
    int action)			/* Action to perform. */
{
    if (action & TEXT_REMOVE_REFS) {
	int i = 0;
	int count = 0;

	while (i < treePtr->startEndCount) {
	    if (i != count) {
		treePtr->startEnd[count] = treePtr->startEnd[i];
		treePtr->startEndRef[count] = treePtr->startEndRef[i];
	    }
	    if (treePtr->startEndRef[i] != textPtr) {
		count++;
	    }
	    i++;
	}
	treePtr->startEndCount = count;
	if (count > 0) {
	    treePtr->startEnd = (TkTextLine**)ckrealloc(treePtr->startEnd,
		    sizeof(TkTextLine*) * count);
	    treePtr->startEndRef = (TkText**)ckrealloc(treePtr->startEndRef,
		    sizeof(TkText*) * count);
	treePtr->startEnd = ckrealloc(treePtr->startEnd,
		sizeof(TkTextLine *) * count);
	treePtr->startEndRef = ckrealloc(treePtr->startEndRef,
		sizeof(TkText *) * count);
	}
	else {
	    ckfree(treePtr->startEndRef);
	    treePtr->startEndRef = NULL;
	    ckfree(treePtr->startEnd);
	    treePtr->startEnd = NULL;
	}
    }
    if ((action & TEXT_ADD_REFS)
	    && (textPtr->start != NULL || textPtr->end != NULL)) {
	int count;

	if (textPtr->start != NULL) {
	    treePtr->startEndCount++;
	}
	if (textPtr->end != NULL) {
	    treePtr->startEndCount++;
	}

	count = treePtr->startEndCount;

	treePtr->startEnd = (TkTextLine **)ckrealloc(treePtr->startEnd,
	treePtr->startEnd = ckrealloc(treePtr->startEnd,
		sizeof(TkTextLine *) * count);
	treePtr->startEndRef = (TkText **)ckrealloc(treePtr->startEndRef,
	treePtr->startEndRef = ckrealloc(treePtr->startEndRef,
		sizeof(TkText *) * count);

	if (textPtr->start != NULL) {
	    count--;
	    treePtr->startEnd[count] = textPtr->start;
	    treePtr->startEndRef[count] = textPtr;
	}
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744
745
746

747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754

755
756
757
758
759
760
761
762







-
+









-
+
















-
+








	while (loopPtr != NULL) {
	    pixelCount += AdjustPixelClient(treePtr, defaultHeight, loopPtr,
		    start, end, useReference, newPixelReferences, counting);
	    loopPtr = loopPtr->nextPtr;
	}
    } else {
	TkTextLine *linePtr = nodePtr->children.linePtr;
	register TkTextLine *linePtr = nodePtr->children.linePtr;

	while (linePtr != NULL) {
	    if (!*counting && (linePtr == start)) {
		*counting = 1;
	    }
	    if (*counting && (linePtr == end)) {
		*counting = 0;
	    }
	    if (newPixelReferences != treePtr->pixelReferences) {
		linePtr->pixels = (int *)ckrealloc(linePtr->pixels,
		linePtr->pixels = ckrealloc(linePtr->pixels,
			sizeof(int) * 2 * newPixelReferences);
	    }

	    /*
	     * Notice that for the very last line, we are never counting and
	     * therefore this always has a height of 0 and an epoch of 1.
	     */

	    linePtr->pixels[2*useReference] = (*counting ? defaultHeight : 0);
	    linePtr->pixels[2*useReference+1] = (*counting ? 0 : 1);
	    pixelCount += linePtr->pixels[2*useReference];

	    linePtr = linePtr->nextPtr;
	}
    }
    if (newPixelReferences != treePtr->pixelReferences) {
	nodePtr->numPixels = (int *)ckrealloc(nodePtr->numPixels,
	nodePtr->numPixels = ckrealloc(nodePtr->numPixels,
		sizeof(int) * newPixelReferences);
    }
    nodePtr->numPixels[useReference] = pixelCount;
    return pixelCount;
}

/*
803
804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823

824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
795
796
797
798
799
800
801

802
803

804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832







-


-
+









-
+










-
+







     */

    if (overwriteWithLast != -1) {
	nodePtr->numPixels[overwriteWithLast] =
		nodePtr->numPixels[treePtr->pixelReferences-1];
    }
    if (treePtr->pixelReferences == 1) {
	ckfree(nodePtr->numPixels);
	nodePtr->numPixels = NULL;
    } else {
	nodePtr->numPixels = (int *)ckrealloc(nodePtr->numPixels,
	nodePtr->numPixels = ckrealloc(nodePtr->numPixels,
		sizeof(int) * (treePtr->pixelReferences - 1));
    }
    if (nodePtr->level != 0) {
	nodePtr = nodePtr->children.nodePtr;
	while (nodePtr != NULL) {
	    RemovePixelClient(treePtr, nodePtr, overwriteWithLast);
	    nodePtr = nodePtr->nextPtr;
	}
    } else {
	TkTextLine *linePtr = nodePtr->children.linePtr;
	register TkTextLine *linePtr = nodePtr->children.linePtr;
	while (linePtr != NULL) {
	    if (overwriteWithLast != -1) {
		linePtr->pixels[2*overwriteWithLast] =
			linePtr->pixels[2*(treePtr->pixelReferences-1)];
		linePtr->pixels[1+2*overwriteWithLast] =
			linePtr->pixels[1+2*(treePtr->pixelReferences-1)];
	    }
	    if (treePtr->pixelReferences == 1) {
		linePtr->pixels = NULL;
	    } else {
		linePtr->pixels = (int *)ckrealloc(linePtr->pixels,
		linePtr->pixels = ckrealloc(linePtr->pixels,
			sizeof(int) * 2 * (treePtr->pixelReferences-1));
	    }
	    linePtr = linePtr->nextPtr;
	}
    }
}

854
855
856
857
858
859
860
861

862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
845
846
847
848
849
850
851

852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869

870
871
872
873
874
875
876
877







-
+

















-
+







 *	All the storage for nodePtr and its descendants is freed.
 *
 *----------------------------------------------------------------------
 */

static void
DestroyNode(
    Node *nodePtr)	/* Destroy from this node downwards. */
    register Node *nodePtr)	/* Destroy from this node downwards. */
{
    if (nodePtr->level == 0) {
	TkTextLine *linePtr;
	TkTextSegment *segPtr;

	while (nodePtr->children.linePtr != NULL) {
	    linePtr = nodePtr->children.linePtr;
	    nodePtr->children.linePtr = linePtr->nextPtr;
	    while (linePtr->segPtr != NULL) {
		segPtr = linePtr->segPtr;
		linePtr->segPtr = segPtr->nextPtr;
		segPtr->typePtr->deleteProc(segPtr, linePtr, 1);
	    }
	    ckfree(linePtr->pixels);
	    ckfree(linePtr);
	}
    } else {
	Node *childPtr;
	register Node *childPtr;

	while (nodePtr->children.nodePtr != NULL) {
	    childPtr = nodePtr->children.nodePtr;
	    nodePtr->children.nodePtr = childPtr->nextPtr;
	    DestroyNode(childPtr);
	}
    }
904
905
906
907
908
909
910
911

912
913
914

915
916
917
918
919
920
921
895
896
897
898
899
900
901

902
903
904

905
906
907
908
909
910
911
912







-
+


-
+







 *	Storage is released.
 *
 *----------------------------------------------------------------------
 */

static void
DeleteSummaries(
    Summary *summaryPtr)
    register Summary *summaryPtr)
				/* First in list of node's tag summaries. */
{
    Summary *nextPtr;
    register Summary *nextPtr;

    while (summaryPtr != NULL) {
	nextPtr = summaryPtr->nextPtr;
	ckfree(summaryPtr);
	summaryPtr = nextPtr;
    }
}
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960
927
928
929
930
931
932
933

934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951







-
+









-
+







 *
 *----------------------------------------------------------------------
 */

int
TkBTreeAdjustPixelHeight(
    const TkText *textPtr,	/* Client of the B-tree. */
    TkTextLine *linePtr,
    register TkTextLine *linePtr,
				/* The logical line to update. */
    int newPixelHeight,		/* The line's known height in pixels. */
    int mergedLogicalLines)	/* The number of extra logical lines which
				 * have been merged with this one (due to
				 * elided eols). They will have their pixel
				 * height set to zero, and the total pixel
				 * height associated with the given
				 * linePtr. */
{
    Node *nodePtr;
    register Node *nodePtr;
    int changeToPixelCount;	/* Counts change to total number of pixels in
				 * file. */
    int pixelReference = textPtr->pixelReference;

    changeToPixelCount = newPixelHeight - linePtr->pixels[2 * pixelReference];

    /*
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020
1021


1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033


1034
1035
1036
1037
1038
1039
1040
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010


1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022


1023
1024
1025
1026
1027
1028
1029
1030
1031







-
+







-
-
+
+








-
+

-
-
+
+







 *
 *----------------------------------------------------------------------
 */

void
TkBTreeInsertChars(
    TkTextBTree tree,		/* Tree to insert into. */
    TkTextIndex *indexPtr,
    register TkTextIndex *indexPtr,
				/* Indicates where to insert text. When the
				 * function returns, this index is no longer
				 * valid because of changes to the segment
				 * structure. */
    const char *string)		/* Pointer to bytes to insert (may contain
				 * newlines, must be null-terminated). */
{
    Node *nodePtr;
    TkTextSegment *prevPtr;
    register Node *nodePtr;
    register TkTextSegment *prevPtr;
				/* The segment just before the first new
				 * segment (NULL means new segment is at
				 * beginning of line). */
    TkTextSegment *curPtr;	/* Current segment; new characters are
				 * inserted just after this one. NULL means
				 * insert at beginning of line. */
    TkTextLine *linePtr;	/* Current line (new segments are added to
				 * this line). */
    TkTextSegment *segPtr;
    register TkTextSegment *segPtr;
    TkTextLine *newLinePtr;
    size_t chunkSize;		/* # characters in current chunk. */
    const char *eol;	/* Pointer to character just after last one in
    int chunkSize;		/* # characters in current chunk. */
    register const char *eol;	/* Pointer to character just after last one in
				 * current chunk. */
    int changeToLineCount;	/* Counts change to total number of lines in
				 * file. */
    int *changeToPixelCount;	/* Counts change to total number of pixels in
				 * file. */
    int ref;
    int pixels[PIXEL_CLIENTS];
1048
1049
1050
1051
1052
1053
1054
1055

1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094


1095
1096
1097
1098
1099
1100
1101
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083


1084
1085
1086
1087
1088
1089
1090
1091
1092







-
+















-
+









-
+











-
-
+
+







    /*
     * Chop the string up into lines and create a new segment for each line,
     * plus a new line for the leftovers from the previous line.
     */

    changeToLineCount = 0;
    if (treePtr->pixelReferences > PIXEL_CLIENTS) {
	changeToPixelCount = (int *)ckalloc(sizeof(int) * treePtr->pixelReferences);
	changeToPixelCount = ckalloc(sizeof(int) * treePtr->pixelReferences);
    } else {
	changeToPixelCount = pixels;
    }
    for (ref = 0; ref < treePtr->pixelReferences; ref++) {
	changeToPixelCount[ref] = 0;
    }

    while (*string != 0) {
	for (eol = string; *eol != 0; eol++) {
	    if (*eol == '\n') {
		eol++;
		break;
	    }
	}
	chunkSize = eol-string;
	segPtr = (TkTextSegment *)ckalloc(CSEG_SIZE(chunkSize));
	segPtr = ckalloc(CSEG_SIZE(chunkSize));
	segPtr->typePtr = &tkTextCharType;
	if (curPtr == NULL) {
	    segPtr->nextPtr = linePtr->segPtr;
	    linePtr->segPtr = segPtr;
	} else {
	    segPtr->nextPtr = curPtr->nextPtr;
	    curPtr->nextPtr = segPtr;
	}
	segPtr->size = chunkSize;
	memcpy(segPtr->body.chars, string, chunkSize);
	memcpy(segPtr->body.chars, string, (size_t) chunkSize);
	segPtr->body.chars[chunkSize] = 0;

	if (eol[-1] != '\n') {
	    break;
	}

	/*
	 * The chunk ended with a newline, so create a new TkTextLine and move
	 * the remainder of the old line to it.
	 */

	newLinePtr = (TkTextLine *)ckalloc(sizeof(TkTextLine));
	newLinePtr->pixels = (int *)
	newLinePtr = ckalloc(sizeof(TkTextLine));
	newLinePtr->pixels =
		ckalloc(sizeof(int) * 2 * treePtr->pixelReferences);

	newLinePtr->parentPtr = linePtr->parentPtr;
	newLinePtr->nextPtr = linePtr->nextPtr;
	linePtr->nextPtr = newLinePtr;
	newLinePtr->segPtr = segPtr->nextPtr;

1194
1195
1196
1197
1198
1199
1200
1201

1202
1203
1204
1205
1206
1207
1208
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199







-
+







static TkTextSegment *
SplitSeg(
    TkTextIndex *indexPtr)	/* Index identifying position at which to
				 * split a segment. */
{
    TkTextSegment *prevPtr, *segPtr;
    TkTextLine *linePtr;
    Tcl_Size count = indexPtr->byteIndex;
    int count = indexPtr->byteIndex;

    linePtr = indexPtr->linePtr;
    prevPtr = NULL;
    segPtr = linePtr->segPtr;

    while (segPtr != NULL) {
	if (segPtr->size > count) {
1316
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326

1327
1328
1329
1330
1331
1332
1333
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316

1317
1318
1319
1320
1321
1322
1323
1324







-
+


-
+







 *
 *----------------------------------------------------------------------
 */

void
TkBTreeDeleteIndexRange(
    TkTextBTree tree,		/* Tree to delete from. */
    TkTextIndex *index1Ptr,
    register TkTextIndex *index1Ptr,
				/* Indicates first character that is to be
				 * deleted. */
    TkTextIndex *index2Ptr)
    register TkTextIndex *index2Ptr)
				/* Indicates character just after the last one
				 * that is to be deleted. */
{
    TkTextSegment *prevPtr;	/* The segment just before the start of the
				 * deletion range. */
    TkTextSegment *lastPtr;	/* The segment just after the end of the
				 * deletion range. */
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1435
1436
1437
1438
1439
1440
1441

1442
1443
1444
1445
1446
1447
1448







-







		    Node *prevNodePtr = parentPtr->children.nodePtr;
		    while (prevNodePtr->nextPtr != curNodePtr) {
			prevNodePtr = prevNodePtr->nextPtr;
		    }
		    prevNodePtr->nextPtr = curNodePtr->nextPtr;
		}
		parentPtr->numChildren--;
		DeleteSummaries(curNodePtr->summaryPtr);
		ckfree(curNodePtr->numPixels);
		ckfree(curNodePtr);
		curNodePtr = parentPtr;
	    }
	    curNodePtr = curLinePtr->parentPtr;
	    continue;
	}
1600
1601
1602
1603
1604
1605
1606
1607
1608


1609
1610
1611
1612
1613
1614
1615
1590
1591
1592
1593
1594
1595
1596


1597
1598
1599
1600
1601
1602
1603
1604
1605







-
-
+
+







TkTextLine *
TkBTreeFindLine(
    TkTextBTree tree,		/* B-tree in which to find line. */
    const TkText *textPtr,	/* Relative to this client of the B-tree. */
    int line)			/* Index of desired line. */
{
    BTree *treePtr = (BTree *) tree;
    Node *nodePtr;
    TkTextLine *linePtr;
    register Node *nodePtr;
    register TkTextLine *linePtr;

    if (treePtr == NULL) {
	treePtr = (BTree *) textPtr->sharedTextPtr->tree;
    }

    nodePtr = treePtr->rootPtr;
    if ((line < 0) || (line >= nodePtr->numLines)) {
1690
1691
1692
1693
1694
1695
1696
1697
1698


1699
1700
1701
1702
1703
1704
1705
1680
1681
1682
1683
1684
1685
1686


1687
1688
1689
1690
1691
1692
1693
1694
1695







-
-
+
+







TkBTreeFindPixelLine(
    TkTextBTree tree,		/* B-tree to use. */
    const TkText *textPtr,	/* Relative to this client of the B-tree. */
    int pixels,			/* Pixel index of desired line. */
    int *pixelOffset)		/* Used to return offset. */
{
    BTree *treePtr = (BTree *) tree;
    Node *nodePtr;
    TkTextLine *linePtr;
    register Node *nodePtr;
    register TkTextLine *linePtr;
    int pixelReference = textPtr->pixelReference;

    nodePtr = treePtr->rootPtr;

    if ((pixels < 0) || (pixels > nodePtr->numPixels[pixelReference])) {
	return NULL;
    }
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
1721
1722
1723
1724
1725
1726
1727




















1728
1729
1730
1731
1732
1733
1734







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    linePtr->pixels[2 * pixelReference] < pixels;
	    linePtr = linePtr->nextPtr) {
	if (linePtr == NULL) {
	    Tcl_Panic("TkBTreeFindPixelLine ran out of lines");
	}
	pixels -= linePtr->pixels[2 * pixelReference];
    }

    /*
     * Check for any start/end offset for this text widget.
     */

    if (textPtr->start != NULL) {
	int lineBoundary = TkBTreeLinesTo(NULL, textPtr->start);

	if (TkBTreeLinesTo(NULL, linePtr) < lineBoundary) {
	    linePtr = TkBTreeFindLine(tree, NULL, lineBoundary);
	}
    }
    if (textPtr->end != NULL) {
	int lineBoundary = TkBTreeLinesTo(NULL, textPtr->end);

	if (TkBTreeLinesTo(NULL, linePtr) > lineBoundary) {
	    linePtr = TkBTreeFindLine(tree, NULL, lineBoundary);
	}
    }

    if (pixelOffset != NULL && linePtr != NULL) {
	*pixelOffset = pixels;
    }
    return linePtr;
}

/*
1779
1780
1781
1782
1783
1784
1785
1786

1787
1788
1789

1790
1791
1792
1793
1794
1795
1796
1749
1750
1751
1752
1753
1754
1755

1756
1757
1758

1759
1760
1761
1762
1763
1764
1765
1766







-
+


-
+







 *
 *----------------------------------------------------------------------
 */

TkTextLine *
TkBTreeNextLine(
    const TkText *textPtr,	/* Next line in the context of this client. */
    TkTextLine *linePtr)
    register TkTextLine *linePtr)
				/* Pointer to existing line in B-tree. */
{
    Node *nodePtr;
    register Node *nodePtr;

    if (linePtr->nextPtr != NULL) {
	if (textPtr != NULL && (linePtr == textPtr->end)) {
	    return NULL;
	} else {
	    return linePtr->nextPtr;
	}
1835
1836
1837
1838
1839
1840
1841
1842

1843
1844
1845
1846
1847



1848
1849
1850
1851
1852
1853
1854
1805
1806
1807
1808
1809
1810
1811

1812
1813
1814



1815
1816
1817
1818
1819
1820
1821
1822
1823
1824







-
+


-
-
-
+
+
+







 *
 *----------------------------------------------------------------------
 */

TkTextLine *
TkBTreePreviousLine(
    TkText *textPtr,		/* Relative to this client of the B-tree. */
    TkTextLine *linePtr)
    register TkTextLine *linePtr)
				/* Pointer to existing line in B-tree. */
{
    Node *nodePtr;
    Node *node2Ptr;
    TkTextLine *prevPtr;
    register Node *nodePtr;
    register Node *node2Ptr;
    register TkTextLine *prevPtr;

    if (textPtr != NULL && textPtr->start == linePtr) {
	return NULL;
    }

    /*
     * Find the line under this node just before the starting line.
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
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







-
+
















-
-
+
+







 * TkBTreePixelsTo --
 *
 *	Given a pointer to a line in a B-tree, return the numerical pixel
 *	index of the top of that line (i.e. the result does not include the
 *	height of the given line).
 *
 *	Since the last line of text (the artificial one) has zero height by
 *	definition, calling this with the last line will return the total
 *	defintion, calling this with the last line will return the total
 *	number of pixels in the widget.
 *
 * Results:
 *	The result is the pixel height of the top of the given line.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkBTreePixelsTo(
    const TkText *textPtr,	/* Relative to this client of the B-tree. */
    TkTextLine *linePtr)	/* Pointer to existing line in B-tree. */
{
    TkTextLine *linePtr2;
    Node *nodePtr, *parentPtr;
    register TkTextLine *linePtr2;
    register Node *nodePtr, *parentPtr;
    int index;
    int pixelReference = textPtr->pixelReference;

    /*
     * First count how many pixels precede this line in its level-0 node.
     */

1945
1946
1947
1948
1949
1950
1951
1952

1953
1954
1955
1956
1957
1958
1959
1915
1916
1917
1918
1919
1920
1921

1922
1923
1924
1925
1926
1927
1928
1929







-
+







    /*
     * Now work up through the levels of the tree one at a time, counting how
     * many pixels are in nodes preceding the current node.
     */

    for (parentPtr = nodePtr->parentPtr ; parentPtr != NULL;
	    nodePtr = parentPtr, parentPtr = parentPtr->parentPtr) {
	Node *nodePtr2;
	register Node *nodePtr2;

	for (nodePtr2 = parentPtr->children.nodePtr; nodePtr2 != nodePtr;
		nodePtr2 = nodePtr2->nextPtr) {
	    if (nodePtr2 == NULL) {
		Tcl_Panic("TkBTreePixelsTo couldn't find node");
	    }
	    index += nodePtr2->numPixels[pixelReference];
1981
1982
1983
1984
1985
1986
1987
1988
1989


1990
1991
1992
1993
1994
1995
1996
1951
1952
1953
1954
1955
1956
1957


1958
1959
1960
1961
1962
1963
1964
1965
1966







-
-
+
+







 */

int
TkBTreeLinesTo(
    const TkText *textPtr,	/* Relative to this client of the B-tree. */
    TkTextLine *linePtr)	/* Pointer to existing line in B-tree. */
{
    TkTextLine *linePtr2;
    Node *nodePtr, *parentPtr, *nodePtr2;
    register TkTextLine *linePtr2;
    register Node *nodePtr, *parentPtr, *nodePtr2;
    int index;

    /*
     * First count how many lines precede this one in its level-0 node.
     */

    nodePtr = linePtr->parentPtr;
2061
2062
2063
2064
2065
2066
2067

2068
2069
2070
2071
2072
2073
2074
2075
2076

2077
2078
2079
2080
2081
2082
2083
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046

2047
2048
2049
2050
2051
2052
2053
2054







+








-
+







 *
 * Side effects:
 *	SegPtr will be linked into its tree.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
void
TkBTreeLinkSegment(
    TkTextSegment *segPtr,	/* Pointer to new segment to be added to
				 * B-tree. Should be completely initialized by
				 * caller except for nextPtr field. */
    TkTextIndex *indexPtr)	/* Where to add segment: it gets linked in
				 * just before the segment indicated here. */
{
    TkTextSegment *prevPtr;
    register TkTextSegment *prevPtr;

    prevPtr = SplitSeg(indexPtr);
    if (prevPtr == NULL) {
	segPtr->nextPtr = indexPtr->linePtr->segPtr;
	indexPtr->linePtr->segPtr = segPtr;
    } else {
	segPtr->nextPtr = prevPtr->nextPtr;
2103
2104
2105
2106
2107
2108
2109

2110
2111
2112
2113
2114
2115

2116
2117
2118
2119
2120
2121
2122
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086

2087
2088
2089
2090
2091
2092
2093
2094







+





-
+







 * Side effects:
 *	SegPtr will be unlinked from linePtr. The segment itself isn't
 *	modified by this function.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
void
TkBTreeUnlinkSegment(
    TkTextSegment *segPtr,	/* Segment to be unlinked. */
    TkTextLine *linePtr)	/* Line that currently contains segment. */
{
    TkTextSegment *prevPtr;
    register TkTextSegment *prevPtr;

    if (linePtr->segPtr == segPtr) {
	linePtr->segPtr = segPtr->nextPtr;
    } else {
	prevPtr = linePtr->segPtr;
	while (prevPtr->nextPtr != segPtr) {
	    prevPtr = prevPtr->nextPtr;
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
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







-
+

-
+



















-
+







 *	indexes may be modified by this function.
 *
 *----------------------------------------------------------------------
 */

int
TkBTreeTag(
    TkTextIndex *index1Ptr,
    register TkTextIndex *index1Ptr,
				/* Indicates first character in range. */
    TkTextIndex *index2Ptr,
    register TkTextIndex *index2Ptr,
				/* Indicates character just after the last one
				 * in range. */
    TkTextTag *tagPtr,		/* Tag to add or remove. */
    int add)			/* One means add tag to the given range of
				 * characters; zero means remove the tag from
				 * the range. */
{
    TkTextSegment *segPtr, *prevPtr;
    TkTextSearch search;
    TkTextLine *cleanupLinePtr;
    int oldState, changed, anyChanges = 0;

    /*
     * See whether the tag is present at the start of the range. If the state
     * doesn't already match what we want then add a toggle there.
     */

    oldState = TkBTreeCharTagged(index1Ptr, tagPtr);
    if ((add != 0) ^ oldState) {
	segPtr = (TkTextSegment *)ckalloc(TSEG_SIZE);
	segPtr = ckalloc(TSEG_SIZE);
	segPtr->typePtr = (add) ? &tkTextToggleOnType : &tkTextToggleOffType;
	prevPtr = SplitSeg(index1Ptr);
	if (prevPtr == NULL) {
	    segPtr->nextPtr = index1Ptr->linePtr->segPtr;
	    index1Ptr->linePtr->segPtr = segPtr;
	} else {
	    segPtr->nextPtr = prevPtr->nextPtr;
2250
2251
2252
2253
2254
2255
2256
2257

2258
2259
2260
2261
2262
2263
2264
2222
2223
2224
2225
2226
2227
2228

2229
2230
2231
2232
2233
2234
2235
2236







-
+







	 */

	if (changed) {
	    TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, &search);
	}
    }
    if ((add != 0) ^ oldState) {
	segPtr = (TkTextSegment *)ckalloc(TSEG_SIZE);
	segPtr = ckalloc(TSEG_SIZE);
	segPtr->typePtr = (add) ? &tkTextToggleOffType : &tkTextToggleOnType;
	prevPtr = SplitSeg(index2Ptr);
	if (prevPtr == NULL) {
	    segPtr->nextPtr = index2Ptr->linePtr->segPtr;
	    index2Ptr->linePtr->segPtr = segPtr;
	} else {
	    segPtr->nextPtr = prevPtr->nextPtr;
2307
2308
2309
2310
2311
2312
2313
2314

2315
2316
2317

2318
2319
2320
2321
2322



2323
2324
2325
2326
2327
2328
2329
2279
2280
2281
2282
2283
2284
2285

2286
2287
2288

2289
2290
2291



2292
2293
2294
2295
2296
2297
2298
2299
2300
2301







-
+


-
+


-
-
-
+
+
+







 *	for the tag, moving it up or down the tree as needed.
 *
 *----------------------------------------------------------------------
 */

static void
ChangeNodeToggleCount(
    Node *nodePtr,	/* Node whose toggle count for a tag must be
    register Node *nodePtr,	/* Node whose toggle count for a tag must be
				 * changed. */
    TkTextTag *tagPtr,		/* Information about tag. */
    Tcl_Size delta)			/* Amount to add to current toggle count for
    int delta)			/* Amount to add to current toggle count for
				 * tag (may be negative). */
{
    Summary *summaryPtr, *prevPtr;
    Node *node2Ptr;
    Tcl_Size rootLevel;	/* Level of original tag root. */
    register Summary *summaryPtr, *prevPtr;
    register Node *node2Ptr;
    int rootLevel;		/* Level of original tag root. */

    tagPtr->toggleCount += delta;
    if (tagPtr->tagRootPtr == NULL) {
	tagPtr->tagRootPtr = nodePtr;
	return;
    }

2362
2363
2364
2365
2366
2367
2368
2369

2370
2371
2372
2373
2374
2375
2376
2334
2335
2336
2337
2338
2339
2340

2341
2342
2343
2344
2345
2346
2347
2348







-
+







	    if (summaryPtr->toggleCount != 0) {
		/*
		 * Should never find a node with max toggle count at this
		 * point (there shouldn't have been a summary entry in the
		 * first place).
		 */

		Tcl_Panic("ChangeNodeToggleCount: bad toggle count (%" TCL_SIZE_MODIFIER "d) max (%" TCL_SIZE_MODIFIER "d)",
		Tcl_Panic("ChangeNodeToggleCount: bad toggle count (%d) max (%d)",
		    summaryPtr->toggleCount, tagPtr->toggleCount);
	    }

	    /*
	     * Zero toggle count; must remove this tag from the list.
	     */

2394
2395
2396
2397
2398
2399
2400
2401

2402
2403
2404
2405
2406
2407
2408
2409
2410

2411
2412
2413
2414
2415
2416
2417
2366
2367
2368
2369
2370
2371
2372

2373
2374
2375
2376
2377
2378
2379
2380
2381

2382
2383
2384
2385
2386
2387
2388
2389







-
+








-
+







		 * next time through the loop). To push it up one level we
		 * copy the original toggle count into the summary information
		 * at the old root and change the root to its parent node.
		 */

		Node *rootNodePtr = tagPtr->tagRootPtr;

		summaryPtr = (Summary *)ckalloc(sizeof(Summary));
		summaryPtr = ckalloc(sizeof(Summary));
		summaryPtr->tagPtr = tagPtr;
		summaryPtr->toggleCount = tagPtr->toggleCount - delta;
		summaryPtr->nextPtr = rootNodePtr->summaryPtr;
		rootNodePtr->summaryPtr = summaryPtr;
		rootNodePtr = rootNodePtr->parentPtr;
		rootLevel = rootNodePtr->level;
		tagPtr->tagRootPtr = rootNodePtr;
	    }
	    summaryPtr = (Summary *)ckalloc(sizeof(Summary));
	    summaryPtr = ckalloc(sizeof(Summary));
	    summaryPtr->tagPtr = tagPtr;
	    summaryPtr->toggleCount = delta;
	    summaryPtr->nextPtr = nodePtr->summaryPtr;
	    nodePtr->summaryPtr = summaryPtr;
	}
    }

2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503




2504
2505
2506
2507
2508
2509
2510
2465
2466
2467
2468
2469
2470
2471




2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482







-
-
-
-
+
+
+
+








static TkTextSegment *
FindTagStart(
    TkTextBTree tree,		/* Tree to search within. */
    TkTextTag *tagPtr,		/* Tag to search for. */
    TkTextIndex *indexPtr)	/* Return - index information. */
{
    Node *nodePtr;
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    Summary *summaryPtr;
    register Node *nodePtr;
    register TkTextLine *linePtr;
    register TkTextSegment *segPtr;
    register Summary *summaryPtr;
    int offset;

    nodePtr = tagPtr->tagRootPtr;
    if (nodePtr == NULL) {
	return NULL;
    }

2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588




2589
2590
2591
2592
2593
2594
2595
2550
2551
2552
2553
2554
2555
2556




2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567







-
-
-
-
+
+
+
+








static TkTextSegment *
FindTagEnd(
    TkTextBTree tree,		/* Tree to search within. */
    TkTextTag *tagPtr,		/* Tag to search for. */
    TkTextIndex *indexPtr)	/* Return - index information. */
{
    Node *nodePtr, *lastNodePtr;
    TkTextLine *linePtr ,*lastLinePtr;
    TkTextSegment *segPtr, *lastSegPtr, *last2SegPtr;
    Summary *summaryPtr;
    register Node *nodePtr, *lastNodePtr;
    register TkTextLine *linePtr ,*lastLinePtr;
    register TkTextSegment *segPtr, *lastSegPtr, *last2SegPtr;
    register Summary *summaryPtr;
    int lastoffset, lastoffset2, offset;

    nodePtr = tagPtr->tagRootPtr;
    if (nodePtr == NULL) {
	return NULL;
    }

2674
2675
2676
2677
2678
2679
2680
2681

2682
2683
2684
2685

2686
2687
2688
2689
2690
2691
2692
2646
2647
2648
2649
2650
2651
2652

2653
2654
2655
2656

2657
2658
2659
2660
2661
2662
2663
2664







-
+



-
+







TkBTreeStartSearch(
    TkTextIndex *index1Ptr,	/* Search starts here. Tag toggles at this
				 * position will not be returned. */
    TkTextIndex *index2Ptr,	/* Search stops here. Tag toggles at this
				 * position *will* be returned. */
    TkTextTag *tagPtr,		/* Tag to search for. NULL means search for
				 * any tag. */
    TkTextSearch *searchPtr)
    register TkTextSearch *searchPtr)
				/* Where to store information about search's
				 * progress. */
{
    Tcl_Size offset;
    int offset;
    TkTextIndex index0;		/* First index of the tag. */
    TkTextSegment *seg0Ptr;	/* First segment of the tag. */

    /*
     * Find the segment that contains the first toggle for the tag. This may
     * become the starting point in the search.
     */
2770
2771
2772
2773
2774
2775
2776
2777

2778
2779
2780
2781

2782
2783
2784
2785
2786
2787
2788
2742
2743
2744
2745
2746
2747
2748

2749
2750
2751
2752

2753
2754
2755
2756
2757
2758
2759
2760







-
+



-
+







TkBTreeStartSearchBack(
    TkTextIndex *index1Ptr,	/* Search starts here. Tag toggles at this
				 * position will not be returned. */
    TkTextIndex *index2Ptr,	/* Search stops here. Tag toggles at this
				 * position *will* be returned. */
    TkTextTag *tagPtr,		/* Tag to search for. NULL means search for
				 * any tag. */
    TkTextSearch *searchPtr)
    register TkTextSearch *searchPtr)
				/* Where to store information about search's
				 * progress. */
{
    Tcl_Size offset;
    int offset;
    TkTextIndex index0;		/* Last index of the tag. */
    TkTextIndex backOne;	/* One character before starting index. */
    TkTextSegment *seg0Ptr;	/* Last segment of the tag. */

    /*
     * Find the segment that contains the last toggle for the tag. This may
     * become the starting point in the search.
2871
2872
2873
2874
2875
2876
2877
2878

2879
2880
2881
2882
2883
2884
2885



2886
2887
2888
2889
2890
2891
2892
2843
2844
2845
2846
2847
2848
2849

2850
2851
2852
2853
2854



2855
2856
2857
2858
2859
2860
2861
2862
2863
2864







-
+




-
-
-
+
+
+







 *	search and indicate where the next tag toggle is located.
 *
 *----------------------------------------------------------------------
 */

int
TkBTreeNextTag(
    TkTextSearch *searchPtr)
    register TkTextSearch *searchPtr)
				/* Information about search in progress; must
				 * have been set up by call to
				 * TkBTreeStartSearch. */
{
    TkTextSegment *segPtr;
    Node *nodePtr;
    Summary *summaryPtr;
    register TkTextSegment *segPtr;
    register Node *nodePtr;
    register Summary *summaryPtr;

    if (searchPtr->linesLeft <= 0) {
	goto searchOver;
    }

    /*
     * The outermost loop iterates over lines that may potentially contain a
3036
3037
3038
3039
3040
3041
3042
3043

3044
3045
3046
3047
3048
3049
3050
3051




3052
3053
3054
3055
3056
3057
3058
3008
3009
3010
3011
3012
3013
3014

3015
3016
3017
3018
3019




3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030







-
+




-
-
-
-
+
+
+
+







 *	search and indicate where the next tag toggle is located.
 *
 *----------------------------------------------------------------------
 */

int
TkBTreePrevTag(
    TkTextSearch *searchPtr)
    register TkTextSearch *searchPtr)
				/* Information about search in progress; must
				 * have been set up by call to
				 * TkBTreeStartSearch. */
{
    TkTextSegment *segPtr, *prevPtr;
    TkTextLine *linePtr, *prevLinePtr;
    Node *nodePtr, *node2Ptr, *prevNodePtr;
    Summary *summaryPtr;
    register TkTextSegment *segPtr, *prevPtr;
    register TkTextLine *linePtr, *prevLinePtr;
    register Node *nodePtr, *node2Ptr, *prevNodePtr;
    register Summary *summaryPtr;
    int byteIndex, linesSkipped;
    int pastLast;		/* Saw last marker during scan. */

    if (searchPtr->linesLeft <= 0) {
	goto searchOver;
    }

3254
3255
3256
3257
3258
3259
3260
3261
3262
3263



3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275

3276
3277
3278
3279
3280
3281
3282
3226
3227
3228
3229
3230
3231
3232



3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246

3247
3248
3249
3250
3251
3252
3253
3254







-
-
-
+
+
+











-
+








int
TkBTreeCharTagged(
    const TkTextIndex *indexPtr,/* Indicates a character position at which to
				 * check for a tag. */
    TkTextTag *tagPtr)		/* Tag of interest. */
{
    Node *nodePtr;
    TkTextLine *siblingLinePtr;
    TkTextSegment *segPtr;
    register Node *nodePtr;
    register TkTextLine *siblingLinePtr;
    register TkTextSegment *segPtr;
    TkTextSegment *toggleSegPtr;
    int toggles, index;

    /*
     * Check for toggles for the tag in indexPtr's line but before indexPtr.
     * If there is one, its type indicates whether or not the character is
     * tagged.
     */

    toggleSegPtr = NULL;
    for (index = 0, segPtr = indexPtr->linePtr->segPtr;
	    (index + (int)segPtr->size) <= indexPtr->byteIndex;
	    (index + segPtr->size) <= indexPtr->byteIndex;
	    index += segPtr->size, segPtr = segPtr->nextPtr) {
	if (((segPtr->typePtr == &tkTextToggleOnType)
		|| (segPtr->typePtr == &tkTextToggleOffType))
		&& (segPtr->body.toggle.tagPtr == tagPtr)) {
	    toggleSegPtr = segPtr;
	}
    }
3310
3311
3312
3313
3314
3315
3316
3317
3318


3319
3320
3321
3322
3323
3324
3325
3282
3283
3284
3285
3286
3287
3288


3289
3290
3291
3292
3293
3294
3295
3296
3297







-
-
+
+







     * node, counting the number of toggles of the given tag in siblings that
     * precede that node.
     */

    toggles = 0;
    for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL;
	    nodePtr = nodePtr->parentPtr) {
	Node *siblingPtr;
	Summary *summaryPtr;
	register Node *siblingPtr;
	register Summary *summaryPtr;

	for (siblingPtr = nodePtr->parentPtr->children.nodePtr;
		siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) {
	    for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL;
		    summaryPtr = summaryPtr->nextPtr) {
		if (summaryPtr->tagPtr == tagPtr) {
		    toggles += summaryPtr->toggleCount;
3358
3359
3360
3361
3362
3363
3364

3365
3366
3367
3368
3369
3370
3371
3372

3373
3374
3375
3376
3377



3378
3379
3380
3381
3382
3383
3384
3385
3386


3387
3388
3389
3390
3391
3392
3393
3394
3395

3396
3397
3398
3399
3400
3401
3402
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344

3345
3346
3347



3348
3349
3350
3351
3352
3353
3354
3355
3356
3357


3358
3359
3360
3361
3362
3363
3364
3365
3366
3367

3368
3369
3370
3371
3372
3373
3374
3375







+







-
+


-
-
-
+
+
+







-
-
+
+








-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
TkTextTag **
TkBTreeGetTags(
    const TkTextIndex *indexPtr,/* Indicates a particular position in the
				 * B-tree. */
    const TkText *textPtr,	/* If non-NULL, then only return tags for this
				 * text widget (when there are peer
				 * widgets). */
    Tcl_Size *numTagsPtr)		/* Store number of tags found at this
    int *numTagsPtr)		/* Store number of tags found at this
				 * location. */
{
    Node *nodePtr;
    TkTextLine *siblingLinePtr;
    TkTextSegment *segPtr;
    register Node *nodePtr;
    register TkTextLine *siblingLinePtr;
    register TkTextSegment *segPtr;
    TkTextLine *linePtr;
    int src, dst, index;
    TagInfo tagInfo;
#define NUM_TAG_INFOS 10

    tagInfo.numTags = 0;
    tagInfo.arraySize = NUM_TAG_INFOS;
    tagInfo.tagPtrs = (TkTextTag **)ckalloc(NUM_TAG_INFOS * sizeof(TkTextTag *));
    tagInfo.counts = (int *)ckalloc(NUM_TAG_INFOS * sizeof(int));
    tagInfo.tagPtrs = ckalloc(NUM_TAG_INFOS * sizeof(TkTextTag *));
    tagInfo.counts = ckalloc(NUM_TAG_INFOS * sizeof(int));

    /*
     * Record tag toggles within the line of indexPtr but preceding indexPtr.
     */

    linePtr = indexPtr->linePtr;
    index = 0;
    segPtr = linePtr->segPtr;
    while ((index + (int)segPtr->size) <= indexPtr->byteIndex) {
    while ((index + segPtr->size) <= indexPtr->byteIndex) {
	if ((segPtr->typePtr == &tkTextToggleOnType)
		|| (segPtr->typePtr == &tkTextToggleOffType)) {
	    IncCount(segPtr->body.toggle.tagPtr, 1, &tagInfo);
	}
	index += segPtr->size;
	segPtr = segPtr->nextPtr;

3431
3432
3433
3434
3435
3436
3437
3438
3439


3440
3441
3442
3443
3444
3445
3446
3404
3405
3406
3407
3408
3409
3410


3411
3412
3413
3414
3415
3416
3417
3418
3419







-
-
+
+







    /*
     * For each node in the ancestry of this line, record tag toggles for all
     * siblings that precede that node.
     */

    for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL;
	    nodePtr = nodePtr->parentPtr) {
	Node *siblingPtr;
	Summary *summaryPtr;
	register Node *siblingPtr;
	register Summary *summaryPtr;

	for (siblingPtr = nodePtr->parentPtr->children.nodePtr;
		siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) {
	    for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL;
		    summaryPtr = summaryPtr->nextPtr) {
		if (summaryPtr->toggleCount & 1) {
		    IncCount(summaryPtr->tagPtr, summaryPtr->toggleCount,
3503
3504
3505
3506
3507
3508
3509

3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524






3525
3526

3527
3528
3529

3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545


3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559

3560
3561
3562
3563

3564
3565
3566
3567
3568
3569
3570
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492






3493
3494
3495
3496
3497
3498
3499

3500
3501
3502

3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517


3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532

3533
3534
3535
3536

3537
3538
3539
3540
3541
3542
3543
3544







+









-
-
-
-
-
-
+
+
+
+
+
+

-
+


-
+














-
-
+
+













-
+



-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
TkTextIsElided(
    const TkText *textPtr,	/* Overall information about text widget. */
    const TkTextIndex *indexPtr,/* The character in the text for which display
				 * information is wanted. */
    TkTextElideInfo *elideInfo)	/* NULL or a pointer to a structure in which
				 * indexPtr's elide state will be stored and
				 * returned. */
{
    Node *nodePtr;
    TkTextLine *siblingLinePtr;
    TkTextSegment *segPtr;
    TkTextTag *tagPtr = NULL;
    Tcl_Size i;
    TkTextElideInfo *infoPtr;
    register Node *nodePtr;
    register TkTextLine *siblingLinePtr;
    register TkTextSegment *segPtr;
    register TkTextTag *tagPtr = NULL;
    register int i, index;
    register TkTextElideInfo *infoPtr;
    TkTextLine *linePtr;
    int elide, index;
    int elide;

    if (elideInfo == NULL) {
	infoPtr = (TkTextElideInfo *)ckalloc(sizeof(TkTextElideInfo));
	infoPtr = ckalloc(sizeof(TkTextElideInfo));
    } else {
	infoPtr = elideInfo;
    }

    infoPtr->elide = 0;		/* If nobody says otherwise, it's visible. */
    infoPtr->tagCnts = infoPtr->deftagCnts;
    infoPtr->tagPtrs = infoPtr->deftagPtrs;
    infoPtr->numTags = textPtr->sharedTextPtr->numTags;

    /*
     * Almost always avoid malloc, so stay out of system calls.
     */

    if (LOTSA_TAGS < infoPtr->numTags) {
	infoPtr->tagCnts = (int *)ckalloc(sizeof(int) * infoPtr->numTags);
	infoPtr->tagPtrs = (TkTextTag **)ckalloc(sizeof(TkTextTag *) * infoPtr->numTags);
	infoPtr->tagCnts = ckalloc(sizeof(int) * infoPtr->numTags);
	infoPtr->tagPtrs = ckalloc(sizeof(TkTextTag *) * infoPtr->numTags);
    }

    for (i=0; i<infoPtr->numTags; i++) {
	infoPtr->tagCnts[i] = 0;
    }

    /*
     * Record tag toggles within the line of indexPtr but preceding indexPtr.
     */

    index = 0;
    linePtr = indexPtr->linePtr;
    segPtr = linePtr->segPtr;
    while ((index + (int)segPtr->size) <= indexPtr->byteIndex) {
    while ((index + segPtr->size) <= indexPtr->byteIndex) {
	if ((segPtr->typePtr == &tkTextToggleOnType)
		|| (segPtr->typePtr == &tkTextToggleOffType)) {
	    tagPtr = segPtr->body.toggle.tagPtr;
	    if (tagPtr->elide >= 0) {
	    if (tagPtr->elideString != NULL) {
		infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
		infoPtr->tagCnts[tagPtr->priority]++;
	    }
	}

	index += segPtr->size;
	segPtr = segPtr->nextPtr;
3596
3597
3598
3599
3600
3601
3602
3603

3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619


3620
3621
3622
3623
3624
3625
3626
3627

3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645

3646
3647
3648
3649
3650
3651
3652
3570
3571
3572
3573
3574
3575
3576

3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591


3592
3593
3594
3595
3596
3597
3598
3599
3600

3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618

3619
3620
3621
3622
3623
3624
3625
3626







-
+














-
-
+
+







-
+

















-
+







	    siblingLinePtr != indexPtr->linePtr;
	    siblingLinePtr = siblingLinePtr->nextPtr) {
	for (segPtr = siblingLinePtr->segPtr; segPtr != NULL;
		segPtr = segPtr->nextPtr) {
	    if ((segPtr->typePtr == &tkTextToggleOnType)
		    || (segPtr->typePtr == &tkTextToggleOffType)) {
		tagPtr = segPtr->body.toggle.tagPtr;
		if (tagPtr->elide >= 0) {
		if (tagPtr->elideString != NULL) {
		    infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
		    infoPtr->tagCnts[tagPtr->priority]++;
		}
	    }
	}
    }

    /*
     * For each node in the ancestry of this line, record tag toggles for all
     * siblings that precede that node.
     */

    for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL;
	    nodePtr = nodePtr->parentPtr) {
	Node *siblingPtr;
	Summary *summaryPtr;
	register Node *siblingPtr;
	register Summary *summaryPtr;

	for (siblingPtr = nodePtr->parentPtr->children.nodePtr;
		siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) {
	    for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL;
		    summaryPtr = summaryPtr->nextPtr) {
		if (summaryPtr->toggleCount & 1) {
		    tagPtr = summaryPtr->tagPtr;
		    if (tagPtr->elide >= 0) {
		    if (tagPtr->elideString != NULL) {
			infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
			infoPtr->tagCnts[tagPtr->priority] +=
				summaryPtr->toggleCount;
		    }
		}
	    }
	}
    }

    /*
     * Now traverse from highest priority to lowest, take elided value from
     * first odd count (= on).
     */

    infoPtr->elidePriority = -1;
    for (i = infoPtr->numTags-1; i >=0; i--) {
	if (infoPtr->tagCnts[i] & 1) {
	    infoPtr->elide = infoPtr->tagPtrs[i]->elide > 0;
	    infoPtr->elide = infoPtr->tagPtrs[i]->elide;

	    /*
	     * Note: i == infoPtr->tagPtrs[i]->priority
	     */

	    infoPtr->elidePriority = i;
	    break;
3717
3718
3719
3720
3721
3722
3723
3724

3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745

3746
3747
3748
3749
3750

3751
3752
3753
3754
3755
3756
3757
3691
3692
3693
3694
3695
3696
3697

3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718

3719
3720
3721
3722
3723

3724
3725
3726
3727
3728
3729
3730
3731







-
+




















-
+




-
+







static void
IncCount(
    TkTextTag *tagPtr,		/* Handle for tag. */
    int inc,			/* Amount by which to increment tag count. */
    TagInfo *tagInfoPtr)	/* Holds cumulative information about tags;
				 * increment count here. */
{
    TkTextTag **tagPtrPtr;
    register TkTextTag **tagPtrPtr;
    int count;

    for (tagPtrPtr = tagInfoPtr->tagPtrs, count = tagInfoPtr->numTags;
	    count > 0; tagPtrPtr++, count--) {
	if (*tagPtrPtr == tagPtr) {
	    tagInfoPtr->counts[tagInfoPtr->numTags-count] += inc;
	    return;
	}
    }

    /*
     * There isn't currently an entry for this tag, so we have to make a new
     * one. If the arrays are full, then enlarge the arrays first.
     */

    if (tagInfoPtr->numTags == tagInfoPtr->arraySize) {
	TkTextTag **newTags;
	int *newCounts, newSize;

	newSize = 2 * tagInfoPtr->arraySize;
	newTags = (TkTextTag **)ckalloc(newSize * sizeof(TkTextTag *));
	newTags = ckalloc(newSize * sizeof(TkTextTag *));
	memcpy(newTags, tagInfoPtr->tagPtrs,
		tagInfoPtr->arraySize * sizeof(TkTextTag *));
	ckfree(tagInfoPtr->tagPtrs);
	tagInfoPtr->tagPtrs = newTags;
	newCounts = (int *)ckalloc(newSize * sizeof(int));
	newCounts = ckalloc(newSize * sizeof(int));
	memcpy(newCounts, tagInfoPtr->counts,
		tagInfoPtr->arraySize * sizeof(int));
	ckfree(tagInfoPtr->counts);
	tagInfoPtr->counts = newCounts;
	tagInfoPtr->arraySize = newSize;
    }

3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790





3791
3792
3793

3794
3795
3796
3797
3798
3799
3800
3801

3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813

3814
3815
3816
3817
3818
3819
3820
3753
3754
3755
3756
3757
3758
3759





3760
3761
3762
3763
3764
3765
3766

3767
3768
3769
3770
3771
3772
3773
3774

3775
3776
3777
3778

3779
3780
3781
3782
3783
3784
3785
3786

3787
3788
3789
3790
3791
3792
3793
3794







-
-
-
-
-
+
+
+
+
+


-
+







-
+



-
+







-
+







 */

void
TkBTreeCheck(
    TkTextBTree tree)		/* Tree to check. */
{
    BTree *treePtr = (BTree *) tree;
    Summary *summaryPtr;
    Node *nodePtr;
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    TkTextTag *tagPtr;
    register Summary *summaryPtr;
    register Node *nodePtr;
    register TkTextLine *linePtr;
    register TkTextSegment *segPtr;
    register TkTextTag *tagPtr;
    Tcl_HashEntry *entryPtr;
    Tcl_HashSearch search;
    Tcl_Size count;
    int count;

    /*
     * Make sure that the tag toggle counts and the tag root pointers are OK.
     */

    for (entryPtr=Tcl_FirstHashEntry(&treePtr->sharedTextPtr->tagTable,&search);
	    entryPtr != NULL ; entryPtr = Tcl_NextHashEntry(&search)) {
	tagPtr = (TkTextTag *)Tcl_GetHashValue(entryPtr);
	tagPtr = Tcl_GetHashValue(entryPtr);
	nodePtr = tagPtr->tagRootPtr;
	if (nodePtr == NULL) {
	    if (tagPtr->toggleCount != 0) {
		Tcl_Panic("TkBTreeCheck found \"%s\" with toggles (%" TCL_SIZE_MODIFIER "d) but no root",
		Tcl_Panic("TkBTreeCheck found \"%s\" with toggles (%d) but no root",
			tagPtr->name, tagPtr->toggleCount);
	    }
	    continue;		/* No ranges for the tag. */
	} else if (tagPtr->toggleCount == 0) {
	    Tcl_Panic("TkBTreeCheck found root for \"%s\" with no toggles",
		    tagPtr->name);
	} else if (tagPtr->toggleCount & 1) {
	    Tcl_Panic("TkBTreeCheck found odd toggle count for \"%s\" (%" TCL_SIZE_MODIFIER "d)",
	    Tcl_Panic("TkBTreeCheck found odd toggle count for \"%s\" (%d)",
		    tagPtr->name, tagPtr->toggleCount);
	}
	for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL;
		summaryPtr = summaryPtr->nextPtr) {
	    if (summaryPtr->tagPtr == tagPtr) {
		Tcl_Panic("TkBTreeCheck found root node with summary info");
	    }
3840
3841
3842
3843
3844
3845
3846
3847

3848
3849
3850
3851
3852
3853
3854
3814
3815
3816
3817
3818
3819
3820

3821
3822
3823
3824
3825
3826
3827
3828







-
+







			 segPtr->body.toggle.tagPtr == tagPtr) {
			count++;
		    }
		}
	    }
	}
	if (count != tagPtr->toggleCount) {
	    Tcl_Panic("TkBTreeCheck toggleCount (%" TCL_SIZE_MODIFIER "d) wrong for \"%s\" should be (%" TCL_SIZE_MODIFIER "d)",
	    Tcl_Panic("TkBTreeCheck toggleCount (%d) wrong for \"%s\" should be (%d)",
		    tagPtr->toggleCount, tagPtr->name, count);
	}
    }

    /*
     * Call a recursive function to do the main body of checks.
     */
3889
3890
3891
3892
3893
3894
3895
3896

3897
3898
3899
3900
3901
3902
3903
3863
3864
3865
3866
3867
3868
3869

3870
3871
3872
3873
3874
3875
3876
3877







-
+







	Tcl_Panic("TkBTreeCheck: last line has bogus segment type");
    }
    if (segPtr->nextPtr != NULL) {
	Tcl_Panic("TkBTreeCheck: last line has too many segments");
    }
    if (segPtr->size != 1) {
	Tcl_Panic("TkBTreeCheck: last line has wrong # characters: %d",
		(int)segPtr->size);
		segPtr->size);
    }
    if ((segPtr->body.chars[0] != '\n') || (segPtr->body.chars[1] != 0)) {
	Tcl_Panic("TkBTreeCheck: last line had bad value: %s",
		segPtr->body.chars);
    }
}

3918
3919
3920
3921
3922
3923
3924
3925

3926
3927
3928
3929
3930
3931
3932
3933





3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954

3955
3956
3957
3958
3959
3960
3961
3892
3893
3894
3895
3896
3897
3898

3899
3900
3901
3902





3903
3904
3905
3906
3907
3908

3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926

3927
3928
3929
3930
3931
3932
3933
3934







-
+



-
-
-
-
-
+
+
+
+
+

-


















-
+







 *	panics.
 *
 *----------------------------------------------------------------------
 */

static void
CheckNodeConsistency(
    Node *nodePtr,	/* Node whose subtree should be checked. */
    register Node *nodePtr,	/* Node whose subtree should be checked. */
    int references)		/* Number of referring widgets which have
				 * pixel counts. */
{
    Node *childNodePtr;
    Summary *summaryPtr, *summaryPtr2;
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    int numChildren, numLines, minChildren, i;
    register Node *childNodePtr;
    register Summary *summaryPtr, *summaryPtr2;
    register TkTextLine *linePtr;
    register TkTextSegment *segPtr;
    int numChildren, numLines, toggleCount, minChildren, i;
    int *numPixels;
    Tcl_Size toggleCount;
    int pixels[PIXEL_CLIENTS];

    if (nodePtr->parentPtr != NULL) {
	minChildren = MIN_CHILDREN;
    } else if (nodePtr->level > 0) {
	minChildren = 2;
    } else {
	minChildren = 1;
    }
    if ((nodePtr->numChildren < minChildren)
	    || (nodePtr->numChildren > MAX_CHILDREN)) {
	Tcl_Panic("CheckNodeConsistency: bad child count (%d)",
		nodePtr->numChildren);
    }

    numChildren = 0;
    numLines = 0;
    if (references > PIXEL_CLIENTS) {
	numPixels = (int *)ckalloc(sizeof(int) * references);
	numPixels = ckalloc(sizeof(int) * references);
    } else {
	numPixels = pixels;
    }
    for (i = 0; i<references; i++) {
	numPixels[i] = 0;
    }

3993
3994
3995
3996
3997
3998
3999
4000

4001
4002
4003
4004
4005
4006
4007
3966
3967
3968
3969
3970
3971
3972

3973
3974
3975
3976
3977
3978
3979
3980







-
+







    } else {
	for (childNodePtr = nodePtr->children.nodePtr; childNodePtr != NULL;
		childNodePtr = childNodePtr->nextPtr) {
	    if (childNodePtr->parentPtr != nodePtr) {
		Tcl_Panic("CheckNodeConsistency: node doesn't point to parent");
	    }
	    if (childNodePtr->level != (nodePtr->level-1)) {
		Tcl_Panic("CheckNodeConsistency: level mismatch (%" TCL_SIZE_MODIFIER "d %" TCL_SIZE_MODIFIER "d)",
		Tcl_Panic("CheckNodeConsistency: level mismatch (%d %d)",
			nodePtr->level, childNodePtr->level);
	    }
	    CheckNodeConsistency(childNodePtr, references);
	    for (summaryPtr = childNodePtr->summaryPtr; summaryPtr != NULL;
			summaryPtr = summaryPtr->nextPtr) {
		for (summaryPtr2 = nodePtr->summaryPtr; ;
			summaryPtr2 = summaryPtr2->nextPtr) {
4074
4075
4076
4077
4078
4079
4080
4081

4082
4083
4084
4085
4086
4087
4088
4047
4048
4049
4050
4051
4052
4053

4054
4055
4056
4057
4058
4059
4060
4061







-
+







		    if (summaryPtr2->tagPtr == summaryPtr->tagPtr) {
			toggleCount += summaryPtr2->toggleCount;
		    }
		}
	    }
	}
	if (toggleCount != summaryPtr->toggleCount) {
	    Tcl_Panic("CheckNodeConsistency: mismatch in toggleCount (%" TCL_SIZE_MODIFIER "d %" TCL_SIZE_MODIFIER "d)",
	    Tcl_Panic("CheckNodeConsistency: mismatch in toggleCount (%d %d)",
		    toggleCount, summaryPtr->toggleCount);
	}
	for (summaryPtr2 = summaryPtr->nextPtr; summaryPtr2 != NULL;
		summaryPtr2 = summaryPtr2->nextPtr) {
	    if (summaryPtr2->tagPtr == summaryPtr->tagPtr) {
		Tcl_Panic("CheckNodeConsistency: duplicated node tag: %s",
			summaryPtr->tagPtr->name);
4108
4109
4110
4111
4112
4113
4114
4115

4116
4117
4118
4119
4120
4121
4122
4123
4124


4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142

4143
4144
4145
4146
4147
4148
4149
4150

4151
4152
4153
4154
4155
4156
4157
4158
4159


4160
4161
4162
4163
4164
4165
4166
4081
4082
4083
4084
4085
4086
4087

4088
4089
4090
4091
4092
4093
4094
4095


4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114

4115
4116
4117
4118
4119
4120
4121
4122

4123
4124
4125
4126
4127
4128
4129
4130


4131
4132
4133
4134
4135
4136
4137
4138
4139







-
+







-
-
+
+

















-
+







-
+







-
-
+
+







 *
 *----------------------------------------------------------------------
 */

static void
Rebalance(
    BTree *treePtr,		/* Tree that is being rebalanced. */
    Node *nodePtr)	/* Node that may be out of balance. */
    register Node *nodePtr)	/* Node that may be out of balance. */
{
    /*
     * Loop over the entire ancestral chain of the node, working up through
     * the tree one node at a time until the root node has been processed.
     */

    for ( ; nodePtr != NULL; nodePtr = nodePtr->parentPtr) {
	Node *newPtr, *childPtr;
	TkTextLine *linePtr;
	register Node *newPtr, *childPtr;
	register TkTextLine *linePtr;
	int i;

	/*
	 * Check to see if the node has too many children. If it does, then
	 * split off all but the first MIN_CHILDREN into a separate node
	 * following the original one. Then repeat until the node has a decent
	 * size.
	 */

	if (nodePtr->numChildren > MAX_CHILDREN) {
	    while (1) {
		/*
		 * If the node being split is the root node, then make a new
		 * root node above it first.
		 */

		if (nodePtr->parentPtr == NULL) {
		    newPtr = (Node *)ckalloc(sizeof(Node));
		    newPtr = ckalloc(sizeof(Node));
		    newPtr->parentPtr = NULL;
		    newPtr->nextPtr = NULL;
		    newPtr->summaryPtr = NULL;
		    newPtr->level = nodePtr->level + 1;
		    newPtr->children.nodePtr = nodePtr;
		    newPtr->numChildren = 1;
		    newPtr->numLines = nodePtr->numLines;
		    newPtr->numPixels = (int *)
		    newPtr->numPixels =
			    ckalloc(sizeof(int) * treePtr->pixelReferences);
		    for (i=0; i<treePtr->pixelReferences; i++) {
			newPtr->numPixels[i] = nodePtr->numPixels[i];
		    }
		    RecomputeNodeCounts(treePtr, newPtr);
		    treePtr->rootPtr = newPtr;
		}
		newPtr = (Node *)ckalloc(sizeof(Node));
		newPtr->numPixels = (int *)
		newPtr = ckalloc(sizeof(Node));
		newPtr->numPixels =
			ckalloc(sizeof(int) * treePtr->pixelReferences);
		for (i=0; i<treePtr->pixelReferences; i++) {
		    newPtr->numPixels[i] = 0;
		}
		newPtr->parentPtr = nodePtr->parentPtr;
		newPtr->nextPtr = nodePtr->nextPtr;
		nodePtr->nextPtr = newPtr;
4191
4192
4193
4194
4195
4196
4197
4198

4199
4200
4201

4202
4203
4204
4205
4206
4207
4208
4164
4165
4166
4167
4168
4169
4170

4171
4172
4173

4174
4175
4176
4177
4178
4179
4180
4181







-
+


-
+







		    RecomputeNodeCounts(treePtr, nodePtr);
		    break;
		}
	    }
	}

	while (nodePtr->numChildren < MIN_CHILDREN) {
	    Node *otherPtr;
	    register Node *otherPtr;
	    Node *halfwayNodePtr = NULL;       /* Initialization needed only */
	    TkTextLine *halfwayLinePtr = NULL; /* to prevent cc warnings. */
	    int totalChildren, firstChildren;
	    int totalChildren, firstChildren, i;

	    /*
	     * Too few children for this node. If this is the root then, it's
	     * OK for it to have less than MIN_CHILDREN children as long as
	     * it's got at least two. If it has only one (and isn't at level
	     * 0), then chop the root node out of the tree and use its child
	     * as the new root.
4255
4256
4257
4258
4259
4260
4261


4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275


4276
4277
4278
4279
4280
4281
4282
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259







+
+














+
+







	    firstChildren = totalChildren/2;
	    if (nodePtr->children.nodePtr == NULL) {
		nodePtr->children = otherPtr->children;
		otherPtr->children.nodePtr = NULL;
		otherPtr->children.linePtr = NULL;
	    }
	    if (nodePtr->level == 0) {
		register TkTextLine *linePtr;

		for (linePtr = nodePtr->children.linePtr, i = 1;
			linePtr->nextPtr != NULL;
			linePtr = linePtr->nextPtr, i++) {
		    if (i == firstChildren) {
			halfwayLinePtr = linePtr;
		    }
		}
		linePtr->nextPtr = otherPtr->children.linePtr;
		while (i <= firstChildren) {
		    halfwayLinePtr = linePtr;
		    linePtr = linePtr->nextPtr;
		    i++;
		}
	    } else {
		register Node *childPtr;

		for (childPtr = nodePtr->children.nodePtr, i = 1;
			childPtr->nextPtr != NULL;
			childPtr = childPtr->nextPtr, i++) {
		    if (i <= firstChildren) {
			if (i == firstChildren) {
			    halfwayNodePtr = childPtr;
			}
4343
4344
4345
4346
4347
4348
4349
4350
4351


4352
4353
4354
4355
4356
4357




4358
4359
4360
4361
4362
4363
4364
4320
4321
4322
4323
4324
4325
4326


4327
4328
4329
4330




4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341







-
-
+
+


-
-
-
-
+
+
+
+







 *	the childrens' parentPtr fields are made to point to nodePtr.
 *
 *----------------------------------------------------------------------
 */

static void
RecomputeNodeCounts(
    BTree *treePtr,	/* The whole B-tree. */
    Node *nodePtr)	/* Node whose tag summary information must be
    register BTree *treePtr,	/* The whole B-tree. */
    register Node *nodePtr)	/* Node whose tag summary information must be
				 * recomputed. */
{
    Summary *summaryPtr, *summaryPtr2;
    Node *childPtr;
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    register Summary *summaryPtr, *summaryPtr2;
    register Node *childPtr;
    register TkTextLine *linePtr;
    register TkTextSegment *segPtr;
    TkTextTag *tagPtr;
    int ref;

    /*
     * Zero out all the existing counts for the node, but don't delete the
     * existing Summary records (most of them will probably be reused).
     */
4394
4395
4396
4397
4398
4399
4400
4401

4402
4403
4404
4405
4406
4407
4408
4371
4372
4373
4374
4375
4376
4377

4378
4379
4380
4381
4382
4383
4384
4385







-
+







			|| !(segPtr->body.toggle.inNodeCounts)) {
		    continue;
		}
		tagPtr = segPtr->body.toggle.tagPtr;
		for (summaryPtr = nodePtr->summaryPtr; ;
			summaryPtr = summaryPtr->nextPtr) {
		    if (summaryPtr == NULL) {
			summaryPtr = (Summary *)ckalloc(sizeof(Summary));
			summaryPtr = ckalloc(sizeof(Summary));
			summaryPtr->tagPtr = tagPtr;
			summaryPtr->toggleCount = 1;
			summaryPtr->nextPtr = nodePtr->summaryPtr;
			nodePtr->summaryPtr = summaryPtr;
			break;
		    }
		    if (summaryPtr->tagPtr == tagPtr) {
4422
4423
4424
4425
4426
4427
4428
4429

4430
4431
4432
4433
4434
4435
4436
4399
4400
4401
4402
4403
4404
4405

4406
4407
4408
4409
4410
4411
4412
4413







-
+







	    }
	    childPtr->parentPtr = nodePtr;
	    for (summaryPtr2 = childPtr->summaryPtr; summaryPtr2 != NULL;
		    summaryPtr2 = summaryPtr2->nextPtr) {
		for (summaryPtr = nodePtr->summaryPtr; ;
			summaryPtr = summaryPtr->nextPtr) {
		    if (summaryPtr == NULL) {
			summaryPtr = (Summary *)ckalloc(sizeof(Summary));
			summaryPtr = ckalloc(sizeof(Summary));
			summaryPtr->tagPtr = summaryPtr2->tagPtr;
			summaryPtr->toggleCount = summaryPtr2->toggleCount;
			summaryPtr->nextPtr = nodePtr->summaryPtr;
			nodePtr->summaryPtr = summaryPtr;
			break;
		    }
		    if (summaryPtr->tagPtr == summaryPtr2->tagPtr) {
4570
4571
4572
4573
4574
4575
4576
4577

4578
4579
4580
4581
4582
4583


4584
4585
4586
4587

4588
4589
4590
4591
4592
4593
4594
4547
4548
4549
4550
4551
4552
4553

4554
4555
4556
4557
4558


4559
4560
4561
4562
4563

4564
4565
4566
4567
4568
4569
4570
4571







-
+




-
-
+
+



-
+







 *
 *--------------------------------------------------------------
 */

static TkTextSegment *
CharSplitProc(
    TkTextSegment *segPtr,	/* Pointer to segment to split. */
    Tcl_Size index)			/* Position within segment at which to
    int index)			/* Position within segment at which to
				 * split. */
{
    TkTextSegment *newPtr1, *newPtr2;

    newPtr1 = (TkTextSegment *)ckalloc(CSEG_SIZE(index));
    newPtr2 = (TkTextSegment *)ckalloc(CSEG_SIZE(segPtr->size - index));
    newPtr1 = ckalloc(CSEG_SIZE(index));
    newPtr2 = ckalloc(CSEG_SIZE(segPtr->size - index));
    newPtr1->typePtr = &tkTextCharType;
    newPtr1->nextPtr = newPtr2;
    newPtr1->size = index;
    memcpy(newPtr1->body.chars, segPtr->body.chars, index);
    memcpy(newPtr1->body.chars, segPtr->body.chars, (size_t) index);
    newPtr1->body.chars[index] = 0;
    newPtr2->typePtr = &tkTextCharType;
    newPtr2->nextPtr = segPtr->nextPtr;
    newPtr2->size = segPtr->size - index;
    memcpy(newPtr2->body.chars, segPtr->body.chars + index, newPtr2->size);
    newPtr2->body.chars[newPtr2->size] = 0;
    ckfree(segPtr);
4609
4610
4611
4612
4613
4614
4615

4616
4617
4618
4619
4620

4621
4622
4623
4624
4625
4626
4627
4628

4629
4630
4631
4632
4633
4634
4635
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597

4598
4599
4600
4601
4602
4603
4604
4605

4606
4607
4608
4609
4610
4611
4612
4613







+




-
+







-
+







 *
 * Side effects:
 *	Storage for the segments may be allocated and freed.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static TkTextSegment *
CharCleanupProc(
    TkTextSegment *segPtr,	/* Pointer to first of two adjacent segments
				 * to join. */
    TCL_UNUSED(TkTextLine *))	/* Line containing segments (not used). */
    TkTextLine *linePtr)	/* Line containing segments (not used). */
{
    TkTextSegment *segPtr2, *newPtr;

    segPtr2 = segPtr->nextPtr;
    if ((segPtr2 == NULL) || (segPtr2->typePtr != &tkTextCharType)) {
	return segPtr;
    }
    newPtr = (TkTextSegment *)ckalloc(CSEG_SIZE(segPtr->size + segPtr2->size));
    newPtr = ckalloc(CSEG_SIZE(segPtr->size + segPtr2->size));
    newPtr->typePtr = &tkTextCharType;
    newPtr->nextPtr = segPtr2->nextPtr;
    newPtr->size = segPtr->size + segPtr2->size;
    memcpy(newPtr->body.chars, segPtr->body.chars, segPtr->size);
    memcpy(newPtr->body.chars + segPtr->size, segPtr2->body.chars, segPtr2->size);
    newPtr->body.chars[newPtr->size] = 0;
    ckfree(segPtr);
4649
4650
4651
4652
4653
4654
4655

4656
4657
4658
4659
4660


4661
4662
4663
4664
4665
4666
4667
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637


4638
4639
4640
4641
4642
4643
4644
4645
4646







+



-
-
+
+







 *
 * Side effects:
 *	Storage for the segment is freed.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
CharDeleteProc(
    TkTextSegment *segPtr,	/* Segment to delete. */
    TCL_UNUSED(TkTextLine *),	/* Line containing segment. */
    TCL_UNUSED(int))		/* Non-zero means the entire tree is being
    TkTextLine *linePtr,	/* Line containing segment. */
    int treeGone)		/* Non-zero means the entire tree is being
				 * deleted, so everything must get cleaned
				 * up. */
{
    ckfree(segPtr);
    return 0;
}

4678
4679
4680
4681
4682
4683
4684

4685
4686
4687
4688

4689
4690
4691
4692
4693
4694
4695
4696
4697

4698
4699
4700

4701
4702
4703
4704
4705
4706
4707
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667

4668
4669
4670
4671
4672
4673
4674
4675
4676

4677
4678
4679

4680
4681
4682
4683
4684
4685
4686
4687







+



-
+








-
+


-
+







 *
 * Side effects:
 *	If the segment isn't inconsistent then the function panics.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
CharCheckProc(
    TkTextSegment *segPtr,	/* Segment to check. */
    TCL_UNUSED(TkTextLine *))	/* Line containing segment. */
    TkTextLine *linePtr)	/* Line containing segment. */
{
    /*
     * Make sure that the segment contains the number of characters indicated
     * by its header, and that the last segment in a line ends in a newline.
     * Also make sure that there aren't ever two character segments adjacent
     * to each other: they should be merged together.
     */

    if (segPtr->size + 1 <= 1) {
    if (segPtr->size <= 0) {
	Tcl_Panic("CharCheckProc: segment has size <= 0");
    }
    if (strlen(segPtr->body.chars) != (size_t)segPtr->size) {
    if (strlen(segPtr->body.chars) != (size_t) segPtr->size) {
	Tcl_Panic("CharCheckProc: segment has wrong size");
    }
    if (segPtr->nextPtr == NULL) {
	if (segPtr->body.chars[segPtr->size-1] != '\n') {
	    Tcl_Panic("CharCheckProc: line doesn't end with newline");
	}
    } else if (segPtr->nextPtr->typePtr == &tkTextCharType) {
4872
4873
4874
4875
4876
4877
4878
4879

4880
4881
4882
4883
4884
4885
4886
4852
4853
4854
4855
4856
4857
4858

4859
4860
4861
4862
4863
4864
4865
4866







-
+







 */

static void
ToggleCheckProc(
    TkTextSegment *segPtr,	/* Segment to check. */
    TkTextLine *linePtr)	/* Line containing segment. */
{
    Summary *summaryPtr;
    register Summary *summaryPtr;
    int needSummary;

    if (segPtr->size != 0) {
	Tcl_Panic("ToggleCheckProc: segment had non-zero size");
    }
    if (!segPtr->body.toggle.inNodeCounts) {
	Tcl_Panic("ToggleCheckProc: toggle counts not updated in nodes");

Changes to generic/tkTextDisp.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22


23

24
25
26
27
28
29
30
31
32
33
34
35
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28


29
30
31
32
33
34
35








-
-
+
+












+
+
-
+



-
-







/*
 * tkTextDisp.c --
 *
 *	This module provides facilities to display text widgets. It is the
 *	only place where information is kept about the screen layout of text
 *	widgets. (Well, strictly, each TkTextLine and B-tree node caches its
 *	last observed pixel height, but that information originates here).
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkText.h"

#ifdef _WIN32
#include "tkWinInt.h"
#elif defined(__CYGWIN__)
#include "tkUnixInt.h"
#endif

#elif defined(MAC_OSX_TK)
#ifdef MAC_OSX_TK
#include "tkMacOSXInt.h"
#endif

#define OK_TO_LOG (!TkpWillDrawWidget(textPtr->tkwin))

/*
 * "Calculations of line pixel heights and the size of the vertical
 * scrollbar."
 *
 * Given that tag, font and elide changes can happen to large numbers of
 * diverse chunks in a text widget containing megabytes of text, it is not
 * possible to recalculate all affected height information immediately any
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
146
147
148
149
150
151
152


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178







-
-
+

















-
+







    int rMargin;		/* Right margin, in pixels. */
    Tk_3DBorder rMarginColor;	/* Color of right margin. */
    int spacing1;		/* Spacing above first dline in text line. */
    int spacing2;		/* Spacing between lines of dline. */
    int spacing3;		/* Spacing below last dline in text line. */
    TkTextTabArray *tabArrayPtr;/* Locations and types of tab stops (may be
				 * NULL). */
    TkTextTabStyle tabStyle;	/* One of TK_TEXT_TABSTYLE_TABULAR
				 * or TK_TEXT_TABSTYLE_WORDPROCESSOR. */
    int tabStyle;		/* One of TABULAR or WORDPROCESSOR. */
    int underline;		/* Non-zero means draw underline underneath
				 * text. */
    XColor *underlineColor;	/* Foreground color for underline underneath
                                 * text. */
    int elide;			/* Zero means draw text, otherwise not. */
    TkWrapMode wrapMode;	/* How to handle wrap-around for this tag.
				 * One of TEXT_WRAPMODE_CHAR,
				 * TEXT_WRAPMODE_NONE or TEXT_WRAPMODE_WORD.*/
} StyleValues;

/*
 * The following structure extends the StyleValues structure above with
 * graphics contexts used to actually draw the characters. The entries in
 * dInfoPtr->styleTable point to structures of this type.
 */

typedef struct TextStyle {
    Tcl_Size refCount;		/* Number of times this structure is
    int refCount;		/* Number of times this structure is
				 * referenced in Chunks. */
    GC bgGC;			/* Graphics context for background. None means
				 * use widget background. */
    GC fgGC;			/* Graphics context for foreground. */
    GC ulGC;			/* Graphics context for underline. */
    GC ovGC;			/* Graphics context for overstrike. */
    StyleValues *sValuePtr;	/* Raw information from which GCs were
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215

216
217
218


219
220
221
222
223
224
225
226
227
228
199
200
201
202
203
204
205

206





207
208

209



210
211



212
213
214
215
216
217
218







-
+
-
-
-
-
-


-
+
-
-
-
+
+
-
-
-







 * precision is different (e.g. Intel)
 */

#define FP_EQUAL_SCALE(double1, double2, scaleFactor) \
    (fabs((double1)-(double2))*((scaleFactor)+1.0) < 0.3)

/*
 * Macros to make debugging/testing logging a little easier.
 * Macro to make debugging/testing logging a little easier.
 *
 * On OSX 10.14 Drawing procedures are sometimes run because the system has
 * decided to redraw the window.  This can corrupt the data that a test is
 * trying to collect.  So we don't write to the logging variables when the
 * drawing procedure is being run that way.  Other systems can always log.
 */

#define LOG(toVar,what)							\
#define LOG(toVar,what) \
    if (OK_TO_LOG)							\
        Tcl_SetVar2(textPtr->interp, toVar, NULL, (what),		\
		    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
    Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \
	    TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
#define CLEAR(var)							\
    if (OK_TO_LOG)							\
	Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY)

/*
 * The following structure describes one line of the display, which may be
 * either part or all of one line of the text.
 */

typedef struct DLine {
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
275
276
277
278
279
280
281

282
283
284
285
286
287
288
289







-
+







 *				neighboring lines (see DisplayLineBackground).
 * NEW_LAYOUT -			Non-zero means that the line has been
 *				re-layed out since the last time the display
 *				was updated.
 * TOP_LINE -			Non-zero means that this was the top line in
 *				in the window the last time that the window
 *				was laid out. This is important because a line
 *				may be displayed differently if it's at the top
 *				may be displayed differently if its at the top
 *				or bottom than if it's in the middle
 *				(e.g. beveled edges aren't displayed for
 *				middle lines if the adjacent line has a
 *				similar background).
 * BOTTOM_LINE -		Non-zero means that this was the bottom line
 *				in the window the last time that the window
 *				was laid out.
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416







-
+







				 * calculations, if they are out of date. */
    TkTextIndex metricIndex;	/* If the current metric update line wraps
				 * into very many display lines, then this is
				 * used to keep track of what index we've got
				 * to so far... */
    int metricPixelHeight;	/* ...and this is for the height calculation
				 * so far...*/
    Tcl_Size metricEpoch;		/* ...and this for the epoch of the partial
    int metricEpoch;		/* ...and this for the epoch of the partial
				 * calculation so it can be cancelled if
				 * things change once more. This field will be
				 * -1 if there is no long-line calculation in
				 * progress, and take a non-negative value if
				 * there is such a calculation in progress. */
    int lastMetricUpdateLine;	/* When the current update line reaches this
				 * line, we are done and should stop the
434
435
436
437
438
439
440
441

442
443
444
445
446



447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
424
425
426
427
428
429
430

431
432
433



434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+


-
-
-
+
+
+









-
+







} TextDInfo;

/*
 * In TkTextDispChunk structures for character segments, the clientData field
 * points to one of the following structures:
 */

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
#if !TK_LAYOUT_WITH_BASE_CHUNKS

typedef struct CharInfo {
    Tcl_Size numBytes;		/* Number of bytes to display. */
    char chars[TKFLEXARRAY];		/* UTF characters to display.
				 * Allocated as large as necessary. THIS MUST BE THE LAST
    int numBytes;		/* Number of bytes to display. */
    char chars[1];		/* UTF characters to display. Actual size will
				 * be numBytes, not 1. THIS MUST BE THE LAST
				 * FIELD IN THE STRUCTURE. */
} CharInfo;

#else /* TK_LAYOUT_WITH_BASE_CHUNKS */

typedef struct CharInfo {
    TkTextDispChunk *baseChunkPtr;
    int baseOffset;		/* Starting offset in base chunk
				 * baseChars. */
    Tcl_Size numBytes;		/* Number of bytes that belong to this
    int numBytes;		/* Number of bytes that belong to this
				 * chunk. */
    const char *chars;		/* UTF characters to display. Actually points
				 * into the baseChars of the base chunk. Only
				 * valid after FinalizeBaseChunk(). */
} CharInfo;

/*
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
479
480
481
482
483
484
485


486
487
488
489
490
491

492
493
494
495
496
497
498
499







-
-






-
+







 * REDRAW_BORDERS:		Means window border or pad area has
 *				potentially been damaged and must be redrawn.
 * REPICK_NEEDED:		1 means that the widget has been modified in a
 *				way that could change the current character (a
 *				different character might be under the mouse
 *				cursor now). Need to recompute the current
 *				character before the next redisplay.
 * OUT_OF_SYNC                  1 means that the last <<WidgetViewSync>> event had
 *                              value 0, indicating that the widget is out of sync.
 */

#define DINFO_OUT_OF_DATE	1
#define REDRAW_PENDING		2
#define REDRAW_BORDERS		4
#define REPICK_NEEDED		8
#define OUT_OF_SYNC             16

/*
 * Action values for FreeDLines:
 *
 * DLINE_FREE:		Free the lines, but no need to unlink them from the
 *			current list of actual display lines.
 * DLINE_UNLINK:	Free and unlink from current display.
 * DLINE_FREE_TEMP:	Free, but don't unlink, and also don't set
532
533
534
535
536
537
538
539

540
541
542

543
544
545
546
547
548
549
550

551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569

570
571
572
573
574

575
576
577
578
579
580
581


582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
606
607
608
609

610
611
612
613
614
615
616
617
618

619
620
621

622
623
624


625
626
627
628
629
630
631
520
521
522
523
524
525
526

527
528
529

530
531
532
533
534
535
536
537

538
539
540

541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556

557
558
559
560
561

562
563
564
565
566
567


568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605

606
607
608

609
610


611
612
613
614
615
616
617
618
619







-
+


-
+







-
+


-
+












-
+


-
+




-
+





-
-
+
+






-
+









-
+










-
+








-
+


-
+

-
-
+
+







 * Forward declarations for functions defined later in this file:
 */

static void		AdjustForTab(TkText *textPtr,
			    TkTextTabArray *tabArrayPtr, int index,
			    TkTextDispChunk *chunkPtr);
static void		CharBboxProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, Tcl_Size index, int y,
			    TkTextDispChunk *chunkPtr, int index, int y,
			    int lineHeight, int baseline, int *xPtr,
			    int *yPtr, int *widthPtr, int *heightPtr);
static Tcl_Size	CharChunkMeasureChars(TkTextDispChunk *chunkPtr,
static int		CharChunkMeasureChars(TkTextDispChunk *chunkPtr,
			    const char *chars, int charsLen,
			    int start, int end, int startX, int maxX,
			    int flags, int *nextX);
static void		CharDisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, int x, int y,
			    int height, int baseline, Display *display,
			    Drawable dst, int screenY);
static Tcl_Size	CharMeasureProc(TkTextDispChunk *chunkPtr, int x);
static int		CharMeasureProc(TkTextDispChunk *chunkPtr, int x);
static void		CharUndisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr);
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
static void		FinalizeBaseChunk(TkTextDispChunk *additionalChunkPtr);
static void		FreeBaseChunk(TkTextDispChunk *baseChunkPtr);
static int		IsSameFGStyle(TextStyle *style1, TextStyle *style2);
static void		RemoveFromBaseChunk(TkTextDispChunk *chunkPtr);
#endif
/*
 * Definitions of elided procs. Compiler can't inline these since we use
 * pointers to these functions. ElideDisplayProc and ElideUndisplayProc are
 * special-cased for speed, as potentially many elided DLine chunks if large,
 * tag toggle-filled elided region.
 */
static void		ElideBboxProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, Tcl_Size index, int y,
			    TkTextDispChunk *chunkPtr, int index, int y,
			    int lineHeight, int baseline, int *xPtr,
			    int *yPtr, int *widthPtr, int *heightPtr);
static Tcl_Size	ElideMeasureProc(TkTextDispChunk *chunkPtr, int x);
static int		ElideMeasureProc(TkTextDispChunk *chunkPtr, int x);
static void		DisplayDLine(TkText *textPtr, DLine *dlPtr,
			    DLine *prevPtr, Pixmap pixmap);
static void		DisplayLineBackground(TkText *textPtr, DLine *dlPtr,
			    DLine *prevPtr, Pixmap pixmap);
static void		DisplayText(void *clientData);
static void		DisplayText(ClientData clientData);
static DLine *		FindDLine(TkText *textPtr, DLine *dlPtr,
                            const TkTextIndex *indexPtr);
static void		FreeDLines(TkText *textPtr, DLine *firstPtr,
			    DLine *lastPtr, int action);
static void		FreeStyle(TkText *textPtr, TextStyle *stylePtr);
static TextStyle *	GetStyle(const TkText *textPtr, const TkTextIndex *indexPtr);
static void		GetXView(Tcl_Interp *interp, const TkText *textPtr,
static TextStyle *	GetStyle(TkText *textPtr, const TkTextIndex *indexPtr);
static void		GetXView(Tcl_Interp *interp, TkText *textPtr,
			    int report);
static void		GetYView(Tcl_Interp *interp, TkText *textPtr,
			    int report);
static int		GetYPixelCount(TkText *textPtr, DLine *dlPtr);
static DLine *		LayoutDLine(TkText *textPtr,
			    const TkTextIndex *indexPtr);
static Tcl_Size	MeasureChars(Tk_Font tkfont, const char *source,
static int		MeasureChars(Tk_Font tkfont, const char *source,
			    int maxBytes, int rangeStart, int rangeLength,
			    int startX, int maxX, int flags, int *nextXPtr);
static void		MeasureUp(TkText *textPtr,
			    const TkTextIndex *srcPtr, int distance,
			    TkTextIndex *dstPtr, int *overlap);
static int		NextTabStop(Tk_Font tkfont, int x, int tabOrigin);
static void		UpdateDisplayInfo(TkText *textPtr);
static void		YScrollByLines(TkText *textPtr, int offset);
static void		YScrollByPixels(TkText *textPtr, int offset);
static int		SizeOfTab(TkText *textPtr, TkTextTabStyle tabStyle,
static int		SizeOfTab(TkText *textPtr, int tabStyle,
			    TkTextTabArray *tabArrayPtr, int *indexPtr, int x,
			    int maxX);
static void		TextChanged(TkText *textPtr,
			    const TkTextIndex *index1Ptr,
			    const TkTextIndex *index2Ptr);
static void		TextInvalidateRegion(TkText *textPtr, TkRegion region);
static void		TextRedrawTag(TkText *textPtr,
			    TkTextIndex *index1Ptr, TkTextIndex *index2Ptr,
			    TkTextTag *tagPtr, int withTag);
static void		TextInvalidateLineMetrics(TkText *textPtr,
			    TkTextLine *linePtr, int lineCount, TkTextInvalidateAction action);
			    TkTextLine *linePtr, int lineCount, int action);
static int		CalculateDisplayLineHeight(TkText *textPtr,
			    const TkTextIndex *indexPtr, int *byteCountPtr,
			    int *mergedLinePtr);
static void		DlineIndexOfX(TkText *textPtr,
			    DLine *dlPtr, int x, TkTextIndex *indexPtr);
static int		DlineXOfIndex(TkText *textPtr,
			    DLine *dlPtr, int byteIndex);
static int		TextGetScrollInfoObj(Tcl_Interp *interp,
			    TkText *textPtr, Tcl_Size objc,
			    TkText *textPtr, int objc,
			    Tcl_Obj *const objv[], double *dblPtr,
			    int *intPtr);
static void		AsyncUpdateLineMetrics(void *clientData);
static void		AsyncUpdateLineMetrics(ClientData clientData);
static void		GenerateWidgetViewSyncEvent(TkText *textPtr, Bool InSync);
static void		AsyncUpdateYScrollbar(void *clientData);
static int              IsStartOfNotMergedLine(const TkText *textPtr,
static void		AsyncUpdateYScrollbar(ClientData clientData);
static int              IsStartOfNotMergedLine(TkText *textPtr,
                            const TkTextIndex *indexPtr);

/*
 * Result values returned by TextGetScrollInfoObj:
 */

#define TKTEXT_SCROLL_MOVETO	1
652
653
654
655
656
657
658
659

660
661
662

663
664
665

666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
640
641
642
643
644
645
646

647
648
649

650
651
652

653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677







-
+


-
+


-
+
















-
+







 *----------------------------------------------------------------------
 */

void
TkTextCreateDInfo(
    TkText *textPtr)		/* Overall information for text widget. */
{
    TextDInfo *dInfoPtr;
    register TextDInfo *dInfoPtr;
    XGCValues gcValues;

    dInfoPtr = (TextDInfo *)ckalloc(sizeof(TextDInfo));
    dInfoPtr = ckalloc(sizeof(TextDInfo));
    Tcl_InitHashTable(&dInfoPtr->styleTable, sizeof(StyleValues)/sizeof(int));
    dInfoPtr->dLinePtr = NULL;
    dInfoPtr->copyGC = NULL;
    dInfoPtr->copyGC = None;
    gcValues.graphics_exposures = True;
    dInfoPtr->scrollGC = Tk_GetGC(textPtr->tkwin, GCGraphicsExposures,
	    &gcValues);
    dInfoPtr->topOfEof = 0;
    dInfoPtr->newXPixelOffset = 0;
    dInfoPtr->curXPixelOffset = 0;
    dInfoPtr->maxLength = 0;
    dInfoPtr->xScrollFirst = -1;
    dInfoPtr->xScrollLast = -1;
    dInfoPtr->yScrollFirst = -1;
    dInfoPtr->yScrollLast = -1;
    dInfoPtr->scanMarkXPixel = 0;
    dInfoPtr->scanMarkX = 0;
    dInfoPtr->scanTotalYScroll = 0;
    dInfoPtr->scanMarkY = 0;
    dInfoPtr->dLinesInvalidated = 0;
    dInfoPtr->flags = 0;
    dInfoPtr->flags = DINFO_OUT_OF_DATE;
    dInfoPtr->topPixelOffset = 0;
    dInfoPtr->newTopPixelOffset = 0;
    dInfoPtr->currentMetricUpdateLine = -1;
    dInfoPtr->lastMetricUpdateLine = -1;
    dInfoPtr->lineMetricUpdateEpoch = 1;
    dInfoPtr->metricEpoch = -1;
    dInfoPtr->metricIndex.textPtr = NULL;
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724







-
+










-
+







 *----------------------------------------------------------------------
 */

void
TkTextFreeDInfo(
    TkText *textPtr)		/* Overall information for text widget. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    register TextDInfo *dInfoPtr = textPtr->dInfoPtr;

    /*
     * Be careful to free up styleTable *after* freeing up all the DLines, so
     * that the hash table is still intact to free up the style-related
     * information from the lines. Once the lines are all free then styleTable
     * will be empty.
     */

    FreeDLines(textPtr, dInfoPtr->dLinePtr, NULL, DLINE_UNLINK);
    Tcl_DeleteHashTable(&dInfoPtr->styleTable);
    if (dInfoPtr->copyGC != NULL) {
    if (dInfoPtr->copyGC != None) {
	Tk_FreeGC(textPtr->display, dInfoPtr->copyGC);
    }
    Tk_FreeGC(textPtr->display, dInfoPtr->scrollGC);
    if (dInfoPtr->flags & REDRAW_PENDING) {
	Tcl_CancelIdleCall(DisplayText, textPtr);
    }
    if (dInfoPtr->lineUpdateTimer != NULL) {
762
763
764
765
766
767
768
769

770
771
772
773
774

775
776
777
778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793







794
795
796
797
798
799
800
750
751
752
753
754
755
756

757
758
759
760
761

762
763
764
765

766

767
768
769
770
771
772
773







774
775
776
777
778
779
780
781
782
783
784
785
786
787







-
+




-
+



-
+
-







-
-
-
-
-
-
-
+
+
+
+
+
+
+







 *	A new entry may be created in the style table for the widget.
 *
 *----------------------------------------------------------------------
 */

static TextStyle *
GetStyle(
    const TkText *textPtr,		/* Overall information about text widget. */
    TkText *textPtr,		/* Overall information about text widget. */
    const TkTextIndex *indexPtr)/* The character in the text for which display
				 * information is wanted. */
{
    TkTextTag **tagPtrs;
    TkTextTag *tagPtr;
    register TkTextTag *tagPtr;
    StyleValues styleValues;
    TextStyle *stylePtr;
    Tcl_HashEntry *hPtr;
    Tcl_Size numTags, i;
    int numTags, isNew, i;
    int isNew;
    int isSelected;
    XGCValues gcValues;
    unsigned long mask;
    /*
     * The variables below keep track of the highest-priority specification
     * that has occurred for each of the various fields of the StyleValues.
     */
    Tcl_Size borderPrio, borderWidthPrio, reliefPrio, bgStipplePrio;
    Tcl_Size fgPrio, fontPrio, fgStipplePrio;
    Tcl_Size underlinePrio, elidePrio, justifyPrio, offsetPrio;
    Tcl_Size lMargin1Prio, lMargin2Prio, rMarginPrio;
    Tcl_Size lMarginColorPrio, rMarginColorPrio;
    Tcl_Size spacing1Prio, spacing2Prio, spacing3Prio;
    Tcl_Size overstrikePrio, tabPrio, tabStylePrio, wrapPrio;
    int borderPrio, borderWidthPrio, reliefPrio, bgStipplePrio;
    int fgPrio, fontPrio, fgStipplePrio;
    int underlinePrio, elidePrio, justifyPrio, offsetPrio;
    int lMargin1Prio, lMargin2Prio, rMarginPrio;
    int lMarginColorPrio, rMarginColorPrio;
    int spacing1Prio, spacing2Prio, spacing3Prio;
    int overstrikePrio, tabPrio, tabStylePrio, wrapPrio;

    /*
     * Find out what tags are present for the character, then compute a
     * StyleValues structure corresponding to those tags (scan through all of
     * the tags, saving information for the highest-priority tag).
     */

855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884
885
886
887
888
889

890
891
892
893

894
895
896
897
898
899
900
901
902

903
904
905
906
907

908
909
910
911
912

913
914
915
916
917
918
919
920
921
922

923
924
925
926
927

928
929

930
931

932
933

934
935
936
937

938
939
940
941
942
943
944
945
946
947

948
949
950
951
952

953
954
955
956
957

958
959
960
961
962
963
964
965
966
967

968
969
970
971
972
973

974
975

976
977

978
979

980
981
982
983

984
985

986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
842
843
844
845
846
847
848

849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875

876
877
878
879

880
881
882
883
884
885
886
887
888

889
890
891
892
893

894
895
896
897
898

899
900
901
902
903
904
905
906
907
908

909
910
911
912
913

914
915

916
917

918
919

920
921
922
923

924
925
926
927
928
929
930
931
932
933

934
935
936
937
938

939
940
941
942
943

944
945
946
947
948
949
950
951
952
953

954

955
956
957
958

959
960

961
962

963
964

965
966
967
968

969
970

971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019







-
+













-
+












-
+



-
+








-
+




-
+




-
+









-
+




-
+

-
+

-
+

-
+



-
+









-
+




-
+




-
+









-
+
-




-
+

-
+

-
+

-
+



-
+

-
+



















-
+








-
+











-
+







	    border = textPtr->inactiveSelBorder;
	}

        if ((tagPtr->selBorder != NULL) && (isSelected)) {
            border = tagPtr->selBorder;
        }

        if ((tagPtr->selFgColor != NULL) && isSelected) {
        if ((tagPtr->selFgColor != None) && (isSelected)) {
            fgColor = tagPtr->selFgColor;
        }

	if ((border != NULL) && (tagPtr->priority > borderPrio)) {
	    styleValues.border = border;
	    borderPrio = tagPtr->priority;
	}
	if ((tagPtr->borderWidthPtr != NULL)
		&& (Tcl_GetString(tagPtr->borderWidthPtr)[0] != '\0')
		&& (tagPtr->priority > borderWidthPrio)) {
	    styleValues.borderWidth = tagPtr->borderWidth;
	    borderWidthPrio = tagPtr->priority;
	}
	if ((tagPtr->relief != TK_RELIEF_NULL)
	if ((tagPtr->reliefString != NULL)
		&& (tagPtr->priority > reliefPrio)) {
	    if (styleValues.border == NULL) {
		styleValues.border = textPtr->border;
	    }
	    styleValues.relief = tagPtr->relief;
	    reliefPrio = tagPtr->priority;
	}
	if ((tagPtr->bgStipple != None)
		&& (tagPtr->priority > bgStipplePrio)) {
	    styleValues.bgStipple = tagPtr->bgStipple;
	    bgStipplePrio = tagPtr->priority;
	}
	if ((fgColor != NULL) && (tagPtr->priority > fgPrio)) {
	if ((fgColor != None) && (tagPtr->priority > fgPrio)) {
	    styleValues.fgColor = fgColor;
	    fgPrio = tagPtr->priority;
	}
	if ((tagPtr->tkfont != NULL) && (tagPtr->priority > fontPrio)) {
	if ((tagPtr->tkfont != None) && (tagPtr->priority > fontPrio)) {
	    styleValues.tkfont = tagPtr->tkfont;
	    fontPrio = tagPtr->priority;
	}
	if ((tagPtr->fgStipple != None)
		&& (tagPtr->priority > fgStipplePrio)) {
	    styleValues.fgStipple = tagPtr->fgStipple;
	    fgStipplePrio = tagPtr->priority;
	}
	if ((tagPtr->justify != TK_JUSTIFY_NULL)
	if ((tagPtr->justifyString != NULL)
		&& (tagPtr->priority > justifyPrio)) {
	    styleValues.justify = tagPtr->justify;
	    justifyPrio = tagPtr->priority;
	}
	if ((tagPtr->lMargin1 != INT_MIN)
	if ((tagPtr->lMargin1String != NULL)
		&& (tagPtr->priority > lMargin1Prio)) {
	    styleValues.lMargin1 = tagPtr->lMargin1;
	    lMargin1Prio = tagPtr->priority;
	}
	if ((tagPtr->lMargin2 != INT_MIN)
	if ((tagPtr->lMargin2String != NULL)
		&& (tagPtr->priority > lMargin2Prio)) {
	    styleValues.lMargin2 = tagPtr->lMargin2;
	    lMargin2Prio = tagPtr->priority;
	}
	if ((tagPtr->lMarginColor != NULL)
		&& (tagPtr->priority > lMarginColorPrio)) {
	    styleValues.lMarginColor = tagPtr->lMarginColor;
	    lMarginColorPrio = tagPtr->priority;
	}
	if ((tagPtr->offset != INT_MIN)
	if ((tagPtr->offsetString != NULL)
		&& (tagPtr->priority > offsetPrio)) {
	    styleValues.offset = tagPtr->offset;
	    offsetPrio = tagPtr->priority;
	}
	if ((tagPtr->overstrike >= 0)
	if ((tagPtr->overstrikeString != NULL)
		&& (tagPtr->priority > overstrikePrio)) {
	    styleValues.overstrike = tagPtr->overstrike > 0;
	    styleValues.overstrike = tagPtr->overstrike;
	    overstrikePrio = tagPtr->priority;
            if (tagPtr->overstrikeColor != NULL) {
            if (tagPtr->overstrikeColor != None) {
                 styleValues.overstrikeColor = tagPtr->overstrikeColor;
            } else if (fgColor != NULL) {
            } else if (fgColor != None) {
                 styleValues.overstrikeColor = fgColor;
            }
	}
	if ((tagPtr->rMargin != INT_MIN)
	if ((tagPtr->rMarginString != NULL)
		&& (tagPtr->priority > rMarginPrio)) {
	    styleValues.rMargin = tagPtr->rMargin;
	    rMarginPrio = tagPtr->priority;
	}
	if ((tagPtr->rMarginColor != NULL)
		&& (tagPtr->priority > rMarginColorPrio)) {
	    styleValues.rMarginColor = tagPtr->rMarginColor;
	    rMarginColorPrio = tagPtr->priority;
	}
	if ((tagPtr->spacing1 != INT_MIN)
	if ((tagPtr->spacing1String != NULL)
		&& (tagPtr->priority > spacing1Prio)) {
	    styleValues.spacing1 = tagPtr->spacing1;
	    spacing1Prio = tagPtr->priority;
	}
	if ((tagPtr->spacing2 != INT_MIN)
	if ((tagPtr->spacing2String != NULL)
		&& (tagPtr->priority > spacing2Prio)) {
	    styleValues.spacing2 = tagPtr->spacing2;
	    spacing2Prio = tagPtr->priority;
	}
	if ((tagPtr->spacing3 != INT_MIN)
	if ((tagPtr->spacing3String != NULL)
		&& (tagPtr->priority > spacing3Prio)) {
	    styleValues.spacing3 = tagPtr->spacing3;
	    spacing3Prio = tagPtr->priority;
	}
	if ((tagPtr->tabStringPtr != NULL)
		&& (tagPtr->priority > tabPrio)) {
	    styleValues.tabArrayPtr = tagPtr->tabArrayPtr;
	    tabPrio = tagPtr->priority;
	}
	if (((tagPtr->tabStyle == TK_TEXT_TABSTYLE_TABULAR)
	if ((tagPtr->tabStyle != TK_TEXT_TABSTYLE_NONE)
		|| (tagPtr->tabStyle == TK_TEXT_TABSTYLE_WORDPROCESSOR))
		&& (tagPtr->priority > tabStylePrio)) {
	    styleValues.tabStyle = tagPtr->tabStyle;
	    tabStylePrio = tagPtr->priority;
	}
	if ((tagPtr->underline >= 0)
	if ((tagPtr->underlineString != NULL)
		&& (tagPtr->priority > underlinePrio)) {
	    styleValues.underline = tagPtr->underline > 0;
	    styleValues.underline = tagPtr->underline;
	    underlinePrio = tagPtr->priority;
            if (tagPtr->underlineColor != NULL) {
            if (tagPtr->underlineColor != None) {
                 styleValues.underlineColor = tagPtr->underlineColor;
            } else if (fgColor != NULL) {
            } else if (fgColor != None) {
                 styleValues.underlineColor = fgColor;
            }
	}
	if ((tagPtr->elide >= 0)
	if ((tagPtr->elideString != NULL)
		&& (tagPtr->priority > elidePrio)) {
	    styleValues.elide = tagPtr->elide > 0;
	    styleValues.elide = tagPtr->elide;
	    elidePrio = tagPtr->priority;
	}
	if ((tagPtr->wrapMode != TEXT_WRAPMODE_NULL)
		&& (tagPtr->priority > wrapPrio)) {
	    styleValues.wrapMode = tagPtr->wrapMode;
	    wrapPrio = tagPtr->priority;
	}
    }
    if (tagPtrs != NULL) {
	ckfree(tagPtrs);
    }

    /*
     * Use an existing style if there's one around that matches.
     */

    hPtr = Tcl_CreateHashEntry(&textPtr->dInfoPtr->styleTable,
	    (char *) &styleValues, &isNew);
    if (!isNew) {
	stylePtr = (TextStyle *)Tcl_GetHashValue(hPtr);
	stylePtr = Tcl_GetHashValue(hPtr);
	stylePtr->refCount++;
	return stylePtr;
    }

    /*
     * No existing style matched. Make a new one.
     */

    stylePtr = (TextStyle *)ckalloc(sizeof(TextStyle));
    stylePtr = ckalloc(sizeof(TextStyle));
    stylePtr->refCount = 1;
    if (styleValues.border != NULL) {
	gcValues.foreground = Tk_3DBorderColor(styleValues.border)->pixel;
	mask = GCForeground;
	if (styleValues.bgStipple != None) {
	    gcValues.stipple = styleValues.bgStipple;
	    gcValues.fill_style = FillStippled;
	    mask |= GCStipple|GCFillStyle;
	}
	stylePtr->bgGC = Tk_GetGC(textPtr->tkwin, mask, &gcValues);
    } else {
	stylePtr->bgGC = NULL;
	stylePtr->bgGC = None;
    }
    mask = GCFont;
    gcValues.font = Tk_FontId(styleValues.tkfont);
    mask |= GCForeground;
    gcValues.foreground = styleValues.fgColor->pixel;
    if (styleValues.fgStipple != None) {
	gcValues.stipple = styleValues.fgStipple;
1065
1066
1067
1068
1069
1070
1071
1072

1073
1074

1075
1076


1077
1078
1079

1080
1081
1082

1083
1084
1085

1086
1087
1088
1089
1090
1091
1092
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061


1062
1063
1064
1065

1066
1067
1068

1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079







-
+


+
-
-
+
+


-
+


-
+


-
+







 *
 *----------------------------------------------------------------------
 */

static void
FreeStyle(
    TkText *textPtr,		/* Information about overall widget. */
    TextStyle *stylePtr)
    register TextStyle *stylePtr)
				/* Information about style to free. */
{
    stylePtr->refCount--;
    if (stylePtr->refCount-- <= 1) {
	if (stylePtr->bgGC != NULL) {
    if (stylePtr->refCount == 0) {
	if (stylePtr->bgGC != None) {
	    Tk_FreeGC(textPtr->display, stylePtr->bgGC);
	}
	if (stylePtr->fgGC != NULL) {
	if (stylePtr->fgGC != None) {
	    Tk_FreeGC(textPtr->display, stylePtr->fgGC);
	}
	if (stylePtr->ulGC != NULL) {
	if (stylePtr->ulGC != None) {
	    Tk_FreeGC(textPtr->display, stylePtr->ulGC);
	}
	if (stylePtr->ovGC != NULL) {
	if (stylePtr->ovGC != None) {
	    Tk_FreeGC(textPtr->display, stylePtr->ovGC);
	}
	Tcl_DeleteHashEntry(stylePtr->hPtr);
	ckfree(stylePtr);
    }
}

1127
1128
1129
1130
1131
1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128







-
+







static DLine *
LayoutDLine(
    TkText *textPtr,		/* Overall information about text widget. */
    const TkTextIndex *indexPtr)/* Beginning of display line. May not
				 * necessarily point to a character
				 * segment. */
{
    DLine *dlPtr;	/* New display line. */
    register DLine *dlPtr;	/* New display line. */
    TkTextSegment *segPtr;	/* Current segment in text. */
    TkTextDispChunk *lastChunkPtr;
				/* Last chunk allocated so far for line. */
    TkTextDispChunk *chunkPtr;	/* Current chunk. */
    TkTextIndex curIndex;
    TkTextDispChunk *breakChunkPtr;
				/* Chunk containing best word break point, if
1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193
1194
1195
1196
1197
1153
1154
1155
1156
1157
1158
1159


1160
1161
1162
1163
1164
1165
1166


1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181
1182







-
-
+






-
-
+







-
+







    TkTextDispChunk *tabChunkPtr;
				/* Pointer to the chunk containing the
				 * previous tab stop. */
    int maxBytes;		/* Maximum number of bytes to include in this
				 * chunk. */
    TkTextTabArray *tabArrayPtr;/* Tab stops for line; taken from style for
				 * the first character on line. */
    TkTextTabStyle tabStyle;	/* One of TK_TEXT_TABSTYLE_TABULAR
				 * or TK_TEXT_TABSTYLE_WORDPROCESSOR. */
    int tabStyle;		/* One of TABULAR or WORDPROCESSOR. */
    int tabSize;		/* Number of pixels consumed by current tab
				 * stop. */
    TkTextDispChunk *lastCharChunkPtr;
				/* Pointer to last chunk in display lines with
				 * numBytes > 0. Used to drop 0-sized chunks
				 * from the end of the line. */
    Tcl_Size byteOffset;
    int ascent, descent, code, elide, elidesize;
    int byteOffset, ascent, descent, code, elide, elidesize;
    StyleValues *sValuePtr;
    TkTextElideInfo info;	/* Keep track of elide state. */

    /*
     * Create and initialize a new DLine structure.
     */

    dlPtr = (DLine *)ckalloc(sizeof(DLine));
    dlPtr = ckalloc(sizeof(DLine));
    dlPtr->index = *indexPtr;
    dlPtr->byteCount = 0;
    dlPtr->y = 0;
    dlPtr->oldY = 0;		/* Only set to avoid compiler warnings. */
    dlPtr->height = 0;
    dlPtr->baseline = 0;
    dlPtr->chunkPtr = NULL;
1241
1242
1243
1244
1245
1246
1247
1248

1249
1250
1251
1252
1253
1254
1255
1226
1227
1228
1229
1230
1231
1232

1233
1234
1235
1236
1237
1238
1239
1240







-
+








		/*
		 * The elide state only changes if this tag is either the
		 * current highest priority tag (and is therefore being
		 * toggled off), or it's a new tag with higher priority.
		 */

		if (tagPtr->elide >= 0) {
		if (tagPtr->elideString != NULL) {
		    info.tagCnts[tagPtr->priority]++;
		    if (info.tagCnts[tagPtr->priority] & 1) {
			info.tagPtrs[tagPtr->priority] = tagPtr;
		    }
		    if (tagPtr->priority >= info.elidePriority) {
			if (segPtr->typePtr == &tkTextToggleOffType) {
			    /*
1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271







-
+




-
+







			     * elide will be zero, of course).
			     */

			    elide = 0;
			    while (--info.elidePriority > 0) {
				if (info.tagCnts[info.elidePriority] & 1) {
				    elide = info.tagPtrs[info.elidePriority]
					    ->elide > 0;
					    ->elide;
				    break;
				}
			    }
			} else {
			    elide = tagPtr->elide > 0;
			    elide = tagPtr->elide;
			    info.elidePriority = tagPtr->priority;
			}
		    }
		}
	    }
	}

1364
1365
1366
1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395

1396
1397

1398
1399
1400
1401
1402
1403
1404
1349
1350
1351
1352
1353
1354
1355

1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379

1380
1381

1382
1383
1384
1385
1386
1387
1388
1389







-
+











-
+











-
+

-
+








    while (segPtr != NULL) {
	/*
	 * Every logical line still gets at least one chunk due to
	 * expectations in the rest of the code, but we are able to skip
	 * elided portions of the line quickly.
	 *
	 * If current chunk is elided and last chunk was too, coalesce.
	 * If current chunk is elided and last chunk was too, coalese.
	 *
	 * This also means that each logical line which is entirely elided
	 * still gets laid out into a DLine, but with zero height. This isn't
	 * particularly a problem, but it does seem somewhat unnecessary. We
	 * may wish to redesign the code to remove these zero height DLines in
	 * the future.
	 */

	if (elide && (lastChunkPtr != NULL)
		&& (lastChunkPtr->displayProc == NULL /*ElideDisplayProc*/)) {
	    elidesize = segPtr->size - byteOffset;
	    if (segPtr->size > byteOffset) {
	    if (elidesize > 0) {
		curIndex.byteIndex += elidesize;
		lastChunkPtr->numBytes += elidesize;
		breakByteOffset = lastChunkPtr->breakIndex
			= lastChunkPtr->numBytes;

		/*
		 * If have we have a tag toggle, there is a chance that
		 * invisibility state changed, so bail out.
		 */
	    } else if ((segPtr->typePtr == &tkTextToggleOffType)
		    || (segPtr->typePtr == &tkTextToggleOnType)) {
		if (segPtr->body.toggle.tagPtr->elide >= 0) {
		if (segPtr->body.toggle.tagPtr->elideString != NULL) {
		    elide = (segPtr->typePtr == &tkTextToggleOffType)
			    ^ (segPtr->body.toggle.tagPtr->elide > 0);
			    ^ segPtr->body.toggle.tagPtr->elide;
		}
	    }

	    byteOffset = 0;
	    segPtr = segPtr->nextPtr;

	    if (segPtr == NULL) {
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1417
1418
1419
1420
1421
1422
1423

1424
1425
1426
1427
1428
1429
1430
1431







-
+








	if (segPtr->typePtr->layoutProc == NULL) {
	    segPtr = segPtr->nextPtr;
	    byteOffset = 0;
	    continue;
	}
	if (chunkPtr == NULL) {
	    chunkPtr = (TkTextDispChunk *)ckalloc(sizeof(TkTextDispChunk));
	    chunkPtr = ckalloc(sizeof(TkTextDispChunk));
	    chunkPtr->nextPtr = NULL;
	    chunkPtr->clientData = NULL;
	}
	chunkPtr->stylePtr = GetStyle(textPtr, &curIndex);
	elide = chunkPtr->stylePtr->sValuePtr->elide;

	/*
1505
1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517
1518
1519
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504







-
+







			maxBytes = (p + 1 - segPtr->body.chars) - byteOffset;
			gotTab = 1;
			break;
		    }
		}
	    }

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
	    if (baseCharChunkPtr != NULL) {
		int expectedX =
			((BaseCharInfo *) baseCharChunkPtr->clientData)->width
			+ baseCharChunkPtr->x;

		if ((expectedX != x) || !IsSameFGStyle(
			baseCharChunkPtr->stylePtr, chunkPtr->stylePtr)) {
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1632
1633
1634
1635
1636
1637
1638

1639
1640
1641
1642
1643
1644
1645
1646







-
+







		    goto connectNextLogicalLine;
		}
	    }
	}

	chunkPtr = NULL;
    }
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
    FinalizeBaseChunk(NULL);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */
    if (noCharsYet) {
	dlPtr->spaceAbove = 0;
	dlPtr->spaceBelow = 0;
	dlPtr->length = 0;

1706
1707
1708
1709
1710
1711
1712
1713

1714
1715
1716
1717
1718
1719
1720
1691
1692
1693
1694
1695
1696
1697

1698
1699
1700
1701
1702
1703
1704
1705







-
+







	    if (breakChunkPtr->undisplayProc != NULL) {
		breakChunkPtr->undisplayProc(textPtr, breakChunkPtr);
	    }
	    segPtr = TkTextIndexToSeg(&breakIndex, &byteOffset);
	    segPtr->typePtr->layoutProc(textPtr, &breakIndex, segPtr,
		    byteOffset, maxX, breakByteOffset, 0, wrapMode,
		    breakChunkPtr);
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
	    FinalizeBaseChunk(NULL);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */
	}
	lastChunkPtr = breakChunkPtr;
	wholeLine = 0;
    }

1830
1831
1832
1833
1834
1835
1836
1837
1838


1839
1840
1841
1842
1843
1844
1845
1815
1816
1817
1818
1819
1820
1821


1822
1823
1824
1825
1826
1827
1828
1829
1830







-
-
+
+







 *----------------------------------------------------------------------
 */

static void
UpdateDisplayInfo(
    TkText *textPtr)		/* Text widget to update. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    DLine *dlPtr, *prevPtr;
    register TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    register DLine *dlPtr, *prevPtr;
    TkTextIndex index;
    TkTextLine *lastLinePtr;
    int y, maxY, xPixelOffset, maxOffset, lineHeight;

    if (!(dInfoPtr->flags & DINFO_OUT_OF_DATE)) {
	return;
    }
1868
1869
1870
1871
1872
1873
1874
1875

1876
1877
1878
1879
1880
1881
1882
1853
1854
1855
1856
1857
1858
1859

1860
1861
1862
1863
1864
1865
1866
1867







-
+







    lastLinePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, textPtr,
	    TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr));
    dlPtr = dInfoPtr->dLinePtr;
    prevPtr = NULL;
    y = dInfoPtr->y - dInfoPtr->newTopPixelOffset;
    maxY = dInfoPtr->maxY;
    while (1) {
	DLine *newPtr;
	register DLine *newPtr;

	if (index.linePtr == lastLinePtr) {
	    break;
	}

	/*
	 * There are three possibilities right now:
1979
1980
1981
1982
1983
1984
1985
1986

1987
1988
1989
1990
1991
1992
1993
1964
1965
1966
1967
1968
1969
1970

1971
1972
1973
1974
1975
1976
1977
1978







-
+








	/*
	 * If we switched text lines, delete any DLines left for the old text
	 * line.
	 */

	if (index.linePtr != prevPtr->index.linePtr) {
	    DLine *nextPtr;
	    register DLine *nextPtr;

	    nextPtr = dlPtr;
	    while ((nextPtr != NULL)
		    && (nextPtr->index.linePtr == prevPtr->index.linePtr)) {
		nextPtr = nextPtr->nextPtr;
	    }
	    if (nextPtr != dlPtr) {
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
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







-
+












-
-
+
+


















-
+







 *
 *----------------------------------------------------------------------
 */

static void
FreeDLines(
    TkText *textPtr,		/* Information about overall text widget. */
    DLine *firstPtr,	/* Pointer to first DLine to free up. */
    register DLine *firstPtr,	/* Pointer to first DLine to free up. */
    DLine *lastPtr,		/* Pointer to DLine just after last one to
				 * free (NULL means everything starting with
				 * firstPtr). */
    int action)			/* DLINE_UNLINK means DLines are currently
				 * linked into the list rooted at
				 * textPtr->dInfoPtr->dLinePtr and they have
				 * to be unlinked. DLINE_FREE means just free
				 * without unlinking. DLINE_FREE_TEMP means
				 * the DLine given is just a temporary one and
				 * we shouldn't invalidate anything for the
				 * overall widget. */
{
    TkTextDispChunk *chunkPtr, *nextChunkPtr;
    DLine *nextDLinePtr;
    register TkTextDispChunk *chunkPtr, *nextChunkPtr;
    register DLine *nextDLinePtr;

    if (action == DLINE_FREE_TEMP) {
	lineHeightsRecalculated++;
	if (tkTextDebug) {
	    char string[TK_POS_CHARS];

	    /*
	     * Debugging is enabled, so keep a log of all the lines whose
	     * height was recalculated. The test suite uses this information.
	     */

	    TkTextPrintIndex(textPtr, &firstPtr->index, string);
	    LOG("tk_textHeightCalc", string);
	}
    } else if (action == DLINE_UNLINK) {
	if (textPtr->dInfoPtr->dLinePtr == firstPtr) {
	    textPtr->dInfoPtr->dLinePtr = lastPtr;
	} else {
	    DLine *prevPtr;
	    register DLine *prevPtr;

	    for (prevPtr = textPtr->dInfoPtr->dLinePtr;
		    prevPtr->nextPtr != firstPtr; prevPtr = prevPtr->nextPtr) {
		/* Empty loop body. */
	    }
	    prevPtr->nextPtr = lastPtr;
	}
2429
2430
2431
2432
2433
2434
2435
2436

2437
2438
2439
2440
2441
2442
2443

2444
2445
2446
2447
2448
2449
2450
2414
2415
2416
2417
2418
2419
2420

2421
2422
2423
2424
2425
2426
2427

2428
2429
2430
2431
2432
2433
2434
2435







-
+






-
+







 *
 *----------------------------------------------------------------------
 */

static void
DisplayDLine(
    TkText *textPtr,		/* Text widget in which to draw line. */
    DLine *dlPtr,	/* Information about line to draw. */
    register DLine *dlPtr,	/* Information about line to draw. */
    DLine *prevPtr,		/* Line just before one to draw, or NULL if
				 * dlPtr is the top line. */
    Pixmap pixmap)		/* Pixmap to use for double-buffering. Caller
				 * must make sure it's large enough to hold
				 * line. */
{
    TkTextDispChunk *chunkPtr;
    register TkTextDispChunk *chunkPtr;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    Display *display;
    int height, y_off;
#ifndef TK_NO_DOUBLE_BUFFERING
    const int y = 0;
#else
    const int y = dlPtr->y;
2462
2463
2464
2465
2466
2467
2468
2469

2470
2471
2472
2473
2474
2475
2476
2447
2448
2449
2450
2451
2452
2453

2454
2455
2456
2457
2458
2459
2460
2461







-
+







	y_off = dInfoPtr->y - dlPtr->y;
	height -= y_off;
    } else {
	y_off = 0;
    }

#ifdef TK_NO_DOUBLE_BUFFERING
    Tk_ClipDrawableToRect(display, pixmap, dInfoPtr->x, y + y_off,
    TkpClipDrawableToRect(display, pixmap, dInfoPtr->x, y + y_off,
	    dInfoPtr->maxX - dInfoPtr->x, height);
#endif /* TK_NO_DOUBLE_BUFFERING */

    /*
     * First, clear the area of the line to the background color for the text
     * widget.
     */
2501
2502
2503
2504
2505
2506
2507
2508

2509
2510
2511
2512
2513
2514
2515
2486
2487
2488
2489
2490
2491
2492

2493
2494
2495
2496
2497
2498
2499
2500







-
+







    /*
     * Make another pass through all of the chunks to redraw the insertion
     * cursor, if it is visible on this line. Must do it here rather than in
     * the foreground pass below because otherwise a wide insertion cursor
     * will obscure the character to its left.
     */

    if (textPtr->state != TK_TEXT_STATE_DISABLED) {
    if (textPtr->state == TK_TEXT_STATE_NORMAL) {
	for (chunkPtr = dlPtr->chunkPtr; (chunkPtr != NULL);
		chunkPtr = chunkPtr->nextPtr) {
	    if (chunkPtr->displayProc == TkTextInsertDisplayProc) {
		int x = chunkPtr->x + dInfoPtr->x - dInfoPtr->curXPixelOffset;

		chunkPtr->displayProc(textPtr, chunkPtr, x,
			y + dlPtr->spaceAbove,
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
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







-
-
-
-
-
-
-



















-
+







	    }
	    chunkPtr->displayProc(textPtr, chunkPtr, x,
		    y + dlPtr->spaceAbove, dlPtr->height - dlPtr->spaceAbove -
		    dlPtr->spaceBelow, dlPtr->baseline - dlPtr->spaceAbove,
		    display, pixmap, dlPtr->y + dlPtr->spaceAbove);
	}

	if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
	    /*
	     * A displayProc called in the loop above invoked a binding
	     * that caused the widget to be deleted. Don't do anything.
	     */
	    return;
	}
	if (dInfoPtr->dLinesInvalidated) {
	    return;
	}
    }

#ifndef TK_NO_DOUBLE_BUFFERING
    /*
     * Copy the pixmap onto the screen. If this is the first or last line on
     * the screen then copy a piece of the line, so that it doesn't overflow
     * into the border area. Another special trick: copy the padding area to
     * the left of the line; this is because the insertion cursor sometimes
     * overflows onto that area and we want to get as much of the cursor as
     * possible.
     */

    XCopyArea(display, pixmap, Tk_WindowId(textPtr->tkwin), dInfoPtr->copyGC,
	    dInfoPtr->x, y + y_off, (unsigned) (dInfoPtr->maxX - dInfoPtr->x),
	    (unsigned) height, dInfoPtr->x, dlPtr->y + y_off);
#else
    Tk_ClipDrawableToRect(display, pixmap, 0, 0, -1, -1);
    TkpClipDrawableToRect(display, pixmap, 0, 0, -1, -1);
#endif /* TK_NO_DOUBLE_BUFFERING */
    linesRedrawn++;
}

/*
 *--------------------------------------------------------------
 *
2615
2616
2617
2618
2619
2620
2621
2622

2623
2624
2625
2626
2627
2628
2629
2593
2594
2595
2596
2597
2598
2599

2600
2601
2602
2603
2604
2605
2606
2607







-
+







 *
 *--------------------------------------------------------------
 */

static void
DisplayLineBackground(
    TkText *textPtr,		/* Text widget containing line. */
    DLine *dlPtr,	/* Information about line to draw. */
    register DLine *dlPtr,	/* Information about line to draw. */
    DLine *prevPtr,		/* Line just above dlPtr, or NULL if dlPtr is
				 * the top-most line in the window. */
    Pixmap pixmap)		/* Pixmap to use for double-buffering. Caller
				 * must make sure it's large enough to hold
				 * line. Caller must also have filled it with
				 * the background color for the widget. */
{
2692
2693
2694
2695
2696
2697
2698
2699

2700
2701
2702
2703
2704
2705
2706
2670
2671
2672
2673
2674
2675
2676

2677
2678
2679
2680
2681
2682
2683
2684







-
+







	    continue;
	}
	sValuePtr = chunkPtr->stylePtr->sValuePtr;
	rightX = chunkPtr->x + chunkPtr->width;
	if ((chunkPtr->nextPtr == NULL) && (rightX < maxX)) {
	    rightX = maxX;
	}
	if (chunkPtr->stylePtr->bgGC != NULL) {
	if (chunkPtr->stylePtr->bgGC != None) {
	    /*
	     * Not visible - bail out now.
	     */

	    if (rightX + xOffset <= 0) {
		leftX = rightX;
		continue;
3009
3010
3011
3012
3013
3014
3015
3016

3017
3018

3019
3020
3021
3022
3023
3024
3025
2987
2988
2989
2990
2991
2992
2993

2994
2995

2996
2997
2998
2999
3000
3001
3002
3003







-
+

-
+







 *	Line heights may be recalculated.
 *
 *----------------------------------------------------------------------
 */

static void
AsyncUpdateLineMetrics(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    int lineNum;

    dInfoPtr->lineUpdateTimer = NULL;

    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)
            || !Tk_IsMapped(textPtr->tkwin)) {
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
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







-
+














-
-




-
-
+




-
+

-
+









+







	    dInfoPtr->lastMetricUpdateLine, 256);

    dInfoPtr->currentMetricUpdateLine = lineNum;

    if (tkTextDebug) {
	char buffer[2 * TCL_INTEGER_SPACE + 1];

	snprintf(buffer, sizeof(buffer), "%d %d", lineNum, dInfoPtr->lastMetricUpdateLine);
	sprintf(buffer, "%d %d", lineNum, dInfoPtr->lastMetricUpdateLine);
	LOG("tk_textInvalidateLine", buffer);
    }

    /*
     * If we're not in the middle of a long-line calculation (metricEpoch==-1)
     * and we've reached the last line, then we're done.
     */

    if (dInfoPtr->metricEpoch == -1
	    && lineNum == dInfoPtr->lastMetricUpdateLine) {
	/*
	 * We have looped over all lines, so we're done. We must release our
	 * refCount on the widget (the timer token was already set to NULL
	 * above). If there is a registered aftersync command, run that first.
	 * Cancel any pending idle task which would try to run the command
	 * after the afterSyncCmd pointer had been set to NULL.
	 */

        if (textPtr->afterSyncCmd) {
            int code;
	    Tcl_CancelIdleCall(TkTextRunAfterSyncCmd, textPtr);
            Tcl_Preserve(textPtr->interp);
            Tcl_Preserve((ClientData) textPtr->interp);
            code = Tcl_EvalObjEx(textPtr->interp, textPtr->afterSyncCmd,
                    TCL_EVAL_GLOBAL);
	    if (code == TCL_ERROR) {
                Tcl_AddErrorInfo(textPtr->interp, "\n    (text sync)");
                Tcl_BackgroundException(textPtr->interp, TCL_ERROR);
                Tcl_BackgroundError(textPtr->interp);
	    }
            Tcl_Release(textPtr->interp);
            Tcl_Release((ClientData) textPtr->interp);
            Tcl_DecrRefCount(textPtr->afterSyncCmd);
            textPtr->afterSyncCmd = NULL;
	}

        /*
         * Fire the <<WidgetViewSync>> event since the widget view is in sync
         * with its internal data (actually it will be after the next trip
         * through the event loop, because the widget redraws at idle-time).
         */

        GenerateWidgetViewSyncEvent(textPtr, 1);

	if (textPtr->refCount-- <= 1) {
	    ckfree(textPtr);
	}
	return;
    }
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
3171
3172
3173
3174
3175
3176


3177
3178
3179
3180
3181
3182
3183
3184
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







-
+
-
-
-
-
-
-
-
+















-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-








/*
 *----------------------------------------------------------------------
 *
 * GenerateWidgetViewSyncEvent --
 *
 *      Send the <<WidgetViewSync>> event related to the text widget
 *      line metrics asynchronous update.  These events should only
 *      line metrics asynchronous update.
 *      be sent when the sync status has changed.  So this function
 *      compares the requested state with the state saved in the
 *      TkText structure, and only generates the event if they are
 *      different.  This means that it is safe to call this function
 *      at any time when the state is known.
 *
 *      If an event is sent, the effect is equivalent to:
 *      This is equivalent to:
 *         event generate $textWidget <<WidgetViewSync>> -data $s
 *      where $s is the sync status: true (when the widget view is in
 *      sync with its internal data) or false (when it is not).
 *
 * Results:
 *      None
 *
 * Side effects:
 *      If corresponding bindings are present, they will trigger.
 *
 *----------------------------------------------------------------------
 */

static void
GenerateWidgetViewSyncEvent(
    TkText *textPtr,	  /* Information about text widget. */
    Bool InSync)          /* true if becoming in sync, false otherwise */
    TkText *textPtr,		/* Information about text widget. */
    Bool InSync)                /* true if in sync, false otherwise */
{
    Bool NewSyncState = (InSync != 0); /* ensure 0 or 1 value */
    Bool OldSyncState = !(textPtr->dInfoPtr->flags & OUT_OF_SYNC);

    /*
     * OSX 10.14 needs to be told to display the window when the Text Widget
     * is in sync.  (That is, to run DisplayText inside of the drawRect
     * method.)  Otherwise the screen might not get updated until an event
     * like a mouse click is received.  But that extra drawing corrupts the
     * data that the test suite is trying to collect.
     */

    if (!tkTextDebug) {
	TkpRedrawWidget(textPtr->tkwin);
    }

    if (NewSyncState != OldSyncState) {
	if (NewSyncState) {
	    textPtr->dInfoPtr->flags &= ~OUT_OF_SYNC;
	} else {
	    textPtr->dInfoPtr->flags |= OUT_OF_SYNC;
	}
	Tk_SendVirtualEvent(textPtr->tkwin, "WidgetViewSync",
		Tcl_NewBooleanObj(NewSyncState));
    TkSendVirtualEvent(textPtr->tkwin, "WidgetViewSync",
        Tcl_NewBooleanObj(InSync));
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkTextUpdateLineMetrics --
 *
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3161
3162
3163
3164
3165
3166
3167



3168
3169
3170
3171
3172
3173
3174
3175
3176
3177

3178
3179
3180
3181
3182
3183
3184







-
-
-










-







				 * lines to recalculate. If '-1' then do
				 * everything in the range (which may take a
				 * while). */
{
    TkTextLine *linePtr = NULL;
    int count = 0;
    int totalLines = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr);
    int fullUpdateRequested = (lineNum == 0 &&
                               endLine == totalLines &&
                               doThisMuch == -1);

    if (totalLines == 0) {
	/*
	 * Empty peer widget.
	 */

	return endLine;
    }

    while (1) {

	/*
	 * Get a suitable line.
	 */

	if (lineNum == -1 && linePtr == NULL) {
	    lineNum = 0;
	    linePtr = TkBTreeFindLine(textPtr->sharedTextPtr->tree, textPtr,
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274

3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3197
3198
3199
3200
3201
3202
3203


3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215

3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226

3227
3228
3229
3230

3231
3232
3233
3234
3235
3236
3237







-
-












-
+










-




-








	    /*
	     * If we're in the middle of a partial-line height calculation,
	     * then we can't be done.
	     */

	    if (textPtr->dInfoPtr->metricEpoch == -1 && lineNum == endLine) {


		/*
		 * We have looped over all lines, so we're done.
		 */

		break;
	    }
	}

	if (lineNum < totalLines) {
	    if (tkTextDebug) {
		char buffer[4 * TCL_INTEGER_SPACE + 3];

		snprintf(buffer, sizeof(buffer), "%d %d %d %d",
		sprintf(buffer, "%d %d %d %d",
			lineNum, endLine, totalLines, count);
		LOG("tk_textInvalidateLine", buffer);
	    }

	    /*
	     * Now update the line's metrics if necessary.
	     */

	    if (TkBTreeLinePixelEpoch(textPtr, linePtr)
		    == textPtr->dInfoPtr->lineMetricUpdateEpoch) {

		/*
		 * This line is already up to date. That means there's nothing
		 * to do here.
		 */

	    } else if (doThisMuch == -1) {
		count += 8 * TkTextUpdateOneLine(textPtr, linePtr, 0,NULL,0);
	    } else {
		TkTextIndex index;
		TkTextIndex *indexPtr;
		int pixelHeight;

3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3245
3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258







-








		if (textPtr->dInfoPtr->metricEpoch ==
			textPtr->sharedTextPtr->stateEpoch &&
			textPtr->dInfoPtr->metricIndex.linePtr==linePtr) {
		    indexPtr = &textPtr->dInfoPtr->metricIndex;
		    pixelHeight = textPtr->dInfoPtr->metricPixelHeight;
		} else {

		    /*
		     * We must reset the partial line height calculation data
		     * here, so we don't use it when it is out of date.
		     */

		    textPtr->dInfoPtr->metricEpoch = -1;
		    index.tree = textPtr->sharedTextPtr->tree;
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3268
3269
3270
3271
3272
3273
3274

3275
3276
3277
3278
3279
3280
3281
3282

3283
3284
3285
3286
3287
3288
3289







-








-







		 * display line we actually re-layout.
		 */

		count += 8 * TkTextUpdateOneLine(textPtr, linePtr,
			pixelHeight, indexPtr, 1);

		if (indexPtr->linePtr == linePtr) {

		    /*
		     * We didn't complete the logical line, because it
		     * produced very many display lines, which must be because
		     * it must be a long line wrapped many times. So we must
		     * cache as far as we got for next time around.
		     */

		    if (pixelHeight == 0) {

			/*
			 * These have already been stored, unless we just
			 * started the new line.
			 */

			textPtr->dInfoPtr->metricIndex = index;
			textPtr->dInfoPtr->metricEpoch =
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3297
3298
3299
3300
3301
3302
3303

3304
3305
3306
3307
3308
3309
3310







-







		/*
		 * We're done with this long line.
		 */

		textPtr->dInfoPtr->metricEpoch = -1;
	    }
	} else {

	    /*
	     * We must never recalculate the height of the last artificial
	     * line. It must stay at zero, and if we recalculate it, it will
	     * change.
	     */

	    if (endLine >= totalLines) {
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395


3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3321
3322
3323
3324
3325
3326
3327

3328


3329
3330
3331
3332
3333
3334



3335
3336
3337
3338
3339
3340
3341







-

-
-
+
+




-
-
-







	count++;

	if (doThisMuch != -1 && count >= doThisMuch) {
	    break;
	}
    }
    if (doThisMuch == -1) {

	/*
	 * If we were requested to update the entire range, then also update
	 * the scrollbar.
	 * If we were requested to provide a full update, then also update the
	 * scrollbar.
	 */

	GetYView(textPtr->interp, textPtr, 1);
    }
    if (fullUpdateRequested) {
        GenerateWidgetViewSyncEvent(textPtr, 1);
    }
    return lineNum;
}

/*
 *----------------------------------------------------------------------
 *
 * TkTextInvalidateLineMetrics, TextInvalidateLineMetrics --
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437







3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456





3457
3458
3459
3460
3461
3462
3463
3356
3357
3358
3359
3360
3361
3362







3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383





3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395







-
-
-
-
-
-
-
+
+
+
+
+
+
+














-
-
-
-
-
+
+
+
+
+







 *	May schedule an asychronous callback.
 *
 *----------------------------------------------------------------------
 */

void
TkTextInvalidateLineMetrics(
    TkSharedText *sharedTextPtr,    /* Shared widget section for all peers, or
				     * NULL. */
    TkText *textPtr,		    /* Widget record for text widget. */
    TkTextLine *linePtr,	    /* Invalidation starts from this line. */
    int lineCount,		    /* And includes this many following lines. */
    TkTextInvalidateAction action)  /* Indicates what type of invalidation
				     * occurred, TK_TEXT_INVALIDATE_(ONLY|INSERT|DELETE). */
    TkSharedText *sharedTextPtr,/* Shared widget section for all peers, or
				 * NULL. */
    TkText *textPtr,		/* Widget record for text widget. */
    TkTextLine *linePtr,	/* Invalidation starts from this line. */
    int lineCount,		/* And includes this many following lines. */
    int action)			/* Indicates what type of invalidation
				 * occurred (insert, delete, or simple). */
{
    if (sharedTextPtr == NULL) {
	TextInvalidateLineMetrics(textPtr, linePtr, lineCount, action);
    } else {
	textPtr = sharedTextPtr->peers;
	while (textPtr != NULL) {
	    TextInvalidateLineMetrics(textPtr, linePtr, lineCount, action);
	    textPtr = textPtr->next;
	}
    }
}

static void
TextInvalidateLineMetrics(
    TkText *textPtr,		    /* Widget record for text widget. */
    TkTextLine *linePtr,	    /* Invalidation starts from this line. */
    int lineCount,		    /* And includes this many following lines. */
    TkTextInvalidateAction action)  /* Indicates what type of invalidation
				     * occurred, TK_TEXT_INVALIDATE_(ONLY|INSERT|DELETE). */
    TkText *textPtr,		/* Widget record for text widget. */
    TkTextLine *linePtr,	/* Invalidation starts from this line. */
    int lineCount,		/* And includes this many following lines. */
    int action)			/* Indicates what type of invalidation
				 * occurred (insert, delete, or simple). */
{
    int fromLine;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;

    if (linePtr != NULL) {
	int counter = lineCount;

3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576


3577
3578
3579
3580
3581
3582
3583
3496
3497
3498
3499
3500
3501
3502






3503
3504
3505
3506
3507
3508
3509
3510
3511







-
-
-
-
-
-
+
+







     * Now re-set the current update calculations.
     */

    if (dInfoPtr->lineUpdateTimer == NULL) {
	textPtr->refCount++;
	dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		AsyncUpdateLineMetrics, textPtr);
    }

    /*
     * The widget is out of sync: send a <<WidgetViewSync>> event.
     */
    GenerateWidgetViewSyncEvent(textPtr, 0);
        GenerateWidgetViewSyncEvent(textPtr, 0);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkTextFindDisplayLineEnd --
 *
3667
3668
3669
3670
3671
3672
3673
3674

3675
3676
3677
3678
3679
3680
3681
3595
3596
3597
3598
3599
3600
3601

3602
3603
3604
3605
3606
3607
3608
3609







-
+








	index = endOfLastLine;
	index.byteIndex = 0;
    }

    while (1) {
	DLine *dlPtr;
	Tcl_Size byteCount;
	int byteCount;
	TkTextIndex nextLineStart;

	dlPtr = LayoutDLine(textPtr, &index);
	byteCount = dlPtr->byteCount;

	TkTextIndexForwBytes(textPtr, &index, byteCount, &nextLineStart);

4137
4138
4139
4140
4141
4142
4143
4144

4145
4146
4147
4148
4149
4150
4151
4065
4066
4067
4068
4069
4070
4071

4072
4073
4074
4075
4076
4077
4078
4079







-
+







    if (tkTextDebug) {
	char buffer[2 * TCL_INTEGER_SPACE + 1];

	if (TkBTreeNextLine(textPtr, linePtr) == NULL) {
	    Tcl_Panic("Mustn't ever update line height of last artificial line");
	}

	snprintf(buffer, sizeof(buffer), "%d %d", TkBTreeLinesTo(textPtr,linePtr), pixelHeight);
	sprintf(buffer, "%d %d", TkBTreeLinesTo(textPtr,linePtr), pixelHeight);
	LOG("tk_textNumPixels", buffer);
    }
    if (textPtr->dInfoPtr->scrollbarTimer == NULL) {
	textPtr->refCount++;
	textPtr->dInfoPtr->scrollbarTimer = Tcl_CreateTimerHandler(200,
		AsyncUpdateYScrollbar, textPtr);
    }
4167
4168
4169
4170
4171
4172
4173
4174

4175
4176

4177
4178

4179
4180
4181
4182
4183
4184
4185












4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215

4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226

4227
4228
4229
4230
4231

4232
4233
4234
4235
4236
4237
4238
4095
4096
4097
4098
4099
4100
4101

4102
4103

4104
4105

4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
















4135
4136
4137
4138

4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149

4150
4151
4152
4153
4154

4155
4156
4157
4158
4159
4160
4161
4162







-
+

-
+

-
+







+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+










-
+




-
+







 *	Information is redrawn on the screen.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayText(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    DLine *dlPtr;
    register DLine *dlPtr;
    DLine *prevPtr;
    Pixmap pixmap;
    int maxHeight, borders;
    int bottomY = 0;		/* Initialization needed only to stop compiler
				 * warnings. */
    Tcl_Interp *interp;

#ifdef MAC_OSX_TK
    /*
     * If drawing is disabled, all we need to do is
     * clear the REDRAW_PENDING flag.
     */
    TkWindow *winPtr = (TkWindow *)(textPtr->tkwin);
    MacDrawable *macWin = winPtr->privatePtr;
    if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){
	dInfoPtr->flags &= ~REDRAW_PENDING;
	return;
    }
#endif

    if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
	/*
	 * The widget has been deleted.	 Don't do anything.
	 */

	return;
    }

#ifdef MAC_OSX_TK
    /*
     * If the toplevel is being resized it would be dangerous to try redrawing
     * the widget.  But we can just clear the REDRAW_PENDING flag and return.
     * This display proc will be called again after the widget has been
     * reconfigured.
     */

    TkWindow *winPtr = (TkWindow *)(textPtr->tkwin);
    MacDrawable *macWin = winPtr->privatePtr;
    if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){
	dInfoPtr->flags &= ~REDRAW_PENDING;
    	return;
     }
#endif

    interp = textPtr->interp;
    Tcl_Preserve(interp);

    if (tkTextDebug) {
	CLEAR("tk_textRelayout");
	Tcl_SetVar2(interp, "tk_textRelayout", NULL, "", TCL_GLOBAL_ONLY);
    }

    if (!Tk_IsMapped(textPtr->tkwin) || (dInfoPtr->maxX <= dInfoPtr->x)
	    || (dInfoPtr->maxY <= dInfoPtr->y)) {
	UpdateDisplayInfo(textPtr);
	dInfoPtr->flags &= ~REDRAW_PENDING;
	goto doScrollbars;
    }
    numRedisplays++;
    if (tkTextDebug) {
	CLEAR("tk_textRedraw");
	Tcl_SetVar2(interp, "tk_textRedraw", NULL, "", TCL_GLOBAL_ONLY);
    }

    /*
     * Choose a new current item if that is needed (this could cause event
     * handlers to be invoked, hence the refcount management and the loop,
     * handlers to be invoked, hence the preserve/release calls and the loop,
     * since the handlers could conceivably necessitate yet another current
     * item calculation). The tkwin check is because the whole window could go
     * away in the Tcl_Release call.
     */

    while (dInfoPtr->flags & REPICK_NEEDED) {
	textPtr->refCount++;
4259
4260
4261
4262
4263
4264
4265
4266

4267
4268
4269
4270
4271
4272
4273
4183
4184
4185
4186
4187
4188
4189

4190
4191
4192
4193
4194
4195
4196
4197







-
+







     * scrolling (copying from other parts of the screen). We have to be
     * particularly careful with the top and bottom lines of the display,
     * since these may only be partially visible and therefore not helpful for
     * some scrolling purposes.
     */

    for (dlPtr = dInfoPtr->dLinePtr; dlPtr != NULL; dlPtr = dlPtr->nextPtr) {
	DLine *dlPtr2;
	register DLine *dlPtr2;
	int offset, height, y, oldY;
	TkRegion damageRgn;

	/*
	 * These tests are, in order:
	 *
	 * 1. If the line is already marked as invalid
4346
4347
4348
4349
4350
4351
4352

4353
4354
4355
4356
4357
4358
4359
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284







+








	    dlPtr->oldY = dlPtr->y;
	    if (dlPtr->nextPtr == dlPtr2) {
		break;
	    }
	    dlPtr = dlPtr->nextPtr;
	}

	/*
	 * Scan through the lines following the copied ones to see if we are
	 * going to overwrite them with the copy operation. If so, mark them
	 * for redisplay.
	 */

	for ( ; dlPtr2 != NULL; dlPtr2 = dlPtr2->nextPtr) {
4369
4370
4371
4372
4373
4374
4375

4376

4377
4378
4379
4380
4381
4382
4383
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310







+

+







	 * calling TextInvalidateRegion to mark the display blocks as stale.
	 */

	damageRgn = TkCreateRegion();
	if (TkScrollWindow(textPtr->tkwin, dInfoPtr->scrollGC, dInfoPtr->x,
		oldY, dInfoPtr->maxX-dInfoPtr->x, height, 0, y-oldY,
		damageRgn)) {
#ifndef MAC_OSX_TK
	    TextInvalidateRegion(textPtr, damageRgn);
#endif
	}
	numCopies++;
	TkDestroyRegion(damageRgn);
    }

    /*
     * Clear the REDRAW_PENDING flag here. This is actually pretty tricky. We
4418
4419
4420
4421
4422
4423
4424
4425

4426
4427
4428

4429
4430
4431
4432
4433
4434
4435
4345
4346
4347
4348
4349
4350
4351

4352
4353
4354

4355
4356
4357
4358
4359
4360
4361
4362







-
+


-
+







	    GC fgGC, bgGC;

	    bgGC = Tk_GCForColor(textPtr->highlightBgColorPtr,
		    Tk_WindowId(textPtr->tkwin));
	    if (textPtr->flags & GOT_FOCUS) {
		fgGC = Tk_GCForColor(textPtr->highlightColorPtr,
			Tk_WindowId(textPtr->tkwin));
		Tk_DrawHighlightBorder(textPtr->tkwin, fgGC, bgGC,
		TkpDrawHighlightBorder(textPtr->tkwin, fgGC, bgGC,
			textPtr->highlightWidth, Tk_WindowId(textPtr->tkwin));
	    } else {
		Tk_DrawHighlightBorder(textPtr->tkwin, bgGC, bgGC,
		TkpDrawHighlightBorder(textPtr->tkwin, bgGC, bgGC,
			textPtr->highlightWidth, Tk_WindowId(textPtr->tkwin));
	    }
	}
	borders = textPtr->borderWidth + textPtr->highlightWidth;
	if (textPtr->padY > 0) {
	    Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
		    textPtr->border, borders, borders,
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521

4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556



4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4430
4431
4432
4433
4434
4435
4436







4437
4438
4439
4440

4441
4442
4443
4444



























4445
4446



4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462


4463
4464
4465
4466
4467
4468
4469







-
-
-
-
-
-
-




-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
+
+
+













-
-







		if (tkTextDebug) {
		    char string[TK_POS_CHARS];

		    TkTextPrintIndex(textPtr, &dlPtr->index, string);
		    LOG("tk_textRedraw", string);
		}
		DisplayDLine(textPtr, dlPtr, prevPtr, pixmap);
		if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
		    /*
		     * DisplayDLine called a displayProc which invoked a binding
		     * that caused the widget to be deleted. Don't do anything.
		     */
		    goto end;
		}
		if (dInfoPtr->dLinesInvalidated) {
#ifndef TK_NO_DOUBLE_BUFFERING
		    Tk_FreePixmap(Tk_Display(textPtr->tkwin), pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
		    goto end;
		    return;
		}
		dlPtr->oldY = dlPtr->y;
		dlPtr->flags &= ~(NEW_LAYOUT | OLD_Y_INVALID);
#ifdef MAC_OSX_TK
	    } else if (dlPtr->chunkPtr != NULL) {
		/*
		 * On macOS we need to redisplay all embedded windows which
		 * were moved by the call to TkScrollWindows above.  This is
		 * not necessary on Unix or Windows because XScrollWindow will
		 * have included the bounding rectangles of all of these
		 * windows in the damage region.  The macosx implementation of
		 * TkScrollWindow does not do this.  It simply generates a
		 * damage region which is the scroll source rectangle minus
		 * the scroll destination rectangle.  This is because there is
		 * no efficient process available for iterating through the
		 * subwindows which meet the scrolled area.  (On Unix this is
		 * handled by GraphicsExpose events generated by XCopyArea and
		 * on Windows by ScrollWindowEx.  On macOS the low level
		 * scrolling is accomplished by calling [view scrollRect:by:].
		 * This method does not provide any damage information and, in
		 * any case, could not be aware of Tk windows which were not
		 * based on NSView objects.
		 *
		 * On the other hand, this loop is already iterating through
		 * all embedded windows which could possibly have been moved
		 * by the scrolling.  So it is as efficient to redisplay them
		 * here as it would have been if they had been redisplayed by
		 * the call to TextInvalidateRegion above.
		 */
#else
	    } else if (dlPtr->chunkPtr != NULL && ((dlPtr->y < 0)
		    || (dlPtr->y + dlPtr->height > dInfoPtr->maxY))) {
		/*
		 * On platforms other than the Mac:
		 *
		register TkTextDispChunk *chunkPtr;

		/*
		 * It's the first or last DLine which are also overlapping the
		 * top or bottom of the window, but we decided above it wasn't
		 * necessary to display them (we were able to update them by
		 * scrolling). This is fine, except that if the lines contain
		 * any embedded windows, we must still call the display proc
		 * on them because they might need to be unmapped or they
		 * might need to be moved to reflect their new position.
		 * Otherwise, everything else moves, but the embedded window
		 * doesn't!
		 *
		 * So, we loop through all the chunks, calling the display
		 * proc of embedded windows only.
		 */
#endif
		TkTextDispChunk *chunkPtr;

		for (chunkPtr = dlPtr->chunkPtr; (chunkPtr != NULL);
			chunkPtr = chunkPtr->nextPtr) {
		    int x;
		    if (chunkPtr->displayProc != TkTextEmbWinDisplayProc) {
			continue;
		    }
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604

4605

4606
4607
4608
4609
4610
4611
4612
4478
4479
4480
4481
4482
4483
4484






4485
4486
4487
4488

4489
4490
4491
4492
4493
4494
4495
4496
4497
4498







-
-
-
-
-
-




-
+

+







			 * as being off-screen to the left (the displayProc
			 * may not be able to tell if something is off to the
			 * right).
			 */

			x = -chunkPtr->width;
		    }
		    if (tkTextDebug) {
			char string[TK_POS_CHARS];

			TkTextPrintIndex(textPtr, &dlPtr->index, string);
			LOG("tk_textEmbWinDisplay", string);
		    }
		    TkTextEmbWinDisplayProc(textPtr, chunkPtr, x,
			    dlPtr->spaceAbove,
			    dlPtr->height-dlPtr->spaceAbove-dlPtr->spaceBelow,
			    dlPtr->baseline - dlPtr->spaceAbove, NULL,
			    None, dlPtr->y + dlPtr->spaceAbove);
			    (Drawable) None, dlPtr->y + dlPtr->spaceAbove);
		}

	    }
	}
#ifndef TK_NO_DOUBLE_BUFFERING
	Tk_FreePixmap(Tk_Display(textPtr->tkwin), pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
    }

4645
4646
4647
4648
4649
4650
4651
4652

4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668

4669
4670
4671
4672
4673
4674
4675
4531
4532
4533
4534
4535
4536
4537

4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553

4554
4555
4556
4557
4558
4559
4560
4561







-
+















-
+







     * clear REDRAW_PENDING here, just in case the scroll function does
     * something that requires redisplay.
     */

  doScrollbars:
    if (textPtr->flags & UPDATE_SCROLLBARS) {
	textPtr->flags &= ~UPDATE_SCROLLBARS;
	if (textPtr->yScrollCmdObj != NULL) {
	if (textPtr->yScrollCmd != NULL) {
	    GetYView(textPtr->interp, textPtr, 1);
	}

	if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
	    /*
	     * The widget has been deleted. Don't do anything.
	     */

	    goto end;
	}

	/*
	 * Update the horizontal scrollbar, if any.
	 */

	if (textPtr->xScrollCmdObj != NULL) {
	if (textPtr->xScrollCmd != NULL) {
	    GetXView(textPtr->interp, textPtr, 1);
	}
    }

  end:
    Tcl_Release(interp);
}
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754

4755
4756
4757
4758
4759
4760
4761
4624
4625
4626
4627
4628
4629
4630






4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642







-
-
-
-
-
-




+







    rect.y = y;
    rect.width = width;
    rect.height = height;
    TkUnionRectWithRegion(&rect, damageRgn, damageRgn);

    TextInvalidateRegion(textPtr, damageRgn);

    TkDestroyRegion(damageRgn);

    /*
     * Schedule the redisplay operation if there isn't one already scheduled.
     */

    if (!(dInfoPtr->flags & REDRAW_PENDING)) {
	dInfoPtr->flags |= REDRAW_PENDING;
	Tcl_DoWhenIdle(DisplayText, textPtr);
    }
    TkDestroyRegion(damageRgn);
}

/*
 *----------------------------------------------------------------------
 *
 * TextInvalidateRegion --
 *
4771
4772
4773
4774
4775
4776
4777
4778

4779
4780
4781
4782
4783
4784
4785
4652
4653
4654
4655
4656
4657
4658

4659
4660
4661
4662
4663
4664
4665
4666







-
+







 */

static void
TextInvalidateRegion(
    TkText *textPtr,		/* Widget record for text widget. */
    TkRegion region)		/* Region of area to redraw. */
{
    DLine *dlPtr;
    register DLine *dlPtr;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    int maxY, inset;
    XRectangle rect;

    /*
     * Find all lines that overlap the given region and mark them for
     * redisplay.
4795
4796
4797
4798
4799
4800
4801




4802
4803
4804
4805
4806
4807
4808
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693







+
+
+
+







	    dlPtr->flags |= OLD_Y_INVALID;
	}
    }
    if (dInfoPtr->topOfEof < maxY) {
	dInfoPtr->topOfEof = maxY;
    }

    /*
     * Schedule the redisplay operation if there isn't one already scheduled.
     */

    inset = textPtr->borderWidth + textPtr->highlightWidth;
    if ((rect.x < (inset + textPtr->padX))
	    || (rect.y < (inset + textPtr->padY))
	    || ((int) (rect.x + rect.width) > (Tk_Width(textPtr->tkwin)
		    - inset - textPtr->padX))
	    || (maxY > (Tk_Height(textPtr->tkwin) - inset - textPtr->padY))) {
	dInfoPtr->flags |= REDRAW_BORDERS;
5025
5026
5027
5028
5029
5030
5031
5032

5033
5034
5035
5036
5037
5038
5039
4910
4911
4912
4913
4914
4915
4916

4917
4918
4919
4920
4921
4922
4923
4924







-
+







    TkTextIndex *index2Ptr,	/* Character just after last one to consider
				 * for redisplay. NULL means process all the
				 * characters in the text. */
    TkTextTag *tagPtr,		/* Information about tag. */
    int withTag)		/* 1 means redraw characters that have the
				 * tag, 0 means redraw those without. */
{
    DLine *dlPtr;
    register DLine *dlPtr;
    DLine *endPtr;
    int tagOn;
    TkTextSearch search;
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    TkTextIndex *curIndexPtr;
    TkTextIndex endOfText, *endIndexPtr;

5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241

5242
5243
5244
5245
5246
5247
5248
5099
5100
5101
5102
5103
5104
5105

5106
5107
5108
5109
5110
5111
5112
5113

5114
5115
5116
5117
5118
5119
5120
5121
5122
5123

5124
5125
5126
5127
5128
5129
5130
5131







-








-










-
+







    TkText *textPtr,		/* Widget record for text widget. */
    int mask)			/* OR'd collection of bits showing what has
				 * changed. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    GC newGC;
    XGCValues gcValues;
    Bool inSync = 1;

    /*
     * Schedule the window redisplay. See TkTextChanged for the reason why
     * this has to be done before any calls to FreeDLines.
     */

    if (!(dInfoPtr->flags & REDRAW_PENDING)) {
	Tcl_DoWhenIdle(DisplayText, textPtr);
	inSync = 0;
    }
    dInfoPtr->flags |= REDRAW_PENDING|REDRAW_BORDERS|DINFO_OUT_OF_DATE
	    |REPICK_NEEDED;

    /*
     * (Re-)create the graphics context for drawing the traversal highlight.
     */

    gcValues.graphics_exposures = False;
    newGC = Tk_GetGC(textPtr->tkwin, GCGraphicsExposures, &gcValues);
    if (dInfoPtr->copyGC != NULL) {
    if (dInfoPtr->copyGC != None) {
	Tk_FreeGC(textPtr->display, dInfoPtr->copyGC);
    }
    dInfoPtr->copyGC = newGC;

    /*
     * Throw away all the current layout information.
     */
5288
5289
5290
5291
5292
5293
5294
5295

5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5171
5172
5173
5174
5175
5176
5177

5178
5179
5180
5181
5182
5183
5184

5185
5186
5187
5188
5189
5190
5191







-
+






-








    if (!IsStartOfNotMergedLine(textPtr, &textPtr->topIndex)) {
	TkTextFindDisplayLineEnd(textPtr, &textPtr->topIndex, 0, NULL);
    }

    /*
     * Invalidate cached scrollbar positions, so that scrollbars sliders will
     * be updated.
     * be udpated.
     */

    dInfoPtr->xScrollFirst = dInfoPtr->xScrollLast = -1;
    dInfoPtr->yScrollFirst = dInfoPtr->yScrollLast = -1;

    if (mask & TK_TEXT_LINE_GEOMETRY) {

	/*
	 * Set up line metric recalculation.
	 *
	 * Avoid the special zero value, since that is used to mark individual
	 * lines as being out of date.
	 */

5320
5321
5322
5323
5324
5325
5326
5327

5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5202
5203
5204
5205
5206
5207
5208

5209
5210


5211
5212
5213
5214
5215
5216
5217







-
+

-
-








	dInfoPtr->metricEpoch = -1;

	if (dInfoPtr->lineUpdateTimer == NULL) {
	    textPtr->refCount++;
	    dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		    AsyncUpdateLineMetrics, textPtr);
	    inSync = 0;
            GenerateWidgetViewSyncEvent(textPtr, 0);
	}

        GenerateWidgetViewSyncEvent(textPtr, inSync);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkTextSetYView --
5365
5366
5367
5368
5369
5370
5371
5372

5373
5374
5375
5376
5377
5378
5379
5245
5246
5247
5248
5249
5250
5251

5252
5253
5254
5255
5256
5257
5258
5259







-
+







				 * line, don't nudge it up or down by a few
				 * pixels just to make sure it is entirely
				 * displayed. Positive numbers indicate the
				 * number of pixels of the index's line which
				 * are to be off the top of the screen. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    DLine *dlPtr;
    register DLine *dlPtr;
    int bottomY, close, lineIndex;
    TkTextIndex tmpIndex, rounded;
    int lineHeight;

    /*
     * If the specified position is the extra line at the end of the text,
     * round it back to the last real line.
5729
5730
5731
5732
5733
5734
5735
5736

5737
5738
5739
5740
5741
5742
5743
5609
5610
5611
5612
5613
5614
5615

5616
5617
5618
5619
5620
5621
5622
5623







-
+







 *--------------------------------------------------------------
 */

int
TkTextSeeCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "see". */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    TkTextIndex index;
    int x, y, width, height, lineWidth, byteCount, oneThird, delta;
5865
5866
5867
5868
5869
5870
5871
5872

5873
5874
5875
5876
5877
5878
5879
5745
5746
5747
5748
5749
5750
5751

5752
5753
5754
5755
5756
5757
5758
5759







-
+







 *--------------------------------------------------------------
 */

int
TkTextXviewCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "xview". */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    int type, count;
    double fraction;
6166
6167
6168
6169
6170
6171
6172
6173

6174
6175
6176
6177
6178
6179
6180
6181

6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200

6201
6202
6203
6204
6205
6206
6207
6046
6047
6048
6049
6050
6051
6052

6053
6054
6055
6056
6057
6058
6059
6060

6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079

6080
6081
6082
6083
6084
6085
6086
6087







-
+







-
+


















-
+







 *--------------------------------------------------------------
 */

int
TkTextYviewCmd(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "yview". */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    int pickPlace, type;
    int pixels, count;
    Tcl_Size switchLength;
    int switchLength;
    double fraction;
    TkTextIndex index;

    if (dInfoPtr->flags & DINFO_OUT_OF_DATE) {
	UpdateDisplayInfo(textPtr);
    }

    if (objc == 2) {
	GetYView(interp, textPtr, 0);
	return TCL_OK;
    }

    /*
     * Next, handle the old syntax: "pathName yview ?-pickplace? where"
     */

    pickPlace = 0;
    if (Tcl_GetString(objv[2])[0] == '-') {
	const char *switchStr =
	register const char *switchStr =
		Tcl_GetStringFromObj(objv[2], &switchLength);

	if ((switchLength >= 2) && (strncmp(switchStr, "-pickplace",
		(unsigned) switchLength) == 0)) {
	    pickPlace = 1;
	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "lineNum|index");
6348
6349
6350
6351
6352
6353
6354
6355




6356
6357
6358
6359
6360
6361
6362
6228
6229
6230
6231
6232
6233
6234

6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245







-
+
+
+
+








Bool
TkTextPendingsync(
    TkText *textPtr)		/* Information about text widget. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;

    return ((dInfoPtr->flags & OUT_OF_SYNC) != 0);
    return (
        ((dInfoPtr->metricEpoch == -1) &&
         (dInfoPtr->lastMetricUpdateLine == dInfoPtr->currentMetricUpdateLine)) ?
        0 : 1);
}

/*
 *--------------------------------------------------------------
 *
 * TkTextScanCmd --
 *
6371
6372
6373
6374
6375
6376
6377
6378

6379
6380

6381
6382
6383
6384
6385
6386
6387
6388

6389
6390
6391
6392
6393

6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409


6410
6411
6412
6413
6414
6415
6416
6254
6255
6256
6257
6258
6259
6260

6261
6262

6263
6264
6265
6266
6267
6268
6269
6270

6271
6272
6273
6274
6275

6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291

6292
6293
6294
6295
6296
6297
6298
6299
6300







-
+

-
+







-
+




-
+















-
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkTextScanCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "scan". */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    TkTextIndex index;
    int c, x, y, totalScroll, gain=10;
    Tcl_Size length;
    size_t length;

    if ((objc != 5) && (objc != 6)) {
	Tcl_WrongNumArgs(interp, 2, objv, "mark x y");
	Tcl_AppendResult(interp, " or \"", Tcl_GetString(objv[0]),
		" scan dragto x y ?gain?\"", (char *)NULL);
		" scan dragto x y ?gain?\"", NULL);
	/*
	 * Ought to be:
	 * Tcl_WrongNumArgs(interp, 2, objc, "dragto x y ?gain?");
	 */
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((objc == 6) && (Tcl_GetIntFromObj(interp, objv[5], &gain) != TCL_OK)) {
	return TCL_ERROR;
    }
    c = Tcl_GetStringFromObj(objv[2], &length)[0];
    c = Tcl_GetString(objv[2])[0];
    length = strlen(Tcl_GetString(objv[2]));
    if (c=='d' && strncmp(Tcl_GetString(objv[2]), "dragto", length)==0) {
	int newX, maxX;

	/*
	 * Amplify the difference between the current position and the mark
	 * position to compute how much the view should shift, then update the
	 * mark position to correspond to the new view. If we run off the edge
6453
6454
6455
6456
6457
6458
6459
6460

6461
6462
6463

6464
6465
6466
6467
6468
6469
6470
6337
6338
6339
6340
6341
6342
6343

6344
6345
6346

6347
6348
6349
6350
6351
6352
6353
6354







-
+


-
+







    } else if (c=='m' && strncmp(Tcl_GetString(objv[2]), "mark", length)==0) {
	dInfoPtr->scanMarkXPixel = dInfoPtr->newXPixelOffset;
	dInfoPtr->scanMarkX = x;
	dInfoPtr->scanTotalYScroll = 0;
	dInfoPtr->scanMarkY = y;
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad scan option \"%s\": must be dragto or mark",
		"bad scan option \"%s\": must be mark or dragto",
		Tcl_GetString(objv[2])));
	Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "scan option",
		Tcl_GetString(objv[2]), (char *)NULL);
		Tcl_GetString(objv[2]), NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
6492
6493
6494
6495
6496
6497
6498
6499

6500
6501
6502
6503
6504
6505
6506
6376
6377
6378
6379
6380
6381
6382

6383
6384
6385
6386
6387
6388
6389
6390







-
+







 */

static void
GetXView(
    Tcl_Interp *interp,		/* If "report" is FALSE, string describing
				 * visible range gets stored in the interp's
				 * result. */
    const TkText *textPtr,		/* Information about text widget. */
    TkText *textPtr,		/* Information about text widget. */
    int report)			/* Non-zero means report info to scrollbar if
				 * it has changed. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    double first, last;
    int code;
    Tcl_Obj *listObj;
6526
6527
6528
6529
6530
6531
6532
6533

6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546




6547
6548
6549
6550
6551
6552
6553
6410
6411
6412
6413
6414
6415
6416

6417
6418
6419
6420
6421
6422
6423
6424
6425
6426




6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437







-
+









-
-
-
-
+
+
+
+







    }
    if (FP_EQUAL_SCALE(first, dInfoPtr->xScrollFirst, dInfoPtr->maxLength) &&
	    FP_EQUAL_SCALE(last, dInfoPtr->xScrollLast, dInfoPtr->maxLength)) {
	return;
    }
    dInfoPtr->xScrollFirst = first;
    dInfoPtr->xScrollLast = last;
    if (textPtr->xScrollCmdObj != NULL) {
    if (textPtr->xScrollCmd != NULL) {
	char buf1[TCL_DOUBLE_SPACE+1];
	char buf2[TCL_DOUBLE_SPACE+1];
	Tcl_DString buf;

	buf1[0] = ' ';
	buf2[0] = ' ';
	Tcl_PrintDouble(NULL, first, buf1+1);
	Tcl_PrintDouble(NULL, last, buf2+1);
	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, Tcl_GetString(textPtr->xScrollCmdObj), TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, buf1, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, buf2, TCL_INDEX_NONE);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, textPtr->xScrollCmd, -1);
	Tcl_DStringAppend(&buf, buf1, -1);
	Tcl_DStringAppend(&buf, buf2, -1);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	if (code != TCL_OK) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (horizontal scrolling command executed by text)");
	    Tcl_BackgroundException(interp, code);
	}
    }
6811
6812
6813
6814
6815
6816
6817
6818

6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831




6832
6833
6834
6835
6836
6837
6838
6695
6696
6697
6698
6699
6700
6701

6702
6703
6704
6705
6706
6707
6708
6709
6710
6711




6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722







-
+









-
-
-
-
+
+
+
+







    if (FP_EQUAL_SCALE(first, dInfoPtr->yScrollFirst, totalPixels) &&
	    FP_EQUAL_SCALE(last, dInfoPtr->yScrollLast, totalPixels)) {
	return;
    }

    dInfoPtr->yScrollFirst = first;
    dInfoPtr->yScrollLast = last;
    if (textPtr->yScrollCmdObj != NULL) {
    if (textPtr->yScrollCmd != NULL) {
	char buf1[TCL_DOUBLE_SPACE+1];
	char buf2[TCL_DOUBLE_SPACE+1];
	Tcl_DString buf;

	buf1[0] = ' ';
	buf2[0] = ' ';
	Tcl_PrintDouble(NULL, first, buf1+1);
	Tcl_PrintDouble(NULL, last, buf2+1);
	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, Tcl_GetString(textPtr->yScrollCmdObj), TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, buf1, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, buf2, TCL_INDEX_NONE);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, textPtr->yScrollCmd, -1);
	Tcl_DStringAppend(&buf, buf1, -1);
	Tcl_DStringAppend(&buf, buf2, -1);
	code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	if (code != TCL_OK) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (vertical scrolling command executed by text)");
	    Tcl_BackgroundException(interp, code);
	}
    }
6854
6855
6856
6857
6858
6859
6860
6861

6862
6863

6864
6865
6866
6867
6868
6869
6870
6738
6739
6740
6741
6742
6743
6744

6745
6746

6747
6748
6749
6750
6751
6752
6753
6754







-
+

-
+







 *	changed.
 *
 *----------------------------------------------------------------------
 */

static void
AsyncUpdateYScrollbar(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkText *textPtr = (TkText *)clientData;
    register TkText *textPtr = clientData;

    textPtr->dInfoPtr->scrollbarTimer = NULL;

    if (!(textPtr->flags & DESTROYED)) {
	GetYView(textPtr->interp, textPtr, 1);
    }

6891
6892
6893
6894
6895
6896
6897
6898

6899
6900
6901
6902
6903
6904
6905
6775
6776
6777
6778
6779
6780
6781

6782
6783
6784
6785
6786
6787
6788
6789







-
+







 *
 *----------------------------------------------------------------------
 */

static DLine *
FindDLine(
    TkText *textPtr,		/* Widget record for text widget. */
    DLine *dlPtr,	/* Pointer to first in list of DLines to
    register DLine *dlPtr,	/* Pointer to first in list of DLines to
				 * search. */
    const TkTextIndex *indexPtr)/* Index of desired character. */
{
    DLine *dlPtrPrev;
    TkTextIndex indexPtr2;

    if (dlPtr == NULL) {
7001
7002
7003
7004
7005
7006
7007
7008

7009
7010
7011
7012
7013
7014
7015
6885
6886
6887
6888
6889
6890
6891

6892
6893
6894
6895
6896
6897
6898
6899







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
IsStartOfNotMergedLine(
      const TkText *textPtr,              /* Widget record for text widget. */
      TkText *textPtr,              /* Widget record for text widget. */
      const TkTextIndex *indexPtr)  /* Index to check. */
{
    TkTextIndex indexPtr2;

    if (indexPtr->byteIndex != 0) {
        /*
         * Not the start of a logical line.
7061
7062
7063
7064
7065
7066
7067
7068

7069
7070
7071
7072
7073
7074
7075
6945
6946
6947
6948
6949
6950
6951

6952
6953
6954
6955
6956
6957
6958
6959







-
+







				 * the character nearest to (x,y). */
    int *nearest)		/* If non-NULL then gets set to 0 if (x,y) is
				 * actually over the returned index, and 1 if
				 * it is just nearby (e.g. if x,y is on the
				 * border of the widget). */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    DLine *dlPtr, *validDlPtr;
    register DLine *dlPtr, *validDlPtr;
    int nearby = 0;

    /*
     * Make sure that all of the layout information about what's displayed
     * where on the screen is up-to-date.
     */

7163
7164
7165
7166
7167
7168
7169
7170

7171
7172
7173
7174
7175
7176
7177
7047
7048
7049
7050
7051
7052
7053

7054
7055
7056
7057
7058
7059
7060
7061







-
+







				 * line. */
    int x,			/* Pixel x coordinate of point in widget's
				 * window. */
    TkTextIndex *indexPtr)	/* This index gets filled in with the index of
				 * the character nearest to x. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    TkTextDispChunk *chunkPtr;
    register TkTextDispChunk *chunkPtr;

    /*
     * Scan through the line's chunks to find the one that contains the
     * desired x-coordinate. Before doing this, translate the x-coordinate
     * from the coordinate system of the window to the coordinate system of
     * the line (to take account of x-scrolling).
     */
7291
7292
7293
7294
7295
7296
7297
7298

7299
7300
7301
7302
7303
7304
7305
7175
7176
7177
7178
7179
7180
7181

7182
7183
7184
7185
7186
7187
7188
7189







-
+







DlineXOfIndex(
    TkText *textPtr,		/* Widget record for text widget. */
    DLine *dlPtr,		/* Display information for this display
				 * line. */
    int byteIndex)		/* The byte index for which we want the
				 * coordinate. */
{
    TkTextDispChunk *chunkPtr = dlPtr->chunkPtr;
    register TkTextDispChunk *chunkPtr = dlPtr->chunkPtr;
    int x = 0;

    if (byteIndex == 0 || chunkPtr == NULL) {
	return x;
    }

    /*
7361
7362
7363
7364
7365
7366
7367
7368
7369


7370
7371
7372
7373
7374
7375
7376
7245
7246
7247
7248
7249
7250
7251


7252
7253
7254
7255
7256
7257
7258
7259
7260







-
-
+
+







    int *charWidthPtr)		/* If the 'index' is at the end of a display
				 * line and therefore takes up a very large
				 * width, this is used to return the smaller
				 * width actually desired by the index. */
{
    TextDInfo *dInfoPtr = textPtr->dInfoPtr;
    DLine *dlPtr;
    TkTextDispChunk *chunkPtr;
    Tcl_Size byteCount;
    register TkTextDispChunk *chunkPtr;
    int byteCount;

    /*
     * Make sure that all of the screen layout information is up to date.
     */

    if (dInfoPtr->flags & DINFO_OUT_OF_DATE) {
	UpdateDisplayInfo(textPtr);
7553
7554
7555
7556
7557
7558
7559
7560

7561
7562

7563
7564
7565
7566
7567


7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587

7588
7589
7590


7591
7592
7593
7594
7595
7596
7597
7437
7438
7439
7440
7441
7442
7443

7444
7445

7446
7447
7448
7449


7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460

7461
7462
7463
7464
7465
7466
7467
7468
7469

7470
7471


7472
7473
7474
7475
7476
7477
7478
7479
7480







-
+

-
+



-
-
+
+









-









-
+

-
-
+
+








/*
 * Get bounding-box information about an elided chunk.
 */

static void
ElideBboxProc(
    TCL_UNUSED(TkText *),
    TkText *textPtr,
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired char. */
    TCL_UNUSED(Tcl_Size),		/* Index of desired character within the
    int index,			/* Index of desired character within the
				 * chunk. */
    int y,			/* Topmost pixel in area allocated for this
				 * line. */
    TCL_UNUSED(int),	/* Height of line, in pixels. */
    TCL_UNUSED(int),	/* Location of line's baseline, in pixels
    int lineHeight,		/* Height of line, in pixels. */
    int baseline,		/* Location of line's baseline, in pixels
				 * measured down from y. */
    int *xPtr, int *yPtr,	/* Gets filled in with coords of character's
				 * upper-left pixel. X-coord is in same
				 * coordinate system as chunkPtr->x. */
    int *widthPtr,		/* Gets filled in with width of character, in
				 * pixels. */
    int *heightPtr)		/* Gets filled in with height of character, in
				 * pixels. */
{

    *xPtr = chunkPtr->x;
    *yPtr = y;
    *widthPtr = *heightPtr = 0;
}

/*
 * Measure an elided chunk.
 */

static Tcl_Size
static int
ElideMeasureProc(
    TCL_UNUSED(TkTextDispChunk *),	/* Chunk containing desired coord. */
    TCL_UNUSED(int))		/* X-coordinate, in same coordinate system as
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired coord. */
    int x)			/* X-coordinate, in same coordinate system as
				 * chunkPtr->x. */
{
    return 0 /*chunkPtr->numBytes - 1*/;
}

/*
 *--------------------------------------------------------------
7612
7613
7614
7615
7616
7617
7618
7619
7620


7621
7622
7623

7624
7625
7626
7627

7628
7629
7630
7631
7632
7633
7634

7635
7636
7637
7638
7639
7640

7641
7642
7643
7644
7645
7646

7647
7648
7649
7650
7651
7652
7653
7495
7496
7497
7498
7499
7500
7501


7502
7503
7504
7505

7506
7507
7508
7509

7510
7511
7512
7513
7514
7515
7516

7517
7518
7519
7520
7521
7522

7523

7524
7525
7526
7527

7528
7529
7530
7531
7532
7533
7534
7535







-
-
+
+


-
+



-
+






-
+





-
+
-




-
+







 *	Memory is allocated to hold additional information about the chunk.
 *
 *--------------------------------------------------------------
 */

int
TkTextCharLayoutProc(
    TCL_UNUSED(TkText *),	/* Text widget being layed out. */
    TCL_UNUSED(TkTextIndex *),	/* Index of first character to lay out
    TkText *textPtr,		/* Text widget being layed out. */
    TkTextIndex *indexPtr,	/* Index of first character to lay out
				 * (corresponds to segPtr and offset). */
    TkTextSegment *segPtr,	/* Segment being layed out. */
    Tcl_Size byteOffset,		/* Byte offset within segment of first
    int byteOffset,		/* Byte offset within segment of first
				 * character to consider. */
    int maxX,			/* Chunk must not occupy pixels at this
				 * position or higher. */
    Tcl_Size maxBytes,		/* Chunk must not include more than this many
    int maxBytes,		/* Chunk must not include more than this many
				 * characters. */
    int noCharsYet,		/* Non-zero means no characters have been
				 * assigned to this display line yet. */
    TkWrapMode wrapMode,	/* How to handle line wrapping:
				 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
				 * TEXT_WRAPMODE_WORD. */
    TkTextDispChunk *chunkPtr)
    register TkTextDispChunk *chunkPtr)
				/* Structure to fill in with information about
				 * this chunk. The x field has already been
				 * set by the caller. */
{
    Tk_Font tkfont;
    int nextX, count;
    int nextX, bytesThatFit, count;
    Tcl_Size bytesThatFit;
    CharInfo *ciPtr;
    char *p;
    TkTextSegment *nextPtr;
    Tk_FontMetrics fm;
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
    const char *line;
    int lineOffset;
    BaseCharInfo *bciPtr;
    Tcl_DString *baseString;
#endif

    /*
7664
7665
7666
7667
7668
7669
7670
7671

7672
7673
7674

7675
7676
7677
7678
7679
7680
7681
7682


7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703

7704
7705
7706

7707
7708

7709
7710
7711
7712
7713
7714
7715
7546
7547
7548
7549
7550
7551
7552

7553
7554
7555

7556
7557
7558
7559
7560
7561
7562


7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584

7585
7586
7587

7588
7589

7590
7591
7592
7593
7594
7595
7596
7597







-
+


-
+






-
-
+
+




















-
+


-
+

-
+







     * characters following the characters that fit in the space we've got,
     * even if no pixel of them is visible.
     */

    p = segPtr->body.chars + byteOffset;
    tkfont = chunkPtr->stylePtr->sValuePtr->tkfont;

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
    if (baseCharChunkPtr == NULL) {
	baseCharChunkPtr = chunkPtr;
	bciPtr = (BaseCharInfo *)ckalloc(sizeof(BaseCharInfo));
	bciPtr = ckalloc(sizeof(BaseCharInfo));
	baseString = &bciPtr->baseChars;
	Tcl_DStringInit(baseString);
	bciPtr->width = 0;

	ciPtr = &bciPtr->ci;
    } else {
	bciPtr = (BaseCharInfo *)baseCharChunkPtr->clientData;
	ciPtr = (CharInfo *)ckalloc(sizeof(CharInfo));
	bciPtr = baseCharChunkPtr->clientData;
	ciPtr = ckalloc(sizeof(CharInfo));
	baseString = &bciPtr->baseChars;
    }

    lineOffset = Tcl_DStringLength(baseString);
    line = Tcl_DStringAppend(baseString,p,maxBytes);

    chunkPtr->clientData = ciPtr;
    ciPtr->baseChunkPtr = baseCharChunkPtr;
    ciPtr->baseOffset = lineOffset;
    ciPtr->chars = NULL;
    ciPtr->numBytes = 0;

    bytesThatFit = CharChunkMeasureChars(chunkPtr, line,
	    lineOffset + maxBytes, lineOffset, -1, chunkPtr->x, maxX,
	    TK_ISOLATE_END, &nextX);
#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */
    bytesThatFit = CharChunkMeasureChars(chunkPtr, p, maxBytes, 0, -1,
	    chunkPtr->x, maxX, TK_ISOLATE_END, &nextX);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */

    if (bytesThatFit + 1 <= maxBytes) {
    if (bytesThatFit < maxBytes) {
	if ((bytesThatFit == 0) && noCharsYet) {
	    int ch;
	    int chLen = Tcl_UtfToUniChar(p, &ch);
	    int chLen = TkUtfToUniChar(p, &ch);

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
	    bytesThatFit = CharChunkMeasureChars(chunkPtr, line,
		    lineOffset+chLen, lineOffset, -1, chunkPtr->x, -1, 0,
		    &nextX);
#else /* !TK_LAYOUT_WITH_BASE_CHUNKS */
	    bytesThatFit = CharChunkMeasureChars(chunkPtr, p, chLen, 0, -1,
		    chunkPtr->x, -1, 0, &nextX);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */
7745
7746
7747
7748
7749
7750
7751
7752

7753
7754
7755
7756
7757
7758
7759
7627
7628
7629
7630
7631
7632
7633

7634
7635
7636
7637
7638
7639
7640
7641







-
+







	     * A newline character takes up no space, so if the previous
	     * character fits then so does the newline.
	     */

	    bytesThatFit++;
	}
	if (bytesThatFit == 0) {
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
	    chunkPtr->clientData = NULL;
	    if (chunkPtr == baseCharChunkPtr) {
		baseCharChunkPtr = NULL;
		Tcl_DStringFree(baseString);
	    } else {
		Tcl_DStringSetLength(baseString,lineOffset);
	    }
7778
7779
7780
7781
7782
7783
7784
7785
7786


7787
7788

7789
7790
7791
7792
7793
7794
7795
7796

7797
7798
7799
7800
7801
7802
7803
7660
7661
7662
7663
7664
7665
7666


7667
7668
7669

7670
7671
7672
7673
7674
7675
7676
7677

7678
7679
7680
7681
7682
7683
7684
7685







-
-
+
+

-
+







-
+







    chunkPtr->numBytes = bytesThatFit;
    chunkPtr->minAscent = fm.ascent + chunkPtr->stylePtr->sValuePtr->offset;
    chunkPtr->minDescent = fm.descent - chunkPtr->stylePtr->sValuePtr->offset;
    chunkPtr->minHeight = 0;
    chunkPtr->width = nextX - chunkPtr->x;
    chunkPtr->breakIndex = -1;

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
    ciPtr = (CharInfo *)ckalloc(offsetof(CharInfo, chars) + 1 + bytesThatFit);
#if !TK_LAYOUT_WITH_BASE_CHUNKS
    ciPtr = ckalloc((Tk_Offset(CharInfo, chars) + 1) + bytesThatFit);
    chunkPtr->clientData = ciPtr;
    memcpy(ciPtr->chars, p, bytesThatFit);
    memcpy(ciPtr->chars, p, (unsigned) bytesThatFit);
#endif /* TK_LAYOUT_WITH_BASE_CHUNKS */

    ciPtr->numBytes = bytesThatFit;
    if (p[bytesThatFit - 1] == '\n') {
	ciPtr->numBytes--;
    }

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
    /*
     * Final update for the current base chunk data.
     */

    Tcl_DStringSetLength(baseString,lineOffset+ciPtr->numBytes);
    bciPtr->width = nextX - baseCharChunkPtr->x;

7872
7873
7874
7875
7876
7877
7878
7879

7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899

7900
7901

7902
7903
7904
7905
7906
7907
7908
7754
7755
7756
7757
7758
7759
7760

7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780

7781
7782

7783
7784
7785
7786
7787
7788
7789
7790







-
+



















-
+

-
+







 *	didn't fit would be drawn, if it were to be drawn.
 *
 * Side effects:
 *	None.
 *--------------------------------------------------------------
 */

static Tcl_Size
static int
CharChunkMeasureChars(
    TkTextDispChunk *chunkPtr,	/* Chunk from which to measure. */
    const char *chars,		/* Chars to use, instead of the chunk's own.
				 * Used by the layoutproc during chunk setup.
				 * All other callers use NULL. Not
				 * NUL-terminated. */
    int charsLen,		/* Length of the "chars" parameter. */
    int start, int end,		/* The range of chars to measure inside the
				 * chunk (or inside the additional chars). */
    int startX,			/* Starting x coordinate where the measured
				 * span will begin. */
    int maxX,			/* Maximum pixel width of the span. May be -1
				 * for unlimited. */
    int flags,			/* Flags to pass to MeasureChars. */
    int *nextXPtr)		/* The function puts the newly calculated
				 * right border x-position of the span
				 * here. */
{
    Tk_Font tkfont = chunkPtr->stylePtr->sValuePtr->tkfont;
    CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;
    CharInfo *ciPtr = chunkPtr->clientData;

#ifndef TK_LAYOUT_WITH_BASE_CHUNKS
#if !TK_LAYOUT_WITH_BASE_CHUNKS
    if (chars == NULL) {
	chars = ciPtr->chars;
	charsLen = ciPtr->numBytes;
    }
    if (end == -1) {
	end = charsLen;
    }
7967
7968
7969
7970
7971
7972
7973
7974

7975
7976
7977
7978
7979
7980
7981

7982
7983
7984
7985

7986
7987
7988

7989
7990
7991
7992

7993
7994

7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007


8008
8009
8010
8011

8012
8013
8014
8015
8016
8017
8018
7849
7850
7851
7852
7853
7854
7855

7856
7857
7858
7859
7860
7861
7862

7863
7864
7865
7866

7867
7868
7869

7870
7871
7872
7873

7874


7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886


7887
7888
7889
7890
7891

7892
7893
7894
7895
7896
7897
7898
7899







-
+






-
+



-
+


-
+



-
+
-
-
+











-
-
+
+



-
+







 *	Graphics are drawn.
 *
 *--------------------------------------------------------------
 */

static void
CharDisplayProc(
    TCL_UNUSED(TkText *),
    TkText *textPtr,
    TkTextDispChunk *chunkPtr,	/* Chunk that is to be drawn. */
    int x,			/* X-position in dst at which to draw this
				 * chunk (may differ from the x-position in
				 * the chunk because of scrolling). */
    int y,			/* Y-position at which to draw this chunk in
				 * dst. */
    TCL_UNUSED(int),		/* Total height of line. */
    int height,			/* Total height of line. */
    int baseline,		/* Offset of baseline from y. */
    Display *display,		/* Display to use for drawing. */
    Drawable dst,		/* Pixmap or window in which to draw chunk. */
    TCL_UNUSED(int))	/* Y-coordinate in text window that
    int screenY)		/* Y-coordinate in text window that
				 * corresponds to y. */
{
    CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;
    CharInfo *ciPtr = chunkPtr->clientData;
    const char *string;
    TextStyle *stylePtr;
    StyleValues *sValuePtr;
    Tcl_Size numBytes, offsetBytes;
    int numBytes, offsetBytes, offsetX;
    int offsetX;
#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
    BaseCharInfo *bciPtr;
#endif /* TK_DRAW_IN_CONTEXT */

    if ((x + chunkPtr->width) <= 0) {
	/*
	 * The chunk is off-screen.
	 */

	return;
    }

#ifdef TK_DRAW_IN_CONTEXT
    bciPtr = (BaseCharInfo *)ciPtr->baseChunkPtr->clientData;
#if TK_DRAW_IN_CONTEXT
    bciPtr = ciPtr->baseChunkPtr->clientData;
    numBytes = Tcl_DStringLength(&bciPtr->baseChars);
    string = Tcl_DStringValue(&bciPtr->baseChars);

#elif defined(TK_LAYOUT_WITH_BASE_CHUNKS)
#elif TK_LAYOUT_WITH_BASE_CHUNKS
    if (ciPtr->baseChunkPtr != chunkPtr) {
	/*
	 * Without context drawing only base chunks display their foreground.
	 */

	return;
    }
8044
8045
8046
8047
8048
8049
8050
8051
8052


8053
8054
8055
8056
8057
8058
8059
7925
7926
7927
7928
7929
7930
7931


7932
7933
7934
7935
7936
7937
7938
7939
7940







-
-
+
+







    }

    /*
     * Draw the text, underline, and overstrike for this chunk.
     */

    if (!sValuePtr->elide && (numBytes > offsetBytes)
	    && (stylePtr->fgGC != NULL)) {
#ifdef TK_DRAW_IN_CONTEXT
	    && (stylePtr->fgGC != None)) {
#if TK_DRAW_IN_CONTEXT
	int start = ciPtr->baseOffset + offsetBytes;
	int len = ciPtr->numBytes - offsetBytes;
	int xDisplacement = x - chunkPtr->x;

	if ((len > 0) && (string[start + len - 1] == '\t')) {
	    len--;
	}
8130
8131
8132
8133
8134
8135
8136
8137

8138
8139
8140

8141
8142
8143

8144
8145
8146
8147
8148
8149
8150
8011
8012
8013
8014
8015
8016
8017

8018
8019
8020

8021
8022
8023

8024
8025
8026
8027
8028
8029
8030
8031







-
+


-
+


-
+







 *	Memory and other resources get freed.
 *
 *--------------------------------------------------------------
 */

static void
CharUndisplayProc(
    TCL_UNUSED(TkText *),	/* Overall information about text widget. */
    TkText *textPtr,		/* Overall information about text widget. */
    TkTextDispChunk *chunkPtr)	/* Chunk that is about to be freed. */
{
    CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;
    CharInfo *ciPtr = chunkPtr->clientData;

    if (ciPtr) {
#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
	if (chunkPtr == ciPtr->baseChunkPtr) {
	    /*
	     * Basechunks are undisplayed first, when DLines are freed or
	     * partially freed, so this makes sure we don't access their data
	     * any more.
	     */

8183
8184
8185
8186
8187
8188
8189
8190

8191
8192
8193
8194
8195
8196
8197
8064
8065
8066
8067
8068
8069
8070

8071
8072
8073
8074
8075
8076
8077
8078







-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static Tcl_Size
static int
CharMeasureProc(
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired coord. */
    int x)			/* X-coordinate, in same coordinate system as
				 * chunkPtr->x. */
{
    int endX;

8219
8220
8221
8222
8223
8224
8225
8226

8227
8228

8229
8230
8231
8232

8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243

8244
8245
8246
8247
8248
8249
8250
8100
8101
8102
8103
8104
8105
8106

8107
8108

8109
8110
8111
8112

8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123

8124
8125
8126
8127
8128
8129
8130
8131







-
+

-
+



-
+










-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static void
CharBboxProc(
    TCL_UNUSED(TkText *),
    TkText *textPtr,
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired char. */
    Tcl_Size byteIndex,		/* Byte offset of desired character within the
    int byteIndex,		/* Byte offset of desired character within the
				 * chunk. */
    int y,			/* Topmost pixel in area allocated for this
				 * line. */
    TCL_UNUSED(int),	/* Height of line, in pixels. */
    int lineHeight,		/* Height of line, in pixels. */
    int baseline,		/* Location of line's baseline, in pixels
				 * measured down from y. */
    int *xPtr, int *yPtr,	/* Gets filled in with coords of character's
				 * upper-left pixel. X-coord is in same
				 * coordinate system as chunkPtr->x. */
    int *widthPtr,		/* Gets filled in with width of character, in
				 * pixels. */
    int *heightPtr)		/* Gets filled in with height of character, in
				 * pixels. */
{
    CharInfo *ciPtr = (CharInfo *)chunkPtr->clientData;
    CharInfo *ciPtr = chunkPtr->clientData;
    int maxX;

    maxX = chunkPtr->width + chunkPtr->x;
    CharChunkMeasureChars(chunkPtr, NULL, 0, 0, byteIndex,
	    chunkPtr->x, -1, 0, xPtr);

    if (byteIndex == ciPtr->numBytes) {
8399
8400
8401
8402
8403
8404
8405
8406

8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427

8428
8429
8430
8431
8432
8433
8434
8280
8281
8282
8283
8284
8285
8286

8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307

8308
8309
8310
8311
8312
8313
8314
8315







-
+




















-
+







    decimalChunkPtr = NULL;
    decimal = gotDigit = 0;
    for (chunkPtr2 = chunkPtr->nextPtr; chunkPtr2 != NULL;
	    chunkPtr2 = chunkPtr2->nextPtr) {
	if (chunkPtr2->displayProc != CharDisplayProc) {
	    continue;
	}
	ciPtr = (CharInfo *)chunkPtr2->clientData;
	ciPtr = chunkPtr2->clientData;
	for (p = ciPtr->chars, i = 0; i < ciPtr->numBytes; p++, i++) {
	    if (isdigit(UCHAR(*p))) {
		gotDigit = 1;
	    } else if ((*p == '.') || (*p == ',')) {
		decimal = p-ciPtr->chars;
		decimalChunkPtr = chunkPtr2;
	    } else if (gotDigit) {
		if (decimalChunkPtr == NULL) {
		    decimal = p-ciPtr->chars;
		    decimalChunkPtr = chunkPtr2;
		}
		goto endOfNumber;
	    }
	}
    }

  endOfNumber:
    if (decimalChunkPtr != NULL) {
	int curX;

	ciPtr = (CharInfo *)decimalChunkPtr->clientData;
	ciPtr = decimalChunkPtr->clientData;
	CharChunkMeasureChars(decimalChunkPtr, NULL, 0, 0, decimal,
		decimalChunkPtr->x, -1, 0, &curX);
	desired = tabX - (curX - x);
	goto update;
    }

    /*
8485
8486
8487
8488
8489
8490
8491
8492

8493
8494
8495
8496
8497
8498
8499
8366
8367
8368
8369
8370
8371
8372

8373
8374
8375
8376
8377
8378
8379
8380







-
+







 *----------------------------------------------------------------------
 */

static int
SizeOfTab(
    TkText *textPtr,		/* Information about the text widget as a
				 * whole. */
    TkTextTabStyle tabStyle,	/* One of TK_TEXT_TABSTYLE_TABULAR
    int tabStyle,		/* One of TK_TEXT_TABSTYLE_TABULAR
				 * or TK_TEXT_TABSTYLE_WORDPROCESSOR. */
    TkTextTabArray *tabArrayPtr,/* Information about the tab stops that apply
				 * to this line. NULL means use default
				 * tabbing (every 8 chars.) */
    int *indexPtr,		/* Contains index of previous tab stop, will
				 * be updated to reflect the number of stops
				 * used. */
8671
8672
8673
8674
8675
8676
8677
8678

8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698

8699
8700
8701
8702
8703
8704
8705
8552
8553
8554
8555
8556
8557
8558

8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578

8579
8580
8581
8582
8583
8584
8585
8586







-
+



















-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static Tcl_Size
static int
MeasureChars(
    Tk_Font tkfont,		/* Font in which to draw characters. */
    const char *source,		/* Characters to be displayed. Need not be
				 * NULL-terminated. */
    int maxBytes,		/* Maximum # of bytes to consider from
				 * source. */
    int rangeStart, int rangeLength,
				/* Range of bytes to consider in source.*/
    int startX,			/* X-position at which first character will be
				 * drawn. */
    int maxX,			/* Don't consider any character that would
				 * cross this x-position. */
    int flags,			/* Flags to pass to Tk_MeasureChars. */
    int *nextXPtr)		/* Return x-position of terminating character
				 * here. */
{
    int curX, width, ch;
    const char *special, *end, *start;

    ch = 0;
    ch = 0;			/* lint. */
    curX = startX;
    start = source + rangeStart;
    end = start + rangeLength;
    special = start;
    while (start < end) {
	if (start >= special) {
	    /*
8718
8719
8720
8721
8722
8723
8724
8725

8726
8727
8728
8729
8730
8731
8732
8599
8600
8601
8602
8603
8604
8605

8606
8607
8608
8609
8610
8611
8612
8613







-
+







	 * Special points at the next special character (or the end of the
	 * string). Process characters between start and special.
	 */

	if ((maxX >= 0) && (curX >= maxX)) {
	    break;
	}
#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
	start += TkpMeasureCharsInContext(tkfont, source, maxBytes,
		start - source, special - start,
		maxX >= 0 ? maxX - curX : -1, flags, &width);
#else
	(void) maxBytes;
	start += Tk_MeasureChars(tkfont, start, special - start,
		maxX >= 0 ? maxX - curX : -1, flags, &width);
8779
8780
8781
8782
8783
8784
8785
8786

8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800

8801
8802
8803

8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825

8826
8827
8828
8829
8830
8831
8832
8833
8834

8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852

8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866

8867
8868
8869
8870
8871
8872
8873
8660
8661
8662
8663
8664
8665
8666

8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680

8681
8682
8683

8684
8685
8686

8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704

8705
8706
8707
8708
8709
8710
8711
8712
8713

8714
8715
8716




8717
8718
8719
8720
8721
8722



8723
8724

8725
8726
8727




8728
8729
8730
8731
8732
8733
8734

8735
8736
8737
8738
8739
8740
8741
8742







-
+













-
+


-
+


-


















-
+








-
+


-
-
-
-






-
-
-


-
+


-
-
-
-







-
+







 *----------------------------------------------------------------------
 */

static int
TextGetScrollInfoObj(
    Tcl_Interp *interp,		/* Used for error reporting. */
    TkText *textPtr,		/* Information about the text widget. */
    Tcl_Size objc,			/* # arguments for command. */
    int objc,			/* # arguments for command. */
    Tcl_Obj *const objv[],	/* Arguments for command. */
    double *dblPtr,		/* Filled in with argument "moveto" option, if
				 * any. */
    int *intPtr)		/* Filled in with number of pages or lines or
				 * pixels to scroll, if any. */
{
    static const char *const subcommands[] = {
	"moveto", "scroll", NULL
    };
    enum viewSubcmds {
	VIEW_MOVETO, VIEW_SCROLL
    };
    static const char *const units[] = {
	"pages", "pixels", "units", NULL
	"units", "pages", "pixels", NULL
    };
    enum viewUnits {
	VIEW_SCROLL_PAGES, VIEW_SCROLL_PIXELS, VIEW_SCROLL_UNITS
	VIEW_SCROLL_UNITS, VIEW_SCROLL_PAGES, VIEW_SCROLL_PIXELS
    };
    int index;
    double d;

    if (Tcl_GetIndexFromObjStruct(interp, objv[2], subcommands,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TKTEXT_SCROLL_ERROR;
    }

    switch ((enum viewSubcmds) index) {
    case VIEW_MOVETO:
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 3, objv, "fraction");
	    return TKTEXT_SCROLL_ERROR;
	}
	if (Tcl_GetDoubleFromObj(interp, objv[3], dblPtr) != TCL_OK) {
	    return TKTEXT_SCROLL_ERROR;
	}
	return TKTEXT_SCROLL_MOVETO;
    case VIEW_SCROLL:
	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 3, objv, "number pages|pixels|units");
	    Tcl_WrongNumArgs(interp, 3, objv, "number units|pages|pixels");
	    return TKTEXT_SCROLL_ERROR;
	}
	if (Tcl_GetIndexFromObjStruct(interp, objv[4], units,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TKTEXT_SCROLL_ERROR;
	}
	switch ((enum viewUnits) index) {
	case VIEW_SCROLL_PAGES:
	    if (Tcl_GetDoubleFromObj(interp, objv[3], &d) != TCL_OK) {
	    if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
		return TKTEXT_SCROLL_ERROR;
	    }
	    *intPtr = (d > 0) ? ceil(d) : floor(d);
	    if (dblPtr) {
		*dblPtr = d;
	    }
	    return TKTEXT_SCROLL_PAGES;
	case VIEW_SCROLL_PIXELS:
	    if (Tk_GetPixelsFromObj(interp, textPtr->tkwin, objv[3],
		    intPtr) != TCL_OK) {
		return TKTEXT_SCROLL_ERROR;
	    }
	    if (dblPtr) {
		*dblPtr = (double)*intPtr;
	    }
	    return TKTEXT_SCROLL_PIXELS;
	case VIEW_SCROLL_UNITS:
	    if (Tcl_GetDoubleFromObj(interp, objv[3], &d) != TCL_OK) {
	    if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
		return TKTEXT_SCROLL_ERROR;
	    }
	    *intPtr = (d > 0) ? ceil(d) : floor(d);
	    if (dblPtr) {
		*dblPtr = d;
	    }
	    return TKTEXT_SCROLL_UNITS;
	}
    }
    Tcl_Panic("unexpected switch fallthrough");
    return TKTEXT_SCROLL_ERROR;
}

#ifdef TK_LAYOUT_WITH_BASE_CHUNKS
#if TK_LAYOUT_WITH_BASE_CHUNKS
/*
 *----------------------------------------------------------------------
 *
 * FinalizeBaseChunk --
 *
 *	This procedure makes sure that all the chunks of the stretch are
 *	up-to-date. It is invoked when the LayoutProc has been called for all
8890
8891
8892
8893
8894
8895
8896
8897

8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911

8912
8913
8914
8915
8916
8917
8918

8919
8920
8921
8922
8923
8924

8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935

8936
8937
8938

8939
8940
8941
8942
8943
8944
8945
8759
8760
8761
8762
8763
8764
8765

8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779

8780
8781
8782
8783
8784
8785
8786

8787
8788
8789
8790
8791
8792

8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803

8804
8805
8806

8807
8808
8809
8810
8811
8812
8813
8814







-
+













-
+






-
+





-
+










-
+


-
+







				 * even though it may not be in the linked
				 * list yet. Used by the LayoutProc, otherwise
				 * NULL. */
{
    const char *baseChars;
    TkTextDispChunk *chunkPtr;
    CharInfo *ciPtr;
#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
    int widthAdjust = 0;
    int newwidth;
#endif /* TK_DRAW_IN_CONTEXT */

    if (baseCharChunkPtr == NULL) {
	return;
    }

    baseChars = Tcl_DStringValue(
	    &((BaseCharInfo *) baseCharChunkPtr->clientData)->baseChars);

    for (chunkPtr = baseCharChunkPtr; chunkPtr != NULL;
	    chunkPtr = chunkPtr->nextPtr) {
#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
	chunkPtr->x += widthAdjust;
#endif /* TK_DRAW_IN_CONTEXT */

	if (chunkPtr->displayProc != CharDisplayProc) {
	    continue;
	}
	ciPtr = (CharInfo *)chunkPtr->clientData;
	ciPtr = chunkPtr->clientData;
	if (ciPtr->baseChunkPtr != baseCharChunkPtr) {
	    break;
	}
	ciPtr->chars = baseChars + ciPtr->baseOffset;

#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
	newwidth = 0;
	CharChunkMeasureChars(chunkPtr, NULL, 0, 0, -1, 0, -1, 0, &newwidth);
	if (newwidth < chunkPtr->width) {
	    widthAdjust += newwidth - chunkPtr->width;
	    chunkPtr->width = newwidth;
	}
#endif /* TK_DRAW_IN_CONTEXT */
    }

    if (addChunkPtr != NULL) {
	ciPtr = (CharInfo *)addChunkPtr->clientData;
	ciPtr = addChunkPtr->clientData;
	ciPtr->chars = baseChars + ciPtr->baseOffset;

#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
	addChunkPtr->x += widthAdjust;
	CharChunkMeasureChars(addChunkPtr, NULL, 0, 0, -1, 0, -1, 0,
		&addChunkPtr->width);
#endif /* TK_DRAW_IN_CONTEXT */
    }

    baseCharChunkPtr = NULL;
8979
8980
8981
8982
8983
8984
8985
8986

8987
8988
8989
8990
8991
8992
8993
8848
8849
8850
8851
8852
8853
8854

8855
8856
8857
8858
8859
8860
8861
8862







-
+







	baseCharChunkPtr = NULL;
    }

    for (chunkPtr=baseChunkPtr; chunkPtr!=NULL; chunkPtr=chunkPtr->nextPtr) {
	if (chunkPtr->undisplayProc != CharUndisplayProc) {
	    continue;
	}
	ciPtr = (CharInfo *)chunkPtr->clientData;
	ciPtr = chunkPtr->clientData;
	if (ciPtr->baseChunkPtr != baseChunkPtr) {
	    break;
	}

	ciPtr->baseChunkPtr = NULL;
	ciPtr->chars = NULL;
    }
9029
9030
9031
9032
9033
9034
9035
9036

9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052

9053
9054
9055
9056
9057
9058
9059
8898
8899
8900
8901
8902
8903
8904

8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920

8921
8922
8923
8924
8925
8926
8927
8928







-
+















-
+







    StyleValues *sv1;
    StyleValues *sv2;

    if (style1 == style2) {
	return 1;
    }

#ifndef TK_DRAW_IN_CONTEXT
#if !TK_DRAW_IN_CONTEXT
    if (
#ifdef MAC_OSX_TK
	    !TkMacOSXCompareColors(style1->fgGC->foreground,
		    style2->fgGC->foreground)
#else
	    style1->fgGC->foreground != style2->fgGC->foreground
#endif
	    ) {
	return 0;
    }
#endif /* !TK_DRAW_IN_CONTEXT */

    sv1 = style1->sValuePtr;
    sv2 = style2->sValuePtr;

#ifdef TK_DRAW_IN_CONTEXT
#if TK_DRAW_IN_CONTEXT
    return sv1->tkfont == sv2->tkfont && sv1->offset == sv2->offset;
#else
    return sv1->tkfont == sv2->tkfont
	    && sv1->underline == sv2->underline
	    && sv1->overstrike == sv2->overstrike
	    && sv1->elide == sv2->elide
	    && sv1->offset == sv2->offset
9099
9100
9101
9102
9103
9104
9105
9106

9107
9108
9109
9110
9111
9112
9113

9114
9115
9116
9117
9118
9119
9120
8968
8969
8970
8971
8972
8973
8974

8975
8976
8977
8978
8979
8980
8981

8982
8983
8984
8985
8986
8987
8988
8989







-
+






-
+







	return;
    }

    /*
     * Reinstitute this base chunk for re-layout.
     */

    ciPtr = (CharInfo *)chunkPtr->clientData;
    ciPtr = chunkPtr->clientData;
    baseCharChunkPtr = ciPtr->baseChunkPtr;

    /*
     * Remove the chunk data from the base chunk data.
     */

    bciPtr = (BaseCharInfo *)baseCharChunkPtr->clientData;
    bciPtr = baseCharChunkPtr->clientData;

#ifdef DEBUG_LAYOUT_WITH_BASE_CHUNKS
    if ((ciPtr->baseOffset + ciPtr->numBytes)
	    != Tcl_DStringLength(&bciPtr->baseChars)) {
	fprintf(stderr,"RemoveFromBaseChunk called with wrong chunk "
		"(not last)\n");
    }

Changes to generic/tkTextImage.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36

37
38
39
40

41
42
43
44
45
46
47
48
49
50

51
52
53

54
55
56
57
58
59
60
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15




16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31

32
33
34
35

36
37
38
39
40
41
42
43
44
45

46
47
48

49
50
51
52
53
54
55
56






-
+








-
-
-
-





-
+










-
+



-
+









-
+


-
+







/*
 * tkImage.c --
 *
 *	This file contains code that allows images to be nested inside text
 *	widgets. It also implements the "image" widget command for texts.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkPort.h"
#include "tkText.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Macro that determines the size of an embedded image segment:
 */

#define EI_SEG_SIZE \
	(offsetof(TkTextSegment, body) + sizeof(TkTextEmbImage))
	((unsigned) (Tk_Offset(TkTextSegment, body) + sizeof(TkTextEmbImage)))

/*
 * Prototypes for functions defined in this file:
 */

static TkTextSegment *	EmbImageCleanupProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static void		EmbImageCheckProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static void		EmbImageBboxProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, Tcl_Size index, int y,
			    TkTextDispChunk *chunkPtr, int index, int y,
			    int lineHeight, int baseline, int *xPtr, int *yPtr,
			    int *widthPtr, int *heightPtr);
static int		EmbImageConfigure(TkText *textPtr,
			    TkTextSegment *eiPtr, Tcl_Size objc,
			    TkTextSegment *eiPtr, int objc,
			    Tcl_Obj *const objv[]);
static int		EmbImageDeleteProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr, int treeGone);
static void		EmbImageDisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, int x, int y,
			    int lineHeight, int baseline, Display *display,
			    Drawable dst, int screenY);
static int		EmbImageLayoutProc(TkText *textPtr,
			    TkTextIndex *indexPtr, TkTextSegment *segPtr,
			    Tcl_Size offset, int maxX, Tcl_Size maxChars,
			    int offset, int maxX, int maxChars,
			    int noCharsYet, TkWrapMode wrapMode,
			    TkTextDispChunk *chunkPtr);
static void		EmbImageProc(void *clientData, int x, int y,
static void		EmbImageProc(ClientData clientData, int x, int y,
			    int width, int height, int imageWidth,
			    int imageHeight);

/*
 * The following structure declares the "embedded image" segment type.
 */

73
74
75
76
77
78
79




80
81
82
83
84
85
86
87


88
89

90
91

92
93

94
95
96

97
98
99
100
101
102
103
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85


86
87
88

89
90

91
92

93
94
95

96
97
98
99
100
101
102
103







+
+
+
+






-
-
+
+

-
+

-
+

-
+


-
+







 * Definitions for alignment values:
 */

static const char *const alignStrings[] = {
    "baseline", "bottom", "center", "top", NULL
};

typedef enum {
    ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_TOP
} alignMode;

/*
 * Information used for parsing image configuration options:
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_STRING_TABLE, "-align", NULL, NULL,
	"center", TCL_INDEX_NONE, offsetof(TkTextEmbImage, align),
	TK_OPTION_ENUM_VAR, alignStrings, 0},
	"center", -1, Tk_Offset(TkTextEmbImage, align),
	0, alignStrings, 0},
    {TK_OPTION_PIXELS, "-padx", NULL, NULL,
	"0", TCL_INDEX_NONE, offsetof(TkTextEmbImage, padX), 0, 0, 0},
	"0", -1, Tk_Offset(TkTextEmbImage, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", NULL, NULL,
	"0", TCL_INDEX_NONE, offsetof(TkTextEmbImage, padY), 0, 0, 0},
	"0", -1, Tk_Offset(TkTextEmbImage, padY), 0, 0, 0},
    {TK_OPTION_STRING, "-image", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextEmbImage, imageString),
	NULL, -1, Tk_Offset(TkTextEmbImage, imageString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-name", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextEmbImage, imageName),
	NULL, -1, Tk_Offset(TkTextEmbImage, imageName),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 *--------------------------------------------------------------
 *
113
114
115
116
117
118
119
120

121
122

123
124
125
126
127
128

129
130
131
132
133
134
135
113
114
115
116
117
118
119

120
121

122
123
124
125
126
127

128
129
130
131
132
133
134
135







-
+

-
+





-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkTextImageCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "image". */
{
    int idx;
    TkTextSegment *eiPtr;
    register TkTextSegment *eiPtr;
    TkTextIndex index;
    static const char *const optionStrings[] = {
	"cget", "configure", "create", "names", NULL
    };
    enum opts {
	CMD_CGET, CMD_CONF, CMD_CREATE, CMD_NAMES
    };
154
155
156
157
158
159
160
161

162
163
164

165
166
167
168
169
170
171
154
155
156
157
158
159
160

161
162
163

164
165
166
167
168
169
170
171







-
+


-
+







	    return TCL_ERROR;
	}
	eiPtr = TkTextIndexToSeg(&index, NULL);
	if (eiPtr->typePtr != &tkTextEmbImageType) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "no embedded image at index \"%s\"",
		    Tcl_GetString(objv[3])));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", NULL);
	    return TCL_ERROR;
	}
	objPtr = Tk_GetOptionValue(interp, &eiPtr->body.ei,
	objPtr = Tk_GetOptionValue(interp, (char *) &eiPtr->body.ei,
		eiPtr->body.ei.optionTable, objv[4], textPtr->tkwin);
	if (objPtr == NULL) {
	    return TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, objPtr);
	    return TCL_OK;
	}
179
180
181
182
183
184
185
186

187
188
189
190
191

192
193
194
195
196
197
198
179
180
181
182
183
184
185

186
187
188
189
190

191
192
193
194
195
196
197
198







-
+




-
+







	    return TCL_ERROR;
	}
	eiPtr = TkTextIndexToSeg(&index, NULL);
	if (eiPtr->typePtr != &tkTextEmbImageType) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "no embedded image at index \"%s\"",
		    Tcl_GetString(objv[3])));
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_IMAGE", NULL);
	    return TCL_ERROR;
	}
	if (objc <= 5) {
	    Tcl_Obj *objPtr = Tk_GetOptionInfo(interp,
		    &eiPtr->body.ei, eiPtr->body.ei.optionTable,
		    (char *) &eiPtr->body.ei, eiPtr->body.ei.optionTable,
		    (objc == 5) ? objv[4] : NULL, textPtr->tkwin);

	    if (objPtr == NULL) {
		return TCL_ERROR;
	    } else {
		Tcl_SetObjResult(interp, objPtr);
		return TCL_OK;
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261







-
+








-
+







		    lineIndex, 1000000, &index);
	}

	/*
	 * Create the new image segment and initialize it.
	 */

	eiPtr = (TkTextSegment *)ckalloc(EI_SEG_SIZE);
	eiPtr = ckalloc(EI_SEG_SIZE);
	eiPtr->typePtr = &tkTextEmbImageType;
	eiPtr->size = 1;
	eiPtr->body.ei.sharedTextPtr = textPtr->sharedTextPtr;
	eiPtr->body.ei.linePtr = NULL;
	eiPtr->body.ei.imageName = NULL;
	eiPtr->body.ei.imageString = NULL;
	eiPtr->body.ei.name = NULL;
	eiPtr->body.ei.image = NULL;
	eiPtr->body.ei.align = TK_ALIGN_CENTER;
	eiPtr->body.ei.align = ALIGN_CENTER;
	eiPtr->body.ei.padX = eiPtr->body.ei.padY = 0;
	eiPtr->body.ei.chunkCount = 0;
	eiPtr->body.ei.optionTable = Tk_CreateOptionTable(interp, optionSpecs);

	/*
	 * Link the segment into the text widget, then configure it (delete it
	 * again if the configuration fails).
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297


298
299
300
301
302
303
304
305
283
284
285
286
287
288
289

290
291
292





293
294

295
296
297
298
299
300
301







-
+


-
-
-
-
-
+
+
-







	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	resultObj = Tcl_NewObj();
	for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->imageTable,
		&search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    -1));
	}
	if (resultObj == NULL) {
	    return TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, resultObj);
	    return TCL_OK;
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
	}
    }
    default:
	Tcl_Panic("unexpected switch fallthrough");
    }
    return TCL_ERROR;
}

323
324
325
326
327
328
329
330

331
332
333
334
335
336

337
338




339
340

341
342
343
344
345
346
347
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334

335
336
337
338
339

340
341
342
343
344
345
346
347







-
+






+

-
+
+
+
+

-
+







 */

static int
EmbImageConfigure(
    TkText *textPtr,		/* Information about text widget that contains
				 * embedded image. */
    TkTextSegment *eiPtr,	/* Embedded image to be configured. */
    Tcl_Size objc,			/* Number of strings in objv. */
    int objc,			/* Number of strings in objv. */
    Tcl_Obj *const objv[])	/* Array of strings describing configuration
				 * options. */
{
    Tk_Image image;
    Tcl_DString newName;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    char *name;
    int dummy, length;
    int dummy;
    int count = 0;		/* The counter for picking a unique name */
    int conflict = 0;		/* True if we have a name conflict */
    size_t len;			/* length of image name */

    if (Tk_SetOptions(textPtr->interp, &eiPtr->body.ei,
    if (Tk_SetOptions(textPtr->interp, (char *) &eiPtr->body.ei,
	    eiPtr->body.ei.optionTable,
	    objc, objv, textPtr->tkwin, NULL, NULL) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Create the image. Save the old image around and don't free it until
377
378
379
380
381
382
383
384

385
386

387
388





389













390

391
392
393
394
395






396
397
398
399
400

401
402
403

404
405


406
407
408
409
410
411
412
413
377
378
379
380
381
382
383

384
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409





410
411
412
413
414
415


416


417
418
419
420
421


422
423

424
425
426
427
428
429
430







-
+

-
+


+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
-
-
-
+
+
+
+
+
+
-
-

-
-
+



+
-
-
+
+
-







    name = eiPtr->body.ei.imageName;
    if (name == NULL) {
    	name = eiPtr->body.ei.imageString;
    }
    if (name == NULL) {
	Tcl_SetObjResult(textPtr->interp, Tcl_NewStringObj(
		"Either a \"-name\" or a \"-image\" argument must be"
		" provided to the \"image create\" subcommand", TCL_INDEX_NONE));
		" provided to the \"image create\" subcommand", -1));
	Tcl_SetErrorCode(textPtr->interp, "TK", "TEXT", "IMAGE_CREATE_USAGE",
		(char *)NULL);
		NULL);
	return TCL_ERROR;
    }
    len = strlen(name);
    for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->imageTable,
	    &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	char *haveName =
		Tcl_GetHashKey(&textPtr->sharedTextPtr->imageTable, hPtr);

	if (strncmp(name, haveName, len) == 0) {
	    int newVal = 0;

	    sscanf(haveName+len, "#%d", &newVal);
	    if (newVal > count) {
		count = newVal;
	    }
	    if (len == strlen(haveName)) {
	    	conflict = 1;
	    }
	}
    }

    Tcl_DStringInit(&newName);
    Tcl_DStringAppend(&newName, name, -1);
    while (Tcl_FindHashEntry(&textPtr->sharedTextPtr->imageTable, name)) {
	char buf[4 + TCL_INTEGER_SPACE];
	snprintf(buf, sizeof(buf), "#%d", ++textPtr->sharedTextPtr->imageCount);
	Tcl_DStringSetLength(&newName, 0);
	Tcl_DStringAppend(&newName, name, TCL_INDEX_NONE);

    if (conflict) {
    	char buf[4 + TCL_INTEGER_SPACE];

	sprintf(buf, "#%d", count+1);
	Tcl_DStringAppend(&newName, buf, -1);
	Tcl_DStringAppend(&newName, buf, TCL_INDEX_NONE);
	name = Tcl_DStringValue(&newName);
    }
    length = strlen(name);

    name = Tcl_DStringValue(&newName);
    hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->imageTable, name,
	    &dummy);
    Tcl_SetHashValue(hPtr, eiPtr);
    Tcl_SetObjResult(textPtr->interp, Tcl_NewStringObj(name, -1));
    eiPtr->body.ei.name = (char *)ckalloc(length + 1);
    memcpy(eiPtr->body.ei.name, name, length + 1);
    eiPtr->body.ei.name = ckalloc(Tcl_DStringLength(&newName) + 1);
    strcpy(eiPtr->body.ei.name, name);
    Tcl_SetObjResult(textPtr->interp, Tcl_NewStringObj(name, TCL_INDEX_NONE));
    Tcl_DStringFree(&newName);

    return TCL_OK;
}

/*
 *--------------------------------------------------------------
423
424
425
426
427
428
429

430
431
432
433
434


435
436
437
438
439
440
441
440
441
442
443
444
445
446
447
448
449
450


451
452
453
454
455
456
457
458
459







+



-
-
+
+







 * Side effects:
 *	The embedded image is deleted, if it exists, and any resources
 *	associated with it are released.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
EmbImageDeleteProc(
    TkTextSegment *eiPtr,	/* Segment being deleted. */
    TCL_UNUSED(TkTextLine *),	/* Line containing segment. */
    TCL_UNUSED(int))		/* Non-zero means the entire tree is being
    TkTextLine *linePtr,	/* Line containing segment. */
    int treeGone)		/* Non-zero means the entire tree is being
				 * deleted, so everything must get cleaned
				 * up. */
{
    Tcl_HashEntry *hPtr;

    if (eiPtr->body.ei.image != NULL) {
	hPtr = Tcl_FindHashEntry(&eiPtr->body.ei.sharedTextPtr->imageTable,
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485







-
+







    }

    /*
     * No need to supply a tkwin argument, since we have no window-specific
     * options.
     */

    Tk_FreeConfigOptions(&eiPtr->body.ei, eiPtr->body.ei.optionTable,
    Tk_FreeConfigOptions((char *) &eiPtr->body.ei, eiPtr->body.ei.optionTable,
	    NULL);
    if (eiPtr->body.ei.name) {
	ckfree(eiPtr->body.ei.name);
    }
    ckfree(eiPtr);
    return 0;
}
505
506
507
508
509
510
511

512
513
514
515

516
517

518
519
520
521

522
523
524
525

526
527
528

529
530
531
532
533
534
535
523
524
525
526
527
528
529
530
531
532
533

534
535

536
537
538
539

540
541
542
543

544
545
546

547
548
549
550
551
552
553
554







+



-
+

-
+



-
+



-
+


-
+







 *
 * Side effects:
 *	None, except for filling in chunkPtr.
 *
 *--------------------------------------------------------------
 */

	/*ARGSUSED*/
static int
EmbImageLayoutProc(
    TkText *textPtr,		/* Text widget being layed out. */
    TCL_UNUSED(TkTextIndex *),	/* Identifies first character in chunk. */
    TkTextIndex *indexPtr,	/* Identifies first character in chunk. */
    TkTextSegment *eiPtr,	/* Segment corresponding to indexPtr. */
    Tcl_Size offset,			/* Offset within segPtr corresponding to
    int offset,			/* Offset within segPtr corresponding to
				 * indexPtr (always 0). */
    int maxX,			/* Chunk must not occupy pixels at this
				 * position or higher. */
    TCL_UNUSED(Tcl_Size),	/* Chunk must not include more than this many
    int maxChars,		/* Chunk must not include more than this many
				 * characters. */
    int noCharsYet,		/* Non-zero means no characters have been
				 * assigned to this line yet. */
    TCL_UNUSED(TkWrapMode),	/* Wrap mode to use for line:
    TkWrapMode wrapMode,	/* Wrap mode to use for line:
				 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
				 * TEXT_WRAPMODE_WORD. */
    TkTextDispChunk *chunkPtr)
    register TkTextDispChunk *chunkPtr)
				/* Structure to fill in with information about
				 * this chunk. The x field has already been
				 * set by the caller. */
{
    int width, height;

    if (offset != 0) {
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591







-
+







     */

    chunkPtr->displayProc = EmbImageDisplayProc;
    chunkPtr->undisplayProc = NULL;
    chunkPtr->measureProc = NULL;
    chunkPtr->bboxProc = EmbImageBboxProc;
    chunkPtr->numBytes = 1;
    if (eiPtr->body.ei.align == TK_ALIGN_BASELINE) {
    if (eiPtr->body.ei.align == ALIGN_BASELINE) {
	chunkPtr->minAscent = height - eiPtr->body.ei.padY;
	chunkPtr->minDescent = eiPtr->body.ei.padY;
	chunkPtr->minHeight = 0;
    } else {
	chunkPtr->minAscent = 0;
	chunkPtr->minDescent = 0;
	chunkPtr->minHeight = height;
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610

611
612
613
614
615
616
617
615
616
617
618
619
620
621

622
623
624
625
626
627
628

629
630
631
632
633
634
635
636







-
+






-
+







 *
 *--------------------------------------------------------------
 */

static void
EmbImageCheckProc(
    TkTextSegment *eiPtr,	/* Segment to check. */
    TCL_UNUSED(TkTextLine *))	/* Line containing segment. */
    TkTextLine *linePtr)	/* Line containing segment. */
{
    if (eiPtr->nextPtr == NULL) {
	Tcl_Panic("EmbImageCheckProc: embedded image is last segment in line");
    }
    if (eiPtr->size != 1) {
	Tcl_Panic("EmbImageCheckProc: embedded image has size %d",
		(int)eiPtr->size);
		eiPtr->size);
    }
}

/*
 *--------------------------------------------------------------
 *
 * EmbImageDisplayProc --
637
638
639
640
641
642
643
644

645
646

647
648
649

650
651
652
653
654
655
656
656
657
658
659
660
661
662

663
664

665
666
667

668
669
670
671
672
673
674
675







-
+

-
+


-
+







				 * chunk (differs from the x-position in the
				 * chunk because of scrolling). */
    int y,			/* Top of rectangular bounding box for line:
				 * tells where to draw this chunk in dst
				 * (x-position is in the chunk itself). */
    int lineHeight,		/* Total height of line. */
    int baseline,		/* Offset of baseline from y. */
    TCL_UNUSED(Display *),	/* Display to use for drawing. */
    Display *display,		/* Display to use for drawing. */
    Drawable dst,		/* Pixmap or window in which to draw */
    TCL_UNUSED(int))	/* Y-coordinate in text window that
    int screenY)		/* Y-coordinate in text window that
				 * corresponds to y. */
{
    TkTextSegment *eiPtr = (TkTextSegment *)chunkPtr->clientData;
    TkTextSegment *eiPtr = chunkPtr->clientData;
    int lineX, imageX, imageY, width, height;
    Tk_Image image;

    image = eiPtr->body.ei.image;
    if (image == NULL) {
	return;
    }
690
691
692
693
694
695
696
697

698
699

700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729
730

731
732
733

734
735
736

737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776

777
778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793

794
795
796
797
798
799
800
709
710
711
712
713
714
715

716
717

718
719
720
721
722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737
738
739
740
741
742
743
744
745

746
747
748

749
750
751

752
753
754

755
756
757
758
759
760
761
762
763
764
765
766
767
768
769



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791
792
793
794

795
796

797
798
799
800












801
802
803
804
805
806
807
808







-
+

-
+













-
+













-
+


-
+


-
+


-
+














-
-
-
+
+
+

















-
+




-
+

-
+



-
-
-
-
-
-
-
-
-
-
-
-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

static void
EmbImageBboxProc(
    TCL_UNUSED(TkText *),
    TkText *textPtr,
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired char. */
    TCL_UNUSED(Tcl_Size),			/* Index of desired character within the
    int index,			/* Index of desired character within the
				 * chunk. */
    int y,			/* Topmost pixel in area allocated for this
				 * line. */
    int lineHeight,		/* Total height of line. */
    int baseline,		/* Location of line's baseline, in pixels
				 * measured down from y. */
    int *xPtr, int *yPtr,	/* Gets filled in with coords of character's
				 * upper-left pixel. */
    int *widthPtr,		/* Gets filled in with width of image, in
				 * pixels. */
    int *heightPtr)		/* Gets filled in with height of image, in
				 * pixels. */
{
    TkTextSegment *eiPtr = (TkTextSegment *)chunkPtr->clientData;
    TkTextSegment *eiPtr = chunkPtr->clientData;
    Tk_Image image;

    image = eiPtr->body.ei.image;
    if (image != NULL) {
	Tk_SizeOfImage(image, widthPtr, heightPtr);
    } else {
	*widthPtr = 0;
	*heightPtr = 0;
    }

    *xPtr = chunkPtr->x + eiPtr->body.ei.padX;

    switch (eiPtr->body.ei.align) {
    case TK_ALIGN_BOTTOM:
    case ALIGN_BOTTOM:
	*yPtr = y + (lineHeight - *heightPtr - eiPtr->body.ei.padY);
	break;
    case TK_ALIGN_CENTER:
    case ALIGN_CENTER:
	*yPtr = y + (lineHeight - *heightPtr)/2;
	break;
    case TK_ALIGN_TOP:
    case ALIGN_TOP:
	*yPtr = y + eiPtr->body.ei.padY;
	break;
    case TK_ALIGN_BASELINE:
    case ALIGN_BASELINE:
	*yPtr = y + (baseline - *heightPtr);
	break;
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkTextImageIndex --
 *
 *	Given the name of an embedded image within a text widget, returns an
 *	index corresponding to the image's position in the text.
 *
 * Results:
 *	The return value is TCL_OK if there is an embedded image by the given
 *	name in the text widget, TCL_ERROR otherwise. If the image exists,
 *	*indexPtr is filled in with its index.
 *	The return value is 1 if there is an embedded image by the given name
 *	in the text widget, 0 otherwise. If the image exists, *indexPtr is
 *	filled in with its index.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkTextImageIndex(
    TkText *textPtr,		/* Text widget containing image. */
    const char *name,		/* Name of image. */
    TkTextIndex *indexPtr)	/* Index information gets stored here. */
{
    Tcl_HashEntry *hPtr;
    TkTextSegment *eiPtr;

    if (textPtr == NULL) {
	return TCL_ERROR;
	return 0;
    }

    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->imageTable, name);
    if (hPtr == NULL) {
	return TCL_ERROR;
	return 0;
    }
    eiPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
    eiPtr = Tcl_GetHashValue(hPtr);
    indexPtr->tree = textPtr->sharedTextPtr->tree;
    indexPtr->linePtr = eiPtr->body.ei.linePtr;
    indexPtr->byteIndex = TkTextSegToOffset(eiPtr, indexPtr->linePtr);

    /*
     * If indexPtr refers to somewhere outside the -startline/-endline
     * range limits of the widget, error out since the image indeed is not
     * reachable from this text widget (it may be reachable from a peer).
     */

    if (TkTextIndexAdjustToStartEnd(textPtr, indexPtr, 1) == TCL_ERROR) {
	return TCL_ERROR;
    }

    return TCL_OK;
    return 1;
}

/*
 *--------------------------------------------------------------
 *
 * EmbImageProc --
 *
808
809
810
811
812
813
814
815
816


817
818
819

820
821
822

823
824
825
826

827
828
829
830
831
832
833
816
817
818
819
820
821
822


823
824
825


826
827


828

829
830

831
832
833
834
835
836
837
838







-
-
+
+

-
-
+

-
-
+
-


-
+







 *	The image will be redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
EmbImageProc(
    void *clientData,	/* Pointer to widget record. */
    TCL_UNUSED(int),		/* Upper left pixel (within image) that must
    ClientData clientData,	/* Pointer to widget record. */
    int x, int y,		/* Upper left pixel (within image) that must
				 * be redisplayed. */
    TCL_UNUSED(int),
    TCL_UNUSED(int),	/* Dimensions of area to redisplay (may be
    int width, int height,	/* Dimensions of area to redisplay (may be
				 * <= 0). */
    TCL_UNUSED(int),
    TCL_UNUSED(int),/* New dimensions of image. */
    int imgWidth, int imgHeight)/* New dimensions of image. */
    TCL_UNUSED(int))

{
    TkTextSegment *eiPtr = (TkTextSegment *)clientData;
    TkTextSegment *eiPtr = clientData;
    TkTextIndex index;

    index.tree = eiPtr->body.ei.sharedTextPtr->tree;
    index.linePtr = eiPtr->body.ei.linePtr;
    index.byteIndex = TkTextSegToOffset(eiPtr, eiPtr->body.ei.linePtr);
    TkTextChanged(eiPtr->body.ei.sharedTextPtr, NULL, &index, &index);

Changes to generic/tkTextIndex.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15


16
17
18
19

20
21
22
23
24
25
26
27
1
2
3
4
5
6


7
8
9
10
11
12
13


14
15




16

17
18
19
20
21
22
23






-
-
+
+





-
-
+
+
-
-
-
-
+
-







/*
 * tkTextIndex.c --
 *
 *	This module provides functions that manipulate indices for text
 *	widgets.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkText.h"
#include "default.h"
#include "tkInt.h"
#include "default.h"

#ifdef _WIN32
#include "tkWinInt.h"
#include "tkText.h"
#endif

/*
 * Index to use to select last character in line (very large integer):
 */

#define LAST_CHAR 1000000

62
63
64
65
66
67
68
69

70
71

72
73
74
75
76
77
78
79


80
81
82
83

84
85
86
87
88
89
90
91
92
58
59
60
61
62
63
64

65
66

67
68
69
70
71
72
73


74
75
76
77
78

79


80
81
82
83
84
85
86







-
+

-
+






-
-
+
+



-
+
-
-







 */

#define GET_TEXTINDEX(objPtr) \
	((TkTextIndex *) (objPtr)->internalRep.twoPtrValue.ptr1)
#define GET_INDEXEPOCH(objPtr) \
	(PTR2INT((objPtr)->internalRep.twoPtrValue.ptr2))
#define SET_TEXTINDEX(objPtr, indexPtr) \
	((objPtr)->internalRep.twoPtrValue.ptr1 = (void *)(indexPtr))
	((objPtr)->internalRep.twoPtrValue.ptr1 = (void *) (indexPtr))
#define SET_INDEXEPOCH(objPtr, epoch) \
	((objPtr)->internalRep.twoPtrValue.ptr2 = (void *) (size_t) (epoch))
	((objPtr)->internalRep.twoPtrValue.ptr2 = INT2PTR(epoch))

/*
 * Define the 'textindex' object type, which Tk uses to represent indices in
 * text widgets internally.
 */

const TkObjType tkTextIndexType = {
    {"textindex",		/* name */
const Tcl_ObjType tkTextIndexType = {
    "textindex",		/* name */
    FreeTextIndexInternalRep,	/* freeIntRepProc */
    DupTextIndexInternalRep,	/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

static void
FreeTextIndexInternalRep(
    Tcl_Obj *indexObjPtr)	/* TextIndex object with internal rep to
				 * free. */
{
106
107
108
109
110
111
112
113

114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148

149
150
151
152
153
154
155
100
101
102
103
104
105
106

107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141

142
143
144
145
146
147
148
149







-
+


-
+












-
+













-
+




-
+







}

static void
DupTextIndexInternalRep(
    Tcl_Obj *srcPtr,		/* TextIndex obj with internal rep to copy. */
    Tcl_Obj *copyPtr)		/* TextIndex obj with internal rep to set. */
{
    Tcl_Size epoch;
    int epoch;
    TkTextIndex *dupIndexPtr, *indexPtr;

    dupIndexPtr = (TkTextIndex *)ckalloc(sizeof(TkTextIndex));
    dupIndexPtr = ckalloc(sizeof(TkTextIndex));
    indexPtr = GET_TEXTINDEX(srcPtr);
    epoch = GET_INDEXEPOCH(srcPtr);

    dupIndexPtr->tree = indexPtr->tree;
    dupIndexPtr->linePtr = indexPtr->linePtr;
    dupIndexPtr->byteIndex = indexPtr->byteIndex;
    dupIndexPtr->textPtr = indexPtr->textPtr;
    if (dupIndexPtr->textPtr != NULL) {
	dupIndexPtr->textPtr->refCount++;
    }
    SET_TEXTINDEX(copyPtr, dupIndexPtr);
    SET_INDEXEPOCH(copyPtr, epoch);
    copyPtr->typePtr = &tkTextIndexType.objType;
    copyPtr->typePtr = &tkTextIndexType;
}

/*
 * This will not be called except by TkTextNewIndexObj below. This is because
 * if a TkTextIndex is no longer valid, it is not possible to regenerate the
 * string representation.
 */

static void
UpdateStringOfTextIndex(
    Tcl_Obj *objPtr)
{
    char buffer[TK_POS_CHARS];
    size_t len;
    register int len;
    const TkTextIndex *indexPtr = GET_TEXTINDEX(objPtr);

    len = TkTextPrintIndex(indexPtr->textPtr, indexPtr, buffer);

    objPtr->bytes = (char *)ckalloc(len + 1);
    objPtr->bytes = ckalloc(len + 1);
    strcpy(objPtr->bytes, buffer);
    objPtr->length = len;
}

/*
 *---------------------------------------------------------------------------
 *
178
179
180
181
182
183
184
185

186
187
188
189
190
191

192
193
194
195
196
197
198
172
173
174
175
176
177
178

179
180
181
182
183
184

185
186
187
188
189
190
191
192







-
+





-
+







static TkTextIndex *
MakeObjIndex(
    TkText *textPtr,		/* Information about text widget. */
    Tcl_Obj *objPtr,		/* Object containing description of
				 * position. */
    const TkTextIndex *origPtr)	/* Pointer to index. */
{
    TkTextIndex *indexPtr = (TkTextIndex *)ckalloc(sizeof(TkTextIndex));
    TkTextIndex *indexPtr = ckalloc(sizeof(TkTextIndex));

    indexPtr->tree = origPtr->tree;
    indexPtr->linePtr = origPtr->linePtr;
    indexPtr->byteIndex = origPtr->byteIndex;
    SET_TEXTINDEX(objPtr, indexPtr);
    objPtr->typePtr = &tkTextIndexType.objType;
    objPtr->typePtr = &tkTextIndexType;
    indexPtr->textPtr = textPtr;

    if (textPtr != NULL) {
	textPtr->refCount++;
	SET_INDEXEPOCH(objPtr, textPtr->sharedTextPtr->stateEpoch);
    } else {
	SET_INDEXEPOCH(objPtr, 0);
207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
201
202
203
204
205
206
207


208
209
210
211
212
213
214
215
216







-
-
+
+







    Tcl_Obj *objPtr)		/* Object containing description of
				 * position. */
{
    TkTextIndex index;
    TkTextIndex *indexPtr = NULL;
    int cache;

    if (objPtr->typePtr == &tkTextIndexType.objType) {
	Tcl_Size epoch;
    if (objPtr->typePtr == &tkTextIndexType) {
	int epoch;

	indexPtr = GET_TEXTINDEX(objPtr);
	epoch = GET_INDEXEPOCH(objPtr);

	if (epoch == textPtr->sharedTextPtr->stateEpoch) {
	    if (indexPtr->textPtr == textPtr) {
		return indexPtr;
383
384
385
386
387
388
389
390

391
392
393
394
395
396

397
398
399
400
401
402
403
377
378
379
380
381
382
383

384
385
386
387
388
389

390
391
392
393
394
395
396
397







-
+





-
+







TkTextIndex *
TkTextMakeByteIndex(
    TkTextBTree tree,	/* Tree that lineIndex and byteIndex refer
				 * to. */
    const TkText *textPtr,
    int lineIndex,		/* Index of desired line (0 means first line
				 * of text). */
    Tcl_Size byteIndex,		/* Byte index of desired character. */
    int byteIndex,		/* Byte index of desired character. */
    TkTextIndex *indexPtr)	/* Structure to fill in. */
{
    TkTextSegment *segPtr;
    int index;
    const char *p, *start;
    int ch;
    Tcl_UniChar ch;

    indexPtr->tree = tree;
    if (lineIndex < 0) {
	lineIndex = 0;
	byteIndex = 0;
    }
    if (byteIndex < 0) {
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435







-
+







	     * character on the line is guaranteed to be a '\n', we can back
	     * up a constant sizeof(char) bytes.
	     */

	    indexPtr->byteIndex = index - sizeof(char);
	    break;
	}
	if (index + (int)segPtr->size > byteIndex) {
	if (index + segPtr->size > byteIndex) {
	    indexPtr->byteIndex = byteIndex;
	    if ((byteIndex > index) && (segPtr->typePtr == &tkTextCharType)) {
		/*
		 * Prevent UTF-8 character from being split up by ensuring
		 * that byteIndex falls on a character boundary. If the index
		 * falls in the middle of a UTF-8 character, it will be
		 * adjusted to the end of that UTF-8 character.
479
480
481
482
483
484
485
486

487
488
489

490
491
492
493
494
495
496
473
474
475
476
477
478
479

480
481
482

483
484
485
486
487
488
489
490







-
+


-
+







				 * to. */
    TkText *textPtr,
    int lineIndex,		/* Index of desired line (0 means first line
				 * of text). */
    int charIndex,		/* Index of desired character. */
    TkTextIndex *indexPtr)	/* Structure to fill in. */
{
    TkTextSegment *segPtr;
    register TkTextSegment *segPtr;
    char *p, *start, *end;
    int index, offset;
    Tcl_UniChar ch = 0;
    Tcl_UniChar ch;

    indexPtr->tree = tree;
    if (lineIndex < 0) {
	lineIndex = 0;
	charIndex = 0;
    }
    if (charIndex < 0) {
533
534
535
536
537
538
539
540

541
542
543
544
545
546
547
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541







-
+







		    return indexPtr;
		}
		charIndex--;
		offset = Tcl_UtfToUniChar(p, &ch);
		index += offset;
	    }
	} else {
	    if (charIndex < (int)segPtr->size) {
	    if (charIndex < segPtr->size) {
		indexPtr->byteIndex = index;
		break;
	    }
	    charIndex -= segPtr->size;
	    index += segPtr->size;
	}
    }
567
568
569
570
571
572
573
574

575
576
577
578

579
580
581
582
583
584
585
561
562
563
564
565
566
567

568
569
570
571

572
573
574
575
576
577
578
579







-
+



-
+







 *
 *---------------------------------------------------------------------------
 */

TkTextSegment *
TkTextIndexToSeg(
    const TkTextIndex *indexPtr,/* Text index. */
    Tcl_Size *offsetPtr)		/* Where to store offset within segment, or
    int *offsetPtr)		/* Where to store offset within segment, or
				 * NULL if offset isn't wanted. */
{
    TkTextSegment *segPtr;
    Tcl_Size offset;
    int offset;

    for (offset = indexPtr->byteIndex, segPtr = indexPtr->linePtr->segPtr;
	    offset >= segPtr->size;
	    offset -= segPtr->size, segPtr = segPtr->nextPtr) {
	/* Empty loop body. */
    }
    if (offsetPtr != NULL) {
602
603
604
605
606
607
608
609

610
611
612
613
614
615

616
617
618
619
620
621
622
596
597
598
599
600
601
602

603
604
605
606
607
608

609
610
611
612
613
614
615
616







-
+





-
+







 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

Tcl_Size
int
TkTextSegToOffset(
    const TkTextSegment *segPtr,/* Segment whose offset is desired. */
    const TkTextLine *linePtr)	/* Line containing segPtr. */
{
    const TkTextSegment *segPtr2;
    Tcl_Size offset = 0;
    int offset = 0;

    for (segPtr2 = linePtr->segPtr; segPtr2 != segPtr;
	    segPtr2 = segPtr2->nextPtr) {
	offset += segPtr2->size;
    }
    return offset;
}
763
764
765
766
767
768
769
770

771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795

796
797
798
799
800
801
802
757
758
759
760
761
762
763

764
765
766
767

768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796







-
+



-
+




















-
+







     *---------------------------------------------------------------------
     */

    if (TkTextMarkNameToIndex(textPtr, string, indexPtr) == TCL_OK) {
	goto done;
    }

    if (TkTextWindowIndex(textPtr, string, indexPtr) == TCL_OK) {
    if (TkTextWindowIndex(textPtr, string, indexPtr) != 0) {
	goto done;
    }

    if (TkTextImageIndex(textPtr, string, indexPtr) == TCL_OK) {
    if (TkTextImageIndex(textPtr, string, indexPtr) != 0) {
	goto done;
    }

    /*
     *------------------------------------------------
     * Stage 2: start again by parsing the base index.
     *------------------------------------------------
     */

    indexPtr->tree = sharedPtr->tree;

    /*
     * First look for the form "tag.first" or "tag.last" where "tag" is the
     * name of a valid tag. Try to use up as much as possible of the string in
     * this check (strrchr instead of strchr below). Doing the check now, and
     * in this way, allows tag names to include funny characters like "@" or
     * "+1c".
     */

    Tcl_DStringInit(&copy);
    p = strrchr(Tcl_DStringAppend(&copy, string, TCL_INDEX_NONE), '.');
    p = strrchr(Tcl_DStringAppend(&copy, string, -1), '.');
    if (p != NULL) {
	TkTextSearch search;
	TkTextTag *tagPtr;
	Tcl_HashEntry *hPtr = NULL;
	const char *tagName;

	if ((p[1] == 'f') && (strncmp(p+1, "first", 5) == 0)) {
818
819
820
821
822
823
824
825

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

842
843
844
845
846
847

848
849
850
851
852
853
854
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840

841
842
843
844
845
846
847
848







-
+















-
+





-
+








	    tagPtr = textPtr->selTagPtr;
	} else {
	    *p = 0;
	    hPtr = Tcl_FindHashEntry(&sharedPtr->tagTable, tagName);
	    *p = '.';
	    if (hPtr != NULL) {
		tagPtr = (TkTextTag *)Tcl_GetHashValue(hPtr);
		tagPtr = Tcl_GetHashValue(hPtr);
	    }
	}

	if (tagPtr == NULL) {
	    goto tryxy;
	}

	TkTextMakeByteIndex(sharedPtr->tree, textPtr, 0, 0, &first);
	TkTextMakeByteIndex(sharedPtr->tree, textPtr,
		TkBTreeNumLines(sharedPtr->tree, textPtr), 0, &last);
	TkBTreeStartSearch(&first, &last, tagPtr, &search);
	if (!TkBTreeCharTagged(&first, tagPtr) && !TkBTreeNextTag(&search)) {
	    if (tagPtr == textPtr->selTagPtr) {
		tagName = "sel";
	    } else if (hPtr != NULL) {
		tagName = (const char *)Tcl_GetHashKey(&sharedPtr->tagTable, hPtr);
		tagName = Tcl_GetHashKey(&sharedPtr->tagTable, hPtr);
	    }
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "text doesn't contain any characters tagged with \"%s\"",
		    tagName));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TEXT_INDEX", tagName,
		    (char *)NULL);
		    NULL);
	    Tcl_DStringFree(&copy);
	    return TCL_ERROR;
	}
	*indexPtr = search.curIndex;
	if (wantLast) {
	    while (TkBTreeNextTag(&search)) {
		*indexPtr = search.curIndex;
919
920
921
922
923
924
925
926

927
928
929
930
931
932

933
934
935
936
937
938
939
913
914
915
916
917
918
919

920
921
922
923
924
925

926
927
928
929
930
931
932
933







-
+





-
+







	 * See if the base position is the name of an embedded window.
	 */

	c = *endOfBase;
	*endOfBase = 0;
	result = TkTextWindowIndex(textPtr, Tcl_DStringValue(&copy), indexPtr);
	*endOfBase = c;
	if (result == TCL_OK) {
	if (result != 0) {
	    goto gotBase;
	}
    }
    if ((string[0] == 'e')
	    && (strncmp(string, "end",
	    endOfBase-Tcl_DStringValue(&copy)) == 0)) {
	    (size_t) (endOfBase-Tcl_DStringValue(&copy))) == 0)) {
	/*
	 * Base position is end of text.
	 */

	TkTextMakeByteIndex(sharedPtr->tree, textPtr,
		TkBTreeNumLines(sharedPtr->tree, textPtr), 0, indexPtr);
	canCache = 1;
956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
950
951
952
953
954
955
956

957
958
959
960
961
962
963
964







-
+







	 * See if the base position is the name of an embedded image.
	 */

	c = *endOfBase;
	*endOfBase = 0;
	result = TkTextImageIndex(textPtr, Tcl_DStringValue(&copy), indexPtr);
	*endOfBase = c;
	if (result == TCL_OK) {
	if (result != 0) {
	    goto gotBase;
	}
    }
    goto error;

    /*
     *-------------------------------------------------------------------
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
993
994
995
996
997
998
999

1000
1001
1002
1003
1004

1005
1006





























































1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1043







-





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+








-
+







  done:
    if (canCachePtr != NULL) {
	*canCachePtr = canCache;
    }
    if (indexPtr->linePtr == NULL) {
	Tcl_Panic("Bad index created");
    }
    TkTextIndexAdjustToStartEnd(textPtr, indexPtr, 0);
    return TCL_OK;

  error:
    Tcl_DStringFree(&copy);
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad text index \"%s\"", string));
    Tcl_SetErrorCode(interp, "TK", "TEXT", "BAD_INDEX", (char *)NULL);
    Tcl_SetErrorCode(interp, "TK", "TEXT", "BAD_INDEX", NULL);
    return TCL_ERROR;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkTextIndexAdjustToStartEnd --
 *
 *      Adjust indexPtr to the -startline/-endline range, or just check
 *      if indexPtr is out of this range.
 *
 * Results:
 *	The return value is a standard Tcl return result. If check is true,
 *      return TCL_ERROR if indexPtr is outside the -startline/-endline
 *      range (indexPtr is not modified).
 *      If check is false, adjust indexPtr to -startline/-endline.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int
TkTextIndexAdjustToStartEnd(
    TkText *textPtr,
    TkTextIndex *indexPtr,  /* Pointer to index. */
    int check)		    /* 1 means only check indexPtr against
			     * the -startline/-endline range
			     * 0 means adjust to this range */
{
    int bound;
    TkTextIndex indexBound;

    if (!textPtr) {
	return TCL_OK;
    }
    if (textPtr->start != NULL) {
	bound = TkBTreeLinesTo(NULL, textPtr->start);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, bound, 0,
		&indexBound);
	if (TkTextIndexCmp(indexPtr, &indexBound) < 0) {
	    if (check) {
		return TCL_ERROR;
	    }
	    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, bound, 0,
		    indexPtr);
	}
    }
    if (textPtr->end != NULL) {
	bound = TkBTreeLinesTo(NULL, textPtr->end);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, bound, 0,
		&indexBound);
	if (TkTextIndexCmp(indexPtr, &indexBound) > 0) {
	    if (check) {
		return TCL_ERROR;
	    }
	    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, bound, 0,
		    indexPtr);
	}
    }
    return TCL_OK;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkTextPrintIndex --
 *
 *	This function generates a string description of an index, suitable for
 *	reading in again later.
 *
 * Results:
 *	The characters pointed to by string are modified. Returns the number
 *	of characters in the string.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

Tcl_Size
int
TkTextPrintIndex(
    const TkText *textPtr,
    const TkTextIndex *indexPtr,/* Pointer to index. */
    char *string)		/* Place to store the position. Must have at
				 * least TK_POS_CHARS characters. */
{
    TkTextSegment *segPtr;
    TkTextLine *linePtr;
    Tcl_Size numBytes, charIndex;
    int numBytes, charIndex;

    numBytes = indexPtr->byteIndex;
    charIndex = 0;
    linePtr = indexPtr->linePtr;

    for (segPtr = linePtr->segPtr; ; segPtr = segPtr->nextPtr) {
	if (segPtr == NULL) {
1130
1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1076







-
+








    if (segPtr->typePtr == &tkTextCharType) {
	charIndex += Tcl_NumUtfChars(segPtr->body.chars, numBytes);
    } else {
	charIndex += numBytes;
    }

    return snprintf(string, TK_POS_CHARS, "%d.%" TCL_SIZE_MODIFIER "d",
    return sprintf(string, "%d.%d",
	    TkBTreeLinesTo(textPtr, indexPtr->linePtr) + 1, charIndex);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkTextIndexCmp --
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1147
1148
1149
1150
1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
1161







-
+







ForwBack(
    TkText *textPtr,		/* Information about text widget. */
    const char *string,		/* String to parse for additional info about
				 * modifier (count and units). Points to "+"
				 * or "-" that starts modifier. */
    TkTextIndex *indexPtr)	/* Index to update as specified in string. */
{
    const char *p, *units;
    register const char *p, *units;
    char *end;
    int count, lineIndex, modifier;
    size_t length;

    /*
     * Get the count (how many units forward or backward).
     */
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392

1393
1394
1395
1396
1397
1398

1399
1400
1401
1402

1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312


1313
1314
1315
1316
1317
1318

1319
1320

1321






1322




1323




1324
1325
1326
1327
1328
1329
1330







-












-
-






-
+

-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-







	    if (count == 0) {
		return p;
	    }

	    if (forward) {
		TkTextFindDisplayLineEnd(textPtr, indexPtr, 1, &xOffset);
		while (count-- > 0) {

		    /*
		     * Go to the end of the line, then forward one char/byte
		     * to get to the beginning of the next line.
		     */

		    TkTextFindDisplayLineEnd(textPtr, indexPtr, 1, NULL);
		    TkTextIndexForwChars(textPtr, indexPtr, 1, indexPtr,
			    COUNT_DISPLAY_INDICES);
		}
	    } else {
		TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, &xOffset);
		while (count-- > 0) {
                    TkTextIndex indexPtr2;

		    /*
		     * Go to the beginning of the line, then backward one
		     * char/byte to get to the end of the previous line.
		     */

		    TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, NULL);
		    TkTextIndexBackChars(textPtr, indexPtr, 1, &indexPtr2,
		    TkTextIndexBackChars(textPtr, indexPtr, 1, indexPtr,
			    COUNT_DISPLAY_INDICES);

		}
                    /*
                     * If we couldn't go to the previous line, then we wanted
                       to go before the start of the text: arrange for returning
                       the first index of the first display line.
                     */

		TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, NULL);
                    if (!TkTextIndexCmp(indexPtr, &indexPtr2)) {
                        xOffset = 0;
                        break;
                    }
	    }
                    *indexPtr = indexPtr2;
		}
	    }
            TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, NULL);

	    /*
	     * This call assumes indexPtr is the beginning of a display line
	     * and moves it to the 'xOffset' position of that line, which is
	     * just what we want.
	     */

1472
1473
1474
1475
1476
1477
1478
1479

1480
1481
1482
1483
1484
1485
1486
1389
1390
1391
1392
1393
1394
1395

1396
1397
1398
1399
1400
1401
1402
1403







-
+







 *---------------------------------------------------------------------------
 */

int
TkTextIndexForwBytes(
    const TkText *textPtr,
    const TkTextIndex *srcPtr,	/* Source index. */
    Tcl_Size byteCount,		/* How many bytes forward to move. May be
    int byteCount,		/* How many bytes forward to move. May be
				 * negative. */
    TkTextIndex *dstPtr)	/* Destination index: gets modified. */
{
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    int lineLength;

1552
1553
1554
1555
1556
1557
1558
1559

1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570

1571
1572
1573
1574
1575
1576
1577
1469
1470
1471
1472
1473
1474
1475

1476
1477

1478
1479
1480
1481
1482
1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493
1494







-
+

-
+








-
+







				 * be negative. */
    TkTextIndex *dstPtr,	/* Destination index: gets modified. */
    TkTextCountType type)	/* The type of item to count */
{
    TkTextLine *linePtr;
    TkTextSegment *segPtr;
    TkTextElideInfo *infoPtr = NULL;
    Tcl_Size byteOffset;
    int byteOffset;
    char *start, *end, *p;
    int ch;
    Tcl_UniChar ch;
    int elide = 0;
    int checkElided = (type & COUNT_DISPLAY);

    if (charCount < 0) {
	TkTextIndexBackChars(textPtr, srcPtr, -charCount, dstPtr, type);
	return;
    }
    if (checkElided) {
	infoPtr = (TkTextElideInfo *)ckalloc(sizeof(TkTextElideInfo));
	infoPtr = ckalloc(sizeof(TkTextElideInfo));
	elide = TkTextIsElided(textPtr, srcPtr, infoPtr);
    }

    *dstPtr = *srcPtr;

    /*
     * Find seg that contains src byteIndex. Move forward specified number of
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535
1536
1537
1538
1539
1540







-
+








		/*
		 * The elide state only changes if this tag is either the
		 * current highest priority tag (and is therefore being
		 * toggled off), or it's a new tag with higher priority.
		 */

		if (tagPtr->elide >= 0) {
		if (tagPtr->elideString != NULL) {
		    infoPtr->tagCnts[tagPtr->priority]++;
		    if (infoPtr->tagCnts[tagPtr->priority] & 1) {
			infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
		    }

		    if (tagPtr->priority >= infoPtr->elidePriority) {
			if (segPtr->typePtr == &tkTextToggleOffType) {
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668

1669
1670
1671
1672
1673
1674
1675
1554
1555
1556
1557
1558
1559
1560

1561
1562
1563
1564
1565

1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584

1585
1586
1587
1588
1589
1590
1591
1592







-
+




-
+


















-
+







			     */

			    elide = 0;
			    while (--infoPtr->elidePriority > 0) {
				if (infoPtr->tagCnts[infoPtr->elidePriority]
					& 1) {
				    elide = infoPtr->tagPtrs
					    [infoPtr->elidePriority]->elide > 0;
					    [infoPtr->elidePriority]->elide;
				    break;
				}
			    }
			} else {
			    elide = tagPtr->elide > 0;
			    elide = tagPtr->elide;
			    infoPtr->elidePriority = tagPtr->priority;
			}
		    }
		}
	    }

	    if (!elide) {
		if (segPtr->typePtr == &tkTextCharType) {
		    start = segPtr->body.chars + byteOffset;
		    end = segPtr->body.chars + segPtr->size;
		    for (p = start; p < end; p += Tcl_UtfToUniChar(p, &ch)) {
			if (charCount == 0) {
			    dstPtr->byteIndex += (p - start);
			    goto forwardCharDone;
			}
			charCount--;
		    }
		} else if (type & COUNT_INDICES) {
		    if (charCount + byteOffset < segPtr->size) {
		    if (charCount < segPtr->size - byteOffset) {
			dstPtr->byteIndex += charCount;
			goto forwardCharDone;
		    }
		    charCount -= segPtr->size - byteOffset;
		}
	    }

1740
1741
1742
1743
1744
1745
1746
1747

1748
1749
1750
1751
1752
1753
1754
1657
1658
1659
1660
1661
1662
1663

1664
1665
1666
1667
1668
1669
1670
1671







-
+







    const TkTextIndex *indexPtr1,
				/* Index describing location of character from
				 * which to count. */
    const TkTextIndex *indexPtr2)
				/* Index describing location of last character
				 * at which to stop the count. */
{
    Tcl_Size byteCount, offset;
    int byteCount, offset;
    TkTextSegment *segPtr, *segPtr1;
    TkTextLine *linePtr;

    if (indexPtr1->linePtr == indexPtr2->linePtr) {
        return indexPtr2->byteIndex - indexPtr1->byteIndex;
    }

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
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







-
+
-













-
+







				/* Index describing location of last character
				 * at which to stop the count. */
    TkTextCountType type)	/* The kind of indices to count. */
{
    TkTextLine *linePtr1;
    TkTextSegment *segPtr, *seg2Ptr = NULL;
    TkTextElideInfo *infoPtr = NULL;
    Tcl_Size byteOffset, maxBytes, count = 0;
    int byteOffset, maxBytes, count = 0, elide = 0;
    int elide = 0;
    int checkElided = (type & COUNT_DISPLAY);

    /*
     * Find seg that contains src index, and remember how many bytes not to
     * count in the given segment.
     */

    segPtr = TkTextIndexToSeg(indexPtr1, &byteOffset);
    linePtr1 = indexPtr1->linePtr;

    seg2Ptr = TkTextIndexToSeg(indexPtr2, &maxBytes);

    if (checkElided) {
	infoPtr = (TkTextElideInfo *)ckalloc(sizeof(TkTextElideInfo));
	infoPtr = ckalloc(sizeof(TkTextElideInfo));
	elide = TkTextIsElided(textPtr, indexPtr1, infoPtr);
    }

    while (1) {
	/*
	 * Go through each segment in line adding up the number of characters.
	 */
1859
1860
1861
1862
1863
1864
1865
1866

1867
1868
1869
1870
1871
1872
1873
1775
1776
1777
1778
1779
1780
1781

1782
1783
1784
1785
1786
1787
1788
1789







-
+








		    /*
		     * The elide state only changes if this tag is either the
		     * current highest priority tag (and is therefore being
		     * toggled off), or it's a new tag with higher priority.
		     */

		    if (tagPtr->elide >= 0) {
		    if (tagPtr->elideString != NULL) {
			infoPtr->tagCnts[tagPtr->priority]++;
			if (infoPtr->tagCnts[tagPtr->priority] & 1) {
			    infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
			}
			if (tagPtr->priority >= infoPtr->elidePriority) {
			    if (segPtr->typePtr == &tkTextToggleOffType) {
				/*
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
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







-
+




-
+















-
-
+
+

-
+


-
+







				 */

				elide = 0;
				while (--infoPtr->elidePriority > 0) {
				    if (infoPtr->tagCnts[
					    infoPtr->elidePriority] & 1) {
					elide = infoPtr->tagPtrs[
						infoPtr->elidePriority]->elide > 0;
						infoPtr->elidePriority]->elide;
					break;
				    }
				}
			    } else {
				elide = tagPtr->elide > 0;
				elide = tagPtr->elide;
				infoPtr->elidePriority = tagPtr->priority;
			    }
			}
		    }
		}
		if (elide) {
		    if (segPtr == seg2Ptr) {
			goto countDone;
		    }
		    byteOffset = 0;
		    continue;
		}
	    }

	    if (segPtr->typePtr == &tkTextCharType) {
		Tcl_Size byteLen = segPtr->size - byteOffset;
		unsigned char *str = (unsigned char *)
		int byteLen = segPtr->size - byteOffset;
		register unsigned char *str = (unsigned char *)
			segPtr->body.chars + byteOffset;
		Tcl_Size i;
		register int i;

		if (segPtr == seg2Ptr) {
		    if (byteLen + byteOffset > maxBytes) {
		    if (byteLen > (maxBytes - byteOffset)) {
			byteLen = maxBytes - byteOffset;
		    }
		}
		i = byteLen;

		/*
		 * This is a speed sensitive function, so run specially over
1941
1942
1943
1944
1945
1946
1947
1948

1949
1950
1951

1952
1953
1954
1955
1956
1957
1958
1857
1858
1859
1860
1861
1862
1863

1864
1865
1866

1867
1868
1869
1870
1871
1872
1873
1874







-
+


-
+







		count += byteLen - i;
		if (i) {
		    count += Tcl_NumUtfChars(segPtr->body.chars + byteOffset
			    + (byteLen - i), i);
		}
	    } else {
		if (type & COUNT_INDICES) {
		    Tcl_Size byteLen = segPtr->size - byteOffset;
		    int byteLen = segPtr->size - byteOffset;

		    if (segPtr == seg2Ptr) {
			if (byteLen + byteOffset > maxBytes) {
			if (byteLen > (maxBytes - byteOffset)) {
			    byteLen = maxBytes - byteOffset;
			}
		    }
		    count += byteLen;
		}
	    }
	    if (segPtr == seg2Ptr) {
2003
2004
2005
2006
2007
2008
2009
2010

2011
2012
2013
2014
2015
2016
2017
1919
1920
1921
1922
1923
1924
1925

1926
1927
1928
1929
1930
1931
1932
1933







-
+







 *---------------------------------------------------------------------------
 */

int
TkTextIndexBackBytes(
    const TkText *textPtr,
    const TkTextIndex *srcPtr,	/* Source index. */
    Tcl_Size byteCount,		/* How many bytes backward to move. May be
    int byteCount,		/* How many bytes backward to move. May be
				 * negative. */
    TkTextIndex *dstPtr)	/* Destination index: gets modified. */
{
    TkTextSegment *segPtr;
    int lineIndex;

    if (byteCount < 0) {
2090
2091
2092
2093
2094
2095
2096
2097

2098
2099
2100
2101
2102
2103
2104
2006
2007
2008
2009
2010
2011
2012

2013
2014
2015
2016
2017
2018
2019
2020







-
+







    int checkElided = (type & COUNT_DISPLAY);

    if (charCount < 0) {
	TkTextIndexForwChars(textPtr, srcPtr, -charCount, dstPtr, type);
	return;
    }
    if (checkElided) {
	infoPtr = (TkTextElideInfo *)ckalloc(sizeof(TkTextElideInfo));
	infoPtr = ckalloc(sizeof(TkTextElideInfo));
	elide = TkTextIsElided(textPtr, srcPtr, infoPtr);
    }

    *dstPtr = *srcPtr;

    /*
     * Find offset within seg that contains byteIndex. Move backward specified
2120
2121
2122
2123
2124
2125
2126
2127

2128
2129
2130
2131
2132
2133
2134
2036
2037
2038
2039
2040
2041
2042

2043
2044
2045
2046
2047
2048
2049
2050







-
+







		 * Two logical lines merged into one display line through
		 * eliding of a newline.
		 */

		linePtr = TkBTreeNextLine(NULL, linePtr);
		segPtr = linePtr->segPtr;
	    }
	    if (segSize <= (int)segPtr->size) {
	    if (segSize <= segPtr->size) {
		break;
	    }
	    segSize -= segPtr->size;
	}
    }

    /*
2148
2149
2150
2151
2152
2153
2154
2155

2156
2157
2158
2159
2160
2161
2162
2064
2065
2066
2067
2068
2069
2070

2071
2072
2073
2074
2075
2076
2077
2078







-
+








	    /*
	     * The elide state only changes if this tag is either the current
	     * highest priority tag (and is therefore being toggled off), or
	     * it's a new tag with higher priority.
	     */

	    if (tagPtr->elide >= 0) {
	    if (tagPtr->elideString != NULL) {
		infoPtr->tagCnts[tagPtr->priority]++;
		if (infoPtr->tagCnts[tagPtr->priority] & 1) {
		    infoPtr->tagPtrs[tagPtr->priority] = tagPtr;
		}
		if (tagPtr->priority >= infoPtr->elidePriority) {
		    if (segPtr->typePtr == &tkTextToggleOnType) {
			/*
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
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







-
+




-
+


















-
-
-
-
-
+
-







			 * will be zero, of course).
			 */

			elide = 0;
			while (--infoPtr->elidePriority > 0) {
			    if (infoPtr->tagCnts[infoPtr->elidePriority] & 1) {
				elide = infoPtr->tagPtrs[
					infoPtr->elidePriority]->elide > 0;
					infoPtr->elidePriority]->elide;
				break;
			    }
			}
		    } else {
			elide = tagPtr->elide > 0;
			elide = tagPtr->elide;
			infoPtr->elidePriority = tagPtr->priority;
		    }
		}
	    }
	}

	if (!elide) {
	    if (segPtr->typePtr == &tkTextCharType) {
		start = segPtr->body.chars;
		end = segPtr->body.chars + segSize;
		for (p = end; ; p = Tcl_UtfPrev(p, start)) {
		    if (charCount == 0) {
			dstPtr->byteIndex -= (end - p);
			goto backwardCharDone;
		    }
		    if (p == start) {
			break;
		    }
		    if ((sizeof(Tcl_UniChar) == 2) &&  (unsigned)(UCHAR(*p) - 0xF0) <= 5) {
			charCount--; /* Characters > U+FFFF count as 2 here */
		    }
		    if (charCount != 0) {
			charCount--;
		    charCount--;
		    }
		}
	    } else {
		if (type & COUNT_INDICES) {
		    if (charCount <= segSize) {
			dstPtr->byteIndex -= charCount;
			goto backwardCharDone;
		    }
2295
2296
2297
2298
2299
2300
2301
2302

2303
2304
2305
2306
2307
2308
2309
2206
2207
2208
2209
2210
2211
2212

2213
2214
2215
2216
2217
2218
2219
2220







-
+







    const char *string,		/* String to parse for additional info about
				 * modifier (count and units). Points to first
				 * character of modifier word. */
    TkTextIndex *indexPtr)	/* Index to modify based on string. */
{
    const char *p;
    size_t length;
    TkTextSegment *segPtr;
    register TkTextSegment *segPtr;
    int modifier;

    /*
     * Find the end of the modifier word.
     */

    for (p = string; isalnum(UCHAR(*p)); p++) {
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
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







-
+


















-
+







	    TkTextFindDisplayLineEnd(textPtr, indexPtr, 0, NULL);
	} else {
	    indexPtr->byteIndex = 0;
	}
    } else if ((*string == 'w') && (strncmp(string, "wordend", length) == 0)
	    && (length >= 5)) {
	int firstChar = 1;
	Tcl_Size offset;
	int offset;

	/*
	 * If the current character isn't part of a word then just move
	 * forward one character. Otherwise move forward until finding a
	 * character that isn't part of a word and stop there.
	 */

	if (modifier == TKINDEX_DISPLAY) {
	    TkTextIndexForwChars(textPtr, indexPtr, 0, indexPtr,
		    COUNT_DISPLAY_INDICES);
	}
	segPtr = TkTextIndexToSeg(indexPtr, &offset);
	while (1) {
	    int chSize = 1;

	    if (segPtr->typePtr == &tkTextCharType) {
		int ch;

		chSize = Tcl_UtfToUniChar(segPtr->body.chars + offset, &ch);
		chSize = TkUtfToUniChar(segPtr->body.chars + offset, &ch);
		if (!Tcl_UniCharIsWordChar(ch)) {
		    break;
		}
		firstChar = 0;
	    }
	    offset += chSize;
	    indexPtr->byteIndex += chSize;
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
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







-
+




















-
+



-
+






-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

+
+
+







		TkTextIndexForwChars(NULL, indexPtr, 1, indexPtr,
			COUNT_INDICES);
	    }
	}
    } else if ((*string == 'w') && (strncmp(string, "wordstart", length) == 0)
	    && (length >= 5)) {
	int firstChar = 1;
	Tcl_Size offset;
	int offset;

	if (modifier == TKINDEX_DISPLAY) {
	    TkTextIndexForwChars(textPtr, indexPtr, 0, indexPtr,
		    COUNT_DISPLAY_INDICES);
	}

	/*
	 * Starting with the current character, look for one that's not part
	 * of a word and keep moving backward until you find one. Then if the
	 * character found wasn't the first one, move forward again one
	 * position.
	 */

	segPtr = TkTextIndexToSeg(indexPtr, &offset);
	while (1) {
	    int chSize = 1;

	    if (segPtr->typePtr == &tkTextCharType) {

		int ch;
		Tcl_UtfToUniChar(segPtr->body.chars + offset, &ch);
		TkUtfToUniChar(segPtr->body.chars + offset, &ch);
		if (!Tcl_UniCharIsWordChar(ch)) {
		    break;
		}
		if (offset + 1 > 1) {
		if (offset > 0) {
		    chSize = (segPtr->body.chars + offset
			    - Tcl_UtfPrev(segPtr->body.chars + offset,
			    segPtr->body.chars));
		}
		firstChar = 0;
	    }
	    if (offset == 0) {
            if (offset == 0) {
		if (indexPtr->byteIndex == 0) {
		    goto done;
		}
		if (modifier == TKINDEX_DISPLAY) {
		    TkTextIndexBackChars(textPtr, indexPtr, 1, indexPtr,
			    COUNT_DISPLAY_INDICES);
		} else {
		    TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr,
			    COUNT_INDICES);
		}
	    } else {
		indexPtr->byteIndex -= chSize;
	    }
	    offset -= chSize;
                if (modifier == TKINDEX_DISPLAY) {
                    TkTextIndexBackChars(textPtr, indexPtr, 1, indexPtr,
                        COUNT_DISPLAY_INDICES);
                } else {
                    TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr,
                        COUNT_INDICES);
                }
            } else {
                indexPtr->byteIndex -= chSize;
            }
            offset -= chSize;
	    if (offset < 0) {
		if (indexPtr->byteIndex == 0) {
		    goto done;
		}
		segPtr = TkTextIndexToSeg(indexPtr, &offset);
	    }
	}

	if (!firstChar) {
	    if (modifier == TKINDEX_DISPLAY) {
		TkTextIndexForwChars(textPtr, indexPtr, 1, indexPtr,

Changes to generic/tkTextMark.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


39
40
41
42
43
44
45
46
47






-
-
+
+













-
-
+
+















-
-
+
+







/*
 * tkTextMark.c --
 *
 *	This file contains the functions that implement marks for text
 *	widgets.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"
#include "tkText.h"
#include "tk3d.h"

/*
 * Macro that determines the size of a mark segment:
 */

#define MSEG_SIZE (offsetof(TkTextSegment, body) \
	+ sizeof(TkTextMark))
#define MSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \
	+ sizeof(TkTextMark)))

/*
 * Forward references for functions defined in this file:
 */

static Tcl_Obj *	GetMarkName(TkText *textPtr, TkTextSegment *segPtr);
static void		InsertUndisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr);
static int		MarkDeleteProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr, int treeGone);
static TkTextSegment *	MarkCleanupProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static void		MarkCheckProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static int		MarkLayoutProc(TkText *textPtr, TkTextIndex *indexPtr,
			    TkTextSegment *segPtr, Tcl_Size offset, int maxX,
			    Tcl_Size maxChars, int noCharsYet, TkWrapMode wrapMode,
			    TkTextSegment *segPtr, int offset, int maxX,
			    int maxChars, int noCharsYet, TkWrapMode wrapMode,
			    TkTextDispChunk *chunkPtr);
static int		MarkFindNext(Tcl_Interp *interp,
			    TkText *textPtr, Tcl_Obj *markName);
static int		MarkFindPrev(Tcl_Interp *interp,
			    TkText *textPtr, Tcl_Obj *markName);


89
90
91
92
93
94
95
96

97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

148
149
150

151
152
153
154
155
156
157
158
159
160

161
162
163
164
165

166
167
168

169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193

194
195
196
197

198
199
200
201
202
203
204
89
90
91
92
93
94
95

96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149

150
151
152
153
154
155
156
157
158
159

160
161
162
163
164

165
166
167

168
169
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192

193
194
195
196

197
198
199
200
201
202
203
204







-
+

-
+


















-
+











-
+

















-
+


-
+









-
+




-
+


-
+




-
+

















-
+

-
+



-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkTextMarkCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "mark". */
{
    Tcl_HashEntry *hPtr;
    TkTextSegment *markPtr;
    Tcl_HashSearch search;
    TkTextIndex index;
    const Tk_SegType *newTypePtr;
    int optionIndex;
    static const char *const markOptionStrings[] = {
	"gravity", "names", "next", "previous", "set", "unset", NULL
    };
    enum markOptions {
	MARK_GRAVITY, MARK_NAMES, MARK_NEXT, MARK_PREVIOUS, MARK_SET,
	MARK_UNSET
    };

    if (objc + 1 < 4) {
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[2], markOptionStrings,
	    sizeof(char *), "mark option", 0, &optionIndex) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum markOptions) optionIndex) {
    case MARK_GRAVITY: {
	char c;
	Tcl_Size length;
	int length;
	const char *str;

	if (objc < 4 || objc > 5) {
	    Tcl_WrongNumArgs(interp, 3, objv, "markName ?gravity?");
	    return TCL_ERROR;
	}
	str = Tcl_GetStringFromObj(objv[3], &length);
	if (length == 6 && !strcmp(str, "insert")) {
	    markPtr = textPtr->insertMarkPtr;
	} else if (length == 7 && !strcmp(str, "current")) {
	    markPtr = textPtr->currentMarkPtr;
	} else {
	    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, str);
	    if (hPtr == NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"there is no mark named \"%s\"", str));
		Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TEXT_MARK", str,
			(char *)NULL);
			NULL);
		return TCL_ERROR;
	    }
	    markPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	    markPtr = Tcl_GetHashValue(hPtr);
	}
	if (objc == 4) {
	    const char *typeStr;

	    if (markPtr->typePtr == &tkTextRightMarkType) {
		typeStr = "right";
	    } else {
		typeStr = "left";
	    }
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, -1));
	    return TCL_OK;
	}
	str = Tcl_GetStringFromObj(objv[4],&length);
	c = str[0];
	if ((c == 'l') && (strncmp(str, "left", length) == 0)) {
	if ((c == 'l') && (strncmp(str, "left", (unsigned) length) == 0)) {
	    newTypePtr = &tkTextLeftMarkType;
	} else if ((c == 'r') &&
		(strncmp(str, "right", length) == 0)) {
		(strncmp(str, "right", (unsigned) length) == 0)) {
	    newTypePtr = &tkTextRightMarkType;
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad mark gravity \"%s\": must be left or right", str));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "MARK_GRAVITY", (char *)NULL);
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "MARK_GRAVITY", NULL);
	    return TCL_ERROR;
	}
	TkTextMarkSegToIndex(textPtr, markPtr, &index);
	TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr);
	markPtr->typePtr = newTypePtr;
	TkBTreeLinkSegment(markPtr, &index);
	break;
    }
    case MARK_NAMES: {
	Tcl_Obj *resultObj;

	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	resultObj = Tcl_NewObj();
	Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		"insert", TCL_INDEX_NONE));
		"insert", -1));
	Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		"current", TCL_INDEX_NONE));
		"current", -1));
	for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->markTable,
		&search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    -1));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;
    }
    case MARK_NEXT:
	if (objc != 4) {
219
220
221
222
223
224
225
226

227
228
229
230
231
232

233
234
235
236
237
238
239
219
220
221
222
223
224
225

226
227
228
229
230
231

232
233
234
235
236
237
238
239







-
+





-
+







	}
	if (TkTextGetObjIndex(interp, textPtr, objv[4], &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	TkTextSetMark(textPtr, Tcl_GetString(objv[3]), &index);
	return TCL_OK;
    case MARK_UNSET: {
	Tcl_Size i;
	int i;

	for (i = 3; i < objc; i++) {
	    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable,
		    Tcl_GetString(objv[i]));
	    if (hPtr != NULL) {
		markPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
		markPtr = Tcl_GetHashValue(hPtr);

		/*
		 * Special case not needed with peer widgets.
		 */

		if ((markPtr == textPtr->insertMarkPtr)
			|| (markPtr == textPtr->currentMarkPtr)) {
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300







-
+







	widgetSpecific = 2;
	markPtr = textPtr->currentMarkPtr;
	isNew = (markPtr == NULL ? 1 : 0);
    } else {
	widgetSpecific = 0;
	hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->markTable, name,
		&isNew);
	markPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	markPtr = Tcl_GetHashValue(hPtr);
    }
    if (!isNew) {
	/*
	 * If this is the insertion point that's being moved, be sure to force
	 * a display update at the old position. Also, don't let the insertion
	 * cursor be after the final newline of the file.
	 */
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340







-
+







		TkTextIndexBackChars(NULL,indexPtr, 1, &insertIndex,
			COUNT_INDICES);
		indexPtr = &insertIndex;
	    }
	}
	TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr);
    } else {
	markPtr = (TkTextSegment *)ckalloc(MSEG_SIZE);
	markPtr = ckalloc(MSEG_SIZE);
	markPtr->typePtr = &tkTextRightMarkType;
	markPtr->size = 0;
	markPtr->body.mark.textPtr = textPtr;
	markPtr->body.mark.linePtr = indexPtr->linePtr;
	markPtr->body.mark.hPtr = hPtr;
	if (widgetSpecific == 0) {
	    Tcl_SetHashValue(hPtr, markPtr);
407
408
409
410
411
412
413
414

415
416
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436


437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

454
455
456
457
458

459
460
461
462
463




464
465
466
467












468
469
470
471
472
473
474
407
408
409
410
411
412
413

414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458


459
460
461
462
463
464
465
466
467
468




469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487







-
+


-
+



















+
+
















-
+



-
-
+





+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







 * TkTextMarkNameToIndex --
 *
 *	Given the name of a mark, return an index corresponding to the mark
 *	name.
 *
 * Results:
 *	The return value is TCL_OK if "name" exists as a mark in the text
 *	widget and is located within its -startline/-endline range. In this
 *	widget and is located within its -starline/-endline range. In this
 *	case *indexPtr is filled in with the next segment who is after the
 *	mark whose size is non-zero. TCL_ERROR is returned if the mark
 *	doesn't exist in the text widget, or if it is out of its -startline/
 *	doesn't exist in the text widget, or if it is out of its -starline/
 *	-endline range. In this latter case *indexPtr still contains valid
 *	information, in particular TkTextMarkNameToIndex called with the
 *	"insert" or "current" mark name may return TCL_ERROR, but *indexPtr
 *	contains the correct index of this mark before -startline or after
 *	-endline.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkTextMarkNameToIndex(
    TkText *textPtr,		/* Text widget containing mark. */
    const char *name,		/* Name of mark. */
    TkTextIndex *indexPtr)	/* Index information gets stored here. */
{
    TkTextSegment *segPtr;
    TkTextIndex index;
    int start, end;

    if (textPtr == NULL) {
        return TCL_ERROR;
    }

    if (!strcmp(name, "insert")) {
	segPtr = textPtr->insertMarkPtr;
    } else if (!strcmp(name, "current")) {
	segPtr = textPtr->currentMarkPtr;
    } else {
	Tcl_HashEntry *hPtr =
		Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, name);

	if (hPtr == NULL) {
	    return TCL_ERROR;
	}
	segPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	segPtr = Tcl_GetHashValue(hPtr);
    }
    TkTextMarkSegToIndex(textPtr, segPtr, indexPtr);

    /*
     * If indexPtr refers to somewhere outside the -startline/-endline
    /* If indexPtr refers to somewhere outside the -startline/-endline
     * range limits of the widget, error out since the mark indeed is not
     * reachable from this text widget (it may be reachable from a peer)
     * (bug 1630271).
     */

    if (textPtr->start != NULL) {
	start = TkBTreeLinesTo(NULL, textPtr->start);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
		&index);
    if (TkTextIndexAdjustToStartEnd(textPtr, indexPtr, 1) == TCL_ERROR) {
	return TCL_ERROR;
    }

	if (TkTextIndexCmp(indexPtr, &index) < 0) {
	    return TCL_ERROR;
	}
    }
    if (textPtr->end != NULL) {
	end = TkBTreeLinesTo(NULL, textPtr->end);
	TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, end, 0,
		&index);
	if (TkTextIndexCmp(indexPtr, &index) > 0) {
	    return TCL_ERROR;
	}
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * MarkDeleteProc --
482
483
484
485
486
487
488

489
490
491
492
493



494
495
496
497
498
499
500
495
496
497
498
499
500
501
502
503
504



505
506
507
508
509
510
511
512
513
514







+


-
-
-
+
+
+







 * Side effects:
 *	None (even if the whole tree is being deleted we don't free up the
 *	mark; it will be done elsewhere).
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
MarkDeleteProc(
    TCL_UNUSED(TkTextSegment *),	/* Segment being deleted. */
    TCL_UNUSED(TkTextLine *),	/* Line containing segment. */
    TCL_UNUSED(int))		/* Non-zero means the entire tree is being
    TkTextSegment *segPtr,	/* Segment being deleted. */
    TkTextLine *linePtr,	/* Line containing segment. */
    int treeGone)		/* Non-zero means the entire tree is being
				 * deleted, so everything must get cleaned
				 * up. */
{
    return 1;
}

/*
541
542
543
544
545
546
547
548

549
550

551
552

553
554

555
556

557
558
559


560
561
562
563
564
565
566
555
556
557
558
559
560
561

562
563

564
565

566
567

568
569

570
571


572
573
574
575
576
577
578
579
580







-
+

-
+

-
+

-
+

-
+

-
-
+
+







 *
 *--------------------------------------------------------------
 */

static int
MarkLayoutProc(
    TkText *textPtr,		/* Text widget being layed out. */
    TCL_UNUSED(TkTextIndex *),	/* Identifies first character in chunk. */
    TkTextIndex *indexPtr,	/* Identifies first character in chunk. */
    TkTextSegment *segPtr,	/* Segment corresponding to indexPtr. */
    TCL_UNUSED(Tcl_Size),		/* Offset within segPtr corresponding to
    int offset,			/* Offset within segPtr corresponding to
				 * indexPtr (always 0). */
    TCL_UNUSED(int),			/* Chunk must not occupy pixels at this
    int maxX,			/* Chunk must not occupy pixels at this
				 * position or higher. */
    TCL_UNUSED(Tcl_Size),		/* Chunk must not include more than this many
    int maxChars,		/* Chunk must not include more than this many
				 * characters. */
    TCL_UNUSED(int),		/* Non-zero means no characters have been
    int noCharsYet,		/* Non-zero means no characters have been
				 * assigned to this line yet. */
    TCL_UNUSED(TkWrapMode),	/* Not used. */
    TkTextDispChunk *chunkPtr)
    TkWrapMode wrapMode,	/* Not used. */
    register TkTextDispChunk *chunkPtr)
				/* Structure to fill in with information about
				 * this chunk. The x field has already been
				 * set by the caller. */
{
    if (segPtr != textPtr->insertMarkPtr) {
	return -1;
    }
597
598
599
600
601
602
603

604
605
606
607

608
609
610
611
612
613
614
615


616
617
618
619
620
621
622
611
612
613
614
615
616
617
618
619
620
621

622
623
624
625
626
627
628


629
630
631
632
633
634
635
636
637







+



-
+






-
-
+
+







 *
 * Side effects:
 *	Graphics are drawn.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
void
TkTextInsertDisplayProc(
    TkText *textPtr,		/* The current text widget. */
    TCL_UNUSED(TkTextDispChunk *),	/* Chunk that is to be drawn. */
    TkTextDispChunk *chunkPtr,	/* Chunk that is to be drawn. */
    int x,			/* X-position in dst at which to draw this
				 * chunk (may differ from the x-position in
				 * the chunk because of scrolling). */
    int y,			/* Y-position at which to draw this chunk in
				 * dst (x-position is in the chunk itself). */
    int height,			/* Total height of line. */
    TCL_UNUSED(int),		/* Offset of baseline from y. */
    TCL_UNUSED(Display *),		/* Display to use for drawing. */
    int baseline,		/* Offset of baseline from y. */
    Display *display,		/* Display to use for drawing. */
    Drawable dst,		/* Pixmap or window in which to draw chunk. */
    int screenY)		/* Y-coordinate in text window that
				 * corresponds to y. */
{
    /*
     * We have no need for the clientData.
     */
702
703
704
705
706
707
708

709
710
711
712


713
714
715
716
717
718
719
717
718
719
720
721
722
723
724
725
726


727
728
729
730
731
732
733
734
735







+


-
-
+
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
InsertUndisplayProc(
    TCL_UNUSED(TkText *),		/* Overall information about text widget. */
    TCL_UNUSED(TkTextDispChunk *))	/* Chunk that is about to be freed. */
    TkText *textPtr,		/* Overall information about text widget. */
    TkTextDispChunk *chunkPtr)	/* Chunk that is about to be freed. */
{
    return;
}

/*
 *--------------------------------------------------------------
 *
789
790
791
792
793
794
795
796

797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
805
806
807
808
809
810
811

812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
840







-
+




















-
+







MarkFindNext(
    Tcl_Interp *interp,		/* For error reporting */
    TkText *textPtr,		/* The widget */
    Tcl_Obj *obj)			/* The starting index or mark name */
{
    TkTextIndex index;
    Tcl_HashEntry *hPtr;
    TkTextSegment *segPtr;
    register TkTextSegment *segPtr;
    int offset;
    const char *string = Tcl_GetString(obj);

    if (!strcmp(string, "insert")) {
	segPtr = textPtr->insertMarkPtr;
	TkTextMarkSegToIndex(textPtr, segPtr, &index);
	segPtr = segPtr->nextPtr;
    } else if (!strcmp(string, "current")) {
	segPtr = textPtr->currentMarkPtr;
	TkTextMarkSegToIndex(textPtr, segPtr, &index);
	segPtr = segPtr->nextPtr;
    } else {
	hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, string);
	if (hPtr != NULL) {
	    /*
	     * If given a mark name, return the next mark in the list of
	     * segments, even if it happens to be at the same character
	     * position.
	     */

	    segPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	    segPtr = Tcl_GetHashValue(hPtr);
	    TkTextMarkSegToIndex(textPtr, segPtr, &index);
	    segPtr = segPtr->nextPtr;
	} else {
	    /*
	     * For non-mark name indices we want to return any marks that are
	     * right at the index.
	     */
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906

907
908
909
910
911
912
913
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922
923
924
925
926
927
928
929







-
+


















-
+







MarkFindPrev(
    Tcl_Interp *interp,		/* For error reporting */
    TkText *textPtr,		/* The widget */
    Tcl_Obj *obj)			/* The starting index or mark name */
{
    TkTextIndex index;
    Tcl_HashEntry *hPtr;
    TkTextSegment *segPtr, *seg2Ptr, *prevPtr;
    register TkTextSegment *segPtr, *seg2Ptr, *prevPtr;
    int offset;
    const char *string = Tcl_GetString(obj);

    if (!strcmp(string, "insert")) {
	segPtr = textPtr->insertMarkPtr;
	TkTextMarkSegToIndex(textPtr, segPtr, &index);
    } else if (!strcmp(string, "current")) {
	segPtr = textPtr->currentMarkPtr;
	TkTextMarkSegToIndex(textPtr, segPtr, &index);
    } else {
	hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, string);
	if (hPtr != NULL) {
	    /*
	     * If given a mark name, return the previous mark in the list of
	     * segments, even if it happens to be at the same character
	     * position.
	     */

	    segPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
	    segPtr = Tcl_GetHashValue(hPtr);
	    TkTextMarkSegToIndex(textPtr, segPtr, &index);
	} else {
	    /*
	     * For non-mark name indices we do not return any marks that are
	     * right at the index.
	     */

992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027







-
+












	 * current marks for textPtr having already been tested above, the
	 * current segment is an insert or current mark from a peer of
	 * textPtr, which we don't want to return.
	 */

	return NULL;
    } else {
	markName = (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable,
	markName = Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable,
		segPtr->body.mark.hPtr);
    }
    return Tcl_NewStringObj(markName, -1);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkTextTag.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17



18






















19
20
21

22
23

24
25
26
27
28
29





30
31

32
33

34
35
36
37
38
39
40
41







42
43
44
45
46
47





48
49
50
51
52
53
54
55






56
57

58
59

60
61
62
63
64
65
66
67







68
69

70
71
72
73
74




75
76
77
78


79
80
81


82
83
84
85
86
87
88
1
2
3
4
5
6
7


8
9
10
11
12
13
14



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44

45
46





47
48
49
50
51
52

53
54

55
56







57
58
59
60
61
62
63
64





65
66
67
68
69
70
71






72
73
74
75
76
77
78

79
80

81
82







83
84
85
86
87
88
89
90

91
92




93
94
95
96
97
98


99
100
101


102
103
104
105
106
107
108
109
110







-
-
+
+





-
-
-
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+

-
+

-
-
-
-
-
+
+
+
+
+

-
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+

-
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+

-
-
-
-
+
+
+
+


-
-
+
+

-
-
+
+







/*
 * tkTextTag.c --
 *
 *	This module implements the "tag" subcommand of the widget command for
 *	text widgets, plus most of the other high-level functions related to
 *	tags.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkText.h"
#include "default.h"
#include "default.h"
#include "tkInt.h"
#include "tkText.h"

/*
 * The 'TkWrapMode' enum in tkText.h is used to define a type for the -wrap
 * option of tags in a Text widget. These values are used as indices into the
 * string table below. Tags are allowed an empty wrap value, but the widget as
 * a whole is not.
 */

static const char *const wrapStrings[] = {
    "char", "none", "word", "", NULL
};

/*
 * The 'TkTextTabStyle' enum in tkText.h is used to define a type for the
 * -tabstyle option of the Text widget. These values are used as indices into
 * the string table below. Tags are allowed an empty tabstyle value, but the
 * widget as a whole is not.
 */

static const char *const tabStyleStrings[] = {
    "tabular", "wordprocessor", "", NULL
};

static const Tk_OptionSpec tagOptionSpecs[] = {
    {TK_OPTION_BORDER, "-background", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, border), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, border), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BITMAP, "-bgstipple", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, bgStipple), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, bgStipple), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-borderwidth", NULL, NULL,
	NULL, offsetof(TkTextTag, borderWidthPtr), offsetof(TkTextTag, borderWidth),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-elide", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, elide),
	TK_OPTION_NULL_OK, 0, 0},
	NULL, Tk_Offset(TkTextTag, borderWidthPtr), Tk_Offset(TkTextTag, borderWidth),
	TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, 0, 0},
    {TK_OPTION_STRING, "-elide", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, elideString),
	TK_OPTION_NULL_OK|TK_OPTION_DONT_SET_DEFAULT, 0, 0},
    {TK_OPTION_BITMAP, "-fgstipple", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, fgStipple), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, fgStipple), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_FONT, "-font", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, tkfont), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, tkfont), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-foreground", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, fgColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, justify), TK_OPTION_NULL_OK, 0,0},
    {TK_OPTION_PIXELS, "-lmargin1", NULL, NULL,
	NULL, offsetof(TkTextTag, lMargin1Obj), offsetof(TkTextTag, lMargin1), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_PIXELS, "-lmargin2", NULL, NULL,
	NULL, offsetof(TkTextTag, lMargin2Obj), offsetof(TkTextTag, lMargin2), TK_OPTION_NULL_OK,0,0},
	NULL, -1, Tk_Offset(TkTextTag, fgColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-justify", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, justifyString), TK_OPTION_NULL_OK, 0,0},
    {TK_OPTION_STRING, "-lmargin1", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, lMargin1String), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-lmargin2", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, lMargin2String), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_BORDER, "-lmargincolor", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, lMarginColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-offset", NULL, NULL,
	NULL, offsetof(TkTextTag, offsetObj), offsetof(TkTextTag, offset), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BOOLEAN, "-overstrike", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, overstrike),
	NULL, -1, Tk_Offset(TkTextTag, lMarginColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-offset", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, offsetString), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-overstrike", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, overstrikeString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-overstrikefg", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, overstrikeColor),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_RELIEF, "-relief", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, relief), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-rmargin", NULL, NULL,
	NULL, offsetof(TkTextTag, rMarginObj), offsetof(TkTextTag, rMargin), TK_OPTION_NULL_OK, 0,0},
	NULL, -1, Tk_Offset(TkTextTag, overstrikeColor),
        TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-relief", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, reliefString), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-rmargin", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, rMarginString), TK_OPTION_NULL_OK, 0,0},
    {TK_OPTION_BORDER, "-rmargincolor", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, rMarginColor), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, rMarginColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_BORDER, "-selectbackground", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, selBorder), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, selBorder), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-selectforeground", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, selFgColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-spacing1", NULL, NULL,
	NULL, offsetof(TkTextTag, spacing1Obj), offsetof(TkTextTag, spacing1), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_PIXELS, "-spacing2", NULL, NULL,
	NULL, offsetof(TkTextTag, spacing2Obj), offsetof(TkTextTag, spacing2), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_PIXELS, "-spacing3", NULL, NULL,
	NULL, offsetof(TkTextTag, spacing3Obj), offsetof(TkTextTag, spacing3), TK_OPTION_NULL_OK,0,0},
	NULL, -1, Tk_Offset(TkTextTag, selFgColor), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-spacing1", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, spacing1String), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-spacing2", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, spacing2String), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-spacing3", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, spacing3String), TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-tabs", NULL, NULL,
	NULL, offsetof(TkTextTag, tabStringPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
	NULL, Tk_Offset(TkTextTag, tabStringPtr), -1, TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-tabstyle", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, tabStyle),
	TK_OPTION_NULL_OK|TK_OPTION_ENUM_VAR, tkTextTabStyleStrings, 0},
    {TK_OPTION_BOOLEAN, "-underline", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, underline),
	NULL, -1, Tk_Offset(TkTextTag, tabStyle),
	TK_OPTION_NULL_OK, tabStyleStrings, 0},
    {TK_OPTION_STRING, "-underline", NULL, NULL,
	NULL, -1, Tk_Offset(TkTextTag, underlineString),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_COLOR, "-underlinefg", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, underlineColor),
	TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextTag, underlineColor),
        TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING_TABLE, "-wrap", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextTag, wrapMode),
	TK_OPTION_NULL_OK|TK_OPTION_ENUM_VAR, tkTextWrapStrings, 0},
	NULL, -1, Tk_Offset(TkTextTag, wrapMode),
	TK_OPTION_NULL_OK, wrapStrings, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 * Forward declarations for functions defined later in this file:
 */

111
112
113
114
115
116
117
118

119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136

137
138
139
140
141
142
143
133
134
135
136
137
138
139

140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155

156


157
158
159
160
161
162
163
164







-
+

-
+













-
+
-
-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkTextTagCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "tag". */
{
    static const char *const tagOptionStrings[] = {
	"add", "bind", "cget", "configure", "delete", "lower", "names",
	"nextrange", "prevrange", "raise", "ranges", "remove", NULL
    };
    enum tagOptions {
	TAG_ADD, TAG_BIND, TAG_CGET, TAG_CONFIGURE, TAG_DELETE, TAG_LOWER,
	TAG_NAMES, TAG_NEXTRANGE, TAG_PREVRANGE, TAG_RAISE, TAG_RANGES,
	TAG_REMOVE
    };
    int optionIndex;
    int optionIndex, i;
    Tcl_Size i;
    TkTextTag *tagPtr;
    register TkTextTag *tagPtr;
    TkTextIndex index1, index2;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
	return TCL_ERROR;
    }

158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173

174
175
176
177
178

179
180
181
182
183
184
185
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193

194
195
196
197
198

199
200
201
202
203
204
205
206







-
+







-
+




-
+







	}
	if (objc < 5) {
	    Tcl_WrongNumArgs(interp, 3, objv,
		    "tagName index1 ?index2 index1 index2 ...?");
	    return TCL_ERROR;
	}
	tagPtr = TkTextCreateTag(textPtr, Tcl_GetString(objv[3]), NULL);
	if (tagPtr->elide > 0) {
	if (tagPtr->elide) {
		/*
		* Indices are potentially obsolete after adding or removing
		* elided character ranges, especially indices having "display"
		* or "any" submodifier, therefore increase the epoch.
		*/
		textPtr->sharedTextPtr->stateEpoch++;
	}
	for (i = 4; i < (Tcl_Size)objc; i += 2) {
	for (i = 4; i < objc; i += 2) {
	    if (TkTextGetObjIndex(interp, textPtr, objv[i],
		    &index1) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if ((Tcl_Size)objc > (i+1)) {
	    if (objc > (i+1)) {
		if (TkTextGetObjIndex(interp, textPtr, objv[i+1],
			&index2) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (TkTextIndexCmp(&index1, &index2) >= 0) {
		    return TCL_OK;
		}
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
239
240
241
242
243
244
245

246
247
248
249
250
251
252







-







		     * equivalent to:
		     *	   event generate $textWidget <<Selection>>
		     */

		    TkTextSelectionEvent(textPtr);

		    if (addTag && textPtr->exportSelection
			    && (!Tcl_IsSafe(textPtr->interp))
			    && !(textPtr->flags & GOT_SELECTION)) {
			Tk_OwnSelection(textPtr->tkwin, XA_PRIMARY,
				TkTextLostSelection, textPtr);
			textPtr->flags |= GOT_SELECTION;
		    }
		    textPtr->abortSelections = 1;
		}
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269

270
271
272
273
274

275
276
277
278
279
280

281
282
283

284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341
342
343
344

345
346
347
348
349
350
351
352
353


354

355
356
357
358
359
360
361
362
363
364
365
366
367
368










































369





370
371
372
373
374





375
376
377
378
379





380
381
382
383
384
385
386
387
388
389
390

391
392
393
394






395






396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418





419
420
421
422
423
424
425





426
427
428
429
430
431
432
433
434
435
436
437
438
439










440
441

442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457
458
459






460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288

289
290
291
292
293

294
295
296
297
298
299

300
301
302

303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

327
328
329
330

331
332
333
334
335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354
355
356
357
358

359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500





501
502
503
504
505
506
507





508
509
510
511
512
513
514
515
516










517
518
519
520
521
522
523
524
525
526
527

528

529
530
531
532
533
534

535
536
537
538
539






540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+







-
+




-
+





-
+


-
+








-
+














-
+



-
+













-
+













-
+




-
+









+
+
-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+




-
+
+
+
+
+




-
+
+
+
+
+










-
+




+
+
+
+
+
+
-
+
+
+
+
+
+


















-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+




-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+
-






-
+




-
-
-
-
-
-
+
+
+
+
+
+

















-
+










-
+











-
+







	    int append = 0;
	    unsigned long mask;
	    const char *fifth = Tcl_GetString(objv[5]);

	    if (fifth[0] == 0) {
		return Tk_DeleteBinding(interp,
			textPtr->sharedTextPtr->bindingTable,
			(void *) tagPtr->name, Tcl_GetString(objv[4]));
			(ClientData) tagPtr->name, Tcl_GetString(objv[4]));
	    }
	    if (fifth[0] == '+') {
		fifth++;
		append = 1;
	    }
	    mask = Tk_CreateBinding(interp,
		    textPtr->sharedTextPtr->bindingTable,
		    (void *) tagPtr->name, Tcl_GetString(objv[4]), fifth,
		    (ClientData) tagPtr->name, Tcl_GetString(objv[4]), fifth,
		    append);
	    if (mask == 0) {
		return TCL_ERROR;
	    }
	    if (mask & ~(unsigned long)(ButtonMotionMask|Button1MotionMask
	    if (mask & (unsigned) ~(ButtonMotionMask|Button1MotionMask
		    |Button2MotionMask|Button3MotionMask|Button4MotionMask
		    |Button5MotionMask|ButtonPressMask|ButtonReleaseMask
		    |EnterWindowMask|LeaveWindowMask|KeyPressMask
		    |KeyReleaseMask|PointerMotionMask|VirtualEventMask)) {
		Tk_DeleteBinding(interp, textPtr->sharedTextPtr->bindingTable,
			(void *) tagPtr->name, Tcl_GetString(objv[4]));
			(ClientData) tagPtr->name, Tcl_GetString(objv[4]));
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"requested illegal events; only key, button, motion,"
			" enter, leave, and virtual events may be used", TCL_INDEX_NONE));
			" enter, leave, and virtual events may be used", -1));
		Tcl_SetErrorCode(interp, "TK", "TEXT", "TAG_BIND_EVENT",NULL);
		return TCL_ERROR;
	    }
	} else if (objc == 5) {
	    const char *command;

	    command = Tk_GetBinding(interp,
		    textPtr->sharedTextPtr->bindingTable,
		    (void *) tagPtr->name, Tcl_GetString(objv[4]));
		    (ClientData) tagPtr->name, Tcl_GetString(objv[4]));
	    if (command == NULL) {
		const char *string = Tcl_GetString(Tcl_GetObjResult(interp));

		/*
		 * Ignore missing binding errors. This is a special hack that
		 * relies on the error message returned by FindSequence in
		 * tkBind.c.
		 */

		if (string[0] != '\0') {
		    return TCL_ERROR;
		}
		Tcl_ResetResult(interp);
	    } else {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(command, TCL_INDEX_NONE));
		Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
	    }
	} else {
	    Tk_GetAllBindings(interp, textPtr->sharedTextPtr->bindingTable,
		    (void *) tagPtr->name);
		    (ClientData) tagPtr->name);
	}
	break;
    case TAG_CGET:
	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 1, objv, "tag cget tagName option");
	    return TCL_ERROR;
	} else {
	    Tcl_Obj *objPtr;

	    tagPtr = FindTag(interp, textPtr, objv[3]);
	    if (tagPtr == NULL) {
		return TCL_ERROR;
	    }
	    objPtr = Tk_GetOptionValue(interp, tagPtr,
	    objPtr = Tk_GetOptionValue(interp, (char *) tagPtr,
		    tagPtr->optionTable, objv[4], textPtr->tkwin);
	    if (objPtr == NULL) {
		return TCL_ERROR;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    return TCL_OK;
	}
	break;
    case TAG_CONFIGURE: {
	int newTag;

	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 3, objv,
		    "tagName ?-option value ...?");
		    "tagName ?-option? ?value? ?-option value ...?");
	    return TCL_ERROR;
	}
	tagPtr = TkTextCreateTag(textPtr, Tcl_GetString(objv[3]), &newTag);
	if (objc <= 5) {
	    Tcl_Obj *objPtr = Tk_GetOptionInfo(interp, tagPtr,
	    Tcl_Obj *objPtr = Tk_GetOptionInfo(interp, (char *) tagPtr,
		    tagPtr->optionTable,
		    (objc == 5) ? objv[4] : NULL, textPtr->tkwin);

	    if (objPtr == NULL) {
		return TCL_ERROR;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    return TCL_OK;
	} else {
	    int result = TCL_OK;

	    if (Tk_SetOptions(interp, tagPtr, tagPtr->optionTable,
	    if (Tk_SetOptions(interp, (char *) tagPtr, tagPtr->optionTable,
		    objc-4, objv+4, textPtr->tkwin, NULL, NULL) != TCL_OK) {
		return TCL_ERROR;
	    }

	    /*
	     * Some of the configuration options, like -underline and
	     * -justify, require additional translation (this is needed
	     * because we need to distinguish a particular value of an option
	     * from "unspecified").
	     */

	    if (tagPtr->borderWidth < 0) {
		tagPtr->borderWidth = 0;
	    }
	    if (tagPtr->reliefString != NULL) {
		if (Tk_GetRelief(interp, tagPtr->reliefString,
			&tagPtr->relief) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->justifyString != NULL) {
		if (Tk_GetJustify(interp, tagPtr->justifyString,
			&tagPtr->justify) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->lMargin1String != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->lMargin1String, &tagPtr->lMargin1) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->lMargin2String != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->lMargin2String, &tagPtr->lMargin2) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->offsetString != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin, tagPtr->offsetString,
			&tagPtr->offset) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->overstrikeString != NULL) {
		if (Tcl_GetBoolean(interp, tagPtr->overstrikeString,
			&tagPtr->overstrike) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->rMarginString != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->rMarginString, &tagPtr->rMargin) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->spacing1 != INT_MIN) {
	    if (tagPtr->spacing1String != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->spacing1String, &tagPtr->spacing1) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (tagPtr->spacing1 < 0) {
		    tagPtr->spacing1 = 0;
		}
	    }
	    if (tagPtr->spacing2 != INT_MIN) {
	    if (tagPtr->spacing2String != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->spacing2String, &tagPtr->spacing2) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (tagPtr->spacing2 < 0) {
		    tagPtr->spacing2 = 0;
		}
	    }
	    if (tagPtr->spacing3 != INT_MIN) {
	    if (tagPtr->spacing3String != NULL) {
		if (Tk_GetPixels(interp, textPtr->tkwin,
			tagPtr->spacing3String, &tagPtr->spacing3) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (tagPtr->spacing3 < 0) {
		    tagPtr->spacing3 = 0;
		}
	    }
	    if (tagPtr->tabArrayPtr != NULL) {
		ckfree(tagPtr->tabArrayPtr);
		tagPtr->tabArrayPtr = NULL;
	    }
	    if (tagPtr->tabStringPtr != NULL) {
		tagPtr->tabArrayPtr =
			TkTextGetTabs(interp, textPtr->tkwin, tagPtr->tabStringPtr);
			TkTextGetTabs(interp, textPtr, tagPtr->tabStringPtr);
		if (tagPtr->tabArrayPtr == NULL) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->underlineString != NULL) {
		if (Tcl_GetBoolean(interp, tagPtr->underlineString,
			&tagPtr->underline) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	    if (tagPtr->elide >= 0) {
	    if (tagPtr->elideString != NULL) {
		if (Tcl_GetBoolean(interp, tagPtr->elideString,
			&tagPtr->elide) != TCL_OK) {
		    return TCL_ERROR;
		}

		/*
		 * Indices are potentially obsolete after changing -elide,
		 * especially those computed with "display" or "any"
		 * submodifier, therefore increase the epoch.
		 */

		textPtr->sharedTextPtr->stateEpoch++;
	    }

	    /*
	     * If the "sel" tag was changed, be sure to mirror information
	     * from the tag back into the text widget record. NOTE: we don't
	     * have to free up information in the widget record before
	     * overwriting it, because it was mirrored in the tag and hence
	     * freed when the tag field was overwritten.
	     */

	    if (tagPtr == textPtr->selTagPtr) {
		if (tagPtr->selBorder == NULL) {
		    textPtr->selBorder = tagPtr->border;
		} else {
		    textPtr->selBorder = tagPtr->selBorder;
		}
                if (tagPtr->selBorder == NULL) {
                    textPtr->selBorder = tagPtr->border;
                } else {
                    textPtr->selBorder = tagPtr->selBorder;
                }
		textPtr->selBorderWidth = tagPtr->borderWidth;
		textPtr->selBorderWidthPtr = tagPtr->borderWidthPtr;
		if (tagPtr->selFgColor == NULL) {
		    textPtr->selFgColorPtr = tagPtr->fgColor;
		} else {
		    textPtr->selFgColorPtr = tagPtr->selFgColor;
		}
                if (tagPtr->selFgColor == NULL) {
                    textPtr->selFgColorPtr = tagPtr->fgColor;
                } else {
                    textPtr->selFgColorPtr = tagPtr->selFgColor;
                }
	    }

	    tagPtr->affectsDisplay = 0;
	    tagPtr->affectsDisplayGeometry = 0;
	    if ((tagPtr->elide >= 0)
		    || (tagPtr->tkfont != NULL)
		    || (tagPtr->justify != TK_JUSTIFY_NULL)
		    || (tagPtr->lMargin1 != INT_MIN)
		    || (tagPtr->lMargin2 != INT_MIN)
		    || (tagPtr->offset != INT_MIN)
		    || (tagPtr->rMargin != INT_MIN)
		    || (tagPtr->spacing1 != INT_MIN)
		    || (tagPtr->spacing2 != INT_MIN)
		    || (tagPtr->spacing3 != INT_MIN)
	    if ((tagPtr->elideString != NULL)
		    || (tagPtr->tkfont != None)
		    || (tagPtr->justifyString != NULL)
		    || (tagPtr->lMargin1String != NULL)
		    || (tagPtr->lMargin2String != NULL)
		    || (tagPtr->offsetString != NULL)
		    || (tagPtr->rMarginString != NULL)
		    || (tagPtr->spacing1String != NULL)
		    || (tagPtr->spacing2String != NULL)
		    || (tagPtr->spacing3String != NULL)
		    || (tagPtr->tabStringPtr != NULL)
		    || (tagPtr->tabStyle == TK_TEXT_TABSTYLE_TABULAR)
		    || (tagPtr->tabStyle != TK_TEXT_TABSTYLE_NONE)
		    || (tagPtr->tabStyle == TK_TEXT_TABSTYLE_WORDPROCESSOR)
		    || (tagPtr->wrapMode != TEXT_WRAPMODE_NULL)) {
		tagPtr->affectsDisplay = 1;
		tagPtr->affectsDisplayGeometry = 1;
	    }
	    if ((tagPtr->border != NULL)
		    || (tagPtr->selBorder != NULL)
		    || (tagPtr->relief != TK_RELIEF_NULL)
		    || (tagPtr->reliefString != NULL)
		    || (tagPtr->bgStipple != None)
		    || (tagPtr->fgColor != NULL)
		    || (tagPtr->selFgColor != NULL)
		    || (tagPtr->fgStipple != None)
		    || (tagPtr->overstrike >= 0)
		    || (tagPtr->overstrikeColor != NULL)
		    || (tagPtr->underline >= 0)
		    || (tagPtr->underlineColor != NULL)
		    || (tagPtr->lMarginColor != NULL)
		    || (tagPtr->rMarginColor != NULL)) {
		    || (tagPtr->overstrikeString != NULL)
                    || (tagPtr->overstrikeColor != NULL)
		    || (tagPtr->underlineString != NULL)
                    || (tagPtr->underlineColor != NULL)
                    || (tagPtr->lMarginColor != NULL)
                    || (tagPtr->rMarginColor != NULL)) {
		tagPtr->affectsDisplay = 1;
	    }
	    if (!newTag) {
		/*
		 * This line is not necessary if this is a new tag, since it
		 * can't possibly have been applied to anything yet.
		 */

		/*
		 * VMD: If this is the 'sel' tag, then we don't need to call
		 * this for all peers, unless we actually want to synchronize
		 * sel-style changes across the peers.
		 */

		TkTextRedrawTag(textPtr->sharedTextPtr, NULL,
			NULL, NULL, tagPtr, 1);
	    }
	    return TCL_OK;
	    return result;
	}
	break;
    }
    case TAG_DELETE: {
	Tcl_HashEntry *hPtr;

	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 3, objv, "tagName ?tagName ...?");
	    return TCL_ERROR;
	}
	for (i = 3; i < (Tcl_Size)objc; i++) {
	for (i = 3; i < objc; i++) {
	    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->tagTable,
		    Tcl_GetString(objv[i]));
	    if (hPtr == NULL) {
		/*
		 * Either this tag doesn't exist or it's the 'sel' tag (which
		 * is not in the hash table). Either way we don't want to
		 * delete it.
		 */

		continue;
	    }
	    tagPtr = (TkTextTag *)Tcl_GetHashValue(hPtr);
	    tagPtr = Tcl_GetHashValue(hPtr);
	    if (tagPtr == textPtr->selTagPtr) {
		continue;
	    }
	    if (tagPtr->affectsDisplay) {
		TkTextRedrawTag(textPtr->sharedTextPtr, NULL,
			NULL, NULL, tagPtr, 1);
	    }
543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
558
559
560
561

562
563
564
565
566

567
568
569
570
571
572
573
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651

652
653
654
655
656
657
658
659







-
+










-
+




-
+







	 */

	TkTextRedrawTag(textPtr->sharedTextPtr, NULL, NULL, NULL, tagPtr, 1);
	break;
    }
    case TAG_NAMES: {
	TkTextTag **arrayPtr;
	Tcl_Size arraySize;
	int arraySize;
	Tcl_Obj *listObj;

	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 3, objv, "?index?");
	    return TCL_ERROR;
	}
	if (objc == 3) {
	    Tcl_HashSearch search;
	    Tcl_HashEntry *hPtr;

	    arrayPtr = (TkTextTag **)ckalloc(textPtr->sharedTextPtr->numTags
	    arrayPtr = ckalloc(textPtr->sharedTextPtr->numTags
		    * sizeof(TkTextTag *));
	    for (i=0, hPtr = Tcl_FirstHashEntry(
		    &textPtr->sharedTextPtr->tagTable, &search);
		    hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) {
		arrayPtr[i] = (TkTextTag *)Tcl_GetHashValue(hPtr);
		arrayPtr[i] = Tcl_GetHashValue(hPtr);
	    }

	    /*
	     * The 'sel' tag is not in the hash table.
	     */

	    arrayPtr[i] = textPtr->selTagPtr;
667
668
669
670
671
672
673
674

675
676
677
678

679
680
681
682
683
684
685
753
754
755
756
757
758
759

760
761
762
763

764
765
766
767
768
769
770
771







-
+



-
+







    gotStart:
	if (TkTextIndexCmp(&tSearch.curIndex, &index2) >= 0) {
	    return TCL_OK;
	}
	resultObj = Tcl_NewObj();
	TkTextPrintIndex(textPtr, &tSearch.curIndex, position);
	Tcl_ListObjAppendElement(NULL, resultObj,
		Tcl_NewStringObj(position, TCL_INDEX_NONE));
		Tcl_NewStringObj(position, -1));
	TkBTreeNextTag(&tSearch);
	TkTextPrintIndex(textPtr, &tSearch.curIndex, position);
	Tcl_ListObjAppendElement(NULL, resultObj,
		Tcl_NewStringObj(position, TCL_INDEX_NONE));
		Tcl_NewStringObj(position, -1));
	Tcl_SetObjResult(interp, resultObj);
	break;
    }
    case TAG_PREVRANGE: {
	TkTextIndex last;
	TkTextSearch tSearch;
	char position1[TK_POS_CHARS];
782
783
784
785
786
787
788
789

790
791

792
793
794
795
796
797
798
868
869
870
871
872
873
874

875
876

877
878
879
880
881
882
883
884







-
+

-
+







		}
	    }
	}

    gotPrevIndexPair:
	resultObj = Tcl_NewObj();
	Tcl_ListObjAppendElement(NULL, resultObj,
		Tcl_NewStringObj(position1, TCL_INDEX_NONE));
		Tcl_NewStringObj(position1, -1));
	Tcl_ListObjAppendElement(NULL, resultObj,
		Tcl_NewStringObj(position2, TCL_INDEX_NONE));
		Tcl_NewStringObj(position2, -1));
	Tcl_SetObjResult(interp, resultObj);
	break;
    }
    case TAG_RAISE: {
	TkTextTag *tagPtr2;
	int prio;

895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
981
982
983
984
985
986
987

988
989
990
991
992
993
994
995







-
+







TkTextTag *
TkTextCreateTag(
    TkText *textPtr,		/* Widget in which tag is being used. */
    const char *tagName,	/* Name of desired tag. */
    int *newTag)		/* If non-NULL, then return 1 if new, or 0 if
				 * already exists. */
{
    TkTextTag *tagPtr;
    register TkTextTag *tagPtr;
    Tcl_HashEntry *hPtr = NULL;
    int isNew;
    const char *name;

    if (!strcmp(tagName, "sel")) {
	if (textPtr->selTagPtr != NULL) {
	    if (newTag != NULL) {
918
919
920
921
922
923
924
925

926
927

928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943

944

945
946
947
948

949
950
951
952
953





954
955
956
957




958
959
960


961
962
963
964
965
966
967
968
969






970
971
972
973



974

975

976
977
978
979
980
981
982
1004
1005
1006
1007
1008
1009
1010

1011
1012

1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036





1037
1038
1039
1040
1041
1042



1043
1044
1045
1046
1047


1048
1049
1050
1051
1052






1053
1054
1055
1056
1057
1058
1059
1060


1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073







-
+

-
+







-
+








+
-
+




+
-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+
+

-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+


-
-
+
+
+

+
-
+







    } else {
	hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->tagTable,
		tagName, &isNew);
	if (newTag != NULL) {
	    *newTag = isNew;
	}
	if (!isNew) {
	    return (TkTextTag *)Tcl_GetHashValue(hPtr);
	    return Tcl_GetHashValue(hPtr);
	}
	name = (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->tagTable, hPtr);
	name = Tcl_GetHashKey(&textPtr->sharedTextPtr->tagTable, hPtr);
    }

    /*
     * No existing entry. Create a new one, initialize it, and add a pointer
     * to it to the hash table entry.
     */

    tagPtr = (TkTextTag *)ckalloc(sizeof(TkTextTag));
    tagPtr = ckalloc(sizeof(TkTextTag));
    tagPtr->name = name;
    tagPtr->textPtr = NULL;
    tagPtr->toggleCount = 0;
    tagPtr->tagRootPtr = NULL;
    tagPtr->priority = textPtr->sharedTextPtr->numTags;
    tagPtr->border = NULL;
    tagPtr->borderWidth = 0;
    tagPtr->borderWidthPtr = NULL;
    tagPtr->reliefString = NULL;
    tagPtr->relief = TK_RELIEF_NULL;
    tagPtr->relief = TK_RELIEF_FLAT;
    tagPtr->bgStipple = None;
    tagPtr->fgColor = NULL;
    tagPtr->tkfont = NULL;
    tagPtr->fgStipple = None;
    tagPtr->justifyString = NULL;
    tagPtr->justify = TK_JUSTIFY_NULL;
    tagPtr->lMargin1Obj = NULL;
    tagPtr->lMargin1 = INT_MIN;
    tagPtr->lMargin2Obj = NULL;
    tagPtr->lMargin2 = INT_MIN;
    tagPtr->justify = TK_JUSTIFY_LEFT;
    tagPtr->lMargin1String = NULL;
    tagPtr->lMargin1 = 0;
    tagPtr->lMargin2String = NULL;
    tagPtr->lMargin2 = 0;
    tagPtr->lMarginColor = NULL;
    tagPtr->offsetObj = NULL;
    tagPtr->offset = INT_MIN;
    tagPtr->overstrike = -1;
    tagPtr->offsetString = NULL;
    tagPtr->offset = 0;
    tagPtr->overstrikeString = NULL;
    tagPtr->overstrike = 0;
    tagPtr->overstrikeColor = NULL;
    tagPtr->rMarginObj = NULL;
    tagPtr->rMargin = INT_MIN;
    tagPtr->rMarginString = NULL;
    tagPtr->rMargin = 0;
    tagPtr->rMarginColor = NULL;
    tagPtr->selBorder = NULL;
    tagPtr->selFgColor = NULL;
    tagPtr->spacing1Obj = NULL;
    tagPtr->spacing1 = INT_MIN;
    tagPtr->spacing2Obj = NULL;
    tagPtr->spacing2 = INT_MIN;
    tagPtr->spacing3Obj = NULL;
    tagPtr->spacing3 = INT_MIN;
    tagPtr->spacing1String = NULL;
    tagPtr->spacing1 = 0;
    tagPtr->spacing2String = NULL;
    tagPtr->spacing2 = 0;
    tagPtr->spacing3String = NULL;
    tagPtr->spacing3 = 0;
    tagPtr->tabStringPtr = NULL;
    tagPtr->tabArrayPtr = NULL;
    tagPtr->tabStyle = TK_TEXT_TABSTYLE_NULL;
    tagPtr->underline = -1;
    tagPtr->tabStyle = TK_TEXT_TABSTYLE_NONE;
    tagPtr->underlineString = NULL;
    tagPtr->underline = 0;
    tagPtr->underlineColor = NULL;
    tagPtr->elideString = NULL;
    tagPtr->elide = -1;
    tagPtr->elide = 0;
    tagPtr->wrapMode = TEXT_WRAPMODE_NULL;
    tagPtr->affectsDisplay = 0;
    tagPtr->affectsDisplayGeometry = 0;
    textPtr->sharedTextPtr->numTags++;
    if (!strcmp(tagName, "sel")) {
	tagPtr->textPtr = textPtr;
	textPtr->refCount++;
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119

1120
1121
1122
1123
1124
1125
1126
1127







-
+









-
+







    Tcl_Interp *interp,		/* Interpreter to use for error message; if
				 * NULL, then don't record an error
				 * message. */
    TkText *textPtr,		/* Widget in which tag is being used. */
    Tcl_Obj *tagName)		/* Name of desired tag. */
{
    Tcl_HashEntry *hPtr;
    Tcl_Size len;
    int len;
    const char *str;

    str = Tcl_GetStringFromObj(tagName, &len);
    if (len == 3 && !strcmp(str, "sel")) {
	return textPtr->selTagPtr;
    }
    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->tagTable,
	    Tcl_GetString(tagName));
    if (hPtr != NULL) {
	return (TkTextTag *)Tcl_GetHashValue(hPtr);
	return Tcl_GetHashValue(hPtr);
    }
    if (interp != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"tag \"%s\" isn't defined in text widget",
		Tcl_GetString(tagName)));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TEXT_TAG",
		Tcl_GetString(tagName), NULL);
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167







-
+







 *
 *----------------------------------------------------------------------
 */

void
TkTextDeleteTag(
    TkText *textPtr,		/* Info about overall widget. */
    TkTextTag *tagPtr)	/* Tag being deleted. */
    register TkTextTag *tagPtr)	/* Tag being deleted. */
{
    TkTextIndex first, last;

    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, 0, 0, &first);
    TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr,
	    TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr), 0, &last),
    TkBTreeTag(&first, &last, tagPtr, 0);
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190
1191
1192







-
+







	 * Since all peer widgets have an independent "sel" tag, we
	 * don't want removal of one sel tag to remove bindings which
	 * are still valid in other peer widgets.
	 */

	if (textPtr->sharedTextPtr->bindingTable != NULL) {
	    Tk_DeleteAllBindings(textPtr->sharedTextPtr->bindingTable,
		    (void *) tagPtr->name);
		    (ClientData) tagPtr->name);
	}
    }

    /*
     * Update the tag priorities to reflect the deletion of this tag.
     */

1120
1121
1122
1123
1124
1125
1126
1127

1128
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233







-
+







-
+







 *
 *----------------------------------------------------------------------
 */

void
TkTextFreeTag(
    TkText *textPtr,		/* Info about overall widget. */
    TkTextTag *tagPtr)	/* Tag being deleted. */
    register TkTextTag *tagPtr)	/* Tag being deleted. */
{
    int i;

    /*
     * Let Tk do most of the hard work for us.
     */

    Tk_FreeConfigOptions(tagPtr, tagPtr->optionTable,
    Tk_FreeConfigOptions((char *) tagPtr, tagPtr->optionTable,
	    textPtr->tkwin);

    /*
     * This associated information is managed by us.
     */

    if (tagPtr->tabArrayPtr != NULL) {
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1290
1291
1292
1293
1294
1295
1296

1297
1298
1299
1300
1301
1302
1303
1304







-
+








static void
SortTags(
    int numTags,		/* Number of tag pointers at *tagArrayPtr. */
    TkTextTag **tagArrayPtr)	/* Pointer to array of pointers. */
{
    int i, j, prio;
    TkTextTag **tagPtrPtr;
    register TkTextTag **tagPtrPtr;
    TkTextTag **maxPtrPtr, *tmp;

    if (numTags < 2) {
	return;
    }
    if (numTags < 20) {
	for (i = numTags-1; i > 0; i--, tagArrayPtr++) {
1283
1284
1285
1286
1287
1288
1289
1290

1291
1292
1293
1294
1295
1296
1297
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388







-
+







static void
ChangeTagPriority(
    TkText *textPtr,		/* Information about text widget. */
    TkTextTag *tagPtr,		/* Tag whose priority is to be changed. */
    int prio)			/* New priority for tag. */
{
    int low, high, delta;
    TkTextTag *tagPtr2;
    register TkTextTag *tagPtr2;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    if (prio < 0) {
	prio = 0;
    }
    if (prio >= textPtr->sharedTextPtr->numTags) {
1316
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1421







-
+








    if ((textPtr->selTagPtr->priority >= low)
	    && (textPtr->selTagPtr->priority <= high)) {
	textPtr->selTagPtr->priority += delta;
    }
    for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->tagTable, &search);
	    hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	tagPtr2 = (TkTextTag *)Tcl_GetHashValue(hPtr);
	tagPtr2 = Tcl_GetHashValue(hPtr);
	if ((tagPtr2->priority >= low) && (tagPtr2->priority <= high)) {
	    tagPtr2->priority += delta;
	}
    }
    tagPtr->priority = prio;
}

1344
1345
1346
1347
1348
1349
1350
1351

1352
1353
1354

1355
1356



1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368

1369
1370
1371





















1372
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392
1393


1394
1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422


1423
1424
1425
1426
1427
1428
1429
1435
1436
1437
1438
1439
1440
1441

1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463


1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489

1490
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504


1505
1506
1507






1508
1509















1510
1511
1512
1513
1514

1515
1516
1517
1518
1519
1520
1521
1522
1523







-
+


-
+


+
+
+











-
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+







-
+






-
-
+
+

-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+
+







 *	any).
 *
 *--------------------------------------------------------------
 */

void
TkTextBindProc(
    void *clientData,	/* Pointer to text widget structure. */
    ClientData clientData,	/* Pointer to canvas structure. */
    XEvent *eventPtr)		/* Pointer to X event that just happened. */
{
    TkText *textPtr = (TkText *)clientData;
    TkText *textPtr = clientData;
    int repick = 0;

# define AnyButtonMask \
	(Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask)

    textPtr->refCount++;

    /*
     * This code simulates grabs for mouse buttons by keeping track of whether
     * a button is pressed and refusing to pick a new current character while
     * a button is pressed.
     */

    if (eventPtr->type == ButtonPress) {
	textPtr->flags |= BUTTON_DOWN;
    } else if (eventPtr->type == ButtonRelease) {
	unsigned long mask;
	int mask;

	mask = Tk_GetButtonMask(eventPtr->xbutton.button);
	if ((eventPtr->xbutton.state & ALL_BUTTONS) == mask) {
	switch (eventPtr->xbutton.button) {
	case Button1:
	    mask = Button1Mask;
	    break;
	case Button2:
	    mask = Button2Mask;
	    break;
	case Button3:
	    mask = Button3Mask;
	    break;
	case Button4:
	    mask = Button4Mask;
	    break;
	case Button5:
	    mask = Button5Mask;
	    break;
	default:
	    mask = 0;
	    break;
	}
	if ((eventPtr->xbutton.state & AnyButtonMask) == (unsigned) mask) {
	    textPtr->flags &= ~BUTTON_DOWN;
	    repick = 1;
	}
    } else if ((eventPtr->type == EnterNotify)
	    || (eventPtr->type == LeaveNotify)) {
	if (eventPtr->xcrossing.state & ALL_BUTTONS) {
	if (eventPtr->xcrossing.state & AnyButtonMask) {
	    textPtr->flags |= BUTTON_DOWN;
	} else {
	    textPtr->flags &= ~BUTTON_DOWN;
	}
	TkTextPickCurrent(textPtr, eventPtr);
	goto done;
    } else if (eventPtr->type == MotionNotify) {
	if (eventPtr->xmotion.state & ALL_BUTTONS) {
	if (eventPtr->xmotion.state & AnyButtonMask) {
	    textPtr->flags |= BUTTON_DOWN;
	} else {
	    textPtr->flags &= ~BUTTON_DOWN;
	}
	TkTextPickCurrent(textPtr, eventPtr);
    }

    if ((textPtr->sharedTextPtr->bindingTable != NULL)
    if ((textPtr->numCurTags > 0)
	    && (textPtr->sharedTextPtr->bindingTable != NULL)
	    && (textPtr->tkwin != NULL) && !(textPtr->flags & DESTROYED)) {
	if (textPtr->numCurTags > 0) {
	    /*
	     * The mouse is inside the text widget, the 'current' mark was updated.
	     */

	    TagBindEvent(textPtr, eventPtr, textPtr->numCurTags,
	TagBindEvent(textPtr, eventPtr, textPtr->numCurTags,
		textPtr->curTagArrayPtr);
	} else if ((eventPtr->type == KeyPress) || (eventPtr->type == KeyRelease)) {
	    /*
	     * Key events fire independently of the 'current' mark and use the
	     * 'insert' mark.
	     */

	    TkTextIndex index;
	    TkTextTag** tagArrayPtr;
	    Tcl_Size numTags;

	    TkTextMarkNameToIndex(textPtr, "insert", &index);
	    tagArrayPtr = TkBTreeGetTags(&index, textPtr, &numTags);
	    SortTags(numTags, tagArrayPtr);
	    TagBindEvent(textPtr, eventPtr, numTags, tagArrayPtr);
	}
    }
    if (repick) {
	unsigned int oldState;

	oldState = eventPtr->xbutton.state;
	eventPtr->xbutton.state &= ~(unsigned long)ALL_BUTTONS;
	eventPtr->xbutton.state &= ~(Button1Mask|Button2Mask
		|Button3Mask|Button4Mask|Button5Mask);
	if (!(textPtr->flags & DESTROYED)) {
	    TkTextPickCurrent(textPtr, eventPtr);
	}
	eventPtr->xbutton.state = oldState;
    }

  done:
1453
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473
1474
1475
1476
1477
1478
1479
1480
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564

1565


1566
1567
1568
1569
1570
1571
1572







-
+










-
+
-
-







 *	widget.
 *
 *--------------------------------------------------------------
 */

void
TkTextPickCurrent(
    TkText *textPtr,	/* Text widget in which to select current
    register TkText *textPtr,	/* Text widget in which to select current
				 * character. */
    XEvent *eventPtr)		/* Event describing location of mouse cursor.
				 * Must be EnterWindow, LeaveWindow,
				 * ButtonRelease, or MotionNotify. */
{
    TkTextIndex index;
    TkTextTag **oldArrayPtr, **newArrayPtr;
    TkTextTag **copyArrayPtr = NULL;
				/* Initialization needed to prevent compiler
				 * warning. */
    int numOldTags, i, nearby;
    int numOldTags, numNewTags, i, j, size, nearby;
    Tcl_Size numNewTags, j;
    size_t size;
    XEvent event;

    /*
     * If a button is down, then don't do anything at all; we'll be called
     * again when all buttons are up, and we can repick then. This implements
     * a form of mouse grabbing.
     */
1558
1559
1560
1561
1562
1563
1564
1565
1566


1567
1568
1569
1570
1571
1572
1573
1650
1651
1652
1653
1654
1655
1656


1657
1658
1659
1660
1661
1662
1663
1664
1665







-
-
+
+







     * compare the old tags to the copy, nullifying any tags that are present
     * in both groups (i.e. the tags that haven't changed).
     */

    SortTags(textPtr->numCurTags, textPtr->curTagArrayPtr);
    if (numNewTags > 0) {
	size = numNewTags * sizeof(TkTextTag *);
	copyArrayPtr = (TkTextTag **)ckalloc(size);
	memcpy(copyArrayPtr, newArrayPtr, size);
	copyArrayPtr = ckalloc(size);
	memcpy(copyArrayPtr, newArrayPtr, (size_t) size);
	for (i = 0; i < textPtr->numCurTags; i++) {
	    for (j = 0; j < numNewTags; j++) {
		if (textPtr->curTagArrayPtr[i] == copyArrayPtr[j]) {
		    textPtr->curTagArrayPtr[i] = NULL;
		    copyArrayPtr[j] = NULL;
		    break;
		}
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602



1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1684
1685
1686
1687
1688
1689
1690




1691
1692
1693







1694
1695
1696
1697
1698
1699
1700







-
-
-
-
+
+
+
-
-
-
-
-
-
-







	if ((textPtr->sharedTextPtr->bindingTable != NULL)
		&& (textPtr->tkwin != NULL)
		&& !(textPtr->flags & DESTROYED)) {
	    event = textPtr->pickEvent;
	    event.type = LeaveNotify;

	    /*
	     * Behaviour before ticket #47d4f29159:
	     *   Always use a detail of NotifyAncestor. Besides being
	     *   consistent, this avoids problems where the binding code will
	     *   discard NotifyInferior events.
	     * Always use a detail of NotifyAncestor. Besides being
	     * consistent, this avoids problems where the binding code will
	     * discard NotifyInferior events.
	     *
	     * Behaviour after ticket #47d4f29159:
	     *   The binding mechanism doesn't discard events with detail field
	     *   NotifyInferior anymore. It would be best to base the detail
	     *   field on the ancestry relationship between the old and new
	     *   tags. For the time being, retain the choice from before
	     *   ticket #47d4f29159, which doesn't harm.
	     */

	    event.xcrossing.detail = NotifyAncestor;
	    TagBindEvent(textPtr, &event, numOldTags, oldArrayPtr);
	}
	ckfree(oldArrayPtr);
    }
1670
1671
1672
1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1754
1755
1756
1757
1758
1759
1760

1761
1762
1763
1764
1765
1766
1767
1768







-
+







    int i;

    /*
     * Try to avoid allocation unless there are lots of tags.
     */

    if (numTags > NUM_BIND_TAGS) {
	nameArrPtr = (const char **)ckalloc(numTags * sizeof(const char *));
	nameArrPtr = ckalloc(numTags * sizeof(const char *));
    } else {
	nameArrPtr = nameArray;
    }

    /*
     * We use tag names as keys in the hash table. We do this instead of using
     * the actual tagPtr objects because we want one "sel" tag binding for all
1697
1698
1699
1700
1701
1702
1703
1704

1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1781
1782
1783
1784
1785
1786
1787

1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801







-
+













	     * being thrown at it.
	     */

	    nameArrPtr[i] = NULL;
	}
    }
    Tk_BindEvent(textPtr->sharedTextPtr->bindingTable, eventPtr,
	    textPtr->tkwin, numTags, (void **) nameArrPtr);
	    textPtr->tkwin, numTags, (ClientData *) nameArrPtr);

    if (numTags > NUM_BIND_TAGS) {
	ckfree(nameArrPtr);
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkTextWind.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25

26
27
28
29
30
31

32
33
34
35
36
37
38
39


40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55


56
57
58
59
60

61
62

63
64
65
66
67
68
69
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30

31
32
33
34
35
36
37


38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53


54
55
56
57
58
59

60
61

62
63
64
65
66
67
68
69







-
-
+
+













-
+

-
+





-
+






-
-
+
+










-
+



-
-
+
+




-
+

-
+







/*
 * tkTextWind.c --
 *
 *	This file contains code that allows arbitrary windows to be nested
 *	inside text widgets. It also implements the "window" widget command
 *	for texts.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkPort.h"
#include "tkText.h"

/*
 * The following structure is the official type record for the embedded window
 * geometry manager:
 */

static void		EmbWinRequestProc(void *clientData,
static void		EmbWinRequestProc(ClientData clientData,
			    Tk_Window tkwin);
static void		EmbWinLostContentProc(void *clientData,
static void		EmbWinLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);

static const Tk_GeomMgr textGeomType = {
    "text",			/* name */
    EmbWinRequestProc,		/* requestProc */
    EmbWinLostContentProc,	/* lostContentProc */
    EmbWinLostSlaveProc,	/* lostSlaveProc */
};

/*
 * Macro that determines the size of an embedded window segment:
 */

#define EW_SEG_SIZE (offsetof(TkTextSegment, body) \
	+ sizeof(TkTextEmbWindow))
#define EW_SEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \
	+ sizeof(TkTextEmbWindow)))

/*
 * Prototypes for functions defined in this file:
 */

static TkTextSegment *	EmbWinCleanupProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static void		EmbWinCheckProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr);
static void		EmbWinBboxProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr, Tcl_Size index, int y,
			    TkTextDispChunk *chunkPtr, int index, int y,
			    int lineHeight, int baseline, int *xPtr,int *yPtr,
			    int *widthPtr, int *heightPtr);
static int		EmbWinConfigure(TkText *textPtr, TkTextSegment *ewPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static void		EmbWinDelayedUnmap(void *clientData);
			    int objc, Tcl_Obj *const objv[]);
static void		EmbWinDelayedUnmap(ClientData clientData);
static int		EmbWinDeleteProc(TkTextSegment *segPtr,
			    TkTextLine *linePtr, int treeGone);
static int		EmbWinLayoutProc(TkText *textPtr,
			    TkTextIndex *indexPtr, TkTextSegment *segPtr,
			    Tcl_Size offset, int maxX, Tcl_Size maxChars,int noCharsYet,
			    int offset, int maxX, int maxChars,int noCharsYet,
			    TkWrapMode wrapMode, TkTextDispChunk *chunkPtr);
static void		EmbWinStructureProc(void *clientData,
static void		EmbWinStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EmbWinUndisplayProc(TkText *textPtr,
			    TkTextDispChunk *chunkPtr);
static TkTextEmbWindowClient *EmbWinGetClient(const TkText *textPtr,
			    TkTextSegment *ewPtr);

/*
85
86
87
88
89
90
91




92
93
94
95
96
97
98
99


100
101

102
103

104
105

106
107

108
109

110
111
112
113
114
115
116
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101


102
103
104

105
106

107
108

109
110

111
112

113
114
115
116
117
118
119
120







+
+
+
+






-
-
+
+

-
+

-
+

-
+

-
+

-
+







 * Definitions for alignment values:
 */

static const char *const alignStrings[] = {
    "baseline", "bottom", "center", "top", NULL
};

typedef enum {
    ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_TOP
} alignMode;

/*
 * Information used for parsing window configuration options:
 */

static const Tk_OptionSpec optionSpecs[] = {
    {TK_OPTION_STRING_TABLE, "-align", NULL, NULL,
	"center", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, align),
	TK_OPTION_ENUM_VAR, alignStrings, 0},
	"center", -1, Tk_Offset(TkTextEmbWindow, align),
	0, alignStrings, 0},
    {TK_OPTION_STRING, "-create", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextEmbWindow, create), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextEmbWindow, create), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_PIXELS, "-padx", NULL, NULL,
	"0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, padX), 0, 0, 0},
	"0", -1, Tk_Offset(TkTextEmbWindow, padX), 0, 0, 0},
    {TK_OPTION_PIXELS, "-pady", NULL, NULL,
	"0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, padY), 0, 0, 0},
	"0", -1, Tk_Offset(TkTextEmbWindow, padY), 0, 0, 0},
    {TK_OPTION_BOOLEAN, "-stretch", NULL, NULL,
	"0", TCL_INDEX_NONE, offsetof(TkTextEmbWindow, stretch), 0, 0, 0},
	"0", -1, Tk_Offset(TkTextEmbWindow, stretch), 0, 0, 0},
    {TK_OPTION_WINDOW, "-window", NULL, NULL,
	NULL, TCL_INDEX_NONE, offsetof(TkTextEmbWindow, tkwin), TK_OPTION_NULL_OK, 0, 0},
	NULL, -1, Tk_Offset(TkTextEmbWindow, tkwin), TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 *--------------------------------------------------------------
 *
 * TkTextWindowCmd --
125
126
127
128
129
130
131
132

133
134

135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
129
130
131
132
133
134
135

136
137

138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170







-
+

-
+











-
+












+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
TkTextWindowCmd(
    TkText *textPtr,	/* Information about text widget. */
    register TkText *textPtr,	/* Information about text widget. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. Someone else has already
				 * parsed this command enough to know that
				 * objv[1] is "window". */
{
    int optionIndex;
    static const char *const windOptionStrings[] = {
	"cget", "configure", "create", "names", NULL
    };
    enum windOptions {
	WIND_CGET, WIND_CONFIGURE, WIND_CREATE, WIND_NAMES
    };
    TkTextSegment *ewPtr;
    register TkTextSegment *ewPtr;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[2], windOptionStrings,
	    sizeof(char *), "window option", 0, &optionIndex) != TCL_OK) {
	return TCL_ERROR;
    }
    switch ((enum windOptions) optionIndex) {
    case WIND_CGET: {
	TkTextIndex index;
	TkTextSegment *ewPtr;
	Tcl_Obj *objPtr;
	TkTextEmbWindowClient *client;

	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 3, objv, "index option");
	    return TCL_ERROR;
	}
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211







-
+









+







	client = EmbWinGetClient(textPtr, ewPtr);
	if (client != NULL) {
	    ewPtr->body.ew.tkwin = client->tkwin;
	} else {
	    ewPtr->body.ew.tkwin = NULL;
	}

	objPtr = Tk_GetOptionValue(interp, &ewPtr->body.ew,
	objPtr = Tk_GetOptionValue(interp, (char *) &ewPtr->body.ew,
		ewPtr->body.ew.optionTable, objv[4], textPtr->tkwin);
	if (objPtr == NULL) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, objPtr);
	return TCL_OK;
    }
    case WIND_CONFIGURE: {
	TkTextIndex index;
	TkTextSegment *ewPtr;

	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 3, objv, "index ?-option value ...?");
	    return TCL_ERROR;
	}
	if (TkTextGetObjIndex(interp, textPtr, objv[3], &index) != TCL_OK) {
	    return TCL_ERROR;
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+







	    client = EmbWinGetClient(textPtr, ewPtr);
	    if (client != NULL) {
		ewPtr->body.ew.tkwin = client->tkwin;
	    } else {
		ewPtr->body.ew.tkwin = NULL;
	    }

	    objPtr = Tk_GetOptionInfo(interp, &ewPtr->body.ew,
	    objPtr = Tk_GetOptionInfo(interp, (char *) &ewPtr->body.ew,
		    ewPtr->body.ew.optionTable, (objc == 5) ? objv[4] : NULL,
		    textPtr->tkwin);
	    if (objPtr == NULL) {
		return TCL_ERROR;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    return TCL_OK;
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294

295
296
297
298
299

300
301
302
303
304
305
306
286
287
288
289
290
291
292

293
294
295
296
297
298
299

300
301
302
303
304

305
306
307
308
309
310
311
312







-
+






-
+




-
+







		    lineIndex, 1000000, &index);
	}

	/*
	 * Create the new window segment and initialize it.
	 */

	ewPtr = (TkTextSegment *)ckalloc(EW_SEG_SIZE);
	ewPtr = ckalloc(EW_SEG_SIZE);
	ewPtr->typePtr = &tkTextEmbWindowType;
	ewPtr->size = 1;
	ewPtr->body.ew.sharedTextPtr = textPtr->sharedTextPtr;
	ewPtr->body.ew.linePtr = NULL;
	ewPtr->body.ew.tkwin = NULL;
	ewPtr->body.ew.create = NULL;
	ewPtr->body.ew.align = TK_ALIGN_CENTER;
	ewPtr->body.ew.align = ALIGN_CENTER;
	ewPtr->body.ew.padX = ewPtr->body.ew.padY = 0;
	ewPtr->body.ew.stretch = 0;
	ewPtr->body.ew.optionTable = Tk_CreateOptionTable(interp, optionSpecs);

	client = (TkTextEmbWindowClient *)ckalloc(sizeof(TkTextEmbWindowClient));
	client = ckalloc(sizeof(TkTextEmbWindowClient));
	client->next = NULL;
	client->textPtr = textPtr;
	client->tkwin = NULL;
	client->chunkCount = 0;
	client->displayed = 0;
	client->parent = ewPtr;
	ewPtr->body.ew.clients = client;
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355







-
+







	    Tcl_WrongNumArgs(interp, 3, objv, NULL);
	    return TCL_ERROR;
	}
	resultObj = Tcl_NewObj();
	for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->windowTable,
		&search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    (const char *)Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr),
		    -1));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;
    }
    }
    return TCL_OK;
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413







-
+


















-
+







 */

static int
EmbWinConfigure(
    TkText *textPtr,		/* Information about text widget that contains
				 * embedded window. */
    TkTextSegment *ewPtr,	/* Embedded window to be configured. */
    Tcl_Size objc,			/* Number of strings in objv. */
    int objc,			/* Number of strings in objv. */
    Tcl_Obj *const objv[])	/* Array of objects describing configuration
				 * options. */
{
    Tk_Window oldWindow;
    TkTextEmbWindowClient *client;

    /*
     * Copy over client specific value before querying or setting.
     */

    client = EmbWinGetClient(textPtr, ewPtr);
    if (client != NULL) {
	ewPtr->body.ew.tkwin = client->tkwin;
    } else {
	ewPtr->body.ew.tkwin = NULL;
    }

    oldWindow = ewPtr->body.ew.tkwin;
    if (Tk_SetOptions(textPtr->interp, &ewPtr->body.ew,
    if (Tk_SetOptions(textPtr->interp, (char *) &ewPtr->body.ew,
	    ewPtr->body.ew.optionTable, objc, objv, textPtr->tkwin, NULL,
	    NULL) != TCL_OK) {
	return TCL_ERROR;
    }

    if (oldWindow != ewPtr->body.ew.tkwin) {
	if (oldWindow != NULL) {
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464

465
466
467
468
469
470
471
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477







-
+















-
+







-
+








	    parent = Tk_Parent(ewPtr->body.ew.tkwin);
	    for (ancestor = textPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
		if (ancestor == parent) {
		    break;
		}
		if (Tk_TopWinHierarchy(ancestor)) {
		badContainer:
		badMaster:
		    Tcl_SetObjResult(textPtr->interp, Tcl_ObjPrintf(
			    "can't embed %s in %s",
			    Tk_PathName(ewPtr->body.ew.tkwin),
			    Tk_PathName(textPtr->tkwin)));
		    Tcl_SetErrorCode(textPtr->interp, "TK", "GEOMETRY",
			    "HIERARCHY", NULL);
		    ewPtr->body.ew.tkwin = NULL;
		    if (client != NULL) {
			client->tkwin = NULL;
		    }
		    return TCL_ERROR;
		}
	    }
	    if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin)
		    || (ewPtr->body.ew.tkwin == textPtr->tkwin)) {
		goto badContainer;
		goto badMaster;
	    }

	    if (client == NULL) {
		/*
		 * Have to make the new client.
		 */

		client = (TkTextEmbWindowClient *)ckalloc(sizeof(TkTextEmbWindowClient));
		client = ckalloc(sizeof(TkTextEmbWindowClient));
		client->next = ewPtr->body.ew.clients;
		client->textPtr = textPtr;
		client->tkwin = NULL;
		client->chunkCount = 0;
		client->displayed = 0;
		client->parent = ewPtr;
		ewPtr->body.ew.clients = client;
513
514
515
516
517
518
519
520

521
522
523

524

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542




543


544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

564
565
566
567


568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592

593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610


611
612
613
614

615
616
617
618
619
620
621
519
520
521
522
523
524
525

526
527
528

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578


579
580
581

582
583
584
585
586
587









588
589
590
591
592
593
594
595
596

597
598

599
600
601
602
603
604
605
606
607
608
609
610
611
612
613


614
615
616
617
618

619
620
621
622
623
624
625
626







-
+


-
+

+


















+
+
+
+
-
+
+




















+


-
-
+
+

-
+





-
-
-
-
-
-
-
-
-
+








-
+

-
+














-
-
+
+



-
+







 *	of the text is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
EmbWinStructureProc(
    void *clientData,	/* Pointer to record describing window item. */
    ClientData clientData,	/* Pointer to record describing window item. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    TkTextEmbWindowClient *client = (TkTextEmbWindowClient *)clientData;
    TkTextEmbWindowClient *client = clientData;
    TkTextSegment *ewPtr = client->parent;
    TkTextIndex index;
    Tcl_HashEntry *hPtr;

    if (eventPtr->type != DestroyNotify) {
	return;
    }

    hPtr = Tcl_FindHashEntry(&ewPtr->body.ew.sharedTextPtr->windowTable,
	    Tk_PathName(client->tkwin));
    if (hPtr != NULL) {
	/*
	 * This may not exist if the entire widget is being deleted.
	 */

	Tcl_DeleteHashEntry(hPtr);
    }

    ewPtr->body.ew.tkwin = NULL;
    client->tkwin = NULL;
    index.tree = ewPtr->body.ew.sharedTextPtr->tree;
    index.linePtr = ewPtr->body.ew.linePtr;
    index.byteIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr);
    TkTextChanged(ewPtr->body.ew.sharedTextPtr, NULL, &index, &index);
    EmbWinRequestProc(client, NULL);
    TkTextInvalidateLineMetrics(ewPtr->body.ew.sharedTextPtr, NULL,
	    index.linePtr, 0, TK_TEXT_INVALIDATE_ONLY);
}

/*
 *--------------------------------------------------------------
 *
 * EmbWinRequestProc --
 *
 *	This function is invoked whenever a window that's associated with a
 *	window canvas item changes its requested dimensions.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The size and location on the screen of the window may change,
 *	depending on the options specified for the window item.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static void
EmbWinRequestProc(
    void *clientData,	/* Pointer to record for window item. */
    TCL_UNUSED(Tk_Window))	/* Window that changed its desired size. */
    ClientData clientData,	/* Pointer to record for window item. */
    Tk_Window tkwin)		/* Window that changed its desired size. */
{
    TkTextEmbWindowClient *client = (TkTextEmbWindowClient *)clientData;
    TkTextEmbWindowClient *client = clientData;
    TkTextSegment *ewPtr = client->parent;
    TkTextIndex index;

    index.tree = ewPtr->body.ew.sharedTextPtr->tree;
    index.linePtr = ewPtr->body.ew.linePtr;

    /*
     * ewPtr->body.ew.tkwin == NULL means the embedded window is already
     * destroyed. The ewPtr segment is no longer linked, TkTextSegToOffset
     * cannot find it within the line pointed by ewPtr->body.ew.linePtr.
     */

    index.byteIndex =  ewPtr->body.ew.tkwin ?
	    TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr) : 0;
    index.byteIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr);
    TkTextChanged(ewPtr->body.ew.sharedTextPtr, NULL, &index, &index);
    TkTextInvalidateLineMetrics(ewPtr->body.ew.sharedTextPtr, NULL,
	    index.linePtr, 0, TK_TEXT_INVALIDATE_ONLY);
}

/*
 *--------------------------------------------------------------
 *
 * EmbWinLostContentProc --
 * EmbWinLostSlaveProc --
 *
 *	This function is invoked by the Tk geometry manager when a content
 *	This function is invoked by the Tk geometry manager when a slave
 *	window managed by a text widget is claimed away by another geometry
 *	manager.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is disassociated from the window segment, and the portion
 *	of the text is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
EmbWinLostContentProc(
    void *clientData,	/* Pointer to record describing window item. */
EmbWinLostSlaveProc(
    ClientData clientData,	/* Pointer to record describing window item. */
    Tk_Window tkwin)		/* Window that was claimed away by another
				 * geometry manager. */
{
    TkTextEmbWindowClient *client = (TkTextEmbWindowClient *)clientData;
    TkTextEmbWindowClient *client = clientData;
    TkTextSegment *ewPtr = client->parent;
    TkTextIndex index;
    Tcl_HashEntry *hPtr;
    TkTextEmbWindowClient *loop;

    Tk_DeleteEventHandler(client->tkwin, StructureNotifyMask,
	    EmbWinStructureProc, client);
727
728
729
730
731
732
733

734
735
736
737
738


739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

760
761
762
763
764
765
766
732
733
734
735
736
737
738
739
740
741
742


743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764

765
766
767
768
769
770
771
772







+



-
-
+
+




















-
+







 * Side effects:
 *	The embedded window is deleted, if it exists, and any resources
 *	associated with it are released.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
static int
EmbWinDeleteProc(
    TkTextSegment *ewPtr,	/* Segment being deleted. */
    TCL_UNUSED(TkTextLine *),	/* Line containing segment. */
    TCL_UNUSED(int))		/* Non-zero means the entire tree is being
    TkTextLine *linePtr,	/* Line containing segment. */
    int treeGone)		/* Non-zero means the entire tree is being
				 * deleted, so everything must get cleaned
				 * up. */
{
    TkTextEmbWindowClient *client;
    client = ewPtr->body.ew.clients;

    while (client != NULL) {
	TkTextEmbWindowClient *next = client->next;
	Tcl_HashEntry *hPtr = NULL;

	if (client->tkwin != NULL) {
	    hPtr = Tcl_FindHashEntry(
		    &ewPtr->body.ew.sharedTextPtr->windowTable,
		    Tk_PathName(client->tkwin));
	}
	TkTextWinFreeClient(hPtr, client);
	client = next;
    }
    ewPtr->body.ew.clients = NULL;

    Tk_FreeConfigOptions(&ewPtr->body.ew, ewPtr->body.ew.optionTable,
    Tk_FreeConfigOptions((char *) &ewPtr->body.ew, ewPtr->body.ew.optionTable,
	    NULL);

    /*
     * Free up all memory allocated.
     */

    ckfree(ewPtr);
806
807
808
809
810
811
812

813
814
815
816

817
818

819
820
821
822

823
824
825
826

827
828
829

830
831
832
833
834
835
836
812
813
814
815
816
817
818
819
820
821
822

823
824

825
826
827
828

829
830
831
832

833
834
835

836
837
838
839
840
841
842
843







+



-
+

-
+



-
+



-
+


-
+







 *
 * Side effects:
 *	None, except for filling in chunkPtr.
 *
 *--------------------------------------------------------------
 */

	/*ARGSUSED*/
static int
EmbWinLayoutProc(
    TkText *textPtr,		/* Text widget being layed out. */
    TCL_UNUSED(TkTextIndex *),	/* Identifies first character in chunk. */
    TkTextIndex *indexPtr,	/* Identifies first character in chunk. */
    TkTextSegment *ewPtr,	/* Segment corresponding to indexPtr. */
    Tcl_Size offset,			/* Offset within segPtr corresponding to
    int offset,			/* Offset within segPtr corresponding to
				 * indexPtr (always 0). */
    int maxX,			/* Chunk must not occupy pixels at this
				 * position or higher. */
    TCL_UNUSED(Tcl_Size),	/* Chunk must not include more than this many
    int maxChars,		/* Chunk must not include more than this many
				 * characters. */
    int noCharsYet,		/* Non-zero means no characters have been
				 * assigned to this line yet. */
    TCL_UNUSED(TkWrapMode),	/* Wrap mode to use for line:
    TkWrapMode wrapMode,	/* Wrap mode to use for line:
				 * TEXT_WRAPMODE_CHAR, TEXT_WRAPMODE_NONE, or
				 * TEXT_WRAPMODE_WORD. */
    TkTextDispChunk *chunkPtr)
    register TkTextDispChunk *chunkPtr)
				/* Structure to fill in with information about
				 * this chunk. The x field has already been
				 * set by the caller. */
{
    int width, height;
    TkTextEmbWindowClient *client;

864
865
866
867
868
869
870
871

872
873
874
875
876
877
878
871
872
873
874
875
876
877

878
879
880
881
882
883
884
885







-
+







	while (*string != 0) {
	    if ((*string == '%') && (string[1] == '%' || string[1] == 'W')) {
		if (dsPtr == NULL) {
		    Tcl_DStringInit(&buf);
		    dsPtr = &buf;
		}
		if (string != before) {
		    Tcl_DStringAppend(dsPtr, before, string-before);
		    Tcl_DStringAppend(dsPtr, before, (int) (string-before));
		    before = string;
		}
		if (string[1] == '%') {
		    Tcl_DStringAppend(dsPtr, "%", 1);
		} else {
		    /*
		     * Substitute string as proper Tcl list element.
899
900
901
902
903
904
905
906
907


908
909
910

911
912
913
914
915
916
917
906
907
908
909
910
911
912


913
914
915
916

917
918
919
920
921
922
923
924







-
-
+
+


-
+







	 * The window doesn't currently exist. Create it by evaluating the
	 * creation script. The script must return the window's path name:
	 * look up that name to get back to the window token. Then register
	 * ourselves as the geometry manager for the window.
	 */

	if (dsPtr != NULL) {
	    Tcl_DStringAppend(dsPtr, before, string-before);
	    code = Tcl_EvalEx(textPtr->interp, Tcl_DStringValue(dsPtr), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    Tcl_DStringAppend(dsPtr, before, (int) (string-before));
	    code = Tcl_EvalEx(textPtr->interp, Tcl_DStringValue(dsPtr), -1, TCL_EVAL_GLOBAL);
	    Tcl_DStringFree(dsPtr);
	} else {
	    code = Tcl_EvalEx(textPtr->interp, ewPtr->body.ew.create, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    code = Tcl_EvalEx(textPtr->interp, ewPtr->body.ew.create, -1, TCL_EVAL_GLOBAL);
	}
	if (code != TCL_OK) {
	    Tcl_BackgroundException(textPtr->interp, code);
	    goto gotWindow;
	}
	nameObj = Tcl_GetObjResult(textPtr->interp);
	Tcl_IncrRefCount(nameObj);
925
926
927
928
929
930
931
932

933
934
935
936
937

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955

956
957
958
959
960
961
962
932
933
934
935
936
937
938

939
940
941
942
943

944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961

962
963
964
965
966
967
968
969







-
+




-
+

















-
+







	}

	for (ancestor = textPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
	    if (ancestor == Tk_Parent(ewPtr->body.ew.tkwin)) {
		break;
	    }
	    if (Tk_TopWinHierarchy(ancestor)) {
		goto badContainer;
		goto badMaster;
	    }
	}
	if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin)
		|| (textPtr->tkwin == ewPtr->body.ew.tkwin)) {
	badContainer:
	badMaster:
	    Tcl_SetObjResult(textPtr->interp, Tcl_ObjPrintf(
		    "can't embed %s relative to %s",
		    Tk_PathName(ewPtr->body.ew.tkwin),
		    Tk_PathName(textPtr->tkwin)));
	    Tcl_SetErrorCode(textPtr->interp, "TK", "GEOMETRY", "HIERARCHY",
		    NULL);
	    Tcl_BackgroundException(textPtr->interp, TCL_ERROR);
	    ewPtr->body.ew.tkwin = NULL;
	    goto gotWindow;
	}

	if (client == NULL) {
	    /*
	     * We just used a '-create' script to make a new window, which we
	     * now need to add to our client list.
	     */

	    client = (TkTextEmbWindowClient *)ckalloc(sizeof(TkTextEmbWindowClient));
	    client = ckalloc(sizeof(TkTextEmbWindowClient));
	    client->next = ewPtr->body.ew.clients;
	    client->textPtr = textPtr;
	    client->tkwin = NULL;
	    client->chunkCount = 0;
	    client->displayed = 0;
	    client->parent = ewPtr;
	    ewPtr->body.ew.clients = client;
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022







-
+







     */

    chunkPtr->displayProc = TkTextEmbWinDisplayProc;
    chunkPtr->undisplayProc = EmbWinUndisplayProc;
    chunkPtr->measureProc = NULL;
    chunkPtr->bboxProc = EmbWinBboxProc;
    chunkPtr->numBytes = 1;
    if (ewPtr->body.ew.align == TK_ALIGN_BASELINE) {
    if (ewPtr->body.ew.align == ALIGN_BASELINE) {
	chunkPtr->minAscent = height - ewPtr->body.ew.padY;
	chunkPtr->minDescent = ewPtr->body.ew.padY;
	chunkPtr->minHeight = 0;
    } else {
	chunkPtr->minAscent = 0;
	chunkPtr->minDescent = 0;
	chunkPtr->minHeight = height;
1041
1042
1043
1044
1045
1046
1047
1048

1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060

1061
1062
1063
1064
1065
1066
1067
1068







-
+





-
+







 *
 *--------------------------------------------------------------
 */

static void
EmbWinCheckProc(
    TkTextSegment *ewPtr,	/* Segment to check. */
    TCL_UNUSED(TkTextLine *))	/* Line containing segment. */
    TkTextLine *linePtr)	/* Line containing segment. */
{
    if (ewPtr->nextPtr == NULL) {
	Tcl_Panic("EmbWinCheckProc: embedded window is last segment in line");
    }
    if (ewPtr->size != 1) {
	Tcl_Panic("EmbWinCheckProc: embedded window has size %" TCL_SIZE_MODIFIER "d", ewPtr->size);
	Tcl_Panic("EmbWinCheckProc: embedded window has size %d", ewPtr->size);
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkTextEmbWinDisplayProc --
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089


1090
1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094


1095
1096
1097
1098
1099
1100
1101
1102

1103
1104
1105
1106
1107
1108
1109
1110







-
+




-
-
+
+






-
+







void
TkTextEmbWinDisplayProc(
    TkText *textPtr,		/* Information about text widget. */
    TkTextDispChunk *chunkPtr,	/* Chunk that is to be drawn. */
    int x,			/* X-position in dst at which to draw this
				 * chunk (differs from the x-position in the
				 * chunk because of scrolling). */
    TCL_UNUSED(int),	/* Top of rectangular bounding box for line:
    int y,			/* Top of rectangular bounding box for line:
				 * tells where to draw this chunk in dst
				 * (x-position is in the chunk itself). */
    int lineHeight,		/* Total height of line. */
    int baseline,		/* Offset of baseline from y. */
    TCL_UNUSED(Display *),	/* Display to use for drawing (unused).  */
    TCL_UNUSED(Drawable),	/* Pixmap or window in which to draw
    Display *display,		/* Display to use for drawing (unused).  */
    Drawable dst,		/* Pixmap or window in which to draw
				 * (unused).  */
    int screenY)		/* Y-coordinate in text window that
				 * corresponds to y. */
{
    int lineX, windowX, windowY, width, height;
    Tk_Window tkwin;
    TkTextSegment *ewPtr = (TkTextSegment *)chunkPtr->clientData;
    TkTextSegment *ewPtr = chunkPtr->clientData;
    TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr);

    if (client == NULL) {
	return;
    }

    tkwin = client->tkwin;
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190







-
+







 */

static void
EmbWinUndisplayProc(
    TkText *textPtr,		/* Overall information about text widget. */
    TkTextDispChunk *chunkPtr)	/* Chunk that is about to be freed. */
{
    TkTextSegment *ewPtr = (TkTextSegment *)chunkPtr->clientData;
    TkTextSegment *ewPtr = chunkPtr->clientData;
    TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr);

    if (client == NULL) {
	return;
    }

    client->chunkCount--;
1217
1218
1219
1220
1221
1222
1223
1224

1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263

1264
1265
1266

1267
1268
1269

1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268
1269

1270
1271
1272

1273
1274
1275

1276
1277
1278

1279
1280
1281
1282
1283
1284
1285
1286







-
+














-
+
















-
+






-
+


-
+


-
+


-
+







 *--------------------------------------------------------------
 */

static void
EmbWinBboxProc(
    TkText *textPtr,		/* Information about text widget. */
    TkTextDispChunk *chunkPtr,	/* Chunk containing desired char. */
    TCL_UNUSED(Tcl_Size),			/* Index of desired character within the
    int index,			/* Index of desired character within the
				 * chunk. */
    int y,			/* Topmost pixel in area allocated for this
				 * line. */
    int lineHeight,		/* Total height of line. */
    int baseline,		/* Location of line's baseline, in pixels
				 * measured down from y. */
    int *xPtr, int *yPtr,	/* Gets filled in with coords of character's
				 * upper-left pixel. */
    int *widthPtr,		/* Gets filled in with width of window, in
				 * pixels. */
    int *heightPtr)		/* Gets filled in with height of window, in
				 * pixels. */
{
    Tk_Window tkwin;
    TkTextSegment *ewPtr = (TkTextSegment *)chunkPtr->clientData;
    TkTextSegment *ewPtr = chunkPtr->clientData;
    TkTextEmbWindowClient *client = EmbWinGetClient(textPtr, ewPtr);

    if (client == NULL) {
	tkwin = NULL;
    } else {
	tkwin = client->tkwin;
    }
    if (tkwin != NULL) {
	*widthPtr = Tk_ReqWidth(tkwin);
	*heightPtr = Tk_ReqHeight(tkwin);
    } else {
	*widthPtr = 0;
	*heightPtr = 0;
    }
    *xPtr = chunkPtr->x + ewPtr->body.ew.padX;
    if (ewPtr->body.ew.stretch) {
	if (ewPtr->body.ew.align == TK_ALIGN_BASELINE) {
	if (ewPtr->body.ew.align == ALIGN_BASELINE) {
	    *heightPtr = baseline - ewPtr->body.ew.padY;
	} else {
	    *heightPtr = lineHeight - 2*ewPtr->body.ew.padY;
	}
    }
    switch (ewPtr->body.ew.align) {
    case TK_ALIGN_BOTTOM:
    case ALIGN_BOTTOM:
	*yPtr = y + (lineHeight - *heightPtr - ewPtr->body.ew.padY);
	break;
    case TK_ALIGN_CENTER:
    case ALIGN_CENTER:
	*yPtr = y + (lineHeight - *heightPtr)/2;
	break;
    case TK_ALIGN_TOP:
    case ALIGN_TOP:
	*yPtr = y + ewPtr->body.ew.padY;
	break;
    case TK_ALIGN_BASELINE:
    case ALIGN_BASELINE:
	*yPtr = y + (baseline - *heightPtr);
	break;
    }
}

/*
 *--------------------------------------------------------------
1292
1293
1294
1295
1296
1297
1298
1299

1300
1301

1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341

1342
1343
1344
1345
1346

1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1299
1300
1301
1302
1303
1304
1305

1306
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327



1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352

1353
1354
1355

1356
1357
1358
1359












1360
1361
1362
1363
1364
1365
1366
1367







-
+

-
+



















-
-
-
+
+
+

















-
+




-
+


-
+



-
-
-
-
-
-
-
-
-
-
-
-
+







 *	non-zero again.
 *
 *--------------------------------------------------------------
 */

static void
EmbWinDelayedUnmap(
    void *clientData)	/* Token for the window to be unmapped. */
    ClientData clientData)	/* Token for the window to be unmapped. */
{
    TkTextEmbWindowClient *client = (TkTextEmbWindowClient *)clientData;
    TkTextEmbWindowClient *client = clientData;

    if (!client->displayed && (client->tkwin != NULL)) {
	if (client->textPtr->tkwin != Tk_Parent(client->tkwin)) {
	    Tk_UnmaintainGeometry(client->tkwin, client->textPtr->tkwin);
	} else {
	    Tk_UnmapWindow(client->tkwin);
	}
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkTextWindowIndex --
 *
 *	Given the name of an embedded window within a text widget, returns an
 *	index corresponding to the window's position in the text.
 *
 * Results:
 *	The return value is TCL_OK if there is an embedded window by the given
 *	name in the text widget, TCL_ERROR otherwise. If the window exists,
 *	*indexPtr is filled in with its index.
 *	The return value is 1 if there is an embedded window by the given name
 *	in the text widget, 0 otherwise. If the window exists, *indexPtr is
 *	filled in with its index.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkTextWindowIndex(
    TkText *textPtr,		/* Text widget containing window. */
    const char *name,		/* Name of window. */
    TkTextIndex *indexPtr)	/* Index information gets stored here. */
{
    Tcl_HashEntry *hPtr;
    TkTextSegment *ewPtr;

    if (textPtr == NULL) {
	return TCL_ERROR;
	return 0;
    }

    hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->windowTable, name);
    if (hPtr == NULL) {
	return TCL_ERROR;
	return 0;
    }

    ewPtr = (TkTextSegment *)Tcl_GetHashValue(hPtr);
    ewPtr = Tcl_GetHashValue(hPtr);
    indexPtr->tree = textPtr->sharedTextPtr->tree;
    indexPtr->linePtr = ewPtr->body.ew.linePtr;
    indexPtr->byteIndex = TkTextSegToOffset(ewPtr, indexPtr->linePtr);

    /*
     * If indexPtr refers to somewhere outside the -startline/-endline
     * range limits of the widget, error out since the window indeed is not
     * reachable from this text widget (it may be reachable from a peer).
     */

    if (TkTextIndexAdjustToStartEnd(textPtr, indexPtr, 1) == TCL_ERROR) {
	return TCL_ERROR;
    }

    return TCL_OK;
    return 1;
}

/*
 *--------------------------------------------------------------
 *
 * EmbWinGetClient --
 *

Changes to generic/tkTrig.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







/*
 * tkTrig.c --
 *
 *	This file contains a collection of trigonometry utility routines that
 *	are used by Tk and in particular by the canvas code. It also has
 *	miscellaneous geometry functions used by canvases.
 *
 * Copyright © 1992-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1992-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.
 */

#include "tkInt.h"
#include "tkCanvas.h"
35
36
37
38
39
40
41
42
43
44



45
46
47
48
49
50
51
35
36
37
38
39
40
41



42
43
44
45
46
47
48
49
50
51







-
-
-
+
+
+







 *	None.
 *
 *--------------------------------------------------------------
 */

double
TkLineToPoint(
    double end1Ptr[],		/* Coordinates of first end-point of line. */
    double end2Ptr[],		/* Coordinates of second end-point of line. */
    double pointPtr[])		/* Points to coords for point. */
    double end1Ptr[2],		/* Coordinates of first end-point of line. */
    double end2Ptr[2],		/* Coordinates of second end-point of line. */
    double pointPtr[2])		/* Points to coords for point. */
{
    double x, y;

    /*
     * Compute the point on the line that is closest to the point. This must
     * be done separately for vertical edges, horizontal edges, and other
     * edges.
139
140
141
142
143
144
145
146

147
148

149
150

151
152
153
154
155
156
157
139
140
141
142
143
144
145

146
147

148
149

150
151
152
153
154
155
156
157







-
+

-
+

-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkLineToArea(
    double end1Ptr[],		/* X and y coordinates for one endpoint of
    double end1Ptr[2],		/* X and y coordinates for one endpoint of
				 * line. */
    double end2Ptr[],		/* X and y coordinates for other endpoint of
    double end2Ptr[2],		/* X and y coordinates for other endpoint of
				 * line. */
    double rectPtr[])		/* Points to coords for rectangle, in the
    double rectPtr[4])		/* Points to coords for rectangle, in the
				 * order x1, y1, x2, y2. X1 must be no larger
				 * than x2, and y1 no larger than y2. */
{
    int inside1, inside2;

    /*
     * First check the two points individually to see whether they are inside
278
279
280
281
282
283
284

285
286
287
288
289
290
291
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292







+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
int
TkThickPolyLineToArea(
    double *coordPtr,		/* Points to an array of coordinates for the
				 * polyline: x0, y0, x1, y1, ... */
    int numPoints,		/* Total number of points at *coordPtr. */
    double width,		/* Width of each line segment. */
    int capStyle,		/* How are end-points of polyline drawn?
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450







-
+







{
    double bestDist;		/* Closest distance between point and any edge
				 * in polygon. */
    int intersections;		/* Number of edges in the polygon that
				 * intersect a ray extending vertically
				 * upwards from the point to infinity. */
    int count;
    double *pPtr;
    register double *pPtr;

    /*
     * Iterate through all of the edges in the polygon, updating bestDist and
     * intersections.
     *
     * TRICKY POINT: when computing intersections, include left x-coordinate
     * of line within its range, but not y-coordinate. Otherwise if the point
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
606







-
+







-
+








int
TkPolygonToArea(
    double *polyPtr,		/* Points to an array coordinates for closed
				 * polygon: x0, y0, x1, y1, ... The polygon
				 * may be self-intersecting. */
    int numPoints,		/* Total number of points at *polyPtr. */
    double *rectPtr)	/* Points to coords for rectangle, in the
    register double *rectPtr)	/* Points to coords for rectangle, in the
				 * order x1, y1, x2, y2. X1 and y1 must be
				 * lower-left corner. */
{
    int state;			/* State of all edges seen so far (-1 means
				 * outside, 1 means inside, won't ever be
				 * 0). */
    int count;
    double *pPtr;
    register double *pPtr;

    /*
     * Iterate over all of the edges of the polygon and test them against the
     * rectangle. Can quit as soon as the state becomes "intersecting".
     */

    state = TkLineToArea(polyPtr, polyPtr+2, rectPtr);
647
648
649
650
651
652
653

654
655
656

657
658
659
660
661
662
663

664
665
666
667
668
669
670
648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664

665
666
667
668
669
670
671
672







+


-
+






-
+







 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
double
TkOvalToPoint(
    double ovalPtr[],		/* Pointer to array of four coordinates (x1,
    double ovalPtr[4],		/* Pointer to array of four coordinates (x1,
				 * y1, x2, y2) defining oval's bounding
				 * box. */
    double width,		/* Width of outline for oval. */
    int filled,			/* Non-zero means oval should be treated as
				 * filled; zero means only consider
				 * outline. */
    double pointPtr[])		/* Coordinates of point. */
    double pointPtr[2])		/* Coordinates of point. */
{
    double xDelta, yDelta, scaledDistance, distToOutline, distToCenter;
    double xDiam, yDiam;

    /*
     * Compute the distance between the center of the oval and the point in
     * question, using a coordinate system where the oval has been transformed
745
746
747
748
749
750
751
752

753
754
755
756

757
758
759
760
761
762
763
747
748
749
750
751
752
753

754
755
756
757

758
759
760
761
762
763
764
765







-
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkOvalToArea(
    double *ovalPtr,	/* Points to coordinates defining the
    register double *ovalPtr,	/* Points to coordinates defining the
				 * bounding rectangle for the oval: x1, y1,
				 * x2, y2. X1 must be less than x2 and y1 less
				 * than y2. */
    double *rectPtr)	/* Points to coords for rectangle, in the
    register double *rectPtr)	/* Points to coords for rectangle, in the
				 * order x1, y1, x2, y2. X1 and y1 must be
				 * lower-left corner. */
{
    double centerX, centerY, radX, radY, deltaX, deltaY;

    /*
     * First, see if oval is entirely inside rectangle or entirely outside
861
862
863
864
865
866
867

868
869
870

871
872
873
874
875
876
877
863
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
880







+


-
+







 *
 * Side effects:
 *	The boudn.
 *
 *--------------------------------------------------------------
 */

	/* ARGSUSED */
void
TkIncludePoint(
    Tk_Item *itemPtr,	/* Item whose bounding box is being
    register Tk_Item *itemPtr,	/* Item whose bounding box is being
				 * calculated. */
    double *pointPtr)		/* Address of two doubles giving x and y
				 * coordinates of point. */
{
    int tmp;

    tmp = (int) (pointPtr[0] + 0.5);
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
915
916
917
918
919
920
921

922
923
924
925
926
927
928
929







-
+








void
TkBezierScreenPoints(
    Tk_Canvas canvas,		/* Canvas in which curve is to be drawn. */
    double control[],		/* Array of coordinates for four control
				 * points: x0, y0, x1, y1, ... x3 y3. */
    int numSteps,		/* Number of curve points to generate. */
    XPoint *xPointPtr)	/* Where to put new points. */
    register XPoint *xPointPtr)	/* Where to put new points. */
{
    int i;
    double u, u2, u3, t, t2, t3;

    for (i = 1; i <= numSteps; i++, xPointPtr++) {
	t = ((double) i)/((double) numSteps);
	t2 = t*t;
958
959
960
961
962
963
964
965

966
967
968
969
970
971
972
961
962
963
964
965
966
967

968
969
970
971
972
973
974
975







-
+







 */

void
TkBezierPoints(
    double control[],		/* Array of coordinates for four control
				 * points: x0, y0, x1, y1, ... x3 y3. */
    int numSteps,		/* Number of curve points to generate. */
    double *coordPtr)	/* Where to put new points. */
    register double *coordPtr)	/* Where to put new points. */
{
    int i;
    double u, u2, u3, t, t2, t3;

    for (i = 1; i <= numSteps; i++, coordPtr += 2) {
	t = ((double) i)/((double) numSteps);
	t2 = t*t;

Changes to generic/tkUndo.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkUndo.c --
 *
 *	This module provides the implementation of an undo stack.
 *
 * Copyright © 2002 Ludwig Callewaert.
 * Copyright © 2003-2004 Vincent Darley.
 * Copyright (c) 2002 by Ludwig Callewaert.
 * Copyright (c) 2003-2004 by Vincent Darley.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkUndo.h"
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+







int
TkUndoInsertSeparator(
    TkUndoAtom **stack)
{
    TkUndoAtom *separator;

    if (*stack!=NULL && (*stack)->type!=TK_UNDO_SEPARATOR) {
	separator = (TkUndoAtom *)ckalloc(sizeof(TkUndoAtom));
	separator = ckalloc(sizeof(TkUndoAtom));
	separator->type = TK_UNDO_SEPARATOR;
	TkUndoPushStack(stack,separator);
	return 1;
    }
    return 0;
}

177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191







-
+







TkUndoPushAction(
    TkUndoRedoStack *stack,	/* An Undo or Redo stack */
    TkUndoSubAtom *apply,
    TkUndoSubAtom *revert)
{
    TkUndoAtom *atom;

    atom = (TkUndoAtom *)ckalloc(sizeof(TkUndoAtom));
    atom = ckalloc(sizeof(TkUndoAtom));
    atom->type = TK_UNDO_ACTION;
    atom->apply = apply;
    atom->revert = revert;

    TkUndoPushStack(&stack->undoStack, atom);
    TkUndoClearStack(&stack->redoStack);
}
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+







{
    TkUndoSubAtom *atom;

    if (command == NULL && actionScript == NULL) {
	Tcl_Panic("NULL command and actionScript in TkUndoMakeCmdSubAtom");
    }

    atom = (TkUndoSubAtom *)ckalloc(sizeof(TkUndoSubAtom));
    atom = ckalloc(sizeof(TkUndoSubAtom));
    atom->command = command;
    atom->funcPtr = NULL;
    atom->clientData = NULL;
    atom->next = NULL;
    atom->action = actionScript;
    if (atom->action != NULL) {
        Tcl_IncrRefCount(atom->action);
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309







-
+







{
    TkUndoSubAtom *atom;

    if (funcPtr == NULL) {
	Tcl_Panic("NULL funcPtr in TkUndoMakeSubAtom");
    }

    atom = (TkUndoSubAtom *)ckalloc(sizeof(TkUndoSubAtom));
    atom = ckalloc(sizeof(TkUndoSubAtom));
    atom->command = NULL;
    atom->funcPtr = funcPtr;
    atom->clientData = clientData;
    atom->next = NULL;
    atom->action = actionScript;
    if (atom->action != NULL) {
        Tcl_IncrRefCount(atom->action);
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+







TkUndoRedoStack *
TkUndoInitStack(
    Tcl_Interp *interp,		/* The interpreter */
    int maxdepth)		/* The maximum stack depth */
{
    TkUndoRedoStack *stack;	/* An Undo/Redo stack */

    stack = (TkUndoRedoStack *)ckalloc(sizeof(TkUndoRedoStack));
    stack = ckalloc(sizeof(TkUndoRedoStack));
    stack->undoStack = NULL;
    stack->redoStack = NULL;
    stack->interp = interp;
    stack->maxdepth = maxdepth;
    stack->depth = 0;
    return stack;
}

Changes to generic/tkUndo.h.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkUndo.h --
 *
 *	Declarations shared among the files that implement an undo stack.
 *
 * Copyright © 2002 Ludwig Callewaert.
 * Copyright (c) 2002 Ludwig Callewaert.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKUNDO
#define _TKUNDO
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57







-
+
















-
+







} TkUndoAtomType;

/*
 * Callback proc type to carry out an undo or redo action via C code. (Actions
 * can also be defined by Tcl scripts).
 */

typedef int (TkUndoProc)(Tcl_Interp *interp, void *clientData,
typedef int (TkUndoProc)(Tcl_Interp *interp, ClientData clientData,
			Tcl_Obj *objPtr);

/*
 * Struct defining a single action, one or more of which may be defined (and
 * stored in a linked list) separately for each undo and redo action of an
 * undo atom.
 */

typedef struct TkUndoSubAtom {
    Tcl_Command command;	/* Tcl token used to get the current Tcl
				 * command name which will be used to execute
				 * apply/revert scripts. If NULL then it is
				 * assumed the apply/revert scripts already
				 * contain everything. */
    TkUndoProc *funcPtr;	/* Function pointer for callback to perform
				 * undo/redo actions. */
    void *clientData;	/* Data for 'funcPtr'. */
    ClientData clientData;	/* Data for 'funcPtr'. */
    Tcl_Obj *action;		/* Command to apply the action that was
				 * taken. */
    struct TkUndoSubAtom *next;	/* Pointer to the next element in the linked
				 * list. */
} TkUndoSubAtom;

/*
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+







MODULE_SCOPE void	TkUndoFreeStack(TkUndoRedoStack *stack);
MODULE_SCOPE int	TkUndoCanRedo(TkUndoRedoStack *stack);
MODULE_SCOPE int	TkUndoCanUndo(TkUndoRedoStack *stack);
MODULE_SCOPE void	TkUndoInsertUndoSeparator(TkUndoRedoStack *stack);
MODULE_SCOPE TkUndoSubAtom *TkUndoMakeCmdSubAtom(Tcl_Command command,
			    Tcl_Obj *actionScript, TkUndoSubAtom *subAtomList);
MODULE_SCOPE TkUndoSubAtom *TkUndoMakeSubAtom(TkUndoProc *funcPtr,
			    void *clientData, Tcl_Obj *actionScript,
			    ClientData clientData, Tcl_Obj *actionScript,
			    TkUndoSubAtom *subAtomList);
MODULE_SCOPE void	TkUndoPushAction(TkUndoRedoStack *stack,
			    TkUndoSubAtom *apply, TkUndoSubAtom *revert);
MODULE_SCOPE int	TkUndoRevert(TkUndoRedoStack *stack);
MODULE_SCOPE int	TkUndoApply(TkUndoRedoStack *stack);

#endif /* _TKUNDO */

Changes to generic/tkUtil.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


27
28
29
30

31
32
33
34
35
36
37
38
39
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15




16
17
18
19
20


21
22
23
24
25

26


27
28
29
30
31
32
33






-
-
+
+







-
-
-
-





-
-
+
+



-
+
-
-







/*
 * tkUtil.c --
 *
 *	This file contains miscellaneous utility functions that are used by
 *	the rest of Tk, such as a function for drawing a focus highlight.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * The structure below defines the implementation of the "statekey" Tcl
 * object, used for quickly finding a mapping in a TkStateMap.
 */

const TkObjType tkStateKeyObjType = {
    {"statekey",			/* name */
const Tcl_ObjType tkStateKeyObjType = {
    "statekey",			/* name */
    NULL,			/* freeIntRepProc */
    NULL,			/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL,			/* setFromAnyProc */
    NULL			/* setFromAnyProc */
    TCL_OBJTYPE_V0},
    0
};

/*
 *--------------------------------------------------------------
 *
 * TkStateParseProc --
 *
48
49
50
51
52
53
54
55

56
57

58
59
60

61
62
63
64
65

66

67
68
69
70
71
72
73
42
43
44
45
46
47
48

49
50

51
52
53

54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+

-
+


-
+





+
-
+







 *	value argument.
 *
 *--------------------------------------------------------------
 */

int
TkStateParseProc(
    void *clientData,	/* some flags.*/
    ClientData clientData,	/* some flags.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    int c;
    int flags = PTR2INT(clientData);
    size_t length;
    Tcl_Obj *msgObj;

    Tk_State *statePtr = (Tk_State *) (widgRec + offset);
    register Tk_State *statePtr = (Tk_State *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*statePtr = TK_STATE_NULL;
	return TCL_OK;
    }

    c = value[0];
89
90
91
92
93
94
95
96

97
98
99

100
101
102

103
104

105
106
107
108
109
110
111
84
85
86
87
88
89
90

91
92
93

94
95
96

97
98

99
100
101
102
103
104
105
106







-
+


-
+


-
+

-
+







	*statePtr = TK_STATE_HIDDEN;
	return TCL_OK;
    }

    msgObj = Tcl_ObjPrintf("bad %s value \"%s\": must be normal",
	    ((flags & 4) ? "-default" : "state"), value);
    if (flags & 1) {
	Tcl_AppendToObj(msgObj, ", active", TCL_INDEX_NONE);
	Tcl_AppendToObj(msgObj, ", active", -1);
    }
    if (flags & 2) {
	Tcl_AppendToObj(msgObj, ", hidden", TCL_INDEX_NONE);
	Tcl_AppendToObj(msgObj, ", hidden", -1);
    }
    if (flags & 3) {
	Tcl_AppendToObj(msgObj, ",", TCL_INDEX_NONE);
	Tcl_AppendToObj(msgObj, ",", -1);
    }
    Tcl_AppendToObj(msgObj, " or disabled", TCL_INDEX_NONE);
    Tcl_AppendToObj(msgObj, " or disabled", -1);
    Tcl_SetObjResult(interp, msgObj);
    Tcl_SetErrorCode(interp, "TK", "VALUE", "STATE", NULL);
    *statePtr = TK_STATE_NORMAL;
    return TCL_ERROR;
}

/*
127
128
129
130
131
132
133
134
135


136
137
138


139
140
141
142

143
144
145
146
147
148
149
122
123
124
125
126
127
128


129
130
131


132
133
134
135
136

137
138
139
140
141
142
143
144







-
-
+
+

-
-
+
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

const char *
TkStatePrintProc(
    TCL_UNUSED(void *),	/* Ignored. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset into item. */
    TCL_UNUSED(Tcl_FreeProc **))	/* Pointer to variable to fill in with
    int offset,			/* Offset into item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    Tk_State *statePtr = (Tk_State *) (widgRec + offset);
    register Tk_State *statePtr = (Tk_State *) (widgRec + offset);

    switch (*statePtr) {
    case TK_STATE_NORMAL:
	return "normal";
    case TK_STATE_DISABLED:
	return "disabled";
    case TK_STATE_HIDDEN:
171
172
173
174
175
176
177
178

179
180

181
182
183

184
185
186

187

188
189
190
191
192
193
194
166
167
168
169
170
171
172

173
174

175
176
177

178
179
180
181
182

183
184
185
186
187
188
189
190







-
+

-
+


-
+



+
-
+







 *	indicated in the value argument.
 *
 *--------------------------------------------------------------
 */

int
TkOrientParseProc(
    TCL_UNUSED(void *),	/* some flags.*/
    ClientData clientData,	/* some flags.*/
    Tcl_Interp *interp,		/* Used for reporting errors. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    const char *value,		/* Value of option. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset)			/* Offset into item. */
    int offset)			/* Offset into item. */
{
    int c;
    size_t length;

    int *orientPtr = (int *) (widgRec + offset);
    register int *orientPtr = (int *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*orientPtr = 0;
	return TCL_OK;
    }

    c = value[0];
229
230
231
232
233
234
235
236
237


238
239
240


241
242
243
244

245
246
247
248
249
250
251
225
226
227
228
229
230
231


232
233
234


235
236
237
238
239

240
241
242
243
244
245
246
247







-
-
+
+

-
-
+
+



-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

const char *
TkOrientPrintProc(
    TCL_UNUSED(void *),	/* Ignored. */
    TCL_UNUSED(Tk_Window),		/* Window containing canvas widget. */
    ClientData clientData,	/* Ignored. */
    Tk_Window tkwin,		/* Window containing canvas widget. */
    char *widgRec,		/* Pointer to record for item. */
    Tcl_Size offset,			/* Offset into item. */
    TCL_UNUSED(Tcl_FreeProc **))	/* Pointer to variable to fill in with
    int offset,			/* Offset into item. */
    Tcl_FreeProc **freeProcPtr)	/* Pointer to variable to fill in with
				 * information about how to reclaim storage
				 * for return string. */
{
    int *statePtr = (int *) (widgRec + offset);
    register int *statePtr = (int *) (widgRec + offset);

    if (*statePtr) {
	return "vertical";
    } else {
	return "horizontal";
    }
}
259
260
261
262
263
264
265
266

267
268
269
270
271

272
273
274
275
276
277
278
255
256
257
258
259
260
261

262
263
264
265
266

267
268
269
270
271
272
273
274







-
+




-
+







 *	structure.
 *
 *----------------------------------------------------------------------
 */

int
TkOffsetParseProc(
    void *clientData,	/* not used */
    ClientData clientData,	/* not used */
    Tcl_Interp *interp,		/* Interpreter to send results back to */
    Tk_Window tkwin,		/* Window on same display as tile */
    const char *value,		/* Name of image */
    char *widgRec,		/* Widget structure record */
    Tcl_Size offset)			/* Offset of tile in record */
    int offset)			/* Offset of tile in record */
{
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
    Tk_TSOffset tsoffset;
    const char *q, *p;
    int result;
    Tcl_Obj *msgObj;

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
295
296
297
298
299
300
301

302
303
304
305
306
307
308







-







	case 'n':
	    if (value[2]!='d' || value[3]!='\0') {
		goto badTSOffset;
	    }
	    tsoffset.flags = INT_MAX;
	    goto goodTSOffset;
	}
	break;
    case 'w':
	if (value[1] != '\0') {goto badTSOffset;}
	tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_MIDDLE;
	goto goodTSOffset;
    case 'n':
	if ((value[1] != '\0') && (value[2] != '\0')) {
	    goto badTSOffset;
385
386
387
388
389
390
391
392

393
394
395

396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419


420
421

422
423
424
425
426
427
428
429
430
431
432


433
434
435
436
437
438
439
380
381
382
383
384
385
386

387
388
389

390
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412


413
414
415

416
417
418
419
420
421
422
423
424
425


426
427
428
429
430
431
432
433
434







-
+


-
+

-
+




















-
-
+
+

-
+









-
-
+
+







  goodTSOffset:
    memcpy(offsetPtr, &tsoffset, sizeof(Tk_TSOffset));
    return TCL_OK;

  badTSOffset:
    msgObj = Tcl_ObjPrintf("bad offset \"%s\": expected \"x,y\"", value);
    if (PTR2INT(clientData) & TK_OFFSET_RELATIVE) {
	Tcl_AppendToObj(msgObj, ", \"#x,y\"", TCL_INDEX_NONE);
	Tcl_AppendToObj(msgObj, ", \"#x,y\"", -1);
    }
    if (PTR2INT(clientData) & TK_OFFSET_INDEX) {
	Tcl_AppendToObj(msgObj, ", <index>", TCL_INDEX_NONE);
	Tcl_AppendToObj(msgObj, ", <index>", -1);
    }
    Tcl_AppendToObj(msgObj, ", n, ne, e, se, s, sw, w, nw, or center", TCL_INDEX_NONE);
    Tcl_AppendToObj(msgObj, ", n, ne, e, se, s, sw, w, nw, or center", -1);
    Tcl_SetObjResult(interp, msgObj);
    Tcl_SetErrorCode(interp, "TK", "VALUE", "OFFSET", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkOffsetPrintProc --
 *
 *	Returns the offset of the tile.
 *
 * Results:
 *	The offset of the tile is returned.
 *
 *----------------------------------------------------------------------
 */

const char *
TkOffsetPrintProc(
    TCL_UNUSED(void *),	/* not used */
    TCL_UNUSED(Tk_Window),		/* not used */
    ClientData clientData,	/* not used */
    Tk_Window tkwin,		/* not used */
    char *widgRec,		/* Widget structure record */
    Tcl_Size offset,			/* Offset of tile in record */
    int offset,			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr)	/* not used */
{
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
    char *p, *q;

    if (offsetPtr->flags & TK_OFFSET_INDEX) {
	if (offsetPtr->flags >= INT_MAX) {
	    return "end";
	}
	p = (char *)ckalloc(32);
	snprintf(p, 32, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX);
	p = ckalloc(32);
	sprintf(p, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX);
	*freeProcPtr = TCL_DYNAMIC;
	return p;
    }
    if (offsetPtr->flags & TK_OFFSET_TOP) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
	    return "nw";
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
454
455
456
457
458
459
460
461

462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482

483
484
485
486
487
488

489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
449
450
451
452
453
454
455

456
457
458
459

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482

483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499







-
+



-
+
















-
+





-
+








-
+







	    return "sw";
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
	    return "s";
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
	    return "se";
	}
    }
    q = p = (char *)ckalloc(32);
    q = p = ckalloc(32);
    if (offsetPtr->flags & TK_OFFSET_RELATIVE) {
	*q++ = '#';
    }
    snprintf(q, 32, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset);
    sprintf(q, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset);
    *freeProcPtr = TCL_DYNAMIC;
    return p;
}

/*
 *----------------------------------------------------------------------
 *
 * TkPixelParseProc --
 *
 *	Converts the name of an image into a tile.
 *
 *----------------------------------------------------------------------
 */

int
TkPixelParseProc(
    void *clientData,	/* If non-NULL, negative values are allowed as
    ClientData clientData,	/* If non-NULL, negative values are allowed as
				 * well. */
    Tcl_Interp *interp,		/* Interpreter to send results back to */
    Tk_Window tkwin,		/* Window on same display as tile */
    const char *value,		/* Name of image */
    char *widgRec,		/* Widget structure record */
    Tcl_Size offset)			/* Offset of tile in record */
    int offset)			/* Offset of tile in record */
{
    double *doublePtr = (double *) (widgRec + offset);
    int result;

    result = TkGetDoublePixels(interp, tkwin, value, doublePtr);

    if ((result == TCL_OK) && (clientData == NULL) && (*doublePtr < 0.0)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"expected screen distance but got \"%.50s\"", value));
		"bad screen distance \"%s\"", value));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "PIXELS", NULL);
	return TCL_ERROR;
    }
    return result;
}

/*
512
513
514
515
516
517
518
519
520


521
522

523
524
525
526

527
528
529
530
531
532
533
507
508
509
510
511
512
513


514
515
516

517
518
519
520

521
522
523
524
525
526
527
528







-
-
+
+

-
+



-
+







 *	The name of the tile is returned.
 *
 *----------------------------------------------------------------------
 */

const char *
TkPixelPrintProc(
    TCL_UNUSED(void *),	/* not used */
    TCL_UNUSED(Tk_Window),		/* not used */
    ClientData clientData,	/* not used */
    Tk_Window tkwin,		/* not used */
    char *widgRec,		/* Widget structure record */
    Tcl_Size offset,			/* Offset of tile in record */
    int offset,			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr)	/* not used */
{
    double *doublePtr = (double *) (widgRec + offset);
    char *p = (char *)ckalloc(24);
    char *p = ckalloc(24);

    Tcl_PrintDouble(NULL, *doublePtr, p);
    *freeProcPtr = TCL_DYNAMIC;
    return p;
}

/*
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595







-
+







 *----------------------------------------------------------------------
 *
 * Tk_DrawFocusHighlight --
 *
 *	This function draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus.
 *
 *	This function is now deprecated. Use Tk_DrawHighlightBorder instead,
 *	This function is now deprecated. Use TkpDrawHighlightBorder instead,
 *	since this function does not handle drawing the Focus ring properly on
 *	the Macintosh - you need to know the background GC as well as the
 *	foreground since the Mac focus ring separated from the widget by a 1
 *	pixel border.
 *
 * Results:
 *	None.
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
637
638
639
640
641
642
643

644
645
646
647
648
649
650
651







-
+







 *
 *----------------------------------------------------------------------
 */

int
Tk_GetScrollInfo(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tcl_Size argc,			/* # arguments for command. */
    int argc,			/* # arguments for command. */
    const char **argv,		/* Arguments for command. */
    double *dblPtr,		/* Filled in with argument "moveto" option, if
				 * any. */
    int *intPtr)		/* Filled in with number of pages or lines to
				 * scroll, if any. */
{
    int c = argv[2][0];
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681

682
683
684
685
686
687
688
689
690
691
692
693
694

695
696
697
698
699
700
701
661
662
663
664
665
666
667

668
669
670

671
672
673
674

675
676
677

678
679
680
681
682
683
684
685
686

687
688
689
690
691
692
693
694







-



-
+



-
+


-









-
+







	}
	if (Tcl_GetDouble(interp, argv[3], dblPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	return TK_SCROLL_MOVETO;
    } else if ((c == 's')
	    && (strncmp(argv[2], "scroll", length) == 0)) {
	double d;
	if (argc != 5) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "wrong # args: should be \"%s %s %s\"",
		    argv[0], argv[1], "scroll number pages|units"));
		    argv[0], argv[1], "scroll number units|pages"));
	    Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDouble(interp, argv[3], &d) != TCL_OK) {
	if (Tcl_GetInt(interp, argv[3], intPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	*intPtr = (d > 0) ? ceil(d) : floor(d);
	length = strlen(argv[4]);
	c = argv[4][0];
	if ((c == 'p') && (strncmp(argv[4], "pages", length) == 0)) {
	    return TK_SCROLL_PAGES;
	} else if ((c == 'u') && (strncmp(argv[4], "units", length) == 0)) {
	    return TK_SCROLL_UNITS;
	}

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad argument \"%s\": must be pages or units", argv[4]));
		"bad argument \"%s\": must be units or pages", argv[4]));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "SCROLL_UNITS", NULL);
	return TK_SCROLL_ERROR;
    }
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "unknown option \"%s\": must be moveto or scroll", argv[2]));
    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option", argv[2],
	    NULL);
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741


742
743
744
745

746
747
748

749
750
751
752
753
754
755
756
757
758
759
760
761
762

763
764
765

766
767
768
769
770
771

772
773


774
775
776
777
778
779
780
781

782
783
784
785
786
787
788
718
719
720
721
722
723
724

725
726
727
728
729
730
731



732
733




734

735

736
737
738
739
740
741
742
743
744
745
746
747

748

749
750
751

752
753
754




755


756
757
758
759
760
761
762
763
764

765
766
767
768
769
770
771
772







-
+






-
-
-
+
+
-
-
-
-
+
-

-
+











-

-
+


-
+


-
-
-
-
+
-
-
+
+







-
+







 *
 *----------------------------------------------------------------------
 */

int
Tk_GetScrollInfoObj(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tcl_Size objc,			/* # arguments for command. */
    int objc,			/* # arguments for command. */
    Tcl_Obj *const objv[],	/* Arguments for command. */
    double *dblPtr,		/* Filled in with argument "moveto" option, if
				 * any. */
    int *intPtr)		/* Filled in with number of pages or lines to
				 * scroll, if any. */
{
    Tcl_Size length;
    const char *arg;

    const char *arg = Tcl_GetString(objv[2]);
    size_t length = objv[2]->length;
    if (objc + 1 < 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "moveto|scroll args");
	return TK_SCROLL_ERROR;
    }

    arg = Tcl_GetStringFromObj(objv[2], &length);
#define ArgPfxEq(str) \
	((arg[0] == str[0]) && !strncmp(arg, str, length))
	((arg[0] == str[0]) && !strncmp(arg, str, (unsigned)length))

    if (ArgPfxEq("moveto")) {
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "moveto fraction");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDoubleFromObj(interp, objv[3], dblPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	return TK_SCROLL_MOVETO;
    } else if (ArgPfxEq("scroll")) {
	double d;
	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "scroll number pages|units");
	    Tcl_WrongNumArgs(interp, 2, objv, "scroll number units|pages");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDoubleFromObj(interp, objv[3], &d) != TCL_OK) {
	if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	*intPtr = (d >= 0) ? ceil(d) : floor(d);
	if (dblPtr) {
	    *dblPtr = d;
	}


	arg = Tcl_GetStringFromObj(objv[4], &length);
	arg = Tcl_GetString(objv[4]);
	length = objv[4]->length;
	if (ArgPfxEq("pages")) {
	    return TK_SCROLL_PAGES;
	} else if (ArgPfxEq("units")) {
	    return TK_SCROLL_UNITS;
	}

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad argument \"%s\": must be pages or units", arg));
		"bad argument \"%s\": must be units or pages", arg));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "SCROLL_UNITS", NULL);
	return TK_SCROLL_ERROR;
    }
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "unknown option \"%s\": must be moveto or scroll", arg));
    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option", arg, NULL);
    return TK_SCROLL_ERROR;
827
828
829
830
831
832
833
834
835
836
837
838






839
840
841
842
843
844


845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863






864
865
866
867
868
869


870
871
872
873
874
875
876
811
812
813
814
815
816
817





818
819
820
821
822
823
824
825
826



827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842





843
844
845
846
847
848
849
850
851



852
853
854
855
856
857
858
859
860







-
-
-
-
-
+
+
+
+
+
+



-
-
-
+
+














-
-
-
-
-
+
+
+
+
+
+



-
-
-
+
+







    switch (anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_W:
    case TK_ANCHOR_SW:
	*xPtr = Tk_InternalBorderLeft(tkwin) + padX;
	break;

    case TK_ANCHOR_NE:
    case TK_ANCHOR_E:
    case TK_ANCHOR_SE:
	*xPtr = Tk_Width(tkwin) - Tk_InternalBorderRight(tkwin) - padX
		- innerWidth;
    case TK_ANCHOR_N:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_S:
	*xPtr = (Tk_Width(tkwin) - innerWidth - Tk_InternalBorderLeft(tkwin) -
		Tk_InternalBorderRight(tkwin)) / 2 +
		Tk_InternalBorderLeft(tkwin);
	break;

    default:
	*xPtr = (Tk_Width(tkwin) - innerWidth - Tk_InternalBorderLeft(tkwin) -
		Tk_InternalBorderRight(tkwin)) / 2 +
		Tk_InternalBorderLeft(tkwin);
	*xPtr = Tk_Width(tkwin) - Tk_InternalBorderRight(tkwin) - padX
		- innerWidth;
	break;
    }

    /*
     * Handle the vertical parts.
     */

    switch (anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_N:
    case TK_ANCHOR_NE:
	*yPtr = Tk_InternalBorderTop(tkwin) + padY;
	break;

    case TK_ANCHOR_SW:
    case TK_ANCHOR_S:
    case TK_ANCHOR_SE:
	*yPtr = Tk_Height(tkwin) - Tk_InternalBorderBottom(tkwin) - padY
		- innerHeight;
    case TK_ANCHOR_W:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_E:
	*yPtr = (Tk_Height(tkwin) - innerHeight- Tk_InternalBorderTop(tkwin) -
		Tk_InternalBorderBottom(tkwin)) / 2 +
		Tk_InternalBorderTop(tkwin);
	break;

    default:
	*yPtr = (Tk_Height(tkwin) - innerHeight- Tk_InternalBorderTop(tkwin) -
		Tk_InternalBorderBottom(tkwin)) / 2 +
		Tk_InternalBorderTop(tkwin);
	*yPtr = Tk_Height(tkwin) - Tk_InternalBorderBottom(tkwin) - padY
		- innerHeight;
	break;
    }
}

/*
 *---------------------------------------------------------------------------
 *
974
975
976
977
978
979
980
981

982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982

983
984
985
986
987
988
989
990







-
+

















-
+







    const char *key;
    const Tcl_ObjType *typePtr;

    /*
     * See if the value is in the object cache.
     */

    if ((keyPtr->typePtr == &tkStateKeyObjType.objType)
    if ((keyPtr->typePtr == &tkStateKeyObjType)
	    && (keyPtr->internalRep.twoPtrValue.ptr1 == mapPtr)) {
	return PTR2INT(keyPtr->internalRep.twoPtrValue.ptr2);
    }

    /*
     * Not there. Look in the state map.
     */

    key = Tcl_GetString(keyPtr);
    for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
	if (strcmp(key, mPtr->strKey) == 0) {
	    typePtr = keyPtr->typePtr;
	    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
		typePtr->freeIntRepProc(keyPtr);
	    }
	    keyPtr->internalRep.twoPtrValue.ptr1 = (void *) mapPtr;
	    keyPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(mPtr->numKey);
	    keyPtr->typePtr = &tkStateKeyObjType.objType;
	    keyPtr->typePtr = &tkStateKeyObjType;
	    return mPtr->numKey;
	}
    }

    /*
     * Not there either. Generate an error message (if we can) and return the
     * default.
1042
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
1062
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037

1038

1039
1040
1041
1042
1043
1044
1045







-
+




-
+
-







 *
 * ----------------------------------------------------------------------
 */

int
TkBackgroundEvalObjv(
    Tcl_Interp *interp,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const *objv,
    int flags)
{
    Tcl_InterpState state;
    int r = TCL_OK;
    int n, r = TCL_OK;
    Tcl_Size n;

    /*
     * Record the state of the interpreter.
     */

    Tcl_Preserve(interp);
    state = Tcl_SaveInterpState(interp, TCL_OK);
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124

1125
1126

1127
1128

1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146



1147
1148

1149
1150
1151
1152

1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242
1243



1244
1245


1246
1247
1248















































































1249
1250
1251
1252
1253
1254
1255
1083
1084
1085
1086
1087
1088
1089

1090
1091

1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108

1109
1110

1111
1112
1113
1114

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126



1127
1128
1129
1130

1131
1132
1133
1134

1135
1136

1137
1138
1139
1140
1141
1142




1143
1144

1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161

































1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186
1187


1188
1189
1190


1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281







-
+

-
+














-
+

-
+

-
+



-
+











-
-
-
+
+
+

-
+



-
+

-
+





-
-
-
-


-

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+












-
+




-
+







-
-
+
+
+
-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *
 *----------------------------------------------------------------------
 */

Tcl_Command
TkMakeEnsemble(
    Tcl_Interp *interp,
    const char *namesp,
    const char *namespace,
    const char *name,
    void *clientData,
    ClientData clientData,
    const TkEnsemble map[])
{
    Tcl_Namespace *namespacePtr = NULL;
    Tcl_Command ensemble = NULL;
    Tcl_Obj *dictObj = NULL, *nameObj;
    Tcl_DString ds;
    int i;

    if (map == NULL) {
	return NULL;
    }

    Tcl_DStringInit(&ds);

    namespacePtr = Tcl_FindNamespace(interp, namesp, NULL, 0);
    namespacePtr = Tcl_FindNamespace(interp, namespace, NULL, 0);
    if (namespacePtr == NULL) {
	namespacePtr = Tcl_CreateNamespace(interp, namesp, NULL, NULL);
	namespacePtr = Tcl_CreateNamespace(interp, namespace, NULL, NULL);
	if (namespacePtr == NULL) {
	    Tcl_Panic("failed to create namespace \"%s\"", namesp);
	    Tcl_Panic("failed to create namespace \"%s\"", namespace);
	}
    }

    nameObj = Tcl_NewStringObj(name, TCL_INDEX_NONE);
    nameObj = Tcl_NewStringObj(name, -1);
    ensemble = Tcl_FindEnsemble(interp, nameObj, 0);
    Tcl_DecrRefCount(nameObj);
    if (ensemble == NULL) {
	ensemble = Tcl_CreateEnsemble(interp, name, namespacePtr,
		TCL_ENSEMBLE_PREFIX);
	if (ensemble == NULL) {
	    Tcl_Panic("failed to create ensemble \"%s\"", name);
	}
    }

    Tcl_DStringSetLength(&ds, 0);
    Tcl_DStringAppend(&ds, namesp, TCL_INDEX_NONE);
    if (!(strlen(namesp) == 2 && namesp[1] == ':')) {
	Tcl_DStringAppend(&ds, "::", TCL_INDEX_NONE);
    Tcl_DStringAppend(&ds, namespace, -1);
    if (!(strlen(namespace) == 2 && namespace[1] == ':')) {
	Tcl_DStringAppend(&ds, "::", -1);
    }
    Tcl_DStringAppend(&ds, name, TCL_INDEX_NONE);
    Tcl_DStringAppend(&ds, name, -1);

    dictObj = Tcl_NewObj();
    for (i = 0; map[i].name != NULL ; ++i) {
	Tcl_Obj *fqdnObj;
	Tcl_Obj *nameObj, *fqdnObj;

	nameObj = Tcl_NewStringObj(map[i].name, TCL_INDEX_NONE);
	nameObj = Tcl_NewStringObj(map[i].name, -1);
	fqdnObj = Tcl_NewStringObj(Tcl_DStringValue(&ds),
		Tcl_DStringLength(&ds));
	Tcl_AppendStringsToObj(fqdnObj, "::", map[i].name, NULL);
	Tcl_DictObjPut(NULL, dictObj, nameObj, fqdnObj);
	if (map[i].proc) {
#if TCL_MAJOR_VERSION > 8
	    Tcl_CreateObjCommand2(interp, Tcl_GetString(fqdnObj),
		    map[i].proc, clientData, NULL);
#else
	    Tcl_CreateObjCommand(interp, Tcl_GetString(fqdnObj),
		    map[i].proc, clientData, NULL);
#endif
	} else if (map[i].subensemble) {
	    TkMakeEnsemble(interp, Tcl_DStringValue(&ds),
		    map[i].name, clientData, map[i].subensemble);
	}
    }

    if (ensemble) {
	Tcl_SetEnsembleMappingDict(interp, ensemble, dictObj);
    }

    Tcl_DStringFree(&ds);
    return ensemble;
}

/*
 *----------------------------------------------------------------------
 *
 * TkScalingLevel --
 *
 *	Returns the display's DPI scaling level as 1.0, 1.25, 1.5, ....
 *
 * Results:
 *      The scaling level.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

double
TkScalingLevel(
    Tk_Window tkwin)
{
    Tcl_Interp *interp = Tk_Interp(tkwin);
    Tcl_Obj *scalingPctPtr = Tcl_GetVar2Ex(interp, "::tk::scalingPct", NULL,
	    TCL_GLOBAL_ONLY);
    if (scalingPctPtr == NULL) {
	return 1.0;
    } else {
	int scalingPct;
	Tcl_GetIntFromObj(interp, scalingPctPtr, &scalingPct);
	return scalingPct / 100.0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SendVirtualEvent --
 * TkSendVirtualEvent --
 *
 * 	Send a virtual event notification to the specified target window.
 * 	Equivalent to:
 * 	    "event generate $target <<$eventName>> -data $detail"
 *
 * 	Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent, so this
 * 	routine does not reenter the interpreter.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SendVirtualEvent(
TkSendVirtualEvent(
    Tk_Window target,
    const char *eventName,
    Tcl_Obj *detail)
{
    union {XEvent general; XVirtualEvent virt;} event;
    union {XEvent general; XVirtualEvent virtual;} event;

    memset(&event, 0, sizeof(event));
    event.general.xany.type = VirtualEvent;
    event.general.xany.serial = NextRequest(Tk_Display(target));
    event.general.xany.send_event = False;
    event.general.xany.window = Tk_WindowId(target);
    event.general.xany.display = Tk_Display(target);
    event.virt.name = Tk_GetUid(eventName);
    event.virt.user_data = detail;
    event.virtual.name = Tk_GetUid(eventName);
    if (detail != NULL) {
	event.virtual.user_data = detail;
    if (detail) Tcl_IncrRefCount(detail); // Event code will DecrRefCount

    }

    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
}

#if TCL_UTF_MAX <= 4
/*
 *---------------------------------------------------------------------------
 *
 * TkUtfToUniChar --
 *
 *	Almost the same as Tcl_UtfToUniChar but using int instead of Tcl_UniChar.
 *	This function is capable of collapsing a upper/lower surrogate pair to a
 *	single unicode character. So, up to 6 bytes might be consumed.
 *
 * Results:
 *	*chPtr is filled with the Tcl_UniChar, and the return value is the
 *	number of bytes from the UTF-8 string that were consumed.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int
TkUtfToUniChar(
    const char *src,	/* The UTF-8 string. */
    int *chPtr)		/* Filled with the Tcl_UniChar represented by
			 * the UTF-8 string. */
{
    Tcl_UniChar uniChar = 0;

    int len = Tcl_UtfToUniChar(src, &uniChar);
    if ((uniChar & 0xfc00) == 0xd800) {
	Tcl_UniChar high = uniChar;
	/* This can only happen if Tcl is compiled with TCL_UTF_MAX=4,
	 * or when a high surrogate character is detected in UTF-8 form */
	int len2 = Tcl_UtfToUniChar(src+len, &uniChar);
	if ((uniChar & 0xfc00) == 0xdc00) {
	    *chPtr = (((high & 0x3ff) << 10) | (uniChar & 0x3ff)) + 0x10000;
	    len += len2;
	} else {
	    *chPtr = high;
	}
    } else {
	*chPtr = uniChar;
    }
    return len;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkUniCharToUtf --
 *
 *	Almost the same as Tcl_UniCharToUtf but producing surrogates if
 *	TCL_UTF_MAX==3. So, up to 6 bytes might be produced.
 *
 * Results:
 *	*buf is filled with the UTF-8 string, and the return value is the
 *	number of bytes produced.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int TkUniCharToUtf(int ch, char *buf)
{
    int size = Tcl_UniCharToUtf(ch, buf);
    if ((ch > 0xffff) && (ch <= 0x10ffff) && (size < 4)) {
	/* Hey, this is wrong, we must be running TCL_UTF_MAX==3
	 * The best thing we can do is spit out 2 surrogates */
	ch -= 0x10000;
	size = Tcl_UniCharToUtf(((ch >> 10) | 0xd800), buf);
	size += Tcl_UniCharToUtf(((ch & 0x3ff) | 0xdc00), buf+size);
    }
    return size;
}


#endif
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/tkVisual.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26

27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25

26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45







-
-
+
+













-
-
+
+

-
+











-
+







/*
 * tkVisual.c --
 *
 *	This file contains library procedures for allocating and freeing
 *	visuals and colormaps. This code is based on a prototype
 *	implementation by Paul Mackerras.
 *
 * Copyright © 1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkInt.h"

/*
 * The table below maps from symbolic names for visual classes to the
 * associated X class symbols.
 */

typedef struct VisualDictionary {
    char name[12];		/* Textual name of class. */
    unsigned short minLength;		/* Minimum # characters that must be specified
    const char *name;		/* Textual name of class. */
    int minLength;		/* Minimum # characters that must be specified
				 * for an unambiguous match. */
    short c_class;			/* X symbol for class. */
    int class;			/* X symbol for class. */
} VisualDictionary;
static const VisualDictionary visualNames[] = {
    {"best",		1,	0},
    {"directcolor",	2,	DirectColor},
    {"grayscale",	1,	GrayScale},
    {"greyscale",	1,	GrayScale},
    {"pseudocolor",	1,	PseudoColor},
    {"staticcolor",	7,	StaticColor},
    {"staticgray",	7,	StaticGray},
    {"staticgrey",	7,	StaticGray},
    {"truecolor",	1,	TrueColor},
    {"",		0,	0},
    {NULL,		0,	0},
};

/*
 * One of the following structures exists for each distinct non-default
 * colormap allocated for a display by Tk_GetColormap.
 */

92
93
94
95
96
97
98
99

100
101
102

103
104
105
106
107
108
109
92
93
94
95
96
97
98

99
100
101

102
103
104
105
106
107
108
109







-
+


-
+







				 * here. */
    Colormap *colormapPtr)	/* If non-NULL, then a suitable colormap for
				 * visual is placed here. This colormap must
				 * eventually be freed by calling
				 * Tk_FreeColormap. */
{
    Tk_Window tkwin2;
    XVisualInfo templ, *visInfoList, *bestPtr;
    XVisualInfo template, *visInfoList, *bestPtr;
    long mask;
    Visual *visual;
    size_t length;
    ptrdiff_t length;
    int c, numVisuals, prio, bestPrio, i;
    const char *p;
    const VisualDictionary *dictPtr;
    TkColormap *cmapPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    /*
140
141
142
143
144
145
146
147
148
149
150
151
152
153







154
155
156
157
158
159
160
140
141
142
143
144
145
146







147
148
149
150
151
152
153
154
155
156
157
158
159
160







-
-
-
-
-
-
-
+
+
+
+
+
+
+







			cmapPtr->refCount++;
			break;
		    }
		}
	    }
	    return visual;
	}
	templ.depth = Tk_Depth(tkwin2);
	templ.c_class = visual->c_class;
	templ.red_mask = visual->red_mask;
	templ.green_mask = visual->green_mask;
	templ.blue_mask = visual->blue_mask;
	templ.colormap_size = visual->map_entries;
	templ.bits_per_rgb = visual->bits_per_rgb;
	template.depth = Tk_Depth(tkwin2);
	template.class = visual->class;
	template.red_mask = visual->red_mask;
	template.green_mask = visual->green_mask;
	template.blue_mask = visual->blue_mask;
	template.colormap_size = visual->map_entries;
	template.bits_per_rgb = visual->bits_per_rgb;
	mask = VisualDepthMask|VisualClassMask|VisualRedMaskMask
		|VisualGreenMaskMask|VisualBlueMaskMask|VisualColormapSizeMask
		|VisualBitsPerRGBMask;
    } else if ((c == 0) || ((c == 'd') && (string[1] != 0)
	    && (strncmp(string, "default", strlen(string)) == 0))) {
	/*
	 * Use the default visual for the window's screen.
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196


197
198
199



200
201
202
203

204
205
206
207
208

209
210
211

212
213
214
215
216
217
218
219
220
221


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238

239
240
241
242

243
244
245
246
247
248
249
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194


195
196
197


198
199
200
201
202
203

204
205
206
207
208

209
210
211

212
213
214
215
216
217
218
219
220


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238

239
240
241
242

243
244
245
246
247
248
249
250







-
+













-
-
+
+

-
-
+
+
+



-
+




-
+


-
+








-
-
+
+














-
+

-
+



-
+








	if (Tcl_GetInt(interp, string, &visualId) == TCL_ERROR) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad X identifier for visual: \"%s\"", string));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "VISUALID", NULL);
	    return NULL;
	}
	templ.visualid = visualId;
	template.visualid = visualId;
	mask = VisualIDMask;
    } else {
	/*
	 * Parse the string into a class name (or "best") optionally followed
	 * by whitespace and a depth.
	 */

	for (p = string; *p != 0; p++) {
	    if (isspace(UCHAR(*p)) || isdigit(UCHAR(*p))) {
		break;
	    }
	}
	length = p - string;
	templ.c_class = -1;
	for (dictPtr = visualNames; dictPtr->minLength; dictPtr++) {
	template.class = -1;
	for (dictPtr = visualNames; dictPtr->name != NULL; dictPtr++) {
	    if ((dictPtr->name[0] == c) && (length >= dictPtr->minLength)
		    && (strncmp(string, dictPtr->name, length) == 0)) {
		templ.c_class = dictPtr->c_class;
		    && (strncmp(string, dictPtr->name,
		    (size_t) length) == 0)) {
		template.class = dictPtr->class;
		break;
	    }
	}
	if (templ.c_class == -1) {
	if (template.class == -1) {
	    Tcl_Obj *msgObj = Tcl_ObjPrintf(
		    "unknown or ambiguous visual name \"%s\": class must be ",
		    string);

	    for (dictPtr = visualNames; dictPtr->minLength; dictPtr++) {
	    for (dictPtr = visualNames; dictPtr->name != NULL; dictPtr++) {
		Tcl_AppendPrintfToObj(msgObj, "%s, ", dictPtr->name);
	    }
	    Tcl_AppendToObj(msgObj, "or default", TCL_INDEX_NONE);
	    Tcl_AppendToObj(msgObj, "or default", -1);
	    Tcl_SetObjResult(interp, msgObj);
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "VISUAL", string, NULL);
	    return NULL;
	}
	while (isspace(UCHAR(*p))) {
	    p++;
	}
	if (*p == 0) {
	    templ.depth = 10000;
	} else if (Tcl_GetInt(interp, p, &templ.depth) != TCL_OK) {
	    template.depth = 10000;
	} else if (Tcl_GetInt(interp, p, &template.depth) != TCL_OK) {
	    return NULL;
	}
	if (c == 'b') {
	    mask = 0;
	} else {
	    mask = VisualClassMask;
	}
    }

    /*
     * Find all visuals that match the template we've just created, and return
     * an error if there are none that match.
     */

    templ.screen = Tk_ScreenNumber(tkwin);
    template.screen = Tk_ScreenNumber(tkwin);
    mask |= VisualScreenMask;
    visInfoList = XGetVisualInfo(Tk_Display(tkwin), mask, &templ,
    visInfoList = XGetVisualInfo(Tk_Display(tkwin), mask, &template,
	    &numVisuals);
    if (visInfoList == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"couldn't find an appropriate visual", TCL_INDEX_NONE));
		"couldn't find an appropriate visual", -1));
	Tcl_SetErrorCode(interp, "TK", "VISUAL", "INAPPROPRIATE", NULL);
	return NULL;
    }

    /*
     * Search through the visuals that were returned to find the best one.
     * The choice is based on the following criteria, in decreasing order of
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272







-
+







     * 3. Default: the default visual for the screen gets preference over
     *    other visuals, all else being equal.
     */

    bestPrio = 0;
    bestPtr = NULL;
    for (i = 0; i < numVisuals; i++) {
	switch (visInfoList[i].c_class) {
	switch (visInfoList[i].class) {
	case DirectColor:
	    prio = 5; break;
	case GrayScale:
	    prio = 1; break;
	case PseudoColor:
	    prio = 7; break;
	case StaticColor:
281
282
283
284
285
286
287
288

289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
282
283
284
285
286
287
288

289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338







-
+



-
+
















-
+




















-
+







		== DefaultVisualOfScreen(Tk_Screen(tkwin))) {
	    prio++;
	}
	if (bestPtr == NULL) {
	    goto newBest;
	}
	if (visInfoList[i].depth < bestPtr->depth) {
	    if (visInfoList[i].depth >= templ.depth) {
	    if (visInfoList[i].depth >= template.depth) {
		goto newBest;
	    }
	} else if (visInfoList[i].depth > bestPtr->depth) {
	    if (bestPtr->depth < templ.depth) {
	    if (bestPtr->depth < template.depth) {
		goto newBest;
	    }
	} else {
	    if (prio > bestPrio) {
		goto newBest;
	    }
	}
	continue;

    newBest:
	bestPtr = &visInfoList[i];
	bestPrio = prio;
    }
    CLANG_ASSERT(bestPtr);
    *depthPtr = bestPtr->depth;
    visual = bestPtr->visual;
    XFree(visInfoList);
    XFree((char *) visInfoList);

    /*
     * If we need to find a colormap for this visual, do it now. If the visual
     * is the default visual for the screen, then use the default colormap.
     * Otherwise search for an existing colormap that's shareable. If all else
     * fails, create a new colormap.
     */

    if (colormapPtr != NULL) {
	if (visual == DefaultVisualOfScreen(Tk_Screen(tkwin))) {
	    *colormapPtr = DefaultColormapOfScreen(Tk_Screen(tkwin));
	} else {
	    for (cmapPtr = dispPtr->cmapPtr; cmapPtr != NULL;
		    cmapPtr = cmapPtr->nextPtr) {
		if (cmapPtr->shareable && (cmapPtr->visual == visual)) {
		    *colormapPtr = cmapPtr->colormap;
		    cmapPtr->refCount++;
		    goto done;
		}
	    }
	    cmapPtr = (TkColormap *)ckalloc(sizeof(TkColormap));
	    cmapPtr = ckalloc(sizeof(TkColormap));
	    cmapPtr->colormap = XCreateColormap(Tk_Display(tkwin),
		    RootWindowOfScreen(Tk_Screen(tkwin)), visual,
		    AllocNone);
	    cmapPtr->visual = visual;
	    cmapPtr->refCount = 1;
	    cmapPtr->shareable = 1;
	    cmapPtr->nextPtr = dispPtr->cmapPtr;
378
379
380
381
382
383
384
385

386
387
388
389
390
391
392
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393







-
+







    Tk_Window other;

    /*
     * Allocate a new colormap, if that's what is wanted.
     */

    if (strcmp(string, "new") == 0) {
	cmapPtr = (TkColormap *)ckalloc(sizeof(TkColormap));
	cmapPtr = ckalloc(sizeof(TkColormap));
	cmapPtr->colormap = XCreateColormap(Tk_Display(tkwin),
		RootWindowOfScreen(Tk_Screen(tkwin)), Tk_Visual(tkwin),
		AllocNone);
	cmapPtr->visual = Tk_Visual(tkwin);
	cmapPtr->refCount = 1;
	cmapPtr->shareable = 0;
	cmapPtr->nextPtr = dispPtr->cmapPtr;

Changes to generic/tkWindow.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15

16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47







-
-
+
+






-
+





-


















-
+







/*
 * tkWindow.c --
 *
 *	This file provides basic window-manipulation functions, which are
 *	equivalent to functions in Xlib (and even invoke them) but also
 *	maintain the local Tk_Window structure.
 *
 * Copyright © 1989-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * 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.
 */

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

#ifdef _WIN32
#include "tkWinInt.h"
#elif !defined(MAC_OSX_TK)
#include "tkUnixInt.h"
#endif
#include "tkUuid.h"

/*
 * Type used to keep track of Window objects that were only partially
 * 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 {
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
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
89
90
91
92
93
94
95

96

97
98
99
100
101
102
103
104







-

-
+







 * the C functions that execute them.
 */

#define ISSAFE 1
#define PASSMAINWINDOW 2
#define WINMACONLY 4
#define USEINITPROC 8
#define SAVEUPDATECMD 16 /* better only be one of these! */

typedef int (TkInitProc)(Tcl_Interp *interp, void *clientData);
typedef int (TkInitProc)(Tcl_Interp *interp, ClientData clientData);
typedef struct {
    const char *name;		/* Name of command. */
    Tcl_ObjCmdProc *objProc;	/* Command's object- (or string-) based
				 * function, or initProc. */
    int flags;
} TkCmd;

122
123
124
125
126
127
128
129

130
131

132
133
134
135
136
137
138
120
121
122
123
124
125
126

127
128

129
130
131
132
133
134
135
136







-
+

-
+







    {"image",		Tk_ImageObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"lower",		Tk_LowerObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"option",		Tk_OptionObjCmd,	PASSMAINWINDOW|ISSAFE},
    {"pack",		Tk_PackObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"place",		Tk_PlaceObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"raise",		Tk_RaiseObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"selection",	Tk_SelectionObjCmd,	PASSMAINWINDOW},
    {"tk",		(Tcl_ObjCmdProc *)(void *)TkInitTkCmd,  USEINITPROC|PASSMAINWINDOW|ISSAFE},
    {"tk",		(Tcl_ObjCmdProc *) TkInitTkCmd,  USEINITPROC|PASSMAINWINDOW|ISSAFE},
    {"tkwait",		Tk_TkwaitObjCmd,	PASSMAINWINDOW|ISSAFE},
    {"update",		Tk_UpdateObjCmd,	PASSMAINWINDOW|ISSAFE|SAVEUPDATECMD},
    {"update",		Tk_UpdateObjCmd,	PASSMAINWINDOW|ISSAFE},
    {"winfo",		Tk_WinfoObjCmd,		PASSMAINWINDOW|ISSAFE},
    {"wm",		Tk_WmObjCmd,		PASSMAINWINDOW},

    /*
     * Default widget class commands.
     */

204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216







-
+







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

static Tk_Window	CreateTopLevelWindow(Tcl_Interp *interp,
			    Tk_Window parent, const char *name,
			    const char *screenName, unsigned int flags);
static void		DeleteWindowsExitProc(void *clientData);
static void		DeleteWindowsExitProc(ClientData clientData);
static TkDisplay *	GetScreen(Tcl_Interp *interp, const char *screenName,
			    int *screenPtr);
static int		Initialize(Tcl_Interp *interp);
static int		NameWindow(Tcl_Interp *interp, TkWindow *winPtr,
			    TkWindow *parentPtr, const char *name);
static void		UnlinkWindow(TkWindow *winPtr);

236
237
238
239
240
241
242


243
244
245
246
247
248
249
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249







+
+







 */

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

    TkpCancelWarp(dispPtr);

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

    if (dispPtr->atomInit) {
	Tcl_DeleteHashTable(&dispPtr->nameTable);
312
313
314
315
316
317
318
319
320


321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340


341
342
343


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362

363
364
365
366
367
368
369
312
313
314
315
316
317
318


319
320
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338


339
340



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370







-
-
+
+

-
+
















-
-
+
+
-
-
-
+
+


















+

+







    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. */
{
    TkWindow *winPtr;
    TkDisplay *dispPtr;
    register TkWindow *winPtr;
    register TkDisplay *dispPtr;
    int screenId;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    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(&tkImgFmtDefault);
	Tk_CreatePhotoImageFormatVersion3(&tkImgFmtGIF);
        Tk_CreatePhotoImageFormat(&tkImgFmtDefault);
	Tk_CreatePhotoImageFormat(&tkImgFmtGIF);
	Tk_CreatePhotoImageFormatVersion3(&tkImgFmtPNG);
	Tk_CreatePhotoImageFormat(&tkImgFmtPPM);
	Tk_CreatePhotoImageFormat(&tkImgFmtSVGnano);
	Tk_CreatePhotoImageFormat(&tkImgFmtPNG);
	Tk_CreatePhotoImageFormat(&tkImgFmtPPM);
    }

    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 NULL;
	}
    }

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

    /*
     * Set the flags specified in the call.
     */

#ifdef TK_USE_INPUT_METHODS
    winPtr->ximGeneration = 0;
#endif /*TK_USE_INPUT_METHODS*/
    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.
415
416
417
418
419
420
421
422

423
424
425
426

427
428
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448
449
450


451
452
453
454
455
456
457
416
417
418
419
420
421
422

423
424
425
426

427
428
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448
449


450
451
452
453
454
455
456
457
458







-
+



-
+











-
+










-
-
+
+







static TkDisplay *
GetScreen(
    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. */
{
    TkDisplay *dispPtr;
    register TkDisplay *dispPtr;
    const char *p;
    int screenId;
    size_t length;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    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_SetObjResult(interp, Tcl_NewStringObj(
		"no display name and no $DISPLAY environment variable", TCL_INDEX_NONE));
		"no display name and no $DISPLAY environment variable", -1));
	Tcl_SetErrorCode(interp, "TK", "NO_DISPLAY", NULL);
	return NULL;
    }
    length = strlen(screenName);
    screenId = 0;
    p = screenName+length-1;
    while (isdigit(UCHAR(*p)) && (p != screenName)) {
	p--;
    }
    if ((*p == '.') && (p[1] != '\0')) {
	length = (size_t)(p - screenName);
	screenId = (int)strtoul(p+1, NULL, 10);
	length = p - screenName;
	screenId = strtoul(p+1, NULL, 10);
    }

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

483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498







-
+







	     * Tk_QueueWindowEvent.
	     */

	    dispPtr->flags |= TK_DISPLAY_COLLAPSE_MOTION_EVENTS;

	    Tcl_InitHashTable(&dispPtr->winTable, TCL_ONE_WORD_KEYS);

	    dispPtr->name = (char *)ckalloc(length + 1);
	    dispPtr->name = ckalloc(length + 1);
	    strncpy(dispPtr->name, screenName, length);
	    dispPtr->name[length] = '\0';
	    break;
	}
	if ((strncmp(dispPtr->name, screenName, length) == 0)
		&& (dispPtr->name[length] == '\0')) {
	    break;
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541







-
+







 */

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

    for (dispPtr = tsdPtr->displayList; dispPtr != NULL;
	    dispPtr = dispPtr->nextPtr) {
	if (dispPtr->display == display) {
	    break;
	}
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574







-
+







 *
 *--------------------------------------------------------------
 */

TkDisplay *
TkGetDisplayList(void)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    return tsdPtr->displayList;
}

/*
 *--------------------------------------------------------------
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601







-
+







 *
 *--------------------------------------------------------------
 */

TkMainInfo *
TkGetMainInfoList(void)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    return tsdPtr->mainWindowList;
}
/*
 *--------------------------------------------------------------
 *
616
617
618
619
620
621
622
623

624
625
626
627
628
629
630
617
618
619
620
621
622
623

624
625
626
627
628
629
630
631







-
+







TkAllocWindow(
    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. */
{
    TkWindow *winPtr = (TkWindow *)ckalloc(sizeof(TkWindow));
    register TkWindow *winPtr = 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;
650
651
652
653
654
655
656

657
658

659
660
661

662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
651
652
653
654
655
656
657
658
659
660
661
662
663

664
665
666
667


668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686







+


+


-
+



-
-











+







	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->ximGeneration = 0;
    winPtr->inputContext = NULL;
#endif /* TK_USE_INPUT_METHODS */
    winPtr->tagPtr = NULL;
    winPtr->numTags = 0;
    winPtr->optionLevel = TCL_INDEX_NONE;
    winPtr->optionLevel = -1;
    winPtr->selHandlerList = NULL;
    winPtr->geomMgrPtr = NULL;
    winPtr->geomData = NULL;
    winPtr->geomMgrName = NULL;
    winPtr->maintainerPtr = 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;
    winPtr->geometryMaster = NULL;

    return winPtr;
}

/*
 *----------------------------------------------------------------------
 *
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
697
698
699
700
701
702
703

704
705
706
707
708
709
710
711







-
+







 *
 *----------------------------------------------------------------------
 */

static int
NameWindow(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    TkWindow *winPtr,	/* Window that is to be named and inserted. */
    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];
765
766
767
768
769
770
771
772

773
774
775
776
777
778
779
767
768
769
770
771
772
773

774
775
776
777
778
779
780
781







-
+







     */

    length1 = strlen(parentPtr->pathName);
    length2 = strlen(name);
    if ((length1 + length2 + 2) <= FIXED_SIZE) {
	pathName = staticSpace;
    } else {
	pathName = (char *)ckalloc(length1 + length2 + 2);
	pathName = ckalloc(length1 + length2 + 2);
    }
    if (length1 == 1) {
	pathName[0] = '.';
	strcpy(pathName+1, name);
    } else {
	strcpy(pathName, parentPtr->pathName);
	pathName[length1] = '.';
787
788
789
790
791
792
793
794

795
796
797
798
799
800
801
789
790
791
792
793
794
795

796
797
798
799
800
801
802
803







-
+







    if (!isNew) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window name \"%s\" already exists in parent", name));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "WINDOW", "EXISTS", NULL);
	return TCL_ERROR;
    }
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->pathName = (char *)Tcl_GetHashKey(&parentPtr->mainPtr->nameTable, hPtr);
    winPtr->pathName = Tcl_GetHashKey(&parentPtr->mainPtr->nameTable, hPtr);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkCreateMainWindow --
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841




842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
867
868
869
870
871

872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907
908

909
910
911
912
913
914
915
816
817
818
819
820
821
822





823
824
825
826
827
828
829
830
831
832
833
834




835
836
837
838


839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854

855
856
857
858
859
860
861
862
863
864
865
866

867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882





883
884
885
886
887
888
889
890

891
892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907







-
-
-
-
-












-
-
-
-
+
+
+
+
-
-
+















-
+











-
+















-
-
-
-
-
+







-
+








-
+







 *	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.
 *
 *----------------------------------------------------------------------
 */

#ifndef STRINGIFY
#  define STRINGIFY(x) STRINGIFY1(x)
#  define STRINGIFY1(x) #x
#endif

Tk_Window
TkCreateMainWindow(
    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. */
    const char *baseName)	/* Base name for application; usually of the
				 * form "prog instance". */
{
    Tk_Window tkwin;
    int dummy, isSafe;
    Tcl_HashEntry *hPtr;
    TkMainInfo *mainPtr;
    TkWindow *winPtr;
    const TkCmd *cmdPtr;
    void *clientData;
    register TkMainInfo *mainPtr;
    register TkWindow *winPtr;
    register const TkCmd *cmdPtr;
    ClientData clientData;
    Tcl_CmdInfo info;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    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, NULL, baseName,
    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 = 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;
    mainPtr->alwaysShowSelection = 0;
    mainPtr->tclUpdateObjProc = NULL;
#if TCL_MAJOR_VERSION > 8
    mainPtr->tclUpdateObjProc2 = NULL;
#endif
    if (Tcl_LinkVar(interp, "tk_strictMotif", &mainPtr->strictMotif,
    if (Tcl_LinkVar(interp, "tk_strictMotif", (char *) &mainPtr->strictMotif,
	    TCL_LINK_BOOLEAN) != TCL_OK) {
	Tcl_ResetResult(interp);
    }
    if (Tcl_CreateNamespace(interp, "::tk", NULL, NULL) == NULL) {
	Tcl_ResetResult(interp);
    }
    if (Tcl_LinkVar(interp, "::tk::AlwaysShowSelection",
	    &mainPtr->alwaysShowSelection,
	    (char *) &mainPtr->alwaysShowSelection,
	    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 = (char *)Tcl_GetHashKey(&mainPtr->nameTable, hPtr);
    winPtr->pathName = Tcl_GetHashKey(&mainPtr->nameTable, hPtr);
    Tcl_InitHashTable(&mainPtr->busyTable, TCL_ONE_WORD_KEYS);

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

923
924
925
926
927
928
929
930
931
932
933
934
935
936
937

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
915
916
917
918
919
920
921


922
923
924
925
926

927
928
929
930
931
932
933
934
935
936
937
938
939
940












941

942
943
944
945
946
947
948
949
950
















































































951
952
953
954
955
956
957







-
-





-
+













-
-
-
-
-
-
-
-
-
-
-
-

-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








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

    isSafe = Tcl_IsSafe(interp);
    for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) {
	Tcl_CmdInfo cmdInfo;

	if (cmdPtr->objProc == NULL) {
	    Tcl_Panic("TkCreateMainWindow: builtin command with NULL string and object procs");
	}

#if defined(_WIN32) && !defined(STATIC_BUILD)
	if ((cmdPtr->flags & WINMACONLY) && tclStubsPtr->tcl_CreateFileHandler) {
	if ((cmdPtr->flags & WINMACONLY) && tclStubsPtr->reserved9) {
	    /*
	     * We are running on Cygwin, so don't use the win32 dialogs.
	     */

	    continue;
	}
#endif /* _WIN32 && !STATIC_BUILD */

	if (cmdPtr->flags & PASSMAINWINDOW) {
	    clientData = tkwin;
	} else {
	    clientData = NULL;
	}
	if ((cmdPtr->flags & SAVEUPDATECMD) &&
	    Tcl_GetCommandInfo(interp, cmdPtr->name, &cmdInfo) &&
	    cmdInfo.isNativeObjectProc && !cmdInfo.deleteProc) {
#if TCL_MAJOR_VERSION > 8
	    if ((cmdInfo.isNativeObjectProc == 2) && !cmdInfo.objClientData2) {
		mainPtr->tclUpdateObjProc2 = cmdInfo.objProc2;
	    } else
#endif
	    if (!cmdInfo.objClientData) {
		mainPtr->tclUpdateObjProc = cmdInfo.objProc;
	    }
	}
	if (cmdPtr->flags & USEINITPROC) {
	    ((TkInitProc *)(void *)cmdPtr->objProc)(interp, clientData);
	    ((TkInitProc *) cmdPtr->objProc)(interp, clientData);
	} else {
	    Tcl_CreateObjCommand(interp, cmdPtr->name, cmdPtr->objProc,
		    clientData, NULL);
	}
	if (isSafe && !(cmdPtr->flags & ISSAFE)) {
	    Tcl_HideCommand(interp, cmdPtr->name, cmdPtr->name);
	}
    }
    if (Tcl_GetCommandInfo(interp, "::tcl::build-info", &info)) {
	static const char version[] = TK_PATCH_LEVEL "+" STRINGIFY(TK_VERSION_UUID)
#if defined(MAC_OSX_TK)
		".aqua"
#endif
#if defined(__clang__) && defined(__clang_major__)
		".clang-" STRINGIFY(__clang_major__)
#if __clang_minor__ < 10
		"0"
#endif
		STRINGIFY(__clang_minor__)
#endif
#if defined(__cplusplus) && !defined(__OBJC__)
		".cplusplus"
#endif
#ifndef NDEBUG
		".debug"
#endif
#if !defined(__clang__) && !defined(__INTEL_COMPILER) && defined(__GNUC__)
		".gcc-" STRINGIFY(__GNUC__)
#if __GNUC_MINOR__ < 10
		"0"
#endif
		STRINGIFY(__GNUC_MINOR__)
#endif
#ifdef __INTEL_COMPILER
		".icc-" STRINGIFY(__INTEL_COMPILER)
#endif
#ifdef TCL_MEM_DEBUG
		".memdebug"
#endif
#if defined(_MSC_VER)
		".msvc-" STRINGIFY(_MSC_VER)
#endif
#ifdef USE_NMAKE
		".nmake"
#endif
#ifdef TK_NO_DEPRECATED
		".no-deprecate"
#endif
#ifndef TCL_CFG_OPTIMIZED
		".no-optimize"
#endif
#ifdef __OBJC__
		".objective-c"
#if defined(__cplusplus)
		"plusplus"
#endif
#endif
#ifdef TCL_CFG_PROFILED
		".profile"
#endif
#ifdef PURIFY
		".purify"
#endif
#ifdef STATIC_BUILD
		".static"
#endif
#if defined(_WIN32)
		".win32"
#endif
#if !defined(_WIN32) && !defined(MAC_OSX_TK)
		".x11"
#if !defined(HAVE_XFT)
		".no-xft"
#endif
#endif
		;
#if TCL_MAJOR_VERSION > 8
	if (info.isNativeObjectProc == 2) {
	    Tcl_CreateObjCommand2(interp, "::tk::build-info",
		    info.objProc2, (void *)
		    version, NULL);

	} else
#endif
	Tcl_CreateObjCommand(interp, "::tk::build-info",
		info.objProc, (void *)
		version, NULL);
    }

    /*
     * Set variables for the interpreter.
     */

    Tcl_SetVar2(interp, "tk_patchLevel", NULL, TK_PATCH_LEVEL, TCL_GLOBAL_ONLY);
    Tcl_SetVar2(interp, "tk_version",    NULL, TK_VERSION,     TCL_GLOBAL_ONLY);
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112

1113
1114
1115
1116
1117
1118
1119
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009

1010
1011
1012
1013
1014
1015
1016
1017







-
+





-
+







				 * window. */
{
    TkWindow *parentPtr = (TkWindow *) parent;

    if (parentPtr) {
	if (parentPtr->flags & TK_ALREADY_DEAD) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't create window: parent has been destroyed", TCL_INDEX_NONE));
		    "can't create window: parent has been destroyed", -1));
	    Tcl_SetErrorCode(interp, "TK", "CREATE", "DEAD_PARENT", NULL);
	    return NULL;
	} else if (parentPtr->flags & TK_CONTAINER) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't create window: its parent has -container = yes",
		    TCL_INDEX_NONE));
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "CREATE", "CONTAINER", NULL);
	    return NULL;
	} else if (screenName == NULL) {
	    TkWindow *winPtr = TkAllocWindow(parentPtr->dispPtr,
		    parentPtr->screenNum, parentPtr);

	    if (NameWindow(interp, winPtr, parentPtr, name) != TCL_OK) {
1163
1164
1165
1166
1167
1168
1169
1170

1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081







-
+





-
+







				 * window. */
{
    TkWindow *parentPtr = (TkWindow *) parent;

    if (parentPtr) {
	if (parentPtr->flags & TK_ALREADY_DEAD) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't create window: parent has been destroyed", TCL_INDEX_NONE));
		    "can't create window: parent has been destroyed", -1));
	    Tcl_SetErrorCode(interp, "TK", "CREATE", "DEAD_PARENT", NULL);
	    return NULL;
	} else if (parentPtr->flags & TK_CONTAINER) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't create window: its parent has -container = yes",
		    TCL_INDEX_NONE));
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "CREATE", "CONTAINER", NULL);
	    return NULL;
	} else if (screenName == NULL) {
	    TkWindow *winPtr = TkAllocWindow(parentPtr->dispPtr,
		    parentPtr->screenNum, parentPtr);
	    /*
	     * Add the anonymous window flag now, so that NameWindow will
1234
1235
1236
1237
1238
1239
1240
1241

1242
1243
1244
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258

1259
1260

1261
1262
1263
1264
1265
1266
1267
1268

1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285

1286
1287
1288
1289
1290

1291
1292
1293
1294
1295
1296
1297
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155

1156
1157

1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195







-
+









-
+






-
+

-
+







-
+
















-
+




-
+







				 * 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;
    size_t numChars;
    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 = (char *)strrchr(pathName, '.');
    p = strrchr(pathName, '.');
    if (p == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad window path name \"%s\"", pathName));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "WINDOW_PATH", NULL);
	return NULL;
    }
    numChars = (size_t)(p - pathName);
    numChars = (int) (p-pathName);
    if (numChars > FIXED_SPACE) {
	p = (char *)ckalloc(numChars + 1);
	p = ckalloc(numChars + 1);
    } else {
	p = fixedSpace;
    }
    if (numChars == 0) {
	*p = '.';
	p[1] = '\0';
    } else {
	strncpy(p, pathName, numChars);
	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_SetObjResult(interp, Tcl_NewStringObj(
		"can't create window: parent has been destroyed", TCL_INDEX_NONE));
		"can't create window: parent has been destroyed", -1));
	Tcl_SetErrorCode(interp, "TK", "CREATE", "DEAD_PARENT", NULL);
	return NULL;
    } else if (((TkWindow *) parent)->flags & TK_CONTAINER) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't create window: its parent has -container = yes", TCL_INDEX_NONE));
		"can't create window: its parent has -container = yes", -1));
	Tcl_SetErrorCode(interp, "TK", "CREATE", "CONTAINER", NULL);
	return NULL;
    }

    /*
     * Create the window.
     */
1334
1335
1336
1337
1338
1339
1340
1341

1342
1343
1344
1345

1346
1347
1348
1349
1350
1351
1352
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250







-
+



-
+







 *--------------------------------------------------------------
 */

void
Tk_DestroyWindow(
    Tk_Window tkwin)		/* Window to destroy. */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    XEvent event;
    TkHalfdeadWindow *halfdeadPtr, *prev_halfdeadPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    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.
	 */
1361
1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382
1383
1384
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
1282







-
+








-
+







     */

    if (tsdPtr->halfdeadWindowList &&
	    (tsdPtr->halfdeadWindowList->flags & HD_CLEANUP) &&
	    (tsdPtr->halfdeadWindowList->winPtr == winPtr)) {
	halfdeadPtr = tsdPtr->halfdeadWindowList;
    } else {
	halfdeadPtr = (TkHalfdeadWindow *)ckalloc(sizeof(TkHalfdeadWindow));
	halfdeadPtr = 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 destroyed before we get to the main
     * 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)) {
1451
1452
1453
1454
1455
1456
1457
1458

1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1349
1350
1351
1352
1353
1354
1355

1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366







-
+


-
+







	/*
	 * 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 Tk_GetOtherWindow will return NULL.
	 * deleted, in which case TkpGetOtherWindow will return NULL.
	 */

	TkWindow *childPtr = (TkWindow *)Tk_GetOtherWindow(tkwin);
	TkWindow *childPtr = TkpGetOtherWindow(winPtr);

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

1541
1542
1543
1544
1545
1546
1547
1548

1549
1550
1551
1552

1553
1554

1555
1556
1557

1558
1559
1560
1561
1562
1563
1564
1565
1566



1567
1568
1569
1570
1571
1572
1573
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463



1464
1465
1466
1467
1468
1469
1470
1471
1472
1473







-
+




+

-
+



+






-
-
-
+
+
+







	     * to do an explicit destroy of this X window.
	     */

	    XDestroyWindow(winPtr->display, winPtr->window);
	}
#endif
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->winTable,
		winPtr->window));
		(char *) winPtr->window));
	winPtr->window = None;
    }
    UnlinkWindow(winPtr);
    TkEventDeadWindow(winPtr);
#ifdef TK_USE_INPUT_METHODS
    if (winPtr->inputContext != NULL &&
	winPtr->ximGeneration == winPtr->dispPtr->ximGeneration) {
	    winPtr->ximGeneration == winPtr->dispPtr->ximGeneration) {
	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->geomMgrName != NULL) {
	ckfree(winPtr->geomMgrName);
	winPtr->geomMgrName = NULL;
    if (winPtr->geometryMaster != NULL) {
	ckfree(winPtr->geometryMaster);
	winPtr->geometryMaster = NULL;
    }
    if (winPtr->mainPtr != NULL) {
	if (winPtr->pathName != NULL) {
	    Tk_DeleteAllBindings(winPtr->mainPtr->bindingTable,
		    winPtr->pathName);
	    Tcl_DeleteHashEntry(Tcl_FindHashEntry(&winPtr->mainPtr->nameTable,
		    winPtr->pathName));
1584
1585
1586
1587
1588
1589
1590
1591

1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605

1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1484
1485
1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504

1505
1506












1507



1508






1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527
1528
1529
1530







-
+













-
+

-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-















-







	     * Invalidate all objects referring to windows with the same main
	     * window.
	     */

	    winPtr->mainPtr->deletionEpoch++;
	}
	if (winPtr->mainPtr->refCount-- <= 1) {
	    const TkCmd *cmdPtr;
	    register const 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)) {
		    !Tcl_InterpDeleted(winPtr->mainPtr->interp)) {
		for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) {
		    if (cmdPtr->flags & SAVEUPDATECMD) {
			/* Restore Tcl's version of [update] */
#if TCL_MAJOR_VERSION > 8
			if (winPtr->mainPtr->tclUpdateObjProc2 != NULL) {
			    Tcl_CreateObjCommand2(winPtr->mainPtr->interp,
				    cmdPtr->name,
				    winPtr->mainPtr->tclUpdateObjProc2,
				    NULL, NULL);
			} else
#endif
			if (winPtr->mainPtr->tclUpdateObjProc != NULL) {
			    Tcl_CreateObjCommand(winPtr->mainPtr->interp,
		    Tcl_CreateObjCommand(winPtr->mainPtr->interp, cmdPtr->name,
				    cmdPtr->name,
				    winPtr->mainPtr->tclUpdateObjProc,
				    NULL, NULL);
			    TkDeadAppObjCmd, NULL, NULL);
			}
		    } else {
			Tcl_CreateObjCommand(winPtr->mainPtr->interp,
					     cmdPtr->name, TkDeadAppObjCmd,
					     NULL, NULL);
		    }
		}
		Tcl_CreateObjCommand(winPtr->mainPtr->interp, "send",
			TkDeadAppObjCmd, NULL, NULL);
		Tcl_UnlinkVar(winPtr->mainPtr->interp, "tk_strictMotif");
		Tcl_UnlinkVar(winPtr->mainPtr->interp,
			"::tk::AlwaysShowSelection");
	    }

	    Tcl_DeleteHashTable(&winPtr->mainPtr->busyTable);
	    Tcl_DeleteHashTable(&winPtr->mainPtr->nameTable);
	    TkBindFree(winPtr->mainPtr);
	    TkDeleteAllImages(winPtr->mainPtr);
	    TkFontPkgFree(winPtr->mainPtr);
	    TkFocusFree(winPtr->mainPtr);
	    TkStylePkgFree(winPtr->mainPtr);
	    Ttk_TkDestroyedHandler(winPtr->mainPtr->interp);

	    /*
	     * 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
	     */
1791
1792
1793
1794
1795
1796
1797
1798

1799
1800
1801
1802
1803
1804
1805
1671
1672
1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1685







-
+







 *--------------------------------------------------------------
 */

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

    if (winPtr->window != None) {
1815
1816
1817
1818
1819
1820
1821
1822

1823
1824
1825
1826
1827
1828
1829
1695
1696
1697
1698
1699
1700
1701

1702
1703
1704
1705
1706
1707
1708
1709







-
+







	parent = winPtr->parentPtr->window;
    }

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

    hPtr = Tcl_CreateHashEntry(&winPtr->dispPtr->winTable,
	    (char *) winPtr->window, &isNew);
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->dirtyAtts = 0;
    winPtr->dirtyChanges = 0;
1900
1901
1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
1780
1781
1782
1783
1784
1785
1786

1787
1788
1789
1790
1791
1792
1793
1794







-
+







 *--------------------------------------------------------------
 */

void
Tk_UnmapWindow(
    Tk_Window tkwin)		/* Token for window to unmap. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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
1937
1938
1939
1940
1941
1942
1943
1944

1945
1946
1947
1948
1949
1950
1951
1817
1818
1819
1820
1821
1822
1823

1824
1825
1826
1827
1828
1829
1830
1831







-
+







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

    if (valueMask & CWX) {
	winPtr->changes.x = valuePtr->x;
    }
    if (valueMask & CWY) {
	winPtr->changes.y = valuePtr->y;
    }
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
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







-
+

















-
+

-
-
+
+
















-
+



-
-
+
+















-
+

















-
+


-
+







}

void
Tk_MoveWindow(
    Tk_Window tkwin,		/* Window to move. */
    int x, int y)		/* New location for window (within parent). */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to resize. */
    int width, int height)	/* New dimensions for window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.width = width;
    winPtr->changes.height = height;
    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(
    Tk_Window tkwin,		/* Window to move and resize. */
    int x, int y,		/* New location for window (within parent). */
    int width, int height)	/* New dimensions for window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.x = x;
    winPtr->changes.y = y;
    winPtr->changes.width = width;
    winPtr->changes.height = height;
    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(
    Tk_Window tkwin,		/* Window to modify. */
    int width)			/* New border width for window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to manipulate. */
    unsigned long valueMask,	/* OR'ed combination of bits, indicating which
				 * fields of *attsPtr are to be used. */
    XSetWindowAttributes *attsPtr)
    register XSetWindowAttributes *attsPtr)
				/* New values for some attributes. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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;
    }
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
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







-
+
















-
+

















-
+
















-
+

















-
+

+
+
+

+












-
+







-
+








void
Tk_SetWindowBackground(
    Tk_Window tkwin,		/* Window to manipulate. */
    unsigned long pixel)	/* Pixel value to use for window's
				 * background. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to manipulate. */
    Pixmap pixmap)		/* Pixmap to use for window's background. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to manipulate. */
    unsigned long pixel)	/* Pixel value to use for window's border. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to manipulate. */
    Pixmap pixmap)		/* Pixmap to use for window's border. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin,		/* Window to manipulate. */
    Tk_Cursor cursor)		/* Cursor to use for window (may be None). */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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(
    Tk_Window tkwin)		/* Window to manipulate. */
{
    Tk_DefineCursor(tkwin, NULL);
    Tk_DefineCursor(tkwin, None);
}

void
Tk_SetWindowColormap(
    Tk_Window tkwin,		/* Window to manipulate. */
    Colormap colormap)		/* Colormap to use for window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    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);
2251
2252
2253
2254
2255
2256
2257
2258

2259
2260
2261
2262
2263
2264
2265
2135
2136
2137
2138
2139
2140
2141

2142
2143
2144
2145
2146
2147
2148
2149







-
+







int
Tk_SetWindowVisual(
    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. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

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

    winPtr->visual = visual;
2294
2295
2296
2297
2298
2299
2300
2301

2302
2303
2304
2305
2306
2307
2308
2178
2179
2180
2181
2182
2183
2184

2185
2186
2187
2188
2189
2190
2191
2192







-
+







 *	An event is generated and processed by Tk_HandleEvent.
 *
 *----------------------------------------------------------------------
 */

void
TkDoConfigureNotify(
    TkWindow *winPtr)	/* Window whose configuration was just
    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;
2340
2341
2342
2343
2344
2345
2346
2347

2348
2349
2350
2351
2352
2353
2354
2224
2225
2226
2227
2228
2229
2230

2231
2232
2233
2234
2235
2236
2237
2238







-
+







 */

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

    winPtr->classUid = Tk_GetUid(className);
    if (winPtr->flags & TK_WIN_MANAGED) {
	TkWmSetClass(winPtr);
    }
    TkOptionClassChanged(winPtr);
}
2371
2372
2373
2374
2375
2376
2377
2378

2379
2380

2381
2382
2383
2384
2385
2386
2387
2255
2256
2257
2258
2259
2260
2261

2262
2263

2264
2265
2266
2267
2268
2269
2270
2271







-
+

-
+







 *----------------------------------------------------------------------
 */

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

    winPtr->classProcsPtr = procs;
    winPtr->instanceData = instanceData;
}

/*
 *----------------------------------------------------------------------
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
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







-
+
















-
+







    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.
	 */

	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("NULL main window",TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("NULL main window",-1));
	    Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", NULL);
	}
	return NULL;
    }

    hPtr = Tcl_FindHashEntry(&((TkWindow *) tkwin)->mainPtr->nameTable,
	    pathName);
    if (hPtr == NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad window path name \"%s\"", pathName));
	    Tcl_SetErrorCode(interp, "TK", "LOOKUP", "WINDOW", pathName,
		    NULL);
	}
	return NULL;
    }
    return (Tk_Window)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_IdToWindow --
 *
2474
2475
2476
2477
2478
2479
2480
2481

2482
2483
2484
2485

2486
2487
2488
2489
2490
2491
2492
2358
2359
2360
2361
2362
2363
2364

2365
2366
2367
2368

2369
2370
2371
2372
2373
2374
2375
2376







-
+



-
+







	    break;
	}
    }
    if (window == None) {
	return NULL;
    }

    hPtr = Tcl_FindHashEntry(&dispPtr->winTable, window);
    hPtr = Tcl_FindHashEntry(&dispPtr->winTable, (char *) window);
    if (hPtr == NULL) {
	return NULL;
    }
    return (Tk_Window)Tcl_GetHashValue(hPtr);
    return Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DisplayName --
 *
2736
2737
2738
2739
2740
2741
2742
2743

2744
2745
2746
2747
2748
2749
2750
2751
2752

2753
2754
2755
2756
2757
2758
2759
2620
2621
2622
2623
2624
2625
2626

2627
2628
2629
2630
2631
2632
2633
2634
2635

2636
2637
2638
2639
2640
2641
2642
2643







-
+








-
+







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

    for (mainPtr = tsdPtr->mainWindowList; mainPtr != NULL;
	    mainPtr = mainPtr->nextPtr) {
	if (mainPtr->interp == interp) {
	    return (Tk_Window) mainPtr->winPtr;
	}
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    "this isn't a Tk application", TCL_INDEX_NONE));
	    "this isn't a Tk application", -1));
    Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", NULL);
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+







-
+

















-
+








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

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

    return tsdPtr->numMainWindows;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_AlwaysShowSelection --
 * TkpAlwaysShowSelection --
 *
 *	Indicates whether text/entry widgets should always display
 *	their selection, regardless of window focus.
 *
 * Results:
 *	The return value is 1 if always showing the selection has been
 *	requested for tkwin's application by setting the
 *	::tk::AlwaysShowSelection variable in its interpreter to a true value.
 *	0 is returned if it has a false value.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_AlwaysShowSelection(
TkpAlwaysShowSelection(
    Tk_Window tkwin)		/* Window whose application is to be
				 * checked. */
{
    return ((TkWindow *) tkwin)->mainPtr->alwaysShowSelection;
}

/*
2860
2861
2862
2863
2864
2865
2866
2867

2868
2869
2870
2871

2872
2873
2874
2875
2876
2877
2878
2744
2745
2746
2747
2748
2749
2750

2751
2752
2753
2754

2755
2756
2757
2758
2759
2760
2761
2762







-
+



-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

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

    if (tsdPtr == NULL) {
	return;
    }

    /*
     * Finish destroying any windows that are in a half-dead state. We must
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
2782
2783
2784
2785
2786
2787
2788












2789
2790
2791
2792
2793
2794
2795







-
-
-
-
-
-
-
-
-
-
-
-







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

    /*
     * Let error handlers catch up before actual close of displays.
     * Must be done before tsdPtr->displayList is cleared, otherwise
     * ErrorProc() in tkError.c cannot associate the pending X errors
     * to the remaining error handlers.
     */

    for (dispPtr = tsdPtr->displayList; dispPtr != NULL;
           dispPtr = dispPtr->nextPtr) {
       XSync(dispPtr->display, False);
    }

    /*
     * 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.
     */

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
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







-
+




-
+

-
+




-
+

-
+







-
-
-
+
+
+

-
-
-
+
+
+

-
+
-
-
-
-
+
-

-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
+







    }

    tsdPtr->numMainWindows = 0;
    tsdPtr->mainWindowList = NULL;
    tsdPtr->initialized = 0;
}

#if defined(_WIN32) && !defined(STATIC_BUILD)
#if defined(_WIN32)

static HMODULE tkcygwindll = NULL;

/*
 * Run Tk_MainEx from libtcl9tk9.?.dll
 * Run Tk_MainEx from libtk8.?.dll
 *
 * This function is only ever called from wish9.?.exe, the cygwin port of Tcl.
 * This function is only ever called from wish8.4.exe, the cygwin port of Tcl.
 * This means that the system encoding is utf-8, so we don't have to do any
 * encoding conversions.
 */

MODULE_SCOPE void
int
TkCygwinMainEx(
    Tcl_Size argc,			/* Number of arguments. */
    int argc,			/* Number of arguments. */
    char **argv,		/* Array of argument strings. */
    Tcl_AppInitProc *appInitProc,
				/* Application-specific initialization
				 * procedure to call after most initialization
				 * but before starting to execute commands. */
    Tcl_Interp *interp)
{
    WCHAR name[MAX_PATH];
    size_t len;
    void (*tkmainex)(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *);
    TCHAR name[MAX_PATH];
    int len;
    void (*tkmainex)(int, char **, Tcl_AppInitProc *, Tcl_Interp *);

    /* construct "<path>/libtcl9tk9.?.dll", from "<path>/tcl9tk9?.dll" */
    len = GetModuleFileNameW((HINSTANCE)Tk_GetHINSTANCE(), name, MAX_PATH);
    name[len-2] = '.';
    /* construct "<path>/libtk8.?.dll", from "<path>/tk8?.dll" */
    len = GetModuleFileNameW(Tk_GetHINSTANCE(), name, MAX_PATH);
    name[len-2] = TEXT('.');
    name[len-1] = name[len-5];
    wcscpy(name+len, L".dll");
    _tcscpy(name+len, TEXT(".dll"));
#if TCL_MAJOR_VERSION > 8
    memcpy(name+len-12, L"libtcl9tk9", 10 * sizeof(WCHAR));
#else
    memcpy(name+len-8, L"libtk9", 6 * sizeof(WCHAR));
    memcpy(name+len-8, TEXT("libtk8"), 6 * sizeof(TCHAR));
#endif

    tkcygwindll = LoadLibraryW(name);
    if (tkcygwindll) {
	tkmainex = (void (*)(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *))
		(void *)GetProcAddress(tkcygwindll, "Tk_MainEx");
	if (tkmainex) {
    tkcygwindll = LoadLibrary(name);
    if (!tkcygwindll) {
	/* dll is not present */
	return 0;
    }
    tkmainex = (void (*)(int, char **, Tcl_AppInitProc *, Tcl_Interp *))
	    GetProcAddress(tkcygwindll, "Tk_MainEx");
    if (!tkmainex) {
	    tkmainex(argc, argv, appInitProc, interp);
	}
	return 0;
    }
    }
    tkmainex(argc, argv, appInitProc, interp);
    return 1;
}
#endif /* _WIN32 */

/*
 *----------------------------------------------------------------------
 *
 * Tk_Init --
3014
3015
3016
3017
3018
3019
3020
3021

3022
3023
3024
3025

3026
3027
3028
3029
3030
3031
3032
2886
2887
2888
2889
2890
2891
2892

2893
2894
2895
2896

2897
2898
2899
2900
2901
2902
2903
2904







-
+



-
+







 *----------------------------------------------------------------------
 */

int
Tk_Init(
    Tcl_Interp *interp)		/* Interpreter to initialize. */
{
#if defined(_WIN32) && !defined(STATIC_BUILD)
#if defined(_WIN32)
    if (tkcygwindll) {
	int (*tkinit)(Tcl_Interp *);

	tkinit = (int(*)(Tcl_Interp *))(void *)GetProcAddress(tkcygwindll,"Tk_Init");
	tkinit = (int(*)(Tcl_Interp *)) GetProcAddress(tkcygwindll,"Tk_Init");
	if (tkinit) {
	    return tkinit(interp);
	}
    }
#endif /* _WIN32 */
    return Initialize(interp);
}
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
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







-
+





-
+




-
+







     * - 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.
     *   CPU time limits can be imposed by an unsafe parent interpreter.
     *   CPU time limits can be imposed by an unsafe master interpreter.
     *
     * The actual code called is the same as Tk_Init but Tcl_IsSafe() is
     * checked at several places to differentiate the two initialisations.
     */

#if defined(_WIN32) && !defined(STATIC_BUILD)
#if defined(_WIN32)
    if (tkcygwindll) {
	int (*tksafeinit)(Tcl_Interp *);

	tksafeinit = (int (*)(Tcl_Interp *))
		(void *)GetProcAddress(tkcygwindll, "Tk_SafeInit");
		GetProcAddress(tkcygwindll, "Tk_SafeInit");
	if (tksafeinit) {
	    return tksafeinit(interp);
	}
    }
#endif /* _WIN32 */
    return Initialize(interp);
}
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
3171

3172
3173
3174
3175
3176
3177
3178
3179
3180

3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196

3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210
3211

3212
3213
3214
3215
3216
3217

3218
3219
3220
3221



3222
3223
3224


3225
3226
3227
3228
3229
3230
3231
3232
3233

3234
3235
3236
3237
3238
3239

3240
3241
3242
3243
3244
3245


3246
3247
3248
3249


3250
3251
3252
3253

3254
3255

3256
3257
3258
3259
3260
3261

3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278

3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296

3297
3298
3299
3300
3301
3302
3303
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







-
+

















-












-
+

-
+

-
+

-
+

-
+

-
+








-
+



-
-
-
-
-
-






-
+










-
+



-
+





-
+

-
-
-
+
+
+

-
-
+
+








-
+





-
+




-
-
+
+


-
-
+
+



-
+

-
+





-
+
















-
+

















-
+







 *	Depends on the initialization scripts that are invoked.
 *
 *----------------------------------------------------------------------
 */

static int
CopyValue(
    TCL_UNUSED(void *),
    ClientData dummy,
    Tcl_Obj *objPtr,
    void *dstPtr)
{
    *(Tcl_Obj **)dstPtr = objPtr;
    return 1;
}

static int
Initialize(
    Tcl_Interp *interp)		/* Interpreter to initialize. */
{
    int code = TCL_OK;
    ThreadSpecificData *tsdPtr;
    Tcl_Obj *value = NULL;
    Tcl_Obj *cmd;

    Tcl_Obj *nameObj = NULL;
    Tcl_Obj* appNameObj = NULL;
    Tcl_Obj *classObj = NULL;
    Tcl_Obj *displayObj = NULL;
    Tcl_Obj *colorMapObj = NULL;
    Tcl_Obj *useObj = NULL;
    Tcl_Obj *visualObj = NULL;
    Tcl_Obj *geometryObj = NULL;

    int sync = 0;

    const Tcl_ArgvInfo table[] = {
	{TCL_ARGV_CONSTANT, "-sync", INT2PTR(1), &sync,
		"Use synchronous mode for display server", NULL},
	{TCL_ARGV_FUNC, "-colormap", (void *)CopyValue, &colorMapObj,
	{TCL_ARGV_FUNC, "-colormap", CopyValue, &colorMapObj,
		"Colormap for main window", NULL},
	{TCL_ARGV_FUNC, "-display", (void *)CopyValue, &displayObj,
	{TCL_ARGV_FUNC, "-display", CopyValue, &displayObj,
		"Display to use", NULL},
	{TCL_ARGV_FUNC, "-geometry", (void *)CopyValue, &geometryObj,
	{TCL_ARGV_FUNC, "-geometry", CopyValue, &geometryObj,
		"Initial geometry for window", NULL},
	{TCL_ARGV_FUNC, "-name", (void *)CopyValue, &nameObj,
	{TCL_ARGV_FUNC, "-name", CopyValue, &nameObj,
		"Name to use for application", NULL},
	{TCL_ARGV_FUNC, "-visual", (void *)CopyValue, &visualObj,
	{TCL_ARGV_FUNC, "-visual", CopyValue, &visualObj,
		"Visual for main window", NULL},
	{TCL_ARGV_FUNC, "-use", (void *)CopyValue, &useObj,
	{TCL_ARGV_FUNC, "-use", CopyValue, &useObj,
		"Id of window in which to embed application", NULL},
	TCL_ARGV_AUTO_REST, TCL_ARGV_AUTO_HELP, TCL_ARGV_TABLE_END
    };

    /*
     * Ensure that we are getting a compatible version of Tcl.
     */

    if (Tcl_InitStubs(interp, "8.7-", 0) == NULL) {
    if (Tcl_InitStubs(interp, "8.6-", 0) == NULL) {
	return TCL_ERROR;
    }

    /*
     * TIP #59: Make embedded configuration information available.
     */

    TkInitEmbeddedConfigurationInformation(interp);

    /*
     * Ensure that our obj-types are registered with the Tcl runtime.
     */

    TkRegisterObjTypes();

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

    /*
     * 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
	 * parent.
	 * master.
	 */

	/*
	 * Step 1 : find the parent and construct the interp name (could be a
	 * 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 *parent = interp;
	Tcl_Interp *master = interp;

	while (Tcl_IsSafe(parent)) {
	    parent = Tcl_GetParent(parent);
	    if (parent == NULL) {
	while (Tcl_IsSafe(master)) {
	    master = Tcl_GetMaster(master);
	    if (master == NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"no controlling parent interpreter", TCL_INDEX_NONE));
		Tcl_SetErrorCode(interp, "TK", "SAFE", "NO_PARENT", NULL);
			"no controlling master interpreter", -1));
		Tcl_SetErrorCode(interp, "TK", "SAFE", "NO_MASTER", NULL);
		return TCL_ERROR;
	    }
	}

	/*
	 * Construct the name (rewalk...)
	 */

	code = Tcl_GetInterpPath(parent, interp);
	code = Tcl_GetInterpPath(master, interp);
	if (code != TCL_OK) {
	    Tcl_Panic("Tcl_GetInterpPath broken!");
	}

	/*
	 * Build the command to eval in trusted parent.
	 * Build the command to eval in trusted master.
	 */

	cmd = Tcl_NewListObj(2, NULL);
	Tcl_ListObjAppendElement(NULL, cmd,
		Tcl_NewStringObj("::safe::TkInit", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_GetObjResult(parent));
		Tcl_NewStringObj("::safe::TkInit", -1));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_GetObjResult(master));

	/*
	 * Step 2 : Eval in the parent. The argument is the *reversed* interp
	 * path of the child.
	 * Step 2 : Eval in the master. The argument is the *reversed* interp
	 * path of the slave.
	 */

	Tcl_IncrRefCount(cmd);
	code = Tcl_EvalObjEx(parent, cmd, 0);
	code = Tcl_EvalObjEx(master, cmd, 0);
	Tcl_DecrRefCount(cmd);
	Tcl_TransferResult(parent, code, interp);
	Tcl_TransferResult(master, code, interp);
	if (code != TCL_OK) {
	    return code;
	}

	/*
	 * Use the parent's result as argv. Note: We don't use the Obj
	 * 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.
	 */

	value = Tcl_GetObjResult(interp);
    } 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.
	 */

	value = Tcl_GetVar2Ex(interp, "argv", NULL, TCL_GLOBAL_ONLY);
    }

    if (value) {
	Tcl_Size objc;
	int objc;
	Tcl_Obj **objv, **rest;
	Tcl_Obj *parseList = Tcl_NewListObj(1, NULL);

	Tcl_ListObjAppendElement(NULL, parseList, Tcl_NewObj());

	Tcl_IncrRefCount(value);
	if (TCL_OK != Tcl_ListObjAppendList(interp, parseList, value) ||
	    TCL_OK != Tcl_ListObjGetElements(NULL, parseList, &objc, &objv) ||
	    TCL_OK != Tcl_ParseArgsObjv(interp, table, &objc, objv, &rest)) {
	    Tcl_AddErrorInfo(interp,
		    "\n    (processing arguments in argv variable)");
	    code = TCL_ERROR;
	}
	if (code == TCL_OK) {
	    Tcl_SetVar2Ex(interp, "argv", NULL,
		    Tcl_NewListObj(objc-1, rest+1), TCL_GLOBAL_ONLY);
	    Tcl_SetVar2Ex(interp, "argc", NULL,
		    Tcl_NewWideIntObj(objc-1), TCL_GLOBAL_ONLY);
		    Tcl_NewIntObj(objc-1), TCL_GLOBAL_ONLY);
	    ckfree(rest);
	}
	Tcl_DecrRefCount(parseList);
	if (code != TCL_OK) {
	    goto done;
	}
    }
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330

3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344

3345
3346
3347
3348
3349
3350

3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365

3366
3367
3368
3369
3370

3371
3372
3373
3374
3375

3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386

3387
3388
3389
3390
3391
3392
3393
3394
3395
3396

3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408

3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420

3421
3422
3423
3424
3425


3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3178
3179
3180
3181
3182
3183
3184


3185
3186
3187
3188
3189
3190
3191
3192

3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206

3207
3208
3209
3210
3211
3212

3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227

3228
3229
3230
3231
3232

3233
3234
3235
3236
3237

3238
3239
3240
3241
3242







3243

3244
3245
3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263

3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275

3276
3277
3278



3279
3280



3281
3282
3283
3284
3285
3286
3287







-
-








-
+













-
+





-
+














-
+




-
+




-
+




-
-
-
-
-
-
-
+
-








-
+











-
+











-
+


-
-
-
+
+
-
-
-







    if (nameObj == NULL) {
	Tcl_DString nameDS;

	Tcl_DStringInit(&nameDS);
	TkpGetAppName(interp, &nameDS);
	nameObj = Tcl_NewStringObj(Tcl_DStringValue(&nameDS),
		Tcl_DStringLength(&nameDS));
	appNameObj = nameObj;
	Tcl_IncrRefCount(appNameObj);
	Tcl_DStringFree(&nameDS);
    }

    /*
     * The -class argument is always the ToTitle of the -name
     */

    {
	Tcl_Size numBytes;
	int numBytes;
	const char *bytes = Tcl_GetStringFromObj(nameObj, &numBytes);

	classObj = Tcl_NewStringObj(bytes, numBytes);

	numBytes = Tcl_UtfToTitle(Tcl_GetString(classObj));
	Tcl_SetObjLength(classObj, numBytes);
    }

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

    cmd = Tcl_NewStringObj("toplevel . -class", TCL_INDEX_NONE);
    cmd = Tcl_NewStringObj("toplevel . -class", -1);

    Tcl_ListObjAppendElement(NULL, cmd, classObj);
    classObj = NULL;

    if (displayObj) {
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-screen", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-screen", -1));
	Tcl_ListObjAppendElement(NULL, cmd, displayObj);

	/*
	 * If this is the first application for this process, save the display
	 * name in the DISPLAY environment variable so that it will be
	 * available to subprocesses created by us.
	 */

	if (tsdPtr->numMainWindows == 0) {
	    Tcl_SetVar2Ex(interp, "env", "DISPLAY", displayObj, TCL_GLOBAL_ONLY);
	}
	displayObj = NULL;
    }
    if (colorMapObj) {
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-colormap", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-colormap", -1));
	Tcl_ListObjAppendElement(NULL, cmd, colorMapObj);
	colorMapObj = NULL;
    }
    if (useObj) {
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-use", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-use", -1));
	Tcl_ListObjAppendElement(NULL, cmd, useObj);
	useObj = NULL;
    }
    if (visualObj) {
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-visual", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj("-visual", -1));
	Tcl_ListObjAppendElement(NULL, cmd, visualObj);
	visualObj = NULL;
    }

    Tcl_Size objc;
    Tcl_Obj **objv;

    if (TCL_OK != Tcl_ListObjGetElements(interp, cmd, &objc, &objv)) {
	return TCL_ERROR;
    }
    code = TkCreateFrame(NULL, interp, objc, objv,
    code = TkListCreateFrame(NULL, interp, cmd, 1, nameObj);
	    1, nameObj ? Tcl_GetString(nameObj) : NULL);

    Tcl_DecrRefCount(cmd);

    if (code != TCL_OK) {
	goto done;
    }
    Tcl_ResetResult(interp);
    if (sync) {
	(void)XSynchronize(Tk_Display(Tk_MainWindow(interp)), True);
	XSynchronize(Tk_Display(Tk_MainWindow(interp)), True);
    }

    /*
     * Set the geometry of the main window, if requested. Put the requested
     * geometry into the "geometry" variable.
     */

    if (geometryObj) {

	Tcl_SetVar2Ex(interp, "geometry", NULL, geometryObj, TCL_GLOBAL_ONLY);

	cmd = Tcl_NewStringObj("wm geometry .", TCL_INDEX_NONE);
	cmd = Tcl_NewStringObj("wm geometry .", -1);
	Tcl_ListObjAppendElement(NULL, cmd, geometryObj);
	Tcl_IncrRefCount(cmd);
	code = Tcl_EvalObjEx(interp, cmd, 0);
	Tcl_DecrRefCount(cmd);
	geometryObj = NULL;
	if (code != TCL_OK) {
	    goto done;
	}
    }

    /*
     * Provide "tk" and its stub table.
     * Provide Tk and its stub table.
     */

#ifndef TK_NO_DEPRECATED
    Tcl_PkgProvideEx(interp, "Tk", TK_PATCH_LEVEL,
	    (void *)&tkStubs);
    code = Tcl_PkgProvideEx(interp, "Tk", TK_PATCH_LEVEL,
	    (ClientData) &tkStubs);
#endif
    code = Tcl_PkgProvideEx(interp, "tk", TK_PATCH_LEVEL,
	    (void *)&tkStubs);
    if (code != TCL_OK) {
	goto done;
    }

    /*
     * If we were able to provide ourselves as a package, then set the main
     * loop function in Tcl to our main loop proc. This will cause tclsh to be
3471
3472
3473
3474
3475
3476
3477
3478

3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3323
3324
3325
3326
3327
3328
3329

3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345




3346
3347
3348
3349
3350
3351
3352







-
+















-
-
-
-







"if {[namespace which -command tkInit] eq \"\"} {\n\
  proc tkInit {} {\n\
    global tk_library tk_version tk_patchLevel\n\
      rename tkInit {}\n\
    tcl_findLibrary tk $tk_version $tk_patchLevel tk.tcl TK_LIBRARY tk_library\n\
  }\n\
}\n\
tkInit", TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
tkInit", -1, 0);
    }
    if (code == TCL_OK) {
	/*
	 * Create exit handlers to delete all windows when the application or
	 * thread exits. The handler need to be invoked before other platform
	 * specific cleanups take place to avoid panics in finalization.
	 */

	TkCreateThreadExitHandler(DeleteWindowsExitProc, tsdPtr);
    }
  done:
    if (value) {
	Tcl_DecrRefCount(value);
	value = NULL;
    }
    if (appNameObj) {
	Tcl_DecrRefCount(appNameObj);
	appNameObj = NULL;
    }
    return code;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_PkgInitStubsCheck --
3519
3520
3521
3522
3523
3524
3525
3526

3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538

3539
3540
3541
3542

3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3367
3368
3369
3370
3371
3372
3373

3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385

3386
3387
3388
3389

3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402







-
+











-
+



-
+













const char *
Tk_PkgInitStubsCheck(
    Tcl_Interp *interp,
    const char * version,
    int exact)
{
    const char *actualVersion = Tcl_PkgRequireEx(interp, "tk", version, 0, NULL);
    const char *actualVersion = Tcl_PkgRequireEx(interp, "Tk", version, 0, NULL);

    if (exact && actualVersion) {
	const char *p = version;
	int count = 0;

	while (*p) {
	    count += !isdigit(UCHAR(*p++));
	}
	if (count == 1) {
	    if (0 != strncmp(version, actualVersion, strlen(version))) {
		/* Construct error message */
		Tcl_PkgPresentEx(interp, "tk", version, 1, NULL);
		Tcl_PkgPresentEx(interp, "Tk", version, 1, NULL);
		return NULL;
	    }
	} else {
	    return Tcl_PkgPresentEx(interp, "tk", version, 1, NULL);
	    return Tcl_PkgPresentEx(interp, "Tk", version, 1, NULL);
	}
    }
    return actualVersion;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to generic/ttk/ttk.decls.

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+








-
+







	Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc)
}

declare 5 {
    int Ttk_RegisterElementSpec(
	Ttk_Theme theme,
	const char *elementName,
	const Ttk_ElementSpec *elementSpec,
	Ttk_ElementSpec *elementSpec,
	void *clientData)
}

declare 6 {
    Ttk_ElementClass *Ttk_RegisterElement(
	Tcl_Interp *interp,
	Ttk_Theme theme,
	const char *elementName,
	const Ttk_ElementSpec *elementSpec,
	Ttk_ElementSpec *elementSpec,
	void *clientData)
}

declare 7 {
    int Ttk_RegisterElementFactory(
	Tcl_Interp *interp,
	const char *name,
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82







-
+







}
declare 13 {
    Tcl_Obj *Ttk_StateMapLookup(
	Tcl_Interp *interp, Ttk_StateMap map, Ttk_State state)
}
declare 14 {
    int Ttk_StateTableLookup(
    	const Ttk_StateTable *map, Ttk_State state)
    	Ttk_StateTable map[], Ttk_State state)
}


#
# Low-level geometry utilities.
#
declare 20 {
140
141
142
143
144
145
146
147

148
149
150
140
141
142
143
144
145
146

147
148
149
150







-
+



    Tcl_Obj *Ttk_NewBoxObj(Ttk_Box box)
}

#
# Utilities.
#
declare 40 {
    int Ttk_GetOrientFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Orient *orient)
    int Ttk_GetOrientFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient)
}


Changes to generic/ttk/ttkBlink.c.

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94

95
96

97
98
99
100
101
102
103
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37


38
39

40
41
42
43
44
45
46
47
48
49
50
51

52



53
54

55
56
57
58
59






















60
61
62
63
64
65
66
67
68

69
70

71
72
73
74
75
76
77
78












+
+


-
-
+
+


















-
+
-
-


-












-
+
-
-
-


-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+








-
+

-
+







/*
 * Copyright 2004, Joe English.
 *
 * Usage:
 * 	TtkBlinkCursor(corePtr), usually called in a widget's Init hook,
 * 	arranges to periodically toggle the corePtr->flags CURSOR_ON bit
 * 	on and off (and schedule a redisplay) whenever the widget has focus.
 *
 * 	Note: Widgets may have additional logic to decide whether
 * 	to display the cursor or not (e.g., readonly or disabled states);
 * 	TtkBlinkCursor() does not account for this.
 *
 * TODO:
 * 	Add script-level access to configure application-wide blink rate.
 */

#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

#define DEF_CURSOR_ON_TIME	600		/* milliseconds */
#define DEF_CURSOR_OFF_TIME	300		/* milliseconds */

/* Interp-specific data for tracking cursors:
 */
typedef struct
{
    WidgetCore		*owner; 	/* Widget that currently has cursor */
    Tcl_TimerToken	timer;		/* Blink timer */
    int 		onTime;		/* #milliseconds to blink cursor on */
    int 		offTime;	/* #milliseconds to blink cursor off */
} CursorManager;

/* CursorManagerDeleteProc --
 * 	InterpDeleteProc for cursor manager.
 */
static void CursorManagerDeleteProc(
static void CursorManagerDeleteProc(ClientData clientData, Tcl_Interp *interp)
    void *clientData,
    TCL_UNUSED(Tcl_Interp *))
{
    CursorManager *cm = (CursorManager*)clientData;

    if (cm->timer) {
	Tcl_DeleteTimerHandler(cm->timer);
    }
    ckfree(clientData);
}

/* GetCursorManager --
 * 	Look up and create if necessary the interp's cursor manager.
 */
static CursorManager *GetCursorManager(Tcl_Interp *interp)
{
    static const char *cm_key = "ttk::CursorManager";
    CursorManager *cm = (CursorManager *)Tcl_GetAssocData(interp, cm_key,0);
    CursorManager *cm = Tcl_GetAssocData(interp, cm_key,0);
    Tk_Window window;
    Tk_Uid value;
    int intValue;

    if (!cm) {
	cm = (CursorManager *)ckalloc(sizeof(*cm));
	cm = ckalloc(sizeof(*cm));
	cm->timer = 0;
	cm->owner = 0;
	cm->onTime = DEF_CURSOR_ON_TIME;
	cm->offTime = DEF_CURSOR_OFF_TIME;

	/* Override on and off default times with values obtained from
	 * the option database (if such values are specified).
	 */

	window = Tk_MainWindow(interp);
	if (window) {
	    value = Tk_GetOption(window, "insertOnTime", "OnTime");
	    if (value) {
		if (Tcl_GetInt(interp, value, &intValue) == TCL_OK) {
		    cm->onTime = intValue;
		}
	    }
	    value = Tk_GetOption(window, "insertOffTime", "OffTime");
	    if (value) {
		if (Tcl_GetInt(interp, value, &intValue) == TCL_OK) {
		    cm->offTime = intValue;
		}
	    }
	}

	Tcl_SetAssocData(interp, cm_key, CursorManagerDeleteProc, cm);
	Tcl_SetAssocData(interp,cm_key,CursorManagerDeleteProc,(ClientData)cm);
    }
    return cm;
}

/* CursorBlinkProc --
 *	Timer handler to blink the insert cursor on and off.
 */
static void
CursorBlinkProc(void *clientData)
CursorBlinkProc(ClientData clientData)
{
    CursorManager *cm = (CursorManager *)clientData;
    CursorManager *cm = (CursorManager*)clientData;
    int blinkTime;

    if (cm->owner->flags & CURSOR_ON) {
	cm->owner->flags &= ~CURSOR_ON;
	blinkTime = cm->offTime;
    } else {
	cm->owner->flags |= CURSOR_ON;
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139







-
+







 */

#define CursorEventMask (FocusChangeMask|StructureNotifyMask)
#define RealFocusEvent(d) \
    (d == NotifyInferior || d == NotifyAncestor || d == NotifyNonlinear)

static void
CursorEventProc(void *clientData, XEvent *eventPtr)
CursorEventProc(ClientData clientData, XEvent *eventPtr)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    CursorManager *cm = GetCursorManager(corePtr->interp);

    switch (eventPtr->type) {
	case DestroyNotify:
	    if (cm->owner == corePtr)
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
148
149
150
151
152
153
154











































155
156
157
158
159
160
161
162
163
164
165
166







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












	case FocusOut:
	    if (RealFocusEvent(eventPtr->xfocus.detail))
		LoseCursor(cm, corePtr);
	    break;
    }
}

void TtkSetBlinkCursorOnTime(Tcl_Interp* interp, int onTime)
{
    CursorManager* cm = GetCursorManager(interp);

    if (onTime >= 0)
	cm->onTime = onTime;
}

void TtkSetBlinkCursorOffTime(Tcl_Interp* interp, int offTime)
{
    CursorManager* cm = GetCursorManager(interp);

    if (offTime >= 0)
	cm->offTime = offTime;
}

/*
 * TtkSetBlinkCursorTimes --
 * 	Set cursor blink on and off times from the "." style defaults
 * 	-insertontime and -insertofftime - For instance to set cursor
 * 	blinking off:
 * 	    ttk::style configure . -insertofftime 0
 */
void TtkSetBlinkCursorTimes(Tcl_Interp* interp)
{
    Ttk_Theme theme;
    Ttk_Style style = NULL;
    Tcl_Obj* result;
    int timeInterval;

    theme = Ttk_GetCurrentTheme(interp);
    style = Ttk_GetStyle(theme, ".");
    result = Ttk_StyleDefault(style, "-insertontime");
    if (result) {
	Tcl_GetIntFromObj(interp, result, &timeInterval);
	TtkSetBlinkCursorOnTime(interp, timeInterval);
    }
    result = Ttk_StyleDefault(style, "-insertofftime");
    if (result) {
	Tcl_GetIntFromObj(interp, result, &timeInterval);
	TtkSetBlinkCursorOffTime(interp, timeInterval);
    }
}
/*
 * TtkBlinkCursor (main routine) --
 * 	Arrange to blink the cursor on and off whenever the
 * 	widget has focus.
 */
void TtkBlinkCursor(WidgetCore *corePtr)
{
    Tk_CreateEventHandler(
	corePtr->tkwin, CursorEventMask, CursorEventProc, corePtr);
}

/*EOF*/

Changes to generic/ttk/ttkButton.c.

1
2

3
4
5
6

7
8


9
10
11
12
13
14
15
1

2
3
4
5
6
7


8
9
10
11
12
13
14
15
16

-
+




+
-
-
+
+







/*
 * Copyright © 2003, Joe English
 * Copyright (c) 2003, Joe English
 *
 * label, button, checkbutton, radiobutton, and menubutton widgets.
 */

#include <string.h>
#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

/* Bit fields for OptionSpec mask field:
 */
#define STATE_CHANGED	 	(0x100)		/* -state option changed */
#define DEFAULTSTATE_CHANGED	(0x200)		/* -default option changed */

50
51
52
53
54
55
56
57

58
59
60
61


62
63

64
65
66

67
68
69




70
71

72
73
74
75
76
77
78

79
80
81
82
83
84
85

86
87

88
89

90
91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128

129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147


148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
51
52
53
54
55
56
57

58
59
60


61
62
63

64
65
66

67
68


69
70
71
72
73

74
75
76
77
78
79
80

81
82
83
84
85
86
87

88


89
90

91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

126


127

128

129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144


145
146





147
148

149
150
151
152
153

154
155
156
157
158
159
160
161







-
+


-
-
+
+

-
+


-
+

-
-
+
+
+
+

-
+






-
+






-
+
-
-
+

-
+






-
-
+
+









-
+
















-
+
-
-

-
+
-







-
+








-
-
+
+
-
-
-
-
-


-





-
+








typedef struct
{
    WidgetCore	core;
    BasePart	base;
} Base;

static const Tk_OptionSpec BaseOptionSpecs[] =
static Tk_OptionSpec BaseOptionSpecs[] =
{
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	"left", offsetof(Base,base.justifyObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
        "left", Tk_Offset(Base,base.justifyObj), -1,
        TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-text", "text", "Text", "",
	offsetof(Base,base.textObj), TCL_INDEX_NONE,
	Tk_Offset(Base,base.textObj), -1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable", "",
	offsetof(Base,base.textVariableObj), TCL_INDEX_NONE,
	Tk_Offset(Base,base.textVariableObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TTK_OPTION_UNDERLINE_DEF(Base, base.underlineObj), 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	"-1", Tk_Offset(Base,base.underlineObj), -1,
	0,0,0 },
    /* SB: OPTION_INT, see <<NOTE-NULLOPTIONS>> */
    {TK_OPTION_STRING, "-width", "width", "Width",
	NULL, offsetof(Base,base.widthObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Base,base.widthObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    /*
     * Image options
     */
    {TK_OPTION_STRING, "-image", "image", "Image", NULL/*default*/,
	offsetof(Base,base.imageObj), TCL_INDEX_NONE,
	Tk_Offset(Base,base.imageObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    /*
     * Compound base/image options
     */
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	NULL, offsetof(Base,base.compoundObj), TCL_INDEX_NONE,
	 "none", Tk_Offset(Base,base.compoundObj), -1,
	TK_OPTION_NULL_OK, ttkCompoundStrings,
	GEOMETRY_CHANGED },
	 0,(ClientData)ttkCompoundStrings,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-padding", "padding", "Pad",
	NULL, offsetof(Base,base.paddingObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Base,base.paddingObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED},

    /*
     * Compatibility/legacy options
     */
    {TK_OPTION_STRING, "-state", "state", "State",
	"normal", offsetof(Base,base.stateObj), TCL_INDEX_NONE,
	0,0,STATE_CHANGED },
	 "normal", Tk_Offset(Base,base.stateObj), -1,
	 0,0,STATE_CHANGED },

    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*
 * Variable trace procedure for -textvariable option:
 */
static void TextVariableChanged(void *clientData, const char *value)
{
    Base *basePtr = (Base *)clientData;
    Base *basePtr = clientData;
    Tcl_Obj *newText;

    if (WidgetDestroyed(&basePtr->core)) {
	return;
    }

    newText = value ? Tcl_NewStringObj(value, -1) : Tcl_NewStringObj("", 0);

    Tcl_IncrRefCount(newText);
    Tcl_DecrRefCount(basePtr->base.textObj);
    basePtr->base.textObj = newText;

    TtkResizeWidget(&basePtr->core);
}

static void
BaseInitialize(
BaseInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Base *basePtr = (Base *)recordPtr;
    Base *basePtr = recordPtr;

    basePtr->base.textVariableTrace = 0;
    basePtr->base.imageSpec = NULL;
}

static void
BaseCleanup(void *recordPtr)
{
    Base *basePtr = (Base *)recordPtr;
    Base *basePtr = recordPtr;
    if (basePtr->base.textVariableTrace)
	Ttk_UntraceVariable(basePtr->base.textVariableTrace);
    if (basePtr->base.imageSpec)
    	TtkFreeImageSpec(basePtr->base.imageSpec);
}

static void
BaseImageChanged(
    void *clientData,
    TCL_UNUSED(int),
	ClientData clientData, int x, int y, int width, int height,
	int imageWidth, int imageHeight)
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    Base *basePtr = (Base *)clientData;

    TtkResizeWidget(&basePtr->core);
}

static int BaseConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Base *basePtr = (Base *)recordPtr;
    Base *basePtr = recordPtr;
    Tcl_Obj *textVarName = basePtr->base.textVariableObj;
    Ttk_TraceHandle *vt = 0;
    Ttk_ImageSpec *imageSpec = NULL;

    if (textVarName != NULL && *Tcl_GetString(textVarName) != '\0') {
	vt = Ttk_TraceVariable(interp,textVarName,TextVariableChanged,basePtr);
	if (!vt) return TCL_ERROR;
197
198
199
200
201
202
203
204

205
206
207
208
209

210
211
212
213
214
215
216
190
191
192
193
194
195
196

197



198

199
200
201
202
203
204
205
206







-
+
-
-
-

-
+







	TtkCheckStateOption(&basePtr->core, basePtr->base.stateObj);
    }

    return TCL_OK;
}

static int
BasePostConfigure(
BasePostConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr,
    TCL_UNUSED(int))
{
    Base *basePtr = (Base *)recordPtr;
    Base *basePtr = recordPtr;
    int status = TCL_OK;

    if (basePtr->base.textVariableTrace) {
	status = Ttk_FireTrace(basePtr->base.textVariableTrace);
    }

    return status;
236
237
238
239
240
241
242
243

244
245
246

247
248
249

250
251
252

253
254
255

256
257
258

259
260
261
262


263
264
265


266
267

268
269
270
271
272
273
274
275
276
277

278
279
280

281
282
283
284

285
286
287
288
289
290
291
226
227
228
229
230
231
232

233
234
235

236
237
238

239
240
241

242
243
244

245
246
247

248
249
250


251
252
253


254
255
256

257
258
259
260
261
262
263
264

265

266
267
268

269
270
271
272

273
274
275
276
277
278
279
280







-
+


-
+


-
+


-
+


-
+


-
+


-
-
+
+

-
-
+
+

-
+







-

-
+


-
+



-
+







typedef struct
{
    WidgetCore	core;
    BasePart	base;
    LabelPart	label;
} Label;

static const Tk_OptionSpec LabelOptionSpecs[] =
static Tk_OptionSpec LabelOptionSpecs[] =
{
    {TK_OPTION_BORDER, "-background", "frameColor", "FrameColor",
	NULL, offsetof(Label,label.backgroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label,label.backgroundObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
	NULL, offsetof(Label,label.foregroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label,label.foregroundObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_FONT, "-font", "font", "Font",
	NULL, offsetof(Label,label.fontObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label,label.fontObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
	NULL, offsetof(Label,label.borderWidthObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label,label.borderWidthObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
	NULL, offsetof(Label,label.reliefObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label,label.reliefObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	"w", offsetof(Label,label.anchorObj), TCL_INDEX_NONE,
	0, 0, GEOMETRY_CHANGED},
	NULL, Tk_Offset(Label,label.anchorObj), -1,
	TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	"left", offsetof(Label, label.justifyObj), TCL_INDEX_NONE,
	0,0,GEOMETRY_CHANGED },
	NULL, Tk_Offset(Label, label.justifyObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	NULL, offsetof(Label, label.wrapLengthObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Label, label.wrapLengthObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED /*SB: SIZE_CHANGED*/ },

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(BaseOptionSpecs)
};

static const Ttk_Ensemble LabelCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec LabelWidgetSpec =
static WidgetSpec LabelWidgetSpec =
{
    "TLabel",			/* className */
    sizeof(Label),		/* recordSize */
    LabelOptionSpecs,		/* optionSpecs */
    LabelCommands,		/* subcommands */
    BaseInitialize,		/* initializeProc */
    BaseCleanup,		/* cleanupProc */
320
321
322
323
324
325
326
327

328
329
330

331
332
333


334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

368
369

370
371
372
373
374
375
376
377
378
379
380
381
382

383

384
385
386
387

388
389
390
391

392
393
394
395
396
397
398
309
310
311
312
313
314
315

316
317
318

319
320


321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

356
357

358
359
360
361
362
363
364
365
366
367
368
369

370
371

372
373

374

375
376
377
378

379
380
381
382
383
384
385
386







-
+


-
+

-
-
+
+







-
+








-
+
















-
+

-
+











-

+
-
+

-

-
+



-
+







    BasePart	base;
    ButtonPart	button;
} Button;

/*
 * Option specifications:
 */
static const Tk_OptionSpec ButtonOptionSpecs[] =
static Tk_OptionSpec ButtonOptionSpecs[] =
{
    {TK_OPTION_STRING, "-command", "command", "Command",
	"", offsetof(Button, button.commandObj), TCL_INDEX_NONE, 0,0,0},
	"", Tk_Offset(Button, button.commandObj), -1, 0,0,0},
    {TK_OPTION_STRING_TABLE, "-default", "default", "Default",
	"normal", offsetof(Button, button.defaultStateObj), TCL_INDEX_NONE,
	0, ttkDefaultStrings, DEFAULTSTATE_CHANGED},
	"normal", Tk_Offset(Button, button.defaultStateObj), -1,
	0, (ClientData) ttkDefaultStrings, DEFAULTSTATE_CHANGED},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(BaseOptionSpecs)
};

static int ButtonConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Button *buttonPtr = (Button *)recordPtr;
    Button *buttonPtr = recordPtr;

    if (BaseConfigure(interp, recordPtr, mask) != TCL_OK) {
	return TCL_ERROR;
    }

    /* Handle "-default" option:
     */
    if (mask & DEFAULTSTATE_CHANGED) {
	Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
	int defaultState = TTK_BUTTON_DEFAULT_DISABLED;
	Ttk_GetButtonDefaultStateFromObj(
	    NULL, buttonPtr->button.defaultStateObj, &defaultState);
	if (defaultState == TTK_BUTTON_DEFAULT_ACTIVE) {
	    TtkWidgetChangeState(&buttonPtr->core, TTK_STATE_ALTERNATE, 0);
	} else {
	    TtkWidgetChangeState(&buttonPtr->core, 0, TTK_STATE_ALTERNATE);
	}
    }
    return TCL_OK;
}

/* $button invoke --
 * 	Evaluate the button's -command.
 */
static int
ButtonInvokeCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Button *buttonPtr = (Button *)recordPtr;
    Button *buttonPtr = recordPtr;
    if (objc > 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "invoke");
	return TCL_ERROR;
    }
    if (buttonPtr->core.state & TTK_STATE_DISABLED) {
	return TCL_OK;
    }
    return Tcl_EvalObjEx(interp, buttonPtr->button.commandObj, TCL_EVAL_GLOBAL);
}

static const Ttk_Ensemble ButtonCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "invoke",		ButtonInvokeCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "invoke",		ButtonInvokeCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec ButtonWidgetSpec =
static WidgetSpec ButtonWidgetSpec =
{
    "TButton",			/* className */
    sizeof(Button),		/* recordSize */
    ButtonOptionSpecs,		/* optionSpecs */
    ButtonCommands,		/* subcommands */
    BaseInitialize,		/* initializeProc */
    BaseCleanup,		/* cleanupProc */
431
432
433
434
435
436
437
438

439
440
441

442
443
444

445
446
447

448
449
450

451
452
453
454
455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
419
420
421
422
423
424
425

426
427
428

429
430
431

432
433
434

435
436
437

438
439
440
441
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457







-
+


-
+


-
+


-
+


-
+











-
+







    BasePart base;
    CheckbuttonPart checkbutton;
} Checkbutton;

/*
 * Option specifications:
 */
static const Tk_OptionSpec CheckbuttonOptionSpecs[] =
static Tk_OptionSpec CheckbuttonOptionSpecs[] =
{
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	NULL, offsetof(Checkbutton, checkbutton.variableObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Checkbutton, checkbutton.variableObj), -1,
	TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-onvalue", "onValue", "OnValue",
	"1", offsetof(Checkbutton, checkbutton.onValueObj), TCL_INDEX_NONE,
	"1", Tk_Offset(Checkbutton, checkbutton.onValueObj), -1,
	0,0,0},
    {TK_OPTION_STRING, "-offvalue", "offValue", "OffValue",
	"0", offsetof(Checkbutton, checkbutton.offValueObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Checkbutton, checkbutton.offValueObj), -1,
	0,0,0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	"", offsetof(Checkbutton, checkbutton.commandObj), TCL_INDEX_NONE,
	"", Tk_Offset(Checkbutton, checkbutton.commandObj), -1,
	0,0,0},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(BaseOptionSpecs)
};

/*
 * Variable trace procedure for checkbutton -variable option
 */
static void CheckbuttonVariableChanged(void *clientData, const char *value)
{
    Checkbutton *checkPtr = (Checkbutton *)clientData;
    Checkbutton *checkPtr = clientData;

    if (WidgetDestroyed(&checkPtr->core)) {
	return;
    }

    if (!value) {
	TtkWidgetChangeState(&checkPtr->core, TTK_STATE_ALTERNATE, 0);
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507

508
509
510


511
512
513
514
515




516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578




579
580
581
582
583
584
585
586
587
588
589
590
591
592

593

594
595

596
597
598
599
600

601
602
603
604
605
606
607
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493
494

495



496
497





498
499
500
501

502
503
504
505
506
507
508


509

510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533

534
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554







555
556
557
558
559
560
561
562
563
564
565
566
567
568

569


570
571
572
573

574
575
576
577
578

579
580
581
582
583
584
585
586







-
+













-
+








-
+
-
-
-
+
+
-
-
-
-
-
+
+
+
+
-







-
-
+
-








-
+















-
+

-
+


















-
-
-
-
-
-
-
+
+
+
+










-

-
-
+

+

-
+




-
+







	TtkWidgetChangeState(&checkPtr->core, 0, TTK_STATE_SELECTED);
    }
}

static void
CheckbuttonInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Checkbutton *checkPtr = (Checkbutton *)recordPtr;
    Checkbutton *checkPtr = recordPtr;
    Tcl_Obj *variableObj;

    /* default -variable is the widget name:
     */
    variableObj = Tcl_NewStringObj(Tk_PathName(checkPtr->core.tkwin), -1);
    Tcl_IncrRefCount(variableObj);
    checkPtr->checkbutton.variableObj = variableObj;
    BaseInitialize(interp, recordPtr);
}

static void
CheckbuttonCleanup(void *recordPtr)
{
    Checkbutton *checkPtr = (Checkbutton *)recordPtr;
    Checkbutton *checkPtr = recordPtr;
    Ttk_UntraceVariable(checkPtr->checkbutton.variableTrace);
    checkPtr->checkbutton.variableTrace = 0;
    BaseCleanup(recordPtr);
}

static int
CheckbuttonConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Checkbutton *checkPtr = (Checkbutton *)recordPtr;
    Checkbutton *checkPtr = recordPtr;
    Tcl_Obj *varName = checkPtr->checkbutton.variableObj;
    Ttk_TraceHandle *vt = NULL;

    Ttk_TraceHandle *vt = Ttk_TraceVariable(
	interp, checkPtr->checkbutton.variableObj,
    if (varName != NULL && *Tcl_GetString(varName) != '\0') {
        vt = Ttk_TraceVariable(interp, varName,
	    CheckbuttonVariableChanged, checkPtr);
        if (!vt) {
	    return TCL_ERROR;
	CheckbuttonVariableChanged, checkPtr);

    if (!vt) {
	return TCL_ERROR;
        }
    }

    if (BaseConfigure(interp, recordPtr, mask) != TCL_OK){
	Ttk_UntraceVariable(vt);
	return TCL_ERROR;
    }

    if (checkPtr->checkbutton.variableTrace) {
        Ttk_UntraceVariable(checkPtr->checkbutton.variableTrace);
    Ttk_UntraceVariable(checkPtr->checkbutton.variableTrace);
    }
    checkPtr->checkbutton.variableTrace = vt;

    return TCL_OK;
}

static int
CheckbuttonPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Checkbutton *checkPtr = (Checkbutton *)recordPtr;
    Checkbutton *checkPtr = recordPtr;
    int status = TCL_OK;

    if (checkPtr->checkbutton.variableTrace)
	status = Ttk_FireTrace(checkPtr->checkbutton.variableTrace);
    if (status == TCL_OK && !WidgetDestroyed(&checkPtr->core))
	status = BasePostConfigure(interp, recordPtr, mask);
    return status;
}

/*
 * Checkbutton 'invoke' subcommand:
 * 	Toggles the checkbutton state.
 */
static int
CheckbuttonInvokeCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Checkbutton *checkPtr = (Checkbutton *)recordPtr;
    Checkbutton *checkPtr = recordPtr;
    WidgetCore *corePtr = &checkPtr->core;
    Tcl_Obj *newValue;

    if (objc > 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "invoke");
	return TCL_ERROR;
    }
    if (corePtr->state & TTK_STATE_DISABLED)
	return TCL_OK;

    /*
     * Toggle the selected state.
     */
    if (corePtr->state & TTK_STATE_SELECTED)
	newValue = checkPtr->checkbutton.offValueObj;
    else
	newValue = checkPtr->checkbutton.onValueObj;

    if (checkPtr->checkbutton.variableObj == NULL ||
        *Tcl_GetString(checkPtr->checkbutton.variableObj) == '\0')
        CheckbuttonVariableChanged(checkPtr, Tcl_GetString(newValue));
    else if (Tcl_ObjSetVar2(interp,
	        checkPtr->checkbutton.variableObj, NULL, newValue,
	        TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG)
	    == NULL)
    if (Tcl_ObjSetVar2(interp,
	    checkPtr->checkbutton.variableObj, NULL, newValue,
	    TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG)
	== NULL)
	return TCL_ERROR;

    if (WidgetDestroyed(corePtr))
	return TCL_ERROR;

    return Tcl_EvalObjEx(interp,
	checkPtr->checkbutton.commandObj, TCL_EVAL_GLOBAL);
}

static const Ttk_Ensemble CheckbuttonCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "invoke",		CheckbuttonInvokeCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    /* MISSING: select, deselect, toggle */
    { 0,0,0 }
};

static const WidgetSpec CheckbuttonWidgetSpec =
static WidgetSpec CheckbuttonWidgetSpec =
{
    "TCheckbutton",		/* className */
    sizeof(Checkbutton),	/* recordSize */
    CheckbuttonOptionSpecs,	/* optionSpecs */
    CheckbuttonCommands,	/* subcommands */
    CheckbuttonInitialize,	/* initializeProc */
    CheckbuttonCleanup,		/* cleanupProc */
640
641
642
643
644
645
646
647

648
649
650

651
652
653

654
655
656

657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
619
620
621
622
623
624
625

626
627
628

629
630
631

632
633
634

635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655







-
+


-
+


-
+


-
+












-
+







    BasePart base;
    RadiobuttonPart radiobutton;
} Radiobutton;

/*
 * Option specifications:
 */
static const Tk_OptionSpec RadiobuttonOptionSpecs[] =
static Tk_OptionSpec RadiobuttonOptionSpecs[] =
{
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	"::selectedButton", offsetof(Radiobutton, radiobutton.variableObj),TCL_INDEX_NONE,
	"::selectedButton", Tk_Offset(Radiobutton, radiobutton.variableObj),-1,
	0,0,0},
    {TK_OPTION_STRING, "-value", "Value", "Value",
	"1", offsetof(Radiobutton, radiobutton.valueObj), TCL_INDEX_NONE,
	"1", Tk_Offset(Radiobutton, radiobutton.valueObj), -1,
	0,0,0},
    {TK_OPTION_STRING, "-command", "command", "Command",
	"", offsetof(Radiobutton, radiobutton.commandObj), TCL_INDEX_NONE,
	"", Tk_Offset(Radiobutton, radiobutton.commandObj), -1,
	0,0,0},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(BaseOptionSpecs)
};

/*
 * Variable trace procedure for radiobuttons.
 */
static void
RadiobuttonVariableChanged(void *clientData, const char *value)
{
    Radiobutton *radioPtr = (Radiobutton *)clientData;
    Radiobutton *radioPtr = clientData;

    if (WidgetDestroyed(&radioPtr->core)) {
	return;
    }

    if (!value) {
	TtkWidgetChangeState(&radioPtr->core, TTK_STATE_ALTERNATE, 0);
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698
699
700

701
702
703
704
705
706
707
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677
678

679
680
681
682
683
684
685
686







-
+








-
+







	TtkWidgetChangeState(&radioPtr->core, 0, TTK_STATE_SELECTED);
    }
}

static void
RadiobuttonCleanup(void *recordPtr)
{
    Radiobutton *radioPtr = (Radiobutton *)recordPtr;
    Radiobutton *radioPtr = recordPtr;
    Ttk_UntraceVariable(radioPtr->radiobutton.variableTrace);
    radioPtr->radiobutton.variableTrace = 0;
    BaseCleanup(recordPtr);
}

static int
RadiobuttonConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Radiobutton *radioPtr = (Radiobutton *)recordPtr;
    Radiobutton *radioPtr = recordPtr;
    Ttk_TraceHandle *vt = Ttk_TraceVariable(
	interp, radioPtr->radiobutton.variableObj,
	RadiobuttonVariableChanged, radioPtr);

    if (!vt) {
	return TCL_ERROR;
    }
716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

740
741

742
743
744
745
746
747
748
695
696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717

718
719

720
721
722
723
724
725
726
727







-
+















-
+

-
+








    return TCL_OK;
}

static int
RadiobuttonPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Radiobutton *radioPtr = (Radiobutton *)recordPtr;
    Radiobutton *radioPtr = recordPtr;
    int status = TCL_OK;

    if (radioPtr->radiobutton.variableTrace)
	status = Ttk_FireTrace(radioPtr->radiobutton.variableTrace);
    if (status == TCL_OK && !WidgetDestroyed(&radioPtr->core))
	status = BasePostConfigure(interp, recordPtr, mask);
    return status;
}

/*
 * Radiobutton 'invoke' subcommand:
 * 	Sets the radiobutton -variable to the -value, evaluates the -command.
 */
static int
RadiobuttonInvokeCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Radiobutton *radioPtr = (Radiobutton *)recordPtr;
    Radiobutton *radioPtr = recordPtr;
    WidgetCore *corePtr = &radioPtr->core;

    if (objc > 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "invoke");
	return TCL_ERROR;
    }
    if (corePtr->state & TTK_STATE_DISABLED)
759
760
761
762
763
764
765
766
767
768
769

770

771
772

773
774
775
776
777

778
779
780
781
782
783
784
738
739
740
741
742
743
744

745


746
747
748
749

750
751
752
753
754

755
756
757
758
759
760
761
762







-

-
-
+

+

-
+




-
+







	return TCL_ERROR;

    return Tcl_EvalObjEx(interp,
	radioPtr->radiobutton.commandObj, TCL_EVAL_GLOBAL);
}

static const Ttk_Ensemble RadiobuttonCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "invoke",		RadiobuttonInvokeCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    /* MISSING: select, deselect */
    { 0,0,0 }
};

static const WidgetSpec RadiobuttonWidgetSpec =
static WidgetSpec RadiobuttonWidgetSpec =
{
    "TRadiobutton",		/* className */
    sizeof(Radiobutton),	/* recordSize */
    RadiobuttonOptionSpecs,	/* optionSpecs */
    RadiobuttonCommands,	/* subcommands */
    BaseInitialize,		/* initializeProc */
    RadiobuttonCleanup,		/* cleanupProc */
814
815
816
817
818
819
820
821

822
823

824
825
826

827
828
829


830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
792
793
794
795
796
797
798

799
800

801
802
803

804
805


806
807
808
809
810
811
812
813
814
815
816
817
818

819
820
821

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

842
843
844
845
846
847
848
849


850
851
852
853
854
855
856







-
+

-
+


-
+

-
-
+
+











-



-
+



















-
+







-
-







    MenubuttonPart menubutton;
} Menubutton;

/*
 * Option specifications:
 */
static const char *const directionStrings[] = {
    "above", "below", "flush", "left", "right", NULL
    "above", "below", "left", "right", "flush", NULL
};
static const Tk_OptionSpec MenubuttonOptionSpecs[] =
static Tk_OptionSpec MenubuttonOptionSpecs[] =
{
    {TK_OPTION_STRING, "-menu", "menu", "Menu",
	"", offsetof(Menubutton, menubutton.menuObj), TCL_INDEX_NONE, 0,0,0},
	"", Tk_Offset(Menubutton, menubutton.menuObj), -1, 0,0,0},
    {TK_OPTION_STRING_TABLE, "-direction", "direction", "Direction",
	"below", offsetof(Menubutton, menubutton.directionObj), TCL_INDEX_NONE,
	0, directionStrings, GEOMETRY_CHANGED},
	"below", Tk_Offset(Menubutton, menubutton.directionObj), -1,
	0,(ClientData)directionStrings,GEOMETRY_CHANGED},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(BaseOptionSpecs)
};

static const Ttk_Ensemble MenubuttonCommands[] = {
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec MenubuttonWidgetSpec =
static WidgetSpec MenubuttonWidgetSpec =
{
    "TMenubutton",		/* className */
    sizeof(Menubutton), 	/* recordSize */
    MenubuttonOptionSpecs, 	/* optionSpecs */
    MenubuttonCommands,  	/* subcommands */
    BaseInitialize,     	/* initializeProc */
    BaseCleanup,		/* cleanupProc */
    BaseConfigure,		/* configureProc */
    BasePostConfigure,  	/* postConfigureProc */
    TtkWidgetGetLayout, 	/* getLayoutProc */
    TtkWidgetSize, 		/* sizeProc */
    TtkWidgetDoLayout,		/* layoutProc */
    TtkWidgetDisplay		/* displayProc */
};

TTK_BEGIN_LAYOUT(MenubuttonLayout)
    TTK_GROUP("Menubutton.border", TTK_FILL_BOTH,
	TTK_GROUP("Menubutton.focus", TTK_FILL_BOTH,
	    TTK_NODE("Menubutton.indicator", TTK_PACK_RIGHT)
	    TTK_GROUP("Menubutton.padding", TTK_FILL_X,
	    TTK_GROUP("Menubutton.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_X,
	        TTK_NODE("Menubutton.label", TTK_PACK_LEFT))))
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * +++ Initialization.
 */

MODULE_SCOPE void TtkButton_Init(Tcl_Interp *);

MODULE_SCOPE
void TtkButton_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(theme, "TLabel", LabelLayout);
    Ttk_RegisterLayout(theme, "TButton", ButtonLayout);

Changes to generic/ttk/ttkCache.c.

1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







/*
 *      Theme engine resource cache.
 *
 * Copyright © 2004, Joe English
 * Copyright (c) 2004, Joe English
 *
 * The problem:
 *
 * Tk maintains reference counts for fonts, colors, and images,
 * and deallocates them when the reference count goes to zero.
 * With the theme engine, resources are allocated right before
 * drawing an element and released immediately after.
24
25
26
27
28
29
30

31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
24
25
26
27
28
29
30
31

32
33
34




35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59







+
-
+


-
-
-
-

















-
+







 * @@@ BUGS/TODO: Need distinct caches for each combination
 * of display, visual, and colormap.
 *
 * @@@ Colormap flashing on PseudoColor visuals is still possible,
 * but this will be a transient effect.
 */

#include <stdio.h>	/* for sprintf */
#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

struct Ttk_ResourceCache_ {
    Tcl_Interp	  *interp;	/* Interpreter for error reporting */
    Tk_Window	  tkwin;	/* Cache window. */
    Tcl_HashTable fontTable;	/* Entries: Tcl_Obj* holding FontObjs */
    Tcl_HashTable colorTable;	/* Entries: Tcl_Obj* holding ColorObjs */
    Tcl_HashTable borderTable;	/* Entries: Tcl_Obj* holding BorderObjs */
    Tcl_HashTable imageTable;	/* Entries: Tk_Images */

    Tcl_HashTable namedColors;	/* Entries: RGB values as Tcl_StringObjs */
};

/*
 * Ttk_CreateResourceCache --
 * 	Initialize a new resource cache.
 */
Ttk_ResourceCache Ttk_CreateResourceCache(Tcl_Interp *interp)
{
    Ttk_ResourceCache cache = (Ttk_ResourceCache)ckalloc(sizeof(*cache));
    Ttk_ResourceCache cache = ckalloc(sizeof(*cache));

    cache->tkwin = NULL;	/* initialized later */
    cache->interp = interp;
    Tcl_InitHashTable(&cache->fontTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->colorTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->borderTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->imageTable, TCL_STRING_KEYS);
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131







-
+














-
+














-
+














-
+







    Tcl_HashEntry *entryPtr;

    /*
     * Free fonts:
     */
    entryPtr = Tcl_FirstHashEntry(&cache->fontTable, &search);
    while (entryPtr != NULL) {
	Tcl_Obj *fontObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *fontObj = Tcl_GetHashValue(entryPtr);
	if (fontObj) {
	    Tk_FreeFontFromObj(cache->tkwin, fontObj);
	    Tcl_DecrRefCount(fontObj);
	}
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&cache->fontTable);
    Tcl_InitHashTable(&cache->fontTable, TCL_STRING_KEYS);

    /*
     * Free colors:
     */
    entryPtr = Tcl_FirstHashEntry(&cache->colorTable, &search);
    while (entryPtr != NULL) {
	Tcl_Obj *colorObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *colorObj = Tcl_GetHashValue(entryPtr);
	if (colorObj) {
	    Tk_FreeColorFromObj(cache->tkwin, colorObj);
	    Tcl_DecrRefCount(colorObj);
	}
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&cache->colorTable);
    Tcl_InitHashTable(&cache->colorTable, TCL_STRING_KEYS);

    /*
     * Free borders:
     */
    entryPtr = Tcl_FirstHashEntry(&cache->borderTable, &search);
    while (entryPtr != NULL) {
	Tcl_Obj *borderObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *borderObj = Tcl_GetHashValue(entryPtr);
	if (borderObj) {
	    Tk_Free3DBorderFromObj(cache->tkwin, borderObj);
	    Tcl_DecrRefCount(borderObj);
	}
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&cache->borderTable);
    Tcl_InitHashTable(&cache->borderTable, TCL_STRING_KEYS);

    /*
     * Free images:
     */
    entryPtr = Tcl_FirstHashEntry(&cache->imageTable, &search);
    while (entryPtr != NULL) {
	Tk_Image image = (Tk_Image)Tcl_GetHashValue(entryPtr);
	Tk_Image image = Tcl_GetHashValue(entryPtr);
	if (image) {
	    Tk_FreeImage(image);
	}
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&cache->imageTable);
    Tcl_InitHashTable(&cache->imageTable, TCL_STRING_KEYS);
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176
177
178
179
180
181
182
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169

170
171

172
173
174
175
176
177
178
179







-
+












-
+

-
+







    Tcl_DeleteHashTable(&cache->imageTable);

    /*
     * Free named colors:
     */
    entryPtr = Tcl_FirstHashEntry(&cache->namedColors, &search);
    while (entryPtr != NULL) {
	Tcl_Obj *colorNameObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *colorNameObj = Tcl_GetHashValue(entryPtr);
	Tcl_DecrRefCount(colorNameObj);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&cache->namedColors);

    ckfree(cache);
}

/*
 * CacheWinEventHandler --
 * 	Detect when the cache window is destroyed, clear cache.
 */
static void CacheWinEventHandler(void *clientData, XEvent *eventPtr)
static void CacheWinEventHandler(ClientData clientData, XEvent *eventPtr)
{
    Ttk_ResourceCache cache = (Ttk_ResourceCache)clientData;
    Ttk_ResourceCache cache = clientData;

    if (eventPtr->type != DestroyNotify) {
	return;
    }
    Tk_DeleteEventHandler(cache->tkwin, StructureNotifyMask,
	    CacheWinEventHandler, clientData);
    Ttk_ClearCache(cache);
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
206
207
208
209
210
211
212

213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247










248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268







-
+






-
+

















-
+









-
-
-
-
-
-
-
-
-
-













-
+







    XColor *colorPtr)
{
    int newEntry;
    Tcl_HashEntry *entryPtr;
    char nameBuf[14];
    Tcl_Obj *colorNameObj;

    snprintf(nameBuf, sizeof(nameBuf), "#%04X%04X%04X",
    sprintf(nameBuf, "#%04X%04X%04X",
    	colorPtr->red, colorPtr->green, colorPtr->blue);
    colorNameObj = Tcl_NewStringObj(nameBuf, -1);
    Tcl_IncrRefCount(colorNameObj);

    entryPtr = Tcl_CreateHashEntry(&cache->namedColors, colorName, &newEntry);
    if (!newEntry) {
    	Tcl_Obj *oldColor = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
    	Tcl_Obj *oldColor = Tcl_GetHashValue(entryPtr);
	Tcl_DecrRefCount(oldColor);
    }

    Tcl_SetHashValue(entryPtr, colorNameObj);
}

/*
 * CheckNamedColor(objPtr) --
 *	If objPtr is a registered color name, return a Tcl_Obj *
 *	containing the registered color value specification.
 *	Otherwise, return the input argument.
 */
static Tcl_Obj *CheckNamedColor(Ttk_ResourceCache cache, Tcl_Obj *objPtr)
{
    Tcl_HashEntry *entryPtr =
    	Tcl_FindHashEntry(&cache->namedColors, Tcl_GetString(objPtr));
    if (entryPtr) {	/* Use named color instead */
    	objPtr = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
    	objPtr = Tcl_GetHashValue(entryPtr);
    }
    return objPtr;
}

/*
 * Template for allocation routines:
 */
typedef void *(*Allocator)(Tcl_Interp *, Tk_Window, Tcl_Obj *);

static void *AllocFont(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) {
	return Tk_AllocFontFromObj(interp, tkwin, objPtr);
}
static void *AllocColor(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) {
	return Tk_AllocColorFromObj(interp, tkwin, objPtr);
}
static void *AllocBorder(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr) {
	return Tk_Alloc3DBorderFromObj(interp, tkwin, objPtr);
}

static Tcl_Obj *Ttk_Use(
    Tcl_Interp *interp,
    Tcl_HashTable *table,
    Allocator allocate,
    Tk_Window tkwin,
    Tcl_Obj *objPtr)
{
    int newEntry;
    Tcl_HashEntry *entryPtr =
	Tcl_CreateHashEntry(table,Tcl_GetString(objPtr),&newEntry);
    Tcl_Obj *cacheObj;

    if (!newEntry) {
	return (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	return Tcl_GetHashValue(entryPtr);
    }

    cacheObj = Tcl_DuplicateObj(objPtr);
    Tcl_IncrRefCount(cacheObj);

    if (allocate(interp, tkwin, cacheObj)) {
	Tcl_SetHashValue(entryPtr, cacheObj);
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332


333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317


318
319







320

321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350







-
+











-
+












-
+






-
-
+
+
-
-
-
-
-
-
-
+
-
















-
+













 * Ttk_UseFont --
 * 	Acquire a font from the cache.
 */
Tcl_Obj *Ttk_UseFont(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
{
    InitCacheWindow(cache, tkwin);
    return Ttk_Use(cache->interp,
	&cache->fontTable, AllocFont, tkwin, objPtr);
	&cache->fontTable,(Allocator)Tk_AllocFontFromObj, tkwin, objPtr);
}

/*
 * Ttk_UseColor --
 * 	Acquire a color from the cache.
 */
Tcl_Obj *Ttk_UseColor(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
{
    objPtr = CheckNamedColor(cache, objPtr);
    InitCacheWindow(cache, tkwin);
    return Ttk_Use(cache->interp,
	&cache->colorTable, AllocColor, tkwin, objPtr);
	&cache->colorTable,(Allocator)Tk_AllocColorFromObj, tkwin, objPtr);
}

/*
 * Ttk_UseBorder --
 * 	Acquire a Tk_3DBorder from the cache.
 */
Tcl_Obj *Ttk_UseBorder(
    Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
{
    objPtr = CheckNamedColor(cache, objPtr);
    InitCacheWindow(cache, tkwin);
    return Ttk_Use(cache->interp,
	&cache->borderTable, AllocBorder, tkwin, objPtr);
	&cache->borderTable,(Allocator)Tk_Alloc3DBorderFromObj, tkwin, objPtr);
}

/* NullImageChanged --
 * 	Tk_ImageChangedProc for Ttk_UseImage
 */

static void NullImageChanged(
    TCL_UNUSED(void *),
static void NullImageChanged(ClientData clientData,
    int x, int y, int width, int height, int imageWidth, int imageHeight)
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{ /* No-op */
{ /* No-op */ }
}

/*
 * Ttk_UseImage --
 * 	Acquire a Tk_Image from the cache.
 */
Tk_Image Ttk_UseImage(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
{
    const char *imageName = Tcl_GetString(objPtr);
    int newEntry;
    Tcl_HashEntry *entryPtr =
	Tcl_CreateHashEntry(&cache->imageTable,imageName,&newEntry);
    Tk_Image image;

    InitCacheWindow(cache, tkwin);

    if (!newEntry) {
	return (Tk_Image)Tcl_GetHashValue(entryPtr);
	return Tcl_GetHashValue(entryPtr);
    }

    image = Tk_GetImage(cache->interp, tkwin, imageName, NullImageChanged,0);
    Tcl_SetHashValue(entryPtr, image);

    if (!image) {
	Tcl_BackgroundException(cache->interp, TCL_ERROR);
    }

    return image;
}

/*EOF*/

Changes to generic/ttk/ttkClamTheme.c.

1
2

3
4
5
6
7

8
9
10
11
12
13
14
15
16

17
18

19
20
21
22
23
24
25
1

2
3
4
5
6

7
8
9
10
11
12
13
14
15

16
17

18
19
20
21
22
23
24
25

-
+




-
+








-
+

-
+







/*
 * Copyright © 2004 Joe English
 * Copyright (C) 2004 Joe English
 *
 * "clam" theme; inspired by the XFCE family of Gnome themes.
 */

#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"

/*
 * Under windows, the Tk-provided XDrawLine and XDrawArc have an
 * off-by-one error in the end point. This is especially apparent with this
 * theme. Defining this macro as true handles this case.
 */
#if defined(_WIN32) && !defined(WIN32_XDRAWLINE_HACK)
  #define WIN32_XDRAWLINE_HACK 1
#	define WIN32_XDRAWLINE_HACK 1
#else
  #define WIN32_XDRAWLINE_HACK 0
#	define WIN32_XDRAWLINE_HACK 0
#endif

#define STR(x) StR(x)
#define StR(x) #x

#define SCROLLBAR_THICKNESS 14

63
64
65
66
67
68
69
70
71
72
73




74
75
76
77
78
79
80


81
82
83
84
85
86
87


88
89
90
91
92
93
94
63
64
65
66
67
68
69




70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94







-
-
-
-
+
+
+
+





-
-
+
+





-
-
+
+







    int y1 = b.y, y2 = b.y + b.height - 1;
    const int w = WIN32_XDRAWLINE_HACK;
    GC gc;

    if (   outerColorObj
	&& (gc=Ttk_GCForColor(tkwin,outerColorObj,d)))
    {
	XDrawLine(display,d,gc, x1+1,y1, x2-1+w,y1);		/* N */
	XDrawLine(display,d,gc, x1+1,y2, x2-1+w,y2);		/* S */
	XDrawLine(display,d,gc, x1,y1+1, x1,y2-1+w);		/* W */
	XDrawLine(display,d,gc, x2,y1+1, x2,y2-1+w);		/* E */
	XDrawLine(display,d,gc, x1+1,y1, x2-1+w,y1); /* N */
	XDrawLine(display,d,gc, x1+1,y2, x2-1+w,y2); /* S */
	XDrawLine(display,d,gc, x1,y1+1, x1,y2-1+w); /* E */
	XDrawLine(display,d,gc, x2,y1+1, x2,y2-1+w); /* W */
    }

    if (   upperColorObj
	&& (gc=Ttk_GCForColor(tkwin,upperColorObj,d)))
    {
	XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1);	/* N */
	XDrawLine(display,d,gc, x1+1,y1+1, x1+1,y2-1);		/* W */
	XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1); /* N */
	XDrawLine(display,d,gc, x1+1,y1+1, x1+1,y2-1);   /* E */
    }

    if (   lowerColorObj
	&& (gc=Ttk_GCForColor(tkwin,lowerColorObj,d)))
    {
	XDrawLine(display,d,gc, x2-1,y2-1, x1+1-w,y2-1);	/* S */
	XDrawLine(display,d,gc, x2-1,y2-1, x2-1,y1+1-w);	/* E */
	XDrawLine(display,d,gc, x2-1,y2-1, x1+1-w,y2-1); /* S */
	XDrawLine(display,d,gc, x2-1,y2-1, x2-1,y1+1-w); /* W */
    }
}

static GC BackgroundGC(Tk_Window tkwin, Tcl_Obj *backgroundObj)
{
    Tk_3DBorder bd = Tk_Get3DBorderFromObj(tkwin, backgroundObj);
    return Tk_3DBorderGC(tkwin, bd, TK_3D_FLAT_GC);
102
103
104
105
106
107
108
109

110
111

112
113

114
115

116
117

118
119
120


121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149

150
151

152
153
154
155

156
157
158
159
160
161
162
102
103
104
105
106
107
108

109
110

111
112

113
114

115
116

117
118


119
120
121
122
123
124
125
126
127
128
129
130
131


132




133
134
135
136

137
138
139
140
141
142


143


144


145

146
147
148
149
150
151
152
153







-
+

-
+

-
+

-
+

-
+

-
-
+
+











-
-
+
-
-
-
-
+



-






-
-
+
-
-
+
-
-

-
+







    Tcl_Obj 	*borderColorObj;
    Tcl_Obj 	*lightColorObj;
    Tcl_Obj 	*darkColorObj;
    Tcl_Obj 	*reliefObj;
    Tcl_Obj 	*borderWidthObj;	/* See <<NOTE-BORDERWIDTH>> */
} BorderElement;

static const Ttk_ElementOptionSpec BorderElementOptions[] = {
static Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(BorderElement,borderColorObj), DARKEST_COLOR },
	Tk_Offset(BorderElement,borderColorObj), DARKEST_COLOR },
    { "-lightcolor", TK_OPTION_COLOR,
	offsetof(BorderElement,lightColorObj), LIGHT_COLOR },
	Tk_Offset(BorderElement,lightColorObj), LIGHT_COLOR },
    { "-darkcolor", TK_OPTION_COLOR,
	offsetof(BorderElement,darkColorObj), DARK_COLOR },
	Tk_Offset(BorderElement,darkColorObj), DARK_COLOR },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(BorderElement,reliefObj), "flat" },
	Tk_Offset(BorderElement,reliefObj), "flat" },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(BorderElement,borderWidthObj), "2" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(BorderElement,borderWidthObj), "2" },
    { NULL, 0, 0, NULL }
};

/*
 * <<NOTE-BORDERWIDTH>>: -borderwidth is only partially supported:
 * in this theme, borders are always exactly 2 pixels thick.
 * With -borderwidth 0, border is not drawn at all;
 * otherwise a 2-pixel border is used.  For -borderwidth > 2,
 * the excess is used as padding.
 */

static void BorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    BorderElement *border = (BorderElement*)elementRecord;
    int borderWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, border->borderWidthObj, &borderWidth);
    if (borderWidth == 1) ++borderWidth;
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void BorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    BorderElement *border = (BorderElement *)elementRecord;
    BorderElement *border = elementRecord;
    int relief = TK_RELIEF_FLAT;
    int borderWidth = 2;
    Tcl_Obj *outer = 0, *upper = 0, *lower = 0;

    Tk_GetReliefFromObj(NULL, border->reliefObj, &relief);
    Tk_GetPixelsFromObj(NULL, tkwin, border->borderWidthObj, &borderWidth);

182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207

208
209

210
211



212
213
214


215
216
217
218
219
220

221
222
223

224
225
226
227
228
229
230

231
232

233
234
235
236

237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263

264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356



357
358

359
360

361
362

363
364

365
366
367


368
369
370
371
372

373
374
375
376

377
378
379

380

381
382


383
384
385

386


387
388
389
390









391
392
393
394
395
396
397
398
399
400
401
402
403















404
405

406

407





408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436





437
438
439

440
441


442
443
444
445


446
447
448
449
450
451
452
453
454
455
456
457

458
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483


484
485
486
487
488
489
490

491
492
493
494
495

496
497
498
499

500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524

525
526
527


528
529
530
531
532
533






534
535

536
537
538
539
540

541
542






























































543
544
545
546
547




548
549
550
551
552

553
554
555

556
557

558
559
560
561
562




563
564
565
566
567

568
569
570
571
572



573
574
575
576



577
578

579
580
581
582
583
584

585
586
587
588
589


590
591
592

593
594
595

596
597
598


599
600
601
602



603
604
605

606
607
608
609



610
611
612
613
614

615
616
617
618
619
620
621
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200

201
202

203
204
205
206


207
208
209
210
211



212



213
214
215
216
217
218


219


220


221

222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248

249
250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271



272






273





















































274
275
276
277
278
279
280

281
282
283
284

285
286

287
288

289
290

291
292


293
294
295
296
297
298

299

300


301
302


303
304
305


306
307
308
309

310

311
312
313



314
315
316
317
318
319
320
321
322
323












324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341
342

343
344
345
346
347
348





349














350
351
352
353





354
355
356
357
358



359


360
361




362
363












364
365





366











367









368
369


370




371





372




373







374










375








376



377
378






379
380
381
382
383
384
385

386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470
471

472
473

474
475




476
477
478
479
480
481
482
483

484

485



486
487
488
489



490
491
492
493

494
495
496
497
498
499

500

501
502


503
504
505
506

507
508
509

510
511


512
513
514



515
516
517
518
519

520
521



522
523
524
525
526
527
528

529
530
531
532
533
534
535
536







-
+














+



-
+

-
+

-
+
+
+

-
-
+
+



-
-
-
+
-
-
-
+





-
-
+
-
-
+
-
-

-
+










-
+













-
+

-
+










-
+











-
-
-

-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+
+
+

-
+

-
+

-
+

-
+

-
-
+
+




-
+
-

-
-
+

-
-
+

+
-
-
+
+


-
+
-
+
+

-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

+
-
+
+
+
+
+

-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-

-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+

-
+




-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





+
+
+
+




-
+


-
+

-
+

-
-
-
-
+
+
+
+




-
+
-

-
-
-
+
+
+

-
-
-
+
+
+

-
+





-
+
-


-
-
+
+


-
+


-
+

-
-
+
+

-
-
-
+
+
+


-
+

-
-
-
+
+
+




-
+







	    outer = upper = lower = border->borderColorObj;
	    break;
    }

    DrawSmoothBorder(tkwin, d, b, outer, upper, lower);
}

static const Ttk_ElementSpec BorderElementSpec = {
static Ttk_ElementSpec BorderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BorderElement),
    BorderElementOptions,
    BorderElementSize,
    BorderElementDraw
};

/*------------------------------------------------------------------------
 * +++ Field element.
 */

typedef struct {
    Tcl_Obj 	*borderColorObj;
    Tcl_Obj 	*lightColorObj;
    Tcl_Obj 	*darkColorObj;
    Tcl_Obj 	*backgroundObj;
} FieldElement;

static const Ttk_ElementOptionSpec FieldElementOptions[] = {
static Ttk_ElementOptionSpec FieldElementOptions[] = {
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(FieldElement,borderColorObj), DARKEST_COLOR },
	Tk_Offset(FieldElement,borderColorObj), DARKEST_COLOR },
    { "-lightcolor", TK_OPTION_COLOR,
	offsetof(FieldElement,lightColorObj), LIGHT_COLOR },
	Tk_Offset(FieldElement,lightColorObj), LIGHT_COLOR },
    { "-darkcolor", TK_OPTION_COLOR,
	Tk_Offset(FieldElement,darkColorObj), DARK_COLOR },
    { "-fieldbackground", TK_OPTION_BORDER,
	offsetof(FieldElement,backgroundObj), "white" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(FieldElement,backgroundObj), "white" },
    { NULL, 0, 0, NULL }
};

static void FieldElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = Ttk_UniformPadding(2);
}

static void FieldElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    FieldElement *field = (FieldElement *)elementRecord;
    FieldElement *field = elementRecord;
    Tk_3DBorder bg = Tk_Get3DBorderFromObj(tkwin, field->backgroundObj);
    Ttk_Box f = Ttk_PadBox(b, Ttk_UniformPadding(2));
    Tcl_Obj *outer = field->borderColorObj,
	    *inner = field->lightColorObj;

    DrawSmoothBorder(tkwin, d, b, outer, inner, inner);
    Tk_Fill3DRectangle(
	tkwin, d, bg, f.x, f.y, f.width, f.height, 0, TK_RELIEF_SUNKEN);
}

static const Ttk_ElementSpec FieldElementSpec = {
static Ttk_ElementSpec FieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    FieldElementSize,
    FieldElementDraw
};

/*
 * Modified field element for comboboxes:
 * 	Right edge is expanded to overlap the dropdown button.
 */
static void ComboboxFieldElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned state)
{
    FieldElement *field = (FieldElement *)elementRecord;
    FieldElement *field = elementRecord;
    GC gc = Ttk_GCForColor(tkwin,field->borderColorObj,d);

    ++b.width;
    FieldElementDraw(clientData, elementRecord, tkwin, d, b, state);

    XDrawLine(Tk_Display(tkwin), d, gc,
	    b.x + b.width - 1, b.y,
	    b.x + b.width - 1, b.y + b.height - 1 + WIN32_XDRAWLINE_HACK);
}

static const Ttk_ElementSpec ComboboxFieldElementSpec = {
static Ttk_ElementSpec ComboboxFieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    FieldElementSize,
    ComboboxFieldElementDraw
};

/*------------------------------------------------------------------------
 * +++ Indicator elements for check and radio buttons.
 */

/*
 * Indicator image descriptor:
 */
typedef struct {
    int width;				/* unscaled width */
    int height;				/* unscaled height */
    const char *const offDataPtr;
    const char *const onDataPtr;
} IndicatorSpec;

    Tcl_Obj *sizeObj;
static const char checkbtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <path d='m0 0v16h1v-15h15v-1z' fill='#9e9a91'/>\n\
     <path d='m15 1v14h-14v1h15v-15z' fill='#cfcdc8'/>\n\
     <rect x='1' y='1' width='14' height='14' fill='#ffffff'/>\n\
    </svg>";

static const char checkbtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <path d='m0 0v16h1v-15h15v-1z' fill='#9e9a91'/>\n\
     <path d='m15 1v14h-14v1h15v-15z' fill='#cfcdc8'/>\n\
     <rect x='1' y='1' width='14' height='14' fill='#ffffff'/>\n\
     <path d='m5 5 6 6m0-6-6 6' fill='none' stroke='#000000' stroke-linecap='round' stroke-width='2'/>\n\
    </svg>";

static const IndicatorSpec checkbutton_spec = {
    16, 16,
    checkbtnOffData,
    checkbtnOnData
};

static const char radiobtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#9e9a91' offset='0'/>\n\
       <stop stop-color='#cfcdc8' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradient)'/>\n\
     <circle cx='8' cy='8' r='7' fill='#ffffff'/>\n\
    </svg>";

static const char radiobtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#9e9a91' offset='0'/>\n\
       <stop stop-color='#cfcdc8' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradient)'/>\n\
     <circle cx='8' cy='8' r='7' fill='#ffffff'/>\n\
     <circle cx='8' cy='8' r='4' fill='#000000'/>\n\
    </svg>";

static const IndicatorSpec radiobutton_spec = {
    16, 16,
    radiobtnOffData,
    radiobtnOnData
};

typedef struct {
    Tcl_Obj *marginObj;
    Tcl_Obj *backgroundObj;
    Tcl_Obj *foregroundObj;
    Tcl_Obj *upperColorObj;
    Tcl_Obj *lowerColorObj;
} IndicatorElement;

static const Ttk_ElementOptionSpec IndicatorElementOptions[] = {
static Ttk_ElementOptionSpec IndicatorElementOptions[] = {
    { "-indicatorsize", TK_OPTION_PIXELS,
	Tk_Offset(IndicatorElement,sizeObj), "10" },
    { "-indicatormargin", TK_OPTION_STRING,
	offsetof(IndicatorElement,marginObj), "1" },
	Tk_Offset(IndicatorElement,marginObj), "1" },
    { "-indicatorbackground", TK_OPTION_COLOR,
	offsetof(IndicatorElement,backgroundObj), "white" },
	Tk_Offset(IndicatorElement,backgroundObj), "white" },
    { "-indicatorforeground", TK_OPTION_COLOR,
	offsetof(IndicatorElement,foregroundObj), "black" },
	Tk_Offset(IndicatorElement,foregroundObj), "black" },
    { "-upperbordercolor", TK_OPTION_COLOR,
	offsetof(IndicatorElement,upperColorObj), DARKEST_COLOR },
	Tk_Offset(IndicatorElement,upperColorObj), DARKEST_COLOR },
    { "-lowerbordercolor", TK_OPTION_COLOR,
	offsetof(IndicatorElement,lowerColorObj), DARK_COLOR },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(IndicatorElement,lowerColorObj), DARK_COLOR },
    { NULL, 0, 0, NULL }
};

static void IndicatorElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorElement *indicator = elementRecord;
    Ttk_Padding margins;
    double scalingLevel = TkScalingLevel(tkwin);

    int size = 10;
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
    *widthPtr = spec->width * scalingLevel + Ttk_PaddingWidth(margins);
    *heightPtr = spec->height * scalingLevel + Ttk_PaddingHeight(margins);
    *widthPtr = size + Ttk_PaddingWidth(margins);
    *heightPtr = size + Ttk_PaddingHeight(margins);
}

static void ColorToStr(
static void RadioIndicatorElementDraw(
    const XColor *colorPtr, char *colorStr)	/* in the format "RRGGBB" */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned state)
{
    snprintf(colorStr, 7, "%02x%02x%02x",
	     colorPtr->red >> 8, colorPtr->green >> 8, colorPtr->blue >> 8);
}
    IndicatorElement *indicator = elementRecord;
    GC gcb=Ttk_GCForColor(tkwin,indicator->backgroundObj,d);
    GC gcf=Ttk_GCForColor(tkwin,indicator->foregroundObj,d);
    GC gcu=Ttk_GCForColor(tkwin,indicator->upperColorObj,d);
    GC gcl=Ttk_GCForColor(tkwin,indicator->lowerColorObj,d);
    Ttk_Padding padding;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
    b = Ttk_PadBox(b, padding);

static void ImageChanged(		/* to be passed to Tk_GetImage() */
    TCL_UNUSED(void *),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
}

static void IndicatorElementDraw(
    XFillArc(Tk_Display(tkwin),d,gcb, b.x,b.y,b.width,b.height, 0,360*64);
    XDrawArc(Tk_Display(tkwin),d,gcl, b.x,b.y,b.width,b.height, 225*64,180*64);
    XDrawArc(Tk_Display(tkwin),d,gcu, b.x,b.y,b.width,b.height, 45*64,180*64);

    if (state & TTK_STATE_SELECTED) {
	b = Ttk_PadBox(b,Ttk_UniformPadding(3));
	XFillArc(Tk_Display(tkwin),d,gcf, b.x,b.y,b.width,b.height, 0,360*64);
	XDrawArc(Tk_Display(tkwin),d,gcf, b.x,b.y,b.width,b.height, 0,360*64);
#if WIN32_XDRAWLINE_HACK
	XDrawArc(Tk_Display(tkwin),d,gcf, b.x,b.y,b.width,b.height, 300*64,360*64);
#endif
    }
}

static void CheckIndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned state)
{
    Display *display = Tk_Display(tkwin);
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorElement *indicator = elementRecord;
    GC gcb=Ttk_GCForColor(tkwin,indicator->backgroundObj,d);
    GC gcf=Ttk_GCForColor(tkwin,indicator->foregroundObj,d);
    GC gcu=Ttk_GCForColor(tkwin,indicator->upperColorObj,d);
    GC gcl=Ttk_GCForColor(tkwin,indicator->lowerColorObj,d);
    Ttk_Padding padding;
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    double scalingLevel = TkScalingLevel(tkwin);
    int width = spec->width * scalingLevel;
    int height = spec->height * scalingLevel;

    const int w = WIN32_XDRAWLINE_HACK;
    char upperBdColorStr[7], lowerBdColorStr[7], bgColorStr[7], fgColorStr[7];
    unsigned int selected = (state & TTK_STATE_SELECTED);
    Tcl_Interp *interp = Tk_Interp(tkwin);
    char imgName[60];
    Tk_Image img;

    const char *svgDataPtr;
    size_t svgDataLen;
    char *svgDataCopy;
    char *upperBdColorPtr, *lowerBdColorPtr, *bgColorPtr, *fgColorPtr;
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    int code;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
    b = Ttk_PadBox(b, padding);

    /*
     * Sanity check
     */
    if (   b.x < 0
	|| b.y < 0
    XFillRectangle(display,d,gcb, b.x,b.y,b.width,b.height);
    XDrawLine(display,d,gcl,b.x,b.y+b.height,b.x+b.width+w,b.y+b.height);/*S*/
    XDrawLine(display,d,gcl,b.x+b.width,b.y,b.x+b.width,b.y+b.height+w); /*E*/
    XDrawLine(display,d,gcu,b.x,b.y, b.x,b.y+b.height+w); /*W*/
    XDrawLine(display,d,gcu,b.x,b.y, b.x+b.width+w,b.y);  /*N*/
	|| Tk_Width(tkwin) < b.x + width
	|| Tk_Height(tkwin) < b.y + height)
    {

	/* Oops!  Not enough room to display the image.
	 * Don't draw anything.
    if (state & TTK_STATE_SELECTED) {
	int p,q,r,s;
	 */
	return;
    }


	b = Ttk_PadBox(b,Ttk_UniformPadding(2));
    /*
     * Construct the color strings upperBdColorStr, lowerBdColorStr,
     * bgColorStr, and fgColorStr
     */
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->upperColorObj),
	       upperBdColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->lowerColorObj),
	       lowerBdColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->backgroundObj),
	       bgColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->foregroundObj),
	       fgColorStr);
	p = b.x, q = b.y, r = b.x+b.width, s = b.y+b.height;

    /*
     * Check whether there is an SVG image of this size for the indicator's
     * type (0 = checkbtn, 1 = radiobtn) and these color strings
     */
    snprintf(imgName, sizeof(imgName),
	r+=w, s+=w;
	     "::tk::icons::indicator_clam%d_%d_%s_%s_%s_%s",
	     width, spec->offDataPtr == radiobtnOffData,
	     upperBdColorStr, lowerBdColorStr, bgColorStr,
	     selected ? fgColorStr : "XXXXXX");
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
	/*
	 * Determine the SVG data to use for the photo image
	 */
	svgDataPtr = (selected ? spec->onDataPtr : spec->offDataPtr);

	XDrawLine(display, d, gcf, p,   q,   r,   s);
	/*
	 * Copy the string pointed to by svgDataPtr to
	 * a newly allocated memory area svgDataCopy
	 */
	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
	    return;
	}
	XDrawLine(display, d, gcf, p+1, q,   r,   s-1);
	XDrawLine(display, d, gcf, p,   q+1, r-1, s);
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	/*
	 * Update the colors within svgDataCopy
	 */

	s-=w, q-=w;
	upperBdColorPtr = strstr(svgDataCopy, "9e9a91");
	lowerBdColorPtr = strstr(svgDataCopy, "cfcdc8");
	bgColorPtr =	  strstr(svgDataCopy, "ffffff");
	fgColorPtr =	  strstr(svgDataCopy, "000000");

	XDrawLine(display, d, gcf, p,   s,   r,   q);
	assert(upperBdColorPtr);
	assert(lowerBdColorPtr);
	assert(bgColorPtr);

	XDrawLine(display, d, gcf, p+1, s,   r,   q+1);
	memcpy(upperBdColorPtr, upperBdColorStr, 6);
	memcpy(lowerBdColorPtr, lowerBdColorStr, 6);
	memcpy(bgColorPtr, bgColorStr, 6);
	if (fgColorPtr != NULL) {
	    memcpy(fgColorPtr, fgColorStr, 6);
	}

	XDrawLine(display, d, gcf, p,   s-1, r-1, q);
	/*
	 * Create an SVG photo image from svgDataCopy
	 */
	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
	    return;
	}
    }
	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
	code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL);
	ckfree(script);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	    return;
	}
}
	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }


static Ttk_ElementSpec RadioIndicatorElementSpec = {
    /*
     * Display the image
     */
    Tk_RedrawImage(img, 0, 0, width, height, d, b.x, b.y);
    Tk_FreeImage(img);
}
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    IndicatorElementSize,
    RadioIndicatorElementDraw
};

static const Ttk_ElementSpec IndicatorElementSpec = {
static Ttk_ElementSpec CheckIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    IndicatorElementSize,
    IndicatorElementDraw
    CheckIndicatorElementDraw
};

#define MENUBUTTON_ARROW_SIZE 5

typedef struct {
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *paddingObj;
} MenuIndicatorElement;

static Ttk_ElementOptionSpec MenuIndicatorElementOptions[] =
{
    { "-arrowsize", TK_OPTION_PIXELS,
	Tk_Offset(MenuIndicatorElement,sizeObj),
	STR(MENUBUTTON_ARROW_SIZE)},
    { "-arrowcolor",TK_OPTION_COLOR,
	Tk_Offset(MenuIndicatorElement,colorObj),
	"black" },
    { "-arrowpadding",TK_OPTION_STRING,
	Tk_Offset(MenuIndicatorElement,paddingObj),
	"3" },
    { NULL, 0, 0, NULL }
};

static void MenuIndicatorElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    MenuIndicatorElement *indicator = elementRecord;
    Ttk_Padding margins;
    int size = MENUBUTTON_ARROW_SIZE;
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->paddingObj, &margins);
    TtkArrowSize(size, ARROW_DOWN, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(margins);
    *heightPtr += Ttk_PaddingHeight(margins);
}

static void MenuIndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    MenuIndicatorElement *indicator = elementRecord;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, indicator->colorObj);
    GC gc = Tk_GCForColor(arrowColor, d);
    int size = MENUBUTTON_ARROW_SIZE;
    int width, height;

    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);

    TtkArrowSize(size, ARROW_DOWN, &width, &height);
    b = Ttk_StickBox(b, width, height, 0);
    TtkFillArrow(Tk_Display(tkwin), d, gc, b, ARROW_DOWN);
}

static Ttk_ElementSpec MenuIndicatorElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(MenuIndicatorElement),
    MenuIndicatorElementOptions,
    MenuIndicatorElementSize,
    MenuIndicatorElementDraw
};

/*------------------------------------------------------------------------
 * +++ Grips.
 *
 * TODO: factor this with ThumbElementDraw
 */

static Ttk_Orient GripClientData[] = {
    TTK_ORIENT_HORIZONTAL, TTK_ORIENT_VERTICAL
};

typedef struct {
    Tcl_Obj 	*lightColorObj;
    Tcl_Obj 	*borderColorObj;
    Tcl_Obj 	*gripSizeObj;
    Tcl_Obj 	*gripCountObj;
} GripElement;

static const Ttk_ElementOptionSpec GripElementOptions[] = {
static Ttk_ElementOptionSpec GripElementOptions[] = {
    { "-lightcolor", TK_OPTION_COLOR,
	offsetof(GripElement,lightColorObj), LIGHT_COLOR },
	Tk_Offset(GripElement,lightColorObj), LIGHT_COLOR },
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(GripElement,borderColorObj), DARKEST_COLOR },
    { "-gripsize", TK_OPTION_PIXELS,
	offsetof(GripElement,gripSizeObj), "7.5p" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(GripElement,borderColorObj), DARKEST_COLOR },
    { "-gripcount", TK_OPTION_INT,
	Tk_Offset(GripElement,gripCountObj), "5" },
    { NULL, 0, 0, NULL }
};

static void GripElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
    GripElement *grip = (GripElement *)elementRecord;
    int gripSize = 0;
    int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL;
    GripElement *grip = elementRecord;
    int gripCount = 0;

    Tk_GetPixelsFromObj(NULL, tkwin, grip->gripSizeObj, &gripSize);
    if (orient == TTK_ORIENT_HORIZONTAL) {
	*widthPtr = gripSize;
    Tcl_GetIntFromObj(NULL, grip->gripCountObj, &gripCount);
    if (horizontal) {
	*widthPtr = 2*gripCount;
    } else {
	*heightPtr = gripSize;
	*heightPtr = 2*gripCount;
    }
}

static void GripElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    Drawable d, Ttk_Box b, unsigned state)
    TCL_UNUSED(Ttk_State))
{
    const int w = WIN32_XDRAWLINE_HACK;
    Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
    GripElement *grip = (GripElement *)elementRecord;
    int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL;
    GripElement *grip = elementRecord;
    GC lightGC = Ttk_GCForColor(tkwin,grip->lightColorObj,d);
    GC darkGC = Ttk_GCForColor(tkwin,grip->borderColorObj,d);
    int gripPad = 1, gripSize = 0;
    int gripPad = 1, gripCount = 0;
    int i;

    Tk_GetPixelsFromObj(NULL, tkwin, grip->gripSizeObj, &gripSize);
    Tcl_GetIntFromObj(NULL, grip->gripCountObj, &gripCount);

    if (orient == TTK_ORIENT_HORIZONTAL) {
	int x = b.x + (b.width - gripSize) / 2;
    if (horizontal) {
	int x = b.x + b.width / 2 - gripCount;
	int y1 = b.y + gripPad, y2 = b.y + b.height - gripPad - 1 + w;
	for (i=0; i<gripSize; ++i) {
	    XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x,y1, x,y2);
	    ++x;
	for (i=0; i<gripCount; ++i) {
	    XDrawLine(Tk_Display(tkwin), d, darkGC,  x,y1, x,y2); ++x;
	    XDrawLine(Tk_Display(tkwin), d, lightGC, x,y1, x,y2); ++x;
	}
    } else {
	int y = b.y + (b.height - gripSize) / 2;
	int y = b.y + b.height / 2 - gripCount;
	int x1 = b.x + gripPad, x2 = b.x + b.width - gripPad - 1 + w;
	for (i=0; i<gripSize; ++i) {
	    XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x1,y, x2,y);
	    ++y;
	for (i=0; i<gripCount; ++i) {
	    XDrawLine(Tk_Display(tkwin), d, darkGC,  x1,y, x2,y); ++y;
	    XDrawLine(Tk_Display(tkwin), d, lightGC, x1,y, x2,y); ++y;
	}
    }
}

static const Ttk_ElementSpec GripElementSpec = {
static Ttk_ElementSpec GripElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(GripElement),
    GripElementOptions,
    GripElementSize,
    GripElementDraw
};

631
632
633
634
635
636
637
638

639
640
641
642

643
644

645
646

647
648

649
650

651
652

653
654

655
656

657
658
659
660
661
662
663






664
665
666
667
668

669
670

671
672
673
674

675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692

693
694

695
696
697
698

699
700
701

702
703
704
705
706
707

708
709

710
711
712
713

714
715

716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736

737
738
739
740
741

742
743
744
745
746
747


748
749


750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766

767
768

769
770
771
772
773


774
775
776
777
778

779
780
781
782
783
784
785
786
787
788
789




790
791
792
793
794
795
796
546
547
548
549
550
551
552

553
554
555
556

557
558

559
560

561
562

563
564

565
566

567
568

569
570

571
572






573
574
575
576
577
578
579
580
581


582


583


584

585
586
587

588
589
590
591

592
593
594
595
596
597
598
599
600


601


602


603

604
605


606
607
608
609
610


611


612


613

614


615
616
617
618
619
620
621
622
623
624
625
626
627
628
629

630
631
632
633
634
635

636
637
638
639
640

641
642
643
644
645


646
647
648

649
650
651
652
653

654
655
656
657
658
659
660
661
662
663
664
665


666


667


668


669
670

671
672
673

674
675
676
677
678
679
680
681
682



683
684
685
686
687
688
689
690
691
692
693







-
+



-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+



-
-
+
-
-
+
-
-

-
+


-




-
+








-
-
+
-
-
+
-
-

-
+

-
-
+




-
-
+
-
-
+
-
-

-
+
-
-
+














-
+





-
+




-
+




-
-
+
+

-
+
+



-
+











-
-
+
-
-
+
-
-

-
-
+
+
-



-
+








-
-
-
+
+
+
+







    Tcl_Obj 	*backgroundObj;
    Tcl_Obj 	*borderColorObj;
    Tcl_Obj 	*troughColorObj;
    Tcl_Obj 	*lightColorObj;
    Tcl_Obj 	*darkColorObj;
    Tcl_Obj 	*arrowColorObj;
    Tcl_Obj 	*arrowSizeObj;
    Tcl_Obj 	*gripSizeObj;
    Tcl_Obj 	*gripCountObj;
    Tcl_Obj 	*sliderlengthObj;
} ScrollbarElement;

static const Ttk_ElementOptionSpec ScrollbarElementOptions[] = {
static Ttk_ElementOptionSpec ScrollbarElementOptions[] = {
    { "-orient", TK_OPTION_ANY,
	offsetof(ScrollbarElement, orientObj), "horizontal" },
	Tk_Offset(ScrollbarElement, orientObj), "horizontal" },
    { "-background", TK_OPTION_BORDER,
	offsetof(ScrollbarElement,backgroundObj), FRAME_COLOR },
	Tk_Offset(ScrollbarElement,backgroundObj), FRAME_COLOR },
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(ScrollbarElement,borderColorObj), DARKEST_COLOR },
	Tk_Offset(ScrollbarElement,borderColorObj), DARKEST_COLOR },
    { "-troughcolor", TK_OPTION_COLOR,
	offsetof(ScrollbarElement,troughColorObj), DARKER_COLOR },
	Tk_Offset(ScrollbarElement,troughColorObj), DARKER_COLOR },
    { "-lightcolor", TK_OPTION_COLOR,
	offsetof(ScrollbarElement,lightColorObj), LIGHT_COLOR },
	Tk_Offset(ScrollbarElement,lightColorObj), LIGHT_COLOR },
    { "-darkcolor", TK_OPTION_COLOR,
	offsetof(ScrollbarElement,darkColorObj), DARK_COLOR },
	Tk_Offset(ScrollbarElement,darkColorObj), DARK_COLOR },
    { "-arrowcolor", TK_OPTION_COLOR,
	offsetof(ScrollbarElement,arrowColorObj), "#000000" },
	Tk_Offset(ScrollbarElement,arrowColorObj), "#000000" },
    { "-arrowsize", TK_OPTION_PIXELS,
	offsetof(ScrollbarElement,arrowSizeObj), STR(SCROLLBAR_THICKNESS) },
    { "-gripsize", TK_OPTION_PIXELS,
	offsetof(ScrollbarElement,gripSizeObj), "7.5p" },
    { "-sliderlength", TK_OPTION_PIXELS,
	offsetof(ScrollbarElement,sliderlengthObj), "30" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(ScrollbarElement,arrowSizeObj), STR(SCROLLBAR_THICKNESS) },
    { "-gripcount", TK_OPTION_INT,
	Tk_Offset(ScrollbarElement,gripCountObj), "5" },
    { "-sliderlength", TK_OPTION_INT,
	Tk_Offset(ScrollbarElement,sliderlengthObj), "30" },
    { NULL, 0, 0, NULL }
};

static void TroughElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;
    GC gcb = Ttk_GCForColor(tkwin,sb->borderColorObj,d);
    GC gct = Ttk_GCForColor(tkwin,sb->troughColorObj,d);

    XFillRectangle(Tk_Display(tkwin), d, gct, b.x, b.y, b.width-1, b.height-1);
    XDrawRectangle(Tk_Display(tkwin), d, gcb, b.x, b.y, b.width-1, b.height-1);
}

static const Ttk_ElementSpec TroughElementSpec = {
static Ttk_ElementSpec TroughElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    TtkNullElementSize,
    TroughElementDraw
};

static void ThumbElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;
    int size = SCROLLBAR_THICKNESS;

    Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
    Tcl_GetIntFromObj(NULL, sb->arrowSizeObj, &size);
    *widthPtr = *heightPtr = size;
}

static void ThumbElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;
    int gripSize = 0;
    Ttk_Orient orient = TTK_ORIENT_HORIZONTAL;
    int gripCount = 0, orient = TTK_ORIENT_HORIZONTAL;
    GC lightGC, darkGC;
    int x1, y1, x2, y2, dx, dy, i;
    const int w = WIN32_XDRAWLINE_HACK;

    DrawSmoothBorder(tkwin, d, b,
	sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);
    XFillRectangle(
	Tk_Display(tkwin), d, BackgroundGC(tkwin, sb->backgroundObj),
	b.x+2, b.y+2, b.width-4, b.height-4);

    /*
     * Draw grip:
     */
    Ttk_GetOrientFromObj(NULL, sb->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, sb->gripSizeObj, &gripSize);
    Tcl_GetIntFromObj(NULL, sb->gripCountObj, &gripCount);
    lightGC = Ttk_GCForColor(tkwin,sb->lightColorObj,d);
    darkGC = Ttk_GCForColor(tkwin,sb->borderColorObj,d);

    if (orient == TTK_ORIENT_HORIZONTAL) {
	dx = 1; dy = 0;
	x1 = x2 = b.x + (b.width - gripSize) / 2;
	x1 = x2 = b.x + b.width / 2 - gripCount;
	y1 = b.y + 2;
	y2 = b.y + b.height - 3 + w;
    } else {
	dx = 0; dy = 1;
	y1 = y2 = b.y + (b.height - gripSize) / 2;
	y1 = y2 = b.y + b.height / 2 - gripCount;
	x1 = b.x + 2;
	x2 = b.x + b.width - 3 + w;
    }

    for (i=0; i<gripSize; ++i) {
	XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x1,y1, x2,y2);
    for (i=0; i<gripCount; ++i) {
	XDrawLine(Tk_Display(tkwin), d, darkGC, x1,y1, x2,y2);
	x1 += dx; x2 += dx; y1 += dy; y2 += dy;

	XDrawLine(Tk_Display(tkwin), d, lightGC, x1,y1, x2,y2);
	x1 += dx; x2 += dx; y1 += dy; y2 += dy;
    }
}

static const Ttk_ElementSpec ThumbElementSpec = {
static Ttk_ElementSpec ThumbElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    ThumbElementSize,
    ThumbElementDraw
};

/*------------------------------------------------------------------------
 * +++ Slider element.
 */
static void SliderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    int length, thickness;
    ScrollbarElement *sb = elementRecord;
    int length, thickness, orient;
    Ttk_Orient orient;

    length = thickness = SCROLLBAR_THICKNESS;
    Ttk_GetOrientFromObj(NULL, sb->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &thickness);
    Tcl_GetIntFromObj(NULL, sb->arrowSizeObj, &thickness);
    Tk_GetPixelsFromObj(NULL, tkwin, sb->sliderlengthObj, &length);
    if (orient == TTK_ORIENT_VERTICAL) {
	*heightPtr = length;
	*widthPtr = thickness;
    } else {
	*heightPtr = thickness;
	*widthPtr = length;
    }
}

static const Ttk_ElementSpec SliderElementSpec = {

}

static Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    SliderElementSize,
    ThumbElementDraw
};

805
806
807
808
809
810
811
812
813

814
815

816
817
818
819

820
821
822
823
824
825
826
827
828
829
830
831

832
833
834
835
836
837

838
839
840
841


842
843
844

845
846
847

848
849
850
851
852
853

854
855
856
857
858
859

860
861
862
863
864
865
866
867

868
869

870

871
872
873
874
875


876
877
878
879
880
881
882
883
884
885


886
887
888
889

890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905

906
907
908

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

961
962

963
964

965
966

967
968
969


970
971
972
973
974
975

976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995

996
997
998

999
1000
1001
1002
1003
1004


1005
1006
1007
1008

1009
1010

1011
1012
1013
1014
1015
1016
1017

1018
1019

1020

1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037



1038
1039
1040


1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067


1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093




1094
1095

1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114


1115
1116

1117
1118
1119
1120
1121

1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150

1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227



















1228
1229
1230
1231



1232
1233
1234

1235
1236
1237


1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249

1250
1251
1252
1253
1254
1255
1256
702
703
704
705
706
707
708


709


710


711

712
713
714
715
716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

740

741

742



743


744






745



746
747
748
749

750

751
752

753





754
755
756
757
758
759
760
761
762
763


764
765




766













767
768

769
770
771

772
773
774
775
776
777
778
779





























780
781
782
783
784
785
786
787
788
789
790
791
792
793
794

795
796

797
798

799
800

801
802


803
804
805
806
807



808



809
810


811













812



813






814
815

816


817


818


819




820
821
822
823

824
825
826
827




828

829
830
831






832
833
834
835


836
837

838

























839
840









841




842












843
844
845
846
847

848



















849
850


851





852



853
854
855
856
857
858
859
860
861
862



863



864
865
866

867
868
869
870


871


872


873

874
875
876
877
878
879
880
881
882
883

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

918
919
920
921
922
923
924
925
926
927



















928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946




947
948
949



950



951
952
953
954
955
956
957
958
959
960
961

962
963

964
965
966
967
968
969
970
971







-
-
+
-
-
+
-
-

-
+











-
+






+




+
+


-
+
-

-
+
-
-
-

-
-
+
-
-
-
-
-
-
+
-
-
-




-
+
-

+
-
+
-
-
-
-
-
+
+








-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+


-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















-
+

-
+

-
+

-
+

-
-
+
+



-
-
-
+
-
-
-
+

-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
+
+
-

-
-
+
-
-
+
-
-

-
-
-
-
+


+
-
+



-
-
-
-

-
+


-
-
-
-
-
-
+
+
+

-
-
+
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
+
-
-
-
+









-
-
-
+
-
-
-
+


-




-
-
+
-
-
+
-
-

-
+









-
+
















-
+
















-










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
-
-
-
+
+









-
+

-
+







	    widthPtr, heightPtr, paddingPtr);
    *paddingPtr = Ttk_UniformPadding(2);
    *widthPtr += 4;
    *heightPtr += 4;
}

static void PbarElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;

    b = Ttk_PadBox(b, Ttk_UniformPadding(2));
    if (b.width > 4 && b.height > 4) {
	DrawSmoothBorder(tkwin, d, b,
	    sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);
	XFillRectangle(Tk_Display(tkwin), d,
	    BackgroundGC(tkwin, sb->backgroundObj),
	    b.x+2, b.y+2, b.width-4, b.height-4);
    }
}

static const Ttk_ElementSpec PbarElementSpec = {
static Ttk_ElementSpec PbarElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    PbarElementSize,
    PbarElementDraw
};


/*------------------------------------------------------------------------
 * +++ Scrollbar arrows.
 */
static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT };

static void ArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
    int size = SCROLLBAR_THICKNESS;

    Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
    Tcl_GetIntFromObj(NULL, sb->arrowSizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
    if (*widthPtr < *heightPtr) {
	*widthPtr = *heightPtr;
    *widthPtr = *heightPtr = size;
    } else {
	*heightPtr = *widthPtr;
    }
}

static void ArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    Drawable d, Ttk_Box b, unsigned state)
    TCL_UNUSED(Ttk_State))
{
    ArrowDirection dir = *(ArrowDirection*)clientData;
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ScrollbarElement *sb = elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
    int cx, cy;
    GC gc = Ttk_GCForColor(tkwin, sb->arrowColorObj, d);
    GC gc = Ttk_GCForColor(tkwin,sb->arrowColorObj, d);
    int h, cx, cy;

    DrawSmoothBorder(tkwin, d, b,
	sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);

    XFillRectangle(
	Tk_Display(tkwin), d, BackgroundGC(tkwin, sb->backgroundObj),
	b.x+2, b.y+2, b.width-4, b.height-4);

    b = Ttk_PadBox(b, padding);

    b = Ttk_PadBox(b, Ttk_UniformPadding(3));
    h = b.width < b.height ? b.width : b.height;
    switch (direction) {
	case ARROW_UP:
	case ARROW_DOWN:
	    TtkArrowSize(b.width/2, direction, &cx, &cy);
    TtkArrowSize(h/2, dir, &cx, &cy);
	    if ((b.height - cy) % 2 == 1) {
		++cy;
	    }
	    break;
	case ARROW_LEFT:
	case ARROW_RIGHT:
	    TtkArrowSize(b.height/2, direction, &cx, &cy);
	    if ((b.width - cx) % 2 == 1) {
		++cx;
	    }
	    break;
    }

    b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

    TtkFillArrow(Tk_Display(tkwin), d, gc, b, direction);
    TtkFillArrow(Tk_Display(tkwin), d, gc, b, dir);
}

static const Ttk_ElementSpec ArrowElementSpec = {
static Ttk_ElementSpec ArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    ArrowElementSize,
    ArrowElementDraw
};

/*
 * Modified arrow element for spinboxes:
 * 	The width and height are different.
 */
static void SpinboxArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
    int size = 10;

    Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
}

static const Ttk_ElementSpec SpinboxArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    SpinboxArrowElementSize,
    ArrowElementDraw
};

/*------------------------------------------------------------------------
 * +++ Notebook elements.
 *
 * Note: Tabs, except for the rightmost, overlap the neighbor to
 * their right by one pixel.
 */

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *borderColorObj;
    Tcl_Obj *lightColorObj;
    Tcl_Obj *darkColorObj;
} NotebookElement;

static const Ttk_ElementOptionSpec NotebookElementOptions[] = {
static Ttk_ElementOptionSpec NotebookElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(NotebookElement,backgroundObj), FRAME_COLOR },
	Tk_Offset(NotebookElement,backgroundObj), FRAME_COLOR },
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(NotebookElement,borderColorObj), DARKEST_COLOR },
	Tk_Offset(NotebookElement,borderColorObj), DARKEST_COLOR },
    { "-lightcolor", TK_OPTION_COLOR,
	offsetof(NotebookElement,lightColorObj), LIGHT_COLOR },
	Tk_Offset(NotebookElement,lightColorObj), LIGHT_COLOR },
    { "-darkcolor", TK_OPTION_COLOR,
	offsetof(NotebookElement,darkColorObj), DARK_COLOR },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(NotebookElement,darkColorObj), DARK_COLOR },
    { NULL, 0, 0, NULL }
};

static void TabElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
    int borderWidth = 2;

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_N:
	    paddingPtr->top = 0;
    paddingPtr->top = paddingPtr->left = paddingPtr->right = borderWidth;
	    break;
	case TTK_STICK_E:
	    paddingPtr->right = 0;
    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_W:
	    paddingPtr->left = 0;
	    break;
    }
}
}


static void TabElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
    int borderWidth = 2, delta = 0;
    NotebookElement *tab = (NotebookElement *)elementRecord;
    NotebookElement *tab = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj);
    Display *display = Tk_Display(tkwin);
    int borderWidth = 2, dh = 0;
    int x1, y1, x2, y2;
    int x1,y1,x2,y2;
    GC gc;
    const int w = WIN32_XDRAWLINE_HACK;

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    if (state & TTK_STATE_SELECTED) {
	delta = borderWidth;
	dh = borderWidth;
    }

    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    if (state & TTK_STATE_USER2) {		/* rightmost tab */
		--b.width;
	    }
    if (state & TTK_STATE_USER2) {	/* Rightmost tab */
	--b.width;
    }

	    Tk_Fill3DRectangle(tkwin, d, border,
		b.x+2, b.y+2, b.width-1, b.height-2+delta,
    Tk_Fill3DRectangle(tkwin, d, border,
	b.x+2, b.y+2, b.width-1, b.height-2+dh, borderWidth, TK_RELIEF_FLAT);
		borderWidth, TK_RELIEF_FLAT);

	    x1 = b.x;		y1 = b.y;		/* top left */
	    x2 = b.x + b.width; y2 = b.y + b.height-1;	/* bottom right */

	    gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
	    XDrawLine(display, d, gc, x1, y1+1, x1, y2+1+w);
	    XDrawLine(display, d, gc, x2, y1+1, x2, y2+1+w);
	    XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);

	    gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
	    XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2+delta+w);
	    XDrawLine(display, d, gc, x1+1, y1+1, x2-1+w, y1+1);
	    break;

	case TTK_STICK_N:
	    if (state & TTK_STATE_USER2) {		/* rightmost tab */
		--b.width;
	    }

	    Tk_Fill3DRectangle(tkwin, d, border,
		b.x+2, b.y-delta, b.width-1, b.height-2+delta,
		borderWidth, TK_RELIEF_FLAT);

	    x1 = b.x;		y1 = b.y + b.height-1;	/* bottom left */
	    x2 = b.x + b.width; y2 = b.y;		/* top right */

    x1 = b.x, x2 = b.x + b.width;
    y1 = b.y, y2 = b.y + b.height;
	    gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
	    XDrawLine(display, d, gc, x1, y1-1, x1, y2-1-w);
	    XDrawLine(display, d, gc, x2, y1-1, x2, y2-1-w);
	    XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);

	    gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
	    XDrawLine(display, d, gc, x1+1, y1-1, x1+1, y2-delta-w);
	    XDrawLine(display, d, gc, x1+1, y1-1, x2-1+w, y1-1);
	    break;

	case TTK_STICK_E:
	    if (state & TTK_STATE_USER2) {		/* bottommost tab */
		--b.height;
	    }


	    Tk_Fill3DRectangle(tkwin, d, border,
		b.x+2, b.y+2, b.width-2+delta, b.height-1,
		borderWidth, TK_RELIEF_FLAT);

	    x1 = b.x;		  y1 = b.y;		/* top left */
	    x2 = b.x + b.width-1; y2 = b.y + b.height;	/* bottom right */

	    gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
	    XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
	    XDrawLine(display, d, gc, x1+1, y1, x2+1+w, y1);
	    XDrawLine(display, d, gc, x1+1, y2, x2+1+w, y2);
    gc=Ttk_GCForColor(tkwin,tab->borderColorObj,d);
    XDrawLine(display,d,gc, x1,y1+1, x1,y2+w);
    XDrawLine(display,d,gc, x2,y1+1, x2,y2+w);
    XDrawLine(display,d,gc, x1+1,y1, x2-1+w,y1);

	    gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
    gc=Ttk_GCForColor(tkwin,tab->lightColorObj,d);
	    XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2-1+w);
	    XDrawLine(display, d, gc, x1+1, y1+1, x2+delta+w, y1+1);
	    break;

	case TTK_STICK_W:
	    if (state & TTK_STATE_USER2) {		/* bottommost tab */
		--b.height;
	    }

	    Tk_Fill3DRectangle(tkwin, d, border,
		b.x-delta, b.y+2, b.width-2+delta, b.height-1,
		borderWidth, TK_RELIEF_FLAT);

	    x1 = b.x + b.width-1; y1 = b.y;		/* top right */
	    x2 = b.x;		  y2 = b.y + b.height;	/* bottom left */

	    gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
	    XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
	    XDrawLine(display, d, gc, x1-1, y1, x2-1-w, y1);
    XDrawLine(display,d,gc, x1+1,y1+1, x1+1,y2-1+dh+w);
    XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1);
	    XDrawLine(display, d, gc, x1-1, y2, x2-1-w, y2);

}
	    gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
	    XDrawLine(display, d, gc, x1-1, y1+1, x1-1, y2-1+w);
	    XDrawLine(display, d, gc, x1-1, y1+1, x2-delta-w, y1+1);
	    break;
    }

}

static const Ttk_ElementSpec TabElementSpec =
static Ttk_ElementSpec TabElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NotebookElement),
    NotebookElementOptions,
    TabElementSize,
    TabElementDraw
};

static void ClientElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    int borderWidth = 2;

    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void ClientElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    NotebookElement *ce = (NotebookElement *)elementRecord;
    NotebookElement *ce = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, ce->backgroundObj);
    int borderWidth = 2;

    Tk_Fill3DRectangle(tkwin, d, border,
	b.x, b.y, b.width, b.height, borderWidth,TK_RELIEF_FLAT);
    DrawSmoothBorder(tkwin, d, b,
    	ce->borderColorObj, ce->lightColorObj, ce->darkColorObj);
}

static const Ttk_ElementSpec ClientElementSpec =
static Ttk_ElementSpec ClientElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NotebookElement),
    NotebookElementOptions,
    ClientElementSize,
    ClientElementDraw
};

/*------------------------------------------------------------------------
 * +++ Modified widget layouts.
 */

TTK_BEGIN_LAYOUT_TABLE(LayoutTable)

TTK_LAYOUT("TCombobox",
    TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y)
    TTK_GROUP("Combobox.field", TTK_FILL_BOTH,
    TTK_GROUP("Combobox.field", TTK_PACK_LEFT|TTK_FILL_BOTH|TTK_EXPAND,
	TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
	    TTK_NODE("Combobox.textarea", TTK_FILL_BOTH))))

TTK_LAYOUT("Horizontal.Sash",
    TTK_GROUP("Sash.hsash", TTK_FILL_BOTH,
	TTK_NODE("Sash.hgrip", TTK_FILL_BOTH)))

TTK_LAYOUT("Vertical.Sash",
    TTK_GROUP("Sash.vsash", TTK_FILL_BOTH,
	TTK_NODE("Sash.vgrip", TTK_FILL_BOTH)))

TTK_END_LAYOUT_TABLE

/*------------------------------------------------------------------------
 * +++ Initialization.
 */
MODULE_SCOPE int TtkClamTheme_Init(Tcl_Interp *);

MODULE_SCOPE int
TtkClamTheme_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_CreateTheme(interp, "clam", 0);

    if (!theme) {
        return TCL_ERROR;
    }

    Ttk_RegisterElement(interp, theme, "border",
	    &BorderElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "field",
	    &FieldElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "Combobox.field",
	    &ComboboxFieldElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "trough",
	    &TroughElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "thumb",
	    &ThumbElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "uparrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
    Ttk_RegisterElement(interp, theme, "Spinbox.uparrow",
	    &SpinboxArrowElementSpec, INT2PTR(ARROW_UP));
    Ttk_RegisterElement(interp, theme, "downarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "Spinbox.downarrow",
	    &SpinboxArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "leftarrow",
    Ttk_RegisterElement(interp,
	theme, "border", &BorderElementSpec, NULL);
    Ttk_RegisterElement(interp,
	theme, "field", &FieldElementSpec, NULL);
    Ttk_RegisterElement(interp,
	theme, "Combobox.field", &ComboboxFieldElementSpec, NULL);
    Ttk_RegisterElement(interp,
	theme, "trough", &TroughElementSpec, NULL);
    Ttk_RegisterElement(interp,
	theme, "thumb", &ThumbElementSpec, NULL);
    Ttk_RegisterElement(interp,
	theme, "uparrow", &ArrowElementSpec, &ArrowElements[0]);
    Ttk_RegisterElement(interp,
	theme, "downarrow", &ArrowElementSpec, &ArrowElements[1]);
    Ttk_RegisterElement(interp,
	theme, "leftarrow", &ArrowElementSpec, &ArrowElements[2]);
    Ttk_RegisterElement(interp,
	theme, "rightarrow", &ArrowElementSpec, &ArrowElements[3]);

	    &ArrowElementSpec, INT2PTR(ARROW_LEFT));
    Ttk_RegisterElement(interp, theme, "rightarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_RIGHT));
    Ttk_RegisterElement(interp, theme, "arrow",
    Ttk_RegisterElement(interp,
	theme, "Radiobutton.indicator", &RadioIndicatorElementSpec, NULL);
    Ttk_RegisterElement(interp,
	    &ArrowElementSpec, INT2PTR(ARROW_UP));

    Ttk_RegisterElement(interp, theme, "Checkbutton.indicator",
	theme, "Checkbutton.indicator", &CheckIndicatorElementSpec, NULL);
	    &IndicatorElementSpec, (void *)&checkbutton_spec);
    Ttk_RegisterElement(interp, theme, "Radiobutton.indicator",
	    &IndicatorElementSpec, (void *)&radiobutton_spec);
    Ttk_RegisterElement(interp,
	theme, "Menubutton.indicator", &MenuIndicatorElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "tab", &TabElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "client", &ClientElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "slider", &SliderElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "bar", &PbarElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "pbar", &PbarElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "hgrip",
	    &GripElementSpec,  INT2PTR(TTK_ORIENT_HORIZONTAL));
	    &GripElementSpec,  &GripClientData[0]);
    Ttk_RegisterElement(interp, theme, "vgrip",
	    &GripElementSpec,  INT2PTR(TTK_ORIENT_VERTICAL));
	    &GripElementSpec,  &GripClientData[1]);

    Ttk_RegisterLayouts(theme, LayoutTable);

    Tcl_PkgProvide(interp, "ttk::theme::clam", TTK_VERSION);

    return TCL_OK;
}

Changes to generic/ttk/ttkClassicTheme.c.

1
2

3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26

27
28
29


30
31
32
33
34

35
36
37
38

39
40

41
42
43
44
45
46
47
48
49

50
51

52
53
54
55

56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
1

2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27

28
29


30
31
32
33
34


35




36
37

38
39
40
41
42
43
44
45


46


47


48

49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67

-
+





-
+
+
+















-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
+







-
-
+
-
-
+
-
-

-
+










-
+







/*
 * Copyright © 2004, Joe English
 * Copyright (c) 2004, Joe English
 *
 * "classic" theme; implements the classic Motif-like Tk look.
 *
 */

#include "tkInt.h"
#include <tk.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "ttkTheme.h"

#define DEFAULT_BORDERWIDTH "2"
#define DEFAULT_ARROW_SIZE "15"

/*----------------------------------------------------------------------
 * +++ Highlight element implementation.
 * 	Draw a solid highlight border to indicate focus.
 */

typedef struct {
    Tcl_Obj	*highlightColorObj;
    Tcl_Obj	*highlightThicknessObj;
} HighlightElement;

static const Ttk_ElementOptionSpec HighlightElementOptions[] = {
static Ttk_ElementOptionSpec HighlightElementOptions[] = {
    { "-highlightcolor",TK_OPTION_COLOR,
	offsetof(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND },
	Tk_Offset(HighlightElement,highlightColorObj), DEFAULT_BACKGROUND },
    { "-highlightthickness",TK_OPTION_PIXELS,
	offsetof(HighlightElement,highlightThicknessObj), "0" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(HighlightElement,highlightThicknessObj), "0" },
    { NULL, 0, 0, NULL }
};

static void HighlightElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    HighlightElement *hl = (HighlightElement *)elementRecord;
    HighlightElement *hl = elementRecord;
    int highlightThickness = 0;

    Tcl_GetIntFromObj(NULL,hl->highlightThicknessObj,&highlightThickness);
    *paddingPtr = Ttk_UniformPadding((short)highlightThickness);
}

static void HighlightElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_Box),
    TCL_UNUSED(Ttk_State))
{
    HighlightElement *hl = (HighlightElement *)elementRecord;
    HighlightElement *hl = elementRecord;
    int highlightThickness = 0;
    XColor *highlightColor = Tk_GetColorFromObj(tkwin, hl->highlightColorObj);

    Tcl_GetIntFromObj(NULL,hl->highlightThicknessObj,&highlightThickness);
    if (highlightColor && highlightThickness > 0) {
	GC gc = Tk_GCForColor(highlightColor, d);
	Tk_DrawFocusHighlight(tkwin, gc, highlightThickness, d);
    }
}

static const Ttk_ElementSpec HighlightElementSpec =
static Ttk_ElementSpec HighlightElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(HighlightElement),
    HighlightElementOptions,
    HighlightElementSize,
    HighlightElementDraw
};
85
86
87
88
89
90
91
92

93
94
95

96
97

98
99

100
101
102


103
104
105
106
107

108
109
110
111

112
113
114


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135

136
137
138
139

140
141
142

143
144
145
146
147
148
149
79
80
81
82
83
84
85

86
87
88

89
90

91
92

93
94


95
96
97
98
99


100




101
102


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121


122


123


124

125
126
127

128
129
130
131
132
133
134
135







-
+


-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
-
+
+

















-
-
+
-
-
+
-
-

-
+


-
+







typedef struct {
    Tcl_Obj	*borderObj;
    Tcl_Obj	*borderWidthObj;
    Tcl_Obj	*reliefObj;
    Tcl_Obj	*defaultStateObj;
} ButtonBorderElement;

static const Ttk_ElementOptionSpec ButtonBorderElementOptions[] =
static Ttk_ElementOptionSpec ButtonBorderElementOptions[] =
{
    { "-background", TK_OPTION_BORDER,
	offsetof(ButtonBorderElement,borderObj), DEFAULT_BACKGROUND },
	Tk_Offset(ButtonBorderElement,borderObj), DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(ButtonBorderElement,borderWidthObj), DEFAULT_BORDERWIDTH },
	Tk_Offset(ButtonBorderElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(ButtonBorderElement,reliefObj), "flat" },
	Tk_Offset(ButtonBorderElement,reliefObj), "flat" },
    { "-default", TK_OPTION_ANY,
	offsetof(ButtonBorderElement,defaultStateObj), "disabled" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(ButtonBorderElement,defaultStateObj), "disabled" },
    { NULL, 0, 0, NULL }
};

static void ButtonBorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    ButtonBorderElement *bd = elementRecord;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int borderWidth = 0;

    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
    Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState);

    if (defaultState != TTK_BUTTON_DEFAULT_DISABLED) {
	borderWidth += 5;
    }
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

/*
 * (@@@ Note: ButtonBorderElement still still still buggy:
 * padding for default ring is drawn in the wrong color
 * when the button is active.)
 */
static void ButtonBorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord;
    ButtonBorderElement *bd = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 1, relief = TK_RELIEF_FLAT;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int inset = 0;

    /*
     * Get option values.
     */
    border = Tk_Get3DBorderFromObj(tkwin, bd->borderObj);
    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
459

460
461

462
463

464
465

466
467
468


469
470
471
472
473

474
475

476
477
478
479

480
481
482
483
484
485
486
487
488

489
490
491
492


493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183






















































































































































































































































184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201

202
203

204
205

206
207


208
209
210
211
212


213


214


215

216
217
218
219
220
221
222
223
224

225

226


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244







-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







+








-
+

-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+








-
+
-

-
-
+
+








+







    if (border && borderWidth > 0) {
	Tk_Draw3DRectangle(tkwin, d, border,
	    b.x+inset, b.y+inset, b.width - 2*inset, b.height - 2*inset,
	    borderWidth,relief);
    }
}

static const Ttk_ElementSpec ButtonBorderElementSpec =
static Ttk_ElementSpec ButtonBorderElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(ButtonBorderElement),
    ButtonBorderElementOptions,
    ButtonBorderElementSize,
    ButtonBorderElementDraw
};

/*----------------------------------------------------------------------
 * +++ Indicator element.
 *
 * Draws the on/off indicator for checkbuttons and radiobuttons.
 *
 * Draws a 3-D square (or diamond), raised if off, sunken if on.
 *
 * This is actually a regression from Tk 8.5 back to the ugly old Motif
 * style; use the "alt", "clam", or "default" theme" for newer, nicer
 * versions.
 */

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *marginObj;
    Tcl_Obj *borderWidthObj;
} IndicatorElement;

static const Ttk_ElementOptionSpec IndicatorElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-indicatorcolor", TK_OPTION_BORDER,
	offsetof(IndicatorElement,colorObj), DEFAULT_BACKGROUND },
    { "-indicatorrelief", TK_OPTION_RELIEF,
	offsetof(IndicatorElement,reliefObj), "raised" },
    { "-indicatorsize", TK_OPTION_PIXELS,
	offsetof(IndicatorElement,sizeObj), "9p" },
    { "-indicatormargin", TK_OPTION_STRING,
	offsetof(IndicatorElement,marginObj), "0 2 4 2" },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(IndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
};

/*
 * Checkbutton indicators: 3-D square.
 */
static void SquareIndicatorElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    Ttk_Padding margins;
    int diameter = 0;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &diameter);
    *widthPtr = diameter + Ttk_PaddingWidth(margins);
    *heightPtr = diameter + Ttk_PaddingHeight(margins);
}

static void SquareIndicatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    Tk_3DBorder border = 0, interior = 0;
    int relief = TK_RELIEF_RAISED;
    Ttk_Padding padding;
    int borderWidth = 2;
    int diameter;

    interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj);
    border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj);
    Tcl_GetIntFromObj(NULL,indicator->borderWidthObj,&borderWidth);
    Tk_GetReliefFromObj(NULL,indicator->reliefObj,&relief);
    Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginObj,&padding);

    b = Ttk_PadBox(b, padding);

    diameter = b.width < b.height ? b.width : b.height;
    Tk_Fill3DRectangle(tkwin, d, interior, b.x, b.y,
	    diameter, diameter,borderWidth, TK_RELIEF_FLAT);
    Tk_Draw3DRectangle(tkwin, d, border, b.x, b.y,
	    diameter, diameter, borderWidth, relief);
}

/*
 * Radiobutton indicators: 3-D diamond.
 */
static void DiamondIndicatorElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    Ttk_Padding margins;
    int diameter = 0;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &diameter);
    *widthPtr = diameter + 3 + Ttk_PaddingWidth(margins);
    *heightPtr = diameter + 3 + Ttk_PaddingHeight(margins);
}

static void DiamondIndicatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    Tk_3DBorder border = 0, interior = 0;
    int borderWidth = 2;
    int relief = TK_RELIEF_RAISED;
    int diameter, radius;
    XPoint points[4];
    Ttk_Padding padding;

    interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj);
    border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj);
    Tcl_GetIntFromObj(NULL,indicator->borderWidthObj,&borderWidth);
    Tk_GetReliefFromObj(NULL,indicator->reliefObj,&relief);
    Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginObj,&padding);

    b = Ttk_PadBox(b, padding);

    diameter = b.width < b.height ? b.width : b.height;
    radius = diameter / 2;

    points[0].x = b.x;
    points[0].y = b.y + radius;
    points[1].x = b.x + radius;
    points[1].y = b.y + 2*radius;
    points[2].x = b.x + 2*radius;
    points[2].y = b.y + radius;
    points[3].x = b.x + radius;
    points[3].y = b.y;

    Tk_Fill3DPolygon(tkwin,d,interior,points,4,borderWidth,TK_RELIEF_FLAT);
    Tk_Draw3DPolygon(tkwin,d,border,points,4,borderWidth,relief);
}

static const Ttk_ElementSpec CheckbuttonIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    SquareIndicatorElementSize,
    SquareIndicatorElementDraw
};

static const Ttk_ElementSpec RadiobuttonIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    DiamondIndicatorElementSize,
    DiamondIndicatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Menubutton indicators.
 *
 * These aren't functional like radio/check indicators,
 * they're just affordability indicators.
 *
 * Standard Tk sets the indicator size to 4.0 mm by 1.7 mm.
 * I have no idea where these numbers came from.
 */

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *widthObj;
    Tcl_Obj *heightObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *marginObj;
} MenuIndicatorElement;

static const Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(MenuIndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-indicatorwidth", TK_OPTION_PIXELS,
	offsetof(MenuIndicatorElement,widthObj), "4.0m" },
    { "-indicatorheight", TK_OPTION_PIXELS,
	offsetof(MenuIndicatorElement,heightObj), "1.7m" },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(MenuIndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { "-indicatorrelief", TK_OPTION_RELIEF,
	offsetof(MenuIndicatorElement,reliefObj),"raised" },
    { "-indicatormargin", TK_OPTION_STRING,
	offsetof(MenuIndicatorElement,marginObj), "5 0" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
};

static void MenuIndicatorElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    MenuIndicatorElement *mi = (MenuIndicatorElement *)elementRecord;
    Ttk_Padding margins;

    Tk_GetPixelsFromObj(NULL, tkwin, mi->widthObj, widthPtr);
    Tk_GetPixelsFromObj(NULL, tkwin, mi->heightObj, heightPtr);
    Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj, &margins);
    *widthPtr += Ttk_PaddingWidth(margins);
    *heightPtr += Ttk_PaddingHeight(margins);
}

static void MenuIndicatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    MenuIndicatorElement *mi = (MenuIndicatorElement *)elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, mi->backgroundObj);
    Ttk_Padding margins;
    int borderWidth = 2;

    Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj,&margins);
    b = Ttk_PadBox(b, margins);
    Tk_GetPixelsFromObj(NULL, tkwin, mi->borderWidthObj, &borderWidth);
    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, TK_RELIEF_RAISED);
}

static const Ttk_ElementSpec MenuIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(MenuIndicatorElement),
    MenuIndicatorElementOptions,
    MenuIndicatorElementSize,
    MenuIndicatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Arrow element(s).
 *
 * Draws a 3-D shaded triangle.
 * clientData is an enum ArrowDirection pointer.
 */

static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT };
typedef struct
{
    Tcl_Obj *sizeObj;
    Tcl_Obj *borderObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
} ArrowElement;

static const Ttk_ElementOptionSpec ArrowElementOptions[] =
static Ttk_ElementOptionSpec ArrowElementOptions[] =
{
    { "-arrowsize", TK_OPTION_PIXELS, offsetof(ArrowElement,sizeObj),
    { "-arrowsize", TK_OPTION_PIXELS, Tk_Offset(ArrowElement,sizeObj),
	DEFAULT_ARROW_SIZE },
    { "-background", TK_OPTION_BORDER, offsetof(ArrowElement,borderObj),
    { "-background", TK_OPTION_BORDER, Tk_Offset(ArrowElement,borderObj),
    	DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS, offsetof(ArrowElement,borderWidthObj),
    { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(ArrowElement,borderWidthObj),
    	DEFAULT_BORDERWIDTH },
    { "-relief", TK_OPTION_RELIEF, offsetof(ArrowElement,reliefObj),"raised" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { "-relief", TK_OPTION_RELIEF, Tk_Offset(ArrowElement,reliefObj),"raised" },
    { NULL, 0, 0, NULL }
};

static void ArrowElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowElement *arrow = elementRecord;
    int size = 12;

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    *widthPtr = *heightPtr = size;
}

static void ArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    int direction = *(int *)clientData;
    ArrowElement *arrow = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    int borderWidth = 2;
    int relief = TK_RELIEF_RAISED;
    int size = b.width < b.height ? b.width : b.height;
    XPoint points[3];

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief);


    /*
     * @@@ There are off-by-one pixel errors in the way these are drawn;
     * @@@ need to take a look at Tk_Fill3DPolygon and X11 to find the
     * @@@ exact rules.
     */
    switch (direction)
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670




671
672
673
674
675
676
677
678
679
680
681

682
683

684
685

686
687

688
689

690
691

692
693
694


695
696
697
698
699

700
701
702

703
704

705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721

722
723
724

725
726
727
728
729

730
731
732
733
734
735
736
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279


















































































































280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309

310
311

312
313

314
315

316
317

318
319


320
321
322
323
324
325

326

327

328
329

330
331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
346

347

348

349
350
351
352
353

354
355
356
357
358
359
360
361







-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














+
+
+
+










-
+

-
+

-
+

-
+

-
+

-
+

-
-
+
+




-
+
-

-
+

-
+








-
+







-
+
-

-
+




-
+







	    points[2].x = b.x;		points[2].y = b.y + size;
	    break;
    }

    Tk_Fill3DPolygon(tkwin, d, border, points, 3, borderWidth, relief);
}

static const Ttk_ElementSpec ArrowElementSpec =
static Ttk_ElementSpec ArrowElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    ArrowElementSize,
    ArrowElementDraw
};

/*------------------------------------------------------------------------
 * +++ Slider element.
 *
 * This is the moving part of the scale widget.  Drawn as a raised box.
 */

typedef struct {
    Tcl_Obj *orientObj;	     /* orientation of overall slider */
    Tcl_Obj *lengthObj;      /* slider length */
    Tcl_Obj *thicknessObj;   /* slider thickness */
    Tcl_Obj *reliefObj;      /* the relief for this object */
    Tcl_Obj *borderObj;      /* the background color */
    Tcl_Obj *borderWidthObj; /* the size of the border */
} SliderElement;

static const Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-sliderlength", TK_OPTION_PIXELS, offsetof(SliderElement,lengthObj),
	"30" },
    { "-sliderthickness",TK_OPTION_PIXELS, offsetof(SliderElement,thicknessObj),
	"15" },
    { "-sliderrelief", TK_OPTION_RELIEF, offsetof(SliderElement,reliefObj),
	"raised" },
    { "-borderwidth", TK_OPTION_PIXELS, offsetof(SliderElement,borderWidthObj),
	DEFAULT_BORDERWIDTH },
    { "-background", TK_OPTION_BORDER, offsetof(SliderElement,borderObj),
	DEFAULT_BACKGROUND },
    { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj),
	"horizontal" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
};

static void SliderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    SliderElement *slider = (SliderElement *)elementRecord;
    Ttk_Orient orient;
    int length, thickness;

    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->lengthObj, &length);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness);

    switch (orient) {
	case TTK_ORIENT_VERTICAL:
	    *widthPtr = thickness;
	    *heightPtr = length;
	    break;

	case TTK_ORIENT_HORIZONTAL:
	    *widthPtr = length;
	    *heightPtr = thickness;
	    break;
    }
}

static void SliderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SliderElement *slider = (SliderElement *)elementRecord;
    Tk_3DBorder border = NULL;
    int relief = TK_RELIEF_RAISED, borderWidth = 2;
    Ttk_Orient orient;

    border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj);
    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border,
	b.x, b.y, b.width, b.height,
	borderWidth, relief);

    if (relief != TK_RELIEF_FLAT) {
	if (orient == TTK_ORIENT_HORIZONTAL) {
	    if (b.width > 4) {
		b.x += b.width/2;
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		    b.x-1, b.y+borderWidth, b.x-1, b.y+b.height-borderWidth);
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		    b.x, b.y+borderWidth, b.x, b.y+b.height-borderWidth);
	    }
	} else {
	    if (b.height > 4) {
		b.y += b.height/2;
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		    b.x+borderWidth, b.y-1, b.x+b.width-borderWidth, b.y-1);
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		    b.x+borderWidth, b.y, b.x+b.width-borderWidth, b.y);
	    }
	}
    }
}

static const Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SliderElement),
    SliderElementOptions,
    SliderElementSize,
    SliderElementDraw
};

/*------------------------------------------------------------------------
 * +++ Sash element (for ttk::panedwindow)
 *
 * NOTES:
 *
 * panedwindows with -orient horizontal use vertical sashes, and vice versa.
 *
 * Interpretation of -sashrelief 'groove' and 'ridge' are
 * swapped wrt. the core panedwindow, which (I think) has them backwards.
 *
 * Default -sashrelief is sunken; the core panedwindow has default
 * -sashrelief raised, but that looks wrong to me.
 */

static Ttk_Orient SashClientData[] = {
    TTK_ORIENT_HORIZONTAL, TTK_ORIENT_VERTICAL
};

typedef struct {
    Tcl_Obj *borderObj; 	/* background color */
    Tcl_Obj *sashReliefObj;	/* sash relief */
    Tcl_Obj *sashThicknessObj;	/* overall thickness of sash */
    Tcl_Obj *sashPadObj;	/* padding on either side of handle */
    Tcl_Obj *handleSizeObj;	/* handle width and height */
    Tcl_Obj *handlePadObj;	/* handle's distance from edge */
} SashElement;

static const Ttk_ElementOptionSpec SashOptions[] = {
static Ttk_ElementOptionSpec SashOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(SashElement,borderObj), DEFAULT_BACKGROUND },
	Tk_Offset(SashElement,borderObj), DEFAULT_BACKGROUND },
    { "-sashrelief", TK_OPTION_RELIEF,
	offsetof(SashElement,sashReliefObj), "sunken" },
	Tk_Offset(SashElement,sashReliefObj), "sunken" },
    { "-sashthickness", TK_OPTION_PIXELS,
	offsetof(SashElement,sashThicknessObj), "6" },
	Tk_Offset(SashElement,sashThicknessObj), "6" },
    { "-sashpad", TK_OPTION_PIXELS,
	offsetof(SashElement,sashPadObj), "2" },
	Tk_Offset(SashElement,sashPadObj), "2" },
    { "-handlesize", TK_OPTION_PIXELS,
	offsetof(SashElement,handleSizeObj), "8" },
	Tk_Offset(SashElement,handleSizeObj), "8" },
    { "-handlepad", TK_OPTION_PIXELS,
	offsetof(SashElement,handlePadObj), "8" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(SashElement,handlePadObj), "8" },
    { NULL, 0, 0, NULL }
};

static void SashElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    SashElement *sash = (SashElement *)elementRecord;
    SashElement *sash = elementRecord;
    int sashPad = 2, sashThickness = 6, handleSize = 8;
    Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
    int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL;

    Tk_GetPixelsFromObj(NULL, tkwin, sash->sashThicknessObj, &sashThickness);
    Tk_GetPixelsFromObj(NULL, tkwin, sash->handleSizeObj, &handleSize);
    Tk_GetPixelsFromObj(NULL, tkwin, sash->sashPadObj, &sashPad);

    if (sashThickness < handleSize + 2*sashPad)
	sashThickness = handleSize + 2*sashPad;

    if (orient == TTK_ORIENT_HORIZONTAL)
    if (horizontal)
	*heightPtr = sashThickness;
    else
	*widthPtr = sashThickness;
}

static void SashElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    Drawable d, Ttk_Box b, Ttk_State state)
    TCL_UNUSED(Ttk_State))
{
    SashElement *sash = (SashElement *)elementRecord;
    SashElement *sash = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, sash->borderObj);
    GC gc1,gc2;
    int relief = TK_RELIEF_RAISED;
    int handleSize = 8, handlePad = 8;
    Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
    int horizontal = *((Ttk_Orient*)clientData) == TTK_ORIENT_HORIZONTAL;
    Ttk_Box hb;

    Tk_GetPixelsFromObj(NULL, tkwin, sash->handleSizeObj, &handleSize);
    Tk_GetPixelsFromObj(NULL, tkwin, sash->handlePadObj, &handlePad);
    Tk_GetReliefFromObj(NULL, sash->sashReliefObj, &relief);

    switch (relief) {
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769

770
771
772
773
774
775
776
777
778
779
780
781

782
783
784
785
786
787
788
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413







-
+












-
+











-
+







	default:
	    gc1 = gc2 = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	    break;
    }

    /* Draw sash line:
     */
    if (orient == TTK_ORIENT_HORIZONTAL) {
    if (horizontal) {
	int y = b.y + b.height/2 - 1;
	XDrawLine(Tk_Display(tkwin), d, gc1, b.x, y, b.x+b.width, y); ++y;
	XDrawLine(Tk_Display(tkwin), d, gc2, b.x, y, b.x+b.width, y);
    } else {
	int x = b.x + b.width/2 - 1;
	XDrawLine(Tk_Display(tkwin), d, gc1, x, b.y, x, b.y+b.height); ++x;
	XDrawLine(Tk_Display(tkwin), d, gc2, x, b.y, x, b.y+b.height);
    }

    /* Draw handle:
     */
    if (handleSize >= 0) {
	if (orient == TTK_ORIENT_HORIZONTAL) {
	if (horizontal) {
	    hb = Ttk_StickBox(b, handleSize, handleSize, TTK_STICK_W);
	    hb.x += handlePad;
	} else {
	    hb = Ttk_StickBox(b, handleSize, handleSize, TTK_STICK_N);
	    hb.y += handlePad;
	}
	Tk_Fill3DRectangle(tkwin, d, border,
	    hb.x, hb.y, hb.width, hb.height, 1, TK_RELIEF_RAISED);
    }
}

static const Ttk_ElementSpec SashElementSpec = {
static Ttk_ElementSpec SashElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SashElement),
    SashOptions,
    SashElementSize,
    SashElementDraw
};

812
813
814
815
816
817
818
819

820
821
822
823
824
825
826
437
438
439
440
441
442
443

444
445
446
447
448
449
450
451







-
+







	        TTK_NODE("Radiobutton.indicator", TTK_PACK_LEFT)
	        TTK_NODE("Radiobutton.label", TTK_PACK_LEFT|TTK_FILL_BOTH)))))

TTK_LAYOUT("TMenubutton",
    TTK_GROUP("Menubutton.highlight", TTK_FILL_BOTH,
        TTK_GROUP("Menubutton.border", TTK_FILL_BOTH,
	    TTK_NODE("Menubutton.indicator", TTK_PACK_RIGHT)
	    TTK_GROUP("Menubutton.padding", TTK_FILL_X,
	    TTK_GROUP("Menubutton.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_X,
	        TTK_NODE("Menubutton.label", 0)))))

/* "classic" entry, includes highlight border */
TTK_LAYOUT("TEntry",
    TTK_GROUP("Entry.highlight", TTK_FILL_BOTH,
        TTK_GROUP("Entry.field", TTK_FILL_BOTH|TTK_BORDER,
	    TTK_GROUP("Entry.padding", TTK_FILL_BOTH,
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872

873
874

875
876

877
878

879
880

881
882
883
884
885
886

887
888

889
890
891
892
893
894
895
896
897
898
899
900
463
464
465
466
467
468
469


470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486







487

488
489

490
491

492
493

494
495

496
497



498

499
500

501
502
503
504
505
506
507
508
509
510
511
512
513







-
-

















-
-
-
-
-
-
-

-
+

-
+

-
+

-
+

-
+

-
-
-

-
+

-
+












 */

/*------------------------------------------------------------------------
 * TtkClassicTheme_Init --
 * 	Install classic theme.
 */

MODULE_SCOPE int TtkClassicTheme_Init(Tcl_Interp *interp);

MODULE_SCOPE int TtkClassicTheme_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_CreateTheme(interp, "classic", NULL);

    if (!theme) {
	return TCL_ERROR;
    }

    /*
     * Register elements:
     */
    Ttk_RegisterElement(interp, theme, "highlight",
	    &HighlightElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "Button.border",
	    &ButtonBorderElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "Checkbutton.indicator",
	    &CheckbuttonIndicatorElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "Radiobutton.indicator",
	    &RadiobuttonIndicatorElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "Menubutton.indicator",
	    &MenuIndicatorElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "uparrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);
    Ttk_RegisterElement(interp, theme, "downarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_DOWN));
	    &ArrowElementSpec, &ArrowElements[1]);
    Ttk_RegisterElement(interp, theme, "leftarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_LEFT));
	    &ArrowElementSpec, &ArrowElements[2]);
    Ttk_RegisterElement(interp, theme, "rightarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_RIGHT));
	    &ArrowElementSpec, &ArrowElements[3]);
    Ttk_RegisterElement(interp, theme, "arrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);

    Ttk_RegisterElement(interp, theme, "slider",
	    &SliderElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "hsash",
	    &SashElementSpec, INT2PTR(TTK_ORIENT_HORIZONTAL));
	    &SashElementSpec, &SashClientData[0]);
    Ttk_RegisterElement(interp, theme, "vsash",
	    &SashElementSpec, INT2PTR(TTK_ORIENT_VERTICAL));
	    &SashElementSpec, &SashClientData[1]);

    /*
     * Register layouts:
     */
    Ttk_RegisterLayouts(theme, LayoutTable);

    Tcl_PkgProvide(interp, "ttk::theme::classic", TTK_VERSION);

    return TCL_OK;
}

/*EOF*/

Changes to generic/ttk/ttkDecls.h.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
9
10
11
12
13
14
15

16
17
18









19
20
21
22
23
24
25







-
+


-
-
-
-
-
-
-
-
-








extern const char *TtkInitializeStubs(
	Tcl_Interp *, const char *version, int epoch, int revision);
#define Ttk_InitStubs(interp) TtkInitializeStubs( \
	interp, TTK_VERSION, TTK_STUBS_EPOCH, TTK_STUBS_REVISION)
#else

#define Ttk_InitStubs(interp) Tcl_PkgRequireEx(interp, "ttk", TTK_VERSION, 0, NULL)
#define Ttk_InitStubs(interp) Tcl_PkgRequireEx(interp, "Ttk", TTK_VERSION, 0, NULL)

#endif

#if !defined(BUILD_tk)
# define TTK_DEPRECATED(msg) TTKAPI TCL_DEPRECATED_API(msg)
#elif defined(TK_NO_DEPRECATED)
# define TTK_DEPRECATED(msg) MODULE_SCOPE
#else
# define TTK_DEPRECATED(msg) TTKAPI
#endif



/* !BEGIN!: Do not edit below this line. */

#define TTK_STUBS_EPOCH 0
#define TTK_STUBS_REVISION 31

52
53
54
55
56
57
58
59

60
61
62
63
64

65
66
67
68
69
70
71
43
44
45
46
47
48
49

50
51
52
53
54

55
56
57
58
59
60
61
62







-
+




-
+







/* 4 */
TTKAPI void		Ttk_RegisterCleanup(Tcl_Interp *interp,
				void *deleteData,
				Ttk_CleanupProc *cleanupProc);
/* 5 */
TTKAPI int		Ttk_RegisterElementSpec(Ttk_Theme theme,
				const char *elementName,
				const Ttk_ElementSpec *elementSpec,
				Ttk_ElementSpec *elementSpec,
				void *clientData);
/* 6 */
TTKAPI Ttk_ElementClass * Ttk_RegisterElement(Tcl_Interp *interp,
				Ttk_Theme theme, const char *elementName,
				const Ttk_ElementSpec *elementSpec,
				Ttk_ElementSpec *elementSpec,
				void *clientData);
/* 7 */
TTKAPI int		Ttk_RegisterElementFactory(Tcl_Interp *interp,
				const char *name,
				Ttk_ElementFactory factoryProc,
				void *clientData);
/* 8 */
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87







-
+







/* 12 */
TTKAPI Ttk_StateMap	Ttk_GetStateMapFromObj(Tcl_Interp *interp,
				Tcl_Obj *objPtr);
/* 13 */
TTKAPI Tcl_Obj *	Ttk_StateMapLookup(Tcl_Interp *interp,
				Ttk_StateMap map, Ttk_State state);
/* 14 */
TTKAPI int		Ttk_StateTableLookup(const Ttk_StateTable *map,
TTKAPI int		Ttk_StateTableLookup(Ttk_StateTable map[],
				Ttk_State state);
/* Slot 15 is reserved */
/* Slot 16 is reserved */
/* Slot 17 is reserved */
/* Slot 18 is reserved */
/* Slot 19 is reserved */
/* 20 */
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157


158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+












-
-
+
+







-
+







TTKAPI Tcl_Obj *	Ttk_NewBoxObj(Ttk_Box box);
/* Slot 36 is reserved */
/* Slot 37 is reserved */
/* Slot 38 is reserved */
/* Slot 39 is reserved */
/* 40 */
TTKAPI int		Ttk_GetOrientFromObj(Tcl_Interp *interp,
				Tcl_Obj *objPtr, Ttk_Orient *orient);
				Tcl_Obj *objPtr, int *orient);

typedef struct TtkStubs {
    int magic;
    int epoch;
    int revision;
    void *hooks;

    Ttk_Theme (*ttk_GetTheme) (Tcl_Interp *interp, const char *name); /* 0 */
    Ttk_Theme (*ttk_GetDefaultTheme) (Tcl_Interp *interp); /* 1 */
    Ttk_Theme (*ttk_GetCurrentTheme) (Tcl_Interp *interp); /* 2 */
    Ttk_Theme (*ttk_CreateTheme) (Tcl_Interp *interp, const char *name, Ttk_Theme parent); /* 3 */
    void (*ttk_RegisterCleanup) (Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc); /* 4 */
    int (*ttk_RegisterElementSpec) (Ttk_Theme theme, const char *elementName, const Ttk_ElementSpec *elementSpec, void *clientData); /* 5 */
    Ttk_ElementClass * (*ttk_RegisterElement) (Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, const Ttk_ElementSpec *elementSpec, void *clientData); /* 6 */
    int (*ttk_RegisterElementSpec) (Ttk_Theme theme, const char *elementName, Ttk_ElementSpec *elementSpec, void *clientData); /* 5 */
    Ttk_ElementClass * (*ttk_RegisterElement) (Tcl_Interp *interp, Ttk_Theme theme, const char *elementName, Ttk_ElementSpec *elementSpec, void *clientData); /* 6 */
    int (*ttk_RegisterElementFactory) (Tcl_Interp *interp, const char *name, Ttk_ElementFactory factoryProc, void *clientData); /* 7 */
    void (*ttk_RegisterLayout) (Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec); /* 8 */
    void (*reserved9)(void);
    int (*ttk_GetStateSpecFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_StateSpec *spec_rtn); /* 10 */
    Tcl_Obj * (*ttk_NewStateSpecObj) (unsigned int onbits, unsigned int offbits); /* 11 */
    Ttk_StateMap (*ttk_GetStateMapFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr); /* 12 */
    Tcl_Obj * (*ttk_StateMapLookup) (Tcl_Interp *interp, Ttk_StateMap map, Ttk_State state); /* 13 */
    int (*ttk_StateTableLookup) (const Ttk_StateTable *map, Ttk_State state); /* 14 */
    int (*ttk_StateTableLookup) (Ttk_StateTable map[], Ttk_State state); /* 14 */
    void (*reserved15)(void);
    void (*reserved16)(void);
    void (*reserved17)(void);
    void (*reserved18)(void);
    void (*reserved19)(void);
    int (*ttk_GetPaddingFromObj) (Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, Ttk_Padding *pad_rtn); /* 20 */
    int (*ttk_GetBorderFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Padding *pad_rtn); /* 21 */
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189







-
+







    Ttk_Box (*ttk_ExpandBox) (Ttk_Box b, Ttk_Padding p); /* 33 */
    Ttk_Box (*ttk_PlaceBox) (Ttk_Box *cavity, int w, int h, Ttk_Side side, Ttk_Sticky sticky); /* 34 */
    Tcl_Obj * (*ttk_NewBoxObj) (Ttk_Box box); /* 35 */
    void (*reserved36)(void);
    void (*reserved37)(void);
    void (*reserved38)(void);
    void (*reserved39)(void);
    int (*ttk_GetOrientFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Orient *orient); /* 40 */
    int (*ttk_GetOrientFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *orient); /* 40 */
} TtkStubs;

extern const TtkStubs *ttkStubsPtr;

#ifdef __cplusplus
}
#endif

Changes to generic/ttk/ttkDefaultTheme.c.

1
2

3
4
5
6
7
8







9
10
11

12
13

14
15
16
17
18
19
20
21
22
23
24
1

2
3
4
5
6


7
8
9
10
11
12
13
14
15

16
17

18




19
20
21
22
23
24
25

-
+




-
-
+
+
+
+
+
+
+


-
+

-
+
-
-
-
-







/*
 * Copyright © 2003 Joe English
 * Copyright (c) 2003, Joe English
 *
 * Tk alternate theme, intended to match the MSUE and Gtk's (old) default theme
 */

#include "tkInt.h"
#include "ttkThemeInt.h"
#include <math.h>
#include <string.h>

#include <tkInt.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "ttkTheme.h"

#if defined(_WIN32)
  #define WIN32_XDRAWLINE_HACK 1
static const int WIN32_XDRAWLINE_HACK = 1;
#else
  #define WIN32_XDRAWLINE_HACK 0
static const int WIN32_XDRAWLINE_HACK = 0;
#endif

#if defined(MAC_OSX_TK)
  #define IGNORES_VISUAL
#endif

#define BORDERWIDTH     2
#define SCROLLBAR_WIDTH 14
#define MIN_THUMB_SIZE  8

/*
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-
+









-
+







 * Please excuse the gross misspelling "LITE" for "LIGHT",
 * but it makes things line up nicer.
 */

enum BorderColor { FLAT = 1, LITE = 2, DARK = 3, BRDR = 4 };

/* top-left outer, top-left inner, bottom-right inner, bottom-right outer */
static const enum BorderColor shadowColors[6][4] = {
static int const shadowColors[6][4] = {
    { FLAT, FLAT, FLAT, FLAT },	/* TK_RELIEF_FLAT   = 0*/
    { DARK, LITE, DARK, LITE },	/* TK_RELIEF_GROOVE = 1*/
    { LITE, FLAT, DARK, BRDR },	/* TK_RELIEF_RAISED = 2*/
    { LITE, DARK, LITE, DARK },	/* TK_RELIEF_RIDGE  = 3*/
    { BRDR, BRDR, BRDR, BRDR },	/* TK_RELIEF_SOLID  = 4*/
    { BRDR, DARK, FLAT, LITE }	/* TK_RELIEF_SUNKEN = 5*/
};

/* top-left, bottom-right */
static const enum BorderColor thinShadowColors[6][4] = {
static int const thinShadowColors[6][4] = {
    { FLAT, FLAT },	/* TK_RELIEF_FLAT   = 0*/
    { DARK, LITE },	/* TK_RELIEF_GROOVE = 1*/
    { LITE, DARK },	/* TK_RELIEF_RAISED = 2*/
    { LITE, DARK },	/* TK_RELIEF_RIDGE  = 3*/
    { BRDR, BRDR },	/* TK_RELIEF_SOLID  = 4*/
    { DARK, LITE }	/* TK_RELIEF_SUNKEN = 5*/
};
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118


119
120
121
122
123
124
125

126
127

128
129

130
131

132
133
134
135
136
137
138
139

140
141
142
143

144
145
146
147
148
149
150
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129

130
131

132
133

134
135
136
137
138
139
140
141

142
143
144
145

146
147
148
149
150
151
152
153







-
+







+
+






-
+

-
+

-
+

-
+







-
+



-
+







	    DrawCorner(tkwin, d, border, borderGC,
		b.x, b.y, b.width, b.height, 1, thinShadowColors[relief][1]);
	    break;
	case 0:	/* no border -- do nothing */
	    break;
	default: /* Fall back to Motif-style borders: */
	    Tk_Draw3DRectangle(tkwin, d, border,
		b.x, b.y, b.width, b.height, borderWidth, relief);
		b.x, b.y, b.width, b.height, borderWidth,relief);
	    break;
    }
}

/* Alternate shadow colors for entry fields:
 * NOTE: FLAT color is normally white, and the LITE color is a darker shade.
 */
static int fieldShadowColors[4] = { DARK, BRDR, LITE, FLAT };

static void DrawFieldBorder(
    Tk_Window tkwin, Drawable d, Tk_3DBorder border, XColor *borderColor,
    Ttk_Box b)
{
    GC borderGC = Tk_GCForColor(borderColor, d);
    DrawCorner(tkwin, d, border, borderGC,
	b.x, b.y, b.width, b.height, 0, DARK);
	b.x, b.y, b.width, b.height, 0,fieldShadowColors[0]);
    DrawCorner(tkwin, d, border, borderGC,
	b.x+1, b.y+1, b.width-2, b.height-2, 0, BRDR);
	b.x+1, b.y+1, b.width-2, b.height-2, 0,fieldShadowColors[1]);
    DrawCorner(tkwin, d, border, borderGC,
	b.x+1, b.y+1, b.width-2, b.height-2, 1, LITE);
	b.x+1, b.y+1, b.width-2, b.height-2, 1,fieldShadowColors[2]);
    DrawCorner(tkwin, d, border, borderGC,
	b.x, b.y, b.width, b.height, 1, FLAT);
	b.x, b.y, b.width, b.height, 1,fieldShadowColors[3]);
    return;
}

/*
 * ArrowPoints --
 * 	Compute points of arrow polygon.
 */
static void ArrowPoints(Ttk_Box b, ArrowDirection direction, XPoint points[4])
static void ArrowPoints(Ttk_Box b, ArrowDirection dir, XPoint points[4])
{
    int cx, cy, h;

    switch (direction) {
    switch (dir) {
	case ARROW_UP:
	    h = (b.width - 1)/2;
	    cx = b.x + h;
	    cy = b.y;
	    if (b.height <= h) h = b.height - 1;
	    points[0].x = cx;		points[0].y = cy;
	    points[1].x = cx - h;  	points[1].y = cy + h;
180
181
182
183
184
185
186
187

188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206

207
208
209
210
211
212
213
214
215
216

217
218
219

220
221
222
223
224
225
226
183
184
185
186
187
188
189

190
191

192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208

209
210
211
212
213
214
215
216
217
218

219
220
221

222
223
224
225
226
227
228
229







-
+

-
+













-
+


-
+









-
+


-
+







    }

    points[3].x = points[0].x;
    points[3].y = points[0].y;
}

/*public*/
void TtkArrowSize(int h, ArrowDirection direction, int *widthPtr, int *heightPtr)
void TtkArrowSize(int h, ArrowDirection dir, int *widthPtr, int *heightPtr)
{
    switch (direction) {
    switch (dir) {
	case ARROW_UP:
	case ARROW_DOWN:	*widthPtr = 2*h+1; *heightPtr = h+1; break;
	case ARROW_LEFT:
	case ARROW_RIGHT:	*widthPtr = h+1; *heightPtr = 2*h+1;
    }
}

/*
 * TtkDrawArrow, TtkFillArrow --
 * 	Draw an arrow in the indicated direction inside the specified box.
 */
/*public*/
void TtkFillArrow(
    Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection direction)
    Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection dir)
{
    XPoint points[4];
    ArrowPoints(b, direction, points);
    ArrowPoints(b, dir, points);
    XFillPolygon(display, d, gc, points, 3, Convex, CoordModeOrigin);
    XDrawLines(display, d, gc, points, 4, CoordModeOrigin);

    /* Work around bug [77527326e5] - ttk artifacts on Ubuntu */
    XDrawPoint(display, d, gc, points[2].x, points[2].y);
}

/*public*/
void TtkDrawArrow(
    Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection direction)
    Display *display, Drawable d, GC gc, Ttk_Box b, ArrowDirection dir)
{
    XPoint points[4];
    ArrowPoints(b, direction, points);
    ArrowPoints(b, dir, points);
    XDrawLines(display, d, gc, points, 4, CoordModeOrigin);

    /* Work around bug [77527326e5] - ttk artifacts on Ubuntu */
    XDrawPoint(display, d, gc, points[2].x, points[2].y);
}

/*
238
239
240
241
242
243
244
245
246


247
248
249
250


251
252

253
254

255
256

257
258
259
260
261

262
263
264
265

266
267

268
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284


285
286
287
288
289

290
291
292
293
294

295
296
297
298
299
300
301
241
242
243
244
245
246
247


248
249
250
251


252
253
254

255
256

257
258

259
260
261
262


263




264
265

266
267

268
269
270
271
272
273
274
275
276
277
278
279
280



281
282



283

284
285
286
287
288

289
290
291
292
293
294
295
296







-
-
+
+


-
-
+
+

-
+

-
+

-
+



-
-
+
-
-
-
-
+

-
+

-
+












-
-
-
+
+
-
-
-

-
+




-
+







    Tcl_Obj	*borderObj;
    Tcl_Obj	*borderColorObj;	/* Extra border color */
    Tcl_Obj	*borderWidthObj;
    Tcl_Obj	*reliefObj;
    Tcl_Obj	*defaultStateObj;	/* for buttons */
} BorderElement;

static const Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-background", TK_OPTION_BORDER, offsetof(BorderElement,borderObj),
static Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-background", TK_OPTION_BORDER, Tk_Offset(BorderElement,borderObj),
    	DEFAULT_BACKGROUND },
    { "-bordercolor",TK_OPTION_COLOR,
	offsetof(BorderElement,borderColorObj), "black" },
    { "-default", TK_OPTION_ANY, offsetof(BorderElement,defaultStateObj),
	Tk_Offset(BorderElement,borderColorObj), "black" },
    { "-default", TK_OPTION_ANY, Tk_Offset(BorderElement,defaultStateObj),
    	"disabled" },
    { "-borderwidth",TK_OPTION_PIXELS, offsetof(BorderElement,borderWidthObj),
    { "-borderwidth",TK_OPTION_PIXELS,Tk_Offset(BorderElement,borderWidthObj),
    	STRINGIFY(BORDERWIDTH) },
    { "-relief", TK_OPTION_RELIEF, offsetof(BorderElement,reliefObj),
    { "-relief", TK_OPTION_RELIEF, Tk_Offset(BorderElement,reliefObj),
    	"flat" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
        { NULL, 0, 0, NULL }
};

static void BorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    BorderElement *bd = (BorderElement *)elementRecord;
    BorderElement *bd = elementRecord;
    int borderWidth = 0;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;

    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
    Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState);

    if (defaultState != TTK_BUTTON_DEFAULT_DISABLED) {
	++borderWidth;
    }

    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void BorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    void *clientData, void *elementRecord,
    Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state)
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    BorderElement *bd = (BorderElement *)elementRecord;
    BorderElement *bd = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, bd->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, bd->borderColorObj);
    int borderWidth = 2;
    int relief = TK_RELIEF_FLAT;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;

    /*
     * Get option values.
     */
    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, bd->reliefObj, &relief);
    Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState);
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336


337
338

339
340
341
342
343
344

345
346
347
348
349
350

351
352
353

354
355
356
357
358
359
360
361


362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413

414
415
416
417



418
419

420
421
422
423
424
425
426
427
428



429
430
431
432

433
434
435
436
437
438





439
440


441
442


443
444
445
446
447
448




































449
450

451
452
453
454
455
456

457
458



459
460
461
462








463














464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504




505
506
507
508
509
510
511
512
513
514
515
516
517

518
519

520
521

522
523

524
525

526
527

528
529

530
531
532


533
534
535
536
537

538
539
540
541


542
543
544
545
546
547


548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

571

572


573
574

575
576
577
578
579
580
581
582
583
584
585


586
587
588

589
590

591
592
593

594
595
596
597
598
599
600
601
602
603
604
605


606
607

608
609
610
611
612
613
614
615




616
617

618
619

620
621
622
623
624
625
626












627
628
629
630

631
632
633
634
635
636
637
638




639
640
641
642
643
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658
659
660
661
662
663
664
665
666




667
668


669
670
671
672

673
674
675
676
677
678

679
680
681

682
683
684
685
686
687
688
689
690
691

692
693


694
695
696



697
698
699
700
701




702
703
704

705
706
707


708
709
710

711
712
713
714
715
716
717
718
719
720
721
722
723
724

725
726
727
728
729
730

731
732
733

734
735

736
737
738
739

740
741

742
743
744




745
746
747
748
749
750
751
752

753
754
755
756

757
758
759
760


761
762
763

764
765
766
767
768
769
770
771
772
773
774





775
776
777
778
779
780


781
782
783
784

785
786

787

788
789
790
791
792
793
794
795
796


797
798
799
800
801


802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830


831
832
833

834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934


935
936

937
938

939
940

941
942
943
944
945




946
947
948

949
950
951
952

953
954

955
956
957
958

959
960
961
962
963
964
965
966
967
968
969
970
971
972


973
974
975
976
977

978
979

980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024






















































































1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042


1043
1044

1045
1046

1047
1048
1049
1050



1051
1052
1053
1054
1055

1056
1057

1058
1059
1060
1061
1062


1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081

1082
1083
1084
1085

1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134




1135
1136

1137


1138

1139
1140

1141
1142
1143
1144

1145
1146

1147
1148
1149
1150
1151

1152
1153

1154
1155
1156
1157

1158
1159

1160
1161

1162
1163


1164
1165
1166
1167
1168
1169

1170
1171
1172
1173
1174
1175
1176
1177
1178
1179

1180
1181

1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220

1221
1222
1223
1224



1225
1226
1227


1228
1229
1230
1231
1232

1233
1234

1235
1236
1237
1238
1239


1240
1241
1242
1243

1244
1245


1246
1247
1248
1249
1250

1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324
325


326
327


328
329
330

331
332





333
334
335
336



337



338
339
340
341
342
343



344
345
346

347
348
349

350




































351










352




353
354
355


356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

372
373
374




375
376
377
378
379
380
381
382
383


384
385






386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422

423






424


425
426
427
428



429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452







































453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470

471
472

473
474

475
476

477
478

479
480

481
482


483
484
485
486
487
488

489

490


491
492
493


494


495
496


















497
498
499
500

501
502
503

504
505
506

507



508







509
510



511


512



513

514
515
516
517



518
519


520
521
522

523
524
525
526
527
528
529


530
531
532
533
534

535


536







537
538
539
540
541
542
543
544
545
546
547
548
549
550


551
552







553
554
555
556













557














558
559
560
561
562


563
564




565






566

567

568










569


570
571



572
573
574





575
576
577
578

579

580
581


582
583
584
585

586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609

610
611

612


613

614
615

616
617


618
619
620
621
622
623
624
625
626
627
628

629
630
631
632

633

634


635
636



637
638










639
640
641
642
643






644
645

646
647

648

649
650

651

652
653




654

655
656
657
658
659


660
661


662




663






















664
665
666
667

668
669
670
671
672
673
674
675















































































676
677
678
679
680
681
682
683
684
685
686
687
688


689
690
691

692
693

694
695

696
697




698
699
700
701
702
703

704
705
706


707


708


709

710
711



712






713


714
715
716
717
718


719


720


721

722
723
724
725
726
727
728


729
730
731
732
733
734
735
736
737
738
739
740
741
742
743







744
745
746
747
748

749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857


858
859
860

861
862

863
864



865
866
867
868
869
870


871


872


873


874
875


876
877
878
879
880
881
882
883
884
885
886
887
888


889


890


891

892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940


941
942
943
944
945

946
947
948
949

950
951

952
953



954
955

956
957
958
959


960


961


962

963


964
965
966
967


968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984


985


986


987

988
989
990
991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022

1023
1024



1025
1026
1027
1028


1029
1030
1031
1032
1033


1034


1035


1036


1037
1038
1039
1040

1041
1042


1043
1044
1045
1046
1047


1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1058







-
+














-
-


-
-
+
+

-
+

-
-
-
-
-
+



-
-
-
+
-
-
-
+





-
-
-
+
+

-
+


-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
+









+
+
+



-
+


-
-
-
-
+
+
+
+
+


+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
+
-
-
+
+
+

-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+












-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
-
+
+




-
+
-

-
-
+
+

-
-

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+

+
-
+
+

-
+
-
-
-

-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
+
-
-
-
+
-




-
-
-


-
-
+
+

-
+






-
-
+
+
+
+

-
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+

-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+
+
+
+
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-

-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
-

-
+

-
-
+
+


-
+














+


-



+


-
+

-
+
-
-

-
+

-
+

-
-
+
+
+
+







-
+



-
+
-

-
-
+
+
-
-
-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
-


-
+
-

+
-
+
-


-
-
-
-

-
+
+



-
-
+
+
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+


-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
-
+
+

-
+

-
+

-
+

-
-
-
-
+
+
+
+


-
+


-
-
+
-
-
+
-
-

-
+

-
-
-

-
-
-
-
-
-

-
-
+
+



-
-
+
-
-
+
-
-

-
+






-
-















-
-
-
-
-
-
-
+




-
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
















-
-
+
+

-
+

-
+

-
-
-
+
+
+



-
-
+
-
-
+
-
-

-
-
+
+
-
-













-
-
+
-
-
+
-
-

-
+



















-
+



















+








-
-
+
+
+
+

-
+

+
+
-
+

-
+

-
-
-
+

-
+



-
-
+
-
-
+
-
-

-
+
-
-
+


+
-
-
+
+






+








-
-
+
-
-
+
-
-

-
+













-
+

















-
+


-
+

-
-
-
+
+
+

-
-
+
+



-
-
+
-
-
+
-
-

-
-
+
+


-

+
-
-
+
+



-
-
+


-
+







	/* Space for default ring: */
	b = Ttk_PadBox(b, Ttk_UniformPadding(1));
    }

    DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief);
}

static const Ttk_ElementSpec BorderElementSpec = {
static Ttk_ElementSpec BorderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BorderElement),
    BorderElementOptions,
    BorderElementSize,
    BorderElementDraw
};

/*----------------------------------------------------------------------
 * +++ Field element:
 * 	Used for editable fields.
 */
typedef struct {
    Tcl_Obj	*borderObj;
    Tcl_Obj	*borderColorObj;	/* Extra border color */
    Tcl_Obj	*focusWidthObj;
    Tcl_Obj	*focusColorObj;
} FieldElement;

static const Ttk_ElementOptionSpec FieldElementOptions[] = {
    { "-fieldbackground", TK_OPTION_BORDER, offsetof(FieldElement,borderObj),
static Ttk_ElementOptionSpec FieldElementOptions[] = {
    { "-fieldbackground", TK_OPTION_BORDER, Tk_Offset(FieldElement,borderObj),
    	"white" },
    { "-bordercolor",TK_OPTION_COLOR, offsetof(FieldElement,borderColorObj),
    { "-bordercolor",TK_OPTION_COLOR, Tk_Offset(FieldElement,borderColorObj),
	"black" },
    { "-focuswidth", TK_OPTION_PIXELS, offsetof(FieldElement,focusWidthObj),
	"2" },
    { "-focuscolor", TK_OPTION_COLOR, offsetof(FieldElement,focusColorObj),
	"#4a6984" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { NULL, 0, 0, NULL }
};

static void FieldElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = Ttk_UniformPadding(2);
}

static void FieldElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    FieldElement *field = (FieldElement *)elementRecord;
    FieldElement *field = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, field->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, field->borderColorObj);
    int focusWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, field->focusWidthObj, &focusWidth);

    if (focusWidth > 0 && (state & TTK_STATE_FOCUS)) {
	Display *disp = Tk_Display(tkwin);
	XColor *focusColor = Tk_GetColorFromObj(tkwin, field->focusColorObj);
	GC focusGC = Tk_GCForColor(focusColor, d);

	if (focusWidth > 1) {
	    int x1 = b.x, x2 = b.x + b.width - 1;
	    int y1 = b.y, y2 = b.y + b.height - 1;
	    int w = WIN32_XDRAWLINE_HACK;

	    /*
	     * Draw the outer rounded rectangle
	     */
	    XDrawLine(disp, d, focusGC, x1+1, y1, x2-1+w, y1);	/* N */
	    XDrawLine(disp, d, focusGC, x1+1, y2, x2-1+w, y2);	/* S */
	    XDrawLine(disp, d, focusGC, x1, y1+1, x1, y2-1+w);	/* W */
	    XDrawLine(disp, d, focusGC, x2, y1+1, x2, y2-1+w);	/* E */

	    /*
	     * Draw the inner rectangle
	     */
	    b.x += 1; b.y += 1; b.width -= 2; b.height -= 2;
	    XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);

	    /*
	     * Fill the inner rectangle
	     */
	    GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	    XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
	} else {
	    /*
	     * Draw the field element as usual
	     */
	    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
    Tk_Fill3DRectangle(
		0, TK_RELIEF_SUNKEN);
	    DrawFieldBorder(tkwin, d, border, borderColor, b);

	    /*
	     * Change the color of the border's outermost pixels
	     */
	    XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
	}
    } else {
	Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	tkwin, d, border, b.x, b.y, b.width, b.height, 0, TK_RELIEF_SUNKEN);
	    0, TK_RELIEF_SUNKEN);
	DrawFieldBorder(tkwin, d, border, borderColor, b);
    }
}
    DrawFieldBorder(tkwin, d, border, borderColor, b);
}


static const Ttk_ElementSpec FieldElementSpec = {
static Ttk_ElementSpec FieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    FieldElementSize,
    FieldElementDraw
};

/*------------------------------------------------------------------------
 * Indicators --
 *
 * 	Code derived (probably incorrectly) from TIP 109 implementation,
 * 	unix/tkUnixButton.c r 1.15.
 */

/*
 * Indicator image descriptor:
 * Indicator bitmap descriptor:
 */
typedef struct {
    int width;				/* unscaled width */
    int height;				/* unscaled height */
    const char *const offDataPtr;
    const char *const onDataPtr;
    int width;		/* Width of each image */
    int height;		/* Height of each image */
    int nimages;	/* #images / row */
    const char *const *pixels;	/* array[height] of char[width*nimage] */
    Ttk_StateTable *map;/* used to look up image index by state */
} IndicatorSpec;

#if 0
/*XPM*/
static const char checkbtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
static const char *const button_images[] = {
    /* width height ncolors chars_per_pixel */
     <path d='m0 0v15h1v-14h14v-1z' fill='#888888'/>\n\
     <path d='m1 1v13h1v-12h12v-1z' fill='#414141'/>\n\
     <path d='m14 1v13h-13v1h14v-14z' fill='#d9d9d9'/>\n\
     <path d='m15 0v15h-15v1h16v-16z' fill='#eeeeee'/>\n\
     <rect x='2' y='2' width='12' height='12' fill='#ffffff'/>\n\
    </svg>";
    "52 13 8 1",
    /* colors */
    "A c #808000000000 s shadow",
    "B c #000080800000 s highlight",
    "C c #808080800000 s 3dlight",
    "D c #000000008080 s window",
    "E c #808000008080 s 3ddark",
    "F c #000080808080 s frame",
    "G c #000000000000 s foreground",
    "H c #000080800000 s disabledfg",
};
#endif

static Ttk_StateTable checkbutton_states[] = {
    { 0, 0, TTK_STATE_SELECTED|TTK_STATE_DISABLED },
    { 1, TTK_STATE_SELECTED, TTK_STATE_DISABLED },
    { 2, TTK_STATE_DISABLED, TTK_STATE_SELECTED },
    { 3, TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0 },
    { 0, 0, 0 }
};

static const char *const checkbutton_pixels[] = {
    "AAAAAAAAAAAABAAAAAAAAAAAABAAAAAAAAAAAABAAAAAAAAAAAAB",
    "AEEEEEEEEEECBAEEEEEEEEEECBAEEEEEEEEEECBAEEEEEEEEEECB",
    "AEDDDDDDDDDCBAEDDDDDDDDDCBAEFFFFFFFFFCBAEFFFFFFFFFCB",
    "AEDDDDDDDDDCBAEDDDDDDDGDCBAEFFFFFFFFFCBAEFFFFFFFHFCB",
    "AEDDDDDDDDDCBAEDDDDDDGGDCBAEFFFFFFFFFCBAEFFFFFFHHFCB",
    "AEDDDDDDDDDCBAEDGDDDGGGDCBAEFFFFFFFFFCBAEFHFFFHHHFCB",
    "AEDDDDDDDDDCBAEDGGDGGGDDCBAEFFFFFFFFFCBAEFHHFHHHFFCB",
    "AEDDDDDDDDDCBAEDGGGGGDDDCBAEFFFFFFFFFCBAEFHHHHHFFFCB",
    "AEDDDDDDDDDCBAEDDGGGDDDDCBAEFFFFFFFFFCBAEFFHHHFFFFCB",
    "AEDDDDDDDDDCBAEDDDGDDDDDCBAEFFFFFFFFFCBAEFFFHFFFFFCB",
    "AEDDDDDDDDDCBAEDDDDDDDDDCBAEFFFFFFFFFCBAEFFFFFFFFFCB",
    "ACCCCCCCCCCCBACCCCCCCCCCCBACCCCCCCCCCCBACCCCCCCCCCCB",
    "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
};

static const char checkbtnOnData[] = "\
static IndicatorSpec checkbutton_spec = {
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <path d='m0 0v15h1v-14h14v-1z' fill='#888888'/>\n\
     <path d='m1 1v13h1v-12h12v-1z' fill='#414141'/>\n\
     <path d='m14 1v13h-13v1h14v-14z' fill='#d9d9d9'/>\n\
     <path d='m15 0v15h-15v1h16v-16z' fill='#eeeeee'/>\n\
     <rect x='2' y='2' width='12' height='12' fill='#ffffff'/>\n\
    13, 13, 4,		/* width, height, nimages */
     <path d='m4.5 8 3 3 4-6' fill='none' stroke='#000000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/>\n\
    </svg>";
    checkbutton_pixels,
    checkbutton_states
};

static const IndicatorSpec checkbutton_spec = {
    16, 16,
    checkbtnOffData,
static Ttk_StateTable radiobutton_states[] = {
    { 0, 0, TTK_STATE_SELECTED|TTK_STATE_DISABLED },
    { 1, TTK_STATE_SELECTED, TTK_STATE_DISABLED },
    { 2, TTK_STATE_DISABLED, TTK_STATE_SELECTED },
    { 3, TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0 },
    { 0, 0, 0 }
};

    checkbtnOnData
static const char *const radiobutton_pixels[] = {
    "FFFFAAAAFFFFFFFFFAAAAFFFFFFFFFAAAAFFFFFFFFFAAAAFFFFF",
    "FFAAEEEEAAFFFFFAAEEEEAAFFFFFAAEEEEAAFFFFFAAEEEEAAFFF",
    "FAEEDDDDEEBFFFAEEDDDDEEBFFFAEEFFFFEEBFFFAEEFFFFEEBFF",
    "FAEDDDDDDCBFFFAEDDDDDDCBFFFAEFFFFFFCBFFFAEFFFFFFCBFF",
    "AEDDDDDDDDCBFAEDDDGGDDDCBFAEFFFFFFFFCBFAEFFFHHFFFCBF",
    "AEDDDDDDDDCBFAEDDGGGGDDCBFAEFFFFFFFFCBFAEFFHHHHFFCBF",
    "AEDDDDDDDDCBFAEDDGGGGDDCBFAEFFFFFFFFCBFAEFFHHHHFFCBF",
    "AEDDDDDDDDCBFAEDDDGGDDDCBFAEFFFFFFFFCBFAEFFFHHFFFCBF",
    "FAEDDDDDDCBFFFAEDDDDDDCBFFFAEFFFFFFCBFFFAEFFFFFFCBFF",
    "FACCDDDDCCBFFFACCDDDDCCBFFFACCFFFFCCBFFFACCFFFFCCBFF",
    "FFBBCCCCBBFFFFFBBCCCCBBFFFFFBBCCCCBBFFFFFBBCCCCBBFFF",
    "FFFFBBBBFFFFFFFFFBBBBFFFFFFFFFBBBBFFFFFFFFFBBBBFFFFF",
    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
};

static const char radiobtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradientOuter' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#888888' offset='0'/>\n\
       <stop stop-color='#eeeeee' offset='1'/>\n\
      </linearGradient>\n\
      <linearGradient id='linearGradientInner' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#414141' offset='0'/>\n\
       <stop stop-color='#d9d9d9' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradientOuter)'/>\n\
     <circle cx='8' cy='8' r='7' fill='url(#linearGradientInner)'/>\n\
     <circle cx='8' cy='8' r='6' fill='#ffffff'/>\n\
    </svg>";

static const char radiobtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradientOuter' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#888888' offset='0'/>\n\
       <stop stop-color='#eeeeee' offset='1'/>\n\
      </linearGradient>\n\
      <linearGradient id='linearGradientInner' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#414141' offset='0'/>\n\
       <stop stop-color='#d9d9d9' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradientOuter)'/>\n\
     <circle cx='8' cy='8' r='7' fill='url(#linearGradientInner)'/>\n\
     <circle cx='8' cy='8' r='6' fill='#ffffff'/>\n\
     <circle cx='8' cy='8' r='3' fill='#000000'/>\n\
    </svg>";

static const IndicatorSpec radiobutton_spec = {
    16, 16,
    radiobtnOffData,
    radiobtnOnData
static IndicatorSpec radiobutton_spec = {
    13, 13, 4,		/* width, height, nimages */
    radiobutton_pixels,
    radiobutton_states
};

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *foregroundObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *lightColorObj;
    Tcl_Obj *shadeColorObj;
    Tcl_Obj *borderColorObj;
    Tcl_Obj *marginObj;
} IndicatorElement;

static const Ttk_ElementOptionSpec IndicatorElementOptions[] = {
static Ttk_ElementOptionSpec IndicatorElementOptions[] = {
    { "-background", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
	    Tk_Offset(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-foreground", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,foregroundObj), DEFAULT_FOREGROUND },
	    Tk_Offset(IndicatorElement,foregroundObj), DEFAULT_FOREGROUND },
    { "-indicatorcolor", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,colorObj), "#FFFFFF" },
	    Tk_Offset(IndicatorElement,colorObj), "#FFFFFF" },
    { "-lightcolor", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,lightColorObj), "#DDDDDD" },
	    Tk_Offset(IndicatorElement,lightColorObj), "#DDDDDD" },
    { "-shadecolor", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,shadeColorObj), "#888888" },
	    Tk_Offset(IndicatorElement,shadeColorObj), "#888888" },
    { "-bordercolor", TK_OPTION_COLOR,
	    offsetof(IndicatorElement,borderColorObj), "black" },
	    Tk_Offset(IndicatorElement,borderColorObj), "black" },
    { "-indicatormargin", TK_OPTION_STRING,
	    offsetof(IndicatorElement,marginObj), "0 2 4 2" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	    Tk_Offset(IndicatorElement,marginObj), "0 2 4 2" },
	    { NULL, 0, 0, NULL }
};

static void IndicatorElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorSpec *spec = clientData;
    IndicatorElement *indicator = elementRecord;
    Ttk_Padding margins;
    double scalingLevel = TkScalingLevel(tkwin);

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    *widthPtr = spec->width * scalingLevel + Ttk_PaddingWidth(margins);
    *heightPtr = spec->height * scalingLevel + Ttk_PaddingHeight(margins);
    *widthPtr = spec->width + Ttk_PaddingWidth(margins);
    *heightPtr = spec->height + Ttk_PaddingHeight(margins);
}

static void ColorToStr(
    const XColor *colorPtr, char *colorStr)	/* in the format "RRGGBB" */
{
    snprintf(colorStr, 7, "%02x%02x%02x",
	     colorPtr->red >> 8, colorPtr->green >> 8, colorPtr->blue >> 8);
}

static void ImageChanged(		/* to be passed to Tk_GetImage() */
    TCL_UNUSED(void *),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
}

static void IndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned int state)
{
    IndicatorSpec *spec = clientData;
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorElement *indicator = elementRecord;
    Display *display = Tk_Display(tkwin);
    Ttk_Padding padding;
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    XColor *fgColor, *frameColor, *shadeColor, *indicatorColor, *borderColor;
    double scalingLevel = TkScalingLevel(tkwin);
    int width = spec->width * scalingLevel;
    int height = spec->height * scalingLevel;

    char bgColorStr[7], fgColorStr[7], indicatorColorStr[7],
	 shadeColorStr[7], borderColorStr[7];
    unsigned int selected = (state & TTK_STATE_SELECTED);
    Tcl_Interp *interp = Tk_Interp(tkwin);
    char imgName[70];
    Tk_Image img;

    int index, ix, iy;
    XGCValues gcValues;
    const char *svgDataPtr;
    size_t svgDataLen;
    char *svgDataCopy;
    GC copyGC;
    char *shadeColorPtr, *highlightColorPtr, *borderColorPtr, *bgColorPtr,
	 *indicatorColorPtr, *fgColorPtr;
    unsigned long imgColors[8];
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    XImage *img;
    int code;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
    b = Ttk_PadBox(b, padding);

    /*
     * Sanity check
     */
    if (   b.x < 0
	|| b.y < 0
	|| Tk_Width(tkwin) < b.x + width
	|| Tk_Height(tkwin) < b.y + height)
	|| Tk_Width(tkwin) < b.x + spec->width
	|| Tk_Height(tkwin) < b.y + spec->height)
    {
	/* Oops!  Not enough room to display the image.
	/* Oops!  not enough room to display the image.
	 * Don't draw anything.
	 */
	return;
    }

    /*
     * Construct the color strings bgColorStr, fgColorStr,
     * indicatorColorStr, shadeColorStr, and borderColorStr
     * Fill in imgColors palette:
     *
     * (SHOULD: take light and shade colors from the border object,
     * but Tk doesn't provide easy access to these in the public API.)
     */
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->backgroundObj),
    fgColor = Tk_GetColorFromObj(tkwin, indicator->foregroundObj);
	       bgColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->foregroundObj),
    frameColor = Tk_GetColorFromObj(tkwin, indicator->backgroundObj);
	       fgColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->colorObj),
	       indicatorColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->shadeColorObj),
	       shadeColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->borderColorObj),
	       borderColorStr);
    shadeColor = Tk_GetColorFromObj(tkwin, indicator->shadeColorObj);
    indicatorColor = Tk_GetColorFromObj(tkwin, indicator->colorObj);
    borderColor = Tk_GetColorFromObj(tkwin, indicator->borderColorObj);

    imgColors[0 /*A*/] = shadeColor->pixel;
    imgColors[1 /*B*/] = indicatorColor->pixel;
    imgColors[2 /*C*/] = frameColor->pixel;
    imgColors[3 /*D*/] = indicatorColor->pixel;
    imgColors[4 /*E*/] = borderColor->pixel;
    imgColors[5 /*F*/] = frameColor->pixel;
    imgColors[6 /*G*/] = fgColor->pixel;
    imgColors[7 /*H*/] = fgColor->pixel;

    /*
     * Check whether there is an SVG image of this size for the indicator's
     * type (0 = checkbtn, 1 = radiobtn) and these color strings
     * Create a scratch buffer to store the image:
     */
    snprintf(imgName, sizeof(imgName),
	     "::tk::icons::indicator_alt%d_%d_%s_%s_%s_%s_%s",
	     width, spec->offDataPtr == radiobtnOffData,
	     shadeColorStr, indicatorColorStr, borderColorStr, bgColorStr,
	     selected ? fgColorStr : "XXXXXX");
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
    img = XGetImage(display,d, 0, 0,
	    (unsigned int)spec->width, (unsigned int)spec->height,
	    AllPlanes, ZPixmap);
    if (img == NULL)
	/*
	 * Determine the SVG data to use for the photo image
	 */
	svgDataPtr = (selected ? spec->onDataPtr : spec->offDataPtr);

	/*
	 * Copy the string pointed to by svgDataPtr to
	 * a newly allocated memory area svgDataCopy
	 */
	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
	    return;
	return;
	}
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	/*
	 * Update the colors within svgDataCopy
	 */

	shadeColorPtr =	    strstr(svgDataCopy, "888888");
	highlightColorPtr = strstr(svgDataCopy, "eeeeee");
	borderColorPtr =    strstr(svgDataCopy, "414141");
	bgColorPtr =	    strstr(svgDataCopy, "d9d9d9");
	indicatorColorPtr = strstr(svgDataCopy, "ffffff");
	fgColorPtr =	    strstr(svgDataCopy, "000000");

    /*
     * Create the image, painting it into an XImage one pixel at a time.
     */
    index = Ttk_StateTableLookup(spec->map, state);
	assert(shadeColorPtr);
	assert(highlightColorPtr);
    for (iy=0 ; iy<spec->height ; iy++) {
	for (ix=0 ; ix<spec->width ; ix++) {
	assert(borderColorPtr);
	assert(bgColorPtr);
	assert(indicatorColorPtr);

	    XPutPixel(img, ix, iy,
	memcpy(shadeColorPtr, shadeColorStr, 6);
	memcpy(highlightColorPtr, indicatorColorStr, 6);
	memcpy(borderColorPtr, borderColorStr, 6);
	memcpy(bgColorPtr, bgColorStr, 6);
	memcpy(indicatorColorPtr, indicatorColorStr, 6);
	if (fgColorPtr != NULL) {
		imgColors[spec->pixels[iy][index*spec->width+ix] - 'A'] );
	    memcpy(fgColorPtr, fgColorStr, 6);
	}

    }
	/*
	 * Create an SVG photo image from svgDataCopy
	 */
	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
	    return;
	}

	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
    /*
     * Copy onto our target drawable surface.
	code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL);
	ckfree(script);
	if (code != TCL_OK) {
     */
    memset(&gcValues, 0, sizeof(gcValues));
    copyGC = Tk_GetGC(tkwin, 0, &gcValues);
	    Tcl_BackgroundException(interp, code);
	    return;
	}
	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }

    TkPutImage(NULL, 0, display, d, copyGC, img, 0, 0, b.x, b.y,
               spec->width, spec->height);


    /*
     * Display the image
     * Tidy up.
     */
    Tk_RedrawImage(img, 0, 0, width, height, d, b.x, b.y);
    Tk_FreeImage(img);
    Tk_FreeGC(display, copyGC);
    XDestroyImage(img);
}

static const Ttk_ElementSpec IndicatorElementSpec = {
static Ttk_ElementSpec IndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    IndicatorElementSize,
    IndicatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Arrow element(s).
 *
 * 	Draws a solid triangle, inside a box.
 * 	clientData is an enum ArrowDirection pointer.
 */

static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT };
typedef struct {
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;		/* Arrow color */
    Tcl_Obj *borderObj;
    Tcl_Obj *borderColorObj;	/* Extra color for borders */
    Tcl_Obj *reliefObj;
    Tcl_Obj *colorObj;		/* Arrow color */
} ArrowElement;

static const Ttk_ElementOptionSpec ArrowElementOptions[] = {
static Ttk_ElementOptionSpec ArrowElementOptions[] = {
    { "-arrowsize", TK_OPTION_PIXELS,
	offsetof(ArrowElement,sizeObj), STRINGIFY(SCROLLBAR_WIDTH) },
	Tk_Offset(ArrowElement,sizeObj), STRINGIFY(SCROLLBAR_WIDTH) },
    { "-arrowcolor", TK_OPTION_COLOR,
	offsetof(ArrowElement,colorObj), "black"},
    { "-background", TK_OPTION_BORDER,
	offsetof(ArrowElement,borderObj), DEFAULT_BACKGROUND },
	Tk_Offset(ArrowElement,borderObj), DEFAULT_BACKGROUND },
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(ArrowElement,borderColorObj), "black" },
	Tk_Offset(ArrowElement,borderColorObj), "black" },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(ArrowElement,reliefObj), "raised"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(ArrowElement,reliefObj),"raised"},
    { "-arrowcolor", TK_OPTION_COLOR,
	Tk_Offset(ArrowElement,colorObj),"black"},
    { NULL, 0, 0, NULL }
};

/*
 * Note asymmetric padding:
 * top/left padding is 1 less than bottom/right,
 * since in this theme 2-pixel borders are asymmetric.
 */
static const Ttk_Padding ArrowPadding = { 3,3,4,4 };
static Ttk_Padding ArrowPadding = { 3,3,4,4 };

static void ArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    ArrowElement *arrow = elementRecord;
    int direction = *(int *)clientData;
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding;
    int size = SCROLLBAR_WIDTH;
    int width = SCROLLBAR_WIDTH;

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.right = padding.left + 1;
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.bottom = padding.top + 1;

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &width);
    width -= Ttk_PaddingWidth(ArrowPadding);
    TtkArrowSize(width/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(ArrowPadding);
    *heightPtr += Ttk_PaddingHeight(ArrowPadding);
    if (*widthPtr < *heightPtr) {
	*widthPtr = *heightPtr;
    } else {
	*heightPtr = *widthPtr;
    }
}
}


static void ArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    int direction = *(int *)clientData;
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowElement *arrow = elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, arrow->borderColorObj);
    int borderWidth = 2, relief = TK_RELIEF_RAISED;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);
    int cx = 0, cy = 0;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    GC gc = Tk_GCForColor(arrowColor, d);
    int relief = TK_RELIEF_RAISED;
    int borderWidth = 2;

    Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    0, TK_RELIEF_FLAT);
    Tk_Fill3DRectangle(
	tkwin, d, border, b.x, b.y, b.width, b.height, 0, TK_RELIEF_FLAT);
    DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief);

    DrawBorder(tkwin,d,border,borderColor,b,borderWidth,relief);
    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.right = padding.left + 1;
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.bottom = padding.top + 1;

    b = Ttk_PadBox(b, padding);

    switch (direction) {
	case ARROW_UP:
	case ARROW_DOWN:
	    TtkArrowSize(b.width/2, direction, &cx, &cy);
	    if ((b.height - cy) % 2 == 1) {
		++cy;
	    }
	    break;
	case ARROW_LEFT:
	case ARROW_RIGHT:
	    TtkArrowSize(b.height/2, direction, &cx, &cy);
	    if ((b.width - cx) % 2 == 1) {
		++cx;
	    }
	    break;
    }

    b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

    TtkFillArrow(Tk_Display(tkwin), d, gc, b, direction);
    TtkFillArrow(Tk_Display(tkwin), d, Tk_GCForColor(arrowColor, d),
	Ttk_PadBox(b, ArrowPadding), direction);
}

static const Ttk_ElementSpec ArrowElementSpec = {
static Ttk_ElementSpec ArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    ArrowElementSize,
    ArrowElementDraw
};

/*
 * Modified arrow element for comboboxes and spinboxes:
 * 	The width and height are different, and the left edge is drawn in the
 *	same color as the inner part of the right one.
 */

static void BoxArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding;
    int size = 14;

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
}

static void BoxArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, arrow->borderColorObj);
    int borderWidth = 2, relief = TK_RELIEF_RAISED;
    Display *disp = Tk_Display(tkwin);
    GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
    int w = WIN32_XDRAWLINE_HACK;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);
    int cx = 0, cy = 0;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    GC arrowGC = Tk_GCForColor(arrowColor, d);

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    0, TK_RELIEF_FLAT);
    DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief);

    XDrawLine(disp, d, darkGC, b.x, b.y+1, b.x, b.y+b.height-2+w);

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    b = Ttk_PadBox(b, padding);

    TtkArrowSize(b.width/2, direction, &cx, &cy);
    if ((b.height - cy) % 2 == 1) {
	++cy;
    }

    b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

    TtkFillArrow(disp, d, arrowGC, b, direction);
}

static const Ttk_ElementSpec BoxArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    BoxArrowElementSize,
    BoxArrowElementDraw
};

/*----------------------------------------------------------------------
 * +++ Menubutton indicator:
 * 	Draw an arrow in the direction where the menu will be posted.
 */

#define MENUBUTTON_ARROW_SIZE 5

typedef struct {
    Tcl_Obj *directionObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;
} MenubuttonArrowElement;

static const char *const directionStrings[] = {	/* See also: button.c */
    "above", "below", "flush", "left", "right", NULL
static const char *directionStrings[] = {	/* See also: button.c */
    "above", "below", "left", "right", "flush", NULL
};
enum { POST_ABOVE, POST_BELOW, POST_FLUSH, POST_LEFT, POST_RIGHT };
enum { POST_ABOVE, POST_BELOW, POST_LEFT, POST_RIGHT, POST_FLUSH };

static const Ttk_ElementOptionSpec MenubuttonArrowElementOptions[] = {
static Ttk_ElementOptionSpec MenubuttonArrowElementOptions[] = {
    { "-direction", TK_OPTION_STRING,
	offsetof(MenubuttonArrowElement,directionObj), "below" },
	Tk_Offset(MenubuttonArrowElement,directionObj), "below" },
    { "-arrowsize", TK_OPTION_PIXELS,
	offsetof(MenubuttonArrowElement,sizeObj), STRINGIFY(MENUBUTTON_ARROW_SIZE)},
    { "-arrowcolor", TK_OPTION_COLOR,
	offsetof(MenubuttonArrowElement,colorObj), "black"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(MenubuttonArrowElement,sizeObj), STRINGIFY(MENUBUTTON_ARROW_SIZE)},
    { "-arrowcolor",TK_OPTION_COLOR,
	Tk_Offset(MenubuttonArrowElement,colorObj), "black"},
    { NULL, 0, 0, NULL }
};

static const Ttk_Padding MenubuttonArrowPadding = { 3, 0, 3, 0 };
static Ttk_Padding MenubuttonArrowPadding = { 3, 0, 3, 0 };

static void MenubuttonArrowElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    MenubuttonArrowElement *arrow = (MenubuttonArrowElement *)elementRecord;
    MenubuttonArrowElement *arrow = elementRecord;
    int size = MENUBUTTON_ARROW_SIZE;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);

    padding.left = round(MenubuttonArrowPadding.left * scalingLevel);
    padding.top = round(MenubuttonArrowPadding.top * scalingLevel);
    padding.right = round(MenubuttonArrowPadding.right * scalingLevel);
    padding.bottom = round(MenubuttonArrowPadding.bottom * scalingLevel);

    *widthPtr = *heightPtr = 2 * size + 1;
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
    *widthPtr += Ttk_PaddingWidth(MenubuttonArrowPadding);
    *heightPtr += Ttk_PaddingHeight(MenubuttonArrowPadding);
}

static void MenubuttonArrowElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    MenubuttonArrowElement *arrow = (MenubuttonArrowElement *)elementRecord;
    MenubuttonArrowElement *arrow = elementRecord;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    GC gc = Tk_GCForColor(arrowColor, d);
    int size = MENUBUTTON_ARROW_SIZE;
    int postDirection = POST_BELOW;
    ArrowDirection arrowDirection = ARROW_DOWN;
    int width = 0, height = 0;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    Tcl_GetIndexFromObjStruct(NULL, arrow->directionObj, directionStrings,
	   sizeof(char *), ""/*message*/, 0/*flags*/, &postDirection);

    /* ... this might not be such a great idea ... */
    switch (postDirection) {
	case POST_ABOVE:	arrowDirection = ARROW_UP; break;
	case POST_BELOW:	arrowDirection = ARROW_DOWN; break;
	case POST_LEFT:		arrowDirection = ARROW_LEFT; break;
	case POST_RIGHT:	arrowDirection = ARROW_RIGHT; break;
	case POST_FLUSH:	arrowDirection = ARROW_DOWN; break;
    }

    TtkArrowSize(size, arrowDirection, &width, &height);

    padding.left = round(MenubuttonArrowPadding.left * scalingLevel);
    padding.top = round(MenubuttonArrowPadding.top * scalingLevel);
    padding.right = round(MenubuttonArrowPadding.right * scalingLevel);
    padding.bottom = round(MenubuttonArrowPadding.bottom * scalingLevel);

    b = Ttk_PadBox(b, padding);
    b = Ttk_PadBox(b, MenubuttonArrowPadding);
    b = Ttk_AnchorBox(b, width, height, TK_ANCHOR_CENTER);
    TtkFillArrow(Tk_Display(tkwin), d, gc, b, arrowDirection);
}

static const Ttk_ElementSpec MenubuttonArrowElementSpec = {
static Ttk_ElementSpec MenubuttonArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(MenubuttonArrowElement),
    MenubuttonArrowElementOptions,
    MenubuttonArrowElementSize,
    MenubuttonArrowElementDraw
};

/*----------------------------------------------------------------------
 * +++ Trough element
 *
 * Used in scrollbars and the scale.
 *
 * The -groovewidth option can be used to set the size of the short axis
 * for the drawn area. This will not affect the geometry, but can be used
 * to draw a thin centered trough inside the packet alloted. This is used
 * to show a win32-style scale widget. Use -1 or a large number to use the
 * full area (default).
 *
 */

typedef struct {
    Tcl_Obj *colorObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *grooveWidthObj;
    Tcl_Obj *orientObj;
} TroughElement;

static Ttk_ElementOptionSpec TroughElementOptions[] = {
    { "-orient", TK_OPTION_ANY,
	Tk_Offset(TroughElement, orientObj), "horizontal" },
    { "-troughborderwidth", TK_OPTION_PIXELS,
	Tk_Offset(TroughElement,borderWidthObj), "1" },
    { "-troughcolor", TK_OPTION_BORDER,
	Tk_Offset(TroughElement,colorObj), DEFAULT_BACKGROUND },
    { "-troughrelief",TK_OPTION_RELIEF,
	Tk_Offset(TroughElement,reliefObj), "sunken" },
    { "-groovewidth", TK_OPTION_PIXELS,
	Tk_Offset(TroughElement,grooveWidthObj), "-1" },
    { NULL, 0, 0, NULL }
};

static void TroughElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TroughElement *troughPtr = elementRecord;
    int borderWidth = 2, grooveWidth = 0;

    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &grooveWidth);

    if (grooveWidth <= 0) {
	*paddingPtr = Ttk_UniformPadding((short)borderWidth);
    }
}

static void TroughElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    TroughElement *troughPtr = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 2, relief = TK_RELIEF_SUNKEN, groove = -1, orient;

    border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj);
    Ttk_GetOrientFromObj(NULL, troughPtr->orientObj, &orient);
    Tk_GetReliefFromObj(NULL, troughPtr->reliefObj, &relief);
    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &groove);

    if (groove != -1 && groove < b.height && groove < b.width) {
	if (orient == TTK_ORIENT_HORIZONTAL) {
	    b.y = b.y + b.height/2 - groove/2;
	    b.height = groove;
	} else {
	    b.x = b.x + b.width/2 - groove/2;
	    b.width = groove;
	}
    }

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, relief);
}

static Ttk_ElementSpec TroughElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TroughElement),
    TroughElementOptions,
    TroughElementSize,
    TroughElementDraw
};

/*
 *----------------------------------------------------------------------
 * +++ Thumb element.
 */

typedef struct {
    Tcl_Obj *sizeObj;
    Tcl_Obj *firstObj;
    Tcl_Obj *lastObj;
    Tcl_Obj *borderObj;
    Tcl_Obj *borderColorObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *orientObj;
} ThumbElement;

static const Ttk_ElementOptionSpec ThumbElementOptions[] = {
    { "-width", TK_OPTION_PIXELS, offsetof(ThumbElement,sizeObj),
static Ttk_ElementOptionSpec ThumbElementOptions[] = {
    { "-width", TK_OPTION_PIXELS, Tk_Offset(ThumbElement,sizeObj),
        STRINGIFY(SCROLLBAR_WIDTH) },
    { "-background", TK_OPTION_BORDER, offsetof(ThumbElement,borderObj),
    { "-background", TK_OPTION_BORDER, Tk_Offset(ThumbElement,borderObj),
	DEFAULT_BACKGROUND },
    { "-bordercolor", TK_OPTION_COLOR, offsetof(ThumbElement,borderColorObj),
    { "-bordercolor", TK_OPTION_COLOR, Tk_Offset(ThumbElement,borderColorObj),
	"black" },
    { "-relief", TK_OPTION_RELIEF, offsetof(ThumbElement,reliefObj),"raised" },
    { "-orient", TK_OPTION_ANY, offsetof(ThumbElement,orientObj),"horizontal"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { "-relief", TK_OPTION_RELIEF,Tk_Offset(ThumbElement,reliefObj),"raised" },
    { "-orient", TK_OPTION_ANY,Tk_Offset(ThumbElement,orientObj),"horizontal"},
    { NULL, 0, 0, NULL }
};

static void ThumbElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ThumbElement *thumb = (ThumbElement *)elementRecord;
    Ttk_Orient orient;
    ThumbElement *thumb = elementRecord;
    int orient, size;
    int size;

    Tk_GetPixelsFromObj(NULL, tkwin, thumb->sizeObj, &size);
    Ttk_GetOrientFromObj(NULL, thumb->orientObj, &orient);

    if (orient == TTK_ORIENT_VERTICAL) {
	*widthPtr = size;
	*heightPtr = MIN_THUMB_SIZE;
    } else {
	*widthPtr = MIN_THUMB_SIZE;
	*heightPtr = size;
    }
}

static void ThumbElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ThumbElement *thumb = (ThumbElement *)elementRecord;
    ThumbElement *thumb = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, thumb->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, thumb->borderColorObj);
    int relief = TK_RELIEF_RAISED;
    int borderWidth = 2;

    /*
     * Don't draw the thumb if we are disabled.
     * This makes it behave like Windows ... if that's what we want.
    if (state & TTK_STATE_DISABLED)
	return;
     */

    Tk_GetReliefFromObj(NULL, thumb->reliefObj, &relief);

    Tk_Fill3DRectangle(
	tkwin, d, border, b.x,b.y,b.width,b.height, 0, TK_RELIEF_FLAT);
    DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief);
}

static const Ttk_ElementSpec ThumbElementSpec = {
static Ttk_ElementSpec ThumbElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ThumbElement),
    ThumbElementOptions,
    ThumbElementSize,
    ThumbElementDraw
};

/*
 *----------------------------------------------------------------------
 * +++ Slider element.
 *
 * This is the moving part of the scale widget.
 *
 * The slider element is the thumb in the scale widget. This is drawn
 * as an arrow-type element that can point up, down, left or right.
 *
 */

typedef struct {
    Tcl_Obj *lengthObj;		/* Long axis dimension */
    Tcl_Obj *thicknessObj;	/* Short axis dimension */
    Tcl_Obj *reliefObj;		/* Relief for this object */
    Tcl_Obj *borderObj;		/* Border / background color */
    Tcl_Obj *borderColorObj;	/* Additional border color */
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *orientObj;		/* Orientation of overall slider */
} SliderElement;

static const Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-sliderthickness",TK_OPTION_PIXELS, offsetof(SliderElement,thicknessObj),
static Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-sliderlength", TK_OPTION_PIXELS, Tk_Offset(SliderElement,lengthObj),
	"15" },
    { "-sliderthickness",TK_OPTION_PIXELS,Tk_Offset(SliderElement,thicknessObj),
	"15" },
    { "-sliderrelief", TK_OPTION_RELIEF, offsetof(SliderElement,reliefObj),
    { "-sliderrelief", TK_OPTION_RELIEF, Tk_Offset(SliderElement,reliefObj),
	"raised" },
    { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SliderElement,borderWidthObj),
	STRINGIFY(BORDERWIDTH) },
    { "-background", TK_OPTION_BORDER, offsetof(SliderElement,borderObj),
    { "-background", TK_OPTION_BORDER, Tk_Offset(SliderElement,borderObj),
	DEFAULT_BACKGROUND },
    { "-bordercolor", TK_OPTION_COLOR, offsetof(SliderElement,borderColorObj),
    { "-bordercolor", TK_OPTION_COLOR, Tk_Offset(ThumbElement,borderColorObj),
	"black" },
    { "-borderwidth", TK_OPTION_PIXELS, offsetof(SliderElement,borderWidthObj),
	STRINGIFY(BORDERWIDTH) },
    { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj),
    { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj),
	"horizontal" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { NULL, 0, 0, NULL }
};

static void SliderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    SliderElement *slider = (SliderElement *)elementRecord;
    SliderElement *slider = elementRecord;
    Ttk_Orient orient;
    int thickness, borderWidth;
    int orient, length, thickness, borderWidth;

    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->lengthObj, &length);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness);

    switch (orient) {
	case TTK_ORIENT_VERTICAL:
	    *widthPtr = thickness + (borderWidth *2);
	    *heightPtr = *widthPtr/2;
	    break;

	case TTK_ORIENT_HORIZONTAL:
	    *heightPtr = thickness + (borderWidth *2);
	    *widthPtr = *heightPtr/2;
	    break;
    }
}

static void SliderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SliderElement *slider = (SliderElement *)elementRecord;
    SliderElement *slider = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, slider->borderColorObj);
    int relief = TK_RELIEF_RAISED, borderWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border,
	b.x, b.y, b.width, b.height,
	borderWidth, TK_RELIEF_FLAT);
    DrawBorder(tkwin, d, border, borderColor, b, borderWidth, relief);
}

static const Ttk_ElementSpec SliderElementSpec = {
static Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SliderElement),
    SliderElementOptions,
    SliderElementSize,
    SliderElementDraw
};

/*------------------------------------------------------------------------
 * +++ Tree indicator element.
 */

#define TTK_STATE_OPEN TTK_STATE_USER1		/* XREF: treeview.c */
#define TTK_STATE_LEAF TTK_STATE_USER2

typedef struct {
    Tcl_Obj *colorObj;
    Tcl_Obj *marginObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *diameterObj;
} TreeitemIndicator;

static const Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = {
static Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = {
    { "-foreground", TK_OPTION_COLOR,
	offsetof(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND },
    { "-size", TK_OPTION_PIXELS,
	offsetof(TreeitemIndicator,sizeObj), "6.75p" },
	Tk_Offset(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND },
    { "-diameter", TK_OPTION_PIXELS,
	Tk_Offset(TreeitemIndicator,diameterObj), "9" },
    { "-indicatormargins", TK_OPTION_STRING,
	offsetof(TreeitemIndicator,marginObj), "2 2 4 2" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(TreeitemIndicator,marginObj), "2 2 4 2" },
    { NULL, 0, 0, NULL }
};

static void TreeitemIndicatorSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord;
    int size = 0;
    TreeitemIndicator *indicator = elementRecord;
    int diameter = 0;
    Ttk_Padding margins;

    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter);
    *widthPtr = size + Ttk_PaddingWidth(margins);
    *heightPtr = size + Ttk_PaddingHeight(margins);
    *widthPtr = diameter + Ttk_PaddingWidth(margins);
    *heightPtr = diameter + Ttk_PaddingHeight(margins);
}

static void TreeitemIndicatorDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
{
    TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord;
    TreeitemIndicator *indicator = elementRecord;
    XColor *color = Tk_GetColorFromObj(tkwin, indicator->colorObj);
    GC gc = Tk_GCForColor(color, d);
    Ttk_Padding padding = Ttk_UniformPadding(0);
    int w = WIN32_XDRAWLINE_HACK;
    int cx, cy;

    if (state & TTK_STATE_LEAF) {
1274
1275
1276
1277
1278
1279
1280
1281

1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308

1309
1310
1311
1312
1313

1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329








1330
1331
1332

1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090


1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101

1102
1103

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114

1115


1116








1117
1118
1119
1120
1121
1122
1123
1124

1125

1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136







-
+











-
-











-
+

-
+





+




-
+
-
-

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
+


-
+








    if (!(state & TTK_STATE_OPEN)) {
	/* turn '-' into a '+' */
	XDrawLine(Tk_Display(tkwin), d, gc, cx, b.y+2, cx, b.y+b.height-3+w);
    }
}

static const Ttk_ElementSpec TreeitemIndicatorElementSpec = {
static Ttk_ElementSpec TreeitemIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TreeitemIndicator),
    TreeitemIndicatorOptions,
    TreeitemIndicatorSize,
    TreeitemIndicatorDraw
};

/*------------------------------------------------------------------------
 * TtkAltTheme_Init --
 * 	Install alternate theme.
 */
MODULE_SCOPE int TtkAltTheme_Init(Tcl_Interp *interp);

MODULE_SCOPE int TtkAltTheme_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_CreateTheme(interp, "alt", NULL);

    if (!theme) {
	return TCL_ERROR;
    }

    Ttk_RegisterElement(interp, theme, "border", &BorderElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "Checkbutton.indicator",
	    &IndicatorElementSpec, (void *)&checkbutton_spec);
	    &IndicatorElementSpec, &checkbutton_spec);
    Ttk_RegisterElement(interp, theme, "Radiobutton.indicator",
	    &IndicatorElementSpec, (void *)&radiobutton_spec);
	    &IndicatorElementSpec, &radiobutton_spec);
    Ttk_RegisterElement(interp, theme, "Menubutton.indicator",
	    &MenubuttonArrowElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "field", &FieldElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "trough", &TroughElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "thumb", &ThumbElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "slider", &SliderElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "uparrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);
    Ttk_RegisterElement(interp, theme, "Spinbox.uparrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_UP));
    Ttk_RegisterElement(interp, theme, "downarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "Spinbox.downarrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "Combobox.downarrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "leftarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_LEFT));
    Ttk_RegisterElement(interp, theme, "rightarrow",
	    &ArrowElementSpec, &ArrowElements[1]);
    Ttk_RegisterElement(interp, theme, "leftarrow",
	    &ArrowElementSpec, &ArrowElements[2]);
    Ttk_RegisterElement(interp, theme, "rightarrow",
	    &ArrowElementSpec, &ArrowElements[3]);
    Ttk_RegisterElement(interp, theme, "arrow",
	    &ArrowElementSpec, &ArrowElements[0]);

	    &ArrowElementSpec, INT2PTR(ARROW_RIGHT));
    Ttk_RegisterElement(interp, theme, "arrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);

    Ttk_RegisterElement(interp, theme, "Treeitem.indicator",
	    &TreeitemIndicatorElementSpec, NULL);
	    &TreeitemIndicatorElementSpec, 0);

    Tcl_PkgProvide(interp, "ttk::theme::alt", TTK_VERSION);

    return TCL_OK;
}

/*EOF*/

Changes to generic/ttk/ttkElements.c.

1
2

3
4
5
6
7

8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34

35
36
37

38
39
40
41
42
43
44
45
46


47
48
49
50
51
52
53
54
55
1

2
3
4
5
6
7
8


9
10
11
12
13






14
15
16
17
18
19
20
21
22
23

24
25
26
27



28



29
30
31
32
33
34




35
36


37
38
39
40
41
42
43

-
+





+
-
-
+
+
+


-
-
-
-
-
-










-
+



-
-
-
+
-
-
-
+





-
-
-
-
+
+
-
-







/*
 * Copyright © 2003 Joe English
 * Copyright (c) 2003, Joe English
 *
 * Default implementation for themed elements.
 *
 */

#include <tcl.h>
#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>
#include <string.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

#if defined(_WIN32)
  #define WIN32_XDRAWLINE_HACK 1
#else
  #define WIN32_XDRAWLINE_HACK 0
#endif

#define DEFAULT_BORDERWIDTH "2"
#define DEFAULT_ARROW_SIZE "15"
#define MIN_THUMB_SIZE 10

/*----------------------------------------------------------------------
 * +++ Null element.  Does nothing; used as a stub.
 * Null element methods, option table and element spec are public,
 * and may be used in other engines.
 */

/* public */ const Ttk_ElementOptionSpec TtkNullElementOptions[] = { { NULL, TK_OPTION_BOOLEAN, 0, NULL } };
/* public */ Ttk_ElementOptionSpec TtkNullElementOptions[] = { { NULL, 0, 0, NULL } };

/* public */ void
TtkNullElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    TCL_UNUSED(Ttk_Padding *))
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
}

/* public */ void
TtkNullElementDraw(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(Drawable),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_Box),
    TCL_UNUSED(Ttk_State))
{
}

/* public */ Ttk_ElementSpec ttkNullElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
66
67
68
69
70
71
72
73

74
75
76


77
78
79
80
81

82
83

84
85
86
87

88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134

135
136

137
138
139


140
141
142
143
144

145
146
147
148

149
150

151
152
153
154
155
156
157
158
159

160
161

162
163
164
165

166
167
168
169
170
171
172
173
174
175

176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200

201
202

203
204
205
206
207

208
209
210
211
212
213

214
215
216
217

218
219
220


221
222
223
224
225
226
227
228
229
230
231
232
233


234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291





292
293

294
295
296
297
298
299
300
54
55
56
57
58
59
60

61
62


63
64
65
66
67


68


69


70

71
72
73
74
75
76
77
78
79
80

81


82
83
84
85
86
87

88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115

116
117

118
119


120
121
122
123
124


125




126
127

128
129

130
131
132
133
134


135


136


137

138
139
140
141
142
143
144
145
146
147

148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166


167
168

169
170

171
172

173





174
175
176

177


178




179
180


181
182

183




184
185
186
187



188
189
190

191
192






































193




194












195
196
197
198
199


200
201
202
203
204
205
206
207







-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+









-
+
-
-






-
+







-
+

















-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
+

-





-
-
+
-
-
+
-
-

-
+









-
+



-
+














-
-


-
+

-
+

-
+
-
-
-
-
-
+


-

-
-
+
-
-
-
-
+

-
-
+
+
-

-
-
-
-




-
-
-
+
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+







 * Ttk_GetLayout() automatically includes a background element.
 */

typedef struct {
    Tcl_Obj	*backgroundObj;
} BackgroundElement;

static const Ttk_ElementOptionSpec BackgroundElementOptions[] = {
static Ttk_ElementOptionSpec BackgroundElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	    offsetof(BackgroundElement,backgroundObj), DEFAULT_BACKGROUND },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	    Tk_Offset(BackgroundElement,backgroundObj), DEFAULT_BACKGROUND },
    { NULL, 0, 0, NULL }
};

static void FillElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    BackgroundElement *bg = (BackgroundElement *)elementRecord;
    BackgroundElement *bg = elementRecord;
    Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,bg->backgroundObj);

    XFillRectangle(Tk_Display(tkwin), d,
	Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC),
	b.x, b.y, b.width, b.height);
}

static void BackgroundElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_Box),
    Ttk_State state)
{
    FillElementDraw(
	clientData, elementRecord, tkwin,
	d, Ttk_WinBox(tkwin), state);
}

static const Ttk_ElementSpec FillElementSpec = {
static Ttk_ElementSpec FillElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BackgroundElement),
    BackgroundElementOptions,
    TtkNullElementSize,
    FillElementDraw
};

static const Ttk_ElementSpec BackgroundElementSpec = {
static Ttk_ElementSpec BackgroundElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BackgroundElement),
    BackgroundElementOptions,
    TtkNullElementSize,
    BackgroundElementDraw
};

/*----------------------------------------------------------------------
 * +++ Border element.
 */

typedef struct {
    Tcl_Obj	*borderObj;
    Tcl_Obj	*borderWidthObj;
    Tcl_Obj	*reliefObj;
} BorderElement;

static const Ttk_ElementOptionSpec BorderElementOptions[] = {
static Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(BorderElement,borderObj), DEFAULT_BACKGROUND },
	Tk_Offset(BorderElement,borderObj), DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(BorderElement,borderWidthObj), DEFAULT_BORDERWIDTH },
	Tk_Offset(BorderElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(BorderElement,reliefObj), "flat" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(BorderElement,reliefObj), "flat" },
    { NULL, 0, 0, NULL }
};

static void BorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    BorderElement *bd = (BorderElement *)elementRecord;
    BorderElement *bd = elementRecord;
    int borderWidth = 0;

    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void BorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    BorderElement *bd = (BorderElement *)elementRecord;
    BorderElement *bd = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 1, relief = TK_RELIEF_FLAT;

    border = Tk_Get3DBorderFromObj(tkwin, bd->borderObj);
    Tcl_GetIntFromObj(NULL, bd->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, bd->reliefObj, &relief);

    if (border && borderWidth > 0 && relief != TK_RELIEF_FLAT) {
	Tk_Draw3DRectangle(tkwin, d, border,
	    b.x, b.y, b.width, b.height, borderWidth, relief);
	    b.x, b.y, b.width, b.height, borderWidth,relief);
    }
}

static const Ttk_ElementSpec BorderElementSpec = {
static Ttk_ElementSpec BorderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BorderElement),
    BorderElementOptions,
    BorderElementSize,
    BorderElementDraw
};

/*----------------------------------------------------------------------
 * +++ Field element.
 * 	Used for editable fields.
 */
typedef struct {
    Tcl_Obj	*borderObj;
    Tcl_Obj	*borderWidthObj;
    Tcl_Obj	*focusWidthObj;
    Tcl_Obj	*focusColorObj;
} FieldElement;

static const Ttk_ElementOptionSpec FieldElementOptions[] = {
static Ttk_ElementOptionSpec FieldElementOptions[] = {
    { "-fieldbackground", TK_OPTION_BORDER,
	offsetof(FieldElement,borderObj), "white" },
	Tk_Offset(FieldElement,borderObj), "white" },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(FieldElement,borderWidthObj), "2" },
	Tk_Offset(FieldElement,borderWidthObj), "2" },
    { "-focuswidth", TK_OPTION_PIXELS,
	offsetof(FieldElement,focusWidthObj), "2" },
    { "-focuscolor", TK_OPTION_COLOR,
	offsetof(FieldElement,focusColorObj), "#4a6984" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { NULL, 0, 0, NULL }
};


static void FieldElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    FieldElement *field = (FieldElement *)elementRecord;
    int borderWidth = 2, focusWidth = 2;
    FieldElement *field = elementRecord;
    int borderWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, field->focusWidthObj, &focusWidth);
    if (focusWidth > 0 && borderWidth < 2) {
	borderWidth += (focusWidth - borderWidth);
    }
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void FieldElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    FieldElement *field = (FieldElement *)elementRecord;
    FieldElement *field = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, field->borderObj);
    int focusWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, field->focusWidthObj, &focusWidth);

    if (focusWidth > 0 && (state & TTK_STATE_FOCUS)) {
	Display *disp = Tk_Display(tkwin);
	XColor *focusColor = Tk_GetColorFromObj(tkwin, field->focusColorObj);
	GC focusGC = Tk_GCForColor(focusColor, d);

	if (focusWidth > 1) {
	    int x1 = b.x, x2 = b.x + b.width - 1;
	    int y1 = b.y, y2 = b.y + b.height - 1;
	    int w = WIN32_XDRAWLINE_HACK;

	    /*
	     * Draw the outer rounded rectangle
	     */
	    XDrawLine(disp, d, focusGC, x1+1, y1, x2-1+w, y1);	/* N */
	    XDrawLine(disp, d, focusGC, x1+1, y2, x2-1+w, y2);	/* S */
	    XDrawLine(disp, d, focusGC, x1, y1+1, x1, y2-1+w);	/* W */
	    XDrawLine(disp, d, focusGC, x2, y1+1, x2, y2-1+w);	/* E */

	    /*
	     * Draw the inner rectangle
	     */
	    b.x += 1; b.y += 1; b.width -= 2; b.height -= 2;
	    XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);

	    /*
	     * Fill the inner rectangle
	     */
	    GC bgGC = Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC);
	    XFillRectangle(disp, d, bgGC, b.x+1, b.y+1, b.width-2, b.height-2);
	} else {
	    /*
	     * Draw the field element as usual
	     */
	    int borderWidth = 2;
    int borderWidth = 2;
	    Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj,
		    &borderWidth);
	    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
		    borderWidth, TK_RELIEF_SUNKEN);

	    /*
	     * Change the color of the border's outermost pixels
	     */
	    XDrawRectangle(disp, d, focusGC, b.x, b.y, b.width-1, b.height-1);
	}
    } else {
	int borderWidth = 2;
	Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth);
	Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
		borderWidth, TK_RELIEF_SUNKEN);
    }
}
    Tk_GetPixelsFromObj(NULL, tkwin, field->borderWidthObj, &borderWidth);
    Tk_Fill3DRectangle(tkwin, d, border,
	    b.x, b.y, b.width, b.height, borderWidth, TK_RELIEF_SUNKEN);
}


static const Ttk_ElementSpec FieldElementSpec = {
static Ttk_ElementSpec FieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    FieldElementSize,
    FieldElementDraw
};

311
312
313
314
315
316
317
318

319
320

321
322

323
324
325


326
327
328
329
330

331
332
333
334

335
336

337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
218
219
220
221
222
223
224

225
226

227
228

229
230


231
232
233
234
235


236




237
238

239
240
241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257







-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
+










-
+








typedef struct {
    Tcl_Obj	*paddingObj;
    Tcl_Obj	*reliefObj;
    Tcl_Obj	*shiftreliefObj;
} PaddingElement;

static const Ttk_ElementOptionSpec PaddingElementOptions[] = {
static Ttk_ElementOptionSpec PaddingElementOptions[] = {
    { "-padding", TK_OPTION_STRING,
	offsetof(PaddingElement,paddingObj), "0" },
	Tk_Offset(PaddingElement,paddingObj), "0" },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(PaddingElement,reliefObj), "flat" },
	Tk_Offset(PaddingElement,reliefObj), "flat" },
    { "-shiftrelief", TK_OPTION_INT,
	offsetof(PaddingElement,shiftreliefObj), "0" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(PaddingElement,shiftreliefObj), "0" },
    { NULL, 0, 0, NULL }
};

static void PaddingElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    PaddingElement *padding = (PaddingElement *)elementRecord;
    PaddingElement *padding = elementRecord;
    int shiftRelief = 0;
    int relief = TK_RELIEF_FLAT;
    Ttk_Padding pad;

    Tk_GetReliefFromObj(NULL, padding->reliefObj, &relief);
    Tcl_GetIntFromObj(NULL, padding->shiftreliefObj, &shiftRelief);
    Ttk_GetPaddingFromObj(NULL,tkwin,padding->paddingObj,&pad);
    *paddingPtr = Ttk_RelievePadding(pad, relief, shiftRelief);
}

static const Ttk_ElementSpec PaddingElementSpec = {
static Ttk_ElementSpec PaddingElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(PaddingElement),
    PaddingElementOptions,
    PaddingElementSize,
    TtkNullElementDraw
};

381
382
383
384
385
386
387
388

389
390

391
392
393


394
395
396
397
398

399
400
401
402

403
404

405
406
407
408
409
410
411
412
413

414
415

416
417
418
419

420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448

449
450

451
452
453


454
455
456
457
458
459
460


461
462
463
464
465
466
467
468
469

470
471

472
473
474
475

476
477
478
479
480
481
482
483
484
485
486

487
488

489
490
491
492

493
494
495
496
497
498
499
500
501
502
503

504
505
506


507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556

557
558
559

560
561
562
563
564

565
566

567
568
569
570
571
572

573
574

575
576
577
578
579

580
581

582
583
584
585

586
587

588
589
590
591
592
593
594
595
596
597
598
599

600
601


602
603
604
605

606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
627
628
629

630
631
632
633
634

635
636
637
638
639
640

641
642
643
644
645
646

647
648
649
650
651
652
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681



682

683
684
685
686
687
688
689
690
691
692
693
694
695
696
697









698
699
700




701
702



703











































704
705

706
707
708
709

710
711
712

713

714
715


716
717
718

719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738

739
740






741
742
743
744
745
746
747
748
749
750

751
752
753

754
755
756
757
758
759
760
761



762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
779



780
781
782
783
784
785
786
787
788
789

790
791
792

793
794
795

796
797
798

799
800
801
802
803
804
805
806
807
808
809
810

811
812

813
814
815
816
817

818
819
820
821
822
823
824
825
826
827
828
829

830
831
832

833
834
835
836
837
838

839
840
841
842
843
844
845

846
847
848
849
850
851
852
853
854
855
856
857
858
859


860
861
862


863
864
865
866

867
868
869
870
871
872

873
874

875
876
877
878
879


880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084




1085
1086

1087
1088
1089





1090
1091
1092
1093
1094
1095
1096
1097
1098
1099














1100
1101
1102
1103
1104

1105
1106

1107
1108
1109
1110

1111
1112
1113
1114
1115



1116
1117
1118
1119
1120
1121
1122
1123

1124
1125

1126
1127
1128
1129
1130


1131
1132
1133


1134


1135
1136


1137
1138

1139
1140
1141
1142

1143
1144
1145
1146
1147
1148
1149
1150
1151
1152


1153



1154
1155
1156
1157
1158
1159









































































1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1170
1171
1172



1173
1174
1175
1176

1177
1178
1179
1180
1181



1182
1183
1184
1185
1186

1187
1188
1189
1190

1191
1192
1193


1194
1195
1196
1197
1198
1199
1200


1201
1202
1203
1204
1205
1206
1207
1208


1209
1210
1211
1212
1213



1214
1215
1216

1217
1218
1219
1220

1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245
1246
1247
284
285
286
287
288
289
290

291
292

293
294


295
296
297
298
299


300




301
302

303
304
305
306
307
308
309
310


311


312


313

314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344

345
346


347
348
349
350
351




352
353


354
355
356
357
358


359


360


361

362
363
364
365
366
367
368
369
370
371


372


373


374

375
376
377
378
379
380
381
382
383
384
385

386
387


388
389

390
391
392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
426
427
428
429
430
431
432

433
434

435
436

437



438
439
440
441


442


443


444



445


446
447
448
449


450


451


452

453


454
455
456
457
458
459



460
461


462


463
464
465
466
467

468
469
470
471
472
473
474
475
476
477
478
479


480











481





482






483






484







485




486



















487
488


489
490
491
492
493
494
495













496
497
498
499
500
501
502
503
504
505


506
507
508
509
510
511
512
513
514

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558

559

560


561
562


563
564
565


566
567
568
569

570


















571

572
573

574
575
576
577
578
579
580




581




582



583








584
585
586
587

588
589






590








591
592
593










594



595



596



597












598


599





600




601







602



603






604


605




606














607
608



609
610




611






612
613

614
615
616
617


618
619


































































































































































































620
621
622
623
624
625
626
627



628
629
630
631
632
633
634



635
636
637
638
639
640
641








642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658


659


660


661

662
663




664
665
666

667
668
669
670
671


672


673


674


675
676



677
678
679
680
681


682
683


684

685
686

687
688
689
690
691
692
693
694



695
696
697
698
699
700






701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779



780
781



782
783
784


785

786





787
788
789
790
791
792


793




794
795


796
797
798
799





800
801



802
803



804
805

806



807
808
809

810

811

812


813














814
815
816
817
818

819
820
821
822
823
824
825
826







-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
+







-
-
+
-
-
+
-
-

-
+








-
+



















-
+

-
+

-
-
+
+



-
-
-
-
+
+
-
-





-
-
+
-
-
+
-
-

-
+









-
-
+
-
-
+
-
-

-
+










-
+

-
-
+
+
-













-
+







-
+







-
+













-


-
+

-
+
-
-
-
+



-
-
+
-
-
+
-
-

-
-
-
+
-
-
+



-
-
+
-
-
+
-
-

-
+
-
-
+





-
-
-


-
-
+
-
-
+
+



-
+











-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+
+

+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+


+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-

-
-
+

-
-
+

+
-
-
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+
+
+
+
+
+

-
-
-
-

-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+

-


-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
+
-
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
+

-
+



-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
-
-
+
+
+
+


+
-
-
-
+
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
-
-
+
-
-

-
+

-
-
-
-
+
+
+
-





-
-
+
-
-
+
-
-

-
-
+
+
-
-
-
+
+

+
+
-
-
+
+
-
-
+
-


-
+







-
-
-
+
+

+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+


-
-
-


-
-
-
+
+
+
-
-

-
+
-
-
-
-
-
+
+
+



-
-
+
-
-
-
-
+

-
-
+
+


-
-
-
-
-
+
+
-
-
-


-
-
-
+
+
-

-
-
-
+
+
+
-

-
+
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+







    mask = GCForeground | GCLineStyle | GCDashList | GCDashOffset | GCLineWidth;

    gc = Tk_GetGC(tkwin, mask, &gcvalues);
    XDrawRectangle(Tk_Display(tkwin), d, gc, b.x, b.y, b.width-1, b.height-1);
    Tk_FreeGC(Tk_Display(tkwin), gc);
}

static const Ttk_ElementOptionSpec FocusElementOptions[] = {
static Ttk_ElementOptionSpec FocusElementOptions[] = {
    { "-focuscolor",TK_OPTION_COLOR,
	offsetof(FocusElement,focusColorObj), "black" },
	Tk_Offset(FocusElement,focusColorObj), "black" },
    { "-focusthickness",TK_OPTION_PIXELS,
	offsetof(FocusElement,focusThicknessObj), "1" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(FocusElement,focusThicknessObj), "1" },
    { NULL, 0, 0, NULL }
};

static void FocusElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    FocusElement *focus = (FocusElement *)elementRecord;
    FocusElement *focus = elementRecord;
    int focusThickness = 0;

    Tcl_GetIntFromObj(NULL, focus->focusThicknessObj, &focusThickness);
    *paddingPtr = Ttk_UniformPadding((short)focusThickness);
}

static void FocusElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    FocusElement *focus = (FocusElement *)elementRecord;
    FocusElement *focus = elementRecord;
    int focusThickness = 0;

    if (state & TTK_STATE_FOCUS) {
	Tcl_GetIntFromObj(NULL,focus->focusThicknessObj,&focusThickness);
	DrawFocusRing(tkwin, d, focus->focusColorObj, b);
    }
}

static const Ttk_ElementSpec FocusElementSpec = {
static Ttk_ElementSpec FocusElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FocusElement),
    FocusElementOptions,
    FocusElementSize,
    FocusElementDraw
};

/*----------------------------------------------------------------------
 * +++ Separator element.
 * 	Just draws a horizontal or vertical bar.
 * 	Three elements are defined: horizontal, vertical, and general;
 *	the general separator checks the "-orient" option.
 */

typedef struct {
    Tcl_Obj	*orientObj;
    Tcl_Obj	*borderObj;
} SeparatorElement;

static const Ttk_ElementOptionSpec SeparatorElementOptions[] = {
static Ttk_ElementOptionSpec SeparatorElementOptions[] = {
    { "-orient", TK_OPTION_ANY,
	offsetof(SeparatorElement, orientObj), "horizontal" },
	Tk_Offset(SeparatorElement, orientObj), "horizontal" },
    { "-background", TK_OPTION_BORDER,
	offsetof(SeparatorElement,borderObj), DEFAULT_BACKGROUND },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(SeparatorElement,borderObj), DEFAULT_BACKGROUND },
    { NULL, 0, 0, NULL }
};

static void SeparatorElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    int *widthPtr,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    *widthPtr = *heightPtr = 2;
}

static void HorizontalSeparatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SeparatorElement *separator = (SeparatorElement *)elementRecord;
    SeparatorElement *separator = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, separator->borderObj);
    GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
    GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);

    XDrawLine(Tk_Display(tkwin), d, darkGC, b.x, b.y, b.x + b.width, b.y);
    XDrawLine(Tk_Display(tkwin), d, lightGC, b.x, b.y+1, b.x + b.width, b.y+1);
}

static void VerticalSeparatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SeparatorElement *separator = (SeparatorElement *)elementRecord;
    SeparatorElement *separator = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, separator->borderObj);
    GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
    GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);

    XDrawLine(Tk_Display(tkwin), d, darkGC, b.x, b.y, b.x, b.y + b.height);
    XDrawLine(Tk_Display(tkwin), d, lightGC, b.x+1, b.y, b.x+1, b.y+b.height);
}

static void GeneralSeparatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned int state)
{
    SeparatorElement *separator = (SeparatorElement *)elementRecord;
    Ttk_Orient orient;
    SeparatorElement *separator = elementRecord;
    int orient;

    Ttk_GetOrientFromObj(NULL, separator->orientObj, &orient);
    switch (orient) {
	case TTK_ORIENT_HORIZONTAL:
	    HorizontalSeparatorElementDraw(
		clientData, elementRecord, tkwin, d, b, state);
	    break;
	case TTK_ORIENT_VERTICAL:
	    VerticalSeparatorElementDraw(
		clientData, elementRecord, tkwin, d, b, state);
	    break;
    }
}

static const Ttk_ElementSpec HorizontalSeparatorElementSpec = {
static Ttk_ElementSpec HorizontalSeparatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SeparatorElement),
    SeparatorElementOptions,
    SeparatorElementSize,
    HorizontalSeparatorElementDraw
};

static const Ttk_ElementSpec VerticalSeparatorElementSpec = {
static Ttk_ElementSpec VerticalSeparatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SeparatorElement),
    SeparatorElementOptions,
    SeparatorElementSize,
    HorizontalSeparatorElementDraw
};

static const Ttk_ElementSpec SeparatorElementSpec = {
static Ttk_ElementSpec SeparatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SeparatorElement),
    SeparatorElementOptions,
    SeparatorElementSize,
    GeneralSeparatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Sizegrip: lower-right corner grip handle for resizing window.
 */

typedef struct {
    Tcl_Obj	*backgroundObj;
    Tcl_Obj	*gripSizeObj;
} SizegripElement;

static const Ttk_ElementOptionSpec SizegripOptions[] = {
static Ttk_ElementOptionSpec SizegripOptions[] = {
    { "-background", TK_OPTION_BORDER,
	offsetof(SizegripElement,backgroundObj), DEFAULT_BACKGROUND },
	Tk_Offset(SizegripElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-gripsize", TK_OPTION_PIXELS,
	offsetof(SizegripElement,gripSizeObj), "11.25p" },
    {0,TK_OPTION_BOOLEAN,0,0}
    {0,0,0,0}
};

static void SizegripSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    SizegripElement *grip = (SizegripElement *)elementRecord;
    int gripSize = 0;

    int gripCount = 3, gripSpace = 2, gripThickness = 3;
    Tk_GetPixelsFromObj(NULL, tkwin, grip->gripSizeObj, &gripSize);
    *widthPtr = *heightPtr = gripSize;
    *widthPtr = *heightPtr = gripCount * (gripSpace + gripThickness);
}

static void SizegripDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SizegripElement *grip = (SizegripElement *)elementRecord;
    SizegripElement *grip = elementRecord;
    int gripSize = 0;
    int gripCount = 3, gripSpace, gripThickness;
    int gripCount = 3, gripSpace = 2;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, grip->backgroundObj);
    GC lightGC = Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC);
    GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
    int x1 = b.x + b.width-1, y1 = b.y + b.height-1, x2 = x1, y2 = y1;

    Tk_GetPixelsFromObj(NULL, tkwin, grip->gripSizeObj, &gripSize);
    gripThickness = gripSize * 3 / (gripCount * 5);
    gripSpace = gripSize / 3 - gripThickness;
    while (gripCount--) {
	x1 -= gripSpace; y2 -= gripSpace;
	for (int i = 1; i < gripThickness; i++) {
	    XDrawLine(Tk_Display(tkwin), d, darkGC,  x1,y1, x2,y2); --x1; --y2;
	XDrawLine(Tk_Display(tkwin), d, darkGC,  x1,y1, x2,y2); --x1; --y2;
	}
	XDrawLine(Tk_Display(tkwin), d, lightGC,  x1,y1, x2,y2); --x1; --y2;
	XDrawLine(Tk_Display(tkwin), d, darkGC,  x1,y1, x2,y2); --x1; --y2;
	XDrawLine(Tk_Display(tkwin), d, lightGC, x1,y1, x2,y2); --x1; --y2;
    }
}

static const Ttk_ElementSpec SizegripElementSpec = {
static Ttk_ElementSpec SizegripElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SizegripElement),
    SizegripOptions,
    SizegripSize,
    SizegripDraw
};

/*----------------------------------------------------------------------
 * +++ Indicator element.
 *
 * Draws the on/off indicator for checkbuttons and radiobuttons.
 */

 *
/*
 * Indicator image descriptor:
 */
typedef struct {
    int width;				/* unscaled width */
    int height;				/* unscaled height */
    const char *const offDataPtr;
    const char *const onDataPtr;
    const char *const triDataPtr;
} IndicatorSpec;

 * Draws a 3-D square (or diamond), raised if off, sunken if on.
static const char checkbtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <rect x='.5' y='.5' width='15' height='15' rx='1.5' fill='#ffffff' stroke='#888888'/>\n\
    </svg>";

 *
static const char checkbtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <rect x='0' y='0' width='16' height='16' fill='#4a6984' rx='2'/>\n\
     <path d='m4.5 8 3 3 4-6' fill='none' stroke='#ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/>\n\
    </svg>";

 * This is actually a regression from Tk 8.5 back to the ugly old Motif
static const char checkbtnTriData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <rect x='0' y='0' width='16' height='16' fill='#4a6984' rx='2'/>\n\
     <path d='m4 8h8' fill='none' stroke='#ffffff' stroke-width='2'/>\n\
    </svg>";

 * style; use "altTheme" for the newer, nicer version.
static const IndicatorSpec checkbutton_spec = {
    16, 16,
    checkbtnOffData,
    checkbtnOnData,
    checkbtnTriData
};

 */
static const char radiobtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <circle cx='8' cy='8' r='7.5' fill='#ffffff' stroke='#888888'/>\n\
    </svg>";

static const char radiobtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <circle cx='8' cy='8' r='8' fill='#4a6984'/>\n\
     <circle cx='8' cy='8' r='3' fill='#ffffff'/>\n\
    </svg>";

static const char radiobtnTriData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <circle cx='8' cy='8' r='8' fill='#4a6984'/>\n\
     <path d='m4 8h8' fill='none' stroke='#ffffff' stroke-width='2'/>\n\
    </svg>";

static const IndicatorSpec radiobutton_spec = {
    16, 16,
    radiobtnOffData,
    radiobtnOnData,
    radiobtnTriData
};

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *foregroundObj;
    Tcl_Obj *borderColorObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *diameterObj;
    Tcl_Obj *marginObj;
    Tcl_Obj *borderWidthObj;
} IndicatorElement;

/*
 * Note that the -indicatorbackground and -indicatorforeground options below
 * have the same default value "#ffffff", but the -indicatorforeground option
 * will only be used for the alternate and selected states, in which the
 * -indicatorbackground option will have a different value (e.g., "#4a6984").
 */
static const Ttk_ElementOptionSpec IndicatorElementOptions[] = {
    { "-indicatorbackground", TK_OPTION_COLOR,
	offsetof(IndicatorElement,backgroundObj), "#ffffff" },
    { "-indicatorforeground", TK_OPTION_COLOR,
        offsetof(IndicatorElement,foregroundObj), "#ffffff" },
    { "-bordercolor", TK_OPTION_COLOR,
	offsetof(IndicatorElement,borderColorObj), "#888888" },
static Ttk_ElementOptionSpec IndicatorElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	Tk_Offset(IndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-indicatorcolor", TK_OPTION_BORDER,
	Tk_Offset(IndicatorElement,colorObj), DEFAULT_BACKGROUND },
    { "-indicatorrelief", TK_OPTION_RELIEF,
	Tk_Offset(IndicatorElement,reliefObj), "raised" },
    { "-indicatordiameter", TK_OPTION_PIXELS,
	Tk_Offset(IndicatorElement,diameterObj), "12" },
    { "-indicatormargin", TK_OPTION_STRING,
	offsetof(IndicatorElement,marginObj), "0 2 4 2" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(IndicatorElement,marginObj), "0 2 4 2" },
    { "-borderwidth", TK_OPTION_PIXELS,
	Tk_Offset(IndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { NULL, 0, 0, NULL }
};

/*
 * Checkbutton indicators (default): 3-D square.
 */
static void IndicatorElementSize(
static void SquareIndicatorElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    IndicatorElement *indicator = elementRecord;
    Ttk_Padding margins;
    int diameter = 0;
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter);
    *widthPtr = diameter + Ttk_PaddingWidth(margins);
    *heightPtr = diameter + Ttk_PaddingHeight(margins);
}

static void SquareIndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    IndicatorElement *indicator = elementRecord;
    Tk_3DBorder border = 0, interior = 0;
    int relief = TK_RELIEF_RAISED;
    Ttk_Padding padding;
    int borderWidth = 2;
    int diameter;

    interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj);
    border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj);
    Tcl_GetIntFromObj(NULL,indicator->borderWidthObj,&borderWidth);
    Tk_GetReliefFromObj(NULL,indicator->reliefObj,&relief);
    Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginObj,&padding);

    b = Ttk_PadBox(b, padding);

    diameter = b.width < b.height ? b.width : b.height;
    Tk_Fill3DRectangle(tkwin, d, interior, b.x, b.y,
	    diameter, diameter,borderWidth, TK_RELIEF_FLAT);
    Tk_Draw3DRectangle(tkwin, d, border, b.x, b.y,
	    diameter, diameter, borderWidth, relief);
}

/*
 * Radiobutton indicators:  3-D diamond.
 */
static void DiamondIndicatorElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorElement *indicator = elementRecord;
    Ttk_Padding margins;
    double scalingLevel = TkScalingLevel(tkwin);

    int diameter = 0;
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &diameter);
    *widthPtr = spec->width * scalingLevel + Ttk_PaddingWidth(margins);
    *heightPtr = spec->height * scalingLevel + Ttk_PaddingHeight(margins);
    *widthPtr = diameter + 3 + Ttk_PaddingWidth(margins);
    *heightPtr = diameter + 3 + Ttk_PaddingHeight(margins);
}

static void ColorToStr(
static void DiamondIndicatorElementDraw(
    const XColor *colorPtr, char *colorStr)     /* in the format "RRGGBB" */
{
    snprintf(colorStr, 7, "%02x%02x%02x",
             colorPtr->red >> 8, colorPtr->green >> 8, colorPtr->blue >> 8);
}

static void ImageChanged(               /* to be passed to Tk_GetImage() */
    TCL_UNUSED(void *),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
}

static void IndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned int state)
{
    IndicatorElement *indicator = (IndicatorElement *)elementRecord;
    IndicatorElement *indicator = elementRecord;
    Tk_3DBorder border = 0, interior = 0;
    int borderWidth = 2;
    int relief = TK_RELIEF_RAISED;
    int diameter, radius;
    XPoint points[4];
    Ttk_Padding padding;
    const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
    double scalingLevel = TkScalingLevel(tkwin);
    int width = spec->width * scalingLevel;
    int height = spec->height * scalingLevel;

    char bgColorStr[7], fgColorStr[7], borderColorStr[7];
    unsigned int selected = (state & TTK_STATE_SELECTED);
    unsigned int tristate = (state & TTK_STATE_ALTERNATE);
    Tcl_Interp *interp = Tk_Interp(tkwin);
    interior = Tk_Get3DBorderFromObj(tkwin, indicator->colorObj);
    char imgName[60];
    Tk_Image img;

    border = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj);
    const char *svgDataPtr;
    size_t svgDataLen;
    char *svgDataCopy;
    char *bgColorPtr, *fgColorPtr, *borderColorPtr;
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    int code;
    Tcl_GetIntFromObj(NULL,indicator->borderWidthObj,&borderWidth);
    Tk_GetReliefFromObj(NULL,indicator->reliefObj,&relief);
    Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginObj,&padding);

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
    b = Ttk_PadBox(b, padding);

    /*
     * Sanity check
     */
    if (   b.x < 0
	|| b.y < 0
	|| Tk_Width(tkwin) < b.x + width
    diameter = b.width < b.height ? b.width : b.height;
	|| Tk_Height(tkwin) < b.y + height)
    {
	/* Oops!  Not enough room to display the image.
	 * Don't draw anything.
	 */
	return;
    }

    radius = diameter / 2;

    points[0].x = b.x;
    /*
     * Construct the color strings bgColorStr, fgColorStr, and borderColorStr
     */
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->backgroundObj),
	       bgColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->foregroundObj),
	       fgColorStr);
    ColorToStr(Tk_GetColorFromObj(tkwin, indicator->borderColorObj),
	       borderColorStr);

    points[0].y = b.y + radius;
    /*
     * Check whether there is an SVG image of this size for the
     * indicator's type (0 = checkbtn, 1 = radiobtn), "state"
    points[1].x = b.x + radius;
     * (0 = off, 1 = on, 2 = tristate), and these color strings
     */
    snprintf(imgName, sizeof(imgName),
    points[1].y = b.y + 2*radius;
	     "::tk::icons::indicator_default%d_%d,%d_%s_%s_%s",
	     width,
	     spec->offDataPtr == radiobtnOffData,
    points[2].x = b.x + 2*radius;
	     tristate ? 2 : (selected ? 1 : 0),
	     bgColorStr,
	     selected || tristate ? fgColorStr : "XXXXXX",
	     selected || tristate ? "XXXXXX" : borderColorStr);
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
	/*
	 * Determine the SVG data to use for the photo image
	 */
	svgDataPtr = (tristate ? spec->triDataPtr :
		      (selected ? spec->onDataPtr : spec->offDataPtr));

    points[2].y = b.y + radius;
	/*
	 * Copy the string pointed to by svgDataPtr to
    points[3].x = b.x + radius;
	 * a newly allocated memory area svgDataCopy
	 */
	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
    points[3].y = b.y;
	    return;
	}
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	/*
	 * Update the colors within svgDataCopy
	 */
	if (selected || tristate) {
	    bgColorPtr = strstr(svgDataCopy, "4a6984");
	    fgColorPtr = strstr(svgDataCopy, "ffffff");

    Tk_Fill3DPolygon(tkwin,d,interior,points,4,borderWidth,TK_RELIEF_FLAT);
	    assert(bgColorPtr);
	    assert(fgColorPtr);

    Tk_Draw3DPolygon(tkwin,d,border,points,4,borderWidth,relief);
	    memcpy(bgColorPtr, bgColorStr, 6);
	    memcpy(fgColorPtr, fgColorStr, 6);
	} else {
	    bgColorPtr =     strstr(svgDataCopy, "ffffff");
	    borderColorPtr = strstr(svgDataCopy, "888888");

}
	    assert(bgColorPtr);
	    assert(borderColorPtr);

	    memcpy(bgColorPtr, bgColorStr, 6);
	    memcpy(borderColorPtr, borderColorStr, 6);
	}

static Ttk_ElementSpec CheckbuttonIndicatorElementSpec = {
	/*
	 * Create an SVG photo image from svgDataCopy
	 */
	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
	    return;
	}
	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
	code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL);
	ckfree(script);
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	    return;
    IndicatorElementOptions,
    SquareIndicatorElementSize,
	}
	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }

    SquareIndicatorElementDraw
    /*
     * Display the image
     */
    Tk_RedrawImage(img, 0, 0, width, height, d, b.x, b.y);
    Tk_FreeImage(img);
}
};

static const Ttk_ElementSpec IndicatorElementSpec = {
static Ttk_ElementSpec RadiobuttonIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(IndicatorElement),
    IndicatorElementOptions,
    IndicatorElementSize,
    IndicatorElementDraw
    DiamondIndicatorElementSize,
    DiamondIndicatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Arrow element(s).
 *
 * 	Draws a solid triangle inside a box.
 * 	clientData is an enum ArrowDirection pointer.
 */

typedef struct {
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *borderObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
} ArrowElement;

static const Ttk_ElementOptionSpec ArrowElementOptions[] = {
    { "-arrowsize", TK_OPTION_PIXELS,
	offsetof(ArrowElement,sizeObj), "14" },
    { "-arrowcolor", TK_OPTION_COLOR,
	offsetof(ArrowElement,colorObj), "black"},
    { "-background", TK_OPTION_BORDER,
	offsetof(ArrowElement,borderObj), DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(ArrowElement,borderWidthObj), "1" },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(ArrowElement,reliefObj), "raised"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
};

static const Ttk_Padding ArrowPadding = { 3,3,3,3 };

static void ArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding;
    int size = 14;

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
    if (*widthPtr < *heightPtr) {
	*widthPtr = *heightPtr;
    } else {
	*heightPtr = *widthPtr;
    }
}

static void ArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    int borderWidth = 1, relief = TK_RELIEF_RAISED;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);
    int cx = 0, cy = 0;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    GC gc = Tk_GCForColor(arrowColor, d);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, relief);

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    b = Ttk_PadBox(b, padding);

    switch (direction) {
	case ARROW_UP:
	case ARROW_DOWN:
	    TtkArrowSize(b.width/2, direction, &cx, &cy);
	    if ((b.height - cy) % 2 == 1) {
		++cy;
	    }
	    break;
	case ARROW_LEFT:
	case ARROW_RIGHT:
	    TtkArrowSize(b.height/2, direction, &cx, &cy);
	    if ((b.width - cx) % 2 == 1) {
		++cx;
	    }
	    break;
    }

    b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

    TtkFillArrow(Tk_Display(tkwin), d, gc, b, direction);
}

static const Ttk_ElementSpec ArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    ArrowElementSize,
    ArrowElementDraw
};

/*
 * Modified arrow element for comboboxes and spinboxes:
 * 	The width and height are different, and the left edge is drawn in the
 *	same color as the right one.
 */

static void BoxArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    double scalingLevel = TkScalingLevel(tkwin);
    Ttk_Padding padding;
    int size = 14;

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &size);
    size -= Ttk_PaddingWidth(padding);
    TtkArrowSize(size/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(padding);
    *heightPtr += Ttk_PaddingHeight(padding);
}

static void BoxArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    ArrowElement *arrow = (ArrowElement *)elementRecord;
    ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    int borderWidth = 1, relief = TK_RELIEF_RAISED;
    Display *disp = Tk_Display(tkwin);
    GC darkGC = Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC);
    int w = WIN32_XDRAWLINE_HACK;
    Ttk_Padding padding;
    double scalingLevel = TkScalingLevel(tkwin);
    int cx = 0, cy = 0;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    GC arrowGC = Tk_GCForColor(arrowColor, d);

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, relief);

    XDrawLine(disp, d, darkGC, b.x, b.y+1, b.x, b.y+b.height-1+w);

    padding.left = round(ArrowPadding.left * scalingLevel);
    padding.top = round(ArrowPadding.top * scalingLevel);
    padding.right = round(ArrowPadding.right * scalingLevel);
    padding.bottom = round(ArrowPadding.bottom * scalingLevel);

    b = Ttk_PadBox(b, padding);

    TtkArrowSize(b.width/2, direction, &cx, &cy);
    if ((b.height - cy) % 2 == 1) {
	++cy;
    }

    b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

    TtkFillArrow(disp, d, arrowGC, b, direction);
}

static const Ttk_ElementSpec BoxArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    BoxArrowElementSize,
    BoxArrowElementDraw
};

/*
 *----------------------------------------------------------------------
 * +++ Menubutton indicators.
 *
 * These aren't functional like radio/check indicators,
 * they're just affordability indicators.
 */

#define MENUBUTTON_ARROW_SIZE 5
 *
 * Standard Tk sets the indicator size to 4.0 mm by 1.7 mm.
 * I have no idea where these numbers came from.
 */

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *paddingObj;
    Tcl_Obj *widthObj;
    Tcl_Obj *heightObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *marginObj;
} MenuIndicatorElement;

static const Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = {
    { "-arrowsize", TK_OPTION_PIXELS,
	offsetof(MenuIndicatorElement,sizeObj), STRINGIFY(MENUBUTTON_ARROW_SIZE)},
    { "-arrowcolor", TK_OPTION_COLOR,
	offsetof(MenuIndicatorElement,colorObj), "black" },
    { "-arrowpadding", TK_OPTION_STRING,
	offsetof(MenuIndicatorElement,paddingObj), "3" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
static Ttk_ElementOptionSpec MenuIndicatorElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	Tk_Offset(MenuIndicatorElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-indicatorwidth", TK_OPTION_PIXELS,
	Tk_Offset(MenuIndicatorElement,widthObj), "4.0m" },
    { "-indicatorheight", TK_OPTION_PIXELS,
	Tk_Offset(MenuIndicatorElement,heightObj), "1.7m" },
    { "-borderwidth", TK_OPTION_PIXELS,
	Tk_Offset(MenuIndicatorElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { "-indicatorrelief", TK_OPTION_RELIEF,
	Tk_Offset(MenuIndicatorElement,reliefObj),"raised" },
    { "-indicatormargin", TK_OPTION_STRING,
	    Tk_Offset(MenuIndicatorElement,marginObj), "5 0" },
    { NULL, 0, 0, NULL }
};

static void MenuIndicatorElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    MenuIndicatorElement *indicator = (MenuIndicatorElement *)elementRecord;
    MenuIndicatorElement *mi = elementRecord;
    Ttk_Padding margins;
    int size = MENUBUTTON_ARROW_SIZE;

    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->paddingObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, mi->widthObj, widthPtr);
    Tk_GetPixelsFromObj(NULL, tkwin, mi->heightObj, heightPtr);
    Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj, &margins);
    TtkArrowSize(size, ARROW_DOWN, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(margins);
    *heightPtr += Ttk_PaddingHeight(margins);
}

static void MenuIndicatorElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    MenuIndicatorElement *indicator = (MenuIndicatorElement *)elementRecord;
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, indicator->colorObj);
    MenuIndicatorElement *mi = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, mi->backgroundObj);
    GC gc = Tk_GCForColor(arrowColor, d);
    int size = MENUBUTTON_ARROW_SIZE;
    int width, height;
    Ttk_Padding margins;
    int borderWidth = 2;

    Ttk_GetPaddingFromObj(NULL,tkwin,mi->marginObj,&margins);
    b = Ttk_PadBox(b, margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);

    Tk_GetPixelsFromObj(NULL, tkwin, mi->borderWidthObj, &borderWidth);
    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
    TtkArrowSize(size, ARROW_DOWN, &width, &height);
    b = Ttk_StickBox(b, width, height, 0);
	    borderWidth, TK_RELIEF_RAISED);
    TtkFillArrow(Tk_Display(tkwin), d, gc, b, ARROW_DOWN);
}

static const Ttk_ElementSpec MenuIndicatorElementSpec = {
static Ttk_ElementSpec MenuIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(MenuIndicatorElement),
    MenuIndicatorElementOptions,
    MenuIndicatorElementSize,
    MenuIndicatorElementDraw
};

/*
 *----------------------------------------------------------------------
 * +++ Trough element.
/*----------------------------------------------------------------------
 * +++ Arrow elements.
 *
 * 	Draws a solid triangle inside a box.
 * 	clientData is an enum ArrowDirection pointer.
 */
 * Used in scrollbars and scales in place of "border".
 *
 * The -groovewidth option can be used to set the size of the short axis
 * for the drawn area. This will not affect the geometry, but can be used
 * to draw a thin centered trough inside the packet alloted. Use -1 or a
 * large number to use the full area (default).

static int ArrowElements[] = { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT };
typedef struct {
    Tcl_Obj *borderObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *colorObj;
} ArrowElement;

static Ttk_ElementOptionSpec ArrowElementOptions[] = {
    { "-background", TK_OPTION_BORDER,
	Tk_Offset(ArrowElement,borderObj), DEFAULT_BACKGROUND },
    { "-relief",TK_OPTION_RELIEF,
	Tk_Offset(ArrowElement,reliefObj),"raised"},
    { "-borderwidth", TK_OPTION_PIXELS,
	Tk_Offset(ArrowElement,borderWidthObj), "1" },
    { "-arrowcolor",TK_OPTION_COLOR,
	Tk_Offset(ArrowElement,colorObj),"black"},
    { "-arrowsize", TK_OPTION_PIXELS,
	Tk_Offset(ArrowElement,sizeObj), "14" },
    { NULL, 0, 0, NULL }
};

static Ttk_Padding ArrowMargins = { 3,3,3,3 };

static void ArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ArrowElement *arrow = elementRecord;
    int direction = *(int *)clientData;
    int width = 14;

    Tk_GetPixelsFromObj(NULL, tkwin, arrow->sizeObj, &width);
    width -= Ttk_PaddingWidth(ArrowMargins);
    TtkArrowSize(width/2, direction, widthPtr, heightPtr);
    *widthPtr += Ttk_PaddingWidth(ArrowMargins);
    *heightPtr += Ttk_PaddingWidth(ArrowMargins);
}

static void ArrowElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    int direction = *(int *)clientData;
    ArrowElement *arrow = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj);
    XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj);
    int relief = TK_RELIEF_RAISED;
    int borderWidth = 1;

    Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief);

    Tk_Fill3DRectangle(
	tkwin, d, border, b.x, b.y, b.width, b.height, borderWidth, relief);

    TtkFillArrow(Tk_Display(tkwin), d, Tk_GCForColor(arrowColor, d),
	Ttk_PadBox(b, ArrowMargins), direction);
}

static Ttk_ElementSpec ArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ArrowElement),
    ArrowElementOptions,
    ArrowElementSize,
    ArrowElementDraw
};

/*----------------------------------------------------------------------
 * +++ Trough element.
 *
 * Used in scrollbars and scales in place of "border".
 */

typedef struct {
    Tcl_Obj *colorObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *colorObj;
    Tcl_Obj *grooveWidthObj;
    Tcl_Obj *orientObj;
} TroughElement;

static const Ttk_ElementOptionSpec TroughElementOptions[] = {
    { "-troughborderwidth", TK_OPTION_PIXELS,
	offsetof(TroughElement,borderWidthObj), "1" },
static Ttk_ElementOptionSpec TroughElementOptions[] = {
    { "-borderwidth", TK_OPTION_PIXELS,
	Tk_Offset(TroughElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { "-troughrelief",TK_OPTION_RELIEF,
	offsetof(TroughElement,reliefObj), "sunken" },
    { "-troughcolor", TK_OPTION_BORDER,
	offsetof(TroughElement,colorObj), DEFAULT_BACKGROUND },
	Tk_Offset(TroughElement,colorObj), DEFAULT_BACKGROUND },
    { "-groovewidth", TK_OPTION_PIXELS,
	offsetof(TroughElement,grooveWidthObj), "-1" },
    { "-orient", TK_OPTION_ANY,
	offsetof(TroughElement, orientObj), "horizontal" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { "-troughrelief",TK_OPTION_RELIEF,
	Tk_Offset(TroughElement,reliefObj), "sunken" },
    { NULL, 0, 0, NULL }
};

static void TroughElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TroughElement *troughPtr = (TroughElement *)elementRecord;
    int borderWidth = 1, grooveWidth = -1;
    TroughElement *troughPtr = elementRecord;
    int borderWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &grooveWidth);

    if (grooveWidth <= 0) {
	*paddingPtr = Ttk_UniformPadding((short)borderWidth);
    }
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}
}

static Ttk_Box troughInnerBox;

static void TroughElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    TroughElement *troughPtr = (TroughElement *)elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj);
    int borderWidth = 1, grooveWidth = -1, relief = TK_RELIEF_SUNKEN;
    TroughElement *troughPtr = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 2, relief = TK_RELIEF_SUNKEN;
    Ttk_Orient orient;

    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
    border = Tk_Get3DBorderFromObj(tkwin, troughPtr->colorObj);
    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->grooveWidthObj, &grooveWidth);
    Tk_GetReliefFromObj(NULL, troughPtr->reliefObj, &relief);
    Ttk_GetOrientFromObj(NULL, troughPtr->orientObj, &orient);

    Tk_GetPixelsFromObj(NULL, tkwin, troughPtr->borderWidthObj, &borderWidth);
    if (grooveWidth > 0 && grooveWidth < b.height && grooveWidth < b.width) {
	if (orient == TTK_ORIENT_HORIZONTAL) {
	    b.y += (b.height - grooveWidth) / 2;
	    b.height = grooveWidth;
	} else {
	    b.x += (b.width - grooveWidth) / 2;
	    b.width = grooveWidth;
        }

	troughInnerBox.x = b.x + borderWidth;
	troughInnerBox.y = b.y + borderWidth;
	troughInnerBox.width =  b.width -  2*borderWidth;
	troughInnerBox.height = b.height - 2*borderWidth;
    }

    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, relief);
}

static const Ttk_ElementSpec TroughElementSpec = {
static Ttk_ElementSpec TroughElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TroughElement),
    TroughElementOptions,
    TroughElementSize,
    TroughElementDraw
};

1256
1257
1258
1259
1260
1261
1262
1263

1264
1265

1266
1267

1268
1269

1270
1271

1272
1273
1274


1275
1276
1277
1278
1279
1280


1281
1282
1283

1284
1285

1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302


1303
1304
1305

1306
1307
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338

1339
1340
1341
1342





1343
1344
1345
1346
1347
1348
1349
1350
1351
1352












1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365





















1366
1367
1368
1369
1370
1371


1372
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382
1383
1384

1385
1386
1387
1388
1389

1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428




1429
1430
1431


1432
1433
1434
1435
1436












1437
1438
1439
1440
1441
1442
1443
1444
1445



1446
1447
1448
1449
1450
1451
1452
1453







1454
1455
1456

1457
1458
1459
1460
1461
1462
1463
1464
1465


1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498

1499
1500
1501
1502
1503
1504
1505
835
836
837
838
839
840
841

842
843

844
845

846
847

848
849

850
851


852
853
854
855
856



857
858

859

860


861
862
863
864
865
866
867
868
869
870
871
872
873
874
875



876
877

878

879
880
881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899
900

901
902
903








904
905




906
907
908
909
910
911
912








913
914
915
916
917
918
919
920
921
922
923
924
925

926
927
928
929








930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953



954
955

956




957







958





959








960














961




962











963
964
965
966



967
968





969
970
971
972
973
974
975
976
977
978
979
980









981
982
983








984
985
986
987
988
989
990



991









992
993



994





























995
996
997
998
999
1000
1001
1002







-
+

-
+

-
+

-
+

-
+

-
-
+
+



-
-
-
+
+
-

-
+
-
-
+














-
-
-
+
+
-

-
+









-
+











-
+


-
-
-
-
-
-
-
-

+
-
-
-
-
+
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
-

-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







    Tcl_Obj *orientObj;
    Tcl_Obj *thicknessObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *borderObj;
    Tcl_Obj *borderWidthObj;
} ThumbElement;

static const Ttk_ElementOptionSpec ThumbElementOptions[] = {
static Ttk_ElementOptionSpec ThumbElementOptions[] = {
    { "-orient", TK_OPTION_ANY,
	offsetof(ThumbElement, orientObj), "horizontal" },
	Tk_Offset(ThumbElement, orientObj), "horizontal" },
    { "-width", TK_OPTION_PIXELS,
	offsetof(ThumbElement,thicknessObj), DEFAULT_ARROW_SIZE },
	Tk_Offset(ThumbElement,thicknessObj), DEFAULT_ARROW_SIZE },
    { "-relief", TK_OPTION_RELIEF,
	offsetof(ThumbElement,reliefObj), "raised" },
	Tk_Offset(ThumbElement,reliefObj), "raised" },
    { "-background", TK_OPTION_BORDER,
	offsetof(ThumbElement,borderObj), DEFAULT_BACKGROUND },
	Tk_Offset(ThumbElement,borderObj), DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(ThumbElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(ThumbElement,borderWidthObj), DEFAULT_BORDERWIDTH },
    { NULL, 0, 0, NULL }
};

static void ThumbElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    ThumbElement *thumb = (ThumbElement *)elementRecord;
    ThumbElement *thumb = elementRecord;
    Ttk_Orient orient;
    int thickness;
    int orient, thickness;

    Tk_GetPixelsFromObj(NULL, tkwin, thumb->thicknessObj, &thickness);
    Ttk_GetOrientFromObj(NULL, thumb->orientObj, &orient);

    if (orient == TTK_ORIENT_VERTICAL) {
	*widthPtr = thickness;
	*heightPtr = MIN_THUMB_SIZE;
    } else {
	*widthPtr = MIN_THUMB_SIZE;
	*heightPtr = thickness;
    }
}

static void ThumbElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    ThumbElement *thumb = (ThumbElement *)elementRecord;
    ThumbElement *thumb = elementRecord;
    Tk_3DBorder  border = Tk_Get3DBorderFromObj(tkwin, thumb->borderObj);
    int borderWidth = 2, relief = TK_RELIEF_RAISED;

    Tk_GetPixelsFromObj(NULL, tkwin, thumb->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, thumb->reliefObj, &relief);
    Tk_Fill3DRectangle(tkwin, d, border, b.x, b.y, b.width, b.height,
	    borderWidth, relief);
}

static const Ttk_ElementSpec ThumbElementSpec = {
static Ttk_ElementSpec ThumbElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ThumbElement),
    ThumbElementOptions,
    ThumbElementSize,
    ThumbElementDraw
};

/*
 *----------------------------------------------------------------------
 * +++ Slider element.
 *
 * This is the moving part of the scale widget.  Drawn as a filled circle.
 * This is the moving part of the scale widget.  Drawn as a raised box.
 */

#define SLIDER_DIM 16

static const char sliderData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <circle cx='8' cy='8' r='7.5' fill='#ffffff' stroke='#c3c3c3'/>\n\
     <circle cx='8' cy='8' r='4' fill='#4a6984'/>\n\
    </svg>";

typedef struct {
    Tcl_Obj *orientObj;	     /* orientation of overall slider */
    Tcl_Obj *innerColorObj;
    Tcl_Obj *outerColorObj;
    Tcl_Obj *borderColorObj;
    Tcl_Obj *orientObj;		/* Orientation of overall slider */
    Tcl_Obj *lengthObj;      /* slider length */
    Tcl_Obj *thicknessObj;   /* slider thickness */
    Tcl_Obj *reliefObj;      /* the relief for this object */
    Tcl_Obj *borderObj;      /* the background color */
    Tcl_Obj *borderWidthObj; /* the size of the border */
} SliderElement;

static const Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-innercolor", TK_OPTION_COLOR, offsetof(SliderElement,innerColorObj),
	"#4a6984" },
    { "-outercolor", TK_OPTION_COLOR, offsetof(SliderElement,outerColorObj),
	"#ffffff" },
    { "-bordercolor", TK_OPTION_COLOR, offsetof(SliderElement,borderColorObj),
	"#c3c3c3" },
    { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj),
static Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-sliderlength", TK_OPTION_PIXELS, Tk_Offset(SliderElement,lengthObj),
	"30" },
    { "-sliderthickness",TK_OPTION_PIXELS,Tk_Offset(SliderElement,thicknessObj),
	"15" },
    { "-sliderrelief", TK_OPTION_RELIEF, Tk_Offset(SliderElement,reliefObj),
	"raised" },
    { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SliderElement,borderWidthObj),
	DEFAULT_BORDERWIDTH },
    { "-background", TK_OPTION_BORDER, Tk_Offset(SliderElement,borderObj),
	DEFAULT_BACKGROUND },
    { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj),
	"horizontal" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { NULL, 0, 0, NULL }
};

static void SliderElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    double scalingLevel = TkScalingLevel(tkwin);
    *widthPtr = *heightPtr = SLIDER_DIM * scalingLevel;
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    SliderElement *slider = elementRecord;
    int orient, length, thickness;

    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->lengthObj, &length);
    Tk_GetPixelsFromObj(NULL, tkwin, slider->thicknessObj, &thickness);

    switch (orient) {
	case TTK_ORIENT_VERTICAL:
	    *widthPtr = thickness;
	    *heightPtr = length;
	    break;

	case TTK_ORIENT_HORIZONTAL:
	    *widthPtr = length;
	    *heightPtr = thickness;
	    break;
    }
}

static void SliderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    double scalingLevel = TkScalingLevel(tkwin);
    int dim = SLIDER_DIM * scalingLevel;

    SliderElement *slider = (SliderElement *)elementRecord;
    SliderElement *slider = elementRecord;
    Ttk_Orient orient;
    Display *disp = Tk_Display(tkwin);
    XColor *innerColor = Tk_GetColorFromObj(tkwin, slider->innerColorObj);
    XColor *outerColor = Tk_GetColorFromObj(tkwin, slider->outerColorObj);
    XColor *borderColor = Tk_GetColorFromObj(tkwin, slider->borderColorObj);
    GC gc = Tk_GCForColor(innerColor, d);

    Tk_3DBorder border = NULL;
    char innerColorStr[7], outerColorStr[7], borderColorStr[7];
    Tcl_Interp *interp = Tk_Interp(tkwin);
    char imgName[50];
    Tk_Image img;

    int relief = TK_RELIEF_RAISED, borderWidth = 2, orient;
    const char *svgDataPtr = sliderData;
    size_t svgDataLen;
    char *svgDataCopy;
    char *innerColorPtr, *outerColorPtr, *borderColorPtr;
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    int code;

    /*
     * Sanity check
     */
    if (   b.x < 0
	|| b.y < 0
	|| Tk_Width(tkwin) < b.x + dim
	|| Tk_Height(tkwin) < b.y + dim)
    {
	/* Oops!  Not enough room to display the image.
	 * Don't draw anything.
	 */
	return;
    }

    border = Tk_Get3DBorderFromObj(tkwin, slider->borderObj);
    /*
     * Fill the thin trough area preceding the
     * slider's center with the inner color
     */
    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    switch (orient) {
	case TTK_ORIENT_HORIZONTAL:
	    XFillRectangle(disp, d, gc, troughInnerBox.x, troughInnerBox.y,
		    b.x + dim/2 - 1, troughInnerBox.height);
	    break;
	case TTK_ORIENT_VERTICAL:
	    XFillRectangle(disp, d, gc, troughInnerBox.x, troughInnerBox.y,
		    troughInnerBox.width, b.y + dim/2 - 1);
	    break;
    }

    Tk_GetPixelsFromObj(NULL, tkwin, slider->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, slider->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border,
    /*
     * Construct the color strings innerColorStr,
     * outerColorStr, and borderColorStr
	b.x, b.y, b.width, b.height,
	borderWidth, relief);
     */
    ColorToStr(innerColor, innerColorStr);
    ColorToStr(outerColor, outerColorStr);
    ColorToStr(borderColor, borderColorStr);


    if (relief != TK_RELIEF_FLAT) {
	if (orient == TTK_ORIENT_HORIZONTAL) {
	    if (b.width > 4) {
		b.x += b.width/2;
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		    b.x-1, b.y+borderWidth, b.x-1, b.y+b.height-borderWidth);
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		    b.x, b.y+borderWidth, b.x, b.y+b.height-borderWidth);
	    }
    /*
     * Check whether there is an SVG image of this size for these color strings
     */
    snprintf(imgName, sizeof(imgName),
	     "::tk::icons::slider_default%d_%s_%s_%s",
	     dim, innerColorStr, outerColorStr, borderColorStr);
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
	/*
	} else {
	    if (b.height > 4) {
		b.y += b.height/2;
	 * Copy the string pointed to by svgDataPtr to
	 * a newly allocated memory area svgDataCopy
	 */
	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
	    return;
	}
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		    b.x+borderWidth, b.y-1, b.x+b.width-borderWidth, b.y-1);
		XDrawLine(Tk_Display(tkwin), d,
		    Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		    b.x+borderWidth, b.y, b.x+b.width-borderWidth, b.y);
	    }
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	}
	/*
	 * Update the colors within svgDataCopy
	 */
	innerColorPtr = strstr(svgDataCopy, "4a6984");
	outerColorPtr = strstr(svgDataCopy, "ffffff");
	borderColorPtr = strstr(svgDataCopy, "c3c3c3");
	assert(innerColorPtr);
	assert(outerColorPtr);
	assert(borderColorPtr);
    }
}
	memcpy(innerColorPtr, innerColorStr, 6);
	memcpy(outerColorPtr, outerColorStr, 6);
	memcpy(borderColorPtr, borderColorStr, 6);

	/*
	 * Create an SVG photo image from svgDataCopy
	 */
	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
	    return;
	}
	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
	code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL);
	ckfree(script);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	    return;
	}
	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }

    /*
     * Display the image
     */
    Tk_RedrawImage(img, 0, 0, dim, dim, d, b.x, b.y);
    Tk_FreeImage(img);
}

static const Ttk_ElementSpec SliderElementSpec = {
static Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SliderElement),
    SliderElementOptions,
    SliderElementSize,
    SliderElementDraw
};

1520
1521
1522
1523
1524
1525
1526
1527
1528


1529
1530

1531
1532

1533
1534

1535
1536

1537
1538

1539
1540

1541
1542
1543
1544
1545
1546


1547
1548
1549

1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573


1574
1575
1576

1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607

1608
1609

1610
1611

1612
1613
1614
1615
1616

1617
1618
1619
1620
1621

1622
1623
1624

1625
1626

1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647

1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658


1659
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
1017
1018
1019
1020
1021
1022
1023


1024
1025
1026

1027
1028

1029
1030

1031
1032

1033
1034

1035
1036

1037
1038
1039
1040



1041
1042

1043

1044


1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064



1065
1066

1067

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094


1095
1096

1097
1098

1099
1100

1101





1102
1103
1104
1105


1106



1107
1108

1109
1110



1111













1112



1113





1114
1115
1116



1117
1118
1119



1120
1121


1122
1123
1124




1125
1126

1127


1128
1129
1130
1131
1132
1133




1134











1135
1136













1137
1138
1139
1140










1141



1142


















1143
1144
1145
1146
1147


1148



1149
1150
1151
1152
1153










1154


1155
1156

1157
1158
1159

1160
1161

1162




1163

















1164
1165
1166




















1167




1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182














1183



1184
1185

1186

1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219



1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240

1241
1242
1243
1244

1245
1246
1247

1248


1249

1250




1251

1252
1253

1254
1255

1256
1257
1258
1259
1260
1261
1262
1263







-
-
+
+

-
+

-
+

-
+

-
+

-
+

-
+



-
-
-
+
+
-

-
+
-
-
+



















-
-
-
+
+
-

-
+











-
+














-
-


-
+

-
+

-
+
-
-
-
-
-
+



-
-
+
-
-
-
+

-
+

-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-



-
-
-
+
+

-
-
-
+

-
-
+
+

-
-
-
-
+

-
+
-
-






-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
+
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-

+
-
+

+
-
+

-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+














-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
+
-

-
+









+
+
+
+
+
+
+
+
+
+
-
+












-
-
-



















-
+

-
+



-
+


-
+
-
-

-
+
-
-
-
-

-
+

-
+

-
+







    Tcl_Obj *thicknessObj;	/* the height/width of the bar */
    Tcl_Obj *lengthObj;		/* default width/height of the bar */
    Tcl_Obj *reliefObj; 	/* border relief for this object */
    Tcl_Obj *borderObj; 	/* background color */
    Tcl_Obj *borderWidthObj; 	/* thickness of the border */
} PbarElement;

static const Ttk_ElementOptionSpec PbarElementOptions[] = {
    { "-orient", TK_OPTION_ANY, offsetof(PbarElement,orientObj),
static Ttk_ElementOptionSpec PbarElementOptions[] = {
    { "-orient", TK_OPTION_ANY, Tk_Offset(PbarElement,orientObj),
	"horizontal" },
    { "-thickness", TK_OPTION_PIXELS, offsetof(PbarElement,thicknessObj),
    { "-thickness", TK_OPTION_PIXELS, Tk_Offset(PbarElement,thicknessObj),
	DEFAULT_PBAR_THICKNESS },
    { "-barsize", TK_OPTION_PIXELS, offsetof(PbarElement,lengthObj),
    { "-barsize", TK_OPTION_PIXELS, Tk_Offset(PbarElement,lengthObj),
	DEFAULT_PBAR_LENGTH },
    { "-pbarrelief", TK_OPTION_RELIEF, offsetof(PbarElement,reliefObj),
    { "-pbarrelief", TK_OPTION_RELIEF, Tk_Offset(PbarElement,reliefObj),
	"raised" },
    { "-borderwidth", TK_OPTION_PIXELS, offsetof(PbarElement,borderWidthObj),
    { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(PbarElement,borderWidthObj),
	DEFAULT_BORDERWIDTH },
    { "-background", TK_OPTION_BORDER, offsetof(PbarElement,borderObj),
    { "-background", TK_OPTION_BORDER, Tk_Offset(PbarElement,borderObj),
	DEFAULT_BACKGROUND },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { NULL, 0, 0, NULL }
};

static void PbarElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    TCL_UNUSED(Ttk_Padding *))
{
    PbarElement *pbar = (PbarElement *)elementRecord;
    PbarElement *pbar = elementRecord;
    Ttk_Orient orient;
    int thickness = 15, length = 30, borderWidth = 2;
    int orient, thickness = 15, length = 30, borderWidth = 2;

    Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orient);
    Tk_GetPixelsFromObj(NULL, tkwin, pbar->thicknessObj, &thickness);
    Tk_GetPixelsFromObj(NULL, tkwin, pbar->lengthObj, &length);
    Tk_GetPixelsFromObj(NULL, tkwin, pbar->borderWidthObj, &borderWidth);

    switch (orient) {
	case TTK_ORIENT_HORIZONTAL:
	    *widthPtr	= length + 2 * borderWidth;
	    *heightPtr	= thickness + 2 * borderWidth;
	    break;
	case TTK_ORIENT_VERTICAL:
	    *widthPtr	= thickness + 2 * borderWidth;
	    *heightPtr	= length + 2 * borderWidth;
	    break;
    }
}

static void PbarElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    TCL_UNUSED(Ttk_State))
{
    PbarElement *pbar = (PbarElement *)elementRecord;
    PbarElement *pbar = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, pbar->borderObj);
    int relief = TK_RELIEF_RAISED, borderWidth = 2;

    Tk_GetPixelsFromObj(NULL, tkwin, pbar->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, pbar->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, border,
	b.x, b.y, b.width, b.height,
	borderWidth, relief);
}

static const Ttk_ElementSpec PbarElementSpec = {
static Ttk_ElementSpec PbarElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(PbarElement),
    PbarElementOptions,
    PbarElementSize,
    PbarElementDraw
};

/*------------------------------------------------------------------------
 * +++ Notebook tabs and client area.
 */

typedef struct {
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *backgroundObj;
    Tcl_Obj *highlightObj;
    Tcl_Obj *highlightColorObj;
} TabElement;

static const Ttk_ElementOptionSpec TabElementOptions[] = {
static Ttk_ElementOptionSpec TabElementOptions[] = {
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(TabElement,borderWidthObj), "1" },
	Tk_Offset(TabElement,borderWidthObj),"1" },
    { "-background", TK_OPTION_BORDER,
	offsetof(TabElement,backgroundObj), DEFAULT_BACKGROUND },
	Tk_Offset(TabElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-highlight", TK_OPTION_BOOLEAN,
	offsetof(TabElement,highlightObj), "0" },
    { "-highlightcolor", TK_OPTION_COLOR,
	offsetof(TabElement,highlightColorObj), "#4a6984" },
    {0,TK_OPTION_BOOLEAN,0,0}
    {0,0,0,0}
};

static void TabElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TabElement *tab = (TabElement *)elementRecord;
    TabElement *tab = elementRecord;
    int borderWidth = 1;
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

    Tk_GetPixelsFromObj(0, tkwin, tab->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_N:
	    paddingPtr->top = 0;
    paddingPtr->top = paddingPtr->left = paddingPtr->right = borderWidth;
	    break;
	case TTK_STICK_E:
	    paddingPtr->right = 0;
    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_W:
	    paddingPtr->left = 0;
	    break;
    }
}

static void TabElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
    TabElement *tab = (TabElement *)elementRecord;
    TabElement *tab = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj);
    int highlight = 0;
    XColor *hlColor = NULL;
    int borderWidth = 1;
    int cut = 2;
    XPoint pts[6];
    double scalingLevel = TkScalingLevel(tkwin);
    int cut = round(2 * scalingLevel);
    Display *disp = Tk_Display(tkwin);
    int borderWidth = 1;
    int n = 0;

    if (mainInfoPtr != NULL) {
    Tcl_GetIntFromObj(NULL, tab->borderWidthObj, &borderWidth);
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    if (state & TTK_STATE_SELECTED) {
	/*
	 * Draw slightly outside of the allocated parcel,
	 * to overwrite the client area border.
	 */
	switch (nbTabsStickBit) {
	    default:
	    case TTK_STICK_S:
		b.height += 1;
	b.height += borderWidth;
		break;
	    case TTK_STICK_N:
		b.height += 1; b.y -= 1;
		break;
	    case TTK_STICK_E:
		b.width += 1;
		break;
	    case TTK_STICK_W:
		b.width += 1; b.x -= 1;
		break;
	}
    }

	Tcl_GetBooleanFromObj(NULL, tab->highlightObj, &highlight);
	if (highlight) {
	    hlColor = Tk_GetColorFromObj(tkwin, tab->highlightColorObj);
	}
    }

    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    pts[0].x = b.x;  pts[0].y = b.y + b.height-1;
	    pts[1].x = b.x;  pts[1].y = b.y + cut;
	    pts[2].x = b.x + cut;  pts[2].y = b.y;
	    pts[3].x = b.x + b.width-1 - cut;  pts[3].y = b.y;
    pts[n].x = b.x; 			pts[n].y = b.y + b.height - 1; ++n;
    pts[n].x = b.x;			pts[n].y = b.y + cut; ++n;
    pts[n].x = b.x + cut;  		pts[n].y = b.y; ++n;
    pts[n].x = b.x + b.width-1-cut;	pts[n].y = b.y; ++n;
	    pts[4].x = b.x + b.width-1;  pts[4].y = b.y + cut;
	    pts[5].x = b.x + b.width-1;  pts[5].y = b.y + b.height;
	    break;
	case TTK_STICK_N:
	    pts[0].x = b.x;  pts[0].y = b.y;
	    pts[1].x = b.x;  pts[1].y = b.y + b.height-1 - cut;
	    pts[2].x = b.x + cut;  pts[2].y = b.y + b.height-1;
	    pts[3].x = b.x + b.width-1 - cut;  pts[3].y = b.y + b.height-1;
	    pts[4].x = b.x + b.width-1;  pts[4].y = b.y + b.height-1 - cut;
	    pts[5].x = b.x + b.width-1;  pts[5].y = b.y-1;
    pts[n].x = b.x + b.width-1; 	pts[n].y = b.y + cut; ++n;
	    break;
	case TTK_STICK_E:
	    pts[0].x = b.x + b.width-1;  pts[0].y = b.y;
    pts[n].x = b.x + b.width-1; 	pts[n].y = b.y + b.height; ++n;
	    pts[1].x = b.x + cut;  pts[1].y = b.y;
	    pts[2].x = b.x;  pts[2].y = b.y + cut;
	    pts[3].x = b.x;  pts[3].y = b.y + b.height-1 - cut;
	    pts[4].x = b.x + cut;  pts[4].y = b.y + b.height-1;
	    pts[5].x = b.x + b.width;  pts[5].y = b.y + b.height-1;
	    break;
	case TTK_STICK_W:
	    pts[0].x = b.x;  pts[0].y = b.y;
	    pts[1].x = b.x + b.width-1 - cut;  pts[1].y = b.y;
	    pts[2].x = b.x + b.width-1;  pts[2].y = b.y + cut;
	    pts[3].x = b.x + b.width-1;  pts[3].y = b.y + b.height-1 - cut;
	    pts[4].x = b.x + b.width-1 - cut;  pts[4].y = b.y + b.height-1;
	    pts[5].x = b.x-1;  pts[5].y = b.y + b.height-1;
	    break;
    }

    XFillPolygon(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC),
	    pts, 6, Convex, CoordModeOrigin);

    XFillPolygon(Tk_Display(tkwin), d,
	Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC),
	pts, 6, Convex, CoordModeOrigin);

    switch (nbTabsStickBit) {
	default:
#ifndef _WIN32
	case TTK_STICK_S:
	    pts[5].y -= 1 - WIN32_XDRAWLINE_HACK;
	    break;
    /*
     * Account for whether XDrawLines draws endpoints by platform
     */
    --pts[5].y;
#endif
	case TTK_STICK_N:
	    pts[5].y += 1 - WIN32_XDRAWLINE_HACK;
	    break;
	case TTK_STICK_E:
	    pts[5].x -= 1 - WIN32_XDRAWLINE_HACK;
	    break;
	case TTK_STICK_W:
	    pts[5].x += 1 - WIN32_XDRAWLINE_HACK;
	    break;
    }


    Tcl_GetIntFromObj(NULL, tab->borderWidthObj, &borderWidth);
    while (borderWidth--) {
	XDrawLines(Tk_Display(tkwin), d,
	XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		pts, 4, CoordModeOrigin);
	XDrawLines(Tk_Display(tkwin), d,
	XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		pts+3, 3, CoordModeOrigin);

	++pts[0].x; ++pts[1].x; ++pts[2].x;             --pts[4].x; --pts[5].x;
	switch (nbTabsStickBit) {
	    default:
	    case TTK_STICK_S:
		++pts[0].x;  ++pts[1].x;  ++pts[2].y;
	                        ++pts[2].y; ++pts[3].y;
		++pts[3].y;  --pts[4].x;  --pts[5].x;
		break;
	    case TTK_STICK_N:
		++pts[0].x;  ++pts[1].x;  --pts[2].y;
		--pts[3].y;  --pts[4].x;  --pts[5].x;
		break;
	    case TTK_STICK_E:
		++pts[0].y;  ++pts[1].y;  ++pts[2].x;
		++pts[3].x;  --pts[4].y;  --pts[5].y;
		break;
	    case TTK_STICK_W:
		++pts[0].y;  ++pts[1].y;  --pts[2].x;
		--pts[3].x;  --pts[4].y;  --pts[5].y;
		break;
	}
    }

    }

}
    if (highlight) {
	switch (nbTabsStickBit) {
	    default:
	    case TTK_STICK_S:
		XFillRectangle(disp, d, Tk_GCForColor(hlColor, d),
			b.x + cut, b.y, b.width - 2*cut, cut);
		break;
	    case TTK_STICK_N:
		XFillRectangle(disp, d, Tk_GCForColor(hlColor, d),
			b.x + cut, b.y + b.height - cut, b.width - 2*cut, cut);
		break;
	    case TTK_STICK_E:
		XFillRectangle(disp, d, Tk_GCForColor(hlColor, d),
			b.x, b.y + cut, cut, b.height - 2*cut);
		break;
	    case TTK_STICK_W:
		XFillRectangle(disp, d, Tk_GCForColor(hlColor, d),
			b.x + b.width - cut, b.y + cut, cut, b.height - 2*cut);
		break;
	}

    }
}

static const Ttk_ElementSpec TabElementSpec = {
static Ttk_ElementSpec TabElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TabElement),
    TabElementOptions,
    TabElementSize,
    TabElementDraw
};

/*
 * Client area element:
 * Uses same resources as tab element.
 */
typedef TabElement ClientElement;
#define ClientElementOptions TabElementOptions

static void ClientElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
{
    ClientElement *ce = (ClientElement *)elementRecord;
    int borderWidth = 1;

    Tk_GetPixelsFromObj(0, tkwin, ce->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static void ClientElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_State))
{
    ClientElement *ce = (ClientElement *)elementRecord;
    ClientElement *ce = elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, ce->backgroundObj);
    int borderWidth = 1;

    Tcl_GetIntFromObj(NULL, ce->borderWidthObj, &borderWidth);

    Tk_Fill3DRectangle(tkwin, d, border,
	b.x, b.y, b.width, b.height, borderWidth,TK_RELIEF_RAISED);
}

static void ClientElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ClientElement *ce = elementRecord;
    int borderWidth = 1;
    Tk_GetPixelsFromObj(0, tkwin, ce->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
}

static const Ttk_ElementSpec ClientElementSpec = {
static Ttk_ElementSpec ClientElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ClientElement),
    ClientElementOptions,
    ClientElementSize,
    ClientElementDraw
};

/*----------------------------------------------------------------------
 * TtkElements_Init --
 *	Register default element implementations.
 */

MODULE_SCOPE
void TtkElements_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkElements_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_GetDefaultTheme(interp);

    /*
     * Elements:
     */
    Ttk_RegisterElement(interp, theme, "background",
	    &BackgroundElementSpec,NULL);

    Ttk_RegisterElement(interp, theme, "fill", &FillElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "border", &BorderElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "field", &FieldElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "focus", &FocusElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "padding", &PaddingElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "Checkbutton.indicator",
	    &IndicatorElementSpec, (void *)&checkbutton_spec);
	    &CheckbuttonIndicatorElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "Radiobutton.indicator",
	    &IndicatorElementSpec, (void *)&radiobutton_spec);
	    &RadiobuttonIndicatorElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "Menubutton.indicator",
	    &MenuIndicatorElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "indicator", &ttkNullElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "indicator", &ttkNullElementSpec,NULL);

    Ttk_RegisterElement(interp, theme, "uparrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);
    Ttk_RegisterElement(interp, theme, "Spinbox.uparrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_UP));
    Ttk_RegisterElement(interp, theme, "downarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_DOWN));
	    &ArrowElementSpec, &ArrowElements[1]);
    Ttk_RegisterElement(interp, theme, "Spinbox.downarrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "Combobox.downarrow",
	    &BoxArrowElementSpec, INT2PTR(ARROW_DOWN));
    Ttk_RegisterElement(interp, theme, "leftarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_LEFT));
	    &ArrowElementSpec, &ArrowElements[2]);
    Ttk_RegisterElement(interp, theme, "rightarrow",
	    &ArrowElementSpec, INT2PTR(ARROW_RIGHT));
	    &ArrowElementSpec, &ArrowElements[3]);
    Ttk_RegisterElement(interp, theme, "arrow",
	    &ArrowElementSpec, INT2PTR(ARROW_UP));
	    &ArrowElementSpec, &ArrowElements[0]);

    Ttk_RegisterElement(interp, theme, "trough", &TroughElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "thumb", &ThumbElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "slider", &SliderElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "pbar", &PbarElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "separator",

Changes to generic/ttk/ttkEntry.c.

1
2
3
4
5
6
7
8





9
10
11





12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3





4
5
6
7
8
9
10

11
12
13
14
15
16
17
18




19
20
21
22
23
24
25



-
-
-
-
-
+
+
+
+
+


-
+
+
+
+
+



-
-
-
-







/*
 * DERIVED FROM: tk/generic/tkEntry.c r1.35.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2000 Ajuba Solutions.
 * Copyright © 2002 ActiveState Corporation.
 * Copyright © 2004 Joe English
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 Ajuba Solutions.
 * Copyright (c) 2002 ActiveState Corporation.
 * Copyright (c) 2004 Joe English
 */

#include "tkInt.h"
#include <string.h>
#include <stdio.h>
#include <tkInt.h>
#include <X11/Xatom.h>

#include "ttkTheme.h"
#include "ttkWidget.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Extra bits for core.flags:
 */
#define GOT_SELECTION		(WIDGET_USER_FLAG<<1)
#define SYNCING_VARIABLE	(WIDGET_USER_FLAG<<2)
#define VALIDATING		(WIDGET_USER_FLAG<<3)
#define VALIDATION_SET_VALUE	(WIDGET_USER_FLAG<<4)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92


93
94
95
96



97
98
99
100
101
102
103
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89


90
91
92



93
94
95
96
97
98
99
100
101
102







-














-
-
+
+

-
-
-
+
+
+







 * displayString points to string if showChar == NULL,
 * or to malloc'ed storage if showChar != NULL.
 */

/* Style parameters:
 */
typedef struct {
    Tcl_Obj *placeholderForegroundObj;/* Foreground color for placeholder text */
    Tcl_Obj *foregroundObj;	/* Foreground color for normal text */
    Tcl_Obj *backgroundObj;	/* Entry widget background color */
    Tcl_Obj *selBorderObj;	/* Border and background for selection */
    Tcl_Obj *selBorderWidthObj;	/* Width of selection border */
    Tcl_Obj *selForegroundObj;	/* Foreground color for selected text */
    Tcl_Obj *insertColorObj;	/* Color of insertion cursor */
    Tcl_Obj *insertWidthObj;	/* Insert cursor width */
} EntryStyleData;

typedef struct {
    /*
     * Internal state:
     */
    char *string;		/* Storage for string (malloced) */
    Tcl_Size numBytes;		/* Length of string in bytes. */
    Tcl_Size numChars;		/* Length of string in characters. */
    int numBytes;		/* Length of string in bytes. */
    int numChars;		/* Length of string in characters. */

    Tcl_Size insertPos;		/* Insert index */
    Tcl_Size selectFirst;		/* Index of start of selection, or TCL_INDEX_NONE */
    Tcl_Size selectLast;		/* Index of end of selection, or TCL_INDEX_NONE */
    int insertPos;		/* Insert index */
    int selectFirst;		/* Index of start of selection, or -1 */
    int selectLast;		/* Index of end of selection, or -1 */

    Scrollable xscroll;		/* Current scroll position */
    ScrollHandle xscrollHandle;

    /*
     * Options managed by Tk_SetOptions:
     */
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
114
115
116
117
118
119
120


121
122
123
124
125
126
127







-
-







    Tk_Justify justify;		/* Text justification */

    EntryStyleData styleData;	/* Display style data (widget options) */
    EntryStyleData styleDefaults;/* Style defaults (fallback values) */

    Tcl_Obj *stateObj;		/* Compatibility option -- see CheckStateObj */

    Tcl_Obj *placeholderObj;	/* Text to display for placeholder text */

    /*
     * Derived resources:
     */
    Ttk_TraceHandle *textVariableTrace;

    char *displayString;	/* String to use when displaying */
    Tk_TextLayout textLayout;	/* Cached text layout information. */
146
147
148
149
150
151
152
153
154


155
156
157
158
159




160
161

162
163

164
165
166

167
168
169

170
171
172
173


174
175
176
177
178

179
180
181

182
183
184

185
186
187
188


189
190

191
192
193

194
195
196

197
198
199
200
201
202
203
204
205

206
207

208
209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
143
144
145
146
147
148
149


150
151





152
153
154
155
156

157
158

159
160
161

162
163
164

165
166
167


168
169



170

171
172
173

174
175
176

177
178
179


180
181
182

183
184
185

186
187
188

189
190
191
192
193



194

195
196

197


198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236







-
-
+
+
-
-
-
-
-
+
+
+
+

-
+

-
+


-
+


-
+


-
-
+
+
-
-
-

-
+


-
+


-
+


-
-
+
+

-
+


-
+


-
+




-
-
-

-
+

-
+
-
-
+




















-











-







#define STATE_CHANGED	 	(0x100)	/* -state option changed */
#define TEXTVAR_CHANGED	 	(0x200)	/* -textvariable option changed */
#define SCROLLCMD_CHANGED	(0x400)	/* -xscrollcommand option changed */

/*
 * Default option values:
 */
#define DEF_SELECT_BG		"#000000"
#define DEF_SELECT_FG		"#ffffff"
#define DEF_SELECT_BG	"#000000"
#define DEF_SELECT_FG	"#ffffff"
#define DEF_PLACEHOLDER_FG	"#b3b3b3"
#define DEF_INSERT_BG		"black"
#define DEF_ENTRY_WIDTH		"20"
#define DEF_ENTRY_FONT		"TkTextFont"
#define DEF_LIST_HEIGHT		"10"
#define DEF_INSERT_BG	"black"
#define DEF_ENTRY_WIDTH	"20"
#define DEF_ENTRY_FONT	"TkTextFont"
#define DEF_LIST_HEIGHT	"10"

static const Tk_OptionSpec EntryOptionSpecs[] = {
static Tk_OptionSpec EntryOptionSpecs[] = {
    {TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
        "ExportSelection", "1", TCL_INDEX_NONE, offsetof(Entry, entry.exportSelection),
        "ExportSelection", "1", -1, Tk_Offset(Entry, entry.exportSelection),
	0,0,0 },
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEF_ENTRY_FONT, offsetof(Entry, entry.fontObj),TCL_INDEX_NONE,
	DEF_ENTRY_FONT, Tk_Offset(Entry, entry.fontObj),-1,
	0,0,GEOMETRY_CHANGED},
    {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
	NULL, TCL_INDEX_NONE, offsetof(Entry, entry.invalidCmd),
	NULL, -1, Tk_Offset(Entry, entry.invalidCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	"left", TCL_INDEX_NONE, offsetof(Entry, entry.justify),
	TK_OPTION_ENUM_VAR, 0, GEOMETRY_CHANGED},
	"left", -1, Tk_Offset(Entry, entry.justify),
	0, 0, GEOMETRY_CHANGED},
    {TK_OPTION_STRING, "-placeholder", "placeHolder", "PlaceHolder",
	NULL, offsetof(Entry, entry.placeholderObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-show", "show", "Show",
        NULL, TCL_INDEX_NONE, offsetof(Entry, entry.showChar),
        NULL, -1, Tk_Offset(Entry, entry.showChar),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_STRING, "-state", "state", "State",
	"normal", offsetof(Entry, entry.stateObj), TCL_INDEX_NONE,
	"normal", Tk_Offset(Entry, entry.stateObj), -1,
        0,0,STATE_CHANGED},
    {TK_OPTION_STRING, "-textvariable", "textVariable", "Variable",
	NULL, offsetof(Entry, entry.textVariableObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Entry, entry.textVariableObj), -1,
	TK_OPTION_NULL_OK,0,TEXTVAR_CHANGED},
    {TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate",
	"none", TCL_INDEX_NONE, offsetof(Entry, entry.validate),
	TK_OPTION_ENUM_VAR, validateStrings, 0},
	"none", -1, Tk_Offset(Entry, entry.validate),
	0, (ClientData) validateStrings, 0},
    {TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand",
	NULL, TCL_INDEX_NONE, offsetof(Entry, entry.validateCmd),
	NULL, -1, Tk_Offset(Entry, entry.validateCmd),
	TK_OPTION_NULL_OK, 0, 0},
    {TK_OPTION_INT, "-width", "width", "Width",
	DEF_ENTRY_WIDTH, offsetof(Entry, entry.widthObj), TCL_INDEX_NONE,
	DEF_ENTRY_WIDTH, Tk_Offset(Entry, entry.widthObj), -1,
	0,0,GEOMETRY_CHANGED},
    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	NULL, TCL_INDEX_NONE, offsetof(Entry, entry.xscroll.scrollCmd),
	NULL, -1, Tk_Offset(Entry, entry.xscroll.scrollCmd),
	TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},

    /* EntryStyleData options:
     */
    {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor",
	NULL, offsetof(Entry, entry.styleData.backgroundObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
	NULL, offsetof(Entry, entry.styleData.foregroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Entry, entry.styleData.foregroundObj), -1,
	TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground",
    {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor",
        "PlaceholderForeground", NULL,
        offsetof(Entry, entry.styleData.placeholderForegroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Entry, entry.styleData.backgroundObj), -1,
	TK_OPTION_NULL_OK,0,0},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*------------------------------------------------------------------------
 * +++ EntryStyleData management.
 * 	This is still more awkward than it should be;
 * 	it should be able to use the Element API instead.
 */

/* EntryInitStyleDefaults --
 * 	Initialize EntryStyleData record to fallback values.
 */
static void EntryInitStyleDefaults(EntryStyleData *es)
{
#define INIT(member, value) \
	es->member = Tcl_NewStringObj(value, -1); \
	Tcl_IncrRefCount(es->member);
    INIT(placeholderForegroundObj, DEF_PLACEHOLDER_FG)
    INIT(foregroundObj, DEFAULT_FOREGROUND)
    INIT(selBorderObj, DEF_SELECT_BG)
    INIT(selForegroundObj, DEF_SELECT_FG)
    INIT(insertColorObj, DEFAULT_FOREGROUND)
    INIT(selBorderWidthObj, "0")
    INIT(insertWidthObj, "1")
#undef INIT
}

static void EntryFreeStyleDefaults(EntryStyleData *es)
{
    Tcl_DecrRefCount(es->placeholderForegroundObj);
    Tcl_DecrRefCount(es->foregroundObj);
    Tcl_DecrRefCount(es->selBorderObj);
    Tcl_DecrRefCount(es->selForegroundObj);
    Tcl_DecrRefCount(es->insertColorObj);
    Tcl_DecrRefCount(es->selBorderWidthObj);
    Tcl_DecrRefCount(es->insertWidthObj);
}
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272







-










-







    /* Initialize to fallback values:
     */
    *es = entryPtr->entry.styleDefaults;

#   define INIT(member, name) \
    if ((tmp=Ttk_QueryOption(entryPtr->core.layout,name,state))) \
    	es->member=tmp;
    INIT(placeholderForegroundObj, "-placeholderforeground");
    INIT(foregroundObj, "-foreground");
    INIT(selBorderObj, "-selectbackground")
    INIT(selBorderWidthObj, "-selectborderwidth")
    INIT(selForegroundObj, "-selectforeground")
    INIT(insertColorObj, "-insertcolor")
    INIT(insertWidthObj, "-insertwidth")
#undef INIT

    /* Reacquire color & border resources from resource cache.
     */
    es->placeholderForegroundObj = Ttk_UseColor(cache, tkwin, es->placeholderForegroundObj);
    es->foregroundObj = Ttk_UseColor(cache, tkwin, es->foregroundObj);
    es->selForegroundObj = Ttk_UseColor(cache, tkwin, es->selForegroundObj);
    es->insertColorObj = Ttk_UseColor(cache, tkwin, es->insertColorObj);
    es->selBorderObj = Ttk_UseBorder(cache, tkwin, es->selBorderObj);
}

/*------------------------------------------------------------------------
296
297
298
299
300
301
302
303
304
305



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359

360
361
362


363
364
365
366

367
368

369
370
371
372
373
374
375
376
377
378
379

380
381



382
383
384
385
386
387
388
389
390
391
392

393
394

395
396

397
398
399
400
401
402

403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428



429
430
431
432
433
434
435
436
437
438
439
440

441
442
443
444

445
446
447
448
449

450
451
452
453
454



455
456
457
458
459
460
461



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478
479
480

481
482
483
484

485
486
487
488
489
490
491

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
281
282
283
284
285
286
287



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306


307


308
309
310
311
312








313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332

333
334


335
336
337
338
339

340


341
342
343
344
345
346
347



348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

365
366

367
368

369
370
371
372
373
374

375
376
377
378
379

380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397



398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415

416
417
418
419
420

421
422
423



424
425
426
427
428
429
430



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

448
449
450
451

452
453
454
455

456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
490







-
-
-
+
+
+
















-
-

-
-
+




-
-
-
-
-
-
-
-


















-
+

-
+

-
-
+
+



-
+
-
-
+






-
-
-

-
+


+
+
+










-
+

-
+

-
+





-
+




-


-
+















-
-
-
+
+
+











-
+



-
+




-
+


-
-
-
+
+
+




-
-
-
+
+
+














-
+



-
+



-
+






-
+



















-
+







static char *EntryDisplayString(const char *showChar, int numChars)
{
    char *displayString, *p;
    int size;
    int ch;
    char buf[6];

    Tcl_UtfToUniChar(showChar, &ch);
    size = Tcl_UniCharToUtf(ch, buf);
    p = displayString = (char *)ckalloc(numChars * size + 1);
    TkUtfToUniChar(showChar, &ch);
    size = TkUniCharToUtf(ch, buf);
    p = displayString = ckalloc(numChars * size + 1);

    while (numChars--) {
	memcpy(p, buf, size);
	p += size;
    }
    *p = '\0';

    return displayString;
}

/* EntryUpdateTextLayout --
 * 	Recompute textLayout, layoutWidth, and layoutHeight
 * 	from displayString and fontObj.
 */
static void EntryUpdateTextLayout(Entry *entryPtr)
{
    Tcl_Size length;
    char *text;
    Tk_FreeTextLayout(entryPtr->entry.textLayout);
    if ((entryPtr->entry.numChars != 0) || (entryPtr->entry.placeholderObj == NULL)) {
        entryPtr->entry.textLayout = Tk_ComputeTextLayout(
    entryPtr->entry.textLayout = Tk_ComputeTextLayout(
	    Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj),
	    entryPtr->entry.displayString, entryPtr->entry.numChars,
	    0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES,
	    &entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight);
    } else {
        text = Tcl_GetStringFromObj(entryPtr->entry.placeholderObj, &length);
        entryPtr->entry.textLayout = Tk_ComputeTextLayout(
	    Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj),
	    text, length,
	    0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES,
	    &entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight);
    }
}

/* EntryEditable --
 * 	Returns 1 if the entry widget accepts user changes, 0 otherwise
 */
static int
EntryEditable(Entry *entryPtr)
{
    return !(entryPtr->core.state & (TTK_STATE_DISABLED|TTK_STATE_READONLY));
}

/*------------------------------------------------------------------------
 * +++ Selection management.
 */

/* EntryFetchSelection --
 *	Selection handler for entry widgets.
 */
static Tcl_Size
static int
EntryFetchSelection(
    void *clientData, Tcl_Size offset, char *buffer, Tcl_Size maxBytes)
    ClientData clientData, int offset, char *buffer, int maxBytes)
{
    Entry *entryPtr = (Entry *)clientData;
    Tcl_Size byteCount;
    Entry *entryPtr = (Entry *) clientData;
    size_t byteCount;
    const char *string;
    const char *selStart, *selEnd;

    if (entryPtr->entry.selectFirst < 0 || (!entryPtr->entry.exportSelection)
    if (entryPtr->entry.selectFirst < 0 || !entryPtr->entry.exportSelection) {
	    || Tcl_IsSafe(entryPtr->core.interp)) {
	return TCL_INDEX_NONE;
	return -1;
    }
    string = entryPtr->entry.displayString;

    selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst);
    selEnd = Tcl_UtfAtIndex(selStart,
	    entryPtr->entry.selectLast - entryPtr->entry.selectFirst);
    if (selEnd  <= selStart + offset) {
	return 0;
    }
    byteCount = selEnd - selStart - offset;
    if (byteCount > maxBytes) {
    if (byteCount > (size_t)maxBytes) {
    /* @@@POSSIBLE BUG: Can transfer partial UTF-8 sequences.  Is this OK? */
	byteCount = maxBytes;
    }
    if (byteCount <= 0) {
	return 0;
    }
    memcpy(buffer, selStart + offset, byteCount);
    buffer[byteCount] = '\0';
    return byteCount;
}

/* EntryLostSelection --
 *	Tk_LostSelProc for Entry widgets; called when an entry
 *	loses ownership of the selection.
 */
static void EntryLostSelection(void *clientData)
static void EntryLostSelection(ClientData clientData)
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = (Entry *) clientData;
    entryPtr->core.flags &= ~GOT_SELECTION;
    entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE;
    entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1;
    TtkRedisplayWidget(&entryPtr->core);
}

/* EntryOwnSelection --
 * 	Assert ownership of the PRIMARY selection,
 * 	if -exportselection set and selection is present and interp is unsafe.
 * 	if -exportselection set and selection is present.
 */
static void EntryOwnSelection(Entry *entryPtr)
{
    if (entryPtr->entry.exportSelection
	&& (!Tcl_IsSafe(entryPtr->core.interp))
	&& !(entryPtr->core.flags & GOT_SELECTION)) {
	Tk_OwnSelection(entryPtr->core.tkwin, XA_PRIMARY, EntryLostSelection,
		entryPtr);
		(ClientData) entryPtr);
	entryPtr->core.flags |= GOT_SELECTION;
    }
}

/*------------------------------------------------------------------------
 * +++ Validation.
 */

/* ExpandPercents --
 *	Expand an entry validation script template (-validatecommand
 *	or -invalidcommand).
 */
static void
ExpandPercents(
     Entry *entryPtr,		/* Entry that needs validation. */
     const char *templ, 	/* Script template */
     const char *newValue,		/* Potential new value of entry string */
     Tcl_Size index,			/* index of insert/delete */
     const char *template, 	/* Script template */
     const char *new,		/* Potential new value of entry string */
     int index,			/* index of insert/delete */
     int count,			/* #changed characters */
     VREASON reason,		/* Reason for change */
     Tcl_DString *dsPtr)	/* Result of %-substitutions */
{
    int spaceNeeded, cvtFlags;
    int number, length;
    const char *string;
    int stringLength;
    int ch;
    char numStorage[2*TCL_INTEGER_SPACE];

    while (*templ) {
    while (*template) {
	/* Find everything up to the next % character and append it
	 * to the result string.
	 */
	string = Tcl_UtfFindFirst(templ, '%');
	string = Tcl_UtfFindFirst(template, '%');
	if (string == NULL) {
	    /* No more %-sequences to expand.
	     * Copy the rest of the template.
	     */
	    Tcl_DStringAppend(dsPtr, templ, TCL_INDEX_NONE);
	    Tcl_DStringAppend(dsPtr, template, -1);
	    return;
	}
	if (string != templ) {
	    Tcl_DStringAppend(dsPtr, templ, string - templ);
	    templ = string;
	if (string != template) {
	    Tcl_DStringAppend(dsPtr, template, string - template);
	    template = string;
	}

	/* There's a percent sequence here.  Process it.
	 */
	++templ; /* skip over % */
	if (*templ != '\0') {
	    templ += Tcl_UtfToUniChar(templ, &ch);
	++template; /* skip over % */
	if (*template != '\0') {
	    template += TkUtfToUniChar(template, &ch);
	} else {
	    ch = '%';
	}

	stringLength = -1;
	switch (ch) {
	    case 'd': /* Type of call that caused validation */
		if (reason == VALIDATE_INSERT) {
		    number = 1;
		} else if (reason == VALIDATE_DELETE) {
		    number = 0;
		} else {
		    number = -1;
		}
		snprintf(numStorage, sizeof(numStorage), "%d", number);
		sprintf(numStorage, "%d", number);
		string = numStorage;
		break;
	    case 'i': /* index of insert/delete */
		snprintf(numStorage, sizeof(numStorage), "%" TCL_SIZE_MODIFIER "d", index);
		sprintf(numStorage, "%d", index);
		string = numStorage;
		break;
	    case 'P': /* 'Peeked' new value of the string */
		string = newValue;
		string = new;
		break;
	    case 's': /* Current string value */
		string = entryPtr->entry.string;
		break;
	    case 'S': /* string to be inserted/deleted, if any */
		if (reason == VALIDATE_INSERT) {
		    string = Tcl_UtfAtIndex(newValue, index);
		    string = Tcl_UtfAtIndex(new, index);
		    stringLength = Tcl_UtfAtIndex(string, count) - string;
		} else if (reason == VALIDATE_DELETE) {
		    string = Tcl_UtfAtIndex(entryPtr->entry.string, index);
		    stringLength = Tcl_UtfAtIndex(string, count) - string;
		} else {
		    string = "";
		    stringLength = 0;
		}
		break;
	    case 'v': /* type of validation currently set */
		string = validateStrings[entryPtr->entry.validate];
		break;
	    case 'V': /* type of validation in effect */
		string = validateReasonStrings[reason];
		break;
	    case 'W': /* widget name */
		string = Tk_PathName(entryPtr->core.tkwin);
		break;
	    default:
		length = Tcl_UniCharToUtf(ch, numStorage);
		length = TkUniCharToUtf(ch, numStorage);
		numStorage[length] = '\0';
		string = numStorage;
		break;
	}

	spaceNeeded = Tcl_ScanCountedElement(string, stringLength, &cvtFlags);
	length = Tcl_DStringLength(dsPtr);
528
529
530
531
532
533
534
535

536
537
538
539



540
541
542
543
544
545
546

547
548
549
550
551
552
553
500
501
502
503
504
505
506

507
508



509
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525







-
+

-
-
-
+
+
+






-
+







 * 	Build and evaluate an entry validation script.
 * 	If the script raises an error, disable validation
 * 	by setting '-validate none'
 */
static int RunValidationScript(
    Tcl_Interp *interp, 	/* Interpreter to use */
    Entry *entryPtr,		/* Entry being validated */
    const char *templ,	/* Script template */
    const char *template,	/* Script template */
    const char *optionName,	/* "-validatecommand", "-invalidcommand" */
    const char *newValue,	/* Potential new value of entry string */
    Tcl_Size index,			/* index of insert/delete */
    Tcl_Size count,			/* #changed characters */
    const char *new,		/* Potential new value of entry string */
    int index,			/* index of insert/delete */
    int count,			/* #changed characters */
    VREASON reason)		/* Reason for change */
{
    Tcl_DString script;
    int code;

    Tcl_DStringInit(&script);
    ExpandPercents(entryPtr, templ, newValue, index, count, reason, &script);
    ExpandPercents(entryPtr, template, new, index, count, reason, &script);
    code = Tcl_EvalEx(interp,
		Tcl_DStringValue(&script), Tcl_DStringLength(&script),
		TCL_EVAL_GLOBAL);
    Tcl_DStringFree(&script);
    if (WidgetDestroyed(&entryPtr->core))
	return TCL_ERROR;

583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600


601
602
603
604
605
606
607

608
609

610
611
612
613
614
615
616
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570


571
572
573
574
575
576
577
578

579
580

581
582
583
584
585
586
587
588







-
+








-
-
+
+






-
+

-
+







/* EntryValidateChange --
 *	Validate a proposed change to the entry widget's value if required.
 *	Call the -invalidcommand if validation fails.
 *
 * Returns:
 *	TCL_OK if the change is accepted
 *	TCL_BREAK if the change is rejected
 *	TCL_ERROR if any errors occurred
 *      TCL_ERROR if any errors occured
 *
 * The change will be rejected if -validatecommand returns 0,
 * or if -validatecommand or -invalidcommand modifies the value.
 */
static int
EntryValidateChange(
    Entry *entryPtr,		/* Entry that needs validation. */
    const char *newValue,	/* Potential new value of entry string */
    Tcl_Size index,			/* index of insert/delete, TCL_INDEX_NONE otherwise */
    Tcl_Size count,			/* #changed characters */
    int index,			/* index of insert/delete, -1 otherwise */
    int count,			/* #changed characters */
    VREASON reason)		/* Reason for change */
{
    Tcl_Interp *interp = entryPtr->core.interp;
    VMODE vmode = entryPtr->entry.validate;
    int code, change_ok;

    if ((entryPtr->entry.validateCmd == NULL)
    if (   (entryPtr->entry.validateCmd == NULL)
	|| (entryPtr->core.flags & VALIDATING)
	|| !EntryNeedsValidation(vmode, reason))
	|| !EntryNeedsValidation(vmode, reason) )
    {
	return TCL_OK;
    }

    entryPtr->core.flags |= VALIDATING;

    /* Run -validatecommand and check return value:
656
657
658
659
660
661
662
663

664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690


691
692
693
694
695
696
697
698
628
629
630
631
632
633
634

635



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654





655
656

657
658
659
660
661
662
663







-
+
-
-
-



















-
-
-
-
-
+
+
-







/* EntryRevalidate --
 * 	Revalidate the current value of an entry widget,
 * 	update the TTK_STATE_INVALID bit.
 *
 * Returns:
 * 	TCL_OK if valid, TCL_BREAK if invalid, TCL_ERROR on error.
 */
static int EntryRevalidate(
static int EntryRevalidate(Tcl_Interp *interp, Entry *entryPtr, VREASON reason)
    TCL_UNUSED(Tcl_Interp *),
    Entry *entryPtr,
    VREASON reason)
{
    int code = EntryValidateChange(
		    entryPtr, entryPtr->entry.string, -1,0, reason);

    if (code == TCL_BREAK) {
	TtkWidgetChangeState(&entryPtr->core, TTK_STATE_INVALID, 0);
    } else if (code == TCL_OK) {
	TtkWidgetChangeState(&entryPtr->core, 0, TTK_STATE_INVALID);
    }

    return code;
}

/* EntryRevalidateBG --
 * 	Revalidate in the background (called from event handler).
 */
static void EntryRevalidateBG(Entry *entryPtr, VREASON reason)
{
    Tcl_Interp *interp = entryPtr->core.interp;
    VMODE vmode = entryPtr->entry.validate;

    if (EntryNeedsValidation(vmode, reason)) {
        if (EntryRevalidate(interp, entryPtr, reason) == TCL_ERROR) {
	    Tcl_BackgroundException(interp, TCL_ERROR);
    if (EntryRevalidate(interp, entryPtr, reason) == TCL_ERROR) {
	Tcl_BackgroundException(interp, TCL_ERROR);
        }
    }
}

/*------------------------------------------------------------------------
 * +++ Entry widget modification.
 */

723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738
739
740
741
742
743

744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702
703
704
705
706
707

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

726
727
728
729
730
731
732
733







-
+












-
+

















-
+








    e->insertPos    = AdjustIndex(e->insertPos, index, nChars);
    e->selectFirst  = AdjustIndex(e->selectFirst, index, nChars);
    e->selectLast   = AdjustIndex(e->selectLast, index+g, nChars);
    e->xscroll.first= AdjustIndex(e->xscroll.first, index+g, nChars);

    if (e->selectLast <= e->selectFirst)
	e->selectFirst = e->selectLast = TCL_INDEX_NONE;
	e->selectFirst = e->selectLast = -1;
}

/* EntryStoreValue --
 *	Replace the contents of a text entry with a given value,
 *	recompute dependent resources, and schedule a redisplay.
 *
 *	See also: EntrySetValue().
 */
static void
EntryStoreValue(Entry *entryPtr, const char *value)
{
    size_t numBytes = strlen(value);
    Tcl_Size numChars = Tcl_NumUtfChars(value, numBytes);
    int numChars = Tcl_NumUtfChars(value, numBytes);

    if (entryPtr->core.flags & VALIDATING)
	entryPtr->core.flags |= VALIDATION_SET_VALUE;

    /* Make sure all indices remain in bounds:
     */
    if (numChars < entryPtr->entry.numChars)
	AdjustIndices(entryPtr, numChars, numChars - entryPtr->entry.numChars);

    /* Free old value:
     */
    if (entryPtr->entry.displayString != entryPtr->entry.string)
	ckfree(entryPtr->entry.displayString);
    ckfree(entryPtr->entry.string);

    /* Store new value:
     */
    entryPtr->entry.string = (char *)ckalloc(numBytes + 1);
    entryPtr->entry.string = ckalloc(numBytes + 1);
    strcpy(entryPtr->entry.string, value);
    entryPtr->entry.numBytes = numBytes;
    entryPtr->entry.numChars = numChars;

    entryPtr->entry.displayString
	= entryPtr->entry.showChar
	? EntryDisplayString(entryPtr->entry.showChar, numChars)
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
776
777
778
779
780
781
782

783
784
785
786
787
788
789
790







-
+







}

/* EntryTextVariableTrace --
 *	Variable trace procedure for entry -textvariable
 */
static void EntryTextVariableTrace(void *recordPtr, const char *value)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;

    if (WidgetDestroyed(&entryPtr->core)) {
	return;
    }

    if (entryPtr->core.flags & SYNCING_VARIABLE) {
	/* Trace was fired due to Tcl_SetVar2 call in EntrySetValue.
837
838
839
840
841
842
843
844

845
846
847
848
849
850
851
852

853
854
855
856
857
858
859
860
861
862




863
864
865

866
867
868
869

870
871
872
873
874

875
876
877
878
879
880
881
882
883
884
885


886
887
888
889

890
891
892
893
894
895

896
897
898
899
900
901
902
903
904
905
906
907
908



909
910
911

912
913
914
915

916
917
918
919

920
921
922
923
924
925
926
927
928
929
930
931
932
933
934

935
936

937
938
939
940
941
942
943
802
803
804
805
806
807
808

809
810
811
812
813
814
815
816

817
818
819
820
821
822
823




824
825
826
827
828
829

830
831
832
833

834
835
836
837
838

839
840
841
842
843
844
845
846
847
848


849
850
851
852
853

854
855
856
857
858
859

860
861
862
863
864
865
866
867
868
869
870



871
872
873
874
875

876
877
878
879

880
881
882
883

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898

899
900

901
902
903
904
905
906
907
908







-
+







-
+






-
-
-
-
+
+
+
+


-
+



-
+




-
+









-
-
+
+



-
+





-
+










-
-
-
+
+
+


-
+



-
+



-
+














-
+

-
+








/* InsertChars --
 *	Add new characters to an entry widget.
 */
static int
InsertChars(
    Entry *entryPtr,		/* Entry that is to get the new elements. */
    Tcl_Size index,			/* Insert before this index */
    int index,			/* Insert before this index */
    const char *value)		/* New characters to add */
{
    char *string = entryPtr->entry.string;
    size_t byteIndex = Tcl_UtfAtIndex(string, index) - string;
    size_t byteCount = strlen(value);
    int charsAdded = Tcl_NumUtfChars(value, byteCount);
    size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1;
    char *newBytes;
    char *new;
    int code;

    if (byteCount == 0) {
	return TCL_OK;
    }

    newBytes =  (char *)ckalloc(newByteCount);
    memcpy(newBytes, string, byteIndex);
    strcpy(newBytes + byteIndex, value);
    strcpy(newBytes + byteIndex + byteCount, string + byteIndex);
    new =  ckalloc(newByteCount);
    memcpy(new, string, byteIndex);
    strcpy(new + byteIndex, value);
    strcpy(new + byteIndex + byteCount, string + byteIndex);

    code = EntryValidateChange(
	    entryPtr, newBytes, index, charsAdded, VALIDATE_INSERT);
	    entryPtr, new, index, charsAdded, VALIDATE_INSERT);

    if (code == TCL_OK) {
	AdjustIndices(entryPtr, index, charsAdded);
	code = EntrySetValue(entryPtr, newBytes);
	code = EntrySetValue(entryPtr, new);
    } else if (code == TCL_BREAK) {
	code = TCL_OK;
    }

    ckfree(newBytes);
    ckfree(new);
    return code;
}

/* DeleteChars --
 *	Remove one or more characters from an entry widget.
 */
static int
DeleteChars(
    Entry *entryPtr,		/* Entry widget to modify. */
    Tcl_Size index,			/* Index of first character to delete. */
    Tcl_Size count)			/* How many characters to delete. */
    int index,			/* Index of first character to delete. */
    int count)			/* How many characters to delete. */
{
    char *string = entryPtr->entry.string;
    size_t byteIndex, byteCount, newByteCount;
    char *newBytes;
    char *new;
    int code;

    if (index < 0) {
	index = 0;
    }
    if (count + index  > entryPtr->entry.numChars) {
    if (count > entryPtr->entry.numChars - index) {
	count = entryPtr->entry.numChars - index;
    }
    if (count <= 0) {
	return TCL_OK;
    }

    byteIndex = Tcl_UtfAtIndex(string, index) - string;
    byteCount = Tcl_UtfAtIndex(string+byteIndex, count) - (string+byteIndex);

    newByteCount = entryPtr->entry.numBytes + 1 - byteCount;
    newBytes =  (char *)ckalloc(newByteCount);
    memcpy(newBytes, string, byteIndex);
    strcpy(newBytes + byteIndex, string + byteIndex + byteCount);
    new =  ckalloc(newByteCount);
    memcpy(new, string, byteIndex);
    strcpy(new + byteIndex, string + byteIndex + byteCount);

    code = EntryValidateChange(
	    entryPtr, newBytes, index, count, VALIDATE_DELETE);
	    entryPtr, new, index, count, VALIDATE_DELETE);

    if (code == TCL_OK) {
	AdjustIndices(entryPtr, index, -count);
	code = EntrySetValue(entryPtr, newBytes);
	code = EntrySetValue(entryPtr, new);
    } else if (code == TCL_BREAK) {
	code = TCL_OK;
    }
    ckfree(newBytes);
    ckfree(new);

    return code;
}

/*------------------------------------------------------------------------
 * +++ Event handler.
 */

/* EntryEventProc --
 *	Extra event handling for entry widgets:
 *	Triggers validation on FocusIn and FocusOut events.
 */
#define EntryEventMask (FocusChangeMask)
static void
EntryEventProc(void *clientData, XEvent *eventPtr)
EntryEventProc(ClientData clientData, XEvent *eventPtr)
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = (Entry *) clientData;

    Tcl_Preserve(clientData);
    switch (eventPtr->type) {
	case DestroyNotify:
	    Tk_DeleteEventHandler(entryPtr->core.tkwin,
		    EntryEventMask, EntryEventProc, clientData);
	    break;
952
953
954
955
956
957
958
959

960
961
962
963

964
965
966
967
968

969
970
971

972
973
974
975
976
977
978
979
980
981
982
983
984


985
986
987
988
989
990

991
992
993
994
995
996
997
917
918
919
920
921
922
923

924


925

926
927
928
929
930

931
932
933

934
935
936
937
938
939
940
941
942
943
944
945


946
947
948
949
950
951
952

953
954
955
956
957
958
959
960







-
+
-
-

-
+




-
+


-
+











-
-
+
+





-
+







}

/*------------------------------------------------------------------------
 * +++ Initialization and cleanup.
 */

static void
EntryInitialize(
EntryInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;

    Tk_CreateEventHandler(
	entryPtr->core.tkwin, EntryEventMask, EntryEventProc, entryPtr);
    Tk_CreateSelHandler(entryPtr->core.tkwin, XA_PRIMARY, XA_STRING,
	EntryFetchSelection, entryPtr, XA_STRING);
	EntryFetchSelection, (ClientData) entryPtr, XA_STRING);
    TtkBlinkCursor(&entryPtr->core);

    entryPtr->entry.string		= (char *)ckalloc(1);
    entryPtr->entry.string		= ckalloc(1);
    *entryPtr->entry.string 		= '\0';
    entryPtr->entry.displayString	= entryPtr->entry.string;
    entryPtr->entry.textVariableTrace 	= 0;
    entryPtr->entry.numBytes = entryPtr->entry.numChars = 0;

    EntryInitStyleDefaults(&entryPtr->entry.styleDefaults);

    entryPtr->entry.xscrollHandle =
	TtkCreateScrollHandle(&entryPtr->core, &entryPtr->entry.xscroll);

    entryPtr->entry.insertPos		= 0;
    entryPtr->entry.selectFirst 	= TCL_INDEX_NONE;
    entryPtr->entry.selectLast		= TCL_INDEX_NONE;
    entryPtr->entry.selectFirst 	= -1;
    entryPtr->entry.selectLast		= -1;
}

static void
EntryCleanup(void *recordPtr)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;

    if (entryPtr->entry.textVariableTrace)
	Ttk_UntraceVariable(entryPtr->entry.textVariableTrace);

    TtkFreeScrollHandle(entryPtr->entry.xscrollHandle);

    EntryFreeStyleDefaults(&entryPtr->entry.styleDefaults);
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017

1018
1019
1020
1021
1022
1023
1024
968
969
970
971
972
973
974

975
976
977
978
979

980
981
982
983
984
985
986
987







-
+




-
+







}

/* EntryConfigure --
 * 	Configure hook for Entry widgets.
 */
static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    Tcl_Obj *textVarName = entryPtr->entry.textVariableObj;
    Ttk_TraceHandle *vt = 0;

    if (mask & TEXTVAR_CHANGED) {
	if (textVarName && *Tcl_GetString(textVarName) != '\0') {
	if (textVarName && *Tcl_GetString(textVarName)) {
	    vt = Ttk_TraceVariable(interp,
		    textVarName,EntryTextVariableTrace,entryPtr);
	    if (!vt) return TCL_ERROR;
	}
    }

    if (TtkCoreConfigure(interp, recordPtr, mask) != TCL_OK) {
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1047
995
996
997
998
999
1000
1001

1002

1003
1004
1005
1006
1007
1008
1009







-
+
-







	if (entryPtr->entry.textVariableTrace)
	    Ttk_UntraceVariable(entryPtr->entry.textVariableTrace);
	entryPtr->entry.textVariableTrace = vt;
    }

    /* Claim the selection, in case we've suddenly started exporting it.
     */
    if (entryPtr->entry.exportSelection && (entryPtr->entry.selectFirst >= 0)
    if (entryPtr->entry.exportSelection && entryPtr->entry.selectFirst != -1) {
	    && (!Tcl_IsSafe(entryPtr->core.interp))) {
	EntryOwnSelection(entryPtr);
    }

    /* Handle -state compatibility option:
     */
    if (mask & STATE_CHANGED) {
	TtkCheckStateOption(&entryPtr->core, entryPtr->entry.stateObj);
1069
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1031
1032
1033
1034
1035
1036
1037

1038



1039

1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086







-
+
-
-
-

-
+


















-
+



















-
+







    EntryUpdateTextLayout(entryPtr);
    return TCL_OK;
}

/* EntryPostConfigure --
 * 	Post-configuration hook for entry widgets.
 */
static int EntryPostConfigure(
static int EntryPostConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr,
    int mask)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    int status = TCL_OK;

    if ((mask & TEXTVAR_CHANGED) && entryPtr->entry.textVariableTrace != NULL) {
	status = Ttk_FireTrace(entryPtr->entry.textVariableTrace);
    }

    return status;
}

/*------------------------------------------------------------------------
 * +++ Layout and display.
 */

/* EntryCharPosition --
 * 	Return the X coordinate of the specified character index.
 * 	Precondition: textLayout and layoutX up-to-date.
 */
static int
EntryCharPosition(Entry *entryPtr, Tcl_Size index)
EntryCharPosition(Entry *entryPtr, int index)
{
    int xPos;
    Tk_CharBbox(entryPtr->entry.textLayout, index, &xPos, NULL, NULL, NULL);
    return xPos + entryPtr->entry.layoutX;
}

/* EntryDoLayout --
 * 	Layout hook for entry widgets.
 *
 * 	Determine position of textLayout based on xscroll.first, justify,
 * 	and display area.
 *
 * 	Recalculates layoutX, layoutY, and rightIndex,
 * 	and updates xscroll accordingly.
 * 	May adjust xscroll.first to ensure the maximum #characters are onscreen.
 */
static void
EntryDoLayout(void *recordPtr)
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    WidgetCore *corePtr = &entryPtr->core;
    Tk_TextLayout textLayout = entryPtr->entry.textLayout;
    int leftIndex = entryPtr->entry.xscroll.first;
    int rightIndex;
    Ttk_Box textarea;

    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));
1189
1190
1191
1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207

1208
1209

1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232

1233
1234


1235
1236
1237
1238
1239
1240
1241
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189

1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200







-
+










-
+

-
+









-












-
+

-
+
+







    gcValues.line_width = 1; mask |= GCLineWidth;
    gcValues.font = Tk_FontId(font); mask |= GCFont;
    if (colorObj != 0 && (colorPtr=Tk_GetColorFromObj(tkwin,colorObj)) != 0) {
	gcValues.foreground = colorPtr->pixel;
	mask |= GCForeground;
    }
    gc = Tk_GetGC(entryPtr->core.tkwin, mask, &gcValues);
    if (clip != NULL) {
    if (clip != None) {
	TkSetRegion(Tk_Display(entryPtr->core.tkwin), gc, clip);
    }
    return gc;
}

/* EntryDisplay --
 *	Redraws the contents of an entry window.
 */
static void EntryDisplay(void *clientData, Drawable d)
{
    Entry *entryPtr = (Entry *)clientData;
    Entry *entryPtr = clientData;
    Tk_Window tkwin = entryPtr->core.tkwin;
    Tcl_Size leftIndex = entryPtr->entry.xscroll.first,
    int leftIndex = entryPtr->entry.xscroll.first,
	rightIndex = entryPtr->entry.xscroll.last + 1,
	selFirst = entryPtr->entry.selectFirst,
	selLast = entryPtr->entry.selectLast;
    EntryStyleData es;
    GC gc;
    int showSelection, showCursor;
    Ttk_Box textarea;
    TkRegion clipRegion;
    XRectangle rect;
    Tcl_Obj *foregroundObj;

    EntryInitStyleData(entryPtr, &es);

    textarea = Ttk_ClientRegion(entryPtr->core.layout, "textarea");
    showCursor =
	   (entryPtr->core.flags & CURSOR_ON)
	&& EntryEditable(entryPtr)
	&& entryPtr->entry.insertPos >= leftIndex
	&& entryPtr->entry.insertPos <= rightIndex
	;
    showSelection =
	   !(entryPtr->core.state & TTK_STATE_DISABLED)
	&& selFirst >= 0
	&& selFirst > -1
	&& selLast > leftIndex
	&& selFirst <= rightIndex;
	&& selFirst <= rightIndex
	;

    /* Adjust selection range to keep in display bounds.
     */
    if (showSelection) {
	if (selFirst < leftIndex)
	    selFirst = leftIndex;
	if (selLast > rightIndex)
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308


1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1336
1337




1338
1339
1340
1341
1342
1343
1344
1345
1346


1347
1348
1349



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1237
1238
1239
1240
1241
1242
1243

1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256








1257
1258

1259
1260
1261
1262
1263
1264
1265















1266









1267
1268
1269
1270









1271
1272
1273


1274
1275
1276
1277
1278
1279
1280
1281










1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297







-













-
-
-
-
-
-
-
-
+

-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+

-
-
+
+
+





-
-
-
-
-
-
-
-
-
-








-
+







#ifdef HAVE_XFT
    TkUnixSetXftClipRegion(clipRegion);
#endif

    /* Draw cursor:
     */
    if (showCursor) {
        Ttk_Box field = Ttk_ClientRegion(entryPtr->core.layout, "field");
	int cursorX = EntryCharPosition(entryPtr, entryPtr->entry.insertPos),
	    cursorY = entryPtr->entry.layoutY,
	    cursorHeight = entryPtr->entry.layoutHeight,
	    cursorWidth = 1;

	Tcl_GetIntFromObj(NULL,es.insertWidthObj,&cursorWidth);
	if (cursorWidth <= 0) {
	    cursorWidth = 1;
	}

	/* @@@ should: maybe: SetCaretPos even when blinked off */
	Tk_SetCaretPos(tkwin, cursorX, cursorY, cursorHeight);

	cursorX -= cursorWidth/2;
	if (cursorX < field.x) {
	    cursorX = field.x;
	} else if (cursorX + cursorWidth > field.x + field.width) {
	    cursorX = field.x + field.width - cursorWidth;
	}

	gc = EntryGetGC(entryPtr, es.insertColorObj, NULL);
	gc = EntryGetGC(entryPtr, es.insertColorObj, clipRegion);
	XFillRectangle(Tk_Display(tkwin), d, gc,
	    cursorX, cursorY, cursorWidth, cursorHeight);
	    cursorX-cursorWidth/2, cursorY, cursorWidth, cursorHeight);
	XSetClipMask(Tk_Display(tkwin), gc, None);
	Tk_FreeGC(Tk_Display(tkwin), gc);
    }

    /* Draw the text:
     */
    if ((*(entryPtr->entry.displayString) == '\0')
		&& (entryPtr->entry.placeholderObj != NULL)) {
	/* No text displayed, but -placeholder is given */
	if (Tcl_GetCharLength(es.placeholderForegroundObj) > 0) {
	    foregroundObj = es.placeholderForegroundObj;
	} else {
	    foregroundObj = es.foregroundObj;
	}
	/* Use placeholder text width */
	leftIndex = 0;
	(void)Tcl_GetStringFromObj(entryPtr->entry.placeholderObj, &rightIndex);
    } else {
	foregroundObj = es.foregroundObj;
    }
    gc = EntryGetGC(entryPtr, foregroundObj, clipRegion);
    gc = EntryGetGC(entryPtr, es.foregroundObj, clipRegion);
    if (showSelection) {

        /* Draw the selected and unselected portions separately.
	 */
	if (leftIndex < selFirst) {
	    Tk_DrawTextLayout(
		Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
		entryPtr->entry.layoutX, entryPtr->entry.layoutY,
		leftIndex, selFirst);
    Tk_DrawTextLayout(
	Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
	entryPtr->entry.layoutX, entryPtr->entry.layoutY,
	leftIndex, rightIndex);
	}
	if (selLast < rightIndex) {
	    Tk_DrawTextLayout(
		Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
		entryPtr->entry.layoutX, entryPtr->entry.layoutY,
		selLast, rightIndex);
	}
	XSetClipMask(Tk_Display(tkwin), gc, None);
	Tk_FreeGC(Tk_Display(tkwin), gc);
    XSetClipMask(Tk_Display(tkwin), gc, None);
    Tk_FreeGC(Tk_Display(tkwin), gc);

	/* Draw the selected portion in the -selectforeground color:
	 */
    /* Overwrite the selected portion (if any) in the -selectforeground color:
     */
    if (showSelection) {
	gc = EntryGetGC(entryPtr, es.selForegroundObj, clipRegion);
	Tk_DrawTextLayout(
	    Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
	    entryPtr->entry.layoutX, entryPtr->entry.layoutY,
	    selFirst, selLast);
	XSetClipMask(Tk_Display(tkwin), gc, None);
	Tk_FreeGC(Tk_Display(tkwin), gc);
    } else {

        /* Draw the entire visible text
         */
	Tk_DrawTextLayout(
	    Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
	    entryPtr->entry.layoutX, entryPtr->entry.layoutY,
	    leftIndex, rightIndex);
	XSetClipMask(Tk_Display(tkwin), gc, None);
	Tk_FreeGC(Tk_Display(tkwin), gc);
    }

    /* Drop the region. Note that we have to manually remove the reference to
     * it from the Xft guts (if they're being used).
     */
#ifdef HAVE_XFT
    TkUnixSetXftClipRegion(NULL);
    TkUnixSetXftClipRegion(None);
#endif
    TkDestroyRegion(clipRegion);
}

/*------------------------------------------------------------------------
 * +++ Widget commands.
 */
1391
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403


1404
1405
1406
1407
1408
1409
1410



1411
1412
1413
1414
1415
1416

1417
1418
1419
1420
1421
1422
1423
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317



1318
1319







1320
1321
1322






1323
1324
1325
1326
1327
1328
1329
1330







-
+


-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+







 *	error occurs then an error message is left in the interp's result.
 */
static int
EntryIndex(
    Tcl_Interp *interp,		/* For error messages. */
    Entry *entryPtr,		/* Entry widget to query */
    Tcl_Obj *indexObj,		/* Symbolic index name */
    Tcl_Size *indexPtr)		/* Return value */
    int *indexPtr)		/* Return value */
{
#   define EntryWidth(e) (Tk_Width(entryPtr->core.tkwin)) /* Not Right */
    Tcl_Size length, idx;
    const char *string;

    const char *string = Tcl_GetString(indexObj);
    size_t length = indexObj->length;
    if (TCL_OK == TkGetIntForIndex(indexObj, entryPtr->entry.numChars - 1, 1, &idx)) {
	if (idx < 0) {
	    idx = 0;
	} else if (idx > entryPtr->entry.numChars) {
	    idx = entryPtr->entry.numChars;
	}
	*indexPtr = idx;

    if (strncmp(string, "end", length) == 0) {
	*indexPtr = entryPtr->entry.numChars;
	return TCL_OK;
    }

    string = Tcl_GetStringFromObj(indexObj, &length);

    if (strncmp(string, "insert", length) == 0) {
    } else if (strncmp(string, "insert", length) == 0) {
	*indexPtr = entryPtr->entry.insertPos;
    } else if (strncmp(string, "left", length) == 0) {	/* for debugging */
	*indexPtr = entryPtr->entry.xscroll.first;
    } else if (strncmp(string, "right", length) == 0) {	/* for debugging */
	*indexPtr = entryPtr->entry.xscroll.last;
    } else if (strncmp(string, "sel.", 4) == 0) {
	if (entryPtr->entry.selectFirst < 0) {
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468







1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484

1485
1486

1487
1488

1489
1490
1491
1492
1493
1494
1495
1352
1353
1354
1355
1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398

1399
1400

1401
1402
1403
1404
1405
1406
1407
1408







-















+
-
+
+
+
+
+
+
+















-
+

-
+

-
+







	if (x > maxWidth) {
	    x = maxWidth;
	    roundUp = 1;
	}
	*indexPtr = Tk_PointToChar(entryPtr->entry.textLayout,
		x - entryPtr->entry.layoutX, 0);

        TtkUpdateScrollInfo(entryPtr->entry.xscrollHandle);
	if (*indexPtr < entryPtr->entry.xscroll.first) {
	    *indexPtr = entryPtr->entry.xscroll.first;
	}

	/*
	 * Special trick:  if the x-position was off-screen to the right,
	 * round the index up to refer to the character just after the
	 * last visible one on the screen.  This is needed to enable the
	 * last character to be selected, for example.
	 */

	if (roundUp && (*indexPtr < entryPtr->entry.numChars)) {
	    *indexPtr += 1;
	}
    } else {
	if (Tcl_GetInt(interp, string, indexPtr) != TCL_OK) {
	goto badIndex;
	    goto badIndex;
	}
	if (*indexPtr < 0) {
	    *indexPtr = 0;
	} else if (*indexPtr > entryPtr->entry.numChars) {
	    *indexPtr = entryPtr->entry.numChars;
	}
    }
    return TCL_OK;

badIndex:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "bad entry index \"%s\"", string));
    Tcl_SetErrorCode(interp, "TTK", "ENTRY", "INDEX", NULL);
    return TCL_ERROR;
}

/* $entry bbox $index --
 * 	Return the bounding box of the character at the specified index.
 */
static int
EntryBBoxCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    Ttk_Box b;
    Tcl_Size index;
    int index;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "index");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
1507
1508
1509
1510
1511
1512
1513
1514

1515
1516
1517


1518
1519
1520
1521
1522
1523
1524
1420
1421
1422
1423
1424
1425
1426

1427
1428


1429
1430
1431
1432
1433
1434
1435
1436
1437







-
+

-
-
+
+








/* $entry delete $from ?$to? --
 *	Delete the characters in the range [$from,$to).
 *	$to defaults to $from+1 if not specified.
 */
static int
EntryDeleteCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Tcl_Size first, last;
    Entry *entryPtr = recordPtr;
    int first, last;

    if ((objc < 3) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "firstIndex ?lastIndex?");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[2], &first) != TCL_OK) {
	return TCL_ERROR;
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559

1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582


1583
1584
1585
1586
1587
1588
1589
1590
1591

1592
1593
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604


1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623

1624
1625

1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637
1638
1639
1640

1641
1642

1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656

1657
1658
1659


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
1449
1450
1451
1452
1453
1454
1455

1456
1457

1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473

1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493


1494
1495
1496
1497
1498
1499
1500
1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1511
1512
1513

1514
1515


1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535

1536
1537

1538
1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554

1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568

1569
1570


1571
1572
1573
1574
1575
1576

1577
1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606

1607
1608

1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

1623
1624

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646

1647
1648

1649
1650
1651
1652

1653
1654
1655
1656
1657
1658
1659
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







-
+

-
+













-
+

-
+

















-
+

-
-
+
+








-
+









-
+

-
-
+
+


















-
+

-
+





-
+








-
+

-
+













-
+

-
-
+
+




-
+








-
+




















-
+

-
+













-
+

-
+



















-
+

-
+

-
+



-
+


















-









-
+







}

/* $entry get --
 * 	Return the current value of the entry widget.
 */
static int
EntryGetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, NULL);
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->entry.string, -1));
    return TCL_OK;
}

/* $entry icursor $index --
 * 	Set the insert cursor position.
 */
static int
EntryICursorCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "pos");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[2],
	    &entryPtr->entry.insertPos) != TCL_OK) {
	return TCL_ERROR;
    }
    TtkRedisplayWidget(&entryPtr->core);
    return TCL_OK;
}

/* $entry index $index --
 * 	Return numeric value (0..numChars) of the specified index.
 */
static int
EntryIndexCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Tcl_Size index;
    Entry *entryPtr = recordPtr;
    int index;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "string");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, TkNewIndexObj(index));
    Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
    return TCL_OK;
}

/* $entry insert $index $text --
 * 	Insert $text after position $index.
 * 	Silent no-op if the entry is disabled or read-only.
 */
static int
EntryInsertCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Tcl_Size index;
    Entry *entryPtr = recordPtr;
    int index;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "index text");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
    }
    if (EntryEditable(entryPtr)) {
	return InsertChars(entryPtr, index, Tcl_GetString(objv[3]));
    }
    return TCL_OK;
}

/* $entry selection clear --
 * 	Clear selection.
 */
static int EntrySelectionClearCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 3, objv, NULL);
	return TCL_ERROR;
    }
    entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE;
    entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1;
    TtkRedisplayWidget(&entryPtr->core);
    return TCL_OK;
}

/* $entry selection present --
 * 	Returns 1 if any characters are selected, 0 otherwise.
 */
static int EntrySelectionPresentCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 3, objv, NULL);
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp,
	    Tcl_NewBooleanObj(entryPtr->entry.selectFirst >= 0));
    return TCL_OK;
}

/* $entry selection range $start $end --
 * 	Explicitly set the selection range.
 */
static int EntrySelectionRangeCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Tcl_Size start, end;
    Entry *entryPtr = recordPtr;
    int start, end;
    if (objc != 5) {
	Tcl_WrongNumArgs(interp, 3, objv, "start end");
	return TCL_ERROR;
    }
    if (EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK
    if (    EntryIndex(interp, entryPtr, objv[3], &start) != TCL_OK
         || EntryIndex(interp, entryPtr, objv[4], &end) != TCL_OK) {
	return TCL_ERROR;
    }
    if (entryPtr->core.state & TTK_STATE_DISABLED) {
	return TCL_OK;
    }

    if (start >= end) {
	entryPtr->entry.selectFirst = entryPtr->entry.selectLast = TCL_INDEX_NONE;
	entryPtr->entry.selectFirst = entryPtr->entry.selectLast = -1;
    } else {
	entryPtr->entry.selectFirst = start;
	entryPtr->entry.selectLast = end;
	EntryOwnSelection(entryPtr);
    }
    TtkRedisplayWidget(&entryPtr->core);
    return TCL_OK;
}

static const Ttk_Ensemble EntrySelectionCommands[] = {
    { "clear",   EntrySelectionClearCommand,0 },
    { "present", EntrySelectionPresentCommand,0 },
    { "range",   EntrySelectionRangeCommand,0 },
    { 0,0,0 }
};

/* $entry set $value
 * 	Sets the value of an entry widget.
 */
static int EntrySetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "value");
	return TCL_ERROR;
    }
    EntrySetValue(entryPtr, Tcl_GetString(objv[2]));
    return TCL_OK;
}

/* $entry validate --
 * 	Trigger forced validation.  Returns 1/0 if validation succeeds/fails
 * 	or error status from -validatecommand / -invalidcommand.
 */
static int EntryValidateCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    int code;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, NULL);
	return TCL_ERROR;
    }

    code = EntryRevalidate(interp, entryPtr, VALIDATE_FORCED);

    if (code == TCL_ERROR)
	return code;

    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(code == TCL_OK));
    return TCL_OK;
}

/* $entry xview	-- horizontal scrolling interface
 */
static int EntryXViewCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Entry *entryPtr = (Entry *)recordPtr;
    Entry *entryPtr = recordPtr;
    if (objc == 3) {
	Tcl_Size newFirst;
	int newFirst;
	if (EntryIndex(interp, entryPtr, objv[2], &newFirst) != TCL_OK) {
	    return TCL_ERROR;
	}
	TtkScrollTo(entryPtr->entry.xscrollHandle, newFirst, 1);
	TtkScrollTo(entryPtr->entry.xscrollHandle, newFirst);
	return TCL_OK;
    }
    return TtkScrollviewCommand(interp, objc, objv, entryPtr->entry.xscrollHandle);
}

static const Ttk_Ensemble EntryCommands[] = {
    { "bbox", 		EntryBBoxCommand,0 },
    { "cget", 		TtkWidgetCgetCommand,0 },
    { "configure", 	TtkWidgetConfigureCommand,0 },
    { "delete", 	EntryDeleteCommand,0 },
    { "get", 		EntryGetCommand,0 },
    { "icursor", 	EntryICursorCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "index", 		EntryIndexCommand,0 },
    { "insert", 	EntryInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "selection", 	0,EntrySelectionCommands },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "validate", 	EntryValidateCommand,0 },
    { "xview", 		EntryXViewCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Entry widget definition.
 */

static const WidgetSpec EntryWidgetSpec = {
static WidgetSpec EntryWidgetSpec = {
    "TEntry",			/* className */
    sizeof(Entry), 		/* recordSize */
    EntryOptionSpecs, 		/* optionSpecs */
    EntryCommands,  		/* subcommands */
    EntryInitialize,     	/* initializeProc */
    EntryCleanup,		/* cleanupProc */
    EntryConfigure,		/* configureProc */
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
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







-
+








-
+

-
+


-
+


-
+










-
+

-
+










-
-
+
+
















-
+

-
-
+
+

-
+


-
+




-
+













-
+



-
+


-
-
+
-
-
-
-
-
-
-
-
+
+
+
-

-
-
+
+





-
+







 * +++ Combobox widget record.
 */

typedef struct {
    Tcl_Obj	*postCommandObj;
    Tcl_Obj	*valuesObj;
    Tcl_Obj	*heightObj;
    Tcl_Size	currentIndex;
    int 	currentIndex;
} ComboboxPart;

typedef struct {
    WidgetCore core;
    EntryPart entry;
    ComboboxPart combobox;
} Combobox;

static const Tk_OptionSpec ComboboxOptionSpecs[] = {
static Tk_OptionSpec ComboboxOptionSpecs[] = {
    {TK_OPTION_STRING, "-height", "height", "Height",
        DEF_LIST_HEIGHT, offsetof(Combobox, combobox.heightObj), TCL_INDEX_NONE,
        DEF_LIST_HEIGHT, Tk_Offset(Combobox, combobox.heightObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-postcommand", "postCommand", "PostCommand",
        "", offsetof(Combobox, combobox.postCommandObj), TCL_INDEX_NONE,
        "", Tk_Offset(Combobox, combobox.postCommandObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-values", "values", "Values",
        "", offsetof(Combobox, combobox.valuesObj), TCL_INDEX_NONE,
        "", Tk_Offset(Combobox, combobox.valuesObj), -1,
	0,0,0 },
    WIDGET_INHERIT_OPTIONS(EntryOptionSpecs)
};

/* ComboboxInitialize --
 * 	Initialization hook for combobox widgets.
 */
static void
ComboboxInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Combobox *cb = (Combobox *)recordPtr;
    Combobox *cb = recordPtr;

    cb->combobox.currentIndex = TCL_INDEX_NONE;
    cb->combobox.currentIndex = -1;
    TtkTrackElementState(&cb->core);
    EntryInitialize(interp, recordPtr);
}

/* ComboboxConfigure --
 * 	Configuration hook for combobox widgets.
 */
static int
ComboboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Combobox *cbPtr = (Combobox *)recordPtr;
    Tcl_Size unused;
    Combobox *cbPtr = recordPtr;
    int unused;

    /* Make sure -values is a valid list:
     */
    if (Tcl_ListObjLength(interp,cbPtr->combobox.valuesObj,&unused) != TCL_OK)
	return TCL_ERROR;

    return EntryConfigure(interp, recordPtr, mask);
}

/* $cb current ?newIndex? -- get or set current index.
 * 	Setting the current index updates the combobox value,
 * 	but the value and -values may be changed independently
 * 	of the index.  Instead of trying to keep currentIndex
 * 	in sync at all times, [$cb current] double-checks
 */
static int ComboboxCurrentCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Combobox *cbPtr = (Combobox *)recordPtr;
    Tcl_Size currentIndex = cbPtr->combobox.currentIndex;
    Combobox *cbPtr = recordPtr;
    int currentIndex = cbPtr->combobox.currentIndex;
    const char *currentValue = cbPtr->entry.string;
    Tcl_Size nValues;
    int nValues;
    Tcl_Obj **values;

    Tcl_ListObjGetElements(interp, cbPtr->combobox.valuesObj, &nValues, &values);
    Tcl_ListObjGetElements(interp,cbPtr->combobox.valuesObj,&nValues,&values);

    if (objc == 2) {
	/* Check if currentIndex still valid:
	 */
	if (currentIndex < 0
	if (    currentIndex < 0
	     || currentIndex >= nValues
	     || strcmp(currentValue,Tcl_GetString(values[currentIndex]))
	   )
	{
	    /* Not valid.  Check current value against each element in -values:
	     */
	    for (currentIndex = 0; currentIndex < nValues; ++currentIndex) {
		if (!strcmp(currentValue,Tcl_GetString(values[currentIndex]))) {
		    break;
		}
	    }
	    if (currentIndex >= nValues) {
		/* Not found */
		currentIndex = TCL_INDEX_NONE;
		currentIndex = -1;
	    }
	}
	cbPtr->combobox.currentIndex = currentIndex;
	Tcl_SetObjResult(interp, TkNewIndexObj(currentIndex));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(currentIndex));
	return TCL_OK;
    } else if (objc == 3) {
	Tcl_Size idx;

	if (Tcl_GetIntFromObj(interp, objv[2], &currentIndex) != TCL_OK) {
	if (TCL_OK == TkGetIntForIndex(objv[2], nValues - 1, 0, &idx)) {
	    if (idx < 0 || idx >= nValues) {
	        Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		        "index \"%s\" out of range", Tcl_GetString(objv[2])));
	        Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL);
	        return TCL_ERROR;
	    }
	    currentIndex = idx;
	    return TCL_ERROR;
	}
	if (currentIndex < 0 || currentIndex >= nValues) {
	} else {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad index \"%s\"", Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_VALUE", NULL);
		    "Index %s out of range", Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL);
	    return TCL_ERROR;
	}

	cbPtr->combobox.currentIndex = currentIndex;

	return EntrySetValue((Entry *)recordPtr, Tcl_GetString(values[currentIndex]));
	return EntrySetValue(recordPtr, Tcl_GetString(values[currentIndex]));
    } else {
	Tcl_WrongNumArgs(interp, 2, objv, "?newIndex?");
	return TCL_ERROR;
    }
    return TCL_OK;
}

1921
1922
1923
1924
1925
1926
1927
1928
1929
1930

1931
1932
1933
1934
1935
1936

1937
1938
1939
1940
1941
1942
1943
1826
1827
1828
1829
1830
1831
1832

1833

1834
1835
1836
1837
1838
1839

1840
1841
1842
1843
1844
1845
1846
1847







-

-
+





-
+







    { "get", 		EntryGetCommand,0 },
    { "icursor", 	EntryICursorCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "index", 		EntryIndexCommand,0 },
    { "insert", 	EntryInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "selection", 	0,EntrySelectionCommands },
    { "set", 		EntrySetCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "set", 		EntrySetCommand,0 },
    { "validate",	EntryValidateCommand,0 },
    { "xview", 		EntryXViewCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec ComboboxWidgetSpec = {
static WidgetSpec ComboboxWidgetSpec = {
    "TCombobox",		/* className */
    sizeof(Combobox), 		/* recordSize */
    ComboboxOptionSpecs,	/* optionSpecs */
    ComboboxCommands,  		/* subcommands */
    ComboboxInitialize,     	/* initializeProc */
    EntryCleanup,		/* cleanupProc */
    ComboboxConfigure,		/* configureProc */
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
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







-
+

-
+



-
+


-
+


-
+


-
+



-
+


-
+











-
+










-
-
+
+








typedef struct {
    WidgetCore core;
    EntryPart entry;
    SpinboxPart spinbox;
} Spinbox;

static const Tk_OptionSpec SpinboxOptionSpecs[] = {
static Tk_OptionSpec SpinboxOptionSpecs[] = {
    {TK_OPTION_STRING, "-values", "values", "Values",
        "", offsetof(Spinbox, spinbox.valuesObj), TCL_INDEX_NONE,
        "", Tk_Offset(Spinbox, spinbox.valuesObj), -1,
	0,0,0 },

    {TK_OPTION_DOUBLE, "-from", "from", "From",
	"0.0", offsetof(Spinbox,spinbox.fromObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Spinbox,spinbox.fromObj), -1,
	0,0,0 },
    {TK_OPTION_DOUBLE, "-to", "to", "To",
	"0.0", offsetof(Spinbox,spinbox.toObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Spinbox,spinbox.toObj), -1,
	0,0,0 },
    {TK_OPTION_DOUBLE, "-increment", "increment", "Increment",
	"1.0", offsetof(Spinbox,spinbox.incrementObj), TCL_INDEX_NONE,
	"1", Tk_Offset(Spinbox,spinbox.incrementObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-format", "format", "Format",
	"", offsetof(Spinbox, spinbox.formatObj), TCL_INDEX_NONE,
	"", Tk_Offset(Spinbox, spinbox.formatObj), -1,
	0,0,0 },

    {TK_OPTION_STRING, "-command", "command", "Command",
	"", offsetof(Spinbox, spinbox.commandObj), TCL_INDEX_NONE,
	"", Tk_Offset(Spinbox, spinbox.commandObj), -1,
	0,0,0 },
    {TK_OPTION_BOOLEAN, "-wrap", "wrap", "Wrap",
	"0", offsetof(Spinbox,spinbox.wrapObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Spinbox,spinbox.wrapObj), -1,
	0,0,0 },

    WIDGET_INHERIT_OPTIONS(EntryOptionSpecs)
};

/* SpinboxInitialize --
 * 	Initialization hook for spinbox widgets.
 */
static void
SpinboxInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Spinbox *sb = (Spinbox *)recordPtr;
    Spinbox *sb = recordPtr;
    TtkTrackElementState(&sb->core);
    EntryInitialize(interp, recordPtr);
}

/* SpinboxConfigure --
 * 	Configuration hook for spinbox widgets.
 */
static int
SpinboxConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Spinbox *sb = (Spinbox *)recordPtr;
    Tcl_Size unused;
    Spinbox *sb = recordPtr;
    int unused;

    /* Make sure -values is a valid list:
     */
    if (Tcl_ListObjLength(interp,sb->spinbox.valuesObj,&unused) != TCL_OK)
	return TCL_ERROR;

    return EntryConfigure(interp, recordPtr, mask);
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043

2044
2045
2046
2047
2048
2049

2050
2051
2052
2053
2054
2055
2056
1938
1939
1940
1941
1942
1943
1944

1945

1946
1947
1948
1949
1950
1951

1952
1953
1954
1955
1956
1957
1958
1959







-

-
+





-
+







    { "get", 		EntryGetCommand,0 },
    { "icursor", 	EntryICursorCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "index", 		EntryIndexCommand,0 },
    { "insert", 	EntryInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "selection", 	0,EntrySelectionCommands },
    { "set", 		EntrySetCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "set", 		EntrySetCommand,0 },
    { "validate",	EntryValidateCommand,0 },
    { "xview", 		EntryXViewCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec SpinboxWidgetSpec = {
static WidgetSpec SpinboxWidgetSpec = {
    "TSpinbox",			/* className */
    sizeof(Spinbox), 		/* recordSize */
    SpinboxOptionSpecs,		/* optionSpecs */
    SpinboxCommands,  		/* subcommands */
    SpinboxInitialize,     	/* initializeProc */
    EntryCleanup,		/* cleanupProc */
    SpinboxConfigure,		/* configureProc */
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
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







-
+

-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+














-
+




















-
+




-
-
-
-
-
-
+
+
+
+
+
+





-
-
-







 */

typedef struct {
    Tcl_Obj	*fontObj;
    Tcl_Obj	*widthObj;
} TextareaElement;

static const Ttk_ElementOptionSpec TextareaElementOptions[] = {
static Ttk_ElementOptionSpec TextareaElementOptions[] = {
    { "-font", TK_OPTION_FONT,
	offsetof(TextareaElement,fontObj), DEF_ENTRY_FONT },
	Tk_Offset(TextareaElement,fontObj), DEF_ENTRY_FONT },
    { "-width", TK_OPTION_INT,
	offsetof(TextareaElement,widthObj), "20" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(TextareaElement,widthObj), "20" },
    { NULL, 0, 0, NULL }
};

static void TextareaElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    TextareaElement *textarea = (TextareaElement *)elementRecord;
    TextareaElement *textarea = elementRecord;
    Tk_Font font = Tk_GetFontFromObj(tkwin, textarea->fontObj);
    int avgWidth = Tk_TextWidth(font, "0", 1);
    Tk_FontMetrics fm;
    int prefWidth = 1;

    Tk_GetFontMetrics(font, &fm);
    Tcl_GetIntFromObj(NULL, textarea->widthObj, &prefWidth);
    if (prefWidth <= 0)
	prefWidth = 1;

    *heightPtr = fm.linespace;
    *widthPtr = prefWidth * avgWidth;
}

static const Ttk_ElementSpec TextareaElementSpec = {
static Ttk_ElementSpec TextareaElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextareaElement),
    TextareaElementOptions,
    TextareaElementSize,
    TtkNullElementDraw
};

/*------------------------------------------------------------------------
 * +++ Widget layouts.
 */

TTK_BEGIN_LAYOUT(EntryLayout)
    TTK_GROUP("Entry.field", TTK_FILL_BOTH|TTK_BORDER,
	TTK_GROUP("Entry.padding", TTK_FILL_BOTH,
	    TTK_NODE("Entry.textarea", TTK_FILL_BOTH)))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(ComboboxLayout)
    TTK_GROUP("Combobox.field", TTK_FILL_BOTH,
	TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y)
	TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
	TTK_GROUP("Combobox.padding", TTK_FILL_BOTH|TTK_PACK_LEFT|TTK_EXPAND,
	    TTK_NODE("Combobox.textarea", TTK_FILL_BOTH)))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(SpinboxLayout)
    TTK_GROUP("Spinbox.field", TTK_PACK_TOP|TTK_FILL_X,
	TTK_GROUP("null", TTK_PACK_RIGHT,
	    TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP|TTK_STICK_E)
	    TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM|TTK_STICK_E))
	TTK_GROUP("Spinbox.padding", TTK_FILL_BOTH,
	    TTK_NODE("Spinbox.textarea", TTK_FILL_BOTH)))
     TTK_GROUP("Spinbox.field", TTK_PACK_TOP|TTK_FILL_X,
	 TTK_GROUP("null", TTK_PACK_RIGHT,
	     TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP|TTK_STICK_E)
	     TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM|TTK_STICK_E))
	 TTK_GROUP("Spinbox.padding", TTK_FILL_BOTH,
	     TTK_NODE("Spinbox.textarea", TTK_FILL_BOTH)))
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * +++ Initialization.
 */
MODULE_SCOPE
void TtkEntry_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkEntry_Init(Tcl_Interp *interp)
{
    Ttk_Theme themePtr =  Ttk_GetDefaultTheme(interp);

    Ttk_RegisterElement(interp, themePtr, "textarea", &TextareaElementSpec, 0);

Changes to generic/ttk/ttkFrame.c.

1
2

3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46
47
48
49
50
51
52
53

54
55
56

57
58
59
60
61
62
63
1

2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46
47
48
49
50
51

52

53
54
55

56
57
58
59
60
61
62
63

-
+




-
-
+
+
+




















-
+

-
+


-
+


-
+


-
+


-
+







-

-
+


-
+







/*
 * Copyright © 2004 Joe English
 * Copyright (c) 2004, Joe English
 *
 * ttk::frame and ttk::labelframe widgets.
 */

#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"
#include "ttkManager.h"

/* ======================================================================
 * +++ Frame widget:
 */

typedef struct {
    Tcl_Obj	*borderWidthObj;
    Tcl_Obj	*paddingObj;
    Tcl_Obj	*reliefObj;
    Tcl_Obj 	*widthObj;
    Tcl_Obj 	*heightObj;
} FramePart;

typedef struct {
    WidgetCore	core;
    FramePart	frame;
} Frame;

static const Tk_OptionSpec FrameOptionSpecs[] = {
static Tk_OptionSpec FrameOptionSpecs[] = {
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", NULL,
	offsetof(Frame,frame.borderWidthObj), TCL_INDEX_NONE,
	Tk_Offset(Frame,frame.borderWidthObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-padding", "padding", "Pad", NULL,
	offsetof(Frame,frame.paddingObj), TCL_INDEX_NONE,
	Tk_Offset(Frame,frame.paddingObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_RELIEF, "-relief", "relief", "Relief", NULL,
	offsetof(Frame,frame.reliefObj), TCL_INDEX_NONE,
	Tk_Offset(Frame,frame.reliefObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_PIXELS, "-width", "width", "Width", "0",
	offsetof(Frame,frame.widthObj), TCL_INDEX_NONE,
	Tk_Offset(Frame,frame.widthObj), -1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_PIXELS, "-height", "height", "Height", "0",
	offsetof(Frame,frame.heightObj), TCL_INDEX_NONE,
	Tk_Offset(Frame,frame.heightObj), -1,
	0,0,GEOMETRY_CHANGED },

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

static const Ttk_Ensemble FrameCommands[] = {
    { "cget",   	TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "cget",   	TtkWidgetCgetCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { 0,0,0 }
};

/*
 * FrameMargins --
 * 	Compute internal margins for a frame widget.
 * 	This includes the -borderWidth, plus any additional -padding.
85
86
87
88
89
90
91
92

93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
85
86
87
88
89
90
91

92



93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122







-
+
-
-
-

-
+




















-
+







    return margins;
}

/* FrameSize procedure --
 * 	The frame doesn't request a size of its own by default,
 * 	but it does have an internal border.  See also <<NOTE-SIZE>>
 */
static int FrameSize(
static int FrameSize(void *recordPtr, int *widthPtr, int *heightPtr)
    void *recordPtr,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *)) /* heightPtr */
{
    Frame *framePtr = (Frame *)recordPtr;
    Frame *framePtr = recordPtr;
    Ttk_SetMargins(framePtr->core.tkwin, FrameMargins(framePtr));
    return 0;
}

/*
 * FrameConfigure -- configure hook.
 *	<<NOTE-SIZE>> Usually the size of a frame is controlled by
 *	a geometry manager (pack, grid); the -width and -height
 *	options are only effective if geometry propagation is turned
 *	off or if the [place] GM is used for child widgets.
 *
 *	To avoid geometry blinking, we issue a geometry request
 *	in the Configure hook instead of the Size hook, and only
 *	if -width and/or -height is nonzero and one of them
 *	or the other size-related options (-borderwidth, -padding)
 *	has been changed.
 */

static int FrameConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Frame *framePtr = (Frame *)recordPtr;
    Frame *framePtr = recordPtr;
    int width, height;

    /*
     * Make sure -padding resource, if present, is correct:
     */
    if (framePtr->frame.paddingObj) {
	Ttk_Padding unused;
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156







-
+







    if ((width > 0 || height > 0) && (mask & GEOMETRY_CHANGED)) {
	Tk_GeometryRequest(framePtr->core.tkwin, width, height);
    }

    return TtkCoreConfigure(interp, recordPtr, mask);
}

static const WidgetSpec FrameWidgetSpec = {
static WidgetSpec FrameWidgetSpec = {
    "TFrame",			/* className */
    sizeof(Frame),		/* recordSize */
    FrameOptionSpecs,		/* optionSpecs */
    FrameCommands,		/* subcommands */
    TtkNullInitialize,		/* initializeProc */
    TtkNullCleanup,		/* cleanupProc */
    FrameConfigure,		/* configureProc */
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256

257
258
259

260
261
262



263
264

265
266
267
268
269
270
271
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

251
252

253
254
255

256
257


258
259
260
261

262
263
264
265
266
267
268
269







-
+















-
+

-
+


-
+

-
-
+
+
+

-
+








/*
 * Labelframe widget record:
 */
typedef struct {
    Tcl_Obj 	*labelAnchorObj;
    Tcl_Obj	*textObj;
    Tcl_Obj	*underlineObj;
    Tcl_Obj 	*underlineObj;
    Tk_Window	labelWidget;

    Ttk_Manager	*mgr;
    Ttk_Layout	labelLayout;	/* Sublayout for label */
    Ttk_Box	labelParcel;	/* Set in layoutProc */
} LabelframePart;

typedef struct {
    WidgetCore  	core;
    FramePart   	frame;
    LabelframePart	label;
} Labelframe;

#define LABELWIDGET_CHANGED 0x100

static const Tk_OptionSpec LabelframeOptionSpecs[] = {
static Tk_OptionSpec LabelframeOptionSpecs[] = {
    {TK_OPTION_STRING, "-labelanchor", "labelAnchor", "LabelAnchor",
	"nw", offsetof(Labelframe, label.labelAnchorObj),TCL_INDEX_NONE,
	"nw", Tk_Offset(Labelframe, label.labelAnchorObj),-1,
        0,0,GEOMETRY_CHANGED},
    {TK_OPTION_STRING, "-text", "text", "Text", "",
	offsetof(Labelframe,label.textObj), TCL_INDEX_NONE,
	Tk_Offset(Labelframe,label.textObj), -1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TTK_OPTION_UNDERLINE_DEF(Labelframe, label.underlineObj), 0},
    {TK_OPTION_INT, "-underline", "underline", "Underline",
	"-1", Tk_Offset(Labelframe,label.underlineObj), -1,
	0,0,0 },
    {TK_OPTION_WINDOW, "-labelwidget", "labelWidget", "LabelWidget", NULL,
	TCL_INDEX_NONE, offsetof(Labelframe,label.labelWidget),
	-1, Tk_Offset(Labelframe,label.labelWidget),
	TK_OPTION_NULL_OK,0,LABELWIDGET_CHANGED|GEOMETRY_CHANGED },

    WIDGET_INHERIT_OPTIONS(FrameOptionSpecs)
};

/*
 * Labelframe style parameters:
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306







-
-
+







    if ((objPtr = Ttk_QueryOption(layout, "-padding", 0)) != NULL) {
	Ttk_GetPaddingFromObj(NULL, lf->core.tkwin, objPtr, &style->padding);
    }
    if ((objPtr = Ttk_QueryOption(layout,"-labelanchor", 0)) != NULL) {
	TtkGetLabelAnchorFromObj(NULL, objPtr, &style->labelAnchor);
    }
    if ((objPtr = Ttk_QueryOption(layout,"-labelmargins", 0)) != NULL) {
	Ttk_GetPaddingFromObj(NULL, lf->core.tkwin, objPtr,
	    &style->labelMargins);
	Ttk_GetBorderFromObj(NULL, objPtr, &style->labelMargins);
    } else {
	if (style->labelAnchor & (TTK_PACK_TOP|TTK_PACK_BOTTOM)) {
	    style->labelMargins =
		Ttk_MakePadding(DEFAULT_LABELINSET,0,DEFAULT_LABELINSET,0);
	} else {
	    style->labelMargins =
		Ttk_MakePadding(0,DEFAULT_LABELINSET,0,DEFAULT_LABELINSET);
337
338
339
340
341
342
343
344

345
346
347
348
349

350
351
352
353
354
355
356
334
335
336
337
338
339
340

341



342

343
344
345
346
347
348
349
350







-
+
-
-
-

-
+







}

/*
 * LabelframeSize --
 * 	Like the frame, this doesn't request a size of its own
 * 	but it does have internal padding and a minimum size.
 */
static int LabelframeSize(
static int LabelframeSize(void *recordPtr, int *widthPtr, int *heightPtr)
    void *recordPtr,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *)) /* heightPtr */
{
    Labelframe *lframePtr = (Labelframe *)recordPtr;
    Labelframe *lframePtr = recordPtr;
    WidgetCore *corePtr = &lframePtr->core;
    Ttk_Padding margins;
    LabelframeStyle style;
    int labelWidth, labelHeight;

    LabelframeStyleOptions(lframePtr, &style);

387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395







-
+







 * LabelframeGetLayout --
 * 	Getlayout widget hook.
 */

static Ttk_Layout LabelframeGetLayout(
    Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Labelframe *lf = (Labelframe *)recordPtr;
    Labelframe *lf = recordPtr;
    Ttk_Layout frameLayout = TtkWidgetGetLayout(interp, theme, recordPtr);
    Ttk_Layout labelLayout;

    if (!frameLayout) {
	return NULL;
    }

418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
412
413
414
415
416
417
418

419
420
421
422
423
424
425
426







-
+







 * 	Labelframe layout hook.
 *
 * Side effects: Computes labelParcel.
 */

static void LabelframeDoLayout(void *recordPtr)
{
    Labelframe *lframePtr = (Labelframe *)recordPtr;
    Labelframe *lframePtr = recordPtr;
    WidgetCore *corePtr = &lframePtr->core;
    int lw, lh;			/* Label width and height */
    LabelframeStyle style;
    Ttk_Box borderParcel = Ttk_WinBox(lframePtr->core.tkwin);
    Ttk_Box labelParcel;

    /*
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481

482
483
484

485
486

487
488

489
490
491
492
493


494
495
496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511

512
513

514
515
516
517

518
519
520
521
522
523


524
525

526
527
528
529
530
531
532
533

534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
436
437
438
439
440
441
442

443
444

445
446
447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472

473
474
475

476
477

478
479

480
481
482
483


484
485
486
487
488

489




490
491
492
493
494
495
496
497
498

499
500

501


502

503

504
505
506


507
508
509

510
511
512
513
514
515
516
517

518


519

520
521
522
523
524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541







-


-












-
+





-
+









-
+


-
+

-
+

-
+



-
-
+
+



-
+
-
-
-
-









-
+

-
+
-
-

-
+
-



-
-
+
+

-
+







-
+
-
-

-
+













-
+







	style.labelMargins);

    if (!style.labelOutside) {
	/* Move border edge so it's over label:
	*/
	switch (LabelAnchorSide(style.labelAnchor)) {
	    case TTK_SIDE_LEFT: 	borderParcel.x -= lw / 2;
	    /* FALLTHRU */
	    case TTK_SIDE_RIGHT:	borderParcel.width += lw/2; 	break;
	    case TTK_SIDE_TOP:  	borderParcel.y -= lh / 2;
	    /* FALLTHRU */
	    case TTK_SIDE_BOTTOM:	borderParcel.height += lh / 2;	break;
	}
    }

    /*
     * Place border and label:
     */
    Ttk_PlaceLayout(corePtr->layout, corePtr->state, borderParcel);
    if (lframePtr->label.labelLayout) {
	Ttk_PlaceLayout(
	    lframePtr->label.labelLayout, corePtr->state, labelParcel);
    }
    /* labelWidget placed in LabelframePlaceContent GM hook */
    /* labelWidget placed in LabelframePlaceSlaves GM hook */
    lframePtr->label.labelParcel = labelParcel;
}

static void LabelframeDisplay(void *recordPtr, Drawable d)
{
    Labelframe *lframePtr = (Labelframe *)recordPtr;
    Labelframe *lframePtr = recordPtr;
    Ttk_DrawLayout(lframePtr->core.layout, lframePtr->core.state, d);
    if (lframePtr->label.labelLayout) {
	Ttk_DrawLayout(lframePtr->label.labelLayout, lframePtr->core.state, d);
    }
}

/* +++ Labelframe geometry manager hooks.
 */

/* LabelframePlaceContent --
/* LabelframePlaceSlaves --
 * 	Sets the position and size of the labelwidget.
 */
static void LabelframePlaceContent(void *recordPtr)
static void LabelframePlaceSlaves(void *recordPtr)
{
    Labelframe *lframe = (Labelframe *)recordPtr;
    Labelframe *lframe = recordPtr;

    if (Ttk_NumberContent(lframe->label.mgr) == 1) {
    if (Ttk_NumberSlaves(lframe->label.mgr) == 1) {
	Ttk_Box b;
	LabelframeDoLayout(recordPtr);
	b = lframe->label.labelParcel;
	/* ASSERT: content #0 is lframe->label.labelWidget */
	Ttk_PlaceContent(lframe->label.mgr, 0, b.x,b.y,b.width,b.height);
	/* ASSERT: slave #0 is lframe->label.labelWidget */
	Ttk_PlaceSlave(lframe->label.mgr, 0, b.x,b.y,b.width,b.height);
    }
}

static int LabelRequest(
static int LabelRequest(void *managerData, int index, int width, int height)
    TCL_UNUSED(void *), /* managerData */
    TCL_UNUSED(Tcl_Size), /* index */
    TCL_UNUSED(int), /* width */
    TCL_UNUSED(int)) /* height */
{
    return 1;
}

/* LabelRemoved --
 * 	Unset the -labelwidget option.
 *
 * <<NOTE-LABELREMOVED>>:
 * 	This routine is also called when the widget voluntarily forgets
 * 	the window in LabelframeConfigure.
 * 	the slave in LabelframeConfigure.
 */
static void LabelRemoved(
static void LabelRemoved(void *managerData, int slaveIndex)
    void *managerData,
    TCL_UNUSED(Tcl_Size)) /* index */
{
    Labelframe *lframe = (Labelframe *)managerData;
    Labelframe *lframe = managerData;

    lframe->label.labelWidget = 0;
}

static const Ttk_ManagerSpec LabelframeManagerSpec = {
    { "labelframe", Ttk_GeometryRequestProc, Ttk_LostContentProc },
static Ttk_ManagerSpec LabelframeManagerSpec = {
    { "labelframe", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
    LabelframeSize,
    LabelframePlaceContent,
    LabelframePlaceSlaves,
    LabelRequest,
    LabelRemoved
};

/* LabelframeInitialize --
 * 	Initialization hook.
 */
static void LabelframeInitialize(
static void LabelframeInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Labelframe *lframe = (Labelframe *)recordPtr;
    Labelframe *lframe = recordPtr;

    lframe->label.mgr = Ttk_CreateManager(
	&LabelframeManagerSpec, lframe, lframe->core.tkwin);
    lframe->label.labelWidget = 0;
    lframe->label.labelLayout = 0;
    lframe->label.labelParcel = Ttk_MakeBox(-1,-1,-1,-1);
}

/* LabelframeCleanup --
 * 	Cleanup hook.
 */
static void LabelframeCleanup(void *recordPtr)
{
    Labelframe *lframe = (Labelframe *)recordPtr;
    Labelframe *lframe = recordPtr;
    Ttk_DeleteManager(lframe->label.mgr);
    if (lframe->label.labelLayout) {
	Ttk_FreeLayout(lframe->label.labelLayout);
    }
}

/* RaiseLabelWidget --
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572







-
+







}

/* LabelframeConfigure --
 * 	Configuration hook.
 */
static int LabelframeConfigure(Tcl_Interp *interp,void *recordPtr,int mask)
{
    Labelframe *lframePtr = (Labelframe *)recordPtr;
    Labelframe *lframePtr = recordPtr;
    Tk_Window labelWidget = lframePtr->label.labelWidget;
    Ttk_PositionSpec unused;

    /* Validate options:
     */
    if (mask & LABELWIDGET_CHANGED && labelWidget != NULL) {
	if (!Ttk_Maintainable(interp, labelWidget, lframePtr->core.tkwin)) {
602
603
604
605
606
607
608
609
610


611
612
613
614
615
616
617

618
619
620
621
622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
585
586
587
588
589
590
591


592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620







-
-
+
+






-
+












-
+







    if (FrameConfigure(interp, recordPtr, mask) != TCL_OK) {
	return TCL_ERROR;
    }

    /* Update -labelwidget changes, if any:
     */
    if (mask & LABELWIDGET_CHANGED) {
	if (Ttk_NumberContent(lframePtr->label.mgr) == 1) {
	    Ttk_ForgetContent(lframePtr->label.mgr, 0);
	if (Ttk_NumberSlaves(lframePtr->label.mgr) == 1) {
	    Ttk_ForgetSlave(lframePtr->label.mgr, 0);
	    /* Restore labelWidget field (see <<NOTE-LABELREMOVED>>)
	     */
	    lframePtr->label.labelWidget = labelWidget;
	}

	if (labelWidget) {
		Ttk_InsertContent(lframePtr->label.mgr, 0, labelWidget, NULL);
	    Ttk_InsertSlave(lframePtr->label.mgr, 0, labelWidget, NULL);
	    RaiseLabelWidget(lframePtr);
	}
    }

    if (mask & GEOMETRY_CHANGED) {
	Ttk_ManagerSizeChanged(lframePtr->label.mgr);
	Ttk_ManagerLayoutChanged(lframePtr->label.mgr);
    }

    return TCL_OK;
}

static const WidgetSpec LabelframeWidgetSpec = {
static WidgetSpec LabelframeWidgetSpec = {
    "TLabelframe",		/* className */
    sizeof(Labelframe),		/* recordSize */
    LabelframeOptionSpecs, 	/* optionSpecs */
    FrameCommands,		/* subcommands */
    LabelframeInitialize,	/* initializeProc */
    LabelframeCleanup,		/* cleanupProc */
    LabelframeConfigure,	/* configureProc */
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
634
635
636
637
638
639
640



641
642
643
644
645
646
647
648
649
650
651
652
653







-
-
-













	TTK_NODE("Label.text", TTK_FILL_BOTH))
TTK_END_LAYOUT

/* ======================================================================
 * +++ Initialization.
 */

MODULE_SCOPE
void TtkFrame_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkFrame_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(theme, "TFrame", FrameLayout);
    Ttk_RegisterLayout(theme, "TLabelframe", LabelframeLayout);
    Ttk_RegisterLayout(theme, "Label", LabelSublayout);

    RegisterWidget(interp, "ttk::frame", &FrameWidgetSpec);
    RegisterWidget(interp, "ttk::labelframe", &LabelframeWidgetSpec);
}

Changes to generic/ttk/ttkImage.c.

1
2
3
4
5


6
7
8
9
10
11
12

13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35


36
37
38
39
40
41
42
43

44
45
46
47
48
49

50
51
52
53
54
55
56
1
2
3


4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34


35
36








37

38
39
40
41

42
43
44
45
46
47
48
49



-
-
+
+







+
-
+














-
+





-
-
+
+
-
-
-
-
-
-
-
-
+
-




-
+







/*
 *	Image specifications and image element factory.
 *
 * Copyright © 2004 Pat Thoyts <[email protected]>
 * Copyright © 2004 Joe English
 * Copyright (C) 2004 Pat Thoyts <[email protected]>
 * Copyright (C) 2004 Joe English
 *
 * An imageSpec is a multi-element list; the first element
 * is the name of the default image to use, the remainder of the
 * list is a sequence of statespec/imagename options as per
 * [style map].
 */

#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"

#define MIN(a,b) ((a) < (b) ? (a) : (b))

/*------------------------------------------------------------------------
 * +++ ImageSpec management.
 */

struct TtkImageSpec {
    Tk_Image 		baseImage;	/* Base image to use */
    int 		mapCount;	/* #state-specific overrides */
    Ttk_StateSpec	*states;	/* array[mapCount] of states ... */
    Tk_Image		*images;	/* ... per-state images to use */
    Tk_ImageChangedProc *imageChanged;
    void		*imageChangedClientData;
    ClientData		imageChangedClientData;
};

/* NullImageChanged --
 * 	Do-nothing Tk_ImageChangedProc.
 */
static void NullImageChanged(
    TCL_UNUSED(void *),
static void NullImageChanged(ClientData clientData,
    int x, int y, int width, int height, int imageWidth, int imageHeight)
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    /* No-op */
{ /* No-op */ }
}

/* ImageSpecImageChanged --
 *     Image changes should trigger a repaint.
 */
static void ImageSpecImageChanged(void *clientData,
static void ImageSpecImageChanged(ClientData clientData,
    int x, int y, int width, int height, int imageWidth, int imageHeight)
{
    Ttk_ImageSpec *imageSpec = (Ttk_ImageSpec *)clientData;
    if (imageSpec->imageChanged != NULL) {
	imageSpec->imageChanged(imageSpec->imageChangedClientData,
		x, y, width, height,
		imageWidth, imageHeight);
72
73
74
75
76
77
78
79

80
81
82

83
84
85
86

87
88
89
90
91
92
93
65
66
67
68
69
70
71

72
73
74

75

76
77

78
79
80
81
82
83
84
85







-
+


-
+
-


-
+







 * 	Constructs a Ttk_ImageSpec * from a Tcl_Obj *.
 * 	Result must be released using TtkFreeImageSpec.
 * 	imageChangedProc will be called when not NULL when
 * 	the image changes to allow widgets to repaint.
 */
Ttk_ImageSpec *
TtkGetImageSpecEx(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr,
    Tk_ImageChangedProc *imageChangedProc, void *imageChangedClientData)
    Tk_ImageChangedProc *imageChangedProc, ClientData imageChangedClientData)
{
    Ttk_ImageSpec *imageSpec = 0;
    int i = 0, n = 0;
    int i = 0, n = 0, objc;
    Tcl_Size objc;
    Tcl_Obj **objv;

    imageSpec = (Ttk_ImageSpec *)ckalloc(sizeof(*imageSpec));
    imageSpec = ckalloc(sizeof(*imageSpec));
    imageSpec->baseImage = 0;
    imageSpec->mapCount = 0;
    imageSpec->states = 0;
    imageSpec->images = 0;
    imageSpec->imageChanged = imageChangedProc;
    imageSpec->imageChangedClientData = imageChangedClientData;

102
103
104
105
106
107
108
109
110


111
112
113
114
115
116
117
94
95
96
97
98
99
100


101
102
103
104
105
106
107
108
109







-
-
+
+







		-1));
	    Tcl_SetErrorCode(interp, "TTK", "IMAGE", "SPEC", NULL);
	}
	goto error;
    }

    n = (objc - 1) / 2;
    imageSpec->states = (Ttk_StateSpec *)ckalloc(n * sizeof(Ttk_StateSpec));
    imageSpec->images = (Tk_Image *)ckalloc(n * sizeof(Tk_Image));
    imageSpec->states = ckalloc(n * sizeof(Ttk_StateSpec));
    imageSpec->images = ckalloc(n * sizeof(Tk_Image *));

    /* Get base image:
    */
    imageSpec->baseImage = Tk_GetImage(
	    interp, tkwin, Tcl_GetString(objv[0]), ImageSpecImageChanged, imageSpec);
    if (!imageSpec->baseImage) {
    	goto error;
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
153
154
155
156
157
158
159

160



161
162
163
164
165
166
167







-
+
-
-
-








    ckfree(imageSpec);
}

/* TtkSelectImage --
 * 	Return a state-specific image from an ImageSpec
 */
Tk_Image TtkSelectImage(
Tk_Image TtkSelectImage(Ttk_ImageSpec *imageSpec, Ttk_State state)
    Ttk_ImageSpec *imageSpec,
    TCL_UNUSED(Tk_Window),
    Ttk_State state)
{
    int i;
    for (i = 0; i < imageSpec->mapCount; ++i) {
	if (Ttk_StateMatches(state, imageSpec->states+i)) {
	    return imageSpec->images[i];
	}
    }
208
209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
197
198
199
200
201
202
203



204


205
206
207
208
209
210
211







-
-
-
+
-
-







    { return Ttk_MakeBox(b.x, b.y+b.height-p.bottom, b.width, p.bottom); }

/* Ttk_Fill --
 *	Fill the destination area of the drawable by replicating
 *	the source area of the image.
 */
static void Ttk_Fill(
    TCL_UNUSED(Tk_Window),
    Drawable d,
    Tk_Image image,
    Tk_Window tkwin, Drawable d, Tk_Image image, Ttk_Box src, Ttk_Box dst)
    Ttk_Box src,
    Ttk_Box dst)
{
    int dr = dst.x + dst.width;
    int db = dst.y + dst.height;
    int x,y;

    if (!(src.width && src.height && dst.width && dst.height))
	return;
261
262
263
264
265
266
267
268

269
270
271
272
273

274
275
276
277
278
279
280
281

282
283

284
285
286
287
288
289
290

291
292
293

294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317

318
319
320
321

322
323
324
325
326

327
328
329
330
331
332
333
334

335
336
337

338
339
340
341
342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369

370
371

372
373
374
375
376
377
378

379
380

381
382
383
384
385
386
387
388
389
390
391
392

393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
246
247
248
249
250
251
252

253
254
255
256
257

258
259
260
261
262
263
264
265

266
267

268
269
270
271
272
273
274

275



276


277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

295



296


297

298
299
300
301
302

303
304
305
306
307
308
309
310

311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345

346
347

348
349
350
351
352
353
354

355
356

357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396







-
+




-
+







-
+

-
+






-
+
-
-
-
+
-
-

-
+
















-
+
-
-
-
+
-
-

-
+




-
+







-
+


-
+













-
+














-
+


-
+

-
+






-
+

-
+











-
+




-
+














-
+







/*------------------------------------------------------------------------
 * +++ Image element definition.
 */

typedef struct {		/* ClientData for image elements */
    Ttk_ImageSpec *imageSpec;	/* Image(s) to use */
    int minWidth;		/* Minimum width; overrides image width */
    int minHeight;		/* Minimum height; overrides image height */
    int minHeight;		/* Minimum width; overrides image width */
    Ttk_Sticky sticky;		/* -stickiness specification */
    Ttk_Padding border;		/* Fixed border region */
    Ttk_Padding padding;	/* Internal padding */

#ifdef TILE_07_COMPAT
#if TILE_07_COMPAT
    Ttk_ResourceCache cache;	/* Resource cache for images */
    Ttk_StateMap imageMap;	/* State-based lookup table for images */
#endif
} ImageData;

static void FreeImageData(void *clientData)
{
    ImageData *imageData = (ImageData *)clientData;
    ImageData *imageData = clientData;
    if (imageData->imageSpec)	{ TtkFreeImageSpec(imageData->imageSpec); }
#ifdef TILE_07_COMPAT
#if TILE_07_COMPAT
    if (imageData->imageMap)	{ Tcl_DecrRefCount(imageData->imageMap); }
#endif
    ckfree(clientData);
}

static void ImageElementSize(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    Ttk_Padding *paddingPtr)
{
    ImageData *imageData = (ImageData *)clientData;
    ImageData *imageData = clientData;
    Tk_Image image = imageData->imageSpec->baseImage;

    if (image) {
	Tk_SizeOfImage(image, widthPtr, heightPtr);
    }
    if (imageData->minWidth >= 0) {
	*widthPtr = imageData->minWidth;
    }
    if (imageData->minHeight >= 0) {
	*heightPtr = imageData->minHeight;
    }

    *paddingPtr = imageData->padding;
}

static void ImageElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    ImageData *imageData = (ImageData *)clientData;
    ImageData *imageData = clientData;
    Tk_Image image = 0;
    int imgWidth, imgHeight;
    Ttk_Box src, dst;

#ifdef TILE_07_COMPAT
#if TILE_07_COMPAT
    if (imageData->imageMap) {
	Tcl_Obj *imageObj = Ttk_StateMapLookup(NULL,imageData->imageMap,state);
	if (imageObj) {
	    image = Ttk_UseImage(imageData->cache, tkwin, imageObj);
	}
    }
    if (!image) {
	image = TtkSelectImage(imageData->imageSpec, tkwin, state);
	image = TtkSelectImage(imageData->imageSpec, state);
    }
#else
    image = TtkSelectImage(imageData->imageSpec, tkwin, state);
    image = TtkSelectImage(imageData->imageSpec, state);
#endif

    if (!image) {
	return;
    }

    Tk_SizeOfImage(image, &imgWidth, &imgHeight);
    src = Ttk_MakeBox(0, 0, imgWidth, imgHeight);
    dst = Ttk_StickBox(b, imgWidth, imgHeight, imageData->sticky);

    Ttk_Tile(tkwin, d, image, src, dst, imageData->border);
}

static const Ttk_ElementSpec ImageElementSpec =
static Ttk_ElementSpec ImageElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    ImageElementSize,
    ImageElementDraw
};

/*------------------------------------------------------------------------
 * +++ Image element factory.
 */
static int
Ttk_CreateImageElement(
    Tcl_Interp *interp,
    TCL_UNUSED(void *),
    void *clientData,
    Ttk_Theme theme,
    const char *elementName,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    static const char *const optionStrings[] =
    static const char *optionStrings[] =
	 { "-border","-height","-padding","-sticky","-width",NULL };
    enum { O_BORDER, O_HEIGHT, O_PADDING, O_STICKY, O_WIDTH };

    Ttk_ImageSpec *imageSpec = 0;
    ImageData *imageData = 0;
    int padding_specified = 0;
    Tcl_Size i;
    int i;

    if (objc + 1 < 2) {
    if (objc <= 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Must supply a base image", -1));
	Tcl_SetErrorCode(interp, "TTK", "IMAGE", "BASE", NULL);
	return TCL_ERROR;
    }

    imageSpec = TtkGetImageSpec(interp, Tk_MainWindow(interp), objv[0]);
    if (!imageSpec) {
	return TCL_ERROR;
    }

    imageData = (ImageData *)ckalloc(sizeof(*imageData));
    imageData = ckalloc(sizeof(*imageData));
    imageData->imageSpec = imageSpec;
    imageData->minWidth = imageData->minHeight = -1;
    imageData->sticky = TTK_FILL_BOTH;
    imageData->border = imageData->padding = Ttk_UniformPadding(0);
#ifdef TILE_07_COMPAT
#if TILE_07_COMPAT
    imageData->cache = Ttk_GetResourceCache(interp);
    imageData->imageMap = 0;
#endif

    for (i = 1; i < objc; i += 2) {
	int option;

	if (i == objc - 1) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "Value for %s missing", Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TTK", "IMAGE", "VALUE", NULL);
	    goto error;
	}

#ifdef TILE_07_COMPAT
#if TILE_07_COMPAT
	if (!strcmp("-map", Tcl_GetString(objv[i]))) {
	    imageData->imageMap = objv[i+1];
	    Tcl_IncrRefCount(imageData->imageMap);
	    continue;
	}
#endif

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
439
440
441
442
443
444
445



446
447
448
449
450
451
452







-
-
-







    return TCL_OK;

error:
    FreeImageData(imageData);
    return TCL_ERROR;
}

MODULE_SCOPE
void TtkImage_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkImage_Init(Tcl_Interp *interp)
{
    Ttk_RegisterElementFactory(interp, "image", Ttk_CreateImageElement, NULL);
}

/*EOF*/

Changes to generic/ttk/ttkInit.c.

1
2

3
4
5
6

7

8
9
10
11
12
13
14
15
16


17
18
19
20

21
22
23
24



25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40

41
42
43
44



45
46
47
48
49
50
51
52
53
54

55
56
57
58
59

60
61
62
63



64
65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80




81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115






















116
117
118
119
120
121
122
1

2
3
4
5
6
7

8
9
10
11
12
13
14
15


16
17
18
19
20

21
22



23
24
25



26
27
28
29
30
31

32
33
34
35
36
37

38
39



40
41
42



43
44
45
46
47
48

49
50
51
52
53

54
55



56
57
58



59
60
61
62
63
64


65
66
67
68




69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

-
+




+
-
+







-
-
+
+



-
+

-
-
-
+
+
+
-
-
-






-
+





-
+

-
-
-
+
+
+
-
-
-






-
+




-
+

-
-
-
+
+
+
-
-
-






-
-
+
+


-
-
-
-
+
+
+
+
















-
-
+
+

















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







/*
 * Copyright © 2003 Joe English
 * Copyright (c) 2003, Joe English
 *
 * Ttk package: initialization routine and miscellaneous utilities.
 */

#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

/*
 * Legal values for the button -default option.
 * See also: enum Ttk_ButtonDefaultState.
 */
const char *const ttkDefaultStrings[] = {
    "active", "disabled", "normal", NULL
const char *ttkDefaultStrings[] = {
    "normal", "active", "disabled", NULL
};

int Ttk_GetButtonDefaultStateFromObj(
    Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_ButtonDefaultState *statePtr)
    Tcl_Interp *interp, Tcl_Obj *objPtr, int *statePtr)
{
    int state = (int)TTK_BUTTON_DEFAULT_DISABLED;
    int result = Tcl_GetIndexFromObj(interp, objPtr, ttkDefaultStrings,
	    "default state", 0, &state);
    *statePtr = TTK_BUTTON_DEFAULT_DISABLED;
    return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkDefaultStrings,
	    sizeof(char *), "default state", 0, statePtr);

    *statePtr = (Ttk_ButtonDefaultState)state;
    return result;
}

/*
 * Legal values for the -compound option.
 * See also: enum Ttk_Compound.
 */
const char *const ttkCompoundStrings[] = {
const char *ttkCompoundStrings[] = {
    "none", "text", "image", "center",
    "top", "bottom", "left", "right", NULL
};

int Ttk_GetCompoundFromObj(
    Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Compound *compoundPtr)
    Tcl_Interp *interp, Tcl_Obj *objPtr, int *statePtr)
{
    int compound = (int)TTK_COMPOUND_NONE;
    int result = Tcl_GetIndexFromObj(interp, objPtr, ttkCompoundStrings,
	    "compound layout", 0, &compound);
    *statePtr = TTK_COMPOUND_NONE;
    return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkCompoundStrings,
	    sizeof(char *), "compound layout", 0, statePtr);

    *compoundPtr = (Ttk_Compound)compound;
    return result;
}

/*
 * Legal values for the -orient option.
 * See also: enum Ttk_Orient.
 */
const char *const ttkOrientStrings[] = {
const char *ttkOrientStrings[] = {
    "horizontal", "vertical", NULL
};

int Ttk_GetOrientFromObj(
    Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Orient *resultPtr)
    Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr)
{
    int orient = (int)TTK_ORIENT_HORIZONTAL;
    int result = Tcl_GetIndexFromObj(interp, objPtr, ttkOrientStrings,
    	    "orientation", 0, &orient);
    *resultPtr = TTK_ORIENT_HORIZONTAL;
    return Tcl_GetIndexFromObjStruct(interp, objPtr, ttkOrientStrings,
	    sizeof(char *), "orientation", 0, resultPtr);

    *resultPtr = (Ttk_Orient)orient;
    return result;
}

/*
 * Recognized values for the -state compatibility option.
 * Other options are accepted and interpreted as synonyms for "normal".
 */
static const char *const ttkStateStrings[] = {
    "active", "disabled", "normal", "readonly", NULL
static const char *ttkStateStrings[] = {
    "normal", "readonly", "disabled", "active", NULL
};
enum {
    TTK_COMPAT_STATE_ACTIVE,
    TTK_COMPAT_STATE_DISABLED,
    TTK_COMPAT_STATE_NORMAL,
    TTK_COMPAT_STATE_READONLY
    TTK_COMPAT_STATE_NORMAL,
    TTK_COMPAT_STATE_READONLY,
    TTK_COMPAT_STATE_DISABLED,
    TTK_COMPAT_STATE_ACTIVE
};

/* TtkCheckStateOption --
 * 	Handle -state compatibility option.
 *
 *	NOTE: setting -state disabled / -state enabled affects the
 *	widget state, but the internal widget state does *not* affect
 *	the value of the -state option.
 *	This option is present for compatibility only.
 */
void TtkCheckStateOption(WidgetCore *corePtr, Tcl_Obj *objPtr)
{
    int stateOption = TTK_COMPAT_STATE_NORMAL;
    unsigned all = TTK_STATE_DISABLED|TTK_STATE_READONLY|TTK_STATE_ACTIVE;
#   define SETFLAGS(f) TtkWidgetChangeState(corePtr, f, all^f)

    Tcl_GetIndexFromObj(NULL, objPtr, ttkStateStrings,
	    "", 0, &stateOption);
    (void)Tcl_GetIndexFromObjStruct(NULL, objPtr, ttkStateStrings,
	    sizeof(char *), "", 0, &stateOption);
    switch (stateOption) {
	case TTK_COMPAT_STATE_NORMAL:
	default:
	    SETFLAGS(0);
	    break;
	case TTK_COMPAT_STATE_READONLY:
	    SETFLAGS(TTK_STATE_READONLY);
	    break;
	case TTK_COMPAT_STATE_DISABLED:
	    SETFLAGS(TTK_STATE_DISABLED);
	    break;
	case TTK_COMPAT_STATE_ACTIVE:
	    SETFLAGS(TTK_STATE_ACTIVE);
	    break;
    }
#   undef SETFLAGS
}

/* TtkSendVirtualEvent --
 * 	Send a virtual event notification to the specified target window.
 * 	Equivalent to "event generate $tgtWindow <<$eventName>>"
 *
 * 	Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent,
 * 	so this routine does not reenter the interpreter.
 */
void TtkSendVirtualEvent(Tk_Window tgtWin, const char *eventName)
{
    union {XEvent general; XVirtualEvent virtual;} event;

    memset(&event, 0, sizeof(event));
    event.general.xany.type = VirtualEvent;
    event.general.xany.serial = NextRequest(Tk_Display(tgtWin));
    event.general.xany.send_event = False;
    event.general.xany.window = Tk_WindowId(tgtWin);
    event.general.xany.display = Tk_Display(tgtWin);
    event.virtual.name = Tk_GetUid(eventName);

    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
}

/* TtkEnumerateOptions, TtkGetOptionValue --
 *	Common factors for data accessor commands.
 */
int TtkEnumerateOptions(
    Tcl_Interp *interp, void *recordPtr, const Tk_OptionSpec *specPtr,
    Tk_OptionTable optionTable, Tk_Window tkwin)
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159







-
+







	    Tcl_ListObjAppendElement(interp, result, optionName);
	    Tcl_ListObjAppendElement(interp, result, optionValue);
	}
	++specPtr;

	if (specPtr->type == TK_OPTION_END && specPtr->clientData != NULL) {
	    /* Chain to next option spec array: */
	    specPtr = (const Tk_OptionSpec *)specPtr->clientData;
	    specPtr = specPtr->clientData;
	}
    }
    Tcl_SetObjResult(interp, result);
    return TCL_OK;
}

int TtkGetOptionValue(
158
159
160
161
162
163
164
165

166
167
168

169
170

171
172

173
174
175
176
177
178
179
180
181
182



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204










205
206
207

208
209
210
211
212
213
214
172
173
174
175
176
177
178

179
180
181

182
183

184
185

186
187
188
189
190
191
192
193



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208










209
210
211
212
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228







-
+


-
+

-
+

-
+







-
-
-
+
+
+












-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+








/*------------------------------------------------------------------------
 * Core Option specifications:
 * type name dbName dbClass default objOffset intOffset flags clientData mask
 */

/* public */
const Tk_OptionSpec ttkCoreOptionSpecs[] =
Tk_OptionSpec ttkCoreOptionSpecs[] =
{
    {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", NULL,
	offsetof(WidgetCore, cursorObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK,0,0 },
	Tk_Offset(WidgetCore, cursorObj), -1, TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_STRING, "-style", "style", "Style", "",
	offsetof(WidgetCore,styleObj), TCL_INDEX_NONE, 0,0,STYLE_CHANGED},
	Tk_Offset(WidgetCore,styleObj), -1, 0,0,STYLE_CHANGED},
    {TK_OPTION_STRING, "-class", "", "", NULL,
	offsetof(WidgetCore,classObj), TCL_INDEX_NONE, 0,0,READONLY_OPTION},
	Tk_Offset(WidgetCore,classObj), -1, 0,0,READONLY_OPTION},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*------------------------------------------------------------------------
 * +++ Initialization: elements and element factories.
 */

MODULE_SCOPE void TtkElements_Init(Tcl_Interp *);
MODULE_SCOPE void TtkLabel_Init(Tcl_Interp *);
MODULE_SCOPE void TtkImage_Init(Tcl_Interp *);
extern void TtkElements_Init(Tcl_Interp *);
extern void TtkLabel_Init(Tcl_Interp *);
extern void TtkImage_Init(Tcl_Interp *);

static void RegisterElements(Tcl_Interp *interp)
{
    TtkElements_Init(interp);
    TtkLabel_Init(interp);
    TtkImage_Init(interp);
}

/*------------------------------------------------------------------------
 * +++ Initialization: Widget definitions.
 */

MODULE_SCOPE void TtkButton_Init(Tcl_Interp *);
MODULE_SCOPE void TtkEntry_Init(Tcl_Interp *);
MODULE_SCOPE void TtkFrame_Init(Tcl_Interp *);
MODULE_SCOPE void TtkNotebook_Init(Tcl_Interp *);
MODULE_SCOPE void TtkPanedwindow_Init(Tcl_Interp *);
MODULE_SCOPE void TtkProgressbar_Init(Tcl_Interp *);
MODULE_SCOPE void TtkScale_Init(Tcl_Interp *);
MODULE_SCOPE void TtkScrollbar_Init(Tcl_Interp *);
MODULE_SCOPE void TtkSeparator_Init(Tcl_Interp *);
MODULE_SCOPE void TtkTreeview_Init(Tcl_Interp *);
extern void TtkButton_Init(Tcl_Interp *);
extern void TtkEntry_Init(Tcl_Interp *);
extern void TtkFrame_Init(Tcl_Interp *);
extern void TtkNotebook_Init(Tcl_Interp *);
extern void TtkPanedwindow_Init(Tcl_Interp *);
extern void TtkProgressbar_Init(Tcl_Interp *);
extern void TtkScale_Init(Tcl_Interp *);
extern void TtkScrollbar_Init(Tcl_Interp *);
extern void TtkSeparator_Init(Tcl_Interp *);
extern void TtkTreeview_Init(Tcl_Interp *);

#ifdef TTK_SQUARE_WIDGET
MODULE_SCOPE int TtkSquareWidget_Init(Tcl_Interp *);
extern int TtkSquareWidget_Init(Tcl_Interp *);
#endif

static void RegisterWidgets(Tcl_Interp *interp)
{
    TtkButton_Init(interp);
    TtkEntry_Init(interp);
    TtkFrame_Init(interp);
224
225
226
227
228
229
230
231
232
233



234
235
236
237
238
239
240
238
239
240
241
242
243
244



245
246
247
248
249
250
251
252
253
254







-
-
-
+
+
+







#endif
}

/*------------------------------------------------------------------------
 * +++ Initialization: Built-in themes.
 */

MODULE_SCOPE int TtkAltTheme_Init(Tcl_Interp *);
MODULE_SCOPE int TtkClassicTheme_Init(Tcl_Interp *);
MODULE_SCOPE int TtkClamTheme_Init(Tcl_Interp *);
extern int TtkAltTheme_Init(Tcl_Interp *);
extern int TtkClassicTheme_Init(Tcl_Interp *);
extern int TtkClamTheme_Init(Tcl_Interp *);

static void RegisterThemes(Tcl_Interp *interp)
{

    TtkAltTheme_Init(interp);
    TtkClassicTheme_Init(interp);
    TtkClamTheme_Init(interp);
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
271
272
273
274
275
276
277


278


279
280
281
282
283







-
-
+
-
-






    RegisterElements(interp);
    RegisterWidgets(interp);
    RegisterThemes(interp);

    Ttk_PlatformInit(interp);

#ifndef TK_NO_DEPRECATED
    Tcl_PkgProvideEx(interp, "Ttk", TTK_PATCH_LEVEL, (void *)&ttkStubs);
    Tcl_PkgProvideEx(interp, "Ttk", TTK_PATCH_LEVEL, (ClientData)&ttkStubs);
#endif
    Tcl_PkgProvideEx(interp, "ttk", TTK_PATCH_LEVEL, (void *)&ttkStubs);

    return TCL_OK;
}

/*EOF*/

Changes to generic/ttk/ttkLabel.c.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17








-
+
+







/*
 * text, image, and label elements.
 *
 * The label element combines text and image elements,
 * with layout determined by the "-compound" option.
 *
 */

#include "tkInt.h"
#include <tcl.h>
#include <tkInt.h>
#include "ttkTheme.h"

/*----------------------------------------------------------------------
 * +++ Text element.
 *
 * This element displays a textual label in the foreground color.
 *
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51

52
53

54
55
56
57



58
59

60
61

62
63

64
65

66
67
68


69
70
71
72
73
74
75
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51

52
53

54
55



56
57
58
59

60
61

62
63

64
65

66
67


68
69
70
71
72
73
74
75
76







-
+















-
+

-
+

-
+

-
-
-
+
+
+

-
+

-
+

-
+

-
+

-
-
+
+







    Tcl_Obj	*fontObj;
    Tcl_Obj	*foregroundObj;
    Tcl_Obj	*underlineObj;
    Tcl_Obj	*widthObj;
    Tcl_Obj	*anchorObj;
    Tcl_Obj	*justifyObj;
    Tcl_Obj	*wrapLengthObj;
    Tcl_Obj	*embossedObj;
    Tcl_Obj     *embossedObj;

    /*
     * Computed resources:
     */
    Tk_Font		tkfont;
    Tk_TextLayout	textLayout;
    int 		width;
    int 		height;
    int			embossed;

} TextElement;

/* Text element options table.
 * NB: Keep in sync with label element option table.
 */
static const Ttk_ElementOptionSpec TextElementOptions[] = {
static Ttk_ElementOptionSpec TextElementOptions[] = {
    { "-text", TK_OPTION_STRING,
	offsetof(TextElement,textObj), "" },
	Tk_Offset(TextElement,textObj), "" },
    { "-font", TK_OPTION_FONT,
	offsetof(TextElement,fontObj), DEFAULT_FONT },
	Tk_Offset(TextElement,fontObj), DEFAULT_FONT },
    { "-foreground", TK_OPTION_COLOR,
	offsetof(TextElement,foregroundObj), "black" },
    { "-underline", TK_OPTION_INDEX,
	offsetof(TextElement,underlineObj), NULL},
	Tk_Offset(TextElement,foregroundObj), "black" },
    { "-underline", TK_OPTION_INT,
	Tk_Offset(TextElement,underlineObj), "-1"},
    { "-width", TK_OPTION_INT,
	offsetof(TextElement,widthObj), "-1"},
	Tk_Offset(TextElement,widthObj), "-1"},
    { "-anchor", TK_OPTION_ANCHOR,
	offsetof(TextElement,anchorObj), "w"},
	Tk_Offset(TextElement,anchorObj), "w"},
    { "-justify", TK_OPTION_JUSTIFY,
	offsetof(TextElement,justifyObj), "left" },
	Tk_Offset(TextElement,justifyObj), "left" },
    { "-wraplength", TK_OPTION_PIXELS,
	offsetof(TextElement,wrapLengthObj), "0" },
	Tk_Offset(TextElement,wrapLengthObj), "0" },
    { "-embossed", TK_OPTION_INT,
	offsetof(TextElement,embossedObj), "0"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(TextElement,embossedObj), "0"},
    { NULL, 0, 0, NULL }
};

static int TextSetup(TextElement *text, Tk_Window tkwin)
{
    const char *string = Tcl_GetString(text->textObj);
    Tk_Justify justify = TK_JUSTIFY_LEFT;
    int wrapLength = 0;
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







 * TextDraw --
 * 	Draw a text element.
 * 	Called by TextElementDraw() and LabelElementDraw().
 */
static void TextDraw(TextElement *text, Tk_Window tkwin, Drawable d, Ttk_Box b)
{
    XColor *color = Tk_GetColorFromObj(tkwin, text->foregroundObj);
    Tcl_Size underline = INT_MIN;
    int underline = -1;
    XGCValues gcValues;
    GC gc1, gc2;
    Tk_Anchor anchor = TK_ANCHOR_CENTER;
    TkRegion clipRegion = NULL;

    gcValues.font = Tk_FontId(text->tkfont);
    gcValues.foreground = color->pixel;
166
167
168
169
170
171
172
173

174
175

176
177
178
179
180
181
182
183
184
185
186






187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203
204

205
206

207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227

228
229
230
231

232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

311
312

313
314

315
316
317


318
319
320
321
322
323
324
167
168
169
170
171
172
173

174


175











176
177
178
179
180
181

182
183
184
185

186
187
188
189
190
191
192
193
194
195
196


197


198


199

200
201
202
203
204
205
206
207
208
209
210
211
212
213


214


215


216

217

218
219
220
221
222
223

224
225
226
227
228
229
230
231













































232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251

252
253

254
255


256
257
258
259
260
261
262
263
264







-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-




-
+










-
-
+
-
-
+
-
-

-
+













-
-
+
-
-
+
-
-

-
+
-






-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-
+

-
+

-
+

-
-
+
+







    if (text->embossed) {
	Tk_DrawTextLayout(Tk_Display(tkwin), d, gc2,
	    text->textLayout, b.x+1, b.y+1, 0/*firstChar*/, -1/*lastChar*/);
    }
    Tk_DrawTextLayout(Tk_Display(tkwin), d, gc1,
	    text->textLayout, b.x, b.y, 0/*firstChar*/, -1/*lastChar*/);

    if (text->underlineObj != NULL) {
    Tcl_GetIntFromObj(NULL, text->underlineObj, &underline);
	TkGetIntForIndex(text->underlineObj, TCL_INDEX_NONE, 0, &underline);
	if (underline < INT_MIN) {
    if (underline >= 0) {
	    underline = INT_MIN;
	} else if (underline > INT_MAX) {
	    underline = INT_MAX;
	}
	if (underline != INT_MIN) {
	    if (text->embossed) {
		Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc2,
			text->textLayout, b.x+1, b.y+1, underline);
	    }
	    Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc1,
		    text->textLayout, b.x, b.y, underline);
	if (text->embossed) {
	    Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc2,
		text->textLayout, b.x+1, b.y+1, underline);
	}
	Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc1,
	    text->textLayout, b.x, b.y, underline);
	}
    }

    if (clipRegion != NULL) {
#ifdef HAVE_XFT
	TkUnixSetXftClipRegion(NULL);
	TkUnixSetXftClipRegion(None);
#endif
	XSetClipMask(Tk_Display(tkwin), gc1, None);
	XSetClipMask(Tk_Display(tkwin), gc2, None);
	TkDestroyRegion(clipRegion);
    }
    Tk_FreeGC(Tk_Display(tkwin), gc1);
    Tk_FreeGC(Tk_Display(tkwin), gc2);
}

static void TextElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    TextElement *text = (TextElement *)elementRecord;
    TextElement *text = elementRecord;

    if (!TextSetup(text, tkwin))
	return;

    *heightPtr = text->height;
    *widthPtr = TextReqWidth(text);

    TextCleanup(text);

    return;
}

static void TextElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    TextElement *text = (TextElement *)elementRecord;
    TextElement *text = elementRecord;

    if (TextSetup(text, tkwin)) {
	TextDraw(text, tkwin, d, b);
	TextCleanup(text);
    }
}

static const Ttk_ElementSpec TextElementSpec = {
static Ttk_ElementSpec TextElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    TextElementSize,
    TextElementDraw
};

/*----------------------------------------------------------------------
 * +++ cText (collapsing text) element.
 *
 * This element is the same as the Text element, except its dimensions
 * are 0,0 when the text to display is "".
 */

static int cTextSetup(TextElement *text, Tk_Window tkwin)
{
    if (*Tcl_GetString(text->textObj) == '\0') {
        return 0;
    } else {
        return TextSetup(text, tkwin);
    }
}

static void cTextElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    TextElement *text = (TextElement *)elementRecord;

    if (!cTextSetup(text, tkwin))
	return;

    *heightPtr = text->height;
    *widthPtr = TextReqWidth(text);

    TextCleanup(text);

    return;
}

static const Ttk_ElementSpec cTextElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    cTextElementSize,
    TextElementDraw
};

/*----------------------------------------------------------------------
 * +++ Image element.
 * Draws an image.
 */

typedef struct {
    Tcl_Obj	*imageObj;
    Tcl_Obj 	*stippleObj;	/* For TTK_STATE_DISABLED */
    Tcl_Obj 	*backgroundObj;	/* " " */

    Ttk_ImageSpec *imageSpec;
    Tk_Image	tkimg;
    int 	width;
    int		height;
} ImageElement;

/* ===> NB: Keep in sync with label element option table.  <===
 */
static const Ttk_ElementOptionSpec ImageElementOptions[] = {
static Ttk_ElementOptionSpec ImageElementOptions[] = {
    { "-image", TK_OPTION_STRING,
	offsetof(ImageElement,imageObj), "" },
	Tk_Offset(ImageElement,imageObj), "" },
    { "-stipple", TK_OPTION_STRING, 	/* Really: TK_OPTION_BITMAP */
	offsetof(ImageElement,stippleObj), "gray50" },
	Tk_Offset(ImageElement,stippleObj), "gray50" },
    { "-background", TK_OPTION_COLOR,
	offsetof(ImageElement,backgroundObj), DEFAULT_BACKGROUND },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(ImageElement,backgroundObj), DEFAULT_BACKGROUND },
    { NULL, 0, 0, NULL }
};

/*
 * ImageSetup() --
 * 	Look up the Tk_Image from the image element's imageObj resource.
 * 	Caller must release the image with ImageCleanup().
 *
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288







-
+







    if (!image->imageObj) {
	return 0;
    }
    image->imageSpec = TtkGetImageSpec(NULL, tkwin, image->imageObj);
    if (!image->imageSpec) {
	return 0;
    }
    image->tkimg = TtkSelectImage(image->imageSpec, tkwin, state);
    image->tkimg = TtkSelectImage(image->imageSpec, state);
    if (!image->tkimg) {
	TtkFreeImageSpec(image->imageSpec);
	return 0;
    }
    Tk_SizeOfImage(image->tkimg, &image->width, &image->height);

    return 1;
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423
424
425

426
427

428
429
430
431

432
433
434
435
436
437
438
439
440
441
442

443
444

445
446
447
448

449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363


364


365


366

367
368
369
370
371
372
373
374
375
376


377


378


379

380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395







-
+








-
-
+
-
-
+
-
-

-
+









-
-
+
-
-
+
-
-

-
+







-
+







     * @@@ it's ugly and out of fashion.
     * Do not stipple at all under Aqua, just draw the image: it shows up
     * as a white rectangle otherwise.
     */


    if (state & TTK_STATE_DISABLED) {
	if (TtkSelectImage(image->imageSpec, tkwin, 0ul) == image->tkimg) {
	if (TtkSelectImage(image->imageSpec, 0ul) == image->tkimg) {
#ifndef MAC_OSX_TK
	    StippleOver(image, tkwin, d, b.x,b.y);
#endif
	}
    }
}

static void ImageElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ImageElement *image = (ImageElement *)elementRecord;
    ImageElement *image = elementRecord;

    if (ImageSetup(image, tkwin, 0)) {
	*widthPtr = image->width;
	*heightPtr = image->height;
	ImageCleanup(image);
    }
}

static void ImageElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    ImageElement *image = (ImageElement *)elementRecord;
    ImageElement *image = elementRecord;

    if (ImageSetup(image, tkwin, state)) {
	ImageDraw(image, tkwin, d, b, state);
	ImageCleanup(image);
    }
}

static const Ttk_ElementSpec ImageElementSpec = {
static Ttk_ElementSpec ImageElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ImageElement),
    ImageElementOptions,
    ImageElementSize,
    ImageElementDraw
};

505
506
507
508
509
510
511
512

513
514

515
516

517
518
519
520
521
522

523
524

525
526
527
528



529
530

531
532

533
534

535
536

537
538

539
540
541
542
543
544

545
546

547
548
549


550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567


568
569
570
571
572
573
574
437
438
439
440
441
442
443

444
445

446
447

448
449
450
451
452
453

454
455

456
457



458
459
460
461

462
463

464
465

466
467

468
469

470
471
472
473
474
475

476
477

478
479


480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497


498
499
500
501
502
503
504
505
506







-
+

-
+

-
+





-
+

-
+

-
-
-
+
+
+

-
+

-
+

-
+

-
+

-
+





-
+

-
+

-
-
+
+










-
+





-
-
+
+







     * Computed values (see LabelSetup)
     */
    Ttk_Compound	compound;
    int  		space;
    int 		totalWidth, totalHeight;
} LabelElement;

static const Ttk_ElementOptionSpec LabelElementOptions[] = {
static Ttk_ElementOptionSpec LabelElementOptions[] = {
    { "-compound", TK_OPTION_ANY,
	offsetof(LabelElement,compoundObj), "none" },
	Tk_Offset(LabelElement,compoundObj), "none" },
    { "-space", TK_OPTION_PIXELS,
	offsetof(LabelElement,spaceObj), "4" },
	Tk_Offset(LabelElement,spaceObj), "4" },

    /* Text element part:
     * NB: Keep in sync with TextElementOptions.
     */
    { "-text", TK_OPTION_STRING,
	offsetof(LabelElement,text.textObj), "" },
	Tk_Offset(LabelElement,text.textObj), "" },
    { "-font", TK_OPTION_FONT,
	offsetof(LabelElement,text.fontObj), DEFAULT_FONT },
	Tk_Offset(LabelElement,text.fontObj), DEFAULT_FONT },
    { "-foreground", TK_OPTION_COLOR,
	offsetof(LabelElement,text.foregroundObj), "black" },
    { "-underline", TK_OPTION_INDEX,
	offsetof(LabelElement,text.underlineObj), "-1"},
	Tk_Offset(LabelElement,text.foregroundObj), "black" },
    { "-underline", TK_OPTION_INT,
	Tk_Offset(LabelElement,text.underlineObj), "-1"},
    { "-width", TK_OPTION_INT,
	offsetof(LabelElement,text.widthObj), ""},
	Tk_Offset(LabelElement,text.widthObj), ""},
    { "-anchor", TK_OPTION_ANCHOR,
	offsetof(LabelElement,text.anchorObj), "w"},
	Tk_Offset(LabelElement,text.anchorObj), "w"},
    { "-justify", TK_OPTION_JUSTIFY,
	offsetof(LabelElement,text.justifyObj), "left" },
	Tk_Offset(LabelElement,text.justifyObj), "left" },
    { "-wraplength", TK_OPTION_PIXELS,
	offsetof(LabelElement,text.wrapLengthObj), "0" },
	Tk_Offset(LabelElement,text.wrapLengthObj), "0" },
    { "-embossed", TK_OPTION_INT,
	offsetof(LabelElement,text.embossedObj), "0"},
	Tk_Offset(LabelElement,text.embossedObj), "0"},

    /* Image element part:
     * NB: Keep in sync with ImageElementOptions.
     */
    { "-image", TK_OPTION_STRING,
	offsetof(LabelElement,image.imageObj), "" },
	Tk_Offset(LabelElement,image.imageObj), "" },
    { "-stipple", TK_OPTION_STRING, 	/* Really: TK_OPTION_BITMAP */
	offsetof(LabelElement,image.stippleObj), "gray50" },
	Tk_Offset(LabelElement,image.stippleObj), "gray50" },
    { "-background", TK_OPTION_COLOR,
	offsetof(LabelElement,image.backgroundObj), DEFAULT_BACKGROUND },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(LabelElement,image.backgroundObj), DEFAULT_BACKGROUND },
    { NULL, 0, 0, NULL }
};

/*
 * LabelSetup --
 * 	Fills in computed fields of the label element.
 *
 * 	Calculate the text, image, and total width and height.
 */

#undef  MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b));
#define MAX(a,b) ((a) > (b) ? a : b);
static void LabelSetup(
    LabelElement *c, Tk_Window tkwin, Ttk_State state)
{
    Ttk_Compound *compoundPtr = &c->compound;

    Tk_GetPixelsFromObj(NULL, tkwin, c->spaceObj, &c->space);
    Ttk_GetCompoundFromObj(NULL, c->compoundObj, compoundPtr);
    Tk_GetPixelsFromObj(NULL,tkwin,c->spaceObj,&c->space);
    Ttk_GetCompoundFromObj(NULL,c->compoundObj,(int*)compoundPtr);

    /*
     * Deal with TTK_COMPOUND_NONE.
     */
    if (c->compound == TTK_COMPOUND_NONE) {
	if (ImageSetup(&c->image, tkwin, state)) {
	    c->compound = TTK_COMPOUND_IMAGE;
626
627
628
629
630
631
632
633
634

635
636

637
638
639
640

641
642
643
644
645
646
647
558
559
560
561
562
563
564


565


566


567

568
569
570
571
572
573
574
575







-
-
+
-
-
+
-
-

-
+







    if (c->compound != TTK_COMPOUND_TEXT)
	ImageCleanup(&c->image);
    if (c->compound != TTK_COMPOUND_IMAGE)
	TextCleanup(&c->text);
}

static void LabelElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    LabelElement *label = (LabelElement *)elementRecord;
    LabelElement *label = elementRecord;
    int textReqWidth = 0;

    LabelSetup(label, tkwin, 0);

    *heightPtr = label->totalHeight;

    /* Requested width based on -width option, not actual text width:
676
677
678
679
680
681
682
683

684
685
686
687
688
689
690
691
692
693
694
695

696
697

698
699
700
701

702
703
704
705
706
707
708
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618
619
620
621


622


623


624

625
626
627
628
629
630
631
632







-
+










-
-
+
-
-
+
-
-

-
+







/*
 * DrawCompound --
 * 	Helper routine for LabelElementDraw;
 * 	Handles layout for -compound {left,right,top,bottom}
 */
static void DrawCompound(
    LabelElement *l, Ttk_Box b, Tk_Window tkwin, Drawable d, Ttk_State state,
	Ttk_Side imageSide, Ttk_Side textSide)
    int imageSide, int textSide)
{
    Ttk_Box imageBox =
	Ttk_PlaceBox(&b, l->image.width, l->image.height, imageSide, 0);
    Ttk_Box textBox =
	Ttk_PlaceBox(&b, l->text.width, l->text.height, textSide, 0);
    ImageDraw(&l->image,tkwin,d,imageBox,state);
    TextDraw(&l->text,tkwin,d,textBox);
}

static void LabelElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    LabelElement *l = (LabelElement *)elementRecord;
    LabelElement *l = elementRecord;
    Tk_Anchor anchor = TK_ANCHOR_CENTER;

    LabelSetup(l, tkwin, state);

    /*
     * Adjust overall parcel based on -anchor:
     */
746
747
748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
670
671
672
673
674
675
676

677
678
679
680
681
682
683
684
685
686
687
688



689
690
691
692
693
694

695
696
697
698







-
+











-
-
-






-




	    DrawCompound(l, b, tkwin, d, state, TTK_SIDE_RIGHT, TTK_SIDE_LEFT);
	    break;
    }

    LabelCleanup(l);
}

static const Ttk_ElementSpec LabelElementSpec = {
static Ttk_ElementSpec LabelElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(LabelElement),
    LabelElementOptions,
    LabelElementSize,
    LabelElementDraw
};

/*------------------------------------------------------------------------
 * +++ Initialization.
 */

MODULE_SCOPE
void TtkLabel_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkLabel_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_GetDefaultTheme(interp);

    Ttk_RegisterElement(interp, theme, "text", &TextElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "ctext", &cTextElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "image", &ImageElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "label", &LabelElementSpec, NULL);
}

Changes to generic/ttk/ttkLayout.c.

1
2
3
4
5
6

7
8

9

10
11
12
13


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49




50
51
52
53
54
55
56
1
2
3
4
5

6
7
8
9

10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







35
36
37
38
39




40
41
42
43
44
45
46
47
48
49
50





-
+


+
-
+


-
-
+
+




















-
-
-
-
-
-
-





-
-
-
-
+
+
+
+







/*
 * ttkLayout.c --
 *
 * Generic layout processing.
 *
 * Copyright © 2003 Joe English.  Freely redistributable.
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 */

#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include "ttkThemeInt.h"

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)

/*------------------------------------------------------------------------
 * +++ Ttk_Box and Ttk_Padding utilities:
 */

Ttk_Box
Ttk_MakeBox(int x, int y, int width, int height)
{
    Ttk_Box b;
    b.x = x; b.y = y; b.width = width; b.height = height;
    return b;
}

int
Ttk_BoxContains(Ttk_Box box, int x, int y)
{
    return box.x <= x && x < box.x + box.width
	&& box.y <= y && y < box.y + box.height;
}

int
TtkBoxEqual(Ttk_Box box1, Ttk_Box box2)
{
    return box1.x == box2.x && box1.y == box2.y
	&& box1.width == box2.width && box1.height == box2.height;
}

Tcl_Obj *
Ttk_NewBoxObj(Ttk_Box box)
{
    Tcl_Obj *result[4];

    result[0] = Tcl_NewWideIntObj(box.x);
    result[1] = Tcl_NewWideIntObj(box.y);
    result[2] = Tcl_NewWideIntObj(box.width);
    result[3] = Tcl_NewWideIntObj(box.height);
    result[0] = Tcl_NewIntObj(box.x);
    result[1] = Tcl_NewIntObj(box.y);
    result[2] = Tcl_NewIntObj(box.width);
    result[3] = Tcl_NewIntObj(box.height);

    return Tcl_NewListObj(4, result);
}

/*
 * packTop, packBottom, packLeft, packRight --
 * 	Carve out a parcel of the specified height (resp width)
223
224
225
226
227
228
229
230


231
232
233
234
235
236
237
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232







-
+
+







	case TK_ANCHOR_NE:	return TTK_STICK_N | TTK_STICK_E;
	case TK_ANCHOR_E:	return TTK_STICK_E;
	case TK_ANCHOR_SE:	return TTK_STICK_S | TTK_STICK_E;
	case TK_ANCHOR_S:	return TTK_STICK_S;
	case TK_ANCHOR_SW:	return TTK_STICK_S | TTK_STICK_W;
	case TK_ANCHOR_W:	return TTK_STICK_W;
	case TK_ANCHOR_NW:	return TTK_STICK_N | TTK_STICK_W;
	default:	return 0;
	default:
	case TK_ANCHOR_CENTER:	return 0;
    }
}

/*
 * Ttk_AnchorBox --
 * 	Place a box of size w * h in the specified parcel,
 * 	according to the specified anchor.
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
314
315
316
317
318
319
320


321
322
323
324
325
326
327
328







-
-
+







int Ttk_GetPaddingFromObj(
    Tcl_Interp *interp,
    Tk_Window tkwin,
    Tcl_Obj *objPtr,
    Ttk_Padding *pad)
{
    Tcl_Obj **padv;
    Tcl_Size i, padc;
    int pixels[4];
    int i, padc, pixels[4];

    if (TCL_OK != Tcl_ListObjGetElements(interp, objPtr, &padc, &padv)) {
	goto error;
    }

    if (padc > 4) {
	if (interp) {
358
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
352
353
354
355
356
357
358


359
360
361
362
363
364
365
366







-
-
+







 * 	instead of Tk_Pixel specifications.  Does not require a Tk_Window
 * 	parameter.
 *
 */
int Ttk_GetBorderFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Padding *pad)
{
    Tcl_Obj **padv;
    Tcl_Size i, padc;
    int pixels[4];
    int i, padc, pixels[4];

    if (TCL_OK != Tcl_ListObjGetElements(interp, objPtr, &padc, &padv)) {
	goto error;
    }

    if (padc > 4) {
	if (interp) {
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535







-
+







    Ttk_Box 		parcel;		/* allocated parcel */
    Ttk_LayoutNode	*next, *child;
};

static Ttk_LayoutNode *Ttk_NewLayoutNode(
    unsigned flags, Ttk_ElementClass *elementClass)
{
    Ttk_LayoutNode *node = (Ttk_LayoutNode *)ckalloc(sizeof(*node));
    Ttk_LayoutNode *node = ckalloc(sizeof(*node));

    node->flags = flags;
    node->eclass = elementClass;
    node->state = 0u;
    node->next = node->child = 0;
    node->parcel = Ttk_MakeBox(0,0,0,0);

561
562
563
564
565
566
567
568
569


570
571
572
573
574
575
576
554
555
556
557
558
559
560


561
562
563
564
565
566
567
568
569







-
-
+
+







    char *name;
    unsigned flags;
    struct Ttk_TemplateNode_ *next, *child;
};

static Ttk_TemplateNode *Ttk_NewTemplateNode(const char *name, unsigned flags)
{
    Ttk_TemplateNode *op = (Ttk_TemplateNode *)ckalloc(sizeof(*op));
    op->name = (char *)ckalloc(strlen(name) + 1); strcpy(op->name, name);
    Ttk_TemplateNode *op = ckalloc(sizeof(*op));
    op->name = ckalloc(strlen(name) + 1); strcpy(op->name, name);
    op->flags = flags;
    op->next = op->child = 0;
    return op;
}

void Ttk_FreeLayoutTemplate(Ttk_LayoutTemplate op)
{
607
608
609
610
611
612
613
614

615
616
617
618
619
620

621
622
623

624
625
626
627
628
629
630
600
601
602
603
604
605
606

607
608
609
610
611
612

613
614
615

616
617
618
619
620
621
622
623







-
+





-
+


-
+







 *	Convert a Tcl list into a layout template.
 *
 * Syntax:
 * 	layoutSpec ::= { elementName ?-option value ...? }+
 */

/* NB: This must match bit definitions TTK_PACK_LEFT etc. */
static const char *const packSideStrings[] =
static const char *packSideStrings[] =
    { "left", "right", "top", "bottom", NULL };

Ttk_LayoutTemplate Ttk_ParseLayoutTemplate(Tcl_Interp *interp, Tcl_Obj *objPtr)
{
    enum {  OP_SIDE, OP_STICKY, OP_EXPAND, OP_BORDER, OP_UNIT, OP_CHILDREN };
    static const char *const optStrings[] = {
    static const char *optStrings[] = {
	"-side", "-sticky", "-expand", "-border", "-unit", "-children", 0 };

    Tcl_Size i = 0, objc;
    int i = 0, objc;
    Tcl_Obj **objv;
    Ttk_TemplateNode *head = 0, *tail = 0;

    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK)
	return 0;

    while (i < objc) {
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
698
699
700
701
702
703
704


705
706
707
708
709
710
711







-
-







	    tail = tail->next;
	} else {
	    head = tail = Ttk_NewTemplateNode(elementName, flags | sticky);
	}
	if (childSpec) {
	    tail->child = Ttk_ParseLayoutTemplate(interp, childSpec);
	    if (!tail->child) {
                Tcl_SetObjResult(interp, Tcl_ObjPrintf("Invalid -children value"));
                Tcl_SetErrorCode(interp, "TTK", "VALUE", "CHILDREN", NULL);
		goto error;
	    }
	}
    }

    return head;

813
814
815
816
817
818
819
820

821
822
823
824
825
826
827
804
805
806
807
808
809
810

811
812
813
814
815
816
817
818







-
+







	 * In Ttk_ParseLayoutTemplate, default -sticky is "nsew", so always
	 * include this even if no sticky bits are set.
	 */

	APPENDSTR("-sticky");
	APPENDOBJ(Ttk_NewStickyObj(flags & _TTK_MASK_STICK));

	/* @@@ Check again: are these necessary? Can't see any effect! */
	/* @@@ Check again: are these necessary? */
	if (flags & TTK_BORDER)	{ APPENDSTR("-border"); APPENDSTR("1"); }
	if (flags & TTK_UNIT) 	{ APPENDSTR("-unit"); APPENDSTR("1"); }

	if (node->child) {
	    APPENDSTR("-children");
	    APPENDOBJ(Ttk_UnparseLayoutTemplate(node->child));
	}
847
848
849
850
851
852
853
854

855
856
857
858
859
860
861
838
839
840
841
842
843
844

845
846
847
848
849
850
851
852







-
+







};

static Ttk_Layout TTKNewLayout(
    Ttk_Style style,
    void *recordPtr,Tk_OptionTable optionTable, Tk_Window tkwin,
    Ttk_LayoutNode *root)
{
    Ttk_Layout layout = (Ttk_Layout)ckalloc(sizeof(*layout));
    Ttk_Layout layout = ckalloc(sizeof(*layout));
    layout->style = style;
    layout->recordPtr = recordPtr;
    layout->optionTable = optionTable;
    layout->tkwin = tkwin;
    layout->root = root;
    return layout;
}
916
917
918
919
920
921
922
923
924


925
926
927
928
929
930
931
907
908
909
910
911
912
913


914
915
916
917
918
919
920
921
922







-
-
+
+







{
    Tcl_DString buf;
    const char *styleName;
    Ttk_Style style;
    Ttk_LayoutTemplate layoutTemplate;

    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, Ttk_StyleName(parentLayout->style), TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, baseName, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, Ttk_StyleName(parentLayout->style), -1);
    Tcl_DStringAppend(&buf, baseName, -1);
    styleName = Tcl_DStringValue(&buf);

    style = Ttk_GetStyle(themePtr, styleName);
    layoutTemplate = Ttk_FindLayoutTemplate(themePtr, styleName);

    if (!layoutTemplate) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1242
1243
1244
1245
1246
1247
1248































1249
1250
1251
1252
1253
1254
1255
1256
1257







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









    node->parcel = b;
    if (node->child) {
	Ttk_PlaceNodeList(layout, node->child, 0,
	    Ttk_PadBox(b, Ttk_LayoutNodeInternalPadding(layout, node)));
    }
}

/*
 * AnchorToPosition --
 * 	Convert a Tk_Anchor enum to a position bitmask.
 */
static Ttk_PositionSpec AnchorToPosition(Tk_Anchor anchor)
{
    switch (anchor)
    {
	case TK_ANCHOR_N:	return TTK_PACK_TOP;
	case TK_ANCHOR_S:	return TTK_PACK_BOTTOM;
	case TK_ANCHOR_NE:	return TTK_PACK_RIGHT|TTK_STICK_N;
	case TK_ANCHOR_SE:	return TTK_PACK_RIGHT|TTK_STICK_S;
	case TK_ANCHOR_E:	return TTK_PACK_RIGHT;
	case TK_ANCHOR_NW:	return TTK_PACK_LEFT|TTK_STICK_N;
	case TK_ANCHOR_SW:	return TTK_PACK_LEFT|TTK_STICK_S;
	case TK_ANCHOR_W:	return TTK_PACK_LEFT;
	case TK_ANCHOR_CENTER:	return 0;
	default:;
    }
    return TTK_PACK_LEFT;
}

/*
 * Ttk_AnchorElement --
 * 	Explicitly specify an element's anchoring.
 */
void Ttk_AnchorElement(Ttk_Element node, Tk_Anchor anchor)
{
    node->flags = AnchorToPosition(anchor);
}

/*
 * Ttk_ChangeElementState --
 */
void Ttk_ChangeElementState(Ttk_LayoutNode *node,unsigned set,unsigned clr)
{
    node->state = (node->state | set) & ~clr;
}

/*EOF*/

Changes to generic/ttk/ttkManager.c.

1
2
3
4
5
6

7

8
9
10
11
12
13
14


15
16
17
18
19


20
21

22
23

24
25
26
27
28
29

30
31

32
33
34
35

36
37
38
39



40
41

42
43
44
45
46
47
48

49
50

51
52

53
54

55
56

57
58
59
60

61
62

63
64
65


66
67
68
69
70
71
72
1
2
3
4
5
6
7

8
9
10
11
12
13


14
15
16
17
18


19
20
21

22
23

24
25
26
27
28
29

30
31

32
33
34
35

36
37



38
39
40
41

42
43
44
45
46
47
48

49
50

51
52

53
54

55
56

57
58
59
60

61
62

63
64


65
66
67
68
69
70
71
72
73






+
-
+





-
-
+
+



-
-
+
+

-
+

-
+





-
+

-
+



-
+

-
-
-
+
+
+

-
+






-
+

-
+

-
+

-
+

-
+



-
+

-
+

-
-
+
+







/*
 * Copyright 2005, Joe English.  Freely redistributable.
 *
 * Support routines for geometry managers.
 */

#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include "ttkManager.h"

/*------------------------------------------------------------------------
 * +++ The Geometry Propagation Dance.
 *
 * When a content window requests a new size or some other parameter changes,
 * the manager recomputes the required size for the container window and calls
 * When a slave window requests a new size or some other parameter changes,
 * the manager recomputes the required size for the master window and calls
 * Tk_GeometryRequest().  This is scheduled as an idle handler so multiple
 * updates can be processed as a single batch.
 *
 * If all goes well, the container's manager will process the request
 * (and so on up the chain to the toplevel window), and the container
 * If all goes well, the master's manager will process the request
 * (and so on up the chain to the toplevel window), and the master
 * window will eventually receive a <Configure> event.  At this point
 * it recomputes the size and position of all content windows and places them.
 * it recomputes the size and position of all slaves and places them.
 *
 * If all does not go well, however, the container's request may be ignored
 * If all does not go well, however, the master's request may be ignored
 * (typically because the top-level window has a fixed, user-specified size).
 * Tk doesn't provide any notification when this happens; to account for this,
 * we also schedule an idle handler to call the layout procedure
 * after making a geometry request.
 *
 * +++ Content window removal <<NOTE-LOSTCONTENT>>.
 * +++ Slave removal <<NOTE-LOSTSLAVE>>.
 *
 * There are three conditions under which a content window is removed:
 * There are three conditions under which a slave is removed:
 *
 * (1) Another GM claims control
 * (2) Manager voluntarily relinquishes control
 * (3) Content window is destroyed
 * (3) Slave is destroyed
 *
 * In case (1), Tk calls the manager's lostContentProc.
 * Case (2) is performed by calling Tk_ManageGeometry(window,NULL,0);
 * in this case Tk does _not_ call the lostContentProc (documented behavior).
 * In case (1), Tk calls the manager's lostSlaveProc.
 * Case (2) is performed by calling Tk_ManageGeometry(slave,NULL,0);
 * in this case Tk does _not_ call the LostSlaveProc (documented behavior).
 * Tk doesn't handle case (3) either; to account for that we
 * register an event handler on the content window to track <Destroy> events.
 * register an event handler on the slave widget to track <Destroy> events.
 */

/* ++ Data structures.
 */
typedef struct
{
    Tk_Window 		window;
    Tk_Window 		slaveWindow;
    Ttk_Manager 	*manager;
    void 		*data;
    void 		*slaveData;
    unsigned		flags;
} Ttk_Content;
} Ttk_Slave;

/* content->flags bits:
/* slave->flags bits:
 */
#define CONTENT_MAPPED 	0x1	/* content windows to be mapped when container is */
#define SLAVE_MAPPED 		0x1	/* slave to be mapped when master is */

struct TtkManager_
{
    const Ttk_ManagerSpec	*managerSpec;
    Ttk_ManagerSpec	*managerSpec;
    void 		*managerData;
    Tk_Window   	window;
    Tk_Window   	masterWindow;
    unsigned		flags;
    Tcl_Size 	 	nContent;
    Ttk_Content 		**content;
    int 	 	nSlaves;
    Ttk_Slave 		**slaves;
};

/* manager->flags bits:
 */
#define MGR_UPDATE_PENDING	0x1
#define MGR_RESIZE_REQUIRED	0x2
#define MGR_RELAYOUT_REQUIRED	0x4
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98

99
100
101
102
103
104
105

106
107
108
109

110
111
112
113
114
115
116

117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139


140
141
142

143
144
145


146
147
148
149
150
151
152
153
154
155
156




157
158
159
160
161
162
163



164
165
166
167
168
169
170
171



172

173

174
175

176
177
178


179
180
181
182
183

184
185
186
187


188
189

190
191
192
193
194




195
196

197
198
199

200
201

202
203
204
205
206
207
208
209

210
211

212
213
214
215
216
217



218
219
220
221

222
223
224
225
226
227
228
229

230
231
232


233
234
235


236
237
238
239
240
241
242
243
244

245
246
247
248


249
250

251
252
253


254
255
256

257
258
259
260

261
262
263


264
265
266


267
268
269
270
271
272


273
274
275
276
277

278
279

280
281
282


283
284
285
286

287
288
289
290
291
292



293
294
295
296
297
298

299
300
301
302


303
304

305
306
307
308
309
310
311
312
313

314
315

316
317

318
319
320
321
322
323
324
325
326
327











328
329
330
331


332
333
334

335
336
337
338
339
340
341
342


343
344
345


346
347
348


349
350
351
352


353
354

355
356
357
358



359
360
361
362


363
364
365
366

367
368
369


370
371
372
373
374
375





376
377
378
379
380


381
382

383
384
385
386



387
388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410

411
412

413
414

415
416

417
418

419
420
421
422
423
424
425
426


427
428

429
430
431
432



433
434
435
436
437
438
439



440
441
442
443
444
445
446
447


448
449
450

451
452
453
454
455
456


457
458
459


460
461
462

463
464
465
466

467
468
469
470
471



472
473
474
475


476
477
478

479
480
481
482
483
484


485
486
487
488
489


490
491

492
493

494
495
496
497

498
499
500
501
502

503
504
505
506

507
508

509
510
511
512
513
514
515
516



517
518
519
520
521




522
523
524
525

526
527

528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544


545
546
547
548
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98

99
100
101
102
103
104
105

106
107
108
109

110
111
112
113
114
115
116

117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138


139
140
141
142

143
144


145
146
147
148
149
150
151
152
153




154
155
156
157
158
159
160
161



162
163
164
165
166
167
168
169



170
171
172
173
174

175
176

177
178


179
180
181
182
183
184

185
186
187


188
189
190

191
192




193
194
195
196
197

198
199
200

201
202

203
204
205
206
207
208
209
210

211
212

213
214
215
216



217
218
219
220
221
222

223
224
225
226
227
228
229
230

231
232


233
234
235


236
237
238
239
240
241
242
243
244
245

246
247
248


249
250
251

252
253


254
255
256
257

258
259
260
261

262
263


264
265
266


267
268
269
270
271
272


273
274
275
276
277
278

279
280

281
282


283
284
285
286
287

288
289
290
291



292
293
294
295
296
297
298
299

300
301
302


303
304
305

306
307
308
309
310
311
312
313
314

315
316

317


318










319
320
321
322
323
324
325
326
327
328
329

330


331
332
333
334

335
336
337
338
339
340
341


342
343
344


345
346
347


348
349
350
351


352
353
354

355
356



357
358
359
360
361


362
363
364
365
366

367
368


369
370
371





372
373
374
375
376
377
378
379


380
381
382

383
384



385
386
387
388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410

411
412

413
414

415
416

417
418

419
420
421
422
423
424
425


426
427
428

429
430



431
432
433
434
435
436
437



438
439
440
441
442
443
444
445
446


447
448
449
450

451
452
453
454
455


456
457
458


459
460
461
462

463
464
465
466

467
468
469



470
471
472
473
474


475
476
477
478

479
480
481
482
483


484
485
486
487
488


489
490
491

492
493

494
495
496
497

498
499
500
501
502

503
504
505
506

507
508

509
510
511
512
513
514



515
516
517
518




519
520
521
522
523
524
525

526
527

528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543


544
545
546
547
548
549







-
+







-
+






-
+



-
+






-
+

-
+



















-
-
+
+


-
+

-
-
+
+







-
-
-
-
+
+
+
+




-
-
-
+
+
+





-
-
-
+
+
+

+
-
+

-
+

-
-
+
+




-
+


-
-
+
+

-
+

-
-
-
-
+
+
+
+

-
+


-
+

-
+







-
+

-
+



-
-
-
+
+
+



-
+







-
+

-
-
+
+

-
-
+
+








-
+


-
-
+
+

-
+

-
-
+
+


-
+



-
+

-
-
+
+

-
-
+
+




-
-
+
+




-
+

-
+

-
-
+
+



-
+



-
-
-
+
+
+





-
+


-
-
+
+

-
+








-
+

-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-

-
-
+
+


-
+






-
-
+
+

-
-
+
+

-
-
+
+


-
-
+
+

-
+

-
-
-
+
+
+


-
-
+
+



-
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+

-
-
-
+
+
+

-
+

-
+

















-
+

-
+

-
+

-
+

-
+

-
+






-
-
+
+

-
+

-
-
-
+
+
+




-
-
-
+
+
+






-
-
+
+


-
+




-
-
+
+

-
-
+
+


-
+



-
+


-
-
-
+
+
+


-
-
+
+


-
+




-
-
+
+



-
-
+
+

-
+

-
+



-
+




-
+



-
+

-
+





-
-
-
+
+
+

-
-
-
-
+
+
+
+



-
+

-
+

-
+













-
-
+
+




	Tcl_DoWhenIdle(ManagerIdleProc, mgr);
	mgr->flags |= MGR_UPDATE_PENDING;
    }
    mgr->flags |= flags;
}

/* ++ RecomputeSize --
 * 	Recomputes the required size of the container window,
 * 	Recomputes the required size of the master window,
 * 	makes geometry request.
 */
static void RecomputeSize(Ttk_Manager *mgr)
{
    int width = 1, height = 1;

    if (mgr->managerSpec->RequestedSize(mgr->managerData, &width, &height)) {
	Tk_GeometryRequest(mgr->window, width, height);
	Tk_GeometryRequest(mgr->masterWindow, width, height);
	ScheduleUpdate(mgr, MGR_RELAYOUT_REQUIRED);
    }
    mgr->flags &= ~MGR_RESIZE_REQUIRED;
}

/* ++ RecomputeLayout --
 * 	Recompute geometry of all content windows.
 * 	Recompute geometry of all slaves.
 */
static void RecomputeLayout(Ttk_Manager *mgr)
{
    mgr->managerSpec->PlaceContent(mgr->managerData);
    mgr->managerSpec->PlaceSlaves(mgr->managerData);
    mgr->flags &= ~MGR_RELAYOUT_REQUIRED;
}

/* ++ ManagerIdleProc --
 * 	DoWhenIdle procedure for deferred updates.
 */
static void ManagerIdleProc(void *clientData)
static void ManagerIdleProc(ClientData clientData)
{
    Ttk_Manager *mgr = (Ttk_Manager *)clientData;
    Ttk_Manager *mgr = clientData;
    mgr->flags &= ~MGR_UPDATE_PENDING;

    if (mgr->flags & MGR_RESIZE_REQUIRED) {
	RecomputeSize(mgr);
    }
    if (mgr->flags & MGR_RELAYOUT_REQUIRED) {
	if (mgr->flags & MGR_UPDATE_PENDING) {
	    /* RecomputeSize has scheduled another update; relayout later */
	    return;
	}
	RecomputeLayout(mgr);
    }
}

/*------------------------------------------------------------------------
 * +++ Event handlers.
 */

/* ++ ManagerEventHandler --
 * 	Recompute content layout when container widget is resized.
 * 	Keep the content's map state in sync with the container's.
 * 	Recompute slave layout when master widget is resized.
 * 	Keep the slave's map state in sync with the master's.
 */
static const int ManagerEventMask = StructureNotifyMask;
static void ManagerEventHandler(void *clientData, XEvent *eventPtr)
static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr)
{
    Ttk_Manager *mgr = (Ttk_Manager *)clientData;
    Tcl_Size i;
    Ttk_Manager *mgr = clientData;
    int i;

    switch (eventPtr->type)
    {
	case ConfigureNotify:
	    RecomputeLayout(mgr);
	    break;
	case MapNotify:
	    for (i = 0; i < mgr->nContent; ++i) {
		Ttk_Content *content = mgr->content[i];
		if (content->flags & CONTENT_MAPPED) {
		    Tk_MapWindow(content->window);
	    for (i = 0; i < mgr->nSlaves; ++i) {
		Ttk_Slave *slave = mgr->slaves[i];
		if (slave->flags & SLAVE_MAPPED) {
		    Tk_MapWindow(slave->slaveWindow);
		}
	    }
	    break;
	case UnmapNotify:
	    for (i = 0; i < mgr->nContent; ++i) {
		Ttk_Content *content = mgr->content[i];
		Tk_UnmapWindow(content->window);
	    for (i = 0; i < mgr->nSlaves; ++i) {
		Ttk_Slave *slave = mgr->slaves[i];
		Tk_UnmapWindow(slave->slaveWindow);
	    }
	    break;
    }
}

/* ++ ContentLostEventHandler --
 * 	Notifies manager when a content window is destroyed
 * 	(see <<NOTE-LOSTCONTENT>>).
/* ++ SlaveEventHandler --
 * 	Notifies manager when a slave is destroyed
 * 	(see <<NOTE-LOSTSLAVE>>).
 */
static const unsigned SlaveEventMask = StructureNotifyMask;
static void ContentLostEventHandler(void *clientData, XEvent *eventPtr)
static void SlaveEventHandler(ClientData clientData, XEvent *eventPtr)
{
    Ttk_Content *content = (Ttk_Content *)clientData;
    Ttk_Slave *slave = clientData;
    if (eventPtr->type == DestroyNotify) {
	content->manager->managerSpec->tkGeomMgr.lostContentProc(
	    content->manager, content->window);
	slave->manager->managerSpec->tkGeomMgr.lostSlaveProc(
	    slave->manager, slave->slaveWindow);
    }
}

/*------------------------------------------------------------------------
 * +++ Content initialization and cleanup.
 * +++ Slave initialization and cleanup.
 */

static Ttk_Content *NewContent(
    Ttk_Manager *mgr, Tk_Window window, void *data)
static Ttk_Slave *NewSlave(
    Ttk_Manager *mgr, Tk_Window slaveWindow, void *slaveData)
{
    Ttk_Content *content = (Ttk_Content *)ckalloc(sizeof(Ttk_Content));
    Ttk_Slave *slave = ckalloc(sizeof(*slave));

    content->window = window;
    content->manager = mgr;
    content->flags = 0;
    content->data = data;
    slave->slaveWindow = slaveWindow;
    slave->manager = mgr;
    slave->flags = 0;
    slave->slaveData = slaveData;

    return content;
    return slave;
}

static void DeleteContent(Ttk_Content *content)
static void DeleteSlave(Ttk_Slave *slave)
{
    ckfree(content);
    ckfree(slave);
}

/*------------------------------------------------------------------------
 * +++ Manager initialization and cleanup.
 */

Ttk_Manager *Ttk_CreateManager(
    const Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window window)
    Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window masterWindow)
{
    Ttk_Manager *mgr = (Ttk_Manager *)ckalloc(sizeof(*mgr));
    Ttk_Manager *mgr = ckalloc(sizeof(*mgr));

    mgr->managerSpec 	= managerSpec;
    mgr->managerData	= managerData;
    mgr->window	= window;
    mgr->nContent 	= 0;
    mgr->content 	= NULL;
    mgr->masterWindow	= masterWindow;
    mgr->nSlaves 	= 0;
    mgr->slaves 	= NULL;
    mgr->flags  	= 0;

    Tk_CreateEventHandler(
	mgr->window, ManagerEventMask, ManagerEventHandler, mgr);
	mgr->masterWindow, ManagerEventMask, ManagerEventHandler, mgr);

    return mgr;
}

void Ttk_DeleteManager(Ttk_Manager *mgr)
{
    Tk_DeleteEventHandler(
	mgr->window, ManagerEventMask, ManagerEventHandler, mgr);
	mgr->masterWindow, ManagerEventMask, ManagerEventHandler, mgr);

    while (mgr->nContent > 0) {
	Ttk_ForgetContent(mgr, mgr->nContent - 1);
    while (mgr->nSlaves > 0) {
	Ttk_ForgetSlave(mgr, mgr->nSlaves - 1);
    }
    if (mgr->content) {
	ckfree(mgr->content);
    if (mgr->slaves) {
	ckfree(mgr->slaves);
    }

    Tcl_CancelIdleCall(ManagerIdleProc, mgr);

    ckfree(mgr);
}

/*------------------------------------------------------------------------
 * +++ Content window management.
 * +++ Slave management.
 */

/* ++ InsertContent --
 * 	Adds content to the list of managed windows.
/* ++ InsertSlave --
 * 	Adds slave to the list of managed windows.
 */
static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, Tcl_Size index)
static void InsertSlave(Ttk_Manager *mgr, Ttk_Slave *slave, int index)
{
    Tcl_Size endIndex = mgr->nContent++;
    mgr->content = (Ttk_Content **)ckrealloc(mgr->content, mgr->nContent * sizeof(Ttk_Content *));
    int endIndex = mgr->nSlaves++;
    mgr->slaves = ckrealloc(mgr->slaves, mgr->nSlaves * sizeof(Ttk_Slave *));

    while (endIndex > index) {
	mgr->content[endIndex] = mgr->content[endIndex - 1];
	mgr->slaves[endIndex] = mgr->slaves[endIndex - 1];
	--endIndex;
    }

    mgr->content[index] = content;
    mgr->slaves[index] = slave;

    Tk_ManageGeometry(content->window,
	&mgr->managerSpec->tkGeomMgr, mgr);
    Tk_ManageGeometry(slave->slaveWindow,
	&mgr->managerSpec->tkGeomMgr, (ClientData)mgr);

    Tk_CreateEventHandler(content->window,
	StructureNotifyMask, ContentLostEventHandler, content);
    Tk_CreateEventHandler(slave->slaveWindow,
	SlaveEventMask, SlaveEventHandler, (ClientData)slave);

    ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
}

/* RemoveContent --
 * 	Unmanage and delete the content window.
/* RemoveSlave --
 * 	Unmanage and delete the slave.
 *
 * NOTES/ASSUMPTIONS:
 *
 * [1] It's safe to call Tk_UnmapWindow / Tk_UnmaintainGeometry even if this
 * routine is called from the content window's DestroyNotify event handler.
 * routine is called from the slave's DestroyNotify event handler.
 */
static void RemoveContent(Ttk_Manager *mgr, Tcl_Size index)
static void RemoveSlave(Ttk_Manager *mgr, int index)
{
    Ttk_Content *content = mgr->content[index];
    Tcl_Size i;
    Ttk_Slave *slave = mgr->slaves[index];
    int i;

    /* Notify manager:
     */
    mgr->managerSpec->ContentRemoved(mgr->managerData, index);
    mgr->managerSpec->SlaveRemoved(mgr->managerData, index);

    /* Remove from array:
     */
    --mgr->nContent;
    for (i = index ; i < mgr->nContent; ++i) {
	mgr->content[i] = mgr->content[i+1];
    --mgr->nSlaves;
    for (i = index ; i < mgr->nSlaves; ++i) {
	mgr->slaves[i] = mgr->slaves[i+1];
    }

    /* Clean up:
     */
    Tk_DeleteEventHandler(
	content->window, StructureNotifyMask, ContentLostEventHandler, content);
	slave->slaveWindow, SlaveEventMask, SlaveEventHandler, slave);

    /* Note [1] */
    Tk_UnmaintainGeometry(content->window, mgr->window);
    Tk_UnmapWindow(content->window);
    Tk_UnmaintainGeometry(slave->slaveWindow, mgr->masterWindow);
    Tk_UnmapWindow(slave->slaveWindow);

    DeleteContent(content);
    DeleteSlave(slave);

    ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
}

/*------------------------------------------------------------------------
 * +++ Tk_GeomMgr hooks.
 */

void Ttk_GeometryRequestProc(void *clientData, Tk_Window window)
void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window slaveWindow)
{
    Ttk_Manager *mgr = (Ttk_Manager *)clientData;
    Ttk_Manager *mgr = clientData;
    Tcl_Size index = Ttk_ContentIndex(mgr, window);

    int slaveIndex = Ttk_SlaveIndex(mgr, slaveWindow);
    if (index >= 0) {
	int reqWidth = Tk_ReqWidth(window);
	int reqHeight= Tk_ReqHeight(window);
	if (mgr->managerSpec->ContentRequest(
	    mgr->managerData, index, reqWidth, reqHeight)) {
	    ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
	}
    }
}

    int reqWidth = Tk_ReqWidth(slaveWindow);
    int reqHeight= Tk_ReqHeight(slaveWindow);

    if (mgr->managerSpec->SlaveRequest(
		mgr->managerData, slaveIndex, reqWidth, reqHeight))
    {
	ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
    }
}

void Ttk_LostSlaveProc(ClientData clientData, Tk_Window slaveWindow)
void Ttk_LostContentProc(void *clientData, Tk_Window window)
{
    Ttk_Manager *mgr = (Ttk_Manager *)clientData;
    Tcl_Size index = Ttk_ContentIndex(mgr, window);
    Ttk_Manager *mgr = clientData;
    int index = Ttk_SlaveIndex(mgr, slaveWindow);

    /* ASSERT: index >= 0 */
    RemoveContent(mgr, index);
    RemoveSlave(mgr, index);
}

/*------------------------------------------------------------------------
 * +++ Public API.
 */

/* ++ Ttk_InsertContent --
 * 	Add a new content window at the specified index.
/* ++ Ttk_InsertSlave --
 * 	Add a new slave window at the specified index.
 */
void Ttk_InsertContent(
    Ttk_Manager *mgr, Tcl_Size index, Tk_Window tkwin, void *data)
void Ttk_InsertSlave(
    Ttk_Manager *mgr, int index, Tk_Window tkwin, void *slaveData)
{
    Ttk_Content *content = NewContent(mgr, tkwin, data);
    InsertContent(mgr, content, index);
    Ttk_Slave *slave = NewSlave(mgr, tkwin, slaveData);
    InsertSlave(mgr, slave, index);
}

/* ++ Ttk_ForgetContent --
 * 	Unmanage the specified content window.
/* ++ Ttk_ForgetSlave --
 * 	Unmanage the specified slave.
 */
void Ttk_ForgetContent(Ttk_Manager *mgr, Tcl_Size index)
void Ttk_ForgetSlave(Ttk_Manager *mgr, int slaveIndex)
{
    Tk_Window window = mgr->content[index]->window;
    RemoveContent(mgr, index);
    Tk_ManageGeometry(window, NULL, 0);
    Tk_Window slaveWindow = mgr->slaves[slaveIndex]->slaveWindow;
    RemoveSlave(mgr, slaveIndex);
    Tk_ManageGeometry(slaveWindow, NULL, 0);
}

/* ++ Ttk_PlaceContent --
 * 	Set the position and size of the specified content window.
/* ++ Ttk_PlaceSlave --
 * 	Set the position and size of the specified slave window.
 *
 * NOTES:
 * 	Contrary to documentation, Tk_MaintainGeometry doesn't always
 * 	map the content window.
 * 	map the slave.
 */
void Ttk_PlaceContent(
    Ttk_Manager *mgr, Tcl_Size index, int x, int y, int width, int height)
void Ttk_PlaceSlave(
    Ttk_Manager *mgr, int slaveIndex, int x, int y, int width, int height)
{
    Ttk_Content *content = mgr->content[index];
    Tk_MaintainGeometry(content->window,mgr->window,x,y,width,height);
    content->flags |= CONTENT_MAPPED;
    if (Tk_IsMapped(mgr->window)) {
	Tk_MapWindow(content->window);
    Ttk_Slave *slave = mgr->slaves[slaveIndex];
    Tk_MaintainGeometry(slave->slaveWindow,mgr->masterWindow,x,y,width,height);
    slave->flags |= SLAVE_MAPPED;
    if (Tk_IsMapped(mgr->masterWindow)) {
	Tk_MapWindow(slave->slaveWindow);
    }
}

/* ++ Ttk_UnmapContent --
 * 	Unmap the specified content window, but leave it managed.
/* ++ Ttk_UnmapSlave --
 * 	Unmap the specified slave, but leave it managed.
 */
void Ttk_UnmapContent(Ttk_Manager *mgr, Tcl_Size index)
void Ttk_UnmapSlave(Ttk_Manager *mgr, int slaveIndex)
{
    Ttk_Content *content = mgr->content[index];
    Tk_UnmaintainGeometry(content->window, mgr->window);
    content->flags &= ~CONTENT_MAPPED;
    Ttk_Slave *slave = mgr->slaves[slaveIndex];
    Tk_UnmaintainGeometry(slave->slaveWindow, mgr->masterWindow);
    slave->flags &= ~SLAVE_MAPPED;
    /* Contrary to documentation, Tk_UnmaintainGeometry doesn't always
     * unmap the content window:
     * unmap the slave:
     */
    Tk_UnmapWindow(content->window);
    Tk_UnmapWindow(slave->slaveWindow);
}

/* LayoutChanged, SizeChanged --
 * 	Schedule a relayout, resp. resize request.
 */
void Ttk_ManagerLayoutChanged(Ttk_Manager *mgr)
{
    ScheduleUpdate(mgr, MGR_RELAYOUT_REQUIRED);
}

void Ttk_ManagerSizeChanged(Ttk_Manager *mgr)
{
    ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
}

/* +++ Accessors.
 */
Tcl_Size Ttk_NumberContent(Ttk_Manager *mgr)
int Ttk_NumberSlaves(Ttk_Manager *mgr)
{
    return mgr->nContent;
    return mgr->nSlaves;
}
void *Ttk_ContentData(Ttk_Manager *mgr, Tcl_Size index)
void *Ttk_SlaveData(Ttk_Manager *mgr, int slaveIndex)
{
    return mgr->content[index]->data;
    return mgr->slaves[slaveIndex]->slaveData;
}
Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, Tcl_Size index)
Tk_Window Ttk_SlaveWindow(Ttk_Manager *mgr, int slaveIndex)
{
    return mgr->content[index]->window;
    return mgr->slaves[slaveIndex]->slaveWindow;
}

/*------------------------------------------------------------------------
 * +++ Utility routines.
 */

/* ++ Ttk_ContentIndex --
 * 	Returns the index of specified content window, TCL_INDEX_NONE if not found.
/* ++ Ttk_SlaveIndex --
 * 	Returns the index of specified slave window, -1 if not found.
 */
Tcl_Size Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window window)
int Ttk_SlaveIndex(Ttk_Manager *mgr, Tk_Window slaveWindow)
{
    Tcl_Size index;
    for (index = 0; index < mgr->nContent; ++index)
	if (mgr->content[index]->window == window)
    int index;
    for (index = 0; index < mgr->nSlaves; ++index)
	if (mgr->slaves[index]->slaveWindow == slaveWindow)
	    return index;
    return -1;
}

/* ++ Ttk_GetContentIndexFromObj(interp, mgr, objPtr, indexPtr) --
 * 	Return the index of the content window specified by objPtr.
 * 	Content windows may be specified as an integer index or
/* ++ Ttk_GetSlaveIndexFromObj(interp, mgr, objPtr, indexPtr) --
 * 	Return the index of the slave specified by objPtr.
 * 	Slaves may be specified as an integer index or
 * 	as the name of the managed window.
 *
 * Returns:
 * 	Standard Tcl completion code.  Leaves an error message in case of error.
 */

int Ttk_GetContentIndexFromObj(
    Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, Tcl_Size *indexPtr)
int Ttk_GetSlaveIndexFromObj(
    Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, int *indexPtr)
{
    const char *string = Tcl_GetString(objPtr);
    Tcl_Size index = 0;
    int slaveIndex = 0;
    Tk_Window tkwin;

    /* Try interpreting as an integer first:
     */
    if (TkGetIntForIndex(objPtr, mgr->nContent - 1, 1, &index) == TCL_OK) {
	if (index < 0 || index > mgr->nContent) {
    if (Tcl_GetIntFromObj(NULL, objPtr, &slaveIndex) == TCL_OK) {
	if (slaveIndex < 0 || slaveIndex >= mgr->nSlaves) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Managed window index %d out of bounds", (int)index));
	    Tcl_SetErrorCode(interp, "TTK", "MANAGED", "INDEX", NULL);
		"Slave index %d out of bounds", slaveIndex));
	    Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL);
	    return TCL_ERROR;
	}
	*indexPtr = index;
	*indexPtr = slaveIndex;
	return TCL_OK;
    }

    /* Try interpreting as a window name;
    /* Try interpreting as a slave window name;
     */
    if ((*string == '.') &&
	    (tkwin = Tk_NameToWindow(interp, string, mgr->window))) {
	index = Ttk_ContentIndex(mgr, tkwin);
	if (index < 0) {
	    (tkwin = Tk_NameToWindow(interp, string, mgr->masterWindow))) {
	slaveIndex = Ttk_SlaveIndex(mgr, tkwin);
	if (slaveIndex < 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "%s is not managed by %s", string,
		    Tk_PathName(mgr->window)));
	    Tcl_SetErrorCode(interp, "TTK", "MANAGED", "MANAGER", NULL);
		    Tk_PathName(mgr->masterWindow)));
	    Tcl_SetErrorCode(interp, "TTK", "SLAVE", "MANAGER", NULL);
	    return TCL_ERROR;
	}
	*indexPtr = index;
	*indexPtr = slaveIndex;
	return TCL_OK;
    }

    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "Invalid managed window specification %s", string));
    Tcl_SetErrorCode(interp, "TTK", "MANAGED", "SPEC", NULL);
	    "Invalid slave specification %s", string));
    Tcl_SetErrorCode(interp, "TTK", "SLAVE", "SPEC", NULL);
    return TCL_ERROR;
}

/* ++ Ttk_ReorderContent(mgr, fromIndex, toIndex) --
 * 	Change content window order.
/* ++ Ttk_ReorderSlave(mgr, fromIndex, toIndex) --
 * 	Change slave order.
 */
void Ttk_ReorderContent(Ttk_Manager *mgr, Tcl_Size fromIndex, Tcl_Size toIndex)
void Ttk_ReorderSlave(Ttk_Manager *mgr, int fromIndex, int toIndex)
{
    Ttk_Content *moved = mgr->content[fromIndex];
    Ttk_Slave *moved = mgr->slaves[fromIndex];

    /* Shuffle down: */
    while (fromIndex > toIndex) {
	mgr->content[fromIndex] = mgr->content[fromIndex - 1];
	mgr->slaves[fromIndex] = mgr->slaves[fromIndex - 1];
	--fromIndex;
    }
    /* Or, shuffle up: */
    while (fromIndex < toIndex) {
	mgr->content[fromIndex] = mgr->content[fromIndex + 1];
	mgr->slaves[fromIndex] = mgr->slaves[fromIndex + 1];
	++fromIndex;
    }
    /* ASSERT: fromIndex == toIndex */
    mgr->content[fromIndex] = moved;
    mgr->slaves[fromIndex] = moved;

    /* Schedule a relayout.  In general, rearranging content
    /* Schedule a relayout.  In general, rearranging slaves
     * may also change the size:
     */
    ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
}

/* ++ Ttk_Maintainable(interp, window, container) --
 * 	Utility routine.  Verifies that 'container' may be used to maintain
 *	the geometry of 'window' via Tk_MaintainGeometry:
/* ++ Ttk_Maintainable(interp, slave, master) --
 * 	Utility routine.  Verifies that 'master' may be used to maintain
 *	the geometry of 'slave' via Tk_MaintainGeometry:
 *
 * 	+ 'container' is either 'window's parent -OR-
 * 	+ 'container is a descendant of 'window's parent.
 * 	+ 'window' is not a toplevel window
 * 	+ 'window' belongs to the same toplevel as 'container'
 * 	+ 'master' is either 'slave's parent -OR-
 * 	+ 'master is a descendant of 'slave's parent.
 * 	+ 'slave' is not a toplevel window
 * 	+ 'slave' belongs to the same toplevel as 'master'
 *
 * Returns: 1 if OK; otherwise 0, leaving an error message in 'interp'.
 */
int Ttk_Maintainable(Tcl_Interp *interp, Tk_Window window, Tk_Window container)
int Ttk_Maintainable(Tcl_Interp *interp, Tk_Window slave, Tk_Window master)
{
    Tk_Window ancestor = container, parent = Tk_Parent(window);
    Tk_Window ancestor = master, parent = Tk_Parent(slave);

    if (Tk_IsTopLevel(window) || window == container) {
    if (Tk_IsTopLevel(slave) || slave == master) {
	goto badWindow;
    }

    while (ancestor != parent) {
	if (Tk_IsTopLevel(ancestor)) {
	    goto badWindow;
	}
	ancestor = Tk_Parent(ancestor);
    }

    return 1;

badWindow:
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("can't add %s as content of %s",
	    Tk_PathName(window), Tk_PathName(container)));
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("can't add %s as slave of %s",
	    Tk_PathName(slave), Tk_PathName(master)));
    Tcl_SetErrorCode(interp, "TTK", "GEOMETRY", "MAINTAINABLE", NULL);
    return 0;
}

Changes to generic/ttk/ttkManager.h.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20


21
22
23


24
25
26

27
28
29
30
31
32
33
34
35



36
37
38
39
40
41
42
43


44
45
46
47
48
49

50
51
52
53
54


55
56
57

58
59
60
61


62
63
64
65
66



67
68
69
70


71
72
73
74
75
76
77
78
79
80


81
82
83
84


85
86
87
88

89
90

91
92
93
94


95
96
97
98


99
100
101


102
103
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18


19
20
21


22
23
24
25

26
27
28
29
30
31
32



33
34
35
36
37
38
39
40



41
42
43
44
45
46
47

48
49
50



51
52
53


54
55



56
57
58




59
60
61
62



63
64
65
66
67
68
69
70
71



72
73
74



75
76
77
78
79

80


81
82



83
84
85



86
87
88


89
90
91
92

-
+














-
+

-
-
+
+

-
-
+
+


-
+






-
-
-
+
+
+





-
-
-
+
+





-
+


-
-
-
+
+

-
-
+

-
-
-
+
+

-
-
-
-
+
+
+

-
-
-
+
+







-
-
-
+
+

-
-
-
+
+



-
+
-
-
+

-
-
-
+
+

-
-
-
+
+

-
-
+
+


/*
 * Copyright © 2005 Joe English.  Freely redistributable.
 * Copyright (c) 2005, Joe English.  Freely redistributable.
 *
 * Geometry manager utilities.
 */

#ifndef _TTKMANAGER
#define _TTKMANAGER

#include "ttkTheme.h"

typedef struct TtkManager_ Ttk_Manager;

/*
 * Geometry manager specification record:
 *
 * RequestedSize computes the requested size of the container window.
 * RequestedSize computes the requested size of the master window.
 *
 * PlaceContent sets the position and size of all managed content windows
 * by calling Ttk_PlaceContent().
 * PlaceSlaves sets the position and size of all managed slaves
 * by calling Ttk_PlaceSlave().
 *
 * ContentRemoved() is called immediately before a content window is removed.
 * NB: the associated content window may have been destroyed when this
 * SlaveRemoved() is called immediately before a slave is removed.
 * NB: the associated slave window may have been destroyed when this
 * routine is called.
 *
 * ContentRequest() is called when a content window requests a size change.
 * SlaveRequest() is called when a slave requests a size change.
 * It should return 1 if the request should propagate, 0 otherwise.
 */
typedef struct {			/* Manager hooks */
    Tk_GeomMgr tkGeomMgr;		/* "real" Tk Geometry Manager */

    int  (*RequestedSize)(void *managerData, int *widthPtr, int *heightPtr);
    void (*PlaceContent)(void *managerData);
    int  (*ContentRequest)(void *managerData, Tcl_Size index, int width, int height);
    void (*ContentRemoved)(void *managerData, Tcl_Size index);
    void (*PlaceSlaves)(void *managerData);
    int  (*SlaveRequest)(void *managerData, int slaveIndex, int w, int h);
    void (*SlaveRemoved)(void *managerData, int slaveIndex);
} Ttk_ManagerSpec;

/*
 * Default implementations for Tk_GeomMgr hooks:
 */
#define Ttk_LostSlaveProc Ttk_LostContentProc
MODULE_SCOPE void Ttk_GeometryRequestProc(void *, Tk_Window window);
MODULE_SCOPE void Ttk_LostContentProc(void *, Tk_Window window);
MODULE_SCOPE void Ttk_GeometryRequestProc(ClientData, Tk_Window slave);
MODULE_SCOPE void Ttk_LostSlaveProc(ClientData, Tk_Window slave);

/*
 * Public API:
 */
MODULE_SCOPE Ttk_Manager *Ttk_CreateManager(
	const Ttk_ManagerSpec *, void *managerData, Tk_Window window);
	Ttk_ManagerSpec *, void *managerData, Tk_Window masterWindow);
MODULE_SCOPE void Ttk_DeleteManager(Ttk_Manager *);

#define  Ttk_InsertSlave Ttk_InsertContent
MODULE_SCOPE void Ttk_InsertContent(
    Ttk_Manager *, Tcl_Size position, Tk_Window, void *clientData);
MODULE_SCOPE void Ttk_InsertSlave(
    Ttk_Manager *, int position, Tk_Window, void *slaveData);

#define Ttk_ForgetSlave Ttk_ForgetContent
MODULE_SCOPE void Ttk_ForgetContent(Ttk_Manager *, Tcl_Size index);
MODULE_SCOPE void Ttk_ForgetSlave(Ttk_Manager *, int slaveIndex);

#define Ttk_ReorderSlave Ttk_ReorderContent
MODULE_SCOPE void Ttk_ReorderContent(Ttk_Manager *, Tcl_Size fromIndex, Tcl_Size toIndex);
    /* Rearrange content window positions */
MODULE_SCOPE void Ttk_ReorderSlave(Ttk_Manager *, int fromIndex, int toIndex);
    /* Rearrange slave positions */

#define Ttk_PlaceSlave Ttk_PlaceContent
MODULE_SCOPE void Ttk_PlaceContent(
    Ttk_Manager *, Tcl_Size index, int x, int y, int width, int height);
    /* Position and map the content window */
MODULE_SCOPE void Ttk_PlaceSlave(
    Ttk_Manager *, int slaveIndex, int x, int y, int width, int height);
    /* Position and map the slave */

#define Ttk_UnmapSlave Ttk_UnmapContent
MODULE_SCOPE void Ttk_UnmapContent(Ttk_Manager *, Tcl_Size index);
    /* Unmap the content window */
MODULE_SCOPE void Ttk_UnmapSlave(Ttk_Manager *, int slaveIndex);
    /* Unmap the slave */

MODULE_SCOPE void Ttk_ManagerSizeChanged(Ttk_Manager *);
MODULE_SCOPE void Ttk_ManagerLayoutChanged(Ttk_Manager *);
    /* Notify manager that size (resp. layout) needs to be recomputed */

/* Utilities:
 */
#define Ttk_SlaveIndex Ttk_ContentIndex
MODULE_SCOPE Tcl_Size Ttk_ContentIndex(Ttk_Manager *, Tk_Window);
    /* Returns: index in content array of specified window, TCL_INDEX_NONE if not found */
MODULE_SCOPE int Ttk_SlaveIndex(Ttk_Manager *, Tk_Window);
    /* Returns: index in slave array of specified window, -1 if not found */

#define Ttk_GetSlaveIndexFromObj Ttk_GetContentIndexFromObj
MODULE_SCOPE int Ttk_GetContentIndexFromObj(
    Tcl_Interp *, Ttk_Manager *, Tcl_Obj *, Tcl_Size *indexPtr);
MODULE_SCOPE int Ttk_GetSlaveIndexFromObj(
    Tcl_Interp *, Ttk_Manager *, Tcl_Obj *, int *indexPtr);

/* Accessor functions:
 */
#define Ttk_NumberSlaves Ttk_NumberContent
MODULE_SCOPE int Ttk_NumberSlaves(Ttk_Manager *);
MODULE_SCOPE Tcl_Size Ttk_NumberContent(Ttk_Manager *);
    /* Returns: number of managed content windows */
    /* Returns: number of managed slaves */

#define Ttk_SlaveData Ttk_ContentData
MODULE_SCOPE void *Ttk_ContentData(Ttk_Manager *, Tcl_Size index);
    /* Returns: client data associated with content window */
MODULE_SCOPE void *Ttk_SlaveData(Ttk_Manager *, int slaveIndex);
    /* Returns: client data associated with slave */

#define Ttk_SlaveWindow Ttk_ContentWindow
MODULE_SCOPE Tk_Window Ttk_ContentWindow(Ttk_Manager *, Tcl_Size index);
    /* Returns: content window */
MODULE_SCOPE Tk_Window Ttk_SlaveWindow(Ttk_Manager *, int slaveIndex);
    /* Returns: slave window */

MODULE_SCOPE int Ttk_Maintainable(Tcl_Interp *, Tk_Window content, Tk_Window container);
    /* Returns: 1 if container can manage content; 0 otherwise leaving error msg */
MODULE_SCOPE int Ttk_Maintainable(Tcl_Interp *, Tk_Window slave, Tk_Window master);
    /* Returns: 1 if master can manage slave; 0 otherwise leaving error msg */

#endif /* _TTKMANAGER */

Changes to generic/ttk/ttkNotebook.c.

1
2

3
4



5
6



7
8
9
10
11
12
13
14
15
16
17
18
19

20
21

22
23
24
25
26
27
28
1

2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
32

-
+


+
+
+
-
-
+
+
+












-
+

-
+







/*
 * Copyright © 2004 Joe English
 * Copyright (c) 2004, Joe English
 */

#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"
#include "ttkManager.h"

#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

/*------------------------------------------------------------------------
 * +++ Tab resources.
 */

#define DEFAULT_MIN_TAB_WIDTH 24

static const char *const TabStateStrings[] = { "disabled", "hidden", "normal", 0 };
static const char *const TabStateStrings[] = { "normal", "disabled", "hidden", 0 };
typedef enum {
    TAB_STATE_DISABLED, TAB_STATE_HIDDEN, TAB_STATE_NORMAL
    TAB_STATE_NORMAL, TAB_STATE_DISABLED, TAB_STATE_HIDDEN
} TAB_STATE;

typedef struct
{
    /* Internal data:
     */
    int 	width, height;		/* Requested size of tab */
49
50
51
52
53
54
55
56

57
58

59
60
61
62


63
64

65
66

67
68
69
70
71




72
73
74
75

76
77
78

79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


99
100
101

102
103
104
105
106
107
108
109
110

111
112
113


114
115
116


117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
53
54
55
56
57
58
59

60
61

62
63
64


65
66
67

68
69

70
71




72
73
74
75
76
77
78

79
80
81

82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100


101
102
103
104

105
106
107
108
109
110
111
112
113

114
115


116
117
118


119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142

143
144

145
146
147
148
149
150
151







-
+

-
+


-
-
+
+

-
+

-
+

-
-
-
-
+
+
+
+



-
+


-
+

-
+
















-
-
+
+


-
+








-
+

-
-
+
+

-
-
+
+


-
+


















-
+
-


-







} Tab;

/* Two different option tables are used for tabs:
 * TabOptionSpecs is used to draw the tab, and only includes resources
 * relevant to the tab.
 *
 * PaneOptionSpecs includes additional options for child window placement
 * and is used to configure the pane.
 * and is used to configure the slave.
 */
static const Tk_OptionSpec TabOptionSpecs[] =
static Tk_OptionSpec TabOptionSpecs[] =
{
    {TK_OPTION_STRING_TABLE, "-state", "", "",
	"normal", TCL_INDEX_NONE, offsetof(Tab,state),
	TK_OPTION_ENUM_VAR, TabStateStrings, 0 },
	"normal", -1,Tk_Offset(Tab,state),
	0,(ClientData)TabStateStrings,0 },
    {TK_OPTION_STRING, "-text", "text", "Text", "",
	offsetof(Tab,textObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED },
	Tk_Offset(Tab,textObj), -1, 0,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-image", "image", "Image", NULL/*default*/,
	offsetof(Tab,imageObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED },
	Tk_Offset(Tab,imageObj), -1, TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound",
	NULL, offsetof(Tab,compoundObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,ttkCompoundStrings,GEOMETRY_CHANGED },
    {TK_OPTION_INDEX, "-underline", "underline", "Underline",
	TTK_OPTION_UNDERLINE_DEF(Tab, underlineObj), GEOMETRY_CHANGED},
	"none", Tk_Offset(Tab,compoundObj), -1,
	0,(ClientData)ttkCompoundStrings,GEOMETRY_CHANGED },
    {TK_OPTION_INT, "-underline", "underline", "Underline", "-1",
	Tk_Offset(Tab,underlineObj), -1, 0,0,GEOMETRY_CHANGED },
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0 }
};

static const Tk_OptionSpec PaneOptionSpecs[] =
static Tk_OptionSpec PaneOptionSpecs[] =
{
    {TK_OPTION_STRING, "-padding", "padding", "Padding", "0",
	offsetof(Tab,paddingObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED },
	Tk_Offset(Tab,paddingObj), -1, 0,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-sticky", "sticky", "Sticky", "nsew",
	offsetof(Tab,stickyObj), TCL_INDEX_NONE, 0, 0, GEOMETRY_CHANGED },
	Tk_Offset(Tab,stickyObj), -1, 0,0,GEOMETRY_CHANGED },

    WIDGET_INHERIT_OPTIONS(TabOptionSpecs)
};

/*------------------------------------------------------------------------
 * +++ Notebook resources.
 */
typedef struct
{
    Tcl_Obj *widthObj;		/* Default width */
    Tcl_Obj *heightObj;		/* Default height */
    Tcl_Obj *paddingObj;	/* Padding around notebook */

    Ttk_Manager *mgr;		/* Geometry manager */
    Tk_OptionTable tabOptionTable;	/* Tab options */
    Tk_OptionTable paneOptionTable;	/* Tab+pane options */
    Tcl_Size currentIndex;		/* index of currently selected tab */
    Tcl_Size activeIndex;		/* index of currently active tab */
    int currentIndex;		/* index of currently selected tab */
    int activeIndex;		/* index of currently active tab */
    Ttk_Layout tabLayout;	/* Sublayout for tabs */

    Ttk_Box clientArea;		/* Where to pack content windows */
    Ttk_Box clientArea;		/* Where to pack slave widgets */
} NotebookPart;

typedef struct
{
    WidgetCore core;
    NotebookPart notebook;
} Notebook;

static const Tk_OptionSpec NotebookOptionSpecs[] =
static Tk_OptionSpec NotebookOptionSpecs[] =
{
    {TK_OPTION_PIXELS, "-width", "width", "Width", "0",
	offsetof(Notebook,notebook.widthObj),TCL_INDEX_NONE,
    {TK_OPTION_INT, "-width", "width", "Width", "0",
	Tk_Offset(Notebook,notebook.widthObj),-1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_PIXELS, "-height", "height", "Height", "0",
	offsetof(Notebook,notebook.heightObj),TCL_INDEX_NONE,
    {TK_OPTION_INT, "-height", "height", "Height", "0",
	Tk_Offset(Notebook,notebook.heightObj),-1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-padding", "padding", "Padding", NULL,
	offsetof(Notebook,notebook.paddingObj),TCL_INDEX_NONE,
	Tk_Offset(Notebook,notebook.paddingObj),-1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/* Notebook style options:
 */
typedef struct
{
    Ttk_PositionSpec	tabPosition;	/* Where to place tabs */
    Ttk_Padding 	tabMargins;	/* Margins around tab row */
    Ttk_PositionSpec 	tabPlacement;	/* How to pack tabs within tab row */
    Ttk_Orient		tabOrient;	/* ... */
    int 		minTabWidth;	/* Minimum tab width */
    Ttk_Padding 	padding;	/* External padding */
} NotebookStyle;

static void NotebookStyleOptions(
static void NotebookStyleOptions(Notebook *nb, NotebookStyle *nbstyle)
    Notebook *nb, NotebookStyle *nbstyle, Tk_Window tkwin)
{
    Tcl_Obj *objPtr;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

    nbstyle->tabPosition = TTK_PACK_TOP | TTK_STICK_W;
    if ((objPtr = Ttk_QueryOption(nb->core.layout, "-tabposition", 0)) != 0) {
	TtkGetLabelAnchorFromObj(NULL, objPtr, &nbstyle->tabPosition);
    }

    /* Guess default tabPlacement as function of tabPosition:
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200

201
202
203

204
205
206

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223


224
225
226
227
228
229
230
231


232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
159
160
161
162
163
164
165







166
167
168
169
170
171
172
173
174
175


176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196

197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
223


224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244







-
-
-
-
-
-
-










-
-
+




-
+












-
+


-
+


-
+















-
-
+
+






-
-
+
+











-
+







    } else { /* Assume TTK_PACK_TOP */
	nbstyle->tabPlacement = TTK_PACK_LEFT | TTK_STICK_S;
    }
    if ((objPtr = Ttk_QueryOption(nb->core.layout, "-tabplacement", 0)) != 0) {
	TtkGetLabelAnchorFromObj(NULL, objPtr, &nbstyle->tabPlacement);
    }

    /* Save the stick bit for later.  One of the values
     * TTK_STICK_S, TTK_STICK_N, TTK_STICK_E, or TTK_STICK_W:
     */
    if (mainInfoPtr != NULL) {
	mainInfoPtr->ttkNbTabsStickBit = (nbstyle->tabPlacement & 0x0f);
    }

    /* Compute tabOrient as function of tabPlacement:
     */
    if (nbstyle->tabPlacement & (TTK_PACK_LEFT|TTK_PACK_RIGHT)) {
	nbstyle->tabOrient = TTK_ORIENT_HORIZONTAL;
    } else {
	nbstyle->tabOrient = TTK_ORIENT_VERTICAL;
    }

    nbstyle->tabMargins = Ttk_UniformPadding(0);
    if ((objPtr = Ttk_QueryOption(nb->core.layout, "-tabmargins", 0)) != 0) {
	Ttk_GetPaddingFromObj(NULL, nb->core.tkwin, objPtr,
	    &nbstyle->tabMargins);
	Ttk_GetBorderFromObj(NULL, objPtr, &nbstyle->tabMargins);
    }

    nbstyle->padding = Ttk_UniformPadding(0);
    if ((objPtr = Ttk_QueryOption(nb->core.layout, "-padding", 0)) != 0) {
	Ttk_GetPaddingFromObj(NULL, nb->core.tkwin, objPtr, &nbstyle->padding);
	Ttk_GetPaddingFromObj(NULL,nb->core.tkwin,objPtr,&nbstyle->padding);
    }

    nbstyle->minTabWidth = DEFAULT_MIN_TAB_WIDTH;
    if ((objPtr = Ttk_QueryOption(nb->core.layout, "-mintabwidth", 0)) != 0) {
	Tcl_GetIntFromObj(NULL, objPtr, &nbstyle->minTabWidth);
    }
}

/*------------------------------------------------------------------------
 * +++ Tab management.
 */

static Tab *CreateTab(Tcl_Interp *interp, Notebook *nb, Tk_Window window)
static Tab *CreateTab(Tcl_Interp *interp, Notebook *nb, Tk_Window slaveWindow)
{
    Tk_OptionTable optionTable = nb->notebook.paneOptionTable;
    Tab *record = (Tab *)ckalloc(sizeof(Tab));
    void *record = ckalloc(sizeof(Tab));
    memset(record, 0, sizeof(Tab));

    if (Tk_InitOptions(interp, record, optionTable, window) != TCL_OK) {
    if (Tk_InitOptions(interp, record, optionTable, slaveWindow) != TCL_OK) {
	ckfree(record);
	return NULL;
    }

    return record;
}

static void DestroyTab(Notebook *nb, Tab *tab)
{
    void *record = tab;
    Tk_FreeConfigOptions(record, nb->notebook.paneOptionTable, nb->core.tkwin);
    ckfree(record);
}

static int ConfigureTab(
    Tcl_Interp *interp, Notebook *nb, Tab *tab, Tk_Window window,
    Tcl_Size objc, Tcl_Obj *const objv[])
    Tcl_Interp *interp, Notebook *nb, Tab *tab, Tk_Window slaveWindow,
    int objc, Tcl_Obj *const objv[])
{
    Ttk_Sticky sticky = tab->sticky;
    Ttk_Padding padding = tab->padding;
    Tk_SavedOptions savedOptions;
    int mask = 0;

    if (Tk_SetOptions(interp, tab, nb->notebook.paneOptionTable,
	    objc, objv, window, &savedOptions, &mask) != TCL_OK)
    if (Tk_SetOptions(interp, (ClientData)tab, nb->notebook.paneOptionTable,
	    objc, objv, slaveWindow, &savedOptions, &mask) != TCL_OK)
    {
	return TCL_ERROR;
    }

    /* Check options:
     * @@@ TODO: validate -image option.
     */
    if (Ttk_GetStickyFromObj(interp, tab->stickyObj, &sticky) != TCL_OK)
    {
	goto error;
    }
    if (Ttk_GetPaddingFromObj(interp, window, tab->paddingObj, &padding)
    if (Ttk_GetPaddingFromObj(interp, slaveWindow, tab->paddingObj, &padding)
	    != TCL_OK)
    {
	goto error;
    }

    tab->sticky = sticky;
    tab->padding = padding;
260
261
262
263
264
265
266
267

268
269
270
271



272
273
274
275
276
277
278

279
280
281
282
283
284
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

301
302
303
304


305
306
307
308
309
310
311
312
313
314
315
316


317
318
319
320
321
322
323
324
325
326


327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
254
255
256
257
258
259
260

261
262



263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296


297
298
299
300
301
302
303
304
305
306
307
308


309
310
311
312
313
314
315
316
317
318


319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336







-
+

-
-
-
+
+
+






-
+






-
+














-
+


-
-
+
+










-
-
+
+








-
-
+
+








-
+







}

/*
 * IdentifyTab --
 * 	Return the index of the tab at point x,y,
 * 	or -1 if no tab at that point.
 */
static Tcl_Size IdentifyTab(Notebook *nb, int x, int y)
static int IdentifyTab(Notebook *nb, int x, int y)
{
    Tcl_Size index;
    for (index = 0; index < Ttk_NumberContent(nb->notebook.mgr); ++index) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr,index);
    int index;
    for (index = 0; index < Ttk_NumberSlaves(nb->notebook.mgr); ++index) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr,index);
	if (	tab->state != TAB_STATE_HIDDEN
	     && Ttk_BoxContains(tab->parcel, x,y))
	{
	    return index;
	}
    }
    return TCL_INDEX_NONE;
    return -1;
}

/*
 * ActivateTab --
 * 	Set the active tab index, redisplay if necessary.
 */
static void ActivateTab(Notebook *nb, Tcl_Size index)
static void ActivateTab(Notebook *nb, int index)
{
    if (index != nb->notebook.activeIndex) {
	nb->notebook.activeIndex = index;
	TtkRedisplayWidget(&nb->core);
    }
}

/*
 * TabState --
 * 	Return the state of the specified tab, based on
 * 	notebook state, currentIndex, activeIndex, and user-specified tab state.
 *	The USER1 bit is set for the leftmost visible tab, and USER2
 * 	is set for the rightmost visible tab.
 */
static Ttk_State TabState(Notebook *nb, Tcl_Size index)
static Ttk_State TabState(Notebook *nb, int index)
{
    Ttk_State state = nb->core.state;
    Tab *itab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    Tcl_Size i = 0;
    Tab *tab = Ttk_SlaveData(nb->notebook.mgr, index);
    int i = 0;

    if (index == nb->notebook.currentIndex) {
	state |= TTK_STATE_SELECTED;
    } else {
	state &= ~TTK_STATE_FOCUS;
    }

    if (index == nb->notebook.activeIndex) {
	state |= TTK_STATE_ACTIVE;
    }
    for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i);
    for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	if (tab->state == TAB_STATE_HIDDEN) {
	    continue;
	}
	if (index == i) {
	    state |= TTK_STATE_USER1;
	}
	break;
    }
    for (i = Ttk_NumberContent(nb->notebook.mgr) - 1; i >= 0; --i) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i);
    for (i = Ttk_NumberSlaves(nb->notebook.mgr) - 1; i >= 0; --i) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	if (tab->state == TAB_STATE_HIDDEN) {
	    continue;
	}
	if (index == i) {
	    state |= TTK_STATE_USER2;
	}
	break;
    }
    if (itab->state == TAB_STATE_DISABLED) {
    if (tab->state == TAB_STATE_DISABLED) {
	state |= TTK_STATE_DISABLED;
    }

    return state;
}

/*------------------------------------------------------------------------
357
358
359
360
361
362
363
364

365
366
367


368
369
370
371
372
373
374
351
352
353
354
355
356
357

358
359


360
361
362
363
364
365
366
367
368







-
+

-
-
+
+







 * 	(max height/width) but not parallel (total width/height).
 */
static void TabrowSize(
    Notebook *nb, Ttk_Orient orient, int minTabWidth, int *widthPtr, int *heightPtr)
{
    Ttk_Layout tabLayout = nb->notebook.tabLayout;
    int tabrowWidth = 0, tabrowHeight = 0;
    Tcl_Size i;
    int i;

    for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i);
    for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	Ttk_State tabState = TabState(nb,i);

	Ttk_RebindSublayout(tabLayout, tab);
	Ttk_LayoutSize(tabLayout,tabState,&tab->width,&tab->height);
        tab->width = MAX(tab->width, minTabWidth);

	if (orient == TTK_ORIENT_HORIZONTAL) {
384
385
386
387
388
389
390
391

392
393
394
395
396
397

398
399
400
401
402
403
404
405

406
407

408
409

410
411
412
413
414
415
416
417







418
419
420


421
422
423
424
425
426


427
428
429
430
431
432
433
378
379
380
381
382
383
384

385
386
387
388
389
390

391

392
393
394
395
396
397

398
399

400
401

402
403







404
405
406
407
408
409
410
411


412
413
414
415
416
417


418
419
420
421
422
423
424
425
426







-
+





-
+
-






-
+

-
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+




-
-
+
+







    *heightPtr = tabrowHeight;
}

/* NotebookSize -- GM and widget size hook.
 *
 * Total height is tab height + client area height + pane internal padding
 * Total width is max(client width, tab width) + pane internal padding
 * Client area size determined by max size of content windows,
 * Client area size determined by max size of slaves,
 * overridden by -width and/or -height if nonzero.
 */

static int NotebookSize(void *clientData, int *widthPtr, int *heightPtr)
{
    Notebook *nb = (Notebook *)clientData;
    Notebook *nb = clientData;
    Tk_Window nbwin = nb->core.tkwin;
    NotebookStyle nbstyle;
    Ttk_Padding padding;
    Ttk_Element clientNode = Ttk_FindElement(nb->core.layout, "client");
    int clientWidth = 0, clientHeight = 0,
    	reqWidth = 0, reqHeight = 0,
	tabrowWidth = 0, tabrowHeight = 0;
    Tcl_Size i;
    int i;

    NotebookStyleOptions(nb, &nbstyle, nbwin);
    NotebookStyleOptions(nb, &nbstyle);

    /* Compute max requested size of all content windows:
    /* Compute max requested size of all slaves:
     */
    for (i = 0; i < Ttk_NumberContent(nb->notebook.mgr); ++i) {
	Tk_Window window = Ttk_ContentWindow(nb->notebook.mgr, i);
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i);
	int width
	    = Tk_ReqWidth(window) + Ttk_PaddingWidth(tab->padding);
	int height
	    = Tk_ReqHeight(window) + Ttk_PaddingHeight(tab->padding);
    for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) {
	Tk_Window slaveWindow = Ttk_SlaveWindow(nb->notebook.mgr, i);
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	int slaveWidth
	    = Tk_ReqWidth(slaveWindow) + Ttk_PaddingWidth(tab->padding);
	int slaveHeight
	    = Tk_ReqHeight(slaveWindow) + Ttk_PaddingHeight(tab->padding);

	clientWidth = MAX(clientWidth, width);
	clientHeight = MAX(clientHeight, height);
	clientWidth = MAX(clientWidth, slaveWidth);
	clientHeight = MAX(clientHeight, slaveHeight);
    }

    /* Client width/height overridable by widget options:
     */
    Tk_GetPixelsFromObj(NULL, nb->core.tkwin, nb->notebook.widthObj,&reqWidth);
    Tk_GetPixelsFromObj(NULL, nb->core.tkwin, nb->notebook.heightObj,&reqHeight);
    Tcl_GetIntFromObj(NULL, nb->notebook.widthObj,&reqWidth);
    Tcl_GetIntFromObj(NULL, nb->notebook.heightObj,&reqHeight);
    if (reqWidth > 0)
	clientWidth = reqWidth;
    if (reqHeight > 0)
	clientHeight = reqHeight;

    /* Tab row:
     */
468
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

500
501
502
503

504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548

549
550
551
552
553
554
555
556
557

558
559
560
561
562
563
564
461
462
463
464
465
466
467

468
469
470
471
472
473
474
475
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495

496
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511
512
513
514
515

















516
517
518
519

520
521
522
523

524
525
526
527
528
529
530

531

532
533
534
535
536
537
538
539







-
+








-
+














-
+



-
+







-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+



-
+






-

-
+







 * @@@ <<NOTE-TABPOSITION>> bug: only works for horizontal orientations
 * @@@ <<NOTE-SQUEEZE-HIDDEN>> does not account for hidden tabs.
 */

static void SqueezeTabs(
    Notebook *nb, int needed, int available)
{
    int nTabs = Ttk_NumberContent(nb->notebook.mgr);
    int nTabs = Ttk_NumberSlaves(nb->notebook.mgr);

    if (nTabs > 0) {
	int difference = available - needed;
	double delta = (double)difference / needed;
	double slack = 0;
	int i;

	for (i = 0; i < nTabs; ++i) {
	    Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr,i);
	    Tab *tab = Ttk_SlaveData(nb->notebook.mgr,i);
	    double ad = slack + tab->width * delta;
	    tab->width += (int)ad;
	    slack = ad - (int)ad;
	}
    }
}

/* PlaceTabs --
 * 	Compute all tab parcels.
 */
static void PlaceTabs(
    Notebook *nb, Ttk_Box tabrowBox, Ttk_PositionSpec tabPlacement)
{
    Ttk_Layout tabLayout = nb->notebook.tabLayout;
    int nTabs = Ttk_NumberContent(nb->notebook.mgr);
    int nTabs = Ttk_NumberSlaves(nb->notebook.mgr);
    int i;

    for (i = 0; i < nTabs; ++i) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, i);
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	Ttk_State tabState = TabState(nb, i);

	if (tab->state != TAB_STATE_HIDDEN) {
	    Ttk_Padding expand = Ttk_UniformPadding(0);
	    Tcl_Obj *expandObj = Ttk_QueryOption(tabLayout,"-expand",tabState);

	    if (expandObj) {
		Ttk_GetPaddingFromObj(NULL, nb->core.tkwin, expandObj, &expand);
		Ttk_GetBorderFromObj(NULL, expandObj, &expand);
	    }

	    tab->parcel =
		Ttk_ExpandBox(
		    Ttk_PositionBox(&tabrowBox,
			tab->width, tab->height, tabPlacement),
		    expand);
	}
    }
}

/*
 * NotebookPlaceContent --
 * 	Set the position and size of a child widget
 * 	based on the current client area and content window options:
 */
static void NotebookPlaceContent(Notebook* nb, Tcl_Size index)
{
    Tab* tab = (Tab*)Ttk_ContentData(nb->notebook.mgr, index);
    Tk_Window window = Ttk_ContentWindow(nb->notebook.mgr, index);
    Ttk_Box box =
	Ttk_StickBox(Ttk_PadBox(nb->notebook.clientArea, tab->padding),
	    Tk_ReqWidth(window), Tk_ReqHeight(window), tab->sticky);

    Ttk_PlaceContent(nb->notebook.mgr, index,
	box.x, box.y, box.width, box.height);
}

/* NotebookDoLayout --
 *	Computes notebook layout and places tabs.
 *
 * Side effects:
 * 	Sets clientArea, used to place panes.
 * 	Sets clientArea, used to place slave panes.
 */
static void NotebookDoLayout(void *recordPtr)
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Tk_Window nbwin = nb->core.tkwin;
    Ttk_Box cavity = Ttk_WinBox(nbwin);
    int tabrowWidth = 0, tabrowHeight = 0;
    Ttk_Element clientNode = Ttk_FindElement(nb->core.layout, "client");
    Ttk_Box tabrowBox;
    NotebookStyle nbstyle;
    Tcl_Size currentIndex = nb->notebook.currentIndex;

    NotebookStyleOptions(nb, &nbstyle, nbwin);
    NotebookStyleOptions(nb, &nbstyle);

    /* Notebook internal padding:
     */
    cavity = Ttk_PadBox(cavity, nbstyle.padding);

    /* Layout for notebook background (base layout):
     */
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603




















604
605
606

607
608
609


610
611
612

613
614
615
616
617
618
619
620

621
622
623


624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640

641
642
643
644
645


646
647
648
649
650
651

652
653
654
655
656
657
658
659
660
661
662


663
664
665
666
667

668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697


698
699
700

701
702
703

704
705
706
707
708
709
710
711

712
713

714
715

716
717
718


719
720
721
722
723
724
725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741
742
743
744
745
746
747
748


749
750
751

752
753
754
755

756
757

758
759
760
761
762
763
764
765

766
767
768
769

770
771
772
773
774

775
776
777
778
779
780

781
782
783
784
785
786
787
788


789
790

791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807

808
809

810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843

844
845
846
847
848

849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864

865
866

867
868
869
870
871
872
873
874
875
876

877
878

879
880
881
882
883
884
885
886
887
888
889

890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915

916
917
918
919




920
921
922
923
924
925
926
927
928


929
930
931

932
933
934


935
936
937

938
939
940
941

942
943
944
945
946
947
948
949
950
951
952
953
954

955
956
957
958
959




960
961
962

963
964
965


966

967
968
969
970
971
972

973
974

975
976
977

978
979
980
981
982
983



984
985

986
987
988
989
990
991
992
993

994
995
996
997


998
999
1000
1001
1002
1003
1004


1005
1006

1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031


1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055


1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070

1071
1072


1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

1083
1084

1085
1086
1087

1088
1089

1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142

1143
1144

1145
1146
1147
1148
1149
1150









1151
1152

1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168

1169
1170
1171
1172

1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195

1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1206
1207


1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218

1219
1220

1221
1222
1223


1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236


1237
1238
1239
1240

1241
1242
1243

1244
1245
1246

1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1294
1295


1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
563
564
565
566
567
568
569


570







571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593
594


595
596
597
598

599
600
601
602
603
604
605
606

607
608


609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

627
628
629



630
631
632


633
634

635
636
637
638
639
640
641
642
643
644


645
646
647
648
649
650

651
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679


680
681
682
683

684
685
686

687
688
689
690
691
692
693
694

695
696

697
698

699
700


701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716

717




718
719
720
721
722
723
724
725
726


727
728
729
730

731
732
733
734

735
736

737
738
739
740
741
742
743
744

745
746
747
748

749
750
751
752
753

754
755
756
757
758
759

760
761
762
763
764
765
766


767
768
769

770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786

787
788

789
790
791
792
793
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
820
821
822

823
824
825
826
827

828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843

844
845

846
847
848
849
850






851


852
853
854
855
856
857
858
859
860
861
862

863
864
865






866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882

883
884



885
886
887
888
889
890
891
892
893
894
895


896
897
898
899

900
901


902
903
904
905

906
907
908
909

910
911
912
913
914
915
916
917
918
919
920
921
922

923
924




925
926
927
928
929
930

931
932
933
934
935
936

937
938
939
940
941
942

943
944

945
946
947

948
949
950
951



952
953
954
955

956
957
958
959


960
961

962
963
964


965
966
967
968
969
970
971


972
973
974

975
976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996

997
998


999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022


1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040


1041
1042

1043
1044
1045
1046
1047
1048
1049
1050

1051
1052

1053
1054
1055

1056
1057

1058

1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109

1110


1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

1128


1129

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141

1142
1143
1144
1145

1146
1147
1148
1149
1150
1151


1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167

1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
1178


1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192

1193
1194


1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207


1208
1209
1210
1211
1212

1213
1214
1215

1216
1217
1218

1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236

1237
1238
1239
1240
1241
1242
1243
1244
1245
1246

1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257

1258
1259
1260
1261
1262
1263
1264
1265


1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277

1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1294







-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+

-
-
+
+


-
+







-
+

-
-
+
+
















-
+


-
-
-
+
+

-
-


-
+









-
-
+
+




-
+








-
+



















-
-
+
+


-
+


-
+







-
+

-
+

-
+

-
-
+
+














-
+
-
-
-
-









-
-
+
+


-
+



-
+

-
+







-
+



-
+




-
+





-
+






-
-
+
+

-
+
















-
+

-
+





-
+

















-
+









-
+




-
+















-
+

-
+




-
-
-
-
-
-
+
-
-
+










-
+


-
-
-
-
-
-

















-
+

-
-
-
+
+
+
+







-
-
+
+


-
+

-
-
+
+


-
+



-
+












-
+

-
-
-
-
+
+
+
+


-
+



+
+
-
+





-
+

-
+


-
+



-
-
-
+
+
+

-
+



-
-


-
+


-
-
+
+





-
-
+
+

-
+



-
+

















-
+

-
-
+
+










-
+









-
+

-
-
+
+











-
+



+
-
-
+
+
-








-
+

-
+


-
+

-
+
-






-
+









-
+



















-
+












-
+

-
+
-
-
+






+
+
+
+
+
+
+
+
+

-
+
-
-
+
-










-
+

-
+



-
+





-
-
+













-
+

-
+


-
+







-
-
+
+










-
+

-
+

-
-
+
+











-
-
+
+



-
+


-
+


-
+

















-

+








-











-
+







-
-
+
+










-
+








-
+







	Ttk_PlaceElement(nb->core.layout, clientNode, cavity);
	cavity = Ttk_LayoutNodeInternalParcel(nb->core.layout, clientNode);
    }

    if (cavity.height <= 0) cavity.height = 1;
    if (cavity.width <= 0) cavity.width = 1;

    if (!TtkBoxEqual(nb->notebook.clientArea, cavity)) {
	nb->notebook.clientArea = cavity;
    nb->notebook.clientArea = cavity;
	if (currentIndex >= 0) {
	    NotebookPlaceContent(nb, currentIndex);
	}
    }
}

/* NotebookPlaceContents --
}

/*
 * NotebookPlaceSlave --
 * 	Set the position and size of a child widget
 * 	based on the current client area and slave options:
 */
static void NotebookPlaceSlave(Notebook *nb, int slaveIndex)
{
    Tab *tab = Ttk_SlaveData(nb->notebook.mgr, slaveIndex);
    Tk_Window slaveWindow = Ttk_SlaveWindow(nb->notebook.mgr, slaveIndex);
    Ttk_Box slaveBox =
	Ttk_StickBox(Ttk_PadBox(nb->notebook.clientArea, tab->padding),
	    Tk_ReqWidth(slaveWindow), Tk_ReqHeight(slaveWindow),tab->sticky);

    Ttk_PlaceSlave(nb->notebook.mgr, slaveIndex,
	slaveBox.x, slaveBox.y, slaveBox.width, slaveBox.height);
}

/* NotebookPlaceSlaves --
 * 	Geometry manager hook.
 */
static void NotebookPlaceContents(void *recordPtr)
static void NotebookPlaceSlaves(void *recordPtr)
{
    Notebook *nb = (Notebook *)recordPtr;
    Tcl_Size currentIndex = nb->notebook.currentIndex;
    Notebook *nb = recordPtr;
    int currentIndex = nb->notebook.currentIndex;
    if (currentIndex >= 0) {
	NotebookDoLayout(nb);
	NotebookPlaceContent(nb, currentIndex);
	NotebookPlaceSlave(nb, currentIndex);
    }
}

/*
 * SelectTab(nb, index) --
 * 	Change the currently-selected tab.
 */
static void SelectTab(Notebook *nb, Tcl_Size index)
static void SelectTab(Notebook *nb, int index)
{
    Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    Tcl_Size currentIndex = nb->notebook.currentIndex;
    Tab *tab = Ttk_SlaveData(nb->notebook.mgr,index);
    int currentIndex = nb->notebook.currentIndex;

    if (index == currentIndex) {
	return;
    }

    if (TabState(nb, index) & TTK_STATE_DISABLED) {
	return;
    }

    /* Unhide the tab if it is currently hidden and being selected.
     */
    if (tab->state == TAB_STATE_HIDDEN) {
	tab->state = TAB_STATE_NORMAL;
    }

    if (currentIndex >= 0) {
	Ttk_UnmapContent(nb->notebook.mgr, currentIndex);
	Ttk_UnmapSlave(nb->notebook.mgr, currentIndex);
    }

    /* Must be set before calling NotebookPlaceContent(), otherwise it may
     * happen that NotebookPlaceContents(), triggered by an interveaning
     * geometry request, will swap to old index. */
    NotebookPlaceSlave(nb, index);

    nb->notebook.currentIndex = index;

    NotebookPlaceContent(nb, index);
    TtkRedisplayWidget(&nb->core);

    Tk_SendVirtualEvent(nb->core.tkwin, "NotebookTabChanged", NULL);
    TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged");
}

/* NextTab --
 * 	Returns the index of the next tab after the specified tab
 * 	in the normal state (e.g., not hidden or disabled),
 * 	or -1 if all tabs are disabled or hidden.
 */
static int NextTab(Notebook *nb, int index)
{
    Tcl_Size nTabs = Ttk_NumberContent(nb->notebook.mgr);
    Tcl_Size nextIndex;
    int nTabs = Ttk_NumberSlaves(nb->notebook.mgr);
    int nextIndex;

    /* Scan forward for following usable tab:
     */
    for (nextIndex = index + 1; nextIndex < nTabs; ++nextIndex) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, nextIndex);
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, nextIndex);
	if (tab->state == TAB_STATE_NORMAL) {
	    return nextIndex;
	}
    }

    /* Not found -- scan backwards.
     */
    for (nextIndex = index - 1; nextIndex >= 0; --nextIndex) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, nextIndex);
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, nextIndex);
	if (tab->state == TAB_STATE_NORMAL) {
	    return nextIndex;
	}
    }

    /* Still nothing.  Give up.
     */
    return -1;
}

/* SelectNearestTab --
 * 	Handles the case where the current tab is forgotten, hidden,
 * 	or destroyed.
 *
 * 	Unmap the current tab and schedule the next available one
 * 	to be mapped at the next GM update.
 */
static void SelectNearestTab(Notebook *nb)
{
    Tcl_Size currentIndex = nb->notebook.currentIndex;
    Tcl_Size nextIndex = NextTab(nb, currentIndex);
    int currentIndex = nb->notebook.currentIndex;
    int nextIndex = NextTab(nb, currentIndex);

    if (currentIndex >= 0) {
	Ttk_UnmapContent(nb->notebook.mgr, currentIndex);
	Ttk_UnmapSlave(nb->notebook.mgr, currentIndex);
    }
    if (currentIndex != nextIndex) {
	Tk_SendVirtualEvent(nb->core.tkwin, "NotebookTabChanged", NULL);
	TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged");
    }

    nb->notebook.currentIndex = nextIndex;
    Ttk_ManagerLayoutChanged(nb->notebook.mgr);
    TtkRedisplayWidget(&nb->core);
}

/* TabRemoved -- GM TabRemoved hook.
/* TabRemoved -- GM SlaveRemoved hook.
 * 	Select the next tab if the current one is being removed.
 * 	Adjust currentIndex to account for removed content window.
 * 	Adjust currentIndex to account for removed slave.
 */
static void TabRemoved(void *managerData, Tcl_Size index)
static void TabRemoved(void *managerData, int index)
{
    Notebook *nb = (Notebook *)managerData;
    Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    Notebook *nb = managerData;
    Tab *tab = Ttk_SlaveData(nb->notebook.mgr, index);

    if (index == nb->notebook.currentIndex) {
	SelectNearestTab(nb);
    }

    if (index < nb->notebook.currentIndex) {
	--nb->notebook.currentIndex;
    }

    DestroyTab(nb, tab);

    TtkRedisplayWidget(&nb->core);
}

static int TabRequest(
static int TabRequest(void *managerData, int index, int width, int height)
    TCL_UNUSED(void *), /* managerData */
    TCL_UNUSED(Tcl_Size), /* index */
    TCL_UNUSED(int), /* width */
    TCL_UNUSED(int)) /* height */
{
    return 1;
}

/* AddTab --
 * 	Add new tab at specified index.
 */
static int AddTab(
    Tcl_Interp *interp, Notebook *nb,
    Tcl_Size destIndex, Tk_Window window,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int destIndex, Tk_Window slaveWindow,
    int objc, Tcl_Obj *const objv[])
{
    Tab *tab;
    if (!Ttk_Maintainable(interp, window, nb->core.tkwin)) {
    if (!Ttk_Maintainable(interp, slaveWindow, nb->core.tkwin)) {
	return TCL_ERROR;
    }
#if 0 /* can't happen */
    if (Ttk_ContentIndex(nb->notebook.mgr, window) >= 0) {
    if (Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow) >= 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s already added",
	    Tk_PathName(window)));
	    Tk_PathName(slaveWindow)));
	Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "PRESENT", NULL);
	return TCL_ERROR;
    }
#endif

    /* Create and insert tab.
     */
    tab = CreateTab(interp, nb, window);
    tab = CreateTab(interp, nb, slaveWindow);
    if (!tab) {
	return TCL_ERROR;
    }
    if (ConfigureTab(interp, nb, tab, window, objc, objv) != TCL_OK) {
    if (ConfigureTab(interp, nb, tab, slaveWindow, objc, objv) != TCL_OK) {
	DestroyTab(nb, tab);
	return TCL_ERROR;
    }

    Ttk_InsertContent(nb->notebook.mgr, destIndex, window, tab);
    Ttk_InsertSlave(nb->notebook.mgr, destIndex, slaveWindow, tab);

    /* Adjust indices and/or autoselect first tab:
     */
    if (nb->notebook.currentIndex < 0) {
	SelectTab(nb, destIndex);
    } else if (nb->notebook.currentIndex  >= destIndex) {
    } else if (nb->notebook.currentIndex >= destIndex) {
	++nb->notebook.currentIndex;
    }

    return TCL_OK;
}

static const Ttk_ManagerSpec NotebookManagerSpec = {
    { "notebook", Ttk_GeometryRequestProc, Ttk_LostContentProc },
static Ttk_ManagerSpec NotebookManagerSpec = {
    { "notebook", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
    NotebookSize,
    NotebookPlaceContents,
    NotebookPlaceSlaves,
    TabRequest,
    TabRemoved
};

/*------------------------------------------------------------------------
 * +++ Event handlers.
 */

/* NotebookEventHandler --
 * 	Tracks the active tab.
 */
static const int NotebookEventMask
    = StructureNotifyMask
    | PointerMotionMask
    | LeaveWindowMask
    ;
static void NotebookEventHandler(void *clientData, XEvent *eventPtr)
static void NotebookEventHandler(ClientData clientData, XEvent *eventPtr)
{
    Notebook *nb = (Notebook *)clientData;
    Notebook *nb = clientData;

    if (eventPtr->type == DestroyNotify) { /* Remove self */
	Tk_DeleteEventHandler(nb->core.tkwin,
	    NotebookEventMask, NotebookEventHandler, clientData);
    } else if (eventPtr->type == MotionNotify) {
	Tcl_Size index = IdentifyTab(nb, eventPtr->xmotion.x, eventPtr->xmotion.y);
	int index = IdentifyTab(nb, eventPtr->xmotion.x, eventPtr->xmotion.y);
	ActivateTab(nb, index);
    } else if (eventPtr->type == LeaveNotify) {
	ActivateTab(nb, -1);
    }
}

/*------------------------------------------------------------------------
 * +++ Utilities.
 */

/* FindTabIndex --
 *	Find the index of the specified tab.
 *	Tab identifiers are one of:
 *
 *	+ positional specifications @x,y,
 *	+ "current",
 *	+ numeric indices [0..nTabs],
 *	+ content window names
 *	+ slave window names
 *
 *	Stores index of specified tab in *index_rtn, -1 if not found.
 *
 *	Returns TCL_ERROR and leaves an error message in interp->result
 *	if the tab identifier was incorrect.
 *
 *	See also: GetTabIndex.
 */
static int FindTabIndex(
    Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, Tcl_Size *index_rtn)
    Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, int *index_rtn)
{
    const char *string = Tcl_GetString(objPtr);
    int x, y;

    *index_rtn = TCL_INDEX_NONE;
    *index_rtn = -1;

    /* Check for @x,y ...
     */
    if (string[0] == '@' && sscanf(string, "@%d,%d",&x,&y) == 2) {
	*index_rtn = IdentifyTab(nb, x, y);
	return TCL_OK;
    }

    /* ... or "current" ...
     */
    if (!strcmp(string, "current")) {
	*index_rtn = nb->notebook.currentIndex;
	return TCL_OK;
    }

    /* ... or integer index or content window name:
    /* ... or integer index or slave window name:
     */
    if (Ttk_GetContentIndexFromObj(
    if (Ttk_GetSlaveIndexFromObj(
	    interp, nb->notebook.mgr, objPtr, index_rtn) == TCL_OK)
    {
	return TCL_OK;
    }
    if (*index_rtn == Ttk_NumberContent(nb->notebook.mgr)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Invalid tab specification %s", string));
	Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "SPEC", NULL);
	return TCL_ERROR;
    }


    /* Nothing matched; Ttk_GetContentIndexFromObj will have left error message.
    /* Nothing matched; Ttk_GetSlaveIndexFromObj will have left error message.
     */
    return TCL_ERROR;
}

/* GetTabIndex --
 * 	Get the index of an existing tab.
 * 	Tab identifiers are as per FindTabIndex.
 * 	Returns TCL_ERROR if the tab does not exist.
 */
static int GetTabIndex(
    Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, Tcl_Size *index_rtn)
    Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, int *index_rtn)
{
    int status = FindTabIndex(interp, nb, objPtr, index_rtn);
	if (status == TCL_OK && *index_rtn  >= Ttk_NumberContent(nb->notebook.mgr)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"tab index %s out of bounds", Tcl_GetString(objPtr)));
	    Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "INDEX", NULL);
	    return TCL_ERROR;
	}

    if (status == TCL_OK && *index_rtn < 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "tab '%s' not found", Tcl_GetString(objPtr)));
	Tcl_SetErrorCode(interp, "TTK", "NOTEBOOK", "TAB", NULL);
	status = TCL_ERROR;
    }
    return status;
}

/*------------------------------------------------------------------------
 * +++ Widget command routines.
 */

/* $nb add window ?options ... ?
 */
static int NotebookAddCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Tk_Window window;
    Tcl_Size index;
    Notebook *nb = recordPtr;
    int index = Ttk_NumberSlaves(nb->notebook.mgr);
    Tk_Window slaveWindow;
    int slaveIndex;
    Tab *tab;

    if (objc <= 2 || objc % 2 != 1) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?-option value ...?");
	return TCL_ERROR;
    }

    window = Tk_NameToWindow(interp,Tcl_GetString(objv[2]),nb->core.tkwin);
    if (!window) {
    slaveWindow = Tk_NameToWindow(interp,Tcl_GetString(objv[2]),nb->core.tkwin);
    if (!slaveWindow) {
	return TCL_ERROR;
    }
    index = Ttk_ContentIndex(nb->notebook.mgr, window);
    slaveIndex = Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow);

    if (index < 0) { /* New tab */
	return AddTab(interp, nb, Ttk_NumberContent(nb->notebook.mgr), window, objc-3,objv+3);
    if (slaveIndex < 0) { /* New tab */
	return AddTab(interp, nb, index, slaveWindow, objc-3,objv+3);
    }

    tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    tab = Ttk_SlaveData(nb->notebook.mgr, slaveIndex);
    if (tab->state == TAB_STATE_HIDDEN) {
	tab->state = TAB_STATE_NORMAL;
    }
    if (ConfigureTab(interp, nb, tab, window, objc-3,objv+3) != TCL_OK) {
    if (ConfigureTab(interp, nb, tab, slaveWindow, objc-3,objv+3) != TCL_OK) {
	return TCL_ERROR;
    }

    TtkRedisplayWidget(&nb->core);

    return TCL_OK;
}

/* $nb insert $index $tab ?-option value ...?
 * 	Insert new tab, or move existing one.
 */
static int NotebookInsertCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Tcl_Size current = nb->notebook.currentIndex;
    Tcl_Size nContent = Ttk_NumberContent(nb->notebook.mgr);
    Tcl_Size srcIndex, destIndex;
    Notebook *nb = recordPtr;
    int current = nb->notebook.currentIndex;
    int nSlaves = Ttk_NumberSlaves(nb->notebook.mgr);
    int srcIndex, destIndex;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2,objv, "index window ?-option value ...?");
	Tcl_WrongNumArgs(interp, 2,objv, "index slave ?-option value ...?");
	return TCL_ERROR;
    }

    if (!strcmp(Tcl_GetString(objv[2]), "end")) {
	destIndex = Ttk_NumberSlaves(nb->notebook.mgr);
    if (TCL_OK != Ttk_GetContentIndexFromObj(
    } else if (TCL_OK != Ttk_GetSlaveIndexFromObj(
		interp, nb->notebook.mgr, objv[2], &destIndex)) {
	return TCL_ERROR;
    }

    if (Tcl_GetString(objv[3])[0] == '.') {
	/* Window name -- could be new or existing content window.
	/* Window name -- could be new or existing slave.
	 */
	Tk_Window window =
	Tk_Window slaveWindow =
	    Tk_NameToWindow(interp,Tcl_GetString(objv[3]),nb->core.tkwin);

	if (!window) {
	if (!slaveWindow) {
	    return TCL_ERROR;
	}

	srcIndex = Ttk_ContentIndex(nb->notebook.mgr, window);
	if (srcIndex < 0) {	/* New content window */
	    return AddTab(interp, nb, destIndex, window, objc-4,objv+4);
	srcIndex = Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow);
	if (srcIndex < 0) {	/* New slave */
	    return AddTab(interp, nb, destIndex, slaveWindow, objc-4,objv+4);
	}
    } else if (Ttk_GetContentIndexFromObj(
    } else if (Ttk_GetSlaveIndexFromObj(
		interp, nb->notebook.mgr, objv[3], &srcIndex) != TCL_OK)
    {
	return TCL_ERROR;
    } else if (srcIndex  >= Ttk_NumberContent(nb->notebook.mgr)) {
	srcIndex = Ttk_NumberContent(nb->notebook.mgr) - 1;
    }

    /* Move existing content window:
    /* Move existing slave:
     */
    if (ConfigureTab(interp, nb,
	     (Tab *)Ttk_ContentData(nb->notebook.mgr, srcIndex),
		 Ttk_ContentWindow(nb->notebook.mgr, srcIndex),
	     Ttk_SlaveData(nb->notebook.mgr,srcIndex),
	     Ttk_SlaveWindow(nb->notebook.mgr,srcIndex),
	     objc-4,objv+4) != TCL_OK)
    {
	return TCL_ERROR;
    }

    if (destIndex  >= nContent) {
	destIndex  = nContent - 1;
    if (destIndex >= nSlaves) {
	destIndex  = nSlaves - 1;
    }
    Ttk_ReorderContent(nb->notebook.mgr, srcIndex, destIndex);
    Ttk_ReorderSlave(nb->notebook.mgr, srcIndex, destIndex);

    /* Adjust internal indexes:
     */
    nb->notebook.activeIndex = TCL_INDEX_NONE;
    nb->notebook.activeIndex = -1;
    if (current == srcIndex) {
	nb->notebook.currentIndex = destIndex;
    } else if (destIndex <= current && current < srcIndex) {
	++nb->notebook.currentIndex;
    } else if (srcIndex < current && current <= destIndex) {
	--nb->notebook.currentIndex;
    }

    TtkRedisplayWidget(&nb->core);

    return TCL_OK;
}

/* $nb forget $tab --
 * 	Removes the specified tab.
 */
static int NotebookForgetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Tcl_Size index;
    Notebook *nb = recordPtr;
    int index;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "tab");
	return TCL_ERROR;
    }

    if (GetTabIndex(interp, nb, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
    }

    Ttk_ForgetContent(nb->notebook.mgr, index);
    Ttk_ForgetSlave(nb->notebook.mgr, index);
    TtkRedisplayWidget(&nb->core);

    return TCL_OK;
}

/* $nb hide $tab --
 * 	Hides the specified tab.
 */
static int NotebookHideCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Tcl_Size index;
    Notebook *nb = recordPtr;
    int index;
    Tab *tab;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "tab");
	return TCL_ERROR;
    }

    if (GetTabIndex(interp, nb, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
    }

    tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    tab = Ttk_SlaveData(nb->notebook.mgr, index);
    tab->state = TAB_STATE_HIDDEN;
    if (index == nb->notebook.currentIndex) {
	SelectNearestTab(nb);
    }
    } else {
        TtkRedisplayWidget(&nb->core);

    TtkRedisplayWidget(&nb->core);
    }

    return TCL_OK;
}

/* $nb identify $x $y --
 * 	Returns name of tab element at $x,$y; empty string if none.
 */
static int NotebookIdentifyCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    static const char *const whatTable[] = { "element", "tab", NULL };
    static const char *whatTable[] = { "element", "tab", NULL };
    enum { IDENTIFY_ELEMENT, IDENTIFY_TAB };
    int what = IDENTIFY_ELEMENT;
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Ttk_Element element = NULL;
    int x, y;
    int x, y, tabIndex;
    Tcl_Size tabIndex;

    if (objc < 4 || objc > 5) {
	Tcl_WrongNumArgs(interp, 2,objv, "?what? x y");
	return TCL_ERROR;
    }

    if (Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
    if (   Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
	|| Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK
	|| (objc == 5 && Tcl_GetIndexFromObjStruct(interp, objv[2], whatTable,
		sizeof(char *), "option", 0, &what) != TCL_OK)
    ) {
	return TCL_ERROR;
    }

    tabIndex = IdentifyTab(nb, x, y);
    if (tabIndex >= 0) {
	Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, tabIndex);
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, tabIndex);
	Ttk_State state = TabState(nb, tabIndex);
	Ttk_Layout tabLayout = nb->notebook.tabLayout;

	Ttk_RebindSublayout(tabLayout, tab);
	Ttk_PlaceLayout(tabLayout, state, tab->parcel);

	element = Ttk_IdentifyElement(tabLayout, x, y);
    }

    switch (what) {
	case IDENTIFY_ELEMENT:
	    if (element) {
		const char *elementName = Ttk_ElementName(element);

		Tcl_SetObjResult(interp, Tcl_NewStringObj(elementName, -1));
	    }
	    break;
	case IDENTIFY_TAB:
	    if (tabIndex >= 0) {
		Tcl_SetObjResult(interp, TkNewIndexObj(tabIndex));
		Tcl_SetObjResult(interp, Tcl_NewIntObj(tabIndex));
	    }
	    break;
    }
    return TCL_OK;
}

/* $nb index $item --
 * 	Returns the integer index of the tab specified by $item,
 * 	the empty string if $item does not identify a tab.
 *	See above for valid item formats.
 */
static int NotebookIndexCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Tcl_Size index;
    int status;
    int index, status;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "tab");
	return TCL_ERROR;
    }

    /*
     * Special-case for "end":
     */
    if (!strcmp("end", Tcl_GetString(objv[2]))) {
	int nSlaves = Ttk_NumberSlaves(nb->notebook.mgr);
	Tcl_SetObjResult(interp, Tcl_NewIntObj(nSlaves));
	return TCL_OK;
    }

    status = FindTabIndex(interp, nb, objv[2], &index);
	if (status == TCL_OK) {
    if (status == TCL_OK && index >= 0) {
	if (index >= 0) {
	    Tcl_SetObjResult(interp, TkNewIndexObj(index));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
	}
    }

    return status;
}

/* $nb select ?$item? --
 * 	Select the specified tab, or return the widget path of
 * 	the currently-selected pane.
 */
static int NotebookSelectCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;

    if (objc == 2) {
	if (nb->notebook.currentIndex >= 0) {
	    Tk_Window pane = Ttk_ContentWindow(
	    Tk_Window pane = Ttk_SlaveWindow(
		nb->notebook.mgr, nb->notebook.currentIndex);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(pane), -1));
	}
	return TCL_OK;
    } else if (objc == 3) {
	Tcl_Size index;
	int status = GetTabIndex(interp, nb, objv[2], &index);
	int index, status = GetTabIndex(interp, nb, objv[2], &index);
	if (status == TCL_OK) {
	    SelectTab(nb, index);
	}
	return status;
    } /*else*/
    Tcl_WrongNumArgs(interp, 2, objv, "?tab?");
    return TCL_ERROR;
}

/* $nb tabs --
 * 	Return list of tabs.
 */
static int NotebookTabsCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Ttk_Manager *mgr = nb->notebook.mgr;
    Tcl_Obj *result;
    Tcl_Size i;
    int i;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "");
	return TCL_ERROR;
    }

    result = Tcl_NewListObj(0, NULL);
    for (i = 0; i < Ttk_NumberContent(mgr); ++i) {
	const char *pathName = Tk_PathName(Ttk_ContentWindow(mgr,i));
    for (i = 0; i < Ttk_NumberSlaves(mgr); ++i) {
	const char *pathName = Tk_PathName(Ttk_SlaveWindow(mgr,i));

	Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj(pathName,-1));
    }
    Tcl_SetObjResult(interp, result);
    return TCL_OK;
}

/* $nb tab $tab ?-option ?value -option value...??
 */
static int NotebookTabCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Ttk_Manager *mgr = nb->notebook.mgr;
    Tcl_Size index;
    Tk_Window window;
    int index;
    Tk_Window slaveWindow;
    Tab *tab;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "tab ?-option ?value??...");
	return TCL_ERROR;
    }

    if (GetTabIndex(interp, nb, objv[2], &index) != TCL_OK) {
	return TCL_ERROR;
    }

    tab = (Tab *)Ttk_ContentData(mgr, index);
    window = Ttk_ContentWindow(mgr, index);
    tab = Ttk_SlaveData(mgr, index);
    slaveWindow = Ttk_SlaveWindow(mgr, index);

    if (objc == 3) {
	return TtkEnumerateOptions(interp, tab,
	    PaneOptionSpecs, nb->notebook.paneOptionTable, window);
	    PaneOptionSpecs, nb->notebook.paneOptionTable, slaveWindow);
    } else if (objc == 4) {
	return TtkGetOptionValue(interp, tab, objv[3],
	    nb->notebook.paneOptionTable, window);
	    nb->notebook.paneOptionTable, slaveWindow);
    } /* else */

    if (ConfigureTab(interp, nb, tab, window, objc-3,objv+3) != TCL_OK) {
    if (ConfigureTab(interp, nb, tab, slaveWindow, objc-3,objv+3) != TCL_OK) {
	return TCL_ERROR;
    }

    /* If the current tab has become disabled or hidden,
     * select the next nondisabled, unhidden one:
     */
    if (index == nb->notebook.currentIndex && tab->state != TAB_STATE_NORMAL) {
	SelectNearestTab(nb);
    }

    return TCL_OK;
}

/* Subcommand table:
 */
static const Ttk_Ensemble NotebookCommands[] = {
    { "add",    	NotebookAddCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "forget",		NotebookForgetCommand,0 },
    { "hide",		NotebookHideCommand,0 },
    { "identify",	NotebookIdentifyCommand,0 },
    { "index",		NotebookIndexCommand,0 },
    { "insert",  	NotebookInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "select",		NotebookSelectCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "tab",   		NotebookTabCommand,0 },
    { "tabs",   	NotebookTabsCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Widget class hooks.
 */

static void NotebookInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;

    nb->notebook.mgr = Ttk_CreateManager(
	    &NotebookManagerSpec, recordPtr, nb->core.tkwin);

    nb->notebook.tabOptionTable = Tk_CreateOptionTable(interp,TabOptionSpecs);
    nb->notebook.paneOptionTable = Tk_CreateOptionTable(interp,PaneOptionSpecs);

    nb->notebook.currentIndex = TCL_INDEX_NONE;
    nb->notebook.activeIndex = TCL_INDEX_NONE;
    nb->notebook.currentIndex = -1;
    nb->notebook.activeIndex = -1;
    nb->notebook.tabLayout = 0;

    nb->notebook.clientArea = Ttk_MakeBox(0,0,1,1);

    Tk_CreateEventHandler(
	nb->core.tkwin, NotebookEventMask, NotebookEventHandler, recordPtr);
}

static void NotebookCleanup(void *recordPtr)
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;

    Ttk_DeleteManager(nb->notebook.mgr);
    if (nb->notebook.tabLayout)
	Ttk_FreeLayout(nb->notebook.tabLayout);
}

static int NotebookConfigure(Tcl_Interp *interp, void *clientData, int mask)
{
    Notebook *nb = (Notebook *)clientData;
    Notebook *nb = clientData;

    /*
     * Error-checks:
     */
    if (nb->notebook.paddingObj) {
	/* Check for valid -padding: */
	Ttk_Padding unused;
1332
1333
1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344
1345
1346
1304
1305
1306
1307
1308
1309
1310

1311
1312
1313
1314
1315
1316
1317
1318







-
+








/* NotebookGetLayout  --
 * 	GetLayout widget hook.
 */
static Ttk_Layout NotebookGetLayout(
    Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Notebook *nb = (Notebook *)recordPtr;
    Notebook *nb = recordPtr;
    Ttk_Layout notebookLayout = TtkWidgetGetLayout(interp, theme, recordPtr);
    Ttk_Layout tabLayout;

    if (!notebookLayout) {
	return NULL;
    }

1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381



1382
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404

1405
1406
1407
1408
1409
1410
1411
1332
1333
1334
1335
1336
1337
1338

1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350



1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375

1376
1377
1378
1379
1380
1381
1382
1383







-
+











-
-
-
+
+
+








-
+













-
+







/*------------------------------------------------------------------------
 * +++ Display routines.
 */

static void DisplayTab(Notebook *nb, int index, Drawable d)
{
    Ttk_Layout tabLayout = nb->notebook.tabLayout;
    Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index);
    Tab *tab = Ttk_SlaveData(nb->notebook.mgr, index);
    Ttk_State state = TabState(nb, index);

    if (tab->state != TAB_STATE_HIDDEN) {
	Ttk_RebindSublayout(tabLayout, tab);
	Ttk_PlaceLayout(tabLayout, state, tab->parcel);
	Ttk_DrawLayout(tabLayout, state, d);
    }
}

static void NotebookDisplay(void *clientData, Drawable d)
{
    Notebook *nb = (Notebook *)clientData;
    Tcl_Size nContent = Ttk_NumberContent(nb->notebook.mgr);
    Tcl_Size index;
    Notebook *nb = clientData;
    int nSlaves = Ttk_NumberSlaves(nb->notebook.mgr);
    int index;

    /* Draw notebook background (base layout):
     */
    Ttk_DrawLayout(nb->core.layout, nb->core.state, d);

    /* Draw tabs from left to right, but draw the current tab last
     * so it will overwrite its neighbors.
     */
    for (index = 0; index < nContent; ++index) {
    for (index = 0; index < nSlaves; ++index) {
	if (index != nb->notebook.currentIndex) {
	    DisplayTab(nb, index, d);
	}
    }
    if (nb->notebook.currentIndex >= 0) {
	DisplayTab(nb, nb->notebook.currentIndex, d);
    }
}

/*------------------------------------------------------------------------
 * +++ Widget specification and layout definitions.
 */

static const WidgetSpec NotebookWidgetSpec =
static WidgetSpec NotebookWidgetSpec =
{
    "TNotebook",		/* className */
    sizeof(Notebook),		/* recordSize */
    NotebookOptionSpecs,	/* optionSpecs */
    NotebookCommands,		/* subcommands */
    NotebookInitialize,		/* initializeProc */
    NotebookCleanup,		/* cleanupProc */
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1400
1401
1402
1403
1404
1405
1406



1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418







-
-
-












		TTK_NODE("Notebook.label", TTK_PACK_TOP))))
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * +++ Initialization.
 */

MODULE_SCOPE
void TtkNotebook_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkNotebook_Init(Tcl_Interp *interp)
{
    Ttk_Theme themePtr = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(themePtr, "Tab", TabLayout);
    Ttk_RegisterLayout(themePtr, "TNotebook", NotebookLayout);

    RegisterWidget(interp, "ttk::notebook", &NotebookWidgetSpec);
}

/*EOF*/

Changes to generic/ttk/ttkPanedwindow.c.

1
2

3
4
5
6
7
8

9

10
11
12
13
14
15
16
1

2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17

-
+






+
-
+







/*
 * Copyright © 2005 Joe English.  Freely redistributable.
 * Copyright (c) 2005, Joe English.  Freely redistributable.
 *
 * ttk::panedwindow widget implementation.
 *
 * TODO: track active/pressed sash.
 */

#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include "ttkManager.h"
#include "ttkTheme.h"
#include "ttkWidget.h"

/*------------------------------------------------------------------------
 * +++ Layout algorithm.
 *
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39







-
+







 * When resizing, sash positions are computed from the request sizes,
 * the available space, and pane weights (see PlaceSashes()).
 * This ensures continuous resize behavior (that is: changing
 * the size by X pixels then changing the size by Y pixels
 * gives the same result as changing the size by X+Y pixels
 * in one step).
 *
 * The request size is initially set to the content window's requested size.
 * The request size is initially set to the slave window's requested size.
 * When the user drags a sash, each pane's request size is set to its
 * actual size.  This ensures that panes "stay put" on the next resize.
 *
 * If reqSize == 0, use 0 for the weight as well.  This ensures that
 * "collapsed" panes stay collapsed during a resize, regardless of
 * their nominal -weight.
 *
70
71
72
73
74
75
76
77

78
79
80


81
82
83


84
85
86


87
88
89
90
91
92
93

94
95
96
97
98
99
100
101

102
103
104


105
106
107
108
109
110

111
112
113
114

115
116
117

118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144


145
146
147
148
149
150
151


152
153
154
155
156
157
158
71
72
73
74
75
76
77

78
79


80
81
82


83
84
85


86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101

102
103


104
105
106
107
108
109
110

111
112
113
114

115
116
117

118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143


144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159







-
+

-
-
+
+

-
-
+
+

-
-
+
+






-
+







-
+

-
-
+
+





-
+



-
+


-
+






-
+


















-
-
+
+





-
-
+
+







typedef struct {
    WidgetCore	core;
    PanedPart	paned;
} Paned;

/* @@@ NOTE: -orient is readonly 'cause dynamic oriention changes NYI
 */
static const Tk_OptionSpec PanedOptionSpecs[] = {
static Tk_OptionSpec PanedOptionSpecs[] = {
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "vertical",
	offsetof(Paned,paned.orientObj), offsetof(Paned,paned.orient),
	0, ttkOrientStrings, READONLY_OPTION|STYLE_CHANGED },
	Tk_Offset(Paned,paned.orientObj), Tk_Offset(Paned,paned.orient),
	0,(ClientData)ttkOrientStrings,READONLY_OPTION|STYLE_CHANGED },
    {TK_OPTION_INT, "-width", "width", "Width", "0",
	TCL_INDEX_NONE, offsetof(Paned, paned.width),
	0, 0, GEOMETRY_CHANGED },
	-1,Tk_Offset(Paned,paned.width),
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_INT, "-height", "height", "Height", "0",
	TCL_INDEX_NONE, offsetof(Paned, paned.height),
	0, 0, GEOMETRY_CHANGED },
	-1,Tk_Offset(Paned,paned.height),
	0,0,GEOMETRY_CHANGED },

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*------------------------------------------------------------------------
 * +++ Pane record.
 * +++ Slave pane record.
 */
typedef struct {
    int 	reqSize;		/* Pane request size */
    int 	sashPos;		/* Folowing sash position */
    int 	weight; 		/* Pane -weight, for resizing */
} Pane;

static const Tk_OptionSpec PaneOptionSpecs[] = {
static Tk_OptionSpec PaneOptionSpecs[] = {
    {TK_OPTION_INT, "-weight", "weight", "Weight", "0",
	TCL_INDEX_NONE, offsetof(Pane,weight), 0,0,GEOMETRY_CHANGED },
    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0}
	-1,Tk_Offset(Pane,weight), 0,0,GEOMETRY_CHANGED },
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0}
};

/* CreatePane --
 * 	Create a new pane record.
 */
static Pane *CreatePane(Tcl_Interp *interp, Paned *pw, Tk_Window window)
static Pane *CreatePane(Tcl_Interp *interp, Paned *pw, Tk_Window slaveWindow)
{
    Tk_OptionTable optionTable = pw->paned.paneOptionTable;
    void *record = ckalloc(sizeof(Pane));
    Pane *pane = (Pane *)record;
    Pane *pane = record;

    memset(record, 0, sizeof(Pane));
    if (Tk_InitOptions(interp, record, optionTable, window) != TCL_OK) {
    if (Tk_InitOptions(interp, record, optionTable, slaveWindow) != TCL_OK) {
	ckfree(record);
	return NULL;
    }

    pane->reqSize
	= pw->paned.orient == TTK_ORIENT_HORIZONTAL
	? Tk_ReqWidth(window) : Tk_ReqHeight(window);
	? Tk_ReqWidth(slaveWindow) : Tk_ReqHeight(slaveWindow);

    return pane;
}

/* DestroyPane --
 * 	Free pane record.
 */
static void DestroyPane(Paned *pw, Pane *pane)
{
    void *record = pane;
    Tk_FreeConfigOptions(record, pw->paned.paneOptionTable, pw->core.tkwin);
    ckfree(record);
}

/* ConfigurePane --
 * 	Set pane options.
 */
static int ConfigurePane(
    Tcl_Interp *interp, Paned *pw, Pane *pane, Tk_Window window,
    Tcl_Size objc, Tcl_Obj *const objv[])
    Tcl_Interp *interp, Paned *pw, Pane *pane, Tk_Window slaveWindow,
    int objc, Tcl_Obj *const objv[])
{
    Ttk_Manager *mgr = pw->paned.mgr;
    Tk_SavedOptions savedOptions;
    int mask = 0;

    if (Tk_SetOptions(interp, pane, pw->paned.paneOptionTable,
	    objc, objv, window, &savedOptions, &mask) != TCL_OK)
    if (Tk_SetOptions(interp, (void*)pane, pw->paned.paneOptionTable,
	    objc, objv, slaveWindow, &savedOptions, &mask) != TCL_OK)
    {
	return TCL_ERROR;
    }

    /* Sanity-check:
     */
    if (pane->weight < 0) {
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209

210
211

212
213
214
215


216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233


234
235
236
237
238
239
240
241
242


243
244
245


246
247
248
249
250
251
252


253
254
255


256
257
258
259
260
261
262
185
186
187
188
189
190
191

192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209

210
211

212
213
214


215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


233
234
235
236
237
238
239
240
241


242
243
244


245
246
247
248
249
250
251


252
253
254


255
256
257
258
259
260
261
262
263







-
+






-
+










-
+

-
+


-
-
+
+

-
+














-
-
+
+







-
-
+
+

-
-
+
+





-
-
+
+

-
-
+
+







 * 	of the window.  If that happens, shove back down.
 *
 * 	Returns: final position of sash i.
 */

static int ShoveUp(Paned *pw, int i, int pos)
{
    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, i);
    Pane *pane = Ttk_SlaveData(pw->paned.mgr, i);
    int sashThickness = pw->paned.sashThickness;

    if (i == 0) {
	if (pos < 0)
	    pos = 0;
    } else {
	Pane *prevPane = (Pane *)Ttk_ContentData(pw->paned.mgr, i-1);
	Pane *prevPane = Ttk_SlaveData(pw->paned.mgr, i-1);
	if (pos < prevPane->sashPos + sashThickness)
	    pos = ShoveUp(pw, i-1, pos - sashThickness) + sashThickness;
    }
    return pane->sashPos = pos;
}

/* ShoveDown --
 * 	Same as ShoveUp, but going in the opposite direction
 * 	and stopping at the sentinel sash.
 */
static int ShoveDown(Paned *pw, Tcl_Size i, int pos)
static int ShoveDown(Paned *pw, int i, int pos)
{
    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr,i);
    Pane *pane = Ttk_SlaveData(pw->paned.mgr,i);
    int sashThickness = pw->paned.sashThickness;

    if (i == Ttk_NumberContent(pw->paned.mgr) - 1) {
	pos = pane->sashPos; /* Sentinel value == container window size */
    if (i == Ttk_NumberSlaves(pw->paned.mgr) - 1) {
	pos = pane->sashPos; /* Sentinel value == master window size */
    } else {
	Pane *nextPane = (Pane *)Ttk_ContentData(pw->paned.mgr,i+1);
	Pane *nextPane = Ttk_SlaveData(pw->paned.mgr,i+1);
	if (pos + sashThickness > nextPane->sashPos)
	    pos = ShoveDown(pw, i+1, pos + sashThickness) - sashThickness;
    }
    return pane->sashPos = pos;
}

/* PanedSize --
 * 	Compute the requested size of the paned widget
 * 	from the individual pane request sizes.
 *
 * 	Used as the WidgetSpec sizeProc and the ManagerSpec sizeProc.
 */
static int PanedSize(void *recordPtr, int *widthPtr, int *heightPtr)
{
    Paned *pw = (Paned *)recordPtr;
    int nPanes = Ttk_NumberContent(pw->paned.mgr);
    Paned *pw = recordPtr;
    int nPanes = Ttk_NumberSlaves(pw->paned.mgr);
    int nSashes = nPanes - 1;
    int sashThickness = pw->paned.sashThickness;
    int width = 0, height = 0;
    int index;

    if (pw->paned.orient == TTK_ORIENT_HORIZONTAL) {
	for (index = 0; index < nPanes; ++index) {
	    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
	    Tk_Window window = Ttk_ContentWindow(pw->paned.mgr, index);
	    Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
	    Tk_Window slaveWindow = Ttk_SlaveWindow(pw->paned.mgr, index);

	    if (height < Tk_ReqHeight(window))
		height = Tk_ReqHeight(window);
	    if (height < Tk_ReqHeight(slaveWindow))
		height = Tk_ReqHeight(slaveWindow);
	    width += pane->reqSize;
	}
	width += nSashes * sashThickness;
    } else {
	for (index = 0; index < nPanes; ++index) {
	    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
	    Tk_Window window = Ttk_ContentWindow(pw->paned.mgr, index);
	    Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
	    Tk_Window slaveWindow = Ttk_SlaveWindow(pw->paned.mgr, index);

	    if (width < Tk_ReqWidth(window))
		width = Tk_ReqWidth(window);
	    if (width < Tk_ReqWidth(slaveWindow))
		width = Tk_ReqWidth(slaveWindow);
	    height += pane->reqSize;
	}
	height += nSashes * sashThickness;
    }

    *widthPtr = pw->paned.width > 0 ? pw->paned.width : width;
    *heightPtr = pw->paned.height > 0 ? pw->paned.height : height;
271
272
273
274
275
276
277
278

279
280
281


282
283
284
285
286
287
288
272
273
274
275
276
277
278

279
280


281
282
283
284
285
286
287
288
289







-
+

-
-
+
+







 * 	will leave the sashes in the same place, as long as available size
 * 	remains contant.
 */
static void AdjustPanes(Paned *pw)
{
    int sashThickness = pw->paned.sashThickness;
    int pos = 0;
    Tcl_Size index;
    int index;

    for (index = 0; index < Ttk_NumberContent(pw->paned.mgr); ++index) {
	Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
    for (index = 0; index < Ttk_NumberSlaves(pw->paned.mgr); ++index) {
	Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
	int size = pane->sashPos - pos;
	pane->reqSize = size >= 0 ? size : 0;
	pos = pane->sashPos + sashThickness;
    }
}

/* PlaceSashes --
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327







-
+











-
+







 * Notes:
 * 	This doesn't distribute the remainder pixels as evenly as it could
 * 	when more than one pane has weight > 1.
 */
static void PlaceSashes(Paned *pw, int width, int height)
{
    Ttk_Manager *mgr = pw->paned.mgr;
    int nPanes = Ttk_NumberContent(mgr);
    int nPanes = Ttk_NumberSlaves(mgr);
    int sashThickness = pw->paned.sashThickness;
    int available = pw->paned.orient == TTK_ORIENT_HORIZONTAL ? width : height;
    int reqSize = 0, totalWeight = 0;
    int difference, delta, remainder, pos, i;

    if (nPanes == 0)
	return;

    /* Compute total required size and total available weight:
     */
    for (i = 0; i < nPanes; ++i) {
	Pane *pane = (Pane *)Ttk_ContentData(mgr, i);
	Pane *pane = Ttk_SlaveData(mgr, i);
	reqSize += pane->reqSize;
	totalWeight += pane->weight * (pane->reqSize != 0);
    }

    /* Compute difference to be redistributed:
     */
    difference = available - reqSize - sashThickness*(nPanes-1);
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+







    }
    /* ASSERT: 0 <= remainder < totalWeight */

    /* Place sashes:
     */
    pos = 0;
    for (i = 0; i < nPanes; ++i) {
	Pane *pane = (Pane *)Ttk_ContentData(mgr, i);
	Pane *pane = Ttk_SlaveData(mgr, i);
	int weight = pane->weight * (pane->reqSize != 0);
	int size = pane->reqSize + delta * weight;

	if (weight > remainder)
	    weight = remainder;
	remainder -= weight;
	size += weight;
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375

376
377
378


379
380
381
382
383

384
385

386
387
388

389
390
391
392
393
394
395
396
397
398
399

400
401

402
403
404
405
406

407
408
409


410
411
412
413
414
415
416


417
418
419

420
421
422

423
424

425
426
427
428
429

430
431
432
433

434
435
436
437
438

439
440
441
442
443
444


445
446
447
448

449
450
451
452



453
454
455

456
457
458
459
460
461
462


463
464

465
466
467
468
469
470






471
472
473
474
475
476
477
478
479
480
481
482
483
484
485

486
487

488
489
490
491

492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511
512
513

514
515
516
517
518
519
520
521
522
523
524

525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375

376
377


378
379
380
381
382
383

384
385

386
387
388

389
390
391
392
393
394
395
396
397
398
399

400
401

402
403
404
405
406

407
408


409
410
411
412
413
414
415


416
417
418
419

420
421
422

423
424

425
426
427
428
429

430
431
432
433

434
435
436
437
438

439
440
441
442
443


444
445
446
447
448

449
450



451
452
453
454
455

456
457
458
459
460
461


462
463
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480








481
482
483

484
485

486
487
488
489

490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519
520
521
522

523



524

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553







-
+







-
+

-
-
+
+




-
+

-
+


-
+










-
+

-
+




-
+

-
-
+
+





-
-
+
+


-
+


-
+

-
+




-
+



-
+




-
+




-
-
+
+



-
+

-
-
-
+
+
+


-
+





-
-
+
+

-
+






+
+
+
+
+
+



-
-
-
-
-
-
-
-



-
+

-
+



-
+









-
+











-
+










-
+
-
-
-

-
+




















-
+







     * Set sentinel sash position to end of widget,
     * shove preceding sashes up.
     */
    ShoveUp(pw, nPanes - 1, available);
}

/* PlacePanes --
 *	Places panes based on sash positions.
 *	Places slave panes based on sash positions.
 */
static void PlacePanes(Paned *pw)
{
    int horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL;
    int width = Tk_Width(pw->core.tkwin), height = Tk_Height(pw->core.tkwin);
    int sashThickness = pw->paned.sashThickness;
    int pos = 0;
    Tcl_Size index;
    int index;

    for (index = 0; index < Ttk_NumberContent(pw->paned.mgr); ++index) {
	Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
    for (index = 0; index < Ttk_NumberSlaves(pw->paned.mgr); ++index) {
	Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
	int size = pane->sashPos - pos;

	if (size > 0) {
	    if (horizontal) {
		Ttk_PlaceContent(pw->paned.mgr, index, pos, 0, size, height);
		Ttk_PlaceSlave(pw->paned.mgr, index, pos, 0, size, height);
	    } else {
		Ttk_PlaceContent(pw->paned.mgr, index, 0, pos, width, size);
		Ttk_PlaceSlave(pw->paned.mgr, index, 0, pos, width, size);
	    }
	} else {
	    Ttk_UnmapContent(pw->paned.mgr, index);
	    Ttk_UnmapSlave(pw->paned.mgr, index);
	}

	pos = pane->sashPos + sashThickness;
    }
}

/*------------------------------------------------------------------------
 * +++ Manager specification.
 */

static void PanedPlaceContent(void *managerData)
static void PanedPlaceSlaves(void *managerData)
{
    Paned *pw = (Paned *)managerData;
    Paned *pw = managerData;
    PlaceSashes(pw, Tk_Width(pw->core.tkwin), Tk_Height(pw->core.tkwin));
    PlacePanes(pw);
}

static void PaneRemoved(void *managerData, Tcl_Size index)
static void PaneRemoved(void *managerData, int index)
{
    Paned *pw = (Paned *)managerData;
    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
    Paned *pw = managerData;
    Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
    DestroyPane(pw, pane);
}

static int AddPane(
    Tcl_Interp *interp, Paned *pw,
    int destIndex, Tk_Window window,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int destIndex, Tk_Window slaveWindow,
    int objc, Tcl_Obj *const objv[])
{
    Pane *pane;
    if (!Ttk_Maintainable(interp, window, pw->core.tkwin)) {
    if (!Ttk_Maintainable(interp, slaveWindow, pw->core.tkwin)) {
	return TCL_ERROR;
    }
    if (Ttk_ContentIndex(pw->paned.mgr, window) >= 0) {
    if (Ttk_SlaveIndex(pw->paned.mgr, slaveWindow) >= 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"%s already added", Tk_PathName(window)));
		"%s already added", Tk_PathName(slaveWindow)));
	Tcl_SetErrorCode(interp, "TTK", "PANE", "PRESENT", NULL);
	return TCL_ERROR;
    }

    pane = CreatePane(interp, pw, window);
    pane = CreatePane(interp, pw, slaveWindow);
    if (!pane) {
	return TCL_ERROR;
    }
    if (ConfigurePane(interp, pw, pane, window, objc, objv) != TCL_OK) {
    if (ConfigurePane(interp, pw, pane, slaveWindow, objc, objv) != TCL_OK) {
	DestroyPane(pw, pane);
	return TCL_ERROR;
    }

    Ttk_InsertContent(pw->paned.mgr, destIndex, window, pane);
    Ttk_InsertSlave(pw->paned.mgr, destIndex, slaveWindow, pane);
    return TCL_OK;
}

/* PaneRequest --
 * 	Only update pane request size if pane is currently unmapped.
 * 	Geometry requests from mapped panes are not directly honored
 * 	Only update pane request size if slave is currently unmapped.
 * 	Geometry requests from mapped slaves are not directly honored
 * 	in order to avoid unexpected pane resizes (esp. while the
 * 	user is dragging a sash [#1325286]).
 */
static int PaneRequest(void *managerData, Tcl_Size index, int width, int height)
static int PaneRequest(void *managerData, int index, int width, int height)
{
    Paned *pw = (Paned *)managerData;
    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
    Tk_Window window = Ttk_ContentWindow(pw->paned.mgr, index);
    Paned *pw = managerData;
    Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
    Tk_Window slaveWindow = Ttk_SlaveWindow(pw->paned.mgr, index);
    int horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL;

    if (!Tk_IsMapped(window)) {
    if (!Tk_IsMapped(slaveWindow)) {
	pane->reqSize = horizontal ? width : height;
    }
    return 1;
}

static const Ttk_ManagerSpec PanedManagerSpec = {
    { "panedwindow", Ttk_GeometryRequestProc, Ttk_LostContentProc },
static Ttk_ManagerSpec PanedManagerSpec = {
    { "panedwindow", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
    PanedSize,
    PanedPlaceContent,
    PanedPlaceSlaves,
    PaneRequest,
    PaneRemoved
};

/*------------------------------------------------------------------------
 * +++ Event handler.
 *
 * <<NOTE-PW-LEAVE-NOTIFYINFERIOR>>
 * Tk does not execute binding scripts for <Leave> events when
 * the pointer crosses from a parent to a child.  This widget
 * needs to know when that happens, though, so it can reset
 * the cursor.
 *
 * This event handler generates an <<EnteredChild>> virtual event
 * on LeaveNotify/NotifyInferior.
 * This was originally introduced because Tk used to discard events with
 * detail field NotifyInferior. The <<EnteredChild>> event was then used
 * to reset the cursor when the pointer crosses from a parent to a child.
 * Since ticket #47d4f29159, LeaveNotify/NotifyInferior are no longer
 * discarded: the <Leave> event will trigger even with NotifyInferior
 * detail field. The generated <<EnteredChild>> is nevertheless kept for
 * backwards compatibility purpose since it is publicly documented,
 * meaning that someone could bind to it.
 */

static const unsigned PanedEventMask = LeaveWindowMask;
static void PanedEventProc(void *clientData, XEvent *eventPtr)
static void PanedEventProc(ClientData clientData, XEvent *eventPtr)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    if (   eventPtr->type == LeaveNotify
	&& eventPtr->xcrossing.detail == NotifyInferior)
    {
	Tk_SendVirtualEvent(corePtr->tkwin, "EnteredChild", NULL);
	TtkSendVirtualEvent(corePtr->tkwin, "EnteredChild");
    }
}

/*------------------------------------------------------------------------
 * +++ Initialization and cleanup hooks.
 */

static void PanedInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Paned *pw = (Paned *)recordPtr;
    Paned *pw = recordPtr;

    Tk_CreateEventHandler(pw->core.tkwin,
	PanedEventMask, PanedEventProc, recordPtr);
    pw->paned.mgr = Ttk_CreateManager(&PanedManagerSpec, pw, pw->core.tkwin);
    pw->paned.paneOptionTable = Tk_CreateOptionTable(interp,PaneOptionSpecs);
    pw->paned.sashLayout = 0;
    pw->paned.sashThickness = 1;
}

static void PanedCleanup(void *recordPtr)
{
    Paned *pw = (Paned *)recordPtr;
    Paned *pw = recordPtr;

    if (pw->paned.sashLayout)
	Ttk_FreeLayout(pw->paned.sashLayout);
    Tk_DeleteEventHandler(pw->core.tkwin,
	PanedEventMask, PanedEventProc, recordPtr);
    Ttk_DeleteManager(pw->paned.mgr);
}

/* Post-configuration hook.
 */
static int PanedPostConfigure(
static int PanedPostConfigure(Tcl_Interp *interp, void *clientData, int mask)
    TCL_UNUSED(Tcl_Interp *),
    void *clientData,
    int mask)
{
    Paned *pw = (Paned *)clientData;
    Paned *pw = clientData;

    if (mask & GEOMETRY_CHANGED) {
	/* User has changed -width or -height.
	 * Recalculate sash positions based on requested size.
	 */
	Tk_Window tkwin = pw->core.tkwin;
	PlaceSashes(pw,
	    pw->paned.width > 0 ? pw->paned.width : Tk_Width(tkwin),
	    pw->paned.height > 0 ? pw->paned.height : Tk_Height(tkwin));
    }

    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Layout management hooks.
 */
static Ttk_Layout PanedGetLayout(
    Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr)
{
    Paned *pw = (Paned *)recordPtr;
    Paned *pw = recordPtr;
    Ttk_Layout panedLayout = TtkWidgetGetLayout(interp, themePtr, recordPtr);

    if (panedLayout) {
	int horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL;
	const char *layoutName =
	    horizontal ? ".Vertical.Sash" : ".Horizontal.Sash";
	Ttk_Layout sashLayout = Ttk_CreateSublayout(
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591







-
+








/* SashLayout --
 * 	Place the sash sublayout after the specified pane,
 * 	in preparation for drawing.
 */
static Ttk_Layout SashLayout(Paned *pw, int index)
{
    Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
    Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
    int thickness = pw->paned.sashThickness,
	height = Tk_Height(pw->core.tkwin),
	width = Tk_Width(pw->core.tkwin),
	sashPos = pane->sashPos;

    Ttk_PlaceLayout(
	pw->paned.sashLayout, pw->core.state,
603
604
605
606
607
608
609
610
611


612
613
614
615


616
617
618
619
620
621
622
623
624
625
626

627
628
629


630
631
632
633
634
635
636

637
638
639

640
641
642
643

644
645
646
647
648


649
650
651

652
653
654
655
656




657
658
659

660
661
662
663

664
665

666
667
668


669
670


671
672
673
674
675
676
677
678




679
680
681
682



683
684
685
686
687
688



689
690
691
692
693
694

695
696
697


698
699
700
701
702
703
704

705
706
707
708
709
710
711

712
713
714
715
716
717
718
719
720

721
722

723
724
725

726
727

728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746

747
748
749
750
751

752
753
754
755
756
757
758
599
600
601
602
603
604
605


606
607
608
609


610
611
612
613
614
615
616
617
618
619
620
621

622
623


624
625
626
627
628
629
630
631

632
633
634

635
636
637
638

639
640
641
642


643
644
645
646

647
648




649
650
651
652
653
654

655
656
657
658

659
660

661
662
663
664
665
666


667
668
669
670
671
672




673
674
675
676
677



678
679
680
681
682
683



684
685
686
687
688
689
690
691

692
693


694
695
696
697
698
699
700
701

702
703
704
705


706

707
708
709
710
711
712
713
714
715

716
717

718
719
720

721
722

723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741

742
743
744
745
746

747
748
749
750
751
752
753
754







-
-
+
+


-
-
+
+










-
+

-
-
+
+






-
+


-
+



-
+



-
-
+
+


-
+

-
-
-
-
+
+
+
+


-
+



-
+

-
+



+
+
-
-
+
+




-
-
-
-
+
+
+
+

-
-
-
+
+
+



-
-
-
+
+
+





-
+

-
-
+
+






-
+



-
-

-
+








-
+

-
+


-
+

-
+


















-
+




-
+







static void DrawSash(Paned *pw, int index, Drawable d)
{
    Ttk_DrawLayout(SashLayout(pw, index), pw->core.state, d);
}

static void PanedDisplay(void *recordPtr, Drawable d)
{
    Paned *pw = (Paned *)recordPtr;
    Tcl_Size i, nContent = Ttk_NumberContent(pw->paned.mgr);
    Paned *pw = recordPtr;
    int i, nSashes = Ttk_NumberSlaves(pw->paned.mgr) - 1;

    TtkWidgetDisplay(recordPtr, d);
    for (i = 1; i < nContent; ++i) {
	DrawSash(pw, i - 1, d);
    for (i = 0; i < nSashes; ++i) {
	DrawSash(pw, i, d);
    }
}

/*------------------------------------------------------------------------
 * +++ Widget commands.
 */

/* $pw add window [ options ... ]
 */
static int PanedAddCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Tk_Window window;
    Paned *pw = recordPtr;
    Tk_Window slaveWindow;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }

    window = Tk_NameToWindow(
    slaveWindow = Tk_NameToWindow(
	interp, Tcl_GetString(objv[2]), pw->core.tkwin);

    if (!window) {
    if (!slaveWindow) {
	return TCL_ERROR;
    }

    return AddPane(interp, pw, Ttk_NumberContent(pw->paned.mgr), window,
    return AddPane(interp, pw, Ttk_NumberSlaves(pw->paned.mgr), slaveWindow,
	    objc - 3, objv + 3);
}

/* $pw insert $index $window ?-option value ...?
 * 	Insert new content window, or move existing one.
/* $pw insert $index $slave ?-option value ...?
 * 	Insert new slave, or move existing one.
 */
static int PanedInsertCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Tcl_Size nContent = Ttk_NumberContent(pw->paned.mgr);
    Tcl_Size srcIndex, destIndex;
    Tk_Window window;
    Paned *pw = recordPtr;
    int nSlaves = Ttk_NumberSlaves(pw->paned.mgr);
    int srcIndex, destIndex;
    Tk_Window slaveWindow;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2,objv, "index window ?-option value ...?");
	Tcl_WrongNumArgs(interp, 2,objv, "index slave ?-option value ...?");
	return TCL_ERROR;
    }

    window = Tk_NameToWindow(
    slaveWindow = Tk_NameToWindow(
	interp, Tcl_GetString(objv[3]), pw->core.tkwin);
    if (!window) {
    if (!slaveWindow) {
	return TCL_ERROR;
    }

    if (!strcmp(Tcl_GetString(objv[2]), "end")) {
	destIndex = Ttk_NumberSlaves(pw->paned.mgr);
    if (TCL_OK != Ttk_GetContentIndexFromObj(
		interp,pw->paned.mgr, objv[2], &destIndex))
    } else if (TCL_OK != Ttk_GetSlaveIndexFromObj(
		interp,pw->paned.mgr,objv[2],&destIndex))
    {
	return TCL_ERROR;
    }

    srcIndex = Ttk_ContentIndex(pw->paned.mgr, window);
    if (srcIndex < 0) { /* New content: */
	return AddPane(interp, pw, destIndex, window, objc-4, objv+4);
    } /* else -- move existing content: */
    srcIndex = Ttk_SlaveIndex(pw->paned.mgr, slaveWindow);
    if (srcIndex < 0) { /* New slave: */
	return AddPane(interp, pw, destIndex, slaveWindow, objc-4, objv+4);
    } /* else -- move existing slave: */

    if (destIndex >= nContent)
	destIndex  = nContent - 1;
    Ttk_ReorderContent(pw->paned.mgr, srcIndex, destIndex);
    if (destIndex >= nSlaves)
	destIndex  = nSlaves - 1;
    Ttk_ReorderSlave(pw->paned.mgr, srcIndex, destIndex);

    return objc == 4 ? TCL_OK :
	ConfigurePane(interp, pw,
		(Pane *)Ttk_ContentData(pw->paned.mgr, destIndex),
		Ttk_ContentWindow(pw->paned.mgr, destIndex),
		objc-4, objv+4);
		Ttk_SlaveData(pw->paned.mgr, destIndex),
		Ttk_SlaveWindow(pw->paned.mgr, destIndex),
		objc-4,objv+4);
}

/* $pw forget $pane
 */
static int PanedForgetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Tcl_Size paneIndex;
    Paned *pw = recordPtr;
    int paneIndex;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2,objv, "pane");
	return TCL_ERROR;
    }

    if (TCL_OK != Ttk_GetContentIndexFromObj(
    if (TCL_OK != Ttk_GetSlaveIndexFromObj(
		    interp, pw->paned.mgr, objv[2], &paneIndex))
    {
	return TCL_ERROR;
    } else if (paneIndex >= Ttk_NumberContent(pw->paned.mgr)) {
	paneIndex = Ttk_NumberContent(pw->paned.mgr) - 1;
    }
    Ttk_ForgetContent(pw->paned.mgr, paneIndex);
    Ttk_ForgetSlave(pw->paned.mgr, paneIndex);

    return TCL_OK;
}

/* $pw identify ?what? $x $y --
 * 	Return index of sash at $x,$y
 */
static int PanedIdentifyCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    static const char *const whatTable[] = { "element", "sash", NULL };
    static const char *whatTable[] = { "element", "sash", NULL };
    enum { IDENTIFY_ELEMENT, IDENTIFY_SASH };
    int what = IDENTIFY_SASH;
    Paned *pw = (Paned *)recordPtr;
    Paned *pw = recordPtr;
    int sashThickness = pw->paned.sashThickness;
    int nSashes = Ttk_NumberContent(pw->paned.mgr) - 1;
    int nSashes = Ttk_NumberSlaves(pw->paned.mgr) - 1;
    int x, y, pos;
    int index;

    if (objc < 4 || objc > 5) {
	Tcl_WrongNumArgs(interp, 2,objv, "?what? x y");
	return TCL_ERROR;
    }

    if (   Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
	|| Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK
	|| (objc == 5 && Tcl_GetIndexFromObjStruct(interp, objv[2], whatTable,
	    sizeof(char *), "option", 0, &what) != TCL_OK)
    ) {
	return TCL_ERROR;
    }

    pos = pw->paned.orient == TTK_ORIENT_HORIZONTAL ? x : y;
    for (index = 0; index < nSashes; ++index) {
	Pane *pane = (Pane *)Ttk_ContentData(pw->paned.mgr, index);
	Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
	if (pane->sashPos <= pos && pos <= pane->sashPos + sashThickness) {
	    /* Found it. */
	    switch (what) {
		case IDENTIFY_SASH:
		    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index));
		    Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
		    return TCL_OK;
		case IDENTIFY_ELEMENT:
		{
		    Ttk_Element element =
			Ttk_IdentifyElement(SashLayout(pw, index), x, y);
		    if (element) {
			Tcl_SetObjResult(interp,
767
768
769
770
771
772
773
774

775
776
777
778



779
780
781
782
783
784
785
786
787


788
789
790
791
792
793
794
795


796
797
798
799
800

801
802
803

804
805

806
807
808
809
810
811
812
813

814
815

816
817
818

819
820
821
822
823
824
825
826
827


828
829
830
831
832
833
834
835
836
837
838
839
840

841
842
843


844
845
846
847
848
849
850

851
852
853

854
855

856
857
858
859
860

861
862
863

864
865
866
867
868

869
870
871
872
873
874
875
876
877
878
879
880
881

882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905

906
907
908
909
910
911
912
763
764
765
766
767
768
769

770
771



772
773
774
775
776
777
778
779
780
781


782
783
784
785


786
787


788
789
790
791
792
793

794
795
796

797
798

799
800
801
802
803
804
805
806

807
808

809
810
811

812
813
814
815
816
817
818
819


820
821
822
823
824
825
826
827
828
829
830
831
832
833

834
835


836
837
838
839
840
841
842
843

844
845
846

847
848

849
850
851
852
853

854
855
856

857
858
859
860
861

862
863
864
865
866
867
868
869
870
871
872
873
874

875
876
877
878
879
880

881
882
883
884
885
886
887
888
889
890

891
892
893
894
895
896
897

898
899
900
901
902
903
904
905







-
+

-
-
-
+
+
+







-
-
+
+


-
-


-
-
+
+




-
+


-
+

-
+







-
+

-
+


-
+







-
-
+
+












-
+

-
-
+
+






-
+


-
+

-
+




-
+


-
+




-
+












-
+





-

+








-







-
+







    return TCL_OK; /* nothing found - return empty string */
}

/* $pw pane $pane ?-option ?value -option value ...??
 * 	Query/modify pane options.
 */
static int PanedPaneCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Tcl_Size paneIndex;
    Tk_Window window;
    Paned *pw = recordPtr;
    int paneIndex;
    Tk_Window slaveWindow;
    Pane *pane;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2,objv, "pane ?-option value ...?");
	return TCL_ERROR;
    }

    if (TCL_OK != Ttk_GetContentIndexFromObj(
		    interp,pw->paned.mgr, objv[2], &paneIndex))
    if (TCL_OK != Ttk_GetSlaveIndexFromObj(
		    interp,pw->paned.mgr,objv[2],&paneIndex))
    {
	return TCL_ERROR;
    } else if (paneIndex >= Ttk_NumberContent(pw->paned.mgr)) {
	paneIndex = Ttk_NumberContent(pw->paned.mgr) - 1;
    }

    pane = (Pane *)Ttk_ContentData(pw->paned.mgr, paneIndex);
    window = Ttk_ContentWindow(pw->paned.mgr, paneIndex);
    pane = Ttk_SlaveData(pw->paned.mgr, paneIndex);
    slaveWindow = Ttk_SlaveWindow(pw->paned.mgr, paneIndex);

    switch (objc) {
	case 3:
	    return TtkEnumerateOptions(interp, pane, PaneOptionSpecs,
			pw->paned.paneOptionTable, window);
			pw->paned.paneOptionTable, slaveWindow);
	case 4:
	    return TtkGetOptionValue(interp, pane, objv[3],
			pw->paned.paneOptionTable, window);
			pw->paned.paneOptionTable, slaveWindow);
	default:
	    return ConfigurePane(interp, pw, pane, window, objc-3,objv+3);
	    return ConfigurePane(interp, pw, pane, slaveWindow, objc-3,objv+3);
    }
}

/* $pw panes --
 * 	Return list of managed panes.
 */
static int PanedPanesCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Paned *pw = recordPtr;
    Ttk_Manager *mgr = pw->paned.mgr;
    Tcl_Obj *panes;
    Tcl_Size i;
    int i;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "");
	return TCL_ERROR;
    }

    panes = Tcl_NewListObj(0, NULL);
    for (i = 0; i < Ttk_NumberContent(mgr); ++i) {
	const char *pathName = Tk_PathName(Ttk_ContentWindow(mgr,i));
    for (i = 0; i < Ttk_NumberSlaves(mgr); ++i) {
	const char *pathName = Tk_PathName(Ttk_SlaveWindow(mgr,i));
	Tcl_ListObjAppendElement(interp, panes, Tcl_NewStringObj(pathName,-1));
    }
    Tcl_SetObjResult(interp, panes);

    return TCL_OK;
}


/* $pw sashpos $index ?$newpos?
 * 	Query or modify sash position.
 */
static int PanedSashposCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Paned *pw = (Paned *)recordPtr;
    Tcl_WideInt sashIndex, position = -1;
    Paned *pw = recordPtr;
    int sashIndex, position = -1;
    Pane *pane;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 2,objv, "index ?newpos?");
	return TCL_ERROR;
    }
    if (Tcl_GetWideIntFromObj(interp, objv[2], &sashIndex) != TCL_OK) {
    if (Tcl_GetIntFromObj(interp, objv[2], &sashIndex) != TCL_OK) {
	return TCL_ERROR;
    }
    if (sashIndex < 0 || sashIndex >= Ttk_NumberContent(pw->paned.mgr) - 1) {
    if (sashIndex < 0 || sashIndex >= Ttk_NumberSlaves(pw->paned.mgr) - 1) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "sash index %" TCL_LL_MODIFIER "d out of range", sashIndex));
	    "sash index %d out of range", sashIndex));
	Tcl_SetErrorCode(interp, "TTK", "PANE", "SASH_INDEX", NULL);
	return TCL_ERROR;
    }

    pane = (Pane *)Ttk_ContentData(pw->paned.mgr, sashIndex);
    pane = Ttk_SlaveData(pw->paned.mgr, sashIndex);

    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pane->sashPos));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(pane->sashPos));
	return TCL_OK;
    }
    /* else -- set new sash position */

    if (Tcl_GetWideIntFromObj(interp, objv[3], &position) != TCL_OK) {
    if (Tcl_GetIntFromObj(interp, objv[3], &position) != TCL_OK) {
	return TCL_ERROR;
    }

    if (position < pane->sashPos) {
	ShoveUp(pw, sashIndex, position);
    } else {
	ShoveDown(pw, sashIndex, position);
    }

    AdjustPanes(pw);
    Ttk_ManagerLayoutChanged(pw->paned.mgr);

    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(pane->sashPos));
    Tcl_SetObjResult(interp, Tcl_NewIntObj(pane->sashPos));
    return TCL_OK;
}

static const Ttk_Ensemble PanedCommands[] = {
    { "add", 		PanedAddCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "forget", 	PanedForgetCommand,0 },
    { "identify", 	PanedIdentifyCommand,0 },
    { "insert", 	PanedInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "pane",   	PanedPaneCommand,0 },
    { "panes",   	PanedPanesCommand,0 },
    { "sashpos",  	PanedSashposCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Widget specification.
 */

static const WidgetSpec PanedWidgetSpec =
static WidgetSpec PanedWidgetSpec =
{
    "TPanedwindow",		/* className */
    sizeof(Paned),		/* recordSize */
    PanedOptionSpecs,		/* optionSpecs */
    PanedCommands,		/* subcommands */
    PanedInitialize,		/* initializeProc */
    PanedCleanup,		/* cleanupProc */
924
925
926
927
928
929
930
931

932
933
934


935
936
937
938
939

940
941

942
943
944
945

946
947
948
949
950
951
952

953
954
955
956
957
958
959
917
918
919
920
921
922
923

924
925


926
927
928
929
930


931


932


933

934
935

936
937
938
939

940
941
942
943
944
945
946
947







-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+

-




-
+








static const int DEFAULT_SASH_THICKNESS = 5;

typedef struct {
    Tcl_Obj *thicknessObj;
} SashElement;

static const Ttk_ElementOptionSpec SashElementOptions[] = {
static Ttk_ElementOptionSpec SashElementOptions[] = {
    { "-sashthickness", TK_OPTION_INT,
	    offsetof(SashElement,thicknessObj), "5" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	    Tk_Offset(SashElement,thicknessObj), "5" },
    { NULL, 0, 0, NULL }
};

static void SashElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    SashElement *sash = (SashElement *)elementRecord;
    SashElement *sash = elementRecord;
    int thickness = DEFAULT_SASH_THICKNESS;

    Tcl_GetIntFromObj(NULL, sash->thicknessObj, &thickness);
    *widthPtr = *heightPtr = thickness;
}

static const Ttk_ElementSpec SashElementSpec = {
static Ttk_ElementSpec SashElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SashElement),
    SashElementOptions,
    SashElementSize,
    TtkNullElementDraw
};

968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
956
957
958
959
960
961
962



963
964
965
966
967
968
969







-
-
-







TTK_BEGIN_LAYOUT(VerticalSashLayout)
    TTK_NODE("Sash.vsash", TTK_FILL_Y)
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * +++ Registration routine.
 */
MODULE_SCOPE
void TtkPanedwindow_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkPanedwindow_Init(Tcl_Interp *interp)
{
    Ttk_Theme themePtr = Ttk_GetDefaultTheme(interp);
    RegisterWidget(interp, "ttk::panedwindow", &PanedWidgetSpec);

    Ttk_RegisterElement(interp, themePtr, "hsash", &SashElementSpec, 0);

Changes to generic/ttk/ttkProgress.c.

1
2

3
4
5
6

7


8
9
10
11
12
13
14
1

2
3
4
5
6
7

8
9
10
11
12
13
14
15
16

-
+




+
-
+
+







/*
 * Copyright © Joe English, Pat Thoyts, Michael Kirkham
 * Copyright (c) Joe English, Pat Thoyts, Michael Kirkham
 *
 * ttk::progressbar widget.
 */

#include <math.h>
#include "tkInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"

/*------------------------------------------------------------------------
 * +++ Widget record:
 */

44
45
46
47
48
49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66

67
68
69

70
71
72
73
74



75
76
77


78
79

80
81
82

83
84
85

86
87
88

89
90
91

92
93
94
95
96
97
98
46
47
48
49
50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67

68
69
70

71
72
73



74
75
76
77


78
79
80

81
82
83

84
85
86

87
88
89

90
91
92

93
94
95
96
97
98
99
100







-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
-
-
+
+
+

-
-
+
+

-
+


-
+


-
+


-
+


-
+







} ProgressbarPart;

typedef struct {
    WidgetCore 		core;
    ProgressbarPart	progress;
} Progressbar;

static const Tk_OptionSpec ProgressbarOptionSpecs[] =
static Tk_OptionSpec ProgressbarOptionSpecs[] =
{
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	"w", offsetof(Progressbar,progress.anchorObj), TCL_INDEX_NONE,
	"w", Tk_Offset(Progressbar,progress.anchorObj), -1,
	TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED},
    {TK_OPTION_FONT, "-font", "font", "Font",
	DEFAULT_FONT, offsetof(Progressbar,progress.fontObj), TCL_INDEX_NONE,
	DEFAULT_FONT, Tk_Offset(Progressbar,progress.fontObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
	"black", offsetof(Progressbar,progress.foregroundObj), TCL_INDEX_NONE,
	"black", Tk_Offset(Progressbar,progress.foregroundObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
	"left", offsetof(Progressbar,progress.justifyObj), TCL_INDEX_NONE,
	"left", Tk_Offset(Progressbar,progress.justifyObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_PIXELS, "-length", "length", "Length",
	DEF_PROGRESSBAR_LENGTH, offsetof(Progressbar,progress.lengthObj), TCL_INDEX_NONE,
        DEF_PROGRESSBAR_LENGTH, Tk_Offset(Progressbar,progress.lengthObj), -1,
	0, 0, GEOMETRY_CHANGED },
    {TK_OPTION_DOUBLE, "-maximum", "maximum", "Maximum",
	"100.0", offsetof(Progressbar,progress.maximumObj), TCL_INDEX_NONE,
	"100", Tk_Offset(Progressbar,progress.maximumObj), -1,
	0, 0, 0 },
    {TK_OPTION_STRING_TABLE, "-mode", "mode", "ProgressMode", "determinate",
	offsetof(Progressbar,progress.modeObj),
	offsetof(Progressbar,progress.mode),
	0, ProgressbarModeStrings, 0 },
	Tk_Offset(Progressbar,progress.modeObj),
	Tk_Offset(Progressbar,progress.mode),
	0, (ClientData)ProgressbarModeStrings, 0 },
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
	"horizontal", offsetof(Progressbar,progress.orientObj), TCL_INDEX_NONE,
	0, ttkOrientStrings, STYLE_CHANGED },
	"horizontal", Tk_Offset(Progressbar,progress.orientObj), -1,
	0, (ClientData)ttkOrientStrings, STYLE_CHANGED },
    {TK_OPTION_INT, "-phase", "phase", "Phase",
	"0", offsetof(Progressbar,progress.phaseObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Progressbar,progress.phaseObj), -1,
	0, 0, 0 },
    {TK_OPTION_STRING, "-text", "text", "Text", "",
	offsetof(Progressbar,progress.textObj), TCL_INDEX_NONE,
	Tk_Offset(Progressbar,progress.textObj), -1,
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_DOUBLE, "-value", "value", "Value",
	"0.0", offsetof(Progressbar,progress.valueObj), TCL_INDEX_NONE,
	"0.0", Tk_Offset(Progressbar,progress.valueObj), -1,
	0, 0, 0 },
    {TK_OPTION_STRING, "-variable", "variable", "Variable",
	NULL, offsetof(Progressbar,progress.variableObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Progressbar,progress.variableObj), -1,
	TK_OPTION_NULL_OK, 0, 0 },
    {TK_OPTION_PIXELS, "-wraplength", "wrapLength", "WrapLength",
	"0", offsetof(Progressbar, progress.wrapLengthObj), TCL_INDEX_NONE,
	"0", Tk_Offset(Progressbar, progress.wrapLengthObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED},

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*------------------------------------------------------------------------
116
117
118
119
120
121
122
123

124
125

126
127

128
129
130
131
132
133
134
135
136
137
138


139
140
141

142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
118
119
120
121
122
123
124

125
126

127
128
129
130
131
132
133
134
135
136
137

138


139
140

141

142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187







-
+

-
+


+







-

-
-
+
+
-

-
+





-


+













-
+















-
+







}

/* AnimateProgressProc --
 * 	Timer callback for progress bar animation.
 * 	Increments the -phase option, redisplays the widget,
 * 	and reschedules itself if animation still enabled.
 */
static void AnimateProgressProc(void *clientData)
static void AnimateProgressProc(ClientData clientData)
{
    Progressbar *pb = (Progressbar *)clientData;
    Progressbar *pb = clientData;

    pb->progress.timer = 0;

    if (AnimationEnabled(pb)) {
	int phase = 0;
	Tcl_GetIntFromObj(NULL, pb->progress.phaseObj, &phase);

	/*
	 * Update -phase:
	 */

	++phase;
	if (phase > pb->progress.maxPhase) {
	    phase = 0;
	if (pb->progress.maxPhase)
	    phase %= pb->progress.maxPhase;
	}
	Tcl_DecrRefCount(pb->progress.phaseObj);
	pb->progress.phaseObj = Tcl_NewWideIntObj(phase);
	pb->progress.phaseObj = Tcl_NewIntObj(phase);
	Tcl_IncrRefCount(pb->progress.phaseObj);

	/*
	 * Reschedule:
	 */

	pb->progress.timer = Tcl_CreateTimerHandler(
	    pb->progress.period, AnimateProgressProc, clientData);

	TtkRedisplayWidget(&pb->core);
    }
}

/* CheckAnimation --
 * 	If animation is enabled and not scheduled, schedule it.
 * 	If animation is disabled but scheduled, cancel it.
 */
static void CheckAnimation(Progressbar *pb)
{
    if (AnimationEnabled(pb)) {
	if (pb->progress.timer == 0) {
	    pb->progress.timer = Tcl_CreateTimerHandler(
		pb->progress.period, AnimateProgressProc, pb);
		pb->progress.period, AnimateProgressProc, (ClientData)pb);
	}
    } else {
	if (pb->progress.timer != 0) {
	    Tcl_DeleteTimerHandler(pb->progress.timer);
	    pb->progress.timer = 0;
	}
    }
}

/*------------------------------------------------------------------------
 * +++ Trace hook for progressbar -variable option:
 */

static void VariableChanged(void *recordPtr, const char *value)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    Tcl_Obj *newValue;
    double scratch;

    if (WidgetDestroyed(&pb->core)) {
	return;
    }

205
206
207
208
209
210
211
212

213
214
215
216

217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
206
207
208
209
210
211
212

213


214

215

216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+
-
-

-
+
-






-
+













-
+







    TtkRedisplayWidget(&pb->core);
}

/*------------------------------------------------------------------------
 * +++ Widget class methods:
 */

static void ProgressbarInitialize(
static void ProgressbarInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;

    pb->progress.variableTrace = 0;
    pb->progress.timer = 0;
}

static void ProgressbarCleanup(void *recordPtr)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    if (pb->progress.variableTrace)
	Ttk_UntraceVariable(pb->progress.variableTrace);
    if (pb->progress.timer)
	Tcl_DeleteTimerHandler(pb->progress.timer);
}

/*
 * Configure hook:
 *
 * @@@ TODO: deal with [$pb configure -value ... -variable ...]
 */
static int ProgressbarConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    Tcl_Obj *varName = pb->progress.variableObj;
    Ttk_TraceHandle *vt = 0;

    if (varName != NULL && *Tcl_GetString(varName) != '\0') {
	vt = Ttk_TraceVariable(interp, varName, VariableChanged, recordPtr);
	if (!vt) return TCL_ERROR;
    }
257
258
259
260
261
262
263
264
265

266
267
268

269
270
271
272
273
274
275
255
256
257
258
259
260
261


262

263

264
265
266
267
268
269
270
271







-
-
+
-

-
+







    return TCL_OK;
}

/*
 * Post-configuration hook:
 */
static int ProgressbarPostConfigure(
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr,
    Tcl_Interp *interp, void *recordPtr, int mask)
    TCL_UNUSED(int))
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    int status = TCL_OK;

    if (pb->progress.variableTrace) {
	status = Ttk_FireTrace(pb->progress.variableTrace);
	if (WidgetDestroyed(&pb->core)) {
	    return TCL_ERROR;
	}
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
286
287
288
289
290
291
292


293
294

295
296
297
298
299
300
301







-
-
+
+
-








/*
 * Size hook:
 * 	Compute base layout size, overrid
 */
static int ProgressbarSize(void *recordPtr, int *widthPtr, int *heightPtr)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    int length = 100;
    Progressbar *pb = recordPtr;
    int length = 100, orient = TTK_ORIENT_HORIZONTAL;
    Ttk_Orient orient = TTK_ORIENT_HORIZONTAL;

    TtkWidgetSize(recordPtr, widthPtr, heightPtr);

    /* Override requested width (height) based on -length and -orient
     */
    Tk_GetPixelsFromObj(NULL, pb->core.tkwin, pb->progress.lengthObj, &length);
    Ttk_GetOrientFromObj(NULL, pb->progress.orientObj, &orient);
359
360
361
362
363
364
365
366

367
368
369
370

371
372
373
374
375
376
377
354
355
356
357
358
359
360

361
362
363
364

365
366
367
368
369
370
371
372







-
+



-
+







	pbarBox.y = parcel.y + (int)(fraction * (parcel.height-pbarBox.height));
    }
    Ttk_PlaceElement(pb->core.layout, pbar, pbarBox);
}

static void ProgressbarDoLayout(void *recordPtr)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    WidgetCore *corePtr = &pb->core;
    Ttk_Element pbar = Ttk_FindElement(corePtr->layout, "pbar");
    double value = 0.0, maximum = 100.0;
    Ttk_Orient orient = TTK_ORIENT_HORIZONTAL;
    int orient = TTK_ORIENT_HORIZONTAL;

    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));

    /* Adjust the bar size:
     */

    Tcl_GetDoubleFromObj(NULL, pb->progress.valueObj, &value);
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400







-
+







	}
    }
}

static Ttk_Layout ProgressbarGetLayout(
    Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    Ttk_Layout layout = TtkWidgetGetOrientedLayout(
	interp, theme, recordPtr, pb->progress.orientObj);

    /*
     * Check if the style supports animation:
     */
    pb->progress.period = 0;
419
420
421
422
423
424
425
426

427
428

429
430
431
432
433
434
435
414
415
416
417
418
419
420

421
422

423
424
425
426
427
428
429
430







-
+

-
+







/*------------------------------------------------------------------------
 * +++ Widget commands:
 */

/* $sb step ?amount?
 */
static int ProgressbarStepCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Progressbar *pb = (Progressbar *)recordPtr;
    Progressbar *pb = recordPtr;
    double value = 0.0, stepAmount = 1.0;
    Tcl_Obj *newValueObj;

    if (objc == 3) {
	if (Tcl_GetDoubleFromObj(interp, objv[2], &stepAmount) != TCL_OK) {
	    return TCL_ERROR;
	}
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463




464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508

509
510
511
512
513
514
515

516
517
518

519
520
521
522
523

524
525
526
527
528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
441
442
443
444
445
446
447

448
449
450
451
452
453




454
455
456
457


458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494




495
496
497

498
499
500
501




502
503
504

505
506
507
508

509
510
511
512
513
514
515
516

517
518
519
520
521
522

523
524
525
526
527
528
529
530







-






-
-
-
-
+
+
+
+
-
-




+












-
+









-
+









-
-
-
-
+


-
+



-
-
-
-
+


-
+



-

+






-






-
+







    if (pb->progress.mode == TTK_PROGRESSBAR_DETERMINATE) {
	double maximum = 100.0;
	(void)Tcl_GetDoubleFromObj(NULL, pb->progress.maximumObj, &maximum);
	value = fmod(value, maximum);
    }

    newValueObj = Tcl_NewDoubleObj(value);
    Tcl_IncrRefCount(newValueObj);

    TtkRedisplayWidget(&pb->core);

    /* Update value by setting the linked -variable, if there is one:
     */
    if (pb->progress.variableTrace) {
	int result = Tcl_ObjSetVar2(
		        interp, pb->progress.variableObj, 0, newValueObj,
		        TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG)
	        ? TCL_OK : TCL_ERROR;
	return Tcl_ObjSetVar2(
		    interp, pb->progress.variableObj, 0, newValueObj,
		    TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG)
	    ? TCL_OK : TCL_ERROR;
        Tcl_DecrRefCount(newValueObj);
        return result;
    }

    /* Otherwise, change the -value directly:
     */
    Tcl_IncrRefCount(newValueObj);
    Tcl_DecrRefCount(pb->progress.valueObj);
    pb->progress.valueObj = newValueObj;
    CheckAnimation(pb);

    return TCL_OK;
}

/* $sb start|stop ?args? --
 * Change [$sb $cmd ...] to [ttk::progressbar::$cmd ...]
 * and pass to interpreter.
 */
static int ProgressbarStartStopCommand(
    Tcl_Interp *interp, const char *cmdName, Tcl_Size objc, Tcl_Obj *const objv[])
    Tcl_Interp *interp, const char *cmdName, int objc, Tcl_Obj *const objv[])
{
    Tcl_Obj *cmd = Tcl_NewListObj(objc, objv);
    Tcl_Obj *prefix[2];
    int status;

    /* ASSERT: objc >= 2 */

    prefix[0] = Tcl_NewStringObj(cmdName, -1);
    prefix[1] = objv[0];
    Tcl_ListObjReplace(interp, cmd, 0, 2, 2,prefix);
    Tcl_ListObjReplace(interp, cmd, 0,2, 2,prefix);

    Tcl_IncrRefCount(cmd);
    status = Tcl_EvalObjEx(interp, cmd, 0);
    Tcl_DecrRefCount(cmd);

    return status;
}

static int ProgressbarStartCommand(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    return ProgressbarStartStopCommand(
	    interp, "::ttk::progressbar::start", objc, objv);
	interp, "::ttk::progressbar::start", objc, objv);
}

static int ProgressbarStopCommand(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    return ProgressbarStartStopCommand(
	    interp, "::ttk::progressbar::stop", objc, objv);
	interp, "::ttk::progressbar::stop", objc, objv);
}

static const Ttk_Ensemble ProgressbarCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "start", 		ProgressbarStartCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "step", 		ProgressbarStepCommand,0 },
    { "stop", 		ProgressbarStopCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

/*
 * Widget specification:
 */
static const WidgetSpec ProgressbarWidgetSpec =
static WidgetSpec ProgressbarWidgetSpec =
{
    "TProgressbar",		/* className */
    sizeof(Progressbar),	/* recordSize */
    ProgressbarOptionSpecs,	/* optionSpecs */
    ProgressbarCommands,	/* subcommands */
    ProgressbarInitialize,	/* initializeProc */
    ProgressbarCleanup,		/* cleanupProc */
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
543
544
545
546
547
548
549

550
551
552
553
554
555
556



557
558
559
560
561
562
563







-
+






-
-
-







    TTK_GROUP("Vertical.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Vertical.Progressbar.pbar", TTK_PACK_BOTTOM|TTK_FILL_X))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout)
    TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)
	TTK_NODE("Horizontal.Progressbar.ctext", TTK_PACK_LEFT))
	TTK_NODE("Horizontal.Progressbar.text", TTK_PACK_LEFT))
TTK_END_LAYOUT

/*
 * Initialization:
 */

MODULE_SCOPE
void TtkProgressbar_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkProgressbar_Init(Tcl_Interp *interp)
{
    Ttk_Theme themePtr = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(themePtr,
	"Vertical.TProgressbar", VerticalProgressbarLayout);

Changes to generic/ttk/ttkScale.c.

1
2

3
4
5
6
7



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56

57
58
59
60


61
62
63
64



65
66
67


68
69
70
71



72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117

118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171

172
173
174
175
176
177
178
1

2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17




18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37





38
39
40
41
42
43
44
45

46
47
48

49
50
51


52
53
54



55
56
57
58


59
60
61



62
63
64
65

66
67
68




69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102


103

104

105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141




142
143
144
145
146
147
148


149

150

151
152
153
154
155
156
157
158

-
+




-
+
+
+








-
-
-
-




















-
-
-
-
-








-
+


-
+


-
-
+
+

-
-
-
+
+
+

-
-
+
+

-
-
-
+
+
+

-
+


-
-
-
-















-
+

















-
+
-
-

-
+
-





-
+












-
+


















-
-
-
-







-
-
+
-

-
+







/*
 * Copyright © 2004 Pat Thoyts <[email protected]>
 * Copyright (C) 2004 Pat Thoyts <[email protected]>
 *
 * ttk::scale widget.
 */

#include "tkInt.h"
#include <tk.h>
#include <string.h>
#include <stdio.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

#define DEF_SCALE_LENGTH "100"

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))

/* Bit fields for OptionSpec mask field:
 */
#define STATE_CHANGED	 	(0x100)		/* -state option changed */

/*
 * Scale widget record
 */
typedef struct
{
    /* slider element options */
    Tcl_Obj *fromObj;         /* minimum value */
    Tcl_Obj *toObj;           /* maximum value */
    Tcl_Obj *valueObj;        /* current value */
    Tcl_Obj *lengthObj;       /* length of the long axis of the scale */
    Tcl_Obj *orientObj;       /* widget orientation */
    int orient;

    /* widget options */
    Tcl_Obj *commandObj;
    Tcl_Obj *variableObj;

    /* internal state */
    Ttk_TraceHandle *variableTrace;

    /*
     * Compatibility/legacy options:
     */
    Tcl_Obj *stateObj;

} ScalePart;

typedef struct
{
    WidgetCore core;
    ScalePart  scale;
} Scale;

static const Tk_OptionSpec ScaleOptionSpecs[] =
static Tk_OptionSpec ScaleOptionSpecs[] =
{
    {TK_OPTION_STRING, "-command", "command", "Command", "",
	offsetof(Scale,scale.commandObj), TCL_INDEX_NONE,
	Tk_Offset(Scale,scale.commandObj), -1,
	TK_OPTION_NULL_OK,0,0},
    {TK_OPTION_STRING, "-variable", "variable", "Variable", "",
	offsetof(Scale,scale.variableObj), TCL_INDEX_NONE,
	0, 0, 0},
	Tk_Offset(Scale,scale.variableObj), -1,
	0,0,0},
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "horizontal",
	offsetof(Scale,scale.orientObj),
	offsetof(Scale,scale.orient),
	0, ttkOrientStrings, STYLE_CHANGED },
	Tk_Offset(Scale,scale.orientObj),
	Tk_Offset(Scale,scale.orient), 0,
	(ClientData)ttkOrientStrings, STYLE_CHANGED },

    {TK_OPTION_DOUBLE, "-from", "from", "From", "0.0",
	offsetof(Scale,scale.fromObj), TCL_INDEX_NONE, 0, 0, 0},
    {TK_OPTION_DOUBLE, "-from", "from", "From", "0",
	Tk_Offset(Scale,scale.fromObj), -1, 0, 0, 0},
    {TK_OPTION_DOUBLE, "-to", "to", "To", "1.0",
	offsetof(Scale,scale.toObj), TCL_INDEX_NONE, 0, 0, 0},
    {TK_OPTION_DOUBLE, "-value", "value", "Value", "0.0",
	offsetof(Scale,scale.valueObj), TCL_INDEX_NONE, 0, 0, 0},
	Tk_Offset(Scale,scale.toObj), -1, 0, 0, 0},
    {TK_OPTION_DOUBLE, "-value", "value", "Value", "0",
	Tk_Offset(Scale,scale.valueObj), -1, 0, 0, 0},
    {TK_OPTION_PIXELS, "-length", "length", "Length",
	DEF_SCALE_LENGTH, offsetof(Scale,scale.lengthObj), TCL_INDEX_NONE, 0, 0,
	DEF_SCALE_LENGTH, Tk_Offset(Scale,scale.lengthObj), -1, 0, 0,
    	GEOMETRY_CHANGED},

    {TK_OPTION_STRING, "-state", "state", "State",
	"normal", offsetof(Scale,scale.stateObj), TCL_INDEX_NONE,
        0, 0, STATE_CHANGED},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

static XPoint ValueToPoint(Scale *scalePtr, double value);
static double PointToValue(Scale *scalePtr, int x, int y);

/* ScaleVariableChanged --
 * 	Variable trace procedure for scale -variable;
 * 	Updates the scale's value.
 * 	If the linked variable is not a valid double,
 * 	sets the 'invalid' state.
 */
static void ScaleVariableChanged(void *recordPtr, const char *value)
{
    Scale *scale = (Scale *)recordPtr;
    Scale *scale = recordPtr;
    double v;

    if (value == NULL || Tcl_GetDouble(0, value, &v) != TCL_OK) {
	TtkWidgetChangeState(&scale->core, TTK_STATE_INVALID, 0);
    } else {
	Tcl_Obj *valueObj = Tcl_NewDoubleObj(v);
	Tcl_IncrRefCount(valueObj);
	Tcl_DecrRefCount(scale->scale.valueObj);
	scale->scale.valueObj = valueObj;
	TtkWidgetChangeState(&scale->core, 0, TTK_STATE_INVALID);
    }
    TtkRedisplayWidget(&scale->core);
}

/* ScaleInitialize --
 * 	Scale widget initialization hook.
 */
static void ScaleInitialize(
static void ScaleInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Scale *scalePtr = (Scale *)recordPtr;
    Scale *scalePtr = recordPtr;

    TtkTrackElementState(&scalePtr->core);
}

static void ScaleCleanup(void *recordPtr)
{
    Scale *scale = (Scale *)recordPtr;
    Scale *scale = recordPtr;

    if (scale->scale.variableTrace) {
	Ttk_UntraceVariable(scale->scale.variableTrace);
	scale->scale.variableTrace = 0;
    }
}

/* ScaleConfigure --
 * 	Configuration hook.
 */
static int ScaleConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Scale *scale = (Scale *)recordPtr;
    Scale *scale = recordPtr;
    Tcl_Obj *varName = scale->scale.variableObj;
    Ttk_TraceHandle *vt = 0;

    if (varName != NULL && *Tcl_GetString(varName) != '\0') {
	vt = Ttk_TraceVariable(interp,varName, ScaleVariableChanged,recordPtr);
	if (!vt) return TCL_ERROR;
    }

    if (TtkCoreConfigure(interp, recordPtr, mask) != TCL_OK) {
	if (vt) Ttk_UntraceVariable(vt);
	return TCL_ERROR;
    }

    if (scale->scale.variableTrace) {
	Ttk_UntraceVariable(scale->scale.variableTrace);
    }
    scale->scale.variableTrace = vt;

    if (mask & STATE_CHANGED) {
	TtkCheckStateOption(&scale->core, scale->scale.stateObj);
    }

    return TCL_OK;
}

/* ScalePostConfigure --
 * 	Post-configuration hook.
 */
static int ScalePostConfigure(
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr,
    Tcl_Interp *interp, void *recordPtr, int mask)
    TCL_UNUSED(int))
{
    Scale *scale = (Scale *)recordPtr;
    Scale *scale = recordPtr;
    int status = TCL_OK;

    if (scale->scale.variableTrace) {
	status = Ttk_FireTrace(scale->scale.variableTrace);
	if (WidgetDestroyed(&scale->core)) {
	    return TCL_ERROR;
	}
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185







-
+








/* ScaleGetLayout --
 *	getLayout hook.
 */
static Ttk_Layout
ScaleGetLayout(Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Scale *scalePtr = (Scale *)recordPtr;
    Scale *scalePtr = recordPtr;
    return TtkWidgetGetOrientedLayout(
	interp, theme, recordPtr, scalePtr->scale.orientObj);
}

/*
 * TroughBox --
 * 	Returns the inner area of the trough element.
257
258
259
260
261
262
263
264

265
266

267
268
269




270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293

294
295
296
297
298
299
300
237
238
239
240
241
242
243

244
245

246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263



264
265
266
267
268
269
270
271

272
273

274
275
276
277
278
279
280
281







-
+

-
+



+
+
+
+


-
+







-
-
-








-
+

-
+








/* $scale get ?x y? --
 * 	Returns the current value of the scale widget, or if $x and
 * 	$y are specified, the value represented by point @x,y.
 */
static int
ScaleGetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scale *scalePtr = (Scale *)recordPtr;
    Scale *scalePtr = recordPtr;
    int x, y, r = TCL_OK;
    double value = 0;

    if ((objc != 2) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 1, objv, "get ?x y?");
	return TCL_ERROR;
    }
    if (objc == 2) {
	Tcl_SetObjResult(interp, scalePtr->scale.valueObj);
    } else if (objc == 4) {
    } else {
	r = Tcl_GetIntFromObj(interp, objv[2], &x);
	if (r == TCL_OK)
	    r = Tcl_GetIntFromObj(interp, objv[3], &y);
	if (r == TCL_OK) {
	    value = PointToValue(scalePtr, x, y);
	    Tcl_SetObjResult(interp, Tcl_NewDoubleObj(value));
	}
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "get ?x y?");
	return TCL_ERROR;
    }
    return r;
}

/* $scale set $newValue
 */
static int
ScaleSetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scale *scalePtr = (Scale *)recordPtr;
    Scale *scalePtr = recordPtr;
    double from = 0.0, to = 1.0, value;
    int result = TCL_OK;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "set value");
	return TCL_ERROR;
    }
352
353
354
355
356
357
358
359

360
361

362
363





364
365
366
367

368
369
370
371
372
373
374
375
376
377
378


379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
333
334
335
336
337
338
339

340
341

342
343
344
345
346
347
348
349
350
351
352

353
354



355
356
357
358
359


360
361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384







-
+

-
+


+
+
+
+
+



-
+

-
-
-





-
-
+
+







-
+







-
+







    }

    return result;
}

static int
ScaleCoordsCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scale *scalePtr = (Scale *)recordPtr;
    Scale *scalePtr = recordPtr;
    double value;
    int r = TCL_OK;

    if (objc < 2 || objc > 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "coords ?value?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	r = Tcl_GetDoubleFromObj(interp, objv[2], &value);
    } else if (objc == 2) {
    } else {
	r = Tcl_GetDoubleFromObj(interp, scalePtr->scale.valueObj, &value);
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "coords ?value?");
	return TCL_ERROR;
    }

    if (r == TCL_OK) {
	Tcl_Obj *point[2];
	XPoint pt = ValueToPoint(scalePtr, value);
	point[0] = Tcl_NewWideIntObj(pt.x);
	point[1] = Tcl_NewWideIntObj(pt.y);
	point[0] = Tcl_NewIntObj(pt.x);
	point[1] = Tcl_NewIntObj(pt.y);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, point));
    }
    return r;
}

static void ScaleDoLayout(void *clientData)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    Ttk_Element slider = Ttk_FindElement(corePtr->layout, "slider");

    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));

    /* Adjust the slider position:
     */
    if (slider) {
	Scale *scalePtr = (Scale *)clientData;
	Scale *scalePtr = clientData;
	Ttk_Box troughBox = TroughBox(scalePtr);
	Ttk_Box sliderBox = Ttk_ElementParcel(slider);
	double value = 0.0;
	double fraction;
	int range;

	Tcl_GetDoubleFromObj(NULL, scalePtr->scale.valueObj, &value);
414
415
416
417
418
419
420
421
422


423
424
425
426
427
428
429
397
398
399
400
401
402
403


404
405
406
407
408
409
410
411
412







-
-
+
+








/*
 * ScaleSize --
 * 	Compute requested size of scale.
 */
static int ScaleSize(void *clientData, int *widthPtr, int *heightPtr)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    Scale *scalePtr = (Scale *)clientData;
    WidgetCore *corePtr = clientData;
    Scale *scalePtr = clientData;
    int length;

    Ttk_LayoutSize(corePtr->layout, corePtr->state, widthPtr, heightPtr);

    /* Assert the -length configuration option */
    Tk_GetPixelsFromObj(NULL, corePtr->tkwin,
	    scalePtr->scale.lengthObj, &length);
475
476
477
478
479
480
481
482
483
484
485
486


487

488
489
490


491
492
493
494

495
496
497
498
499
500
501
458
459
460
461
462
463
464

465



466
467
468
469
470


471
472
473
474
475

476
477
478
479
480
481
482
483







-

-
-
-
+
+

+

-
-
+
+



-
+







	pt.x = troughBox.x + troughBox.width / 2;
	pt.y = troughBox.y + (int)(fraction * troughBox.height);
    }
    return pt;
}

static const Ttk_Ensemble ScaleCommands[] = {
    { "cget",        TtkWidgetCgetCommand,0 },
    { "configure",   TtkWidgetConfigureCommand,0 },
    { "coords",      ScaleCoordsCommand,0 },
    { "get",         ScaleGetCommand,0 },
    { "identify",    TtkWidgetIdentifyCommand,0 },
    { "cget",        TtkWidgetCgetCommand,0 },
    { "state",       TtkWidgetStateCommand,0 },
    { "instate",     TtkWidgetInstateCommand,0 },
    { "identify",    TtkWidgetIdentifyCommand,0 },
    { "set",         ScaleSetCommand,0 },
    { "state",       TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "get",         ScaleGetCommand,0 },
    { "coords",      ScaleCoordsCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec ScaleWidgetSpec =
static WidgetSpec ScaleWidgetSpec =
{
    "TScale",			/* Class name */
    sizeof(Scale),		/* record size */
    ScaleOptionSpecs,		/* option specs */
    ScaleCommands,		/* widget commands */
    ScaleInitialize,		/* initialization proc */
    ScaleCleanup,		/* cleanup proc */
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
498
499
500
501
502
503
504



505
506
507
508
509
510
511
512
513
514
515







-
-
-











    TTK_GROUP("Horizontal.Scale.trough", TTK_FILL_BOTH,
	TTK_NODE("Horizontal.Scale.slider", TTK_PACK_LEFT) )
TTK_END_LAYOUT

/*
 * Initialization.
 */
MODULE_SCOPE
void TtkScale_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkScale_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(theme, "Vertical.TScale", VerticalScaleLayout);
    Ttk_RegisterLayout(theme, "Horizontal.TScale", HorizontalScaleLayout);

    RegisterWidget(interp, "ttk::scale", &ScaleWidgetSpec);
}

Changes to generic/ttk/ttkScroll.c.

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







-
+




















-
+







 * If the widget value changes, it should call TtkScrolled() (step 4).
 * (This usually happens automatically when the widget is redisplayed).
 *
 * If the scrollee's -[xy]scrollcommand changes, it should call
 * TtkScrollbarUpdateRequired, which will invoke step (5) (@@@ Fix this)
 */

#include "tkInt.h"
#include <tkInt.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

/* Private data:
 */
#define SCROLL_UPDATE_PENDING  (0x1)
#define SCROLL_UPDATE_REQUIRED (0x2)

struct ScrollHandleRec
{
    unsigned 	flags;
    WidgetCore	*corePtr;
    Scrollable	*scrollPtr;
};

/* TtkCreateScrollHandle --
 * 	Initialize scroll handle.
 */
ScrollHandle TtkCreateScrollHandle(WidgetCore *corePtr, Scrollable *scrollPtr)
{
    ScrollHandle h = (ScrollHandle)ckalloc(sizeof(*h));
    ScrollHandle h = ckalloc(sizeof(*h));

    h->flags = 0;
    h->corePtr = corePtr;
    h->scrollPtr = scrollPtr;

    scrollPtr->first = 0;
    scrollPtr->last = 1;
86
87
88
89
90
91
92
93
94
95



96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112


113
114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133

134
135
136
137
138

139
140
141
142
143
144
145
86
87
88
89
90
91
92



93
94
95
96
97
98
99
100
101
102
103
104
105
106



107


108
109
110
111
112
113
114
115

116
117
118
119
120
121
122

123
124
125
126
127
128
129

130
131
132
133
134

135
136
137
138
139
140
141
142







-
-
-
+
+
+











-
-
-
+
-
-

+
+





-







-
+






-
+




-
+







	return TCL_OK;
    }

    arg1[0] = arg2[0] = ' ';
    Tcl_PrintDouble(interp, (double)s->first / s->total, arg1+1);
    Tcl_PrintDouble(interp, (double)s->last / s->total, arg2+1);
    Tcl_DStringInit(&buf);
    Tcl_DStringAppend(&buf, s->scrollCmd, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, arg1, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, arg2, TCL_INDEX_NONE);
    Tcl_DStringAppend(&buf, s->scrollCmd, -1);
    Tcl_DStringAppend(&buf, arg1, -1);
    Tcl_DStringAppend(&buf, arg2, -1);

    Tcl_Preserve(corePtr);
    code = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, TCL_EVAL_GLOBAL);
    Tcl_DStringFree(&buf);
    if (WidgetDestroyed(corePtr)) {
	Tcl_Release(corePtr);
	return TCL_ERROR;
    }
    Tcl_Release(corePtr);

    if (code != TCL_OK && !Tcl_InterpDeleted(interp)) {
	/* Add error to stack trace.
         * Also set the SCROLL_UPDATE_REQUIRED flag so that a later call to
         * TtkScrolled has an effect. Indeed, the error in the -scrollcommand
	/* Disable the -scrollcommand, add to stack trace:
         * callback may later be gone, for instance the callback proc got
         * defined in the meantime.
	 */
	ckfree(s->scrollCmd);
	s->scrollCmd = 0;

	Tcl_AddErrorInfo(interp, /* @@@ "horizontal" / "vertical" */
		"\n    (scrolling command executed by ");
	Tcl_AddErrorInfo(interp, Tk_PathName(h->corePtr->tkwin));
	Tcl_AddErrorInfo(interp, ")");
        TtkScrollbarUpdateRequired(h);
    }
    return code;
}

/* UpdateScrollbarBG --
 * 	Idle handler to update the scrollbar.
 */
static void UpdateScrollbarBG(void *clientData)
static void UpdateScrollbarBG(ClientData clientData)
{
    ScrollHandle h = (ScrollHandle)clientData;
    Tcl_Interp *interp = h->corePtr->interp;
    int code;

    h->flags &= ~SCROLL_UPDATE_PENDING;
    Tcl_Preserve(interp);
    Tcl_Preserve((ClientData) interp);
    code = UpdateScrollbar(interp, h);
    if (code == TCL_ERROR && !Tcl_InterpDeleted(interp)) {
	Tcl_BackgroundException(interp, code);
    }
    Tcl_Release(interp);
    Tcl_Release((ClientData) interp);
}

/* TtkScrolled --
 * 	Update scroll info, schedule scrollbar update.
 */
void TtkScrolled(ScrollHandle h, int first, int last, int total)
{
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183













184
185
186
187
188
189
190
191
192

193
194
195




196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225


226
227
228

229
230
231
232
233

234
235
236
237




238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258







-
+
















-
-
-
-
-
-
-
-
-
-
-
-
-









-
+


-
-
-
-
+
















+
+











-
-



-
+




-
+



-
-
-
-
















-
+




	    || (h->flags & SCROLL_UPDATE_REQUIRED))
    {
	s->first = first;
	s->last = last;
	s->total = total;

	if (!(h->flags & SCROLL_UPDATE_PENDING)) {
	    Tcl_DoWhenIdle(UpdateScrollbarBG, h);
	    Tcl_DoWhenIdle(UpdateScrollbarBG, (ClientData)h);
	    h->flags |= SCROLL_UPDATE_PENDING;
	}
    }
}

/* TtkScrollbarUpdateRequired --
 * 	Force a scrollbar update at the next call to TtkScrolled(),
 * 	even if scroll parameters haven't changed (e.g., if
 * 	-yscrollcommand has changed).
 */

void TtkScrollbarUpdateRequired(ScrollHandle h)
{
    h->flags |= SCROLL_UPDATE_REQUIRED;
}

/* TtkUpdateScrollInfo --
 * 	Call the layoutProc to update the scroll info first, last, and total.
 * 	Do it only if needed, that is when a redisplay is pending (which
 * 	indicates scroll info are possibly out of date).
 */

void TtkUpdateScrollInfo(ScrollHandle h)
{
    if (h->corePtr->flags & REDISPLAY_PENDING) {
        h->corePtr->widgetSpec->layoutProc(h->corePtr);
    }
}

/* TtkScrollviewCommand --
 * 	Widget [xy]view command implementation.
 *
 *  $w [xy]view -- return current view region
 *  $w [xy]view $index -- set topmost item
 *  $w [xy]view moveto $fraction
 *  $w [xy]view scroll $number $what -- scrollbar interface
 */
int TtkScrollviewCommand(
    Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], ScrollHandle h)
    Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], ScrollHandle h)
{
    Scrollable *s = h->scrollPtr;
    int newFirst;

    TtkUpdateScrollInfo(h);
    newFirst = s->first;
    int newFirst = s->first;

    if (objc == 2) {
	Tcl_Obj *result[2];
	result[0] = Tcl_NewDoubleObj((double)s->first / s->total);
	result[1] = Tcl_NewDoubleObj((double)s->last / s->total);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, result));
	return TCL_OK;
    } else if (objc == 3) {
	if (Tcl_GetIntFromObj(interp, objv[2], &newFirst) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	double fraction;
	int count;

	switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count)) {
	    case TK_SCROLL_ERROR:
		return TCL_ERROR;
	    case TK_SCROLL_MOVETO:
		newFirst = (int) ((fraction * s->total) + 0.5);
		break;
	    case TK_SCROLL_UNITS:
		newFirst = s->first + count;
		break;
	    case TK_SCROLL_PAGES: {
		int perPage = s->last - s->first;	/* @@@ */
		newFirst = s->first + count * perPage;
		break;
	    }
	    default:
		return TCL_ERROR;
	}
    }

    TtkScrollTo(h, newFirst, 0);
    TtkScrollTo(h, newFirst);

    return TCL_OK;
}

void TtkScrollTo(ScrollHandle h, int newFirst, int updateScrollInfo)
void TtkScrollTo(ScrollHandle h, int newFirst)
{
    Scrollable *s = h->scrollPtr;

    if (updateScrollInfo) {
        TtkUpdateScrollInfo(h);
    }

    if (newFirst >= s->total)
	newFirst = s->total - 1;
    if (newFirst > s->first && s->last >= s->total) /* don't scroll past end */
	newFirst = s->first;
    if (newFirst < 0)
	newFirst = 0;

    if (newFirst != s->first) {
	s->first = newFirst;
	TtkRedisplayWidget(h->corePtr);
    }
}

void TtkFreeScrollHandle(ScrollHandle h)
{
    if (h->flags & SCROLL_UPDATE_PENDING) {
	Tcl_CancelIdleCall(UpdateScrollbarBG, h);
	Tcl_CancelIdleCall(UpdateScrollbarBG, (ClientData)h);
    }
    ckfree(h);
}

Changes to generic/ttk/ttkScrollbar.c.

1
2

3
4
5
6
7


8
9
10
11
12
13
14
1

2
3
4
5
6

7
8
9
10
11
12
13
14
15

-
+




-
+
+







/*
 * Copyright © 2003 Joe English
 * Copyright (c) 2003, Joe English
 *
 * ttk::scrollbar widget.
 */

#include "tkInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"

/*------------------------------------------------------------------------
 * +++ Scrollbar widget record.
 */
typedef struct
27
28
29
30
31
32
33
34

35
36
37

38
39
40
41
42



43
44
45
46
47
48
49
50
51
52
53

54
55
56
57

58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
28
29
30
31
32
33
34

35
36
37

38
39
40



41
42
43
44
45
46
47
48
49
50
51
52
53

54


55

56

57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87







-
+


-
+


-
-
-
+
+
+










-
+
-
-

-
+
-









-
+













-
+








typedef struct
{
    WidgetCore core;
    ScrollbarPart scrollbar;
} Scrollbar;

static const Tk_OptionSpec ScrollbarOptionSpecs[] =
static Tk_OptionSpec ScrollbarOptionSpecs[] =
{
    {TK_OPTION_STRING, "-command", "command", "Command", "",
	offsetof(Scrollbar, scrollbar.commandObj), TCL_INDEX_NONE, 0, 0, 0},
	Tk_Offset(Scrollbar,scrollbar.commandObj), -1, 0,0,0},

    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "vertical",
	offsetof(Scrollbar, scrollbar.orientObj),
	offsetof(Scrollbar, scrollbar.orient),
	0, ttkOrientStrings, STYLE_CHANGED },
	Tk_Offset(Scrollbar,scrollbar.orientObj),
	Tk_Offset(Scrollbar,scrollbar.orient),
	0,(ClientData)ttkOrientStrings,STYLE_CHANGED },

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*------------------------------------------------------------------------
 * +++ Widget hooks.
 */

static void
ScrollbarInitialize(
ScrollbarInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    void *recordPtr)
{
    Scrollbar *sb = (Scrollbar *)recordPtr;
    Scrollbar *sb = recordPtr;

    sb->scrollbar.first = 0.0;
    sb->scrollbar.last = 1.0;

    TtkTrackElementState(&sb->core);
}

static Ttk_Layout ScrollbarGetLayout(
    Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Scrollbar *sb = (Scrollbar *)recordPtr;
    Scrollbar *sb = recordPtr;
    return TtkWidgetGetOrientedLayout(
	interp, theme, recordPtr, sb->scrollbar.orientObj);
}

/*
 * ScrollbarDoLayout --
 * 	Layout hook.  Adjusts the position of the scrollbar thumb.
 *
 * Side effects:
 * 	Sets sb->troughBox and sb->minSize.
 */
static void ScrollbarDoLayout(void *recordPtr)
{
    Scrollbar *sb = (Scrollbar *)recordPtr;
    Scrollbar *sb = recordPtr;
    WidgetCore *corePtr = &sb->core;
    Ttk_Element thumb;
    Ttk_Box thumbBox;
    int thumbWidth, thumbHeight;
    double first, last, size;
    int minSize;

129
130
131
132
133
134
135
136

137
138

139
140
141
142
143
144
145
127
128
129
130
131
132
133

134
135

136
137
138
139
140
141
142
143







-
+

-
+







 */

/* $sb set $first $last --
 * 	Set the position of the scrollbar.
 */
static int
ScrollbarSetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scrollbar *scrollbar = (Scrollbar *)recordPtr;
    Scrollbar *scrollbar = recordPtr;
    Tcl_Obj *firstObj, *lastObj;
    double first, last;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "first last");
	return TCL_ERROR;
    }
180
181
182
183
184
185
186
187

188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

211
212

213
214
215
216
217
218
219
178
179
180
181
182
183
184

185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209

210
211
212
213
214
215
216
217







-
+

-
+




















-
+

-
+







}

/* $sb get --
 * 	Returns the last thing passed to 'set'.
 */
static int
ScrollbarGetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scrollbar *scrollbar = (Scrollbar *)recordPtr;
    Scrollbar *scrollbar = recordPtr;
    Tcl_Obj *result[2];

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "");
	return TCL_ERROR;
    }

    result[0] = Tcl_NewDoubleObj(scrollbar->scrollbar.first);
    result[1] = Tcl_NewDoubleObj(scrollbar->scrollbar.last);
    Tcl_SetObjResult(interp, Tcl_NewListObj(2, result));

    return TCL_OK;
}

/* $sb delta $dx $dy --
 * 	Returns the percentage change corresponding to a mouse movement
 * 	of $dx, $dy.
 */
static int
ScrollbarDeltaCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scrollbar *sb = (Scrollbar *)recordPtr;
    Scrollbar *sb = recordPtr;
    double dx, dy;
    double delta = 0.0;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "dx dy");
	return TCL_ERROR;
    }
243
244
245
246
247
248
249
250

251
252

253
254
255
256
257
258
259
241
242
243
244
245
246
247

248
249

250
251
252
253
254
255
256
257







-
+

-
+








/* $sb fraction $x $y --
 * 	Returns a real number between 0 and 1 indicating  where  the
 * 	point given by x and y lies in the trough area of the scrollbar.
 */
static int
ScrollbarFractionCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Scrollbar *sb = (Scrollbar *)recordPtr;
    Scrollbar *sb = recordPtr;
    Ttk_Box b = sb->scrollbar.troughBox;
    int minSize = sb->scrollbar.minSize;
    double x, y;
    double fraction = 0.0;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "x y");
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

321

322
323
324
325
326
327

328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291

292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326

327
328
329
330
331
332
333



334
335
336
337
338
339
340
341
342
343
344
345







-

+







-






-
+



















+
-
+






+
-
+






-
-
-












    }

    Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fraction));
    return TCL_OK;
}

static const Ttk_Ensemble ScrollbarCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "delta",    	ScrollbarDeltaCommand,0 },
    { "fraction",    	ScrollbarFractionCommand,0 },
    { "get",    	ScrollbarGetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "set",  		ScrollbarSetCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Widget specification.
 */
static const WidgetSpec ScrollbarWidgetSpec =
static WidgetSpec ScrollbarWidgetSpec =
{
    "TScrollbar",		/* className */
    sizeof(Scrollbar),		/* recordSize */
    ScrollbarOptionSpecs,	/* optionSpecs */
    ScrollbarCommands,		/* subcommands */
    ScrollbarInitialize,	/* initializeProc */
    TtkNullCleanup,		/* cleanupProc */
    TtkCoreConfigure,		/* configureProc */
    TtkNullPostConfigure,	/* postConfigureProc */
    ScrollbarGetLayout,		/* getLayoutProc */
    TtkWidgetSize, 		/* sizeProc */
    ScrollbarDoLayout,		/* layoutProc */
    TtkWidgetDisplay		/* displayProc */
};

TTK_BEGIN_LAYOUT(VerticalScrollbarLayout)
    TTK_GROUP("Vertical.Scrollbar.trough", TTK_FILL_Y,
	TTK_NODE("Vertical.Scrollbar.uparrow", TTK_PACK_TOP)
	TTK_NODE("Vertical.Scrollbar.downarrow", TTK_PACK_BOTTOM)
	TTK_NODE(
	TTK_NODE("Vertical.Scrollbar.thumb", TTK_FILL_BOTH))
	    "Vertical.Scrollbar.thumb", TTK_PACK_TOP|TTK_EXPAND|TTK_FILL_BOTH))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalScrollbarLayout)
    TTK_GROUP("Horizontal.Scrollbar.trough", TTK_FILL_X,
	TTK_NODE("Horizontal.Scrollbar.leftarrow", TTK_PACK_LEFT)
	TTK_NODE("Horizontal.Scrollbar.rightarrow", TTK_PACK_RIGHT)
	TTK_NODE(
	TTK_NODE("Horizontal.Scrollbar.thumb", TTK_FILL_BOTH))
	"Horizontal.Scrollbar.thumb", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_BOTH))
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * +++ Initialization.
 */

MODULE_SCOPE
void TtkScrollbar_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkScrollbar_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(theme,"Vertical.TScrollbar",VerticalScrollbarLayout);
    Ttk_RegisterLayout(theme,"Horizontal.TScrollbar",HorizontalScrollbarLayout);

    RegisterWidget(interp, "ttk::scrollbar", &ScrollbarWidgetSpec);
}

/*EOF*/

Changes to generic/ttk/ttkSeparator.c.

1
2

3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29



30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
1

2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51

52
53
54
55
56

57
58
59
60
61
62

63
64
65
66
67
68
69
70

-
+




-
+
+

















-
+

-
-
-
+
+
+












-
+








-

+



-






-
+







/*
 * Copyright © 2004 Joe English
 * Copyright (c) 2004, Joe English
 *
 * ttk::separator and ttk::sizegrip widgets.
 */

#include "tkInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"

/* +++ Separator widget record:
 */
typedef struct
{
    Tcl_Obj	*orientObj;
    int 	orient;
} SeparatorPart;

typedef struct
{
    WidgetCore core;
    SeparatorPart separator;
} Separator;

static const Tk_OptionSpec SeparatorOptionSpecs[] = {
static Tk_OptionSpec SeparatorOptionSpecs[] = {
    {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "horizontal",
	offsetof(Separator,separator.orientObj),
	offsetof(Separator,separator.orient),
	0, ttkOrientStrings, STYLE_CHANGED },
	Tk_Offset(Separator,separator.orientObj),
	Tk_Offset(Separator,separator.orient),
	0,(ClientData)ttkOrientStrings,STYLE_CHANGED },

    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*
 * GetLayout hook --
 * 	Choose layout based on -orient option.
 */
static Ttk_Layout SeparatorGetLayout(
    Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
{
    Separator *sep = (Separator *)recordPtr;
    Separator *sep = recordPtr;
    return TtkWidgetGetOrientedLayout(
	interp, theme, recordPtr, sep->separator.orientObj);
}

/*
 * Widget commands:
 */
static const Ttk_Ensemble SeparatorCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

/*
 * Widget specification:
 */
static const WidgetSpec SeparatorWidgetSpec =
static WidgetSpec SeparatorWidgetSpec =
{
    "TSeparator",		/* className */
    sizeof(Separator),		/* recordSize */
    SeparatorOptionSpecs,	/* optionSpecs */
    SeparatorCommands,		/* subcommands */
    TtkNullInitialize,		/* initializeProc */
    TtkNullCleanup,		/* cleanupProc */
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94

95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
80
81
82
83
84
85
86

87
88
89
90
91
92

93
94
95
96
97

98
99
100

101
102
103
104
105
106
107
108







-
+





-

+



-



-
+







    TTK_NODE("Separator.separator", TTK_FILL_BOTH)
TTK_END_LAYOUT

/* +++ Sizegrip widget:
 * 	Has no options or methods other than the standard ones.
 */

static const Tk_OptionSpec SizegripOptionSpecs[] = {
static Tk_OptionSpec SizegripOptionSpecs[] = {
    WIDGET_TAKEFOCUS_FALSE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

static const Ttk_Ensemble SizegripCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

static const WidgetSpec SizegripWidgetSpec =
static WidgetSpec SizegripWidgetSpec =
{
    "TSizegrip",		/* className */
    sizeof(WidgetCore),		/* recordSize */
    SizegripOptionSpecs, 	/* optionSpecs */
    SizegripCommands,		/* subcommands */
    TtkNullInitialize,		/* initializeProc */
    TtkNullCleanup,		/* cleanupProc */
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
117
118
119
120
121
122
123



124
125
126
127
128
129
130
131
132
133
134
135
136







-
-
-













TTK_BEGIN_LAYOUT(SizegripLayout)
    TTK_NODE("Sizegrip.sizegrip", TTK_PACK_BOTTOM|TTK_STICK_S|TTK_STICK_E)
TTK_END_LAYOUT

/* +++ Initialization:
 */

MODULE_SCOPE
void TtkSeparator_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkSeparator_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    Ttk_RegisterLayout(theme, "TSeparator", SeparatorLayout);
    Ttk_RegisterLayout(theme, "TSizegrip", SizegripLayout);

    RegisterWidget(interp, "ttk::separator", &SeparatorWidgetSpec);
    RegisterWidget(interp, "ttk::sizegrip", &SizegripWidgetSpec);
}

/*EOF*/

Changes to generic/ttk/ttkSquare.c.

1

2
3
4
5
6

7
8
9
10
11
12
13

1
2
3
4
5

6
7
8
9
10
11
12
13
-
+




-
+







/* square.c - Copyright © 2004 Pat Thoyts <[email protected]>
/* square.c - Copyright (C) 2004 Pat Thoyts <[email protected]>
 *
 * Minimal sample ttk widget.
 */

#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

#if defined(TTK_SQUARE_WIDGET) || 1

#ifndef DEFAULT_BORDERWIDTH
#define DEFAULT_BORDERWIDTH "2"
44
45
46
47
48
49
50
51

52
53
54

55
56
57
58


59
60
61

62
63
64

65
66
67
68

69
70
71
72

73
74
75

76
77
78
79
80
81
82
44
45
46
47
48
49
50

51
52
53

54
55
56


57
58
59
60

61
62
63

64
65
66
67

68
69
70
71

72
73
74

75
76
77
78
79
80
81
82







-
+


-
+


-
-
+
+


-
+


-
+



-
+



-
+


-
+







 * This structure is the same as the option specification structure used
 * for Tk widgets. For each option we provide the type, name and options
 * database name and class name and the position in the structure and
 * default values. At the bottom we bring in the standard widget option
 * defined for all widgets.
 */

static const Tk_OptionSpec SquareOptionSpecs[] =
static Tk_OptionSpec SquareOptionSpecs[] =
{
    {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
     DEFAULT_BORDERWIDTH, offsetof(Square,square.borderWidthObj), TCL_INDEX_NONE,
     DEFAULT_BORDERWIDTH, Tk_Offset(Square,square.borderWidthObj), -1,
     0,0,GEOMETRY_CHANGED },
    {TK_OPTION_BORDER, "-foreground", "foreground", "Foreground",
     DEFAULT_BACKGROUND, offsetof(Square,square.foregroundObj),
     TCL_INDEX_NONE, 0, 0, 0},
     DEFAULT_BACKGROUND, Tk_Offset(Square,square.foregroundObj),
     -1, 0, 0, 0},

    {TK_OPTION_PIXELS, "-width", "width", "Width",
     "50", offsetof(Square,square.widthObj), TCL_INDEX_NONE, 0, 0,
     "50", Tk_Offset(Square,square.widthObj), -1, 0, 0,
     GEOMETRY_CHANGED},
    {TK_OPTION_PIXELS, "-height", "height", "Height",
     "50", offsetof(Square,square.heightObj), TCL_INDEX_NONE, 0, 0,
     "50", Tk_Offset(Square,square.heightObj), -1, 0, 0,
     GEOMETRY_CHANGED},

    {TK_OPTION_STRING, "-padding", "padding", "Pad", NULL,
     offsetof(Square,square.paddingObj), TCL_INDEX_NONE,
     Tk_Offset(Square,square.paddingObj), -1,
     TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
     NULL, offsetof(Square,square.reliefObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
     NULL, Tk_Offset(Square,square.reliefObj), -1, TK_OPTION_NULL_OK, 0, 0},

    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
     "center", offsetof(Square,square.anchorObj), TCL_INDEX_NONE, 0, 0, 0},
     NULL, Tk_Offset(Square,square.anchorObj), -1, TK_OPTION_NULL_OK, 0, 0},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*
 * Almost all of the widget functionality is handled by the default Ttk
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136

137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153







-
+



















-

+



-









-
+








    /*
     * Adjust the position of the square element within the widget according
     * to the -anchor option.
     */

    if (squareNode) {
	Square *squarePtr = (Square *)clientData;
	Square *squarePtr = clientData;
	Tk_Anchor anchor = TK_ANCHOR_CENTER;
	Ttk_Box b;

	b = Ttk_ElementParcel(squareNode);
	if (squarePtr->square.anchorObj != NULL)
	    Tk_GetAnchorFromObj(NULL, squarePtr->square.anchorObj, &anchor);
	b = Ttk_AnchorBox(winBox, b.width, b.height, anchor);

	Ttk_PlaceElement(corePtr->layout, squareNode, b);
    }
}

/*
 * Widget commands. A widget is impelemented as an ensemble and the
 * subcommands are listed here. Ttk provides default implementations
 * that are sufficient for our needs.
 */

static const Ttk_Ensemble SquareCommands[] = {
    { "cget",		TtkWidgetCgetCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "identify",	TtkWidgetIdentifyCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { 0,0,0 }
};

/*
 * The Widget specification structure holds all the implementation
 * information about this widget and this is what must be registered
 * with Tk in the package initialization code (see bottom).
 */

static const WidgetSpec SquareWidgetSpec =
static WidgetSpec SquareWidgetSpec =
{
    "TSquare",			/* className */
    sizeof(Square),		/* recordSize */
    SquareOptionSpecs,		/* optionSpecs */
    SquareCommands,		/* subcommands */
    TtkNullInitialize,		/* initializeProc */
    TtkNullCleanup,		/* cleanupProc */
173
174
175
176
177
178
179
180

181
182

183
184

185
186

187
188

189
190
191
192



193
194
195
196
197
198
199
200
201
202
203

204
205

206
207
208
209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

225
226

227
228
229
230

231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
172
173
174
175
176
177
178

179
180

181
182

183
184

185
186

187
188



189
190
191
192
193
194
195
196
197
198
199
200


201


202


203

204
205
206
207
208
209
210
211
212
213
214
215
216
217


218


219


220

221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240







-
+

-
+

-
+

-
+

-
+

-
-
-
+
+
+









-
-
+
-
-
+
-
-

-
+













-
-
+
-
-
+
-
-

-
+











-
+







    Tcl_Obj *foregroundObj;
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *reliefObj;
    Tcl_Obj *widthObj;
    Tcl_Obj *heightObj;
} SquareElement;

static const Ttk_ElementOptionSpec SquareElementOptions[] =
static Ttk_ElementOptionSpec SquareElementOptions[] =
{
    { "-background", TK_OPTION_BORDER, offsetof(SquareElement,borderObj),
    { "-background", TK_OPTION_BORDER, Tk_Offset(SquareElement,borderObj),
    	DEFAULT_BACKGROUND },
    { "-foreground", TK_OPTION_BORDER, offsetof(SquareElement,foregroundObj),
    { "-foreground", TK_OPTION_BORDER, Tk_Offset(SquareElement,foregroundObj),
    	DEFAULT_BACKGROUND },
    { "-borderwidth", TK_OPTION_PIXELS, offsetof(SquareElement,borderWidthObj),
    { "-borderwidth", TK_OPTION_PIXELS, Tk_Offset(SquareElement,borderWidthObj),
    	DEFAULT_BORDERWIDTH },
    { "-relief", TK_OPTION_RELIEF, offsetof(SquareElement,reliefObj),
    { "-relief", TK_OPTION_RELIEF, Tk_Offset(SquareElement,reliefObj),
    	"raised" },
    { "-width",  TK_OPTION_PIXELS, offsetof(SquareElement,widthObj), "20"},
    { "-height", TK_OPTION_PIXELS, offsetof(SquareElement,heightObj), "20"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    { "-width",  TK_OPTION_PIXELS, Tk_Offset(SquareElement,widthObj), "20"},
    { "-height", TK_OPTION_PIXELS, Tk_Offset(SquareElement,heightObj), "20"},
    { NULL, 0, 0, NULL }
};

/*
 * The element geometry function is called when the layout code wishes to
 * find out how big this element wants to be. We must return our preferred
 * size and padding information
 */

static void SquareElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    Ttk_Padding *paddingPtr)
{
    SquareElement *square = (SquareElement *)elementRecord;
    SquareElement *square = elementRecord;
    int borderWidth = 0;

    Tcl_GetIntFromObj(NULL, square->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);
    Tk_GetPixelsFromObj(NULL, tkwin, square->widthObj, widthPtr);
    Tk_GetPixelsFromObj(NULL, tkwin, square->heightObj, heightPtr);
}

/*
 * Draw the element in the box provided.
 */

static void SquareElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    SquareElement *square = (SquareElement *)elementRecord;
    SquareElement *square = elementRecord;
    Tk_3DBorder foreground = NULL;
    int borderWidth = 1, relief = TK_RELIEF_FLAT;

    foreground = Tk_Get3DBorderFromObj(tkwin, square->foregroundObj);
    Tcl_GetIntFromObj(NULL, square->borderWidthObj, &borderWidth);
    Tk_GetReliefFromObj(NULL, square->reliefObj, &relief);

    Tk_Fill3DRectangle(tkwin, d, foreground,
	b.x, b.y, b.width, b.height, borderWidth, relief);
}

static const Ttk_ElementSpec SquareElementSpec =
static Ttk_ElementSpec SquareElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(SquareElement),
    SquareElementOptions,
    SquareElementSize,
    SquareElementDraw
};
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
276
277
278
279
280
281
282



283
284
285
286
287
288
289







-
-
-







 * new instance. If this is done, a new layout will need to be created (which
 * can be done at script level). Some widgets may require particular elements
 * to be present but we try to avoid this where possible. In this widget's C
 * code, no reference is made to any particular elements. The programmer is
 * free to specify a new style using completely different elements.
 */

MODULE_SCOPE int
TtkSquareWidget_Init(Tcl_Interp *interp);

/* public */ MODULE_SCOPE int
TtkSquareWidget_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    /* register the new elements for this theme engine */
    Ttk_RegisterElement(interp, theme, "square", &SquareElementSpec, NULL);

Changes to generic/ttk/ttkState.c.

1
2
3
4

5
6
7


8

9
10
11
12
13
14
15
1
2
3

4
5
6
7
8
9

10
11
12
13
14
15
16
17



-
+



+
+
-
+







/*
 * Tk widget state utilities.
 *
 * Copyright © 2003 Joe English.  Freely redistributable.
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 *
 */

#include <string.h>

#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"

/*
 * Table of state names.  Must be kept in sync with TTK_STATE_*
 * #defines in ttkTheme.h.
 */
static const char *const stateNames[] =
46
47
48
49
50
51
52
53
54


55
56

57
58
59
60

61
62
63
64
65
66
67
68

69
70
71
72
73
74

75

76
77
78
79
80
81
82
48
49
50
51
52
53
54


55
56
57

58
59
60
61

62


63
64
65
66
67

68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83







-
-
+
+

-
+



-
+
-
-





-
+





-
+

+








static int  StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *obj);
/* static void StateSpecFreeIntRep(Tcl_Obj *); */
#define StateSpecFreeIntRep 0		/* not needed */
static void StateSpecDupIntRep(Tcl_Obj *, Tcl_Obj *);
static void StateSpecUpdateString(Tcl_Obj *);

static const
TkObjType StateSpecObjType =
static
struct Tcl_ObjType StateSpecObjType =
{
    {"StateSpec",
    "StateSpec",
    StateSpecFreeIntRep,
    StateSpecDupIntRep,
    StateSpecUpdateString,
    StateSpecSetFromAny,
    StateSpecSetFromAny
    TCL_OBJTYPE_V0},
    0
};

static void StateSpecDupIntRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr)
{
    copyPtr->internalRep.longValue = srcPtr->internalRep.longValue;
    copyPtr->typePtr = &StateSpecObjType.objType;
    copyPtr->typePtr = &StateSpecObjType;
}

static int StateSpecSetFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr)
{
    int status;
    Tcl_Size i, objc;
    int objc;
    Tcl_Obj **objv;
    int i;
    unsigned int onbits = 0, offbits = 0;

    status = Tcl_ListObjGetElements(interp, objPtr, &objc, &objv);
    if (status != TCL_OK)
	return status;

    for (i = 0; i < objc; ++i) {
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149

150
151

152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132

133

134
135
136
137
138
139
140

141
142
143
144
145
146
147
148

149
150

151
152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
+











-
+
-







-
+







-
+

-
+




-
+











-
+










-
+








    /* Invalidate old intrep:
     */
    if (objPtr->typePtr && objPtr->typePtr->freeIntRepProc) {
	objPtr->typePtr->freeIntRepProc(objPtr);
    }

    objPtr->typePtr = &StateSpecObjType.objType;
    objPtr->typePtr = &StateSpecObjType;
    objPtr->internalRep.longValue = (onbits << 16) | offbits;

    return TCL_OK;
}

static void StateSpecUpdateString(Tcl_Obj *objPtr)
{
    unsigned int onbits = (objPtr->internalRep.longValue & 0xFFFF0000) >> 16;
    unsigned int offbits = objPtr->internalRep.longValue & 0x0000FFFF;
    unsigned int mask = onbits | offbits;
    Tcl_DString result;
    int i;
    int i, len;
    int len;

    Tcl_DStringInit(&result);

    for (i=0; stateNames[i] != NULL; ++i) {
	if (mask & (1<<i)) {
	    if (offbits & (1<<i))
		Tcl_DStringAppend(&result, "!", 1);
	    Tcl_DStringAppend(&result, stateNames[i], TCL_INDEX_NONE);
	    Tcl_DStringAppend(&result, stateNames[i], -1);
	    Tcl_DStringAppend(&result, " ", 1);
	}
    }

    len = Tcl_DStringLength(&result);
    if (len) {
	/* 'len' includes extra trailing ' ' */
	objPtr->bytes = (char *)ckalloc(len);
	objPtr->bytes = Tcl_Alloc((unsigned)len);
	objPtr->length = len-1;
	strncpy(objPtr->bytes, Tcl_DStringValue(&result), len-1);
	strncpy(objPtr->bytes, Tcl_DStringValue(&result), (size_t)len-1);
	objPtr->bytes[len-1] = '\0';
    } else {
	/* empty string */
	objPtr->length = 0;
	objPtr->bytes = (char *)ckalloc(1);
	objPtr->bytes = Tcl_Alloc(1);
	*objPtr->bytes = '\0';
    }

    Tcl_DStringFree(&result);
}

Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits, unsigned int offbits)
{
    Tcl_Obj *objPtr = Tcl_NewObj();

    Tcl_InvalidateStringRep(objPtr);
    objPtr->typePtr = &StateSpecObjType.objType;
    objPtr->typePtr = &StateSpecObjType;
    objPtr->internalRep.longValue = (onbits << 16) | offbits;

    return objPtr;
}

int Ttk_GetStateSpecFromObj(
    Tcl_Interp *interp,
    Tcl_Obj *objPtr,
    Ttk_StateSpec *spec)
{
    if (objPtr->typePtr != &StateSpecObjType.objType) {
    if (objPtr->typePtr != &StateSpecObjType) {
	int status = StateSpecSetFromAny(interp, objPtr);
	if (status != TCL_OK)
	    return status;
    }

    spec->onbits = (objPtr->internalRep.longValue & 0xFFFF0000) >> 16;
    spec->offbits = objPtr->internalRep.longValue & 0x0000FFFF;
197
198
199
200
201
202
203
204
205


206
207
208
209
210
211
212
197
198
199
200
201
202
203


204
205
206
207
208
209
210
211
212







-
-
+
+







 */
Tcl_Obj *Ttk_StateMapLookup(
    Tcl_Interp *interp,		/* Where to leave error messages; may be NULL */
    Ttk_StateMap map,		/* State map */
    Ttk_State state)    	/* State to look up */
{
    Tcl_Obj **specs;
    Tcl_Size j, nSpecs;
    int status;
    int nSpecs;
    int j, status;

    status = Tcl_ListObjGetElements(interp, map, &nSpecs, &specs);
    if (status != TCL_OK)
	return NULL;

    for (j = 0; j < nSpecs; j += 2) {
	Ttk_StateSpec spec;
229
230
231
232
233
234
235
236
237


238
239
240
241
242
243
244
229
230
231
232
233
234
235


236
237
238
239
240
241
242
243
244







-
-
+
+







 * 	this basically just checks for errors.
 */
Ttk_StateMap Ttk_GetStateMapFromObj(
    Tcl_Interp *interp,		/* Where to leave error messages; may be NULL */
    Tcl_Obj *mapObj)		/* State map */
{
    Tcl_Obj **specs;
    Tcl_Size j, nSpecs;
    int status;
    int nSpecs;
    int j, status;

    status = Tcl_ListObjGetElements(interp, mapObj, &nSpecs, &specs);
    if (status != TCL_OK)
	return NULL;

    if (nSpecs % 2 != 0) {
	if (interp) {
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275







-
+










    return mapObj;
}

/*
 * Ttk_StateTableLooup --
 * 	Look up an index from a statically allocated state table.
 */
int Ttk_StateTableLookup(const Ttk_StateTable *map, Ttk_State state)
int Ttk_StateTableLookup(Ttk_StateTable *map, unsigned int state)
{
    while ((state & map->onBits) != map->onBits
	    || (~state & map->offBits) != map->offBits)
    {
	++map;
    }
    return map->index;
}

/*EOF*/

Changes to generic/ttk/ttkStubInit.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4
5

6
7
8
9
10








11
12
13
14
15
16
17





-
+




-
-
-
-
-
-
-
-







/*
 * This file is (mostly) automatically generated from ttk.decls.
 * It is compiled and linked in with the ttk package proper.
 */

#include "tkInt.h"
#include "tk.h"
#include "ttkTheme.h"

MODULE_SCOPE const TtkStubs ttkStubs;

#ifdef __GNUC__
/*
 * The rest of this file shouldn't warn about deprecated functions; they're
 * there because we intend them to be so and know that this file is OK to
 * touch those fields.
 */
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
/* !BEGIN!: Do not edit below this line. */

const TtkStubs ttkStubs = {
    TCL_STUB_MAGIC,
    TTK_STUBS_EPOCH,
    TTK_STUBS_REVISION,
    0,

Changes to generic/ttk/ttkStubLib.c.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 * We need to ensure that we use the tcl stub macros so that this file
 * contains no references to any of the tcl stub functions.
 */

#undef USE_TCL_STUBS
#define USE_TCL_STUBS

#include "tkInt.h"
#include "tk.h"

#define USE_TTK_STUBS 1
#include "ttkTheme.h"

MODULE_SCOPE const TtkStubs *ttkStubsPtr;
const TtkStubs *ttkStubsPtr = NULL;

30
31
32
33
34
35
36
37

38
39

40
41
42

43
44
45
46
47
48
49
50
51



52
53
54
55
56
57
58
59
60
30
31
32
33
34
35
36

37
38

39
40
41

42
43
44







45
46
47


48
49
50
51
52
53
54







-
+

-
+


-
+


-
-
-
-
-
-
-
+
+
+
-
-







 *
 */
MODULE_SCOPE const char *
TtkInitializeStubs(
    Tcl_Interp *interp, const char *version, int epoch, int revision)
{
    int exact = 0;
    const char *packageName = "ttk";
    const char *packageName = "Ttk";
    const char *errMsg = NULL;
    void *pkgClientData = NULL;
    ClientData pkgClientData = NULL;
    const char *actualVersion = Tcl_PkgRequireEx(
	interp, packageName, version, exact, &pkgClientData);
    const TtkStubs *stubsPtr;
    const TtkStubs *stubsPtr = pkgClientData;

    if (!actualVersion) {
	packageName = "Ttk";
	actualVersion = Tcl_PkgRequireEx(
		interp, packageName, version, exact, &pkgClientData);
	if (!actualVersion) {
	    return NULL;
	}
    }
	return NULL;
    }


    stubsPtr = (const TtkStubs *)pkgClientData;
    if (!stubsPtr) {
	errMsg = "missing stub table pointer";
	goto error;
    }
    if (stubsPtr->epoch != epoch) {
	errMsg = "epoch number mismatch";
	goto error;

Changes to generic/ttk/ttkTagSet.c.

1
2
3
4

5
6


7


8
9
10
11
12
13
14
15

16
17
18
19
20
21
22

23
24
25


26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
1
2
3

4
5
6
7
8

9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24

25
26


27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44



-
+


+
+
-
+
+







-
+






-
+

-
-
+
+








-
+







/*
 * Tag tables.  3/4-baked, work in progress.
 *
 * Copyright © 2005, Joe English.  Freely redistributable.
 * Copyright (C) 2005, Joe English.  Freely redistributable.
 */

#include <string.h>	/* for memset() */
#include <tcl.h>
#include "tkInt.h"
#include <tk.h>

#include "ttkTheme.h"
#include "ttkWidget.h"

/*------------------------------------------------------------------------
 * +++ Internal data structures.
 */
struct TtkTag {
    Tcl_Size 	priority;		/* 1=>highest */
    int 	priority;		/* 1=>highest */
    const char	*tagName;		/* Back-pointer to hash table entry */
    void	*tagRecord;		/* User data */
};

struct TtkTagTable {
    Tk_Window		tkwin;		/* owner window */
    const Tk_OptionSpec	*optionSpecs;	/* ... */
    Tk_OptionSpec	*optionSpecs;	/* ... */
    Tk_OptionTable	optionTable;	/* ... */
    size_t         	recordSize;	/* size of tag record */
    Tcl_Size 		nTags;		/* #tags defined so far */
    int         	recordSize;	/* size of tag record */
    int 		nTags;		/* #tags defined so far */
    Tcl_HashTable	tags;		/* defined tags */
};

/*------------------------------------------------------------------------
 * +++ Tags.
 */
static Ttk_Tag NewTag(Ttk_TagTable tagTable, const char *tagName)
{
    Ttk_Tag tag = (Ttk_Tag)ckalloc(sizeof(*tag));
    Ttk_Tag tag = ckalloc(sizeof(*tag));
    tag->tagRecord = ckalloc(tagTable->recordSize);
    memset(tag->tagRecord, 0, tagTable->recordSize);
    /* Don't need Tk_InitOptions() here, all defaults should be NULL. */
    tag->priority = ++tagTable->nTags;
    tag->tagName = tagName;
    return tag;
}
49
50
51
52
53
54
55
56

57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104

105
106
107
108
109
110
111
52
53
54
55
56
57
58

59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85











86
87
88
89
90
91
92

93
94
95

96
97
98
99
100
101
102
103







-
+

-
+
















-
+







-
-
-
-
-
-
-
-
-
-
-







-
+


-
+








/*------------------------------------------------------------------------
 * +++ Tag tables.
 */

Ttk_TagTable Ttk_CreateTagTable(
    Tcl_Interp *interp, Tk_Window tkwin,
    const Tk_OptionSpec *optionSpecs, size_t recordSize)
    Tk_OptionSpec optionSpecs[], int recordSize)
{
    Ttk_TagTable tagTable = (Ttk_TagTable)ckalloc(sizeof(*tagTable));
    Ttk_TagTable tagTable = ckalloc(sizeof(*tagTable));
    tagTable->tkwin = tkwin;
    tagTable->optionSpecs = optionSpecs;
    tagTable->optionTable = Tk_CreateOptionTable(interp, optionSpecs);
    tagTable->recordSize = recordSize;
    tagTable->nTags = 0;
    Tcl_InitHashTable(&tagTable->tags, TCL_STRING_KEYS);
    return tagTable;
}

void Ttk_DeleteTagTable(Ttk_TagTable tagTable)
{
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;

    entryPtr = Tcl_FirstHashEntry(&tagTable->tags, &search);
    while (entryPtr != NULL) {
	DeleteTag(tagTable, (Ttk_Tag)Tcl_GetHashValue(entryPtr));
	DeleteTag(tagTable, Tcl_GetHashValue(entryPtr));
	entryPtr = Tcl_NextHashEntry(&search);
    }

    Tcl_DeleteHashTable(&tagTable->tags);
    ckfree(tagTable);
}

void Ttk_DeleteTagFromTable(Ttk_TagTable tagTable, Ttk_Tag tag)
{
    Tcl_HashEntry *entryPtr;

    entryPtr = Tcl_FindHashEntry(&tagTable->tags, tag->tagName);
    if (entryPtr != NULL) {
        DeleteTag(tagTable, tag);
        Tcl_DeleteHashEntry(entryPtr);
    }
}

Ttk_Tag Ttk_GetTag(Ttk_TagTable tagTable, const char *tagName)
{
    int isNew = 0;
    Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
	&tagTable->tags, tagName, &isNew);

    if (isNew) {
	tagName = (char *)Tcl_GetHashKey(&tagTable->tags, entryPtr);
	tagName = Tcl_GetHashKey(&tagTable->tags, entryPtr);
	Tcl_SetHashValue(entryPtr, NewTag(tagTable,tagName));
    }
    return (Ttk_Tag)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

Ttk_Tag Ttk_GetTagFromObj(Ttk_TagTable tagTable, Tcl_Obj *objPtr)
{
    return Ttk_GetTag(tagTable, Tcl_GetString(objPtr));
}

120
121
122
123
124
125
126
127

128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
112
113
114
115
116
117
118

119
120

121
122
123
124
125
126
127
128
129
130
131
132
133


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186
187
188
189
190

191
192
193
194
195
196






























197
198
199
200
201
202
203

204
205
206
207
208
209
210
211







-
+

-
+












-
-
+
+














-
+


















-
+















-
+





-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+







 * Returns NULL and leaves an error message in interp->result on error.
 *
 * Non-NULL results must be passed to Ttk_FreeTagSet().
 */
Ttk_TagSet Ttk_GetTagSetFromObj(
    Tcl_Interp *interp, Ttk_TagTable tagTable, Tcl_Obj *objPtr)
{
    Ttk_TagSet tagset = (Ttk_TagSet)ckalloc(sizeof(*tagset));
    Ttk_TagSet tagset = ckalloc(sizeof(*tagset));
    Tcl_Obj **objv;
    Tcl_Size i, objc;
    int i, objc;

    if (objPtr == NULL) {
	tagset->tags = NULL;
	tagset->nTags = 0;
	return tagset;
    }

    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
	ckfree(tagset);
    	return NULL;
    }

    tagset->tags = (Ttk_Tag *)ckalloc((objc+1) * sizeof(Ttk_Tag));
    for (i = 0; i < objc; ++i) {
    tagset->tags = ckalloc((objc+1) * sizeof(Ttk_Tag));
    for (i=0; i<objc; ++i) {
	tagset->tags[i] = Ttk_GetTagFromObj(tagTable, objv[i]);
    }
    tagset->tags[i] = NULL;
    tagset->nTags = objc;

    return tagset;
}

/* Ttk_NewTagSetObj --
 * 	Construct a fresh Tcl_Obj * from a tag set.
 */
Tcl_Obj *Ttk_NewTagSetObj(Ttk_TagSet tagset)
{
    Tcl_Obj *result = Tcl_NewListObj(0,0);
    Tcl_Size i;
    int i;

    for (i = 0; i < tagset->nTags; ++i) {
	Tcl_ListObjAppendElement(
	    NULL, result, Tcl_NewStringObj(tagset->tags[i]->tagName, -1));
    }
    return result;
}

void Ttk_FreeTagSet(Ttk_TagSet tagset)
{
    ckfree(tagset->tags);
    ckfree(tagset);
}

/* Ttk_TagSetContains -- test if tag set contains a tag.
 */
int Ttk_TagSetContains(Ttk_TagSet tagset, Ttk_Tag tag)
{
    Tcl_Size i;
    int i;
    for (i = 0; i < tagset->nTags; ++i) {
	if (tagset->tags[i] == tag) {
	    return 1;
	}
    }
    return 0;
}

/* Ttk_TagSetAdd -- add a tag to a tag set.
 *
 * Returns: 0 if tagset already contained tag,
 * 1 if tagset was modified.
 */
int Ttk_TagSetAdd(Ttk_TagSet tagset, Ttk_Tag tag)
{
    Tcl_Size i;
    int i;
    for (i = 0; i < tagset->nTags; ++i) {
	if (tagset->tags[i] == tag) {
	    return 0;
	}
    }
    tagset->tags = (Ttk_Tag *)ckrealloc(tagset->tags,
    tagset->tags = ckrealloc(tagset->tags,
	    (tagset->nTags+1)*sizeof(tagset->tags[0]));
    tagset->tags[tagset->nTags++] = tag;
    return 1;
}

/* Ttk_TagSetAddSet -- add a tag set to a tag set.
 *
 * Returns: 0 if tagset already contained tags,
 * 1 if tagset was modified.
 */
int Ttk_TagSetAddSet(Ttk_TagSet tagset, Ttk_TagSet tagsetFrom)
{
    Tcl_Size i, j, total, nTags = tagset->nTags;
    int result = 0, found;
    Ttk_Tag tag;

    total = tagsetFrom->nTags + tagset->nTags;
    tagset->tags = (Ttk_Tag *)ckrealloc(tagset->tags,
	    (total)*sizeof(tagset->tags[0]));
    for (j = 0; j < tagsetFrom->nTags; ++j) {
	tag = tagsetFrom->tags[j];
	found = 0;
	for (i = 0; i < nTags; ++i) {
	    if (tagset->tags[i] == tag) {
		found = 1;
		break;
	    }
	}
	if (found) continue;
	tagset->tags[tagset->nTags++] = tag;
	result = 1;
    }
    return result;
}

/* Ttk_TagSetRemove -- remove a tag from a tag set.
 *
 * Returns: 0 if tagset did not contain tag,
 * 1 if tagset was modified.
 */
int Ttk_TagSetRemove(Ttk_TagSet tagset, Ttk_Tag tag)
{
    Tcl_Size i = 0, j = 0;
    int i = 0, j = 0;
    while (i < tagset->nTags) {
	if ((tagset->tags[j] = tagset->tags[i]) != tag) {
	    ++j;
	}
	++i;
    }
    tagset->nTags = j;
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

322


323
324
325


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

342
343
344

345
346
347
348


349
350
351
352
353
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266













267
268
269

270
271
272
273
274


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294

295
296
297
298
299
300
301
302
303
304
305
306







-
+












-
-
-
-
-
-
-
-
-
-
-
-
-



-
+

+
+

-
-
+
+















-
+


-
+




+
+






/* Ttk_ConfigureTag -- implements [$w tag configure $tag -option value...]
 */
int Ttk_ConfigureTag(
    Tcl_Interp *interp,
    Ttk_TagTable tagTable,
    Ttk_Tag tag,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    return Tk_SetOptions(
	interp, tag->tagRecord, tagTable->optionTable,
	objc, objv, tagTable->tkwin, NULL/*savedOptions*/, NULL/*mask*/);
}

/*------------------------------------------------------------------------
 * +++ Tag values.
 */

#define OBJ_AT(record, offset) (*(Tcl_Obj**)(((char*)record)+offset))

void Ttk_TagSetDefaults(Ttk_TagTable tagTable, Ttk_Style style, void *record)
{
    const Tk_OptionSpec *optionSpec = tagTable->optionSpecs;
    memset(record, 0, tagTable->recordSize);

    while (optionSpec->type != TK_OPTION_END) {
	int offset = optionSpec->objOffset;
	const char *optionName = optionSpec->optionName;
	OBJ_AT(record, offset) = Ttk_StyleDefault(style, optionName);
	++optionSpec;
    }
}

void Ttk_TagSetValues(Ttk_TagTable tagTable, Ttk_TagSet tagSet, void *record)
{
    const int LOWEST_PRIORITY = 0x7FFFFFFF;
    Tcl_Size i, j;
    int i, j;

    memset(record, 0, tagTable->recordSize);

    for (i = 0; tagTable->optionSpecs[i].type != TK_OPTION_END; ++i) {
	const Tk_OptionSpec *optionSpec = tagTable->optionSpecs + i;
	Tcl_Size offset = optionSpec->objOffset;
	Tk_OptionSpec *optionSpec = tagTable->optionSpecs + i;
	int offset = optionSpec->objOffset;
	int prio = LOWEST_PRIORITY;

	for (j = 0; j < tagSet->nTags; ++j) {
	    Ttk_Tag tag = tagSet->tags[j];
	    if (OBJ_AT(tag->tagRecord, offset) != 0 && tag->priority < prio) {
		OBJ_AT(record, offset) = OBJ_AT(tag->tagRecord, offset);
		prio = tag->priority;
	    }
	}
    }
}

void Ttk_TagSetApplyStyle(
    Ttk_TagTable tagTable, Ttk_Style style, Ttk_State state, void *record)
{
    const Tk_OptionSpec *optionSpec = tagTable->optionSpecs;
    Tk_OptionSpec *optionSpec = tagTable->optionSpecs;

    while (optionSpec->type != TK_OPTION_END) {
	Tcl_Size offset = optionSpec->objOffset;
	int offset = optionSpec->objOffset;
	const char *optionName = optionSpec->optionName;
	Tcl_Obj *val = Ttk_StyleMap(style, optionName, state);
	if (val) {
	    OBJ_AT(record, offset) = val;
	} else if (OBJ_AT(record, offset) == 0) {
	    OBJ_AT(record, offset) = Ttk_StyleDefault(style, optionName);
	}
	++optionSpec;
    }
}

Changes to generic/ttk/ttkTheme.c.

1
2
3
4
5
6
7


8
9
10
11
12


13


14
15
16
17
18
19
20
1
2
3
4
5


6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23





-
-
+
+





+
+
-
+
+







/*
 * ttkTheme.c --
 *
 *	This file implements the widget styles and themes support.
 *
 * Copyright © 2002 Frederic Bonnet
 * Copyright © 2003 Joe English
 * Copyright (c) 2002 Frederic Bonnet
 * Copyright (c) 2003 Joe English
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include <stdlib.h>
#include <string.h>
#include "tkInt.h"
#include <tk.h>
#include <tkInt.h>
#include "ttkThemeInt.h"

#define PKG_ASSOC_KEY "Ttk"

/*------------------------------------------------------------------------
 * +++ Styles.
 *
31
32
33
34
35
36
37
38

39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
34
35
36
37
38
39
40

41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130







-
+

-
+


















-
+







-
+




















-
+









-
+







-
+













-
+







    Tcl_HashTable	settingsTable;	/* KEY: string; VALUE: StateMap */
    Tcl_HashTable	defaultsTable;	/* KEY: string; VALUE: resource */
    Ttk_LayoutTemplate	layoutTemplate;	/* Layout template for style, or NULL */
    Ttk_Style		parentStyle;	/* Previous style in chain */
    Ttk_ResourceCache	cache;		/* Back-pointer to resource cache */
} Style;

static Style *NewStyle(void)
static Style *NewStyle()
{
    Style *stylePtr = (Style *)ckalloc(sizeof(Style));
    Style *stylePtr = ckalloc(sizeof(Style));

    stylePtr->styleName = NULL;
    stylePtr->parentStyle = NULL;
    stylePtr->layoutTemplate = NULL;
    stylePtr->cache = NULL;
    Tcl_InitHashTable(&stylePtr->settingsTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&stylePtr->defaultsTable, TCL_STRING_KEYS);

    return stylePtr;
}

static void FreeStyle(Style *stylePtr)
{
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;

    entryPtr = Tcl_FirstHashEntry(&stylePtr->settingsTable, &search);
    while (entryPtr != NULL) {
	Ttk_StateMap stateMap = (Ttk_StateMap)Tcl_GetHashValue(entryPtr);
	Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr);
	Tcl_DecrRefCount(stateMap);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&stylePtr->settingsTable);

    entryPtr = Tcl_FirstHashEntry(&stylePtr->defaultsTable, &search);
    while (entryPtr != NULL) {
	Tcl_Obj *defaultValue = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *defaultValue = Tcl_GetHashValue(entryPtr);
	Tcl_DecrRefCount(defaultValue);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&stylePtr->defaultsTable);

    Ttk_FreeLayoutTemplate(stylePtr->layoutTemplate);

    ckfree(stylePtr);
}

/*
 * Ttk_StyleMap --
 * 	Look up state-specific option value from specified style.
 */
Tcl_Obj *Ttk_StyleMap(Ttk_Style style, const char *optionName, Ttk_State state)
{
    while (style) {
	Tcl_HashEntry *entryPtr =
	    Tcl_FindHashEntry(&style->settingsTable, optionName);
	if (entryPtr) {
	    Ttk_StateMap stateMap = (Ttk_StateMap)Tcl_GetHashValue(entryPtr);
	    Ttk_StateMap stateMap = Tcl_GetHashValue(entryPtr);
	    return Ttk_StateMapLookup(NULL, stateMap, state);
	}
	style = style->parentStyle;
    }
    return 0;
}

/*
 * Ttk_StyleDefault --
 * 	Look up default resource setting in the specified style.
 * 	Look up default resource setting the in the specified style.
 */
Tcl_Obj *Ttk_StyleDefault(Ttk_Style style, const char *optionName)
{
    while (style) {
	Tcl_HashEntry *entryPtr =
	    Tcl_FindHashEntry(&style->defaultsTable, optionName);
	if (entryPtr)
	    return (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	    return Tcl_GetHashValue(entryPtr);
	style= style->parentStyle;
    }
    return 0;
}

/*------------------------------------------------------------------------
 * +++ Elements.
 */
typedef const Tk_OptionSpec **OptionMap;
    /* array of Tk_OptionSpecs mapping widget options to element options */

struct Ttk_ElementClass_ {
    const char *name;		/* Points to hash table key */
    const Ttk_ElementSpec *specPtr;	/* Template provided during registration. */
    Ttk_ElementSpec *specPtr;	/* Template provided during registration. */
    void *clientData;		/* Client data passed in at registration time */
    void *elementRecord;	/* Scratch buffer for element record storage */
    int nResources;		/* #Element options */
    Tcl_Obj **defaultValues;	/* Array of option default values */
    Tcl_HashTable optMapCache;	/* Map: Tk_OptionTable * -> OptionMap */
};

172
173
174
175
176
177
178
179

180
181
182
183
184

185
186
187
188
189
190
191
175
176
177
178
179
180
181

182
183
184
185
186

187
188
189
190
191
192
193
194







-
+




-
+








/* BuildOptionMap --
 * 	Construct the mapping from element options to widget options.
 */
static OptionMap
BuildOptionMap(Ttk_ElementClass *elementClass, Tk_OptionTable optionTable)
{
    OptionMap optionMap = (OptionMap)ckalloc(
    OptionMap optionMap = ckalloc(
	    sizeof(const Tk_OptionSpec) * elementClass->nResources + 1);
    int i;

    for (i = 0; i < elementClass->nResources; ++i) {
	const Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i;
	Ttk_ElementOptionSpec *e = elementClass->specPtr->options+i;
	optionMap[i] = TTKGetOptionSpec(e->optionName, optionTable, e->type);
    }

    return optionMap;
}

/* GetOptionMap --
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219

220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218
219
220
221

222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+











-
+

-
+















-
+







    Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
	&elementClass->optMapCache, (void*)optionTable, &isNew);

    if (isNew) {
	optionMap = BuildOptionMap(elementClass, optionTable);
	Tcl_SetHashValue(entryPtr, optionMap);
    } else {
	optionMap = (OptionMap)Tcl_GetHashValue(entryPtr);
	optionMap = Tcl_GetHashValue(entryPtr);
    }

    return optionMap;
}

/*
 * NewElementClass --
 * 	Allocate and initialize an element class record
 * 	from the specified element specification.
 */
static Ttk_ElementClass *
NewElementClass(const char *name, const Ttk_ElementSpec *specPtr, void *clientData)
NewElementClass(const char *name, Ttk_ElementSpec *specPtr,void *clientData)
{
    Ttk_ElementClass *elementClass = (Ttk_ElementClass *)ckalloc(sizeof(Ttk_ElementClass));
    Ttk_ElementClass *elementClass = ckalloc(sizeof(Ttk_ElementClass));
    int i;

    elementClass->name = name;
    elementClass->specPtr = specPtr;
    elementClass->clientData = clientData;
    elementClass->elementRecord = ckalloc(specPtr->elementSize);

    /* Count #element resources:
     */
    for (i = 0; specPtr->options[i].optionName != 0; ++i)
	continue;
    elementClass->nResources = i;

    /* Initialize default values:
     */
    elementClass->defaultValues = (Tcl_Obj **)
    elementClass->defaultValues =
	ckalloc(elementClass->nResources * sizeof(Tcl_Obj *) + 1);
    for (i=0; i < elementClass->nResources; ++i) {
        const char *defaultValue = specPtr->options[i].defaultValue;
	if (defaultValue) {
	    elementClass->defaultValues[i] = Tcl_NewStringObj(defaultValue,-1);
	    Tcl_IncrRefCount(elementClass->defaultValues[i]);
	} else {
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
290
291
292
293
294
295
296

297



298


299
300
301
302
303
304
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365







-
+
-
-
-

-
-














-
+
















-
+
















-
+










-
+







    ckfree(elementClass);
}

/*------------------------------------------------------------------------
 * +++ Themes.
 */

static int ThemeEnabled(
static int ThemeEnabled(Ttk_Theme theme, void *clientData) { return 1; }
    TCL_UNUSED(Ttk_Theme),
    TCL_UNUSED(void *))
{
    /* Default ThemeEnabledProc -- always return true */
    return 1;
}

typedef struct Ttk_Theme_
{
    Ttk_Theme parentPtr;             	/* Parent theme. */
    Tcl_HashTable elementTable;	     	/* Map element names to class records */
    Tcl_HashTable styleTable;	     	/* Map style names to Styles */
    Ttk_Style rootStyle;		/* "." style, root of chain */
    Ttk_ThemeEnabledProc *enabledProc;	/* Function called by SetTheme */
    void *enabledData;              	/* ClientData for enabledProc */
    Ttk_ResourceCache cache;		/* Back-pointer to resource cache */
} Theme;

static Theme *NewTheme(Ttk_ResourceCache cache, Ttk_Theme parent)
{
    Theme *themePtr = (Theme *)ckalloc(sizeof(Theme));
    Theme *themePtr = ckalloc(sizeof(Theme));
    Tcl_HashEntry *entryPtr;
    int unused;

    themePtr->parentPtr = parent;
    themePtr->enabledProc = ThemeEnabled;
    themePtr->enabledData = NULL;
    themePtr->cache = cache;
    Tcl_InitHashTable(&themePtr->elementTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&themePtr->styleTable, TCL_STRING_KEYS);

    /*
     * Create root style "."
     */
    entryPtr = Tcl_CreateHashEntry(&themePtr->styleTable, ".", &unused);
    themePtr->rootStyle = NewStyle();
    themePtr->rootStyle->styleName =
	(const char *)Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
	Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
    themePtr->rootStyle->cache = themePtr->cache;
    Tcl_SetHashValue(entryPtr, themePtr->rootStyle);

    return themePtr;
}

static void FreeTheme(Theme *themePtr)
{
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;

    /*
     * Free element table:
     */
    entryPtr = Tcl_FirstHashEntry(&themePtr->elementTable, &search);
    while (entryPtr != NULL) {
	Ttk_ElementClass *elementClass = (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr);
	Ttk_ElementClass *elementClass = Tcl_GetHashValue(entryPtr);
	FreeElementClass(elementClass);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&themePtr->elementTable);

    /*
     * Free style table:
     */
    entryPtr = Tcl_FirstHashEntry(&themePtr->styleTable, &search);
    while (entryPtr != NULL) {
	Style *stylePtr = (Style *)Tcl_GetHashValue(entryPtr);
	Style *stylePtr = Tcl_GetHashValue(entryPtr);
	FreeStyle(stylePtr);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&themePtr->styleTable);

    /*
     * Free theme record:
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403
404
405


406
407
408
409

410
411
412
413

414
415
416







417
418
419
420
421
422
423

424
425
426
427
428
429
430
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409


410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435







-
+













+
+



-
+
-
-

-
+



+
+
+
+
+
+
+






-
+







typedef struct CleanupStruct {
    void *clientData;
    Ttk_CleanupProc *cleanupProc;
    struct CleanupStruct *next;
} Cleanup;

/*------------------------------------------------------------------------
 * +++ Style package data structure.
 * +++ Master style package data structure.
 */
typedef struct
{
    Tcl_Interp *interp;			/* Owner interp */
    Tcl_HashTable themeTable;		/* KEY: name; VALUE: Theme pointer */
    Tcl_HashTable factoryTable; 	/* KEY: name; VALUE: FactoryRec ptr */
    Theme *defaultTheme;		/* Default theme; global fallback*/
    Theme *currentTheme;		/* Currently-selected theme */
    Cleanup *cleanupList;		/* Cleanup records */
    Ttk_ResourceCache cache;		/* Resource cache */
    int themeChangePending;		/* scheduled ThemeChangedProc call? */
} StylePackageData;

static void ThemeChangedProc(ClientData);	/* Forward */

/* Ttk_StylePkgFree --
 *	Cleanup procedure for StylePackageData.
 */
static void Ttk_StylePkgFree(
static void Ttk_StylePkgFree(ClientData clientData, Tcl_Interp *interp)
    void *clientData,
    TCL_UNUSED(Tcl_Interp *))
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;
    Cleanup *cleanup;

    /*
     * Cancel any pending ThemeChanged calls:
     */
    if (pkgPtr->themeChangePending) {
	Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
    }

    /*
     * Free themes.
     */
    entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
    while (entryPtr != NULL) {
	Theme *themePtr = (Theme *)Tcl_GetHashValue(entryPtr);
	Theme *themePtr = Tcl_GetHashValue(entryPtr);
	FreeTheme(themePtr);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&pkgPtr->themeTable);

    /*
     * Free element constructor table:
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481
482

483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522
523


524
525
526
527
528
529



















530
531
532
533
534
535
536







-
+












-
+


-
+



















-
+


-
+














-
-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * GetStylePackageData --
 * 	Look up the package data registered with the interp.
 */

static StylePackageData *GetStylePackageData(Tcl_Interp *interp)
{
    return (StylePackageData *)Tcl_GetAssocData(interp, PKG_ASSOC_KEY, NULL);
    return Tcl_GetAssocData(interp, PKG_ASSOC_KEY, NULL);
}

/*
 * Ttk_RegisterCleanup --
 *
 *	Register a function to be called when a theme engine is deleted.
 *	(This only happens when the main interp is destroyed). The cleanup
 *	function is called with the current Tcl interpreter and the client
 *	data provided here.
 *
 */
void Ttk_RegisterCleanup(
    Tcl_Interp *interp, void *clientData, Ttk_CleanupProc *cleanupProc)
    Tcl_Interp *interp, ClientData clientData, Ttk_CleanupProc *cleanupProc)
{
    StylePackageData *pkgPtr = GetStylePackageData(interp);
    Cleanup *cleanup = (Cleanup *)ckalloc(sizeof(*cleanup));
    Cleanup *cleanup = ckalloc(sizeof(*cleanup));

    cleanup->clientData = clientData;
    cleanup->cleanupProc = cleanupProc;
    cleanup->next = pkgPtr->cleanupList;
    pkgPtr->cleanupList = cleanup;
}

/* ThemeChangedProc --
 * 	Notify all widgets that the theme has been changed.
 * 	Scheduled as an idle callback; clientData is a StylePackageData *.
 *
 * 	Sends a <<ThemeChanged>> event to every widget in the hierarchy.
 * 	Widgets respond to this by calling the  WorldChanged class proc,
 * 	which in turn recreates the layout.
 *
 * 	The Tk C API doesn't doesn't provide an easy way to traverse
 * 	the widget hierarchy, so this is done by evaluating a Tcl script.
 */

static void ThemeChangedProc(void *clientData)
static void ThemeChangedProc(ClientData clientData)
{
    static char ThemeChangedScript[] = "ttk::ThemeChanged";
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;

    int code = Tcl_EvalEx(pkgPtr->interp, ThemeChangedScript, -1, TCL_EVAL_GLOBAL);
    if (code != TCL_OK) {
	Tcl_BackgroundException(pkgPtr->interp, code);
    }
    pkgPtr->themeChangePending = 0;
}

/*
 * ThemeChanged --
 * 	Schedule a call to ThemeChanged if one is not already pending.
 */
static void ThemeChanged(StylePackageData *pkgPtr)
{
    TtkSetBlinkCursorTimes(pkgPtr->interp);

    if (!pkgPtr->themeChangePending) {
	Tcl_DoWhenIdle(ThemeChangedProc, pkgPtr);
	pkgPtr->themeChangePending = 1;
    }
}

/* Ttk_TkDestroyedHandler --
 *	See bug [310c74ecf440]: idle calls to ThemeChangedProc()
 *	need to be canceled when Tk is destroyed, since the interp
 *	may still be active afterward; canceling them from
 *	Ttk_StylePkgFree() would be too late.
 */
void Ttk_TkDestroyedHandler(
    Tcl_Interp* interp)
{
    StylePackageData* pkgPtr = GetStylePackageData(interp);

    /*
     * Cancel any pending ThemeChanged calls:
     */
    if (pkgPtr->themeChangePending) {
	Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
    }
}

/*
 * Ttk_CreateTheme --
 *	Create a new theme and register it in the global theme table.
 *
 * Returns:
 * 	Pointer to new Theme structure; NULL if named theme already exists.
 * 	Leaves an error message in interp's result on error.
598
599
600
601
602
603
604
605

606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609







-
+












-
+







 * LookupTheme --
 *	Retrieve a registered theme by name.  If not found,
 *	returns NULL and leaves an error message in interp's result.
 */

static Ttk_Theme LookupTheme(
    Tcl_Interp *interp,		/* where to leave error messages */
    StylePackageData *pkgPtr,	/* style package record */
    StylePackageData *pkgPtr,	/* style package master record */
    const char *name)		/* theme name */
{
    Tcl_HashEntry *entryPtr;

    entryPtr = Tcl_FindHashEntry(&pkgPtr->themeTable, name);
    if (!entryPtr) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"theme \"%s\" doesn't exist", name));
	Tcl_SetErrorCode(interp, "TTK", "LOOKUP", "THEME", name, NULL);
	return NULL;
    }

    return (Ttk_Theme)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

/*
 * Ttk_GetTheme --
 *	Public interface to LookupTheme.
 */
Ttk_Theme Ttk_GetTheme(Tcl_Interp *interp, const char *themeName)
719
720
721
722
723
724
725
726

727
728
729
730
731

732
733
734
735
736
737
738
703
704
705
706
707
708
709

710
711
712
713
714

715
716
717
718
719
720
721
722







-
+




-
+








	if (dot) {
	    stylePtr->parentStyle = Ttk_GetStyle(themePtr, dot + 1);
	} else {
	    stylePtr->parentStyle = themePtr->rootStyle;
	}

	stylePtr->styleName = (const char *)Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
	stylePtr->styleName = Tcl_GetHashKey(&themePtr->styleTable, entryPtr);
	stylePtr->cache = stylePtr->parentStyle->cache;
	Tcl_SetHashValue(entryPtr, stylePtr);
	return stylePtr;
    }
    return (Ttk_Style)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

/* FindLayoutTemplate --
 * 	Locate a layout template in the layout table, checking
 * 	generic names to specific names first, then looking for
 * 	the full name in the parent theme.
 */
770
771
772
773
774
775
776
777

778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842

843
844

845
846
847
848
849
850
851
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787

788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825

826
827

828
829
830
831
832
833
834
835







-
+










-
+















-
+
















-
+




















-
+

-
+







    const char *dot = elementName;

    /*
     * Check if element has already been registered:
     */
    entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, elementName);
    if (entryPtr) {
	return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr);
	return Tcl_GetHashValue(entryPtr);
    }

    /*
     * Check generic names:
     */
    while (!entryPtr && ((dot = strchr(dot, '.')) != NULL)) {
	dot++;
	entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, dot);
    }
    if (entryPtr) {
	return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr);
	return Tcl_GetHashValue(entryPtr);
    }

    /*
     * Check parent theme:
     */
    if (themePtr->parentPtr) {
	return Ttk_GetElement(themePtr->parentPtr, elementName);
    }

    /*
     * Not found, and this is the root theme; return null element, "".
     * (@@@ SHOULD: signal a background error)
     */
    entryPtr = Tcl_FindHashEntry(&themePtr->elementTable, "");
    /* ASSERT: entryPtr != 0 */
    return (Ttk_ElementClass *)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

const char *Ttk_ElementClassName(Ttk_ElementClass *elementClass)
{
    return elementClass->name;
}

/*
 * Ttk_RegisterElementFactory --
 *	Register a new element factory.
 */
int Ttk_RegisterElementFactory(
    Tcl_Interp *interp,	const char *name,
    Ttk_ElementFactory factory, void *clientData)
{
    StylePackageData *pkgPtr = GetStylePackageData(interp);
    FactoryRec *recPtr = (FactoryRec *)ckalloc(sizeof(*recPtr));
    FactoryRec *recPtr = ckalloc(sizeof(*recPtr));
    Tcl_HashEntry *entryPtr;
    int newEntry;

    recPtr->factory = factory;
    recPtr->clientData = clientData;

    entryPtr = Tcl_CreateHashEntry(&pkgPtr->factoryTable, name, &newEntry);
    if (!newEntry) {
    	/* Free old factory: */
	ckfree(Tcl_GetHashValue(entryPtr));
    }
    Tcl_SetHashValue(entryPtr, recPtr);

    return TCL_OK;
}

/* Ttk_CloneElement -- element factory procedure.
 * 	(style element create $name) "from" $theme ?$element?
 */
static int Ttk_CloneElement(
    Tcl_Interp *interp, TCL_UNUSED(void *),
    Tcl_Interp *interp, void *clientData,
    Ttk_Theme theme, const char *elementName,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    Ttk_Theme fromTheme;
    Ttk_ElementClass *fromElement;

    if (objc <= 0 || objc > 2) {
	Tcl_WrongNumArgs(interp, 0, objv, "theme ?element?");
	return TCL_ERROR;
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
864
865
866
867
868
869
870

871
872
873
874
875
876
877
878







-
+







 *	if interp is non-NULL.
 */

Ttk_ElementClass *Ttk_RegisterElement(
    Tcl_Interp *interp,		/* Where to leave error messages */
    Ttk_Theme theme,		/* Style engine providing the implementation. */
    const char *name,		/* Name of new element */
    const Ttk_ElementSpec *specPtr, 	/* Static template information */
    Ttk_ElementSpec *specPtr, 	/* Static template information */
    void *clientData)		/* application-specific data */
{
    Ttk_ElementClass *elementClass;
    Tcl_HashEntry *entryPtr;
    int newEntry;

    if (specPtr->version != TK_STYLE_VERSION_2) {
910
911
912
913
914
915
916
917

918
919
920
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919







-
+










-
+







	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Duplicate element %s", name));
	    Tcl_SetErrorCode(interp, "TTK", "REGISTER_ELEMENT", "DUPE", NULL);
	}
	return 0;
    }

    name = (char *)Tcl_GetHashKey(&theme->elementTable, entryPtr);
    name = Tcl_GetHashKey(&theme->elementTable, entryPtr);
    elementClass = NewElementClass(name, specPtr, clientData);
    Tcl_SetHashValue(entryPtr, elementClass);

    return elementClass;
}

/* Ttk_RegisterElementSpec (deprecated) --
 * 	Register a new element.
 */
int Ttk_RegisterElementSpec(Ttk_Theme theme,
    const char *name, const Ttk_ElementSpec *specPtr, void *clientData)
    const char *name, Ttk_ElementSpec *specPtr, void *clientData)
{
    return Ttk_RegisterElement(NULL, theme, name, specPtr, clientData)
	   ? TCL_OK : TCL_ERROR;
}

/*------------------------------------------------------------------------
 * +++ Element record initialization.
985
986
987
988
989
990
991
992

993
994
995
996
997

998
999
1000
1001

1002
1003
1004
1005
1006

1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
969
970
971
972
973
974
975

976
977
978
979
980

981
982
983
984

985
986
987
988
989

990
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004
1005







-
+




-
+



-
+




-
+







-
+







 * 	Tcl_Obj * reference counts are _NOT_ adjusted.
 */

static
int InitializeElementRecord(
    Ttk_ElementClass *eclass,	/* Element instance to initialize */
    Ttk_Style style,		/* Style table */
    void *widgetRecord,		/* Source of widget option values */
    char *widgetRecord,		/* Source of widget option values */
    Tk_OptionTable optionTable,	/* Option table describing widget record */
    Tk_Window tkwin,		/* Corresponding window */
    Ttk_State state)	/* Widget or element state */
{
    void *elementRecord = eclass->elementRecord;
    char *elementRecord = eclass->elementRecord;
    OptionMap optionMap = GetOptionMap(eclass,optionTable);
    int nResources = eclass->nResources;
    Ttk_ResourceCache cache = style->cache;
    const Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options;
    Ttk_ElementOptionSpec *elementOption = eclass->specPtr->options;

    int i;
    for (i=0; i<nResources; ++i, ++elementOption) {
	Tcl_Obj **dest = (Tcl_Obj **)
	    ((char *)elementRecord + elementOption->offset);
	    (elementRecord + elementOption->offset);
	const char *optionName = elementOption->optionName;
	Tcl_Obj *dynamicSetting = Ttk_StyleMap(style, optionName, state);
	Tcl_Obj *widgetValue = 0;
	Tcl_Obj *elementDefault = eclass->defaultValues[i];

	if (optionMap[i]) {
	    widgetValue = *(Tcl_Obj **)
		((char *)widgetRecord + optionMap[i]->objOffset);
		(widgetRecord + optionMap[i]->objOffset);
	}

	if (widgetValue) {
	    *dest = widgetValue;
	} else if (dynamicSetting) {
	    *dest = dynamicSetting;
	} else {
1079
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077







-
+







 *	Compute the requested size of the given element.
 */

void
Ttk_ElementSize(
    Ttk_ElementClass *eclass,		/* Element to query */
    Ttk_Style style,			/* Style settings */
    void *recordPtr,			/* The widget record. */
    char *recordPtr,			/* The widget record. */
    Tk_OptionTable optionTable,		/* Description of widget record */
    Tk_Window tkwin,			/* The widget window. */
    Ttk_State state,			/* Current widget state */
    int *widthPtr, 			/* Requested width */
    int *heightPtr,			/* Reqested height */
    Ttk_Padding *paddingPtr)		/* Requested inner border */
{
1109
1110
1111
1112
1113
1114
1115
1116

1117
1118
1119
1120
1121
1122
1123
1093
1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1107







-
+







 *	Draw the given widget element in a given drawable area.
 */

void
Ttk_DrawElement(
    Ttk_ElementClass *eclass,		/* Element instance */
    Ttk_Style style,			/* Style settings */
    void *recordPtr,			/* The widget record. */
    char *recordPtr,			/* The widget record. */
    Tk_OptionTable optionTable,		/* Description of option table */
    Tk_Window tkwin,			/* The widget window. */
    Drawable d,				/* Where to draw element. */
    Ttk_Box b,				/* Element area */
    Ttk_State state)			/* Widget or element state flags. */
{
    if (b.width <= 0 || b.height <= 0)
1149
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177


1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195

1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159


1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178

1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189







-
+



















-
-
+
+















-
+

-
+


-
+







int TtkEnumerateHashTable(Tcl_Interp *interp, Tcl_HashTable *ht)
{
    Tcl_HashSearch search;
    Tcl_Obj *result = Tcl_NewListObj(0, NULL);
    Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(ht, &search);

    while (entryPtr != NULL) {
	Tcl_Obj *nameObj = Tcl_NewStringObj((const char *)Tcl_GetHashKey(ht, entryPtr),-1);
	Tcl_Obj *nameObj = Tcl_NewStringObj(Tcl_GetHashKey(ht, entryPtr),-1);
	Tcl_ListObjAppendElement(interp, result, nameObj);
	entryPtr = Tcl_NextHashEntry(&search);
    }

    Tcl_SetObjResult(interp, result);
    return TCL_OK;
}

/* HashTableToDict --
 * 	Helper routine.  Converts a TCL_STRING_KEYS Tcl_HashTable
 * 	with Tcl_Obj * entries into a dictionary.
 */
static Tcl_Obj* HashTableToDict(Tcl_HashTable *ht)
{
    Tcl_HashSearch search;
    Tcl_Obj *result = Tcl_NewListObj(0, NULL);
    Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(ht, &search);

    while (entryPtr != NULL) {
	Tcl_Obj *nameObj = Tcl_NewStringObj((const char *)Tcl_GetHashKey(ht, entryPtr),-1);
	Tcl_Obj *valueObj = (Tcl_Obj *)Tcl_GetHashValue(entryPtr);
	Tcl_Obj *nameObj = Tcl_NewStringObj(Tcl_GetHashKey(ht, entryPtr),-1);
	Tcl_Obj *valueObj = Tcl_GetHashValue(entryPtr);
	Tcl_ListObjAppendElement(NULL, result, nameObj);
	Tcl_ListObjAppendElement(NULL, result, valueObj);
	entryPtr = Tcl_NextHashEntry(&search);
    }

    return result;
}

/* + style map $style ? -resource statemap ... ?
 *
 * 	Note that resource names are unconstrained; the Style
 * 	doesn't know what resources individual elements may use.
 */
static int
StyleMapCmd(
    void *clientData,		/* StylePackageData pointer */
    ClientData clientData,		/* Master StylePackageData pointer */
    Tcl_Interp *interp,			/* Current interpreter */
    Tcl_Size objc,				/* Number of arguments */
    int objc,				/* Number of arguments */
    Tcl_Obj *const objv[])		/* Argument objects */
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    const char *styleName;
    Style *stylePtr;
    int i;

    if (objc < 3) {
usage:
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277

1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1237
1238
1239
1240
1241
1242
1243

1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271







-
+

-
+














-
+


-
+







    ThemeChanged(pkgPtr);
    return TCL_OK;
}

/* + style configure $style -option ?value...
 */
static int StyleConfigureCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    const char *styleName;
    Style *stylePtr;
    int i;

    if (objc < 3) {
usage:
	Tcl_WrongNumArgs(interp,2,objv,"style ?-option ?value...??");
	return TCL_ERROR;
    }

    styleName = Tcl_GetString(objv[2]);
    stylePtr = Ttk_GetStyle(theme, styleName);

    if (objc == 3) {		/* style configure $styleName */
    if (objc == 3) {		/* style default $styleName */
	Tcl_SetObjResult(interp, HashTableToDict(&stylePtr->defaultsTable));
	return TCL_OK;
    } else if (objc == 4) {	/* style configure $styleName -option */
    } else if (objc == 4) {	/* style default $styleName -option */
	const char *optionName = Tcl_GetString(objv[3]);
	Tcl_HashEntry *entryPtr =
	    Tcl_FindHashEntry(&stylePtr->defaultsTable, optionName);
	if (entryPtr) {
	    Tcl_SetObjResult(interp, (Tcl_Obj*)Tcl_GetHashValue(entryPtr));
	}
	return TCL_OK;
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317

1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329


1330

1331
1332
1333
1334
1335
1336
1337
1292
1293
1294
1295
1296
1297
1298

1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323







-
+

-
+












+
+
-
+







    ThemeChanged(pkgPtr);
    return TCL_OK;
}

/* + style lookup $style -option ?statespec? ?defaultValue?
 */
static int StyleLookupCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    Ttk_Style style = NULL;
    const char *optionName;
    Ttk_State state = 0ul;
    Tcl_Obj *result;

    if (objc < 4 || objc > 6) {
	Tcl_WrongNumArgs(interp, 2, objv, "style -option ?state? ?default?");
	return TCL_ERROR;
    }

    style = Ttk_GetStyle(theme, Tcl_GetString(objv[2]));
    if (!style) {
	return TCL_ERROR;

    }
    optionName = Tcl_GetString(objv[3]);

    if (objc >= 5) {
	Ttk_StateSpec stateSpec;
	/* @@@ SB: Ttk_GetStateFromObj(); 'offbits' spec is ignored */
	if (Ttk_GetStateSpecFromObj(interp, objv[4], &stateSpec) != TCL_OK) {
	    return TCL_ERROR;
1348
1349
1350
1351
1352
1353
1354
1355

1356
1357

1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369

1370
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394


1395
1396
1397
1398
1399
1400
1401
1334
1335
1336
1337
1338
1339
1340

1341
1342

1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354

1355
1356

1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378


1379
1380
1381
1382
1383
1384
1385
1386
1387







-
+

-
+











-
+

-
+



















-
+

-
-
+
+







	Tcl_SetObjResult(interp, result);
    }

    return TCL_OK;
}

static int StyleThemeCurrentCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj * const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr = NULL;
    const char *name = NULL;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 3, objv, "");
	return TCL_ERROR;
    }

    entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
    while (entryPtr != NULL) {
	Theme *ptr = (Theme *)Tcl_GetHashValue(entryPtr);
	Theme *ptr = Tcl_GetHashValue(entryPtr);
	if (ptr == pkgPtr->currentTheme) {
	    name = (char *)Tcl_GetHashKey(&pkgPtr->themeTable, entryPtr);
	    name = Tcl_GetHashKey(&pkgPtr->themeTable, entryPtr);
	    break;
	}
	entryPtr = Tcl_NextHashEntry(&search);
    }

    if (name == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"error: failed to get theme name", -1));
	Tcl_SetErrorCode(interp, "TTK", "THEME", "NAMELESS", NULL);
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
    return TCL_OK;
}

/* + style theme create name ?-parent $theme? ?-settings { script }?
 */
static int StyleThemeCreateCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    static const char *const optStrings[] =
    StylePackageData *pkgPtr = clientData;
    static const char *optStrings[] =
    	 { "-parent", "-settings", NULL };
    enum { OP_PARENT, OP_SETTINGS };
    Ttk_Theme parentTheme = pkgPtr->defaultTheme, newTheme;
    Tcl_Obj *settingsScript = NULL;
    const char *themeName;
    int i;

1448
1449
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474

1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1434
1435
1436
1437
1438
1439
1440


1441


1442

1443

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453

1454
1455

1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466







-
-
+
-
-

-
+
-










-
+

-
+


-
+







    }
}

/* + style theme names --
 * 	Return list of registered themes.
 */
static int StyleThemeNamesCmd(
    void *clientData,
    Tcl_Interp *interp,
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
    TCL_UNUSED(Tcl_Size), /* objc */
    TCL_UNUSED(Tcl_Obj *const *)) /* objv */
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;

    return TtkEnumerateHashTable(interp, &pkgPtr->themeTable);
}

/* + style theme settings $theme $script
 *
 * 	Temporarily sets the current theme to $themeName,
 * 	evaluates $script, then restores the old theme.
 */
static int
StyleThemeSettingsCmd(
    void *clientData,		/* StylePackageData pointer */
    ClientData clientData,		/* Master StylePackageData pointer */
    Tcl_Interp *interp,			/* Current interpreter */
    Tcl_Size objc,				/* Number of arguments */
    int objc,				/* Number of arguments */
    Tcl_Obj *const objv[])		/* Argument objects */
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme oldTheme = pkgPtr->currentTheme;
    Ttk_Theme newTheme;
    int status;

    if (objc != 5) {
	Tcl_WrongNumArgs(interp, 3, objv, "theme script");
	return TCL_ERROR;
1494
1495
1496
1497
1498
1499
1500
1501

1502
1503

1504
1505
1506
1507
1508
1509
1510
1476
1477
1478
1479
1480
1481
1482

1483
1484

1485
1486
1487
1488
1489
1490
1491
1492







-
+

-
+








    return status;
}

/* + style element create name type ? ...args ?
 */
static int StyleElementCreateCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    const char *elementName, *factoryName;
    Tcl_HashEntry *entryPtr;
    FactoryRec *recPtr;

    if (objc < 5) {
	Tcl_WrongNumArgs(interp, 3, objv, "name type ?-option value ...?");
1519
1520
1521
1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532
1533
1534
1535
1536

1537
1538

1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554

1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568


1569
1570
1571
1572
1573
1574
1575
1501
1502
1503
1504
1505
1506
1507

1508
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519

1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533

1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548


1549
1550
1551
1552
1553
1554
1555
1556
1557







-
+









-
+

-
+













-
+

-
+












-
-
+
+







	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"No such element type %s", factoryName));
	Tcl_SetErrorCode(interp, "TTK", "LOOKUP", "ELEMENT_TYPE", factoryName,
		NULL);
	return TCL_ERROR;
    }

    recPtr = (FactoryRec *)Tcl_GetHashValue(entryPtr);
    recPtr = Tcl_GetHashValue(entryPtr);

    return recPtr->factory(interp, recPtr->clientData,
	    theme, elementName, objc - 5, objv + 5);
}

/* + style element names --
 * 	Return a list of elements defined in the current theme.
 */
static int StyleElementNamesCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 3, objv, NULL);
	return TCL_ERROR;
    }
    return TtkEnumerateHashTable(interp, &theme->elementTable);
}

/* + style element options $element --
 * 	Return list of element options for specified element
 */
static int StyleElementOptionsCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    const char *elementName;
    Ttk_ElementClass *elementClass;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 3, objv, "element");
	return TCL_ERROR;
    }

    elementName = Tcl_GetString(objv[3]);
    elementClass = Ttk_GetElement(theme, elementName);
    if (elementClass) {
	const Ttk_ElementSpec *specPtr = elementClass->specPtr;
	const Ttk_ElementOptionSpec *option = specPtr->options;
	Ttk_ElementSpec *specPtr = elementClass->specPtr;
	Ttk_ElementOptionSpec *option = specPtr->options;
	Tcl_Obj *result = Tcl_NewListObj(0,0);

	while (option->optionName) {
	    Tcl_ListObjAppendElement(
		interp, result, Tcl_NewStringObj(option->optionName,-1));
	    ++option;
	}
1583
1584
1585
1586
1587
1588
1589
1590

1591
1592

1593
1594
1595
1596
1597
1598
1599
1565
1566
1567
1568
1569
1570
1571

1572
1573

1574
1575
1576
1577
1578
1579
1580
1581







-
+

-
+







    Tcl_SetErrorCode(interp, "TTK", "LOOKUP", "ELEMENT", elementName, NULL);
    return TCL_ERROR;
}

/* + style layout name ?spec?
 */
static int StyleLayoutCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme = pkgPtr->currentTheme;
    const char *layoutName;
    Ttk_LayoutTemplate layoutTemplate;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "name ?spec?");
	return TCL_ERROR;
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658

1659
1660

1661
1662
1663

1664
1665
1666
1667
1668
1669
1670
1600
1601
1602
1603
1604
1605
1606




























1607
1608
1609
1610
1611

1612
1613

1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+

-
+


-
+







	}
	Ttk_RegisterLayoutTemplate(theme, layoutName, layoutTemplate);
	ThemeChanged(pkgPtr);
    }
    return TCL_OK;
}

/* + style theme styles ?$theme? --
 * 	Return list of styles available in $theme.
 *      Use the current theme if $theme is omitted.
 */
static int StyleThemeStylesCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[])
{
    Ttk_Theme themePtr;

    if (objc < 3 || objc > 4) {
        Tcl_WrongNumArgs(interp, 3, objv, "?theme?");
        return TCL_ERROR;
    }

    if (objc == 3) {
        themePtr = Ttk_GetCurrentTheme(interp);
    } else {
        themePtr = Ttk_GetTheme(interp, Tcl_GetString(objv[3]));
    }
    if (!themePtr)
        return TCL_ERROR;

    return TtkEnumerateHashTable(interp, &themePtr->styleTable);
}

/* + style theme use $theme --
 *  	Sets the current theme to $theme
 */
static int
StyleThemeUseCmd(
    void *clientData,		/* StylePackageData pointer */
    ClientData clientData,		/* Master StylePackageData pointer */
    Tcl_Interp *interp,			/* Current interpreter */
    Tcl_Size objc,				/* Number of arguments */
    int objc,				/* Number of arguments */
    Tcl_Obj *const objv[])		/* Argument objects */
{
    StylePackageData *pkgPtr = (StylePackageData *)clientData;
    StylePackageData *pkgPtr = clientData;
    Ttk_Theme theme;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 3, objv, "?theme?");
	return TCL_ERROR;
    }

1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1639
1640
1641
1642
1643
1644
1645

1646
1647
1648
1649
1650
1651
1652







-







 *	Implementation of the [style] command.
 */

static const Ttk_Ensemble StyleThemeEnsemble[] = {
    { "create", StyleThemeCreateCmd, 0 },
    { "names", StyleThemeNamesCmd, 0 },
    { "settings", StyleThemeSettingsCmd, 0 },
    { "styles", StyleThemeStylesCmd, 0 },
    { "use", StyleThemeUseCmd, 0 },
    { NULL, 0, 0 }
};

static const Ttk_Ensemble StyleElementEnsemble[] = {
    { "create", StyleElementCreateCmd, 0 },
    { "names", StyleElementNamesCmd, 0 },
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
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







-
+









-
-
+
+







    { "theme", 0, StyleThemeEnsemble },
    { "element", 0, StyleElementEnsemble },
    { NULL, 0, 0 }
};

static int
StyleObjCmd(
    void *clientData,		/* StylePackageData pointer */
    ClientData clientData,		/* Master StylePackageData pointer */
    Tcl_Interp *interp,			/* Current interpreter */
    int objc,				/* Number of arguments */
    Tcl_Obj *const objv[])		/* Argument objects */
{
    return Ttk_InvokeEnsemble(StyleEnsemble, 1, clientData,interp,objc,objv);
}

MODULE_SCOPE
int Ttk_InvokeEnsemble(	/* Run an ensemble command */
    const Ttk_Ensemble *ensemble, Tcl_Size cmdIndex,
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    const Ttk_Ensemble *ensemble, int cmdIndex,
    void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    while (cmdIndex < objc) {
	int index;
	if (Tcl_GetIndexFromObjStruct(interp,
		objv[cmdIndex], ensemble, sizeof(ensemble[0]),
		"command", 0, &index)
	    != TCL_OK)
1752
1753
1754
1755
1756
1757
1758
1759

1760
1761
1762
1763
1764
1765
1766
1705
1706
1707
1708
1709
1710
1711

1712
1713
1714
1715
1716
1717
1718
1719







-
+







 *	package on a per-interp basis.
 */

void Ttk_StylePkgInit(Tcl_Interp *interp)
{
    Tcl_Namespace *nsPtr;

    StylePackageData *pkgPtr = (StylePackageData *)ckalloc(sizeof(StylePackageData));
    StylePackageData *pkgPtr = ckalloc(sizeof(StylePackageData));

    pkgPtr->interp = interp;
    Tcl_InitHashTable(&pkgPtr->themeTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&pkgPtr->factoryTable, TCL_STRING_KEYS);
    pkgPtr->cleanupList = NULL;
    pkgPtr->cache = Ttk_CreateResourceCache(interp);
    pkgPtr->themeChangePending = 0;

Changes to generic/ttk/ttkTheme.h.

25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
25
26
27
28
29
30
31




32
33

34
35
36
37
38
39
40
41







-
-
-
-


-
+







#define TTK_VERSION    TK_VERSION
#define TTK_PATCH_LEVEL TK_PATCH_LEVEL

/*------------------------------------------------------------------------
 * +++ Defaults for element option specifications.
 */
#define DEFAULT_FONT 		"TkDefaultFont"
#ifdef MAC_OSX_TK
#define DEFAULT_BACKGROUND	"systemTextBackgroundColor"
#define DEFAULT_FOREGROUND	"systemTextColor"
#else
#define DEFAULT_BACKGROUND	"#d9d9d9"
#define DEFAULT_FOREGROUND	"black"
#endif

/*------------------------------------------------------------------------
 * +++ Widget states.
 * 	Keep in sync with stateNames[] in tkstate.c.
 */

typedef unsigned int Ttk_State;

71
72
73
74
75
76
77



78
79
80
81
82



83
84
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99
100
101
102
103








104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121



122
123
124
125
126
127
128
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143







+
+
+





+
+
+









+
+












+
+
+
+
+
+
+
+


















+
+
+








#define Ttk_StateMatches(state, spec) \
    (((state) & ((spec)->onbits|(spec)->offbits)) == (spec)->onbits)

#define Ttk_ModifyState(state, spec) \
    (((state) & ~(spec)->offbits) | (spec)->onbits)

TTKAPI int Ttk_GetStateSpecFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_StateSpec *);
TTKAPI Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits,unsigned int offbits);

/*------------------------------------------------------------------------
 * +++ State maps and state tables.
 */
typedef Tcl_Obj *Ttk_StateMap;

TTKAPI Ttk_StateMap Ttk_GetStateMapFromObj(Tcl_Interp *, Tcl_Obj *);
TTKAPI Tcl_Obj *Ttk_StateMapLookup(Tcl_Interp*, Ttk_StateMap, Ttk_State);

/*
 * Table for looking up an integer index based on widget state:
 */
typedef struct
{
    int index;			/* Value to return if this entry matches */
    unsigned int onBits;	/* Bits which must be set */
    unsigned int offBits;	/* Bits which must be cleared */
} Ttk_StateTable;

TTKAPI int Ttk_StateTableLookup(Ttk_StateTable map[], Ttk_State);

/*------------------------------------------------------------------------
 * +++ Padding.
 * 	Used to represent internal padding and borders.
 */
typedef struct
{
    short left;
    short top;
    short right;
    short bottom;
} Ttk_Padding;

TTKAPI int Ttk_GetPaddingFromObj(Tcl_Interp*,Tk_Window,Tcl_Obj*,Ttk_Padding*);
TTKAPI int Ttk_GetBorderFromObj(Tcl_Interp*,Tcl_Obj*,Ttk_Padding*);

TTKAPI Ttk_Padding Ttk_MakePadding(short l, short t, short r, short b);
TTKAPI Ttk_Padding Ttk_UniformPadding(short borderWidth);
TTKAPI Ttk_Padding Ttk_AddPadding(Ttk_Padding, Ttk_Padding);
TTKAPI Ttk_Padding Ttk_RelievePadding(Ttk_Padding, int relief, int n);

#define Ttk_PaddingWidth(p) ((p).left + (p).right)
#define Ttk_PaddingHeight(p) ((p).top + (p).bottom)

#define Ttk_SetMargins(tkwin, pad) \
    Tk_SetInternalBorderEx(tkwin, pad.left, pad.right, pad.top, pad.bottom)

/*------------------------------------------------------------------------
 * +++ Boxes.
 * 	Used to represent rectangular regions
 */
typedef struct 	/* Hey, this is an XRectangle! */
{
    int x;
    int y;
    int width;
    int height;
} Ttk_Box;

TTKAPI Ttk_Box Ttk_MakeBox(int x, int y, int width, int height);
TTKAPI int Ttk_BoxContains(Ttk_Box, int x, int y);

#define Ttk_WinBox(tkwin) Ttk_MakeBox(0,0,Tk_Width(tkwin),Tk_Height(tkwin))

/*------------------------------------------------------------------------
 * +++ Layout utilities.
 */
typedef enum {
142
143
144
145
146
147
148

149
150
151
152
153
154
155
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171







+







/*
 * Aliases and useful combinations:
 */
#define TTK_FILL_X	(0x3)	/* -sticky ew */
#define TTK_FILL_Y	(0xC)	/* -sticky ns */
#define TTK_FILL_BOTH	(0xF)	/* -sticky nswe */

TTKAPI int Ttk_GetStickyFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_Sticky *);
TTKAPI Tcl_Obj *Ttk_NewStickyObj(Ttk_Sticky);

/*
 * Extra bits for position specifications (combine -side and -sticky)
 */

typedef unsigned int Ttk_PositionSpec;	/* See below */
168
169
170
171
172
173
174






175
176
177
178
179
180
181
182
183
184
185
186







187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219

220
221
222
223




224
225
226




227
228
229
230
231
232
233
234
235
236
237
238
239





240
241
242
243
244
245
246
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274



275
276
277
278
279
280
281
282
283
284
285
286







+
+
+
+
+
+












+
+
+
+
+
+
+







+
+
















-
+








-
+




+
+
+
+


-
+
+
+
+










-
-
-
+
+
+
+
+







#define _TTK_CHILDREN	(0x1000)/* for LayoutSpecs -- children follow */
#define _TTK_LAYOUT_END	(0x2000)/* for LayoutSpecs -- end of child list */
#define _TTK_LAYOUT	(0x4000)/* for LayoutSpec tables -- define layout */

#define _TTK_MASK_STICK (0x0F)	/* See Ttk_UnparseLayout() */
#define _TTK_MASK_PACK	(0xF0)	/* See Ttk_UnparseLayout(), packStrings */

TTKAPI Ttk_Box Ttk_PackBox(Ttk_Box *cavity, int w, int h, Ttk_Side side);
TTKAPI Ttk_Box Ttk_StickBox(Ttk_Box parcel, int w, int h, Ttk_Sticky sticky);
TTKAPI Ttk_Box Ttk_AnchorBox(Ttk_Box parcel, int w, int h, Tk_Anchor anchor);
TTKAPI Ttk_Box Ttk_PadBox(Ttk_Box b, Ttk_Padding p);
TTKAPI Ttk_Box Ttk_ExpandBox(Ttk_Box b, Ttk_Padding p);
TTKAPI Ttk_Box Ttk_PlaceBox(Ttk_Box *cavity, int w,int h, Ttk_Side,Ttk_Sticky);
TTKAPI Ttk_Box Ttk_PositionBox(Ttk_Box *cavity, int w, int h, Ttk_PositionSpec);

/*------------------------------------------------------------------------
 * +++ Themes.
 */
MODULE_SCOPE void Ttk_StylePkgInit(Tcl_Interp *);

typedef struct Ttk_Theme_ *Ttk_Theme;
typedef struct Ttk_ElementClass_ Ttk_ElementClass;
typedef struct Ttk_Layout_ *Ttk_Layout;
typedef struct Ttk_LayoutNode_ *Ttk_Element;
typedef struct Ttk_Style_ *Ttk_Style;

TTKAPI Ttk_Theme Ttk_GetTheme(Tcl_Interp *interp, const char *name);
TTKAPI Ttk_Theme Ttk_GetDefaultTheme(Tcl_Interp *interp);
TTKAPI Ttk_Theme Ttk_GetCurrentTheme(Tcl_Interp *interp);

TTKAPI Ttk_Theme Ttk_CreateTheme(
    Tcl_Interp *interp, const char *name, Ttk_Theme parent);

typedef int (Ttk_ThemeEnabledProc)(Ttk_Theme theme, void *clientData);
MODULE_SCOPE void Ttk_SetThemeEnabledProc(Ttk_Theme, Ttk_ThemeEnabledProc, void *);

MODULE_SCOPE int Ttk_UseTheme(Tcl_Interp *, Ttk_Theme);

typedef void (Ttk_CleanupProc)(void *clientData);
TTKAPI void Ttk_RegisterCleanup(
    Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc);

/*------------------------------------------------------------------------
 * +++ Elements.
 */

enum TTKStyleVersion2 { TK_STYLE_VERSION_2 = 2 };

typedef void (Ttk_ElementSizeProc)(void *clientData, void *elementRecord,
        Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding*);
typedef void (Ttk_ElementDrawProc)(void *clientData, void *elementRecord,
        Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state);

typedef struct Ttk_ElementOptionSpec
{
    const char *optionName;		/* Command-line name of the widget option */
    Tk_OptionType type; 	/* Accepted option types */
    Tcl_Size offset;			/* Offset of Tcl_Obj* field in element record */
    int offset;			/* Offset of Tcl_Obj* field in element record */
    const char *defaultValue;		/* Default value to used if resource missing */
} Ttk_ElementOptionSpec;

#define TK_OPTION_ANY TK_OPTION_STRING

typedef struct Ttk_ElementSpec {
    enum TTKStyleVersion2 version;	/* Version of the style support. */
    size_t elementSize;			/* Size of element record */
    const Ttk_ElementOptionSpec *options;	/* List of options, NULL-terminated */
    Ttk_ElementOptionSpec *options;	/* List of options, NULL-terminated */
    Ttk_ElementSizeProc *size;		/* Compute min size and padding */
    Ttk_ElementDrawProc *draw;  	/* Draw the element */
} Ttk_ElementSpec;

TTKAPI Ttk_ElementClass *Ttk_RegisterElement(
	Tcl_Interp *interp, Ttk_Theme theme, const char *elementName,
	Ttk_ElementSpec *, void *clientData);

typedef int (*Ttk_ElementFactory)
	(Tcl_Interp *, void *clientData,
	 Ttk_Theme, const char *elementName, Tcl_Size objc, Tcl_Obj *const objv[]);
	 Ttk_Theme, const char *elementName, int objc, Tcl_Obj *const objv[]);

TTKAPI int Ttk_RegisterElementFactory(
	Tcl_Interp *, const char *name, Ttk_ElementFactory, void *clientData);

/*
 * Null element implementation:
 * has no geometry or layout; may be used as a stub or placeholder.
 */

typedef struct {
    Tcl_Obj	*unused;
} NullElement;

MODULE_SCOPE Ttk_ElementSizeProc TtkNullElementSize;
MODULE_SCOPE Ttk_ElementDrawProc TtkNullElementDraw;
MODULE_SCOPE const Ttk_ElementOptionSpec TtkNullElementOptions[];
MODULE_SCOPE void TtkNullElementSize
	(void *, void *, Tk_Window, int *, int *, Ttk_Padding *);
MODULE_SCOPE void TtkNullElementDraw
	(void *, void *, Tk_Window, Drawable, Ttk_Box, Ttk_State);
MODULE_SCOPE Ttk_ElementOptionSpec TtkNullElementOptions[];
MODULE_SCOPE Ttk_ElementSpec ttkNullElementSpec;

/*------------------------------------------------------------------------
 * +++ Layout templates.
 */
typedef struct {
    const char *	elementName;
259
260
261
262
263
264
265



266
267
268
269
270
271
272
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315







+
+
+







				{ 0, _TTK_LAYOUT_END },
#define TTK_NODE(name, flags)	{ name, flags },
#define TTK_END_LAYOUT_TABLE	{ 0, _TTK_LAYOUT | _TTK_LAYOUT_END } };

#define TTK_BEGIN_LAYOUT(name)	static TTKLayoutInstruction name[] = {
#define TTK_END_LAYOUT 		{ 0, _TTK_LAYOUT_END } };

TTKAPI void Ttk_RegisterLayout(
    Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec);

TTKAPI void Ttk_RegisterLayouts(
    Ttk_Theme theme, Ttk_LayoutSpec layoutTable);

/*------------------------------------------------------------------------
 * +++ Layout instances.
 */

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
337
338
339
340
341
342
343

344
345
346
347
348
349
350







-







MODULE_SCOPE Ttk_Box Ttk_ClientRegion(Ttk_Layout, const char *elementName);

MODULE_SCOPE Ttk_Box Ttk_LayoutNodeInternalParcel(Ttk_Layout,Ttk_Element);
MODULE_SCOPE Ttk_Padding Ttk_LayoutNodeInternalPadding(Ttk_Layout,Ttk_Element);
MODULE_SCOPE void Ttk_LayoutNodeReqSize(Ttk_Layout, Ttk_Element, int *w, int *h);

MODULE_SCOPE void Ttk_PlaceElement(Ttk_Layout, Ttk_Element, Ttk_Box);
MODULE_SCOPE void Ttk_AnchorElement(Ttk_Element node, Tk_Anchor anchor);
MODULE_SCOPE void Ttk_ChangeElementState(Ttk_Element,unsigned set,unsigned clr);

MODULE_SCOPE Tcl_Obj *Ttk_QueryOption(Ttk_Layout, const char *, Ttk_State);

TTKAPI Ttk_Style Ttk_LayoutStyle(Ttk_Layout);
TTKAPI Tcl_Obj *Ttk_StyleDefault(Ttk_Style, const char *optionName);
TTKAPI Tcl_Obj *Ttk_StyleMap(Ttk_Style, const char *optionName, Ttk_State);
327
328
329
330
331
332
333
334

335
336

337
338
339
340
341
342
343

344
345

346
347
348
349

350
351
352
353
354
355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376

377
378
379
380
381
382


383
384
385
386
387
388
389
369
370
371
372
373
374
375

376
377

378
379
380
381
382
383
384
385
386
387

388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415
416
417

418
419
420
421
422


423
424
425
426
427
428
429
430
431







-
+

-
+







+

-
+
-


-
+













-
+












-
+




-
-
+
+







/*------------------------------------------------------------------------
 * +++ Image specifications.
 */

typedef struct TtkImageSpec Ttk_ImageSpec;
TTKAPI Ttk_ImageSpec *TtkGetImageSpec(Tcl_Interp *, Tk_Window, Tcl_Obj *);
TTKAPI Ttk_ImageSpec *TtkGetImageSpecEx(Tcl_Interp *, Tk_Window, Tcl_Obj *,
					Tk_ImageChangedProc *, void *);
					Tk_ImageChangedProc *, ClientData);
TTKAPI void TtkFreeImageSpec(Ttk_ImageSpec *);
TTKAPI Tk_Image TtkSelectImage(Ttk_ImageSpec *, Tk_Window, Ttk_State);
TTKAPI Tk_Image TtkSelectImage(Ttk_ImageSpec *, Ttk_State);

/*------------------------------------------------------------------------
 * +++ Miscellaneous enumerations.
 * 	Other stuff that element implementations need to know about.
 */
typedef enum 			/* -default option values */
{
    TTK_BUTTON_DEFAULT_NORMAL,	/* widget defaultable */
    TTK_BUTTON_DEFAULT_ACTIVE,	/* currently the default widget */
    TTK_BUTTON_DEFAULT_DISABLED,	/* not defaultable */
    TTK_BUTTON_DEFAULT_DISABLED	/* not defaultable */
    TTK_BUTTON_DEFAULT_NORMAL	/* widget defaultable */
} Ttk_ButtonDefaultState;

TTKAPI int Ttk_GetButtonDefaultStateFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_ButtonDefaultState *);
TTKAPI int Ttk_GetButtonDefaultStateFromObj(Tcl_Interp *, Tcl_Obj *, int *);

typedef enum 			/* -compound option values */
{
    TTK_COMPOUND_NONE,  	/* image if specified, otherwise text */
    TTK_COMPOUND_TEXT,  	/* text only */
    TTK_COMPOUND_IMAGE,  	/* image only */
    TTK_COMPOUND_CENTER,	/* text overlays image */
    TTK_COMPOUND_TOP,   	/* image above text */
    TTK_COMPOUND_BOTTOM,	/* image below text */
    TTK_COMPOUND_LEFT,   	/* image to left of text */
    TTK_COMPOUND_RIGHT  	/* image to right of text */
} Ttk_Compound;

TTKAPI int Ttk_GetCompoundFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_Compound *);
TTKAPI int Ttk_GetCompoundFromObj(Tcl_Interp *, Tcl_Obj *, int *);

typedef enum { 		/* -orient option values */
    TTK_ORIENT_HORIZONTAL,
    TTK_ORIENT_VERTICAL
} Ttk_Orient;

/*------------------------------------------------------------------------
 * +++ Utilities.
 */

typedef struct TtkEnsemble {
    const char *name;			/* subcommand name */
    Tcl_ObjCmdProc2 *command; 		/* subcommand implementation, OR: */
    Tcl_ObjCmdProc *command; 		/* subcommand implementation, OR: */
    const struct TtkEnsemble *ensemble;	/* subcommand ensemble */
} Ttk_Ensemble;

MODULE_SCOPE int Ttk_InvokeEnsemble(	/* Run an ensemble command */
    const Ttk_Ensemble *commands, Tcl_Size cmdIndex,
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]);
    const Ttk_Ensemble *commands, int cmdIndex,
    void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);

MODULE_SCOPE int TtkEnumerateHashTable(Tcl_Interp *, Tcl_HashTable *);

/*------------------------------------------------------------------------
 * +++ Stub table declarations.
 */

Changes to generic/ttk/ttkThemeInt.h.

11
12
13
14
15
16
17
18

19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
11
12
13
14
15
16
17

18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41






42







-
+



-
+



















-
-
-
-
-
-


typedef struct Ttk_TemplateNode_ Ttk_TemplateNode, *Ttk_LayoutTemplate;

MODULE_SCOPE Ttk_ElementClass *Ttk_GetElement(Ttk_Theme, const char *name);
MODULE_SCOPE const char *Ttk_ElementClassName(Ttk_ElementClass *);

MODULE_SCOPE void Ttk_ElementSize(
	Ttk_ElementClass *, Ttk_Style, void *recordPtr, Tk_OptionTable,
	Ttk_ElementClass *, Ttk_Style, char *recordPtr, Tk_OptionTable,
	Tk_Window tkwin, Ttk_State state,
	int *widthPtr, int *heightPtr, Ttk_Padding*);
MODULE_SCOPE void Ttk_DrawElement(
	Ttk_ElementClass *, Ttk_Style, void *recordPtr, Tk_OptionTable,
	Ttk_ElementClass *, Ttk_Style, char *recordPtr, Tk_OptionTable,
	Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state);

MODULE_SCOPE Tcl_Obj *Ttk_QueryStyle(
    Ttk_Style, void *, Tk_OptionTable, const char *, Ttk_State state);

MODULE_SCOPE Ttk_LayoutTemplate Ttk_ParseLayoutTemplate(
	Tcl_Interp *, Tcl_Obj *);
MODULE_SCOPE Tcl_Obj *Ttk_UnparseLayoutTemplate(Ttk_LayoutTemplate);
MODULE_SCOPE Ttk_LayoutTemplate Ttk_BuildLayoutTemplate(Ttk_LayoutSpec);
MODULE_SCOPE void Ttk_FreeLayoutTemplate(Ttk_LayoutTemplate);
MODULE_SCOPE void Ttk_RegisterLayoutTemplate(
    Ttk_Theme theme, const char *layoutName, Ttk_LayoutTemplate);

MODULE_SCOPE Ttk_Style Ttk_GetStyle(Ttk_Theme themePtr, const char *styleName);
MODULE_SCOPE Ttk_LayoutTemplate Ttk_FindLayoutTemplate(
    Ttk_Theme themePtr, const char *layoutName);

MODULE_SCOPE const char *Ttk_StyleName(Ttk_Style);

MODULE_SCOPE void TtkSetBlinkCursorTimes(Tcl_Interp* interp);

MODULE_SCOPE int TtkBoxEqual(Ttk_Box, Ttk_Box);

#define TTK_OPTION_UNDERLINE_DEF(type, field) NULL, offsetof(type, field), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL

#endif /* _TTKTHEMEINT */

Changes to generic/ttk/ttkTrace.c.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30


31
32
33

34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28


29
30
31
32

33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61









-
+
















-
+

-
-
+
+


-
+



-
+
















-
+







/*
 * Copyright 2003, Joe English
 *
 * Simplified interface to Tcl_TraceVariable.
 *
 * PROBLEM: Can't distinguish "variable does not exist" (which is OK)
 * from other errors (which are not).
 */

#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

struct TtkTraceHandle_
{
    Tcl_Interp		*interp;	/* Containing interpreter */
    Tcl_Obj 		*varnameObj;	/* Name of variable being traced */
    Ttk_TraceProc	callback;	/* Callback procedure */
    void		*clientData;	/* Data to pass to callback */
};

/*
 * Tcl_VarTraceProc for trace handles.
 */
static char *
VarTraceProc(
    void *clientData,	/* Widget record pointer */
    ClientData clientData,	/* Widget record pointer */
    Tcl_Interp *interp, 	/* Interpreter containing variable. */
    TCL_UNUSED(const char *),	/* name1 */
    TCL_UNUSED(const char *),	/* name2 */
    const char *name1,		/* (unused) */
    const char *name2,		/* (unused) */
    int flags)			/* Information about what happened. */
{
    Ttk_TraceHandle *tracePtr = (Ttk_TraceHandle *)clientData;
    Ttk_TraceHandle *tracePtr = clientData;
    const char *name, *value;
    Tcl_Obj *valuePtr;

    if (Tcl_InterpDeleted(interp)) {
    if (flags & TCL_INTERP_DESTROYED) {
	return NULL;
    }

    name = Tcl_GetString(tracePtr->varnameObj);

    /*
     * If the variable is being unset, then re-establish the trace:
     */
    if (flags & TCL_TRACE_DESTROYED) {
	/*
	 * If a prior call to Ttk_UntraceVariable() left behind an
	 * indicator that we wanted this handler to be deleted (see below),
	 * cleanup the ClientData bits and exit.
	 */
	if (tracePtr->interp == NULL) {
	    Tcl_DecrRefCount(tracePtr->varnameObj);
	    ckfree(tracePtr);
	    ckfree((ClientData)tracePtr);
	    return NULL;
	}
	Tcl_TraceVar2(interp, name, NULL,
		TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		VarTraceProc, clientData);
	tracePtr->callback(tracePtr->clientData, NULL);
	return NULL;
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124







-
+










-
+

















-
+







 */
Ttk_TraceHandle *Ttk_TraceVariable(
    Tcl_Interp *interp,
    Tcl_Obj *varnameObj,
    Ttk_TraceProc callback,
    void *clientData)
{
    Ttk_TraceHandle *h = (Ttk_TraceHandle *)ckalloc(sizeof(*h));
    Ttk_TraceHandle *h = ckalloc(sizeof(*h));
    int status;

    h->interp = interp;
    h->varnameObj = Tcl_DuplicateObj(varnameObj);
    Tcl_IncrRefCount(h->varnameObj);
    h->clientData = clientData;
    h->callback = callback;

    status = Tcl_TraceVar2(interp, Tcl_GetString(varnameObj),
	    NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
	    VarTraceProc, h);
	    VarTraceProc, (ClientData)h);

    if (status != TCL_OK) {
	Tcl_DecrRefCount(h->varnameObj);
	ckfree(h);
	return NULL;
    }

    return h;
}

/*
 * Ttk_UntraceVariable --
 * 	Remove previously-registered trace and free the handle.
 */
void Ttk_UntraceVariable(Ttk_TraceHandle *h)
{
    if (h) {
	void *cd = NULL;
	ClientData cd = NULL;

	/*
	 * Workaround for Tcl Bug 3062331.  The trace design problem is
	 * that when variable unset traces fire, Tcl documents that the
	 * traced variable has already been unset.  It's already gone.
	 * So from within an unset trace, if you try to call
	 * Tcl_UntraceVar() on that variable, it will do nothing, because
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162







-
+














-
+








	/*
	 * Search the traces on the variable to see if the one we are tasked
	 * with removing is present.
	 */
	while ((cd = Tcl_VarTraceInfo(h->interp, Tcl_GetString(h->varnameObj),
		TCL_GLOBAL_ONLY, VarTraceProc, cd)) != NULL) {
	    if (cd == h) {
	    if (cd == (ClientData) h) {
		break;
	    }
	}
	/*
	 * If the trace we wish to delete is not visible, Tcl_UntraceVar
	 * will do nothing, so don't try to call it.  Instead set an
	 * indicator in the Ttk_TraceHandle that we need to cleanup later.
	 */
	if (cd == NULL) {
	    h->interp = NULL;
	    return;
	}
	Tcl_UntraceVar2(h->interp, Tcl_GetString(h->varnameObj),
		NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
		VarTraceProc, h);
		VarTraceProc, (ClientData)h);
	Tcl_DecrRefCount(h->varnameObj);
	ckfree(h);
    }
}

/*
 * Ttk_FireTrace --

Changes to generic/ttk/ttkTrack.c.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23

24
25
26

27
28
29
30
31
32
33
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22

23
24
25

26
27
28
29
30
31
32
33

-
+
















-
+



-
+


-
+







/*
 * Copyright © 2004, Joe English
 * Copyright (c) 2004, Joe English
 *
 * TtkTrackElementState() -- helper routine for widgets
 * like scrollbars in which individual elements may
 * be active or pressed instead of the widget as a whole.
 *
 * Usage:
 * 	TtkTrackElementState(&recordPtr->core);
 *
 * Registers an event handler on the widget that tracks pointer
 * events and updates the state of the element under the
 * mouse cursor.
 *
 * The "active" element is the one under the mouse cursor,
 * and is normally set to the ACTIVE state unless another element
 * is currently being pressed.
 *
 * The active element becomes "pressed" on <Button> events,
 * The active element becomes "pressed" on <ButtonPress> events,
 * and remains "active" and "pressed" until the corresponding
 * <ButtonRelease> event.
 *
 * TODO: Handle "chords" properly (e.g., <B1-Button-2>)
 * TODO: Handle "chords" properly (e.g., <B1-ButtonPress-2>)
 */

#include "tkInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

typedef struct {
    WidgetCore		*corePtr;	/* widget to track */
    Ttk_Layout		tracking;	/* current layout being tracked */
    Ttk_Element 	activeElement;	/* element under the mouse cursor */
112
113
114
115
116
117
118
119

120
121

122
123
124
125
126
127
128
112
113
114
115
116
117
118

119
120

121
122
123
124
125
126
127
128







-
+

-
+







    | PointerMotionMask
    | LeaveWindowMask
    | EnterWindowMask
    | StructureNotifyMask
    ;

static void
ElementStateEventProc(void *clientData, XEvent *ev)
ElementStateEventProc(ClientData clientData, XEvent *ev)
{
    ElementStateTracker *es = (ElementStateTracker *)clientData;
    ElementStateTracker *es = clientData;
    Ttk_Layout layout = es->corePtr->layout;
    Ttk_Element element;

    /* Guard against dangling pointers [#2431428]
     */
    if (es->tracking != layout) {
	es->pressedElement = es->activeElement = 0;
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183







-
+







 * TtkTrackElementState --
 * 	Register an event handler to manage the 'pressed'
 * 	and 'active' states of individual widget elements.
 */

void TtkTrackElementState(WidgetCore *corePtr)
{
    ElementStateTracker *es = (ElementStateTracker *)ckalloc(sizeof(*es));
    ElementStateTracker *es = ckalloc(sizeof(*es));
    es->corePtr = corePtr;
    es->tracking = 0;
    es->activeElement = es->pressedElement = 0;
    Tk_CreateEventHandler(corePtr->tkwin,
	    ElementStateMask,ElementStateEventProc,es);
}

Changes to generic/ttk/ttkTreeview.c.

1
2

3
4
5
6
7
8
9




10
11
12

13
14
15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
1

2
3
4
5
6



7
8
9
10



11

12
13



14
15
16

17
18

19
20
21
22
23
24
25


26
27
28
29
30
31
32

-
+




-
-
-
+
+
+
+
-
-
-
+
-


-
-
-



-
+

-
+






-
-







/*
 * Copyright © 2004, Joe English
 * Copyright (c) 2004, Joe English
 *
 * ttk::treeview widget implementation.
 */

#include "tkInt.h"
#include "ttkThemeInt.h"
#include "ttkWidget.h"
#include <string.h>
#include <stdio.h>
#include <tk.h>
#include "ttkTheme.h"

#ifdef _WIN32
#include "tkWinInt.h"
#include "ttkWidget.h"
#endif

#define DEF_TREE_ROWS		"10"
#define DEF_TITLECOLUMNS	"0"
#define DEF_TITLEITEMS		"0"
#define DEF_STRIPED		"0"
#define DEF_COLWIDTH		"200"
#define DEF_MINWIDTH		"20"

static const Tk_Anchor DEFAULT_IMAGEANCHOR = TK_ANCHOR_W;
static const int DEFAULT_ROWHEIGHT 	= 20;
static const int DEFAULT_INDENT 	= 20;
static const int HALO   		= 4;	/* heading separator */
static const int HALO   		= 4;	/* separator */

#define TTK_STATE_OPEN TTK_STATE_USER1
#define TTK_STATE_LEAF TTK_STATE_USER2

#define STATE_CHANGED	 	(0x100)	/* item state option changed */

#define MAX(a,b) (((a) > (b)) ? (a) : (b))

/*------------------------------------------------------------------------
 * +++ Tree items.
 *
 * INVARIANTS:
 * 	item->children	==> item->children->parent == item
 *	item->next	==> item->next->parent == item->parent
 * 	item->next 	==> item->next->prev == item
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83

84
85
86
87
88
89
90
91
92

93
94
95
96
97
98

99
100
101

102
103
104

105
106
107

108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
46
47
48
49
50
51
52







53
54
55
56
57
58



59
60
61
62
63

64
65

66
67






68

69
70



71

72
73
74

75
76
77

78
79
80

81
82
83




84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99






100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116


117
118
119








120
121
122
123

124
125
126
127
128
129
130
131







-
-
-
-
-
-
-






-
-
-





-
+

-
+

-
-
-
-
-
-

-
+

-
-
-

-
+


-
+


-
+


-
+


-
-
-
-





-
+










-
-
-
-
-
-












-





-
-



-
-
-
-
-
-
-
-




-
+







     */
    Ttk_State 	state;
    Tcl_Obj	*textObj;
    Tcl_Obj	*imageObj;
    Tcl_Obj	*valuesObj;
    Tcl_Obj	*openObj;
    Tcl_Obj	*tagsObj;
    Tcl_Obj     *selObj;
    Tcl_Obj     *imageAnchorObj;
    int 	hidden;
    int		height; 	/* Height is in number of row heights */

    Ttk_TagSet  *cellTagSets;
    Tcl_Size	nTagSets;

    /*
     * Derived resources:
     */
    Ttk_TagSet	tagset;
    Ttk_ImageSpec *imagespec;
    int itemPos; 		/* Counting items */
    int visiblePos; 		/* Counting visible items */
    int rowPos;			/* Counting rows (visible physical space) */
};

#define ITEM_OPTION_TAGS_CHANGED	0x100
#define ITEM_OPTION_IMAGE_CHANGED	0x200

static const Tk_OptionSpec ItemOptionSpecs[] = {
static Tk_OptionSpec ItemOptionSpecs[] = {
    {TK_OPTION_STRING, "-text", "text", "Text",
	"", offsetof(TreeItem,textObj), TCL_INDEX_NONE,
	"", Tk_Offset(TreeItem,textObj), -1,
	0,0,0 },
    {TK_OPTION_INT, "-height", "height", "Height",
	"1", TCL_INDEX_NONE, offsetof(TreeItem,height),
	0,0,0 },
    {TK_OPTION_BOOLEAN, "-hidden", "hidden", "Hidden",
	"0", TCL_INDEX_NONE, offsetof(TreeItem,hidden),
	0,0,0 },
    {TK_OPTION_STRING, "-image", "image", "Image",
	NULL, offsetof(TreeItem,imageObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(TreeItem,imageObj), -1,
	TK_OPTION_NULL_OK,0,ITEM_OPTION_IMAGE_CHANGED },
    {TK_OPTION_ANCHOR, "-imageanchor", "imageAnchor", "ImageAnchor",
	NULL, offsetof(TreeItem,imageAnchorObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_STRING, "-values", "values", "Values",
	NULL, offsetof(TreeItem,valuesObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(TreeItem,valuesObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_BOOLEAN, "-open", "open", "Open",
	"0", offsetof(TreeItem,openObj), TCL_INDEX_NONE,
	"0", Tk_Offset(TreeItem,openObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-tags", "tags", "Tags",
	NULL, offsetof(TreeItem,tagsObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(TreeItem,tagsObj), -1,
	TK_OPTION_NULL_OK,0,ITEM_OPTION_TAGS_CHANGED },

    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0}
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0}
};

/* Forward declarations */
static void RemoveTag(TreeItem *, Ttk_Tag);
static void RemoveTagFromCellsAtItem(TreeItem *, Ttk_Tag);

/* + NewItem --
 * 	Allocate a new, uninitialized, unlinked item
 */
static TreeItem *NewItem(void)
{
    TreeItem *item = (TreeItem *)ckalloc(sizeof(*item));
    TreeItem *item = ckalloc(sizeof(*item));

    item->entryPtr = 0;
    item->parent = item->children = item->next = item->prev = NULL;

    item->state = 0ul;
    item->textObj = NULL;
    item->imageObj = NULL;
    item->valuesObj = NULL;
    item->openObj = NULL;
    item->tagsObj = NULL;
    item->selObj = NULL;
    item->imageAnchorObj = NULL;
    item->hidden = 0;
    item->height = 1;
    item->cellTagSets = NULL;
    item->nTagSets = 0;

    item->tagset = NULL;
    item->imagespec = NULL;

    return item;
}

/* + FreeItem --
 * 	Destroy an item
 */
static void FreeItem(TreeItem *item)
{
    Tcl_Size i;
    if (item->textObj) { Tcl_DecrRefCount(item->textObj); }
    if (item->imageObj) { Tcl_DecrRefCount(item->imageObj); }
    if (item->valuesObj) { Tcl_DecrRefCount(item->valuesObj); }
    if (item->openObj) { Tcl_DecrRefCount(item->openObj); }
    if (item->tagsObj) { Tcl_DecrRefCount(item->tagsObj); }
    if (item->selObj) { Tcl_DecrRefCount(item->selObj); }
    if (item->imageAnchorObj) { Tcl_DecrRefCount(item->imageAnchorObj); }

    if (item->tagset)	{ Ttk_FreeTagSet(item->tagset); }
    if (item->imagespec) { TtkFreeImageSpec(item->imagespec); }
    if (item->cellTagSets) {
	for (i = 0; i < item->nTagSets; ++i) {
	    if (item->cellTagSets[i] != NULL) {
		Ttk_FreeTagSet(item->cellTagSets[i]);
	    }
	}
	ckfree(item->cellTagSets);
    }

    ckfree(item);
}

static void FreeItemCB(void *clientData) { FreeItem((TreeItem *)clientData); }
static void FreeItemCB(void *clientData) { FreeItem(clientData); }

/* + DetachItem --
 * 	Unlink an item from the tree.
 */
static void DetachItem(TreeItem *item)
{
    if (item->parent && item->parent->children == item)
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242

243
244

245
246
247
248
249
250
251
252
253

254
255
256
257



258
259

260
261
262
263
264
265

266
267
268

269
270
271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347

348
349
350

351
352
353
354
355
356
357


358
359

360
361
362

363
364

365
366
367

368
369

370
371
372

373
374
375

376
377
378

379
380
381

382
383

384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403

404
405
406
407

408
409
410
411
412
413
414
178
179
180
181
182
183
184

185

186
187

188
189

190
191

192
193

194
195






196

197
198



199
200
201
202

203
204



205

206
207
208

209
210



211

212
213
214


215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241


242
243
244
245


246
247
248

249
250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277

278
279
280

281
282



283


284
285
286

287
288
289

290
291

292
293
294

295
296

297
298
299

300
301
302

303
304
305

306
307
308

309
310

311
312
313
314
315
316
317
318
319
320
321
322
323

324
325
326
327
328
329
330

331
332
333
334

335
336
337
338
339
340
341
342







-
+
-


-


-


-
+

-
+

-
-
-
-
-
-

-
+

-
-
-
+
+
+

-
+

-
-
-

-
+


-
+

-
-
-

-
+


-
-











-
















-
-




-
-
+
+

-











-
















-
+

-
+


-
+

-
-
-

-
-
+
+

-
+


-
+

-
+


-
+

-
+


-
+


-
+


-
+


-
+

-
+












-
+






-
+



-
+








/*------------------------------------------------------------------------
 * +++ Display items and tag options.
 */

typedef struct {
    Tcl_Obj *textObj;		/* taken from item / data cell */
    Tcl_Obj *imageObj;		/* taken from item or tag*/
    Tcl_Obj *imageObj;		/* taken from item */
    Tcl_Obj *imageAnchorObj;	/* taken from item or tag */
    Tcl_Obj *anchorObj;		/* from column <<NOTE-ANCHOR>> */
    Tcl_Obj *backgroundObj;	/* remainder from tag */
    Tcl_Obj *stripedBgObj;
    Tcl_Obj *foregroundObj;
    Tcl_Obj *fontObj;
    Tcl_Obj *paddingObj;
} DisplayItem;

static const Tk_OptionSpec DisplayOptionSpecs[] = {
static Tk_OptionSpec TagOptionSpecs[] = {
    {TK_OPTION_STRING, "-text", "text", "Text",
	NULL, offsetof(DisplayItem,textObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(DisplayItem,textObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	"center", offsetof(DisplayItem,anchorObj), TCL_INDEX_NONE,
	0, 0, GEOMETRY_CHANGED},	/* <<NOTE-ANCHOR>> */
    /* From here down are the tags options. The index in TagOptionSpecs
     * below should be kept in synch with this position.
     */
    {TK_OPTION_STRING, "-image", "image", "Image",
	NULL, offsetof(DisplayItem,imageObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(DisplayItem,imageObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_ANCHOR, "-imageanchor", "imageAnchor", "ImageAnchor",
	NULL, offsetof(DisplayItem,imageAnchorObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	NULL, Tk_Offset(DisplayItem,anchorObj), -1,
	TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED},	/* <<NOTE-ANCHOR>> */
    {TK_OPTION_COLOR, "-background", "windowColor", "WindowColor",
	NULL, offsetof(DisplayItem,backgroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(DisplayItem,backgroundObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_COLOR, "-stripedbackground", "windowColor", "WindowColor",
	NULL, offsetof(DisplayItem,stripedBgObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
	NULL, offsetof(DisplayItem,foregroundObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(DisplayItem,foregroundObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_FONT, "-font", "font", "Font",
	NULL, offsetof(DisplayItem,fontObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(DisplayItem,fontObj), -1,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-padding", "padding", "Pad",
	NULL, offsetof(DisplayItem,paddingObj), TCL_INDEX_NONE,
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0}
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0}
};

static const Tk_OptionSpec *TagOptionSpecs = &DisplayOptionSpecs[2];

/*------------------------------------------------------------------------
 * +++ Columns.
 *
 * There are separate option tables associated with the column record:
 * ColumnOptionSpecs is for configuring the column,
 * and HeadingOptionSpecs is for drawing headings.
 */
typedef struct {
    int 	width;		/* Column width, in pixels */
    int 	minWidth;	/* Minimum column width, in pixels */
    int 	stretch;	/* Should column stretch while resizing? */
    int         separator;      /* Should this column have a separator? */
    Tcl_Obj	*idObj;		/* Column identifier, from -columns option */

    Tcl_Obj	*anchorObj;	/* -anchor for cell data <<NOTE-ANCHOR>> */

    /* Column heading data:
     */
    Tcl_Obj 	*headingObj;		/* Heading label */
    Tcl_Obj	*headingImageObj;	/* Heading image */
    Tcl_Obj 	*headingAnchorObj;	/* -anchor for heading label */
    Tcl_Obj	*headingCommandObj;	/* Command to execute */
    Tcl_Obj 	*headingStateObj;	/* @@@ testing ... */
    Ttk_State	headingState;		/* ... */

    /* Temporary storage for cell data
     */
    Tcl_Obj 	*data;
    int         selected;
    Ttk_TagSet	tagset;
} TreeColumn;

static void InitColumn(TreeColumn *column)
{
    column->width = atoi(DEF_COLWIDTH);
    column->minWidth = atoi(DEF_MINWIDTH);
    column->width = 200;
    column->minWidth = 20;
    column->stretch = 1;
    column->separator = 0;
    column->idObj = 0;
    column->anchorObj = 0;

    column->headingState = 0;
    column->headingObj = 0;
    column->headingImageObj = 0;
    column->headingAnchorObj = 0;
    column->headingStateObj = 0;
    column->headingCommandObj = 0;

    column->data = 0;
    column->tagset = NULL;
}

static void FreeColumn(TreeColumn *column)
{
    if (column->idObj) { Tcl_DecrRefCount(column->idObj); }
    if (column->anchorObj) { Tcl_DecrRefCount(column->anchorObj); }

    if (column->headingObj) { Tcl_DecrRefCount(column->headingObj); }
    if (column->headingImageObj) { Tcl_DecrRefCount(column->headingImageObj); }
    if (column->headingAnchorObj) { Tcl_DecrRefCount(column->headingAnchorObj); }
    if (column->headingStateObj) { Tcl_DecrRefCount(column->headingStateObj); }
    if (column->headingCommandObj) { Tcl_DecrRefCount(column->headingCommandObj); }

    /* Don't touch column->data, it's scratch storage */
}

static const Tk_OptionSpec ColumnOptionSpecs[] = {
static Tk_OptionSpec ColumnOptionSpecs[] = {
    {TK_OPTION_INT, "-width", "width", "Width",
	DEF_COLWIDTH, TCL_INDEX_NONE, offsetof(TreeColumn,width),
	DEF_COLWIDTH, -1, Tk_Offset(TreeColumn,width),
	0,0,GEOMETRY_CHANGED },
    {TK_OPTION_INT, "-minwidth", "minWidth", "MinWidth",
	DEF_MINWIDTH, TCL_INDEX_NONE, offsetof(TreeColumn,minWidth),
	DEF_MINWIDTH, -1, Tk_Offset(TreeColumn,minWidth),
	0,0,0 },
    {TK_OPTION_BOOLEAN, "-separator", "separator", "Separator",
	"0", TCL_INDEX_NONE, offsetof(TreeColumn,separator),
	0,0,0 },
    {TK_OPTION_BOOLEAN, "-stretch", "stretch", "Stretch",
	"1", TCL_INDEX_NONE, offsetof(TreeColumn,stretch),
	0,0,GEOMETRY_CHANGED },
	"1", -1, Tk_Offset(TreeColumn,stretch),
	0,0,0 },
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	"w", offsetof(TreeColumn,anchorObj), TCL_INDEX_NONE,	/* <<NOTE-ANCHOR>> */
	"w", Tk_Offset(TreeColumn,anchorObj), -1,	/* <<NOTE-ANCHOR>> */
	0,0,0 },
    {TK_OPTION_STRING, "-id", "id", "ID",
	NULL, offsetof(TreeColumn,idObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(TreeColumn,idObj), -1,
	TK_OPTION_NULL_OK,0,READONLY_OPTION },
    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0}
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0}
};

static const Tk_OptionSpec HeadingOptionSpecs[] = {
static Tk_OptionSpec HeadingOptionSpecs[] = {
    {TK_OPTION_STRING, "-text", "text", "Text",
	"", offsetof(TreeColumn,headingObj), TCL_INDEX_NONE,
	"", Tk_Offset(TreeColumn,headingObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-image", "image", "Image",
	"", offsetof(TreeColumn,headingImageObj), TCL_INDEX_NONE,
	"", Tk_Offset(TreeColumn,headingImageObj), -1,
	0,0,0 },
    {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor",
	"center", offsetof(TreeColumn,headingAnchorObj), TCL_INDEX_NONE,
	"center", Tk_Offset(TreeColumn,headingAnchorObj), -1,
	0,0,0 },
    {TK_OPTION_STRING, "-command", "", "",
	"", offsetof(TreeColumn,headingCommandObj), TCL_INDEX_NONE,
	"", Tk_Offset(TreeColumn,headingCommandObj), -1,
	TK_OPTION_NULL_OK,0,0 },
    {TK_OPTION_STRING, "state", "", "",
	"", offsetof(TreeColumn,headingStateObj), TCL_INDEX_NONE,
	"", Tk_Offset(TreeColumn,headingStateObj), -1,
	0,0,STATE_CHANGED },
    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0,0,0}
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0,0,0}
};

/*------------------------------------------------------------------------
 * +++ -show option:
 * TODO: Implement SHOW_BRANCHES.
 */

#define SHOW_TREE 	(0x1) 	/* Show tree column? */
#define SHOW_HEADINGS	(0x2)	/* Show heading row? */

#define DEFAULT_SHOW	"tree headings"

static const char *const showStrings[] = {
static const char *showStrings[] = {
    "tree", "headings", NULL
};

static int GetEnumSetFromObj(
    Tcl_Interp *interp,
    Tcl_Obj *objPtr,
    const char *const table[],
    const char *table[],
    unsigned *resultPtr)
{
    unsigned result = 0;
    Tcl_Size i, objc;
    int i, objc;
    Tcl_Obj **objv;

    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK)
	return TCL_ERROR;

    for (i = 0; i < objc; ++i) {
	int index;
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495



496
497

498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518

519
520
521

522
523
524


525
526
527


528
529
530


531
532
533
534


535
536
537
538
539
540
541


542
543

544
545
546
547
548
549
550
551
552
553

554
555
556

557
558
559

560
561
562
563
564
565
566
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379

380
381
382


383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403



404
405
406

407
408
409
410
411
412
413
414
415


416
417
418
419

420



421
422
423

424
425
426
427
428
429
430
431
432
433
434
435
436
437

438

439

440
441


442
443
444


445
446
447


448
449
450
451


452
453



454
455


456
457
458

459










460
461
462

463
464
465

466
467
468
469
470
471
472
473







-
+









-



-
-
+




















-
-
-



-









-
-
+
+
+

-
+
-
-
-



-
+













-
+
-

-
+

-
-
+
+

-
-
+
+

-
-
+
+


-
-
+
+
-
-
-


-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
+


-
+


-
+







 */
typedef struct {
    /* Resources acquired at initialization-time:
     */
    Tk_OptionTable itemOptionTable;
    Tk_OptionTable columnOptionTable;
    Tk_OptionTable headingOptionTable;
    Tk_OptionTable displayOptionTable;
    Tk_OptionTable tagOptionTable;
    Tk_BindingTable bindingTable;
    Ttk_TagTable tagTable;

    /* Acquired in GetLayout hook:
     */
    Ttk_Layout itemLayout;
    Ttk_Layout cellLayout;
    Ttk_Layout headingLayout;
    Ttk_Layout rowLayout;
    Ttk_Layout separatorLayout;

    int headingHeight;		/* Space for headings */
    int rowHeight;		/* Height of each item */
    int colSeparatorWidth;	/* Width of column separator, if used (screen units) */
    int indent;			/* Horizontal offset for child items (screen units) */
    int indent;			/* #pixels horizontal offset for child items */

    /* Tree data:
     */
    Tcl_HashTable items;	/* Map: item name -> item */
    int serial;			/* Next item # for autogenerated names */
    TreeItem *root;		/* Root item */

    TreeColumn column0;		/* Column options for display column #0 */
    TreeColumn *columns;	/* Array of column options for data columns */

    TreeItem *focus;		/* Current focus item */
    TreeItem *endPtr;		/* See EndPosition() */

    /* Widget options:
     */
    Tcl_Obj *columnsObj;	/* List of symbolic column names */
    Tcl_Obj *displayColumnsObj;	/* List of columns to display */

    Tcl_Obj *heightObj;		/* height (rows) */
    Tcl_Obj *paddingObj;	/* internal padding */
    Tcl_Size nTitleColumns;	/* -titlecolumns */
    Tcl_Size nTitleItems;		/* -titleitems */
    int striped;		/* -striped option */

    Tcl_Obj *showObj;		/* -show list */
    Tcl_Obj *selectModeObj;	/* -selectmode option */
    Tcl_Obj *selectTypeObj;	/* -selecttype option */

    Scrollable xscroll;
    ScrollHandle xscrollHandle;
    Scrollable yscroll;
    ScrollHandle yscrollHandle;

    /* Derived resources:
     */
    Tcl_HashTable columnNames;	/* Map: column name -> column table entry */
    Tcl_Size nColumns; 		/* #columns */
    Tcl_Size nDisplayColumns;	/* #display columns */
    int nColumns; 		/* #columns */
    unsigned showFlags;		/* bitmask of subparts to display */

    TreeColumn **displayColumns; /* List of columns for display (incl tree) */
    int titleWidth;		/* Width of non-scrolled columns */
    int nDisplayColumns;	/* #display columns */
    int titleRows;		/* Height of non-scrolled items, in rows */
    int totalRows;		/* Height of non-hidden items, in rows */
    int rowPosNeedsUpdate;	/* Internal rowPos data needs update */
    Ttk_Box headingArea;	/* Display area for column headings */
    Ttk_Box treeArea;   	/* Display area for tree */
    int slack;			/* Slack space (see Resizing section) */
    unsigned showFlags;		/* bitmask of subparts to display */

} TreePart;

typedef struct {
    WidgetCore core;
    TreePart tree;
} Treeview;

#define USER_MASK 		0x0100
#define COLUMNS_CHANGED 	(USER_MASK)
#define DCOLUMNS_CHANGED	(USER_MASK<<1)
#define SCROLLCMD_CHANGED	(USER_MASK<<2)
#define SHOW_CHANGED 		(USER_MASK<<3)

static const char *const SelectModeStrings[] = { "none", "browse", "extended", NULL };
static const char *SelectModeStrings[] = { "none", "browse", "extended", NULL };
static const char *const SelectTypeStrings[] = { "item", "cell", NULL };

static const Tk_OptionSpec TreeviewOptionSpecs[] = {
static Tk_OptionSpec TreeviewOptionSpecs[] = {
    {TK_OPTION_STRING, "-columns", "columns", "Columns",
	"", offsetof(Treeview,tree.columnsObj), TCL_INDEX_NONE,
	0, 0, COLUMNS_CHANGED | GEOMETRY_CHANGED /*| READONLY_OPTION*/ },
	"", Tk_Offset(Treeview,tree.columnsObj), -1,
	0,0,COLUMNS_CHANGED | GEOMETRY_CHANGED /*| READONLY_OPTION*/ },
    {TK_OPTION_STRING, "-displaycolumns","displayColumns","DisplayColumns",
	"#all", offsetof(Treeview,tree.displayColumnsObj), TCL_INDEX_NONE,
	0, 0, DCOLUMNS_CHANGED | GEOMETRY_CHANGED },
	"#all", Tk_Offset(Treeview,tree.displayColumnsObj), -1,
	0,0,DCOLUMNS_CHANGED | GEOMETRY_CHANGED },
    {TK_OPTION_STRING, "-show", "show", "Show",
	DEFAULT_SHOW, offsetof(Treeview,tree.showObj), TCL_INDEX_NONE,
	0, 0, SHOW_CHANGED | GEOMETRY_CHANGED },
	DEFAULT_SHOW, Tk_Offset(Treeview,tree.showObj), -1,
	0,0,SHOW_CHANGED | GEOMETRY_CHANGED },

    {TK_OPTION_STRING_TABLE, "-selectmode", "selectMode", "SelectMode",
	"extended", offsetof(Treeview,tree.selectModeObj), TCL_INDEX_NONE,
	0, SelectModeStrings, 0 },
	"extended", Tk_Offset(Treeview,tree.selectModeObj), -1,
	0,(ClientData)SelectModeStrings,0 },
    {TK_OPTION_STRING_TABLE, "-selecttype", "selectType", "SelectType",
	"item", offsetof(Treeview,tree.selectTypeObj), TCL_INDEX_NONE,
	0, SelectTypeStrings, 0 },

    {TK_OPTION_PIXELS, "-height", "height", "Height",
	DEF_TREE_ROWS, offsetof(Treeview,tree.heightObj), TCL_INDEX_NONE,
	0, 0, GEOMETRY_CHANGED},
	DEF_TREE_ROWS, Tk_Offset(Treeview,tree.heightObj), -1,
	0,0,GEOMETRY_CHANGED},
    {TK_OPTION_STRING, "-padding", "padding", "Pad",
	NULL, offsetof(Treeview,tree.paddingObj), TCL_INDEX_NONE,
	NULL, Tk_Offset(Treeview,tree.paddingObj), -1,
	TK_OPTION_NULL_OK, 0, GEOMETRY_CHANGED },
    {TK_OPTION_INT, "-titlecolumns", "titlecolumns", "Titlecolumns",
	DEF_TITLECOLUMNS, TCL_INDEX_NONE, offsetof(Treeview,tree.nTitleColumns),
	TK_OPTION_VAR(Tcl_Size), 0, GEOMETRY_CHANGED},
    {TK_OPTION_INT, "-titleitems", "titleitems", "Titleitems",
	DEF_TITLEITEMS, TCL_INDEX_NONE, offsetof(Treeview,tree.nTitleItems),
	TK_OPTION_VAR(Tcl_Size), 0, GEOMETRY_CHANGED},
    {TK_OPTION_BOOLEAN, "-striped", "striped", "Striped",
	DEF_STRIPED, TCL_INDEX_NONE, offsetof(Treeview,tree.striped),
	0, 0, GEOMETRY_CHANGED},
	TK_OPTION_NULL_OK,0,GEOMETRY_CHANGED },

    {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
	NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.xscroll.scrollCmd),
	NULL, -1, Tk_Offset(Treeview, tree.xscroll.scrollCmd),
	TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},
    {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
	NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.yscroll.scrollCmd),
	NULL, -1, Tk_Offset(Treeview, tree.yscroll.scrollCmd),
	TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},

    WIDGET_TAKEFOCUS_TRUE,
    WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
};

/*------------------------------------------------------------------------
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
481
482
483
484
485
486
487














488
489
490
491
492
493
494







-
-
-
-
-
-
-
-
-
-
-
-
-
-







    Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(ht, &search);
    while (entryPtr != NULL) {
	func(Tcl_GetHashValue(entryPtr));
	entryPtr = Tcl_NextHashEntry(&search);
    }
}

static int CellSelectionClear(Treeview *tv)
{
    TreeItem *item;
    int anyChange = 0;
    for (item=tv->tree.root; item; item = NextPreorder(item)) {
	if (item->selObj != NULL) {
	    Tcl_DecrRefCount(item->selObj);
	    item->selObj = NULL;
	    anyChange = 1;
	}
    }
    return anyChange;
}

/* + unshareObj(objPtr) --
 * 	Ensure that a Tcl_Obj * has refcount 1 -- either return objPtr
 * 	itself,	or a duplicated copy.
 */
static Tcl_Obj *unshareObj(Tcl_Obj *objPtr)
{
    if (Tcl_IsShared(objPtr)) {
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664

665
666
667

668
669

670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

693
694

695
696
697
698
699
700
701
507
508
509
510
511
512
513



























514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529

530
531
532

533
534

535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557

558
559

560
561
562
563
564
565
566
567







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+






-
+


-
+

-
+


-
+



















-
+

-
+







    Ttk_Layout layout, void *recordPtr, Ttk_State state, Ttk_Box b, Drawable d)
{
    Ttk_RebindSublayout(layout, recordPtr);
    Ttk_PlaceLayout(layout, state, b);
    Ttk_DrawLayout(layout, state, d);
}

/* DisplayLayoutTree --
 *	Like DisplayLayout, but for the tree column.
 */
static void DisplayLayoutTree(
    Tk_Anchor imageAnchor, Tk_Anchor textAnchor,
    Ttk_Layout layout, void *recordPtr, Ttk_State state, Ttk_Box b, Drawable d)
{
    Ttk_Element elem;
    Ttk_RebindSublayout(layout, recordPtr);

    elem = Ttk_FindElement(layout, "image");
    if (elem != NULL) {
	Ttk_AnchorElement(elem, imageAnchor);
    }
    elem = Ttk_FindElement(layout, "text");
    if (elem != NULL) {
	Ttk_AnchorElement(elem, textAnchor);
    }
    elem = Ttk_FindElement(layout, "focus");
    if (elem != NULL) {
	Ttk_AnchorElement(elem, textAnchor);
    }

    Ttk_PlaceLayout(layout, state, b);
    Ttk_DrawLayout(layout, state, d);
}

/* + GetColumn --
 * 	Look up column by name or number.
 * 	Returns: pointer to column table entry, NULL if not found.
 * 	Leaves an error message in interp->result on error.
 */
static TreeColumn *GetColumn(
    Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
{
    Tcl_HashEntry *entryPtr;
    Tcl_Size columnIndex;
    int columnIndex;

    /* Check for named column:
     */
    entryPtr = Tcl_FindHashEntry(
	    &tv->tree.columnNames, Tcl_GetString(columnIDObj));
    if (entryPtr) {
	return (TreeColumn *)Tcl_GetHashValue(entryPtr);
	return Tcl_GetHashValue(entryPtr);
    }

    /* Check for index:
    /* Check for number:
     */
    if (TkGetIntForIndex(columnIDObj, tv->tree.nColumns - 1, 1, &columnIndex) == TCL_OK) {
    if (Tcl_GetIntFromObj(NULL, columnIDObj, &columnIndex) == TCL_OK) {
	if (columnIndex < 0 || columnIndex >= tv->tree.nColumns) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "Column index \"%s\" out of bounds",
		    "Column index %s out of bounds",
		    Tcl_GetString(columnIDObj)));
	    Tcl_SetErrorCode(interp, "TTK", "TREE", "COLBOUND", NULL);
	    return NULL;
	}

	return tv->tree.columns + columnIndex;
    }
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	"Invalid column index %s", Tcl_GetString(columnIDObj)));
    Tcl_SetErrorCode(interp, "TTK", "TREE", "COLUMN", NULL);
    return NULL;
}

/* + FindColumn --
 * 	Look up column by name, number, or display index.
 */
static TreeColumn *FindColumn(
    Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
{
    Tcl_WideInt colno;
    int colno;

    if (sscanf(Tcl_GetString(columnIDObj), "#%" TCL_LL_MODIFIER "d", &colno) == 1)
    if (sscanf(Tcl_GetString(columnIDObj), "#%d", &colno) == 1)
    {	/* Display column specification, #n */
	if (colno >= 0 && colno < tv->tree.nDisplayColumns) {
	    return tv->tree.displayColumns[colno];
	}
	/* else */
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "Column %s out of range", Tcl_GetString(columnIDObj)));
718
719
720
721
722
723
724
725

726
727
728
729
730
731
732
733
734
735
736
737
738
739
740

741
742
743
744
745
746

747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784

785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833

834
835
836

837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863
864
865
866

867
868
869
870
871

872
873
874
875
876
877
878
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605

606
607
608
609
610
611

612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686

687
688
689
690
691
692
693
694
695
696
697
698

699
700
701

702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
729
730
731

732
733
734
735
736

737
738
739
740
741
742
743
744







-
+














-
+





-
+
















-
+




















-
+



















-
+
















-
+











-
+


-
+



















-
+









-
+




-
+








    if (!entryPtr) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Item %s not found", itemName));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "ITEM", NULL);
	return 0;
    }
    return (TreeItem *)Tcl_GetHashValue(entryPtr);
    return Tcl_GetHashValue(entryPtr);
}

/* + GetItemListFromObj --
 * 	Parse a Tcl_Obj * as a list of items.
 * 	Returns a NULL-terminated array of items; result must
 * 	be ckfree()d. On error, returns NULL and leaves an error
 * 	message in interp.
 */

static TreeItem **GetItemListFromObj(
    Tcl_Interp *interp, Treeview *tv, Tcl_Obj *objPtr)
{
    TreeItem **items;
    Tcl_Obj **elements;
    Tcl_Size i, nElements;
    int i, nElements;

    if (Tcl_ListObjGetElements(interp,objPtr,&nElements,&elements) != TCL_OK) {
	return NULL;
    }

    items = (TreeItem **)ckalloc((nElements + 1)*sizeof(TreeItem*));
    items = ckalloc((nElements + 1)*sizeof(TreeItem*));
    for (i = 0; i < nElements; ++i) {
	items[i] = FindItem(interp, tv, elements[i]);
	if (!items[i]) {
	    ckfree(items);
	    return NULL;
	}
    }
    items[i] = NULL;
    return items;
}

/* + ItemName --
 * 	Returns the item's ID.
 */
static const char *ItemName(Treeview *tv, TreeItem *item)
{
    return (const char *)Tcl_GetHashKey(&tv->tree.items, item->entryPtr);
    return Tcl_GetHashKey(&tv->tree.items, item->entryPtr);
}

/* + ItemID --
 * 	Returns a fresh Tcl_Obj * (refcount 0) holding the
 * 	item identifier of the specified item.
 */
static Tcl_Obj *ItemID(Treeview *tv, TreeItem *item)
{
    return Tcl_NewStringObj(ItemName(tv, item), -1);
}

/*------------------------------------------------------------------------
 * +++ Column configuration.
 */

/* + TreeviewFreeColumns --
 * 	Free column data.
 */
static void TreeviewFreeColumns(Treeview *tv)
{
    Tcl_Size i;
    int i;

    Tcl_DeleteHashTable(&tv->tree.columnNames);
    Tcl_InitHashTable(&tv->tree.columnNames, TCL_STRING_KEYS);

    if (tv->tree.columns) {
	for (i = 0; i < tv->tree.nColumns; ++i)
	    FreeColumn(tv->tree.columns + i);
	ckfree(tv->tree.columns);
	tv->tree.columns = 0;
    }
}

/* + TreeviewInitColumns --
 *	Initialize column data when -columns changes.
 *	Returns: TCL_OK or TCL_ERROR;
 */
static int TreeviewInitColumns(Tcl_Interp *interp, Treeview *tv)
{
    Tcl_Obj **columns;
    Tcl_Size i, ncols;
    int i, ncols;

    if (Tcl_ListObjGetElements(
	    interp, tv->tree.columnsObj, &ncols, &columns) != TCL_OK)
    {
	return TCL_ERROR;
    }

    /*
     * Free old values:
     */
    TreeviewFreeColumns(tv);

    /*
     * Initialize columns array and columnNames hash table:
     */
    tv->tree.nColumns = ncols;
    tv->tree.columns = (TreeColumn *)ckalloc(tv->tree.nColumns * sizeof(TreeColumn));
    tv->tree.columns = ckalloc(tv->tree.nColumns * sizeof(TreeColumn));

    for (i = 0; i < ncols; ++i) {
	int isNew;
	Tcl_Obj *columnName = Tcl_DuplicateObj(columns[i]);

	Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
	    &tv->tree.columnNames, Tcl_GetString(columnName), &isNew);
	Tcl_SetHashValue(entryPtr, tv->tree.columns + i);

	InitColumn(tv->tree.columns + i);
	Tk_InitOptions(
	    interp, tv->tree.columns + i,
	    interp, (ClientData)(tv->tree.columns + i),
	    tv->tree.columnOptionTable, tv->core.tkwin);
	Tk_InitOptions(
	    interp, tv->tree.columns + i,
	    interp, (ClientData)(tv->tree.columns + i),
	    tv->tree.headingOptionTable, tv->core.tkwin);
	Tcl_IncrRefCount(columnName);
	tv->tree.columns[i].idObj = columnName;
    }

    return TCL_OK;
}

/* + TreeviewInitDisplayColumns --
 * 	Initializes the 'displayColumns' array.
 *
 * 	Note that displayColumns[0] is always the tree column,
 * 	even when SHOW_TREE is not set.
 *
 * @@@ TODO: disallow duplicated columns
 */
static int TreeviewInitDisplayColumns(Tcl_Interp *interp, Treeview *tv)
{
    Tcl_Obj **dcolumns;
    Tcl_Size index, ndcols;
    int index, ndcols;
    TreeColumn **displayColumns = 0;

    if (Tcl_ListObjGetElements(interp,
	    tv->tree.displayColumnsObj, &ndcols, &dcolumns) != TCL_OK) {
	return TCL_ERROR;
    }

    if (!strcmp(Tcl_GetString(tv->tree.displayColumnsObj), "#all")) {
	ndcols = tv->tree.nColumns;
	displayColumns = (TreeColumn **)ckalloc((ndcols+1) * sizeof(TreeColumn*));
	displayColumns = ckalloc((ndcols+1) * sizeof(TreeColumn*));
	for (index = 0; index < ndcols; ++index) {
	    displayColumns[index+1] = tv->tree.columns + index;
	}
    } else {
	displayColumns = (TreeColumn **)ckalloc((ndcols+1) * sizeof(TreeColumn*));
	displayColumns = ckalloc((ndcols+1) * sizeof(TreeColumn*));
	for (index = 0; index < ndcols; ++index) {
	    displayColumns[index+1] = GetColumn(interp, tv, dcolumns[index]);
	    if (!displayColumns[index+1]) {
		ckfree(displayColumns);
		return TCL_ERROR;
	    }
	}
895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936



937
938
939
940
941
942
943
761
762
763
764
765
766
767

768
769
770

771



772
773



774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793


794
795
796
797
798
799
800
801
802
803







-
+


-

-
-
-


-
-
-




















-
-
+
+
+







#define FirstColumn(tv)  ((tv->tree.showFlags&SHOW_TREE) ? 0 : 1)

/* + TreeWidth --
 * 	Compute the requested tree width from the sum of visible column widths.
 */
static int TreeWidth(Treeview *tv)
{
    Tcl_Size i = FirstColumn(tv);
    int i = FirstColumn(tv);
    int width = 0;

    tv->tree.titleWidth = 0;
    while (i < tv->tree.nDisplayColumns) {
	if (i == tv->tree.nTitleColumns) {
	    tv->tree.titleWidth = width;
	}
	width += tv->tree.displayColumns[i++]->width;
    }
    if (tv->tree.nTitleColumns >= tv->tree.nDisplayColumns) {
	tv->tree.titleWidth = width;
    }
    return width;
}

/* + RecomputeSlack --
 */
static void RecomputeSlack(Treeview *tv)
{
    tv->tree.slack = tv->tree.treeArea.width - TreeWidth(tv);
}

/* + PickupSlack/DepositSlack --
 * 	When resizing columns, distribute extra space to 'slack' first,
 * 	and only adjust column widths if 'slack' goes to zero.
 * 	That is, don't bother changing column widths if the tree
 * 	is already scrolled or short.
 */
static int PickupSlack(Treeview *tv, int extra)
{
    int newSlack = tv->tree.slack + extra;

    if ((newSlack < 0 && 0 <= tv->tree.slack)
	    || (newSlack > 0 && 0 >= tv->tree.slack)) {
    if (   (newSlack < 0 && 0 <= tv->tree.slack)
	|| (newSlack > 0 && 0 >= tv->tree.slack))
    {
	tv->tree.slack = 0;
	return newSlack;
    } else {
	tv->tree.slack = newSlack;
	return 0;
    }
}
963
964
965
966
967
968
969
970

971
972

973
974
975
976
977
978
979
980
981
982
983
984
985
986
987

988
989
990
991
992
993
994
823
824
825
826
827
828
829

830
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846

847
848
849
850
851
852
853
854







-
+

-
+














-
+







    return n;
}

/* + ShoveLeft --
 * 	Adjust width of (stretchable) columns to the left by N pixels.
 * 	Returns: leftover slack.
 */
static int ShoveLeft(Treeview *tv, Tcl_Size i, int n)
static int ShoveLeft(Treeview *tv, int i, int n)
{
    Tcl_Size first = FirstColumn(tv);
    int first = FirstColumn(tv);
    while (n != 0 && i >= first) {
	TreeColumn *c = tv->tree.displayColumns[i];
	if (c->stretch) {
	    n -= Stretch(c, n);
	}
	--i;
    }
    return n;
}

/* + ShoveRight --
 * 	Adjust width of (stretchable) columns to the right by N pixels.
 * 	Returns: leftover slack.
 */
static int ShoveRight(Treeview *tv, Tcl_Size i, int n)
static int ShoveRight(Treeview *tv, int i, int n)
{
    while (n != 0 && i < tv->tree.nDisplayColumns) {
	TreeColumn *c = tv->tree.displayColumns[i];
	if (c->stretch) {
	    n -= Stretch(c, n);
	}
	++i;
1003
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
863
864
865
866
867
868
869


870
871
872
873
874
875
876
877







-
-
+







 * 	The "((++w % m) < r)" term is there so that the remainder r = n % m
 * 	is distributed round-robin.
 */
static int DistributeWidth(Treeview *tv, int n)
{
    int w = TreeWidth(tv);
    int m = 0;
    Tcl_Size  i;
    int d, r;
    int i, d, r;

    for (i = FirstColumn(tv); i < tv->tree.nDisplayColumns; ++i) {
	if (tv->tree.displayColumns[i]->stretch) {
	    ++m;
	}
    }
    if (m == 0) {
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267
1268
1269


1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407




1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919












































































































920
921
922
923
924

925

926
927
928
929
930
931
932
933
934

935
936
937



938
939
940
941
942
943
944
945
946
947
948
949
950
951

952
953
954

955
956
957
958
959
960
961
962
963
964
965
966
967
968
969

















970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995


996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008

1009

1010

1011
1012
1013
1014







1015
1016
1017
1018
1019


1020

1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064

1065

1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

















1099
1100
1101
1102



1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148









1149
1150
1151
1152
1153
1154
1155







-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-

-
+








-
+


-
-
-














-



-















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

















-
+








-
-
+
+











-

-
+
-




-
-
-
-
-
-
-





-
-

-
+


-
+










-
+


















-
+










-

-



-
+

















-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
+
+
+
+







-













-
+






-
+









-
+




-
-
-
-
-
-
-
-
-







	    DistributeWidth(tv, PickupSlack(tv, delta))));
}

/* + DragColumn --
 * 	Move the separator to the right of specified column,
 * 	adjusting other column widths as necessary.
 */
static void DragColumn(Treeview *tv, Tcl_Size i, int delta)
static void DragColumn(Treeview *tv, int i, int delta)
{
    TreeColumn *c = tv->tree.displayColumns[i];
    int dl = delta - ShoveLeft(tv, i-1, delta - Stretch(c, delta));
    int dr = ShoveRight(tv, i+1, PickupSlack(tv, -dl));
    DepositSlack(tv, dr);
}

/*------------------------------------------------------------------------
 * +++ Cells.
 */

typedef struct {
    TreeItem *item;
    TreeColumn *column;
    Tcl_Obj *colObj;
} TreeCell;

/* + GetCellFromObj
 * 	Get Row and Column from a cell ID.
 */
static int GetCellFromObj(
    Tcl_Interp *interp, Treeview *tv, Tcl_Obj *obj,
    int displayColumnOnly, int *displayColumn,
    TreeCell *cell)
{
    Tcl_Size nElements;
    Tcl_Obj **elements;

    if (Tcl_ListObjGetElements(interp, obj, &nElements, &elements) != TCL_OK) {
	return TCL_ERROR;
    }
    if (nElements != 2) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Cell id must be a list of two elements", -1));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "CELL", NULL);
	return TCL_ERROR;
    }
    /* Valid item/column in each pair? */
    cell->item = FindItem(interp, tv, elements[0]);
    if (!cell->item) {
	return TCL_ERROR;
    }
    cell->column = FindColumn(interp, tv, elements[1]);
    if (!cell->column) {
	return TCL_ERROR;
    }
    /* colObj is short lived and do not keep a reference counted */
    cell->colObj = elements[1];
    if (displayColumnOnly) {
	Tcl_Size i = FirstColumn(tv);
	while (i < tv->tree.nDisplayColumns) {
	    if (tv->tree.displayColumns[i] == cell->column) {
		break;
	    }
	    ++i;
	}
	if (i == tv->tree.nDisplayColumns) { /* specified column unviewable */
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Cell id must be in a visible column", -1));
	    Tcl_SetErrorCode(interp, "TTK", "TREE", "CELL", NULL);
	    return TCL_ERROR;
	}
	if (displayColumn != NULL) {
	    *displayColumn = i;
	}
    }
    return TCL_OK;
}

/* + GetCellListFromObj --
 * 	Parse a Tcl_Obj * as a list of cells.
 * 	Returns an array of cells; result must be ckfree()d.
 *      On error, returns NULL and leaves an error
 * 	message in interp.
 */

static TreeCell *GetCellListFromObj(
	Tcl_Interp *interp, Treeview *tv, Tcl_Obj *objPtr, Tcl_Size *nCells)
{
    TreeCell *cells;
    TreeCell cell;
    Tcl_Obj **elements;
    Tcl_Obj *oneCell;
    Tcl_Size i, n;

    if (Tcl_ListObjGetElements(interp, objPtr, &n, &elements) != TCL_OK) {
	return NULL;
    }

    /* A two element list might be a single cell */
    if (n == 2) {
	if (GetCellFromObj(interp, tv, objPtr, 0, NULL, &cell)
		== TCL_OK) {
	    n = 1;
	    oneCell = objPtr;
	    elements = &oneCell;
	} else {
	    Tcl_ResetResult(interp);
	}
    }

    cells = (TreeCell *) ckalloc(n * sizeof(TreeCell));
    for (i = 0; i < n; ++i) {
	if (GetCellFromObj(interp, tv, elements[i], 0, NULL, &cells[i]) != TCL_OK) {
	    ckfree(cells);
	    return NULL;
	}
    }

    if (nCells) {
	*nCells = n;
    }
    return cells;
}

/*------------------------------------------------------------------------
 * +++ Event handlers.
 */

static TreeItem *IdentifyItem(Treeview *tv, int y); /*forward*/
static Tcl_Size IdentifyDisplayColumn(Treeview *tv, int x, int *x1); /*forward*/

static const unsigned long TreeviewBindEventMask =
static const unsigned int TreeviewBindEventMask =
      KeyPressMask|KeyReleaseMask
    | ButtonPressMask|ButtonReleaseMask
    | PointerMotionMask|ButtonMotionMask
    | VirtualEventMask
    ;

static void TreeviewBindEventProc(void *clientData, XEvent *event)
{
    Treeview *tv = (Treeview *)clientData;
    Treeview *tv = clientData;
    TreeItem *item = NULL;
    Ttk_TagSet tagset;
    int unused;
    Tcl_Size colno = TCL_INDEX_NONE;
    TreeColumn *column = NULL;

    /*
     * Figure out where to deliver the event.
     */
    switch (event->type)
    {
	case KeyPress:
	case KeyRelease:
	case VirtualEvent:
	    item = tv->tree.focus;
	    break;
	case ButtonPress:
	case ButtonRelease:
	    item = IdentifyItem(tv, event->xbutton.y);
	    colno = IdentifyDisplayColumn(tv, event->xbutton.x, &unused);
	    break;
	case MotionNotify:
	    item = IdentifyItem(tv, event->xmotion.y);
	    colno = IdentifyDisplayColumn(tv, event->xmotion.x, &unused);
	    break;
	default:
	    break;
    }

    if (!item) {
	return;
    }

    /* ASSERT: Ttk_GetTagSetFromObj succeeds.
     * NB: must use a local copy of the tagset,
     * in case a binding script stomps on -tags.
     */
    tagset = Ttk_GetTagSetFromObj(NULL, tv->tree.tagTable, item->tagsObj);

    /*
     * Pick up any cell tags.
     */
    if (colno >= 0) {
	column = tv->tree.displayColumns[colno];
	if (column == &tv->tree.column0) {
	    colno = 0;
	} else {
	    colno = column - tv->tree.columns + 1;
	}
	if (colno < item->nTagSets) {
	    if (item->cellTagSets[colno] != NULL) {
		Ttk_TagSetAddSet(tagset, item->cellTagSets[colno]);
	    }
	}
    }

    /*
     * Fire binding:
     */
    Tcl_Preserve(clientData);
    Tk_BindEvent(tv->tree.bindingTable, event, tv->core.tkwin,
	    tagset->nTags, (void **)tagset->tags);
    Tcl_Release(clientData);

    Ttk_FreeTagSet(tagset);
}

/*------------------------------------------------------------------------
 * +++ Initialization and cleanup.
 */

static void TreeviewInitialize(Tcl_Interp *interp, void *recordPtr)
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    int unused;

    tv->tree.itemOptionTable =
	Tk_CreateOptionTable(interp, ItemOptionSpecs);
    tv->tree.columnOptionTable =
	Tk_CreateOptionTable(interp, ColumnOptionSpecs);
    tv->tree.headingOptionTable =
	Tk_CreateOptionTable(interp, HeadingOptionSpecs);
    tv->tree.displayOptionTable =
	Tk_CreateOptionTable(interp, DisplayOptionSpecs);
    tv->tree.tagOptionTable =
	Tk_CreateOptionTable(interp, TagOptionSpecs);

    tv->tree.tagTable = Ttk_CreateTagTable(
	interp, tv->core.tkwin, TagOptionSpecs, sizeof(DisplayItem));
    tv->tree.bindingTable = Tk_CreateBindingTable(interp);
    Tk_CreateEventHandler(tv->core.tkwin,
	TreeviewBindEventMask, TreeviewBindEventProc, tv);

    tv->tree.itemLayout
	= tv->tree.cellLayout
	= tv->tree.headingLayout
	= tv->tree.rowLayout
	= tv->tree.separatorLayout
	= 0;
    tv->tree.headingHeight = tv->tree.rowHeight = 0;
    tv->tree.headingHeight = tv->tree.rowHeight = DEFAULT_ROWHEIGHT;
    tv->tree.colSeparatorWidth = 1;
    tv->tree.indent = DEFAULT_INDENT;

    Tcl_InitHashTable(&tv->tree.columnNames, TCL_STRING_KEYS);
    tv->tree.nColumns = tv->tree.nDisplayColumns = 0;
    tv->tree.nTitleColumns = 0;
    tv->tree.nTitleItems = 0;
    tv->tree.titleWidth = 0;
    tv->tree.titleRows = 0;
    tv->tree.totalRows = 0;
    tv->tree.rowPosNeedsUpdate = 1;
    tv->tree.striped = 0;
    tv->tree.columns = NULL;
    tv->tree.displayColumns = NULL;
    tv->tree.showFlags = ~0;

    InitColumn(&tv->tree.column0);
    tv->tree.column0.idObj = Tcl_NewStringObj("#0", 2);
    Tcl_IncrRefCount(tv->tree.column0.idObj);
    Tk_InitOptions(
	interp, &tv->tree.column0,
	interp, (ClientData)(&tv->tree.column0),
	tv->tree.columnOptionTable, tv->core.tkwin);
    Tk_InitOptions(
	interp, &tv->tree.column0,
	interp, (ClientData)(&tv->tree.column0),
	tv->tree.headingOptionTable, tv->core.tkwin);

    Tcl_InitHashTable(&tv->tree.items, TCL_STRING_KEYS);
    tv->tree.serial = 0;

    tv->tree.focus = tv->tree.endPtr = 0;

    /* Create root item "":
     */
    tv->tree.root = NewItem();
    Tk_InitOptions(interp, tv->tree.root,
    Tk_InitOptions(interp, (ClientData)tv->tree.root,
	tv->tree.itemOptionTable, tv->core.tkwin);
    tv->tree.root->tagset = Ttk_GetTagSetFromObj(NULL, tv->tree.tagTable, NULL);
    tv->tree.root->entryPtr = Tcl_CreateHashEntry(&tv->tree.items, "", &unused);
    Tcl_SetHashValue(tv->tree.root->entryPtr, tv->tree.root);

    /* Scroll handles:
     */
    tv->tree.xscrollHandle = TtkCreateScrollHandle(&tv->core,&tv->tree.xscroll);
    tv->tree.yscrollHandle = TtkCreateScrollHandle(&tv->core,&tv->tree.yscroll);

    /* Size parameters:
     */
    tv->tree.treeArea = tv->tree.headingArea = Ttk_MakeBox(0,0,0,0);
    tv->tree.slack = 0;
}

static void TreeviewCleanup(void *recordPtr)
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;

    Tk_DeleteEventHandler(tv->core.tkwin,
	    TreeviewBindEventMask,  TreeviewBindEventProc, tv);
    Tk_DeleteBindingTable(tv->tree.bindingTable);
    Ttk_DeleteTagTable(tv->tree.tagTable);

    if (tv->tree.itemLayout) Ttk_FreeLayout(tv->tree.itemLayout);
    if (tv->tree.cellLayout) Ttk_FreeLayout(tv->tree.cellLayout);
    if (tv->tree.headingLayout) Ttk_FreeLayout(tv->tree.headingLayout);
    if (tv->tree.rowLayout) Ttk_FreeLayout(tv->tree.rowLayout);
    if (tv->tree.separatorLayout) Ttk_FreeLayout(tv->tree.separatorLayout);

    FreeColumn(&tv->tree.column0);
    TreeviewFreeColumns(tv);

    if (tv->tree.displayColumns)
	ckfree(tv->tree.displayColumns);
	Tcl_Free((ClientData)tv->tree.displayColumns);

    foreachHashEntry(&tv->tree.items, FreeItemCB);
    Tcl_DeleteHashTable(&tv->tree.items);

    TtkFreeScrollHandle(tv->tree.xscrollHandle);
    TtkFreeScrollHandle(tv->tree.yscrollHandle);
}

/* + TreeviewConfigure --
 * 	Configuration widget hook.
 *
 * 	BUG: If user sets -columns and -displaycolumns, but -displaycolumns
 * 	has an error, the widget is left in an inconsistent state.
 */
static int
TreeviewConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    unsigned showFlags = tv->tree.showFlags;

    if (mask & COLUMNS_CHANGED) {
	if (TreeviewInitColumns(interp, tv) != TCL_OK)
	    return TCL_ERROR;
	mask |= DCOLUMNS_CHANGED;
    }
    if (mask & DCOLUMNS_CHANGED) {
	if (TreeviewInitDisplayColumns(interp, tv) != TCL_OK)
	    return TCL_ERROR;
    }
    if (mask & COLUMNS_CHANGED) {
	CellSelectionClear(tv);
    }
    if (tv->tree.nTitleColumns < 0) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                "\"#%" TCL_SIZE_MODIFIER "d\" is out of range",
                tv->tree.nTitleColumns));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "TITLECOLUMNS", NULL);
	return TCL_ERROR;
    }
    if (tv->tree.nTitleItems < 0) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                "\"%" TCL_SIZE_MODIFIER "d\" is out of range",
                tv->tree.nTitleItems));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "TITLEITEMS", NULL);
	return TCL_ERROR;
    }
    if (mask & SCROLLCMD_CHANGED) {
	TtkScrollbarUpdateRequired(tv->tree.xscrollHandle);
	TtkScrollbarUpdateRequired(tv->tree.yscrollHandle);
    }
    if ((mask & SHOW_CHANGED)
	    && GetEnumSetFromObj(
		    interp,tv->tree.showObj,showStrings,&showFlags) != TCL_OK) {
    if (  (mask & SHOW_CHANGED)
	&& GetEnumSetFromObj(
		    interp,tv->tree.showObj,showStrings,&showFlags) != TCL_OK)
    {
	return TCL_ERROR;
    }

    if (TtkCoreConfigure(interp, recordPtr, mask) != TCL_OK) {
	return TCL_ERROR;
    }

    tv->tree.rowPosNeedsUpdate = 1;
    tv->tree.showFlags = showFlags;

    if (mask & (SHOW_CHANGED | DCOLUMNS_CHANGED)) {
	RecomputeSlack(tv);
    }
    return TCL_OK;
}

/* + ConfigureItem --
 * 	Set item options.
 */
static int ConfigureItem(
    Tcl_Interp *interp, Treeview *tv, TreeItem *item,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    Tk_SavedOptions savedOptions;
    int mask;
    Ttk_ImageSpec *newImageSpec = NULL;
    Ttk_TagSet newTagSet = NULL;

    if (Tk_SetOptions(interp, item, tv->tree.itemOptionTable,
    if (Tk_SetOptions(interp, (ClientData)item, tv->tree.itemOptionTable,
		objc, objv, tv->core.tkwin, &savedOptions, &mask)
		!= TCL_OK)
    {
	return TCL_ERROR;
    }

    /* Make sure that -values is a valid list:
     */
    if (item->valuesObj) {
	Tcl_Size unused;
	int unused;
	if (Tcl_ListObjLength(interp, item->valuesObj, &unused) != TCL_OK)
	    goto error;
    }

    /* Check -height
     */
    if (item->height < 1) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Invalid item height %d", item->height));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "HEIGHT", NULL);
	goto error;
    }

    /* Check -image.
     */
    if ((mask & ITEM_OPTION_IMAGE_CHANGED) && item->imageObj) {
	newImageSpec = TtkGetImageSpec(interp, tv->core.tkwin, item->imageObj);
	if (!newImageSpec) {
	    goto error;
	}
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521

1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548


1549
1550
1551
1552




1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567

1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234


1235
1236




1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254

1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267







-















-
+




-
+




















-
-
+
+
-
-
-
-
+
+
+
+














-
+




-
+







	if (item->tagset) { Ttk_FreeTagSet(item->tagset); }
	item->tagset = newTagSet;
    }
    if (mask & ITEM_OPTION_IMAGE_CHANGED) {
	if (item->imagespec) { TtkFreeImageSpec(item->imagespec); }
	item->imagespec = newImageSpec;
    }
    tv->tree.rowPosNeedsUpdate = 1;
    TtkRedisplayWidget(&tv->core);
    return TCL_OK;

error:
    Tk_RestoreSavedOptions(&savedOptions);
    if (newTagSet) { Ttk_FreeTagSet(newTagSet); }
    if (newImageSpec) { TtkFreeImageSpec(newImageSpec); }
    return TCL_ERROR;
}

/* + ConfigureColumn --
 * 	Set column options.
 */
static int ConfigureColumn(
    Tcl_Interp *interp, Treeview *tv, TreeColumn *column,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    Tk_SavedOptions savedOptions;
    int mask;

    if (Tk_SetOptions(interp, column,
    if (Tk_SetOptions(interp, (ClientData)column,
	    tv->tree.columnOptionTable, objc, objv, tv->core.tkwin,
	    &savedOptions,&mask) != TCL_OK)
    {
	return TCL_ERROR;
    }

    if (mask & READONLY_OPTION) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Attempt to change read-only option", -1));
	Tcl_SetErrorCode(interp, "TTK", "TREE", "READONLY", NULL);
	goto error;
    }

    /* Propagate column width changes to overall widget request width,
     * but only if the widget is currently unmapped, in order to prevent
     * geometry jumping during interactive column resize.
     */
    if (mask & GEOMETRY_CHANGED) {
	if (!Tk_IsMapped(tv->core.tkwin)) {
	    TtkResizeWidget(&tv->core);
        } else {
	    RecomputeSlack(tv);
	}
	RecomputeSlack(tv);
	    ResizeColumns(tv, TreeWidth(tv));
        }
    }
    TtkRedisplayWidget(&tv->core);
    }
    TtkRedisplayWidget(&tv->core);

    /* ASSERT: SLACKINVARIANT */

    Tk_FreeSavedOptions(&savedOptions);
    return TCL_OK;

error:
    Tk_RestoreSavedOptions(&savedOptions);
    return TCL_ERROR;
}

/* + ConfigureHeading --
 * 	Set heading options.
 */
static int ConfigureHeading(
    Tcl_Interp *interp, Treeview *tv, TreeColumn *column,
    Tcl_Size objc, Tcl_Obj *const objv[])
    int objc, Tcl_Obj *const objv[])
{
    Tk_SavedOptions savedOptions;
    int mask;

    if (Tk_SetOptions(interp, column,
    if (Tk_SetOptions(interp, (ClientData)column,
	    tv->tree.headingOptionTable, objc, objv, tv->core.tkwin,
	    &savedOptions,&mask) != TCL_OK)
    {
	return TCL_ERROR;
    }

    /* @@@ testing ... */
1599
1600
1601
1602
1603
1604
1605
1606
1607


1608
1609
1610

1611
1612
1613
1614
1615

1616
1617
1618
1619
1620







1621
1622

1623
1624
1625
1626
1627
1628
1629

1630










1631
1632
1633
1634
1635
1636
1637











1638
1639
1640
1641
1642
1643




1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1287
1288
1289
1290
1291
1292
1293


1294
1295
1296


1297

1298



1299
1300




1301
1302
1303
1304
1305
1306
1307


1308







1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320







1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331






1332
1333
1334
1335











1336
1337
1338
1339
1340
1341
1342

1343

1344












1345




1346
1347
1348
1349
1350
1351

1352
1353


1354
1355




1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366




1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415


1416
1417
1418
1419

1420
1421


1422










1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456

1457




1458
1459
1460
1461


1462
1463
1464
1465
1466
1467
1468

1469

1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482





1483
1484
1485
1486
1487
1488
1489







-
-
+
+

-
-
+
-

-
-
-
+

-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+

+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-







-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-






-
+

-
-
+
+
-
-
-
-










+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
-
+
















-
-
+
+
+

-
+

-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+


-
+
-
-
-
-




-
-
+
+





-
+
-













-
-
-
-
-







    return TCL_ERROR;
}

/*------------------------------------------------------------------------
 * +++ Geometry routines.
 */

/* + UpdatePositionItem --
 * 	Update position data for all visible items.
/* + CountRows --
 * 	Returns the number of viewable rows rooted at item
 */
static void UpdatePositionItem(
    Treeview *tv, TreeItem *item, int hidden,
static int CountRows(TreeItem *item)
    int *rowPos, int *itemPos, int *visiblePos)
{
    TreeItem *child = item->children;
    item->itemPos = *itemPos;
    *itemPos += 1;
    int rows = 1;

    if (item->hidden) {
	hidden = 1;
    }

    if (item->state & TTK_STATE_OPEN) {
	TreeItem *child = item->children;
	while (child) {
	    rows += CountRows(child);
	    child = child->next;
	}
    }
    if (hidden) {
	item->rowPos = -1;
    return rows;
	item->visiblePos = -1;
    } else {
	item->rowPos = *rowPos;
	item->visiblePos = *visiblePos;
	if (*visiblePos == tv->tree.nTitleItems) {
	    tv->tree.titleRows = *rowPos;
	}
}

/* + IdentifyRow --
 * 	Recursive search for item at specified y position.
 * 	Main work routine for IdentifyItem()
 */
static TreeItem *IdentifyRow(
    Treeview *tv,	/* Widget record */
    TreeItem *item, 	/* Where to start search */
    int *ypos,		/* Scan position */
    int y)		/* Target y coordinate */
{
	*visiblePos += 1;
	*rowPos += item->height;
    }

    if (!(item->state & TTK_STATE_OPEN)) {
	hidden = 1;
    }
    while (item) {
	int next_ypos = *ypos + tv->tree.rowHeight;
	if (*ypos <= y && y <= next_ypos) {
	    return item;
	}
	*ypos = next_ypos;
	if (item->state & TTK_STATE_OPEN) {
	    TreeItem *subitem = IdentifyRow(tv, item->children, ypos, y);
	    if (subitem) {
		return subitem;
	    }
    while (child) {
	UpdatePositionItem(tv, child, hidden, rowPos, itemPos, visiblePos);
	child = child->next;
    }
}

	}
	item = item->next;
    }
    return 0;
/* + UpdatePositionTree --
 * 	Update position data for all visible items.
 */
static void UpdatePositionTree(Treeview *tv)
{
    /* -1 for the invisible root */
    int rowPos = -1, itemPos = -1, visiblePos = -1;
    tv->tree.titleRows = 0;
    UpdatePositionItem(tv, tv->tree.root, 0, &rowPos, &itemPos, &visiblePos);
    tv->tree.totalRows = rowPos;
    tv->tree.rowPosNeedsUpdate = 0;
}

/* + IdentifyItem --
 * 	Locate the item at the specified y position, if any.
 */
static TreeItem *IdentifyItem(Treeview *tv, int y)
{
    TreeItem *item;
    int rowHeight = tv->tree.rowHeight;
    int ypos = tv->tree.treeArea.y;
    int ypos = tv->tree.treeArea.y - rowHeight * tv->tree.yscroll.first;
    int nextRow, row;
    if (y < ypos) {
	return NULL;
    }
    if (tv->tree.rowPosNeedsUpdate) {
	UpdatePositionTree(tv);
    }
    row = (y - ypos) / rowHeight;
    if (row >= tv->tree.titleRows) {
	row += tv->tree.yscroll.first;
    }
    for (item = tv->tree.root->children; item; item = NextPreorder(item)) {
    return IdentifyRow(tv, tv->tree.root->children, &ypos, y);
	nextRow = item->rowPos + item->height;
	if (item->rowPos <= row && row < nextRow) break;
    }
    return item;
}

/* + IdentifyDisplayColumn --
 * 	Returns the display column number at the specified x position,
 * 	or -1 if x is outside any columns.
 */
static Tcl_Size IdentifyDisplayColumn(Treeview *tv, int x, int *x1)
static int IdentifyDisplayColumn(Treeview *tv, int x, int *x1)
{
    Tcl_Size colno = FirstColumn(tv);
    int xpos = tv->tree.treeArea.x;
    int colno = FirstColumn(tv);
    int xpos = tv->tree.treeArea.x - tv->tree.xscroll.first;

    if (tv->tree.nTitleColumns <= colno) {
	xpos -= tv->tree.xscroll.first;
    }

    while (colno < tv->tree.nDisplayColumns) {
	TreeColumn *column = tv->tree.displayColumns[colno];
	int next_xpos = xpos + column->width;
	if (xpos <= x && x <= next_xpos + HALO) {
	    *x1 = next_xpos;
	    return colno;
	}
	++colno;
	xpos = next_xpos;
    }
	if (tv->tree.nTitleColumns == colno) {
	    xpos -= tv->tree.xscroll.first;
	}
    }

    return -1;
}

/* + RowNumber --
 * 	Calculate which row the specified item appears on;
 * 	returns -1 if the item is not viewable.
 * 	Xref: DrawForest, IdentifyItem.
 */
static int RowNumber(Treeview *tv, TreeItem *item)
{
    TreeItem *p = tv->tree.root->children;
    int n = 0;

    while (p) {
	if (p == item)
	    return n;

	++n;

	/* Find next viewable item in preorder traversal order
	 */
	if (p->children && (p->state & TTK_STATE_OPEN)) {
	    p = p->children;
	} else {
	    while (!p->next && p && p->parent)
		p = p->parent;
	    if (p)
		p = p->next;
	}
    }

    return TCL_INDEX_NONE;
    return -1;
}

/* + ItemDepth -- return the depth of a tree item.
 * 	The depth of an item is equal to the number of proper ancestors,
 * 	not counting the root node.
 */
static int ItemDepth(TreeItem *item)
{
    int depth = 0;
    while (item->parent) {
	++depth;
	item = item->parent;
    }
    return depth-1;
}

/* + DisplayRow --
 * 	Returns the position row has on screen, or -1 if off-screen.
/* + ItemRow --
 * 	Returns row number of specified item relative to root,
 * 	-1 if item is not viewable.
 */
static int DisplayRow(int row, Treeview *tv)
static int ItemRow(Treeview *tv, TreeItem *p)
{
    int visibleRows = tv->tree.treeArea.height / tv->tree.rowHeight
	    - tv->tree.titleRows;
    TreeItem *root = tv->tree.root;
    if (row < tv->tree.titleRows) {
	return row;
    }
    row -= tv->tree.titleRows;
    if (row < tv->tree.yscroll.first
	    || row > tv->tree.yscroll.first + visibleRows) {
	/* not viewable, or off-screen */
	return -1;
    }
    return row - tv->tree.yscroll.first + tv->tree.titleRows;
    int rowNumber = 0;

    for (;;) {
	if (p->prev) {
	    p = p->prev;
	    rowNumber += CountRows(p);
	} else {
	    p = p->parent;
	    if (!(p && (p->state & TTK_STATE_OPEN))) {
		/* detached or closed ancestor */
		return -1;
	    }
	    if (p == root) {
		return rowNumber;
	    }
	    ++rowNumber;
	}
    }
}

/* + BoundingBox --
 * 	Compute the parcel of the specified column of the specified item,
 *	(or the entire item if column is NULL)
 *	Returns: 0 if item or column is not viewable, 1 otherwise.
 */
static int BoundingBox(
    Treeview *tv,		/* treeview widget */
    TreeItem *item,		/* desired item */
    TreeColumn *column,		/* desired column */
    Ttk_Box *bbox_rtn)		/* bounding box of item */
{
    int dispRow;
    int row = ItemRow(tv, item);
    Ttk_Box bbox = tv->tree.treeArea;

    if (tv->tree.rowPosNeedsUpdate) {
    if (row < tv->tree.yscroll.first || row > tv->tree.yscroll.last) {
	UpdatePositionTree(tv);
    }
    dispRow = DisplayRow(item->rowPos, tv);
    if (dispRow < 0) {
	/* not viewable, or off-screen */
	return 0;
    }

    bbox.y += dispRow * tv->tree.rowHeight;
    bbox.height = tv->tree.rowHeight * item->height;
    bbox.y += (row - tv->tree.yscroll.first) * tv->tree.rowHeight;
    bbox.height = tv->tree.rowHeight;

    bbox.x -= tv->tree.xscroll.first;
    bbox.width = TreeWidth(tv);

    if (column) {
	int xpos = 0;
	int xpos = 0, i = FirstColumn(tv);
	Tcl_Size i = FirstColumn(tv);
	while (i < tv->tree.nDisplayColumns) {
	    if (tv->tree.displayColumns[i] == column) {
		break;
	    }
	    xpos += tv->tree.displayColumns[i]->width;
	    ++i;
	}
	if (i == tv->tree.nDisplayColumns) { /* specified column unviewable */
	    return 0;
	}
	bbox.x += xpos;
	bbox.width = column->width;

	if (i < tv->tree.nTitleColumns) {
	    /* Unscrollable column, remove scroll shift */
	    bbox.x += tv->tree.xscroll.first;
	}

	/* Account for indentation in tree column:
	 */
	if (column == &tv->tree.column0) {
	    int indent = tv->tree.indent * ItemDepth(item);
	    bbox.x += indent;
	    bbox.width -= indent;
	}
1812
1813
1814
1815
1816
1817
1818
1819

1820
1821
1822
1823
1824
1825

1826
1827

1828
1829
1830
1831
1832
1833
1834
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511

1512

1513
1514
1515
1516
1517
1518
1519
1520
1521







-
+





-
+
-

+







    REGION_NOTHING = 0,
    REGION_HEADING,
    REGION_SEPARATOR,
    REGION_TREE,
    REGION_CELL
} TreeRegion;

static const char *const regionStrings[] = {
static const char *regionStrings[] = {
    "nothing", "heading", "separator", "tree", "cell", 0
};

static TreeRegion IdentifyRegion(Treeview *tv, int x, int y)
{
    int x1 = 0;
    int x1 = 0, colno;
    Tcl_Size colno = IdentifyDisplayColumn(tv, x, &x1);

    colno = IdentifyDisplayColumn(tv, x, &x1);
    if (Ttk_BoxContains(tv->tree.headingArea, x, y)) {
	if (colno < 0) {
	    return REGION_NOTHING;
	} else if (-HALO <= x1 - x  && x1 - x <= HALO) {
	    return REGION_SEPARATOR;
	} else {
	    return REGION_HEADING;
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
1559
1560
1561
1562
1563
1564
1565

1566
1567
1568

1569


1570
1571
1572
1573

1574
1575

1576
1577
1578
1579

1580


1581
1582
1583
1584
1585
1586
1587
1588
1589


1590
1591
1592











1593


1594
1595

1596
1597









1598

1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614

1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626



1627
1628
1629

1630
1631
1632
1633
1634
1635
1636
1637
1638
1639



1640
1641
1642


1643









1644
1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659







-
+


-
+
-
-




-
+

-
+



-
+
-
-









-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
+
-
-
+

-
+

-
-
-
-
-
-
-
-
-

-
+















-
+

-
+
+





+

+
-
-
-
+
+
+
-










-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-








-
+








/* + TreeviewGetLayout --
 * 	GetLayout() widget hook.
 */
static Ttk_Layout TreeviewGetLayout(
    Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr)
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Ttk_Layout treeLayout = TtkWidgetGetLayout(interp, themePtr, recordPtr);
    Tcl_Obj *objPtr;
    int unused, cellHeight;
    int unused;
    DisplayItem displayItem;
    Ttk_Style style;

    if (!(
	treeLayout
     && GetSublayout(interp, themePtr, treeLayout, ".Item",
	    tv->tree.displayOptionTable, &tv->tree.itemLayout)
	    tv->tree.tagOptionTable, &tv->tree.itemLayout)
     && GetSublayout(interp, themePtr, treeLayout, ".Cell",
	    tv->tree.displayOptionTable, &tv->tree.cellLayout)
	    tv->tree.tagOptionTable, &tv->tree.cellLayout)
     && GetSublayout(interp, themePtr, treeLayout, ".Heading",
	    tv->tree.headingOptionTable, &tv->tree.headingLayout)
     && GetSublayout(interp, themePtr, treeLayout, ".Row",
	    tv->tree.displayOptionTable, &tv->tree.rowLayout)
	    tv->tree.tagOptionTable, &tv->tree.rowLayout)
     && GetSublayout(interp, themePtr, treeLayout, ".Separator",
	    tv->tree.displayOptionTable, &tv->tree.separatorLayout)
    )) {
	return 0;
    }

    /* Compute heading height.
     */
    Ttk_RebindSublayout(tv->tree.headingLayout, &tv->tree.column0);
    Ttk_LayoutSize(tv->tree.headingLayout, 0, &unused, &tv->tree.headingHeight);

    /* Get row height from style, or compute it to fit Item and Cell.
     * Pick up default font from the Treeview style.
    /* Get item height, indent from style:
     * @@@ TODO: sanity-check.
     */
    style = Ttk_LayoutStyle(treeLayout);
    Ttk_TagSetDefaults(tv->tree.tagTable, style, &displayItem);

    Ttk_RebindSublayout(tv->tree.itemLayout, &displayItem);
    Ttk_LayoutSize(tv->tree.itemLayout, 0, &unused, &tv->tree.rowHeight);

    Ttk_RebindSublayout(tv->tree.cellLayout, &displayItem);
    Ttk_LayoutSize(tv->tree.cellLayout, 0, &unused, &cellHeight);

    if (cellHeight > tv->tree.rowHeight) {
	tv->tree.rowHeight = cellHeight;
    tv->tree.rowHeight = DEFAULT_ROWHEIGHT;
    }

    tv->tree.indent = DEFAULT_INDENT;
    if ((objPtr = Ttk_QueryOption(treeLayout, "-rowheight", 0))) {
	(void)Tk_GetPixelsFromObj(NULL, tv->core.tkwin, objPtr, &tv->tree.rowHeight);
	(void)Tcl_GetIntFromObj(NULL, objPtr, &tv->tree.rowHeight);
    }
    tv->tree.rowHeight = MAX(tv->tree.rowHeight, 1);

    if ((objPtr = Ttk_QueryOption(treeLayout, "-columnseparatorwidth", 0))) {
	(void)Tk_GetPixelsFromObj(NULL, tv->core.tkwin, objPtr, &tv->tree.colSeparatorWidth);
    }

    /* Get item indent from style:
     */
    tv->tree.indent = DEFAULT_INDENT;
    if ((objPtr = Ttk_QueryOption(treeLayout, "-indent", 0))) {
	(void)Tk_GetPixelsFromObj(NULL, tv->core.tkwin, objPtr, &tv->tree.indent);
	(void)Tcl_GetIntFromObj(NULL, objPtr, &tv->tree.indent);
    }

    return treeLayout;
}

/* + TreeviewDoLayout --
 * 	DoLayout() widget hook.  Computes widget layout.
 *
 * Side effects:
 * 	Computes headingArea and treeArea.
 * 	Computes subtree height.
 * 	Invokes scroll callbacks.
 */
static void TreeviewDoLayout(void *clientData)
{
    Treeview *tv = (Treeview *)clientData;
    Treeview *tv = clientData;
    int visibleRows;
    int first, last, total;

    /* ASSERT: SLACKINVARIANT */

    Ttk_PlaceLayout(tv->core.layout,tv->core.state,Ttk_WinBox(tv->core.tkwin));
    tv->tree.treeArea = Ttk_ClientRegion(tv->core.layout, "treearea");

    ResizeColumns(tv, tv->tree.treeArea.width);
    /* ASSERT: SLACKINVARIANT */

    TtkScrolled(tv->tree.xscrollHandle,
    first = tv->tree.xscroll.first;
    last = first + tv->tree.treeArea.width - tv->tree.titleWidth;
    total = TreeWidth(tv) - tv->tree.titleWidth;
	    tv->tree.xscroll.first,
	    tv->tree.xscroll.first + tv->tree.treeArea.width,
	    TreeWidth(tv));
    TtkScrolled(tv->tree.xscrollHandle, first, last, total);

    if (tv->tree.showFlags & SHOW_HEADINGS) {
	tv->tree.headingArea = Ttk_PackBox(
	    &tv->tree.treeArea, 1, tv->tree.headingHeight, TTK_SIDE_TOP);
    } else {
	tv->tree.headingArea = Ttk_MakeBox(0,0,0,0);
    }

    visibleRows = tv->tree.treeArea.height / tv->tree.rowHeight;
    tv->tree.root->state |= TTK_STATE_OPEN;
    UpdatePositionTree(tv);
    first = tv->tree.yscroll.first;
    last = tv->tree.yscroll.first + visibleRows - tv->tree.titleRows;
    TtkScrolled(tv->tree.yscrollHandle,
	    tv->tree.yscroll.first,
	    tv->tree.yscroll.first + visibleRows,
    total = tv->tree.totalRows - tv->tree.titleRows;
    if (tv->tree.treeArea.height % tv->tree.rowHeight) {
	    CountRows(tv->tree.root) - 1);
        /* When the treeview height doesn't correspond to an exact number
         * of rows, the last row count must be incremented to draw a
         * partial row at the bottom. The total row count must also be
         * incremented to be able to scroll all the way to the bottom.
         */
        last++;
        total++;
    }
    TtkScrolled(tv->tree.yscrollHandle, first, last, total);
}

/* + TreeviewSize --
 * 	SizeProc() widget hook.  Size is determined by
 * 	-height option and column widths.
 */
static int TreeviewSize(void *clientData, int *widthPtr, int *heightPtr)
{
    Treeview *tv = (Treeview *)clientData;
    Treeview *tv = clientData;
    int nRows, padHeight, padWidth;

    Ttk_LayoutSize(tv->core.layout, tv->core.state, &padWidth, &padHeight);
    Tcl_GetIntFromObj(NULL, tv->tree.heightObj, &nRows);

    *widthPtr = padWidth + TreeWidth(tv);
    *heightPtr = padHeight + tv->tree.rowHeight * nRows;
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
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







-
+


-
+


-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+


+

-
-

-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+
-
-
+


-


-
-
-
-
-
+
+
+
+

-
-
-
+
+


-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-




-
-
-
-
+
-
-
-
-
-
-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-

-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
+
+
-
-
-
+
-
-




-
+

-

-
-
+
+

-
-
-
+

+
-
-
+
+








-
+


+
-
+
+
+
+
+
+
+
+




-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+

-
-
+
+

-
-
-
+
+



-
+
+
+





+
+
+

-
-
+
+

-
-
+
+


+







-
+





-
+
-







}

/* + DrawHeadings --
 *	Draw tree headings.
 */
static void DrawHeadings(Treeview *tv, Drawable d)
{
    int x0 = tv->tree.headingArea.x - tv->tree.xscroll.first;
    const int x0 = tv->tree.headingArea.x - tv->tree.xscroll.first;
    const int y0 = tv->tree.headingArea.y;
    const int h0 = tv->tree.headingArea.height;
    Tcl_Size i = FirstColumn(tv);
    int i = FirstColumn(tv);
    int x = 0;

    if (tv->tree.nTitleColumns > i) {
	x = tv->tree.titleWidth;
	i = tv->tree.nTitleColumns;
    }

    while (i < tv->tree.nDisplayColumns) {
	TreeColumn *column = tv->tree.displayColumns[i];
	Ttk_Box parcel = Ttk_MakeBox(x0+x, y0, column->width, h0);
	if (x0+x+column->width > tv->tree.titleWidth) {
	    DisplayLayout(tv->tree.headingLayout,
		    column, column->headingState, parcel, d);
	}
	x += column->width;
	++i;
    }

    x0 = tv->tree.headingArea.x;
    i = FirstColumn(tv);
    x = 0;
    while ((i < tv->tree.nTitleColumns) && (i < tv->tree.nDisplayColumns)) {
	TreeColumn *column = tv->tree.displayColumns[i];
	Ttk_Box parcel = Ttk_MakeBox(x0+x, y0, column->width, h0);
	DisplayLayout(tv->tree.headingLayout,
	    column, column->headingState, parcel, d);
	x += column->width;
	++i;
    }
}

/* + DrawSeparators --
 *	Draw separators between columns
 */
static void DrawSeparators(Treeview *tv, Drawable d)
{
    const int y0 = tv->tree.treeArea.y;
    const int h0 = tv->tree.treeArea.height;
    DisplayItem displayItem;
    Ttk_Style style = Ttk_LayoutStyle(tv->tree.separatorLayout);
    int x = tv->tree.treeArea.x;
    Tcl_Size i;

    Ttk_TagSetDefaults(tv->tree.tagTable, style, &displayItem);

    for (i = FirstColumn(tv); i < tv->tree.nDisplayColumns; ++i) {
	TreeColumn *column = tv->tree.displayColumns[i];
	Ttk_Box parcel;
	int xDraw = x + column->width;
	x += column->width;

	if (!column->separator) continue;

	if (i >= tv->tree.nTitleColumns) {
	    xDraw -= tv->tree.xscroll.first;
	    if (xDraw < tv->tree.titleWidth) continue;
	}

	parcel = Ttk_MakeBox(xDraw - (tv->tree.colSeparatorWidth+1)/2, y0,
		tv->tree.colSeparatorWidth, h0);
	DisplayLayout(tv->tree.separatorLayout, &displayItem, 0, parcel, d);
    }
}

/* + OverrideStriped --
 * 	Each level of settings might add stripedbackground, and it should
 * 	override background if this is indeed on a striped item.
 * 	By copying it between each level, and NULL-ing stripedBgObj,
 * 	it can be detected if the next level overrides it.
 */
 static void OverrideStriped(
    Treeview *tv, TreeItem *item, DisplayItem *displayItem)
{
    int striped = item->visiblePos % 2 && tv->tree.striped;
    if (striped && displayItem->stripedBgObj) {
	displayItem->backgroundObj = displayItem->stripedBgObj;
	displayItem->stripedBgObj = NULL;
    }
}

/* + PrepareItem --
 * 	Fill in a displayItem record.
 */
static void PrepareItem(
    Treeview *tv, TreeItem *item, DisplayItem *displayItem, Ttk_State state)
    Treeview *tv, TreeItem *item, DisplayItem *displayItem)
{
    Ttk_Style style = Ttk_LayoutStyle(tv->core.layout);
    Ttk_State state = ItemState(tv, item);

    Ttk_TagSetDefaults(tv->tree.tagTable, style, displayItem);
    OverrideStriped(tv, item, displayItem);
    Ttk_TagSetValues(tv->tree.tagTable, item->tagset, displayItem);
    OverrideStriped(tv, item, displayItem);
    Ttk_TagSetApplyStyle(tv->tree.tagTable, style, state, displayItem);
}

/* Fill in data from item to temporary storage in columns. */
static void PrepareCells(
   Treeview *tv, TreeItem *item)
{
    Tcl_Size i, nValues = 0;
    Tcl_Obj **values = NULL;
    TreeColumn *column;

    if (item->valuesObj) {
	Tcl_ListObjGetElements(NULL, item->valuesObj, &nValues, &values);
    }
    for (i = 0; i < tv->tree.nColumns; ++i) {
	tv->tree.columns[i].data = (i < nValues) ? values[i] : 0;
	tv->tree.columns[i].selected = 0;
	tv->tree.columns[i].tagset = NULL;
    }
    tv->tree.column0.data = NULL;
    tv->tree.column0.selected = 0;
    tv->tree.column0.tagset = NULL;

    if (item->selObj != NULL) {
	Tcl_ListObjGetElements(NULL, item->selObj, &nValues, &values);
	for (i = 0; i < nValues; ++i) {
	    column = FindColumn(NULL, tv, values[i]);
	    /* Just in case. It should not be possible for column to be NULL */
	    if (column != NULL) {
		column->selected = 1;
	    }
	}
    }
    if (item->nTagSets > 0) {
	tv->tree.column0.tagset = item->cellTagSets[0];
    }
    for (i = 1; i < item->nTagSets && i <= tv->tree.nColumns; ++i) {
	tv->tree.columns[i-1].tagset = item->cellTagSets[i];
    }
}

/* + DrawCells --
 *	Draw data cells for specified item.
 */
static void DrawCells(
    Treeview *tv, TreeItem *item,
    Treeview *tv, TreeItem *item, DisplayItem *displayItem,
    DisplayItem *displayItem, DisplayItem *displayItemSel,
    Drawable d, int x, int y, int title)
    Drawable d, int x, int y)
{
    Ttk_Layout layout = tv->tree.cellLayout;
    Ttk_Style style = Ttk_LayoutStyle(tv->core.layout);
    Ttk_State state = ItemState(tv, item);
    Ttk_Padding cellPadding = {4, 0, 4, 0};
    DisplayItem displayItemLocal;
    DisplayItem displayItemCell, displayItemCellSel;
    int rowHeight = tv->tree.rowHeight * item->height;
    int xPad = 0, defaultPadding = 1;
    Tcl_Size i;
    int rowHeight = tv->tree.rowHeight;
    int nValues = 0;
    Tcl_Obj **values = 0;
    int i;

    /* Adjust if the tree column has a separator */
    if (tv->tree.showFlags & SHOW_TREE && tv->tree.column0.separator) {
	xPad = tv->tree.colSeparatorWidth/2;
    if (!item->valuesObj) {
	return;
    }

    /* An Item's image should not propagate to a Cell.
       A Cell's image can only be set by cell tags. */
    displayItemCell = *displayItem;
    displayItemCellSel = *displayItemSel;
    displayItemCell.imageObj = NULL;
    displayItemCellSel.imageObj = NULL;
    displayItemCell.imageAnchorObj = NULL;
    displayItemCellSel.imageAnchorObj = NULL;

    Tcl_ListObjGetElements(NULL, item->valuesObj, &nValues, &values);
    /* If explicit padding was asked for, skip default. */
    if (Ttk_QueryStyle(Ttk_LayoutStyle(tv->tree.cellLayout), &displayItemCell,
		    tv->tree.displayOptionTable, "-padding", state) != NULL) {
    for (i = 0; i < tv->tree.nColumns; ++i) {
	tv->tree.columns[i].data = (i < nValues) ? values[i] : 0;
	defaultPadding = 0;
    }

    for (i = 1; i < tv->tree.nDisplayColumns; ++i) {
	TreeColumn *column = tv->tree.displayColumns[i];
	int parcelX = x + xPad;
	int parcelWidth = column->separator ?
		column->width - tv->tree.colSeparatorWidth : column->width;
	Ttk_Box parcel = Ttk_MakeBox(parcelX, y, parcelWidth, rowHeight);
	Ttk_Box parcel = Ttk_PadBox(
	DisplayItem *displayItemUsed = &displayItemCell;
	Ttk_State stateCell = state;
	Tk_Anchor textAnchor, imageAnchor;
	xPad = column->separator ? tv->tree.colSeparatorWidth/2 : 0;

	x += column->width;
	    Ttk_MakeBox(x, y, column->width, rowHeight), cellPadding);
	if (title  && i >= tv->tree.nTitleColumns) break;
	if (!title && i <  tv->tree.nTitleColumns) continue;
	if (!title && x <  tv->tree.titleWidth) continue;

	if (column->selected) {
	    displayItemUsed = &displayItemCellSel;
	    stateCell |= TTK_STATE_SELECTED;
	}

	if (column->tagset) {
	    displayItemLocal = *displayItemUsed;
	    displayItemUsed = &displayItemLocal;
	    Ttk_TagSetValues(tv->tree.tagTable, column->tagset,
		    displayItemUsed);
	    OverrideStriped(tv, item, displayItemUsed);
	    Ttk_TagSetApplyStyle(tv->tree.tagTable, style, stateCell,
		    displayItemUsed);
	}

	displayItemUsed->textObj = column->data;
	displayItemUsed->anchorObj = column->anchorObj;/* <<NOTE-ANCHOR>> */
	displayItem->textObj = column->data;
	displayItem->anchorObj = column->anchorObj;	/* <<NOTE-ANCHOR>> */
	Tk_GetAnchorFromObj(NULL, column->anchorObj, &textAnchor);

	imageAnchor = DEFAULT_IMAGEANCHOR;
	if (displayItemUsed->imageAnchorObj) {
	    Tk_GetAnchorFromObj(NULL, displayItemUsed->imageAnchorObj,
		    &imageAnchor);
	}
	/* displayItem was used to draw the full item backgound.
	   Redraw cell background if needed. */
	if (displayItemUsed != &displayItemCell) {
	    DisplayLayout(tv->tree.rowLayout, displayItemUsed, stateCell,
		    parcel, d);
	DisplayLayout(layout, displayItem, state, parcel, d);
	}

	x += column->width;
	if (defaultPadding && displayItemUsed->paddingObj == NULL) {
	    /* If no explicit padding was asked for, add some default. */
	    parcel = Ttk_PadBox(parcel, cellPadding);
	}

    }
}
	DisplayLayoutTree(imageAnchor, textAnchor,
		layout, displayItemUsed, state, parcel, d);
    }

}

/* + DrawItem --
 * 	Draw an item (row background, tree label, and cells).
 */
static void DrawItem(
    Treeview *tv, TreeItem *item, Drawable d, int depth)
    Treeview *tv, TreeItem *item, Drawable d, int depth, int row)
{
    Ttk_Style style = Ttk_LayoutStyle(tv->core.layout);
    Ttk_State state = ItemState(tv, item);
    DisplayItem displayItem, displayItemSel, displayItemLocal;
    int rowHeight = tv->tree.rowHeight * item->height;
    DisplayItem displayItem;
    int rowHeight = tv->tree.rowHeight;
    int x = tv->tree.treeArea.x - tv->tree.xscroll.first;
    int xTitle = tv->tree.treeArea.x;
    int dispRow = DisplayRow(item->rowPos, tv);
    int y = tv->tree.treeArea.y + tv->tree.rowHeight * dispRow;
    int y = tv->tree.treeArea.y + rowHeight * (row - tv->tree.yscroll.first);

    if (row % 2) state |= TTK_STATE_ALTERNATE;
    PrepareItem(tv, item, &displayItem, state);
    PrepareItem(tv, item, &displayItemSel, state | TTK_STATE_SELECTED);

    PrepareItem(tv, item, &displayItem);

    /* Draw row background:
     */
    {
	Ttk_Box rowBox = Ttk_MakeBox(x, y, TreeWidth(tv), rowHeight);
	DisplayLayout(tv->tree.rowLayout, &displayItem, state, rowBox, d);
    }

    /* Make room for tree label:
    /* Draw tree label:
     */
    if (tv->tree.showFlags & SHOW_TREE) {
	int indent = depth * tv->tree.indent;
	x += tv->tree.column0.width;
	int colwidth = tv->tree.column0.width;
	Ttk_Box parcel = Ttk_MakeBox(
		x+indent, y, colwidth-indent, rowHeight);
	if (item->textObj) { displayItem.textObj = item->textObj; }
	if (item->imageObj) { displayItem.imageObj = item->imageObj; }
	/* ??? displayItem.anchorObj = 0; <<NOTE-ANCHOR>> */
	DisplayLayout(tv->tree.itemLayout, &displayItem, state, parcel, d);
	x += colwidth;
    }

    /* Draw data cells:
     */
    PrepareCells(tv, item);
    DrawCells(tv, item, &displayItem, &displayItemSel, d, x, y, 0);

    DrawCells(tv, item, &displayItem, d, x, y);
}
    /* Draw row background for non-scrolled area:
     */
    if (tv->tree.nTitleColumns >= 1) {
	Ttk_Box rowBox = Ttk_MakeBox(tv->tree.treeArea.x, y,
		tv->tree.titleWidth, rowHeight);
	DisplayLayout(tv->tree.rowLayout, &displayItem, state, rowBox, d);
    }


/* + DrawSubtree --
    /* Draw tree label:
     */
    x = tv->tree.treeArea.x - tv->tree.xscroll.first;
    if (tv->tree.showFlags & SHOW_TREE) {
	TreeColumn *column = &tv->tree.column0;
	int indent = depth * tv->tree.indent;
	int colwidth = tv->tree.column0.width -
		(tv->tree.column0.separator ? tv->tree.colSeparatorWidth/2 : 0);
	int xTree = tv->tree.nTitleColumns >= 1 ? xTitle : x;
	Ttk_Box parcel = Ttk_MakeBox(xTree, y, colwidth, rowHeight);
	DisplayItem *displayItemUsed = &displayItem;
	Ttk_State stateCell = state;
	Tk_Anchor textAnchor, imageAnchor = DEFAULT_IMAGEANCHOR;
	Ttk_Padding cellPadding = {(short)indent, 0, 0, 0};

 * 	Draw an item and all of its (viewable) descendants.
	if (column->selected) {
	    displayItemUsed = &displayItemSel;
 	    stateCell |= TTK_STATE_SELECTED;
	}

 *
	if (column->tagset) {
	    displayItemLocal = *displayItemUsed;
	    displayItemUsed = &displayItemLocal;
	    Ttk_TagSetValues(tv->tree.tagTable, column->tagset,
		    displayItemUsed);
	    OverrideStriped(tv, item, displayItemUsed);
	    Ttk_TagSetApplyStyle(tv->tree.tagTable, style, stateCell,
		    displayItemUsed);
	}

 * Returns:
        displayItem.anchorObj = tv->tree.column0.anchorObj;
	Tk_GetAnchorFromObj(NULL, column->anchorObj, &textAnchor);
	displayItemUsed->textObj = item->textObj;
	/* Item's image can be null, and may come from the tag */
	if (item->imageObj) {
	    displayItemUsed->imageObj = item->imageObj;
	}
	if (item->imageAnchorObj) {
	    displayItemUsed->imageAnchorObj = item->imageAnchorObj;
	}
	if (displayItemUsed->imageAnchorObj) {
	    Tk_GetAnchorFromObj(NULL, displayItemUsed->imageAnchorObj,
		    &imageAnchor);
	}

 * 	Row number of the last item drawn.
	if (displayItemUsed != &displayItem) {
	    DisplayLayout(tv->tree.rowLayout, displayItemUsed, stateCell,
		    parcel, d);
	}

	parcel = Ttk_PadBox(parcel, cellPadding);
	DisplayLayoutTree(imageAnchor, textAnchor,
		tv->tree.itemLayout, displayItemUsed, state, parcel, d);
	xTitle += colwidth;
    }

    /* Draw non-scrolled data cells:
     */
    if (tv->tree.nTitleColumns > 1) {
	DrawCells(tv, item, &displayItem, &displayItemSel, d, xTitle, y, 1);
    }
}

/* + DrawSubtree --
 * 	Draw an item and all of its (viewable) descendants.
 */

static void DrawForest(	/* forward */
    Treeview *tv, TreeItem *item, Drawable d, int depth);
static int DrawForest(	/* forward */
    Treeview *tv, TreeItem *item, Drawable d, int depth, int row);

static void DrawSubtree(
    Treeview *tv, TreeItem *item, Drawable d, int depth)
static int DrawSubtree(
    Treeview *tv, TreeItem *item, Drawable d, int depth, int row)
{
    int dispRow = DisplayRow(item->rowPos, tv);
    if (dispRow >= 0) {
	DrawItem(tv, item, d, depth);
    if (row >= tv->tree.yscroll.first) {
	DrawItem(tv, item, d, depth, row);
    }

    if (item->state & TTK_STATE_OPEN) {
	DrawForest(tv, item->children, d, depth + 1);
	return DrawForest(tv, item->children, d, depth + 1, row + 1);
    } else {
	return row + 1;
    }
}

/* + DrawForest --
 * 	Draw a sequence of items and their visible descendants.
 *
 * Returns:
 * 	Row number of the last item drawn.
 */
static void DrawForest(
    Treeview *tv, TreeItem *item, Drawable d, int depth)
static int DrawForest(
    Treeview *tv, TreeItem *item, Drawable d, int depth, int row)
{
    while (item) {
        DrawSubtree(tv, item, d, depth);
    while (item && row <= tv->tree.yscroll.last) {
        row = DrawSubtree(tv, item, d, depth, row);
	item = item->next;
    }
    return row;
}

/* + TreeviewDisplay --
 * 	Display() widget hook.  Draw the widget contents.
 */
static void TreeviewDisplay(void *clientData, Drawable d)
{
    Treeview *tv = (Treeview *)clientData;
    Treeview *tv = clientData;

    Ttk_DrawLayout(tv->core.layout, tv->core.state, d);
    if (tv->tree.showFlags & SHOW_HEADINGS) {
	DrawHeadings(tv, d);
    }
    DrawForest(tv, tv->tree.root->children, d, 0);
    DrawForest(tv, tv->tree.root->children, d, 0,0);
    DrawSeparators(tv, d);
}

/*------------------------------------------------------------------------
 * +++ Utilities for widget commands
 */

/* + InsertPosition --
2514
2515
2516
2517
2518
2519
2520
2521

2522
2523

2524
2525
2526
2527
2528
2529
2530
1945
1946
1947
1948
1949
1950
1951

1952
1953

1954
1955
1956
1957
1958
1959
1960
1961







-
+

-
+







 * +++ Widget commands -- item inquiry.
 */

/* + $tv children $item ?newchildren? --
 * 	Return the list of children associated with $item
 */
static int TreeviewChildrenCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;
    Tcl_Obj *result;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "item ?newchildren?");
	return TCL_ERROR;
    }
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
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







-
+

















-
+








-
+











-










-
+

-
+







	int i;

	if (!newChildren)
	    return TCL_ERROR;

	/* Sanity-check:
	 */
	for (i = 0; newChildren[i]; ++i) {
	for (i=0; newChildren[i]; ++i) {
	    if (!AncestryCheck(interp, tv, newChildren[i], item)) {
		ckfree(newChildren);
		return TCL_ERROR;
	    }
	}

	/* Detach old children:
	 */
	child = item->children;
	while (child) {
	    TreeItem *next = child->next;
	    DetachItem(child);
	    child = next;
	}

	/* Detach new children from their current locations:
	 */
	for (i = 0; newChildren[i]; ++i) {
	for (i=0; newChildren[i]; ++i) {
	    DetachItem(newChildren[i]);
	}

	/* Reinsert new children:
	 * Note: it is not an error for an item to be listed more than once,
	 * though it probably should be...
	 */
	child = 0;
	for (i = 0; newChildren[i]; ++i) {
	for (i=0; newChildren[i]; ++i) {
	    if (newChildren[i]->parent) {
		/* This is a duplicate element which has already been
		 * inserted.  Ignore it.
		 */
		continue;
	    }
	    InsertItem(item, child, newChildren[i]);
	    child = newChildren[i];
	}

	ckfree(newChildren);
	tv->tree.rowPosNeedsUpdate = 1;
	TtkRedisplayWidget(&tv->core);
    }

    return TCL_OK;
}

/* + $tv parent $item --
 * 	Return the item ID of $item's parent.
 */
static int TreeviewParentCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    item = FindItem(interp, tv, objv[2]);
2623
2624
2625
2626
2627
2628
2629
2630

2631
2632

2633
2634
2635
2636
2637
2638
2639
2053
2054
2055
2056
2057
2058
2059

2060
2061

2062
2063
2064
2065
2066
2067
2068
2069







-
+

-
+







    return TCL_OK;
}

/* + $tv next $item
 * 	Return the ID of $item's next sibling.
 */
static int TreeviewNextCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    item = FindItem(interp, tv, objv[2]);
2648
2649
2650
2651
2652
2653
2654
2655

2656
2657

2658
2659
2660
2661
2662
2663
2664
2078
2079
2080
2081
2082
2083
2084

2085
2086

2087
2088
2089
2090
2091
2092
2093
2094







-
+

-
+







    return TCL_OK;
}

/* + $tv prev $item
 * 	Return the ID of $item's previous sibling.
 */
static int TreeviewPrevCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    item = FindItem(interp, tv, objv[2]);
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
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







-
+

-
+

-
+















-
+







-
+

-
+
















-
+

-
+













-
+




















-
+
-
-
-




-
-
+
+




-
-
+
+
+







-
+


















-


-
+
-
-

-
+







    return TCL_OK;
}

/* + $tv index $item --
 * 	Return the index of $item within its parent.
 */
static int TreeviewIndexCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;
    Tcl_Size index = 0;
    int index = 0;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    item = FindItem(interp, tv, objv[2]);
    if (!item) {
	return TCL_ERROR;
    }

    while (item->prev) {
	++index;
	item = item->prev;
    }

    Tcl_SetObjResult(interp, TkNewIndexObj(index));
    Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
    return TCL_OK;
}

/* + $tv exists $itemid --
 * 	Test if the specified item id is present in the tree.
 */
static int TreeviewExistsCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Tcl_HashEntry *entryPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "itemid");
	return TCL_ERROR;
    }

    entryPtr = Tcl_FindHashEntry(&tv->tree.items, Tcl_GetString(objv[2]));
    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(entryPtr != 0));
    return TCL_OK;
}

/* + $tv bbox $itemid ?$column? --
 * 	Return bounding box [x y width height] of specified item.
 */
static int TreeviewBBoxCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item = 0;
    TreeColumn *column = 0;
    Ttk_Box bbox;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "itemid ?column");
	return TCL_ERROR;
    }

    item = FindItem(interp, tv, objv[2]);
    if (!item) {
	return TCL_ERROR;
    }
    if (objc >= 4 && (column = FindColumn(interp,tv,objv[3])) == NULL) {
    if (objc >=4 && (column = FindColumn(interp,tv,objv[3])) == NULL) {
	return TCL_ERROR;
    }

    if (BoundingBox(tv, item, column, &bbox)) {
	Tcl_SetObjResult(interp, Ttk_NewBoxObj(bbox));
    }

    return TCL_OK;
}

/* + $tv identify $x $y -- (obsolescent)
 * 	Implements the old, horrible, 2-argument form of [$tv identify].
 *
 * Returns: one of
 * 	heading #n
 * 	cell itemid #n
 * 	item itemid element
 * 	row itemid
 */
static int TreeviewHorribleIdentify(
    Tcl_Interp *interp,
    Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], Treeview *tv)
    TCL_UNUSED(Tcl_Size), /* objc */
    Tcl_Obj *const objv[],
    Treeview *tv)
{
    const char *what = "nothing", *detail = NULL;
    TreeItem *item = 0;
    Tcl_Obj *result;
    Tcl_Size dColumnNumber;
    char dcolbuf[32];
    int dColumnNumber;
    char dcolbuf[16];
    int x, y, x1;

    /* ASSERT: objc == 4 */

    if (Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK
	    || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK) {
    if (   Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK
	|| Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK
    ) {
	return TCL_ERROR;
    }

    dColumnNumber = IdentifyDisplayColumn(tv, x, &x1);
    if (dColumnNumber < 0) {
	goto done;
    }
    snprintf(dcolbuf, sizeof(dcolbuf), "#%" TCL_SIZE_MODIFIER "d", dColumnNumber);
    sprintf(dcolbuf, "#%d", dColumnNumber);

    if (Ttk_BoxContains(tv->tree.headingArea,x,y)) {
	if (-HALO <= x1 - x  && x1 - x <= HALO) {
	    what = "separator";
	} else {
	    what = "heading";
	}
	detail = dcolbuf;
    } else if (Ttk_BoxContains(tv->tree.treeArea,x,y)) {
	item = IdentifyItem(tv, y);
	if (item && dColumnNumber > 0) {
	    what = "cell";
	    detail = dcolbuf;
	} else if (item) {
	    Ttk_Layout layout = tv->tree.itemLayout;
	    Ttk_Box itemBox;
	    DisplayItem displayItem;
	    Ttk_Element element;
	    Ttk_State state = ItemState(tv, item);

	    BoundingBox(tv, item, NULL, &itemBox);
	    PrepareItem(tv, item, &displayItem, state);
	    PrepareItem(tv, item, &displayItem); /*@@@ FIX: -text, etc*/
            if (item->textObj) { displayItem.textObj = item->textObj; }
            if (item->imageObj) { displayItem.imageObj = item->imageObj; }
	    Ttk_RebindSublayout(layout, &displayItem);
	    Ttk_PlaceLayout(layout, state, itemBox);
	    Ttk_PlaceLayout(layout, ItemState(tv,item), itemBox);
	    element = Ttk_IdentifyElement(layout, x, y);

	    if (element) {
		what = "item";
		detail = Ttk_ElementName(element);
	    } else {
		what = "row";
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
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







-
+

-
-
-
+
+
+

-
+







-
+
-







}

/* + $tv identify $component $x $y --
 * 	Identify the component at position x,y.
 */

static int TreeviewIdentifyCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    static const char *const submethodStrings[] =
	 { "region", "item", "column", "row", "element", "cell", NULL };
    enum { I_REGION, I_ITEM, I_COLUMN, I_ROW, I_ELEMENT, I_CELL };
    static const char *submethodStrings[] =
	 { "region", "item", "column", "row", "element", NULL };
    enum { I_REGION, I_ITEM, I_COLUMN, I_ROW, I_ELEMENT };

    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    int submethod;
    int x, y;

    TreeRegion region;
    Ttk_Box bbox;
    TreeItem *item;
    TreeColumn *column = 0;
    Tcl_Size colno;
    int colno, x1;
    int x1;

    if (objc == 4) {	/* Old form */
	return TreeviewHorribleIdentify(interp, objc, objv, tv);
    } else if (objc != 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "command x y");
	return TCL_ERROR;
    }
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
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







-
+
-
-
-
-
-
-
-
-
-








-

















-
-
-



-
-
+
+
-
-

-
+




















-
+

-
+



-
+







	    if (item) {
		Tcl_SetObjResult(interp, ItemID(tv, item));
	    }
	    break;

	case I_COLUMN :
	    if (colno >= 0) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf("#%" TCL_SIZE_MODIFIER "d", colno));
		Tcl_SetObjResult(interp, Tcl_ObjPrintf("#%d", colno));
	    }
	    break;

	case I_CELL :
	    if (item && colno >= 0) {
		Tcl_Obj *elem[2];
		elem[0] = ItemID(tv, item);
		elem[1] = Tcl_ObjPrintf("#%" TCL_SIZE_MODIFIER "d", colno);
		Tcl_SetObjResult(interp, Tcl_NewListObj(2, elem));
	    }
	    break;

	case I_ELEMENT :
	{
	    Ttk_Layout layout = 0;
	    DisplayItem displayItem;
	    Ttk_Element element;
	    Ttk_State state;

	    switch (region) {
		case REGION_NOTHING:
		    layout = tv->core.layout;
		    return TCL_OK; /* @@@ NYI */
		case REGION_HEADING:
		case REGION_SEPARATOR:
		    layout = tv->tree.headingLayout;
		    return TCL_OK; /* @@@ NYI */
		case REGION_TREE:
		    layout = tv->tree.itemLayout;
		    break;
		case REGION_CELL:
		    layout = tv->tree.cellLayout;
		    break;
	    }

	    if (item == NULL) {
		return TCL_OK;
	    }
	    if (!BoundingBox(tv, item, column, &bbox)) {
		return TCL_OK;
	    }
	    state = ItemState(tv, item);
	    PrepareItem(tv, item, &displayItem, state);

	    PrepareItem(tv, item, &displayItem); /*@@@ FIX: fill in -text,etc */
            if (item->textObj) { displayItem.textObj = item->textObj; }
            if (item->imageObj) { displayItem.imageObj = item->imageObj; }
	    Ttk_RebindSublayout(layout, &displayItem);
	    Ttk_PlaceLayout(layout, state, bbox);
	    Ttk_PlaceLayout(layout, ItemState(tv,item), bbox);
	    element = Ttk_IdentifyElement(layout, x, y);

	    if (element) {
		const char *elementName = Ttk_ElementName(element);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(elementName, -1));
	    }
	    break;
	}
    }
    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Widget commands -- item and column configuration.
 */

/* + $tv item $item ?options ....?
 * 	Query or configure item options.
 */
static int TreeviewItemCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item ?-option ?value??...");
	Tcl_WrongNumArgs(interp, 2, objv, "item ?option ?value??...");
	return TCL_ERROR;
    }
    if (!(item = FindItem(interp, tv, objv[2]))) {
	return TCL_ERROR;
    }

    if (objc == 3) {
2983
2984
2985
2986
2987
2988
2989
2990

2991
2992

2993
2994
2995
2996
2997
2998
2999
2392
2393
2394
2395
2396
2397
2398

2399
2400

2401
2402
2403
2404
2405
2406
2407
2408







-
+

-
+







    }
}

/* + $tv column column ?options ....?
 * 	Column data accessor
 */
static int TreeviewColumnCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeColumn *column;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "column -option value...");
	return TCL_ERROR;
    }
    if (!(column = FindColumn(interp, tv, objv[2]))) {
3011
3012
3013
3014
3015
3016
3017
3018

3019
3020

3021
3022
3023
3024
3025
3026
3027
2420
2421
2422
2423
2424
2425
2426

2427
2428

2429
2430
2431
2432
2433
2434
2435
2436







-
+

-
+







    }
}

/* + $tv heading column ?options ....?
 * 	Heading data accessor
 */
static int TreeviewHeadingCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Tk_OptionTable optionTable = tv->tree.headingOptionTable;
    Tk_Window tkwin = tv->core.tkwin;
    TreeColumn *column;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "column -option value...");
	return TCL_ERROR;
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
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







-
+

-
+


-
+




















-
+







    }
}

/* + $tv set $item ?$column ?value??
 * 	Query or configure cell values
 */
static int TreeviewSetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item;
    TreeColumn *column;
    Tcl_Size columnNumber;
    int columnNumber;

    if (objc < 3 || objc > 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "item ?column ?value??");
	return TCL_ERROR;
    }
    if (!(item = FindItem(interp, tv, objv[2])))
	return TCL_ERROR;

    /* Make sure -values exists:
     */
    if (!item->valuesObj) {
	item->valuesObj = Tcl_NewListObj(0,0);
	Tcl_IncrRefCount(item->valuesObj);
    }

    if (objc == 3) {
	/* Return dictionary:
	 */
	Tcl_Obj *result = Tcl_NewListObj(0,0);
	Tcl_Obj *value;
	for (columnNumber = 0; columnNumber < tv->tree.nColumns; ++columnNumber) {
	for (columnNumber=0; columnNumber<tv->tree.nColumns; ++columnNumber) {
	    Tcl_ListObjIndex(interp, item->valuesObj, columnNumber, &value);
	    if (value) {
		Tcl_ListObjAppendElement(NULL, result,
			tv->tree.columns[columnNumber].idObj);
		Tcl_ListObjAppendElement(NULL, result, value);
	    }
	}
3106
3107
3108
3109
3110
3111
3112
3113

3114
3115
3116
3117
3118
3119
3120
2515
2516
2517
2518
2519
2520
2521

2522
2523
2524
2525
2526
2527
2528
2529







-
+







	Tcl_ListObjIndex(interp, item->valuesObj, columnNumber, &result);
	if (!result) {
	    result = Tcl_NewStringObj("",0);
	}
	Tcl_SetObjResult(interp, result);
	return TCL_OK;
    } else {		/* set column */
	Tcl_Size length;
	int length;

	item->valuesObj = unshareObj(item->valuesObj);

	/* Make sure -values is fully populated:
	 */
	Tcl_ListObjLength(interp, item->valuesObj, &length);
	while (length < tv->tree.nColumns) {
3135
3136
3137
3138
3139
3140
3141
3142

3143
3144

3145
3146
3147
3148
3149
3150
3151
2544
2545
2546
2547
2548
2549
2550

2551
2552

2553
2554
2555
2556
2557
2558
2559
2560







-
+

-
+







 * +++ Widget commands -- tree modification.
 */

/* + $tv insert $parent $index ?-id id? ?-option value ...?
 * 	Insert a new item.
 */
static int TreeviewInsertCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *parent, *sibling, *newItem;
    Tcl_HashEntry *entryPtr;
    int isNew;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "parent index ?-id id? -options...");
	return TCL_ERROR;
3184
3185
3186
3187
3188
3189
3190
3191

3192
3193
3194
3195
3196
3197
3198
3199
3200

3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221


3222
3223
3224

3225
3226

3227
3228

3229
3230
3231
3232
3233
3234
3235
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







-
+








-
+












-






-
-
+
+


-
+

-
+

-
+







	    return TCL_ERROR;
	}
	objc -= 2; objv += 2;
    } else {
	char idbuf[16];
	do {
	    ++tv->tree.serial;
	    snprintf(idbuf, sizeof(idbuf), "I%03X", tv->tree.serial);
	    sprintf(idbuf, "I%03X", tv->tree.serial);
	    entryPtr = Tcl_CreateHashEntry(&tv->tree.items, idbuf, &isNew);
	} while (!isNew);
    }

    /* Create and configure new item:
     */
    newItem = NewItem();
    Tk_InitOptions(
	interp, newItem, tv->tree.itemOptionTable, tv->core.tkwin);
	interp, (ClientData)newItem, tv->tree.itemOptionTable, tv->core.tkwin);
    newItem->tagset = Ttk_GetTagSetFromObj(NULL, tv->tree.tagTable, NULL);
    if (ConfigureItem(interp, tv, newItem, objc, objv) != TCL_OK) {
    	Tcl_DeleteHashEntry(entryPtr);
	FreeItem(newItem);
	return TCL_ERROR;
    }

    /* Store in hash table, link into tree:
     */
    Tcl_SetHashValue(entryPtr, newItem);
    newItem->entryPtr = entryPtr;
    InsertItem(parent, sibling, newItem);
    tv->tree.rowPosNeedsUpdate = 1;
    TtkRedisplayWidget(&tv->core);

    Tcl_SetObjResult(interp, ItemID(tv, newItem));
    return TCL_OK;
}

/* + $tv detach $items --
 * 	Unlink each item in $items from the tree.
/* + $tv detach $item --
 * 	Unlink $item from the tree.
 */
static int TreeviewDetachCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem **items;
    Tcl_Size i;
    int i;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    if (!(items = GetItemListFromObj(interp, tv, objv[2]))) {
	return TCL_ERROR;
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316

3317
3318

3319
3320

3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334

3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347

3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385

3386
3387

3388
3389
3390
3391
3392
3393
3394
3395
3396



3397
3398
3399
3400
3401
3402
3403
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







-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
+

-
+

-
+
-












-
+












-
+
-
-
-
-
-
-
-
-
-
















-
-
-
-








-
+

-
+







-
-
+
+
+







	}
    }

    for (i = 0; items[i]; ++i) {
	DetachItem(items[i]);
    }

    tv->tree.rowPosNeedsUpdate = 1;
    TtkRedisplayWidget(&tv->core);
    ckfree(items);
    return TCL_OK;
}

/* Is an item detached? The root is never detached. */
static int IsDetached(Treeview *tv, TreeItem *item)
{
	return item->next == NULL && item->prev == NULL &&
			item->parent == NULL && item != tv->tree.root;
}

/* + $tv detached ?$item? --
 * 	List detached items (in arbitrary order) or query the detached state of
 * 	$item.
 */
static int TreeviewDetachedCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    TreeItem *item;

    if (objc == 2) {
	/* List detached items */
	Tcl_HashSearch search;
	Tcl_HashEntry *entryPtr = Tcl_FirstHashEntry(&tv->tree.items, &search);
	Tcl_Obj *objPtr = Tcl_NewObj();

	while (entryPtr != NULL) {
	    item = (TreeItem *)Tcl_GetHashValue(entryPtr);
	    entryPtr = Tcl_NextHashEntry(&search);
	    if (IsDetached(tv, item)) {
		Tcl_ListObjAppendElement(NULL, objPtr, ItemID(tv, item));
	    }
	}
	Tcl_SetObjResult(interp, objPtr);
	return TCL_OK;
    } else if (objc == 3) {
	/* Query; the root is never reported as detached */
	if (!(item = FindItem(interp, tv, objv[2]))) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(IsDetached(tv, item)));
	return TCL_OK;
    } else {
	Tcl_WrongNumArgs(interp, 2, objv, "?item?");
	return TCL_ERROR;
    }
}
/* + $tv delete $items --
 * 	Delete each item in $items.
 *
 * 	Do this in two passes:
 * 	First detach the item and all its descendants and remove them
 * 	from the hash table.  Free the items themselves in a second pass.
 *
 * 	It's done this way because an item may appear more than once
 *	in the list of items to delete (either directly or as a descendant
 *	of a previously deleted item.)
 */

static int TreeviewDeleteCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem **items, *delq;
    Tcl_Size i;
    int i;
    int selChange = 0;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "items");
	return TCL_ERROR;
    }

    if (!(items = GetItemListFromObj(interp, tv, objv[2]))) {
	return TCL_ERROR;
    }

    /* Sanity-check:
     */
    for (i = 0; items[i]; ++i) {
    for (i=0; items[i]; ++i) {
	if (items[i] == tv->tree.root) {
	    ckfree(items);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Cannot delete root item", -1));
	    Tcl_SetErrorCode(interp, "TTK", "TREE", "ROOT", NULL);
	    return TCL_ERROR;
	}
    }

    /* Remove items from hash table.
     */
    delq = 0;
    for (i = 0; items[i]; ++i) {
    for (i=0; items[i]; ++i) {
        if (items[i]->state & TTK_STATE_SELECTED) {
            selChange = 1;
        } else if (items[i]->selObj != NULL) {
	    Tcl_Size length;
	    Tcl_ListObjLength(interp, items[i]->selObj, &length);
	    if (length > 0) {
		selChange = 1;
	    }
	}
	delq = DeleteItems(items[i], delq);
    }

    /* Free items:
     */
    while (delq) {
	TreeItem *next = delq->next;
	if (tv->tree.focus == delq)
	    tv->tree.focus = 0;
	if (tv->tree.endPtr == delq)
	    tv->tree.endPtr = 0;
	FreeItem(delq);
	delq = next;
    }

    ckfree(items);
    if (selChange) {
        Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL);
    }
    tv->tree.rowPosNeedsUpdate = 1;
    TtkRedisplayWidget(&tv->core);
    return TCL_OK;
}

/* + $tv move $item $parent $index
 * 	Move $item to the specified $index in $parent's child list.
 */
static int TreeviewMoveCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item, *parent;
    TreeItem *sibling;

    if (objc != 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "item parent index");
	return TCL_ERROR;
    }
    if ((item = FindItem(interp, tv, objv[2])) == 0
	    || (parent = FindItem(interp, tv, objv[3])) == 0) {
    if (   (item = FindItem(interp, tv, objv[2])) == 0
	|| (parent = FindItem(interp, tv, objv[3])) == 0)
    {
	return TCL_ERROR;
    }

    /* Locate previous sibling based on $index:
     */
    if (!strcmp(Tcl_GetString(objv[4]), "end")) {
	sibling = EndPosition(tv, parent);
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448

3449
3450

3451
3452
3453
3454
3455

3456
3457

3458
3459
3460
3461
3462
3463
3464
3465

3466
3467

3468
3469

3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490

3491
3492
3493
3494
3495
3496

3497
3498
3499
3500
3501
3502
3503
3504
3505



3506
3507


3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521

3522
3523

3524
3525

3526
3527
3528
3529
3530
3531
3532
3533
3534
3535



3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547

3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581

3582
3583

3584
3585
3586
3587
3588
3589
3590
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







-









-
+

-
+




-
+

-
+







-
+

-
+

-
+
















-



-
+
-
-



-
+
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+













-
+

-
+

-
+








-
-
+
+
+







-
-
-
-

+












-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+

-
+







    }

    /* Move item:
     */
    DetachItem(item);
    InsertItem(parent, sibling, item);

    tv->tree.rowPosNeedsUpdate = 1;
    TtkRedisplayWidget(&tv->core);
    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Widget commands -- scrolling
 */

static int TreeviewXViewCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    return TtkScrollviewCommand(interp, objc, objv, tv->tree.xscrollHandle);
}

static int TreeviewYViewCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    return TtkScrollviewCommand(interp, objc, objv, tv->tree.yscrollHandle);
}

/* $tree see $item --
 * 	Ensure that $item is visible.
 */
static int TreeviewSeeCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    TreeItem *item, *parent;
    int scrollRow1, scrollRow2, visibleRows;
    int rowNumber;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "item");
	return TCL_ERROR;
    }
    if (!(item = FindItem(interp, tv, objv[2]))) {
	return TCL_ERROR;
    }

    /* Make sure all ancestors are open:
     */
    for (parent = item->parent; parent; parent = parent->parent) {
	if (!(parent->state & TTK_STATE_OPEN)) {
	    parent->openObj = unshareObj(parent->openObj);
	    Tcl_SetBooleanObj(parent->openObj, 1);
	    parent->state |= TTK_STATE_OPEN;
	    tv->tree.rowPosNeedsUpdate = 1;
	    TtkRedisplayWidget(&tv->core);
	}
    }
    if (tv->tree.rowPosNeedsUpdate) {
    tv->tree.yscroll.total = CountRows(tv->tree.root) - 1;
	UpdatePositionTree(tv);
    }

    /* Make sure item is visible:
     */
    if (item->rowPos < tv->tree.titleRows) {
    rowNumber = RowNumber(tv, item);
	return TCL_OK;
    }
    visibleRows = tv->tree.treeArea.height / tv->tree.rowHeight
	    - tv->tree.titleRows;
    scrollRow1 = item->rowPos - tv->tree.titleRows;
    scrollRow2 = scrollRow1 + item->height - 1;
    if (scrollRow1 < tv->tree.yscroll.first || item->height > visibleRows) {
	TtkScrollTo(tv->tree.yscrollHandle, scrollRow1, 1);
    } else if (scrollRow2 >= tv->tree.yscroll.first + visibleRows) {
    if (rowNumber < tv->tree.yscroll.first) {
	TtkScrollTo(tv->tree.yscrollHandle, rowNumber);
    } else if (rowNumber >= tv->tree.yscroll.last) {
	scrollRow1 = 1 + scrollRow2 - visibleRows;
	TtkScrollTo(tv->tree.yscrollHandle, scrollRow1, 1);
	TtkScrollTo(tv->tree.yscrollHandle,
	    tv->tree.yscroll.first + (1+rowNumber - tv->tree.yscroll.last));
    }

    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Widget commands -- interactive column resize
 */

/* + $tree drag $column $newX --
 * 	Set right edge of display column $column to x position $X
 */
static int TreeviewDragCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    int left = tv->tree.treeArea.x - tv->tree.xscroll.first;
    Tcl_Size i = FirstColumn(tv);
    int i = FirstColumn(tv);
    TreeColumn *column;
    int newx;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "column xposition");
	return TCL_ERROR;
    }

    if ((column = FindColumn(interp, tv, objv[2])) == 0
	    || Tcl_GetIntFromObj(interp, objv[3], &newx) != TCL_OK) {
    if (  (column = FindColumn(interp, tv, objv[2])) == 0
        || Tcl_GetIntFromObj(interp, objv[3], &newx) != TCL_OK)
    {
	return TCL_ERROR;
    }

    for (;i < tv->tree.nDisplayColumns; ++i) {
	TreeColumn *c = tv->tree.displayColumns[i];
	int right = left + c->width;
	if (c == column) {
	    if (i < tv->tree.nTitleColumns) {
		/* Unscrollable column, remove scroll shift */
		right += tv->tree.xscroll.first;
	    }
	    DragColumn(tv, i, newx - right);
	    /* ASSERT: SLACKINVARIANT */
	    TtkRedisplayWidget(&tv->core);
	    return TCL_OK;
	}
	left = right;
    }

    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	"column %s is not displayed", Tcl_GetString(objv[2])));
    Tcl_SetErrorCode(interp, "TTK", "TREE", "COLUMN_INVISIBLE", NULL);
    return TCL_ERROR;
}

static int TreeviewDropCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "drop");
	return TCL_ERROR;
    }
    ResizeColumns(tv, TreeWidth(tv));
    TtkRedisplayWidget(&tv->core);
    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Widget commands -- focus and selection
 */

/* + $tree focus ?item?
 */
static int TreeviewFocusCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;

    if (objc == 2) {
	if (tv->tree.focus) {
	    Tcl_SetObjResult(interp, ItemID(tv, tv->tree.focus));
	}
	return TCL_OK;
    } else if (objc == 3) {
3599
3600
3601
3602
3603
3604
3605
3606

3607
3608
3609
3610
3611

3612
3613
3614
3615
3616


3617
3618
3619
3620
3621

3622
3623
3624
3625
3626
3627
3628
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







-
+




-
+



-
-
+
+




-
+







	return TCL_ERROR;
    }
}

/* + $tree selection ?add|remove|set|toggle $items?
 */
static int TreeviewSelectionCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    enum {
	SELECTION_SET, SELECTION_ADD, SELECTION_REMOVE, SELECTION_TOGGLE
    };
    static const char *const selopStrings[] = {
    static const char *selopStrings[] = {
	"set", "add", "remove", "toggle", NULL
    };

    Treeview *tv = (Treeview *)recordPtr;
    int selop, i, selChange = 0;
    Treeview *tv = recordPtr;
    int selop, i;
    TreeItem *item, **items;

    if (objc == 2) {
	Tcl_Obj *result = Tcl_NewListObj(0,0);
	for (item = tv->tree.root->children; item; item = NextPreorder(item)) {
	for (item = tv->tree.root->children; item; item=NextPreorder(item)) {
	    if (item->state & TTK_STATE_SELECTED)
		Tcl_ListObjAppendElement(NULL, result, ItemID(tv, item));
	}
	Tcl_SetObjResult(interp, result);
	return TCL_OK;
    }

3640
3641
3642
3643
3644
3645
3646
3647
3648

3649
3650

3651
3652

3653
3654
3655
3656
3657
3658

3659
3660
3661
3662

3663
3664
3665
3666
3667
3668
3669
3670

3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685

3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944

3945
3946

3947
3948
3949
3950
3951
3952
3953
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







-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
+


-
-
+
-
-




-
-
+
-
-





-





-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+

-
+







    if (!items) {
	return TCL_ERROR;
    }

    switch (selop)
    {
	case SELECTION_SET:
	    /* Clear */
	    for (item=tv->tree.root; item; item = NextPreorder(item)) {
	    for (item=tv->tree.root; item; item=NextPreorder(item)) {
		if (item->state & TTK_STATE_SELECTED) {
		    item->state &= ~TTK_STATE_SELECTED;
		item->state &= ~TTK_STATE_SELECTED;
		    selChange = 1;
		}
	    }
	    }
	    for (i=0; items[i]; ++i) {
		items[i]->state |= TTK_STATE_SELECTED;
		selChange = 1;
	    }
	    break;
	    /*FALLTHRU*/
	case SELECTION_ADD:
	    for (i=0; items[i]; ++i) {
		if (!(items[i]->state & TTK_STATE_SELECTED)) {
		    items[i]->state |= TTK_STATE_SELECTED;
		items[i]->state |= TTK_STATE_SELECTED;
		    selChange = 1;
		}
	    }
	    break;
	case SELECTION_REMOVE:
	    for (i=0; items[i]; ++i) {
		if (items[i]->state & TTK_STATE_SELECTED) {
		    items[i]->state &= ~TTK_STATE_SELECTED;
		items[i]->state &= ~TTK_STATE_SELECTED;
		    selChange = 1;
		}
	    }
	    break;
	case SELECTION_TOGGLE:
	    for (i=0; items[i]; ++i) {
		items[i]->state ^= TTK_STATE_SELECTED;
		selChange = 1;
	    }
	    break;
    }

    ckfree(items);
    if (selChange) {
	Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL);
    TtkSendVirtualEvent(tv->core.tkwin, "TreeviewSelect");
    }
    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/* + SelObjChangeElement --
 * 	Change an element in a cell selection list.
 */
static int SelObjChangeElement(
    Treeview *tv, Tcl_Obj *listPtr, Tcl_Obj *elemPtr,
    int add,
    TCL_UNUSED(int) /*remove*/,
    int toggle)
{
    Tcl_Size i, nElements;
    int anyChange = 0;
    TreeColumn *column, *elemColumn;
    Tcl_Obj **elements;

    elemColumn = FindColumn(NULL, tv, elemPtr);
    Tcl_ListObjGetElements(NULL, listPtr, &nElements, &elements);
    for (i = 0; i < nElements; i++) {
	column = FindColumn(NULL, tv, elements[i]);
	if (column == elemColumn) {
	    if (add) {
		return anyChange;
	    }
	    Tcl_ListObjReplace(NULL, listPtr, i, 1, 0, NULL);
	    anyChange = 1;
	    return anyChange;
	}
    }
    if (add || toggle) {
	Tcl_ListObjAppendElement(NULL, listPtr, elemColumn->idObj);
	anyChange = 1;
    }
    return anyChange;
}

/* + $tree cellselection ?add|remove|set|toggle $items?
 */
static int CellSelectionRange(
    Tcl_Interp *interp, Treeview *tv, Tcl_Obj *fromCell, Tcl_Obj *toCell,
    int add, int remove, int toggle)
{
    TreeCell cellFrom, cellTo;
    TreeItem *item;
    Tcl_Obj *columns, **elements;
    int colno, fromNo, toNo, anyChange = 0;
    Tcl_Size i, nElements;
    int set = !(add || remove || toggle);

    if (GetCellFromObj(interp, tv, fromCell, 1, &fromNo, &cellFrom)
	    != TCL_OK) {
	return TCL_ERROR;
    }
    if (GetCellFromObj(interp, tv, toCell, 1, &toNo, &cellTo)
	    != TCL_OK) {
	return TCL_ERROR;
    }

    /* Correct order.
     */
    if (fromNo > toNo) {
	colno = fromNo;
	fromNo = toNo;
	toNo = colno;
    }

    /* Make a list of columns in this rectangle.
     */
    columns = Tcl_NewListObj(0, 0);
    Tcl_IncrRefCount(columns);
    for (colno = fromNo; colno <= toNo; colno++) {
	Tcl_ListObjAppendElement(NULL, columns,
		tv->tree.displayColumns[colno]->idObj);
    }

    /* Set is the only operation that affects items outside its rectangle.
     * Start with clearing out.
     */
    if (set) {
	anyChange = CellSelectionClear(tv);
    }

    /* Correct order.
     */
    if (tv->tree.rowPosNeedsUpdate) {
	UpdatePositionTree(tv);
    }
    if (cellFrom.item->itemPos > cellTo.item->itemPos) {
	item = cellFrom.item;
	cellFrom.item = cellTo.item;
	cellTo.item = item;
    }

    /* Go through all items in this rectangle.
     */
    for (item = cellFrom.item; item; item = NextPreorder(item)) {
	if (item->selObj != NULL) {
	    item->selObj = unshareObj(item->selObj);

	    Tcl_ListObjGetElements(NULL, columns, &nElements, &elements);
	    for (i = 0; i < nElements; ++i) {
		anyChange |= SelObjChangeElement(tv, item->selObj, elements[i],
			add, remove, toggle);
	    }
	} else {
	    /* Set, add and toggle do the same thing when empty before.
	     */
	    if (!remove) {
		item->selObj = columns;
		Tcl_IncrRefCount(item->selObj);
		anyChange = 1;
	    }
	}
	if (item == cellTo.item) {
	    break;
	}
    }

    Tcl_DecrRefCount(columns);

    if (anyChange) {
	Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL);
    }
    TtkRedisplayWidget(&tv->core);
    return TCL_OK;
}

/* + $tree cellselection ?add|remove|set|toggle $items?
 */
static int TreeviewCellSelectionCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    enum {
	SELECTION_SET, SELECTION_ADD, SELECTION_REMOVE, SELECTION_TOGGLE
    };
    static const char *const selopStrings[] = {
	"set", "add", "remove", "toggle", NULL
    };

    Treeview *tv = (Treeview *)recordPtr;
    int selop, anyChange = 0;
    Tcl_Size i, nCells;
    TreeCell *cells;
    TreeItem *item;

    if (objc == 2) {
	Tcl_Obj *result = Tcl_NewListObj(0,0);
	for (item = tv->tree.root->children; item; item = NextPreorder(item)) {
	    if (item->selObj != NULL) {
		Tcl_Size n, elemc;
		Tcl_Obj **elemv;

		Tcl_ListObjGetElements(interp, item->selObj, &n, &elemv);
		elemc = n;
		for (i = 0; i < elemc; ++i) {
		    Tcl_Obj *elem[2];
		    elem[0] = ItemID(tv, item);
		    elem[1] = elemv[i];
		    Tcl_ListObjAppendElement(NULL, result,
			    Tcl_NewListObj(2, elem));
		}
	    }
	}
	Tcl_SetObjResult(interp, result);
	return TCL_OK;
    }

    if (objc < 4 || objc > 5) {
    	Tcl_WrongNumArgs(interp, 2, objv, "?add|remove|set|toggle arg...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[2], selopStrings,
	    sizeof(char *), "cellselection operation", 0, &selop) != TCL_OK) {
	return TCL_ERROR;
    }

    if (objc == 5) {
	switch (selop)
	{
	    case SELECTION_SET:
		return CellSelectionRange(interp, tv, objv[3], objv[4], 0, 0, 0);
	    case SELECTION_ADD:
		return CellSelectionRange(interp, tv, objv[3], objv[4], 1, 0, 0);
	    case SELECTION_REMOVE:
		return CellSelectionRange(interp, tv, objv[3], objv[4], 0, 1, 0);
	    case SELECTION_TOGGLE:
		return CellSelectionRange(interp, tv, objv[3], objv[4], 0, 0, 1);
	}
    }

    cells = GetCellListFromObj(interp, tv, objv[3], &nCells);
    if (cells == NULL) {
	return TCL_ERROR;
    }

    switch (selop)
    {
	case SELECTION_SET:
	    anyChange = CellSelectionClear(tv);
	    /*FALLTHRU*/
	case SELECTION_ADD:
	    for (i = 0; i < nCells; i++) {
		item = cells[i].item;
		if (item->selObj == NULL) {
		    item->selObj = Tcl_NewListObj(0, 0);
		    Tcl_IncrRefCount(item->selObj);
		}
		item->selObj = unshareObj(item->selObj);
		anyChange |= SelObjChangeElement(tv, item->selObj,
			cells[i].colObj, 1, 0, 0);
	    }
	    break;
	case SELECTION_REMOVE:
	    for (i = 0; i < nCells; i++) {
		item = cells[i].item;
		if (item->selObj == NULL) {
		    continue;
		}
		item->selObj = unshareObj(item->selObj);
		anyChange |= SelObjChangeElement(tv, item->selObj,
			cells[i].colObj, 0, 1, 0);
	    }
	    break;
	case SELECTION_TOGGLE:
	    for (i = 0; i < nCells; i++) {
		item = cells[i].item;
		if (item->selObj == NULL) {
		    item->selObj = Tcl_NewListObj(0, 0);
		    Tcl_IncrRefCount(item->selObj);
		}
		item->selObj = unshareObj(item->selObj);
		anyChange = SelObjChangeElement(tv, item->selObj,
			cells[i].colObj, 0, 0, 1);
	    }
	    break;
    }

    ckfree(cells);
    if (anyChange) {
	Tk_SendVirtualEvent(tv->core.tkwin, "TreeviewSelect", NULL);
    }
    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/*------------------------------------------------------------------------
 * +++ Widget commands -- tags and bindings.
 */

/* + $tv tag bind $tag ?$sequence ?$script??
 */
static int TreeviewTagBindCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Ttk_TagTable tagTable = tv->tree.tagTable;
    Tk_BindingTable bindingTable = tv->tree.bindingTable;
    Ttk_Tag tag;

    if (objc < 4 || objc > 6) {
    	Tcl_WrongNumArgs(interp, 3, objv, "tagName ?sequence? ?script?");
	return TCL_ERROR;
3990
3991
3992
3993
3994
3995
3996
3997

3998
3999

4000
4001
4002
4003
4004

4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058

4059
4060

4061
4062
4063
4064
4065
4066
4067
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







-
+

-
+




-
+




















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+

-
+







    }
    return TCL_OK;
}

/* + $tv tag configure $tag ?-option ?value -option value...??
 */
static int TreeviewTagConfigureCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Ttk_TagTable tagTable = tv->tree.tagTable;
    Ttk_Tag tag;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 3, objv, "tagName ?-option ?value ...??");
    	Tcl_WrongNumArgs(interp, 3, objv, "tagName ?-option ?value ...??");
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tagTable, objv[3]);

    if (objc == 4) {
	return Ttk_EnumerateTagOptions(interp, tagTable, tag);
    } else if (objc == 5) {
	Tcl_Obj *result = Ttk_TagOptionValue(interp, tagTable, tag, objv[4]);
	if (result) {
	    Tcl_SetObjResult(interp, result);
	    return TCL_OK;
	} /* else */
	return TCL_ERROR;
    }
    /* else */
    TtkRedisplayWidget(&tv->core);
    return Ttk_ConfigureTag(interp, tagTable, tag, objc - 4, objv + 4);
}

/* + $tv tag delete $tag
 */
static int TreeviewTagDeleteCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Ttk_TagTable tagTable = tv->tree.tagTable;
    TreeItem *item = tv->tree.root;
    Ttk_Tag tag;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 3, objv, "tagName");
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tagTable, objv[3]);
    /* remove the tag from all cells and items */
    while (item) {
        RemoveTagFromCellsAtItem(item, tag);
	RemoveTag(item, tag);
	item = NextPreorder(item);
    }
    /* then remove the tag from the tag table */
    Tk_DeleteAllBindings(tv->tree.bindingTable, tag);
    Ttk_DeleteTagFromTable(tagTable, tag);
    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/* + $tv tag has $tag ?$item?
 */
static int TreeviewTagHasCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;

    if (objc == 4) {	/* Return list of all items with tag */
	Ttk_Tag tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[3]);
	TreeItem *item = tv->tree.root;
	Tcl_Obj *result = Tcl_NewListObj(0,0);

	while (item) {
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153

4154
4155
4156

4157
4158

4159
4160
4161
4162
4163
4164
4165
3116
3117
3118
3119
3120
3121
3122































































3123
3124
3125

3126
3127

3128
3129
3130
3131
3132
3133
3134
3135







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
+

-
+







	return TCL_OK;
    } else {
    	Tcl_WrongNumArgs(interp, 3, objv, "tagName ?item?");
	return TCL_ERROR;
    }
}

/* + $tv tag cell has $tag ?$cell?
 */
static int TreeviewCtagHasCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    TreeCell cell;
    Tcl_Size i, columnNumber;

    if (objc == 5) {	/* Return list of all cells with tag */
	Ttk_Tag tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[4]);
	TreeItem *item = tv->tree.root;
	Tcl_Obj *result = Tcl_NewListObj(0,0);

	while (item) {
	    for (i = 0; i < item->nTagSets && i <= tv->tree.nColumns; ++i) {
		if (item->cellTagSets[i] != NULL) {
		    if (Ttk_TagSetContains(item->cellTagSets[i], tag)) {
			Tcl_Obj *elem[2];
			elem[0] = ItemID(tv, item);
			if (i == 0) {
			    elem[1] = tv->tree.column0.idObj;
			} else {
			    elem[1] = tv->tree.columns[i-1].idObj;
			}
			Tcl_ListObjAppendElement(NULL, result,
				Tcl_NewListObj(2, elem));
		    }
		}
	    }
	    item = NextPreorder(item);
	}

	Tcl_SetObjResult(interp, result);
	return TCL_OK;
    } else if (objc == 6) {	/* Test if cell has specified tag */
	Ttk_Tag tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[4]);
	int result = 0;
	if (GetCellFromObj(interp, tv, objv[5], 0, NULL, &cell) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (cell.column == &tv->tree.column0) {
	    columnNumber = 0;
	} else {
	    columnNumber = cell.column - tv->tree.columns + 1;
	}
	if (columnNumber < cell.item->nTagSets) {
	    if (cell.item->cellTagSets[columnNumber] != NULL) {
		result = Ttk_TagSetContains(
			cell.item->cellTagSets[columnNumber],
			tag);
	    }
	}

	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(result));
	return TCL_OK;
    } else {
    	Tcl_WrongNumArgs(interp, 4, objv, "tagName ?cell?");
	return TCL_ERROR;
    }
}

/* + $tv tag names
/* + $tv tag names $tag
 */
static int TreeviewTagNamesCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 3, objv, "");
	return TCL_ERROR;
    }

    return Ttk_EnumerateTags(interp, tv->tree.tagTable);
4173
4174
4175
4176
4177
4178
4179
4180

4181
4182

4183
4184
4185

4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199

4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298

4299
4300

4301
4302
4303
4304


4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317

4318
4319
4320
4321
4322
4323
4324
4325

4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422

4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443

4444
4445
4446
4447
4448
4449
4450
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
3171

3172
































































3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188













3189

3190
3191

3192
3193
3194


3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208

3209
3210
3211

3212
3213
3214
3215

3216
3217
3218
3219
3220
3221
3222
3223
3224























































3225
3226
3227

3228

3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239

3240
3241
3242
3243
3244
3245

3246

3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262

3263
3264
3265
3266
3267
3268
3269
3270
3271
3272

3273
3274
3275
3276
3277
3278
3279
3280







-
+

-
+


-
+













-
+


-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+


-
-
+
+












-
+


-




-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-

-











-






-

-





-

+









-










-
+







	if (item->tagsObj) Tcl_DecrRefCount(item->tagsObj);
	item->tagsObj = Ttk_NewTagSetObj(item->tagset);
	Tcl_IncrRefCount(item->tagsObj);
    }
}

static int TreeviewTagAddCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Ttk_Tag tag;
    TreeItem **items;
    Tcl_Size i;
    int i;

    if (objc != 5) {
	Tcl_WrongNumArgs(interp, 3, objv, "tagName items");
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[3]);
    items = GetItemListFromObj(interp, tv, objv[4]);

    if (!items) {
	return TCL_ERROR;
    }

    for (i = 0; items[i]; ++i) {
    for (i=0; items[i]; ++i) {
	AddTag(items[i], tag);
    }
    ckfree(items);

    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/* Make sure tagset at column is allocated and initialised */
static void AllocCellTagSets(Treeview *tv, TreeItem *item, Tcl_Size columnNumber)
{
    Tcl_Size i, newSize = MAX(columnNumber + 1, tv->tree.nColumns + 1);
    if (item->nTagSets < newSize) {
	if (item->cellTagSets == NULL) {
	    item->cellTagSets = (Ttk_TagSet *)
		    ckalloc(sizeof(Ttk_TagSet)*newSize);
	} else {
	    item->cellTagSets = (Ttk_TagSet *)
		    ckrealloc(item->cellTagSets, sizeof(Ttk_TagSet) * newSize);
	}
	for (i = item->nTagSets; i < newSize; i++) {
	    item->cellTagSets[i] = NULL;
	}
	item->nTagSets = newSize;
    }

    if (item->cellTagSets[columnNumber] == NULL) {
	item->cellTagSets[columnNumber] =
		Ttk_GetTagSetFromObj(NULL, tv->tree.tagTable, NULL);
    }
}

/* + $tv tag cell add $tag $cells
 */
static int TreeviewCtagAddCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Ttk_Tag tag;
    TreeCell *cells;
    TreeItem *item;
    Tcl_Size i, nCells, columnNumber;

    if (objc != 6) {
	Tcl_WrongNumArgs(interp, 4, objv, "tagName cells");
	return TCL_ERROR;
    }

    cells = GetCellListFromObj(interp, tv, objv[5], &nCells);
    if (cells == NULL) {
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[4]);

    for (i = 0; i < nCells; i++) {
	if (cells[i].column == &tv->tree.column0) {
	    columnNumber = 0;
	} else {
	    columnNumber = cells[i].column - tv->tree.columns  + 1;
	}
	item = cells[i].item;
	AllocCellTagSets(tv, item, columnNumber);
	Ttk_TagSetAdd(item->cellTagSets[columnNumber], tag);
    }

    ckfree(cells);
    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/* + $tv tag remove $tag ?$items?
 */
static void RemoveTag(TreeItem *item, Ttk_Tag tag)
{
    if (Ttk_TagSetRemove(item->tagset, tag)) {
	if (item->tagsObj) Tcl_DecrRefCount(item->tagsObj);
	item->tagsObj = Ttk_NewTagSetObj(item->tagset);
	Tcl_IncrRefCount(item->tagsObj);
    }
}

/* Remove tag from all cells at row 'item'
 */
static void RemoveTagFromCellsAtItem(TreeItem *item, Ttk_Tag tag)
{
    Tcl_Size i;

    for (i = 0; i < item->nTagSets; i++) {
        if (item->cellTagSets[i] != NULL) {
            Ttk_TagSetRemove(item->cellTagSets[i], tag);
        }
    }
}

static int TreeviewTagRemoveCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Treeview *tv = recordPtr;
    Ttk_Tag tag;

    if (objc < 4 || objc > 5) {
	Tcl_WrongNumArgs(interp, 3, objv, "tagName ?items?");
    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 3, objv, "tagName items");
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[3]);

    if (objc == 5) {
	TreeItem **items = GetItemListFromObj(interp, tv, objv[4]);
	int i;

	if (!items) {
	    return TCL_ERROR;
	}
	for (i = 0; items[i]; ++i) {
	for (i=0; items[i]; ++i) {
	    RemoveTag(items[i], tag);
	}
	ckfree(items);
    } else if (objc == 4) {
	TreeItem *item = tv->tree.root;
	while (item) {
	    RemoveTag(item, tag);
	    item = NextPreorder(item);
	    item=NextPreorder(item);
	}
    }

    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

/* + $tv tag cell remove $tag ?$cells?
 */
static int TreeviewCtagRemoveCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    Treeview *tv = (Treeview *)recordPtr;
    Ttk_Tag tag;
    TreeCell *cells;
    TreeItem *item;
    Tcl_Size i, nCells, columnNumber;

    if (objc < 5 || objc > 6) {
	Tcl_WrongNumArgs(interp, 4, objv, "tagName ?cells?");
	return TCL_ERROR;
    }

    tag = Ttk_GetTagFromObj(tv->tree.tagTable, objv[4]);

    if (objc == 6) {
	cells = GetCellListFromObj(interp, tv, objv[5], &nCells);
	if (cells == NULL) {
	    return TCL_ERROR;
	}

	for (i = 0; i < nCells; i++) {
	    if (cells[i].column == &tv->tree.column0) {
		columnNumber = 0;
	    } else {
		columnNumber = cells[i].column - tv->tree.columns  + 1;
	    }
	    item = cells[i].item;
	    AllocCellTagSets(tv, item, columnNumber);
	    Ttk_TagSetRemove(item->cellTagSets[columnNumber], tag);
	}
	ckfree(cells);
    } else {
	item = tv->tree.root;
	while (item) {
            RemoveTagFromCellsAtItem(item, tag);
	    item = NextPreorder(item);
	}
    }

    TtkRedisplayWidget(&tv->core);

    return TCL_OK;
}

static const Ttk_Ensemble TreeviewCtagCommands[] = {
    { "add",		TreeviewCtagAddCommand,0 },
    { "has",		TreeviewCtagHasCommand,0 },
    { "remove",		TreeviewCtagRemoveCommand,0 },
    { 0,0,0 }
};

static const Ttk_Ensemble TreeviewTagCommands[] = {
    { "add",		TreeviewTagAddCommand,0 },
    { "bind",		TreeviewTagBindCommand,0 },
    { "cell",    	0,TreeviewCtagCommands },
    { "configure",	TreeviewTagConfigureCommand,0 },
    { "delete",		TreeviewTagDeleteCommand,0 },
    { "has",		TreeviewTagHasCommand,0 },
    { "names",		TreeviewTagNamesCommand,0 },
    { "remove",		TreeviewTagRemoveCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Widget commands record.
 */
static const Ttk_Ensemble TreeviewCommands[] = {
    { "bbox",  		TreeviewBBoxCommand,0 },
    { "cellselection" ,	TreeviewCellSelectionCommand,0 },
    { "children",	TreeviewChildrenCommand,0 },
    { "cget",		TtkWidgetCgetCommand,0 },
    { "column", 	TreeviewColumnCommand,0 },
    { "configure",	TtkWidgetConfigureCommand,0 },
    { "delete", 	TreeviewDeleteCommand,0 },
    { "detach", 	TreeviewDetachCommand,0 },
    { "detached", 	TreeviewDetachedCommand,0 },
    { "drag",   	TreeviewDragCommand,0 },
    { "drop",   	TreeviewDropCommand,0 },
    { "exists", 	TreeviewExistsCommand,0 },
    { "focus", 		TreeviewFocusCommand,0 },
    { "heading", 	TreeviewHeadingCommand,0 },
    { "identify",  	TreeviewIdentifyCommand,0 },
    { "index",  	TreeviewIndexCommand,0 },
    { "insert", 	TreeviewInsertCommand,0 },
    { "instate",	TtkWidgetInstateCommand,0 },
    { "insert", 	TreeviewInsertCommand,0 },
    { "item", 		TreeviewItemCommand,0 },
    { "move", 		TreeviewMoveCommand,0 },
    { "next", 		TreeviewNextCommand,0 },
    { "parent", 	TreeviewParentCommand,0 },
    { "prev", 		TreeviewPrevCommand,0 },
    { "see", 		TreeviewSeeCommand,0 },
    { "selection" ,	TreeviewSelectionCommand,0 },
    { "set",  		TreeviewSetCommand,0 },
    { "state",  	TtkWidgetStateCommand,0 },
    { "style",		TtkWidgetStyleCommand,0 },
    { "tag",    	0,TreeviewTagCommands },
    { "xview",  	TreeviewXViewCommand,0 },
    { "yview",  	TreeviewYViewCommand,0 },
    { 0,0,0 }
};

/*------------------------------------------------------------------------
 * +++ Widget definition.
 */

static const WidgetSpec TreeviewWidgetSpec = {
static WidgetSpec TreeviewWidgetSpec = {
    "Treeview",			/* className */
    sizeof(Treeview),   	/* recordSize */
    TreeviewOptionSpecs,	/* optionSpecs */
    TreeviewCommands,   	/* subcommands */
    TreeviewInitialize,   	/* initializeProc */
    TreeviewCleanup,		/* cleanupProc */
    TreeviewConfigure,    	/* configureProc */
4466
4467
4468
4469
4470
4471
4472

4473

4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505

4506
4507

4508
4509

4510
4511
4512


4513
4514
4515
4516
4517

4518
4519

4520
4521
4522
4523

4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536

4537
4538

4539
4540
4541
4542

4543
4544
4545
4546
4547
4548
4549
3296
3297
3298
3299
3300
3301
3302
3303

3304
3305
3306
3307

3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319



3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331

3332
3333

3334
3335

3336
3337


3338
3339
3340
3341
3342


3343


3344


3345

3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357


3358


3359


3360

3361
3362
3363
3364
3365
3366
3367
3368







+
-
+



-












-
-
-












-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+











-
-
+
-
-
+
-
-

-
+







	TTK_GROUP("Treeview.padding", TTK_FILL_BOTH,
	    TTK_NODE("Treeview.treearea", TTK_FILL_BOTH))))

TTK_LAYOUT("Item",
    TTK_GROUP("Treeitem.padding", TTK_FILL_BOTH,
	TTK_NODE("Treeitem.indicator", TTK_PACK_LEFT)
	TTK_NODE("Treeitem.image", TTK_PACK_LEFT)
	TTK_GROUP("Treeitem.focus", TTK_PACK_LEFT,
	TTK_NODE("Treeitem.text", TTK_FILL_BOTH)))
	    TTK_NODE("Treeitem.text", TTK_PACK_LEFT))))

TTK_LAYOUT("Cell",
    TTK_GROUP("Treedata.padding", TTK_FILL_BOTH,
	TTK_NODE("Treeitem.image", TTK_PACK_LEFT)
	TTK_NODE("Treeitem.text", TTK_FILL_BOTH)))

TTK_LAYOUT("Heading",
    TTK_NODE("Treeheading.cell", TTK_FILL_BOTH)
    TTK_GROUP("Treeheading.border", TTK_FILL_BOTH,
	TTK_GROUP("Treeheading.padding", TTK_FILL_BOTH,
	    TTK_NODE("Treeheading.image", TTK_PACK_RIGHT)
	    TTK_NODE("Treeheading.text", TTK_FILL_X))))

TTK_LAYOUT("Row",
    TTK_NODE("Treeitem.row", TTK_FILL_BOTH))

TTK_LAYOUT("Separator",
    TTK_NODE("Treeitem.separator", TTK_FILL_BOTH))

TTK_END_LAYOUT_TABLE

/*------------------------------------------------------------------------
 * +++ Tree indicator element.
 */

typedef struct {
    Tcl_Obj *colorObj;
    Tcl_Obj *sizeObj;
    Tcl_Obj *marginsObj;
} TreeitemIndicator;

static const Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = {
static Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = {
    { "-foreground", TK_OPTION_COLOR,
	offsetof(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND },
	Tk_Offset(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND },
    { "-indicatorsize", TK_OPTION_PIXELS,
	offsetof(TreeitemIndicator,sizeObj), "12" },
	Tk_Offset(TreeitemIndicator,sizeObj), "12" },
    { "-indicatormargins", TK_OPTION_STRING,
	offsetof(TreeitemIndicator,marginsObj), "2 2 4 2" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(TreeitemIndicator,marginsObj), "2 2 4 2" },
    { NULL, 0, 0, NULL }
};

static void TreeitemIndicatorSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord;
    TreeitemIndicator *indicator = elementRecord;
    Ttk_Padding margins;
    int size = 0;

    Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginsObj, &margins);
    Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);

    *widthPtr = size + Ttk_PaddingWidth(margins);
    *heightPtr = size + Ttk_PaddingHeight(margins);
}

static void TreeitemIndicatorDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord;
    TreeitemIndicator *indicator = elementRecord;
    ArrowDirection direction =
	(state & TTK_STATE_OPEN) ? ARROW_DOWN : ARROW_RIGHT;
    Ttk_Padding margins;
    XColor *borderColor = Tk_GetColorFromObj(tkwin, indicator->colorObj);
    XGCValues gcvalues; GC gc; unsigned mask;

    if (state & TTK_STATE_LEAF) /* don't draw anything */
4558
4559
4560
4561
4562
4563
4564
4565

4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582

4583
4584

4585
4586
4587


4588
4589
4590
4591
4592

4593
4594

4595
4596
4597
4598

4599
4600
4601
4602
4603
4604
4605
4606

4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
3377
3378
3379
3380
3381
3382
3383

3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400

3401
3402

3403
3404


3405
3406
3407
3408
3409


3410


3411


3412

3413
3414
3415

3416
3417
3418
3419

3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431



3432
3433
3434
3435
3436
3437
3438
3439
3440
3441

3442
3443
3444
3445
3446
3447
3448







-
+
















-
+

-
+

-
-
+
+



-
-
+
-
-
+
-
-

-
+


-




-
+











-
-
-










-







    gc = Tk_GetGC(tkwin, mask, &gcvalues);

    TtkDrawArrow(Tk_Display(tkwin), d, gc, b, direction);

    Tk_FreeGC(Tk_Display(tkwin), gc);
}

static const Ttk_ElementSpec TreeitemIndicatorElementSpec = {
static Ttk_ElementSpec TreeitemIndicatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TreeitemIndicator),
    TreeitemIndicatorOptions,
    TreeitemIndicatorSize,
    TreeitemIndicatorDraw
};

/*------------------------------------------------------------------------
 * +++ Row element.
 */

typedef struct {
    Tcl_Obj *backgroundObj;
    Tcl_Obj *rowNumberObj;
} RowElement;

static const Ttk_ElementOptionSpec RowElementOptions[] = {
static Ttk_ElementOptionSpec RowElementOptions[] = {
    { "-background", TK_OPTION_COLOR,
	offsetof(RowElement,backgroundObj), DEFAULT_BACKGROUND },
	Tk_Offset(RowElement,backgroundObj), DEFAULT_BACKGROUND },
    { "-rownumber", TK_OPTION_INT,
	offsetof(RowElement,rowNumberObj), "0" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
	Tk_Offset(RowElement,rowNumberObj), "0" },
    { NULL, 0, 0, NULL }
};

static void RowElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    RowElement *row = (RowElement *)elementRecord;
    RowElement *row = elementRecord;
    XColor *color = Tk_GetColorFromObj(tkwin, row->backgroundObj);
    GC gc = Tk_GCForColor(color, d);

    XFillRectangle(Tk_Display(tkwin), d, gc,
	    b.x, b.y, b.width, b.height);
}

static const Ttk_ElementSpec RowElementSpec = {
static Ttk_ElementSpec RowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(RowElement),
    RowElementOptions,
    TtkNullElementSize,
    RowElementDraw
};

/*------------------------------------------------------------------------
 * +++ Initialisation.
 */

MODULE_SCOPE
void TtkTreeview_Init(Tcl_Interp *interp);

MODULE_SCOPE
void TtkTreeview_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme = Ttk_GetDefaultTheme(interp);

    RegisterWidget(interp, "ttk::treeview", &TreeviewWidgetSpec);

    Ttk_RegisterElement(interp, theme, "Treeitem.indicator",
	    &TreeitemIndicatorElementSpec, 0);
    Ttk_RegisterElement(interp, theme, "Treeitem.row", &RowElementSpec, 0);
    Ttk_RegisterElement(interp, theme, "Treeitem.separator", &RowElementSpec, 0);
    Ttk_RegisterElement(interp, theme, "Treeheading.cell", &RowElementSpec, 0);
    Ttk_RegisterElement(interp, theme, "treearea", &ttkNullElementSpec, 0);

    Ttk_RegisterLayouts(theme, LayoutTable);
}

/*EOF*/

Changes to generic/ttk/ttkWidget.c.

1
2

3
4
5
6

7
8


9




10
11
12
13
14
15
16
1

2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21

-
+




+
-
-
+
+

+
+
+
+







/*
 * Copyright © 2003, Joe English
 * Copyright (c) 2003, Joe English
 *
 * Core widget utilities.
 */

#include <string.h>
#include "tkInt.h"
#include "ttkThemeInt.h"
#include <tk.h>
#include "ttkTheme.h"
#include "ttkWidget.h"

#ifdef MAC_OSX_TK
#define TK_NO_DOUBLE_BUFFERING 1
#endif

/*------------------------------------------------------------------------
 * +++ Internal helper routines.
 */

/* UpdateLayout --
 * 	Call the widget's get-layout hook to recompute corePtr->layout.
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94

95
96

97
98
99
100
101
102
103
82
83
84
85
86
87
88

89




90
91
92
93
94

95
96

97
98
99
100
101
102
103
104







-
+
-
-
-
-





-
+

-
+








    Tk_FreePixmap(Tk_Display(tkwin), d);
    Tk_FreeGC(Tk_Display(tkwin), gc);
}
#else
/* No double-buffering: draw directly into the window. */
static Drawable BeginDrawing(Tk_Window tkwin) { return Tk_WindowId(tkwin); }
static void EndDrawing(
static void EndDrawing(Tk_Window tkwin, Drawable d) { }
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(Drawable))
{
}
#endif

/* DrawWidget --
 *	Redraw a widget.  Called as an idle handler.
 */
static void DrawWidget(void *recordPtr)
static void DrawWidget(ClientData recordPtr)
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;

    corePtr->flags &= ~REDISPLAY_PENDING;
    if (Tk_IsMapped(corePtr->tkwin)) {
	Drawable d = BeginDrawing(corePtr->tkwin);
	corePtr->widgetSpec->layoutProc(recordPtr);
	corePtr->widgetSpec->displayProc(recordPtr, d);
	EndDrawing(corePtr->tkwin, d);
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168

169
170
171
172
173
174
175
116
117
118
119
120
121
122














123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155

156
157
158
159
160
161
162
163







-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+
+




















-
+

-
+








    if (!(corePtr->flags & REDISPLAY_PENDING)) {
	Tcl_DoWhenIdle(DrawWidget, corePtr);
	corePtr->flags |= REDISPLAY_PENDING;
    }
}

/*
 * WidgetWorldChanged --
 * 	Default Tk_ClassWorldChangedProc() for widgets.
 * 	Invoked whenever fonts or other system resources are changed;
 * 	recomputes geometry.
 */
static void WidgetWorldChanged(void *clientData)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    (void)UpdateLayout(corePtr->interp, corePtr);
    SizeChanged(corePtr);
    TtkRedisplayWidget(corePtr);
}

/* TtkResizeWidget --
 * 	Recompute widget size, schedule geometry propagation and redisplay.
 */
void TtkResizeWidget(WidgetCore *corePtr)
{
    if (corePtr->flags & WIDGET_DESTROYED) {
	return;
    }

    WidgetWorldChanged(corePtr);
    SizeChanged(corePtr);
    TtkRedisplayWidget(corePtr);
}

/* TtkWidgetChangeState --
 * 	Set / clear the specified bits in the 'state' flag,
 */
void TtkWidgetChangeState(WidgetCore *corePtr,
    unsigned int setBits, unsigned int clearBits)
{
    Ttk_State oldState = corePtr->state;
    corePtr->state = (oldState & ~clearBits) | setBits;
    if (corePtr->state ^ oldState) {
	TtkRedisplayWidget(corePtr);
    }
}

/* WidgetInstanceObjCmd --
 *	Widget instance command implementation.
 */
static int
WidgetInstanceObjCmd(
    void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    const Ttk_Ensemble *commands = corePtr->widgetSpec->commands;
    int status;

    Tcl_Preserve(clientData);
    status = Ttk_InvokeEnsemble(commands,1, clientData,interp,objc,objv);
    Tcl_Release(clientData);

194
195
196
197
198
199
200
201

202
203

204
205
206
207









208
209
210
211
212
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249


250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266
267

268
269
270
271
272
273
274
182
183
184
185
186
187
188

189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

264
265

266
267
268
269
270
271
272
273







-
+

-
+




+
+
+
+
+
+
+
+
+












-
+
















-
+












+
+















-
+

-
+







 * the WIDGET_DESTROYED flag bit upon return.
 */

/* WidgetInstanceObjCmdDeleted --
 * 	Widget instance command	deletion callback.
 */
static void
WidgetInstanceObjCmdDeleted(void *clientData)
WidgetInstanceObjCmdDeleted(ClientData clientData)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    corePtr->widgetCmd = NULL;
    if (corePtr->tkwin != NULL)
	Tk_DestroyWindow(corePtr->tkwin);
}

/* FreeWidget --
 *	 Final cleanup for widget; called via Tcl_EventuallyFree().
 */
static void
FreeWidget(void *memPtr)
{
    ckfree(memPtr);
}

/* DestroyWidget --
 * 	Main widget destructor; called from <DestroyNotify> event handler.
 */
static void
DestroyWidget(WidgetCore *corePtr)
{
    corePtr->flags |= WIDGET_DESTROYED;

    corePtr->widgetSpec->cleanupProc(corePtr);

    Tk_FreeConfigOptions(
	    corePtr, corePtr->optionTable, corePtr->tkwin);
	(ClientData)corePtr, corePtr->optionTable, corePtr->tkwin);

    if (corePtr->layout) {
	Ttk_FreeLayout(corePtr->layout);
    }

    if (corePtr->flags & REDISPLAY_PENDING) {
	Tcl_CancelIdleCall(DrawWidget, corePtr);
    }

    corePtr->tkwin = NULL;
    if (corePtr->widgetCmd) {
	Tcl_Command cmd = corePtr->widgetCmd;
	corePtr->widgetCmd = 0;
	/* NB: this can reenter the interpreter via a command traces */
	Tcl_DeleteCommandFromToken(corePtr->interp, cmd);
    }
    Tcl_EventuallyFree(corePtr, TCL_DYNAMIC);
    Tcl_EventuallyFree(corePtr, (Tcl_FreeProc *) FreeWidget);
}

/*
 * CoreEventProc --
 *	Event handler for basic events.
 *	Processes Expose, Configure, FocusIn/Out, and Destroy events.
 *	Also handles <<ThemeChanged>> virtual events.
 *
 *	For Expose and Configure, simply schedule the widget for redisplay.
 *	For Destroy events, handle the cleanup process.
 *
 *	For Focus events, set/clear the focus bit in the state field.
 *	It turns out this is impossible to do correctly in a binding script,
 *	because Tk filters out focus events with detail == NotifyInferior.
 *
 *	For Deactivate/Activate pseudo-events, set/clear the background state
 *	flag.
 */

static const unsigned CoreEventMask
    = ExposureMask
    | StructureNotifyMask
    | FocusChangeMask
    | VirtualEventMask
    | ActivateMask
    | EnterWindowMask
    | LeaveWindowMask
    ;

static void CoreEventProc(void *clientData, XEvent *eventPtr)
static void CoreEventProc(ClientData clientData, XEvent *eventPtr)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;

    switch (eventPtr->type)
    {
	case ConfigureNotify :
	    TtkRedisplayWidget(corePtr);
	    break;
	case Expose :
307
308
309
310
311
312
313
314

315
316
317



318
319
320


321
322
323
324
325
326













327

328
329
330
331



332
333
334
335
336
337
338
339
340

341
342

343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
306
307
308
309
310
311
312

313



314
315
316



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

338
339



340
341
342
343
344
345
346
347
348
349
350

351
352

353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368







-
+
-
-
-
+
+
+
-
-
-
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
-
-
+
+
+








-
+

-
+







-
+







	    corePtr->state &= ~TTK_STATE_HOVER;
	    TtkRedisplayWidget(corePtr);
	    break;
	case EnterNotify:
	    corePtr->state |= TTK_STATE_HOVER;
	    TtkRedisplayWidget(corePtr);
	    break;
	case VirtualEvent: {
	case VirtualEvent:
	    const char *name = ((XVirtualEvent *)eventPtr)->name;
	    if ((name != NULL) && !strcmp("ThemeChanged", name)) {
		WidgetWorldChanged(corePtr);
	    if (!strcmp("ThemeChanged", ((XVirtualEvent *)(eventPtr))->name)) {
		(void)UpdateLayout(corePtr->interp, corePtr);
		SizeChanged(corePtr);
	    }
	    break;
	}
		TtkRedisplayWidget(corePtr);
	    }
	default:
	    /* can't happen... */
	    break;
    }
}

/*
 * WidgetWorldChanged --
 * 	Default Tk_ClassWorldChangedProc() for widgets.
 * 	Invoked whenever fonts or other system resources are changed;
 * 	recomputes geometry.
 */
static void WidgetWorldChanged(ClientData clientData)
{
    WidgetCore *corePtr = clientData;
    SizeChanged(corePtr);
    TtkRedisplayWidget(corePtr);
}

static const Tk_ClassProcs widgetClassProcs = {
static Tk_ClassProcs widgetClassProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    WidgetWorldChanged,		/* worldChangedProc */
    NULL,			/* createProc */
    NULL			/* modalProc */
    WidgetWorldChanged,	/* worldChangedProc */
    NULL,					/* createProc */
    NULL					/* modalProc */
};

/*
 * TtkWidgetConstructorObjCmd --
 *	General-purpose widget constructor command implementation.
 *	ClientData is a WidgetSpec *.
 */
int TtkWidgetConstructorObjCmd(
    void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetSpec *widgetSpec = (WidgetSpec *)clientData;
    WidgetSpec *widgetSpec = clientData;
    const char *className = widgetSpec->className;
    Tk_OptionTable optionTable =
	Tk_CreateOptionTable(interp, widgetSpec->optionSpecs);
    Tk_Window tkwin;
    void *recordPtr;
    WidgetCore *corePtr;
    Tk_SavedOptions savedOptions;
    Tcl_Size i;
    int i;

    if (objc < 2 || objc % 2 == 1) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
	return TCL_ERROR;
    }

    /* Check if a -class option has been specified.
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396







-
+







	return TCL_ERROR;

    /*
     * Allocate and initialize the widget record.
     */
    recordPtr = ckalloc(widgetSpec->recordSize);
    memset(recordPtr, 0, widgetSpec->recordSize);
    corePtr = (WidgetCore *)recordPtr;
    corePtr = recordPtr;

    corePtr->tkwin	= tkwin;
    corePtr->interp 	= interp;
    corePtr->widgetSpec	= widgetSpec;
    corePtr->widgetCmd	= Tcl_CreateObjCommand(interp, Tk_PathName(tkwin),
	WidgetInstanceObjCmd, recordPtr, WidgetInstanceObjCmdDeleted);
    corePtr->optionTable = optionTable;
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471







-
+







 * 	Default getLayoutProc.
 *	Looks up the layout based on the -style resource (if specified),
 *	otherwise use the widget class.
 */
Ttk_Layout TtkWidgetGetLayout(
    Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr)
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    const char *styleName = 0;

    if (corePtr->styleObj)
    	styleName = Tcl_GetString(corePtr->styleObj);

    if (!styleName || *styleName == '\0')
    	styleName = corePtr->widgetSpec->className;
468
469
470
471
472
473
474
475

476
477
478

479
480
481
482
483
484
485
486
487

488
489

490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513

514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530
531
532
533
534
535
536

537
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589
590

591
592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

611
612

613
614
615
616
617
618
619
479
480
481
482
483
484
485

486
487
488

489
490
491
492
493
494
495
496
497

498
499

500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522
523

524


525
526
527
528
529
530

531



532
533
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552
553
554

555

556
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594

595
596

597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616

617
618
619
620
621
622
623
624







-
+


-
+








-
+

-
+








-
+














-
+
-
-






-
+
-
-
-










-
+












-
+
-









-
+








-
+








-
+











-
+

-
+

















-
+

-
+







 * 	Helper routine.  Same as TtkWidgetGetLayout, but prefixes
 * 	"Horizontal." or "Vertical." to the style name, depending
 * 	on the value of the 'orient' option.
 */
Ttk_Layout TtkWidgetGetOrientedLayout(
    Tcl_Interp *interp, Ttk_Theme themePtr, void *recordPtr, Tcl_Obj *orientObj)
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    const char *baseStyleName = 0;
    Tcl_DString styleName;
    Ttk_Orient orient = TTK_ORIENT_HORIZONTAL;
    int orient = TTK_ORIENT_HORIZONTAL;
    Ttk_Layout layout;

    Tcl_DStringInit(&styleName);

    /* Prefix:
     */
    Ttk_GetOrientFromObj(NULL, orientObj, &orient);
    if (orient == TTK_ORIENT_HORIZONTAL)
	Tcl_DStringAppend(&styleName, "Horizontal.", TCL_INDEX_NONE);
	Tcl_DStringAppend(&styleName, "Horizontal.", -1);
    else
	Tcl_DStringAppend(&styleName, "Vertical.", TCL_INDEX_NONE);
	Tcl_DStringAppend(&styleName, "Vertical.", -1);

    /* Add base style name:
     */
    if (corePtr->styleObj)
    	baseStyleName = Tcl_GetString(corePtr->styleObj);
    if (!baseStyleName || *baseStyleName == '\0')
    	baseStyleName = corePtr->widgetSpec->className;

    Tcl_DStringAppend(&styleName, baseStyleName, TCL_INDEX_NONE);
    Tcl_DStringAppend(&styleName, baseStyleName, -1);

    /* Create layout:
     */
    layout= Ttk_CreateLayout(interp, themePtr, Tcl_DStringValue(&styleName),
	recordPtr, corePtr->optionTable, corePtr->tkwin);

    Tcl_DStringFree(&styleName);

    return layout;
}

/* TtkNullInitialize --
 * 	Default widget initializeProc (no-op)
 */
void TtkNullInitialize(
void TtkNullInitialize(Tcl_Interp *interp, void *recordPtr)
    TCL_UNUSED(Tcl_Interp *),
    TCL_UNUSED(void *))
{
}

/* TtkNullPostConfigure --
 * 	Default widget postConfigureProc (no-op)
 */
int TtkNullPostConfigure(
int TtkNullPostConfigure(Tcl_Interp *interp, void *clientData, int mask)
    TCL_UNUSED(Tcl_Interp *),
    TCL_UNUSED(void *),
    TCL_UNUSED(int))
{
    return TCL_OK;
}

/* TtkCoreConfigure --
 * 	Default widget configureProc.
 * 	Handles -style option.
 */
int TtkCoreConfigure(Tcl_Interp *interp, void *clientData, int mask)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    int status = TCL_OK;

    if (mask & STYLE_CHANGED) {
	status = UpdateLayout(interp, corePtr);
    }

    return status;
}

/* TtkNullCleanup --
 * 	Default widget cleanupProc (no-op)
 */
void TtkNullCleanup(
void TtkNullCleanup(void *recordPtr)
    TCL_UNUSED(void *))
{
    return;
}

/* TtkWidgetDoLayout --
 * 	Default widget layoutProc.
 */
void TtkWidgetDoLayout(void *clientData)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    WidgetCore *corePtr = clientData;
    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));
}

/* TtkWidgetDisplay --
 * 	Default widget displayProc.
 */
void TtkWidgetDisplay(void *recordPtr, Drawable d)
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Ttk_DrawLayout(corePtr->layout, corePtr->state, d);
}

/* TtkWidgetSize --
 * 	Default widget sizeProc()
 */
int TtkWidgetSize(void *recordPtr, int *widthPtr, int *heightPtr)
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Ttk_LayoutSize(corePtr->layout, corePtr->state, widthPtr, heightPtr);
    return 1;
}

/*------------------------------------------------------------------------
 * +++ Default implementations for widget subcommands.
 */

/* $w cget -option
 */
int TtkWidgetCgetCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Tcl_Obj *result;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "option");
	return TCL_ERROR;
    }
    result = Tk_GetOptionValue(interp, recordPtr,
		corePtr->optionTable, objv[2], corePtr->tkwin);
    if (result == NULL)
	return TCL_ERROR;
    Tcl_SetObjResult(interp, result);
    return TCL_OK;
}

/* $w configure ?-option ?value ....??
 */
int TtkWidgetConfigureCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Tcl_Obj *result;

    if (objc == 2) {
	result = Tk_GetOptionInfo(interp, recordPtr,
		corePtr->optionTable, NULL, corePtr->tkwin);
    } else if (objc == 3) {
	result = Tk_GetOptionInfo(interp, recordPtr,
673
674
675
676
677
678
679
680

681
682

683
684
685
686
687
688
689
678
679
680
681
682
683
684

685
686

687
688
689
690
691
692
693
694







-
+

-
+







 * 	If $stateSpec is specified, modify the widget state accordingly,
 * 	return a new stateSpec representing the changed bits.
 *
 * 	Otherwise, return a statespec matching all the currently-set bits.
 */

int TtkWidgetStateCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Ttk_StateSpec spec;
    int status;
    Ttk_State oldState, changed;

    if (objc == 2) {
	Tcl_SetObjResult(interp,
	    Ttk_NewStateSpecObj(corePtr->state, 0ul));
713
714
715
716
717
718
719
720

721
722

723
724
725
726
727
728
729
718
719
720
721
722
723
724

725
726

727
728
729
730
731
732
733
734







-
+

-
+







 *
 * 	Tests if widget state matches $stateSpec.
 *	If $script is specified, execute script if state matches.
 *	Otherwise, return true/false
 */

int TtkWidgetInstateCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Ttk_State state = corePtr->state;
    Ttk_StateSpec spec;
    int status = TCL_OK;

    if (objc < 3 || objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "state-spec ?script?");
	return TCL_ERROR;
744
745
746
747
748
749
750
751

752
753

754
755

756
757
758
759
760
761
762
749
750
751
752
753
754
755

756
757

758
759

760
761
762
763
764
765
766
767







-
+

-
+

-
+







}

/* $w identify $x $y
 * $w identify element $x $y
 * 	Returns: name of element at $x, $y
 */
int TtkWidgetIdentifyCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
    void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;
    WidgetCore *corePtr = recordPtr;
    Ttk_Element element;
    static const char *const whatTable[] = { "element", NULL };
    static const char *whatTable[] = { "element", NULL };
    int x, y, what;

    if (objc < 4 || objc > 5) {
	Tcl_WrongNumArgs(interp, 2, objv, "?what? x y");
	return TCL_ERROR;
    }
    if (objc == 5) {
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
781
782
783
784
785
786
787




















788
789
790
791







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





    element = Ttk_IdentifyElement(corePtr->layout, x, y);
    if (element) {
	const char *elementName = Ttk_ElementName(element);
	Tcl_SetObjResult(interp,Tcl_NewStringObj(elementName,-1));
    }

    return TCL_OK;
}

/* $w style
 * 	Return the style currently applied to the widget.
 */

int TtkWidgetStyleCommand(
    void *recordPtr, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[])
{
    WidgetCore *corePtr = (WidgetCore *)recordPtr;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 2, objv, "");
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tcl_NewStringObj(
            Ttk_StyleName(Ttk_LayoutStyle(corePtr->layout)), -1));

    return TCL_OK;
}

/*EOF*/

Changes to generic/ttk/ttkWidget.h.

85
86
87
88
89
90
91
92
93
94
95
96
97



98
99

100
101
102
103



104
105
106
107


108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127

128
129
130

131
132
133
134
135
136
137

138
139
140
141

142
143
144
145
146
147
148
85
86
87
88
89
90
91


92



93
94
95
96

97
98



99
100
101
102
103
104

105
106
107

108




109

110

111
112
113
114
115
116
117
118
119

120
121
122

123
124
125
126
127
128
129

130
131
132
133

134
135
136
137
138
139
140
141







-
-

-
-
-
+
+
+

-
+

-
-
-
+
+
+



-
+
+

-

-
-
-
-

-
+
-









-
+


-
+






-
+



-
+







MODULE_SCOPE void TtkWidgetDoLayout(void *recordPtr);
MODULE_SCOPE void TtkWidgetDisplay(void *recordPtr, Drawable);

MODULE_SCOPE int TtkCoreConfigure(Tcl_Interp*, void *, int mask);

/* Common widget commands:
 */
MODULE_SCOPE int TtkWidgetCgetCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetConfigureCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetIdentifyCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
	void *,Tcl_Interp *, int, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetCgetCommand(
	void *,Tcl_Interp *, int, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetInstateCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
	void *,Tcl_Interp *, int, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetStateCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetStyleCommand(
	void *,Tcl_Interp *, Tcl_Size, Tcl_Obj*const[]);
	void *,Tcl_Interp *, int, Tcl_Obj*const[]);
MODULE_SCOPE int TtkWidgetIdentifyCommand(
	void *,Tcl_Interp *, int, Tcl_Obj*const[]);

/* Widget constructor:
 */
MODULE_SCOPE Tcl_ObjCmdProc2 TtkWidgetConstructorObjCmd;
MODULE_SCOPE int TtkWidgetConstructorObjCmd(
	ClientData, Tcl_Interp*, int, Tcl_Obj*const[]);

#if TCL_MAJOR_VERSION > 8
#define RegisterWidget(interp, name, specPtr) \
    Tcl_CreateObjCommand2(interp, name, \
	TtkWidgetConstructorObjCmd, (void *)specPtr,NULL)
#else
#define RegisterWidget(interp, name, specPtr) \
    Tcl_CreateObjCommand(interp, name, \
	TtkWidgetConstructorObjCmd, (void *)specPtr,NULL)
	TtkWidgetConstructorObjCmd, (ClientData)specPtr,NULL)
#endif

/* WIDGET_TAKEFOCUS_TRUE --
 * WIDGET_TAKEFOCUS_FALSE --
 *	Add one or the other of these to each OptionSpecs table
 *	to indicate whether the widget should take focus
 *	during keyboard traversal.
 */
#define WIDGET_TAKEFOCUS_TRUE \
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", \
	"ttk::takefocus", offsetof(WidgetCore, takeFocusPtr), TCL_INDEX_NONE, 0,0,0 }
	"ttk::takefocus", Tk_Offset(WidgetCore, takeFocusPtr), -1, 0,0,0 }
#define WIDGET_TAKEFOCUS_FALSE \
    {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", \
	"", offsetof(WidgetCore, takeFocusPtr), TCL_INDEX_NONE, 0,0,0 }
	"", Tk_Offset(WidgetCore, takeFocusPtr), -1, 0,0,0 }

/* WIDGET_INHERIT_OPTIONS(baseOptionSpecs) --
 * Add this at the end of an OptionSpecs table to inherit
 * the options from 'baseOptionSpecs'.
 */
#define WIDGET_INHERIT_OPTIONS(baseOptionSpecs) \
    {TK_OPTION_END, 0,0,0, NULL, TCL_INDEX_NONE,TCL_INDEX_NONE, 0, baseOptionSpecs, 0}
    {TK_OPTION_END, 0,0,0, NULL, -1,-1, 0, (ClientData)baseOptionSpecs, 0}

/* All widgets should inherit from ttkCoreOptionSpecs[].
 */
MODULE_SCOPE const Tk_OptionSpec ttkCoreOptionSpecs[];
MODULE_SCOPE Tk_OptionSpec ttkCoreOptionSpecs[];

/*
 * Useful routines for use inside widget implementations:
 */
/* extern int WidgetDestroyed(WidgetCore *); */
#define WidgetDestroyed(corePtr) ((corePtr)->flags & WIDGET_DESTROYED)

167
168
169
170
171
172
173





174
175
176
177
178
179
180
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178







+
+
+
+
+







typedef struct TtkTraceHandle_ Ttk_TraceHandle;

MODULE_SCOPE Ttk_TraceHandle *Ttk_TraceVariable(
    Tcl_Interp*, Tcl_Obj *varnameObj, Ttk_TraceProc callback, void *clientData);
MODULE_SCOPE void Ttk_UntraceVariable(Ttk_TraceHandle *);
MODULE_SCOPE int Ttk_FireTrace(Ttk_TraceHandle *);

/*
 * Virtual events:
 */
MODULE_SCOPE void TtkSendVirtualEvent(Tk_Window tgtWin, const char *eventName);

/*
 * Helper routines for data accessor commands:
 */
MODULE_SCOPE int TtkEnumerateOptions(
    Tcl_Interp *, void *, const Tk_OptionSpec *, Tk_OptionTable, Tk_Window);
MODULE_SCOPE int TtkGetOptionValue(
    Tcl_Interp *, void *, Tcl_Obj *optName, Tk_OptionTable, Tk_Window);
191
192
193
194
195
196
197
198

199
200
201

202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258



259
260
261
262
263
264
265
189
190
191
192
193
194
195

196
197


198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227


228
229

230
231
232
233
234
235
236
237
238
239

240
241

242
243
244
245
246
247
248



249
250
251
252
253
254
255
256
257
258







-
+

-
-
+











-
+



-
+













-
-


-
+









-


-







-
-
-
+
+
+








typedef struct ScrollHandleRec *ScrollHandle;

MODULE_SCOPE ScrollHandle TtkCreateScrollHandle(WidgetCore *, Scrollable *);
MODULE_SCOPE void TtkFreeScrollHandle(ScrollHandle);

MODULE_SCOPE int TtkScrollviewCommand(
    Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], ScrollHandle);
    Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], ScrollHandle);

MODULE_SCOPE void TtkUpdateScrollInfo(ScrollHandle h);
MODULE_SCOPE void TtkScrollTo(ScrollHandle, int newFirst, int updateScrollInfo);
MODULE_SCOPE void TtkScrollTo(ScrollHandle, int newFirst);
MODULE_SCOPE void TtkScrolled(ScrollHandle, int first, int last, int total);
MODULE_SCOPE void TtkScrollbarUpdateRequired(ScrollHandle);

/*
 * Tag sets (work in progress, half-baked)
 */

typedef struct TtkTag *Ttk_Tag;
typedef struct TtkTagTable *Ttk_TagTable;
typedef struct TtkTagSet {	/* TODO: make opaque */
    Ttk_Tag	*tags;
    Tcl_Size 	nTags;
    int 	nTags;
} *Ttk_TagSet;

MODULE_SCOPE Ttk_TagTable Ttk_CreateTagTable(
	Tcl_Interp *, Tk_Window tkwin, const Tk_OptionSpec *, size_t recordSize);
	Tcl_Interp *, Tk_Window tkwin, Tk_OptionSpec[], int recordSize);
MODULE_SCOPE void Ttk_DeleteTagTable(Ttk_TagTable);

MODULE_SCOPE Ttk_Tag Ttk_GetTag(Ttk_TagTable, const char *tagName);
MODULE_SCOPE Ttk_Tag Ttk_GetTagFromObj(Ttk_TagTable, Tcl_Obj *);

MODULE_SCOPE Tcl_Obj *Ttk_TagOptionValue(
    Tcl_Interp *, Ttk_TagTable, Ttk_Tag, Tcl_Obj *optionName);

MODULE_SCOPE int Ttk_EnumerateTagOptions(
    Tcl_Interp *, Ttk_TagTable, Ttk_Tag);

MODULE_SCOPE int Ttk_EnumerateTags(Tcl_Interp *, Ttk_TagTable);

MODULE_SCOPE void Ttk_DeleteTagFromTable(Ttk_TagTable, Ttk_Tag);

MODULE_SCOPE int Ttk_ConfigureTag(
    Tcl_Interp *interp, Ttk_TagTable tagTable, Ttk_Tag tag,
    Tcl_Size objc, Tcl_Obj *const objv[]);
    int objc, Tcl_Obj *const objv[]);

MODULE_SCOPE Ttk_TagSet Ttk_GetTagSetFromObj(
    Tcl_Interp *interp, Ttk_TagTable, Tcl_Obj *objPtr);
MODULE_SCOPE Tcl_Obj *Ttk_NewTagSetObj(Ttk_TagSet);

MODULE_SCOPE void Ttk_FreeTagSet(Ttk_TagSet);

MODULE_SCOPE int Ttk_TagSetContains(Ttk_TagSet, Ttk_Tag tag);
MODULE_SCOPE int Ttk_TagSetAdd(Ttk_TagSet, Ttk_Tag tag);
MODULE_SCOPE int Ttk_TagSetAddSet(Ttk_TagSet, Ttk_TagSet);
MODULE_SCOPE int Ttk_TagSetRemove(Ttk_TagSet, Ttk_Tag tag);

MODULE_SCOPE void Ttk_TagSetDefaults(Ttk_TagTable, Ttk_Style, void *);
MODULE_SCOPE void Ttk_TagSetValues(Ttk_TagTable, Ttk_TagSet, void *record);
MODULE_SCOPE void Ttk_TagSetApplyStyle(Ttk_TagTable,Ttk_Style,Ttk_State,void*);

/*
 * String tables for widget resource specifications:
 */

MODULE_SCOPE const char *const ttkOrientStrings[];
MODULE_SCOPE const char *const ttkCompoundStrings[];
MODULE_SCOPE const char *const ttkDefaultStrings[];
MODULE_SCOPE const char *ttkOrientStrings[];
MODULE_SCOPE const char *ttkCompoundStrings[];
MODULE_SCOPE const char *ttkDefaultStrings[];

/*
 * ... other option types...
 */
MODULE_SCOPE int TtkGetLabelAnchorFromObj(
	Tcl_Interp*, Tcl_Obj*, Ttk_PositionSpec *);

Changes to library/bgerror.tcl.

1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
1
2
3
4
5
6
7
8




9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59








-
-
-
-
+
+
+
+











-
+
-


















-
+








-
+







# bgerror.tcl --
#
#	Implementation of the bgerror procedure.  It posts a dialog box with
#	the error message and gives the user a chance to see a more detailed
#	stack trace, and possible do something more interesting with that
#	trace (like save it to a log).  This is adapted from work done by
#	Donal K. Fellows.
#
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2007 ActiveState Software Inc.
# Copyright © 2007 Daniel A. Steffen <[email protected]>
# Copyright © 2009 Pat Thoyts <[email protected]>
# Copyright (c) 1998-2000 by Ajuba Solutions.
# Copyright (c) 2007 by ActiveState Software Inc.
# Copyright (c) 2007 Daniel A. Steffen <[email protected]>
# Copyright (c) 2009 Pat Thoyts <[email protected]>

namespace eval ::tk::dialog::error {
    namespace import -force ::tk::msgcat::*
    namespace export bgerror
    option add *ErrorDialog.function.text [mc "Save To Log"] \
	widgetDefault
    option add *ErrorDialog.function.command [namespace code SaveToLog]
    option add *ErrorDialog*Label.font TkCaptionFont widgetDefault
    if {[tk windowingsystem] eq "aqua"} {
	option add *ErrorDialog*background systemAlertBackgroundActive \
		widgetDefault
	option add *ErrorDialog*info.text.background \
	option add *ErrorDialog*info.text.background white widgetDefault
	        systemTextBackgroundColor widgetDefault
	option add *ErrorDialog*Button.highlightBackground \
		systemAlertBackgroundActive widgetDefault
    }
}

proc ::tk::dialog::error::Return {which code} {
    variable button

    .bgerrorDialog.$which state {active selected focus}
    update idletasks
    after 100
    set button $code
}

proc ::tk::dialog::error::Details {} {
    set w .bgerrorDialog
    set caption [option get $w.function text {}]
    set command [option get $w.function command {}]
    if {($caption eq "") || ($command eq "")} {
    if { ($caption eq "") || ($command eq "") } {
	grid forget $w.function
    }
    lappend command [$w.top.info.text get 1.0 end-1c]
    $w.function configure -text $caption -command $command
    grid $w.top.info - -sticky nsew -padx 3m -pady 3m
}

proc ::tk::dialog::error::SaveToLog {text} {
    if {$::tcl_platform(platform) eq "windows"} {
    if { $::tcl_platform(platform) eq "windows" } {
	set allFiles *.*
    } else {
	set allFiles *
    }
    set types [list \
	    [list [mc "Log Files"] .log]      \
	    [list [mc "Text Files"] .txt]     \
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111


112
113
114
115
116
117
118

119
120
121


122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139


140
141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108


109
110



111
112


113



114
115
116
117

118


119
120
121
122
123

124







125
126
127
128


129
130
131



132
133
134
135
136

137
138
139
140
141
142
143







-
+








-
-
+
+
-
-
-


-
-
+
-
-
-
+
+


-

-
-
+
+



-

-
-
-
-
-
-
-
+
+


-
-
+
+

-
-
-





-







#	It tries to execute tkerror, if that fails it posts a dialog box
#	containing the error message and gives the user a chance to ask
#	to see a stack trace.
#
# Arguments:
#	err - The error message.
#
proc ::tk::dialog::error::bgerror {err {flag 1}} {
proc ::tk::dialog::error::bgerror err {
    global errorInfo
    variable button

    set info $errorInfo

    set ret [catch {::tkerror $err} msg];
    if {$ret != 1} {return -code $ret $msg}

    # The application's tkerror either failed or was not found
    # so we use the default dialog.  But on Aqua we cannot display
    # Ok the application's tkerror either failed or was not found
    # we use the default dialog then :
    # the dialog if the background error occurs in an idle task
    # being processed inside of [NSView drawRect].  In that case
    # we post the dialog as an after task instead.
    set windowingsystem [tk windowingsystem]
    if {$windowingsystem eq "aqua"} {
	if $flag {
	    set errorInfo $info
	set ok [mc Ok]
	    after 500 [list bgerror "$err" 0]
	    return
	}
    } else {
	set ok [mc OK]
    }

    set ok [mc OK]
    # Truncate the message if it is too wide (>maxLine characters) or
    # too tall (>maxRows lines).  Truncation occurs at the first point at
    # which one of those conditions is met. No trailing newline.
    # too tall (>4 lines).  Truncation occurs at the first point at
    # which one of those conditions is met.
    set displayedErr ""
    set lines 0
    set maxLine 45
    set maxRows 5
    foreach line [split $err \n] {
	if {$lines > $maxRows - 1} {
            # No more lines.  Append to previous line.
	    append displayedErr { ...}
	    break
	}
	if {[string length $line] > $maxLine} {
	    append displayedErr "[string range $line 0 $maxLine-3]..."
	if { [string length $line] > $maxLine } {
	    append displayedErr "[string range $line 0 [expr {$maxLine-3}]]..."
	    break
	}
	if {$lines > $maxRows - 2 && [string length $line] > $maxLine-4} {
	    append displayedErr "[string range $line 0 $maxLine-3]..."
	if { $lines > 4 } {
	    append displayedErr "..."
	    break
	} elseif {$lines > $maxRows - 2} {
            # Last line, but no break or newline.  Room to add 4 chars.
	    append displayedErr "${line}"
	} else {
	    append displayedErr "${line}\n"
	}
	incr lines
    }
    set displayedErr [string trim $displayedErr]

    set title [mc "Application Error"]
    set text [mc "Error: %1\$s" $displayedErr]
    set buttons [list ok $ok dismiss [mc "Skip Messages"] \
		     function [mc "Details >>"]]

    # 1. Create the top-level window and divide it into top
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185







-
+










-
+








    ttk::frame $dlg.bot
    ttk::frame $dlg.top
    pack $dlg.bot -side bottom -fill both
    pack $dlg.top -side top -fill both -expand 1

    set W [ttk::frame $dlg.top.info]
    text $W.text -setgrid false -height 10 -wrap char \
    text $W.text -setgrid true -height 10 -wrap char \
	-yscrollcommand [list $W.scroll set]
    if {$windowingsystem ne "aqua"} {
	$W.text configure -width 40
    }

    ttk::scrollbar $W.scroll -command [list $W.text yview]
    pack $W.scroll -side right -fill y
    pack $W.text -side left -expand yes -fill both
    $W.text insert 0.0 "$err\n$info"
    $W.text mark set insert 0.0
    bind $W.text <Button-1> {focus %W}
    bind $W.text <ButtonPress-1> { focus %W }
    $W.text configure -state disabled

    # 2. Fill the top part with bitmap and message

    # Max-width of message is the width of the screen...
    set wrapwidth [winfo screenwidth $dlg]
    # ...minus the width of the icon, padding and a fudge factor for
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+








    # 3. Create a row of buttons at the bottom of the dialog.

    set i 0
    foreach {name caption} $buttons {
	ttk::button $dlg.$name -text $caption -default normal \
	    -command [namespace code [list set button $i]]
	grid $dlg.$name -in $dlg.bot -column $i -row 0 -sticky ew -padx 7.5p
	grid $dlg.$name -in $dlg.bot -column $i -row 0 -sticky ew -padx 10
	grid columnconfigure $dlg.bot $i -weight 1
	# We boost the size of some Mac buttons for l&f
	if {$windowingsystem eq "aqua"} {
	    if {($name eq "ok") || ($name eq "dismiss")} {
		grid columnconfigure $dlg.bot $i -minsize 90
	    }
	    grid configure $dlg.$name -pady 7

Changes to library/button.tcl.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44

45
46
47

48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90

91
92
93
94
95
96
97
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43

44
45
46

47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89

90
91
92
93
94
95
96
97






-
-
-
+
+
+














-
+








-
+










-
+


-
+





-
+












-
+




















-
+


-
+







# button.tcl --
#
# This file defines the default bindings for Tk label, button,
# checkbutton, and radiobutton widgets and provides procedures
# that help in implementing those bindings.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 2002 ActiveState Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 2002 ActiveState Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#-------------------------------------------------------------------------
# The code below creates the default class bindings for buttons.
#-------------------------------------------------------------------------

if {[tk windowingsystem] eq "aqua"} {

    bind Radiobutton <Enter> {
	tk::ButtonEnter %W
    }
    bind Radiobutton <Button-1> {
    bind Radiobutton <1> {
	tk::ButtonDown %W
    }
    bind Radiobutton <ButtonRelease-1> {
	tk::ButtonUp %W
    }
    bind Checkbutton <Enter> {
	tk::ButtonEnter %W
    }
    bind Checkbutton <Button-1> {
    bind Checkbutton <1> {
	tk::ButtonDown %W
    }
    bind Checkbutton <ButtonRelease-1> {
	tk::ButtonUp %W
    }
    bind Checkbutton <Leave> {
	tk::ButtonLeave %W
    }
}
if {"win32" eq [tk windowingsystem]} {
    bind Checkbutton <=> {
    bind Checkbutton <equal> {
	tk::CheckRadioInvoke %W select
    }
    bind Checkbutton <+> {
    bind Checkbutton <plus> {
	tk::CheckRadioInvoke %W select
    }
    bind Checkbutton <minus> {
	tk::CheckRadioInvoke %W deselect
    }
    bind Checkbutton <Button-1> {
    bind Checkbutton <1> {
	tk::CheckRadioDown %W
    }
    bind Checkbutton <ButtonRelease-1> {
	tk::ButtonUp %W
    }
    bind Checkbutton <Enter> {
	tk::CheckRadioEnter %W
    }
    bind Checkbutton <Leave> {
	tk::ButtonLeave %W
    }

    bind Radiobutton <Button-1> {
    bind Radiobutton <1> {
	tk::CheckRadioDown %W
    }
    bind Radiobutton <ButtonRelease-1> {
	tk::ButtonUp %W
    }
    bind Radiobutton <Enter> {
	tk::CheckRadioEnter %W
    }
}
if {"x11" eq [tk windowingsystem]} {
    bind Checkbutton <Return> {
	if {!$tk_strictMotif} {
	    tk::CheckInvoke %W
	}
    }
    bind Radiobutton <Return> {
	if {!$tk_strictMotif} {
	    tk::CheckRadioInvoke %W
	}
    }
    bind Checkbutton <Button-1> {
    bind Checkbutton <1> {
	tk::CheckInvoke %W
    }
    bind Radiobutton <Button-1> {
    bind Radiobutton <1> {
	tk::CheckRadioInvoke %W
    }
    bind Checkbutton <Enter> {
	tk::CheckEnter %W
    }
    bind Radiobutton <Enter> {
	tk::ButtonEnter %W
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







bind Button <FocusIn> {}
bind Button <Enter> {
    tk::ButtonEnter %W
}
bind Button <Leave> {
    tk::ButtonLeave %W
}
bind Button <Button-1> {
bind Button <1> {
    tk::ButtonDown %W
}
bind Button <ButtonRelease-1> {
    tk::ButtonUp %W
}

bind Checkbutton <FocusIn> {}
744
745
746
747
748
749
750
751
752


753
754
755
756
757
758

759
760
761
762
763
764
765
766
744
745
746
747
748
749
750


751
752
753
754




755

756
757
758
759
760
761
762







-
-
+
+


-
-
-
-
+
-








proc ::tk::CheckLeave {w} {
    variable ::tk::Priv
    if {[$w cget -state] ne "disabled"} {
	$w configure -state normal
    }

    # Restore the original button "selected" color; but only if the user
    # has not changed it in the meantime.
    # Restore the original button "selected" color; assume that the user
    # wasn't monkeying around with things too much.

    if {![$w cget -indicatoron] && [info exist Priv($w,selectcolor)]} {
        if {[$w cget -selectcolor] eq $Priv($w,selectcolor)
                || ([info exist Priv($w,aselectcolor)] &&
                    [$w cget -selectcolor] eq $Priv($w,aselectcolor))} {
	    $w configure -selectcolor $Priv($w,selectcolor)
	$w configure -selectcolor $Priv($w,selectcolor)
	}
    }
    unset -nocomplain Priv($w,selectcolor) Priv($w,aselectcolor)

    # Restore the original button relief if it was changed by Tk. That is
    # signaled by the existence of Priv($w,prelief).

    if {[info exists Priv($w,relief)]} {

Changes to library/choosedir.tcl.

1
2
3
4
5

6
7
8
9
10
11
12
1
2
3
4

5
6
7
8
9
10
11
12




-
+







# choosedir.tcl --
#
#	Choose directory dialog implementation for Unix/Mac.
#
# Copyright © 1998-2000 Scriptics Corporation.
# Copyright (c) 1998-2000 by Scriptics Corporation.
# All rights reserved.

# Make sure the tk::dialog namespace, in which all dialogs should live, exists
namespace eval ::tk::dialog {}
namespace eval ::tk::dialog::file {}

# Make the chooseDir namespace inside the dialog namespace
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
114
115
116
117
118
119
120


121

122
123
124
125
126
127
128







-
-
+
-








    # Cleanup traces on selectPath variable
    #

    foreach trace [trace info variable data(selectPath)] {
	trace remove variable data(selectPath) [lindex $trace 0] [lindex $trace 1]
    }
    if {[winfo exists $data(dirMenuBtn)]} {
	$data(dirMenuBtn) configure -textvariable {}
    $data(dirMenuBtn) configure -textvariable {}
    }

    # Return value to user
    #

    return $Priv(selectFilePath)
}

Changes to library/clrpick.tcl.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







# clrpick.tcl --
#
#	Color selection dialog for platforms that do not support a
#	standard color selection dialog.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright (c) 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.
#
# ToDo:
#
#	(1): Find out how many free colors are left in the colormap and
46
47
48
49
50
51
52
53
54
55


56
57
58
59

60
61

62
63
64
65

66
67
68
69
70
71
72
46
47
48
49
50
51
52



53
54
55
56
57

58


59
60
61
62

63
64
65
66
67
68
69
70







-
-
-
+
+



-
+
-
-
+



-
+







    # This is the actual number of lines that are drawn in each color strip.
    # Note that the bars may be of any width.
    # However, NUM_COLORBARS must be a number that evenly divides 256.
    # Such as 256, 128, 64, etc.
    set data(NUM_COLORBARS) 16

    # BARS_WIDTH is the number of pixels wide the color bar portion of the
    # canvas is. BARS_WIDTH, BARS_WIDTH * 1.25, BARS_WIDTH * 1.5, and
    # BARS_WIDTH * 1.75 must be multiples of NUM_COLORBARS.
    set data(BARS_WIDTH) [::tk::ScaleNum 192]
    # canvas is. This number must be a multiple of NUM_COLORBARS
    set data(BARS_WIDTH) 160

    # PLGN_WIDTH is the number of pixels wide of the triangular selection
    # polygon. This also results in the definition of the padding on the
    # left and right sides which is half of PLGN_WIDTH. PLGN_WIDTH,
    # left and right sides which is half of PLGN_WIDTH. Make this number even.
    # PLGN_WIDTH * 1.25, PLGN_WIDTH * 1.5, and PLGN_WIDTH * 1.75 must be even.
    set data(PLGN_WIDTH) [::tk::ScaleNum 8]
    set data(PLGN_HEIGHT) 10

    # PLGN_HEIGHT is the height of the selection polygon and the height of the
    # selection rectangle at the bottom of the color bar. No restrictions.
    set data(PLGN_HEIGHT) [::tk::ScaleNum 8]
    set data(PLGN_WIDTH) 10

    Config $dataName $args
    InitValues $dataName

    set sc [winfo screen $data(-parent)]
    set winExists [winfo exists $w]
    if {!$winExists || $sc ne [winfo screen $w]} {
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289

290
291
292


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321

322
323
324

325
326
327
328
329
330
331
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286

287
288


289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330







-
+















-
+




















-
+











-
+

-
-
+
+




















-
+







-
+



+







	::tk::AmpWidget label $box.label -text "[mc $l]:" \
		-width $maxWidth -anchor ne
	bind $box.label <<AltUnderlined>> [list focus $box.entry]

	entry $box.entry -textvariable \
		::tk::dialog::color::[winfo name $w]($color,intensity) \
		-width 4
	pack $box.label -side left -fill y -padx 1.5p -pady 2p
	pack $box.label -side left -fill y -padx 2 -pady 3
	pack $box.entry -side left -anchor n -pady 0
	pack $box -side left -fill both

	set height [expr {
	    [winfo reqheight $box.entry] -
	    2*([$box.entry cget -highlightthickness] + [$box.entry cget -bd])
	}]

	canvas $f.color -height $height \
		-width $data(BARS_WIDTH) -relief sunken -bd 2
	canvas $f.sel -height $data(PLGN_HEIGHT) \
		-width $data(canvasWidth) -highlightthickness 0
	pack $f.color -expand yes -fill both
	pack $f.sel -expand yes -fill both

	pack $f -side top -fill x -padx 0 -pady 1.5p
	pack $f -side top -fill x -padx 0 -pady 2

	set data($color,entry) $box.entry
	set data($color,col) $f.color
	set data($color,sel) $f.sel

	bind $data($color,col) <Configure> \
		[list tk::dialog::color::DrawColorScale $w $color 1]
	bind $data($color,col) <Enter> \
		[list tk::dialog::color::EnterColorBar $w $color]
	bind $data($color,col) <Leave> \
		[list tk::dialog::color::LeaveColorBar $w $color]

	bind $data($color,sel) <Enter> \
		[list tk::dialog::color::EnterColorBar $w $color]
	bind $data($color,sel) <Leave> \
		[list tk::dialog::color::LeaveColorBar $w $color]

	bind $box.entry <Return> [list tk::dialog::color::HandleRGBEntry $w]
    }

    pack $stripsFrame -side left -fill both -padx 3p -pady 7.5p
    pack $stripsFrame -side left -fill both -padx 4 -pady 10

    # The selFrame contains a frame that demonstrates the currently
    # selected color
    #
    set selFrame [frame $topFrame.sel]
    set lab [::tk::AmpWidget label $selFrame.lab \
	    -text [mc "&Selection:"] -anchor sw]
    set ent [entry $selFrame.ent \
	    -textvariable ::tk::dialog::color::[winfo name $w](selection) \
	    -width 16]
    set f1  [frame $selFrame.f1 -relief sunken -bd 2]
    set data(finalCanvas) [frame $f1.demo -bd 0 -width 75p -height 51p]
    set data(finalCanvas) [frame $f1.demo -bd 0 -width 100 -height 70]

    pack $lab $ent -side top -fill x -padx 3p -pady 1.5p
    pack $f1 -expand yes -anchor nw -fill both -padx 4.5p -pady 7.5p
    pack $lab $ent -side top -fill x -padx 4 -pady 2
    pack $f1 -expand yes -anchor nw -fill both -padx 6 -pady 10
    pack $data(finalCanvas) -expand yes -fill both

    bind $ent <Return> [list tk::dialog::color::HandleSelEntry $w]

    pack $selFrame -side left -fill none -anchor nw
    pack $topFrame -side top -expand yes -fill both -anchor nw

    # the botFrame frame contains the buttons
    #
    set botFrame [frame $w.bot -relief raised -bd 1]

    ::tk::AmpWidget button $botFrame.ok     -text [mc "&OK"]		\
	    -command [list tk::dialog::color::OkCmd $w]
    ::tk::AmpWidget button $botFrame.cancel -text [mc "&Cancel"]	\
	    -command [list tk::dialog::color::CancelCmd $w]

    set data(okBtn)      $botFrame.ok
    set data(cancelBtn)  $botFrame.cancel

    grid x $botFrame.ok x $botFrame.cancel x -sticky ew
    grid configure $botFrame.ok $botFrame.cancel -padx 7.5p -pady 7.5p
    grid configure $botFrame.ok $botFrame.cancel -padx 10 -pady 10
    grid columnconfigure $botFrame {0 4} -weight 1 -uniform space
    grid columnconfigure $botFrame {1 3} -weight 1 -uniform button
    grid columnconfigure $botFrame 2 -weight 2 -uniform space
    pack $botFrame -side bottom -fill x

    # Accelerator bindings
    bind $lab <<AltUnderlined>> [list focus $ent]
    bind $w <Escape> [list tk::ButtonInvoke $data(cancelBtn)]
    bind $w <KeyPress-Escape> [list tk::ButtonInvoke $data(cancelBtn)]
    bind $w <Alt-Key> [list tk::AltKeyInDialog $w %A]

    wm protocol $w WM_DELETE_WINDOW [list tk::dialog::color::CancelCmd $w]
    bind $lab <Destroy> [list tk::dialog::color::CancelCmd $w]
}

# ::tk::dialog::color::SetRGBValue --
#
#	Sets the current selection of the dialog box
#
proc ::tk::dialog::color::SetRGBValue {w color} {
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420

421
422
423
424
425
426
427
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418

419
420
421
422
423
424
425
426







-
+












-
+






-
+







	# Delete the selector if it exists
	if {[info exists data($c,index)]} {
	    $sel delete $data($c,index)
	}

	# Draw the selection polygons
	CreateSelector $w $sel $c
	$sel bind $data($c,index) <Button-1> \
	$sel bind $data($c,index) <ButtonPress-1> \
		[list tk::dialog::color::StartMove $w $sel $c %x $data(selPad) 1]
	$sel bind $data($c,index) <B1-Motion> \
		[list tk::dialog::color::MoveSelector $w $sel $c %x $data(selPad)]
	$sel bind $data($c,index) <ButtonRelease-1> \
		[list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(selPad)]

	set height [winfo height $col]
	# Create an invisible region under the colorstrip to catch mouse clicks
	# that aren't on the selector.
	set data($c,clickRegion) [$sel create rectangle 0 0 \
		$data(canvasWidth) $height -fill {} -outline {}]

	bind $col <Button-1> \
	bind $col <ButtonPress-1> \
		[list tk::dialog::color::StartMove $w $sel $c %x $data(colorPad)]
	bind $col <B1-Motion> \
		[list tk::dialog::color::MoveSelector $w $sel $c %x $data(colorPad)]
	bind $col <ButtonRelease-1> \
		[list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(colorPad)]

	$sel bind $data($c,clickRegion) <Button-1> \
	$sel bind $data($c,clickRegion) <ButtonPress-1> \
		[list tk::dialog::color::StartMove $w $sel $c %x $data(selPad)]
	$sel bind $data($c,clickRegion) <B1-Motion> \
		[list tk::dialog::color::MoveSelector $w $sel $c %x $data(selPad)]
	$sel bind $data($c,clickRegion) <ButtonRelease-1> \
		[list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(selPad)]
    } else {
	# l is the canvas index of the first colorbar.

Changes to library/comdlg.tcl.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







# comdlg.tcl --
#
#	Some functions needed for the common dialog boxes. Probably need to go
#	in a different file.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright (c) 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.
#

# tclParseConfigSpec --
#
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
25
26
27
28
29
30
31

32

33
34
35
36
37
38
39







-
+
-







# w = widget record to modify. Must be the pathname of a widget.
#
# specs = {
#    {-commandlineswitch resourceName ResourceClass defaultValue verifier}
#    {....}
# }
#
# flags = a list of flags. Currently supported flags are:
# flags = currently unused.
#     DONTSETDEFAULTS = skip default values setting
#
# argList = The list of  "-option value" pairs.
#
proc tclParseConfigSpec {w specs flags argList} {
    upvar #0 $w data

    # 1: Put the specs in associative arrays for faster access
60
61
62
63
64
65
66
67
68
69


70
71
72
73
74
75
76
77
59
60
61
62
63
64
65



66
67

68
69
70
71
72
73
74







-
-
-
+
+
-







	}
	return -code error -errorcode {TK VALUE_MISSING} \
	    "value for \"$cmdsw\" missing"
    }

    # 2: set the default values
    #
    if {"DONTSETDEFAULTS" ni $flags} {
        foreach cmdsw [array names cmd] {
	    set data($cmdsw) $def($cmdsw)
    foreach cmdsw [array names cmd] {
	set data($cmdsw) $def($cmdsw)
        }
    }

    # 3: parse the argument list
    #
    foreach {cmdsw value} $argList {
	if {![info exists cmd($cmdsw)]} {
	    return -code error -errorcode [list TK LOOKUP OPTION $cmdsw] \

Changes to library/console.tcl.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16






-
-
-
+
+
+







# console.tcl --
#
# This code constructs the console window for an application.  It
# can be used by non-unix systems that do not have built-in support
# for shells.
#
# Copyright © 1995-1997 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2007-2008 Daniel A. Steffen <[email protected]>
# Copyright (c) 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Ajuba Solutions.
# Copyright (c) 2007-2008 Daniel A. Steffen <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

# TODO: history - remember partially written command

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102









103
104
105
106
107




108
109
110
111
112

113
114

115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131



132
133
134
135
136
137




138
139
140
141
142
143
144



145
146
147
148
149

150
151

152
153

154
155
156
157
158
159
160
87
88
89
90
91
92
93









94
95
96
97
98
99
100
101
102
103




104
105
106
107
108
109
110
111

112
113

114
115

116
117
118
119
120
121
122
123
124
125
126
127
128



129
130
131
132
133




134
135
136
137
138
139
140
141



142
143
144
145
146
147
148

149
150

151
152

153
154
155
156
157
158
159
160







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+




-
+

-
+

-
+












-
-
-
+
+
+


-
-
-
-
+
+
+
+




-
-
-
+
+
+




-
+

-
+

-
+







	menu .menubar.help -tearoff 0
	AmpMenuArgs .menubar.help add command -label [mc &About...] \
		-command tk::ConsoleAbout
    }

    AmpMenuArgs .menubar.edit add separator
    if {$::tk::console::useFontchooser} {
	if {[tk windowingsystem] eq "aqua"} {
	    .menubar.edit add command -label tk_choose_font_marker
	    set index [.menubar.edit index tk_choose_font_marker]
	    .menubar.edit entryconfigure $index \
		-label [mc "Show Fonts"]\
		-accelerator "$mod-T"\
		-command [list ::tk::console::FontchooserToggle]
	    bind Console <<TkFontchooserVisibility>> \
		[list ::tk::console::FontchooserVisibility $index]
        if {[tk windowingsystem] eq "aqua"} {
            .menubar.edit add command -label tk_choose_font_marker
            set index [.menubar.edit index tk_choose_font_marker]
            .menubar.edit entryconfigure $index \
                -label [mc "Show Fonts"]\
                -accelerator "$mod-T"\
                -command [list ::tk::console::FontchooserToggle]
            bind Console <<TkFontchooserVisibility>> \
                [list ::tk::console::FontchooserVisibility $index]
	    ::tk::console::FontchooserVisibility $index
	} else {
	    AmpMenuArgs .menubar.edit add command -label [mc "&Font..."] \
		-command [list ::tk::console::FontchooserToggle]
	}
        } else {
            AmpMenuArgs .menubar.edit add command -label [mc "&Font..."] \
                -command [list ::tk::console::FontchooserToggle]
        }
	bind Console <FocusIn>  [list ::tk::console::FontchooserFocus %W 1]
	bind Console <FocusOut> [list ::tk::console::FontchooserFocus %W 0]
    }
    AmpMenuArgs .menubar.edit add command -label [mc "&Increase Font Size"] \
	-accel "$mod++" -command {event generate .console <<Console_FontSizeIncr>>}
        -accel "$mod++" -command {event generate .console <<Console_FontSizeIncr>>}
    AmpMenuArgs .menubar.edit add command -label [mc "&Decrease Font Size"] \
	-accel "$mod+-" -command {event generate .console <<Console_FontSizeDecr>>}
        -accel "$mod+-" -command {event generate .console <<Console_FontSizeDecr>>}
    AmpMenuArgs .menubar.edit add command -label [mc "Fit To Screen Width"] \
	-command {event generate .console <<Console_FitScreenWidth>>}
        -command {event generate .console <<Console_FitScreenWidth>>}

    if {[tk windowingsystem] eq "aqua"} {
	.menubar add cascade -label [mc Window] -menu [menu .menubar.window]
	.menubar add cascade -label [mc Help] -menu [menu .menubar.help]
    }

    . configure -menu .menubar

    # See if we can find a better font than the TkFixedFont
    catch {font create TkConsoleFont {*}[font configure TkFixedFont]}
    set families [font families]
    switch -exact -- [tk windowingsystem] {
	aqua { set preferred {Monaco 10} }
	win32 { set preferred {ProFontWindows 8 Consolas 8} }
	default { set preferred {} }
        aqua { set preferred {Monaco 10} }
        win32 { set preferred {ProFontWindows 8 Consolas 8} }
        default { set preferred {} }
    }
    foreach {family size} $preferred {
	if {$family in $families} {
	    font configure TkConsoleFont -family $family -size $size
	    break
	}
        if {[lsearch -exact $families $family] != -1} {
            font configure TkConsoleFont -family $family -size $size
            break
        }
    }

    # Provide the right border for the text widget (platform dependent).
    ::ttk::style layout ConsoleFrame {
	Entry.field -sticky news -border 1 -children {
	    ConsoleFrame.padding -sticky news
	}
        Entry.field -sticky news -border 1 -children {
            ConsoleFrame.padding -sticky news
        }
    }
    ::ttk::frame .consoleframe -style ConsoleFrame

    set con [text .console -yscrollcommand [list .sb set] -setgrid true \
		 -borderwidth 0 -highlightthickness 0 -font TkConsoleFont]
                 -borderwidth 0 -highlightthickness 0 -font TkConsoleFont]
    if {[tk windowingsystem] eq "aqua"} {
	scrollbar .sb -command [list $con yview]
        scrollbar .sb -command [list $con yview]
    } else {
	::ttk::scrollbar .sb -command [list $con yview]
        ::ttk::scrollbar .sb -command [list $con yview]
    }
    pack .sb  -in .consoleframe -fill both -side right -padx 1 -pady 1
    pack $con -in .consoleframe -fill both -expand 1 -side left -padx 1 -pady 1
    pack .consoleframe -fill both -expand 1 -side left

    ConsoleBind $con

211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225







-
+







proc ::tk::ConsoleSource {} {
    set filename [tk_getOpenFile -defaultextension .tcl -parent . \
	    -title [mc "Select a file to source"] \
	    -filetypes [list \
	    [list [mc "Tcl Scripts"] .tcl] \
	    [list [mc "All Files"] *]]]
    if {$filename ne ""} {
	set cmd [list source -encoding utf-8 $filename]
    	set cmd [list source $filename]
	if {[catch {consoleinterp eval $cmd} result]} {
	    ConsoleOutput stderr "$result\n"
	}
    }
}

# ::tk::ConsoleInvoke --
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286




287
288

289
290
291


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310




311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331





332
333
334
335
336
337



338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
363
364




365
366
367
368
369
370
371
372
373
374
375
376
377
378
379









380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398








399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421

422
423
424
425

426
427

428
429
430
431
432
433
434



435
436
437
438
439
440
441
442




443
444
445
446
447
448
449
450
451
452









453
454
455
456
457
458
459
460







461
462
463
464
465
466








467
468



469
470
471
472
473
474
475
269
270
271
272
273
274
275

276
277
278
279
280
281
282




283
284
285
286
287

288



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304





305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324





325
326
327
328
329
330
331
332



333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350


351
352
353
354
355
356
357
358




359
360
361
362
363
364
365
366
367
368









369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388








389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416

417
418

419
420
421
422

423
424

425
426
427
428
429



430
431
432


433
434




435
436
437
438
439









440
441
442
443
444
445
446
447
448
449







450
451
452
453
454
455
456


457
458
459
460
461
462
463
464
465
466
467
468


469
470
471
472
473
474
475
476
477
478







-
+






-
-
-
-
+
+
+
+

-
+
-
-
-
+
+














-
-
-
-
-
+
+
+
+
















-
-
-
-
-
+
+
+
+
+



-
-
-
+
+
+

-
+













-
-
+
+






-
-
-
-
+
+
+
+






-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+











-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+




















-
+

-
+



-
+

-
+




-
-
-
+
+
+
-
-


-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-




+
+
+
+
+
+
+
+
-
-
+
+
+







# cmd -	Which action to take: prev, next, reset.

set ::tk::HistNum 1
proc ::tk::ConsoleHistory {cmd} {
    variable HistNum

    switch $cmd {
	prev {
    	prev {
	    incr HistNum -1
	    if {$HistNum == 0} {
		set cmd {history event [expr {[history nextid] -1}]}
	    } else {
		set cmd "history event $HistNum"
	    }
	    if {[catch {consoleinterp eval $cmd} cmd]} {
		incr HistNum
		return
	    }
    	    if {[catch {consoleinterp eval $cmd} cmd]} {
    	    	incr HistNum
    	    	return
    	    }
	    .console delete promptEnd end
	    .console insert promptEnd $cmd {input stdin}
    	    .console insert promptEnd $cmd {input stdin}
	    .console see end
	}
	next {
    	}
    	next {
	    incr HistNum
	    if {$HistNum == 0} {
		set cmd {history event [expr {[history nextid] -1}]}
	    } elseif {$HistNum > 0} {
		set cmd ""
		set HistNum 1
	    } else {
		set cmd "history event $HistNum"
	    }
	    if {$cmd ne ""} {
		catch {consoleinterp eval $cmd} cmd
	    }
	    .console delete promptEnd end
	    .console insert promptEnd $cmd {input stdin}
	    .console see end
	}
	reset {
	    set HistNum 1
	}
    	}
    	reset {
    	    set HistNum 1
    	}
    }
}

# ::tk::ConsolePrompt --
# This procedure draws the prompt.  If tcl_prompt1 or tcl_prompt2
# exists in the main interpreter it will be called to generate the
# prompt.  Otherwise, a hard coded default prompt is printed.
#
# Arguments:
# partial -	Flag to specify which prompt to print.

proc ::tk::ConsolePrompt {{partial normal}} {
    set w .console
    if {$partial eq "normal"} {
	set temp [$w index "end - 1 char"]
	$w mark set output end
	if {[consoleinterp eval "info exists tcl_prompt1"]} {
	    consoleinterp eval "eval \[set tcl_prompt1\]"
	} else {
	    puts -nonewline [EvalAttached $::tk::console::defaultPrompt]
	}
    	if {[consoleinterp eval "info exists tcl_prompt1"]} {
    	    consoleinterp eval "eval \[set tcl_prompt1\]"
    	} else {
    	    puts -nonewline [EvalAttached $::tk::console::defaultPrompt]
    	}
    } else {
	set temp [$w index output]
	$w mark set output end
	if {[consoleinterp eval "info exists tcl_prompt2"]} {
	    consoleinterp eval "eval \[set tcl_prompt2\]"
	} else {
    	if {[consoleinterp eval "info exists tcl_prompt2"]} {
    	    consoleinterp eval "eval \[set tcl_prompt2\]"
    	} else {
	    puts -nonewline "> "
	}
    	}
    }
    flush stdout
    $w mark set output $temp
    ::tk::TextSetCursor $w end
    $w mark set promptEnd insert
    $w mark gravity promptEnd left
    ::tk::console::ConstrainBuffer $w $::tk::console::maxLines
    $w see end
}

# Copy selected text from the console
proc ::tk::console::Copy {w} {
    if {![catch {set data [$w get sel.first sel.last]}]} {
	clipboard clear -displayof $w
	clipboard append -displayof $w $data
        clipboard clear -displayof $w
        clipboard append -displayof $w $data
    }
}
# Copies selected text. If the selection is within the current active edit
# region then it will be cut, if not it is only copied.
proc ::tk::console::Cut {w} {
    if {![catch {set data [$w get sel.first sel.last]}]} {
	clipboard clear -displayof $w
	clipboard append -displayof $w $data
	if {[$w compare sel.first >= output]} {
	    $w delete sel.first sel.last
        clipboard clear -displayof $w
        clipboard append -displayof $w $data
        if {[$w compare sel.first >= output]} {
            $w delete sel.first sel.last
	}
    }
}
# Paste text from the clipboard
proc ::tk::console::Paste {w} {
    catch {
	set clip [::tk::GetSelection $w CLIPBOARD]
	set list [split $clip \n\r]
	tk::ConsoleInsert $w [lindex $list 0]
	foreach x [lrange $list 1 end] {
	    $w mark set insert {end - 1c}
	    tk::ConsoleInsert $w "\n"
	    tk::ConsoleInvoke
	    tk::ConsoleInsert $w $x
	}
        set clip [::tk::GetSelection $w CLIPBOARD]
        set list [split $clip \n\r]
        tk::ConsoleInsert $w [lindex $list 0]
        foreach x [lrange $list 1 end] {
            $w mark set insert {end - 1c}
            tk::ConsoleInsert $w "\n"
            tk::ConsoleInvoke
            tk::ConsoleInsert $w $x
        }
    }
}

# Fit TkConsoleFont to window width
proc ::tk::console::FitScreenWidth {w} {
    set width [winfo screenwidth $w]
    set cwidth [$w cget -width]
    set s -50
    set fit 0
    array set fi [font configure TkConsoleFont]
    while {$s < 0} {
	set fi(-size) $s
	set f [font create {*}[array get fi]]
	set c [font measure $f "eM"]
	font delete $f
	if {$c * $cwidth < 1.667 * $width} {
	    font configure TkConsoleFont -size $s
	    break
	}
        set fi(-size) $s
        set f [font create {*}[array get fi]]
        set c [font measure $f "eM"]
        font delete $f
        if {$c * $cwidth < 1.667 * $width} {
            font configure TkConsoleFont -size $s
            break
        }
	incr s 2
    }
}

# ::tk::ConsoleBind --
# This procedure first ensures that the default bindings for the Text
# class have been defined.  Then certain bindings are overridden for
# the class.
#
# Arguments:
# None.

proc ::tk::ConsoleBind {w} {
    bindtags $w [list $w Console PostConsole [winfo toplevel $w] all]

    ## Get all Text bindings into Console
    foreach ev [bind Text] {
	bind Console $ev [bind Text $ev]
    }
    ## We really didn't want the newline insertion...
    bind Console <Control-o> {}
    bind Console <Control-Key-o> {}
    ## ...or any Control-v binding (would block <<Paste>>)
    bind Console <Control-v> {}
    bind Console <Control-Key-v> {}

    # For the moment, transpose isn't enabled until the console
    # gets and overhaul of how it handles input -- hobbs
    bind Console <Control-t> {}
    bind Console <Control-Key-t> {}

    # Ignore all Alt, Meta, Control, Command, and Fn keypresses unless explicitly bound.
    # Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
    # Otherwise, if a widget binding for one of these is defined, the
    # <Keypress> class binding will also fire and insert the character
    # which is wrong.

    bind Console <Alt-Key> {# nothing }
    bind Console <Meta-Key> {# nothing}
    bind Console <Control-Key> {# nothing}
    bind Console <Alt-KeyPress> {# nothing }
    bind Console <Meta-KeyPress> {# nothing}
    bind Console <Control-KeyPress> {# nothing}
    bind Console <Command-Key> {# nothing}
    bind Console <Fn-Key> {# nothing}

    foreach {ev key} {
	<<Console_NextImmediate>>	<Control-n>
	<<Console_PrevImmediate>>	<Control-p>
	<<Console_PrevSearch>>		<Control-r>
	<<Console_NextSearch>>		<Control-s>
	<<Console_NextImmediate>>	<Control-Key-n>
	<<Console_PrevImmediate>>	<Control-Key-p>
	<<Console_PrevSearch>>		<Control-Key-r>
	<<Console_NextSearch>>		<Control-Key-s>

	<<Console_Expand>>		<Tab>
	<<Console_Expand>>		<Escape>
	<<Console_ExpandFile>>		<Control-Shift-F>
	<<Console_ExpandProc>>		<Control-Shift-P>
	<<Console_ExpandVar>>		<Control-Shift-V>
	<<Console_Tab>>			<Control-i>
	<<Console_Tab>>			<Meta-i>
	<<Console_Eval>>		<Return>
	<<Console_Eval>>		<KP_Enter>
	<<Console_Expand>>		<Key-Tab>
	<<Console_Expand>>		<Key-Escape>
	<<Console_ExpandFile>>		<Control-Shift-Key-F>
	<<Console_ExpandProc>>		<Control-Shift-Key-P>
	<<Console_ExpandVar>>		<Control-Shift-Key-V>
	<<Console_Tab>>			<Control-Key-i>
	<<Console_Tab>>			<Meta-Key-i>
	<<Console_Eval>>		<Key-Return>
	<<Console_Eval>>		<Key-KP_Enter>

	<<Console_Clear>>		<Control-l>
	<<Console_KillLine>>		<Control-k>
	<<Console_Transpose>>		<Control-t>
	<<Console_ClearLine>>		<Control-u>
	<<Console_SaveCommand>>		<Control-z>
	<<Console_FontSizeIncr>>	<Control-+>
	<<Console_FontSizeDecr>>	<Control-minus>
	<<Console_Clear>>		<Control-Key-l>
	<<Console_KillLine>>		<Control-Key-k>
	<<Console_Transpose>>		<Control-Key-t>
	<<Console_ClearLine>>		<Control-Key-u>
	<<Console_SaveCommand>>		<Control-Key-z>
        <<Console_FontSizeIncr>>	<Control-Key-plus>
        <<Console_FontSizeDecr>>	<Control-Key-minus>
	<<Console_FontSizeIncr>>	<Command-+>
	<<Console_FontSizeDecr>>	<Command-minus>
    } {
	event add $ev $key
	bind Console $key {}
    }
    if {[tk windowingsystem] eq "aqua"} {
	foreach {ev key} {
	    <<Console_FontSizeIncr>>	<Command-Key-plus>
	    <<Console_FontSizeDecr>>	<Command-Key-minus>
	} {
	    event add $ev $key
	    bind Console $key {}
	}
    if {$::tk::console::useFontchooser} {
	bind Console <Command-t> [list ::tk::console::FontchooserToggle]
	if {$::tk::console::useFontchooser} {
	    bind Console <Command-Key-t> [list ::tk::console::FontchooserToggle]
	}
    }
    bind Console <<Console_Expand>> {
	if {[%W compare insert > promptEnd]} {
	    ::tk::console::Expand %W
	}
    }
    bind Console <<Console_ExpandFile>> {
578
579
580
581
582
583
584
585

586
587
588
589
590


591

592
593



594
595
596
597
598
599
600
601
602
603




604
605
606
607
608
609
610
611
612
613





614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630

631
632
633
634
635

636
637
638
639
640

641
642
643
644
645
646

647
648
649
650
651
652
653
581
582
583
584
585
586
587

588
589
590
591


592
593
594
595


596
597
598
599
600
601
602
603
604




605
606
607
608
609
610
611
612
613





614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629

630
631
632
633
634

635
636
637
638
639

640
641
642
643
644

645
646
647
648
649
650

651
652
653
654
655
656
657
658







-
+



-
-
+
+

+
-
-
+
+
+






-
-
-
-
+
+
+
+





-
-
-
-
-
+
+
+
+
+











-
+




-
+




-
+




-
+





-
+







    }
    bind Console <<NextLine>> {
	tk::ConsoleHistory next
    }
    bind Console <Insert> {
	catch {tk::ConsoleInsert %W [::tk::GetSelection %W PRIMARY]}
    }
    bind Console <Key> {
    bind Console <KeyPress> {
	tk::ConsoleInsert %W %A
    }
    bind Console <F9> {
	destroy {*}[winfo children .]
	source -encoding utf-8 [file join $tk_library console.tcl]
	eval destroy [winfo child .]
	source [file join $tk_library console.tcl]
    }
    if {[tk windowingsystem] eq "aqua"} {
    bind Console <Command-q> {
	exit
	bind Console <Command-q> {
	    exit
	}
    }
    bind Console <<Cut>> { ::tk::console::Cut %W }
    bind Console <<Copy>> { ::tk::console::Copy %W }
    bind Console <<Paste>> { ::tk::console::Paste %W }

    bind Console <<Console_FontSizeIncr>> {
	set size [font configure TkConsoleFont -size]
	if {$size < 0} {set sign -1} else {set sign 1}
	set size [expr {(abs($size) + 1) * $sign}]
	font configure TkConsoleFont -size $size
        set size [font configure TkConsoleFont -size]
        if {$size < 0} {set sign -1} else {set sign 1}
        set size [expr {(abs($size) + 1) * $sign}]
        font configure TkConsoleFont -size $size
	if {$::tk::console::useFontchooser} {
	    tk fontchooser configure -font TkConsoleFont
	}
    }
    bind Console <<Console_FontSizeDecr>> {
	set size [font configure TkConsoleFont -size]
	if {abs($size) < 2} { return }
	if {$size < 0} {set sign -1} else {set sign 1}
	set size [expr {(abs($size) - 1) * $sign}]
	font configure TkConsoleFont -size $size
        set size [font configure TkConsoleFont -size]
        if {abs($size) < 2} { return }
        if {$size < 0} {set sign -1} else {set sign 1}
        set size [expr {(abs($size) - 1) * $sign}]
        font configure TkConsoleFont -size $size
	if {$::tk::console::useFontchooser} {
	    tk fontchooser configure -font TkConsoleFont
	}
    }
    bind Console <<Console_FitScreenWidth>> {
	::tk::console::FitScreenWidth %W
    }

    ##
    ## Bindings for doing special things based on certain keys
    ##
    bind PostConsole <)> {
    bind PostConsole <Key-parenright> {
	if {"\\" ne [%W get insert-2c]} {
	    ::tk::console::MatchPair %W \( \) promptEnd
	}
    }
    bind PostConsole <bracketright> {
    bind PostConsole <Key-bracketright> {
	if {"\\" ne [%W get insert-2c]} {
	    ::tk::console::MatchPair %W \[ \] promptEnd
	}
    }
    bind PostConsole <braceright> {
    bind PostConsole <Key-braceright> {
	if {"\\" ne [%W get insert-2c]} {
	    ::tk::console::MatchPair %W \{ \} promptEnd
	}
    }
    bind PostConsole <quotedbl> {
    bind PostConsole <Key-quotedbl> {
	if {"\\" ne [%W get insert-2c]} {
	    ::tk::console::MatchQuote %W promptEnd
	}
    }

    bind PostConsole <Key> {
    bind PostConsole <KeyPress> {
	if {"%A" ne ""} {
	    ::tk::console::TagProc %W
	}
    }
}

# ::tk::ConsoleInsert --
729
730
731
732
733
734
735
736

737
738

739
740
741
742
743
744
745
734
735
736
737
738
739
740

741
742

743
744
745
746
747
748
749
750







-
+

-
+







	tk fontchooser hide
    } else {
	tk fontchooser show
    }
}
proc ::tk::console::FontchooserVisibility {index} {
    if {[tk fontchooser configure -visible]} {
	.menubar.edit entryconfigure $index -label [::tk::msgcat::mc "Hide Fonts"]
	.menubar.edit entryconfigure $index -label [msgcat::mc "Hide Fonts"]
    } else {
	.menubar.edit entryconfigure $index -label [::tk::msgcat::mc "Show Fonts"]
	.menubar.edit entryconfigure $index -label [msgcat::mc "Show Fonts"]
    }
}
proc ::tk::console::FontchooserFocus {w isFocusIn} {
    if {$isFocusIn} {
	tk fontchooser configure -parent $w -font TkConsoleFont \
		-command [namespace code [list FontchooserApply]]
    } else {

Changes to library/demos/anilabel.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# anilabel.tcl --
#
# This demonstration script creates a toplevel window containing
# several animated label widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .anilabel
catch {destroy $w}
toplevel $w
wm title $w "Animated Label Demonstration"
wm iconname $w "anilabel"
positionWindow $w
62
63
64
65
66
67
68
69

70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126




127
128
129

130
131
132
133
134
135
136
62
63
64
65
66
67
68

69
70
71

72
73
74
75
76
77
78
79
80
81
82

83
84

85
86
87
88
89









90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114




115
116
117
118
119
120

121
122
123
124
125
126
127
128







-
+


-
+










-


-
+




-
-
-
-
-
-
-
-
-
+
+




















-
+


-
-
-
-
+
+
+
+


-
+







	unset animationCallbacks(%W)
    }
}

## Next, a similar pair of procedures to animate a GIF loaded into a
## photo image.
proc SelectNextImageFrame {w interval} {
    global animationCallbacks image zoomFactor
    global animationCallbacks
    set animationCallbacks($w) \
	    [after $interval SelectNextImageFrame $w $interval]
    set image2 [$w cget -image]
    set image [$w cget -image]

    # The easy way to animate a GIF!
    set idx -1
    scan [$image cget -format] "GIF -index %d" idx
    if {[catch {
	# Note that we get an error if the index is out of range
	$image configure -format "GIF -index [incr idx]"
    }]} then {
	$image configure -format "GIF -index 0"
    }
    $image2 copy $image -zoom $zoomFactor
}
proc animateLabelImage {w imageData interval} {
    global animationCallbacks image zoomFactor
    global animationCallbacks

    # Create a multi-frame GIF from base-64-encoded data
    set image [image create photo -format GIF -data $imageData]

    # Create a copy of the image just created, magnified according to the
    # display's DPI scaling level.  Since the zooom factor must be an integer,
    # the copy will only be effectively magnified if $tk::scalingPct >= 200.
    set image2 [image create photo]
    set zoomFactor [expr {$tk::scalingPct / 100}]
    $image2 copy $image -zoom $zoomFactor

    # Install the image copy into the widget
    $w configure -image $image2
    # Install the image into the widget
    $w configure -image $image

    # Schedule the start of the animation loop
    set animationCallbacks($w) \
	    [after $interval SelectNextImageFrame $w $interval]

    # Make sure that the animation stops and is cleaned up after itself
    # when the animated label is destroyed.  Note that at this point we
    # cannot manipulate the widget itself, as that has already died.
    # Also note that this script is in double-quotes; this is always OK
    # because image names are chosen automatically to be simple words.
    bind $w <Destroy> "
	after cancel \$animationCallbacks(%W)
	unset animationCallbacks(%W)
	rename $image {}
    "
}

# Make some widgets to contain the animations
labelframe $w.left -text "Scrolling Texts"
labelframe $w.right -text "GIF Image"
pack $w.left $w.right -side left -padx 7.5p -pady 7.5p -expand yes
pack $w.left $w.right -side left -padx 10 -pady 10 -expand yes

# This method of scrolling text looks far better with a fixed-width font
label $w.left.l1 -bd 3p -relief ridge -font fixedFont
label $w.left.l2 -bd 3p -relief groove -font fixedFont
label $w.left.l3 -bd 3p -relief flat -font fixedFont -width 18
pack $w.left.l1 $w.left.l2 $w.left.l3 -side top -expand yes -padx 7.5p -pady 7.5p -anchor w
label $w.left.l1 -bd 4 -relief ridge -font fixedFont
label $w.left.l2 -bd 4 -relief groove -font fixedFont
label $w.left.l3 -bd 4 -relief flat -font fixedFont -width 18
pack $w.left.l1 $w.left.l2 $w.left.l3 -side top -expand yes -padx 10 -pady 10 -anchor w
# Don't need to do very much with this label except turn off the border
label $w.right.l -bd 0
pack $w.right.l -side top -expand yes -padx 7.5p -pady 7.5p
pack $w.right.l -side top -expand yes -padx 10 -pady 10

# This is a base-64-encoded animated GIF file.
set tclPoweredData {
    R0lGODlhKgBAAPQAAP//////zP//AP/MzP/Mmf/MAP+Zmf+ZZv+ZAMz//8zM
    zMyZmcyZZsxmZsxmAMwzAJnMzJmZzJmZmZlmmZlmZplmM5kzM2aZzGZmzGZm
    mWZmZmYzZmYzMzNmzDMzZgAzmSH+IE1hZGUgd2l0aCBHSU1QIGJ5IExARGVt
    YWlsbHkuY29tACH5BAVkAAEALAAAAAAqAEAAAAX+YCCOZEkyTKM2jOm66yPP

Changes to library/demos/aniwave.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49



50
51
52
53
54
55
56










-
+

















-
+














-
+





-
-
-







# aniwave.tcl --
#
# This demonstration script illustrates how to adjust canvas item
# coordinates in a way that does something fairly similar to waveform
# display.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .aniwave
catch {destroy $w}
toplevel $w
wm title $w "Animated Wave Demonstration"
wm iconname $w "aniwave"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration contains a canvas widget with a line item inside it. The animation routines work by adjusting the coordinates list of the line; a trace on a variable is used so updates to the variable result in a change of position of the line."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

# Create a canvas large enough to hold the wave. In fact, the wave
# sticks off both sides of the canvas to prevent visual glitches.
pack [canvas $w.c -width 225p -height 150p -background black] -padx 7.5p -pady 7.5p -expand yes
pack [canvas $w.c -width 300 -height 200 -background black] -padx 10 -pady 10 -expand yes

# Ensure that this this is an array
array set animationCallbacks {}

# Creates a coordinates list of a wave. This code does a very sketchy
# job and relies on Tk's line smoothing to make things look better.
set waveCoords {}
for {set x -10} {$x<=300} {incr x 5} {
    lappend waveCoords $x 100
}
lappend waveCoords $x 0 [incr x 5] 200

# Create a smoothed line and arrange for its coordinates to be the
# contents of the variable waveCoords.
$w.c create line $waveCoords -tags wave -width 0.75p -fill green -smooth 1
$w.c create line $waveCoords -tags wave -width 1 -fill green -smooth 1
proc waveCoordsTracer {w args} {
    global waveCoords
    # Actual visual update will wait until we have finished
    # processing; Tk does that for us automatically.
    $w.c coords wave $waveCoords

    set scaleFactor [expr {$tk::scalingPct / 100.0}]
    $w.c scale wave 0 0 $scaleFactor $scaleFactor
}
trace add variable waveCoords write [list waveCoordsTracer $w]

# Basic motion handler. Given what direction the wave is travelling
# in, it advances the y coordinates in the coordinate-list one step in
# that direction.
proc basicMotion {} {

Changes to library/demos/arrow.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9

10










11
12
13
14
15
16
17









-
+
-
-
-
-
-
-
-
-
-
-







# arrow.tcl --
#
# This demonstration script creates a canvas widget that displays a
# large line with an arrowhead whose shape can be edited interactively.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# scl --
# Scales an integer according to the display's current scaling percentage.
#
# Arguments:
#   num -	An integer.

proc scl num {
    return [expr {round($num*$tk::scalingPct/100.0)}]
}

# arrowSetup --
# This procedure regenerates all the text and graphics in the canvas
# window.  It's called when the canvas is initially created, and also
# whenever any of the parameters of the arrow head are changed
# interactively.
#
39
40
41
42
43
44
45
46

47
48
49


50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67









68
69

70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88












89
90
91
92
93

94
95
96
97

98
99

100
101
102
103
104


105
106
107

108
109

110
111
112

113
114
115

116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144




145
146
147
148
149




150
151
152
153

154
155
156
157
158


159
160
161
162
163
164


165
166
167
168
169
170
171
172
173



174
175

176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220


221
222

223
224
225
226
227
228


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254


255
256
257
258
259
260
29
30
31
32
33
34
35

36
37


38
39
40
41
42
43

44
45
46
47










48
49
50
51
52
53
54
55
56
57

58
59
60

61
62















63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82

83
84

85
86
87
88


89
90
91
92

93
94

95
96
97

98
99
100

101
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126




127
128
129
130
131




132
133
134
135
136
137


138





139
140
141
142
143
144


145
146
147
148
149
150
151
152



153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197



198
199
200

201
202
203
204



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229



230
231
232
233
234
235
236
237







-
+

-
-
+
+




-
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+




-
+



-
+

-
+



-
-
+
+


-
+

-
+


-
+


-
+

-
+




















-
+


-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+


-
-
+
-
-
-
-
-
+
+




-
-
+
+






-
-
-
+
+
+

-
+












-
+



-
-
-
+
+


















-
-
+



-
-
-
+
+

-
+



-
-
-
+
+



















-
+



-
-
-
+
+






    } else {
	set cur ""
    }

    # Create the arrow and outline.

    $c delete all
    $c create line $v(x1) $v(y) $v(x2) $v(y) -arrow last \
    eval {$c create line $v(x1) $v(y) $v(x2) $v(y)  -arrow last \
	    -width [expr {10*$v(width)}] -arrowshape [list \
	    [expr {10*$v(a)}] [expr {10*$v(b)}] [expr {10*$v(c)}]] \
	    {*}$v(bigLineStyle)
	    [expr {10*$v(a)}] [expr {10*$v(b)}] [expr {10*$v(c)}]]} \
	    $v(bigLineStyle)
    set xtip [expr {$v(x2)-10*$v(b)}]
    set deltaY [expr {10*$v(c)+5*$v(width)}]
    $c create line $v(x2) $v(y) $xtip [expr {$v(y)+$deltaY}] \
	    [expr {$v(x2)-10*$v(a)}] $v(y) $xtip [expr {$v(y)-$deltaY}] \
	    $v(x2) $v(y) -width 1.5p -capstyle round -joinstyle round
	    $v(x2) $v(y) -width 2 -capstyle round -joinstyle round

    # Create the boxes for reshaping the line and arrowhead.

    set _5 [scl 5]
    $c create rect [expr {$v(x2)-10*$v(a)-$_5}] [expr {$v(y)-$_5}] \
	    [expr {$v(x2)-10*$v(a)+$_5}] [expr {$v(y)+$_5}] \
	    -tags {box1 box} {*}$v(boxStyle)
    $c create rect [expr {$xtip-$_5}] [expr {$v(y)-$deltaY-$_5}] \
	    [expr {$xtip+$_5}] [expr {$v(y)-$deltaY+$_5}] \
	    -tags {box2 box} {*}$v(boxStyle)
    $c create rect [expr {$v(x1)-$_5}] [expr {$v(y)-5*$v(width)-$_5}] \
	    [expr {$v(x1)+$_5}] [expr {$v(y)-5*$v(width)+$_5}] \
	    -tags {box3 box} {*}$v(boxStyle)
    eval {$c create rect [expr {$v(x2)-10*$v(a)-5}] [expr {$v(y)-5}] \
	    [expr {$v(x2)-10*$v(a)+5}] [expr {$v(y)+5}] \
	    -tags {box1 box}} $v(boxStyle)
    eval {$c create rect [expr {$xtip-5}] [expr {$v(y)-$deltaY-5}] \
	    [expr {$xtip+5}] [expr {$v(y)-$deltaY+5}] \
	    -tags {box2 box}} $v(boxStyle)
    eval {$c create rect [expr {$v(x1)-5}] [expr {$v(y)-5*$v(width)-5}] \
	    [expr {$v(x1)+5}] [expr {$v(y)-5*$v(width)+5}] \
	    -tags {box3 box}} $v(boxStyle)
    if {$cur != ""} {
	$c itemconfigure $cur {*}$v(activeStyle)
	eval $c itemconfigure $cur $v(activeStyle)
    }

    # Create three arrows in actual size with the same parameters.
    # Create three arrows in actual size with the same parameters

    set _10  [scl 10]
    set _15  [scl 15]
    set _25  [scl 25]
    set _50  [scl 50]
    set _75  [scl 75]
    set _125 [scl 125]
    $c create line [expr {$v(x2)+$_50}] 0 [expr {$v(x2)+$_50}] 750p -width 1.5p
    set tmp [expr {$v(x2)+[scl 100]}]
    $c create line $tmp [expr {$v(y)-$_125}] $tmp [expr {$v(y)-$_75}] \
	    -width $v(width) -arrow both -arrowshape "$v(a) $v(b) $v(c)"
    $c create line [expr {$tmp-$_25}] $v(y) [expr {$tmp+$_25}] $v(y) \
	    -width $v(width) -arrow both -arrowshape "$v(a) $v(b) $v(c)"
    $c create line [expr {$tmp-$_25}] [expr {$v(y)+$_75}] \
	    [expr {$tmp+$_25}] [expr {$v(y)+$_125}] \
	    -width $v(width) -arrow both -arrowshape "$v(a) $v(b) $v(c)"
    $c create line [expr {$v(x2)+50}] 0 [expr {$v(x2)+50}] 1000 \
	    -width 2
    set tmp [expr {$v(x2)+100}]
    $c create line $tmp [expr {$v(y)-125}] $tmp [expr {$v(y)-75}] \
	    -width $v(width) \
	    -arrow both -arrowshape "$v(a) $v(b) $v(c)"
    $c create line [expr {$tmp-25}] $v(y) [expr {$tmp+25}] $v(y) \
	    -width $v(width) \
	    -arrow both -arrowshape "$v(a) $v(b) $v(c)"
    $c create line [expr {$tmp-25}] [expr {$v(y)+75}] [expr {$tmp+25}] \
	    [expr {$v(y)+125}] -width $v(width) \
	    -arrow both -arrowshape "$v(a) $v(b) $v(c)"

    # Create a bunch of other arrows and text items showing the
    # current dimensions.

    set tmp [expr {$v(x2)+$_10}]
    set tmp [expr {$v(x2)+10}]
    $c create line $tmp [expr {$v(y)-5*$v(width)}] \
	    $tmp [expr {$v(y)-$deltaY}] \
	    -arrow both -arrowshape $v(smallTips)
    $c create text [expr {$v(x2)+$_15}] [expr {$v(y)-$deltaY+5*$v(c)}] \
    $c create text [expr {$v(x2)+15}] [expr {$v(y)-$deltaY+5*$v(c)}] \
	    -text $v(c) -anchor w
    set tmp [expr {$v(x1)-$_10}]
    set tmp [expr {$v(x1)-10}]
    $c create line $tmp [expr {$v(y)-5*$v(width)}] \
	    $tmp [expr {$v(y)+5*$v(width)}] \
	    -arrow both -arrowshape $v(smallTips)
    $c create text [expr {$v(x1)-$_15}] $v(y) -text $v(width) -anchor e
    set tmp [expr {$v(y)+5*$v(width)+10*$v(c)+$_10}]
    $c create text [expr {$v(x1)-15}] $v(y) -text $v(width) -anchor e
    set tmp [expr {$v(y)+5*$v(width)+10*$v(c)+10}]
    $c create line [expr {$v(x2)-10*$v(a)}] $tmp $v(x2) $tmp \
	    -arrow both -arrowshape $v(smallTips)
    $c create text [expr {$v(x2)-5*$v(a)}] [expr {$tmp+$_5}] \
    $c create text [expr {$v(x2)-5*$v(a)}] [expr {$tmp+5}] \
	    -text $v(a) -anchor n
    set tmp [expr {$tmp+$_25}]
    set tmp [expr {$tmp+25}]
    $c create line [expr {$v(x2)-10*$v(b)}] $tmp $v(x2) $tmp \
	    -arrow both -arrowshape $v(smallTips)
    $c create text [expr {$v(x2)-5*$v(b)}] [expr {$tmp+$_5}] \
    $c create text [expr {$v(x2)-5*$v(b)}] [expr {$tmp+5}] \
	    -text $v(b) -anchor n

    $c create text $v(x1) 232.5p -text "-width  $v(width)" \
    $c create text $v(x1) 310 -text "-width  $v(width)" \
	    -anchor w -font {Helvetica 18}
    $c create text $v(x1) 247.5p -text "-arrowshape  {$v(a)  $v(b)  $v(c)}" \
    $c create text $v(x1) 330 -text "-arrowshape  {$v(a)  $v(b)  $v(c)}" \
	    -anchor w -font {Helvetica 18}

    incr v(count)
}

set w .arrow
catch {destroy $w}
toplevel $w
wm title $w "Arrowhead Editor Demonstration"
wm iconname $w "arrow"
positionWindow $w
set c $w.c

label $w.msg -font $font -wraplength 5i -justify left -text "This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases.  To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow.  The arrows on the right give examples at normal scale.  The text at the bottom shows the configuration options as you'd enter them for a canvas line item."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

canvas $c -width 375p -height 262.5p -relief sunken -borderwidth 2
canvas $c -width 500 -height 350 -relief sunken -borderwidth 2
pack $c -expand yes -fill both

set demo_arrowInfo(a)	  [scl 8]
set demo_arrowInfo(b)	  [scl 10]
set demo_arrowInfo(c)	  [scl 3]
set demo_arrowInfo(width) [scl 2]
set demo_arrowInfo(a) 8
set demo_arrowInfo(b) 10
set demo_arrowInfo(c) 3
set demo_arrowInfo(width) 2
set demo_arrowInfo(motionProc) arrowMoveNull
set demo_arrowInfo(x1)	  [scl 40]
set demo_arrowInfo(x2)	  [scl 350]
set demo_arrowInfo(y)	  [scl 150]
set demo_arrowInfo(smallTips) {3.75p 3.75p 1.5p}
set demo_arrowInfo(x1) 40
set demo_arrowInfo(x2) 350
set demo_arrowInfo(y) 150
set demo_arrowInfo(smallTips) {5 5 2}
set demo_arrowInfo(count) 0
if {[winfo depth $c] > 1} {
    if {[tk windowingsystem] eq "aqua"} {
	set demo_arrowInfo(bigLineStyle) "-fill systemSelectedTextBackgroundColor"
    set demo_arrowInfo(bigLineStyle) "-fill SkyBlue1"
    } else {
	set demo_arrowInfo(bigLineStyle) "-fill LightSeaGreen"
    }
    set demo_arrowInfo(boxStyle) "-fill {} -width 0.75p"
    set demo_arrowInfo(activeStyle) "-fill red -width 0.75p"
    set demo_arrowInfo(boxStyle) "-fill {} -outline black -width 1"
    set demo_arrowInfo(activeStyle) "-fill red -outline black -width 1"
} else {
    # Main widget program sets variable tk_demoDirectory
    set demo_arrowInfo(bigLineStyle) "-fill black \
	-stipple @[file join $tk_demoDirectory images grey.25]"
    set demo_arrowInfo(boxStyle) "-fill {} -outline black -width 0.75p"
    set demo_arrowInfo(activeStyle) "-fill black -outline black -width 0.75p"
    set demo_arrowInfo(boxStyle) "-fill {} -outline black -width 1"
    set demo_arrowInfo(activeStyle) "-fill black -outline black -width 1"
}
arrowSetup $c
$c bind box <Enter> "$c itemconfigure current $demo_arrowInfo(activeStyle)"
$c bind box <Leave> "$c itemconfigure current $demo_arrowInfo(boxStyle)"
$c bind box <B1-Enter> " "
$c bind box <B1-Leave> " "
$c bind box1 <Button-1> {set demo_arrowInfo(motionProc) arrowMove1}
$c bind box2 <Button-1> {set demo_arrowInfo(motionProc) arrowMove2}
$c bind box3 <Button-1> {set demo_arrowInfo(motionProc) arrowMove3}
$c bind box1 <1> {set demo_arrowInfo(motionProc) arrowMove1}
$c bind box2 <1> {set demo_arrowInfo(motionProc) arrowMove2}
$c bind box3 <1> {set demo_arrowInfo(motionProc) arrowMove3}
$c bind box <B1-Motion> "\$demo_arrowInfo(motionProc) $c %x %y"
bind $c <ButtonRelease-1> "arrowSetup $c"
bind $c <Any-ButtonRelease-1> "arrowSetup $c"

# arrowMove1 --
# This procedure is called for each mouse motion event on box1 (the
# one at the vertex of the arrow).  It updates the controlling parameters
# for the line and arrowhead.
#
# Arguments:
# c -		The name of the canvas window.
# x, y -	The coordinates of the mouse.

proc arrowMove1 {c x y} {
    upvar #0 demo_arrowInfo v
    set newA [expr {($v(x2)+[scl 5]-round([$c canvasx $x]))/10}]
    set newA [expr {($v(x2)+5-round([$c canvasx $x]))/10}]
    if {$newA < 0} {
	set newA 0
    }
    set _25 [scl 25]
    if {$newA > $_25} {
	set newA $_25
    if {$newA > 25} {
	set newA 25
    }
    if {$newA != $v(a)} {
	$c move box1 [expr {10*($v(a)-$newA)}] 0
	set v(a) $newA
    }
}

# arrowMove2 --
# This procedure is called for each mouse motion event on box2 (the
# one at the trailing tip of the arrowhead).  It updates the controlling
# parameters for the line and arrowhead.
#
# Arguments:
# c -		The name of the canvas window.
# x, y -	The coordinates of the mouse.

proc arrowMove2 {c x y} {
    upvar #0 demo_arrowInfo v
    set _5 [scl 5]
    set newB [expr {($v(x2)+$_5-round([$c canvasx $x]))/10}]
    set newB [expr {($v(x2)+5-round([$c canvasx $x]))/10}]
    if {$newB < 0} {
	set newB 0
    }
    set _25 [scl 25]
    if {$newB > $_25} {
	set newB $_25
    if {$newB > 25} {
	set newB 25
    }
    set newC [expr {($v(y)+$_5-round([$c canvasy $y])-5*$v(width))/10}]
    set newC [expr {($v(y)+5-round([$c canvasy $y])-5*$v(width))/10}]
    if {$newC < 0} {
	set newC 0
    }
    set _20 [scl 20]
    if {$newC > $_20} {
	set newC $_20
    if {$newC > 20} {
	set newC 20
    }
    if {($newB != $v(b)) || ($newC != $v(c))} {
	$c move box2 [expr {10*($v(b)-$newB)}] [expr {10*($v(c)-$newC)}]
	set v(b) $newB
	set v(c) $newC
    }
}

# arrowMove3 --
# This procedure is called for each mouse motion event on box3 (the
# one that controls the thickness of the line).  It updates the
# controlling parameters for the line and arrowhead.
#
# Arguments:
# c -		The name of the canvas window.
# x, y -	The coordinates of the mouse.

proc arrowMove3 {c x y} {
    upvar #0 demo_arrowInfo v
    set newWidth [expr {($v(y)+[scl 2]-round([$c canvasy $y]))/5}]
    set newWidth [expr {($v(y)+2-round([$c canvasy $y]))/5}]
    if {$newWidth < 0} {
	set newWidth 0
    }
    set _20 [scl 20]
    if {$newWidth > $_20} {
	set newWidth $_20
    if {$newWidth > 20} {
	set newWidth 20
    }
    if {$newWidth != $v(width)} {
	$c move box3 0 [expr {5*($v(width)-$newWidth)}]
	set v(width) $newWidth
    }
}

Changes to library/demos/bind.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# bind.tcl --
#
# This demonstration script creates a text widget with bindings set
# up for hypertext-like effects.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .bind
catch {destroy $w}
toplevel $w
wm title $w "Text Demonstration - Tag Bindings"
wm iconname $w "bind"
positionWindow $w
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75






76
77
78
59
60
61
62
63
64
65


66
67
68
69






70
71
72
73
74
75
76
77
78







-
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+



$w.text insert end \n\n
$w.text insert end \
{6. A grid that demonstrates how canvases can be scrolled.} d6

# Create bindings for tags.

foreach tag {d1 d2 d3 d4 d5 d6} {
    $w.text tag bind $tag <Enter> "$w.text tag configure $tag $bold"
    $w.text tag bind $tag <Leave> "$w.text tag configure $tag $normal"
    $w.text tag bind $tag <Any-Enter> "$w.text tag configure $tag $bold"
    $w.text tag bind $tag <Any-Leave> "$w.text tag configure $tag $normal"
}
# Main widget program sets variable tk_demoDirectory
$w.text tag bind d1 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory items.tcl]}
$w.text tag bind d2 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory plot.tcl]}
$w.text tag bind d3 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory ctext.tcl]}
$w.text tag bind d4 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory arrow.tcl]}
$w.text tag bind d5 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory ruler.tcl]}
$w.text tag bind d6 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory cscroll.tcl]}
$w.text tag bind d1 <1> {source [file join $tk_demoDirectory items.tcl]}
$w.text tag bind d2 <1> {source [file join $tk_demoDirectory plot.tcl]}
$w.text tag bind d3 <1> {source [file join $tk_demoDirectory ctext.tcl]}
$w.text tag bind d4 <1> {source [file join $tk_demoDirectory arrow.tcl]}
$w.text tag bind d5 <1> {source [file join $tk_demoDirectory ruler.tcl]}
$w.text tag bind d6 <1> {source [file join $tk_demoDirectory cscroll.tcl]}

$w.text mark set insert 0.0
$w.text configure -state disabled

Changes to library/demos/bitmap.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# bitmap.tcl --
#
# This demonstration script creates a toplevel window that displays
# all of Tk's built-in bitmaps.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# bitmapRow --
# Create a row of bitmap items in a window.
#
# Arguments:
# w -		The window that is to contain the row.
# args -	The names of one or more bitmaps, which will be displayed

Changes to library/demos/browse.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# browse --
# This script generates a directory browser, which lists the working
# directory and allows you to open files or subdirectories by
# double-clicking.

package require tk
package require Tk

# Create a scrollbar on the right side of the main window and a listbox
# on the left side.

scrollbar .scroll -command ".list yview"
pack .scroll -side right -fill y
listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \

Changes to library/demos/button.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# button.tcl --
#
# This demonstration script creates a toplevel window containing
# several button widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .button
catch {destroy $w}
toplevel $w
wm title $w "Button Demonstration"
wm iconname $w "button"
positionWindow $w
40
41
42
43
44
45
46
47

40
41
42
43
44
45
46

47







-
+
    -command [list colorrefresh $w PeachPuff1]
button $w.b2 -text "Light Blue" -width 10 \
    -command [list colorrefresh $w LightBlue1]
button $w.b3 -text "Sea Green" -width 10 \
    -command [list colorrefresh $w SeaGreen2]
button $w.b4 -text "Yellow" -width 10 \
    -command [list colorrefresh $w Yellow1]
pack $w.b1 $w.b2 $w.b3 $w.b4 -side top -expand yes -pady 1.5p
pack $w.b1 $w.b2 $w.b3 $w.b4 -side top -expand yes -pady 2

Changes to library/demos/check.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# check.tcl --
#
# This demonstration script creates a toplevel window containing
# several checkbuttons.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .check
catch {destroy $w}
toplevel $w
wm title $w "Checkbutton Demonstration"
wm iconname $w "check"
positionWindow $w
26
27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40
41







-
-
+
+







checkbutton $w.b0 -text "Safety Check" -variable safety -relief flat \
    -onvalue "all" \
    -offvalue "none" \
    -tristatevalue "partial"
checkbutton $w.b1 -text "Wipers OK" -variable wipers -relief flat
checkbutton $w.b2 -text "Brakes OK" -variable brakes -relief flat
checkbutton $w.b3 -text "Driver Sober" -variable sober -relief flat
pack $w.b0 -side top -pady 1.5p -anchor w
pack $w.b1 $w.b2 $w.b3 -side top -pady 1.5p -anchor w -padx 12p
pack $w.b0 -side top -pady 2 -anchor w
pack $w.b1 $w.b2 $w.b3 -side top -pady 2 -anchor w -padx 15

## This code makes $w.b0 function as a tri-state button; it's not
## needed at all for just straight yes/no buttons.

set in_check 0
proc tristate_check {n1 n2 op} {
    global safety wipers brakes sober in_check
61
62
63
64
65
66
67
68
69
70
71




61
62
63
64
65
66
67




68
69
70
71







-
-
-
-
+
+
+
+
	} else {
	    set safety none
	}
    }
    set in_check 0
}

trace add variable wipers write tristate_check
trace add variable brakes write tristate_check
trace add variable sober  write tristate_check
trace add variable safety write tristate_check
trace variable wipers w tristate_check
trace variable brakes w tristate_check
trace variable sober  w tristate_check
trace variable safety w tristate_check

Changes to library/demos/clrpick.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# clrpick.tcl --
#
# This demonstration script prompts the user to select a color.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .clrpick
catch {destroy $w}
toplevel $w
wm title $w "Color Selection Dialog"
wm iconname $w "colors"
positionWindow $w

Changes to library/demos/colors.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30

31
32
33
34
35

36
37
38
39
40
41
42
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29

30
31
32
33
34

35
36
37
38
39
40
41
42










-
+















-
+


-
+




-
+







# colors.tcl --
#
# This demonstration script creates a listbox widget that displays
# many of the colors from the X color database.  You can click on
# a color to change the application's palette.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .colors
catch {destroy $w}
toplevel $w
wm title $w "Listbox Demonstration (colors)"
wm iconname $w "Listbox"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "A listbox containing several color names is displayed below, along with a scrollbar.  You can scan the list either using the scrollbar or by dragging in the listbox window with button 2 pressed.  If you double-click button 1 on a color, then the application's color palette will be set to match that color"
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame -side top -expand yes -fill y

ttk::scrollbar $w.frame.scroll -command "$w.frame.list yview"
scrollbar $w.frame.scroll -command "$w.frame.list yview"
listbox $w.frame.list -yscroll "$w.frame.scroll set" \
	-width 20 -height 16 -setgrid 1
pack $w.frame.list $w.frame.scroll -side left -fill y -expand 1

bind $w.frame.list <Double-Button-1> {
bind $w.frame.list <Double-1> {
    tk_setPalette [selection get]
}
$w.frame.list insert 0 gray60 gray70 gray80 gray85 gray90 gray95 \
    snow1 snow2 snow3 snow4 seashell1 seashell2 \
    seashell3 seashell4 AntiqueWhite1 AntiqueWhite2 AntiqueWhite3 \
    AntiqueWhite4 bisque1 bisque2 bisque3 bisque4 PeachPuff1 \
    PeachPuff2 PeachPuff3 PeachPuff4 NavajoWhite1 NavajoWhite2 \

Changes to library/demos/combo.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# combo.tcl --
#
# This demonstration script creates several combobox widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .combo
catch {destroy $w}
toplevel $w
wm title $w "Combobox Demonstration"
wm iconname $w "combo"
positionWindow $w
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62




39
40
41
42
43
44
45

46

47
48
49
50
51
52
53
54
55
56
57




58
59
60
61







-
+
-











-
-
-
-
+
+
+
+
    Canberra Sydney Melbourne Perth Adelaide Brisbane
    Hobart Darwin "Alice Springs"
}
set secondValue unchangable
set ozCity Sydney

ttk::labelframe $w.c1 -text "Fully Editable"
ttk::combobox $w.c1.c -textvariable firstValue -placeholder {Enter text here}
ttk::combobox $w.c1.c -textvariable firstValue
ttk::style configure TEntry -placeholderforeground gray50
ttk::labelframe $w.c2 -text Disabled
ttk::combobox $w.c2.c -textvariable secondValue -state disabled
ttk::labelframe $w.c3 -text "Defined List Only"
ttk::combobox $w.c3.c -textvariable ozCity -state readonly \
	-values $australianCities
bind $w.c1.c <Return> {
    if {[%W get] ni [%W cget -values]} {
	%W configure -values [concat [%W cget -values] [list [%W get]]]
    }
}

pack $w.c1 $w.c2 $w.c3 -side top -pady 3p -padx 7.5p
pack $w.c1.c -pady 3p -padx 7.5p
pack $w.c2.c -pady 3p -padx 7.5p
pack $w.c3.c -pady 3p -padx 7.5p
pack $w.c1 $w.c2 $w.c3 -side top -pady 5 -padx 10
pack $w.c1.c -pady 5 -padx 10
pack $w.c2.c -pady 5 -padx 10
pack $w.c3.c -pady 5 -padx 10

Changes to library/demos/cscroll.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35









-
+









-
+







-
+







# cscroll.tcl --
#
# This demonstration script creates a simple canvas that can be
# scrolled in two dimensions.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .cscroll
catch {destroy $w}
toplevel $w
wm title $w "Scrollable Canvas Demonstration"
wm iconname $w "cscroll"
positionWindow $w
set c $w.c

label $w.msg -font $font -wraplength 4i -justify left -text "This window displays a canvas widget that can be scrolled by using the scrollbars, by dragging with button 2 in the canvas, by using a mouse wheel, or with the two-finger gesture on a touchpad.  If you click button 1 on one of the rectangles, its indices will be printed on stdout."
label $w.msg -font $font -wraplength 4i -justify left -text "This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas.  If you click button 1 on one of the rectangles, its indices will be printed on stdout."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.grid
scrollbar $w.hscroll -orient horizontal -command "$c xview"
scrollbar $w.hscroll -orient horiz -command "$c xview"
scrollbar $w.vscroll -command "$c yview"
canvas $c -relief sunken -borderwidth 2 -scrollregion {-11c -11c 50c 20c} \
	-xscrollcommand "$w.hscroll set" \
	-yscrollcommand "$w.vscroll set"
pack $w.grid -expand yes -fill both -padx 1 -pady 1
grid rowconfig    $w.grid 0 -weight 1 -minsize 0
grid columnconfig $w.grid 0 -weight 1 -minsize 0
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76


77
78
79
80
81
82

83
84
85

86
87
88

89
90
91
92

93
94
95

96
97
98
99
100
101
102


103
104
105
106

107
108
109
110


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158



159

160
161
162
163
164
165
166
167
168
169

170
171
172

173
174
175
176
177
178
43
44
45
46
47
48
49

50
51
52
53
54
55



56
57
58


















59
60






61
62


63



64

65


66



67

68





69
70

71


72




73
74



































75
76
77
78
79
80
81
82
83




84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108







-
+





-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+

-
-
+
-
-
-
+
-

-
-
+
-
-
-
+
-

-
-
-
-
-
+
+
-

-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
-
-
+
+
+
-
+










+



+








set bg [lindex [$c config -bg] 4]
for {set i 0} {$i < 20} {incr i} {
    set x [expr {-10 + 3*$i}]
    for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
	$c create rect ${x}c ${y}c [expr {$x+2}]c [expr {$y+2}]c \
		-fill $bg -tags rect
		-outline black -fill $bg -tags rect
	$c create text [expr {$x+1}]c [expr {$y+1}]c -text "$i,$j" \
	    -anchor center -tags text
    }
}

$c bind all <Enter> "scrollEnter $c"
$c bind all <Leave> "scrollLeave $c"
$c bind all <Button-1> "scrollButton $c"
$c bind all <Any-Enter> "scrollEnter $c"
$c bind all <Any-Leave> "scrollLeave $c"
$c bind all <1> "scrollButton $c"
if {([tk windowingsystem] eq "aqua") && ![package vsatisfies [package provide tk] 8.7-]} {
    bind $c <Button-3> "$c scan mark %x %y"
    bind $c <B3-Motion> "$c scan dragto %x %y"
    bind $c <MouseWheel> {
	%W yview scroll [expr {-%D}] units
    }
    bind $c <Option-MouseWheel> {
	%W yview scroll [expr {-10*%D}] units
    }
    bind $c <Shift-MouseWheel> {
	%W xview scroll [expr {-%D}] units
    }
    bind $c <Shift-Option-MouseWheel> {
	%W xview scroll [expr {-10*%D}] units
    }
} else {
    bind $c <Button-2> "$c scan mark %x %y"
    bind $c <B2-Motion> "$c scan dragto %x %y"
bind $c <2> "$c scan mark %x %y"
bind $c <B2-Motion> "$c scan dragto %x %y"
    # We must make sure that positive and negative movements are rounded
    # equally to integers, avoiding the problem that
    #     (int)1/-30 = -1,
    # but
    #     (int)-1/-30 = 0
    # The following code ensure equal +/- behaviour.
if {[tk windowingsystem] eq "aqua"} {
    bind $c <MouseWheel> {
	if {%D >= 0} {
	    %W yview scroll [expr {%D/-30}] units
        %W yview scroll [expr {- (%D)}] units
	} else {
	    %W yview scroll [expr {(%D-29)/-30}] units
	}
    }
    }
    bind $c <Option-MouseWheel> {
	if {%D >= 0} {
	    %W yview scroll [expr {%D/-3}] units
        %W yview scroll [expr {-10 * (%D)}] units
	} else {
	    %W yview scroll [expr {(%D-2)/-3}] units
	}
    }
    }
    bind $c <Shift-MouseWheel> {
	if {%D >= 0} {
	    %W xview scroll [expr {%D/-30}] units
	} else {
	    %W xview scroll [expr {(%D-29)/-30}] units
	}
        %W xview scroll [expr {- (%D)}] units
    }
    }
    bind $c <Shift-Option-MouseWheel> {
	if {%D >= 0} {
	    %W xview scroll [expr {%D/-3}] units
        %W xview scroll [expr {-10 * (%D)}] units
	} else {
	    %W xview scroll [expr {(%D-2)/-3}] units
	}
    }
    }
}
    bind $c <TouchpadScroll> {
	lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
	if {$deltaX != 0 || $deltaY != 0} {
	    tk::ScrollByPixels %W $deltaX $deltaY
	}
    }
}

if {[tk windowingsystem] eq "x11" && ![package vsatisfies [package provide tk] 8.7-]} {
    # Support for mousewheels on Linux/Unix commonly comes through mapping
    # the wheel to the extended buttons.  If you have a mousewheel, find
    # Linux configuration info at:
    #	https://linuxreviews.org/HOWTO_change_the_mouse_speed_in_X
    bind $c <Button-4> {
	if {!$tk_strictMotif} {
	    %W yview scroll -5 units
	}
    }
    bind $c <Shift-Button-4> {
	if {!$tk_strictMotif} {
	    %W xview scroll -5 units
	}
    }
    bind $c <Button-5> {
	if {!$tk_strictMotif} {
	    %W yview scroll 5 units
	}
    }
    bind $c <Shift-Button-5> {
	if {!$tk_strictMotif} {
	    %W xview scroll 5 units
	}
    }
}


proc scrollEnter canvas {
    global oldFill
    set id [$canvas find withtag current]
    if {[lsearch [$canvas gettags current] text] >= 0} {
	set id [expr {$id-1}]
    }
    set oldFill [lindex [$canvas itemconfig $id -fill] 4]
    if {[winfo depth $canvas] > 1} {
	if {[tk windowingsystem] eq "aqua"} {
	    $canvas itemconfigure $id -fill systemSelectedTextBackgroundColor
	} else {
	    $canvas itemconfigure $id -fill LightSeaGreen
	$canvas itemconfigure $id -fill SeaGreen1
    } else {
	$canvas itemconfigure $id -fill black
	}
	$canvas itemconfigure [expr {$id+1}] -fill white
    }
}

proc scrollLeave canvas {
    global oldFill
    set id [$canvas find withtag current]
    if {[lsearch [$canvas gettags current] text] >= 0} {
	set id [expr {$id-1}]
    }
    $canvas itemconfigure $id -fill $oldFill
    $canvas itemconfigure [expr {$id+1}] -fill black
}

proc scrollButton canvas {
    global oldFill
    set id [$canvas find withtag current]
    if {[lsearch [$canvas gettags current] text] < 0} {
	set id [expr {$id+1}]
    }
    puts stdout "You buttoned at [lindex [$canvas itemconf $id -text] 4]"
}

Changes to library/demos/ctext.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# ctext.tcl --
#
# This demonstration script creates a canvas widget with a text
# item that can be edited and reconfigured in various ways.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ctext
catch {destroy $w}
toplevel $w
wm title $w "Canvas Text Demonstration"
wm iconname $w "Text"
positionWindow $w
27
28
29
30
31
32
33
34

35
36
37
38
39

40
41
42
43
44


45
46

47
48

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65




66
67
68
69


70
71
72


73
74
75
76
77


78
79
80
81
82
83
84
85
86
87








88
89

90
91
92


93
94
95
96
97
98


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113


114
115
116
117
118
119


120
121
122
123
124



125
126
127
128
129
130
131
27
28
29
30
31
32
33

34
35
36
37
38

39
40
41
42


43
44
45

46
47

48
49
50
51
52




53

54
55
56
57




58
59
60
61
62
63


64
65
66


67
68
69
70
71


72
73
74
75








76
77
78
79
80
81
82
83
84

85
86


87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107


108
109
110
111
112
113


114
115
116
117



118
119
120
121
122
123
124
125
126
127







-
+




-
+



-
-
+
+

-
+

-
+




-
-
-
-
+
-




-
-
-
-
+
+
+
+


-
-
+
+

-
-
+
+



-
-
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+

-
-
+
+




-
-
+
+













-
-
+
+




-
-
+
+


-
-
-
+
+
+







     the character just after the insertion cursor."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

canvas $c -relief flat -borderwidth 0 -width 375p -height 262.5p
canvas $c -relief flat -borderwidth 0 -width 500 -height 350
pack $w.c -side top -expand yes -fill both

set textFont {Helvetica 24}

$c create rectangle 183.75p 122.25p 191.25p 129.75p -outline black -fill red
$c create rectangle 245 195 255 205 -outline black -fill red

# First, create the text item and give it bindings so it can be edited.

$c addtag text withtag [$c create text 187.5p 126p -text "This is just a string of text to demonstrate the text facilities of canvas widgets. Bindings have been defined to support editing (see above)." -width 330p -anchor n -font $textFont -justify left]
$c bind text <Button-1> "textB1Press $c %x %y"
$c addtag text withtag [$c create text 250 200 -text "This is just a string of text to demonstrate the text facilities of canvas widgets. Bindings have been been defined to support editing (see above)." -width 440 -anchor n -font $textFont -justify left]
$c bind text <1> "textB1Press $c %x %y"
$c bind text <B1-Motion> "textB1Move $c %x %y"
$c bind text <Shift-Button-1> "$c select adjust current @%x,%y"
$c bind text <Shift-1> "$c select adjust current @%x,%y"
$c bind text <Shift-B1-Motion> "textB1Move $c %x %y"
$c bind text <Key> "textInsert $c %A"
$c bind text <KeyPress> "textInsert $c %A"
$c bind text <Return> "textInsert $c \\n"
$c bind text <Control-h> "textBs $c"
$c bind text <BackSpace> "textBs $c"
$c bind text <Delete> "textDel $c"
if {[tk windowingsystem] eq "aqua" && ![package vsatisfies [package provide tk] 8.7-]} {
    $c bind text <Button-3> "textPaste $c @%x,%y"
} else {
    $c bind text <Button-2> "textPaste $c @%x,%y"
$c bind text <2> "textPaste $c @%x,%y"
}

# Next, create some items that allow the text's anchor position
# to be edited.

proc mkTextConfigBox {w x y option value color} {	;# x, y are in points
    set item [$w create rect ${x}p ${y}p [expr {$x+22.5}]p [expr {$y+22.5}]p \
	    -outline black -fill $color -width 0.75p]
    $w bind $item <Button-1> "$w itemconf text $option $value"
proc mkTextConfigBox {w x y option value color} {
    set item [$w create rect $x $y [expr {$x+30}] [expr {$y+30}] \
	    -outline black -fill $color -width 1]
    $w bind $item <1> "$w itemconf text $option $value"
    $w addtag config withtag $item
}
proc mkTextConfigPie {w x y a option value color} {	;# x, y are in points
    set item [$w create arc ${x}p ${y}p [expr {$x+67.5}]p [expr {$y+67.5}]p \
proc mkTextConfigPie {w x y a option value color} {
    set item [$w create arc $x $y [expr {$x+90}] [expr {$y+90}] \
	    -start [expr {$a-15}] -extent 30 -outline black -fill $color \
	    -width 0.75p]
    $w bind $item <Button-1> "$w itemconf text $option $value"
	    -width 1]
    $w bind $item <1> "$w itemconf text $option $value"
    $w addtag config withtag $item
}

set x 37.5	;# in points
set y 37.5	;# in points
set x 50
set y 50
set color LightSkyBlue1
mkTextConfigBox $c $x $y -anchor se $color
mkTextConfigBox $c [expr {$x+22.5}] [expr {$y     }] -anchor s      $color
mkTextConfigBox $c [expr {$x+45  }] [expr {$y     }] -anchor sw     $color
mkTextConfigBox $c [expr {$x     }] [expr {$y+22.5}] -anchor e      $color
mkTextConfigBox $c [expr {$x+22.5}] [expr {$y+22.5}] -anchor center $color
mkTextConfigBox $c [expr {$x+45  }] [expr {$y+22.5}] -anchor w      $color
mkTextConfigBox $c [expr {$x     }] [expr {$y+45  }] -anchor ne     $color
mkTextConfigBox $c [expr {$x+22.5}] [expr {$y+45  }] -anchor n      $color
mkTextConfigBox $c [expr {$x+45  }] [expr {$y+45  }] -anchor nw     $color
mkTextConfigBox $c [expr {$x+30}] [expr {$y   }] -anchor s      $color
mkTextConfigBox $c [expr {$x+60}] [expr {$y   }] -anchor sw     $color
mkTextConfigBox $c [expr {$x   }] [expr {$y+30}] -anchor e      $color
mkTextConfigBox $c [expr {$x+30}] [expr {$y+30}] -anchor center $color
mkTextConfigBox $c [expr {$x+60}] [expr {$y+30}] -anchor w      $color
mkTextConfigBox $c [expr {$x   }] [expr {$y+60}] -anchor ne     $color
mkTextConfigBox $c [expr {$x+30}] [expr {$y+60}] -anchor n      $color
mkTextConfigBox $c [expr {$x+60}] [expr {$y+60}] -anchor nw     $color
set item [$c create rect \
	[expr {$x+30}]p [expr {$y+30}]p [expr {$x+37.5}]p [expr {$y+37.5}]p \
	[expr {$x+40}] [expr {$y+40}] [expr {$x+50}] [expr {$y+50}] \
	-outline black -fill red]
$c bind $item <Button-1> "$c itemconf text -anchor center"
$c create text [expr {$x+33.75}]p [expr {$y-3.75}]p \
$c bind $item <1> "$c itemconf text -anchor center"
$c create text [expr {$x+45}] [expr {$y-5}] \
	-text {Text Position}  -anchor s  -font {Times 20}  -fill brown

# Now create some items that allow the text's angle to be changed.

set x 153.75	;# in points
set y 37.5	;# in points
set x 205
set y 50
set color Yellow
mkTextConfigPie $c $x $y   0 -angle  90 $color
mkTextConfigPie $c $x $y  30 -angle 120 $color
mkTextConfigPie $c $x $y  60 -angle 150 $color
mkTextConfigPie $c $x $y  90 -angle 180 $color
mkTextConfigPie $c $x $y 120 -angle 210 $color
mkTextConfigPie $c $x $y 150 -angle 240 $color
mkTextConfigPie $c $x $y 180 -angle 270 $color
mkTextConfigPie $c $x $y 210 -angle 300 $color
mkTextConfigPie $c $x $y 240 -angle 330 $color
mkTextConfigPie $c $x $y 270 -angle   0 $color
mkTextConfigPie $c $x $y 300 -angle  30 $color
mkTextConfigPie $c $x $y 330 -angle  60 $color
$c create text [expr {$x+33.75}]p [expr {$y-3.75}]p \
	-text {Text Angle}     -anchor s  -font {Times 20}  -fill brown
$c create text [expr {$x+45}] [expr {$y-5}] \
	-text {Text Angle}  -anchor s  -font {Times 20}  -fill brown

# Lastly, create some items that allow the text's justification to be
# changed.

set x 262.5	;# in points
set y 37.5	;# in points
set x 350
set y 50
set color SeaGreen2
mkTextConfigBox $c $x $y -justify left $color
mkTextConfigBox $c [expr {$x+22.5}] $y -justify center $color
mkTextConfigBox $c [expr {$x+45}] $y -justify right $color
$c create text [expr {$x+33.75}]p [expr {$y-3.75}]p \
mkTextConfigBox $c [expr {$x+30}] $y -justify center $color
mkTextConfigBox $c [expr {$x+60}] $y -justify right $color
$c create text [expr {$x+45}] [expr {$y-5}] \
	-text {Justification}  -anchor s  -font {Times 20}  -fill brown

$c bind config <Enter> "textEnter $c"
$c bind config <Leave> "$c itemconf current -fill \$textConfigFill"

set textConfigFill {}

Changes to library/demos/dialog1.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
1
2
3
4








5

6
7
8
9
10
11
12
13








-
-
-
-
-
-
-
-

-
+







-
-
-
-
# dialog1.tcl --
#
# This demonstration script creates a dialog box with a local grab.

interp create child
load {} Tk child
child eval {
    wm title . child
    wm geometry . +700+30
    pack [text .t -width 30 -height 10]
}

after idle {.dialog1.msg configure -wraplength 4i}
set i [tk_dialog .dialog1 "Dialog with local grab" {This is a modal dialog box.  It uses Tk's "grab" command to create a "local grab" on the dialog box.  The grab prevents any mouse or keyboard events from getting to any other windows in the application until you have answered the dialog by invoking one of the buttons below.  However, you can still interact with other applications.  For example, you should be able to edit text in the window named "child" which was created by a child interpreter.} \
set i [tk_dialog .dialog1 "Dialog with local grab" {This is a modal dialog box.  It uses Tk's "grab" command to create a "local grab" on the dialog box.  The grab prevents any pointer-related events from getting to any other windows in the application until you have answered the dialog by invoking one of the buttons below.  However, you can still interact with other applications.} \
info 0 OK Cancel {Show Code}]

switch $i {
    0 {puts "You pressed OK"}
    1 {puts "You pressed Cancel"}
    2 {showCode .dialog1}
}

if {[interp exists child]} {
    interp delete child
}

Changes to library/demos/dialog2.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11

12
13
14
15
16
17










-
+
-






# dialog2.tcl --
#
# This demonstration script creates a dialog box with a global grab.

after idle {
    .dialog2.msg configure -wraplength 4i
}
after 100 {
    grab -global .dialog2
}
set i [tk_dialog .dialog2 "Dialog with global grab" {This dialog box uses a global grab. If you are using an X11 window manager you will be prevented from interacting with anything on your display until you invoke one of the buttons below.  This is almost always a bad idea; don't use global grabs with X11 unless you're truly desperate.  On macOS systems you will not be able to interact with any window belonging to this process, but interaction with other macOS Applications will still be possible.}\
set i [tk_dialog .dialog2 "Dialog with global grab" {This dialog box uses a global grab, so it prevents you from interacting with anything on your display until you invoke one of the buttons below.  Global grabs are almost always a bad idea; don't use them unless you're truly desperate.} warning 0 OK Cancel {Show Code}]
warning 0 OK Cancel {Show Code}]

switch $i {
    0 {puts "You pressed OK"}
    1 {puts "You pressed Cancel"}
    2 {showCode .dialog2}
}

Changes to library/demos/en.msg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
























37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17

18
19

20
21













22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60

61
62
63
64
65
66

67
68
69
70
71
72

73
74
75
76
77
78
79
80

81
82
83

84
85
86
87
88
89
90
91
92
93








94
95
96
97












-






-


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











-




-






-






-








-



-










-
-
-
-
-
-
-
-




-
::msgcat::mcset en "Widget Demonstration"
::msgcat::mcset en "tkWidgetDemo"
::msgcat::mcset en "&File"
::msgcat::mcset en "About..."
::msgcat::mcset en "&About..."
::msgcat::mcset en "<F1>"
::msgcat::mcset en "&Quit"
::msgcat::mcset en "Meta+Q"		;# Displayed hotkey
::msgcat::mcset en "Meta-q"		;# Actual binding sequence
::msgcat::mcset en "Ctrl+Q"		;# Displayed hotkey
::msgcat::mcset en "Control-q"		;# Actual binding sequence
::msgcat::mcset en "See Variables"
::msgcat::mcset en "Variable values"
::msgcat::mcset en "Variable values:"
::msgcat::mcset en "OK"
::msgcat::mcset en "Run the \"%s\" sample program"
::msgcat::mcset en "Dismiss"
::msgcat::mcset en "Rerun Demo"
::msgcat::mcset en "Print Code"
::msgcat::mcset en "Demo code: %s"
::msgcat::mcset en "About Widget Demo"
::msgcat::mcset en "Tk widget demonstration"
::msgcat::mcset en "Tk widget demonstration application"
::msgcat::mcset en "Copyright © %s"

::msgcat::mcset en "Tk Widget Demonstrations"
::msgcat::mcset en "This application provides a front end for several short scripts"
::msgcat::mcset en "that demonstrate what you can do with Tk widgets.  Each of the"
::msgcat::mcset en "numbered lines below describes a demonstration;  you can click on"
::msgcat::mcset en "it to invoke the demonstration.  Once the demonstration window"
::msgcat::mcset en "appears, you can click the"
::msgcat::mcset en "See Code"  "See Code"	;# This is also button text!
::msgcat::mcset en "button to see the Tcl/Tk code that created the demonstration.  If"
::msgcat::mcset en "you wish, you can edit the code and click the"
::msgcat::mcset en "button in the code window to reinvoke the demonstration with the"
::msgcat::mcset en "modified code."

::msgcat::mcset en "
    @@title
    Tk Widget Demonstrations
    @@newline
    @@normal
    @@newline

    This application provides a front end for several short scripts
    that demonstrate what you can do with Tk widgets.  Each of the
    numbered lines below describes a demonstration;  you can click on
    it to invoke the demonstration.  Once the demonstration window
    appears, you can click the
    @@bold
    See Code
    @@normal
    button to see the Tcl/Tk code that created the demonstration.  If
    you wish, you can edit the code and click the
    @@bold
    Rerun Demo
    @@normal
    button in the code window to reinvoke the demonstration with the
    modified code.
    @@newline
"
::msgcat::mcset en "Labels, buttons, checkbuttons, and radiobuttons"
::msgcat::mcset en "Labels (text and bitmaps)"
::msgcat::mcset en "Labels and UNICODE text"
::msgcat::mcset en "Buttons"
::msgcat::mcset en "Check-buttons (select any of a group)"
::msgcat::mcset en "Radio-buttons (select one of a group)"
::msgcat::mcset en "A 15-puzzle game made out of buttons"
::msgcat::mcset en "Iconic buttons that use bitmaps"
::msgcat::mcset en "Two labels displaying images"
::msgcat::mcset en "A simple user interface for viewing images"
::msgcat::mcset en "Labelled frames"

::msgcat::mcset en "Listboxes"
::msgcat::mcset en "The 50 states"
::msgcat::mcset en "Colors: change the color scheme for the application"
::msgcat::mcset en "A collection of famous and infamous sayings"

::msgcat::mcset en "Entries and Spin-boxes"
::msgcat::mcset en "Entries without scrollbars"
::msgcat::mcset en "Entries with scrollbars"
::msgcat::mcset en "Validated entries and password fields"
::msgcat::mcset en "Spin-boxes"
::msgcat::mcset en "Simple Rolodex-like form"

::msgcat::mcset en "Text"
::msgcat::mcset en "Basic editable text"
::msgcat::mcset en "Text display styles"
::msgcat::mcset en "Hypertext (tag bindings)"
::msgcat::mcset en "A text widget with embedded windows"
::msgcat::mcset en "A search tool built with a text widget"

::msgcat::mcset en "Canvases"
::msgcat::mcset en "The canvas item types"
::msgcat::mcset en "A simple 2-D plot"
::msgcat::mcset en "Text items in canvases"
::msgcat::mcset en "An editor for arrowheads on canvas lines"
::msgcat::mcset en "A ruler with adjustable tab stops"
::msgcat::mcset en "A building floor plan"
::msgcat::mcset en "A simple scrollable canvas"

::msgcat::mcset en "Scales"
::msgcat::mcset en "Horizontal scale"
::msgcat::mcset en "Vertical scale"

::msgcat::mcset en "Paned Windows"
::msgcat::mcset en "Horizontal paned window"
::msgcat::mcset en "Vertical paned window"
::msgcat::mcset en "Menus"
::msgcat::mcset en "Menus and cascades (sub-menus)"
::msgcat::mcset en "Menu-buttons"
::msgcat::mcset en "Common Dialogs"
::msgcat::mcset en "Message boxes"
::msgcat::mcset en "File selection dialog"
::msgcat::mcset en "Color picker"
::msgcat::mcset en "Font selection dialog"
::msgcat::mcset en "System tray icon and notification"
::msgcat::mcset en "Printing from canvas and text widgets"
::msgcat::mcset en "Animation"
::msgcat::mcset en "Animated labels"
::msgcat::mcset en "Animated wave"
::msgcat::mcset en "Pendulum simulation"
::msgcat::mcset en "A celebration of Rube Goldberg"
::msgcat::mcset en "Miscellaneous"
::msgcat::mcset en "The built-in bitmaps"
::msgcat::mcset en "A dialog box with a local grab"
::msgcat::mcset en "A dialog box with a global grab"
::msgcat::mcset en "Window icons and badges"

Changes to library/demos/entry1.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29


30
31
32
33
34
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34









-
+








-
+








-
-
+
+





# entry1.tcl --
#
# This demonstration script creates several entry widgets without
# scrollbars.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .entry1
catch {destroy $w}
toplevel $w
wm title $w "Entry Demonstration (no scrollbars)"
wm iconname $w "entry1"
positionWindow $w

label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below.  You can add characters by pointing, clicking and typing.  The normal Motif editing characters are supported, along with many Emacs bindings.  For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor.  For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse the middle mouse button pressed."
label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below.  You can add characters by pointing, clicking and typing.  The normal Motif editing characters are supported, along with many Emacs bindings.  For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor.  For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse button2 pressed."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

entry $w.e1
entry $w.e2
entry $w.e3 -placeholder {Enter text here} -placeholderforeground gray75
pack $w.e1 $w.e2 $w.e3 -side top -pady 3p -padx 7.5p -fill x
entry $w.e3
pack $w.e1 $w.e2 $w.e3 -side top -pady 5 -padx 10 -fill x

$w.e1 insert 0 "Initial value"
$w.e2 insert end "This entry contains a long value, much too long "
$w.e2 insert end "to fit in the window at one time, so long in fact "
$w.e2 insert end "that you'll have to scan or scroll to see the end."

Changes to library/demos/entry2.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26

27
28
29
30

31
32

33
34

35
36

37
38

39
40
41
42
43
44
45
46
47
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25

26
27
28
29

30
31

32
33

34
35

36
37

38
39
40
41
42
43
44
45
46










-
+








-
+






-
+



-
+

-
+

-
+

-
+

-
+








-
# entry2.tcl --
#
# This demonstration script is the same as the entry1.tcl script
# except that it creates scrollbars for the entries.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .entry2
catch {destroy $w}
toplevel $w
wm title $w "Entry Demonstration (with scrollbars)"
wm iconname $w "entry2"
positionWindow $w

label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below, with a scrollbar for each entry.  You can add characters by pointing, clicking and typing.  The normal Motif editing characters are supported, along with many Emacs bindings.  For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor.  For entries that are too large to fit in the window all at once, you can scan through the entries with the scrollbars, or by dragging with the middle mouse button pressed."
label $w.msg -font $font -wraplength 5i -justify left -text "Three different entries are displayed below, with a scrollbar for each entry.  You can add characters by pointing, clicking and typing.  The normal Motif editing characters are supported, along with many Emacs bindings.  For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor.  For entries that are too large to fit in the window all at once, you can scan through the entries with the scrollbars, or by dragging with mouse button2 pressed."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame -side top -fill x -expand 1

entry $w.frame.e1 -xscrollcommand "$w.frame.s1 set"
ttk::scrollbar $w.frame.s1 -orient horizontal -command \
ttk::scrollbar $w.frame.s1 -orient horiz -command \
	"$w.frame.e1 xview"
frame $w.frame.spacer1 -width 15p -height 7.5p
frame $w.frame.spacer1 -width 20 -height 10
entry $w.frame.e2 -xscrollcommand "$w.frame.s2 set"
ttk::scrollbar $w.frame.s2 -orient horizontal -command \
ttk::scrollbar $w.frame.s2 -orient horiz -command \
	"$w.frame.e2 xview"
frame $w.frame.spacer2 -width 15p -height 7.5p
frame $w.frame.spacer2 -width 20 -height 10
entry $w.frame.e3 -xscrollcommand "$w.frame.s3 set"
ttk::scrollbar $w.frame.s3 -orient horizontal -command \
ttk::scrollbar $w.frame.s3 -orient horiz -command \
	"$w.frame.e3 xview"
pack $w.frame.e1 $w.frame.s1 $w.frame.spacer1 $w.frame.e2 $w.frame.s2 \
	$w.frame.spacer2 $w.frame.e3 $w.frame.s3 -side top -fill x

$w.frame.e1 insert 0 "Initial value"
$w.frame.e2 insert end "This entry contains a long value, much too long "
$w.frame.e2 insert end "to fit in the window at one time, so long in fact "
$w.frame.e2 insert end "that you'll have to scan or scroll to see the end."
$w.frame.e3 configure -placeholder {Enter text here} -placeholderforeground gray75

Changes to library/demos/entry3.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







# entry3.tcl --
#
# This demonstration script creates several entry widgets whose
# permitted input is constrained in some way.  It also shows off a
# password entry.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .entry3
catch {destroy $w}
toplevel $w
wm title $w "Constrained Entry Demonstration"
wm iconname $w "entry3"
positionWindow $w
60
61
62
63
64
65
66
67

68
69
70
71
72
73

74
75
76
77
78
79
80
60
61
62
63
64
65
66

67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+





-
+







	after 200 [list focusAndFlash $W $fg $bg [expr {$count-1}]]
    }
}

labelframe $w.l1 -text "Integer Entry"
# Alternatively try using {string is digit} for arbitrary length numbers,
# and not just 32-bit ones.
entry $w.l1.e -validate focus -validatecommand {string is integer %P}
entry $w.l1.e -validate focus -vcmd {string is integer %P}
$w.l1.e configure -invalidcommand \
	"focusAndFlash %W [$w.l1.e cget -fg] [$w.l1.e cget -bg]"
pack $w.l1.e -fill x -expand 1 -padx 1m -pady 1m

labelframe $w.l2 -text "Length-Constrained Entry"
entry $w.l2.e -validate key -invcmd bell -validatecommand {expr {[string length %P]<10}}
entry $w.l2.e -validate key -invcmd bell -vcmd {expr {[string length %P]<10}}
pack $w.l2.e -fill x -expand 1 -padx 1m -pady 1m

### PHONE NUMBER ENTRY ###
# Note that the source to this is quite a bit longer as the behaviour
# demonstrated is a lot more ambitious than with the others.

# Initial content for the third entry widget
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112







-
+







# vmode - The widget's validation mode
# idx -	  The index where replacement is to occur
# char -  The character (or string, though that will always be
#	  refused) to be overwritten at that point.

proc validatePhoneChange {W vmode idx char} {
    global phoneNumberMap entry3content
    if {$idx < 0} {return 1}
    if {$idx == -1} {return 1}
    after idle [list $W configure -validate $vmode -invcmd bell]
    if {
	!($idx<3 || $idx==6 || $idx==7 || $idx==11 || $idx>15) &&
	[string match {[0-9A-Za-z]} $char]
    } then {
	$W delete $idx
	$W insert $idx [string map $phoneNumberMap $char]
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185







-
+












-
+








	bell
	return -code break
    }
}

labelframe $w.l3 -text "US Phone-Number Entry"
entry $w.l3.e -validate key  -invcmd bell  -textvariable entry3content \
	-validatecommand {validatePhoneChange %W %v %i %S}
	-vcmd {validatePhoneChange %W %v %i %S}
# Click to focus goes to the first editable character...
bind $w.l3.e <FocusIn> {
    if {"%d" ne "NotifyAncestor"} {
	%W icursor 3
	after idle {%W selection clear}
    }
}
bind $w.l3.e <<PrevChar>> {phoneSkipLeft  %W}
bind $w.l3.e <<NextChar>> {phoneSkipRight %W}
pack $w.l3.e -fill x -expand 1 -padx 1m -pady 1m

labelframe $w.l4 -text "Password Entry"
entry $w.l4.e -validate key -show "*" -validatecommand {expr {[string length %P]<=8}}
entry $w.l4.e -validate key -show "*" -vcmd {expr {[string length %P]<=8}}
pack $w.l4.e -fill x -expand 1 -padx 1m -pady 1m

lower [frame $w.mid]
grid $w.l1 $w.l2 -in $w.mid -padx 3m -pady 1m -sticky ew
grid $w.l3 $w.l4 -in $w.mid -padx 3m -pady 1m -sticky ew
grid columnconfigure $w.mid {0 1} -uniform 1
pack $w.msg -side top
pack $w.mid -fill both -expand 1

Changes to library/demos/filebox.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35







36
37
38
39
40
41
42
43
44
45
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29






30
31
32
33
34
35
36
37


38
39
40
41
42
43
44








-
+


















-

+
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-







# filebox.tcl --
#
# This demonstration script prompts the user to select a file.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .filebox
catch {destroy $w}
toplevel $w
wm title $w "File Selection Dialogs"
wm iconname $w "filebox"
positionWindow $w

ttk::frame $w._bg
place $w._bg -x 0 -y 0 -relwidth 1 -relheight 1

ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

set f [ttk::frame $w.f]
foreach i {open save} {
    set f [ttk::frame $w.$i]
    ttk::label $f.lab_$i -text "Select a file to $i:"
    ttk::entry $f.ent_$i -width 20
    ttk::button $f.but_$i -text "Browse ..." -command \
	    "fileDialog $w $f.ent_$i $i"
    grid $f.lab_$i $f.ent_$i $f.but_$i -pady 3p -sticky w
    grid configure $f.ent_$i -padx 3p -sticky ew
    ttk::label $f.lab -text "Select a file to $i: " -anchor e
    ttk::entry $f.ent -width 20
    ttk::button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
    pack $f.lab -side left
    pack $f.ent -side left -expand yes -fill x
    pack $f.but -side left
    pack $f -fill x -padx 1c -pady 3
}
grid columnconfigure $f 1 -weight 1
pack $f -fill x -padx 1c

if {[tk windowingsystem] eq "x11"} {
    ttk::checkbutton $w.strict -text "Use Motif Style Dialog" \
	-variable tk_strictMotif -onvalue 1 -offvalue 0
    pack $w.strict -anchor c

    # This binding ensures that we don't run the rest of the demos

Changes to library/demos/floor.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# floor.tcl --
#
# This demonstration script creates a canvas widet that displays the
# floorplan for DEC's Western Research Laboratory.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# floorDisplay --
# Recreate the floorplan display in the canvas given by "w".  The
# floor given by "active" is displayed on top with its office structure
# visible.
#
# Arguments:
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
49
50
51
52
53
54
55






56
57
58
59
60
61
62


63
64




65





66
67
68
69
70
71
72







-
-
-
-
-
-







-
-
+
+
-
-
-
-
+
-
-
-
-
-







    # Make sure that the room polygons are on top.

    catch {unset floorLabels}
    catch {unset floorItems}
    fg$active $w $colors(offices)
    $w raise room

    # Rescale the coordinates in pixels of all of the
    # items according to the display's DPI scaling level.

    set scaleFactor [expr {$tk::scalingPct / 100.0}]
    $w scale all 0 0 $scaleFactor $scaleFactor

    # Offset the floors diagonally from each other.

    $w move floor1 2c 2c
    $w move floor2 1c 1c

    # Create items for the room entry and its label.

    $w create window 450p 75p -anchor w -window $w.entry
    $w create text 450p 75p -anchor e -text "Room: "
    $w create window 600 100 -anchor w -window $w.entry
    $w create text 600 100 -anchor e -text "Room: "

    # Configure the canvas.

    set bbox [$w bbox all]
    $w config -scrollregion [$w bbox all]
    lassign $bbox x1 y1 x2 y2
    set morePx [expr {round(20 * $tk::scalingPct / 100.0)}]
    set width  [expr {$x2 - $x1 + $morePx}]
    set height [expr {$y2 - $y1 + $morePx}]
    $w configure -scrollregion $bbox -width $width -height $height
}

# newRoom --
# This procedure is invoked whenever the mouse enters a room
# in the floorplan.  It changes tags so that the current room is
# highlighted.
#
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+














-
+












-
+







    global currentRoom floorItems colors
    $w delete highlight
    if {[catch {set item $floorItems($currentRoom)}]} {
	return
    }
    set new [eval \
	"$w create polygon [$w coords $item] -fill $colors(active) \
	-outline {} -tags highlight"]
	-tags highlight"]
    $w raise $new marker
}

# bg1 --
# This procedure represents part of the floorplan database.  When
# invoked, it instantiates the background information for the first
# floor.
#
# Arguments:
# w -		The canvas window.
# fill -	Fill color to use for the floor's background.
# outline -	Color to use for the floor's outline.

proc bg1 {w fill outline} {
    $w create polygon 347 80 349 82 351 84 353 85 363 92 375 99 386 104 \
    $w create poly 347 80 349 82 351 84 353 85 363 92 375 99 386 104 \
	386 129 398 129 398 162 484 162 484 129 559 129 559 133 725 \
	133 725 129 802 129 802 389 644 389 644 391 559 391 559 327 \
	508 327 508 311 484 311 484 278 395 278 395 288 400 288 404 \
	288 409 290 413 292 418 297 421 302 422 309 421 318 417 325 \
	411 330 405 332 397 333 344 333 340 334 336 336 335 338 332 \
	342 331 347 332 351 334 354 336 357 341 359 340 360 335 363 \
	331 365 326 366 304 366 304 355 258 355 258 387 60 387 60 391 \
	0 391 0 337 3 337 3 114 8 114 8 25 30 25 30 5 93 5 98 5 104 7 \
	110 10 116 16 119 20 122 28 123 32 123 68 220 68 220 34 221 \
	22 223 17 227 13 231 8 236 4 242 2 246 0 260 0 283 1 300 5 \
	321 14 335 22 348 25 365 29 363 39 358 48 352 56 337 70 \
	344 76 347 80 \
	-tags {floor1 bg} -fill $fill -outline {}
	-tags {floor1 bg} -fill $fill
    $w create line 386 129 398 129 -fill $outline -tags {floor1 bg}
    $w create line 258 355 258 387 -fill $outline -tags {floor1 bg}
    $w create line 60 387 60 391 -fill $outline -tags {floor1 bg}
    $w create line 0 337 0 391 -fill $outline -tags {floor1 bg}
    $w create line 60 391 0 391 -fill $outline -tags {floor1 bg}
    $w create line 3 114 3 337 -fill $outline -tags {floor1 bg}
    $w create line 258 387 60 387 -fill $outline -tags {floor1 bg}
249
250
251
252
253
254
255
256

257
258
259
260
261

262
263
264
265
266
267
268
235
236
237
238
239
240
241

242
243
244
245
246

247
248
249
250
251
252
253
254







-
+




-
+







#
# Arguments:
# w -		The canvas window.
# fill -	Fill color to use for the floor's background.
# outline -	Color to use for the floor's outline.

proc bg2 {w fill outline} {
    $w create polygon 559 129 484 129 484 162 398 162 398 129 315 129 \
    $w create poly 559 129 484 129 484 162 398 162 398 129 315 129 \
	315 133 176 133 176 129 96 129 96 133 3 133 3 339 0 339 0 391 \
	60 391 60 387 258 387 258 329 350 329 350 311 395 311 395 280 \
	484 280 484 311 508 311 508 327 558 327 558 391 644 391 644 \
	367 802 367 802 129 725 129 725 133 559 133 559 129 \
	-tags {floor2 bg} -fill $fill -outline {}
	-tags {floor2 bg} -fill $fill
    $w create line 350 311 350 329 -fill $outline -tags {floor2 bg}
    $w create line 398 129 398 162 -fill $outline -tags {floor2 bg}
    $w create line 802 367 802 129 -fill $outline -tags {floor2 bg}
    $w create line 802 129 725 129 -fill $outline -tags {floor2 bg}
    $w create line 725 133 725 129 -fill $outline -tags {floor2 bg}
    $w create line 559 129 559 133 -fill $outline -tags {floor2 bg}
    $w create line 559 133 725 133 -fill $outline -tags {floor2 bg}
304
305
306
307
308
309
310
311

312
313
314


315
316

317
318
319
320
321
322
323
290
291
292
293
294
295
296

297
298


299
300
301

302
303
304
305
306
307
308
309







-
+

-
-
+
+

-
+







#
# Arguments:
# w -		The canvas window.
# fill -	Fill color to use for the floor's background.
# outline -	Color to use for the floor's outline.

proc bg3 {w fill outline} {
    $w create polygon 159 300 107 300 107 248 159 248 159 129 96 129 96 \
    $w create poly 159 300 107 300 107 248 159 248 159 129 96 129 96 \
	133 21 133 21 331 0 331 0 391 60 391 60 370 159 370 159 300 \
	-tags {floor3 bg} -fill $fill -outline {}
    $w create polygon 258 370 258 329 350 329 350 311 399 311 399 129 \
	-tags {floor3 bg} -fill $fill
    $w create poly 258 370 258 329 350 329 350 311 399 311 399 129 \
	315 129 315 133 176 133 176 129 159 129 159 370 258 370 \
	-tags {floor3 bg} -fill $fill -outline {}
	-tags {floor3 bg} -fill $fill
    $w create line 96 133 96 129 -fill $outline -tags {floor3 bg}
    $w create line 176 129 96 129 -fill $outline -tags {floor3 bg}
    $w create line 176 129 176 133 -fill $outline -tags {floor3 bg}
    $w create line 315 133 176 133 -fill $outline -tags {floor3 bg}
    $w create line 315 133 315 129 -fill $outline -tags {floor3 bg}
    $w create line 399 129 315 129 -fill $outline -tags {floor3 bg}
    $w create line 399 311 399 129 -fill $outline -tags {floor3 bg}
343
344
345
346
347
348
349
350

351
352
353
354

355
356
357
358

359
360
361
362

363
364
365
366

367
368
369
370

371
372
373
374

375
376
377
378

379
380
381
382

383
384
385
386

387
388
389
390

391
392
393
394

395
396
397
398

399
400
401
402

403
404
405
406

407
408
409
410

411
412
413
414

415
416
417
418

419
420
421
422

423
424
425
426

427
428
429
430

431
432
433
434

435
436
437
438

439
440
441
442

443
444
445
446

447
448
449
450

451
452
453
454

455
456
457
458

459
460
461
462

463
464
465
466

467
468
469
470

471
472
473
474

475
476
477
478

479
480
481
482

483
484
485
486

487
488
489
490

491
492
493
494

495
496
497
498

499
500
501
502

503
504
505
506

507
508
509
510

511
512
513
514

515
516
517
518

519
520
521
522

523
524
525
526

527
528
529
530

531
532
533
534

535
536
537
538

539
540
541
542
543
544
545
329
330
331
332
333
334
335

336
337
338
339

340
341
342
343

344
345
346
347

348
349
350
351

352
353
354
355

356
357
358
359

360
361
362
363

364
365
366
367

368
369
370
371

372
373
374
375

376
377
378
379

380
381
382
383

384
385
386
387

388
389
390
391

392
393
394
395

396
397
398
399

400
401
402
403

404
405
406
407

408
409
410
411

412
413
414
415

416
417
418
419

420
421
422
423

424
425
426
427

428
429
430
431

432
433
434
435

436
437
438
439

440
441
442
443

444
445
446
447

448
449
450
451

452
453
454
455

456
457
458
459

460
461
462
463

464
465
466
467

468
469
470
471

472
473
474
475

476
477
478
479

480
481
482
483

484
485
486
487

488
489
490
491

492
493
494
495

496
497
498
499

500
501
502
503

504
505
506
507

508
509
510
511

512
513
514
515

516
517
518
519

520
521
522
523

524
525
526
527
528
529
530
531







-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+







#
# Arguments:
# w -		The canvas window.
# color -	Color to use for drawing foreground information.

proc fg1 {w color} {
    global floorLabels floorItems
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -tags {floor1 room}]
    set floorLabels($i) 101
    set {floorItems(101)} $i
    $w create text 358 209 -text 101 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -tags {floor1 room}]
    set floorLabels($i) {Pub Lift1}
    set {floorItems(Pub Lift1)} $i
    $w create text 323 223 -text {Pub Lift1} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -tags {floor1 room}]
    set floorLabels($i) {Priv Lift1}
    set {floorItems(Priv Lift1)} $i
    $w create text 323 188 -text {Priv Lift1} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 42 389 42 337 1 337 1 389 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 42 389 42 337 1 337 1 389 -fill {} -tags {floor1 room}]
    set floorLabels($i) 110
    set {floorItems(110)} $i
    $w create text 21.5 363 -text 110 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 59 389 59 385 90 385 90 337 44 337 44 389 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 59 389 59 385 90 385 90 337 44 337 44 389 -fill {} -tags {floor1 room}]
    set floorLabels($i) 109
    set {floorItems(109)} $i
    $w create text 67 363 -text 109 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 51 300 51 253 6 253 6 300 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 51 300 51 253 6 253 6 300 -fill {} -tags {floor1 room}]
    set floorLabels($i) 111
    set {floorItems(111)} $i
    $w create text 28.5 276.5 -text 111 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 98 248 98 309 79 309 79 248 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 98 248 98 309 79 309 79 248 -fill {} -tags {floor1 room}]
    set floorLabels($i) 117B
    set {floorItems(117B)} $i
    $w create text 88.5 278.5 -text 117B -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 51 251 51 204 6 204 6 251 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 51 251 51 204 6 204 6 251 -fill {} -tags {floor1 room}]
    set floorLabels($i) 112
    set {floorItems(112)} $i
    $w create text 28.5 227.5 -text 112 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 6 156 51 156 51 203 6 203 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 6 156 51 156 51 203 6 203 -fill {} -tags {floor1 room}]
    set floorLabels($i) 113
    set {floorItems(113)} $i
    $w create text 28.5 179.5 -text 113 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 85 169 79 169 79 192 85 192 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 85 169 79 169 79 192 85 192 -fill {} -tags {floor1 room}]
    set floorLabels($i) 117A
    set {floorItems(117A)} $i
    $w create text 82 180.5 -text 117A -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 77 302 77 168 53 168 53 302 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 77 302 77 168 53 168 53 302 -fill {} -tags {floor1 room}]
    set floorLabels($i) 117
    set {floorItems(117)} $i
    $w create text 65 235 -text 117 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 51 155 51 115 6 115 6 155 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 51 155 51 115 6 115 6 155 -fill {} -tags {floor1 room}]
    set floorLabels($i) 114
    set {floorItems(114)} $i
    $w create text 28.5 135 -text 114 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 95 115 53 115 53 168 95 168 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 95 115 53 115 53 168 95 168 -fill {} -tags {floor1 room}]
    set floorLabels($i) 115
    set {floorItems(115)} $i
    $w create text 74 141.5 -text 115 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 87 113 87 27 10 27 10 113 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 87 113 87 27 10 27 10 113 -fill {} -tags {floor1 room}]
    set floorLabels($i) 116
    set {floorItems(116)} $i
    $w create text 48.5 70 -text 116 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 89 91 128 91 128 113 89 113 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 89 91 128 91 128 113 89 113 -fill {} -tags {floor1 room}]
    set floorLabels($i) 118
    set {floorItems(118)} $i
    $w create text 108.5 102 -text 118 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 178 128 178 132 216 132 216 91 163 91 163 112 149 112 149 128 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 178 128 178 132 216 132 216 91 163 91 163 112 149 112 149 128 -fill {} -tags {floor1 room}]
    set floorLabels($i) 120
    set {floorItems(120)} $i
    $w create text 189.5 111.5 -text 120 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 79 193 87 193 87 169 136 169 136 192 156 192 156 169 175 169 175 246 79 246 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 79 193 87 193 87 169 136 169 136 192 156 192 156 169 175 169 175 246 79 246 -fill {} -tags {floor1 room}]
    set floorLabels($i) 122
    set {floorItems(122)} $i
    $w create text 131 207.5 -text 122 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 138 169 154 169 154 191 138 191 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 138 169 154 169 154 191 138 191 -fill {} -tags {floor1 room}]
    set floorLabels($i) 121
    set {floorItems(121)} $i
    $w create text 146 180 -text 121 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 99 300 126 300 126 309 99 309 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 99 300 126 300 126 309 99 309 -fill {} -tags {floor1 room}]
    set floorLabels($i) 106A
    set {floorItems(106A)} $i
    $w create text 112.5 304.5 -text 106A -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 128 299 128 309 150 309 150 248 99 248 99 299 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 128 299 128 309 150 309 150 248 99 248 99 299 -fill {} -tags {floor1 room}]
    set floorLabels($i) 105
    set {floorItems(105)} $i
    $w create text 124.5 278.5 -text 105 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 174 309 174 300 152 300 152 309 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 174 309 174 300 152 300 152 309 -fill {} -tags {floor1 room}]
    set floorLabels($i) 106B
    set {floorItems(106B)} $i
    $w create text 163 304.5 -text 106B -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 176 299 176 309 216 309 216 248 152 248 152 299 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 176 299 176 309 216 309 216 248 152 248 152 299 -fill {} -tags {floor1 room}]
    set floorLabels($i) 104
    set {floorItems(104)} $i
    $w create text 184 278.5 -text 104 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 138 385 138 337 91 337 91 385 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 138 385 138 337 91 337 91 385 -fill {} -tags {floor1 room}]
    set floorLabels($i) 108
    set {floorItems(108)} $i
    $w create text 114.5 361 -text 108 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 256 337 140 337 140 385 256 385 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 256 337 140 337 140 385 256 385 -fill {} -tags {floor1 room}]
    set floorLabels($i) 107
    set {floorItems(107)} $i
    $w create text 198 361 -text 107 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 300 353 300 329 260 329 260 353 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 300 353 300 329 260 329 260 353 -fill {} -tags {floor1 room}]
    set floorLabels($i) Smoking
    set {floorItems(Smoking)} $i
    $w create text 280 341 -text Smoking -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 314 135 314 170 306 170 306 246 177 246 177 135 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 314 135 314 170 306 170 306 246 177 246 177 135 -fill {} -tags {floor1 room}]
    set floorLabels($i) 123
    set {floorItems(123)} $i
    $w create text 245.5 190.5 -text 123 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 217 248 301 248 301 326 257 326 257 310 217 310 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 217 248 301 248 301 326 257 326 257 310 217 310 -fill {} -tags {floor1 room}]
    set floorLabels($i) 103
    set {floorItems(103)} $i
    $w create text 259 287 -text 103 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 396 188 377 188 377 169 316 169 316 131 396 131 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 396 188 377 188 377 169 316 169 316 131 396 131 -fill {} -tags {floor1 room}]
    set floorLabels($i) 124
    set {floorItems(124)} $i
    $w create text 356 150 -text 124 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 397 226 407 226 407 189 377 189 377 246 397 246 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 397 226 407 226 407 189 377 189 377 246 397 246 -fill {} -tags {floor1 room}]
    set floorLabels($i) 125
    set {floorItems(125)} $i
    $w create text 392 217.5 -text 125 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 399 187 409 187 409 207 474 207 474 164 399 164 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 399 187 409 187 409 207 474 207 474 164 399 164 -fill {} -tags {floor1 room}]
    set floorLabels($i) 126
    set {floorItems(126)} $i
    $w create text 436.5 185.5 -text 126 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 409 209 409 229 399 229 399 253 486 253 486 239 474 239 474 209 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 409 209 409 229 399 229 399 253 486 253 486 239 474 239 474 209 -fill {} -tags {floor1 room}]
    set floorLabels($i) 127
    set {floorItems(127)} $i
    $w create text 436.5 231 -text 127 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 501 164 501 174 495 174 495 188 490 188 490 204 476 204 476 164 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 501 164 501 174 495 174 495 188 490 188 490 204 476 204 476 164 -fill {} -tags {floor1 room}]
    set floorLabels($i) MShower
    set {floorItems(MShower)} $i
    $w create text 488.5 184 -text MShower -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 497 176 513 176 513 204 492 204 492 190 497 190 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 497 176 513 176 513 204 492 204 492 190 497 190 -fill {} -tags {floor1 room}]
    set floorLabels($i) Closet
    set {floorItems(Closet)} $i
    $w create text 502.5 190 -text Closet -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 476 237 476 206 513 206 513 254 488 254 488 237 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 476 237 476 206 513 206 513 254 488 254 488 237 -fill {} -tags {floor1 room}]
    set floorLabels($i) WShower
    set {floorItems(WShower)} $i
    $w create text 494.5 230 -text WShower -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 486 131 558 131 558 135 724 135 724 166 697 166 697 275 553 275 531 254 515 254 515 174 503 174 503 161 486 161 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 486 131 558 131 558 135 724 135 724 166 697 166 697 275 553 275 531 254 515 254 515 174 503 174 503 161 486 161 -fill {} -tags {floor1 room}]
    set floorLabels($i) 130
    set {floorItems(130)} $i
    $w create text 638.5 205 -text 130 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 308 242 339 242 339 248 342 248 342 246 397 246 397 276 393 276 393 309 300 309 300 248 308 248 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 308 242 339 242 339 248 342 248 342 246 397 246 397 276 393 276 393 309 300 309 300 248 308 248 -fill {} -tags {floor1 room}]
    set floorLabels($i) 102
    set {floorItems(102)} $i
    $w create text 367.5 278.5 -text 102 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 397 255 486 255 486 276 397 276 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 397 255 486 255 486 276 397 276 -fill {} -tags {floor1 room}]
    set floorLabels($i) 128
    set {floorItems(128)} $i
    $w create text 441.5 265.5 -text 128 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 510 309 486 309 486 255 530 255 552 277 561 277 561 325 510 325 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 510 309 486 309 486 255 530 255 552 277 561 277 561 325 510 325 -fill {} -tags {floor1 room}]
    set floorLabels($i) 129
    set {floorItems(129)} $i
    $w create text 535.5 293 -text 129 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 696 281 740 281 740 387 642 387 642 389 561 389 561 277 696 277 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 696 281 740 281 740 387 642 387 642 389 561 389 561 277 696 277 -fill {} -tags {floor1 room}]
    set floorLabels($i) 133
    set {floorItems(133)} $i
    $w create text 628.5 335 -text 133 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 742 387 742 281 800 281 800 387 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 742 387 742 281 800 281 800 387 -fill {} -tags {floor1 room}]
    set floorLabels($i) 132
    set {floorItems(132)} $i
    $w create text 771 334 -text 132 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 800 168 800 280 699 280 699 168 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 800 168 800 280 699 280 699 168 -fill {} -tags {floor1 room}]
    set floorLabels($i) 134
    set {floorItems(134)} $i
    $w create text 749.5 224 -text 134 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 726 131 726 166 800 166 800 131 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 726 131 726 166 800 166 800 131 -fill {} -tags {floor1 room}]
    set floorLabels($i) 135
    set {floorItems(135)} $i
    $w create text 763 148.5 -text 135 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 340 360 335 363 331 365 326 366 304 366 304 312 396 312 396 288 400 288 404 288 409 290 413 292 418 297 421 302 422 309 421 318 417 325 411 330 405 332 397 333 344 333 340 334 336 336 335 338 332 342 331 347 332 351 334 354 336 357 341 359 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 340 360 335 363 331 365 326 366 304 366 304 312 396 312 396 288 400 288 404 288 409 290 413 292 418 297 421 302 422 309 421 318 417 325 411 330 405 332 397 333 344 333 340 334 336 336 335 338 332 342 331 347 332 351 334 354 336 357 341 359 -fill {} -tags {floor1 room}]
    set floorLabels($i) {Ramona Stair}
    set {floorItems(Ramona Stair)} $i
    $w create text 368 323 -text {Ramona Stair} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 30 23 30 5 93 5 98 5 104 7 110 10 116 16 119 20 122 28 123 32 123 68 220 68 220 87 90 87 90 23 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 30 23 30 5 93 5 98 5 104 7 110 10 116 16 119 20 122 28 123 32 123 68 220 68 220 87 90 87 90 23 -fill {} -tags {floor1 room}]
    set floorLabels($i) {University Stair}
    set {floorItems(University Stair)} $i
    $w create text 155 77.5 -text {University Stair} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 282 37 295 40 312 49 323 56 337 70 352 56 358 48 363 39 365 29 348 25 335 22 321 14 300 5 283 1 260 0 246 0 242 2 236 4 231 8 227 13 223 17 221 22 220 34 260 34 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 282 37 295 40 312 49 323 56 337 70 352 56 358 48 363 39 365 29 348 25 335 22 321 14 300 5 283 1 260 0 246 0 242 2 236 4 231 8 227 13 223 17 221 22 220 34 260 34 -fill {} -tags {floor1 room}]
    set floorLabels($i) {Plaza Stair}
    set {floorItems(Plaza Stair)} $i
    $w create text 317.5 28.5 -text {Plaza Stair} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 220 34 260 34 282 37 295 40 312 49 323 56 337 70 350 83 365 94 377 100 386 104 386 128 220 128 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 220 34 260 34 282 37 295 40 312 49 323 56 337 70 350 83 365 94 377 100 386 104 386 128 220 128 -fill {} -tags {floor1 room}]
    set floorLabels($i) {Plaza Deck}
    set {floorItems(Plaza Deck)} $i
    $w create text 303 81 -text {Plaza Deck} -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 257 336 77 336 6 336 6 301 77 301 77 310 257 310 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 257 336 77 336 6 336 6 301 77 301 77 310 257 310 -fill {} -tags {floor1 room}]
    set floorLabels($i) 106
    set {floorItems(106)} $i
    $w create text 131.5 318.5 -text 106 -fill $color -anchor c -tags {floor1 label}
    set i [$w create polygon 146 110 162 110 162 91 130 91 130 115 95 115 95 128 114 128 114 151 157 151 157 153 112 153 112 130 97 130 97 168 175 168 175 131 146 131 -fill {} -outline {} -tags {floor1 room}]
    set i [$w create polygon 146 110 162 110 162 91 130 91 130 115 95 115 95 128 114 128 114 151 157 151 157 153 112 153 112 130 97 130 97 168 175 168 175 131 146 131 -fill {} -tags {floor1 room}]
    set floorLabels($i) 119
    set {floorItems(119)} $i
    $w create text 143.5 133 -text 119 -fill $color -anchor c -tags {floor1 label}
    $w create line 155 191 155 189 -fill $color -tags {floor1 wall}
    $w create line 155 177 155 169 -fill $color -tags {floor1 wall}
    $w create line 96 129 96 169 -fill $color -tags {floor1 wall}
    $w create line 78 169 176 169 -fill $color -tags {floor1 wall}
706
707
708
709
710
711
712
713

714
715
716
717

718
719
720
721

722
723
724
725

726
727
728
729

730
731
732
733

734
735
736
737

738
739
740
741

742
743
744
745

746
747
748
749

750
751
752
753

754
755
756
757

758
759
760
761

762
763
764
765

766
767
768
769

770
771
772
773

774
775
776
777

778
779
780
781

782
783
784
785

786
787
788
789

790
791
792
793

794
795
796
797

798
799
800
801

802
803
804
805

806
807
808
809

810
811
812
813

814
815
816
817

818
819
820
821

822
823
824
825

826
827
828
829

830
831
832
833

834
835
836
837

838
839
840
841

842
843
844
845

846
847
848
849

850
851
852
853

854
855
856
857

858
859
860
861

862
863
864
865

866
867
868
869

870
871
872
873

874
875
876
877

878
879
880
881

882
883
884
885

886
887
888
889

890
891
892
893

894
895
896
897

898
899
900
901

902
903
904
905

906
907
908
909

910
911
912
913

914
915
916
917
918
919
920
692
693
694
695
696
697
698

699
700
701
702

703
704
705
706

707
708
709
710

711
712
713
714

715
716
717
718

719
720
721
722

723
724
725
726

727
728
729
730

731
732
733
734

735
736
737
738

739
740
741
742

743
744
745
746

747
748
749
750

751
752
753
754

755
756
757
758

759
760
761
762

763
764
765
766

767
768
769
770

771
772
773
774

775
776
777
778

779
780
781
782

783
784
785
786

787
788
789
790

791
792
793
794

795
796
797
798

799
800
801
802

803
804
805
806

807
808
809
810

811
812
813
814

815
816
817
818

819
820
821
822

823
824
825
826

827
828
829
830

831
832
833
834

835
836
837
838

839
840
841
842

843
844
845
846

847
848
849
850

851
852
853
854

855
856
857
858

859
860
861
862

863
864
865
866

867
868
869
870

871
872
873
874

875
876
877
878

879
880
881
882

883
884
885
886

887
888
889
890

891
892
893
894

895
896
897
898

899
900
901
902
903
904
905
906







-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+







#
# Arguments:
# w -		The canvas window.
# color -	Color to use for drawing foreground information.

proc fg2 {w color} {
    global floorLabels floorItems
    set i [$w create polygon 748 188 755 188 755 205 758 205 758 222 800 222 800 168 748 168 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 748 188 755 188 755 205 758 205 758 222 800 222 800 168 748 168 -fill {} -tags {floor2 room}]
    set floorLabels($i) 238
    set {floorItems(238)} $i
    $w create text 774 195 -text 238 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 726 188 746 188 746 166 800 166 800 131 726 131 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 726 188 746 188 746 166 800 166 800 131 726 131 -fill {} -tags {floor2 room}]
    set floorLabels($i) 237
    set {floorItems(237)} $i
    $w create text 763 148.5 -text 237 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 497 187 497 204 559 204 559 324 641 324 643 324 643 291 641 291 641 205 696 205 696 291 694 291 694 314 715 314 715 291 715 205 755 205 755 190 724 190 724 187 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 497 187 497 204 559 204 559 324 641 324 643 324 643 291 641 291 641 205 696 205 696 291 694 291 694 314 715 314 715 291 715 205 755 205 755 190 724 190 724 187 -fill {} -tags {floor2 room}]
    set floorLabels($i) 246
    set {floorItems(246)} $i
    $w create text 600 264 -text 246 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 694 279 643 279 643 314 694 314 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 694 279 643 279 643 314 694 314 -fill {} -tags {floor2 room}]
    set floorLabels($i) 247
    set {floorItems(247)} $i
    $w create text 668.5 296.5 -text 247 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 232 250 308 250 308 242 339 242 339 246 397 246 397 255 476 255 476 250 482 250 559 250 559 274 482 274 482 278 396 278 396 274 232 274 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 232 250 308 250 308 242 339 242 339 246 397 246 397 255 476 255 476 250 482 250 559 250 559 274 482 274 482 278 396 278 396 274 232 274 -fill {} -tags {floor2 room}]
    set floorLabels($i) 202
    set {floorItems(202)} $i
    $w create text 285.5 260 -text 202 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 53 228 53 338 176 338 233 338 233 196 306 196 306 180 175 180 175 169 156 169 156 196 176 196 176 228 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 53 228 53 338 176 338 233 338 233 196 306 196 306 180 175 180 175 169 156 169 156 196 176 196 176 228 -fill {} -tags {floor2 room}]
    set floorLabels($i) 206
    set {floorItems(206)} $i
    $w create text 143 267 -text 206 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 51 277 6 277 6 338 51 338 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 51 277 6 277 6 338 51 338 -fill {} -tags {floor2 room}]
    set floorLabels($i) 212
    set {floorItems(212)} $i
    $w create text 28.5 307.5 -text 212 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 557 276 486 276 486 309 510 309 510 325 557 325 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 557 276 486 276 486 309 510 309 510 325 557 325 -fill {} -tags {floor2 room}]
    set floorLabels($i) 245
    set {floorItems(245)} $i
    $w create text 521.5 300.5 -text 245 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 560 389 599 389 599 326 560 326 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 560 389 599 389 599 326 560 326 -fill {} -tags {floor2 room}]
    set floorLabels($i) 244
    set {floorItems(244)} $i
    $w create text 579.5 357.5 -text 244 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 601 389 601 326 643 326 643 389 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 601 389 601 326 643 326 643 389 -fill {} -tags {floor2 room}]
    set floorLabels($i) 243
    set {floorItems(243)} $i
    $w create text 622 357.5 -text 243 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 688 316 645 316 645 365 688 365 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 688 316 645 316 645 365 688 365 -fill {} -tags {floor2 room}]
    set floorLabels($i) 242
    set {floorItems(242)} $i
    $w create text 666.5 340.5 -text 242 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 802 367 759 367 759 226 802 226 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 802 367 759 367 759 226 802 226 -fill {} -tags {floor2 room}]
    set floorLabels($i) {Barbecue Deck}
    set {floorItems(Barbecue Deck)} $i
    $w create text 780.5 296.5 -text {Barbecue Deck} -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 755 262 755 314 717 314 717 262 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 755 262 755 314 717 314 717 262 -fill {} -tags {floor2 room}]
    set floorLabels($i) 240
    set {floorItems(240)} $i
    $w create text 736 288 -text 240 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 755 316 689 316 689 365 755 365 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 755 316 689 316 689 365 755 365 -fill {} -tags {floor2 room}]
    set floorLabels($i) 241
    set {floorItems(241)} $i
    $w create text 722 340.5 -text 241 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 755 206 717 206 717 261 755 261 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 755 206 717 206 717 261 755 261 -fill {} -tags {floor2 room}]
    set floorLabels($i) 239
    set {floorItems(239)} $i
    $w create text 736 233.5 -text 239 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 695 277 643 277 643 206 695 206 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 695 277 643 277 643 206 695 206 -fill {} -tags {floor2 room}]
    set floorLabels($i) 248
    set {floorItems(248)} $i
    $w create text 669 241.5 -text 248 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 676 135 676 185 724 185 724 135 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 676 135 676 185 724 185 724 135 -fill {} -tags {floor2 room}]
    set floorLabels($i) 236
    set {floorItems(236)} $i
    $w create text 700 160 -text 236 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 675 135 635 135 635 145 628 145 628 185 675 185 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 675 135 635 135 635 145 628 145 628 185 675 185 -fill {} -tags {floor2 room}]
    set floorLabels($i) 235
    set {floorItems(235)} $i
    $w create text 651.5 160 -text 235 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 626 143 633 143 633 135 572 135 572 143 579 143 579 185 626 185 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 626 143 633 143 633 135 572 135 572 143 579 143 579 185 626 185 -fill {} -tags {floor2 room}]
    set floorLabels($i) 234
    set {floorItems(234)} $i
    $w create text 606 160 -text 234 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 557 135 571 135 571 145 578 145 578 185 527 185 527 131 557 131 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 557 135 571 135 571 145 578 145 578 185 527 185 527 131 557 131 -fill {} -tags {floor2 room}]
    set floorLabels($i) 233
    set {floorItems(233)} $i
    $w create text 552.5 158 -text 233 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 476 249 557 249 557 205 476 205 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 476 249 557 249 557 205 476 205 -fill {} -tags {floor2 room}]
    set floorLabels($i) 230
    set {floorItems(230)} $i
    $w create text 516.5 227 -text 230 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 476 164 486 164 486 131 525 131 525 185 476 185 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 476 164 486 164 486 131 525 131 525 185 476 185 -fill {} -tags {floor2 room}]
    set floorLabels($i) 232
    set {floorItems(232)} $i
    $w create text 500.5 158 -text 232 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 476 186 495 186 495 204 476 204 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 476 186 495 186 495 204 476 204 -fill {} -tags {floor2 room}]
    set floorLabels($i) 229
    set {floorItems(229)} $i
    $w create text 485.5 195 -text 229 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 474 207 409 207 409 187 399 187 399 164 474 164 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 474 207 409 207 409 187 399 187 399 164 474 164 -fill {} -tags {floor2 room}]
    set floorLabels($i) 227
    set {floorItems(227)} $i
    $w create text 436.5 185.5 -text 227 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 399 228 399 253 474 253 474 209 409 209 409 228 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 399 228 399 253 474 253 474 209 409 209 409 228 -fill {} -tags {floor2 room}]
    set floorLabels($i) 228
    set {floorItems(228)} $i
    $w create text 436.5 231 -text 228 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 397 246 397 226 407 226 407 189 377 189 377 246 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 397 246 397 226 407 226 407 189 377 189 377 246 -fill {} -tags {floor2 room}]
    set floorLabels($i) 226
    set {floorItems(226)} $i
    $w create text 392 217.5 -text 226 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 377 169 316 169 316 131 397 131 397 188 377 188 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 377 169 316 169 316 131 397 131 397 188 377 188 -fill {} -tags {floor2 room}]
    set floorLabels($i) 225
    set {floorItems(225)} $i
    $w create text 356.5 150 -text 225 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 234 198 306 198 306 249 234 249 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 234 198 306 198 306 249 234 249 -fill {} -tags {floor2 room}]
    set floorLabels($i) 224
    set {floorItems(224)} $i
    $w create text 270 223.5 -text 224 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 270 179 306 179 306 170 314 170 314 135 270 135 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 270 179 306 179 306 170 314 170 314 135 270 135 -fill {} -tags {floor2 room}]
    set floorLabels($i) 223
    set {floorItems(223)} $i
    $w create text 292 157 -text 223 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 268 179 221 179 221 135 268 135 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 268 179 221 179 221 135 268 135 -fill {} -tags {floor2 room}]
    set floorLabels($i) 222
    set {floorItems(222)} $i
    $w create text 244.5 157 -text 222 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 177 179 219 179 219 135 177 135 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 177 179 219 179 219 135 177 135 -fill {} -tags {floor2 room}]
    set floorLabels($i) 221
    set {floorItems(221)} $i
    $w create text 198 157 -text 221 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 299 327 349 327 349 284 341 284 341 276 299 276 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 299 327 349 327 349 284 341 284 341 276 299 276 -fill {} -tags {floor2 room}]
    set floorLabels($i) 204
    set {floorItems(204)} $i
    $w create text 324 301.5 -text 204 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 234 276 297 276 297 327 257 327 257 338 234 338 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 234 276 297 276 297 327 257 327 257 338 234 338 -fill {} -tags {floor2 room}]
    set floorLabels($i) 205
    set {floorItems(205)} $i
    $w create text 265.5 307 -text 205 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 256 385 256 340 212 340 212 385 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 256 385 256 340 212 340 212 385 -fill {} -tags {floor2 room}]
    set floorLabels($i) 207
    set {floorItems(207)} $i
    $w create text 234 362.5 -text 207 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 210 340 164 340 164 385 210 385 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 210 340 164 340 164 385 210 385 -fill {} -tags {floor2 room}]
    set floorLabels($i) 208
    set {floorItems(208)} $i
    $w create text 187 362.5 -text 208 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 115 340 162 340 162 385 115 385 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 115 340 162 340 162 385 115 385 -fill {} -tags {floor2 room}]
    set floorLabels($i) 209
    set {floorItems(209)} $i
    $w create text 138.5 362.5 -text 209 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 89 228 89 156 53 156 53 228 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 89 228 89 156 53 156 53 228 -fill {} -tags {floor2 room}]
    set floorLabels($i) 217
    set {floorItems(217)} $i
    $w create text 71 192 -text 217 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 89 169 97 169 97 190 89 190 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 89 169 97 169 97 190 89 190 -fill {} -tags {floor2 room}]
    set floorLabels($i) 217A
    set {floorItems(217A)} $i
    $w create text 93 179.5 -text 217A -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 89 156 89 168 95 168 95 135 53 135 53 156 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 89 156 89 168 95 168 95 135 53 135 53 156 -fill {} -tags {floor2 room}]
    set floorLabels($i) 216
    set {floorItems(216)} $i
    $w create text 71 145.5 -text 216 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 51 179 51 135 6 135 6 179 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 51 179 51 135 6 135 6 179 -fill {} -tags {floor2 room}]
    set floorLabels($i) 215
    set {floorItems(215)} $i
    $w create text 28.5 157 -text 215 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 51 227 6 227 6 180 51 180 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 51 227 6 227 6 180 51 180 -fill {} -tags {floor2 room}]
    set floorLabels($i) 214
    set {floorItems(214)} $i
    $w create text 28.5 203.5 -text 214 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 51 275 6 275 6 229 51 229 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 51 275 6 275 6 229 51 229 -fill {} -tags {floor2 room}]
    set floorLabels($i) 213
    set {floorItems(213)} $i
    $w create text 28.5 252 -text 213 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 114 340 67 340 67 385 114 385 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 114 340 67 340 67 385 114 385 -fill {} -tags {floor2 room}]
    set floorLabels($i) 210
    set {floorItems(210)} $i
    $w create text 90.5 362.5 -text 210 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 59 389 59 385 65 385 65 340 1 340 1 389 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 59 389 59 385 65 385 65 340 1 340 1 389 -fill {} -tags {floor2 room}]
    set floorLabels($i) 211
    set {floorItems(211)} $i
    $w create text 33 364.5 -text 211 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 393 309 350 309 350 282 342 282 342 276 393 276 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 393 309 350 309 350 282 342 282 342 276 393 276 -fill {} -tags {floor2 room}]
    set floorLabels($i) 203
    set {floorItems(203)} $i
    $w create text 367.5 292.5 -text 203 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 99 191 91 191 91 226 174 226 174 198 154 198 154 192 109 192 109 169 99 169 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 99 191 91 191 91 226 174 226 174 198 154 198 154 192 109 192 109 169 99 169 -fill {} -tags {floor2 room}]
    set floorLabels($i) 220
    set {floorItems(220)} $i
    $w create text 132.5 208.5 -text 220 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -tags {floor2 room}]
    set floorLabels($i) {Priv Lift2}
    set {floorItems(Priv Lift2)} $i
    $w create text 323 188 -text {Priv Lift2} -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -tags {floor2 room}]
    set floorLabels($i) {Pub Lift 2}
    set {floorItems(Pub Lift 2)} $i
    $w create text 323 223 -text {Pub Lift 2} -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 175 168 97 168 97 131 175 131 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 175 168 97 168 97 131 175 131 -fill {} -tags {floor2 room}]
    set floorLabels($i) 218
    set {floorItems(218)} $i
    $w create text 136 149.5 -text 218 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 154 191 111 191 111 169 154 169 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 154 191 111 191 111 169 154 169 -fill {} -tags {floor2 room}]
    set floorLabels($i) 219
    set {floorItems(219)} $i
    $w create text 132.5 180 -text 219 -fill $color -anchor c -tags {floor2 label}
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -outline {} -tags {floor2 room}]
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -tags {floor2 room}]
    set floorLabels($i) 201
    set {floorItems(201)} $i
    $w create text 358 209 -text 201 -fill $color -anchor c -tags {floor2 label}
    $w create line 641 186 678 186 -fill $color -tags {floor2 wall}
    $w create line 757 350 757 367 -fill $color -tags {floor2 wall}
    $w create line 634 133 634 144 -fill $color -tags {floor2 wall}
    $w create line 634 144 627 144 -fill $color -tags {floor2 wall}
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087

1088
1089
1090
1091

1092
1093
1094
1095

1096
1097
1098
1099

1100
1101
1102
1103

1104
1105
1106
1107

1108
1109
1110
1111

1112
1113
1114
1115

1116
1117
1118
1119

1120
1121
1122
1123

1124
1125
1126
1127

1128
1129
1130
1131

1132
1133
1134
1135

1136
1137
1138
1139

1140
1141
1142
1143

1144
1145
1146
1147

1148
1149
1150
1151

1152
1153
1154
1155

1156
1157
1158
1159

1160
1161
1162
1163

1164
1165
1166
1167

1168
1169
1170
1171

1172
1173
1174
1175

1176
1177
1178
1179

1180
1181
1182
1183

1184
1185
1186
1187

1188
1189
1190
1191

1192
1193
1194
1195

1196
1197
1198
1199

1200
1201
1202
1203

1204
1205
1206
1207

1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072

1073
1074
1075
1076

1077
1078
1079
1080

1081
1082
1083
1084

1085
1086
1087
1088

1089
1090
1091
1092

1093
1094
1095
1096

1097
1098
1099
1100

1101
1102
1103
1104

1105
1106
1107
1108

1109
1110
1111
1112

1113
1114
1115
1116

1117
1118
1119
1120

1121
1122
1123
1124

1125
1126
1127
1128

1129
1130
1131
1132

1133
1134
1135
1136

1137
1138
1139
1140

1141
1142
1143
1144

1145
1146
1147
1148

1149
1150
1151
1152

1153
1154
1155
1156

1157
1158
1159
1160

1161
1162
1163
1164

1165
1166
1167
1168

1169
1170
1171
1172

1173
1174
1175
1176

1177
1178
1179
1180

1181
1182
1183
1184

1185
1186
1187
1188

1189
1190
1191
1192

1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204







-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+







#
# Arguments:
# w -		The canvas window.
# color -	Color to use for drawing foreground information.

proc fg3 {w color} {
    global floorLabels floorItems
    set i [$w create polygon 89 228 89 180 70 180 70 228 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 89 228 89 180 70 180 70 228 -fill {} -tags {floor3 room}]
    set floorLabels($i) 316
    set {floorItems(316)} $i
    $w create text 79.5 204 -text 316 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 115 368 162 368 162 323 115 323 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 115 368 162 368 162 323 115 323 -fill {} -tags {floor3 room}]
    set floorLabels($i) 309
    set {floorItems(309)} $i
    $w create text 138.5 345.5 -text 309 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 164 323 164 368 211 368 211 323 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 164 323 164 368 211 368 211 323 -fill {} -tags {floor3 room}]
    set floorLabels($i) 308
    set {floorItems(308)} $i
    $w create text 187.5 345.5 -text 308 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 256 368 212 368 212 323 256 323 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 256 368 212 368 212 323 256 323 -fill {} -tags {floor3 room}]
    set floorLabels($i) 307
    set {floorItems(307)} $i
    $w create text 234 345.5 -text 307 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 244 276 297 276 297 327 260 327 260 321 244 321 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 244 276 297 276 297 327 260 327 260 321 244 321 -fill {} -tags {floor3 room}]
    set floorLabels($i) 305
    set {floorItems(305)} $i
    $w create text 270.5 301.5 -text 305 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 251 219 251 203 244 203 244 219 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 251 219 251 203 244 203 244 219 -fill {} -tags {floor3 room}]
    set floorLabels($i) 324B
    set {floorItems(324B)} $i
    $w create text 247.5 211 -text 324B -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 251 249 244 249 244 232 251 232 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 251 249 244 249 244 232 251 232 -fill {} -tags {floor3 room}]
    set floorLabels($i) 324A
    set {floorItems(324A)} $i
    $w create text 247.5 240.5 -text 324A -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 223 135 223 179 177 179 177 135 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 223 135 223 179 177 179 177 135 -fill {} -tags {floor3 room}]
    set floorLabels($i) 320
    set {floorItems(320)} $i
    $w create text 200 157 -text 320 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 114 368 114 323 67 323 67 368 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 114 368 114 323 67 323 67 368 -fill {} -tags {floor3 room}]
    set floorLabels($i) 310
    set {floorItems(310)} $i
    $w create text 90.5 345.5 -text 310 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 23 277 23 321 68 321 68 277 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 23 277 23 321 68 321 68 277 -fill {} -tags {floor3 room}]
    set floorLabels($i) 312
    set {floorItems(312)} $i
    $w create text 45.5 299 -text 312 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 23 229 68 229 68 275 23 275 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 23 229 68 229 68 275 23 275 -fill {} -tags {floor3 room}]
    set floorLabels($i) 313
    set {floorItems(313)} $i
    $w create text 45.5 252 -text 313 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 68 227 23 227 23 180 68 180 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 68 227 23 227 23 180 68 180 -fill {} -tags {floor3 room}]
    set floorLabels($i) 314
    set {floorItems(314)} $i
    $w create text 45.5 203.5 -text 314 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 95 179 95 135 23 135 23 179 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 95 179 95 135 23 135 23 179 -fill {} -tags {floor3 room}]
    set floorLabels($i) 315
    set {floorItems(315)} $i
    $w create text 59 157 -text 315 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 99 226 99 204 91 204 91 226 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 99 226 99 204 91 204 91 226 -fill {} -tags {floor3 room}]
    set floorLabels($i) 316B
    set {floorItems(316B)} $i
    $w create text 95 215 -text 316B -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 91 202 99 202 99 180 91 180 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 91 202 99 202 99 180 91 180 -fill {} -tags {floor3 room}]
    set floorLabels($i) 316A
    set {floorItems(316A)} $i
    $w create text 95 191 -text 316A -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 97 169 109 169 109 192 154 192 154 198 174 198 174 226 101 226 101 179 97 179 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 97 169 109 169 109 192 154 192 154 198 174 198 174 226 101 226 101 179 97 179 -fill {} -tags {floor3 room}]
    set floorLabels($i) 319
    set {floorItems(319)} $i
    $w create text 141.5 209 -text 319 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 65 368 58 368 58 389 1 389 1 333 23 333 23 323 65 323 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 65 368 58 368 58 389 1 389 1 333 23 333 23 323 65 323 -fill {} -tags {floor3 room}]
    set floorLabels($i) 311
    set {floorItems(311)} $i
    $w create text 29.5 361 -text 311 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 154 191 111 191 111 169 154 169 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 154 191 111 191 111 169 154 169 -fill {} -tags {floor3 room}]
    set floorLabels($i) 318
    set {floorItems(318)} $i
    $w create text 132.5 180 -text 318 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 175 168 97 168 97 131 175 131 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 175 168 97 168 97 131 175 131 -fill {} -tags {floor3 room}]
    set floorLabels($i) 317
    set {floorItems(317)} $i
    $w create text 136 149.5 -text 317 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 274 194 274 221 306 221 306 194 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 274 194 274 221 306 221 306 194 -fill {} -tags {floor3 room}]
    set floorLabels($i) 323
    set {floorItems(323)} $i
    $w create text 290 207.5 -text 323 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 306 222 274 222 274 249 306 249 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 306 222 274 222 274 249 306 249 -fill {} -tags {floor3 room}]
    set floorLabels($i) 325
    set {floorItems(325)} $i
    $w create text 290 235.5 -text 325 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 263 179 224 179 224 135 263 135 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 263 179 224 179 224 135 263 135 -fill {} -tags {floor3 room}]
    set floorLabels($i) 321
    set {floorItems(321)} $i
    $w create text 243.5 157 -text 321 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 314 169 306 169 306 192 273 192 264 181 264 135 314 135 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 314 169 306 169 306 192 273 192 264 181 264 135 314 135 -fill {} -tags {floor3 room}]
    set floorLabels($i) 322
    set {floorItems(322)} $i
    $w create text 293.5 163.5 -text 322 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 307 240 339 240 339 206 307 206 -fill {} -tags {floor3 room}]
    set floorLabels($i) {Pub Lift3}
    set {floorItems(Pub Lift3)} $i
    $w create text 323 223 -text {Pub Lift3} -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 339 205 307 205 307 171 339 171 -fill {} -tags {floor3 room}]
    set floorLabels($i) {Priv Lift3}
    set {floorItems(Priv Lift3)} $i
    $w create text 323 188 -text {Priv Lift3} -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 350 284 376 284 376 276 397 276 397 309 350 309 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 350 284 376 284 376 276 397 276 397 309 350 309 -fill {} -tags {floor3 room}]
    set floorLabels($i) 303
    set {floorItems(303)} $i
    $w create text 373.5 292.5 -text 303 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 272 203 272 249 252 249 252 230 244 230 244 221 252 221 252 203 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 272 203 272 249 252 249 252 230 244 230 244 221 252 221 252 203 -fill {} -tags {floor3 room}]
    set floorLabels($i) 324
    set {floorItems(324)} $i
    $w create text 262 226 -text 324 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 299 276 299 327 349 327 349 284 341 284 341 276 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 299 276 299 327 349 327 349 284 341 284 341 276 -fill {} -tags {floor3 room}]
    set floorLabels($i) 304
    set {floorItems(304)} $i
    $w create text 324 301.5 -text 304 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 375 246 375 172 341 172 341 246 -fill {} -tags {floor3 room}]
    set floorLabels($i) 301
    set {floorItems(301)} $i
    $w create text 358 209 -text 301 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 397 246 377 246 377 185 397 185 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 397 246 377 246 377 185 397 185 -fill {} -tags {floor3 room}]
    set floorLabels($i) 327
    set {floorItems(327)} $i
    $w create text 387 215.5 -text 327 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 316 131 316 169 377 169 377 185 397 185 397 131 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 316 131 316 169 377 169 377 185 397 185 397 131 -fill {} -tags {floor3 room}]
    set floorLabels($i) 326
    set {floorItems(326)} $i
    $w create text 356.5 150 -text 326 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 308 251 242 251 242 274 342 274 342 282 375 282 375 274 397 274 397 248 339 248 339 242 308 242 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 308 251 242 251 242 274 342 274 342 282 375 282 375 274 397 274 397 248 339 248 339 242 308 242 -fill {} -tags {floor3 room}]
    set floorLabels($i) 302
    set {floorItems(302)} $i
    $w create text 319.5 261 -text 302 -fill $color -anchor c -tags {floor3 label}
    set i [$w create polygon 70 321 242 321 242 200 259 200 259 203 272 203 272 193 263 180 242 180 175 180 175 169 156 169 156 196 177 196 177 228 107 228 70 228 70 275 107 275 107 248 160 248 160 301 107 301 107 275 70 275 -fill {} -outline {} -tags {floor3 room}]
    set i [$w create polygon 70 321 242 321 242 200 259 200 259 203 272 203 272 193 263 180 242 180 175 180 175 169 156 169 156 196 177 196 177 228 107 228 70 228 70 275 107 275 107 248 160 248 160 301 107 301 107 275 70 275 -fill {} -tags {floor3 room}]
    set floorLabels($i) 306
    set {floorItems(306)} $i
    $w create text 200.5 284.5 -text 306 -fill $color -anchor c -tags {floor3 label}
    $w create line 341 275 341 283 -fill $color -tags {floor3 wall}
    $w create line 162 197 155 197 -fill $color -tags {floor3 wall}
    $w create line 396 247 399 247 -fill $color -tags {floor3 wall}
    $w create line 399 129 399 311 -fill $color -tags {floor3 wall}
1306
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328



1329
1330
1331
1332
1333
1334
1335
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312


1313
1314
1315
1316
1317
1318
1319
1320
1321
1322







-
+













-
-
+
+
+







set w .floor
global c currentRoom colors activeFloor
catch {destroy $w}
toplevel $w
wm title $w "Floorplan Canvas Demonstration"
wm iconname $w "Floorplan"
wm geometry $w +20+20
wm minsize $w 75p 75p
wm minsize $w 100 100

label $w.msg -font $font -wraplength 8i -justify left  -text "This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory.  It has three levels.  At any given time one of the levels is active, meaning that you can see its room structure.  To activate a level, click the left mouse button anywhere on it.  As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry.  You can also type a room number in the entry and the room will light up."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

set f [frame $w.frame]
pack $f -side top -fill both -expand yes
set h [ttk::scrollbar $f.hscroll -orient horizontal]
set v [ttk::scrollbar $f.vscroll -orient vertical]
set f1 [frame $f.f1 -borderwidth 2 -relief sunken]
set c [canvas $f1.c -highlightthickness 0 \
	   -xscrollcommand [list $h set] -yscrollcommand [list $v set]]
set c [canvas $f1.c -width 900 -height 500 -highlightthickness 0 \
	   -xscrollcommand [list $h set] \
	   -yscrollcommand [list $v set]]
pack $c -expand yes -fill both
grid $f1 -padx 1 -pady 1 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid $v -padx 1 -pady 1 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
grid $h -padx 1 -pady 1 -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid rowconfig    $f 0 -weight 1 -minsize 0
grid columnconfig $f 0 -weight 1 -minsize 0
pack $f -expand yes -fill both -padx 1 -pady 1
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372



1373
1374
1375
1376
1377
1378
1379
1380


1381
1382
1383
1384

1350
1351
1352
1353
1354
1355
1356



1357
1358
1359
1360
1361






1362
1363

1364
1365

1366







-
-
-
+
+
+


-
-
-
-
-
-
+
+
-


-
+
    set colors(active) black
}
set activeFloor ""
floorDisplay $c 3

# Set up event bindings for canvas:

$c bind floor1 <Button-1> "floorDisplay $c 1"
$c bind floor2 <Button-1> "floorDisplay $c 2"
$c bind floor3 <Button-1> "floorDisplay $c 3"
$c bind floor1 <1> "floorDisplay $c 1"
$c bind floor2 <1> "floorDisplay $c 2"
$c bind floor3 <1> "floorDisplay $c 3"
$c bind room <Enter> "newRoom $c"
$c bind room <Leave> {set currentRoom ""}
if {[tk windowingsystem] eq "aqua" && ![package vsatisfies [package provide tk] 8.7-]} {
    bind $c <Button-3> "$c scan mark %x %y"
    bind $c <B3-Motion> "$c scan dragto %x %y"
} else {
    bind $c <Button-2> "$c scan mark %x %y"
    bind $c <B2-Motion> "$c scan dragto %x %y"
bind $c <2> "$c scan mark %x %y"
bind $c <B2-Motion> "$c scan dragto %x %y"
}
bind $c <Destroy> "unset currentRoom"
set currentRoom ""
trace add variable currentRoom write "roomChanged $c"
trace variable currentRoom w "roomChanged $c"

Changes to library/demos/fontchoose.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# fontchoose.tcl --
#
# Show off the stock font selector dialog

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .fontchoose
catch {destroy $w}
toplevel $w
wm title $w "Font Selection Dialog"
wm iconname $w "fontchooser"
positionWindow $w
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57




58
59
60
61
62
63
64
65
66
67
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69









-
+














+
+
+
+








-
-
        %W.f.font state disabled
    } else {
        %W.f.font state !disabled
    }
}


set f [ttk::frame $w.f -relief sunken -padding 1.5p]
set f [ttk::frame $w.f -relief sunken -padding 2]

text $f.msg -font FontchooseDemoFont -width 40 -height 6 -borderwidth 0 \
    -yscrollcommand [list $f.vs set]
ttk::scrollbar $f.vs -command [list $f.msg yview]

$f.msg insert end "Press the buttons below to choose a new font for the\
  text shown in this window.\n" {}

ttk::button $f.font -text "Set font ..." -command [list SelectFont $w]

grid $f.msg $f.vs -sticky news
grid $f.font -    -sticky e
grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1
bind $w <Visibility> {
    bind %W <Visibility> {}
    grid propagate %W.f 0
}

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]

grid $f -sticky news
grid $btns -sticky ew
grid columnconfigure $w 0 -weight 1
grid rowconfigure $w 0 -weight 1
update idletasks
grid propagate $f 0

Changes to library/demos/form.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# form.tcl --
#
# This demonstration script creates a simple form with a bunch
# of entry widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .form
catch {destroy $w}
toplevel $w
wm title $w "Form Demonstration"
wm iconname $w "form"
positionWindow $w

Changes to library/demos/goldberg.tcl.

36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56



57
58
59
60



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88

89
90
91
92
93
94
95
96


97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124


125
126
127
128
129
130



131
132
133
134

135
136
137
138
139
140
141
142

143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172

173
174

175
176
177


178
179

180
181
182
183
184
185
186
187



188
189

190
191

192
193
194

195
196

197
198
199



200
201
202
203
204
205
206
207
208
209
210






211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52




53
54
55




56
57
58
59
60






















61
62
63
64

65
66
67
68
69
70
71


72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96

97
98


99
100
101
102




103
104
105
106
107


108
109
110
111
112
113
114
115

116
117



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139

140
141
142

143
144

145
146


147
148
149

150
151
152
153
154
155



156
157
158
159

160
161

162
163
164

165
166
167
168



169
170
171
172










173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209

210
211
212
213
214

215
216
217
218
219
220


































221
222
223
224
225
226
227







-
+









-
-
-
-
+
+
+
-
-
-
-
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+



-
+






-
-
+
+
-






+














-


-
+

-
-
+
+


-
-
-
-
+
+
+


-
-
+







-
+

-
-
-
+




















-
+
-



-
+

-
+

-
-
+
+

-
+





-
-
-
+
+
+

-
+

-
+


-
+


+
-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+









+


















-
+


-
+




-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







# I could comment on the code, but it's just 26 state machines with
# lots of canvas create and move calls.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .goldberg
catch {destroy $w}
toplevel $w
wm title $w "Tk Goldberg (demonstration)"
wm iconname $w "goldberg"
wm resizable $w 0 0
#positionWindow $w

proc StartMessage {w} {
    set msg1 "This\
	    is a demonstration of just how complex you can make your animations\
	    become. Close this dialog and click the ball to start things\
label $w.msg -font {Arial 10} -wraplength 4i -justify left -text "This is a\
	demonstration of just how complex you can make your animations\
	become. Click the ball to start things moving!\n\n\"Man will always\
	    moving!\n\n\"Man will always find a difficult means to perform a\
	    simple task\"\n - Rube Goldberg"
    PlacedDialog $w.c.messframe $msg1 {Helvetica 12}
}
	find a difficult means to perform a simple task\"\n - Rube Goldberg"
pack $w.msg -side top

###--- End of Boilerplate ---###

array set BaseDimensions {
    CanX    675
    CanY    540
    ScrX    750
    ScrY    750
    MsgX    338
    MsgY    573
    MovX     10
    MovY    -45
}

# The original value was 1.0 but this can make the demo
# too large for the screen.  Try a smaller value.
set overallFactor 0.75

foreach el [array names BaseDimensions] {
    set Dims($el) [expr {$BaseDimensions($el) * $overallFactor}]p
}

set scaleFactor [expr {$::tk::scalingPct / 100.0 * $overallFactor}]

# Ensure that this is an array
# Ensure that this this is an array
array set animationCallbacks {}
bind $w <Destroy> {
    if {"%W" eq [winfo toplevel %W]} {
	unset S C delays
	unset S C speed
    }
}

set S(title) "Tk Goldberg"
set S(speed) 5
set S(cnt) 0
set S(message) "\\nWelcome\\nto\\nTcl/Tk!"
array set delays \
set S(message) "\\nWelcome\\nto\\nTcl/Tk"
array set speed {1 10 2 20 3 50 4 80 5 100 6 150 7 200 8 300 9 400 10 500}
	{1 500  2 400  3 300  4 200  5 150  6 100  7 80  8 50  9 20  10 10}

set MSTART 0; set MGO 1; set MPAUSE 2; set MSSTEP 3; set MBSTEP 4; set MDONE 5
set S(mode) $::MSTART

# Colors for everything
set C(fg) black
set C(bg) gray75
set C(bg) cornflowerblue

set C(0) white;		set C(1a) darkgreen;	set C(1b) yellow
set C(2) red;		set C(3a) green;	set C(3b) darkblue
set C(4) $C(fg);	set C(5a) brown;	set C(5b) white
set C(6) magenta;	set C(7) green;		set C(8) $C(fg)
set C(9) blue4;		set C(10a) white;	set C(10b) cyan
set C(11a) yellow;	set C(11b) mediumblue;	set C(12) tan2
set C(13a) yellow;	set C(13b) red;		set C(14) white
set C(15a) green;	set C(15b) yellow;	set C(16) gray65
set C(17) \#A65353;	set C(18) $C(fg);	set C(19) gray50
set C(20) cyan;		set C(21) gray65;	set C(22) $C(20)
set C(23a) blue;	set C(23b) red;		set C(23c) yellow
set C(24a) red;		set C(24b) white;
set C(24c) black;	set C(26) $C(0);

proc DoDisplay {w} {
    global S C Dims
    global S C

    ttk::frame $w.ctrl -relief ridge -borderwidth 1 -padding 3p
    pack [frame $w.screen -bd 1 -relief raised] \
    ttk::frame $w.ctrl -relief ridge -borderwidth 2 -padding 5
    pack [frame $w.screen -bd 2 -relief raised] \
	    -side left -fill both -expand 1

    canvas $w.c -width $Dims(CanX) -height $Dims(CanY) -bg $C(bg) \
	    -highlightthickness 0
    $w.c config -scrollregion [list 0 0 $Dims(ScrX) $Dims(ScrY)]
    $w.c yview moveto .06			;# Kludge: move everything up
    canvas $w.c -width 860 -height 730 -bg $C(bg) -highlightthickness 0
    $w.c config -scrollregion {0 0 1000 1000}	;# Kludge: move everything up
    $w.c yview moveto .05
    pack $w.c -in $w.screen -side top -fill both -expand 1

    bind $w.c <Configure> { %W yview moveto .06 }
    bind $w.c <Button-3> [list $w.pause invoke]
    bind $w.c <3> [list $w.pause invoke]
    bind $w.c <Destroy> {
	after cancel $animationCallbacks(goldberg)
	unset animationCallbacks(goldberg)
    }
    DoCtrlFrame $w
    DoDetailFrame $w
    if {[tk windowingsystem] ne "aqua"} {
	ttk::button $w.show -text "" -command [list ShowCtrl $w] -width 2
	ttk::button $w.show -text "\u00bb" -command [list ShowCtrl $w] -width 2
    } else {
	button $w.show -text "▶" -command [list ShowCtrl $w] -width 1 \
		-borderwidth 1 -highlightthickness 0 -padx 0 -pady 0 \
		-highlightbackground $C(bg)
	button $w.show -text "\u00bb" -command [list ShowCtrl $w] -width 2 -highlightbackground $C(bg)
    }
    place $w.show -in $w.c -relx 1 -rely 0 -anchor ne
    update
}

proc DoCtrlFrame {w} {
    global S
    ttk::button $w.start -text "Start" -command [list DoButton $w 0]
    ttk::checkbutton $w.pause -text "Pause" -command [list DoButton $w 1] \
	    -variable S(pause)
    ttk::button $w.step -text "Single Step" -command [list DoButton $w 2]
    ttk::button $w.bstep -text "Big Step" -command [list DoButton $w 4]
    ttk::button $w.reset -text "Reset" -command [list DoButton $w 3]
    ttk::labelframe $w.details
    raise $w.details
    set S(details) 0
    ttk::checkbutton $w.details.cb -text "Details" -variable S(details)
    ttk::labelframe $w.message -text "Message"
    ttk::entry $w.message.e -textvariable S(message) -justify center
    ttk::labelframe $w.speed -text "Speed: 0"
    ttk::scale $w.speed.scale -orient horizontal -from 1 -to 10 \
    ttk::scale $w.speed.scale -orient h -from 1 -to 10 -variable S(speed)
	    -variable S(speed)
    ttk::button $w.about -text About -command [list About $w]

    grid $w.start -in $w.ctrl -row 0 -sticky ew
    grid rowconfigure $w.ctrl 1 -minsize 3p
    grid rowconfigure $w.ctrl 1 -minsize 10
    grid $w.pause -in $w.ctrl -row 2 -sticky ew
    grid $w.step  -in $w.ctrl -sticky ew -pady 1.5p
    grid $w.step  -in $w.ctrl -sticky ew -pady 2
    grid $w.bstep -in $w.ctrl -sticky ew
    grid $w.reset -in $w.ctrl -sticky ew -pady 1.5p
    grid rowconfigure $w.ctrl 10 -minsize 3p
    grid $w.reset -in $w.ctrl -sticky ew -pady 2
    grid rowconfigure $w.ctrl 10 -minsize 18
    grid $w.details -in $w.ctrl -row 11 -sticky ew
    grid rowconfigure $w.ctrl 11 -minsize 3p
    grid rowconfigure $w.ctrl 11 -minsize 20
    $w.details configure -labelwidget $w.details.cb
    grid [ttk::frame $w.details.b -height 1]	;# Work around minor bug
    raise $w.details
    raise $w.details.cb
    grid rowconfigure $w.ctrl 50 -weight 1
    trace add variable ::S(mode) write	  [list ActiveGUI $w]
    trace add variable ::S(details) write [list ActiveGUI $w]
    trace add variable ::S(speed) write	  [list ActiveGUI $w]
    trace variable ::S(mode) w	  [list ActiveGUI $w]
    trace variable ::S(details) w [list ActiveGUI $w]
    trace variable ::S(speed) w	  [list ActiveGUI $w]

    grid $w.message -in $w.ctrl -row 98 -sticky ew -pady {0 3p}
    grid $w.message -in $w.ctrl -row 98 -sticky ew -pady 5
    grid $w.message.e -sticky nsew
    grid $w.speed -in $w.ctrl -row 99 -sticky ew -pady {0 3p}
    grid $w.speed -in $w.ctrl -row 99 -sticky ew -pady {0 5}
    pack $w.speed.scale -fill both -expand 1
    grid $w.about -in $w.ctrl -row 100 -sticky ew
    bind $w.reset <Button-3> {set S(mode) -1}		;# Debugging
    bind $w.reset <3> {set S(mode) -1}		;# Debugging

    ## See Code / Dismiss buttons hack!
    set btns [addSeeDismiss $w.ctrl.buttons $w]
    grid [ttk::separator $w.ctrl.sep] -sticky ew -pady {3p 1.5p}
    set btns {}
    foreach b [winfo children [addSeeDismiss $w.ctrl.buttons $w]] {
    grid [ttk::separator $w.ctrl.sep] -sticky ew -pady 4
    set i 0
    foreach b [winfo children $btns] {
	if {[winfo class $b] eq "TButton"} {
	    set btns [linsert $btns 0 $b]		;# Prepend
	}
    }
    set i 0
    foreach b $btns {
	grid [set b2 [ttk::button $w.ctrl.b[incr i]]] -sticky ew -pady {1.5p 0}
	foreach b3 [$b configure] {
	    set b3 [lindex $b3 0]
	    # Some options are read-only; ignore those errors
	    catch {$b2 configure $b3 [$b cget $b3]}
	    grid [set b2 [ttk::button $w.ctrl.b[incr i]]] -sticky ew
	    foreach b3 [$b configure] {
		set b3 [lindex $b3 0]
		# Some options are read-only; ignore those errors
		catch {$b2 configure $b3 [$b cget $b3]}
	    }
	}
    }
    destroy $btns
}

proc DoDetailFrame {w} {
    set w2 $w.details.f
    ttk::frame $w2

    set bd 2
    ttk::label $w2.l -textvariable S(cnt) -background white
    grid $w2.l - - - -sticky ew -row 0
    for {set i 1} {1} {incr i} {
	if {[info procs "Move$i"] eq ""} break
	ttk::label $w2.l$i -text $i -anchor e -width 2 -background white
	ttk::label $w2.ll$i -textvariable STEP($i) -width 5 -background white
	set row [expr {($i + 1) / 2}]
	set col [expr {(($i + 1) & 1) * 2}]
	grid $w2.l$i -sticky ew -row $row -column $col
	grid $w2.ll$i -sticky ew -row $row -column [incr col]
    }
    grid columnconfigure $w2 1 -weight 1
}

# Map or unmap the ctrl window
proc ShowCtrl {w} {
    if {[winfo ismapped $w.ctrl]} {
	pack forget $w.ctrl
	$w.show config -text ""
	$w.show config -text "\u00bb"
    } else {
	pack $w.ctrl -side right -fill both -ipady 5
	$w.show config -text ""
	$w.show config -text "\u00ab"
    }
}

proc DrawAll {w} {
    global scaleFactor
    ResetStep
    $w.c delete all
    for {set i 0} {1} {incr i} {
	set p "Draw$i"
	if {[info procs $p] eq ""} break
	$p $w
    }

    $w.c scale all 0 0 $scaleFactor $scaleFactor

    # Tile the strike box with a 4x4 bitmap image derived
    # from Tk's built-in 16x16 bitmap gray25.  Adjust
    # x1, y2 to make dimensions multiples of 4 pixels.

    image create bitmap smallGray25 -data {
	#define smallGray25_width 4
	#define smallGray25_height 4
	static unsigned char smallGray25_bits[] = {
	    0x08, 0x02, 0x08, 0x02};
    } -foreground $::C(fg)

    lassign [$w.c coords StrikeBox] x1 y1 x2 y2
    set oldMidY [expr {round(($y1 + $y2) / 2.0)}]

    set rowCount [expr {round(($y2 - $y1) / 4.0)}]
    set colCount [expr {round(($x2 - $x1) / 4.0)}]
    set x2 [expr {round($x2)}]
    set x1 [expr {$x2 - $colCount * 4}]
    set y1 [expr {round($y1)}]
    set y2 [expr {$y1 + $rowCount * 4}]

    set newMidY [expr {round(($y1 + $y2) / 2.0)}]
    set deltaY [expr {$oldMidY - $newMidY}]
    incr y1 $deltaY; incr y2 $deltaY
    $w.c coords StrikeBox $x1 $y1 $x2 $y2

    for {set row 0; set y $y1} {$row < $rowCount} {incr row; incr y 4} {
	for {set col 0; set x $x1} {$col < $colCount} {incr col; incr x 4} {
	    $w.c create image $x $y -image smallGray25 -anchor nw
	}
    }
}

proc ActiveGUI {w var1 var2 op} {
    global S MGO MSTART MDONE
    array set z {0 disabled 1 normal}

329
330
331
332
333
334
335
336

337
338
339
340
341

342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
263
264
265
266
267
268
269

270
271
272
273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298







-
+




-
+















-
+







	Reset $w
    } elseif {$what == 4} {			;# Big step
	set S(mode) $MBSTEP
    }
}

proc Go {w {who {}}} {
    global S delays animationCallbacks MGO MPAUSE MSSTEP MBSTEP
    global S speed animationCallbacks MGO MPAUSE MSSTEP MBSTEP

    set now [clock clicks -milliseconds]
    catch {after cancel $animationCallbacks(goldberg)}
    if {$who ne ""} {				;# Start here for debugging
	set S(active) $who
	set S(active) $who;
	set S(mode) $MGO
    }
    if {$S(mode) == -1} return			;# Debugging
    set n 0
    if {$S(mode) != $MPAUSE} {			;# Not paused
	set n [NextStep $w]			;# Do the next move
    }
    if {$S(mode) == $MSSTEP} {			;# Single step
	set S(mode) $MPAUSE
    }
    if {$S(mode) == $MBSTEP && $n} {		;# Big step
	set S(mode) $MSSTEP
    }

    set elapsed [expr {[clock click -milliseconds] - $now}]
    set delay [expr {$delays($S(speed)) - $elapsed}]
    set delay [expr {$speed($S(speed)) - $elapsed}]
    if {$delay <= 0} {
	set delay 1
    }
    set animationCallbacks(goldberg) [after $delay [list Go $w]]
}

# NextStep: drives the next step of the animation
384
385
386
387
388
389
390
391
392
393
394
395
396


397
398
399
400
401
402
403
404
405
406
407
408
409



410
411
412
413



414
415
416
417
418
419
420
421
422
423
424
425



426

427
428

429
430
431
432
433
434
435
436
437
438
439

440
441

442
443
444
445

446
447
448
449

450
451
452
453

454
455
456
457
458
459
460
318
319
320
321
322
323
324

325
326
327


328
329

330
331
332
333
334
335
336
337
338



339
340
341
342



343
344
345
346
347
348
349
350
351
352
353
354



355
356
357

358
359

360


361
362
363
364
365
366
367
368

369
370

371
372
373
374

375
376
377
378

379
380
381
382

383
384
385
386
387
388
389
390







-



-
-
+
+
-









-
-
-
+
+
+

-
-
-
+
+
+









-
-
-
+
+
+
-
+

-
+
-
-








-
+

-
+



-
+



-
+



-
+







	    set S(active) {}			;# No more animation
	    return 1
	}
    }
    set S(active) $alive
    return $rval
}

proc About {w} {
    set msg "$::S(title)\nby Keith Vetter, March 2003\n(Reproduced by kind\
	    permission of the author)\n\n\"Man will always find a difficult\
	    means to perform a simple task.\"\n - Rube Goldberg"
    PlacedDialog $w.c.messframe $msg {Helvetica 12 bold}
	    means to perform a simple task.\"\nRube Goldberg"
    tk_messageBox -parent $w -message $msg -title About
    return
}
################################################################
#
# All the drawing and moving routines
#

# START HERE! banner
proc Draw0 {w} {
    set color $::C(0)
    set xy {699 119}
    $w.c create text $xy -text "START HERE!" -fill $color -anchor e \
	    -tag {I0 I0_0} -font {Times 12 italic bold}
    set xy {579 119}
    $w.c create text $xy -text "START HERE!" -fill $color -anchor w \
	    -tag I0 -font {{Times Roman} 12 italic bold}
    set xy {719 119 763 119}
    $w.c create line $xy -tag {I0 I0_1} -fill $color -width 3.75p -arrow last \
	    -arrowshape {13.5p 13.5p 3.75p}
    $w.c bind I0 <Button-1> Start
    $w.c create line $xy -tag I0 -fill $color -width 5 -arrow last \
	    -arrowshape {18 18 5}
    $w.c bind I0 <1> Start
}
proc Move0 {w {step {}}} {
    set step [GetStep 0 $step]

    if {$::S(mode) > $::MSTART} {		;# Start the ball rolling
	MoveAbs $w I0 {-100 -100}		;# Hide the banner
	return 2
    }

    set pos [scl {
	{719 119} {724 119} {729 119} {734 119}
	{739 119} {734 119} {729 119} {724 119}
    set pos {
	{673 119} {678 119} {683 119} {688 119}
	{693 119} {688 119} {683 119} {678 119}
    }]
    }
    set step [expr {$step % [llength $pos]}]
    lassign [lindex $pos $step] x y
    MoveAbs $w I0 [lindex $pos $step]
    $w.c coords I0_0 [expr {$x - [scl 20]}] $y
    $w.c coords I0_1 $x $y [expr {$x + [scl 44]}] $y
    return 1
}

# Dropping ball
proc Draw1 {w} {
    set color $::C(1a)
    set color2 $::C(1b)
    set xy {844 133 800 133 800 346 820 346 820 168 844 168 844 133}
    $w.c create poly $xy -width 2.25p -fill $color -outline {}
    $w.c create poly $xy -width 3 -fill $color -outline {}
    set xy {771 133 685 133 685 168 751 168 751 346 771 346 771 133}
    $w.c create poly $xy -width 2.25p -fill $color -outline {}
    $w.c create poly $xy -width 3 -fill $color -outline {}

    set xy [box 812 122 9]
    $w.c create oval $xy -tag I1 -fill $color2 -outline {}
    $w.c bind I1 <Button-1> Start
    $w.c bind I1 <1> Start
}
proc Move1 {w {step {}}} {
    set step [GetStep 1 $step]
    set pos [scl {
    set pos {
	{807 122} {802 122} {797 123} {793 124} {789 129} {785 153}
	{785 203} {785 278 x} {785 367} {810 392} {816 438} {821 503}
	{824 585 y} {838 587} {848 593} {857 601} {-100 -100}
    }]
    }
    if {$step >= [llength $pos]} {
	return 0
    }
    set where [lindex $pos $step]
    MoveAbs $w I1 $where

    if {[lindex $where 2] eq "y"} {
469
470
471
472
473
474
475
476
477









478
479

480
481

482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504



505
506
507

508
509
510
511
512
513
514
399
400
401
402
403
404
405


406
407
408
409
410
411
412
413
414
415

416
417

418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437




438
439
440
441
442

443
444
445
446
447
448
449
450







-
-
+
+
+
+
+
+
+
+
+

-
+

-
+

-
+














-
+


-
-
-
-
+
+
+


-
+







# Lighting the match
proc Draw2 {w} {
    set color red
    set color $::C(2)
    set xy  {750 369 740 392 760 392}		;# Fulcrum
    $w.c create poly $xy -fill $::C(fg) -outline $::C(fg)
    set xy {628 335 660 383}			;# Strike box
    $w.c create rect $xy -fill {} -outline $::C(fg) -tag StrikeBox

    $w.c create rect $xy -fill {} -outline $::C(fg)
    for {set y 0} {$y < 3} {incr y} {
	set yy [expr {335+$y*16}]
	$w.c create bitmap 628 $yy -bitmap gray25 -anchor nw \
		-foreground $::C(fg)
	$w.c create bitmap 644 $yy -bitmap gray25 -anchor nw \
		-foreground $::C(fg)
    }

    set xy {702 366 798 366}			;# Lever
    $w.c create line $xy -fill $::C(fg) -width 5.25p -tag I2_0
    $w.c create line $xy -fill $::C(fg) -width 6 -tag I2_0
    set xy {712 363 712 355}			;# R strap
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I2_1
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I2_1
    set xy {705 363 705 355}			;# L strap
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I2_2
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I2_2
    set xy {679 356 679 360 717 360 717 356 679 356}	;# Match stick
    $w.c create line $xy -fill $::C(fg) -tag I2_3

    #set xy {662 352 680 365}			;# Match head
    set xy {
	671 352 677.4 353.9 680 358.5 677.4 363.1 671 365 664.6 363.1
	662 358.5 664.6 353.9
    }
    $w.c create poly $xy -fill $color -outline $color -tag I2_4
}
proc Move2 {w {step {}}} {
    set step [GetStep 2 $step]

    set stages {0 0 1 2 0 2 1 0 1 2 0 2 1}
    set xy(0) [scl {
    set xy(0) {
	686 333 692 323 682 316 674 309 671 295 668 307 662 318 662 328
	671 336
    }]
    set xy(1) [scl {
	687 331 698 322 703 295 680 320 668 297 663 311 661 327 671 335}]
    set xy(2) [scl {
    }
    set xy(1) {687 331 698 322 703 295 680 320 668 297 663 311 661 327 671 335}
    set xy(2) {
	686 331 704 322 688 300 678 283 678 283 674 298 666 309 660 324
	672 336
    }]
    }

    if {$step >= [llength $stages]} {
	$w.c delete I2
	return 0
    }

    if {$step == 0} {				;# Rotate the match
528
529
530
531
532
533
534
535

536
537
538
539
540

541
542

543
544

545
546

547
548

549
550

551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572

573
574
575
576
577
578
579
580
581





582
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604

605
606
607

608
609
610
611

612
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639

640
641
642
643
644
645

646
647

648
649

650
651

652
653
654
655
656

657
658
659
660
661

662
663
664
665
666
667
668
464
465
466
467
468
469
470

471
472
473
474
475

476
477

478
479

480
481

482
483

484
485

486
487

488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

505
506
507

508
509
510
511
512





513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539

540
541
542

543
544
545
546

547
548
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574

575
576
577
578
579
580

581
582

583
584

585
586

587
588
589
590
591

592
593
594
595
596

597
598
599
600
601
602
603
604







-
+




-
+

-
+

-
+

-
+

-
+

-
+

-
+
















-
+


-
+




-
-
-
-
-
+
+
+
+
+








-
+













-
+


-
+



-
+








-
+










-
+







-
+





-
+

-
+

-
+

-
+




-
+




-
+







proc Draw3 {w} {
    set color $::C(3a)
    set color2 $::C(3b)

    set xy {602 296 577 174 518 174}
    foreach {x y} $xy {				;# 3 Pulleys
	$w.c create oval [box $x $y 13] -fill $color -outline $::C(fg) \
		-width 2.25p
		-width 3
	$w.c create oval [box $x $y 2] -fill $::C(fg) -outline $::C(fg)
    }

    set xy {750 309 670 309}			;# Wall to flame
    $w.c create line $xy -tag I3_s -width 2.25p -fill $::C(fg) -smooth 1
    $w.c create line $xy -tag I3_s -width 3 -fill $::C(fg) -smooth 1
    set xy {670 309 650 309}			;# Flame to pulley 1
    $w.c create line $xy -tag I3_0 -width 2.25p -fill $::C(fg)
    $w.c create line $xy -tag I3_0 -width 3 -fill $::C(fg)
    set xy {650 309 600 309}			;# Flame to pulley 1
    $w.c create line $xy -tag I3_1 -width 2.25p -fill $::C(fg)
    $w.c create line $xy -tag I3_1 -width 3 -fill $::C(fg)
    set xy {589 296 589 235}			;# Pulley 1 half way to 2
    $w.c create line $xy -tag I3_2 -width 2.25p -fill $::C(fg)
    $w.c create line $xy -tag I3_2 -width 3 -fill $::C(fg)
    set xy {589 235 589 174}			;# Pulley 1 other half to 2
    $w.c create line $xy -width 2.25p -fill $::C(fg)
    $w.c create line $xy -width 3 -fill $::C(fg)
    set xy {577 161 518 161}			;# Across the top
    $w.c create line $xy -width 2.25p -fill $::C(fg)
    $w.c create line $xy -width 3 -fill $::C(fg)
    set xy {505 174 505 205}			;# Down to weight
    $w.c create line $xy -tag I3_w -width 2.25p -fill $::C(fg)
    $w.c create line $xy -tag I3_w -width 3 -fill $::C(fg)

    # Draw the weight as 2 circles, two rectangles and 1 rounded rectangle
    set xy {515 207 495 207}
    foreach {x1 y1 x2 y2} $xy {
	$w.c create oval [box $x1 $y1 6] -tag I3_ -fill $color2 \
		-outline $color2
	$w.c create oval [box $x2 $y2 6] -tag I3_ -fill $color2 \
		-outline $color2
	incr y1 -6; incr y2 6
	$w.c create rect $x1 $y1 $x2 $y2 -tag I3_ -fill $color2 \
		-outline $color2
    }
    set xy {492 220 518 263}
    set xy [RoundRect $w $xy 15]
    $w.c create poly $xy -smooth 1 -tag I3_ -fill $color2 -outline $color2
    set xy {500 217 511 217}
    $w.c create line $xy -tag I3_ -fill $color2 -width 7.5p
    $w.c create line $xy -tag I3_ -fill $color2 -width 10

    set xy {502 393 522 393 522 465}		;# Bottom weight target
    $w.c create line $xy -tag I3__ -fill $::C(fg) -join miter -width 7.5p
    $w.c create line $xy -tag I3__ -fill $::C(fg) -join miter -width 10
}
proc Move3 {w {step {}}} {
    set step [GetStep 3 $step]

    set pos [scl {{505 247} {505 297} {505 386.5} {505 386.5}}]
    set rope(0) [scl {750 309 729 301 711 324 690 300}]
    set rope(1) [scl {750 309 737 292 736 335 717 315 712 320}]
    set rope(2) [scl {750 309 737 309 740 343 736 351 725 340}]
    set rope(3) [scl {750 309 738 321 746 345 742 356}]
    set pos {{505 247} {505 297} {505 386.5} {505 386.5}}
    set rope(0) {750 309 729 301 711 324 690 300}
    set rope(1) {750 309 737 292 736 335 717 315 712 320}
    set rope(2) {750 309 737 309 740 343 736 351 725 340}
    set rope(3) {750 309 738 321 746 345 742 356}

    if {$step >= [llength $pos]} {
	return 0
    }

    $w.c delete "I3_$step"			;# Delete part of the rope
    MoveAbs $w I3_ [lindex $pos $step]		;# Move weight down
    $w.c coords I3_s $rope($step)		;# Flapping rope end
    $w.c coords I3_w [concat [scl {505 174}] [lindex $pos $step]]
    $w.c coords I3_w [concat 505 174 [lindex $pos $step]]
    if {$step == 2} {
	$w.c move I3__ 0 30
	return 2
    }
    return 1
}

# Cage and door
proc Draw4 {w} {
    set color $::C(4)
    lassign {527 356 611 464} x0 y0 x1 y1

    for {set y $y0} {$y <= $y1} {incr y 12} {	;# Horizontal bars
	$w.c create line $x0 $y $x1 $y -fill $color -width 0.75p
	$w.c create line $x0 $y $x1 $y -fill $color -width 1
    }
    for {set x $x0} {$x <= $x1} {incr x 12} {	;# Vertical bars
	$w.c create line $x $y0 $x $y1 -fill $color -width 0.75p
	$w.c create line $x $y0 $x $y1 -fill $color -width 1
    }

    set xy {518 464 518 428}			;# Swing gate
    $w.c create line $xy -tag I4 -fill $color -width 2.25p
    $w.c create line $xy -tag I4 -fill $color -width 3
}
proc Move4 {w {step {}}} {
    set step [GetStep 4 $step]

    set angles {-10 -20 -30 -30}
    if {$step >= [llength $angles]} {
	return 0
    }
    RotateItem $w I4 [scl 518] [scl 464] [lindex $angles $step]
    RotateItem $w I4 518 464 [lindex $angles $step]
    $w.c raise I4
    return [expr {$step == 3 ? 3 : 1}]
}

# Mouse
proc Draw5 {w} {
    set color $::C(5a)
    set color2 $::C(5b)
    set xy {377 248 410 248 410 465 518 465}	;# Mouse course
    lappend xy 518 428 451 428 451 212 377 212
    $w.c create poly $xy -fill $color2 -outline $::C(fg) -width 2.25p
    $w.c create poly $xy -fill $color2 -outline $::C(fg) -width 3

    set xy {
	534.5 445.5 541 440 552 436 560 436 569 440 574 446 575 452 574 454
	566 456 554 456 545 456 537 454 530 452
    }
    $w.c create poly $xy -tag {I5 I5_0} -fill $color
    set xy {573 452 592 458 601 460 613 456}	;# Tail
    $w.c create line $xy -tag {I5 I5_1} -fill $color -smooth 1 -width 2.25p
    $w.c create line $xy -tag {I5 I5_1} -fill $color -smooth 1 -width 3
    set xy [box 540 446 2]			;# Eye
    set xy {540 444 541 445 541 447 540 448 538 447 538 445}
    #.c create oval $xy -tag {I5 I5_2} -fill $::C(bg) -outline {}
    $w.c create poly $xy -tag {I5 I5_2} -fill $::C(bg) -outline {} -smooth 1
    set xy {538 454 535 461}			;# Front leg
    $w.c create line $xy -tag {I5 I5_3} -fill $color -width 1.5p
    $w.c create line $xy -tag {I5 I5_3} -fill $color -width 2
    set xy {566 455 569 462}			;# Back leg
    $w.c create line $xy -tag {I5 I5_4} -fill $color -width 1.5p
    $w.c create line $xy -tag {I5 I5_4} -fill $color -width 2
    set xy {544 455 545 460}			;# 2nd front leg
    $w.c create line $xy -tag {I5 I5_5} -fill $color -width 1.5p
    $w.c create line $xy -tag {I5 I5_5} -fill $color -width 2
    set xy {560 455 558 460}			;# 2nd back leg
    $w.c create line $xy -tag {I5 I5_6}	 -fill $color -width 1.5p
    $w.c create line $xy -tag {I5 I5_6}	 -fill $color -width 2
}
proc Move5 {w {step {}}} {
    set step [GetStep 5 $step]

    set pos [scl {
    set pos {
	{553 452} {533 452} {513 452} {493 452} {473 452}
	{463 442 30} {445.5 441.5 30} {425.5 434.5 30} {422 414} {422 394}
	{422 374} {422 354} {422 334} {422 314} {422 294}
	{422 274 -30} {422 260.5 -30 x} {422.5 248.5 -28} {425 237}
    }]
    }
    if {$step >= [llength $pos]} {
	return 0
    }

    lassign [lindex $pos $step] x y beta next
    MoveAbs $w I5 [list $x $y]
    if {$beta ne ""} {
691
692
693
694
695
696
697
698

699
700

701
702
703
704

705
706

707
708
709
710
711
712
713

714
715
716
717
718
719
720
721
722


723
724
725
726

727
728

729
730
731

732
733

734
735

736
737
738
739
740
741
742
743
744
745
746
747
748
749

750
751
752
753
754

755
756
757
758
759
760
761

762
763
764
765

766
767
768
769
770
771
772
773
774
775

776
777

778
779
780
781
782
783
784
785
786
787
788
789
790

791
792

793
794
795
796
797
798
799
800
801

802
803
804
805
806
807

808
809
810
811
812
813
814
815
816

817
818
819
820

821
822
823
824

825
826
827
828
829
830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845

846
847
848
849
850
851
852
627
628
629
630
631
632
633

634
635

636
637
638
639

640
641

642
643
644
645
646
647
648

649
650
651
652
653
654
655
656


657
658
659
660
661

662
663

664
665
666

667
668

669
670

671
672
673
674
675
676
677
678
679
680
681
682
683
684

685
686




687

688
689




690

691
692

693
694
695
696
697
698
699
700
701
702

703
704

705
706
707
708
709
710
711
712
713
714
715
716
717

718
719

720
721
722
723
724
725
726
727
728

729
730
731
732
733
734

735
736
737
738
739
740
741
742
743

744
745
746
747

748
749
750
751

752
753
754
755
756
757
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772

773
774
775
776
777
778
779
780







-
+

-
+



-
+

-
+






-
+







-
-
+
+



-
+

-
+


-
+

-
+

-
+













-
+

-
-
-
-
+
-


-
-
-
-
+
-


-
+









-
+

-
+












-
+

-
+








-
+





-
+








-
+



-
+



-
+













-
+






-
+







    13,12 {331 420} 13,13 {360 417} 13,14 {345 412} 13,15 {376 410}
    13,16 {360 403}
}
proc Draw6 {w} {
    set color $::C(6)
    set xy {324 130 391 204}			;# Ball holder
    set xy [RoundRect $w $xy 10]
    $w.c create poly $xy -smooth 1 -outline $::C(fg) -width 2.25p -fill $color
    $w.c create poly $xy -smooth 1 -outline $::C(fg) -width 3 -fill $color
    set xy {339 204 376 253}			;# Below the ball holder
    $w.c create rect $xy -fill {} -outline $::C(fg) -width 2.25p -fill $color \
    $w.c create rect $xy -fill {} -outline $::C(fg) -width 3 -fill $color \
	    -tag I6c
    set xy [box 346 339 28]
    $w.c create oval $xy -fill $color -outline {}	;# Rotor
    $w.c create arc $xy -outline $::C(fg) -width 1.5p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 2 -style arc \
	    -start 80 -extent 205
    $w.c create arc $xy -outline $::C(fg) -width 1.5p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 2 -style arc \
	    -start -41 -extent 85

    set xy [box 346 339 15]			;# Center of rotor
    $w.c create oval $xy -outline $::C(fg) -fill $::C(fg) -tag I6m
    set xy {352 312 352 254 368 254 368 322}	;# Top drop to rotor
    $w.c create poly $xy -fill $color -outline {}
    $w.c create line $xy -fill $::C(fg) -width 1.5p
    $w.c create line $xy -fill $::C(fg) -width 2

    set xy {353 240 367 300}			;# Poke bottom hole
    $w.c create rect $xy -fill $color -outline {}
    set xy {341 190 375 210}			;# Poke another hole
    $w.c create rect $xy -fill $color -outline {}

    set xy {368 356 368 403 389 403 389 464 320 464 320 403 352 403 352 366}
    $w.c create poly $xy -fill $color -outline {} -width 1.5p	;# Below rotor
    $w.c create line $xy -fill $::C(fg) -width 1.5p
    $w.c create poly $xy -fill $color -outline {} -width 2	;# Below rotor
    $w.c create line $xy -fill $::C(fg) -width 2
    set xy [box 275 342 7]			;# On/off rotor
    $w.c create oval $xy -outline $::C(fg) -fill $::C(fg)
    set xy {276 334 342 325}			;# Fan belt top
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3
    set xy {276 349 342 353}			;# Fan belt bottom
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3

    set xy {337 212 337 247}			;# What the mouse pushes
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I6_
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I6_
    set xy {392 212 392 247}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I6_
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I6_
    set xy {337 230 392 230}
    $w.c create line $xy -fill $::C(fg) -width 5.25p -tag I6_
    $w.c create line $xy -fill $::C(fg) -width 7 -tag I6_

    set who -1					;# All the balls
    set colors {red cyan orange green blue darkblue}
    lappend colors {*}$colors {*}$colors

    for {set i 0} {$i < 17} {incr i} {
	set loc [expr {-1 * $i}]
	set color [lindex $colors $i]
	$w.c create oval [box {*}$::XY6($loc) 5] -fill $color \
		-outline $color -tag I6_b$i
    }
    Draw6a $w 12				;# The wheel
}
proc Draw6a {w beta {scale 0}} {
proc Draw6a {w beta} {
    $w.c delete I6_0
    if {$scale} {
	lassign [scl {346 339}] Ox Oy
    } else {
	lassign {346 339} Ox Oy
    lassign {346 339} Ox Oy
    }
    for {set i 0} {$i < 4} {incr i} {
	set b [expr {$beta + $i * 45}]
	if {$scale} {
	    lassign [RotateC [scl 28] 0 0 0 $b] x y
	} else {
	    lassign [RotateC 28 0 0 0 $b] x y
	lassign [RotateC 28 0 0 0 $b] x y
	}
	set xy [list [expr {$Ox+$x}] [expr {$Oy+$y}] \
		[expr {$Ox-$x}] [expr {$Oy-$y}]]
	$w.c create line $xy -tag I6_0 -fill $::C(fg) -width 1.5p
	$w.c create line $xy -tag I6_0 -fill $::C(fg) -width 2
    }
}
proc Move6 {w {step {}}} {
    set step [GetStep 6 $step]
    if {$step > 62} {
	return 0
    }

    if {$step < 2} {				;# Open gate for balls to drop
	$w.c move I6_ -5.25p 0
	$w.c move I6_ -7 0
	if {$step == 1} {			;# Poke a hole
	    set xy [scl {348 226 365 240}]
	    set xy {348 226 365 240}
	    $w.c create rect $xy -fill [$w.c itemcget I6c -fill] -outline {}
	}
	return 1
    }

    set s [expr {$step - 1}]			;# Do the gumball drop dance
    for {set i 0} {$i <= int(($s-1) / 3)} {incr i} {
	set tag "I6_b$i"
	if {[$w.c find withtag $tag] eq ""} break
	set loc [expr {$s - 3 * $i}]

	if {[info exists ::XY6($loc,$i)]} {
	    MoveAbs $w $tag [scl $::XY6($loc,$i)]
	    MoveAbs $w $tag $::XY6($loc,$i)
	} elseif {[info exists ::XY6($loc)]} {
	    MoveAbs $w $tag [scl $::XY6($loc)]
	    MoveAbs $w $tag $::XY6($loc)
	}
    }
    if {($s % 3) == 1} {
	set first [expr {($s + 2) / 3}]
	for {set i $first} {1} {incr i} {
	    set tag "I6_b$i"
	    if {[$w.c find withtag $tag] eq ""} break
	    set loc [expr {$first - $i}]
	    MoveAbs $w $tag [scl $::XY6($loc)]
	    MoveAbs $w $tag $::XY6($loc)
	}
    }
    if {$s >= 3} {				;# Rotate the motor
	set idx [expr {$s % 3}]
	#Draw6a $w [lindex {12 35 64} $idx]
	Draw6a $w [expr {12 + $s * 15}] 1
	Draw6a $w [expr {12 + $s * 15}]
    }
    return [expr {$s == 3 ? 3 : 1}]
}

# On/off switch
proc Draw7 {w} {
    set color $::C(7)
    set xy {198 306 277 374}			;# Box
    $w.c create rect $xy -outline $::C(fg) -width 1.5p -fill $color -tag I7z
    $w.c create rect $xy -outline $::C(fg) -width 2 -fill $color -tag I7z
    $w.c lower I7z
    set xy {275 343 230 349}
    $w.c create line $xy -tag I7 -fill $::C(fg) -arrow last \
	    -arrowshape {17.25p 17.25p 6p} -width 4.5p
	    -arrowshape {23 23 8} -width 6
    set xy {225 324}				;# On button
    $w.c create oval [box {*}$xy 3] -fill $::C(fg) -outline $::C(fg)
    set xy {218 323}				;# On text
    set font {Times 8}
    set font {{Times Roman} 8}
    $w.c create text $xy -text "on" -anchor e -fill $::C(fg) -font $font
    set xy {225 350}				;# Off button
    $w.c create oval [box {*}$xy 3] -fill $::C(fg) -outline $::C(fg)
    set xy {218 349}				;# Off button
    $w.c create text $xy -text "off" -anchor e -fill $::C(fg) -font $font
}
proc Move7 {w {step {}}} {
    set step [GetStep 7 $step]
    set numsteps 30
    if {$step > $numsteps} {
	return 0
    }
    set beta [expr {30.0 / $numsteps}]
    RotateItem $w I7 [scl 275] [scl 343] $beta
    RotateItem $w I7 275 343 $beta

    return [expr {$step == $numsteps ? 3 : 1}]
}

# Electricity to the fan
proc Draw8 {w} {
    Sine $w 271 248 271 306 5 8 -tag I8_s -fill $::C(8) -width 2.25p
    Sine $w 271 248 271 306 5 8 -tag I8_s -fill $::C(8) -width 3
}
proc Move8 {w {step {}}} {
    set step [GetStep 8 $step]

    if {$step > 3} {
	return 0
    }
874
875
876
877
878
879
880
881

882
883

884
885

886
887

888
889
890
891
892
893
894


895
896
897
898


899
900
901
902
903
904
905
906
907
908
909
910
911
912

913
914
915
916

917
918
919

920
921

922
923
924
925

926
927

928
929

930
931
932

933
934
935
936
937
938

939
940
941

942
943
944

945
946
947
948

949
950
951
952

953
954
955
956
957
958
959
802
803
804
805
806
807
808

809
810

811
812

813
814

815
816
817
818
819
820


821
822
823
824


825
826
827
828
829
830
831
832
833
834
835
836
837
838
839

840
841
842
843

844
845
846

847
848

849
850
851
852

853
854

855
856

857
858
859

860
861
862
863
864
865

866
867
868

869
870
871

872
873
874
875

876
877
878
879

880
881
882
883
884
885
886
887







-
+

-
+

-
+

-
+





-
-
+
+


-
-
+
+













-
+



-
+


-
+

-
+



-
+

-
+

-
+


-
+





-
+


-
+


-
+



-
+



-
+







    set xy {288 249 252 249 260 240 280 234 296 234 316 240 324 249 288 249}
    $w.c create poly $xy -fill $color -smooth 1

    set xy {248 205 265 214 264 205 265 196}	;# Spinner
    $w.c create poly $xy -fill $color

    set xy {255 206 265 234}			;# Fan blades
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 2.25p -tag I9_0
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 3 -tag I9_0
    set xy {255 176 265 204}
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 2.25p -tag I9_0
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 3 -tag I9_0
    set xy {255 206 265 220}
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 0.75p -tag I9_1
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 1 -tag I9_1
    set xy {255 190 265 204}
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 0.75p -tag I9_1
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 1 -tag I9_1
}
proc Move9 {w {step {}}} {
    set step [GetStep 9 $step]

    if {$step & 1} {
	$w.c itemconfig I9_0 -width 3p
	$w.c itemconfig I9_1 -width 0.75p
	$w.c itemconfig I9_0 -width 4
	$w.c itemconfig I9_1 -width 1
	$w.c lower I9_1 I9_0
    } else {
	$w.c itemconfig I9_0 -width 0.75p
	$w.c itemconfig I9_1 -width 3p
	$w.c itemconfig I9_0 -width 1
	$w.c itemconfig I9_1 -width 4
	$w.c lower I9_0 I9_1
    }
    if {$step == 0} {
	return 3
    }
    return 1
}

# Boat
proc Draw10 {w} {
    set color $::C(10a)
    set color2 $::C(10b)
    set xy {191 230 233 230 233 178 191 178}	;# Sail
    $w.c create poly $xy -fill $color -width 2.25p -outline $::C(fg) -tag I10
    $w.c create poly $xy -fill $color -width 3 -outline $::C(fg) -tag I10
    set xy [box 209 204 31]			;# Front
    $w.c create arc $xy -outline {} -fill $color -style pie \
	    -start 120 -extent 120 -tag I10
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc \
	    -start 120 -extent 120 -tag I10
    set xy [box 249 204 31]			;# Back
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 2.25p -style pie \
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 3 -style pie \
	    -start 120 -extent 120 -tag I10
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc \
	    -start 120 -extent 120 -tag I10

    set xy {200 171 200 249}			;# Mast
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I10
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I10
    set xy {159 234 182 234}			;# Bow sprit
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I10
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I10
    set xy {180 234 180 251 220 251}		;# Hull
    $w.c create line $xy -fill $::C(fg) -width 4.5p -tag I10
    $w.c create line $xy -fill $::C(fg) -width 6 -tag I10

    set xy {92 255 221 255}			;# Waves
    Sine $w {*}$xy 2 25 -fill $color2 -width 0.75p -tag I10w
    Sine $w {*}$xy 2 25 -fill $color2 -width 1 -tag I10w

    set xy [lrange [$w.c coords I10w] 4 end-4]	;# Water
    set xy [concat $xy 222 266 222 277 99 277]
    $w.c create poly $xy -fill $color2 -outline $color2
    set xy {222 266 222 277 97 277 97 266}	;# Water bottom
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3

    set xy [box 239 262 17]
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc \
	    -start 95 -extent 103
    set xy [box 76 266 21]
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc -extent 190
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc -extent 190
}
proc Move10 {w {step {}}} {
    set step [GetStep 10 $step]
    set pos [scl {
    set pos {
	{195 212} {193 212} {190 212} {186 212} {181 212} {176 212}
	{171 212} {166 212} {161 212} {156 212} {151 212} {147 212} {142 212}
	{137 212} {132 212 x} {127 212} {121 212} {116 212} {111 212}
    }]
    }

    if {$step >= [llength $pos]} {
	return 0
    }
    set where [lindex $pos $step]
    MoveAbs $w I10 $where

969
970
971
972
973
974
975
976

977
978

979
980

981
982
983
984


985
986
987

988
989

990
991
992

993
994
995
996

997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
897
898
899
900
901
902
903

904
905

906
907

908
909
910


911
912
913
914

915
916

917
918
919

920
921
922
923

924
925
926
927

928
929
930
931
932
933
934
935







-
+

-
+

-
+


-
-
+
+


-
+

-
+


-
+



-
+



-
+







    set color2 $::C(11b)
    set xy {23 264 55 591}			;# Color the down tube
    $w.c create rect $xy -fill $color -outline {}
    set xy [box 71 460 48]			;# Color the outer loop
    $w.c create oval $xy -fill $color -outline {}

    set xy {55 264 55 458}			;# Top right side
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3
    set xy {55 504 55 591}			;# Bottom right side
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3
    set xy [box 71 460 48]			;# Outer loop
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc \
	    -start 110 -extent -290 -tag I11i
    set xy [box 71 460 16]			;# Inner loop
    $w.c create oval $xy -outline $::C(fg) -fill {} -width 2.25p -tag I11i
    $w.c create oval $xy -outline $::C(fg) -fill $::C(bg) -width 2.25p
    $w.c create oval $xy -outline $::C(fg) -fill {} -width 3 -tag I11i
    $w.c create oval $xy -outline $::C(fg) -fill $::C(bg) -width 3

    set xy {23 264 23 591}			;# Left side
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3
    set xy [box 1 266 23]			;# Top left curve
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc -extent 90
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc -extent 90

    set xy [box 75 235 9]			;# The ball
    $w.c create oval $xy -fill $color2 -outline {} -width 2.25p -tag I11
    $w.c create oval $xy -fill $color2 -outline {} -width 3 -tag I11
}
proc Move11 {w {step {}}} {
    set step [GetStep 11 $step]
    set pos [scl {
    set pos {
	{75 235} {70 235} {65 237} {56 240} {46 247} {38 266} {38 296}
	{38 333} {38 399} {38 475} {74 496} {105 472} {100 437} {65 423}
	{-100 -100} {38 505} {38 527 x} {38 591}
    }]
    }

    if {$step >= [llength $pos]} {
	return 0
    }
    set where [lindex $pos $step]
    MoveAbs $w I11 $where
    if {[lindex $where 2] eq "x"} {
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031

1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052


1053
1054
1055

1056
1057
1058

1059
1060
1061
1062


1063
1064


1065
1066
1067

1068
1069

1070
1071

1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100

1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

1128
1129
1130
1131
1132
1133
1134
948
949
950
951
952
953
954

955
956
957
958

959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978


979
980
981
982

983
984
985

986
987
988
989

990
991
992

993
994
995
996

997
998

999
1000

1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027

1028
1029

1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1064







-
+



-
+



















-
-
+
+


-
+


-
+



-
+
+

-
+
+


-
+

-
+

-
+







-
+


















-
+

-
+





-
+






-
+













-
+







    set y1 645
    for {set x 50} {$x > 20} {incr x -10} {
	set x1 [expr {$x - 5}]
	set x2 [expr {$x - 10}]
	lappend xy $x $y0 $x1 $y1 $x2 $y0
    }
    $w.c create poly $xy -fill $::C(12) -outline $::C(fg) -smooth 1 -tag I12 \
	    -width 2.25p
	    -width 3
}
proc Move12 {w {step {}}} {
    set step [GetStep 12 $step]
    set pos [scl {{42 641 x}}]
    set pos {{42.5 641 x}}
    if {$step >= [llength $pos]} {
	return 0
    }

    set where [lindex $pos $step]
    MoveAbs $w I12 $where
    if {[lindex $where 2] eq "x"} {
	return 3
    }
    return 1
}

# Fax
proc Draw13 {w} {
    set color $::C(13a)
    set xy {86 663 149 663 149 704 50 704 50 681 64 681 86 671}
    set xy2 {784 663 721 663 721 704 820 704 820 681 806 681 784 671}
    set radii {2 9 9 8 5 5 2}

    RoundPoly $w.c $xy $radii -width 2.25p -outline $::C(fg) -fill $color
    RoundPoly $w.c $xy2 $radii -width 2.25p -outline $::C(fg) -fill $color
    RoundPoly $w.c $xy $radii -width 3 -outline $::C(fg) -fill $color
    RoundPoly $w.c $xy2 $radii -width 3 -outline $::C(fg) -fill $color

    set xy {56 677}
    $w.c create rect [box {*}$xy 4] -fill {} -outline $::C(fg) -width 2.25p \
    $w.c create rect [box {*}$xy 4] -fill {} -outline $::C(fg) -width 3 \
	    -tag I13
    set xy {809 677}
    $w.c create rect [box {*}$xy 4] -fill {} -outline $::C(fg) -width 2.25p \
    $w.c create rect [box {*}$xy 4] -fill {} -outline $::C(fg) -width 3 \
	    -tag I13R

    set xy {112 687}				;# Label
    $w.c create text $xy -text "FAX" -fill $::C(fg) -font {Times 12 bold}
    $w.c create text $xy -text "FAX" -fill $::C(fg) \
	    -font {{Times Roman} 12 bold}
    set xy {762 687}
    $w.c create text $xy -text "FAX" -fill $::C(fg) -font {Times 12 bold}
    $w.c create text $xy -text "FAX" -fill $::C(fg) \
	    -font {{Times Roman} 12 bold}

    set xy {138 663 148 636 178 636}		;# Paper guide
    $w.c create line $xy -smooth 1 -fill $::C(fg) -width 2.25p
    $w.c create line $xy -smooth 1 -fill $::C(fg) -width 3
    set xy {732 663 722 636 692 636}
    $w.c create line $xy -smooth 1 -fill $::C(fg) -width 2.25p
    $w.c create line $xy -smooth 1 -fill $::C(fg) -width 3

    Sine $w 149 688 720 688 5 15 -tag I13_s -fill $::C(fg) -width 2.25p
    Sine $w 149 688 720 688 5 15 -tag I13_s -fill $::C(fg) -width 3
}
proc Move13 {w {step {}}} {
    set step [GetStep 13 $step]
    set numsteps 7

    if {$step == $numsteps+2} {
	MoveAbs $w I13_star {-100 -100}
	$w.c itemconfig I13R -fill $::C(13b) -width 1.5p
	$w.c itemconfig I13R -fill $::C(13b) -width 2
	return 2
    }
    if {$step == 0} {				;# Button down
	$w.c delete I13
	Sparkle $w {-100 -100} I13_star		;# Create off screen
	return 1
    }
    lassign [Anchor $w I13_s w] x0 y0
    lassign [Anchor $w I13_s e] x1 y1
    set x [expr {$x0 + ($x1-$x0) * ($step - 1) / double($numsteps)}]
    MoveAbs $w I13_star [list $x $y0]
    return 1
}

# Paper in fax
proc Draw14 {w} {
    set color $::C(14)
    set xy {102 661 113 632 130 618}		;# Left paper edge
    $w.c create line $xy -smooth 1 -fill $color -width 2.25p -tag I14L_0
    $w.c create line $xy -smooth 1 -fill $color -width 3 -tag I14L_0
    set xy {148 629 125 640 124 662}		;# Right paper edge
    $w.c create line $xy -smooth 1 -fill $color -width 2.25p -tag I14L_1
    $w.c create line $xy -smooth 1 -fill $color -width 3 -tag I14L_1
    Draw14a $w L

    set xy {
	768.0 662.5 767.991316225 662.433786215 767.926187912 662.396880171
    }
    $w.c create line $xy -smooth 1 -fill $color -width 2.25p -tag I14R_0
    $w.c create line $xy -smooth 1 -fill $color -width 3 -tag I14R_0
    $w.c lower I14R_0
    # NB. these numbers are VERY sensitive, you must start with final size
    # and shrink down to get the values
    set xy {
	745.947897349 662.428358855 745.997829056 662.452239237 746.0 662.5
    }
    $w.c create line $xy -smooth 1 -fill $color -width 2.25p -tag I14R_1
    $w.c create line $xy -smooth 1 -fill $color -width 3 -tag I14R_1
    $w.c lower I14R_1
}
proc Draw14a {w side} {
    set color $::C(14)
    set xy [$w.c coords I14${side}_0]
    set xy2 [$w.c coords I14${side}_1]
    lassign $xy x0 y0 x1 y1 x2 y2
    lassign $xy2 x3 y3 x4 y4 x5 y5
    set zz [concat \
	    $x0 $y0 $x0 $y0 $xy $x2 $y2 $x2 $y2 \
	    $x3 $y3 $x3 $y3 $xy2 $x5 $y5 $x5 $y5]
    $w.c delete I14$side
    $w.c create poly $zz -tag I14$side -smooth 1 -fill $color -outline $color \
	    -width 2.25p
	    -width 3
    $w.c lower I14$side
}
proc Move14 {w {step {}}} {
    set step [GetStep 14 $step]

    # Paper going down
    set sc [expr {.9 - .05*$step}]
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165

1166
1167

1168
1169

1170
1171
1172

1173
1174

1175
1176

1177
1178

1179
1180
1181
1182
1183
1184



1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213

1214
1215
1216
1217
1218

1219
1220
1221
1222
1223
1224
1225
1226

1227
1228
1229

1230
1231
1232

1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247

1248
1249
1250

1251
1252
1253
1254

1255
1256

1257
1258
1259

1260
1261

1262
1263
1264
1265


1266
1267

1268
1269

1270
1271

1272
1273
1274

1275
1276

1277
1278

1279
1280
1281

1282
1283

1284
1285

1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297






1298
1299
1300
1301
1302
1303





1304
1305

1306
1307
1308
1309

1310
1311
1312
1313
1314
1315
1316
1317







1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336

1337
1338

1339
1340
1341
1342
1343

1344
1345
1346
1347
1348
1349




1350
1351
1352
1353
1354



1355
1356
1357
1358
1359
1360
1361
1086
1087
1088
1089
1090
1091
1092

1093
1094

1095
1096

1097
1098

1099
1100
1101

1102
1103

1104
1105

1106
1107

1108
1109
1110
1111



1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142

1143
1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158

1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176

1177
1178
1179

1180
1181
1182
1183

1184
1185

1186
1187
1188

1189
1190

1191
1192
1193


1194
1195
1196

1197
1198

1199
1200

1201
1202
1203

1204
1205

1206
1207

1208
1209
1210

1211
1212

1213
1214

1215
1216
1217
1218
1219
1220
1221






1222
1223
1224
1225
1226
1227
1228





1229
1230
1231
1232
1233
1234

1235
1236
1237
1238

1239
1240







1241
1242
1243
1244
1245
1246
1247
1248
1249

1250
1251
1252
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265

1266
1267

1268
1269
1270
1271
1272

1273
1274
1275




1276
1277
1278
1279
1280
1281



1282
1283
1284
1285
1286
1287
1288
1289
1290
1291







-
+

-
+

-
+

-
+


-
+

-
+

-
+

-
+



-
-
-
+
+
+











-
+














-
+

-
+




-
+







-
+


-
+


-
+












-
+

-
+


-
+



-
+

-
+


-
+

-
+


-
-
+
+

-
+

-
+

-
+


-
+

-
+

-
+


-
+

-
+

-
+






-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+



-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
+









-
+





-
+

-
+




-
+


-
-
-
-
+
+
+
+


-
-
-
+
+
+







    return [expr {$step == 10 ? 3 : 1}]
}

# Light beam
proc Draw15 {w} {
    set color $::C(15a)
    set xy {824 599 824 585 820 585 829 585}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I15a
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I15a
    set xy {789 599 836 643}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 3
    set xy {778 610 788 632}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 3
    set xy {766 617 776 625}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 3

    set xy {633 600 681 640}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 3
    set xy {635 567 657 599}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2
    set xy {765 557 784 583}
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 2

    Sine $w 658 580 765 580 3 15 -tag I15_s -fill $::C(fg) -width 2.25p
    Sine $w 658 580 765 580 3 15 -tag I15_s -fill $::C(fg) -width 3
}
proc Move15a {w} {
    set color $::C(15b)
    $w.c scale I15a [scl 824] [scl 599] 1 .3		;# Button down
    set xy [scl {765 621 681 621}]
    $w.c create line $xy -dash "-" -width 2.25p -fill $color -tag I15
    $w.c scale I15a 824 599 1 .3		;# Button down
    set xy {765 621 681 621}
    $w.c create line $xy -dash "-" -width 3 -fill $color -tag I15
}
proc Move15 {w {step {}}} {
    set step [GetStep 15 $step]
    set numsteps 6

    if {$step == $numsteps+2} {
	MoveAbs $w I15_star {-100 -100}
	return 2
    }
    if {$step == 0} {				;# Break the light beam
	Sparkle $w {-100 -100} I15_star
	set xy [scl {765 621 745 621}]
	set xy {765 621 745 621}
	$w.c coords I15 $xy
	return 1
    }
    lassign [Anchor $w I15_s w] x0 y0
    lassign [Anchor $w I15_s e] x1 y1
    set x [expr {$x0 + ($x1-$x0) * ($step - 1) / double($numsteps)}]
    MoveAbs $w I15_star [list $x $y0]
    return 1
}

# Bell
proc Draw16 {w} {
    set color $::C(16)
    set xy {722 485 791 556}
    $w.c create rect $xy -fill {} -outline $::C(fg) -width 2.25p
    $w.c create rect $xy -fill {} -outline $::C(fg) -width 3
    set xy [box 752 515 25]			;# Bell
    $w.c create oval $xy -fill $color -outline black -tag I16b -width 1.5p
    $w.c create oval $xy -fill $color -outline black -tag I16b -width 2
    set xy [box 752 515 5]			;# Bell button
    $w.c create oval $xy -fill black -outline black -tag I16b

    set xy {784 523 764 549}			;# Clapper
    $w.c create line $xy -width 2.25p -tag I16c -fill $::C(fg)
    $w.c create line $xy -width 3 -tag I16c -fill $::C(fg)
    set xy [box 784 523 4]
    $w.c create oval $xy -fill $::C(fg) -outline $::C(fg) -tag I16d
}
proc Move16 {w {step {}}} {
    set step [GetStep 16 $step]

    # Note: we never stop
    lassign [scl {760 553}] Ox Oy
    lassign {760 553} Ox Oy
    if {$step & 1} {
	set beta 12
	$w.c move I16b 2.25p 0
	$w.c move I16b 3 0
    } else {
	set beta -12
	$w.c move I16b -2.25p 0
	$w.c move I16b -3 0
    }
    RotateItem $w I16c $Ox $Oy $beta
    RotateItem $w I16d $Ox $Oy $beta

    return [expr {$step == 1 ? 3 : 1}]
}

# Cat
proc Draw17 {w} {
    set color $::C(17)

    set xy {584 556 722 556}
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3
    set xy {584 485 722 485}
    $w.c create line $xy -fill $::C(fg) -width 2.25p
    $w.c create line $xy -fill $::C(fg) -width 3

    set xy {664 523 717 549}			;# Body
    $w.c create arc $xy -outline $::C(fg) -fill $color -width 2.25p \
    $w.c create arc $xy -outline $::C(fg) -fill $color -width 3 \
	    -style chord -start 128 -extent -260 -tag I17

    set xy {709 554 690 543}			;# Paw
    $w.c create oval $xy -outline $::C(fg) -fill $color -width 2.25p -tag I17
    $w.c create oval $xy -outline $::C(fg) -fill $color -width 3 -tag I17
    set xy {657 544 676 555}
    $w.c create oval $xy -outline $::C(fg) -fill $color -width 2.25p -tag I17
    $w.c create oval $xy -outline $::C(fg) -fill $color -width 3 -tag I17

    set xy [box 660 535 15]			;# Lower face
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 3 -style arc \
	    -start 150 -extent 240 -tag I17_
    $w.c create arc $xy -outline {} -fill $color -width 0.75p -style chord \
    $w.c create arc $xy -outline {} -fill $color -width 1 -style chord \
	    -start 150 -extent 240 -tag I17_
    set xy {674 529 670 513 662 521 658 521 650 513 647 529}	;# Ears
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
    $w.c create poly $xy -fill $color -outline {} -width 0.75p -tag {I17_ I17_c}
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
    $w.c create poly $xy -fill $color -outline {} -width 1 -tag {I17_ I17_c}
    set xy {652 542 628 539}			;# Whiskers
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
    set xy {652 543 632 545}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
    set xy {652 546 632 552}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I17_

    set xy {668 543 687 538}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag {I17_ I17w}
    $w.c create line $xy -fill $::C(fg) -width 3 -tag {I17_ I17w}
    set xy {668 544 688 546}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag {I17_ I17w}
    $w.c create line $xy -fill $::C(fg) -width 3 -tag {I17_ I17w}
    set xy {668 547 688 553}
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag {I17_ I17w}
    $w.c create line $xy -fill $::C(fg) -width 3 -tag {I17_ I17w}

    set xy {649 530 654 538 659 530}		;# Left eye
    $w.c create line $xy -fill $::C(fg) -width 1.5p -smooth 1 -tag I17
    $w.c create line $xy -fill $::C(fg) -width 2 -smooth 1 -tag I17
    set xy {671 530 666 538 661 530}		;# Right eye
    $w.c create line $xy -fill $::C(fg) -width 1.5p -smooth 1 -tag I17
    $w.c create line $xy -fill $::C(fg) -width 2 -smooth 1 -tag I17
    set xy {655 543 660 551 665 543}		;# Mouth
    $w.c create line $xy -fill $::C(fg) -width 1.5p -smooth 1 -tag I17
    $w.c create line $xy -fill $::C(fg) -width 2 -smooth 1 -tag I17
}
proc Move17 {w {step {}}} {
    set step [GetStep 17 $step]

    if {$step == 0} {
	$w.c delete I17				;# Delete most of the cat
	set xy [scl {655 543 660 535 665 543}]	;# Mouth
	$w.c create line $xy -fill $::C(fg) -width 2.25p -smooth 1 -tag I17_
	set xy [box [scl 654] [scl 530] [scl 4]]	;# Left eye
	$w.c create oval $xy -outline $::C(fg) -width 2.25p -fill {} -tag I17_
	set xy [box [scl 666] [scl 530] [scl 4]]	;# Right eye
	$w.c create oval $xy -outline $::C(fg) -width 2.25p -fill {} -tag I17_
	set xy {655 543 660 535 665 543}	;# Mouth
	$w.c create line $xy -fill $::C(fg) -width 3 -smooth 1 -tag I17_
	set xy [box 654 530 4]			;# Left eye
	$w.c create oval $xy -outline $::C(fg) -width 3 -fill {} -tag I17_
	set xy [box 666 530 4]			;# Right eye
	$w.c create oval $xy -outline $::C(fg) -width 3 -fill {} -tag I17_

	$w.c move I17_ 0 -15p			;# Move face up
	set xy [scl {652 528 652 554}]		;# Front leg
	$w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
	set xy [scl {670 528 670 554}]		;# 2nd front leg
	$w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
	$w.c move I17_ 0 -20			;# Move face up
	set xy {652 528 652 554}		;# Front leg
	$w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
	set xy {670 528 670 554}		;# 2nd front leg
	$w.c create line $xy -fill $::C(fg) -width 3 -tag I17_

	set xy [scl {
	set xy {
	    675 506 694 489 715 513 715 513 715 513 716 525 716 525 716 525
	    706 530 695 530 679 535 668 527 668 527 668 527 675 522 676 517
	    677 512
	}]					;# Body
	}					;# Body
	$w.c create poly $xy -fill [$w.c itemcget I17_c -fill] \
		-outline $::C(fg) -width 2.25p -smooth 1 -tag I17_
	set xy [scl {716 514 716 554}]		;# Back leg
	$w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
	set xy [scl {694 532 694 554}]		;# 2nd back leg
	$w.c create line $xy -fill $::C(fg) -width 2.25p -tag I17_
	set xy [scl {715 514 718 506 719 495 716 488}]	;# Tail
	$w.c create line $xy -fill $::C(fg) -width 2.25p -smooth 1 -tag I17_
		-outline $::C(fg) -width 3 -smooth 1 -tag I17_
	set xy {716 514 716 554}		;# Back leg
	$w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
	set xy {694 532 694 554}		;# 2nd back leg
	$w.c create line $xy -fill $::C(fg) -width 3 -tag I17_
	set xy {715 514 718 506 719 495 716 488};# Tail
	$w.c create line $xy -fill $::C(fg) -width 3 -smooth 1 -tag I17_

	$w.c raise I17w				;# Make whiskers visible
	$w.c move I17_ -3.75p 0			;# Move away from wall a bit
	$w.c move I17_ -5 0			;# Move away from wall a bit
	return 2
    }
    return 0
}

# Sling shot
proc Draw18 {w} {
    set color $::C(18)
    set xy {721 506 627 506}			;# Sling hold
    $w.c create line $xy -width 3p -fill $::C(fg) -tag I18
    $w.c create line $xy -width 4 -fill $::C(fg) -tag I18

    set xy {607 500 628 513}			;# Sling rock
    $w.c create oval $xy -fill $color -outline {} -tag I18a

    set xy {526 513 606 507 494 502}		;# Sling band
    $w.c create line $xy -fill $::C(fg) -width 3p -tag I18b
    $w.c create line $xy -fill $::C(fg) -width 4 -tag I18b
    set xy { 485 490 510 540 510 575 510 540 535 491 }	;# Sling
    $w.c create line $xy -fill $::C(fg) -width 4.5p
    $w.c create line $xy -fill $::C(fg) -width 6
}
proc Move18 {w {step {}}} {
    set step [GetStep 18 $step]

    set pos [scl {
    set pos {
	{587 506} {537 506} {466 506} {376 506} {266 506 x} {136 506}
	{16 506} {-100 -100}
    }]

    set b(0) [scl {490 502 719 507 524 512}]		;# Band collapsing
    set b(1) [scl {
    }

    set b(0) {490 502 719 507 524 512}		;# Band collapsing
    set b(1) {
	491 503 524 557 563 505 559 496 546 506 551 525 553 536 538 534
	532 519 529 499
    }]
    set b(2) [scl {491 503 508 563 542 533 551 526 561 539 549 550 530 500}]
    set b(3) [scl {491 503 508 563 530 554 541 562 525 568 519 544 530 501}]
    }
    set b(2) {491 503 508 563 542 533 551 526 561 539 549 550 530 500}
    set b(3) {491 503 508 563 530 554 541 562 525 568 519 544 530 501}

    if {$step >= [llength $pos]} {
	return 0
    }

    if {$step == 0} {
	$w.c delete I18
1375
1376
1377
1378
1379
1380
1381
1382
1383


1384
1385
1386
1387
1388
1389

1390
1391

1392
1393
1394
1395

1396
1397
1398

1399
1400

1401
1402
1403
1404
1405

1406
1407
1408

1409
1410

1411
1412
1413

1414
1415

1416
1417
1418

1419
1420

1421
1422
1423

1424
1425

1426
1427
1428
1429

1430
1431

1432
1433

1434
1435

1436
1437

1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462

1463
1464

1465
1466
1467

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487



1488
1489

1490
1491
1492


1493
1494
1495
1496
1497
1498
1499

1500
1501

1502
1503
1504
1505
1506
1507
1508


1509
1510
1511
1512


1513
1514

1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527

1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1305
1306
1307
1308
1309
1310
1311


1312
1313
1314
1315
1316
1317
1318

1319
1320

1321
1322
1323
1324

1325
1326
1327

1328
1329

1330
1331
1332
1333
1334

1335
1336
1337

1338
1339

1340
1341
1342

1343
1344

1345
1346
1347

1348
1349

1350
1351
1352

1353
1354

1355
1356
1357
1358

1359
1360

1361
1362

1363
1364

1365
1366

1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391

1392
1393

1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414



1415
1416
1417
1418

1419
1420


1421
1422
1423
1424
1425
1426
1427
1428

1429
1430

1431
1432
1433
1434
1435
1436


1437
1438
1439
1440


1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1467







-
-
+
+





-
+

-
+



-
+


-
+

-
+




-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+



-
+

-
+

-
+

-
+

-
+




-
+



















-
+

-
+


-
+

















-
-
-
+
+
+

-
+

-
-
+
+






-
+

-
+





-
-
+
+


-
-
+
+

-
+












-
+


-
+








# Water pipe
proc Draw19 {w} {
    set color $::C(19)
    set xx {249 181 155 118  86 55 22 0}
    foreach {x1 x2} $xx {
	$w.c create rect $x1 453 $x2 467 -fill $color -outline {} -tag I19
	$w.c create line $x1 453 $x2 453 -fill $::C(fg) -width 0.75p;# Pipe top
	$w.c create line $x1 467 $x2 467 -fill $::C(fg) -width 0.75p;# Pipe btm
	$w.c create line $x1 453 $x2 453 -fill $::C(fg) -width 1;# Pipe top
	$w.c create line $x1 467 $x2 467 -fill $::C(fg) -width 1;# Pipe bottom
    }
    $w.c raise I11i

    set xy [box 168 460 16]			;# Bulge by the joint
    $w.c create oval $xy -fill $color -outline {}
    $w.c create arc $xy -outline $::C(fg) -width 0.75p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 1 -style arc \
	    -start 21 -extent 136
    $w.c create arc $xy -outline $::C(fg) -width 0.75p -style arc \
    $w.c create arc $xy -outline $::C(fg) -width 1 -style arc \
	    -start -21 -extent -130

    set xy {249 447 255 473}			;# First joint 26x6
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1

    set xy [box 257 433 34]			;# Bend up
    $w.c create arc $xy -outline {} -fill $color -width 0.75p \
    $w.c create arc $xy -outline {} -fill $color -width 1 \
	    -style pie -start 0 -extent -91
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 0 -extent -90
    set xy [box 257 433 20]
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 1 \
	    -style pie -start 0 -extent -92
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 0 -extent -90
    set xy [box 257 421 34]			;# Bend left
    $w.c create arc $xy -outline {} -fill $color -width 0.75p \
    $w.c create arc $xy -outline {} -fill $color -width 1 \
	    -style pie -start 1 -extent 91
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 0 -extent 90
    set xy [box 257 421 20]
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 0.75p \
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 1 \
	    -style pie -start 0 -extent 90
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 0 -extent 90
    set xy [box 243 421 34]			;# Bend down
    $w.c create arc $xy -outline {} -fill $color -width 0.75p \
    $w.c create arc $xy -outline {} -fill $color -width 1 \
	    -style pie -start 90 -extent 90
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 90 -extent 90
    set xy [box 243 421 20]
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 0.75p \
    $w.c create arc $xy -outline {} -fill $::C(bg) -width 1 \
	    -style pie -start 90 -extent 90
    $w.c create arc $xy -outline $::C(fg) -width 0.75p \
    $w.c create arc $xy -outline $::C(fg) -width 1 \
	    -style arc -start 90 -extent 90

    set xy {270 427 296 433}			;# 2nd joint bottom
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1
    set xy {270 421 296 427}			;# 2nd joint top
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1
    set xy {249 382 255 408}			;# Third joint right
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1
    set xy {243 382 249 408}			;# Third joint left
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1
    set xy {203 420 229 426}			;# Last joint
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 0.75p
    $w.c create rect $xy -fill $color -outline $::C(fg) -width 1

    set xy [box 168 460 6]			;# Handle joint
    $w.c create oval $xy -fill $::C(fg) -outline {} -tag I19a
    set xy {168 460 168 512}			;# Handle bar
    $w.c create line $xy -fill $::C(fg) -width 3.75p -tag I19b
    $w.c create line $xy -fill $::C(fg) -width 5 -tag I19b
}
proc Move19 {w {step {}}} {
    set step [GetStep 19 $step]

    set angles {30 30 30}
    if {$step == [llength $angles]} {
	return 2
    }

    RotateItem $w I19b {*}[Centroid $w I19a] [lindex $angles $step]
    return 1
}

# Water pouring
proc Draw20 {w} {
}
proc Move20 {w {step {}}} {
    set step [GetStep 20 $step]

    set pos [scl {451 462 473 484 496 504 513 523 532}]
    set pos {451 462 473 484 496 504 513 523 532}
    set freq {20 40   40  40  40  40  40  40  40}
    set pos [scl {
    set pos {
	{451 20} {462 40} {473 40} {484 40} {496 40} {504 40} {513 40}
	{523 40} {532 40 x}
    }]
    }
    if {$step >= [llength $pos]} {
	return 0
    }

    $w.c delete I20
    set where [lindex $pos $step]
    lassign $where y f
    H2O $w $y $f
    if {[lindex $where 2] eq "x"} {
	return 3
    }
    return 1
}
proc H2O {w y f} {
    set color $::C(20)
    $w.c delete I20

    Sine $w [scl 208] [scl 428] [scl 208] $y 4 $f -tag {I20 I20s} \
	    -width 2.25p -fill $color -smooth 1
    $w.c create line [$w.c coords I20s] -width 2.25p -fill $color -smooth 1 \
    Sine $w 208 428 208 $y 4 $f -tag {I20 I20s} -width 3 -fill $color \
	    -smooth 1
    $w.c create line [$w.c coords I20s] -width 3 -fill $color -smooth 1 \
	    -tag {I20 I20a}
    $w.c create line [$w.c coords I20s] -width 2.25p -fill $color -smooth 1 \
    $w.c create line [$w.c coords I20s] -width 3 -fill $color -smooth 1 \
	    -tag {I20 I20b}
    $w.c move I20a 6p 0
    $w.c move I20b 12p 0
    $w.c move I20a 8 0
    $w.c move I20b 16 0
}

# Bucket
proc Draw21 {w} {
    set color $::C(21)
    set xy {217 451 244 490}			;# Right handle
    $w.c create line $xy -fill $::C(fg) -width 1.5p -tag I21_a
    $w.c create line $xy -fill $::C(fg) -width 2 -tag I21_a
    set xy {201 467 182 490}			;# Left handle
    $w.c create line $xy -fill $::C(fg) -width 1.5p -tag I21_a
    $w.c create line $xy -fill $::C(fg) -width 2 -tag I21_a

    set xy {245 490 237 535}			;# Right side
    set xy2 {189 535 181 490}			;# Left side
    $w.c create poly [concat $xy $xy2] -fill $color -outline {} \
	    -tag {I21 I21f}
    $w.c create line $xy -fill $::C(fg) -width 1.5p -tag I21
    $w.c create line $xy2 -fill $::C(fg) -width 1.5p -tag I21
    $w.c create line $xy -fill $::C(fg) -width 2 -tag I21
    $w.c create line $xy2 -fill $::C(fg) -width 2 -tag I21

    set xy {182 486 244 498}			;# Top
    $w.c create oval $xy -fill $color -outline {} -width 1.5p -tag {I21 I21f}
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 1.5p -tag {I21 I21t}
    $w.c create oval $xy -fill $color -outline {} -width 2 -tag {I21 I21f}
    $w.c create oval $xy -fill {} -outline $::C(fg) -width 2 -tag {I21 I21t}
    set xy {189 532 237 540}			;# Bottom
    $w.c create oval $xy -fill $color -outline $::C(fg) -width 1.5p \
    $w.c create oval $xy -fill $color -outline $::C(fg) -width 2 \
	    -tag {I21 I21b}
}
proc Move21 {w {step {}}} {
    set step [GetStep 21 $step]

    set numsteps 30
    if {$step  >= $numsteps} {
	return 0
    }

    lassign [$w.c coords I21b] x1 y1 x2 y2
    #lassign [$w.c coords I21t] X1 Y1 X2 Y2
    lassign [scl {183 492 243 504}] X1 Y1 X2 Y2
    lassign {183 492 243 504} X1 Y1 X2 Y2

    set f [expr {$step / double($numsteps)}]
    set y2 [expr {$y2 - [scl 3]}]
    set y2 [expr {$y2 - 3}]
    set xx1 [expr {$x1 + ($X1 - $x1) * $f}]
    set yy1 [expr {$y1 + ($Y1 - $y1) * $f}]
    set xx2 [expr {$x2 + ($X2 - $x2) * $f}]
    set yy2 [expr {$y2 + ($Y2 - $y2) * $f}]
    #H2O $w $yy1 40

    $w.c itemconfig I21b -fill $::C(20)
1546
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486
1487
1488
1489
1490







-
+







}

# Bucket drop
proc Draw22 {w} {
}
proc Move22 {w {step {}}} {
    set step [GetStep 22 $step]
    set pos [scl {{213 513} {213 523} {213 543 x} {213 583} {213 593}}]
    set pos {{213 513} {213 523} {213 543 x} {213 583} {213 593}}

    if {$step == 0} {$w.c itemconfig I21f -fill $::C(22)}
    if {$step >= [llength $pos]} {
	return 0
    }
    set where [lindex $pos $step]
    MoveAbs $w I21 $where
1570
1571
1572
1573
1574
1575
1576
1577

1578
1579
1580

1581
1582
1583
1584

1585
1586
1587

1588
1589

1590
1591

1592
1593

1594
1595
1596
1597
1598

1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

1623
1624

1625
1626

1627
1628
1629

1630
1631

1632
1633

1634
1635

1636
1637
1638

1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654

1655
1656

1657
1658
1659

1660
1661
1662
1663
1664


1665
1666
1667
1668
1669
1670
1671
1500
1501
1502
1503
1504
1505
1506

1507
1508
1509

1510
1511
1512
1513

1514
1515
1516

1517
1518

1519
1520

1521
1522

1523
1524
1525
1526
1527

1528
1529
1530

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551

1552
1553

1554
1555

1556
1557
1558

1559
1560

1561
1562

1563
1564

1565
1566
1567

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578

1579
1580
1581
1582
1583

1584
1585

1586
1587
1588

1589
1590
1591
1592


1593
1594
1595
1596
1597
1598
1599
1600
1601







-
+


-
+



-
+


-
+

-
+

-
+

-
+




-
+


-
+




















-
+

-
+

-
+


-
+

-
+

-
+

-
+


-
+










-
+




-
+

-
+


-
+



-
-
+
+







# Blow dart
proc Draw23 {w} {
    set color  $::C(23a)
    set color2 $::C(23b)
    set color3 $::C(23c)

    set xy {185 623 253 650}			;# Block
    $w.c create rect $xy -fill black -outline $::C(fg) -width 1.5p -tag I23a
    $w.c create rect $xy -fill black -outline $::C(fg) -width 2 -tag I23a
    set xy {187 592 241 623}			;# Balloon
    $w.c create oval $xy -outline {} -fill $color -tag I23b
    $w.c create arc $xy -outline $::C(fg) -width 2.25p -tag I23b \
    $w.c create arc $xy -outline $::C(fg) -width 3 -tag I23b \
	    -style arc -start 12 -extent 336
    set xy {239 604  258 589 258 625 239 610}	;# Balloon nozzle
    $w.c create poly $xy -outline {} -fill $color -tag I23b
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I23b
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I23b

    set xy {285 611 250 603}			;# Dart body
    $w.c create oval $xy -fill $color2 -outline $::C(fg) -width 2.25p -tag I23d
    $w.c create oval $xy -fill $color2 -outline $::C(fg) -width 3 -tag I23d
    set xy {249 596 249 618 264 607 249 596}	;# Dart tail
    $w.c create poly $xy -fill $color3 -outline $::C(fg) -width 2.25p -tag I23d
    $w.c create poly $xy -fill $color3 -outline $::C(fg) -width 3 -tag I23d
    set xy {249 607 268 607}			;# Dart detail
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I23d
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I23d
    set xy {285 607 305 607}			;# Dart needle
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I23d
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I23d
}
proc Move23 {w {step {}}} {
    set step [GetStep 23 $step]

    set pos [scl {
    set pos {
	{277 607} {287 607} {307 607 x} {347 607} {407 607} {487 607}
	{587 607} {687 607} {787 607} {-100 -100}
    }]
    }

    if {$step >= [llength $pos]} {
	return 0
    }
    if {$step <= 1} {
	$w.c scale I23b {*}[Anchor $w I23a n] .9 .5
    }
    set where [lindex $pos $step]
    MoveAbs $w I23d $where

    if {[lindex $where 2] eq "x"} {
	return 3
    }
    return 1
}

# Balloon
proc Draw24 {w} {
    set color $::C(24a)
    set xy {366 518 462 665}			;# Balloon
    $w.c create oval $xy -fill $color -outline $::C(fg) -width 2.25p -tag I24
    $w.c create oval $xy -fill $color -outline $::C(fg) -width 3 -tag I24
    set xy {414 666 414 729}			;# String
    $w.c create line $xy -fill $::C(fg) -width 2.25p -tag I24
    $w.c create line $xy -fill $::C(fg) -width 3 -tag I24
    set xy {410 666 404 673 422 673 418 666}	;# Nozzle
    $w.c create poly $xy -fill $color -outline $::C(fg) -width 2.25p -tag I24
    $w.c create poly $xy -fill $color -outline $::C(fg) -width 3 -tag I24

    set xy {387 567 390 549 404 542}		;# Reflections
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 1.5p -tag I24
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 2 -tag I24
    set xy {395 568 399 554 413 547}
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 1.5p -tag I24
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 2 -tag I24
    set xy {403 570 396 555 381 553}
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 1.5p -tag I24
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 2 -tag I24
    set xy {408 564 402 547 386 545}
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 1.5p -tag I24
    $w.c create line $xy -fill $::C(fg) -smooth 1 -width 2 -tag I24
}
proc Move24 {w {step {}}} {
    global S Dims
    global S
    set step [GetStep 24 $step]

    if {$step > 4} {
	return 0
    } elseif {$step == 4} {
	return 2
    }

    if {$step == 0} {
	$w.c delete I24				;# Exploding balloon
	set xy [scl {
	set xy {
	    347 465 361 557 271 503 272 503 342 574 259 594 259 593 362 626
	    320 737 320 740 398 691 436 738 436 739 476 679 528 701 527 702
	    494 627 548 613 548 613 480 574 577 473 577 473 474 538 445 508
	    431 441 431 440 400 502 347 465 347 465
	}]
	}
	$w.c create poly $xy -tag I24 -fill $::C(24b) -outline $::C(24a) \
		-width 7.5p -smooth 1
		-width 10 -smooth 1
	set msg [subst $S(message)]
	$w.c create text [Centroid $w I24] -text $msg -tag {I24 I24t} \
		-fill $::C(24c) -justify center -font {Times 18 bold}
		-justify center -font {{Times Roman} 18 bold}
	return 1
    }

    $w.c itemconfig I24t -font [list Times [expr {18 + 6*$step}] bold]
    $w.c move I24 $Dims(MovX) $Dims(MovY)
    $w.c itemconfig I24t -font [list {Times Roman} [expr {18 + 6*$step}] bold]
    $w.c move I24 0 -60
    $w.c scale I24 {*}[Centroid $w I24] 1.25 1.25
    return 1
}

# Displaying the message
proc Move25 {w {step {}}} {
    global S
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
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620



1621
1622
1623
1624
1625
1626
1627


1628
1629
1630
1631
1632
1633
1634
1635
1636







-
+




-
-
-
+
+
+




-
-
+
+







	return 1
    }
    return 2
}

# Collapsing balloon
proc Move26 {w {step {}}} {
    global S Dims
    global S
    set step [GetStep 26 $step]

    if {$step >= 3} {
	$w.c delete I24 I26
	$w.c create text $Dims(MsgX) $Dims(MsgY) -anchor s -tag I26 \
		-fill $::C(26) -text "click to continue" -font {Times 24 bold}
	bind $w.c <Button-1> [list Reset $w]
	$w.c create text 430 755 -anchor s -tag I26 \
		-text "click to continue" -font {{Times Roman} 24 bold}
	bind $w.c <1> [list Reset $w]
	return 4
    }

    $w.c scale I24 {*}[Centroid $w I24] .8 .8
    $w.c move I24 0 45p
    $w.c itemconfig I24t -font [list Times [expr {30 - 6*$step}] bold]
    $w.c move I24 0 60
    $w.c itemconfig I24t -font [list {Times Roman} [expr {30 - 6*$step}] bold]
    return 1
}

################################################################
#
# Helper functions
#
1741
1742
1743
1744
1745
1746
1747
1748

1749
1750
1751
1752
1753
1754
1755
1671
1672
1673
1674
1675
1676
1677

1678
1679
1680
1681
1682
1683
1684
1685







-
+








    return [list $xx $yy]
}

proc Reset {w} {
    global S
    DrawAll $w
    bind $w.c <Button-1> {}
    bind $w.c <1> {}
    set S(mode) $::MSTART
    set S(active) 0
}

# Each Move## keeps its state info in STEP, this retrieves and increments it
proc GetStep {who step} {
    global STEP
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
1823
1824
1825
1826
1827
1828
1829
1830


































































1831
1832
1833









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
    } elseif {[string match *e* $where]} {
	set x $x2
    } else {
	set x [expr {($x1 + $x2) / 2.0}]
    }
    return [list $x $y]
}

proc scl {lst} {
    global scaleFactor
    set lst2 {}
    foreach elem $lst {
	set elem2 {}
	set idx 0
	foreach val $elem {
	    if {$idx < 2} {
		set val [expr {round($val * $scaleFactor)}]
	    }
	    lappend elem2 $val
	    incr idx
	}

	lappend lst2 $elem2
    }

    return $lst2
}

# Simple placed dialog - stacked dialogs are not allowed,
# the command does nothing if another grab already exists.

proc PlacedDialog {w msg {labelFnt {Helvetica 10}}} {
    if {[grab current] ne {}} {
        return
    }
    destroy $w

    frame $w -relief raised -bd 3p
    label $w.lab -font $labelFnt -wraplength 3i -justify left -text $msg
    ttk::button $w.but -text "OK" -underline 0 \
	    -command [list ClosePlacedDialog $w]

    foreach key {Escape Return o O} {
	bind $w.but "<KeyPress-${key}>" { ClosePlacedDialog [winfo parent %W] }
    }
    foreach child {{} .but .lab} {
	bind $w$child <<NextWindow>> break
	bind $w$child <<PrevWindow>> break
    }

    pack $w.lab -padx 10p -pady {10p 5p}
    pack $w.but -padx 10p -pady {0p 10p}
    place $w -anchor center -relx 0.5 -rely 0.5

    set tl [winfo toplevel $w]
    set ::PlacedDialogOldFocus [focus -lastfor $tl]
    focus $w.but
    grab set $w
    return
}

proc ClosePlacedDialog {w} {
    set tl [winfo toplevel $w]
    if {![winfo exists $::PlacedDialogOldFocus]} {
        set ::PlacedDialogOldFocus $tl
    }
    focus $::PlacedDialogOldFocus
    set ::PlacedDialogOldFocus {}
    grab release $w
    destroy $w
    return
}


DoDisplay $w
Reset $w
Go $w						;# Start everything going
StartMessage $w					;# Message box at startup

Changes to library/demos/hello.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# hello --
# Simple Tk script to create a button that prints "Hello, world".
# Click on the button to terminate the program.

package require tk
package require Tk

# The first line below creates the button, and the second line
# asks the packer to shrink-wrap the application's main window
# around the button.

button .hello -text "Hello, world" -command {
    puts stdout "Hello, world"; destroy .

Changes to library/demos/hscale.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33

34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32

33
34
35
36
37
38
39
40
41
42
43
44

45












-
+















-
+


-
+


-
+

-
+











-
+
-
-
-
-
# hscale.tcl --
#
# This demonstration script shows an example with a horizontal scale.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .hscale
catch {destroy $w}
toplevel $w
wm title $w "Horizontal Scale Demonstration"
wm iconname $w "hscale"
positionWindow $w

label $w.msg -font $font -wraplength 3.5i -justify left -text "An arrow and a horizontal scale are displayed below.  If you click or drag mouse button 1 in the scale, you can change the length of the arrow."
pack $w.msg -side top -padx .5c

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame -side top -fill x

canvas $w.frame.canvas -width 37.5p -height 37.5p -bd 0 -highlightthickness 0
canvas $w.frame.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
$w.frame.canvas create polygon 0 0 1 1 2 2 -fill DeepSkyBlue3 -tags poly
$w.frame.canvas create line 0 0 1 1 2 2 0 0 -fill black -tags line
scale $w.frame.scale -orient horizontal -length 213p -from 0 -to 250 \
scale $w.frame.scale -orient horizontal -length 284 -from 0 -to 250 \
	-command "setWidth $w.frame.canvas" -tickinterval 50
pack $w.frame.canvas -side top -expand yes -anchor s -fill x -padx 12p
pack $w.frame.canvas -side top -expand yes -anchor s -fill x  -padx 15
pack $w.frame.scale -side bottom -expand yes -anchor n
$w.frame.scale set 75

proc setWidth {w width} {
    incr width 21
    set x2 [expr {$width - 30}]
    if {$x2 < 21} {
	set x2 21
    }
    $w coords poly 20 15 20 35 $x2 35 $x2 45 $width 25 $x2 5 $x2 15 20 15
    $w coords line 20 15 20 35 $x2 35 $x2 45 $width 25 $x2 5 $x2 15 20 15

}
    set scaleFactor [expr {$tk::scalingPct / 100.0}]
    $w scale poly 0 0 $scaleFactor $scaleFactor
    $w scale line 0 0 $scaleFactor $scaleFactor
}

Changes to library/demos/icon.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# icon.tcl --
#
# This demonstration script creates a toplevel window containing
# buttons that display bitmaps instead of text.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .icon
catch {destroy $w}
toplevel $w
wm title $w "Iconic Button Demonstration"
wm iconname $w "icon"
positionWindow $w
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+







# Main widget program sets variable tk_demoDirectory
image create bitmap flagup \
	-file [file join $tk_demoDirectory images flagup.xbm] \
	-maskfile [file join $tk_demoDirectory images flagup.xbm]
image create bitmap flagdown \
	-file [file join $tk_demoDirectory images flagdown.xbm] \
	-maskfile [file join $tk_demoDirectory images flagdown.xbm]
frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame -side top

checkbutton $w.frame.b1 -image flagdown -selectimage flagup \
	-indicatoron 0
$w.frame.b1 configure -selectcolor [$w.frame.b1 cget -background]
checkbutton $w.frame.b2 \
	-bitmap @[file join $tk_demoDirectory images letters.xbm] \

Changes to library/demos/image1.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32












33
34
35








-
+


















+
+



-
-
-
-
-
-
-
-
-
-
-
-
+


# image1.tcl --
#
# This demonstration script displays two image widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .image1
catch {destroy $w}
toplevel $w
wm title $w "Image Demonstration #1"
wm iconname $w "Image1"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration displays two images, each in a separate label widget."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

# Main widget program sets variable tk_demoDirectory
catch {image delete image1a}
image create photo image1a -file [file join $tk_demoDirectory images earth.gif]
label $w.l1 -image image1a -bd 1 -relief sunken

catch {image delete image1b}
image create photo image1b \
	-file [file join $tk_demoDirectory images earthris.gif]

# Create copies of the images just created, magnified according to the
# display's DPI scaling level.  Since the zooom factor must be an integer,
# the copies will only be effectively magnified if $tk::scalingPct >= 200.
set zoomFactor [expr {$tk::scalingPct / 100}]
image create photo image1a2
image1a2 copy image1a -zoom $zoomFactor
image create photo image1b2
image1b2 copy image1b -zoom $zoomFactor

label $w.l1 -image image1a2 -bd 1 -relief sunken
label $w.l2 -image image1b2 -bd 1 -relief sunken
label $w.l2 -image image1b -bd 1 -relief sunken

pack $w.l1 $w.l2 -side top -padx .5m -pady .5m

Changes to library/demos/image2.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# image2.tcl --
#
# This demonstration script creates a simple collection of widgets
# that allow you to select and view images in a Tk label.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# loadDir --
# This procedure reloads the directory listbox from the directory
# named in the demo's entry.
#
# Arguments:
# w -			Name of the toplevel window of the demo.
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
51
52
53
54
55
56
57






58

59
60
61
62
63
64
65
66







-
-
-
-
-
-

-
+







# w -			Name of the toplevel window of the demo.
# x, y-			Mouse position within the listbox.

proc loadImage {w x y} {
    global dirName

    set file [file join $dirName [$w.f.list get @$x,$y]]
    set opts [list -file $file]
    if {[string tolower [file extension $file]] eq ".svg"} {
	lappend opts -format $tk::svgFmt
    } else {
	lappend opts -format {}
    }
    if {[catch {
	image2a configure {*}$opts
	image2a configure -file $file
    }]} then {
	# Mark the file as not loadable
	$w.f.list itemconfigure @$x,$y -bg \#c00000 -selectbackground \#ff0000
    }
}

set w .image2
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113
114
90
91
92
93
94
95
96


97
98
99
100
101
102
103
104
105
106
107
108







-
-
+
+










pack $w.dir.e -side left -fill both -padx 2m     -pady 2m -expand true
pack $w.dir.b -side left -fill y    -padx {0 2m} -pady 2m
labelframe $w.f -text "File:" -padx 2m -pady 2m

listbox $w.f.list -width 20 -height 10 -yscrollcommand "$w.f.scroll set"
ttk::scrollbar $w.f.scroll -command "$w.f.list yview"
pack $w.f.list $w.f.scroll -side left -fill y -expand 1
$w.f.list insert 0 earth.gif earthris.gif teapot.ppm Tcl.svg
bind $w.f.list <Double-Button-1> "loadImage $w %x %y"
$w.f.list insert 0 earth.gif earthris.gif teapot.ppm
bind $w.f.list <Double-1> "loadImage $w %x %y"

catch {image delete image2a}
image create photo image2a
labelframe $w.image -text "Image:"
label $w.image.image -image image2a
pack $w.image.image -padx 2m -pady 2m

grid $w.dir -        -sticky ew -padx 1m -pady 1m -in $w.mid
grid $w.f   $w.image -sticky nw -padx 1m -pady 1m -in $w.mid
grid columnconfigure $w.mid 1 -weight 1

Deleted library/demos/images/Tcl.svg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75











































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://web.resource.org/cc/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="124.98526"
   height="264.6875"
   id="svg2309"
   sodipodi:version="0.32"
   inkscape:version="0.45"
   sodipodi:modified="true"
   version="1.0">
  <defs
     id="defs2311" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     gridtolerance="10000"
     guidetolerance="10"
     objecttolerance="10"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.35"
     inkscape:cx="375"
     inkscape:cy="520"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     inkscape:window-width="910"
     inkscape:window-height="626"
     inkscape:window-x="5"
     inkscape:window-y="49" />
  <metadata
     id="metadata2314">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-311.79308,-365.73272)">
    <g
       style="opacity:1;display:inline"
       id="g2244"
       transform="translate(308.95998,366.42022)">
      <path
         id="path4426"
         d="M 445.52492,372.22514 C 445.90652,395.55723 445.21415,418.63757 425.02492,440.56889 L 424.27492,441.41264 L 425.39992,441.41264 L 433.64992,441.53764 C 420.24442,469.42405 411.52244,497.23134 392.24367,525.00639 L 391.55617,526.00639 L 392.74367,525.78764 L 402.93117,523.85014 C 395.71427,542.16045 383.37359,554.28293 369.99367,558.35014 C 366.31107,506.78151 392.04593,461.26308 413.89992,415.88139 C 413.92002,415.83965 413.94233,415.79813 413.96242,415.75639 L 413.14992,415.19389 C 377.36425,455.2074 361.23872,511.6427 355.14992,558.19389 C 343.02146,551.34666 338.97913,542.28079 334.86867,529.94389 L 343.33742,533.50639 L 344.21242,533.88139 L 344.02492,532.94389 C 337.58858,504.32416 347.5814,483.78143 357.27492,456.78764 L 364.24367,461.44389 L 365.05617,462.00639 L 365.02492,461.03764 C 364.47892,439.10645 379.24595,417.08983 398.83742,397.44389 L 401.55617,404.72514 L 401.93117,405.69389 L 402.46242,404.78764 L 408.43117,394.85014 L 408.46242,394.78764 C 418.31429,381.21812 428.72988,376.80082 445.52492,372.22514 z "
         style="fill:#c3b15f;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline"
         transform="translate(-324.02492,-364.63139)" />
      <path
         sodipodi:nodetypes="ccccccccccccccccccccccc"
         id="path7600"
         d="M 121.54988,7.5808058 C 104.81215,12.147023 94.270242,16.613077 84.4375,30.15625 L 84.40625,30.21875 L 78.4375,40.15625 L 77.90625,41.0625 L 77.53125,40.09375 L 74.8125,32.8125 C 55.22103,52.45844 40.454,74.47506 41,96.40625 L 41.03125,97.375 L 40.21875,96.8125 L 33.25,92.15625 C 23.55648,119.15004 13.56366,139.69277 20,168.3125 L 20.1875,169.25 L 19.3125,168.875 L 10.9375,165.34375 C 10.96447,165.51523 11.003113,165.67421 11.03125,165.84375 C 15.080346,177.9015 19.176955,186.81713 31.125,193.5625 C 31.596616,189.95681 32.122231,186.27456 32.71875,182.5625 C 18.12816,148.39836 30.79293,123.2814 36.5625,100.6875 L 45.4375,105.8125 C 44.211577,84.657017 56.63174,61.842112 72.78125,41.9375 L 77.46875,50.1875 C 89.477498,25.486664 98.97512,15.57175 121.54988,7.5808058 z "
         style="opacity:1;fill:#eff1cb;fill-opacity:1;fill-rule:evenodd;stroke:#eff1cb;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline" />
      <path
         style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline"
         d="M 126.9375,-0.6875 L 126.40625,-0.59375 C 106.72165,2.83976 87.4508,10.07244 79,27.375 L 75.4375,21.15625 L 75.125,20.59375 L 74.65625,21.0625 C 64.96254,30.33838 54.55574,42.35306 46.875,54.15625 C 39.66528,65.23562 34.88327,76.07934 35.40625,84.375 L 30.375,78.09375 L 29.875,77.46875 L 29.53125,78.1875 C 23.40732,91.41649 17.22694,107.69157 13.53125,122.625 C 10.02725,136.78385 8.77244,149.67206 12.03125,157.78125 L 3.75,152.96875 L 3.0625,152.5625 L 3,153.375 C 1.44089,176.99202 11.0382,188.26833 22.0625,199.15625 L 12.875,201.4375 L 11.03125,201.90625 L 12.875,202.40625 C 18.14953,203.83558 23.15023,205.44485 26.625,208.125 C 30.09977,210.80515 32.09598,214.49082 31.5,220.375 L 31.5,220.40625 L 31.5,245.90625 L 31.5,246.0625 L 31.59375,246.1875 L 43.09375,262.6875 L 44,264 L 44,262.40625 L 44,223.53125 C 45.52181,216.98735 47.30807,212.4833 49.875,209.5 C 52.44193,206.5167 55.78211,204.98483 60.5625,204.40625 L 62.28125,204.1875 L 60.71875,203.46875 L 54.65625,200.59375 C 69.11174,191.89001 85.3013,170.55445 89.5625,150.28125 L 89.75,149.46875 L 88.96875,149.6875 L 81.46875,151.71875 C 88.13174,145.46249 94.84392,133.06721 101.21875,118.625 C 107.9798,103.3078 114.29247,85.96032 119.46875,72.09375 L 119.75,71.34375 L 118.96875,71.40625 L 113.1875,71.8125 C 120.3346,64.22669 124.30703,51.6996 126.25,38.46875 C 128.27227,24.69793 128.13035,10.1977 127,-0.15625 L 126.9375,-0.6875 z M 121.5,7.59375 C 121.8816,30.92584 121.18923,54.00618 101,75.9375 L 100.25,76.78125 L 101.375,76.78125 L 109.625,76.90625 C 96.2195,104.79266 87.49752,132.59995 68.21875,160.375 L 67.53125,161.375 L 68.71875,161.15625 L 78.90625,159.21875 C 71.68935,177.52906 59.34867,189.65154 45.96875,193.71875 C 42.28615,142.15012 68.02101,96.63169 89.875,51.25 C 89.8951,51.20826 89.91741,51.16674 89.9375,51.125 L 89.125,50.5625 C 53.33933,90.57601 37.2138,147.01131 31.125,193.5625 C 18.99654,186.71527 14.95421,177.6494 10.84375,165.3125 L 19.3125,168.875 L 20.1875,169.25 L 20,168.3125 C 13.56366,139.69277 23.55648,119.15004 33.25,92.15625 L 40.21875,96.8125 L 41.03125,97.375 L 41,96.40625 C 40.454,74.47506 55.22103,52.45844 74.8125,32.8125 L 77.53125,40.09375 L 77.90625,41.0625 L 78.4375,40.15625 L 84.40625,30.21875 L 84.4375,30.15625 C 94.28937,16.58673 104.70496,12.16943 121.5,7.59375 z "
         id="path2177" />
    </g>
  </g>
</svg>

Deleted library/demos/images/Tk_feather.png.

cannot compute difference between binary files

Changes to library/demos/images/earth.gif.

cannot compute difference between binary files

Deleted library/demos/images/earthmenu.png.

cannot compute difference between binary files

Deleted library/demos/images/plowed_field.png.

cannot compute difference between binary files

Deleted library/demos/images/starry_night.png.

cannot compute difference between binary files

Changes to library/demos/items.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59





60
61
62
63
64
65
66
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35







36
37
38
39
40
41
42
43
44
45
46
47





48
49
50
51
52
53
54
55
56
57
58
59









-
+









-
+














-
+
-
-
-
-
-
-
-












-
-
-
-
-
+
+
+
+
+







# items.tcl --
#
# This demonstration script creates a canvas that displays the
# canvas item types.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .items
catch {destroy $w}
toplevel $w
wm title $w "Canvas Item Demonstration"
wm iconname $w "Items"
positionWindow $w
set c $w.frame.c

label $w.msg -font $font -wraplength 5i -justify left -text "This window contains a canvas widget with examples of the various kinds of items supported by canvases.  The following operations are supported:\n  Left-Button drag:\tmoves item under pointer.\n  Middle-Button drag:\trepositions view.\n  Right-Button drag:\tstrokes out area.\n  Ctrl+f:\t\tprints items under area."
label $w.msg -font $font -wraplength 5i -justify left -text "This window contains a canvas widget with examples of the various kinds of items supported by canvases.  The following operations are supported:\n  Button-1 drag:\tmoves item under pointer.\n  Button-2 drag:\trepositions view.\n  Button-3 drag:\tstrokes out area.\n  Ctrl+f:\t\tprints items under area."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame
pack $w.frame -side top -fill both -expand yes

canvas $c -scrollregion {0c 0c 30c 24c} -width 15c -height 10c \
	-relief sunken -borderwidth 2 \
	-xscrollcommand "$w.frame.hscroll set" \
	-yscrollcommand "$w.frame.vscroll set"
ttk::scrollbar $w.frame.vscroll -command "$c yview"
ttk::scrollbar $w.frame.hscroll -orient horizontal -command "$c xview"
ttk::scrollbar $w.frame.hscroll -orient horiz -command "$c xview"

bind $c <TouchpadScroll> {
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    if {$deltaX != 0 || $deltaY != 0} {
	tk::ScrollByPixels %W $deltaX $deltaY
    }
}

grid $c -in $w.frame \
    -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid $w.frame.vscroll \
    -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
grid $w.frame.hscroll \
    -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid rowconfig    $w.frame 0 -weight 1 -minsize 0
grid columnconfig $w.frame 0 -weight 1 -minsize 0

# Display a 3x3 rectangular grid.

$c create rect 0c 0c 30c 24c -width 1.5p
$c create line 0c 8c 30c 8c -width 1.5p
$c create line 0c 16c 30c 16c -width 1.5p
$c create line 10c 0c 10c 24c -width 1.5p
$c create line 20c 0c 20c 24c -width 1.5p
$c create rect 0c 0c 30c 24c -width 2
$c create line 0c 8c 30c 8c -width 2
$c create line 0c 16c 30c 16c -width 2
$c create line 10c 0c 10c 24c -width 2
$c create line 20c 0c 20c 24c -width 2

set font1 {Helvetica 12}
set font2 {Helvetica 24 bold}
if {[winfo depth $c] > 1} {
    set blue DeepSkyBlue3
    set red red
    set bisque bisque3
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105

106
107

108
109
110
111

112
113
114
115
116
117
118
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97

98
99

100
101
102
103

104
105
106
107
108
109
110
111







-
+











-
+








-
+

-
+



-
+







$c create text 5c .2c -text Lines -anchor n
$c create line 1c 1c 3c 1c 1c 4c 3c 4c -width 2m -fill $blue \
	-cap butt -join miter -tags item
$c create line 4.67c 1c 4.67c 4c -arrow last -tags item
$c create line 6.33c 1c 6.33c 4c -arrow both -tags item
$c create line 5c 6c 9c 6c 9c 1c 8c 1c 8c 4.8c 8.8c 4.8c 8.8c 1.2c \
	8.2c 1.2c 8.2c 4.6c 8.6c 4.6c 8.6c 1.4c 8.4c 1.4c 8.4c 4.4c \
	-width 2.25p -fill $red -tags item
	-width 3 -fill $red -tags item
# Main widget program sets variable tk_demoDirectory
$c create line 1c 5c 7c 5c 7c 7c 9c 7c -width .5c \
	-stipple @[file join $tk_demoDirectory images gray25.xbm] \
	-arrow both -arrowshape {15 15 7} -tags item
$c create line 1c 7c 1.75c 5.8c 2.5c 7c 3.25c 5.8c 4c 7c -width .5c \
	-cap round -join round -tags item

$c create text 15c .2c -text "Curves (smoothed lines)" -anchor n
$c create line 11c 4c 11.5c 1c 13.5c 1c 14c 4c -smooth on \
	-fill $blue -tags item
$c create line 15.5c 1c 19.5c 1.5c 15.5c 4.5c 19.5c 4c -smooth on \
	-arrow both -width 2.25p -tags item
	-arrow both -width 3 -tags item
$c create line 12c 6c 13.5c 4.5c 16.5c 7.5c 18c 6c \
	16.5c 4.5c 13.5c 7.5c 12c 6c -smooth on -width 3m -cap round \
	-stipple @[file join $tk_demoDirectory images gray25.xbm] \
	-fill $red -tags item

$c create text 25c .2c -text Polygons -anchor n
$c create polygon 21c 1.0c 22.5c 1.75c 24c 1.0c 23.25c 2.5c \
	24c 4.0c 22.5c 3.25c 21c 4.0c 21.75c 2.5c -fill $green \
	-outline {} -width 3p -tags item
	-outline black -width 4 -tags item
$c create polygon 25c 4c 25c 4c 25c 1c 26c 1c 27c 4c 28c 1c \
	29c 1c 29c 4c 29c 4c -fill $red -outline {} -smooth on -tags item
	29c 1c 29c 4c 29c 4c -fill $red -smooth on -tags item
$c create polygon 22c 4.5c 25c 4.5c 25c 6.75c 28c 6.75c \
	28c 5.25c 24c 5.25c 24c 6.0c 26c 6c 26c 7.5c 22c 7.5c \
	-stipple @[file join $tk_demoDirectory images gray25.xbm] \
	-fill $blue -outline {} -tags item
	-outline black -tags item

$c create text 5c 8.2c -text Rectangles -anchor n
$c create rectangle 1c 9.5c 4c 12.5c -outline $red -width 3m -tags item
$c create rectangle 0.5c 13.5c 4.5c 15.5c -fill $green -tags item
$c create rectangle 6c 10c 9c 15c -outline {} \
	-stipple @[file join $tk_demoDirectory images gray25.xbm] \
	-fill $blue -tags item
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

161
162
163
164


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187


188
189
190
191
192
193
194
195
196
197




198
199
200

201
202
203
204
205
206
207
122
123
124
125
126
127
128

129
130

131
132
133
134
135
136
137
138
139
140
141
142


143
144
145
146



147




148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169


170
171










172
173
174
175

176

177
178
179
180
181
182
183
184







-


-












-
-




-
-
-
+
-
-
-
-
+
+
-




















-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-

-
+







$c create text 22.5c 9c -anchor n -font $font1 -width 4c \
	-text "A short string of text, word-wrapped, justified left, and anchored north (at the top).  The rectangles show the anchor points for each piece of text." -tags item
$c create rectangle 25.4c 10.9c 25.6c 11.1c
$c create text 25.5c 11c -anchor w -font $font1 -fill $blue \
	-text "Several lines,\n each centered\nindividually,\nand all anchored\nat the left edge." \
	-justify center -tags item
$c create rectangle 24.9c 13.9c 25.1c 14.1c
catch {
$c create text 25c 14c -font $font2 -anchor c -fill $red -angle 15 \
	-text "Angled characters" -tags item
}

$c create text 5c 16.2c -text Arcs -anchor n
$c create arc 0.5c 17c 7c 20c -fill $green -outline black \
	-start 45 -extent 270 -style pieslice -tags item
$c create arc 6.5c 17c 9.5c 20c -width 4m -style arc \
	-outline $blue -start -135 -extent 270 -tags item \
	-outlinestipple @[file join $tk_demoDirectory images gray25.xbm]
$c create arc 0.5c 20c 9.5c 24c -width 4m -style pieslice \
	-fill {} -outline $red -start 225 -extent -90 -tags item
$c create arc 5.5c 20.5c 9.5c 23.5c -width 4m -style chord \
	-fill $blue -outline {} -start 45 -extent 270  -tags item

$c create text 15c 16.2c -text "Bitmaps and Images" -anchor n
catch {
image create photo items.ousterhout \
    -file [file join $tk_demoDirectory images ouster.png]
image create photo items.ousterhout.active -format "png -alpha 0.5" \
    -file [file join $tk_demoDirectory images ouster.png]
set zoomFactor [expr {$tk::scalingPct / 100}]
foreach img {items.ousterhout items.ousterhout.active} {
    image create photo ${img}2
$c create text 15c 16.2c -text "Bitmaps and Images" -anchor n
    ${img}2 copy $img -zoom $zoomFactor
}
$c create image 13c 20c -tags item -image items.ousterhout2 \
    -activeimage items.ousterhout.active2
$c create image 13c 20c -tags item -image items.ousterhout \
    -activeimage items.ousterhout.active
}
$c create bitmap 17c 18.5c -tags item \
	-bitmap @[file join $tk_demoDirectory images noletter.xbm]
$c create bitmap 17c 21.5c -tags item \
	-bitmap @[file join $tk_demoDirectory images letters.xbm]

$c create text 25c 16.2c -text Windows -anchor n
button $c.button -text "Press Me" -command "butPress $c $red"
$c create window 21c 18c -window $c.button -anchor nw -tags item
entry $c.entry -width 20 -relief sunken
$c.entry insert end "Edit this text"
$c create window 21c 21c -window $c.entry -anchor nw -tags item
scale $c.scale -from 0 -to 100 -length 6c -sliderlength .4c \
	-width .5c -tickinterval 0
$c create window 28.5c 17.5c -window $c.scale -anchor n -tags item
$c create text 21c 17.9c -text Button: -anchor sw
$c create text 21c 20.9c -text Entry: -anchor sw
$c create text 28.5c 17.4c -text Scale: -anchor s

# Set up event bindings for canvas:

$c bind item <Enter> "itemEnter $c"
$c bind item <Leave> "itemLeave $c"
$c bind item <Any-Enter> "itemEnter $c"
$c bind item <Any-Leave> "itemLeave $c"
if {[tk windowingsystem] eq "aqua" && ![package vsatisfies [package provide tk] 8.7-]} {
    bind $c <Button-2> "itemMark $c %x %y"
    bind $c <B2-Motion> "itemStroke $c %x %y"
    bind $c <Button-3> "$c scan mark %x %y"
    bind $c <B3-Motion> "$c scan dragto %x %y"
} else {
    bind $c <Button-2> "$c scan mark %x %y"
    bind $c <B2-Motion> "$c scan dragto %x %y"
    bind $c <Button-3> "itemMark $c %x %y"
    bind $c <B3-Motion> "itemStroke $c %x %y"
bind $c <2> "$c scan mark %x %y"
bind $c <B2-Motion> "$c scan dragto %x %y"
bind $c <3> "itemMark $c %x %y"
bind $c <B3-Motion> "itemStroke $c %x %y"
}
bind $c <<NextChar>> "itemsUnderArea $c"
bind $c <Button-1> "itemStartDrag $c %x %y"
bind $c <1> "itemStartDrag $c %x %y"
bind $c <B1-Motion> "itemDrag $c %x %y"

# Utility procedures for highlighting the item under the pointer:

proc itemEnter {c} {
    global restoreCmd

265
266
267
268
269
270
271
272

273
274
275
276
277
278
279

280
281
282
283
284
285
286
242
243
244
245
246
247
248

249
250
251
252
253
254
255

256
257
258
259
260
261
262
263







-
+






-
+







}

proc itemsUnderArea {c} {
    global areaX1 areaY1 areaX2 areaY2
    set area [$c find withtag area]
    set items ""
    foreach i [$c find enclosed $areaX1 $areaY1 $areaX2 $areaY2] {
	if {[lsearch [$c gettags $i] item] >= 0} {
	if {[lsearch [$c gettags $i] item] != -1} {
	    lappend items $i
	}
    }
    puts stdout "Items enclosed by area: $items"
    set items ""
    foreach i [$c find overlapping $areaX1 $areaY1 $areaX2 $areaY2] {
	if {[lsearch [$c gettags $i] item] >= 0} {
	if {[lsearch [$c gettags $i] item] != -1} {
	    lappend items $i
	}
    }
    puts stdout "Items overlapping area: $items"
}

set areaX1 0

Changes to library/demos/ixset.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19











-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# ixset --
# A nice interface to "xset" to change X server settings
#
# History :
#   91/11/23 : [email protected], [email protected] : design
#   92/08/01 : [email protected] : cleaning

package require tk
package require Tk

#
# Button actions
#

proc quit {} {
    destroy .
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
+







    global mouseacc ;	set mouseacc	"3/1"
    global mousethr ;	set mousethr	4
    global screenbla ;	set screenbla	"blank"
    global screentim ;	set screentim	600
    global screencyc ;	set screencyc	600

    set xfd [open "|xset q" r]
    while {[gets $xfd line] >= 0} {
    while {[gets $xfd line] > -1} {
	switch -- [lindex $line 0] {
	    auto {
		set rpt [lindex $line 1]
		if {$rpt eq "repeat:"} {
		    set kbdrep [lindex $line 2]
		    set kbdcli [lindex $line 6]
		}
189
190
191
192
193
194
195
196

197
198
199
200

201
202
203
204
205
206
207
189
190
191
192
193
194
195

196
197
198
199

200
201
202
203
204
205
206
207







-
+



-
+







    button .buttons.apply  -default normal -command apply  -text "Apply" \
	    -state disabled
    button .buttons.cancel -default normal -command cancel -text "Cancel" \
	    -state disabled
    button .buttons.quit   -default normal -command quit   -text "Quit"

    pack .buttons.ok .buttons.apply .buttons.cancel .buttons.quit \
	    -side left -expand yes -pady 3p
	    -side left -expand yes -pady 5

    bind . <Return> {.buttons.ok   flash; .buttons.ok   invoke}
    bind . <Escape> {.buttons.quit flash; .buttons.quit invoke}
    bind . <Button-1> {
    bind . <1> {
	if {![string match .buttons* %W]} {
	    .buttons.apply  configure -state normal
	    .buttons.cancel configure -state normal
	}
    }
    bind . <Key> {
	if {![string match .buttons* %W]} {
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251

252
253
254
255
256
257
258
217
218
219
220
221
222
223

224
225
226
227
228
229


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250

251
252
253
254
255
256
257
258







-
+





-
-
+
+














-
+




-
+








    #
    # Bell settings
    #

    labelframe .bell -text "Bell Settings" -padx 1.5m -pady 1.5m
    scale .bell.vol \
	    -from 0 -to 100 -length 150p -tickinterval 20 \
	    -from 0 -to 100 -length 200 -tickinterval 20 \
	    -label "Volume (%)" -orient horizontal

    frame .bell.val
    labelentry .bell.val.pit "Pitch (Hz)"    6 {25 20000}
    labelentry .bell.val.dur "Duration (ms)" 6 {1 10000}
    pack .bell.val.pit -side left -padx 3p
    pack .bell.val.dur -side right -padx 3p
    pack .bell.val.pit -side left -padx 5
    pack .bell.val.dur -side right -padx 5
    pack .bell.vol .bell.val -side top -expand yes

    #
    # Keyboard settings
    #

    labelframe .kbd -text "Keyboard Repeat Settings" -padx 1.5m -pady 1.5m

    frame .kbd.val
    checkbutton .kbd.val.onoff \
	    -text "On" \
	    -onvalue "on" -offvalue "off" -variable kbdrep \
	    -relief flat
    scale .kbd.val.cli \
	    -from 0 -to 100 -length 150p -tickinterval 20 \
	    -from 0 -to 100 -length 200 -tickinterval 20 \
	    -label "Click Volume (%)" -orient horizontal
    pack .kbd.val.onoff -side left -fill x -expand yes -padx {0 1m}
    pack .kbd.val.cli -side left -expand yes -fill x -padx {1m 0}

    pack .kbd.val -side top -expand yes -pady 1.5p -fill x
    pack .kbd.val -side top -expand yes -pady 2 -fill x

    #
    # Mouse settings
    #

    labelframe .mouse -text "Mouse Settings" -padx 1.5m -pady 1.5m

Changes to library/demos/knightstour.tcl.

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







# Copyright © 2008 Pat Thoyts <[email protected]>
# Copyright (C) 2008 Pat Thoyts <[email protected]>
#
#	Calculate a Knight's tour of a chessboard.
#
#	This uses Warnsdorff's rule to calculate the next square each
#	time. This specifies that the next square should be the one that
#	has the least number of available moves.
#
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65







-
+







-
+











-
+













-
+







#	If the call to the Edgemost function is commented out you can see
#	this occur.
#
#	You can drag the knight to a specific square to start if you wish.
#	If you let it repeat then it will choose random start positions
#	for each new tour.

package require tk
package require Tk 8.5

# Return a list of accessible squares from a given square
proc ValidMoves {square} {
    set moves {}
    foreach pair {{-1 -2} {-2 -1} {-2 1} {-1 2} {1 2} {2 1} {2 -1} {1 -2}} {
        set col [expr {($square % 8) + [lindex $pair 0]}]
        set row [expr {($square / 8) + [lindex $pair 1]}]
        if {$row >= 0 && $row < 8 && $col >= 0 && $col < 8} {
        if {$row > -1 && $row < 8 && $col > -1 && $col < 8} {
            lappend moves [expr {$row * 8 + $col}]
        }
    }
    return $moves
}

# Return the number of available moves for this square
proc CheckSquare {square} {
    variable visited
    set moves 0
    foreach test [ValidMoves $square] {
        if {[lsearch -exact -integer $visited $test] < 0} {
        if {[lsearch -exact -integer $visited $test] == -1} {
            incr moves
        }
    }
    return $moves
}

# Select the next square to move to. Returns -1 if there are no available
# squares remaining that we can move to.
proc Next {square} {
    variable visited
    set minimum 9
    set nextSquare -1
    foreach testSquare [ValidMoves $square] {
        if {[lsearch -exact -integer $visited $testSquare] < 0} {
        if {[lsearch -exact -integer $visited $testSquare] == -1} {
            set count [CheckSquare $testSquare]
            if {$count < $minimum} {
                set minimum $count
                set nextSquare $testSquare
            } elseif {$count == $minimum} {
                # to remove the enhancement to Warnsdorff's rule
                # remove the next line:
77
78
79
80
81
82
83
84


85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116

117
118
119
120
121
122
123
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115

116
117
118
119
120
121
122
123







-
+
+







-
-
+















-
+






-
+







    set rowA [expr {3-int(abs(3.5-($a/8)))}]
    set rowB [expr {3-int(abs(3.5-($b/8)))}]
    return [expr {($colA * $rowA) < ($colB * $rowB) ? $a : $b}]
}

# Display a square number as a standard chess square notation.
proc N {square} {
    return [format %c%d [expr {97 + $square % 8}] [expr {$square / 8 + 1}]]
    return [format %c%d [expr {97 + $square % 8}] \
                [expr {$square / 8 + 1}]]
}

# Perform a Knight's move and schedule the next move.
proc MovePiece {dlg last square} {
    variable visited
    variable delay
    variable continuous
    set line [format "%2d. %s .. %s" [llength $visited] [N $last] [N $square]]
    $dlg.f.txt insert end $line\n
    $dlg.f.txt insert end "[llength $visited]. [N $last] .. [N $square]\n" {}
    $dlg.f.txt see end
    $dlg.f.c itemconfigure [expr {1+$last}] -state normal -outline black
    $dlg.f.c itemconfigure [expr {1+$square}] -state normal -outline red
    $dlg.f.c moveto knight {*}[lrange [$dlg.f.c coords [expr {1+$square}]] 0 1]
    lappend visited $square
    set next [Next $square]
    if {$next ne -1} {
        variable aid [after $delay [list MovePiece $dlg $square $next]]
    } else {
        $dlg.tf.b1 configure -state normal
        if {[llength $visited] == 64} {
            variable initial
            if {$initial == $square} {
                $dlg.f.txt insert end "Closed tour!"
            } else {
                $dlg.f.txt insert end "Success"
                $dlg.f.txt insert end "Success\n" {}
                if {$continuous} {
                    after [expr {$delay * 2}] [namespace code \
                        [list Tour $dlg [expr {int(rand() * 64)}]]]
                }
            }
        } else {
            $dlg.f.txt insert end "FAILED!"
            $dlg.f.txt insert end "FAILED!\n" {}
        }
    }
}

# Begin a new tour of the board given a random start position
proc Tour {dlg {square {}}} {
    variable visited {}
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
141
142
143
144
145
146
147


148
149
150
151
152
153
154
155







-
-
+








proc Exit {dlg} {
    Stop
    destroy $dlg
}

proc SetDelay {new} {
    variable speed [expr {int($new)}]
    variable delay [expr {2000 - $speed}]
    variable delay [expr {int($new)}]
}

proc DragStart {w x y} {
    $w dtag selected
    $w addtag selected withtag current
    variable dragging [list $x $y]
}
168
169
170
171
172
173
174
175

176
177
178
179
180



181
182
183
184

185
186
187
188
189
190





191
192
193
194
195

196
197
198
199
200
201
202

203
204

205
206
207

208
209
210
211
212


213
214
215

216
217
218

219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243

244
245
246
247
248
249
250
167
168
169
170
171
172
173

174
175
176



177
178
179
180
181


182
183
184




185
186
187
188
189

190
191
192

193
194
195
196
197
198
199

200


201

202

203
204
205
206


207
208
209
210

211
212
213

214
215
216
217
218


219
220

221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236

237
238
239
240
241
242
243
244







-
+


-
-
-
+
+
+


-
-
+


-
-
-
-
+
+
+
+
+
-



-
+






-
+
-
-
+
-

-
+



-
-
+
+


-
+


-
+




-
-


-
+








-
+






-
+







    $w dtag selected
    variable dragging ; unset dragging
}

proc CreateGUI {} {
    catch {destroy .knightstour}
    set dlg [toplevel .knightstour]
    wm title $dlg "Knight's Tour"
    wm title $dlg "Knights tour"
    wm withdraw $dlg
    set f [ttk::frame $dlg.f]
    set c [canvas $f.c -width 192p -height 192p]
    text $f.txt -width 12 -height 1 -padx 3p \
        -yscrollcommand [list $f.vs set] -font TkFixedFont
    set c [canvas $f.c -width 240 -height 240]
    text $f.txt -width 10 -height 1 -background white \
        -yscrollcommand [list $f.vs set] -font {Arial 8}
    ttk::scrollbar $f.vs -command [list $f.txt yview]

    variable speed 1400
    variable delay [expr {2000 - $speed}]
    variable delay 600
    variable continuous 0
    ttk::frame $dlg.tf
    ttk::checkbutton $dlg.tf.cc -text Repeat \
        -variable [namespace which -variable continuous]
    ttk::scale $dlg.tf.sc  -from 0 -to 1992 -command [list SetDelay] \
        -variable [namespace which -variable speed]
    ttk::label $dlg.tf.ls -text Speed
    ttk::scale $dlg.tf.sc  -from 8 -to 2000 -command [list SetDelay] \
        -variable [namespace which -variable delay]
    ttk::checkbutton $dlg.tf.cc -text Repeat \
        -variable [namespace which -variable continuous]
    ttk::label $dlg.tf.ls -text Speed
    ttk::button $dlg.tf.b1 -text Start -command [list Tour $dlg]
    ttk::button $dlg.tf.b2 -text Exit -command [list Exit $dlg]
    set square 0
    for {set row 7} {$row >= 0} {incr row -1} {
    for {set row 7} {$row != -1} {incr row -1} {
        for {set col 0} {$col < 8} {incr col} {
            if {(($col & 1) ^ ($row & 1))} {
                set fill tan3 ; set dfill tan4
            } else {
                set fill bisque ; set dfill bisque3
            }
            set coords [list [expr {$col * 24 + 3}]p \
            set coords [list [expr {$col * 30 + 4}] [expr {$row * 30 + 4}] \
			     [expr {$row * 24 + 3}]p \
                             [expr {$col * 24 + 24}]p \
                            [expr {$col * 30 + 30}] [expr {$row * 30 + 30}]]
			     [expr {$row * 24 + 24}]p]
            $c create rectangle $coords -fill $fill -disabledfill $dfill \
                -width 1.5p -state disabled -outline black
                -width 2 -state disabled
        }
    }
    if {[tk windowingsystem] ne "x11"} {
        catch {eval font create KnightFont -size 18}
        $c create text 0 0 -font KnightFont -text "" \
        catch {eval font create KnightFont -size -24}
        $c create text 0 0 -font KnightFont -text "\u265e" \
            -anchor nw -tags knight -fill black -activefill "#600000"
    } else {
        # On X11 we cannot reliably tell if the  glyph is available
        # On X11 we cannot reliably tell if the \u265e glyph is available
        # so just use a polygon
        set pts {
            2 25   24 25  21 19   20 8   14 0   10 0    0 13  0 16
            2 25   24 25  21 19   20 8   14 0   10 0   0 13   0 16
            2 17    4 14   5 15    3 17   5 17   9 14  10 15  5 21
        }
        $c create polygon $pts -tag knight -offset 8 \
            -fill black -activefill "#600000"
	set scaleFactor [expr {$tk::scalingPct / 100.0}]
	$c scale knight 0 0 $scaleFactor $scaleFactor
    }
    $c moveto knight {*}[lrange [$c coords [expr {1 + int(rand() * 64)}]] 0 1]
    $c bind knight <Button-1> [namespace code [list DragStart %W %x %y]]
    $c bind knight <ButtonPress-1> [namespace code [list DragStart %W %x %y]]
    $c bind knight <Motion> [namespace code [list DragMotion %W %x %y]]
    $c bind knight <ButtonRelease-1> [namespace code [list DragEnd %W %x %y]]

    grid $c $f.txt $f.vs  -sticky news
    grid rowconfigure    $f 0 -weight 1
    grid columnconfigure $f 1 -weight 1

    grid $f - - - - - -sticky news
    set things [list $dlg.tf.cc $dlg.tf.sc $dlg.tf.ls $dlg.tf.b1]
    set things [list $dlg.tf.ls $dlg.tf.sc $dlg.tf.cc $dlg.tf.b1]
    if {![info exists ::widgetDemo]} {
	lappend things $dlg.tf.b2
	if {[tk windowingsystem] ne "aqua"} {
	    set things [linsert $things 0 [ttk::sizegrip $dlg.tf.sg]]
	}
    }
    pack {*}$things -side right -padx 3p
    pack {*}$things -side right
    if {[tk windowingsystem] eq "aqua"} {
	pack configure {*}$things -padx {4 4} -pady {12 12}
	pack configure [lindex $things 0] -padx {4 24}
	pack configure [lindex $things end] -padx {16 4}
    }
    grid $dlg.tf  - - - - - -sticky ew
    if {[info exists ::widgetDemo]} {

Changes to library/demos/label.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45

46
47
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32

33
34
35
36
37








38
39
40









-
+

















-
+




-
+




-
-
-
-
-
-
-
-
+


# label.tcl --
#
# This demonstration script creates a toplevel window containing
# several label widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .label
catch {destroy $w}
toplevel $w
wm title $w "Label Demonstration"
wm iconname $w "label"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "Five labels are displayed below: three textual ones on the left, and an image label and a text label on the right.  Labels are pretty boring because you can't do anything with them."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.left
frame $w.right
pack $w.left $w.right -side left -expand yes -padx 7.5p -pady 7.5p -fill both
pack $w.left $w.right -side left -expand yes -padx 10 -pady 10 -fill both

label $w.left.l1 -text "First label"
label $w.left.l2 -text "Second label, raised" -relief raised
label $w.left.l3 -text "Third label, sunken" -relief sunken
pack $w.left.l1 $w.left.l2 $w.left.l3 -side top -expand yes -pady 1.5p -anchor w
pack $w.left.l1 $w.left.l2 $w.left.l3 -side top -expand yes -pady 2 -anchor w

# Main widget program sets variable tk_demoDirectory
image create photo label.ousterhout \
    -file [file join $tk_demoDirectory images ouster.png]

# Create a copy of the image just created, magnified according to the
# display's DPI scaling level.  Since the zooom factor must be an integer,
# the copy will only be effectively magnified if $tk::scalingPct >= 200.
image create photo label.ousterhout2
label.ousterhout2 copy label.ousterhout -zoom [expr {$tk::scalingPct / 100}]

label $w.right.picture -borderwidth 2 -relief sunken -image label.ousterhout2
label $w.right.picture -borderwidth 2 -relief sunken -image label.ousterhout
label $w.right.caption -text "Tcl/Tk Creator"
pack $w.right.picture $w.right.caption -side top

Changes to library/demos/labelframe.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# labelframe.tcl --
#
# This demonstration script creates a toplevel window containing
# several labelframe widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .labelframe
catch {destroy $w}
toplevel $w
wm title $w "Labelframe Demonstration"
wm iconname $w "labelframe"
positionWindow $w
31
32
33
34
35
36
37
38

39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
31
32
33
34
35
36
37

38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76







-
+





-
+
















-
+








-
+







frame $w.f
pack $w.f -side bottom -fill both -expand 1
set w $w.f

# A group of radiobuttons in a labelframe

labelframe $w.f -text "Value" -padx 1.5p -pady 1.5p
labelframe $w.f -text "Value" -padx 2 -pady 2
grid $w.f -row 0 -column 0 -pady 2m -padx 2m

foreach value {1 2 3 4} {
    radiobutton $w.f.b$value -text "This is value $value" \
            -variable lfdummy -value $value
    pack $w.f.b$value -side top -fill x -pady 1.5p
    pack $w.f.b$value -side top -fill x -pady 2
}


# Using a label window to control a group of options.

proc lfEnableButtons {w} {
    foreach child [winfo children $w] {
        if {$child == "$w.cb"} continue
        if {$::lfdummy2} {
            $child configure -state normal
        } else {
            $child configure -state disabled
        }
    }
}

labelframe $w.f2 -pady 1.5p -padx 1.5p
labelframe $w.f2 -pady 2 -padx 2
checkbutton $w.f2.cb -text "Use this option." -variable lfdummy2 \
        -command "lfEnableButtons $w.f2" -padx 0
$w.f2 configure -labelwidget $w.f2.cb
grid $w.f2 -row 0 -column 1 -pady 2m -padx 2m

set t 0
foreach str {Option1 Option2 Option3} {
    checkbutton $w.f2.b$t -text $str
    pack $w.f2.b$t -side top -fill x -pady 1.5p
    pack $w.f2.b$t -side top -fill x -pady 2
    incr t
}
lfEnableButtons $w.f2


grid columnconfigure $w {0 1} -weight 1

Deleted library/demos/mac_styles.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266










































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# mac_styles.tcl --
#
# This demonstration script creates a toplevel window containing a notebook
# whose pages provide examples of the various mac-specific widgets that are
# provided via special values for the -style option.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

set w .mac_styles
catch {destroy $w}
toplevel $w
package require tk
wm title $w "Tk Aqua Widgets"
wm iconname $w "mac_styles"
positionWindow $w
##
# System images we use in our buttons

set featherImg [file join $tk_demoDirectory images Tk_feather.png]
set starryImg [file join $tk_demoDirectory images starry_night.png]
set fieldImg [file join $tk_demoDirectory images plowed_field.png]
image create nsimage action -source NSAction -width 48 -height 48
image create nsimage bonjour -source NSBonjour -width 48 -height 48
image create nsimage bonjour1 -source NSBonjour -width 48 -height 48 -pressed 1
image create nsimage tkfeather -source $featherImg -as file -width 48 -height 48
image create nsimage tkfeather1 -source $featherImg -as file -width 48 -height 48 -pressed 1
image create nsimage starry -source $starryImg -as file -width 96 -radius 10
image create nsimage starry1 -source $starryImg -as file -width 96 -radius 10 -pressed 1
image create nsimage starry2 -source $starryImg -as file -width 96 -radius 10 -ring 3
image create nsimage field -source $fieldImg -as file -width 96 -radius 10
image create nsimage field1 -source $fieldImg -as file -width 96 -radius 10 -pressed 1
image create nsimage field2 -source $fieldImg -as file -width 96 -radius 10 -ring 3
image create nsimage add -source NSAddTemplate -width 20 -height 20
image create nsimage remove -source NSRemoveTemplate -width 18 -height 4

# Off state and variables for checkbuttons and radio buttons
set off {!selected !alternate}
variable $w.checkVar
variable $w.radioVar
variable $w.triangleVar
variable $w.popupVar
variable $w.stepVar
variable $w.comboVar

# Make a disclosure triangle change state when clicked.
proc toggleTriangle {tri} {
    $tri instate {user1} {
	$tri state {!user1}
	return
    }
    $tri instate {!user1} {
	$tri state {user1}
    }
}

proc popupButton {win varName firstValue args} {
    upvar #0 $varName var
    if {![info exists var]} {
	set var $firstValue
    }
    ttk::menubutton $win -textvariable $varName -menu $win.menu -direction flush
    menu $win.menu -tearoff 0
    $win.menu add radiobutton -label $firstValue -variable $varName
    foreach i $args {
	$win.menu add radiobutton -label $i -variable $varName
    }
    return $win.menu
}

set mag [encoding convertfrom utf-8 "\xf0\x9f\x94\x8d"]

proc searchFocusOut {e} {
    global mag
    if {[$e get] eq ""} {
	$e configure -foreground gray60
	$e insert 0 "Search"
    }
}

proc searchFocusIn {e} {
    if {[$e cget -foreground] == {gray60}} {
	$e delete 0 end
	$e configure -foreground black
    }
}

## Make the notebook and set up Ctrl+Tab traversal
ttk::notebook $w.notebook
ttk::notebook::enableTraversal $w.notebook

# Frames pane
set framesFrame [ttk::frame $w.notebook.frames -padding {40 35 40 50}]
$w.notebook add $framesFrame -text "Frames"
pack [ttk::labelframe $framesFrame.darker -text Darker -padding {50 30 50 50}] \
    -fill both -expand 1
pack [ttk::label $framesFrame.darker.label -padding {0 0 0 6} \
	  -text "This Group Box is nested to depth 2"] \
    -fill x
pack [ttk::labelframe $framesFrame.darker.darker -text "Darker Still" -padding 24] \
    -fill both -expand 1
pack [ttk::label $framesFrame.darker.darker.label \
	  -text "This Group Box is nested to depth 3"] -fill x
pack [button $framesFrame.darker.darker.tkbutton -text "Tk Button" -width 7 \
	  -highlightbackground systemWindowBackgroundColor3] -pady 10
pack [ttk::button $framesFrame.darker.darker.ttkbutton -text "Ttk Button" \
	  -width 7 -padding {-4 0 -4 0}] \
	  -pady 3
# Button pane
set buttonFrame [ttk::frame $w.notebook.buttons -padding {100 20 0 20}]
$w.notebook add $buttonFrame -text "Buttons"
grid columnconfigure $buttonFrame 0 -minsize 100
grid columnconfigure $buttonFrame 1 -minsize 100

set plain [ttk::button $buttonFrame.plain -text Button -padding {-12 0}]
popupButton $buttonFrame.options .popupVar "Item 1" "Item 2" "Item 3"
set options $buttonFrame.options
set check [ttk::checkbutton $buttonFrame.check -text Check -variable .checkVar]
set radio [ttk::frame $buttonFrame.radio]
pack [ttk::radiobutton $radio.r1 -text "Radio 1" -variable .radioVar -value 1] -pady 4
pack [ttk::radiobutton $radio.r2 -text "Radio 2" -variable .radioVar -value 2] -pady 4
set triangle [ttk::checkbutton $buttonFrame.triangle -style Item -variable TriangleVar]
bind $triangle <Button-1> {toggleTriangle %W}
set bonjour [ttk::button $buttonFrame.bonjour -style ImageButton -text Bonjour \
 		     -image {bonjour pressed bonjour1}]
set feather [ttk::button $buttonFrame.feather -style ImageButton -text Tk \
		      -image {tkfeather pressed tkfeather1}]
set gradient [ttk::frame $buttonFrame.gradient]
pack [ttk::button $buttonFrame.gradient.add -style GradientButton \
	  -image add -padding {2 0}] -side left
pack [ttk::button $buttonFrame.gradient.remove -style GradientButton \
	  -image remove -padding {2 8}] -side left
set disclosure [ttk::checkbutton $buttonFrame.disclosure -style DisclosureButton]
set help [ttk::button $buttonFrame.help -style HelpButton];

$check state $off
$radio.r1 state $off
$radio.r2 state $off

grid [ttk::label $buttonFrame.plainLabel -text "Push Button:"]\
    -row 0 -column 0 -padx 4 -sticky e
grid $plain -pady 4 -row 0 -column 1 -sticky w
grid [ttk::label $buttonFrame.optionsLabel -text "Pop-up Button:"]\
    -row 1 -column 0 -padx 4 -sticky e
grid $options  -pady 4 -row 1 -column 1 -sticky w
grid [ttk::label $buttonFrame.checkLabel -text "Check Button:"]\
    -row 2 -column 0 -padx 4 -sticky e
grid $check    -pady 4 -row 2 -column 1 -sticky w
grid [ttk::label $buttonFrame.radioLabel -text "Radio Buttons:"]\
    -row 3 -column 0 -padx 4 -sticky e
grid $radio    -pady 4 -row 3 -column 1 -sticky w
grid [ttk::label $buttonFrame.triangleLabel -text "Disclosure Triangle:"]\
    -row 4 -column 0 -padx 4 -sticky e
grid $triangle -pady 4 -row 4 -column 1 -sticky w
grid [ttk::label $buttonFrame.disclosureLabel -text "Disclosure Button:"]\
    -row 5 -column 0 -padx 4 -sticky e
grid $disclosure -row 5 -column 1 -sticky w
grid [ttk::label $buttonFrame.imageLabel -text "Image Buttons:"]\
    -row 7 -column 0 -padx 4 -sticky e
grid $bonjour -pady 4 -row 6 -rowspan 4 -column 1 -sticky w
grid $feather -padx 10 -pady 4 -row 6 -rowspan 4 -column 2
grid [ttk::label $buttonFrame.gradentLabel -text "Gradient Buttons:"]\
-row 10 -column 0 -padx 4 -sticky e
grid $gradient -pady 4 -row 10 -column 1 -sticky w
grid [ttk::label $buttonFrame.helpLabel -text "Help Button:"]\
-row 11 -column 0 -padx 4 -sticky e
grid $help -row 11 -column 1 -sticky w

#ttk::button .f.b1 -style Toolbutton -image action
#pack $buttonFrame

# Entries Frame
set entryFrame [ttk::frame $w.notebook.entries -padding {0 30 80 0}]
grid columnconfigure $entryFrame 0 -minsize 200
$w.notebook add $entryFrame -text "Entries"

set textfield [ttk::entry $entryFrame.text -width 17]
set searchfield [ttk::entry $entryFrame.search -width 1]
set combo [ttk::combobox $entryFrame.combo -width 1 -textvariable comboVar \
	   -values {"Item 1" "Item 2" "Item 3"}]
set stepper [ttk::spinbox $entryFrame.stepper -width 1 -textvariable stepVar \
		 -from 99000 -to 101000 -increment 1]
set stepVar 100000
searchFocusOut $searchfield
bind $searchfield <FocusIn> {searchFocusIn %W}
bind $searchfield <FocusOut> {searchFocusOut %W}

grid [ttk::label $entryFrame.l0 -text "Text Field"] -row 0 -column 0 -padx 20 -sticky e
grid $textfield -sticky ew -row 0 -column 1 -pady 13
grid [ttk::label $entryFrame.l1 -text "Search Field"] -row 1 -column 0 -padx 20 -sticky e
grid $searchfield -sticky ew -row 1 -column 1 -pady 13
grid [ttk::label $entryFrame.l2 -text "Combo Box"] -row 2 -column 0 -padx 20 -sticky e
grid $combo -sticky ew -row 2 -column 1 -pady 13
grid [ttk::label $entryFrame.l3 -text "Stepper"] -row 3 -column 0 -padx 20 -sticky e
grid $stepper -sticky ew -row 3 -column 1 -pady 13

#Scales Frame
set scaleFrame [ttk::frame $w.notebook.scales -padding {0 40 0 80}]
$w.notebook add $scaleFrame -text "Scales"

variable topVar 50
set topSlider [ttk::scale $scaleFrame.topSlider -from 0 -to 100 \
		   -length 280 -variable topVar]
set topProgress [ttk::progressbar $scaleFrame.topProgress \
		     -maximum 100 -variable topVar]

variable bottomVar 50
set bottomSlider [ttk::scale $scaleFrame.bottomSlider -from 0 -to 100 \
		      -length 280 -variable bottomVar]
$bottomSlider state alternate
set bottomProgress [ttk::progressbar $scaleFrame.bottomProgress \
		    -maximum 100 -variable bottomVar]


grid $topSlider -padx 80 -pady 12 -sticky ew -row 0 -column 0 -columnspan 2
grid $topProgress -padx 120 -pady 15 -sticky ew -row 1 -column 0 -columnspan 2
grid [ttk::frame $scaleFrame.spacer] -row 2 -column 0 -columnspan 2 -pady 32

grid $bottomSlider -padx 80 -sticky new -row 3 -column 0 -columnspan 2
grid [ttk::label $scaleFrame.low -text Low -padding {70 0 0 0}] \
    -row 4 -column 0 -sticky sw
grid [ttk::label $scaleFrame.high -text High -padding {0 0 70 0}] \
    -row 4 -column 1 -sticky se
grid $bottomProgress -padx 120 -pady 15 -sticky ew -row 5 -column 0 -columnspan 2

#Appearance Frame
set appearanceFrame [ttk::frame $w.notebook.appearance -padding {0 40 0 80}]
grid [ttk::label $w.notebook.appearance.info -justify left -padding {0 20 0 40}\
	  -text "Use the image buttons below to view this demo in light or dark mode."] \
    -row 0 -column 0 -columnspan 3
set light [ttk::button $appearanceFrame.light -style ImageButton -text Light \
	       -image {field pressed field1 selected field2} \
	       -command "beLight $appearanceFrame $w"]
grid columnconfigure $appearanceFrame 1 -minsize 10
grid $light -row 1 -column 0 -sticky e
set dark [ttk::button $appearanceFrame.dark -style ImageButton -text Dark \
	      -image {starry pressed starry1 selected starry2} \
	      -command "beDark $appearanceFrame $w"]
grid $dark -row 1 -column 2 -sticky w
if { [wm attributes $w -isdark] } {
    $dark state selected
} else {
    $light state selected
}
proc beLight {f w} {
    wm attributes $w -appearance aqua
    $f.dark state !selected
    $f.light state selected
    after 10 $f.light state !hover
}

proc beDark {f w} {
    wm attributes $w -appearance darkaqua
    $f.light state !selected
    $f.dark state selected
    after 10 $f.dark state !hover
}
$w.notebook add $appearanceFrame -text "Appearance"

## See Code / Dismiss
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x

## Notebook
pack $w.notebook -side bottom -fill both -expand 1 -padx 16 -pady 16

Deleted library/demos/mac_tabs.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76












































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# mac_tabs.tcl --
#
# This demonstration script creates three tabbable windows and allows the
# wm attributes tabbingid and tabbingmode to be manipulated for the third
# window, to demonstrate the effects of those attributes.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
catch {font create giant -family {Times New Roman} -size 64}
set w .mac_tabs
catch {destroy $w}
toplevel $w
wm title $w "Tabbed Windows in Aqua"
wm iconname $w "mac_tabs"
positionWindow $w
set suffix 0
set winlist {}
##

## See Code / Dismiss
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x
##
set info "\
This demo shows 3 toplevels, A, B, and C.  \
Each of these has tabbingmode set to preferred. \
The tabbingid of Window A is groupA, the \
tabbingid of Window B is groupB and the tabbingid \
of Window C is groupC.  Use the menubuttons below \
to see the effect of changing the tabbingid and \
tabbingmode attributes for Window C. \
"
pack [message $w.info -text $info -width 300]
wm geometry $w +450+350

ttk::frame $w.f
menu $w.idmenu -tearoff 0
foreach id {groupA groupB groupC} {
    $w.idmenu add command -label $id \
	-command [list wm attributes $w.c -tabbingid $id]
}
menu $w.modemenu -tearoff 0
foreach mode {auto preferred disallowed} {
    $w.modemenu add command -label $mode \
	-command [list wm attributes $w.c -tabbingmode $mode]
}
ttk::menubutton $w.f.idbutton -menu $w.idmenu -text "tabbingid"\
    -direction below
grid $w.f.idbutton -row 0 -column 0
ttk::menubutton $w.f.modebutton -menu $w.modemenu -text "tabbingmode"\
    -direction below
grid $w.f.modebutton -row 1 -column 0
pack $w.f

wm attributes $w.a -tabbingid groupA
wm attributes $w.a -tabbingmode preferred
toplevel $w.a
wm geometry $w.a +50+100
wm title $w.a "Window A"
pack [ttk::label $w.a.l -text A -font giant] -padx 100 -pady 30

wm attributes $w.b -tabbingid groupB
wm attributes $w.b -tabbingmode preferred
toplevel $w.b
wm geometry $w.b +400+100
wm title $w.b "Window B"
pack [ttk::label $w.b.l -text B -font giant] -padx 100 -pady 30

wm attributes $w.c -tabbingid groupC
wm attributes $w.c -tabbingmode preferred
toplevel $w.c
wm geometry $w.c +750+100
wm title $w.c "Window C"
pack [ttk::label $w.c.l -text C -font giant] -padx 100 -pady 30

Deleted library/demos/mac_wm.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227



































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# mac_window_styles.tcl --
#
# This demonstration script creates a toplevel window containing a notebook
# whose pages provide examples of the various mac-specific widgets that are
# provided via special values for the -style option.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk

set w .mac_wm
catch {destroy $w}
toplevel $w
wm title $w "Tk Aqua Window Styles"
wm iconname $w "mac_wm"
positionWindow $w
set suffix 0
set winlist {}
##

## See Code / Dismiss
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x

proc launch {name windowInfo class} {
    if {[winfo exists $name]} {
	wm deiconify $name
	focus -force $name
	return
    }
    wm attributes $name -class $class; toplevel $name
    wm title $name $class
    set f $name.f
    ttk::frame $f
    set t $f.t
    text $t -background systemWindowBackgroundColor \
	-highlightcolor systemWindowBackgroundColor \
	-font systemDefaultFont\
	-wrap word -width 50 -height 6
    $t insert insert $windowInfo
    $t configure -state disabled
    grid columnconfigure $f 0 -weight 1
    grid $t -row 0 -column 0 -columnspan 2 -sticky NSEW
    ttk::labelframe $f.stylemask -text "styleMask bits"
    # titled
    if {$class == "nswindow"} {
       ttk::checkbutton $f.stylemask.titled -text titled -variable $name.titled \
          -command [list setbit $name $f.stylemask.titled titled]
       $f.stylemask.titled state selected
       grid $f.stylemask.titled -row 0 -column 0 -sticky w
    }
    # closable
    ttk::checkbutton $f.stylemask.closable -text closable -variable $name.closable \
        -command [list setbit $name $f.stylemask.closable closable]
    $f.stylemask.closable state selected
    grid $f.stylemask.closable -row 1 -column 0 -sticky w
    # miniaturizableable
    ttk::checkbutton $f.stylemask.miniaturizable -text miniaturizable \
	-variable $name.miniaturizable \
        -command [list setbit $name $f.stylemask.miniaturizable miniaturizable]
    if {$class == "nswindow"} {
        $f.stylemask.miniaturizable state selected
    } else {
        $f.stylemask.miniaturizable state !alternate
    }
    grid $f.stylemask.miniaturizable -row 2 -column 0 -sticky w
    # resizable
    ttk::checkbutton $f.stylemask.resizable -text resizable -variable $name.resizable \
	-command [list setbit $name $f.stylemask.resizable resizable]
    $f.stylemask.resizable state selected
    grid $f.stylemask.resizable -row 3 -column 0 -sticky w
    # docmodal
    ttk::checkbutton $f.stylemask.docmodal -text docmodal -variable $name.docmodal \
	-command [list setbit $name $f.stylemask.docmodal docmodal]
    $f.stylemask.docmodal state !alternate
    grid $f.stylemask.docmodal -row 4 -column 0 -sticky w

    grid $f.stylemask -row 1 -column 0
    pack $name.f -side bottom -fill both -expand 1 -padx 16 -pady 16
}

set info "The command wm attributes window -stylemask ?bitnames? can \
be used to modify bits in the stylemask property of the NSWindow or \
NSPanel underlying a Tk Window.  Changing these bits causes the \
style of the window to change.  This demo allows you to see the \
effects of changing the bits.  (Note that buttons in the title bar \
can also be enabled or disabled with the ::tk::unsupported::MacWindowStyle \
command.)"

set panelInfo "A toplevel based on an NSPanel has a narrower title bar\
than one based on an NSWindow.  In addition the panel remains above all\
windows on the screen, regardless of which app is active. These are\
intended to be used as modal windows."

set windowInfo "This is a standard Apple document window, based on an\
NSWindow.  It has a larger title bar and behaves normally with respect\
to other windows from the same or another app."

## background frame
set f $w.f
ttk::frame $f
set t $f.t
text $t -background systemWindowBackgroundColor \
    -highlightcolor systemWindowBackgroundColor \
    -font systemDefaultFont\
    -wrap word -width 50 -height 8
$t insert insert $info
$t configure -state disabled
grid columnconfigure $f 0 -weight 1
grid $t -row 0 -column 0 -columnspan 2 -sticky NSEW
ttk::labelframe $f.stylemask -text "styleMask"
grid $f.stylemask -row 1 -column 0
grid [ttk::button $f.wbw -text "Open an NSWindow" -width 20 \
	  -command [list launch .nswindow $windowInfo nswindow]] -row 2 -column 0
grid [ttk::button $f.wbp -text "Open an NSPanel" -width 20 \
	  -command [list launch .nspanel $panelInfo nspanel]] -row 3 -column 0
grid [ttk::button $f.wbm -text "Open a modern window" -width 20 \
	  -command launchModernWindow] -row 4 -column 0
pack $w.f -side bottom -fill both -expand 1 -padx 16 -pady 16

proc setbit {win cb bitname} {
    set state [$cb instate selected]
    set bits [wm attributes $win -stylemask]
    set index [lsearch $bits $bitname]
    if {$index >= 0 && !$state} {
        set bits [lreplace $bits $index $index]
    }
    if {$index < 0 && $state} {
        lappend bits $bitname
    }
    wm attributes $win -stylemask $bits
}

set aboutText \
"Most of the apps which ship with a contemporary version of macOS \
feature a window similar to this one, with a left sidebar that \
allows selecting the content to be shown on the right hand side of \
the window.  These windows do not have a (visible) titlebar.\
\n\nApps that use such windows include the Finder and the App Store as \
well as Notes, Messages, Books, Maps and many others.\
\n\nTo create a window like this one in Tk simply set the fullsizecontent bit \
in the stylemask. For example:\n\n"

set aboutCode \
"wm attributes .t -stylemask {titled \\\
\nfullsizecontent closable miniaturizable \\\
\nresizable}\n\n"

set detailsText \
"(1) In the Apple API, setting the fullsizecontent bit in the stylemask \
only allows content to be drawn in the part of the window covered by \
the titlebar.  In order for that content to be visible the title bar \
must be transparent.  Since it would be pointless to draw content under \
an opaque title bar, Tk makes the title bar transparent whenever the \
fullsizecontent bit is set.\

\n\n\(2) Each radio button in the sidebar is a standard ttk::radiobutton \
but created with a special value for its -style option.  The value of the \
-style option used to create these buttons is SidebarButton.\n"

set whichPage 1
trace add variable whichPage write "flipPage whichPage"
proc flipPage {varname args} {
    global whichPage
    set newpage [set $varname]
    grid remove [grid content .mod.right -row 0 -column 0]
    switch $newpage\
	1 {grid .mod.right.about -padx 30 -pady 30 -row 0 -column 0 -sticky nsew}\
	2 {grid .mod.right.details -padx 30 -pady 30 -row 0 -column 0 -sticky nsew}
    update idletasks
}

proc launchModernWindow {} {
    global whichPage
    global aboutText
    global aboutCode
    global detailsText
    if {[winfo exists .mod]} {
	wm deiconify .mod
	focus -force .mod
	return
    }
    toplevel .mod
    wm title .mod {}
    wm attributes .mod -stylemask {titled fullsizecontent closable \
				       miniaturizable resizable}
    .mod configure -background white
    grid columnconfigure .mod 0 -weight 0
    grid columnconfigure .mod 1 -weight 1
    grid rowconfigure .mod 0 -weight 1
    frame .mod.left -width 220 -height 400 -background systemWindowBackgroundColor
    catch {
	font create leftFont -family .AppleSystemUIFont -size 11
        font create rightFont -family .AppleSystemUIFont -size 16
        font create codeFont -family Courier -size 16
    }
    grid [ttk::label .mod.left.spacer -padding {220 30 0 0}] -row 0 -column 0
    grid [ttk::radiobutton .mod.left.about -text About -style SidebarButton \
	      -variable whichPage -value 1] \
	-row 1 -column 0 -sticky nsew -padx 14
    grid [ttk::radiobutton .mod.left.details -text Details -style SidebarButton \
	-variable whichPage -value 2] \
	-row 2 -column 0 -sticky nsew -padx 14
    grid .mod.left -row 0 -column 0 -sticky nsew
    frame .mod.right -width 500 -background systemTextBackgroundColor
    grid rowconfigure .mod.right 0 -weight 0
    text .mod.right.about -highlightcolor systemTextBackgroundColor \
	-background systemTextBackgroundColor -font rightFont \
	-highlightthickness 0 -wrap word -width 40
    .mod.right.about tag configure code -font codeFont
    .mod.right.about insert end $aboutText
    .mod.right.about insert end $aboutCode code
    .mod.right.about configure -state disabled

    text .mod.right.details -highlightcolor systemTextBackgroundColor \
	-background systemTextBackgroundColor -font rightFont\
	-highlightthickness 0 -wrap word -width 40
    .mod.right.details insert end $detailsText
    .mod.right.details configure -state disabled

    grid .mod.right.about -padx 30 -pady 30 -row 0 -column 0 -sticky nsew
    grid .mod.right -row 0 -column 1 -sticky nsew
    wm geometry .mod 800x500
    update idletasks
}

Changes to library/demos/mclist.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14

15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53

54
55
56
57
58
59

60
61
62
63
64
65
66

67
68
69

70
71
72
73
74
75
76


77
78
79
80
81
82
83
84
85
86
87
1
2
3
4
5
6
7
8
9

10
11
12
13

14
15
16
17
18
19
20
21
22
23

24



25
26
27
28
29
30
31
32
33
34
35
36







37







38






39







40



41







42
43




44
45
46
47
48
49
50









-
+



-
+









-
+
-
-
-












-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-







# mclist.tcl --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget configured as a multi-column listbox.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .mclist
catch {destroy $w}
toplevel $w -class MCList
toplevel $w
wm title $w "Multi-Column List"
wm iconname $w "mclist"
positionWindow $w

## Explanatory text
ttk::label $w.msg -font $font -wraplength 4i -justify left -anchor n -padding {10 2 10 6} -text "Ttk is the new Tk themed widget set. One of the widgets it includes is a tree widget, which can be configured to display multiple columns of informational data without displaying the tree itself. This is a simple way to build a listbox that has multiple columns. Clicking on the heading for a column will sort the data by that column. You can also change the width of the columns by dragging the boundary between them."
pack $w.msg -fill x

## See Code / Dismiss
pack [addSeeDismiss $w.seeDismiss $w {} {
pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
    ttk::checkbutton $w.seeDismiss.cb1 -text Grid -variable mclistGrid -command tglGrid
}] -side bottom -fill x


ttk::frame $w.container
ttk::treeview $w.tree -columns {country capital currency} -show headings \
    -yscroll "$w.vsb set" -xscroll "$w.hsb set"
ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
pack $w.container -fill both -expand 1
grid $w.tree $w.vsb -in $w.container -sticky nsew
grid $w.hsb         -in $w.container -sticky nsew
grid column $w.container 0 -weight 1
grid row    $w.container 0 -weight 1

set upArrowData {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="4" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="m4 4 4-4 4 4z" fill="#000000"/>
    </svg>
}

image create photo upArrow -data {
set downArrowData {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="4" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="m4 0 4 4 4-4z" fill="#000000"/>
    </svg>
}

    R0lGODlhDgAOAJEAANnZ2YCAgPz8/P///yH5BAEAAAAALAAAAAAOAA4AAAImhI+
proc createArrowImages {} {
    set fgColor [ttk::style lookup . -foreground {} black]
    lassign [winfo rgb . $fgColor] r g b
    set fgColor [format "#%02x%02x%02x" \
	    [expr {$r >> 8}] [expr {$g >> 8}] [expr {$b >> 8}]]

    py+1LIsJHiBAh+BgmiEAJQITgW6DgUQIAECH4JN8IPqYuNxUAOw==}
    foreach dir {up down} {
	upvar ${dir}ArrowData imgData
	set idx1 [string first "#000000" $imgData]
	set idx2 [expr {$idx1 + 6}]
	set data [string replace $imgData $idx1 $idx2 $fgColor]

	image create photo ${dir}Arrow -format $::tk::svgFmt -data $data]
image create photo downArrow -data {
    }
}

    R0lGODlhDgAOAJEAANnZ2YCAgPz8/P///yH5BAEAAAAALAAAAAAOAA4AAAInhI+
createArrowImages
foreach event {<<ThemeChanged>> <<LightAqua>> <<DarkAqua>>} {
    bind MCList $event { createArrowImages }
}
unset event

image create photo noArrow -format $tk::svgFmt -data {
    py+1I4ocQ/IgDEYIPgYJICUCE4F+YIBolEoKPEJKZmVJK6ZACADs=}
image create photo noArrow -height 14 -width 14
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="4" version="1.1" xmlns="http://www.w3.org/2000/svg">
    </svg>
}

## The data we're going to insert
set data {
    Argentina		{Buenos Aires}		ARS
    Australia		Canberra		AUD
    Brazil		Brazilia		BRL
    Canada		Ottawa			CAD
95
96
97
98
99
100
101
102

103
104
105
106
107



108
109

110
111
112
113
114
115
116
58
59
60
61
62
63
64

65

66
67
68

69
70
71
72

73
74
75
76
77
78
79
80







-
+
-



-
+
+
+

-
+







    Russia		Moscow			RUB
    {South Africa}	Pretoria		ZAR
    {United Kingdom}	London			GBP
    {United States}	{Washington, D.C.}	USD
}

## Code to insert the data nicely
set font [ttk::style lookup Heading -font {} TkDefaultFont]
set font [ttk::style lookup Heading -font]
set morePx [expr {[image width noArrow] + round(4 * $tk::scalingPct / 100.0)}]
foreach col {country capital currency} name {Country Capital Currency} {
    $w.tree heading $col -text $name -image noArrow -anchor w \
	-command [list SortBy $w.tree $col 0]
    $w.tree column $col -width [expr {[font measure $font $name] + $morePx}]
    $w.tree column $col -width [expr {
	[font measure $font $name] + [image width noArrow] + 5
    }]
}
set font [ttk::style lookup Treeview -font {} TkDefaultFont]
set font [ttk::style lookup Treeview -font]
foreach {country capital currency} $data {
    $w.tree insert {} end -values [list $country $capital $currency]
    foreach col {country capital currency} {
	set len [font measure $font "[set $col]  "]
	if {[$w.tree column $col -width] < $len} {
	    $w.tree column $col -width $len
	}
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
113
114
115
116
117
118
119






















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    if {[ttk::style theme use] eq "aqua"} {
	# Aqua theme displays native sort arrows when user1 state is set
	$tree heading $col state "user1"
    } else {
	$tree heading $col -image [expr {$direction?"upArrow":"downArrow"}]
    }
}

set mclistGrid 0
proc tglGrid {} {
    if {$::mclistGrid} {
        .mclist.tree configure -stripe 1
        foreach col [.mclist.tree cget -columns] {
            .mclist.tree column $col -separator 1
        }
    } else {
        .mclist.tree configure -stripe 0
        foreach col [.mclist.tree cget -columns] {
            .mclist.tree column $col -separator 0
        }
    }
}

Changes to library/demos/menu.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28









-
+










+







# menu.tcl --
#
# This demonstration script creates a window with a bunch of menus
# and cascaded menus using menubars.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .menu
catch {destroy $w}
toplevel $w
wm title $w "Menu Demonstration"
wm iconname $w "menu"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left
if {[tk windowingsystem] eq "aqua"} {
    catch {set origUseCustomMDEF $::tk::mac::useCustomMDEF; set ::tk::mac::useCustomMDEF 1}
    $w.msg configure -text "This window has a menubar with cascaded menus.  You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by selecting the first item in the menu."
} else {
    $w.msg configure -text "This window contains a menubar with cascaded menus.  You can post a menu from the keyboard by typing Alt+x, where \"x\" is the character underlined on the menu.  You can then traverse among the menus using the arrow keys.  When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character.  If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu."
}
pack $w.msg -side top

set menustatus "    "
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65

66
67
68
69
70
71
72
52
53
54
55
56
57
58

59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+






-
+








set m $w.menu.basic
$w.menu add cascade -label "Basic" -menu $m -underline 0
menu $m -tearoff 0
$m add command -label "Long entry that does nothing"
if {[tk windowingsystem] eq "aqua"} {
    set modifier Command
} elseif {[tk windowingsystem] eq "win32"} {
} elseif {[tk windowingsystem] == "win32"} {
    set modifier Control
} else {
    set modifier Meta
}
foreach i {A B C D E F} {
    $m add command -label "Print letter \"$i\"" -underline 14 \
	    -accelerator $modifier+$i -command "puts $i"
	    -accelerator Meta+$i -command "puts $i" -accelerator $modifier+$i
    bind $w <$modifier-[string tolower $i]> "puts $i"
}

set m $w.menu.cascade
$w.menu add cascade -label "Cascades" -menu $m -underline 0
menu $m -tearoff 0
$m add command -label "Print hello" \
109
110
111
112
113
114
115
116

117
118
119
120
121

122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171


172
173
174
175
176
177
178
179
180
181
182
183
184


110
111
112
113
114
115
116

117


118
119

120
121
122
123
124
125
126
127
128
129
130
131

132
133
134


135
136
137
138
139
140
141







142
143
144




145













146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161







-
+
-
-


-
+











-
+


-
-







-
-
-
-
-
-
-



-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-












+
+
$m invoke 1
$m invoke 7

set m $w.menu.icon
$w.menu add cascade -label "Icons" -menu $m -underline 0
menu $m -tearoff 0
# Main widget program sets variable tk_demoDirectory
image create photo lilearth -file [file join $tk_demoDirectory \
$m add command -bitmap @[file join $tk_demoDirectory images pattern.xbm] \
images earthmenu.png]
$m add command -image lilearth \
    -hidemargin 1 -command [list \
	tk_dialog $w.pattern {Bitmap Menu Entry} \
		"The menu entry you invoked displays a photoimage rather than\
		"The menu entry you invoked displays a bitmap rather than\
		a text string.  Other than this, it is just like any other\
		menu entry." {} 0 OK ]
foreach i {info questhead error} {
    $m add command -bitmap $i -hidemargin 1 -command [list \
	    puts "You invoked the $i bitmap" ]
}
$m entryconfigure 2 -columnbreak 1

set m $w.menu.more
$w.menu add cascade -label "More" -menu $m -underline 0
menu $m -tearoff 0
foreach i {{An entry} {Another entry} {Does nothing} {Does almost nothing} {Does almost nothing also} {Make life meaningful}} {
foreach i {{An entry} {Another entry} {Does nothing} {Does almost nothing} {Make life meaningful}} {
    $m add command -label $i -command [list puts "You invoked \"$i\""]
}
set emojiLabel [encoding convertfrom utf-8 "\xF0\x9F\x98\x8D Make friends"]
$m add command -label $emojiLabel -command [list puts "Menu labels can include non-BMP characters."]
$m entryconfigure "Does almost nothing" -bitmap questhead -compound left \
	-command [list \
	tk_dialog $w.compound {Compound Menu Entry} \
		"The menu entry you invoked displays both a bitmap and a\
		text string.  Other than this, it is just like any other\
		menu entry." {} 0 OK ]

$m entryconfigure "Does almost nothing also" -image lilearth -compound left \
	-command [list \
	tk_dialog $w.compound {Compound Menu Entry} \
		"The menu entry you invoked displays both a image and a\
		text string.  Other than this, it is just like any other\
		menu entry." {} 0 OK ]

set m $w.menu.colors
$w.menu add cascade -label "Colors" -menu $m -underline 1
menu $m -tearoff 1
if {[tk windowingsystem] eq "aqua"} {
    # Aqua ignores the -background and -foreground options, but a compound
    # button can be used for selecting colors.
    foreach i {red orange yellow green blue} {
foreach i {red orange yellow green blue} {
	image create photo image_$i -height 16 -width 16
	image_$i put black -to 0 0 16 1
	image_$i put black -to 0 1 1 16
	image_$i put black -to 0 15 16 16
	image_$i put black -to 15 1 16 16
	image_$i put $i -to 1 1 15 15
	$m add command -label $i -image image_$i -compound left -command [list \
	puts "You invoked \"$i\"" ]
    }
} else {
    foreach i {red orange yellow green blue} {
	$m add command -label $i -background $i -command [list \
	puts "You invoked \"$i\"" ]
    $m add command -label $i -background $i -command [list \
	    puts "You invoked \"$i\"" ]
    }
}

$w configure -menu $w.menu

bind Menu <<MenuSelect>> {
    global $menustatus
    if {[catch {%W entrycget active -label} label]} {
	set label "    "
    }
    set menustatus $label
    update idletasks
}

if {[tk windowingsystem] eq "aqua"} {catch {set ::tk::mac::useCustomMDEF $origUseCustomMDEF}}

Changes to library/demos/menubu.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28









-
+










+







# menubu.tcl --
#
# This demonstration script creates a window with a bunch of menus
# and cascaded menus using menubuttons.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .menubu
catch {destroy $w}
toplevel $w
wm title $w "Menu Button Demonstration"
wm iconname $w "menubutton"
positionWindow $w

frame $w.body
pack $w.body -expand 1 -fill both
if {[tk windowingsystem] eq "aqua"} {catch {set origUseCustomMDEF $::tk::mac::useCustomMDEF; set ::tk::mac::useCustomMDEF 1}}

menubutton $w.body.below -text "Below" -underline 0 -direction below -menu $w.body.below.m -relief raised
menu $w.body.below.m -tearoff 0
$w.body.below.m add command -label "Below menu: first item" -command "puts \"You have selected the first item from the Below menu.\""
$w.body.below.m add command -label "Below menu: second item" -command "puts \"You have selected the second item from the Below menu.\""
grid $w.body.below -row 0 -column 1 -sticky n
menubutton $w.body.right -text "Right" -underline 0 -direction right -menu $w.body.right.m -relief raised
43
44
45
46
47
48
49
50
51


52
53

54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74






75
76
77
78
79
80
81






82
83
84
85
86
87
88
89
90



44
45
46
47
48
49
50


51
52
53

54
55

56
57
58
59
60
61
62
63
64



65
66






67
68
69
70
71
72
73






74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90







-
-
+
+

-
+

-
+








-
-
-


-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+








-
+
+
+
grid $w.body.above -row 2 -column 1 -sticky s

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

set body $w.body.center
label $body.label -wraplength 225p -font "Helvetica 14" -justify left -text "This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette."
pack $body.label -side top -padx 18p -pady 18p
label $body.label -wraplength 300 -font "Helvetica 14" -justify left -text "This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette."
pack $body.label -side top -padx 25 -pady 25
frame $body.buttons
pack $body.buttons -padx 18p -pady 18p
pack $body.buttons -padx 25 -pady 25
tk_optionMenu $body.buttons.options menubuttonoptions one two three
pack $body.buttons.options -side left -padx 18p -pady 18p
pack $body.buttons.options -side left -padx 25 -pady 25
set m [tk_optionMenu $body.buttons.colors paletteColor Black red4 DarkGreen NavyBlue gray75 Red Green Blue gray50 Yellow Cyan Magenta White Brown DarkSeaGreen DarkViolet]
if {[tk windowingsystem] eq "aqua"} {
    set topBorderColor Black
    set bottomBorderColor Black
} else {
    set topBorderColor gray50
    set bottomBorderColor gray75
}
set dim  [expr {round(16 * $tk::scalingPct / 100.0)}]
set dim1 [expr {$dim - 1}]
set dim2 [expr {$dim - 2}]
for {set i 0} {$i <= [$m index last]} {incr i} {
    set name [$m entrycget $i -label]
    image create photo image_$name -height $dim -width $dim
    image_$name put $topBorderColor -to 0 0 $dim 1
    image_$name put $topBorderColor -to 0 1 1 $dim
    image_$name put $bottomBorderColor -to 0 $dim1 $dim $dim
    image_$name put $bottomBorderColor -to $dim1 1 $dim $dim
    image_$name put $name -to 1 1 $dim1 $dim1
    image create photo image_$name -height 16 -width 16
    image_$name put $topBorderColor -to 0 0 16 1
    image_$name put $topBorderColor -to 0 1 1 16
    image_$name put $bottomBorderColor -to 0 15 16 16
    image_$name put $bottomBorderColor -to 15 1 16 16
    image_$name put $name -to 1 1 15 15

    image create photo image_${name}_s -height $dim -width $dim
    image_${name}_s put Black -to 0 0 $dim 2
    image_${name}_s put Black -to 0 2 2 $dim
    image_${name}_s put Black -to 2 $dim2 $dim $dim
    image_${name}_s put Black -to $dim2 2 $dim $dim2
    image_${name}_s put $name -to 2 2 $dim2 $dim2
    image create photo image_${name}_s -height 16 -width 16
    image_${name}_s put Black -to 0 0 16 2
    image_${name}_s put Black -to 0 2 2 16
    image_${name}_s put Black -to 2 14 16 16
    image_${name}_s put Black -to 14 2 16 14
    image_${name}_s put $name -to 2 2 14 14

    $m entryconfigure $i -image image_$name -selectimage image_${name}_s -hidemargin 1
}
$m configure -tearoff 1
foreach i {Black gray75 gray50 White} {
	$m entryconfigure $i -columnbreak 1
}

pack $body.buttons.colors -side left -padx 18p -pady 18p
pack $body.buttons.colors -side left -padx 25 -pady 25

if {[tk windowingsystem] eq "aqua"} {catch {set ::tk::mac::useCustomMDEF $origUseCustomMDEF}}

Changes to library/demos/msgbox.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# msgbox.tcl --
#
# This demonstration script creates message boxes of various type

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .msgbox
catch {destroy $w}
toplevel $w
wm title $w "Message Box Demonstration"
wm iconname $w "messagebox"
positionWindow $w
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62







-
+











-
+











pack $w.left.label -side top
pack $w.left.sep -side top -fill x -expand no

set msgboxIcon info
foreach i {error info question warning} {
    radiobutton $w.left.b$i -text $i -variable msgboxIcon \
	-relief flat -value $i -width 16 -anchor w
    pack $w.left.b$i  -side top -pady 1.5p -anchor w -fill x
    pack $w.left.b$i  -side top -pady 2 -anchor w -fill x
}

label $w.right.label -text "Type"
frame $w.right.sep -relief ridge -bd 1 -height 2
pack $w.right.label -side top
pack $w.right.sep -side top -fill x -expand no

set msgboxType ok
foreach t {abortretryignore ok okcancel retrycancel yesno yesnocancel} {
    radiobutton $w.right.$t -text $t -variable msgboxType \
	-relief flat -value $t -width 16 -anchor w
    pack $w.right.$t -side top -pady 1.5p -anchor w -fill x
    pack $w.right.$t -side top -pady 2 -anchor w -fill x
}

proc showMessageBox {w} {
    global msgboxIcon msgboxType
    set button [tk_messageBox -icon $msgboxIcon -type $msgboxType \
	-title Message -parent $w\
	-message "This is a \"$msgboxType\" type messagebox with the \"$msgboxIcon\" icon"]

    tk_messageBox -icon info -message "You have selected \"$button\"" -type ok\
	-parent $w
}

Changes to library/demos/nl.msg.

1
2

3
4
5
6
7
8
9
10
11

12
13

14
15

16
17
18
19
20
21
22
23
24
25
1

2
3
4
5
6
7
8
9
10
11
12
13

14


15
16


17
18
19
20
21
22
23

-
+









+

-
+
-
-
+

-
-







::msgcat::mcset nl "Widget Demonstration" "Demonstratie van widgets"
::msgcat::mcset nl "tkWidgetDemo"
::msgcat::mcset nl "tkWidgetDemo" "tkWidgetDemo"
::msgcat::mcset nl "&File"     "&Bestand"
::msgcat::mcset nl "About..."  "Info..."
::msgcat::mcset nl "&About..." "&Info..."
::msgcat::mcset nl "<F1>"      "<F1>"
::msgcat::mcset nl "&Quit"     "&Einde"
::msgcat::mcset nl "Meta+Q"    "Meta+E"		;# Displayed hotkey
::msgcat::mcset nl "Meta-q"    "Meta-e"		;# Actual binding sequence
::msgcat::mcset nl "Ctrl+Q"    "Ctrl+E"		;# Displayed hotkey
::msgcat::mcset nl "Control-q" "Control-e"	;# Actual binding sequence
::msgcat::mcset nl "Dismiss"   "Sluiten"
::msgcat::mcset nl "See Variables"    "Bekijk Variabelen"
::msgcat::mcset nl "Variable values"  "Waarden variabelen"
::msgcat::mcset nl "Variable Values"  "Waarden Variabelen"
::msgcat::mcset nl "Variable values:"  "Waarden variabelen"
::msgcat::mcset nl "OK"
::msgcat::mcset nl "OK"        "OK"
::msgcat::mcset nl "Run the \"%s\" sample program" "Start voorbeeld \"%s\""
::msgcat::mcset nl "Dismiss"   "Sluiten"
::msgcat::mcset nl "Rerun Demo" "Herstart Demo"	;# This is also button text!
::msgcat::mcset nl "Print Code" "Code Afdrukken"
::msgcat::mcset nl "Demo code: %s" "Code van Demo %s"
::msgcat::mcset nl "About Widget Demo" "Over deze demonstratie"
::msgcat::mcset nl "Tk widget demonstration" "Demonstratie van Tk widgets"
::msgcat::mcset nl "Copyright © %s"

::msgcat::mcset nl "Tk Widget Demonstrations" "Demonstratie van Tk widgets"
34
35
36
37
38
39
40

41
42
43
44
45
46
47

48
49
50
51
52
53
54
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54







+







+







::msgcat::mcset nl "appears, you can click the" \
    "Zodra het nieuwe venster verschijnt, kun je op de knop"
::msgcat::mcset nl "See Code"  "Bekijk Code"	;# This is also button text!
::msgcat::mcset nl "button to see the Tcl/Tk code that created the demonstration.  If" \
    "drukken om de achterliggende Tcl/Tk code te zien.  Als je dat wilt,"
::msgcat::mcset nl "you wish, you can edit the code and click the" \
    "kun je de code wijzigen en op de knop"
::msgcat::mcset nl "Rerun Demo" "Herstart Demo"	;# This is also button text!
::msgcat::mcset nl "button in the code window to reinvoke the demonstration with the" \
    "drukken in het codevenster om de demonstratie uit te voeren met de"
::msgcat::mcset nl "modified code." \
    "nieuwe code."

::msgcat::mcset nl "Labels, buttons, checkbuttons, and radiobuttons" \
    "Labels, knoppen, vinkjes/aankruishokjes en radioknoppen"

::msgcat::mcset nl "Labels (text and bitmaps)" "Labels (tekst en plaatjes)"
::msgcat::mcset nl "Labels and UNICODE text"   "Labels en tekst in UNICODE"
::msgcat::mcset nl "Buttons" "Buttons (drukknoppen)"
::msgcat::mcset nl "Check-buttons (select any of a group)" \
    "Check-buttons (een of meer uit een groep)"
::msgcat::mcset nl "Radio-buttons (select one of a group)" \
    "Radio-buttons (een van een groep)"
102
103
104
105
106
107
108

109
110
111
112

113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119







120
121
122
123
124
125









+




+




-
+
-
-
-
-
-
-
-






-
-
::msgcat::mcset nl "Scales" "Schaalverdelingen"
::msgcat::mcset nl "Horizontal scale"          "Horizontale schaal"
::msgcat::mcset nl "Vertical scale"          "Verticale schaal"

::msgcat::mcset nl "Paned Windows" "Vensters opgedeeld in stukken"
::msgcat::mcset nl "Horizontal paned window"   "Horizontaal gedeeld venster"
::msgcat::mcset nl "Vertical paned window"     "Verticaal gedeeld venster"

::msgcat::mcset nl "Menus" "Menu's"
::msgcat::mcset nl "Menus and cascades (sub-menus)" \
    "Menu's en cascades (submenu's)"
::msgcat::mcset nl "Menu-buttons" "Menu-buttons"

::msgcat::mcset nl "Common Dialogs" "Veel voorkomende dialoogvensters"
::msgcat::mcset nl "Message boxes"  "Mededeling (message box)"
::msgcat::mcset nl "File selection dialog"     "Selectie van bestanden"
::msgcat::mcset nl "Color picker"              "Kleurenpalet"
::msgcat::mcset nl "Font selection dialog"     "Selectie van fonts"

::msgcat::mcset nl "System tray icon and notification" "Systeemvakpictogram en melding"
::msgcat::mcset nl "Printing from canvas and text widgets" "Afdrukken van canvas en tekst widgets"
::msgcat::mcset nl "Animation" "Animaties"
::msgcat::mcset nl "Animated labels" "Geanimeerde labels"
::msgcat::mcset nl "Animated wave" "Geanimeerde golf"
::msgcat::mcset nl "Pendulum simulation" "Pendulum simulatie"
::msgcat::mcset nl "A celebration of Rube Goldberg" "Een viering van Rube Goldberg"
::msgcat::mcset nl "Miscellaneous"             "Diversen"
::msgcat::mcset nl "The built-in bitmaps"      "Ingebouwde plaatjes"
::msgcat::mcset nl "A dialog box with a local grab" \
    "Een dialoogvenster met een locale \"grab\""
::msgcat::mcset nl "A dialog box with a global grab" \
    "Een dialoogvenster met een globale \"grab\""
::msgcat::mcset nl "Window icons and badges" "Vensterpictogrammen en badges"

Changes to library/demos/paned1.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30


31
32

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28


29
30
31

32









-
+
















-
+

-
-
+
+

-
+
# paned1.tcl --
#
# This demonstration script creates a toplevel window containing
# a paned window that separates two windows horizontally.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .paned1
catch {destroy $w}
toplevel $w
wm title $w "Horizontal Paned Window Demonstration"
wm iconname $w "paned1"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "The sash between the two coloured windows below can be used to divide the area between them.  Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)"
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

panedwindow $w.pane
pack $w.pane -side top -expand yes -fill both -pady 1.5p -padx 2m
pack $w.pane -side top -expand yes -fill both -pady 2 -padx 2m

label $w.pane.left  -text "This is the\nleft side"  -fg black -bg yellow
label $w.pane.right -text "This is the\nright side" -fg black -bg cyan
label $w.pane.left  -text "This is the\nleft side"  -bg yellow
label $w.pane.right -text "This is the\nright side" -bg cyan

$w.pane add $w.pane.left $w.pane.right -stretch always
$w.pane add $w.pane.left $w.pane.right

Changes to library/demos/paned2.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35









-
+

















-
+







# paned2.tcl --
#
# This demonstration script creates a toplevel window containing
# a paned window that separates two windows vertically.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .paned2
catch {destroy $w}
toplevel $w
wm title $w "Vertical Paned Window Demonstration"
wm iconname $w "paned2"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "The sash between the two scrolled windows below can be used to divide the area between them.  Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)"
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

# Create the pane itself
panedwindow $w.pane -orient vertical
pack $w.pane -side top -expand yes -fill both -pady 1.5p -padx 2m
pack $w.pane -side top -expand yes -fill both -pady 2 -padx 2m

# The top window is a listbox with scrollbar
set paneList {
    {List of Tk Widgets}
    button
    canvas
    checkbutton
67
68
69
70
71
72
73
74

67
68
69
70
71
72
73

74







-
+
grid $f.text $f.yscr -sticky nsew
grid $f.xscr         -sticky nsew
grid columnconfigure $f 0 -weight 1
grid rowconfigure    $f 0 -weight 1
$f.text insert 1.0 "This is just a normal text widget"

# Now add our contents to the paned window
$w.pane add $w.pane.top $w.pane.bottom -stretch always
$w.pane add $w.pane.top $w.pane.bottom

Changes to library/demos/pendulum.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


30
31
32
33
34


35
36

37
38

39
40
41
42
43
44
45
46
47



48
49
50
51
52
53
54


55
56
57
58
59
60
61



62
63
64


65
66
67
68
69
70
71
72
73
74
75
76

77
78

79
80
81


82
83
84
85
86
87


88
89
90
91



92
93
94
95
96
97
98
99
100
101
102

103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138



139
140
141
142
143
144
145
146






147
148
149
150
151
152
153
154
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32


33
34
35

36
37

38
39
40
41
42
43
44



45
46
47
48
49
50
51
52


53
54
55
56
57
58



59
60
61



62
63



64
65
66
67
68
69
70
71

72


73
74


75
76
77
78
79
80


81
82
83



84
85
86
87
88
89
90
91
92
93
94



95
96

97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127



128
129
130
131
132






133
134
135
136
137
138

139
140
141
142
143
144
145









-
+

















-
-
+
+



-
-
+
+

-
+

-
+






-
-
-
+
+
+





-
-
+
+




-
-
-
+
+
+
-
-
-
+
+
-
-
-








-
+
-
-
+

-
-
+
+




-
-
+
+

-
-
-
+
+
+








-
-
-
+

-
+





-













-
+











-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
-







# pendulum.tcl --
#
# This demonstration illustrates how Tcl/Tk can be used to construct
# simulations of physical systems.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .pendulum
catch {destroy $w}
toplevel $w
wm title $w "Pendulum Animation Demonstration"
wm iconname $w "pendulum"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration shows how Tcl/Tk can be used to carry out animations that are linked to simulations of physical systems. In the left canvas is a graphical representation of the physical system itself, a simple pendulum, and in the right canvas is a graph of the phase space of the system, which is a plot of the angle (relative to the vertical) against the angular velocity. The pendulum bob may be repositioned by clicking and dragging anywhere on the left canvas."
pack $w.msg

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

# Create some structural widgets
pack [panedwindow $w.p] -fill both -expand 1
$w.p add [labelframe $w.p.l1 -text "Pendulum Simulation"] -stretch always
$w.p add [labelframe $w.p.l2 -text "Phase Space"] -stretch always
$w.p add [labelframe $w.p.l1 -text "Pendulum Simulation"]
$w.p add [labelframe $w.p.l2 -text "Phase Space"]

# Create the canvas containing the graphical representation of the
# simulated system.
canvas $w.c -width 240p -height 150p -background white -bd 1.5p -relief sunken
$w.c create text 3p 3p -anchor nw -text "Click to Adjust Bob Start Position"
canvas $w.c -width 320 -height 200 -background white -bd 2 -relief sunken
$w.c create text 5 5 -anchor nw -text "Click to Adjust Bob Start Position"
# Coordinates of these items don't matter; they will be set properly below
$w.c create line 0 25 320 25   -tags plate -fill grey50 -width 1.5p
$w.c create line 0 25 320 25   -tags plate -fill grey50 -width 2
$w.c create oval 155 20 165 30 -tags pivot -fill grey50 -outline {}
$w.c create line 1 1 1 1       -tags rod   -fill black  -width 2.25p
$w.c create line 1 1 1 1       -tags rod   -fill black  -width 3
$w.c create oval 1 1 2 2       -tags bob   -fill yellow -outline black
pack $w.c -in $w.p.l1 -fill both -expand true

# Create the canvas containing the phase space graph; this consists of
# a line that gets gradually paler as it ages, which is an extremely
# effective visual trick.
canvas $w.k -width 240p -height 150p -background white -bd 1.5p -relief sunken
$w.k create line 120p 150p 120p 0 -fill grey75 -arrow last -tags y_axis
$w.k create line 0 75p 240p 75p -fill grey75 -arrow last -tags x_axis
canvas $w.k -width 320 -height 200 -background white -bd 2 -relief sunken
$w.k create line 160 200 160 0 -fill grey75 -arrow last -tags y_axis
$w.k create line 0 100 320 100 -fill grey75 -arrow last -tags x_axis
for {set i 90} {$i>=0} {incr i -10} {
    # Coordinates of these items don't matter; they will be set properly below
    $w.k create line 0 0 1 1 -smooth true -tags graph$i -fill grey$i
}

$w.k create text 0 0 -anchor ne -text "θ"  -tags label_theta
$w.k create text 0 0 -anchor ne -text "δθ" -tags label_dtheta
$w.k create text 0 0 -anchor ne -text "\u03b8" -tags label_theta
$w.k create text 0 0 -anchor ne -text "\u03b4\u03b8" -tags label_dtheta
pack $w.k -in $w.p.l2 -fill both -expand true

# Initialize some variables
set points {}
set Theta  45.0
set dTheta  0.0
set pi      3.1415926535897933
set Theta   45.0
set dTheta   0.0
set pi       3.1415926535897933
set tkScl  [tk scaling]
set length [expr {round(111*$tkScl)}]			;# 111p -> pixels
set xHome  [expr {round(120*$tkScl)}]			;# 120p -> pixels
set length 150
set home   160
set yHome  [expr {round( 18*$tkScl)}]			;#  18p -> pixels
set rBob   [expr {round( 12*$tkScl)}]			;#  12p -> pixels
set rPivot [expr {round(  3*$tkScl)}]			;#   3p -> pixels

# This procedure makes the pendulum appear at the correct place on the
# canvas. If the additional arguments "at $x $y" are passed (the 'at'
# is really just syntactic sugar) instead of computing the position of
# the pendulum from the length of the pendulum rod and its angle, the
# length and angle are computed in reverse from the given location
# (which is taken to be the centre of the pendulum bob.)
proc showPendulum {canvas {at {}} {x {}} {y {}}} {
    global Theta dTheta pi length xHome yHome rBob
    global Theta dTheta pi length home

    if {$at eq "at" && ($x!=$xHome || $y!=$yHome)} {
    if {$at eq "at" && ($x!=$home || $y!=25)} {
	set dTheta 0.0
	set x2 [expr {$x - $xHome}]
	set y2 [expr {$y - $yHome}]
	set x2 [expr {$x - $home}]
	set y2 [expr {$y - 25}]
	set length [expr {hypot($x2, $y2)}]
	set Theta  [expr {atan2($x2, $y2) * 180/$pi}]
    } else {
	set angle [expr {$Theta * $pi/180}]
	set x [expr {$xHome + $length*sin($angle)}]
	set y [expr {$yHome + $length*cos($angle)}]
	set x [expr {$home + $length*sin($angle)}]
	set y [expr {25    + $length*cos($angle)}]
    }
    $canvas coords rod $xHome $yHome $x $y
    $canvas coords bob [expr {$x - $rBob}] [expr {$y - $rBob}] \
		       [expr {$x + $rBob}] [expr {$y + $rBob}]
    $canvas coords rod $home 25 $x $y
    $canvas coords bob \
	    [expr {$x-15}] [expr {$y-15}] [expr {$x+15}] [expr {$y+15}]
}
showPendulum $w.c

# Update the phase-space graph according to the current angle and the
# rate at which the angle is changing (the first derivative with
# respect to time.)
proc showPhase {canvas} {
    global Theta dTheta points psw psh
    set sclFactor [expr {$tk::scalingPct / 100.0}]

    lappend points [expr {$Theta + $psw}] [expr {-20*$sclFactor*$dTheta + $psh}]
    lappend points [expr {$Theta+$psw}] [expr {-20*$dTheta+$psh}]
    if {[llength $points] > 100} {
	set points [lrange $points end-99 end]
    	 set points [lrange $points end-99 end]
    }
    for {set i 0} {$i<100} {incr i 10} {
	set list [lrange $points end-[expr {$i-1}] end-[expr {$i-12}]]
	if {[llength $list] >= 4} {
	    $canvas coords graph$i $list
	    $canvas scale graph$i $psw $psh $sclFactor $sclFactor
	}
    }
}

# Set up some bindings on the canvases.  Note that when the user
# clicks we stop the animation until they release the mouse
# button. Also note that both canvases are sensitive to <Configure>
# events, which allows them to find out when they have been resized by
# the user.
bind $w.c <Destroy> {
    after cancel $animationCallbacks(pendulum)
    unset animationCallbacks(pendulum)
}
bind $w.c <Button-1> {
bind $w.c <1> {
    after cancel $animationCallbacks(pendulum)
    showPendulum %W at %x %y
}
bind $w.c <B1-Motion> {
    showPendulum %W at %x %y
}
bind $w.c <ButtonRelease-1> {
    showPendulum %W at %x %y
    set animationCallbacks(pendulum) [after 15 repeat [winfo toplevel %W]]
}
bind $w.c <Configure> {
    %W coords plate 0 18p %w 18p
    set xHome [expr {%w/2}]
    %W coords pivot [expr {$xHome - $rPivot}] 15p [expr {$xHome + $rPivot}] 21p
    %W coords plate 0 25 %w 25
    set home [expr %w/2]
    %W coords pivot [expr $home-5] 20 [expr $home+5] 30
}
bind $w.k <Configure> {
    set psh [expr {%h/2}]
    set psw [expr {%w/2}]
    %W coords x_axis	   1.5p $psh [expr {%w - round(1.5*$tkScl)}] $psh
    %W coords y_axis	   $psw [expr {%h - round(1.5*$tkScl)}] $psw 1.5p
    %W coords label_dtheta [expr {$psw - round(3*$tkScl)}] 4.5p
    %W coords label_theta  [expr {%w - round(4.5*$tkScl)}] \
    set psh [expr %h/2]
    set psw [expr %w/2]
    %W coords x_axis 2 $psh [expr %w-2] $psh
    %W coords y_axis $psw [expr %h-2] $psw 2
    %W coords label_dtheta [expr $psw-4] 6
    %W coords label_theta [expr %w-6] [expr $psh+4]
			   [expr {$psh + round(3*$tkScl)}]
}

# This procedure is the "business" part of the simulation that does
# simple numerical integration of the formula for a simple rotational
# pendulum.
proc recomputeAngle {} {
    global Theta dTheta pi length

Changes to library/demos/plot.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30

31
32
33
34



35
36
37
38
39



40
41
42
43
44



45
46
47
48

49
50
51
52
53




54
55
56
57
58
59
60



61
62
63
64
65
66
67
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29

30
31



32
33
34
35
36



37
38
39
40
41



42
43
44
45
46
47

48
49




50
51
52
53
54
55
56
57



58
59
60
61
62
63
64
65
66
67









-
+
















-
+


-
+

-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+



-
+

-
-
-
-
+
+
+
+




-
-
-
+
+
+







# plot.tcl --
#
# This demonstration script creates a canvas widget showing a 2-D
# plot with data points that can be dragged with the mouse.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .plot
catch {destroy $w}
toplevel $w
wm title $w "Plot Demonstration"
wm iconname $w "Plot"
positionWindow $w
set c $w.c

label $w.msg -font $font -wraplength 4i -justify left -text "This window displays a canvas widget containing a simple 2-dimensional plot.  You can doctor the data by dragging any of the points with mouse button 1."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

canvas $c -relief raised -width 337.5p -height 225p
canvas $c -relief raised -width 450 -height 300
pack $w.c -side top -fill x

set plotFont {Helvetica 16}
set plotFont {Helvetica 18}

$c create line 75p 187.5p 300p 187.5p -width 1.5p
$c create line 75p 187.5p 75p 37.5p -width 1.5p
$c create text 168.75p 15p -text "A Simple Plot" -font $plotFont -fill brown
$c create line 100 250 400 250 -width 2
$c create line 100 250 100 50 -width 2
$c create text 225 20 -text "A Simple Plot" -font $plotFont -fill brown

for {set i 0} {$i <= 10} {incr i} {
    set x [expr {75 + ($i*22.5)}]			;# in points
    $c create line ${x}p 187.5p ${x}p 183.75p -width 1.5p
    $c create text ${x}p 190.5p -text [expr {10*$i}] -anchor n -font $plotFont
    set x [expr {100 + ($i*30)}]
    $c create line $x 250 $x 245 -width 2
    $c create text $x 254 -text [expr {10*$i}] -anchor n -font $plotFont
}
for {set i 0} {$i <= 5} {incr i} {
    set y [expr {187.5 - ($i*30)}]			;# in points
    $c create line 75p ${y}p 78.75p ${y}p -width 1.5p
    $c create text 72p ${y}p -text [expr {$i*50}].0 -anchor e -font $plotFont
    set y [expr {250 - ($i*40)}]
    $c create line 100 $y 105 $y -width 2
    $c create text 96 $y -text [expr {$i*50}].0 -anchor e -font $plotFont
}

foreach point {
    {9 42} {15 70.5} {24.75 73.5} {24 90} {45.75 135} {56.25 120} {73.5 167.25}
    {12 56} {20 94} {33 98} {32 120} {61 180} {75 160} {98 223}
} {
    set x [expr {75 + (2.25*[lindex $point 0])}]	;# in points
    set y [expr {187.5 - (3*[lindex $point 1])/5}]	;# in points
    set item [$c create oval [expr {$x-4.5}]p [expr {$y-4.5}]p \
	    [expr {$x+4.5}]p [expr {$y+4.5}]p -width 0.75p -outline black \
    set x [expr {100 + (3*[lindex $point 0])}]
    set y [expr {250 - (4*[lindex $point 1])/5}]
    set item [$c create oval [expr {$x-6}] [expr {$y-6}] \
	    [expr {$x+6}] [expr {$y+6}] -width 1 -outline black \
	    -fill SkyBlue2]
    $c addtag point withtag $item
}

$c bind point <Enter> "$c itemconfig current -fill red"
$c bind point <Leave> "$c itemconfig current -fill SkyBlue2"
$c bind point <Button-1> "plotDown $c %x %y"
$c bind point <Any-Enter> "$c itemconfig current -fill red"
$c bind point <Any-Leave> "$c itemconfig current -fill SkyBlue2"
$c bind point <1> "plotDown $c %x %y"
$c bind point <ButtonRelease-1> "$c dtag selected"
bind $c <B1-Motion> "plotMove $c %x %y"

set plot(lastX) 0
set plot(lastY) 0

# plotDown --

Deleted library/demos/print.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90


























































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# print.tcl --
#
# This demonstration script showcases the tk print commands.
#

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

set w .print
destroy $w
toplevel $w
wm title $w "Printing Demonstration"
positionWindow $w

pack [label $w.l -text "This demonstration showcases
the tk print command. Clicking the buttons below
prints the data from the canvas and text widgets
using platform-native dialogs."] -side top

## See Code / Dismiss buttons
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x

frame $w.m

image create photo logo -data {
R0lGODlhMABLAPUAAP//////zP//mf//AP/MzP/Mmf/MAP+Zmf+ZZv+ZAMz//8zM/8zMzMyZzMyZ
mcyZZsyZAMxmZsxmM8xmAMwzM8wzAJnMzJmZzJmZmZlmmZlmZplmM5kzZpkzM5kzAGaZzGZmzGZm
mWYzZmYzMzNmzDNmmTMzmTMzZgAzmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH+BSAtZGwtACH5BAEKAAIALAAAAAAw
AEsAAAb+QIFwSCwahY9HRMI8Op/JJVNSqVqv2OvjyRU8slbIJGwYg60S5ZR6jRi/4ITBOhkYIOd8
dltEnAdmFQMJeoVXCEd/VnKGjRVOZ3NVgHlsjpBxVRCEYBIEAAARl4lgZmVgEQAKFx8Mo0ZnpqgA
Fyi2JqKGmGebWRIAILbCIo27cYFWASTCtievRXqSVwQfzLYeeYESxlnSVRIW1igjWHJmjBXbpKXe
FQTizlh1eJNVHbYf0LGc39XW2PIoVZE0whasWPSqFBBHrkKEA3QG0DFTEMXBUsjCWesg4oMFAGwg
tKsiwqA+jGiCiRPGAM6pLCVLGKHQ6EGJlc0IuDxzAgX+CCOW9DjAaUsEyAoT+GHpeSRoHgxEUWgA
UEUpFhMWgTbKEPUBAU15TBZxekYD0RMEqCDLIpYIWTAcmGEd9rWQBxQyjeQqdK/ZTWEO3mK5l+9N
o75SrcHhm9WwnlzNoA5zdM+JHz0HCPQdUauZowoFnSw+c2CBvw6dUXT4LMKE6EIHUqMexgCiIREk
nOwl7Q+FhNQoLuzOc6Kw3kIIVOLqjYKBYCwinmgo9CBEswfMAziK7mRDoQhcUZxwoBKFibq3n3jX
I0GyCPLC0DrS8GR1oaEoRBRYVhT99/qG4DcCA/yNU4Ajbjhhnx4P2DJggR3YZog6RyyYxwM9PSgM
BaP+sQdgIRL0JAKBwnTooRMAFWLdiPyJ8JwvTnyQoh5midCASh149ZkTIFAmHnzOZOBfIU6U4Mhd
4zF34DNEoDAhARGY50BvJkioyxFOGkKAShGkFsJwejiR5Xf8aZAaBp89coQJjuDXAQOApekEm45A
NaAtIbyYxREf0OlICCK841uaahZBQjyfjXCACYjuaASjhFagRKSFNtloHg+hYWIxRohnBQWCSSAh
BVZ+hkgRnlbxwJIVgIqGlaU6wkeTxHxjm6gVLImrFbHWVEQ1taZjWxJX7KqqnqgUEUxDwtqajrOa
RkqhEDcxWwECbEjxTYe9gojqOJQ6JO231ob72bSqAjh4RgfsjiDCCfDCK8K8I9TL7r33nvGtCO7C
O1dUAONk3LcBFxzwwEMwZ/DC4iAsRIE+CWNCbzeV8FfEtoDwVwnlacxMkcKQYIE/F5TQ2QcedUZC
agyc3NsFGrXVZMipWVBCzKv4Q0JvCviDsjAwf4ylxBeX0KcwGs81ccgqGS3MBxc3RjDDVAvdBRcf
eFy1MFd3bcQHJEQdlddkP5E1Cf9yXfbaV2d9RBAAOw==
}

# Create a copy of the image just created, magnified according to the
# display's DPI scaling level.  Since the zooom factor must be an integer,
# the copy will only be effectively magnified if $tk::scalingPct >= 200.
image create photo logo2
logo2 copy logo -zoom [expr {$tk::scalingPct / 100}]

set c [canvas $w.m.c -bg white]
pack $c -fill both -expand yes -fill both -side left

# For scaling-awareness specify the coordinates of the canvas items in points
# rather than pixels.  Create the items with a left and top padding of 15 pt.
$c create rectangle 15p 15p 165p 60p -fill blue -outline black	;# 150p x 45p
$c create oval 15p 75p 165p 120p -fill green			;# 150p x 45p
set imgId [$c create image 90p 135p -image logo2 -anchor n]

# Compute the scaled y coordinate of the next canvas item's top edge in pixels
lassign [$c bbox $imgId] x1 y1 x2 y2		;# x1, y1, x2, y2 are in pixels
incr y2 [expr {round(15 * [tk scaling])}]	;# convert 15 pt to pixels

$c create text 15p $y2 -anchor nw -font {Helvetica 12} \
	-text "A short demo of simple canvas elements."

set txt {
Tcl, or Tool Command Language, is an open-source multi-purpose C library which includes a powerful dynamic scripting language. Together they provide ideal cross-platform development environment for any programming project. It has served for decades as an essential system component in organizations ranging from NASA to Cisco Systems, is a must-know language in the fields of EDA, and powers companies such as FlightAware and F5 Networks.

Tcl is fit for both the smallest and largest programming tasks, obviating the need to decide whether it is overkill for a given job or whether a system written in Tcl will scale up as needed. Wherever a shell script might be used Tcl is a better choice, and entire web ecosystems and mission-critical control and testing systems have also been written in Tcl. Tcl excels in all these roles due to the minimal syntax of the language, the unique programming paradigm exposed at the script level, and the careful engineering that has gone into the design of the Tcl internals.
}

set t [text $w.m.t -wrap word]
pack $t -side right -expand yes -fill both
$t insert end $txt

frame $w.f

pack [button $w.f.c -text "Print Canvas" -command [list tk print $w.m.c]] \
	-side left -anchor w -padx 3p
pack [button $w.f.t -text "Print Text" -command [list tk print $w.m.t]] \
	-side right -anchor e -padx 3p

pack $w.f -side bottom -fill x
pack $w.m -expand yes -fill both -side top

Changes to library/demos/puzzle.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9

10
11
12
13

14
15
16
17
18
19
20
21









-
+



-
+







# puzzle.tcl --
#
# This demonstration script creates a 15-puzzle game using a collection
# of buttons.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# puzzleSwitch --
# This procedure is invoked when the user clicks on a particular button;
# if the button is next to the empty space, it moves the button into the
# if the button is next to the empty space, it moves the button into th
# empty space.

proc puzzleSwitch {w num} {
    global xpos ypos
    if {(($ypos($num) >= ($ypos(space) - .01))
	    && ($ypos($num) <= ($ypos(space) + .01))
	    && ($xpos($num) >= ($xpos(space) - .26))
54
55
56
57
58
59
60
61

62
63

64
65
66

67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
54
55
56
57
58
59
60

61
62

63
64
65

66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82







-
+

-
+


-
+









-
+






scrollbar $w.s

# The button metrics are a bit bigger in Aqua, and since we are
# using place which doesn't autosize, then we need to have a
# slightly larger frame here...

if {[tk windowingsystem] eq "aqua"} {
    set frameSize 126p
    set frameSize 168
} else {
    set frameSize 90p
    set frameSize 120
}

frame $w.frame -width $frameSize -height $frameSize -borderwidth 2 \
frame $w.frame -width $frameSize -height $frameSize -borderwidth 2\
	-relief sunken -bg [$w.s cget -troughcolor]
pack $w.frame -side top -pady 1c -padx 1c
destroy $w.s

set order {3 1 6 2 5 7 15 13 4 11 8 9 14 10 12}
for {set i 0} {$i < 15} {set i [expr {$i+1}]} {
    set num [lindex $order $i]
    set xpos($num) [expr {($i%4)*.25}]
    set ypos($num) [expr {($i/4)*.25}]
    button $w.frame.$num -relief raised -text $num -bd 0 -highlightthickness 0 \
    button $w.frame.$num -relief raised -text $num -highlightthickness 0 \
	    -command "puzzleSwitch $w $num"
    place $w.frame.$num -relx $xpos($num) -rely $ypos($num) \
	-relwidth .25 -relheight .25
}
set xpos(space) .75
set ypos(space) .75

Changes to library/demos/radio.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27



28
29

30
31

32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24



25
26
27
28

29
30

31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57









-
+














-
-
-
+
+
+

-
+

-
+









-
+








-
+







# radio.tcl --
#
# This demonstration script creates a toplevel window containing
# several radiobutton widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .radio
catch {destroy $w}
toplevel $w
wm title $w "Radiobutton Demonstration"
wm iconname $w "radio"
positionWindow $w
label $w.msg -font $font -wraplength 5i -justify left -text "Three groups of radiobuttons are displayed below.  If you click on a button then the button will become selected exclusively among all the buttons in its group.  A Tcl variable is associated with each group to indicate which of the group's buttons is selected.  When the 'Tristate' button is pressed, the radio buttons will display the tri-state mode. Selecting any radio button will return the buttons to their respective on/off state. Click the \"See Variables\" button to see the current values of the variables."
grid $w.msg -row 0 -column 0 -columnspan 3 -sticky nsew

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w [list size color align]]
grid $btns -row 3 -column 0 -columnspan 3 -sticky ew

labelframe $w.left -pady 1.5p -text "Point Size" -padx 1.5p
labelframe $w.mid -pady 1.5p -text "Color" -padx 1.5p
labelframe $w.right -pady 1.5p -text "Alignment" -padx 1.5p
labelframe $w.left -pady 2 -text "Point Size" -padx 2
labelframe $w.mid -pady 2 -text "Color" -padx 2
labelframe $w.right -pady 2 -text "Alignment" -padx 2
button $w.tristate -text Tristate -command "set size multi; set color multi" \
    -pady 1.5p -padx 1.5p
    -pady 2 -padx 2
if {[tk windowingsystem] eq "aqua"} {
    $w.tristate configure -padx 7.5p
    $w.tristate configure -padx 10
}
grid $w.left     -column 0 -row 1 -pady .5c -padx .5c -rowspan 2
grid $w.mid      -column 1 -row 1 -pady .5c -padx .5c -rowspan 2
grid $w.right    -column 2 -row 1 -pady .5c -padx .5c
grid $w.tristate -column 2 -row 2 -pady .5c -padx .5c

foreach i {10 12 14 18 24} {
    radiobutton $w.left.b$i -text "Point Size $i" -variable size \
	    -relief flat -value $i -tristatevalue "multi"
    pack $w.left.b$i  -side top -pady 1.5p -anchor w -fill x
    pack $w.left.b$i  -side top -pady 2 -anchor w -fill x
}

foreach c {Red Green Blue Yellow Orange Purple} {
    set lower [string tolower $c]
    radiobutton $w.mid.$lower -text $c -variable color \
	    -relief flat -value $lower -anchor w \
	    -command "$w.mid configure -fg \$color" \
	-tristatevalue "multi"
    pack $w.mid.$lower -side top -pady 1.5p -fill x
    pack $w.mid.$lower -side top -pady 2 -fill x
}


label $w.right.l -text "Label" -bitmap questhead -compound left
$w.right.l configure -width [winfo reqwidth $w.right.l] -compound top
$w.right.l configure -height [winfo reqheight $w.right.l]
foreach a {Top Left Right Bottom} {

Changes to library/demos/rmt.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# rmt --
# This script implements a simple remote-control mechanism for
# Tk applications.  It allows you to select an application and
# then type commands to that application.

package require tk
package require Tk

wm title . "Tk Remote Controller"
wm iconname . "Tk Remote"
wm minsize . 1 1

# The global variable below keeps track of the remote application
# that we're sending to.  If it's an empty string then we execute

Changes to library/demos/rolodex.

1
2
3
4
5
6
7
8
9
10
11

12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34

35
36
37
38
39
40

41
42
43
44
45
46
47
1
2
3
4
5
6
7
8
9
10

11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33

34
35
36
37
38
39

40
41
42
43
44
45
46
47










-
+

-
+
















-
+



-
+





-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# rolodex --
# This script was written as an entry in Tom LaStrange's rolodex
# benchmark.  It creates something that has some of the look and
# feel of a rolodex program, although it's lifeless and doesn't
# actually do the rolodex application.

package require tk
package require Tk

foreach i [winfo children .] {
foreach i [winfo child .] {
    catch {destroy $i}
}

set version 1.2

#------------------------------------------
# Phase 0: create the front end.
#------------------------------------------

frame .frame -relief flat
pack .frame -side top -fill y -anchor center

set names {{} Name: Address: {} {} {Home Phone:} {Work Phone:} Fax:}
foreach i {1 2 3 4 5 6 7} {
    label .frame.label$i -text [lindex $names $i] -anchor e
    entry .frame.entry$i -width 35
    grid .frame.label$i .frame.entry$i -sticky ew -pady 1.5p -padx 0.75p
    grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1
}

frame .buttons
pack .buttons -side bottom -pady 1.5p -anchor center
pack .buttons -side bottom -pady 2 -anchor center
button .buttons.clear -text Clear
button .buttons.add -text Add
button .buttons.search -text Search
button .buttons.delete -text "Delete ..."
pack .buttons.clear .buttons.add .buttons.search .buttons.delete \
	-side left -padx 1.5p
	-side left -padx 2

#------------------------------------------
# Phase 1: Add menus, dialog boxes
#------------------------------------------

# DKF - note that this is an old-style menu bar; I just have not yet
# got around to converting the context help code to work with the new

Changes to library/demos/ruler.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26
27
28
29
30
31
32
33
34
35
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21



22
23




24
25
26
27
28
29
30









-
+











-
-
-
+
+
-
-
-
-







# ruler.tcl --
#
# This demonstration script creates a canvas widget that displays a ruler
# with tab stops that can be set, moved, and deleted.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# rulerMkTab --
# This procedure creates a new triangular polygon in a canvas to
# represent a tab stop.
#
# Arguments:
# c -		The canvas window.
# x, y -	Coordinates at which to create the tab stop.

proc rulerMkTab {c x y} {
    upvar #0 demo_rulerInfo v
    set newTab [$c create polygon $x $y \
	    [expr {$x+$v(size)}] [expr {$y+$v(size)}] \
	    [expr {$x-$v(size)}] [expr {$y+$v(size)}]]
    $c create polygon $x $y [expr {$x+$v(size)}] [expr {$y+$v(size)}] \
	    [expr {$x-$v(size)}] [expr {$y+$v(size)}]
    set fill [$c itemcget $newTab -outline]
    $c itemconfigure $newTab -fill $fill -outline {}
    set v(normalStyle) "-fill $fill"
    return $newTab
}

set w .ruler
catch {destroy $w}
toplevel $w
wm title $w "Ruler Demonstration"
wm iconname $w "ruler"
48
49
50
51
52
53
54

55
56
57
58
59
60
61
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+








set demo_rulerInfo(grid) .25c
set demo_rulerInfo(left) [winfo fpixels $c 1c]
set demo_rulerInfo(right) [winfo fpixels $c 13c]
set demo_rulerInfo(top) [winfo fpixels $c 1c]
set demo_rulerInfo(bottom) [winfo fpixels $c 1.5c]
set demo_rulerInfo(size) [winfo fpixels $c .2c]
set demo_rulerInfo(normalStyle) "-fill black"
# Main widget program sets variable tk_demoDirectory
if {[winfo depth $c] > 1} {
    set demo_rulerInfo(activeStyle) "-fill red -stipple {}"
    set demo_rulerInfo(deleteStyle) [list -fill red \
	    -stipple @[file join $tk_demoDirectory images gray25.xbm]]
} else {
    set demo_rulerInfo(activeStyle) "-fill black -stipple {}"
69
70
71
72
73
74
75
76

77
78
79
80
81


82
83

84
85
86
87
88
89
90
65
66
67
68
69
70
71

72
73
74
75


76
77
78

79
80
81
82
83
84
85
86







-
+



-
-
+
+

-
+







    $c create line ${x}c 1c ${x}c 0.6c -width 1
    $c create line $x.25c 1c $x.25c 0.8c -width 1
    $c create line $x.5c 1c $x.5c 0.7c -width 1
    $c create line $x.75c 1c $x.75c 0.8c -width 1
    $c create text $x.15c .75c -text $i -anchor sw
}
$c addtag well withtag [$c create rect 13.2c 1c 13.8c 0.5c \
	-fill [lindex [$c config -bg] 4]]
	-outline black -fill [lindex [$c config -bg] 4]]
$c addtag well withtag [rulerMkTab $c [winfo pixels $c 13.5c] \
	[winfo pixels $c .65c]]

$c bind well <Button-1> "rulerNewTab $c %x %y"
$c bind tab <Button-1> "rulerSelectTab $c %x %y"
$c bind well <1> "rulerNewTab $c %x %y"
$c bind tab <1> "rulerSelectTab $c %x %y"
bind $c <B1-Motion> "rulerMoveTab $c %x %y"
bind $c <ButtonRelease-1> "rulerReleaseTab $c"
bind $c <Any-ButtonRelease-1> "rulerReleaseTab $c"

# rulerNewTab --
# Does all the work of creating a tab stop, including creating the
# triangle object and adding tags to it to give it tab behavior.
#
# Arguments:
# c -		The canvas window.

Changes to library/demos/sayings.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34










-
+















-
+







# sayings.tcl --
#
# This demonstration script creates a listbox that can be scrolled
# both horizontally and vertically.  It displays a collection of
# well-known sayings.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .sayings
catch {destroy $w}
toplevel $w
wm title $w "Listbox Demonstration (well-known sayings)"
wm iconname $w "sayings"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "The listbox below contains a collection of well-known sayings.  You can scan the list using either of the scrollbars or by dragging in the listbox window with button 2 pressed."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame -side top -expand yes -fill both -padx 1c


ttk::scrollbar $w.frame.yscroll -command "$w.frame.list yview"
ttk::scrollbar $w.frame.xscroll -orient horizontal \
    -command "$w.frame.list xview"
listbox $w.frame.list -width 20 -height 10 -setgrid 1 \

Changes to library/demos/search.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







# search.tcl --
#
# This demonstration script creates a collection of widgets that
# allow you to load a file into a text widget, then perform searches
# on that file.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# textLoadFile --
# This procedure below loads a file into a text widget, discarding
# the previous contents of the widget. Tags for the old widget are
# not affected, however.
#
# Arguments:
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+












-
+








frame $w.file
label $w.file.label -text "File name:" -width 13 -anchor w
entry $w.file.entry -width 40 -textvariable fileName
button $w.file.button -text "Load File" \
	-command "textLoadFile $w.text \$fileName"
pack $w.file.label $w.file.entry -side left
pack $w.file.button -side left -pady 3p -padx 7.5p
pack $w.file.button -side left -pady 5 -padx 10
bind $w.file.entry <Return> "
    textLoadFile $w.text \$fileName
    focus $w.string.entry
"
focus $w.file.entry

frame $w.string
label $w.string.label -text "Search string:" -width 13 -anchor w
entry $w.string.entry -width 40 -textvariable searchString
button $w.string.button -text "Highlight" \
	-command "textSearch $w.text \$searchString search"
pack $w.string.label $w.string.entry -side left
pack $w.string.button -side left -pady 3p -padx 7.5p
pack $w.string.button -side left -pady 5 -padx 10
bind $w.string.entry <Return> "textSearch $w.text \$searchString search"

text $w.text -yscrollcommand "$w.scroll set" -setgrid true
ttk::scrollbar $w.scroll -command "$w.text yview"
pack $w.file $w.string -side top -fill x
pack $w.scroll -side right -fill y
pack $w.text -expand yes -fill both

Changes to library/demos/spin.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# spin.tcl --
#
# This demonstration script creates several spinbox widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .spin
catch {destroy $w}
toplevel $w
wm title $w "Spinbox Demonstration"
wm iconname $w "spin"
positionWindow $w
34
35
36
37
38
39
40
41

42
43
44



45






34
35
36
37
38
39
40

41
42
43
44
45
46
47

48
49
50
51
52
53







-
+



+
+
+
-
+
+
+
+
+
+

set australianCities {
    Canberra Sydney Melbourne Perth Adelaide Brisbane
    Hobart Darwin "Alice Springs"
}

spinbox $w.s1 -from 1 -to 10 -width 10 -validate key \
	-validatecommand {string is integer %P}
	-vcmd {string is integer %P}
spinbox $w.s2 -from 0 -to 3 -increment .5 -format %05.2f -width 10
spinbox $w.s3 -values $australianCities -width 10

#entry $w.e1
#entry $w.e2
#entry $w.e3
pack $w.s1 $w.s2 $w.s3 -side top -pady 3p -padx 7.5p
pack $w.s1 $w.s2 $w.s3 -side top -pady 5 -padx 10 ;#-fill x

#$w.e1 insert 0 "Initial value"
#$w.e2 insert end "This entry contains a long value, much too long "
#$w.e2 insert end "to fit in the window at one time, so long in fact "
#$w.e2 insert end "that you'll have to scan or scroll to see the end."

Changes to library/demos/square.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21

22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37













-
-
+
+





-
+








-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# square --
# This script generates a demo application containing only a "square"
# widget.  It's only usable in the "tktest" application or if Tk has
# been compiled with tkSquare.c. This demo arranges the following
# bindings for the widget:
#
# Button-1 press/drag:		moves square to mouse
# "a":				toggle size animation on/off

package require tk		;# We use Tk generally, and...
package require tk::test	;# ... we use the square widget too.
package require Tk		;# We use Tk generally, and...
package require Tktest		;# ... we use the square widget too.

square .s
pack .s -expand yes -fill both
wm minsize . 1 1

bind .s <Button-1> {center %x %y}
bind .s <1> {center %x %y}
bind .s <B1-Motion> {center %x %y}
bind .s a animate
focus .s

# The procedure below centers the square on a given position.

proc center {x y} {
    set a [.s size]
    .s position [expr {$x-($a/2)}] [expr {$y-($a/2)}]
    .s position [expr $x-($a/2)] [expr $y-($a/2)]
}

# The procedures below provide a simple form of animation where
# the box changes size in a pulsing pattern: larger, smaller, larger,
# and so on.

set inc 0

Changes to library/demos/states.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36









-
+


















-
+







# states.tcl --
#
# This demonstration script creates a listbox widget that displays
# the names of the 50 states in the United States of America.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .states
catch {destroy $w}
toplevel $w
wm title $w "Listbox Demonstration (50 states)"
wm iconname $w "states"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text "A listbox containing the 50 states is displayed below, along with a scrollbar.  You can scan the list either using the scrollbar or by scanning.  To scan, press button 2 in the widget and drag up or down."
pack $w.msg -side top

labelframe $w.justif -text Justification
foreach c {Left Center Right} {
    set lower [string tolower $c]
    radiobutton $w.justif.$lower -text $c -variable just \
        -relief flat -value $lower -anchor w \
        -command "$w.frame.list configure -justify \$just" \
        -tristatevalue "multi"
    pack $w.justif.$lower -side left -pady 1.5p -fill x
    pack $w.justif.$lower -side left -pady 2 -fill x
}
pack $w.justif

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

Changes to library/demos/style.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# style.tcl --
#
# This demonstration script creates a text widget that illustrates the
# various display styles that may be set for tags.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .style
catch {destroy $w}
toplevel $w
wm title $w "Text Demonstration - Display Styles"
wm iconname $w "style"
positionWindow $w
48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63







-
-
+
+







	    -borderwidth 1
    $w.text tag configure sunken -background white -relief sunken \
	    -borderwidth 1
}
$w.text tag configure bgstipple -background black -borderwidth 0 \
	-bgstipple gray12
$w.text tag configure fgstipple -fgstipple gray50
$w.text tag configure underline -underline 1
$w.text tag configure overstrike -overstrike 1
$w.text tag configure underline -underline on
$w.text tag configure overstrike -overstrike on
$w.text tag configure right -justify right
$w.text tag configure center -justify center
$w.text tag configure super -offset 4p -font "$family 10"
$w.text tag configure sub -offset -2p -font "$family 10"
$w.text tag configure margins -lmargin1 12m -lmargin2 6m -rmargin 10m
$w.text tag configure spacing -spacing1 10p -spacing2 2p \
	-lmargin1 12m -lmargin2 6m -rmargin 10m

Deleted library/demos/systray.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

























































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# systray.tcl --
#
# This demonstration script showcases the tk systray and tk sysnotify commands.
#

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

set w .systray
destroy $w
toplevel $w
wm title $w "System Tray Demonstration"
positionWindow $w

## See Code / Dismiss buttons
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x

catch {tk systray destroy}
set trayIconExists false

set iconmenu .menubar
destroy $iconmenu
menu $iconmenu
$iconmenu add command -label "Status" -command { puts "status icon clicked" }
$iconmenu add command -label "Exit" -command exit

pack [label $w.l -text "This demonstration showcases
        the tk systray and tk sysnotify commands.
        Running this demo creates the systray icon.
        Clicking the buttons below modifies and destroys the icon
        and displays the notification."]

image create photo book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==

labelframe $w.f -text "Tray Icon"
button $w.f.b0 -text "Create" -command create
button $w.f.b1 -text "Modify" -command modify
button $w.f.b2 -text "Destroy" -command remove
pack $w.f.b0 $w.f.b1 $w.f.b2 -padx 3p -pady 3p -side left -expand true -fill x

button $w.b3 -text "Display Notification" -command notify
pack $w.f $w.b3 -fill x -padx 3p -pady 3p

proc create {} {
    global trayIconExists
    if {$trayIconExists} {
        tk_messageBox -message "Systray icon already exists"
        return
    }
    tk systray create -image book -text "Systray sample" \
            -button1 {puts "foo"} \
            -button3 {tk_popup $iconmenu [winfo pointerx .] [winfo pointery .]}
    set trayIconExists true
}

proc modify {} {
    global trayIconExists
    if {!$trayIconExists} {
        tk_messageBox -message "Please create systray icon first"
        return
    }
    image create photo page -data R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7
    tk systray configure -image page
    tk systray configure -text "Modified text"
    tk systray configure -button1 {puts "this is a different output"}
    tk systray configure -button3 {puts "hello yall"}
}

proc notify {} {
    global trayIconExists
    if {!$trayIconExists} {
        tk_messageBox -message "Please create systray icon first"
        return
    }
    tk sysnotify  "Alert" "This is an alert"
}

proc remove {} {
    global trayIconExists
    if {!$trayIconExists} {
        tk_messageBox -message "Systray icon was already destroyed"
        return
    }
    tk systray destroy
    set trayIconExists false
}

create

Changes to library/demos/tclIndex.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67



























































68
69
70
1
2
3
4
5
6
7
8



























































9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
# Tcl autoload index file, version 2.0
# This file is generated by the "auto_mkindex" command
# and sourced to set up indexing information for one or
# more commands.  Typically each line is a command that
# sets an element in the auto_index array, where the
# element name is the name of a command and the value is
# a script that loads the command.

set auto_index(arrowSetup) [list source -encoding utf-8 [file join $dir arrow.tcl]]
set auto_index(arrowMove1) [list source -encoding utf-8 [file join $dir arrow.tcl]]
set auto_index(arrowMove2) [list source -encoding utf-8 [file join $dir arrow.tcl]]
set auto_index(arrowMove3) [list source -encoding utf-8 [file join $dir arrow.tcl]]
set auto_index(textLoadFile) [list source -encoding utf-8 [file join $dir search.tcl]]
set auto_index(textSearch) [list source -encoding utf-8 [file join $dir search.tcl]]
set auto_index(textToggle) [list source -encoding utf-8 [file join $dir search.tcl]]
set auto_index(itemEnter) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemLeave) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemMark) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemStroke) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemsUnderArea) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemStartDrag) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(itemDrag) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(butPress) [list source -encoding utf-8 [file join $dir items.tcl]]
set auto_index(loadDir) [list source -encoding utf-8 [file join $dir image2.tcl]]
set auto_index(loadImage) [list source -encoding utf-8 [file join $dir image2.tcl]]
set auto_index(rulerMkTab) [list source -encoding utf-8 [file join $dir ruler.tcl]]
set auto_index(rulerNewTab) [list source -encoding utf-8 [file join $dir ruler.tcl]]
set auto_index(rulerSelectTab) [list source -encoding utf-8 [file join $dir ruler.tcl]]
set auto_index(rulerMoveTab) [list source -encoding utf-8 [file join $dir ruler.tcl]]
set auto_index(rulerReleaseTab) [list source -encoding utf-8 [file join $dir ruler.tcl]]
set auto_index(mkTextConfig) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textEnter) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textInsert) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textPaste) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textB1Press) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textB1Move) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textBs) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(textDel) [list source -encoding utf-8 [file join $dir ctext.tcl]]
set auto_index(bitmapRow) [list source -encoding utf-8 [file join $dir bitmap.tcl]]
set auto_index(scrollEnter) [list source -encoding utf-8 [file join $dir cscroll.tcl]]
set auto_index(scrollLeave) [list source -encoding utf-8 [file join $dir cscroll.tcl]]
set auto_index(scrollButton) [list source -encoding utf-8 [file join $dir cscroll.tcl]]
set auto_index(textWindOn) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(textWindOff) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(textWindPlot) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(embPlotDown) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(embPlotMove) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(textWindDel) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(embDefBg) [list source -encoding utf-8 [file join $dir twind.tcl]]
set auto_index(floorDisplay) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(newRoom) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(roomChanged) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(bg1) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(bg2) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(bg3) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(fg1) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(fg2) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(fg3) [list source -encoding utf-8 [file join $dir floor.tcl]]
set auto_index(setWidth) [list source -encoding utf-8 [file join $dir hscale.tcl]]
set auto_index(plotDown) [list source -encoding utf-8 [file join $dir plot.tcl]]
set auto_index(plotMove) [list source -encoding utf-8 [file join $dir plot.tcl]]
set auto_index(puzzleSwitch) [list source -encoding utf-8 [file join $dir puzzle.tcl]]
set auto_index(setHeight) [list source -encoding utf-8 [file join $dir vscale.tcl]]
set auto_index(showMessageBox) [list source -encoding utf-8 [file join $dir msgbox.tcl]]
set auto_index(setColor) [list source -encoding utf-8 [file join $dir clrpick.tcl]]
set auto_index(setColor_helper) [list source -encoding utf-8 [file join $dir clrpick.tcl]]
set auto_index(fileDialog) [list source -encoding utf-8 [file join $dir filebox.tcl]]
set auto_index(arrowSetup) [list source [file join $dir arrow.tcl]]
set auto_index(arrowMove1) [list source [file join $dir arrow.tcl]]
set auto_index(arrowMove2) [list source [file join $dir arrow.tcl]]
set auto_index(arrowMove3) [list source [file join $dir arrow.tcl]]
set auto_index(textLoadFile) [list source [file join $dir search.tcl]]
set auto_index(textSearch) [list source [file join $dir search.tcl]]
set auto_index(textToggle) [list source [file join $dir search.tcl]]
set auto_index(itemEnter) [list source [file join $dir items.tcl]]
set auto_index(itemLeave) [list source [file join $dir items.tcl]]
set auto_index(itemMark) [list source [file join $dir items.tcl]]
set auto_index(itemStroke) [list source [file join $dir items.tcl]]
set auto_index(itemsUnderArea) [list source [file join $dir items.tcl]]
set auto_index(itemStartDrag) [list source [file join $dir items.tcl]]
set auto_index(itemDrag) [list source [file join $dir items.tcl]]
set auto_index(butPress) [list source [file join $dir items.tcl]]
set auto_index(loadDir) [list source [file join $dir image2.tcl]]
set auto_index(loadImage) [list source [file join $dir image2.tcl]]
set auto_index(rulerMkTab) [list source [file join $dir ruler.tcl]]
set auto_index(rulerNewTab) [list source [file join $dir ruler.tcl]]
set auto_index(rulerSelectTab) [list source [file join $dir ruler.tcl]]
set auto_index(rulerMoveTab) [list source [file join $dir ruler.tcl]]
set auto_index(rulerReleaseTab) [list source [file join $dir ruler.tcl]]
set auto_index(mkTextConfig) [list source [file join $dir ctext.tcl]]
set auto_index(textEnter) [list source [file join $dir ctext.tcl]]
set auto_index(textInsert) [list source [file join $dir ctext.tcl]]
set auto_index(textPaste) [list source [file join $dir ctext.tcl]]
set auto_index(textB1Press) [list source [file join $dir ctext.tcl]]
set auto_index(textB1Move) [list source [file join $dir ctext.tcl]]
set auto_index(textBs) [list source [file join $dir ctext.tcl]]
set auto_index(textDel) [list source [file join $dir ctext.tcl]]
set auto_index(bitmapRow) [list source [file join $dir bitmap.tcl]]
set auto_index(scrollEnter) [list source [file join $dir cscroll.tcl]]
set auto_index(scrollLeave) [list source [file join $dir cscroll.tcl]]
set auto_index(scrollButton) [list source [file join $dir cscroll.tcl]]
set auto_index(textWindOn) [list source [file join $dir twind.tcl]]
set auto_index(textWindOff) [list source [file join $dir twind.tcl]]
set auto_index(textWindPlot) [list source [file join $dir twind.tcl]]
set auto_index(embPlotDown) [list source [file join $dir twind.tcl]]
set auto_index(embPlotMove) [list source [file join $dir twind.tcl]]
set auto_index(textWindDel) [list source [file join $dir twind.tcl]]
set auto_index(embDefBg) [list source [file join $dir twind.tcl]]
set auto_index(floorDisplay) [list source [file join $dir floor.tcl]]
set auto_index(newRoom) [list source [file join $dir floor.tcl]]
set auto_index(roomChanged) [list source [file join $dir floor.tcl]]
set auto_index(bg1) [list source [file join $dir floor.tcl]]
set auto_index(bg2) [list source [file join $dir floor.tcl]]
set auto_index(bg3) [list source [file join $dir floor.tcl]]
set auto_index(fg1) [list source [file join $dir floor.tcl]]
set auto_index(fg2) [list source [file join $dir floor.tcl]]
set auto_index(fg3) [list source [file join $dir floor.tcl]]
set auto_index(setWidth) [list source [file join $dir hscale.tcl]]
set auto_index(plotDown) [list source [file join $dir plot.tcl]]
set auto_index(plotMove) [list source [file join $dir plot.tcl]]
set auto_index(puzzleSwitch) [list source [file join $dir puzzle.tcl]]
set auto_index(setHeight) [list source [file join $dir vscale.tcl]]
set auto_index(showMessageBox) [list source [file join $dir msgbox.tcl]]
set auto_index(setColor) [list source [file join $dir clrpick.tcl]]
set auto_index(setColor_helper) [list source [file join $dir clrpick.tcl]]
set auto_index(fileDialog) [list source [file join $dir filebox.tcl]]
set auto_index(systray) [list source -encoding utf-8 [file join $dir systray.tcl]]
set auto_index(windoicons [list source -encoding utf-8 [file join $dir windowicons.tcl]]

Changes to library/demos/tcolor.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# tcolor --
# This script implements a simple color editor, where you can
# create colors using either the RGB, HSB, or CYM color spaces
# and apply the color to existing applications.

package require tk
package require Tk 8.4
wm title . "Color Editor"

# Global variables that control the program:
#
# colorSpace -			Color space currently being used for
#				editing.  Must be "rgb", "cmy", or "hsb".
# label1, label2, label3 -	Labels for the scales.
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100







-
+







    }
    set f [open $i]
    labelframe .names -text "Select:" -padx .1c -pady .1c
    grid .names -row 0 -column 0 -sticky nsew -padx .15c -pady .15c -rowspan 2
    grid columnconfigure . 0 -weight 1
    listbox .names.lb -width 20 -height 12 -yscrollcommand ".names.s set" \
	-exportselection false
    bind .names.lb <Double-Button-1> {
    bind .names.lb <Double-1> {
	    tc_loadNamedColor [.names.lb get [.names.lb curselection]]
    }
    scrollbar .names.s -orient vertical -command ".names.lb yview"
    pack .names.lb .names.s -side left -fill y -expand 1
    while {[gets $f line] >= 0} {
	if {[regexp {^\s*\d+\s+\d+\s+\d+\s+(\S+)$} $line -> col]} {
	    .names.lb insert end $col

Changes to library/demos/text.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# text.tcl --
#
# This demonstration script creates a text widget that describes
# the basic editing functions.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .text
catch {destroy $w}
toplevel $w
wm title $w "Text Demonstration - Basic Facilities"
wm iconname $w "text"
positionWindow $w
53
54
55
56
57
58
59
60
61


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
53
54
55
56
57
58
59


60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80

81
82
83
84
85
86
87







-
-
+
+
-


















-
+
-







$w.text insert 0.0 \
{This window is a text widget.  It displays one or more lines of text
and allows you to edit the text.  Here is a summary of the things you
can do to a text widget:

1. Scrolling. Use the scrollbar to adjust the view in the text window.

2. Scanning. Press the middle mouse button in the text window and drag up
or down. This will drag the text at high speed to allow you to scan its
2. Scanning. Press mouse button 2 in the text window and drag up or down.
This will drag the text at high speed to allow you to scan its contents.
contents.

3. Insert text. Press mouse button 1 to set the insertion cursor, then
type text.  What you type will be added to the widget.

4. Select. Press mouse button 1 and drag to select a range of characters.
Once you've released the button, you can adjust the selection by pressing
button 1 with the shift key down.  This will reset the end of the
selection nearest the mouse cursor and you can drag that end of the
selection by dragging the mouse before releasing the mouse button.
You can double-click to select whole words or triple-click to select
whole lines.

5. Delete and replace. To delete text, select the characters you'd like
to delete and type Backspace or Delete.  Alternatively, you can type new
text, in which case it will replace the selected text.

6. Copy the selection. To copy the selection into this window, select
what you want to copy (either here or in another application), then
click the middle mouse button to copy the selection to the point of the
click button 2 to copy the selection to the point of the mouse cursor.
mouse cursor.

7. Edit.  Text widgets support the standard Motif editing characters
plus many Emacs editing characters.  Backspace and Control-h erase the
character to the left of the insertion cursor.  Delete and Control-d
erase the character to the right of the insertion cursor.  Meta-backspace
deletes the word to the left of the insertion cursor, and Meta-d deletes
the word to the right of the insertion cursor.  Control-k deletes from

Changes to library/demos/textpeer.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







# textpeer.tcl --
#
# This demonstration script creates a pair of text widgets that can edit a
# single logical buffer. This is particularly useful when editing related text
# in two (or more) parts of the same file.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .textpeer
catch {destroy $w}
toplevel $w
wm title $w "Text Widget Peering Demonstration"
wm iconname $w "textpeer"
positionWindow $w

Changes to library/demos/timer.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15







-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# timer --
# This script generates a counter with start and stop buttons.

package require tk
package require Tk

label .counter -text 0.00 -relief raised -width 10 -padx 2m -pady 1m
button .start -text Start -command {
    if {$stopped} {
	set stopped 0
	set startMoment [clock clicks -milliseconds]
	tick

Changes to library/demos/toolbar.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41








-
+










-
+













-
+







# toolbar.tcl --
#
# This demonstration script creates a toolbar that can be torn off.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .toolbar
destroy $w
toplevel $w
wm title $w "Toolbar Demonstration"
wm iconname $w "toolbar"
positionWindow $w

ttk::label $w.msg -wraplength 4i -text "This is a demonstration of how to do\
	a toolbar that is styled correctly and which can be torn off. The\
	buttons are configured to be toolbar style buttons by\
	buttons are configured to be \u201Ctoolbar style\u201D buttons by\
	telling them that they are to use the Toolbutton style. At the left\
	end of the toolbar is a simple marker that the cursor changes to a\
	movement icon over; drag that away from the toolbar to tear off the\
	whole toolbar into a separate toplevel widget. When the dragged-off\
	toolbar is no longer needed, just close it like any normal toplevel\
	and it will reattach to the window it was torn off from."

## Set up the toolbar hull
set t [frame $w.toolbar]		;# Must be a frame!
ttk::separator $w.sep
ttk::frame $t.tearoff -cursor fleur
ttk::separator $t.tearoff.to -orient vertical
ttk::separator $t.tearoff.to2 -orient vertical
pack $t.tearoff.to -fill y -expand 1 -padx 3p -side left
pack $t.tearoff.to -fill y -expand 1 -padx 2 -side left
pack $t.tearoff.to2 -fill y -expand 1 -side left
ttk::frame $t.contents
grid $t.tearoff $t.contents -sticky nsew
grid columnconfigure $t $t.contents -weight 1
grid columnconfigure $t.contents 1000 -weight 1

## Bindings so that the toolbar can be torn off and reattached
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92







-
+










}

## Some content for the rest of the toplevel
text $w.txt -width 40 -height 10
interp alias {} doInsert {} $w.txt insert end	;# Make bindings easy to write

## Arrange contents
grid $t.button $t.check $t.menu $t.combo -in $t.contents -padx 1.5p -pady 3p -sticky ns
grid $t.button $t.check $t.menu $t.combo -in $t.contents -padx 2 -sticky ns
grid $t -sticky ew
grid $w.sep -sticky ew
grid $w.msg -sticky ew
grid $w.txt -sticky nsew
grid rowconfigure $w $w.txt -weight 1
grid columnconfigure $w $w.txt -weight 1

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
grid $btns -sticky ew

Changes to library/demos/tree.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# tree.tcl --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .tree
catch {destroy $w}
toplevel $w
wm title $w "Directory Browser"
wm iconname $w "tree"
positionWindow $w
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48







-







proc populateTree {tree node} {
    if {[$tree set $node type] ne "directory"} {
	return
    }
    set path [$tree set $node fullpath]
    $tree delete [$tree children $node]
    foreach f [lsort -dictionary [glob -nocomplain -dir $path *]] {
	set f [file normalize $f]
	set type [file type $f]
	set id [$tree insert $node end -text [file tail $f] \
		-values [list $f $type]]

	if {$type eq "directory"} {
	    ## Make it so that this node is openable
	    $tree insert $id 0 -text dummy ;# a dummy
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88







-
+










## Create the tree and set it up
ttk::treeview $w.tree -columns {fullpath type size} -displaycolumns {size} \
	-yscroll "$w.vsb set" -xscroll "$w.hsb set"
ttk::scrollbar $w.vsb -orient vertical -command "$w.tree yview"
ttk::scrollbar $w.hsb -orient horizontal -command "$w.tree xview"
$w.tree heading \#0 -text "Directory Structure"
$w.tree heading size -text "File Size"
$w.tree column size -width 70
$w.tree column size -stretch 0 -width 70
populateRoots $w.tree
bind $w.tree <<TreeviewOpen>> {populateTree %W [%W focus]}

## Arrange the tree and its scrollbars in the toplevel
lower [ttk::frame $w.dummy]
pack $w.dummy -fill both -expand 1
grid $w.tree $w.vsb -sticky nsew -in $w.dummy
grid $w.hsb -sticky nsew -in $w.dummy
grid columnconfigure $w.dummy 0 -weight 1
grid rowconfigure $w.dummy 0 -weight 1

Changes to library/demos/ttkbut.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20

21
22
23
24

25
26
27
28
29

30
31
32

33
34
35
36
37
38
39
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19

20
21
22
23

24
25
26
27
28

29
30
31

32
33
34
35
36
37
38
39










-
+








-
+



-
+




-
+


-
+







# ttkbut.tcl --
#
# This demonstration script creates a toplevel window containing several
# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and
# radiobuttons.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttkbut
catch {destroy $w}
toplevel $w
wm title $w "Simple Ttk Widgets"
wm iconname $w "ttkbut"
positionWindow $w

ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Ttk is the new Tk themed widget set. This is a Ttk themed label, and below are three groups of Ttk widgets in Ttk labelframes. The first group are all buttons that set the current application theme when pressed. The second group contains three sets of checkbuttons, with a separator widget between the sets. Note that the Enabled button controls whether all the other themed widgets in this toplevel are in the disabled state. The third group has a collection of linked radiobuttons."
ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Ttk is the new Tk themed widget set. This is a Ttk themed label, and below are three groups of Ttk widgets in Ttk labelframes. The first group are all buttons that set the current application theme when pressed. The second group contains three sets of checkbuttons, with a separator widget between the sets. Note that the \u201cEnabled\u201d button controls whether all the other themed widgets in this toplevel are in the disabled state. The third group has a collection of linked radiobuttons."
pack $w.msg -side top -fill x

## See Code / Dismiss
pack [addSeeDismiss $w.seeDismiss $w {enabled cheese tomato basil oregano happiness}]\
pack [addSeeDismiss $w.seeDismiss $w {enabled cheese tomato basil oregano happyness}]\
	-side bottom -fill x

## Add buttons for setting the theme
ttk::labelframe $w.buttons -text "Buttons"
foreach theme [lsort [ttk::themes]] {
foreach theme [ttk::themes] {
    ttk::button $w.buttons.$theme -text $theme \
	    -command [list ttk::setTheme $theme]
    pack $w.buttons.$theme -pady 1.5p
    pack $w.buttons.$theme -pady 2
}

## Helper procedure for the top checkbutton
proc setState {rootWidget exceptThese value} {
    if {$rootWidget in $exceptThese} {
	return
    }
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76





77
78

79
80
81
82
83

84
61
62
63
64
65
66
67

68
69
70
71





72
73
74
75
76
77

78
79
80
81
82

83
84







-
+



-
-
-
-
-
+
+
+
+
+

-
+




-
+

ttk::separator   $w.checks.sep1
ttk::checkbutton $w.checks.c1 -text Cheese  -variable cheese
ttk::checkbutton $w.checks.c2 -text Tomato  -variable tomato
ttk::separator   $w.checks.sep2
ttk::checkbutton $w.checks.c3 -text Basil   -variable basil
ttk::checkbutton $w.checks.c4 -text Oregano -variable oregano
pack $w.checks.e $w.checks.sep1 $w.checks.c1 $w.checks.c2 $w.checks.sep2 \
	$w.checks.c3 $w.checks.c4   -fill x -pady 1.5p
	$w.checks.c3 $w.checks.c4   -fill x -pady 2

## Set up the radiobutton group
ttk::labelframe $w.radios -text "Radiobuttons"
ttk::radiobutton $w.radios.r1 -text "Great" -variable happiness -value great
ttk::radiobutton $w.radios.r2 -text "Good" -variable happiness -value good
ttk::radiobutton $w.radios.r3 -text "OK" -variable happiness -value ok
ttk::radiobutton $w.radios.r4 -text "Poor" -variable happiness -value poor
ttk::radiobutton $w.radios.r5 -text "Awful" -variable happiness -value awful
ttk::radiobutton $w.radios.r1 -text "Great" -variable happyness -value great
ttk::radiobutton $w.radios.r2 -text "Good" -variable happyness -value good
ttk::radiobutton $w.radios.r3 -text "OK" -variable happyness -value ok
ttk::radiobutton $w.radios.r4 -text "Poor" -variable happyness -value poor
ttk::radiobutton $w.radios.r5 -text "Awful" -variable happyness -value awful
pack $w.radios.r1 $w.radios.r2 $w.radios.r3 $w.radios.r4 $w.radios.r5 \
	-fill x -padx 3p -pady 1.5p
	-fill x -padx 3 -pady 2

## Arrange things neatly
pack [ttk::frame $w.f] -fill both -expand 1
lower $w.f
grid $w.buttons $w.checks $w.radios -in $w.f -sticky nwe -pady 1.5p -padx 3p
grid $w.buttons $w.checks $w.radios -in $w.f -sticky nwe -pady 2 -padx 3
grid columnconfigure $w.f {0 1 2} -weight 1 -uniform yes

Changes to library/demos/ttkmenu.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17









-
+







# ttkmenu.tcl --
#
# This demonstration script creates a toplevel window containing several Ttk
# menubutton widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttkmenu
catch {destroy $w}
toplevel $w
wm title $w "Ttk Menu Buttons"
wm iconname $w "ttkmenu"
positionWindow $w
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53



31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50



51
52
53







-
+












-
-
-
+
+
+

menu $w.m1.menu -tearoff 0
menu $w.m2.menu -tearoff 0
menu $w.m3.menu -tearoff 0
menu $w.m4.menu -tearoff 0
menu $w.m5.menu -tearoff 0

foreach theme [lsort [ttk::themes]] {
foreach theme [ttk::themes] {
    $w.m1.menu add command -label $theme -command [list ttk::setTheme $theme]
    $w.m2.menu add command -label $theme -command [list ttk::setTheme $theme]
    $w.m3.menu add command -label $theme -command [list ttk::setTheme $theme]
    $w.m4.menu add command -label $theme -command [list ttk::setTheme $theme]
    $w.m5.menu add command -label $theme -command [list ttk::setTheme $theme]
}

pack [ttk::frame $w.f] -fill x
pack [ttk::frame $w.f1] -fill both -expand yes
lower $w.f

grid anchor $w.f center
grid   x   $w.m1   x    -in $w.f -padx 2.25p -pady 1.5p
grid $w.m2 $w.m4 $w.m3  -in $w.f -padx 2.25p -pady 1.5p
grid   x   $w.m5   x    -in $w.f -padx 2.25p -pady 1.5p
grid   x   $w.m1   x    -in $w.f -padx 3 -pady 2
grid $w.m2 $w.m4 $w.m3  -in $w.f -padx 3 -pady 2
grid   x   $w.m5   x    -in $w.f -padx 3 -pady 2

Changes to library/demos/ttknote.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57


1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57









-
+

















-
+











-
-
-
+
+
+













-
-
+
+
# ttknote.tcl --
#
# This demonstration script creates a toplevel window containing a Ttk
# notebook widget.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttknote
catch {destroy $w}
toplevel $w
wm title $w "Ttk Notebook Widget"
wm iconname $w "ttknote"
positionWindow $w

## See Code / Dismiss
pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x

ttk::frame $w.f
pack $w.f -fill both -expand 1
set w $w.f

## Make the notebook and set up Ctrl+Tab traversal
ttk::notebook $w.note
pack $w.note -fill both -expand 1 -padx 1.5p -pady 3p
pack $w.note -fill both -expand 1 -padx 2 -pady 3
ttk::notebook::enableTraversal $w.note

## Popuplate the first pane
ttk::frame $w.note.msg
ttk::label $w.note.msg.m -font $font -wraplength 4i -justify left -anchor n -text "Ttk is the new Tk themed widget set. One of the widgets it includes is the notebook widget, which provides a set of tabs that allow the selection of a group of panels, each with distinct content. They are a feature of many modern user interfaces. Not only can the tabs be selected with the mouse, but they can also be switched between using Ctrl+Tab when the notebook page heading itself is selected. Note that the second tab is disabled, and cannot be selected."
ttk::button $w.note.msg.b -text "Neat!" -underline 0 -command {
    set neat "Yeah, I know..."
    after 500 {set neat {}}
}
bind $w <Alt-n> "focus $w.note.msg.b; $w.note.msg.b invoke"
ttk::label $w.note.msg.l -textvariable neat
$w.note add $w.note.msg -text "Description" -underline 0 -padding 1.5p
grid $w.note.msg.m - -sticky new -pady 1.5p
grid $w.note.msg.b $w.note.msg.l -pady {1.5p 3p}
$w.note add $w.note.msg -text "Description" -underline 0 -padding 2
grid $w.note.msg.m - -sticky new -pady 2
grid $w.note.msg.b $w.note.msg.l -pady {2 4}
grid rowconfigure $w.note.msg 1 -weight 1
grid columnconfigure $w.note.msg {0 1} -weight 1 -uniform 1

## Populate the second pane. Note that the content doesn't really matter
ttk::frame $w.note.disabled
$w.note add $w.note.disabled -text "Disabled" -state disabled

## Popuplate the third pane
ttk::frame $w.note.editor
$w.note add $w.note.editor -text "Text Editor" -underline 0
text $w.note.editor.t -width 40 -height 10 -wrap char \
	-yscroll "$w.note.editor.s set"
ttk::scrollbar $w.note.editor.s -orient vertical -command "$w.note.editor.t yview"
pack $w.note.editor.s -side right -fill y -padx {0 1.5p} -pady 1.5p
pack $w.note.editor.t -fill both -expand 1 -pady 1.5p -padx {1.5p 0}
pack $w.note.editor.s -side right -fill y -padx {0 2} -pady 2
pack $w.note.editor.t -fill both -expand 1 -pady 2 -padx {2 0}

Changes to library/demos/ttkpane.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







# ttkpane.tcl --
#
# This demonstration script creates a Ttk pane with some content.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttkpane
catch {destroy $w}
toplevel $w
wm title $w "Themed Nested Panes"
wm iconname $w "ttkpane"
positionWindow $w
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+







}

# Fill the button pane
ttk::button $w.outer.inLeft.top.b -text "Press Me" -command {
    tk_messageBox -type ok -icon info -message "Ouch!" -detail "That hurt..." \
	    -parent .ttkpane -title "Button Pressed"
}
pack $w.outer.inLeft.top.b -padx 1.5p -pady 3p
pack $w.outer.inLeft.top.b -padx 2 -pady 5

# Fill the clocks pane
set i 0
proc every {delay script} {
    uplevel #0 $script
    after $delay [list every $delay $script]
}
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107

108
109
110
111
112
93
94
95
96
97
98
99

100
101
102
103
104
105
106

107
108
109
110
111
112







-
+






-
+





    # The trick with the ttk::frame makes the text widget look like it fits with
    # the current Ttk theme despite not being a themed widget itself. It is done
    # by styling the frame like an entry, turning off the border in the text
    # widget, and putting the text widget in the frame with enough space to allow
    # the surrounding border to show through (2 pixels seems to be enough).
    ttk::frame $w.outer.inRight.bot.f				-style TEntry
    text $w.txt -wrap word -yscroll "$w.sb set" -width 30	-borderwidth 0
    pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot.f	-pady 1.5p -padx 1.5p
    pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot.f	-pady 2 -padx 2
    ttk::scrollbar $w.sb -orient vertical -command "$w.txt yview"
    pack $w.sb -side right -fill y -in $w.outer.inRight.bot
    pack $w.outer.inRight.bot.f -fill both -expand 1
    pack $w.outer -fill both -expand 1
} else {
    text $w.txt -wrap word -yscroll "$w.sb set" -width 30 -borderwidth 0
    ttk::scrollbar $w.sb -orient vertical -command "$w.txt yview"
    scrollbar $w.sb -orient vertical -command "$w.txt yview"
    pack $w.sb -side right -fill y -in $w.outer.inRight.bot
    pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot
    pack $w.outer -fill both -expand 1 -padx 10 -pady {6 10}
}

Changes to library/demos/ttkprogress.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25








-
+








-
+







# ttkprogress.tcl --
#
# This demonstration script creates several progress bar widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttkprogress
catch {destroy $w}
toplevel $w
wm title $w "Progress Bar Demonstration"
wm iconname $w "ttkprogress"
positionWindow $w

ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Below are two progress bars. The top one is a determinate progress bar, which is used for showing how far through a defined task the program has got. The bottom one is an indeterminate progress bar, which is used to show that the program is busy but does not know how long for. Both are run here in self-animated mode, which can be turned on and off using the buttons underneath."
ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Below are two progress bars. The top one is a \u201Cdeterminate\u201D progress bar, which is used for showing how far through a defined task the program has got. The bottom one is an \u201Cindeterminate\u201D progress bar, which is used to show that the program is busy but does not know how long for. Both are run here in self-animated mode, which can be turned on and off using the buttons underneath."
pack $w.msg -side top -fill x

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

ttk::frame $w.f
34
35
36
37
38
39
40
41
42
43



44
45
46
34
35
36
37
38
39
40



41
42
43
44
45
46







-
-
-
+
+
+



ttk::progressbar $w.p1 -mode determinate
ttk::progressbar $w.p2 -mode indeterminate
ttk::button $w.start -text "Start Progress" -command [list \
	doBars start $w.p1 $w.p2]
ttk::button $w.stop -text "Stop Progress" -command [list \
	doBars stop $w.p1 $w.p2]

grid $w.p1 - -pady 3p -padx 7.5p
grid $w.p2 - -pady 3p -padx 7.5p
grid $w.start $w.stop -padx 7.5p -pady 3p
grid $w.p1 - -pady 5 -padx 10
grid $w.p2 - -pady 5 -padx 10
grid $w.start $w.stop -padx 10 -pady 5
grid configure $w.start -sticky e
grid configure $w.stop -sticky w
grid columnconfigure $w all -weight 1

Changes to library/demos/ttkscale.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30

31
32
33
34
35
36
37
38
39
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29

30
31
32
33
34
35
36
37
38
39








-
+

















-
+


-
+









# ttkscale.tcl --
#
# This demonstration script shows an example with a horizontal scale.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .ttkscale
catch {destroy $w}
toplevel $w -bg [ttk::style lookup TLabel -background]
wm title $w "Themed Scale Demonstration"
wm iconname $w "ttkscale"
positionWindow $w

pack [ttk::frame [set w $w.contents]] -fill both -expand 1

ttk::label $w.msg -font $font -wraplength 3.5i -justify left -text "A label tied to a horizontal scale is displayed below.  If you click or drag mouse button 1 in the scale, you can change the contents of the label; a callback command is used to couple the slider to both the text and the coloring of the label."
pack $w.msg -side top -padx .5c

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons [winfo toplevel $w]]
pack $btns -side bottom -fill x

ttk::frame $w.frame -borderwidth 7.5p
ttk::frame $w.frame -borderwidth 10
pack $w.frame -side top -fill x

# List of colors from rainbow; "Indigo" is not a standard color
# List of colors from rainbox; "Indigo" is not a standard color
set colorList {Red Orange Yellow Green Blue Violet}
ttk::label $w.frame.label
ttk::scale $w.frame.scale -from 0 -to 5 -command [list apply {{w idx} {
    set c [lindex $::colorList [tcl::mathfunc::int $idx]]
    $w.frame.label configure -foreground $c -text "Color: $c"
}} $w]
# Trigger the setting of the label's text
$w.frame.scale set 0
pack $w.frame.label $w.frame.scale

Deleted library/demos/ttkspin.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# ttkspin.tcl --
#
# This demonstration script creates several Ttk spinbox widgets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk

set w .ttkspin
catch {destroy $w}
toplevel $w
wm title $w "Themed Spinbox Demonstration"
wm iconname $w "ttkspin"
positionWindow $w

label $w.msg -font $font -wraplength 5i -justify left -text "Three different\
	themed spin-boxes are displayed below.  You can add characters by\
	pointing, clicking and typing.  The normal Motif editing characters\
	are supported, along with many Emacs bindings.  For example, Backspace\
	and Control-h delete the character to the left of the insertion\
	cursor and Delete and Control-d delete the chararacter to the right\
	of the insertion cursor.  For values that are too large to fit in the\
	window all at once, you can scan through the value by dragging with\
	mouse button2 pressed.  Note that the first spin-box will only permit\
	you to type in integers, and the third selects from a list of\
	Australian cities."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

set australianCities {
    Canberra Sydney Melbourne Perth Adelaide Brisbane
    Hobart Darwin "Alice Springs"
}

ttk::spinbox $w.s1 -from 1 -to 10 -width 10 -validate key \
	-validatecommand {string is integer %P}
ttk::spinbox $w.s2 -from 0 -to 3 -increment .5 -format %05.2f -width 10
ttk::spinbox $w.s3 -values $australianCities -width 10

$w.s1 set 1
$w.s2 set 00.00
$w.s3 set Canberra

pack $w.s1 $w.s2 $w.s3 -side top -pady 3p -padx 7.5p

Changes to library/demos/twind.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9

10








11
12
13
14
15
16
17









-
+
-
-
-
-
-
-
-
-







# twind.tcl --
#
# This demonstration script creates a text widget with a bunch of
# embedded windows.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

# Make an Aqua button's fill color match its parent's background
proc blend {bt} {
    if {[tk windowingsystem] eq "aqua"} {
	$bt configure -highlightbackground [[winfo parent $bt] cget -background]
    }
    return $bt
}

set w .twind
catch {destroy $w}
toplevel $w
wm title $w "Text Demonstration - Embedded Windows and Other Features"
wm iconname $w "Embedded Windows"
positionWindow $w
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39







-
+







text $t -yscrollcommand "$w.scroll set" -setgrid true -font $font -width 70 \
	-height 35 -wrap word -highlightthickness 0 -borderwidth 0
pack $t -expand  yes -fill both
ttk::scrollbar $w.scroll -command "$t yview"
pack $w.scroll -side right -fill y
panedwindow $w.pane
pack $w.pane -expand yes -fill both
$w.pane add $w.f -stretch always
$w.pane add $w.f
# Import to raise given creation order above
raise $w.f

$t tag configure center -justify center -spacing1 5m -spacing3 5m
$t tag configure buttons -lmargin1 1c -lmargin2 1c -rmargin 1c \
	-spacing1 3m -spacing2 0 -spacing3 0

57
58
59
60
61
62
63
64

65
66
67
68

69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103






104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137


138
139
140
141
142
143
144
145


146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174






175
176
177
178
179

180
181
182
183

184
185
186
187
188
189

190
191
192
193

194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
49
50
51
52
53
54
55

56
57
58
59

60
61
62
63
64
65

66


67
68
69
70
71
72
73
74

75

76
77
78
79
80
81
82

83

84
85






86
87
88
89
90
91
92
93
94

95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

115
116

117
118
119
120
121


122
123
124
125
126
127
128
129


130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154






155
156
157
158
159
160
161
162
163


164




165

166

167
168

169
170
171
172

173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198







-
+



-
+





-
+
-
-








-
+
-







-
+
-


-
-
-
-
-
-
+
+
+
+
+
+



-
+
-



















-


-
+




-
-
+
+






-
-
+
+


-
+




















-
-
-
-
-
-
+
+
+
+
+
+



-
-
+
-
-
-
-
+
-

-


-
+



-
+



-
+













+







$t insert end "scrolling in all directions is provided.\n\n"

$t insert end "A text widget can contain other widgets embedded "
$t insert end "it.  These are called \"embedded windows\", "
$t insert end "and they can consist of arbitrary widgets.  "
$t insert end "For example, here are two embedded button "
$t insert end "widgets.  You can click on the first button to "
$t window create end -window [blend $t.on]
$t window create end -window $t.on
$t insert end " horizontal scrolling, which also turns off "
$t insert end "word wrapping.  Or, you can click on the second "
$t insert end "button to\n"
$t window create end -window [blend $t.off]
$t window create end -window $t.off
$t insert end " horizontal scrolling and turn back on word wrapping.\n\n"

$t insert end "Or, here is another example.  If you "
$t window create end -create {
    button %W.click -text "Click Here" -command "textWindPlot %W" \
	-cursor top_left_arrow
	    -cursor top_left_arrow}
    blend %W.click
}

$t insert end " a canvas displaying an x-y plot will appear right here."
$t mark set plot insert
$t mark gravity plot left
$t insert end "  You can drag the data points around with the mouse, "
$t insert end "or you can click here to "
$t window create end -create {
    button %W.delete -text "Delete" -command "textWindDel %W" \
	-cursor top_left_arrow
	    -cursor top_left_arrow
    blend %W.delete
}
$t insert end " the plot again.\n\n"

$t insert end "You can also create multiple text widgets each of which "
$t insert end "display the same underlying text. Click this button to "
$t window create end \
  -create {button %W.peer -text "Make A Peer" -command "textMakePeer %W" \
	       -cursor top_left_arrow
  -cursor top_left_arrow} -padx 3
      blend %W.peer} -padx 3p
$t insert end " widget.  Notice how peer widgets can have different "
$t insert end "font settings, and by default contain all the images "
$t insert end "of the 'parent', but that the embedded windows, "
$t insert end "such as buttons may not appear in the peer.  To ensure "
$t insert end "that embedded windows appear in all peers you can set the "
$t insert end "'-create' option to a script or a string containing %W.  "
$t insert end "(The plot above and the 'Make A Peer' button are "
$t insert end "designed to show up in all peers.)  A good use of "
$t insert end "of the 'parent', but many of the embedded windows, "
$t insert end "such as buttons will not be there.  The easiest way "
$t insert end "to ensure they are in all peers is to use '-create' "
$t insert end "embedded window creation scripts "
$t insert end "(the plot above and the 'Make A Peer' button are "
$t insert end "designed to show up in all peers).  A good use of "
$t insert end "peers is for "
$t window create end \
  -create {button %W.split -text "Split Windows" -command "textSplitWindow %W" \
	       -cursor top_left_arrow
  -cursor top_left_arrow} -padx 3
      blend %W.split} -padx 3p
$t insert end " \n\n"

$t insert end "Users of previous versions of Tk will also be interested "
$t insert end "to note that now cursor movement is now by visual line by "
$t insert end "default, and that all scrolling of this widget is by pixel.\n\n"

$t insert end "You may also find it useful to put embedded windows in "
$t insert end "a text without any actual text.  In this case the "
$t insert end "text widget acts like a geometry manager.  For "
$t insert end "example, here is a collection of buttons laid out "
$t insert end "neatly into rows by the text widget.  These buttons "
$t insert end "can be used to change the background color of the "
$t insert end "text widget (\"Default\" restores the color to "
$t insert end "its default).  If you click on the button labeled "
$t insert end "\"Short\", it changes to a longer string so that "
$t insert end "you can see how the text widget automatically "
$t insert end "changes the layout.  Click on the button again "
$t insert end "to restore the short string.\n"

$t insert end "\nNOTE: these buttons will not appear in peers!\n" "peer_warning"
button $t.default -text Default -command "embDefBg $t" \
	-cursor top_left_arrow
$t window create end -window $t.default -padx 3p
$t window create end -window $t.default -padx 3
global embToggle
set embToggle Short
checkbutton $t.toggle -textvariable embToggle -indicatoron 0 \
	-variable embToggle -onvalue "A much longer string" \
	-offvalue "Short" -cursor top_left_arrow -pady 3p -padx 1.5p
$t window create end -window $t.toggle -padx 3p -pady 1.5p
	-offvalue "Short" -cursor top_left_arrow -pady 5 -padx 2
$t window create end -window $t.toggle -padx 3 -pady 2
set i 1
foreach color {AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
	SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3 LightBlue1
	DarkSlateGray1 Aquamarine2 DarkSeaGreen2 SeaGreen1
	Yellow1 IndianRed1 IndianRed2 Tan1 Tan4} {
    button $t.color$i -text $color -cursor top_left_arrow -command \
	    "changeBg $t $color"
    $t window create end -window [blend $t.color$i] -padx 3p -pady 1.5p
	    "$t configure -bg $color"
    $t window create end -window $t.color$i -padx 3 -pady 2
    incr i
}
$t tag add buttons [blend $t.default] end
$t tag add buttons $t.default end

button $t.bigB -text "Big borders" -command "textWindBigB $t" \
  -cursor top_left_arrow
button $t.smallB -text "Small borders" -command "textWindSmallB $t" \
  -cursor top_left_arrow
button $t.bigH -text "Big highlight" -command "textWindBigH $t" \
  -cursor top_left_arrow
button $t.smallH -text "Small highlight" -command "textWindSmallH $t" \
  -cursor top_left_arrow
button $t.bigP -text "Big pad" -command "textWindBigP $t" \
  -cursor top_left_arrow
button $t.smallP -text "Small pad" -command "textWindSmallP $t" \
  -cursor top_left_arrow

set text_normal(border) [$t cget -borderwidth]
set text_normal(highlight) [$t cget -highlightthickness]
set text_normal(pad) [$t cget -padx]

$t insert end "\nYou can also change the usual border width and "
$t insert end "highlightthickness and padding.\n"
$t window create end -window [blend $t.bigB]
$t window create end -window [blend $t.smallB]
$t window create end -window [blend $t.bigH]
$t window create end -window [blend $t.smallH]
$t window create end -window [blend $t.bigP]
$t window create end -window [blend $t.smallP]
$t window create end -window $t.bigB
$t window create end -window $t.smallB
$t window create end -window $t.bigH
$t window create end -window $t.smallH
$t window create end -window $t.bigP
$t window create end -window $t.smallP

$t insert end "\n\nFinally, images fit comfortably in text widgets too:"

image create photo img -file [file join $tk_demoDirectory images ouster.png]

$t image create end -image \
# Create a copy of the image just created, magnified according to the
# display's DPI scaling level.  Since the zooom factor must be an integer,
# the copy will only be effectively magnified if $tk::scalingPct >= 200.
image create photo img2
    [image create photo -file [file join $tk_demoDirectory images ouster.png]]
img2 copy img -zoom [expr {$tk::scalingPct / 100}]

$t image create end -image img2

proc textWindBigB w {
    $w configure -borderwidth 12p
    $w configure -borderwidth 15
}

proc textWindBigH w {
    $w configure -highlightthickness 12p
    $w configure -highlightthickness 15
}

proc textWindBigP w {
    $w configure -padx 12p -pady 12p
    $w configure -padx 15 -pady 15
}

proc textWindSmallB w {
    $w configure -borderwidth $::text_normal(border)
}

proc textWindSmallH w {
    $w configure -highlightthickness $::text_normal(highlight)
}

proc textWindSmallP w {
    $w configure -padx $::text_normal(pad) -pady $::text_normal(pad)
}


proc textWindOn w {
    catch {destroy $w.scroll2}
    set t $w.f.text
    ttk::scrollbar $w.scroll2 -orient horizontal -command "$t xview"
    pack $w.scroll2 -after $w.buttons -side bottom -fill x
    $t configure -xscrollcommand "$w.scroll2 set" -wrap none
268
269
270
271
272
273
274
275
276
277



278
279
280
281
282
283
284
249
250
251
252
253
254
255



256
257
258
259
260
261
262
263
264
265







-
-
-
+
+
+







	set y [expr {250 - (4*[lindex $point 1])/5}]
	set item [$c create oval [expr {$x-6}] [expr {$y-6}] \
		[expr {$x+6}] [expr {$y+6}] -width 1 -outline black \
		-fill SkyBlue2]
	$c addtag point withtag $item
    }

    $c bind point <Enter> "$c itemconfig current -fill red"
    $c bind point <Leave> "$c itemconfig current -fill SkyBlue2"
    $c bind point <Button-1> "embPlotDown $c %x %y"
    $c bind point <Any-Enter> "$c itemconfig current -fill red"
    $c bind point <Any-Leave> "$c itemconfig current -fill SkyBlue2"
    $c bind point <1> "embPlotDown $c %x %y"
    $c bind point <ButtonRelease-1> "$c dtag selected"
    bind $c <B1-Motion> "embPlotMove $c %x %y"
    return $c
}

set embPlot(lastX) 0
set embPlot(lastY) 0
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357
358
286
287
288
289
290
291
292











293

294

295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315
316
317
318
319


320
321
322
323
324
325







-
-
-
-
-
-
-
-
-
-
-

-
+
-










-















-
-
+





	while {[string first [$t get plot] " \t\n"] >= 0} {
	    $t delete plot
	}
	$t insert plot "  "
    }
}

proc changeBg {t c} {
    $t configure -background $c
    if {[tk windowingsystem] eq "aqua"} {
	foreach b [$t window names] {
	    if {[winfo class $b] eq "Button"} {
		$b configure -highlightbackground $c
	    }
	}
    }
}

proc embDefBg t {
    set bg [lindex [$t configure -background] 3]
    $t configure -background [lindex [$t configure -background] 3]
    changeBg $t $bg
}

proc textMakePeer {parent} {
    set n 1
    while {[winfo exists .peer$n]} { incr n }
    set w [toplevel .peer$n]
    wm title $w "Text Peer #$n"
    frame $w.f -highlightthickness 1 -borderwidth 1 -relief sunken
    set t [$parent peer create $w.f.text -yscrollcommand "$w.scroll set" \
	       -borderwidth 0 -highlightthickness 0]
    $t tag configure peer_warning -font boldFont
    pack $t -expand  yes -fill both
    ttk::scrollbar $w.scroll -command "$t yview"
    pack $w.scroll -side right -fill y
    pack $w.f -expand yes -fill both
}

proc textSplitWindow {textW} {
    if {$textW eq ".twind.f.text"} {
	if {[winfo exists .twind.peer]} {
	    destroy .twind.peer
	} else {
	    set parent [winfo parent $textW]
	    set w [winfo parent $parent]
	    set t [$textW peer create $w.peer \
	      -yscrollcommand "$w.scroll set"]
	    $t tag configure peer_warning -font boldFont
	    $w.pane add $t -stretch always
	    $w.pane add $t
	}
    } else {
        return
    }
}

Changes to library/demos/unicodeout.tcl.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33









-
+













-
+
+
+







# unicodeout.tcl --
#
# This demonstration script shows how you can produce output (in label
# widgets) using many different alphabets.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .unicodeout
catch {destroy $w}
toplevel $w
wm title $w "Unicode Label Demonstration"
wm iconname $w "unicodeout"
positionWindow $w

label $w.msg -font $font -wraplength 4i -anchor w -justify left \
	-text "This is a sample of Tk's support for languages that use\
	non-Western character sets.  However, what you will actually see\
	below depends largely on what character sets you have installed,\
	and what you see for characters that are not present varies greatly\
	between platforms as well."
	between platforms as well.  The strings are written in Tcl using\
	UNICODE characters using the \\uXXXX escape so as to do so in a\
	portable fashion."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

## The frame that will contain the sample texts.
92
93
94
95
96
97
98
99



100
101
102



103
104
105
106
107






108
109
110


111
112
113


114
115
116
117
118
119








120
121
122

123
124
125
126
94
95
96
97
98
99
100

101
102
103
104
105

106
107
108
109




110
111
112
113
114
115
116
117

118
119
120
121

122
123
124





125
126
127
128
129
130
131
132



133
134
135
136
137







-
+
+
+


-
+
+
+

-
-
-
-
+
+
+
+
+
+


-
+
+


-
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+




set oldCursor [$w cget -cursor]
$w conf -cursor watch
update

## Add the samples...
if {[usePresentationFormsFor Arabic]} {
    # Using presentation forms (pre-layouted)
    addSample $w Arabic "ﺔﻴﺑﺮﻌﻟﺍ ﺔﻤﻠﻜﻟﺍ"
    addSample $w Arabic \
	    "\uFE94\uFEF4\uFE91\uFEAE\uFECC\uFEDF\uFE8D " \
	    "\uFE94\uFEE4\uFEE0\uFEDC\uFEDF\uFE8D"
} else {
    # Using standard text characters
    addSample $w Arabic "الكلمة العربية"
    addSample $w Arabic \
	    "\u0627\u0644\u0643\u0644\u0645\u0629 " \
	    "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
}
addSample $w "Trad. Chinese"  "中國的漢字"
addSample $w "Simpl. Chinese" "汉语"
addSample $w French "Langue française"
addSample $w Greek "Ελληνική γλώσσα"
addSample $w "Trad. Chinese"  "\u4E2D\u570B\u7684\u6F22\u5B57"
addSample $w "Simpl. Chinese" "\u6C49\u8BED"
addSample $w French "Langue fran\u00E7aise"
addSample $w Greek \
	 "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE " \
	 "\u03B3\u03BB\u03CE\u03C3\u03C3\u03B1"
if {[usePresentationFormsFor Hebrew]} {
    # Visual order (pre-layouted)
    addSample $w Hebrew "תירבע בתכ"
    addSample $w Hebrew \
	    "\u05EA\u05D9\u05E8\u05D1\u05E2 \u05D1\u05EA\u05DB"
} else {
    # Standard logical order
    addSample $w Hebrew "כתב עברית"
    addSample $w Hebrew \
	    "\u05DB\u05EA\u05D1 \u05E2\u05D1\u05E8\u05D9\u05EA"
}
addSample $w Hindi "हिन्दी भाषा"
addSample $w Icelandic "Íslenska"
addSample $w Japanese "日本語のひらがな, 漢字とカタカナ"
addSample $w Korean "대한민국의 한글"
addSample $w Russian "Русский язык"
addSample $w Hindi \
    "\u0939\u093f\u0928\u094d\u0926\u0940 \u092d\u093e\u0937\u093e"
addSample $w Icelandic "\u00CDslenska"
addSample $w Japanese \
	 "\u65E5\u672C\u8A9E\u306E\u3072\u3089\u304C\u306A, " \
	 "\u6F22\u5B57\u3068\u30AB\u30BF\u30AB\u30CA"
addSample $w Korean "\uB300\uD55C\uBBFC\uAD6D\uC758 \uD55C\uAE00"
addSample $w Russian \
if {([tk windowingsystem] ne "x11") || (![catch {tk::pkgconfig get fontsystem} fs] && ($fs eq "xft"))} {
    addSample $w Emoji "😀💩👍🇳🇱"
}
	"\u0420\u0443\u0441\u0441\u043A\u0438\u0439 \u044F\u0437\u044B\u043A"

## We're done processing, so change things back to normal running...
destroy $w.wait
$w conf -cursor $oldCursor

Changes to library/demos/vscale.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30

31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29

30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45

46












-
+















-
+


-
+

-
+


-
+












-
+
-
-
-
-
# vscale.tcl --
#
# This demonstration script shows an example with a vertical scale.

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require tk
package require Tk

set w .vscale
catch {destroy $w}
toplevel $w
wm title $w "Vertical Scale Demonstration"
wm iconname $w "vscale"
positionWindow $w

label $w.msg -font $font -wraplength 3.5i -justify left -text "An arrow and a vertical scale are displayed below.  If you click or drag mouse button 1 in the scale, you can change the size of the arrow."
pack $w.msg -side top -padx .5c

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

frame $w.frame -borderwidth 7.5p
frame $w.frame -borderwidth 10
pack $w.frame

scale $w.frame.scale -orient vertical -length 213p -from 0 -to 250 \
scale $w.frame.scale -orient vertical -length 284 -from 0 -to 250 \
	-command "setHeight $w.frame.canvas" -tickinterval 50
canvas $w.frame.canvas -width 37.5p -height 37.5p -bd 0 -highlightthickness 0
canvas $w.frame.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
$w.frame.canvas create polygon 0 0 1 1 2 2 -fill SeaGreen3 -tags poly
$w.frame.canvas create line 0 0 1 1 2 2 0 0 -fill black -tags line
frame $w.frame.right -borderwidth 11.25p
frame $w.frame.right -borderwidth 15
pack $w.frame.scale -side left -anchor ne
pack $w.frame.canvas -side left -anchor nw -fill y
$w.frame.scale set 75

proc setHeight {w height} {
    incr height 21
    set y2 [expr {$height - 30}]
    if {$y2 < 21} {
	set y2 21
    }
    $w coords poly 15 20 35 20 35 $y2 45 $y2 25 $height 5 $y2 15 $y2 15 20
    $w coords line 15 20 35 20 35 $y2 45 $y2 25 $height 5 $y2 15 $y2 15 20

}
    set scaleFactor [expr {$tk::scalingPct / 100.0}]
    $w scale poly 0 0 $scaleFactor $scaleFactor
    $w scale line 0 0 $scaleFactor $scaleFactor
}

Changes to library/demos/widget.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16

17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15

16
17
18
19
20
21
22
23












-
+


-
+







#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

# widget --
# This script demonstrates the various widgets provided by Tk, along with many
# of the features of the Tk toolkit. This file only contains code to generate
# the main window for the application, which invokes individual
# demonstrations. The code for the actual demonstrations is contained in
# separate ".tcl" files is this directory, which are sourced by this script as
# needed.

package require tk
package require Tk	8.5
package require msgcat

destroy {*}[winfo children .]
eval destroy [winfo child .]
set tk_demoDirectory [file join [pwd] [file dirname [info script]]]
::msgcat::mcload $tk_demoDirectory
namespace import ::msgcat::mc
wm title . [mc "Widget Demonstration"]
if {[tk windowingsystem] eq "x11"} {
    # This won't work everywhere, but there's no other way in core Tk at the
    # moment to display a coloured icon.
53
54
55
56
57
58
59
60
61


62
63
64
65

66
67
68
69
70

71
72
73
74
75
76
77




78
79
80
81
82
83
84
85



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107





108
109

110
111
112

113
114
115
116
117
118
119
120


121
122
123
124
125






126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156


157
158
159
160
161
162
163
164

165
166
167

168
169

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
53
54
55
56
57
58
59


60
61




62





63
64
65





66
67
68
69
70
71






72
73
74
75






76












77


78
79
80
81
82


83



84








85
86





87
88
89
90
91
92
93
94

95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130

131
132
133

134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158







-
-
+
+
-
-
-
-
+
-
-
-
-
-
+


-
-
-
-
-
+
+
+
+


-
-
-
-
-
-
+
+
+

-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+


-
+






-



















-

+
+







-
+


-
+

-
+














-
+







        font create varsFont   -family Helvetica -size 14
    }
}

set widgetDemo 1
set font mainFont

# The SVG images used below are based on some icons provided by the
# official open source SVG icon library for the Bootstrap project,
image create photo ::img::refresh -format GIF -data {
    R0lGODlhEAAQAJEDAP///wAAACpnKv///yH5BAEAAAMALAAAAAAQABAAAAI63IKp
# licensed under the MIT license (https://opensource.org/licenses/MIT).
#
# See https://github.com/twbs/icons.

    xgcPH2ouwgBCw1HIxHCQ4F3hSJKmwZXqWrmWxj7lKJ2dndcon9EBUq+gz3brVXAR
set viewData {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" fill="#000000"/>
    </svg>
    2tICU0gXBQA7
}

set refreshData {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="M11 5.466V4H5a4 4 0 0 0-3.584 5.777.5.5 0 1 1-.896.446A5 5 0 0 1 5 3h6V1.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384l-2.36 1.966a.25.25 0 0 1-.41-.192Zm3.81.086a.5.5 0 0 1 .67.225A5 5 0 0 1 11 13H5v1.466a.25.25 0 0 1-.41.192l-2.36-1.966a.25.25 0 0 1 0-.384l2.36-1.966a.25.25 0 0 1 .41.192V12h6a4 4 0 0 0 3.585-5.777.5.5 0 0 1 .225-.67Z" fill="#000000"/>
    </svg>
image create photo ::img::view -format GIF -data {
    R0lGODlhEAAQAKIHAP///wwMDAAAAMDAwNnZ2SYmJmZmZv///yH5BAEAAAcALAAA
    AAAQABAAAANMKLos90+ASamDRxJCgw9YVnlDOXiQBgRDBRgHKE6sW8QR3doPKK27
    yg33q/GIOhdg6OsEJzeZykiBSUcs06e56Xx6np8ScIkFGuhQAgA7
}

set printData {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="M2.5 8a.5.5 0 1 0 0-1 .5.5 0 0 0 0 1z" fill="#000000"/>
     <path d="M5 1a2 2 0 0 0-2 2v2H2a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h1v1a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2v-1h1a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-1V3a2 2 0 0 0-2-2H5zM4 3a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2H4V3zm1 5a2 2 0 0 0-2 2v1H2a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-1v-1a2 2 0 0 0-2-2H5zm7 2v3a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1z" fill="#000000"/>
    </svg>
image create photo ::img::delete -format GIF -data {
    R0lGODlhEAAQAIABAIQAAP///yH5BAEAAAEALAAAAAAQABAAAAIjjI+pmwAc3HGy
    PUSvqYpuvWQg40FfSVacBa5nN6JYDI3mzRQAOw==
}

proc images {arg} {
    set fgColor [ttk::style lookup . -foreground {} black]
    lassign [winfo rgb . $fgColor] r g b
    set fgColor [format "#%02x%02x%02x" \
	    [expr {$r >> 8}] [expr {$g >> 8}] [expr {$b >> 8}]]

    foreach action {view refresh print} {
	upvar ${action}Data imgData
	for {set data $imgData; set startIdx 0} \
		{[set idx1 [string first "#000000" $data $startIdx]] >= 0} \
		{set startIdx [expr {$idx1 + 7}]} {
	    set idx2 [expr {$idx1 + 6}]
	    set data [string replace $data $idx1 $idx2 $fgColor]
	}

	switch $arg {
	    create {
		image create photo ::img::$action -format $::tk::svgFmt \
image create photo ::img::print -format GIF -data {
			-data $data
	    }
    R0lGODlhEAAQALMKAAAAAP///52VunNkl8C82Yl+qldBgq+pyrOzs1fYAP///wAA
    AAAAAAAAAAAAAAAAACH5BAEAAAoALAAAAAAQABAAAARGUMlJKwU4AztB+ODGeUiJ
    fGLlgeEYmGWQXmx7aXgmAUTv/74N4EAsGhOJg1DAbDqbwoJ0Sp0KB9isNis0eL/g
    ryhH5pgnEQA7
}
	    configure { ::img::$action configure -data $data }
	}

    }
}

# Note that this is run through the message catalog! This is because this is
images create
set mainClass [winfo class .]
foreach event {<<ThemeChanged>> <<LightAqua>> <<DarkAqua>>} {
    bind $mainClass $event { images configure }
}
unset mainClass event

image create photo ::img::delete -format $::tk::svgFmt -data {
# actually an image of a word.
image create photo ::img::new -format GIF -data [mc {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <path d="M2.146 2.854a.5.5 0 1 1 .708-.708L8 7.293l5.146-5.147a.5.5 0 0 1 .708.708L8.707 8l5.147 5.146a.5.5 0 0 1-.708.708L8 8.707l-5.146 5.147a.5.5 0 0 1-.708-.708L7.293 8 2.146 2.854Z" fill="#d00000"/>
    </svg>
}
    R0lGODlhHgAOALMPALMAANyIiOu7u8dEROaqqvru7sxVVeGZmbgREfXd3b0iItZ3
    d8IzM9FmZvDMzP///yH5BAEAAA8ALAAAAAAeAA4AAASa8MlJq7046827WVOCHEkw
    nANhUgJlEBIABJIwL3K+4IcUALCHjfbItYZDSgJgkBiYPmBMAUAkkLPKs/BAyLgM
    wAQwOAAY2ByCaw4QAFQSoDEePJ6DmU1xInYZTw5nOEFFdgVUelkVDTIMd3AKFGQ1
    MgI2AwEmQW8APZ0gdRONAks5nhIFVVxdAAkUAS2pAVwFl7ITB4UqHb0XEQA7
}]

#----------------------------------------------------------------
# The code below creates the main window, consisting of a menu bar and a text
# The code below create the main window, consisting of a menu bar and a text
# widget that explains how to use the program, plus lists all of the demos as
# hypertext items.
#----------------------------------------------------------------

menu .menuBar -tearoff 0

# On Aqua, just use the default menu.
if {[tk windowingsystem] ne "aqua"} {
    # This is a tk-internal procedure to make i18n easier
    ::tk::AmpMenuArgs .menuBar add cascade -label [mc "&File"] \
	    -menu .menuBar.file
    menu .menuBar.file -tearoff 0
    ::tk::AmpMenuArgs .menuBar.file add command -label [mc "&About..."] \
	    -command {tkAboutDialog} -accelerator [mc "<F1>"]
    bind . <F1> {tkAboutDialog}
    .menuBar.file add sep
    if {[string match win* [tk windowingsystem]]} {
	# Windows doesn't usually have a Meta key
	::tk::AmpMenuArgs .menuBar.file add command -label [mc "&Quit"] \
		-command {exit} -accelerator [mc "Ctrl+Q"]
	bind . <[mc "Control-q"]> {exit}
    } else {
	::tk::AmpMenuArgs .menuBar.file add command -label [mc "&Quit"] \
		-command {exit} -accelerator [mc "Meta-Q"]
	bind . <[mc "Meta-q"]> {exit}
    }
    . configure -menu .menuBar
}

. configure -menu .menuBar

ttk::frame .statusBar
ttk::label .statusBar.lab -text "   " -anchor w
if {[tk windowingsystem] eq "aqua"} {
    ttk::separator .statusBar.sep
    pack .statusBar.sep -side top -expand yes -fill x -pady 0
}
pack .statusBar.lab -side left -padx 1.5p -expand yes -fill both
pack .statusBar.lab -side left -padx 2 -expand yes -fill both
if {[tk windowingsystem] ne "aqua"} {
    ttk::sizegrip .statusBar.foo
    pack .statusBar.foo -side left -padx 1.5p
    pack .statusBar.foo -side left -padx 2
}
pack .statusBar -side bottom -fill x -pady 1.5p
pack .statusBar -side bottom -fill x -pady 2

set textheight 30
catch {
    set textheight [expr {
	([winfo screenheight .] * 0.7) /
	[font metrics mainFont -displayof . -linespace]
    }]
}

ttk::frame .textFrame
ttk::scrollbar .s -orient vertical -command {.t yview} -takefocus 1
pack .s -in .textFrame -side right -fill y
text .t -yscrollcommand {.s set} -wrap word -width 70 -height $textheight \
	-font mainFont -setgrid 1 -highlightthickness 0 \
	-padx 3p -pady 1.5p -takefocus 0
	-padx 4 -pady 2 -takefocus 0
pack .t -in .textFrame -expand y -fill both -padx 1
pack .textFrame -expand yes -fill both
if {[tk windowingsystem] eq "aqua"} {
    pack configure .statusBar.lab -padx {10 18} -pady {4 6}
    pack configure .statusBar -pady 0
    .t configure -padx 10 -pady 0
}
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
182
183
184
185
186
187
188




189
190





191
192
193
194
195
196
197







-
-
-
-


-
-
-
-
-







	-underline 1
    .t tag configure hot -background black -foreground white
} else {
    .t tag configure demo -lmargin1 1c -lmargin2 1c \
	-foreground blue -underline 1
    .t tag configure visited -lmargin1 1c -lmargin2 1c \
	-foreground #303080 -underline 1
    if {[tk windowingsystem] eq "aqua"} {
	.t tag configure demo -foreground systemLinkColor
	.t tag configure visited -foreground purple
    }
    .t tag configure hot -foreground red -underline 1
}

# The tag "new" must be the one having the highest priority.
#
.t tag configure new -foreground #c00000 -underline 0 -font boldFont

.t tag bind demo <ButtonRelease-1> {
    invoke [.t index {@%x,%y}]
}
set lastLine ""
.t tag bind demo <Enter> {
    set lastLine [.t index {@%x,%y linestart}]
    .t tag add hot "$lastLine +1 chars" "$lastLine lineend -1 chars"
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273







-
+







		    set demoCount 0
		}
		demo {
		    set description [lassign $values name]
		    .t insert end "[incr demoCount]. [mc $description]" \
			    [list demo demo-$name]
		    if {$new} {
			.t insert end " [mc NEW]" new
			.t image create end -image ::img::new -padx 5
			set new 0
		    }
		    .t insert end " \n " demospace
		}
		new {
		    set new 1
		}
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
313
314
315
316
317
318
319

320














321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-







    @@demo radio	Radio-buttons (select one of a group)
    @@demo puzzle	A 15-puzzle game made out of buttons
    @@demo icon		Iconic buttons that use bitmaps
    @@demo image1	Two labels displaying images
    @@demo image2	A simple user interface for viewing images
    @@demo labelframe	Labelled frames
    @@demo ttkbut	The simple Themed Tk widgets
}


if {[tk windowingsystem] eq "aqua"} {
    addFormattedText {
	@@subtitle Mac-Specific Widgets and Window Styles
	@@new
	@@demo mac_styles	Special widgets for macOS
	@@new
	@@demo mac_wm	Window styles for macOS
	@@new
	@@demo mac_tabs	Tabbed Windows on macOS
    }
}

addFormattedText {
    @@subtitle	Listboxes and Trees
    @@demo states	The 50 states
    @@demo colors	Colors: change the color scheme for the application
    @@demo sayings	A collection of famous and infamous sayings
    @@demo mclist	A multi-column list of countries
    @@demo tree		A directory browser tree

    @@subtitle	Entries, Spin-boxes and Combo-boxes
    @@demo entry1	Entries without scrollbars
    @@demo entry2	Entries with scrollbars
    @@demo entry3	Validated entries and password fields
    @@demo spin		Spin-boxes
    @@demo ttkspin	Themed spin-boxes
    @@demo combo	Combo-boxes
    @@demo form		Simple Rolodex-like form

    @@subtitle	Text
    @@demo text		Basic editable text
    @@demo style	Text display styles
    @@demo bind		Hypertext (tag bindings)
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469

470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377




378
379
380
381
382
383
384
385
386
387
388


389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406

407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
431







+




















-
-
-
-











-
-
















-

+
-
+
















-
+







    @@demo floor	A building floor plan
    @@demo cscroll	A simple scrollable canvas
    @@demo knightstour  A Knight's tour of the chess board

    @@subtitle	Scales and Progress Bars
    @@demo hscale	Horizontal scale
    @@demo vscale	Vertical scale
    @@new
    @@demo ttkscale	Themed scale linked to a label with traces
    @@demo ttkprogress	Progress bar

    @@subtitle	Paned Windows and Notebooks
    @@demo paned1	Horizontal paned window
    @@demo paned2	Vertical paned window
    @@demo ttkpane	Themed nested panes
    @@demo ttknote	Notebook widget

    @@subtitle	Menus and Toolbars
    @@demo menu		Menus and cascades (sub-menus)
    @@demo menubu	Menu-buttons
    @@demo ttkmenu	Themed menu buttons
    @@demo toolbar	Themed toolbar

    @@subtitle	Common Dialogs
    @@demo msgbox	Message boxes
    @@demo filebox	File selection dialog
    @@demo clrpick	Color picker
    @@demo fontchoose	Font selection dialog
    @@new
    @@demo systray      System tray icon and notification
    @@new
    @@demo print        Printing from canvas and text widgets

    @@subtitle	Animation
    @@demo anilabel	Animated labels
    @@demo aniwave	Animated wave
    @@demo pendulum	Pendulum simulation
    @@demo goldberg	A celebration of Rube Goldberg

    @@subtitle	Miscellaneous
    @@demo bitmap	The built-in bitmaps
    @@demo dialog1	A dialog box with a local grab
    @@demo dialog2	A dialog box with a global grab
    @@new
    @@demo windowicons  Window icons and badges
}

##############################################################################

.t configure -state disabled
focus .s

# addSeeDismiss --
# Add "See Code" and "Dismiss" button frame, with optional "See Vars"
#
# Arguments:
# w -		The name of the frame to use.

proc addSeeDismiss {w show {vars {}} {extra {}}} {
    ## See Code / Dismiss buttons
    ttk::frame $w
    #ttk::frame $w.sep -height 2 -relief sunken
    ttk::separator $w.sep
    #ttk::frame $w.sep -height 2 -relief sunken
    grid $w.sep -columnspan 4 -row 0 -sticky ew -pady 1.5p
    grid $w.sep -columnspan 4 -row 0 -sticky ew -pady 2
    ttk::button $w.dismiss -text [mc "Dismiss"] \
	-image ::img::delete -compound left \
	-command [list destroy [winfo toplevel $w]]
    ttk::button $w.code -text [mc "See Code"] \
	-image ::img::view -compound left \
	-command [list showCode $show]
    set buttons [list x $w.code $w.dismiss]
    if {[llength $vars]} {
	ttk::button $w.vars -text [mc "See Variables"] \
	    -image ::img::view -compound left \
	    -command [concat [list showVars $w.dialog] $vars]
	set buttons [linsert $buttons 1 $w.vars]
    }
    if {$extra ne ""} {
	set buttons [linsert $buttons 1 [uplevel 1 $extra]]
    }
    grid {*}$buttons -padx 3p -pady 3p
    grid {*}$buttons -padx 4 -pady 4
    grid columnconfigure $w 0 -weight 1
    if {[tk windowingsystem] eq "aqua"} {
	foreach b [lrange $buttons 1 end] {$b configure -takefocus 0}
	grid configure $w.sep -pady 0
	grid configure {*}$buttons -pady {10 12}
	grid configure [lindex $buttons 1] -padx {16 4}
	grid configure [lindex $buttons end] -padx {4 18}
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537


538
539
540
541
542
543
544
460
461
462
463
464
465
466

467
468
469
470
471
472
473


474
475
476
477
478
479
480
481
482







-
+






-
-
+
+








    set b [ttk::frame $w.frame]
    grid $b -sticky news
    set f [ttk::labelframe $b.title -text [mc "Variable values:"]]
    foreach var $args {
	ttk::label $f.n$var -text "$var:" -anchor w
	ttk::label $f.v$var -textvariable $var -anchor w
	grid $f.n$var $f.v$var -padx 1.5p -pady 1.5p -sticky w
	grid $f.n$var $f.v$var -padx 2 -pady 2 -sticky w
    }
    ttk::button $b.ok -text [mc "OK"] \
	-command [list destroy $w] -default active
    bind $w <Return> [list $b.ok invoke]
    bind $w <Escape> [list $b.ok invoke]

    grid $f -sticky news -padx 3p
    grid $b.ok -sticky e -padx 3p -pady {4.5p 3p}
    grid $f -sticky news -padx 4
    grid $b.ok -sticky e -padx 4 -pady {6 4}
    if {[tk windowingsystem] eq "aqua"} {
	$b.ok configure -takefocus 0
	grid configure $b.ok -pady {10 12} -padx {16 18}
	grid configure $f -padx 10 -pady {10 0}
    }
    grid columnconfig $f 1 -weight 1
    grid rowconfigure $f 100 -weight 1
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514







-
+







    if {$i < 0} {
	return
    }
    set cursor [.t cget -cursor]
    .t configure -cursor [::ttk::cursor busy]
    update
    set demo [string range [lindex $tags $i] 5 end]
    uplevel 1 [list source -encoding utf-8 [file join $tk_demoDirectory $demo.tcl]]
    uplevel 1 [list source [file join $tk_demoDirectory $demo.tcl]]
    update
    .t configure -cursor $cursor

    .t tag add visited "$index linestart +1 chars" "$index lineend -1 chars"
}

# showStatus --
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
559
560
561
562
563
564
565

566

567
568
569
570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597







-
+
-












-
+










-
+







	toplevel $top
	if {[tk windowingsystem] eq "x11"} {wm attributes $top -type dialog}

	set t [frame $top.f]
	set text [text $t.text -font fixedFont -height 24 -wrap word \
		      -xscrollcommand [list $t.xscroll set] \
		      -yscrollcommand [list $t.yscroll set] \
		      -setgrid 1 -highlightthickness 0 -padx 3p -pady 1.5p \
		      -setgrid 1 -highlightthickness 0 -pady 2 -padx 3]
		      -tabstyle wordprocessor]
	ttk::scrollbar $t.xscroll -command [list $t.text xview] \
	    -orient horizontal
	ttk::scrollbar $t.yscroll -command [list $t.text yview] \
	    -orient vertical

	grid $t.text $t.yscroll -sticky news
	#grid $t.xscroll
	grid rowconfigure $t 0 -weight 1
	grid columnconfig $t 0 -weight 1

	set btns [ttk::frame $top.btns]
	ttk::separator $btns.sep
	grid $btns.sep -columnspan 4 -row 0 -sticky ew -pady 1.5p
	grid $btns.sep -columnspan 4 -row 0 -sticky ew -pady 2
	ttk::button $btns.dismiss -text [mc "Dismiss"] \
	    -default active -command [list destroy $top] \
	    -image ::img::delete -compound left
	ttk::button $btns.print   -text [mc "Print Code"] \
	    -command [list printCode $text $file] \
	    -image ::img::print -compound left
	ttk::button $btns.rerun   -text [mc "Rerun Demo"] \
	    -command [list evalShowCode $text] \
	    -image ::img::refresh -compound left
	set buttons [list x $btns.rerun $btns.print $btns.dismiss]
	grid {*}$buttons -padx 3p -pady 3p
	grid {*}$buttons -padx 4 -pady 4
	grid columnconfigure $btns 0 -weight 1
	if {[tk windowingsystem] eq "aqua"} {
	    foreach b [lrange $buttons 1 end] {$b configure -takefocus 0}
	    grid configure $btns.sep -pady 0
	    grid configure {*}$buttons -pady {10 12}
	    grid configure [lindex $buttons 1] -padx {16 4}
	    grid configure [lindex $buttons end] -padx {4 18}
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693

694









































































695
696
697
698
699
700
701
702
703
704
705
706
707




708
709
710
711
712
713
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712




713
714
715
716

717
718
719
720
721







-















+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
+
+
+
+
-





    } else {
	wm deiconify $top
	raise $top
    }
    wm title $top [mc "Demo code: %s" [file join $tk_demoDirectory $file]]
    wm iconname $top $file
    set id [open [file join $tk_demoDirectory $file]]
    fconfigure $id -encoding utf-8 -eofchar "\032 {}"
    $top.f.text delete 1.0 end
    $top.f.text insert 1.0 [read $id]
    $top.f.text mark set insert 1.0
    close $id
}

# printCode --
# Prints the source code currently displayed in the See Code dialog. Much
# thanks to Arjen Markus for this.
#
# Arguments:
# w -		Name of text widget containing code to print
# file -		Name of the original file (implicitly for title)

proc printCode {w file} {
    set code [$w get 1.0 end-1c]
    tk print $w

    set dir "."
    if {[info exists ::env(HOME)]} {
	set dir "$::env(HOME)"
    }
    if {[info exists ::env(TMP)]} {
	set dir $::env(TMP)
    }
    if {[info exists ::env(TEMP)]} {
	set dir $::env(TEMP)
    }

    set filename [file join $dir "tkdemo-$file"]
    set outfile [open $filename "w"]
    puts $outfile $code
    close $outfile

    switch -- $::tcl_platform(platform) {
	unix {
	    if {[catch {exec lp -c $filename} msg]} {
		tk_messageBox -title "Print spooling failure" \
			-message "Print spooling probably failed: $msg"
	    }
	}
	windows {
	    if {[catch {PrintTextWin32 $filename} msg]} {
		tk_messageBox -title "Print spooling failure" \
			-message "Print spooling probably failed: $msg"
	    }
	}
	default {
	    tk_messageBox -title "Operation not Implemented" \
		    -message "Wow! Unknown platform: $::tcl_platform(platform)"
	}
    }

    #
    # Be careful to throw away the temporary file in a gentle manner ...
    #
    if {[file exists $filename]} {
	catch {file delete $filename}
    }
}

# PrintTextWin32 --
#    Print a file under Windows using all the "intelligence" necessary
#
# Arguments:
# filename -		Name of the file
#
# Note:
# Taken from the Wiki page by Keith Vetter, "Printing text files under
# Windows".
# Note:
# Do not execute the command in the background: that way we can dispose of the
# file smoothly.
#
proc PrintTextWin32 {filename} {
    package require registry
    set app [auto_execok notepad.exe]
    set pcmd "$app /p %1"
    catch {
	set app [registry get {HKEY_CLASSES_ROOT\.txt} {}]
	set pcmd [registry get \
		{HKEY_CLASSES_ROOT\\$app\\shell\\print\\command} {}]
    }

    regsub -all {%1} $pcmd $filename pcmd
    puts $pcmd

    regsub -all {\\} $pcmd {\\\\} pcmd
    set command "[auto_execok start] /min $pcmd"
    eval exec $command
}

# tkAboutDialog --
#
#	Pops up a message box with an "about" message
#
proc tkAboutDialog {} {
    tk_messageBox -icon info -type ok -title [mc "About Widget Demo"] \
	    -message [mc "Tk widget demonstration application"] -detail \
"[mc "Copyright © %s" {1996-1997 Sun Microsystems, Inc.}]
[mc "Copyright © %s" {1997-2000 Ajuba Solutions, Inc.}]
[mc "Copyright © %s" {2001-2009 Donal K. Fellows}]
[mc "Copyright © %s" {2002-2007 Daniel A. Steffen}]
"[mc "Copyright \u00a9 %s" {1996-1997 Sun Microsystems, Inc.}]
[mc "Copyright \u00a9 %s" {1997-2000 Ajuba Solutions, Inc.}]
[mc "Copyright \u00a9 %s" {2001-2009 Donal K. Fellows}]
[mc "Copyright \u00a9 %s" {2002-2007 Daniel A. Steffen}]"
[mc "Copyright © %s" {2021 Kevin Walzer}]"
}

# Local Variables:
# mode: tcl
# End:

Deleted library/demos/windowicons.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108












































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# windowicons.tcl --
#
# This demonstration script showcases the wm iconphoto and wm iconbadge commands.
#

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

set w .windowicons
destroy $w
toplevel $w
wm title $w "Window Icon Demonstration"
positionWindow $w

## See Code / Dismiss buttons
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x

image create photo icon -data {
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGP
    C/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3Cc
    ulE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAArQNAAK0DQEdFIm+AAAJ
    QElEQVRYw+WXW2xdV5nHf/ty7lcf2/FxYsdOnMSNC0HTpDiRKJWAQjWCEQNU
    SEAFfUOiQqrEC2+IxwpemDLSzNBBCCQeQEKqRJgBSikiuGlN22TqhsR27OPL
    8eWc43Pdt7X22osHHydOm4FBPM6Slr69paX9/32Xtb614f/7MP6vC3O5f8L3
    G7HJyZPHBwfz5wrF7HQ6nRwxLTOhQuU4PW+z3eq9Xa+33rq9cms7k8pHjvfS
    3w8wOfk52u1u8oHpiUff897JJ8+dO/nI6LHho6OjQ3ahkMYwTTZ2O2zXutS3
    G/7ayubq7Vtr/7Ve2f7RytLam4ViXq1t/vRvB0ilPsjzz3+LZ5/9j7MzM5Nf
    /8hj5//5H97/YNbK5hkfTFLMxAEQQvD766v0yBGIEBEEuPUGi9dv7lx77cb3
    Vm9vfqc0WNi9evUKWr/xLh3rfuLj45+l0bjM7m768U98/OJ/fulLH/3wiemx
    eCafxRcKw7TJxKC+12RpbYdAx7HsOCrSRNpg+sQQj1w8nS0N5h8JAvm+rWr9
    9ZmZB2qWdZq9vWt/GWBm5im+9rUn6HRGPv7EE4/++2P/eOFkV0FkJTDQgCaX
    TbO1tcV2R2EmCxBJQixs2+R9EwV00MFAceJE2ZiZOT7VaTsPLyxU5orFTK1c
    fphq9bX7A8zOfoV8Ps3c3NsXPvWpD37vc5//0ETNt8gNjDAzlsdAE0vliTCR
    xEhnC2CaRIZNMmZiaonv9mh1PcrDJQZzCfK5OGNjQ8e2tvZO37y5+ctk0naq
    1fn7A4yOnmd5uVp4/PGHn/vylz8xe+zoEIP5JAMpA0OHeK6DG4TEk2li8Tha
    QxRpIg0q6DGUNjg6UuLYSInhYoYoigiCgHQ6TrGYnlpd3Q1ffvk3L128+ITe
    2Hj1XoBLl55menqcbDb1haeeevyrDz102tJaE7ctLBMqG1X23Ag7kcKOJzAA
    DSilCVWEZdmMDaXJJCxSiRimaaK1RkqJ7/uUSlk6Hed0oxG9HI9bm+Pjs2xs
    vIp5AKC15oUX/lA8f/7MF2dnz8YADMNASslypYqrUxSHyqSy+f31hzaRZRpM
    DKVYr+7y4usVri1WWavWCWSIZZkYhoFSIRcuTI1MTAw9OTf33Tu7zz54SCRi
    nD17/Pzs7AMPFQqZPlTE8vo2DlmGhgbo12BffD/8SmukitiuNxHKoDwyzPJG
    nTdXmtiWwdnRNCN5GxWGDA/nOH26/NGpqSfHgPU7AJcuPc0nP/kBrl698YGZ
    mYmMEIJmx6Hn+my0DUZGC6gIzEOnhu4Lh2GEbRocGyxRSO/7c3QgiRuEVOtd
    EvEQrSN8IVEq5MSJ4YlSKX3OMKJ14G4KnnnmM9bkZPk92VyKy3M3eentJjd3
    FUYyjxuEeELt7/NoP+eBVAipCFXEsYE4xcydYFIeSHKynOXhUwM0mh32egH1
    tsdL16oo007kcskHs7kYly49fRcALqby+fQopklkZ4jHY3g6gQgjHF/QcgQd
    V+7DHJoGmnzSQuvD0QGlIsJQkU4luLXR4kgxxcRgjM1mQCyZHrv0sUe4JwKF
    XMmu7/VSXV9xaXqI0YzC8328QOJ4gq4raHQDGt2AtitwfIEbSAwibOvdJ7pS
    CiElR3IxGh2X5Y0GV66v0wnAsq3MN5759L1FqKMoCkQoX19u0QkkD47lKSYi
    Th1NoSLYafu0ehrTNNBaE2mNUop2z+DEUJKBbPxecSEIgoAoUjwwmmZpdZPl
    muL4oIFWkbx8rXIvQMfZ9p2e1xBCstOJcFe6nB1NcWokhW1ZHMkazK90qXXD
    fZFII0NFIBW/XQiZHraoNbsU81mmjhbxfZ8gCAiCgELKQitJGCoIQ6SQO//2
    ze/fm4Kf/Px50dzr3Aoch1Ap2o4kn8tgW/sHynAxzcVTBQYzFp4v6boBjidw
    fcFCpcmPf7/Oz+ZrvPBalb12D9/370DUGk1evr6NacWIfD/yveDmXq3F3Nxz
    dwH+5dkfUq8155rb9dA2QcqQcjFx57DRGgaySR47d4RHZ0pYeh/C9QSOJ3EE
    CGWw3fJZ323j+x6e5xH4Pgu3d6g0FMWUjdvu7bo9/5oK1d0IzM09hwhCGrvN
    ubXFylI2pum4AZXtDqEURFGE1hoNxGMW5ZyB22nS8wQ9r1+QvsDzBc1uQGW7
    jee6eN4+RMfxMdHkYgatWmtur9ZaOnD8TgQMA27c+uH68s3KT8O9BoYBv3pj
    kxuVGo7Tw+1/MAh83lreYm1P9r3fT4XjSVxf4voC1/NwHAfXdXFcB891KGVj
    hO2e16q3fzR2cjQwDPPeZrSx8SqXL2/RqDU2EnH7I8dPjQ8v7Tqs1RwmSzEs
    QoQQSBHw1lKVha0AEUb4IiQQIb4I8YUkkCHTQwa5WIjne9xY2mT+VouRfI7N
    xfVfrK8sfTuRSAavXP3Xd7fjavWPRq1+3TeiQTVcGnh0oHwktlZzmBq0SNsR
    QgiuXLvNL/+nQU/aBFL1xSW+kAghEb5PEkE5q3Bdl7dv72LGCrTXdzf+9Nb8
    N5dXfrG6Wf1jeNDP3nkjigOFWm2xpvx0+tjI8LnMYMnMxQT5eIjruVye36LS
    TRAqRSD3vZdCIqUgEj5R4CEDj2O5kMZei3rHoLXV6Sy88cp3Fhf/ew6IAAGE
    9wOIARmtw9Tu7vKa1yY+Wiqeee+ZYdsi4HdvrjK/HiKUiZQhoZREQhDJAC18
    tPSIhEfouwSuQ9cx2VxpNK/PX/n+4uKvXwQdAAHgA/J+AAaQABJRJOydnVsr
    zZ1O13eMcSuezC61LJzQRgY+KvCJhI+WPpH0IAywIkEhaVIupAhdHS0t3F66
    Nv/iD9bW/nAFtAM4QA9wAXX3RnEvQBoYODSL+fzEmalTsx+emjl3YWjsaMlM
    pcwg0ggZEimFoSNsI8JSCtF1wtpmdWt1aeGVSuW133leYwNoA01gr297BzVw
    v/8CA0gBBaDYtzkw87ns6PhI+czM0JHjp/PFUjmZSmUM07RCKUPP6XVae/Vq
    fbdys1ZbvOX5ja2+ULcP0Opbt18H/G8Ah+shDWQPzVQ/RSnLTGRsO5U0TMuM
    VKjC0PUjLd1+fgPAOxTybl9YcvdC9VcBDobV3x0JINm3MfYbmdX/hu57FfZF
    Dgot6Fe8eqfw3wLwzvVmX9jsvx8AHEAcnn91/BlySEFKTpuCtgAAABN0RVh0
    QXV0aG9yAHdhcnN6YXdpYW5rYQy+S5cAAABYdEVYdENvcHlyaWdodABDQzAg
    UHVibGljIERvbWFpbiBEZWRpY2F0aW9uIGh0dHA6Ly9jcmVhdGl2ZWNvbW1v
    bnMub3JnL3B1YmxpY2RvbWFpbi96ZXJvLzEuMC/G4735AAAAIXRFWHRDcmVh
    dGlvbiBUaW1lADIwMTAtMDMtMjlUMDg6MDg6MzD47LxwAAAAJXRFWHRkYXRl
    OmNyZWF0ZQAyMDIxLTA4LTE1VDIwOjU0OjM5LTA0OjAwNBT3DQAAACV0RVh0
    ZGF0ZTptb2RpZnkAMjAyMS0wOC0xNVQyMDo1NDoxMS0wNDowMDSDBqsAAADI
    elRYdERlc2NyaXB0aW9uAAAY042OwQqCQBCGn6B3GOy+Cl0qTAjEc1HRJVhW
    HXUrd2pmLXr7tDrVpcMP838w/F+wxxxyprsgB2ALclAxtRAbaBirRdB4f5mH
    oTeuJlUxYoly8nRRxHW4HahO30SvmI5Y+CCBF4dPhzg0CYwOLs45GdKfG+sK
    hBuy2H4xUlM1i76+BhcBwwirLj/bAlJqjXXzP9UyxmuHzp8feiknLPW6Q/H9
    moy3yK1oqvROUE2yH99suX45PwEyf2MTOoCNrQAAABl0RVh0U29mdHdhcmUA
    d3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABWdEVYdFNvdXJjZQBodHRwczovL29w
    ZW5jbGlwYXJ0Lm9yZy9kZXRhaWwvMzUyMzMvdGFuZ28taW5ldHJuZXQtd2Vi
    LWJyb3dzZXItYnktd2Fyc3phd2lhbmth5nAuRgAAACB0RVh0VGl0bGUAdGF
    uZ28gaW5ldHJuZXQgd2ViIGJyb3dzZXLyr62TAAAAAElFTkSuQmCC
}

set ::tk::icons::base_icon(.) icon

# Create a copy of the image just created, magnified according to the
# display's DPI scaling level.  Since the zooom factor must be an integer,
# the copy will only be effectively magnified if $tk::scalingPct >= 200.
image create photo icon2
icon2 copy icon -zoom [expr {$tk::scalingPct / 100}]

pack [button $w.i -text "Set Window Icon to Globe" -image icon2 \
        -compound top -command {wm iconphoto . icon}] -fill x -padx 3p
pack [button $w.b -text "Set Badge to 3" -command {wm iconbadge . 3}] \
	-fill x -padx 3p
pack [button $w.e -text "Set Badge to 11" -command {wm iconbadge . 11}] \
	-fill x -padx 3p
pack [button $w.f -text "Reset Badge" -command {wm iconbadge . ""}] \
	-fill x -padx 3p

Changes to library/dialog.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# dialog.tcl --
#
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#
# Copyright © 1992-1993 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1992-1993 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.
#

#
# ::tk_dialog:
40
41
42
43
44
45
46





47
48
49
50
51
52
53
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+
+
+
+
+







    } elseif {"" eq $default} {
	set default -1
    } else {
	set default [lsearch -exact $args $default]
    }

    set windowingsystem [tk windowingsystem]
    if {$windowingsystem eq "aqua"} {
	option add *Dialog*background systemDialogBackgroundActive widgetDefault
	option add *Dialog*Button.highlightBackground \
		systemDialogBackgroundActive widgetDefault
    }

    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    destroy $w
    toplevel $w -class Dialog
    wm title $w $title
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124







-
+







	button $w.button$i -text $but -command [list set ::tk::Priv(button) $i]
	if {$i == $default} {
	    $w.button$i configure -default active
	} else {
	    $w.button$i configure -default normal
	}
	grid $w.button$i -in $w.bot -column $i -row 0 -sticky ew \
		-padx 7.5p -pady 3p
		-padx 10 -pady 4
	grid columnconfigure $w.bot $i
	# We boost the size of some Mac buttons for l&f
	if {$windowingsystem eq "aqua"} {
	    set tmp [string tolower $but]
	    if {$tmp eq "ok" || $tmp eq "cancel"} {
		grid columnconfigure $w.bot $i -minsize 90
	    }

Changes to library/entry.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# entry.tcl --
#
# This file defines the default bindings for Tk entry widgets and provides
# procedures that help in implementing those bindings.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1992-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.
#

#-------------------------------------------------------------------------
# Elements of tk::Priv that are used in this file:
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85

86
87
88
89
90

91
92
93
94
95

96
97
98
99

100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122

123
124
125

126
127
128

129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84

85
86
87
88
89

90
91
92
93
94

95
96
97
98

99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121

122
123
124

125
126
127

128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153







-
+















-
+







-
+




-
+




-
+



-
+



-
+













-
+




-
+


-
+


-
+



-
+













-
+







	}
	%W insert insert [::tk::GetSelection %W CLIPBOARD]
	tk::EntrySeeInsert %W
    }
}
bind Entry <<Clear>> {
    # ignore if there is no selection
    catch {%W delete sel.first sel.last}
    catch { %W delete sel.first sel.last }
}
bind Entry <<PasteSelection>> {
    if {$tk_strictMotif || ![info exists tk::Priv(mouseMoved)]
	|| !$tk::Priv(mouseMoved)} {
	tk::EntryPaste %W %x
    }
}

bind Entry <<TraverseIn>> {
    %W selection range 0 end
    %W icursor end
}

# Standard Motif bindings:

bind Entry <Button-1> {
bind Entry <1> {
    tk::EntryButton1 %W %x
    %W selection clear
}
bind Entry <B1-Motion> {
    set tk::Priv(x) %x
    tk::EntryMouseSelect %W %x
}
bind Entry <Double-Button-1> {
bind Entry <Double-1> {
    set tk::Priv(selectMode) word
    tk::EntryMouseSelect %W %x
    catch {%W icursor sel.last}
}
bind Entry <Triple-Button-1> {
bind Entry <Triple-1> {
    set tk::Priv(selectMode) line
    tk::EntryMouseSelect %W %x
    catch {%W icursor sel.last}
}
bind Entry <Shift-Button-1> {
bind Entry <Shift-1> {
    set tk::Priv(selectMode) char
    %W selection adjust @%x
}
bind Entry <Double-Shift-Button-1>	{
bind Entry <Double-Shift-1>	{
    set tk::Priv(selectMode) word
    tk::EntryMouseSelect %W %x
}
bind Entry <Triple-Shift-Button-1>	{
bind Entry <Triple-Shift-1>	{
    set tk::Priv(selectMode) line
    tk::EntryMouseSelect %W %x
}
bind Entry <B1-Leave> {
    set tk::Priv(x) %x
    tk::EntryAutoScan %W
}
bind Entry <B1-Enter> {
    tk::CancelRepeat
}
bind Entry <ButtonRelease-1> {
    tk::CancelRepeat
}
bind Entry <Control-Button-1> {
bind Entry <Control-1> {
    %W icursor @%x
}

bind Entry <<PrevChar>> {
    tk::EntrySetCursor %W [tk::EntryPreviousChar %W insert]
    tk::EntrySetCursor %W [expr {[%W index insert] - 1}]
}
bind Entry <<NextChar>> {
    tk::EntrySetCursor %W [tk::EntryNextChar %W insert]
    tk::EntrySetCursor %W [expr {[%W index insert] + 1}]
}
bind Entry <<SelectPrevChar>> {
    tk::EntryKeySelect %W [tk::EntryPreviousChar %W insert]
    tk::EntryKeySelect %W [expr {[%W index insert] - 1}]
    tk::EntrySeeInsert %W
}
bind Entry <<SelectNextChar>> {
    tk::EntryKeySelect %W [tk::EntryNextChar %W insert]
    tk::EntryKeySelect %W [expr {[%W index insert] + 1}]
    tk::EntrySeeInsert %W
}
bind Entry <<PrevWord>> {
    tk::EntrySetCursor %W [tk::EntryPreviousWord %W insert]
}
bind Entry <<NextWord>> {
    tk::EntrySetCursor %W [tk::EntryNextWord %W insert]
}
bind Entry <<SelectPrevWord>> {
    tk::EntryKeySelect %W [tk::EntryPreviousWord %W insert]
    tk::EntrySeeInsert %W
}
bind Entry <<SelectNextWord>> {
    tk::EntryKeySelect %W [tk::EntrySelectNextWord %W insert]
    tk::EntryKeySelect %W [tk::EntryNextWord %W insert]
    tk::EntrySeeInsert %W
}
bind Entry <<LineStart>> {
    tk::EntrySetCursor %W 0
}
bind Entry <<SelectLineStart>> {
    tk::EntryKeySelect %W 0
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
161
162
163
164
165
166
167

168

169
170
171
172
173
174
175







-
+
-







    tk::EntrySeeInsert %W
}

bind Entry <Delete> {
    if {[%W selection present]} {
	%W delete sel.first sel.last
    } else {
	%W delete [tk::startOfCluster [%W get] [%W index insert]] \
	%W delete insert
		[tk::endOfCluster [%W get] [%W index insert]]
    }
}
bind Entry <BackSpace> {
    tk::EntryBackspace %W
}

bind Entry <Control-space> {
187
188
189
190
191
192
193
194

195
196
197
198
199

200
201

202
203
204
205
206



207
208
209
210
211
212

213

214

215
216
217
218
219
220
221
186
187
188
189
190
191
192

193
194
195
196
197

198
199

200
201
202



203
204
205
206
207
208
209
210
211
212

213

214
215
216
217
218
219
220
221







-
+




-
+

-
+


-
-
-
+
+
+






+
-
+
-
+







}
bind Entry <<SelectAll>> {
    %W selection range 0 end
}
bind Entry <<SelectNone>> {
    %W selection clear
}
bind Entry <Key> {
bind Entry <KeyPress> {
    tk::CancelRepeat
    tk::EntryInsert %W %A
}

# Ignore all Alt, Meta, Control, Command, and Fn keypresses unless explicitly bound.
# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
# Otherwise, if a widget binding for one of these is defined, the
# <Key> class binding will also fire and insert the character,
# <KeyPress> class binding will also fire and insert the character,
# which is wrong.  Ditto for Escape, Return, and Tab.

bind Entry <Alt-Key> {# nothing}
bind Entry <Meta-Key> {# nothing}
bind Entry <Control-Key> {# nothing}
bind Entry <Alt-KeyPress> {# nothing}
bind Entry <Meta-KeyPress> {# nothing}
bind Entry <Control-KeyPress> {# nothing}
bind Entry <Escape> {# nothing}
bind Entry <Return> {# nothing}
bind Entry <KP_Enter> {# nothing}
bind Entry <Tab> {# nothing}
bind Entry <Prior> {# nothing}
bind Entry <Next> {# nothing}
if {[tk windowingsystem] eq "aqua"} {
bind Entry <Command-Key> {# nothing}
    bind Entry <Command-KeyPress> {# nothing}
bind Entry <Fn-Key> {# nothing}
}
# Tk-on-Cocoa generates characters for these two keys. [Bug 2971663]
bind Entry <<NextLine>> {# nothing}
bind Entry <<PrevLine>> {# nothing}

# On Windows, paste is done using Shift-Insert.  Shift-Insert already
# generates the <<Paste>> event, so we don't need to do anything here.
if {[tk windowingsystem] ne "win32"} {
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

310
311

312
313
314
315
316
317


318
319
320
321
322
323
324
268
269
270
271
272
273
274
































275
276

277
278

279
280
281
282
283


284
285
286
287
288
289
290
291
292







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+

-
+




-
-
+
+







}
bind Entry <Meta-Delete> {
    if {!$tk_strictMotif} {
	%W delete [tk::EntryPreviousWord %W insert] insert
    }
}

# Bindings for IME text input and accents.

bind Entry <<TkStartIMEMarkedText>> {
    dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
}
bind Entry <<TkEndIMEMarkedText>> {
    ::tk::EntryEndIMEMarkedText %W
}
bind Entry <<TkClearIMEMarkedText>> {
    %W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert]
}
bind Entry <<TkAccentBackspace>> {
    tk::EntryBackspace %W
}

# ::tk::EntryEndIMEMarkedText --
# Handles input method text marking in an entry
#
# Arguments:
# w -		The entry window.

proc ::tk::EntryEndIMEMarkedText {w} {
    variable Priv
    if {[catch {
	set mark [dict get $Priv(IMETextMark) $w]
    }]} {
	bell
	return
    }
    $w selection range $mark insert
}

# A few additional bindings of my own.

bind Entry <Button-2> {
bind Entry <2> {
    if {!$tk_strictMotif} {
        ::tk::EntryScanMark %W %x
	::tk::EntryScanMark %W %x
    }
}
bind Entry <B2-Motion> {
    if {!$tk_strictMotif} {
        ::tk::EntryScanDrag %W %x
     }
	::tk::EntryScanDrag %W %x
    }
}

# ::tk::EntryClosestGap --
# Given x and y coordinates, this procedure finds the closest boundary
# between characters to the given coordinates and returns the index
# of the character just after the boundary.
#
386
387
388
389
390
391
392
393
394


395
396
397


398
399
400
401
402
403


404
405
406
407
408
409
410
354
355
356
357
358
359
360


361
362
363


364
365
366
367
368
369


370
371
372
373
374
375
376
377
378







-
-
+
+

-
-
+
+




-
-
+
+







		} else {
		    $w selection clear
		}
	    }
	}
	word {
	    if {$cur < $anchor} {
		set before [tk::wordBreakBefore [$w get] $cur]
		set after [tk::wordBreakAfter [$w get] $anchor-1]
		set before [tcl_wordBreakBefore [$w get] $cur]
		set after [tcl_wordBreakAfter [$w get] [expr {$anchor-1}]]
	    } elseif {$cur > $anchor} {
		set before [tk::wordBreakBefore [$w get] $anchor]
		set after [tk::wordBreakAfter [$w get] $cur-1]
		set before [tcl_wordBreakBefore [$w get] $anchor]
		set after [tcl_wordBreakAfter [$w get] [expr {$cur - 1}]]
	    } else {
		if {[$w index @$Priv(pressX)] < $anchor} {
		      incr anchor -1
		}
		set before [tk::wordBreakBefore [$w get] $anchor]
		set after [tk::wordBreakAfter [$w get] $anchor]
		set before [tcl_wordBreakBefore [$w get] $anchor]
		set after [tcl_wordBreakAfter [$w get] $anchor]
	    }
	    if {$before < 0} {
		set before 0
	    }
	    if {$after < 0} {
		set after end
	    }
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
531
484
485
486
487
488
489
490

491

492
493
494
495
496
497
498







-
+
-








proc ::tk::EntryBackspace w {
    if {[$w selection present]} {
	$w delete sel.first sel.last
    } else {
	set x [expr {[$w index insert] - 1}]
	if {$x >= 0} {
	    $w delete [tk::startOfCluster [$w get] $x] \
	    $w delete $x
		      [tk::endOfCluster [$w get] $x]
	}
	if {[$w index @0] >= [$w index insert]} {
	    set range [$w xview]
	    set left [lindex $range 0]
	    set right [lindex $range 1]
	    $w xview moveto [expr {$left - ($right - $left)/2.0}]
	}
572
573
574
575
576
577
578

579

580
581
582
583
584

585
586
587
588
589
590


591
592


593
594
595
596
597

598

599
600
601
602
603
604
605
606
607
608
609
610
611
612










613
614
615
616
617
618
619
620
621

622
623
624
625
626
627
628
629
630






631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
539
540
541
542
543
544
545
546

547
548
549

550

551
552
553
554
555
556
557
558
559


560
561
562
563
564
565
566
567

568














569
570
571
572
573
574
575
576
577
578









579









580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597





598
599
600
601
602
603

















604
605
606
607
608
609
610







+
-
+


-

-
+






+
+
-
-
+
+





+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+












-
-
-
-
-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







# w -		The entry window.

proc ::tk::EntryTranspose w {
    set i [$w index insert]
    if {$i < [$w index end]} {
	incr i
    }
    set first [expr {$i-2}]
    if {$i < 2} {
    if {$first < 0} {
	return
    }
    set first $i-2
    set data [$w get]
    set new [string index $data $i-1][string index $data $first]
    set new [string index $data [expr {$i-1}]][string index $data $first]
    $w delete $first $i
    $w insert insert $new
    EntrySeeInsert $w
}

# ::tk::EntryNextWord --
# Returns the index of the next word position after a given position in the
# entry.  The next word is platform dependent and may be either the next
# Returns the index of the next start-of-word position after the next
# end-of-word position after a given position in the text.
# end-of-word position or the next start-of-word position after the next
# end-of-word position.
#
# Arguments:
# w -		The entry window in which the cursor is to move.
# start -	Position at which to start search.

if {[tk windowingsystem] eq "win32"}  {
proc ::tk::EntryNextWord {w start} {
    proc ::tk::EntryNextWord {w start} {
    # the check on [winfo class] is because the spinbox also uses this proc
    if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
	return end
    }
    set pos [tk::endOfWord [$w get] [$w index $start]]
    if {$pos >= 0} {
	set pos [tk::startOfNextWord [$w get] $pos]
    }
    if {$pos < 0} {
	return end
    }
    return $pos
}

	set pos [tcl_endOfWord [$w get] [$w index $start]]
	if {$pos >= 0} {
	    set pos [tcl_startOfNextWord [$w get] $pos]
	}
	if {$pos < 0} {
	    return end
	}
	return $pos
    }
} else {
# ::tk::EntrySelectNextWord --
# Returns the index of the next end-of-word position after a given
# position in the text.
#
# Arguments:
# w -		The entry window in which the cursor is to move.
# start -	Position at which to start search.

proc ::tk::EntrySelectNextWord {w start} {
    proc ::tk::EntryNextWord {w start} {
    # the check on [winfo class] is because the spinbox also uses this proc
    if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
	return end
    }
    set pos [tk::endOfWord [$w get] [$w index $start]]
    if {$pos < 0} {
	return end
    }
    return $pos
	set pos [tcl_endOfWord [$w get] [$w index $start]]
	if {$pos < 0} {
	    return end
	}
	return $pos
    }
}

# ::tk::EntryPreviousWord --
#
# Returns the index of the previous word position before a given
# position in the entry.
#
# Arguments:
# w -		The entry window in which the cursor is to move.
# start -	Position at which to start search.

proc ::tk::EntryPreviousWord {w start} {
    # the check on [winfo class] is because the spinbox also uses this proc
    if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
	return 0
    }
    set pos [tk::startOfPreviousWord [$w get] [$w index $start]]
    set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
    if {$pos < 0} {
	return 0
    }
    return $pos
}

proc ::tk::EntryNextChar {w start} {
    set pos [tk::endOfCluster [$w get] [$w index $start]]
    if {$pos < 0} {
	return end
    }
    return $pos
}

proc ::tk::EntryPreviousChar {w start} {
    set pos [tk::startOfCluster [$w get] [expr {[$w index $start]-1}]]
    if {$pos < 0} {
	return 0
    }
    return $pos
}


# ::tk::EntryScanMark --
#
# Marks the start of a possible scan drag operation
#
# Arguments:
# w -	The entry window from which the text to get
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714

715
716
717
718
719
720
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654







-
+
















-
+






# Arguments:
# w -	The entry window from which the text to get
# x -	x location on screen

proc ::tk::EntryScanDrag {w x} {
    # Make sure these exist, as some weird situations can trigger the
    # motion binding without the initial press.  [Bug #220269]
    if {![info exists ::tk::Priv(x)]} {set ::tk::Priv(x) $x}
    if {![info exists ::tk::Priv(x)]} { set ::tk::Priv(x) $x }
    # allow for a delta
    if {abs($x-$::tk::Priv(x)) > 2} {
	set ::tk::Priv(mouseMoved) 1
    }
    $w scan dragto $x
}

# ::tk::EntryGetSelection --
#
# Returns the selected text of the entry with respect to the -show option.
#
# Arguments:
# w -         The entry window from which the text to get

proc ::tk::EntryGetSelection {w} {
    set entryString [string range [$w get] [$w index sel.first] \
	    [$w index sel.last]-1]
	    [expr {[$w index sel.last] - 1}]]
    if {[$w cget -show] ne ""} {
	return [string repeat [string index [$w cget -show] 0] \
		[string length $entryString]]
    }
    return $entryString
}

Changes to library/focus.tcl.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







# focus.tcl --
#
# This file defines several procedures for managing the input
# focus.
#
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

# ::tk_focusNext --
# This procedure returns the name of the next window after "w" in

Changes to library/fontchooser.tcl.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15

16
17
18
19
20
21






22
23
24
25

26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56






57
58
59
60
61
62
63
64
65


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
1
2
3
4


5
6
7
8
9
10
11
12
13
14

15
16





17
18
19
20
21
22
23
24
25
26
27
28

29
30
31





















32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49


50
51
52
53
54
55
56
57
58
59
60
61
62



63
64
65
66










67
68
69
70
71
72
73




-
-
+
+








-
+

-
-
-
-
-
+
+
+
+
+
+




+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+
+
+
+
+
+







-
-
+
+











-
-
-




-
-
-
-
-
-
-
-
-
-







# fontchooser.tcl -
#
#	A themeable Tk font selection dialog. See TIP #324.
#
# Copyright © 2008 Keith Vetter
# Copyright © 2008 Pat Thoyts <[email protected]>
# Copyright (C) 2008 Keith Vetter
# Copyright (C) 2008 Pat Thoyts <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

namespace eval ::tk::fontchooser {
    variable S

    set S(W) .__tk__fontchooser
    set S(fonts) [lsort -dictionary -unique [font families]]
    set S(fonts) [lsort -dictionary [font families]]
    set S(styles) [list \
            [::msgcat::mc Regular] \
            [::msgcat::mc Italic] \
            [::msgcat::mc Bold] \
            [::msgcat::mc {Bold Italic}] \
    ]
                       [::msgcat::mc "Regular"] \
                       [::msgcat::mc "Italic"] \
                       [::msgcat::mc "Bold"] \
                       [::msgcat::mc "Bold Italic"] \
                      ]

    set S(sizes) {8 9 10 11 12 14 16 18 20 22 24 26 28 36 48 72}
    set S(strike) 0
    set S(under) 0
    set S(first) 1
    set S(sampletext) [::msgcat::mc "AaBbYyZz01"]
    set S(-parent) .
    set S(-title) {}
    set S(-title) [::msgcat::mc "Font"]
    set S(-command) ""
    set S(-font) TkDefaultFont
    set S(bad) [list ]
}

proc ::tk::fontchooser::Canonical {} {
    variable S

    foreach style $S(styles) {
        lappend S(styles,lcase) [string tolower $style]
    }
    set S(sizes,lcase) $S(sizes)
    set S(sampletext) [::msgcat::mc "AaBbYyZz01"]

    # Canonical versions of font families, styles, etc. for easier searching
    set S(fonts,lcase) {}
    foreach font $S(fonts) {
        lappend S(fonts,lcase) [string tolower $font]
    }
    set S(styles,lcase) {}
    foreach style $S(styles) {
        lappend S(styles,lcase) [string tolower $style]
    }
}

proc ::tk::fontchooser::Setup {} {
    variable S

    Canonical
    # Canonical versions of font families, styles, etc. for easier searching
    set S(fonts,lcase) {}
    foreach font $S(fonts) { lappend S(fonts,lcase) [string tolower $font]}
    set S(styles,lcase) {}
    foreach style $S(styles) { lappend S(styles,lcase) [string tolower $style]}
    set S(sizes,lcase) $S(sizes)

    ::ttk::style layout FontchooserFrame {
        Entry.field -sticky news -border true -children {
            FontchooserFrame.padding -sticky news
        }
    }
    bind [winfo class .] <<ThemeChanged>> \
            [list +ttk::style layout FontchooserFrame \
                    [ttk::style layout FontchooserFrame]]
        [list +ttk::style layout FontchooserFrame \
             [ttk::style layout FontchooserFrame]]

    namespace ensemble create -map {
        show ::tk::fontchooser::Show
        hide ::tk::fontchooser::Hide
        configure ::tk::fontchooser::Configure
    }
}
::tk::fontchooser::Setup

proc ::tk::fontchooser::Show {} {
    variable S

    Canonical

    if {![winfo exists $S(W)]} {
        Create
        wm transient $S(W) [winfo toplevel $S(-parent)]
        tk::PlaceWindow $S(W) widget $S(-parent)
        if {[string trim $S(-title)] eq ""} {
            wm title $S(W) [::msgcat::mc "Font"]
        } else {
            wm title $S(W) $S(-title)
        }
    }
    set S(fonts) [lsort -dictionary -unique [font families]]
    set S(fonts,lcase) {}
    foreach font $S(fonts) {
        lappend S(fonts,lcase) [string tolower $font]
    }
    wm deiconify $S(W)
}

proc ::tk::fontchooser::Hide {} {
    variable S
    wm withdraw $S(W)
111
112
113
114
115
116
117
118

119
120
121

122
123
124
125
126
127
128
129
130
131
132
133


134

135
136
137


138
139

140
141
142
143


144
145


146
147
148


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181

182
183
184
185
186

187
188

189
190

191
192
193
194


195
196
197


198
199
200


201
202
203
204
205
206
207



208
209
210
211



212
213
214
215

216
217

218
219

220
221
222
223
224
225
226

227
228
229

230
231

232
233

234
235

236
237
238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

260
261

262
263
264
265
266
267
268





269
270
271
272


273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297

298
299

300
301
302
303
304
305
306



307
308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324

325
326

327
328

329
330
331
332


333
334
335
336
337
338
339
340
341
84
85
86
87
88
89
90

91
92
93

94
95
96
97
98
99
100
101
102
103
104


105
106
107
108
109


110
111
112

113
114
115
116
117
118
119


120
121



122
123









124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140


141
142
143
144

145
146
147
148
149

150
151

152
153

154
155
156


157
158
159


160
161
162


163
164
165
166
167
168



169
170
171
172



173
174
175
176
177
178

179
180

181
182

183
184
185
186
187
188
189

190
191
192

193
194

195
196

197
198

199



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

221
222

223
224
225
226
227



228
229
230
231
232
233
234


235
236
237
238
239
240
241

242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259

260
261

262







263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282

283


284


285
286



287
288


289
290
291
292
293
294
295







-
+


-
+










-
-
+
+

+

-
-
+
+

-
+




+
+
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
















-
+
-
-




-
+




-
+

-
+

-
+


-
-
+
+

-
-
+
+

-
-
+
+




-
-
-
+
+
+

-
-
-
+
+
+



-
+

-
+

-
+






-
+


-
+

-
+

-
+

-
+
-
-
-
+




















-
+

-
+




-
-
-
+
+
+
+
+


-
-
+
+





-
+

-














-
+

-
+

-
+
-
-
-
-
-
-
-
+
+
+











-
+





-
+
-
-
+
-
-
+

-
-
-
+
+
-
-







    }

    if {[llength $args] == 0} {
        set result {}
        foreach spec $specs {
            foreach {name xx yy default} $spec break
            lappend result $name \
                    [expr {[info exists S($name)] ? $S($name) : $default}]
                [expr {[info exists S($name)] ? $S($name) : $default}]
        }
        lappend result -visible \
                [expr {[winfo exists $S(W)] && [winfo ismapped $S(W)]}]
            [expr {[winfo exists $S(W)] && [winfo ismapped $S(W)]}]
        return $result
    }
    if {[llength $args] == 1} {
        set option [lindex $args 0]
        if {[string equal $option "-visible"]} {
            return [expr {[winfo exists $S(W)] && [winfo ismapped $S(W)]}]
        } elseif {[info exists S($option)]} {
            return $S($option)
        }
        return -code error -errorcode [list TK LOOKUP OPTION $option] \
                "bad option \"$option\": must be\
                -command, -font, -parent, -title or -visible"
	    "bad option \"$option\": must be\
            -command, -font, -parent, -title or -visible"
    }

    set cache [dict create -parent $S(-parent) -title $S(-title) \
            -font $S(-font) -command $S(-command)]
    set r [tclParseConfigSpec [namespace which -variable S] $specs DONTSETDEFAULTS $args]
                   -font $S(-font) -command $S(-command)]
    set r [tclParseConfigSpec [namespace which -variable S] $specs "" $args]
    if {![winfo exists $S(-parent)]} {
        set code [list TK LOOKUP WINDOW $S(-parent)]
	set code [list TK LOOKUP WINDOW $S(-parent)]
        set err "bad window path name \"$S(-parent)\""
        array set S $cache
        return -code error -errorcode $code $err
    }
    if {[string trim $S(-title)] eq ""} {
        set S(-title) [::msgcat::mc "Font"]

    if {[winfo exists $S(W)]} {
    }
    if {[winfo exists $S(W)] && [lsearch $args -font] != -1} {
        if {{-font} in $args} {
            Init $S(-font)
            event generate $S(-parent) <<TkFontchooserFontChanged>>
	Init $S(-font)
	event generate $S(-parent) <<TkFontchooserFontChanged>>
        }

        if {[string trim $S(-title)] eq {}} {
            wm title $S(W) [::msgcat::mc Font]
        } else {
            wm title $S(W) $S(-title)
        }
        $S(W).ok configure -state $S(nstate)
        $S(W).apply configure -state $S(nstate)
    }
    return $r
}

proc ::tk::fontchooser::Create {} {
    variable S
    set windowName __tk__fontchooser
    if {$S(-parent) eq "."} {
        set S(W) .$windowName
    } else {
        set S(W) $S(-parent).$windowName
    }

    # Now build the dialog
    if {![winfo exists $S(W)]} {
        toplevel $S(W) -class TkFontDialog
        if {[package provide tcltest] ne {}} {
        if {[package provide tcltest] ne {}} {set ::tk_dialog $S(W)}
            set ::tk_dialog $S(W)
        }
        wm withdraw $S(W)
        wm title $S(W) $S(-title)
        wm transient $S(W) [winfo toplevel $S(-parent)]

        set outer [::ttk::frame $S(W).outer -padding {7.5p 7.5p}]
        set outer [::ttk::frame $S(W).outer -padding {10 10}]
        ::tk::AmpWidget ::ttk::label $S(W).font -text [::msgcat::mc "&Font:"]
        ::tk::AmpWidget ::ttk::label $S(W).style -text [::msgcat::mc "Font st&yle:"]
        ::tk::AmpWidget ::ttk::label $S(W).size -text [::msgcat::mc "&Size:"]
        ttk::entry $S(W).efont -width 18 \
                -textvariable [namespace which -variable S](font)
            -textvariable [namespace which -variable S](font)
        ttk::entry $S(W).estyle -width 10 \
                -textvariable [namespace which -variable S](style)
            -textvariable [namespace which -variable S](style)
        ttk::entry $S(W).esize -textvariable [namespace which -variable S](size) \
                -width 3 -validate key -validatecommand {regexp -- {^-*[0-9]*$} %P}
            -width 3 -validate key -validatecommand {string is double %P}

        ttk_slistbox $S(W).lfonts -height 7 -exportselection 0 \
                -selectmode browse -activestyle none \
                -listvariable [namespace which -variable S](fonts)
            -selectmode browse -activestyle none \
            -listvariable [namespace which -variable S](fonts)
        ttk_slistbox $S(W).lstyles -width 5 -height 7 -exportselection 0 \
                -selectmode browse -activestyle none \
                -listvariable [namespace which -variable S](styles)
            -selectmode browse -activestyle none \
            -listvariable [namespace which -variable S](styles)
        ttk_slistbox $S(W).lsizes -width 4 -height 7 -exportselection 0 \
                -selectmode browse -activestyle none \
                -listvariable [namespace which -variable S](sizes)
            -selectmode browse -activestyle none \
            -listvariable [namespace which -variable S](sizes)

        set WE $S(W).effects
        ::ttk::labelframe $WE -text [::msgcat::mc "Effects"]
        ::tk::AmpWidget ::ttk::checkbutton $WE.strike \
                -variable [namespace which -variable S](strike) \
                -text [::msgcat::mc "Stri&keout"] \
                -command [namespace code [list Click strike]]
            -variable [namespace which -variable S](strike) \
            -text [::msgcat::mc "Stri&keout"] \
            -command [namespace code [list Click strike]]
        ::tk::AmpWidget ::ttk::checkbutton $WE.under \
                -variable [namespace which -variable S](under) \
                -text [::msgcat::mc "&Underline"] \
                -command [namespace code [list Click under]]
            -variable [namespace which -variable S](under) \
            -text [::msgcat::mc "&Underline"] \
            -command [namespace code [list Click under]]

        set bbox [::ttk::frame $S(W).bbox]
        ::ttk::button $S(W).ok -text [::msgcat::mc OK] -default active\
                -command [namespace code [list Done 1]]
            -command [namespace code [list Done 1]]
        ::ttk::button $S(W).cancel -text [::msgcat::mc Cancel] \
                -command [namespace code [list Done 0]]
            -command [namespace code [list Done 0]]
        ::tk::AmpWidget ::ttk::button $S(W).apply -text [::msgcat::mc "&Apply"] \
                -command [namespace code [list Apply]]
            -command [namespace code [list Apply]]
        wm protocol $S(W) WM_DELETE_WINDOW [namespace code [list Done 0]]

        # Calculate minimum sizes
        ttk::scrollbar $S(W).tmpvs
        set scroll_width [winfo reqwidth $S(W).tmpvs]
        destroy $S(W).tmpvs
        set minsize(gap) [::tk::ScaleNum 10]
        set minsize(gap) 10
        set minsize(bbox) [winfo reqwidth $S(W).ok]
        set minsize(fonts) \
                [expr {[font measure TkDefaultFont "Helvetica"] + $scroll_width}]
            [expr {[font measure TkDefaultFont "Helvetica"] + $scroll_width}]
        set minsize(styles) \
                [expr {[font measure TkDefaultFont "Bold Italic"] + $scroll_width}]
            [expr {[font measure TkDefaultFont "Bold Italic"] + $scroll_width}]
        set minsize(sizes) \
                [expr {[font measure TkDefaultFont "-99"] + $scroll_width}]
            [expr {[font measure TkDefaultFont "-99"] + $scroll_width}]
        set min [expr {$minsize(gap) * 4}]
        foreach {what width} [array get minsize] {
        foreach {what width} [array get minsize] { incr min $width }
            incr min $width
        }
        wm minsize $S(W) $min [::tk::ScaleNum 260]
        wm minsize $S(W) $min 260

        bind $S(W) <Return> [namespace code [list Done 1]]
        bind $S(W) <Escape> [namespace code [list Done 0]]
        bind $S(W) <Map> [namespace code [list Visibility %W 1]]
        bind $S(W) <Unmap> [namespace code [list Visibility %W 0]]
        bind $S(W) <Destroy> [namespace code [list Visibility %W 0]]
        bind $S(W).lfonts.list <<ListboxSelect>> [namespace code [list Click font]]
        bind $S(W).lstyles.list <<ListboxSelect>> [namespace code [list Click style]]
        bind $S(W).lsizes.list <<ListboxSelect>> [namespace code [list Click size]]
        bind $S(W) <Alt-Key> [list ::tk::AltKeyInDialog $S(W) %A]
        bind $S(W).font <<AltUnderlined>> [list ::focus $S(W).efont]
        bind $S(W).style <<AltUnderlined>> [list ::focus $S(W).estyle]
        bind $S(W).size <<AltUnderlined>> [list ::focus $S(W).esize]
        bind $S(W).apply <<AltUnderlined>> [namespace code [list Apply]]
        bind $WE.strike <<AltUnderlined>> [list $WE.strike invoke]
        bind $WE.under <<AltUnderlined>> [list $WE.under invoke]

        set WS $S(W).sample
        ::ttk::labelframe $WS -text [::msgcat::mc "Sample"]
        ::ttk::label $WS.sample -relief sunken -anchor center \
                -textvariable [namespace which -variable S](sampletext)
            -textvariable [namespace which -variable S](sampletext)
        set S(sample) $WS.sample
        grid $WS.sample -sticky news -padx 4.5p -pady 3p
        grid $WS.sample -sticky news -padx 6 -pady 4
        grid rowconfigure $WS 0 -weight 1
        grid columnconfigure $WS 0 -weight 1
        grid propagate $WS 0

        grid $S(W).ok     -in $bbox -sticky new -pady {0 1.5p}
        grid $S(W).cancel -in $bbox -sticky new -pady 1.5p
        grid $S(W).apply  -in $bbox -sticky new -pady 1.5p
        grid $S(W).ok     -in $bbox -sticky new -pady {0 2}
        grid $S(W).cancel -in $bbox -sticky new -pady 2
        if {$S(-command) ne ""} {
            grid $S(W).apply -in $bbox -sticky new -pady 2
        }
        grid columnconfigure $bbox 0 -weight 1

        grid $WE.strike -sticky w -padx 7.5p
        grid $WE.under -sticky w -padx 7.5p -pady {0 22.5p}
        grid $WE.strike -sticky w -padx 10
        grid $WE.under -sticky w -padx 10 -pady {0 30}
        grid columnconfigure $WE 1 -weight 1

        grid $S(W).font   x $S(W).style   x $S(W).size   x       -in $outer -sticky w
        grid $S(W).efont  x $S(W).estyle  x $S(W).esize  x $bbox -in $outer -sticky ew
        grid $S(W).lfonts x $S(W).lstyles x $S(W).lsizes x ^     -in $outer -sticky news
        grid $WE          x $WS           - -            x ^     -in $outer -sticky news -pady {11p 22.5p}
        grid $WE          x $WS           - -            x ^     -in $outer -sticky news -pady {15 30}
        grid configure $bbox -sticky n
        grid rowconfigure $outer 2 -weight 1
        grid columnconfigure $outer {1 3 5} -minsize $minsize(gap)
        grid columnconfigure $outer {0 2 4} -weight 1
        grid columnconfigure $outer 0 -minsize $minsize(fonts)
        grid columnconfigure $outer 2 -minsize $minsize(styles)
        grid columnconfigure $outer 4 -minsize $minsize(sizes)
        grid columnconfigure $outer 6 -minsize $minsize(bbox)

        grid $outer -sticky news
        grid rowconfigure $S(W) 0 -weight 1
        grid columnconfigure $S(W) 0 -weight 1

        Init $S(-font)

        trace add variable [namespace which -variable S](size) \
                write [namespace code [list Tracer]]
            write [namespace code [list Tracer]]
        trace add variable [namespace which -variable S](style) \
                write [namespace code [list Tracer]]
            write [namespace code [list Tracer]]
        trace add variable [namespace which -variable S](font) \
                write [namespace code [list Tracer]]
            write [namespace code [list Tracer]]
        trace add variable [namespace which -variable S](strike) \
                write [namespace code [list Tracer]]
        trace add variable [namespace which -variable S](under) \
                write [namespace code [list Tracer]]
    }

    Init $S(-font)
    } else {
        Init $S(-font)
    }

    return
}

# ::tk::fontchooser::Done --
#
#       Handles teardown of the dialog, calling -command if needed
#
# Arguments:
#       ok              true if user pressed OK
#
proc ::tk::fontchooser::Done {ok} {
proc ::tk::::fontchooser::Done {ok} {
    variable S

    if {! $ok} {
        set S(result) ""
    }
    trace remove variable S(size) write [namespace code [list Tracer]]
    trace vdelete S(size) w [namespace code [list Tracer]]
    trace remove variable S(style) write [namespace code [list Tracer]]
    trace remove variable S(font) write [namespace code [list Tracer]]
    trace vdelete S(style) w [namespace code [list Tracer]]
    trace remove variable S(strike) write [namespace code [list Tracer]]
    trace remove variable S(under) write [namespace code [list Tracer]]
    trace vdelete S(font) w [namespace code [list Tracer]]
    destroy $S(W)
    if {$ok} {
        if {$S(-command) ne ""} {
            uplevel #0 $S(-command) [list $S(result)]
    if {$ok && $S(-command) ne ""} {
        uplevel #0 $S(-command) [list $S(result)]
        }
        event generate $S(-parent) <<TkFontchooserFontChanged>>
    }
}

# ::tk::fontchooser::Apply --
#
#	Call the -command procedure appending the current font
#	Errors are reported via the background error mechanism
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

375
376

377
378

379
380

381

382
383



384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423













424
425
426
427
428
429




430
431
432


433
434

435
436
437
438


439
440

441
442
443
444

445
446
447
448

449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464

465
466
467

468
469

470
471
472

473
474

475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497

498
499
500
501
502
503
504
311
312
313
314
315
316
317

318
319
320
321
322
323

324
325
326
327
328

329
330

331
332

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371











372
373
374
375
376
377
378
379
380
381
382
383
384






385
386
387
388



389
390


391




392
393


394
395



396




397

398
399
400
401
402
403
404
405
406
407


408



409



410


411



412


413

414

415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433

434
435
436
437
438
439
440
441







-






-



+

-
+

-
+

-
+

+


+
+
+











+







+











-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
+
-
-
-
-
+
+
-
-
+

-
-
-
+
-
-
-
-
+
-










-
-
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-

-













-
+





-
+







# Arguments:
#       defaultFont     font to use as the default
#
proc ::tk::fontchooser::Init {{defaultFont ""}} {
    variable S

    if {$S(first) || $defaultFont ne ""} {
        Canonical
        if {$defaultFont eq ""} {
            set defaultFont [[entry .___e] cget -font]
            destroy .___e
        }
        array set F [font actual $defaultFont]
        set S(font) $F(-family)
        set S(style) [::msgcat::mc "Regular"]
        set S(size) $F(-size)
        set S(strike) $F(-overstrike)
        set S(under) $F(-underline)
        set S(style) "Regular"
        if {$F(-weight) eq "bold" && $F(-slant) eq "italic"} {
            set S(style) [::msgcat::mc "Bold Italic"]
            set S(style) "Bold Italic"
        } elseif {$F(-weight) eq "bold"} {
            set S(style) [::msgcat::mc "Bold"]
            set S(style) "Bold"
        } elseif {$F(-slant) eq "italic"} {
            set S(style) [::msgcat::mc "Italic"]
            set S(style) "Italic"
        }

        set S(first) 0
    }

    Tracer a b c
    Update
}

# ::tk::fontchooser::Click --
#
#       Handles all button clicks, updating the appropriate widgets
#
# Arguments:
#       who             which widget got pressed
#
proc ::tk::fontchooser::Click {who} {
    variable S

    if {$who eq "font"} {
        set S(font) [$S(W).lfonts get [$S(W).lfonts curselection]]
    } elseif {$who eq "style"} {
        set S(style) [$S(W).lstyles get [$S(W).lstyles curselection]]
    } elseif {$who eq "size"} {
        set S(size) [$S(W).lsizes get [$S(W).lsizes curselection]]
    }
    Update
}

# ::tk::fontchooser::Tracer --
#
#       Handles traces on key variables, updating the appropriate widgets
#
# Arguments:
#       standard trace arguments (not used)
#
proc ::tk::fontchooser::Tracer {var1 var2 op} {
    variable S
    # We don't need to process strike and under
    if {$var2 ni [list strike under]} {
        # Make selection in listbox
        set value [string tolower $S($var2)]
        $S(W).l${var2}s selection clear 0 end
        set n [lsearch -exact $S(${var2}s,lcase) $value]
        $S(W).l${var2}s selection set $n
        if {$n >= 0} {
            set S($var2) [lindex $S(${var2}s) $n]
            $S(W).e$var2 icursor end
            $S(W).e$var2 selection clear

    set bad 0
    set nstate normal
    # Make selection in each listbox
    foreach var {font style size} {
        set value [string tolower $S($var)]
        $S(W).l${var}s selection clear 0 end
        set n [lsearch -exact $S(${var}s,lcase) $value]
        $S(W).l${var}s selection set $n
        if {$n != -1} {
            set S($var) [lindex $S(${var}s) $n]
            $S(W).e$var icursor end
            $S(W).e$var selection clear
            if {[set i [lsearch $S(bad) $var2]] >= 0} {
                set S(bad) [lreplace $S(bad) $i $i]
            }
        } else {
            # No match, try prefix
            set n [lsearch -glob $S(${var2}s,lcase) "$value*"]
        } else {                                ;# No match, try prefix
            # Size is weird: valid numbers are legal but don't display
            # unless in the font size list
            set n [lsearch -glob $S(${var}s,lcase) "$value*"]
            if {$var2 ne "size" || !([regexp -- {^(-[0-9]+|[0-9]+)$} $value] && $value >= -4096 && $value <= 4096)} {
                 if {[lsearch $S(bad) $var2] < 0} {
                     lappend S(bad) $var2
            set bad 1
            if {$var ne "size" || ! [string is double -strict $value]} {
                 }
            } else {
                set nstate disabled
                if {[set i [lsearch $S(bad) $var2]] >= 0} {
                    set S(bad) [lreplace $S(bad) $i $i]
                }
            }
            }
        }
        }
        $S(W).l${var2}s see $n
        $S(W).l${var}s see $n
    }
    if {[llength $S(bad)] == 0} {
        set S(nstate) normal
        Update
    if {!$bad} { Update }
    } else {
        set S(nstate) disabled
    }
    $S(W).ok configure -state $S(nstate)
    $S(W).ok configure -state $nstate
    $S(W).apply configure -state $S(nstate)
}

# ::tk::fontchooser::Update --
#
#       Shows a sample of the currently selected font
#
proc ::tk::fontchooser::Update {} {
    variable S

    set S(result) [list $S(font) $S(size)]
    if {$S(style) eq [::msgcat::mc "Bold"]} {
        lappend S(result) bold
    if {$S(style) eq "Bold"} { lappend S(result) bold }
    }
    if {$S(style) eq [::msgcat::mc "Italic"]} {
        lappend S(result) italic
    if {$S(style) eq "Italic"} { lappend S(result) italic }
    }
    if {$S(style) eq [::msgcat::mc "Bold Italic"]} {
        lappend S(result) bold italic
    if {$S(style) eq "Bold Italic"} { lappend S(result) bold italic}
    }
    if {$S(strike)} {
    if {$S(strike)} { lappend S(result) overstrike}
        lappend S(result) overstrike
    }
    if {$S(under)} {
    if {$S(under)} { lappend S(result) underline}
        lappend S(result) underline
    }


    $S(sample) configure -font $S(result)
    set S(-font) $S(result)
}

# ::tk::fontchooser::Visibility --
#
#	Notify the parent when the dialog visibility changes
#
proc ::tk::fontchooser::Visibility {w visible} {
    variable S
    if {$w eq $S(W)} {
        event generate $S(-parent) <<TkFontchooserVisibility>>
    }
}

# ::tk::fontchooser::ttk_slistbox --
# ::tk::fontchooser::ttk_listbox --
#
#	Create a properly themed scrolled listbox.
#	This is exactly right on XP but may need adjusting on other platforms.
#
proc ::tk::fontchooser::ttk_slistbox {w args} {
    set f [ttk::frame $w -style FontchooserFrame -padding 1.5p]
    set f [ttk::frame $w -style FontchooserFrame -padding 2]
    if {[catch {
        listbox $f.list -relief flat -highlightthickness 0 -borderwidth 0 {*}$args
        ttk::scrollbar $f.vs -command [list $f.list yview]
        $f.list configure -yscrollcommand [list $f.vs set]
        grid $f.list $f.vs -sticky news
        grid rowconfigure $f 0 -weight 1
        grid columnconfigure $f 0 -weight 1

Deleted library/iconbadges.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254






























































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# iconbadges.tcl --
#
#	Notification badges for Tk applications.
#
#
# Copyright © 2021 Kevin Walzer/WordTech Communications LLC

namespace eval ::tk::icons {}

image create photo ::tk::icons::1-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    kFBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/HBz/V1f/Rkb/BQX/Dw//oKD/////y8v/Bgb/Pz//ra3/+/v/
    zMz/Li7/5ub/+vr/8fH/Ly//uLj/Zmb/n5//Bwf/Dg7/kpL/YWH/rq7/h4f/Cgr/
    AQH/AgLXmjE+AAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAABYktHRBib
    aYUeAAAAnElEQVQY022Q5w6DMBCD78hi03RQuvegg77/25ULCakq/MenT4piGwAQ
    A8aFlIKzABGAiAojbRSFihhinOheSdwyVKn+UaoQsry7x5PpjDzPgBWGlPNqUdJR
    MODky9V6U20N0hwE2W5/ODokQJKdzperQ7JDt7uuPRL299o/5P+IuxA9akO4qI/n
    622jukLNp3GFBmoPjOMnHNkJv3kDExXHctm+AAAAJXRFWHRkYXRlOmNyZWF0ZQAy
    MDIxLTA4LTEwVDA4OjM1OjE0LTA0OjAw0aX6GwAAACV0RVh0ZGF0ZTptb2RpZnkA
    MjAyMS0wOC0xMFQwODozNToxNC0wNDowMKD4QqcAAAAASUVORK5CYII=
}
image create photo ::tk::icons::2-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    21BMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/Cwv/ODj/UlL/UFD/MjL/CAj/ExP/oKD/8fH//v7//f3/7u7/
    kJD/DAz/ZWX/9fX/jIz/lpb/+vr/9/f/TEz/TU3/m5v/iYn/Ly//6+v/////YmL/
    nJz/5OT/MDD/KSn/srL/7Oz/ZGT/AQH/Nzf/zs7/zc3/SUn/AgL/ICD/ysr/7e3/
    gYH/VVX/WVn/Kir/fX3/eXn/AwP/dnb/rKz/qan/q6vjChO4AAAAEXRSTlMAAA5V
    q9/4NK/0St3cDa7z4Pnet34AAAABYktHRCy63XGrAAAAwElEQVQY021Q1xLCMAxz
    uktpS9hQoOwZ9t57/P8XUSesB/RinXz2SQIAQiRZUTVNVWSJEABUdMOkHKaho0ZI
    yKIfWKFAI3qY/iCsE7AdZNFYPJFMIXNskN1gpjNZL5cv+AF1ZVBwVfRK5Uq1Vkeu
    gIqj0Wz57Q7rIldBe/1N91h/gER7S8ORN55MhcQP6WzOFssVFYf8/XrDtrv94Sje
    cxMnxnEWJtDq5Xq7B3gkhFUeaCUwFYH+xP5TzrfCyKvCJ3EzGUFH/1QDAAAAJXRF
    WHRkYXRlOmNyZWF0ZQAyMDIxLTA4LTEwVDA4OjM1OjE0LTA0OjAw0aX6GwAAACV0
    RVh0ZGF0ZTptb2RpZnkAMjAyMS0wOC0xMFQwODozNToxNC0wNDowMKD4QqcAAAAA
    SUVORK5CYII=
}
image create photo ::tk::icons::3-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    +VBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/CQn/NTX/UlL/Tk7/Kir/BAT/ERH/mZn/8PD/+Pj/+vr/5ub/
    cHD/AgL/Vlb/9PT/5eX/X1//nZ3/////29v/HR3/Fhb/QED/RET/Cwv/f3//1dX/
    Ghr/Bwf/mpr/9vb/+fn/b2//lZX/2tr//Pz/wsL/Jyf/Dg7/Bgb/MzP/c3P/XV3/
    wMD/qqr/ExP/KSn/4+P/bm7/Q0P/6ur/vb3/x8f/19f/KCj/SEj/qan/zc3/y8v/
    oKD/ODj/BQX/DQ3/AwON+4wDAAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34A
    AAABYktHRCXDAckPAAAAx0lEQVQY021Q1RLCQBDbo4qW4l7ssOLu7g7//zH07oo8
    kJfNZGczyQIAQhaOF0RR4DkLQgBEkWSrSmGVJaIhZLOrH9hthoYkh/oDh4TA6SLM
    4/X5A0HCXE7gFGOGwpFoLJ7QDKpwwJNVMpXOZHEuTzgPAhmFYkkv40qVcAFEZlur
    N5otysS3pLc73V6fSfRQ8wyGozges0NqP5nO5oslXjF7GmK96W53eH9gIWhU7Xg6
    X643M6pZ6D54PN+F/tT+85zvC93mC1+z9hl5VNGhJwAAACV0RVh0ZGF0ZTpjcmVh
    dGUAMjAyMS0wOC0xMFQwODozNToxNC0wNDowMNGl+hsAAAAldEVYdGRhdGU6bW9k
    aWZ5ADIwMjEtMDgtMTBUMDg6MzU6MTQtMDQ6MDCg+EKnAAAAAElFTkSuQmCC
}
image create photo ::tk::icons::4-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    1VBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/AgL/OTn/W1v/ODj/QED/4uL/////oaH/AQH/KSn/zs7/oqL/
    Fhb/tbX/9PT/1NT/Cgr/l5f//Pz/h4f/fHz/dXX/+/v/trb/HBz/fX3/qKj/DAz/
    EBD/ysr/4eH/zc3/5eX/8fH/lJT/BAT/Dw//uLj/5+f/5ub/8vL/+vr/paX/BQX/
    HR3/JCT/ISH/iYn/sLD/Ghr/Tk7/rq7/a2vT0ZXAAAAAEXRSTlMAAA5Vq9/4NK/0
    St3cDa7z4Pnet34AAAABYktHRBibaYUeAAAAvklEQVQY022QVRPCMBCEL1RSg5Ji
    Ibi7W9Hi//8n0aRBHtiXvflm7mZvAQChmKJquq6pSgwhAE6wYRIh08CcIWTZ5CPb
    ChnCDvmRgxHEE9HspdIZ7ok4KG6EsjmaZ6G7CqgRKRQpLXFEVNAEKVeqNYk00LnV
    G81WWyJdINbp9voDOhxFiC+OJ3Q6m9PFciUW+fn1xt/6O7o/HMV5HsI7BcH5Qq83
    JkK8o5L74ymjfh5iHpMP/Xn7TznfCpOywhdM6Ra8aC+AYwAAACV0RVh0ZGF0ZTpj
    cmVhdGUAMjAyMS0wOC0xMFQwODozNToxNS0wNDowMHfS8a8AAAAldEVYdGRhdGU6
    bW9kaWZ5ADIwMjEtMDgtMTBUMDg6MzU6MTUtMDQ6MDAGj0kTAAAAAElFTkSuQmCC
}
image create photo ::tk::icons::5-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    7VBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/ICD/MjL/Li7/CQn/Bgb/q6v/8/P/8vL/9PT/4uL/FRX/0tL/
    ////wsL/xcX/uLj/Jib/Kyv/6ur/8fH/aGj/XV3/SUn/Fhb/AQH/+Pj//Pz/7Oz/
    +fn/l5f/Dg7/ODj/qan/sLD/W1v/fn7/9/f/+vr/WVn/EBD/Ghr/2dn/gID/X1//
    oKD/EhL/5OT/Y2P/S0v/7e3/vb3/ycn/yMj/HR3/AwP/Skr/zc3/LCz/BQX/DAz/
    AgKLBoLHAAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAABYktHRB5yCiAr
    AAAAyUlEQVQY021Q1RLDMAxzVhp1XcbYMXXMzIz//zmLk9HD9GKdzvZJAgBCbJKs
    qKoiSzZCAFDR7A7K4bBrqBHidNEPXE6mEc1Nf+DWCOgeZD4/QyDImEcHyWAzFI5E
    I7F4gFFDAhmXEkkzmUpnsshlUHDk8oViqVyxkCug4ihXa/VGtNlCrgqp3en2+oPh
    SEj80AqO6WRqzsQhfz/PLJa5lbkW77mJzba225uHozDBrZ7Oncu+eaXC6ivQrXV/
    vAP9if2nnG+F3leFT2jDGOnV8F/uAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIxLTA4
    LTEwVDA4OjM1OjE1LTA0OjAwd9LxrwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMS0w
    OC0xMFQwODozNToxNS0wNDowMAaPSRMAAAAASUVORK5CYII=
}
image create photo ::tk::icons::6-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    9lBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/AQH/ICD/S0v/UlL/NDT/CAj/WVn/2dn/+Pj/+fn/8PD/jY3/
    Cgr/LCz/4OD//f3/hob/cHD/5eX/1NT/NTX/bGz/////39//T0//Bwf/j4//5ub/
    wcH/7+//4uL/f3//CQn/lpb/+/v/n5//iIj/8vL/9/f/UVH/hYX/3t7/Hx//vb3/
    VVX/6Oj/MzP/ExP/x8f/e3v/EhL/t7f/0tL/wMD/MTH/IiL/xsb/zc3/qKj/QkL/
    AgL/Cwv/Dg7/BQWiS7IgAAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAAB
    YktHRCi9sLWyAAAAyklEQVQY021Q1RLCQBDbowalBYq7y+FWirs7/P/PwPawB/Ky
    mezsThIAIMTC8YIoCjxnIQQAFclq00zYrBJqhMh27QO7/NSIpGg/UCQCqgOZ2+P1
    +QPIHCpwTlSCoXAkGos/qZMDHleJZCqdyebyyHkQcBRoMeEvecrIBRBxVGi1Vm80
    W8hFJrWp3jG6vT6TzMMBHY4CY2qwQ/P9RJ/O5gu6ZO9NE6s13Wz14o6ZYFb3scPx
    dHYzq69Al+vt/g70J/afcr4Vul4VPgDLCRmO3FuJegAAACV0RVh0ZGF0ZTpjcmVh
    dGUAMjAyMS0wOC0xMFQwODozNToxNS0wNDowMHfS8a8AAAAldEVYdGRhdGU6bW9k
    aWZ5ADIwMjEtMDgtMTBUMDg6MzU6MTUtMDQ6MDAGj0kTAAAAAElFTkSuQmCC
}
image create photo ::tk::icons::7-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    xlBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/Hh7/Njb/NTX/Ghr/i4v/9/f/8/P/8vL/8fH/9PT/eHj/fHz/
    3Nz/2Nj/19f/6Oj/////+Pj/YGD/DQ3/Fxf/FRX/IiL/trb/j4//CQn/Zmb/+/v/
    xsb/GBj/HR3/0tL//f3/Xl7/ZGT/1dX/BAT/p6f/n5//AQH/Fhb/09P/c3P/GRn/
    mZn/qqr/PT3/AgKXVg1iAAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAAB
    YktHRCJdZVysAAAAu0lEQVQY022Q1xKCMBBFN5LQixFR7Bp77wU7//9TJgTFB+7L
    njmTydxdAECooGCiqgQrBYQAhNF0gyYxdE04hEyL/mKZ3CHNpn+xNQSOy6Hkl3n8
    gKPrgOLxWamGYa3eaHL0FMDieavd6fZYfyAYAxFjOBpPpmw2F0xATf9dLFfrBNSv
    2mx3e5oqIuHAjoEkIr+npzO7RFJhWYJeb+wuDS+RVKWP5+stFa8qF4riOFsoZ+2c
    42QnLKYn/ADYChWCRPB9rQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wOC0xMFQw
    ODozNToxNS0wNDowMHfS8a8AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDgtMTBU
    MDg6MzU6MTUtMDQ6MDAGj0kTAAAAAElFTkSuQmCC
}
image create photo ::tk::icons::8-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    6lBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/Bwf/MjL/UVH/TU3/Kir/BAT/DAz/j4//7e3/+Pj/5+f/eXn/
    BQX/Skr/9/f/7+//Z2f/fn7/+/v/6ur/MDD/UFD/4uL/Jib/QUH/9PT/NTX/EhL/
    srL/////09P/2tr/m5v/CAj/ycn//f3/y8v/1dX/s7P/GBj/hYX/HR3/Zmb/0dH/
    LCz/5eX/dHT/S0v/wsL/NDT/V1f/sLD/zc3/ysr/paX/RUX/AQH/Bgb/Dg7/DQ3m
    iTf5AAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAABYktHRC8j1CARAAAA
    yklEQVQY021Q1RLCQBDbowZFSpEWh+J+xd3d/v936N5hD+QlmezsTrIAQIhLECVZ
    lkTBRQgAOorbozN43Ap6hKhe/QOv6nhE8ek/8CkE/AFUoXAkapioAn4QNIdj8UQy
    mUpnHKkJIOIom7PyhWKpjFoECalSrNbqDauJWgIZqdWmdod2e6hlbhn9wXBExxNu
    scUptWfhFJ3zRXY+TheT5Yqu+XkWYmMNtkNa3fEQLGpmfziezpcrj/oqdLs/zHeh
    P7X/POf7wuDrhU+46hlBGTVCQgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wOC0x
    MFQwODozNToxNS0wNDowMHfS8a8AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDgt
    MTBUMDg6MzU6MTUtMDQ6MDAGj0kTAAAAAElFTkSuQmCC
}
image create photo ::tk::icons::9-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    8FBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/DAz/OTn/U1P/R0f/HBz/AQH/Fhb/oqL/8/P/+fn/+Pj/1NT/
    S0v/cXH/////29v/W1v/mJj/0ND/AgL/paX/np7/Ly//7e3//Pz/lZX/vr7/GBj/
    VVX/9fX/c3P/QED/5ub//f3/19f/4OD/+/v/eXn/Pz//mZn/oaH/dXX/6Oj/Z2f/
    Kir/cHD/enr/FRX/TU3/8PD/Ojr/Ozv/2tr/nJz/CAj/Tk7/sbH/z8//wcH/Bgb/
    Dw//CgoJOUsyAAAAEXRSTlMAAA5Vq9/4NK/0St3cDa7z4Pnet34AAAABYktHRCCz
    az2AAAAAy0lEQVQY022Q1RLCQAxFs9QovlAozuLu7u72/39D0y3yQB6SO2cmmXsD
    AITYBFGSZUkUbIQAIFHsKjVLtSvICHE46aecDoMRxUV/yqUQcHtQ+QNaMKSj8rhB
    8BozHInG4okkIq8AIs4US2eyLBdCLYJk9HyBFWmpXNEQSSDjqLJavdFkLdQyR+1O
    t9cfsCFHuEj10XgynbE5XzTPL5ar9Sa+3fHzpon9rFI7sOOJmzCt5s+X6221tqxa
    ge6Pp/4O9Cf2n+d8X+izXvgCm5cZM7QQ1AwAAAAldEVYdGRhdGU6Y3JlYXRlADIw
    MjEtMDgtMTBUMDg6MzU6MTUtMDQ6MDB30vGvAAAAJXRFWHRkYXRlOm1vZGlmeQAy
    MDIxLTA4LTEwVDA4OjM1OjE1LTA0OjAwBo9JEwAAAABJRU5ErkJggg==
}

image create photo ::tk::icons::9plus-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB
    OFBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/ERH/AAD/NDT/AQH/AAD/AAD/Cgr/Nzf/U1P/SUn/Hx//AQH/mJj/8fH/+fn/
    2dn/VFT/BAT/YmL//f3/4uL/YGD/j4//IyP/GBj/xsb/xcX/Fxf/lZX/////rKz/
    JSX/5eX/3t7/3Nz/AgL/hob/yMj/Hh7/Skr/fn7/MTH/srL/vr7/9fX/NDT/NTX/
    39///v7/3d3/+vr/g4P/RET/9PT/+/v/8/P/R0f/OTn/lpb/pKT/c3P/4eH/dHT/
    Dw//Pz//VVX/5ub/ExP/JCT/bW3/fX3/Ghr/QUH/Rkb/Gxv/wsL/1dX/p6f/DAz/
    e3v/enr/Dg7/ra3/zs7/w8P/gYH/GRn/Bgb/CwuphzIHAAAAFHRSTlMAAA5Vq9/4
    NK/0St3cDa7z8/Ou4A5hHfoAAAABYktHRCy63XGrAAAA+ElEQVQY02NgYGBkZGJm
    YWVjY2VhZmJkZGAAibBzcIqAAScHO0iMkZGLWwQOuLmAYozsPCJIgIedkYGXT1RM
    XEJSCibGx8vAzC8tIysrJw/kKUhKKogIMDOwKCopq6gqyamJiKhraGqJiLAwsGrr
    6Erp6euoABUZGEoqGLEysBnrmJiayeiYW1haWVtbWdqwMbDZ2tnLOTjqODm7uNrb
    u7q5szGwinh4enn76Pj6+QcE6gf4B7EysASHhIaFu1lHiIhEGhiGgYxnFvSxj4rW
    iYkVEfGLi08AOYJXKCIxKTklFcmpQA+lJaRLIXsIi7exBA4iCIWhQQgAiNMk9J5+
    e/MAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjEtMDgtMTBUMDg6MzU6MTYtMDQ6MDBG
    OusyAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIxLTA4LTEwVDA4OjM1OjE2LTA0OjAw
    N2dTjgAAAABJRU5ErkJggg==
}
image create photo ::tk::icons::!-badge -data {
    iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAABGdBTUEAALGPC/xh
    BQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA
    olBMVEUAAAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/
    AAD/AAD/AAD/AAD/Fhb/QED/Pj7/ExP/VVX/9PT/8PD/SUn/WFj//v7/+fn/S0v/
    SEj/PDz/MjL/6Oj/Jyf/ICD/4+P/2Nj/Fxf/Dw//qKj/nZ3/Cgr/IyP/hIT/gYH/
    Hh7/PT3/Ly//paX/oqL/KCj/AgL///8V6AjgAAAAEXRSTlMAAA5Vq9/4NK/0St3c
    Da7z4Pnet34AAAABYktHRDXettlrAAAAoElEQVQY022QxxKCQBBEZ9hERkygophz
    lv//NmF3Bz0wp1dd1V3dAwCIDuNCSsGZgwjQKMr1Un2eqxoN0Q/S9gK/1lCF6d+F
    CiGKNfYHw5GGOAKWaBpn+URDwoAbw3RWzA1xEAYWRVYaEiANLPPV2pAkabPd7Umy
    xsPxdCajjb9cb3eKtyXq+AeVsFWfr/eHqtKgqmoHdczueM7vhT37wi9PRRMHXNeq
    aAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wOC0xMFQwODozNToxNi0wNDowMEY6
    6zIAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDgtMTBUMDg6MzU6MTYtMDQ6MDA3
    Z1OOAAAAAElFTkSuQmCC
}


if {[tk windowingsystem] eq "x11"} {

    # ::tk::icons::IconBadge --
    # This procedure creates an icon with an overlay badge on systems that
    # do not have a native icon/badge API.
    #
    # Arguments:
    # win - window name
    # badgenumber - badge number to draw over the window icon

    proc ::tk::icons::IconBadge {win badgenumber} {

	variable ::tk::icons::base_icon

	if {![info exists ::tk::icons::base_icon]} {
	    return -code error "::tk::icons::base_icon($win) must be set on X11"
	}

	if {![info exists ::tk::icons::base_icon($win)]} {
	    return -code error "::tk::icons::base_icon($win) must be set on X11"
	}

	if {[lsearch -exact [image names] $::tk::icons::base_icon($win)] <= 0} {
	    return -code error "can't use \"$::tk::icons::base_icon($win)\" as iconphoto: not a photo image"
	}

	if {!([string is integer $badgenumber] && $badgenumber > 0)
	        && [string match $badgenumber "!"] == 0
	        && $badgenumber ne ""} {
	    return -code error "can't use \"$badgenumber\" as icon badge"
	}

	wm iconphoto $win $::tk::icons::base_icon($win)

	if {$badgenumber eq ""} {
	    return
	}

	image create photo overlay

	switch -glob -- $badgenumber {
	    ! {
		set badge ::tk::icons::!-badge
	    }
	    [1-9] {
		set badge ::tk::icons::$badgenumber-badge
	    }
	    default {
		set badge ::tk::icons::9plus-badge
	    }

        }

	overlay copy $::tk::icons::base_icon($win)
	overlay copy $badge -from 0 0 18 18 -to 18 0
	wm iconphoto $win overlay

    }
}

Changes to library/iconlist.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# iconlist.tcl
#
#	Implements the icon-list megawidget used in the "Tk" standard file
#	selection dialog boxes.
#
# Copyright © 1994-1998 Sun Microsystems, Inc.
# Copyright © 2009 Donal K. Fellows
# Copyright (c) 1994-1998 Sun Microsystems, Inc.
# Copyright (c) 2009 Donal K. Fellows
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# API Summary:
#	tk::IconList <path> ?<option> <value>? ...
#	<path> add <imageName> <itemList>
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36







-
+







#	<path> see <index>
#	<path> selection anchor ?<int>?
#	<path> selection clear <first> ?<last>?
#	<path> selection get
#	<path> selection includes <item>
#	<path> selection set <first> ?<last>?

package require tk
package require Tk 8.6

::tk::Megawidget create ::tk::IconList ::tk::FocusableWidget {
    variable w canvas sbar accel accelCB fill font index \
	itemList itemsPerColumn list maxIH maxIW maxTH maxTW noScroll \
	numItems oldX oldY options rect selected selection textList
    constructor args {
	next {*}$args
334
335
336
337
338
339
340
341
342


343
344
345
346
347
348
349
334
335
336
337
338
339
340


341
342
343
344
345
346
347
348
349







-
-
+
+







	foreach sublist $list {
	    set usedColumn 1
	    lassign $sublist iTag tTag rTag iW iH tW tH

	    set i_dy [expr {($dy - $iH)/2}]
	    set t_dy [expr {($dy - $tH)/2}]

	    $canvas coords $iTag $x [expr {$y + $i_dy}]
	    $canvas coords $tTag [expr {$x + $shift}] [expr {$y + $t_dy}]
	    $canvas coords $iTag $x                    [expr {$y + $i_dy}]
	    $canvas coords $tTag [expr {$x + $shift}]  [expr {$y + $t_dy}]
	    $canvas coords $rTag $x $y [expr {$x+$dx}] [expr {$y+$dy}]

	    incr y $dy
	    if {($y + $dy) > $H} {
		set y [expr {$pad * 1}] ; # *1 ?
		incr x $dx
		set usedColumn 0
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387







-
+







	}

	my DrawSelection
    }

    method DrawSelection {} {
	$canvas delete selection
	$canvas itemconfigure selectionText -fill $fill
	$canvas itemconfigure selectionText -fill black
	$canvas dtag selectionText
	set cbg [ttk::style lookup TEntry -selectbackground focus]
	set cfg [ttk::style lookup TEntry -selectforeground focus]
	foreach item $selection {
	    set rTag [lindex $list $item 2]
	    foreach {iTag tTag text serial} $itemList($rTag) {
		break
401
402
403
404
405
406
407
408
409
410
411



412
413
414
415
416
417
418
419
420
421
422
423
424
425




426


427
428
429
430
431
432

433
434
435
436


437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457

458
459

460
461
462
463
464
465
466
401
402
403
404
405
406
407




408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435

436
437
438


439
440
441
442
443
444
445
446
447




448
449
450
451
452
453

454



455


456
457
458
459
460
461
462
463







-
-
-
-
+
+
+














+
+
+
+
-
+
+





-
+


-
-
+
+







-
-
-
-






-
+
-
-
-
+
-
-
+







    #	operations.
    #
    method Create {} {
	variable hull
	set sbar [ttk::scrollbar $hull.sbar -orient horizontal -takefocus 0]
	catch {$sbar configure -highlightthickness 0}
	set canvas [canvas $hull.canvas -highlightthick 0 -takefocus 1 \
			-width 300p -height 90p \
			-background [ttk::style lookup Treeview -background {} white]]
	pack $sbar -side bottom -fill x -padx 1.5p -pady {0 1.5p}
	pack $canvas -expand yes -fill both -padx 1.5p -pady {1.5p 0}
			-width 400 -height 120 -background white]
	pack $sbar -side bottom -fill x -padx 2 -pady {0 2}
	pack $canvas -expand yes -fill both -padx 2 -pady {2 0}

	$sbar configure -command [list $canvas xview]
	$canvas configure -xscrollcommand [list $sbar set]

	# Initializes the max icon/text width and height and other variables
	#
	set maxIW 1
	set maxIH 1
	set maxTW 1
	set maxTH 1
	set numItems 0
	set noScroll 1
	set selection {}
	set index(anchor) ""
	set fg [option get $canvas foreground Foreground]
	if {$fg eq ""} {
	    set fill black
	} else {
	set fill [ttk::style lookup Treeview -foreground {} black]
	    set fill $fg
	}

	# Creates the event bindings.
	#
	bind $canvas <Configure>	[namespace code {my WhenIdle Arrange}]

	bind $canvas <Button-1>		[namespace code {my Btn1 %x %y}]
	bind $canvas <1>		[namespace code {my Btn1 %x %y}]
	bind $canvas <B1-Motion>	[namespace code {my Motion1 %x %y}]
	bind $canvas <B1-Leave>		[namespace code {my Leave1 %x %y}]
	bind $canvas <Control-Button-1>	[namespace code {my CtrlBtn1 %x %y}]
	bind $canvas <Shift-Button-1>	[namespace code {my ShiftBtn1 %x %y}]
	bind $canvas <Control-1>	[namespace code {my CtrlBtn1 %x %y}]
	bind $canvas <Shift-1>		[namespace code {my ShiftBtn1 %x %y}]
	bind $canvas <B1-Enter>		[list tk::CancelRepeat]
	bind $canvas <ButtonRelease-1>	[list tk::CancelRepeat]
	bind $canvas <Double-ButtonRelease-1> \
	    [namespace code {my Double1 %x %y}]

	bind $canvas <Control-B1-Motion> {;}
	bind $canvas <Shift-B1-Motion>	[namespace code {my ShiftMotion1 %x %y}]

	bind $canvas <Shift-MouseWheel>	[namespace code {my MouseWheel %D}]
	bind $canvas <Option-Shift-MouseWheel>	[namespace code {my MouseWheel %D -12}]


	bind $canvas <<PrevLine>>	[namespace code {my UpDown -1}]
	bind $canvas <<NextLine>>	[namespace code {my UpDown  1}]
	bind $canvas <<PrevChar>>	[namespace code {my LeftRight -1}]
	bind $canvas <<NextChar>>	[namespace code {my LeftRight  1}]
	bind $canvas <Return>		[namespace code {my ReturnKey}]
	bind $canvas <Key>		[namespace code {my KeyPress %A}]
	bind $canvas <KeyPress>		[namespace code {my KeyPress %A}]
	bind $canvas <Alt-Key>		{# nothing}
	bind $canvas <Meta-Key> 	{# nothing}
	bind $canvas <Control-Key> 	{# nothing}
	bind $canvas <Control-KeyPress> ";"
	bind $canvas <Command-Key> 	{# nothing}
	bind $canvas <Fn-Key>		{# nothing}
	bind $canvas <Alt-KeyPress>	";"

	bind $canvas <FocusIn>		[namespace code {my FocusIn}]
	bind $canvas <FocusOut>		[namespace code {my FocusOut}]

	return $w
    }

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
488
489
490
491
492
493
494






495
496
497
498
499
500
501







-
-
-
-
-
-







	my Motion1 $x $y
	set ::tk::Priv(afterId) [after 50 [namespace code {my AutoScan}]]
    }

    # ----------------------------------------------------------------------

    # Event handlers
    method MouseWheel {amount {factor -120.0}} {
	if {$noScroll || $::tk_strictMotif} {
	    return
	}
	$canvas xview scroll [expr {$amount/$factor}] units
    }
    method Btn1 {x y} {
	focus $canvas
	set i [$w index @$x,$y]
	if {$i eq ""} {
	    return
	}
	$w selection clear 0 end
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
672
673
674
675
676
677
678

679
680
681
682
683
684
685
686







-
+







		set i 0
	    }
	    if {$i == $start} {
		break
	    }
	}

	if {$theIndex >= 0} {
	if {$theIndex > -1} {
	    $w selection clear 0 end
	    $w selection set $theIndex
	    $w selection anchor $theIndex
	    $w see $theIndex
	}
    }
    method Reset {} {

Changes to library/icons.tcl.

1
2
3
4

5
6
7

8
9

10
11

12
13
14
15
16
17
18



























19
20
21
22
23
24
25
26
27
28
29
































30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45




































46
47
48

49
50
51
52
53








































54
1
2
3

4
5
6

7
8

9
10

11


12
13
14


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41











42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
















74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112





113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153



-
+


-
+

-
+

-
+
-
-



-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

# icons.tcl --
#
#	A set of stock icons for use in Tk dialogs. The icons used here
#	were provided by the Vimix Icon Theme project, which provides a
#	were provided by the Tango Desktop project which provides a
#	unified set of high quality icons licensed under the
#	Creative Commons Attribution Share-Alike license
#	(https://creativecommons.org/licenses/by-sa/4.0/)
#	(http://creativecommons.org/licenses/by-sa/3.0/)
#
#	See https://github.com/vinceliuice/vimix-icon-theme
#	See http://tango.freedesktop.org/Tango_Desktop_Project
#
# Copyright © 2009 Pat Thoyts <[email protected]>
# Copyright (c) 2009 Pat Thoyts <[email protected]>
# Copyright © 2022 Harald Oehlmann <[email protected]>
# Copyright © 2022 Csaba Nemethi <[email protected]>

namespace eval ::tk::icons {}

variable ::tk::svgFmt [list svg -scale [expr {[::tk::ScalingPct] / 100.0}]]

image create photo ::tk::icons::warning -data {
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAABSZJREFU
    WIXll1toVEcYgL+Zc87u2Yu7MYmrWRuTJuvdiMuqiJd4yYKXgMQKVkSjFR80kFIVJfWCWlvpg4h9
    8sXGWGof8iKNICYSo6JgkCBEJRG8ImYThNrNxmaTeM7pQ5IlJkabi0/9YZhhZv7///4z/8zPgf+7
    KCNRLgdlJijXwRyuDTlcxV9hbzv8nQmxMjg+XDtiOEplkG9PSfkztGmTgmFQd+FCVzwa3fYN/PHZ
    AcpBaReicW5xcbb64IEQqko8Lc26d/58cxS+/BY6hmJvyEfQBoUpwWCmW1FErKaGWHU13uRk4QkE
    UtxQNFR7QwIoB4eiKD9PWbVKbb10CZmaCqmpxCormRYO26QQx85B0mcD+AeK0xYvHqu1tNDx+DH6
    gQM4jh0j3tCA3tGBLyfHLuD7zwJwAcYqun44sHy51nr5MsqsWWj5+djCYdS5c4ldvUr24sU2qarf
    lUL6qAN0wqH0vDy7+fAhXZEI+v79CNmt7igpofPVK5SmJvyhkJBwYlQBSiHd7vUWZ86bp8WqqtCW
    LkVbuBAhBEIItGAQ2+rVxG7cICMY1KTDsekc5IwagIQTmStXis47dzBiMfR9+xCi+wb39s79+zFi
    MczGRjLmzTMlnBoVgLMwyzF+/Cb/lClq2/Xr2AoKUKdPxzAMWltbiUajmKaJkpGBY8sW3tbW4g8E
    VNXrXVEKK0YMoMKp7Px8K15Tg2VZOHbvBiASiRAMBgkGg0QiEYQQOIuLsRSFrnv3yJo/HxVOW594
    7D4KUAa57qysvNSUFOVtbS32rVuRfj9CCFwuV2Kfy+VCCIFMScFVVET7/fukJidLm883rQy+HhaA
    BUII8cvUNWt4W1WFcLvRd+5MnHl/AOjOB+eOHchx44jX1ZEdCqkSTpaDbcgA5+GrpNmzc9ymKdvr
    67Hv2oVMSko4cjgcKIqCoijoup64EdLpxLV3Lx1PnuCVUrgmTfK9hV1DAjgKqlSUk1PCYdl25QrS
    70cvLEw4SWS+04nT6XxvXgiBc8MGtKlTaa+rIysnR1Ok/OF38PxngAzY4VuwYKL99WvR8fQpjj17
    kLqeiL6393g8eDyeAWBSVfEcOkRXczOOaBRvVpZuDPJEDwD4DVyKrv+UlZurxSorUWfMQC8oGOBc
    CDHgC/Rdc4TD2BctIl5fT+bkyTahaXvOw8RPApiwd2Ju7hjZ2EhXSwvOkhKQcoADgIqKCioqKgYc
    QW9LOnIEIxZDbWpiXCCABT9+FKAUxtm83pKMUEiLVVejLVqEtmTJB50LIdi2bRuFPbnRd7232efM
    wbVuHR2PHjHR77dJXS8sg5mDAihweFJenmrevYvR1oazpGTQ6IQQaJqG7ClI/dd655IOHsSyLMSL
    F6QFAib9nugEQClk2Xy+orTsbK3t1i3sa9ei5eQMGr0QgvLyci5evDiocyEEtsxMPNu30/nsGRO8
    XlVzu8NlkNvrV+0T/fHMZcusrtu3MeNx9PXrobUVq8cYQrw3TrRub1h9+v573Bs3Ej1zBvP5c/zp
    6dbLhoaTwPy+ANKCfF92thq7dg2A6JYt/fNlxGK8eUNSerryHEJHQT8K8V4A5ztojty8OeaLzZul
    1DSwLCzDANPEMozusWFgmWZ33288YK3/nGlixuM0v3xpWfDX0Z4i1VupXEWwIgRnJfhGPfQ+YsLr
    +7DzNFwCuvqWyiRg7DSYoIBu9smPkYqEd4AwIN4ITUAL0A4Da7UC6ICdEfy2fUBMoAvo7GnWKNoe
    mfwLcAuinuFNL7QAAAAASUVORK5CYII=
}
image create photo ::tk::icons::error -format $::tk::svgFmt -data {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <circle cx="16" cy="16" r="16" fill="#d32f2f"/>
     <g transform="rotate(45,16,16)" fill="#fff">
      <rect x="6" y="14" width="20" height="4"/>
      <rect x="14" y="6" width="4" height="20"/>
     </g>
    </svg>
}


image create photo ::tk::icons::error -data {
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAABiRJREFU
    WIXFl11sHFcVgL97Z/bX693sbtd2ipOqCU7sQKukFYUigQgv/a+hoZGoqipvfQKpAsEDD0hIvCHE
    j/pQ3sIDUdOiIqUyqXioEFSUhqit7cRJFJpEruxs1mt77Z3d2Z259/KwM5vZXTtOERJXOrozZ+6e
    852fuXcW/s9D3O3Cs1Bow1Nx234BKQ9qpYpK6yFLSseScsVoveApdUrAzNOw9j8DOAMTtmX9RsM3
    SqOjevcXDqUzu8dI5AvEc8O0axu4q6s4yzdZvnCxUSmXLWHMXzxjXpmGq/81wGmIZ6T8NXDi8w8d
    id//+GPS8j1YWQXHgVYbfA/sGCRiMDQExTzKtvn3zDv6k9m5FsacXNT6+y+D95kAZqCEEO/cMzIy
    9eBLLybjyodrN6DpDqw1/dfpFNw3TtuSfPz7P7irlZUL2pjHn4GVuwJ4G/JCiLl9U1OjB58/ZnP5
    Mqxv3NGpMWZAz64cHNzHlTf/5N9YuHzTMeaLx6HW78+K3pwGKynEu/snJycOHPuWzdw81BuDUQZO
    dfQ+MmvAuC1MdY3i178izUo15VZXj07DyTf6OGX0Jivlz0vFwgMTz3/bNnMXO0ZCo8b0iIk4C0WF
    zsP1TRc1e4l9x56N5YuFwxkpf9afgW4J/gi7M1IuHH3lezm5uAQbmwOpjc79ujArA2uMgWwGMz7K
    P377u/WW1pPTUB7IQFrKXx44NJWRbQ9d2+hGqbeRMEoTZEQFJdERfVgmvVFH+D57Jw9k4lL+YqAE
    pyGnjZm+95knLHVjcVvHA6WIPgtLE+hVH4i6vsS9T3zTVsY8NwPZHoAUPFUs5JVQCt1q9zqORKm3
    iLKrF6IjkfSHOiUlqu0hhCSXHdYePNYDEBPiu6MT+zOquo6JGNGhESkxUnYNmkCnLQtjWRgpMRG9
    CtZ3JdD7axsU9+3N2EK8EALYQcNMpvfuQTcaXUMIAa+/Hi0Xgs9weASjefx4p5mFQDdbpD63G/HR
    hakeAA2l+EgJU652iIMMyO2sRoYxBq1191oIgZQSITqooT0A7fnEirswUAp/LwG0MZlYIY9WqpPa
    IHU7Da01Sqluo4UQSil830dr3emVsBeMIZbLoI0Z7gGQQtTbjoOOxW/XewcApVQ38jsBNs6fx6tW
    O70Si+GWKwghNsM1NoCAW81KJTeUjKNbrR2N7uS4B7TRwJ+fR6TTxO4fxzUeAio9AMCl+tVrE0NH
    DmM2nU4DAu6JE53UGoNfLuNdv45xnO4OF/ZKz+4X2T179I6D5To0NupouNgD4Btzqjx/8WjpS0cy
    PU1Tr6MqFfylpc4bss1W26/rBwyfybECtcvXNrUxp3oAXJjZ2Kxb7cVP8P61gDGgWy2M624Z5d1E
    3wNkDDKdwMQkjtuygbMhgAQ4DjUhxFvL/5z15X1jeLUaynW7p1u484WiuL3V9m/NoV6F50Ogjx3Y
    Q/mDBV8a3piGzR4AAFfrHy4vlesmm0bks7edRQ6aAafcPoZVH2AUXOYzkI5TvbVa9+FHREYX4Bgs
    I8RrV9/9oJF4eBKTjO8YvdoCJgqujcGkEqQemmDxb7OOFOLV6FHcAwBQ1/onTtOd/fTvH3rJRx/A
    pBIDqd0q+p5sRaInnWDoywdZem+u7bbaH9W1/il9Y2Brfwt22TBfKOVHxr92JOacv4S/UuttuC06
    PKoHsEs5hg7vZ/m9eW+zWltuwoNbfRNuebacgXsEnE2lkof2Hn04ZRouzQvXUU5z29cwFGs4TWpy
    HJGK8+lfP256bnuuDU8+B9WtfG17uL0GsTF4VQrxYn60kBh55JDEbdG6uYq/7qDdFtpTELOQyQRW
    Lk1sLI+MW9w6d8Wv3Vrz2nDyJPzgDDS287MVgAAywBCQ+Q5MTsOPs/BIMpVQ2bFCKlnMYg+nsYeS
    eE6TVq1Be3WD9ZtrTc9tWetw7k341dtwBagDTmTeESAdAAxH5z0w9iQ8ehi+moWxBGRsiPvguVBf
    h8qH8P6f4dxSp9PrdN73cN6k859R3U0J0nS+28JMpIM5FUgCiNP5X2ECox7gAk06KQ8ldLzZ7/xO
    ANHnscBhCkgGjuOB3gb8CEAbaAWO3UA34DQ6/gPnmhBFs5mqXAAAAABJRU5ErkJggg==
}
image create photo ::tk::icons::warning -format $::tk::svgFmt -data {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <circle cx="16" cy="16" r="16" fill="#f67400"/>
     <circle cx="16" cy="24" r="2" fill="#fff"/>
     <path d="m14 20h4v-14h-4z" fill="#fff"/>
    </svg>
}

image create photo ::tk::icons::information -format $::tk::svgFmt -data {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <circle cx="16" cy="16" r="16" fill="#2091df"/>
     <circle cx="16" cy="8" r="2" fill="#fff"/>
     <path d="m14 12h4v14h-4z" fill="#fff"/>
    </svg>

image create photo ::tk::icons::information -data {
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
    WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gUdFDM4pWaDogAABwNJREFUWMPFlltsVNcVhv+199ln
    bh7PjAdfMGNDcA04EKMkJlIsBVJVbRqlEVUrqyW0QAtFTVWpjVpFfamUF6K+tCTKQyXn0jaiShOr
    bRqRoHJpEEoIEBucENuk2OViPB5f5j5zrvuc3YcMFQ8FPBFVj7S0paN91v+tf1/OAv7PD9UzeeCp
    p0KRCrYyHtymoPrgySYAANdyBBr2Peu1agP+NrR/v3nHAb6/52d7wfivWlet11NdvZG21laEwzo0
    RvA9F4uLi7h08bxxaWLUVp78xSsv/XrwjgAMDDyjRxPWUGOy5Uu9/VsjEA3I5KvIVQ240gHIh9CA
    5YkwelIJRATw94NvGpnpK0fL+eDA0NAzzq3ya7cDjCbsoWWr1j+y4f4vB/41Z8JTeaxqE7hndSNi
    EeELzn3LkapQdfzJTE5JV/GBb28LHz327lcnzp4ZAvB1AOpmAvyWtv/g6R9GW1c+uf6Bx0Kfzpjo
    TmnYtDaKtkTAj4aEFBqTnJPUOfciIeG3N4XVQtmyzl/JuY8/fH9wOjO/smvVmuy5s+8P1w2wa9dP
    46SLN3sf2ha7uiixaU0Qna06NA6PMXIZQRJBMiIXRBKABygv3hBQV+bK1dmcoR7d3Bc5c/pk/8YN
    fYOjo6es/6bDbgbAdLa9uXNj2PYF2pOEloQGAiRIuUTkME42J7IZweYES+NkckZWWNfseEPAKJtO
    oWxLu69/c5jpbPtNdW7qPwvsbO1cF8pVLKxs0+HD94gpl0AOQTlEsDkjizFmMk4WESyNM4NzMgOC
    VYI6q17OlIp9992ngek769+EvtfVEI3jWqaKgAgAIAlFLuOwGZHDiTnElGQgF4DvM1LKV7Bdz2NE
    xaCuhQpVm1Y0p5qhvNV1AyjlRTWhwVM2TMdzgkJzieAQyGGMbMZgfwZBEiBPA3xX+VSouAvBAFeM
    yDddD7rgpHw/WjcAMa0EZScZk5heqFrxiO4BzCGCzYgsBrI4I5sYcxlBKl/5WdOdd6S0gxoLEZEi
    Iq4AnzGq1r0HiPhYuZRFU1R3FgqWkS1aZQA2gWzOyGQcJudkaAwVR3qz8yXzvCXlzJoViaagrlWC
    jJnLm8Jarli2GNMm6wbwPPO31y6Ollc2N3pcI+fyYjW/8a5EKqQTz5WtdLHsTi1W7Im5vDlcMdxx
    wVk2Ys9/pTI3+WhAaIauM+MLbYnlH46MVKVyX6v7Hhg9e2ps3doN32ld0Rlrb1nmmK4stCdCSCUj
    Le1NwW6uXJ08m/t2OarBXh0ie0syHu0plKtTFGw8n4o33q1z1XngD7+X3C/uHBkZces7hoAi1946
    fPSvtpDlYFdLPDI8mR03HC87frXwFpgqLYuFuzrbkg8m49EeDsqDa+cizXcNpppia5ui+sYXnn+O
    29LbOTg4aHzun9GOPT/pDemhf3xzx25DicjkiqaAIs4zhumMRUJaPhzgJZ0LQ5C7gXjQL1kS0YD+
    o337nhWlYvHJV178zZ9vlZ/dDuDVl57/2HWt755894hINoYSmZx11TYKCUZKCs4cnQuDmGtfvDiR
    dD3n04aA6J4YHzeLhfLg7cSXBAAA5NPpufS1WFjwkFSelZ6ZLWfn0kliTDJdue8dO9qenp2d1DVR
    4cTarlyZJgV5dim5lwTw8sv7c1L6H89cm6FlDcHVhlOJffThsa9d+ud72y5+cnTn2PjJJ1avjOoE
    SnBiPadOfRDTGT5YSm5tqR2R7Zp7//L6gRPf27NjVaolqS9MCzh28W6mgDXdKxCNRb/oOlV18O3D
    1xzXGXpx8LnZO94Tbt/x+MFYouexh7dsQU/PWjRGI+BcAyMgm1vAO28fxvj4xOX5jL7u0KEX7Dvq
    AAC0Nucf2rLZhq8Y3njjT8gulOBKDw0NAQjNQT435eQWL3iHDk3YS81ZF0B6psI/GbuAXbu+gQf7
    H4ArPeQWC5jLZKCUhQvjWb2QD3bVk5PVM9nz5LML8waOH38fekBHIhFDqqMFXd0pnDhxGmMTU3Bd
    9/X/GQDntO/eezswMPBjaFwAABxH4sKFq+jt7cX6ni6EQuJbdeWsZ3J3d/PTmqaEYUyhXDZBTEOh
    WIIQwOi5jzA1eRnZXPFSPO7/bmbGlLfqhus5BVotRH9/x7rGxtBeIQJPACrMOYNSPpRiUIpnlTIO
    nzmT+eX8fLH8WZMKF4Csje7ncUAHEKhFcHq6ZE5OZoc7O3tlc3N33+7dP9c2bXoE09NlO52uHDhy
    ZOTVatUWte+otsTXg2pQSwagG6r/jwsAQul0erqjo+OesbGx1tHRUT+fz48dP378j57neQD8mtB1
    B1TtnV9zo64loJqoXhtFDUQHEGhvb2/2fZ9nMpliTcAFYNdC1sIBYN1sCeq5Ca9bqtWcu9Fe3FDl
    9Uqvu3HLjfhvTUo85WzjhogAAAAASUVORK5CYII=
}

image create photo ::tk::icons::question -format $::tk::svgFmt -data {
image create photo ::tk::icons::question -data {
    <?xml version="1.0" encoding="UTF-8"?>
    <svg width="32" height="32" version="1.1" xmlns="http://www.w3.org/2000/svg">
     <circle cx="16" cy="16" r="16" fill="#5c6bc0"/>
     <path d="m17.6 27.2h-3.2v-3.2h3.2zm3.312-12.4-1.44 1.472c-1.152 1.168-1.872 2.128-1.872 4.528h-3.2v-0.8c0-1.76 0.72-3.36 1.872-4.528l1.984-2.016a3.128 3.128 0 0 0 0.944-2.256c0-1.76-1.44-3.2-3.2-3.2s-3.2 1.44-3.2 3.2h-3.2c0-3.536 2.864-6.4 6.4-6.4s6.4 2.864 6.4 6.4c0 1.408-0.576 2.688-1.488 3.6z" fill="#fff"/>
    </svg>
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAACG5JREFU
    WIXFl3twVdUVxn97n3Nubm7euZcghEdeBBICEQUFIgVECqIo1uJMp3WodqyjMzpjZ7TTh20cK31N
    /2jL2FYdKXaqRcbnDKGpoBFaAY1BHgHMgyRKQkJy87yv3Nyzd/84594k1RlppzPumTXn3Dl3r/Wd
    b31rrbPhS17iSv+4bl2t2ZFhrRGI7QKxRkMAyHEfjwgYEOgjNnpfcXjiSENDbeL/AqBoW22uGE/7
    MYL7yubN4MYVpVkrquaKqwJZ+LPTARgcjdIbHKOx+aI+9EH7WGvnZdA8q9PGf9b5eu3w/wygaPPO
    h6Uhntxcsyj9/q+vtMrnBa6Is7ZPgzzzyvGJ/YfPRpWWj3fWff93/xWAonW1Xu3z/nVx6cxNTz74
    1YzK4gIQjuN/nfyEEx9fIjgaYXAkhhAQyE3Hn5PBsvJZrF46l5I5+QB83NnP40+/FT7d1ltPOPrN
    zoba2BcCWLy91hMOp72/bX1VxU/u3+BJ91i0fhrkuTcaaTzbjTQkhpQIIZBSIBApL1prtNYsryhk
    xy1XUzonn1g8wVPPvh1/5dDpcz5f7LrmfbXxqfGM6eG1yCw+9uq2G6tW7nxoU5plGrzecJYnnnub
    SwMhTNPAmmKmYWCaBoYpMQyJaRhIQ3IpGOKt4+1k+dKoLJ7BjStKjb6hcN7JloFrhlsO7oUnPh9A
    8Rbvo6uuLrr3N4/ckm4Ykt/vPcqe/R9hGAamaWJZbnDL+W2axqRJA8NlxzAkAI3newhF4lxbMZs1
    y4rNM+19c0PZ++NDLQff+0wKCu/Y6c/UVsubv/12/ryZubxUf5Ln3vgQ0zKnvK1kadkMlpQUUFEU
    oCDPR25WOuPxBH2DYZpa+qg/3kEoGsdWCttWJGzF3ZuXcuf6Ci5eHmXrw7sHR4mXd7/2w+A0Bvyl
    N+265/bl19+8eqE8c6GPn+85jGkYWC4Ay3Luf/3AV1g038+MXB8+rwfDkKR5TPKyvCyan8+qqtmc
    au8nFrcdnQCn2vuoLptJSWEeE7bynDjdXTDUcvBNAAmweF1tpmXKu+65bYWh0Ty97zhSyGkUO0BM
    hBAI4RAXTyjiCYWUEukKMz/Ly/b1C7EsE49lYlkmhjTYvf8jNHD3lmsM0zTuWryuNhPABIj4vFvW
    Xl0s87PTOdXWS8snQTwec4ro3DSYBglbcfx8P+8199I7FMEQgg3L53N7TWkKXOV8Px7LJCFtXKx0
    dA9zrnOAyqIAa68tkQePtm4BXpaO9vWOm65b4EPAkY+6HDEZTt4NN/dJML946QSv/fMCA6PjpHks
    LI/F2a5BtNYpMUtJirGpLL7f3A3AxpXlPiHFjhQDaJZVlc0EoPWT4DQ1m8ZkKizTJDRuY1mmC04i
    pWDNksJUD9Bac7E/jGUZrmuN1qCU5sKlIQAqSwrQWi+bBCDwF+RnAk5fl27wqeYAkZM9wLWaxVex
    qnJmKritFO+e7sMyDdBOc1JKYxiSkdA4CMGM3Aw02j+VAfLcwTIWibuiEpNApJMSw208ydJcu3QW
    axZPCW7bHGjspmcwimkYTmAlMWzHTyTmDMiczLRU/ctkNxgajboPvUghppuUGFJMY6O6OJ/ViwIo
    pVBKYds2dR9e4uPuMbc7Tm9MUgqyM70AjITHUy1IAghNsH8oDEAgz4cQOIqWjkkpEC4rSYfXL/Sn
    giulONYyRFd/1GXKAZxkUrgvkp/tAAgORxAQnAQg5InmC5cBWDgv4NS5EAhAINzyIlVmUgiy040U
    9Uop2voiKYakEAiRvDp7EYKS2XkAnOvsR0h5IqUBrfWeQ8fb1t2xvtJXs3QuB462TfZokbxMGZxC
    8If6DtI8Fh6PhcdjojSpBuXin7Kc3csXzQLgrWOtEWWrPSkAvkis7kjTBTU8FqOypIAF8/x09Y6Q
    FGjyTdHJstLsWDsnNZIBXj7Wj1LKYSS5B412nRTNymHBnHxGQ+O8836r8kVidakUNDfUhhIJtfcv
    dU22AO69dRlCCNeZU8fJe6U0ylZYBlgGmNKx+ESCiYRNwlYoWzn/UxqtHOB3ra8AAX/7x0nbttXe
    5oba0GQVAPGE9dju1z4Y7u4fY9F8P9/YWOUEV06O7eTVnXBTBaiUIj4xwcSETSJhk7BtbNtOPdta
    U0ZpYS59wRB/2ndsOBa3HkvGTU3D0fb6aE7ZBt3RM1yzuabcqiwKEI5N0N495ChaSKcihJPRa0pz
    sbUmYTugPmgbJmErB4DLxETC5oYlhWxdXUrCVvxgV32krav/qa4Djx76D4kllxalt/7q9e2bqjf9
    9Lsb0oQQHGrsYO+hc0gp3emW/Bhxm5NbZlqD0g79CTcFt60u4YYlhWhg5/MN4y/WNdW3vfnoNhD6
    Mww46wlmV9/w6snzA1sHRqKBVUvnGQvm+qkuKyA4GqVvKOJAdrcn8zz14yNh2ywozOVbGyuoKg4w
    PmHzyxcOx1+sazqTlhbZ3H92vT29Pj5nzVn1SLqVH3ipunzOxqceutlX6n7lXrw8yqn2flq7hxgL
    TzAWiyOFICfTS44vjbLCXKqK/cwOOHOl49IwP9r192hT84V3e4+9cF90sC0IRL8QAOADsgvXfu9B
    b3bgkTs3LPN+52srzPlX5V7RUerTy6M8/0Zj4uUDH45Hg13PdB/9425gzLUhQH0RgDQgC8hKLyid
    7a/c9oCV4d9WVTpLbF5TmX5tRaGYkecjJ8MLAkZD4wyMRGg636PrDjfHzrT26NhYT33w1Kt/Hh/u
    6XUDh4BBIHwlDIBTohlANpBhWb6s7PKNK30FCzZa6dnVYORoIX2OExVF26Px8NCZSN/5d0bb3mlK
    JGIhHLpDwLAL4jPnxSs9nBqABXhddrw4XdRygSrABuKuxYBx9/6KDqlf2vo3PYe56vmkuwMAAAAA
    SUVORK5CYII=
}

Changes to library/listbox.tcl.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60

61
62
63
64
65
66
67
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59

60
61
62
63
64
65
66
67





-
-
-
+
+
+








-
+
















-
+









-
+












-
+


-
+







# listbox.tcl --
#
# This file defines the default bindings for Tk listbox widgets
# and provides procedures that help in implementing those bindings.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

#--------------------------------------------------------------------------
# tk::Priv elements used in this file:
#
# afterId -		Token returned by "after" for autoscanning.
# listboxPrev -	The last element to be selected or deselected
# listboxPrev -		The last element to be selected or deselected
#			during a selection operation.
# listboxSelection -	All of the items that were selected before the
#			current selection operation (such as a mouse
#			drag) started;  used to cancel an operation.
#--------------------------------------------------------------------------

#-------------------------------------------------------------------------
# The code below creates the default class bindings for listboxes.
#-------------------------------------------------------------------------

# Note: the check for existence of %W below is because this binding
# is sometimes invoked after a window has been deleted (e.g. because
# there is a double-click binding on the widget that deletes it).  Users
# can put "break"s in their bindings to avoid the error, but this check
# makes that unnecessary.

bind Listbox <Button-1> {
bind Listbox <1> {
    if {[winfo exists %W]} {
	tk::ListboxBeginSelect %W [%W index @%x,%y] 1
    }
}

# Ignore double clicks so that users can define their own behaviors.
# Among other things, this prevents errors if the user deletes the
# listbox on a double click.

bind Listbox <Double-Button-1> {
bind Listbox <Double-1> {
    # Empty script
}

bind Listbox <B1-Motion> {
    set tk::Priv(x) %x
    set tk::Priv(y) %y
    tk::ListboxMotion %W [%W index @%x,%y]
}
bind Listbox <ButtonRelease-1> {
    tk::CancelRepeat
    %W activate @%x,%y
}
bind Listbox <Shift-Button-1> {
bind Listbox <Shift-1> {
    tk::ListboxBeginExtend %W [%W index @%x,%y]
}
bind Listbox <Control-Button-1> {
bind Listbox <Control-1> {
    tk::ListboxBeginToggle %W [%W index @%x,%y]
}
bind Listbox <B1-Leave> {
    set tk::Priv(x) %x
    set tk::Priv(y) %y
    tk::ListboxAutoScan %W
}
165
166
167
168
169
170
171
172

173
174
175
176
177






178
179
180
181
182
183
184
185
186
187
188
189
190
191




























192
193


194
195
196
197
198
199















200
201
202
203
204
205
206
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183














184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211


212
213






214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235







-
+





+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	%W selection clear 0 end
        tk::FireListboxSelectEvent %W
    }
}

# Additional Tk bindings that aren't part of the Motif look and feel:

bind Listbox <Button-2> {
bind Listbox <2> {
    %W scan mark %x %y
}
bind Listbox <B2-Motion> {
    %W scan dragto %x %y
}

# The MouseWheel will typically only fire on Windows and Mac OS X.
# However, someone could use the "event generate" command to produce
# one on other platforms.

if {[tk windowingsystem] eq "aqua"} {
bind Listbox <MouseWheel> {
    tk::MouseWheel %W y %D -40.0 units
}
bind Listbox <Option-MouseWheel> {
    tk::MouseWheel %W y %D -12.0 units
}
bind Listbox <Shift-MouseWheel> {
    tk::MouseWheel %W x %D -40.0 units
}
bind Listbox <Shift-Option-MouseWheel> {
    tk::MouseWheel %W x %D -12.0 units
}
bind Listbox <TouchpadScroll> {
    if {%# %% 5 != 0} {
    bind Listbox <MouseWheel> {
        %W yview scroll [expr {- (%D)}] units
    }
    bind Listbox <Option-MouseWheel> {
        %W yview scroll [expr {-10 * (%D)}] units
    }
    bind Listbox <Shift-MouseWheel> {
        %W xview scroll [expr {- (%D)}] units
    }
    bind Listbox <Shift-Option-MouseWheel> {
        %W xview scroll [expr {-10 * (%D)}] units
    }
} else {
    bind Listbox <MouseWheel> {
        %W yview scroll [expr {- (%D / 120) * 4}] units
    }
    bind Listbox <Shift-MouseWheel> {
        %W xview scroll [expr {- (%D / 120) * 4}] units
    }
}

if {"x11" eq [tk windowingsystem]} {
    # Support for mousewheels on Linux/Unix commonly comes through mapping
    # the wheel to the extended buttons.  If you have a mousewheel, find
    # Linux configuration info at:
    #	http://www.inria.fr/koala/colas/mouse-wheel-scroll/
    bind Listbox <4> {
	if {!$tk_strictMotif} {
	return
    }
	    %W yview scroll -5 units
	}
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    if {$deltaX != 0} {
 	%W xview scroll [expr {-$deltaX}] units
    }
    if {$deltaY != 0} {
	%W yview scroll [expr {-$deltaY}] units
    }
    bind Listbox <Shift-4> {
	if {!$tk_strictMotif} {
	    %W xview scroll -5 units
	}
    }
    bind Listbox <5> {
	if {!$tk_strictMotif} {
	    %W yview scroll 5 units
	}
    }
    bind Listbox <Shift-5> {
	if {!$tk_strictMotif} {
	    %W xview scroll 5 units
	}
    }
}

# ::tk::ListboxBeginSelect --
#
# This procedure is typically invoked on button-1 presses.  It begins
# the process of making a selection in the listbox.  Its exact behavior
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283

284
285
286
287
288
289
290
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

306
307
308
309
310
311

312
313
314
315
316
317
318
319







-
+














-
+





-
+







	    $w selection clear 0 end
	    $w selection set $el
	    set Priv(listboxPrev) $el
	    tk::FireListboxSelectEvent $w
	}
	extended {
	    set i $Priv(listboxPrev)
	    if {$i < 0} {
	    if {$i eq ""} {
		set i $el
		$w selection set $el
	    }
	    if {[$w selection includes anchor]} {
		$w selection clear $i $el
		$w selection set anchor $el
	    } else {
		$w selection clear $i $el
		$w selection clear anchor $el
	    }
	    if {![info exists Priv(listboxSelection)]} {
		set Priv(listboxSelection) [$w curselection]
	    }
	    while {($i < $el) && ($i < $anchor)} {
		if {$i in $Priv(listboxSelection)} {
		if {[lsearch $Priv(listboxSelection) $i] >= 0} {
		    $w selection set $i
		}
		incr i
	    }
	    while {($i > $el) && ($i > $anchor)} {
		if {$i in $Priv(listboxSelection)} {
		if {[lsearch $Priv(listboxSelection) $i] >= 0} {
		    $w selection set $i
		}
		incr i -1
	    }
	    set Priv(listboxPrev) $el
	    tk::FireListboxSelectEvent $w
	}
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519







-
+










-
+







proc ::tk::ListboxCancel w {
    variable ::tk::Priv
    if {[$w cget -selectmode] ne "extended"} {
	return
    }
    set first [$w index anchor]
    set last $Priv(listboxPrev)
    if {$last < 0} {
    if {$last eq ""} {
	# Not actually doing any selection right now
	return
    }
    if {$first > $last} {
	set tmp $first
	set first $last
	set last $tmp
    }
    $w selection clear $first $last
    while {$first <= $last} {
	if {$first in $Priv(listboxSelection)} {
	if {[lsearch $Priv(listboxSelection) $first] >= 0} {
	    $w selection set $first
	}
	incr first
    }
    tk::FireListboxSelectEvent $w
}

Changes to library/megawidget.tcl.

1
2
3
4
5
6
7

8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6

7
8
9
10
11
12

13
14
15
16
17
18
19
20






-
+





-
+







# megawidget.tcl
#
#	Basic megawidget support classes. Experimental for any use other than
#	the ::tk::IconList megawdget, which is itself only designed for use in
#	the Unix file dialogs.
#
# Copyright © 2009-2010 Donal K. Fellows
# Copyright (c) 2009-2010 Donal K. Fellows
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

package require tk
package require Tk 8.6

::oo::class create ::tk::Megawidget {
    superclass ::oo::class
    method unknown {w args} {
	if {[string match .* $w]} {
	    [self] create $w {*}$args
	    return $w
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297







-
+










	    {-cursor cursor Cursor {}}
	    {-takefocus takeFocus TakeFocus ::ttk::takefocus}
	}
    }
    method CreateHull {} {
	ttk::frame $w
	set hull [ttk::entry $w.cHull -takefocus 0 -cursor $options(-cursor)]
	pack $hull -expand yes -fill both -ipadx 1.5p -ipady 1.5p
	pack $hull -expand yes -fill both -ipadx 2 -ipady 2
	my TraceOption -cursor UpdateCursorOption
    }
}

return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to library/menu.tcl.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17






-
-
-
-
+
+
+
+







# menu.tcl --
#
# This file defines the default bindings for Tk menus and menubuttons.
# It also implements keyboard traversal of menus and implements a few
# other utility procedures related to menus.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2007 Daniel A. Steffen <[email protected]>
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2007 Daniel A. Steffen <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#-------------------------------------------------------------------------
# Elements of tk::Priv that are used in this file:
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98







-
+







bind Menubutton <FocusIn> {}
bind Menubutton <Enter> {
    tk::MbEnter %W
}
bind Menubutton <Leave> {
    tk::MbLeave %W
}
bind Menubutton <Button-1> {
bind Menubutton <1> {
    if {$tk::Priv(inMenubutton) ne ""} {
	tk::MbPost $tk::Priv(inMenubutton) %X %Y
    }
}
bind Menubutton <Motion> {
    tk::MbMotion %W up %X %Y
}
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148







-
+








bind Menu <Leave> {
    tk::MenuLeave %W %X %Y %s
}
bind Menu <Motion> {
    tk::MenuMotion %W %x %y %s
}
bind Menu <Button> {
bind Menu <ButtonPress> {
    tk::MenuButtonDown %W
}
bind Menu <ButtonRelease> {
   tk::MenuInvoke %W 1
}
bind Menu <space> {
    tk::MenuInvoke %W 0
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195







-
+








-
+







-
+







}
bind Menu <<PrevLine>> {
    tk::MenuUpArrow %W
}
bind Menu <<NextLine>> {
    tk::MenuDownArrow %W
}
bind Menu <Key> {
bind Menu <KeyPress> {
    tk::TraverseWithinMenu %W %A
    break
}

# The following bindings apply to all windows, and are used to
# implement keyboard menu traversal.

if {[tk windowingsystem] eq "x11"} {
    bind all <Alt-Key> {
    bind all <Alt-KeyPress> {
	tk::TraverseToMenu %W %A
    }

    bind all <F10> {
	tk::FirstMenu %W
    }
} else {
    bind Menubutton <Alt-Key> {
    bind Menubutton <Alt-KeyPress> {
	tk::TraverseToMenu %W %A
    }

    bind Menubutton <F10> {
	tk::FirstMenu %W
    }
}
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
230
231
232
233
234
235
236

237
238
239
240
241
242
243







-







	return
    }
    if {[$w cget -state] eq "active" && [tk windowingsystem] ne "aqua"} {
	$w configure -state normal
    }
}


# ::tk::MbPost --
# Given a menubutton, this procedure does all the work of posting
# its associated menu and unposting any other menu that is currently
# posted.
#
# Arguments:
# w -			The name of the menubutton widget whose menu
265
266
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282
283
284

285





286








287
288








































































289
290

291
292
293
294
295
296

297
298
299
300
301
302
303
264
265
266
267
268
269
270


271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
-
+
+










-
+

+
+
+
+
+

+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+





-
+







	    "can't post $menu: it isn't a descendant of $w"
    }
    set cur $Priv(postedMb)
    if {$cur ne ""} {
	MenuUnpost {}
    }
    if {$::tk_strictMotif} {
	set Priv(cursor) [$w cget -cursor]
	$w configure -cursor arrow
        set Priv(cursor) [$w cget -cursor]
        $w configure -cursor arrow
    }
    if {[tk windowingsystem] ne "aqua"} {
	set Priv(relief) [$w cget -relief]
	$w configure -relief raised
    } else {
	$w configure -state active
    }

    set Priv(postedMb) $w
    set Priv(focus) [focus]
    $menu activate {}
    $menu activate none
    GenerateMenuSelect $menu

    # If this looks like an option menubutton then post the menu so
    # that the current entry is on top of the mouse.  Otherwise post
    # the menu just below the menubutton, as for a pull-down.

    update idletasks
    if {[catch {
	switch [$w cget -direction] {
	    above {
		set x [winfo rootx $w]
		set y [expr {[winfo rooty $w] - [winfo reqheight $menu]}]
		# if we go offscreen to the top, show as 'below'
		if {$y < [winfo vrooty $w]} {
		    set y [expr {[winfo vrooty $w] + [winfo rooty $w] + [winfo reqheight $w]}]

    if {[catch {PostMenubuttonMenu $w $menu $x $y} msg opt]} {
		}
		PostOverPoint $menu $x $y
	    }
	    below {
		set x [winfo rootx $w]
		set y [expr {[winfo rooty $w] + [winfo height $w]}]
		# if we go offscreen to the bottom, show as 'above'
		set mh [winfo reqheight $menu]
		if {($y + $mh) > ([winfo vrooty $w] + [winfo vrootheight $w])} {
		    set y [expr {[winfo vrooty $w] + [winfo vrootheight $w] + [winfo rooty $w] - $mh}]
		}
		PostOverPoint $menu $x $y
	    }
	    left {
		set x [expr {[winfo rootx $w] - [winfo reqwidth $menu]}]
		set y [expr {(2 * [winfo rooty $w] + [winfo height $w]) / 2}]
		set entry [MenuFindName $menu [$w cget -text]]
		if {$entry eq ""} {
                    set entry 0
		}
		if {[$w cget -indicatoron]} {
		    if {$entry == [$menu index last]} {
			incr y [expr {-([$menu yposition $entry] \
				+ [winfo reqheight $menu])/2}]
		    } else {
			incr y [expr {-([$menu yposition $entry] \
			        + [$menu yposition [expr {$entry+1}]])/2}]
		    }
		}
		PostOverPoint $menu $x $y
		if {$entry ne "" \
			&& [$menu entrycget $entry -state] ne "disabled"} {
		    $menu activate $entry
		    GenerateMenuSelect $menu
		}
	    }
	    right {
		set x [expr {[winfo rootx $w] + [winfo width $w]}]
		set y [expr {(2 * [winfo rooty $w] + [winfo height $w]) / 2}]
		set entry [MenuFindName $menu [$w cget -text]]
		if {$entry eq ""} {
                    set entry 0
		}
		if {[$w cget -indicatoron]} {
		    if {$entry == [$menu index last]} {
			incr y [expr {-([$menu yposition $entry] \
				+ [winfo reqheight $menu])/2}]
		    } else {
			incr y [expr {-([$menu yposition $entry] \
			        + [$menu yposition [expr {$entry+1}]])/2}]
		    }
		}
		PostOverPoint $menu $x $y
		if {$entry ne "" \
			&& [$menu entrycget $entry -state] ne "disabled"} {
		    $menu activate $entry
		    GenerateMenuSelect $menu
		}
	    }
	    default {
		if {[$w cget -indicatoron]} {
		    if {$y eq ""} {
			set x [expr {[winfo rootx $w] + [winfo width $w]/2}]
			set y [expr {[winfo rooty $w] + [winfo height $w]/2}]
		    }
	            PostOverPoint $menu $x $y [MenuFindName $menu [$w cget -text]]
		} else {
		    PostOverPoint $menu [winfo rootx $w] [expr {[winfo rooty $w]+[winfo height $w]}]
		}
	    }
	}
    } msg opt]} {
	# Error posting menu (e.g. bogus -postcommand). Unpost it and
	# reflect the error.

	MenuUnpost {}
	return -options $opt $msg
    }

    set Priv(tearoff) $tearoff
    if {$tearoff != 0 && [tk windowingsystem] ne "aqua"} {
    if {$tearoff != 0} {
	focus $menu
	if {[winfo viewable $w]} {
	    SaveGrabInfo $w
	    grab -global $w
	}
    }
}
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368


369
370
371
372
373
374
375
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449


450
451
452
453
454
455
456
457
458







-
+




















-
-
+
+








    catch {
	if {$mb ne ""} {
	    set menu [$mb cget -menu]
	    $menu unpost
	    set Priv(postedMb) {}
	    if {$::tk_strictMotif} {
		$mb configure -cursor $Priv(cursor)
	        $mb configure -cursor $Priv(cursor)
	    }
	    if {[tk windowingsystem] ne "aqua"} {
		$mb configure -relief $Priv(relief)
	    } else {
		$mb configure -state normal
	    }
	} elseif {$Priv(popup) ne ""} {
	    $Priv(popup) unpost
	    set Priv(popup) {}
	} elseif {[$menu cget -type] ne "menubar" && [$menu cget -type] ne "tearoff"} {
	    # We're in a cascaded sub-menu from a torn-off menu or popup.
	    # Unpost all the menus up to the toplevel one (but not
	    # including the top-level torn-off one) and deactivate the
	    # top-level torn off menu if there is one.

	    while {1} {
		set parent [winfo parent $menu]
		if {[winfo class $parent] ne "Menu" || ![winfo ismapped $parent]} {
		    break
		}
		$parent activate {}
		$parent postcascade {}
		$parent activate none
		$parent postcascade none
		GenerateMenuSelect $parent
		set type [$parent cget -type]
		if {$type eq "menubar" || $type eq "tearoff"} {
		    break
		}
		set menu $parent
	    }
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495








496
497
498
499


500
501
502
503



504
505
506
507



508
509
510
511
512
513
514
554
555
556
557
558
559
560

561
562
563
564
565
566
567
568
569
570








571
572
573
574
575
576
577
578




579
580




581
582
583




584
585
586
587
588
589
590
591
592
593







-
+









-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+







# x -			The x position of the mouse.
# y -			The y position of the mouse.
# state -		Modifier state (tells whether buttons are down).

proc ::tk::MenuMotion {menu x y state} {
    variable ::tk::Priv
    if {$menu eq $Priv(window)} {
	set activeindex [$menu index active]
        set activeindex [$menu index active]
	if {[$menu cget -type] eq "menubar"} {
	    if {[info exists Priv(focus)] && $menu ne $Priv(focus)} {
		$menu activate @$x,$y
		GenerateMenuSelect $menu
	    }
	} else {
	    $menu activate @$x,$y
	    GenerateMenuSelect $menu
	}
	set index [$menu index @$x,$y]
	if {[info exists Priv(menuActivated)] \
		&& $index >= 0 \
		&& $index ne $activeindex} {
	    set mode [option get $menu clickToFocus ClickToFocus]
	    if {[string is false $mode]} {
		set delay [expr {[$menu cget -type] eq "menubar" ? 0 : 50}]
		if {[$menu type $index] eq "cascade"} {
        set index [$menu index @$x,$y]
        if {[info exists Priv(menuActivated)] \
                && $index ne "none" \
                && $index ne $activeindex} {
            set mode [option get $menu clickToFocus ClickToFocus]
            if {[string is false $mode]} {
                set delay [expr {[$menu cget -type] eq "menubar" ? 0 : 50}]
                if {[$menu type $index] eq "cascade"} {
		    # Catch these postcascade commands since the menu could be
		    # destroyed before they run.
		    set Priv(menuActivatedTimer) \
			[after $delay [list catch [list \
                    set Priv(menuActivatedTimer) \
                        [after $delay [list $menu postcascade active]]
			    $menu postcascade active]]]
		} else {
		    set Priv(menuDeactivatedTimer) \
			[after $delay [list catch [list
                } else {
                    set Priv(menuDeactivatedTimer) \
                        [after $delay [list $menu postcascade none]]
			    $menu postcascade {}]]]
		}
	    }
	}
                }
            }
        }
    }
}

# ::tk::MenuButtonDown --
# Handles button presses in menus.  There are a couple of tricky things
# here:
# 1. Change the posted cascade entry (if any) to match the mouse position.
523
524
525
526
527
528
529
530

531
532

533
534

535
536

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557

558
559
560
561
562
563
564
602
603
604
605
606
607
608

609
610

611


612


613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
641







-
+

-
+
-
-
+
-
-
+




















-
+







# Arguments:
# menu -		The menu window.

proc ::tk::MenuButtonDown menu {
    variable ::tk::Priv

    if {![winfo viewable $menu]} {
	return
        return
    }
    if {[$menu index active] < 0} {
    if {[$menu index active] eq "none"} {
	if {[$menu cget -type] ne "menubar" } {
	    set Priv(window) {}
        set Priv(window) {}
	}
	return
        return
    }
    $menu postcascade active
    if {$Priv(postedMb) ne "" && [winfo viewable $Priv(postedMb)]} {
	grab -global $Priv(postedMb)
    } else {
	while {[$menu cget -type] eq "normal" \
		&& [winfo class [winfo parent $menu]] eq "Menu" \
		&& [winfo ismapped [winfo parent $menu]]} {
	    set menu [winfo parent $menu]
	}

	if {$Priv(menuBar) eq {}} {
	    set Priv(menuBar) $menu
	    if {$::tk_strictMotif} {
		set Priv(cursor) [$menu cget -cursor]
		$menu configure -cursor arrow
	    }
	    if {[$menu type active] eq "cascade"} {
		set Priv(menuActivated) 1
	    }
	}
        }

	# Don't update grab information if the grab window isn't changing.
	# Otherwise, we'll get an error when we unpost the menus and
	# restore the grab, since the old grab window will not be viewable
	# anymore.

	if {$menu ne [grab current $menu]} {
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682







-
+







-
+







# menu -		The menu window.
# rootx, rooty -	Root coordinates of mouse.
# state -		Modifier state.

proc ::tk::MenuLeave {menu rootx rooty state} {
    variable ::tk::Priv
    set Priv(window) {}
    if {[$menu index active] < 0} {
    if {[$menu index active] eq "none"} {
	return
    }
    if {[$menu type active] eq "cascade" \
	    && [winfo containing $rootx $rooty] eq \
		[$menu entrycget active -menu]} {
	return
    }
    $menu activate {}
    $menu activate none
    GenerateMenuSelect $menu
}

# ::tk::MenuInvoke --
# This procedure is invoked when button 1 is released over a menu.
# It invokes the appropriate menu action and unposts the menu if
# it came from a menubutton.
613
614
615
616
617
618
619
620
621


622
623
624
625
626
627
628
629
630
631
632
633
634
635
636



637
638
639
640
641
642
643

644
645
646
647
648
649
650
651
652
653
654

655
656

657

658
659
660
661
662
663
664
690
691
692
693
694
695
696


697
698
699
700
701
702
703
704
705
706
707
708
709
710



711
712
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
728
729
730

731
732
733
734

735
736
737
738
739
740
741
742







-
-
+
+












-
-
-
+
+
+






-
+










-
+


+
-
+







    variable ::tk::Priv

    if {$buttonRelease && $Priv(window) eq ""} {
	# Mouse was pressed over a menu without a menu button, then
	# dragged off the menu (possibly with a cascade posted) and
	# released.  Unpost everything and quit.

	$w postcascade {}
	$w activate {}
	$w postcascade none
	$w activate none
	event generate $w <<MenuSelect>>
	MenuUnpost $w
	return
    }
    if {[$w type active] eq "cascade"} {
	$w postcascade active
	set menu [$w entrycget active -menu]
	MenuFirstEntry $menu
    } elseif {[$w type active] eq "tearoff"} {
	::tk::TearOffMenu $w
	MenuUnpost $w
    } elseif {[$w cget -type] eq "menubar"} {
	$w postcascade {}
	set activeindex [$w index active]
	set isCascade [string equal [$w type $activeindex] "cascade"]
	$w postcascade none
	set active [$w index active]
	set isCascade [string equal [$w type $active] "cascade"]

	# Only de-activate the active item if it's a cascade; this prevents
	# the annoying "activation flicker" you otherwise get with
	# checkbuttons/commands/etc. on menubars

	if { $isCascade } {
	    $w activate {}
	    $w activate none
	    event generate $w <<MenuSelect>>
	}

	MenuUnpost $w

	# If the active item is not a cascade, invoke it.  This enables
	# the use of checkbuttons/commands/etc. on menubars (which is legal,
	# but not recommended)

	if { !$isCascade } {
	    uplevel #0 [list $w invoke $activeindex]
	    uplevel #0 [list $w invoke $active]
	}
    } else {
	set active [$w index active]
	if {$Priv(popup) eq "" || [$w index active] >= 0} {
	if {$Priv(popup) eq "" || $active ne "none"} {
	    MenuUnpost $w
	}
	uplevel #0 [list $w invoke active]
    }
}

# ::tk::MenuEscape --
754
755
756
757
758
759
760
761

762
763
764
765

766
767
768
769
770
771
772
832
833
834
835
836
837
838

839
840
841
842

843
844
845
846
847
848
849
850







-
+



-
+







		set parent [winfo parent $parent]
	    }
	}
    } else {
	set count -1
	set m2 [winfo parent $menu]
	if {[winfo class $m2] eq "Menu"} {
	    $menu activate {}
	    $menu activate none
	    GenerateMenuSelect $menu
	    tk_menuSetFocus $m2

	    $m2 postcascade {}
	    $m2 postcascade none

	    if {[$m2 cget -type] ne "menubar"} {
		return
	    }
	}
    }

794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
872
873
874
875
876
877
878

879
880
881
882
883
884
885
886







-
+







	while {$i >= $length} {
	    incr i -$length
	}
	set mb [lindex $buttons $i]
	if {[winfo class $mb] eq "Menubutton" \
		&& [$mb cget -state] ne "disabled" \
		&& [$mb cget -menu] ne "" \
		&& [[$mb cget -menu] index last] >= 0} {
		&& [[$mb cget -menu] index last] ne "none"} {
	    break
	}
	if {$mb eq $w} {
	    return
	}
	incr i $count
    }
816
817
818
819
820
821
822
823

824
825
826
827

828
829
830


831
832
833

834
835
836
837
838
839
840
894
895
896
897
898
899
900

901

902
903

904
905


906
907
908
909

910
911
912
913
914
915
916
917







-
+
-


-
+

-
-
+
+


-
+







#
# Arguments:
# menu -			Menu window that received the keystroke.
# count -			1 means go to the next lower entry,
#				-1 means go to the next higher entry.

proc ::tk::MenuNextEntry {menu count} {
    set last [$menu index last]
    if {[$menu index last] eq "none"} {
    if {$last < 0} {
	return
    }
    set length [expr {$last+1}]
    set length [expr {[$menu index last]+1}]
    set quitAfter $length
    set activeindex [$menu index active]
    if {$activeindex < 0} {
    set active [$menu index active]
    if {$active eq "none"} {
	set i 0
    } else {
	set i [expr {$activeindex + $count}]
	set i [expr {$active + $count}]
    }
    while {1} {
	if {$quitAfter <= 0} {
	    # We've tried every entry in the menu.  Either there are
	    # none, or they're all disabled.  Just give up.

	    return
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
925
926
927
928
929
930
931

932
933
934
935
936
937
938
939







-
+







	if {[catch {$menu entrycget $i -state} state] == 0} {
	    if {$state ne "disabled" && \
		    ($i!=0 || [$menu cget -type] ne "tearoff" \
		    || [$menu type 0] ne "tearoff")} {
		break
	    }
	}
	if {$i == $activeindex} {
	if {$i == $active} {
	    return
	}
	incr i $count
	incr quitAfter -1
    }
    $menu activate $i
    GenerateMenuSelect $menu
891
892
893
894
895
896
897
898

899
900
901
902
903
904
905
906
907
908

909
910

911

912
913


914
915
916
917
918
919
920
921
922
923

924
925
926
927
928
929
930
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982
983
984

985
986
987
988

989


990
991
992
993
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
1008







-
+









-
+


+
-
+
-
-
+
+









-
+








proc ::tk::MenuFind {w char} {
    set char [string tolower $char]
    set windowlist [winfo child $w]

    foreach child $windowlist {
	# Don't descend into other toplevels.
	if {[winfo toplevel $w] ne [winfo toplevel $child]} {
        if {[winfo toplevel $w] ne [winfo toplevel $child]} {
	    continue
	}
	if {[winfo class $child] eq "Menu" && \
		[$child cget -type] eq "menubar"} {
	    if {$char eq ""} {
		return $child
	    }
	    set last [$child index last]
	    for {set i [$child cget -tearoff]} {$i <= $last} {incr i} {
		if {([$child type $i] eq "separator") || ([$child entrycget $i -state] eq "disabled")} {
		if {[$child type $i] eq "separator"} {
		    continue
		}
		set char2 [string index [$child entrycget $i -label] \
		set underline [$child entrycget $i -underline]
			[$child entrycget $i -underline]]
		if {$underline >= 0} {
		    if {$char eq [string tolower [string index [$child entrycget $i -label] $underline]]} {
		if {$char eq [string tolower $char2] || $char eq ""} {
		    if {[$child entrycget $i -state] ne "disabled"} {
			return $child
		    }
		}
	    }
	}
    }

    foreach child $windowlist {
	# Don't descend into other toplevels.
	if {[winfo toplevel $w] ne [winfo toplevel $child]} {
        if {[winfo toplevel $w] ne [winfo toplevel $child]} {
	    continue
	}
	switch -- [winfo class $child] {
	    Menubutton {
		set char2 [string index [$child cget -text] \
			[$child cget -underline]]
		if {$char eq [string tolower $char2] || $char eq ""} {
1023
1024
1025
1026
1027
1028
1029



1030
1031
1032
1033
1034
1035
1036
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117







+
+
+








proc ::tk::TraverseWithinMenu {w char} {
    if {$char eq ""} {
	return
    }
    set char [string tolower $char]
    set last [$w index last]
    if {$last eq "none"} {
	return
    }
    for {set i 0} {$i <= $last} {incr i} {
	if {[catch {set char2 [string index \
		[$w entrycget $i -label] [$w entrycget $i -underline]]}]} {
	    continue
	}
	if {$char eq [string tolower $char2]} {
	    if {[$w type $i] eq "cascade"} {
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072



1073
1074
1075
1076
1077
1078
1079
1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163







-
+



+
+
+







# menu -		Name of the menu window (possibly empty).

proc ::tk::MenuFirstEntry menu {
    if {$menu eq ""} {
	return
    }
    tk_menuSetFocus $menu
    if {[$menu index active] >= 0} {
    if {[$menu index active] ne "none"} {
	return
    }
    set last [$menu index last]
    if {$last eq "none"} {
	return
    }
    for {set i 0} {$i <= $last} {incr i} {
	if {([catch {set state [$menu entrycget $i -state]}] == 0) \
		&& $state ne "disabled" && [$menu type $i] ne "tearoff"} {
	    $menu activate $i
	    GenerateMenuSelect $menu
	    # Only post the cascade if the current menu is a menubar;
	    # otherwise, if the first entry of the cascade is a cascade,
1105
1106
1107
1108
1109
1110
1111



1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238



1239
1240
1241
1242


1243
1244
1245


1246
1247

1248
1249
1250
1251
1252
1253


1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284




1285
1286
1287
1288
1289
1290
1291
1292
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208


































































































1209




1210
1211
1212


1213
1214
1215
1216
1217
1218
1219
1220




1221
1222
1223




1224
1225

1226

1227
1228
1229

1230
1231





1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248

1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261




1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272







+
+
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
+
+
+
-
-








-
-
-
-
+
+
+
-
-
-
-
+
+
-

-
+
+

-
+

-
-
-
-
-
+
+















-
+











+
-
-
-
-
+
+
+
+
-







proc ::tk::MenuFindName {menu s} {
    set i ""
    if {![regexp {^active$|^last$|^none$|^[0-9]|^@} $s]} {
	catch {set i [$menu index $s]}
	return $i
    }
    set last [$menu index last]
    if {$last eq "none"} {
	return
    }
    for {set i 0} {$i <= $last} {incr i} {
	if {![catch {$menu entrycget $i -label} label]} {
	    if {$label eq $s} {
		return $i
	    }
	}
    }
    return ""
}

# ::tk::PostMenubuttonMenu --
#
# Given a menubutton and a menu, this procedure posts the menu at the
# appropriate location.  If the menubutton looks like an option
# menubutton, meaning that the indicator is on and the direction is
# neither above nor below, then the menu is posted so that the current
# entry is vertically aligned with the menubutton.  On the Mac this
# will expose a small amount of the blue indicator on the right hand
# side.  On other platforms the entry is centered over the button.

if {[tk windowingsystem] eq "aqua"} {
    proc ::tk::PostMenubuttonMenu {button menu cx cy} {
	set entry ""
	if {[$button cget -indicatoron]} {
	    set entry [MenuFindName $menu [$button cget -text]]
	    if {$entry eq ""} {
		set entry 0
	    }
	}
	set x [winfo rootx $button]
	set y [expr {2 + [winfo rooty $button]}]
	switch [$button cget -direction] {
	    above {
		set entry ""
		incr y [expr {4 - [winfo reqheight $menu]}]
	    }
	    below {
		set entry ""
		incr y [expr {2 + [winfo height $button]}]
	    }
	    left {
		incr x [expr {-[winfo reqwidth $menu]}]
	    }
	    right {
		incr x [winfo width $button]
	    }
	    default {  # flush
		incr x [expr {[winfo width $button] - [winfo reqwidth $menu] - 5}]
	    }
	}
	PostOverPoint $menu $x $y $entry
    }
} else {
    proc ::tk::PostMenubuttonMenu {button menu cx cy} {
	set entry ""
	if {[$button cget -indicatoron]} {
	    set entry [MenuFindName $menu [$button cget -text]]
	    if {$entry eq ""} {
		set entry 0
	    }
	}
	set x [winfo rootx $button]
	set y [winfo rooty $button]
	switch [$button cget -direction] {
	    above {
		incr y [expr {-[winfo reqheight $menu]}]
		# if we go offscreen to the top, show as 'below'
		if {$y < [winfo vrooty $button]} {
		    set y [expr {[winfo vrooty $button] + [winfo rooty $button]\
			   + [winfo reqheight $button]}]
		}
		set entry {}
	    }
	    below {
		incr y [winfo height $button]
		# if we go offscreen to the bottom, show as 'above'
		set mh [winfo reqheight $menu]
		if {($y + $mh) > ([winfo vrooty $button] + [winfo vrootheight $button])} {
		    set y [expr {[winfo vrooty $button] + [winfo vrootheight $button] \
			   + [winfo rooty $button] - $mh}]
		}
		set entry {}
	    }
	    left {
		incr x [expr {- [winfo reqwidth $menu]}]
	    }
	    right {
		incr x [expr {[winfo width $button]}]
	    }
	    default {  # flush
                if {[$button cget -indicatoron]} {
                    if {$cx ne ""} {
                        set x [expr {$cx - [winfo reqwidth $menu] / 2}]
                        set l [font metrics [$menu cget -font] -linespace]
                        set y [expr {$cy - $l/2 - 2}]
                    } else {
                        incr x [expr {([winfo width $button] - \
				[winfo reqwidth $menu])/ 2}]
                    }
                } else {
                    incr y [winfo height $button]
                }
	    }
	}
	PostOverPoint $menu $x $y $entry
    }
}

# ::tk::PostOverPoint --
#
# This procedure posts a menu on the screen so that a given entry in
# the menu is positioned with its upper left corner at a given point
# in the root window.  The procedure also activates that entry.  If no
# This procedure posts a given menu such that a given entry in the
# menu is centered over a given point in the root window.  It also
# activates the given entry.
# entry is specified the upper left corner of the entire menu is
# placed at the point.
#
# Arguments:
# menu -		Menu to post.
# x, y -		Root coordinates of point.
# entry -		Index of entry within menu to center over (x,y).
#			If omitted or specified as {}, then the menu's
#			upper-left corner goes at (x,y).

if {[tk windowingsystem] ne "win32"} {
    proc ::tk::PostOverPoint {menu x y {entry {}}}  {
	if {$entry ne ""} {
	    $menu post $x $y $entry
proc ::tk::PostOverPoint {menu x y {entry {}}}  {
    if {$entry ne ""} {
	if {$entry == [$menu index last]} {
	    if {[$menu type $entry] ni {separator tearoff} &&
		[$menu entrycget $entry -state] ne "disabled"} {
		$menu activate $entry
		GenerateMenuSelect $menu
	    incr y [expr {-([$menu yposition $entry] \
		    + [winfo reqheight $menu])/2}]
	    }
	} else {
	    $menu post $x $y
	    incr y [expr {-([$menu yposition $entry] \
		    + [$menu yposition [expr {$entry+1}]])/2}]
	}
	return
	incr x [expr {-[winfo reqwidth $menu]/2}]
    }
} else {
    proc ::tk::PostOverPoint {menu x y {entry {}}}  {
	if {$entry ne ""} {
	    incr y [expr {-[$menu yposition $entry]}]
	}

    if {[tk windowingsystem] eq "win32"} {
	# osVersion is not available in safe interps
	set ver 5
	if {[info exists ::tcl_platform(osVersion)]} {
	    scan $::tcl_platform(osVersion) %d ver
	}

	# We need to fix some problems with menu posting on Windows,
	# where, if the menu would overlap top or bottom of screen,
	# Windows puts it in the wrong place for us.  We must also
	# subtract an extra amount for half the height of the current
	# entry.  To be safe we subtract an extra 10.
	# NOTE: this issue appears to have been resolved in the Window
	# manager provided with Vista and Windows 7.
	if {$ver < 6} {
	    set yoffset [expr {[winfo screenheight $menu] \
				   - $y - [winfo reqheight $menu] - 10}]
		    - $y - [winfo reqheight $menu] - 10}]
	    if {$yoffset < [winfo vrooty $menu]} {
		# The bottom of the menu is offscreen, so adjust upwards
		incr y [expr {$yoffset - [winfo vrooty $menu]}]
	    }
	    # If we're off the top of the screen (either because we were
	    # originally or because we just adjusted too far upwards),
	    # then make the menu popup on the top edge.
	    if {$y < [winfo vrooty $menu]} {
		set y [winfo vrooty $menu]
	    }
	}
    }
	$menu post $x $y
	if {$entry ne "" && [$menu entrycget $entry -state] ne "disabled"} {
	    $menu activate $entry
	    GenerateMenuSelect $menu
    $menu post $x $y
    if {$entry ne "" && [$menu entrycget $entry -state] ne "disabled"} {
	$menu activate $entry
	GenerateMenuSelect $menu
	}
    }
}

# ::tk::SaveGrabInfo --
# Sets the variables tk::Priv(oldGrab) and tk::Priv(grabStatus) to record
# the state of any existing grab on the w's display.
#
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342








1343
1344
1345
1346
1347
1348
1349
1350
1311
1312
1313
1314
1315
1316
1317





1318
1319
1320
1321
1322
1323
1324
1325

1326
1327
1328
1329
1330
1331
1332







-
-
-
-
-
+
+
+
+
+
+
+
+
-







    }
    focus $menu
}

proc ::tk::GenerateMenuSelect {menu} {
    variable ::tk::Priv

    if {$Priv(activeMenu) ne $menu \
	    || $Priv(activeItem) ne [$menu index active]} {
	set Priv(activeMenu) $menu
	set Priv(activeItem) [$menu index active]
	event generate $menu <<MenuSelect>>
    if {$Priv(activeMenu) eq $menu \
	    && $Priv(activeItem) eq [$menu index active]} {
	return
    }

    set Priv(activeMenu) $menu
    set Priv(activeItem) [$menu index active]
    event generate $menu <<MenuSelect>>
    }
}

# ::tk_popup --
# This procedure pops up a menu and sets things up for traversing
# the menu and its submenus.
#
# Arguments:
1358
1359
1360
1361
1362
1363
1364
1365

1366
1367
1368
1369
1370
1371
1372
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353
1354







-
+







proc ::tk_popup {menu x y {entry {}}} {
    variable ::tk::Priv
    if {$Priv(popup) ne "" || $Priv(postedMb) ne ""} {
	tk::MenuUnpost {}
    }
    tk::PostOverPoint $menu $x $y $entry
    if {[tk windowingsystem] eq "x11" && [winfo viewable $menu]} {
	tk::SaveGrabInfo $menu
        tk::SaveGrabInfo $menu
	grab -global $menu
	set Priv(popup) $menu
	set Priv(window) $menu
	set Priv(menuActivated) 1
	tk_menuSetFocus $menu
    }
}

Changes to library/msgbox.tcl.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







# msgbox.tcl --
#
#	Implements messageboxes for platforms that do not have native
#	messagebox support.
#
# Copyright © 1994-1997 Sun Microsystems, Inc.
# 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.
#

# Ensure existence of ::tk::dialog namespace
#
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
119
120
121
122
123
124
125



126
127
128
129
130
131
132







-
-
-







#	by tk_messageBox if the platform does not have native
#	messagebox support, or if the particular type of messagebox is
#	not supported natively.
#
#	Color icons are used on Unix displays that have a color
#	depth of 4 or more and $tk_strictMotif is not on.
#
#	Uses ::tk::Priv.${disp}(button) instead of ::tk::Priv(button) to
#	avoid adverse effects of [::tk::ScreenChanged]. Bug [e2cec2fa41].
#
#	This procedure is a private procedure shouldn't be called
#	directly. Call tk_messageBox instead.
#
#	See the user documentation for details on what tk_messageBox does.
#
proc ::tk::MessageBox {args} {
    global tk_strictMotif
163
164
165
166
167
168
169



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
























177
178
179
180
181
182
183







+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    set windowingsystem [tk windowingsystem]
    if {$windowingsystem eq "aqua"} {
	switch -- $data(-icon) {
	    "error"     {set data(-icon) "stop"}
	    "warning"   {set data(-icon) "caution"}
	    "info"      {set data(-icon) "note"}
	}
	option add *Dialog*background systemDialogBackgroundActive widgetDefault
	option add *Dialog*Button.highlightBackground \
		systemDialogBackgroundActive widgetDefault
    }

    if {![winfo exists $data(-parent)]} {
	return -code error -errorcode [list TK LOOKUP WINDOW $data(-parent)] \
	    "bad window path name \"$data(-parent)\""
    }

    # Select the vwait variable carefully.
    set oldScreen $Priv(screen)
    set screen [winfo screen $data(-parent)]

    # Extract the display name (cf. ScreenChanged, including [Bug 2912473] fix).
    set disp [string range $screen 0 [string last . $screen]-1]

    # Ensure that namespace separators never occur in the display name (as
    # they cause problems in variable names). Double-colons exist in some VNC
    # display names. [Bug 2912473]
    set disp [string map {:: _doublecolon_} $disp]

    if {![info exists ::tk::Priv.${disp}]} {
	# Use ScreenChanged to create ::tk::Priv.${disp}, then change back to old
	# screen to avoid interfering with Tk expectations for bindings.
	ScreenChanged $screen
	ScreenChanged $oldScreen
    }

    variable ::tk::Priv.${disp}
    # Now in place of ::tk::Priv(button), use ::tk::Priv.${disp}(button) which
    # is the intended target variable of upvar and will not be redefined when
    # ::tk::ScreenChanged is called.

    switch -- $data(-type) {
	abortretryignore {
	    set names [list abort retry ignore]
	    set labels [list &Abort &Retry &Ignore]
	    set cancel abort
	}
	ok {
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
230
231
232
233
234
235
236

237

238
239
240
241
242
243
244







-
+
-







	if {[lindex $btn 0] eq $data(-default)} {
	    set valid 1
	    break
	}
    }
    if {!$valid} {
	return -code error -errorcode {TK MSGBOX DEFAULT} \
	    "bad -default value \"$data(-default)\": must be\
	    "invalid default button \"$data(-default)\""
	    abort, retry, ignore, ok, cancel, no, or yes"
    }

    # 2. Set the dialog to be a child window of $parent
    #
    #
    if {$data(-parent) ne "."} {
	set w $data(-parent).__tk__messagebox
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







	if {![llength $opts]} {
	    # Capitalize the first letter of $name
	    set capName [string toupper $name 0]
	    set opts [list -text $capName]
	}

	eval [list tk::AmpWidget ttk::button $w.$name] $opts \
		[list -command [list set tk::Priv.${disp}(button) $name]]
		[list -command [list set tk::Priv(button) $name]]

	if {$name eq $data(-default)} {
	    $w.$name configure -default active
	} else {
	    $w.$name configure -default normal
	}
	grid $w.$name -in $w.bot -row 0 -column $i -padx 3m -pady 2m -sticky ew
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405







-
+







	}
    }

    # Invoke the designated cancelling operation
    bind $w <Escape> [list $w.$cancel invoke]

    # At <Destroy> the buttons have vanished, so must do this directly.
    bind $w.msg <Destroy> [list set tk::Priv.${disp}(button) $cancel]
    bind $w.msg <Destroy> [list set tk::Priv(button) $cancel]

    # 7. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display (Motif style) and de-iconify it.

    ::tk::PlaceWindow $w widget $data(-parent)

439
440
441
442
443
444
445
446

447
448
449

450
451
452
453
454
414
415
416
417
418
419
420

421
422
423

424
425
426
427
428
429







-
+


-
+






    # 9. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    vwait ::tk::Priv.${disp}(button)
    vwait ::tk::Priv(button)
    # Copy the result now so any <Destroy> that happens won't cause
    # trouble
    set result [set Priv.${disp}(button)]
    set result $Priv(button)

    ::tk::RestoreFocusGrab $w $focus

    return $result
}

Changes to library/msgs/cs.msg.

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
71
72
73
74
75
76
77

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset cs "green" "zeleá"
    ::msgcat::mcset cs "ignore" "ignorovat"
    ::msgcat::mcset cs "ok"
    ::msgcat::mcset cs "red" "červeá"
    ::msgcat::mcset cs "retry" "znovu"
    ::msgcat::mcset cs "yes" "ano"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  cs "Print" "Tisknout"
    ::msgcat::mcset  cs "Printer" "Tiskárna"
    ::msgcat::mcset  cs "Letter " "Dopis "
    ::msgcat::mcset  cs "Legal " "Legální "
    ::msgcat::mcset  cs "A4" "A4"
    ::msgcat::mcset  cs "Grayscale" "Stupně Šedi"
    ::msgcat::mcset  cs "RGB" "RGB"
    ::msgcat::mcset  cs "Options" "Možnosti"
    ::msgcat::mcset  cs "Copies" "Kopie"
    ::msgcat::mcset  cs "Paper" "Papír"
    ::msgcat::mcset  cs "Scale" "Škála"
    ::msgcat::mcset  cs "Orientation" "Orientace"
    ::msgcat::mcset  cs "Portrait" "Portrét"
    ::msgcat::mcset  cs "Landscape" "Krajina"
    ::msgcat::mcset  cs "Output" "Výstup"
}

Changes to library/msgs/da.msg.

1
2
3
4
5
6

7
8
9
10

11
12
13
14
15
16
17
1
2
3
4
5

6
7
8
9

10
11
12
13
14
15
16
17





-
+



-
+







namespace eval ::tk {
    ::msgcat::mcset da "&Abort" "&Afbryd"
    ::msgcat::mcset da "&About..." "&Om..."
    ::msgcat::mcset da "All Files" "Alle filer"
    ::msgcat::mcset da "Application Error" "Programfejl"
    ::msgcat::mcset da "&Blue" "&Blå"
    ::msgcat::mcset da "&Blue" "&Bl\u00E5"
    ::msgcat::mcset da "Cancel" "Annuller"
    ::msgcat::mcset da "&Cancel" "&Annuller"
    ::msgcat::mcset da "Cannot change to the directory \"%1\$s\".\nPermission denied." "Kan ikke skifte til katalog \"%1\$s\".\nIngen rettigheder."
    ::msgcat::mcset da "Choose Directory" "Vælg katalog"
    ::msgcat::mcset da "Choose Directory" "V\u00E6lg katalog"
    ::msgcat::mcset da "Cl&ear" "&Ryd"
    ::msgcat::mcset da "&Clear Console" "&Ryd konsolen"
    ::msgcat::mcset da "Color" "Farve"
    ::msgcat::mcset da "Console" "Konsol"
    ::msgcat::mcset da "&Copy" "&Kopier"
    ::msgcat::mcset da "Cu&t" "Kli&p"
    ::msgcat::mcset da "&Delete" "&Slet"
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
45
46
47
48




49
50

51
52
53
54
55
56
57


58
59
60
61
62

63
64
65
66
67
68

69
70
71
72

73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
27
28
29
30
31
32
33


34
35
36
37
38
39
40
41
42
43
44




45
46
47
48
49

50
51
52
53
54
55


56
57
58
59
60
61

62
63
64
65
66
67

68
69
70
71

72
73
74

75
76
77
78

























-
-
+
+









-
-
-
-
+
+
+
+

-
+





-
-
+
+




-
+





-
+



-
+


-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset da "File \"%1\$s\" does not exist." "Filen \"%1\$s\" findes ikke."
    ::msgcat::mcset da "File &name:" "Fil&navn:"
    ::msgcat::mcset da "File &names:" "Fil&navne:"
    ::msgcat::mcset da "Files of &type:" "Fil&typer:"
    ::msgcat::mcset da "Fi&les:" "Fi&ler:"
    ::msgcat::mcset da "&Filter"
    ::msgcat::mcset da "Fil&ter:"
    ::msgcat::mcset da "&Green" "&Grøn"
    ::msgcat::mcset da "&Help" "&Hjælp"
    ::msgcat::mcset da "&Green" "&Gr\u00F8n"
    ::msgcat::mcset da "&Help" "&Hj\u00E6lp"
    ::msgcat::mcset da "Hi" "Hej"
    ::msgcat::mcset da "&Hide Console" "Skjul &konsol"
    ::msgcat::mcset da "&Ignore" "&Ignorer"
    ::msgcat::mcset da "Invalid file name \"%1\$s\"." "Ugyldig fil navn \"%1\$s\"."
    ::msgcat::mcset da "Log Files" "Logfiler"
    ::msgcat::mcset da "&No" "&Nej"
    ::msgcat::mcset da "&OK" "&O.K."
    ::msgcat::mcset da "OK" "O.K."
    ::msgcat::mcset da "Ok"
    ::msgcat::mcset da "Open" "Åbn"
    ::msgcat::mcset da "&Open" "&Åbn"
    ::msgcat::mcset da "Open Multiple Files" "Åbn flere filer"
    ::msgcat::mcset da "P&aste" "&Indsæt"
    ::msgcat::mcset da "Open" "\u00C5bn"
    ::msgcat::mcset da "&Open" "&\u00C5bn"
    ::msgcat::mcset da "Open Multiple Files" "\u00C5bn flere filer"
    ::msgcat::mcset da "P&aste" "&Inds\u00E6t"
    ::msgcat::mcset da "&Quit" "&Afslut"
    ::msgcat::mcset da "&Red" "&Rød"
    ::msgcat::mcset da "&Red" "&R\u00F8d"
    ::msgcat::mcset da "Replace existing file?" "Erstat eksisterende fil?"
    ::msgcat::mcset da "&Retry" "&Gentag"
    ::msgcat::mcset da "&Save" "&Gem"
    ::msgcat::mcset da "Save As" "Gem som"
    ::msgcat::mcset da "Save To Log" "Gem i log"
    ::msgcat::mcset da "Select Log File" "Vælg logfil"
    ::msgcat::mcset da "Select a file to source" "Vælg kørbar fil"
    ::msgcat::mcset da "Select Log File" "V\u00E6lg logfil"
    ::msgcat::mcset da "Select a file to source" "V\u00E6lg k\u00F8rbar fil"
    ::msgcat::mcset da "&Selection:" "&Udvalg:"
    ::msgcat::mcset da "Show &Hidden Directories" "Vis &skjulte kataloger"
    ::msgcat::mcset da "Show &Hidden Files and Directories" "Vis &skjulte filer og kataloger"
    ::msgcat::mcset da "Skip Messages" "Overspring beskeder"
    ::msgcat::mcset da "&Source..." "&Kør..."
    ::msgcat::mcset da "&Source..." "&K\u00F8r..."
    ::msgcat::mcset da "Tcl Scripts" "Tcl-Skripter"
    ::msgcat::mcset da "Tcl for Windows" "Tcl for Windows"
    ::msgcat::mcset da "Text Files" "Tekstfiler"
    ::msgcat::mcset da "&Yes" "&Ja"
    ::msgcat::mcset da "abort" "afbryd"
    ::msgcat::mcset da "blue" "blå"
    ::msgcat::mcset da "blue" "bl\u00E5"
    ::msgcat::mcset da "cancel" "afbryd"
    ::msgcat::mcset da "extension"
    ::msgcat::mcset da "extensions"
    ::msgcat::mcset da "green" "grøn"
    ::msgcat::mcset da "green" "gr\u00F8n"
    ::msgcat::mcset da "ignore" "ignorer"
    ::msgcat::mcset da "ok"
    ::msgcat::mcset da "red" "rød"
    ::msgcat::mcset da "red" "r\u00F8d"
    ::msgcat::mcset da "retry" "gentag"
    ::msgcat::mcset da "yes" "ja"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  da "Print" "Trykke"
    ::msgcat::mcset  da "Printer" "Printer"
    ::msgcat::mcset  da "Letter " "Brev"
    ::msgcat::mcset  da "Legal " "Juridisk"
    ::msgcat::mcset  da "A4" "A4"
    ::msgcat::mcset  da "Grayscale" "Gråtoneskala"
    ::msgcat::mcset  da "RGB" "Rgb"
    ::msgcat::mcset  da "Options" "Indstillinger"
    ::msgcat::mcset  da "Copies" "Kopier"
    ::msgcat::mcset  da "Paper" "Papir"
    ::msgcat::mcset  da "Scale" "Skalere"
    ::msgcat::mcset  da "Orientation" "Orientering"
    ::msgcat::mcset  da "Portrait" "Portræt"
    ::msgcat::mcset  da "Landscape" "Landskab"
    ::msgcat::mcset  da "Output" "Udskriv Publikation"
}

Changes to library/msgs/de.msg.

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+







    ::msgcat::mcset de "Log Files" "Protokolldatei"
    ::msgcat::mcset de "&No" "&Nein"
    ::msgcat::mcset de "&OK"
    ::msgcat::mcset de "OK"
    ::msgcat::mcset de "Ok"
    ::msgcat::mcset de "Open" "Öffnen"
    ::msgcat::mcset de "&Open" "Ö&ffnen"
    ::msgcat::mcset de "Open Multiple Files" "Mehrere Dateien Öffnen"
    ::msgcat::mcset de "Open Multiple Files" "Mehrere Dateien \u00F6ffnen"
    ::msgcat::mcset de "P&aste" "E&infügen"
    ::msgcat::mcset de "&Quit" "&Beenden"
    ::msgcat::mcset de "&Red" "&Rot"
    ::msgcat::mcset de "Regular" "Standard"
    ::msgcat::mcset de "Replace existing file?" "Existierende Datei ersetzen?"
    ::msgcat::mcset de "&Retry" "&Wiederholen"
    ::msgcat::mcset de "Sample" "Beispiel"
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
85
86
87
88
89
90
91

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset de "green" "grün"
    ::msgcat::mcset de "ignore" "ignorieren"
    ::msgcat::mcset de "ok"
    ::msgcat::mcset de "red" "rot"
    ::msgcat::mcset de "retry" "wiederholen"
    ::msgcat::mcset de "yes" "ja"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  de "Print" "Drucken"
    ::msgcat::mcset  de "Printer" "Drucker"
    ::msgcat::mcset  de "Letter " "Letter"
    ::msgcat::mcset  de "Legal " "Legal"
    ::msgcat::mcset  de "A4" "A4"
    ::msgcat::mcset  de "Grayscale" "Graustufen"
    ::msgcat::mcset  de "RGB" "RGB"
    ::msgcat::mcset  de "Options" "Optionen"
    ::msgcat::mcset  de "Copies" "Kopien"
    ::msgcat::mcset  de "Paper" "Papier"
    ::msgcat::mcset  de "Scale" "Skalierung"
    ::msgcat::mcset  de "Orientation" "Ausrichtung"
    ::msgcat::mcset  de "Portrait" "Hochformat"
    ::msgcat::mcset  de "Landscape" "Querformat"
    ::msgcat::mcset  de "Output" "Ausgabe"
}

Changes to library/msgs/el.msg.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
80
81
82
83
84
85
86

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset el "green"              "πράσινο"
    ::msgcat::mcset el "ignore"             "αγνόηση"
    ::msgcat::mcset el "ok"                 "εντάξει"
    ::msgcat::mcset el "red"                "κόκκινο"
    ::msgcat::mcset el "retry"              "προσπάθησε ξανά"
    ::msgcat::mcset el "yes"                "ναι"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  el "Print" "Τυπώνω"
    ::msgcat::mcset  el "Printer" "Εκτυπωτής"
    ::msgcat::mcset  el "Letter " "Γράμμα"
    ::msgcat::mcset  el "Legal " "Νομικός"
    ::msgcat::mcset  el "A4" "Α4"
    ::msgcat::mcset  el "Grayscale" "Κλίμακα Του Γκρι"
    ::msgcat::mcset  el "RGB" "Rgb"
    ::msgcat::mcset  el "Options" "Επιλογές"
    ::msgcat::mcset  el "Copies" "Αντίγραφα"
    ::msgcat::mcset  el "Paper" "Χαρτί"
    ::msgcat::mcset  el "Scale" "Κλίμακα"
    ::msgcat::mcset  el "Orientation" "Προσανατολισμός"
    ::msgcat::mcset  el "Portrait" "Προσωπογραφία"
    ::msgcat::mcset  el "Landscape" "Τοπίο"
    ::msgcat::mcset  el "Output" "Έξοδος"
}

Changes to library/msgs/en.msg.

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
85
86
87
88
89
90
91


























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset en "green"
    ::msgcat::mcset en "ignore"
    ::msgcat::mcset en "ok"
    ::msgcat::mcset en "red"
    ::msgcat::mcset en "retry"
    ::msgcat::mcset en "yes"
}

#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  en "Print"
    ::msgcat::mcset  en "Printer"
    ::msgcat::mcset  en "Letter "
    ::msgcat::mcset  en "Legal "
    ::msgcat::mcset  en "A4"
    ::msgcat::mcset  en "Grayscale"
    ::msgcat::mcset  en "RGB"
    ::msgcat::mcset  en "Options"
    ::msgcat::mcset  en "Copies"
    ::msgcat::mcset  en "Paper"
    ::msgcat::mcset  en "Scale"
    ::msgcat::mcset  en "Orientation"
    ::msgcat::mcset  en "Portrait"
    ::msgcat::mcset  en "Landscape"
    ::msgcat::mcset  en "Output"
}

Changes to library/msgs/eo.msg.

1
2

3
4
5


6
7
8
9
10
11
12
13





14
15
16
17


18
19
20
21
22
23
24
25
26
27



28
29
30

31
32
33
34
35
36
37
38
39
40

41
42
43
44



45
46
47
48
49
50
51
52
53
54
55









56
57
58
59

60
61
62
63


64
65

66
67
68
69


70
71

72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
1

2
3


4
5
6
7
8





9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24



25
26
27
28
29

30
31
32
33
34
35
36
37
38
39

40
41



42
43
44
45
46









47
48
49
50
51
52
53
54
55
56
57
58

59
60
61


62
63
64

65
66
67


68
69
70

71
72

73
74
75



















-
+

-
-
+
+



-
-
-
-
-
+
+
+
+
+


-
-
+
+







-
-
-
+
+
+


-
+









-
+

-
-
-
+
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+



-
+


-
-
+
+

-
+


-
-
+
+

-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
namespace eval ::tk {
    ::msgcat::mcset eo "&Abort" "&Ĉesigu"
    ::msgcat::mcset eo "&Abort" "&Ĉesigo"
    ::msgcat::mcset eo "&About..." "Pri..."
    ::msgcat::mcset eo "All Files" "Ĉiuj dosieroj"
    ::msgcat::mcset eo "Application Error" "Aplikoeraro"
    ::msgcat::mcset eo "All Files" "Ĉioj dosieroj"
    ::msgcat::mcset eo "Application Error" "Aplikoerraro"
    ::msgcat::mcset eo "&Blue" "&Blua"
    ::msgcat::mcset eo "Cancel" "Rezignu"
    ::msgcat::mcset eo "&Cancel" "&Rezignu"
    ::msgcat::mcset eo "Cannot change to the directory \"%1\$s\".\nPermission denied." "Neeble ŝanĝi al dosierujo \"%1\$s\".\nVi ne rajtas tion."
    ::msgcat::mcset eo "Choose Directory" "Elektu Dosierujon"
    ::msgcat::mcset eo "Cl&ear" "&Vakigu"
    ::msgcat::mcset eo "&Clear Console" "&Vakigu konzolon"
    ::msgcat::mcset eo "Color" "Koloro"
    ::msgcat::mcset eo "Cannot change to the directory \"%1\$s\".\nPermission denied." "Neeble ĉangi al dosierulon \"%1\$s\".\nVi ne rajtas tion."
    ::msgcat::mcset eo "Choose Directory" "Elektu Dosierujo"
    ::msgcat::mcset eo "Cl&ear" "&Klaru"
    ::msgcat::mcset eo "&Clear Console" "&Klaru konzolon"
    ::msgcat::mcset eo "Color" "Farbo"
    ::msgcat::mcset eo "Console" "Konzolo"
    ::msgcat::mcset eo "&Copy" "&Kopiu"
    ::msgcat::mcset eo "Cu&t" "&Eltondu"
    ::msgcat::mcset eo "&Delete" "&Forigu"
    ::msgcat::mcset eo "Cu&t" "&Enpoŝigu"
    ::msgcat::mcset eo "&Delete" "&Forprenu"
    ::msgcat::mcset eo "Details >>" "Detaloj >>"
    ::msgcat::mcset eo "Directory \"%1\$s\" does not exist." "La dosierujo \"%1\$s\" ne ekzistas."
    ::msgcat::mcset eo "&Directory:" "&Dosierujo:"
    ::msgcat::mcset eo "&Edit" "&Redaktu"
    ::msgcat::mcset eo "Error: %1\$s" "Eraro: %1\$s"
    ::msgcat::mcset eo "E&xit" "&Eliru"
    ::msgcat::mcset eo "&File" "&Dosiero"
    ::msgcat::mcset eo "File \"%1\$s\" already exists.\nDo you want to overwrite it?" "La dosiero \"%1\$s\" jam ekzistas.\nĈu vi volas anstataŭigi la dosieron?"
    ::msgcat::mcset eo "File \"%1\$s\" already exists.\n\n" "La dosiero \"%1\$s\" jam ekzistas. \n\n"
    ::msgcat::mcset eo "File \"%1\$s\" does not exist." "La dosiero \"%1\$s\" ne ekzistas."
    ::msgcat::mcset eo "File \"%1\$s\" already exists.\nDo you want to overwrite it?" "La dosiero \"%1\$s\" jam ekzistas.\nĈu vi volas anstataûigi la dosieron?"
    ::msgcat::mcset eo "File \"%1\$s\" already exists.\n\n" "La dosiero \"%1\$s\" jam egzistas. \n\n"
    ::msgcat::mcset eo "File \"%1\$s\" does not exist." "La dosierp \"%1\$s\" ne estas."
    ::msgcat::mcset eo "File &name:" "Dosiero&nomo:"
    ::msgcat::mcset eo "File &names:" "Dosiero&nomoj:"
    ::msgcat::mcset eo "Files of &type:" "Dosieroj de &Tipo:"
    ::msgcat::mcset eo "Files of &type:" "Dosieroj de &Typo:"
    ::msgcat::mcset eo "Fi&les:" "Do&sieroj:"
    ::msgcat::mcset eo "&Filter" "&Filtrilo"
    ::msgcat::mcset eo "Fil&ter:" "&Filtrilo:"
    ::msgcat::mcset eo "&Green" "&Verda"
    ::msgcat::mcset eo "&Help" "&Helpu"
    ::msgcat::mcset eo "Hi" "Saluton"
    ::msgcat::mcset eo "&Hide Console" "&Kaŝu konzolon"
    ::msgcat::mcset eo "&Ignore" "&Ignoru"
    ::msgcat::mcset eo "Invalid file name \"%1\$s\"." "Malvalida dosieronomo \"%1\$s\"."
    ::msgcat::mcset eo "Log Files" "Protokolaj dosieroj"
    ::msgcat::mcset eo "Log Files" "Protokolo"
    ::msgcat::mcset eo "&No" "&Ne"
    ::msgcat::mcset eo "&OK" "&Bone"
    ::msgcat::mcset eo "OK" "Bone"
    ::msgcat::mcset eo "Ok" "Bone"
    ::msgcat::mcset eo "&OK"
    ::msgcat::mcset eo "OK"
    ::msgcat::mcset eo "Ok"
    ::msgcat::mcset eo "Open" "Malfermu"
    ::msgcat::mcset eo "&Open" "&Malfermu"
    ::msgcat::mcset eo "Open Multiple Files" "Malfermu plurajn dosierojn"
    ::msgcat::mcset eo "P&aste" "&Algluu"
    ::msgcat::mcset eo "&Quit" "&Forlasu"
    ::msgcat::mcset eo "&Red" "&Ra"
    ::msgcat::mcset eo "Replace existing file?" "Ĉu anstataŭigi ekzistantan dosieron?"
    ::msgcat::mcset eo "&Retry" "&Reprovu"
    ::msgcat::mcset eo "&Save" "&Konservu"
    ::msgcat::mcset eo "Save As" "Konservu kiel"
    ::msgcat::mcset eo "Save To Log" "Konservu en protokolon"
    ::msgcat::mcset eo "Open Multiple Files" "Melfermu multan dosierojn"
    ::msgcat::mcset eo "P&aste" "&Elpoŝigi"
    ::msgcat::mcset eo "&Quit" "&Finigu"
    ::msgcat::mcset eo "&Red" "&Rosa"
    ::msgcat::mcset eo "Replace existing file?" "Ĉu anstataûu ekzistantan dosieron?"
    ::msgcat::mcset eo "&Retry" "&Ripetu"
    ::msgcat::mcset eo "&Save" "&Savu"
    ::msgcat::mcset eo "Save As" "Savu kiel"
    ::msgcat::mcset eo "Save To Log" "Savu en protokolon"
    ::msgcat::mcset eo "Select Log File" "Elektu prokolodosieron"
    ::msgcat::mcset eo "Select a file to source" "Elektu dosieron por interpreti"
    ::msgcat::mcset eo "&Selection:" "&Elekto:"
    ::msgcat::mcset eo "Skip Messages" "transsaltu mesaĝojn"
    ::msgcat::mcset eo "Skip Messages" "transsaltu pluajn mesaĝojn"
    ::msgcat::mcset eo "&Source..." "&Fontoprogramo..."
    ::msgcat::mcset eo "Tcl Scripts" "Tcl-skriptoj"
    ::msgcat::mcset eo "Tcl for Windows" "Tcl por Vindozo"
    ::msgcat::mcset eo "Text Files" "Tekstodosieroj"
    ::msgcat::mcset eo "Tcl for Windows" "Tcl por vindoso"
    ::msgcat::mcset eo "Text Files" "Tekstodosierojn"
    ::msgcat::mcset eo "&Yes" "&Jes"
    ::msgcat::mcset eo "abort" "ĉesigu"
    ::msgcat::mcset eo "abort" "ĉesigo"
    ::msgcat::mcset eo "blue" "blua"
    ::msgcat::mcset eo "cancel" "rezignu"
    ::msgcat::mcset eo "extension" "kromprogramo"
    ::msgcat::mcset eo "extensions" "kromprogramoj"
    ::msgcat::mcset eo "extension" "ekspansio"
    ::msgcat::mcset eo "extensions" "ekspansioj"
    ::msgcat::mcset eo "green" "verda"
    ::msgcat::mcset eo "ignore" "ignoru"
    ::msgcat::mcset eo "ignore" "ignorieren"
    ::msgcat::mcset eo "red" "ruĝa"
    ::msgcat::mcset eo "retry" "reprovu"
    ::msgcat::mcset eo "retry" "ripetu"
    ::msgcat::mcset eo "yes" "jes"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  eo "Print" "Presi"
    ::msgcat::mcset  eo "Printer" "Presilo"
    ::msgcat::mcset  eo "Letter " "Letero"
    ::msgcat::mcset  eo "Legal " "Laŭleĝa"
    ::msgcat::mcset  eo "A4" "A4"
    ::msgcat::mcset  eo "Grayscale" "Grizskalo"
    ::msgcat::mcset  eo "RGB" "RGB"
    ::msgcat::mcset  eo "Options" "Opcioj"
    ::msgcat::mcset  eo "Copies" "Kopioj"
    ::msgcat::mcset  eo "Paper" "Papero"
    ::msgcat::mcset  eo "Scale" "Skalo"
    ::msgcat::mcset  eo "Orientation" "Orientiĝo"
    ::msgcat::mcset  eo "Portrait" "Portreto"
    ::msgcat::mcset  eo "Landscape" "Pejzaĝo"
    ::msgcat::mcset  eo "Output" "Eligo"
}

Changes to library/msgs/es.msg.

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
70
71
72
73
74
75
76

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset es "green" "verde"
    ::msgcat::mcset es "ignore" "ignorar"
    ::msgcat::mcset es "ok"
    ::msgcat::mcset es "red" "rojo"
    ::msgcat::mcset es "retry" "reintentar"
    ::msgcat::mcset es "yes" "sí"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
	::msgcat::mcset  es "Print" "Imprimir"
	::msgcat::mcset  es "Printer" "Impresora"
	::msgcat::mcset  es "Letter" "Carta"
	::msgcat::mcset  es "Legal" "Legal"
	::msgcat::mcset  es "A4" "A4"
	::msgcat::mcset  es "Grayscale" "Escala De Grises"
	::msgcat::mcset  es "RGB" "Color"
	::msgcat::mcset  es "Options" "Opciones"
	::msgcat::mcset  es "Copies" "Copias"
	::msgcat::mcset  es "Paper" "Papel"
	::msgcat::mcset  es "Scale" "Escala"
	::msgcat::mcset  es "Orientation" "Orientación"
	::msgcat::mcset  es "Portrait" "Retrato"
	::msgcat::mcset  es "Landscape" "Paisaje"
	::msgcat::mcset  es "Output" "Salida"
}

Deleted library/msgs/fi.msg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114


















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
namespace eval ::tk {
    ::msgcat::mcset fi "AaBbYyZz01" "AaBbÄäÖö01"
    ::msgcat::mcset fi "&Abort" "&Keskeytä"
    ::msgcat::mcset fi "&About..." "&Tietoja..."
    ::msgcat::mcset fi "All Files" "Kaikki tiedostot"
    ::msgcat::mcset fi "&Apply" "Kä&ytä"
    ::msgcat::mcset fi "Application Error" "Ohjelmavirhe"
    ::msgcat::mcset fi "&Blue" "&Sininen"
    ::msgcat::mcset fi "Bold" "Lihavoitu"
    ::msgcat::mcset fi "Bold Italic" "Lihavoitu, kursivoitu"
    ::msgcat::mcset fi "Cancel" "Peruuta"
    ::msgcat::mcset fi "&Cancel" "&Peruuta"
    ::msgcat::mcset fi "Cannot change to the directory \"%1\$s\".\nPermission denied." "Ei voitu vaihtaa hakemistoon \"%1\$s\".\nLupa evätty."
    ::msgcat::mcset fi "Choose Directory" "Valitse hakemisto"
    ::msgcat::mcset fi "Cl&ear" "&Tyhjennä"
    ::msgcat::mcset fi "&Clear Console" "&Tyhjennä konsoli"
    ::msgcat::mcset fi "Color" "Väri"
    ::msgcat::mcset fi "Console" "Konsoli"
    ::msgcat::mcset fi "&Copy" "K&opioi"
    ::msgcat::mcset fi "Cu&t" "&Leikkaa"
    ::msgcat::mcset fi "&Decrease Font Size" "&Pienennä kirjasinkokoa"
    ::msgcat::mcset fi "&Delete" "&Poista"
    ::msgcat::mcset fi "Details >>" "Lisätiedot >>"
    ::msgcat::mcset fi "Directory \"%1\$s\" does not exist." "Hakemistoa \"%1\$s\" ei ole olemassa."
    ::msgcat::mcset fi "&Directory:" "&Hakemisto:"
    ::msgcat::mcset fi "&Edit" "&Muokkaa"
    ::msgcat::mcset fi "Effects" "Tehosteet"
    ::msgcat::mcset fi "Error: %1\$s" "Virhe: %1\$s"
    ::msgcat::mcset fi "E&xit" "&Lopeta"
    ::msgcat::mcset fi "&File" "&Tiedosto"
    ::msgcat::mcset fi "File \"%1\$s\" already exists.\nDo you want to overwrite it?" "Tiedosto \"%1\$s\" on jo olemassa.\nHaluatko korvata sen?"
    ::msgcat::mcset fi "File \"%1\$s\" already exists.\n\n" "Tiedosto \"%1\$s\" on jo olemassa.\n\n"
    ::msgcat::mcset fi "File \"%1\$s\" does not exist." "Tiedostoa \"%1\$s\" ei ole olemassa."
    ::msgcat::mcset fi "File &name:" "Tiedosto&nimi:"
    ::msgcat::mcset fi "File &names:" "Tiedosto&nimet:"
    ::msgcat::mcset fi "Files of &type:" "T&yyppi:"
    ::msgcat::mcset fi "Fi&les:" "Ti&edostot:"
    ::msgcat::mcset fi "&Filter" "&Suodata"
    ::msgcat::mcset fi "Fil&ter:" "Suo&data:"
    ::msgcat::mcset fi "Fit To Screen Width" "Sovita ruudun kokoon"
    ::msgcat::mcset fi "Font" "Kirjasin"
    ::msgcat::mcset fi "&Font..." "Kir&jasin..."
    ::msgcat::mcset fi "&Font:" "&Kirjasin:"
    ::msgcat::mcset fi "Font st&yle:" "Kirjasint&yyli:"
    ::msgcat::mcset fi "&Green" "&Vihreä"
    ::msgcat::mcset fi "Help" "Ohje"
    ::msgcat::mcset fi "&Help" "&Ohje"
    ::msgcat::mcset fi "Hi" "Hei"
    ::msgcat::mcset fi "&Hide Console" "P&iilota konsoli"
    ::msgcat::mcset fi "Hide Fonts" "Piilota kirjasimet"
    ::msgcat::mcset fi "&Ignore" "&Ohita"
    ::msgcat::mcset fi "&Increase Font Size" "&Suurenna kirjasinkokoa"
    ::msgcat::mcset fi "Invalid file name \"%1\$s\"." "Virheellinen tiedostonimi \"%1\$s\"."
    ::msgcat::mcset fi "Italic" "Kursivoitu"
    ::msgcat::mcset fi "Log Files" "Lokitiedostot"
    ::msgcat::mcset fi "&No" "&Ei"
    ::msgcat::mcset fi "&OK"
    ::msgcat::mcset fi "OK"
    ::msgcat::mcset fi "Ok" "OK"
    ::msgcat::mcset fi "Open" "Avaa"
    ::msgcat::mcset fi "&Open" "&Avaa"
    ::msgcat::mcset fi "Open Multiple Files" "Avaa monta tiedostoa"
    ::msgcat::mcset fi "P&aste" "L&iitä"
    ::msgcat::mcset fi "&Quit" "&Lopeta"
    ::msgcat::mcset fi "&Red" "&Punainen"
    ::msgcat::mcset fi "Regular" "Tavallinen"
    ::msgcat::mcset fi "Replace existing file?" "Korvataanko olemassaoleva tiedosto?"
    ::msgcat::mcset fi "&Retry" "&Yritä uudelleen"
    ::msgcat::mcset fi "Sample" "Malli"
    ::msgcat::mcset fi "&Save" "&Tallenna"
    ::msgcat::mcset fi "Save As" "Tallenna nimellä"
    ::msgcat::mcset fi "Save To Log" "Tallenna lokiin"
    ::msgcat::mcset fi "Select Log File" "Valitse lokitiedosto"
    ::msgcat::mcset fi "Select a file to source" "Valitse lähdetiedosto"
    ::msgcat::mcset fi "&Selection:" "&Valinta:"
    ::msgcat::mcset fi "Show Fonts" "Näytä kirjasimet"
    ::msgcat::mcset fi "Skip Messages" "Jätä viestit huomiotta"
    ::msgcat::mcset fi "&Size:" "K&oko:"
    ::msgcat::mcset fi "&Source..." "L&ähde..."
    ::msgcat::mcset fi "Stri&keout" "&Yliviivaa"
    ::msgcat::mcset fi "Tcl Scripts" "Tcl-skriptit"
    ::msgcat::mcset fi "Tcl for Windows" "Tcl Windowsille"
    ::msgcat::mcset fi "Text Files" "Tekstitiedostot"
    ::msgcat::mcset fi "&Underline" "&Alleviivaa"
    ::msgcat::mcset fi "Window" "Ikkuna"
    ::msgcat::mcset fi "&Yes" "&Kyllä"
    ::msgcat::mcset fi "abort" "keskeytä"
    ::msgcat::mcset fi "blue" "sininen"
    ::msgcat::mcset fi "cancel" "peruuta"
    ::msgcat::mcset fi "extension" "lisäosa"
    ::msgcat::mcset fi "extensions" "lisäosat"
    ::msgcat::mcset fi "green" "vihreä"
    ::msgcat::mcset fi "ignore" "ohita"
    ::msgcat::mcset fi "ok"
    ::msgcat::mcset fi "red" "punainen"
    ::msgcat::mcset fi "retry" "yritä uudelleen"
    ::msgcat::mcset fi "yes" "kyllä"

    ::msgcat::mcset fi "Print" "Tulosta"
    ::msgcat::mcset fi "Printer" "Tulostin"
    ::msgcat::mcset fi "Letter " "Letter"
    ::msgcat::mcset fi "Legal " "Legal"
    ::msgcat::mcset fi "A4" "A4"
    ::msgcat::mcset fi "Grayscale" "Harmaasävy"
    ::msgcat::mcset fi "RGB" "RGB"
    ::msgcat::mcset fi "Options" "Asetukset"
    ::msgcat::mcset fi "Copies" "Tulosteita"
    ::msgcat::mcset fi "Paper" "Paperikoko"
    ::msgcat::mcset fi "Scale" "Skaalaus"
    ::msgcat::mcset fi "Orientation" "Suunta"
    ::msgcat::mcset fi "Portrait" "Pysty"
    ::msgcat::mcset fi "Landscape" "Vaaka"
    ::msgcat::mcset fi "Output" "Tulos"
}

Changes to library/msgs/fr.msg.

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
66
67
68
69
70
71
72

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset fr "green" "vert"
    ::msgcat::mcset fr "ignore" "ignorer"
    ::msgcat::mcset fr "ok"
    ::msgcat::mcset fr "red" "rouge"
    ::msgcat::mcset fr "retry" "réessayer"
    ::msgcat::mcset fr "yes" "oui"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  fr "Print" "Imprimer"
    ::msgcat::mcset  fr "Printer" "Imprimante"
    ::msgcat::mcset  fr "Letter " "Lettre"
    ::msgcat::mcset  fr "Legal " "Légal"
    ::msgcat::mcset  fr "A4" "A4"
    ::msgcat::mcset  fr "Grayscale" "Niveaux de Gris"
    ::msgcat::mcset  fr "RGB" "RVB"
    ::msgcat::mcset  fr "Options" "Options"
    ::msgcat::mcset  fr "Copies" "Nombre d'exemplaires"
    ::msgcat::mcset  fr "Paper" "Papier"
    ::msgcat::mcset  fr "Scale" "Échelle"
    ::msgcat::mcset  fr "Orientation" "Orientation"
    ::msgcat::mcset  fr "Portrait" "Portrait"
    ::msgcat::mcset  fr "Landscape" "Paysage"
    ::msgcat::mcset  fr "Output" "Sortie"
}

Changes to library/msgs/hu.msg.

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
72
73
74
75
76
77
78

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset hu "green" "zöld"
    ::msgcat::mcset hu "ignore" "ignorer"
    ::msgcat::mcset hu "ok"
    ::msgcat::mcset hu "red" "vörös"
    ::msgcat::mcset hu "retry" "újra"
    ::msgcat::mcset hu "yes" "igen"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  hu "Print" "Nyomtat"
    ::msgcat::mcset  hu "Printer" "Nyomtató"
    ::msgcat::mcset  hu "Letter " "Levél"
    ::msgcat::mcset  hu "Legal " "Törvényes"
    ::msgcat::mcset  hu "A4" "A4"
    ::msgcat::mcset  hu "Grayscale" "Szürkeárnyalatos"
    ::msgcat::mcset  hu "RGB" "Rgb"
    ::msgcat::mcset  hu "Options" "Beállítások"
    ::msgcat::mcset  hu "Copies" "Másolatok"
    ::msgcat::mcset  hu "Paper" "Papír"
    ::msgcat::mcset  hu "Scale" "Hangsor"
    ::msgcat::mcset  hu "Orientation" "Tájékozódás"
    ::msgcat::mcset  hu "Portrait" "Portré"
    ::msgcat::mcset  hu "Landscape" "Táj"
    ::msgcat::mcset  hu "Output" "Hozam"
}

Changes to library/msgs/it.msg.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
67
68
69
70
71
72
73

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset it "green" "verde"
    ::msgcat::mcset it "ignore" "ignora"
    ::msgcat::mcset it "ok"
    ::msgcat::mcset it "red" "rosso"
    ::msgcat::mcset it "retry" "riprova"
    ::msgcat::mcset it "yes" "sì"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  it "Print" "Stampare"
    ::msgcat::mcset  it "Printer" "Stampante"
    ::msgcat::mcset  it "Letter " "Lettera"
    ::msgcat::mcset  it "Legal " "Legale"
    ::msgcat::mcset  it "A4" "A4"
    ::msgcat::mcset  it "Grayscale" "Scala Di Grigi"
    ::msgcat::mcset  it "RGB" "Rgb"
    ::msgcat::mcset  it "Options" "Opzioni"
    ::msgcat::mcset  it "Copies" "Copie"
    ::msgcat::mcset  it "Paper" "Carta"
    ::msgcat::mcset  it "Scale" "Scala"
    ::msgcat::mcset  it "Orientation" "Orientamento"
    ::msgcat::mcset  it "Portrait" "Ritratto"
    ::msgcat::mcset  it "Landscape" "Paesaggio"
    ::msgcat::mcset  it "Output" "Prodotto"
}

Changes to library/msgs/nl.msg.

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
85
86
87
88
89
90
91

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset nl "green" "groen"
    ::msgcat::mcset nl "ignore" "negeren"
    ::msgcat::mcset nl "ok"
    ::msgcat::mcset nl "red" "rood"
    ::msgcat::mcset nl "retry" "opnieuw"
    ::msgcat::mcset nl "yes" "ja"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  nl "Print" "Afdrukken"
    ::msgcat::mcset  nl "Printer" "Printer"
    ::msgcat::mcset  nl "Letter " "Brief"
    ::msgcat::mcset  nl "Legal " "Legaal"
    ::msgcat::mcset  nl "A4" "A4"
    ::msgcat::mcset  nl "Grayscale" "Grijswaarden"
    ::msgcat::mcset  nl "RGB" "Rgb"
    ::msgcat::mcset  nl "Options" "Opties"
    ::msgcat::mcset  nl "Copies" "Kopieën"
    ::msgcat::mcset  nl "Paper" "Papier"
    ::msgcat::mcset  nl "Scale" "Schub"
    ::msgcat::mcset  nl "Orientation" "Oriëntatie"
    ::msgcat::mcset  nl "Portrait" "Portret"
    ::msgcat::mcset  nl "Landscape" "Landschap"
    ::msgcat::mcset  nl "Output" "Uitvoer"
}

Changes to library/msgs/pl.msg.

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
85
86
87
88
89
90
91

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset pl "green" "zielony"
    ::msgcat::mcset pl "ignore" "ignoruj"
    ::msgcat::mcset pl "ok"
    ::msgcat::mcset pl "red" "czerwony"
    ::msgcat::mcset pl "retry" "ponów"
    ::msgcat::mcset pl "yes" "tak"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  pl "Print" "Drukować"
    ::msgcat::mcset  pl "Printer" "Drukarka"
    ::msgcat::mcset  pl "Letter " "Litera"
    ::msgcat::mcset  pl "Legal " "Legalny"
    ::msgcat::mcset  pl "A4" "A4"
    ::msgcat::mcset  pl "Grayscale" "Skala Szarości"
    ::msgcat::mcset  pl "RGB" "Rgb"
    ::msgcat::mcset  pl "Options" "Opcje"
    ::msgcat::mcset  pl "Copies" "Kopie"
    ::msgcat::mcset  pl "Paper" "Papier"
    ::msgcat::mcset  pl "Scale" "Skala"
    ::msgcat::mcset  pl "Orientation" "Orientacja"
    ::msgcat::mcset  pl "Portrait" "Portret"
    ::msgcat::mcset  pl "Landscape" "Krajobraz"
    ::msgcat::mcset  pl "Output" "Produkt Wyjściowy"
}

Changes to library/msgs/pt.msg.

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
68
69
70
71
72
73
74

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset pt "green" "verde"
    ::msgcat::mcset pt "ignore" "ignorar"
    ::msgcat::mcset pt "ok"
    ::msgcat::mcset pt "red" "vermelho"
    ::msgcat::mcset pt "retry" "tentar novamente"
    ::msgcat::mcset pt "yes" "sim"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  pt "Print" "Imprimir"
    ::msgcat::mcset  pt "Printer" "Impressora"
    ::msgcat::mcset  pt "Letter " "Letra"
    ::msgcat::mcset  pt "Legal " "Legal"
    ::msgcat::mcset  pt "A4" "A4"
    ::msgcat::mcset  pt "Grayscale" "Escala De Cinza"
    ::msgcat::mcset  pt "RGB" "Rgb"
    ::msgcat::mcset  pt "Options" "Opções"
    ::msgcat::mcset  pt "Copies" "Exemplares"
    ::msgcat::mcset  pt "Paper" "Papel"
    ::msgcat::mcset  pt "Scale" "Escala"
    ::msgcat::mcset  pt "Orientation" "Orientação"
    ::msgcat::mcset  pt "Portrait" "Retrato"
    ::msgcat::mcset  pt "Landscape" "Paisagem"
    ::msgcat::mcset  pt "Output" "Saída"
}

Changes to library/msgs/ru.msg.

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
1
2
3
4
5



6

7
8
9
10
11
12

13
14
15
16
17
18
19
20


21
22

23
24
25
26
27
28
29
30
31
32



33

34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49

50

51
52
53
54
55
56



57
58

59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75























-
-
-

-
+





-








-
-


-










-
-
-

-




-












-

-






-
-
-


-



-














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
namespace eval ::tk {
    ::msgcat::mcset ru "&Abort" "&Отменить"
    ::msgcat::mcset ru "&About..." "Про..."
    ::msgcat::mcset ru "All Files" "Все файлы"
    ::msgcat::mcset ru "Application Error" "Ошибка в программе"
    ::msgcat::mcset ru "&Apply" "&Применить"
    ::msgcat::mcset ru "Bold" "Bold"
    ::msgcat::mcset ru "Bold Italic" "Bold Italic"
    ::msgcat::mcset ru "&Blue" " &Голубой"
    ::msgcat::mcset ru "Cancel" "Отмена"
    ::msgcat::mcset ru "Cancel" "От&мена"
    ::msgcat::mcset ru "&Cancel" "От&мена"
    ::msgcat::mcset ru "Cannot change to the directory \"%1\$s\".\nPermission denied." \
			"Не могу перейти в каталог \"%1\$s\".\nНедостаточно прав доступа"
    ::msgcat::mcset ru "Choose Directory" "Выберите каталог"
    ::msgcat::mcset ru "Cl&ear" "Очистить"
    ::msgcat::mcset ru "&Clear Console" "&Clear Console"
    ::msgcat::mcset ru "Color" "Цвет"
    ::msgcat::mcset ru "Console" "Консоль"
    ::msgcat::mcset ru "&Copy" "Копировать"
    ::msgcat::mcset ru "Cu&t" "Вырезать"
    ::msgcat::mcset ru "&Delete" "Удалить"
    ::msgcat::mcset ru "Details >>" "Подробнее >>"
    ::msgcat::mcset ru "Directory \"%1\$s\" does not exist." "Каталога \"%1\$s\" не существует."
    ::msgcat::mcset ru "&Directory:" "&Каталог:"
    ::msgcat::mcset ru "&Edit" "&Edit"
    ::msgcat::mcset ru "Effects" "Эффекты"
    ::msgcat::mcset ru "Error: %1\$s" "Ошибка: %1\$s"
    ::msgcat::mcset ru "E&xit" "Выход"
    ::msgcat::mcset ru "&File" "&File"
    ::msgcat::mcset ru "File \"%1\$s\" already exists.\nDo you want to overwrite it?" \
			    "Файл \"%1\$s\" уже существует.\nЗаменить его?"
    ::msgcat::mcset ru "File \"%1\$s\" already exists.\n\n" "Файл \"%1\$s\" уже существует.\n\n"
    ::msgcat::mcset ru "File \"%1\$s\" does not exist." "Файл \"%1\$s\" не найден."
    ::msgcat::mcset ru "File &name:" "&Имя файла:"
    ::msgcat::mcset ru "File &names:" "&Имена файлов:"
    ::msgcat::mcset ru "Files of &type:" "&Тип файлов:"
    ::msgcat::mcset ru "Fi&les:" "Фай&лы:"
    ::msgcat::mcset ru "&Filter" "&Фильтр"
    ::msgcat::mcset ru "Fil&ter:" "Филь&тр:"
    ::msgcat::mcset ru "Font" "Шрифт"
    ::msgcat::mcset ru "&Font:" "&Шрифт"
    ::msgcat::mcset ru "Font st&yle:" "&Стиль шрифта:"
    ::msgcat::mcset ru "&Green" " &Зеленый"
    ::msgcat::mcset ru "&Help" "&Help"
    ::msgcat::mcset ru "Hi" "Привет"
    ::msgcat::mcset ru "&Hide Console" "Спрятать консоль"
    ::msgcat::mcset ru "&Ignore" "&Игнорировать"
    ::msgcat::mcset ru "Invalid file name \"%1\$s\"." "Неверное имя файла \"%1\$s\"."
    ::msgcat::mcset ru "Italic" "Italic"
    ::msgcat::mcset ru "Log Files" "Файлы журнала"
    ::msgcat::mcset ru "&No" "&Нет"
    ::msgcat::mcset ru "&OK" "&ОК"
    ::msgcat::mcset ru "OK" "ОК"
    ::msgcat::mcset ru "Ok" "Да"
    ::msgcat::mcset ru "Open" "Открыть"
    ::msgcat::mcset ru "&Open" "&Открыть"
    ::msgcat::mcset ru "Open Multiple Files" "Открыть несколько файлов"
    ::msgcat::mcset ru "P&aste" "Вставить"
    ::msgcat::mcset ru "&Quit" "Выход"
    ::msgcat::mcset ru "&Red" " &Красный"
    ::msgcat::mcset ru "Replace existing file?" "Заменить существующий файл?"
    ::msgcat::mcset ru "Regular" "Regular"
    ::msgcat::mcset ru "&Retry" "&Повторить"
    ::msgcat::mcset ru "Sample" "Пример"
    ::msgcat::mcset ru "&Save" "&Сохранить"
    ::msgcat::mcset ru "Save As" "Сохранить как"
    ::msgcat::mcset ru "Save To Log" "Сохранить в журнал"
    ::msgcat::mcset ru "Select Log File" "Выбрать журнал"
    ::msgcat::mcset ru "Select a file to source" "Выберите файл для интерпретации"
    ::msgcat::mcset ru "&Selection:"
    ::msgcat::mcset ru "&Size:" "&Размер:"
    ::msgcat::mcset ru "Show &Hidden Directories" "Show &Hidden Directories"
    ::msgcat::mcset ru "Show &Hidden Files and Directories" "Show &Hidden Files and Directories"
    ::msgcat::mcset ru "Skip Messages" "Пропустить сообщения"
    ::msgcat::mcset ru "&Source..." "Интерпретировать файл..."
    ::msgcat::mcset ru "Stri&keout" "П&еречёркнутый"
    ::msgcat::mcset ru "Tcl Scripts" "Программа на языке TCL"
    ::msgcat::mcset ru "Tcl for Windows" "TCL для Windows"
    ::msgcat::mcset ru "Text Files" "Текстовые файлы"
    ::msgcat::mcset ru "&Underline" "По&дчеркнутый"
    ::msgcat::mcset ru "&Yes" "&Да"
    ::msgcat::mcset ru "abort" "отмена"
    ::msgcat::mcset ru "blue" " голубой"
    ::msgcat::mcset ru "cancel" "отмена"
    ::msgcat::mcset ru "extension" "расширение"
    ::msgcat::mcset ru "extensions" "расширения"
    ::msgcat::mcset ru "green" " зеленый"
    ::msgcat::mcset ru "ignore" "пропустить"
    ::msgcat::mcset ru "ok" "ок"
    ::msgcat::mcset ru "red" " красный"
    ::msgcat::mcset ru "retry" "повторить"
    ::msgcat::mcset ru "yes" "да"
}

#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  ru "Print" "Печатать"
    ::msgcat::mcset  ru "Printer" "Принтер"
    ::msgcat::mcset  ru "Letter " "Письмо"
    ::msgcat::mcset  ru "Legal " "Законный"
    ::msgcat::mcset  ru "A4" "A4"
    ::msgcat::mcset  ru "Grayscale" "Серый Масштаб"
    ::msgcat::mcset  ru "RGB" "Ргб"
    ::msgcat::mcset  ru "Options" "Параметры"
    ::msgcat::mcset  ru "Copies" "Копии"
    ::msgcat::mcset  ru "Paper" "Бумага"
    ::msgcat::mcset  ru "Scale" "Шкала"
    ::msgcat::mcset  ru "Orientation" "Ориентация"
    ::msgcat::mcset  ru "Portrait" "Портрет"
    ::msgcat::mcset  ru "Landscape" "Ландшафт"
    ::msgcat::mcset  ru "Output" "Выпуск"
}

Changes to library/msgs/sv.msg.

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
70
71
72
73
74
75
76

























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    ::msgcat::mcset sv "green" "grön"
    ::msgcat::mcset sv "ignore" "ignorera"
    ::msgcat::mcset sv "ok"
    ::msgcat::mcset sv "red" "röd"
    ::msgcat::mcset sv "retry" "försök igen"
    ::msgcat::mcset sv "yes" "ja"
}
#localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  sv "Print" "Trycka"
    ::msgcat::mcset  sv "Printer" "Skrivare"
    ::msgcat::mcset  sv "Letter " "Brev"
    ::msgcat::mcset  sv "Legal " "Laglig"
    ::msgcat::mcset  sv "A4" "A4 (På 199"
    ::msgcat::mcset  sv "Grayscale" "Gråskala"
    ::msgcat::mcset  sv "RGB" "Rgb"
    ::msgcat::mcset  sv "Options" "Alternativ"
    ::msgcat::mcset  sv "Copies" "Kopior"
    ::msgcat::mcset  sv "Paper" "Papper"
    ::msgcat::mcset  sv "Scale" "Skala"
    ::msgcat::mcset  sv "Orientation" "Orientering"
    ::msgcat::mcset  sv "Portrait" "Porträtt"
    ::msgcat::mcset  sv "Landscape" "Landskap"
    ::msgcat::mcset  sv "Output" "Utdata"
}

Deleted library/msgs/zh_cn.msg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110














































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
namespace eval ::tk {
    ::msgcat::mcset zh_cn "&Abort" "&中止"
    ::msgcat::mcset zh_cn "&About..." "&关于……"
    ::msgcat::mcset zh_cn "All Files" "所有文件"
    ::msgcat::mcset zh_cn "Application Error" "应用程序错误"
    ::msgcat::mcset zh_cn "&Apply" "&添加"
    ::msgcat::mcset zh_cn "Bold" "粗体"
    ::msgcat::mcset zh_cn "Bold Italic" "加粗斜体"
    ::msgcat::mcset zh_cn "&Blue" "&蓝色"
    ::msgcat::mcset zh_cn "Cancel" "取消"
    ::msgcat::mcset zh_cn "&Cancel" "&取消"
    ::msgcat::mcset zh_cn "Cannot change to the directory \"%1\$s\".\nPermission denied." "无法更改目录 \"%1\$s\"。\n访问被拒绝。"
    ::msgcat::mcset zh_cn "Choose Directory" "选择文件夹"
    ::msgcat::mcset zh_cn "Cl&ear" "清&除"
    ::msgcat::mcset zh_cn "&Clear Console" "&清除终端"
    ::msgcat::mcset zh_cn "Color" "颜色"
    ::msgcat::mcset zh_cn "Console" "终端"
    ::msgcat::mcset zh_cn "&Copy" "&复制"
    ::msgcat::mcset zh_cn "Cu&t" "剪&切"
    ::msgcat::mcset zh_cn "&Delete" "&删除"
    ::msgcat::mcset zh_cn "Details >>" "详细信息 >>"
    ::msgcat::mcset zh_cn "Directory \"%1\$s\" does not exist." "目录 \"%1\$s\" 不存在。"
    ::msgcat::mcset zh_cn "&Directory:" "&目录:"
    ::msgcat::mcset zh_cn "&Edit" "&编辑"
    ::msgcat::mcset zh_cn "Effects" "效果"
    ::msgcat::mcset zh_cn "Error: %1\$s" "错误: %1\$s"
    ::msgcat::mcset zh_cn "E&xit" "退&出"
    ::msgcat::mcset zh_cn "&File" "&文件"
    ::msgcat::mcset zh_cn "File \"%1\$s\" already exists.\nDo you want to overwrite it?" "文件 \"%1\$s\" 已经存在。\n您想要覆盖它吗?"
    ::msgcat::mcset zh_cn "File \"%1\$s\" already exists.\n\n" "文件 \"%1\$s\" 已经存在。\n\n"
    ::msgcat::mcset zh_cn "File \"%1\$s\" does not exist." "文件 \"%1\$s\" 不存在。"
    ::msgcat::mcset zh_cn "File &name:" "文件&名:"
    ::msgcat::mcset zh_cn "File &names:" "文件&名:"
    ::msgcat::mcset zh_cn "Files of &type:" "文件&类型:"
    ::msgcat::mcset zh_cn "Fi&les:" "文&件:"
    ::msgcat::mcset zh_cn "&Filter" "&过滤"
    ::msgcat::mcset zh_cn "Fil&ter:" "过&滤:"
    ::msgcat::mcset zh_cn "Font" "字体"
    ::msgcat::mcset zh_cn "&Font:" "&字体:"
    ::msgcat::mcset zh_cn "Font st&yle:" "字体&样式:"
    ::msgcat::mcset zh_cn "&Green" "&绿色"
    ::msgcat::mcset zh_cn "&Help" "&帮助"
    ::msgcat::mcset zh_cn "Hi" "你好"
    ::msgcat::mcset zh_cn "&Hide Console" "&隐藏终端"
    ::msgcat::mcset zh_cn "&Ignore" "&忽略"
    ::msgcat::mcset zh_cn "Invalid file name \"%1\$s\"." "无效的文件名 \"%1\$s\"。"
    ::msgcat::mcset zh_cn "Italic" "斜体"
    ::msgcat::mcset zh_cn "Log Files" "日志文件"
    ::msgcat::mcset zh_cn "&No" "&否"
    ::msgcat::mcset zh_cn "&OK" "&确定"
    ::msgcat::mcset zh_cn "OK" "确定"
    ::msgcat::mcset zh_cn "Ok" "确定"
    ::msgcat::mcset zh_cn "Open" "打开"
    ::msgcat::mcset zh_cn "&Open" "&打开"
    ::msgcat::mcset zh_cn "Open Multiple Files" "打开多个文件"
    ::msgcat::mcset zh_cn "P&aste" "粘&贴"
    ::msgcat::mcset zh_cn "&Quit" "&退出"
    ::msgcat::mcset zh_cn "&Red" "红色"
    ::msgcat::mcset zh_cn "Regular" "规则"
    ::msgcat::mcset zh_cn "Replace existing file?" "替换已有文件?"
    ::msgcat::mcset zh_cn "&Retry" "&重试"
    ::msgcat::mcset zh_cn "Sample" "样式"
    ::msgcat::mcset zh_cn "&Save" "&保存"
    ::msgcat::mcset zh_cn "Save As" "另存为"
    ::msgcat::mcset zh_cn "Save To Log" "保存到日志"
    ::msgcat::mcset zh_cn "Select Log File" "选择日志文件"
    ::msgcat::mcset zh_cn "Select a file to source" "选择一个源文件"
    ::msgcat::mcset zh_cn "&Selection:" "&选择:"
    ::msgcat::mcset zh_cn "&Size:" "&大小:"
    ::msgcat::mcset zh_cn "Show &Hidden Directories" "显示&隐藏目录"
    ::msgcat::mcset zh_cn "Show &Hidden Files and Directories" "显示&隐藏文件和目录"
    ::msgcat::mcset zh_cn "Skip Messages" "跳过信息"
    ::msgcat::mcset zh_cn "&Source..." "&来源……"
    ::msgcat::mcset zh_cn "Stri&keout" "删&除线"
    ::msgcat::mcset zh_cn "Tcl Scripts" "Tcl脚本"
    ::msgcat::mcset zh_cn "Tcl for Windows" "适用于Windows的Tcl"
    ::msgcat::mcset zh_cn "Text Files" "文本文档"
    ::msgcat::mcset zh_cn "&Underline" "&下划线"
    ::msgcat::mcset zh_cn "&Yes" "&确定"
    ::msgcat::mcset zh_cn "abort" "中止"
    ::msgcat::mcset zh_cn "blue" "蓝色"
    ::msgcat::mcset zh_cn "cancel" "取消"
    ::msgcat::mcset zh_cn "extension" "拓展"
    ::msgcat::mcset zh_cn "extensions" "拓展"
    ::msgcat::mcset zh_cn "green" "绿色"
    ::msgcat::mcset zh_cn "ignore" "忽略"
    ::msgcat::mcset zh_cn "ok" "确定"
    ::msgcat::mcset zh_cn "red" "红色"
    ::msgcat::mcset zh_cn "retry" "重试"
    ::msgcat::mcset zh_cn "yes" "确认"
}

#Kevin Walzer通过微软翻译对打印内容进行本地化    localization of print terms by Kevin Walzer via Microsoft Translator
namespace eval ::tk {
    ::msgcat::mcset  zh_cn "Print" "输出"
    ::msgcat::mcset  zh_cn "Printer" "输出器"
    ::msgcat::mcset  zh_cn "Letter " "信 "
    ::msgcat::mcset  zh_cn "Legal " "合法的 "
    ::msgcat::mcset  zh_cn "A4" "A4"
    ::msgcat::mcset  zh_cn "Grayscale" "灰度"
    ::msgcat::mcset  zh_cn "RGB" "RGB"
    ::msgcat::mcset  zh_cn "Options" "设置"
    ::msgcat::mcset  zh_cn "Copies" "复制"
    ::msgcat::mcset  zh_cn "Paper" "纸"
    ::msgcat::mcset  zh_cn "Scale" "规模"
    ::msgcat::mcset  zh_cn "Orientation" "方向"
    ::msgcat::mcset  zh_cn "Portrait" "竖向"
    ::msgcat::mcset  zh_cn "Landscape" "横向"
    ::msgcat::mcset  zh_cn "Output" "输出"
}

Added library/obsolete.tcl.



















































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# obsolete.tcl --
#
# This file contains obsolete procedures that people really shouldn't
# be using anymore, but which are kept around for backward compatibility.
#
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

# The procedures below are here strictly for backward compatibility with
# Tk version 3.6 and earlier.  The procedures are no longer needed, so
# they are no-ops.  You should not use these procedures anymore, since
# they may be removed in some future release.

proc tk_menuBar args {}
proc tk_bindForTraversal args {}

# ::tk::classic::restore --
#
# Restore the pre-8.5 (Tk classic) look as the widget defaults for classic
# Tk widgets.
#
# The value following an 'option add' call is the new 8.5 value.
#
namespace eval ::tk::classic {
    # This may need to be adjusted for some window managers that are
    # more aggressive with their own Xdefaults (like KDE and CDE)
    variable prio "widgetDefault"
}

proc ::tk::classic::restore {args} {
    # Restore classic (8.4) look to classic Tk widgets
    variable prio

    if {[llength $args]} {
	foreach what $args {
	    ::tk::classic::restore_$what
	}
    } else {
	foreach cmd [info procs restore_*] {
	    $cmd
	}
    }
}

proc ::tk::classic::restore_font {args} {
    # Many widgets were adjusted from hard-coded defaults to using the
    # TIP#145 fonts defined in fonts.tcl (eg TkDefaultFont, TkFixedFont, ...)
    # For restoring compatibility, we only correct size and weighting changes,
    # as the fonts themselves remained mostly the same.
    if {[tk windowingsystem] eq "x11"} {
	font configure TkDefaultFont -weight bold ; # normal
	font configure TkFixedFont -size -12 ; # -10
    }
    # Add these with prio 21 to override value in dialog/msgbox.tcl
    if {[tk windowingsystem] eq "aqua"} {
	option add *Dialog.msg.font system 21; # TkCaptionFont
	option add *Dialog.dtl.font system 21; # TkCaptionFont
	option add *ErrorDialog*Label.font system 21; # TkCaptionFont
    } else {
	option add *Dialog.msg.font {Times 12} 21; # TkCaptionFont
	option add *Dialog.dtl.font {Times 10} 21; # TkCaptionFont
	option add *ErrorDialog*Label.font {Times -18} 21; # TkCaptionFont
    }
}

proc ::tk::classic::restore_button {args} {
    variable prio
    if {[tk windowingsystem] eq "x11"} {
	foreach cls {Button Radiobutton Checkbutton} {
	    option add *$cls.borderWidth 2 $prio; # 1
	}
    }
}

proc ::tk::classic::restore_entry {args} {
    variable prio
    # Entry and Spinbox share core defaults
    foreach cls {Entry Spinbox} {
	if {[tk windowingsystem] ne "aqua"} {
	    option add *$cls.borderWidth	2 $prio; # 1
	}
	if {[tk windowingsystem] eq "x11"} {
	    option add *$cls.background		"#d9d9d9" $prio; # "white"
	    option add *$cls.selectBorderWidth	1 $prio; # 0
	}
    }
}

proc ::tk::classic::restore_listbox {args} {
    variable prio
    if {[tk windowingsystem] ne "win32"} {
	option add *Listbox.background		"#d9d9d9" $prio; # "white"
	option add *Listbox.activeStyle		"underline" $prio; # "dotbox"
    }
    if {[tk windowingsystem] ne "aqua"} {
	option add *Listbox.borderWidth		2 $prio; # 1
    }
    if {[tk windowingsystem] eq "x11"} {
	option add *Listbox.selectBorderWidth	1 $prio; # 0
    }
    # Remove focus into Listbox added for 8.5
    bind Listbox <1> {
	if {[winfo exists %W]} {
	    tk::ListboxBeginSelect %W [%W index @%x,%y]
	}
    }
}

proc ::tk::classic::restore_menu {args} {
    variable prio
    if {[tk windowingsystem] eq "x11"} {
	option add *Menu.activeBorderWidth	2 $prio; # 1
	option add *Menu.borderWidth		2 $prio; # 1
        option add *Menu.clickToFocus		true $prio
        option add *Menu.useMotifHelp		true $prio
    }
    if {[tk windowingsystem] ne "aqua"} {
	option add *Menu.font		"TkDefaultFont" $prio; # "TkMenuFont"
    }
}

proc ::tk::classic::restore_menubutton {args} {
    variable prio
    option add *Menubutton.borderWidth	2 $prio; # 1
}

proc ::tk::classic::restore_message {args} {
    variable prio
    option add *Message.borderWidth	2 $prio; # 1
}

proc ::tk::classic::restore_panedwindow {args} {
    variable prio
    option add *Panedwindow.borderWidth	2 $prio; # 1
    option add *Panedwindow.sashWidth	2 $prio; # 3
    option add *Panedwindow.sashPad	2 $prio; # 0
    option add *Panedwindow.sashRelief	raised $prio; # flat
    option add *Panedwindow.opaqueResize	0 $prio; # 1
    if {[tk windowingsystem] ne "win32"} {
	option add *Panedwindow.showHandle	1 $prio; # 0
    }
}

proc ::tk::classic::restore_scale {args} {
    variable prio
    option add *Scale.borderWidth	2 $prio; # 1
    if {[tk windowingsystem] eq "x11"} {
	option add *Scale.troughColor	"#c3c3c3" $prio; # "#b3b3b3"
    }
}

proc ::tk::classic::restore_scrollbar {args} {
    variable prio
    if {[tk windowingsystem] eq "x11"} {
	option add *Scrollbar.borderWidth	2 $prio; # 1
	option add *Scrollbar.highlightThickness 1 $prio; # 0
	option add *Scrollbar.width		15 $prio; # 11
	option add *Scrollbar.troughColor	"#c3c3c3" $prio; # "#b3b3b3"
    }
}

proc ::tk::classic::restore_text {args} {
    variable prio
    if {[tk windowingsystem] ne "aqua"} {
	option add *Text.borderWidth	2 $prio; # 1
    }
    if {[tk windowingsystem] eq "win32"} {
	option add *Text.font		"TkDefaultFont" $prio; # "TkFixedFont"
    }
    if {[tk windowingsystem] eq "x11"} {
	option add *Text.background		"#d9d9d9" $prio; # white
	option add *Text.selectBorderWidth	1 $prio; # 0
    }
}

Changes to library/optMenu.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# optMenu.tcl --
#
# This file defines the procedure tk_optionMenu, which creates
# an option button and its associated menu.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

# ::tk_optionMenu --
# This procedure creates an option button named $w and an associated
33
34
35
36
37
38
39
40

41
42
43
33
34
35
36
37
38
39

40
41
42
43







-
+



    }
    menubutton $w -textvariable $varName -indicatoron 1 -menu $w.menu \
	    -relief raised -highlightthickness 1 -anchor c \
	    -direction flush
    menu $w.menu -tearoff 0
    $w.menu add radiobutton -label $firstValue -variable $varName
    foreach i $args {
	$w.menu add radiobutton -label $i -variable $varName
    	$w.menu add radiobutton -label $i -variable $varName
    }
    return $w.menu
}

Changes to library/palette.tcl.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







# palette.tcl --
#
# This file contains procedures that change the color palette used
# by Tk.
#
# Copyright © 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1995-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.
#

# ::tk_setPalette --
# Changes the default color scheme for a Tk application by setting
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
66
67
68
69
70
71
72














73
74
75
76
77
78
79







-
-
-
-
-
-
-
-
-
-
-
-
-
-







	set new(disabledForeground) [format #%02x%02x%02x \
		[expr {(3*$bg_r + $fg_r)/1024}] \
		[expr {(3*$bg_g + $fg_g)/1024}] \
		[expr {(3*$bg_b + $fg_b)/1024}]]
    }
    if {![info exists new(highlightBackground)]} {
	set new(highlightBackground) $new(background)
    }
    # 'buttonBackground' is the background color of the buttons in
    # the spinbox widget.
    if {![info exists new(buttonBackground)]} {
	set new(buttonBackground) $new(background)
    }
    # 'selectColor' is the background of check & radio buttons.
    if {![info exists new(selectColor)]} {
	foreach {r g b} $bg {break}
	if {$r+1.5*$g+0.5*$b > 100000} {
	    set new(selectColor) white
	} else {
	    set new(selectColor) black
	}
    }
    if {![info exists new(activeBackground)]} {
	# Pick a default active background that islighter than the
	# normal background.  To do this, round each color component
	# up by 15% or 1/3 of the way to full white, whichever is
	# greater.

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
135
136
137
138
139
140
141




















142
143
144
145
146
147
148







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	option add *$option $new($option) widgetDefault
    }

    # Save the options in the variable ::tk::Palette, for use the
    # next time we change the options.

    array set ::tk::Palette [array get new]

    if {[tk windowingsystem] ne "x11" || [ttk::style theme use] ne "default"} {
	return
    }

    # Update the 'default' ttk theme with the new palette,
    # and then set 'default' as the current ttk theme,
    # in order to apply the new palette to the ttk widgets.

    foreach option [array names new] {
	if {[info exists ttk::theme::default::colorOptionLookup($option)]} {
	    foreach colorName $ttk::theme::default::colorOptionLookup($option) {
		set ttk::theme::default::colors($colorName) $new($option)
	    }
	}
    }
    ttk::theme::default::reconfigureDefaultTheme
    ttk::setTheme default

    return
}

# ::tk::RecolorTree --
# This procedure changes the colors in a window and all of its
# descendants, according to information provided by the colors
# argument. This looks at the defaults provided by the option
# database, if it exists, and if not, then it looks at the default
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256







257
258
259
260







261
262

263
264
265
266
267
268
269
201
202
203
204
205
206
207

208
209
210
211
212










213
214
215
216
217
218
219




220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235







-
+




-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+

-
+








# ::tk::Darken --
# Given a color name, computes a new color value that darkens (or
# brightens) the given color by a given percent.
#
# Arguments:
# color -	Name of starting color.
# percent -	Integer telling how much to brighten or darken as a
# perecent -	Integer telling how much to brighten or darken as a
#		percent: 50 means darken by 50%, 110 means brighten
#		by 10%.

proc ::tk::Darken {color percent} {
    if {$percent < 0} {
        return #000000
    } elseif {$percent > 200} {
        return #ffffff
    } elseif {$percent <= 100} {
        lassign [winfo rgb . $color] r g b
        set r [expr {($r/256)*$percent/100}]
        set g [expr {($g/256)*$percent/100}]
        set b [expr {($b/256)*$percent/100}]
    } elseif {$percent > 100} {
    foreach {red green blue} [winfo rgb . $color] {
	set red [expr {($red/256)*$percent/100}]
	set green [expr {($green/256)*$percent/100}]
	set blue [expr {($blue/256)*$percent/100}]
	break
    }
    if {$red > 255} {
        lassign [winfo rgb . $color] r g b
        set r [expr {255 - ((65535-$r)/256)*(200-$percent)/100}]
        set g [expr {255 - ((65535-$g)/256)*(200-$percent)/100}]
        set b [expr {255 - ((65535-$b)/256)*(200-$percent)/100}]
	set red 255
    }
    if {$green > 255} {
	set green 255
    }
    if {$blue > 255} {
	set blue 255
    }
    return [format #%02x%02x%02x $r $g $b]
    return [format "#%02x%02x%02x" $red $green $blue]
}

# ::tk_bisque --
# Reset the Tk color palette to the old "bisque" colors.
#
# Arguments:
# None.

Deleted library/print.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# print.tcl --

# This file defines the 'tk print' command for printing of the canvas
# widget and text on X11, Windows, and macOS. It implements an abstraction
# layer that presents a consistent API across the three platforms.

# Copyright © 2009 Michael I. Schwartz.
# Copyright © 2021 Kevin Walzer/WordTech Communications LLC.
# Copyright © 2021 Harald Oehlmann, Elmicron GmbH
# Copyright © 2022 Emiliano Gavilan
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

namespace eval ::tk::print {
    namespace import -force ::tk::msgcat::*

    # makeTempFile:
    #    Create a temporary file and populate its contents
    # Arguments:
    #	 filename - base of the name of the file to create
    #    contents - what to put in the file; defaults to empty
    # Returns:
    #    Full filename for created file
    #
    proc makeTempFile {filename {contents ""}} {
	set dumpfile [file join /tmp rawprint.txt]
	set tmpfile [file join /tmp $filename]
	set f [open $dumpfile w]
	try {
	    puts -nonewline $f $contents
	} finally {
	    close $f
	    if {[file extension $filename] == ".ps"} {
		#don't apply formatting to PostScript
		file rename -force $dumpfile $tmpfile
	    } else {
	    #Make text fixed width for improved printed output
		exec fmt -w 75 $dumpfile > $tmpfile
	    }
	    return $tmpfile
	}
    }

    if {[tk windowingsystem] eq "win32"} {
	variable printer_name
	variable copies
	variable dpi_x
	variable dpi_y
	variable paper_width
	variable paper_height
	variable margin_left
	variable margin_top
	variable printargs
	array set printargs {}

	# Multiple utility procedures for printing text based on the
	# C printer primitives.

	# _set_dc:
	# Select printer and set device context and other parameters
	# for print job.
	#
	proc _set_dc {} {
	    variable printargs
	    variable printer_name
	    variable paper_width
	    variable paper_height
	    variable dpi_x
	    variable dpi_y
	    variable copies

	    #First, we select the printer.
	    _selectprinter

	    #Next, set values. Some are taken from the printer,
	    #some are sane defaults.

        if {[info exists printer_name] && $printer_name ne ""} {
	    set printargs(hDC) $printer_name
	    set printargs(pw) $paper_width
	    set printargs(pl) $paper_height
	    set printargs(lm) 1000
	    set printargs(tm) 1000
	    set printargs(rm) 1000
	    set printargs(bm) 1000
	    set printargs(resx) $dpi_x
	    set printargs(resy) $dpi_y
	    set printargs(copies) $copies
	    set printargs(resolution) [list $dpi_x $dpi_y]
		}
	}

	# _print_data
	# This function prints multiple-page files, using a line-oriented
	# function, taking advantage of knowing the character widths.
	# Arguments:
	# data -       Text data for printing
	# breaklines - If non-zero, keep newlines in the string as
	#              newlines in the output.
	# font -       Font for printing
	proc _print_data {data {breaklines 1} {font ""}} {
	    variable printargs
	    variable printer_name

	    _set_dc

	    if {![info exists printer_name]} {
		return
	    }

	    if {$font eq ""} {
		_gdi characters $printargs(hDC) -array printcharwid
	    } else {
		_gdi characters $printargs(hDC) -font $font -array printcharwid
	    }
	    set pagewid [expr {($printargs(pw) - $printargs(rm) ) / 1000 * $printargs(resx)}]
	    set pagehgt [expr {($printargs(pl) - $printargs(bm) ) / 1000 * $printargs(resy)}]
	    set totallen [string length $data]
	    set curlen 0
	    set curhgt [expr {$printargs(tm) * $printargs(resy) / 1000}]

	    _opendoc
	    _openpage

	    while {$curlen < $totallen} {
		set linestring [string range $data $curlen end]
		if {$breaklines} {
		    set endind [string first "\n" $linestring]
		    if {$endind >= 0} {
			set linestring [string range $linestring 0 $endind]
			# handle blank lines....
			if {$linestring eq ""} {
			    set linestring " "
			}
		    }
		}

		set result [_print_page_nextline $linestring \
				printcharwid printargs $curhgt $font]
		incr curlen [lindex $result 0]
		incr curhgt [lindex $result 1]
		if {$curhgt + [lindex $result 1] > $pagehgt} {
		    _closepage
		    _openpage
		    set curhgt [expr {$printargs(tm) * $printargs(resy) / 1000}]
		}
	    }

	    _closepage
	    _closedoc
	}

	# _print_file
	# This function prints multiple-page files
	# It will either break lines or just let them run over the
	# margins (and thus truncate).
	# The font argument is JUST the font name, not any additional
	# arguments.
	# Arguments:
	#   filename -   File to open for printing
	#   breaklines - 1 to break lines as done on input, 0 to ignore newlines
	#   font -       Optional arguments to supply to the text command
	proc _print_file {filename {breaklines 1} {font ""}} {
	    set fn [open $filename r]
	    set data [read $fn]
	    close $fn
	    _print_data $data $breaklines $font
	}

	# _print_page_nextline
	# Returns the pair "chars y"
	# where chars is the number of characters printed on the line
	# and y is the height of the line printed
	# Arguments:
	#   string -         Data to print
	#   pdata -         Array of values for printer characteristics
	#   cdata -         Array of values for character widths
	#   y -              Y value to begin printing at
	#   font -           if non-empty specifies a font to draw the line in
	proc _print_page_nextline {string carray parray y font} {
	    upvar #0 $carray charwidths
	    upvar #0 $parray printargs

	    variable printargs

	    set endindex 0
	    set totwidth 0
	    set maxwidth [expr {
		(($printargs(pw) - $printargs(rm)) / 1000) * $printargs(resx)
	    }]
	    set maxstring [string length $string]
	    set lm [expr {$printargs(lm) * $printargs(resx) / 1000}]

	    for {set i 0} {($i < $maxstring) && ($totwidth < $maxwidth)} {incr i} {
		incr totwidth $charwidths([string index $string $i])
		# set width($i) $totwidth
	    }

	    set endindex $i
	    set startindex $endindex

	    if {$i < $maxstring} {
		# In this case, the whole data string is not used up, and we
		# wish to break on a word. Since we have all the partial
		# widths calculated, this should be easy.

		set endindex [expr {[string wordstart $string $endindex] - 1}]
		set startindex [expr {$endindex + 1}]

		# If the line is just too long (no word breaks), print as much
		# as you can....
		if {$endindex <= 1} {
		    set endindex $i
		    set startindex $i
		}
	    }

	    set txt [string trim [string range $string 0 $endindex] "\r\n"]
	    if {$font ne ""} {
		set result [_gdi text $printargs(hDC) $lm $y \
				 -anchor nw -justify left \
				 -text $txt -font $font]
	    } else {
		set result [_gdi text $printargs(hDC) $lm $y \
				 -anchor nw -justify left -text $txt]
	    }
	    return "$startindex $result"
	}

	# These procedures read in the canvas widget, and write all of
	# its contents out to the Windows printer.

	variable option
	variable vtgPrint

	proc _init_print_canvas {} {
	    variable option
	    variable vtgPrint
	    variable printargs

	    set vtgPrint(printer.bg) white
	}

	proc _is_win {} {
	    variable printargs

	    return [info exist tk_patchLevel]
	}

	# _print_widget
	# Main procedure for printing a widget.  Currently supports
	# canvas widgets.  Handles opening and closing of printer.
	# Arguments:
	#   wid -              The widget to be printed.
	#   printer -          Flag whether to use the default printer.
	#   name  -            App name to pass to printer.

	proc _print_widget {wid {printer default} {name "Tk Print Output"}} {
	    variable printargs
	    variable printer_name

	    _set_dc

	    if {![info exists printer_name]} {
		return
	    }

	    _opendoc
	    _openpage

	    # Here is where any scaling/gdi mapping should take place
	    # For now, scale so the dimensions of the window are sized to the
	    # width of the page. Scale evenly.

	    # For normal windows, this may be fine--but for a canvas, one
	    # wants the canvas dimensions, and not the WINDOW dimensions.
	    if {[winfo class $wid] eq "Canvas"} {
		set sc [$wid cget -scrollregion]
		# if there is no scrollregion, use width and height.
		if {$sc eq ""} {
		    set window_x [$wid cget -width]
		    set window_y [$wid cget -height]
		} else {
		    set window_x [lindex $sc 2]
		    set window_y [lindex $sc 3]
		}
	    } else {
		set window_x [winfo width $wid]
		set window_y [winfo height $wid]
	    }

	    set printer_x [expr {
		( $printargs(pw) - $printargs(lm) - $printargs(rm) ) *
		$printargs(resx)  / 1000.0
	    }]
	    set printer_y [expr {
		( $printargs(pl) - $printargs(tm) - $printargs(bm) ) *
		$printargs(resy) / 1000.0
	    }]
	    set factor_x [expr {$window_x / $printer_x}]
	    set factor_y [expr {$window_y / $printer_y}]

	    if {$factor_x < $factor_y} {
		set lo $window_y
		set ph $printer_y
	    } else {
		set lo $window_x
		set ph $printer_x
	    }

	    _gdi map $printargs(hDC) -logical $lo -physical $ph \
		-offset $printargs(resolution)

	    # Handling of canvas widgets.
	    switch [winfo class $wid] {
		Canvas {
		    _print_canvas $printargs(hDC) $wid
		}
		default {
		    puts "Can't print items of type [winfo class $wid]. No handler registered"
		}
	    }

	    # End printing process.
	    _closepage
	    _closedoc
	}

	#  _print_canvas
	# Main procedure for writing canvas widget items to printer.
	# Arguments:
	#    hdc -              The printer handle.
	#    cw  -              The canvas widget.
	proc _print_canvas {hdc cw} {
	    variable  vtgPrint
	    variable printargs

	    # Get information about page being printed to
	    # print_canvas.CalcSizing $cw
	    set vtgPrint(canvas.bg) [string tolower [$cw cget -background]]

	    # Re-write each widget from cw to printer
	    foreach id [$cw find all] {
		set type [$cw type $id]
		if {[info commands _print_canvas.$type] eq "_print_canvas.$type"} {
		    _print_canvas.[$cw type $id] $printargs(hDC) $cw $id
		} else {
		    puts "Omitting canvas item of type $type since there is no handler registered for it"
		}
	    }
	}

	# These procedures support the various canvas item types, reading the
	# information about the item on the real canvas and then writing a
	# similar item to the printer.

	# _print_canvas.line
	# Description:
	#   Prints a line item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.line {hdc cw id} {
	    variable vtgPrint
	    variable printargs

	    set color [_print_canvas.TransColor [$cw itemcget $id -fill]]
	    if {[string match $vtgPrint(printer.bg) $color]} {
		return
	    }

	    set coords  [$cw coords $id]
	    set wdth    [$cw itemcget $id -width]
	    set arrow   [$cw itemcget $id -arrow]
	    set arwshp  [$cw itemcget $id -arrowshape]
	    set dash    [$cw itemcget $id -dash]
	    set smooth  [$cw itemcget $id -smooth]
	    set splinesteps [$cw itemcget $id -splinesteps]

	    set cmdargs {}

	    if {$wdth > 1} {
		lappend cmdargs -width $wdth
	    }
	    if {$dash ne ""} {
		lappend cmdargs -dash $dash
	    }
	    if {$smooth ne ""} {
		lappend cmdargs -smooth $smooth
	    }
	    if {$splinesteps ne ""} {
		lappend cmdargs -splinesteps $splinesteps
	    }

	    set result [_gdi line $hdc {*}$coords \
			    -fill $color -arrow $arrow -arrowshape $arwshp \
			    {*}$cmdargs]
	    if {$result ne ""} {
		puts $result
	    }
	}

	# _print_canvas.arc
	#   Prints a arc item.
	# Args:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.arc {hdc cw id} {
	    variable vtgPrint
	    variable printargs

	    set color [_print_canvas.TransColor [$cw itemcget $id -outline]]
	    if {[string match $vtgPrint(printer.bg) $color]} {
		return
	    }
	    set coords  [$cw coords $id]
	    set wdth    [$cw itemcget $id -width]
	    set style   [$cw itemcget $id -style]
	    set start   [$cw itemcget $id -start]
	    set extent  [$cw itemcget $id -extent]
	    set fill    [$cw itemcget $id -fill]

	    set cmdargs {}
	    if {$wdth > 1} {
		lappend cmdargs -width $wdth
	    }
	    if {$fill ne ""} {
		lappend cmdargs -fill $fill
	    }

	    _gdi arc $hdc {*}$coords \
		-outline $color -style $style -start $start -extent $extent \
		{*}$cmdargs
	}

	# _print_canvas.polygon
	#   Prints a polygon item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.polygon {hdc cw id} {
	    variable vtgPrint
	    variable printargs

	    set fcolor [_print_canvas.TransColor [$cw itemcget $id -fill]]
	    if {$fcolor eq ""} {
		set fcolor $vtgPrint(printer.bg)
	    }
	    set ocolor [_print_canvas.TransColor [$cw itemcget $id -outline]]
	    if {$ocolor eq ""} {
		set ocolor $vtgPrint(printer.bg)
	    }
	    set coords  [$cw coords $id]
	    set wdth [$cw itemcget $id -width]
	    set smooth  [$cw itemcget $id -smooth]
	    set splinesteps [$cw itemcget $id -splinesteps]

	    set cmdargs {}
	    if {$smooth ne ""} {
		lappend cmdargs -smooth $smooth
	    }
	    if {$splinesteps ne ""} {
		lappend cmdargs -splinesteps $splinesteps
	    }

	    _gdi polygon $hdc {*}$coords \
		-width $wdth -fill $fcolor -outline $ocolor {*}$cmdargs
	}

	# _print_canvas.oval
	#   Prints an oval item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.oval {hdc cw id} {
	    variable vtgPrint

	    set fcolor [_print_canvas.TransColor [$cw itemcget $id -fill]]
	    if {$fcolor eq ""} {
		set fcolor $vtgPrint(printer.bg)
	    }
	    set ocolor [_print_canvas.TransColor [$cw itemcget $id -outline]]
	    if {$ocolor eq ""} {
		set ocolor $vtgPrint(printer.bg)
	    }
	    set coords  [$cw coords $id]
	    set wdth [$cw itemcget $id -width]

	    _gdi oval $hdc {*}$coords \
		-width $wdth -fill $fcolor -outline $ocolor
	}

	# _print_canvas.rectangle
	#   Prints a rectangle item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.rectangle {hdc cw id} {
	    variable vtgPrint

	    set fcolor [_print_canvas.TransColor [$cw itemcget $id -fill]]
	    if {$fcolor eq ""} {
		set fcolor $vtgPrint(printer.bg)
	    }
	    set ocolor [_print_canvas.TransColor [$cw itemcget $id -outline]]
	    if {$ocolor eq ""} {
		set ocolor $vtgPrint(printer.bg)
	    }
	    set coords  [$cw coords $id]
	    set wdth [$cw itemcget $id -width]

	    _gdi rectangle $hdc {*}$coords \
		-width $wdth -fill $fcolor -outline $ocolor
	}

	# _print_canvas.text
	#   Prints a text item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.text {hdc cw id} {
	    variable vtgPrint
	    variable printargs

	    set color [_print_canvas.TransColor [$cw itemcget $id -fill]]
	    #    if {"white" eq [string tolower $color]} {return}
	    #    set color black
	    set txt [$cw itemcget $id -text]
	    if {$txt eq ""} {
		return
	    }
	    set coords [$cw coords $id]
	    set anchr [$cw itemcget $id -anchor]

	    set bbox [$cw bbox $id]
	    set wdth [expr {[lindex $bbox 2] - [lindex $bbox 0]}]

	    set just [$cw itemcget $id -justify]

	    # Get the real canvas font info and create a compatible font,
	    # suitable for printer name extraction.
	    set font [font create {*}[font actual [$cw itemcget $id -font]]]

	    # Just get the name and family, or some of the _gdi commands will
	    # fail.
	    set font [list [font configure $font -family] \
			  -[font configure $font -size]]

	    _gdi text $hdc {*}$coords \
		-fill $color -text $txt -font $font \
		-anchor $anchr -width $wdth -justify $just
	}

	# _print_canvas.image
	# Prints an image item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.image {hdc cw id} {
	    # First, we have to get the image name.
	    set imagename [$cw itemcget $id -image]

	    # Now we get the size.
	    set wid [image width $imagename]
	    set hgt [image height $imagename]

	    # Next, we get the location and anchor
	    set anchor [$cw itemcget $id -anchor]
	    set coords [$cw coords $id]

	    _gdi photo $hdc -destination $coords -photo $imagename
	}

	# _print_canvas.bitmap
	#   Prints a bitmap item.
	# Arguments:
	#   hdc -              The printer handle.
	#   cw  -              The canvas widget.
	#   id  -              The id of the canvas item.
	proc _print_canvas.bitmap {hdc cw id} {
	    variable option
	    variable vtgPrint

	    # First, we have to get the bitmap name.
	    set imagename [$cw itemcget $id -image]

	    # Now we get the size.
	    set wid [image width $imagename]
	    set hgt [image height $imagename]

	    #Next, we get the location and anchor.
	    set anchor [$cw itemcget $id -anchor]
	    set coords [$cw coords $id]

	    # Since the GDI commands don't yet support images and bitmaps,
	    # and since this represents a rendered bitmap, we CAN use
	    # copybits IF we create a new temporary toplevel to hold the beast.
	    # If this is too ugly, change the option!

	    if {[info exist option(use_copybits)]} {
		set firstcase $option(use_copybits)
	    } else {
		set firstcase 0
	    }
	    if {$firstcase > 0} {
		set tl [toplevel .tmptop[expr {int( rand() * 65535 )}] \
			    -height $hgt -width $wid \
			    -background $vtgPrint(canvas.bg)]
		canvas $tl.canvas -width $wid -height $hgt
		$tl.canvas create image 0 0 -image $imagename -anchor nw
		pack $tl.canvas -side left -expand false -fill none
		tkwait visibility $tl.canvas
		update
		set srccoords [list 0 0 [expr {$wid - 1}] [expr {$hgt - 1}]]
		set dstcoords [list [lindex $coords 0] [lindex $coords 1] [expr {$wid - 1}] [expr {$hgt - 1}]]
		_gdi copybits $hdc -window $tl -client \
		    -source $srccoords -destination $dstcoords
		destroy $tl
	    } else {
		_gdi bitmap $hdc {*}$coords \
		    -anchor $anchor -bitmap $imagename
	    }
	}

	# These procedures transform attribute setting from the real
	# canvas to the appropriate setting for printing to paper.

	# _print_canvas.TransColor
	#   Does the actual transformation of colors from the
	#   canvas widget to paper.
	# Arguments:
	#   color -            The color value to be transformed.
	proc _print_canvas.TransColor {color} {
	    variable vtgPrint
	    variable printargs

	    switch [string toupper $color] {
		$vtgPrint(canvas.bg)       {return $vtgPrint(printer.bg)}
	    }
	    return $color
	}

	# Initialize all the variables once.
	_init_print_canvas
    }
    #end win32 procedures

    #begin X11 procedures

    # X11 procedures wrap standard Unix shell commands such as lp/lpr and
    # lpstat for printing. Some output configuration that on other platforms
    # is managed through the printer driver/dialog is configured through the
    # canvas postscript command.

    if {[tk windowingsystem] eq "x11"} {
	variable printcmd {}

	# print options
	variable optlist
	set optlist(printer) {}
	set optlist(paper)   [list [mc "Letter"] [mc "Legal"] [mc "A4"]]
	set optlist(orient)  [list [mc "Portrait"] [mc "Landscape"]]
	set optlist(color)   [list [mc "Grayscale"] [mc "RGB"]]
	set optlist(zoom)    {100 90 80 70 60 50 40 30 20 10}

	# selected options
	variable sel
	array set sel {
	    printer {}
	    copies  {}
	    paper   {}
	    orient  {}
	    color   {}
	    zoom    {}
	}

	# default values for dialog widgets
	option add *Printdialog*TLabel.anchor e
	option add *Printdialog*TMenubutton.Menu.tearOff 0
	option add *Printdialog*TMenubutton.width 12
	option add *Printdialog*TSpinbox.width 12
	# this is tempting to add, but it's better to leave it to user's taste
	# option add *Printdialog*Menu.background snow

	# returns the full qualified var name
	proc myvar {varname} {
	    set fqvar [uplevel 1 [list namespace which -variable $varname]]
	    # assert var existence
	    if {$fqvar eq ""} {
		return -code error "Wrong varname \"$varname\""
	    }
	    return $fqvar
	}

	# ttk version of [tk_optionMenu]
	# var should be a full qualified varname
	proc ttk_optionMenu {w var args} {
	    ttk::menubutton $w \
		-textvariable $var \
		-menu $w.menu
	    menu $w.menu
	    foreach option $args {
		$w.menu add command \
		    -label $option \
		    -command [list set $var $option]
	    }
	    # return the same value as tk_optionMenu
	    return $w.menu
	}

	# _setprintenv
	#  Set the print environtment - print command, and list of printers.
	#  Arguments:
	#    none.

	proc _setprintenv {} {
	    variable printcmd
	    variable optlist

	    #Test for existence of lpstat command to obtain list of printers. Return error
	    #if not found.

	    catch {exec lpstat -a} msg
	    set notfound "command not found"
	    if {[string first $notfound $msg] >= 0} {
		error "Unable to obtain list of printers. Please install the CUPS package \
		for your system."
		return
	    }
 	    set notfound "No destinations added"
 	    if {[string first $notfound $msg] != -1} {
		error "Please check or update your CUPS installation."
		return
	    }

	    # Select print command. We prefer lpr, but will fall back to lp if
	    # necessary.
	    if {[auto_execok lpr] ne ""} {
		set printcmd lpr
	    } else {
		set printcmd lp
	    }

	    #Build list of printers
	    set printers {}
	    set printdata [exec lpstat -a]
	    foreach item [split $printdata \n] {
		lappend printers [lindex [split $item] 0]
	    }
	    # filter out duplicates
	    set optlist(printer) [lsort -unique $printers]
	}

	# _print
	#  Main printer dialog. Select printer, set options, and
	#  fire print command.
	# Arguments:
	#  w - widget with contents to print.
	#

	proc _print {w} {
	# TODO: revise padding
	    variable optlist
	    variable sel

	    # should this be called with every invocaton?
	    _setprintenv
	    if {$sel(printer) eq "" && [llength $optlist(printer)] > 0} {
		set sel(printer) [lindex $optlist(printer) 0]
	    }

	    set p ._print
	    catch {destroy $p}

	    # copy the current values to a dialog's temorary variable
	    # this allow us to cancel the dialog discarding any changes
	    # made to the options
	    namespace eval dlg {variable sel}
	    array set dlg::sel [array get sel]

	    # The toplevel of our dialog
	    toplevel $p -class Printdialog
	    place [ttk::frame $p.background] -x 0 -y 0 -relwidth 1.0 -relheight 1.0
	    wm title $p [mc "Print"]
	    wm resizable $p 0 0
	    wm attributes $p -type dialog

	    # The printer to use
	    set pf [ttk::frame $p.printerf]
	    pack $pf -side top -fill x -expand no -padx 9p -pady 9p

	    ttk::label $pf.printerl -text "[mc "Printer"] :"
	    ttk::combobox $pf.printer \
		-textvariable [myvar dlg::sel](printer) \
		-state readonly \
		-values $optlist(printer)
	    pack $pf.printerl -side left -padx {0 4.5p}
	    pack $pf.printer  -side left

	    # Start of printing options
	    set of [ttk::labelframe $p.optionsframe -text [mc "Options"]]
	    pack $of -fill x -padx 9p -pady {0 9p} -ipadx 2p -ipady 2p

	    # COPIES
	    ttk::label $of.copiesl -text "[mc "Copies"] :"
	    ttk::spinbox $of.copies -from 1 -to 1000 \
		-textvariable [myvar dlg::sel](copies)
	    grid $of.copiesl $of.copies -sticky ew -padx 2p -pady 2p

	    # PAPER SIZE
	    ttk::label $of.paperl -text "[mc "Paper"] :"
	    ttk_optionMenu $of.paper [myvar dlg::sel](paper) {*}$optlist(paper)
	    grid $of.paperl $of.paper -sticky ew -padx 2p -pady 2p

	    # additional options for canvas output
	    if {[winfo class $w] eq "Canvas"} {
		# SCALE
		ttk::label $of.percentl -text "[mc "Scale"] :"
		ttk_optionMenu $of.percent [myvar dlg::sel](zoom) {*}$optlist(zoom)
		grid $of.percentl $of.percent -sticky ew -padx 2p -pady 2p

		# ORIENT
		ttk::label $of.orientl -text "[mc "Orientation"] :"
		ttk_optionMenu $of.orient [myvar dlg::sel](orient) {*}$optlist(orient)
		grid $of.orientl $of.orient -sticky ew -padx 2p -pady 2p

		# COLOR
		ttk::label $of.colorl -text "[mc "Output"] :"
		ttk_optionMenu $of.color [myvar dlg::sel](color) {*}$optlist(color)
		grid $of.colorl $of.color -sticky ew -padx 2p -pady 2p
	    }

	    # The buttons frame.
	    set bf [ttk::frame $p.buttonf]
	    pack $bf -fill x -expand no -side bottom -padx 9p -pady {0 9p}

	    ttk::button $bf.print -text [mc "Print"] \
		-command [namespace code [list _runprint $w $p]]
	    ttk::button $bf.cancel -text [mc "Cancel"] \
		-command [namespace code [list _cancel $p]]
	    pack $bf.print  -side right
	    pack $bf.cancel -side right -padx {0 4.5p}
	    #Center the window as a dialog.
	    ::tk::PlaceWindow $p
	}

	proc _cancel {p} {
	    namespace delete dlg
	    destroy $p
	}

	# _runprint -
	#   Execute the print command--print the file.
	# Arguments:
	#  w - widget with contents to print.
	#
	proc _runprint {w p} {
	    variable printcmd
	    variable sel

	    # copy the values back from the dialog
	    array set sel [array get dlg::sel]
	    namespace delete dlg

	    #First, generate print file.
	    if {[winfo class $w] eq "Text"} {
		set file [makeTempFile tk_text.txt [$w get 1.0 end]]
	    }

	    if {[winfo class $w] eq "Canvas"} {
		if {$sel(color) eq [mc "RGB"]} {
		    set colormode color
		} else {
		    set colormode gray
		}

		if {$sel(orient) eq [mc "Landscape"]} {
		    set willrotate "1"
		} else {
		    set willrotate "0"
		}

		#Scale based on size of widget, not size of paper.
		set printwidth [expr {$sel(zoom) / 100.00 * [winfo width $w]}]
		set file [makeTempFile tk_canvas.ps]
		$w postscript -file $file -colormode $colormode \
		    -rotate $willrotate -pagewidth $printwidth
	    }

	    #Build list of args to pass to print command.
	    set printargs {}
	    if {$printcmd eq "lpr"} {
		lappend printargs -P $sel(printer) -# $sel(copies)
	    } else {
		lappend printargs -d $sel(printer) -n $sel(copies)
	    }

	    # launch the job in the background
	    after 0 [list exec $printcmd {*}$printargs -o PageSize=$sel(paper) $file]
	    destroy $p
	}

	# Initialize with sane defaults.
	set sel(copies)  1
	set sel(paper)   [mc "A4"]
	set sel(orient)  [mc "Portrait"]
	set sel(color)   [mc "RGB"]
	set sel(zoom)    100
    }
    #end X11 procedures

    #begin macOS Aqua procedures
    if {[tk windowingsystem] eq "aqua"} {
	# makePDF -
	#   Convert a file to PDF
	# Arguments:
	#   inFilename -  file containing the data to convert; format is
	#                 autodetected.
	#   outFilename - base for filename to write to; conventionally should
	#                 have .pdf as suffix
	# Returns:
	#   The full pathname of the generated PDF.
	#
	proc makePDF {inFilename outFilename} {
	    set out [::tk::print::makeTempFile $outFilename]
	    try {
		exec /usr/sbin/cupsfilter $inFilename > $out
	    } trap NONE {msg} {
		# cupsfilter produces a lot of debugging output, which we
		# don't want.
		regsub -all -line {^(?:DEBUG|INFO):.*$} $msg "" msg
		set msg [string trimleft [regsub -all {\n+} $msg "\n"] "\n"]
		if {$msg ne ""} {
		    # Lines should be prefixed with WARN or ERROR now
		    puts $msg
		}
	    }
	    return $out
	}
    }
    #end macOS Aqua procedures

    namespace export canvas text
    namespace ensemble create
}

# tk print --
# This procedure prints the canvas and text widgets using platform-
# native API's.
#   Arguments:
#      w: Widget to print.
proc ::tk::print {w} {
    switch [winfo class $w],[tk windowingsystem] {
	"Canvas,win32" {
	    tailcall ::tk::print::_print_widget $w 0 "Tk Print Output"
	}
	"Canvas,x11" {
	    tailcall ::tk::print::_print $w
	}
	"Canvas,aqua" {
	    ::tk::print::_printcanvas $w
	    set printfile /tmp/tk_canvas.pdf
	    ::tk::print::_print $printfile
	}
	"Text,win32" {
	    tailcall ::tk::print::_print_data [$w get 1.0 end] 1 {Arial 12}
	}
	"Text,x11" {
	    tailcall ::tk::print::_print $w
	}
	"Text,aqua" {
	    set txtfile [::tk::print::makeTempFile tk_text.txt [$w get 1.0 end]]
	    try {
		set printfile [::tk::print::makePDF $txtfile [file join /tmp tk_text.pdf]]
		::tk::print::_print $printfile
	    } finally {
		file delete $txtfile
	    }
	}

	default {
	    return -code error -errorcode {TK PRINT CLASS_UNSUPPORTED} \
		"widgets of class [winfo class $w] are not supported on\
		this platform"
	}
    }
}

#Add this command to the tk command ensemble: tk print
#Thanks to Christian Gollwitzer for the guidance here
namespace ensemble configure tk -map \
    [dict merge [namespace ensemble configure tk -map] \
	 {print ::tk::print}]

return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to library/safetk.tcl.

1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17

18
19

20
21
22
23
24
25
26
27
28
29
30
31
32

33
34

35
36

37
38
39
40
41
42
43

44
45
46

47
48

49
50

51
52
53
54
55
56

57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72

73
74
75
76
77

78
79
80
81
82
83
84

85
86
87
88

89
90
91


92
93
94
95


96
97
98
99
100
101
102
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16

17
18

19
20
21
22
23
24
25
26
27
28
29
30
31

32
33

34
35

36
37
38
39
40
41
42

43
44
45

46
47

48
49

50
51
52
53
54
55

56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71

72
73
74
75
76

77
78
79
80
81
82
83

84
85
86
87

88
89


90
91
92
93


94
95
96
97
98
99
100
101
102




-
+











-
+

-
+












-
+

-
+

-
+






-
+


-
+

-
+

-
+





-
+








-
+






-
+




-
+






-
+



-
+

-
-
+
+


-
-
+
+







# safetk.tcl --
#
# Support procs to use Tk in safe interpreters.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright (c) 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.

# see safetk.n for documentation

#
#
# Note: It is now ok to let untrusted code being executed
#       between the creation of the interp and the actual loading
#       of Tk in that interp because the C side Tk_Init will
#       now look up the parent interp and ask its safe::TkInit
#       now look up the master interp and ask its safe::TkInit
#       for the actual parameters to use for it's initialization (if allowed),
#       not relying on the child state.
#       not relying on the slave state.
#

# We use opt (optional arguments parsing)
package require opt 0.4.1;

namespace eval ::safe {

    # counter for safe toplevels
    variable tkSafeId 0
}

#
# tkInterpInit : prepare the child interpreter for tk loading
# tkInterpInit : prepare the slave interpreter for tk loading
#                most of the real job is done by loadTk
# returns the child name (tkInterpInit does)
# returns the slave name (tkInterpInit does)
#
proc ::safe::tkInterpInit {child argv} {
proc ::safe::tkInterpInit {slave argv} {
    global env tk_library

    # We have to make sure that the tk_library variable is normalized.
    set tk_library [file normalize $tk_library]

    # Clear Tk's access for that interp (path).
    allowTk $child $argv
    allowTk $slave $argv

    # Ensure tk_library and subdirs (eg, ttk) are on the access path
    ::interp eval $child [list set tk_library [::safe::interpAddToAccessPath $child $tk_library]]
    ::interp eval $slave [list set tk_library [::safe::interpAddToAccessPath $slave $tk_library]]
    foreach subdir [::safe::AddSubDirs [list $tk_library]] {
	::safe::interpAddToAccessPath $child $subdir
	::safe::interpAddToAccessPath $slave $subdir
    }
    return $child
    return $slave
}


# tkInterpLoadTk:
# Do additional configuration as needed (calling tkInterpInit)
# and actually load Tk into the child.
# and actually load Tk into the slave.
#
# Either contained in the specified windowId (-use) or
# creating a decorated toplevel for it.

# empty definition for auto_mkIndex
proc ::safe::loadTk {} {}

::tcl::OptProc ::safe::loadTk {
    {child -interp "name of the child interpreter"}
    {slave -interp "name of the slave interpreter"}
    {-use  -windowId {} "window Id to use (new toplevel otherwise)"}
    {-display -displayName {} "display name to use (current one otherwise)"}
} {
    set displayGiven [::tcl::OptProcArgGiven "-display"]
    if {!$displayGiven} {
	# Try to get the current display from "."
	# (which might not exist if the parent is tk-less)
	# (which might not exist if the master is tk-less)
	if {[catch {set display [winfo screen .]}]} {
	    if {[info exists ::env(DISPLAY)]} {
		set display $::env(DISPLAY)
	    } else {
		Log $child "no winfo screen . nor env(DISPLAY)" WARNING
		Log $slave "no winfo screen . nor env(DISPLAY)" WARNING
		set display ":0.0"
	    }
	}
    }

    # Get state for access to the cleanupHook.
    namespace upvar ::safe S$child state
    namespace upvar ::safe S$slave state

    if {![::tcl::OptProcArgGiven "-use"]} {
	# create a decorated toplevel
	lassign [tkTopLevel $child $display] w use
	lassign [tkTopLevel $slave $display] w use

	# set our delete hook (child arg is added by interpDelete)
	# to clean up both window related code and tkInit(child)
	# set our delete hook (slave arg is added by interpDelete)
	# to clean up both window related code and tkInit(slave)
	set state(cleanupHook) [list tkDelete {} $w]
    } else {
	# set our delete hook (child arg is added by interpDelete)
	# to clean up tkInit(child)
	# set our delete hook (slave arg is added by interpDelete)
	# to clean up tkInit(slave)
	set state(cleanupHook) [list disallowTk]

	# Let's be nice and also accept tk window names instead of ids
	if {[string match ".*" $use]} {
	    set windowName $use
	    set use [winfo id $windowName]
	    set nDisplay [winfo screen $windowName]
118
119
120
121
122
123
124
125
126


127
128

129
130

131
132
133
134
135
136
137
118
119
120
121
122
123
124


125
126
127

128
129

130
131
132
133
134
135
136
137







-
-
+
+

-
+

-
+







		    "conflicting -display $display and -use $use -> $nDisplay"
	    } else {
		set display $nDisplay
	    }
	}
    }

    # Prepares the child for tk with those parameters
    tkInterpInit $child [list "-use" $use "-display" $display]
    # Prepares the slave for tk with those parameters
    tkInterpInit $slave [list "-use" $use "-display" $display]

    load {} Tk $child
    load {} Tk $slave

    return $child
    return $slave
}

proc ::safe::TkInit {interpPath} {
    variable tkInit
    if {[info exists tkInit($interpPath)]} {
	set value $tkInit($interpPath)
	Log $interpPath "TkInit called, returning \"$value\"" NOTICE
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196

197
198
199
200
201
202
203
204




205
206
207
208

209
210
211
212
213


214
215
216
217

218
219
220
221
222
223

224
225

226
227

228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250

251
252
253

254
255
256
257
258
259
260
261
262
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195

196
197
198
199
200




201
202
203
204
205
206
207

208
209
210
211


212
213
214
215
216

217
218
219
220
221
222

223
224

225
226

227
228
229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247
248
249

250
251
252

253
254
255
256
257
258
259
260
261
262







-
+


















-
+



















-
+




-
+




-
-
-
-
+
+
+
+



-
+



-
-
+
+



-
+





-
+

-
+

-
+











-
+










-
+


-
+










# safe::allowTk --
#
#	Set tkInit(interpPath) to allow Tk to be initialized in
#	safe::TkInit.
#
# Arguments:
#	interpPath	child interpreter handle
#	interpPath	slave interpreter handle
#	argv		arguments passed to safe::TkInterpInit
#
# Results:
#	none.

proc ::safe::allowTk {interpPath argv} {
    variable tkInit
    set tkInit($interpPath) $argv
    return
}


# safe::disallowTk --
#
#	Unset tkInit(interpPath) to disallow Tk from getting initialized
#	in safe::TkInit.
#
# Arguments:
#	interpPath	child interpreter handle
#	interpPath	slave interpreter handle
#
# Results:
#	none.

proc ::safe::disallowTk {interpPath} {
    variable tkInit
    # This can already be deleted by the DeleteHook of the interp
    if {[info exists tkInit($interpPath)]} {
	unset tkInit($interpPath)
    }
    return
}


# safe::tkDelete --
#
#	Clean up the window associated with the interp being deleted.
#
# Arguments:
#	interpPath	child interpreter handle
#	interpPath	slave interpreter handle
#
# Results:
#	none.

proc ::safe::tkDelete {W window child} {
proc ::safe::tkDelete {W window slave} {

    # we are going to be called for each widget... skip untill it's
    # top level

    Log $child "Called tkDelete $W $window" NOTICE
    if {[::interp exists $child]} {
	if {[catch {::safe::interpDelete $child} msg]} {
	    Log $child "Deletion error : $msg"
    Log $slave "Called tkDelete $W $window" NOTICE
    if {[::interp exists $slave]} {
	if {[catch {::safe::interpDelete $slave} msg]} {
	    Log $slave "Deletion error : $msg"
	}
    }
    if {[winfo exists $window]} {
	Log $child "Destroy toplevel $window" NOTICE
	Log $slave "Destroy toplevel $window" NOTICE
	destroy $window
    }

    # clean up tkInit(child)
    disallowTk $child
    # clean up tkInit(slave)
    disallowTk $slave
    return
}

proc ::safe::tkTopLevel {child display} {
proc ::safe::tkTopLevel {slave display} {
    variable tkSafeId
    incr tkSafeId
    set w ".safe$tkSafeId"
    if {[catch {toplevel $w -screen $display -class SafeTk} msg]} {
	return -code error -errorcode {TK TOPLEVEL SAFE} \
	    "Unable to create toplevel for \"$child\" ($msg)"
	    "Unable to create toplevel for safe slave \"$slave\" ($msg)"
    }
    Log $child "New toplevel $w" NOTICE
    Log $slave "New toplevel $w" NOTICE

    set msg "Untrusted Tcl applet ($child)"
    set msg "Untrusted Tcl applet ($slave)"
    wm title $w $msg

    # Control frame (we must create a style for it)
    ttk::style layout TWarningFrame {WarningFrame.border -sticky nswe}
    ttk::style configure TWarningFrame -background red

    set wc $w.fc
    ttk::frame $wc -relief ridge -borderwidth 4 -style TWarningFrame

    # We will destroy the interp when the window is destroyed
    bindtags $wc [concat Safe$wc [bindtags $wc]]
    bind Safe$wc <Destroy> [list ::safe::tkDelete %W $w $child]
    bind Safe$wc <Destroy> [list ::safe::tkDelete %W $w $slave]

    ttk::label $wc.l -text $msg -anchor w

    # We want the button to be the last visible item
    # (so be packed first) and at the right and not resizing horizontally

    # frame the button so it does not expand horizontally
    # but still have the default background instead of red one from the parent
    ttk::frame  $wc.fb -borderwidth 0
    ttk::button $wc.fb.b -text "Delete" \
	    -command [list ::safe::tkDelete $w $w $child]
	    -command [list ::safe::tkDelete $w $w $slave]
    pack $wc.fb.b -side right -fill both
    pack $wc.fb -side right -fill both -expand 1
    pack $wc.l -side left -fill both -expand 1 -ipady 1.5p
    pack $wc.l -side left -fill both -expand 1 -ipady 2
    pack $wc -side bottom -fill x

    # Container frame
    frame $w.c -container 1
    pack $w.c -fill both -expand 1

    # return both the toplevel window name and the id to use for embedding
    list $w [winfo id $w.c]
}

Changes to library/scale.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# scale.tcl --
#
# This file defines the default bindings for Tk scale widgets and provides
# procedures that help in implementing the bindings.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#-------------------------------------------------------------------------
# The code below creates the default class bindings for entries.
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62








63

64
65
66
67
68
69
70
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78







-
+












-
+












+
+
+
+
+
+
+
+
-
+







    if {$tk_strictMotif} {
	%W configure -activebackground $tk::Priv(activeBg)
    }
    if {[%W cget -state] eq "active"} {
	%W configure -state normal
    }
}
bind Scale <Button-1> {
bind Scale <1> {
    tk::ScaleButtonDown %W %x %y
}
bind Scale <B1-Motion> {
    tk::ScaleDrag %W %x %y
}
bind Scale <B1-Leave> { }
bind Scale <B1-Enter> { }
bind Scale <ButtonRelease-1> {
    tk::CancelRepeat
    tk::ScaleEndDrag %W
    tk::ScaleActivate %W %x %y
}
bind Scale <Button-2> {
bind Scale <2> {
    tk::ScaleButton2Down %W %x %y
}
bind Scale <B2-Motion> {
    tk::ScaleDrag %W %x %y
}
bind Scale <B2-Leave> { }
bind Scale <B2-Enter> { }
bind Scale <ButtonRelease-2> {
    tk::CancelRepeat
    tk::ScaleEndDrag %W
    tk::ScaleActivate %W %x %y
}
if {[tk windowingsystem] eq "win32"} {
    # On Windows do the same with button 3, as that is the right mouse button
    bind Scale <3>		[bind Scale <2>]
    bind Scale <B3-Motion>	[bind Scale <B2-Motion>]
    bind Scale <B3-Leave>	[bind Scale <B2-Leave>]
    bind Scale <B3-Enter>	[bind Scale <B2-Enter>]
    bind Scale <ButtonRelease-3> [bind Scale <ButtonRelease-2>]
}
bind Scale <Control-Button-1> {
bind Scale <Control-1> {
    tk::ScaleControlPress %W %x %y
}
bind Scale <<PrevLine>> {
    tk::ScaleIncrement %W up little noRepeat
}
bind Scale <<NextLine>> {
    tk::ScaleIncrement %W down little noRepeat
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
206
207
208
209
210
211
212

213












214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233


234
235
236

237
238
239
240
241

242
243
244
245
246
247
248







-

-
-
-
-
-
-
-
-
-
-
-
-




















-
-



-





-







# repeat -	Whether and how to auto-repeat the action:  "noRepeat"
#		means don't auto-repeat, "initial" means this is the
#		first action in an auto-repeat sequence, and "again"
#		means this is the second repetition or later.

proc ::tk::ScaleIncrement {w dir big repeat} {
    variable ::tk::Priv

    if {![winfo exists $w]} return

    # give the cancel callback a chance to be serviced if the execution time of
    # the -command script lasts longer than -repeatdelay
    set clockms [clock milliseconds]
    if {$repeat eq "again" &&
            [expr {$clockms - $Priv(clockms)}] > [expr {[$w cget -repeatinterval] * 1.1}]} {
        set Priv(clockms) $clockms
	set Priv(afterId) [after [$w cget -repeatinterval] \
		[list tk::ScaleIncrement $w $dir $big again]]
	return
    }

    if {$big eq "big"} {
	set inc [$w cget -bigincrement]
	if {$inc == 0} {
	    set inc [expr {abs([$w cget -to] - [$w cget -from])/10.0}]
	}
	if {$inc < [$w cget -resolution]} {
	    set inc [$w cget -resolution]
	}
    } else {
	set inc [$w cget -resolution]
    }
    if {([$w cget -from] > [$w cget -to]) ^ ($dir eq "up")} {
        if {$inc > 0} {
            set inc [expr {-$inc}]
        }
    } else {
        if {$inc < 0} {
            set inc [expr {-$inc}]
        }
    }
    # this will run the -command script (if any) during the redrawing
    # of the scale at idle time
    $w set [expr {[$w get] + $inc}]

    if {$repeat eq "again"} {
        set Priv(clockms) $clockms
	set Priv(afterId) [after [$w cget -repeatinterval] \
		[list tk::ScaleIncrement $w $dir $big again]]
    } elseif {$repeat eq "initial"} {
	set delay [$w cget -repeatdelay]
	if {$delay > 0} {
	    set Priv(clockms) $clockms
	    set Priv(afterId) [after $delay \
		    [list tk::ScaleIncrement $w $dir $big again]]
	}
    }
}

# ::tk::ScaleControlPress --

Deleted library/scaling.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232








































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# scaling.tcl --
#
# Contains scaling-related utility procedures.
#
# Copyright © 2022 Csaba Nemethi <[email protected]>

# ::tk::ScalingPct --
#
# Returns the display's "scaling percentage" (the display resolution expressed
# as a percentage of 96dpi), rounded to the nearest multiple of 25 that is at
# least 100.
#
# On X11 systems (but not on SDL systems that claim to be X11), the first call
# of the command also sets [tk scaling] and ::tk::fontScalingFactor to values
# extracted from the X11 configuration.
#
# The command is called during Tk initialization, from icons.tcl, when the
# latter is sourced by tk.tcl.

proc ::tk::ScalingPct {} {
    set pct [expr {[tk scaling] * 75}]

    variable doneScalingInitX11
    if {![info exists doneScalingInitX11]} {
	set pct [::tk::ScalingInitX11 $pct]
	set doneScalingInitX11 1
    }

    #
    # Save the value of pct rounded to the nearest multiple
    # of 25 that is at least 100, in the variable scalingPct.
    # See "man n tk_scalingPct" for use of ::tk::scalingPct.
    #
    variable scalingPct
    for {set scalingPct 100} {1} {incr scalingPct 25} {
	if {$pct < $scalingPct + 12.5} {
	    break
	}
    }

    return $scalingPct
}

proc ::tk::ScalingInitX11 {pct} {
    set onX11 [expr {[tk windowingsystem] eq "x11"}]
    set usingSDL [expr {[info exists ::tk::sdltk] && $::tk::sdltk}]

    if {$onX11 && !$usingSDL} {
	set origPct $pct

	#
	# Try to get the window scaling factor (1 or 2), partly
	# based on https://wiki.archlinux.org/title/HiDPI
	#
	set winScalingFactor 1
	variable fontScalingFactor 1		;# needed in the file ttk/fonts
	if {[catch {exec ps -e | grep xfce4-session}] == 0} {		;# Xfce
	    if {[catch {exec xfconf-query -c xsettings \
		 -p /Gdk/WindowScalingFactor} result] == 0} {
		set winScalingFactor $result
		if {$winScalingFactor >= 2} {
		    set fontScalingFactor 2
		}
	    }

	    #
	    # The DPI value can be set in the "Fonts" tab of the "Appearance"
	    # dialog or (on Linux Lite 5+) via the "HiDPI Settings" dialog.
	    #
	} elseif {[catch {exec ps -e | grep mate-session}] == 0} {	;# MATE
	    if {[catch {exec gsettings get org.mate.interface \
		 window-scaling-factor} result] == 0} {
		if {$result == 0} {			;# means: "Auto-detect"
		    #
		    # Try to get winScalingFactor from the cursor size
		    #
		    if {[catch {exec xrdb -query | grep Xcursor.size} result]
			== 0 &&
			[catch {exec gsettings get org.mate.peripherals-mouse \
			 cursor-size} defCursorSize] == 0} {
			set cursorSize [lindex $result 1]
			set winScalingFactor \
			    [expr {($cursorSize + $defCursorSize - 1) /
				   $defCursorSize}]
		    }
		} else {
		    set winScalingFactor $result
		}
	    }

	    #
	    # The DPI value can be set via the "Font Rendering Details"
	    # dialog, which can be opened using the "Details..." button
	    # in the "Fonts" tab of the "Appearance Preferences" dialog.
	    #
	} elseif {[catch {exec ps -e | grep gnome-session}] == 0 &&
		  [catch {exec gsettings get \
		   org.gnome.settings-daemon.plugins.xsettings overrides} \
		   result] == 0 &&
		  [set idx \
		   [string first "'Gdk/WindowScalingFactor'" $result]] >= 0} {
	    scan [string range $result $idx end] "%*s <%d>" winScalingFactor
	}

	#
	# Get the scaling percentage
	#
	if {$winScalingFactor >= 2} {
	    set pct 200
	} elseif {[catch {exec xrdb -query | grep Xft.dpi} result] == 0} {
	    #
	    # Derive the value of pct from that of the font DPI
	    #
	    set dpi [lindex $result 1]
	    set pct [expr {100.0 * $dpi / 96}]
	} elseif {[catch {exec ps -e | grep gnome-session}] == 0 &&
		  ![info exists ::env(WAYLAND_DISPLAY)] &&
		  [catch {exec xrandr | grep " connected"} result] == 0 &&
		  [catch {open $::env(HOME)/.config/monitors.xml} chan] == 0} {
	    #
	    # Update pct by scanning the file ~/.config/monitors.xml
	    #
	    ScanMonitorsFile $result $chan pct
	}

	if {($pct != 100) && ($pct != $origPct) && (![interp issafe])} {
	    #
	    # Set Tk's scaling factor according to $pct
	    #
	    tk scaling [expr {$pct / 75.0}]
	}
    }
    return $pct
}

# ::tk::ScaleNum --
#
# Scales an integer according to the display's current scaling percentage.
#
# Arguments:
#   num - An integer.

proc ::tk::ScaleNum num {
    return [expr {round($num * [tk scaling] * 0.75)}]
}

# ::tk::FontScalingFactor --
#
# Accessor command for variable ::tk::fontScalingFactor.

proc ::tk::FontScalingFactor {} {
    variable fontScalingFactor
    if {[info exists fontScalingFactor]} {
	return $fontScalingFactor
    } else {
	return 1
    }
}

# ::tk::ScanMonitorsFile --
#
# Updates the scaling percentage by scanning the file ~/.config/monitors.xml.
#
# Arguments:
#   xrandrResult - The output of 'xrandr | grep " connected"'.
#   chan -	   Returned from 'open ~/.config/monitors.xml'.
#   pctName -	   The name of a variable containing the scaling percentage.

proc ::tk::ScanMonitorsFile {xrandrResult chan pctName} {
    upvar $pctName pct

    #
    # Get the list of connected outputs reported by xrandr
    #
    set outputList {}
    foreach line [split $xrandrResult "\n"] {
	set idx [string first " " $line]
	set output [string range $line 0 [incr idx -1]]
	lappend outputList $output
    }
    set outputList [lsort $outputList]

    #
    # Get the content of the file ~/.config/monitors.xml
    #
    set str [read $chan]
    close $chan

    #
    # Run over the file's "configuration" sections
    #
    set idx 0
    while {[set idx2 [string first "<configuration>" $str $idx]] >= 0} {
	set idx2 [string first ">" $str $idx2]
	set idx [string first "</configuration>" $str $idx2]
	set config [string range $str [incr idx2] [incr idx -1]]

	#
	# Get the list of connectors within this configuration
	#
	set connectorList {}
	foreach {dummy connector} [regexp -all -inline \
		{<connector>([^<]+)</connector>} $config] {
	    lappend connectorList $connector
	}
	set connectorList [lsort $connectorList]

	#
	# If $outputList and $connectorList are identical then set the
	# variable pct to 100, 200, 300, 400, or 500, depending on the
	# max. scaling within this configuration, and exit the loop
	#
	if {$outputList eq $connectorList} {
	    set maxScaling 1.0
	    foreach {dummy scaling} [regexp -all -inline \
		    {<scale>([^<]+)</scale>} $config] {
		if {$scaling > $maxScaling} {
		    set maxScaling $scaling
		}
	    }

	    foreach n {4 3 2 1 0} {
		if {$maxScaling > $n} {
		    set pct [expr {($n + 1) * 100}]
		    break
		}
	    }

	    break
	}
    }
}

Changes to library/scrlbar.tcl.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# scrlbar.tcl --
#
# This file defines the default bindings for Tk scrollbar widgets.
# It also provides procedures that help in implementing the bindings.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-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.
#

#-------------------------------------------------------------------------
# The code below creates the default class bindings for scrollbars.
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63

64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90

91
92
93
94
95
96
97
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62

63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89

90
91
92
93
94
95
96
97







-
+

















-
+


-
+


-
+




















-
+


-
+








bind Scrollbar <Leave> {
    if {$tk_strictMotif && [info exists tk::Priv(activeBg)]} {
	%W configure -activebackground $tk::Priv(activeBg)
    }
    %W activate {}
}
bind Scrollbar <Button-1> {
bind Scrollbar <1> {
    tk::ScrollButtonDown %W %x %y
}
bind Scrollbar <B1-Motion> {
    tk::ScrollDrag %W %x %y
}
bind Scrollbar <B1-B2-Motion> {
    tk::ScrollDrag %W %x %y
}
bind Scrollbar <ButtonRelease-1> {
    tk::ScrollButtonUp %W %x %y
}
bind Scrollbar <B1-Leave> {
    # Prevents <Leave> binding from being invoked.
}
bind Scrollbar <B1-Enter> {
    # Prevents <Enter> binding from being invoked.
}
bind Scrollbar <Button-2> {
bind Scrollbar <2> {
    tk::ScrollButton2Down %W %x %y
}
bind Scrollbar <B1-Button-2> {
bind Scrollbar <B1-2> {
    # Do nothing, since button 1 is already down.
}
bind Scrollbar <B2-Button-1> {
bind Scrollbar <B2-1> {
    # Do nothing, since button 2 is already down.
}
bind Scrollbar <B2-Motion> {
    tk::ScrollDrag %W %x %y
}
bind Scrollbar <ButtonRelease-2> {
    tk::ScrollButtonUp %W %x %y
}
bind Scrollbar <B1-ButtonRelease-2> {
    # Do nothing:  B1 release will handle it.
}
bind Scrollbar <B2-ButtonRelease-1> {
    # Do nothing:  B2 release will handle it.
}
bind Scrollbar <B2-Leave> {
    # Prevents <Leave> binding from being invoked.
}
bind Scrollbar <B2-Enter> {
    # Prevents <Enter> binding from being invoked.
}
bind Scrollbar <Control-Button-1> {
bind Scrollbar <Control-1> {
    tk::ScrollTopBottom %W %x %y
}
bind Scrollbar <Control-Button-2> {
bind Scrollbar <Control-2> {
    tk::ScrollTopBottom %W %x %y
}

bind Scrollbar <<PrevLine>> {
    tk::ScrollByUnits %W v -1
}
bind Scrollbar <<NextLine>> {
124
125
126
127
128
129
130




131
132


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147



















148
149
150
151


152
153
154
155
156









157
158
159
160
161
162
163
124
125
126
127
128
129
130
131
132
133
134


135
136















137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155




156
157





158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173







+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+







bind Scrollbar <<LineStart>> {
    tk::ScrollToPos %W 0
}
bind Scrollbar <<LineEnd>> {
    tk::ScrollToPos %W 1
}
}
switch [tk windowingsystem] {
    "aqua" {
	bind Scrollbar <MouseWheel> {
	    tk::ScrollByUnits %W v [expr {- (%D)}]

bind Scrollbar <Enter> {+
	}
	bind Scrollbar <Option-MouseWheel> {
    set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0
}
bind Scrollbar <MouseWheel> {
    tk::ScrollByUnits %W vh %D -40.0
}
bind Scrollbar <Option-MouseWheel> {
    tk::ScrollByUnits %W vh %D -12.0
}
bind Scrollbar <Shift-MouseWheel> {
    tk::ScrollByUnits %W hv %D -40.0
}
bind Scrollbar <Shift-Option-MouseWheel> {
    tk::ScrollByUnits %W hv %D -12.0
}
bind Scrollbar <TouchpadScroll> {
	    tk::ScrollByUnits %W v [expr {-10 * (%D)}]
	}
	bind Scrollbar <Shift-MouseWheel> {
	    tk::ScrollByUnits %W h [expr {- (%D)}]
	}
	bind Scrollbar <Shift-Option-MouseWheel> {
	    tk::ScrollByUnits %W h [expr {-10 * (%D)}]
	}
    }
    "win32" {
	bind Scrollbar <MouseWheel> {
	    tk::ScrollByUnits %W v [expr {- (%D / 120) * 4}]
	}
	bind Scrollbar <Shift-MouseWheel> {
	    tk::ScrollByUnits %W h [expr {- (%D / 120) * 4}]
	}
    }
    "x11" {
	bind Scrollbar <MouseWheel> {
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    if {$deltaX != 0 && [%W cget -orient] eq "horizontal"} {
	tk::ScrollbarScrollByPixels %W h $deltaX
    }
	    tk::ScrollByUnits %W v [expr {- (%D /120 ) * 4}]
	}
    if {$deltaY != 0 && [%W cget -orient] eq "vertical"} {
	tk::ScrollbarScrollByPixels %W v $deltaY
    }
}

	bind Scrollbar <Shift-MouseWheel> {
	    tk::ScrollByUnits %W h [expr {- (%D /120 ) * 4}]
	}
	bind Scrollbar <4> {tk::ScrollByUnits %W v -5}
	bind Scrollbar <5> {tk::ScrollByUnits %W v 5}
	bind Scrollbar <Shift-4> {tk::ScrollByUnits %W h -5}
	bind Scrollbar <Shift-5> {tk::ScrollByUnits %W h 5}
    }
}
# tk::ScrollButtonDown --
# This procedure is invoked when a button is pressed in a scrollbar.
# It changes the way the scrollbar is displayed and takes actions
# depending on where the mouse is.
#
# Arguments:
# w -		The scrollbar widget.
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

366
367
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391

392
393

394
395
396
397
398
399
400
319
320
321
322
323
324
325









































326
327
328
329
330
331
332
333

334
335
336

337
338
339
340
341
342















343
344

345
346

347
348
349
350
351
352
353
354







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
+


-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+

-
+







	set delta [$w delta [expr {$x - $Priv(pressX)}] \
		[expr {$y - $Priv(pressY)}]]
	ScrollToPos $w [expr {$Priv(initPos) + $delta}]
    }
    set Priv(initPos) ""
}

# ::tk::ScrollbarScrollByPixels --
# This procedure tells the scrollbar's associated widget to scroll up
# or down by a given number of pixels.  It only works with scrollbars
# because it uses the delta command.
#
# Arguments:
# w -		The scrollbar widget.
# orient -	Which kind of scrollbar this applies to: "h" for
#		horizontal, "v" for vertical.
# amount -	How many pixels to scroll.

proc ::tk::ScrollbarScrollByPixels {w orient amount} {
    set cmd [$w cget -command]
    if {$cmd eq ""} {
	return
    }
    set xyview [lindex [split $cmd] end]
    if {$orient eq "v"} {
	if {$xyview eq "xview"} {
	    return
	}
    }
    if {$orient eq "h"} {
	if {$xyview eq "yview"} {
	    return
	}
    }

    # The code below works with both the current and old syntax for
    # the scrollbar get command.

    set info [$w get]
    if {[llength $info] == 2} {
	set first [lindex $info 0]
    } else {
	set first [lindex $info 2]
    }
    set pixels [expr {-$amount}]
    uplevel #0 $cmd moveto [expr $first + [$w delta $pixels $pixels]]
}

# ::tk::ScrollByUnits --
# This procedure tells the scrollbar's associated widget to scroll up
# or down by a given number of units.  It notifies the associated widget
# in different ways for old and new command syntaxes.
#
# Arguments:
# w -		The scrollbar widget.
# orient -	Which kinds of scrollbars this applies to:  "h" for
#		horizontal, "v" for vertical, "hv" or "vh" for both.
#		horizontal, "v" for vertical, "hv" for both.
# amount -	How many units to scroll:  typically 1 or -1.

proc ::tk::ScrollByUnits {w orient amount {factor 1.0}} {
proc ::tk::ScrollByUnits {w orient amount} {
    set cmd [$w cget -command]
    if {$cmd eq "" || ([string first \
	    [string index [$w cget -orient] 0] $orient] < 0)} {
	return
    }

    if {[string length $orient] == 2 && $factor != 1.0} {
	# Count both the <MouseWheel> and <Shift-MouseWheel>
	# events, and ignore the non-dominant ones

	variable ::tk::Priv
	set axis [expr {[string index $orient 0] eq "h" ? "x" : "y"}]
	incr Priv(${axis}Events)
	if {($Priv(xEvents) + $Priv(yEvents) > 10) &&
		($axis eq "x" && $Priv(xEvents) < $Priv(yEvents) ||
		 $axis eq "y" && $Priv(yEvents) < $Priv(xEvents))} {
	    return
	}
    }

    set info [$w get]
    if {[llength $info] == 2} {
	uplevel #0 $cmd scroll [expr {$amount/$factor}] units
	uplevel #0 $cmd scroll $amount units
    } else {
	uplevel #0 $cmd [expr {[lindex $info 2] + [expr {$amount/$factor}]}]
	uplevel #0 $cmd [expr {[lindex $info 2] + $amount}]
    }
}

# ::tk::ScrollByPages --
# This procedure tells the scrollbar's associated widget to scroll up
# or down by a given number of screenfuls.  It notifies the associated
# widget in different ways for old and new command syntaxes.

Changes to library/spinbox.tcl.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17






-
-
-
-
+
+
+
+







# spinbox.tcl --
#
# This file defines the default bindings for Tk spinbox widgets and provides
# procedures that help in implementing those bindings.  The spinbox builds
# off the entry widget, so it can reuse Entry bindings and procedures.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1999-2000 Jeffrey Hobbs
# Copyright © 2000 Ajuba Solutions
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1999-2000 Jeffrey Hobbs
# Copyright (c) 2000 Ajuba Solutions
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#-------------------------------------------------------------------------
# Elements of tk::Priv that are used in this file:
75
76
77
78
79
80
81
82

83
84
85
86
87
88

89
90
91
92
93

94
95
96
97
98

99
100
101
102

103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132

133
134
135

136
137
138

139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
75
76
77
78
79
80
81

82
83
84
85
86
87

88
89
90
91
92

93
94
95
96
97

98
99
100
101

102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131

132
133
134

135
136
137

138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+





-
+




-
+




-
+



-
+



-
+













-
+











-
+


-
+


-
+



-
+













-
+







bind Spinbox <<TraverseIn>> {
    %W selection range 0 end
    %W icursor end
}

# Standard Motif bindings:

bind Spinbox <Button-1> {
bind Spinbox <1> {
    ::tk::spinbox::ButtonDown %W %x %y
}
bind Spinbox <B1-Motion> {
    ::tk::spinbox::Motion %W %x %y
}
bind Spinbox <Double-Button-1> {
bind Spinbox <Double-1> {
    ::tk::spinbox::ArrowPress %W %x %y
    set tk::Priv(selectMode) word
    ::tk::spinbox::MouseSelect %W %x sel.first
}
bind Spinbox <Triple-Button-1> {
bind Spinbox <Triple-1> {
    ::tk::spinbox::ArrowPress %W %x %y
    set tk::Priv(selectMode) line
    ::tk::spinbox::MouseSelect %W %x 0
}
bind Spinbox <Shift-Button-1> {
bind Spinbox <Shift-1> {
    set tk::Priv(selectMode) char
    %W selection adjust @%x
}
bind Spinbox <Double-Shift-Button-1> {
bind Spinbox <Double-Shift-1> {
    set tk::Priv(selectMode) word
    ::tk::spinbox::MouseSelect %W %x
}
bind Spinbox <Triple-Shift-Button-1> {
bind Spinbox <Triple-Shift-1> {
    set tk::Priv(selectMode) line
    ::tk::spinbox::MouseSelect %W %x
}
bind Spinbox <B1-Leave> {
    set tk::Priv(x) %x
    ::tk::spinbox::AutoScan %W
}
bind Spinbox <B1-Enter> {
    tk::CancelRepeat
}
bind Spinbox <ButtonRelease-1> {
    ::tk::spinbox::ButtonUp %W %x %y
}
bind Spinbox <Control-Button-1> {
bind Spinbox <Control-1> {
    %W icursor @%x
}

bind Spinbox <<PrevLine>> {
    %W invoke buttonup
}
bind Spinbox <<NextLine>> {
    %W invoke buttondown
}

bind Spinbox <<PrevChar>> {
    ::tk::EntrySetCursor %W [tk::EntryPreviousChar %W insert]
    ::tk::EntrySetCursor %W [expr {[%W index insert] - 1}]
}
bind Spinbox <<NextChar>> {
    ::tk::EntrySetCursor %W [tk::EntryNextChar %W insert]
    ::tk::EntrySetCursor %W [expr {[%W index insert] + 1}]
}
bind Spinbox <<SelectPrevChar>> {
    ::tk::EntryKeySelect %W [tk::EntryPreviousChar %W insert]
    ::tk::EntryKeySelect %W [expr {[%W index insert] - 1}]
    ::tk::EntrySeeInsert %W
}
bind Spinbox <<SelectNextChar>> {
    ::tk::EntryKeySelect %W [tk::EntryNextChar %W insert]
    ::tk::EntryKeySelect %W [expr {[%W index insert] + 1}]
    ::tk::EntrySeeInsert %W
}
bind Spinbox <<PrevWord>> {
    ::tk::EntrySetCursor %W [::tk::EntryPreviousWord %W insert]
}
bind Spinbox <<NextWord>> {
    ::tk::EntrySetCursor %W [::tk::EntryNextWord %W insert]
}
bind Spinbox <<SelectPrevWord>> {
    ::tk::EntryKeySelect %W [::tk::EntryPreviousWord %W insert]
    ::tk::EntrySeeInsert %W
}
bind Spinbox <<SelectNextWord>> {
    ::tk::EntryKeySelect %W [::tk::EntrySelectNextWord %W insert]
    ::tk::EntryKeySelect %W [::tk::EntryNextWord %W insert]
    ::tk::EntrySeeInsert %W
}
bind Spinbox <<LineStart>> {
    ::tk::EntrySetCursor %W 0
}
bind Spinbox <<SelectLineStart>> {
    ::tk::EntryKeySelect %W 0
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
171
172
173
174
175
176
177

178

179
180
181
182
183
184
185







-
+
-







    ::tk::EntrySeeInsert %W
}

bind Spinbox <Delete> {
    if {[%W selection present]} {
	%W delete sel.first sel.last
    } else {
	%W delete [tk::startOfCluster [%W get] [%W index insert]] \
	%W delete insert
		[tk::endOfCluster [%W get] [%W index insert]]
    }
}
bind Spinbox <BackSpace> {
    ::tk::EntryBackspace %W
}

bind Spinbox <Control-space> {
197
198
199
200
201
202
203
204

205
206
207
208

209
210

211
212
213
214
215



216
217
218
219
220
221

222

223

224
225
226
227
228
229
230
196
197
198
199
200
201
202

203
204
205
206

207
208

209
210
211



212
213
214
215
216
217
218
219
220
221

222

223
224
225
226
227
228
229
230







-
+



-
+

-
+


-
-
-
+
+
+






+
-
+
-
+







}
bind Spinbox <<SelectAll>> {
    %W selection range 0 end
}
bind Spinbox <<SelectNone>> {
    %W selection clear
}
bind Spinbox <Key> {
bind Spinbox <KeyPress> {
    ::tk::EntryInsert %W %A
}

# Ignore all Alt, Meta, Control, Command, and Fn keypresses unless explicitly bound.
# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
# Otherwise, if a widget binding for one of these is defined, the
# <Key> class binding will also fire and insert the character,
# <KeyPress> class binding will also fire and insert the character,
# which is wrong.  Ditto for Escape, Return, and Tab.

bind Spinbox <Alt-Key> {# nothing}
bind Spinbox <Meta-Key> {# nothing}
bind Spinbox <Control-Key> {# nothing}
bind Spinbox <Alt-KeyPress> {# nothing}
bind Spinbox <Meta-KeyPress> {# nothing}
bind Spinbox <Control-KeyPress> {# nothing}
bind Spinbox <Escape> {# nothing}
bind Spinbox <Return> {# nothing}
bind Spinbox <KP_Enter> {# nothing}
bind Spinbox <Tab> {# nothing}
bind Spinbox <Prior> {# nothing}
bind Spinbox <Next> {# nothing}
if {[tk windowingsystem] eq "aqua"} {
bind Spinbox <Command-Key> {# nothing}
    bind Spinbox <Command-KeyPress> {# nothing}
bind Spinbox <Fn-Key> {# nothing}
}

# On Windows, paste is done using Shift-Insert.  Shift-Insert already
# generates the <<Paste>> event, so we don't need to do anything here.
if {[tk windowingsystem] ne "win32"} {
    bind Spinbox <Insert> {
	catch {::tk::EntryInsert %W [::tk::GetSelection %W PRIMARY]}
    }
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290







-
+







    if {!$tk_strictMotif} {
	%W delete [::tk::EntryPreviousWord %W insert] insert
    }
}

# A few additional bindings of my own.

bind Spinbox <Button-2> {
bind Spinbox <2> {
    if {!$tk_strictMotif} {
	::tk::EntryScanMark %W %x
    }
}
bind Spinbox <B2-Motion> {
    if {!$tk_strictMotif} {
	::tk::EntryScanDrag %W %x
465
466
467
468
469
470
471
472
473


474
475
476


477
478
479
480
481
482
483
465
466
467
468
469
470
471


472
473
474


475
476
477
478
479
480
481
482
483







-
-
+
+

-
-
+
+







		} else {
		    $w selection clear
		}
	    }
	}
	word {
	    if {$cur < [$w index anchor]} {
		set before [tk::wordBreakBefore [$w get] $cur]
		set after [tk::wordBreakAfter [$w get] $anchor-1]
		set before [tcl_wordBreakBefore [$w get] $cur]
		set after [tcl_wordBreakAfter [$w get] [expr {$anchor-1}]]
	    } else {
		set before [tk::wordBreakBefore [$w get] $anchor]
		set after [tk::wordBreakAfter [$w get] $cur-1]
		set before [tcl_wordBreakBefore [$w get] $anchor]
		set after [tcl_wordBreakAfter [$w get] [expr {$cur - 1}]]
	    }
	    if {$before < 0} {
		set before 0
	    }
	    if {$after < 0} {
		set after end
	    }
572
573
574
575
576
577
578
579

580
572
573
574
575
576
577
578

579
580







-
+

# a spinbox has no -show option to obscure contents.
#
# Arguments:
# w -         The spinbox window from which the text to get

proc ::tk::spinbox::GetSelection {w} {
    return [string range [$w get] [$w index sel.first] \
	    [$w index sel.last]-1]
	    [expr {[$w index sel.last] - 1}]]
}

Deleted library/systray.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482


































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# systray.tcl --

# This file defines the 'tk systray' command for icon display and manipulation
# in the system tray on X11, Windows, and macOS, and the 'tk sysnotify' command
# for system alerts on each platform. It implements an abstraction layer that
# presents a consistent API across the three platforms.

# Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
# Copyright © 2020 Eric Boudaillier.
# Copyright © 2020 Francois Vogel.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

# Pure-Tcl system tooltip window for use with system tray icon if native
# implementation not available.

namespace eval ::tk::systray {
    variable _created 0
    variable _options {-image "" -text "" -button1 "" -button3 ""}
    variable _current {}
    variable _ico

    proc _balloon {w help} {
	bind $w <Any-Enter> "after 100 [list [namespace current]::_balloon_show %W [list $help] cursor]"
	bind $w <Any-Leave> "destroy %W._balloon"
    }

    proc _balloon_show {w msg i} {
	if {![winfo exists $w]} { return }

	# Use string match to allow that the help will be shown when
	# the pointer is in any child of the desired widget
	if {([winfo class $w] ne "Menu") && ![string match $w* [eval [list winfo containing] \
								    [winfo pointerxy $w]]]} {
	    return
	}

	set top $w._balloon
	catch {destroy $top}
	toplevel $top -bg black -bd 1
	wm overrideredirect $top 1
	if {[tk windowingsystem] eq "aqua"}  {
	    ::tk::unsupported::MacWindowStyle style $top help none
	}
	pack [message $top._txt -aspect 10000 -text $msg]

	update idletasks
	set screenw [winfo screenwidth $w]
	set screenh [winfo screenheight $w]
	set reqw [winfo reqwidth $top]
	set reqh [winfo reqheight $top]
	# When adjusting for being on the screen boundary, check that we are
	# near the "edge" already, as Tk handles multiple monitors oddly
	if {$i eq "cursor"} {
	    set y [expr {[winfo pointery $w]+20}]
	    if {($y < $screenh) && ($y+$reqh) > $screenh} {
		set y [expr {[winfo pointery $w]-$reqh-5}]
	    }
	} elseif {$i ne ""} {
	    set y [expr {[winfo rooty $w]+[winfo vrooty $w]+[$w yposition $i]+25}]
	    if {($y < $screenh) && ($y+$reqh) > $screenh} {
		# show above if we would be offscreen
		set y [expr {[winfo rooty $w]+[$w yposition $i]-$reqh-5}]
	    }
	} else {
	    set y [expr {[winfo rooty $w]+[winfo vrooty $w]+[winfo height $w]+5}]
	    if {($y < $screenh) && ($y+$reqh) > $screenh} {
		# show above if we would be offscreen
		set y [expr {[winfo rooty $w]-$reqh-5}]
	    }
	}
	if {$i eq "cursor"} {
	    set x [winfo pointerx $w]
	} else {
	    set x [expr {[winfo rootx $w]+[winfo vrootx $w]+ ([winfo width $w]-$reqw)/2}]
	}
	# only readjust when we would appear right on the screen edge
	if {$x<0 && ($x+$reqw)>0} {
	    set x 0
	} elseif {($x < $screenw) && ($x+$reqw) > $screenw} {
	    set x [expr {$screenw-$reqw}]
	}
	if {[tk windowingsystem] eq "aqua"} {
	    set focus [focus]
	}

	wm geometry $top +$x+$y
	wm deiconify $top
	raise $top

	if {[tk windowingsystem] eq "aqua" && $focus ne ""} {
	    # Aqua's help window steals focus on display
	    after idle [list focus -force $focus]
	}
    }

    proc _win_callback {msg} {
	variable _current
	# The API at the Tk level does not feature bindings to double  clicks. Whatever
	# the speed the user clicks with, he expects the single click binding to fire.
	# Therefore we need to bind to both WM_*BUTTONDOWN and to WM_*BUTTONDBLCLK.
	switch -exact -- $msg {
	    WM_LBUTTONDOWN - WM_LBUTTONDBLCLK {
		uplevel #0 [dict get $_current -button1]
	    }
	    WM_RBUTTONDOWN - WM_RBUTTONDBLCLK {
		uplevel #0 [dict get $_current -button3]
	    }
	}
    }

    namespace export create configure destroy exists
    namespace ensemble create
}


# Pure-Tcl system notification window for use if native implementation not available.
# This is supposed to happen only on X11 when libnotify is not present.
namespace eval ::tk::sysnotify:: {
    # These defaults mimic the default behaviour of gnome and xfce notifications.
    # These are hardcoded defaults.
    variable defaults {
	padX            3
	padY            3
	background      gray15
	foreground      white
	delay           10000
	alpha           0.85
    }
    # These options are meant to be "public". The user could tinker with
    # these values to adjust the system notification appearance/behaviour.
    option add *Sysnotify.padX       [dict get $defaults padX]
    option add *Sysnotify.padY       [dict get $defaults padY]
    option add *Sysnotify.background [dict get $defaults background]
    option add *Sysnotify.foreground [dict get $defaults foreground]
    option add *Sysnotify.delay      [dict get $defaults delay]
    option add *Sysnotify.alpha      [dict get $defaults alpha]

    proc _notifywindow {title msg} {
	variable defaults

	# cleanup any previous notify window and create a new one
	set w ._notify
	_notifyDestroy $w
	toplevel $w -class Sysnotify

	# read the option database to check out whether the user has set
	# some options; fall back to our hardcoded defaults otherwise
	dict for {option value} [dict remove $defaults alpha] {
	    set $option [option get $w $option ""]
	    if {[set $option] eq ""} {
		set $option $value
	    }
	}

	set xpos [tk::ScaleNum 16]
	set ypos [tk::ScaleNum 48]
	# position from the "ne" corner
	wm geometry $w -$xpos+$ypos
	wm overrideredirect $w true

	# internal options
	option add *Sysnotify.Label.anchor     w
	option add *Sysnotify.Label.justify    left
	option add *Sysnotify.Label.wrapLength [expr {[winfo screenwidth .] / 4}]
	foreach option {padX padY foreground background} {
	    option add *Sysnotify.Label.$option [set $option]
	}
	set icon ::tk::icons::information
	set width [expr {[image width $icon] + 2 * $padX}]
	set height [expr {[image height $icon] + 2 * $padY}]
	label $w.icon -image $icon -width $width -height $height -anchor c
	label $w.title -text $title -font TkHeadingFont
	label $w.message -text [_filterMarkup $msg] -font TkTooltipFont

	grid $w.icon $w.title -sticky news
	grid ^       $w.message -sticky news

	bind Sysnotify <Map> [namespace code {
	    # set the wm attribute here; it is ignored if set
	    # before the window is mapped
	    wm attributes %W -alpha 0.0
	    if {[wm attributes %W -alpha] == 0.0} {
		_fadeIn %W
	    }
	}]
	bind Sysnotify <Enter> [namespace code {_onEnter %W}]
	bind Sysnotify <Leave> [namespace code {_onLeave %W}]
	bind $w <Button-1> [namespace code [list _notifyDestroy $w]]
	after $delay [namespace code [list _fadeOut $w]]
	return
    }

    # Fade the window into view.
    proc _fadeIn {w} {
	variable defaults
        if {![winfo exists $w]} {return}
	if {[set alpha  [option get $w alpha ""]] eq ""} {
	    set alpha [dict get $defaults alpha]
	}
	raise $w
	set before [wm attributes $w -alpha]
	set new    [expr { min($alpha, $before + 0.10) }]
	wm attributes $w -alpha $new
	set after  [wm attributes $w -alpha]
	if {($before == 1.0) || ($before == $after)} {
	    # not supported or we're done
	    return
	}
	after 40 [namespace code [list _fadeIn $w]]
    }

    # Fade out and destroy window.
    proc _fadeOut {w} {
        if {![winfo exists $w]} {return}
	set before [wm attributes $w -alpha]
	set new    [expr { $before - 0.02 }]
	wm attributes $w -alpha $new
	set after  [wm attributes $w -alpha]
	if {($after == 1.0) || ($before == $after)} {
	    _notifyDestroy $w
	    return
	}
	after 40 [namespace code [list _fadeOut $w]]
    }

    proc _notifyDestroy {w} {
	# cancel any pending fade in or fade out
	_cancelFading $w
	destroy $w
    }

    proc _onEnter {w} {
	wm attributes $w -alpha 1.0
	_cancelFading $w
    }

    proc _onLeave {w} {
	variable defaults
	if {[set alpha [option get $w alpha ""]] eq ""} {
	    set alpha [dict get $defaults alpha]
	}
	if {[set delay [option get $w delay ""]] eq ""} {
	    set delay [dict get $defaults delay]
	}
	wm attributes $w -alpha $alpha
	after $delay [namespace code [list _fadeOut $w]]
    }

    proc _cancelFading {w} {
	after cancel [namespace code [list _fadeOut $w]]
	after cancel [namespace code [list _fadeIn $w]]
    }

    # The Desktop Notifications Specification allow for some markup
    # in the message to display. It also specifies
    # "Notification servers that do not support these tags should
    # filter them out"
    # See https://specifications.freedesktop.org/notification-spec/latest/ar01s04.html
    # We don't event try to render those properly
    proc _filterMarkup {txt} {
	# remove fixed tags
	set maplist {<b> "" </b> "" <i> "" </i> "" <u> "" </u> "" </a> ""}
	set txt [string map $maplist $txt]
	# remove <img> tags leaving (possible) alt text
	set txt [regsub -- {<img *src="[^"]*" *(alt="([^"]*)")? */?>} $txt {\2}]
	# remove <a href=""> variable tag
	set txt [regsub -- {<a[^>]*>} $txt {}]
	return $txt
    }
}


# tk systray --
# This procedure creates an icon display in the platform-specific system tray.
#
# Subcommands:
#
#     create - create systray icon.
#         Arguments:
#             -image - Tk image to display.
#             -text - string to display in tooltip over image.
#             -button1 - Tcl proc to invoke on <Button-1> event.
#             -button3 - Tcl proc to invoke on <Button-3> event.
#
#     configure - change one of the systray properties.
#         Arguments (Any or all can be called):
#             -image - Tk image to update.
#             -text - string to update.
#             -button1 - Tcl proc to change for <Button-1> event.
#             -button3  - Tcl proc to change for <Button-3> event.
#
#     destroy - destroy systray icon.
#         Arguments:
#             none.
proc ::tk::systray::create {args} {
    variable _created
    variable _options
    variable _current
    variable _ico

    if {$_created} {
	return -code error -errorcode {TK SYSTRAY CREATE} "only one system tray icon supported per interpeter"
    }
    _check_options $args 0
    if {![dict exists $args -image]} {
	return -code error -errorcode {TK SYSTRAY CREATE} "missing required option \"-image\""
    }
    set values [dict merge $_options $args]
    try {
	switch -- [tk windowingsystem] {
	    "win32" {
		set _ico [_systray add -image [dict get $values -image] \
			-text [dict get $values -text] \
			-callback [list ::tk::systray::_win_callback %m]]
	    }
	    "x11" {
		_systray ._tray -image [dict get $values -image] -visible true
		_balloon ._tray [dict get $values -text]
		bind ._tray <Button-1> [dict get $values -button1]
		bind ._tray <Button-3> [dict get $values -button3]
	    }
	    "aqua" {
		_systray create [dict get $values -image] [dict get $values -text] \
			[dict get $values -button1] [dict get $values -button3]
	    }
	}
    } on ok {} {
	set _current $values
	set _created 1
	return
    } on error {msg opts} {
	return -code error -errorcode [dict get $opts -errorcode] $msg
    }
}

# Modify the systray icon.
proc ::tk::systray::configure {args} {
    variable _created
    variable _options
    variable _current
    variable _ico

    if {!$_created} {
	return -code error -errorcode {TK SYSTRAY CREATE} "systray not created"
    }
    _check_options $args 1
    if {[llength $args] == 0} {
	return $_current
    } elseif {[llength $args] == 1} {
	return [dict get $_current [lindex $args 0]]
    }
    set values [dict merge $_current $args]
    try {
	switch -- [tk windowingsystem] {
	    "win32" {
		if {[dict exists $args -image]} {
		    _systray modify $_ico -image [dict get $args -image]
		}
		if {[dict exists $args -text]} {
		    _systray modify $_ico -text [dict get $args -text]
		}
	    }
	    "x11" {
		if {[dict exists $args -image]} {
		    ._tray configure -image [dict get $args -image]
		}
		if {[dict exists $args -text]} {
		    _balloon ._tray [dict get $args -text]
		}
		if {[dict exists $args -button1]} {
		    bind ._tray <Button-1> [dict get $args -button1]
		}
		if {[dict exists $args -button3]} {
		    bind ._tray <Button-3> [dict get $args -button3]
		}
	    }
	    "aqua" {
		foreach {key opt} {image -image text \
			-text b1_callback -button1 b3_callback -button3} {
		    if {[dict exists $args $opt]} {
			_systray modify $key [dict get $args $opt]
		    }
		}
	    }
	}
    } on ok {} {
	set _current $values
	return
    } on error {msg opts} {
	return -code error -errorcode [dict get $opts -errorcode] $msg
    }
}

# Remove the systray icon.
proc ::tk::systray::destroy {} {
    variable _created
    variable _current
    variable _ico

    if {!$_created} {
	return -code error -errorcode {TK SYSTRAY DESTROY} "systray not created"
    }
    switch -- [tk windowingsystem] {
	"win32" {
	    _systray delete $_ico
	    set _ico ""
	}
	"x11" {
	    ::destroy ._tray
	}
	"aqua" {
	    _systray destroy
	}
    }
    set _created 0
    set _current {}
    return
}

# Check systray icon existence.
proc tk::systray::exists {} {
    variable _created
    return $_created
}

# Check systray options
proc ::tk::systray::_check_options {argsList singleOk} {
    variable _options

    set len [llength $argsList]
    while {[llength $argsList] > 0} {
        set opt [lindex $argsList 0]
        if {![dict exists $_options $opt]} {
            tailcall return -code error -errorcode {TK SYSTRAY OPTION} \
		"unknown option \"$opt\": must be -image, -text, -button1 or -button3"
        }
        if {[llength $argsList] == 1 && !($len == 1 && $singleOk)} {
            tailcall return -code error -errorcode {TK SYSTRAY OPTION} \
		"missing value for option \"$opt\""
        }
        set argsList [lrange $argsList 2 end]
    }
}

# tk sysnotify --
# This procedure implements a platform-specific system notification alert.
#
#   Arguments:
#       title - main text of alert.
#       message - body text of alert.

proc ::tk::sysnotify::sysnotify {title message} {

    switch -- [tk windowingsystem] {
	"win32" {
	    if {!$::tk::systray::_created} {
		error "must create a system tray icon with the \"tk systray\" command first"
	    }
	    _sysnotify notify $::tk::systray::_ico $title $message
	}
	"x11" {
	    if {[info commands ::tk::sysnotify::_sysnotify] eq ""} {
		_notifywindow $title $message
	    } else {
		_sysnotify $title $message
	    }
	}
	"aqua" {
	    _sysnotify $title $message
	}
    }
    return
}

#Add these commands to the tk command ensemble: tk systray, tk sysnotify
#Thanks to Christian Gollwitzer for the guidance here
namespace ensemble configure tk -map \
    [dict merge [namespace ensemble configure tk -map] \
        {systray ::tk::systray sysnotify ::tk::sysnotify::sysnotify}]

Changes to library/tclIndex.

118
119
120
121
122
123
124



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146




147
148
149
150
151
152
153







+
+
+



















-
-
-
-







set auto_index(::tk::SaveGrabInfo) [list source [file join $dir menu.tcl]]
set auto_index(::tk::RestoreOldGrab) [list source [file join $dir menu.tcl]]
set auto_index(tk_menuSetFocus) [list source [file join $dir menu.tcl]]
set auto_index(::tk::GenerateMenuSelect) [list source [file join $dir menu.tcl]]
set auto_index(tk_popup) [list source [file join $dir menu.tcl]]
set auto_index(::tk::ensure_psenc_is_loaded) [list source [file join $dir mkpsenc.tcl]]
set auto_index(::tk::MessageBox) [list source [file join $dir msgbox.tcl]]
set auto_index(tk_menuBar) [list source [file join $dir obsolete.tcl]]
set auto_index(tk_bindForTraversal) [list source [file join $dir obsolete.tcl]]
set auto_index(::tk::classic::restore) [list source [file join $dir obsolete.tcl]]
set auto_index(tk_optionMenu) [list source [file join $dir optMenu.tcl]]
set auto_index(tk_setPalette) [list source [file join $dir palette.tcl]]
set auto_index(::tk::RecolorTree) [list source [file join $dir palette.tcl]]
set auto_index(::tk::Darken) [list source [file join $dir palette.tcl]]
set auto_index(tk_bisque) [list source [file join $dir palette.tcl]]
set auto_index(::safe::tkInterpInit) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::loadTk) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::TkInit) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::allowTk) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::disallowTk) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::tkDelete) [list source [file join $dir safetk.tcl]]
set auto_index(::safe::tkTopLevel) [list source [file join $dir safetk.tcl]]
set auto_index(::tk::ScaleActivate) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleButtonDown) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleDrag) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleEndDrag) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleIncrement) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleControlPress) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScaleButton2Down) [list source [file join $dir scale.tcl]]
set auto_index(::tk::ScalingPct) [list source [file join $dir scaling.tcl]]
set auto_index(::tk::ScaleNum) [list source [file join $dir scaling.tcl]]
set auto_index(::tk::FontScalingFactor) [list source [file join $dir scaling.tcl]]
set auto_index(::tk::ScanMonitorsFile) [list source [file join $dir scaling.tcl]]
set auto_index(::tk::ScrollButtonDown) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollButtonUp) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollSelect) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollStartDrag) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollDrag) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollEndDrag) [list source [file join $dir scrlbar.tcl]]
set auto_index(::tk::ScrollByUnits) [list source [file join $dir scrlbar.tcl]]
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
195
196
197
198
199
200
201

202
203
204
205
206
207
208







-







set auto_index(::tk::TextPrevPos) [list source [file join $dir text.tcl]]
set auto_index(::tk::PlaceWindow) [list source [file join $dir tk.tcl]]
set auto_index(::tk::SetFocusGrab) [list source [file join $dir tk.tcl]]
set auto_index(::tk::RestoreFocusGrab) [list source [file join $dir tk.tcl]]
set auto_index(::tk::ScreenChanged) [list source [file join $dir tk.tcl]]
set auto_index(::tk::EventMotifBindings) [list source [file join $dir tk.tcl]]
set auto_index(::tk::CancelRepeat) [list source [file join $dir tk.tcl]]
set auto_index(::tk::MouseWheel) [list source [file join $dir tk.tcl]]
set auto_index(::tk::TabToWindow) [list source [file join $dir tk.tcl]]
set auto_index(::tk::dialog::file::) [list source [file join $dir tkfbox.tcl]]
set auto_index(::tk::dialog::file::Config) [list source [file join $dir tkfbox.tcl]]
set auto_index(::tk::dialog::file::Create) [list source [file join $dir tkfbox.tcl]]
set auto_index(::tk::dialog::file::SetSelectMode) [list source [file join $dir tkfbox.tcl]]
set auto_index(::tk::dialog::file::UpdateWhenIdle) [list source [file join $dir tkfbox.tcl]]
set auto_index(::tk::dialog::file::Update) [list source [file join $dir tkfbox.tcl]]
245
246
247
248
249
250
251


252
243
244
245
246
247
248
249
250
251
252







+
+

set auto_index(::tk::MotifFDialog_FilterCmd) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::MotifFDialog_CancelCmd) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::ListBoxKeyAccel_Set) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::ListBoxKeyAccel_Unset) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::ListBoxKeyAccel_Key) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::ListBoxKeyAccel_Goto) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::ListBoxKeyAccel_Reset) [list source [file join $dir xmfbox.tcl]]
set auto_index(::tk::unsupported::ExposePrivateCommand) [list source [file join $dir unsupported.tcl]]
set auto_index(::tk::unsupported::ExposePrivateVariable) [list source [file join $dir unsupported.tcl]]
set auto_index(::tk::fontchooser) [list source [file join $dir fontchooser.tcl]]

Changes to library/tearoff.tcl.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# tearoff.tcl --
#
# This file contains procedures that implement tear-off menus.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 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.
#

# ::tk::TearoffMenu --
# Given the name of a menu, this procedure creates a torn-off menu
27
28
29
30
31
32
33
34

35
36
37

38
39
40
41
42

43
44
45
46
47
48
49
27
28
29
30
31
32
33

34
35
36

37
38
39
40
41

42
43
44
45
46
47
48
49







-
+


-
+




-
+







    # the parent of the new menu.  This guarantees that the torn off
    # menu will be on the same screen as the original menu.  By making
    # it a child of the ancestor, rather than a child of the menu, it
    # can continue to live even if the menu is deleted;  it will go
    # away when the toplevel goes away.

    if {$x == 0} {
	set x [winfo rootx $w]
    	set x [winfo rootx $w]
    }
    if {$y == 0} {
	set y [winfo rooty $w]
    	set y [winfo rooty $w]
	if {[tk windowingsystem] eq "aqua"} {
	    # Shift by height of tearoff entry minus height of window titlebar
	    catch {incr y [expr {[$w yposition 1] - 16}]}
	    # Avoid the native menu bar which sits on top of everything.
	    if {$y < 22} {set y 22}
	    if {$y < 22} { set y 22 }
	}
    }

    set parent [winfo parent $w]
    while {[winfo toplevel $parent] ne $parent \
	    || [winfo class $parent] eq "Menu"} {
	set parent [winfo parent $parent]
62
63
64
65
66
67
68
69

70
71

72
73

74
75
76

77
78
79
80
81
82
83
84
85
86





87
88
89
90
91
92
93
62
63
64
65
66
67
68

69
70

71
72

73
74
75

76
77
78
79
80
81





82
83
84
85
86
87
88
89
90
91
92
93







-
+

-
+

-
+


-
+





-
-
-
-
-
+
+
+
+
+








    # Pick a title for the new menu by looking at the parent of the
    # original: if the parent is a menu, then use the text of the active
    # entry.  If it's a menubutton then use its text.

    set parent [winfo parent $w]
    if {[$menu cget -title] ne ""} {
	wm title $menu [$menu cget -title]
    	wm title $menu [$menu cget -title]
    } else {
	switch -- [winfo class $parent] {
    	switch -- [winfo class $parent] {
	    Menubutton {
		wm title $menu [$parent cget -text]
	    	wm title $menu [$parent cget -text]
	    }
	    Menu {
		wm title $menu [$parent entrycget active -label]
	    	wm title $menu [$parent entrycget active -label]
	    }
	}
    }

    if {[tk windowingsystem] eq "win32"} {
	# [Bug 3181181]: Find the toplevel window for the menu
	set parent [winfo toplevel $parent]
	while {[winfo class $parent] eq "Menu"} {
	    set parent [winfo toplevel [winfo parent $parent]]
	}
        # [Bug 3181181]: Find the toplevel window for the menu
        set parent [winfo toplevel $parent]
        while {[winfo class $parent] eq "Menu"} {
            set parent [winfo toplevel [winfo parent $parent]]
        }
	wm transient $menu [winfo toplevel $parent]
	wm attributes $menu -toolwindow 1
    }

    $menu post $x $y

    if {[winfo exists $menu] == 0} {
130
131
132
133
134
135
136
137
138
139




140
141
142

143
144
145
146
147
148
149

150
151

152
153
154
155




























130
131
132
133
134
135
136



137
138
139
140

141

142
143
144
145
146
147
148

149
150
151
152




153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180







-
-
-
+
+
+
+
-

-
+






-
+


+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
	}
	if {[lindex $option 0] eq "-type"} {
	    continue
	}
	lappend cmd [lindex $option 0] [lindex $option 4]
    }
    eval $cmd

    # Copy the meny entries, if any

    set last [$src index last]
    if {$last eq "none"} {
	return
    }
    set last [$src index last]
    for {set i [$src cget -tearoff]} {$i <= $last} {incr i} {
	set cmd [list $dst add [$src type $i] [$src id $i]]
	set cmd [list $dst add [$src type $i]]
	foreach option [$src entryconfigure $i]  {
	    lappend cmd [lindex $option 0] [lindex $option 4]
	}
	eval $cmd
    }

    # Duplicate the binding tags from the source menu, replacing src with dst
    # Duplicate the binding tags and bindings from the source menu.

    set tags [bindtags $src]
    set srcLen [string length $src]
    set x [lsearch -exact $tags $src]
    if {$x >= 0} {lset tags $x $dst}
    bindtags $dst $tags
}

    # Copy tags to x, replacing each substring of src with dst.

    while {[set index [string first $src $tags]] != -1} {
	append x [string range $tags 0 [expr {$index - 1}]]$dst
	set tags [string range $tags [expr {$index + $srcLen}] end]
    }
    append x $tags

    bindtags $dst $x

    foreach event [bind $src] {
	unset x
	set script [bind $src $event]
	set eventLen [string length $event]

	# Copy script to x, replacing each substring of event with dst.

	while {[set index [string first $event $script]] != -1} {
	    append x [string range $script 0 [expr {$index - 1}]]
	    append x $dst
	    set script [string range $script [expr {$index + $eventLen}] end]
	}
	append x $script

	bind $dst $event $x
    }
}

Changes to library/text.tcl.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







# text.tcl --
#
# This file defines the default bindings for Tk text widgets and provides
# procedures that help in implementing the bindings.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998 Scriptics Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#-------------------------------------------------------------------------
# Elements of ::tk::Priv that are used in this file:
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54

55
56
57
58
59

60
61
62
63
64

65
66
67
68
69

70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98

99
100
101
102

103
104
105

106
107
108
109
110
111
112
113
114

115
116
117

118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138

139
140
141

142
143
144
145
146
147
148
34
35
36
37
38
39
40


41
42

43
44
45
46
47
48
49
50
51

52
53
54
55
56

57
58
59
60
61

62
63
64
65
66

67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94

95
96
97
98

99
100
101

102
103
104
105
106
107
108
109
110

111
112
113

114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134

135
136
137

138
139
140
141
142
143
144
145







-
-


-
+








-
+




-
+




-
+




-
+



-
+














-
-
+








-
+



-
+


-
+








-
+


-
+








-
+











-
+


-
+







#
#-------------------------------------------------------------------------

#-------------------------------------------------------------------------
# The code below creates the default class bindings for text widgets.
#-------------------------------------------------------------------------



# Standard Motif bindings:

bind Text <Button-1> {
bind Text <1> {
    tk::TextButton1 %W %x %y
    %W tag remove sel 0.0 end
}
bind Text <B1-Motion> {
    set tk::Priv(x) %x
    set tk::Priv(y) %y
    tk::TextSelectTo %W %x %y
}
bind Text <Double-Button-1> {
bind Text <Double-1> {
    set tk::Priv(selectMode) word
    tk::TextSelectTo %W %x %y
    catch {%W mark set insert sel.first}
}
bind Text <Triple-Button-1> {
bind Text <Triple-1> {
    set tk::Priv(selectMode) line
    tk::TextSelectTo %W %x %y
    catch {%W mark set insert sel.first}
}
bind Text <Shift-Button-1> {
bind Text <Shift-1> {
    tk::TextResetAnchor %W @%x,%y
    set tk::Priv(selectMode) char
    tk::TextSelectTo %W %x %y
}
bind Text <Double-Shift-Button-1>	{
bind Text <Double-Shift-1>	{
    set tk::Priv(selectMode) word
    tk::TextSelectTo %W %x %y 1
}
bind Text <Triple-Shift-Button-1>	{
bind Text <Triple-Shift-1>	{
    set tk::Priv(selectMode) line
    tk::TextSelectTo %W %x %y
}
bind Text <B1-Leave> {
    set tk::Priv(x) %x
    set tk::Priv(y) %y
    tk::TextAutoScan %W
}
bind Text <B1-Enter> {
    tk::CancelRepeat
}
bind Text <ButtonRelease-1> {
    tk::CancelRepeat
}

bind Text <Control-Button-1> {
bind Text <Control-1> {
    %W mark set insert @%x,%y
    # An operation that moves the insert mark without making it
    # one end of the selection must insert an autoseparator
    if {[%W cget -autoseparators]} {
	%W edit separator
    }
}
# stop an accidental double click triggering <Double-Button-1>
bind Text <Double-Control-Button-1> { # nothing }
bind Text <Double-Control-1> { # nothing }
# stop an accidental movement triggering <B1-Motion>
bind Text <Control-B1-Motion> { # nothing }
bind Text <<PrevChar>> {
    tk::TextSetCursor %W [tk::TextPrevPos %W insert tk::startOfCluster]
    tk::TextSetCursor %W insert-1displayindices
}
bind Text <<NextChar>> {
    tk::TextSetCursor %W [tk::TextNextPos %W insert tk::endOfCluster]
    tk::TextSetCursor %W insert+1displayindices
}
bind Text <<PrevLine>> {
    tk::TextSetCursor %W [tk::TextUpDownLine %W -1]
}
bind Text <<NextLine>> {
    tk::TextSetCursor %W [tk::TextUpDownLine %W 1]
}
bind Text <<SelectPrevChar>> {
    tk::TextKeySelect %W [tk::TextPrevPos %W insert tk::startOfCluster]
    tk::TextKeySelect %W [%W index {insert - 1displayindices}]
}
bind Text <<SelectNextChar>> {
    tk::TextKeySelect %W [tk::TextNextPos %W insert tk::endOfCluster]
    tk::TextKeySelect %W [%W index {insert + 1displayindices}]
}
bind Text <<SelectPrevLine>> {
    tk::TextKeySelect %W [tk::TextUpDownLine %W -1]
}
bind Text <<SelectNextLine>> {
    tk::TextKeySelect %W [tk::TextUpDownLine %W 1]
}
bind Text <<PrevWord>> {
    tk::TextSetCursor %W [tk::TextPrevPos %W insert tk::startOfPreviousWord]
    tk::TextSetCursor %W [tk::TextPrevPos %W insert tcl_startOfPreviousWord]
}
bind Text <<NextWord>> {
    tk::TextSetCursor %W [tk::TextNextWord %W insert]
}
bind Text <<PrevPara>> {
    tk::TextSetCursor %W [tk::TextPrevPara %W insert]
}
bind Text <<NextPara>> {
    tk::TextSetCursor %W [tk::TextNextPara %W insert]
}
bind Text <<SelectPrevWord>> {
    tk::TextKeySelect %W [tk::TextPrevPos %W insert tk::startOfPreviousWord]
    tk::TextKeySelect %W [tk::TextPrevPos %W insert tcl_startOfPreviousWord]
}
bind Text <<SelectNextWord>> {
    tk::TextKeySelect %W [tk::TextSelectNextWord %W insert]
    tk::TextKeySelect %W [tk::TextNextWord %W insert]
}
bind Text <<SelectPrevPara>> {
    tk::TextKeySelect %W [tk::TextPrevPara %W insert]
}
bind Text <<SelectNextPara>> {
    tk::TextKeySelect %W [tk::TextNextPara %W insert]
}
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
215
216
217
218
219
220
221

222

223
224
225
226
227
228
229
230
231

232

233
234
235
236
237
238
239







-
+
-









-
+
-







    }
}
bind Text <Delete> {
    if {[tk::TextCursorInSelection %W]} {
	%W delete sel.first sel.last
    } else {
	if {[%W compare end != insert+1c]} {
	    %W delete [tk::TextPrevPos %W insert+1c tk::startOfCluster] \
	    %W delete insert
		    [tk::TextNextPos %W insert tk::endOfCluster]
	}
	%W see insert
    }
}
bind Text <BackSpace> {
    if {[tk::TextCursorInSelection %W]} {
	%W delete sel.first sel.last
    } else {
	if {[%W compare insert != 1.0]} {
	    %W delete [tk::TextPrevPos %W insert tk::startOfCluster] \
	    %W delete insert-1c
		    [tk::TextNextPos %W insert-1c tk::endOfCluster]
	}
	%W see insert
    }
}

bind Text <Control-space> {
    %W mark set [tk::TextAnchor %W] insert
290
291
292
293
294
295
296
297

298
299
300
301

302
303

304
305
306
307
308



309
310

311

312

313
314
315
316
317
318
319
285
286
287
288
289
290
291

292
293
294
295

296
297

298
299
300



301
302
303
304
305
306

307

308
309
310
311
312
313
314
315







-
+



-
+

-
+


-
-
-
+
+
+


+
-
+
-
+







	    || !$tk::Priv(mouseMoved)} {
	tk::TextPasteSelection %W %x %y
    }
}
bind Text <Insert> {
    catch {tk::TextInsert %W [::tk::GetSelection %W PRIMARY]}
}
bind Text <Key> {
bind Text <KeyPress> {
    tk::TextInsert %W %A
}

# Ignore all Alt, Meta, Control, Command, and Fn keypresses unless explicitly bound.
# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
# Otherwise, if a widget binding for one of these is defined, the
# <Key> class binding will also fire and insert the character,
# <KeyPress> class binding will also fire and insert the character,
# which is wrong.  Ditto for <Escape>.

bind Text <Alt-Key> {# nothing }
bind Text <Meta-Key> {# nothing}
bind Text <Control-Key> {# nothing}
bind Text <Alt-KeyPress> {# nothing }
bind Text <Meta-KeyPress> {# nothing}
bind Text <Control-KeyPress> {# nothing}
bind Text <Escape> {# nothing}
bind Text <KP_Enter> {# nothing}
if {[tk windowingsystem] eq "aqua"} {
bind Text <Command-Key> {# nothing}
    bind Text <Command-KeyPress> {# nothing}
bind Text <Fn-Key> {# nothing}
}

# Additional emacs-like bindings:

bind Text <Control-d> {
    if {!$tk_strictMotif && [%W compare end != insert+1c]} {
	%W delete insert
    }
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364







-
+








bind Text <<Redo>> {
    catch { %W edit redo }
}

bind Text <Meta-b> {
    if {!$tk_strictMotif} {
	tk::TextSetCursor %W [tk::TextPrevPos %W insert tk::startOfPreviousWord]
	tk::TextSetCursor %W [tk::TextPrevPos %W insert tcl_startOfPreviousWord]
    }
}
bind Text <Meta-d> {
    if {!$tk_strictMotif && [%W compare end != insert+1c]} {
	%W delete insert [tk::TextNextWord %W insert]
    }
}
379
380
381
382
383
384
385
386

387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

448
449
450
451
452
453
454
455
456
457
458






459

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477


























































478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
375
376
377
378
379
380
381

382
383
384
385
386

387
388


































389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427


















428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504





505
506
507
508
509
510
511
512







-
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+











+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-
-
-
-
-
+







bind Text <Meta-greater> {
    if {!$tk_strictMotif} {
	tk::TextSetCursor %W end-1c
    }
}
bind Text <Meta-BackSpace> {
    if {!$tk_strictMotif} {
	%W delete [tk::TextPrevPos %W insert tk::startOfPreviousWord] insert
	%W delete [tk::TextPrevPos %W insert tcl_startOfPreviousWord] insert
    }
}
bind Text <Meta-Delete> {
    if {!$tk_strictMotif} {
	%W delete [tk::TextPrevPos %W insert tk::startOfPreviousWord] insert
	%W delete [tk::TextPrevPos %W insert tcl_startOfPreviousWord] insert
    }
}

# Bindings for IME text input.

bind Text <<TkStartIMEMarkedText>> {
    dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
}
bind Text <<TkEndIMEMarkedText>> {
    ::tk::TextEndIMEMarkedText %W
}
bind Text <<TkClearIMEMarkedText>> {
    %W delete IMEmarkedtext.first IMEmarkedtext.last
}
bind Text <<TkAccentBackspace>> {
    %W delete insert-1c
}

# ::tk::TextEndIMEMarkedText --
#
# Handles input method text marking in a text widget.
#
# Arguments:
# w -	The text widget

proc ::tk::TextEndIMEMarkedText {w} {
    variable Priv
    if {[catch {
	set mark [dict get $Priv(IMETextMark) $w]
    }]} {
	bell
	return
    }
    $w tag add IMEmarkedtext $mark insert
    $w tag configure IMEmarkedtext -underline 1
}

# Macintosh only bindings:

if {[tk windowingsystem] eq "aqua"} {
bind Text <Control-v> {
    tk::TextScrollPages %W 1
}

# End of Mac only bindings
}

# A few additional bindings of my own.

bind Text <Control-h> {
    if {!$tk_strictMotif && [%W compare insert != 1.0]} {
	%W delete insert-1c
	%W see insert
    }
}
bind Text <Button-2> {
bind Text <2> {
    if {!$tk_strictMotif} {
	tk::TextScanMark %W %x %y
    }
}
bind Text <B2-Motion> {
    if {!$tk_strictMotif} {
	tk::TextScanDrag %W %x %y
    }
}
set ::tk::Priv(prevPos) {}

# The MouseWheel will typically only fire on Windows and MacOS X.
# However, someone could use the "event generate" command to produce one
# on other platforms.  We must be careful not to round -ve values of %D
# down to zero.

if {[tk windowingsystem] eq "aqua"} {
bind Text <MouseWheel> {
    bind Text <MouseWheel> {
    tk::MouseWheel %W y [tk::ScaleNum %D] -4.0 pixels
}
bind Text <Option-MouseWheel> {
    tk::MouseWheel %W y [tk::ScaleNum %D] -1.2 pixels
}
bind Text <Shift-MouseWheel> {
    tk::MouseWheel %W x [tk::ScaleNum %D] -4.0 pixels
}
bind Text <Shift-Option-MouseWheel> {
    tk::MouseWheel %W x [tk::ScaleNum %D] -1.2 pixels
}
bind Text <TouchpadScroll> {
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    if {$deltaX != 0} {
	%W xview scroll [tk::ScaleNum [expr {-$deltaX}]] pixels
    }
    if {$deltaY != 0} {
	%W yview scroll [tk::ScaleNum [expr {-$deltaY}]] pixels
        %W yview scroll [expr {-15 * (%D)}] pixels
    }
    bind Text <Option-MouseWheel> {
        %W yview scroll [expr {-150 * (%D)}] pixels
    }
    bind Text <Shift-MouseWheel> {
        %W xview scroll [expr {-15 * (%D)}] pixels
    }
    bind Text <Shift-Option-MouseWheel> {
        %W xview scroll [expr {-150 * (%D)}] pixels
    }
} else {
    # We must make sure that positive and negative movements are rounded
    # equally to integers, avoiding the problem that
    #     (int)1/3 = 0,
    # but
    #     (int)-1/3 = -1
    # The following code ensure equal +/- behaviour.
    bind Text <MouseWheel> {
	if {%D >= 0} {
	    %W yview scroll [expr {-%D/3}] pixels
	} else {
	    %W yview scroll [expr {(2-%D)/3}] pixels
	}
    }
    bind Text <Shift-MouseWheel> {
	if {%D >= 0} {
	    %W xview scroll [expr {-%D/3}] pixels
	} else {
	    %W xview scroll [expr {(2-%D)/3}] pixels
	}
    }
}

if {"x11" eq [tk windowingsystem]} {
    # Support for mousewheels on Linux/Unix commonly comes through mapping
    # the wheel to the extended buttons.  If you have a mousewheel, find
    # Linux configuration info at:
    #	http://www.inria.fr/koala/colas/mouse-wheel-scroll/
    bind Text <4> {
	if {!$tk_strictMotif} {
	    %W yview scroll -50 pixels
	}
    }
    bind Text <5> {
	if {!$tk_strictMotif} {
	    %W yview scroll 50 pixels
	}
    }
    bind Text <Shift-4> {
	if {!$tk_strictMotif} {
	    %W xview scroll -50 pixels
	}
    }
    bind Text <Shift-5> {
	if {!$tk_strictMotif} {
	    %W xview scroll 50 pixels
	}
    }
}

# ::tk::TextClosestGap --
# Given x and y coordinates, this procedure finds the closest boundary
# between characters to the given coordinates and returns the index
# of the character just after the boundary.
#
# Arguments:
# w -		The text window.
# x -		X-coordinate within the window.
# y -		Y-coordinate within the window.

proc ::tk::TextClosestGap {w x y} {
    set pos [$w index @$x,$y]
    set bbox [$w bbox $pos]
    if {$bbox eq ""} {
	return $pos
    }
    # The check on y coord of the line bbox with dlineinfo is to fix
    # [a9cf210a42] to properly handle selecting and moving the mouse
    # out of the widget.
    if {$y < [lindex [$w dlineinfo $pos] 1] ||
            $x - [lindex $bbox 0] < [lindex $bbox 2]/2} {
    if {($x - [lindex $bbox 0]) < ([lindex $bbox 2]/2)} {
	return $pos
    }
    $w index "$pos + 1 char"
}

# ::tk::TextButton1 --
# This procedure is invoked to handle button-1 presses in text
527
528
529
530
531
532
533




534


535
536
537
538
539
540
541
531
532
533
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549
550







+
+
+
+
-
+
+







    # relative to the gap
    set bbox [$w bbox [$w index $anchorname]]
    if {$x > [lindex $bbox 0]} {
	$w mark gravity $anchorname right
    } else {
	$w mark gravity $anchorname left
    }
    # Allow focus in any case on Windows, because that will let the
    # selection be displayed even for state disabled text widgets.
    if {[tk windowingsystem] eq "win32" \
	    || [$w cget -state] eq "normal"} {
    focus $w
	focus $w
    }
    if {[$w cget -autoseparators]} {
	$w edit separator
    }
}

# ::tk::TextSelectTo --
# This procedure is invoked to extend the selection, typically when
599
600
601
602
603
604
605
606
607


608
609
610
611
612
613
614
608
609
610
611
612
613
614


615
616
617
618
619
620
621
622
623







-
-
+
+







	    if {[$w compare $cur < $first]} {
		set first $cur
	    } elseif {[$w compare $cur > $last]} {
		set last $cur
	    }

	    # Now find word boundaries
	    set first [TextPrevPos $w "$first + 1c" tk::wordBreakBefore]
	    set last [TextNextPos $w "$last - 1c" tk::wordBreakAfter]
	    set first [TextPrevPos $w "$first + 1c" tcl_wordBreakBefore]
	    set last [TextNextPos $w "$last - 1c" tcl_wordBreakAfter]
	}
	line {
	    # Set initial range based only on the anchor
	    set first "$anchorname linestart"
	    set last "$anchorname lineend"

	    # Extend range (if necessary) based on the current point
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
764
765
766
767
768
769
770



771
772
773
774
775
776
777







-
-
-







	if {[$w compare $new < insert]} {
	    $w tag add sel $new insert
	} else {
	    $w tag add sel insert $new
	}
	$w mark set $anchorname insert
    } else {
        if {[catch {$w index $anchorname}]} {
            $w mark set $anchorname insert
        }
	if {[$w compare $new < $anchorname]} {
	    set first $new
	    set last $anchorname
	} else {
	    set first $anchorname
	    set last $new
	}
878
879
880
881
882
883
884
885
886
887
888





889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908



909

910
911
912
913
914
915
916
884
885
886
887
888
889
890




891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911




912
913
914
915
916
917
918
919
920
921
922
923







-
-
-
-
+
+
+
+
+
















-
-
-
-
+
+
+

+







	$w edit separator
	$w configure -autoseparators 1
    }
}

# ::tk::TextUpDownLine --
# Returns the index of the character one display line above or below the
# insertion cursor.  There is a tricky thing here: we want to maintain the
# original x position across repeated operations, even though some lines
# that will get passed through don't have enough characters to cover the
# original column.
# insertion cursor.  There are two tricky things here.  First, we want to
# maintain the original x position across repeated operations, even though
# some lines that will get passed through don't have enough characters to
# cover the original column.  Second, don't try to scroll past the
# beginning or end of the text.
#
# Arguments:
# w -		The text window in which the cursor is to move.
# n -		The number of display lines to move: -1 for up one line,
#		+1 for down one line.

proc ::tk::TextUpDownLine {w n} {
    variable ::tk::Priv

    set i [$w index insert]
    if {$Priv(prevPos) ne $i} {
	set Priv(textPosOrig) $i
    }
    set lines [$w count -displaylines $Priv(textPosOrig) $i]
    set new [$w index \
	    "$Priv(textPosOrig) + [expr {$lines + $n}] displaylines"]
    set Priv(prevPos) $new
    if {[$w compare $new == "end display lineend"] \
            || [$w compare $new == "insert display linestart"]} {
        set Priv(textPosOrig) $new
    if {[$w compare $new == end] \
	    || [$w compare $new == "insert display linestart"]} {
	set new $i
    }
    set Priv(prevPos) $new
    return $new
}

# ::tk::TextPrevPara --
# Returns the index of the beginning of the paragraph just before a given
# position in the text (the beginning of a paragraph is the first non-blank
# character after a blank line).
1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071







-
+





-
+







# w -		Name of a text widget.

proc ::tk_textCut w {
    if {![catch {set data [$w get sel.first sel.last]}]} {
        # make <<Cut>> an atomic operation on the Undo stack,
        # i.e. separate it from other delete operations on either side
	set oldSeparator [$w cget -autoseparators]
	if {([$w cget -state] eq "normal") && $oldSeparator} {
	if {$oldSeparator} {
	    $w edit separator
	}
	clipboard clear -displayof $w
	clipboard append -displayof $w $data
	$w delete sel.first sel.last
	if {([$w cget -state] eq "normal") && $oldSeparator} {
	if {$oldSeparator} {
	    $w edit separator
	}
    }
}

# ::tk_textPaste --
# This procedure pastes the contents of the clipboard to the insertion
1082
1083
1084
1085
1086
1087
1088


1089
1090


1091
1092
1093
1094
1095

1096
1097
1098
1099
1100





1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112




1113
1114
1115
1116
1117
1118
1119
1089
1090
1091
1092
1093
1094
1095
1096
1097


1098
1099
1100
1101
1102
1103
1104
1105





1106
1107
1108
1109
1110












1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121







+
+
-
-
+
+





+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+







	    $w edit separator
	    $w configure -autoseparators 1
	}
    }
}

# ::tk::TextNextWord --
# Returns the index of the next word position after a given position in the
# text.  The next word is platform dependent and may be either the next
# Returns the index of the next start-of-word position after the next
# end-of-word position after a given position in the text.
# end-of-word position or the next start-of-word position after the next
# end-of-word position.
#
# Arguments:
# w -		The text window in which the cursor is to move.
# start -	Position at which to start search.

if {[tk windowingsystem] eq "win32"}  {
proc ::tk::TextNextWord {w start} {
    TextNextPos $w [TextNextPos $w $start tk::endOfWord] \
	    tk::startOfNextWord
}

    proc ::tk::TextNextWord {w start} {
	TextNextPos $w [TextNextPos $w $start tcl_endOfWord] \
		tcl_startOfNextWord
    }
} else {
# ::tk::TextSelectNextWord --
# Returns the index of the next end-of-word position after a given
# position in the text.
#
# Arguments:
# w -		The text window in which the cursor is to move.
# start -	Position at which to start search.

proc ::tk::TextSelectNextWord {w start} {
    TextNextPos $w $start tk::endOfWord
}

    proc ::tk::TextNextWord {w start} {
	TextNextPos $w $start tcl_endOfWord
    }
}

# ::tk::TextNextPos --
# Returns the index of the next position after the given starting
# position in the text as computed by a specified function.
#
# Arguments:
# w -		The text window in which the cursor is to move.
1196
1197
1198
1199
1200
1201
1202

1203
1204
1205
1206
1207
1208
1209
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212







+







    if {($x != $Priv(x)) || ($y != $Priv(y))} {
	set Priv(mouseMoved) 1
    }
    if {[info exists Priv(mouseMoved)] && $Priv(mouseMoved)} {
	$w scan dragto $x $y
    }
}

# ::tk::TextUndoRedoProcessMarks --
#
# This proc is executed after an undo or redo action.
# It processes the list of undo/redo marks temporarily set in the
# text widget to positions delimiting where changes happened, and
# returns a flat list of ranges. The temporary marks are removed
# from the text widget.
1237
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1240
1241
1242
1243
1244
1245
1246


1247



1248
1249
1250
1251
1252
1253
1254







-
-
+
-
-
-







    #           deleteProc
    #         . mark deletion rather happen through [.text mark unset xxx]
    #           which was not used _up to this point of the code_ (it
    #           is a bit later just before exiting the present proc)
    set nUndoMarks [llength $undoMarks]
    set n [expr {$nUndoMarks / 2}]
    set undoMarks [lsort -dictionary $undoMarks]
    if {$n > 0} {
	set Lmarks [lrange $undoMarks 0 [expr {$n - 1}]]
    set Lmarks [lrange $undoMarks 0 [expr {$n - 1}]]
    } else {
	set Lmarks {}
    }
    set Rmarks [lrange $undoMarks $n [llength $undoMarks]]
    foreach Lmark $Lmarks Rmark $Rmarks {
        lappend indices [$w index $Lmark] [$w index $Rmark]
        $w mark unset $Lmark $Rmark
    }

    # process ranges to:
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280

1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1291





1292
1293
1294
1295
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291


1292
1293
1294
1295
1296
1297
1298
1299
1300







+






+



+






-
-
+
+
+
+
+




            set ir2 [lindex $ind [expr {$j + 1}]]

            if {[$w compare $il2 > $ir1]} {
                # second range starts after the end of first range
                # -> further second ranges do not need to be considered
                #    because ranges were sorted by increasing first index
                set j $nUndoMarks

            } else {
                if {[$w compare $ir2 > $ir1]} {
                    # second range overlaps first range
                    # -> merge them into a single range
                    set indices [lreplace $indices end-1 end]
                    lappend indices $il1 $ir2

                } else {
                    # second range is fully included in first range
                    # -> ignore it

                }
                # in both cases above, the second range shall be
                # trimmed out from the list of ranges
                set ind [lreplace $ind $j [expr {$j + 1}]]
                incr j -2
                incr nUndoMarks -2
            }
        }

            }

        }

    }

    return $indices
}

Changes to library/tk.tcl.

1
2
3
4
5
6
7
8



9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5



6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21





-
-
-
+
+
+





-
+







# tk.tcl --
#
# Initialization script normally executed in the interpreter for each Tk-based
# application.  Arranges class bindings for widgets.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Ajuba Solutions.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.

# Verify that we have Tk binary and script components from the same release
package require -exact tk  9.0b2
package require -exact Tk  8.7a0

# Create a ::tk namespace
namespace eval ::tk {
    # Set up the msgcat commands
    namespace eval msgcat {
	namespace export mc mcmax
        if {[interp issafe] || [catch {package require msgcat}]} {
174
175
176
177
178
179
180
181
182
183
184
185
186





187
188
189
190
191
192
193

194
195

196
197
198
199
200
201
202
174
175
176
177
178
179
180






181
182
183
184
185

186



187

188
189

190
191
192
193
194
195
196
197







-
-
-
-
-
-
+
+
+
+
+
-

-
-
-

-
+

-
+







	unset ::tk::FocusGrab($index)
    } else {
	set oldGrab ""
    }

    catch {focus $oldFocus}
    grab release $grab
    if {[winfo exists $grab]} {
	if {$destroy eq "withdraw"} {
	    wm withdraw $grab
	} else {
	    destroy $grab
	}
    if {$destroy eq "withdraw"} {
	wm withdraw $grab
    } else {
	destroy $grab
    }
    }
    if {[winfo exists $oldGrab] && [winfo ismapped $oldGrab]} {
	# The "grab" command will fail if another application
	# already holds the grab on a window with the same name.
	# So catch it. See [7447ed20ec] for an example.
	if {$oldStatus eq "global"} {
	    catch {grab -global $oldGrab}
	    grab -global $oldGrab
	} else {
	    catch {grab $oldGrab}
	    grab $oldGrab
	}
    }
}

# ::tk::GetSelection --
#   This tries to obtain the default selection.  On Unix, we first try
#   and get a UTF8_STRING, a type supported by modern Unix apps for
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328















329
330
331
332
333
334
335
302
303
304
305
306
307
308















309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








    if {$name} {
	set op delete
    } else {
	set op add
    }

    event $op <<Cut>> <Control-w> <Control-Lock-W> <Shift-Delete>
    event $op <<Copy>> <Meta-w> <Meta-Lock-W> <Control-Insert>
    event $op <<Paste>> <Control-y> <Control-Lock-Y> <Shift-Insert>
    event $op <<PrevChar>> <Control-b> <Control-Lock-B>
    event $op <<NextChar>> <Control-f> <Control-Lock-F>
    event $op <<PrevLine>> <Control-p> <Control-Lock-P>
    event $op <<NextLine>> <Control-n> <Control-Lock-N>
    event $op <<LineStart>> <Control-a> <Control-Lock-A>
    event $op <<LineEnd>> <Control-e> <Control-Lock-E>
    event $op <<SelectPrevChar>> <Control-B> <Control-Lock-b>
    event $op <<SelectNextChar>> <Control-F> <Control-Lock-f>
    event $op <<SelectPrevLine>> <Control-P> <Control-Lock-p>
    event $op <<SelectNextLine>> <Control-N> <Control-Lock-n>
    event $op <<SelectLineStart>> <Control-A> <Control-Lock-a>
    event $op <<SelectLineEnd>> <Control-E> <Control-Lock-e>
    event $op <<Cut>> <Control-Key-w> <Control-Lock-Key-W> <Shift-Key-Delete>
    event $op <<Copy>> <Meta-Key-w> <Meta-Lock-Key-W> <Control-Key-Insert>
    event $op <<Paste>> <Control-Key-y> <Control-Lock-Key-Y> <Shift-Key-Insert>
    event $op <<PrevChar>> <Control-Key-b> <Control-Lock-Key-B>
    event $op <<NextChar>> <Control-Key-f> <Control-Lock-Key-F>
    event $op <<PrevLine>> <Control-Key-p> <Control-Lock-Key-P>
    event $op <<NextLine>> <Control-Key-n> <Control-Lock-Key-N>
    event $op <<LineStart>> <Control-Key-a> <Control-Lock-Key-A>
    event $op <<LineEnd>> <Control-Key-e> <Control-Lock-Key-E>
    event $op <<SelectPrevChar>> <Control-Key-B> <Control-Lock-Key-b>
    event $op <<SelectNextChar>> <Control-Key-F> <Control-Lock-Key-f>
    event $op <<SelectPrevLine>> <Control-Key-P> <Control-Lock-Key-p>
    event $op <<SelectNextLine>> <Control-Key-N> <Control-Lock-Key-n>
    event $op <<SelectLineStart>> <Control-Key-A> <Control-Lock-Key-a>
    event $op <<SelectLineEnd>> <Control-Key-E> <Control-Lock-Key-e>
}

#----------------------------------------------------------------------
# Define common dialogs on platforms where they are not implemented
# using compiled code.
#----------------------------------------------------------------------

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383







384
385
386
387
388


389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432







433
434
435


436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

457
458
459
460
461




462

463
464
465
466



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484








485
486
487
488
489
490
491

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
362
363
364
365
366
367
368



369
370





371
372
373
374
375
376
377
378
379
380


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421





422
423
424
425
426
427
428
429


430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

452
453
454



455
456
457
458
459
460
461
462


463
464
465
466
467
468
469
470
471
472
473
474
475








476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503

504
505
506
507
508

509
510
511



512
513
514
515
516
517
518







-
-
-


-
-
-
-
-
+
+
+
+
+
+
+



-
-
+
+




















-
+


















-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+




















-
+


-
-
-
+
+
+
+

+


-
-
+
+
+










-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
+













-





-



-
-
-







    }
}

#----------------------------------------------------------------------
# Define the set of common virtual events.
#----------------------------------------------------------------------

event add <<ContextMenu>>	<Button-3>
event add <<PasteSelection>>	<ButtonRelease-2>

switch -exact -- [tk windowingsystem] {
    "x11" {
	event add <<Cut>>		<Control-x> <F20> <Control-Lock-X>
	event add <<Copy>>		<Control-c> <F16> <Control-Lock-C>
	event add <<Paste>>		<Control-v> <F18> <Control-Lock-V>
	event add <<Undo>>		<Control-z> <Control-Lock-Z>
	event add <<Redo>>		<Control-Z> <Control-Lock-z>
	event add <<Cut>>		<Control-Key-x> <Key-F20> <Control-Lock-Key-X>
	event add <<Copy>>		<Control-Key-c> <Key-F16> <Control-Lock-Key-C>
	event add <<Paste>>		<Control-Key-v> <Key-F18> <Control-Lock-Key-V>
	event add <<PasteSelection>>	<ButtonRelease-2>
	event add <<Undo>>		<Control-Key-z> <Control-Lock-Key-Z>
	event add <<Redo>>		<Control-Key-Z> <Control-Lock-Key-z>
	event add <<ContextMenu>>	<Button-3>
	# On Darwin/Aqua, buttons from left to right are 1,3,2.  On Darwin/X11 with recent
	# XQuartz as the X server, they are 1,2,3; other X servers may differ.

	event add <<SelectAll>>		<Control-/>
	event add <<SelectNone>>	<Control-backslash>
	event add <<SelectAll>>		<Control-Key-slash>
	event add <<SelectNone>>	<Control-Key-backslash>
	event add <<NextChar>>		<Right>
	event add <<SelectNextChar>>	<Shift-Right>
	event add <<PrevChar>>		<Left>
	event add <<SelectPrevChar>>	<Shift-Left>
	event add <<NextWord>>		<Control-Right>
	event add <<SelectNextWord>>	<Control-Shift-Right>
	event add <<PrevWord>>		<Control-Left>
	event add <<SelectPrevWord>>	<Control-Shift-Left>
	event add <<LineStart>>		<Home>
	event add <<SelectLineStart>>	<Shift-Home>
	event add <<LineEnd>>		<End>
	event add <<SelectLineEnd>>	<Shift-End>
	event add <<PrevLine>>		<Up>
	event add <<NextLine>>		<Down>
	event add <<SelectPrevLine>>	<Shift-Up>
	event add <<SelectNextLine>>	<Shift-Down>
	event add <<PrevPara>>		<Control-Up>
	event add <<NextPara>>		<Control-Down>
	event add <<SelectPrevPara>>	<Control-Shift-Up>
	event add <<SelectNextPara>>	<Control-Shift-Down>
	event add <<ToggleSelection>>	<Control-Button-1>
	event add <<ToggleSelection>>	<Control-ButtonPress-1>

	# Some OS's define a goofy (as in, not <Shift-Tab>) keysym that is
	# returned when the user presses <Shift-Tab>. In order for tab
	# traversal to work, we have to add these keysyms to the PrevWindow
	# event. We use catch just in case the keysym isn't recognized.

	# This is needed for XFree86 systems
	catch { event add <<PrevWindow>> <ISO_Left_Tab> }
	# This seems to be correct on *some* HP systems.
	catch { event add <<PrevWindow>> <hpBackTab> }

	trace add variable ::tk_strictMotif write ::tk::EventMotifBindings
	set ::tk_strictMotif $::tk_strictMotif
	# On unix, we want to always display entry/text selection,
	# regardless of which window has focus
	set ::tk::AlwaysShowSelection 1
    }
    "win32" {
	event add <<Cut>>		<Control-x> <Shift-Delete> <Control-Lock-X>
	event add <<Copy>>		<Control-c> <Control-Insert> <Control-Lock-C>
	event add <<Paste>>		<Control-v> <Shift-Insert> <Control-Lock-V>
  	event add <<Undo>>		<Control-z> <Control-Lock-Z>
	event add <<Redo>>		<Control-y> <Control-Lock-Y>
	event add <<Cut>>		<Control-Key-x> <Shift-Key-Delete> <Control-Lock-Key-X>
	event add <<Copy>>		<Control-Key-c> <Control-Key-Insert> <Control-Lock-Key-C>
	event add <<Paste>>		<Control-Key-v> <Shift-Key-Insert> <Control-Lock-Key-V>
	event add <<PasteSelection>>	<ButtonRelease-2>
  	event add <<Undo>>		<Control-Key-z> <Control-Lock-Key-Z>
	event add <<Redo>>		<Control-Key-y> <Control-Lock-Key-Y>
	event add <<ContextMenu>>	<Button-3>

	event add <<SelectAll>>		<Control-/> <Control-a> <Control-Lock-A>
	event add <<SelectNone>>	<Control-backslash>
	event add <<SelectAll>>		<Control-Key-slash> <Control-Key-a> <Control-Lock-Key-A>
	event add <<SelectNone>>	<Control-Key-backslash>
	event add <<NextChar>>		<Right>
	event add <<SelectNextChar>>	<Shift-Right>
	event add <<PrevChar>>		<Left>
	event add <<SelectPrevChar>>	<Shift-Left>
	event add <<NextWord>>		<Control-Right>
	event add <<SelectNextWord>>	<Control-Shift-Right>
	event add <<PrevWord>>		<Control-Left>
	event add <<SelectPrevWord>>	<Control-Shift-Left>
	event add <<LineStart>>		<Home>
	event add <<SelectLineStart>>	<Shift-Home>
	event add <<LineEnd>>		<End>
	event add <<SelectLineEnd>>	<Shift-End>
	event add <<PrevLine>>		<Up>
	event add <<NextLine>>		<Down>
	event add <<SelectPrevLine>>	<Shift-Up>
	event add <<SelectNextLine>>	<Shift-Down>
	event add <<PrevPara>>		<Control-Up>
	event add <<NextPara>>		<Control-Down>
	event add <<SelectPrevPara>>	<Control-Shift-Up>
	event add <<SelectNextPara>>	<Control-Shift-Down>
	event add <<ToggleSelection>>	<Control-Button-1>
	event add <<ToggleSelection>>	<Control-ButtonPress-1>
    }
    "aqua" {
	event add <<Cut>>		<Command-x> <F2> <Command-Lock-X>
	event add <<Copy>>		<Command-c> <F3> <Command-Lock-C>
	event add <<Paste>>		<Command-v> <F4> <Command-Lock-V>
	event add <<Cut>>		<Command-Key-x> <Key-F2> <Command-Lock-Key-X>
	event add <<Copy>>		<Command-Key-c> <Key-F3> <Command-Lock-Key-C>
	event add <<Paste>>		<Command-Key-v> <Key-F4> <Command-Lock-Key-V>
	event add <<PasteSelection>>	<ButtonRelease-3>
	event add <<Clear>>		<Clear>
	event add <<ContextMenu>>	<Button-2>

	# Official bindings
	# See https://support.apple.com/en-us/HT201236
	event add <<SelectAll>>		<Command-a>
	# See http://support.apple.com/kb/HT1343
	event add <<SelectAll>>		<Command-Key-a>
	event add <<SelectNone>>	<Option-Command-Key-a>
	event add <<Undo>>		<Command-Key-z> <Command-Lock-Key-Z>
	event add <<Redo>>		<Shift-Command-Key-z> <Shift-Command-Lock-Key-z>
	event add <<NextChar>>		<Right> <Control-Key-f> <Control-Lock-Key-F>
	event add <<SelectNextChar>>	<Shift-Right> <Shift-Control-Key-F> <Shift-Control-Lock-Key-F>
	event add <<PrevChar>>		<Left> <Control-Key-b> <Control-Lock-Key-B>
	event add <<SelectPrevChar>>	<Shift-Left> <Shift-Control-Key-B> <Shift-Control-Lock-Key-B>
	event add <<NextWord>>		<Option-Right>
	event add <<SelectNextWord>>	<Shift-Option-Right>
	event add <<PrevWord>>		<Option-Left>
	event add <<SelectPrevWord>>	<Shift-Option-Left>
	event add <<LineStart>>		<Home> <Command-Left> <Control-a> <Control-Lock-A>
	event add <<SelectLineStart>>	<Shift-Home> <Shift-Command-Left> <Shift-Control-A> <Shift-Control-Lock-A>
	event add <<LineEnd>>		<End> <Command-Right> <Control-e> <Control-Lock-E>
	event add <<SelectLineEnd>>	<Shift-End> <Shift-Command-Right> <Shift-Control-E> <Shift-Control-Lock-E>
	event add <<PrevLine>>		<Up> <Control-p> <Control-Lock-P>
	event add <<SelectPrevLine>>	<Shift-Up> <Shift-Control-P> <Shift-Control-Lock-P>
	event add <<NextLine>>		<Down> <Control-n> <Control-Lock-N>
	event add <<SelectNextLine>>	<Shift-Down> <Shift-Control-N> <Shift-Control-Lock-N>
	event add <<LineStart>>		<Home> <Command-Left> <Control-Key-a> <Control-Lock-Key-A>
	event add <<SelectLineStart>>	<Shift-Home> <Shift-Command-Left> <Shift-Control-Key-A> <Shift-Control-Lock-Key-A>
	event add <<LineEnd>>		<End> <Command-Right> <Control-Key-e> <Control-Lock-Key-E>
	event add <<SelectLineEnd>>	<Shift-End> <Shift-Command-Right> <Shift-Control-Key-E> <Shift-Control-Lock-Key-E>
	event add <<PrevLine>>		<Up> <Control-Key-p> <Control-Lock-Key-P>
	event add <<SelectPrevLine>>	<Shift-Up> <Shift-Control-Key-P> <Shift-Control-Lock-Key-P>
	event add <<NextLine>>		<Down> <Control-Key-n> <Control-Lock-Key-N>
	event add <<SelectNextLine>>	<Shift-Down> <Shift-Control-Key-N> <Shift-Control-Lock-Key-N>
	# Not official, but logical extensions of above. Also derived from
	# bindings present in MS Word on OSX.
	event add <<PrevPara>>		<Option-Up>
	event add <<NextPara>>		<Option-Down>
	event add <<SelectPrevPara>>	<Shift-Option-Up>
	event add <<SelectNextPara>>	<Shift-Option-Down>
	event add <<ToggleSelection>>	<Command-Button-1>
	event add <<ToggleSelection>>	<Command-ButtonPress-1>
    }
}

# ----------------------------------------------------------------------
# Read in files that define all of the class bindings.
# ----------------------------------------------------------------------

if {$::tk_library ne ""} {
    proc ::tk::SourceLibFile {file} {
        namespace eval :: [list source [file join $::tk_library $file.tcl]]
    }
    namespace eval ::tk {
	SourceLibFile icons
	SourceLibFile iconbadges
	SourceLibFile button
	SourceLibFile entry
	SourceLibFile listbox
	SourceLibFile menu
	SourceLibFile panedwindow
	SourceLibFile print
	SourceLibFile scale
	SourceLibFile scrlbar
	SourceLibFile spinbox
	if {![interp issafe]} {
	    SourceLibFile systray
	}
	SourceLibFile text
    }
}

# ----------------------------------------------------------------------
# Default bindings for keyboard traversal.
# ----------------------------------------------------------------------
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
533
534
535
536
537
538
539





























540
541
542
543
544
545
546







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








proc ::tk::CancelRepeat {} {
    variable ::tk::Priv
    after cancel $Priv(afterId)
    set Priv(afterId) {}
}

## ::tk::MouseWheel $w $dir $amount $factor $units

proc ::tk::MouseWheel {w dir amount {factor -120.0} {units units}} {
    $w ${dir}view scroll [expr {$amount/$factor}] $units
}

## ::tk::PreciseScrollDeltas $dxdy

proc ::tk::PreciseScrollDeltas {dxdy} {
    set deltaX [expr {$dxdy >> 16}]
    set low [expr {$dxdy & 0xffff}]
    set deltaY [expr {$low < 0x8000 ? $low : $low - 0x10000}]
    return [list $deltaX $deltaY]
}

# Helper for smooth scrolling of widgets that support xview moveto,
# yview moveto, height and width.

proc ::tk::ScrollByPixels {w deltaX deltaY} {
    set width [expr {1.0 * [$w cget -width]}]
    set height [expr {1.0 * [$w cget -height]}]
    set X [lindex [$w xview] 0]
    set Y [lindex [$w yview] 0]
    set x [expr {$X - $deltaX / $width}]
    set y [expr {$Y - $deltaY / $height}]
    $w xview moveto $x
    $w yview moveto $y
}

# ::tk::TabToWindow --
# This procedure moves the focus to the given widget.
# It sends a <<TraverseOut>> virtual event to the previous focus window,
# if any, before changing the focus, and a <<TraverseIn>> event
# to the new focus window afterwards.
#
# Arguments:
631
632
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
658
659
660
661
662

663
664
665
666
667


668
669
670
671
672
673
674
596
597
598
599
600
601
602

603

604
605
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629


630
631
632
633
634
635
636
637
638







-

-
+









-
+











-
+



-
-
+
+







    }
    return $result
}

# ::tk::AmpMenuArgs --
#	Processes arguments for a menu entry, turning -label option into
#	-label and -underline options, returned by ::tk::UnderlineAmpersand.
#      The cmd argument is supposed to be either "add" or "entryconfigure"
#
proc ::tk::AmpMenuArgs {widget cmd type args} {
proc ::tk::AmpMenuArgs {widget add type args} {
    set options {}
    foreach {opt val} $args {
	if {$opt eq "-label"} {
	    lassign [UnderlineAmpersand $val] newlabel under
	    lappend options -label $newlabel -underline $under
	} else {
	    lappend options $opt $val
	}
    }
    $widget $cmd $type {*}$options
    $widget add $type {*}$options
}

# ::tk::FindAltKeyTarget --
#	Search recursively through the hierarchy of visible widgets to find
#	button or label which has $char as underlined character.
#
proc ::tk::FindAltKeyTarget {path char} {
    set class [winfo class $path]
    if {$class in {
	Button Checkbutton Label Radiobutton
	TButton TCheckbutton TLabel TRadiobutton
    } && ([$path cget -underline] >= 0) && [string equal -nocase $char \
    } && [string equal -nocase $char \
	    [string index [$path cget -text] [$path cget -underline]]]} {
	return $path
    }
    set subwins [concat [grid content $path] [pack content $path] \
	    [place content $path]]
    set subwins [concat [grid slaves $path] [pack slaves $path] \
	    [place slaves $path]]
    if {$class eq "Canvas"} {
	foreach item [$path find all] {
	    if {[$path type $item] eq "window"} {
		set w [$path itemcget $item -window]
		if {$w ne ""} {lappend subwins $w}
	    }
	}
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823

824
825
826

827
828

829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
671
672
673
674
675
676
677

















678





679
























































































680



681


682





683








684
685
686
687
688
689

690
691
692
693
694







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-






-





	if {$length > $maxlen} {
	    set maxlen $length
	}
    }
    return $maxlen
}

if {[tk windowingsystem] eq "aqua"} {
    #stub procedures to respond to "do script" Apple Events
    proc ::tk::mac::DoScriptFile {file} {
	uplevel #0 $file
	source $file
    }
    proc ::tk::mac::DoScriptText {script} {
	uplevel #0 $script
	eval $script
    }
    #This procedure is required to silence warnings generated
    #by inline AppleScript execution.
    proc ::tk::mac::GetDynamicSdef {} {
         puts ""
     }
}

# For now, turn off the custom mdef proc for the mac:
if {[info commands ::tk::endOfWord] eq ""} {
    proc ::tk::endOfWord {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	}

	set start [tcl_endOfWord $str $start]
	if {$start < 0} {
	    set start ""
	}
	return $start
    }
}
if {[info commands ::tk::startOfNextWord] eq ""} {
    proc ::tk::startOfNextWord {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	}
	set start [tcl_startOfNextWord $str $start]
	if {$start < 0} {
	    set start ""
	}
	return $start
    }
}
if {[info commands ::tk::startOfPreviousWord] eq ""} {
    proc ::tk::startOfPreviousWord {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	}
	set start [tcl_startOfPreviousWord $str $start]
	if {$start < 0} {
	    set start ""
	}
	return $start
    }
}
if {[info commands ::tk::wordBreakBefore] eq ""} {
    proc ::tk::wordBreakBefore {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	}
	set start [tcl_wordBreakBefore $str $start]
	if {$start < 0} {
	    set start ""
	}
	return $start
    }
}
if {[info commands ::tk::wordBreakAfter] eq ""} {
    proc ::tk::wordBreakAfter {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	}
	set start [tcl_wordBreakAfter $str $start]
	if {$start < 0} {
	    set start ""
	}
	return $start
    }
}
if {[info commands ::tk::endOfCluster] eq ""} {
    proc ::tk::endOfCluster {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	} elseif {$start eq "end"} {
	    set start [expr {[string length $str]-1}]
	} elseif {[string match end-* $start]} {
	    set start [expr {[string length $str]-1-[string range $start 4 end]}]
	} elseif {$start >= [string length $str]} {
	    return ""
	}
	incr start
	return $start
    }
}
if {[info commands ::tk::startOfCluster] eq ""} {
    proc ::tk::startOfCluster {str start {locale {}}} {
	if {$start < 0} {
	    set start -1
	} elseif {$start eq "end"} {
	    set start [expr {[string length $str]-1}]
	} elseif {[string match end-* $start]} {
	    set start [expr {[string length $str]-1-[string range $start 4 end]}]
	} elseif {$start >= [string length $str]} {
	    return [string length $str]
	}
	if {$start < 0} {
	    return ""
	}
	return $start
    }
}

if {[tk windowingsystem] eq "aqua"} {
# Create a dictionary to store the starting index of the IME marked
# text in an Entry or Text widget.

    namespace eval ::tk::mac {
set ::tk::Priv(IMETextMark) [dict create]

	set useCustomMDEF 0
# Scale the default parameters of the panedwindow sash
option add *Panedwindow.handlePad	6p widgetDefault
option add *Panedwindow.handleSize	6p widgetDefault
option add *Panedwindow.sashWidth	2.25p widgetDefault

    }
# Scale the default size of the scale widget and its slider
option add *Scale.length		75p widgetDefault
option add *Scale.sliderLength		22.5p widgetDefault
option add *Scale.width			11.25p widgetDefault

# Scale the default scrollbar width on X11
if {[tk windowingsystem] eq "x11"} {
    option add *Scrollbar.width		8.25p widgetDefault
}

# Run the Ttk themed widget set initialization
if {$::ttk::library ne ""} {
    uplevel \#0 [list source $::ttk::library/ttk.tcl]
}


# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to library/tkfbox.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73




























74
75
76
77
78
79
80
81


82
83
84

85
86
87














88
89

90
91

92








93
94
95
96
97
98
99
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24











































25

26




27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54








55
56



57



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73


74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89












-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
+
-
+
+
+
+
+
+
+
+







# tkfbox.tcl --
#
#	Implements the "TK" standard file selection dialog box.  This dialog
#	box is used on the Unix platforms whenever the tk_strictMotif flag is
#	not set.
#
#	The "TK" standard file selection dialog box is similar to the file
#	selection dialog box on Win95(TM).  The user can navigate the
#	directories by clicking on the folder icons or by selecting the
#	"Directory" option menu.  The user can select files by clicking on the
#	file icons or by entering a filename in the "Filename:" entry.
#
# Copyright © 1994-1998 Sun Microsystems, Inc.
# Copyright (c) 1994-1998 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

namespace eval ::tk::dialog {}
namespace eval ::tk::dialog::file {
    namespace import -force ::tk::msgcat::*
    variable showHiddenBtn 0
    variable showHiddenVar 1

    # Based on Vimix/16/actions/go-up.svg
    # See https://github.com/vinceliuice/vimix-icon-theme
    set updirImageData {
	<?xml version="1.0" encoding="UTF-8"?>
	<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
	 <path d="m7 14v-9l-4 4-1-1 6-6 6 6-1 1-4-4v9z" fill="#000000"/>
	</svg>
    }

    proc UpdateUpdirImageData {} {
	variable updirImageData
	set idx1 [string first "#000000" $updirImageData]
	set idx2 [expr {$idx1 + 6}]

	set fgColor [ttk::style lookup . -foreground {} black]
	lassign [winfo rgb . $fgColor] r g b
	set fgColor [format "#%02x%02x%02x" \
		[expr {$r >> 8}] [expr {$g >> 8}] [expr {$b >> 8}]]

	return [string replace $updirImageData $idx1 $idx2 $fgColor]
    }

    # Based on https://icons8.com/icon/JXYalxb9XWWd/folder
    set folderImageData {
	<?xml version="1.0" encoding="UTF-8"?>
	<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
	 <path d="m0.5 13.5v-12h4.293l2 2h8.707v10z" fill="#59afff"/>
	 <path d="m4.586 2 2 2h8.414v9h-14v-11h3.586m0.414-1h-5v13h16v-11h-9l-2-2z" fill="#2d8cff"/>
	 <path d="m0.5 14.5v-10h4.618l2-1h8.382v11z" fill="#8cc5ff"/>
	 <path d="m15 4v10h-14v-9h4.236l0.211-0.106 1.789-0.894h7.764m1-1h-9l-2 1h-5v11h16z" fill="#2d8cff"/>
	</svg>
    }

    # Based on https://icons8.com/icon/mEF_vyjYlnE3/file
    set fileImageData {
	<?xml version="1.0" encoding="UTF-8"?>
	<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
	 <path d="m2 1h8l4 4v11h-12z" fill="#808080"/>
	 <path d="m3 2h6.5l3.5 3.5v9.5h-10z" fill="#f0f0f0"/>
	 <path d="m9 1v5h5v-1h-4v-4h-1z" fill="#808080"/>
	</svg>
    }

    # Create the images if they did not already exist.
    if {![info exists ::tk::Priv(updirImage)] ||
    if {![info exists ::tk::Priv(updirImage)]} {
	    $::tk::Priv(updirImage) ni [image names]} {
	set ::tk::Priv(updirImage)  [image create photo \
		-format $::tk::svgFmt -data [UpdateUpdirImageData]]

	set ::tk::Priv(updirImage) [image create photo -data {
	    iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAABmJLR0QA/gD+AP7rGN
	    SCAAAACXBIWXMAAA3WAAAN1gGQb3mcAAAACXZwQWcAAAAWAAAAFgDcxelYAAAENUlE
	    QVQ4y7WUbWiVZRjHf/f9POcc9+Kc5bC2aIq5sGG0XnTzNU13zAIlFMNc9CEhTCKwCC
	    JIgt7AglaR0RcrolAKg14+GBbiGL6xZiYyy63cmzvu7MVznnOe537rw7bDyvlBoT/c
	    n+6L3/3nf13XLZLJJP+HfICysjKvqqpq+rWKysvLR1tbW+11g+fPn/+bEGIe4KYqCs
	    Owu66u7oG2trah6wJrrRc0NTVhjME5h7Vj5pxzCCE4duxYZUdHx/aGhoZmgJ+yb+wF
	    uCO19RmAffv25f8LFslkktraWtvU1CS6u7vRWmOtxVpbAPu+T0tLS04pFU/J34Wd3S
	    cdFtlfZWeZBU4IcaS5uXn1ZLAEMMY4ay1aa4wx/zpKKYIgoL6+vmjxqoXe5ZLTcsPq
	    bTyycjODpe1y3WMrvDAMV14jCuW0VhhjiJQpOJ5w7Zwjk8/y9R+vsHHNNq6oFMrkeX
	    BxI+8d2sktap3YvOPD0lRQrH+Z81fE7t3WB4gihVKazsuaA20aKSUgAG/seQdy2l6W
	    37+EyopqTv39I6HJUT2zlnlza2jLdgiTaxwmDov6alLHcZUTzXPGGAauWJbfO4dHl9
	    bgJs3HyfNf0N4ZsOa+jbT3/ownY/hO09p1kBULtjBw+Tvq7xzwauds4dWPDleAcP5E
	    xlprgtBRUZRgYCRPTzoHwEi2g6OnX+eFrW/RM9qBE4p43CeTz5ATaU6nDrFm2cPs/+
	    E1SopqkZ7MFJqntXZaa7IKppckwIEvJbg8LWd28OT6nVihCPQQ8UScWCLGqO4hXuQx
	    qDtJ204eWrqWb1ufRspwtABWaqx5gRKUFSdwDnxPcuLcyyxbuIyaqntIBV34MY9YzC
	    Owg+S9YeJFkniRpGPkCLMrZzG3+jbktA/KClMxFoUhiKC0OAbAhd79CO8i6xe/STyW
	    4O7KVRgUJ/sP0heeJV4kEVKw/vZd40sFKxat4mLvp6VLdvnb/XHHGGPIKwBBpC1/9n
	    3DpfRZnn9/AwCxRII9O79kVPdjvByxuET6Ai8mePeTt4lyheXzhOSpCcdWa00uckTG
	    kckbGu76nEhbIm2xznH4VB3OWYaiXqQn8GKSWGIMHuXyPL76LBcupmhp69pz4uMnXi
	    w4VloTGcdQRtGdzmHs1f+RdYZslMZJhzUOHVnceN1ooEiP5JUzdqCQMWCD0JCIeQzn
	    NNpO+clhrCYf5rC+A2cxWmDUWG2oHEOZMEKIwclgMnnLrTeXUV7sUzpNXgU9DmijWV
	    v9LEKCkAIhKIBnlvpks6F21qUZ31u/sbExPa9h0/RzwzMov2nGlG5TmW1YOzzlnSfL
	    mVnyGf19Q7lwZHBp+1fPtflAIgiC7389n9qkihP+lWyeqfUO15ZwQTqlw9H+o2cOvN
	    QJCAHEgEqgYnI0NyALjAJdyWQy7wMa6AEujUdzo3LjcAXwD/XCTKIRjWytAAAAJXRF
	    WHRjcmVhdGUtZGF0ZQAyMDA5LTA0LTA2VDIxOjI1OjQxLTAzOjAw8s+uCAAAACV0RV
	    h0bW9kaWZ5LWRhdGUAMjAwOC0wMS0wM1QxNTowODoyMS0wMjowMJEc/44AAAAZdEVY
	    dFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC
	if {"TkFileDialog" ni [bindtags .]} {
	    bindtags . [linsert [bindtags .] 1 TkFileDialog]
	    bind TkFileDialog <<ThemeChanged>> {
		if {$::tk::Priv(updirImage) in [image names]} {
		    $::tk::Priv(updirImage) configure \
			    -data [::tk::dialog::file::UpdateUpdirImageData]
		}
	    }
	}]
    }
	}
    }
    if {![info exists ::tk::Priv(folderImage)] ||
    if {![info exists ::tk::Priv(folderImage)]} {
	    $::tk::Priv(folderImage) ni [image names]} {
	set ::tk::Priv(folderImage) [image create photo \
		-format $::tk::svgFmt -data $folderImageData]
	set ::tk::Priv(folderImage) [image create photo -data {
	    iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiA
	    AAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBl
	    Lm9yZ5vuPBoAAAHCSURBVDiNpZAxa5NRFIafc+9XLCni4BC6FBycMnbrLpkcgtDVX6
	    C70D/g4lZX/4coxLlgxFkpiiSSUGm/JiXfveee45AmNlhawXc53HvPee55X+l2u/yP
	    qt3d3Tfu/viatwt3fzIYDI5uBJhZr9fr3TMzzAx3B+D09PR+v98/7HQ6z5fNOWdCCG
	    U4HH6s67oAVDlnV1UmkwmllBUkhMD29nYHeLuEAkyn06qU8qqu64MrgIyqYmZrkHa7
	    3drc3KTVahFjJITAaDRiPB4/XFlQVVMtHH5IzJo/P4EA4MyB+erWPQB7++zs7ccYvl
	    U5Z08pMW2cl88eIXLZeDUpXzsBkNQ5eP1+p0opmaoCTgzw6fjs6gLLsp58FB60t0Dc
	    K1Ul54yIEIMQ43Uj68pquDmCeJVztpwzuBNE2LgBoMVpslHMCUEAFgDVxQbzVAiA+a
	    K5uGPmmDtZF3VpoUm2ArhqQaRiUjcMf81p1G60UEVhcjZfAFTVUkrgkS+jc06mDX9n
	    vq4YhJ9nlxZExMwMEaHJRutOdWuIIsJFUoBSuTvHJ4YIfP46unV4qdlsjsBRZRtb/X
	    fHd5+C8+P7+J8BIoxFwovfRxYhnhxjpzEAAAAASUVORK5CYII=
	}]
    }
    if {![info exists ::tk::Priv(fileImage)] ||
    if {![info exists ::tk::Priv(fileImage)]} {
	    $::tk::Priv(fileImage) ni [image names]} {
	set ::tk::Priv(fileImage)   [image create photo \
	set ::tk::Priv(fileImage)   [image create photo -data {
		-format $::tk::svgFmt -data $fileImageData]
	    iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gva
	    eTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QQWFA84umAmQgAAANpJREFU
	    OMutkj1uhDAQhb8HSLtbISGfgZ+zbJkix0HmFhwhUdocBnMBGvqtTIqIFSReWKK8ai
	    x73nwzHrVt+zEMwwvH9FrX9TsA1trpqKy10+yUzME4jnjvAZB0LzXHkojjmDRNVyh3
	    A+89zrlVwlKSqKrqVy/J8lAUxSZBSMny4ZLgp54iyPM8UPHGNJ2IomibAKDv+9VlWZ
	    bABbgB5/0WQgSSkC4PF2JF4JzbHN430c4vhAm0TyCJruuClefph4yCBCGT3T3Isoy/
	    KDHGfDZNcz2SZIx547/0BVRRX7n8uT/sAAAAAElFTkSuQmCC
	}]
    }
}

# ::tk::dialog::file:: --
#
#	Implements the TK file selection dialog.  This dialog is used when the
#	tk_strictMotif flag is set to false.  This procedure shouldn't be
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
222
223
224
225
226
227
228


229

230
231
232
233
234
235
236







-
-
+
-








    # Cleanup traces on selectPath variable
    #

    foreach trace [trace info variable data(selectPath)] {
	trace remove variable data(selectPath) {*}$trace
    }
    if {[winfo exists $data(dirMenuBtn)]} {
	$data(dirMenuBtn) configure -textvariable {}
    $data(dirMenuBtn) configure -textvariable {}
    }

    return $Priv(selectFilePath)
}

# ::tk::dialog::file::Config --
#
#	Configures the TK filedialog according to the argument list
369
370
371
372
373
374
375
376
377
378



379
380
381
382
383
384
385
357
358
359
360
361
362
363



364
365
366
367
368
369
370
371
372
373







-
-
-
+
+
+







    $data(dirMenu) add radiobutton -label "" -variable \
	    [format %s(selectPath) ::tk::dialog::file::$dataName]
    set data(upBtn) [ttk::button $f1.up]
    $data(upBtn) configure -image $Priv(updirImage)

    $f1.menu configure -takefocus 1;# -highlightthickness 2

    pack $data(upBtn) -side right -padx 3p -fill both
    pack $f1.lab -side left -padx 3p -fill both
    pack $f1.menu -expand yes -fill both -padx 3p
    pack $data(upBtn) -side right -padx 4 -fill both
    pack $f1.lab -side left -padx 4 -fill both
    pack $f1.menu -expand yes -fill both -padx 4

    # data(icons): the IconList that list the files and directories.
    #
    if {$class eq "TkFDialog"} {
	if { $data(-multiple) } {
	    set fNameCaption [mc "File &names:"]
	} else {
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447

448
449
450

451
452
453
454
455


456
457
458

459
460

461
462

463
464
465
466
467
468
469
470



471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434

435
436
437

438
439
440
441


442
443
444
445

446
447

448
449

450
451
452
453
454
455



456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473







-
+








-
+


-
+



-
-
+
+


-
+

-
+

-
+





-
-
-
+
+
+







-
+







    } else {
	set text [mc "Show &Hidden Directories"]
    }
    set data(hiddenBtn) [::tk::AmpWidget ttk::checkbutton $f2.hidden \
	    -text $text -state disabled \
	    -variable ::tk::dialog::file::showHiddenVar \
	    -command [list ::tk::dialog::file::UpdateWhenIdle $w]]
# -anchor w -padx 2p
# -anchor w -padx 3

    # the okBtn is created after the typeMenu so that the keyboard traversal
    # is in the right order, and add binding so that we find out when the
    # dialog is destroyed by the user (added here instead of to the overall
    # window so no confusion about how much <Destroy> gets called; exactly
    # once will do). [Bug 987169]

    set data(okBtn)     [::tk::AmpWidget ttk::button $f2.ok \
	    -text [mc "&OK"]     -default active];# -pady 2p]
	    -text [mc "&OK"]     -default active];# -pady 3]
    bind $data(okBtn) <Destroy> [list ::tk::dialog::file::Destroyed $w]
    set data(cancelBtn) [::tk::AmpWidget ttk::button $f2.cancel \
	    -text [mc "&Cancel"] -default normal];# -pady 2p]
	    -text [mc "&Cancel"] -default normal];# -pady 3]

    # grid the widgets in f2
    #
    grid $f2.lab $f2.ent $data(okBtn) -padx 3p -pady 2p -sticky ew
    grid configure $f2.ent -padx 1.5p
    grid $f2.lab $f2.ent $data(okBtn) -padx 4 -pady 3 -sticky ew
    grid configure $f2.ent -padx 2
    if {$class eq "TkFDialog"} {
	grid $data(typeMenuLab) $data(typeMenuBtn) $data(cancelBtn) \
		-padx 3p -sticky ew
		-padx 4 -sticky ew
	grid configure $data(typeMenuBtn) -padx 0
	grid $data(hiddenBtn) -columnspan 2 -padx 3p -sticky ew
	grid $data(hiddenBtn) -columnspan 2 -padx 4 -sticky ew
    } else {
	grid $data(hiddenBtn) - $data(cancelBtn) -padx 3p -sticky ew
	grid $data(hiddenBtn) - $data(cancelBtn) -padx 4 -sticky ew
    }
    grid columnconfigure $f2 1 -weight 1

    # Pack all the frames together. We are done with widget construction.
    #
    pack $f1 -side top -fill x -pady 3p
    pack $f2 -side bottom -pady 3p -fill x
    pack $data(icons) -expand yes -fill both -padx 3p -pady 1p
    pack $f1 -side top -fill x -pady 4
    pack $f2 -side bottom -pady 4 -fill x
    pack $data(icons) -expand yes -fill both -padx 4 -pady 1

    # Set up the event handlers that are common to Directory and File Dialogs
    #

    wm protocol $w WM_DELETE_WINDOW [list ::tk::dialog::file::CancelCmd $w]
    $data(upBtn)     configure -command [list ::tk::dialog::file::UpDirCmd $w]
    $data(cancelBtn) configure -command [list ::tk::dialog::file::CancelCmd $w]
    bind $w <Escape> [list $data(cancelBtn) invoke]
    bind $w <KeyPress-Escape> [list $data(cancelBtn) invoke]
    bind $w <Alt-Key> [list tk::AltKeyInDialog $w %A]

    # Set up event handlers specific to File or Directory Dialogs
    #
    if {$class eq "TkFDialog"} {
	bind $data(ent) <Return> [list ::tk::dialog::file::ActivateEnt $w]
	$data(okBtn)     configure -command [list ::tk::dialog::file::OkCmd $w]
589
590
591
592
593
594
595
596

597
598

599
600
601
602
603
604
605
577
578
579
580
581
582
583

584
585

586
587
588
589
590
591
592
593







-
+

-
+







	return
    }

    # Turn on the busy cursor. BUG?? We haven't disabled X events, though,
    # so the user may still click and cause havoc ...
    #
    set entCursor [$data(ent) cget -cursor]
    set dlgCursor [$w cget -cursor]
    set dlgCursor [$w         cget -cursor]
    $data(ent) configure -cursor watch
    $w configure -cursor watch
    $w         configure -cursor watch
    update idletasks

    $data(icons) deleteall

    set showHidden $showHiddenVar

    # Make the dir list. Note that using an explicit [pwd] (instead of '.') is
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643







-
+







	    ::tk::SetAmpText $data(okBtn) [mc "&Save"]
	}
    }

    # turn off the busy cursor.
    #
    $data(ent) configure -cursor $entCursor
    $w configure -cursor $dlgCursor
    $w         configure -cursor $dlgCursor
}

# ::tk::dialog::file::SetPathSilently --
#
# 	Sets data(selectPath) without invoking the trace procedure
#
proc ::tk::dialog::file::SetPathSilently {w path} {
917
918
919
920
921
922
923
924
925


926
927
928
929
930
931
932


933
934
935
936
937
938
939
905
906
907
908
909
910
911


912
913
914
915
916
917
918


919
920
921
922
923
924
925
926
927







-
-
+
+





-
-
+
+







		} else {
		    set data(selectFile) $file
		}
		Done $w
	    }
	}
	PATH {
	    tk_messageBox -icon warning -type ok -parent $w -message \
		    [mc "Directory \"%1\$s\" does not exist." $path]
	    tk_messageBox -icon warning -type ok -parent $w \
		    -message [mc "Directory \"%1\$s\" does not exist." $path]
	    $data(ent) selection range 0 end
	    $data(ent) icursor end
	}
	CHDIR {
	    tk_messageBox -type ok -parent $w -icon warning -message  \
		    [mc "Cannot change to the directory\
			\"%1\$s\".\nPermission denied." $path]
		[mc "Cannot change to the directory\
                     \"%1\$s\".\nPermission denied." $path]
	    $data(ent) selection range 0 end
	    $data(ent) icursor end
	}
	ERROR {
	    tk_messageBox -type ok -parent $w -icon warning -message \
		    [mc "Invalid file name \"%1\$s\"." $path]
	    $data(ent) selection range 0 end
1129
1130
1131
1132
1133
1134
1135
1136


1137
1138
1139
1140
1141
1142
1143
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1131
1132







-
+
+







	if {
	    [info exists data(-typevariable)] && $data(-typevariable) ne ""
	    && [info exists data(-filetypes)] && [llength $data(-filetypes)]
	    && [info exists data(filterType)] && $data(filterType) ne ""
	} then {
	    upvar #0 $data(-typevariable) typeVariable
	    set typeVariable [lindex $data(origfiletypes) \
		    [lsearch -exact $data(-filetypes) $data(filterType)] 0]
	            [lsearch -exact $data(-filetypes) $data(filterType)] 0]

	}
    }
    bind $data(okBtn) <Destroy> {}
    set Priv(selectFilePath) $selectFilePath
}

# ::tk::dialog::file::GlobFiltered --

Changes to library/ttk/altTheme.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



32
33
34
35



36
37
38

39
40

41
42
43


44
45
46

47
48

49
50
51
52
53
54
55
56
57
58
59
60

61
62

63
64
65

66
67

68
69
70
71
72




73
74

75
76
77
78
79
80

81
82
83
84
85
86

87
88
89
90
91
92
93



94
95
96


97
98
99
100
101
102

103
104
105
106
107
108
109

110
111

112
113
114
115


116
117
118

119
120
121
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28


29
30
31
32



33
34
35
36
37

38
39
40
41
42


43
44
45
46

47


48

49
50
51
52
53
54
55
56
57
58

59
60

61

62

63


64

65



66
67
68
69
70

71

72
73
74
75

76
77
78
79
80
81

82

83
84
85



86
87
88
89
90

91
92
93
94
95



96




97


98


99
100
101


102
103

104

105

106
107










-


















-
-
+
+
+

-
-
-
+
+
+


-
+


+

-
-
+
+


-
+
-
-
+
-










-
+

-
+
-

-
+
-
-
+
-

-
-
-
+
+
+
+

-
+
-




-
+





-
+
-



-
-
-
+
+
+


-
+
+



-
-
-
+
-
-
-
-

-
-
+
-
-
+


-
-
+
+
-

-
+
-


#
# Ttk widget set: Alternate theme
#

namespace eval ttk::theme::alt {

    variable colors
    array set colors {
	-frame 		"#d9d9d9"
	-window		"#ffffff"
	-alternate	"#f0f0f0"
	-darker 	"#c3c3c3"
	-border		"#414141"
	-activebg 	"#ececec"
	-disabledfg	"#a3a3a3"
	-selectbg	"#4a6984"
	-selectfg	"#ffffff"
	-altindicator	"#aaaaaa"
    }

    ttk::style theme settings alt {

	ttk::style configure "." \
	    -background 	$colors(-frame) \
	    -foreground 	black \
	    -troughcolor	$colors(-darker) \
	    -bordercolor	$colors(-border) \
	    -selectbackground 	$colors(-selectbg) \
	    -selectforeground 	$colors(-selectfg) \
	    -font 		TkDefaultFont

	    -font 		TkDefaultFont \
	    ;

	ttk::style map "." -background \
	    [list disabled $colors(-frame)  active $colors(-activebg)]
	ttk::style map "." -foreground [list disabled $colors(-disabledfg)]
        ttk::style map "." -embossed [list disabled 1]
	    [list disabled $colors(-frame)  active $colors(-activebg)] ;
	ttk::style map "." -foreground [list disabled $colors(-disabledfg)] ;
        ttk::style map "." -embossed [list disabled 1] ;

	ttk::style configure TButton \
	    -anchor center -width -11 -padding 0.75p \
	    -anchor center -width -11 -padding "1 1" \
	    -relief raised -shiftrelief 1 \
	    -highlightthickness 1 -highlightcolor $colors(-frame)

	ttk::style map TButton -relief {
	    {pressed !disabled}	sunken
	    {active !disabled}	raised
	    {pressed !disabled} 	sunken
	    {active !disabled} 	raised
	} -highlightcolor {alternate black}

	ttk::style configure TCheckbutton -indicatorcolor "#ffffff" \
	ttk::style configure TCheckbutton -indicatorcolor "#ffffff" -padding 2
	    -indicatormargin {0 1.5p 3p 1.5p} -padding 1.5p
	ttk::style configure TRadiobutton -indicatorcolor "#ffffff" \
	ttk::style configure TRadiobutton -indicatorcolor "#ffffff" -padding 2
	    -indicatormargin {0 1.5p 3p 1.5p} -padding 1.5p
	ttk::style map TCheckbutton -indicatorcolor \
	    [list  pressed $colors(-frame) \
	           alternate $colors(-altindicator) \
	           disabled $colors(-frame)]
	ttk::style map TRadiobutton -indicatorcolor \
	    [list  pressed $colors(-frame) \
	           alternate $colors(-altindicator) \
	           disabled $colors(-frame)]

	ttk::style configure TMenubutton \
	    -width -11 -padding 2.25p -arrowsize 3.75p -relief raised
	    -width -11 -padding "3 3" -relief raised

	ttk::style configure TEntry -padding 1 \
	ttk::style configure TEntry -padding 1
	    -focuswidth 2 -focuscolor $colors(-selectbg)
	ttk::style map TEntry -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)]
		[list readonly $colors(-frame) disabled $colors(-frame)]

	ttk::style configure TCombobox -padding 1 -arrowsize 10.5p \
	ttk::style configure TCombobox -padding 1
	    -focuswidth 1 -focuscolor $colors(-selectbg)
	ttk::style map TCombobox -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)] \
	    -arrowcolor [list disabled $colors(-disabledfg)]
	ttk::style configure ComboboxPopdownFrame -relief solid -borderwidth 1
		[list readonly $colors(-frame) disabled $colors(-frame)] \
		-arrowcolor [list disabled $colors(-disabledfg)]
	ttk::style configure ComboboxPopdownFrame \
	    -relief solid -borderwidth 1

	ttk::style configure TSpinbox -arrowsize 7.5p -padding {1.5p 0 7.5p 0} \
	ttk::style configure TSpinbox -arrowsize 10 -padding {2 0 10 0}
	    -focuswidth 1 -focuscolor $colors(-selectbg)
	ttk::style map TSpinbox -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)] \
	    -arrowcolor [list disabled $colors(-disabledfg)]

	ttk::style configure Toolbutton -relief flat -padding 1.5p
	ttk::style configure Toolbutton -relief flat -padding 2
	ttk::style map Toolbutton -relief \
	    {disabled flat selected sunken pressed sunken active raised}
	ttk::style map Toolbutton -background \
	    [list pressed $colors(-darker)  active $colors(-activebg)]

	ttk::style configure TScrollbar -relief raised \
	ttk::style configure TScrollbar -relief raised
	    -arrowsize 10.5p -width 10.5p

	ttk::style configure TLabelframe -relief groove -borderwidth 2

	ttk::style configure TNotebook -tabmargins {1.5p 1.5p 0.75p 0}
	ttk::style configure TNotebook.Tab -background $colors(-darker) \
	    -padding {3p 1.5p}
	ttk::style configure TNotebook -tabmargins {2 2 1 0}
	ttk::style configure TNotebook.Tab \
	    -padding {4 2} -background $colors(-darker)
	ttk::style map TNotebook.Tab \
	    -background [list selected $colors(-frame)] \
	    -expand {selected {1.5p 1.5p 0.75p 0}}
	    -expand [list selected {2 2 1 0}] \
	    ;

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont -relief raised
	ttk::style configure Item \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Treeview -background $colors(-window) \
	ttk::style configure Treeview -background $colors(-window)
	    -stripedbackground $colors(-alternate) -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style configure Treeview.Separator \
	    -background $colors(-alternate)
	ttk::style map Treeview \
	    -background [list disabled $colors(-frame)\
				selected $colors(-selectbg)] \
	    -background [list selected $colors(-selectbg)] \
	    -foreground [list disabled $colors(-disabledfg) \
				selected $colors(-selectfg)]
	    -foreground [list selected $colors(-selectfg)] ;

	ttk::style configure TScale \
	    -groovewidth 3p -troughrelief sunken \
	    -sliderthickness 11.25p -borderwidth 2
	    -groovewidth 4 -troughrelief sunken \
	    -sliderwidth raised -borderwidth 2

	ttk::style configure TProgressbar \
	    -background $colors(-selectbg) -borderwidth 0 \
	    -background $colors(-selectbg) -borderwidth 0
	    -barsize 22.5p -thickness 11.25p
    }
}

Changes to library/ttk/aquaTheme.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13




14
15
16
17
18

19
20
21


22
23
24


25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135


136

137
138
139
140
141



142
143
144
145
146
147
148
149

150
151
152
153

154
155
156
157
158
159
160
161



162
163
164

165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
1
2
3
4
5
6
7
8
9




10
11
12
13
14
15
16
17

18



19
20



21
22


23







































































































24
25
26
27
28
29
30
31

32
33
34
35


36
37
38





39
40

41




42




43



44
45
46

47

48
49
50
51
52
53
54

55




56
57
58
59









-
-
-
-
+
+
+
+




-
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






+
+
-
+



-
-
+
+
+
-
-
-
-
-


-
+
-
-
-
-
+
-
-
-
-

-
-
-
+
+
+
-

-
+






-
+
-
-
-
-




#
# Aqua theme (OSX native look and feel)
#

namespace eval ttk::theme::aqua {
    ttk::style theme settings aqua {

	ttk::style configure . \
	    -font TkDefaultFont \
	    -background systemWindowBackgroundColor \
	    -foreground systemLabelColor \
	    -selectbackground systemSelectedTextBackgroundColor \
	    -selectforeground systemSelectedTextColor \
	    -background systemWindowBody \
	    -foreground systemModelessDialogActiveText \
	    -selectbackground systemHighlight \
	    -selectforeground systemModelessDialogActiveText \
	    -selectborderwidth 0 \
	    -insertwidth 1

	ttk::style map . \
	    -foreground {
	    -foreground {disabled systemModelessDialogInactiveText
		disabled systemDisabledControlTextColor
		background systemLabelColor} \
	    -selectbackground {
		    background systemModelessDialogInactiveText} \
	    -selectbackground {background systemHighlightSecondary
		background systemSelectedTextBackgroundColor
		!focus systemSelectedTextBackgroundColor} \
	    -selectforeground {
		    !focus systemHighlightSecondary} \
	    -selectforeground {background systemModelessDialogInactiveText
		background systemSelectedTextColor
		!focus systemSelectedTextColor}
		    !focus systemDialogActiveText}

	# Button
	ttk::style configure TButton -anchor center \
	    -foreground systemControlTextColor
	ttk::style map TButton \
	    -foreground {
		pressed white
	        {alternate !pressed !background} white
	        disabled systemDisabledControlTextColor}

	# Menubutton
	ttk::style configure TMenubutton -anchor center -padding {2 0 0 2}

	# Toolbutton
	ttk::style configure Toolbutton -anchor center

	# Inline Button
	ttk::style configure InlineButton -anchor center -font TkHeadingFont \
	    -foreground systemTextBackgroundColor
	ttk::style map InlineButton \
	    -foreground {
		disabled systemWindowBackgroundColor
	    }

	# Image Button
	ttk::style configure ImageButton -anchor center -width 1 \
	    -compound top
	ttk::style map ImageButton \
	    -foreground {
		pressed systemLabelColor
		!pressed systemSecondaryLabelColor
	    }

	# Recessed (radio) button
	font create RecessedFont -family EmphasizedSystem -size 11 -weight bold
	ttk::style configure RecessedButton \
	    -foreground systemControlTextColor
	ttk::style map RecessedButton \
	    -foreground {
		{disabled selected} systemWindowBackgroundColor3
		{disabled !selected} systemDisabledControlTextColor
		selected systemTextBackgroundColor
		active white
		pressed white
	    } \
	    -font {
		selected RecessedFont
		active RecessedFont
		pressed RecessedFont
	    }

	# Sidebar (radio) button
	font create SidebarFont -family .AppleSystemUIFont -size 11 -weight normal
	ttk::style configure SidebarButton \
	    -foreground systemControlTextColor \
	    -font SidebarFont
	ttk::style map SidebarButton \
	    -foreground {
		{disabled selected} systemWindowBackgroundColor3
		{disabled !selected} systemDisabledControlTextColor
		selected systemTextColor
		active systemTextColor
		pressed systemTextColor
	    }

	# For Entry, Combobox and Spinbox widgets the selected text background
	# is the "Highlight color" selected in preferences when the widget
	# has focus.  It is a gray color when the widget does not have focus or
	# the window does not have focus. (The background state implies !focus
	# so we only need to specify !focus.)

	# Entry
	ttk::style configure TEntry \
	    -foreground systemTextColor \
	    -background systemTextBackgroundColor
	ttk::style map TEntry \
	    -foreground {
		disabled systemDisabledControlTextColor
	    } \
	    -selectbackground {
		!focus systemUnemphasizedSelectedTextBackgroundColor
	    }

	# Combobox:
	ttk::style map TCombobox \
	    -foreground {
		disabled systemDisabledControlTextColor
	    } \
	    -selectbackground {
		!focus systemUnemphasizedSelectedTextBackgroundColor
	    }

	# Spinbox
	ttk::style configure TSpinbox \
	    -foreground systemTextColor \
	    -background systemTextBackgroundColor
	ttk::style map TSpinbox \
	    -foreground {
		disabled systemDisabledControlTextColor
	    } \
	    -selectbackground {
		!focus systemUnemphasizedSelectedTextBackgroundColor
	    }

	# Workaround for #1100117:
	# Actually, on Aqua we probably shouldn't stipple images in
	# disabled buttons even if it did work...
	ttk::style configure . -stipple {}

	ttk::style configure TButton -anchor center -width -6
	ttk::style configure Toolbutton -padding 4
	# Notebook

	ttk::style configure TNotebook -tabmargins {10 0} -tabposition n
	ttk::style configure TNotebook -padding {18 8 18 17}
	ttk::style configure TNotebook.Tab -padding {12 3 12 2}
	ttk::style configure TNotebook.Tab -foreground systemControlTextColor
	ttk::style map TNotebook.Tab \

	# Combobox:
	ttk::style configure TCombobox -postoffset {5 -2 -10 0}
	    -foreground {
		{background !selected} systemControlTextColor
		{background selected} black
		{!background selected} systemSelectedTabTextColor
		disabled systemDisabledControlTextColor}

	# Treeview:
	ttk::style configure Heading \
	ttk::style configure Heading -font TkHeadingFont
	    -font TkHeadingFont \
	    -foreground systemTextColor \
	    -background systemWindowBackgroundColor
	ttk::style configure Treeview -rowheight 18 \
	ttk::style configure Treeview -rowheight 18 -background White
	    -background systemControlBackgroundColor \
	    -stripedbackground systemControlAlternatingRowColor \
            -foreground systemTextColor \
	    -fieldbackground systemTextBackgroundColor
	ttk::style map Treeview \
	    -background {
		selected systemSelectedTextBackgroundColor
	    }
	    -background {{selected background} systemHighlightSecondary
		    selected systemHighlight}


	# Enable animation for ttk::progressbar widget:
	ttk::style configure TProgressbar -period 100 -maxphase 120
	ttk::style configure TProgressbar -period 100 -maxphase 255

	# For Aqua, labelframe labels should appear outside the border,
	# with a 14 pixel inset and 4 pixels spacing between border and label
	# (ref: Apple Human Interface Guidelines / Controls / Grouping Controls)
	#
	ttk::style configure TLabelframe \
	    -labeloutside true \
		-labeloutside true -labelmargins {14 0 14 4}
	    -labelmargins {14 0 14 2}

	ttk::style configure TLabelframe.Label \
	    -font TkSmallCaptionFont

	# TODO: panedwindow sashes should be 9 pixels (HIG:Controls:Split Views)
    }
}

Changes to library/ttk/button.tcl.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23

24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


44
45
46


47
48
49
50
51
52
53
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22

23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


42
43
44


45
46
47
48
49
50
51
52
53











-
+










-
+


-
+















-
-
+
+

-
-
+
+







#
# Bindings for Buttons, Checkbuttons, and Radiobuttons.
#
# Notes: <Button1-Leave>, <Button1-Enter> only control the "pressed"
# state; widgets remain "active" if the pointer is dragged out.
# This doesn't seem to be conventional, but it's a nice way
# to provide extra feedback while the grab is active.
# (If the button is released off the widget, the grab deactivates and
# we get a <Leave> event then, which turns off the "active" state)
#
# Normally, <ButtonRelease> and <ButtonN-Enter/Leave> events are
# delivered to the widget which received the initial <Button>
# delivered to the widget which received the initial <ButtonPress>
# event.  However, Tk [grab]s (#1223103) and menu interactions
# (#1222605) can interfere with this.  To guard against spurious
# <Button1-Enter> events, the <Button1-Enter> binding only sets
# the pressed state if the button is currently active.
#

namespace eval ttk::button {}

bind TButton <Enter> 		{ %W instate !disabled {%W state active} }
bind TButton <Leave>		{ %W state !active }
bind TButton <space>		{ ttk::button::activate %W }
bind TButton <Key-space>	{ ttk::button::activate %W }
bind TButton <<Invoke>> 	{ ttk::button::activate %W }

bind TButton <Button-1> \
bind TButton <ButtonPress-1> \
    { %W instate !disabled { ttk::clickToFocus %W; %W state pressed } }
bind TButton <ButtonRelease-1> \
    { %W instate pressed { %W state !pressed; %W instate !disabled { %W invoke } } }
bind TButton <Button1-Leave> \
    { %W state !pressed }
bind TButton <Button1-Enter> \
    { %W instate {active !disabled} { %W state pressed } }

# Checkbuttons and Radiobuttons have the same bindings as Buttons:
#
ttk::copyBindings TButton TCheckbutton
ttk::copyBindings TButton TRadiobutton

# ...plus a few more:

bind TRadiobutton <Up>  		{ ttk::button::RadioTraverse %W -1 }
bind TRadiobutton <Down> 		{ ttk::button::RadioTraverse %W +1 }
bind TRadiobutton <KeyPress-Up> 	{ ttk::button::RadioTraverse %W -1 }
bind TRadiobutton <KeyPress-Down> 	{ ttk::button::RadioTraverse %W +1 }

# bind TCheckbutton <+> { %W select }
# bind TCheckbutton <minus> { %W deselect }
# bind TCheckbutton <KeyPress-plus> { %W select }
# bind TCheckbutton <KeyPress-minus> { %W deselect }

# activate --
#	Simulate a button press: temporarily set the state to 'pressed',
#	then invoke the button.
#
proc ttk::button::activate {w} {
    $w instate disabled { return }
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78

79
80
81
82
83
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77

78
79
80
81
82
83







-
+








-
+





#	A radiobutton group consists of all the radiobuttons with
#	the same parent and -variable; this is a pretty good heuristic
#	that works most of the time.
#
proc ttk::button::RadioTraverse {w dir} {
    set group [list]
    foreach sibling [winfo children [winfo parent $w]] {
	if {   [winfo class $sibling] eq "TRadiobutton"
    	if {   [winfo class $sibling] eq "TRadiobutton"
	    && [$sibling cget -variable] eq [$w cget -variable]
	    && ![$sibling instate disabled]
	} {
	   lappend group $sibling
	}
    }

    if {![llength $group]} {	 # Shouldn't happen, but can.
	return
    	return
    }

    set pos [expr {([lsearch -exact $group $w] + $dir) % [llength $group]}]
    tk::TabToWindow [lindex $group $pos]
}

Changes to library/ttk/clamTheme.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7

8
9
10
11
12
13
14







-







#
# "Clam" theme.
#
# Inspired by the XFCE family of Gnome themes.
#

namespace eval ttk::theme::clam {

    variable colors
    array set colors {
	-disabledfg		"#999999"
	-frame  		"#dcdad5"
	-window  		"#ffffff"
	-dark			"#cfcdc8"
	-darker 		"#bab5ab"
30
31
32
33
34
35
36
37


38
39
40
41
42
43
44
45



46
47
48
49

50
51
52
53
54
55
56
57
58



59
60

61
62
63
64
65
66
67
68
69
70
71
72


73
74
75
76
77


78
79
80
81


82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103







104
105
106
107
108
109
110
111

112
113
114
115
116

117
118
119


120
121
122

123
124

125
126
127



128
129
130

131
132
133

134
135
136
137
138
139
140

141
142

143
144
145


146
147
148
149
150
151
152
153
154

155
156
157

158
159
29
30
31
32
33
34
35

36
37
38
39
40
41
42



43
44
45
46
47
48

49
50
51
52
53
54
55
56


57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77


78
79
80
81


82
83
84
85
86
87
88
89
90
91
92
93
94
95


96
97
98
99





100
101
102
103
104
105
106

107
108
109
110
111
112

113

114
115
116

117
118


119
120

121

122
123

124
125


126
127
128
129
130

131



132




133


134


135
136


137
138
139
140







141

142

143
144
145







-
+
+





-
-
-
+
+
+



-
+







-
-
+
+
+

-
+











-
+
+



-
-
+
+


-
-
+
+












-
-
+



-
-
-
-
-
+
+
+
+
+
+
+
-






-
+
-



-
+

-
-
+
+
-

-
+

-
+

-
-
+
+
+


-
+
-
-
-
+
-
-
-
-

-
-
+
-
-
+

-
-
+
+


-
-
-
-
-
-
-
+
-

-
+


	    -bordercolor $colors(-darkest) \
	    -darkcolor $colors(-dark) \
	    -lightcolor $colors(-lighter) \
	    -troughcolor $colors(-darker) \
	    -selectbackground $colors(-selectbg) \
	    -selectforeground $colors(-selectfg) \
	    -selectborderwidth 0 \
	    -font TkDefaultFont
	    -font TkDefaultFont \
	    ;

	ttk::style map "." \
	    -background [list disabled $colors(-frame) \
			     active $colors(-lighter)] \
	    -foreground [list disabled $colors(-disabledfg)] \
	    -selectbackground [list !focus $colors(-darkest)] \
	    -selectforeground [list !focus white]

	    -selectbackground [list  !focus $colors(-darkest)] \
	    -selectforeground [list  !focus white] \
	    ;
	# -selectbackground [list  !focus "#847d73"]

	ttk::style configure TButton \
	    -anchor center -width -11 -padding 3.75p -relief raised
	    -anchor center -width -11 -padding 5 -relief raised
	ttk::style map TButton \
	    -background [list \
			     disabled $colors(-frame) \
			     pressed $colors(-darker) \
			     active $colors(-lighter)] \
	    -lightcolor [list pressed $colors(-darker)] \
	    -darkcolor [list pressed $colors(-darker)] \
	    -bordercolor {alternate #000000}

	    -bordercolor [list alternate "#000000"] \
	    ;

	ttk::style configure Toolbutton \
	    -anchor center -padding 1.5p -relief flat
	    -anchor center -padding 2 -relief flat
	ttk::style map Toolbutton \
	    -relief [list \
		    disabled flat \
		    selected sunken \
		    pressed sunken \
		    active raised] \
	    -background [list \
		    disabled $colors(-frame) \
		    pressed $colors(-darker) \
		    active $colors(-lighter)] \
	    -lightcolor [list pressed $colors(-darker)] \
	    -darkcolor [list pressed $colors(-darker)]
	    -darkcolor [list pressed $colors(-darker)] \
	    ;

	ttk::style configure TCheckbutton \
	    -indicatorbackground "#ffffff" \
	    -indicatormargin {0.75p 0.75p 3p 0.75p} \
	    -padding 1.5p
	    -indicatormargin {1 1 4 1} \
	    -padding 2 ;
	ttk::style configure TRadiobutton \
	    -indicatorbackground "#ffffff" \
	    -indicatormargin {0.75p 0.75p 3p 0.75p} \
	    -padding 1.5p
	    -indicatormargin {1 1 4 1} \
	    -padding 2 ;
	ttk::style map TCheckbutton -indicatorbackground \
	    [list  pressed $colors(-frame) \
			{!disabled alternate} $colors(-altindicator) \
			{disabled alternate} $colors(-disabledaltindicator) \
			disabled $colors(-frame)]
	ttk::style map TRadiobutton -indicatorbackground \
	    [list  pressed $colors(-frame) \
			{!disabled alternate} $colors(-altindicator) \
			{disabled alternate} $colors(-disabledaltindicator) \
			disabled $colors(-frame)]

	ttk::style configure TMenubutton \
	    -width -11 -arrowsize 3.75p -arrowpadding 2.25p -padding 3.75p \
	    -relief raised
	    -width -11 -padding 5 -relief raised

	ttk::style configure TEntry -padding 1 -insertwidth 1
	ttk::style map TEntry \
	    -background [list readonly $colors(-frame)] \
	    -bordercolor [list focus $colors(-selectbg)] \
	    -lightcolor [list focus #6f9dc6]

	ttk::style configure TCombobox -padding 1 -insertwidth 1 \
	    -background [list  readonly $colors(-frame)] \
	    -bordercolor [list  focus $colors(-selectbg)] \
	    -lightcolor [list  focus "#6f9dc6"] \
	    -darkcolor [list  focus "#6f9dc6"] \
	    ;

	ttk::style configure TCombobox -padding 1 -insertwidth 1
	    -arrowsize 10.5p
	ttk::style map TCombobox \
	    -background [list active $colors(-lighter) \
			     pressed $colors(-lighter)] \
	    -fieldbackground [list {readonly focus} $colors(-selectbg) \
				  readonly $colors(-frame)] \
	    -foreground [list {readonly focus} $colors(-selectfg)] \
	    -arrowcolor [list disabled $colors(-disabledfg)] \
	    -arrowcolor [list disabled $colors(-disabledfg)]
	    -bordercolor [list focus $colors(-selectbg)]
	ttk::style configure ComboboxPopdownFrame \
	    -relief solid -borderwidth 1

	ttk::style configure TSpinbox -arrowsize 7.5p -padding {1.5p 0 7.5p 0}
	ttk::style configure TSpinbox -arrowsize 10 -padding {2 0 10 0}
	ttk::style map TSpinbox \
	    -background [list readonly $colors(-frame)] \
            -arrowcolor [list disabled $colors(-disabledfg)] \
	    -background [list  readonly $colors(-frame)] \
            -arrowcolor [list disabled $colors(-disabledfg)]
	    -bordercolor [list focus $colors(-selectbg)]

	ttk::style configure TNotebook.Tab -padding {4.5p 1.5p 4.5p 1.5p}
	ttk::style configure TNotebook.Tab -padding {6 2 6 2}
	ttk::style map TNotebook.Tab \
	    -padding {selected {4.5p 3p 4.5p 1.5p}} \
	    -padding [list selected {6 4 6 2}] \
	    -background [list selected $colors(-frame) {} $colors(-darker)] \
	    -lightcolor [list selected $colors(-lighter) {} $colors(-dark)]

	    -lightcolor [list selected $colors(-lighter) {} $colors(-dark)] \
	    ;

	# Treeview:
	ttk::style configure Heading \
	    -font TkHeadingFont -relief raised -padding 2.25p
	    -font TkHeadingFont -relief raised -padding {3}
	ttk::style configure Item -indicatorsize 9p \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Treeview -background $colors(-window) \
	ttk::style configure Treeview -background $colors(-window)
	    -stripedbackground $colors(-lighter) -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style configure Treeview.Separator \
	    -background $colors(-lighter)
	ttk::style map Treeview \
	    -background [list disabled $colors(-frame)\
				selected $colors(-selectbg)] \
	    -background [list selected $colors(-selectbg)] \
	    -foreground [list disabled $colors(-disabledfg) \
				selected $colors(-selectfg)]
	    -foreground [list selected $colors(-selectfg)] ;

	ttk::style configure TLabelframe \
	    -labeloutside true -labelmargins {0 0 0 3p} \
    	ttk::style configure TLabelframe \
	    -labeloutside true -labelmargins {0 0 0 4} \
	    -borderwidth 2 -relief raised

	ttk::style configure TScrollbar -gripsize 7.5p \
	    -arrowsize 10.5p -width 10.5p

	ttk::style configure TScale -gripsize 7.5p \
	    -arrowsize 10.5p -sliderlength 22.5p

	ttk::style configure TProgressbar -background $colors(-frame) \
	ttk::style configure TProgressbar -background $colors(-frame)
	    -arrowsize 10.5p -sliderlength 22.5p

	ttk::style configure Sash -sashthickness 4.5p -gripsize 15p
	ttk::style configure Sash -sashthickness 6 -gripcount 10
    }
}

Changes to library/ttk/classicTheme.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8

9

10
11

12
13
14
15
16
17
18








-
+
-


-







#
# "classic" Tk theme.
#
# Implements Tk's traditional Motif-like look and feel.
#

namespace eval ttk::theme::classic {

    variable colors
    variable colors; array set colors {
    array set colors {
	-frame		"#d9d9d9"
	-window		"#ffffff"
	-alternate	"#f0f0f0"
	-activebg	"#ececec"
	-troughbg	"#c3c3c3"
	-selectbg	"#c3c3c3"
	-selectfg	"#000000"
	-disabledfg	"#a3a3a3"
	-indicator	"#b03060"
	-altindicator	"#b05e5e"
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
45

46
47
48
49

50
51

52
53
54
55
56
57
58
59
60




61
62
63
64
65
66
67
68
69




70
71
72

73
74
75
76

77
78
79
80
81
82

83
84
85
86
87
88

89
90
91
92

93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115

116
117

118
119
120
121
122

123
124
125
126
127

128
129
130

131
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43

44
45
46
47

48
49

50

51
52
53
54
55



56
57
58
59

60
61
62
63
64



65
66
67
68

69

70
71
72


73
74
75
76
77
78

79
80
81
82
83
84

85

86
87

88

89
90

91


92
93
94
95
96
97
98



99




100


101


102
103
104
105
106

107
108
109
110
111

112



113








-
+
+









-
+



-
+

-
+
-





-
-
-
+
+
+
+
-





-
-
-
+
+
+
+
-

-
+


-
-
+





-
+





-
+
-


-
+
-


-
+
-
-







-
-
-
+
-
-
-
-

-
-
+
-
-
+




-
+




-
+
-
-
-
+
-
	    -selectbackground	$colors(-selectbg) \
	    -selectforeground	$colors(-selectfg) \
	    -troughcolor	$colors(-troughbg) \
	    -indicatorcolor	$colors(-frame) \
	    -highlightcolor	$colors(-frame) \
	    -highlightthickness	1 \
	    -selectborderwidth	1 \
	    -insertwidth	2
	    -insertwidth	2 \
	    ;

	# To match pre-Xft X11 appearance, use:
	#	ttk::style configure . -font {Helvetica 12 bold}

	ttk::style map "." -background \
	    [list disabled $colors(-frame) active $colors(-activebg)]
	ttk::style map "." -foreground \
	    [list disabled $colors(-disabledfg)]

	ttk::style map "." -highlightcolor {focus black}
	ttk::style map "." -highlightcolor [list focus black]

	ttk::style configure TButton \
	    -anchor center -padding "3m 1m" -relief raised -shiftrelief 1
	ttk::style map TButton -relief {{!disabled pressed} sunken}
	ttk::style map TButton -relief [list {!disabled pressed} sunken]

	ttk::style configure TCheckbutton -indicatorrelief raised \
	ttk::style configure TCheckbutton -indicatorrelief raised
	    -indicatormargin {0 1.5p 3p 1.5p}
	ttk::style map TCheckbutton \
	    -indicatorcolor [list \
		    pressed $colors(-frame) \
		    alternate $colors(-altindicator) \
		    selected $colors(-indicator)] \
	    -indicatorrelief {alternate raised  selected sunken  pressed sunken}

	ttk::style configure TRadiobutton -indicatorrelief raised \
	    -indicatorrelief {alternate raised  selected sunken  pressed sunken} \
	    ;

	ttk::style configure TRadiobutton -indicatorrelief raised
	    -indicatormargin {0 1.5p 3p 1.5p}
	ttk::style map TRadiobutton \
	    -indicatorcolor [list \
		    pressed $colors(-frame) \
		    alternate $colors(-altindicator) \
		    selected $colors(-indicator)] \
	    -indicatorrelief {alternate raised  selected sunken  pressed sunken}

	ttk::style configure TMenubutton -relief raised \
	    -indicatorrelief {alternate raised  selected sunken  pressed sunken} \
	    ;

	ttk::style configure TMenubutton -relief raised -padding "3m 1m"
	    -indicatormargin {3.75p 0} -padding {3m 1m}

	ttk::style configure TEntry -padding 1 -font TkTextFont
	ttk::style configure TEntry -relief sunken -padding 1 -font TkTextFont
	ttk::style map TEntry -fieldbackground \
		[list readonly $colors(-frame) disabled $colors(-frame)]

	ttk::style configure TCombobox -padding 1 -arrowsize 11.75p
	ttk::style configure TCombobox -padding 1
	ttk::style map TCombobox -fieldbackground \
		[list readonly $colors(-frame) disabled $colors(-frame)]
	ttk::style configure ComboboxPopdownFrame \
	    -relief solid -borderwidth 1

	ttk::style configure TSpinbox -arrowsize 7.5p -padding {1.5p 0 7.5p 0}
	ttk::style configure TSpinbox -arrowsize 10 -padding {2 0 10 0}
	ttk::style map TSpinbox -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)]

	ttk::style configure TLabelframe -borderwidth 2 -relief groove

	ttk::style configure TScrollbar -relief raised \
	ttk::style configure TScrollbar -relief raised
	    -arrowsize 11.25p -width 11.25p -troughborderwidth 2
	ttk::style map TScrollbar -relief {{pressed !disabled} sunken}

	ttk::style configure TScale -sliderrelief raised \
	ttk::style configure TScale -sliderrelief raised
	    -sliderlength 22.5p -sliderthickness 11.25p -troughborderwidth 2
	ttk::style map TScale -sliderrelief {{pressed !disabled} sunken}

	ttk::style configure TProgressbar -background SteelBlue \
	ttk::style configure TProgressbar -background SteelBlue
	    -barsize 22.5p -thickness 11.25p -troughborderwidth 2

	ttk::style configure TNotebook.Tab \
	    -padding {3m 1m} \
	    -background $colors(-troughbg)
	ttk::style map TNotebook.Tab -background [list selected $colors(-frame)]

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont -relief raised
	ttk::style configure Item -indicatorsize 9p \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Treeview -background $colors(-window) \
	ttk::style configure Treeview -background $colors(-window)
	    -stripedbackground $colors(-alternate) -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style configure Treeview.Separator \
	    -background $colors(-alternate)
	ttk::style map Treeview \
	    -background [list disabled $colors(-frame)\
				selected $colors(-selectbg)] \
	    -background [list selected $colors(-selectbg)] \
	    -foreground [list disabled $colors(-disabledfg) \
				selected $colors(-selectfg)]
	    -foreground [list selected $colors(-selectfg)] ;

	#
	# Toolbar buttons:
	#
	ttk::style configure Toolbutton -padding 1.5p -relief flat -shiftrelief 2
	ttk::style configure Toolbutton -padding 2 -relief flat -shiftrelief 2
	ttk::style map Toolbutton -relief \
	    {disabled flat selected sunken pressed sunken active raised}
	ttk::style map Toolbutton -background \
	    [list pressed $colors(-troughbg)  active $colors(-activebg)]

    }
	ttk::style configure Sash \
	    -sashthickness 4.5p -sashpad 1.5 -handlesize 6p -handlepad 6p
    }
}
}

Changes to library/ttk/combobox.tcl.

12
13
14
15
16
17
18
19
20
21



22
23
24
25
26
27
28









29


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


47
48
49
50
51




52
53
54
55

56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102



103
104
105
106
107
108




109
110
111
112
113
114
115

116
117
118
119
120
121
122
12
13
14
15
16
17
18



19
20
21







22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


48
49
50




51
52
53
54
55
56
57

58



59







60
61
62
63
64



65
66
67
68
69
70
71
72
73
74
75
76
77
78



79
80
81
82
83
84

85
86
87
88
89
90



91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+















-
-
+
+

-
-
-
-
+
+
+
+



-
+
-
-
-
+
-
-
-
-
-
-
-





-
-
-
+
+
+











-
-
-






-
+





-
-
-
+
+
+





-
+
+
+
+






-
+







#	(Tk 8.4.8+)
#
#	On X11: WM_TRANSIENT_FOR on override-redirect windows
#	may be used by compositing managers and by EWMH-aware
#	window managers (even though the older ICCCM spec says
#	it's meaningless).
#
#       On OSX: The native combobox uses a popup menu to display the
#       combobox choices.  So this implementation does that as well,
#       rather than construc a Tk listbox.  Since the window manager
#	On OSX: [wm transient] does utterly the wrong thing.
#	Instead, we use [MacWindowStyle "help" "noActivates hideOnSuspend"].
#	The "noActivates" attribute prevents the parent toplevel
#       takes care of scrolling and making sure that the menu can be
#       displayed even when the button is close to the bottom of the
#       screen, this actually simplifies the implementation.  The Post
#       and PopupWindow procs have separate implementations for Aqua
#       and other systems.  The configuration of the menu is handled
#       by a different proc than the one which configures the listbox
#       on other platforms -- ConfigureAquaMenu instead of
#	from deactivating when the popdown is posted, and is also
#	necessary for "help" windows to receive mouse events.
#	"hideOnSuspend" makes the popdown disappear (resp. reappear)
#	when the parent toplevel is deactivated (resp. reactivated).
#	(see [#1814778]).  Also set [wm resizable 0 0], to prevent
#	TkAqua from shrinking the scrollbar to make room for a grow box
#	that isn't there.
#
#	In order to work around other platform quirks in TkAqua,
#       ConfigureListbox.
#	[grab] and [focus] are set in <Map> bindings instead of
#	immediately after deiconifying the window.
#

namespace eval ttk::combobox {
    variable Values	;# Values($cb) is -listvariable of listbox widget
    variable State
    set State(entryPress) 0
}

### Combobox bindings.
#
# Duplicate the Entry bindings, override if needed:
#

ttk::copyBindings TEntry TCombobox

bind TCombobox <Down> 			{ ttk::combobox::Post %W }
bind TCombobox <Escape> 		{ ttk::combobox::Unpost %W }
bind TCombobox <KeyPress-Down> 		{ ttk::combobox::Post %W }
bind TCombobox <KeyPress-Escape> 	{ ttk::combobox::Unpost %W }

bind TCombobox <Button-1> 		{ ttk::combobox::Press "" %W %x %y }
bind TCombobox <Shift-Button-1>		{ ttk::combobox::Press "s" %W %x %y }
bind TCombobox <Double-Button-1> 	{ ttk::combobox::Press "2" %W %x %y }
bind TCombobox <Triple-Button-1> 	{ ttk::combobox::Press "3" %W %x %y }
bind TCombobox <ButtonPress-1> 		{ ttk::combobox::Press "" %W %x %y }
bind TCombobox <Shift-ButtonPress-1>	{ ttk::combobox::Press "s" %W %x %y }
bind TCombobox <Double-ButtonPress-1> 	{ ttk::combobox::Press "2" %W %x %y }
bind TCombobox <Triple-ButtonPress-1> 	{ ttk::combobox::Press "3" %W %x %y }
bind TCombobox <B1-Motion>		{ ttk::combobox::Drag %W %x }
bind TCombobox <Motion>			{ ttk::combobox::Motion %W %x %y }

ttk::bindMouseWheel TCombobox		{ ttk::combobox::Scroll %W }
ttk::bindMouseWheel TCombobox [list ttk::combobox::Scroll %W]
bind TCombobox <Shift-MouseWheel> {
    # Ignore the event
}

bind TCombobox <TouchpadScroll> {
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    # TouchpadScroll events fire about 60 times per second.
    if {$deltaY != 0 && %# %% 15 == 0} {
	ttk::combobox::Scroll %W [expr {$deltaY > 0 ? -1 : 1}]
    }
}
bind TCombobox <<TraverseIn>> 		{ ttk::combobox::TraverseIn %W }

### Combobox listbox bindings.
#
bind ComboboxListbox <ButtonRelease-1>	{ ttk::combobox::LBSelected %W }
bind ComboboxListbox <Return>		{ ttk::combobox::LBSelected %W }
bind ComboboxListbox <Escape>		{ ttk::combobox::LBCancel %W }
bind ComboboxListbox <Tab>		{ ttk::combobox::LBTab %W next }
bind ComboboxListbox <KeyPress-Return>	{ ttk::combobox::LBSelected %W }
bind ComboboxListbox <KeyPress-Escape>  { ttk::combobox::LBCancel %W }
bind ComboboxListbox <KeyPress-Tab>	{ ttk::combobox::LBTab %W next }
bind ComboboxListbox <<PrevWindow>>	{ ttk::combobox::LBTab %W prev }
bind ComboboxListbox <Destroy>		{ ttk::combobox::LBCleanup %W }
bind ComboboxListbox <Motion>		{ ttk::combobox::LBHover %W %x %y }
bind ComboboxListbox <Map>		{ focus -force %W }

switch -- [tk windowingsystem] {
    win32 {
	# Dismiss listbox when user switches to a different application.
	# NB: *only* do this on Windows (see #1814778)
	bind ComboboxListbox <FocusOut>		{ ttk::combobox::LBCancel %W }
    }
    aqua {
	bind TCombobox <Destroy>		{ ttk::combobox::AquaCleanup %W }
    }
}

### Combobox popdown window bindings.
#
bind ComboboxPopdown	<Map>		{ ttk::combobox::MapPopdown %W }
bind ComboboxPopdown	<Unmap>		{ ttk::combobox::UnmapPopdown %W }
bind ComboboxPopdown	<Button> \
bind ComboboxPopdown	<ButtonPress> \
			{ ttk::combobox::Unpost [winfo parent %W] }

### Option database settings.
#

option add *TCombobox*Listbox.font TkTextFont widgetDefault
option add *TCombobox*Listbox.relief flat widgetDefault
option add *TCombobox*Listbox.highlightThickness 0 widgetDefault
option add *TCombobox*Listbox.font TkTextFont
option add *TCombobox*Listbox.relief flat
option add *TCombobox*Listbox.highlightThickness 0

## Platform-specific settings.
#
switch -- [tk windowingsystem] {
    x11 {
	option add *TCombobox*Listbox.background white widgetDefault
	option add *TCombobox*Listbox.background white
    }
    aqua {
	option add *TCombobox*Listbox.borderWidth 0
    }
}

### Binding procedures.
#

## Press $mode $x $y -- Button binding for comboboxes.
## Press $mode $x $y -- ButtonPress binding for comboboxes.
#	Either post/unpost the listbox, or perform Entry widget binding,
#	depending on widget state and location of button press.
#
proc ttk::combobox::Press {mode w x y} {
    variable State

    $w instate disabled { return }
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151


152
153
154
155
156

157
158
159
160
161
162
163
164







-
+













-
-





-
+







	}
    } else {
	Post $w
    }
}

## Drag -- B1-Motion binding for comboboxes.
#	If the initial Button event was handled by Entry binding,
#	If the initial ButtonPress event was handled by Entry binding,
#	perform Entry widget drag binding; otherwise nothing.
#
proc ttk::combobox::Drag {w x}  {
    variable State
    if {$State(entryPress)} {
	ttk::entry::Drag $w $x
    }
}

## Motion --
#	Set cursor.
#
proc ttk::combobox::Motion {w x y} {
    variable State
    ttk::saveCursor $w State(userConfCursor) [ttk::cursor text]
    if {   [$w identify $x $y] eq "textarea"
        && [$w instate {!readonly !disabled}]
    } {
	ttk::setCursor $w text
    } else {
	ttk::setCursor $w $State(userConfCursor)
	ttk::setCursor $w ""
    }
}

## TraverseIn -- receive focus due to keyboard navigation
#	For editable comboboxes, set the selection and insert cursor.
#
proc ttk::combobox::TraverseIn {w} {
184
185
186
187
188
189
190
191

192
193
194
195

196
197
198
199
200
201
202
203
204


205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230

231
232
233
234
235
236
237
176
177
178
179
180
181
182

183
184
185
186

187









188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214

215
216
217
218
219
220
221
222







-
+



-
+
-
-
-
-
-
-
-
-
-
+
+








-
+









-
+






-
+







    $cb selection range 0 end
    $cb icursor end
    event generate $cb <<ComboboxSelected>> -when mark
}

## Scroll -- Mousewheel binding
#
proc ttk::combobox::Scroll {cb dir {factor 1.0}} {
proc ttk::combobox::Scroll {cb dir} {
    $cb instate disabled { return }
    set max [llength [$cb cget -values]]
    set current [$cb current]
    if {$current < 0} {
    incr current $dir
	set index 0
    } else {
	set d [expr {$dir/$factor}]
	set index [expr {$current + int($d > 0 ? ceil($d) : floor($d))}]
	if {$index >= $max} {set index [expr {$max - 1}]}
	if {$index < 0} {set index 0}
    }
    if {$max != 0 && $index != $current} {
	SelectEntry $cb $index
    if {$max != 0 && $current == $current % $max} {
	SelectEntry $cb $current
    }
}

## LBSelected $lb -- Activation binding for listbox
#	Set the combobox value to the currently-selected listbox value
#	and unpost the listbox.
#
proc ttk::combobox::LBSelected {lb} {
    set cb [LBMain $lb]
    set cb [LBMaster $lb]
    LBSelect $lb
    Unpost $cb
    focus $cb
}

## LBCancel --
#	Unpost the listbox.
#
proc ttk::combobox::LBCancel {lb} {
    Unpost [LBMain $lb]
    Unpost [LBMaster $lb]
}

## LBTab -- Tab key binding for combobox listbox.
#	Set the selection, and navigate to next/prev widget.
#
proc ttk::combobox::LBTab {lb dir} {
    set cb [LBMain $lb]
    set cb [LBMaster $lb]
    switch -- $dir {
	next	{ set newFocus [tk_focusNext $cb] }
	prev	{ set newFocus [tk_focusPrev $cb] }
    }

    if {$newFocus ne ""} {
	LBSelect $lb
261
262
263
264
265
266
267












268
269
270
271
272
273
274
275
276
277
278






279
280
281
282
283
284
285
286
287
288









289
290
291


292
293
294
295
296




297
298
299
300
301
302





303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269






270
271
272
273
274
275
276









277
278
279
280
281
282
283
284
285
286


287
288
289




290
291
292
293
294





295
296
297
298
299
















300
301
302
303
304
305
306







+
+
+
+
+
+
+
+
+
+
+
+





-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








## UnmapPopdown -- <Unmap> binding for ComboboxPopdown
#
proc ttk::combobox::UnmapPopdown {w} {
    [winfo parent $w] state !pressed
    ttk::releaseGrab $w
}

###
#

namespace eval ::ttk::combobox {
    # @@@ Until we have a proper native scrollbar on Aqua, use
    # @@@ the regular Tk one.  Use ttk::scrollbar on other platforms.
    variable scrollbar ttk::scrollbar
    if {[tk windowingsystem] eq "aqua"} {
	set scrollbar ::scrollbar
    }
}

## PopdownWindow --
#	Returns the popdown widget associated with a combobox,
#	creating it if necessary.
#

if {[tk windowingsystem] ne "aqua"} {
    proc ttk::combobox::PopdownWindow {cb} {
	if {![winfo exists $cb.popdown]} {
	    set poplevel [PopdownToplevel $cb.popdown]
	    set popdown [ttk::frame $poplevel.f -style ComboboxPopdownFrame]
proc ttk::combobox::PopdownWindow {cb} {
    variable scrollbar

    if {![winfo exists $cb.popdown]} {
	set poplevel [PopdownToplevel $cb.popdown]
	set popdown [ttk::frame $poplevel.f -style ComboboxPopdownFrame]

	    ttk::scrollbar $popdown.sb \
		-orient vertical -command [list $popdown.l yview]
	    listbox $popdown.l \
		-listvariable ttk::combobox::Values($cb) \
		-yscrollcommand [list $popdown.sb set] \
		-exportselection false \
		-selectmode browse \
		-activestyle none \
		;
	$scrollbar $popdown.sb \
	    -orient vertical -command [list $popdown.l yview]
	listbox $popdown.l \
	    -listvariable ttk::combobox::Values($cb) \
	    -yscrollcommand [list $popdown.sb set] \
	    -exportselection false \
	    -selectmode browse \
	    -activestyle none \
	    ;

	    bindtags $popdown.l \
		[list $popdown.l ComboboxListbox Listbox $popdown all]
	bindtags $popdown.l \
	    [list $popdown.l ComboboxListbox Listbox $popdown all]

	    grid $popdown.l -row 0 -column 0 -padx {1 0} -pady 1 -sticky nsew
	    grid $popdown.sb -row 0 -column 1 -padx {0 1} -pady 1 -sticky ns
	    grid columnconfigure $popdown 0 -weight 1
	    grid rowconfigure $popdown 0 -weight 1
	grid $popdown.l -row 0 -column 0 -padx {1 0} -pady 1 -sticky nsew
        grid $popdown.sb -row 0 -column 1 -padx {0 1} -pady 1 -sticky ns
	grid columnconfigure $popdown 0 -weight 1
	grid rowconfigure $popdown 0 -weight 1

	    grid $popdown -sticky news -padx 0 -pady 0
	    grid rowconfigure $poplevel 0 -weight 1
	    grid columnconfigure $poplevel 0 -weight 1
	}
	return $cb.popdown
        grid $popdown -sticky news -padx 0 -pady 0
        grid rowconfigure $poplevel 0 -weight 1
        grid columnconfigure $poplevel 0 -weight 1
    }
    return $cb.popdown
    }
} else {
    proc ttk::combobox::PopdownWindow {cb} {
	if {![winfo exists $cb.popdown]} {
	    set poplevel [PopdownToplevel $cb.popdown]
	    # The menu should be (at least) the same length as the button.
	    # Since there is no direct way to control the width of a menu
	    # in Tk, we fake it by using an invisible image in a disabled
	    # menu item, adjusting the image size to make the menu be the
	    # correct width.
	    image create nsimage $cb.spacer -source NSStatusNone -as name \
		-alpha 0
	    set menu [menu $cb.popdown.menu -tearoff 0]
	}
	return $cb.popdown
    }
}

## PopdownToplevel -- Create toplevel window for the combobox popdown
#
#	See also <<NOTE-WM-TRANSIENT>>
#
proc ttk::combobox::PopdownToplevel {w} {
334
335
336
337
338
339
340


341
342


343
344
345
346
347
348
349
315
316
317
318
319
320
321
322
323


324
325
326
327
328
329
330
331
332







+
+
-
-
+
+







	}
	win32 {
	    $w configure -relief flat -borderwidth 0
	    wm overrideredirect $w true
	    wm attributes $w -topmost 1
	}
	aqua {
	    $w configure -relief solid -borderwidth 0
	    tk::unsupported::MacWindowStyle style $w \
	    wm overrideredirect $w true
	    wm attributes $w -alpha 0
	    	help {noActivates hideOnSuspend}
	    wm resizable $w 0 0
	}
    }
    return $w
}

## ConfigureListbox --
#	Set listbox values, selection, height, and scrollbar visibility
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458
459
460




461
462

463
464
465
466



467
468
469
470
471
472
473
474
475








476
477
478
479
480
481





482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523

524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360

































361
362
363
364
365
366
367
368
369
370
371



372
373

374
375
376
377
378
379
380
381
382
383
384
385














386

387
388





389
390
391
392
393

394
395



396
397
398
399








400
401
402
403
404
405
406
407
408





409
410
411
412
413


























414
415
416
417
418
419
420
421
422
423
424
425

426
427
428

429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

454




455
456
457







-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
-
-


-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
-
-
-
-
+
+
+
+

-
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+


-
+







-
+
















-
+
-
-
-
-



    $popdown.l selection clear 0 end
    $popdown.l selection set $current
    $popdown.l activate $current
    $popdown.l see $current
    set height [llength $values]
    if {$height > [$cb cget -height]} {
	set height [$cb cget -height]
	grid $popdown.sb
    	grid $popdown.sb
        grid configure $popdown.l -padx {1 0}
    } else {
	grid remove $popdown.sb
        grid configure $popdown.l -padx 1
    }
    $popdown.l configure -height $height
}

proc ttk::combobox::ConfigureAquaMenu {cb width} {
    set popdown [PopdownWindow $cb]
    set values [$cb cget -values]
    set current [$cb current]
    if {$current < 0} {
	set current 0 		;# no current entry, highlight first one
    }
    $cb.popdown.menu delete 0 end
    $cb.spacer configure -width [expr {$width - 40}] -height 1
    set i 0
    foreach item $values {
	if {$i == 0} {
	    # Add spaces to the first item to make the menu as long as cb
	    set menufont [$cb cget -font]
	    set stretch $item
	    while {[font measure $menufont $stretch] < [expr {$width - 32}]} {
		set stretch "$stretch "
	    }
	    $cb.popdown.menu add command -label "$stretch" \
		-command "ttk::combobox::SelectEntry $cb $i"
	} else {
	    $cb.popdown.menu add command -label "$item" \
		-command "ttk::combobox::SelectEntry $cb $i"
	}
	incr i
    }
    if { $i == 0 } {
	# There are no items.  To make an empty menu appear add a dummy item
	# containing a transparent image of the right width.
	$cb.popdown.menu add command -label {} -image $cb.spacer -state disabled
    }
}

## PlacePopdown --
#	Set popdown window geometry.
#
# @@@TODO: factor with menubutton::PostPosition
#
proc ttk::combobox::PlacePopdown {cb popdown} {
    set x [winfo rootx $cb]
    set y [winfo rooty $cb]
    set w [winfo width $cb]
    set h [winfo height $cb]
    set style [$cb cget -style]
    if { $style eq {} } {
      set style TCombobox
    }
    set postoffset [ttk::style lookup $style -postoffset {} {0 0 0 0}]
    foreach var {x y w h} delta $postoffset {
	incr $var $delta
    	incr $var $delta
    }

    set H [winfo reqheight $popdown]
    if {$y + $h + $H > [winfo screenheight $popdown]} {
	set Y [expr {$y - $H}]
    } else {
	set Y [expr {$y + $h}]
    }
    wm geometry $popdown ${w}x${H}+${x}+${Y}
}

proc ttk::combobox::AquaPlacePopdown {cb popdown} {
    set x [winfo rootx $cb]
    set y [winfo rooty $cb]
    set w [winfo width $cb]
    set h [winfo height $cb]
    set style [$cb cget -style]
    set postoffset [ttk::style lookup $style -postoffset {} {0 0 0 0}]
    foreach var {x y w h} delta $postoffset {
    	incr $var $delta
    }
    wm geometry $popdown ${w}x${h}+${x}+${y}
    return [list $x $y $w $h]
}

## Post $cb --
#	Pop down the associated listbox or menu.
#	Pop down the associated listbox.
#
if {[tk windowingsystem] ne "aqua"} {
    proc ttk::combobox::Post {cb} {
	# Don't do anything if disabled:
	#
	$cb instate disabled { return }
proc ttk::combobox::Post {cb} {
    # Don't do anything if disabled:
    #
    $cb instate disabled { return }

	# ASSERT: ![$cb instate pressed]
    # ASSERT: ![$cb instate pressed]

	# Run -postcommand callback:
	#
	uplevel #0 [$cb cget -postcommand]
    # Run -postcommand callback:
    #
    uplevel #0 [$cb cget -postcommand]

	set popdown [PopdownWindow $cb]
	ConfigureListbox $cb
	update idletasks	;# needed for geometry propagation.
	PlacePopdown $cb $popdown
	# See <<NOTE-WM-TRANSIENT>>
	switch -- [tk windowingsystem] {
	    x11 - win32 { wm transient $popdown [winfo toplevel $cb] }
	}
    set popdown [PopdownWindow $cb]
    ConfigureListbox $cb
    update idletasks	;# needed for geometry propagation.
    PlacePopdown $cb $popdown
    # See <<NOTE-WM-TRANSIENT>>
    switch -- [tk windowingsystem] {
	x11 - win32 { wm transient $popdown [winfo toplevel $cb] }
    }

	# Post the listbox:
	#
	wm attribute $popdown -topmost 1
	wm deiconify $popdown
	raise $popdown
    # Post the listbox:
    #
    wm attribute $popdown -topmost 1
    wm deiconify $popdown
    raise $popdown
    }
} else {
    proc ttk::combobox::Post {cb} {
	# Don't do anything if disabled:
	#
	$cb instate disabled { return }

	# ASSERT: ![$cb instate pressed]

	# Run -postcommand callback:
	#
	uplevel #0 [$cb cget -postcommand]

	set popdown [PopdownWindow $cb]

	# Configure the menu

	foreach {x y width height} [AquaPlacePopdown $cb $popdown] { break }
	ConfigureAquaMenu $cb [winfo width $cb]

	# Post the menu.  It will have a disclosure indicator if it is too
	# close to the bottom of the screen, and it may be posted above the
	# button if necessary to be visible.

	$popdown.menu post [expr {$x + 2}] [expr {$y + $height + 2}]
    }
}

## Unpost $cb --
#	Unpost the listbox.
#
proc ttk::combobox::Unpost {cb} {
    if {[winfo exists $cb.popdown]} {
	wm withdraw $cb.popdown
    }
    grab release $cb.popdown ;# in case of stuck or unexpected grab [#1239190]
}

## LBMain $lb --
## LBMaster $lb --
#	Return the combobox main widget that owns the listbox.
#
proc ttk::combobox::LBMain {lb} {
proc ttk::combobox::LBMaster {lb} {
    winfo parent [winfo parent [winfo parent $lb]]
}

## LBSelect $lb --
#	Transfer listbox selection to combobox value.
#
proc ttk::combobox::LBSelect {lb} {
    set cb [LBMain $lb]
    set cb [LBMaster $lb]
    set selection [$lb curselection]
    if {[llength $selection] == 1} {
	SelectEntry $cb [lindex $selection 0]
    }
}

## LBCleanup $lb --
#	<Destroy> binding for combobox listboxes.
#	Cleans up by unsetting the linked textvariable.
#
#	Note: we can't just use { unset [%W cget -listvariable] }
#	because the widget command is already gone when this binding fires).
#	[winfo parent] still works, fortunately.
#
proc ttk::combobox::LBCleanup {lb} {
    variable Values
    unset Values([LBMain $lb])
    unset Values([LBMaster $lb])
}

proc ttk::combobox::AquaCleanup {cb} {
    catch {image delete $cb.spacer}
}

#*EOF*

Changes to library/ttk/cursors.tcl.

95
96
97
98
99
100
101


102
103
104
105
106
107
108







109
110
111
112
113
114
115







116
117
118
119
120
121
122
95
96
97
98
99
100
101
102
103







104
105
106
107
108
109
110
111






112
113
114
115
116
117
118
119
120
121
122
123
124
125







+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+








		neresize	size_ne_sw
		seresize	size_nw_se
	    }
	}

	"aqua" {
	    if {[package vsatisfies [package provide Tk] 8.5]} {
		# appeared 2007-04-23, Tk 8.5a6
	    array set Cursors {
		standard	arrow
		text 	ibeam
		link	pointinghand
		crosshair	crosshair
		busy	watch
		forbidden	notallowed
		array set Cursors {
		    standard	arrow
		    text 	ibeam
		    link	pointinghand
		    crosshair	crosshair
		    busy	watch
		    forbidden	notallowed

		hresize 	resizeleftright
		vresize 	resizeupdown
		nresize	resizeup
		sresize	resizedown
		wresize	resizeleft
		eresize	resizeright
		    hresize 	resizeleftright
		    vresize 	resizeupdown
		    nresize	resizeup
		    sresize	resizedown
		    wresize	resizeleft
		    eresize	resizeright
		}
	    }
	}
    }
}

## ttk::cursor $cursor --
#	Return platform-specific cursor for specified symbolic cursor.
133
134
135
136
137
138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
136
137
138
139
140
141
142







143
144

















145
146
147
148
149
150
151







-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







# instead of directly calling [$w configure -cursor ...],
# as the latter always incurs a server round-trip and
# can lead to high CPU load (see [#1184746])
#

proc ttk::setCursor {w name} {
    variable Cursors
    if {[info exists Cursors($name)]} {
        set cursorname $Cursors($name)
    }  else {
        set cursorname $name
    }
    if {[$w cget -cursor] ne $cursorname} {
        $w configure -cursor $cursorname
    if {[$w cget -cursor] ne $Cursors($name)} {
	$w configure -cursor $Cursors($name)
    }
}

## ttk::saveCursor $w $saveVar $excludeList --
#       Set variable $saveVar to the -cursor value from widget $w,
#       if either:
#       a. $saveVar does not yet exist
#       b. the currently user-specified cursor for $w is not in
#          $excludeList

proc ttk::saveCursor {w saveVar excludeList} {
    upvar $saveVar sv
    if {![info exists sv]} {
        set sv [$w cget -cursor]
    }
    if {[$w cget -cursor] ni $excludeList} {
        set sv [$w cget -cursor]
    }
}

## Interactive test harness:
#
proc ttk::CursorSampler {f} {
    ttk::frame $f
194
195
196
197
198
199
200
201

202
203
204
205
175
176
177
178
179
180
181

182
183
184
185
186







-
+





    return $f
}

if {[info exists argv0] && $argv0 eq [info script]} {
    wm title . "[array size ::ttk::Cursors] cursors"
    pack [ttk::CursorSampler .f] -expand true -fill both
    bind . <Escape> [list destroy .]
    bind . <KeyPress-Escape> [list destroy .]
    focus .f
}

#*EOF*

Changes to library/ttk/defaults.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97

98

99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114





115
116

117
118
119


120
121

122
123
124












125
126
127

128
129
130
131
132
133

134
135
136
137
138

139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169

170
171

172
173
174
175
176
177

178
179

180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199

200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
1
2
3
4
5

6
7
8
9
10

11
12
13
14
15
16
17
18

19


20




























21
































22
23
24
25
26
27
28
29
30

31
32
33
34

35

36
37
38
39
40
41
42
43

44
45
46
47





48
49
50
51
52


53



54
55


56



57
58
59
60
61
62
63
64
65
66
67
68
69
70

71



72
73

74

75
76
77

78



79
80
81
82

83



84
85
86
87
88
89
90
91

92
93
94
95
96







97
98

99



100
101

102
103

104


105
106
107
108


109
110



111




112


113


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141







-





-








-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+



-
+
-
+







-
+



-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
+
+
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-


-
+
-



-
+
-
-
-




-
+
-
-
-








-
+




-
-
-
-
-
-
-
+

-
+
-
-
-


-
+

-
+
-
-




-
-


-
-
-
+
-
-
-
-

-
-
+
-
-
+




















-
+






-
-
#
# Settings for default theme.
#

namespace eval ttk::theme::default {

    variable colors
    array set colors {
	-frame			"#d9d9d9"
	-foreground		"#000000"
	-window			"#ffffff"
	-alternate		"#e8e8e8"
	-text   		"#000000"
	-activebg		"#ececec"
	-selectbg		"#4a6984"
	-selectfg		"#ffffff"
	-darker 		"#c3c3c3"
	-disabledfg		"#a3a3a3"
	-indicator		"#4a6984"
	-disabledindicator	"#a3a3a3"
	-pressedindicator	"#5895bc"
	-altindicator		"#9fbdd8"
    }

	-disabledaltindicator	"#c0c0c0"
    # On X11, if the user specifies their own choice of colour scheme via
    # X resources, then set the colour palette based on the user's choice.
    if {[tk windowingsystem] eq "x11"} {
	foreach \
		xResourceName {
		    {	background		Background		}
		    {	foreground		Foreground		}
		    {	background		Background		}
		    {	background		Background		}
		    {	foreground		Foreground		}
		    {	activeBackground	ActiveBackground	}
		    {	selectBackground	SelectBackground	}
		    {	selectForeground	SelectForeground	}
		    {	troughColor		TroughColor		}
		    {	disabledForeground	DisabledForeground	}
		    {	selectBackground	SelectBackground	}
		    {	disabledForeground	DisabledForeground	}
		    {	selectBackground	SelectBackground	}
		    {	windowColor		Background		} } \
		colorName {
		    -frame -foreground -window -alternate -text
		    -activebg -selectbg -selectfg
		    -darker -disabledfg -indicator
		    -disabledindicator -pressedindicator -window } {
	    set color [eval option get . $xResourceName]
	    if {$color ne ""} {
		set colors($colorName) $color
	    }
    }
	}
    }

    # This array is used to match up the tk widget options with
    # the corresponding values in the 'colors' array.
    # This is used by tk_setPalette to apply the new palette
    # to the ttk widgets.
    variable colorOptionLookup
    array set colorOptionLookup {
	background		{-frame -window -alternate}
	foreground		{-foreground -text}
	activeBackground	-activebg
	selectBackground	{-selectbg -indicator -pressedindicator}
	selectForeground	-selectfg
	troughColor		-darker
	disabledForeground	{-disabledfg -disabledindicator}
    }
}

# ttk::theme::default::reconfigureDefaultTheme --
#
# This procedure contains the definition of the 'default' theme itself.
# The theme definition is in a procedure, so it can be re-called when
# required, enabling tk_setPalette to set the colours of the ttk widgets.
#
# Arguments:
# None.

proc ttk::theme::default::reconfigureDefaultTheme {} {
    upvar ttk::theme::default::colors colors

    # The definition of the 'default' theme.

    ttk::style theme settings default {

	ttk::style configure "." \
	    -borderwidth 	1 \
	    -background 	$colors(-frame) \
	    -foreground 	$colors(-foreground) \
	    -troughcolor 	$colors(-darker) \
	    -font 		TkDefaultFont \
	    -selectborderwidth	0 \
	    -selectborderwidth	1 \
	    -selectbackground	$colors(-selectbg) \
	    -selectforeground	$colors(-selectfg) \
	    -insertwidth 	1 \
	    -insertcolor	$colors(-foreground) \
	    -indicatordiameter	10 \
	    -focuscolor		$colors(-text)
	    ;

	ttk::style map "." -background \
	    [list disabled $colors(-frame)  active $colors(-activebg)]
	ttk::style map "." -foreground \
	    [list disabled $colors(-disabledfg)]

	ttk::style configure TButton \
	    -anchor center -padding 2.25p -width -9 \
	    -anchor center -padding "3 3" -width -9 \
	    -relief raised -shiftrelief 1
	ttk::style map TButton -relief [list {!disabled pressed} sunken]

	foreach style {TCheckbutton TRadiobutton} {
	    ttk::style configure $style \
		-indicatorbackground $colors(-window) \
		-indicatorforeground $colors(-selectfg) \
		-indicatormargin {0 1.5p 3p 1.5p} -padding 0.75p
	ttk::style configure TCheckbutton \
	    -indicatorcolor "#ffffff" -indicatorrelief sunken -padding 1
	ttk::style map TCheckbutton -indicatorcolor \
	    [list pressed $colors(-activebg)  \
			{!disabled alternate} $colors(-altindicator) \
	    ttk::style map $style -indicatorbackground \
		[list {alternate disabled}	$colors(-disabledindicator) \
			{disabled alternate} $colors(-disabledaltindicator) \
		      {alternate pressed}	$colors(-pressedindicator) \
		      alternate			$colors(-indicator) \
		      {selected disabled}	$colors(-disabledindicator) \
			{!disabled selected} $colors(-indicator) \
			{disabled selected} $colors(-disabledindicator)]
		      {selected pressed}	$colors(-pressedindicator) \
		      selected			$colors(-indicator) \
	ttk::style map TCheckbutton -indicatorrelief \
		      disabled			$colors(-frame) \
		      pressed			$colors(-darker)]
	}
	    [list alternate raised]

	ttk::style configure TRadiobutton \
	    -indicatorcolor "#ffffff" -indicatorrelief sunken -padding 1
	ttk::style map TRadiobutton -indicatorcolor \
	    [list pressed $colors(-activebg)  \
			{!disabled alternate} $colors(-altindicator) \
			{disabled alternate} $colors(-disabledaltindicator) \
			{!disabled selected} $colors(-indicator) \
			{disabled selected} $colors(-disabledindicator)]
	ttk::style map TRadiobutton -indicatorrelief \
	    [list alternate raised]

	ttk::style configure TMenubutton \
	    -relief raised -arrowsize 3.75p -arrowpadding 2.25p \
	    -relief raised -padding "10 3"
	    -arrowcolor $colors(-text) -padding {7.5p 2.25p}
	ttk::style map TMenubutton \
	    -arrowcolor [list disabled $colors(-disabledfg)]

	ttk::style configure TEntry \
	    -fieldbackground $colors(-window) -padding 1 \
	    -relief sunken -fieldbackground white -padding 1
	    -focuswidth 2 -focuscolor $colors(-selectbg)
	ttk::style map TEntry -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)]

	ttk::style configure TCombobox \
	ttk::style configure TCombobox -arrowsize 12 -padding 1
	    -arrowsize 9p -arrowcolor $colors(-text) \
	    -fieldbackground $colors(-window) -padding 1 \
	    -focuswidth 1 -focuscolor $colors(-selectbg)
	ttk::style map TCombobox -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)] \
	    -arrowcolor [list disabled $colors(-disabledfg)]

	ttk::style configure TSpinbox \
	ttk::style configure TSpinbox -arrowsize 10 -padding {2 0 10 0}
	    -arrowsize 7.5p -arrowcolor $colors(-text) \
	    -fieldbackground $colors(-window) -padding {1.5p 0 7.5p 0} \
	    -focuswidth 1 -focuscolor $colors(-selectbg)
	ttk::style map TSpinbox -fieldbackground \
	    [list readonly $colors(-frame) disabled $colors(-frame)] \
	    -arrowcolor [list disabled $colors(-disabledfg)]

	ttk::style configure TLabelframe \
	    -relief groove -borderwidth 2

	ttk::style configure TScrollbar \
	    -width 9p -arrowsize 9p -arrowcolor $colors(-text)
	    -width 12 -arrowsize 12
	ttk::style map TScrollbar \
	    -arrowcolor [list disabled $colors(-disabledfg)]

	ttk::style configure TScale \
	    -innercolor $colors(-selectbg) \
	    -outercolor $colors(-window) \
	    -bordercolor $colors(-darker) \
	    -groovewidth 3p
	ttk::style map TScale \
	    -outercolor [list active $colors(-activebg)]

	    -sliderrelief raised
	ttk::style configure TProgressbar \
	    -background $colors(-selectbg) \
	    -background $colors(-selectbg)
	    -borderwidth 0 \
	    -barsize 22.5p \
	    -thickness 3p

	ttk::style configure TNotebook.Tab \
	    -padding {3p 1.5p} -background $colors(-darker)
	    -padding {4 2} -background $colors(-darker)
	ttk::style map TNotebook.Tab \
	    -background [list selected $colors(-frame)] \
	    -background [list selected $colors(-frame)]
	    -highlight [list selected 1] \
	    -highlightcolor [list selected $colors(-selectbg)]

	# Treeview.
	#
	ttk::style configure Heading -font TkHeadingFont -relief raised
	ttk::style configure Item -indicatorsize 9p \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Treeview \
	    -background $colors(-window) \
	    -stripedbackground $colors(-alternate) \
	    -fieldbackground $colors(-window) \
	    -foreground $colors(-text) \
	    -foreground $colors(-text) ;
	    -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style configure Treeview.Separator \
	    -background $colors(-alternate)
	ttk::style map Treeview \
	    -background [list disabled $colors(-frame)\
				selected $colors(-selectbg)] \
	    -background [list selected $colors(-selectbg)] \
	    -foreground [list disabled $colors(-disabledfg) \
				selected $colors(-selectfg)]
	    -foreground [list selected $colors(-selectfg)] ;

	# Combobox popdown frame
	ttk::style layout ComboboxPopdownFrame {
	    ComboboxPopdownFrame.border -sticky nswe
	}
 	ttk::style configure ComboboxPopdownFrame \
	    -borderwidth 1 -relief solid

	#
	# Toolbar buttons:
	#
	ttk::style layout Toolbutton {
	    Toolbutton.border -children {
		Toolbutton.padding -children {
		    Toolbutton.label
		}
	    }
	}

	ttk::style configure Toolbutton \
	    -padding 1.5p -relief flat
	    -padding 2 -relief flat
	ttk::style map Toolbutton -relief \
	    [list disabled flat selected sunken pressed sunken active raised]
	ttk::style map Toolbutton -background \
	    [list pressed $colors(-darker)  active $colors(-activebg)]
    }
}

ttk::theme::default::reconfigureDefaultTheme

Changes to library/ttk/entry.tcl.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







#
# DERIVED FROM: tk/library/entry.tcl r1.22
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 2004, Joe English
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 2004, Joe English
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

namespace eval ttk {
    namespace eval entry {
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44


45
46

47
48
49

50
51
52


53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74




75
76
77
78
79



80
81
82
83
84
85
86
87

88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117
118
119
120



121
122
123


124
125
126
127
128
129
130
131
132
133












134
135

136
137
138
139
140
141
142
143
144



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
30
31
32
33
34
35
36

37
38
39
40
41
42


43
44
45

46
47
48

49
50


51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70




71
72
73
74
75
76



77
78
79
80
81
82
83
84
85
86

87

88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116



117
118
119
120


121
122
123
124








125
126
127
128
129
130
131
132
133
134
135
136


137
138
139
140
141
142
143



144
145
146
































147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+





-
-
+
+

-
+


-
+

-
-
+
+



-
+














-
-
-
-
+
+
+
+


-
-
-
+
+
+







-
+
-

-
+
















-
+










-
-
-
+
+
+

-
-
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+






-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+







	set State(scanDen) 1
	set State(deadband) 3	;# #pixels for mouse-moved deadband.
    }
}

### Option database settings.
#
option add *TEntry.cursor [ttk::cursor text] widgetDefault
option add *TEntry.cursor [ttk::cursor text]

### Bindings.
#
# Removed the following standard Tk bindings:
#
# <Control-space>, <Control-Shift-space>,
# <Select>,  <Shift-Select>:
# <Control-Key-space>, <Control-Shift-Key-space>,
# <Key-Select>,  <Shift-Key-Select>:
#	Ttk entry widget doesn't use selection anchor.
# <Insert>:
# <Key-Insert>:
#	Inserts PRIMARY selection (on non-Windows platforms).
#	This is inconsistent with typical platform bindings.
# <Double-Shift-Button-1>, <Triple-Shift-Button-1>:
# <Double-Shift-ButtonPress-1>, <Triple-Shift-ButtonPress-1>:
#	These don't do the right thing to start with.
# <Meta-b>, <Meta-d>, <Meta-f>,
# <Meta-BackSpace>, <Meta-Delete>:
# <Meta-Key-b>, <Meta-Key-d>, <Meta-Key-f>,
# <Meta-Key-BackSpace>, <Meta-Key-Delete>:
#	Judgment call.  If <Meta> happens to be assigned to the Alt key,
#	these could conflict with application accelerators.
#	(Plus, who has a Meta key these days?)
# <Control-t>:
# <Control-Key-t>:
#	Another judgment call.  If anyone misses this, let me know
#	and I'll put it back.
#

## Clipboard events:
#
bind TEntry <<Cut>> 			{ ttk::entry::Cut %W }
bind TEntry <<Copy>> 			{ ttk::entry::Copy %W }
bind TEntry <<Paste>> 			{ ttk::entry::Paste %W }
bind TEntry <<Clear>> 			{ ttk::entry::Clear %W }

## Button1 bindings:
#	Used for selection and navigation.
#
bind TEntry <Button-1> 			{ ttk::entry::Press %W %x }
bind TEntry <Shift-Button-1>		{ ttk::entry::Shift-Press %W %x }
bind TEntry <Double-Button-1> 		{ ttk::entry::Select %W %x word }
bind TEntry <Triple-Button-1> 		{ ttk::entry::Select %W %x line }
bind TEntry <ButtonPress-1> 		{ ttk::entry::Press %W %x }
bind TEntry <Shift-ButtonPress-1>	{ ttk::entry::Shift-Press %W %x }
bind TEntry <Double-ButtonPress-1> 	{ ttk::entry::Select %W %x word }
bind TEntry <Triple-ButtonPress-1> 	{ ttk::entry::Select %W %x line }
bind TEntry <B1-Motion>			{ ttk::entry::Drag %W %x }

bind TEntry <B1-Leave> 			{ ttk::entry::DragOut %W %m }
bind TEntry <B1-Enter>			{ ttk::entry::DragIn %W }
bind TEntry <ButtonRelease-1>		{ ttk::entry::Release %W }
bind TEntry <B1-Leave> 		{ ttk::entry::DragOut %W %m }
bind TEntry <B1-Enter>		{ ttk::entry::DragIn %W }
bind TEntry <ButtonRelease-1>	{ ttk::entry::Release %W }

bind TEntry <<ToggleSelection>> {
    %W instate {!readonly !disabled} { %W icursor @%x ; focus %W }
}

## Button2 bindings:
#	Used for scanning and primary transfer.
#	Note: ButtonRelease-2
#	Note: ButtonRelease-2 is mapped to <<PasteSelection>> in tk.tcl.
#	is mapped to <<PasteSelection>> in tk.tcl.
#
bind TEntry <Button-2> 			{ ttk::entry::ScanMark %W %x }
bind TEntry <ButtonPress-2> 		{ ttk::entry::ScanMark %W %x }
bind TEntry <B2-Motion> 		{ ttk::entry::ScanDrag %W %x }
bind TEntry <ButtonRelease-2>		{ ttk::entry::ScanRelease %W %x }
bind TEntry <<PasteSelection>>		{ ttk::entry::ScanRelease %W %x }

## Keyboard navigation bindings:
#
bind TEntry <<PrevChar>>		{ ttk::entry::Move %W prevchar }
bind TEntry <<NextChar>> 		{ ttk::entry::Move %W nextchar }
bind TEntry <<PrevWord>>		{ ttk::entry::Move %W prevword }
bind TEntry <<NextWord>>		{ ttk::entry::Move %W nextword }
bind TEntry <<LineStart>>		{ ttk::entry::Move %W home }
bind TEntry <<LineEnd>>			{ ttk::entry::Move %W end }

bind TEntry <<SelectPrevChar>> 		{ ttk::entry::Extend %W prevchar }
bind TEntry <<SelectNextChar>>		{ ttk::entry::Extend %W nextchar }
bind TEntry <<SelectPrevWord>>		{ ttk::entry::Extend %W prevword }
bind TEntry <<SelectNextWord>>		{ ttk::entry::Extend %W selectnextword }
bind TEntry <<SelectNextWord>>		{ ttk::entry::Extend %W nextword }
bind TEntry <<SelectLineStart>>		{ ttk::entry::Extend %W home }
bind TEntry <<SelectLineEnd>>		{ ttk::entry::Extend %W end }

bind TEntry <<SelectAll>> 		{ %W selection range 0 end }
bind TEntry <<SelectNone>> 		{ %W selection clear }

bind TEntry <<TraverseIn>> 	{ %W selection range 0 end; %W icursor end }

## Edit bindings:
#
bind TEntry <Key> 			{ ttk::entry::Insert %W %A }
bind TEntry <Delete>			{ ttk::entry::Delete %W }
bind TEntry <BackSpace> 		{ ttk::entry::Backspace %W }
bind TEntry <KeyPress> 			{ ttk::entry::Insert %W %A }
bind TEntry <Key-Delete>		{ ttk::entry::Delete %W }
bind TEntry <Key-BackSpace> 		{ ttk::entry::Backspace %W }

# Ignore all Alt, Meta, Control, Command, and Fn keypresses unless explicitly bound.
# Otherwise, the <Key> class binding will fire and insert the character.
# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
# Otherwise, the <KeyPress> class binding will fire and insert the character.
# Ditto for Escape, Return, and Tab.
#
bind TEntry <Alt-Key>			{# nothing}
bind TEntry <Meta-Key>			{# nothing}
bind TEntry <Control-Key> 		{# nothing}
bind TEntry <Escape> 			{# nothing}
bind TEntry <Return> 			{# nothing}
bind TEntry <KP_Enter> 			{# nothing}
bind TEntry <Tab> 			{# nothing}
bind TEntry <Command-Key>		{# nothing}
bind TEntry <Alt-KeyPress>		{# nothing}
bind TEntry <Meta-KeyPress>		{# nothing}
bind TEntry <Control-KeyPress> 		{# nothing}
bind TEntry <Key-Escape> 		{# nothing}
bind TEntry <Key-Return> 		{# nothing}
bind TEntry <Key-KP_Enter> 		{# nothing}
bind TEntry <Key-Tab> 			{# nothing}

# Argh.  Apparently on Windows, the NumLock modifier is interpreted
# as a Command modifier.
if {[tk windowingsystem] eq "aqua"} {
    bind TEntry <Command-KeyPress>	{# nothing}
bind TEntry <Fn-Key>			{# nothing}

}
# Tk-on-Cocoa generates characters for these two keys. [Bug 2971663]
bind TEntry <<PrevLine>>		{# nothing}
bind TEntry <<NextLine>>		{# nothing}

## Additional emacs-like bindings:
#
bind TEntry <Control-d>			{ ttk::entry::Delete %W }
bind TEntry <Control-h>			{ ttk::entry::Backspace %W }
bind TEntry <Control-k>			{ %W delete insert end }
bind TEntry <Control-Key-d>		{ ttk::entry::Delete %W }
bind TEntry <Control-Key-h>		{ ttk::entry::Backspace %W }
bind TEntry <Control-Key-k>		{ %W delete insert end }

# Bindings for IME text input.

bind TEntry <<TkStartIMEMarkedText>> {
    dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
}
bind TEntry <<TkEndIMEMarkedText>> {
    if { [catch {dict get $::tk::Priv(IMETextMark) "%W"} mark] } {
	bell
    } else {
	%W selection range $mark insert
    }
}
bind TEntry <<TkClearIMEMarkedText>> {
    %W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert]
}
bind TEntry <<TkAccentBackspace>> {
    ttk::entry::Backspace %W
}

## EndIMEMarkedText -- Handle the end of input method selection.
#
proc ::ttk::entry::EndIMEMarkedText {w} {
    variable ::tk::Priv
    if {[catch {
	set mark [dict get $Priv(IMETextMark) $w]
    }]} {
	bell
	return
    }
    $w selection range $mark insert
}

### Clipboard procedures.
#

## EntrySelection -- Return the selected text of the entry.
#	Raises an error if there is no selection.
#
proc ttk::entry::EntrySelection {w} {
    set entryString [string range [$w get] [$w index sel.first] \
	    [$w index sel.last]-1]
	    [expr {[$w index sel.last] - 1}]]
    if {[$w cget -show] ne ""} {
	return [string repeat [string index [$w cget -show] 0] \
		[string length $entryString]]
    }
    return $entryString
}

237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253




254
255

256
257

258
259
260
261
262






263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326


327
328
329
330
331
332
333
334
335
336
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221



222
223
224
225
226

227


228





229
230
231
232
233
234
235
















236
237
238
239
240
241
242
243
244





245





















246
247
248
249
250
251
252
253
254
255


256
257
258
259

260
261
262
263
264
265
266







+







-
-
-
+
+
+
+

-
+
-
-
+
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
+
+


-







    }
    return $pos
}

## See $index -- Make sure that the character at $index is visible.
#
proc ttk::entry::See {w {index insert}} {
    update idletasks	;# ensure scroll data up-to-date
    set c [$w index $index]
    # @@@ OR: check [$w index left] / [$w index right]
    if {$c < [$w index @0] || $c >= [$w index @[winfo width $w]]} {
	$w xview $c
    }
}

## NextWord --
# Returns the index of the next start-of-word position after the next
# end-of-word position after a given position in the text.
## NextWord -- Find the next word position.
#	Note: The "next word position" follows platform conventions:
#	either the next end-of-word position, or the start-of-word
#	position following the next end-of-word position.
#
proc ttk::entry::NextWord {w start} {
set ::ttk::entry::State(startNext) \
    # the check on [winfo class] is because the spinbox and combobox also use this proc
    if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} {
	[string equal [tk windowingsystem] "win32"]
	return end
    }
    set pos [tk::endOfWord [$w get] [$w index $start]]
    if {$pos >= 0} {
	set pos [tk::startOfNextWord [$w get] $pos]

proc ttk::entry::NextWord {w start} {
    variable State
    set pos [tcl_endOfWord [$w get] [$w index $start]]
    if {$pos >= 0 && $State(startNext)} {
	set pos [tcl_startOfNextWord [$w get] $pos]
    }
    if {$pos < 0} {
	return end
    }
    return $pos
}

## SelectNextWord --
# Returns the index of the next end-of-word position after a given
# position in the text.
#
proc ttk::entry::SelectNextWord {w start} {
    # the check on [winfo class] is because the spinbox and combobox also use this proc
    if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} {
	return end
    }
    set pos [tk::endOfWord [$w get] [$w index $start]]
    if {$pos < 0} {
	return end
    }
    return $pos
}

## PrevWord -- Find the previous word position.
#
proc ttk::entry::PrevWord {w start} {
    # the check on [winfo class] is because the spinbox and combobox also use this proc
    if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} {
	return 0
    }
    set pos [tk::startOfPreviousWord [$w get] [$w index $start]]
    set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
    if {$pos < 0} {
	return 0
    }
    return $pos
}

## NextChar -- Find the next char position.
#
proc ttk::entry::NextChar {w start} {
    variable State
    set pos [tk::endOfCluster [$w get] [$w index $start]]
    if {$pos < 0} {
	return end
    }
    return $pos
}

## PrevChar -- Find the previous char position.
#
proc ttk::entry::PrevChar {w start} {
    set pos [tk::startOfCluster [$w get] [expr {[$w index $start]-1}]]
    if {$pos < 0} {
	return 0
    }
    return $pos
}

## RelIndex -- Compute character/word/line-relative index.
#
proc ttk::entry::RelIndex {w where {index insert}} {
    switch -- $where {
	prevchar	{ PrevChar $w $index }
    	nextchar	{ NextChar $w $index }
	prevchar	{ expr {[$w index $index] - 1} }
    	nextchar	{ expr {[$w index $index] + 1} }
	prevword	{ PrevWord $w $index }
	nextword	{ NextWord $w $index }
	selectnextword	{ SelectNextWord $w $index }
	home		{ return 0 }
	end		{ $w index end }
	default		{ error "Bad relative index $index" }
    }
}

## Move -- Move insert cursor to relative location.
361
362
363
364
365
366
367
368

369
370

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
291
292
293
294
295
296
297

298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360







-
+

-
+















-
+



















-
+
















-
+







#
proc ttk::entry::ExtendTo {w index} {
    set index [$w index $index]
    set insert [$w index insert]

    # Figure out selection anchor:
    if {![$w selection present]} {
	set anchor $insert
    	set anchor $insert
    } else {
	set selfirst [$w index sel.first]
    	set selfirst [$w index sel.first]
	set sellast  [$w index sel.last]

	if {   ($index < $selfirst)
	    || ($insert == $selfirst && $index <= $sellast)
	} {
	    set anchor $sellast
	} else {
	    set anchor $selfirst
	}
    }

    # Extend selection:
    if {$anchor < $index} {
	$w selection range $anchor $index
    } else {
	$w selection range $index $anchor
    	$w selection range $index $anchor
    }

    $w icursor $index
    return $anchor
}

## Extend -- Extend the selection to a relative position, show insert cursor
#
proc ttk::entry::Extend {w where} {
    ExtendTo $w [RelIndex $w $where]
    See $w
}

### Button 1 binding procedures.
#
# Double-clicking followed by a drag enters "word-select" mode.
# Triple-clicking enters "line-select" mode.
#

## Press -- Button-1 binding.
## Press -- ButtonPress-1 binding.
#	Set the insertion cursor, claim the input focus, set up for
#	future drag operations.
#
proc ttk::entry::Press {w x} {
    variable State

    $w icursor [ClosestGap $w $x]
    $w selection clear
    $w instate !disabled { focus $w }

    # Set up for future drag, double-click, or triple-click.
    set State(x) $x
    set State(selectMode) char
    set State(anchor) [$w index insert]
}

## Shift-Press -- Shift-Button-1 binding.
## Shift-Press -- Shift-ButtonPress-1 binding.
#	Extends the selection, sets anchor for future drag operations.
#
proc ttk::entry::Shift-Press {w x} {
    variable State

    focus $w
    set anchor [ExtendTo $w @$x]
439
440
441
442
443
444
445
446
447


448
449
450
451
452
453
454
369
370
371
372
373
374
375


376
377
378
379
380
381
382
383
384







-
-
+
+







#	and sets the selection mode for subsequent drag operations.
#
proc ttk::entry::Select {w x mode} {
    variable State
    set cur [ClosestGap $w $x]

    switch -- $mode {
	word	{ WordSelect $w $cur $cur }
	line	{ LineSelect $w $cur $cur }
    	word	{ WordSelect $w $cur $cur }
    	line	{ LineSelect $w $cur $cur }
	char	{ # no-op }
    }

    set State(anchor) $cur
    set State(selectMode) $mode
}

545
546
547
548
549
550
551
552
553


554
555
556
557


558
559
560
561
562
563
564
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579
475
476
477
478
479
480
481


482
483
484
485


486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509







-
-
+
+


-
-
+
+














-
+







	$w icursor $last
    }
    $w selection range $first $last
}

## WordBack, WordForward -- helper routines for WordSelect.
#
proc ttk::entry::WordBack {text index {locale {}}} {
    if {[set pos [tk::wordBreakBefore $text $index $locale]] < 0} { return 0 }
proc ttk::entry::WordBack {text index} {
    if {[set pos [tcl_wordBreakBefore $text $index]] < 0} { return 0 }
    return $pos
}
proc ttk::entry::WordForward {text index {locale {}}} {
    if {[set pos [tk::wordBreakAfter $text $index $locale]] < 0} { return end }
proc ttk::entry::WordForward {text index} {
    if {[set pos [tcl_wordBreakAfter $text $index]] < 0} { return end }
    return $pos
}

## LineSelect -- Select the entire line.
#
proc ttk::entry::LineSelect {w _ _} {
    variable State
    $w selection range 0 end
    $w icursor end
}

### Button 2 binding procedures.
#

## ScanMark -- Button-2 binding.
## ScanMark -- ButtonPress-2 binding.
#	Marks the start of a scan or primary transfer operation.
#
proc ttk::entry::ScanMark {w x} {
    variable State
    set State(scanX) $x
    set State(scanIndex) [$w index @0]
    set State(scanMoved) 0
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
518
519
520
521
522
523
524

525
526
527
528
529
530
531
532







-
+







    if {abs($dx) > $State(deadband)} {
	set State(scanMoved) 1
    }
    set left [expr {$State(scanIndex) + ($dx*$State(scanNum))/$State(scanDen)}]
    $w xview $left

    if {$left != [set newLeft [$w index @0]]} {
	# We've scanned past one end of the entry;
    	# We've scanned past one end of the entry;
	# reset the mark so that the text will start dragging again
	# as soon as the mouse reverses direction.
	#
	set State(scanX) $x
	set State(scanIndex) $newLeft
    }
}
645
646
647
648
649
650
651
652

653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
575
576
577
578
579
580
581

582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603

604
605
606
607







-
+





-
+














-
+
-




## Backspace -- Backspace over the character just before the insert cursor.
#	If there is a selection, delete that instead.
#	If the new insert position is offscreen to the left,
#	scroll to place the cursor at about the middle of the window.
#
proc ttk::entry::Backspace {w} {
    if {[PendingDelete $w]} {
	See $w
    	See $w
	return
    }
    set x [expr {[$w index insert] - 1}]
    if {$x < 0} { return }

    $w delete [tk::startOfCluster [$w get] $x] [tk::endOfCluster [$w get] $x]
    $w delete $x

    if {[$w index @0] >= [$w index insert]} {
	set range [$w xview]
	set left [lindex $range 0]
	set right [lindex $range 1]
	$w xview moveto [expr {$left - ($right - $left)/2.0}]
    }
}

## Delete -- Delete the character after the insert cursor.
#	If there is a selection, delete that instead.
#
proc ttk::entry::Delete {w} {
    if {![PendingDelete $w]} {
	$w delete [tk::startOfCluster [$w get] [$w index insert]] \
	$w delete insert
		[tk::endOfCluster [$w get] [$w index insert]]
    }
}

#*EOF*

Changes to library/ttk/fonts.tcl.

41
42
43
44
45
46
47



48
49
50
51
52




53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73

74
75

76
77
78
79


80
81

82
83
84

85
86
87
88
89
90






91
92
93
94



95
96
97
98
99
100
101
102
103
104








105
106
107
108
109
110
111
112
113
114










115
116
117
118
119
120



121
122
123


124
125
126
127
128
129




130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145











146
147
148


149
150
151
152
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72


73
74
75
76
77
78
79

80
81

82
83
84


85
86
87

88
89
90

91
92





93
94
95
96
97
98
99



100
101
102
103
104








105
106
107
108
109
110
111
112
113









114
115
116
117
118
119
120
121
122
123
124
125
126



127
128
129
130


131
132
133





134
135
136
137






138










139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157







+
+
+





+
+
+
+













-
-
+
+





-
+

-
+


-
-
+
+

-
+


-
+

-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
+
+




#
#	Note that the font for column headings (TkHeadingFont) is
#	_smaller_ than the default font.
#
#	There does not appear to be any recommendations for fixed-width fonts.
#
# X11:
#	Need a way to tell if Xft is enabled or not.
#	For now, assume patch #971980 applied.
#
#	"Classic" look used Helvetica bold for everything except
#	for entry widgets, which use Helvetica medium.
#	Most other toolkits use medium weight for all UI elements,
#	which is what we do now.
#
#	Font size specified in pixels on X11, not points.
#	This is Theoretically Wrong, but in practice works better; using
#	points leads to huge inconsistencies across different servers.
#

namespace eval ttk {

variable tip145 [catch {font create TkDefaultFont}]
catch {font create TkTextFont}
catch {font create TkHeadingFont}
catch {font create TkCaptionFont}
catch {font create TkTooltipFont}
catch {font create TkFixedFont}
catch {font create TkIconFont}
catch {font create TkMenuFont}
catch {font create TkSmallCaptionFont}

if {!$tip145} {apply {{} {
global tcl_platform
if {!$tip145} {
variable F	;# miscellaneous platform-specific font parameters
switch -- [tk windowingsystem] {
    win32 {
        # In safe interps there is no osVersion element.
	if {[info exists tcl_platform(osVersion)]} {
            if {$tcl_platform(osVersion) >= 5.0} {
                set family "Tahoma"
                set F(family) "Tahoma"
            } else {
                set family "MS Sans Serif"
                set F(family) "MS Sans Serif"
            }
        } else {
            if {[lsearch -exact [font families] Tahoma] >= 0} {
                set family "Tahoma"
            if {[lsearch -exact [font families] Tahoma] != -1} {
                set F(family) "Tahoma"
            } else {
                set family "MS Sans Serif"
                set F(family) "MS Sans Serif"
            }
        }
	set size 8
	set F(size) 8

	font configure TkDefaultFont -family $family -size $size
	font configure TkTextFont    -family $family -size $size
	font configure TkHeadingFont -family $family -size $size
	font configure TkCaptionFont -family $family -size $size -weight bold
	font configure TkTooltipFont -family $family -size $size
	font configure TkDefaultFont -family $F(family) -size $F(size)
	font configure TkTextFont    -family $F(family) -size $F(size)
	font configure TkHeadingFont -family $F(family) -size $F(size)
	font configure TkCaptionFont -family $F(family) -size $F(size) \
	    -weight bold
	font configure TkTooltipFont -family $F(family) -size $F(size)
	font configure TkFixedFont   -family Courier -size 10
	font configure TkIconFont    -family $family -size $size
	font configure TkMenuFont    -family $family -size $size
	font configure TkSmallCaptionFont -family $family -size $size
	font configure TkIconFont    -family $F(family) -size $F(size)
	font configure TkMenuFont    -family $F(family) -size $F(size)
	font configure TkSmallCaptionFont -family $F(family) -size $F(size)
    }
    aqua {
	set family "Lucida Grande"
	set fixed "Monaco"
	set menusize 14
	set size 13
	set viewsize 12
	set smallsize 11
	set labelsize 10
	set fixedsize 11
	set F(family) "Lucida Grande"
	set F(fixed) "Monaco"
	set F(menusize) 14
	set F(size) 13
	set F(viewsize) 12
	set F(smallsize) 11
	set F(labelsize) 10
	set F(fixedsize) 11

	font configure TkDefaultFont -family $family -size $size
	font configure TkTextFont    -family $family -size $size
	font configure TkHeadingFont -family $family -size $smallsize
	font configure TkCaptionFont -family $family -size $size -weight bold
	font configure TkTooltipFont -family $family -size $smallsize
	font configure TkFixedFont   -family $fixed  -size $fixedsize
	font configure TkIconFont    -family $family -size $size
	font configure TkMenuFont    -family $family -size $menusize
	font configure TkSmallCaptionFont -family $family -size $labelsize
	font configure TkDefaultFont -family $F(family) -size $F(size)
	font configure TkTextFont    -family $F(family) -size $F(size)
	font configure TkHeadingFont -family $F(family) -size $F(smallsize)
	font configure TkCaptionFont -family $F(family) -size $F(size) \
					-weight bold
	font configure TkTooltipFont -family $F(family) -size $F(smallsize)
	font configure TkFixedFont   -family $F(fixed)  -size $F(fixedsize)
	font configure TkIconFont    -family $F(family) -size $F(size)
	font configure TkMenuFont    -family $F(family) -size $F(menusize)
	font configure TkSmallCaptionFont -family $F(family) -size $F(labelsize)
    }
    default -
    x11 {
	if {![catch {tk::pkgconfig get fontsystem} fs] && $fs eq "xft"} {
	    set family "sans-serif"
	    set fixed  "monospace"
	if {![catch {tk::pkgconfig get fontsystem} F(fs)] && $F(fs) eq "xft"} {
	    set F(family) "sans-serif"
	    set F(fixed)  "monospace"
	} else {
	    set family "Helvetica"
	    set fixed  "courier"
	    set F(family) "Helvetica"
	    set F(fixed)  "courier"
	}
	if {[::tk::FontScalingFactor] == 1} {
	    set size 10
	    set ttsize 9
	    set capsize 12
	    set fixedsize 10
	set F(size) -12
	set F(ttsize) -10
	set F(capsize) -14
	set F(fixedsize) -12
	} else {
	    set size 20
	    set ttsize 18
	    set capsize 24
	    set fixedsize 20
	}


	font configure TkDefaultFont -family $family -size $size
	font configure TkTextFont    -family $family -size $size
	font configure TkHeadingFont -family $family -size $size    -weight bold
	font configure TkCaptionFont -family $family -size $capsize -weight bold
	font configure TkTooltipFont -family $family -size $ttsize
	font configure TkFixedFont   -family $fixed  -size $fixedsize
	font configure TkIconFont    -family $family -size $size
	font configure TkMenuFont    -family $family -size $size
	font configure TkSmallCaptionFont -family $family -size $ttsize
	font configure TkDefaultFont -family $F(family) -size $F(size)
	font configure TkTextFont    -family $F(family) -size $F(size)
	font configure TkHeadingFont -family $F(family) -size $F(size) \
			-weight bold
	font configure TkCaptionFont -family $F(family) -size $F(capsize) \
			-weight bold
	font configure TkTooltipFont -family $F(family) -size $F(ttsize)
	font configure TkFixedFont   -family $F(fixed)  -size $F(fixedsize)
	font configure TkIconFont    -family $F(family) -size $F(size)
	font configure TkMenuFont    -family $F(family) -size $F(size)
	font configure TkSmallCaptionFont -family $F(family) -size $F(ttsize)
    }
}
} ::ttk}}
unset -nocomplain F
}

}

#*EOF*

Changes to library/ttk/menubutton.tcl.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29







-
+













-
+







#
# Bindings for Menubuttons.
#
# Menubuttons have three interaction modes:
#
# Pulldown: Press menubutton, drag over menu, release to activate menu entry
# Popdown: Click menubutton to post menu
# Keyboard: <space> or accelerator key to post menu
# Keyboard: <Key-space> or accelerator key to post menu
#
# (In addition, when menu system is active, "dropdown" -- menu posts
# on mouse-over.  Ttk menubuttons don't implement this).
#
# For keyboard and popdown mode, we hand off to tk_popup and let
# the built-in Tk bindings handle the rest of the interaction.
#
# ON X11:
#
# Standard Tk menubuttons use a global grab on the menubutton.
# This won't work for Ttk menubuttons in pulldown mode,
# since we need to process the final <ButtonRelease> event,
# and this might be delivered to the menu.  So instead we
# rely on the passive grab that occurs on <Button> events,
# rely on the passive grab that occurs on <ButtonPress> events,
# and transition to popdown mode when the mouse is released
# or dragged outside the menubutton.
#
# ON WINDOWS:
#
# I'm not sure what the hell is going on here.  [$menu post] apparently
# sets up some kind of internal grab for native menus.
42
43
44
45
46
47
48
49

50
51
52
53

54
55
56
57

58
59
60

61
62
63
64

65
66

67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136





137
138
139
140
141
142
143
144
145
146

















147
148
149
150
151
152
153


154
155
156
157

158
159
160
161
162



163
164
165
166
167
168
169
170
171
172
173
174


175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221

222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
42
43
44
45
46
47
48

49
50
51
52

53
54
55
56

57
58
59

60
61
62
63

64


65



66
67
68
69
70














































71

















72
73
74
75
76










77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







94
95
96



97





98
99
100

101
102
103
104
105
106
107
108
109


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129





130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152

153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169







-
+



-
+



-
+


-
+



-
+
-
-
+
-
-
-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+

-
-
-
+
-
-
-
-
-
+
+
+
-









-
-
+
+












+





-
-
-
-
-
+
-















-
-
+






-
+



-
+












	    oldcursor	{}
	}
    }
}

bind TMenubutton <Enter>	{ %W instate !disabled {%W state active } }
bind TMenubutton <Leave>	{ %W state !active }
bind TMenubutton <space>	{ ttk::menubutton::Popdown %W }
bind TMenubutton <Key-space> 	{ ttk::menubutton::Popdown %W }
bind TMenubutton <<Invoke>> 	{ ttk::menubutton::Popdown %W }

if {[tk windowingsystem] eq "x11"} {
    bind TMenubutton <Button-1>  	{ ttk::menubutton::Pulldown %W }
    bind TMenubutton <ButtonPress-1>  	{ ttk::menubutton::Pulldown %W }
    bind TMenubutton <ButtonRelease-1>	{ ttk::menubutton::TransferGrab %W }
    bind TMenubutton <B1-Leave> 	{ ttk::menubutton::TransferGrab %W }
} else {
    bind TMenubutton <Button-1>  \
    bind TMenubutton <ButtonPress-1>  \
	{ %W state pressed ; ttk::menubutton::Popdown %W }
    bind TMenubutton <ButtonRelease-1>  \
	{ if {[winfo exists %W]} { %W state {!pressed}} }
	{ if {[winfo exists %W]} { %W state !pressed } }
}

# PostPosition --
#	Returns x and y coordinates and a menu item index.
#	Returns the x and y coordinates where the menu
#       If the index is not an empty string the menu should
#       be posted so that the upper left corner of the indexed
#	should be posted, based on the menubutton and menu size
#       menu item is located at the point (x, y).  Otherwise
#       the top left corner of the menu itself should be located
#       at that point.
#	and -direction option.
#
# TODO: adjust menu width to be at least as wide as the button
#	for -direction above, below.
#

if {[tk windowingsystem] eq "aqua"} {
    proc ::ttk::menubutton::PostPosition {mb menu} {
	set menuPad 5
	set buttonPad 1
	set bevelPad 4
	set flushPad 4
	set mh [winfo reqheight $menu]
	set bh [expr {[winfo height $mb]} + $buttonPad]
	set bbh [expr {[winfo height $mb]} + $bevelPad]
	set mw [winfo reqwidth $menu]
	set bw [winfo width $mb]
	set entry [::tk::MenuFindName $menu [$mb cget -text]]
	if {$entry < 0} {
	    set entry 0
	}
	set x [winfo rootx $mb]
	set y [winfo rooty $mb]
	switch [$mb cget -direction] {
	    above {
		set entry ""
		incr y [expr {-$mh + 2 * $menuPad}]
	    }
	    below {
		set entry ""
		incr y $bh
	    }
	    left {
		incr y $menuPad
		incr x -$mw
	    }
	    right {
		incr y $menuPad
		incr x $bw
	    }
	    flush {
		incr y $flushPad
		incr x -$flushPad
	    }
	    default {
	    }
	}
	return [list $x $y $entry]
    }
} else {
    proc ::ttk::menubutton::PostPosition {mb menu} {
proc ttk::menubutton::PostPosition {mb menu} {
	set mh [expr {[winfo reqheight $menu]}]
	set bh [expr {[winfo height $mb]}]
	set mw [expr {[winfo reqwidth $menu]}]
	set bw [expr {[winfo width $mb]}]
	if {[tk windowingsystem] eq "win32"} {
	    incr mh 6
	    incr mw 16
	}
	set entry [::tk::MenuFindName $menu [$mb cget -text]]
	if {$entry < 0} {
	    set entry 0
	}
	set x [winfo rootx $mb]
	set y [winfo rooty $mb]
	switch [$mb cget -direction] {
	    above {
		set entry ""
    set x [winfo rootx $mb]
    set y [winfo rooty $mb]
    set dir [$mb cget -direction]

    set bw [winfo width $mb]
		incr y -$mh
		# if we go offscreen to the top, show as 'below'
		if {$y < [winfo vrooty $mb]} {
		    set y [expr {[winfo vrooty $mb] + [winfo rooty $mb]\
                           + [winfo reqheight $mb]}]
		}
	    }
	    below {
		set entry ""
		incr y $bh
    set bh [winfo height $mb]
    set mw [winfo reqwidth $menu]
    set mh [winfo reqheight $menu]
    set sw [expr {[winfo screenwidth  $menu] - $bw - $mw}]
    set sh [expr {[winfo screenheight $menu] - $bh - $mh}]

    switch -- $dir {
	above { if {$y >= $mh} { incr y -$mh } { incr y  $bh } }
	below { if {$y <= $sh} { incr y  $bh } { incr y -$mh } }
	left  { if {$x >= $mw} { incr x -$mw } { incr x  $bw } }
	right { if {$x <= $sw} { incr x  $bw } { incr x -$mw } }
	flush {
	    # post menu atop menubutton.
	    # If there's a menu entry whose label matches the
	    # menubutton -text, assume this is an optionmenu
	    # and place that entry over the menubutton.
	    set index [FindMenuEntry $menu [$mb cget -text]]
		# if we go offscreen to the bottom, show as 'above'
		if {($y + $mh) > ([winfo vrooty $mb] + [winfo vrootheight $mb])} {
		    set y [expr {[winfo vrooty $mb] + [winfo rooty $mb] - $mh}]
		}
	    }
	    left {
		incr x -$mw
	    if {$index ne ""} {
		incr y -[$menu yposition $index]
	    }
	    right {
		incr x $bw
	    }
	}
	    default {  # flush
		incr x [expr {([winfo width $mb] - [winfo reqwidth $menu])/ 2}]
	    }
	}
	return [list $x $y $entry]
    }

    return [list $x $y]
    }
}

# Popdown --
#	Post the menu and set a grab on the menu.
#
proc ttk::menubutton::Popdown {mb} {
    if {[$mb instate disabled] || [set menu [$mb cget -menu]] eq ""} {
	return
    }
    foreach {x y entry} [PostPosition $mb $menu] { break }
    tk_popup $menu $x $y $entry
    foreach {x y} [PostPosition $mb $menu] { break }
    tk_popup $menu $x $y
}

# Pulldown (X11 only) --
#	Called when Button1 is pressed on a menubutton.
#	Posts the menu; a subsequent ButtonRelease
#	or Leave event will set a grab on the menu.
#
proc ttk::menubutton::Pulldown {mb} {
    variable State
    if {[$mb instate disabled] || [set menu [$mb cget -menu]] eq ""} {
	return
    }
    foreach {x y} [PostPosition $mb $menu] { break }
    set State(pulldown) 1
    set State(oldcursor) [$mb cget -cursor]

    $mb state pressed
    $mb configure -cursor [$menu cget -cursor]
    foreach {x y entry} [PostPosition $mb $menu] { break }
    if {$entry >= 0} {
	$menu post $x $y $entry
    } else {
	$menu post $x $y
    $menu post $x $y
    }
    tk_menuSetFocus $menu
}

# TransferGrab (X11 only) --
#	Switch from pulldown mode (menubutton has an implicit grab)
#	to popdown mode (menu has an explicit grab).
#
proc ttk::menubutton::TransferGrab {mb} {
    variable State
    if {$State(pulldown)} {
	$mb configure -cursor $State(oldcursor)
	$mb state {!pressed !active}
	set State(pulldown) 0

	set menu [$mb cget -menu]
	foreach {x y entry} [PostPosition $mb $menu] { break }
	tk_popup $menu [winfo rootx $menu] [winfo rooty $menu]
    	tk_popup $menu [winfo rootx $menu] [winfo rooty $menu]
    }
}

# FindMenuEntry --
#	Hack to support tk_optionMenus.
#	Returns the index of the menu entry with a matching -label,
#	"" if not found.
#	-1 if not found.
#
proc ttk::menubutton::FindMenuEntry {menu s} {
    set last [$menu index last]
    if {$last < 0} {
    if {$last eq "none"} {
	return ""
    }
    for {set i 0} {$i <= $last} {incr i} {
	if {![catch {$menu entrycget $i -label} label]
	    && ($label eq $s)} {
	    return $i
	}
    }
    return ""
}

#*EOF*

Changes to library/ttk/notebook.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13





14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1
2
3
4
5
6
7
8





9
10
11
12
13
14
15
16
17
18






















19
20
21
22
23
24
25








-
-
-
-
-
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







#
# Bindings for TNotebook widget
#

namespace eval ttk::notebook {
    variable TLNotebooks ;# See enableTraversal
}

bind TNotebook <Button-1>		{ ttk::notebook::Press %W %x %y }
bind TNotebook <Right>			{ ttk::notebook::CycleTab %W  1; break }
bind TNotebook <Left>			{ ttk::notebook::CycleTab %W -1; break }
bind TNotebook <Control-Tab>		{ ttk::notebook::CycleTab %W  1; break }
bind TNotebook <Control-Shift-Tab>	{ ttk::notebook::CycleTab %W -1; break }
bind TNotebook <ButtonPress-1>		{ ttk::notebook::Press %W %x %y }
bind TNotebook <Key-Right>		{ ttk::notebook::CycleTab %W  1; break }
bind TNotebook <Key-Left>		{ ttk::notebook::CycleTab %W -1; break }
bind TNotebook <Control-Key-Tab>	{ ttk::notebook::CycleTab %W  1; break }
bind TNotebook <Control-Shift-Key-Tab>	{ ttk::notebook::CycleTab %W -1; break }
catch {
bind TNotebook <Control-ISO_Left_Tab>	{ ttk::notebook::CycleTab %W -1; break }
}
bind TNotebook <Destroy>		{ ttk::notebook::Cleanup %W }

bind TNotebook <Enter> {
    set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0
}
bind TNotebook <MouseWheel> {
    ttk::notebook::CondCycleTab1 %W y %D -120.0
}
bind TNotebook <Option-MouseWheel> {
    ttk::notebook::CondCycleTab1 %W y %D -12.0
}
bind TNotebook <Shift-MouseWheel> {
    ttk::notebook::CondCycleTab1 %W x %D -120.0
}
bind TNotebook <Shift-Option-MouseWheel> {
    ttk::notebook::CondCycleTab1 %W x %D -12.0
}
bind TNotebook <TouchpadScroll> {
    # TouchpadScroll events fire about 60 times per second.
    if {%# %% 15 == 0} {
	ttk::notebook::CondCycleTab2 %W %D
    }
}

# ActivateTab $nb $tab --
#	Select the specified tab and set focus.
#
#  Desired behavior:
#	+ take focus when reselecting the currently-selected tab;
#	+ keep focus if the notebook already has it;
#	+ otherwise set focus to the first traversable widget
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82



83
84
85
86
87

88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146



147
148
149
150
151
152
153
154
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58


59
60
61





62



63
64
65
66
67
68
69
70
71



































72
73
74
75
76
77
78
79
80
81




82
83
84

85
86
87
88
89
90
91







-
+












-
-
+
+
+
-
-
-
-
-
+
-
-
-
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
-
-
+
+
+
-







	ttk::traverseTo $f
    } else {
	focus $w
    }
}

# Press $nb $x $y --
#	Button-1 binding for notebook widgets.
#	ButtonPress-1 binding for notebook widgets.
#	Activate the tab under the mouse cursor, if any.
#
proc ttk::notebook::Press {w x y} {
    set index [$w index @$x,$y]
    if {$index ne ""} {
	ActivateTab $w $index
    }
}

# CycleTab --
#	Select the next/previous tab in the list.
#
proc ttk::notebook::CycleTab {w dir {factor 1.0}} {
    set current [$w index current]
proc ttk::notebook::CycleTab {w dir} {
    if {[$w index end] != 0} {
	set current [$w index current]
    if {$current >= 0} {
	set tabCount [$w index end]
	set d [expr {$dir/$factor}]
	set d [expr {int($d > 0 ? ceil($d) : floor($d))}]
	set select [expr {($current + $d) % $tabCount}]
	set select [expr {($current + $dir) % [$w index end]}]
	set step [expr {$d > 0 ? 1 : -1}]
	while {[$w tab $select -state] ne "normal" && ($select != $current)} {
	    set select [expr {($select + $step) % $tabCount}]
	while {[$w tab $select -state] != "normal" && ($select != $current)} {
	    set select [expr {($select + $dir) % [$w index end]}]
	}
	if {$select != $current} {
	    ActivateTab $w $select
	}
    }
}

# CondCycleTab1 --
#	Conditionally invoke the ttk::notebook::CycleTab proc.
#
proc ttk::notebook::CondCycleTab1 {w axis dir {factor 1.0}} {
    # Count both the <MouseWheel> and <Shift-MouseWheel>
    # events, and ignore the non-dominant ones

    variable ::tk::Priv
    incr Priv(${axis}Events)
    if {($Priv(xEvents) + $Priv(yEvents) > 10) &&
	    ($axis eq "x" && $Priv(xEvents) < $Priv(yEvents) ||
	     $axis eq "y" && $Priv(yEvents) < $Priv(xEvents))} {
	return
    }

    CycleTab $w $dir $factor
}

# CondCycleTab2 --
#	Conditionally invoke the ttk::notebook::CycleTab proc.
#
proc ttk::notebook::CondCycleTab2 {w dxdy} {
    if {[set style [$w cget -style]] eq ""} {
	set style TNotebook
    }
    set tabSide [string index [ttk::style lookup $style -tabposition {} nw] 0]

    lassign [tk::PreciseScrollDeltas $dxdy] deltaX deltaY
    if {$tabSide in {n s} && $deltaX != 0} {
	CycleTab $w [expr {$deltaX < 0 ? -1 : 1}]
    } elseif {$tabSide in {w e} && $deltaY != 0} {
	CycleTab $w [expr {$deltaY < 0 ? -1 : 1}]
    }
}

# MnemonicTab $nb $key --
#	Scan all tabs in the specified notebook for one with the
#	specified mnemonic. If found, returns path name of tab;
#	otherwise returns ""
#
proc ttk::notebook::MnemonicTab {nb key} {
    set key [string toupper $key]
    foreach tab [$nb tabs] {
	set label [$nb tab $tab -text]
	set underline [$nb tab $tab -underline]
	if {$underline >= 0} {
	    set mnemonic [string toupper [string index $label $underline]]
	    if {$mnemonic ne "" && $mnemonic eq $key} {
		return $tab
	set mnemonic [string toupper [string index $label $underline]]
	if {$mnemonic ne "" && $mnemonic eq $key} {
	    return $tab
	    }
	}
    }
    return ""
}

# +++ Toplevel keyboard traversal.
#
164
165
166
167
168
169
170
171
172
173
174




175
176

177

178
179






180
181
182
183
184
185
186
101
102
103
104
105
106
107




108
109
110
111
112

113
114
115


116
117
118
119
120
121
122
123
124
125
126
127
128







-
-
-
-
+
+
+
+

-
+

+
-
-
+
+
+
+
+
+







    variable TLNotebooks

    set top [winfo toplevel $nb]

    if {![info exists TLNotebooks($top)]} {
	# Augment $top bindings:
	#
	bind $top <Control-Next>             {+ttk::notebook::TLCycleTab %W  1}
	bind $top <Control-Prior>            {+ttk::notebook::TLCycleTab %W -1}
	bind $top <Control-Tab> 	     {+ttk::notebook::TLCycleTab %W  1}
	bind $top <Control-Shift-Tab>        {+ttk::notebook::TLCycleTab %W -1}
	bind $top <Control-Key-Next>         {+ttk::notebook::TLCycleTab %W  1}
	bind $top <Control-Key-Prior>        {+ttk::notebook::TLCycleTab %W -1}
	bind $top <Control-Key-Tab> 	     {+ttk::notebook::TLCycleTab %W  1}
	bind $top <Control-Shift-Key-Tab>    {+ttk::notebook::TLCycleTab %W -1}
	catch {
	bind $top <Control-ISO_Left_Tab>     {+ttk::notebook::TLCycleTab %W -1}
	bind $top <Control-Key-ISO_Left_Tab> {+ttk::notebook::TLCycleTab %W -1}
	}
	if {[tk windowingsystem] eq "aqua"} {
	bind $top <Option-Key> \
	    +[list ttk::notebook::MnemonicActivation $top %K]
	    bind $top <Option-KeyPress> \
		+[list ttk::notebook::MnemonicActivation $top %K]
	} else {
	    bind $top <Alt-KeyPress> \
		+[list ttk::notebook::MnemonicActivation $top %K]
	}
	bind $top <Destroy> {+ttk::notebook::TLCleanup %W}
    }

    lappend TLNotebooks($top) $nb
}

# TLCleanup -- <Destroy> binding for traversal-enabled toplevels
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192
193
194
195
196
197







-
+












    if {$nb ne ""} {
	CycleTab $nb $dir
	return -code break
    }
}

# MnemonicActivation $nb $key --
#	Alt-Key binding procedure for mnemonic activation.
#	Alt-KeyPress binding procedure for mnemonic activation.
#	Scan all notebooks in specified toplevel for a tab with the
#	the specified mnemonic.  If found, activate it and return TCL_BREAK.
#
proc ttk::notebook::MnemonicActivation {top key} {
    variable TLNotebooks
    foreach nb $TLNotebooks($top) {
	if {[set tab [MnemonicTab $nb $key]] ne ""} {
	    ActivateTab $nb [$nb index $tab]
	    return -code break
	}
    }
}

Changes to library/ttk/panedwindow.tcl.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

19
20
21
22
23
24


25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78

79
80
81
82
83




84
85
86
87
88
89
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64




65

66
67
68
69
70






71
72




73
74
75
76
77
78
79
80
81
82








-
+








-
+






+
+








-
+












-
-
-
+
+
+














-
-
-
-

-
+




-
-
-
-
-
-
+

-
-
-
-
+
+
+
+






#
# Bindings for ttk::panedwindow widget.
#

namespace eval ttk::panedwindow {
    variable State
    array set State {
	pressed 0
	pressX	-
    	pressX	-
	pressY	-
	sash 	-
	sashPos -
    }
}

## Bindings:
#
bind TPanedwindow <Button-1> 		{ ttk::panedwindow::Press %W %x %y }
bind TPanedwindow <ButtonPress-1> 	{ ttk::panedwindow::Press %W %x %y }
bind TPanedwindow <B1-Motion>		{ ttk::panedwindow::Drag %W %x %y }
bind TPanedwindow <ButtonRelease-1> 	{ ttk::panedwindow::Release %W %x %y }

bind TPanedwindow <Motion> 		{ ttk::panedwindow::SetCursor %W %x %y }
bind TPanedwindow <Enter> 		{ ttk::panedwindow::SetCursor %W %x %y }
bind TPanedwindow <Leave> 		{ ttk::panedwindow::ResetCursor %W }
# See <<NOTE-PW-LEAVE-NOTIFYINFERIOR>>
bind TPanedwindow <<EnteredChild>>	{ ttk::panedwindow::ResetCursor %W }

## Sash movement:
#
proc ttk::panedwindow::Press {w x y} {
    variable State

    set sash [$w identify $x $y]
    if {$sash eq ""} {
	set State(pressed) 0
    	set State(pressed) 0
	return
    }
    set State(pressed) 	1
    set State(pressX) 	$x
    set State(pressY) 	$y
    set State(sash) 	$sash
    set State(sashPos)	[$w sashpos $sash]
}

proc ttk::panedwindow::Drag {w x y} {
    variable State
    if {!$State(pressed)} { return }
    switch -glob -- [$w cget -orient] {
    	h*  { set delta [expr {$x - $State(pressX)}] }
    	v*  { set delta [expr {$y - $State(pressY)}] }
    switch -- [$w cget -orient] {
    	horizontal 	{ set delta [expr {$x - $State(pressX)}] }
    	vertical 	{ set delta [expr {$y - $State(pressY)}] }
    }
    $w sashpos $State(sash) [expr {$State(sashPos) + $delta}]
}

proc ttk::panedwindow::Release {w x y} {
    variable State
    set State(pressed) 0
    SetCursor $w $x $y
}

## Cursor management:
#
proc ttk::panedwindow::ResetCursor {w} {
    variable State

    ttk::saveCursor $w State(userConfCursor) \
            [list [ttk::cursor hresize] [ttk::cursor vresize]]

    if {!$State(pressed)} {
	ttk::setCursor $w $State(userConfCursor)
	ttk::setCursor $w {}
    }
}

proc ttk::panedwindow::SetCursor {w x y} {
    variable State

    ttk::saveCursor $w State(userConfCursor) \
            [list [ttk::cursor hresize] [ttk::cursor vresize]]

    set cursor $State(userConfCursor)
    set cursor ""
    if {[llength [$w identify $x $y]]} {
	# Assume we're over a sash.
	switch -glob -- [$w cget -orient] {
	    h*  { set cursor hresize }
	    v*  { set cursor vresize }
    	# Assume we're over a sash.
	switch -- [$w cget -orient] {
	    horizontal 	{ set cursor hresize }
	    vertical 	{ set cursor vresize }
	}
    }
    ttk::setCursor $w $cursor
}

#*EOF*

Changes to library/ttk/progress.tcl.

9
10
11
12
13
14
15
16

17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
9
10
11
12
13
14
15

16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34



35
36
37
38
39
40
41
42
43
44
45
46



47
48
49







-
+





-
+












-
-
-












-
-
-



# Autoincrement --
#	Periodic callback procedure for autoincrement mode
#
proc ttk::progressbar::Autoincrement {pb steptime stepsize} {
    variable Timers

    if {![winfo exists $pb]} {
	# widget has been destroyed -- cancel timer
    	# widget has been destroyed -- cancel timer
	unset -nocomplain Timers($pb)
	return
    }

    set Timers($pb) [after $steptime \
	[list ttk::progressbar::Autoincrement $pb $steptime $stepsize] ]
    	[list ttk::progressbar::Autoincrement $pb $steptime $stepsize] ]

    $pb step $stepsize
}

# ttk::progressbar::start --
#	Start autoincrement mode.  Invoked by [$pb start] widget code.
#
proc ttk::progressbar::start {pb {steptime 50} {stepsize 1}} {
    variable Timers
    if {![info exists Timers($pb)]} {
	Autoincrement $pb $steptime $stepsize
    }
    if {[tk windowingsystem] eq "aqua"} {
	$pb state selected
    }
}

# ttk::progressbar::stop --
#	Cancel autoincrement mode. Invoked by [$pb stop] widget code.
#
proc ttk::progressbar::stop {pb} {
    variable Timers
    if {[info exists Timers($pb)]} {
	after cancel $Timers($pb)
	unset Timers($pb)
    }
    $pb configure -value 0
    if {[tk windowingsystem] eq "aqua"} {
	$pb state !selected
    }
}


Changes to library/ttk/scale.tcl.

1

2
3
4
5
6
7
8
9
10
11
12

13
14
15
16

17
18
19
20

21
22
23
24
25
26
27

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15

16
17
18
19

20
21
22
23
24
25
26
27
-
+










-
+



-
+



-
+







# scale.tcl - Copyright © 2004 Pat Thoyts <[email protected]>
# scale.tcl - Copyright (C) 2004 Pat Thoyts <[email protected]>
#
# Bindings for the TScale widget

namespace eval ttk::scale {
    variable State
    array set State  {
	dragging 0
    }
}

bind TScale <Button-1>        { ttk::scale::Press %W %x %y }
bind TScale <ButtonPress-1>   { ttk::scale::Press %W %x %y }
bind TScale <B1-Motion>       { ttk::scale::Drag %W %x %y }
bind TScale <ButtonRelease-1> { ttk::scale::Release %W %x %y }

bind TScale <Button-2>        { ttk::scale::Jump %W %x %y }
bind TScale <ButtonPress-2>   { ttk::scale::Jump %W %x %y }
bind TScale <B2-Motion>       { ttk::scale::Drag %W %x %y }
bind TScale <ButtonRelease-2> { ttk::scale::Release %W %x %y }

bind TScale <Button-3>        { ttk::scale::Jump %W %x %y }
bind TScale <ButtonPress-3>   { ttk::scale::Jump %W %x %y }
bind TScale <B3-Motion>       { ttk::scale::Drag %W %x %y }
bind TScale <ButtonRelease-3> { ttk::scale::Release %W %x %y }

## Keyboard navigation bindings:
#
bind TScale <<LineStart>>     { %W set [%W cget -from] }
bind TScale <<LineEnd>>       { %W set [%W cget -to] }
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+







        *slider {
            set State(dragging) 1
            set State(initial) [$w get]
        }
    }
}

# scale::Jump -- Button-2/3 binding for scale acts like
# scale::Jump -- ButtonPress-2/3 binding for scale acts like
#	Press except that clicking in the trough jumps to the
#	clicked position.
proc ttk::scale::Jump {w x y} {
    variable State
    set State(dragging) 0

    switch -glob -- [$w identify $x $y] {

Changes to library/ttk/scrollbar.tcl.

1
2
3


















4
5
6
7
8
9
10
11
12

13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33

34
35
36
37












38
39
40
41
42
43
44



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+



-
+



-
-
-
-
-
-
-
-
-
-
-
-







#
# Bindings for TScrollbar widget
#

# Still don't have a working ttk::scrollbar under OSX -
# Swap in a [tk::scrollbar] on that platform,
# unless user specifies -class or -style.
#
if {[tk windowingsystem] eq "aqua"} {
    rename ::ttk::scrollbar ::ttk::_scrollbar
    proc ttk::scrollbar {w args} {
	set constructor ::tk::scrollbar
	foreach {option _} $args {
	    if {$option eq "-class" || $option eq "-style"} {
		set constructor ::ttk::_scrollbar
		break
	    }
	}
	return [$constructor $w {*}$args]
    }
}

namespace eval ttk::scrollbar {
    variable State
    # State(xPress)	--
    # State(yPress)	-- initial position of mouse at start of drag.
    # State(first)	-- value of -first at start of drag.
}

bind TScrollbar <Button-1> 		{ ttk::scrollbar::Press %W %x %y }
bind TScrollbar <ButtonPress-1> 	{ ttk::scrollbar::Press %W %x %y }
bind TScrollbar <B1-Motion>		{ ttk::scrollbar::Drag %W %x %y }
bind TScrollbar <ButtonRelease-1>	{ ttk::scrollbar::Release %W %x %y }

bind TScrollbar <Button-2> 		{ ttk::scrollbar::Jump %W %x %y }
bind TScrollbar <ButtonPress-2> 	{ ttk::scrollbar::Jump %W %x %y }
bind TScrollbar <B2-Motion>		{ ttk::scrollbar::Drag %W %x %y }
bind TScrollbar <ButtonRelease-2>	{ ttk::scrollbar::Release %W %x %y }

# Copy the mouse wheel event bindings from Scrollbar to TScrollbar
#
bind TScrollbar <Enter> {
    set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0
}
foreach event {<MouseWheel> <Option-MouseWheel>
	       <Shift-MouseWheel> <Shift-Option-MouseWheel>
	       <TouchpadScroll>} {
    bind TScrollbar $event [bind Scrollbar $event]
}
unset event

proc ttk::scrollbar::Scroll {w n units} {
    set cmd [$w cget -command]
    if {$cmd ne ""} {
	uplevel #0 $cmd scroll $n $units
    }
}

46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66

67
68
69
70
71
72
73







-
+







-







proc ttk::scrollbar::Press {w x y} {
    variable State

    set State(xPress) $x
    set State(yPress) $y

    switch -glob -- [$w identify $x $y] {
	*uparrow -
    	*uparrow -
	*leftarrow {
	    ttk::Repeatedly Scroll $w -1 units
	}
	*downarrow -
	*rightarrow {
	    ttk::Repeatedly Scroll $w  1 units
	}
	*grip -
	*thumb {
	    set State(first) [lindex [$w get] 0]
	}
	*trough {
	    set f [$w fraction $x $y]
	    if {$f < [lindex [$w get] 0]} {
		# Clicked in upper/left trough
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123







-
+














-
+







-












	}
    }
}

proc ttk::scrollbar::Drag {w x y} {
    variable State
    if {![info exists State(first)]} {
	# Initial buttonpress was not on the thumb,
    	# Initial buttonpress was not on the thumb,
	# or something screwy has happened.  In either case, ignore:
	return;
    }
    set xDelta [expr {$x - $State(xPress)}]
    set yDelta [expr {$y - $State(yPress)}]
    Moveto $w [expr {$State(first) + [$w delta $xDelta $yDelta]}]
}

proc ttk::scrollbar::Release {w x y} {
    variable State
    unset -nocomplain State(xPress) State(yPress) State(first)
    ttk::CancelRepeat
}

# scrollbar::Jump -- Button-2 binding for scrollbars.
# scrollbar::Jump -- ButtonPress-2 binding for scrollbars.
# 	Behaves exactly like scrollbar::Press, except that
#	clicking in the trough jumps to the the selected position.
#
proc ttk::scrollbar::Jump {w x y} {
    variable State

    switch -glob -- [$w identify $x $y] {
	*grip -
	*thumb -
	*trough {
	    set State(first) [$w fraction $x $y]
	    Moveto $w $State(first)
	    set State(xPress) $x
	    set State(yPress) $y
	}
	default {
	    Press $w $x $y
	}
    }
}

Changes to library/ttk/sizegrip.tcl.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
1
2
3
4
5
6
7
8
9
10
11

12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42











-
+


-
+



















-
+







#
# Sizegrip widget bindings.
#
# Dragging a sizegrip widget resizes the containing toplevel.
#
# NOTE: the sizegrip widget must be in the lower right hand corner.
#

switch -- [tk windowingsystem] {
    x11 -
    win32 {
	option add *TSizegrip.cursor [ttk::cursor seresize] widgetDefault
	option add *TSizegrip.cursor [ttk::cursor seresize]
    }
    aqua {
	# Aqua sizegrips use default Arrow cursor.
    	# Aqua sizegrips use default Arrow cursor.
    }
}

namespace eval ttk::sizegrip {
    variable State
    array set State {
	pressed 	0
	pressX 		0
	pressY 		0
	width 		0
	height 		0
	widthInc	1
	heightInc	1
        resizeX         1
        resizeY         1
	toplevel 	{}
    }
}

bind TSizegrip <Button-1> 		{ ttk::sizegrip::Press	%W %X %Y }
bind TSizegrip <ButtonPress-1> 		{ ttk::sizegrip::Press	%W %X %Y }
bind TSizegrip <B1-Motion> 		{ ttk::sizegrip::Drag 	%W %X %Y }
bind TSizegrip <ButtonRelease-1> 	{ ttk::sizegrip::Release %W %X %Y }

proc ttk::sizegrip::Press {W X Y} {
    variable State

    if {[$W instate disabled]} { return }

Changes to library/ttk/spinbox.tcl.

8
9
10
11
12
13
14
15

16
17
18
19
20
21


22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49

50
51
52
53
54
55
56
57
58
59

60
61

62
63

64
65
66

67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93

94
95

96
97

98
99

100
101
102
103
104
105
106
8
9
10
11
12
13
14

15
16
17
18
19


20
21
22
23
24
25

26










27
28
29
30
31


32

33
34
35
36

37
38
39
40
41
42
43
44
45
46

47
48

49
50

51
52
53

54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80

81
82

83


84
85

86
87
88
89
90
91
92
93







-
+




-
-
+
+




-
+
-
-
-
-
-
-
-
-
-
-





-
-

-
+



-
+









-
+

-
+

-
+


-
+

-
+













-
+










-
+

-
+
-
-
+

-
+







#
# Duplicate the Entry bindings, override if needed:
#

ttk::copyBindings TEntry TSpinbox

bind TSpinbox <Motion>			{ ttk::spinbox::Motion %W %x %y }
bind TSpinbox <Button-1> 		{ ttk::spinbox::Press %W %x %y }
bind TSpinbox <ButtonPress-1> 		{ ttk::spinbox::Press %W %x %y }
bind TSpinbox <ButtonRelease-1> 	{ ttk::spinbox::Release %W }
bind TSpinbox <Double-Button-1> 	{ ttk::spinbox::DoubleClick %W %x %y }
bind TSpinbox <Triple-Button-1> 	{} ;# disable TEntry triple-click

bind TSpinbox <Up>			{ event generate %W <<Increment>> }
bind TSpinbox <Down> 			{ event generate %W <<Decrement>> }
bind TSpinbox <KeyPress-Up>		{ event generate %W <<Increment>> }
bind TSpinbox <KeyPress-Down> 		{ event generate %W <<Decrement>> }

bind TSpinbox <<Increment>>		{ ttk::spinbox::Spin %W +1 }
bind TSpinbox <<Decrement>> 		{ ttk::spinbox::Spin %W -1 }

ttk::bindMouseWheel TSpinbox 		{ ttk::spinbox::Spin %W }
ttk::bindMouseWheel TSpinbox 		[list ttk::spinbox::MouseWheel %W]
bind TSpinbox <Shift-MouseWheel> {
    # Ignore the event
}
bind TSpinbox <TouchpadScroll> {
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    # TouchpadScroll events fire about 60 times per second.
    if {$deltaY != 0 && %# %% 12 == 0} {
	ttk::spinbox::Spin %W [expr {$deltaY > 0 ? -1 : 1}]
    }
}

## Motion --
#	Sets cursor.
#
proc ttk::spinbox::Motion {w x y} {
    variable State
    ttk::saveCursor $w State(userConfCursor) [ttk::cursor text]
    if {   [$w identify $x $y] eq "textarea"
	&& [$w instate {!readonly !disabled}]
        && [$w instate {!readonly !disabled}]
    } {
	ttk::setCursor $w text
    } else {
	ttk::setCursor $w $State(userConfCursor)
	ttk::setCursor $w ""
    }
}

## Press --
#
proc ttk::spinbox::Press {w x y} {
    if {[$w instate disabled]} { return }
    focus $w
    switch -glob -- [$w identify $x $y] {
	*textarea	{ ttk::entry::Press $w $x }
        *textarea	{ ttk::entry::Press $w $x }
	*rightarrow	-
	*uparrow 	{ ttk::Repeatedly event generate $w <<Increment>> }
        *uparrow 	{ ttk::Repeatedly event generate $w <<Increment>> }
	*leftarrow	-
	*downarrow	{ ttk::Repeatedly event generate $w <<Decrement>> }
        *downarrow	{ ttk::Repeatedly event generate $w <<Decrement>> }
	*spinbutton {
	    if {$y * 2 >= [winfo height $w]} {
		set event <<Decrement>>
	    	set event <<Decrement>>
	    } else {
		set event <<Increment>>
	    	set event <<Increment>>
	    }
	    ttk::Repeatedly event generate $w $event
	}
    }
}

## DoubleClick --
#	Select all if over the text area; otherwise same as Press.
#
proc ttk::spinbox::DoubleClick {w x y} {
    if {[$w instate disabled]} { return }

    switch -glob -- [$w identify $x $y] {
	*textarea	{ SelectAll $w }
        *textarea	{ SelectAll $w }
	*		{ Press $w $x $y }
    }
}

proc ttk::spinbox::Release {w} {
    ttk::CancelRepeat
}

## MouseWheel --
#	Mousewheel callback.  Turn these into <<Increment>> (-1, up)
# 	or <<Decrement> (+1, down) events. Not used any more.
# 	or <<Decrement> (+1, down) events.
#
proc ttk::spinbox::MouseWheel {w dir {factor 1.0}} {
proc ttk::spinbox::MouseWheel {w dir} {
    if {[$w instate disabled]} { return }
    if {($dir < 0) ^ ($factor < 0)} {
    if {$dir < 0} {
	event generate $w <<Increment>>
    } elseif {$dir != 0} {
    } else {
	event generate $w <<Decrement>>
    }
}

## SelectAll --
#	Select widget contents.
#
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163


164
165

166
167
168

169
170
171

172
173
174


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203
204
127
128
129
130
131
132
133

134









135







136
137


138



139



140
141


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173







-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
+
-
-
-
+

-
-
+
+

















-
+













## Spin --
#	Handle <<Increment>> and <<Decrement>> events.
#	If -values is specified, cycle through the list.
#	Otherwise cycle through numeric range based on
#	-from, -to, and -increment.
#
proc ttk::spinbox::Spin {w dir {factor -1.0}} {
proc ttk::spinbox::Spin {w dir} {
    variable State

    if {[$w instate disabled]} { return }

    if {![info exists State($w,values.length)]} {
	set State($w,values.index) -1
	set State($w,values.last) {}
    }
    set State($w,values) [$w cget -values]
    set nvalues [llength [set values [$w cget -values]]]
    set State($w,values.length) [llength $State($w,values)]

    set d [expr {-($dir/$factor)}]
    set d [expr {int($d > 0 ? ceil($d) : floor($d))}]
    if {$State($w,values.length) > 0} {
	set value [$w get]
	set current $State($w,values.index)
    set value [$w get]
    if {$nvalues} {
	if {$value ne $State($w,values.last)} {
	    set current [lsearch -exact $State($w,values) $value]
	set current [lsearch -exact $values $value]
	    if {$current < 0} {set current -1}
	}
	set State($w,values.index) [Adjust $w [expr {$current + $d}] 0 \
	set index [Adjust $w [expr {$current + $dir}] 0 [expr {$nvalues - 1}]]
		[expr {$State($w,values.length) - 1}]]
	set State($w,values.last) [lindex $State($w,values) $State($w,values.index)]
	$w set $State($w,values.last)
	$w set [lindex $values $index]
    } else {
	if {[catch {
	    set v [expr {[scan [$w get] %f] + $d * [$w cget -increment]}]
        if {[catch {
    	    set v [expr {[scan [$w get] %f] + $dir * [$w cget -increment]}]
	}]} {
	    set v [$w cget -from]
	}
	$w set [FormatValue $w [Adjust $w $v [$w cget -from] [$w cget -to]]]
    }
    SelectAll $w
    uplevel #0 [$w cget -command]
}

## FormatValue --
#	Reformat numeric value based on -format.
#
proc ttk::spinbox::FormatValue {w val} {
    set fmt [$w cget -format]
    if {$fmt eq ""} {
	# Try to guess a suitable -format based on -increment.
	set delta [expr {abs([$w cget -increment])}]
	if {0 < $delta && $delta < 1} {
        if {0 < $delta && $delta < 1} {
	    # NB: This guesses wrong if -increment has more than 1
	    # significant digit itself, e.g., -increment 0.25
	    set nsd [expr {int(ceil(-log10($delta)))}]
	    set fmt "%.${nsd}f"
	} else {
	    set fmt "%.0f"
	}
    }
    return [format $fmt $val]
}

#*EOF*

Changes to library/ttk/treeview.tcl.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
45








46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
16
17
18
19
20
21
22



23
24
25
26
27
28
29
30


31
32
33
34








35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61










62
63
64
65
66
67
68







-
-
-








-
-
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+














-



-
-
-
-
-
-
-
-
-
-







    set State(pressX)		0

    # For pressMode == "resize"
    set State(resizeColumn)	#0

    # For pressmode == "heading"
    set State(heading)  	{}

    set State(cellAnchor)	{}
    set State(cellAnchorOp)	"set"
}

### Widget bindings.
#

bind Treeview	<Motion> 		{ ttk::treeview::Motion %W %x %y }
bind Treeview	<B1-Leave>		{ #nothing }
bind Treeview	<Leave>			{ ttk::treeview::ActivateHeading {} {}}
bind Treeview	<Button-1> 		{ ttk::treeview::Press %W %x %y }
bind Treeview	<Double-Button-1> 	{ ttk::treeview::DoubleClick %W %x %y }
bind Treeview	<ButtonPress-1> 	{ ttk::treeview::Press %W %x %y }
bind Treeview	<Double-ButtonPress-1> 	{ ttk::treeview::DoubleClick %W %x %y }
bind Treeview	<ButtonRelease-1> 	{ ttk::treeview::Release %W %x %y }
bind Treeview	<B1-Motion> 		{ ttk::treeview::Drag %W %x %y }
bind Treeview 	<Up>    		{ ttk::treeview::Keynav %W up }
bind Treeview 	<Down>  		{ ttk::treeview::Keynav %W down }
bind Treeview 	<Right> 		{ ttk::treeview::Keynav %W right }
bind Treeview 	<Left>  		{ ttk::treeview::Keynav %W left }
bind Treeview	<Prior>			{ %W yview scroll -1 pages }
bind Treeview	<Next> 			{ %W yview scroll  1 pages }
bind Treeview	<Return>		{ ttk::treeview::ToggleFocus %W }
bind Treeview	<space>			{ ttk::treeview::ToggleFocus %W }
bind Treeview 	<KeyPress-Up>    	{ ttk::treeview::Keynav %W up }
bind Treeview 	<KeyPress-Down>  	{ ttk::treeview::Keynav %W down }
bind Treeview 	<KeyPress-Right> 	{ ttk::treeview::Keynav %W right }
bind Treeview 	<KeyPress-Left>  	{ ttk::treeview::Keynav %W left }
bind Treeview	<KeyPress-Prior>	{ %W yview scroll -1 pages }
bind Treeview	<KeyPress-Next> 	{ %W yview scroll  1 pages }
bind Treeview	<KeyPress-Return>	{ ttk::treeview::ToggleFocus %W }
bind Treeview	<KeyPress-space>	{ ttk::treeview::ToggleFocus %W }

bind Treeview	<Shift-Button-1> \
bind Treeview	<Shift-ButtonPress-1> \
		{ ttk::treeview::Select %W %x %y extend }
bind Treeview	<<ToggleSelection>> \
		{ ttk::treeview::Select %W %x %y toggle }

ttk::copyBindings TtkScrollable Treeview

### Binding procedures.
#

## Keynav -- Keyboard navigation
#
# @@@ TODO: verify/rewrite up and down code.
#
proc ttk::treeview::Keynav {w dir} {
    variable State
    set focus [$w focus]
    if {$focus eq ""} { return }

    set cells [expr {[$w cget -selecttype] eq "cell"}]

    if {$cells} {
        lassign $State(cellAnchor) _ colAnchor
        # Just in case, give it a valid value
        if {$colAnchor eq ""} {
            set colAnchor "#1"
        }
    }

    switch -- $dir {
	up {
	    if {[set up [$w prev $focus]] eq ""} {
	        set focus [$w parent $focus]
	    } else {
		while {[$w item $up -open] && [llength [$w children $up]]} {
		    set up [lindex [$w children $up] end]
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108


109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213

214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
78
79
80
81
82
83
84










85
86
87

88
89
90
91














92

93
94
95
96



97



98
99
100
101
102
103
104





105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

123











124
125
126
127
128
129
130
131
132
133













134
135
136
137
138
139


140
141
142
143

144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164



165
166
167
168
169
170
171
172







-
-
-
-
-
-
-
-
-
-
+
+

-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-




-
-
-
+
-
-
-







-
-
-
-
-
+

















-
+
-
-
-
-
-
-
-
-
-
-
-
+









-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+



-
+









-
+










-
-
-
+







		while {$up ne "" && [set down [$w next $up]] eq ""} {
		    set up [$w parent $up]
		}
		set focus $down
	    }
	}
	left {
            if {$cells} {
                # This assumes that colAnchor is of the "#N" format.
                set colNo [string range $colAnchor 1 end]
                set firstCol [expr {"tree" ni [$w cget -show]}]
                if {$colNo >  $firstCol} {
                    incr colNo -1
                    set colAnchor "#$colNo"
                }
            } elseif {[$w item $focus -open] && [llength [$w children $focus]]} {
		CloseItem $w $focus
	    if {[$w item $focus -open] && [llength [$w children $focus]]} {
	    	CloseItem $w $focus
	    } else {
		set focus [$w parent $focus]
	    	set focus [$w parent $focus]
	    }
	}
	right {
            if {$cells} {
                set colNo [string range $colAnchor 1 end]
                set dispCol [$w cget -displaycolumns]
                if {$dispCol eq "#all"} {
                    set lastCol [llength [$w cget -columns]]
                } else {
                    set lastCol [llength $dispCol]
                }
                if {$colNo < ($lastCol - 1)} {
                    incr colNo
                    set colAnchor "#$colNo"
                }
            } else {
                OpenItem $w $focus
	    OpenItem $w $focus
            }
	}
    }

    if {$focus != {}} {
        if {$cells} {
            set cell [list $focus $colAnchor]
            SelectOp $w $focus $cell choose
	SelectOp $w $focus choose
        } else {
            SelectOp $w $focus "" choose
        }
    }
}

## Motion -- pointer motion binding.
#	Sets cursor, active element ...
#
proc ttk::treeview::Motion {w x y} {
    variable State

    ttk::saveCursor $w State(userConfCursor) [ttk::cursor hresize]

    set cursor $State(userConfCursor)
    set cursor {}
    set activeHeading {}

    switch -- [$w identify region $x $y] {
	separator { set cursor hresize }
	heading { set activeHeading [$w identify column $x $y] }
    }

    ttk::setCursor $w $cursor
    ActivateHeading $w $activeHeading
}

## ActivateHeading -- track active heading element
#
proc ttk::treeview::ActivateHeading {w heading} {
    variable State

    if {$w != $State(activeWidget) || $heading != $State(activeHeading)} {
	if {[winfo exists $State(activeWidget)] && $State(activeHeading) != {}} {
	if {$State(activeHeading) != {}} {
	    # It may happen that $State(activeHeading) no longer corresponds
	    # to an existing display column. This happens for instance when
	    # changing -displaycolumns in a bound script when this change
	    # triggers a <Leave> event. A proc checking if the display column
	    # $State(activeHeading) is really still present or not could be
	    # written but it would need to check several special cases:
	    #   a. -displaycolumns "#all" or being an explicit columns list
	    #   b. column #0 display is not governed by the -displaycolumn
	    #      list but by the value of the -show option
	    # --> Let's rather catch the following line.
	    catch {$State(activeWidget) heading $State(activeHeading) state !active}
	    $State(activeWidget) heading $State(activeHeading) state !active
	}
	if {$heading != {}} {
	    $w heading $heading state active
	}
	set State(activeHeading) $heading
	set State(activeWidget) $w
    }
}

## IndentifyCell -- Locate the cell at coordinate
#	Only active when -selecttype is "cell", and leaves cell empty otherwise.
#       Down the call chain it is enough to check cell to know the selecttype.
proc ttk::treeview::IdentifyCell {w x y} {
    set cell {}
    if {[$w cget -selecttype] eq "cell"} {
        # Later handling assumes that the column in the cell ID is of the
        # format #N, which is always the case from "identify cell"
        set cell [$w identify cell $x $y]
    }
    return $cell
}

## Select $w $x $y $selectop
#	Binding procedure for selection operations.
#	See "Selection modes", below.
#
proc ttk::treeview::Select {w x y op} {
    if {[set item [$w identify row $x $y]] ne "" } {
        set cell [IdentifyCell $w $x $y]
	SelectOp $w $item $cell $op
	SelectOp $w $item $op
    }
}

## DoubleClick -- Double-Button-1 binding.
## DoubleClick -- Double-ButtonPress-1 binding.
#
proc ttk::treeview::DoubleClick {w x y} {
    if {[set row [$w identify row $x $y]] ne ""} {
	Toggle $w $row
    } else {
	Press $w $x $y ;# perform single-click action
    }
}

## Press -- Button binding.
## Press -- ButtonPress binding.
#
proc ttk::treeview::Press {w x y} {
    focus $w
    switch -- [$w identify region $x $y] {
	nothing { }
	heading { heading.press $w $x $y }
	separator { resize.press $w $x $y }
	tree -
	cell {
	    set item [$w identify item $x $y]
            set cell [IdentifyCell $w $x $y]

	    SelectOp $w $item $cell choose
	    SelectOp $w $item choose
	    switch -glob -- [$w identify element $x $y] {
		*indicator -
		*disclosure { Toggle $w $item }
	    }
	}
    }
}
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320


321
322
323
324
325
326
327



328
329
330
331
332
333



334
335
336
337
338


339
340

341
342
343
344
345
346
347
348


349
350

351
352
353
354
355
356
357
358
359
360
361
362




363
364
365
366
367
368
369
370
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247


248
249
250
251
252
253



254
255
256
257
258
259



260
261
262
263
264
265


266
267
268

269








270
271


272












273
274
275
276

277
278
279
280
281
282
283







-
+


















-
+

-
+


















-
-
+
+




-
-
-
+
+
+



-
-
-
+
+
+



-
-
+
+

-
+
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-








proc ttk::treeview::resize.drag {w x} {
    variable State
    $w drag $State(resizeColumn) $x
}

proc ttk::treeview::resize.release {w x} {
    $w drop
    # no-op
}

### Heading activation.
#

proc ttk::treeview::heading.press {w x y} {
    variable State
    set column [$w identify column $x $y]
    set State(pressMode) "heading"
    set State(heading) $column
    $w heading $column state pressed
}

proc ttk::treeview::heading.drag {w x y} {
    variable State
    if {   [$w identify region $x $y] eq "heading"
        && [$w identify column $x $y] eq $State(heading)
    } {
	$w heading $State(heading) state pressed
    	$w heading $State(heading) state pressed
    } else {
	$w heading $State(heading) state !pressed
    	$w heading $State(heading) state !pressed
    }
}

proc ttk::treeview::heading.release {w} {
    variable State
    if {[lsearch -exact [$w heading $State(heading) state] pressed] >= 0} {
	after 0 [$w heading $State(heading) -command]
    }
    $w heading $State(heading) state !pressed
}

### Selection modes.
#

## SelectOp $w $item [ choose | extend | toggle ] --
#	Dispatch to appropriate selection operation
#	depending on current value of -selectmode.
#
proc ttk::treeview::SelectOp {w item cell op} {
    select.$op.[$w cget -selectmode] $w $item $cell
proc ttk::treeview::SelectOp {w item op} {
    select.$op.[$w cget -selectmode] $w $item
}

## -selectmode none:
#
proc ttk::treeview::select.choose.none {w item cell} { $w focus $item; $w see $item }
proc ttk::treeview::select.toggle.none {w item cell} { $w focus $item; $w see $item }
proc ttk::treeview::select.extend.none {w item cell} { $w focus $item; $w see $item }
proc ttk::treeview::select.choose.none {w item} { $w focus $item }
proc ttk::treeview::select.toggle.none {w item} { $w focus $item }
proc ttk::treeview::select.extend.none {w item} { $w focus $item }

## -selectmode browse:
#
proc ttk::treeview::select.choose.browse {w item cell} { BrowseTo $w $item $cell }
proc ttk::treeview::select.toggle.browse {w item cell} { BrowseTo $w $item $cell }
proc ttk::treeview::select.extend.browse {w item cell} { BrowseTo $w $item $cell }
proc ttk::treeview::select.choose.browse {w item} { BrowseTo $w $item }
proc ttk::treeview::select.toggle.browse {w item} { BrowseTo $w $item }
proc ttk::treeview::select.extend.browse {w item} { BrowseTo $w $item }

## -selectmode multiple:
#
proc ttk::treeview::select.choose.extended {w item cell} {
    BrowseTo $w $item $cell
proc ttk::treeview::select.choose.extended {w item} {
    BrowseTo $w $item
}
proc ttk::treeview::select.toggle.extended {w item cell} {
proc ttk::treeview::select.toggle.extended {w item} {
    variable State
    if {$cell ne ""} {
        $w cellselection toggle [list $cell]
        set State(cellAnchor) $cell
        set State(cellAnchorOp) add
    } else {
        $w selection toggle [list $item]
    }
    $w selection toggle [list $item]
}
}
proc ttk::treeview::select.extend.extended {w item cell} {
proc ttk::treeview::select.extend.extended {w item} {
    variable State
    if {$cell ne ""} {
        if {$State(cellAnchor) ne ""} {
            $w cellselection $State(cellAnchorOp) $State(cellAnchor) $cell
        } else {
            BrowseTo $w $item $cell
        }
    } else {
        if {[set anchor [$w focus]] ne ""} {
            $w selection set [between $w $anchor $item]
        } else {
            BrowseTo $w $item $cell
    if {[set anchor [$w focus]] ne ""} {
	$w selection set [between $w $anchor $item]
    } else {
    	BrowseTo $w $item
        }
    }
}

### Tree structure utilities.
#

## between $tv $item1 $item2 --
388
389
390
391
392
393
394
395

396
397
398

399
400
401
402
403
404
405
301
302
303
304
305
306
307

308
309
310

311
312
313
314
315
316
317
318







-
+


-
+







#	Recursive worker routine for ttk::treeview::between
#
proc ttk::treeview::ScanBetween {tv item1 item2 item} {
    variable between
    variable selectingBetween

    if {$item eq $item1 || $item eq $item2} {
	lappend between $item
    	lappend between $item
	set selectingBetween [expr {!$selectingBetween}]
    } elseif {$selectingBetween} {
	lappend between $item
    	lappend between $item
    }
    foreach child [$tv children $item] {
	ScanBetween $tv $item1 $item2 $child
    }
}

### User interaction utilities.
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444

445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460

461
462
463
464
332
333
334
335
336
337
338






339
340
341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356

357


358
359






360

361
362
363







-
-
-
-
-
-












-
+





-
+
-
-


-
-
-
-
-
-
+
-



    $w focus $item
    event generate $w <<TreeviewClose>>
}

## Toggle -- toggle opened/closed state of item
#
proc ttk::treeview::Toggle {w item} {
    # don't allow toggling on indicators that
    # are not present in front of leaf items
    if {[$w children $item] == {}} {
        return
    }
    # not a leaf, toggle!
    if {[$w item $item -open]} {
	CloseItem $w $item
    } else {
	OpenItem $w $item
    }
}

## ToggleFocus -- toggle opened/closed state of focus item
#
proc ttk::treeview::ToggleFocus {w} {
    set item [$w focus]
    if {$item ne ""} {
	Toggle $w $item
    	Toggle $w $item
    }
}

## BrowseTo -- navigate to specified item; set focus and selection
#
proc ttk::treeview::BrowseTo {w item cell} {
proc ttk::treeview::BrowseTo {w item} {
    variable State

    $w see $item
    $w focus $item
    set State(cellAnchor) $cell
    set State(cellAnchorOp) set
    if {$cell ne ""} {
        $w cellselection set [list $cell]
    } else {
        $w selection set [list $item]
    $w selection set [list $item]
    }
}

#*EOF*

Changes to library/ttk/ttk.tcl.

8
9
10
11
12
13
14
15
16
17



18
19
20
21
22
23
24
8
9
10
11
12
13
14



15
16
17
18
19
20
21
22
23
24







-
-
-
+
+
+







namespace eval ::ttk {
    variable library
    if {![info exists library]} {
	set library [file dirname [info script]]
    }
}

source -encoding utf-8 [file join $::ttk::library fonts.tcl]
source -encoding utf-8 [file join $::ttk::library cursors.tcl]
source -encoding utf-8 [file join $::ttk::library utils.tcl]
source [file join $::ttk::library fonts.tcl]
source [file join $::ttk::library cursors.tcl]
source [file join $::ttk::library utils.tcl]

## ttk::deprecated $old $new --
#	Define $old command as a deprecated alias for $new command
#	$old and $new must be fully namespace-qualified.
#
proc ttk::deprecated {old new} {
    interp alias {} $old {} ttk::do'deprecate $old $new
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139












140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
91
92
93
94
95
96
97




























98
99












100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+













-
+












-
+







    if {$theme ni [::ttk::style theme names]} {
	package require ttk::theme::$theme
    }
    ::ttk::style theme use $theme
    set currentTheme $theme
}

## ttk::setTreeviewRowHeight --
#	Sets the default height of the ttk::treeview rows for the current theme.
#	To be invoked from within the library files for the built-in themes.
#
proc ::ttk::setTreeviewRowHeight {} {
    set font [::ttk::style lookup Treeview -font]
    if {$font eq {}} {
	set font TkDefaultFont
    }

    ::ttk::style configure Treeview -rowheight \
	    [expr {[font metrics $font -linespace] + 2}]
}

# Applications should make sure that the ttk::setTreeviewRowHeight
# procedure will be invoked whenever the virtual event <<ThemeChanged>>
# is received (e.g., because the value of the Treeview style's -font
# option has changed), or the virtual event <<TkWorldChanged>> with
# the user_data field (%d) set to "FontChanged" is received.  Example:
#
# bindtags . [linsert [bindtags .] 1 MyMainWin]
# bind MyMainWin <<ThemeChanged>> ttk::setTreeviewRowHeight
# bind MyMainWin <<TkWorldChanged>> {
#     if {"%d" eq "FontChanged"} {
#         ttk::setTreeviewRowHeight
#     }
# }

### Load widget bindings.
#
source -encoding utf-8 [file join $::ttk::library button.tcl]
source -encoding utf-8 [file join $::ttk::library menubutton.tcl]
source -encoding utf-8 [file join $::ttk::library scrollbar.tcl]
source -encoding utf-8 [file join $::ttk::library scale.tcl]
source -encoding utf-8 [file join $::ttk::library progress.tcl]
source -encoding utf-8 [file join $::ttk::library notebook.tcl]
source -encoding utf-8 [file join $::ttk::library panedwindow.tcl]
source -encoding utf-8 [file join $::ttk::library entry.tcl]
source -encoding utf-8 [file join $::ttk::library combobox.tcl]	;# dependency: entry.tcl
source -encoding utf-8 [file join $::ttk::library spinbox.tcl]  ;# dependency: entry.tcl
source -encoding utf-8 [file join $::ttk::library treeview.tcl]
source -encoding utf-8 [file join $::ttk::library sizegrip.tcl]
source [file join $::ttk::library button.tcl]
source [file join $::ttk::library menubutton.tcl]
source [file join $::ttk::library scrollbar.tcl]
source [file join $::ttk::library scale.tcl]
source [file join $::ttk::library progress.tcl]
source [file join $::ttk::library notebook.tcl]
source [file join $::ttk::library panedwindow.tcl]
source [file join $::ttk::library entry.tcl]
source [file join $::ttk::library combobox.tcl]	;# dependency: entry.tcl
source [file join $::ttk::library spinbox.tcl]  ;# dependency: entry.tcl
source [file join $::ttk::library treeview.tcl]
source [file join $::ttk::library sizegrip.tcl]

## Label and Labelframe bindings:
#  (not enough to justify their own file...)
#
bind TLabelframe <<Invoke>>	{ tk::TabToWindow [tk_focusNext %W] }
bind TLabel <<Invoke>>		{ tk::TabToWindow [tk_focusNext %W] }

### Load settings for built-in themes:
#
proc ttk::LoadThemes {} {
    variable library

    # "default" always present:
    uplevel #0 [list source -encoding utf-8 [file join $library defaults.tcl]]
    uplevel #0 [list source [file join $library defaults.tcl]]

    set builtinThemes [style theme names]
    foreach {theme scripts} {
	classic 	classicTheme.tcl
	alt 		altTheme.tcl
	clam 		clamTheme.tcl
	winnative	winTheme.tcl
	xpnative	{xpTheme.tcl vistaTheme.tcl}
	aqua 		aquaTheme.tcl
    } {
	if {[lsearch -exact $builtinThemes $theme] >= 0} {
            foreach script $scripts {
                uplevel #0 [list source -encoding utf-8 [file join $library $script]]
                uplevel #0 [list source [file join $library $script]]
            }
	}
    }
}

ttk::LoadThemes; rename ::ttk::LoadThemes {}

197
198
199
200
201
202
203
204
205
206
207
208
169
170
171
172
173
174
175




176







-
-
-
-

	}
    }
    return "default"
}

ttk::setTheme [ttk::DefaultTheme] ; rename ttk::DefaultTheme {}

# Scale the default ttk::scale and ttk::progressbar length
option add *TScale.length	75p widgetDefault
option add *TProgressbar.length	75p widgetDefault

#*EOF*

Changes to library/ttk/utils.tcl.

54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+














-
+







	event generate $focus <<TraverseOut>>
    }
    focus $w
    event generate $w <<TraverseIn>>
}

## ttk::clickToFocus $w --
#	Utility routine, used in <Button-1> bindings --
#	Utility routine, used in <ButtonPress-1> bindings --
#	Assign keyboard focus to the specified widget if -takefocus is enabled.
#
proc ttk::clickToFocus {w} {
    if {[ttk::takesFocus $w]} { focus $w }
}

## ttk::takesFocus w --
#	Test if the widget can take keyboard focus.
#
#	See the description of the -takefocus option in options(n)
#	for details.
#
proc ttk::takesFocus {w} {
    if {![winfo viewable $w]} {
	return 0
    	return 0
    } elseif {[catch {$w cget -takefocus} takefocus]} {
	return [GuessTakeFocus $w]
    } else {
	switch -- $takefocus {
	    "" { return [GuessTakeFocus $w] }
	    0  { return 0 }
	    1  { return 1 }
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+








-
+







	return
    }

    set restoreGrab [set restoreFocus ""]

    set grabbed [grab current $w]
    if {[winfo exists $grabbed]} {
	switch [grab status $grabbed] {
    	switch [grab status $grabbed] {
	    global { set restoreGrab [list grab -global $grabbed] }
	    local  { set restoreGrab [list grab $grabbed] }
	    none   { ;# grab window is really in a different interp }
	}
    }

    set focus [focus]
    if {$focus ne ""} {
	set restoreFocus [list focus -force $focus]
    	set restoreFocus [list focus -force $focus]
    }

    set Grab($w) [list $restoreGrab $restoreFocus]
}

## RestoreGrab --
#	Restore previous grab and focus windows.
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256







-

+







-

+







#	Begin auto-repeat.
#
proc ttk::Repeatedly {args} {
    variable Repeat
    after cancel $Repeat(timer)
    set script [uplevel 1 [list namespace code $args]]
    set Repeat(script) $script
    set Repeat(timer) [after $Repeat(delay) ttk::Repeat]
    uplevel #0 $script
    set Repeat(timer) [after $Repeat(delay) ttk::Repeat]
}

## Repeat --
#	Continue auto-repeat
#
proc ttk::Repeat {} {
    variable Repeat
    set Repeat(timer) [after $Repeat(interval) ttk::Repeat]
    uplevel #0 $Repeat(script)
    set Repeat(timer) [after $Repeat(interval) ttk::Repeat]
}

## ttk::CancelRepeat --
#	Halt auto-repeat.
#
proc ttk::CancelRepeat {} {
    variable Repeat
268
269
270
271
272
273
274















275
276
277
278
279
280
281
282
283
284


285
286
287






288
289






290
291
292
293

294
295








296
297

298
299

300
301

302
303
304


305
306

307
308



309
310
311
312









313
314
315
316
317


318
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297


298
299
300
301
302
303
304
305
306
307
308


309
310
311
312
313
314
315
316
317
318
319


320
321
322
323
324
325
326
327


328


329


330



331
332


333


334
335
336
337



338
339
340
341
342
343
344
345
346
347




348
349
350







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
+
+



+
+
+
+
+
+
-
-
+
+
+
+
+
+




+
-
-
+
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
-
+
+
-
-
+
-
-
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+

	bind $to $event [bind $from $event]
    }
}

### Mousewheel bindings.
#
# Platform inconsistencies:
#
# On X11, the server typically maps the mouse wheel to Button4 and Button5.
#
# On OSX, Tk generates sensible values for the %D field in <MouseWheel> events.
#
# On Windows, %D must be scaled by a factor of 120.
# In addition, Tk redirects mousewheel events to the window with
# keyboard focus instead of sending them to the window under the pointer.
# We do not attempt to fix that here, see also TIP#171.
#
# OSX conventionally uses Shift+MouseWheel for horizontal scrolling,
# and Option+MouseWheel for accelerated scrolling.
#
# The Shift+MouseWheel behavior is not conventional on Windows or most
# X11 toolkits, but it's useful.
#
# MouseWheel scrolling is accelerated on X11, which is conventional
# for Tk and appears to be conventional for other toolkits (although
# Gtk+ and Qt do not appear to use as large a factor).
#

## ttk::bindMouseWheel $bindtag $command...
#	Adds basic mousewheel support to $bindtag.
#	$command will be passed two additional arguments
#	specifying the mousewheel change and a factor.
#	$command will be passed one additional argument
#	specifying the mousewheel direction (-1: up, +1: down).
#

proc ttk::bindMouseWheel {bindtag callback} {
    switch -- [tk windowingsystem] {
	x11 {
	    bind $bindtag <ButtonPress-4> "$callback -1"
	    bind $bindtag <ButtonPress-5> "$callback +1"
	}
	win32 {
    bind $bindtag <MouseWheel> "$callback %D -120.0"
    bind $bindtag <Option-MouseWheel> "$callback %D -12.0"
	    bind $bindtag <MouseWheel> [append callback { [expr {-(%D/120)}]}]
	}
	aqua {
	    bind $bindtag <MouseWheel> [append callback { [expr {-(%D)}]} ]
	}
    }
}

## Mousewheel bindings for standard scrollable widgets.
#
# Usage: [ttk::copyBindings TtkScrollable $bindtag]

bind TtkScrollable <MouseWheel> \
#
# $bindtag should be for a widget that supports the
# standard scrollbar protocol.
#

switch -- [tk windowingsystem] {
    x11 {
	bind TtkScrollable <ButtonPress-4>       { %W yview scroll -5 units }
	{ tk::MouseWheel %W y %D -40.0 }
bind TtkScrollable <Option-MouseWheel> \
	bind TtkScrollable <ButtonPress-5>       { %W yview scroll  5 units }
	{ tk::MouseWheel %W y %D -12.0 }
bind TtkScrollable <Shift-MouseWheel> \
	bind TtkScrollable <Shift-ButtonPress-4> { %W xview scroll -5 units }
	{ tk::MouseWheel %W x %D -40.0 }
bind TtkScrollable <Shift-Option-MouseWheel> \
	bind TtkScrollable <Shift-ButtonPress-5> { %W xview scroll  5 units }
	{ tk::MouseWheel %W x %D -12.0 }

## Touchpad scrolling
    }
    win32 {
#
bind TtkScrollable <TouchpadScroll> {
	bind TtkScrollable <MouseWheel> \
    if {%# %% 5 != 0} {
        return
	    { %W yview scroll [expr {-(%D/120)}] units }
	bind TtkScrollable <Shift-MouseWheel> \
	    { %W xview scroll [expr {-(%D/120)}] units }
    }
    lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
    if {$deltaX != 0} {
 	%W xview scroll [expr {-$deltaX}] units
    aqua {
	bind TtkScrollable <MouseWheel> \
	    { %W yview scroll [expr {-(%D)}] units }
	bind TtkScrollable <Shift-MouseWheel> \
	    { %W xview scroll [expr {-(%D)}] units }
	bind TtkScrollable <Option-MouseWheel> \
	    { %W yview scroll  [expr {-10*(%D)}] units }
	bind TtkScrollable <Shift-Option-MouseWheel> \
	    { %W xview scroll [expr {-10*(%D)}] units }
    }
    if {$deltaY != 0} {
	%W yview scroll [expr {-$deltaY}] units
    }
}
}

#*EOF*

Changes to library/ttk/vistaTheme.tcl.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32











33
34
35
36
37
38
39
40


41
42
43
44

45
46
47
48
49
50

51
52

53
54
55

56
57

58
59
60
61
62
63
64





65
66
67
68
69
70
71

72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
17
18
19
20
21
22
23









24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46

47



48


49


50
51
52

53
54

55
56
57





58
59
60
61
62
63
64
65
66
67
68

69



70
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







-
+
+



-
+
-
-
-

-
-
+
-
-
+


-
+

-
+


-
-
-
-
-
+
+
+
+
+






-
+
-
-
-
+
+
-

















-
+

-
+
+


















-
+
+







    ttk::style theme settings vista {

 	ttk::style configure . \
	    -background SystemButtonFace \
	    -foreground SystemWindowText \
	    -selectforeground SystemHighlightText \
	    -selectbackground SystemHighlight \
	    -insertcolor SystemWindowText \
	    -font TkDefaultFont

	ttk::style map "." -foreground {disabled SystemGrayText}

	ttk::style configure TButton -anchor center -padding 0.75p -width -11
	ttk::style configure TRadiobutton -padding 1.5p
	ttk::style configure TCheckbutton -padding 1.5p
	ttk::style configure TMenubutton -padding {6p 3p}
	    -font TkDefaultFont \
	    ;

	ttk::style map "." \
	    -foreground [list disabled SystemGrayText] \
	    ;

	ttk::style configure TButton -anchor center -padding {1 1} -width -11
	ttk::style configure TRadiobutton -padding 2
	ttk::style configure TCheckbutton -padding 2
	ttk::style configure TMenubutton -padding {8 4}

	ttk::style element create Menubutton.dropdown vsapi \
	    TOOLBAR 4 {{selected active} 6 {selected !active} 5
		disabled 4 pressed 3 active 2 {} 1} \
	    -syssize {SM_CXVSCROLL SM_CYVSCROLL}

	ttk::style configure TNotebook -tabmargins {2 2 2 0}
	ttk::style map TNotebook.Tab -expand {selected {2 2 2 2}}
	ttk::style map TNotebook.Tab \
	    -expand [list selected {2 2 2 2}]

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont
	ttk::style configure Treeview -background SystemWindow \
	ttk::style configure Treeview -background SystemWindow
                -stripedbackground System3dLight
	ttk::style configure Treeview.Separator \
                -background System3dLight
	ttk::style map Treeview \
	    -background [list   disabled SystemButtonFace \
				selected SystemHighlight] \
	    -background [list selected SystemHighlight] \
	    -foreground [list   disabled SystemGrayText \
				selected SystemHighlightText]
	    -foreground [list selected SystemHighlightText] ;

        # Label and Toolbutton
	ttk::style configure TLabelframe.Label -foreground SystemButtonText
	ttk::style configure TLabelframe.Label -foreground "#0046d5"

	ttk::style configure Toolbutton -padding 3p
	ttk::style configure Toolbutton -padding {4 4}

        # Combobox
	ttk::style configure TCombobox -padding 1.5p
        ttk::style element create Combobox.border vsapi \
            COMBOBOX 4 {disabled 4 focus 3 active 2 hover 2 {} 1}
        ttk::style element create Combobox.background vsapi \
            EDIT 3 {disabled 3 readonly 5 focus 4 hover 2 {} 1}
	ttk::style configure TCombobox -padding 2
        ttk::style element create Combobox.field vsapi \
            COMBOBOX 2 {{} 1}
        ttk::style element create Combobox.border vsapi \
            COMBOBOX 4 {disabled 4 focus 3 active 2 hover 2 {} 1}
        ttk::style element create Combobox.rightdownarrow vsapi \
            COMBOBOX 6 {disabled 4 pressed 3 active 2 {} 1} \
            -syssize {SM_CXVSCROLL SM_CYVSCROLL}
        ttk::style layout TCombobox {
            Combobox.border -sticky nswe -border 0 -children {
                Combobox.rightdownarrow -side right -sticky ns
                Combobox.padding -sticky nswe -children {
                Combobox.padding -expand 1 -sticky nswe -children {
                    Combobox.background -sticky nswe -children {
                        Combobox.focus -sticky nswe -children {
                            Combobox.textarea -sticky nswe
                    Combobox.focus -expand 1 -sticky nswe -children {
                        Combobox.textarea -sticky nswe
                        }
                    }
                }
            }
        }
        # Vista.Combobox droplist frame
        ttk::style element create ComboboxPopdownFrame.background vsapi\
            LISTBOX 3 {disabled 4 active 3 focus 2 {} 1}
        ttk::style layout ComboboxPopdownFrame {
            ComboboxPopdownFrame.background -sticky news -border 1 -children {
                ComboboxPopdownFrame.padding -sticky news
            }
        }
	ttk::style map TCombobox \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText] \
	    -foreground	[list \
		disabled		SystemGrayText \
		{readonly focus}	SystemHighlightText \
	    	{readonly focus}	SystemHighlightText \
	    ] \
	    -focusfill	[list {readonly focus} SystemHighlight]
	    -focusfill	[list {readonly focus} SystemHighlight] \
	    ;

        # Entry
        ttk::style configure TEntry -padding {1 1 1 1} ;# Needs lookup
        ttk::style element create Entry.field vsapi \
            EDIT 6 {disabled 4 focus 3 hover 2 {} 1} -padding {2 2 2 2}
        ttk::style element create Entry.background vsapi \
            EDIT 3 {disabled 3 readonly 3 focus 4 hover 2 {} 1}
        ttk::style layout TEntry {
            Entry.field -sticky news -border 0 -children {
                Entry.background -sticky news -children {
                    Entry.padding -sticky news -children {
                        Entry.textarea -sticky news
                    }
                }
            }
        }
	ttk::style map TEntry \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText]
	    -selectforeground [list !focus SystemWindowText] \
	    ;

        # Spinbox
        ttk::style configure TSpinbox -padding 0
        ttk::style element create Spinbox.field vsapi \
            EDIT 9 {disabled 4 focus 3 hover 2 {} 1} -padding {1 1 1 2}
        ttk::style element create Spinbox.background vsapi \
            EDIT 3 {disabled 3 readonly 3 focus 4 hover 2 {} 1}
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148


149
150
151
152
153
154
155
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154







-
+









-
+
+







            -padding 1 -halfheight 1 \
            -syssize { SM_CXVSCROLL SM_CYVSCROLL }
        ttk::style layout TSpinbox {
            Spinbox.field -sticky nswe -children {
                Spinbox.background -sticky news -children {
                    Spinbox.padding -sticky news -children {
                        Spinbox.innerbg -sticky news -children {
                            Spinbox.textarea
                            Spinbox.textarea -expand 1
                        }
                    }
                    Spinbox.uparrow -side top -sticky ens
                    Spinbox.downarrow -side bottom -sticky ens
                }
            }
        }
	ttk::style map TSpinbox \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText]
	    -selectforeground [list !focus SystemWindowText] \
	    ;


        # SCROLLBAR elements (Vista includes a state for 'hover')
        ttk::style element create Vertical.Scrollbar.uparrow vsapi \
            SCROLLBAR 1 {disabled 4 pressed 3 active 2 hover 17 {} 1} \
            -syssize {SM_CXVSCROLL SM_CYVSCROLL}
        ttk::style element create Vertical.Scrollbar.downarrow vsapi \
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203


204
205
206
207
208
209
210
211
212
213
214


215
216
217
218
219
220
221
222

223
224
225
226
227
228
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200


201
202
203
204
205
206
207
208
209
210
211


212
213
214
215
216
217
218
219
220

221


222
223
224
225







-
+















-
-
+
+









-
-
+
+







-
+
-
-





        # Progressbar
        ttk::style element create Horizontal.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Horizontal.TProgressbar {
            Horizontal.Progressbar.trough -sticky nswe -children {
                Horizontal.Progressbar.pbar -side left -sticky ns
                Horizontal.Progressbar.ctext -sticky nesw
                Horizontal.Progressbar.text -sticky nesw
            }
        }
        ttk::style element create Vertical.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Vertical.TProgressbar {
            Vertical.Progressbar.trough -sticky nswe -children {
                Vertical.Progressbar.pbar -side bottom -sticky we
            }
        }

        # Scale
        ttk::style element create Horizontal.Scale.slider vsapi \
            TRACKBAR 3 {disabled 5 focus 4 pressed 3 active 2 {} 1} \
            -width 6 -height 12
        ttk::style layout Horizontal.TScale {
            Scale.focus -sticky nswe -children {
                Horizontal.Scale.trough -sticky nswe -children {
            Scale.focus -expand 1 -sticky nswe -children {
                Horizontal.Scale.trough -expand 1 -sticky nswe -children {
                    Horizontal.Scale.track -sticky we
                    Horizontal.Scale.slider -side left -sticky {}
                }
            }
        }
        ttk::style element create Vertical.Scale.slider vsapi \
            TRACKBAR 6 {disabled 5 focus 4 pressed 3 active 2 {} 1} \
            -width 12 -height 6
        ttk::style layout Vertical.TScale {
            Scale.focus -sticky nswe -children {
                Vertical.Scale.trough -sticky nswe -children {
            Scale.focus -expand 1 -sticky nswe -children {
                Vertical.Scale.trough -expand 1 -sticky nswe -children {
                    Vertical.Scale.track -sticky ns
                    Vertical.Scale.slider -side top -sticky {}
                }
            }
        }

        # Treeview
        ttk::style configure Item -padding {3p 0 0 0}
        ttk::style configure Item -padding {4 0 0 0}
	ttk::style configure Treeview -indent 15p
	ttk::setTreeviewRowHeight

        package provide ttk::theme::vista 1.0
    }
}

Changes to library/ttk/winTheme.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20





21
22
23
24
25
26
27


28
29

30


31
32
33
34
35
36
37
38
39
40






41
42
43
44
45

46
47
48
49

50
51


52
53
54
55
56
57

58
59
60
61

62
63

64
65

66
67
68
69


70
71
72
73
74
75

76
77
78
79
80

81
82

83
84
85

86
87
88
1
2
3
4
5

6
7
8
9
10
11
12


13




14
15
16
17
18
19
20
21




22
23

24
25

26
27
28
29
30
31
32





33
34
35
36
37
38
39
40
41
42

43
44
45
46

47
48

49
50
51
52
53
54
55

56
57
58
59

60
61

62
63

64
65
66


67
68
69
70
71



72


73


74


75
76
77

78

79
80





-







-
-

-
-
-
-
+
+
+
+
+



-
-
-
-
+
+
-

+
-
+
+





-
-
-
-
-
+
+
+
+
+
+




-
+



-
+

-
+
+





-
+



-
+

-
+

-
+


-
-
+
+



-
-
-
+
-
-

-
-
+
-
-
+


-
+
-


#
# Settings for 'winnative' theme.
#

namespace eval ttk::theme::winnative {

    ttk::style theme settings winnative {

	ttk::style configure "." \
	    -background SystemButtonFace \
	    -foreground SystemWindowText \
	    -selectforeground SystemHighlightText \
	    -selectbackground SystemHighlight \
	    -fieldbackground SystemWindow \
	    -insertcolor SystemWindowText \
	    -troughcolor SystemScrollbar \
	    -font TkDefaultFont

	ttk::style map "." -foreground {disabled SystemGrayText}
        ttk::style map "." -embossed {disabled 1}
	    -font TkDefaultFont \
	    ;

	ttk::style map "." -foreground [list disabled SystemGrayText] ;
        ttk::style map "." -embossed [list disabled 1] ;

	ttk::style configure TButton \
	    -anchor center -width -11 -relief raised -shiftrelief 1
	ttk::style map TButton -relief {{!disabled pressed} sunken}

	ttk::style configure TCheckbutton -padding {1.5p 3p}
	ttk::style configure TRadiobutton -padding {1.5p 3p}
	ttk::style configure TCheckbutton -padding "2 4"
	ttk::style configure TRadiobutton -padding "2 4"

	ttk::style configure TMenubutton \
	    -padding "8 4" -arrowsize 3 -relief raised
	    -padding {6p 3p} -arrowsize 2.25p -relief raised

	ttk::style map TButton -relief {{!disabled pressed} sunken}

	ttk::style configure TEntry \
	    -padding 2 -selectborderwidth 0 -insertwidth 1
	ttk::style map TEntry \
	    -fieldbackground \
		{readonly SystemButtonFace disabled SystemButtonFace} \
	    -selectbackground {!focus SystemWindow} \
	    -selectforeground {!focus SystemWindowText}

	ttk::style configure TCombobox -padding 1.5p
	    	[list readonly SystemButtonFace disabled SystemButtonFace] \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText] \
	    ;

	ttk::style configure TCombobox -padding 2
	ttk::style map TCombobox \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText] \
	    -fieldbackground [list \
		readonly SystemButtonFace \
	    	readonly SystemButtonFace \
		disabled SystemButtonFace] \
	    -foreground	[list \
		disabled		SystemGrayText \
		{readonly focus}	SystemHighlightText \
	    	{readonly focus}	SystemHighlightText \
	    ] \
	    -focusfill {{readonly focus} SystemHighlight}
	    -focusfill	[list {readonly focus} SystemHighlight] \
	    ;

	ttk::style element create ComboboxPopdownFrame.border from default
	ttk::style configure ComboboxPopdownFrame \
	    -borderwidth 1 -relief solid

	ttk::style configure TSpinbox -padding {1.5p 0 12p 0}
        ttk::style configure TSpinbox -padding {2 0 16 0}

	ttk::style configure TLabelframe -borderwidth 2 -relief groove

	ttk::style configure Toolbutton -relief flat -padding {6p 3p}
	ttk::style configure Toolbutton -relief flat -padding {8 4}
	ttk::style map Toolbutton -relief \
	    {disabled flat  selected sunken  pressed sunken  active raised}
	    {disabled flat selected sunken  pressed sunken  active raised}

	ttk::style configure TScale -groovewidth 3p
	ttk::style configure TScale -groovewidth 4

	ttk::style configure TNotebook -tabmargins {2 2 2 0}
	ttk::style configure TNotebook.Tab -padding {2.25p 0.75p} -borderwidth 1
	ttk::style map TNotebook.Tab -expand {selected {2 2 2 0}}
	ttk::style configure TNotebook.Tab -padding {3 1} -borderwidth 1
	ttk::style map TNotebook.Tab -expand [list selected {2 2 2 0}]

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont -relief raised
	ttk::style configure Item \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Treeview -background SystemWindow \
	ttk::style configure Treeview -background SystemWindow
	    -stripedbackground System3dLight -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style map Treeview \
	    -background [list   disabled SystemButtonFace \
				selected SystemHighlight] \
	    -background [list selected SystemHighlight] \
	    -foreground [list   disabled SystemGrayText \
				selected SystemHighlightText]
	    -foreground [list selected SystemHighlightText] ;

        ttk::style configure TProgressbar \
	    -background SystemHighlight -borderwidth 0 \
	    -background SystemHighlight -borderwidth 0 ;
	    -barsize 22.5p -thickness 11.25p
    }
}

Changes to library/ttk/xpTheme.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22











23
24
25









26
27
28
29
30
31
32
33
34



35
36
37
38
39
40

41
42
43
44




45
46
47
48


49
50
51
52
53
54


55
56
57
58
59
60
61
62
63
64
1
2
3
4
5
6
7
8
9
10
11
12
13









14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50

51
52



53
54
55
56
57
58


59
60

61




62
63








64
65













-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
+
+
+
+
+
+
+
+
+







-
-
+
+
+





-
+

-
-
-
+
+
+
+


-
-
+
+
-

-
-
-
-
+
+
-
-
-
-
-
-
-
-


#
# Settings for 'xpnative' theme
#

namespace eval ttk::theme::xpnative {

    ttk::style theme settings xpnative {

	ttk::style configure . \
	    -background SystemButtonFace \
	    -foreground SystemWindowText \
	    -selectforeground SystemHighlightText \
	    -selectbackground SystemHighlight \
	    -insertcolor SystemWindowText \
	    -font TkDefaultFont

	ttk::style map "." -foreground [list disabled SystemGrayText]

	ttk::style configure TButton -anchor center -padding 0.75p -width -11
	ttk::style configure TRadiobutton -padding 1.5p
	ttk::style configure TCheckbutton -padding 1.5p
	ttk::style configure TMenubutton -padding {6p 3p}
	    -font TkDefaultFont \
	    ;

	ttk::style map "." \
	    -foreground [list disabled SystemGrayText] \
	    ;

	ttk::style configure TButton -anchor center -padding {1 1} -width -11
	ttk::style configure TRadiobutton -padding 2
	ttk::style configure TCheckbutton -padding 2
	ttk::style configure TMenubutton -padding {8 4}

	ttk::style configure TNotebook -tabmargins {2 2 2 0}
	ttk::style map TNotebook.Tab -expand {selected {2 2 2 2}}
	ttk::style map TNotebook.Tab \
	    -expand [list selected {2 2 2 2}]

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont
	ttk::style configure Treeview -background SystemWindow
	ttk::style map Treeview \
	    -background [list selected SystemHighlight] \
	    -foreground [list selected SystemHighlightText] ;

	ttk::style configure TLabelframe.Label -foreground "#0046d5"

	# OR: -padding {3 3 3 6}, which some apps seem to use.
	ttk::style configure TEntry -padding {2 2 2 4}
	ttk::style map TEntry \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText]
	ttk::style configure TCombobox -padding 1.5p
	    -selectforeground [list !focus SystemWindowText] \
	    ;
	ttk::style configure TCombobox -padding 2
	ttk::style map TCombobox \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText] \
	    -foreground	[list \
		disabled		SystemGrayText \
		{readonly focus}	SystemHighlightText \
	    	{readonly focus}	SystemHighlightText \
	    ] \
	    -focusfill	[list {readonly focus} SystemHighlight]

	ttk::style configure TSpinbox -padding {1.5p 0 10.5p 0}
	    -focusfill	[list {readonly focus} SystemHighlight] \
	    ;

	ttk::style configure TSpinbox -padding {2 0 14 0}
	ttk::style map TSpinbox \
	    -selectbackground [list !focus SystemWindow] \
	    -selectforeground [list !focus SystemWindowText]

	    -selectforeground [list !focus SystemWindowText] \
	    ;
	ttk::style configure Toolbutton -padding 3p

	# Treeview:
	ttk::style configure Heading -font TkHeadingFont -relief raised
	ttk::style configure Item \
	    -indicatormargins {1.5p 1.5p 3p 1.5p}
	ttk::style configure Toolbutton -padding {4 4}

	ttk::style configure Treeview -background SystemWindow \
	    -stripedbackground System3dLight -indent 15p
	ttk::setTreeviewRowHeight
	ttk::style map Treeview \
	    -background [list   disabled SystemButtonFace \
				selected SystemHighlight] \
	    -foreground [list   disabled SystemGrayText \
				selected SystemHighlightText]
    }
}

Added library/unsupported.tcl.














































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# unsupported.tcl --
#
# Commands provided by Tk without official support.  Use them at your
# own risk.  They may change or go away without notice.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

# ----------------------------------------------------------------------
# Unsupported compatibility interface for folks accessing Tk's private
# commands and variable against recommended usage.
# ----------------------------------------------------------------------

namespace eval ::tk::unsupported {

    # Map from the old global names of Tk private commands to their
    # new namespace-encapsulated names.

    variable PrivateCommands
    array set PrivateCommands {
	tkButtonAutoInvoke		::tk::ButtonAutoInvoke
	tkButtonDown			::tk::ButtonDown
	tkButtonEnter			::tk::ButtonEnter
	tkButtonInvoke			::tk::ButtonInvoke
	tkButtonLeave			::tk::ButtonLeave
	tkButtonUp			::tk::ButtonUp
	tkCancelRepeat			::tk::CancelRepeat
	tkCheckRadioDown		::tk::CheckRadioDown
	tkCheckRadioEnter		::tk::CheckRadioEnter
	tkCheckRadioInvoke		::tk::CheckRadioInvoke
	tkColorDialog			::tk::dialog::color::
	tkColorDialog_BuildDialog	::tk::dialog::color::BuildDialog
	tkColorDialog_CancelCmd		::tk::dialog::color::CancelCmd
	tkColorDialog_Config		::tk::dialog::color::Config
	tkColorDialog_CreateSelector	::tk::dialog::color::CreateSelector
	tkColorDialog_DrawColorScale	::tk::dialog::color::DrawColorScale
	tkColorDialog_EnterColorBar	::tk::dialog::color::EnterColorBar
	tkColorDialog_InitValues	::tk::dialog::color::InitValues
	tkColorDialog_HandleRGBEntry	::tk::dialog::color::HandleRGBEntry
	tkColorDialog_HandleSelEntry	::tk::dialog::color::HandleSelEntry
	tkColorDialog_LeaveColorBar	::tk::dialog::color::LeaveColorBar
	tkColorDialog_MoveSelector	::tk::dialog::color::MoveSelector
	tkColorDialog_OkCmd		::tk::dialog::color::OkCmd
	tkColorDialog_RedrawColorBars	::tk::dialog::color::RedrawColorBars
	tkColorDialog_RedrawFinalColor	::tk::dialog::color::RedrawFinalColor
	tkColorDialog_ReleaseMouse	::tk::dialog::color::ReleaseMouse
	tkColorDialog_ResizeColorBars	::tk::dialog::color::ResizeColorBars
	tkColorDialog_RgbToX		::tk::dialog::color::RgbToX
	tkColorDialog_SetRGBValue	::tk::dialog::color::SetRGBValue
	tkColorDialog_StartMove		::tk::dialog::color::StartMove
	tkColorDialog_XToRgb		::tk::dialog::color::XToRGB
	tkConsoleAbout			::tk::ConsoleAbout
	tkConsoleBind			::tk::ConsoleBind
	tkConsoleExit			::tk::ConsoleExit
	tkConsoleHistory		::tk::ConsoleHistory
	tkConsoleInit			::tk::ConsoleInit
	tkConsoleInsert			::tk::ConsoleInsert
	tkConsoleInvoke			::tk::ConsoleInvoke
	tkConsoleOutput			::tk::ConsoleOutput
	tkConsolePrompt			::tk::ConsolePrompt
	tkConsoleSource			::tk::ConsoleSource
	tkDarken			::tk::Darken
	tkEntryAutoScan			::tk::EntryAutoScan
	tkEntryBackspace		::tk::EntryBackspace
	tkEntryButton1			::tk::EntryButton1
	tkEntryClosestGap		::tk::EntryClosestGap
	tkEntryGetSelection		::tk::EntryGetSelection
	tkEntryInsert			::tk::EntryInsert
	tkEntryKeySelect		::tk::EntryKeySelect
	tkEntryMouseSelect		::tk::EntryMouseSelect
	tkEntryNextWord			::tk::EntryNextWord
	tkEntryPaste			::tk::EntryPaste
	tkEntryPreviousWord		::tk::EntryPreviousWord
	tkEntrySeeInsert		::tk::EntrySeeInsert
	tkEntrySetCursor		::tk::EntrySetCursor
	tkEntryTranspose		::tk::EntryTranspose
	tkEventMotifBindings		::tk::EventMotifBindings
	tkFDGetFileTypes		::tk::FDGetFileTypes
	tkFirstMenu			::tk::FirstMenu
	tkFocusGroup_BindIn		::tk::FocusGroup_BindIn
	tkFocusGroup_BindOut		::tk::FocusGroup_BindOut
	tkFocusGroup_Create		::tk::FocusGroup_Create
	tkFocusGroup_Destroy		::tk::FocusGroup_Destroy
	tkFocusGroup_In			::tk::FocusGroup_In
	tkFocusGroup_Out		::tk::FocusGroup_Out
	tkFocusOK			::tk::FocusOK
	tkGenerateMenuSelect		::tk::GenerateMenuSelect
	tkIconList			::tk::IconList
	tkListbox			::tk::Listbox
	tkListboxAutoScan		::tk::ListboxAutoScan
	tkListboxBeginExtend		::tk::ListboxBeginExtend
	tkListboxBeginSelect		::tk::ListboxBeginSelect
	tkListboxBeginToggle		::tk::ListboxBeginToggle
	tkListboxCancel			::tk::ListboxCancel
	tkListboxDataExtend		::tk::ListboxDataExtend
	tkListboxExtendUpDown		::tk::ListboxExtendUpDown
	tkListboxKeyAccel_Goto		::tk::ListboxKeyAccel_Goto
	tkListboxKeyAccel_Key		::tk::ListboxKeyAccel_Key
	tkListboxKeyAccel_Reset		::tk::ListboxKeyAccel_Reset
	tkListboxKeyAccel_Set		::tk::ListboxKeyAccel_Set
	tkListboxKeyAccel_Unset		::tk::ListboxKeyAccel_Unxet
	tkListboxMotion			::tk::ListboxMotion
	tkListboxSelectAll		::tk::ListboxSelectAll
	tkListboxUpDown			::tk::ListboxUpDown
	tkListboxBeginToggle		::tk::ListboxBeginToggle
	tkMbButtonUp			::tk::MbButtonUp
	tkMbEnter			::tk::MbEnter
	tkMbLeave			::tk::MbLeave
	tkMbMotion			::tk::MbMotion
	tkMbPost			::tk::MbPost
	tkMenuButtonDown		::tk::MenuButtonDown
	tkMenuDownArrow			::tk::MenuDownArrow
	tkMenuDup			::tk::MenuDup
	tkMenuEscape			::tk::MenuEscape
	tkMenuFind			::tk::MenuFind
	tkMenuFindName			::tk::MenuFindName
	tkMenuFirstEntry		::tk::MenuFirstEntry
	tkMenuInvoke			::tk::MenuInvoke
	tkMenuLeave			::tk::MenuLeave
	tkMenuLeftArrow			::tk::MenuLeftArrow
	tkMenuMotion			::tk::MenuMotion
	tkMenuNextEntry			::tk::MenuNextEntry
	tkMenuNextMenu			::tk::MenuNextMenu
	tkMenuRightArrow		::tk::MenuRightArrow
	tkMenuUnpost			::tk::MenuUnpost
	tkMenuUpArrow			::tk::MenuUpArrow
	tkMessageBox			::tk::MessageBox
	tkMotifFDialog			::tk::MotifFDialog
	tkMotifFDialog_ActivateDList	::tk::MotifFDialog_ActivateDList
	tkMotifFDialog_ActivateFList	::tk::MotifFDialog_ActivateFList
	tkMotifFDialog_ActivateFEnt	::tk::MotifFDialog_ActivateFEnt
	tkMotifFDialog_ActivateSEnt	::tk::MotifFDialog_ActivateSEnt
	tkMotifFDialog			::tk::MotifFDialog
	tkMotifFDialog_BrowseDList	::tk::MotifFDialog_BrowseDList
	tkMotifFDialog_BrowseFList	::tk::MotifFDialog_BrowseFList
	tkMotifFDialog_BuildUI		::tk::MotifFDialog_BuildUI
	tkMotifFDialog_CancelCmd	::tk::MotifFDialog_CancelCmd
	tkMotifFDialog_Config		::tk::MotifFDialog_Config
	tkMotifFDialog_Create		::tk::MotifFDialog_Create
	tkMotifFDialog_FileTypes	::tk::MotifFDialog_FileTypes
	tkMotifFDialog_FilterCmd	::tk::MotifFDialog_FilterCmd
	tkMotifFDialog_InterpFilter	::tk::MotifFDialog_InterpFilter
	tkMotifFDialog_LoadFiles	::tk::MotifFDialog_LoadFiles
	tkMotifFDialog_MakeSList	::tk::MotifFDialog_MakeSList
	tkMotifFDialog_OkCmd		::tk::MotifFDialog_OkCmd
	tkMotifFDialog_SetFilter	::tk::MotifFDialog_SetFilter
	tkMotifFDialog_SetListMode	::tk::MotifFDialog_SetListMode
	tkMotifFDialog_Update		::tk::MotifFDialog_Update
	tkPostOverPoint			::tk::PostOverPoint
	tkRecolorTree			::tk::RecolorTree
	tkRestoreOldGrab		::tk::RestoreOldGrab
	tkSaveGrabInfo			::tk::SaveGrabInfo
	tkScaleActivate			::tk::ScaleActivate
	tkScaleButtonDown		::tk::ScaleButtonDown
	tkScaleButton2Down		::tk::ScaleButton2Down
	tkScaleControlPress		::tk::ScaleControlPress
	tkScaleDrag			::tk::ScaleDrag
	tkScaleEndDrag			::tk::ScaleEndDrag
	tkScaleIncrement		::tk::ScaleIncrement
	tkScreenChanged			::tk::ScreenChanged
	tkScrollButtonDown		::tk::ScrollButtonDown
	tkScrollButton2Down		::tk::ScrollButton2Down
	tkScrollButtonDrag		::tk::ScrollButtonDrag
	tkScrollButtonUp		::tk::ScrollButtonUp
	tkScrollByPages			::tk::ScrollByPages
	tkScrollByUnits			::tk::ScrollByUnits
	tkScrollEndDrag			::tk::ScrollEndDrag
	tkScrollSelect			::tk::ScrollSelect
	tkScrollStartDrag		::tk::ScrollStartDrag
	tkScrollTopBottom		::tk::ScrollTopBottom
	tkScrollToPos			::tk::ScrollToPos
	tkTabToWindow			::tk::TabToWindow
	tkTearOffMenu			::tk::TearOffMenu
	tkTextAutoScan			::tk::TextAutoScan
	tkTextButton1			::tk::TextButton1
	tkTextClosestGap		::tk::TextClosestGap
	tkTextInsert			::tk::TextInsert
	tkTextKeyExtend			::tk::TextKeyExtend
	tkTextKeySelect			::tk::TextKeySelect
	tkTextNextPara			::tk::TextNextPara
	tkTextNextPos			::tk::TextNextPos
	tkTextNextWord			::tk::TextNextWord
	tkTextPaste			::tk::TextPaste
	tkTextPrevPara			::tk::TextPrevPara
	tkTextPrevPos			::tk::TextPrevPos
	tkTextPrevWord			::tk::TextPrevWord
	tkTextResetAnchor		::tk::TextResetAnchor
	tkTextScrollPages		::tk::TextScrollPages
	tkTextSelectTo			::tk::TextSelectTo
	tkTextSetCursor			::tk::TextSetCursor
	tkTextTranspose			::tk::TextTranspose
	tkTextUpDownLine		::tk::TextUpDownLine
	tkTraverseToMenu		::tk::TraverseToMenu
	tkTraverseWithinMenu		::tk::TraverseWithinMenu
	unsupported1			::tk::unsupported::MacWindowStyle
    }

    # Map from the old global names of Tk private variable to their
    # new namespace-encapsulated names.

    variable PrivateVariables
    array set PrivateVariables {
	droped_to_start		::tk::mac::Droped_to_start
	histNum			::tk::HistNum
	stub_location		::tk::mac::Stub_location
	tkFocusIn		::tk::FocusIn
	tkFocusOut		::tk::FocusOut
	tkPalette		::tk::Palette
	tkPriv			::tk::Priv
	tkPrivMsgBox		::tk::PrivMsgBox
    }
}

# ::tk::unsupported::ExposePrivateCommand --
#
#	Expose one of Tk's private commands to be visible under its
#	old global name
#
# Arguments:
#	cmd	Global name by which the command was once known,
#               or a glob-style pattern.
#
# Results:
#	None.
#
# Side effects:
#	The old command name in the global namespace is aliased to the
#	new private name.

proc ::tk::unsupported::ExposePrivateCommand {cmd} {
    variable PrivateCommands
    set cmds [array get PrivateCommands $cmd]
    if {[llength $cmds] == 0} {
	return -code error -errorcode {TK EXPOSE_PRIVATE_COMMAND} \
	    "No compatibility support for \[$cmd]"
    }
    foreach {old new} $cmds {
	namespace eval :: [list interp alias {} $old {}] $new
    }
}

# ::tk::unsupported::ExposePrivateVariable --
#
#	Expose one of Tk's private variables to be visible under its
#	old global name
#
# Arguments:
#	var	Global name by which the variable was once known,
#               or a glob-style pattern.
#
# Results:
#	None.
#
# Side effects:
#	The old variable name in the global namespace is aliased to the
#	new private name.

proc ::tk::unsupported::ExposePrivateVariable {var} {
    variable PrivateVariables
    set vars [array get PrivateVariables $var]
    if {[llength $vars] == 0} {
	return -code error -errorcode {TK EXPOSE_PRIVATE_VARIABLE} \
	    "No compatibility support for \$$var"
    }
    namespace eval ::tk::mac {}
    foreach {old new} $vars {
	namespace eval :: [list upvar "#0" $new $old]
    }
}

Changes to library/xmfbox.tcl.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







# xmfbox.tcl --
#
#	Implements the "Motif" style file selection dialog for the
#	Unix platform. This implementation is used only if the
#	"::tk_strictMotif" flag is set.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Scriptics Corporation
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Scriptics Corporation
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

namespace eval ::tk::dialog {}
namespace eval ::tk::dialog::file {}

79
80
81
82
83
84
85
86

87
88

89
90
91
92
93
94
95
79
80
81
82
83
84
85

86
87

88
89
90
91
92
93
94
95







-
+

-
+








proc ::tk::MotifFDialog_Create {dataName type argList} {
    upvar ::tk::dialog::file::$dataName data

    MotifFDialog_Config $dataName $type $argList

    if {$data(-parent) eq "."} {
	set w .$dataName
        set w .$dataName
    } else {
	set w $data(-parent).$dataName
        set w $data(-parent).$dataName
    }

    # (re)create the dialog box if necessary
    #
    if {![winfo exists $w]} {
	MotifFDialog_BuildUI $w
    } elseif {[winfo class $w] ne "TkMotifFDialog"} {
340
341
342
343
344
345
346
347

348
349

350
351
352
353
354
355
356
357
358
359
360
361


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
340
341
342
343
344
345
346

347
348

349
350
351
352
353
354
355
356
357
358
359


360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375


376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401







-
+

-
+










-
-
+
+














-
-
+
+
















-
+







    pack $f1 -side top    -fill x
    pack $f3 -side bottom -fill x
    pack $f2 -expand yes -fill both

    set f2a [frame $f2.a]
    set f2b [frame $f2.b]

    grid $f2a -row 0 -column 0 -rowspan 1 -columnspan 1 -padx 3p -pady 3p \
    grid $f2a -row 0 -column 0 -rowspan 1 -columnspan 1 -padx 4 -pady 4 \
	-sticky news
    grid $f2b -row 0 -column 1 -rowspan 1 -columnspan 1 -padx 3p -pady 3p \
    grid $f2b -row 0 -column 1 -rowspan 1 -columnspan 1 -padx 4 -pady 4 \
	-sticky news
    grid rowconfigure $f2 0    -minsize 0   -weight 1
    grid columnconfigure $f2 0 -minsize 0   -weight 1
    grid columnconfigure $f2 1 -minsize 150 -weight 2

    # The Filter box
    #
    bind [::tk::AmpWidget label $f1.lab -text [mc "Fil&ter:"] -anchor w] \
	<<AltUnderlined>> [list focus $f1.ent]
    entry $f1.ent
    pack $f1.lab -side top -fill x -padx 4.5p -pady 3p
    pack $f1.ent -side top -fill x -padx 3p -pady 0
    pack $f1.lab -side top -fill x -padx 6 -pady 4
    pack $f1.ent -side top -fill x -padx 4 -pady 0
    set data(fEnt) $f1.ent

    # The file and directory lists
    #
    set data(dList) [MotifFDialog_MakeSList $w $f2a \
	    [mc "&Directory:"] DList]
    set data(fList) [MotifFDialog_MakeSList $w $f2b \
	    [mc "Fi&les:"]     FList]

    # The Selection box
    #
    bind [::tk::AmpWidget label $f3.lab -text [mc "&Selection:"] -anchor w] \
	<<AltUnderlined>> [list focus $f3.ent]
    entry $f3.ent
    pack $f3.lab -side top -fill x -padx 4.5p -pady 0
    pack $f3.ent -side top -fill x -padx 3p -pady 3p
    pack $f3.lab -side top -fill x -padx 6 -pady 0
    pack $f3.ent -side top -fill x -padx 4 -pady 4
    set data(sEnt) $f3.ent

    # The buttons
    #
    set maxWidth [::tk::mcmaxamp &OK &Filter &Cancel]
    set maxWidth [expr {$maxWidth<6?6:$maxWidth}]
    set data(okBtn) [::tk::AmpWidget button $bot.ok -text [mc "&OK"] \
	    -width $maxWidth \
	    -command [list tk::MotifFDialog_OkCmd $w]]
    set data(filterBtn) [::tk::AmpWidget button $bot.filter -text [mc "&Filter"] \
	    -width $maxWidth \
	    -command [list tk::MotifFDialog_FilterCmd $w]]
    set data(cancelBtn) [::tk::AmpWidget button $bot.cancel -text [mc "&Cancel"] \
	    -width $maxWidth \
	    -command [list tk::MotifFDialog_CancelCmd $w]]

    pack $bot.ok $bot.filter $bot.cancel -padx 7.5p -pady 7.5p -expand yes \
    pack $bot.ok $bot.filter $bot.cancel -padx 10 -pady 10 -expand yes \
	-side left

    # Create the bindings:
    #
    bind $w <Alt-Key> [list ::tk::AltKeyInDialog $w %A]

    bind $data(fEnt) <Return> [list tk::MotifFDialog_ActivateFEnt $w]
437
438
439
440
441
442
443
444

445
446
447
448
449
450
451
437
438
439
440
441
442
443

444
445
446
447
448
449
450
451







-
+







    bind [::tk::AmpWidget label $f.lab -text $label -anchor w] \
	<<AltUnderlined>> [list focus $f.l]
    listbox $f.l -width 12 -height 5 -exportselection 0\
	-xscrollcommand [list $f.h set]	-yscrollcommand [list $f.v set]
    scrollbar $f.v -orient vertical   -takefocus 0 -command [list $f.l yview]
    scrollbar $f.h -orient horizontal -takefocus 0 -command [list $f.l xview]
    grid $f.lab -row 0 -column 0 -sticky news -rowspan 1 -columnspan 2 \
	-padx 1.5p -pady 1.5p
	-padx 2 -pady 2
    grid $f.l -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
    grid $f.v -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
    grid $f.h -row 2 -column 0 -rowspan 1 -columnspan 1 -sticky news

    grid rowconfigure    $f 0 -weight 0 -minsize 0
    grid rowconfigure    $f 1 -weight 1 -minsize 0
    grid columnconfigure $f 0 -weight 1 -minsize 0
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
544
545
546
547
548
549
550

551
552
553
554
555
556
557
558







-
+







#	None.

proc ::tk::MotifFDialog_Update {w} {
    upvar ::tk::dialog::file::[winfo name $w] data

    $data(fEnt) delete 0 end
    $data(fEnt) insert 0 \
	    [::tk::dialog::file::JoinFile $data(selectPath) $data(filter)]
            [::tk::dialog::file::JoinFile $data(selectPath) $data(filter)]
    $data(sEnt) delete 0 end
    $data(sEnt) insert 0 [::tk::dialog::file::JoinFile $data(selectPath) \
	    $data(selectFile)]

    MotifFDialog_LoadFiles $w
}

592
593
594
595
596
597
598
599
600


601
602
603
604
605

606
607

608
609
610
611
612
613
614
592
593
594
595
596
597
598


599
600
601
602
603
604

605
606

607
608
609
610
611
612
613
614







-
-
+
+




-
+

-
+







    set top 0
    set dlist ""
    set flist ""
    foreach f [glob -nocomplain .* *] {
	if {[file isdir ./$f]} {
	    lappend dlist $f
	} else {
	    foreach pat $data(filter) {
		if {[string match $pat $f]} {
            foreach pat $data(filter) {
                if {[string match $pat $f]} {
		    if {[string match .* $f]} {
			incr top
		    }
		    lappend flist $f
		    break
                    break
		}
	    }
            }
	}
    }
    eval [list $data(dList) insert end] [lsort -dictionary $dlist]
    eval [list $data(fList) insert end] [lsort -dictionary $flist]

    # The user probably doesn't want to see the . files. We adjust the view
    # so that the listbox displays all the non-dot files
902
903
904
905
906
907
908
909

910
911

912
913
914
915
916
917
918
902
903
904
905
906
907
908

909
910

911
912
913
914
915
916
917
918







-
+

-
+








    set Priv(selectFilePath) ""
    set Priv(selectFile)     ""
    set Priv(selectPath)     ""
}

proc ::tk::ListBoxKeyAccel_Set {w} {
    bind Listbox <Key> ""
    bind Listbox <Any-KeyPress> ""
    bind $w <Destroy> [list tk::ListBoxKeyAccel_Unset $w]
    bind $w <Key> [list tk::ListBoxKeyAccel_Key $w %A]
    bind $w <Any-KeyPress> [list tk::ListBoxKeyAccel_Key $w %A]
}

proc ::tk::ListBoxKeyAccel_Unset {w} {
    variable ::tk::Priv

    catch {after cancel $Priv(lbAccel,$w,afterId)}
    unset -nocomplain Priv(lbAccel,$w) Priv(lbAccel,$w,afterId)

Deleted macosx/Credits.html.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
<!doctype htmL>
<html>
<head>
</head>
<body style="font-size:120%;font-family:Arial,sans-serif;">
<p>
Tcl and Tk are distributed under a modified BSD license:<br>
<a href="https://www.tcl-lang.org/software/tcltk/license.html">
  https://www.tcl-lang.org/software/tcltk/license.html
</a>
</p>
<ul style="list-style-type:none;">
<li>&copy; 1987-@TK_YEAR@ Tcl Core Team and Contributers.</li>
<li>&copy; 2011-@TK_YEAR@ Kevin Walzer/WordTech Communications LLC.</li>
<li>&copy; 2014-@TK_YEAR@ Marc Culler.</li>
<li>&copy; 2002-2012 Daniel A. Steffen.</li>
<li>&copy; 2001-2009 Apple Inc.</li>
<li>&copy; 2001-2002 Jim Ingham &amp; Ian Reid.</li>
<li>&copy; 1998-2000 Jim Ingham &amp; Ray Johnson.</li>
<li>&copy; 1998-2000 Scriptics Inc.</li>
<li>&copy; 1996-1997 Sun Microsystems Inc.</li>
</ul>
</body>
</html>

Changes to macosx/GNUmakefile.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45






46
47
48
49
50
51
52







-


















-
-
-
-
-
-







SYMROOT			?= ${BUILD_DIR}/${PROJECT}
OBJROOT			?= ${SYMROOT}

EXTRA_CONFIGURE_ARGS	?=
EXTRA_MAKE_ARGS		?=

INSTALL_PATH		?= /Library/Frameworks
TCL_INSTALL_PATH	?= ${INSTALL_PATH}/Tcl.framework
APPLICATION_INSTALL_PATH ?= /Applications/Utilities
PREFIX			?= /usr/local
BINDIR			?= ${PREFIX}/bin
LIBDIR			?= ${INSTALL_PATH}
MANDIR			?= ${PREFIX}/man

# tcl build directory (containing tclConfig.sh and Makefile)
TCL_BUILD_DIR		?= ${BUILD_DIR}/tcl/${BUILD_STYLE}
# location of installed tcl, only used if tcl in TCL_BUILD_DIR can't be found
TCL_FRAMEWORK_DIR	?= /Library/Frameworks
TCLSH_DIR		?= ${PREFIX}/bin

# set to non-empty value to install manpages in addition to html help:
INSTALL_MANPAGES	?=

# set to non-empty value to build TkX11 instead of TkAqua:
TK_X11			?=

# Checks and overrides for subframework builds
ifeq (${SUBFRAMEWORK}_${TK_X11},1_)
override BUILD_DIR = ${DESTDIR}/build
override INSTALL_PATH = /Frameworks
endif

#-------------------------------------------------------------------------------------------------------
# meta targets

meta			:= all install embedded install-embedded clean distclean test

styles			:= develop deploy

110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144

145
146
147
148
149
150
151
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136

137
138
139
140
141
142
143
144







-
+







-
+
















-
+

-
+








UNIX_DIR		:= ${CURDIR}/../unix
VERSION			:= $(shell awk -F= '/^TK_VERSION/ {print $$2; nextfile}' ${UNIX_DIR}/configure.ac)
TCL_VERSION		:= ${VERSION}
wish			:= wish
WISH			= wish${VERSION}

BUILD_TARGET		:= binaries libraries tktest
BUILD_TARGET		:= all tktest
INSTALL_TARGET		:= install

ifneq ($(wildcard $(subst ${space},\ ,${TCL_BUILD_DIR})/tclConfig.sh),)
TCL_DIR			:= ${TCL_BUILD_DIR}
TCL_FRAMEWORK_DIR	:= ${TCL_BUILD_DIR}/..
MAKE_VARS		:=
else
TCL_DIR			:= ${TCL_INSTALL_PATH}
TCL_DIR			:= ${TCL_FRAMEWORK_DIR}/Tcl.framework
TCL_EXE			:= ${TCLSH_DIR}/tclsh${TCL_VERSION}
MAKE_VARS		:= TCL_EXE
export DYLD_FRAMEWORK_PATH := ${TCL_FRAMEWORK_DIR}
endif

export CPPROG		:= cp -p

ifeq (${TK_X11},)
override CONFIGURE_ARGS := ${CONFIGURE_ARGS} --enable-aqua
else
override CONFIGURE_ARGS := ${CONFIGURE_ARGS} --enable-xft
VERSION			:= ${VERSION}-X11
wish			:= ${wish}-X11
override EMBEDDED_BUILD :=
endif

INSTALL_TARGETS		= install-binaries install-libraries install-headers
INSTALL_TARGETS		= install-binaries install-libraries
ifeq (${EMBEDDED_BUILD},)
INSTALL_TARGETS		+= install-private-headers install-demos
INSTALL_TARGETS		+= install-private-headers install-headers install-demos
endif
ifeq (${INSTALL_BUILD}_${EMBEDDED_BUILD}_${BUILD_STYLE},1__Deployment)
INSTALL_TARGETS		+= html-tk
ifneq (${INSTALL_MANPAGES},)
INSTALL_TARGETS		+= install-doc
endif
endif
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190







-
+







	${MAKE} install-${PROJECT} INSTALL_ROOT="${OBJ_DIR}/"

${objdir}/Makefile: ${UNIX_DIR}/Makefile.in ${UNIX_DIR}/configure \
		     ${UNIX_DIR}/tkConfig.sh.in Tk-Info.plist.in Wish-Info.plist.in
	mkdir -p "${OBJ_DIR}" && cd "${OBJ_DIR}" && \
	if [ ${UNIX_DIR}/configure -nt config.status ]; then ${UNIX_DIR}/configure -C \
	--prefix="${PREFIX}" --bindir="${BINDIR}" --libdir="${LIBDIR}" \
	--mandir="${MANDIR}" --enable-framework --disable-zipfs \
	--mandir="${MANDIR}" --enable-threads --enable-framework \
	--with-tcl="${TCL_DIR}" \
	${CONFIGURE_ARGS} ${EXTRA_CONFIGURE_ARGS}; else ./config.status; fi
ifneq (${VERSION},${TCL_VERSION})
	@cd "${OBJ_DIR}" && sed -e 's#/Versions/${TCL_VERSION}#/Versions/${VERSION}#' \
	tkConfig.sh > tkConfig.sh.1 && mv -f tkConfig.sh.1 tkConfig.sh
endif

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
















241
242
243
244


245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
206
207
208
209
210
211
212



213
214
215



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245


246
247
248
249
250
251
252
253
254

255
256

257
258
259
260
261
262
263







-
-
-



-
-
-












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+







-
+

-







	rm -f Tcl.framework && ln -s "${TCL_FRAMEWORK_DIR}/Tcl.framework" . ; fi
endif

install-${PROJECT}: build-${PROJECT}
ifeq (${EMBEDDED_BUILD}_${INSTALL_ROOT},1_)
	@echo "Cannot install-embedded with empty INSTALL_ROOT !" && false
endif
ifeq (${SUBFRAMEWORK}_${DYLIB_INSTALL_DIR},1_)
	@echo "Cannot install subframework with empty DYLIB_INSTALL_DIR !" && false
endif
ifeq (${EMBEDDED_BUILD},1)
	@rm -rf "${INSTALL_ROOT}/${LIBDIR}/Tk.framework"
endif
ifeq (${SUBFRAMEWORK},1)
	@rm -rf "${INSTALL_ROOT}/Frameworks/Tk.framework"
endif
	${DO_MAKE}
ifeq (${EMBEDDED_BUILD}_${TK_X11},1_)
# workaround bug with 'cp -pRH' on Darwin 6 and earlier
	@if [ "`uname -r | awk -F. '{print $$1}'`" -lt 7 ]; then \
	mkdir -p "${TOP_DIR}"/{"${TCL_FMWK_DIR}","${TK_FMWK_DIR}"}/PrivateHeaders; fi
endif
ifeq (${INSTALL_BUILD},1)
ifeq (${EMBEDDED_BUILD},1)
# if we are embedding frameworks, don't install wish
	@rm -f "${INSTALL_ROOT}${BINDIR}/${WISH}" && \
	rmdir -p "${INSTALL_ROOT}${BINDIR}" 2>&- || true
else
# redo prebinding (when not building for Mac OS X 10.4 or later only)
	@if [ "`echo "$${MACOSX_DEPLOYMENT_TARGET}" | \
	awk -F '10\\.' '{print int($$2)}'`" -lt 4 -a "`echo "$${CFLAGS}" | \
	awk -F '-mmacosx-version-min=10\\.' '{print int($$2)}'`" -lt 4 ]; \
	then cd ${INSTALL_ROOT}/; \
	if [ ! -d usr/lib ]; then mkdir -p usr && ln -fs /usr/lib usr/ && RM_USRLIB=1; fi; \
	if [ -n "${TK_X11}" -a ! -d usr/X11R6 ]; then mkdir -p usr && ln -fs /usr/X11R6 usr/ && RM_USRX11=1; fi; \
	if [ ! -d System ]; then ln -fs /System . && RM_SYSTEM=1; fi; \
	if [ ! -d "./${LIBDIR}/Tcl.framework" ]; then ln -fs "${TCL_FRAMEWORK_DIR}/Tcl.framework" "./${LIBDIR}"; RM_TCL=1; fi; \
	redo_prebinding -r . "./${TK_FMWK_DIR}/${PRODUCT_NAME}"; \
	if [ -z "${TK_X11}" ]; then redo_prebinding -r . "./${TK_FMWK_DIR}/Resources/Wish.app/Contents/MacOS/Wish"; \
	else redo_prebinding -r . "./${BINDIR}/${WISH}"; fi; \
	if [ -n "$${RM_USRLIB:-}" ]; then rm -f usr/lib; rmdir -p usr 2>&-; fi; \
	if [ -n "$${RM_USRX11:-}" ]; then rm -f usr/X11R6; rmdir -p usr 2>&-; fi; \
	if [ -n "$${RM_SYSTEM:-}" ]; then rm -f System; fi; \
	if [ -n "$${RM_TCL:-}" ]; then rm -f "./${LIBDIR}/Tcl.framework"; fi; fi
# install wish symbolic link
	@ln -fs ${WISH} "${INSTALL_ROOT}${BINDIR}/${wish}"
endif # embedded
endif # install
endif
endif
ifeq (${BUILD_STYLE}_${EMBEDDED_BUILD},Development_)
# keep copy of debug library around, so that
# Deployment build can be installed on top
# of Development build without overwriting
# the debug library
	@cd "${INSTALL_ROOT}${LIBDIR}/${PRODUCT_NAME}.framework/Versions/${VERSION}" && \
	ln -f "${PRODUCT_NAME}" "${PRODUCT_NAME}_debug"
endif # Development, not embedded
endif
ifeq (${TK_X11},)
ifeq (${SUBFRAMEWORK},)
ifeq (${EMBEDDED_BUILD},)
# install Wish.app link in APPLICATION_INSTALL_PATH and setup 'Wish Shell' compatibility links
	@cd "${TOP_DIR}" && if [ -n "${APP_DIR}" ]; then mkdir -p "./${APP_DIR}" && rm -rf "./${APP_DIR}/Wish.app" && \
	ln -fsh "./$$(echo "${APP_DIR}" | sed -e 's#/[^/][^/]*#/..#g')/${FMWK_DIR}/${PRODUCT_NAME}.framework/Resources/Wish.app" "./${APP_DIR}" && \
	ln -fsh Wish.app "./${APP_DIR}/Wish Shell.app"; fi && \
	ln -fsh Wish.app "./${TK_FMWK_DIR}/Resources/Wish Shell.app" && \
	ln -fsh Wish "./${TK_FMWK_DIR}/Resources/Wish.app/Contents/MacOS/Wish Shell"
281
282
283
284
285
286
287
288
289
290
291



292
293
294
295
296
297
298
283
284
285
286
287
288
289




290
291
292
293
294
295
296
297
298
299







-
-
-
-
+
+
+







	    install_name_tool -change $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {print \$$1; sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
	    chmod -RH a-w "$$1"; \
	} && \
	fix_install_id Frameworks/Tcl.framework/Tcl Tcl && fix_install_id Frameworks/Tk.framework/Tk Tk && \
	fix_install_name MacOS/Wish Tcl && fix_install_name MacOS/Wish Tk
ifeq (${INSTALL_BUILD},1)
	@cd "${TOP_DIR}" && rm -rf "./${FMWK_DIR}"/T{cl,k}.framework && rmdir -p "./${FMWK_DIR}" 2>&- || true
endif # install not subframework
endif # embedded
endif # not subframework
endif # not X11
endif
endif
endif

clean-${PROJECT}: %-${PROJECT}:
	${DO_MAKE}
	rm -rf "${SYMROOT}"/{${PRODUCT_NAME}.framework,${WISH},tktest}
	rm -f "${OBJ_DIR}"{"${LIBDIR}","${BINDIR}"} && \
	rmdir -p "${OBJ_DIR}"$(dir $(subst ${space},\ ,${LIBDIR})) 2>&- || true && \
	rmdir -p "${OBJ_DIR}"$(dir $(subst ${space},\ ,${BINDIR})) 2>&- || true

Changes to macosx/README.

1

2
3
4

5
6
7
8
9
10

11
12
13
14
15
16
17
18
19



20
21
22


23
24

25
26
27
28
29




30
31
32
33


34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


54
55
56
57
58






59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81






















82
83
84
85
86
87
88

1
2
3

4
5
6
7
8
9

10
11
12
13
14
15
16
17


18
19
20
21


22
23
24

25
26
27



28
29
30
31
32
33


34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-
+


-
+





-
+







-
-
+
+
+

-
-
+
+

-
+


-
-
-
+
+
+
+


-
-
+
+

-
+
















-
-
+
+





+
+
+
+
+
+









-
+













+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







Tcl/Tk macOS README
Tcl/Tk Mac OS X README
----------------------

This is the README file for the macOS/Darwin version of Tcl/Tk.
This is the README file for the Mac OS X/Darwin version of Tcl/Tk.

1. Where to go for support
--------------------------

- The tcl-mac mailing list on sourceforge is the best place to ask questions
specific to Tcl & Tk on macOS:
specific to Tcl & Tk on Mac OS X:
	http://lists.sourceforge.net/lists/listinfo/tcl-mac
(this page also has a link to searchable archives of the list, please check them
before asking on the list, many questions have already been answered).

- For general Tcl/Tk questions, the newsgroup comp.lang.tcl is your best bet:
	http://groups.google.com/group/comp.lang.tcl/

- The Tcl'ers Wiki also has many pages dealing with Tcl & Tk on macOS, see
	https://wiki.tcl-lang.org/page/MacOS
- The Tcl'ers Wiki also has many pages dealing with Tcl & Tk on Mac OS X, see
	http://wiki.tcl.tk/_/ref?N=3753
	http://wiki.tcl.tk/_/ref?N=8361

- Please report bugs with Tk on macOS to the tracker:
	https://core.tcl-lang.org/tk/reportlist
- Please report bugs with Tk on Mac OS X to the tracker:
	http://core.tcl.tk/tk/reportlist

2. Using Tcl/Tk on macOS
2. Using Tcl/Tk on Mac OS X
---------------------------

- There are two versions of Tk available on macOS: TkAqua using the native
aqua widgets and look&feel, and TkX11 using the traditional unix X11 widgets.
TkX11 requires an X11 server to be installed, such as XQuartz (available from www.xquartz.org).
- There are two versions of Tk available on Mac OS X: TkAqua using the native
aqua widgets and look&feel, and TkX11 using the traditional unix X11 wigets.
TkX11 requires an X11 server to be installed, such as Apple's X11 (which is
available as an optional or default install on recent Mac OS X).
TkAqua and TkX11 can be distinguished at runtime via [tk windowingsystem].

- At a minimum, macOS 10.3 is required to run Tcl and TkX11.
TkAqua requires macOS 10.6 or later.
- At a minimum, Mac OS X 10.3 is required to run Tcl and TkX11.
TkAqua requires Mac OS X 10.5 or later (starting with the Cocoa-based Tk 8.5.7).

- Unless weak-linking is used, Tcl/Tk built on macOS 10.x will not run on
- Unless weak-linking is used, Tcl/Tk built on Mac OS X 10.x will not run on
10.y with y < x; on the other hand Tcl/Tk built on 10.y will always run on 10.x
with y <= x (but without any of the fixes and optimizations that would be
available in a binary built on 10.x).
Weak-linking is available on OS X 10.2 or later, it additionally allows Tcl/Tk
built on 10.x to run on any 10.y with x > y >= z (for a chosen z >= 2).

- Wish checks the Resources/Scripts directory in its application bundle for a
file called AppMain.tcl, if found it is used as the startup script and the
Scripts folder is added to the auto_path. This can be used to emulate the old
OS9 TclTk droplets.

- If standard input is a special file of zero length (e.g. /dev/null), Wish
brings up the Tk console window at startup. This is the case when double
clicking Wish in the Finder (or using 'open Wish.app' from the Terminal).

- Tcl extensions can be installed in any of:
	$HOME/Library/Tcl /Library/Tcl
	$HOME/Library/Frameworks /Library/Frameworks
	$HOME/Library/Tcl /Library/Tcl /System/Library/Tcl
	$HOME/Library/Frameworks /Library/Frameworks /System/Library/Frameworks
	(searched in that order).
Given a potential package directory $pkg, Tcl on OSX checks for the file
$pkg/Resources/Scripts/pkgIndex.tcl as well as the usual $pkg/pkgIndex.tcl.
This allows building extensions as frameworks with all script files contained in
the Resources/Scripts directory of the framework.

- [load]able binary extensions can linked as either ordinary shared libraries
(.dylib) or as MachO bundles (since 8.4.10/8.5a3); bundles have the advantage
that they are [load]ed more efficiently from a tcl VFS (no temporary copy to the
native filesystem required), and prior to Mac OS X 10.5, only bundles can be
[unload]ed.

- The 'deploy' target of macosx/GNUmakefile installs the html manpages into the
standard documentation location in the Tcl/Tk frameworks:
	Tcl.framework/Resources/Documentation/Reference/Tcl
	Tk.framework/Resources/Documentation/Reference/Tk
No nroff manpages are installed by default by the GNUmakefile.

- The Tcl and Tk frameworks can be installed in any of the system's standard
framework directories:
	$HOME/Library/Frameworks /Library/Frameworks
	$HOME/Library/Frameworks /Library/Frameworks /System/Library/Frameworks

- ${prefix}/bin/wish8.x is a script that calls a copy of 'Wish' contained in
	Tk.framework/Resources

- if 'Wish' is started from the Finder or via 'open', $argv may contain a
"-psn_XXXX" argument. This is the process serial number, you may need to filter
it out for cross platform compatibility of your scripts.

- the env array is different when Wish is started from the Finder (i.e. via
LaunchServices) than when it (or tclsh) is invoked from the Terminal, in
particular PATH may not be what you expect. (Wish started by LaunchServices
inherits loginwindow's environment variables, which are essentially those set in
$HOME/.MacOSX/environment.plist, and are unrelated to those set in your shell).

- TkAqua drawing is antialiased by default, but (outline) linewidth can be used
to control whether a line/shape is drawn antialiased. The antialiasing threshold
is 0 by default (i.e. antialias everything), it can be changed by setting
	set tk::mac::CGAntialiasLimit <limit>
in your script before drawing, in which case lines (or shapes with outlines)
thinner than <limit> pixels will not be antialiased.

- Text antialiasing by default uses the standard OS antialising settings.
Setting the global variable '::tk::mac::antialiasedtext' allows to control text
antialiasing from Tcl: a value of 1 enables AA, 0 disables AA and -1 restores
the default behaviour of respecting the OS settings.

- Scrollbars: There are two scrollbar variants in Aqua, normal & small. The
normal scrollbar has a small dimension of 15, the small variant 11.
Access to the small variant was added in Tk 8.4.2.

- The default metrics of native buttons, radiobuttons, checkboxes and
menubuttons in the Cocoa-based Tk 8.5.7 and later preserve compatibility with
the older Carbon-based implementation, you can turn off the compatibility
metrics to get more native-looking spacing by setting:
	set tk::mac::useCompatibilityMetrics 0

- TkAqua provides access to native OS X images via the Tk native bitmap facility
(including any image file readable by NSImage). A native bitmap name is
interpreted as follows (in order):
    - predefined builtin 32x32 icon name (stop, caution, document, etc)
    - name defined by [tk::mac::iconBitmap]
    - NSImage named image name
119
120
121
122
123
124
125
126
127
128
129
130
131
132








133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151



152
153
154
155
156




157

158
159



160
161
162
163
164
165
166
167
168
169





170
171
172
173















174
175
176


177
178
179


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312

313
314

315
316




317
318


319
320

321
322
323
324
325

326
327
328
329
330

331
332


333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348

349
350
351


352
353
354
355
356
357
358
359
360

361
362
363
364

365
366
367











368
369
370
371

372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389

390
391



392
393
394

395
396
397
398
399
400
401
149
150
151
152
153
154
155







156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185




186
187
188
189
190
191


192
193
194


195







196
197
198
199
200



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217


218
219



220
221
222
223
224
225
226
227


228




























































































































229
230
231
232


233
234
235
236


237
238
239

240
241
242
243
244

245
246
247
248
249

250


251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285
286
287

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

324
325

326
327
328
329
330

331
332
333
334
335
336
337
338







-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
+















-
+
+
+

-
-
-
-
+
+
+
+

+
-
-
+
+
+
-
-

-
-
-
-
-
-
-
+
+
+
+
+
-
-
-

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
-
-
-
+
+






-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


+
-
-
+
+
+
+
-
-
+
+

-
+




-
+




-
+
-
-
+
+















+

+



+
+








-
+



-
+



+
+
+
+
+
+
+
+
+
+
+



-
+

-
+















-
+

-
+
+
+


-
+







application bundle files (i.e. standard about panel with no options specified).
See Apple Technote TN2179 and the AppKit documentation for -[NSApplication
orderFrontStandardAboutPanelWithOptions:] for details on the Info.plist keys and
app bundle files used by the about panel.
This support was added with the Cocoa-based Tk 8.5.7.

- TkAqua has three special menu names that give access to the standard
Application, Window and Help menus, see menu.n for details.  By default, the
platform-specific standard Help menu item "YourApp Help" performs the default
Cocoa action of showing the Help Book configured in the application's
Info.plist (or displaying an alert if no Help Book is set). This action can be
customized by defining a procedure named [tk::mac::ShowHelp]. If present, this
procedure is invoked instead by the standard Help menu item.  Support for the
Window menu and [tk::mac::ShowHelp] was added with the Cocoa-based Tk 8.5.7.
Application, Window and Help menus, see menu.n for details.
By default, the platform-specific standard Help menu item "YourApp Help" peforms
the default Cocoa action of showing the Help Book configured in the
application's Info.plist (or displaying an alert if no Help Book is set). This
action can be customized by defining a procedure named [tk::mac::ShowHelp], if
present, this procedure is invoked instead by the standard Help menu item.
Support for the Window menu and [tk::mac::ShowHelp] was added with the
Cocoa-based Tk 8.5.7.

- The TkAqua-specific command [tk::unsupported::MacWindowStyle style] is used to
get and set macOS-specific toplevel window class and attributes. Note that
get and set Mac OS X-specific toplevel window class and attributes. Note that
the window class and many attributes have to be set before the window is first
mapped for the change to have any effect.
The command has the following syntax:
	tk::unsupported::MacWindowStyle style window ?class? ?attributes?
The 2 argument form returns a list of the current class and attributes for the
given window. The 3 argument form sets the class for the given window using the
default attributes for that class. The 4 argument form sets the class and the
list of attributes for the given window.
Window class names:
    document, modal, floating, utility, toolbar, simple, help, overlay
Window attribute names:
    standardDocument, standardFloating, resizable, fullZoom, horizontalZoom,
    verticalZoom, closeBox, collapseBox, toolbarButton, sideTitlebar,
    noTitleBar, unifiedTitleAndToolbar, metal, hud, noShadow, doesNotCycle,
    noActivates, hideOnSuspend, inWindowMenu, ignoreClicks, doesNotHide,
    canJoinAllSpaces, moveToActiveSpace, nonActivating
    canJoinAllSpaces, moveToActiveSpace, nonActivating, black, dark, light,
    gray, red, green, blue, cyan, yellow, magenta, orange, purple,
    brown, clear, opacity

Note that not all attributes are valid for all window classes.  Support for the
3 argument form was added with the Cocoa-based Tk 8.5.7, at the same time
support for some legacy Carbon-specific classes and attributes was removed
(they are still accepted by the command but no longer have any effect).
Note that not all attributes are valid for all window classes.
Support for the 3 argument form was added with the Cocoa-based Tk 8.5.7, at the
same time support for some legacy Carbon-specific classes and attributes was
removed (they are still accepted by the command but no longer have any effect).

The color window attributes (black, dark, red, etc.) and the "opacity" allow  one to set the background and opacity of a textured ("metal") window. This allows a Tk window to implement a window without the dividing line between the titlebar and the rest of the window, or the "unified toolbar" effect, which is increasingly standard in Mac applications. An example:
- Another command available in the tk::unsupported::MacWindowStyle namespace is:
  tk::unsupported::MacWindowStyle tabbingid window ?newId?

toplevel .f
tk::unsupported::MacWindowStyle style .f document {metal light opaque closeBox collapseBox resizable standardDocument }
which can be used to get or set the tabbingIdentifier for the NSWindow
associated with a Tk Window.  See section 3 for details.

- The command:
  tk::unsupported::MacWindowStyle appearance window ?newAppearance?
is available when Tk is built and run on macOS 10.14 (Mojave) or later.  In
that case the Ttk widgets all support the "Dark Mode" appearance which was
introduced in 10.14. The command accepts the following values for the optional
newAppearance option: "aqua", "darkaqua", or "auto".  If the appearance is set
to aqua or darkaqua then the window will be displayed with the corresponding
pack [label .f.f -bg  #ababab -text "This is a textured window\nwith opacity and a gray background\nsimilar to other Mac applications"] -fill both -expand yes

The color attributes correspond to system-defined NSColor constants (e.g., red is [NSColor redColor]. The "light" and "dark" attributes correspond to lightGrayColor and darkGrayColor, respectively (because of the way the attributes are parsed, using "lightgray" and "darkgray" would cause a conflict with the core "gray" attribute).

Below are the corresponding hex and/or Tk-defined colors that can be used from Tk widgets to match the NSColor-based attributes:
appearance independent of any preferences settings.  If it is set to "auto"
the appearance will be determined by the preferences.  This command can be
used to opt out of Dark Mode on a per-window basis.  It may be best to run the "update" command before setting the appearance property, to allow the event loop to run.

black	#000000
dark	#545454
light	#ababab
white	#ffffff
gray	#7f7f7f
red 	#ff0000
green	#00ff00
blue	#0000ff
cyan	#00ffff
yellow	#ffff00
magenta	#ff00ff
orange	#ff8000
purple 	#800080
brown	#996633
clear	systemTransparent

- To determine the current appearance of a window in macOS 10.14 (Mojave) and
higher, one can use the command:
- The Cocoa-based TkAqua can be distinguished from the older Carbon-based
version via the [winfo server .] command, example output on Mac OS X 10.5.7:
  tk::unsupported::MacWindowStyle isdark
The boolean return value is true if the window is currently displayed with the
dark appearance.
    Cocoa-based:	CG409.3 Apple AppKit GC 949.46 Mac OS X 1057
    Carbon-based:	QD10R30 Apple 1057

- If you want to use Remote Debugging with Xcode, you need to set the
environment variable XCNOSTDIN to 1 in the Executable editor for Wish. That will
cause us to force closing stdin & stdout.  Otherwise, given how Xcode launches
Wish remotely, they will be left open and then Wish & gdb will fight for stdin.

3. FullScreen, Split View and Tabbed Windows
--------------------------------------------

Since the release of OSX 10.6 (Snow Leopard) a steadily expanding sequence of
high level window operations have been added to Apple's window manager.  These
operations are launched by user actions which are handled directly by the
window manager; they are not initiated by the application.  In some, but not
all cases, the application is notified before and after the operations are
carried out.

In OSX releases up to and including 10.6 there were three buttons with
stoplight colors located on the left side of a window's title bar.  The
function of the green button was to "zoom" or "maximize" the window, i.e. to
expand the window so that it fills the entire screen, while preserving the
appearance of the window including its title bar.  The release of OSX 10.7
(Lion) introduced the "FullScreen" window which not only filled the screen but
also hid the window's title bar and the menu bar which normally appears at the
top of the screen. These hidden objects would only become visible when the
mouse hovered near the top of the screen.  FullScreen mode was initiated by
pressing a button showing two outward pointing arrows located on the right side
of the title bar; it was terminated by pressing a similar button with inward
pointing arrows on the right hand side of the menu bar.  In OSX 10.10
(Yosemite) the FullScreen button was removed. The green button was repurposed
to cause a window to become a FullScreen window. To zoom a window the user had
to hold down the option key while pressing the green button.  The release of
OSX 10.11 added a third function to the green button: to create two half-screen
windows with hidden title bars and a hidden menu bar, called Split View
windows.  If the green button is held down for one second its window expands to
fill half of the screen.  It can be moved to one side or the other with the
mouse.  The opposite side shows thumbnail images of other windows.  Selecting
one of the thumbnails expands its window to fill that half of the screen.  The
divider between the two windows can be moved to adjust the percentage of the
screen occupied by each of the two tiles.  In OSX 10.12 (Sierra) Tabbed windows
were introduced.  These allow an application with multiple windows to display
its windows as tabs within a single window frame.  Clicking on a tab brings its
window into view.  Tabs can be rearranged by dragging.  Dragging a tab to the
desktop turns it into a separate window.  Items in the Window menu can be used
to cycle through the tabs, move tabbed windows to separate windows, or merge a
set of separate windows as tabs in the same window frame.

Tk now fully supports all of these high level window operations on any system
where the operation exists.  The FullScreen and Split View windows are handled
automatically with no action required on the part of the programmer.  Tabbed
windows, on the other hand, require some attention from the programmer.
Because many of the operations with tabs are handled through the application's
Window menu, it is essential that an application provide a Windows menu to
avoid presenting a confusing interface to the user. This cannot be ignored, in
part because the systemwide Dock Preferences offers an option to always attempt
to open application windows as tabs. An application which does not provide a
Window menu will necessarily present a confusing interface to any user who has
selected this option.

A further complication is that it is not neccessarily appropriate for all of an
application's windows to be grouped together as tabs in the same frame.  In
fact, the Apple guidelines insist that windows which are grouped together as
tabs should be similar to each other.  The mechanism provided for arranging
this was to assign to each NSwindow a tabbingIdentifier, and to require that
all windows grouped together as tabs in the same window frame must have the
same tabbingIdentifier.  A tabbingIdentifier is implemented as an arbitrary
string, and a system-generated default tabbingIdentifier is provided to all new
windows.

Tk provides a means for getting and setting the tabbingIdentifier of
the NSWindow underlying a Tk Window. This is handled by the command

tk::unsupported::MacWindowStyle tabbingid window ?newId?

(This command generates an error if used on OSX 10.11 or earlier, since the
tabbingIdentifier does not exist on those systems.)  The command returns the
tabbingIdentifier which had been assigned to the window prior to execution of
the command.  If the optional newId argument is omitted, the window's
tabbingIdentifier is not changed.  Otherwise it is set to the string specified
by the argument.

Since NSWindows can only be grouped together as tabs if they all have the same
tabbingIdentifier, one can prevent a window from becoming a tab by giving it a
unique tabbingIdentifier. This is independent of any preferences setting. To
ensure that we maintain consistency, changing the tabbingIdentifier of a window
which is already displayed as a tab will also cause it to become a separate
window.

4. Ttk, Dark Mode and semantic colors
---------------------------------------

With the release of OSX 10.14 (Mojave), Apple introduced the DarkAqua
appearance.  Part of the implementation of the Dark Mode was to make
some of the named NSColors have dynamic values.  Apple calls these
"semantic colors" because the name does not specify a specific color,
but rather refers to the context in which the color should be used.
In particular, when a user selects Dark Mode in the system preferences
these colors change appearance.  For example systemTextColor is dark in
Aqua and light in DarkAqua.

Tk now provides colors corresponding to all of the NSColors in Apple's System
ColorList.  The convention for naming these colors is that the Tk name is
generated by capitalizing the macOS name and adding the prefix "system". The
System ColorList differs between releases of macOS and some colors, such as
systemLinkColor and systemControlAccentColor, are simulated on older systems
which did not provide them.  The following colors are available on all
supported macOS releases, although newer systems will support additional
colors: systemControlAccentColor, systemControlTextColor,
systemDisabledControlTextColor, systemLabelColor, systemLinkColor,
systemPlaceholderTextColor, systemSelectedTextBackgroundColor,
systemSelectedTextColor, systemSeparatorColor, systemTextBackgroundColor, and
systemTextColor.  One additional color, systemSelectedTabTextColor, does not
exist in macOS but is used by Tk to match the different colors used for
Notebook tab titles in different OS versions.

The default background and foreground colors of most of the Tk widgets
have been set to semantic colors, which means that the widgets will change
appearance, and remain usable, when Dark Mode is selected in the system
preferences.  However, to get a close match to the native Dark Mode style it
is recommended to use Ttk widgets when possible.

Apple's tab view and GroupBox objects delimit their content by
displaying it within a rounded rectangle with a background color that
contrasts with the background of the containing object.  This means
that the background color of a Ttk widget depends on how deeply it is
nested inside of other widgets that use contrasting backgrounds.  To
support this, there are 8 contrasting system colors named
systemWindowBackgroundColor, and systemWindowBackgroundColor1 - 7.
The systemWindowBackgroundColor is the standard background for a
dialog window and the others match the contrasting background colors
used in ttk::notebooks and ttk::labelframes which are nested to the
corresponding depth.

5. Building Tcl/Tk on macOS
3. Building Tcl/Tk on Mac OS X
------------------------------

- At least Mac OS X 10.3 is required to build Tcl and TkX11, and Mac OS X 10.5
- macOS 10.6 is required to build TkAqua and TkX11.  The XCode application provides everything needed to build Tk, but it is not necessary to install the full XCode.
It suffices to install the Command Line Tools package, which can be done
is required to build TkAqua.
Apple's Xcode Developer Tools need to be installed (only the most recent version
matching your OS release is supported), the Xcode installer is available on Mac
OS X install media or may be present in /Applications/Installers on Macs that
by running the command:
xcode-select --install
came with OS X preinstalled. The most recent version can always be downloaded
from the ADC website http://connect.apple.com (free ADC membership required).

- Tcl/Tk are most easily built as macOS frameworks via GNUmakefile in
- Tcl/Tk are most easily built as Mac OS X frameworks via GNUmakefile in
tcl/macosx and tk/macosx (see below for details), but can also be built with the
standard unix configure and make buildsystem in tcl/unix resp. tk/unix as on any
other unix platform (indeed, the GNUmakefiles are just wrappers around the unix
buildsystem).
The macOS specific configure flags are --enable-aqua, --enable-framework and
The Mac OS X specific configure flags are --enable-aqua, --enable-framework and
--disable-corefoundation (which disables CF and notably reverts to the standard
select based notifier). Note that --enable-aqua is incompatible with
--disable-corefoundation (for both Tcl and Tk configure).

- It was once possible to build with the Xcode IDE via the project in
- It is also possible to build with the Xcode IDE via the projects in
tk/macosx, but this has not been tested recently. Take care to use the
project matching your DevTools and OS version:
tk/macosx, take care to use the project matching your DevTools and OS version:
	Tk.xcode: 		    for Xcode 3.1 on 10.5
	Tk.xcodeproj:		    for Xcode 3.2 on 10.6
These have the following targets:
	Tk:			    calls through to tk/macosx/GNUMakefile,
				    requires a corresponding build of the Tcl
				    target of tcl/macosx/Tcl.xcode.
	tktest:			    static build of TkAqua tktest for debugging.
	tktest-X11:		    static build of TkX11 tktest for debugging.
The following build configurations are available:
	Debug:			    debug build for the active architecture,
				    with Fix & Continue enabled.
	Debug clang:		    use clang compiler.
	Debug llvm-gcc:		    use llvm-gcc compiler.
	Debug gcc40:		    use gcc 4.0 compiler.
	DebugNoGC:		    disable Objective-C garbage collection.
	DebugNoFixAndContinue:      disable Fix & Continue.
	DebugUnthreaded:	    disable threading.
	DebugNoCF:		    disable corefoundation (X11 only).
	DebugNoCFUnthreaded:	    disable corefoundation an threading.
	DebugMemCompile:	    enable memory and bytecode debugging.
	DebugLeaks:		    define PURIFY.
	DebugGCov:		    enable generation of gcov data files.
	Debug64bit:		    configure with --enable-64bit (requires
				    building on a 64bit capable processor).
	Release:		    release build for the active architecture.
	ReleaseUniversal:	    32/64-bit universal build.
	ReleaseUniversal clang:	    use clang compiler.
	ReleaseUniversal llvm-gcc:  use llvm-gcc compiler.
	ReleaseUniversal gcc40:	    use gcc 4.0 compiler.
	ReleaseUniversal10.5SDK:    build against the 10.5 SDK (with 10.5
				    deployment target).
	Note that the non-SDK configurations have their deployment target set to
	10.6 (Tk.xcodeproj).
	10.5 (Tk.xcode) resp. 10.6 (Tk.xcodeproj).
The Xcode projects refer to the toplevel tcl and tk source directories via the
the TCL_SRCROOT and TK_SRCROOT user build settings, by default these are set to
the project-relative paths '../../tcl' and '../../tk', if your source
directories are named differently, e.g. '../../tcl8.7' and '../../tk8.7', you
directories are named differently, e.g. '../../tcl8.6' and '../../tk8.6', you
need to manually change the TCL_SRCROOT and TK_SRCROOT settings by editing your
${USER}.pbxuser file (located inside the Tk.xcodeproj bundle directory) with a
text editor.

- To build universal binaries outside of the Xcode IDE, set CFLAGS as follows:
	export CFLAGS="-arch i386 -arch x86_64 -arch ppc"
This requires Mac OS X 10.4 and Xcode 2.4 (or Xcode 2.2 if -arch x86_64 is
omitted, but _not_ Xcode 2.1) and will work on any architecture (on PowerPC
Tiger you need to add "-isysroot /Developer/SDKs/MacOSX10.4u.sdk").
Note that configure requires CFLAGS to contain a least one architecture that can
be run on the build machine (i.e. ppc on G3/G4, ppc or ppc64 on G5, ppc or i386
on Core and ppc, i386 or x86_64 on Core2/Xeon).
Universal builds of Tcl TEA extensions are also possible with CFLAGS set as
above, they will be [load]able by universal as well as thin binaries of Tcl.

- To enable weak-linking, set the MACOSX_DEPLOYMENT_TARGET environment variable
to the minimal OS version the binaries should be able to run on, e.g:
	export MACOSX_DEPLOYMENT_TARGET=10.6
	export MACOSX_DEPLOYMENT_TARGET=10.4
This requires at least gcc 3.1; with gcc 4 or later, set/add to CFLAGS instead:
	export CFLAGS="-mmacosx-version-min=10.6"
	export CFLAGS="-mmacosx-version-min=10.4"
Support for weak-linking was added with 8.4.14/8.5a5.

Detailed Instructions for building with macosx/GNUmakefile
----------------------------------------------------------

- Unpack the Tcl and Tk source release archives and place the tcl and tk source
trees in a common parent directory.
[ If you don't want have the two source trees in one directory, you'll need to ]
[ create the following symbolic link for the build to work as setup by default ]
[      ln -fs /path_to_tcl/build /path_to_tk/build			       ]
[ (where /path_to_{tcl,tk} is the directory containing the tcl resp. tk tree)  ]
[ or you can pass an argument of BUILD_DIR=/somewhere to the tcl and tk make.  ]

- The following instructions assume the Tcl and Tk source trees are named
"tcl${ver}" and "tk${ver}" (where ${ver} is a shell variable containing the
Tcl/Tk version number, e.g. '8.7').
Tcl/Tk version number, e.g. '8.6').
Setup this shell variable as follows:
	ver="8.7"
	ver="8.6"
If you are building from CVS, omit this step (CVS source tree names usually do
not contain a version number).

- Setup environment variables as desired, e.g. for a universal build on 10.5:
	CFLAGS="-arch x86_64 -arch arm64 -mmacosx-version-min=10.5"
	CFLAGS="-arch i386 -arch x86_64 -arch ppc -mmacosx-version-min=10.5"
	export CFLAGS

- Change to the directory containing the Tcl and Tk source trees and build:
	make -C tcl${ver}/macosx
	make -C tk${ver}/macosx

- Install Tcl and Tk onto the root volume (admin password required):
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470

471
472
473
474
475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491




492
493
494
495
496
497
498
499
500
501



502
503

504

505
506
507
508
509





510
511
512

513
514
515
516


517
518
519


520
521
522
523
524
525
526
527
528
529
530



531
532
533

534
535
536
537
538
539
540
541
542

543
544
545
546
547



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562





563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710

711
712
713

714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
385
386
387
388
389
390
391














392


393
394




395


396
397
398
399
400
401



402




403
404
405
406
407
408
409
410
411
412
413



414
415
416


417
418
419





420
421
422
423
424



425

426


427
428



429
430











431
432
433



434









435
436
437



438
439
440









441





442
443
444
445
446
447
448
449

















































































































































450



451

















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+

-
-
-
-
+
-
-






-
-
-

-
-
-
-
+
+
+
+







-
-
-
+
+
+
-
-
+

+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-

-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+


-
-
-
+
+
+
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
make overrides to the tk/macosx GNUmakefile, e.g.
	make -C tk${ver}/macosx \
	    TCL_FRAMEWORK_DIR=$HOME/Library/Frameworks TCLSH_DIR=$HOME/usr/bin
	sudo make -C tk${ver}/macosx install \
	    TCL_FRAMEWORK_DIR=$HOME/Library/Frameworks TCLSH_DIR=$HOME/usr/bin
The Makefile variables TCL_FRAMEWORK_DIR and TCLSH_DIR were added with Tk 8.4.3.

- To build a Tcl.framework and Tk.framework for use as subframeworks in another
framework, use the install-embedded target and set SUBFRAMEWORK=1.  Set the
DYLIB_INSTALL_DIR variable to the path which should be the install_name path of
the shared library and set the DESTDIR variable to the pathname of a staging
directory where the frameworks will be written.  The Tcl framework must be
built first.
For example, running the commands:
	make -C ../tcl8.7/macosx install-embedded SUBFRAMEWORK=1 DESTDIR=/tmp/tcltk \
	DYLIB_INSTALL_DIR=/Library/Frameworks/Some.framework/Versions/X.Y/Frameworks/Tcl.framework
	make -C macosx install-embedded SUBFRAMEWORK=1 DESTDIR=/tmp/tcltk \
	DYLIB_INSTALL_DIR=/Library/Frameworks/Some.framework/Versions/X.Y/Frameworks/Tk.framework
will produce a Tcl.framework and a Tk.framework usable as subframeworks of
Some.framework.  The frameworks will be found in /tmp/tcltk/Frameworks/

4. About the event loop in Tk for Mac OSX
5. Details regarding the macOS port of Tk.
-------------------------------------------
-----------------------------------------

5.1 About the event loop
~~~~~~~~~~~~~~~~~~~~~~~~

The main program in a typical OSX application looks like this (see
The main program in a typical OSX application looks like this (see *)
https://developer.apple.com/library/mac/documentation/Cocoa/\
Reference/ApplicationKit/Classes/NSApplication_Class)

    void NSApplicationMain(int argc, char *argv[]) {
        [NSApplication sharedApplication];
        [NSBundle loadNibNamed:@"myMain" owner:NSApp];
        [NSApp run];
    }
Here NSApp is a standard global variable, initialized by the OS, which
points to an object in a subclass of NSApplication (called
TKApplication in the case of the macOS port of Tk).

The [NSApp run] method implements the event loop for a typical Mac
application.  There are three key steps in the run method.  First it
calls [NSApp finishLaunching], which creates the bouncing application
icon and does other mysterious things. Second it creates an
The run method implements the event loop for the application.  There
are three key steps in the run method.  First it calls
[NSApp finishLaunching], which creates the bouncing application icon
and does other mysterious things. Second it creates an
NSAutoreleasePool.  Third, it starts an event loop which drains the
NSAutoreleasePool every time the queue is empty, and replaces the
drained pool with a new one.  This third step is essential to
preventing memory leaks, since the internal methods of Appkit objects
all assume that an autorelease pool is in scope and will be drained
when the event processing cycle ends.

The macOS Tk application does not call the [NSApp run] method at
all.  Instead it uses the event loop built in to Tk.  So the
application must take care to replicate the important features of the
Mac OSX Tk does not call the [NSApp run] method at all.  Instead it
uses the event loop built in to Tk.  So we must take care to replicate
the important features of the method ourselves.  Here is how this
method ourselves.  The way that autorelease pools are handled is
discussed in 5.2 below.  Here we discuss the event handling itself.
works in outline.

We add a private NSAUtoreleasePool* property to our subclass of
The Tcl event loop simply consists of repeated calls to TclDoOneEvent.
Each call to TclDoOneEvent begins by collecting all pending events from
an "event source", converting them to Tcl events and adding them
to the Tcl event queue. For macOS, the event source is the NSApp
object, which maintains an event queue even though its run method
NSApplication.  (The subclass is called TKApplication but can be
referenced with the global variable NSApp).  The TkpInit
function calls [NSApp _setup] which initializes this property by
creating an NSAutoreleasePool. A bit later on, TkpInit calls
[NSAPP _setupEventLoop] which in turn calls the
will never be called to process them.  The NSApp provides methods for
inspecting the queue and removing events from it as well as the
[NSApp sendevent] which sends an event to all of the application's
[NSApp finishLaunching] method.
NSWindows which can then send it to subwindows, etc.

The event collection process consists of first calling a platform
specific SetupProc and then a platform specific CheckProc.  In
Each time that Tcl processes an event in its queue, it calls a
platform specific function which, in the case of Mac OSX, is named
the macOS port, these are named TkMacOSXEventsSetupProc and
TkMacOSXEventsCheckProc.

TkMacOSXEventsCheckProc.  In the unix implementations of Tk, including
the Mac OSX version, this function collects events from an "event
It is important to understand that the Apple window manager does not
have the concept of an expose event.  Their replacement for an expose
event is to have the window manager call the [NSView drawRect] method
in any situation where an expose event for that NSView would be
generated in X11.  The [NSView drawRect] method is a no-op which is
expected to be overridden by any application.  In the case of Tcl, the
replacement [NSView drawRect] method creates a Tcl expose event
for each dirty rectangle of the NSView, and then adds the expose
event to the Tcl queue.


source", and transfers them to the Tcl event queue.  In Mac OSX the
event source is the NSApplication event queue.  Each NSEvent is
converted to a Tcl event which is added to the Tcl event queue.  The
5.2 Autorelease pools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NSEvent is also passed to [NSApp sendevent], which sends the event on
In order to carry out the job of managing autorelease pools, which
would normally be handled by the [NSApp run] method, a private
NSAutoreleasePool* property is added to the TkApplication subclass of
NSApplication. The TkpInit function calls [NSApp _setup] which
initializes this property by creating an NSAutoreleasePool prior to
calling [NSApp finishLaunching].  This mimics the behavior of the
[NSApp run] method, which calls [NSApp finishLaunching] just before
starting the event loop.

to the application's NSWindows, which send it to their NSViews, etc.
Since the CheckProc function gets called for every Tk event, it is an
appropriate place to drain the main NSAutoreleasePool and replace it
with a new pool.  This is done by calling the method [NSApp
_resetAutoreleasePool], where _resetAutoreleasePool is a method which
we define for the subclass.  Unfortunately, by itself this is not
with a new pool.  This is done by calling the method
[NSApp _resetAutoreleasePool], where _resetAutoreleasePool is a method
which we define for the subclass TKApplication.
sufficient for safe memory management because, as was made painfully
evident with the release of OS X 10.13, it is possible for calls to
TclDoOneEvent, and hence to CheckProc, to be nested.  Draining the
autorelease pool in a nested call leads to crashes as objects in use
by the outer call can get freed by the inner call and then reused later.
One particular situation where this happens is when a modal dialogue
gets posted by a Tk Application.  To address this, the NSApp object
also implements a semaphore to prevent draining the autorelease pool
in nested calls to CheckProc.

One additional minor caveat for developers is that there are several
steps of the Tk initialization which precede the call to TkpInit.
Notably, the font package is initialized first.  Since there is no
NSAutoreleasePool in scope prior to calling TkpInit, the functions
called in these preliminary stages need to create and drain their own
One minor caveat is that there are several steps of the Tk
initialization which precede the call to TkpInit.  Notably, the font
package is initialized first.  Since there is no NSAUtoreleasePool in
scope prior to calling TkpInit, the functions called in these
preliminary stages need to create and drain their own
NSAutoreleasePools whenever they call methods of Appkit objects
(e.g. NSFont).

5.3 Clipping regions and "ghost windows"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Another unusual aspect of the macOS port is its use of clipping
regions.  It was part of Daniel Steffen's original design that the
TkWindowPrivate struct maintains three HIShapeRef regions, named
visRgn, aboveVisRgn and drawRgn.  These regions are used as clipping
masks whenever drawing into an NSView.  The visRgn is the bounding box
of the window with a rectangle removed for each subwindow and for each
sibling window at a higher stacking level.  The drawRgn is the
intersection of the visRgn with the clipping rectangle of the
window. (Normally, the clipping rectangle is the same as the bounding
rectangle, but drawing can be clipped to a smaller rectangle by
calling TkpClipDrawableToRect.) The aboveVisRgn is the intersection of
the window's bounding rectangle with the bounding rectangle of the
parent window.  Much of the code in tkMacOSXSubwindows.c is devoted to
rebuilding these clipping regions whenever something changes in the
layout of the windows.  This turns out to be a tricky thing to do and
it is extremely prone to errors which can be difficult to trace.

It is not entirely clear what the original reason for using these
clipping regions was.  But one benefit is that if they are correctly
maintained then it allows windows to be drawn in any order.  You do
not have to draw them in the order of the window hierarchy.  Each
window can draw its entire rectangle through its own mask and never
have to worry about drawing in the wrong place.  It is likely that
the need for using clipping regions arose because, as Apple explicitly
states in the documentation for [NSView subviews],

    "The order of the subviews may be considered as being
    back-to-front, but this does not imply invalidation and drawing
    behavior."

In the early versions of the macOS port, buttons were implemented as
subviews of class TkButton.  This probably exacerbated the likelihood
that Tk windows would need to be drawn in arbitrary order.

The most obvious side effect caused by not maintaining the clipping
regions is the appearance of so-called "ghost windows".  A common
situation where these may arise is when a window containing buttons
is being scrolled.  A user may see two images of the same button on
the screen, one in the pre-scroll location and one in the post-scroll
location.

To see how these 'ghost windows' can arise, think about what happens if
the clipping regions are not maintained correctly.  A window might
have a rectangle missing from its clipping region because that
rectangle is the bounding rectangle for a subwindow, say a button.
The parent should not draw in the missing rectangle since doing so
would trash the button.  The button is responsible for drawing
there. Now imagine that the button gets moved, say by a scroll, but
the missing rectangle in the parent's clipping region does not get
moved correctly, or it gets moved later on, after the parent has
redrawn itself.  The parent would still not be allowed to draw in the
old rectangle, so the user would continue to see the image of the
button in its old location, as well as another image in the new
location.  This is a prototypical example of a "ghost window".
Anytime you see a "ghost window", you should suspect problems with the
updates to the clipping region visRgn.  It is natural to look for
timing issues, race conditions, or other "event loop problems".  But
in fact, the whole design of the code is to make those timing issues
irrelevant.  As long as the clipping regions are correctly maintained
the timing does not matter.  And if they are not correctly maintained
then you will see "ghost windows".

It is worth including a detailed description of one specific place
where the failure to correctly maintain clipping regions caused "ghost
window" artifacts that plagued the macOS port for years.  These
occurred when scrolling a Text widget which contained embedded
subwindows.  It involved some specific differences between the
low-level behavior of Apple's window manager versus those of the other
platforms, and the fix ultimately required changes in the generic Tk
implementation (documented in the comments in the DisplayText
function).

The Text widget attempts to improve performance when scrolling by
minimizing the number of text lines which need to be redisplayed.  It
does this by calling the platform-specific TkScrollWindow function
which uses a low-level routine to map one rectangle of the window to
another.  The TkScrollWindow function returns a damage region which is
then used by the Text widget's DisplayText function to determine which
text lines need to be redrawn.  On the unix and win platforms, this
damage region includes bounding rectangles for all embedded windows
inside the Text widget.  The way that this works is system dependent.
On unix, the low level scrolling is done by XCopyArea, which
generates a GraphicsExpose event for each embedded window.  These
GraphicsExposed events are processsed within TkScrollWindow, using a
special handler which adds the bounding rectangle of each subwindow to
the damage region.  On the win platform the damage region is built by
the low level function ScrollWindowEx, and it also includes bounding
rectangles for all embedded windows.  This is possible because on X11
and Windows every Tk widget is also known to the window manager as a
window.  The situation is different on macOS.  The underlying object
for a top level window on macOS is the NSView.  However, Apple
explicitly warns in its documentation that performance degradation
occurs when an NSView has more than about 100 subviews.  A Text widget
with thousands of lines of text could easily contain more than 100
embedded windows.  In fact, while the original Cocoa port of Tk did
use the NSButton object, which is derived from NSView, as the basis
for its Tk Buttons, that was changed in order to improve performance.
Moreover, the low level routine used for scrolling on macOS, namely
[NSView scrollrect:by], does not provide any damage information.  So
TkScrollWindow needs to work differently on macOS.  Since it would be
inefficient to iterate through all embedded windows in a Text widget,
looking for those which meet the scrolling area, the damage region
constructed by TkScrollWindow contains only the difference between the
source and destination rectangles for the scrolling.  The embedded
windows are redrawn within the DisplayText function by some
conditional code which is only used for macOS.

6.0 Virtual events on macOS 10.14 and later
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The 10.14 release added support for system appearance changes,
including a "Dark Mode" that renders all window frames and menus in
dark colors. Tk 8.7 provides three virtual events <<LightAqua>>,
<<DarkAqua>> and <<AppearanceChanged>>, to allow you to update your Tk
app's appearance when the system appearance changes.  These events are
generated in [NSView effectiveAppearanceChanged], which is called by
the Apple window manager when the General Preferences is changed
either by switching between Light Mode and Dark Mode or by changing
the Accent Color or Highlight Color.

The <<AppearanceChanged>> virtual event has a data string which can be
accessed with the %d substitution.  The format of the data string is
that it consists of 6 words:
  "Appearance XXXX Accent YYYY Highlight ZZZZ"
For example, the following code will print the current appearance
name, accent color and highlight color when the <<AppearanceChanged>>
virtual event fires:

bind . <<AppearanceChanged>> {
    array set data [split %d]
    puts "  Appearance: $data(Appearance)"
    puts "  Accent: $data(Accent)"
    puts "  Highlight: $data(Highlight)\n"
}



7.0 Mac Services
~~~~~~~~~~~~~~~~~~~~~~~~~~~

With 8.6.10, Tk supports the Mac's NSServices API, documented at
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/SysServices/introduction.html#//apple_ref/doc/uid/10000101-SW1
* https://developer.apple.com/library/mac/documentation/Cocoa/\
and in TIP 536 and Tk's man page. Tk presents a simple,
straightforward API to implement the Services functionality.

Reference/ApplicationKit/Classes/NSApplication_Class
The Tk implementation of the NSServices API is intended for standalone
applications, such as one wrapped by the standalone version of Wish
and re-named into a different application.  In particular such an
application would specify its own unique CFBundleIdentifier in its
Info.plist file.  During development, however, if Wish itself is being
used as the receiver, it may be necessary to take some care to ensure
that the correct version of Wish.app is available as a receiver of
NSServices data.

When one macOS app uses NSServices to send data to another app that is
not running, LaunchServices will launch the receiver.  LaunchServices
assumes that the CFBundleIdentifier uniquely identifies an app among
all of the apps installed on a system.  But this may not be the case
for Wish.app if, for example, you have compiled Tk from source at some
time in the past.  In that case the Tk build directory will contain
its own copy of Wish.app that will be visible to LaunchServices.  It
may be necessary when testing your app to take some steps to ensure
that LaunchServices is launching the correct Wish.app.  Instructions
for doing this are provided below.

The command line tool which manages the LaunchServices database has
an amazingly unwieldy path name.  So, first, run this command:

alias lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister'

Then you can reset the LaunchServices database like this:

$ lsregister -kill
$ lsregister -seed

To find out which versions of Wish.app have been located by
LaunchServices, run:

$ lsregister -dump | grep path | grep Wish

If more than one version of Wish is showing up in this list, eliminate
all of the unintended targets by running

lsregister -u /path/to/bad/Wish.app

Continue this until only the correct version of Wish shows up in the
list.

Changes to macosx/Tk-Common.xcconfig.

19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35

36
37
38

39
40
41
42
43
44

45
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44

45
46







-
+









+


-
+





-
+

GCC_PREFIX_HEADER = $(DERIVED_FILE_DIR)/tk/tkConfig.h
OTHER_CFLAGS = -imacros "$(DERIVED_FILE_DIR)/tcl/tclConfig.h" $(OTHER_CFLAGS)
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
GCC_NO_COMMON_BLOCKS = YES
GCC_DYNAMIC_NO_PIC = YES
GCC_VERSION = 4.2
GCC = gcc-$(GCC_VERSION)
WARNING_CFLAGS = -Wall -Wextra -Wshadow -Wundef -Wwrite-strings -Wpointer-arith -Winit-self -Wcast-align -Wdisabled-optimization -Winline $(WARNING_CFLAGS)
WARNING_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-value -Winit-self -Wpointer-arith -Wcast-align -Wdisabled-optimization -Winline $(WARNING_CFLAGS)
REZ_RESOURCE_MAP_READ_ONLY = YES
APPLICATION_INSTALL_PATH = /Applications/Utilities
BINDIR = $(PREFIX)/bin
CFLAGS = $(CFLAGS)
CPPFLAGS = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) $(CPPFLAGS)
FRAMEWORK_INSTALL_PATH = /Library/Frameworks
INCLUDEDIR = $(PREFIX)/include
LIBDIR = $(PREFIX)/lib
MANDIR = $(PREFIX)/man
PER_ARCH_CFLAGS_ppc = -mcpu=G3 -mtune=G4 $(PER_ARCH_CFLAGS_ppc)
PREFIX = /usr/local
TCL_BUILD_DIR = $(OBJROOT)/../tcl/Tcl.build/$(CONFIGURATION)/Tcl.build/Objects
TCL_CONFIGURE_ARGS = --enable-dtrace
TCL_CONFIGURE_ARGS = --enable-threads --enable-dtrace
TCL_FRAMEWORK_DIR = $(SYMROOT)/../tcl/$(CONFIGURATION)
TCL_LIBRARY = $(LIBDIR)/tcl$(VERSION)
TCL_PACKAGE_PATH = "$(LIBDIR)"
TCL_DEFS = HAVE_TCL_CONFIG_H
TK_LIBRARY = $(LIBDIR)/tk$(VERSION)
TK_DEFS = HAVE_TK_CONFIG_H
TK_DEFS = HAVE_TK_CONFIG_H TCL_NO_DEPRECATED
VERSION = 8.7

Changes to macosx/Tk-Release.xcconfig.

9
10
11
12
13
14
15
16

17
18
19
9
10
11
12
13
14
15

16
17
18
19







-
+



// See the file "license.terms" for information on usage and redistribution
// of this file, and for a DISCLAIMER OF ALL WARRANTIES.

#include "Tk-Common.xcconfig"

DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
// DEPLOYMENT_POSTPROCESSING = YES
GCC_OPTIMIZATION_LEVEL = 2
GCC_OPTIMIZATION_LEVEL = s
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG $(TCL_DEFS) $(TK_DEFS) $(GCC_PREPROCESSOR_DEFINITIONS)
CONFIGURE_ARGS = --disable-symbols $(TCL_CONFIGURE_ARGS) $(CONFIGURE_ARGS)
MAKE_TARGET = deploy

Added macosx/Tk.xcode/default.pbxuser.

































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// !$*UTF8*$!
{
	08FB7793FE84155DC02AAC07 /* Project object */ = {
		activeBuildConfigurationName = Debug;
		activeExecutable = F9E61D1C090A4282002B3151 /* Wish */;
		activeTarget = F9E61D16090A3E94002B3151 /* Tk */;
		codeSenseManager = F944EB9D08F798180049FDD4 /* Code sense */;
		executables = (
			F9E61D1C090A4282002B3151 /* Wish */,
			F944EB8F08F798100049FDD4 /* tktest */,
			F9FD31F50CC1AD070073837D /* tktest-X11 */,
		);
		perUserDictionary = {
			com.apple.ide.smrt.PBXUserSmartGroupsKey.Rev10 = <040b73747265616d747970656481e8038401408484840e4e534d757461626c654172726179008484074e534172726179008484084e534f626a65637400858401690192848484134e534d757461626c6544696374696f6e6172790084840c4e5344696374696f6e6172790095960792848484084e53537472696e67019584012b046e616d658692849a9a14496d706c656d656e746174696f6e2046696c65738692849a9a146162736f6c75746550617468546f42756e646c658692849a9a008692849a9a195042585472616e7369656e744c6f636174696f6e4174546f708692849a9a06626f74746f6d8692849a9a03636c7a8692849a9a1550425846696c656e616d65536d61727447726f75708692849a9a0b6465736372697074696f6e8692849a9a103c6e6f206465736372697074696f6e3e8692849a9a0b707265666572656e63657386928497960892849a9a07666e6d617463688692849a9a008692849a9a05696d6167658692849a9a0b536d617274466f6c6465728692849a9a04726f6f748692849a9a093c50524f4a4543543e8692849a9a0572656765788692849a9a065c2e286329248692849a9a097265637572736976658692848484084e534e756d626572008484074e5356616c7565009584012a849696018692849a9a0669734c656166869284b09db296008692849a9a0763616e536176658692af92849a9a1250425850726f6a65637453636f70654b65798692849a9a03594553868692849a9a08676c6f62616c49448692849a9a18314343304541343030343335304546393030343434313042868686>;
		};
		sourceControlManager = F944EB9C08F798180049FDD4 /* Source Control */;
		userBuildSettings = {
			SYMROOT = "${SRCROOT}/../../build/tk";
			TCL_SRCROOT = "${SRCROOT}/../../tcl";
			TK_SRCROOT = "${SRCROOT}/../../tk";
		};
	};
	8DD76FA90486AB0100D96B5E /* tktest */ = {
		activeExec = 0;
		executables = (
			F944EB8F08F798100049FDD4 /* tktest */,
		);
	};
	F944EB8F08F798100049FDD4 /* tktest */ = {
		isa = PBXExecutable;
		activeArgIndices = (
			YES,
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
		);
		argumentStrings = (
			"${TK_SRCROOT}/library/demos/widget",
			"${TK_SRCROOT}/tests/all.tcl",
			"${TK_SRCROOT}/tests/ttk/all.tcl",
			"-geometry +0+0",
			"-singleproc 1",
			"-verbose \"bet\"",
			"-skip window-2.9",
		);
		autoAttachOnCrash = 1;
		breakpointsEnabled = 1;
		configStateDict = {
			"PBXLSLaunchAction-0" = {
				PBXLSLaunchAction = 0;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXLSRunLaunchConfig;
				displayName = "Executable Runner";
				identifier = com.apple.Xcode.launch.runConfig;
				remoteHostInfo = "";
				startActionInfo = "";
			};
			"PBXLSLaunchAction-1" = {
				PBXLSLaunchAction = 1;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXGDB_LaunchConfig;
				displayName = GDB;
				identifier = com.apple.Xcode.launch.GDBMI_Config;
				remoteHostInfo = "";
				startActionInfo = "";
			};
		};
		customDataFormattersEnabled = 1;
		debuggerPlugin = GDBDebugging;
		disassemblyDisplayState = 0;
		dylibVariantSuffix = "";
		enableDebugStr = 0;
		environmentEntries = (
			{
				active = YES;
				name = TCL_LIBRARY;
				value = "${TCL_SRCROOT}/library";
			},
			{
				active = YES;
				name = TK_LIBRARY;
				value = "${TK_SRCROOT}/library";
			},
			{
				active = YES;
				name = TCLLIBPATH;
				value = /Library/Tcl;
			},
			{
				active = YES;
				name = TK_SRCROOT;
				value = "${TK_SRCROOT}";
			},
			{
				active = NO;
				name = TK_CONSOLE;
				value = 1;
			},
			{
				active = NO;
				name = DYLD_PRINT_LIBRARIES;
			},
			{
				active = NO;
				name = NSTraceEvents;
				value = YES;
			},
			{
				active = NO;
				name = MallocBadFreeAbort;
				value = 1;
			},
			{
				active = NO;
				name = MallocLogFile;
				value = /tmp/malloc.log;
			},
			{
				active = NO;
				name = MallocStackLogging;
				value = 1;
			},
			{
				active = NO;
				name = MallocStackLoggingNoCompact;
				value = 1;
			},
			{
				active = NO;
				name = MallocPreScribble;
				value = 1;
			},
			{
				active = NO;
				name = MallocScribble;
				value = 1;
			},
			{
				active = NO;
				name = NSZombieEnabled;
				value = YES;
			},
			{
				active = NO;
				name = NSDeallocateZombies;
				value = YES;
			},
			{
				active = NO;
				name = NSAutoreleaseFreedObjectCheckEnabled;
				value = YES;
			},
			{
				active = NO;
				name = NSEnableAutoreleasePool;
				value = NO;
			},
			{
				active = NO;
				name = AUTO_LOG_ALL;
				value = YES;
			},
			{
				active = NO;
				name = AUTO_LOG_NOISY;
				value = YES;
			},
			{
				active = NO;
				name = AUTO_REFERENCE_COUNT_LOGGING;
				value = YES;
			},
		);
		executableSystemSymbolLevel = 0;
		executableUserSymbolLevel = 0;
		libgmallocEnabled = 0;
		name = tktest;
		sourceDirectories = (
		);
	};
	F944EB9C08F798180049FDD4 /* Source Control */ = {
		isa = PBXSourceControlManager;
		fallbackIsa = XCSourceControlManager;
		isSCMEnabled = 0;
		scmConfiguration = {
			CVSToolPath = /usr/bin/cvs;
			CVSUseSSH = NO;
			SubversionToolPath = /usr/bin/svn;
			repositoryNamesForRoots = {
				.. = "";
			};
		};
		scmType = scm.cvs;
	};
	F944EB9D08F798180049FDD4 /* Code sense */ = {
		isa = PBXCodeSenseManager;
		indexTemplatePath = "";
	};
	F97258A50A86873C00096C78 /* tktest-X11 */ = {
		activeExec = 0;
		executables = (
			F9FD31F50CC1AD070073837D /* tktest-X11 */,
		);
	};
	F9E61D16090A3E94002B3151 /* Tk */ = {
		activeExec = 0;
		executables = (
			F9E61D1C090A4282002B3151 /* Wish */,
		);
	};
	F9E61D1C090A4282002B3151 /* Wish */ = {
		isa = PBXExecutable;
		activeArgIndices = (
			YES,
		);
		argumentStrings = (
			"${TK_SRCROOT}/library/demos/widget",
		);
		autoAttachOnCrash = 1;
		breakpointsEnabled = 1;
		configStateDict = {
			"PBXLSLaunchAction-0" = {
				PBXLSLaunchAction = 0;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXLSRunLaunchConfig;
				displayName = "Executable Runner";
				identifier = com.apple.Xcode.launch.runConfig;
				remoteHostInfo = "";
				startActionInfo = "";
			};
			"PBXLSLaunchAction-1" = {
				PBXLSLaunchAction = 1;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXGDB_LaunchConfig;
				displayName = GDB;
				identifier = com.apple.Xcode.launch.GDBMI_Config;
				remoteHostInfo = "";
				startActionInfo = "";
			};
		};
		customDataFormattersEnabled = 1;
		debuggerPlugin = GDBDebugging;
		disassemblyDisplayState = 0;
		dylibVariantSuffix = "";
		enableDebugStr = 0;
		environmentEntries = (
			{
				active = NO;
				name = DYLD_PRINT_LIBRARIES;
			},
		);
		executableSystemSymbolLevel = 0;
		executableUserSymbolLevel = 0;
		libgmallocEnabled = 0;
		name = Wish;
		sourceDirectories = (
		);
	};
	F9FD31F50CC1AD070073837D /* tktest-X11 */ = {
		isa = PBXExecutable;
		activeArgIndices = (
			YES,
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
		);
		argumentStrings = (
			"${TK_SRCROOT}/library/demos/widget",
			"${TK_SRCROOT}/tests/all.tcl",
			"${TK_SRCROOT}/tests/ttk/all.tcl",
			"-geometry +0+0",
			"-singleproc 1",
			"-verbose \"bet\"",
			"-skip window-2.9",
		);
		autoAttachOnCrash = 1;
		breakpointsEnabled = 1;
		configStateDict = {
			"PBXLSLaunchAction-0" = {
				PBXLSLaunchAction = 0;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXLSRunLaunchConfig;
				displayName = "Executable Runner";
				identifier = com.apple.Xcode.launch.runConfig;
				remoteHostInfo = "";
				startActionInfo = "";
			};
			"PBXLSLaunchAction-1" = {
				PBXLSLaunchAction = 1;
				PBXLSLaunchStartAction = 1;
				PBXLSLaunchStdioStyle = 2;
				PBXLSLaunchStyle = 0;
				class = PBXGDB_LaunchConfig;
				displayName = GDB;
				identifier = com.apple.Xcode.launch.GDBMI_Config;
				remoteHostInfo = "";
				startActionInfo = "";
			};
		};
		customDataFormattersEnabled = 1;
		debuggerPlugin = GDBDebugging;
		disassemblyDisplayState = 0;
		dylibVariantSuffix = "";
		enableDebugStr = 0;
		environmentEntries = (
			{
				active = YES;
				name = TCL_LIBRARY;
				value = "${TCL_SRCROOT}/library";
			},
			{
				active = YES;
				name = TK_LIBRARY;
				value = "${TK_SRCROOT}/library";
			},
			{
				active = YES;
				name = TCLLIBPATH;
				value = /Library/Tcl;
			},
			{
				active = YES;
				name = DISPLAY;
				value = ":0";
			},
			{
				active = NO;
				name = DYLD_PRINT_LIBRARIES;
			},
			{
				active = NO;
				name = MallocBadFreeAbort;
				value = 1;
			},
			{
				active = NO;
				name = MallocLogFile;
				value = /tmp/malloc.log;
			},
			{
				active = NO;
				name = MallocStackLogging;
				value = 1;
			},
			{
				active = NO;
				name = MallocStackLoggingNoCompact;
				value = 1;
			},
			{
				active = NO;
				name = MallocPreScribble;
				value = 1;
			},
			{
				active = NO;
				name = MallocScribble;
				value = 1;
			},
		);
		executableSystemSymbolLevel = 0;
		executableUserSymbolLevel = 0;
		libgmallocEnabled = 0;
		name = "tktest-X11";
		sourceDirectories = (
		);
	};
}

Added macosx/Tk.xcode/project.pbxproj.



















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 45;
	objects = {

/* Begin PBXBuildFile section */
		F9067BCD0BFBA2900074F726 /* tkOldTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFE08F27A39005CB29B /* tkOldTest.c */; };
		F9152B090EAF8A5000CD5C7B /* tkBusy.c in Sources */ = {isa = PBXBuildFile; fileRef = F9152B080EAF8A5000CD5C7B /* tkBusy.c */; };
		F9152B0A0EAF8A5700CD5C7B /* tkBusy.c in Sources */ = {isa = PBXBuildFile; fileRef = F9152B080EAF8A5000CD5C7B /* tkBusy.c */; };
		F92EE8BF0E62F846001A6E80 /* tkImgPhInstance.c in Sources */ = {isa = PBXBuildFile; fileRef = F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */; };
		F92EE8D30E62F939001A6E80 /* tkImgPhInstance.c in Sources */ = {isa = PBXBuildFile; fileRef = F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */; };
		F93599B30DF1F75400E04F67 /* tclOO.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B20DF1F75400E04F67 /* tclOO.c */; };
		F93599B70DF1F76100E04F67 /* tclOOBasic.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B60DF1F76100E04F67 /* tclOOBasic.c */; };
		F93599B90DF1F76600E04F67 /* tclOOCall.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B80DF1F76600E04F67 /* tclOOCall.c */; };
		F93599BC0DF1F77000E04F67 /* tclOODefineCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599BB0DF1F77000E04F67 /* tclOODefineCmds.c */; };
		F93599BE0DF1F77400E04F67 /* tclOOInfo.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599BD0DF1F77400E04F67 /* tclOOInfo.c */; };
		F93599C20DF1F78300E04F67 /* tclOOMethod.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C10DF1F78300E04F67 /* tclOOMethod.c */; };
		F93599C40DF1F78800E04F67 /* tclOOStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C30DF1F78800E04F67 /* tclOOStubInit.c */; };
		F93599C60DF1F78D00E04F67 /* tclOOStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C50DF1F78D00E04F67 /* tclOOStubLib.c */; };
		F94523A20E6FC2AC00C1D987 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F94523A10E6FC2AC00C1D987 /* Cocoa.framework */; };
		F95D77EA0DFD820D00A8BF6F /* tclIORTrans.c in Sources */ = {isa = PBXBuildFile; fileRef = F95D77E90DFD820D00A8BF6F /* tclIORTrans.c */; };
		F96437CA0EF0D4B2003F468E /* tclZlib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96437C90EF0D4B2003F468E /* tclZlib.c */; };
		F96437CB0EF0D4B2003F468E /* tclZlib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96437C90EF0D4B2003F468E /* tclZlib.c */; };
		F96437E70EF0D652003F468E /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F96437E60EF0D652003F468E /* libz.dylib */; };
		F96437E80EF0D652003F468E /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F96437E60EF0D652003F468E /* libz.dylib */; };
		F966BDCF08F27A3F005CB29B /* tk3d.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAC08F27A39005CB29B /* tk3d.c */; };
		F966BDD108F27A3F005CB29B /* tkArgv.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAE08F27A39005CB29B /* tkArgv.c */; };
		F966BDD208F27A3F005CB29B /* tkAtom.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAF08F27A39005CB29B /* tkAtom.c */; };
		F966BDD308F27A3F005CB29B /* tkBind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB008F27A39005CB29B /* tkBind.c */; };
		F966BDD408F27A3F005CB29B /* tkBitmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB108F27A39005CB29B /* tkBitmap.c */; };
		F966BDD508F27A3F005CB29B /* tkButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB208F27A39005CB29B /* tkButton.c */; };
		F966BDD708F27A3F005CB29B /* tkCanvArc.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB408F27A39005CB29B /* tkCanvArc.c */; };
		F966BDD808F27A3F005CB29B /* tkCanvas.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB508F27A39005CB29B /* tkCanvas.c */; };
		F966BDDA08F27A3F005CB29B /* tkCanvBmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB708F27A39005CB29B /* tkCanvBmap.c */; };
		F966BDDB08F27A3F005CB29B /* tkCanvImg.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB808F27A39005CB29B /* tkCanvImg.c */; };
		F966BDDC08F27A3F005CB29B /* tkCanvLine.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB908F27A39005CB29B /* tkCanvLine.c */; };
		F966BDDD08F27A3F005CB29B /* tkCanvPoly.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABA08F27A39005CB29B /* tkCanvPoly.c */; };
		F966BDDE08F27A3F005CB29B /* tkCanvPs.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABB08F27A39005CB29B /* tkCanvPs.c */; };
		F966BDE008F27A3F005CB29B /* tkCanvText.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABD08F27A39005CB29B /* tkCanvText.c */; };
		F966BDE108F27A3F005CB29B /* tkCanvUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABE08F27A39005CB29B /* tkCanvUtil.c */; };
		F966BDE208F27A3F005CB29B /* tkCanvWind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABF08F27A39005CB29B /* tkCanvWind.c */; };
		F966BDE308F27A3F005CB29B /* tkClipboard.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC008F27A39005CB29B /* tkClipboard.c */; };
		F966BDE408F27A3F005CB29B /* tkCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC108F27A39005CB29B /* tkCmds.c */; };
		F966BDE508F27A3F005CB29B /* tkColor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC208F27A39005CB29B /* tkColor.c */; };
		F966BDE708F27A3F005CB29B /* tkConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC408F27A39005CB29B /* tkConfig.c */; };
		F966BDE808F27A3F005CB29B /* tkConsole.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC508F27A39005CB29B /* tkConsole.c */; };
		F966BDE908F27A3F005CB29B /* tkCursor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC608F27A39005CB29B /* tkCursor.c */; };
		F966BDEB08F27A3F005CB29B /* tkEntry.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC808F27A39005CB29B /* tkEntry.c */; };
		F966BDED08F27A3F005CB29B /* tkError.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACA08F27A39005CB29B /* tkError.c */; };
		F966BDEE08F27A3F005CB29B /* tkEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACB08F27A39005CB29B /* tkEvent.c */; };
		F966BDEF08F27A3F005CB29B /* tkFileFilter.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACC08F27A39005CB29B /* tkFileFilter.c */; };
		F966BDF108F27A3F005CB29B /* tkFocus.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACE08F27A39005CB29B /* tkFocus.c */; };
		F966BDF208F27A3F005CB29B /* tkFont.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACF08F27A39005CB29B /* tkFont.c */; };
		F966BDF408F27A3F005CB29B /* tkFrame.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD108F27A39005CB29B /* tkFrame.c */; };
		F966BDF508F27A3F005CB29B /* tkGC.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD208F27A39005CB29B /* tkGC.c */; };
		F966BDF608F27A3F005CB29B /* tkGeometry.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD308F27A39005CB29B /* tkGeometry.c */; };
		F966BDF708F27A3F005CB29B /* tkGet.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD408F27A39005CB29B /* tkGet.c */; };
		F966BDF808F27A3F005CB29B /* tkGrab.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD508F27A39005CB29B /* tkGrab.c */; };
		F966BDF908F27A3F005CB29B /* tkGrid.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD608F27A39005CB29B /* tkGrid.c */; };
		F966BDFA08F27A3F005CB29B /* tkImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD708F27A39005CB29B /* tkImage.c */; };
		F966BDFB08F27A3F005CB29B /* tkImgBmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD808F27A39005CB29B /* tkImgBmap.c */; };
		F966BDFC08F27A3F005CB29B /* tkImgGIF.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD908F27A39005CB29B /* tkImgGIF.c */; };
		F966BDFD08F27A3F005CB29B /* tkImgPhoto.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BADA08F27A39005CB29B /* tkImgPhoto.c */; };
		F966BDFE08F27A3F005CB29B /* tkImgPPM.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BADB08F27A39005CB29B /* tkImgPPM.c */; };
		F966BE0708F27A3F005CB29B /* tkListbox.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE408F27A39005CB29B /* tkListbox.c */; };
		F966BE0808F27A3F005CB29B /* tkMacWinMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE508F27A39005CB29B /* tkMacWinMenu.c */; };
		F966BE0908F27A3F005CB29B /* tkMain.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE608F27A39005CB29B /* tkMain.c */; };
		F966BE0A08F27A3F005CB29B /* tkMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE708F27A39005CB29B /* tkMenu.c */; };
		F966BE0C08F27A3F005CB29B /* tkMenubutton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE908F27A39005CB29B /* tkMenubutton.c */; };
		F966BE0E08F27A3F005CB29B /* tkMenuDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEB08F27A39005CB29B /* tkMenuDraw.c */; };
		F966BE0F08F27A3F005CB29B /* tkMessage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEC08F27A39005CB29B /* tkMessage.c */; };
		F966BE1008F27A3F005CB29B /* tkObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAED08F27A39005CB29B /* tkObj.c */; };
		F966BE1108F27A3F005CB29B /* tkOldConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEE08F27A39005CB29B /* tkOldConfig.c */; };
		F966BE1208F27A3F005CB29B /* tkOption.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEF08F27A39005CB29B /* tkOption.c */; };
		F966BE1308F27A3F005CB29B /* tkPack.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF008F27A39005CB29B /* tkPack.c */; };
		F966BE1408F27A3F005CB29B /* tkPanedWindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF108F27A39005CB29B /* tkPanedWindow.c */; };
		F966BE1508F27A3F005CB29B /* tkPlace.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF208F27A39005CB29B /* tkPlace.c */; };
		F966BE1708F27A3F005CB29B /* tkPointer.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF408F27A39005CB29B /* tkPointer.c */; };
		F966BE1908F27A3F005CB29B /* tkRectOval.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF608F27A39005CB29B /* tkRectOval.c */; };
		F966BE1A08F27A3F005CB29B /* tkScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF708F27A39005CB29B /* tkScale.c */; };
		F966BE1C08F27A40005CB29B /* tkScrollbar.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF908F27A39005CB29B /* tkScrollbar.c */; };
		F966BE1E08F27A40005CB29B /* tkSelect.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFB08F27A39005CB29B /* tkSelect.c */; };
		F966BE2008F27A40005CB29B /* tkSquare.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFD08F27A39005CB29B /* tkSquare.c */; };
		F966BE2208F27A40005CB29B /* tkStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFF08F27A39005CB29B /* tkStubInit.c */; };
		F966BE2308F27A40005CB29B /* tkStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0008F27A39005CB29B /* tkStubLib.c */; };
		F966BE2408F27A40005CB29B /* tkStyle.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0108F27A39005CB29B /* tkStyle.c */; };
		F966BE2508F27A40005CB29B /* tkTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0208F27A39005CB29B /* tkTest.c */; };
		F966BE2608F27A40005CB29B /* tkText.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0308F27A39005CB29B /* tkText.c */; };
		F966BE2808F27A40005CB29B /* tkTextBTree.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0508F27A39005CB29B /* tkTextBTree.c */; };
		F966BE2908F27A40005CB29B /* tkTextDisp.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0608F27A39005CB29B /* tkTextDisp.c */; };
		F966BE2B08F27A40005CB29B /* tkTextImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0808F27A39005CB29B /* tkTextImage.c */; };
		F966BE2C08F27A40005CB29B /* tkTextIndex.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0908F27A39005CB29B /* tkTextIndex.c */; };
		F966BE2D08F27A40005CB29B /* tkTextMark.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0A08F27A39005CB29B /* tkTextMark.c */; };
		F966BE2E08F27A40005CB29B /* tkTextTag.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0B08F27A39005CB29B /* tkTextTag.c */; };
		F966BE2F08F27A40005CB29B /* tkTextWind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0C08F27A39005CB29B /* tkTextWind.c */; };
		F966BE3008F27A40005CB29B /* tkTrig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0D08F27A39005CB29B /* tkTrig.c */; };
		F966BE3108F27A40005CB29B /* tkUndo.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0E08F27A39005CB29B /* tkUndo.c */; };
		F966BE3308F27A40005CB29B /* tkUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1008F27A39005CB29B /* tkUtil.c */; };
		F966BE3408F27A40005CB29B /* tkVisual.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1108F27A39005CB29B /* tkVisual.c */; };
		F966BE3508F27A40005CB29B /* tkWindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1208F27A39005CB29B /* tkWindow.c */; };
		F966BEDB08F27A40005CB29B /* tkMacOSXBitmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBC508F27A3B005CB29B /* tkMacOSXBitmap.c */; };
		F966BEDC08F27A40005CB29B /* tkMacOSXButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBC608F27A3B005CB29B /* tkMacOSXButton.c */; };
		F966BEDE08F27A40005CB29B /* tkMacOSXClipboard.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBC808F27A3B005CB29B /* tkMacOSXClipboard.c */; };
		F966BEDF08F27A40005CB29B /* tkMacOSXColor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBC908F27A3B005CB29B /* tkMacOSXColor.c */; };
		F966BEE008F27A40005CB29B /* tkMacOSXConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBCA08F27A3B005CB29B /* tkMacOSXConfig.c */; };
		F966BEE108F27A40005CB29B /* tkMacOSXCursor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBCB08F27A3B005CB29B /* tkMacOSXCursor.c */; };
		F966BEE308F27A40005CB29B /* tkMacOSXDebug.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBCD08F27A3B005CB29B /* tkMacOSXDebug.c */; };
		F966BEE608F27A40005CB29B /* tkMacOSXDialog.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD008F27A3B005CB29B /* tkMacOSXDialog.c */; };
		F966BEE708F27A40005CB29B /* tkMacOSXDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD108F27A3B005CB29B /* tkMacOSXDraw.c */; };
		F966BEE808F27A40005CB29B /* tkMacOSXEmbed.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD208F27A3B005CB29B /* tkMacOSXEmbed.c */; };
		F966BEE908F27A40005CB29B /* tkMacOSXEntry.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD308F27A3B005CB29B /* tkMacOSXEntry.c */; };
		F966BEEA08F27A40005CB29B /* tkMacOSXEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD408F27A3B005CB29B /* tkMacOSXEvent.c */; };
		F966BEEC08F27A40005CB29B /* tkMacOSXFont.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD608F27A3B005CB29B /* tkMacOSXFont.c */; };
		F966BEED08F27A40005CB29B /* tkMacOSXHLEvents.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD708F27A3B005CB29B /* tkMacOSXHLEvents.c */; };
		F966BEEE08F27A40005CB29B /* tkMacOSXInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBD808F27A3B005CB29B /* tkMacOSXInit.c */; settings = {COMPILER_FLAGS = "-DTK_LIBRARY=\\\"$(TK_LIBRARY)\\\""; }; };
		F966BEF108F27A40005CB29B /* tkMacOSXKeyboard.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBDB08F27A3B005CB29B /* tkMacOSXKeyboard.c */; };
		F966BEF208F27A40005CB29B /* tkMacOSXKeyEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBDC08F27A3B005CB29B /* tkMacOSXKeyEvent.c */; };
		F966BEF308F27A40005CB29B /* tkMacOSXMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBDD08F27A3B005CB29B /* tkMacOSXMenu.c */; };
		F966BEF608F27A40005CB29B /* tkMacOSXMenubutton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBE008F27A3B005CB29B /* tkMacOSXMenubutton.c */; };
		F966BEF708F27A40005CB29B /* tkMacOSXMenus.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBE108F27A3B005CB29B /* tkMacOSXMenus.c */; };
		F966BEF808F27A40005CB29B /* tkMacOSXMouseEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBE208F27A3B005CB29B /* tkMacOSXMouseEvent.c */; };
		F966BEF908F27A40005CB29B /* tkMacOSXNotify.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBE308F27A3B005CB29B /* tkMacOSXNotify.c */; };
		F966BF0108F27A40005CB29B /* tkMacOSXRegion.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBEB08F27A3C005CB29B /* tkMacOSXRegion.c */; };
		F966BF0308F27A40005CB29B /* tkMacOSXScrlbr.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBED08F27A3C005CB29B /* tkMacOSXScrlbr.c */; };
		F966BF0408F27A40005CB29B /* tkMacOSXSend.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBEE08F27A3C005CB29B /* tkMacOSXSend.c */; };
		F966BF0508F27A40005CB29B /* tkMacOSXSubwindows.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBEF08F27A3C005CB29B /* tkMacOSXSubwindows.c */; };
		F966BF0608F27A40005CB29B /* tkMacOSXTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBF008F27A3C005CB29B /* tkMacOSXTest.c */; };
		F966BF0708F27A40005CB29B /* tkMacOSXWindowEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBF108F27A3C005CB29B /* tkMacOSXWindowEvent.c */; };
		F966BF0808F27A40005CB29B /* tkMacOSXWm.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBF208F27A3C005CB29B /* tkMacOSXWm.c */; };
		F966BF0B08F27A40005CB29B /* tkMacOSXXStubs.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BBF508F27A3C005CB29B /* tkMacOSXXStubs.c */; };
		F966BF7F08F27A41005CB29B /* tkAppInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7508F27A3D005CB29B /* tkAppInit.c */; settings = {COMPILER_FLAGS = "-DTK_TEST"; }; };
		F966BF8308F27A41005CB29B /* tkUnix3d.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7908F27A3D005CB29B /* tkUnix3d.c */; };
		F966BF9608F27A41005CB29B /* tkUnixScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8C08F27A3D005CB29B /* tkUnixScale.c */; };
		F966C02A08F27A42005CB29B /* xcolors.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BD2408F27A3F005CB29B /* xcolors.c */; };
		F966C02B08F27A42005CB29B /* xdraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BD2508F27A3F005CB29B /* xdraw.c */; };
		F966C02C08F27A42005CB29B /* xgc.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BD2608F27A3F005CB29B /* xgc.c */; };
		F966C02D08F27A42005CB29B /* ximage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BD2708F27A3F005CB29B /* ximage.c */; };
		F966C02E08F27A42005CB29B /* xutil.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BD2808F27A3F005CB29B /* xutil.c */; };
		F966C07508F2820D005CB29B /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F966C07408F2820D005CB29B /* CoreFoundation.framework */; };
		F966C07708F2821B005CB29B /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F966C07608F2821B005CB29B /* Carbon.framework */; };
		F966C07908F28233005CB29B /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F966C07808F28233005CB29B /* IOKit.framework */; };
		F96888050AF786D5000797B5 /* ttkBlink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E10AF786D5000797B5 /* ttkBlink.c */; };
		F96888060AF786D5000797B5 /* ttkButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E20AF786D5000797B5 /* ttkButton.c */; };
		F96888070AF786D5000797B5 /* ttkCache.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E30AF786D5000797B5 /* ttkCache.c */; };
		F96888080AF786D5000797B5 /* ttkClamTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E40AF786D5000797B5 /* ttkClamTheme.c */; };
		F96888090AF786D5000797B5 /* ttkClassicTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E50AF786D5000797B5 /* ttkClassicTheme.c */; };
		F968880A0AF786D5000797B5 /* ttkDefaultTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E70AF786D5000797B5 /* ttkDefaultTheme.c */; };
		F968880B0AF786D5000797B5 /* ttkElements.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E80AF786D5000797B5 /* ttkElements.c */; };
		F968880C0AF786D5000797B5 /* ttkEntry.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E90AF786D5000797B5 /* ttkEntry.c */; };
		F968880D0AF786D5000797B5 /* ttkFrame.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EA0AF786D5000797B5 /* ttkFrame.c */; };
		F968880E0AF786D5000797B5 /* ttkImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EB0AF786D5000797B5 /* ttkImage.c */; };
		F968880F0AF786D5000797B5 /* ttkInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EC0AF786D5000797B5 /* ttkInit.c */; };
		F96888100AF786D5000797B5 /* ttkLabel.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887ED0AF786D5000797B5 /* ttkLabel.c */; };
		F96888110AF786D5000797B5 /* ttkLayout.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EE0AF786D5000797B5 /* ttkLayout.c */; };
		F96888120AF786D5000797B5 /* ttkManager.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EF0AF786D5000797B5 /* ttkManager.c */; };
		F96888130AF786D5000797B5 /* ttkNotebook.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F10AF786D5000797B5 /* ttkNotebook.c */; };
		F96888140AF786D5000797B5 /* ttkPanedwindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F20AF786D5000797B5 /* ttkPanedwindow.c */; };
		F96888150AF786D5000797B5 /* ttkProgress.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F30AF786D5000797B5 /* ttkProgress.c */; };
		F96888160AF786D5000797B5 /* ttkScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F40AF786D5000797B5 /* ttkScale.c */; };
		F96888170AF786D5000797B5 /* ttkScroll.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F50AF786D5000797B5 /* ttkScroll.c */; };
		F96888180AF786D5000797B5 /* ttkScrollbar.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F60AF786D5000797B5 /* ttkScrollbar.c */; };
		F96888190AF786D5000797B5 /* ttkSeparator.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F70AF786D5000797B5 /* ttkSeparator.c */; };
		F968881A0AF786D5000797B5 /* ttkSquare.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F80AF786D5000797B5 /* ttkSquare.c */; };
		F968881B0AF786D5000797B5 /* ttkState.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F90AF786D5000797B5 /* ttkState.c */; };
		F968881C0AF786D5000797B5 /* ttkStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FA0AF786D5000797B5 /* ttkStubInit.c */; };
		F968881D0AF786D5000797B5 /* ttkStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FB0AF786D5000797B5 /* ttkStubLib.c */; };
		F968881E0AF786D5000797B5 /* ttkTagSet.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FC0AF786D5000797B5 /* ttkTagSet.c */; };
		F968881F0AF786D5000797B5 /* ttkTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FD0AF786D5000797B5 /* ttkTheme.c */; };
		F96888200AF786D5000797B5 /* ttkTrace.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888000AF786D5000797B5 /* ttkTrace.c */; };
		F96888210AF786D5000797B5 /* ttkTrack.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888010AF786D5000797B5 /* ttkTrack.c */; };
		F96888220AF786D5000797B5 /* ttkTreeview.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888020AF786D5000797B5 /* ttkTreeview.c */; };
		F96888230AF786D5000797B5 /* ttkWidget.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888030AF786D5000797B5 /* ttkWidget.c */; };
		F96888850AF78938000797B5 /* ttkMacOSXTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888840AF78938000797B5 /* ttkMacOSXTheme.c */; };
		F96D456F08F272BB004A47F5 /* regcomp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED008F272A7004A47F5 /* regcomp.c */; };
		F96D457208F272BB004A47F5 /* regerror.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED308F272A7004A47F5 /* regerror.c */; };
		F96D457508F272BB004A47F5 /* regexec.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED608F272A7004A47F5 /* regexec.c */; };
		F96D457608F272BB004A47F5 /* regfree.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED708F272A7004A47F5 /* regfree.c */; };
		F96D457B08F272BB004A47F5 /* tclAlloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDC08F272A7004A47F5 /* tclAlloc.c */; settings = {COMPILER_FLAGS = "-DUSE_TCLALLOC=0"; }; };
		F96D457C08F272BB004A47F5 /* tclAsync.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDD08F272A7004A47F5 /* tclAsync.c */; };
		F96D457D08F272BB004A47F5 /* tclBasic.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDE08F272A7004A47F5 /* tclBasic.c */; };
		F96D457E08F272BC004A47F5 /* tclBinary.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDF08F272A7004A47F5 /* tclBinary.c */; };
		F96D457F08F272BC004A47F5 /* tclCkalloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE008F272A7004A47F5 /* tclCkalloc.c */; };
		F96D458008F272BC004A47F5 /* tclClock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE108F272A7004A47F5 /* tclClock.c */; };
		F96D458108F272BC004A47F5 /* tclCmdAH.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE208F272A7004A47F5 /* tclCmdAH.c */; };
		F96D458208F272BC004A47F5 /* tclCmdIL.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE308F272A7004A47F5 /* tclCmdIL.c */; };
		F96D458308F272BC004A47F5 /* tclCmdMZ.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE408F272A7004A47F5 /* tclCmdMZ.c */; };
		F96D458408F272BC004A47F5 /* tclCompCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE508F272A7004A47F5 /* tclCompCmds.c */; };
		F96D458508F272BC004A47F5 /* tclCompExpr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE608F272A7004A47F5 /* tclCompExpr.c */; };
		F96D458608F272BC004A47F5 /* tclCompile.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE708F272A7004A47F5 /* tclCompile.c */; };
		F96D458808F272BC004A47F5 /* tclConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE908F272A7004A47F5 /* tclConfig.c */; };
		F96D458908F272BC004A47F5 /* tclDate.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEA08F272A7004A47F5 /* tclDate.c */; };
		F96D458B08F272BC004A47F5 /* tclDictObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEC08F272A7004A47F5 /* tclDictObj.c */; };
		F96D458C08F272BC004A47F5 /* tclEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EED08F272A7004A47F5 /* tclEncoding.c */; };
		F96D458D08F272BC004A47F5 /* tclEnv.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEE08F272A7004A47F5 /* tclEnv.c */; };
		F96D458E08F272BC004A47F5 /* tclEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEF08F272A7004A47F5 /* tclEvent.c */; };
		F96D458F08F272BC004A47F5 /* tclExecute.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF008F272A7004A47F5 /* tclExecute.c */; };
		F96D459008F272BC004A47F5 /* tclFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF108F272A7004A47F5 /* tclFCmd.c */; };
		F96D459108F272BC004A47F5 /* tclFileName.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF208F272A7004A47F5 /* tclFileName.c */; };
		F96D459308F272BC004A47F5 /* tclGet.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF408F272A7004A47F5 /* tclGet.c */; };
		F96D459508F272BC004A47F5 /* tclHash.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF608F272A7004A47F5 /* tclHash.c */; };
		F96D459608F272BC004A47F5 /* tclHistory.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF708F272A7004A47F5 /* tclHistory.c */; };
		F96D459708F272BC004A47F5 /* tclIndexObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF808F272A7004A47F5 /* tclIndexObj.c */; };
		F96D459B08F272BC004A47F5 /* tclInterp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EFC08F272A7004A47F5 /* tclInterp.c */; };
		F96D459D08F272BC004A47F5 /* tclIO.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EFE08F272A7004A47F5 /* tclIO.c */; };
		F96D459F08F272BC004A47F5 /* tclIOCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0008F272A7004A47F5 /* tclIOCmd.c */; };
		F96D45A008F272BC004A47F5 /* tclIOGT.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0108F272A7004A47F5 /* tclIOGT.c */; };
		F96D45A108F272BC004A47F5 /* tclIORChan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0208F272A7004A47F5 /* tclIORChan.c */; };
		F96D45A208F272BC004A47F5 /* tclIOSock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0308F272A7004A47F5 /* tclIOSock.c */; };
		F96D45A308F272BC004A47F5 /* tclIOUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0408F272A7004A47F5 /* tclIOUtil.c */; };
		F96D45A408F272BC004A47F5 /* tclLink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0508F272A7004A47F5 /* tclLink.c */; };
		F96D45A508F272BC004A47F5 /* tclListObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0608F272A7004A47F5 /* tclListObj.c */; };
		F96D45A608F272BC004A47F5 /* tclLiteral.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0708F272A7004A47F5 /* tclLiteral.c */; };
		F96D45A708F272BC004A47F5 /* tclLoad.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0808F272A7004A47F5 /* tclLoad.c */; };
		F96D45A908F272BC004A47F5 /* tclMain.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0A08F272A7004A47F5 /* tclMain.c */; };
		F96D45AA08F272BC004A47F5 /* tclNamesp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0B08F272A7004A47F5 /* tclNamesp.c */; };
		F96D45AB08F272BC004A47F5 /* tclNotify.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0C08F272A7004A47F5 /* tclNotify.c */; };
		F96D45AC08F272BC004A47F5 /* tclObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0D08F272A7004A47F5 /* tclObj.c */; };
		F96D45AD08F272BC004A47F5 /* tclPanic.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0E08F272A7004A47F5 /* tclPanic.c */; };
		F96D45AE08F272BC004A47F5 /* tclParse.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0F08F272A7004A47F5 /* tclParse.c */; };
		F96D45B008F272BC004A47F5 /* tclPathObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1108F272A7004A47F5 /* tclPathObj.c */; };
		F96D45B108F272BC004A47F5 /* tclPipe.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1208F272A7004A47F5 /* tclPipe.c */; };
		F96D45B208F272BC004A47F5 /* tclPkg.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1308F272A7004A47F5 /* tclPkg.c */; };
		F96D45B308F272BC004A47F5 /* tclPkgConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1408F272A7004A47F5 /* tclPkgConfig.c */; settings = {COMPILER_FLAGS = "-DCFG_INSTALL_LIBDIR=\\\"$(LIBDIR)\\\" -DCFG_INSTALL_BINDIR=\\\"$(BINDIR)\\\" -DCFG_INSTALL_SCRDIR=\\\"$(TCL_LIBRARY)\\\" -DCFG_INSTALL_INCDIR=\\\"$(INCLUDEDIR)\\\" -DCFG_INSTALL_DOCDIR=\\\"$(MANDIR)\\\" -DCFG_RUNTIME_LIBDIR=\\\"$(LIBDIR)\\\" -DCFG_RUNTIME_BINDIR=\\\"$(BINDIR)\\\" -DCFG_RUNTIME_SCRDIR=\\\"$(TCL_LIBRARY)\\\" -DCFG_RUNTIME_INCDIR=\\\"$(INCLUDEDIR)\\\" -DCFG_RUNTIME_DOCDIR=\\\"$(MANDIR)\\\""; }; };
		F96D45B608F272BC004A47F5 /* tclPosixStr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1708F272A7004A47F5 /* tclPosixStr.c */; };
		F96D45B708F272BC004A47F5 /* tclPreserve.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1808F272A7004A47F5 /* tclPreserve.c */; };
		F96D45B808F272BC004A47F5 /* tclProc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1908F272A7004A47F5 /* tclProc.c */; };
		F96D45B908F272BC004A47F5 /* tclRegexp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1A08F272A7004A47F5 /* tclRegexp.c */; };
		F96D45BB08F272BC004A47F5 /* tclResolve.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1C08F272A7004A47F5 /* tclResolve.c */; };
		F96D45BC08F272BC004A47F5 /* tclResult.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1D08F272A7004A47F5 /* tclResult.c */; };
		F96D45BD08F272BC004A47F5 /* tclScan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1E08F272A7004A47F5 /* tclScan.c */; };
		F96D45BE08F272BC004A47F5 /* tclStringObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1F08F272A7004A47F5 /* tclStringObj.c */; };
		F96D45C308F272BC004A47F5 /* tclStrToD.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2408F272A7004A47F5 /* tclStrToD.c */; };
		F96D45C408F272BC004A47F5 /* tclStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2508F272A7004A47F5 /* tclStubInit.c */; };
		F96D45C508F272BC004A47F5 /* tclStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2608F272A7004A47F5 /* tclStubLib.c */; };
		F96D45C908F272BC004A47F5 /* tclThread.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2A08F272A7004A47F5 /* tclThread.c */; };
		F96D45CA08F272BC004A47F5 /* tclThreadAlloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */; };
		F96D45CB08F272BC004A47F5 /* tclThreadJoin.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */; };
		F96D45CC08F272BC004A47F5 /* tclThreadStorage.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */; };
		F96D45CE08F272BC004A47F5 /* tclTimer.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2F08F272A7004A47F5 /* tclTimer.c */; };
		F96D45D008F272BC004A47F5 /* tclTomMathInterface.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */; };
		F96D45D108F272BC004A47F5 /* tclTrace.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3208F272A7004A47F5 /* tclTrace.c */; };
		F96D45D308F272BC004A47F5 /* tclUtf.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3408F272A7004A47F5 /* tclUtf.c */; };
		F96D45D408F272BC004A47F5 /* tclUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3508F272A7004A47F5 /* tclUtil.c */; };
		F96D45D508F272BC004A47F5 /* tclVar.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3608F272A7004A47F5 /* tclVar.c */; };
		F96D48E208F272C3004A47F5 /* bn_fast_s_mp_mul_digs.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426408F272B3004A47F5 /* bn_fast_s_mp_mul_digs.c */; };
		F96D48E408F272C3004A47F5 /* bn_fast_s_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426608F272B3004A47F5 /* bn_fast_s_mp_sqr.c */; };
		F96D48E708F272C3004A47F5 /* bn_mp_add.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426908F272B3004A47F5 /* bn_mp_add.c */; };
		F96D48E808F272C3004A47F5 /* bn_mp_add_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426A08F272B3004A47F5 /* bn_mp_add_d.c */; };
		F96D48EB08F272C3004A47F5 /* bn_mp_clamp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426D08F272B3004A47F5 /* bn_mp_clamp.c */; };
		F96D48EC08F272C3004A47F5 /* bn_mp_clear.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426E08F272B3004A47F5 /* bn_mp_clear.c */; };
		F96D48ED08F272C3004A47F5 /* bn_mp_clear_multi.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426F08F272B3004A47F5 /* bn_mp_clear_multi.c */; };
		F96D48EE08F272C3004A47F5 /* bn_mp_cmp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427008F272B3004A47F5 /* bn_mp_cmp.c */; };
		F96D48F008F272C3004A47F5 /* bn_mp_cmp_mag.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427208F272B3004A47F5 /* bn_mp_cmp_mag.c */; };
		F96D48F208F272C3004A47F5 /* bn_mp_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427408F272B3004A47F5 /* bn_mp_copy.c */; };
		F96D48F308F272C3004A47F5 /* bn_mp_count_bits.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427508F272B3004A47F5 /* bn_mp_count_bits.c */; };
		F96D48F408F272C3004A47F5 /* bn_mp_div.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427608F272B3004A47F5 /* bn_mp_div.c */; };
		F96D48F508F272C3004A47F5 /* bn_mp_div_2.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427708F272B3004A47F5 /* bn_mp_div_2.c */; };
		F96D48F608F272C3004A47F5 /* bn_mp_div_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427808F272B3004A47F5 /* bn_mp_div_2d.c */; };
		F96D48F708F272C3004A47F5 /* bn_mp_div_3.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427908F272B3004A47F5 /* bn_mp_div_3.c */; };
		F96D48F808F272C3004A47F5 /* bn_mp_div_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427A08F272B3004A47F5 /* bn_mp_div_d.c */; };
		F96D48FC08F272C3004A47F5 /* bn_mp_exch.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427E08F272B3004A47F5 /* bn_mp_exch.c */; };
		F96D490508F272C3004A47F5 /* bn_mp_grow.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428708F272B3004A47F5 /* bn_mp_grow.c */; };
		F96D490608F272C3004A47F5 /* bn_mp_init.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428808F272B3004A47F5 /* bn_mp_init.c */; };
		F96D490708F272C3004A47F5 /* bn_mp_init_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428908F272B3004A47F5 /* bn_mp_init_copy.c */; };
		F96D490808F272C3004A47F5 /* bn_mp_init_multi.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428A08F272B3004A47F5 /* bn_mp_init_multi.c */; };
		F96D490908F272C3004A47F5 /* bn_mp_init_set.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428B08F272B3004A47F5 /* bn_mp_init_set.c */; };
		F96D490B08F272C3004A47F5 /* bn_mp_init_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428D08F272B3004A47F5 /* bn_mp_init_size.c */; };
		F96D491008F272C3004A47F5 /* bn_mp_karatsuba_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429208F272B3004A47F5 /* bn_mp_karatsuba_mul.c */; };
		F96D491108F272C3004A47F5 /* bn_mp_karatsuba_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429308F272B3004A47F5 /* bn_mp_karatsuba_sqr.c */; };
		F96D491308F272C3004A47F5 /* bn_mp_lshd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429508F272B3004A47F5 /* bn_mp_lshd.c */; };
		F96D491408F272C3004A47F5 /* bn_mp_mod.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429608F272B3004A47F5 /* bn_mp_mod.c */; };
		F96D491508F272C3004A47F5 /* bn_mp_mod_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429708F272B3004A47F5 /* bn_mp_mod_2d.c */; };
		F96D491A08F272C3004A47F5 /* bn_mp_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429C08F272B3004A47F5 /* bn_mp_mul.c */; };
		F96D491B08F272C3004A47F5 /* bn_mp_mul_2.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429D08F272B3004A47F5 /* bn_mp_mul_2.c */; };
		F96D491C08F272C3004A47F5 /* bn_mp_mul_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429E08F272B3004A47F5 /* bn_mp_mul_2d.c */; };
		F96D491D08F272C3004A47F5 /* bn_mp_mul_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429F08F272B3004A47F5 /* bn_mp_mul_d.c */; };
		F96D492908F272C3004A47F5 /* bn_mp_radix_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AB08F272B3004A47F5 /* bn_mp_radix_size.c */; };
		F96D492A08F272C3004A47F5 /* bn_mp_radix_smap.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AC08F272B3004A47F5 /* bn_mp_radix_smap.c */; };
		F96D492C08F272C3004A47F5 /* bn_mp_read_radix.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AE08F272B3004A47F5 /* bn_mp_read_radix.c */; };
		F96D493708F272C3004A47F5 /* bn_mp_rshd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42B908F272B3004A47F5 /* bn_mp_rshd.c */; };
		F96D493808F272C3004A47F5 /* bn_mp_set.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BA08F272B3004A47F5 /* bn_mp_set.c */; };
		F96D493C08F272C3004A47F5 /* bn_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BE08F272B3004A47F5 /* bn_mp_sqr.c */; };
		F96D493F08F272C3004A47F5 /* bn_mp_sub.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C108F272B3004A47F5 /* bn_mp_sub.c */; };
		F96D494008F272C3004A47F5 /* bn_mp_sub_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C208F272B3004A47F5 /* bn_mp_sub_d.c */; };
		F96D494608F272C3004A47F5 /* bn_mp_toom_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C808F272B3004A47F5 /* bn_mp_toom_mul.c */; };
		F96D494708F272C3004A47F5 /* bn_mp_toom_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C908F272B3004A47F5 /* bn_mp_toom_sqr.c */; };
		F96D494908F272C3004A47F5 /* bn_mp_toradix_n.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CB08F272B3004A47F5 /* bn_mp_toradix_n.c */; };
		F96D494C08F272C3004A47F5 /* bn_mp_zero.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CE08F272B3004A47F5 /* bn_mp_zero.c */; };
		F96D494E08F272C3004A47F5 /* bn_reverse.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D008F272B3004A47F5 /* bn_reverse.c */; };
		F96D494F08F272C3004A47F5 /* bn_s_mp_add.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D108F272B3004A47F5 /* bn_s_mp_add.c */; };
		F96D495108F272C3004A47F5 /* bn_s_mp_mul_digs.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D308F272B3004A47F5 /* bn_s_mp_mul_digs.c */; };
		F96D495308F272C3004A47F5 /* bn_s_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D508F272B3004A47F5 /* bn_s_mp_sqr.c */; };
		F96D495408F272C3004A47F5 /* bn_s_mp_sub.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D608F272B3004A47F5 /* bn_s_mp_sub.c */; };
		F96D495508F272C3004A47F5 /* bncore.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D708F272B3004A47F5 /* bncore.c */; };
		F96D49A908F272C4004A47F5 /* tclMacOSXBundle.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433908F272B5004A47F5 /* tclMacOSXBundle.c */; };
		F96D49AD08F272C4004A47F5 /* tclMacOSXFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433D08F272B5004A47F5 /* tclMacOSXFCmd.c */; };
		F96D49AE08F272C4004A47F5 /* tclMacOSXNotify.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433E08F272B5004A47F5 /* tclMacOSXNotify.c */; };
		F96D4AC608F272C9004A47F5 /* tclLoadDyld.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D445B08F272B9004A47F5 /* tclLoadDyld.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
		F96D4ACA08F272C9004A47F5 /* tclUnixChan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D445F08F272B9004A47F5 /* tclUnixChan.c */; };
		F96D4ACB08F272C9004A47F5 /* tclUnixEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446008F272B9004A47F5 /* tclUnixEvent.c */; };
		F96D4ACC08F272C9004A47F5 /* tclUnixFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446108F272B9004A47F5 /* tclUnixFCmd.c */; };
		F96D4ACD08F272C9004A47F5 /* tclUnixFile.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446208F272B9004A47F5 /* tclUnixFile.c */; };
		F96D4ACE08F272C9004A47F5 /* tclUnixInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446308F272B9004A47F5 /* tclUnixInit.c */; settings = {COMPILER_FLAGS = "-DTCL_LIBRARY=\\\"$(TCL_LIBRARY)\\\" -DTCL_PACKAGE_PATH=\\\"$(TCL_PACKAGE_PATH)\\\""; }; };
		F96D4ACF08F272C9004A47F5 /* tclUnixNotfy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446408F272B9004A47F5 /* tclUnixNotfy.c */; };
		F96D4AD008F272C9004A47F5 /* tclUnixPipe.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446508F272B9004A47F5 /* tclUnixPipe.c */; };
		F96D4AD208F272CA004A47F5 /* tclUnixSock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446708F272B9004A47F5 /* tclUnixSock.c */; };
		F96D4AD408F272CA004A47F5 /* tclUnixThrd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446908F272B9004A47F5 /* tclUnixThrd.c */; };
		F96D4AD608F272CA004A47F5 /* tclUnixTime.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446B08F272B9004A47F5 /* tclUnixTime.c */; };
		F9C9CC000E84059800E00935 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9C9CBFF0E84059800E00935 /* ApplicationServices.framework */; };
		F9DD99BD0F07DF850018B2E4 /* tkImgPNG.c in Sources */ = {isa = PBXBuildFile; fileRef = F9DD99BC0F07DF850018B2E4 /* tkImgPNG.c */; };
		F9DD99BE0F07DF850018B2E4 /* tkImgPNG.c in Sources */ = {isa = PBXBuildFile; fileRef = F9DD99BC0F07DF850018B2E4 /* tkImgPNG.c */; };
		F9E61D28090A481F002B3151 /* bn_mp_cmp_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427108F272B3004A47F5 /* bn_mp_cmp_d.c */; };
		F9E61D29090A486C002B3151 /* bn_mp_neg.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42A208F272B3004A47F5 /* bn_mp_neg.c */; };
		F9E61D2A090A4891002B3151 /* bn_mp_sqrt.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C008F272B3004A47F5 /* bn_mp_sqrt.c */; };
		F9E61D2B090A48A4002B3151 /* bn_mp_and.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426C08F272B3004A47F5 /* bn_mp_and.c */; };
		F9E61D2C090A48AC002B3151 /* bn_mp_expt_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427F08F272B3004A47F5 /* bn_mp_expt_d.c */; };
		F9E61D2D090A48BB002B3151 /* bn_mp_xor.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CD08F272B3004A47F5 /* bn_mp_xor.c */; };
		F9E61D2E090A48BF002B3151 /* bn_mp_or.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42A308F272B3004A47F5 /* bn_mp_or.c */; };
		F9E61D2F090A48C7002B3151 /* bn_mp_shrink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BC08F272B3004A47F5 /* bn_mp_shrink.c */; };
		F9E61D30090A48E2002B3151 /* bn_mp_to_unsigned_bin_n.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C708F272B3004A47F5 /* bn_mp_to_unsigned_bin_n.c */; };
		F9E61D31090A48F9002B3151 /* bn_mp_to_unsigned_bin.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C608F272B3004A47F5 /* bn_mp_to_unsigned_bin.c */; };
		F9E61D32090A48FA002B3151 /* bn_mp_unsigned_bin_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CC08F272B3004A47F5 /* bn_mp_unsigned_bin_size.c */; };
		F9F4415E0C8BAE6F00BCCD67 /* tclDTrace.d in Sources */ = {isa = PBXBuildFile; fileRef = F9F4415D0C8BAE6F00BCCD67 /* tclDTrace.d */; };
		F9FC77B80AB29E9100B7077D /* tclUnixCompat.c in Sources */ = {isa = PBXBuildFile; fileRef = F9FC77B70AB29E9100B7077D /* tclUnixCompat.c */; };
		F9FD30BC0CC1AD070073837D /* regcomp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED008F272A7004A47F5 /* regcomp.c */; };
		F9FD30BD0CC1AD070073837D /* regerror.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED308F272A7004A47F5 /* regerror.c */; };
		F9FD30BE0CC1AD070073837D /* regexec.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED608F272A7004A47F5 /* regexec.c */; };
		F9FD30BF0CC1AD070073837D /* regfree.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3ED708F272A7004A47F5 /* regfree.c */; };
		F9FD30C00CC1AD070073837D /* tclAlloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDC08F272A7004A47F5 /* tclAlloc.c */; settings = {COMPILER_FLAGS = "-DUSE_TCLALLOC=0"; }; };
		F9FD30C10CC1AD070073837D /* tclAsync.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDD08F272A7004A47F5 /* tclAsync.c */; };
		F9FD30C20CC1AD070073837D /* tclBasic.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDE08F272A7004A47F5 /* tclBasic.c */; };
		F9FD30C30CC1AD070073837D /* tclBinary.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EDF08F272A7004A47F5 /* tclBinary.c */; };
		F9FD30C40CC1AD070073837D /* tclCkalloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE008F272A7004A47F5 /* tclCkalloc.c */; };
		F9FD30C50CC1AD070073837D /* tclClock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE108F272A7004A47F5 /* tclClock.c */; };
		F9FD30C60CC1AD070073837D /* tclCmdAH.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE208F272A7004A47F5 /* tclCmdAH.c */; };
		F9FD30C70CC1AD070073837D /* tclCmdIL.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE308F272A7004A47F5 /* tclCmdIL.c */; };
		F9FD30C80CC1AD070073837D /* tclCmdMZ.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE408F272A7004A47F5 /* tclCmdMZ.c */; };
		F9FD30C90CC1AD070073837D /* tclCompCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE508F272A7004A47F5 /* tclCompCmds.c */; };
		F9FD30CA0CC1AD070073837D /* tclCompExpr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE608F272A7004A47F5 /* tclCompExpr.c */; };
		F9FD30CB0CC1AD070073837D /* tclCompile.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE708F272A7004A47F5 /* tclCompile.c */; };
		F9FD30CC0CC1AD070073837D /* tclConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EE908F272A7004A47F5 /* tclConfig.c */; };
		F9FD30CD0CC1AD070073837D /* tclDate.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEA08F272A7004A47F5 /* tclDate.c */; };
		F9FD30CE0CC1AD070073837D /* tclDictObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEC08F272A7004A47F5 /* tclDictObj.c */; };
		F9FD30CF0CC1AD070073837D /* tclEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EED08F272A7004A47F5 /* tclEncoding.c */; };
		F9FD30D00CC1AD070073837D /* tclEnv.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEE08F272A7004A47F5 /* tclEnv.c */; };
		F9FD30D10CC1AD070073837D /* tclEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EEF08F272A7004A47F5 /* tclEvent.c */; };
		F9FD30D20CC1AD070073837D /* tclExecute.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF008F272A7004A47F5 /* tclExecute.c */; };
		F9FD30D30CC1AD070073837D /* tclFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF108F272A7004A47F5 /* tclFCmd.c */; };
		F9FD30D40CC1AD070073837D /* tclFileName.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF208F272A7004A47F5 /* tclFileName.c */; };
		F9FD30D50CC1AD070073837D /* tclGet.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF408F272A7004A47F5 /* tclGet.c */; };
		F9FD30D60CC1AD070073837D /* tclHash.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF608F272A7004A47F5 /* tclHash.c */; };
		F9FD30D70CC1AD070073837D /* tclHistory.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF708F272A7004A47F5 /* tclHistory.c */; };
		F9FD30D80CC1AD070073837D /* tclIndexObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EF808F272A7004A47F5 /* tclIndexObj.c */; };
		F9FD30D90CC1AD070073837D /* tclInterp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EFC08F272A7004A47F5 /* tclInterp.c */; };
		F9FD30DA0CC1AD070073837D /* tclIO.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3EFE08F272A7004A47F5 /* tclIO.c */; };
		F9FD30DB0CC1AD070073837D /* tclIOCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0008F272A7004A47F5 /* tclIOCmd.c */; };
		F9FD30DC0CC1AD070073837D /* tclIOGT.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0108F272A7004A47F5 /* tclIOGT.c */; };
		F9FD30DD0CC1AD070073837D /* tclIORChan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0208F272A7004A47F5 /* tclIORChan.c */; };
		F9FD30DE0CC1AD070073837D /* tclIOSock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0308F272A7004A47F5 /* tclIOSock.c */; };
		F9FD30DF0CC1AD070073837D /* tclIOUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0408F272A7004A47F5 /* tclIOUtil.c */; };
		F9FD30E00CC1AD070073837D /* tclLink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0508F272A7004A47F5 /* tclLink.c */; };
		F9FD30E10CC1AD070073837D /* tclListObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0608F272A7004A47F5 /* tclListObj.c */; };
		F9FD30E20CC1AD070073837D /* tclLiteral.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0708F272A7004A47F5 /* tclLiteral.c */; };
		F9FD30E30CC1AD070073837D /* tclLoad.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0808F272A7004A47F5 /* tclLoad.c */; };
		F9FD30E40CC1AD070073837D /* tclMain.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0A08F272A7004A47F5 /* tclMain.c */; };
		F9FD30E50CC1AD070073837D /* tclNamesp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0B08F272A7004A47F5 /* tclNamesp.c */; };
		F9FD30E60CC1AD070073837D /* tclNotify.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0C08F272A7004A47F5 /* tclNotify.c */; };
		F9FD30E70CC1AD070073837D /* tclObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0D08F272A7004A47F5 /* tclObj.c */; };
		F9FD30E80CC1AD070073837D /* tclPanic.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0E08F272A7004A47F5 /* tclPanic.c */; };
		F9FD30E90CC1AD070073837D /* tclParse.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F0F08F272A7004A47F5 /* tclParse.c */; };
		F9FD30EA0CC1AD070073837D /* tclPathObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1108F272A7004A47F5 /* tclPathObj.c */; };
		F9FD30EB0CC1AD070073837D /* tclPipe.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1208F272A7004A47F5 /* tclPipe.c */; };
		F9FD30EC0CC1AD070073837D /* tclPkg.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1308F272A7004A47F5 /* tclPkg.c */; };
		F9FD30ED0CC1AD070073837D /* tclPkgConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1408F272A7004A47F5 /* tclPkgConfig.c */; settings = {COMPILER_FLAGS = "-DCFG_INSTALL_LIBDIR=\\\"$(LIBDIR)\\\" -DCFG_INSTALL_BINDIR=\\\"$(BINDIR)\\\" -DCFG_INSTALL_SCRDIR=\\\"$(TCL_LIBRARY)\\\" -DCFG_INSTALL_INCDIR=\\\"$(INCLUDEDIR)\\\" -DCFG_INSTALL_DOCDIR=\\\"$(MANDIR)\\\" -DCFG_RUNTIME_LIBDIR=\\\"$(LIBDIR)\\\" -DCFG_RUNTIME_BINDIR=\\\"$(BINDIR)\\\" -DCFG_RUNTIME_SCRDIR=\\\"$(TCL_LIBRARY)\\\" -DCFG_RUNTIME_INCDIR=\\\"$(INCLUDEDIR)\\\" -DCFG_RUNTIME_DOCDIR=\\\"$(MANDIR)\\\""; }; };
		F9FD30EE0CC1AD070073837D /* tclPosixStr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1708F272A7004A47F5 /* tclPosixStr.c */; };
		F9FD30EF0CC1AD070073837D /* tclPreserve.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1808F272A7004A47F5 /* tclPreserve.c */; };
		F9FD30F00CC1AD070073837D /* tclProc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1908F272A7004A47F5 /* tclProc.c */; };
		F9FD30F10CC1AD070073837D /* tclRegexp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1A08F272A7004A47F5 /* tclRegexp.c */; };
		F9FD30F20CC1AD070073837D /* tclResolve.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1C08F272A7004A47F5 /* tclResolve.c */; };
		F9FD30F30CC1AD070073837D /* tclResult.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1D08F272A7004A47F5 /* tclResult.c */; };
		F9FD30F40CC1AD070073837D /* tclScan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1E08F272A7004A47F5 /* tclScan.c */; };
		F9FD30F50CC1AD070073837D /* tclStringObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F1F08F272A7004A47F5 /* tclStringObj.c */; };
		F9FD30F60CC1AD070073837D /* tclStrToD.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2408F272A7004A47F5 /* tclStrToD.c */; };
		F9FD30F70CC1AD070073837D /* tclStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2508F272A7004A47F5 /* tclStubInit.c */; };
		F9FD30F80CC1AD070073837D /* tclStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2608F272A7004A47F5 /* tclStubLib.c */; };
		F9FD30F90CC1AD070073837D /* tclThread.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2A08F272A7004A47F5 /* tclThread.c */; };
		F9FD30FA0CC1AD070073837D /* tclThreadAlloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */; };
		F9FD30FB0CC1AD070073837D /* tclThreadJoin.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */; };
		F9FD30FC0CC1AD070073837D /* tclThreadStorage.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */; };
		F9FD30FD0CC1AD070073837D /* tclTimer.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2F08F272A7004A47F5 /* tclTimer.c */; };
		F9FD30FE0CC1AD070073837D /* tclTomMathInterface.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */; };
		F9FD30FF0CC1AD070073837D /* tclTrace.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3208F272A7004A47F5 /* tclTrace.c */; };
		F9FD31000CC1AD070073837D /* tclUtf.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3408F272A7004A47F5 /* tclUtf.c */; };
		F9FD31010CC1AD070073837D /* tclUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3508F272A7004A47F5 /* tclUtil.c */; };
		F9FD31020CC1AD070073837D /* tclVar.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3608F272A7004A47F5 /* tclVar.c */; };
		F9FD31030CC1AD070073837D /* bn_fast_s_mp_mul_digs.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426408F272B3004A47F5 /* bn_fast_s_mp_mul_digs.c */; };
		F9FD31040CC1AD070073837D /* bn_fast_s_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426608F272B3004A47F5 /* bn_fast_s_mp_sqr.c */; };
		F9FD31050CC1AD070073837D /* bn_mp_add.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426908F272B3004A47F5 /* bn_mp_add.c */; };
		F9FD31060CC1AD070073837D /* bn_mp_add_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426A08F272B3004A47F5 /* bn_mp_add_d.c */; };
		F9FD31070CC1AD070073837D /* bn_mp_and.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426C08F272B3004A47F5 /* bn_mp_and.c */; };
		F9FD31080CC1AD070073837D /* bn_mp_clamp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426D08F272B3004A47F5 /* bn_mp_clamp.c */; };
		F9FD31090CC1AD070073837D /* bn_mp_clear.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426E08F272B3004A47F5 /* bn_mp_clear.c */; };
		F9FD310A0CC1AD070073837D /* bn_mp_clear_multi.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D426F08F272B3004A47F5 /* bn_mp_clear_multi.c */; };
		F9FD310B0CC1AD070073837D /* bn_mp_cmp.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427008F272B3004A47F5 /* bn_mp_cmp.c */; };
		F9FD310C0CC1AD070073837D /* bn_mp_cmp_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427108F272B3004A47F5 /* bn_mp_cmp_d.c */; };
		F9FD310D0CC1AD070073837D /* bn_mp_cmp_mag.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427208F272B3004A47F5 /* bn_mp_cmp_mag.c */; };
		F9FD310E0CC1AD070073837D /* bn_mp_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427408F272B3004A47F5 /* bn_mp_copy.c */; };
		F9FD310F0CC1AD070073837D /* bn_mp_count_bits.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427508F272B3004A47F5 /* bn_mp_count_bits.c */; };
		F9FD31100CC1AD070073837D /* bn_mp_div.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427608F272B3004A47F5 /* bn_mp_div.c */; };
		F9FD31110CC1AD070073837D /* bn_mp_div_2.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427708F272B3004A47F5 /* bn_mp_div_2.c */; };
		F9FD31120CC1AD070073837D /* bn_mp_div_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427808F272B3004A47F5 /* bn_mp_div_2d.c */; };
		F9FD31130CC1AD070073837D /* bn_mp_div_3.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427908F272B3004A47F5 /* bn_mp_div_3.c */; };
		F9FD31140CC1AD070073837D /* bn_mp_div_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427A08F272B3004A47F5 /* bn_mp_div_d.c */; };
		F9FD31150CC1AD070073837D /* bn_mp_exch.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427E08F272B3004A47F5 /* bn_mp_exch.c */; };
		F9FD31160CC1AD070073837D /* bn_mp_expt_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D427F08F272B3004A47F5 /* bn_mp_expt_d.c */; };
		F9FD31170CC1AD070073837D /* bn_mp_grow.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428708F272B3004A47F5 /* bn_mp_grow.c */; };
		F9FD31180CC1AD070073837D /* bn_mp_init.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428808F272B3004A47F5 /* bn_mp_init.c */; };
		F9FD31190CC1AD070073837D /* bn_mp_init_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428908F272B3004A47F5 /* bn_mp_init_copy.c */; };
		F9FD311A0CC1AD070073837D /* bn_mp_init_multi.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428A08F272B3004A47F5 /* bn_mp_init_multi.c */; };
		F9FD311B0CC1AD070073837D /* bn_mp_init_set.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428B08F272B3004A47F5 /* bn_mp_init_set.c */; };
		F9FD311C0CC1AD070073837D /* bn_mp_init_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D428D08F272B3004A47F5 /* bn_mp_init_size.c */; };
		F9FD311D0CC1AD070073837D /* bn_mp_karatsuba_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429208F272B3004A47F5 /* bn_mp_karatsuba_mul.c */; };
		F9FD311E0CC1AD070073837D /* bn_mp_karatsuba_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429308F272B3004A47F5 /* bn_mp_karatsuba_sqr.c */; };
		F9FD311F0CC1AD070073837D /* bn_mp_lshd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429508F272B3004A47F5 /* bn_mp_lshd.c */; };
		F9FD31200CC1AD070073837D /* bn_mp_mod.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429608F272B3004A47F5 /* bn_mp_mod.c */; };
		F9FD31210CC1AD070073837D /* bn_mp_mod_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429708F272B3004A47F5 /* bn_mp_mod_2d.c */; };
		F9FD31220CC1AD070073837D /* bn_mp_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429C08F272B3004A47F5 /* bn_mp_mul.c */; };
		F9FD31230CC1AD070073837D /* bn_mp_mul_2.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429D08F272B3004A47F5 /* bn_mp_mul_2.c */; };
		F9FD31240CC1AD070073837D /* bn_mp_mul_2d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429E08F272B3004A47F5 /* bn_mp_mul_2d.c */; };
		F9FD31250CC1AD070073837D /* bn_mp_mul_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D429F08F272B3004A47F5 /* bn_mp_mul_d.c */; };
		F9FD31260CC1AD070073837D /* bn_mp_neg.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42A208F272B3004A47F5 /* bn_mp_neg.c */; };
		F9FD31270CC1AD070073837D /* bn_mp_or.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42A308F272B3004A47F5 /* bn_mp_or.c */; };
		F9FD31280CC1AD070073837D /* bn_mp_radix_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AB08F272B3004A47F5 /* bn_mp_radix_size.c */; };
		F9FD31290CC1AD070073837D /* bn_mp_radix_smap.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AC08F272B3004A47F5 /* bn_mp_radix_smap.c */; };
		F9FD312A0CC1AD070073837D /* bn_mp_read_radix.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42AE08F272B3004A47F5 /* bn_mp_read_radix.c */; };
		F9FD312B0CC1AD070073837D /* bn_mp_rshd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42B908F272B3004A47F5 /* bn_mp_rshd.c */; };
		F9FD312C0CC1AD070073837D /* bn_mp_set.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BA08F272B3004A47F5 /* bn_mp_set.c */; };
		F9FD312D0CC1AD070073837D /* bn_mp_shrink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BC08F272B3004A47F5 /* bn_mp_shrink.c */; };
		F9FD312E0CC1AD070073837D /* bn_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42BE08F272B3004A47F5 /* bn_mp_sqr.c */; };
		F9FD312F0CC1AD070073837D /* bn_mp_sqrt.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C008F272B3004A47F5 /* bn_mp_sqrt.c */; };
		F9FD31300CC1AD070073837D /* bn_mp_sub.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C108F272B3004A47F5 /* bn_mp_sub.c */; };
		F9FD31310CC1AD070073837D /* bn_mp_sub_d.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C208F272B3004A47F5 /* bn_mp_sub_d.c */; };
		F9FD31320CC1AD070073837D /* bn_mp_to_unsigned_bin_n.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C708F272B3004A47F5 /* bn_mp_to_unsigned_bin_n.c */; };
		F9FD31330CC1AD070073837D /* bn_mp_to_unsigned_bin.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C608F272B3004A47F5 /* bn_mp_to_unsigned_bin.c */; };
		F9FD31340CC1AD070073837D /* bn_mp_toom_mul.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C808F272B3004A47F5 /* bn_mp_toom_mul.c */; };
		F9FD31350CC1AD070073837D /* bn_mp_toom_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42C908F272B3004A47F5 /* bn_mp_toom_sqr.c */; };
		F9FD31360CC1AD070073837D /* bn_mp_toradix_n.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CB08F272B3004A47F5 /* bn_mp_toradix_n.c */; };
		F9FD31370CC1AD070073837D /* bn_mp_unsigned_bin_size.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CC08F272B3004A47F5 /* bn_mp_unsigned_bin_size.c */; };
		F9FD31380CC1AD070073837D /* bn_mp_xor.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CD08F272B3004A47F5 /* bn_mp_xor.c */; };
		F9FD31390CC1AD070073837D /* bn_mp_zero.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42CE08F272B3004A47F5 /* bn_mp_zero.c */; };
		F9FD313A0CC1AD070073837D /* bn_reverse.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D008F272B3004A47F5 /* bn_reverse.c */; };
		F9FD313B0CC1AD070073837D /* bn_s_mp_add.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D108F272B3004A47F5 /* bn_s_mp_add.c */; };
		F9FD313C0CC1AD070073837D /* bn_s_mp_mul_digs.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D308F272B3004A47F5 /* bn_s_mp_mul_digs.c */; };
		F9FD313D0CC1AD070073837D /* bn_s_mp_sqr.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D508F272B3004A47F5 /* bn_s_mp_sqr.c */; };
		F9FD313E0CC1AD070073837D /* bn_s_mp_sub.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D608F272B3004A47F5 /* bn_s_mp_sub.c */; };
		F9FD313F0CC1AD070073837D /* bncore.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D42D708F272B3004A47F5 /* bncore.c */; };
		F9FD31400CC1AD070073837D /* tclMacOSXBundle.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433908F272B5004A47F5 /* tclMacOSXBundle.c */; };
		F9FD31410CC1AD070073837D /* tclMacOSXFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433D08F272B5004A47F5 /* tclMacOSXFCmd.c */; };
		F9FD31420CC1AD070073837D /* tclMacOSXNotify.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D433E08F272B5004A47F5 /* tclMacOSXNotify.c */; };
		F9FD31430CC1AD070073837D /* tclLoadDyld.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D445B08F272B9004A47F5 /* tclLoadDyld.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
		F9FD31440CC1AD070073837D /* tclUnixChan.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D445F08F272B9004A47F5 /* tclUnixChan.c */; };
		F9FD31450CC1AD070073837D /* tclUnixCompat.c in Sources */ = {isa = PBXBuildFile; fileRef = F9FC77B70AB29E9100B7077D /* tclUnixCompat.c */; };
		F9FD31460CC1AD070073837D /* tclUnixEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446008F272B9004A47F5 /* tclUnixEvent.c */; };
		F9FD31470CC1AD070073837D /* tclUnixFCmd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446108F272B9004A47F5 /* tclUnixFCmd.c */; };
		F9FD31480CC1AD070073837D /* tclUnixFile.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446208F272B9004A47F5 /* tclUnixFile.c */; };
		F9FD31490CC1AD070073837D /* tclUnixInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446308F272B9004A47F5 /* tclUnixInit.c */; settings = {COMPILER_FLAGS = "-DTCL_LIBRARY=\\\"$(TCL_LIBRARY)\\\" -DTCL_PACKAGE_PATH=\\\"$(TCL_PACKAGE_PATH)\\\""; }; };
		F9FD314A0CC1AD070073837D /* tclUnixNotfy.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446408F272B9004A47F5 /* tclUnixNotfy.c */; };
		F9FD314B0CC1AD070073837D /* tclUnixPipe.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446508F272B9004A47F5 /* tclUnixPipe.c */; };
		F9FD314C0CC1AD070073837D /* tclUnixSock.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446708F272B9004A47F5 /* tclUnixSock.c */; };
		F9FD314D0CC1AD070073837D /* tclUnixThrd.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446908F272B9004A47F5 /* tclUnixThrd.c */; };
		F9FD314E0CC1AD070073837D /* tclUnixTime.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D446B08F272B9004A47F5 /* tclUnixTime.c */; };
		F9FD314F0CC1AD070073837D /* tk3d.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAC08F27A39005CB29B /* tk3d.c */; };
		F9FD31500CC1AD070073837D /* tkArgv.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAE08F27A39005CB29B /* tkArgv.c */; };
		F9FD31510CC1AD070073837D /* tkAtom.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAAF08F27A39005CB29B /* tkAtom.c */; };
		F9FD31520CC1AD070073837D /* tkBind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB008F27A39005CB29B /* tkBind.c */; };
		F9FD31530CC1AD070073837D /* tkBitmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB108F27A39005CB29B /* tkBitmap.c */; };
		F9FD31540CC1AD070073837D /* tkButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB208F27A39005CB29B /* tkButton.c */; };
		F9FD31550CC1AD070073837D /* tkCanvArc.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB408F27A39005CB29B /* tkCanvArc.c */; };
		F9FD31560CC1AD070073837D /* tkCanvas.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB508F27A39005CB29B /* tkCanvas.c */; };
		F9FD31570CC1AD070073837D /* tkCanvBmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB708F27A39005CB29B /* tkCanvBmap.c */; };
		F9FD31580CC1AD070073837D /* tkCanvImg.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB808F27A39005CB29B /* tkCanvImg.c */; };
		F9FD31590CC1AD070073837D /* tkCanvLine.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAB908F27A39005CB29B /* tkCanvLine.c */; };
		F9FD315A0CC1AD070073837D /* tkCanvPoly.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABA08F27A39005CB29B /* tkCanvPoly.c */; };
		F9FD315B0CC1AD070073837D /* tkCanvPs.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABB08F27A39005CB29B /* tkCanvPs.c */; };
		F9FD315C0CC1AD070073837D /* tkCanvText.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABD08F27A39005CB29B /* tkCanvText.c */; };
		F9FD315D0CC1AD070073837D /* tkCanvUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABE08F27A39005CB29B /* tkCanvUtil.c */; };
		F9FD315E0CC1AD070073837D /* tkCanvWind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BABF08F27A39005CB29B /* tkCanvWind.c */; };
		F9FD315F0CC1AD070073837D /* tkClipboard.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC008F27A39005CB29B /* tkClipboard.c */; };
		F9FD31600CC1AD070073837D /* tkCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC108F27A39005CB29B /* tkCmds.c */; };
		F9FD31610CC1AD070073837D /* tkColor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC208F27A39005CB29B /* tkColor.c */; };
		F9FD31620CC1AD070073837D /* tkConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC408F27A39005CB29B /* tkConfig.c */; };
		F9FD31630CC1AD070073837D /* tkConsole.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC508F27A39005CB29B /* tkConsole.c */; };
		F9FD31640CC1AD070073837D /* tkCursor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC608F27A39005CB29B /* tkCursor.c */; };
		F9FD31650CC1AD070073837D /* tkEntry.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAC808F27A39005CB29B /* tkEntry.c */; };
		F9FD31660CC1AD070073837D /* tkError.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACA08F27A39005CB29B /* tkError.c */; };
		F9FD31670CC1AD070073837D /* tkEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACB08F27A39005CB29B /* tkEvent.c */; };
		F9FD31680CC1AD070073837D /* tkFileFilter.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACC08F27A39005CB29B /* tkFileFilter.c */; };
		F9FD31690CC1AD070073837D /* tkFocus.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACE08F27A39005CB29B /* tkFocus.c */; };
		F9FD316A0CC1AD070073837D /* tkFont.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BACF08F27A39005CB29B /* tkFont.c */; };
		F9FD316B0CC1AD070073837D /* tkFrame.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD108F27A39005CB29B /* tkFrame.c */; };
		F9FD316C0CC1AD070073837D /* tkGC.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD208F27A39005CB29B /* tkGC.c */; };
		F9FD316D0CC1AD070073837D /* tkGeometry.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD308F27A39005CB29B /* tkGeometry.c */; };
		F9FD316E0CC1AD070073837D /* tkGet.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD408F27A39005CB29B /* tkGet.c */; };
		F9FD316F0CC1AD070073837D /* tkGrab.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD508F27A39005CB29B /* tkGrab.c */; };
		F9FD31700CC1AD070073837D /* tkGrid.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD608F27A39005CB29B /* tkGrid.c */; };
		F9FD31710CC1AD070073837D /* tkImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD708F27A39005CB29B /* tkImage.c */; };
		F9FD31720CC1AD070073837D /* tkImgBmap.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD808F27A39005CB29B /* tkImgBmap.c */; };
		F9FD31730CC1AD070073837D /* tkImgGIF.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAD908F27A39005CB29B /* tkImgGIF.c */; };
		F9FD31740CC1AD070073837D /* tkImgPhoto.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BADA08F27A39005CB29B /* tkImgPhoto.c */; };
		F9FD31750CC1AD070073837D /* tkImgPPM.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BADB08F27A39005CB29B /* tkImgPPM.c */; };
		F9FD31760CC1AD070073837D /* tkListbox.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE408F27A39005CB29B /* tkListbox.c */; };
		F9FD31770CC1AD070073837D /* tkMacWinMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE508F27A39005CB29B /* tkMacWinMenu.c */; };
		F9FD31780CC1AD070073837D /* tkMain.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE608F27A39005CB29B /* tkMain.c */; };
		F9FD31790CC1AD070073837D /* tkMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE708F27A39005CB29B /* tkMenu.c */; };
		F9FD317A0CC1AD070073837D /* tkMenubutton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE908F27A39005CB29B /* tkMenubutton.c */; };
		F9FD317B0CC1AD070073837D /* tkMenuDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEB08F27A39005CB29B /* tkMenuDraw.c */; };
		F9FD317C0CC1AD070073837D /* tkMessage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEC08F27A39005CB29B /* tkMessage.c */; };
		F9FD317D0CC1AD070073837D /* tkObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAED08F27A39005CB29B /* tkObj.c */; };
		F9FD317E0CC1AD070073837D /* tkOldConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEE08F27A39005CB29B /* tkOldConfig.c */; };
		F9FD317F0CC1AD070073837D /* tkOldTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFE08F27A39005CB29B /* tkOldTest.c */; };
		F9FD31800CC1AD070073837D /* tkOption.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEF08F27A39005CB29B /* tkOption.c */; };
		F9FD31810CC1AD070073837D /* tkPack.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF008F27A39005CB29B /* tkPack.c */; };
		F9FD31820CC1AD070073837D /* tkPanedWindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF108F27A39005CB29B /* tkPanedWindow.c */; };
		F9FD31830CC1AD070073837D /* tkPlace.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF208F27A39005CB29B /* tkPlace.c */; };
		F9FD31850CC1AD070073837D /* tkRectOval.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF608F27A39005CB29B /* tkRectOval.c */; };
		F9FD31860CC1AD070073837D /* tkScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF708F27A39005CB29B /* tkScale.c */; };
		F9FD31870CC1AD070073837D /* tkScrollbar.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF908F27A39005CB29B /* tkScrollbar.c */; };
		F9FD31880CC1AD070073837D /* tkSelect.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFB08F27A39005CB29B /* tkSelect.c */; };
		F9FD31890CC1AD070073837D /* tkSquare.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFD08F27A39005CB29B /* tkSquare.c */; };
		F9FD318A0CC1AD070073837D /* tkStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFF08F27A39005CB29B /* tkStubInit.c */; };
		F9FD318B0CC1AD070073837D /* tkStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0008F27A39005CB29B /* tkStubLib.c */; };
		F9FD318C0CC1AD070073837D /* tkStyle.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0108F27A39005CB29B /* tkStyle.c */; };
		F9FD318D0CC1AD070073837D /* tkTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0208F27A39005CB29B /* tkTest.c */; };
		F9FD318E0CC1AD070073837D /* tkText.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0308F27A39005CB29B /* tkText.c */; };
		F9FD318F0CC1AD070073837D /* tkTextBTree.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0508F27A39005CB29B /* tkTextBTree.c */; };
		F9FD31900CC1AD070073837D /* tkTextDisp.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0608F27A39005CB29B /* tkTextDisp.c */; };
		F9FD31910CC1AD070073837D /* tkTextImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0808F27A39005CB29B /* tkTextImage.c */; };
		F9FD31920CC1AD070073837D /* tkTextIndex.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0908F27A39005CB29B /* tkTextIndex.c */; };
		F9FD31930CC1AD070073837D /* tkTextMark.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0A08F27A39005CB29B /* tkTextMark.c */; };
		F9FD31940CC1AD070073837D /* tkTextTag.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0B08F27A39005CB29B /* tkTextTag.c */; };
		F9FD31950CC1AD070073837D /* tkTextWind.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0C08F27A39005CB29B /* tkTextWind.c */; };
		F9FD31960CC1AD070073837D /* tkTrig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0D08F27A39005CB29B /* tkTrig.c */; };
		F9FD31970CC1AD070073837D /* tkUndo.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB0E08F27A39005CB29B /* tkUndo.c */; };
		F9FD31980CC1AD070073837D /* tkUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1008F27A39005CB29B /* tkUtil.c */; };
		F9FD31990CC1AD070073837D /* tkVisual.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1108F27A39005CB29B /* tkVisual.c */; };
		F9FD319A0CC1AD070073837D /* tkWindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BB1208F27A39005CB29B /* tkWindow.c */; };
		F9FD319B0CC1AD070073837D /* ttkBlink.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E10AF786D5000797B5 /* ttkBlink.c */; };
		F9FD319C0CC1AD070073837D /* ttkButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E20AF786D5000797B5 /* ttkButton.c */; };
		F9FD319D0CC1AD070073837D /* ttkCache.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E30AF786D5000797B5 /* ttkCache.c */; };
		F9FD319E0CC1AD070073837D /* ttkClamTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E40AF786D5000797B5 /* ttkClamTheme.c */; };
		F9FD319F0CC1AD070073837D /* ttkClassicTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E50AF786D5000797B5 /* ttkClassicTheme.c */; };
		F9FD31A00CC1AD070073837D /* ttkDefaultTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E70AF786D5000797B5 /* ttkDefaultTheme.c */; };
		F9FD31A10CC1AD070073837D /* ttkElements.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E80AF786D5000797B5 /* ttkElements.c */; };
		F9FD31A20CC1AD070073837D /* ttkEntry.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887E90AF786D5000797B5 /* ttkEntry.c */; };
		F9FD31A30CC1AD070073837D /* ttkFrame.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EA0AF786D5000797B5 /* ttkFrame.c */; };
		F9FD31A40CC1AD070073837D /* ttkImage.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EB0AF786D5000797B5 /* ttkImage.c */; };
		F9FD31A50CC1AD070073837D /* ttkInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EC0AF786D5000797B5 /* ttkInit.c */; };
		F9FD31A60CC1AD070073837D /* ttkLabel.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887ED0AF786D5000797B5 /* ttkLabel.c */; };
		F9FD31A70CC1AD070073837D /* ttkLayout.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EE0AF786D5000797B5 /* ttkLayout.c */; };
		F9FD31A80CC1AD070073837D /* ttkManager.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887EF0AF786D5000797B5 /* ttkManager.c */; };
		F9FD31A90CC1AD070073837D /* ttkNotebook.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F10AF786D5000797B5 /* ttkNotebook.c */; };
		F9FD31AA0CC1AD070073837D /* ttkPanedwindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F20AF786D5000797B5 /* ttkPanedwindow.c */; };
		F9FD31AB0CC1AD070073837D /* ttkProgress.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F30AF786D5000797B5 /* ttkProgress.c */; };
		F9FD31AC0CC1AD070073837D /* ttkScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F40AF786D5000797B5 /* ttkScale.c */; };
		F9FD31AD0CC1AD070073837D /* ttkScroll.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F50AF786D5000797B5 /* ttkScroll.c */; };
		F9FD31AE0CC1AD070073837D /* ttkScrollbar.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F60AF786D5000797B5 /* ttkScrollbar.c */; };
		F9FD31AF0CC1AD070073837D /* ttkSeparator.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F70AF786D5000797B5 /* ttkSeparator.c */; };
		F9FD31B00CC1AD070073837D /* ttkSquare.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F80AF786D5000797B5 /* ttkSquare.c */; };
		F9FD31B10CC1AD070073837D /* ttkState.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887F90AF786D5000797B5 /* ttkState.c */; };
		F9FD31B20CC1AD070073837D /* ttkStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FA0AF786D5000797B5 /* ttkStubInit.c */; };
		F9FD31B30CC1AD070073837D /* ttkStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FB0AF786D5000797B5 /* ttkStubLib.c */; };
		F9FD31B40CC1AD070073837D /* ttkTagSet.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FC0AF786D5000797B5 /* ttkTagSet.c */; };
		F9FD31B50CC1AD070073837D /* ttkTheme.c in Sources */ = {isa = PBXBuildFile; fileRef = F96887FD0AF786D5000797B5 /* ttkTheme.c */; };
		F9FD31B60CC1AD070073837D /* ttkTrace.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888000AF786D5000797B5 /* ttkTrace.c */; };
		F9FD31B70CC1AD070073837D /* ttkTrack.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888010AF786D5000797B5 /* ttkTrack.c */; };
		F9FD31B80CC1AD070073837D /* ttkTreeview.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888020AF786D5000797B5 /* ttkTreeview.c */; };
		F9FD31B90CC1AD070073837D /* ttkWidget.c in Sources */ = {isa = PBXBuildFile; fileRef = F96888030AF786D5000797B5 /* ttkWidget.c */; };
		F9FD31DA0CC1AD070073837D /* tkAppInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7508F27A3D005CB29B /* tkAppInit.c */; settings = {COMPILER_FLAGS = "-DTK_TEST"; }; };
		F9FD31DB0CC1AD070073837D /* tkUnix3d.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7908F27A3D005CB29B /* tkUnix3d.c */; };
		F9FD31DC0CC1AD070073837D /* tkUnixScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8C08F27A3D005CB29B /* tkUnixScale.c */; };
		F9FD31E20CC1AD070073837D /* tclDTrace.d in Sources */ = {isa = PBXBuildFile; fileRef = F9F4415D0C8BAE6F00BCCD67 /* tclDTrace.d */; };
		F9FD31E40CC1AD070073837D /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F966C07408F2820D005CB29B /* CoreFoundation.framework */; };
		F9FD31F80CC1ADB70073837D /* tkUnixCursor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7D08F27A3D005CB29B /* tkUnixCursor.c */; };
		F9FD31FA0CC1ADB70073837D /* tkUnixKey.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8708F27A3D005CB29B /* tkUnixKey.c */; };
		F9FD31FB0CC1ADB70073837D /* tkUnixXId.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC9108F27A3D005CB29B /* tkUnixXId.c */; };
		F9FD31FC0CC1ADB70073837D /* tkUnixInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8508F27A3D005CB29B /* tkUnixInit.c */; };
		F9FD31FD0CC1ADB70073837D /* tkUnixEmbed.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8108F27A3D005CB29B /* tkUnixEmbed.c */; };
		F9FD31FE0CC1ADB70073837D /* tkUnixSend.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8F08F27A3D005CB29B /* tkUnixSend.c */; };
		F9FD31FF0CC1ADB70073837D /* tkUnixFocus.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8308F27A3D005CB29B /* tkUnixFocus.c */; };
		F9FD32000CC1ADB70073837D /* tkUnixWm.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC9008F27A3D005CB29B /* tkUnixWm.c */; };
		F9FD32010CC1ADB70073837D /* tkUnixRFont.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8B08F27A3D005CB29B /* tkUnixRFont.c */; };
		F9FD32020CC1ADB70073837D /* tkUnix.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7808F27A3D005CB29B /* tkUnix.c */; };
		F9FD32030CC1ADB70073837D /* tkUnixMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8808F27A3D005CB29B /* tkUnixMenu.c */; };
		F9FD32040CC1ADB70073837D /* tkUnixConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */; };
		F9FD32050CC1ADB70073837D /* tkUnixDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8008F27A3D005CB29B /* tkUnixDraw.c */; };
		F9FD32060CC1ADB70073837D /* tkUnixDialog.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */; };
		F9FD32070CC1ADB70073837D /* tkUnixSelect.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8E08F27A3D005CB29B /* tkUnixSelect.c */; };
		F9FD32080CC1ADB70073837D /* tkUnixEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8208F27A3D005CB29B /* tkUnixEvent.c */; };
		F9FD32090CC1ADB70073837D /* tkUnixColor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7B08F27A3D005CB29B /* tkUnixColor.c */; };
		F9FD320A0CC1ADB70073837D /* tkUnixButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7A08F27A3D005CB29B /* tkUnixButton.c */; };
		F9FD320B0CC1ADB70073837D /* tkUnixMenubu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8908F27A3D005CB29B /* tkUnixMenubu.c */; };
		F9FD320C0CC1ADB70073837D /* tkUnixScrlbr.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8D08F27A3D005CB29B /* tkUnixScrlbr.c */; };
		F9FD32170CC1AF170073837D /* libX11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD32140CC1AF170073837D /* libX11.dylib */; };
		F9FD32180CC1AF170073837D /* libXext.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD32150CC1AF170073837D /* libXext.dylib */; };
		F9FD32190CC1AF170073837D /* libXss.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD32160CC1AF170073837D /* libXss.dylib */; };
		F9FD349B0CC1BB0D0073837D /* libfreetype.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD34990CC1BB0D0073837D /* libfreetype.dylib */; };
		F9FD349C0CC1BB0D0073837D /* libXft.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD349A0CC1BB0D0073837D /* libXft.dylib */; };
		F9FD34C40CC1BBD70073837D /* libfontconfig.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD34C30CC1BBD70073837D /* libfontconfig.dylib */; };
		F9FFAF1D0DFDDB26007F8A6A /* tclIORTrans.c in Sources */ = {isa = PBXBuildFile; fileRef = F95D77E90DFD820D00A8BF6F /* tclIORTrans.c */; };
		F9FFAF1F0DFDDB2F007F8A6A /* tclOO.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B20DF1F75400E04F67 /* tclOO.c */; };
		F9FFAF200DFDDB32007F8A6A /* tclOOBasic.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B60DF1F76100E04F67 /* tclOOBasic.c */; };
		F9FFAF210DFDDB32007F8A6A /* tclOOCall.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B80DF1F76600E04F67 /* tclOOCall.c */; };
		F9FFAF220DFDDB34007F8A6A /* tclOODefineCmds.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599BB0DF1F77000E04F67 /* tclOODefineCmds.c */; };
		F9FFAF230DFDDB35007F8A6A /* tclOOInfo.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599BD0DF1F77400E04F67 /* tclOOInfo.c */; };
		F9FFAF240DFDDB36007F8A6A /* tclOOMethod.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C10DF1F78300E04F67 /* tclOOMethod.c */; };
		F9FFAF250DFDDB37007F8A6A /* tclOOStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C30DF1F78800E04F67 /* tclOOStubInit.c */; };
		F9FFAF260DFDDB38007F8A6A /* tclOOStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599C50DF1F78D00E04F67 /* tclOOStubLib.c */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
		8DD76FB20486AB0100D96B5E /* tktest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = tktest; sourceTree = BUILT_PRODUCTS_DIR; };
		F9099B8A0CC67D30005A9580 /* textpeer.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textpeer.tcl; sourceTree = "<group>"; };
		F9099B8B0CC67D3E005A9580 /* ttkbut.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttkbut.tcl; sourceTree = "<group>"; };
		F9152B080EAF8A5000CD5C7B /* tkBusy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkBusy.c; sourceTree = "<group>"; };
		F91543270EF201A90032D1E8 /* fontchoose.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fontchoose.tcl; sourceTree = "<group>"; };
		F915432A0EF201CF0032D1E8 /* zlib.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = zlib.test; sourceTree = "<group>"; };
		F915432D0EF201EE0032D1E8 /* zlib.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = zlib.n; sourceTree = "<group>"; };
		F9183E640EFC80CD0030B814 /* throw.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = throw.n; sourceTree = "<group>"; };
		F9183E650EFC80D70030B814 /* try.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = try.n; sourceTree = "<group>"; };
		F9183E6A0EFC81560030B814 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F9183E8F0EFC817B0030B814 /* tdbc */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tdbc; sourceTree = "<group>"; };
		F91DC23C0E44C51B002CB8D1 /* nre.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = nre.test; sourceTree = "<group>"; };
		F91E62260C1AE686006C9D96 /* Tclsh-Info.plist.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "Tclsh-Info.plist.in"; sourceTree = "<group>"; };
		F92240290D7C620F005EC715 /* knightstour.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = knightstour.tcl; sourceTree = "<group>"; };
		F92D7F100DE777240033A13A /* tsdPerf.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tsdPerf.tcl; sourceTree = "<group>"; };
		F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgPhInstance.c; sourceTree = "<group>"; };
		F93599B20DF1F75400E04F67 /* tclOO.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOO.c; sourceTree = "<group>"; };
		F93599B40DF1F75900E04F67 /* tclOO.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclOO.decls; sourceTree = "<group>"; };
		F93599B50DF1F75D00E04F67 /* tclOO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclOO.h; sourceTree = "<group>"; };
		F93599B60DF1F76100E04F67 /* tclOOBasic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOBasic.c; sourceTree = "<group>"; };
		F93599B80DF1F76600E04F67 /* tclOOCall.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOCall.c; sourceTree = "<group>"; };
		F93599BA0DF1F76A00E04F67 /* tclOODecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclOODecls.h; sourceTree = "<group>"; };
		F93599BB0DF1F77000E04F67 /* tclOODefineCmds.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOODefineCmds.c; sourceTree = "<group>"; };
		F93599BD0DF1F77400E04F67 /* tclOOInfo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOInfo.c; sourceTree = "<group>"; };
		F93599BF0DF1F77900E04F67 /* tclOOInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclOOInt.h; sourceTree = "<group>"; };
		F93599C00DF1F77D00E04F67 /* tclOOIntDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclOOIntDecls.h; sourceTree = "<group>"; };
		F93599C10DF1F78300E04F67 /* tclOOMethod.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOMethod.c; sourceTree = "<group>"; };
		F93599C30DF1F78800E04F67 /* tclOOStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOStubInit.c; sourceTree = "<group>"; };
		F93599C50DF1F78D00E04F67 /* tclOOStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclOOStubLib.c; sourceTree = "<group>"; };
		F93599C80DF1F81900E04F67 /* oo.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = oo.test; sourceTree = "<group>"; };
		F93599CF0DF1F87F00E04F67 /* Class.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Class.3; sourceTree = "<group>"; };
		F93599D00DF1F89E00E04F67 /* class.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = class.n; sourceTree = "<group>"; };
		F93599D20DF1F8DF00E04F67 /* copy.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = copy.n; sourceTree = "<group>"; };
		F93599D30DF1F8F500E04F67 /* define.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = define.n; sourceTree = "<group>"; };
		F93599D40DF1F91900E04F67 /* Method.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Method.3; sourceTree = "<group>"; };
		F93599D50DF1F93700E04F67 /* my.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = my.n; sourceTree = "<group>"; };
		F93599D60DF1F95000E04F67 /* next.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = next.n; sourceTree = "<group>"; };
		F93599D70DF1F96800E04F67 /* object.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = object.n; sourceTree = "<group>"; };
		F93599D80DF1F98300E04F67 /* self.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = self.n; sourceTree = "<group>"; };
		F936FCD70CCD984500716967 /* ttkprogress.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttkprogress.tcl; sourceTree = "<group>"; };
		F936FCD80CCD984600716967 /* tree.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tree.tcl; sourceTree = "<group>"; };
		F936FCD90CCD984600716967 /* toolbar.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = toolbar.tcl; sourceTree = "<group>"; };
		F936FCDA0CCD984600716967 /* ttknote.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttknote.tcl; sourceTree = "<group>"; };
		F936FCDB0CCD984600716967 /* combo.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = combo.tcl; sourceTree = "<group>"; };
		F93E5EFD09CF8711008FA367 /* tkMacOSXFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXFont.h; sourceTree = "<group>"; };
		F94523A10E6FC2AC00C1D987 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
		F946FB8B0FBE3AED00CD6495 /* itcl */ = {isa = PBXFileReference; lastKnownFileType = folder; path = itcl; sourceTree = "<group>"; };
		F95D77E90DFD820D00A8BF6F /* tclIORTrans.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIORTrans.c; sourceTree = "<group>"; };
		F95D8D4B0F1715610006B020 /* Tk.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Tk.icns; sourceTree = "<group>"; };
		F95D8D4C0F1715610006B020 /* Tk.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Tk.tiff; sourceTree = "<group>"; };
		F95FAFF90B34F1130072E431 /* macOSXLoad.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = macOSXLoad.test; sourceTree = "<group>"; };
		F962F7C60DADC26200648DB8 /* vsapi.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = vsapi.test; sourceTree = "<group>"; };
		F96437C90EF0D4B2003F468E /* tclZlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclZlib.c; sourceTree = "<group>"; };
		F96437E60EF0D652003F468E /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = /usr/lib/libz.dylib; sourceTree = "<absolute>"; };
		F966BA0408F27A37005CB29B /* error.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = error.xbm; sourceTree = "<group>"; };
		F966BA0508F27A37005CB29B /* gray12.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray12.xbm; sourceTree = "<group>"; };
		F966BA0608F27A37005CB29B /* gray25.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray25.xbm; sourceTree = "<group>"; };
		F966BA0708F27A37005CB29B /* gray50.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray50.xbm; sourceTree = "<group>"; };
		F966BA0808F27A37005CB29B /* gray75.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray75.xbm; sourceTree = "<group>"; };
		F966BA0908F27A37005CB29B /* hourglass.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = hourglass.xbm; sourceTree = "<group>"; };
		F966BA0A08F27A37005CB29B /* info.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = info.xbm; sourceTree = "<group>"; };
		F966BA0B08F27A37005CB29B /* questhead.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = questhead.xbm; sourceTree = "<group>"; };
		F966BA0C08F27A37005CB29B /* question.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = question.xbm; sourceTree = "<group>"; };
		F966BA0D08F27A37005CB29B /* warning.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = warning.xbm; sourceTree = "<group>"; };
		F966BA0E08F27A37005CB29B /* ChangeLog */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = ChangeLog; sourceTree = "<group>"; };
		F966BA0F08F27A37005CB29B /* changes */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes; sourceTree = "<group>"; };
		F966BA1108F27A37005CB29B /* 3DBorder.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = 3DBorder.3; sourceTree = "<group>"; };
		F966BA1208F27A37005CB29B /* AddOption.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AddOption.3; sourceTree = "<group>"; };
		F966BA1308F27A37005CB29B /* bell.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bell.n; sourceTree = "<group>"; };
		F966BA1408F27A37005CB29B /* bind.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bind.n; sourceTree = "<group>"; };
		F966BA1508F27A37005CB29B /* BindTable.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = BindTable.3; sourceTree = "<group>"; };
		F966BA1608F27A37005CB29B /* bindtags.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bindtags.n; sourceTree = "<group>"; };
		F966BA1708F27A37005CB29B /* bitmap.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bitmap.n; sourceTree = "<group>"; };
		F966BA1808F27A37005CB29B /* button.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = button.n; sourceTree = "<group>"; };
		F966BA1908F27A37005CB29B /* canvas.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = canvas.n; sourceTree = "<group>"; };
		F966BA1A08F27A37005CB29B /* CanvPsY.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CanvPsY.3; sourceTree = "<group>"; };
		F966BA1B08F27A37005CB29B /* CanvTkwin.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CanvTkwin.3; sourceTree = "<group>"; };
		F966BA1C08F27A37005CB29B /* CanvTxtInfo.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CanvTxtInfo.3; sourceTree = "<group>"; };
		F966BA1D08F27A37005CB29B /* checkbutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = checkbutton.n; sourceTree = "<group>"; };
		F966BA1E08F27A37005CB29B /* chooseColor.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = chooseColor.n; sourceTree = "<group>"; };
		F966BA1F08F27A37005CB29B /* chooseDirectory.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = chooseDirectory.n; sourceTree = "<group>"; };
		F966BA2008F27A37005CB29B /* Clipboard.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Clipboard.3; sourceTree = "<group>"; };
		F966BA2108F27A37005CB29B /* clipboard.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = clipboard.n; sourceTree = "<group>"; };
		F966BA2208F27A37005CB29B /* ClrSelect.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ClrSelect.3; sourceTree = "<group>"; };
		F966BA2308F27A37005CB29B /* colors.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = colors.n; sourceTree = "<group>"; };
		F966BA2408F27A37005CB29B /* ConfigWidg.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ConfigWidg.3; sourceTree = "<group>"; };
		F966BA2508F27A37005CB29B /* ConfigWind.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ConfigWind.3; sourceTree = "<group>"; };
		F966BA2608F27A37005CB29B /* console.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = console.n; sourceTree = "<group>"; };
		F966BA2708F27A37005CB29B /* CoordToWin.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CoordToWin.3; sourceTree = "<group>"; };
		F966BA2808F27A37005CB29B /* CrtCmHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtCmHdlr.3; sourceTree = "<group>"; };
		F966BA2908F27A37005CB29B /* CrtErrHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtErrHdlr.3; sourceTree = "<group>"; };
		F966BA2A08F27A37005CB29B /* CrtGenHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtGenHdlr.3; sourceTree = "<group>"; };
		F966BA2B08F27A37005CB29B /* CrtImgType.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtImgType.3; sourceTree = "<group>"; };
		F966BA2C08F27A37005CB29B /* CrtItemType.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtItemType.3; sourceTree = "<group>"; };
		F966BA2D08F27A37005CB29B /* CrtPhImgFmt.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtPhImgFmt.3; sourceTree = "<group>"; };
		F966BA2E08F27A37005CB29B /* CrtSelHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtSelHdlr.3; sourceTree = "<group>"; };
		F966BA2F08F27A37005CB29B /* CrtWindow.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtWindow.3; sourceTree = "<group>"; };
		F966BA3008F27A37005CB29B /* cursors.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = cursors.n; sourceTree = "<group>"; };
		F966BA3108F27A37005CB29B /* DeleteImg.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DeleteImg.3; sourceTree = "<group>"; };
		F966BA3208F27A37005CB29B /* destroy.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = destroy.n; sourceTree = "<group>"; };
		F966BA3308F27A37005CB29B /* dialog.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = dialog.n; sourceTree = "<group>"; };
		F966BA3408F27A37005CB29B /* DrawFocHlt.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DrawFocHlt.3; sourceTree = "<group>"; };
		F966BA3508F27A37005CB29B /* entry.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = entry.n; sourceTree = "<group>"; };
		F966BA3608F27A37005CB29B /* event.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = event.n; sourceTree = "<group>"; };
		F966BA3708F27A37005CB29B /* EventHndlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = EventHndlr.3; sourceTree = "<group>"; };
		F966BA3808F27A37005CB29B /* FindPhoto.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = FindPhoto.3; sourceTree = "<group>"; };
		F966BA3908F27A37005CB29B /* focus.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = focus.n; sourceTree = "<group>"; };
		F966BA3A08F27A37005CB29B /* focusNext.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = focusNext.n; sourceTree = "<group>"; };
		F966BA3B08F27A37005CB29B /* font.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = font.n; sourceTree = "<group>"; };
		F966BA3C08F27A37005CB29B /* FontId.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = FontId.3; sourceTree = "<group>"; };
		F966BA3D08F27A37005CB29B /* frame.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = frame.n; sourceTree = "<group>"; };
		F966BA3E08F27A37005CB29B /* FreeXId.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = FreeXId.3; sourceTree = "<group>"; };
		F966BA3F08F27A37005CB29B /* GeomReq.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GeomReq.3; sourceTree = "<group>"; };
		F966BA4008F27A37005CB29B /* GetAnchor.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetAnchor.3; sourceTree = "<group>"; };
		F966BA4108F27A37005CB29B /* GetBitmap.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetBitmap.3; sourceTree = "<group>"; };
		F966BA4208F27A37005CB29B /* GetCapStyl.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetCapStyl.3; sourceTree = "<group>"; };
		F966BA4308F27A37005CB29B /* GetClrmap.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetClrmap.3; sourceTree = "<group>"; };
		F966BA4408F27A37005CB29B /* GetColor.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetColor.3; sourceTree = "<group>"; };
		F966BA4508F27A37005CB29B /* GetCursor.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetCursor.3; sourceTree = "<group>"; };
		F966BA4608F27A37005CB29B /* GetDash.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetDash.3; sourceTree = "<group>"; };
		F966BA4708F27A37005CB29B /* GetFont.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetFont.3; sourceTree = "<group>"; };
		F966BA4808F27A37005CB29B /* GetGC.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetGC.3; sourceTree = "<group>"; };
		F966BA4908F27A37005CB29B /* GetHINSTANCE.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetHINSTANCE.3; sourceTree = "<group>"; };
		F966BA4A08F27A37005CB29B /* GetHWND.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetHWND.3; sourceTree = "<group>"; };
		F966BA4B08F27A37005CB29B /* GetImage.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetImage.3; sourceTree = "<group>"; };
		F966BA4C08F27A37005CB29B /* GetJoinStl.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetJoinStl.3; sourceTree = "<group>"; };
		F966BA4D08F27A37005CB29B /* GetJustify.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetJustify.3; sourceTree = "<group>"; };
		F966BA4E08F27A37005CB29B /* getOpenFile.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = getOpenFile.n; sourceTree = "<group>"; };
		F966BA4F08F27A37005CB29B /* GetOption.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetOption.3; sourceTree = "<group>"; };
		F966BA5008F27A38005CB29B /* GetPixels.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetPixels.3; sourceTree = "<group>"; };
		F966BA5108F27A38005CB29B /* GetPixmap.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetPixmap.3; sourceTree = "<group>"; };
		F966BA5208F27A38005CB29B /* GetRelief.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetRelief.3; sourceTree = "<group>"; };
		F966BA5308F27A38005CB29B /* GetRootCrd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetRootCrd.3; sourceTree = "<group>"; };
		F966BA5408F27A38005CB29B /* GetScroll.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetScroll.3; sourceTree = "<group>"; };
		F966BA5508F27A38005CB29B /* GetSelect.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetSelect.3; sourceTree = "<group>"; };
		F966BA5608F27A38005CB29B /* GetUid.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetUid.3; sourceTree = "<group>"; };
		F966BA5708F27A38005CB29B /* GetVisual.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetVisual.3; sourceTree = "<group>"; };
		F966BA5808F27A38005CB29B /* GetVRoot.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetVRoot.3; sourceTree = "<group>"; };
		F966BA5908F27A38005CB29B /* Grab.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Grab.3; sourceTree = "<group>"; };
		F966BA5A08F27A38005CB29B /* grab.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = grab.n; sourceTree = "<group>"; };
		F966BA5B08F27A38005CB29B /* grid.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = grid.n; sourceTree = "<group>"; };
		F966BA5C08F27A38005CB29B /* HandleEvent.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = HandleEvent.3; sourceTree = "<group>"; };
		F966BA5D08F27A38005CB29B /* HWNDToWindow.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = HWNDToWindow.3; sourceTree = "<group>"; };
		F966BA5E08F27A38005CB29B /* IdToWindow.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = IdToWindow.3; sourceTree = "<group>"; };
		F966BA5F08F27A38005CB29B /* image.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = image.n; sourceTree = "<group>"; };
		F966BA6008F27A38005CB29B /* ImgChanged.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ImgChanged.3; sourceTree = "<group>"; };
		F966BA6108F27A38005CB29B /* Inactive.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Inactive.3; sourceTree = "<group>"; };
		F966BA6208F27A38005CB29B /* InternAtom.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = InternAtom.3; sourceTree = "<group>"; };
		F966BA6308F27A38005CB29B /* keysyms.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = keysyms.n; sourceTree = "<group>"; };
		F966BA6408F27A38005CB29B /* label.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = label.n; sourceTree = "<group>"; };
		F966BA6508F27A38005CB29B /* labelframe.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = labelframe.n; sourceTree = "<group>"; };
		F966BA6608F27A38005CB29B /* listbox.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = listbox.n; sourceTree = "<group>"; };
		F966BA6708F27A38005CB29B /* loadTk.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = loadTk.n; sourceTree = "<group>"; };
		F966BA6808F27A38005CB29B /* lower.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lower.n; sourceTree = "<group>"; };
		F966BA6908F27A38005CB29B /* MainLoop.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MainLoop.3; sourceTree = "<group>"; };
		F966BA6A08F27A38005CB29B /* MaintGeom.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MaintGeom.3; sourceTree = "<group>"; };
		F966BA6B08F27A38005CB29B /* MainWin.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MainWin.3; sourceTree = "<group>"; };
		F966BA6D08F27A38005CB29B /* ManageGeom.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ManageGeom.3; sourceTree = "<group>"; };
		F966BA6E08F27A38005CB29B /* MapWindow.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MapWindow.3; sourceTree = "<group>"; };
		F966BA6F08F27A38005CB29B /* MeasureChar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MeasureChar.3; sourceTree = "<group>"; };
		F966BA7008F27A38005CB29B /* menu.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menu.n; sourceTree = "<group>"; };
		F966BA7108F27A38005CB29B /* menubar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menubar.n; sourceTree = "<group>"; };
		F966BA7208F27A38005CB29B /* menubutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menubutton.n; sourceTree = "<group>"; };
		F966BA7308F27A38005CB29B /* message.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = message.n; sourceTree = "<group>"; };
		F966BA7408F27A38005CB29B /* messageBox.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = messageBox.n; sourceTree = "<group>"; };
		F966BA7508F27A38005CB29B /* MoveToplev.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MoveToplev.3; sourceTree = "<group>"; };
		F966BA7608F27A38005CB29B /* Name.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Name.3; sourceTree = "<group>"; };
		F966BA7708F27A38005CB29B /* NameOfImg.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = NameOfImg.3; sourceTree = "<group>"; };
		F966BA7808F27A38005CB29B /* option.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = option.n; sourceTree = "<group>"; };
		F966BA7908F27A38005CB29B /* optionMenu.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = optionMenu.n; sourceTree = "<group>"; };
		F966BA7A08F27A38005CB29B /* options.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = options.n; sourceTree = "<group>"; };
		F966BA7B08F27A38005CB29B /* OwnSelect.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = OwnSelect.3; sourceTree = "<group>"; };
		F966BA7C08F27A38005CB29B /* pack-old.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = "pack-old.n"; sourceTree = "<group>"; };
		F966BA7D08F27A38005CB29B /* pack.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = pack.n; sourceTree = "<group>"; };
		F966BA7E08F27A38005CB29B /* palette.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = palette.n; sourceTree = "<group>"; };
		F966BA7F08F27A38005CB29B /* panedwindow.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = panedwindow.n; sourceTree = "<group>"; };
		F966BA8008F27A38005CB29B /* ParseArgv.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ParseArgv.3; sourceTree = "<group>"; };
		F966BA8108F27A38005CB29B /* photo.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = photo.n; sourceTree = "<group>"; };
		F966BA8208F27A38005CB29B /* place.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = place.n; sourceTree = "<group>"; };
		F966BA8308F27A38005CB29B /* popup.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = popup.n; sourceTree = "<group>"; };
		F966BA8408F27A38005CB29B /* QWinEvent.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = QWinEvent.3; sourceTree = "<group>"; };
		F966BA8508F27A38005CB29B /* radiobutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = radiobutton.n; sourceTree = "<group>"; };
		F966BA8608F27A38005CB29B /* raise.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = raise.n; sourceTree = "<group>"; };
		F966BA8708F27A38005CB29B /* Restack.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Restack.3; sourceTree = "<group>"; };
		F966BA8808F27A38005CB29B /* RestrictEv.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = RestrictEv.3; sourceTree = "<group>"; };
		F966BA8908F27A38005CB29B /* scale.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = scale.n; sourceTree = "<group>"; };
		F966BA8A08F27A38005CB29B /* scrollbar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = scrollbar.n; sourceTree = "<group>"; };
		F966BA8B08F27A38005CB29B /* selection.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = selection.n; sourceTree = "<group>"; };
		F966BA8C08F27A38005CB29B /* send.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = send.n; sourceTree = "<group>"; };
		F966BA8D08F27A38005CB29B /* SetAppName.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetAppName.3; sourceTree = "<group>"; };
		F966BA8E08F27A38005CB29B /* SetCaret.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetCaret.3; sourceTree = "<group>"; };
		F966BA8F08F27A38005CB29B /* SetClass.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetClass.3; sourceTree = "<group>"; };
		F966BA9008F27A38005CB29B /* SetClassProcs.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetClassProcs.3; sourceTree = "<group>"; };
		F966BA9108F27A38005CB29B /* SetGrid.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetGrid.3; sourceTree = "<group>"; };
		F966BA9208F27A38005CB29B /* SetOptions.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetOptions.3; sourceTree = "<group>"; };
		F966BA9308F27A38005CB29B /* SetVisual.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetVisual.3; sourceTree = "<group>"; };
		F966BA9408F27A38005CB29B /* spinbox.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = spinbox.n; sourceTree = "<group>"; };
		F966BA9508F27A38005CB29B /* StrictMotif.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = StrictMotif.3; sourceTree = "<group>"; };
		F966BA9608F27A38005CB29B /* text.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = text.n; sourceTree = "<group>"; };
		F966BA9708F27A38005CB29B /* TextLayout.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TextLayout.3; sourceTree = "<group>"; };
		F966BA9808F27A38005CB29B /* tk.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tk.n; sourceTree = "<group>"; };
		F966BA9A08F27A38005CB29B /* Tk_Init.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Tk_Init.3; sourceTree = "<group>"; };
		F966BA9B08F27A38005CB29B /* Tk_Main.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Tk_Main.3; sourceTree = "<group>"; };
		F966BA9C08F27A38005CB29B /* tkerror.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tkerror.n; sourceTree = "<group>"; };
		F966BA9D08F27A38005CB29B /* TkInitStubs.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TkInitStubs.3; sourceTree = "<group>"; };
		F966BA9E08F27A38005CB29B /* tkvars.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tkvars.n; sourceTree = "<group>"; };
		F966BA9F08F27A38005CB29B /* tkwait.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tkwait.n; sourceTree = "<group>"; };
		F966BAA008F27A38005CB29B /* toplevel.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = toplevel.n; sourceTree = "<group>"; };
		F966BAA108F27A38005CB29B /* WindowId.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = WindowId.3; sourceTree = "<group>"; };
		F966BAA208F27A38005CB29B /* winfo.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = winfo.n; sourceTree = "<group>"; };
		F966BAA308F27A38005CB29B /* wish.1 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = wish.1; sourceTree = "<group>"; };
		F966BAA408F27A38005CB29B /* wm.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = wm.n; sourceTree = "<group>"; };
		F966BAA608F27A38005CB29B /* default.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = default.h; sourceTree = "<group>"; };
		F966BAA708F27A38005CB29B /* ks_names.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ks_names.h; sourceTree = "<group>"; };
		F966BAA908F27A39005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BAAA08F27A39005CB29B /* tk.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tk.decls; sourceTree = "<group>"; };
		F966BAAB08F27A39005CB29B /* tk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tk.h; sourceTree = "<group>"; };
		F966BAAC08F27A39005CB29B /* tk3d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tk3d.c; sourceTree = "<group>"; };
		F966BAAD08F27A39005CB29B /* tk3d.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tk3d.h; sourceTree = "<group>"; };
		F966BAAE08F27A39005CB29B /* tkArgv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkArgv.c; sourceTree = "<group>"; };
		F966BAAF08F27A39005CB29B /* tkAtom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkAtom.c; sourceTree = "<group>"; };
		F966BAB008F27A39005CB29B /* tkBind.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkBind.c; sourceTree = "<group>"; };
		F966BAB108F27A39005CB29B /* tkBitmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkBitmap.c; sourceTree = "<group>"; };
		F966BAB208F27A39005CB29B /* tkButton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkButton.c; sourceTree = "<group>"; };
		F966BAB308F27A39005CB29B /* tkButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkButton.h; sourceTree = "<group>"; };
		F966BAB408F27A39005CB29B /* tkCanvArc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvArc.c; sourceTree = "<group>"; };
		F966BAB508F27A39005CB29B /* tkCanvas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvas.c; sourceTree = "<group>"; };
		F966BAB608F27A39005CB29B /* tkCanvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkCanvas.h; sourceTree = "<group>"; };
		F966BAB708F27A39005CB29B /* tkCanvBmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvBmap.c; sourceTree = "<group>"; };
		F966BAB808F27A39005CB29B /* tkCanvImg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvImg.c; sourceTree = "<group>"; };
		F966BAB908F27A39005CB29B /* tkCanvLine.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvLine.c; sourceTree = "<group>"; };
		F966BABA08F27A39005CB29B /* tkCanvPoly.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvPoly.c; sourceTree = "<group>"; };
		F966BABB08F27A39005CB29B /* tkCanvPs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvPs.c; sourceTree = "<group>"; };
		F966BABD08F27A39005CB29B /* tkCanvText.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvText.c; sourceTree = "<group>"; };
		F966BABE08F27A39005CB29B /* tkCanvUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvUtil.c; sourceTree = "<group>"; };
		F966BABF08F27A39005CB29B /* tkCanvWind.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCanvWind.c; sourceTree = "<group>"; };
		F966BAC008F27A39005CB29B /* tkClipboard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkClipboard.c; sourceTree = "<group>"; };
		F966BAC108F27A39005CB29B /* tkCmds.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCmds.c; sourceTree = "<group>"; };
		F966BAC208F27A39005CB29B /* tkColor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkColor.c; sourceTree = "<group>"; };
		F966BAC308F27A39005CB29B /* tkColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkColor.h; sourceTree = "<group>"; };
		F966BAC408F27A39005CB29B /* tkConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkConfig.c; sourceTree = "<group>"; };
		F966BAC508F27A39005CB29B /* tkConsole.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkConsole.c; sourceTree = "<group>"; };
		F966BAC608F27A39005CB29B /* tkCursor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkCursor.c; sourceTree = "<group>"; };
		F966BAC708F27A39005CB29B /* tkDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkDecls.h; sourceTree = "<group>"; };
		F966BAC808F27A39005CB29B /* tkEntry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkEntry.c; sourceTree = "<group>"; };
		F966BAC908F27A39005CB29B /* tkEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkEntry.h; sourceTree = "<group>"; };
		F966BACA08F27A39005CB29B /* tkError.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkError.c; sourceTree = "<group>"; };
		F966BACB08F27A39005CB29B /* tkEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkEvent.c; sourceTree = "<group>"; };
		F966BACC08F27A39005CB29B /* tkFileFilter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkFileFilter.c; sourceTree = "<group>"; };
		F966BACD08F27A39005CB29B /* tkFileFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkFileFilter.h; sourceTree = "<group>"; };
		F966BACE08F27A39005CB29B /* tkFocus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkFocus.c; sourceTree = "<group>"; };
		F966BACF08F27A39005CB29B /* tkFont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkFont.c; sourceTree = "<group>"; };
		F966BAD008F27A39005CB29B /* tkFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkFont.h; sourceTree = "<group>"; };
		F966BAD108F27A39005CB29B /* tkFrame.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkFrame.c; sourceTree = "<group>"; };
		F966BAD208F27A39005CB29B /* tkGC.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkGC.c; sourceTree = "<group>"; };
		F966BAD308F27A39005CB29B /* tkGeometry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkGeometry.c; sourceTree = "<group>"; };
		F966BAD408F27A39005CB29B /* tkGet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkGet.c; sourceTree = "<group>"; };
		F966BAD508F27A39005CB29B /* tkGrab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkGrab.c; sourceTree = "<group>"; };
		F966BAD608F27A39005CB29B /* tkGrid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkGrid.c; sourceTree = "<group>"; };
		F966BAD708F27A39005CB29B /* tkImage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImage.c; sourceTree = "<group>"; };
		F966BAD808F27A39005CB29B /* tkImgBmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgBmap.c; sourceTree = "<group>"; };
		F966BAD908F27A39005CB29B /* tkImgGIF.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgGIF.c; sourceTree = "<group>"; };
		F966BADA08F27A39005CB29B /* tkImgPhoto.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgPhoto.c; sourceTree = "<group>"; };
		F966BADB08F27A39005CB29B /* tkImgPPM.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgPPM.c; sourceTree = "<group>"; };
		F966BADC08F27A39005CB29B /* tkImgUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgUtil.c; sourceTree = "<group>"; };
		F966BADE08F27A39005CB29B /* tkInt.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tkInt.decls; sourceTree = "<group>"; };
		F966BADF08F27A39005CB29B /* tkInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkInt.h; sourceTree = "<group>"; };
		F966BAE108F27A39005CB29B /* tkIntDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkIntDecls.h; sourceTree = "<group>"; };
		F966BAE208F27A39005CB29B /* tkIntPlatDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkIntPlatDecls.h; sourceTree = "<group>"; };
		F966BAE308F27A39005CB29B /* tkIntXlibDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkIntXlibDecls.h; sourceTree = "<group>"; };
		F966BAE408F27A39005CB29B /* tkListbox.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkListbox.c; sourceTree = "<group>"; };
		F966BAE508F27A39005CB29B /* tkMacWinMenu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMacWinMenu.c; sourceTree = "<group>"; };
		F966BAE608F27A39005CB29B /* tkMain.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMain.c; sourceTree = "<group>"; };
		F966BAE708F27A39005CB29B /* tkMenu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMenu.c; sourceTree = "<group>"; };
		F966BAE808F27A39005CB29B /* tkMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMenu.h; sourceTree = "<group>"; };
		F966BAE908F27A39005CB29B /* tkMenubutton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMenubutton.c; sourceTree = "<group>"; };
		F966BAEA08F27A39005CB29B /* tkMenubutton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMenubutton.h; sourceTree = "<group>"; };
		F966BAEB08F27A39005CB29B /* tkMenuDraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMenuDraw.c; sourceTree = "<group>"; };
		F966BAEC08F27A39005CB29B /* tkMessage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkMessage.c; sourceTree = "<group>"; };
		F966BAED08F27A39005CB29B /* tkObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkObj.c; sourceTree = "<group>"; };
		F966BAEE08F27A39005CB29B /* tkOldConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkOldConfig.c; sourceTree = "<group>"; };
		F966BAEF08F27A39005CB29B /* tkOption.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkOption.c; sourceTree = "<group>"; };
		F966BAF008F27A39005CB29B /* tkPack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkPack.c; sourceTree = "<group>"; };
		F966BAF108F27A39005CB29B /* tkPanedWindow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkPanedWindow.c; sourceTree = "<group>"; };
		F966BAF208F27A39005CB29B /* tkPlace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkPlace.c; sourceTree = "<group>"; };
		F966BAF308F27A39005CB29B /* tkPlatDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkPlatDecls.h; sourceTree = "<group>"; };
		F966BAF408F27A39005CB29B /* tkPointer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkPointer.c; sourceTree = "<group>"; };
		F966BAF508F27A39005CB29B /* tkPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkPort.h; sourceTree = "<group>"; };
		F966BAF608F27A39005CB29B /* tkRectOval.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkRectOval.c; sourceTree = "<group>"; };
		F966BAF708F27A39005CB29B /* tkScale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkScale.c; sourceTree = "<group>"; };
		F966BAF808F27A39005CB29B /* tkScale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkScale.h; sourceTree = "<group>"; };
		F966BAF908F27A39005CB29B /* tkScrollbar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkScrollbar.c; sourceTree = "<group>"; };
		F966BAFA08F27A39005CB29B /* tkScrollbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkScrollbar.h; sourceTree = "<group>"; };
		F966BAFB08F27A39005CB29B /* tkSelect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkSelect.c; sourceTree = "<group>"; };
		F966BAFC08F27A39005CB29B /* tkSelect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkSelect.h; sourceTree = "<group>"; };
		F966BAFD08F27A39005CB29B /* tkSquare.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkSquare.c; sourceTree = "<group>"; };
		F966BAFE08F27A39005CB29B /* tkOldTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkOldTest.c; sourceTree = "<group>"; };
		F966BAFF08F27A39005CB29B /* tkStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStubInit.c; sourceTree = "<group>"; };
		F966BB0008F27A39005CB29B /* tkStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStubLib.c; sourceTree = "<group>"; };
		F966BB0108F27A39005CB29B /* tkStyle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStyle.c; sourceTree = "<group>"; };
		F966BB0208F27A39005CB29B /* tkTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTest.c; sourceTree = "<group>"; };
		F966BB0308F27A39005CB29B /* tkText.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkText.c; sourceTree = "<group>"; };
		F966BB0408F27A39005CB29B /* tkText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkText.h; sourceTree = "<group>"; };
		F966BB0508F27A39005CB29B /* tkTextBTree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextBTree.c; sourceTree = "<group>"; };
		F966BB0608F27A39005CB29B /* tkTextDisp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextDisp.c; sourceTree = "<group>"; };
		F966BB0808F27A39005CB29B /* tkTextImage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextImage.c; sourceTree = "<group>"; };
		F966BB0908F27A39005CB29B /* tkTextIndex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextIndex.c; sourceTree = "<group>"; };
		F966BB0A08F27A39005CB29B /* tkTextMark.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextMark.c; sourceTree = "<group>"; };
		F966BB0B08F27A39005CB29B /* tkTextTag.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextTag.c; sourceTree = "<group>"; };
		F966BB0C08F27A39005CB29B /* tkTextWind.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextWind.c; sourceTree = "<group>"; };
		F966BB0D08F27A39005CB29B /* tkTrig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTrig.c; sourceTree = "<group>"; };
		F966BB0E08F27A39005CB29B /* tkUndo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUndo.c; sourceTree = "<group>"; };
		F966BB0F08F27A39005CB29B /* tkUndo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUndo.h; sourceTree = "<group>"; };
		F966BB1008F27A39005CB29B /* tkUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUtil.c; sourceTree = "<group>"; };
		F966BB1108F27A39005CB29B /* tkVisual.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkVisual.c; sourceTree = "<group>"; };
		F966BB1208F27A39005CB29B /* tkWindow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWindow.c; sourceTree = "<group>"; };
		F966BB1408F27A39005CB29B /* bgerror.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bgerror.tcl; sourceTree = "<group>"; };
		F966BB1508F27A39005CB29B /* button.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = button.tcl; sourceTree = "<group>"; };
		F966BB1608F27A39005CB29B /* choosedir.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = choosedir.tcl; sourceTree = "<group>"; };
		F966BB1708F27A39005CB29B /* clrpick.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clrpick.tcl; sourceTree = "<group>"; };
		F966BB1808F27A39005CB29B /* comdlg.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = comdlg.tcl; sourceTree = "<group>"; };
		F966BB1908F27A39005CB29B /* console.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = console.tcl; sourceTree = "<group>"; };
		F966BB1B08F27A39005CB29B /* anilabel.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = anilabel.tcl; sourceTree = "<group>"; };
		F966BB1C08F27A39005CB29B /* aniwave.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = aniwave.tcl; sourceTree = "<group>"; };
		F966BB1D08F27A39005CB29B /* arrow.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = arrow.tcl; sourceTree = "<group>"; };
		F966BB1E08F27A39005CB29B /* bind.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bind.tcl; sourceTree = "<group>"; };
		F966BB1F08F27A39005CB29B /* bitmap.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bitmap.tcl; sourceTree = "<group>"; };
		F966BB2008F27A39005CB29B /* browse */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = browse; sourceTree = "<group>"; };
		F966BB2108F27A39005CB29B /* button.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = button.tcl; sourceTree = "<group>"; };
		F966BB2208F27A39005CB29B /* check.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = check.tcl; sourceTree = "<group>"; };
		F966BB2308F27A39005CB29B /* clrpick.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clrpick.tcl; sourceTree = "<group>"; };
		F966BB2408F27A39005CB29B /* colors.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = colors.tcl; sourceTree = "<group>"; };
		F966BB2508F27A39005CB29B /* cscroll.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cscroll.tcl; sourceTree = "<group>"; };
		F966BB2608F27A39005CB29B /* ctext.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ctext.tcl; sourceTree = "<group>"; };
		F966BB2708F27A39005CB29B /* dialog1.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dialog1.tcl; sourceTree = "<group>"; };
		F966BB2808F27A39005CB29B /* dialog2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dialog2.tcl; sourceTree = "<group>"; };
		F966BB2A08F27A39005CB29B /* entry1.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry1.tcl; sourceTree = "<group>"; };
		F966BB2B08F27A39005CB29B /* entry2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry2.tcl; sourceTree = "<group>"; };
		F966BB2C08F27A39005CB29B /* entry3.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry3.tcl; sourceTree = "<group>"; };
		F966BB2D08F27A39005CB29B /* filebox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = filebox.tcl; sourceTree = "<group>"; };
		F966BB2E08F27A39005CB29B /* floor.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = floor.tcl; sourceTree = "<group>"; };
		F966BB2F08F27A39005CB29B /* form.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = form.tcl; sourceTree = "<group>"; };
		F966BB3008F27A39005CB29B /* goldberg.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = goldberg.tcl; sourceTree = "<group>"; };
		F966BB3108F27A39005CB29B /* hello */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = hello; sourceTree = "<group>"; };
		F966BB3208F27A39005CB29B /* hscale.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = hscale.tcl; sourceTree = "<group>"; };
		F966BB3308F27A39005CB29B /* icon.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = icon.tcl; sourceTree = "<group>"; };
		F966BB3408F27A39005CB29B /* image1.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = image1.tcl; sourceTree = "<group>"; };
		F966BB3508F27A39005CB29B /* image2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = image2.tcl; sourceTree = "<group>"; };
		F966BB4208F27A3A005CB29B /* items.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = items.tcl; sourceTree = "<group>"; };
		F966BB4308F27A3A005CB29B /* ixset */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = ixset; sourceTree = "<group>"; };
		F966BB4408F27A3A005CB29B /* label.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = label.tcl; sourceTree = "<group>"; };
		F966BB4508F27A3A005CB29B /* labelframe.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = labelframe.tcl; sourceTree = "<group>"; };
		F966BB4608F27A3A005CB29B /* menu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menu.tcl; sourceTree = "<group>"; };
		F966BB4708F27A3A005CB29B /* menubu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menubu.tcl; sourceTree = "<group>"; };
		F966BB4808F27A3A005CB29B /* msgbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgbox.tcl; sourceTree = "<group>"; };
		F966BB4A08F27A3A005CB29B /* paned1.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = paned1.tcl; sourceTree = "<group>"; };
		F966BB4B08F27A3A005CB29B /* paned2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = paned2.tcl; sourceTree = "<group>"; };
		F966BB4C08F27A3A005CB29B /* pendulum.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pendulum.tcl; sourceTree = "<group>"; };
		F966BB4D08F27A3A005CB29B /* plot.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = plot.tcl; sourceTree = "<group>"; };
		F966BB4E08F27A3A005CB29B /* puzzle.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = puzzle.tcl; sourceTree = "<group>"; };
		F966BB4F08F27A3A005CB29B /* radio.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = radio.tcl; sourceTree = "<group>"; };
		F966BB5008F27A3A005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BB5108F27A3A005CB29B /* rmt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = rmt; sourceTree = "<group>"; };
		F966BB5208F27A3A005CB29B /* rolodex */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = rolodex; sourceTree = "<group>"; };
		F966BB5308F27A3A005CB29B /* ruler.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ruler.tcl; sourceTree = "<group>"; };
		F966BB5408F27A3A005CB29B /* sayings.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = sayings.tcl; sourceTree = "<group>"; };
		F966BB5508F27A3A005CB29B /* search.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = search.tcl; sourceTree = "<group>"; };
		F966BB5608F27A3A005CB29B /* spin.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = spin.tcl; sourceTree = "<group>"; };
		F966BB5708F27A3A005CB29B /* square */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = square; sourceTree = "<group>"; };
		F966BB5808F27A3A005CB29B /* states.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = states.tcl; sourceTree = "<group>"; };
		F966BB5908F27A3A005CB29B /* style.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = style.tcl; sourceTree = "<group>"; };
		F966BB5A08F27A3A005CB29B /* tclIndex */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclIndex; sourceTree = "<group>"; };
		F966BB5B08F27A3A005CB29B /* tcolor */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = tcolor; sourceTree = "<group>"; };
		F966BB5C08F27A3A005CB29B /* text.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = text.tcl; sourceTree = "<group>"; };
		F966BB5D08F27A3A005CB29B /* timer */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = timer; sourceTree = "<group>"; };
		F966BB5E08F27A3A005CB29B /* twind.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = twind.tcl; sourceTree = "<group>"; };
		F966BB5F08F27A3A005CB29B /* unicodeout.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unicodeout.tcl; sourceTree = "<group>"; };
		F966BB6008F27A3A005CB29B /* vscale.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = vscale.tcl; sourceTree = "<group>"; };
		F966BB6108F27A3A005CB29B /* widget */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = widget; sourceTree = "<group>"; };
		F966BB6208F27A3A005CB29B /* dialog.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dialog.tcl; sourceTree = "<group>"; };
		F966BB6308F27A3A005CB29B /* entry.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry.tcl; sourceTree = "<group>"; };
		F966BB6408F27A3A005CB29B /* focus.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = focus.tcl; sourceTree = "<group>"; };
		F966BB7308F27A3A005CB29B /* listbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = listbox.tcl; sourceTree = "<group>"; };
		F966BB7408F27A3A005CB29B /* menu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menu.tcl; sourceTree = "<group>"; };
		F966BB7508F27A3A005CB29B /* mkpsenc.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = mkpsenc.tcl; sourceTree = "<group>"; };
		F966BB7608F27A3A005CB29B /* msgbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgbox.tcl; sourceTree = "<group>"; };
		F966BB8608F27A3A005CB29B /* obsolete.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = obsolete.tcl; sourceTree = "<group>"; };
		F966BB8708F27A3A005CB29B /* optMenu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = optMenu.tcl; sourceTree = "<group>"; };
		F966BB8808F27A3A005CB29B /* palette.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = palette.tcl; sourceTree = "<group>"; };
		F966BB8908F27A3B005CB29B /* panedwindow.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.tcl; sourceTree = "<group>"; };
		F966BB8B08F27A3B005CB29B /* safetk.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = safetk.tcl; sourceTree = "<group>"; };
		F966BB8C08F27A3B005CB29B /* scale.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scale.tcl; sourceTree = "<group>"; };
		F966BB8D08F27A3B005CB29B /* scrlbar.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scrlbar.tcl; sourceTree = "<group>"; };
		F966BB8E08F27A3B005CB29B /* spinbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = spinbox.tcl; sourceTree = "<group>"; };
		F966BB8F08F27A3B005CB29B /* tclIndex */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclIndex; sourceTree = "<group>"; };
		F966BB9008F27A3B005CB29B /* tearoff.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tearoff.tcl; sourceTree = "<group>"; };
		F966BB9108F27A3B005CB29B /* text.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = text.tcl; sourceTree = "<group>"; };
		F966BB9208F27A3B005CB29B /* tk.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tk.tcl; sourceTree = "<group>"; };
		F966BB9308F27A3B005CB29B /* tkfbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tkfbox.tcl; sourceTree = "<group>"; };
		F966BB9408F27A3B005CB29B /* unsupported.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unsupported.tcl; sourceTree = "<group>"; };
		F966BB9508F27A3B005CB29B /* xmfbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = xmfbox.tcl; sourceTree = "<group>"; };
		F966BB9608F27A3B005CB29B /* license.terms */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = license.terms; sourceTree = "<group>"; };
		F966BBBA08F27A3B005CB29B /* configure.ac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure.ac; sourceTree = "<group>"; };
		F966BBBB08F27A3B005CB29B /* GNUmakefile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = GNUmakefile; sourceTree = "<group>"; };
		F966BBBE08F27A3B005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BBC008F27A3B005CB29B /* Tk-Info.plist.in */ = {isa = PBXFileReference; explicitFileType = text.plist; fileEncoding = 4; path = "Tk-Info.plist.in"; sourceTree = "<group>"; };
		F966BBC208F27A3B005CB29B /* tkMacOSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSX.h; sourceTree = "<group>"; };
		F966BBC508F27A3B005CB29B /* tkMacOSXBitmap.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXBitmap.c; sourceTree = "<group>"; };
		F966BBC608F27A3B005CB29B /* tkMacOSXButton.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXButton.c; sourceTree = "<group>"; };
		F966BBC808F27A3B005CB29B /* tkMacOSXClipboard.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXClipboard.c; sourceTree = "<group>"; };
		F966BBC908F27A3B005CB29B /* tkMacOSXColor.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXColor.c; sourceTree = "<group>"; };
		F966BBCA08F27A3B005CB29B /* tkMacOSXConfig.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXConfig.c; sourceTree = "<group>"; };
		F966BBCB08F27A3B005CB29B /* tkMacOSXCursor.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXCursor.c; sourceTree = "<group>"; };
		F966BBCC08F27A3B005CB29B /* tkMacOSXCursors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXCursors.h; sourceTree = "<group>"; };
		F966BBCD08F27A3B005CB29B /* tkMacOSXDebug.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXDebug.c; sourceTree = "<group>"; };
		F966BBCE08F27A3B005CB29B /* tkMacOSXDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXDebug.h; sourceTree = "<group>"; };
		F966BBCF08F27A3B005CB29B /* tkMacOSXDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXDefault.h; sourceTree = "<group>"; };
		F966BBD008F27A3B005CB29B /* tkMacOSXDialog.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXDialog.c; sourceTree = "<group>"; };
		F966BBD108F27A3B005CB29B /* tkMacOSXDraw.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXDraw.c; sourceTree = "<group>"; };
		F966BBD208F27A3B005CB29B /* tkMacOSXEmbed.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEmbed.c; sourceTree = "<group>"; };
		F966BBD308F27A3B005CB29B /* tkMacOSXEntry.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEntry.c; sourceTree = "<group>"; };
		F966BBD408F27A3B005CB29B /* tkMacOSXEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEvent.c; sourceTree = "<group>"; };
		F966BBD508F27A3B005CB29B /* tkMacOSXEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXEvent.h; sourceTree = "<group>"; };
		F966BBD608F27A3B005CB29B /* tkMacOSXFont.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXFont.c; sourceTree = "<group>"; };
		F966BBD708F27A3B005CB29B /* tkMacOSXHLEvents.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXHLEvents.c; sourceTree = "<group>"; };
		F966BBD808F27A3B005CB29B /* tkMacOSXInit.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXInit.c; sourceTree = "<group>"; };
		F966BBDA08F27A3B005CB29B /* tkMacOSXInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXInt.h; sourceTree = "<group>"; };
		F966BBDB08F27A3B005CB29B /* tkMacOSXKeyboard.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXKeyboard.c; sourceTree = "<group>"; };
		F966BBDC08F27A3B005CB29B /* tkMacOSXKeyEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXKeyEvent.c; sourceTree = "<group>"; };
		F966BBDD08F27A3B005CB29B /* tkMacOSXMenu.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXMenu.c; sourceTree = "<group>"; };
		F966BBE008F27A3B005CB29B /* tkMacOSXMenubutton.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXMenubutton.c; sourceTree = "<group>"; };
		F966BBE108F27A3B005CB29B /* tkMacOSXMenus.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXMenus.c; sourceTree = "<group>"; };
		F966BBE208F27A3B005CB29B /* tkMacOSXMouseEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXMouseEvent.c; sourceTree = "<group>"; };
		F966BBE308F27A3B005CB29B /* tkMacOSXNotify.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXNotify.c; sourceTree = "<group>"; };
		F966BBEA08F27A3C005CB29B /* tkMacOSXPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXPort.h; sourceTree = "<group>"; };
		F966BBEB08F27A3C005CB29B /* tkMacOSXRegion.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXRegion.c; sourceTree = "<group>"; };
		F966BBEC08F27A3C005CB29B /* tkMacOSXScale.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXScale.c; sourceTree = "<group>"; };
		F966BBED08F27A3C005CB29B /* tkMacOSXScrlbr.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXScrlbr.c; sourceTree = "<group>"; };
		F966BBEE08F27A3C005CB29B /* tkMacOSXSend.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXSend.c; sourceTree = "<group>"; };
		F966BBEF08F27A3C005CB29B /* tkMacOSXSubwindows.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXSubwindows.c; sourceTree = "<group>"; };
		F966BBF008F27A3C005CB29B /* tkMacOSXTest.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXTest.c; sourceTree = "<group>"; };
		F966BBF108F27A3C005CB29B /* tkMacOSXWindowEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXWindowEvent.c; sourceTree = "<group>"; };
		F966BBF208F27A3C005CB29B /* tkMacOSXWm.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXWm.c; sourceTree = "<group>"; };
		F966BBF308F27A3C005CB29B /* tkMacOSXWm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXWm.h; sourceTree = "<group>"; };
		F966BBF408F27A3C005CB29B /* tkMacOSXXCursors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXXCursors.h; sourceTree = "<group>"; };
		F966BBF508F27A3C005CB29B /* tkMacOSXXStubs.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXXStubs.c; sourceTree = "<group>"; };
		F966BBF708F27A3C005CB29B /* Wish-Info.plist.in */ = {isa = PBXFileReference; explicitFileType = text.plist; fileEncoding = 4; path = "Wish-Info.plist.in"; sourceTree = "<group>"; };
		F966BC0308F27A3C005CB29B /* README */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = README; sourceTree = "<group>"; };
		F966BC0508F27A3C005CB29B /* all.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = all.tcl; sourceTree = "<group>"; };
		F966BC0608F27A3C005CB29B /* arc.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = arc.tcl; sourceTree = "<group>"; };
		F966BC0708F27A3C005CB29B /* bell.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bell.test; sourceTree = "<group>"; };
		F966BC0808F27A3C005CB29B /* bevel.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bevel.tcl; sourceTree = "<group>"; };
		F966BC0908F27A3C005CB29B /* bgerror.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bgerror.test; sourceTree = "<group>"; };
		F966BC0A08F27A3C005CB29B /* bind.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bind.test; sourceTree = "<group>"; };
		F966BC0B08F27A3C005CB29B /* bitmap.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bitmap.test; sourceTree = "<group>"; };
		F966BC0C08F27A3C005CB29B /* border.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = border.test; sourceTree = "<group>"; };
		F966BC0D08F27A3C005CB29B /* bugs.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = bugs.tcl; sourceTree = "<group>"; };
		F966BC0E08F27A3C005CB29B /* butGeom.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = butGeom.tcl; sourceTree = "<group>"; };
		F966BC0F08F27A3C005CB29B /* butGeom2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = butGeom2.tcl; sourceTree = "<group>"; };
		F966BC1008F27A3C005CB29B /* button.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = button.test; sourceTree = "<group>"; };
		F966BC1108F27A3C005CB29B /* canvas.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvas.test; sourceTree = "<group>"; };
		F966BC1208F27A3C005CB29B /* canvImg.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvImg.test; sourceTree = "<group>"; };
		F966BC1308F27A3C005CB29B /* canvPs.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPs.test; sourceTree = "<group>"; };
		F966BC1408F27A3C005CB29B /* canvPsArc.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPsArc.tcl; sourceTree = "<group>"; };
		F966BC1508F27A3C005CB29B /* canvPsBmap.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPsBmap.tcl; sourceTree = "<group>"; };
		F966BC1608F27A3C005CB29B /* canvPsGrph.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPsGrph.tcl; sourceTree = "<group>"; };
		F966BC1708F27A3C005CB29B /* canvPsImg.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPsImg.tcl; sourceTree = "<group>"; };
		F966BC1808F27A3C005CB29B /* canvPsText.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvPsText.tcl; sourceTree = "<group>"; };
		F966BC1908F27A3C005CB29B /* canvRect.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvRect.test; sourceTree = "<group>"; };
		F966BC1A08F27A3C005CB29B /* canvText.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvText.test; sourceTree = "<group>"; };
		F966BC1B08F27A3C005CB29B /* canvWind.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = canvWind.test; sourceTree = "<group>"; };
		F966BC1C08F27A3C005CB29B /* choosedir.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = choosedir.test; sourceTree = "<group>"; };
		F966BC1D08F27A3C005CB29B /* clipboard.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clipboard.test; sourceTree = "<group>"; };
		F966BC1E08F27A3C005CB29B /* clrpick.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clrpick.test; sourceTree = "<group>"; };
		F966BC1F08F27A3C005CB29B /* cmap.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmap.tcl; sourceTree = "<group>"; };
		F966BC2008F27A3C005CB29B /* cmds.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmds.test; sourceTree = "<group>"; };
		F966BC2108F27A3C005CB29B /* color.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = color.test; sourceTree = "<group>"; };
		F966BC2208F27A3C005CB29B /* config.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = config.test; sourceTree = "<group>"; };
		F966BC2308F27A3C005CB29B /* constraints.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = constraints.tcl; sourceTree = "<group>"; };
		F966BC2408F27A3C005CB29B /* cursor.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cursor.test; sourceTree = "<group>"; };
		F966BC2508F27A3C005CB29B /* dialog.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dialog.test; sourceTree = "<group>"; };
		F966BC2608F27A3C005CB29B /* embed.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = embed.test; sourceTree = "<group>"; };
		F966BC2708F27A3C005CB29B /* entry.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry.test; sourceTree = "<group>"; };
		F966BC2808F27A3C005CB29B /* event.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = event.test; sourceTree = "<group>"; };
		F966BC2908F27A3C005CB29B /* filebox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = filebox.test; sourceTree = "<group>"; };
		F966BC2A08F27A3C005CB29B /* focus.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = focus.test; sourceTree = "<group>"; };
		F966BC2B08F27A3C005CB29B /* focusTcl.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = focusTcl.test; sourceTree = "<group>"; };
		F966BC2C08F27A3C005CB29B /* font.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = font.test; sourceTree = "<group>"; };
		F966BC2D08F27A3C005CB29B /* frame.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = frame.test; sourceTree = "<group>"; };
		F966BC2E08F27A3C005CB29B /* geometry.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = geometry.test; sourceTree = "<group>"; };
		F966BC2F08F27A3C005CB29B /* get.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = get.test; sourceTree = "<group>"; };
		F966BC3008F27A3C005CB29B /* grab.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = grab.test; sourceTree = "<group>"; };
		F966BC3108F27A3C005CB29B /* grid.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = grid.test; sourceTree = "<group>"; };
		F966BC3308F27A3C005CB29B /* image.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = image.test; sourceTree = "<group>"; };
		F966BC3408F27A3C005CB29B /* imgBmap.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = imgBmap.test; sourceTree = "<group>"; };
		F966BC3508F27A3C005CB29B /* imgPhoto.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = imgPhoto.test; sourceTree = "<group>"; };
		F966BC3608F27A3C005CB29B /* imgPPM.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = imgPPM.test; sourceTree = "<group>"; };
		F966BC3708F27A3C005CB29B /* listbox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = listbox.test; sourceTree = "<group>"; };
		F966BC3808F27A3C005CB29B /* main.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = main.test; sourceTree = "<group>"; };
		F966BC3908F27A3C005CB29B /* menu.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menu.test; sourceTree = "<group>"; };
		F966BC3A08F27A3C005CB29B /* menubut.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menubut.test; sourceTree = "<group>"; };
		F966BC3B08F27A3C005CB29B /* menuDraw.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menuDraw.test; sourceTree = "<group>"; };
		F966BC3C08F27A3C005CB29B /* message.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = message.test; sourceTree = "<group>"; };
		F966BC3D08F27A3C005CB29B /* msgbox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgbox.test; sourceTree = "<group>"; };
		F966BC3E08F27A3C005CB29B /* obj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = obj.test; sourceTree = "<group>"; };
		F966BC3F08F27A3C005CB29B /* oldpack.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = oldpack.test; sourceTree = "<group>"; };
		F966BC4008F27A3C005CB29B /* option.file1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = option.file1; sourceTree = "<group>"; };
		F966BC4108F27A3C005CB29B /* option.file2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = option.file2; sourceTree = "<group>"; };
		F966BC4208F27A3C005CB29B /* option.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = option.test; sourceTree = "<group>"; };
		F966BC4308F27A3C005CB29B /* pack.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pack.test; sourceTree = "<group>"; };
		F966BC4408F27A3C005CB29B /* panedwindow.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.test; sourceTree = "<group>"; };
		F966BC4508F27A3D005CB29B /* place.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = place.test; sourceTree = "<group>"; };
		F966BC4608F27A3D005CB29B /* raise.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = raise.test; sourceTree = "<group>"; };
		F966BC4708F27A3D005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BC4808F27A3D005CB29B /* safe.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = safe.test; sourceTree = "<group>"; };
		F966BC4908F27A3D005CB29B /* scale.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scale.test; sourceTree = "<group>"; };
		F966BC4A08F27A3D005CB29B /* scrollbar.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scrollbar.test; sourceTree = "<group>"; };
		F966BC4B08F27A3D005CB29B /* select.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = select.test; sourceTree = "<group>"; };
		F966BC4C08F27A3D005CB29B /* send.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = send.test; sourceTree = "<group>"; };
		F966BC4D08F27A3D005CB29B /* spinbox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = spinbox.test; sourceTree = "<group>"; };
		F966BC4E08F27A3D005CB29B /* text.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = text.test; sourceTree = "<group>"; };
		F966BC4F08F27A3D005CB29B /* textBTree.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textBTree.test; sourceTree = "<group>"; };
		F966BC5008F27A3D005CB29B /* textDisp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textDisp.test; sourceTree = "<group>"; };
		F966BC5108F27A3D005CB29B /* textImage.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textImage.test; sourceTree = "<group>"; };
		F966BC5208F27A3D005CB29B /* textIndex.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textIndex.test; sourceTree = "<group>"; };
		F966BC5308F27A3D005CB29B /* textMark.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textMark.test; sourceTree = "<group>"; };
		F966BC5408F27A3D005CB29B /* textTag.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textTag.test; sourceTree = "<group>"; };
		F966BC5508F27A3D005CB29B /* textWind.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = textWind.test; sourceTree = "<group>"; };
		F966BC5608F27A3D005CB29B /* tk.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tk.test; sourceTree = "<group>"; };
		F966BC5708F27A3D005CB29B /* unixButton.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixButton.test; sourceTree = "<group>"; };
		F966BC5808F27A3D005CB29B /* unixEmbed.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixEmbed.test; sourceTree = "<group>"; };
		F966BC5908F27A3D005CB29B /* unixFont.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixFont.test; sourceTree = "<group>"; };
		F966BC5A08F27A3D005CB29B /* unixMenu.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixMenu.test; sourceTree = "<group>"; };
		F966BC5B08F27A3D005CB29B /* unixSelect.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixSelect.test; sourceTree = "<group>"; };
		F966BC5C08F27A3D005CB29B /* unixWm.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixWm.test; sourceTree = "<group>"; };
		F966BC5D08F27A3D005CB29B /* util.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = util.test; sourceTree = "<group>"; };
		F966BC5E08F27A3D005CB29B /* visual.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = visual.test; sourceTree = "<group>"; };
		F966BC5F08F27A3D005CB29B /* visual_bb.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = visual_bb.test; sourceTree = "<group>"; };
		F966BC6008F27A3D005CB29B /* winButton.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winButton.test; sourceTree = "<group>"; };
		F966BC6108F27A3D005CB29B /* winClipboard.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winClipboard.test; sourceTree = "<group>"; };
		F966BC6208F27A3D005CB29B /* winDialog.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winDialog.test; sourceTree = "<group>"; };
		F966BC6308F27A3D005CB29B /* window.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = window.test; sourceTree = "<group>"; };
		F966BC6408F27A3D005CB29B /* winfo.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winfo.test; sourceTree = "<group>"; };
		F966BC6508F27A3D005CB29B /* winFont.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winFont.test; sourceTree = "<group>"; };
		F966BC6608F27A3D005CB29B /* winMenu.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winMenu.test; sourceTree = "<group>"; };
		F966BC6708F27A3D005CB29B /* winSend.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winSend.test; sourceTree = "<group>"; };
		F966BC6808F27A3D005CB29B /* winWm.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winWm.test; sourceTree = "<group>"; };
		F966BC6908F27A3D005CB29B /* wm.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = wm.test; sourceTree = "<group>"; };
		F966BC6A08F27A3D005CB29B /* xmfbox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = xmfbox.test; sourceTree = "<group>"; };
		F966BC6C08F27A3D005CB29B /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = "<group>"; };
		F966BC6D08F27A3D005CB29B /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F966BC6E08F27A3D005CB29B /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F966BC6F08F27A3D005CB29B /* install-sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "install-sh"; sourceTree = "<group>"; };
		F966BC7008F27A3D005CB29B /* installManPage */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = installManPage; sourceTree = "<group>"; };
		F966BC7108F27A3D005CB29B /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F966BC7208F27A3D005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BC7308F27A3D005CB29B /* tcl.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tcl.m4; sourceTree = "<group>"; };
		F966BC7408F27A3D005CB29B /* tk.spec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tk.spec; sourceTree = "<group>"; };
		F966BC7508F27A3D005CB29B /* tkAppInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkAppInit.c; sourceTree = "<group>"; };
		F966BC7608F27A3D005CB29B /* tkConfig.h.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = tkConfig.h.in; sourceTree = "<group>"; };
		F966BC7708F27A3D005CB29B /* tkConfig.sh.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tkConfig.sh.in; sourceTree = "<group>"; };
		F966BC7808F27A3D005CB29B /* tkUnix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnix.c; sourceTree = "<group>"; };
		F966BC7908F27A3D005CB29B /* tkUnix3d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnix3d.c; sourceTree = "<group>"; };
		F966BC7A08F27A3D005CB29B /* tkUnixButton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixButton.c; sourceTree = "<group>"; };
		F966BC7B08F27A3D005CB29B /* tkUnixColor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixColor.c; sourceTree = "<group>"; };
		F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixConfig.c; sourceTree = "<group>"; };
		F966BC7D08F27A3D005CB29B /* tkUnixCursor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixCursor.c; sourceTree = "<group>"; };
		F966BC7E08F27A3D005CB29B /* tkUnixDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUnixDefault.h; sourceTree = "<group>"; };
		F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixDialog.c; sourceTree = "<group>"; };
		F966BC8008F27A3D005CB29B /* tkUnixDraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixDraw.c; sourceTree = "<group>"; };
		F966BC8108F27A3D005CB29B /* tkUnixEmbed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixEmbed.c; sourceTree = "<group>"; };
		F966BC8208F27A3D005CB29B /* tkUnixEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixEvent.c; sourceTree = "<group>"; };
		F966BC8308F27A3D005CB29B /* tkUnixFocus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixFocus.c; sourceTree = "<group>"; };
		F966BC8408F27A3D005CB29B /* tkUnixFont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixFont.c; sourceTree = "<group>"; };
		F966BC8508F27A3D005CB29B /* tkUnixInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixInit.c; sourceTree = "<group>"; };
		F966BC8608F27A3D005CB29B /* tkUnixInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUnixInt.h; sourceTree = "<group>"; };
		F966BC8708F27A3D005CB29B /* tkUnixKey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixKey.c; sourceTree = "<group>"; };
		F966BC8808F27A3D005CB29B /* tkUnixMenu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixMenu.c; sourceTree = "<group>"; };
		F966BC8908F27A3D005CB29B /* tkUnixMenubu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixMenubu.c; sourceTree = "<group>"; };
		F966BC8A08F27A3D005CB29B /* tkUnixPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUnixPort.h; sourceTree = "<group>"; };
		F966BC8B08F27A3D005CB29B /* tkUnixRFont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixRFont.c; sourceTree = "<group>"; };
		F966BC8C08F27A3D005CB29B /* tkUnixScale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixScale.c; sourceTree = "<group>"; };
		F966BC8D08F27A3D005CB29B /* tkUnixScrlbr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixScrlbr.c; sourceTree = "<group>"; };
		F966BC8E08F27A3D005CB29B /* tkUnixSelect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixSelect.c; sourceTree = "<group>"; };
		F966BC8F08F27A3D005CB29B /* tkUnixSend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixSend.c; sourceTree = "<group>"; };
		F966BC9008F27A3D005CB29B /* tkUnixWm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixWm.c; sourceTree = "<group>"; };
		F966BC9108F27A3D005CB29B /* tkUnixXId.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixXId.c; sourceTree = "<group>"; };
		F966BC9408F27A3D005CB29B /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = "<group>"; };
		F966BC9508F27A3D005CB29B /* buildall.vc.bat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = buildall.vc.bat; sourceTree = "<group>"; };
		F966BC9608F27A3E005CB29B /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F966BC9708F27A3E005CB29B /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F966BC9908F27A3E005CB29B /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F966BC9A08F27A3E005CB29B /* makefile.vc */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = makefile.vc; sourceTree = "<group>"; };
		F966BC9C08F27A3E005CB29B /* nmakehlp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nmakehlp.c; sourceTree = "<group>"; };
		F966BCEE08F27A3E005CB29B /* tk.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tk.rc; sourceTree = "<group>"; };
		F966BCEF08F27A3E005CB29B /* tk_base.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tk_base.rc; sourceTree = "<group>"; };
		F966BCF208F27A3E005CB29B /* wish.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = wish.rc; sourceTree = "<group>"; };
		F966BCF308F27A3E005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BCF508F27A3F005CB29B /* rules.vc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = rules.vc; sourceTree = "<group>"; };
		F966BCF608F27A3F005CB29B /* stubs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stubs.c; sourceTree = "<group>"; };
		F966BCF708F27A3F005CB29B /* tcl.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tcl.m4; sourceTree = "<group>"; };
		F966BCF808F27A3F005CB29B /* tkConfig.sh.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tkConfig.sh.in; sourceTree = "<group>"; };
		F966BCF908F27A3F005CB29B /* tkWin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkWin.h; sourceTree = "<group>"; };
		F966BCFA08F27A3F005CB29B /* tkWin32Dll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWin32Dll.c; sourceTree = "<group>"; };
		F966BCFB08F27A3F005CB29B /* tkWin3d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWin3d.c; sourceTree = "<group>"; };
		F966BCFC08F27A3F005CB29B /* tkWinButton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinButton.c; sourceTree = "<group>"; };
		F966BCFD08F27A3F005CB29B /* tkWinClipboard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinClipboard.c; sourceTree = "<group>"; };
		F966BCFE08F27A3F005CB29B /* tkWinColor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinColor.c; sourceTree = "<group>"; };
		F966BCFF08F27A3F005CB29B /* tkWinConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinConfig.c; sourceTree = "<group>"; };
		F966BD0008F27A3F005CB29B /* tkWinCursor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinCursor.c; sourceTree = "<group>"; };
		F966BD0108F27A3F005CB29B /* tkWinDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkWinDefault.h; sourceTree = "<group>"; };
		F966BD0208F27A3F005CB29B /* tkWinDialog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinDialog.c; sourceTree = "<group>"; };
		F966BD0308F27A3F005CB29B /* tkWinDraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinDraw.c; sourceTree = "<group>"; };
		F966BD0408F27A3F005CB29B /* tkWinEmbed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinEmbed.c; sourceTree = "<group>"; };
		F966BD0508F27A3F005CB29B /* tkWinFont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinFont.c; sourceTree = "<group>"; };
		F966BD0708F27A3F005CB29B /* tkWinImage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinImage.c; sourceTree = "<group>"; };
		F966BD0808F27A3F005CB29B /* tkWinInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinInit.c; sourceTree = "<group>"; };
		F966BD0908F27A3F005CB29B /* tkWinInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkWinInt.h; sourceTree = "<group>"; };
		F966BD0A08F27A3F005CB29B /* tkWinKey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinKey.c; sourceTree = "<group>"; };
		F966BD0B08F27A3F005CB29B /* tkWinMenu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinMenu.c; sourceTree = "<group>"; };
		F966BD0C08F27A3F005CB29B /* tkWinPixmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinPixmap.c; sourceTree = "<group>"; };
		F966BD0D08F27A3F005CB29B /* tkWinPointer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinPointer.c; sourceTree = "<group>"; };
		F966BD0E08F27A3F005CB29B /* tkWinPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkWinPort.h; sourceTree = "<group>"; };
		F966BD0F08F27A3F005CB29B /* tkWinRegion.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinRegion.c; sourceTree = "<group>"; };
		F966BD1008F27A3F005CB29B /* tkWinScrlbr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinScrlbr.c; sourceTree = "<group>"; };
		F966BD1108F27A3F005CB29B /* tkWinSend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinSend.c; sourceTree = "<group>"; };
		F966BD1208F27A3F005CB29B /* tkWinSendCom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinSendCom.c; sourceTree = "<group>"; };
		F966BD1308F27A3F005CB29B /* tkWinSendCom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkWinSendCom.h; sourceTree = "<group>"; };
		F966BD1408F27A3F005CB29B /* tkWinTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinTest.c; sourceTree = "<group>"; };
		F966BD1508F27A3F005CB29B /* tkWinWindow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinWindow.c; sourceTree = "<group>"; };
		F966BD1608F27A3F005CB29B /* tkWinWm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinWm.c; sourceTree = "<group>"; };
		F966BD1708F27A3F005CB29B /* tkWinX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkWinX.c; sourceTree = "<group>"; };
		F966BD1808F27A3F005CB29B /* winMain.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = winMain.c; sourceTree = "<group>"; };
		F966BD1B08F27A3F005CB29B /* cursorfont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cursorfont.h; sourceTree = "<group>"; };
		F966BD1C08F27A3F005CB29B /* keysym.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = keysym.h; sourceTree = "<group>"; };
		F966BD1D08F27A3F005CB29B /* keysymdef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = keysymdef.h; sourceTree = "<group>"; };
		F966BD1E08F27A3F005CB29B /* X.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = X.h; sourceTree = "<group>"; };
		F966BD1F08F27A3F005CB29B /* Xatom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Xatom.h; sourceTree = "<group>"; };
		F966BD2008F27A3F005CB29B /* Xfuncproto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Xfuncproto.h; sourceTree = "<group>"; };
		F966BD2108F27A3F005CB29B /* Xlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Xlib.h; sourceTree = "<group>"; };
		F966BD2208F27A3F005CB29B /* Xutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Xutil.h; sourceTree = "<group>"; };
		F966BD2308F27A3F005CB29B /* xbytes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xbytes.h; sourceTree = "<group>"; };
		F966BD2408F27A3F005CB29B /* xcolors.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xcolors.c; sourceTree = "<group>"; };
		F966BD2508F27A3F005CB29B /* xdraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xdraw.c; sourceTree = "<group>"; };
		F966BD2608F27A3F005CB29B /* xgc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xgc.c; sourceTree = "<group>"; };
		F966BD2708F27A3F005CB29B /* ximage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ximage.c; sourceTree = "<group>"; };
		F966BD2808F27A3F005CB29B /* xutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xutil.c; sourceTree = "<group>"; };
		F966C07408F2820D005CB29B /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
		F966C07608F2821B005CB29B /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
		F966C07808F28233005CB29B /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
		F96887E00AF786D5000797B5 /* ttk.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttk.decls; sourceTree = "<group>"; };
		F96887E10AF786D5000797B5 /* ttkBlink.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkBlink.c; sourceTree = "<group>"; };
		F96887E20AF786D5000797B5 /* ttkButton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkButton.c; sourceTree = "<group>"; };
		F96887E30AF786D5000797B5 /* ttkCache.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkCache.c; sourceTree = "<group>"; };
		F96887E40AF786D5000797B5 /* ttkClamTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkClamTheme.c; sourceTree = "<group>"; };
		F96887E50AF786D5000797B5 /* ttkClassicTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkClassicTheme.c; sourceTree = "<group>"; };
		F96887E60AF786D5000797B5 /* ttkDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttkDecls.h; sourceTree = "<group>"; };
		F96887E70AF786D5000797B5 /* ttkDefaultTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkDefaultTheme.c; sourceTree = "<group>"; };
		F96887E80AF786D5000797B5 /* ttkElements.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkElements.c; sourceTree = "<group>"; };
		F96887E90AF786D5000797B5 /* ttkEntry.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkEntry.c; sourceTree = "<group>"; };
		F96887EA0AF786D5000797B5 /* ttkFrame.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkFrame.c; sourceTree = "<group>"; };
		F96887EB0AF786D5000797B5 /* ttkImage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkImage.c; sourceTree = "<group>"; };
		F96887EC0AF786D5000797B5 /* ttkInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkInit.c; sourceTree = "<group>"; };
		F96887ED0AF786D5000797B5 /* ttkLabel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkLabel.c; sourceTree = "<group>"; };
		F96887EE0AF786D5000797B5 /* ttkLayout.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkLayout.c; sourceTree = "<group>"; };
		F96887EF0AF786D5000797B5 /* ttkManager.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkManager.c; sourceTree = "<group>"; };
		F96887F00AF786D5000797B5 /* ttkManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttkManager.h; sourceTree = "<group>"; };
		F96887F10AF786D5000797B5 /* ttkNotebook.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkNotebook.c; sourceTree = "<group>"; };
		F96887F20AF786D5000797B5 /* ttkPanedwindow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkPanedwindow.c; sourceTree = "<group>"; };
		F96887F30AF786D5000797B5 /* ttkProgress.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkProgress.c; sourceTree = "<group>"; };
		F96887F40AF786D5000797B5 /* ttkScale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkScale.c; sourceTree = "<group>"; };
		F96887F50AF786D5000797B5 /* ttkScroll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkScroll.c; sourceTree = "<group>"; };
		F96887F60AF786D5000797B5 /* ttkScrollbar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkScrollbar.c; sourceTree = "<group>"; };
		F96887F70AF786D5000797B5 /* ttkSeparator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkSeparator.c; sourceTree = "<group>"; };
		F96887F80AF786D5000797B5 /* ttkSquare.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkSquare.c; sourceTree = "<group>"; };
		F96887F90AF786D5000797B5 /* ttkState.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkState.c; sourceTree = "<group>"; };
		F96887FA0AF786D5000797B5 /* ttkStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkStubInit.c; sourceTree = "<group>"; };
		F96887FB0AF786D5000797B5 /* ttkStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkStubLib.c; sourceTree = "<group>"; };
		F96887FC0AF786D5000797B5 /* ttkTagSet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkTagSet.c; sourceTree = "<group>"; };
		F96887FD0AF786D5000797B5 /* ttkTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkTheme.c; sourceTree = "<group>"; };
		F96887FE0AF786D5000797B5 /* ttkTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttkTheme.h; sourceTree = "<group>"; };
		F96887FF0AF786D5000797B5 /* ttkThemeInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttkThemeInt.h; sourceTree = "<group>"; };
		F96888000AF786D5000797B5 /* ttkTrace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkTrace.c; sourceTree = "<group>"; };
		F96888010AF786D5000797B5 /* ttkTrack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkTrack.c; sourceTree = "<group>"; };
		F96888020AF786D5000797B5 /* ttkTreeview.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkTreeview.c; sourceTree = "<group>"; };
		F96888030AF786D5000797B5 /* ttkWidget.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWidget.c; sourceTree = "<group>"; };
		F96888040AF786D5000797B5 /* ttkWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ttkWidget.h; sourceTree = "<group>"; };
		F96888370AF787B3000797B5 /* altTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = altTheme.tcl; sourceTree = "<group>"; };
		F96888380AF787B3000797B5 /* aquaTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = aquaTheme.tcl; sourceTree = "<group>"; };
		F96888390AF787B3000797B5 /* button.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = button.tcl; sourceTree = "<group>"; };
		F968883A0AF787B3000797B5 /* clamTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clamTheme.tcl; sourceTree = "<group>"; };
		F968883B0AF787B3000797B5 /* classicTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = classicTheme.tcl; sourceTree = "<group>"; };
		F968883C0AF787B3000797B5 /* combobox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = combobox.tcl; sourceTree = "<group>"; };
		F968883D0AF787B3000797B5 /* cursors.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cursors.tcl; sourceTree = "<group>"; };
		F968883E0AF787B3000797B5 /* defaults.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = defaults.tcl; sourceTree = "<group>"; };
		F96888400AF787B3000797B5 /* entry.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry.tcl; sourceTree = "<group>"; };
		F96888410AF787B3000797B5 /* fonts.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fonts.tcl; sourceTree = "<group>"; };
		F96888440AF787B3000797B5 /* menubutton.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menubutton.tcl; sourceTree = "<group>"; };
		F96888450AF787B3000797B5 /* notebook.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = notebook.tcl; sourceTree = "<group>"; };
		F96888460AF787B3000797B5 /* panedwindow.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.tcl; sourceTree = "<group>"; };
		F96888470AF787B3000797B5 /* progress.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = progress.tcl; sourceTree = "<group>"; };
		F96888480AF787B3000797B5 /* scale.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scale.tcl; sourceTree = "<group>"; };
		F96888490AF787B3000797B5 /* scrollbar.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scrollbar.tcl; sourceTree = "<group>"; };
		F968884A0AF787B3000797B5 /* sizegrip.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = sizegrip.tcl; sourceTree = "<group>"; };
		F968884B0AF787B3000797B5 /* treeview.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = treeview.tcl; sourceTree = "<group>"; };
		F968884C0AF787B3000797B5 /* ttk.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttk.tcl; sourceTree = "<group>"; };
		F968884D0AF787B3000797B5 /* utils.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = utils.tcl; sourceTree = "<group>"; };
		F968884E0AF787B3000797B5 /* winTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winTheme.tcl; sourceTree = "<group>"; };
		F968884F0AF787B3000797B5 /* xpTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = xpTheme.tcl; sourceTree = "<group>"; };
		F96888540AF7880C000797B5 /* all.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = all.tcl; sourceTree = "<group>"; };
		F96888560AF7880C000797B5 /* combobox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = combobox.test; sourceTree = "<group>"; };
		F96888570AF7880C000797B5 /* entry.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry.test; sourceTree = "<group>"; };
		F96888580AF7880C000797B5 /* image.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = image.test; sourceTree = "<group>"; };
		F96888590AF7880C000797B5 /* labelframe.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = labelframe.test; sourceTree = "<group>"; };
		F968885A0AF7880C000797B5 /* layout.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = layout.test; sourceTree = "<group>"; };
		F968885C0AF7880C000797B5 /* notebook.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = notebook.test; sourceTree = "<group>"; };
		F968885D0AF7880C000797B5 /* panedwindow.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.test; sourceTree = "<group>"; };
		F968885E0AF7880C000797B5 /* progressbar.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = progressbar.test; sourceTree = "<group>"; };
		F968885F0AF7880C000797B5 /* scrollbar.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scrollbar.test; sourceTree = "<group>"; };
		F96888600AF7880C000797B5 /* treetags.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = treetags.test; sourceTree = "<group>"; };
		F96888610AF7880C000797B5 /* treeview.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = treeview.test; sourceTree = "<group>"; };
		F96888620AF7880C000797B5 /* ttk.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ttk.test; sourceTree = "<group>"; };
		F96888630AF7880C000797B5 /* validate.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = validate.test; sourceTree = "<group>"; };
		F968886B0AF788F6000797B5 /* ttk_button.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_button.n; sourceTree = "<group>"; };
		F968886C0AF788F6000797B5 /* ttk_checkbutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_checkbutton.n; sourceTree = "<group>"; };
		F968886D0AF788F6000797B5 /* ttk_combobox.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_combobox.n; sourceTree = "<group>"; };
		F968886F0AF788F6000797B5 /* ttk_entry.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_entry.n; sourceTree = "<group>"; };
		F96888700AF788F6000797B5 /* ttk_frame.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_frame.n; sourceTree = "<group>"; };
		F96888710AF788F6000797B5 /* ttk_Geometry.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_Geometry.3; sourceTree = "<group>"; };
		F96888720AF788F6000797B5 /* ttk_image.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_image.n; sourceTree = "<group>"; };
		F96888730AF788F6000797B5 /* ttk_intro.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_intro.n; sourceTree = "<group>"; };
		F96888740AF788F6000797B5 /* ttk_label.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_label.n; sourceTree = "<group>"; };
		F96888750AF788F6000797B5 /* ttk_labelframe.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_labelframe.n; sourceTree = "<group>"; };
		F96888760AF788F6000797B5 /* ttk_menubutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_menubutton.n; sourceTree = "<group>"; };
		F96888770AF788F6000797B5 /* ttk_notebook.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_notebook.n; sourceTree = "<group>"; };
		F96888780AF788F6000797B5 /* ttk_panedwindow.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_panedwindow.n; sourceTree = "<group>"; };
		F96888790AF788F6000797B5 /* ttk_progressbar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_progressbar.n; sourceTree = "<group>"; };
		F968887A0AF788F6000797B5 /* ttk_radiobutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_radiobutton.n; sourceTree = "<group>"; };
		F968887B0AF788F6000797B5 /* ttk_scrollbar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_scrollbar.n; sourceTree = "<group>"; };
		F968887C0AF788F6000797B5 /* ttk_separator.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_separator.n; sourceTree = "<group>"; };
		F968887D0AF788F6000797B5 /* ttk_sizegrip.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_sizegrip.n; sourceTree = "<group>"; };
		F968887E0AF788F6000797B5 /* ttk_style.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_style.n; sourceTree = "<group>"; };
		F968887F0AF788F6000797B5 /* ttk_Theme.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_Theme.3; sourceTree = "<group>"; };
		F96888800AF788F6000797B5 /* ttk_treeview.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_treeview.n; sourceTree = "<group>"; };
		F96888810AF788F6000797B5 /* ttk_widget.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_widget.n; sourceTree = "<group>"; };
		F96888840AF78938000797B5 /* ttkMacOSXTheme.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = ttkMacOSXTheme.c; sourceTree = "<group>"; };
		F96888860AF78953000797B5 /* ttkWinMonitor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinMonitor.c; sourceTree = "<group>"; };
		F96888870AF78953000797B5 /* ttkWinTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinTheme.c; sourceTree = "<group>"; };
		F96888880AF78953000797B5 /* ttkWinXPTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinXPTheme.c; sourceTree = "<group>"; };
		F96D3DFA08F272A4004A47F5 /* ChangeLog */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = ChangeLog; sourceTree = "<group>"; };
		F96D3DFB08F272A4004A47F5 /* changes */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes; sourceTree = "<group>"; };
		F96D3DFD08F272A4004A47F5 /* Access.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Access.3; sourceTree = "<group>"; };
		F96D3DFE08F272A4004A47F5 /* AddErrInfo.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AddErrInfo.3; sourceTree = "<group>"; };
		F96D3DFF08F272A4004A47F5 /* after.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = after.n; sourceTree = "<group>"; };
		F96D3E0008F272A4004A47F5 /* Alloc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Alloc.3; sourceTree = "<group>"; };
		F96D3E0108F272A4004A47F5 /* AllowExc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AllowExc.3; sourceTree = "<group>"; };
		F96D3E0208F272A4004A47F5 /* append.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = append.n; sourceTree = "<group>"; };
		F96D3E0308F272A4004A47F5 /* AppInit.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AppInit.3; sourceTree = "<group>"; };
		F96D3E0408F272A5004A47F5 /* array.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = array.n; sourceTree = "<group>"; };
		F96D3E0508F272A5004A47F5 /* AssocData.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AssocData.3; sourceTree = "<group>"; };
		F96D3E0608F272A5004A47F5 /* Async.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Async.3; sourceTree = "<group>"; };
		F96D3E0708F272A5004A47F5 /* BackgdErr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = BackgdErr.3; sourceTree = "<group>"; };
		F96D3E0808F272A5004A47F5 /* Backslash.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Backslash.3; sourceTree = "<group>"; };
		F96D3E0908F272A5004A47F5 /* bgerror.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bgerror.n; sourceTree = "<group>"; };
		F96D3E0A08F272A5004A47F5 /* binary.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = binary.n; sourceTree = "<group>"; };
		F96D3E0B08F272A5004A47F5 /* BoolObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = BoolObj.3; sourceTree = "<group>"; };
		F96D3E0C08F272A5004A47F5 /* break.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = break.n; sourceTree = "<group>"; };
		F96D3E0D08F272A5004A47F5 /* ByteArrObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ByteArrObj.3; sourceTree = "<group>"; };
		F96D3E0E08F272A5004A47F5 /* CallDel.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CallDel.3; sourceTree = "<group>"; };
		F96D3E0F08F272A5004A47F5 /* case.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = case.n; sourceTree = "<group>"; };
		F96D3E1008F272A5004A47F5 /* catch.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = catch.n; sourceTree = "<group>"; };
		F96D3E1108F272A5004A47F5 /* cd.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = cd.n; sourceTree = "<group>"; };
		F96D3E1208F272A5004A47F5 /* chan.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = chan.n; sourceTree = "<group>"; };
		F96D3E1308F272A5004A47F5 /* ChnlStack.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ChnlStack.3; sourceTree = "<group>"; };
		F96D3E1408F272A5004A47F5 /* clock.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = clock.n; sourceTree = "<group>"; };
		F96D3E1508F272A5004A47F5 /* close.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = close.n; sourceTree = "<group>"; };
		F96D3E1608F272A5004A47F5 /* CmdCmplt.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CmdCmplt.3; sourceTree = "<group>"; };
		F96D3E1708F272A5004A47F5 /* Concat.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Concat.3; sourceTree = "<group>"; };
		F96D3E1808F272A5004A47F5 /* concat.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = concat.n; sourceTree = "<group>"; };
		F96D3E1908F272A5004A47F5 /* continue.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = continue.n; sourceTree = "<group>"; };
		F96D3E1A08F272A5004A47F5 /* CrtChannel.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtChannel.3; sourceTree = "<group>"; };
		F96D3E1B08F272A5004A47F5 /* CrtChnlHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtChnlHdlr.3; sourceTree = "<group>"; };
		F96D3E1C08F272A5004A47F5 /* CrtCloseHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtCloseHdlr.3; sourceTree = "<group>"; };
		F96D3E1D08F272A5004A47F5 /* CrtCommand.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtCommand.3; sourceTree = "<group>"; };
		F96D3E1E08F272A5004A47F5 /* CrtFileHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtFileHdlr.3; sourceTree = "<group>"; };
		F96D3E1F08F272A5004A47F5 /* CrtInterp.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtInterp.3; sourceTree = "<group>"; };
		F96D3E2008F272A5004A47F5 /* CrtMathFnc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtMathFnc.3; sourceTree = "<group>"; };
		F96D3E2108F272A5004A47F5 /* CrtObjCmd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtObjCmd.3; sourceTree = "<group>"; };
		F96D3E2208F272A5004A47F5 /* CrtSlave.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtSlave.3; sourceTree = "<group>"; };
		F96D3E2308F272A5004A47F5 /* CrtTimerHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtTimerHdlr.3; sourceTree = "<group>"; };
		F96D3E2408F272A5004A47F5 /* CrtTrace.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtTrace.3; sourceTree = "<group>"; };
		F96D3E2508F272A5004A47F5 /* dde.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = dde.n; sourceTree = "<group>"; };
		F96D3E2608F272A5004A47F5 /* DetachPids.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DetachPids.3; sourceTree = "<group>"; };
		F96D3E2708F272A5004A47F5 /* dict.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = dict.n; sourceTree = "<group>"; };
		F96D3E2808F272A5004A47F5 /* DictObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DictObj.3; sourceTree = "<group>"; };
		F96D3E2908F272A5004A47F5 /* DoOneEvent.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DoOneEvent.3; sourceTree = "<group>"; };
		F96D3E2A08F272A5004A47F5 /* DoubleObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DoubleObj.3; sourceTree = "<group>"; };
		F96D3E2B08F272A5004A47F5 /* DoWhenIdle.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DoWhenIdle.3; sourceTree = "<group>"; };
		F96D3E2C08F272A5004A47F5 /* DString.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DString.3; sourceTree = "<group>"; };
		F96D3E2D08F272A5004A47F5 /* DumpActiveMemory.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DumpActiveMemory.3; sourceTree = "<group>"; };
		F96D3E2E08F272A5004A47F5 /* Encoding.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Encoding.3; sourceTree = "<group>"; };
		F96D3E2F08F272A5004A47F5 /* encoding.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = encoding.n; sourceTree = "<group>"; };
		F96D3E3008F272A5004A47F5 /* Ensemble.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Ensemble.3; sourceTree = "<group>"; };
		F96D3E3108F272A5004A47F5 /* Environment.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Environment.3; sourceTree = "<group>"; };
		F96D3E3208F272A5004A47F5 /* eof.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = eof.n; sourceTree = "<group>"; };
		F96D3E3308F272A5004A47F5 /* error.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = error.n; sourceTree = "<group>"; };
		F96D3E3408F272A5004A47F5 /* Eval.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Eval.3; sourceTree = "<group>"; };
		F96D3E3508F272A5004A47F5 /* eval.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = eval.n; sourceTree = "<group>"; };
		F96D3E3608F272A5004A47F5 /* exec.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = exec.n; sourceTree = "<group>"; };
		F96D3E3708F272A5004A47F5 /* Exit.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Exit.3; sourceTree = "<group>"; };
		F96D3E3808F272A5004A47F5 /* exit.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = exit.n; sourceTree = "<group>"; };
		F96D3E3908F272A5004A47F5 /* expr.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = expr.n; sourceTree = "<group>"; };
		F96D3E3A08F272A5004A47F5 /* ExprLong.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ExprLong.3; sourceTree = "<group>"; };
		F96D3E3B08F272A5004A47F5 /* ExprLongObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ExprLongObj.3; sourceTree = "<group>"; };
		F96D3E3C08F272A5004A47F5 /* fblocked.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = fblocked.n; sourceTree = "<group>"; };
		F96D3E3D08F272A5004A47F5 /* fconfigure.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = fconfigure.n; sourceTree = "<group>"; };
		F96D3E3E08F272A5004A47F5 /* fcopy.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = fcopy.n; sourceTree = "<group>"; };
		F96D3E3F08F272A5004A47F5 /* file.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = file.n; sourceTree = "<group>"; };
		F96D3E4008F272A5004A47F5 /* fileevent.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = fileevent.n; sourceTree = "<group>"; };
		F96D3E4108F272A5004A47F5 /* filename.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = filename.n; sourceTree = "<group>"; };
		F96D3E4208F272A5004A47F5 /* FileSystem.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = FileSystem.3; sourceTree = "<group>"; };
		F96D3E4308F272A5004A47F5 /* FindExec.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = FindExec.3; sourceTree = "<group>"; };
		F96D3E4408F272A5004A47F5 /* flush.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = flush.n; sourceTree = "<group>"; };
		F96D3E4508F272A5004A47F5 /* for.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = for.n; sourceTree = "<group>"; };
		F96D3E4608F272A5004A47F5 /* foreach.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = foreach.n; sourceTree = "<group>"; };
		F96D3E4708F272A5004A47F5 /* format.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = format.n; sourceTree = "<group>"; };
		F96D3E4808F272A5004A47F5 /* GetCwd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetCwd.3; sourceTree = "<group>"; };
		F96D3E4908F272A5004A47F5 /* GetHostName.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetHostName.3; sourceTree = "<group>"; };
		F96D3E4A08F272A5004A47F5 /* GetIndex.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetIndex.3; sourceTree = "<group>"; };
		F96D3E4B08F272A5004A47F5 /* GetInt.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetInt.3; sourceTree = "<group>"; };
		F96D3E4C08F272A5004A47F5 /* GetOpnFl.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetOpnFl.3; sourceTree = "<group>"; };
		F96D3E4D08F272A5004A47F5 /* gets.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = gets.n; sourceTree = "<group>"; };
		F96D3E4E08F272A5004A47F5 /* GetStdChan.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetStdChan.3; sourceTree = "<group>"; };
		F96D3E4F08F272A5004A47F5 /* GetTime.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetTime.3; sourceTree = "<group>"; };
		F96D3E5008F272A5004A47F5 /* GetVersion.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = GetVersion.3; sourceTree = "<group>"; };
		F96D3E5108F272A5004A47F5 /* glob.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = glob.n; sourceTree = "<group>"; };
		F96D3E5208F272A6004A47F5 /* global.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = global.n; sourceTree = "<group>"; };
		F96D3E5308F272A6004A47F5 /* Hash.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Hash.3; sourceTree = "<group>"; };
		F96D3E5408F272A6004A47F5 /* history.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = history.n; sourceTree = "<group>"; };
		F96D3E5508F272A6004A47F5 /* http.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = http.n; sourceTree = "<group>"; };
		F96D3E5608F272A6004A47F5 /* if.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = if.n; sourceTree = "<group>"; };
		F96D3E5708F272A6004A47F5 /* incr.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = incr.n; sourceTree = "<group>"; };
		F96D3E5808F272A6004A47F5 /* info.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = info.n; sourceTree = "<group>"; };
		F96D3E5908F272A6004A47F5 /* Init.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Init.3; sourceTree = "<group>"; };
		F96D3E5A08F272A6004A47F5 /* InitStubs.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = InitStubs.3; sourceTree = "<group>"; };
		F96D3E5B08F272A6004A47F5 /* Interp.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Interp.3; sourceTree = "<group>"; };
		F96D3E5C08F272A6004A47F5 /* interp.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = interp.n; sourceTree = "<group>"; };
		F96D3E5D08F272A6004A47F5 /* IntObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = IntObj.3; sourceTree = "<group>"; };
		F96D3E5E08F272A6004A47F5 /* join.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = join.n; sourceTree = "<group>"; };
		F96D3E5F08F272A6004A47F5 /* lappend.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lappend.n; sourceTree = "<group>"; };
		F96D3E6008F272A6004A47F5 /* lassign.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lassign.n; sourceTree = "<group>"; };
		F96D3E6108F272A6004A47F5 /* library.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = library.n; sourceTree = "<group>"; };
		F96D3E6208F272A6004A47F5 /* Limit.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Limit.3; sourceTree = "<group>"; };
		F96D3E6308F272A6004A47F5 /* lindex.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lindex.n; sourceTree = "<group>"; };
		F96D3E6408F272A6004A47F5 /* LinkVar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = LinkVar.3; sourceTree = "<group>"; };
		F96D3E6508F272A6004A47F5 /* linsert.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = linsert.n; sourceTree = "<group>"; };
		F96D3E6608F272A6004A47F5 /* list.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = list.n; sourceTree = "<group>"; };
		F96D3E6708F272A6004A47F5 /* ListObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ListObj.3; sourceTree = "<group>"; };
		F96D3E6808F272A6004A47F5 /* llength.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = llength.n; sourceTree = "<group>"; };
		F96D3E6908F272A6004A47F5 /* load.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = load.n; sourceTree = "<group>"; };
		F96D3E6A08F272A6004A47F5 /* lrange.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lrange.n; sourceTree = "<group>"; };
		F96D3E6B08F272A6004A47F5 /* lrepeat.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lrepeat.n; sourceTree = "<group>"; };
		F96D3E6C08F272A6004A47F5 /* lreplace.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lreplace.n; sourceTree = "<group>"; };
		F96D3E6D08F272A6004A47F5 /* lsearch.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lsearch.n; sourceTree = "<group>"; };
		F96D3E6E08F272A6004A47F5 /* lset.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lset.n; sourceTree = "<group>"; };
		F96D3E6F08F272A6004A47F5 /* lsort.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = lsort.n; sourceTree = "<group>"; };
		F96D3E7008F272A6004A47F5 /* man.macros */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = man.macros; sourceTree = "<group>"; };
		F96D3E7108F272A6004A47F5 /* mathfunc.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = mathfunc.n; sourceTree = "<group>"; };
		F96D3E7208F272A6004A47F5 /* memory.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = memory.n; sourceTree = "<group>"; };
		F96D3E7308F272A6004A47F5 /* msgcat.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = msgcat.n; sourceTree = "<group>"; };
		F96D3E7408F272A6004A47F5 /* Namespace.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Namespace.3; sourceTree = "<group>"; };
		F96D3E7508F272A6004A47F5 /* namespace.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = namespace.n; sourceTree = "<group>"; };
		F96D3E7608F272A6004A47F5 /* Notifier.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Notifier.3; sourceTree = "<group>"; };
		F96D3E7708F272A6004A47F5 /* Object.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Object.3; sourceTree = "<group>"; };
		F96D3E7808F272A6004A47F5 /* ObjectType.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ObjectType.3; sourceTree = "<group>"; };
		F96D3E7908F272A6004A47F5 /* open.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = open.n; sourceTree = "<group>"; };
		F96D3E7A08F272A6004A47F5 /* OpenFileChnl.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = OpenFileChnl.3; sourceTree = "<group>"; };
		F96D3E7B08F272A6004A47F5 /* OpenTcp.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = OpenTcp.3; sourceTree = "<group>"; };
		F96D3E7C08F272A6004A47F5 /* package.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = package.n; sourceTree = "<group>"; };
		F96D3E7D08F272A6004A47F5 /* packagens.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = packagens.n; sourceTree = "<group>"; };
		F96D3E7E08F272A6004A47F5 /* Panic.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Panic.3; sourceTree = "<group>"; };
		F96D3E7F08F272A6004A47F5 /* ParseCmd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ParseCmd.3; sourceTree = "<group>"; };
		F96D3E8008F272A6004A47F5 /* pid.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = pid.n; sourceTree = "<group>"; };
		F96D3E8108F272A6004A47F5 /* pkgMkIndex.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = pkgMkIndex.n; sourceTree = "<group>"; };
		F96D3E8208F272A6004A47F5 /* PkgRequire.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = PkgRequire.3; sourceTree = "<group>"; };
		F96D3E8308F272A6004A47F5 /* Preserve.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Preserve.3; sourceTree = "<group>"; };
		F96D3E8408F272A6004A47F5 /* PrintDbl.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = PrintDbl.3; sourceTree = "<group>"; };
		F96D3E8508F272A6004A47F5 /* proc.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = proc.n; sourceTree = "<group>"; };
		F96D3E8608F272A6004A47F5 /* puts.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = puts.n; sourceTree = "<group>"; };
		F96D3E8708F272A6004A47F5 /* pwd.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = pwd.n; sourceTree = "<group>"; };
		F96D3E8808F272A6004A47F5 /* re_syntax.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = re_syntax.n; sourceTree = "<group>"; };
		F96D3E8908F272A6004A47F5 /* read.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = read.n; sourceTree = "<group>"; };
		F96D3E8A08F272A6004A47F5 /* RecEvalObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = RecEvalObj.3; sourceTree = "<group>"; };
		F96D3E8B08F272A6004A47F5 /* RecordEval.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = RecordEval.3; sourceTree = "<group>"; };
		F96D3E8C08F272A6004A47F5 /* RegConfig.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = RegConfig.3; sourceTree = "<group>"; };
		F96D3E8D08F272A6004A47F5 /* RegExp.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = RegExp.3; sourceTree = "<group>"; };
		F96D3E8E08F272A6004A47F5 /* regexp.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = regexp.n; sourceTree = "<group>"; };
		F96D3E8F08F272A6004A47F5 /* registry.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = registry.n; sourceTree = "<group>"; };
		F96D3E9008F272A6004A47F5 /* regsub.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = regsub.n; sourceTree = "<group>"; };
		F96D3E9108F272A6004A47F5 /* rename.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = rename.n; sourceTree = "<group>"; };
		F96D3E9208F272A6004A47F5 /* return.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = return.n; sourceTree = "<group>"; };
		F96D3E9308F272A6004A47F5 /* safe.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = safe.n; sourceTree = "<group>"; };
		F96D3E9408F272A6004A47F5 /* SaveResult.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SaveResult.3; sourceTree = "<group>"; };
		F96D3E9508F272A6004A47F5 /* scan.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = scan.n; sourceTree = "<group>"; };
		F96D3E9608F272A6004A47F5 /* seek.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = seek.n; sourceTree = "<group>"; };
		F96D3E9708F272A6004A47F5 /* set.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = set.n; sourceTree = "<group>"; };
		F96D3E9808F272A6004A47F5 /* SetChanErr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetChanErr.3; sourceTree = "<group>"; };
		F96D3E9908F272A6004A47F5 /* SetErrno.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetErrno.3; sourceTree = "<group>"; };
		F96D3E9A08F272A6004A47F5 /* SetRecLmt.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetRecLmt.3; sourceTree = "<group>"; };
		F96D3E9B08F272A7004A47F5 /* SetResult.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetResult.3; sourceTree = "<group>"; };
		F96D3E9C08F272A7004A47F5 /* SetVar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SetVar.3; sourceTree = "<group>"; };
		F96D3E9D08F272A7004A47F5 /* Signal.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Signal.3; sourceTree = "<group>"; };
		F96D3E9E08F272A7004A47F5 /* Sleep.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Sleep.3; sourceTree = "<group>"; };
		F96D3E9F08F272A7004A47F5 /* socket.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = socket.n; sourceTree = "<group>"; };
		F96D3EA008F272A7004A47F5 /* source.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = source.n; sourceTree = "<group>"; };
		F96D3EA108F272A7004A47F5 /* SourceRCFile.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SourceRCFile.3; sourceTree = "<group>"; };
		F96D3EA208F272A7004A47F5 /* split.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = split.n; sourceTree = "<group>"; };
		F96D3EA308F272A7004A47F5 /* SplitList.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SplitList.3; sourceTree = "<group>"; };
		F96D3EA408F272A7004A47F5 /* SplitPath.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SplitPath.3; sourceTree = "<group>"; };
		F96D3EA508F272A7004A47F5 /* StaticPkg.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = StaticPkg.3; sourceTree = "<group>"; };
		F96D3EA608F272A7004A47F5 /* StdChannels.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = StdChannels.3; sourceTree = "<group>"; };
		F96D3EA708F272A7004A47F5 /* string.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = string.n; sourceTree = "<group>"; };
		F96D3EA808F272A7004A47F5 /* StringObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = StringObj.3; sourceTree = "<group>"; };
		F96D3EA908F272A7004A47F5 /* StrMatch.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = StrMatch.3; sourceTree = "<group>"; };
		F96D3EAA08F272A7004A47F5 /* subst.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = subst.n; sourceTree = "<group>"; };
		F96D3EAB08F272A7004A47F5 /* SubstObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = SubstObj.3; sourceTree = "<group>"; };
		F96D3EAC08F272A7004A47F5 /* switch.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = switch.n; sourceTree = "<group>"; };
		F96D3EAD08F272A7004A47F5 /* Tcl.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Tcl.n; sourceTree = "<group>"; };
		F96D3EAE08F272A7004A47F5 /* Tcl_Main.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Tcl_Main.3; sourceTree = "<group>"; };
		F96D3EAF08F272A7004A47F5 /* TCL_MEM_DEBUG.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TCL_MEM_DEBUG.3; sourceTree = "<group>"; };
		F96D3EB008F272A7004A47F5 /* tclsh.1 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tclsh.1; sourceTree = "<group>"; };
		F96D3EB108F272A7004A47F5 /* tcltest.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tcltest.n; sourceTree = "<group>"; };
		F96D3EB208F272A7004A47F5 /* tclvars.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tclvars.n; sourceTree = "<group>"; };
		F96D3EB308F272A7004A47F5 /* tell.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tell.n; sourceTree = "<group>"; };
		F96D3EB408F272A7004A47F5 /* Thread.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Thread.3; sourceTree = "<group>"; };
		F96D3EB508F272A7004A47F5 /* time.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = time.n; sourceTree = "<group>"; };
		F96D3EB608F272A7004A47F5 /* tm.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tm.n; sourceTree = "<group>"; };
		F96D3EB708F272A7004A47F5 /* ToUpper.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ToUpper.3; sourceTree = "<group>"; };
		F96D3EB808F272A7004A47F5 /* trace.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = trace.n; sourceTree = "<group>"; };
		F96D3EB908F272A7004A47F5 /* TraceCmd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TraceCmd.3; sourceTree = "<group>"; };
		F96D3EBA08F272A7004A47F5 /* TraceVar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TraceVar.3; sourceTree = "<group>"; };
		F96D3EBB08F272A7004A47F5 /* Translate.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Translate.3; sourceTree = "<group>"; };
		F96D3EBC08F272A7004A47F5 /* UniCharIsAlpha.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = UniCharIsAlpha.3; sourceTree = "<group>"; };
		F96D3EBD08F272A7004A47F5 /* unknown.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = unknown.n; sourceTree = "<group>"; };
		F96D3EBE08F272A7004A47F5 /* unload.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = unload.n; sourceTree = "<group>"; };
		F96D3EBF08F272A7004A47F5 /* unset.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = unset.n; sourceTree = "<group>"; };
		F96D3EC008F272A7004A47F5 /* update.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = update.n; sourceTree = "<group>"; };
		F96D3EC108F272A7004A47F5 /* uplevel.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = uplevel.n; sourceTree = "<group>"; };
		F96D3EC208F272A7004A47F5 /* UpVar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = UpVar.3; sourceTree = "<group>"; };
		F96D3EC308F272A7004A47F5 /* upvar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = upvar.n; sourceTree = "<group>"; };
		F96D3EC408F272A7004A47F5 /* Utf.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Utf.3; sourceTree = "<group>"; };
		F96D3EC508F272A7004A47F5 /* variable.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = variable.n; sourceTree = "<group>"; };
		F96D3EC608F272A7004A47F5 /* vwait.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = vwait.n; sourceTree = "<group>"; };
		F96D3EC708F272A7004A47F5 /* while.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = while.n; sourceTree = "<group>"; };
		F96D3EC808F272A7004A47F5 /* WrongNumArgs.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = WrongNumArgs.3; sourceTree = "<group>"; };
		F96D3ECA08F272A7004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D3ECB08F272A7004A47F5 /* regc_color.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regc_color.c; sourceTree = "<group>"; };
		F96D3ECC08F272A7004A47F5 /* regc_cvec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regc_cvec.c; sourceTree = "<group>"; };
		F96D3ECD08F272A7004A47F5 /* regc_lex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regc_lex.c; sourceTree = "<group>"; };
		F96D3ECE08F272A7004A47F5 /* regc_locale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regc_locale.c; sourceTree = "<group>"; };
		F96D3ECF08F272A7004A47F5 /* regc_nfa.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regc_nfa.c; sourceTree = "<group>"; };
		F96D3ED008F272A7004A47F5 /* regcomp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regcomp.c; sourceTree = "<group>"; };
		F96D3ED108F272A7004A47F5 /* regcustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = regcustom.h; sourceTree = "<group>"; };
		F96D3ED208F272A7004A47F5 /* rege_dfa.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rege_dfa.c; sourceTree = "<group>"; };
		F96D3ED308F272A7004A47F5 /* regerror.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regerror.c; sourceTree = "<group>"; };
		F96D3ED408F272A7004A47F5 /* regerrs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = regerrs.h; sourceTree = "<group>"; };
		F96D3ED508F272A7004A47F5 /* regex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = regex.h; sourceTree = "<group>"; };
		F96D3ED608F272A7004A47F5 /* regexec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regexec.c; sourceTree = "<group>"; };
		F96D3ED708F272A7004A47F5 /* regfree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regfree.c; sourceTree = "<group>"; };
		F96D3ED808F272A7004A47F5 /* regfronts.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = regfronts.c; sourceTree = "<group>"; };
		F96D3ED908F272A7004A47F5 /* regguts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = regguts.h; sourceTree = "<group>"; };
		F96D3EDA08F272A7004A47F5 /* tcl.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tcl.decls; sourceTree = "<group>"; };
		F96D3EDB08F272A7004A47F5 /* tcl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tcl.h; sourceTree = "<group>"; };
		F96D3EDC08F272A7004A47F5 /* tclAlloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclAlloc.c; sourceTree = "<group>"; };
		F96D3EDD08F272A7004A47F5 /* tclAsync.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclAsync.c; sourceTree = "<group>"; };
		F96D3EDE08F272A7004A47F5 /* tclBasic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclBasic.c; sourceTree = "<group>"; };
		F96D3EDF08F272A7004A47F5 /* tclBinary.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclBinary.c; sourceTree = "<group>"; };
		F96D3EE008F272A7004A47F5 /* tclCkalloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCkalloc.c; sourceTree = "<group>"; };
		F96D3EE108F272A7004A47F5 /* tclClock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclClock.c; sourceTree = "<group>"; };
		F96D3EE208F272A7004A47F5 /* tclCmdAH.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCmdAH.c; sourceTree = "<group>"; };
		F96D3EE308F272A7004A47F5 /* tclCmdIL.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCmdIL.c; sourceTree = "<group>"; };
		F96D3EE408F272A7004A47F5 /* tclCmdMZ.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCmdMZ.c; sourceTree = "<group>"; };
		F96D3EE508F272A7004A47F5 /* tclCompCmds.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCompCmds.c; sourceTree = "<group>"; };
		F96D3EE608F272A7004A47F5 /* tclCompExpr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCompExpr.c; sourceTree = "<group>"; };
		F96D3EE708F272A7004A47F5 /* tclCompile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclCompile.c; sourceTree = "<group>"; };
		F96D3EE808F272A7004A47F5 /* tclCompile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclCompile.h; sourceTree = "<group>"; };
		F96D3EE908F272A7004A47F5 /* tclConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclConfig.c; sourceTree = "<group>"; };
		F96D3EEA08F272A7004A47F5 /* tclDate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclDate.c; sourceTree = "<group>"; };
		F96D3EEB08F272A7004A47F5 /* tclDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclDecls.h; sourceTree = "<group>"; };
		F96D3EEC08F272A7004A47F5 /* tclDictObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclDictObj.c; sourceTree = "<group>"; };
		F96D3EED08F272A7004A47F5 /* tclEncoding.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclEncoding.c; sourceTree = "<group>"; };
		F96D3EEE08F272A7004A47F5 /* tclEnv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclEnv.c; sourceTree = "<group>"; };
		F96D3EEF08F272A7004A47F5 /* tclEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclEvent.c; sourceTree = "<group>"; };
		F96D3EF008F272A7004A47F5 /* tclExecute.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclExecute.c; sourceTree = "<group>"; };
		F96D3EF108F272A7004A47F5 /* tclFCmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclFCmd.c; sourceTree = "<group>"; };
		F96D3EF208F272A7004A47F5 /* tclFileName.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclFileName.c; sourceTree = "<group>"; };
		F96D3EF308F272A7004A47F5 /* tclFileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclFileSystem.h; sourceTree = "<group>"; };
		F96D3EF408F272A7004A47F5 /* tclGet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclGet.c; sourceTree = "<group>"; };
		F96D3EF508F272A7004A47F5 /* tclGetDate.y */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; path = tclGetDate.y; sourceTree = "<group>"; };
		F96D3EF608F272A7004A47F5 /* tclHash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclHash.c; sourceTree = "<group>"; };
		F96D3EF708F272A7004A47F5 /* tclHistory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclHistory.c; sourceTree = "<group>"; };
		F96D3EF808F272A7004A47F5 /* tclIndexObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIndexObj.c; sourceTree = "<group>"; };
		F96D3EF908F272A7004A47F5 /* tclInt.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclInt.decls; sourceTree = "<group>"; };
		F96D3EFA08F272A7004A47F5 /* tclInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclInt.h; sourceTree = "<group>"; };
		F96D3EFB08F272A7004A47F5 /* tclIntDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclIntDecls.h; sourceTree = "<group>"; };
		F96D3EFC08F272A7004A47F5 /* tclInterp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclInterp.c; sourceTree = "<group>"; };
		F96D3EFD08F272A7004A47F5 /* tclIntPlatDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclIntPlatDecls.h; sourceTree = "<group>"; };
		F96D3EFE08F272A7004A47F5 /* tclIO.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIO.c; sourceTree = "<group>"; };
		F96D3EFF08F272A7004A47F5 /* tclIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclIO.h; sourceTree = "<group>"; };
		F96D3F0008F272A7004A47F5 /* tclIOCmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIOCmd.c; sourceTree = "<group>"; };
		F96D3F0108F272A7004A47F5 /* tclIOGT.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIOGT.c; sourceTree = "<group>"; };
		F96D3F0208F272A7004A47F5 /* tclIORChan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIORChan.c; sourceTree = "<group>"; };
		F96D3F0308F272A7004A47F5 /* tclIOSock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIOSock.c; sourceTree = "<group>"; };
		F96D3F0408F272A7004A47F5 /* tclIOUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclIOUtil.c; sourceTree = "<group>"; };
		F96D3F0508F272A7004A47F5 /* tclLink.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLink.c; sourceTree = "<group>"; };
		F96D3F0608F272A7004A47F5 /* tclListObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclListObj.c; sourceTree = "<group>"; };
		F96D3F0708F272A7004A47F5 /* tclLiteral.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLiteral.c; sourceTree = "<group>"; };
		F96D3F0808F272A7004A47F5 /* tclLoad.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoad.c; sourceTree = "<group>"; };
		F96D3F0908F272A7004A47F5 /* tclLoadNone.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadNone.c; sourceTree = "<group>"; };
		F96D3F0A08F272A7004A47F5 /* tclMain.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclMain.c; sourceTree = "<group>"; };
		F96D3F0B08F272A7004A47F5 /* tclNamesp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclNamesp.c; sourceTree = "<group>"; };
		F96D3F0C08F272A7004A47F5 /* tclNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclNotify.c; sourceTree = "<group>"; };
		F96D3F0D08F272A7004A47F5 /* tclObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclObj.c; sourceTree = "<group>"; };
		F96D3F0E08F272A7004A47F5 /* tclPanic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPanic.c; sourceTree = "<group>"; };
		F96D3F0F08F272A7004A47F5 /* tclParse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclParse.c; sourceTree = "<group>"; };
		F96D3F1108F272A7004A47F5 /* tclPathObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPathObj.c; sourceTree = "<group>"; };
		F96D3F1208F272A7004A47F5 /* tclPipe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPipe.c; sourceTree = "<group>"; };
		F96D3F1308F272A7004A47F5 /* tclPkg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPkg.c; sourceTree = "<group>"; };
		F96D3F1408F272A7004A47F5 /* tclPkgConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPkgConfig.c; sourceTree = "<group>"; };
		F96D3F1508F272A7004A47F5 /* tclPlatDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclPlatDecls.h; sourceTree = "<group>"; };
		F96D3F1608F272A7004A47F5 /* tclPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclPort.h; sourceTree = "<group>"; };
		F96D3F1708F272A7004A47F5 /* tclPosixStr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPosixStr.c; sourceTree = "<group>"; };
		F96D3F1808F272A7004A47F5 /* tclPreserve.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclPreserve.c; sourceTree = "<group>"; };
		F96D3F1908F272A7004A47F5 /* tclProc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclProc.c; sourceTree = "<group>"; };
		F96D3F1A08F272A7004A47F5 /* tclRegexp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclRegexp.c; sourceTree = "<group>"; };
		F96D3F1B08F272A7004A47F5 /* tclRegexp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclRegexp.h; sourceTree = "<group>"; };
		F96D3F1C08F272A7004A47F5 /* tclResolve.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclResolve.c; sourceTree = "<group>"; };
		F96D3F1D08F272A7004A47F5 /* tclResult.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclResult.c; sourceTree = "<group>"; };
		F96D3F1E08F272A7004A47F5 /* tclScan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclScan.c; sourceTree = "<group>"; };
		F96D3F1F08F272A7004A47F5 /* tclStringObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStringObj.c; sourceTree = "<group>"; };
		F96D3F2408F272A7004A47F5 /* tclStrToD.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStrToD.c; sourceTree = "<group>"; };
		F96D3F2508F272A7004A47F5 /* tclStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStubInit.c; sourceTree = "<group>"; };
		F96D3F2608F272A7004A47F5 /* tclStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStubLib.c; sourceTree = "<group>"; };
		F96D3F2708F272A7004A47F5 /* tclTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTest.c; sourceTree = "<group>"; };
		F96D3F2808F272A7004A47F5 /* tclTestObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTestObj.c; sourceTree = "<group>"; };
		F96D3F2908F272A7004A47F5 /* tclTestProcBodyObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTestProcBodyObj.c; sourceTree = "<group>"; };
		F96D3F2A08F272A7004A47F5 /* tclThread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThread.c; sourceTree = "<group>"; };
		F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadAlloc.c; sourceTree = "<group>"; };
		F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadJoin.c; sourceTree = "<group>"; };
		F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadStorage.c; sourceTree = "<group>"; };
		F96D3F2E08F272A7004A47F5 /* tclThreadTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadTest.c; sourceTree = "<group>"; };
		F96D3F2F08F272A7004A47F5 /* tclTimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTimer.c; sourceTree = "<group>"; };
		F96D3F3008F272A7004A47F5 /* tclTomMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclTomMath.h; sourceTree = "<group>"; };
		F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTomMathInterface.c; sourceTree = "<group>"; };
		F96D3F3208F272A7004A47F5 /* tclTrace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTrace.c; sourceTree = "<group>"; };
		F96D3F3308F272A7004A47F5 /* tclUniData.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUniData.c; sourceTree = "<group>"; };
		F96D3F3408F272A7004A47F5 /* tclUtf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUtf.c; sourceTree = "<group>"; };
		F96D3F3508F272A7004A47F5 /* tclUtil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUtil.c; sourceTree = "<group>"; };
		F96D3F3608F272A7004A47F5 /* tclVar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclVar.c; sourceTree = "<group>"; };
		F96D3F3708F272A7004A47F5 /* tommath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tommath.h; sourceTree = "<group>"; };
		F96D3F3908F272A8004A47F5 /* auto.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = auto.tcl; sourceTree = "<group>"; };
		F96D3F3A08F272A8004A47F5 /* clock.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clock.tcl; sourceTree = "<group>"; };
		F96D3F3C08F272A8004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D3F8C08F272A8004A47F5 /* history.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = history.tcl; sourceTree = "<group>"; };
		F96D3F8E08F272A8004A47F5 /* http.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = http.tcl; sourceTree = "<group>"; };
		F96D3F8F08F272A8004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D3F9108F272A8004A47F5 /* http.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = http.tcl; sourceTree = "<group>"; };
		F96D3F9208F272A8004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D3F9308F272A8004A47F5 /* init.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = init.tcl; sourceTree = "<group>"; };
		F96D3F9508F272A8004A47F5 /* msgcat.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgcat.tcl; sourceTree = "<group>"; };
		F96D3F9608F272A8004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D401808F272AA004A47F5 /* optparse.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = optparse.tcl; sourceTree = "<group>"; };
		F96D401908F272AA004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D401A08F272AA004A47F5 /* package.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = package.tcl; sourceTree = "<group>"; };
		F96D401B08F272AA004A47F5 /* parray.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = parray.tcl; sourceTree = "<group>"; };
		F96D401D08F272AA004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D401E08F272AA004A47F5 /* safe.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = safe.tcl; sourceTree = "<group>"; };
		F96D401F08F272AA004A47F5 /* tclIndex */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclIndex; sourceTree = "<group>"; };
		F96D402108F272AA004A47F5 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F96D402208F272AA004A47F5 /* tcltest.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tcltest.tcl; sourceTree = "<group>"; };
		F96D402308F272AA004A47F5 /* tm.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tm.tcl; sourceTree = "<group>"; };
		F96D425B08F272B2004A47F5 /* word.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = word.tcl; sourceTree = "<group>"; };
		F96D426408F272B3004A47F5 /* bn_fast_s_mp_mul_digs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_fast_s_mp_mul_digs.c; sourceTree = "<group>"; };
		F96D426608F272B3004A47F5 /* bn_fast_s_mp_sqr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_fast_s_mp_sqr.c; sourceTree = "<group>"; };
		F96D426908F272B3004A47F5 /* bn_mp_add.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_add.c; sourceTree = "<group>"; };
		F96D426A08F272B3004A47F5 /* bn_mp_add_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_add_d.c; sourceTree = "<group>"; };
		F96D426C08F272B3004A47F5 /* bn_mp_and.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_and.c; sourceTree = "<group>"; };
		F96D426D08F272B3004A47F5 /* bn_mp_clamp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_clamp.c; sourceTree = "<group>"; };
		F96D426E08F272B3004A47F5 /* bn_mp_clear.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_clear.c; sourceTree = "<group>"; };
		F96D426F08F272B3004A47F5 /* bn_mp_clear_multi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_clear_multi.c; sourceTree = "<group>"; };
		F96D427008F272B3004A47F5 /* bn_mp_cmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_cmp.c; sourceTree = "<group>"; };
		F96D427108F272B3004A47F5 /* bn_mp_cmp_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_cmp_d.c; sourceTree = "<group>"; };
		F96D427208F272B3004A47F5 /* bn_mp_cmp_mag.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_cmp_mag.c; sourceTree = "<group>"; };
		F96D427408F272B3004A47F5 /* bn_mp_copy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_copy.c; sourceTree = "<group>"; };
		F96D427508F272B3004A47F5 /* bn_mp_count_bits.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_count_bits.c; sourceTree = "<group>"; };
		F96D427608F272B3004A47F5 /* bn_mp_div.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_div.c; sourceTree = "<group>"; };
		F96D427708F272B3004A47F5 /* bn_mp_div_2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_div_2.c; sourceTree = "<group>"; };
		F96D427808F272B3004A47F5 /* bn_mp_div_2d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_div_2d.c; sourceTree = "<group>"; };
		F96D427908F272B3004A47F5 /* bn_mp_div_3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_div_3.c; sourceTree = "<group>"; };
		F96D427A08F272B3004A47F5 /* bn_mp_div_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_div_d.c; sourceTree = "<group>"; };
		F96D427E08F272B3004A47F5 /* bn_mp_exch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_exch.c; sourceTree = "<group>"; };
		F96D427F08F272B3004A47F5 /* bn_mp_expt_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_expt_d.c; sourceTree = "<group>"; };
		F96D428708F272B3004A47F5 /* bn_mp_grow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_grow.c; sourceTree = "<group>"; };
		F96D428808F272B3004A47F5 /* bn_mp_init.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_init.c; sourceTree = "<group>"; };
		F96D428908F272B3004A47F5 /* bn_mp_init_copy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_init_copy.c; sourceTree = "<group>"; };
		F96D428A08F272B3004A47F5 /* bn_mp_init_multi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_init_multi.c; sourceTree = "<group>"; };
		F96D428B08F272B3004A47F5 /* bn_mp_init_set.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_init_set.c; sourceTree = "<group>"; };
		F96D428D08F272B3004A47F5 /* bn_mp_init_size.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_init_size.c; sourceTree = "<group>"; };
		F96D429208F272B3004A47F5 /* bn_mp_karatsuba_mul.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_karatsuba_mul.c; sourceTree = "<group>"; };
		F96D429308F272B3004A47F5 /* bn_mp_karatsuba_sqr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_karatsuba_sqr.c; sourceTree = "<group>"; };
		F96D429508F272B3004A47F5 /* bn_mp_lshd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_lshd.c; sourceTree = "<group>"; };
		F96D429608F272B3004A47F5 /* bn_mp_mod.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mod.c; sourceTree = "<group>"; };
		F96D429708F272B3004A47F5 /* bn_mp_mod_2d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mod_2d.c; sourceTree = "<group>"; };
		F96D429C08F272B3004A47F5 /* bn_mp_mul.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mul.c; sourceTree = "<group>"; };
		F96D429D08F272B3004A47F5 /* bn_mp_mul_2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mul_2.c; sourceTree = "<group>"; };
		F96D429E08F272B3004A47F5 /* bn_mp_mul_2d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mul_2d.c; sourceTree = "<group>"; };
		F96D429F08F272B3004A47F5 /* bn_mp_mul_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_mul_d.c; sourceTree = "<group>"; };
		F96D42A208F272B3004A47F5 /* bn_mp_neg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_neg.c; sourceTree = "<group>"; };
		F96D42A308F272B3004A47F5 /* bn_mp_or.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_or.c; sourceTree = "<group>"; };
		F96D42AB08F272B3004A47F5 /* bn_mp_radix_size.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_radix_size.c; sourceTree = "<group>"; };
		F96D42AC08F272B3004A47F5 /* bn_mp_radix_smap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_radix_smap.c; sourceTree = "<group>"; };
		F96D42AE08F272B3004A47F5 /* bn_mp_read_radix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_read_radix.c; sourceTree = "<group>"; };
		F96D42B908F272B3004A47F5 /* bn_mp_rshd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_rshd.c; sourceTree = "<group>"; };
		F96D42BA08F272B3004A47F5 /* bn_mp_set.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_set.c; sourceTree = "<group>"; };
		F96D42BC08F272B3004A47F5 /* bn_mp_shrink.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_shrink.c; sourceTree = "<group>"; };
		F96D42BE08F272B3004A47F5 /* bn_mp_sqr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_sqr.c; sourceTree = "<group>"; };
		F96D42C008F272B3004A47F5 /* bn_mp_sqrt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_sqrt.c; sourceTree = "<group>"; };
		F96D42C108F272B3004A47F5 /* bn_mp_sub.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_sub.c; sourceTree = "<group>"; };
		F96D42C208F272B3004A47F5 /* bn_mp_sub_d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_sub_d.c; sourceTree = "<group>"; };
		F96D42C608F272B3004A47F5 /* bn_mp_to_unsigned_bin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_to_unsigned_bin.c; sourceTree = "<group>"; };
		F96D42C708F272B3004A47F5 /* bn_mp_to_unsigned_bin_n.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_to_unsigned_bin_n.c; sourceTree = "<group>"; };
		F96D42C808F272B3004A47F5 /* bn_mp_toom_mul.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_toom_mul.c; sourceTree = "<group>"; };
		F96D42C908F272B3004A47F5 /* bn_mp_toom_sqr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_toom_sqr.c; sourceTree = "<group>"; };
		F96D42CB08F272B3004A47F5 /* bn_mp_toradix_n.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_toradix_n.c; sourceTree = "<group>"; };
		F96D42CC08F272B3004A47F5 /* bn_mp_unsigned_bin_size.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_unsigned_bin_size.c; sourceTree = "<group>"; };
		F96D42CD08F272B3004A47F5 /* bn_mp_xor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_xor.c; sourceTree = "<group>"; };
		F96D42CE08F272B3004A47F5 /* bn_mp_zero.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_mp_zero.c; sourceTree = "<group>"; };
		F96D42D008F272B3004A47F5 /* bn_reverse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_reverse.c; sourceTree = "<group>"; };
		F96D42D108F272B3004A47F5 /* bn_s_mp_add.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_s_mp_add.c; sourceTree = "<group>"; };
		F96D42D308F272B3004A47F5 /* bn_s_mp_mul_digs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_s_mp_mul_digs.c; sourceTree = "<group>"; };
		F96D42D508F272B3004A47F5 /* bn_s_mp_sqr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_s_mp_sqr.c; sourceTree = "<group>"; };
		F96D42D608F272B3004A47F5 /* bn_s_mp_sub.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bn_s_mp_sub.c; sourceTree = "<group>"; };
		F96D42D708F272B3004A47F5 /* bncore.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bncore.c; sourceTree = "<group>"; };
		F96D432908F272B4004A47F5 /* tommath_class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tommath_class.h; sourceTree = "<group>"; };
		F96D432A08F272B4004A47F5 /* tommath_superclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tommath_superclass.h; sourceTree = "<group>"; };
		F96D432B08F272B4004A47F5 /* license.terms */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = license.terms; sourceTree = "<group>"; };
		F96D432E08F272B5004A47F5 /* configure.ac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure.ac; sourceTree = "<group>"; };
		F96D432F08F272B5004A47F5 /* GNUmakefile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = GNUmakefile; sourceTree = "<group>"; };
		F96D433108F272B5004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D433208F272B5004A47F5 /* Tcl-Info.plist.in */ = {isa = PBXFileReference; explicitFileType = text.plist; fileEncoding = 4; path = "Tcl-Info.plist.in"; sourceTree = "<group>"; };
		F96D433908F272B5004A47F5 /* tclMacOSXBundle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclMacOSXBundle.c; sourceTree = "<group>"; };
		F96D433D08F272B5004A47F5 /* tclMacOSXFCmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclMacOSXFCmd.c; sourceTree = "<group>"; };
		F96D433E08F272B5004A47F5 /* tclMacOSXNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclMacOSXNotify.c; sourceTree = "<group>"; };
		F96D434308F272B5004A47F5 /* README */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = README; sourceTree = "<group>"; };
		F96D434508F272B5004A47F5 /* all.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = all.tcl; sourceTree = "<group>"; };
		F96D434608F272B5004A47F5 /* append.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = append.test; sourceTree = "<group>"; };
		F96D434708F272B5004A47F5 /* appendComp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = appendComp.test; sourceTree = "<group>"; };
		F96D434808F272B5004A47F5 /* assocd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = assocd.test; sourceTree = "<group>"; };
		F96D434908F272B5004A47F5 /* async.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = async.test; sourceTree = "<group>"; };
		F96D434A08F272B5004A47F5 /* autoMkindex.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = autoMkindex.test; sourceTree = "<group>"; };
		F96D434B08F272B5004A47F5 /* basic.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = basic.test; sourceTree = "<group>"; };
		F96D434C08F272B5004A47F5 /* binary.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = binary.test; sourceTree = "<group>"; };
		F96D434D08F272B5004A47F5 /* case.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = case.test; sourceTree = "<group>"; };
		F96D434E08F272B5004A47F5 /* chan.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = chan.test; sourceTree = "<group>"; };
		F96D434F08F272B5004A47F5 /* clock.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = clock.test; sourceTree = "<group>"; };
		F96D435008F272B5004A47F5 /* cmdAH.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmdAH.test; sourceTree = "<group>"; };
		F96D435108F272B5004A47F5 /* cmdIL.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmdIL.test; sourceTree = "<group>"; };
		F96D435208F272B5004A47F5 /* cmdInfo.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmdInfo.test; sourceTree = "<group>"; };
		F96D435308F272B5004A47F5 /* cmdMZ.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = cmdMZ.test; sourceTree = "<group>"; };
		F96D435408F272B5004A47F5 /* compExpr-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "compExpr-old.test"; sourceTree = "<group>"; };
		F96D435508F272B5004A47F5 /* compExpr.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = compExpr.test; sourceTree = "<group>"; };
		F96D435608F272B5004A47F5 /* compile.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = compile.test; sourceTree = "<group>"; };
		F96D435708F272B5004A47F5 /* concat.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = concat.test; sourceTree = "<group>"; };
		F96D435808F272B5004A47F5 /* config.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = config.test; sourceTree = "<group>"; };
		F96D435908F272B5004A47F5 /* dcall.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dcall.test; sourceTree = "<group>"; };
		F96D435A08F272B5004A47F5 /* dict.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dict.test; sourceTree = "<group>"; };
		F96D435C08F272B5004A47F5 /* dstring.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dstring.test; sourceTree = "<group>"; };
		F96D435E08F272B5004A47F5 /* encoding.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = encoding.test; sourceTree = "<group>"; };
		F96D435F08F272B5004A47F5 /* env.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = env.test; sourceTree = "<group>"; };
		F96D436008F272B5004A47F5 /* error.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = error.test; sourceTree = "<group>"; };
		F96D436108F272B5004A47F5 /* eval.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = eval.test; sourceTree = "<group>"; };
		F96D436208F272B5004A47F5 /* event.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = event.test; sourceTree = "<group>"; };
		F96D436308F272B5004A47F5 /* exec.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = exec.test; sourceTree = "<group>"; };
		F96D436408F272B5004A47F5 /* execute.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = execute.test; sourceTree = "<group>"; };
		F96D436508F272B5004A47F5 /* expr-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "expr-old.test"; sourceTree = "<group>"; };
		F96D436608F272B5004A47F5 /* expr.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = expr.test; sourceTree = "<group>"; };
		F96D436708F272B6004A47F5 /* fCmd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fCmd.test; sourceTree = "<group>"; };
		F96D436808F272B6004A47F5 /* fileName.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fileName.test; sourceTree = "<group>"; };
		F96D436908F272B6004A47F5 /* fileSystem.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fileSystem.test; sourceTree = "<group>"; };
		F96D436A08F272B6004A47F5 /* for-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "for-old.test"; sourceTree = "<group>"; };
		F96D436B08F272B6004A47F5 /* for.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = for.test; sourceTree = "<group>"; };
		F96D436C08F272B6004A47F5 /* foreach.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = foreach.test; sourceTree = "<group>"; };
		F96D436D08F272B6004A47F5 /* format.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = format.test; sourceTree = "<group>"; };
		F96D436E08F272B6004A47F5 /* get.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = get.test; sourceTree = "<group>"; };
		F96D436F08F272B6004A47F5 /* history.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = history.test; sourceTree = "<group>"; };
		F96D437008F272B6004A47F5 /* http.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = http.test; sourceTree = "<group>"; };
		F96D437108F272B6004A47F5 /* httpd */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = httpd; sourceTree = "<group>"; };
		F96D437208F272B6004A47F5 /* httpold.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = httpold.test; sourceTree = "<group>"; };
		F96D437308F272B6004A47F5 /* if-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "if-old.test"; sourceTree = "<group>"; };
		F96D437408F272B6004A47F5 /* if.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = if.test; sourceTree = "<group>"; };
		F96D437508F272B6004A47F5 /* incr-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "incr-old.test"; sourceTree = "<group>"; };
		F96D437608F272B6004A47F5 /* incr.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = incr.test; sourceTree = "<group>"; };
		F96D437708F272B6004A47F5 /* indexObj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = indexObj.test; sourceTree = "<group>"; };
		F96D437808F272B6004A47F5 /* info.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = info.test; sourceTree = "<group>"; };
		F96D437908F272B6004A47F5 /* init.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = init.test; sourceTree = "<group>"; };
		F96D437A08F272B6004A47F5 /* interp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = interp.test; sourceTree = "<group>"; };
		F96D437B08F272B6004A47F5 /* io.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = io.test; sourceTree = "<group>"; };
		F96D437C08F272B6004A47F5 /* ioCmd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = ioCmd.test; sourceTree = "<group>"; };
		F96D437D08F272B6004A47F5 /* iogt.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = iogt.test; sourceTree = "<group>"; };
		F96D437F08F272B6004A47F5 /* join.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = join.test; sourceTree = "<group>"; };
		F96D438008F272B6004A47F5 /* lindex.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lindex.test; sourceTree = "<group>"; };
		F96D438108F272B6004A47F5 /* link.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = link.test; sourceTree = "<group>"; };
		F96D438208F272B6004A47F5 /* linsert.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = linsert.test; sourceTree = "<group>"; };
		F96D438308F272B6004A47F5 /* list.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = list.test; sourceTree = "<group>"; };
		F96D438408F272B6004A47F5 /* listObj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = listObj.test; sourceTree = "<group>"; };
		F96D438508F272B6004A47F5 /* llength.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = llength.test; sourceTree = "<group>"; };
		F96D438608F272B6004A47F5 /* load.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = load.test; sourceTree = "<group>"; };
		F96D438708F272B6004A47F5 /* lrange.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lrange.test; sourceTree = "<group>"; };
		F96D438808F272B6004A47F5 /* lrepeat.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lrepeat.test; sourceTree = "<group>"; };
		F96D438908F272B6004A47F5 /* lreplace.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lreplace.test; sourceTree = "<group>"; };
		F96D438A08F272B6004A47F5 /* lsearch.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lsearch.test; sourceTree = "<group>"; };
		F96D438B08F272B6004A47F5 /* lset.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lset.test; sourceTree = "<group>"; };
		F96D438C08F272B6004A47F5 /* lsetComp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = lsetComp.test; sourceTree = "<group>"; };
		F96D438D08F272B6004A47F5 /* macOSXFCmd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = macOSXFCmd.test; sourceTree = "<group>"; };
		F96D438E08F272B6004A47F5 /* main.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = main.test; sourceTree = "<group>"; };
		F96D438F08F272B6004A47F5 /* misc.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = misc.test; sourceTree = "<group>"; };
		F96D439008F272B6004A47F5 /* msgcat.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgcat.test; sourceTree = "<group>"; };
		F96D439108F272B6004A47F5 /* namespace-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "namespace-old.test"; sourceTree = "<group>"; };
		F96D439208F272B7004A47F5 /* namespace.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = namespace.test; sourceTree = "<group>"; };
		F96D439308F272B7004A47F5 /* notify.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = notify.test; sourceTree = "<group>"; };
		F96D439408F272B7004A47F5 /* obj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = obj.test; sourceTree = "<group>"; };
		F96D439508F272B7004A47F5 /* opt.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = opt.test; sourceTree = "<group>"; };
		F96D439608F272B7004A47F5 /* package.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = package.test; sourceTree = "<group>"; };
		F96D439708F272B7004A47F5 /* parse.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = parse.test; sourceTree = "<group>"; };
		F96D439808F272B7004A47F5 /* parseExpr.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = parseExpr.test; sourceTree = "<group>"; };
		F96D439908F272B7004A47F5 /* parseOld.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = parseOld.test; sourceTree = "<group>"; };
		F96D439A08F272B7004A47F5 /* pid.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pid.test; sourceTree = "<group>"; };
		F96D439B08F272B7004A47F5 /* pkg.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkg.test; sourceTree = "<group>"; };
		F96D439C08F272B7004A47F5 /* pkgMkIndex.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgMkIndex.test; sourceTree = "<group>"; };
		F96D439D08F272B7004A47F5 /* platform.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = platform.test; sourceTree = "<group>"; };
		F96D439E08F272B7004A47F5 /* proc-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "proc-old.test"; sourceTree = "<group>"; };
		F96D439F08F272B7004A47F5 /* proc.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = proc.test; sourceTree = "<group>"; };
		F96D43A008F272B7004A47F5 /* pwd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pwd.test; sourceTree = "<group>"; };
		F96D43A108F272B7004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D43A208F272B7004A47F5 /* reg.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = reg.test; sourceTree = "<group>"; };
		F96D43A308F272B7004A47F5 /* regexp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = regexp.test; sourceTree = "<group>"; };
		F96D43A408F272B7004A47F5 /* regexpComp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = regexpComp.test; sourceTree = "<group>"; };
		F96D43A508F272B7004A47F5 /* registry.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = registry.test; sourceTree = "<group>"; };
		F96D43A608F272B7004A47F5 /* remote.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = remote.tcl; sourceTree = "<group>"; };
		F96D43A708F272B7004A47F5 /* rename.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = rename.test; sourceTree = "<group>"; };
		F96D43A808F272B7004A47F5 /* result.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = result.test; sourceTree = "<group>"; };
		F96D43A908F272B7004A47F5 /* safe.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = safe.test; sourceTree = "<group>"; };
		F96D43AA08F272B7004A47F5 /* scan.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scan.test; sourceTree = "<group>"; };
		F96D43AB08F272B7004A47F5 /* security.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = security.test; sourceTree = "<group>"; };
		F96D43AC08F272B7004A47F5 /* set-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "set-old.test"; sourceTree = "<group>"; };
		F96D43AD08F272B7004A47F5 /* set.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = set.test; sourceTree = "<group>"; };
		F96D43AE08F272B7004A47F5 /* socket.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = socket.test; sourceTree = "<group>"; };
		F96D43AF08F272B7004A47F5 /* source.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = source.test; sourceTree = "<group>"; };
		F96D43B008F272B7004A47F5 /* split.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = split.test; sourceTree = "<group>"; };
		F96D43B108F272B7004A47F5 /* stack.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = stack.test; sourceTree = "<group>"; };
		F96D43B208F272B7004A47F5 /* string.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = string.test; sourceTree = "<group>"; };
		F96D43B308F272B7004A47F5 /* stringComp.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = stringComp.test; sourceTree = "<group>"; };
		F96D43B408F272B7004A47F5 /* stringObj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = stringObj.test; sourceTree = "<group>"; };
		F96D43B508F272B7004A47F5 /* subst.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = subst.test; sourceTree = "<group>"; };
		F96D43B608F272B7004A47F5 /* switch.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = switch.test; sourceTree = "<group>"; };
		F96D43B708F272B7004A47F5 /* tcltest.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tcltest.test; sourceTree = "<group>"; };
		F96D43B808F272B7004A47F5 /* thread.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = thread.test; sourceTree = "<group>"; };
		F96D43B908F272B7004A47F5 /* timer.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = timer.test; sourceTree = "<group>"; };
		F96D43BA08F272B7004A47F5 /* tm.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tm.test; sourceTree = "<group>"; };
		F96D43BB08F272B7004A47F5 /* trace.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = trace.test; sourceTree = "<group>"; };
		F96D43BC08F272B7004A47F5 /* unixFCmd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixFCmd.test; sourceTree = "<group>"; };
		F96D43BD08F272B7004A47F5 /* unixFile.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixFile.test; sourceTree = "<group>"; };
		F96D43BE08F272B7004A47F5 /* unixInit.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixInit.test; sourceTree = "<group>"; };
		F96D43BF08F272B7004A47F5 /* unixNotfy.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unixNotfy.test; sourceTree = "<group>"; };
		F96D43C008F272B7004A47F5 /* unknown.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unknown.test; sourceTree = "<group>"; };
		F96D43C108F272B7004A47F5 /* unload.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unload.test; sourceTree = "<group>"; };
		F96D43C208F272B7004A47F5 /* uplevel.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = uplevel.test; sourceTree = "<group>"; };
		F96D43C308F272B7004A47F5 /* upvar.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = upvar.test; sourceTree = "<group>"; };
		F96D43C408F272B7004A47F5 /* utf.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = utf.test; sourceTree = "<group>"; };
		F96D43C508F272B7004A47F5 /* util.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = util.test; sourceTree = "<group>"; };
		F96D43C608F272B7004A47F5 /* var.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = var.test; sourceTree = "<group>"; };
		F96D43C708F272B7004A47F5 /* while-old.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "while-old.test"; sourceTree = "<group>"; };
		F96D43C808F272B7004A47F5 /* while.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = while.test; sourceTree = "<group>"; };
		F96D43C908F272B7004A47F5 /* winConsole.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winConsole.test; sourceTree = "<group>"; };
		F96D43CA08F272B7004A47F5 /* winDde.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winDde.test; sourceTree = "<group>"; };
		F96D43CB08F272B7004A47F5 /* winFCmd.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winFCmd.test; sourceTree = "<group>"; };
		F96D43CC08F272B7004A47F5 /* winFile.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winFile.test; sourceTree = "<group>"; };
		F96D43CD08F272B7004A47F5 /* winNotify.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winNotify.test; sourceTree = "<group>"; };
		F96D43CE08F272B7004A47F5 /* winPipe.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winPipe.test; sourceTree = "<group>"; };
		F96D43CF08F272B7004A47F5 /* winTime.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = winTime.test; sourceTree = "<group>"; };
		F96D43D108F272B8004A47F5 /* checkLibraryDoc.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = checkLibraryDoc.tcl; sourceTree = "<group>"; };
		F96D43D208F272B8004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F96D43D308F272B8004A47F5 /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F96D442208F272B8004A47F5 /* eolFix.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = eolFix.tcl; sourceTree = "<group>"; };
		F96D442408F272B8004A47F5 /* fix_tommath_h.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fix_tommath_h.tcl; sourceTree = "<group>"; };
		F96D442508F272B8004A47F5 /* genStubs.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = genStubs.tcl; sourceTree = "<group>"; };
		F96D442708F272B8004A47F5 /* index.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = index.tcl; sourceTree = "<group>"; };
		F96D442808F272B8004A47F5 /* installData.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = installData.tcl; sourceTree = "<group>"; };
		F96D442908F272B8004A47F5 /* loadICU.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = loadICU.tcl; sourceTree = "<group>"; };
		F96D442A08F272B8004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F96D442B08F272B8004A47F5 /* makeTestCases.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = makeTestCases.tcl; sourceTree = "<group>"; };
		F96D442C08F272B8004A47F5 /* man2help.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = man2help.tcl; sourceTree = "<group>"; };
		F96D442D08F272B8004A47F5 /* man2help2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = man2help2.tcl; sourceTree = "<group>"; };
		F96D442E08F272B8004A47F5 /* man2html.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = man2html.tcl; sourceTree = "<group>"; };
		F96D442F08F272B8004A47F5 /* man2html1.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = man2html1.tcl; sourceTree = "<group>"; };
		F96D443008F272B8004A47F5 /* man2html2.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = man2html2.tcl; sourceTree = "<group>"; };
		F96D443108F272B8004A47F5 /* man2tcl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = man2tcl.c; sourceTree = "<group>"; };
		F96D443208F272B8004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D443308F272B8004A47F5 /* regexpTestLib.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = regexpTestLib.tcl; sourceTree = "<group>"; };
		F96D443508F272B8004A47F5 /* tcl.hpj.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.hpj.in; sourceTree = "<group>"; };
		F96D443608F272B8004A47F5 /* tcl.wse.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.wse.in; sourceTree = "<group>"; };
		F96D443908F272B9004A47F5 /* tcltk-man2html.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = "tcltk-man2html.tcl"; sourceTree = "<group>"; };
		F96D443A08F272B9004A47F5 /* tclZIC.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclZIC.tcl; sourceTree = "<group>"; };
		F96D443B08F272B9004A47F5 /* uniClass.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = uniClass.tcl; sourceTree = "<group>"; };
		F96D443C08F272B9004A47F5 /* uniParse.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = uniParse.tcl; sourceTree = "<group>"; };
		F96D444008F272B9004A47F5 /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = "<group>"; };
		F96D444108F272B9004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F96D444208F272B9004A47F5 /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F96D444408F272B9004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F96D444508F272B9004A47F5 /* pkga.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkga.c; sourceTree = "<group>"; };
		F96D444608F272B9004A47F5 /* pkgb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkgb.c; sourceTree = "<group>"; };
		F96D444708F272B9004A47F5 /* pkgc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkgc.c; sourceTree = "<group>"; };
		F96D444808F272B9004A47F5 /* pkgd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkgd.c; sourceTree = "<group>"; };
		F96D444908F272B9004A47F5 /* pkge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkge.c; sourceTree = "<group>"; };
		F96D444B08F272B9004A47F5 /* pkgua.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkgua.c; sourceTree = "<group>"; };
		F96D444C08F272B9004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D444D08F272B9004A47F5 /* install-sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "install-sh"; sourceTree = "<group>"; };
		F96D444E08F272B9004A47F5 /* installManPage */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = installManPage; sourceTree = "<group>"; };
		F96D444F08F272B9004A47F5 /* ldAix */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = ldAix; sourceTree = "<group>"; };
		F96D445008F272B9004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F96D445208F272B9004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D445308F272B9004A47F5 /* tcl.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tcl.m4; sourceTree = "<group>"; };
		F96D445408F272B9004A47F5 /* tcl.spec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.spec; sourceTree = "<group>"; };
		F96D445508F272B9004A47F5 /* tclAppInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclAppInit.c; sourceTree = "<group>"; };
		F96D445608F272B9004A47F5 /* tclConfig.h.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = tclConfig.h.in; sourceTree = "<group>"; };
		F96D445708F272B9004A47F5 /* tclConfig.sh.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tclConfig.sh.in; sourceTree = "<group>"; };
		F96D445808F272B9004A47F5 /* tclLoadAix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadAix.c; sourceTree = "<group>"; };
		F96D445908F272B9004A47F5 /* tclLoadDl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadDl.c; sourceTree = "<group>"; };
		F96D445B08F272B9004A47F5 /* tclLoadDyld.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadDyld.c; sourceTree = "<group>"; };
		F96D445C08F272B9004A47F5 /* tclLoadNext.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadNext.c; sourceTree = "<group>"; };
		F96D445D08F272B9004A47F5 /* tclLoadOSF.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadOSF.c; sourceTree = "<group>"; };
		F96D445E08F272B9004A47F5 /* tclLoadShl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclLoadShl.c; sourceTree = "<group>"; };
		F96D445F08F272B9004A47F5 /* tclUnixChan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixChan.c; sourceTree = "<group>"; };
		F96D446008F272B9004A47F5 /* tclUnixEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixEvent.c; sourceTree = "<group>"; };
		F96D446108F272B9004A47F5 /* tclUnixFCmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixFCmd.c; sourceTree = "<group>"; };
		F96D446208F272B9004A47F5 /* tclUnixFile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixFile.c; sourceTree = "<group>"; };
		F96D446308F272B9004A47F5 /* tclUnixInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixInit.c; sourceTree = "<group>"; };
		F96D446408F272B9004A47F5 /* tclUnixNotfy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixNotfy.c; sourceTree = "<group>"; };
		F96D446508F272B9004A47F5 /* tclUnixPipe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixPipe.c; sourceTree = "<group>"; };
		F96D446608F272B9004A47F5 /* tclUnixPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclUnixPort.h; sourceTree = "<group>"; };
		F96D446708F272B9004A47F5 /* tclUnixSock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixSock.c; sourceTree = "<group>"; };
		F96D446808F272B9004A47F5 /* tclUnixTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixTest.c; sourceTree = "<group>"; };
		F96D446908F272B9004A47F5 /* tclUnixThrd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixThrd.c; sourceTree = "<group>"; };
		F96D446A08F272B9004A47F5 /* tclUnixThrd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclUnixThrd.h; sourceTree = "<group>"; };
		F96D446B08F272B9004A47F5 /* tclUnixTime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixTime.c; sourceTree = "<group>"; };
		F96D446C08F272B9004A47F5 /* tclXtNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtNotify.c; sourceTree = "<group>"; };
		F96D446D08F272B9004A47F5 /* tclXtTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtTest.c; sourceTree = "<group>"; };
		F96D447008F272BA004A47F5 /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = "<group>"; };
		F96D447108F272BA004A47F5 /* buildall.vc.bat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = buildall.vc.bat; sourceTree = "<group>"; };
		F96D447208F272BA004A47F5 /* cat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cat.c; sourceTree = "<group>"; };
		F96D447308F272BA004A47F5 /* coffbase.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = coffbase.txt; sourceTree = "<group>"; };
		F96D447408F272BA004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F96D447508F272BA004A47F5 /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F96D447708F272BA004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F96D447808F272BA004A47F5 /* makefile.vc */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = makefile.vc; sourceTree = "<group>"; };
		F96D447908F272BA004A47F5 /* nmakehlp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nmakehlp.c; sourceTree = "<group>"; };
		F96D447A08F272BA004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D447C08F272BA004A47F5 /* rules.vc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = rules.vc; sourceTree = "<group>"; };
		F96D447D08F272BA004A47F5 /* stub16.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stub16.c; sourceTree = "<group>"; };
		F96D447E08F272BA004A47F5 /* tcl.dsp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.dsp; sourceTree = "<group>"; };
		F96D447F08F272BA004A47F5 /* tcl.dsw */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.dsw; sourceTree = "<group>"; };
		F96D448008F272BA004A47F5 /* tcl.hpj.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.hpj.in; sourceTree = "<group>"; };
		F96D448108F272BA004A47F5 /* tcl.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tcl.m4; sourceTree = "<group>"; };
		F96D448208F272BA004A47F5 /* tcl.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.rc; sourceTree = "<group>"; };
		F96D448308F272BA004A47F5 /* tclAppInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclAppInit.c; sourceTree = "<group>"; };
		F96D448408F272BA004A47F5 /* tclConfig.sh.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = tclConfig.sh.in; sourceTree = "<group>"; };
		F96D448608F272BA004A47F5 /* tclsh.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tclsh.rc; sourceTree = "<group>"; };
		F96D448708F272BA004A47F5 /* tclWin32Dll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWin32Dll.c; sourceTree = "<group>"; };
		F96D448808F272BA004A47F5 /* tclWinChan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinChan.c; sourceTree = "<group>"; };
		F96D448908F272BA004A47F5 /* tclWinConsole.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinConsole.c; sourceTree = "<group>"; };
		F96D448A08F272BA004A47F5 /* tclWinDde.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinDde.c; sourceTree = "<group>"; };
		F96D448B08F272BA004A47F5 /* tclWinError.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinError.c; sourceTree = "<group>"; };
		F96D448C08F272BA004A47F5 /* tclWinFCmd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinFCmd.c; sourceTree = "<group>"; };
		F96D448D08F272BA004A47F5 /* tclWinFile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinFile.c; sourceTree = "<group>"; };
		F96D448E08F272BA004A47F5 /* tclWinInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinInit.c; sourceTree = "<group>"; };
		F96D448F08F272BA004A47F5 /* tclWinInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclWinInt.h; sourceTree = "<group>"; };
		F96D449008F272BA004A47F5 /* tclWinLoad.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinLoad.c; sourceTree = "<group>"; };
		F96D449108F272BA004A47F5 /* tclWinNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinNotify.c; sourceTree = "<group>"; };
		F96D449208F272BA004A47F5 /* tclWinPipe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinPipe.c; sourceTree = "<group>"; };
		F96D449308F272BA004A47F5 /* tclWinPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclWinPort.h; sourceTree = "<group>"; };
		F96D449408F272BA004A47F5 /* tclWinReg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinReg.c; sourceTree = "<group>"; };
		F96D449508F272BA004A47F5 /* tclWinSerial.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinSerial.c; sourceTree = "<group>"; };
		F96D449608F272BA004A47F5 /* tclWinSock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinSock.c; sourceTree = "<group>"; };
		F96D449708F272BA004A47F5 /* tclWinTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinTest.c; sourceTree = "<group>"; };
		F96D449808F272BA004A47F5 /* tclWinThrd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinThrd.c; sourceTree = "<group>"; };
		F96D449908F272BA004A47F5 /* tclWinThrd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclWinThrd.h; sourceTree = "<group>"; };
		F96D449A08F272BA004A47F5 /* tclWinTime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclWinTime.c; sourceTree = "<group>"; };
		F973E5960EE99384001A648E /* vistaTheme.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = vistaTheme.tcl; sourceTree = "<group>"; };
		F974D56C0FBE7D6300BF728B /* http11.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = http11.test; sourceTree = "<group>"; };
		F974D56D0FBE7D6300BF728B /* httpd11.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = httpd11.tcl; sourceTree = "<group>"; };
		F974D5720FBE7DC600BF728B /* coroutine.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = coroutine.n; sourceTree = "<group>"; };
		F974D5760FBE7E1900BF728B /* tailcall.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = tailcall.n; sourceTree = "<group>"; };
		F974D5770FBE7E6100BF728B /* coroutine.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = coroutine.test; sourceTree = "<group>"; };
		F974D5780FBE7E6100BF728B /* tailcall.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tailcall.test; sourceTree = "<group>"; };
		F974D5790FBE7E9C00BF728B /* tcl.pc.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tcl.pc.in; sourceTree = "<group>"; };
		F974D57B0FBE7EC000BF728B /* tk.pc.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tk.pc.in; sourceTree = "<group>"; };
		F974D57C0FBE7EFF00BF728B /* iconlist.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = iconlist.tcl; sourceTree = "<group>"; };
		F974D57D0FBE7EFF00BF728B /* icons.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = icons.tcl; sourceTree = "<group>"; };
		F97590AE1039A96200558A9A /* Wish.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.sdef; path = Wish.sdef; sourceTree = "<group>"; };
		F976F6A70C325FB6005066D9 /* tkMacOSXPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXPrivate.h; sourceTree = "<group>"; };
		F97AE7F10B65C1E900310EA2 /* Tk-Common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "Tk-Common.xcconfig"; sourceTree = "<group>"; };
		F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "Tk-Release.xcconfig"; sourceTree = "<group>"; };
		F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "Tk-Debug.xcconfig"; sourceTree = "<group>"; };
		F98383650F0FA43900171CA6 /* checkbutton.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = checkbutton.test; sourceTree = "<group>"; };
		F98383680F0FA44700171CA6 /* radiobutton.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = radiobutton.test; sourceTree = "<group>"; };
		F9903CAF094FAADA004613E9 /* tclTomMath.decls */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclTomMath.decls; sourceTree = "<group>"; };
		F9903CB0094FAADA004613E9 /* tclTomMathDecls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclTomMathDecls.h; sourceTree = "<group>"; };
		F99388380EE0114B0065FE6B /* fontchooser.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fontchooser.tcl; sourceTree = "<group>"; };
		F99388950EE02D980065FE6B /* fontchooser.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = fontchooser.test; sourceTree = "<group>"; };
		F99D61180EF5573A00BBFE01 /* TclZlib.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = TclZlib.3; sourceTree = "<group>"; };
		F9A3082D08F2D4AB00BAE1AB /* Tk.framework */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Tk.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		F9A3084B08F2D4CE00BAE1AB /* Wish.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Wish.app; sourceTree = BUILT_PRODUCTS_DIR; };
		F9A3084E08F2D4F400BAE1AB /* Tcl.framework */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.framework; path = Tcl.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		F9A493240CEBF38300B78AE2 /* chanio.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = chanio.test; sourceTree = "<group>"; };
		F9C888C20EEF6571003F63AD /* fontchooser.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = fontchooser.n; sourceTree = "<group>"; };
		F9C9CBFF0E84059800E00935 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
		F9D1360A0CDC252C00DBE0B5 /* mclist.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = mclist.tcl; sourceTree = "<group>"; };
		F9DD99BC0F07DF850018B2E4 /* tkImgPNG.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkImgPNG.c; sourceTree = "<group>"; };
		F9DD99BF0F07DFCD0018B2E4 /* imgPNG.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = imgPNG.test; sourceTree = "<group>"; };
		F9ECB1120B26521500A28025 /* pkgIndex.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pkgIndex.tcl; sourceTree = "<group>"; };
		F9ECB1130B26521500A28025 /* platform.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = platform.tcl; sourceTree = "<group>"; };
		F9ECB1140B26521500A28025 /* shell.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = shell.tcl; sourceTree = "<group>"; };
		F9ECB1CA0B2652D300A28025 /* apply.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = apply.test; sourceTree = "<group>"; };
		F9ECB1CB0B26534C00A28025 /* mathop.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = mathop.test; sourceTree = "<group>"; };
		F9ECB1E10B26543C00A28025 /* platform_shell.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = platform_shell.n; sourceTree = "<group>"; };
		F9ECB1E20B26543C00A28025 /* platform.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = platform.n; sourceTree = "<group>"; };
		F9F4415D0C8BAE6F00BCCD67 /* tclDTrace.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.dtrace; path = tclDTrace.d; sourceTree = "<group>"; };
		F9F4EFDC0CC7B3CA00378A27 /* ttkpane.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; languageSpecificationIdentifier = shell; path = ttkpane.tcl; sourceTree = "<group>"; };
		F9F4EFDD0CC7B3CB00378A27 /* ttkmenu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; languageSpecificationIdentifier = shell; path = ttkmenu.tcl; sourceTree = "<group>"; };
		F9FC77B70AB29E9100B7077D /* tclUnixCompat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixCompat.c; sourceTree = "<group>"; };
		F9FD31F40CC1AD070073837D /* tktest-X11 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "tktest-X11"; sourceTree = BUILT_PRODUCTS_DIR; };
		F9FD32140CC1AF170073837D /* libX11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libX11.dylib; path = /usr/X11R6/lib/libX11.dylib; sourceTree = "<absolute>"; };
		F9FD32150CC1AF170073837D /* libXext.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libXext.dylib; path = /usr/X11R6/lib/libXext.dylib; sourceTree = "<absolute>"; };
		F9FD32160CC1AF170073837D /* libXss.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libXss.dylib; path = /usr/X11R6/lib/libXss.dylib; sourceTree = "<absolute>"; };
		F9FD34990CC1BB0D0073837D /* libfreetype.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfreetype.dylib; path = /usr/X11R6/lib/libfreetype.dylib; sourceTree = "<absolute>"; };
		F9FD349A0CC1BB0D0073837D /* libXft.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libXft.dylib; path = /usr/X11R6/lib/libXft.dylib; sourceTree = "<absolute>"; };
		F9FD34C30CC1BBD70073837D /* libfontconfig.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfontconfig.dylib; path = /usr/X11R6/lib/libfontconfig.dylib; sourceTree = "<absolute>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		8DD76FAD0486AB0100D96B5E /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				F966C07508F2820D005CB29B /* CoreFoundation.framework in Frameworks */,
				F96437E70EF0D652003F468E /* libz.dylib in Frameworks */,
				F966C07708F2821B005CB29B /* Carbon.framework in Frameworks */,
				F966C07908F28233005CB29B /* IOKit.framework in Frameworks */,
				F94523A20E6FC2AC00C1D987 /* Cocoa.framework in Frameworks */,
				F9C9CC000E84059800E00935 /* ApplicationServices.framework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		F9FD31E30CC1AD070073837D /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				F9FD31E40CC1AD070073837D /* CoreFoundation.framework in Frameworks */,
				F96437E80EF0D652003F468E /* libz.dylib in Frameworks */,
				F9FD32170CC1AF170073837D /* libX11.dylib in Frameworks */,
				F9FD32180CC1AF170073837D /* libXext.dylib in Frameworks */,
				F9FD32190CC1AF170073837D /* libXss.dylib in Frameworks */,
				F9FD349C0CC1BB0D0073837D /* libXft.dylib in Frameworks */,
				F9FD349B0CC1BB0D0073837D /* libfreetype.dylib in Frameworks */,
				F9FD34C40CC1BBD70073837D /* libfontconfig.dylib in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		08FB7794FE84155DC02AAC07 /* Tk */ = {
			isa = PBXGroup;
			children = (
				F96D3DF708F271BE004A47F5 /* Tk Sources */,
				F96D3DF608F27169004A47F5 /* Tcl Sources */,
				F966C06F08F281DC005CB29B /* Frameworks */,
				1AB674ADFE9D54B511CA2CBB /* Products */,
			);
			comments = "Copyright (c) 2004-2009 Daniel A. Steffen <[email protected]>\nCopyright 2008-2009, Apple Inc.\n\nSee the file \"license.terms\" for information on usage and redistribution of\nthis file, and for a DISCLAIMER OF ALL WARRANTIES.\n";
			name = Tk;
			path = .;
			sourceTree = SOURCE_ROOT;
		};
		1AB674ADFE9D54B511CA2CBB /* Products */ = {
			isa = PBXGroup;
			children = (
				F9A3084B08F2D4CE00BAE1AB /* Wish.app */,
				F9A3082D08F2D4AB00BAE1AB /* Tk.framework */,
				F9A3084E08F2D4F400BAE1AB /* Tcl.framework */,
				8DD76FB20486AB0100D96B5E /* tktest */,
				F9FD31F40CC1AD070073837D /* tktest-X11 */,
			);
			includeInIndex = 0;
			name = Products;
			sourceTree = "<group>";
		};
		F9183E690EFC81560030B814 /* pkgs */ = {
			isa = PBXGroup;
			children = (
				F9183E6A0EFC81560030B814 /* README */,
				F946FB8B0FBE3AED00CD6495 /* itcl */,
				F9183E8F0EFC817B0030B814 /* tdbc */,
			);
			path = pkgs;
			sourceTree = "<group>";
		};
		F966BA0308F27A37005CB29B /* bitmaps */ = {
			isa = PBXGroup;
			children = (
				F966BA0408F27A37005CB29B /* error.xbm */,
				F966BA0508F27A37005CB29B /* gray12.xbm */,
				F966BA0608F27A37005CB29B /* gray25.xbm */,
				F966BA0708F27A37005CB29B /* gray50.xbm */,
				F966BA0808F27A37005CB29B /* gray75.xbm */,
				F966BA0908F27A37005CB29B /* hourglass.xbm */,
				F966BA0A08F27A37005CB29B /* info.xbm */,
				F966BA0B08F27A37005CB29B /* questhead.xbm */,
				F966BA0C08F27A37005CB29B /* question.xbm */,
				F966BA0D08F27A37005CB29B /* warning.xbm */,
			);
			path = bitmaps;
			sourceTree = "<group>";
		};
		F966BA1008F27A37005CB29B /* doc */ = {
			isa = PBXGroup;
			children = (
				F966BA1108F27A37005CB29B /* 3DBorder.3 */,
				F966BA1208F27A37005CB29B /* AddOption.3 */,
				F966BA1308F27A37005CB29B /* bell.n */,
				F966BA1408F27A37005CB29B /* bind.n */,
				F966BA1508F27A37005CB29B /* BindTable.3 */,
				F966BA1608F27A37005CB29B /* bindtags.n */,
				F966BA1708F27A37005CB29B /* bitmap.n */,
				F966BA1808F27A37005CB29B /* button.n */,
				F966BA1908F27A37005CB29B /* canvas.n */,
				F966BA1A08F27A37005CB29B /* CanvPsY.3 */,
				F966BA1B08F27A37005CB29B /* CanvTkwin.3 */,
				F966BA1C08F27A37005CB29B /* CanvTxtInfo.3 */,
				F966BA1D08F27A37005CB29B /* checkbutton.n */,
				F966BA1E08F27A37005CB29B /* chooseColor.n */,
				F966BA1F08F27A37005CB29B /* chooseDirectory.n */,
				F966BA2008F27A37005CB29B /* Clipboard.3 */,
				F966BA2108F27A37005CB29B /* clipboard.n */,
				F966BA2208F27A37005CB29B /* ClrSelect.3 */,
				F966BA2308F27A37005CB29B /* colors.n */,
				F966BA2408F27A37005CB29B /* ConfigWidg.3 */,
				F966BA2508F27A37005CB29B /* ConfigWind.3 */,
				F966BA2608F27A37005CB29B /* console.n */,
				F966BA2708F27A37005CB29B /* CoordToWin.3 */,
				F966BA2808F27A37005CB29B /* CrtCmHdlr.3 */,
				F966BA2908F27A37005CB29B /* CrtErrHdlr.3 */,
				F966BA2A08F27A37005CB29B /* CrtGenHdlr.3 */,
				F966BA2B08F27A37005CB29B /* CrtImgType.3 */,
				F966BA2C08F27A37005CB29B /* CrtItemType.3 */,
				F966BA2D08F27A37005CB29B /* CrtPhImgFmt.3 */,
				F966BA2E08F27A37005CB29B /* CrtSelHdlr.3 */,
				F966BA2F08F27A37005CB29B /* CrtWindow.3 */,
				F966BA3008F27A37005CB29B /* cursors.n */,
				F966BA3108F27A37005CB29B /* DeleteImg.3 */,
				F966BA3208F27A37005CB29B /* destroy.n */,
				F966BA3308F27A37005CB29B /* dialog.n */,
				F966BA3408F27A37005CB29B /* DrawFocHlt.3 */,
				F966BA3508F27A37005CB29B /* entry.n */,
				F966BA3608F27A37005CB29B /* event.n */,
				F966BA3708F27A37005CB29B /* EventHndlr.3 */,
				F966BA3808F27A37005CB29B /* FindPhoto.3 */,
				F966BA3908F27A37005CB29B /* focus.n */,
				F966BA3A08F27A37005CB29B /* focusNext.n */,
				F966BA3B08F27A37005CB29B /* font.n */,
				F9C888C20EEF6571003F63AD /* fontchooser.n */,
				F966BA3C08F27A37005CB29B /* FontId.3 */,
				F966BA3D08F27A37005CB29B /* frame.n */,
				F966BA3E08F27A37005CB29B /* FreeXId.3 */,
				F966BA3F08F27A37005CB29B /* GeomReq.3 */,
				F966BA4008F27A37005CB29B /* GetAnchor.3 */,
				F966BA4108F27A37005CB29B /* GetBitmap.3 */,
				F966BA4208F27A37005CB29B /* GetCapStyl.3 */,
				F966BA4308F27A37005CB29B /* GetClrmap.3 */,
				F966BA4408F27A37005CB29B /* GetColor.3 */,
				F966BA4508F27A37005CB29B /* GetCursor.3 */,
				F966BA4608F27A37005CB29B /* GetDash.3 */,
				F966BA4708F27A37005CB29B /* GetFont.3 */,
				F966BA4808F27A37005CB29B /* GetGC.3 */,
				F966BA4908F27A37005CB29B /* GetHINSTANCE.3 */,
				F966BA4A08F27A37005CB29B /* GetHWND.3 */,
				F966BA4B08F27A37005CB29B /* GetImage.3 */,
				F966BA4C08F27A37005CB29B /* GetJoinStl.3 */,
				F966BA4D08F27A37005CB29B /* GetJustify.3 */,
				F966BA4E08F27A37005CB29B /* getOpenFile.n */,
				F966BA4F08F27A37005CB29B /* GetOption.3 */,
				F966BA5008F27A38005CB29B /* GetPixels.3 */,
				F966BA5108F27A38005CB29B /* GetPixmap.3 */,
				F966BA5208F27A38005CB29B /* GetRelief.3 */,
				F966BA5308F27A38005CB29B /* GetRootCrd.3 */,
				F966BA5408F27A38005CB29B /* GetScroll.3 */,
				F966BA5508F27A38005CB29B /* GetSelect.3 */,
				F966BA5608F27A38005CB29B /* GetUid.3 */,
				F966BA5708F27A38005CB29B /* GetVisual.3 */,
				F966BA5808F27A38005CB29B /* GetVRoot.3 */,
				F966BA5908F27A38005CB29B /* Grab.3 */,
				F966BA5A08F27A38005CB29B /* grab.n */,
				F966BA5B08F27A38005CB29B /* grid.n */,
				F966BA5C08F27A38005CB29B /* HandleEvent.3 */,
				F966BA5D08F27A38005CB29B /* HWNDToWindow.3 */,
				F966BA5E08F27A38005CB29B /* IdToWindow.3 */,
				F966BA5F08F27A38005CB29B /* image.n */,
				F966BA6008F27A38005CB29B /* ImgChanged.3 */,
				F966BA6108F27A38005CB29B /* Inactive.3 */,
				F966BA6208F27A38005CB29B /* InternAtom.3 */,
				F966BA6308F27A38005CB29B /* keysyms.n */,
				F966BA6408F27A38005CB29B /* label.n */,
				F966BA6508F27A38005CB29B /* labelframe.n */,
				F966BA6608F27A38005CB29B /* listbox.n */,
				F966BA6708F27A38005CB29B /* loadTk.n */,
				F966BA6808F27A38005CB29B /* lower.n */,
				F966BA6908F27A38005CB29B /* MainLoop.3 */,
				F966BA6A08F27A38005CB29B /* MaintGeom.3 */,
				F966BA6B08F27A38005CB29B /* MainWin.3 */,
				F966BA6D08F27A38005CB29B /* ManageGeom.3 */,
				F966BA6E08F27A38005CB29B /* MapWindow.3 */,
				F966BA6F08F27A38005CB29B /* MeasureChar.3 */,
				F966BA7008F27A38005CB29B /* menu.n */,
				F966BA7108F27A38005CB29B /* menubar.n */,
				F966BA7208F27A38005CB29B /* menubutton.n */,
				F966BA7308F27A38005CB29B /* message.n */,
				F966BA7408F27A38005CB29B /* messageBox.n */,
				F966BA7508F27A38005CB29B /* MoveToplev.3 */,
				F966BA7608F27A38005CB29B /* Name.3 */,
				F966BA7708F27A38005CB29B /* NameOfImg.3 */,
				F966BA7808F27A38005CB29B /* option.n */,
				F966BA7908F27A38005CB29B /* optionMenu.n */,
				F966BA7A08F27A38005CB29B /* options.n */,
				F966BA7B08F27A38005CB29B /* OwnSelect.3 */,
				F966BA7C08F27A38005CB29B /* pack-old.n */,
				F966BA7D08F27A38005CB29B /* pack.n */,
				F966BA7E08F27A38005CB29B /* palette.n */,
				F966BA7F08F27A38005CB29B /* panedwindow.n */,
				F966BA8008F27A38005CB29B /* ParseArgv.3 */,
				F966BA8108F27A38005CB29B /* photo.n */,
				F966BA8208F27A38005CB29B /* place.n */,
				F966BA8308F27A38005CB29B /* popup.n */,
				F966BA8408F27A38005CB29B /* QWinEvent.3 */,
				F966BA8508F27A38005CB29B /* radiobutton.n */,
				F966BA8608F27A38005CB29B /* raise.n */,
				F966BA8708F27A38005CB29B /* Restack.3 */,
				F966BA8808F27A38005CB29B /* RestrictEv.3 */,
				F966BA8908F27A38005CB29B /* scale.n */,
				F966BA8A08F27A38005CB29B /* scrollbar.n */,
				F966BA8B08F27A38005CB29B /* selection.n */,
				F966BA8C08F27A38005CB29B /* send.n */,
				F966BA8D08F27A38005CB29B /* SetAppName.3 */,
				F966BA8E08F27A38005CB29B /* SetCaret.3 */,
				F966BA8F08F27A38005CB29B /* SetClass.3 */,
				F966BA9008F27A38005CB29B /* SetClassProcs.3 */,
				F966BA9108F27A38005CB29B /* SetGrid.3 */,
				F966BA9208F27A38005CB29B /* SetOptions.3 */,
				F966BA9308F27A38005CB29B /* SetVisual.3 */,
				F966BA9408F27A38005CB29B /* spinbox.n */,
				F966BA9508F27A38005CB29B /* StrictMotif.3 */,
				F966BA9608F27A38005CB29B /* text.n */,
				F966BA9708F27A38005CB29B /* TextLayout.3 */,
				F966BA9808F27A38005CB29B /* tk.n */,
				F966BA9A08F27A38005CB29B /* Tk_Init.3 */,
				F966BA9B08F27A38005CB29B /* Tk_Main.3 */,
				F966BA9C08F27A38005CB29B /* tkerror.n */,
				F966BA9D08F27A38005CB29B /* TkInitStubs.3 */,
				F966BA9E08F27A38005CB29B /* tkvars.n */,
				F966BA9F08F27A38005CB29B /* tkwait.n */,
				F966BAA008F27A38005CB29B /* toplevel.n */,
				F968886B0AF788F6000797B5 /* ttk_button.n */,
				F968886C0AF788F6000797B5 /* ttk_checkbutton.n */,
				F968886D0AF788F6000797B5 /* ttk_combobox.n */,
				F968886F0AF788F6000797B5 /* ttk_entry.n */,
				F96888700AF788F6000797B5 /* ttk_frame.n */,
				F96888710AF788F6000797B5 /* ttk_Geometry.3 */,
				F96888720AF788F6000797B5 /* ttk_image.n */,
				F96888730AF788F6000797B5 /* ttk_intro.n */,
				F96888740AF788F6000797B5 /* ttk_label.n */,
				F96888750AF788F6000797B5 /* ttk_labelframe.n */,
				F96888760AF788F6000797B5 /* ttk_menubutton.n */,
				F96888770AF788F6000797B5 /* ttk_notebook.n */,
				F96888780AF788F6000797B5 /* ttk_panedwindow.n */,
				F96888790AF788F6000797B5 /* ttk_progressbar.n */,
				F968887A0AF788F6000797B5 /* ttk_radiobutton.n */,
				F968887B0AF788F6000797B5 /* ttk_scrollbar.n */,
				F968887C0AF788F6000797B5 /* ttk_separator.n */,
				F968887D0AF788F6000797B5 /* ttk_sizegrip.n */,
				F968887E0AF788F6000797B5 /* ttk_style.n */,
				F968887F0AF788F6000797B5 /* ttk_Theme.3 */,
				F96888800AF788F6000797B5 /* ttk_treeview.n */,
				F96888810AF788F6000797B5 /* ttk_widget.n */,
				F966BAA108F27A38005CB29B /* WindowId.3 */,
				F966BAA208F27A38005CB29B /* winfo.n */,
				F966BAA308F27A38005CB29B /* wish.1 */,
				F966BAA408F27A38005CB29B /* wm.n */,
			);
			path = doc;
			sourceTree = "<group>";
		};
		F966BAA508F27A38005CB29B /* generic */ = {
			isa = PBXGroup;
			children = (
				F966BAA608F27A38005CB29B /* default.h */,
				F966BAA708F27A38005CB29B /* ks_names.h */,
				F966BAA908F27A39005CB29B /* README */,
				F966BAAA08F27A39005CB29B /* tk.decls */,
				F966BAAB08F27A39005CB29B /* tk.h */,
				F966BAAC08F27A39005CB29B /* tk3d.c */,
				F966BAAD08F27A39005CB29B /* tk3d.h */,
				F966BAAE08F27A39005CB29B /* tkArgv.c */,
				F966BAAF08F27A39005CB29B /* tkAtom.c */,
				F966BAB008F27A39005CB29B /* tkBind.c */,
				F966BAB108F27A39005CB29B /* tkBitmap.c */,
				F9152B080EAF8A5000CD5C7B /* tkBusy.c */,
				F966BAB208F27A39005CB29B /* tkButton.c */,
				F966BAB308F27A39005CB29B /* tkButton.h */,
				F966BAB408F27A39005CB29B /* tkCanvArc.c */,
				F966BAB508F27A39005CB29B /* tkCanvas.c */,
				F966BAB608F27A39005CB29B /* tkCanvas.h */,
				F966BAB708F27A39005CB29B /* tkCanvBmap.c */,
				F966BAB808F27A39005CB29B /* tkCanvImg.c */,
				F966BAB908F27A39005CB29B /* tkCanvLine.c */,
				F966BABA08F27A39005CB29B /* tkCanvPoly.c */,
				F966BABB08F27A39005CB29B /* tkCanvPs.c */,
				F966BABD08F27A39005CB29B /* tkCanvText.c */,
				F966BABE08F27A39005CB29B /* tkCanvUtil.c */,
				F966BABF08F27A39005CB29B /* tkCanvWind.c */,
				F966BAC008F27A39005CB29B /* tkClipboard.c */,
				F966BAC108F27A39005CB29B /* tkCmds.c */,
				F966BAC208F27A39005CB29B /* tkColor.c */,
				F966BAC308F27A39005CB29B /* tkColor.h */,
				F966BAC408F27A39005CB29B /* tkConfig.c */,
				F966BAC508F27A39005CB29B /* tkConsole.c */,
				F966BAC608F27A39005CB29B /* tkCursor.c */,
				F966BAC708F27A39005CB29B /* tkDecls.h */,
				F966BAC808F27A39005CB29B /* tkEntry.c */,
				F966BAC908F27A39005CB29B /* tkEntry.h */,
				F966BACA08F27A39005CB29B /* tkError.c */,
				F966BACB08F27A39005CB29B /* tkEvent.c */,
				F966BACC08F27A39005CB29B /* tkFileFilter.c */,
				F966BACD08F27A39005CB29B /* tkFileFilter.h */,
				F966BACE08F27A39005CB29B /* tkFocus.c */,
				F966BACF08F27A39005CB29B /* tkFont.c */,
				F966BAD008F27A39005CB29B /* tkFont.h */,
				F966BAD108F27A39005CB29B /* tkFrame.c */,
				F966BAD208F27A39005CB29B /* tkGC.c */,
				F966BAD308F27A39005CB29B /* tkGeometry.c */,
				F966BAD408F27A39005CB29B /* tkGet.c */,
				F966BAD508F27A39005CB29B /* tkGrab.c */,
				F966BAD608F27A39005CB29B /* tkGrid.c */,
				F966BAD708F27A39005CB29B /* tkImage.c */,
				F966BAD808F27A39005CB29B /* tkImgBmap.c */,
				F966BAD908F27A39005CB29B /* tkImgGIF.c */,
				F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */,
				F966BADA08F27A39005CB29B /* tkImgPhoto.c */,
				F9DD99BC0F07DF850018B2E4 /* tkImgPNG.c */,
				F966BADB08F27A39005CB29B /* tkImgPPM.c */,
				F966BADC08F27A39005CB29B /* tkImgUtil.c */,
				F966BADE08F27A39005CB29B /* tkInt.decls */,
				F966BADF08F27A39005CB29B /* tkInt.h */,
				F966BAE108F27A39005CB29B /* tkIntDecls.h */,
				F966BAE208F27A39005CB29B /* tkIntPlatDecls.h */,
				F966BAE308F27A39005CB29B /* tkIntXlibDecls.h */,
				F966BAE408F27A39005CB29B /* tkListbox.c */,
				F966BAE508F27A39005CB29B /* tkMacWinMenu.c */,
				F966BAE608F27A39005CB29B /* tkMain.c */,
				F966BAE708F27A39005CB29B /* tkMenu.c */,
				F966BAE808F27A39005CB29B /* tkMenu.h */,
				F966BAE908F27A39005CB29B /* tkMenubutton.c */,
				F966BAEA08F27A39005CB29B /* tkMenubutton.h */,
				F966BAEB08F27A39005CB29B /* tkMenuDraw.c */,
				F966BAEC08F27A39005CB29B /* tkMessage.c */,
				F966BAED08F27A39005CB29B /* tkObj.c */,
				F966BAEE08F27A39005CB29B /* tkOldConfig.c */,
				F966BAEF08F27A39005CB29B /* tkOption.c */,
				F966BAF008F27A39005CB29B /* tkPack.c */,
				F966BAF108F27A39005CB29B /* tkPanedWindow.c */,
				F966BAF208F27A39005CB29B /* tkPlace.c */,
				F966BAF308F27A39005CB29B /* tkPlatDecls.h */,
				F966BAF408F27A39005CB29B /* tkPointer.c */,
				F966BAF508F27A39005CB29B /* tkPort.h */,
				F966BAF608F27A39005CB29B /* tkRectOval.c */,
				F966BAF708F27A39005CB29B /* tkScale.c */,
				F966BAF808F27A39005CB29B /* tkScale.h */,
				F966BAF908F27A39005CB29B /* tkScrollbar.c */,
				F966BAFA08F27A39005CB29B /* tkScrollbar.h */,
				F966BAFB08F27A39005CB29B /* tkSelect.c */,
				F966BAFC08F27A39005CB29B /* tkSelect.h */,
				F966BAFD08F27A39005CB29B /* tkSquare.c */,
				F966BAFE08F27A39005CB29B /* tkOldTest.c */,
				F966BAFF08F27A39005CB29B /* tkStubInit.c */,
				F966BB0008F27A39005CB29B /* tkStubLib.c */,
				F966BB0108F27A39005CB29B /* tkStyle.c */,
				F966BB0208F27A39005CB29B /* tkTest.c */,
				F966BB0308F27A39005CB29B /* tkText.c */,
				F966BB0408F27A39005CB29B /* tkText.h */,
				F966BB0508F27A39005CB29B /* tkTextBTree.c */,
				F966BB0608F27A39005CB29B /* tkTextDisp.c */,
				F966BB0808F27A39005CB29B /* tkTextImage.c */,
				F966BB0908F27A39005CB29B /* tkTextIndex.c */,
				F966BB0A08F27A39005CB29B /* tkTextMark.c */,
				F966BB0B08F27A39005CB29B /* tkTextTag.c */,
				F966BB0C08F27A39005CB29B /* tkTextWind.c */,
				F966BB0D08F27A39005CB29B /* tkTrig.c */,
				F966BB0E08F27A39005CB29B /* tkUndo.c */,
				F966BB0F08F27A39005CB29B /* tkUndo.h */,
				F966BB1008F27A39005CB29B /* tkUtil.c */,
				F966BB1108F27A39005CB29B /* tkVisual.c */,
				F966BB1208F27A39005CB29B /* tkWindow.c */,
				F96887DF0AF786D5000797B5 /* ttk */,
			);
			path = generic;
			sourceTree = "<group>";
		};
		F966BB1308F27A39005CB29B /* library */ = {
			isa = PBXGroup;
			children = (
				F966BB1408F27A39005CB29B /* bgerror.tcl */,
				F966BB1508F27A39005CB29B /* button.tcl */,
				F966BB1608F27A39005CB29B /* choosedir.tcl */,
				F966BB1708F27A39005CB29B /* clrpick.tcl */,
				F966BB1808F27A39005CB29B /* comdlg.tcl */,
				F966BB1908F27A39005CB29B /* console.tcl */,
				F966BB1A08F27A39005CB29B /* demos */,
				F966BB6208F27A3A005CB29B /* dialog.tcl */,
				F966BB6308F27A3A005CB29B /* entry.tcl */,
				F966BB6408F27A3A005CB29B /* focus.tcl */,
				F99388380EE0114B0065FE6B /* fontchooser.tcl */,
				F974D57C0FBE7EFF00BF728B /* iconlist.tcl */,
				F974D57D0FBE7EFF00BF728B /* icons.tcl */,
				F966BB7308F27A3A005CB29B /* listbox.tcl */,
				F966BB7408F27A3A005CB29B /* menu.tcl */,
				F966BB7508F27A3A005CB29B /* mkpsenc.tcl */,
				F966BB7608F27A3A005CB29B /* msgbox.tcl */,
				F966BB8608F27A3A005CB29B /* obsolete.tcl */,
				F966BB8708F27A3A005CB29B /* optMenu.tcl */,
				F966BB8808F27A3A005CB29B /* palette.tcl */,
				F966BB8908F27A3B005CB29B /* panedwindow.tcl */,
				F966BB8B08F27A3B005CB29B /* safetk.tcl */,
				F966BB8C08F27A3B005CB29B /* scale.tcl */,
				F966BB8D08F27A3B005CB29B /* scrlbar.tcl */,
				F966BB8E08F27A3B005CB29B /* spinbox.tcl */,
				F966BB8F08F27A3B005CB29B /* tclIndex */,
				F966BB9008F27A3B005CB29B /* tearoff.tcl */,
				F966BB9108F27A3B005CB29B /* text.tcl */,
				F966BB9208F27A3B005CB29B /* tk.tcl */,
				F966BB9308F27A3B005CB29B /* tkfbox.tcl */,
				F96888360AF787B3000797B5 /* ttk */,
				F966BB9408F27A3B005CB29B /* unsupported.tcl */,
				F966BB9508F27A3B005CB29B /* xmfbox.tcl */,
			);
			path = library;
			sourceTree = "<group>";
		};
		F966BB1A08F27A39005CB29B /* demos */ = {
			isa = PBXGroup;
			children = (
				F966BB1B08F27A39005CB29B /* anilabel.tcl */,
				F966BB1C08F27A39005CB29B /* aniwave.tcl */,
				F966BB1D08F27A39005CB29B /* arrow.tcl */,
				F966BB1E08F27A39005CB29B /* bind.tcl */,
				F966BB1F08F27A39005CB29B /* bitmap.tcl */,
				F966BB2008F27A39005CB29B /* browse */,
				F966BB2108F27A39005CB29B /* button.tcl */,
				F966BB2208F27A39005CB29B /* check.tcl */,
				F966BB2308F27A39005CB29B /* clrpick.tcl */,
				F966BB2408F27A39005CB29B /* colors.tcl */,
				F936FCDB0CCD984600716967 /* combo.tcl */,
				F966BB2508F27A39005CB29B /* cscroll.tcl */,
				F966BB2608F27A39005CB29B /* ctext.tcl */,
				F966BB2708F27A39005CB29B /* dialog1.tcl */,
				F966BB2808F27A39005CB29B /* dialog2.tcl */,
				F966BB2A08F27A39005CB29B /* entry1.tcl */,
				F966BB2B08F27A39005CB29B /* entry2.tcl */,
				F966BB2C08F27A39005CB29B /* entry3.tcl */,
				F966BB2D08F27A39005CB29B /* filebox.tcl */,
				F966BB2E08F27A39005CB29B /* floor.tcl */,
				F91543270EF201A90032D1E8 /* fontchoose.tcl */,
				F966BB2F08F27A39005CB29B /* form.tcl */,
				F966BB3008F27A39005CB29B /* goldberg.tcl */,
				F966BB3108F27A39005CB29B /* hello */,
				F966BB3208F27A39005CB29B /* hscale.tcl */,
				F966BB3308F27A39005CB29B /* icon.tcl */,
				F966BB3408F27A39005CB29B /* image1.tcl */,
				F966BB3508F27A39005CB29B /* image2.tcl */,
				F966BB4208F27A3A005CB29B /* items.tcl */,
				F966BB4308F27A3A005CB29B /* ixset */,
				F92240290D7C620F005EC715 /* knightstour.tcl */,
				F966BB4408F27A3A005CB29B /* label.tcl */,
				F966BB4508F27A3A005CB29B /* labelframe.tcl */,
				F9D1360A0CDC252C00DBE0B5 /* mclist.tcl */,
				F966BB4608F27A3A005CB29B /* menu.tcl */,
				F966BB4708F27A3A005CB29B /* menubu.tcl */,
				F966BB4808F27A3A005CB29B /* msgbox.tcl */,
				F966BB4A08F27A3A005CB29B /* paned1.tcl */,
				F966BB4B08F27A3A005CB29B /* paned2.tcl */,
				F966BB4C08F27A3A005CB29B /* pendulum.tcl */,
				F966BB4D08F27A3A005CB29B /* plot.tcl */,
				F966BB4E08F27A3A005CB29B /* puzzle.tcl */,
				F966BB4F08F27A3A005CB29B /* radio.tcl */,
				F966BB5008F27A3A005CB29B /* README */,
				F966BB5108F27A3A005CB29B /* rmt */,
				F966BB5208F27A3A005CB29B /* rolodex */,
				F966BB5308F27A3A005CB29B /* ruler.tcl */,
				F966BB5408F27A3A005CB29B /* sayings.tcl */,
				F966BB5508F27A3A005CB29B /* search.tcl */,
				F966BB5608F27A3A005CB29B /* spin.tcl */,
				F966BB5708F27A3A005CB29B /* square */,
				F966BB5808F27A3A005CB29B /* states.tcl */,
				F966BB5908F27A3A005CB29B /* style.tcl */,
				F966BB5A08F27A3A005CB29B /* tclIndex */,
				F966BB5B08F27A3A005CB29B /* tcolor */,
				F966BB5C08F27A3A005CB29B /* text.tcl */,
				F9099B8A0CC67D30005A9580 /* textpeer.tcl */,
				F966BB5D08F27A3A005CB29B /* timer */,
				F936FCD90CCD984600716967 /* toolbar.tcl */,
				F936FCD80CCD984600716967 /* tree.tcl */,
				F9099B8B0CC67D3E005A9580 /* ttkbut.tcl */,
				F9F4EFDD0CC7B3CB00378A27 /* ttkmenu.tcl */,
				F936FCDA0CCD984600716967 /* ttknote.tcl */,
				F9F4EFDC0CC7B3CA00378A27 /* ttkpane.tcl */,
				F936FCD70CCD984500716967 /* ttkprogress.tcl */,
				F966BB5E08F27A3A005CB29B /* twind.tcl */,
				F966BB5F08F27A3A005CB29B /* unicodeout.tcl */,
				F966BB6008F27A3A005CB29B /* vscale.tcl */,
				F966BB6108F27A3A005CB29B /* widget */,
			);
			path = demos;
			sourceTree = "<group>";
		};
		F966BB9708F27A3B005CB29B /* macosx */ = {
			isa = PBXGroup;
			children = (
				F966BBBA08F27A3B005CB29B /* configure.ac */,
				F966BBBB08F27A3B005CB29B /* GNUmakefile */,
				F966BBBE08F27A3B005CB29B /* README */,
				F966BBC008F27A3B005CB29B /* Tk-Info.plist.in */,
				F966BBC208F27A3B005CB29B /* tkMacOSX.h */,
				F966BBC508F27A3B005CB29B /* tkMacOSXBitmap.c */,
				F966BBC608F27A3B005CB29B /* tkMacOSXButton.c */,
				F966BBC808F27A3B005CB29B /* tkMacOSXClipboard.c */,
				F966BBC908F27A3B005CB29B /* tkMacOSXColor.c */,
				F966BBCA08F27A3B005CB29B /* tkMacOSXConfig.c */,
				F966BBCB08F27A3B005CB29B /* tkMacOSXCursor.c */,
				F966BBCC08F27A3B005CB29B /* tkMacOSXCursors.h */,
				F966BBCD08F27A3B005CB29B /* tkMacOSXDebug.c */,
				F966BBCE08F27A3B005CB29B /* tkMacOSXDebug.h */,
				F966BBCF08F27A3B005CB29B /* tkMacOSXDefault.h */,
				F966BBD008F27A3B005CB29B /* tkMacOSXDialog.c */,
				F966BBD108F27A3B005CB29B /* tkMacOSXDraw.c */,
				F966BBD208F27A3B005CB29B /* tkMacOSXEmbed.c */,
				F966BBD308F27A3B005CB29B /* tkMacOSXEntry.c */,
				F966BBD408F27A3B005CB29B /* tkMacOSXEvent.c */,
				F966BBD508F27A3B005CB29B /* tkMacOSXEvent.h */,
				F966BBD608F27A3B005CB29B /* tkMacOSXFont.c */,
				F93E5EFD09CF8711008FA367 /* tkMacOSXFont.h */,
				F966BBD708F27A3B005CB29B /* tkMacOSXHLEvents.c */,
				F966BBD808F27A3B005CB29B /* tkMacOSXInit.c */,
				F966BBDA08F27A3B005CB29B /* tkMacOSXInt.h */,
				F966BBDB08F27A3B005CB29B /* tkMacOSXKeyboard.c */,
				F966BBDC08F27A3B005CB29B /* tkMacOSXKeyEvent.c */,
				F966BBDD08F27A3B005CB29B /* tkMacOSXMenu.c */,
				F966BBE008F27A3B005CB29B /* tkMacOSXMenubutton.c */,
				F966BBE108F27A3B005CB29B /* tkMacOSXMenus.c */,
				F966BBE208F27A3B005CB29B /* tkMacOSXMouseEvent.c */,
				F966BBE308F27A3B005CB29B /* tkMacOSXNotify.c */,
				F966BBEA08F27A3C005CB29B /* tkMacOSXPort.h */,
				F976F6A70C325FB6005066D9 /* tkMacOSXPrivate.h */,
				F966BBEB08F27A3C005CB29B /* tkMacOSXRegion.c */,
				F966BBEC08F27A3C005CB29B /* tkMacOSXScale.c */,
				F966BBED08F27A3C005CB29B /* tkMacOSXScrlbr.c */,
				F966BBEE08F27A3C005CB29B /* tkMacOSXSend.c */,
				F966BBEF08F27A3C005CB29B /* tkMacOSXSubwindows.c */,
				F966BBF008F27A3C005CB29B /* tkMacOSXTest.c */,
				F966BBF108F27A3C005CB29B /* tkMacOSXWindowEvent.c */,
				F966BBF208F27A3C005CB29B /* tkMacOSXWm.c */,
				F966BBF308F27A3C005CB29B /* tkMacOSXWm.h */,
				F966BBF408F27A3C005CB29B /* tkMacOSXXCursors.h */,
				F966BBF508F27A3C005CB29B /* tkMacOSXXStubs.c */,
				F96888840AF78938000797B5 /* ttkMacOSXTheme.c */,
				F95D8D4B0F1715610006B020 /* Tk.icns */,
				F95D8D4C0F1715610006B020 /* Tk.tiff */,
				F966BBF708F27A3C005CB29B /* Wish-Info.plist.in */,
				F97590AE1039A96200558A9A /* Wish.sdef */,
				F97AE7F10B65C1E900310EA2 /* Tk-Common.xcconfig */,
				F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */,
				F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */,
			);
			path = macosx;
			sourceTree = "<group>";
		};
		F966BC0408F27A3C005CB29B /* tests */ = {
			isa = PBXGroup;
			children = (
				F966BC0508F27A3C005CB29B /* all.tcl */,
				F966BC0608F27A3C005CB29B /* arc.tcl */,
				F966BC0708F27A3C005CB29B /* bell.test */,
				F966BC0808F27A3C005CB29B /* bevel.tcl */,
				F966BC0908F27A3C005CB29B /* bgerror.test */,
				F966BC0A08F27A3C005CB29B /* bind.test */,
				F966BC0B08F27A3C005CB29B /* bitmap.test */,
				F966BC0C08F27A3C005CB29B /* border.test */,
				F966BC0D08F27A3C005CB29B /* bugs.tcl */,
				F966BC0E08F27A3C005CB29B /* butGeom.tcl */,
				F966BC0F08F27A3C005CB29B /* butGeom2.tcl */,
				F966BC1008F27A3C005CB29B /* button.test */,
				F966BC1108F27A3C005CB29B /* canvas.test */,
				F966BC1208F27A3C005CB29B /* canvImg.test */,
				F966BC1308F27A3C005CB29B /* canvPs.test */,
				F966BC1408F27A3C005CB29B /* canvPsArc.tcl */,
				F966BC1508F27A3C005CB29B /* canvPsBmap.tcl */,
				F966BC1608F27A3C005CB29B /* canvPsGrph.tcl */,
				F966BC1708F27A3C005CB29B /* canvPsImg.tcl */,
				F966BC1808F27A3C005CB29B /* canvPsText.tcl */,
				F966BC1908F27A3C005CB29B /* canvRect.test */,
				F966BC1A08F27A3C005CB29B /* canvText.test */,
				F966BC1B08F27A3C005CB29B /* canvWind.test */,
				F966BC1C08F27A3C005CB29B /* choosedir.test */,
				F966BC1D08F27A3C005CB29B /* clipboard.test */,
				F966BC1E08F27A3C005CB29B /* clrpick.test */,
				F966BC1F08F27A3C005CB29B /* cmap.tcl */,
				F966BC2008F27A3C005CB29B /* cmds.test */,
				F966BC2108F27A3C005CB29B /* color.test */,
				F966BC2208F27A3C005CB29B /* config.test */,
				F966BC2308F27A3C005CB29B /* constraints.tcl */,
				F966BC2408F27A3C005CB29B /* cursor.test */,
				F966BC2508F27A3C005CB29B /* dialog.test */,
				F966BC2608F27A3C005CB29B /* embed.test */,
				F966BC2708F27A3C005CB29B /* entry.test */,
				F966BC2808F27A3C005CB29B /* event.test */,
				F966BC2908F27A3C005CB29B /* filebox.test */,
				F966BC2A08F27A3C005CB29B /* focus.test */,
				F966BC2B08F27A3C005CB29B /* focusTcl.test */,
				F966BC2C08F27A3C005CB29B /* font.test */,
				F99388950EE02D980065FE6B /* fontchooser.test */,
				F966BC2D08F27A3C005CB29B /* frame.test */,
				F966BC2E08F27A3C005CB29B /* geometry.test */,
				F966BC2F08F27A3C005CB29B /* get.test */,
				F966BC3008F27A3C005CB29B /* grab.test */,
				F966BC3108F27A3C005CB29B /* grid.test */,
				F966BC3308F27A3C005CB29B /* image.test */,
				F966BC3408F27A3C005CB29B /* imgBmap.test */,
				F966BC3508F27A3C005CB29B /* imgPhoto.test */,
				F9DD99BF0F07DFCD0018B2E4 /* imgPNG.test */,
				F966BC3608F27A3C005CB29B /* imgPPM.test */,
				F966BC3708F27A3C005CB29B /* listbox.test */,
				F966BC3808F27A3C005CB29B /* main.test */,
				F966BC3908F27A3C005CB29B /* menu.test */,
				F966BC3A08F27A3C005CB29B /* menubut.test */,
				F966BC3B08F27A3C005CB29B /* menuDraw.test */,
				F966BC3C08F27A3C005CB29B /* message.test */,
				F966BC3D08F27A3C005CB29B /* msgbox.test */,
				F966BC3E08F27A3C005CB29B /* obj.test */,
				F966BC3F08F27A3C005CB29B /* oldpack.test */,
				F966BC4008F27A3C005CB29B /* option.file1 */,
				F966BC4108F27A3C005CB29B /* option.file2 */,
				F966BC4208F27A3C005CB29B /* option.test */,
				F966BC4308F27A3C005CB29B /* pack.test */,
				F966BC4408F27A3C005CB29B /* panedwindow.test */,
				F966BC4508F27A3D005CB29B /* place.test */,
				F966BC4608F27A3D005CB29B /* raise.test */,
				F966BC4708F27A3D005CB29B /* README */,
				F966BC4808F27A3D005CB29B /* safe.test */,
				F966BC4908F27A3D005CB29B /* scale.test */,
				F966BC4A08F27A3D005CB29B /* scrollbar.test */,
				F966BC4B08F27A3D005CB29B /* select.test */,
				F966BC4C08F27A3D005CB29B /* send.test */,
				F966BC4D08F27A3D005CB29B /* spinbox.test */,
				F966BC4E08F27A3D005CB29B /* text.test */,
				F966BC4F08F27A3D005CB29B /* textBTree.test */,
				F966BC5008F27A3D005CB29B /* textDisp.test */,
				F966BC5108F27A3D005CB29B /* textImage.test */,
				F966BC5208F27A3D005CB29B /* textIndex.test */,
				F966BC5308F27A3D005CB29B /* textMark.test */,
				F966BC5408F27A3D005CB29B /* textTag.test */,
				F966BC5508F27A3D005CB29B /* textWind.test */,
				F966BC5608F27A3D005CB29B /* tk.test */,
				F96888530AF7880C000797B5 /* ttk */,
				F966BC5708F27A3D005CB29B /* unixButton.test */,
				F966BC5808F27A3D005CB29B /* unixEmbed.test */,
				F966BC5908F27A3D005CB29B /* unixFont.test */,
				F966BC5A08F27A3D005CB29B /* unixMenu.test */,
				F966BC5B08F27A3D005CB29B /* unixSelect.test */,
				F966BC5C08F27A3D005CB29B /* unixWm.test */,
				F966BC5D08F27A3D005CB29B /* util.test */,
				F966BC5E08F27A3D005CB29B /* visual.test */,
				F966BC5F08F27A3D005CB29B /* visual_bb.test */,
				F966BC6008F27A3D005CB29B /* winButton.test */,
				F966BC6108F27A3D005CB29B /* winClipboard.test */,
				F966BC6208F27A3D005CB29B /* winDialog.test */,
				F966BC6308F27A3D005CB29B /* window.test */,
				F966BC6408F27A3D005CB29B /* winfo.test */,
				F966BC6508F27A3D005CB29B /* winFont.test */,
				F966BC6608F27A3D005CB29B /* winMenu.test */,
				F966BC6708F27A3D005CB29B /* winSend.test */,
				F966BC6808F27A3D005CB29B /* winWm.test */,
				F966BC6908F27A3D005CB29B /* wm.test */,
				F966BC6A08F27A3D005CB29B /* xmfbox.test */,
			);
			path = tests;
			sourceTree = "<group>";
		};
		F966BC6B08F27A3D005CB29B /* unix */ = {
			isa = PBXGroup;
			children = (
				F966BC6C08F27A3D005CB29B /* aclocal.m4 */,
				F966BC6D08F27A3D005CB29B /* configure */,
				F966BC6E08F27A3D005CB29B /* configure.ac */,
				F966BC6F08F27A3D005CB29B /* install-sh */,
				F966BC7008F27A3D005CB29B /* installManPage */,
				F966BC7108F27A3D005CB29B /* Makefile.in */,
				F966BC7208F27A3D005CB29B /* README */,
				F966BC7308F27A3D005CB29B /* tcl.m4 */,
				F974D57B0FBE7EC000BF728B /* tk.pc.in */,
				F966BC7408F27A3D005CB29B /* tk.spec */,
				F966BC7508F27A3D005CB29B /* tkAppInit.c */,
				F966BC7608F27A3D005CB29B /* tkConfig.h.in */,
				F966BC7708F27A3D005CB29B /* tkConfig.sh.in */,
				F966BC7808F27A3D005CB29B /* tkUnix.c */,
				F966BC7908F27A3D005CB29B /* tkUnix3d.c */,
				F966BC7A08F27A3D005CB29B /* tkUnixButton.c */,
				F966BC7B08F27A3D005CB29B /* tkUnixColor.c */,
				F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */,
				F966BC7D08F27A3D005CB29B /* tkUnixCursor.c */,
				F966BC7E08F27A3D005CB29B /* tkUnixDefault.h */,
				F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */,
				F966BC8008F27A3D005CB29B /* tkUnixDraw.c */,
				F966BC8108F27A3D005CB29B /* tkUnixEmbed.c */,
				F966BC8208F27A3D005CB29B /* tkUnixEvent.c */,
				F966BC8308F27A3D005CB29B /* tkUnixFocus.c */,
				F966BC8408F27A3D005CB29B /* tkUnixFont.c */,
				F966BC8508F27A3D005CB29B /* tkUnixInit.c */,
				F966BC8608F27A3D005CB29B /* tkUnixInt.h */,
				F966BC8708F27A3D005CB29B /* tkUnixKey.c */,
				F966BC8808F27A3D005CB29B /* tkUnixMenu.c */,
				F966BC8908F27A3D005CB29B /* tkUnixMenubu.c */,
				F966BC8A08F27A3D005CB29B /* tkUnixPort.h */,
				F966BC8B08F27A3D005CB29B /* tkUnixRFont.c */,
				F966BC8C08F27A3D005CB29B /* tkUnixScale.c */,
				F966BC8D08F27A3D005CB29B /* tkUnixScrlbr.c */,
				F966BC8E08F27A3D005CB29B /* tkUnixSelect.c */,
				F966BC8F08F27A3D005CB29B /* tkUnixSend.c */,
				F966BC9008F27A3D005CB29B /* tkUnixWm.c */,
				F966BC9108F27A3D005CB29B /* tkUnixXId.c */,
			);
			path = unix;
			sourceTree = "<group>";
		};
		F966BC9208F27A3D005CB29B /* win */ = {
			isa = PBXGroup;
			children = (
				F966BC9408F27A3D005CB29B /* aclocal.m4 */,
				F966BC9508F27A3D005CB29B /* buildall.vc.bat */,
				F966BC9608F27A3E005CB29B /* configure */,
				F966BC9708F27A3E005CB29B /* configure.ac */,
				F966BC9908F27A3E005CB29B /* Makefile.in */,
				F966BC9A08F27A3E005CB29B /* makefile.vc */,
				F966BC9C08F27A3E005CB29B /* nmakehlp.c */,
				F966BC9D08F27A3E005CB29B /* rc */,
				F966BCF308F27A3E005CB29B /* README */,
				F966BCF408F27A3E005CB29B /* rmd.bat */,
				F966BCF508F27A3F005CB29B /* rules.vc */,
				F966BCF608F27A3F005CB29B /* stubs.c */,
				F966BCF708F27A3F005CB29B /* tcl.m4 */,
				F966BCF808F27A3F005CB29B /* tkConfig.sh.in */,
				F966BCF908F27A3F005CB29B /* tkWin.h */,
				F966BCFA08F27A3F005CB29B /* tkWin32Dll.c */,
				F966BCFB08F27A3F005CB29B /* tkWin3d.c */,
				F966BCFC08F27A3F005CB29B /* tkWinButton.c */,
				F966BCFD08F27A3F005CB29B /* tkWinClipboard.c */,
				F966BCFE08F27A3F005CB29B /* tkWinColor.c */,
				F966BCFF08F27A3F005CB29B /* tkWinConfig.c */,
				F966BD0008F27A3F005CB29B /* tkWinCursor.c */,
				F966BD0108F27A3F005CB29B /* tkWinDefault.h */,
				F966BD0208F27A3F005CB29B /* tkWinDialog.c */,
				F966BD0308F27A3F005CB29B /* tkWinDraw.c */,
				F966BD0408F27A3F005CB29B /* tkWinEmbed.c */,
				F966BD0508F27A3F005CB29B /* tkWinFont.c */,
				F966BD0708F27A3F005CB29B /* tkWinImage.c */,
				F966BD0808F27A3F005CB29B /* tkWinInit.c */,
				F966BD0908F27A3F005CB29B /* tkWinInt.h */,
				F966BD0A08F27A3F005CB29B /* tkWinKey.c */,
				F966BD0B08F27A3F005CB29B /* tkWinMenu.c */,
				F966BD0C08F27A3F005CB29B /* tkWinPixmap.c */,
				F966BD0D08F27A3F005CB29B /* tkWinPointer.c */,
				F966BD0E08F27A3F005CB29B /* tkWinPort.h */,
				F966BD0F08F27A3F005CB29B /* tkWinRegion.c */,
				F966BD1008F27A3F005CB29B /* tkWinScrlbr.c */,
				F966BD1108F27A3F005CB29B /* tkWinSend.c */,
				F966BD1208F27A3F005CB29B /* tkWinSendCom.c */,
				F966BD1308F27A3F005CB29B /* tkWinSendCom.h */,
				F966BD1408F27A3F005CB29B /* tkWinTest.c */,
				F966BD1508F27A3F005CB29B /* tkWinWindow.c */,
				F966BD1608F27A3F005CB29B /* tkWinWm.c */,
				F966BD1708F27A3F005CB29B /* tkWinX.c */,
				F96888860AF78953000797B5 /* ttkWinMonitor.c */,
				F96888870AF78953000797B5 /* ttkWinTheme.c */,
				F96888880AF78953000797B5 /* ttkWinXPTheme.c */,
				F966BD1808F27A3F005CB29B /* winMain.c */,
			);
			path = win;
			sourceTree = "<group>";
		};
		F966BC9D08F27A3E005CB29B /* rc */ = {
			isa = PBXGroup;
			children = (
				F966BCEE08F27A3E005CB29B /* tk.rc */,
				F966BCEF08F27A3E005CB29B /* tk_base.rc */,
				F966BCF208F27A3E005CB29B /* wish.rc */,
			);
			path = rc;
			sourceTree = "<group>";
		};
		F966BD1908F27A3F005CB29B /* xlib */ = {
			isa = PBXGroup;
			children = (
				F966BD1A08F27A3F005CB29B /* X11 */,
				F966BD2308F27A3F005CB29B /* xbytes.h */,
				F966BD2408F27A3F005CB29B /* xcolors.c */,
				F966BD2508F27A3F005CB29B /* xdraw.c */,
				F966BD2608F27A3F005CB29B /* xgc.c */,
				F966BD2708F27A3F005CB29B /* ximage.c */,
				F966BD2808F27A3F005CB29B /* xutil.c */,
			);
			path = xlib;
			sourceTree = "<group>";
		};
		F966BD1A08F27A3F005CB29B /* X11 */ = {
			isa = PBXGroup;
			children = (
				F966BD1B08F27A3F005CB29B /* cursorfont.h */,
				F966BD1C08F27A3F005CB29B /* keysym.h */,
				F966BD1D08F27A3F005CB29B /* keysymdef.h */,
				F966BD1E08F27A3F005CB29B /* X.h */,
				F966BD1F08F27A3F005CB29B /* Xatom.h */,
				F966BD2008F27A3F005CB29B /* Xfuncproto.h */,
				F966BD2108F27A3F005CB29B /* Xlib.h */,
				F966BD2208F27A3F005CB29B /* Xutil.h */,
			);
			path = X11;
			sourceTree = "<group>";
		};
		F966C06F08F281DC005CB29B /* Frameworks */ = {
			isa = PBXGroup;
			children = (
				F9C9CBFF0E84059800E00935 /* ApplicationServices.framework */,
				F966C07408F2820D005CB29B /* CoreFoundation.framework */,
				F96437E60EF0D652003F468E /* libz.dylib */,
				F966C07608F2821B005CB29B /* Carbon.framework */,
				F94523A10E6FC2AC00C1D987 /* Cocoa.framework */,
				F966C07808F28233005CB29B /* IOKit.framework */,
				F9FD32140CC1AF170073837D /* libX11.dylib */,
				F9FD32150CC1AF170073837D /* libXext.dylib */,
				F9FD32160CC1AF170073837D /* libXss.dylib */,
				F9FD349A0CC1BB0D0073837D /* libXft.dylib */,
				F9FD34990CC1BB0D0073837D /* libfreetype.dylib */,
				F9FD34C30CC1BBD70073837D /* libfontconfig.dylib */,
			);
			name = Frameworks;
			sourceTree = "<group>";
		};
		F96887DF0AF786D5000797B5 /* ttk */ = {
			isa = PBXGroup;
			children = (
				F96887E00AF786D5000797B5 /* ttk.decls */,
				F96887E10AF786D5000797B5 /* ttkBlink.c */,
				F96887E20AF786D5000797B5 /* ttkButton.c */,
				F96887E30AF786D5000797B5 /* ttkCache.c */,
				F96887E40AF786D5000797B5 /* ttkClamTheme.c */,
				F96887E50AF786D5000797B5 /* ttkClassicTheme.c */,
				F96887E60AF786D5000797B5 /* ttkDecls.h */,
				F96887E70AF786D5000797B5 /* ttkDefaultTheme.c */,
				F96887E80AF786D5000797B5 /* ttkElements.c */,
				F96887E90AF786D5000797B5 /* ttkEntry.c */,
				F96887EA0AF786D5000797B5 /* ttkFrame.c */,
				F96887EB0AF786D5000797B5 /* ttkImage.c */,
				F96887EC0AF786D5000797B5 /* ttkInit.c */,
				F96887ED0AF786D5000797B5 /* ttkLabel.c */,
				F96887EE0AF786D5000797B5 /* ttkLayout.c */,
				F96887EF0AF786D5000797B5 /* ttkManager.c */,
				F96887F00AF786D5000797B5 /* ttkManager.h */,
				F96887F10AF786D5000797B5 /* ttkNotebook.c */,
				F96887F20AF786D5000797B5 /* ttkPanedwindow.c */,
				F96887F30AF786D5000797B5 /* ttkProgress.c */,
				F96887F40AF786D5000797B5 /* ttkScale.c */,
				F96887F50AF786D5000797B5 /* ttkScroll.c */,
				F96887F60AF786D5000797B5 /* ttkScrollbar.c */,
				F96887F70AF786D5000797B5 /* ttkSeparator.c */,
				F96887F80AF786D5000797B5 /* ttkSquare.c */,
				F96887F90AF786D5000797B5 /* ttkState.c */,
				F96887FA0AF786D5000797B5 /* ttkStubInit.c */,
				F96887FB0AF786D5000797B5 /* ttkStubLib.c */,
				F96887FC0AF786D5000797B5 /* ttkTagSet.c */,
				F96887FD0AF786D5000797B5 /* ttkTheme.c */,
				F96887FE0AF786D5000797B5 /* ttkTheme.h */,
				F96887FF0AF786D5000797B5 /* ttkThemeInt.h */,
				F96888000AF786D5000797B5 /* ttkTrace.c */,
				F96888010AF786D5000797B5 /* ttkTrack.c */,
				F96888020AF786D5000797B5 /* ttkTreeview.c */,
				F96888030AF786D5000797B5 /* ttkWidget.c */,
				F96888040AF786D5000797B5 /* ttkWidget.h */,
			);
			path = ttk;
			sourceTree = "<group>";
		};
		F96888360AF787B3000797B5 /* ttk */ = {
			isa = PBXGroup;
			children = (
				F96888370AF787B3000797B5 /* altTheme.tcl */,
				F96888380AF787B3000797B5 /* aquaTheme.tcl */,
				F96888390AF787B3000797B5 /* button.tcl */,
				F968883A0AF787B3000797B5 /* clamTheme.tcl */,
				F968883B0AF787B3000797B5 /* classicTheme.tcl */,
				F968883C0AF787B3000797B5 /* combobox.tcl */,
				F968883D0AF787B3000797B5 /* cursors.tcl */,
				F968883E0AF787B3000797B5 /* defaults.tcl */,
				F96888400AF787B3000797B5 /* entry.tcl */,
				F96888410AF787B3000797B5 /* fonts.tcl */,
				F96888440AF787B3000797B5 /* menubutton.tcl */,
				F96888450AF787B3000797B5 /* notebook.tcl */,
				F96888460AF787B3000797B5 /* panedwindow.tcl */,
				F96888470AF787B3000797B5 /* progress.tcl */,
				F96888480AF787B3000797B5 /* scale.tcl */,
				F96888490AF787B3000797B5 /* scrollbar.tcl */,
				F968884A0AF787B3000797B5 /* sizegrip.tcl */,
				F968884B0AF787B3000797B5 /* treeview.tcl */,
				F968884C0AF787B3000797B5 /* ttk.tcl */,
				F968884D0AF787B3000797B5 /* utils.tcl */,
				F968884E0AF787B3000797B5 /* winTheme.tcl */,
				F973E5960EE99384001A648E /* vistaTheme.tcl */,
				F968884F0AF787B3000797B5 /* xpTheme.tcl */,
			);
			path = ttk;
			sourceTree = "<group>";
		};
		F96888530AF7880C000797B5 /* ttk */ = {
			isa = PBXGroup;
			children = (
				F96888540AF7880C000797B5 /* all.tcl */,
				F98383650F0FA43900171CA6 /* checkbutton.test */,
				F96888560AF7880C000797B5 /* combobox.test */,
				F96888570AF7880C000797B5 /* entry.test */,
				F96888580AF7880C000797B5 /* image.test */,
				F96888590AF7880C000797B5 /* labelframe.test */,
				F968885A0AF7880C000797B5 /* layout.test */,
				F968885C0AF7880C000797B5 /* notebook.test */,
				F968885D0AF7880C000797B5 /* panedwindow.test */,
				F968885E0AF7880C000797B5 /* progressbar.test */,
				F98383680F0FA44700171CA6 /* radiobutton.test */,
				F968885F0AF7880C000797B5 /* scrollbar.test */,
				F96888600AF7880C000797B5 /* treetags.test */,
				F96888610AF7880C000797B5 /* treeview.test */,
				F96888620AF7880C000797B5 /* ttk.test */,
				F96888630AF7880C000797B5 /* validate.test */,
				F962F7C60DADC26200648DB8 /* vsapi.test */,
			);
			path = ttk;
			sourceTree = "<group>";
		};
		F96D3DF608F27169004A47F5 /* Tcl Sources */ = {
			isa = PBXGroup;
			children = (
				F96D3EC908F272A7004A47F5 /* generic */,
				F96D432C08F272B4004A47F5 /* macosx */,
				F96D443E08F272B9004A47F5 /* unix */,
				F96D425C08F272B2004A47F5 /* libtommath */,
				F96D446E08F272B9004A47F5 /* win */,
				F96D3F3808F272A7004A47F5 /* library */,
				F96D434408F272B5004A47F5 /* tests */,
				F96D3DFC08F272A4004A47F5 /* doc */,
				F96D43D008F272B8004A47F5 /* tools */,
				F9183E690EFC81560030B814 /* pkgs */,
				F96D3DFA08F272A4004A47F5 /* ChangeLog */,
				F96D3DFB08F272A4004A47F5 /* changes */,
				F96D434308F272B5004A47F5 /* README */,
				F96D432B08F272B4004A47F5 /* license.terms */,
			);
			name = "Tcl Sources";
			sourceTree = TCL_SRCROOT;
		};
		F96D3DF708F271BE004A47F5 /* Tk Sources */ = {
			isa = PBXGroup;
			children = (
				F966BAA508F27A38005CB29B /* generic */,
				F966BB9708F27A3B005CB29B /* macosx */,
				F966BC6B08F27A3D005CB29B /* unix */,
				F966BD1908F27A3F005CB29B /* xlib */,
				F966BA0308F27A37005CB29B /* bitmaps */,
				F966BC9208F27A3D005CB29B /* win */,
				F966BB1308F27A39005CB29B /* library */,
				F966BC0408F27A3C005CB29B /* tests */,
				F966BA1008F27A37005CB29B /* doc */,
				F966BA0E08F27A37005CB29B /* ChangeLog */,
				F966BA0F08F27A37005CB29B /* changes */,
				F966BC0308F27A3C005CB29B /* README */,
				F966BB9608F27A3B005CB29B /* license.terms */,
			);
			name = "Tk Sources";
			sourceTree = TK_SRCROOT;
		};
		F96D3DFC08F272A4004A47F5 /* doc */ = {
			isa = PBXGroup;
			children = (
				F96D3DFD08F272A4004A47F5 /* Access.3 */,
				F96D3DFE08F272A4004A47F5 /* AddErrInfo.3 */,
				F96D3DFF08F272A4004A47F5 /* after.n */,
				F96D3E0008F272A4004A47F5 /* Alloc.3 */,
				F96D3E0108F272A4004A47F5 /* AllowExc.3 */,
				F96D3E0208F272A4004A47F5 /* append.n */,
				F96D3E0308F272A4004A47F5 /* AppInit.3 */,
				F96D3E0408F272A5004A47F5 /* array.n */,
				F96D3E0508F272A5004A47F5 /* AssocData.3 */,
				F96D3E0608F272A5004A47F5 /* Async.3 */,
				F96D3E0708F272A5004A47F5 /* BackgdErr.3 */,
				F96D3E0808F272A5004A47F5 /* Backslash.3 */,
				F96D3E0908F272A5004A47F5 /* bgerror.n */,
				F96D3E0A08F272A5004A47F5 /* binary.n */,
				F96D3E0B08F272A5004A47F5 /* BoolObj.3 */,
				F96D3E0C08F272A5004A47F5 /* break.n */,
				F96D3E0D08F272A5004A47F5 /* ByteArrObj.3 */,
				F96D3E0E08F272A5004A47F5 /* CallDel.3 */,
				F96D3E0F08F272A5004A47F5 /* case.n */,
				F96D3E1008F272A5004A47F5 /* catch.n */,
				F96D3E1108F272A5004A47F5 /* cd.n */,
				F96D3E1208F272A5004A47F5 /* chan.n */,
				F96D3E1308F272A5004A47F5 /* ChnlStack.3 */,
				F93599CF0DF1F87F00E04F67 /* Class.3 */,
				F93599D00DF1F89E00E04F67 /* class.n */,
				F96D3E1408F272A5004A47F5 /* clock.n */,
				F96D3E1508F272A5004A47F5 /* close.n */,
				F96D3E1608F272A5004A47F5 /* CmdCmplt.3 */,
				F96D3E1708F272A5004A47F5 /* Concat.3 */,
				F96D3E1808F272A5004A47F5 /* concat.n */,
				F96D3E1908F272A5004A47F5 /* continue.n */,
				F93599D20DF1F8DF00E04F67 /* copy.n */,
				F974D5720FBE7DC600BF728B /* coroutine.n */,
				F96D3E1A08F272A5004A47F5 /* CrtChannel.3 */,
				F96D3E1B08F272A5004A47F5 /* CrtChnlHdlr.3 */,
				F96D3E1C08F272A5004A47F5 /* CrtCloseHdlr.3 */,
				F96D3E1D08F272A5004A47F5 /* CrtCommand.3 */,
				F96D3E1E08F272A5004A47F5 /* CrtFileHdlr.3 */,
				F96D3E1F08F272A5004A47F5 /* CrtInterp.3 */,
				F96D3E2008F272A5004A47F5 /* CrtMathFnc.3 */,
				F96D3E2108F272A5004A47F5 /* CrtObjCmd.3 */,
				F96D3E2208F272A5004A47F5 /* CrtSlave.3 */,
				F96D3E2308F272A5004A47F5 /* CrtTimerHdlr.3 */,
				F96D3E2408F272A5004A47F5 /* CrtTrace.3 */,
				F96D3E2508F272A5004A47F5 /* dde.n */,
				F93599D30DF1F8F500E04F67 /* define.n */,
				F96D3E2608F272A5004A47F5 /* DetachPids.3 */,
				F96D3E2708F272A5004A47F5 /* dict.n */,
				F96D3E2808F272A5004A47F5 /* DictObj.3 */,
				F96D3E2908F272A5004A47F5 /* DoOneEvent.3 */,
				F96D3E2A08F272A5004A47F5 /* DoubleObj.3 */,
				F96D3E2B08F272A5004A47F5 /* DoWhenIdle.3 */,
				F96D3E2C08F272A5004A47F5 /* DString.3 */,
				F96D3E2D08F272A5004A47F5 /* DumpActiveMemory.3 */,
				F96D3E2E08F272A5004A47F5 /* Encoding.3 */,
				F96D3E2F08F272A5004A47F5 /* encoding.n */,
				F96D3E3008F272A5004A47F5 /* Ensemble.3 */,
				F96D3E3108F272A5004A47F5 /* Environment.3 */,
				F96D3E3208F272A5004A47F5 /* eof.n */,
				F96D3E3308F272A5004A47F5 /* error.n */,
				F96D3E3408F272A5004A47F5 /* Eval.3 */,
				F96D3E3508F272A5004A47F5 /* eval.n */,
				F96D3E3608F272A5004A47F5 /* exec.n */,
				F96D3E3708F272A5004A47F5 /* Exit.3 */,
				F96D3E3808F272A5004A47F5 /* exit.n */,
				F96D3E3908F272A5004A47F5 /* expr.n */,
				F96D3E3A08F272A5004A47F5 /* ExprLong.3 */,
				F96D3E3B08F272A5004A47F5 /* ExprLongObj.3 */,
				F96D3E3C08F272A5004A47F5 /* fblocked.n */,
				F96D3E3D08F272A5004A47F5 /* fconfigure.n */,
				F96D3E3E08F272A5004A47F5 /* fcopy.n */,
				F96D3E3F08F272A5004A47F5 /* file.n */,
				F96D3E4008F272A5004A47F5 /* fileevent.n */,
				F96D3E4108F272A5004A47F5 /* filename.n */,
				F96D3E4208F272A5004A47F5 /* FileSystem.3 */,
				F96D3E4308F272A5004A47F5 /* FindExec.3 */,
				F96D3E4408F272A5004A47F5 /* flush.n */,
				F96D3E4508F272A5004A47F5 /* for.n */,
				F96D3E4608F272A5004A47F5 /* foreach.n */,
				F96D3E4708F272A5004A47F5 /* format.n */,
				F96D3E4808F272A5004A47F5 /* GetCwd.3 */,
				F96D3E4908F272A5004A47F5 /* GetHostName.3 */,
				F96D3E4A08F272A5004A47F5 /* GetIndex.3 */,
				F96D3E4B08F272A5004A47F5 /* GetInt.3 */,
				F96D3E4C08F272A5004A47F5 /* GetOpnFl.3 */,
				F96D3E4D08F272A5004A47F5 /* gets.n */,
				F96D3E4E08F272A5004A47F5 /* GetStdChan.3 */,
				F96D3E4F08F272A5004A47F5 /* GetTime.3 */,
				F96D3E5008F272A5004A47F5 /* GetVersion.3 */,
				F96D3E5108F272A5004A47F5 /* glob.n */,
				F96D3E5208F272A6004A47F5 /* global.n */,
				F96D3E5308F272A6004A47F5 /* Hash.3 */,
				F96D3E5408F272A6004A47F5 /* history.n */,
				F96D3E5508F272A6004A47F5 /* http.n */,
				F96D3E5608F272A6004A47F5 /* if.n */,
				F96D3E5708F272A6004A47F5 /* incr.n */,
				F96D3E5808F272A6004A47F5 /* info.n */,
				F96D3E5908F272A6004A47F5 /* Init.3 */,
				F96D3E5A08F272A6004A47F5 /* InitStubs.3 */,
				F96D3E5B08F272A6004A47F5 /* Interp.3 */,
				F96D3E5C08F272A6004A47F5 /* interp.n */,
				F96D3E5D08F272A6004A47F5 /* IntObj.3 */,
				F96D3E5E08F272A6004A47F5 /* join.n */,
				F96D3E5F08F272A6004A47F5 /* lappend.n */,
				F96D3E6008F272A6004A47F5 /* lassign.n */,
				F96D3E6108F272A6004A47F5 /* library.n */,
				F96D3E6208F272A6004A47F5 /* Limit.3 */,
				F96D3E6308F272A6004A47F5 /* lindex.n */,
				F96D3E6408F272A6004A47F5 /* LinkVar.3 */,
				F96D3E6508F272A6004A47F5 /* linsert.n */,
				F96D3E6608F272A6004A47F5 /* list.n */,
				F96D3E6708F272A6004A47F5 /* ListObj.3 */,
				F96D3E6808F272A6004A47F5 /* llength.n */,
				F96D3E6908F272A6004A47F5 /* load.n */,
				F96D3E6A08F272A6004A47F5 /* lrange.n */,
				F96D3E6B08F272A6004A47F5 /* lrepeat.n */,
				F96D3E6C08F272A6004A47F5 /* lreplace.n */,
				F96D3E6D08F272A6004A47F5 /* lsearch.n */,
				F96D3E6E08F272A6004A47F5 /* lset.n */,
				F96D3E6F08F272A6004A47F5 /* lsort.n */,
				F96D3E7008F272A6004A47F5 /* man.macros */,
				F96D3E7108F272A6004A47F5 /* mathfunc.n */,
				F96D3E7208F272A6004A47F5 /* memory.n */,
				F93599D40DF1F91900E04F67 /* Method.3 */,
				F96D3E7308F272A6004A47F5 /* msgcat.n */,
				F93599D50DF1F93700E04F67 /* my.n */,
				F96D3E7408F272A6004A47F5 /* Namespace.3 */,
				F96D3E7508F272A6004A47F5 /* namespace.n */,
				F93599D60DF1F95000E04F67 /* next.n */,
				F96D3E7608F272A6004A47F5 /* Notifier.3 */,
				F96D3E7708F272A6004A47F5 /* Object.3 */,
				F93599D70DF1F96800E04F67 /* object.n */,
				F96D3E7808F272A6004A47F5 /* ObjectType.3 */,
				F96D3E7908F272A6004A47F5 /* open.n */,
				F96D3E7A08F272A6004A47F5 /* OpenFileChnl.3 */,
				F96D3E7B08F272A6004A47F5 /* OpenTcp.3 */,
				F96D3E7C08F272A6004A47F5 /* package.n */,
				F96D3E7D08F272A6004A47F5 /* packagens.n */,
				F96D3E7E08F272A6004A47F5 /* Panic.3 */,
				F96D3E7F08F272A6004A47F5 /* ParseCmd.3 */,
				F96D3E8008F272A6004A47F5 /* pid.n */,
				F96D3E8108F272A6004A47F5 /* pkgMkIndex.n */,
				F96D3E8208F272A6004A47F5 /* PkgRequire.3 */,
				F9ECB1E10B26543C00A28025 /* platform_shell.n */,
				F9ECB1E20B26543C00A28025 /* platform.n */,
				F96D3E8308F272A6004A47F5 /* Preserve.3 */,
				F96D3E8408F272A6004A47F5 /* PrintDbl.3 */,
				F96D3E8508F272A6004A47F5 /* proc.n */,
				F96D3E8608F272A6004A47F5 /* puts.n */,
				F96D3E8708F272A6004A47F5 /* pwd.n */,
				F96D3E8808F272A6004A47F5 /* re_syntax.n */,
				F96D3E8908F272A6004A47F5 /* read.n */,
				F96D3E8A08F272A6004A47F5 /* RecEvalObj.3 */,
				F96D3E8B08F272A6004A47F5 /* RecordEval.3 */,
				F96D3E8C08F272A6004A47F5 /* RegConfig.3 */,
				F96D3E8D08F272A6004A47F5 /* RegExp.3 */,
				F96D3E8E08F272A6004A47F5 /* regexp.n */,
				F96D3E8F08F272A6004A47F5 /* registry.n */,
				F96D3E9008F272A6004A47F5 /* regsub.n */,
				F96D3E9108F272A6004A47F5 /* rename.n */,
				F96D3E9208F272A6004A47F5 /* return.n */,
				F96D3E9308F272A6004A47F5 /* safe.n */,
				F96D3E9408F272A6004A47F5 /* SaveResult.3 */,
				F96D3E9508F272A6004A47F5 /* scan.n */,
				F96D3E9608F272A6004A47F5 /* seek.n */,
				F93599D80DF1F98300E04F67 /* self.n */,
				F96D3E9708F272A6004A47F5 /* set.n */,
				F96D3E9808F272A6004A47F5 /* SetChanErr.3 */,
				F96D3E9908F272A6004A47F5 /* SetErrno.3 */,
				F96D3E9A08F272A6004A47F5 /* SetRecLmt.3 */,
				F96D3E9B08F272A7004A47F5 /* SetResult.3 */,
				F96D3E9C08F272A7004A47F5 /* SetVar.3 */,
				F96D3E9D08F272A7004A47F5 /* Signal.3 */,
				F96D3E9E08F272A7004A47F5 /* Sleep.3 */,
				F96D3E9F08F272A7004A47F5 /* socket.n */,
				F96D3EA008F272A7004A47F5 /* source.n */,
				F96D3EA108F272A7004A47F5 /* SourceRCFile.3 */,
				F96D3EA208F272A7004A47F5 /* split.n */,
				F96D3EA308F272A7004A47F5 /* SplitList.3 */,
				F96D3EA408F272A7004A47F5 /* SplitPath.3 */,
				F96D3EA508F272A7004A47F5 /* StaticPkg.3 */,
				F96D3EA608F272A7004A47F5 /* StdChannels.3 */,
				F96D3EA708F272A7004A47F5 /* string.n */,
				F96D3EA808F272A7004A47F5 /* StringObj.3 */,
				F96D3EA908F272A7004A47F5 /* StrMatch.3 */,
				F96D3EAA08F272A7004A47F5 /* subst.n */,
				F96D3EAB08F272A7004A47F5 /* SubstObj.3 */,
				F96D3EAC08F272A7004A47F5 /* switch.n */,
				F974D5760FBE7E1900BF728B /* tailcall.n */,
				F96D3EAD08F272A7004A47F5 /* Tcl.n */,
				F99D61180EF5573A00BBFE01 /* TclZlib.3 */,
				F96D3EAE08F272A7004A47F5 /* Tcl_Main.3 */,
				F96D3EAF08F272A7004A47F5 /* TCL_MEM_DEBUG.3 */,
				F96D3EB008F272A7004A47F5 /* tclsh.1 */,
				F96D3EB108F272A7004A47F5 /* tcltest.n */,
				F96D3EB208F272A7004A47F5 /* tclvars.n */,
				F96D3EB308F272A7004A47F5 /* tell.n */,
				F96D3EB408F272A7004A47F5 /* Thread.3 */,
				F9183E640EFC80CD0030B814 /* throw.n */,
				F96D3EB508F272A7004A47F5 /* time.n */,
				F96D3EB608F272A7004A47F5 /* tm.n */,
				F96D3EB708F272A7004A47F5 /* ToUpper.3 */,
				F96D3EB808F272A7004A47F5 /* trace.n */,
				F96D3EB908F272A7004A47F5 /* TraceCmd.3 */,
				F96D3EBA08F272A7004A47F5 /* TraceVar.3 */,
				F96D3EBB08F272A7004A47F5 /* Translate.3 */,
				F9183E650EFC80D70030B814 /* try.n */,
				F96D3EBC08F272A7004A47F5 /* UniCharIsAlpha.3 */,
				F96D3EBD08F272A7004A47F5 /* unknown.n */,
				F96D3EBE08F272A7004A47F5 /* unload.n */,
				F96D3EBF08F272A7004A47F5 /* unset.n */,
				F96D3EC008F272A7004A47F5 /* update.n */,
				F96D3EC108F272A7004A47F5 /* uplevel.n */,
				F96D3EC208F272A7004A47F5 /* UpVar.3 */,
				F96D3EC308F272A7004A47F5 /* upvar.n */,
				F96D3EC408F272A7004A47F5 /* Utf.3 */,
				F96D3EC508F272A7004A47F5 /* variable.n */,
				F96D3EC608F272A7004A47F5 /* vwait.n */,
				F96D3EC708F272A7004A47F5 /* while.n */,
				F96D3EC808F272A7004A47F5 /* WrongNumArgs.3 */,
				F915432D0EF201EE0032D1E8 /* zlib.n */,
			);
			path = doc;
			sourceTree = "<group>";
		};
		F96D3EC908F272A7004A47F5 /* generic */ = {
			isa = PBXGroup;
			children = (
				F96D3ECA08F272A7004A47F5 /* README */,
				F96D3ECB08F272A7004A47F5 /* regc_color.c */,
				F96D3ECC08F272A7004A47F5 /* regc_cvec.c */,
				F96D3ECD08F272A7004A47F5 /* regc_lex.c */,
				F96D3ECE08F272A7004A47F5 /* regc_locale.c */,
				F96D3ECF08F272A7004A47F5 /* regc_nfa.c */,
				F96D3ED008F272A7004A47F5 /* regcomp.c */,
				F96D3ED108F272A7004A47F5 /* regcustom.h */,
				F96D3ED208F272A7004A47F5 /* rege_dfa.c */,
				F96D3ED308F272A7004A47F5 /* regerror.c */,
				F96D3ED408F272A7004A47F5 /* regerrs.h */,
				F96D3ED508F272A7004A47F5 /* regex.h */,
				F96D3ED608F272A7004A47F5 /* regexec.c */,
				F96D3ED708F272A7004A47F5 /* regfree.c */,
				F96D3ED808F272A7004A47F5 /* regfronts.c */,
				F96D3ED908F272A7004A47F5 /* regguts.h */,
				F96D3EDA08F272A7004A47F5 /* tcl.decls */,
				F96D3EDB08F272A7004A47F5 /* tcl.h */,
				F96D3EDC08F272A7004A47F5 /* tclAlloc.c */,
				F96D3EDD08F272A7004A47F5 /* tclAsync.c */,
				F96D3EDE08F272A7004A47F5 /* tclBasic.c */,
				F96D3EDF08F272A7004A47F5 /* tclBinary.c */,
				F96D3EE008F272A7004A47F5 /* tclCkalloc.c */,
				F96D3EE108F272A7004A47F5 /* tclClock.c */,
				F96D3EE208F272A7004A47F5 /* tclCmdAH.c */,
				F96D3EE308F272A7004A47F5 /* tclCmdIL.c */,
				F96D3EE408F272A7004A47F5 /* tclCmdMZ.c */,
				F96D3EE508F272A7004A47F5 /* tclCompCmds.c */,
				F96D3EE608F272A7004A47F5 /* tclCompExpr.c */,
				F96D3EE708F272A7004A47F5 /* tclCompile.c */,
				F96D3EE808F272A7004A47F5 /* tclCompile.h */,
				F96D3EE908F272A7004A47F5 /* tclConfig.c */,
				F96D3EEA08F272A7004A47F5 /* tclDate.c */,
				F96D3EEB08F272A7004A47F5 /* tclDecls.h */,
				F96D3EEC08F272A7004A47F5 /* tclDictObj.c */,
				F9F4415D0C8BAE6F00BCCD67 /* tclDTrace.d */,
				F96D3EED08F272A7004A47F5 /* tclEncoding.c */,
				F96D3EEE08F272A7004A47F5 /* tclEnv.c */,
				F96D3EEF08F272A7004A47F5 /* tclEvent.c */,
				F96D3EF008F272A7004A47F5 /* tclExecute.c */,
				F96D3EF108F272A7004A47F5 /* tclFCmd.c */,
				F96D3EF208F272A7004A47F5 /* tclFileName.c */,
				F96D3EF308F272A7004A47F5 /* tclFileSystem.h */,
				F96D3EF408F272A7004A47F5 /* tclGet.c */,
				F96D3EF508F272A7004A47F5 /* tclGetDate.y */,
				F96D3EF608F272A7004A47F5 /* tclHash.c */,
				F96D3EF708F272A7004A47F5 /* tclHistory.c */,
				F96D3EF808F272A7004A47F5 /* tclIndexObj.c */,
				F96D3EF908F272A7004A47F5 /* tclInt.decls */,
				F96D3EFA08F272A7004A47F5 /* tclInt.h */,
				F96D3EFB08F272A7004A47F5 /* tclIntDecls.h */,
				F96D3EFC08F272A7004A47F5 /* tclInterp.c */,
				F96D3EFD08F272A7004A47F5 /* tclIntPlatDecls.h */,
				F96D3EFE08F272A7004A47F5 /* tclIO.c */,
				F96D3EFF08F272A7004A47F5 /* tclIO.h */,
				F96D3F0008F272A7004A47F5 /* tclIOCmd.c */,
				F96D3F0108F272A7004A47F5 /* tclIOGT.c */,
				F96D3F0208F272A7004A47F5 /* tclIORChan.c */,
				F95D77E90DFD820D00A8BF6F /* tclIORTrans.c */,
				F96D3F0308F272A7004A47F5 /* tclIOSock.c */,
				F96D3F0408F272A7004A47F5 /* tclIOUtil.c */,
				F96D3F0508F272A7004A47F5 /* tclLink.c */,
				F96D3F0608F272A7004A47F5 /* tclListObj.c */,
				F96D3F0708F272A7004A47F5 /* tclLiteral.c */,
				F96D3F0808F272A7004A47F5 /* tclLoad.c */,
				F96D3F0908F272A7004A47F5 /* tclLoadNone.c */,
				F96D3F0A08F272A7004A47F5 /* tclMain.c */,
				F96D3F0B08F272A7004A47F5 /* tclNamesp.c */,
				F96D3F0C08F272A7004A47F5 /* tclNotify.c */,
				F96D3F0D08F272A7004A47F5 /* tclObj.c */,
				F93599B20DF1F75400E04F67 /* tclOO.c */,
				F93599B40DF1F75900E04F67 /* tclOO.decls */,
				F93599B50DF1F75D00E04F67 /* tclOO.h */,
				F93599B60DF1F76100E04F67 /* tclOOBasic.c */,
				F93599B80DF1F76600E04F67 /* tclOOCall.c */,
				F93599BA0DF1F76A00E04F67 /* tclOODecls.h */,
				F93599BB0DF1F77000E04F67 /* tclOODefineCmds.c */,
				F93599BD0DF1F77400E04F67 /* tclOOInfo.c */,
				F93599BF0DF1F77900E04F67 /* tclOOInt.h */,
				F93599C00DF1F77D00E04F67 /* tclOOIntDecls.h */,
				F93599C10DF1F78300E04F67 /* tclOOMethod.c */,
				F93599C30DF1F78800E04F67 /* tclOOStubInit.c */,
				F93599C50DF1F78D00E04F67 /* tclOOStubLib.c */,
				F96D3F0E08F272A7004A47F5 /* tclPanic.c */,
				F96D3F0F08F272A7004A47F5 /* tclParse.c */,
				F96D3F1108F272A7004A47F5 /* tclPathObj.c */,
				F96D3F1208F272A7004A47F5 /* tclPipe.c */,
				F96D3F1308F272A7004A47F5 /* tclPkg.c */,
				F96D3F1408F272A7004A47F5 /* tclPkgConfig.c */,
				F96D3F1508F272A7004A47F5 /* tclPlatDecls.h */,
				F96D3F1608F272A7004A47F5 /* tclPort.h */,
				F96D3F1708F272A7004A47F5 /* tclPosixStr.c */,
				F96D3F1808F272A7004A47F5 /* tclPreserve.c */,
				F96D3F1908F272A7004A47F5 /* tclProc.c */,
				F96D3F1A08F272A7004A47F5 /* tclRegexp.c */,
				F96D3F1B08F272A7004A47F5 /* tclRegexp.h */,
				F96D3F1C08F272A7004A47F5 /* tclResolve.c */,
				F96D3F1D08F272A7004A47F5 /* tclResult.c */,
				F96D3F1E08F272A7004A47F5 /* tclScan.c */,
				F96D3F1F08F272A7004A47F5 /* tclStringObj.c */,
				F96D3F2408F272A7004A47F5 /* tclStrToD.c */,
				F96D3F2508F272A7004A47F5 /* tclStubInit.c */,
				F96D3F2608F272A7004A47F5 /* tclStubLib.c */,
				F96D3F2708F272A7004A47F5 /* tclTest.c */,
				F96D3F2808F272A7004A47F5 /* tclTestObj.c */,
				F96D3F2908F272A7004A47F5 /* tclTestProcBodyObj.c */,
				F96D3F2A08F272A7004A47F5 /* tclThread.c */,
				F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */,
				F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */,
				F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */,
				F96D3F2E08F272A7004A47F5 /* tclThreadTest.c */,
				F96D3F2F08F272A7004A47F5 /* tclTimer.c */,
				F9903CAF094FAADA004613E9 /* tclTomMath.decls */,
				F96D3F3008F272A7004A47F5 /* tclTomMath.h */,
				F9903CB0094FAADA004613E9 /* tclTomMathDecls.h */,
				F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */,
				F96D3F3208F272A7004A47F5 /* tclTrace.c */,
				F96D3F3308F272A7004A47F5 /* tclUniData.c */,
				F96D3F3408F272A7004A47F5 /* tclUtf.c */,
				F96D3F3508F272A7004A47F5 /* tclUtil.c */,
				F96D3F3608F272A7004A47F5 /* tclVar.c */,
				F96437C90EF0D4B2003F468E /* tclZlib.c */,
				F96D3F3708F272A7004A47F5 /* tommath.h */,
			);
			path = generic;
			sourceTree = "<group>";
		};
		F96D3F3808F272A7004A47F5 /* library */ = {
			isa = PBXGroup;
			children = (
				F96D3F3908F272A8004A47F5 /* auto.tcl */,
				F96D3F3A08F272A8004A47F5 /* clock.tcl */,
				F96D3F3B08F272A8004A47F5 /* dde */,
				F96D3F8C08F272A8004A47F5 /* history.tcl */,
				F96D3F8D08F272A8004A47F5 /* http */,
				F96D3F9008F272A8004A47F5 /* http1.0 */,
				F96D3F9308F272A8004A47F5 /* init.tcl */,
				F96D3F9408F272A8004A47F5 /* msgcat */,
				F96D401708F272AA004A47F5 /* opt */,
				F96D401A08F272AA004A47F5 /* package.tcl */,
				F96D401B08F272AA004A47F5 /* parray.tcl */,
				F9ECB1110B26521500A28025 /* platform */,
				F96D401C08F272AA004A47F5 /* reg */,
				F96D401E08F272AA004A47F5 /* safe.tcl */,
				F96D401F08F272AA004A47F5 /* tclIndex */,
				F96D402008F272AA004A47F5 /* tcltest */,
				F96D402308F272AA004A47F5 /* tm.tcl */,
				F96D425B08F272B2004A47F5 /* word.tcl */,
			);
			path = library;
			sourceTree = "<group>";
		};
		F96D3F3B08F272A8004A47F5 /* dde */ = {
			isa = PBXGroup;
			children = (
				F96D3F3C08F272A8004A47F5 /* pkgIndex.tcl */,
			);
			path = dde;
			sourceTree = "<group>";
		};
		F96D3F8D08F272A8004A47F5 /* http */ = {
			isa = PBXGroup;
			children = (
				F96D3F8E08F272A8004A47F5 /* http.tcl */,
				F96D3F8F08F272A8004A47F5 /* pkgIndex.tcl */,
			);
			path = http;
			sourceTree = "<group>";
		};
		F96D3F9008F272A8004A47F5 /* http1.0 */ = {
			isa = PBXGroup;
			children = (
				F96D3F9108F272A8004A47F5 /* http.tcl */,
				F96D3F9208F272A8004A47F5 /* pkgIndex.tcl */,
			);
			path = http1.0;
			sourceTree = "<group>";
		};
		F96D3F9408F272A8004A47F5 /* msgcat */ = {
			isa = PBXGroup;
			children = (
				F96D3F9508F272A8004A47F5 /* msgcat.tcl */,
				F96D3F9608F272A8004A47F5 /* pkgIndex.tcl */,
			);
			path = msgcat;
			sourceTree = "<group>";
		};
		F96D401708F272AA004A47F5 /* opt */ = {
			isa = PBXGroup;
			children = (
				F96D401808F272AA004A47F5 /* optparse.tcl */,
				F96D401908F272AA004A47F5 /* pkgIndex.tcl */,
			);
			path = opt;
			sourceTree = "<group>";
		};
		F96D401C08F272AA004A47F5 /* reg */ = {
			isa = PBXGroup;
			children = (
				F96D401D08F272AA004A47F5 /* pkgIndex.tcl */,
			);
			path = reg;
			sourceTree = "<group>";
		};
		F96D402008F272AA004A47F5 /* tcltest */ = {
			isa = PBXGroup;
			children = (
				F96D402108F272AA004A47F5 /* pkgIndex.tcl */,
				F96D402208F272AA004A47F5 /* tcltest.tcl */,
			);
			path = tcltest;
			sourceTree = "<group>";
		};
		F96D425C08F272B2004A47F5 /* libtommath */ = {
			isa = PBXGroup;
			children = (
				F96D426408F272B3004A47F5 /* bn_fast_s_mp_mul_digs.c */,
				F96D426608F272B3004A47F5 /* bn_fast_s_mp_sqr.c */,
				F96D426908F272B3004A47F5 /* bn_mp_add.c */,
				F96D426A08F272B3004A47F5 /* bn_mp_add_d.c */,
				F96D426C08F272B3004A47F5 /* bn_mp_and.c */,
				F96D426D08F272B3004A47F5 /* bn_mp_clamp.c */,
				F96D426E08F272B3004A47F5 /* bn_mp_clear.c */,
				F96D426F08F272B3004A47F5 /* bn_mp_clear_multi.c */,
				F96D427008F272B3004A47F5 /* bn_mp_cmp.c */,
				F96D427108F272B3004A47F5 /* bn_mp_cmp_d.c */,
				F96D427208F272B3004A47F5 /* bn_mp_cmp_mag.c */,
				F96D427408F272B3004A47F5 /* bn_mp_copy.c */,
				F96D427508F272B3004A47F5 /* bn_mp_count_bits.c */,
				F96D427608F272B3004A47F5 /* bn_mp_div.c */,
				F96D427708F272B3004A47F5 /* bn_mp_div_2.c */,
				F96D427808F272B3004A47F5 /* bn_mp_div_2d.c */,
				F96D427908F272B3004A47F5 /* bn_mp_div_3.c */,
				F96D427A08F272B3004A47F5 /* bn_mp_div_d.c */,
				F96D427E08F272B3004A47F5 /* bn_mp_exch.c */,
				F96D427F08F272B3004A47F5 /* bn_mp_expt_d.c */,
				F96D428708F272B3004A47F5 /* bn_mp_grow.c */,
				F96D428808F272B3004A47F5 /* bn_mp_init.c */,
				F96D428908F272B3004A47F5 /* bn_mp_init_copy.c */,
				F96D428A08F272B3004A47F5 /* bn_mp_init_multi.c */,
				F96D428B08F272B3004A47F5 /* bn_mp_init_set.c */,
				F96D428D08F272B3004A47F5 /* bn_mp_init_size.c */,
				F96D429208F272B3004A47F5 /* bn_mp_karatsuba_mul.c */,
				F96D429308F272B3004A47F5 /* bn_mp_karatsuba_sqr.c */,
				F96D429508F272B3004A47F5 /* bn_mp_lshd.c */,
				F96D429608F272B3004A47F5 /* bn_mp_mod.c */,
				F96D429708F272B3004A47F5 /* bn_mp_mod_2d.c */,
				F96D429C08F272B3004A47F5 /* bn_mp_mul.c */,
				F96D429D08F272B3004A47F5 /* bn_mp_mul_2.c */,
				F96D429E08F272B3004A47F5 /* bn_mp_mul_2d.c */,
				F96D429F08F272B3004A47F5 /* bn_mp_mul_d.c */,
				F96D42A208F272B3004A47F5 /* bn_mp_neg.c */,
				F96D42A308F272B3004A47F5 /* bn_mp_or.c */,
				F96D42AB08F272B3004A47F5 /* bn_mp_radix_size.c */,
				F96D42AC08F272B3004A47F5 /* bn_mp_radix_smap.c */,
				F96D42AE08F272B3004A47F5 /* bn_mp_read_radix.c */,
				F96D42B908F272B3004A47F5 /* bn_mp_rshd.c */,
				F96D42BA08F272B3004A47F5 /* bn_mp_set.c */,
				F96D42BC08F272B3004A47F5 /* bn_mp_shrink.c */,
				F96D42BE08F272B3004A47F5 /* bn_mp_sqr.c */,
				F96D42C008F272B3004A47F5 /* bn_mp_sqrt.c */,
				F96D42C108F272B3004A47F5 /* bn_mp_sub.c */,
				F96D42C208F272B3004A47F5 /* bn_mp_sub_d.c */,
				F96D42C608F272B3004A47F5 /* bn_mp_to_unsigned_bin.c */,
				F96D42C708F272B3004A47F5 /* bn_mp_to_unsigned_bin_n.c */,
				F96D42C808F272B3004A47F5 /* bn_mp_toom_mul.c */,
				F96D42C908F272B3004A47F5 /* bn_mp_toom_sqr.c */,
				F96D42CB08F272B3004A47F5 /* bn_mp_toradix_n.c */,
				F96D42CC08F272B3004A47F5 /* bn_mp_unsigned_bin_size.c */,
				F96D42CD08F272B3004A47F5 /* bn_mp_xor.c */,
				F96D42CE08F272B3004A47F5 /* bn_mp_zero.c */,
				F96D42D008F272B3004A47F5 /* bn_reverse.c */,
				F96D42D108F272B3004A47F5 /* bn_s_mp_add.c */,
				F96D42D308F272B3004A47F5 /* bn_s_mp_mul_digs.c */,
				F96D42D508F272B3004A47F5 /* bn_s_mp_sqr.c */,
				F96D42D608F272B3004A47F5 /* bn_s_mp_sub.c */,
				F96D42D708F272B3004A47F5 /* bncore.c */,
				F96D432908F272B4004A47F5 /* tommath_class.h */,
				F96D432A08F272B4004A47F5 /* tommath_superclass.h */,
			);
			path = libtommath;
			sourceTree = "<group>";
		};
		F96D432C08F272B4004A47F5 /* macosx */ = {
			isa = PBXGroup;
			children = (
				F96D432E08F272B5004A47F5 /* configure.ac */,
				F96D432F08F272B5004A47F5 /* GNUmakefile */,
				F96D433108F272B5004A47F5 /* README */,
				F96D433908F272B5004A47F5 /* tclMacOSXBundle.c */,
				F96D433D08F272B5004A47F5 /* tclMacOSXFCmd.c */,
				F96D433E08F272B5004A47F5 /* tclMacOSXNotify.c */,
				F96D433208F272B5004A47F5 /* Tcl-Info.plist.in */,
				F91E62260C1AE686006C9D96 /* Tclsh-Info.plist.in */,
			);
			path = macosx;
			sourceTree = "<group>";
		};
		F96D434408F272B5004A47F5 /* tests */ = {
			isa = PBXGroup;
			children = (
				F96D434508F272B5004A47F5 /* all.tcl */,
				F96D434608F272B5004A47F5 /* append.test */,
				F96D434708F272B5004A47F5 /* appendComp.test */,
				F9ECB1CA0B2652D300A28025 /* apply.test */,
				F96D434808F272B5004A47F5 /* assocd.test */,
				F96D434908F272B5004A47F5 /* async.test */,
				F96D434A08F272B5004A47F5 /* autoMkindex.test */,
				F96D434B08F272B5004A47F5 /* basic.test */,
				F96D434C08F272B5004A47F5 /* binary.test */,
				F96D434D08F272B5004A47F5 /* case.test */,
				F96D434E08F272B5004A47F5 /* chan.test */,
				F9A493240CEBF38300B78AE2 /* chanio.test */,
				F96D434F08F272B5004A47F5 /* clock.test */,
				F96D435008F272B5004A47F5 /* cmdAH.test */,
				F96D435108F272B5004A47F5 /* cmdIL.test */,
				F96D435208F272B5004A47F5 /* cmdInfo.test */,
				F96D435308F272B5004A47F5 /* cmdMZ.test */,
				F96D435408F272B5004A47F5 /* compExpr-old.test */,
				F96D435508F272B5004A47F5 /* compExpr.test */,
				F96D435608F272B5004A47F5 /* compile.test */,
				F96D435708F272B5004A47F5 /* concat.test */,
				F96D435808F272B5004A47F5 /* config.test */,
				F974D5770FBE7E6100BF728B /* coroutine.test */,
				F96D435908F272B5004A47F5 /* dcall.test */,
				F96D435A08F272B5004A47F5 /* dict.test */,
				F96D435C08F272B5004A47F5 /* dstring.test */,
				F96D435E08F272B5004A47F5 /* encoding.test */,
				F96D435F08F272B5004A47F5 /* env.test */,
				F96D436008F272B5004A47F5 /* error.test */,
				F96D436108F272B5004A47F5 /* eval.test */,
				F96D436208F272B5004A47F5 /* event.test */,
				F96D436308F272B5004A47F5 /* exec.test */,
				F96D436408F272B5004A47F5 /* execute.test */,
				F96D436508F272B5004A47F5 /* expr-old.test */,
				F96D436608F272B5004A47F5 /* expr.test */,
				F96D436708F272B6004A47F5 /* fCmd.test */,
				F96D436808F272B6004A47F5 /* fileName.test */,
				F96D436908F272B6004A47F5 /* fileSystem.test */,
				F96D436A08F272B6004A47F5 /* for-old.test */,
				F96D436B08F272B6004A47F5 /* for.test */,
				F96D436C08F272B6004A47F5 /* foreach.test */,
				F96D436D08F272B6004A47F5 /* format.test */,
				F96D436E08F272B6004A47F5 /* get.test */,
				F96D436F08F272B6004A47F5 /* history.test */,
				F96D437008F272B6004A47F5 /* http.test */,
				F974D56C0FBE7D6300BF728B /* http11.test */,
				F96D437108F272B6004A47F5 /* httpd */,
				F974D56D0FBE7D6300BF728B /* httpd11.tcl */,
				F96D437208F272B6004A47F5 /* httpold.test */,
				F96D437308F272B6004A47F5 /* if-old.test */,
				F96D437408F272B6004A47F5 /* if.test */,
				F96D437508F272B6004A47F5 /* incr-old.test */,
				F96D437608F272B6004A47F5 /* incr.test */,
				F96D437708F272B6004A47F5 /* indexObj.test */,
				F96D437808F272B6004A47F5 /* info.test */,
				F96D437908F272B6004A47F5 /* init.test */,
				F96D437A08F272B6004A47F5 /* interp.test */,
				F96D437B08F272B6004A47F5 /* io.test */,
				F96D437C08F272B6004A47F5 /* ioCmd.test */,
				F96D437D08F272B6004A47F5 /* iogt.test */,
				F96D437F08F272B6004A47F5 /* join.test */,
				F96D438008F272B6004A47F5 /* lindex.test */,
				F96D438108F272B6004A47F5 /* link.test */,
				F96D438208F272B6004A47F5 /* linsert.test */,
				F96D438308F272B6004A47F5 /* list.test */,
				F96D438408F272B6004A47F5 /* listObj.test */,
				F96D438508F272B6004A47F5 /* llength.test */,
				F96D438608F272B6004A47F5 /* load.test */,
				F96D438708F272B6004A47F5 /* lrange.test */,
				F96D438808F272B6004A47F5 /* lrepeat.test */,
				F96D438908F272B6004A47F5 /* lreplace.test */,
				F96D438A08F272B6004A47F5 /* lsearch.test */,
				F96D438B08F272B6004A47F5 /* lset.test */,
				F96D438C08F272B6004A47F5 /* lsetComp.test */,
				F96D438D08F272B6004A47F5 /* macOSXFCmd.test */,
				F95FAFF90B34F1130072E431 /* macOSXLoad.test */,
				F96D438E08F272B6004A47F5 /* main.test */,
				F9ECB1CB0B26534C00A28025 /* mathop.test */,
				F96D438F08F272B6004A47F5 /* misc.test */,
				F96D439008F272B6004A47F5 /* msgcat.test */,
				F96D439108F272B6004A47F5 /* namespace-old.test */,
				F96D439208F272B7004A47F5 /* namespace.test */,
				F96D439308F272B7004A47F5 /* notify.test */,
				F91DC23C0E44C51B002CB8D1 /* nre.test */,
				F96D439408F272B7004A47F5 /* obj.test */,
				F93599C80DF1F81900E04F67 /* oo.test */,
				F96D439508F272B7004A47F5 /* opt.test */,
				F96D439608F272B7004A47F5 /* package.test */,
				F96D439708F272B7004A47F5 /* parse.test */,
				F96D439808F272B7004A47F5 /* parseExpr.test */,
				F96D439908F272B7004A47F5 /* parseOld.test */,
				F96D439A08F272B7004A47F5 /* pid.test */,
				F96D439B08F272B7004A47F5 /* pkg.test */,
				F96D439C08F272B7004A47F5 /* pkgMkIndex.test */,
				F96D439D08F272B7004A47F5 /* platform.test */,
				F96D439E08F272B7004A47F5 /* proc-old.test */,
				F96D439F08F272B7004A47F5 /* proc.test */,
				F96D43A008F272B7004A47F5 /* pwd.test */,
				F96D43A108F272B7004A47F5 /* README */,
				F96D43A208F272B7004A47F5 /* reg.test */,
				F96D43A308F272B7004A47F5 /* regexp.test */,
				F96D43A408F272B7004A47F5 /* regexpComp.test */,
				F96D43A508F272B7004A47F5 /* registry.test */,
				F96D43A608F272B7004A47F5 /* remote.tcl */,
				F96D43A708F272B7004A47F5 /* rename.test */,
				F96D43A808F272B7004A47F5 /* result.test */,
				F96D43A908F272B7004A47F5 /* safe.test */,
				F96D43AA08F272B7004A47F5 /* scan.test */,
				F96D43AB08F272B7004A47F5 /* security.test */,
				F96D43AC08F272B7004A47F5 /* set-old.test */,
				F96D43AD08F272B7004A47F5 /* set.test */,
				F96D43AE08F272B7004A47F5 /* socket.test */,
				F96D43AF08F272B7004A47F5 /* source.test */,
				F96D43B008F272B7004A47F5 /* split.test */,
				F96D43B108F272B7004A47F5 /* stack.test */,
				F96D43B208F272B7004A47F5 /* string.test */,
				F96D43B308F272B7004A47F5 /* stringComp.test */,
				F96D43B408F272B7004A47F5 /* stringObj.test */,
				F96D43B508F272B7004A47F5 /* subst.test */,
				F96D43B608F272B7004A47F5 /* switch.test */,
				F974D5780FBE7E6100BF728B /* tailcall.test */,
				F96D43B708F272B7004A47F5 /* tcltest.test */,
				F96D43B808F272B7004A47F5 /* thread.test */,
				F96D43B908F272B7004A47F5 /* timer.test */,
				F96D43BA08F272B7004A47F5 /* tm.test */,
				F96D43BB08F272B7004A47F5 /* trace.test */,
				F96D43BC08F272B7004A47F5 /* unixFCmd.test */,
				F96D43BD08F272B7004A47F5 /* unixFile.test */,
				F96D43BE08F272B7004A47F5 /* unixInit.test */,
				F96D43BF08F272B7004A47F5 /* unixNotfy.test */,
				F96D43C008F272B7004A47F5 /* unknown.test */,
				F96D43C108F272B7004A47F5 /* unload.test */,
				F96D43C208F272B7004A47F5 /* uplevel.test */,
				F96D43C308F272B7004A47F5 /* upvar.test */,
				F96D43C408F272B7004A47F5 /* utf.test */,
				F96D43C508F272B7004A47F5 /* util.test */,
				F96D43C608F272B7004A47F5 /* var.test */,
				F96D43C708F272B7004A47F5 /* while-old.test */,
				F96D43C808F272B7004A47F5 /* while.test */,
				F96D43C908F272B7004A47F5 /* winConsole.test */,
				F96D43CA08F272B7004A47F5 /* winDde.test */,
				F96D43CB08F272B7004A47F5 /* winFCmd.test */,
				F96D43CC08F272B7004A47F5 /* winFile.test */,
				F96D43CD08F272B7004A47F5 /* winNotify.test */,
				F96D43CE08F272B7004A47F5 /* winPipe.test */,
				F96D43CF08F272B7004A47F5 /* winTime.test */,
				F915432A0EF201CF0032D1E8 /* zlib.test */,
			);
			path = tests;
			sourceTree = "<group>";
		};
		F96D43D008F272B8004A47F5 /* tools */ = {
			isa = PBXGroup;
			children = (
				F96D43D108F272B8004A47F5 /* checkLibraryDoc.tcl */,
				F96D43D208F272B8004A47F5 /* configure */,
				F96D43D308F272B8004A47F5 /* configure.ac */,
				F96D442208F272B8004A47F5 /* eolFix.tcl */,
				F96D442408F272B8004A47F5 /* fix_tommath_h.tcl */,
				F96D442508F272B8004A47F5 /* genStubs.tcl */,
				F96D442708F272B8004A47F5 /* index.tcl */,
				F96D442808F272B8004A47F5 /* installData.tcl */,
				F96D442908F272B8004A47F5 /* loadICU.tcl */,
				F96D442A08F272B8004A47F5 /* Makefile.in */,
				F96D442B08F272B8004A47F5 /* makeTestCases.tcl */,
				F96D442C08F272B8004A47F5 /* man2help.tcl */,
				F96D442D08F272B8004A47F5 /* man2help2.tcl */,
				F96D442E08F272B8004A47F5 /* man2html.tcl */,
				F96D442F08F272B8004A47F5 /* man2html1.tcl */,
				F96D443008F272B8004A47F5 /* man2html2.tcl */,
				F96D443108F272B8004A47F5 /* man2tcl.c */,
				F96D443208F272B8004A47F5 /* README */,
				F96D443308F272B8004A47F5 /* regexpTestLib.tcl */,
				F96D443508F272B8004A47F5 /* tcl.hpj.in */,
				F96D443608F272B8004A47F5 /* tcl.wse.in */,
				F96D443908F272B9004A47F5 /* tcltk-man2html.tcl */,
				F96D443A08F272B9004A47F5 /* tclZIC.tcl */,
				F92D7F100DE777240033A13A /* tsdPerf.tcl */,
				F96D443B08F272B9004A47F5 /* uniClass.tcl */,
				F96D443C08F272B9004A47F5 /* uniParse.tcl */,
			);
			path = tools;
			sourceTree = "<group>";
		};
		F96D443E08F272B9004A47F5 /* unix */ = {
			isa = PBXGroup;
			children = (
				F96D444008F272B9004A47F5 /* aclocal.m4 */,
				F96D444108F272B9004A47F5 /* configure */,
				F96D444208F272B9004A47F5 /* configure.ac */,
				F96D444308F272B9004A47F5 /* dltest */,
				F96D444D08F272B9004A47F5 /* install-sh */,
				F96D444E08F272B9004A47F5 /* installManPage */,
				F96D444F08F272B9004A47F5 /* ldAix */,
				F96D445008F272B9004A47F5 /* Makefile.in */,
				F96D445208F272B9004A47F5 /* README */,
				F96D445308F272B9004A47F5 /* tcl.m4 */,
				F974D5790FBE7E9C00BF728B /* tcl.pc.in */,
				F96D445408F272B9004A47F5 /* tcl.spec */,
				F96D445508F272B9004A47F5 /* tclAppInit.c */,
				F96D445608F272B9004A47F5 /* tclConfig.h.in */,
				F96D445708F272B9004A47F5 /* tclConfig.sh.in */,
				F96D445808F272B9004A47F5 /* tclLoadAix.c */,
				F96D445908F272B9004A47F5 /* tclLoadDl.c */,
				F96D445B08F272B9004A47F5 /* tclLoadDyld.c */,
				F96D445C08F272B9004A47F5 /* tclLoadNext.c */,
				F96D445D08F272B9004A47F5 /* tclLoadOSF.c */,
				F96D445E08F272B9004A47F5 /* tclLoadShl.c */,
				F96D445F08F272B9004A47F5 /* tclUnixChan.c */,
				F9FC77B70AB29E9100B7077D /* tclUnixCompat.c */,
				F96D446008F272B9004A47F5 /* tclUnixEvent.c */,
				F96D446108F272B9004A47F5 /* tclUnixFCmd.c */,
				F96D446208F272B9004A47F5 /* tclUnixFile.c */,
				F96D446308F272B9004A47F5 /* tclUnixInit.c */,
				F96D446408F272B9004A47F5 /* tclUnixNotfy.c */,
				F96D446508F272B9004A47F5 /* tclUnixPipe.c */,
				F96D446608F272B9004A47F5 /* tclUnixPort.h */,
				F96D446708F272B9004A47F5 /* tclUnixSock.c */,
				F96D446808F272B9004A47F5 /* tclUnixTest.c */,
				F96D446908F272B9004A47F5 /* tclUnixThrd.c */,
				F96D446A08F272B9004A47F5 /* tclUnixThrd.h */,
				F96D446B08F272B9004A47F5 /* tclUnixTime.c */,
				F96D446C08F272B9004A47F5 /* tclXtNotify.c */,
				F96D446D08F272B9004A47F5 /* tclXtTest.c */,
			);
			path = unix;
			sourceTree = "<group>";
		};
		F96D444308F272B9004A47F5 /* dltest */ = {
			isa = PBXGroup;
			children = (
				F96D444408F272B9004A47F5 /* Makefile.in */,
				F96D444508F272B9004A47F5 /* pkga.c */,
				F96D444608F272B9004A47F5 /* pkgb.c */,
				F96D444708F272B9004A47F5 /* pkgc.c */,
				F96D444808F272B9004A47F5 /* pkgd.c */,
				F96D444908F272B9004A47F5 /* pkge.c */,
				F96D444B08F272B9004A47F5 /* pkgua.c */,
				F96D444C08F272B9004A47F5 /* README */,
			);
			path = dltest;
			sourceTree = "<group>";
		};
		F96D446E08F272B9004A47F5 /* win */ = {
			isa = PBXGroup;
			children = (
				F96D447008F272BA004A47F5 /* aclocal.m4 */,
				F96D447108F272BA004A47F5 /* buildall.vc.bat */,
				F96D447208F272BA004A47F5 /* cat.c */,
				F96D447308F272BA004A47F5 /* coffbase.txt */,
				F96D447408F272BA004A47F5 /* configure */,
				F96D447508F272BA004A47F5 /* configure.ac */,
				F96D447708F272BA004A47F5 /* Makefile.in */,
				F96D447808F272BA004A47F5 /* makefile.vc */,
				F96D447908F272BA004A47F5 /* nmakehlp.c */,
				F96D447A08F272BA004A47F5 /* README */,
				F96D447C08F272BA004A47F5 /* rules.vc */,
				F96D447D08F272BA004A47F5 /* stub16.c */,
				F96D447E08F272BA004A47F5 /* tcl.dsp */,
				F96D447F08F272BA004A47F5 /* tcl.dsw */,
				F96D448008F272BA004A47F5 /* tcl.hpj.in */,
				F96D448108F272BA004A47F5 /* tcl.m4 */,
				F96D448208F272BA004A47F5 /* tcl.rc */,
				F96D448308F272BA004A47F5 /* tclAppInit.c */,
				F96D448408F272BA004A47F5 /* tclConfig.sh.in */,
				F96D448608F272BA004A47F5 /* tclsh.rc */,
				F96D448708F272BA004A47F5 /* tclWin32Dll.c */,
				F96D448808F272BA004A47F5 /* tclWinChan.c */,
				F96D448908F272BA004A47F5 /* tclWinConsole.c */,
				F96D448A08F272BA004A47F5 /* tclWinDde.c */,
				F96D448B08F272BA004A47F5 /* tclWinError.c */,
				F96D448C08F272BA004A47F5 /* tclWinFCmd.c */,
				F96D448D08F272BA004A47F5 /* tclWinFile.c */,
				F96D448E08F272BA004A47F5 /* tclWinInit.c */,
				F96D448F08F272BA004A47F5 /* tclWinInt.h */,
				F96D449008F272BA004A47F5 /* tclWinLoad.c */,
				F96D449108F272BA004A47F5 /* tclWinNotify.c */,
				F96D449208F272BA004A47F5 /* tclWinPipe.c */,
				F96D449308F272BA004A47F5 /* tclWinPort.h */,
				F96D449408F272BA004A47F5 /* tclWinReg.c */,
				F96D449508F272BA004A47F5 /* tclWinSerial.c */,
				F96D449608F272BA004A47F5 /* tclWinSock.c */,
				F96D449708F272BA004A47F5 /* tclWinTest.c */,
				F96D449808F272BA004A47F5 /* tclWinThrd.c */,
				F96D449908F272BA004A47F5 /* tclWinThrd.h */,
				F96D449A08F272BA004A47F5 /* tclWinTime.c */,
			);
			path = win;
			sourceTree = "<group>";
		};
		F9ECB1110B26521500A28025 /* platform */ = {
			isa = PBXGroup;
			children = (
				F9ECB1120B26521500A28025 /* pkgIndex.tcl */,
				F9ECB1130B26521500A28025 /* platform.tcl */,
				F9ECB1140B26521500A28025 /* shell.tcl */,
			);
			path = platform;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
		8DD76FA90486AB0100D96B5E /* tktest */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = F95CC8B009158F3100EA5ACE /* Build configuration list for PBXNativeTarget "tktest" */;
			buildPhases = (
				F9A5C5F508F651A2008AE941 /* Configure Tcl */,
				F9A5C5F608F651AB008AE941 /* Configure Tk */,
				8DD76FAB0486AB0100D96B5E /* Sources */,
				8DD76FAD0486AB0100D96B5E /* Frameworks */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = tktest;
			productInstallPath = "$(BINDIR)";
			productName = tktest;
			productReference = 8DD76FB20486AB0100D96B5E /* tktest */;
			productType = "com.apple.product-type.tool";
		};
		F97258A50A86873C00096C78 /* tktest-X11 */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = F97258A80A86873D00096C78 /* Build configuration list for PBXNativeTarget "tktest-X11" */;
			buildPhases = (
				F9FD30B40CC1AD070073837D /* Configure Tcl */,
				F9FD30B50CC1AD070073837D /* Configure Tk */,
				F9FD30BB0CC1AD070073837D /* Sources */,
				F9FD31E30CC1AD070073837D /* Frameworks */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = "tktest-X11";
			productInstallPath = "$(BINDIR)";
			productName = tktest;
			productReference = F9FD31F40CC1AD070073837D /* tktest-X11 */;
			productType = "com.apple.product-type.tool";
		};
		F9E61D16090A3E94002B3151 /* Tk */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = F95CC8AB09158F3100EA5ACE /* Build configuration list for PBXNativeTarget "Tk" */;
			buildPhases = (
				F97AF02F0B665DA900310EA2 /* Build Tk */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = Tk;
			productName = Wish;
			productReference = F9A3084B08F2D4CE00BAE1AB /* Wish.app */;
			productType = "com.apple.product-type.application";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		08FB7793FE84155DC02AAC07 /* Project object */ = {
			isa = PBXProject;
			attributes = {
				BuildIndependentTargetsInParallel = YES;
			};
			buildConfigurationList = F95CC8B509158F3100EA5ACE /* Build configuration list for PBXProject "Tk" */;
			compatibilityVersion = "Xcode 3.1";
			hasScannedForEncodings = 1;
			mainGroup = 08FB7794FE84155DC02AAC07 /* Tk */;
			projectDirPath = "";
			projectRoot = ..;
			targets = (
				F9E61D16090A3E94002B3151 /* Tk */,
				8DD76FA90486AB0100D96B5E /* tktest */,
				F97258A50A86873C00096C78 /* tktest-X11 */,
			);
		};
/* End PBXProject section */

/* Begin PBXShellScriptBuildPhase section */
		F97AF02F0B665DA900310EA2 /* Build Tk */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"${TARGET_TEMP_DIR}/.none",
			);
			name = "Build Tk";
			outputPaths = (
				"${TARGET_BUILD_DIR}/${WRAPPER_NAME}",
			);
			runOnlyForDeploymentPostprocessing = 0;
			shellPath = /bin/bash;
			shellScript = "export CC=$(xcrun -find ${GCC} || echo ${GCC}); export LD=${CC}\ngnumake -C \"${TK_SRCROOT}/macosx\"  -j \"$(sysctl -n hw.activecpu)\" \"$(echo \"${ACTION}\" | sed -e s/build// -e s/clean/distclean/ -e s/..\\*/\\&-/)${MAKE_TARGET}\" CFLAGS_WARNING=\"${WARNING_CFLAGS}\" CFLAGS_OPTIMIZE=\"-O${GCC_OPTIMIZATION_LEVEL}\" SYMROOT=\"${BUILT_PRODUCTS_DIR}\" OBJ_DIR=\"${OBJECT_FILE_DIR}\" INSTALL_ROOT=\"${DSTROOT}\" PREFIX=\"${PREFIX}\" BINDIR=\"${BINDIR}\" LIBDIR=\"${FRAMEWORK_INSTALL_PATH}\" MANDIR=\"${MANDIR}\" EXTRA_CONFIGURE_ARGS=\"${CONFIGURE_ARGS}\" APPLICATION_INSTALL_PATH=\"${APPLICATION_INSTALL_PATH}\" TCL_BUILD_DIR=\"${TCL_BUILD_DIR}\" TCL_FRAMEWORK_DIR=\"${TCL_FRAMEWORK_DIR}\" ${EXTRA_MAKE_FLAGS}\nresult=$?\nif [ -e \"${BUILT_PRODUCTS_DIR}/tktest\" ]; then\n\trm -f \"${BUILT_PRODUCTS_DIR}/tktest\"\nfi\necho \"Done\"\nrm -f \"${SCRIPT_INPUT_FILE_0}\"\nexit ${result}\n";
			showEnvVarsInLog = 0;
		};
		F9A5C5F508F651A2008AE941 /* Configure Tcl */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"$(TCL_SRCROOT)/macosx/configure.ac",
				"$(TCL_SRCROOT)/unix/configure.ac",
				"$(TCL_SRCROOT)/unix/tcl.m4",
				"$(TCL_SRCROOT)/unix/aclocal.m4",
				"$(TCL_SRCROOT)/unix/tclConfig.sh.in",
				"$(TCL_SRCROOT)/unix/Makefile.in",
				"$(TCL_SRCROOT)/unix/dltest/Makefile.in",
			);
			name = "Configure Tcl";
			outputPaths = (
				"$(DERIVED_FILE_DIR)/tcl/tclConfig.sh",
			);
			runOnlyForDeploymentPostprocessing = 0;
			shellPath = /bin/bash;
			shellScript = "## tcl configure shell script phase\n\ncd \"${TCL_SRCROOT}\"/macosx &&\nif [ configure.ac -nt configure -o ../unix/configure.ac -nt configure -o ../unix/tcl.m4 -nt configure -o ../unix/aclocal.m4 -nt configure ]; then\n    echo \"Running autoconf & autoheader in tcl/macosx\"\n    rm -rf autom4te.cache\n    ${AUTOCONF:-${DEVELOPER_DIR}/usr/bin/autoconf} && ${AUTOHEADER:-${DEVELOPER_DIR}/usr/bin/autoheader} || exit $?\n    rm -rf autom4te.cache\nfi\n\ncd \"${DERIVED_FILE_DIR}\" && mkdir -p tcl && cd tcl &&\nif [ \"${TCL_SRCROOT}\"/macosx/configure -nt config.status ]; then\n    echo \"Configuring Tcl\"\n    CC=$(xcrun -find ${GCC} || echo ${GCC})\n    \"${TCL_SRCROOT}\"/macosx/configure --cache-file=../config.cache --prefix=${PREFIX} --bindir=${BINDIR} --libdir=${LIBDIR} --mandir=${MANDIR} --includedir=${INCLUDEDIR} --disable-shared CC=${CC} LD=${CC} ${CONFIGURE_ARGS}\nelse\n    ./config.status\nfi\n";
			showEnvVarsInLog = 0;
		};
		F9A5C5F608F651AB008AE941 /* Configure Tk */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"$(TK_SRCROOT)/macosx/configure.ac",
				"$(TK_SRCROOT)/unix/configure.ac",
				"$(TK_SRCROOT)/unix/tcl.m4",
				"$(TK_SRCROOT)/unix/aclocal.m4",
				"$(TK_SRCROOT)/unix/tkConfig.sh.in",
			);
			name = "Configure Tk";
			outputPaths = (
				"$(DERIVED_FILE_DIR)/tk/tkConfig.sh",
			);
			runOnlyForDeploymentPostprocessing = 0;
			shellPath = /bin/bash;
			shellScript = "## tk configure shell script phase\n\ncd \"${TK_SRCROOT}\"/macosx &&\nif [ configure.ac -nt configure -o ../unix/configure.ac -nt configure -o ../unix/tcl.m4 -nt configure -o ../unix/aclocal.m4 -nt configure ]; then\n    echo \"Running autoconf & autoheader in tk/macosx\"\n    rm -rf autom4te.cache\n    ${AUTOCONF:-${DEVELOPER_DIR}/usr/bin/autoconf} && ${AUTOHEADER:-${DEVELOPER_DIR}/usr/bin/autoheader} || exit $?\n    rm -rf autom4te.cache\nfi\n\ncd \"${DERIVED_FILE_DIR}\" && mkdir -p tk && cd tk &&\nif [ \"${TK_SRCROOT}\"/macosx/configure -nt config.status ]; then\n    echo \"Configuring Tk\"\n    CC=$(xcrun -find ${GCC} || echo ${GCC})\n    \"${TK_SRCROOT}\"/macosx/configure --cache-file=../config.cache --prefix=${PREFIX} --bindir=${BINDIR} --libdir=${LIBDIR} --mandir=${MANDIR} --includedir=${INCLUDEDIR} --disable-shared --enable-aqua --with-tcl=../tcl CC=${CC} LD=${CC} ${CONFIGURE_ARGS}\nelse\n    ./config.status\nfi\n";
			showEnvVarsInLog = 0;
		};
		F9FD30B40CC1AD070073837D /* Configure Tcl */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"$(TCL_SRCROOT)/macosx/configure.ac",
				"$(TCL_SRCROOT)/unix/configure.ac",
				"$(TCL_SRCROOT)/unix/tcl.m4",
				"$(TCL_SRCROOT)/unix/aclocal.m4",
				"$(TCL_SRCROOT)/unix/tclConfig.sh.in",
				"$(TCL_SRCROOT)/unix/Makefile.in",
				"$(TCL_SRCROOT)/unix/dltest/Makefile.in",
			);
			name = "Configure Tcl";
			outputPaths = (
				"$(DERIVED_FILE_DIR)/tcl/tclConfig.sh",
			);
			runOnlyForDeploymentPostprocessing = 0;
			shellPath = /bin/bash;
			shellScript = "## tcl configure shell script phase\n\ncd \"${TCL_SRCROOT}\"/macosx &&\nif [ configure.ac -nt configure -o ../unix/configure.ac -nt configure -o ../unix/tcl.m4 -nt configure -o ../unix/aclocal.m4 -nt configure ]; then\n    echo \"Running autoconf & autoheader in tcl/macosx\"\n    rm -rf autom4te.cache\n    ${AUTOCONF:-${DEVELOPER_DIR}/usr/bin/autoconf} && ${AUTOHEADER:-${DEVELOPER_DIR}/usr/bin/autoheader} || exit $?\n    rm -rf autom4te.cache\nfi\n\ncd \"${DERIVED_FILE_DIR}\" && mkdir -p tcl && cd tcl &&\nif [ \"${TCL_SRCROOT}\"/macosx/configure -nt config.status ]; then\n    echo \"Configuring Tcl\"\n    CC=$(xcrun -find ${GCC} || echo ${GCC})\n    \"${TCL_SRCROOT}\"/macosx/configure --cache-file=../config.cache --prefix=${PREFIX} --bindir=${BINDIR} --libdir=${LIBDIR} --mandir=${MANDIR} --includedir=${INCLUDEDIR} --disable-shared CC=${CC} LD=${CC} ${CONFIGURE_ARGS}\nelse\n    ./config.status\nfi\n";
			showEnvVarsInLog = 0;
		};
		F9FD30B50CC1AD070073837D /* Configure Tk */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"$(TK_SRCROOT)/macosx/configure.ac",
				"$(TK_SRCROOT)/unix/configure.ac",
				"$(TK_SRCROOT)/unix/tcl.m4",
				"$(TK_SRCROOT)/unix/aclocal.m4",
				"$(TK_SRCROOT)/unix/tkConfig.sh.in",
			);
			name = "Configure Tk";
			outputPaths = (
				"$(DERIVED_FILE_DIR)/tk/tkConfig.sh",
			);
			runOnlyForDeploymentPostprocessing = 0;
			shellPath = /bin/bash;
			shellScript = "## tk configure shell script phase\n\ncd \"${TK_SRCROOT}\"/macosx &&\nif [ configure.ac -nt configure -o ../unix/configure.ac -nt configure -o ../unix/tcl.m4 -nt configure -o ../unix/aclocal.m4 -nt configure ]; then\n    echo \"Running autoconf & autoheader in tk/macosx\"\n    rm -rf autom4te.cache\n    ${AUTOCONF:-${DEVELOPER_DIR}/usr/bin/autoconf} && ${AUTOHEADER:-${DEVELOPER_DIR}/usr/bin/autoheader} || exit $?\n    rm -rf autom4te.cache\nfi\n\ncd \"${DERIVED_FILE_DIR}\" && mkdir -p tk && cd tk &&\nif [ \"${TK_SRCROOT}\"/macosx/configure -nt config.status ]; then\n    echo \"Configuring Tk\"\n    CC=$(xcrun -find ${GCC} || echo ${GCC})\n    PATH=\"${PATH}:/usr/X11R6/bin\" \"${TK_SRCROOT}\"/macosx/configure --cache-file=../config.cache --prefix=${PREFIX} --bindir=${BINDIR} --libdir=${LIBDIR} --mandir=${MANDIR} --includedir=${INCLUDEDIR} --disable-shared --enable-xft --with-tcl=../tcl CC=${CC} LD=${CC} ${CONFIGURE_ARGS}\nelse\n    ./config.status\nfi";
			showEnvVarsInLog = 0;
		};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
		8DD76FAB0486AB0100D96B5E /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				F96D456F08F272BB004A47F5 /* regcomp.c in Sources */,
				F96D457208F272BB004A47F5 /* regerror.c in Sources */,
				F96D457508F272BB004A47F5 /* regexec.c in Sources */,
				F96D457608F272BB004A47F5 /* regfree.c in Sources */,
				F96D457B08F272BB004A47F5 /* tclAlloc.c in Sources */,
				F96D457C08F272BB004A47F5 /* tclAsync.c in Sources */,
				F96D457D08F272BB004A47F5 /* tclBasic.c in Sources */,
				F96D457E08F272BC004A47F5 /* tclBinary.c in Sources */,
				F96D457F08F272BC004A47F5 /* tclCkalloc.c in Sources */,
				F96D458008F272BC004A47F5 /* tclClock.c in Sources */,
				F96D458108F272BC004A47F5 /* tclCmdAH.c in Sources */,
				F96D458208F272BC004A47F5 /* tclCmdIL.c in Sources */,
				F96D458308F272BC004A47F5 /* tclCmdMZ.c in Sources */,
				F96D458408F272BC004A47F5 /* tclCompCmds.c in Sources */,
				F96D458508F272BC004A47F5 /* tclCompExpr.c in Sources */,
				F96D458608F272BC004A47F5 /* tclCompile.c in Sources */,
				F96D458808F272BC004A47F5 /* tclConfig.c in Sources */,
				F96D458908F272BC004A47F5 /* tclDate.c in Sources */,
				F96D458B08F272BC004A47F5 /* tclDictObj.c in Sources */,
				F96D458C08F272BC004A47F5 /* tclEncoding.c in Sources */,
				F96D458D08F272BC004A47F5 /* tclEnv.c in Sources */,
				F96D458E08F272BC004A47F5 /* tclEvent.c in Sources */,
				F96D458F08F272BC004A47F5 /* tclExecute.c in Sources */,
				F96D459008F272BC004A47F5 /* tclFCmd.c in Sources */,
				F96D459108F272BC004A47F5 /* tclFileName.c in Sources */,
				F96D459308F272BC004A47F5 /* tclGet.c in Sources */,
				F96D459508F272BC004A47F5 /* tclHash.c in Sources */,
				F96D459608F272BC004A47F5 /* tclHistory.c in Sources */,
				F96D459708F272BC004A47F5 /* tclIndexObj.c in Sources */,
				F96D459B08F272BC004A47F5 /* tclInterp.c in Sources */,
				F96D459D08F272BC004A47F5 /* tclIO.c in Sources */,
				F96D459F08F272BC004A47F5 /* tclIOCmd.c in Sources */,
				F96D45A008F272BC004A47F5 /* tclIOGT.c in Sources */,
				F96D45A108F272BC004A47F5 /* tclIORChan.c in Sources */,
				F95D77EA0DFD820D00A8BF6F /* tclIORTrans.c in Sources */,
				F96D45A208F272BC004A47F5 /* tclIOSock.c in Sources */,
				F96D45A308F272BC004A47F5 /* tclIOUtil.c in Sources */,
				F96D45A408F272BC004A47F5 /* tclLink.c in Sources */,
				F96D45A508F272BC004A47F5 /* tclListObj.c in Sources */,
				F96D45A608F272BC004A47F5 /* tclLiteral.c in Sources */,
				F96D45A708F272BC004A47F5 /* tclLoad.c in Sources */,
				F96D45A908F272BC004A47F5 /* tclMain.c in Sources */,
				F96D45AA08F272BC004A47F5 /* tclNamesp.c in Sources */,
				F96D45AB08F272BC004A47F5 /* tclNotify.c in Sources */,
				F96D45AC08F272BC004A47F5 /* tclObj.c in Sources */,
				F93599B30DF1F75400E04F67 /* tclOO.c in Sources */,
				F93599B70DF1F76100E04F67 /* tclOOBasic.c in Sources */,
				F93599B90DF1F76600E04F67 /* tclOOCall.c in Sources */,
				F93599BC0DF1F77000E04F67 /* tclOODefineCmds.c in Sources */,
				F93599BE0DF1F77400E04F67 /* tclOOInfo.c in Sources */,
				F93599C20DF1F78300E04F67 /* tclOOMethod.c in Sources */,
				F93599C40DF1F78800E04F67 /* tclOOStubInit.c in Sources */,
				F93599C60DF1F78D00E04F67 /* tclOOStubLib.c in Sources */,
				F96D45AD08F272BC004A47F5 /* tclPanic.c in Sources */,
				F96D45AE08F272BC004A47F5 /* tclParse.c in Sources */,
				F96D45B008F272BC004A47F5 /* tclPathObj.c in Sources */,
				F96D45B108F272BC004A47F5 /* tclPipe.c in Sources */,
				F96D45B208F272BC004A47F5 /* tclPkg.c in Sources */,
				F96D45B308F272BC004A47F5 /* tclPkgConfig.c in Sources */,
				F96D45B608F272BC004A47F5 /* tclPosixStr.c in Sources */,
				F96D45B708F272BC004A47F5 /* tclPreserve.c in Sources */,
				F96D45B808F272BC004A47F5 /* tclProc.c in Sources */,
				F96D45B908F272BC004A47F5 /* tclRegexp.c in Sources */,
				F96D45BB08F272BC004A47F5 /* tclResolve.c in Sources */,
				F96D45BC08F272BC004A47F5 /* tclResult.c in Sources */,
				F96D45BD08F272BC004A47F5 /* tclScan.c in Sources */,
				F96D45BE08F272BC004A47F5 /* tclStringObj.c in Sources */,
				F96D45C308F272BC004A47F5 /* tclStrToD.c in Sources */,
				F96D45C408F272BC004A47F5 /* tclStubInit.c in Sources */,
				F96D45C508F272BC004A47F5 /* tclStubLib.c in Sources */,
				F96D45C908F272BC004A47F5 /* tclThread.c in Sources */,
				F96D45CA08F272BC004A47F5 /* tclThreadAlloc.c in Sources */,
				F96D45CB08F272BC004A47F5 /* tclThreadJoin.c in Sources */,
				F96D45CC08F272BC004A47F5 /* tclThreadStorage.c in Sources */,
				F96D45CE08F272BC004A47F5 /* tclTimer.c in Sources */,
				F96D45D008F272BC004A47F5 /* tclTomMathInterface.c in Sources */,
				F96D45D108F272BC004A47F5 /* tclTrace.c in Sources */,
				F96D45D308F272BC004A47F5 /* tclUtf.c in Sources */,
				F96D45D408F272BC004A47F5 /* tclUtil.c in Sources */,
				F96D45D508F272BC004A47F5 /* tclVar.c in Sources */,
				F96437CA0EF0D4B2003F468E /* tclZlib.c in Sources */,
				F96D48E208F272C3004A47F5 /* bn_fast_s_mp_mul_digs.c in Sources */,
				F96D48E408F272C3004A47F5 /* bn_fast_s_mp_sqr.c in Sources */,
				F96D48E708F272C3004A47F5 /* bn_mp_add.c in Sources */,
				F96D48E808F272C3004A47F5 /* bn_mp_add_d.c in Sources */,
				F9E61D2B090A48A4002B3151 /* bn_mp_and.c in Sources */,
				F96D48EB08F272C3004A47F5 /* bn_mp_clamp.c in Sources */,
				F96D48EC08F272C3004A47F5 /* bn_mp_clear.c in Sources */,
				F96D48ED08F272C3004A47F5 /* bn_mp_clear_multi.c in Sources */,
				F96D48EE08F272C3004A47F5 /* bn_mp_cmp.c in Sources */,
				F9E61D28090A481F002B3151 /* bn_mp_cmp_d.c in Sources */,
				F96D48F008F272C3004A47F5 /* bn_mp_cmp_mag.c in Sources */,
				F96D48F208F272C3004A47F5 /* bn_mp_copy.c in Sources */,
				F96D48F308F272C3004A47F5 /* bn_mp_count_bits.c in Sources */,
				F96D48F408F272C3004A47F5 /* bn_mp_div.c in Sources */,
				F96D48F508F272C3004A47F5 /* bn_mp_div_2.c in Sources */,
				F96D48F608F272C3004A47F5 /* bn_mp_div_2d.c in Sources */,
				F96D48F708F272C3004A47F5 /* bn_mp_div_3.c in Sources */,
				F96D48F808F272C3004A47F5 /* bn_mp_div_d.c in Sources */,
				F96D48FC08F272C3004A47F5 /* bn_mp_exch.c in Sources */,
				F9E61D2C090A48AC002B3151 /* bn_mp_expt_d.c in Sources */,
				F96D490508F272C3004A47F5 /* bn_mp_grow.c in Sources */,
				F96D490608F272C3004A47F5 /* bn_mp_init.c in Sources */,
				F96D490708F272C3004A47F5 /* bn_mp_init_copy.c in Sources */,
				F96D490808F272C3004A47F5 /* bn_mp_init_multi.c in Sources */,
				F96D490908F272C3004A47F5 /* bn_mp_init_set.c in Sources */,
				F96D490B08F272C3004A47F5 /* bn_mp_init_size.c in Sources */,
				F96D491008F272C3004A47F5 /* bn_mp_karatsuba_mul.c in Sources */,
				F96D491108F272C3004A47F5 /* bn_mp_karatsuba_sqr.c in Sources */,
				F96D491308F272C3004A47F5 /* bn_mp_lshd.c in Sources */,
				F96D491408F272C3004A47F5 /* bn_mp_mod.c in Sources */,
				F96D491508F272C3004A47F5 /* bn_mp_mod_2d.c in Sources */,
				F96D491A08F272C3004A47F5 /* bn_mp_mul.c in Sources */,
				F96D491B08F272C3004A47F5 /* bn_mp_mul_2.c in Sources */,
				F96D491C08F272C3004A47F5 /* bn_mp_mul_2d.c in Sources */,
				F96D491D08F272C3004A47F5 /* bn_mp_mul_d.c in Sources */,
				F9E61D29090A486C002B3151 /* bn_mp_neg.c in Sources */,
				F9E61D2E090A48BF002B3151 /* bn_mp_or.c in Sources */,
				F96D492908F272C3004A47F5 /* bn_mp_radix_size.c in Sources */,
				F96D492A08F272C3004A47F5 /* bn_mp_radix_smap.c in Sources */,
				F96D492C08F272C3004A47F5 /* bn_mp_read_radix.c in Sources */,
				F96D493708F272C3004A47F5 /* bn_mp_rshd.c in Sources */,
				F96D493808F272C3004A47F5 /* bn_mp_set.c in Sources */,
				F9E61D2F090A48C7002B3151 /* bn_mp_shrink.c in Sources */,
				F96D493C08F272C3004A47F5 /* bn_mp_sqr.c in Sources */,
				F9E61D2A090A4891002B3151 /* bn_mp_sqrt.c in Sources */,
				F96D493F08F272C3004A47F5 /* bn_mp_sub.c in Sources */,
				F96D494008F272C3004A47F5 /* bn_mp_sub_d.c in Sources */,
				F9E61D30090A48E2002B3151 /* bn_mp_to_unsigned_bin_n.c in Sources */,
				F9E61D31090A48F9002B3151 /* bn_mp_to_unsigned_bin.c in Sources */,
				F96D494608F272C3004A47F5 /* bn_mp_toom_mul.c in Sources */,
				F96D494708F272C3004A47F5 /* bn_mp_toom_sqr.c in Sources */,
				F96D494908F272C3004A47F5 /* bn_mp_toradix_n.c in Sources */,
				F9E61D32090A48FA002B3151 /* bn_mp_unsigned_bin_size.c in Sources */,
				F9E61D2D090A48BB002B3151 /* bn_mp_xor.c in Sources */,
				F96D494C08F272C3004A47F5 /* bn_mp_zero.c in Sources */,
				F96D494E08F272C3004A47F5 /* bn_reverse.c in Sources */,
				F96D494F08F272C3004A47F5 /* bn_s_mp_add.c in Sources */,
				F96D495108F272C3004A47F5 /* bn_s_mp_mul_digs.c in Sources */,
				F96D495308F272C3004A47F5 /* bn_s_mp_sqr.c in Sources */,
				F96D495408F272C3004A47F5 /* bn_s_mp_sub.c in Sources */,
				F96D495508F272C3004A47F5 /* bncore.c in Sources */,
				F96D49A908F272C4004A47F5 /* tclMacOSXBundle.c in Sources */,
				F96D49AD08F272C4004A47F5 /* tclMacOSXFCmd.c in Sources */,
				F96D49AE08F272C4004A47F5 /* tclMacOSXNotify.c in Sources */,
				F96D4AC608F272C9004A47F5 /* tclLoadDyld.c in Sources */,
				F96D4ACA08F272C9004A47F5 /* tclUnixChan.c in Sources */,
				F9FC77B80AB29E9100B7077D /* tclUnixCompat.c in Sources */,
				F96D4ACB08F272C9004A47F5 /* tclUnixEvent.c in Sources */,
				F96D4ACC08F272C9004A47F5 /* tclUnixFCmd.c in Sources */,
				F96D4ACD08F272C9004A47F5 /* tclUnixFile.c in Sources */,
				F96D4ACE08F272C9004A47F5 /* tclUnixInit.c in Sources */,
				F96D4ACF08F272C9004A47F5 /* tclUnixNotfy.c in Sources */,
				F96D4AD008F272C9004A47F5 /* tclUnixPipe.c in Sources */,
				F96D4AD208F272CA004A47F5 /* tclUnixSock.c in Sources */,
				F96D4AD408F272CA004A47F5 /* tclUnixThrd.c in Sources */,
				F96D4AD608F272CA004A47F5 /* tclUnixTime.c in Sources */,
				F9F4415E0C8BAE6F00BCCD67 /* tclDTrace.d in Sources */,
				F966BDCF08F27A3F005CB29B /* tk3d.c in Sources */,
				F966BDD108F27A3F005CB29B /* tkArgv.c in Sources */,
				F966BDD208F27A3F005CB29B /* tkAtom.c in Sources */,
				F966BDD308F27A3F005CB29B /* tkBind.c in Sources */,
				F966BDD408F27A3F005CB29B /* tkBitmap.c in Sources */,
				F9152B090EAF8A5000CD5C7B /* tkBusy.c in Sources */,
				F966BDD508F27A3F005CB29B /* tkButton.c in Sources */,
				F966BDD708F27A3F005CB29B /* tkCanvArc.c in Sources */,
				F966BDD808F27A3F005CB29B /* tkCanvas.c in Sources */,
				F966BDDA08F27A3F005CB29B /* tkCanvBmap.c in Sources */,
				F966BDDB08F27A3F005CB29B /* tkCanvImg.c in Sources */,
				F966BDDC08F27A3F005CB29B /* tkCanvLine.c in Sources */,
				F966BDDD08F27A3F005CB29B /* tkCanvPoly.c in Sources */,
				F966BDDE08F27A3F005CB29B /* tkCanvPs.c in Sources */,
				F966BDE008F27A3F005CB29B /* tkCanvText.c in Sources */,
				F966BDE108F27A3F005CB29B /* tkCanvUtil.c in Sources */,
				F966BDE208F27A3F005CB29B /* tkCanvWind.c in Sources */,
				F966BDE308F27A3F005CB29B /* tkClipboard.c in Sources */,
				F966BDE408F27A3F005CB29B /* tkCmds.c in Sources */,
				F966BDE508F27A3F005CB29B /* tkColor.c in Sources */,
				F966BDE708F27A3F005CB29B /* tkConfig.c in Sources */,
				F966BDE808F27A3F005CB29B /* tkConsole.c in Sources */,
				F966BDE908F27A3F005CB29B /* tkCursor.c in Sources */,
				F966BDEB08F27A3F005CB29B /* tkEntry.c in Sources */,
				F966BDED08F27A3F005CB29B /* tkError.c in Sources */,
				F966BDEE08F27A3F005CB29B /* tkEvent.c in Sources */,
				F966BDEF08F27A3F005CB29B /* tkFileFilter.c in Sources */,
				F966BDF108F27A3F005CB29B /* tkFocus.c in Sources */,
				F966BDF208F27A3F005CB29B /* tkFont.c in Sources */,
				F966BDF408F27A3F005CB29B /* tkFrame.c in Sources */,
				F966BDF508F27A3F005CB29B /* tkGC.c in Sources */,
				F966BDF608F27A3F005CB29B /* tkGeometry.c in Sources */,
				F966BDF708F27A3F005CB29B /* tkGet.c in Sources */,
				F966BDF808F27A3F005CB29B /* tkGrab.c in Sources */,
				F966BDF908F27A3F005CB29B /* tkGrid.c in Sources */,
				F966BDFA08F27A3F005CB29B /* tkImage.c in Sources */,
				F966BDFB08F27A3F005CB29B /* tkImgBmap.c in Sources */,
				F966BDFC08F27A3F005CB29B /* tkImgGIF.c in Sources */,
				F92EE8BF0E62F846001A6E80 /* tkImgPhInstance.c in Sources */,
				F966BDFD08F27A3F005CB29B /* tkImgPhoto.c in Sources */,
				F9DD99BD0F07DF850018B2E4 /* tkImgPNG.c in Sources */,
				F966BDFE08F27A3F005CB29B /* tkImgPPM.c in Sources */,
				F966BE0708F27A3F005CB29B /* tkListbox.c in Sources */,
				F966BE0808F27A3F005CB29B /* tkMacWinMenu.c in Sources */,
				F966BE0908F27A3F005CB29B /* tkMain.c in Sources */,
				F966BE0A08F27A3F005CB29B /* tkMenu.c in Sources */,
				F966BE0C08F27A3F005CB29B /* tkMenubutton.c in Sources */,
				F966BE0E08F27A3F005CB29B /* tkMenuDraw.c in Sources */,
				F966BE0F08F27A3F005CB29B /* tkMessage.c in Sources */,
				F966BE1008F27A3F005CB29B /* tkObj.c in Sources */,
				F966BE1108F27A3F005CB29B /* tkOldConfig.c in Sources */,
				F9067BCD0BFBA2900074F726 /* tkOldTest.c in Sources */,
				F966BE1208F27A3F005CB29B /* tkOption.c in Sources */,
				F966BE1308F27A3F005CB29B /* tkPack.c in Sources */,
				F966BE1408F27A3F005CB29B /* tkPanedWindow.c in Sources */,
				F966BE1508F27A3F005CB29B /* tkPlace.c in Sources */,
				F966BE1708F27A3F005CB29B /* tkPointer.c in Sources */,
				F966BE1908F27A3F005CB29B /* tkRectOval.c in Sources */,
				F966BE1A08F27A3F005CB29B /* tkScale.c in Sources */,
				F966BE1C08F27A40005CB29B /* tkScrollbar.c in Sources */,
				F966BE1E08F27A40005CB29B /* tkSelect.c in Sources */,
				F966BE2008F27A40005CB29B /* tkSquare.c in Sources */,
				F966BE2208F27A40005CB29B /* tkStubInit.c in Sources */,
				F966BE2308F27A40005CB29B /* tkStubLib.c in Sources */,
				F966BE2408F27A40005CB29B /* tkStyle.c in Sources */,
				F966BE2508F27A40005CB29B /* tkTest.c in Sources */,
				F966BE2608F27A40005CB29B /* tkText.c in Sources */,
				F966BE2808F27A40005CB29B /* tkTextBTree.c in Sources */,
				F966BE2908F27A40005CB29B /* tkTextDisp.c in Sources */,
				F966BE2B08F27A40005CB29B /* tkTextImage.c in Sources */,
				F966BE2C08F27A40005CB29B /* tkTextIndex.c in Sources */,
				F966BE2D08F27A40005CB29B /* tkTextMark.c in Sources */,
				F966BE2E08F27A40005CB29B /* tkTextTag.c in Sources */,
				F966BE2F08F27A40005CB29B /* tkTextWind.c in Sources */,
				F966BE3008F27A40005CB29B /* tkTrig.c in Sources */,
				F966BE3108F27A40005CB29B /* tkUndo.c in Sources */,
				F966BE3308F27A40005CB29B /* tkUtil.c in Sources */,
				F966BE3408F27A40005CB29B /* tkVisual.c in Sources */,
				F966BE3508F27A40005CB29B /* tkWindow.c in Sources */,
				F96888050AF786D5000797B5 /* ttkBlink.c in Sources */,
				F96888060AF786D5000797B5 /* ttkButton.c in Sources */,
				F96888070AF786D5000797B5 /* ttkCache.c in Sources */,
				F96888080AF786D5000797B5 /* ttkClamTheme.c in Sources */,
				F96888090AF786D5000797B5 /* ttkClassicTheme.c in Sources */,
				F968880A0AF786D5000797B5 /* ttkDefaultTheme.c in Sources */,
				F968880B0AF786D5000797B5 /* ttkElements.c in Sources */,
				F968880C0AF786D5000797B5 /* ttkEntry.c in Sources */,
				F968880D0AF786D5000797B5 /* ttkFrame.c in Sources */,
				F968880E0AF786D5000797B5 /* ttkImage.c in Sources */,
				F968880F0AF786D5000797B5 /* ttkInit.c in Sources */,
				F96888100AF786D5000797B5 /* ttkLabel.c in Sources */,
				F96888110AF786D5000797B5 /* ttkLayout.c in Sources */,
				F96888120AF786D5000797B5 /* ttkManager.c in Sources */,
				F96888130AF786D5000797B5 /* ttkNotebook.c in Sources */,
				F96888140AF786D5000797B5 /* ttkPanedwindow.c in Sources */,
				F96888150AF786D5000797B5 /* ttkProgress.c in Sources */,
				F96888160AF786D5000797B5 /* ttkScale.c in Sources */,
				F96888170AF786D5000797B5 /* ttkScroll.c in Sources */,
				F96888180AF786D5000797B5 /* ttkScrollbar.c in Sources */,
				F96888190AF786D5000797B5 /* ttkSeparator.c in Sources */,
				F968881A0AF786D5000797B5 /* ttkSquare.c in Sources */,
				F968881B0AF786D5000797B5 /* ttkState.c in Sources */,
				F968881C0AF786D5000797B5 /* ttkStubInit.c in Sources */,
				F968881D0AF786D5000797B5 /* ttkStubLib.c in Sources */,
				F968881E0AF786D5000797B5 /* ttkTagSet.c in Sources */,
				F968881F0AF786D5000797B5 /* ttkTheme.c in Sources */,
				F96888200AF786D5000797B5 /* ttkTrace.c in Sources */,
				F96888210AF786D5000797B5 /* ttkTrack.c in Sources */,
				F96888220AF786D5000797B5 /* ttkTreeview.c in Sources */,
				F96888230AF786D5000797B5 /* ttkWidget.c in Sources */,
				F966BEDB08F27A40005CB29B /* tkMacOSXBitmap.c in Sources */,
				F966BEDC08F27A40005CB29B /* tkMacOSXButton.c in Sources */,
				F966BEDE08F27A40005CB29B /* tkMacOSXClipboard.c in Sources */,
				F966BEDF08F27A40005CB29B /* tkMacOSXColor.c in Sources */,
				F966BEE008F27A40005CB29B /* tkMacOSXConfig.c in Sources */,
				F966BEE108F27A40005CB29B /* tkMacOSXCursor.c in Sources */,
				F966BEE308F27A40005CB29B /* tkMacOSXDebug.c in Sources */,
				F966BEE608F27A40005CB29B /* tkMacOSXDialog.c in Sources */,
				F966BEE708F27A40005CB29B /* tkMacOSXDraw.c in Sources */,
				F966BEE808F27A40005CB29B /* tkMacOSXEmbed.c in Sources */,
				F966BEE908F27A40005CB29B /* tkMacOSXEntry.c in Sources */,
				F966BEEA08F27A40005CB29B /* tkMacOSXEvent.c in Sources */,
				F966BEEC08F27A40005CB29B /* tkMacOSXFont.c in Sources */,
				F966BEED08F27A40005CB29B /* tkMacOSXHLEvents.c in Sources */,
				F966BEEE08F27A40005CB29B /* tkMacOSXInit.c in Sources */,
				F966BEF108F27A40005CB29B /* tkMacOSXKeyboard.c in Sources */,
				F966BEF208F27A40005CB29B /* tkMacOSXKeyEvent.c in Sources */,
				F966BEF308F27A40005CB29B /* tkMacOSXMenu.c in Sources */,
				F966BEF608F27A40005CB29B /* tkMacOSXMenubutton.c in Sources */,
				F966BEF708F27A40005CB29B /* tkMacOSXMenus.c in Sources */,
				F966BEF808F27A40005CB29B /* tkMacOSXMouseEvent.c in Sources */,
				F966BEF908F27A40005CB29B /* tkMacOSXNotify.c in Sources */,
				F966BF0108F27A40005CB29B /* tkMacOSXRegion.c in Sources */,
				F966BF0308F27A40005CB29B /* tkMacOSXScrlbr.c in Sources */,
				F966BF0408F27A40005CB29B /* tkMacOSXSend.c in Sources */,
				F966BF0508F27A40005CB29B /* tkMacOSXSubwindows.c in Sources */,
				F966BF0608F27A40005CB29B /* tkMacOSXTest.c in Sources */,
				F966BF0708F27A40005CB29B /* tkMacOSXWindowEvent.c in Sources */,
				F966BF0808F27A40005CB29B /* tkMacOSXWm.c in Sources */,
				F966BF0B08F27A40005CB29B /* tkMacOSXXStubs.c in Sources */,
				F96888850AF78938000797B5 /* ttkMacOSXTheme.c in Sources */,
				F966BF7F08F27A41005CB29B /* tkAppInit.c in Sources */,
				F966BF8308F27A41005CB29B /* tkUnix3d.c in Sources */,
				F966BF9608F27A41005CB29B /* tkUnixScale.c in Sources */,
				F966C02A08F27A42005CB29B /* xcolors.c in Sources */,
				F966C02B08F27A42005CB29B /* xdraw.c in Sources */,
				F966C02C08F27A42005CB29B /* xgc.c in Sources */,
				F966C02D08F27A42005CB29B /* ximage.c in Sources */,
				F966C02E08F27A42005CB29B /* xutil.c in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		F9FD30BB0CC1AD070073837D /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				F9FD30BC0CC1AD070073837D /* regcomp.c in Sources */,
				F9FD30BD0CC1AD070073837D /* regerror.c in Sources */,
				F9FD30BE0CC1AD070073837D /* regexec.c in Sources */,
				F9FD30BF0CC1AD070073837D /* regfree.c in Sources */,
				F9FD30C00CC1AD070073837D /* tclAlloc.c in Sources */,
				F9FD30C10CC1AD070073837D /* tclAsync.c in Sources */,
				F9FD30C20CC1AD070073837D /* tclBasic.c in Sources */,
				F9FD30C30CC1AD070073837D /* tclBinary.c in Sources */,
				F9FD30C40CC1AD070073837D /* tclCkalloc.c in Sources */,
				F9FD30C50CC1AD070073837D /* tclClock.c in Sources */,
				F9FD30C60CC1AD070073837D /* tclCmdAH.c in Sources */,
				F9FD30C70CC1AD070073837D /* tclCmdIL.c in Sources */,
				F9FD30C80CC1AD070073837D /* tclCmdMZ.c in Sources */,
				F9FD30C90CC1AD070073837D /* tclCompCmds.c in Sources */,
				F9FD30CA0CC1AD070073837D /* tclCompExpr.c in Sources */,
				F9FD30CB0CC1AD070073837D /* tclCompile.c in Sources */,
				F9FD30CC0CC1AD070073837D /* tclConfig.c in Sources */,
				F9FD30CD0CC1AD070073837D /* tclDate.c in Sources */,
				F9FD30CE0CC1AD070073837D /* tclDictObj.c in Sources */,
				F9FD30CF0CC1AD070073837D /* tclEncoding.c in Sources */,
				F9FD30D00CC1AD070073837D /* tclEnv.c in Sources */,
				F9FD30D10CC1AD070073837D /* tclEvent.c in Sources */,
				F9FD30D20CC1AD070073837D /* tclExecute.c in Sources */,
				F9FD30D30CC1AD070073837D /* tclFCmd.c in Sources */,
				F9FD30D40CC1AD070073837D /* tclFileName.c in Sources */,
				F9FD30D50CC1AD070073837D /* tclGet.c in Sources */,
				F9FD30D60CC1AD070073837D /* tclHash.c in Sources */,
				F9FD30D70CC1AD070073837D /* tclHistory.c in Sources */,
				F9FD30D80CC1AD070073837D /* tclIndexObj.c in Sources */,
				F9FD30D90CC1AD070073837D /* tclInterp.c in Sources */,
				F9FD30DA0CC1AD070073837D /* tclIO.c in Sources */,
				F9FD30DB0CC1AD070073837D /* tclIOCmd.c in Sources */,
				F9FD30DC0CC1AD070073837D /* tclIOGT.c in Sources */,
				F9FD30DD0CC1AD070073837D /* tclIORChan.c in Sources */,
				F9FFAF1D0DFDDB26007F8A6A /* tclIORTrans.c in Sources */,
				F9FD30DE0CC1AD070073837D /* tclIOSock.c in Sources */,
				F9FD30DF0CC1AD070073837D /* tclIOUtil.c in Sources */,
				F9FD30E00CC1AD070073837D /* tclLink.c in Sources */,
				F9FD30E10CC1AD070073837D /* tclListObj.c in Sources */,
				F9FD30E20CC1AD070073837D /* tclLiteral.c in Sources */,
				F9FD30E30CC1AD070073837D /* tclLoad.c in Sources */,
				F9FD30E40CC1AD070073837D /* tclMain.c in Sources */,
				F9FD30E50CC1AD070073837D /* tclNamesp.c in Sources */,
				F9FD30E60CC1AD070073837D /* tclNotify.c in Sources */,
				F9FD30E70CC1AD070073837D /* tclObj.c in Sources */,
				F9FFAF1F0DFDDB2F007F8A6A /* tclOO.c in Sources */,
				F9FFAF200DFDDB32007F8A6A /* tclOOBasic.c in Sources */,
				F9FFAF210DFDDB32007F8A6A /* tclOOCall.c in Sources */,
				F9FFAF220DFDDB34007F8A6A /* tclOODefineCmds.c in Sources */,
				F9FFAF230DFDDB35007F8A6A /* tclOOInfo.c in Sources */,
				F9FFAF240DFDDB36007F8A6A /* tclOOMethod.c in Sources */,
				F9FFAF250DFDDB37007F8A6A /* tclOOStubInit.c in Sources */,
				F9FFAF260DFDDB38007F8A6A /* tclOOStubLib.c in Sources */,
				F9FD30E80CC1AD070073837D /* tclPanic.c in Sources */,
				F9FD30E90CC1AD070073837D /* tclParse.c in Sources */,
				F9FD30EA0CC1AD070073837D /* tclPathObj.c in Sources */,
				F9FD30EB0CC1AD070073837D /* tclPipe.c in Sources */,
				F9FD30EC0CC1AD070073837D /* tclPkg.c in Sources */,
				F9FD30ED0CC1AD070073837D /* tclPkgConfig.c in Sources */,
				F9FD30EE0CC1AD070073837D /* tclPosixStr.c in Sources */,
				F9FD30EF0CC1AD070073837D /* tclPreserve.c in Sources */,
				F9FD30F00CC1AD070073837D /* tclProc.c in Sources */,
				F9FD30F10CC1AD070073837D /* tclRegexp.c in Sources */,
				F9FD30F20CC1AD070073837D /* tclResolve.c in Sources */,
				F9FD30F30CC1AD070073837D /* tclResult.c in Sources */,
				F9FD30F40CC1AD070073837D /* tclScan.c in Sources */,
				F9FD30F50CC1AD070073837D /* tclStringObj.c in Sources */,
				F9FD30F60CC1AD070073837D /* tclStrToD.c in Sources */,
				F9FD30F70CC1AD070073837D /* tclStubInit.c in Sources */,
				F9FD30F80CC1AD070073837D /* tclStubLib.c in Sources */,
				F9FD30F90CC1AD070073837D /* tclThread.c in Sources */,
				F9FD30FA0CC1AD070073837D /* tclThreadAlloc.c in Sources */,
				F9FD30FB0CC1AD070073837D /* tclThreadJoin.c in Sources */,
				F9FD30FC0CC1AD070073837D /* tclThreadStorage.c in Sources */,
				F9FD30FD0CC1AD070073837D /* tclTimer.c in Sources */,
				F9FD30FE0CC1AD070073837D /* tclTomMathInterface.c in Sources */,
				F9FD30FF0CC1AD070073837D /* tclTrace.c in Sources */,
				F9FD31000CC1AD070073837D /* tclUtf.c in Sources */,
				F9FD31010CC1AD070073837D /* tclUtil.c in Sources */,
				F9FD31020CC1AD070073837D /* tclVar.c in Sources */,
				F96437CB0EF0D4B2003F468E /* tclZlib.c in Sources */,
				F9FD31030CC1AD070073837D /* bn_fast_s_mp_mul_digs.c in Sources */,
				F9FD31040CC1AD070073837D /* bn_fast_s_mp_sqr.c in Sources */,
				F9FD31050CC1AD070073837D /* bn_mp_add.c in Sources */,
				F9FD31060CC1AD070073837D /* bn_mp_add_d.c in Sources */,
				F9FD31070CC1AD070073837D /* bn_mp_and.c in Sources */,
				F9FD31080CC1AD070073837D /* bn_mp_clamp.c in Sources */,
				F9FD31090CC1AD070073837D /* bn_mp_clear.c in Sources */,
				F9FD310A0CC1AD070073837D /* bn_mp_clear_multi.c in Sources */,
				F9FD310B0CC1AD070073837D /* bn_mp_cmp.c in Sources */,
				F9FD310C0CC1AD070073837D /* bn_mp_cmp_d.c in Sources */,
				F9FD310D0CC1AD070073837D /* bn_mp_cmp_mag.c in Sources */,
				F9FD310E0CC1AD070073837D /* bn_mp_copy.c in Sources */,
				F9FD310F0CC1AD070073837D /* bn_mp_count_bits.c in Sources */,
				F9FD31100CC1AD070073837D /* bn_mp_div.c in Sources */,
				F9FD31110CC1AD070073837D /* bn_mp_div_2.c in Sources */,
				F9FD31120CC1AD070073837D /* bn_mp_div_2d.c in Sources */,
				F9FD31130CC1AD070073837D /* bn_mp_div_3.c in Sources */,
				F9FD31140CC1AD070073837D /* bn_mp_div_d.c in Sources */,
				F9FD31150CC1AD070073837D /* bn_mp_exch.c in Sources */,
				F9FD31160CC1AD070073837D /* bn_mp_expt_d.c in Sources */,
				F9FD31170CC1AD070073837D /* bn_mp_grow.c in Sources */,
				F9FD31180CC1AD070073837D /* bn_mp_init.c in Sources */,
				F9FD31190CC1AD070073837D /* bn_mp_init_copy.c in Sources */,
				F9FD311A0CC1AD070073837D /* bn_mp_init_multi.c in Sources */,
				F9FD311B0CC1AD070073837D /* bn_mp_init_set.c in Sources */,
				F9FD311C0CC1AD070073837D /* bn_mp_init_size.c in Sources */,
				F9FD311D0CC1AD070073837D /* bn_mp_karatsuba_mul.c in Sources */,
				F9FD311E0CC1AD070073837D /* bn_mp_karatsuba_sqr.c in Sources */,
				F9FD311F0CC1AD070073837D /* bn_mp_lshd.c in Sources */,
				F9FD31200CC1AD070073837D /* bn_mp_mod.c in Sources */,
				F9FD31210CC1AD070073837D /* bn_mp_mod_2d.c in Sources */,
				F9FD31220CC1AD070073837D /* bn_mp_mul.c in Sources */,
				F9FD31230CC1AD070073837D /* bn_mp_mul_2.c in Sources */,
				F9FD31240CC1AD070073837D /* bn_mp_mul_2d.c in Sources */,
				F9FD31250CC1AD070073837D /* bn_mp_mul_d.c in Sources */,
				F9FD31260CC1AD070073837D /* bn_mp_neg.c in Sources */,
				F9FD31270CC1AD070073837D /* bn_mp_or.c in Sources */,
				F9FD31280CC1AD070073837D /* bn_mp_radix_size.c in Sources */,
				F9FD31290CC1AD070073837D /* bn_mp_radix_smap.c in Sources */,
				F9FD312A0CC1AD070073837D /* bn_mp_read_radix.c in Sources */,
				F9FD312B0CC1AD070073837D /* bn_mp_rshd.c in Sources */,
				F9FD312C0CC1AD070073837D /* bn_mp_set.c in Sources */,
				F9FD312D0CC1AD070073837D /* bn_mp_shrink.c in Sources */,
				F9FD312E0CC1AD070073837D /* bn_mp_sqr.c in Sources */,
				F9FD312F0CC1AD070073837D /* bn_mp_sqrt.c in Sources */,
				F9FD31300CC1AD070073837D /* bn_mp_sub.c in Sources */,
				F9FD31310CC1AD070073837D /* bn_mp_sub_d.c in Sources */,
				F9FD31320CC1AD070073837D /* bn_mp_to_unsigned_bin_n.c in Sources */,
				F9FD31330CC1AD070073837D /* bn_mp_to_unsigned_bin.c in Sources */,
				F9FD31340CC1AD070073837D /* bn_mp_toom_mul.c in Sources */,
				F9FD31350CC1AD070073837D /* bn_mp_toom_sqr.c in Sources */,
				F9FD31360CC1AD070073837D /* bn_mp_toradix_n.c in Sources */,
				F9FD31370CC1AD070073837D /* bn_mp_unsigned_bin_size.c in Sources */,
				F9FD31380CC1AD070073837D /* bn_mp_xor.c in Sources */,
				F9FD31390CC1AD070073837D /* bn_mp_zero.c in Sources */,
				F9FD313A0CC1AD070073837D /* bn_reverse.c in Sources */,
				F9FD313B0CC1AD070073837D /* bn_s_mp_add.c in Sources */,
				F9FD313C0CC1AD070073837D /* bn_s_mp_mul_digs.c in Sources */,
				F9FD313D0CC1AD070073837D /* bn_s_mp_sqr.c in Sources */,
				F9FD313E0CC1AD070073837D /* bn_s_mp_sub.c in Sources */,
				F9FD313F0CC1AD070073837D /* bncore.c in Sources */,
				F9FD31400CC1AD070073837D /* tclMacOSXBundle.c in Sources */,
				F9FD31410CC1AD070073837D /* tclMacOSXFCmd.c in Sources */,
				F9FD31420CC1AD070073837D /* tclMacOSXNotify.c in Sources */,
				F9FD31430CC1AD070073837D /* tclLoadDyld.c in Sources */,
				F9FD31440CC1AD070073837D /* tclUnixChan.c in Sources */,
				F9FD31450CC1AD070073837D /* tclUnixCompat.c in Sources */,
				F9FD31460CC1AD070073837D /* tclUnixEvent.c in Sources */,
				F9FD31470CC1AD070073837D /* tclUnixFCmd.c in Sources */,
				F9FD31480CC1AD070073837D /* tclUnixFile.c in Sources */,
				F9FD31490CC1AD070073837D /* tclUnixInit.c in Sources */,
				F9FD314A0CC1AD070073837D /* tclUnixNotfy.c in Sources */,
				F9FD314B0CC1AD070073837D /* tclUnixPipe.c in Sources */,
				F9FD314C0CC1AD070073837D /* tclUnixSock.c in Sources */,
				F9FD314D0CC1AD070073837D /* tclUnixThrd.c in Sources */,
				F9FD314E0CC1AD070073837D /* tclUnixTime.c in Sources */,
				F9FD31E20CC1AD070073837D /* tclDTrace.d in Sources */,
				F9FD314F0CC1AD070073837D /* tk3d.c in Sources */,
				F9FD31500CC1AD070073837D /* tkArgv.c in Sources */,
				F9FD31510CC1AD070073837D /* tkAtom.c in Sources */,
				F9FD31520CC1AD070073837D /* tkBind.c in Sources */,
				F9FD31530CC1AD070073837D /* tkBitmap.c in Sources */,
				F9152B0A0EAF8A5700CD5C7B /* tkBusy.c in Sources */,
				F9FD31540CC1AD070073837D /* tkButton.c in Sources */,
				F9FD31550CC1AD070073837D /* tkCanvArc.c in Sources */,
				F9FD31560CC1AD070073837D /* tkCanvas.c in Sources */,
				F9FD31570CC1AD070073837D /* tkCanvBmap.c in Sources */,
				F9FD31580CC1AD070073837D /* tkCanvImg.c in Sources */,
				F9FD31590CC1AD070073837D /* tkCanvLine.c in Sources */,
				F9FD315A0CC1AD070073837D /* tkCanvPoly.c in Sources */,
				F9FD315B0CC1AD070073837D /* tkCanvPs.c in Sources */,
				F9FD315C0CC1AD070073837D /* tkCanvText.c in Sources */,
				F9FD315D0CC1AD070073837D /* tkCanvUtil.c in Sources */,
				F9FD315E0CC1AD070073837D /* tkCanvWind.c in Sources */,
				F9FD315F0CC1AD070073837D /* tkClipboard.c in Sources */,
				F9FD31600CC1AD070073837D /* tkCmds.c in Sources */,
				F9FD31610CC1AD070073837D /* tkColor.c in Sources */,
				F9FD31620CC1AD070073837D /* tkConfig.c in Sources */,
				F9FD31630CC1AD070073837D /* tkConsole.c in Sources */,
				F9FD31640CC1AD070073837D /* tkCursor.c in Sources */,
				F9FD31650CC1AD070073837D /* tkEntry.c in Sources */,
				F9FD31660CC1AD070073837D /* tkError.c in Sources */,
				F9FD31670CC1AD070073837D /* tkEvent.c in Sources */,
				F9FD31680CC1AD070073837D /* tkFileFilter.c in Sources */,
				F9FD31690CC1AD070073837D /* tkFocus.c in Sources */,
				F9FD316A0CC1AD070073837D /* tkFont.c in Sources */,
				F9FD316B0CC1AD070073837D /* tkFrame.c in Sources */,
				F9FD316C0CC1AD070073837D /* tkGC.c in Sources */,
				F9FD316D0CC1AD070073837D /* tkGeometry.c in Sources */,
				F9FD316E0CC1AD070073837D /* tkGet.c in Sources */,
				F9FD316F0CC1AD070073837D /* tkGrab.c in Sources */,
				F9FD31700CC1AD070073837D /* tkGrid.c in Sources */,
				F9FD31710CC1AD070073837D /* tkImage.c in Sources */,
				F9FD31720CC1AD070073837D /* tkImgBmap.c in Sources */,
				F9FD31730CC1AD070073837D /* tkImgGIF.c in Sources */,
				F92EE8D30E62F939001A6E80 /* tkImgPhInstance.c in Sources */,
				F9FD31740CC1AD070073837D /* tkImgPhoto.c in Sources */,
				F9DD99BE0F07DF850018B2E4 /* tkImgPNG.c in Sources */,
				F9FD31750CC1AD070073837D /* tkImgPPM.c in Sources */,
				F9FD31760CC1AD070073837D /* tkListbox.c in Sources */,
				F9FD31770CC1AD070073837D /* tkMacWinMenu.c in Sources */,
				F9FD31780CC1AD070073837D /* tkMain.c in Sources */,
				F9FD31790CC1AD070073837D /* tkMenu.c in Sources */,
				F9FD317A0CC1AD070073837D /* tkMenubutton.c in Sources */,
				F9FD317B0CC1AD070073837D /* tkMenuDraw.c in Sources */,
				F9FD317C0CC1AD070073837D /* tkMessage.c in Sources */,
				F9FD317D0CC1AD070073837D /* tkObj.c in Sources */,
				F9FD317E0CC1AD070073837D /* tkOldConfig.c in Sources */,
				F9FD317F0CC1AD070073837D /* tkOldTest.c in Sources */,
				F9FD31800CC1AD070073837D /* tkOption.c in Sources */,
				F9FD31810CC1AD070073837D /* tkPack.c in Sources */,
				F9FD31820CC1AD070073837D /* tkPanedWindow.c in Sources */,
				F9FD31830CC1AD070073837D /* tkPlace.c in Sources */,
				F9FD31850CC1AD070073837D /* tkRectOval.c in Sources */,
				F9FD31860CC1AD070073837D /* tkScale.c in Sources */,
				F9FD31870CC1AD070073837D /* tkScrollbar.c in Sources */,
				F9FD31880CC1AD070073837D /* tkSelect.c in Sources */,
				F9FD31890CC1AD070073837D /* tkSquare.c in Sources */,
				F9FD318A0CC1AD070073837D /* tkStubInit.c in Sources */,
				F9FD318B0CC1AD070073837D /* tkStubLib.c in Sources */,
				F9FD318C0CC1AD070073837D /* tkStyle.c in Sources */,
				F9FD318D0CC1AD070073837D /* tkTest.c in Sources */,
				F9FD318E0CC1AD070073837D /* tkText.c in Sources */,
				F9FD318F0CC1AD070073837D /* tkTextBTree.c in Sources */,
				F9FD31900CC1AD070073837D /* tkTextDisp.c in Sources */,
				F9FD31910CC1AD070073837D /* tkTextImage.c in Sources */,
				F9FD31920CC1AD070073837D /* tkTextIndex.c in Sources */,
				F9FD31930CC1AD070073837D /* tkTextMark.c in Sources */,
				F9FD31940CC1AD070073837D /* tkTextTag.c in Sources */,
				F9FD31950CC1AD070073837D /* tkTextWind.c in Sources */,
				F9FD31960CC1AD070073837D /* tkTrig.c in Sources */,
				F9FD31970CC1AD070073837D /* tkUndo.c in Sources */,
				F9FD31980CC1AD070073837D /* tkUtil.c in Sources */,
				F9FD31990CC1AD070073837D /* tkVisual.c in Sources */,
				F9FD319A0CC1AD070073837D /* tkWindow.c in Sources */,
				F9FD319B0CC1AD070073837D /* ttkBlink.c in Sources */,
				F9FD319C0CC1AD070073837D /* ttkButton.c in Sources */,
				F9FD319D0CC1AD070073837D /* ttkCache.c in Sources */,
				F9FD319E0CC1AD070073837D /* ttkClamTheme.c in Sources */,
				F9FD319F0CC1AD070073837D /* ttkClassicTheme.c in Sources */,
				F9FD31A00CC1AD070073837D /* ttkDefaultTheme.c in Sources */,
				F9FD31A10CC1AD070073837D /* ttkElements.c in Sources */,
				F9FD31A20CC1AD070073837D /* ttkEntry.c in Sources */,
				F9FD31A30CC1AD070073837D /* ttkFrame.c in Sources */,
				F9FD31A40CC1AD070073837D /* ttkImage.c in Sources */,
				F9FD31A50CC1AD070073837D /* ttkInit.c in Sources */,
				F9FD31A60CC1AD070073837D /* ttkLabel.c in Sources */,
				F9FD31A70CC1AD070073837D /* ttkLayout.c in Sources */,
				F9FD31A80CC1AD070073837D /* ttkManager.c in Sources */,
				F9FD31A90CC1AD070073837D /* ttkNotebook.c in Sources */,
				F9FD31AA0CC1AD070073837D /* ttkPanedwindow.c in Sources */,
				F9FD31AB0CC1AD070073837D /* ttkProgress.c in Sources */,
				F9FD31AC0CC1AD070073837D /* ttkScale.c in Sources */,
				F9FD31AD0CC1AD070073837D /* ttkScroll.c in Sources */,
				F9FD31AE0CC1AD070073837D /* ttkScrollbar.c in Sources */,
				F9FD31AF0CC1AD070073837D /* ttkSeparator.c in Sources */,
				F9FD31B00CC1AD070073837D /* ttkSquare.c in Sources */,
				F9FD31B10CC1AD070073837D /* ttkState.c in Sources */,
				F9FD31B20CC1AD070073837D /* ttkStubInit.c in Sources */,
				F9FD31B30CC1AD070073837D /* ttkStubLib.c in Sources */,
				F9FD31B40CC1AD070073837D /* ttkTagSet.c in Sources */,
				F9FD31B50CC1AD070073837D /* ttkTheme.c in Sources */,
				F9FD31B60CC1AD070073837D /* ttkTrace.c in Sources */,
				F9FD31B70CC1AD070073837D /* ttkTrack.c in Sources */,
				F9FD31B80CC1AD070073837D /* ttkTreeview.c in Sources */,
				F9FD31B90CC1AD070073837D /* ttkWidget.c in Sources */,
				F9FD31DA0CC1AD070073837D /* tkAppInit.c in Sources */,
				F9FD32020CC1ADB70073837D /* tkUnix.c in Sources */,
				F9FD31DB0CC1AD070073837D /* tkUnix3d.c in Sources */,
				F9FD320A0CC1ADB70073837D /* tkUnixButton.c in Sources */,
				F9FD32090CC1ADB70073837D /* tkUnixColor.c in Sources */,
				F9FD32040CC1ADB70073837D /* tkUnixConfig.c in Sources */,
				F9FD31F80CC1ADB70073837D /* tkUnixCursor.c in Sources */,
				F9FD32060CC1ADB70073837D /* tkUnixDialog.c in Sources */,
				F9FD32050CC1ADB70073837D /* tkUnixDraw.c in Sources */,
				F9FD31FD0CC1ADB70073837D /* tkUnixEmbed.c in Sources */,
				F9FD32080CC1ADB70073837D /* tkUnixEvent.c in Sources */,
				F9FD31FF0CC1ADB70073837D /* tkUnixFocus.c in Sources */,
				F9FD31FC0CC1ADB70073837D /* tkUnixInit.c in Sources */,
				F9FD31FA0CC1ADB70073837D /* tkUnixKey.c in Sources */,
				F9FD32030CC1ADB70073837D /* tkUnixMenu.c in Sources */,
				F9FD320B0CC1ADB70073837D /* tkUnixMenubu.c in Sources */,
				F9FD32010CC1ADB70073837D /* tkUnixRFont.c in Sources */,
				F9FD31DC0CC1AD070073837D /* tkUnixScale.c in Sources */,
				F9FD320C0CC1ADB70073837D /* tkUnixScrlbr.c in Sources */,
				F9FD32070CC1ADB70073837D /* tkUnixSelect.c in Sources */,
				F9FD31FE0CC1ADB70073837D /* tkUnixSend.c in Sources */,
				F9FD32000CC1ADB70073837D /* tkUnixWm.c in Sources */,
				F9FD31FB0CC1ADB70073837D /* tkUnixXId.c in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
		F90E36D50F3B5C8400810A10 /* DebugNoGC */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = unsupported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugNoGC;
		};
		F90E36D60F3B5C8400810A10 /* DebugNoGC */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugNoGC;
		};
		F90E36D70F3B5C8400810A10 /* DebugNoGC */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugNoGC;
		};
		F90E36D80F3B5C8400810A10 /* DebugNoGC */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoGC;
		};
		F91BCC4F093152310042A6BF /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = ReleaseUniversal;
		};
		F91BCC50093152310042A6BF /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = ReleaseUniversal;
		};
		F91BCC51093152310042A6BF /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
			};
			name = ReleaseUniversal;
		};
		F93084370BB93D2800CD0B9E /* DebugMemCompile */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugMemCompile;
		};
		F93084380BB93D2800CD0B9E /* DebugMemCompile */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugMemCompile;
		};
		F93084390BB93D2800CD0B9E /* DebugMemCompile */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugMemCompile;
		};
		F930843A0BB93D2800CD0B9E /* DebugMemCompile */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-symbols=all";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugMemCompile;
		};
		F9359B250DF212DA00E04F67 /* DebugGCov */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_GENERATE_TEST_COVERAGE_FILES = YES;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS)",
					"-lgcov",
				);
				PREBINDING = NO;
			};
			name = DebugGCov;
		};
		F9359B260DF212DA00E04F67 /* DebugGCov */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugGCov;
		};
		F9359B270DF212DA00E04F67 /* DebugGCov */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugGCov;
		};
		F9359B280DF212DA00E04F67 /* DebugGCov */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugGCov;
		};
		F95CC8AC09158F3100EA5ACE /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = Debug;
		};
		F95CC8AD09158F3100EA5ACE /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = Release;
		};
		F95CC8AE09158F3100EA5ACE /* DebugNoFixAndContinue */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugNoFixAndContinue;
		};
		F95CC8B109158F3100EA5ACE /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = Debug;
		};
		F95CC8B209158F3100EA5ACE /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = Release;
		};
		F95CC8B309158F3100EA5ACE /* DebugNoFixAndContinue */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugNoFixAndContinue;
		};
		F95CC8B609158F3100EA5ACE /* Debug */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = Debug;
		};
		F95CC8B709158F3100EA5ACE /* Release */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = Release;
		};
		F95CC8B809158F3100EA5ACE /* DebugNoFixAndContinue */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugNoFixAndContinue;
		};
		F97258A90A86873D00096C78 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = Debug;
		};
		F97258AA0A86873D00096C78 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = Release;
		};
		F97258AB0A86873D00096C78 /* DebugNoFixAndContinue */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoFixAndContinue;
		};
		F97258AC0A86873D00096C78 /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = ReleaseUniversal;
		};
		F97AED1B0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = Debug64bit;
		};
		F97AED1C0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = Debug64bit;
		};
		F97AED1D0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = Debug64bit;
		};
		F97AED1E0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = "$(NATIVE_ARCH_64_BIT)";
				CONFIGURE_ARGS = "--enable-64bit $(CONFIGURE_ARGS)";
				CPPFLAGS = "-arch $(NATIVE_ARCH_64_BIT) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
			};
			name = Debug64bit;
		};
		F987512F0DE7B57E00B1C9EC /* DebugNoCF */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --disable-corefoundation";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugNoCF;
		};
		F98751300DE7B57E00B1C9EC /* DebugNoCF */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugNoCF;
		};
		F98751310DE7B57E00B1C9EC /* DebugNoCF */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugNoCF;
		};
		F98751320DE7B57E00B1C9EC /* DebugNoCF */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoCF;
		};
		F98751330DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --disable-threads --disable-corefoundation";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751340DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751350DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751360DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoCFUnthreaded;
		};
		F9988AB10D814C6500B6B03B /* Debug gcc40 */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_VERSION = 4.0;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = "Debug gcc40";
		};
		F9988AB20D814C6500B6B03B /* Debug gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = "Debug gcc40";
		};
		F9988AB30D814C6500B6B03B /* Debug gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = "Debug gcc40";
		};
		F9988AB40D814C6500B6B03B /* Debug gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "Debug gcc40";
		};
		F9988AB50D814C7500B6B03B /* Debug llvm-gcc */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC = "llvm-gcc";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_VERSION = com.apple.compilers.llvmgcc42;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = "Debug llvm-gcc";
		};
		F9988AB60D814C7500B6B03B /* Debug llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = "Debug llvm-gcc";
		};
		F9988AB70D814C7500B6B03B /* Debug llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = "Debug llvm-gcc";
		};
		F9988AB80D814C7500B6B03B /* Debug llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "tcl_cv_cc_visibility_hidden=no $(CONFIGURE_ARGS)";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"__private_extern__=extern",
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "Debug llvm-gcc";
		};
		F9988BB10D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_VERSION = 4.0;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB20D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB30D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB40D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB50D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				DEBUG_INFORMATION_FORMAT = dwarf;
				GCC = "llvm-gcc";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_OPTIMIZATION_LEVEL = 4;
				GCC_VERSION = com.apple.compilers.llvmgcc42;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F9988BB60D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F9988BB70D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F9988BB80D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F99EE73B0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugUnthreaded;
		};
		F99EE73C0BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugLeaks;
		};
		F99EE73D0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugUnthreaded;
		};
		F99EE73E0BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugLeaks;
		};
		F99EE73F0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugUnthreaded;
		};
		F99EE7400BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugLeaks;
		};
		F99EE7410BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --disable-threads";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugUnthreaded;
		};
		F99EE7420BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = unsupported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_PREPROCESSOR_DEFINITIONS = (
					PURIFY,
					"$(GCC_PREPROCESSOR_DEFINITIONS)",
				);
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugLeaks;
		};
		F9EEED960C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = ReleaseUniversal10.5SDK;
		};
		F9EEED970C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = ReleaseUniversal10.5SDK;
		};
		F9EEED980C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = ReleaseUniversal10.5SDK;
		};
		F9EEED990C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				CPPFLAGS = "-isysroot $(SDKROOT) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
				SDKROOT = macosx10.5;
			};
			name = ReleaseUniversal10.5SDK;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		F95CC8AB09158F3100EA5ACE /* Build configuration list for PBXNativeTarget "Tk" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F95CC8AC09158F3100EA5ACE /* Debug */,
				F9988AB60D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB20D814C6500B6B03B /* Debug gcc40 */,
				F90E36D60F3B5C8400810A10 /* DebugNoGC */,
				F95CC8AE09158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE73B0BE835310060D4AF /* DebugUnthreaded */,
				F98751300DE7B57E00B1C9EC /* DebugNoCF */,
				F98751340DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084370BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE73C0BE835310060D4AF /* DebugLeaks */,
				F9359B260DF212DA00E04F67 /* DebugGCov */,
				F97AED1B0B660B2100310EA2 /* Debug64bit */,
				F95CC8AD09158F3100EA5ACE /* Release */,
				F91BCC4F093152310042A6BF /* ReleaseUniversal */,
				F9988BB60D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB20D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED960C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F95CC8B009158F3100EA5ACE /* Build configuration list for PBXNativeTarget "tktest" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F95CC8B109158F3100EA5ACE /* Debug */,
				F9988AB70D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB30D814C6500B6B03B /* Debug gcc40 */,
				F90E36D70F3B5C8400810A10 /* DebugNoGC */,
				F95CC8B309158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE73D0BE835310060D4AF /* DebugUnthreaded */,
				F98751310DE7B57E00B1C9EC /* DebugNoCF */,
				F98751350DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084380BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE73E0BE835310060D4AF /* DebugLeaks */,
				F9359B270DF212DA00E04F67 /* DebugGCov */,
				F97AED1C0B660B2100310EA2 /* Debug64bit */,
				F95CC8B209158F3100EA5ACE /* Release */,
				F91BCC50093152310042A6BF /* ReleaseUniversal */,
				F9988BB70D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB30D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED970C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F95CC8B509158F3100EA5ACE /* Build configuration list for PBXProject "Tk" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F95CC8B609158F3100EA5ACE /* Debug */,
				F9988AB50D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB10D814C6500B6B03B /* Debug gcc40 */,
				F90E36D50F3B5C8400810A10 /* DebugNoGC */,
				F95CC8B809158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE7410BE835310060D4AF /* DebugUnthreaded */,
				F987512F0DE7B57E00B1C9EC /* DebugNoCF */,
				F98751330DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F930843A0BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE7420BE835310060D4AF /* DebugLeaks */,
				F9359B250DF212DA00E04F67 /* DebugGCov */,
				F97AED1E0B660B2100310EA2 /* Debug64bit */,
				F95CC8B709158F3100EA5ACE /* Release */,
				F91BCC51093152310042A6BF /* ReleaseUniversal */,
				F9988BB50D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB10D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED990C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F97258A80A86873D00096C78 /* Build configuration list for PBXNativeTarget "tktest-X11" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F97258A90A86873D00096C78 /* Debug */,
				F9988AB80D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB40D814C6500B6B03B /* Debug gcc40 */,
				F90E36D80F3B5C8400810A10 /* DebugNoGC */,
				F97258AB0A86873D00096C78 /* DebugNoFixAndContinue */,
				F99EE73F0BE835310060D4AF /* DebugUnthreaded */,
				F98751320DE7B57E00B1C9EC /* DebugNoCF */,
				F98751360DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084390BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE7400BE835310060D4AF /* DebugLeaks */,
				F9359B280DF212DA00E04F67 /* DebugGCov */,
				F97AED1D0B660B2100310EA2 /* Debug64bit */,
				F97258AA0A86873D00096C78 /* Release */,
				F97258AC0A86873D00096C78 /* ReleaseUniversal */,
				F9988BB80D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB40D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED980C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
/* End XCConfigurationList section */
	};
	rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}

Changes to macosx/Tk.xcodeproj/project.pbxproj.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17









+







// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 46;
	objects = {

/* Begin PBXBuildFile section */
		F9067BCD0BFBA2900074F726 /* tkOldTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFE08F27A39005CB29B /* tkOldTest.c */; };
		F9152B090EAF8A5000CD5C7B /* tkBusy.c in Sources */ = {isa = PBXBuildFile; fileRef = F9152B080EAF8A5000CD5C7B /* tkBusy.c */; };
		F9152B0A0EAF8A5700CD5C7B /* tkBusy.c in Sources */ = {isa = PBXBuildFile; fileRef = F9152B080EAF8A5000CD5C7B /* tkBusy.c */; };
		F92EE8BF0E62F846001A6E80 /* tkImgPhInstance.c in Sources */ = {isa = PBXBuildFile; fileRef = F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */; };
		F92EE8D30E62F939001A6E80 /* tkImgPhInstance.c in Sources */ = {isa = PBXBuildFile; fileRef = F92EE8BE0E62F846001A6E80 /* tkImgPhInstance.c */; };
		F93599B30DF1F75400E04F67 /* tclOO.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B20DF1F75400E04F67 /* tclOO.c */; };
		F93599B70DF1F76100E04F67 /* tclOOBasic.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B60DF1F76100E04F67 /* tclOOBasic.c */; };
		F93599B90DF1F76600E04F67 /* tclOOCall.c in Sources */ = {isa = PBXBuildFile; fileRef = F93599B80DF1F76600E04F67 /* tclOOCall.c */; };
515
516
517
518
519
520
521

522
523
524
525
526
527
528
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530







+







		F9FD31780CC1AD070073837D /* tkMain.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE608F27A39005CB29B /* tkMain.c */; };
		F9FD31790CC1AD070073837D /* tkMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE708F27A39005CB29B /* tkMenu.c */; };
		F9FD317A0CC1AD070073837D /* tkMenubutton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAE908F27A39005CB29B /* tkMenubutton.c */; };
		F9FD317B0CC1AD070073837D /* tkMenuDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEB08F27A39005CB29B /* tkMenuDraw.c */; };
		F9FD317C0CC1AD070073837D /* tkMessage.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEC08F27A39005CB29B /* tkMessage.c */; };
		F9FD317D0CC1AD070073837D /* tkObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAED08F27A39005CB29B /* tkObj.c */; };
		F9FD317E0CC1AD070073837D /* tkOldConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEE08F27A39005CB29B /* tkOldConfig.c */; };
		F9FD317F0CC1AD070073837D /* tkOldTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAFE08F27A39005CB29B /* tkOldTest.c */; };
		F9FD31800CC1AD070073837D /* tkOption.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAEF08F27A39005CB29B /* tkOption.c */; };
		F9FD31810CC1AD070073837D /* tkPack.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF008F27A39005CB29B /* tkPack.c */; };
		F9FD31820CC1AD070073837D /* tkPanedWindow.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF108F27A39005CB29B /* tkPanedWindow.c */; };
		F9FD31830CC1AD070073837D /* tkPlace.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF208F27A39005CB29B /* tkPlace.c */; };
		F9FD31850CC1AD070073837D /* tkRectOval.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF608F27A39005CB29B /* tkRectOval.c */; };
		F9FD31860CC1AD070073837D /* tkScale.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF708F27A39005CB29B /* tkScale.c */; };
		F9FD31870CC1AD070073837D /* tkScrollbar.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BAF908F27A39005CB29B /* tkScrollbar.c */; };
590
591
592
593
594
595
596

597
598
599
600
601
602
603
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606







+







		F9FD31FF0CC1ADB70073837D /* tkUnixFocus.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8308F27A3D005CB29B /* tkUnixFocus.c */; };
		F9FD32000CC1ADB70073837D /* tkUnixWm.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC9008F27A3D005CB29B /* tkUnixWm.c */; };
		F9FD32010CC1ADB70073837D /* tkUnixRFont.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8B08F27A3D005CB29B /* tkUnixRFont.c */; };
		F9FD32020CC1ADB70073837D /* tkUnix.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7808F27A3D005CB29B /* tkUnix.c */; };
		F9FD32030CC1ADB70073837D /* tkUnixMenu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8808F27A3D005CB29B /* tkUnixMenu.c */; };
		F9FD32040CC1ADB70073837D /* tkUnixConfig.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */; };
		F9FD32050CC1ADB70073837D /* tkUnixDraw.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8008F27A3D005CB29B /* tkUnixDraw.c */; };
		F9FD32060CC1ADB70073837D /* tkUnixDialog.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */; };
		F9FD32070CC1ADB70073837D /* tkUnixSelect.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8E08F27A3D005CB29B /* tkUnixSelect.c */; };
		F9FD32080CC1ADB70073837D /* tkUnixEvent.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8208F27A3D005CB29B /* tkUnixEvent.c */; };
		F9FD32090CC1ADB70073837D /* tkUnixColor.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7B08F27A3D005CB29B /* tkUnixColor.c */; };
		F9FD320A0CC1ADB70073837D /* tkUnixButton.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC7A08F27A3D005CB29B /* tkUnixButton.c */; };
		F9FD320B0CC1ADB70073837D /* tkUnixMenubu.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8908F27A3D005CB29B /* tkUnixMenubu.c */; };
		F9FD320C0CC1ADB70073837D /* tkUnixScrlbr.c in Sources */ = {isa = PBXBuildFile; fileRef = F966BC8D08F27A3D005CB29B /* tkUnixScrlbr.c */; };
		F9FD32170CC1AF170073837D /* libX11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F9FD32140CC1AF170073837D /* libX11.dylib */; };
678
679
680
681
682
683
684

685

686
687
688
689
690
691
692
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696







+
-
+







		F966BA0708F27A37005CB29B /* gray50.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray50.xbm; sourceTree = "<group>"; };
		F966BA0808F27A37005CB29B /* gray75.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = gray75.xbm; sourceTree = "<group>"; };
		F966BA0908F27A37005CB29B /* hourglass.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = hourglass.xbm; sourceTree = "<group>"; };
		F966BA0A08F27A37005CB29B /* info.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = info.xbm; sourceTree = "<group>"; };
		F966BA0B08F27A37005CB29B /* questhead.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = questhead.xbm; sourceTree = "<group>"; };
		F966BA0C08F27A37005CB29B /* question.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = question.xbm; sourceTree = "<group>"; };
		F966BA0D08F27A37005CB29B /* warning.xbm */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; path = warning.xbm; sourceTree = "<group>"; };
		F966BA0E08F27A37005CB29B /* ChangeLog */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = ChangeLog; sourceTree = "<group>"; };
		F966BA0F08F27A37005CB29B /* changes.md */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes.md; sourceTree = "<group>"; };
		F966BA0F08F27A37005CB29B /* changes */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes; sourceTree = "<group>"; };
		F966BA1108F27A37005CB29B /* 3DBorder.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = 3DBorder.3; sourceTree = "<group>"; };
		F966BA1208F27A37005CB29B /* AddOption.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AddOption.3; sourceTree = "<group>"; };
		F966BA1308F27A37005CB29B /* bell.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bell.n; sourceTree = "<group>"; };
		F966BA1408F27A37005CB29B /* bind.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bind.n; sourceTree = "<group>"; };
		F966BA1508F27A37005CB29B /* BindTable.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = BindTable.3; sourceTree = "<group>"; };
		F966BA1608F27A37005CB29B /* bindtags.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bindtags.n; sourceTree = "<group>"; };
		F966BA1708F27A37005CB29B /* bitmap.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = bitmap.n; sourceTree = "<group>"; };
774
775
776
777
778
779
780

781
782
783
784
785
786
787
788
789
790

791
792
793
794
795
796
797
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803







+










+







		F966BA6908F27A38005CB29B /* MainLoop.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MainLoop.3; sourceTree = "<group>"; };
		F966BA6A08F27A38005CB29B /* MaintGeom.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MaintGeom.3; sourceTree = "<group>"; };
		F966BA6B08F27A38005CB29B /* MainWin.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MainWin.3; sourceTree = "<group>"; };
		F966BA6D08F27A38005CB29B /* ManageGeom.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ManageGeom.3; sourceTree = "<group>"; };
		F966BA6E08F27A38005CB29B /* MapWindow.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MapWindow.3; sourceTree = "<group>"; };
		F966BA6F08F27A38005CB29B /* MeasureChar.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MeasureChar.3; sourceTree = "<group>"; };
		F966BA7008F27A38005CB29B /* menu.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menu.n; sourceTree = "<group>"; };
		F966BA7108F27A38005CB29B /* menubar.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menubar.n; sourceTree = "<group>"; };
		F966BA7208F27A38005CB29B /* menubutton.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = menubutton.n; sourceTree = "<group>"; };
		F966BA7308F27A38005CB29B /* message.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = message.n; sourceTree = "<group>"; };
		F966BA7408F27A38005CB29B /* messageBox.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = messageBox.n; sourceTree = "<group>"; };
		F966BA7508F27A38005CB29B /* MoveToplev.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = MoveToplev.3; sourceTree = "<group>"; };
		F966BA7608F27A38005CB29B /* Name.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Name.3; sourceTree = "<group>"; };
		F966BA7708F27A38005CB29B /* NameOfImg.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = NameOfImg.3; sourceTree = "<group>"; };
		F966BA7808F27A38005CB29B /* option.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = option.n; sourceTree = "<group>"; };
		F966BA7908F27A38005CB29B /* optionMenu.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = optionMenu.n; sourceTree = "<group>"; };
		F966BA7A08F27A38005CB29B /* options.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = options.n; sourceTree = "<group>"; };
		F966BA7B08F27A38005CB29B /* OwnSelect.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = OwnSelect.3; sourceTree = "<group>"; };
		F966BA7C08F27A38005CB29B /* pack-old.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = "pack-old.n"; sourceTree = "<group>"; };
		F966BA7D08F27A38005CB29B /* pack.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = pack.n; sourceTree = "<group>"; };
		F966BA7E08F27A38005CB29B /* palette.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = palette.n; sourceTree = "<group>"; };
		F966BA7F08F27A38005CB29B /* panedwindow.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = panedwindow.n; sourceTree = "<group>"; };
		F966BA8008F27A38005CB29B /* ParseArgv.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ParseArgv.3; sourceTree = "<group>"; };
		F966BA8108F27A38005CB29B /* photo.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = photo.n; sourceTree = "<group>"; };
		F966BA8208F27A38005CB29B /* place.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = place.n; sourceTree = "<group>"; };
		F966BA8308F27A38005CB29B /* popup.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = popup.n; sourceTree = "<group>"; };
907
908
909
910
911
912
913

914
915
916
917
918
919
920
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927







+







		F966BAF708F27A39005CB29B /* tkScale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkScale.c; sourceTree = "<group>"; };
		F966BAF808F27A39005CB29B /* tkScale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkScale.h; sourceTree = "<group>"; };
		F966BAF908F27A39005CB29B /* tkScrollbar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkScrollbar.c; sourceTree = "<group>"; };
		F966BAFA08F27A39005CB29B /* tkScrollbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkScrollbar.h; sourceTree = "<group>"; };
		F966BAFB08F27A39005CB29B /* tkSelect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkSelect.c; sourceTree = "<group>"; };
		F966BAFC08F27A39005CB29B /* tkSelect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkSelect.h; sourceTree = "<group>"; };
		F966BAFD08F27A39005CB29B /* tkSquare.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkSquare.c; sourceTree = "<group>"; };
		F966BAFE08F27A39005CB29B /* tkOldTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkOldTest.c; sourceTree = "<group>"; };
		F966BAFF08F27A39005CB29B /* tkStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStubInit.c; sourceTree = "<group>"; };
		F966BB0008F27A39005CB29B /* tkStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStubLib.c; sourceTree = "<group>"; };
		F966BB0108F27A39005CB29B /* tkStyle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkStyle.c; sourceTree = "<group>"; };
		F966BB0208F27A39005CB29B /* tkTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTest.c; sourceTree = "<group>"; };
		F966BB0308F27A39005CB29B /* tkText.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkText.c; sourceTree = "<group>"; };
		F966BB0408F27A39005CB29B /* tkText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkText.h; sourceTree = "<group>"; };
		F966BB0508F27A39005CB29B /* tkTextBTree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkTextBTree.c; sourceTree = "<group>"; };
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030







+












+







		F966BB6208F27A3A005CB29B /* dialog.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = dialog.tcl; sourceTree = "<group>"; };
		F966BB6308F27A3A005CB29B /* entry.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = entry.tcl; sourceTree = "<group>"; };
		F966BB6408F27A3A005CB29B /* focus.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = focus.tcl; sourceTree = "<group>"; };
		F966BB7308F27A3A005CB29B /* listbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = listbox.tcl; sourceTree = "<group>"; };
		F966BB7408F27A3A005CB29B /* menu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menu.tcl; sourceTree = "<group>"; };
		F966BB7508F27A3A005CB29B /* mkpsenc.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = mkpsenc.tcl; sourceTree = "<group>"; };
		F966BB7608F27A3A005CB29B /* msgbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgbox.tcl; sourceTree = "<group>"; };
		F966BB8608F27A3A005CB29B /* obsolete.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = obsolete.tcl; sourceTree = "<group>"; };
		F966BB8708F27A3A005CB29B /* optMenu.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = optMenu.tcl; sourceTree = "<group>"; };
		F966BB8808F27A3A005CB29B /* palette.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = palette.tcl; sourceTree = "<group>"; };
		F966BB8908F27A3B005CB29B /* panedwindow.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.tcl; sourceTree = "<group>"; };
		F966BB8B08F27A3B005CB29B /* safetk.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = safetk.tcl; sourceTree = "<group>"; };
		F966BB8C08F27A3B005CB29B /* scale.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scale.tcl; sourceTree = "<group>"; };
		F966BB8D08F27A3B005CB29B /* scrlbar.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = scrlbar.tcl; sourceTree = "<group>"; };
		F966BB8E08F27A3B005CB29B /* spinbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = spinbox.tcl; sourceTree = "<group>"; };
		F966BB8F08F27A3B005CB29B /* tclIndex */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tclIndex; sourceTree = "<group>"; };
		F966BB9008F27A3B005CB29B /* tearoff.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tearoff.tcl; sourceTree = "<group>"; };
		F966BB9108F27A3B005CB29B /* text.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = text.tcl; sourceTree = "<group>"; };
		F966BB9208F27A3B005CB29B /* tk.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tk.tcl; sourceTree = "<group>"; };
		F966BB9308F27A3B005CB29B /* tkfbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = tkfbox.tcl; sourceTree = "<group>"; };
		F966BB9408F27A3B005CB29B /* unsupported.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = unsupported.tcl; sourceTree = "<group>"; };
		F966BB9508F27A3B005CB29B /* xmfbox.tcl */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = xmfbox.tcl; sourceTree = "<group>"; };
		F966BB9608F27A3B005CB29B /* license.terms */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = license.terms; sourceTree = "<group>"; };
		F966BBBA08F27A3B005CB29B /* configure.ac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure.ac; sourceTree = "<group>"; };
		F966BBBB08F27A3B005CB29B /* GNUmakefile */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = GNUmakefile; sourceTree = "<group>"; };
		F966BBBE08F27A3B005CB29B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F966BBC008F27A3B005CB29B /* Tk-Info.plist.in */ = {isa = PBXFileReference; explicitFileType = text.plist; fileEncoding = 4; path = "Tk-Info.plist.in"; sourceTree = "<group>"; };
		F966BBC208F27A3B005CB29B /* tkMacOSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSX.h; sourceTree = "<group>"; };
1030
1031
1032
1033
1034
1035
1036

1037
1038
1039
1040
1041
1042
1043
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053







+







		F966BBCE08F27A3B005CB29B /* tkMacOSXDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXDebug.h; sourceTree = "<group>"; };
		F966BBCF08F27A3B005CB29B /* tkMacOSXDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXDefault.h; sourceTree = "<group>"; };
		F966BBD008F27A3B005CB29B /* tkMacOSXDialog.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXDialog.c; sourceTree = "<group>"; };
		F966BBD108F27A3B005CB29B /* tkMacOSXDraw.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXDraw.c; sourceTree = "<group>"; };
		F966BBD208F27A3B005CB29B /* tkMacOSXEmbed.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEmbed.c; sourceTree = "<group>"; };
		F966BBD308F27A3B005CB29B /* tkMacOSXEntry.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEntry.c; sourceTree = "<group>"; };
		F966BBD408F27A3B005CB29B /* tkMacOSXEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXEvent.c; sourceTree = "<group>"; };
		F966BBD508F27A3B005CB29B /* tkMacOSXEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXEvent.h; sourceTree = "<group>"; };
		F966BBD608F27A3B005CB29B /* tkMacOSXFont.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXFont.c; sourceTree = "<group>"; };
		F966BBD708F27A3B005CB29B /* tkMacOSXHLEvents.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXHLEvents.c; sourceTree = "<group>"; };
		F966BBD808F27A3B005CB29B /* tkMacOSXInit.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXInit.c; sourceTree = "<group>"; };
		F966BBDA08F27A3B005CB29B /* tkMacOSXInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkMacOSXInt.h; sourceTree = "<group>"; };
		F966BBDB08F27A3B005CB29B /* tkMacOSXKeyboard.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXKeyboard.c; sourceTree = "<group>"; };
		F966BBDC08F27A3B005CB29B /* tkMacOSXKeyEvent.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXKeyEvent.c; sourceTree = "<group>"; };
		F966BBDD08F27A3B005CB29B /* tkMacOSXMenu.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = tkMacOSXMenu.c; sourceTree = "<group>"; };
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136







+







		F966BC3808F27A3C005CB29B /* main.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = main.test; sourceTree = "<group>"; };
		F966BC3908F27A3C005CB29B /* menu.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menu.test; sourceTree = "<group>"; };
		F966BC3A08F27A3C005CB29B /* menubut.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menubut.test; sourceTree = "<group>"; };
		F966BC3B08F27A3C005CB29B /* menuDraw.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = menuDraw.test; sourceTree = "<group>"; };
		F966BC3C08F27A3C005CB29B /* message.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = message.test; sourceTree = "<group>"; };
		F966BC3D08F27A3C005CB29B /* msgbox.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = msgbox.test; sourceTree = "<group>"; };
		F966BC3E08F27A3C005CB29B /* obj.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = obj.test; sourceTree = "<group>"; };
		F966BC3F08F27A3C005CB29B /* oldpack.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = oldpack.test; sourceTree = "<group>"; };
		F966BC4008F27A3C005CB29B /* option.file1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = option.file1; sourceTree = "<group>"; };
		F966BC4108F27A3C005CB29B /* option.file2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = option.file2; sourceTree = "<group>"; };
		F966BC4208F27A3C005CB29B /* option.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = option.test; sourceTree = "<group>"; };
		F966BC4308F27A3C005CB29B /* pack.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = pack.test; sourceTree = "<group>"; };
		F966BC4408F27A3C005CB29B /* panedwindow.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = panedwindow.test; sourceTree = "<group>"; };
		F966BC4508F27A3D005CB29B /* place.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = place.test; sourceTree = "<group>"; };
		F966BC4608F27A3D005CB29B /* raise.test */ = {isa = PBXFileReference; explicitFileType = text.script; fileEncoding = 4; path = raise.test; sourceTree = "<group>"; };
1174
1175
1176
1177
1178
1179
1180

1181
1182
1183
1184
1185
1186
1187
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199







+







		F966BC7808F27A3D005CB29B /* tkUnix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnix.c; sourceTree = "<group>"; };
		F966BC7908F27A3D005CB29B /* tkUnix3d.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnix3d.c; sourceTree = "<group>"; };
		F966BC7A08F27A3D005CB29B /* tkUnixButton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixButton.c; sourceTree = "<group>"; };
		F966BC7B08F27A3D005CB29B /* tkUnixColor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixColor.c; sourceTree = "<group>"; };
		F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixConfig.c; sourceTree = "<group>"; };
		F966BC7D08F27A3D005CB29B /* tkUnixCursor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixCursor.c; sourceTree = "<group>"; };
		F966BC7E08F27A3D005CB29B /* tkUnixDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUnixDefault.h; sourceTree = "<group>"; };
		F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixDialog.c; sourceTree = "<group>"; };
		F966BC8008F27A3D005CB29B /* tkUnixDraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixDraw.c; sourceTree = "<group>"; };
		F966BC8108F27A3D005CB29B /* tkUnixEmbed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixEmbed.c; sourceTree = "<group>"; };
		F966BC8208F27A3D005CB29B /* tkUnixEvent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixEvent.c; sourceTree = "<group>"; };
		F966BC8308F27A3D005CB29B /* tkUnixFocus.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixFocus.c; sourceTree = "<group>"; };
		F966BC8408F27A3D005CB29B /* tkUnixFont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixFont.c; sourceTree = "<group>"; };
		F966BC8508F27A3D005CB29B /* tkUnixInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tkUnixInit.c; sourceTree = "<group>"; };
		F966BC8608F27A3D005CB29B /* tkUnixInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tkUnixInt.h; sourceTree = "<group>"; };
1354
1355
1356
1357
1358
1359
1360

1361

1362
1363
1364
1365
1366
1367
1368
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381







+
-
+







		F968887F0AF788F6000797B5 /* ttk_Theme.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_Theme.3; sourceTree = "<group>"; };
		F96888800AF788F6000797B5 /* ttk_treeview.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_treeview.n; sourceTree = "<group>"; };
		F96888810AF788F6000797B5 /* ttk_widget.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = ttk_widget.n; sourceTree = "<group>"; };
		F96888840AF78938000797B5 /* ttkMacOSXTheme.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = ttkMacOSXTheme.c; sourceTree = "<group>"; };
		F96888860AF78953000797B5 /* ttkWinMonitor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinMonitor.c; sourceTree = "<group>"; };
		F96888870AF78953000797B5 /* ttkWinTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinTheme.c; sourceTree = "<group>"; };
		F96888880AF78953000797B5 /* ttkWinXPTheme.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ttkWinXPTheme.c; sourceTree = "<group>"; };
		F96D3DFA08F272A4004A47F5 /* ChangeLog */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = ChangeLog; sourceTree = "<group>"; };
		F96D3DFB08F272A4004A47F5 /* changes.md */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes.md; sourceTree = "<group>"; };
		F96D3DFB08F272A4004A47F5 /* changes */ = {isa = PBXFileReference; explicitFileType = text; fileEncoding = 4; path = changes; sourceTree = "<group>"; };
		F96D3DFD08F272A4004A47F5 /* Access.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Access.3; sourceTree = "<group>"; };
		F96D3DFE08F272A4004A47F5 /* AddErrInfo.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AddErrInfo.3; sourceTree = "<group>"; };
		F96D3DFF08F272A4004A47F5 /* after.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = after.n; sourceTree = "<group>"; };
		F96D3E0008F272A4004A47F5 /* Alloc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = Alloc.3; sourceTree = "<group>"; };
		F96D3E0108F272A4004A47F5 /* AllowExc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AllowExc.3; sourceTree = "<group>"; };
		F96D3E0208F272A4004A47F5 /* append.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = append.n; sourceTree = "<group>"; };
		F96D3E0308F272A4004A47F5 /* AppInit.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = AppInit.3; sourceTree = "<group>"; };
1392
1393
1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419







-
+







		F96D3E1B08F272A5004A47F5 /* CrtChnlHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtChnlHdlr.3; sourceTree = "<group>"; };
		F96D3E1C08F272A5004A47F5 /* CrtCloseHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtCloseHdlr.3; sourceTree = "<group>"; };
		F96D3E1D08F272A5004A47F5 /* CrtCommand.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtCommand.3; sourceTree = "<group>"; };
		F96D3E1E08F272A5004A47F5 /* CrtFileHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtFileHdlr.3; sourceTree = "<group>"; };
		F96D3E1F08F272A5004A47F5 /* CrtInterp.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtInterp.3; sourceTree = "<group>"; };
		F96D3E2008F272A5004A47F5 /* CrtMathFnc.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtMathFnc.3; sourceTree = "<group>"; };
		F96D3E2108F272A5004A47F5 /* CrtObjCmd.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtObjCmd.3; sourceTree = "<group>"; };
		F96D3E2208F272A5004A47F5 /* CrtAlias.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtAlias.3; sourceTree = "<group>"; };
		F96D3E2208F272A5004A47F5 /* CrtSlave.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtSlave.3; sourceTree = "<group>"; };
		F96D3E2308F272A5004A47F5 /* CrtTimerHdlr.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtTimerHdlr.3; sourceTree = "<group>"; };
		F96D3E2408F272A5004A47F5 /* CrtTrace.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = CrtTrace.3; sourceTree = "<group>"; };
		F96D3E2508F272A5004A47F5 /* dde.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = dde.n; sourceTree = "<group>"; };
		F96D3E2608F272A5004A47F5 /* DetachPids.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DetachPids.3; sourceTree = "<group>"; };
		F96D3E2708F272A5004A47F5 /* dict.n */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = dict.n; sourceTree = "<group>"; };
		F96D3E2808F272A5004A47F5 /* DictObj.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DictObj.3; sourceTree = "<group>"; };
		F96D3E2908F272A5004A47F5 /* DoOneEvent.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 4; path = DoOneEvent.3; sourceTree = "<group>"; };
1964
1965
1966
1967
1968
1969
1970

1971
1972
1973
1974
1975
1976
1977
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991







+







		F96D446A08F272B9004A47F5 /* tclUnixThrd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclUnixThrd.h; sourceTree = "<group>"; };
		F96D446B08F272B9004A47F5 /* tclUnixTime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUnixTime.c; sourceTree = "<group>"; };
		F96D446C08F272B9004A47F5 /* tclXtNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtNotify.c; sourceTree = "<group>"; };
		F96D446D08F272B9004A47F5 /* tclXtTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtTest.c; sourceTree = "<group>"; };
		F96D447008F272BA004A47F5 /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = "<group>"; };
		F96D447108F272BA004A47F5 /* buildall.vc.bat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = buildall.vc.bat; sourceTree = "<group>"; };
		F96D447208F272BA004A47F5 /* cat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cat.c; sourceTree = "<group>"; };
		F96D447308F272BA004A47F5 /* coffbase.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = coffbase.txt; sourceTree = "<group>"; };
		F96D447408F272BA004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = "<group>"; };
		F96D447508F272BA004A47F5 /* configure.ac */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.ac; sourceTree = "<group>"; };
		F96D447708F272BA004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = "<group>"; };
		F96D447808F272BA004A47F5 /* makefile.vc */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = makefile.vc; sourceTree = "<group>"; };
		F96D447908F272BA004A47F5 /* nmakehlp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nmakehlp.c; sourceTree = "<group>"; };
		F96D447A08F272BA004A47F5 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
		F96D447C08F272BA004A47F5 /* rules.vc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = rules.vc; sourceTree = "<group>"; };
2236
2237
2238
2239
2240
2241
2242

2243
2244
2245
2246
2247
2248
2249
2250
2251
2252

2253
2254
2255
2256
2257
2258
2259
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







+










+







				F966BA6908F27A38005CB29B /* MainLoop.3 */,
				F966BA6A08F27A38005CB29B /* MaintGeom.3 */,
				F966BA6B08F27A38005CB29B /* MainWin.3 */,
				F966BA6D08F27A38005CB29B /* ManageGeom.3 */,
				F966BA6E08F27A38005CB29B /* MapWindow.3 */,
				F966BA6F08F27A38005CB29B /* MeasureChar.3 */,
				F966BA7008F27A38005CB29B /* menu.n */,
				F966BA7108F27A38005CB29B /* menubar.n */,
				F966BA7208F27A38005CB29B /* menubutton.n */,
				F966BA7308F27A38005CB29B /* message.n */,
				F966BA7408F27A38005CB29B /* messageBox.n */,
				F966BA7508F27A38005CB29B /* MoveToplev.3 */,
				F966BA7608F27A38005CB29B /* Name.3 */,
				F966BA7708F27A38005CB29B /* NameOfImg.3 */,
				F966BA7808F27A38005CB29B /* option.n */,
				F966BA7908F27A38005CB29B /* optionMenu.n */,
				F966BA7A08F27A38005CB29B /* options.n */,
				F966BA7B08F27A38005CB29B /* OwnSelect.3 */,
				F966BA7C08F27A38005CB29B /* pack-old.n */,
				F966BA7D08F27A38005CB29B /* pack.n */,
				F966BA7E08F27A38005CB29B /* palette.n */,
				F966BA7F08F27A38005CB29B /* panedwindow.n */,
				F966BA8008F27A38005CB29B /* ParseArgv.3 */,
				F966BA8108F27A38005CB29B /* photo.n */,
				F966BA8208F27A38005CB29B /* place.n */,
				F966BA8308F27A38005CB29B /* popup.n */,
2401
2402
2403
2404
2405
2406
2407

2408
2409
2410
2411
2412
2413
2414
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431







+







				F966BAF708F27A39005CB29B /* tkScale.c */,
				F966BAF808F27A39005CB29B /* tkScale.h */,
				F966BAF908F27A39005CB29B /* tkScrollbar.c */,
				F966BAFA08F27A39005CB29B /* tkScrollbar.h */,
				F966BAFB08F27A39005CB29B /* tkSelect.c */,
				F966BAFC08F27A39005CB29B /* tkSelect.h */,
				F966BAFD08F27A39005CB29B /* tkSquare.c */,
				F966BAFE08F27A39005CB29B /* tkOldTest.c */,
				F966BAFF08F27A39005CB29B /* tkStubInit.c */,
				F966BB0008F27A39005CB29B /* tkStubLib.c */,
				F966BB0108F27A39005CB29B /* tkStyle.c */,
				F966BB0208F27A39005CB29B /* tkTest.c */,
				F966BB0308F27A39005CB29B /* tkText.c */,
				F966BB0408F27A39005CB29B /* tkText.h */,
				F966BB0508F27A39005CB29B /* tkTextBTree.c */,
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
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







+













+







				F99388380EE0114B0065FE6B /* fontchooser.tcl */,
				F974D57C0FBE7EFF00BF728B /* iconlist.tcl */,
				F974D57D0FBE7EFF00BF728B /* icons.tcl */,
				F966BB7308F27A3A005CB29B /* listbox.tcl */,
				F966BB7408F27A3A005CB29B /* menu.tcl */,
				F966BB7508F27A3A005CB29B /* mkpsenc.tcl */,
				F966BB7608F27A3A005CB29B /* msgbox.tcl */,
				F966BB8608F27A3A005CB29B /* obsolete.tcl */,
				F966BB8708F27A3A005CB29B /* optMenu.tcl */,
				F966BB8808F27A3A005CB29B /* palette.tcl */,
				F966BB8908F27A3B005CB29B /* panedwindow.tcl */,
				F966BB8B08F27A3B005CB29B /* safetk.tcl */,
				F966BB8C08F27A3B005CB29B /* scale.tcl */,
				F966BB8D08F27A3B005CB29B /* scrlbar.tcl */,
				F966BB8E08F27A3B005CB29B /* spinbox.tcl */,
				F966BB8F08F27A3B005CB29B /* tclIndex */,
				F966BB9008F27A3B005CB29B /* tearoff.tcl */,
				F966BB9108F27A3B005CB29B /* text.tcl */,
				F966BB9208F27A3B005CB29B /* tk.tcl */,
				F966BB9308F27A3B005CB29B /* tkfbox.tcl */,
				F96888360AF787B3000797B5 /* ttk */,
				F966BB9408F27A3B005CB29B /* unsupported.tcl */,
				F966BB9508F27A3B005CB29B /* xmfbox.tcl */,
			);
			path = library;
			sourceTree = "<group>";
		};
		F966BB1A08F27A39005CB29B /* demos */ = {
			isa = PBXGroup;
2562
2563
2564
2565
2566
2567
2568

2569
2570
2571
2572
2573
2574
2575
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595







+







				F966BBCE08F27A3B005CB29B /* tkMacOSXDebug.h */,
				F966BBCF08F27A3B005CB29B /* tkMacOSXDefault.h */,
				F966BBD008F27A3B005CB29B /* tkMacOSXDialog.c */,
				F966BBD108F27A3B005CB29B /* tkMacOSXDraw.c */,
				F966BBD208F27A3B005CB29B /* tkMacOSXEmbed.c */,
				F966BBD308F27A3B005CB29B /* tkMacOSXEntry.c */,
				F966BBD408F27A3B005CB29B /* tkMacOSXEvent.c */,
				F966BBD508F27A3B005CB29B /* tkMacOSXEvent.h */,
				F966BBD608F27A3B005CB29B /* tkMacOSXFont.c */,
				F93E5EFD09CF8711008FA367 /* tkMacOSXFont.h */,
				F966BBD708F27A3B005CB29B /* tkMacOSXHLEvents.c */,
				F966BBD808F27A3B005CB29B /* tkMacOSXInit.c */,
				F966BBDA08F27A3B005CB29B /* tkMacOSXInt.h */,
				F966BBDB08F27A3B005CB29B /* tkMacOSXKeyboard.c */,
				F966BBDC08F27A3B005CB29B /* tkMacOSXKeyEvent.c */,
2661
2662
2663
2664
2665
2666
2667

2668
2669
2670
2671
2672
2673
2674
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695







+







				F966BC3808F27A3C005CB29B /* main.test */,
				F966BC3908F27A3C005CB29B /* menu.test */,
				F966BC3A08F27A3C005CB29B /* menubut.test */,
				F966BC3B08F27A3C005CB29B /* menuDraw.test */,
				F966BC3C08F27A3C005CB29B /* message.test */,
				F966BC3D08F27A3C005CB29B /* msgbox.test */,
				F966BC3E08F27A3C005CB29B /* obj.test */,
				F966BC3F08F27A3C005CB29B /* oldpack.test */,
				F966BC4008F27A3C005CB29B /* option.file1 */,
				F966BC4108F27A3C005CB29B /* option.file2 */,
				F966BC4208F27A3C005CB29B /* option.test */,
				F966BC4308F27A3C005CB29B /* pack.test */,
				F966BC4408F27A3C005CB29B /* panedwindow.test */,
				F966BC4508F27A3D005CB29B /* place.test */,
				F966BC4608F27A3D005CB29B /* raise.test */,
2732
2733
2734
2735
2736
2737
2738

2739
2740
2741
2742
2743
2744
2745
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767







+







				F966BC7808F27A3D005CB29B /* tkUnix.c */,
				F966BC7908F27A3D005CB29B /* tkUnix3d.c */,
				F966BC7A08F27A3D005CB29B /* tkUnixButton.c */,
				F966BC7B08F27A3D005CB29B /* tkUnixColor.c */,
				F966BC7C08F27A3D005CB29B /* tkUnixConfig.c */,
				F966BC7D08F27A3D005CB29B /* tkUnixCursor.c */,
				F966BC7E08F27A3D005CB29B /* tkUnixDefault.h */,
				F966BC7F08F27A3D005CB29B /* tkUnixDialog.c */,
				F966BC8008F27A3D005CB29B /* tkUnixDraw.c */,
				F966BC8108F27A3D005CB29B /* tkUnixEmbed.c */,
				F966BC8208F27A3D005CB29B /* tkUnixEvent.c */,
				F966BC8308F27A3D005CB29B /* tkUnixFocus.c */,
				F966BC8408F27A3D005CB29B /* tkUnixFont.c */,
				F966BC8508F27A3D005CB29B /* tkUnixInit.c */,
				F966BC8608F27A3D005CB29B /* tkUnixInt.h */,
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
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







+
-
+


















+
-
+







				F96D425C08F272B2004A47F5 /* libtommath */,
				F96D446E08F272B9004A47F5 /* win */,
				F96D3F3808F272A7004A47F5 /* library */,
				F96D434408F272B5004A47F5 /* tests */,
				F96D3DFC08F272A4004A47F5 /* doc */,
				F96D43D008F272B8004A47F5 /* tools */,
				F9183E690EFC81560030B814 /* pkgs */,
				F96D3DFA08F272A4004A47F5 /* ChangeLog */,
				F96D3DFB08F272A4004A47F5 /* changes.md */,
				F96D3DFB08F272A4004A47F5 /* changes */,
				F96D434308F272B5004A47F5 /* README */,
				F96D432B08F272B4004A47F5 /* license.terms */,
			);
			name = "Tcl Sources";
			sourceTree = TCL_SRCROOT;
		};
		F96D3DF708F271BE004A47F5 /* Tk Sources */ = {
			isa = PBXGroup;
			children = (
				F966BAA508F27A38005CB29B /* generic */,
				F966BB9708F27A3B005CB29B /* macosx */,
				F966BC6B08F27A3D005CB29B /* unix */,
				F966BD1908F27A3F005CB29B /* xlib */,
				F966BA0308F27A37005CB29B /* bitmaps */,
				F966BC9208F27A3D005CB29B /* win */,
				F966BB1308F27A39005CB29B /* library */,
				F966BC0408F27A3C005CB29B /* tests */,
				F966BA1008F27A37005CB29B /* doc */,
				F966BA0E08F27A37005CB29B /* ChangeLog */,
				F966BA0F08F27A37005CB29B /* changes.md */,
				F966BA0F08F27A37005CB29B /* changes */,
				F966BC0308F27A3C005CB29B /* README */,
				F966BB9608F27A3B005CB29B /* license.terms */,
			);
			name = "Tk Sources";
			sourceTree = TK_SRCROOT;
		};
		F96D3DFC08F272A4004A47F5 /* doc */ = {
3047
3048
3049
3050
3051
3052
3053
3054

3055
3056
3057
3058
3059
3060
3061
3071
3072
3073
3074
3075
3076
3077

3078
3079
3080
3081
3082
3083
3084
3085







-
+







				F96D3E1B08F272A5004A47F5 /* CrtChnlHdlr.3 */,
				F96D3E1C08F272A5004A47F5 /* CrtCloseHdlr.3 */,
				F96D3E1D08F272A5004A47F5 /* CrtCommand.3 */,
				F96D3E1E08F272A5004A47F5 /* CrtFileHdlr.3 */,
				F96D3E1F08F272A5004A47F5 /* CrtInterp.3 */,
				F96D3E2008F272A5004A47F5 /* CrtMathFnc.3 */,
				F96D3E2108F272A5004A47F5 /* CrtObjCmd.3 */,
				F96D3E2208F272A5004A47F5 /* CrtAlias.3 */,
				F96D3E2208F272A5004A47F5 /* CrtSlave.3 */,
				F96D3E2308F272A5004A47F5 /* CrtTimerHdlr.3 */,
				F96D3E2408F272A5004A47F5 /* CrtTrace.3 */,
				F96D3E2508F272A5004A47F5 /* dde.n */,
				F93599D30DF1F8F500E04F67 /* define.n */,
				F96D3E2608F272A5004A47F5 /* DetachPids.3 */,
				F96D3E2708F272A5004A47F5 /* dict.n */,
				F96D3E2808F272A5004A47F5 /* DictObj.3 */,
3784
3785
3786
3787
3788
3789
3790

3791
3792
3793
3794
3795
3796
3797
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822







+







		};
		F96D446E08F272B9004A47F5 /* win */ = {
			isa = PBXGroup;
			children = (
				F96D447008F272BA004A47F5 /* aclocal.m4 */,
				F96D447108F272BA004A47F5 /* buildall.vc.bat */,
				F96D447208F272BA004A47F5 /* cat.c */,
				F96D447308F272BA004A47F5 /* coffbase.txt */,
				F96D447408F272BA004A47F5 /* configure */,
				F96D447508F272BA004A47F5 /* configure.ac */,
				F96D447708F272BA004A47F5 /* Makefile.in */,
				F96D447808F272BA004A47F5 /* makefile.vc */,
				F96D447908F272BA004A47F5 /* nmakehlp.c */,
				F96D447A08F272BA004A47F5 /* README */,
				F96D447C08F272BA004A47F5 /* rules.vc */,
4237
4238
4239
4240
4241
4242
4243

4244
4245
4246
4247
4248
4249
4250
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276







+







				F966BE0908F27A3F005CB29B /* tkMain.c in Sources */,
				F966BE0A08F27A3F005CB29B /* tkMenu.c in Sources */,
				F966BE0C08F27A3F005CB29B /* tkMenubutton.c in Sources */,
				F966BE0E08F27A3F005CB29B /* tkMenuDraw.c in Sources */,
				F966BE0F08F27A3F005CB29B /* tkMessage.c in Sources */,
				F966BE1008F27A3F005CB29B /* tkObj.c in Sources */,
				F966BE1108F27A3F005CB29B /* tkOldConfig.c in Sources */,
				F9067BCD0BFBA2900074F726 /* tkOldTest.c in Sources */,
				F966BE1208F27A3F005CB29B /* tkOption.c in Sources */,
				F966BE1308F27A3F005CB29B /* tkPack.c in Sources */,
				F966BE1408F27A3F005CB29B /* tkPanedWindow.c in Sources */,
				F966BE1508F27A3F005CB29B /* tkPlace.c in Sources */,
				F966BE1708F27A3F005CB29B /* tkPointer.c in Sources */,
				F966BE1908F27A3F005CB29B /* tkRectOval.c in Sources */,
				F966BE1A08F27A3F005CB29B /* tkScale.c in Sources */,
4550
4551
4552
4553
4554
4555
4556

4557
4558
4559
4560
4561
4562
4563
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590







+







				F9FD31780CC1AD070073837D /* tkMain.c in Sources */,
				F9FD31790CC1AD070073837D /* tkMenu.c in Sources */,
				F9FD317A0CC1AD070073837D /* tkMenubutton.c in Sources */,
				F9FD317B0CC1AD070073837D /* tkMenuDraw.c in Sources */,
				F9FD317C0CC1AD070073837D /* tkMessage.c in Sources */,
				F9FD317D0CC1AD070073837D /* tkObj.c in Sources */,
				F9FD317E0CC1AD070073837D /* tkOldConfig.c in Sources */,
				F9FD317F0CC1AD070073837D /* tkOldTest.c in Sources */,
				F9FD31800CC1AD070073837D /* tkOption.c in Sources */,
				F9FD31810CC1AD070073837D /* tkPack.c in Sources */,
				F9FD31820CC1AD070073837D /* tkPanedWindow.c in Sources */,
				F9FD31830CC1AD070073837D /* tkPlace.c in Sources */,
				F9FD31850CC1AD070073837D /* tkRectOval.c in Sources */,
				F9FD31860CC1AD070073837D /* tkScale.c in Sources */,
				F9FD31870CC1AD070073837D /* tkScrollbar.c in Sources */,
4614
4615
4616
4617
4618
4619
4620

4621
4622
4623
4624
4625
4626
4627
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655







+







				F9FD31DA0CC1AD070073837D /* tkAppInit.c in Sources */,
				F9FD32020CC1ADB70073837D /* tkUnix.c in Sources */,
				F9FD31DB0CC1AD070073837D /* tkUnix3d.c in Sources */,
				F9FD320A0CC1ADB70073837D /* tkUnixButton.c in Sources */,
				F9FD32090CC1ADB70073837D /* tkUnixColor.c in Sources */,
				F9FD32040CC1ADB70073837D /* tkUnixConfig.c in Sources */,
				F9FD31F80CC1ADB70073837D /* tkUnixCursor.c in Sources */,
				F9FD32060CC1ADB70073837D /* tkUnixDialog.c in Sources */,
				F9FD32050CC1ADB70073837D /* tkUnixDraw.c in Sources */,
				F9FD31FD0CC1ADB70073837D /* tkUnixEmbed.c in Sources */,
				F9FD32080CC1ADB70073837D /* tkUnixEvent.c in Sources */,
				F9FD31FF0CC1ADB70073837D /* tkUnixFocus.c in Sources */,
				F9FD31FC0CC1ADB70073837D /* tkUnixInit.c in Sources */,
				F9FD31FA0CC1ADB70073837D /* tkUnixKey.c in Sources */,
				F9FD32030CC1ADB70073837D /* tkUnixMenu.c in Sources */,
4721
4722
4723
4724
4725
4726
4727
4728
4729


4730
4731
4732
4733
4734
4735
4736
4749
4750
4751
4752
4753
4754
4755


4756
4757
4758
4759
4760
4761
4762
4763
4764







-
-
+
+







			};
			name = ReleaseUniversal;
		};
		F91BCC51093152310042A6BF /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.6;
				PREBINDING = NO;
			};
5033
5034
5035
5036
5037
5038
5039
5040
5041


5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054




















































5055
5056
5057
5058
5059
5060
5061
5061
5062
5063
5064
5065
5066
5067


5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141







-
-
+
+













+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoFixAndContinue;
		};
		F97258AC0A86873D00096C78 /* ReleaseUniversal */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = ReleaseUniversal;
		};
		F97AED1B0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = Debug64bit;
		};
		F97AED1C0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = Debug64bit;
		};
		F97AED1D0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = Debug64bit;
		};
		F97AED1E0B660B2100310EA2 /* Debug64bit */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = "$(NATIVE_ARCH_64_BIT)";
				CONFIGURE_ARGS = "--enable-64bit $(CONFIGURE_ARGS)";
				CPPFLAGS = "-arch $(NATIVE_ARCH_64_BIT) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.6;
				PREBINDING = NO;
			};
			name = Debug64bit;
		};
		F987512F0DE7B57E00B1C9EC /* DebugNoCF */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
5106
5107
5108
5109
5110
5111
5112


























































5113
5114
5115
5116
5117
5118
5119
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoCF;
		};
		F98751330DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --disable-threads --disable-corefoundation";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.6;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751340DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751350DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --enable-corefoundation";
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugNoCFUnthreaded;
		};
		F98751360DE7B5A200B1C9EC /* DebugNoCFUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugNoCFUnthreaded;
		};
		F9988AB10D814C6500B6B03B /* Debug gcc40 */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
5256
5257
5258
5259
5260
5261
5262
5263
5264


5265
5266
5267
5268
5269
5270
5271
5394
5395
5396
5397
5398
5399
5400


5401
5402
5403
5404
5405
5406
5407
5408
5409







-
-
+
+







			};
			name = "Debug llvm-gcc";
		};
		F9988BB10D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_VERSION = 4.0;
				MACOSX_DEPLOYMENT_TARGET = 10.6;
				PREBINDING = NO;
5290
5291
5292
5293
5294
5295
5296
5297
5298


5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318


5319
5320
5321
5322
5323
5324
5325
5428
5429
5430
5431
5432
5433
5434


5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454


5455
5456
5457
5458
5459
5460
5461
5462
5463







-
-
+
+


















-
-
+
+







				PRODUCT_NAME = tktest;
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB40D81586D00B6B03B /* ReleaseUniversal gcc40 */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "ReleaseUniversal gcc40";
		};
		F9988BB50D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				DEBUG_INFORMATION_FORMAT = dwarf;
				GCC = "llvm-gcc";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_OPTIMIZATION_LEVEL = 4;
5348
5349
5350
5351
5352
5353
5354
5355
5356


5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369








5370
5371
5372
5373
5374
5375
5376
5377











5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388

















5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405




















5406
5407
5408
5409
5410
5411
5412

5413
5414
5415
5416
5417
5418
5419
5486
5487
5488
5489
5490
5491
5492


5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614







-
-
+
+













+
+
+
+
+
+
+
+








+
+
+
+
+
+
+
+
+
+
+











+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+







				PRODUCT_NAME = tktest;
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F9988BB80D81587400B6B03B /* ReleaseUniversal llvm-gcc */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = "ReleaseUniversal llvm-gcc";
		};
		F99EE73B0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugUnthreaded;
		};
		F99EE73C0BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				PRODUCT_NAME = Wish;
				SKIP_INSTALL = NO;
			};
			name = DebugLeaks;
		};
		F99EE73D0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugUnthreaded;
		};
		F99EE73E0BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				OTHER_LDFLAGS = (
					"$(OTHER_LDFLAGS_AQUA)",
					"$(OTHER_LDFLAGS)",
				);
				PRODUCT_NAME = tktest;
			};
			name = DebugLeaks;
		};
		F99EE73F0BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugUnthreaded;
		};
		F99EE7400BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = DebugLeaks;
		};
		F99EE7410BE835310060D4AF /* DebugUnthreaded */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CONFIGURE_ARGS = "$(CONFIGURE_ARGS) --disable-threads";
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.6;
				ONLY_ACTIVE_ARCH = YES;
				PREBINDING = NO;
			};
			name = DebugUnthreaded;
		};
		F99EE7420BE835310060D4AF /* DebugLeaks */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE8330B65C87F00310EA2 /* Tk-Debug.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CPPFLAGS = "-arch $(CURRENT_ARCH) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = unsupported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_PREPROCESSOR_DEFINITIONS = (
5501
5502
5503
5504
5505
5506
5507

5508
5509

5510
5511
5512
5513
5514
5515
5516
5696
5697
5698
5699
5700
5701
5702
5703
5704

5705
5706
5707
5708
5709
5710
5711
5712







+

-
+







		};
		F9A9D1F30FC77799002A2BE3 /* ReleaseUniversal clang */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = (
					"$(NATIVE_ARCH_64_BIT)",
					"$(NATIVE_ARCH_32_BIT)",
				);
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				CFLAGS = "-arch i386 -arch x86_64 $(CFLAGS)";
				DEBUG_INFORMATION_FORMAT = dwarf;
				GCC = clang;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				GCC_OPTIMIZATION_LEVEL = 4;
5538
5539
5540
5541
5542
5543
5544
5545
5546


5547
5548
5549
5550
5551
5552
5553
5734
5735
5736
5737
5738
5739
5740


5741
5742
5743
5744
5745
5746
5747
5748
5749







-
-
+
+







				PRODUCT_NAME = tktest;
			};
			name = "ReleaseUniversal clang";
		};
		F9A9D1F60FC77799002A2BE3 /* ReleaseUniversal clang */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
5575
5576
5577
5578
5579
5580
5581
5582
5583


5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603


5604
5605
5606
5607
5608
5609
5610
5771
5772
5773
5774
5775
5776
5777


5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797


5798
5799
5800
5801
5802
5803
5804
5805
5806







-
-
+
+


















-
-
+
+







				PRODUCT_NAME = tktest;
			};
			name = ReleaseUniversal10.5SDK;
		};
		F9EEED980C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				GCC_INPUT_FILETYPE = sourcecode.c.c;
				HEADER_SEARCH_PATHS = (
					/usr/X11R6/include,
					/usr/X11R6/include/freetype2,
					"$(HEADER_SEARCH_PATHS)",
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/X11R6/lib,
					"$(LIBRARY_SEARCH_PATHS)",
				);
				PRODUCT_NAME = "tktest-X11";
			};
			name = ReleaseUniversal10.5SDK;
		};
		F9EEED990C2FEFD300396116 /* ReleaseUniversal10.5SDK */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = F97AE82B0B65C69B00310EA2 /* Tk-Release.xcconfig */;
			buildSettings = {
				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
				CFLAGS = "-arch x86_64 -arch arm64 $(CFLAGS)";
				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
				CFLAGS = "-arch i386 -arch x86_64 -arch ppc $(CFLAGS)";
				CPPFLAGS = "-isysroot $(SDKROOT) $(CPPFLAGS)";
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_ENABLE_OBJC_GC = supported;
				GCC_ENABLE_PASCAL_STRINGS = NO;
				GCC_INPUT_FILETYPE = sourcecode.c.objc;
				MACOSX_DEPLOYMENT_TARGET = 10.5;
				PREBINDING = NO;
5620
5621
5622
5623
5624
5625
5626

5627

5628
5629
5630

5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649

5650

5651
5652
5653

5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672

5673

5674
5675
5676

5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695

5696

5697
5698
5699

5700
5701
5702
5703
5704
5705
5706
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914







+

+



+



















+

+



+



















+

+



+



















+

+



+







			buildConfigurations = (
				F95CC8AC09158F3100EA5ACE /* Debug */,
				F9A9D1F00FC77787002A2BE3 /* Debug clang */,
				F9988AB60D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB20D814C6500B6B03B /* Debug gcc40 */,
				F90E36D60F3B5C8400810A10 /* DebugNoGC */,
				F95CC8AE09158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE73B0BE835310060D4AF /* DebugUnthreaded */,
				F98751300DE7B57E00B1C9EC /* DebugNoCF */,
				F98751340DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084370BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE73C0BE835310060D4AF /* DebugLeaks */,
				F9359B260DF212DA00E04F67 /* DebugGCov */,
				F97AED1B0B660B2100310EA2 /* Debug64bit */,
				F95CC8AD09158F3100EA5ACE /* Release */,
				F91BCC4F093152310042A6BF /* ReleaseUniversal */,
				F9A9D1F40FC77799002A2BE3 /* ReleaseUniversal clang */,
				F9988BB60D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB20D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED960C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F95CC8B009158F3100EA5ACE /* Build configuration list for PBXNativeTarget "tktest" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F95CC8B109158F3100EA5ACE /* Debug */,
				F9A9D1F10FC77787002A2BE3 /* Debug clang */,
				F9988AB70D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB30D814C6500B6B03B /* Debug gcc40 */,
				F90E36D70F3B5C8400810A10 /* DebugNoGC */,
				F95CC8B309158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE73D0BE835310060D4AF /* DebugUnthreaded */,
				F98751310DE7B57E00B1C9EC /* DebugNoCF */,
				F98751350DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084380BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE73E0BE835310060D4AF /* DebugLeaks */,
				F9359B270DF212DA00E04F67 /* DebugGCov */,
				F97AED1C0B660B2100310EA2 /* Debug64bit */,
				F95CC8B209158F3100EA5ACE /* Release */,
				F91BCC50093152310042A6BF /* ReleaseUniversal */,
				F9A9D1F50FC77799002A2BE3 /* ReleaseUniversal clang */,
				F9988BB70D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB30D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED970C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F95CC8B509158F3100EA5ACE /* Build configuration list for PBXProject "Tk" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F95CC8B609158F3100EA5ACE /* Debug */,
				F9A9D1EF0FC77787002A2BE3 /* Debug clang */,
				F9988AB50D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB10D814C6500B6B03B /* Debug gcc40 */,
				F90E36D50F3B5C8400810A10 /* DebugNoGC */,
				F95CC8B809158F3100EA5ACE /* DebugNoFixAndContinue */,
				F99EE7410BE835310060D4AF /* DebugUnthreaded */,
				F987512F0DE7B57E00B1C9EC /* DebugNoCF */,
				F98751330DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F930843A0BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE7420BE835310060D4AF /* DebugLeaks */,
				F9359B250DF212DA00E04F67 /* DebugGCov */,
				F97AED1E0B660B2100310EA2 /* Debug64bit */,
				F95CC8B709158F3100EA5ACE /* Release */,
				F91BCC51093152310042A6BF /* ReleaseUniversal */,
				F9A9D1F30FC77799002A2BE3 /* ReleaseUniversal clang */,
				F9988BB50D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB10D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED990C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		F97258A80A86873D00096C78 /* Build configuration list for PBXNativeTarget "tktest-X11" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				F97258A90A86873D00096C78 /* Debug */,
				F9A9D1F20FC77787002A2BE3 /* Debug clang */,
				F9988AB80D814C7500B6B03B /* Debug llvm-gcc */,
				F9988AB40D814C6500B6B03B /* Debug gcc40 */,
				F90E36D80F3B5C8400810A10 /* DebugNoGC */,
				F97258AB0A86873D00096C78 /* DebugNoFixAndContinue */,
				F99EE73F0BE835310060D4AF /* DebugUnthreaded */,
				F98751320DE7B57E00B1C9EC /* DebugNoCF */,
				F98751360DE7B5A200B1C9EC /* DebugNoCFUnthreaded */,
				F93084390BB93D2800CD0B9E /* DebugMemCompile */,
				F99EE7400BE835310060D4AF /* DebugLeaks */,
				F9359B280DF212DA00E04F67 /* DebugGCov */,
				F97AED1D0B660B2100310EA2 /* Debug64bit */,
				F97258AA0A86873D00096C78 /* Release */,
				F97258AC0A86873D00096C78 /* ReleaseUniversal */,
				F9A9D1F60FC77799002A2BE3 /* ReleaseUniversal clang */,
				F9988BB80D81587400B6B03B /* ReleaseUniversal llvm-gcc */,
				F9988BB40D81586D00B6B03B /* ReleaseUniversal gcc40 */,
				F9EEED980C2FEFD300396116 /* ReleaseUniversal10.5SDK */,
			);

Changes to macosx/Wish-Info.plist.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38




























39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92










































93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
1
2
3
4
5
6
7
8
9
10




























11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38






















































39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80













81


82










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
	Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
	Copyright 2008-2009, Apple Inc.

	See the file "license.terms" for information on usage and redistribution of
	this file, and for a DISCLAIMER OF ALL WARRANTIES.
-->
<plist version="1.0">
  <dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDocumentTypes</key>
    <array>
      <dict>
	<key>CFBundleTypeExtensions</key>
	<array>
	  <string>tcl</string>
	  <string>TCL</string>
	  <string>*</string>
	</array>
	<key>CFBundleTypeMIMETypes</key>
	<array>
	  <string>application/x-tcl</string>
	  <string>text/plain</string>
	</array>
	<key>CFBundleTypeName</key>
	<string>NSStringPboardType</string>
	<key>CFBundleTypeOSTypes</key>
	<array>
	  <string>TEXT</string>
	  <string>****</string>
	</array>
	<key>CFBundleTypeRole</key>
	<string>Viewer</string>
      </dict>
    </array>
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeExtensions</key>
			<array>
				<string>tcl</string>
				<string>TCL</string>
				<string>*</string>
			</array>
			<key>CFBundleTypeMIMETypes</key>
			<array>
				<string>application/x-tcl</string>
				<string>text/plain</string>
			</array>
			<key>CFBundleTypeName</key>
			<string>NSStringPboardType</string>
			<key>CFBundleTypeOSTypes</key>
			<array>
				<string>TEXT</string>
				<string>****</string>
			</array>
			<key>CFBundleTypeRole</key>
			<string>Viewer</string>
		</dict>
	</array>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
	<key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>foo</string>
        </array>
        <key>CFBundleURLName</key>
        <string>Get Foo</string>
      </dict>
    </array>
    <key>CFBundleExecutable</key>
    <string>Wish</string>
    <key>CFBundleGetInfoString</key>
    <string>Wish Shell @TK_VERSION@@TK_PATCH_LEVEL@,
    Copyright © 1989-@TK_YEAR@ Tcl Core Team,
    Copyright © 1989-@TK_YEAR@ Contributors,
    Copyright © 2011-@TK_YEAR@ Kevin Walzer/WordTech Communications LLC,
    Copyright © 2014-@TK_YEAR@ Marc Culler,
    Copyright © 2002-@TK_YEAR@ Daniel A. Steffen,
    Copyright © 2001-2009 Apple Inc.,
    Copyright © 2001-2002 Jim Ingham &amp; Ian Reid</string>
    <key>CFBundleIconFile</key>
    <string>Wish.icns</string>
    <key>CFBundleIdentifier</key>
    <string>com.tcltk.wish</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleLocalizations</key>
    <array>
      @CFBUNDLELOCALIZATIONS@
    </array>
    <key>CFBundleName</key>
    <string>Wish</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>@TK_VERSION@@TK_PATCH_LEVEL@</string>
    <key>CFBundleSignature</key>
    <string>WiSH</string>
    <key>CFBundleVersion</key>
    <string>@TK_VERSION@@TK_PATCH_LEVEL@</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.6.0</string>
    <key>LSRequiresCarbon</key>
    <true/>
    <key>NSAppleScriptEnabled</key>
    <true/>
    <key>OSAScriptingDefinition</key>
    <string>Wish.sdef</string>
    <key>NSHighResolutionCapable</key>
    <string>True</string>
	<key>CFBundleExecutable</key>
	<string>Wish</string>
	<key>CFBundleGetInfoString</key>
	<string>Wish Shell @TK_VERSION@@TK_PATCH_LEVEL@,
	Copyright © 1989-@TK_YEAR@ Tcl Core Team,
	Copyright © 1989-@TK_YEAR@ Contributors,
	Copyright © 2011-@TK_YEAR@ Kevin Walzer/WordTech
	Communications LLC,
	Copyright © 2014-@TK_YEAR@ Marc Culler,
	Copyright © 2002-@TK_YEAR@ Daniel A. Steffen,
	Copyright © 2001-2009 Apple Inc.,
	Copyright © 2001-2002 Jim Ingham &amp; Ian Reid</string>
	<key>CFBundleIconFile</key>
	<string>Wish.icns</string>
	<key>CFBundleIdentifier</key>
	<string>com.tcltk.wish</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleLocalizations</key>
	<array>
		@CFBUNDLELOCALIZATIONS@
	</array>
	<key>CFBundleName</key>
	<string>Wish</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>@TK_VERSION@@TK_PATCH_LEVEL@</string>
	<key>CFBundleSignature</key>
	<string>WiSH</string>
	<key>CFBundleVersion</key>
	<string>@TK_VERSION@@TK_PATCH_LEVEL@</string>
	<key>LSMinimumSystemVersion</key>
	<string>10.5.0</string>
	<key>LSRequiresCarbon</key>
	<true/>
	<key>NSAppleScriptEnabled</key>
	<true/>
	<key>OSAScriptingDefinition</key>
	<string>Wish.sdef</string>
	<key>NSHighResolutionCapable</key>
	<string>True</string>
    <key>NSServices</key>
    <array>
      <dict>
	<key>NSMessage</key>
	<string>provideService</string>
	<key>NSPortName</key>
	<string>Wish</string>
	<key>NSSendTypes</key>
	<array>
          <string>NSStringPboardType</string>
          <string>NSPasteboardTypeString</string>
	</array>
      </dict>
</dict>
    </array>
  </dict>
</plist>

Changes to macosx/Wish.sdef.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
25
26
27
28
29
30
31









32
33
34
35
36
37







-
-
-
-
-
-
-
-
-






		<command name="quit" code="aevtquit" description="Quit the application."/>
	</suite>
	<suite name="Wish Suite" code="WIsH" description="Commands for the Wish application.">
		<command name="do script" code="miscdosc" description="Execute a Tcl script.">
			<direct-parameter description="Script to execute" type="text">
				<type type="text"/>
			</direct-parameter>
			<result description="Result">
				<type type="text"/>
			</result>
		</command>
			<command name="open location" code="GURLGURL"
				 description="Open a URL.">
			<direct-parameter description="URL" type="text">
				<type type="text"/>
			</direct-parameter>
			<result description="Result">
				<type type="text"/>
			</result>
		</command>
	</suite>
</dictionary>

Changes to macosx/tkMacOSX.h.

22
23
24
25
26
27
28
29

30
31
32
33
34
22
23
24
25
26
27
28

29
30
31
32
33
34







-
+





 * Structures and function types for handling Netscape-type in process
 * embedding where Tk does not control the top-level
 */

typedef int (Tk_MacOSXEmbedRegisterWinProc) (long winID, Tk_Window window);
typedef void* (Tk_MacOSXEmbedGetGrafPortProc) (Tk_Window window);
typedef int (Tk_MacOSXEmbedMakeContainerExistProc) (Tk_Window window);
typedef void (Tk_MacOSXEmbedGetClipProc) (Tk_Window window, void *rgn);
typedef void (Tk_MacOSXEmbedGetClipProc) (Tk_Window window, TkRegion rgn);
typedef void (Tk_MacOSXEmbedGetOffsetInParentProc) (Tk_Window window, void *ulCorner);

#include "tkPlatDecls.h"

#endif /* _TKMAC */

Changes to macosx/tkMacOSXBitmap.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61


62
63
64
65


66
67
68
69
70
71
72
1
2
3
4
5



6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58


59
60
61
62


63
64
65
66
67
68
69
70
71





-
-
-
+
+
+






-











-
+




















-
+











-
-
+
+


-
-
+
+







/*
 * tkMacOSXBitmap.c --
 *
 *	This file handles the implementation of native bitmaps.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXConstants.h"

/*
 * This structure holds information about native bitmaps.
 */

typedef struct {
    const char *name;		/* Name of icon. */
    OSType iconType;		/* OSType of icon. */
} BuiltInIcon;

/*
 * This array maps a string name to the supported builtin icons
 * This array mapps a string name to the supported builtin icons
 * on the Macintosh.
 */

static BuiltInIcon builtInIcons[] = {
    {"document",	kGenericDocumentIcon},
    {"stationery",	kGenericStationeryIcon},
    {"edition",		kGenericEditionFileIcon},
    {"application",	kGenericApplicationIcon},
    {"accessory",	kGenericDeskAccessoryIcon},
    {"folder",		kGenericFolderIcon},
    {"pfolder",		kPrivateFolderIcon},
    {"trash",		kTrashIcon},
    {"floppy",		kGenericFloppyIcon},
    {"ramdisk",		kGenericRAMDiskIcon},
    {"cdrom",		kGenericCDROMIcon},
    {"preferences",	kGenericPreferencesIcon},
    {"querydoc",	kGenericQueryDocumentIcon},
    {"stop",		kAlertStopIcon},
    {"note",		kAlertNoteIcon},
    {"caution",		kAlertCautionIcon},
    {NULL,			0}
    {NULL}
};

#define builtInIconSize 32

static Tcl_HashTable iconBitmapTable = {};
typedef struct {
    int kind, width, height;
    char *value;
} IconBitmap;

static const char *const iconBitmapOptionStrings[] = {
    "-file", "-fileType", "-imageFile", "-namedImage", "-osType",
    "-systemType", NULL
    "-file", "-fileType", "-osType", "-systemType", "-namedImage",
    "-imageFile", NULL
};
enum iconBitmapOptions {
    ICON_FILE, ICON_FILETYPE, ICON_IMAGEFILE, ICON_NAMEDIMAGE, ICON_OSTYPE,
    ICON_SYSTEMTYPE
    ICON_FILE, ICON_FILETYPE, ICON_OSTYPE, ICON_SYSTEMTYPE, ICON_NAMEDIMAGE,
    ICON_IMAGEFILE,
};


/*
 *----------------------------------------------------------------------
 *
 * TkpDefineNativeBitmaps --
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119

120
121
122
123
124
125
126
127
128

129
130

131
132
133
134
135
136
137


138
139
140




141
142
143

144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109

110
111
112
113

114
115
116

117
118
119
120
121
122
123
124
125

126
127

128
129
130
131
132
133


134
135
136


137
138
139
140
141


142


143

144
145
146
147
148

149
150
151
152
153
154
155







-
+









-




-
+


-
+








-
+

-
+





-
-
+
+

-
-
+
+
+
+

-
-
+
-
-
+
-





-







	Tcl_HashEntry *predefHashPtr;
	Tk_Uid name;
	int isNew;

	name = Tk_GetUid(builtInPtr->name);
	predefHashPtr = Tcl_CreateHashEntry(tablePtr, name, &isNew);
	if (isNew) {
	    TkPredefBitmap *predefPtr = (TkPredefBitmap *)ckalloc(sizeof(TkPredefBitmap));
	    TkPredefBitmap *predefPtr = ckalloc(sizeof(TkPredefBitmap));

	    predefPtr->source = UINT2PTR(builtInPtr->iconType);
	    predefPtr->width = builtInIconSize;
	    predefPtr->height = builtInIconSize;
	    predefPtr->native = 1;
	    Tcl_SetHashValue(predefHashPtr, predefPtr);
	}
    }
}


/*
 *----------------------------------------------------------------------
 *
 * PixmapFromImage --
 * GetBitmapForIcon --
 *
 * Results:
 *	Returns a Pixmap with an NSImage drawn into it.
 *	Bitmap for the given IconRef.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Pixmap
PixmapFromImage(
GetBitmapForIcon(
    Display *display,
    NSImage* image,
    IconRef icon,
    CGSize size)
{
    TkMacOSXDrawingContext dc;
    Pixmap pixmap;

    pixmap = Tk_GetPixmap(display, None, (int)size.width, (int)size.height, 0);
    if (TkMacOSXSetupDrawingContext(pixmap, NULL, &dc)) {
    pixmap = Tk_GetPixmap(display, None, size.width, size.height, 0);
    if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
	if (dc.context) {
	    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
				    .tx = 0, .ty = size.height};
	    const CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
		    .tx = 0, .ty = size.height };
	    const CGRect r = { .origin = { .x = 0, .y = 0 }, .size = size };

	    CGContextConcatCTM(dc.context, t);
	    [NSGraphicsContext saveGraphicsState];
	    [NSGraphicsContext setCurrentContext:GET_NSCONTEXT(dc.context, NO)];
	    PlotIconRefInContext(dc.context, &r, kAlignAbsoluteCenter,
	    [image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
		operation:NSCompositeCopy fraction:1.0];
		    kTransformNone, NULL, kPlotIconRefNormalFlags, icon);
	    [NSGraphicsContext restoreGraphicsState];
	}
	TkMacOSXRestoreDrawingContext(&dc);
    }
    return pixmap;
}


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateNativeBitmap --
 *
 *	Create native bitmap.
168
169
170
171
172
173
174



175
176
177
178
179
180
181













182
183
184
185
186
187
188
164
165
166
167
168
169
170
171
172
173







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193







+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







 */

Pixmap
TkpCreateNativeBitmap(
    Display *display,
    const void *source)		/* Info about the icon to build. */
{
    Pixmap pixmap;
    IconRef icon;
    OSErr err;
    NSString *filetype = TkMacOSXOSTypeToUTI(PTR2UINT(source));
    NSImage *iconImage = TkMacOSXIconForFileType(filetype);
    CGSize size = CGSizeMake(builtInIconSize, builtInIconSize);
    Pixmap pixmap = PixmapFromImage(display, iconImage, size);
    return pixmap;
}


    err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
	    PTR2UINT(source), &icon);
    if (err == noErr) {
	pixmap = GetBitmapForIcon(display, icon, CGSizeMake(builtInIconSize,
		builtInIconSize));
	ReleaseIconRef(icon);
    } else {
	pixmap = Tk_GetPixmap(display, None, builtInIconSize,
		builtInIconSize, 0);
    }
    return pixmap;
}

/*
 *----------------------------------------------------------------------
 *
 * OSTypeFromString --
 *
 *	Helper to convert string to OSType.
198
199
200
201
202
203
204
205

206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
203
204
205
206
207
208
209

210
211
212

213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228







-
+


-
+








-








static int
OSTypeFromString(const char *s, OSType *t) {
    int result = TCL_ERROR;
    Tcl_DString ds;
    Tcl_Encoding encoding = Tcl_GetEncoding(NULL, "macRoman");

    (void)Tcl_UtfToExternalDString(encoding, s, TCL_INDEX_NONE, &ds);
    Tcl_UtfToExternalDString(encoding, s, -1, &ds);
    if (Tcl_DStringLength(&ds) <= 4) {
	char string[4] = {};
	memcpy(string, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
	memcpy(string, Tcl_DStringValue(&ds), (size_t) Tcl_DStringLength(&ds));
	*t = (OSType) string[0] << 24 | (OSType) string[1] << 16 |
	     (OSType) string[2] <<  8 | (OSType) string[3];
	result = TCL_OK;
    }
    Tcl_DStringFree(&ds);
    Tcl_FreeEncoding(encoding);
    return result;
}


/*
 *----------------------------------------------------------------------
 *
 * TkpGetNativeAppBitmap --
 *
 *	Get a named native bitmap.
246
247
248
249
250
251
252

253
254
255
256

257
258
259
260
261
262
263
264
265
266
267

268
269
270
271
272


273
274
275
276
277
278
279
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270
271

272
273
274
275


276
277
278
279
280
281
282
283
284







+



-
+










-
+



-
-
+
+







    int *height)
{
    Tcl_HashEntry *hPtr;
    Pixmap pixmap = None;
    NSString *string;
    NSImage *image = nil;
    NSSize size = { .width = builtInIconSize, .height = builtInIconSize };

    if (iconBitmapTable.buckets &&
	    (hPtr = Tcl_FindHashEntry(&iconBitmapTable, name))) {
	OSType type;
	IconBitmap *iconBitmap = (IconBitmap *)Tcl_GetHashValue(hPtr);
	IconBitmap *iconBitmap = Tcl_GetHashValue(hPtr);
	name = NULL;
	size = NSMakeSize(iconBitmap->width, iconBitmap->height);
	switch (iconBitmap->kind) {
	case ICON_FILE:
	    string = [[NSString stringWithUTF8String:iconBitmap->value]
		    stringByExpandingTildeInPath];
	    image = [[NSWorkspace sharedWorkspace] iconForFile:string];
	    break;
	case ICON_FILETYPE:
	    string = [NSString stringWithUTF8String:iconBitmap->value];
	    image = TkMacOSXIconForFileType(string);
	    image = [[NSWorkspace sharedWorkspace] iconForFileType:string];
	    break;
	case ICON_OSTYPE:
	    if (OSTypeFromString(iconBitmap->value, &type) == TCL_OK) {
		string = [NSString stringWithUTF8String:iconBitmap->value];
		image = TkMacOSXIconForFileType(string);
		string = NSFileTypeForHFSTypeCode(type);
		image = [[NSWorkspace sharedWorkspace] iconForFileType:string];
	    }
	    break;
	case ICON_SYSTEMTYPE:
	    name = iconBitmap->value;
	    break;
	case ICON_NAMEDIMAGE:
	    string = [NSString stringWithUTF8String:iconBitmap->value];
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304
305
306


307






























308
309
310
311
312
313
314
315


316

317
318
319
320







321
322

323
324
325
326
327
328
329
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344





345
346
347
348

349




350
351
352
353
354
355
356


357
358
359
360
361
362
363
364







-
+










+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-


+
+
-
+
-
-
-
-
+
+
+
+
+
+
+
-
-
+







	if (image) {
	    [image setSize:size];
	}
    } else {
	string = [NSString stringWithUTF8String:name];
	image = [NSImage imageNamed:string];
	if (!image) {
	    NSURL *url = [NSURL fileURLWithPath:string];
	    NSURL *url = [NSURL URLWithString:string];
	    if (url) {
		image = [[[NSImage alloc] initWithContentsOfURL:url]
			autorelease];
	    }
	}
	if (image) {
	    size = [image size];
	}
    }
    if (image) {
	TkMacOSXDrawingContext dc;
	int depth = 0;
	pixmap = PixmapFromImage(display, image, NSSizeToCGSize(size));

#ifdef MAC_OSX_TK_TODO
	for (NSImageRep *r in [image representations]) {
	    NSInteger bitsPerSample = [r bitsPerSample];
	    if (bitsPerSample && bitsPerSample > depth) {
		depth = bitsPerSample;
	    };
	}
	if (depth == 1) {
	    /* TODO: convert BW NSImage to CGImageMask */
	}
#endif
	pixmap = Tk_GetPixmap(display, None, size.width, size.height, depth);
	*width = size.width;
	*height = size.height;
	if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
	    if (dc.context) {
		CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
			.tx = 0, .ty = size.height};

		CGContextConcatCTM(dc.context, t);
		[NSGraphicsContext saveGraphicsState];
		[NSGraphicsContext setCurrentContext:[NSGraphicsContext
			graphicsContextWithGraphicsPort:dc.context flipped:NO]];
		[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
			operation:NSCompositeCopy fraction:1.0];
		[NSGraphicsContext restoreGraphicsState];
	    }
	    TkMacOSXRestoreDrawingContext(&dc);
	}
    } else if (name) {
	/*
	 * As a last resort, try to interpret the name as an OSType.
	 * It would probably be better to just return None at this
	 * point.
	 */
	OSType iconType;
	if (OSTypeFromString(name, &iconType) == TCL_OK) {
	    IconRef icon;
	    OSErr err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
	    NSString *iconUTI = TkMacOSXOSTypeToUTI(iconType);
		    iconType, &icon);
	    NSImage *iconImage = TkMacOSXIconForFileType(iconUTI);
	    pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
	}
    }
	    if (err == noErr) {
		pixmap = GetBitmapForIcon(display, icon, NSSizeToCGSize(size));
		*width = size.width;
		*height = size.height;
		ReleaseIconRef(icon);
	    }
	}
    *width = (int)size.width;
    *height = (int)size.height;
    }
    return pixmap;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXIconBitmapObjCmd --
337
338
339
340
341
342
343
344

345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388

389
390
391
392
393
394

395
396
397
398
399
400

401
402
403
404
405
406
407

408
409
410

411
412
413
414
415
416
417
372
373
374
375
376
377
378

379
380
381
382
383
384

385

386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420
421

422
423
424
425
426
427

428
429
430
431
432
433

434
435
436
437
438
439
440

441
442
443

444
445
446
447
448
449
450
451







-
+





-
+
-











-
+















-
+








-
+





-
+





-
+






-
+


-
+







 *	none
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXIconBitmapObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Unused. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tcl_HashEntry *hPtr;
    int isNew, result = TCL_ERROR;
    int i = 1, len, isNew, result = TCL_ERROR;
    Tcl_Size i = 1, len;
    const char *name, *value;
    IconBitmap ib, *iconBitmap;

    if (objc != 6) {
	Tcl_WrongNumArgs(interp, 1, objv, "name width height "
		"-file|-fileType|-osType|-systemType|-namedImage|-imageFile "
		"value");
	goto end;
    }
    name = Tcl_GetStringFromObj(objv[i++], &len);
    if (!len) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("empty bitmap name", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("empty bitmap name", -1));
	Tcl_SetErrorCode(interp, "TK", "MACBITMAP", "BAD", NULL);
	goto end;
    }
    if (Tcl_GetIntFromObj(interp, objv[i++], &ib.width) != TCL_OK) {
	goto end;
    }
    if (Tcl_GetIntFromObj(interp, objv[i++], &ib.height) != TCL_OK) {
	goto end;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[i++], iconBitmapOptionStrings,
	    sizeof(char *), "kind", TCL_EXACT, &ib.kind) != TCL_OK) {
	goto end;
    }
    value = Tcl_GetStringFromObj(objv[i++], &len);
    if (!len) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("empty bitmap value", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("empty bitmap value", -1));
	Tcl_SetErrorCode(interp, "TK", "MACBITMAP", "EMPTY", NULL);
	goto end;
    }
#if 0
    if ((kind == ICON_TYPE || kind == ICON_SYSTEM)) {
	Tcl_DString ds;
 	Tcl_Encoding encoding = Tcl_GetEncoding(NULL, "macRoman");

	(void)Tcl_UtfToExternalDString(encoding, value, TCL_INDEX_NONE, &ds);
	Tcl_UtfToExternalDString(encoding, value, -1, &ds);
	len = Tcl_DStringLength(&ds);
	Tcl_DStringFree(&ds);
	Tcl_FreeEncoding(encoding);
	if (len > 4) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "invalid bitmap value", TCL_INDEX_NONE));
		    "invalid bitmap value", -1));
	    Tcl_SetErrorCode(interp, "TK", "MACBITMAP", "INVALID", NULL);
	    goto end;
	}
    }
#endif
    ib.value = (char *)ckalloc(len + 1);
    ib.value = ckalloc(len + 1);
    strcpy(ib.value, value);
    if (!iconBitmapTable.buckets) {
	Tcl_InitHashTable(&iconBitmapTable, TCL_STRING_KEYS);
    }
    hPtr = Tcl_CreateHashEntry(&iconBitmapTable, name, &isNew);
    if (!isNew) {
	iconBitmap = (IconBitmap *)Tcl_GetHashValue(hPtr);
	iconBitmap = Tcl_GetHashValue(hPtr);
	ckfree(iconBitmap->value);
    } else {
	iconBitmap = (IconBitmap *)ckalloc(sizeof(IconBitmap));
	iconBitmap = ckalloc(sizeof(IconBitmap));
	Tcl_SetHashValue(hPtr, iconBitmap);
    }
    *iconBitmap = ib;
    result = TCL_OK;
  end:
    return result;
}

Changes to macosx/tkMacOSXButton.c.

1
2
3
4
5


6
7
8
9
10
11
12






13
14
15
16
17
18
19
20
21
22

23
24
25
26

27


28
29








30
31
32
33




34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
1
2
3


4
5
6






7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65



-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+










+




+

+
+
-
-
+
+
+
+
+
+
+
+


-
-
+
+
+
+












+







/*
 * tkMacOSXButton.c --
 *
 *	This file implements the Macintosh specific portion of the button
 *	widgets.
 *	This file implements the Macintosh specific portion of the
 *	button widgets.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright © 2001 Apple Computer, Inc.
 * Copyright © 2006-2007 Daniel A. Steffen <[email protected]>
 * Copyright © 2007 Revar Desmera.
 * Copyright © 2015 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2015 Marc Culler.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
 * Copyright 2007 Revar Desmera.
 * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
 * Copyright 2015 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include "tkMacOSXPrivate.h"
#include "tkButton.h"
#include "tkMacOSXFont.h"
#include "tkMacOSXDebug.h"


#define FIRST_DRAW	    2
#define ACTIVE		    4


/*
 * Default insets for controls
 */
 * Extra padding used for computing the content size that should
 * be allowed when drawing the HITheme button.

#define DEF_INSET_LEFT 12
#define DEF_INSET_RIGHT 12
#define DEF_INSET_TOP 1
#define DEF_INSET_BOTTOM 1

/*
 * Some defines used to control what type of control is drawn.
 */

#define HI_PADX 14
#define HI_PADY 1
#define DRAW_LABEL	0	/* Labels are treated genericly. */
#define DRAW_CONTROL	1	/* Draw using the Native control. */
#define DRAW_CUSTOM	2	/* Make our own button drawing. */
#define DRAW_BEVEL	3

/*
 * The delay in milliseconds between pulsing default button redraws.
 */
#define PULSE_TIMER_MSECS 62   /* Largest value that didn't look stuttery */

/*
 * Declaration of Mac specific button structure.
 */


typedef struct {
    int drawType;
    Tk_3DBorder border;
    int relief;
    int offset;			/* 0 means this is a normal widget. 1 means
				 * it is an image button, so we offset the
				 * image to make the button appear to move
				 * up and down as the relief changes. */
    GC gc;
66
67
68
69
70
71
72

73
74


75
76
77
78



79
80
81


82
83
84


85
86

87
88
89



90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111



112
113
114
115
116
117
118
119
120
121
122
123
124
125

126

127
128
129
130
131
132
133
79
80
81
82
83
84
85
86


87
88




89
90
91



92
93



94
95


96



97
98
99
100
101
102
103
104
105
106
107


108
109
110

111
112
113
114
115
116



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142







+
-
-
+
+
-
-
-
-
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
+
+
+








-
-



-
+





-
-
-
+
+
+













-
+

+







    Tcl_TimerToken defaultPulseHandler;
} MacButton;

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


static void	ButtonBackgroundDrawCB(const HIRect *btnbounds,
		    MacButton *ptr, SInt16 depth, Boolean isColorDev);
static void ButtonBackgroundDrawCB (const HIRect *btnbounds, MacButton *ptr,
        SInt16 depth, Boolean isColorDev);
static void	ButtonContentDrawCB(const HIRect *bounds,
		    ThemeButtonKind kind,
		    const HIThemeButtonDrawInfo *info, MacButton *ptr,
		    SInt16 depth, Boolean isColorDev);
static void ButtonContentDrawCB (const HIRect *bounds, ThemeButtonKind kind,
        const HIThemeButtonDrawInfo *info, MacButton *ptr, SInt16 depth,
	Boolean isColorDev);
static void	ButtonEventProc(void *clientData,
		    XEvent *eventPtr);
static void	TkMacOSXComputeButtonParams(TkButton *butPtr,
static void ButtonEventProc(ClientData clientData, XEvent *eventPtr);
static void TkMacOSXComputeButtonParams (TkButton * butPtr, ThemeButtonKind* btnkind,
		    ThemeButtonKind *btnkind,
		    HIThemeButtonDrawInfo *drawinfo);
static int	TkMacOSXComputeButtonDrawParams(TkButton *butPtr,
	HIThemeButtonDrawInfo* drawinfo);
static int TkMacOSXComputeButtonDrawParams (TkButton * butPtr, DrawParams * dpPtr);
		    DrawParams * dpPtr);
static void	TkMacOSXDrawButton(MacButton *butPtr, GC gc,
static void TkMacOSXDrawButton (MacButton *butPtr, GC gc, Pixmap pixmap);
		    Pixmap pixmap);
static void	DrawButtonImageAndText(TkButton *butPtr);
static void	PulseDefaultButtonProc(void *clientData);
static void DrawButtonImageAndText(TkButton* butPtr);
static void PulseDefaultButtonProc(ClientData clientData);


/*
 * The class procedure table for the button widgets.
 */

const Tk_ClassProcs tkpButtonProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    TkButtonWorldChanged,	/* worldChangedProc */
    NULL,
	NULL
};

static int bCount;


/*
 *----------------------------------------------------------------------
 *
 * TkpButtonSetDefaults --
 *
 *	This procedure is invoked before option tables are created for buttons.
 *	It modifies some of the default values to match the current values
 *	defined for this platform.
 *	This procedure is invoked before option tables are created for
 *	buttons. It modifies some of the default values to match the current
 *	values defined for this platform.
 *
 * Results:
 *	Some of the default values in *specPtr are modified.
 *
 * Side effects:
 *	Updates some of.
 *
 *----------------------------------------------------------------------
 */

void
TkpButtonSetDefaults()
{
    /*No-op.*/
/*No-op.*/
}


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateButton --
 *
 *	Allocate a new TkButton structure.
141
142
143
144
145
146
147
148

149
150
151

152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167
168


169
170
171
172
173
174
175


176
177
178
179
180
181
182

183
184
185


186
187
188
189
190
191
192
193
194
195

196
197

198
199
200
201







202
203
204
205
206
207
208
209
210
211
212

213
214
215
216

217
218
219

220
221
222
223
224
225

226
227
228
229
230
231
232
233
234

235
236
237
238
239

240
241

242
243
244
245
246



247
248
249
250
251
252
253
254
255
256
257



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275

276




277
278
279
280
281
282
283
284
285
286
287




288
289
290
291



292
293
294
295
296




297
298
299

300
301
302

303
304
305


306
307
308
309
310
311
312
313
314
315
316
317
318
319
320


321

322
323
324





325
326
327
328
329


330
331
332
333
334


335
336
337
338
339
340
341
342
343


344
345

346
347
348
349
350
351


352
353
354
355
356
357
358
359
360
361
362






363
364
365
366
367
368
369

370
371
372
373
374
375

376
377
378
379

380
381
382




383
384
385
386
387
388
389
390
391

392
393

394
395
396
397
398


399
400
401

402
403
404
405
406

407
408
409


410

411
412

413


414
415

416











417
418
419







420
421
422
423

424
425
426
427
428
429

430
431
432

433
434
435

436
437
438
439
440
441

442
443
444
445
446
447
448
449
450
451
452
453

















454
455
456
457
458

459

460
461

462
463
464
465
466
467
468
469

470
471
472

473
474
475
476
477
478







479
480
481
482
483
484
485
486
487
488
489
490
491
492
493














494
495
496
497
498




499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
















515
516
517
518
519
520
521
522
523
524










525
526

527
528
529
530
531
532
533
150
151
152
153
154
155
156

157
158
159

160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175


176
177
178
179
180
181
182


183
184
185
186
187
188
189
190

191
192


193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227


228


229

230
231


232


233
234


235


236
237
238
239
240


241


242


243


244





245
246
247
248
249
250
251
252
253
254
255



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277

278
279
280
281
282
283
284
285
286
287
288




289
290
291
292




293
294
295





296
297
298
299



300



301
302


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317


318
319
320
321



322
323
324
325
326
327
328



329
330
331
332
333


334
335
336
337
338
339
340
341
342


343
344
345

346
347
348
349
350


351
352
353
354
355
356
357
358





359
360
361
362
363
364







365
366
367
368
369


370
371
372


373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389


390





391
392
393
394

395





396

397

398
399
400
401
402

403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420



421
422
423
424
425
426
427
428
429
430

431
432
433
434
435
436

437
438
439

440
441
442

443
444
445
446
447
448

449
450
451










452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476

477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493


494
495
496
497
498
499
500
501
502
503












504
505
506
507
508
509
510
511
512
513
514
515
516
517
518




519
520
521
522
523















524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540









541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559







-
+


-
+







-
+







-
-
+
+





-
-
+
+






-
+

-
-
+
+










+

-
+




+
+
+
+
+
+
+









-
-
+
-
-

-
+

-
-
+
-
-


-
-
+
-
-





-
-
+
-
-

-
-
+
-
-
+
-
-
-
-
-
+
+
+








-
-
-
+
+
+
















-
+

+
-
+
+
+
+







-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
+
-
-
-
+

-
-
+
+













-
-
+
+

+
-
-
-
+
+
+
+
+


-
-
-
+
+



-
-
+
+







-
-
+
+

-
+




-
-
+
+






-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+




-
-
+


-
-
+



+
+
+
+








-
+
-
-
+
-
-
-
-
-
+
+


-
+
-
-
-
-
-
+
-

-
+
+

+

-
+

+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+



-
+





-
+


-
+


-
+





-
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





+
-
+

-
+







-
+



+




-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+







 *----------------------------------------------------------------------
 */

TkButton *
TkpCreateButton(
    Tk_Window tkwin)
{
    MacButton *macButtonPtr = (MacButton *)ckalloc(sizeof(MacButton));
    MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));

    Tk_CreateEventHandler(tkwin, ActivateMask,
	    ButtonEventProc, macButtonPtr);
	    ButtonEventProc, (ClientData) macButtonPtr);
    macButtonPtr->id = bCount++;
    macButtonPtr->flags = FIRST_DRAW;
    macButtonPtr->btnkind = kThemePushButton;
    macButtonPtr->defaultPulseHandler = NULL;
    bzero(&macButtonPtr->drawinfo, sizeof(macButtonPtr->drawinfo));
    bzero(&macButtonPtr->lastdrawinfo, sizeof(macButtonPtr->lastdrawinfo));

    return (TkButton *) macButtonPtr;
    return (TkButton *)macButtonPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayButton --
 *
 *	This procedure is invoked to display a button widget. It is normally
 *	invoked as an idle handler.
 *	This procedure is invoked to display a button widget. It is
 *	normally invoked as an idle handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands are output to X to display the button in its current mode. The
 *	REDRAW_PENDING flag is cleared.
 *	Commands are output to X to display the button in its
 *	current mode. The REDRAW_PENDING flag is cleared.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayButton(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    MacButton *macButtonPtr = (MacButton *)clientData;
    TkButton *butPtr = (TkButton *)clientData;
    MacButton *macButtonPtr = (MacButton *) clientData;
    TkButton *butPtr = (TkButton *) clientData;
    Tk_Window tkwin = butPtr->tkwin;
    Pixmap pixmap;
    DrawParams* dpPtr = &macButtonPtr->drawParams;
    int needhighlight = 0;

    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr)) {
    if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr) ) {
	macButtonPtr->useTkText = 0;
    } else {
	macButtonPtr->useTkText = 1;
    }


    /*
     * Set up clipping region. Make sure the we are using the port
     * for this button, or we will set the wrong window's clip.
     */

    if (macButtonPtr->useTkText) {
	if (butPtr->type == TYPE_BUTTON) {
	    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
		    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
	} else {
	    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
		    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
	}

        /*
	 * Display image or bitmap or text for labels or custom controls.
        /* Display image or bitmap or text for labels or custom controls.  */
	 */

	DrawButtonImageAndText(butPtr);
        needhighlight = 1;
        needhighlight  = 1;
    } else {
        /*
	 * Draw the native portion of the buttons.
        /* Draw the native portion of the buttons. */
	 */

        TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap);

        /*
	 * Ask for the highlight border, if needed.
        /* Draw highlight border, if needed. */
	 */

        if (butPtr->highlightWidth < 3) {
            needhighlight = 1;
        }
    }

    /*
     * Draw highlight border, if needed.
    /* Draw highlight border, if needed. */
     */

    if (needhighlight) {
	GC gc = NULL;
        if ((butPtr->flags & GOT_FOCUS) && butPtr->highlightColorPtr) {
        if ((butPtr->flags & GOT_FOCUS)) {
	    gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
	} else if (butPtr->type == TYPE_LABEL) {
            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
	    gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder), pixmap);
	}
	if (gc) {
	    TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
	}
                Tk_Width(tkwin), Tk_Height(tkwin),
                butPtr->highlightWidth, TK_RELIEF_SOLID);
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeButtonGeometry --
 *
 *	After changes in a button's text or bitmap, this procedure recomputes
 *	the button's geometry and passes this information along to the geometry
 *	manager for the window.
 *	After changes in a button's text or bitmap, this procedure
 *	recomputes the button's geometry and passes this information
 *	along to the geometry manager for the window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeButtonGeometry(
    TkButton *butPtr)		/* Button whose geometry may have changed. */
{
    int width = 0, height = 0, charWidth = 1, haveImage = 0, haveText = 0;
    int txtWidth = 0, txtHeight = 0;
    MacButton *mbPtr = (MacButton *) butPtr;
    MacButton *mbPtr = (MacButton*)butPtr;
    Tk_FontMetrics fm;
    DrawParams drawParams;
    char *text = Tcl_GetString(butPtr->textPtr);

    /*
     * First figure out the size of the contents of the button.
     */

    TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);

    /*
     * If the indicator is on, get its size.
     */

    if (butPtr->indicatorOn) {
	switch (butPtr->type) {
	case TYPE_RADIO_BUTTON:
	    GetThemeMetric(kThemeMetricRadioButtonWidth,
    if ( butPtr->indicatorOn ) {
      switch (butPtr->type) {
      case TYPE_RADIO_BUTTON:
	GetThemeMetric(kThemeMetricRadioButtonWidth, (SInt32 *)&butPtr->indicatorDiameter);
		    (SInt32 *) &butPtr->indicatorDiameter);
	    break;
	case TYPE_CHECK_BUTTON:
	    GetThemeMetric(kThemeMetricCheckBoxWidth,
	  break;
      case TYPE_CHECK_BUTTON:
	GetThemeMetric(kThemeMetricCheckBoxWidth, (SInt32 *)&butPtr->indicatorDiameter);
		    (SInt32 *) &butPtr->indicatorDiameter);
	    break;
	default:
	    break;
	}
	  break;
      default:
	break;
      }

	/*
	 * Allow 2px extra space next to the indicator.
      /* Allow 2px extra space next to the indicator. */
	 */

	butPtr->indicatorSpace = butPtr->indicatorDiameter + 2;
      butPtr->indicatorSpace = butPtr->indicatorDiameter + 2;
    } else {
	butPtr->indicatorSpace = 0;
	butPtr->indicatorDiameter = 0;
      butPtr->indicatorSpace = 0;
      butPtr->indicatorDiameter = 0;
    }

    if (butPtr->image != NULL) {
	Tk_SizeOfImage(butPtr->image, &width, &height);
	haveImage = 1;
    } else if (butPtr->bitmap != None) {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
	haveImage = 1;
    }

    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(butPtr->textLayout);
	butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
		text, TCL_INDEX_NONE, butPtr->wrapLength, butPtr->justify, 0,
		&butPtr->textWidth, &butPtr->textHeight);
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

	/*Remove extraneous padding around label widgets.*/
	txtWidth = butPtr->textWidth + 2*butPtr->padX;
	txtHeight = butPtr->textHeight + 2*butPtr->padY;
	haveText = 1;
	txtWidth = butPtr->textWidth;
	txtHeight = butPtr->textHeight + DEF_INSET_BOTTOM + DEF_INSET_TOP;
	charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(butPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
    }

    if (haveImage) {
	if (haveText) { /* Image and Text */
	    switch ((enum compound) butPtr->compound) {
    if (haveImage && haveText) { /* Image and Text */
	switch ((enum compound) butPtr->compound) {
	    case COMPOUND_TOP:
	    case COMPOUND_BOTTOM:
		/*
		* Image is above or below text.
		*/
		 * Image is above or below text.
		 */

		height += txtHeight + butPtr->padY;
		width = (width > txtWidth ? width : txtWidth);
		break;
	    case COMPOUND_LEFT:
	    case COMPOUND_RIGHT:
		/*
		* Image is left or right of text.
		*/
		 * Image is left or right of text.
		 */

		width += txtWidth + 2*butPtr->padX;
		width += txtWidth + butPtr->padX;
		height = (height > txtHeight ? height : txtHeight);
		break;
	    case COMPOUND_CENTER:
		/*
		* Image and text are superimposed.
		*/
		 * Image and text are superimposed.
		 */

		width = (width > txtWidth ? width : txtWidth);
		height = (height > txtHeight ? height : txtHeight);
		break;
	    default:
		break;
	    }
	}
	/* Image with or without text */
	width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace;
	height = butPtr->height > 0 ? butPtr->height : height;
	}
	width += butPtr->indicatorSpace;

    } else if (haveImage) { /* Image only */
      width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace;
      height = butPtr->height > 0 ? butPtr->height : height;
	if (butPtr->type == TYPE_BUTTON) {
	    /*
	     * Allow room to shift the image.
	     */
	    width += 2;
	    height += 2;
	}

    } else { /* Text only */
        width = txtWidth + butPtr->indicatorSpace;
	height = txtHeight;
	if (butPtr->width > 0) {
	    charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	    width = butPtr->width * charWidth + 2*butPtr->padX;
	   width = butPtr->width * charWidth;
	}
	if (butPtr->height > 0) {
	    Tk_GetFontMetrics(butPtr->tkfont, &fm);
	    height = butPtr->height * fm.linespace + 2*butPtr->padY;
	  height = butPtr->height * fm.linespace;
	}
    }

    /* Add padding */
    width  += 2 * butPtr->padX;
    height += 2 * butPtr->padY;

    /*
     * Now figure out the size of the border decorations for the button.
     */

    if (butPtr->highlightWidth < 0) {
	butPtr->highlightWidth = 0;
    }

    butPtr->inset = butPtr->borderWidth + butPtr->highlightWidth;
    butPtr->inset = 0;

    width += butPtr->inset*2;
    butPtr->inset += butPtr->highlightWidth;
    height += butPtr->inset*2;
    if ([NSApp macOSVersion] == 100600) {
	width += 12;
    }
    if (mbPtr->btnkind == kThemePushButton) {

    if (TkMacOSXComputeButtonDrawParams(butPtr,&drawParams)) {
        HIRect tmpRect;
    	HIRect contBounds;

        int paddingx = 0;
	/*
	 * A PushButton has a minimum size.  We make sure that we are not
	 * underestimating the size by requesting the content size of a
	 * Pushbutton whose overall size is our content size expanded by the
	 * standard padding.
        int paddingy = 0;
	 */

	tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY);
    	tmpRect = CGRectMake(0, 0, width, height);

        HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
        /* If the content region has a minimum height, match it. */
        if (height < contBounds.size.height) {
	    height = (int)contBounds.size.height;
    	  height = contBounds.size.height;
        }

        /* If the content region has a minimum width, match it. */
        if (width < contBounds.size.width) {
	    width = (int)contBounds.size.width;
    	  width = contBounds.size.width;
        }

        /* Pad to fill difference between content bounds and button bounds. */
    	paddingx = contBounds.origin.x;
    	paddingy = contBounds.origin.y;

        if (height < paddingx - 4) {
            /* can't have buttons much shorter than button side diameter. */
            height = paddingx - 4;
    	}

    } else {
	height += 2*HI_PADY;
	width += 2*HI_PADX;
    }
        height += butPtr->borderWidth*2;
        width += butPtr->borderWidth*2;
    }

    width += butPtr->inset*2;
    height += butPtr->inset*2;

    Tk_GeometryRequest(butPtr->tkwin, width, height);
    Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}


/*
 *----------------------------------------------------------------------
 *
 * DrawButtonImageAndText --
 *
 *	Draws the image and text associated with a button or label.
 *        Draws the image and text associated with a button or label.
 *
 * Results:
 *	None.
 *        None.
 *
 * Side effects:
 *	The image and text are drawn.
 *        The image and text are drawn.
 *
 *----------------------------------------------------------------------
 */
static void
DrawButtonImageAndText(
    TkButton *butPtr)
    TkButton* butPtr)
{

    MacButton *mbPtr = (MacButton *) butPtr;
    Tk_Window tkwin = butPtr->tkwin;
    Pixmap pixmap;
    int haveImage = 0, haveText = 0, pressed = 0;
    int imageWidth = 0, imageHeight = 0;
    int imageXOffset = 0, imageYOffset = 0;
    int textXOffset = 0, textYOffset = 0;
    int width = 0, height = 0;
    int fullWidth = 0, fullHeight = 0;
    DrawParams *dpPtr = &mbPtr->drawParams;
    MacButton *mbPtr = (MacButton*)butPtr;
    Tk_Window  tkwin  = butPtr->tkwin;
    Pixmap     pixmap;
    int        haveImage = 0;
    int        haveText = 0;
    int        imageWidth = 0;
    int        imageHeight = 0;
    int        imageXOffset = 0;
    int        imageYOffset = 0;
    int        textXOffset = 0;
    int        textYOffset = 0;
    int        width = 0;
    int        height = 0;
    int        fullWidth = 0;
    int        fullHeight = 0;
    int        pressed = 0;


    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }

    DrawParams* dpPtr = &mbPtr->drawParams;
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    pixmap = (Pixmap)Tk_WindowId(tkwin);

    if (butPtr->image != NULL) {
    if (butPtr->image != None) {
        Tk_SizeOfImage(butPtr->image, &width, &height);
        haveImage = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        haveImage = 1;
    }

    imageWidth = width;
    imageWidth  = width;
    imageHeight = height;

    if (mbPtr->drawinfo.state == kThemeStatePressed) {
        /* Offset bitmaps by a bit when the button is pressed. */
        pressed = 1;
    }

    haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
    if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { /* Image and Text */
        int x, y;
    if (haveImage && haveText) { /* Image and Text */
        int x;
        int y;
        textXOffset = 0;
        textYOffset = 0;
        fullWidth = 0;
        fullHeight = 0;

        switch ((enum compound) butPtr->compound) {
	case COMPOUND_TOP:
	case COMPOUND_BOTTOM:
	    /* Image is above or below text */
	    if (butPtr->compound == COMPOUND_TOP) {
		textYOffset = height + butPtr->padY;
	    } else {
		imageYOffset = butPtr->textHeight + butPtr->padY;
	    }
	    fullHeight = height + butPtr->textHeight + butPtr->padY;
	    fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth);
	    textXOffset = (fullWidth - butPtr->textWidth)/2;
	    imageXOffset = (fullWidth - width)/2;
	    break;
	case COMPOUND_BOTTOM: {
	  /* Image is above or below text */
	  if (butPtr->compound == COMPOUND_TOP) {
	    textYOffset = height + butPtr->padY;
	  } else {
	    imageYOffset = butPtr->textHeight + butPtr->padY;
	  }
	  fullHeight = height + butPtr->textHeight + butPtr->padY;
	  fullWidth = (width > butPtr->textWidth ? width :
		       butPtr->textWidth);
	  textXOffset = (fullWidth - butPtr->textWidth)/2;
	  imageXOffset = (fullWidth - width)/2;
	  break;
	}
	case COMPOUND_LEFT:
	case COMPOUND_RIGHT:
	    /*
	     * Image is left or right of text
	     */
	case COMPOUND_RIGHT: {
	  /*
	   * Image is left or right of text
	   */

	    if (butPtr->compound == COMPOUND_LEFT) {
		textXOffset = width + butPtr->padX;
	    } else {
		imageXOffset = butPtr->textWidth + butPtr->padX;
	    }
	    fullWidth = butPtr->textWidth + butPtr->padX + width;
	    fullHeight = (height > butPtr->textHeight ? height :
		    butPtr->textHeight);
	    textYOffset = (fullHeight - butPtr->textHeight)/2;
	    imageYOffset = (fullHeight - height)/2;
	    break;
	case COMPOUND_CENTER:
	    /*
	     * Image and text are superimposed
	     */
	  if (butPtr->compound == COMPOUND_LEFT) {
	    textXOffset = width + butPtr->padX;
	  } else {
	    imageXOffset = butPtr->textWidth + butPtr->padX;
	  }
	  fullWidth = butPtr->textWidth + butPtr->padX + width;
	  fullHeight = (height > butPtr->textHeight ? height :
                        butPtr->textHeight);
	  textYOffset = (fullHeight - butPtr->textHeight)/2;
	  imageYOffset = (fullHeight - height)/2;
	  break;
	}
	case COMPOUND_CENTER: {
	  /*
	   * Image and text are superimposed
	   */

	    fullWidth = (width > butPtr->textWidth ? width :
		    butPtr->textWidth);
	    fullHeight = (height > butPtr->textHeight ? height :
		    butPtr->textHeight);
	    textXOffset = (fullWidth - butPtr->textWidth)/2;
	    imageXOffset = (fullWidth - width)/2;
	    textYOffset = (fullHeight - butPtr->textHeight)/2;
	    imageYOffset = (fullHeight - height)/2;
	    break;
	  fullWidth = (width > butPtr->textWidth ? width :
		       butPtr->textWidth);
	  fullHeight = (height > butPtr->textHeight ? height :
                        butPtr->textHeight);
	  textXOffset = (fullWidth - butPtr->textWidth)/2;
	  imageXOffset = (fullWidth - width)/2;
	  textYOffset = (fullHeight - butPtr->textHeight)/2;
	  imageYOffset = (fullHeight - height)/2;
	  break;
	}
	default:
	    break;
	  break;
	}

        TkComputeAnchor(butPtr->anchor, tkwin,
                butPtr->padX + butPtr->borderWidth,
                butPtr->padY + butPtr->borderWidth,
                fullWidth + butPtr->indicatorSpace, fullHeight, &x, &y);
	x += butPtr->indicatorSpace;
541
542
543
544
545
546
547

548
549
550
551
552
553
554
555
556
557
558
559
560
561












562
563
564
565
566
567
568






569
570
571
572




573
574
575
576
577
578
579


580
581
582
583




584
585
586
587


588
589
590
591
592

593
594
595
596
597
598
599
600
601
602
603
604












605
606
607
608
609
610







611
612
613
614
615
616
617


618
619
620
621

622
623
624
625
626
627
628



629
630
631
632
633
634
635
567
568
569
570
571
572
573
574
575
576












577
578
579
580
581
582
583
584
585
586
587
588
589






590
591
592
593
594
595
596



597
598
599
600
601
602
603
604
605


606
607
608



609
610
611
612
613
614


615
616
617
618
619
620
621
622












623
624
625
626
627
628
629
630
631
632
633
634
635





636
637
638
639
640
641
642
643
644
645

646


647
648
649

650

651
652
653
654
655



656
657
658
659
660
661
662
663
664
665







+


-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
+





-
-
+
+

-
-
-
+
+
+
+


-
-
+
+





+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+
+



-

-
-
+
+

-

-
+




-
-
-
+
+
+







        }
        if (pressed) {
            x += dpPtr->offset;
            y += dpPtr->offset;
        }
        imageXOffset += x;
        imageYOffset += y;
        textYOffset -= 1;

        if (butPtr->image != NULL) {
	    if ((butPtr->selectImage != NULL) &&
		    (butPtr->flags & SELECTED)) {
		Tk_RedrawImage(butPtr->selectImage, 0, 0,
			width, height, pixmap, imageXOffset, imageYOffset);
	    } else if ((butPtr->tristateImage != NULL) &&
		    (butPtr->flags & TRISTATED)) {
		Tk_RedrawImage(butPtr->tristateImage, 0, 0,
			width, height, pixmap, imageXOffset, imageYOffset);
	    } else {
		Tk_RedrawImage(butPtr->image, 0, 0, width,
			height, pixmap, imageXOffset, imageYOffset);
	    }
	  if ((butPtr->selectImage != NULL) &&
	      (butPtr->flags & SELECTED)) {
	    Tk_RedrawImage(butPtr->selectImage, 0, 0,
			   width, height, pixmap, imageXOffset, imageYOffset);
	  } else if ((butPtr->tristateImage != NULL) &&
		     (butPtr->flags & TRISTATED)) {
	    Tk_RedrawImage(butPtr->tristateImage, 0, 0,
			   width, height, pixmap, imageXOffset, imageYOffset);
	  } else {
	    Tk_RedrawImage(butPtr->image, 0, 0, width,
			   height, pixmap, imageXOffset, imageYOffset);
	  }
        } else {
	    XSetClipOrigin(butPtr->display, dpPtr->gc,
		    imageXOffset, imageYOffset);
	    XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
		    0, 0, (unsigned int) width, (unsigned int) height,
		    imageXOffset, imageYOffset, 1);
	    XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
	  XSetClipOrigin(butPtr->display, dpPtr->gc,
			 imageXOffset, imageYOffset);
	  XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
		     0, 0, (unsigned int) width, (unsigned int) height,
		     imageXOffset, imageYOffset, 1);
	  XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
        }
	y += 1; /* Tweak to match native buttons. */
        Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
			  x + textXOffset, y + textYOffset, 0, -1);

        Tk_DrawTextLayout(butPtr->display, pixmap,
                dpPtr->gc, butPtr->textLayout,
                x + textXOffset, y + textYOffset, 0, -1);
        Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
                butPtr->textLayout,
                x + textXOffset, y + textYOffset,
                butPtr->underline);
    } else if (haveImage) { /* Image only */
        int x = 0, y;

        int x = 0;
	int y;
	TkComputeAnchor(butPtr->anchor, tkwin,
		butPtr->padX + butPtr->borderWidth,
		butPtr->padY + butPtr->borderWidth,
		width + butPtr->indicatorSpace, height, &x, &y);
			butPtr->padX + butPtr->borderWidth,
			butPtr->padY + butPtr->borderWidth,
			width + butPtr->indicatorSpace,
			height, &x, &y);
        x += butPtr->indicatorSpace;
	if (pressed) {
	    x += dpPtr->offset;
	    y += dpPtr->offset;
	  x += dpPtr->offset;
	  y += dpPtr->offset;
	}
	imageXOffset += x;
	imageYOffset += y;

	if (butPtr->image != NULL) {

	    if ((butPtr->selectImage != NULL) &&
		    (butPtr->flags & SELECTED)) {
		Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
			height, pixmap, imageXOffset, imageYOffset);
	    } else if ((butPtr->tristateImage != NULL) &&
		    (butPtr->flags & TRISTATED)) {
		Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
			height, pixmap, imageXOffset, imageYOffset);
	    } else {
		Tk_RedrawImage(butPtr->image, 0, 0, width, height,
			pixmap, imageXOffset, imageYOffset);
	    }
	  if ((butPtr->selectImage != NULL) &&
	      (butPtr->flags & SELECTED)) {
	    Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
			   height, pixmap, imageXOffset, imageYOffset);
	  } else if ((butPtr->tristateImage != NULL) &&
		     (butPtr->flags & TRISTATED)) {
	    Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
			   height, pixmap, imageXOffset, imageYOffset);
	  } else {
	    Tk_RedrawImage(butPtr->image, 0, 0, width, height,
			   pixmap, imageXOffset, imageYOffset);
	  }
	} else {
	    XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
	    XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
		    0, 0, (unsigned int) width, (unsigned int) height,
		    imageXOffset, imageYOffset, 1);
	    XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
	  XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
	  XCopyPlane(butPtr->display, butPtr->bitmap,
		     pixmap, dpPtr->gc,
		     0, 0, (unsigned int) width,
		     (unsigned int) height,
		     imageXOffset, imageYOffset, 1);
	  XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
	}
    } else { /* Text only */
        int x, y;

	TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
		butPtr->textWidth + butPtr->indicatorSpace,
		butPtr->textHeight, &x, &y);
			butPtr->textWidth + butPtr->indicatorSpace,
			  butPtr->textHeight, &x, &y);
	x += butPtr->indicatorSpace;
	y += 1; /* Tweak to match native buttons */
	Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
			  x, y, 0, -1);
			  x, y - DEF_INSET_BOTTOM, 0, -1);
    }

    /*
     * If the button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect.  If the widget is
     * selected and we use a different background color when selected, must
     * temporarily modify the GC so the stippling is the right color.
     * foreground color, generate the stippled effect.  If the widget
     * is selected and we use a different background color when selected,
     * must temporarily modify the GC so the stippling is the right color.
     */

    if (mbPtr->useTkText) {
        if ((butPtr->state == STATE_DISABLED)
                && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
            if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
                    && (butPtr->selectBorder != NULL)) {
659
660
661
662
663
664
665
666

667
668
669
670



671
672
673
674






675
676
677
678
679
680
681
689
690
691
692
693
694
695

696




697
698
699
700
701


702
703
704
705
706
707
708
709
710
711
712
713
714







-
+
-
-
-
-
+
+
+


-
-
+
+
+
+
+
+








        /*
         * Draw the border and traversal highlight last.  This way, if the
         * button's contents overflow they'll be covered up by the border.
         */

        if (dpPtr->relief != TK_RELIEF_FLAT) {
	    int inset = butPtr->highlightWidth;
            int inset = butPtr->highlightWidth;

	    Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
		    Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
		    butPtr->borderWidth, dpPtr->relief);
            Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
                Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
                butPtr->borderWidth, dpPtr->relief);
        }
    }
}


   }




/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyButton --
 *
 *	Free data structures associated with the button control.
 *
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708



709
710
711
712
713
714
715
716
717
718
719
720
721
722

723
724
725
726
727
728
729



730
731

732


733
734
735
736
737




738
739

740
741
742
743
744
745
746
747

748
749
750













751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776


777
778
779
780


781
782

783
784
785
786
787
788
789
790
791
792
793
794
795
796
797


798
799
800
801
802
803
804
805
806
807
808
809
810


811
812
813


814
815
816
817



818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833






834
835
836
837
838
839
840
722
723
724
725
726
727
728

729
730
731
732
733
734
735
736
737
738


739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754

755
756
757
758
759



760
761
762
763

764
765
766
767
768
769
770


771
772
773
774
775

776
777
778
779
780
781
782
783

784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802

803
804
805
806
807
808
809
810
















811
812
813
814
815

816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832


833
834
835
836
837
838
839
840
841
842
843

844


845
846
847


848
849
850



851
852
853
854
855
856
857
858
859

860
861
862
863






864
865
866
867
868
869
870
871
872
873
874
875
876







-










-
-
+
+
+













-
+




-
-
-
+
+
+

-
+

+
+



-
-
+
+
+
+

-
+







-
+



+
+
+
+
+
+
+
+
+
+
+
+
+


-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+



-
+
+

-
+













-
-
+
+









-

-
-
+
+

-
-
+
+

-
-
-
+
+
+






-
+



-
-
-
-
-
-
+
+
+
+
+
+







 */

void
TkpDestroyButton(
    TkButton *butPtr)
{
    MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */

    if (mbPtr->defaultPulseHandler) {
        Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkMacOSXDrawButton --
 *
 *        This function draws the tk button using Mac controls. In addition,
 *        this code may apply custom colors passed in the TkButton.
 *        This function draws the tk button using Mac controls
 *        In addition, this code may apply custom colors passed
 *        in the TkButton.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *      The control is created, or reinitialised as needed
 *
 *--------------------------------------------------------------
 */

static void
TkMacOSXDrawButton(
    MacButton *mbPtr,    /* Mac button. */
    TCL_UNUSED(GC),      /* The GC we are drawing into - needed for
    GC gc,               /* The GC we are drawing into - needed for
                          * the bevel button */
    Pixmap pixmap)       /* The pixmap we are drawing into - needed
                          * for the bevel button */
{
    TkButton *butPtr = (TkButton *) mbPtr;
    TkWindow *winPtr = (TkWindow *) butPtr->tkwin;
    HIRect cntrRect;
    TkButton * butPtr = ( TkButton *)mbPtr;
    TkWindow * winPtr;
    HIRect      cntrRect;
    TkMacOSXDrawingContext dc;
    DrawParams *dpPtr = &mbPtr->drawParams;
    DrawParams* dpPtr = &mbPtr->drawParams;
    int useNewerHITools = 1;

    winPtr = (TkWindow *)butPtr->tkwin;

    TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);

    cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff,
	    Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin));
    cntrRect = CGRectMake(winPtr->privatePtr->xOff,
			  winPtr->privatePtr->yOff,
			  Tk_Width(butPtr->tkwin),
			  Tk_Height(butPtr->tkwin));

    cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset);
     cntrRect = CGRectInset(cntrRect,  butPtr->inset, butPtr->inset);

    if (useNewerHITools == 1) {
        HIRect contHIRec;
        static HIThemeButtonDrawInfo hiinfo;

        ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true);

	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}


	if (mbPtr->btnkind == kThemePushButton) {
	    /*
	     * For some reason, pushbuttons get drawn a bit
	     * too low, normally.  Correct for this.
	     */
	    if (cntrRect.size.height < 22) {
		cntrRect.origin.y -= 1;
	    } else if (cntrRect.size.height < 23) {
		cntrRect.origin.y -= 2;
	    }
	}

        hiinfo.version = 0;
        hiinfo.state = mbPtr->drawinfo.state;
        hiinfo.kind = mbPtr->btnkind;
        hiinfo.kind  = mbPtr->btnkind;
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
            hiinfo.animation.time.start = hiinfo.animation.time.current;
        }

	/*
	 * To avoid buttons with white text on a white background, we set the
	 * state to inactive in Dark Mode unless the button is pressed or is a
	 * -default active button.  This isn't perfect but it is mostly usable.
	 * Using a ttk::button would be a much better choice, however.
	 */

	if ([NSApp macOSVersion] < 101500) {
	    if (TkMacOSXInDarkMode(butPtr->tkwin) &&
		mbPtr->drawinfo.state != kThemeStatePressed &&
		!(mbPtr->drawinfo.adornment & kThemeAdornmentDefault)) {
		hiinfo.state = kThemeStateInactive;
	    }
	}
	HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
		kHIThemeOrientationNormal, &contHIRec);
	HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal,
			  &contHIRec);

	TkMacOSXRestoreDrawingContext(&dc);
        ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo,
		(MacButton *) mbPtr, 32, true);
			    (MacButton *)mbPtr, 32, true);

    } else {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}

	TkMacOSXRestoreDrawingContext(&dc);
    }
    mbPtr->lastdrawinfo = mbPtr->drawinfo;
}

/*
 *--------------------------------------------------------------
 *
 * ButtonBackgroundDrawCB --
 *
 *        This function draws the background that lies under checkboxes and
 *        radiobuttons.
 *        This function draws the background that
 *        lies under checkboxes and radiobuttons.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        The background gets updated to the current color.
 *
 *--------------------------------------------------------------
 */

static void
ButtonBackgroundDrawCB(
    TCL_UNUSED(const HIRect *),
ButtonBackgroundDrawCB (
    const HIRect * btnbounds,
    MacButton *ptr,
    TCL_UNUSED(SInt16),
    TCL_UNUSED(Boolean))
    SInt16 depth,
    Boolean isColorDev)
{
    MacButton *mbPtr = (MacButton *) ptr;
    TkButton *butPtr = (TkButton *) mbPtr;
    Tk_Window tkwin = butPtr->tkwin;
    MacButton* mbPtr = (MacButton*)ptr;
    TkButton* butPtr = (TkButton*)mbPtr;
    Tk_Window  tkwin  = butPtr->tkwin;
    Pixmap pixmap;
    int usehlborder = 0;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    pixmap = (Pixmap)Tk_WindowId(tkwin);

    if (butPtr->type != TYPE_LABEL) {
        switch (mbPtr->btnkind) {
	case kThemeSmallBevelButton:
	case kThemeBevelButton:
	case kThemeRoundedBevelButton:
	case kThemePushButton:
	    usehlborder = 1;
	    break;
            case kThemeSmallBevelButton:
            case kThemeBevelButton:
            case kThemeRoundedBevelButton:
            case kThemePushButton:
                usehlborder = 1;
                break;
        }
    }
    if (usehlborder) {
        Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
            Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
    } else {
        Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
855
856
857
858
859
860
861
862
863
864



865
866
867


868
869
870


871
872
873
874
875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890


891
892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907


908
909
910
911
912
913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
928
929
930
931
932
933



934
935
936
937
938
939
940
941
942
943
944
945
946
947
948



949
950

951
952
953
954
955
956
957
958
959
960
961
962

963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980

















981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999














1000
1001
1002
1003


1004
1005
1006
1007
1008
1009
1010
891
892
893
894
895
896
897



898
899
900
901


902
903
904


905
906
907
908
909
910
911


912



913
914
915
916
917
918
919
920


921
922
923
924
925
926
927
928
929
930
931
932
933
934

935
936
937


938
939
940
941
942
943
944
945
946
947
948
949
950
951

952
953
954
955
956
957
958
959
960
961
962



963
964
965
966
967
968
969
970
971
972
973
974
975
976
977



978
979
980
981

982
983
984
985
986
987
988
989
990
991
992
993

994
995

















996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017














1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038
1039
1040
1041
1042
1043







-
-
-
+
+
+

-
-
+
+

-
-
+
+





-
-
+
-
-
-








-
-
+
+












-
+


-
-
+
+












-
+










-
-
-
+
+
+












-
-
-
+
+
+

-
+











-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+
+







 * Side effects:
 *        The content of the button gets updated.
 *
 *--------------------------------------------------------------
 */
static void
ButtonContentDrawCB (
    TCL_UNUSED(const HIRect *),
    TCL_UNUSED(ThemeButtonKind),
    TCL_UNUSED(const HIThemeButtonDrawInfo *),
    const HIRect * btnbounds,
    ThemeButtonKind kind,
    const HIThemeButtonDrawInfo *drawinfo,
    MacButton *ptr,
    TCL_UNUSED(SInt16),
    TCL_UNUSED(Boolean))
    SInt16 depth,
    Boolean isColorDev)
{
    TkButton *butPtr = (TkButton *) ptr;
    Tk_Window tkwin = butPtr->tkwin;
    TkButton  *butPtr = (TkButton *)ptr;
    Tk_Window  tkwin  = butPtr->tkwin;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }

    /*
     * Overlay Tk elements over button native region: drawing elements within
    /*Overlay Tk elements over button native region: drawing elements within button boundaries/native region causes unpredictable metrics.*/
     * button boundaries/native region causes unpredictable metrics.
     */

    DrawButtonImageAndText( butPtr);
}

/*
 *--------------------------------------------------------------
 *
 * ButtonEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for various events on
 *	buttons.
 *	This procedure is invoked by the Tk dispatcher for various
 *	events on buttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ButtonEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkButton *buttonPtr = (TkButton *)clientData;
    MacButton *mbPtr = (MacButton *)clientData;
    TkButton *buttonPtr = (TkButton *) clientData;
    MacButton *mbPtr = (MacButton *) clientData;

    if (eventPtr->type == ActivateNotify
	    || eventPtr->type == DeactivateNotify) {
	if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
	    return;
	}
	if (eventPtr->type == ActivateNotify) {
	    mbPtr->flags |= ACTIVE;
	} else {
	    mbPtr->flags &= ~ACTIVE;
	}
	if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
	    Tcl_DoWhenIdle(TkpDisplayButton, buttonPtr);
	    Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
	    buttonPtr->flags |= REDRAW_PENDING;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXComputeButtonParams --
 *
 *      This procedure computes the various parameters used when creating a
 *      Carbon Appearance control.  These are determined by the various tk
 *      button parameters
 *      This procedure computes the various parameters used
 *        when creating a Carbon Appearance control.
 *	These are determined by the various tk button parameters
 *
 * Results:
 *	None.
 *
 * Side effects:
 *        Sets the btnkind and drawinfo parameters
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeButtonParams(
    TkButton *butPtr,
    ThemeButtonKind *btnkind,
    HIThemeButtonDrawInfo *drawinfo)
        TkButton * butPtr,
        ThemeButtonKind* btnkind,
	HIThemeButtonDrawInfo *drawinfo)
{
    MacButton *mbPtr = (MacButton *) butPtr;
    MacButton *mbPtr = (MacButton *)butPtr;

    if (butPtr->borderWidth <= 2) {
        *btnkind = kThemeSmallBevelButton;
    } else if (butPtr->borderWidth == 3) {
        *btnkind = kThemeBevelButton;
    } else if (butPtr->borderWidth == 4) {
        *btnkind = kThemeRoundedBevelButton;
    } else {
        *btnkind = kThemePushButton;
    }

    if ((butPtr->image == NULL) && (butPtr->bitmap == None)) {
    if ((butPtr->image == None) && (butPtr->bitmap == None)) {
        switch (butPtr->type) {
	case TYPE_BUTTON:
	    *btnkind = kThemePushButton;
	    break;
	case TYPE_RADIO_BUTTON:
	    if (butPtr->borderWidth <= 1) {
		*btnkind = kThemeSmallRadioButton;
	    } else {
		*btnkind = kThemeRadioButton;
	    }
	    break;
	case TYPE_CHECK_BUTTON:
	    if (butPtr->borderWidth <= 1) {
		*btnkind = kThemeSmallCheckBox;
	    } else {
		*btnkind = kThemeCheckBox;
	    }
	    break;
            case TYPE_BUTTON:
                *btnkind = kThemePushButton;
                break;
            case TYPE_RADIO_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallRadioButton;
		} else {
                    *btnkind = kThemeRadioButton;
		}
		break;
	    case TYPE_CHECK_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallCheckBox;
	        } else {
                    *btnkind = kThemeCheckBox;
		}
		break;
	}
    }

    if (butPtr->indicatorOn) {
        switch (butPtr->type) {
	case TYPE_RADIO_BUTTON:
	    if (butPtr->borderWidth <= 1) {
		*btnkind = kThemeSmallRadioButton;
	    } else {
		*btnkind = kThemeRadioButton;
	    }
	    break;
	case TYPE_CHECK_BUTTON:
	    if (butPtr->borderWidth <= 1) {
		*btnkind = kThemeSmallCheckBox;
	    } else {
		*btnkind = kThemeCheckBox;
	    }
	    break;
            case TYPE_RADIO_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallRadioButton;
                } else {
                    *btnkind = kThemeRadioButton;
                }
                break;
            case TYPE_CHECK_BUTTON:
                if (butPtr->borderWidth <= 1) {
                    *btnkind = kThemeSmallCheckBox;
                } else {
                    *btnkind = kThemeCheckBox;
                }
                break;
        }
    } else {
        if (butPtr->type == TYPE_RADIO_BUTTON ||
		butPtr->type == TYPE_CHECK_BUTTON) {
	    butPtr->type == TYPE_CHECK_BUTTON
	) {
	    if (*btnkind == kThemePushButton) {
		*btnkind = kThemeBevelButton;
	    }
        }
    }

    if (butPtr->flags & SELECTED) {
1035
1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051
1052

1053
1054


1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072



1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102






1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131


1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147



1148





1149







1150
1151
1152
1153
1154






1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1068
1069
1070
1071
1072
1073
1074


1075









1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095


1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1121
1122






1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139







1140
1141
1142
1143
1144
1145
1146
1147
1148
1149


1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162





1163
1164
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179




1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

1206

1207
1208
1209

1210







1211
1212
1213

1214















-
-
+
-
-
-
-
-
-
-
-
-
+

-
+
+
















-
-
+
+
+















-
+








-
-
-
-
-
-
+
+
+
+
+
+



+







-
-
-
-
-
-
-










-
-
+
+











-
-
-
-
-
+
+
+

+
+
+
+
+
-
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+
+
+




















-

-
+


-

-
-
-
-
-
-
-



-
+
-
-
-
-
-
-
-
-
        drawinfo->state = kThemeStatePressed;
    } else {
        drawinfo->state = kThemeStateActive;
    }

    drawinfo->adornment = kThemeAdornmentNone;
    if (butPtr->defaultState == DEFAULT_ACTIVE) {
	if (drawinfo->state != kThemeStatePressed) {
	    drawinfo->adornment |= kThemeAdornmentDefault;
        drawinfo->adornment |= kThemeAdornmentDefault;
	}

	/*
	 * Older macOS systems (10.9 and earlier) use an animation to
	 * indicate the active button.  This is simulated by redrawing
	 * the button periodically.
	 */

        if (!mbPtr->defaultPulseHandler && ([NSApp macOSVersion] <= 100900)) {
        if (!mbPtr->defaultPulseHandler) {
            mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
                    PULSE_TIMER_MSECS, PulseDefaultButtonProc, butPtr);
                    PULSE_TIMER_MSECS, PulseDefaultButtonProc,
                    (ClientData) butPtr);
        }
    } else if (mbPtr->defaultPulseHandler) {
        Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
    }
    if (butPtr->highlightWidth >= 3) {
        if ((butPtr->flags & GOT_FOCUS)) {
            drawinfo->adornment |= kThemeAdornmentFocus;
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXComputeButtonDrawParams --
 *
 *	This procedure computes the various parameters used when drawing a
 *	button. These are determined by the various tk button parameters
 *	This procedure computes the various parameters used
 *	when drawing a button
 *	These are determined by the various tk button parameters
 *
 * Results:
 *	1 if control will be used, 0 otherwise.
 *
 * Side effects:
 *	Sets the button draw parameters
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXComputeButtonDrawParams(
    TkButton *butPtr,
    DrawParams *dpPtr)
{
    MacButton *mbPtr = (MacButton *) butPtr;
    MacButton *mbPtr = (MacButton *)butPtr;

    dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
	    || (butPtr->bitmap != None));

    if (butPtr->type != TYPE_LABEL) {
        dpPtr->offset = 0;
        if (dpPtr->hasImageOrBitmap) {
            switch (mbPtr->btnkind) {
	    case kThemeSmallBevelButton:
	    case kThemeBevelButton:
	    case kThemeRoundedBevelButton:
	    case kThemePushButton:
		dpPtr->offset = 1;
		break;
                case kThemeSmallBevelButton:
                case kThemeBevelButton:
                case kThemeRoundedBevelButton:
                case kThemePushButton:
                    dpPtr->offset = 1;
                    break;
            }
        }
    }


    dpPtr->border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
	dpPtr->gc = butPtr->disabledGC;
    } else if (butPtr->type == TYPE_BUTTON && butPtr->state == STATE_ACTIVE) {
	dpPtr->gc = butPtr->activeTextGC;
	dpPtr->border = butPtr->activeBorder;
    } else if ((mbPtr->drawinfo.adornment & kThemeAdornmentDefault) &&
	       mbPtr->drawinfo.state == kThemeStateActive) {
	/*
	 * This is a "-default active" button in the front window.
	 */

	dpPtr->gc = butPtr->activeTextGC;
    } else {
	dpPtr->gc = butPtr->normalTextGC;
    }

    if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
	    && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
	dpPtr->border = butPtr->selectBorder;
    }

    /*
     * Override the relief specified for the button if this is a checkbutton or
     * radiobutton and there's no indicator.
     * Override the relief specified for the button if this is a
     * checkbutton or radiobutton and there's no indicator.
     */

    dpPtr->relief = butPtr->relief;

    if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
	if (!dpPtr->hasImageOrBitmap) {
	    dpPtr->relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
		    : TK_RELIEF_RAISED;
	}
    }

    if (butPtr->type != TYPE_LABEL && (butPtr->type == TYPE_BUTTON ||
	    butPtr->indicatorOn || dpPtr->hasImageOrBitmap)) {
	/*
	 * Draw this widget as a native control.
	 */
    /*
     * Determine the draw type
     */

    if (butPtr->type == TYPE_LABEL) {
	dpPtr->drawType = DRAW_LABEL;
    } else if (butPtr->type == TYPE_BUTTON) {
	if (!dpPtr->hasImageOrBitmap) {
	    dpPtr->drawType = DRAW_CONTROL;
	return 1;
	} else {
            dpPtr->drawType = DRAW_BEVEL;
	}
    } else if (butPtr->indicatorOn) {
      dpPtr->drawType = DRAW_CONTROL;
    } else if (dpPtr->hasImageOrBitmap) {
	dpPtr->drawType = DRAW_BEVEL;
    } else {
	/*
	 * Draw this widget from scratch.
	 */

	dpPtr->drawType = DRAW_CUSTOM;
    }

    if ((dpPtr->drawType == DRAW_CONTROL) || (dpPtr->drawType == DRAW_BEVEL)) {
	return 1;
    } else {
	return 0;
    }
}

/*
 *--------------------------------------------------------------
 *
 * PulseDefaultButtonProc --
 *
 *     This function redraws the button on a timer, to pulse
 *     default buttons.
 *
 * Results:
 *     None.
 *
 * Side effects:
 *     Sets a timer to run itself again.
 *
 *--------------------------------------------------------------
 */

static void
PulseDefaultButtonProc(void *clientData)
PulseDefaultButtonProc(ClientData clientData)
{
    MacButton *mbPtr = (MacButton *)clientData;

    TkpDisplayButton(clientData);
    /*
     * Fix 40ada90762: any idle calls to TkpDisplayButton need to be canceled
     * in case the button is destroyed and has its data freed before the idle
     * event is handled (DestroyButton only cancels calls when REDRAW_PENDING
     * is set, which is not the case after calling TkpDisplayButton directly).
     */
    Tcl_CancelIdleCall(TkpDisplayButton, clientData);
    mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
            PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData);
}


/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXClipboard.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5



6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21





-
-
-
+
+
+






-







/*
 * tkMacOSXClipboard.c --
 *
 *	This file manages the clipboard for the Tk toolkit.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXConstants.h"
#include "tkSelect.h"

static NSInteger changeCount = -1;
static Tk_Window clipboardOwner = NULL;

#pragma mark TKApplication(TKClipboard)

31
32
33
34
35
36
37
38
39
40




41
42
43
44
45
46
47
30
31
32
33
34
35
36



37
38
39
40
41
42
43
44
45
46
47







-
-
-
+
+
+
+







	    [type isEqualToString:NSStringPboardType]) {
	for (TkClipboardTarget *targetPtr = dispPtr->clipTargetPtr; targetPtr;
		targetPtr = targetPtr->nextPtr) {
	    if (targetPtr->type == XA_STRING ||
		    targetPtr->type == dispPtr->utf8Atom) {
		for (TkClipboardBuffer *cbPtr = targetPtr->firstBufferPtr;
			cbPtr; cbPtr = cbPtr->nextPtr) {
		    NSString *s = [[TKNSString alloc]
				      initWithTclUtfBytes:cbPtr->buffer
						   length:(NSUInteger)cbPtr->length];
		    NSString *s = [[NSString alloc] initWithBytesNoCopy:
			    cbPtr->buffer length:cbPtr->length
			    encoding:NSUTF8StringEncoding freeWhenDone:NO];

		    [string appendString:s];
		    [s release];
		}
		break;
	    }
	}
    }
66
67
68
69
70
71
72

73
74

75
76
77
78
79
80
81
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83







+


+







}

- (void) tkCheckPasteboard
{
    if (clipboardOwner && [[NSPasteboard generalPasteboard] changeCount] !=
	    changeCount) {
	TkDisplay *dispPtr = TkGetDisplayList();

	if (dispPtr) {
	    XEvent event;

	    event.xany.type = SelectionClear;
	    event.xany.serial = NextRequest(Tk_Display(clipboardOwner));
	    event.xany.send_event = False;
	    event.xany.window = Tk_WindowId(clipboardOwner);
	    event.xany.display = Tk_Display(clipboardOwner);
	    event.xselectionclear.selection = dispPtr->clipboardAtom;
	    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130


131
132
133
134
135
136
137
138
139
140

141
142
143
144
145
146



147
148
149
150
151
152
153
116
117
118
119
120
121
122

123
124
125
126


127



128
129
130
131
132
133
134
135
136
137


138

139
140



141
142
143
144
145
146
147
148
149
150







-
+



-
-

-
-
-
+
+








-
-
+
-


-
-
-
+
+
+







				 * selection (determines display from which to
				 * retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection is to be
				 * returned. */
    Tk_GetSelProc *proc,	/* Procedure to call to process the selection,
				 * once it has been retrieved. */
    void *clientData)	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    int result = TCL_ERROR;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    int haveExternalClip =
	    ([[NSPasteboard generalPasteboard] changeCount] != changeCount);

    if (dispPtr && (haveExternalClip || dispPtr->clipboardActive)
	        && selection == dispPtr->clipboardAtom
	        && (target == XA_STRING || target == dispPtr->utf8Atom)) {
    if (dispPtr && selection == dispPtr->clipboardAtom && (target == XA_STRING
	    || target == dispPtr->utf8Atom)) {
	NSString *string = nil;
	NSPasteboard *pb = [NSPasteboard generalPasteboard];
	NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:
		NSStringPboardType]];

	if (type) {
	    string = [pb stringForType:type];
	}
	if (string) {
	    result = proc(clientData, interp, string.UTF8String);
	result = proc(clientData, interp, string ? [string UTF8String] : "");
	}
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	     "%s selection doesn't exist or form \"%s\" not defined",
	     Tk_GetAtomName(tkwin, selection),
	     Tk_GetAtomName(tkwin, target)));
		"%s selection doesn't exist or form \"%s\" not defined",
		Tk_GetAtomName(tkwin, selection),
		Tk_GetAtomName(tkwin, target)));
	Tcl_SetErrorCode(interp, "TK", "SELECTION", "EXISTS", NULL);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195


196
197
198
199
200
201
202
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190


191
192
193
194
195
196
197
198
199







-
+



















-
-
+
+







 */

int
XSetSelectionOwner(
    Display *display,		/* X Display. */
    Atom selection,		/* What selection to own. */
    Window owner,		/* Window to be the owner. */
    TCL_UNUSED(Time))			/* The current time? */
    Time time)			/* The current time? */
{
    TkDisplay *dispPtr = TkGetDisplayList();

    if (dispPtr && selection == dispPtr->clipboardAtom) {
	clipboardOwner = owner ? Tk_IdToWindow(display, owner) : NULL;
	if (!dispPtr->clipboardActive) {
	    NSPasteboard *pb = [NSPasteboard generalPasteboard];

	    changeCount = [pb declareTypes:[NSArray array] owner:NSApp];
	}
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSelDeadWindow --
 *
 *	This function is invoked just before a TkWindow is deleted. It performs
 *	selection-related cleanup.
 *	This function is invoked just before a TkWindow is deleted. It
 *	performs selection-related cleanup.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	clipboardOwner is cleared.
 *
227
228
229
230
231
232
233
234
235


236
237
238
239
240
241
242
224
225
226
227
228
229
230


231
232
233
234
235
236
237
238
239







-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelUpdateClipboard(
    TCL_UNUSED(TkWindow *),		/* Window associated with clipboard. */
    TCL_UNUSED(TkClipboardTarget *))
    TkWindow *winPtr,		/* Window associated with clipboard. */
    TkClipboardTarget *targetPtr)
				/* Info about the content. */
{
    NSPasteboard *pb = [NSPasteboard generalPasteboard];

    changeCount = [pb addTypes:[NSArray arrayWithObject:NSStringPboardType]
	    owner:NSApp];
}
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267







-
+







 *
 *--------------------------------------------------------------
 */

void
TkSelEventProc(
    Tk_Window tkwin,		/* Window for which event was targeted. */
    XEvent *eventPtr)	/* X event: either SelectionClear,
    register XEvent *eventPtr)	/* X event: either SelectionClear,
				 * SelectionRequest, or SelectionNotify. */
{
    if (eventPtr->type == SelectionClear) {
	clipboardOwner = NULL;
	TkSelClearSelection(tkwin, eventPtr);
    }
}
284
285
286
287
288
289
290
291

292






















293
294
295
296
297
298
299
300
301
302
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321







-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelPropProc(
    TCL_UNUSED(XEvent *))	/* X PropertyChange event. */
    register XEvent *eventPtr)	/* X PropertyChange event. */
{
}

/*
 *----------------------------------------------------------------------
 *
 * TkSuspendClipboard --
 *
 *	Handle clipboard conversion as required by the suppend event.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The local scrap is moved to the global scrap.
 *
 *----------------------------------------------------------------------
 */

void
TkSuspendClipboard(void)
{
    changeCount = [[NSPasteboard generalPasteboard] changeCount];
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXColor.c.

1
2

3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27







28
29
30
31
32





33
34
35

36
37



















38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80












































































































































81
82





83
84
85




86
87
88
89
90







91
92
93
94
95
96























97

98

99
100


101
102

103
104
105
106
107
108
109












110
111
112

















113
114
115




116
117
118



119
120
121
122





123
124
125
126





























127








128

129
130














131
132
133





134
135
136
137
138
139

140
141
142
143







144
145
146
147
148
149
150
151



















152
153
154





155
156
157
158
159
160
161
162




























163
164

165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265


266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482
483
484

485
486
487
488

489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511

512
513
514

515
516
517
518


519
520
521
522





523
524
525
526
527
528
529
530
531
532
533



534

535
536
537
538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553





554
555
556
557
558




559
560
561

562
563







564
565
566









567


568


569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593
594
595
596
597
598



599
600
601
602
603
604
605
606

607
608
609


610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627


628
629
630
631
632


633
634
635
636
637







638
639
640

641
642
643
644
645
646
647
648
649
650
651
652

653
654
655


656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681


682
683
684
685
686
687
688
689



690
691
692

693
694
695

696




697
698
699

700
701

702
703
704
705
706
707
708
709



710
711
712
713
714
715
716
717
718
719

720
721
722
723


724
725
726




727
728
729
730

731
732
733
734
735
736
737

738
739
740
741

742
743
744
745
746

747
748
749
750
751
752
753
1

2
3
4
5
6
7




8
9
10
11

12
13
14
15
16
17
18

19






20
21
22
23
24
25
26





27
28
29
30
31


32
33


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52











































53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192


193
194
195
196
197



198
199
200
201





202
203
204
205
206
207
208






209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234


235
236


237







238
239
240
241
242
243
244
245
246
247
248
249



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267


268
269
270
271



272
273
274




275
276
277
278
279




280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

318


319
320
321
322
323
324
325
326
327
328
329
330
331
332
333


334
335
336
337
338






339




340
341
342
343
344
345
346








347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365



366
367
368
369
370








371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403

404
405






























406


407







408

















409












410
411
412
413
414
415
416







417












418
419
























420

421



422










































































423





























































































424















425








426




427

428
429
430
431
432
433
434
435

436
437

438
439
440
441
442
443
444
445
446
447

448
449
450

451
452
453

454
455
456




457
458
459
460
461
462
463
464
465
466
467
468
469
470


471
472
473

474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490



491
492
493
494
495
496




497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512



513
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
529
530
531
532



533
534
535
536
537
538
539

540






541
542
543
544
545


546
547
548
549
550
551
552
553
554
555

556
557
558

559
560
561
562



563










564

565
566
567

568


569
570
571




572
573
574
575
576
577
578



579












580



581
582


























583
584
585
586
587
588
589



590
591
592
593
594

595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615



616
617
618
619
620
621
622
623
624
625
626


627




628
629
630
631

632
633
634
635
636
637
638

639
640
641
642
643
644
645

646
647
648
649

650
651
652
653
654

655
656
657
658
659
660
661
662

-
+





-
-
-
-
+
+
+
+
-







-

-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-

+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+
-
-
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-

-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-

-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-








-


-
+









-
+


-
+


-

+
+
-
-
-
-
+
+
+
+
+









-
-
+
+
+
-
+












-
+



-
-
-
+
+
+
+
+

-
-
-
-
+
+
+
+


-
+


+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+

+
+






-
-
-







-
+
-
-
-
-
-
-





-
-
+
+
+







-
+


-
+
+


-
-
-

-
-
-
-
-
-
-
-
-
-

-
+
+

-

-
-
+
+

-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+





-
-
-
+
+
+


-
+


-
+

+
+
+
+



+


+





-
-
-
+
+
+








-
-
+
-
-
-
-
+
+


-
+
+
+
+



-
+






-
+



-
+




-
+







/*
 * TkMacOSXColor.c --
 * tkMacOSXColor.c --
 *
 *	This file maintains a database of color values for the Tk
 *	toolkit, in order to avoid round-trips to the server to
 *	map color names to pixel values.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1996 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1996 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2020 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkColor.h"
#include "tkMacOSXColor.h"

static Tcl_HashTable systemColors;
static size_t numSystemColors;
static size_t rgbColorIndex;
static size_t controlAccentIndex;
static size_t controlAlternatingRowIndex;
static size_t selectedTabTextIndex;
struct SystemColorMapEntry {
    const char *name;
    ThemeBrush brush;
    ThemeTextColor textColor;
    ThemeBackgroundKind background;
};  /* unsigned char pixelCode; */

static size_t pressedButtonTextIndex;
static Bool useFakeAccentColor = NO;
static SystemColorDatum **systemColorIndex;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
static NSAppearance *lightAqua = nil;
/*
 * Array of system color definitions: the array index is required to equal the
 * color's (pixelCode - MIN_PIXELCODE), i.e. the array order needs to be kept
 * in sync with the public pixel code values in tkMacOSXPort.h !
 */
static NSAppearance *darkAqua = nil;
#endif

#define MIN_PIXELCODE  30
static NSColorSpace* sRGB = NULL;
static const CGFloat WINDOWBACKGROUND[4] =
static const struct SystemColorMapEntry systemColorMap[] = {
    { "Transparent",			    0, 0, 0 },							/*  30: TRANSPARENT_PIXEL */
    { "Highlight",			    kThemeBrushPrimaryHighlightColor, 0, 0 },			/*  31: HIGHLIGHT_PIXEL */
    { "HighlightSecondary",		    kThemeBrushSecondaryHighlightColor, 0, 0 },			/*  32: HIGHLIGHT_SECONDARY_PIXEL */
    { "HighlightText",			    kThemeBrushBlack, 0, 0 },					/*  33: HIGHLIGHT_TEXT_PIXEL */
    { "HighlightAlternate",		    kThemeBrushAlternatePrimaryHighlightColor, 0, 0 },		/*  34: HIGHLIGHT_ALTERNATE_PIXEL */
    { "ButtonText",			    0, kThemeTextColorPushButtonActive, 0 },			/*  35: CONTROL_TEXT_PIXEL */
    { "PrimaryHighlightColor",		    kThemeBrushPrimaryHighlightColor, 0, 0 },			/*  36 */
    { "ButtonFace",			    kThemeBrushButtonFaceActive, 0, 0 },			/*  37: CONTROL_BODY_PIXEL */
    { "SecondaryHighlightColor",	    kThemeBrushSecondaryHighlightColor, 0, 0 },			/*  38 */
    { "ButtonFrame",			    kThemeBrushButtonFrameActive, 0, 0 },			/*  39: CONTROL_FRAME_PIXEL */
    { "AlternatePrimaryHighlightColor",	    kThemeBrushAlternatePrimaryHighlightColor, 0, 0 },		/*  40 */
    { "WindowBody",			    kThemeBrushDocumentWindowBackground, 0, 0 },		/*  41: WINDOW_BODY_PIXEL */
    { "SheetBackground",		    kThemeBrushSheetBackground, 0, 0 },				/*  42 */
    { "MenuActive",			    kThemeBrushMenuBackgroundSelected, 0, 0 },			/*  43: MENU_ACTIVE_PIXEL */
    { "Black",				    kThemeBrushBlack, 0, 0 },					/*  44 */
    { "MenuActiveText",			    0, kThemeTextColorMenuItemSelected, 0 },			/*  45: MENU_ACTIVE_TEXT_PIXEL */
    { "White",				    kThemeBrushWhite, 0, 0 },					/*  46 */
    { "Menu",				    kThemeBrushMenuBackground, 0, 0 },				/*  47: MENU_BACKGROUND_PIXEL */
    {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0};

static void initColorTable()
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    Tcl_InitHashTable(&systemColors, TCL_STRING_KEYS);
    SystemColorDatum *entry, *oldEntry;
    Tcl_HashSearch search;
    Tcl_HashEntry *hPtr;
    int newPtr;
    size_t index = 0;
    NSColorList *systemColorList = [NSColorList colorListNamed:@"System"];
    NSString *key;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
    if (@available(macOS 10.14, *)) {
	darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
        lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
    }
#endif

    /*
     * Build a hash table for looking up a color by its name.
     * First add all of the static entries from tkMacOSXColor.h
     */

    for (entry = systemColorData; entry->name != NULL; entry++) {
	hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr);
	if (entry->type == semantic) {
	    NSString *colorName = [[NSString alloc]
				   initWithCString:entry->macName
					  encoding:NSUTF8StringEncoding];
	    SEL colorSelector = NSSelectorFromString(colorName);
	    if (![NSColor respondsToSelector:colorSelector]) {
		if ([colorName isEqualToString:@"controlAccentColor"]) {
		    useFakeAccentColor = YES;
		} else if (   ![colorName isEqualToString:@"selectedTabTextColor"]
			   && ![colorName isEqualToString:@"controlAlternatingRowColor"]
			   && ![colorName isEqualToString:@"pressedButtonTextColor"]) {
		    /* Uncomment to print all unsupported colors:              */
		    /* printf("Unsupported color %s\n", colorName.UTF8String); */
		    continue;
		}
    { "DialogBackgroundActive",		    kThemeBrushDialogBackgroundActive, 0, 0 },			/*  48 */
    { "MenuDisabled",			    0, kThemeTextColorMenuItemDisabled, 0 },			/*  49: MENU_DISABLED_PIXEL */
    { "DialogBackgroundInactive",	    kThemeBrushDialogBackgroundInactive, 0, 0 },		/*  50 */
    { "MenuText",			    0, kThemeTextColorMenuItemActive, 0 },			/*  51: MENU_TEXT_PIXEL */
    { "AppearanceColor",		    0, 0, 0 },							/*  52: APPEARANCE_PIXEL */
    { "AlertBackgroundActive",		    kThemeBrushAlertBackgroundActive, 0, 0 },			/*  53 */
    { "AlertBackgroundInactive",	    kThemeBrushAlertBackgroundInactive, 0, 0 },			/*  54 */
    { "ModelessDialogBackgroundActive",	    kThemeBrushModelessDialogBackgroundActive, 0, 0 },		/*  55 */
    { "ModelessDialogBackgroundInactive",   kThemeBrushModelessDialogBackgroundInactive, 0, 0 },	/*  56 */
    { "UtilityWindowBackgroundActive",	    kThemeBrushUtilityWindowBackgroundActive, 0, 0 },		/*  57 */
    { "UtilityWindowBackgroundInactive",    kThemeBrushUtilityWindowBackgroundInactive, 0, 0 },		/*  58 */
    { "ListViewSortColumnBackground",	    kThemeBrushListViewSortColumnBackground, 0, 0 },		/*  59 */
    { "ListViewBackground",		    kThemeBrushListViewBackground, 0, 0 },			/*  60 */
    { "IconLabelBackground",		    kThemeBrushIconLabelBackground, 0, 0 },			/*  61 */
    { "ListViewSeparator",		    kThemeBrushListViewSeparator, 0, 0 },			/*  62 */
    { "ChasingArrows",			    kThemeBrushChasingArrows, 0, 0 },				/*  63 */
    { "DragHilite",			    kThemeBrushDragHilite, 0, 0 },				/*  64 */
    { "DocumentWindowBackground",	    kThemeBrushDocumentWindowBackground, 0, 0 },		/*  65 */
    { "FinderWindowBackground",		    kThemeBrushFinderWindowBackground, 0, 0 },			/*  66 */
    { "ScrollBarDelimiterActive",	    kThemeBrushScrollBarDelimiterActive, 0, 0 },		/*  67 */
    { "ScrollBarDelimiterInactive",	    kThemeBrushScrollBarDelimiterInactive, 0, 0 },		/*  68 */
    { "FocusHighlight",			    kThemeBrushFocusHighlight, 0, 0 },				/*  69 */
    { "PopupArrowActive",		    kThemeBrushPopupArrowActive, 0, 0 },			/*  70 */
    { "PopupArrowPressed",		    kThemeBrushPopupArrowPressed, 0, 0 },			/*  71 */
    { "PopupArrowInactive",		    kThemeBrushPopupArrowInactive, 0, 0 },			/*  72 */
    { "AppleGuideCoachmark",		    kThemeBrushAppleGuideCoachmark, 0, 0 },			/*  73 */
    { "IconLabelBackgroundSelected",	    kThemeBrushIconLabelBackgroundSelected, 0, 0 },		/*  74 */
    { "StaticAreaFill",			    kThemeBrushStaticAreaFill, 0, 0 },				/*  75 */
    { "ActiveAreaFill",			    kThemeBrushActiveAreaFill, 0, 0 },				/*  76 */
    { "ButtonFrameActive",		    kThemeBrushButtonFrameActive, 0, 0 },			/*  77 */
    { "ButtonFrameInactive",		    kThemeBrushButtonFrameInactive, 0, 0 },			/*  78 */
    { "ButtonFaceActive",		    kThemeBrushButtonFaceActive, 0, 0 },			/*  79 */
    { "ButtonFaceInactive",		    kThemeBrushButtonFaceInactive, 0, 0 },			/*  80 */
    { "ButtonFacePressed",		    kThemeBrushButtonFacePressed, 0, 0 },			/*  81 */
    { "ButtonActiveDarkShadow",		    kThemeBrushButtonActiveDarkShadow, 0, 0 },			/*  82 */
    { "ButtonActiveDarkHighlight",	    kThemeBrushButtonActiveDarkHighlight, 0, 0 },		/*  83 */
    { "ButtonActiveLightShadow",	    kThemeBrushButtonActiveLightShadow, 0, 0 },			/*  84 */
    { "ButtonActiveLightHighlight",	    kThemeBrushButtonActiveLightHighlight, 0, 0 },		/*  85 */
    { "ButtonInactiveDarkShadow",	    kThemeBrushButtonInactiveDarkShadow, 0, 0 },		/*  86 */
    { "ButtonInactiveDarkHighlight",	    kThemeBrushButtonInactiveDarkHighlight, 0, 0 },		/*  87 */
    { "ButtonInactiveLightShadow",	    kThemeBrushButtonInactiveLightShadow, 0, 0 },		/*  88 */
    { "ButtonInactiveLightHighlight",	    kThemeBrushButtonInactiveLightHighlight, 0, 0 },		/*  89 */
    { "ButtonPressedDarkShadow",	    kThemeBrushButtonPressedDarkShadow, 0, 0 },			/*  90 */
    { "ButtonPressedDarkHighlight",	    kThemeBrushButtonPressedDarkHighlight, 0, 0 },		/*  91 */
    { "ButtonPressedLightShadow",	    kThemeBrushButtonPressedLightShadow, 0, 0 },		/*  92 */
    { "ButtonPressedLightHighlight",	    kThemeBrushButtonPressedLightHighlight, 0, 0 },		/*  93 */
    { "BevelActiveLight",		    kThemeBrushBevelActiveLight, 0, 0 },			/*  94 */
    { "BevelActiveDark",		    kThemeBrushBevelActiveDark, 0, 0 },				/*  95 */
    { "BevelInactiveLight",		    kThemeBrushBevelInactiveLight, 0, 0 },			/*  96 */
    { "BevelInactiveDark",		    kThemeBrushBevelInactiveDark, 0, 0 },			/*  97 */
    { "NotificationWindowBackground",	    kThemeBrushNotificationWindowBackground, 0, 0 },		/*  98 */
    { "MovableModalBackground",		    kThemeBrushMovableModalBackground, 0, 0 },			/*  99 */
    { "SheetBackgroundOpaque",		    kThemeBrushSheetBackgroundOpaque, 0, 0 },			/* 100 */
    { "DrawerBackground",		    kThemeBrushDrawerBackground, 0, 0 },			/* 101 */
    { "ToolbarBackground",		    kThemeBrushToolbarBackground, 0, 0 },			/* 102 */
    { "SheetBackgroundTransparent",	    kThemeBrushSheetBackgroundTransparent, 0, 0 },		/* 103 */
    { "MenuBackground",			    kThemeBrushMenuBackground, 0, 0 },				/* 104 */
    { "Pixel",				    0, 0, 0 },							/* 105: PIXEL_MAGIC */
    { "MenuBackgroundSelected",		    kThemeBrushMenuBackgroundSelected, 0, 0 },			/* 106 */
    { "ListViewOddRowBackground",	    kThemeBrushListViewOddRowBackground, 0, 0 },		/* 107 */
    { "ListViewEvenRowBackground",	    kThemeBrushListViewEvenRowBackground, 0, 0 },		/* 108 */
    { "ListViewColumnDivider",		    kThemeBrushListViewColumnDivider, 0, 0 },			/* 109 */
    { "BlackText",			    0, kThemeTextColorBlack, 0 },				/* 110 */
    { "DialogActiveText",		    0, kThemeTextColorDialogActive, 0 },			/* 111 */
    { "DialogInactiveText",		    0, kThemeTextColorDialogInactive, 0 },			/* 112 */
    { "AlertActiveText",		    0, kThemeTextColorAlertActive, 0 },				/* 113 */
    { "AlertInactiveText",		    0, kThemeTextColorAlertInactive, 0 },			/* 114 */
    { "ModelessDialogActiveText",	    0, kThemeTextColorModelessDialogActive, 0 },		/* 115 */
    { "ModelessDialogInactiveText",	    0, kThemeTextColorModelessDialogInactive, 0 },		/* 116 */
    { "WindowHeaderActiveText",		    0, kThemeTextColorWindowHeaderActive, 0 },			/* 117 */
    { "WindowHeaderInactiveText",	    0, kThemeTextColorWindowHeaderInactive, 0 },		/* 118 */
    { "PlacardActiveText",		    0, kThemeTextColorPlacardActive, 0 },			/* 119 */
    { "PlacardInactiveText",		    0, kThemeTextColorPlacardInactive, 0 },			/* 120 */
    { "PlacardPressedText",		    0, kThemeTextColorPlacardPressed, 0 },			/* 121 */
    { "PushButtonActiveText",		    0, kThemeTextColorPushButtonActive, 0 },			/* 122 */
    { "PushButtonInactiveText",		    0, kThemeTextColorPushButtonInactive, 0 },			/* 123 */
    { "PushButtonPressedText",		    0, kThemeTextColorPushButtonPressed, 0 },			/* 124 */
    { "BevelButtonActiveText",		    0, kThemeTextColorBevelButtonActive, 0 },			/* 125 */
    { "BevelButtonInactiveText",	    0, kThemeTextColorBevelButtonInactive, 0 },			/* 126 */
    { "BevelButtonPressedText",		    0, kThemeTextColorBevelButtonPressed, 0 },			/* 127 */
    { "PopupButtonActiveText",		    0, kThemeTextColorPopupButtonActive, 0 },			/* 128 */
    { "PopupButtonInactiveText",	    0, kThemeTextColorPopupButtonInactive, 0 },			/* 129 */
    { "PopupButtonPressedText",		    0, kThemeTextColorPopupButtonPressed, 0 },			/* 130 */
    { "IconLabelText",			    0, kThemeTextColorIconLabel, 0 },				/* 131 */
    { "ListViewText",			    0, kThemeTextColorListView, 0 },				/* 132 */
    { "DocumentWindowTitleActiveText",	    0, kThemeTextColorDocumentWindowTitleActive, 0 },		/* 133 */
    { "DocumentWindowTitleInactiveText",    0, kThemeTextColorDocumentWindowTitleInactive, 0 },		/* 134 */
    { "MovableModalWindowTitleActiveText",  0, kThemeTextColorMovableModalWindowTitleActive, 0 },	/* 135 */
    { "MovableModalWindowTitleInactiveText",0, kThemeTextColorMovableModalWindowTitleInactive, 0 },	/* 136 */
    { "UtilityWindowTitleActiveText",	    0, kThemeTextColorUtilityWindowTitleActive, 0 },		/* 137 */
    { "UtilityWindowTitleInactiveText",	    0, kThemeTextColorUtilityWindowTitleInactive, 0 },		/* 138 */
    { "PopupWindowTitleActiveText",	    0, kThemeTextColorPopupWindowTitleActive, 0 },		/* 139 */
    { "PopupWindowTitleInactiveText",	    0, kThemeTextColorPopupWindowTitleInactive, 0 },		/* 140 */
    { "RootMenuActiveText",		    0, kThemeTextColorRootMenuActive, 0 },			/* 141 */
    { "RootMenuSelectedText",		    0, kThemeTextColorRootMenuSelected, 0 },			/* 142 */
    { "RootMenuDisabledText",		    0, kThemeTextColorRootMenuDisabled, 0 },			/* 143 */
    { "MenuItemActiveText",		    0, kThemeTextColorMenuItemActive, 0 },			/* 144 */
    { "MenuItemSelectedText",		    0, kThemeTextColorMenuItemSelected, 0 },			/* 145 */
    { "MenuItemDisabledText",		    0, kThemeTextColorMenuItemDisabled, 0 },			/* 146 */
    { "PopupLabelActiveText",		    0, kThemeTextColorPopupLabelActive, 0 },			/* 147 */
    { "PopupLabelInactiveText",		    0, kThemeTextColorPopupLabelInactive, 0 },			/* 148 */
    { "TabFrontActiveText",		    0, kThemeTextColorTabFrontActive, 0 },			/* 149 */
    { "TabNonFrontActiveText",		    0, kThemeTextColorTabNonFrontActive, 0 },			/* 150 */
    { "TabNonFrontPressedText",		    0, kThemeTextColorTabNonFrontPressed, 0 },			/* 151 */
    { "TabFrontInactiveText",		    0, kThemeTextColorTabFrontInactive, 0 },			/* 152 */
    { "TabNonFrontInactiveText",	    0, kThemeTextColorTabNonFrontInactive, 0 },			/* 153 */
    { "IconLabelSelectedText",		    0, kThemeTextColorIconLabelSelected, 0 },			/* 154 */
    { "BevelButtonStickyActiveText",	    0, kThemeTextColorBevelButtonStickyActive, 0 },		/* 155 */
    { "BevelButtonStickyInactiveText",	    0, kThemeTextColorBevelButtonStickyInactive, 0 },		/* 156 */
    { "NotificationText",		    0, kThemeTextColorNotification, 0 },			/* 157 */
    { "SystemDetailText",		    0, kThemeTextColorSystemDetail, 0 },			/* 158 */
    { "WhiteText",			    0, kThemeTextColorWhite, 0 },				/* 159 */
    { "TabPaneBackground",		    0, 0, kThemeBackgroundTabPane },				/* 160 */
    { "PlacardBackground",		    0, 0, kThemeBackgroundPlacard },				/* 161 */
    { "WindowHeaderBackground",		    0, 0, kThemeBackgroundWindowHeader },			/* 162 */
    { "ListViewWindowHeaderBackground",	    0, 0, kThemeBackgroundListViewWindowHeader },		/* 163 */
    { "SecondaryGroupBoxBackground",	    0, 0, kThemeBackgroundSecondaryGroupBox },			/* 164 */
    { "MetalBackground",		    0, 0, kThemeBackgroundMetal },				/* 165 */
    { NULL,				    0, 0, 0 }
};
#define MAX_PIXELCODE 165

/*
 *----------------------------------------------------------------------
 *
 * GetThemeFromPixelCode --
 *
 *	When given a pixel code corresponding to a theme system color,
 *	set one of brush, textColor or background to the corresponding
 *	Appearance Mgr theme constant.
 *
 * Results:
 *	Returns false if not a real pixel, true otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

	    }
	    entry->selector = [colorName retain];
static int
GetThemeFromPixelCode(
    unsigned char code,
    ThemeBrush *brush,
    ThemeTextColor *textColor,
	}
	if (newPtr == 0) {
	    oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
    ThemeBackgroundKind *background)
{
    if (code >= MIN_PIXELCODE && code <= MAX_PIXELCODE) {
	*brush = systemColorMap[code - MIN_PIXELCODE].brush;
	    entry->index = oldEntry->index;
	    [oldEntry->selector release];
	} else {
	    entry->index = index++;
	}
	*textColor = systemColorMap[code - MIN_PIXELCODE].textColor;
	*background = systemColorMap[code - MIN_PIXELCODE].background;
    } else {
	*brush = 0;
	*textColor = 0;
	*background = 0;
    }
	Tcl_SetHashValue(hPtr, entry);
    }

    /*
     * Add all of the colors in the System ColorList.
     */
    if (!*brush && !*textColor && !*background && code != PIXEL_MAGIC &&
	    code != TRANSPARENT_PIXEL) {
	return false;
    } else {
	return true;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GetThemeColor --
 *
 *	Get RGB color for a given system color or pixel value.
 *
 * Results:
 *	OSStatus
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSStatus
    for (key in [systemColorList allKeys]) {
GetThemeColor(
	NSUInteger length = [key lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
	char *name;
    unsigned long pixel,
    ThemeBrush brush,
	entry = (SystemColorDatum *)ckalloc(sizeof(SystemColorDatum));
	bzero(entry, sizeof(SystemColorDatum));
    ThemeTextColor textColor,
	name = (char *)ckalloc(length + 1);
	strcpy(name, key.UTF8String);
	name[0] = (char)toupper(UCHAR(name[0]));
        if (!strcmp(name, "WindowBackgroundColor")) {

	    /*
	     * Avoid black windows on old systems.
    ThemeBackgroundKind background,
    CGColorRef *c)
{
    OSStatus err = noErr;

    if (brush) {
	err = ChkErr(HIThemeBrushCreateCGColor, brush, c);
    /*} else if (textColor) {
	err = ChkErr(GetThemeTextColor, textColor, 32, true, c);*/
    } else {
	CGFloat rgba[4] = {0, 0, 0, 1};

	     */

	    continue;
	switch ((pixel >> 24) & 0xff) {
	case PIXEL_MAGIC: {
	    unsigned short red, green, blue;
	    red		= (pixel >> 16) & 0xff;
	    green	= (pixel >>  8) & 0xff;
	    blue	= (pixel      ) & 0xff;
	    red		|= red   << 8;
	    green	|= green << 8;
	    blue	|= blue  << 8;
	    rgba[0]	= red	/ 65535.0;
	    rgba[1]	= green / 65535.0;
	    rgba[2]	= blue  / 65535.0;
	    break;
	    }
	case TRANSPARENT_PIXEL:
	    rgba[3]	= 0.0;
	    break;
	}
	entry->type=semantic;
	entry->name = name;

        // this attempts to find something roughly fitting for any display
//	*c = CGColorCreateGenericRGB(rgba[0], rgba[1], rgba[2], rgba[3]);

	entry->selector = [key retain];
	hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr);
	if (newPtr == 0) {
        // may be off for non-main display but in most cases better than prev
	static CGColorSpaceRef deviceRGBSpace = NULL;
	if (!deviceRGBSpace) {
	    oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
	    entry->index = oldEntry->index;
	    [oldEntry->selector release];
	} else {
	    deviceRGBSpace = CGDisplayCopyColorSpace(CGMainDisplayID());
	}
	*c = CGColorCreate(deviceRGBSpace, rgba );
    }
    return err;
	    entry->index = index++;
	}
	Tcl_SetHashValue(hPtr, entry);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetMacColor --
 *
 *	Creates a CGColorRef from a X style pixel value.
 *
 * Results:
 *	Returns false if not a real pixel, true otherwise.
 *
 * Side effects:
 *	The variable macColor is set to a new CGColorRef, the caller is
 *	responsible for releasing it!
 *
 *----------------------------------------------------------------------
 */

int
TkSetMacColor(
    unsigned long pixel,		/* Pixel value to convert. */
    void *macColor)			/* CGColorRef to modify. */
{
    CGColorRef *color = (CGColorRef*)macColor;
    OSStatus err = -1;
    ThemeBrush brush;
    ThemeTextColor textColor;
    ThemeBackgroundKind background;

    if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor,
	    &background)) {
	err = ChkErr(GetThemeColor, pixel, brush, textColor, background,
		color);
    }
    return (err == noErr);
}

    /*
/*
     * Build an array for looking up a color by its index.
     */
 *----------------------------------------------------------------------
 *
 * TkpInitGCCache, TkpFreeGCCache, CopyCachedColor, SetCachedColor --
 *
 *	Maintain a per-GC cache of previously converted CGColorRefs
 *
 * Results:
 *	None resp. retained CGColorRef for CopyCachedColor()
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

    numSystemColors = index;
    systemColorIndex = (SystemColorDatum **)ckalloc(numSystemColors * sizeof(SystemColorDatum *));
void
TkpInitGCCache(
    GC gc)
{
    bzero(TkpGetGCCache(gc), sizeof(TkpGCCache));
    for (hPtr = Tcl_FirstHashEntry(&systemColors, &search); hPtr != NULL;
	 hPtr = Tcl_NextHashEntry(&search)) {
	entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
	if (entry == NULL) {
	    Tcl_Panic("Unsupported semantic color with no supported backup!");
	}
}
	systemColorIndex[entry->index] = entry;
    }

    /*

void
TkpFreeGCCache(
    GC gc)
{
    TkpGCCache *gcCache = TkpGetGCCache(gc);

     * Remember the indexes of some special entries.
     */

    hPtr = Tcl_FindHashEntry(&systemColors, "Pixel");
    entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
    rgbColorIndex = entry->index;
    hPtr = Tcl_FindHashEntry(&systemColors, "ControlAccentColor");
    entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
    if (gcCache->cachedForegroundColor) {
	CFRelease(gcCache->cachedForegroundColor);
    }
    if (gcCache->cachedBackgroundColor) {
	CFRelease(gcCache->cachedBackgroundColor);
    }
}

static CGColorRef
CopyCachedColor(
    GC gc,
    unsigned long pixel)
{
    TkpGCCache *gcCache = TkpGetGCCache(gc);
    CGColorRef cgColor = NULL;

    if (gcCache) {
	if (gcCache->cachedForeground == pixel) {
	    cgColor = gcCache->cachedForegroundColor;
    controlAccentIndex = entry->index;
    hPtr = Tcl_FindHashEntry(&systemColors, "ControlAlternatingRowColor");
    entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
	} else if (gcCache->cachedBackground == pixel) {
	    cgColor = gcCache->cachedBackgroundColor;
	}
	if (cgColor) {
	    CFRetain(cgColor);
    controlAlternatingRowIndex = entry->index;
    hPtr = Tcl_FindHashEntry(&systemColors, "SelectedTabTextColor");
    entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
    selectedTabTextIndex = entry->index;
    hPtr = Tcl_FindHashEntry(&systemColors, "PressedButtonTextColor");
    entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
    pressedButtonTextIndex = entry->index;
    [pool drain];
	}
    }
    return cgColor;
}

static void
SetCachedColor(
    GC gc,
    unsigned long pixel,
    CGColorRef cgColor)
{
    TkpGCCache *gcCache = TkpGetGCCache(gc);

    if (gcCache && cgColor) {
	if (gc->foreground == pixel) {
	    if (gcCache->cachedForegroundColor) {
		CFRelease(gcCache->cachedForegroundColor);
	    }
	    gcCache->cachedForegroundColor = (CGColorRef) CFRetain(cgColor);
	    gcCache->cachedForeground = pixel;
	} else if (gc->background == pixel) {
	    if (gcCache->cachedBackgroundColor) {
		CFRelease(gcCache->cachedBackgroundColor);
	    }
	    gcCache->cachedBackgroundColor = (CGColorRef) CFRetain(cgColor);
	    gcCache->cachedBackground = pixel;
	}
    }
}


/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXRGBPixel --
 * TkMacOSXCreateCGColor --
 *
 *	Return an unsigned long value suitable for use in the pixel
 *	field of an XColor with the specified red, green and blue
 *	intensities.  The inputs are cast as unsigned longs but are
 *      expected to have values representable by an unsigned char.
 *
 *      This is called in the TkpGetPixel macro, used in xcolor.c,
 *      and in ImageGetPixel.
 *
 * Results:
 *	An unsigned long that can be used as the pixel field of an XColor.
 *
 * Side effects:
 *	None.
 *----------------------------------------------------------------------
 */
MODULE_SCOPE
unsigned long
TkMacOSXRGBPixel(
    unsigned long red,
    unsigned long green,
    unsigned long blue)
{
    MacPixel p = {0};
    p.pixel.colortype = rgbColor;
    p.pixel.value = (unsigned int)(((red & 0xff) << 16)  |
	            ((green & 0xff) << 8) |
	            (blue & 0xff));
    return p.ulong;
}

 *	Creates a CGColorRef from a X style pixel value.
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXClearPixel --
 *
 *	Return the unsigned long value that appears in the pixel
 *	field of the XColor for systemTransparentColor.
 *
 *      This is used in tkMacOSXImage.c.
 *
 * Results:
 *	The unsigned long that appears in the pixel field of the XColor
 *      for systemTransparentPixel.
 *
 * Side effects:
 *	None.
 *----------------------------------------------------------------------
 */
MODULE_SCOPE
unsigned long TkMacOSXClearPixel(
    void)
{
    MacPixel p = {0};
    p.pixel.value = 0;
    p.pixel.colortype = clearColor;
    return p.ulong;
}

 *	Returns NULL if not a real pixel, CGColorRef otherwise.

/*
 *----------------------------------------------------------------------
 *
 * GetEntryFromPixel --
 *
 *	Look up a SystemColorDatum which describes the XColor with
 *      the specified value as its pixel field.
 *
 * Results:
 *	A pointer to a SystemColorDatum, or NULL if the pixel value is
 *	invalid.
 *
 * Side effects:
 *	None
 *
 *----------------------------------------------------------------------
 */

static SystemColorDatum*
GetEntryFromPixel(
    unsigned long pixel)
{
    MacPixel p = {0};
    size_t index = rgbColorIndex;

CGColorRef
    p.ulong = pixel;
    if (p.pixel.colortype != rgbColor) {
	index = p.pixel.value;
    }
    if (index < numSystemColors) {
	return systemColorIndex[index];
    } else {
	return NULL;
    }
}


TkMacOSXCreateCGColor(
    GC gc,
/*
 *----------------------------------------------------------------------
 *
 * GetRGBA --
 *
 *	Given a SystemColorDatum and a pointer to an array of 4 CGFloats, store
 *      the associated RGBA color values in the array.  In the case of the
 *      RGBColor datum, the unsigned long pixel value containing the RGB values
 *      must also be provided as the pixel parameter.  Otherwise the pixel
 *      parameter is ignored.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The array rgba is filled in.
 *
 *----------------------------------------------------------------------
 */

static void
GetRGBA(
    SystemColorDatum *entry,
    unsigned long pixel,
    unsigned long pixel)		/* Pixel value to convert. */
    CGFloat *rgba)
{
    NSColor *bgColor, *color = nil;
    int OSVersion = [NSApp macOSVersion];

    CGColorRef cgColor = CopyCachedColor(gc, pixel);
    if (!sRGB) {
	sRGB = [NSColorSpace sRGBColorSpace];
    }

    switch (entry->type) {
    case rgbColor:
	rgba[0] = ((pixel >> 16) & 0xff) / 255.0;
	rgba[1] = ((pixel >>  8) & 0xff) / 255.0;
	rgba[2] = ((pixel      ) & 0xff) / 255.0;
	break;
    case ttkBackground:

	/*
	 * Prior to OSX 10.14, getComponents returns black when applied to
	 * windowBackgroundColor.
	 */

	if ([NSApp macOSVersion] < 101400) {
	    for (int i = 0; i < 3; i++) {
		rgba[i] = WINDOWBACKGROUND[i];
	    }
	} else {
	    bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:sRGB];
	    [bgColor getComponents: rgba];
	}
	if (rgba[0] + rgba[1] + rgba[2] < 1.5) {
	    for (int i=0; i<3; i++) {
		rgba[i] += entry->value*8.0 / 255.0;
	    }
	} else {
	    for (int i=0; i<3; i++) {
		rgba[i] -= entry->value*8.0 / 255.0;
	    }
	}
	break;
    case clearColor:
	rgba[0] = rgba[1] = rgba[2] = 1.0;
	rgba[3] = 0;
	break;
    case semantic:
	if (entry->index == controlAccentIndex && useFakeAccentColor) {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101400
	    color = [[NSColor colorForControlTint: [NSColor currentControlTint]]
			      colorUsingColorSpace:sRGB];
#endif
	} else if (entry->index == controlAlternatingRowIndex) {
	    /*
	     * Color which is now called alternatingContentBackgroundColor on 10.14.
	     * Taken from NSColor.controlAlternatingRowBackgroundColors (which was
	     * replaced by NSColor.alternatingContentBackgroundColors on 10.14).
	     */
	    color = [[NSColor colorWithCatalogName:@"System"
					 colorName:@"controlAlternatingRowColor"]
			colorUsingColorSpace:sRGB];
	} else if (entry->index == selectedTabTextIndex) {
	    if (OSVersion > 100600 && OSVersion < 110000) {
		color = [[NSColor whiteColor] colorUsingColorSpace:sRGB];
	    } else {
		color = [[NSColor textColor] colorUsingColorSpace:sRGB];
	    }
	} else if (entry->index == pressedButtonTextIndex) {
	    if (OSVersion < 120000) {
		color = [[NSColor whiteColor] colorUsingColorSpace:sRGB];
	    } else {
		color = [[NSColor blackColor] colorUsingColorSpace:sRGB];
	    }
	} else {
	    color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB];
	}
	[color getComponents: rgba];
	break;
    default:
	break;
    }

}

/*
 *----------------------------------------------------------------------
 *
 * SetCGColorComponents --
 *
 *	Set the components of a CGColorRef from an XColor pixel value and a
 *      SystemColorDatum.  The pixel value is only used in the case where
 *      the color is of type rgbColor.  In that case the normalized XColor RGB
 *      values are copied into the CGColorRef.  Otherwise the components are
 *      computed from the SystemColorDatum.
 *
 * Results:
 *	True if the function succeeds, false otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Bool
SetCGColorComponents(
    SystemColorDatum *entry,
    unsigned long pixel,
    CGColorRef *c)
{
    CGFloat rgba[4] = {0, 0, 0, 1};

    if (entry->type == HIBrush) {
     	OSStatus err = ChkErr(HIThemeBrushCreateCGColor, entry->value, c);
     	return err == noErr;
    }

    /*
     * This function is called before our autorelease pool is set up,
     * so it needs its own pool.
     */

    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    GetRGBA(entry, pixel, rgba);
    *c = CGColorCreate(sRGB.CGColorSpace, rgba);
    [pool drain];
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInDarkMode --
 *
 *      Tests whether the given window's NSView has a DarkAqua Appearance.
 *
 * Results:
 *      Returns true if the NSView is in DarkMode, false if not.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE Bool
TkMacOSXInDarkMode(Tk_Window tkwin)
{

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
    if (@available(macOS 10.14, *)) {
        TkWindow *winPtr = (TkWindow*) tkwin;
	NSAppearanceName name;
	NSView *view = nil;
	if (winPtr && winPtr->privatePtr) {
	    view = TkMacOSXGetNSViewForDrawable((Drawable)winPtr->privatePtr);
	}
	if (view) {
	    name = [[view effectiveAppearance] name];
	} else {
	    name = [[NSApp effectiveAppearance] name];
	}
	return (name == NSAppearanceNameDarkAqua);
    }
#else
    (void) tkwin;
#endif
    return false;
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetMacColor --
    if (!cgColor && TkSetMacColor(pixel, &cgColor)) {
 *
 *	Sets the components of a CGColorRef from an XColor pixel value.  The
 *      pixel value is used to look up the color in the system color table, and
 *      then SetCGColorComponents is called with the table entry and the pixel
 *      value.  The parameter macColor should be a pointer to a CGColorRef.
 *
 * Results:
 *      Returns false if the color is not found, true otherwise.
 *
 * Side effects:
 *	The CGColorRef referenced by the variable macColor may be modified.
 *
 *----------------------------------------------------------------------
 */

	SetCachedColor(gc, pixel, cgColor);
int
TkSetMacColor(
    unsigned long pixel,	/* Pixel value to convert. */
    void *macColor)		/* CGColorRef to modify. */
{
    CGColorRef *color = (CGColorRef*)macColor;
    SystemColorDatum *entry = GetEntryFromPixel(pixel);

    }
    if (entry) {
	return SetCGColorComponents(entry, pixel, color);
    } else {
	return false;
    return cgColor;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSColor --
 *
 *	Creates an autoreleased NSColor from a X style pixel value.
 *      The return value is nil if the pixel value is invalid.
 *
 * Results:
 *	A possibly nil pointer to an NSColor.
 *	Returns nil if not a real pixel, NSColor* otherwise.
 *
 * Side effects:
 *	None
 *
 *----------------------------------------------------------------------
 */

NSColor*
TkMacOSXGetNSColor(
    TCL_UNUSED(GC),
    GC gc,
    unsigned long pixel)		/* Pixel value to convert. */
{
    CGColorRef cgColor = NULL;
    CGColorRef cgColor = TkMacOSXCreateCGColor(gc, pixel);
    NSColor *nsColor = nil;

    TkSetMacColor(pixel, &cgColor);
    if (cgColor) {
	NSColorSpace *colorSpace = [[NSColorSpace alloc]
		initWithCGColorSpace:CGColorGetColorSpace(cgColor)];
	nsColor = [NSColor colorWithColorSpace:sRGB
			components:CGColorGetComponents(cgColor)
			count:(NSInteger)CGColorGetNumberOfComponents(cgColor)];
	CGColorRelease(cgColor);
	nsColor = [NSColor colorWithColorSpace:colorSpace
		components:CGColorGetComponents(cgColor)
		count:CGColorGetNumberOfComponents(cgColor)];
	[colorSpace release];
	CFRelease(cgColor);
    }
    return nsColor;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetColorInContext --
 *
 *	Sets the fill and stroke colors in the given CGContext to the CGColor
 *	which corresponds to the XColor having the specified value for its pixel
 *	Sets fill and stroke color in the given CG context from an X
 *	pixel value, or if the pixel code indicates a system color,
 *	sets the corresponding brush, textColor or background via
 *	field.
 *	HITheme APIs if available or Appearance mgr APIs.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetColorInContext(
    TCL_UNUSED(GC),
    GC gc,
    unsigned long pixel,
    CGContextRef context)
{
    OSStatus err = noErr;
    CGColorRef cgColor = NULL;
    SystemColorDatum *entry = GetEntryFromPixel(pixel);
    OSStatus err = -1;
    CGColorRef cgColor = CopyCachedColor(gc, pixel);
    ThemeBrush brush;
    ThemeTextColor textColor;
    ThemeBackgroundKind background;

    if (entry) {
	switch (entry->type) {
	case HIBrush:
	    err = ChkErr(HIThemeSetFill, entry->value, NULL, context,
    if (!cgColor && GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush,
	    &textColor, &background)) {
	if (brush) {
	    err = ChkErr(HIThemeSetFill, brush, NULL, context,
		    kHIThemeOrientationNormal);
	    if (err == noErr) {
		err = ChkErr(HIThemeSetStroke, entry->value, NULL, context,
		err = ChkErr(HIThemeSetStroke, brush, NULL, context,
			kHIThemeOrientationNormal);
	    }
	} else if (textColor) {
	    err = ChkErr(HIThemeSetTextFill, textColor, NULL, context,
		    kHIThemeOrientationNormal);
	} else if (background) {
	    CGRect rect = CGContextGetClipBoundingBox(context);
	    HIThemeBackgroundDrawInfo info = { 0, kThemeStateActive,
		    background };
	    break;
	default:
	    SetCGColorComponents(entry, pixel, &cgColor);

	    err = ChkErr(HIThemeApplyBackground, &rect, &info,
		    context, kHIThemeOrientationNormal);
	}
	if (err == noErr) {
	    return;
	}
	err = ChkErr(GetThemeColor, pixel, brush, textColor, background,
		&cgColor);
	    break;
	if (err == noErr) {
	    SetCachedColor(gc, pixel, cgColor);
	}
    } else if (!cgColor) {
	TkMacOSXDbgMsg("Ignored unknown pixel value 0x%lx", pixel);
    }
    if (cgColor) {
	CGContextSetFillColorWithColor(context, cgColor);
	CGContextSetStrokeColorWithColor(context, cgColor);
	CGColorRelease(cgColor);
    }
    if (err != noErr) {
	TkMacOSXDbgMsg("Ignored unknown pixel value 0x%lx", pixel);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetColor --
 *
 *	Create a new TkColor for the color with the given name, for use in the
 *	Allocate a new TkColor for the color with the given name.
 *      specified window. The colormap field is set to lightColormap if the
 *      window has a LightAqua appearance, or darkColormap if the window has a
 *      DarkAqua appearance.  TkColors with different colormaps are managed
 *      separately in the per-display table of TkColors maintained by Tk.
 *
 *      This function is called by Tk_GetColor.
 *
 * Results:
 *	Returns a newly allocated TkColor, or NULL on failure.
 *
 * Side effects:
 *
 *	Allocates memory for the TkColor structure.
 *	May invalidate the colormap cache associated with tkwin upon
 *	allocating a new colormap entry. Allocates a new TkColor
 *	structure.
 *
 *----------------------------------------------------------------------
 */

TkColor *
TkpGetColor(
    Tk_Window tkwin,		/* Window in which color will be used. */
    Tk_Uid name)		/* Name of color to be allocated (in form
    Tk_Uid name)		/* Name of color to allocated (in form
				 * suitable for passing to XParseColor). */
{
    Display *display = NULL;
    Display *display = tkwin != None ? Tk_Display(tkwin) : NULL;
    Colormap colormap = tkwin!= None ? Tk_Colormap(tkwin) : None;
    TkColor *tkColPtr;
    XColor color;
    Colormap colormap = tkwin ? Tk_Colormap(tkwin) : noColormap;
    NSView *view = nil;
    static Bool initialized = NO;

    if (!initialized) {
	initialized = YES;
	initColorTable();
    }
    if (tkwin) {
	display = Tk_Display(tkwin);
	Drawable d = Tk_WindowId(tkwin);
	view = TkMacOSXGetNSViewForDrawable(d);
    }

    /*
     * Check to see if this is a system color. If not, just call XParseColor.
     * Check to see if this is a system color. Otherwise, XParseColor
     * will do all the work.
     */

    if (strncasecmp(name, "system", 6) == 0) {
	Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&systemColors, name + 6);
	MacPixel p = {0};
	Tcl_Obj *strPtr = Tcl_NewStringObj(name+6, -1);
	int idx, result;

	if (hPtr != NULL) {
	    SystemColorDatum *entry = (SystemColorDatum *)Tcl_GetHashValue(hPtr);
	    CGColorRef c = NULL;

	result = Tcl_GetIndexFromObjStruct(NULL, strPtr, systemColorMap,
		    sizeof(struct SystemColorMapEntry), NULL, TCL_EXACT, &idx);
	Tcl_DecrRefCount(strPtr);
	if (result == TCL_OK) {
	    OSStatus err;
	    CGColorRef c;
	    unsigned char pixelCode = idx + MIN_PIXELCODE;
	    p.pixel.colortype = entry->type;
	    p.pixel.value = (unsigned int)entry->index;
	    color.pixel = p.ulong;
	    ThemeBrush brush = systemColorMap[idx].brush;
	    if (entry->type == semantic) {
		CGFloat rgba[4];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
		if (@available(macOS 10.14, *)) {
		    NSAppearance *windowAppearance;
		    if (view) {
			windowAppearance = [view effectiveAppearance];
		    } else {
			windowAppearance = [NSApp effectiveAppearance];
		    }
		    if ([windowAppearance name] == NSAppearanceNameDarkAqua) {
			colormap = darkColormap;
	    ThemeTextColor textColor = systemColorMap[idx].textColor;
		    } else {
			colormap = lightColormap;
		    }
	    ThemeBackgroundKind background = systemColorMap[idx].background;

		    if (@available(macOS 11.0, *)) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
			CGFloat *rgbaPtr = rgba;
			[windowAppearance performAsCurrentDrawingAppearance:^{
				GetRGBA(entry, p.ulong, rgbaPtr);
			    }];
#endif
		    } else {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
			NSAppearance *savedAppearance = [NSAppearance currentAppearance];
			[NSAppearance setCurrentAppearance:windowAppearance];
			GetRGBA(entry, p.ulong, rgba);
			[NSAppearance setCurrentAppearance:savedAppearance];
#endif
		    }
		} else {
		    GetRGBA(entry, p.ulong, rgba);
		}
#else
		GetRGBA(entry, p.ulong, rgba);
#endif
		color.red   = (unsigned short)(rgba[0] * 65535.0);
		color.green = (unsigned short)(rgba[1] * 65535.0);
		color.blue  = (unsigned short)(rgba[2] * 65535.0);
		goto validXColor;
	    } else if (SetCGColorComponents(entry, 0, &c)) {
	    err = ChkErr(GetThemeColor, 0, brush, textColor, background, &c);
	    if (err == noErr) {
		const size_t n = CGColorGetNumberOfComponents(c);
		const CGFloat *rgba = CGColorGetComponents(c);

		switch (n) {
		case 4:
		    color.red   = (unsigned short)(rgba[0] * 65535.0);
		    color.green = (unsigned short)(rgba[1] * 65535.0);
		    color.blue  = (unsigned short)(rgba[2] * 65535.0);
		    color.red   = rgba[0] * 65535.0;
		    color.green = rgba[1] * 65535.0;
		    color.blue  = rgba[2] * 65535.0;
		    break;
		case 2:
		    color.red = color.green = color.blue = (unsigned short)(rgba[0] * 65535.0);
		    color.red = color.green = color.blue = rgba[0] * 65535.0;
		    break;
		default:
		    Tcl_Panic("CGColor with %d components", (int) n);
		  Tcl_Panic("CGColor with %d components", (int) n);
		}
		color.pixel = ((((((pixelCode << 8)
		    | ((color.red   >> 8) & 0xff)) << 8)
		    | ((color.green >> 8) & 0xff)) << 8)
		    | ((color.blue  >> 8) & 0xff));
		CGColorRelease(c);
		goto validXColor;
	    }
	    CGColorRelease(c);
	}
    }

    if (TkParseColor(display, colormap, name, &color) == 0) {
	return NULL;
    }

validXColor:
    tkColPtr = (TkColor *)ckalloc(sizeof(TkColor));
    tkColPtr->colormap = colormap;
    tkColPtr->color = color;
    tkColPtr = ckalloc(sizeof(TkColor));
    tkColPtr->color = color;

    return tkColPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetColorByValue --
 *
 *	Given an pointer to an XColor, construct a TkColor whose red, green and
 *	blue intensities match those of the XColor as closely as possible.  For
 *	Given a desired set of red-green-blue intensities for a color,
 *	the Macintosh, this means that the colortype bitfield of the pixel
 *	value will be RGBColor and that the color intensities stored in its
 *	24-bit value bitfield are computed from the 16-bit red green and blue
 *	values in the XColor by dividing by 256.
 *	locate a pixel value to use to draw that color in a given
 *	window.
 *
 * Results:
 *	A pointer to a newly allocated TkColor structure.
 *	The return value is a pointer to an TkColor structure that
 *	indicates the closest red, blue, and green intensities available
 *	to those specified in colorPtr, and also specifies a pixel
 *	value to use to draw in that color.
 *
 * Side effects:
 *	May invalidate the colormap cache for the specified window.
 *	Allocates memory for a TkColor structure.
 *	Allocates a new TkColor structure.
 *
 *----------------------------------------------------------------------
 */

TkColor *
TkpGetColorByValue(
    TCL_UNUSED(Tk_Window),		/* Window in which color will be used. */
    Tk_Window tkwin,		/* Window in which color will be used. */
    XColor *colorPtr)		/* Red, green, and blue fields indicate
				 * desired color. */
{
    TkColor *tkColPtr = (TkColor *)ckalloc(sizeof(TkColor));
    TkColor *tkColPtr = ckalloc(sizeof(TkColor));

    tkColPtr->color.red = colorPtr->red;
    tkColPtr->color.green = colorPtr->green;
    tkColPtr->color.blue = colorPtr->blue;
    tkColPtr->color.pixel = TkpGetPixel(colorPtr);
    tkColPtr->color.pixel = TkpGetPixel(&tkColPtr->color);
    return tkColPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Stub functions --
763
764
765
766
767
768
769
770

771
772
773

774
775
776
777
778
779
780
781
782
783




784
785

786
787
788

789
790
791
792
793
794
795
796
797


798
799
800
801
802
803
804
805
806
807
808





809
810

811
812


813
814
815
816
817
818
819
820
821
822
823
824
672
673
674
675
676
677
678

679
680
681

682
683
684
685
686
687
688




689
690
691
692
693

694
695
696

697

698
699
700
701
702
703


704
705
706
707
708
709
710
711





712
713
714
715
716
717
718
719


720
721
722
723
724
725
726
727
728
729
730
731
732
733







-
+


-
+






-
-
-
-
+
+
+
+

-
+


-
+
-






-
-
+
+






-
-
-
-
-
+
+
+
+
+


+
-
-
+
+












 *
 *----------------------------------------------------------------------
 */

Status
XAllocColor(
    Display *display,		/* Display. */
    TCL_UNUSED(Colormap),		/* Not used. */
    Colormap map,		/* Not used. */
    XColor *colorPtr)		/* XColor struct to modify. */
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    colorPtr->pixel = TkpGetPixel(colorPtr);
    return 1;
}

Colormap
XCreateColormap(
    TCL_UNUSED(Display *),		/* Display. */
    TCL_UNUSED(Window),		/* X window. */
    TCL_UNUSED(Visual *),		/* Not used. */
    TCL_UNUSED(int))			/* Not used. */
    Display *display,		/* Display. */
    Window window,		/* X window. */
    Visual *visual,		/* Not used. */
    int alloc)			/* Not used. */
{
    static Colormap index = 16;
    static Colormap index = 1;

    /*
     * Just return a new value each time, large enough that it will not
     * Just return a new value each time.
     * conflict with any value of the macColormap enum.
     */
    return index++;
}

int
XFreeColormap(
    TCL_UNUSED(Display *),		/* Display. */
    TCL_UNUSED(Colormap))		/* Colormap. */
    Display* display,		/* Display. */
    Colormap colormap)		/* Colormap. */
{
    return Success;
}

int
XFreeColors(
    TCL_UNUSED(Display *),		/* Display. */
    TCL_UNUSED(Colormap),		/* Colormap. */
    TCL_UNUSED(unsigned long *),	/* Array of pixels. */
    TCL_UNUSED(int),		/* Number of pixels. */
    TCL_UNUSED(unsigned long))	/* Number of pixel planes. */
    Display* display,		/* Display. */
    Colormap colormap,		/* Colormap. */
    unsigned long* pixels,	/* Array of pixels. */
    int npixels,		/* Number of pixels. */
    unsigned long planes)	/* Number of pixel planes. */
{
    /*
     * The Macintosh version of Tk uses TrueColor. Nothing
     * Nothing needs to be done to release colors as there really is no
     * colormap in the Tk sense.
     * needs to be done to release colors as there really is
     * no colormap in the Tk sense.
     */
    return Success;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXColor.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203











































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#ifndef MACOSXCOLOR_H
#define MACOSXCOLOR_H
/*
 * The generic Tk code uses the X11 GC type to describe a graphics context.
 * (A GC is a pointer to a struct XGCValues).  The foreground and background
 * colors in a GC are unsigned longs.  These are meant to be used as indexes
 * into a table of XColors, where an XColor is declared in Xlib.h as:
 * typedef struct {
 *       unsigned long pixel;
 *       unsigned short red, green, blue;
 *       char flags;
 *       char pad;
 * } XColor;
 *
 * The xlib function XParseColor creates XColors from strings.  It recognizes
 * literal hexadecimal color specifications such as "#RRGGBB" as well as the
 * standard X11 color names.  When XParseColor creates an XColor it fills in
 * all of the fields except for the pixel field, and then passes the XColor
 * to TkpGetPixel to get a value to use for the pixel field. Since TkpGetPixel
 * is platform specific, each platform is free to choose a value which can
 * be used to set the foreground or background color in the platform's graphics
 * context.
 *
 * Tk represents a color by a struct TkColor, which extends the XColor struct.
 * Tk provides a mapping from color names to TkColors which extends the mapping
 * provided by XParseColor but also allows for platform specific color names.
 * By convention, these platform specific color names begin with the string
 * "system".  The mapping from names to TkColors is implemented by the function
 * TkpGetColor defined for the Macintosh in this file.  The pixel field in the
 * XColor contained in a TkColor will be stored in the X11 graphics context.
 * In X11 the pixel field is used as an index into a colormap.  On the Mac
 * the high order byte of the pixel is used to indicate a color type and
 * the low 24 bits are either used as an rgb value (if the type is rgbColor)
 * or as an index into a table of color descriptions.
 */

enum colorType {
    rgbColor,      /* The 24 bit value is an rgb color. */
    clearColor,    /* The unique rgba color with all channels 0. */
    HIBrush,       /* A HITheme brush color.*/
    ttkBackground, /* A background color which indicates nesting level.*/
    semantic,      /* A semantic NSColor.*/
};

typedef struct xpixel_t {
    unsigned value: 24;     /* Either RGB or an index into systemColorData. */
    unsigned colortype: 8;
} xpixel;

typedef union MacPixel_t {
    unsigned long ulong;
    xpixel pixel;
} MacPixel;

/*
 * We maintain two colormaps, one for the LightAqua appearance and one for the
 * DarkAqua appearance.
 */

enum macColormap {
    noColormap,
    lightColormap,
    darkColormap,
};

/*
 * In TkMacOSXColor.c a Tk hash table is constructed from the static data
 * below to map system color names to CGColors.
 */

typedef struct {
    const char *name;
    enum colorType type;
    ThemeBrush value;
    const char *macName;
    /* Fields below are filled in after or during construction of the hash table. */
    size_t index;
    NSString *selector;
} SystemColorDatum;

/*
 * WARNING: Semantic colors which are not supported on all systems must be
 * preceded by a backup color with the same name which *is* supported.  Systems
 * which do support the color will replace the backup value when the table is
 * constructed.  Failing to ensure this will result in a Tcl_Panic abort.
 */

static SystemColorDatum systemColorData[] = {
{"Pixel",				rgbColor, 0, NULL, 0, NULL },
{"Transparent",			       	clearColor,   0, NULL, 0, NULL },

{"Highlight",				HIBrush,  kThemeBrushPrimaryHighlightColor, NULL, 0, NULL },
{"HighlightSecondary",		    	HIBrush,  kThemeBrushSecondaryHighlightColor, NULL, 0, NULL },
{"HighlightText",			HIBrush,  kThemeBrushBlack, NULL, 0, NULL },
{"HighlightAlternate",			HIBrush,  kThemeBrushAlternatePrimaryHighlightColor, NULL, 0, NULL },
{"PrimaryHighlightColor",		HIBrush,  kThemeBrushPrimaryHighlightColor, NULL, 0, NULL },
{"ButtonFace",				HIBrush,  kThemeBrushButtonFaceActive, NULL, 0, NULL },
{"SecondaryHighlightColor",		HIBrush,  kThemeBrushSecondaryHighlightColor, NULL, 0, NULL },
{"ButtonFrame",				HIBrush,  kThemeBrushButtonFrameActive, NULL, 0, NULL },
{"AlternatePrimaryHighlightColor",      HIBrush,  kThemeBrushAlternatePrimaryHighlightColor, NULL, 0, NULL },
{"WindowBody",				HIBrush,  kThemeBrushDocumentWindowBackground, NULL, 0, NULL },
{"SheetBackground",			HIBrush,  kThemeBrushSheetBackground, NULL, 0, NULL },
{"MenuActive",				HIBrush,  kThemeBrushMenuBackgroundSelected, NULL, 0, NULL },
{"Menu",				HIBrush,  kThemeBrushMenuBackground, NULL, 0, NULL },
{"DialogBackgroundInactive",		HIBrush,  kThemeBrushDialogBackgroundInactive, NULL, 0, NULL },
{"DialogBackgroundActive",		HIBrush,  kThemeBrushDialogBackgroundActive, NULL, 0, NULL },
{"AlertBackgroundActive",		HIBrush,  kThemeBrushAlertBackgroundActive, NULL, 0, NULL },
{"AlertBackgroundInactive",		HIBrush,  kThemeBrushAlertBackgroundInactive, NULL, 0, NULL },
{"ModelessDialogBackgroundActive",	HIBrush,  kThemeBrushModelessDialogBackgroundActive, NULL, 0, NULL },
{"ModelessDialogBackgroundInactive",	HIBrush,  kThemeBrushModelessDialogBackgroundInactive, NULL, 0, NULL },
{"UtilityWindowBackgroundActive",	HIBrush,  kThemeBrushUtilityWindowBackgroundActive, NULL, 0, NULL },
{"UtilityWindowBackgroundInactive",	HIBrush,  kThemeBrushUtilityWindowBackgroundInactive, NULL, 0, NULL },
{"ListViewSortColumnBackground",	HIBrush,  kThemeBrushListViewSortColumnBackground, NULL, 0, NULL },
{"ListViewBackground",			HIBrush,  kThemeBrushListViewBackground, NULL, 0, NULL },
{"IconLabelBackground",			HIBrush,  kThemeBrushIconLabelBackground, NULL, 0, NULL },
{"ListViewSeparator",			HIBrush,  kThemeBrushListViewSeparator, NULL, 0, NULL },
{"ChasingArrows",			HIBrush,  kThemeBrushChasingArrows, NULL, 0, NULL },
{"DragHilite",				HIBrush,  kThemeBrushDragHilite, NULL, 0, NULL },
{"DocumentWindowBackground",		HIBrush,  kThemeBrushDocumentWindowBackground, NULL, 0, NULL },
{"FinderWindowBackground",		HIBrush,  kThemeBrushFinderWindowBackground, NULL, 0, NULL },
{"ScrollBarDelimiterActive",		HIBrush,  kThemeBrushScrollBarDelimiterActive, NULL, 0, NULL },
{"ScrollBarDelimiterInactive",		HIBrush,  kThemeBrushScrollBarDelimiterInactive, NULL, 0, NULL },
{"FocusHighlight",			HIBrush,  kThemeBrushFocusHighlight, NULL, 0, NULL },
{"PopupArrowActive",			HIBrush,  kThemeBrushPopupArrowActive, NULL, 0, NULL },
{"PopupArrowPressed",			HIBrush,  kThemeBrushPopupArrowPressed, NULL, 0, NULL },
{"PopupArrowInactive",			HIBrush,  kThemeBrushPopupArrowInactive, NULL, 0, NULL },
{"AppleGuideCoachmark",			HIBrush,  kThemeBrushAppleGuideCoachmark, NULL, 0, NULL },
{"IconLabelBackgroundSelected",		HIBrush,  kThemeBrushIconLabelBackgroundSelected, NULL, 0, NULL },
{"StaticAreaFill",			HIBrush,  kThemeBrushStaticAreaFill, NULL, 0, NULL },
{"ActiveAreaFill",			HIBrush,  kThemeBrushActiveAreaFill, NULL, 0, NULL },
{"ButtonFrameActive",			HIBrush,  kThemeBrushButtonFrameActive, NULL, 0, NULL },
{"ButtonFrameInactive",			HIBrush,  kThemeBrushButtonFrameInactive, NULL, 0, NULL },
{"ButtonFaceActive",			HIBrush,  kThemeBrushButtonFaceActive, NULL, 0, NULL },
{"ButtonFaceInactive",			HIBrush,  kThemeBrushButtonFaceInactive, NULL, 0, NULL },
{"ButtonFacePressed",			HIBrush,  kThemeBrushButtonFacePressed, NULL, 0, NULL },
{"ButtonActiveDarkShadow",		HIBrush,  kThemeBrushButtonActiveDarkShadow, NULL, 0, NULL },
{"ButtonActiveDarkHighlight",		HIBrush,  kThemeBrushButtonActiveDarkHighlight, NULL, 0, NULL },
{"ButtonActiveLightShadow",		HIBrush,  kThemeBrushButtonActiveLightShadow, NULL, 0, NULL },
{"ButtonActiveLightHighlight",		HIBrush,  kThemeBrushButtonActiveLightHighlight, NULL, 0, NULL },
{"ButtonInactiveDarkShadow",		HIBrush,  kThemeBrushButtonInactiveDarkShadow, NULL, 0, NULL },
{"ButtonInactiveDarkHighlight",		HIBrush,  kThemeBrushButtonInactiveDarkHighlight, NULL, 0, NULL },
{"ButtonInactiveLightShadow",		HIBrush,  kThemeBrushButtonInactiveLightShadow, NULL, 0, NULL },
{"ButtonInactiveLightHighlight",	HIBrush,  kThemeBrushButtonInactiveLightHighlight, NULL, 0, NULL },
{"ButtonPressedDarkShadow",		HIBrush,  kThemeBrushButtonPressedDarkShadow, NULL, 0, NULL },
{"ButtonPressedDarkHighlight",		HIBrush,  kThemeBrushButtonPressedDarkHighlight, NULL, 0, NULL },
{"ButtonPressedLightShadow",		HIBrush,  kThemeBrushButtonPressedLightShadow, NULL, 0, NULL },
{"ButtonPressedLightHighlight",		HIBrush,  kThemeBrushButtonPressedLightHighlight, NULL, 0, NULL },
{"BevelActiveLight",			HIBrush,  kThemeBrushBevelActiveLight, NULL, 0, NULL },
{"BevelActiveDark",			HIBrush,  kThemeBrushBevelActiveDark, NULL, 0, NULL },
{"BevelInactiveLight",			HIBrush,  kThemeBrushBevelInactiveLight, NULL, 0, NULL },
{"BevelInactiveDark",			HIBrush,  kThemeBrushBevelInactiveDark, NULL, 0, NULL },
{"NotificationWindowBackground",	HIBrush,  kThemeBrushNotificationWindowBackground, NULL, 0, NULL },
{"MovableModalBackground",		HIBrush,  kThemeBrushMovableModalBackground, NULL, 0, NULL },
{"SheetBackgroundOpaque",		HIBrush,  kThemeBrushSheetBackgroundOpaque, NULL, 0, NULL },
{"DrawerBackground",			HIBrush,  kThemeBrushDrawerBackground, NULL, 0, NULL },
{"ToolbarBackground",			HIBrush,  kThemeBrushToolbarBackground, NULL, 0, NULL },
{"SheetBackgroundTransparent",		HIBrush,  kThemeBrushSheetBackgroundTransparent, NULL, 0, NULL },
{"MenuBackground",			HIBrush,  kThemeBrushMenuBackground, NULL, 0, NULL },
{"MenuBackgroundSelected",		HIBrush,  kThemeBrushMenuBackgroundSelected, NULL, 0, NULL },
{"ListViewOddRowBackground",		HIBrush,  kThemeBrushListViewOddRowBackground, NULL, 0, NULL },
{"ListViewEvenRowBackground",		HIBrush,  kThemeBrushListViewEvenRowBackground, NULL, 0, NULL },
{"ListViewColumnDivider",		HIBrush,  kThemeBrushListViewColumnDivider, NULL, 0, NULL },

    /*
     * Dynamic Colors
     */

{"WindowBackgroundColor",	    ttkBackground, 0, NULL, 0, NULL },
{"WindowBackgroundColor1",	    ttkBackground, 1, NULL, 0, NULL },
{"WindowBackgroundColor2",	    ttkBackground, 2, NULL, 0, NULL },
{"WindowBackgroundColor3",	    ttkBackground, 3, NULL, 0, NULL },
{"WindowBackgroundColor4",	    ttkBackground, 4, NULL, 0, NULL },
{"WindowBackgroundColor5",	    ttkBackground, 5, NULL, 0, NULL },
{"WindowBackgroundColor6",	    ttkBackground, 6, NULL, 0, NULL },
{"WindowBackgroundColor7",	    ttkBackground, 7, NULL, 0, NULL },
/* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */
{"SecondaryLabelColor",		    ttkBackground, 14, NULL, 0, NULL },
/* Color to use for notebook tab label text -- depends on OS version. */
{"SelectedTabTextColor",	    semantic, 0, "textColor", 0, NULL },
/* Color to use for selected button labels -- depends on OS version. */
{"PressedButtonTextColor",	    semantic, 0, "textColor", 0, NULL },
/* Semantic colors that we simulate on older systems which don't supoort them. */
{"SelectedMenuItemTextColor",       semantic, 0, "selectedMenuItemTextColor", 0, NULL },
{"ControlAccentColor",		    semantic, 0, "controlAccentColor", 0, NULL },
{"LabelColor",                      semantic, 0, "blackColor", 0, NULL },
{"LinkColor",			    semantic, 0, "blueColor", 0, NULL },
{"PlaceholderTextColor",	    semantic, 0, "grayColor", 0, NULL },
{"SeparatorColor",		    semantic, 0, "grayColor", 0, NULL },
{"UnemphasizedSelectedTextBackgroundColor", semantic, 0, "grayColor", 0, NULL },
/* This color is available since 10.3, so the fallback is unused */
{"ControlAlternatingRowColor",	    semantic, 0, "grayColor" , 0, NULL },
{NULL,				    rgbColor, 0, NULL, 0, NULL }
};

#endif
/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXConfig.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40




41
42
43
44
45
46
47
48
49
50
51
52
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36




37
38
39
40
41
42
43















-
-
+
+











-
+





-
+










-
-
-
-
+
+
+
+



-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXConfig.c --
 *
 *	This module implements the Macintosh system defaults for
 *	the configuration package.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright © 2001, Apple Inc.
 * Copyright (c) 1997 by Sun Microsystems, Inc.
 * Copyright 2001, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"


/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSystemDefault --
 * TkpGetSystemDefault --
 *
 *	Given a dbName and className for a configuration option,
 *	return a string representation of the option.
 *
 * Results:
 *	Returns a Tcl_Obj* with the string identifier that identifies
 *	Returns a Tk_Uid that is the string identifier that identifies
 *	this option. Returns NULL if there are no system defaults
 *	that match this pair.
 *
 * Side effects:
 *	None, once the package is initialized.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
Tk_GetSystemDefault(
    TCL_UNUSED(Tk_Window),			/* A window to use. */
    TCL_UNUSED(const char *),			/* The option database name. */
    TCL_UNUSED(const char *))		/* The name of the option class. */
TkpGetSystemDefault(
    Tk_Window tkwin,			/* A window to use. */
    const char *dbName,			/* The option database name. */
    const char *className)		/* The name of the option class. */
{
    return NULL;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXConstants.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126






























































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXConstants.h --
 *
 *	Macros which map the names of NS constants used in the Tk code to
 *      the new name that Apple came up with for subsequent versions of the
 *      operating system.  (Each new OS release seems to come with a new
 *      naming convention for the same old constants.)
 *
 * Copyright © 2017 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMACCONSTANTS
#define _TKMACCONSTANTS

#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
#define NSFullScreenWindowMask (1 << 14)
#endif

#if MAC_OS_X_VERSION_MAX_ALLOWED < 1090
typedef NSInteger NSModalResponse;
#endif

/*
 * Let's raise a glass for the project manager who improves our lives by
 * generating deprecation warnings about pointless changes of the names
 * of constants.
 */

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#define kCTFontDefaultOrientation kCTFontOrientationDefault
#define kCTFontVerticalOrientation kCTFontOrientationVertical
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
#define NSOKButton NSModalResponseOK
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
#define kCTFontUserFixedPitchFontType kCTFontUIFontUserFixedPitch
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
#define NSAppKitDefined NSEventTypeAppKitDefined
#define NSApplicationDefined NSEventTypeApplicationDefined
#define NSApplicationActivatedEventType NSEventSubtypeApplicationActivated
#define NSApplicationDeactivatedEventType NSEventSubtypeApplicationDeactivated
#define NSWindowExposedEventType NSEventSubtypeWindowExposed
#define NSScreenChangedEventType NSEventSubtypeScreenChanged
#define NSWindowMovedEventType NSEventSubtypeWindowMoved
#define NSKeyUp NSEventTypeKeyUp
#define NSKeyDown NSEventTypeKeyDown
#define NSFlagsChanged NSEventTypeFlagsChanged
#define NSLeftMouseDown NSEventTypeLeftMouseDown
#define NSLeftMouseUp NSEventTypeLeftMouseUp
#define NSRightMouseDown NSEventTypeRightMouseDown
#define NSRightMouseUp NSEventTypeRightMouseUp
#define NSLeftMouseDragged NSEventTypeLeftMouseDragged
#define NSRightMouseDragged NSEventTypeRightMouseDragged
#define NSMouseMoved NSEventTypeMouseMoved
#define NSMouseEntered NSEventTypeMouseEntered
#define NSMouseExited NSEventTypeMouseExited
#define NSScrollWheel NSEventTypeScrollWheel
#define NSOtherMouseDown NSEventTypeOtherMouseDown
#define NSOtherMouseUp NSEventTypeOtherMouseUp
#define NSOtherMouseDragged NSEventTypeOtherMouseDragged
#define NSTabletPoint NSEventTypeTabletPoint
#define NSTabletProximity NSEventTypeTabletProximity
#define NSDeviceIndependentModifierFlagsMask NSEventModifierFlagDeviceIndependentFlagsMask
#define NSCommandKeyMask NSEventModifierFlagCommand
#define NSShiftKeyMask NSEventModifierFlagShift
#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock
#define NSAlternateKeyMask NSEventModifierFlagOption
#define NSControlKeyMask NSEventModifierFlagControl
#define NSNumericPadKeyMask NSEventModifierFlagNumericPad
#define NSFunctionKeyMask NSEventModifierFlagFunction
#define NSCursorUpdate NSEventTypeCursorUpdate
#define NSTexturedBackgroundWindowMask NSWindowStyleMaskTexturedBackground
#define NSCompositeCopy NSCompositingOperationCopy
#define NSCompositeSourceOver NSCompositingOperationSourceOver
#define NSCompositeSourceAtop NSCompositingOperationSourceAtop
#define NSCompositeDestinationIn NSCompositingOperationDestinationIn
#define NSWarningAlertStyle NSAlertStyleWarning
#define NSInformationalAlertStyle NSAlertStyleInformational
#define NSCriticalAlertStyle NSAlertStyleCritical
#define NSCenterTextAlignment NSTextAlignmentCenter
#define NSApplicationDefinedMask NSEventMaskApplicationDefined
#define NSUtilityWindowMask NSWindowStyleMaskUtilityWindow
#define NSNonactivatingPanelMask NSWindowStyleMaskNonactivatingPanel
#define NSDocModalWindowMask NSWindowStyleMaskDocModalWindow
#define NSHUDWindowMask NSWindowStyleMaskHUDWindow
#define NSTitledWindowMask NSWindowStyleMaskTitled
#define NSClosableWindowMask NSWindowStyleMaskClosable
#define NSResizableWindowMask NSWindowStyleMaskResizable
#define NSUnifiedTitleAndToolbarWindowMask NSWindowStyleMaskUnifiedTitleAndToolbar
#define NSMiniaturizableWindowMask NSWindowStyleMaskMiniaturizable
#define NSBorderlessWindowMask NSWindowStyleMaskBorderless
#define NSFullScreenWindowMask NSWindowStyleMaskFullScreen
#define NSAlphaFirstBitmapFormat NSBitmapFormatAlphaFirst
#define NSAnyEventMask NSEventMaskAny
#define NSLeftMouseDownMask NSEventMaskLeftMouseDown
#define NSMouseMovedMask NSEventMaskMouseMoved
#define NSLeftMouseDraggedMask NSEventMaskLeftMouseDragged
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
#define NSStringPboardType NSPasteboardTypeString
#define NSOnState NSControlStateValueOn
#define NSOffState NSControlStateValueOff
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
#define NSWindowStyleMaskTexturedBackground 0
#endif

#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
#define GET_NSCONTEXT(context, flip) [NSGraphicsContext		\
	    graphicsContextWithGraphicsPort:context flipped:flip]
#else
#define GET_NSCONTEXT(context, flip) [NSGraphicsContext		\
	    graphicsContextWithCGContext:context flipped:NO]
#endif

#endif

Changes to macosx/tkMacOSXCursor.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







/*
 * tkMacOSXCursor.c --
 *
 *	This file contains Macintosh specific cursor related routines.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXCursors.h"
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94






































95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181






















































































182
183
184
185
186
187
188

189









190
191
192
193
194
195
196
50
51
52
53
54
55
56






































57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95






















































































96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+

+
+
+
+
+
+
+
+
+







    NSPoint hotspot;
};

#define MacCursorData(n)	((id)tkMacOSXCursors[TK_MAC_CURSOR_##n])
#define MacXCursorData(n)	((id)tkMacOSXXCursors[TK_MAC_XCURSOR_##n])

static const struct CursorName cursorNames[] = {
    {"none",			NONE,	    nil, nil, {0, 0}},
    {"arrow",			SELECTOR,    @"arrowCursor", nil, {0, 0}},
    {"top_left_arrow",		SELECTOR,    @"arrowCursor", nil, {0, 0}},
    {"left_ptr",		SELECTOR,    @"arrowCursor", nil, {0, 0}},
    {"copyarrow",		SELECTOR,    @"dragCopyCursor", @"_copyDragCursor", {0, 0}},
    {"aliasarrow",		SELECTOR,    @"dragLinkCursor", @"_linkDragCursor", {0, 0}},
    {"contextualmenuarrow",	SELECTOR,    @"contextualMenuCursor", nil, {0, 0}},
    {"movearrow",		SELECTOR,    @"_moveCursor", nil, {0, 0}},
    {"ibeam",			SELECTOR,    @"IBeamCursor", nil, {0, 0}},
    {"text",			SELECTOR,    @"IBeamCursor", nil, {0, 0}},
    {"xterm",			SELECTOR,    @"IBeamCursor", nil, {0, 0}},
    {"cross",			SELECTOR,    @"crosshairCursor", nil, {0, 0}},
    {"crosshair",		SELECTOR,    @"crosshairCursor", nil, {0, 0}},
    {"cross-hair",		SELECTOR,    @"crosshairCursor", nil, {0, 0}},
    {"tcross",			SELECTOR,    @"crosshairCursor", nil, {0, 0}},
    {"hand",			SELECTOR,    @"openHandCursor", nil, {0, 0}},
    {"openhand",		SELECTOR,    @"openHandCursor", nil, {0, 0}},
    {"closedhand",		SELECTOR,    @"closedHandCursor", nil, {0, 0}},
    {"fist",			SELECTOR,    @"closedHandCursor", nil, {0, 0}},
    {"pointinghand",		SELECTOR,    @"pointingHandCursor", nil, {0, 0}},
    {"resize",			SELECTOR,    @"arrowCursor", nil, {0, 0}},
    {"resizeleft",		SELECTOR,    @"resizeLeftCursor", nil, {0, 0}},
    {"resizeright",		SELECTOR,    @"resizeRightCursor", nil, {0, 0}},
    {"resizeleftright",		SELECTOR,    @"resizeLeftRightCursor", nil, {0, 0}},
    {"resizeup",		SELECTOR,    @"resizeUpCursor", nil, {0, 0}},
    {"resizedown",		SELECTOR,    @"resizeDownCursor", nil, {0, 0}},
    {"resizeupdown",		SELECTOR,    @"resizeUpDownCursor", nil, {0, 0}},
    {"resizebottomleft",	SELECTOR,    @"_bottomLeftResizeCursor", nil, {0, 0}},
    {"resizetopleft",		SELECTOR,    @"_topLeftResizeCursor", nil, {0, 0}},
    {"resizebottomright",	SELECTOR,    @"_bottomRightResizeCursor", nil, {0, 0}},
    {"resizetopright",		SELECTOR,    @"_topRightResizeCursor", nil, {0, 0}},
    {"notallowed",		SELECTOR,    @"operationNotAllowedCursor", nil, {0, 0}},
    {"poof",			SELECTOR,    @"disappearingItemCursor", nil, {0, 0}},
    {"wait",			SELECTOR,    @"busyButClickableCursor", nil, {0, 0}},
    {"spinning",		SELECTOR,    @"busyButClickableCursor", nil, {0, 0}},
    {"countinguphand",		SELECTOR,    @"busyButClickableCursor", nil, {0, 0}},
    {"countingdownhand",	SELECTOR,    @"busyButClickableCursor", nil, {0, 0}},
    {"countingupanddownhand",	SELECTOR,    @"busyButClickableCursor", nil, {0, 0}},
    {"none",			NONE,	    nil},
    {"arrow",			SELECTOR,    @"arrowCursor"},
    {"top_left_arrow",		SELECTOR,    @"arrowCursor"},
    {"left_ptr",		SELECTOR,    @"arrowCursor"},
    {"copyarrow",		SELECTOR,    @"dragCopyCursor", @"_copyDragCursor"},
    {"aliasarrow",		SELECTOR,    @"dragLinkCursor", @"_linkDragCursor"},
    {"contextualmenuarrow",	SELECTOR,    @"contextualMenuCursor"},
    {"movearrow",		SELECTOR,    @"_moveCursor"},
    {"ibeam",			SELECTOR,    @"IBeamCursor"},
    {"text",			SELECTOR,    @"IBeamCursor"},
    {"xterm",			SELECTOR,    @"IBeamCursor"},
    {"cross",			SELECTOR,    @"crosshairCursor"},
    {"crosshair",		SELECTOR,    @"crosshairCursor"},
    {"cross-hair",		SELECTOR,    @"crosshairCursor"},
    {"tcross",			SELECTOR,    @"crosshairCursor"},
    {"hand",			SELECTOR,    @"openHandCursor"},
    {"openhand",		SELECTOR,    @"openHandCursor"},
    {"closedhand",		SELECTOR,    @"closedHandCursor"},
    {"fist",			SELECTOR,    @"closedHandCursor"},
    {"pointinghand",		SELECTOR,    @"pointingHandCursor"},
    {"resize",			SELECTOR,    @"arrowCursor"},
    {"resizeleft",		SELECTOR,    @"resizeLeftCursor"},
    {"resizeright",		SELECTOR,    @"resizeRightCursor"},
    {"resizeleftright",		SELECTOR,    @"resizeLeftRightCursor"},
    {"resizeup",		SELECTOR,    @"resizeUpCursor"},
    {"resizedown",		SELECTOR,    @"resizeDownCursor"},
    {"resizeupdown",		SELECTOR,    @"resizeUpDownCursor"},
    {"resizebottomleft",	SELECTOR,    @"_bottomLeftResizeCursor"},
    {"resizetopleft",		SELECTOR,    @"_topLeftResizeCursor"},
    {"resizebottomright",	SELECTOR,    @"_bottomRightResizeCursor"},
    {"resizetopright",		SELECTOR,    @"_topRightResizeCursor"},
    {"notallowed",		SELECTOR,    @"operationNotAllowedCursor"},
    {"poof",			SELECTOR,    @"disappearingItemCursor"},
    {"wait",			SELECTOR,    @"busyButClickableCursor"},
    {"spinning",		SELECTOR,    @"busyButClickableCursor"},
    {"countinguphand",		SELECTOR,    @"busyButClickableCursor"},
    {"countingdownhand",	SELECTOR,    @"busyButClickableCursor"},
    {"countingupanddownhand",	SELECTOR,    @"busyButClickableCursor"},
    {"help",			IMAGENAMED,  @"NSHelpCursor", nil, {8, 8}},
//  {"hand",			IMAGEBITMAP, MacCursorData(hand), nil, {0, 0}},
    {"bucket",			IMAGEBITMAP, MacCursorData(bucket), nil, {0, 0}},
    {"cancel",			IMAGEBITMAP, MacCursorData(cancel), nil, {0, 0}},
//  {"resize",			IMAGEBITMAP, MacCursorData(resize), nil, {0, 0}},
    {"eyedrop",			IMAGEBITMAP, MacCursorData(eyedrop), nil, {0, 0}},
    {"eyedrop-full",		IMAGEBITMAP, MacCursorData(eyedrop_full), nil, {0, 0}},
    {"zoom-in",			IMAGEBITMAP, MacCursorData(zoom_in), nil, {0, 0}},
    {"zoom-out",		IMAGEBITMAP, MacCursorData(zoom_out), nil, {0, 0}},
    {"X_cursor",		IMAGEBITMAP, MacXCursorData(X_cursor), nil, {0, 0}},
//  {"arrow",			IMAGEBITMAP, MacXCursorData(arrow), nil, {0, 0}},
    {"based_arrow_down",	IMAGEBITMAP, MacXCursorData(based_arrow_down), nil, {0, 0}},
    {"based_arrow_up",		IMAGEBITMAP, MacXCursorData(based_arrow_up), nil, {0, 0}},
    {"boat",			IMAGEBITMAP, MacXCursorData(boat), nil, {0, 0}},
    {"bogosity",		IMAGEBITMAP, MacXCursorData(bogosity), nil, {0, 0}},
    {"bottom_left_corner",	IMAGEBITMAP, MacXCursorData(bottom_left_corner), nil, {0, 0}},
    {"bottom_right_corner",	IMAGEBITMAP, MacXCursorData(bottom_right_corner), nil, {0, 0}},
    {"bottom_side",		IMAGEBITMAP, MacXCursorData(bottom_side), nil, {0, 0}},
    {"bottom_tee",		IMAGEBITMAP, MacXCursorData(bottom_tee), nil, {0, 0}},
    {"box_spiral",		IMAGEBITMAP, MacXCursorData(box_spiral), nil, {0, 0}},
    {"center_ptr",		IMAGEBITMAP, MacXCursorData(center_ptr), nil, {0, 0}},
    {"circle",			IMAGEBITMAP, MacXCursorData(circle), nil, {0, 0}},
    {"clock",			IMAGEBITMAP, MacXCursorData(clock), nil, {0, 0}},
    {"coffee_mug",		IMAGEBITMAP, MacXCursorData(coffee_mug), nil, {0, 0}},
//  {"cross",			IMAGEBITMAP, MacXCursorData(cross), nil, {0, 0}},
    {"cross_reverse",		IMAGEBITMAP, MacXCursorData(cross_reverse), nil, {0, 0}},
//  {"crosshair",		IMAGEBITMAP, MacXCursorData(crosshair), nil, {0, 0}},
    {"diamond_cross",		IMAGEBITMAP, MacXCursorData(diamond_cross), nil, {0, 0}},
    {"dot",			IMAGEBITMAP, MacXCursorData(dot), nil, {0, 0}},
    {"dotbox",			IMAGEBITMAP, MacXCursorData(dotbox), nil, {0, 0}},
    {"double_arrow",		IMAGEBITMAP, MacXCursorData(double_arrow), nil, {0, 0}},
    {"draft_large",		IMAGEBITMAP, MacXCursorData(draft_large), nil, {0, 0}},
    {"draft_small",		IMAGEBITMAP, MacXCursorData(draft_small), nil, {0, 0}},
    {"draped_box",		IMAGEBITMAP, MacXCursorData(draped_box), nil, {0, 0}},
    {"exchange",		IMAGEBITMAP, MacXCursorData(exchange), nil, {0, 0}},
    {"fleur",			IMAGEBITMAP, MacXCursorData(fleur), nil, {0, 0}},
    {"gobbler",			IMAGEBITMAP, MacXCursorData(gobbler), nil, {0, 0}},
    {"gumby",			IMAGEBITMAP, MacXCursorData(gumby), nil, {0, 0}},
    {"hand1",			IMAGEBITMAP, MacXCursorData(hand1), nil, {0, 0}},
    {"hand2",			IMAGEBITMAP, MacXCursorData(hand2), nil, {0, 0}},
    {"heart",			IMAGEBITMAP, MacXCursorData(heart), nil, {0, 0}},
    {"icon",			IMAGEBITMAP, MacXCursorData(icon), nil, {0, 0}},
    {"iron_cross",		IMAGEBITMAP, MacXCursorData(iron_cross), nil, {0, 0}},
//  {"left_ptr",		IMAGEBITMAP, MacXCursorData(left_ptr), nil, {0, 0}},
    {"left_side",		IMAGEBITMAP, MacXCursorData(left_side), nil, {0, 0}},
    {"left_tee",		IMAGEBITMAP, MacXCursorData(left_tee), nil, {0, 0}},
    {"leftbutton",		IMAGEBITMAP, MacXCursorData(leftbutton), nil, {0, 0}},
    {"ll_angle",		IMAGEBITMAP, MacXCursorData(ll_angle), nil, {0, 0}},
    {"lr_angle",		IMAGEBITMAP, MacXCursorData(lr_angle), nil, {0, 0}},
    {"man",			IMAGEBITMAP, MacXCursorData(man), nil, {0, 0}},
    {"middlebutton",		IMAGEBITMAP, MacXCursorData(middlebutton), nil, {0, 0}},
    {"mouse",			IMAGEBITMAP, MacXCursorData(mouse), nil, {0, 0}},
    {"pencil",			IMAGEBITMAP, MacXCursorData(pencil), nil, {0, 0}},
    {"pirate",			IMAGEBITMAP, MacXCursorData(pirate), nil, {0, 0}},
    {"plus",			IMAGEBITMAP, MacXCursorData(plus), nil, {0, 0}},
    {"question_arrow",		IMAGEBITMAP, MacXCursorData(question_arrow), nil, {0, 0}},
    {"right_ptr",		IMAGEBITMAP, MacXCursorData(right_ptr), nil, {0, 0}},
    {"right_side",		IMAGEBITMAP, MacXCursorData(right_side), nil, {0, 0}},
    {"right_tee",		IMAGEBITMAP, MacXCursorData(right_tee), nil, {0, 0}},
    {"rightbutton",		IMAGEBITMAP, MacXCursorData(rightbutton), nil, {0, 0}},
    {"rtl_logo",		IMAGEBITMAP, MacXCursorData(rtl_logo), nil, {0, 0}},
    {"sailboat",		IMAGEBITMAP, MacXCursorData(sailboat), nil, {0, 0}},
    {"sb_down_arrow",		IMAGEBITMAP, MacXCursorData(sb_down_arrow), nil, {0, 0}},
    {"sb_h_double_arrow",	IMAGEBITMAP, MacXCursorData(sb_h_double_arrow), nil, {0, 0}},
    {"sb_left_arrow",		IMAGEBITMAP, MacXCursorData(sb_left_arrow), nil, {0, 0}},
    {"sb_right_arrow",		IMAGEBITMAP, MacXCursorData(sb_right_arrow), nil, {0, 0}},
    {"sb_up_arrow",		IMAGEBITMAP, MacXCursorData(sb_up_arrow), nil, {0, 0}},
    {"sb_v_double_arrow",	IMAGEBITMAP, MacXCursorData(sb_v_double_arrow), nil, {0, 0}},
    {"shuttle",			IMAGEBITMAP, MacXCursorData(shuttle), nil, {0, 0}},
    {"sizing",			IMAGEBITMAP, MacXCursorData(sizing), nil, {0, 0}},
    {"spider",			IMAGEBITMAP, MacXCursorData(spider), nil, {0, 0}},
    {"spraycan",		IMAGEBITMAP, MacXCursorData(spraycan), nil, {0, 0}},
    {"star",			IMAGEBITMAP, MacXCursorData(star), nil, {0, 0}},
    {"target",			IMAGEBITMAP, MacXCursorData(target), nil, {0, 0}},
//  {"tcross",			IMAGEBITMAP, MacXCursorData(tcross), nil, {0, 0}},
//  {"top_left_arrow",		IMAGEBITMAP, MacXCursorData(top_left_arrow), nil, {0, 0}},
    {"top_left_corner",		IMAGEBITMAP, MacXCursorData(top_left_corner), nil, {0, 0}},
    {"top_right_corner",	IMAGEBITMAP, MacXCursorData(top_right_corner), nil, {0, 0}},
    {"top_side",		IMAGEBITMAP, MacXCursorData(top_side), nil, {0, 0}},
    {"top_tee",			IMAGEBITMAP, MacXCursorData(top_tee), nil, {0, 0}},
    {"trek",			IMAGEBITMAP, MacXCursorData(trek), nil, {0, 0}},
    {"ul_angle",		IMAGEBITMAP, MacXCursorData(ul_angle), nil, {0, 0}},
    {"umbrella",		IMAGEBITMAP, MacXCursorData(umbrella), nil, {0, 0}},
    {"ur_angle",		IMAGEBITMAP, MacXCursorData(ur_angle), nil, {0, 0}},
    {"watch",			IMAGEBITMAP, MacXCursorData(watch), nil, {0, 0}},
//  {"xterm",			IMAGEBITMAP, MacXCursorData(xterm), nil, {0, 0}},
    {NULL, 0, nil, nil, {0, 0}}
//  {"hand",			IMAGEBITMAP, MacCursorData(hand)},
    {"bucket",			IMAGEBITMAP, MacCursorData(bucket)},
    {"cancel",			IMAGEBITMAP, MacCursorData(cancel)},
//  {"resize",			IMAGEBITMAP, MacCursorData(resize)},
    {"eyedrop",			IMAGEBITMAP, MacCursorData(eyedrop)},
    {"eyedrop-full",		IMAGEBITMAP, MacCursorData(eyedrop_full)},
    {"zoom-in",			IMAGEBITMAP, MacCursorData(zoom_in)},
    {"zoom-out",		IMAGEBITMAP, MacCursorData(zoom_out)},
    {"X_cursor",		IMAGEBITMAP, MacXCursorData(X_cursor)},
//  {"arrow",			IMAGEBITMAP, MacXCursorData(arrow)},
    {"based_arrow_down",	IMAGEBITMAP, MacXCursorData(based_arrow_down)},
    {"based_arrow_up",		IMAGEBITMAP, MacXCursorData(based_arrow_up)},
    {"boat",			IMAGEBITMAP, MacXCursorData(boat)},
    {"bogosity",		IMAGEBITMAP, MacXCursorData(bogosity)},
    {"bottom_left_corner",	IMAGEBITMAP, MacXCursorData(bottom_left_corner)},
    {"bottom_right_corner",	IMAGEBITMAP, MacXCursorData(bottom_right_corner)},
    {"bottom_side",		IMAGEBITMAP, MacXCursorData(bottom_side)},
    {"bottom_tee",		IMAGEBITMAP, MacXCursorData(bottom_tee)},
    {"box_spiral",		IMAGEBITMAP, MacXCursorData(box_spiral)},
    {"center_ptr",		IMAGEBITMAP, MacXCursorData(center_ptr)},
    {"circle",			IMAGEBITMAP, MacXCursorData(circle)},
    {"clock",			IMAGEBITMAP, MacXCursorData(clock)},
    {"coffee_mug",		IMAGEBITMAP, MacXCursorData(coffee_mug)},
//  {"cross",			IMAGEBITMAP, MacXCursorData(cross)},
    {"cross_reverse",		IMAGEBITMAP, MacXCursorData(cross_reverse)},
//  {"crosshair",		IMAGEBITMAP, MacXCursorData(crosshair)},
    {"diamond_cross",		IMAGEBITMAP, MacXCursorData(diamond_cross)},
    {"dot",			IMAGEBITMAP, MacXCursorData(dot)},
    {"dotbox",			IMAGEBITMAP, MacXCursorData(dotbox)},
    {"double_arrow",		IMAGEBITMAP, MacXCursorData(double_arrow)},
    {"draft_large",		IMAGEBITMAP, MacXCursorData(draft_large)},
    {"draft_small",		IMAGEBITMAP, MacXCursorData(draft_small)},
    {"draped_box",		IMAGEBITMAP, MacXCursorData(draped_box)},
    {"exchange",		IMAGEBITMAP, MacXCursorData(exchange)},
    {"fleur",			IMAGEBITMAP, MacXCursorData(fleur)},
    {"gobbler",			IMAGEBITMAP, MacXCursorData(gobbler)},
    {"gumby",			IMAGEBITMAP, MacXCursorData(gumby)},
    {"hand1",			IMAGEBITMAP, MacXCursorData(hand1)},
    {"hand2",			IMAGEBITMAP, MacXCursorData(hand2)},
    {"heart",			IMAGEBITMAP, MacXCursorData(heart)},
    {"icon",			IMAGEBITMAP, MacXCursorData(icon)},
    {"iron_cross",		IMAGEBITMAP, MacXCursorData(iron_cross)},
//  {"left_ptr",		IMAGEBITMAP, MacXCursorData(left_ptr)},
    {"left_side",		IMAGEBITMAP, MacXCursorData(left_side)},
    {"left_tee",		IMAGEBITMAP, MacXCursorData(left_tee)},
    {"leftbutton",		IMAGEBITMAP, MacXCursorData(leftbutton)},
    {"ll_angle",		IMAGEBITMAP, MacXCursorData(ll_angle)},
    {"lr_angle",		IMAGEBITMAP, MacXCursorData(lr_angle)},
    {"man",			IMAGEBITMAP, MacXCursorData(man)},
    {"middlebutton",		IMAGEBITMAP, MacXCursorData(middlebutton)},
    {"mouse",			IMAGEBITMAP, MacXCursorData(mouse)},
    {"pencil",			IMAGEBITMAP, MacXCursorData(pencil)},
    {"pirate",			IMAGEBITMAP, MacXCursorData(pirate)},
    {"plus",			IMAGEBITMAP, MacXCursorData(plus)},
    {"question_arrow",		IMAGEBITMAP, MacXCursorData(question_arrow)},
    {"right_ptr",		IMAGEBITMAP, MacXCursorData(right_ptr)},
    {"right_side",		IMAGEBITMAP, MacXCursorData(right_side)},
    {"right_tee",		IMAGEBITMAP, MacXCursorData(right_tee)},
    {"rightbutton",		IMAGEBITMAP, MacXCursorData(rightbutton)},
    {"rtl_logo",		IMAGEBITMAP, MacXCursorData(rtl_logo)},
    {"sailboat",		IMAGEBITMAP, MacXCursorData(sailboat)},
    {"sb_down_arrow",		IMAGEBITMAP, MacXCursorData(sb_down_arrow)},
    {"sb_h_double_arrow",	IMAGEBITMAP, MacXCursorData(sb_h_double_arrow)},
    {"sb_left_arrow",		IMAGEBITMAP, MacXCursorData(sb_left_arrow)},
    {"sb_right_arrow",		IMAGEBITMAP, MacXCursorData(sb_right_arrow)},
    {"sb_up_arrow",		IMAGEBITMAP, MacXCursorData(sb_up_arrow)},
    {"sb_v_double_arrow",	IMAGEBITMAP, MacXCursorData(sb_v_double_arrow)},
    {"shuttle",			IMAGEBITMAP, MacXCursorData(shuttle)},
    {"sizing",			IMAGEBITMAP, MacXCursorData(sizing)},
    {"spider",			IMAGEBITMAP, MacXCursorData(spider)},
    {"spraycan",		IMAGEBITMAP, MacXCursorData(spraycan)},
    {"star",			IMAGEBITMAP, MacXCursorData(star)},
    {"target",			IMAGEBITMAP, MacXCursorData(target)},
//  {"tcross",			IMAGEBITMAP, MacXCursorData(tcross)},
//  {"top_left_arrow",		IMAGEBITMAP, MacXCursorData(top_left_arrow)},
    {"top_left_corner",		IMAGEBITMAP, MacXCursorData(top_left_corner)},
    {"top_right_corner",	IMAGEBITMAP, MacXCursorData(top_right_corner)},
    {"top_side",		IMAGEBITMAP, MacXCursorData(top_side)},
    {"top_tee",			IMAGEBITMAP, MacXCursorData(top_tee)},
    {"trek",			IMAGEBITMAP, MacXCursorData(trek)},
    {"ul_angle",		IMAGEBITMAP, MacXCursorData(ul_angle)},
    {"umbrella",		IMAGEBITMAP, MacXCursorData(umbrella)},
    {"ur_angle",		IMAGEBITMAP, MacXCursorData(ur_angle)},
    {"watch",			IMAGEBITMAP, MacXCursorData(watch)},
//  {"xterm",			IMAGEBITMAP, MacXCursorData(xterm)},
    {NULL}
};

/*
 * Declarations of static variables used in this file.
 */

static TkMacOSXCursor *gCurrentCursor = NULL;
static TkMacOSXCursor * gCurrentCursor = NULL;
				/* A pointer to the current cursor. */
static int gResizeOverride = false;
				/* A boolean indicating whether we should use
				 * the resize cursor during installations. */
static int gTkOwnsCursor = true;/* A boolean indicating whether Tk owns the
				 * cursor. If not (for instance, in the case
				 * where a Tk window is embedded in another
				 * app's window, and the cursor is out of the
				 * tk window, we will not attempt to adjust
				 * the cursor. */

/*
 * Declarations of procedures local to this file
 */

static void FindCursorByName(TkMacOSXCursor *macCursorPtr, const char *string);

227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250







-
+







	/*
	 * System cursor of type @filename
	 */

	macCursorPtr->type = IMAGEPATH;
	path = [NSString stringWithUTF8String:&name[1]];
    } else {
	Tcl_Obj *strPtr = Tcl_NewStringObj(name, TCL_INDEX_NONE);
	Tcl_Obj *strPtr = Tcl_NewStringObj(name, -1);
	int idx;

	result = Tcl_GetIndexFromObjStruct(NULL, strPtr, cursorNames,
		    sizeof(struct CursorName), NULL, TCL_EXACT, &idx);
	Tcl_DecrRefCount(strPtr);
	if (result == TCL_OK) {
	    macCursorPtr->type = cursorNames[idx].kind;
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276
277
278
279
267
268
269
270
271
272
273

274
275
276
277
278
279
280

281
282
283
284
285
286
287







-
+






-







		haveHotSpot = 1;
		break;
	    case IMAGEPATH:
		path = [NSApp tkFrameworkImagePath:cursorNames[idx].id1];
		break;
	    case IMAGEBITMAP: {
		unsigned char *bitmap = (unsigned char *)(cursorNames[idx].id1);
		NSBitmapImageRep *bitmapImageRep = nil;
		NSBitmapImageRep *bitmapImageRep = NULL;
		CGImageRef img = NULL, mask = NULL, maskedImg = NULL;
		static const CGFloat decodeWB[] = {1, 0};
		CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(
			kCGColorSpaceGenericGray);
		CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
			bitmap, pix*pix/8, NULL);

		if (provider) {
		    img = CGImageCreate(pix, pix, 1, 1, pix/8, colorspace,
			    kCGBitmapByteOrderDefault, provider, decodeWB, 0,
			    kCGRenderingIntentDefault);
		    CFRelease(provider);
		}
		provider = CGDataProviderCreateWithData(NULL, bitmap +
287
288
289
290
291
292
293
294

295
296
297

298
299
300

301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
295
296
297
298
299
300
301

302



303



304


305
306
307

308
309

310
311
312
313
314
315
316







-
+
-
-
-
+
-
-
-
+
-
-



-


-







		    maskedImg = CGImageCreateWithMask(img, mask);
		}
		if (maskedImg) {
		    bitmapImageRep = [[NSBitmapImageRep alloc]
			    initWithCGImage:maskedImg];
		    CFRelease(maskedImg);
		}
		if (mask) {
		if (mask) { CFRelease(mask); }
		    CFRelease(mask);
		}
		if (img) {
		if (img)  { CFRelease(img); }
		    CFRelease(img);
		}
		if (colorspace) {
		if (colorspace) { CFRelease(colorspace); }
		    CFRelease(colorspace);
		}
		if (bitmapImageRep) {
		    image = [[NSImage alloc] initWithSize:NSMakeSize(pix, pix)];
		    [image addRepresentation:bitmapImageRep];
		    [image setTemplate:YES];
		    [bitmapImageRep release];
		}

		uint16_t *hotSpotData = (uint16_t*)(bitmap + 2*pix*pix/8);
		hotSpot.y = CFSwapInt16BigToHost(*hotSpotData++);
		hotSpot.x = CFSwapInt16BigToHost(*hotSpotData);
		haveHotSpot = 1;
		break;
	    }
	    }
362
363
364
365
366
367
368
369

370
371
372
373
374
375

376
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
362
363
364
365
366
367
368

369
370
371
372
373
374

375
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391







-
+





-
+








-
+







 *
 *----------------------------------------------------------------------
 */

TkCursor *
TkGetCursorByName(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    TCL_UNUSED(Tk_Window),		/* Window in which cursor will be used. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    Tk_Uid string)		/* Description of cursor. See manual entry
				 * for details on legal syntax. */
{
    TkMacOSXCursor *macCursorPtr = NULL;
    const char **argv = NULL;
    Tcl_Size argc;
    int argc;

    /*
     * All cursor names are valid lists of one element (for
     * TkX11-compatibility), even unadorned system cursor names.
     */

    if (Tcl_SplitList(interp, string, &argc, &argv) == TCL_OK) {
	if (argc) {
	    macCursorPtr = (TkMacOSXCursor *)ckalloc(sizeof(TkMacOSXCursor));
	    macCursorPtr = ckalloc(sizeof(TkMacOSXCursor));
	    macCursorPtr->info.cursor = (Tk_Cursor) macCursorPtr;
	    macCursorPtr->macCursor = nil;
	    macCursorPtr->type = 0;
	    FindCursorByName(macCursorPtr, argv[0]);
	}
	ckfree(argv);
    }
416
417
418
419
420
421
422
423
424
425
426




427
428

429
430
431


432
433
434
435
436
437
438
416
417
418
419
420
421
422




423
424
425
426


427



428
429
430
431
432
433
434
435
436







-
-
-
-
+
+
+
+
-
-
+
-
-
-
+
+







 *	Allocates a new cursor.
 *
 *----------------------------------------------------------------------
 */

TkCursor *
TkCreateCursorFromData(
    TCL_UNUSED(Tk_Window),		/* Window in which cursor will be used. */
    TCL_UNUSED(const char *),		/* Bitmap data for cursor shape. */
    TCL_UNUSED(const char *),		/* Bitmap data for cursor mask. */
    TCL_UNUSED(int),	/* Dimensions of cursor. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    const char *source,		/* Bitmap data for cursor shape. */
    const char *mask,		/* Bitmap data for cursor mask. */
    int width, int height,	/* Dimensions of cursor. */
    TCL_UNUSED(int),
    TCL_UNUSED(int),		/* Location of hot-spot in cursor. */
    int xHot, int yHot,		/* Location of hot-spot in cursor. */
    TCL_UNUSED(int),
    TCL_UNUSED(XColor),		/* Foreground color for cursor. */
    TCL_UNUSED(XColor))		/* Background color for cursor. */
    XColor fgColor,		/* Foreground color for cursor. */
    XColor bgColor)		/* Background color for cursor. */
{
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+







void
TkpFreeCursor(
    TkCursor *cursorPtr)
{
    TkMacOSXCursor *macCursorPtr = (TkMacOSXCursor *) cursorPtr;

    [macCursorPtr->macCursor release];
    macCursorPtr->macCursor = nil;
    macCursorPtr->macCursor = NULL;
    if (macCursorPtr == gCurrentCursor) {
	gCurrentCursor = NULL;
    }
}

/*
 *----------------------------------------------------------------------
476
477
478
479
480
481
482
483

484
485

486
487
488
489
490


491

492
493
494
495
496
497
498
474
475
476
477
478
479
480

481
482

483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498







-
+

-
+





+
+
-
+







 *
 * Side effects:
 *	Changes the Macintosh mouse cursor.
 *
 *----------------------------------------------------------------------
 */

static void
void
TkMacOSXInstallCursor(
    void)
    int resizeOverride)
{
    TkMacOSXCursor *macCursorPtr = gCurrentCursor;
    static int cursorHidden = 0;
    int cursorNone = 0;

    gResizeOverride = resizeOverride;

    if (!macCursorPtr) {
    if (resizeOverride || !macCursorPtr) {
	[[NSCursor arrowCursor] set];
    } else {
	switch (macCursorPtr->type) {
	case NONE:
	    if (!cursorHidden) {
		cursorHidden = 1;
		[NSCursor hide];
532
533
534
535
536
537
538




539

540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557

558
559























560
561
562
563
564
565
566
567
568
532
533
534
535
536
537
538
539
540
541
542

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595







+
+
+
+
-
+

















-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










void
TkpSetCursor(
    TkpCursor cursor)
{
    int cursorChanged = 1;

    if (!gTkOwnsCursor) {
	return;
    }

    if (cursor == NULL) {
    if (cursor == None) {
	/*
	 * This is a little tricky. We can't really tell whether
	 * gCurrentCursor is NULL because it was NULL last time around or
	 * because we just freed the current cursor. So if the input cursor is
	 * NULL, we always need to reset it, we can't trust the cursorChanged
	 * logic.
	 */

	gCurrentCursor = NULL;
    } else {
	if (gCurrentCursor == (TkMacOSXCursor *) cursor) {
	    cursorChanged = 0;
	}
	gCurrentCursor = (TkMacOSXCursor *) cursor;
    }

    if (Tk_MacOSXIsAppInFront() && cursorChanged) {
	TkMacOSXInstallCursor();
	TkMacOSXInstallCursor(gResizeOverride);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXTkOwnsCursor --
 *
 *	Sets whether Tk has the right to adjust the cursor.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May keep Tk from changing the cursor.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MacOSXTkOwnsCursor(
    int tkOwnsIt)
{
    gTkOwnsCursor = tkOwnsIt;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXCursors.h.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16






-
-
-
+
+
+







/*
 * tkMacOSXCursors.h --
 *
 *	This file defines a set of Macintosh cursor resources that
 *	are only available on the Macintosh platform.
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * Copyright © 2008-2009 Apple Inc.
 * Copyright © 2008-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright 2008-2009, Apple Inc.
 * Copyright (c) 2008-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

static const unsigned char tkMacOSXCursors[][68] = {

Changes to macosx/tkMacOSXDebug.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkMacOSXDebug.c --
 *
 *	Implementation of Macintosh specific functions for debugging MacOS
 *	events, regions, etc...
 *
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXDebug.h"
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74







-
+








	if (module && *module) {
	    module_len = strlen(module);
	}
	for (i = 0; i < n; i++) {
	    if (module && *module) {
		/* Find image with given module name */
		const char *name;
		char *name;
		const char *path = _dyld_get_image_name(i);

		if (!path) {
		    continue;
		}
		name = strrchr(path, '/') + 1;
		if (strncmp(name, module, module_len) != 0) {

Changes to macosx/tkMacOSXDebug.h.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkMacOSXDebug.h --
 *
 *	Declarations of Macintosh specific functions for debugging MacOS events,
 *	regions, etc...
 *
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMACDEBUG
#define _TKMACDEBUG

Changes to macosx/tkMacOSXDefault.h.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45





46
47
48

49
50
51
52
53
54
55
56
57
58
59


60

61

62
63
64
65
66
67
68
69
70
71

72
73

74
75
76
77
78

79
80
81
82
83
84
85
86

87
88
89
90
91
92




93

94




95

96
97
98
99
100
101
102
103

104
105
106

107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
19
20
21
22
23
24
25

26

27
28
29
30
31
32
33
34
35

36







37
38
39
40
41
42
43

44

45
46
47
48
49
50
51
52


53
54
55
56

57
58
59
60
61
62
63
64
65
66

67


68
69
70
71
72

73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156







-

-









-
+
-
-
-
-
-
-
-
+
+
+
+
+


-
+
-








-
-
+
+

+
-
+









-
+
-
-
+




-
+







-
+






+
+
+
+

+

+
+
+
+

+







-
+


-
+


+


















-
+















-
+







//#ifndef TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
//#define TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS 1
//#endif

/*
 * The definitions below provide symbolic names for the default colors.
 * NORMAL_BG -		Normal background color.
 * NORMAL_FG -		Normal foreground color.
 * ACTIVE_BG -		Background color when widget is active.
 * ACTIVE_FG -		Foreground color when widget is active.
 * SELECT_BG -		Background color for selected text.
 * SELECT_FG -		Foreground color for selected text.
 * TROUGH -		Background color for troughs in scales and scrollbars.
 * INDICATOR -		Color for indicator when button is selected.
 * DISABLED -		Foreground color when widget is disabled.
 */

#define BLACK			"Black"
#define WHITE			"White"
#define NORMAL_BG		"systemWindowBackgroundColor"
#define NORMAL_BG		"systemWindowBody"
#define TEXT_BG                 "systemTextBackgroundColor"
#define NORMAL_FG		"systemTextColor"
#define ACTIVE_BG		"systemWindowBackgroundColor"
#define ACTIVE_FG		"systemTextColor"
#define SELECT_BG		"systemSelectedTextBackgroundColor"
#define SELECT_FG		"systemSelectedTextColor"
#define INACTIVE_SELECT_BG	"systemUnemphasizedSelectedTextBackgroundColor"
#define ACTIVE_BG		"systemButtonFacePressed"
#define ACTIVE_FG		"systemPushButtonPressedText"
#define SELECT_BG		"systemHighlight"
#define SELECT_FG		None
#define INACTIVE_SELECT_BG	"systemHighlightSecondary"
#define TROUGH			"#c3c3c3"
#define INDICATOR		"#b03060"
#define DISABLED		"systemDisabledControlTextColor"
#define DISABLED		"#a3a3a3"
#define IGNORED                 "#abcdef"

/*
 * Defaults for labels, buttons, checkbuttons, and radiobuttons:
 */

#define DEF_BUTTON_ANCHOR		"center"
#define DEF_BUTTON_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_BUTTON_ACTIVE_BG_MONO	BLACK
#define DEF_BUTTON_ACTIVE_FG_COLOR	"systemPressedButtonTextColor"
#define DEF_CHKRAD_ACTIVE_FG_COLOR	ACTIVE_FG
#define DEF_BUTTON_ACTIVE_FG_COLOR	ACTIVE_FG
#define DEF_CHKRAD_ACTIVE_FG_COLOR	DEF_BUTTON_ACTIVE_FG_COLOR
#define DEF_BUTTON_ACTIVE_FG_MONO	WHITE
/* #define DEF_BUTTON_BG_COLOR	"systemButtonFace"*/
#define DEF_BUTTON_BG_COLOR		NORMAL_BG
#define DEF_BUTTON_BG_COLOR		WHITE
#define DEF_BUTTON_BG_MONO		WHITE
#define DEF_BUTTON_BITMAP		""
#define DEF_BUTTON_BORDER_WIDTH		"2"
#define DEF_BUTTON_CURSOR		""
#define DEF_BUTTON_COMMAND		""
#define DEF_BUTTON_COMPOUND		"none"
#define DEF_BUTTON_DEFAULT		"disabled"
#define DEF_BUTTON_DISABLED_FG_COLOR	DISABLED
#define DEF_BUTTON_DISABLED_FG_MONO	""
#define DEF_BUTTON_FG			BLACK
#define DEF_BUTTON_FG			"systemButtonText"
#define DEF_LABEL_FG			NORMAL_FG
#define DEF_CHKRAD_FG			DEF_LABEL_FG
#define DEF_CHKRAD_FG			DEF_BUTTON_FG
#define DEF_BUTTON_FONT			"TkDefaultFont"
#define DEF_BUTTON_HEIGHT		"0"
#define DEF_BUTTON_HIGHLIGHT_BG_COLOR	DEF_BUTTON_BG_COLOR
#define DEF_BUTTON_HIGHLIGHT_BG_MONO	DEF_BUTTON_BG_MONO
#define DEF_BUTTON_HIGHLIGHT		NORMAL_FG
#define DEF_BUTTON_HIGHLIGHT		"systemButtonFrame"
#define DEF_LABEL_HIGHLIGHT_WIDTH	"0"
//#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
//#define DEF_BUTTON_HIGHLIGHT_WIDTH	"4"
//#define DEF_BUTTON_HIGHLIGHT_WIDTH_NOCM	"1"
//#else
#define DEF_BUTTON_HIGHLIGHT_WIDTH	"1"
//#endif
#define DEF_BUTTON_IMAGE		NULL
#define DEF_BUTTON_IMAGE		((char *) NULL)
#define DEF_BUTTON_INDICATOR		"1"
#define DEF_BUTTON_JUSTIFY		"center"
#define DEF_BUTTON_OFF_VALUE		"0"
#define DEF_BUTTON_ON_VALUE		"1"
#define DEF_BUTTON_TRISTATE_VALUE	""
#define DEF_BUTTON_OVER_RELIEF		""
//#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
//#define DEF_BUTTON_PADX			"12"
//#define DEF_BUTTON_PADX_NOCM		"1"
//#else
#define DEF_BUTTON_PADX			"1"
//#endif
#define DEF_LABCHKRAD_PADX		"1"
//#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS
//#define DEF_BUTTON_PADY			"3"
//#define DEF_BUTTON_PADY_NOCM		"1"
//#else
#define DEF_BUTTON_PADY			"1"
//#endif
#define DEF_LABCHKRAD_PADY		"1"
#define DEF_BUTTON_RELIEF		"flat"
#define DEF_LABCHKRAD_RELIEF		"flat"
#define DEF_BUTTON_REPEAT_DELAY		"0"
#define DEF_BUTTON_REPEAT_INTERVAL	"0"
#define DEF_BUTTON_SELECT_COLOR		INDICATOR
#define DEF_BUTTON_SELECT_MONO		BLACK
#define DEF_BUTTON_SELECT_IMAGE		NULL
#define DEF_BUTTON_SELECT_IMAGE		((char *) NULL)
#define DEF_BUTTON_STATE		"normal"
#define DEF_LABEL_TAKE_FOCUS		"0"
#define DEF_BUTTON_TAKE_FOCUS		NULL
#define DEF_BUTTON_TAKE_FOCUS		((char *) NULL)
#define DEF_BUTTON_TEXT			""
#define DEF_BUTTON_TEXT_VARIABLE	""
#define DEF_BUTTON_UNDERLINE		"-1"
#define DEF_BUTTON_VALUE		""
#define DEF_BUTTON_WIDTH		"0"
#define DEF_BUTTON_WRAP_LENGTH		"0"
#define DEF_RADIOBUTTON_VARIABLE	"selectedButton"
#define DEF_CHECKBUTTON_VARIABLE	""

/*
 * Defaults for canvases:
 */

#define DEF_CANVAS_BG_COLOR		NORMAL_BG
#define DEF_CANVAS_BG_MONO		WHITE
#define DEF_CANVAS_BORDER_WIDTH		"0"
#define DEF_CANVAS_CLOSE_ENOUGH		"1"
#define DEF_CANVAS_CONFINE		"1"
#define DEF_CANVAS_CURSOR		""
#define DEF_CANVAS_HEIGHT		"7c"
#define DEF_CANVAS_HIGHLIGHT_BG		NORMAL_BG
#define DEF_CANVAS_HIGHLIGHT		NORMAL_FG
#define DEF_CANVAS_HIGHLIGHT		BLACK
#define DEF_CANVAS_HIGHLIGHT_WIDTH	"3"
#define DEF_CANVAS_INSERT_BG		BLACK
#define DEF_CANVAS_INSERT_BD_COLOR	"0"
#define DEF_CANVAS_INSERT_BD_MONO	"0"
#define DEF_CANVAS_INSERT_OFF_TIME	"300"
#define DEF_CANVAS_INSERT_ON_TIME	"600"
#define DEF_CANVAS_INSERT_WIDTH		"2"
#define DEF_CANVAS_RELIEF		"flat"
#define DEF_CANVAS_SCROLL_REGION	""
#define DEF_CANVAS_SELECT_COLOR		SELECT_BG
#define DEF_CANVAS_SELECT_MONO		BLACK
#define DEF_CANVAS_SELECT_BD_COLOR	"1"
#define DEF_CANVAS_SELECT_BD_MONO	"0"
#define DEF_CANVAS_SELECT_FG_COLOR	SELECT_FG
#define DEF_CANVAS_SELECT_FG_MONO	WHITE
#define DEF_CANVAS_TAKE_FOCUS		NULL
#define DEF_CANVAS_TAKE_FOCUS		((char *) NULL)
#define DEF_CANVAS_WIDTH		"10c"
#define DEF_CANVAS_X_SCROLL_CMD		""
#define DEF_CANVAS_X_SCROLL_INCREMENT	"0"
#define DEF_CANVAS_Y_SCROLL_CMD		""
#define DEF_CANVAS_Y_SCROLL_INCREMENT	"0"

/*
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175

176
177


178
179

180
181
182
183
184
185
186



187
188
189
190

191
192
193
194
195
196
197
198

199
200

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252

253
254
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277
278
279
280





281
282

283
284
285


286
287

288
289
290


291
292
293

294
295
296


297
298


299
300
301
302
303
304
305


306
307
308


309
310
311


312
313
314

315
316
317

318
319
320
321


322





323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338







339
340

341
342
343
344
345
346

347
348
349
350

351
352

353
354
355
356
357


358
359
360
361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376

377
378
379

380
381
382
383


384
385
386
387
388
389
390
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180

181
182

183
184
185

186
187
188
189
190



191
192
193

194
195
196
197
198
199
200
201
202
203
204

205
206

207
208
209
210
211
212
213
214
215

216

217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280





281
282
283
284
285
286

287
288


289
290
291

292
293


294
295
296
297

298
299


300
301
302

303
304
305
306
307
308
309


310
311
312


313
314



315
316
317
318

319
320
321

322
323
324


325
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341







342
343
344
345
346
347
348
349

350
351
352
353
354
355

356
357
358
359

360
361

362
363
364
365


366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388
389

390
391
392


393
394
395
396
397
398
399
400
401







-
+








-
+

-
+
+

-
+




-
-
-
+
+
+
-



+







-
+

-
+








-

-







-
+















-
+









-
+






-
+


-
+













-
+






-
-
-
-
-
+
+
+
+
+

-
+

-
-
+
+

-
+

-
-
+
+


-
+

-
-
+
+

-
+
+





-
-
+
+

-
-
+
+
-
-
-
+
+


-
+


-
+


-
-
+
+

+
+
+
+
+

-
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+





-
+



-
+

-
+



-
-
+
+





+













-
+


-
+


-
-
+
+







 */

#define MAC_OSX_FOCUS_WIDTH		3
#define MAC_OSX_ENTRY_BORDER		2
#define MAC_OSX_ENTRY_RELIEF		TK_RELIEF_SUNKEN
#define MAC_OSX_ENTRY_SELECT_RELIEF	TK_RELIEF_FLAT

#define DEF_ENTRY_BG_COLOR		TEXT_BG
#define DEF_ENTRY_BG_COLOR		NORMAL_BG
#define DEF_ENTRY_BG_MONO		WHITE
#define DEF_ENTRY_BORDER_WIDTH		"2"
#define DEF_ENTRY_CURSOR		"xterm"
#define DEF_ENTRY_DISABLED_BG_COLOR	NORMAL_BG
#define DEF_ENTRY_DISABLED_BG_MONO	WHITE
#define DEF_ENTRY_DISABLED_FG		DISABLED
#define DEF_ENTRY_EXPORT_SELECTION	"1"
#define DEF_ENTRY_FONT			"TkTextFont"
#define DEF_ENTRY_FG			NORMAL_FG
#define DEF_ENTRY_FG			BLACK
#define DEF_ENTRY_HIGHLIGHT_BG		NORMAL_BG
#define DEF_ENTRY_HIGHLIGHT		NORMAL_FG
#define DEF_ENTRY_HIGHLIGHT		BLACK
/* #define DEF_ENTRY_HIGHLIGHT_WIDTH	"3" */
#define DEF_ENTRY_HIGHLIGHT_WIDTH	"3"
#define DEF_ENTRY_INSERT_BG		NORMAL_FG
#define DEF_ENTRY_INSERT_BG		BLACK
#define DEF_ENTRY_INSERT_BD_COLOR	"0"
#define DEF_ENTRY_INSERT_BD_MONO	"0"
#define DEF_ENTRY_INSERT_OFF_TIME	"300"
#define DEF_ENTRY_INSERT_ON_TIME	"600"
#define DEF_ENTRY_INSERT_WIDTH		"1"
#define DEF_ENTRY_JUSTIFY		"left"
#define DEF_ENTRY_PLACEHOLDER		""
/* #define DEF_ENTRY_INSERT_WIDTH		"2" */
#define DEF_ENTRY_INSERT_WIDTH		"1"
#define DEF_ENTRY_JUSTIFY		"left"
#define DEF_ENTRY_PLACEHOLDERFG		"systemPlaceholderTextColor"
#define DEF_ENTRY_READONLY_BG_COLOR	NORMAL_BG
#define DEF_ENTRY_READONLY_BG_MONO	WHITE
#define DEF_ENTRY_RELIEF		"sunken"
/* #define DEF_ENTRY_RELIEF		"solid" */
#define DEF_ENTRY_SCROLL_COMMAND	""
#define DEF_ENTRY_SELECT_COLOR		SELECT_BG
#define DEF_ENTRY_SELECT_MONO		BLACK
#define DEF_ENTRY_SELECT_BD_COLOR	"1"
#define DEF_ENTRY_SELECT_BD_MONO	"0"
#define DEF_ENTRY_SELECT_FG_COLOR	SELECT_FG
#define DEF_ENTRY_SELECT_FG_MONO	WHITE
#define DEF_ENTRY_SHOW			NULL
#define DEF_ENTRY_SHOW			((char *) NULL)
#define DEF_ENTRY_STATE			"normal"
#define DEF_ENTRY_TAKE_FOCUS		NULL
#define DEF_ENTRY_TAKE_FOCUS		((char *) NULL)
#define DEF_ENTRY_TEXT_VARIABLE		""
#define DEF_ENTRY_WIDTH			"20"

/*
 * Defaults for frames:
 */

#define DEF_FRAME_BG_COLOR		NORMAL_BG
#define DEF_FRAME_BG_IMAGE		NULL
#define DEF_FRAME_BG_MONO		WHITE
#define DEF_FRAME_BG_TILE		"0"
#define DEF_FRAME_BORDER_WIDTH		"0"
#define DEF_FRAME_CLASS			"Frame"
#define DEF_FRAME_COLORMAP		""
#define DEF_FRAME_CONTAINER		"0"
#define DEF_FRAME_CURSOR		""
#define DEF_FRAME_HEIGHT		"0"
#define DEF_FRAME_HIGHLIGHT_BG		NORMAL_BG
#define DEF_FRAME_HIGHLIGHT		NORMAL_FG
#define DEF_FRAME_HIGHLIGHT		BLACK
#define DEF_FRAME_HIGHLIGHT_WIDTH	"0"
#define DEF_FRAME_PADX			"0"
#define DEF_FRAME_PADY			"0"
#define DEF_FRAME_RELIEF		"flat"
#define DEF_FRAME_TAKE_FOCUS		"0"
#define DEF_FRAME_VISUAL		""
#define DEF_FRAME_WIDTH			"0"

/*
 * Defaults for labelframes:
 */

#define DEF_LABELFRAME_BORDER_WIDTH	"2"
#define DEF_LABELFRAME_CLASS		"Labelframe"
#define DEF_LABELFRAME_RELIEF		"groove"
#define DEF_LABELFRAME_FG		NORMAL_FG
#define DEF_LABELFRAME_FG		"systemButtonText"
#define DEF_LABELFRAME_FONT		"TkDefaultFont"
#define DEF_LABELFRAME_TEXT		""
#define DEF_LABELFRAME_LABELANCHOR	"nw"

/*
 * Defaults for listboxes:
 */

#define DEF_LISTBOX_ACTIVE_STYLE	"dotbox"
#define DEF_LISTBOX_BG_COLOR		TEXT_BG
#define DEF_LISTBOX_BG_COLOR		WHITE
#define DEF_LISTBOX_BG_MONO		WHITE
#define DEF_LISTBOX_BORDER_WIDTH	"1"
#define DEF_LISTBOX_CURSOR		""
#define DEF_LISTBOX_DISABLED_FG		DISABLED
#define DEF_LISTBOX_EXPORT_SELECTION	"1"
#define DEF_LISTBOX_FONT		"TkTextFont"
#define DEF_LISTBOX_FG			NORMAL_FG
#define DEF_LISTBOX_FG			BLACK
#define DEF_LISTBOX_HEIGHT		"10"
#define DEF_LISTBOX_HIGHLIGHT_BG	NORMAL_BG
#define DEF_LISTBOX_HIGHLIGHT		NORMAL_FG
#define DEF_LISTBOX_HIGHLIGHT		BLACK
#define DEF_LISTBOX_HIGHLIGHT_WIDTH	"0"
#define DEF_LISTBOX_JUSTIFY		"left"
#define DEF_LISTBOX_RELIEF		"solid"
#define DEF_LISTBOX_SCROLL_COMMAND	""
#define DEF_LISTBOX_LIST_VARIABLE	""
#define DEF_LISTBOX_SELECT_COLOR	SELECT_BG
#define DEF_LISTBOX_SELECT_MONO		BLACK
#define DEF_LISTBOX_SELECT_BD		"0"
#define DEF_LISTBOX_SELECT_FG_COLOR	SELECT_FG
#define DEF_LISTBOX_SELECT_FG_MONO	WHITE
#define DEF_LISTBOX_SELECT_MODE		"browse"
#define DEF_LISTBOX_SET_GRID		"0"
#define DEF_LISTBOX_STATE		"normal"
#define DEF_LISTBOX_TAKE_FOCUS		NULL
#define DEF_LISTBOX_TAKE_FOCUS		((char *) NULL)
#define DEF_LISTBOX_WIDTH		"20"

/*
 * Defaults for individual entries of menus:
 */

#define DEF_MENU_ENTRY_ACTIVE_BG	NULL
#define DEF_MENU_ENTRY_ACTIVE_FG	NULL
#define DEF_MENU_ENTRY_ACCELERATOR	NULL
#define DEF_MENU_ENTRY_BG		NULL
#define DEF_MENU_ENTRY_BITMAP		NULL
#define DEF_MENU_ENTRY_ACTIVE_BG	((char *) NULL)
#define DEF_MENU_ENTRY_ACTIVE_FG	((char *) NULL)
#define DEF_MENU_ENTRY_ACCELERATOR	((char *) NULL)
#define DEF_MENU_ENTRY_BG		((char *) NULL)
#define DEF_MENU_ENTRY_BITMAP		None
#define DEF_MENU_ENTRY_COLUMN_BREAK	"0"
#define DEF_MENU_ENTRY_COMMAND		NULL
#define DEF_MENU_ENTRY_COMMAND		((char *) NULL)
#define DEF_MENU_ENTRY_COMPOUND		"none"
#define DEF_MENU_ENTRY_FG		NULL
#define DEF_MENU_ENTRY_FONT		NULL
#define DEF_MENU_ENTRY_FG		((char *) NULL)
#define DEF_MENU_ENTRY_FONT		((char *) NULL)
#define DEF_MENU_ENTRY_HIDE_MARGIN	"0"
#define DEF_MENU_ENTRY_IMAGE		NULL
#define DEF_MENU_ENTRY_IMAGE		((char *) NULL)
#define DEF_MENU_ENTRY_INDICATOR	"1"
#define DEF_MENU_ENTRY_LABEL		NULL
#define DEF_MENU_ENTRY_MENU		NULL
#define DEF_MENU_ENTRY_LABEL		((char *) NULL)
#define DEF_MENU_ENTRY_MENU		((char *) NULL)
#define DEF_MENU_ENTRY_OFF_VALUE	"0"
#define DEF_MENU_ENTRY_ON_VALUE		"1"
#define DEF_MENU_ENTRY_SELECT_IMAGE	NULL
#define DEF_MENU_ENTRY_SELECT_IMAGE	((char *) NULL)
#define DEF_MENU_ENTRY_STATE		"normal"
#define DEF_MENU_ENTRY_VALUE		NULL
#define DEF_MENU_ENTRY_CHECK_VARIABLE	NULL
#define DEF_MENU_ENTRY_VALUE		((char *) NULL)
#define DEF_MENU_ENTRY_CHECK_VARIABLE	((char *) NULL)
#define DEF_MENU_ENTRY_RADIO_VARIABLE	"selectedButton"
#define DEF_MENU_ENTRY_SELECT		NULL
#define DEF_MENU_ENTRY_SELECT		((char *) NULL)
#define DEF_MENU_ENTRY_UNDERLINE	"-1"

/*
 * Defaults for menus overall:
 */

#define DEF_MENU_ACTIVE_BG_COLOR	IGNORED
#define DEF_MENU_ACTIVE_BG_MONO		IGNORED
#define DEF_MENU_ACTIVE_BG_COLOR	"systemMenuActive"
#define DEF_MENU_ACTIVE_BG_MONO		BLACK
#define DEF_MENU_ACTIVE_BORDER_WIDTH	"0"
#define DEF_MENU_ACTIVE_FG_COLOR	IGNORED
#define DEF_MENU_ACTIVE_FG_MONO		IGNORED
#define DEF_MENU_ACTIVE_FG_COLOR	"systemMenuActiveText"
#define DEF_MENU_ACTIVE_FG_MONO		WHITE
#define DEF_MENU_ACTIVE_RELIEF		"flat"
#define DEF_MENU_BG_COLOR		"#000001" /* Detects custom bg. */
#define DEF_MENU_BG_MONO		IGNORED
#define DEF_MENU_BG_COLOR		"systemMenu"
#define DEF_MENU_BG_MONO		WHITE
#define DEF_MENU_BORDER_WIDTH		"0"
#define DEF_MENU_CURSOR			"arrow"
#define DEF_MENU_DISABLED_FG_COLOR	IGNORED
#define DEF_MENU_DISABLED_FG_COLOR	"systemMenuDisabled"
#define DEF_MENU_DISABLED_FG_MONO	""
#define DEF_MENU_FONT			"menu" /* special: see tkMacOSXMenu.c */
#define DEF_MENU_FG			"#010000"  /* Detects custom fg. */
#define DEF_MENU_FG			"systemMenuText"
#define DEF_MENU_POST_COMMAND		""
#define DEF_MENU_RELIEF			"flat"
#define DEF_MENU_SELECT_COLOR		IGNORED
#define DEF_MENU_SELECT_MONO		IGNORED
#define DEF_MENU_SELECT_COLOR		"systemMenuActive"
#define DEF_MENU_SELECT_MONO		BLACK
#define DEF_MENU_TAKE_FOCUS		"0"

/*
 * FIXME: Turn the default back to 1 when we make tearoff menus work again.
 */

#define DEF_MENU_TEAROFF		"0"
#define DEF_MENU_TEAROFF_CMD		NULL
#define DEF_MENU_TEAROFF_CMD		((char *) NULL)
#define DEF_MENU_TITLE			""
#define DEF_MENU_TYPE			"normal"

/*
 * Defaults for menubuttons:
 */

#define DEF_MENUBUTTON_ANCHOR		"w"
#define DEF_MENUBUTTON_ACTIVE_BG_COLOR	NORMAL_BG /*ignored*/
#define DEF_MENUBUTTON_ACTIVE_BG_MONO	NORMAL_BG /*ignored*/
#define DEF_MENUBUTTON_ACTIVE_FG_COLOR	"systemTextColor"
#define DEF_MENUBUTTON_ACTIVE_FG_MONO	"systemTextColor"
#define DEF_MENUBUTTON_BG_COLOR		NORMAL_BG /*ignored*/
#define DEF_MENUBUTTON_BG_MONO		NORMAL_BG /*ignored*/
#define DEF_MENUBUTTON_ANCHOR		"center"
#define DEF_MENUBUTTON_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_MENUBUTTON_ACTIVE_BG_MONO	BLACK
#define DEF_MENUBUTTON_ACTIVE_FG_COLOR	ACTIVE_FG
#define DEF_MENUBUTTON_ACTIVE_FG_MONO	WHITE
#define DEF_MENUBUTTON_BG_COLOR		NORMAL_BG
#define DEF_MENUBUTTON_BG_MONO		WHITE
#define DEF_MENUBUTTON_BITMAP		""
#define DEF_MENUBUTTON_BORDER_WIDTH	"0"
#define DEF_MENUBUTTON_BORDER_WIDTH	"2"
#define DEF_MENUBUTTON_CURSOR		""
#define DEF_MENUBUTTON_DIRECTION	"below"
#define DEF_MENUBUTTON_DISABLED_FG_COLOR DISABLED
#define DEF_MENUBUTTON_DISABLED_FG_MONO	""
#define DEF_MENUBUTTON_FONT		"TkDefaultFont"
#define DEF_MENUBUTTON_FG		NORMAL_FG
#define DEF_MENUBUTTON_FG		BLACK
#define DEF_MENUBUTTON_HEIGHT		"0"
#define DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR DEF_MENUBUTTON_BG_COLOR
#define DEF_MENUBUTTON_HIGHLIGHT_BG_MONO  DEF_MENUBUTTON_BG_MONO
#define DEF_MENUBUTTON_HIGHLIGHT	NORMAL_FG
#define DEF_MENUBUTTON_HIGHLIGHT	BLACK
#define DEF_MENUBUTTON_HIGHLIGHT_WIDTH	"0"
#define DEF_MENUBUTTON_IMAGE		NULL
#define DEF_MENUBUTTON_IMAGE		((char *) NULL)
#define DEF_MENUBUTTON_INDICATOR	"1"
#define DEF_MENUBUTTON_JUSTIFY		"left"
#define DEF_MENUBUTTON_MENU		""
#define DEF_MENUBUTTON_PADX		"0"
#define DEF_MENUBUTTON_PADY		"0"
#define DEF_MENUBUTTON_PADX		"4"
#define DEF_MENUBUTTON_PADY		"3"
#define DEF_MENUBUTTON_RELIEF		"flat"
#define DEF_MENUBUTTON_STATE		"normal"
#define DEF_MENUBUTTON_TAKE_FOCUS	"0"
#define DEF_MENUBUTTON_TEXT		""
#define DEF_MENUBUTTON_TEXT_VARIABLE	""
#define DEF_MENUBUTTON_UNDERLINE	"-1"
#define DEF_MENUBUTTON_WIDTH		"0"
#define DEF_MENUBUTTON_WRAP_LENGTH	"0"

/*
 * Defaults for messages:
 */

#define DEF_MESSAGE_ANCHOR		"center"
#define DEF_MESSAGE_ASPECT		"150"
#define DEF_MESSAGE_BG_COLOR		NORMAL_BG
#define DEF_MESSAGE_BG_MONO		WHITE
#define DEF_MESSAGE_BORDER_WIDTH	"1"
#define DEF_MESSAGE_CURSOR		""
#define DEF_MESSAGE_FG			NORMAL_FG
#define DEF_MESSAGE_FG			BLACK
#define DEF_MESSAGE_FONT		"TkDefaultFont"
#define DEF_MESSAGE_HIGHLIGHT_BG	NORMAL_BG
#define DEF_MESSAGE_HIGHLIGHT		NORMAL_FG
#define DEF_MESSAGE_HIGHLIGHT		BLACK
#define DEF_MESSAGE_HIGHLIGHT_WIDTH	"0"
#define DEF_MESSAGE_JUSTIFY		"left"
#define DEF_MESSAGE_PADX		NULL
#define DEF_MESSAGE_PADY		NULL
#define DEF_MESSAGE_PADX		"-1"
#define DEF_MESSAGE_PADY		"-1"
#define DEF_MESSAGE_RELIEF		"flat"
#define DEF_MESSAGE_TAKE_FOCUS		"0"
#define DEF_MESSAGE_TEXT		""
#define DEF_MESSAGE_TEXT_VARIABLE	""
#define DEF_MESSAGE_WIDTH		"0"
/*
 * Defaults for panedwindows
427
428
429
430
431
432
433
434

435
436
437
438
439
440

441
442

443
444
445

446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480

481
482
483
484
485
486
487

488
489
490
491
492
493
494
495
496
497

498
499
500
501
502

503
504
505
506
507

508
509

510
511
512
513
514
515
516
438
439
440
441
442
443
444

445
446
447
448
449
450

451
452

453
454
455

456
457
458
459
460
461
462
463

464
465
466
467
468
469
470



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507

508
509
510
511
512

513
514
515
516
517

518
519

520
521
522
523
524
525
526
527







-
+





-
+

-
+


-
+







-
+






-
-
-
+
+
+

















-
+






-
+









-
+




-
+




-
+

-
+







 * Defaults for scales:
 */

#define DEF_SCALE_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_SCALE_ACTIVE_BG_MONO	BLACK
#define DEF_SCALE_BG_COLOR		NORMAL_BG
#define DEF_SCALE_BG_MONO		WHITE
#define DEF_SCALE_BIG_INCREMENT		"0.0"
#define DEF_SCALE_BIG_INCREMENT		"0"
#define DEF_SCALE_BORDER_WIDTH		"1"
#define DEF_SCALE_COMMAND		""
#define DEF_SCALE_CURSOR		""
#define DEF_SCALE_DIGITS		"0"
#define DEF_SCALE_FONT			"TkDefaultFont"
#define DEF_SCALE_FG_COLOR		NORMAL_FG
#define DEF_SCALE_FG_COLOR		BLACK
#define DEF_SCALE_FG_MONO		BLACK
#define DEF_SCALE_FROM			"0.0"
#define DEF_SCALE_FROM			"0"
#define DEF_SCALE_HIGHLIGHT_BG_COLOR	DEF_SCALE_BG_COLOR
#define DEF_SCALE_HIGHLIGHT_BG_MONO	DEF_SCALE_BG_MONO
#define DEF_SCALE_HIGHLIGHT		NORMAL_FG
#define DEF_SCALE_HIGHLIGHT		BLACK
#define DEF_SCALE_HIGHLIGHT_WIDTH	"0"
#define DEF_SCALE_LABEL			""
#define DEF_SCALE_LENGTH		"100"
#define DEF_SCALE_ORIENT		"vertical"
#define DEF_SCALE_RELIEF		"flat"
#define DEF_SCALE_REPEAT_DELAY	"300"
#define DEF_SCALE_REPEAT_INTERVAL	"100"
#define DEF_SCALE_RESOLUTION		"1.0"
#define DEF_SCALE_RESOLUTION		"1"
#define DEF_SCALE_TROUGH_COLOR		TROUGH
#define DEF_SCALE_TROUGH_MONO		WHITE
#define DEF_SCALE_SHOW_VALUE		"1"
#define DEF_SCALE_SLIDER_LENGTH		"30"
#define DEF_SCALE_SLIDER_RELIEF		"raised"
#define DEF_SCALE_STATE			"normal"
#define DEF_SCALE_TAKE_FOCUS		NULL
#define DEF_SCALE_TICK_INTERVAL		"0.0"
#define DEF_SCALE_TO			"100.0"
#define DEF_SCALE_TAKE_FOCUS		((char *) NULL)
#define DEF_SCALE_TICK_INTERVAL		"0"
#define DEF_SCALE_TO			"100"
#define DEF_SCALE_VARIABLE		""
#define DEF_SCALE_WIDTH			"15"

/*
 * Defaults for scrollbars:
 */

#define DEF_SCROLLBAR_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_SCROLLBAR_ACTIVE_BG_MONO	BLACK
#define DEF_SCROLLBAR_ACTIVE_RELIEF	"raised"
#define DEF_SCROLLBAR_BG_COLOR		NORMAL_BG
#define DEF_SCROLLBAR_BG_MONO		WHITE
#define DEF_SCROLLBAR_BORDER_WIDTH	"0"
#define DEF_SCROLLBAR_COMMAND		""
#define DEF_SCROLLBAR_CURSOR		""
#define DEF_SCROLLBAR_EL_BORDER_WIDTH	"-1"
#define DEF_SCROLLBAR_HIGHLIGHT_BG	NORMAL_BG
#define DEF_SCROLLBAR_HIGHLIGHT		NORMAL_FG
#define DEF_SCROLLBAR_HIGHLIGHT		BLACK
#define DEF_SCROLLBAR_HIGHLIGHT_WIDTH	"0"
#define DEF_SCROLLBAR_JUMP		"0"
#define DEF_SCROLLBAR_ORIENT		"vertical"
#define DEF_SCROLLBAR_RELIEF		"flat"
#define DEF_SCROLLBAR_REPEAT_DELAY	"300"
#define DEF_SCROLLBAR_REPEAT_INTERVAL	"100"
#define DEF_SCROLLBAR_TAKE_FOCUS	NULL
#define DEF_SCROLLBAR_TAKE_FOCUS	((char *) NULL)
#define DEF_SCROLLBAR_TROUGH_COLOR	TROUGH
#define DEF_SCROLLBAR_TROUGH_MONO	WHITE
#define DEF_SCROLLBAR_WIDTH		"15"

/*
 * Defaults for texts:
 */

#define DEF_TEXT_AUTO_SEPARATORS	"1"
#define DEF_TEXT_BG_COLOR		TEXT_BG
#define DEF_TEXT_BG_COLOR		NORMAL_BG
#define DEF_TEXT_BG_MONO		WHITE
#define DEF_TEXT_BLOCK_CURSOR		"0"
#define DEF_TEXT_BORDER_WIDTH		"0"
#define DEF_TEXT_CURSOR			"xterm"
#define DEF_TEXT_FG			NORMAL_FG
#define DEF_TEXT_FG			BLACK
#define DEF_TEXT_EXPORT_SELECTION	"1"
#define DEF_TEXT_FONT			"TkFixedFont"
#define DEF_TEXT_HEIGHT			"24"
#define DEF_TEXT_HIGHLIGHT_BG		NORMAL_BG
#define DEF_TEXT_HIGHLIGHT		NORMAL_FG
#define DEF_TEXT_HIGHLIGHT		BLACK
#define DEF_TEXT_HIGHLIGHT_WIDTH	"3"
#define DEF_TEXT_INSERT_BG		NORMAL_FG
#define DEF_TEXT_INSERT_BG		BLACK
#define DEF_TEXT_INSERT_BD_COLOR	"0"
#define DEF_TEXT_INSERT_BD_MONO		"0"
#define DEF_TEXT_INSERT_OFF_TIME	"300"
#define DEF_TEXT_INSERT_ON_TIME		"600"
#define DEF_TEXT_INSERT_UNFOCUSSED	"none"
#define DEF_TEXT_INSERT_WIDTH		"1"
#define DEF_TEXT_MAX_UNDO		"0"
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553
554
555
556
557
558








559
560
561
562
563
564
565







-
+












-
-
-
-
-
-
-
-







#define DEF_TEXT_SET_GRID		"0"
#define DEF_TEXT_SPACING1		"0"
#define DEF_TEXT_SPACING2		"0"
#define DEF_TEXT_SPACING3		"0"
#define DEF_TEXT_STATE			"normal"
#define DEF_TEXT_TABS			""
#define DEF_TEXT_TABSTYLE		"tabular"
#define DEF_TEXT_TAKE_FOCUS		NULL
#define DEF_TEXT_TAKE_FOCUS		((char *) NULL)
#define DEF_TEXT_UNDO			"0"
#define DEF_TEXT_WIDTH			"80"
#define DEF_TEXT_WRAP			"char"
#define DEF_TEXT_XSCROLL_COMMAND	""
#define DEF_TEXT_YSCROLL_COMMAND	""

/*
 * Defaults for canvas text:
 */

#define DEF_CANVTEXT_FONT		"TkDefaultFont"

/*
 * Defaults for canvas items
 * (arcs, bitmaps, lines, polygons, rectangles, and ovals):
 */

#define DEF_CANVBMAP_FG			NORMAL_FG
#define DEF_CANVITEM_OUTLINE		NORMAL_FG

/*
 * Defaults for toplevels (most of the defaults for frames also apply
 * to toplevels):
 */

#define DEF_TOPLEVEL_CLASS		"Toplevel"
#define DEF_TOPLEVEL_MENU		""

Changes to macosx/tkMacOSXDialog.c.

1
2
3
4
5
6
7
8
9




10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59

60
61

62
63

64
65

66
67

68
69

70
71
72
73
74

75
76

77
78
79
80
81
82

83
84
85
86


87
88
89
90
91
92
93
94
95
96
97
98



99
100
101
102
103



104
105
106
107
108



109
110
111
112
113



114
115
116

117
118
119
120
121


122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
1
2
3
4
5




6
7
8
9

10
11
12
13
14
15
16

17
18
19
20
21
22
23


24
25
26
27


























28


29

30


31


32


33


34


35





36


37

38
39



40
41



42
43
44
45
46
47
48
49
50
51
52



53
54
55
56
57



58
59
60
61
62



63
64
65
66
67



68
69
70
71
72

73
74
75
76


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99





-
-
-
-
+
+
+
+
-







-







-
-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-

-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
-
-
+
-
-
+
-


-
-
-
+

-
-
-
+
+









-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
+



-
-
+
+













-
+







/*
 * tkMacOSXDialog.c --
 *
 *	Contains the Mac implementation of the common dialog boxes.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2017 Christian Gollwitzer
 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2017 Christian Gollwitzer.
 * Copyright © 2022 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkFileFilter.h"
#include "tkMacOSXConstants.h"

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
#define modalOK     NSOKButton
#define modalCancel NSCancelButton
#else
#define modalOK     NSModalResponseOK
#define modalCancel NSModalResponseCancel
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
#define modalOther  -1 // indicates that the -command option was used.
#endif
#define modalOther  -1
#define modalError  -2

static void setAllowedFileTypes(
    NSSavePanel *panel,
    NSMutableArray *extensions)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
/* UTType exists in the SDK */
    if (@available(macOS 11.0, *)) {
	NSMutableArray<UTType *> *allowedTypes = [NSMutableArray array];
	for (NSString *ext in extensions) {
	    UTType *uttype = [UTType typeWithFilenameExtension: ext];
	    [allowedTypes addObject:uttype];
	}
	[panel setAllowedContentTypes:allowedTypes];
    } else {
# if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
/* setAllowedFileTypes is not deprecated */
	[panel setAllowedFileTypes:extensions];
#endif
    }
#else
    [panel setAllowedFileTypes:extensions];
#endif
}

/*
 * Vars for filtering in "open file" and "save file" dialogs.
/*Vars for filtering in "open file" and "save file" dialogs.*/
 */

typedef struct {
    bool doFileTypes;			/* Show the accessory view which
    bool doFileTypes; // show the accessory view which displays the filter menu
					 * displays the filter menu */
    bool preselectFilter;		/* A filter was selected by the
    bool preselectFilter; // a filter was selected by the typevariable
					 * typevariable. */
    bool userHasSelectedFilter;		/* The user has changed the filter in
    bool userHasSelectedFilter; // The user has changed the filter in the accessory view
					 * the accessory view. */
    NSMutableArray *fileTypeNames;	/* Array of names, e.g. "Text
    NSMutableArray *fileTypeNames; // array of names, e.g. "Text document"
					 * document". */
    NSMutableArray *fileTypeExtensions;	/* Array of allowed extensions per
    NSMutableArray *fileTypeExtensions; // array of allowed extensions per name, e.g. "txt", "doc"
					 * name, e.g. "txt", "doc". */
    NSMutableArray *fileTypeLabels;	/* Displayed string, e.g. "Text
    NSMutableArray *fileTypeLabels; // displayed string, e.g. "Text document (.txt, .doc)"
					 * document (.txt, .doc)". */
    NSMutableArray *fileTypeAllowsAll;	/* Boolean if the all pattern (*.*) is
					 * included. */
    NSMutableArray *allowedExtensions;	/* Set of all allowed extensions. */
    bool allowedExtensionsAllowAll;	/* Set of all allowed extensions
    NSMutableArray *allAllowedExtensions; // set of all allowed extensions
					 * includes *.* */
    NSUInteger fileTypeIndex;		/* Index of currently selected
    NSInteger fileTypeIndex; // index of currently selected filter
					 * filter. */
} filepanelFilterInfo;

/*
 * Only one of these is needed for the application, so they can be static.
 */
filepanelFilterInfo filterInfo;

static filepanelFilterInfo filterInfo;
static NSOpenPanel *openpanel;
static NSSavePanel *savepanel;
NSOpenPanel *openpanel;
NSSavePanel *savepanel;

static const char *const colorOptionStrings[] = {
    "-initialcolor", "-parent", "-title", NULL
};
enum colorOptions {
    COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
};

static const char *const openOptionStrings[] = {
    "-command", "-defaultextension", "-filetypes", "-initialdir",
    "-initialfile", "-message", "-multiple", "-parent", "-title",
    "-typevariable", NULL
    "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
    "-message", "-multiple", "-parent", "-title", "-typevariable",
    "-command", NULL
};
enum openOptions {
    OPEN_COMMAND, OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR,
    OPEN_INITFILE, OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE,
    OPEN_TYPEVARIABLE
    OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE,
    OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE,
    OPEN_TYPEVARIABLE, OPEN_COMMAND,
};
static const char *const saveOptionStrings[] = {
    "-command", "-confirmoverwrite", "-defaultextension", "-filetypes",
    "-initialdir", "-initialfile", "-message", "-parent", "-title",
    "-typevariable", NULL
    "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
    "-message", "-parent", "-title", "-typevariable", "-command",
    "-confirmoverwrite", NULL
};
enum saveOptions {
    SAVE_COMMAND, SAVE_CONFIRMOW, SAVE_DEFAULT, SAVE_FILETYPES,
    SAVE_INITDIR, SAVE_INITFILE, SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE,
    SAVE_TYPEVARIABLE
    SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE,
    SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE, SAVE_TYPEVARIABLE, SAVE_COMMAND,
    SAVE_CONFIRMOW
};
static const char *const chooseOptionStrings[] = {
    "-command", "-initialdir", "-message", "-mustexist", "-parent", "-title",
    "-initialdir", "-message", "-mustexist", "-parent", "-title", "-command",
    NULL
};
enum chooseOptions {
    CHOOSE_COMMAND, CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST,
    CHOOSE_PARENT, CHOOSE_TITLE
    CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, CHOOSE_PARENT,
    CHOOSE_TITLE, CHOOSE_COMMAND,
};
typedef struct {
    Tcl_Interp *interp;
    Tcl_Obj *cmdObj;
    int multiple;
} FilePanelCallbackInfo;

static const char *const alertOptionStrings[] = {
    "-default", "-detail", "-icon", "-message", "-parent", "-title",
    "-type", "-command", NULL
};
enum alertOptions {
    ALERT_DEFAULT, ALERT_DETAIL, ALERT_ICON, ALERT_MESSAGE, ALERT_PARENT,
    ALERT_TITLE, ALERT_TYPE, ALERT_COMMAND
    ALERT_TITLE, ALERT_TYPE, ALERT_COMMAND,
};
typedef struct {
    Tcl_Interp *interp;
    Tcl_Obj *cmdObj;
    int typeIndex;
} AlertCallbackInfo;
static const char *const alertTypeStrings[] = {
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121







-
+







static const char *const alertIconStrings[] = {
    "error", "info", "question", "warning", NULL
};
enum alertIconOptions {
    ICON_ERROR, ICON_INFO, ICON_QUESTION, ICON_WARNING
};
static const char *const alertButtonStrings[] = {
    "abort", "retry", "ignore", "ok", "cancel", "no", "yes", NULL
    "abort", "retry", "ignore", "ok", "cancel", "yes", "no", NULL
};

static const NSString *const alertButtonNames[][3] = {
    [TYPE_ABORTRETRYIGNORE] =   {@"Abort", @"Retry", @"Ignore"},
    [TYPE_OK] =			{@"OK"},
    [TYPE_OKCANCEL] =		{@"OK", @"Cancel"},
    [TYPE_RETRYCANCEL] =	{@"Retry", @"Cancel"},
180
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196
197
198
199
200
201
202


203
204
205
206
207
208
209
210


211
212
213
214

215
216
217
218
219
220
221
222
223
224

225


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251

252
253

254
255
256
257
258
259
260

261
262
263

264
265
266
267
268

269
270
271
272

273
274
275
276
277
278
279
280
281
282

283
284

285
286
287









288
289

290
291

292
293
294
295
296

297
298
299
300
301

302
303
304
305

306
307
308
309
310
311
312
313
314
315
316
317
318



319
320



321
322
323


324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339

340
341
342

343
344
345
346
347


348
349
350
351
352
353

354
355
356
357


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440

441
442
443
444
445
446
447
137
138
139
140
141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157


158
159
160
161






162
163




164










165

166
167
168
169
170


















171


172
173

174
175

176
177
178
179
180
181
182

183
184
185

186
187
188
189


190
191
192
193

194
195
196
197
198
199
200
201
202
203

204
205
206
207



208
209
210
211
212
213
214
215
216
217

218
219

220
221
222
223
224

225
226
227
228


229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249


250
251
252
253


254
255













256



257


258
259
260
261
262


263
264






265




266
267
268



269
270
271

















































272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294
295
296
297

298
299
300
301
302
303
304
305







-
-
+
+












-
-
+
+


-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+

-
+

-
+






-
+


-
+



-
-
+



-
+









-
+


+
-
-
-
+
+
+
+
+
+
+
+
+

-
+

-
+




-
+



-
-
+



-
+













+
+
+
-
-
+
+
+

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-

+



-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
+
+

-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
+





-
+








static const short alertButtonIndexAndTypeToNativeButtonIndex[][7] = {
			    /*  abort retry ignore ok   cancel yes   no */
    [TYPE_ABORTRETRYIGNORE] =   {1,    2,    3,    0,    0,    0,    0},
    [TYPE_OK] =			{0,    0,    0,    1,    0,    0,    0},
    [TYPE_OKCANCEL] =		{0,    0,    0,    1,    2,    0,    0},
    [TYPE_RETRYCANCEL] =	{0,    1,    0,    0,    2,    0,    0},
    [TYPE_YESNO] =		{0,    0,    0,    0,    0,    2,    1},
    [TYPE_YESNOCANCEL] =	{0,    0,    0,    0,    3,    2,    1},
    [TYPE_YESNO] =		{0,    0,    0,    0,    0,    1,    2},
    [TYPE_YESNOCANCEL] =	{0,    0,    0,    0,    3,    1,    2},
};

/*
 * Need also the inverse mapping, from NSAlertFirstButtonReturn etc to the
 * descriptive button text string index.
 */

static const short alertNativeButtonIndexAndTypeToButtonIndex[][3] = {
    [TYPE_ABORTRETRYIGNORE] =   {0, 1, 2},
    [TYPE_OK] =			{3, 0, 0},
    [TYPE_OKCANCEL] =		{3, 4, 0},
    [TYPE_RETRYCANCEL] =	{1, 4, 0},
    [TYPE_YESNO] =		{6, 5, 0},
    [TYPE_YESNOCANCEL] =	{6, 5, 4},
    [TYPE_YESNO] =		{5, 6, 0},
    [TYPE_YESNOCANCEL] =	{5, 6, 4},
};

/*
 * Construct a file URL from directory and filename. Either may be nil. If both
 * are nil, returns nil.
 */

static NSURL *

#pragma mark TKApplication(TKDialog)
getFileURL(
    NSString *directory,
    NSString *filename)
{

    NSURL *url = nil;
    if (directory) {
	url = [NSURL fileURLWithPath:directory isDirectory:YES];
    }
    if (filename) {
	url = [NSURL URLWithString:filename relativeToURL:url];
    }
    return url;
}

@interface NSColorPanel(TKDialog)
#pragma mark TKApplication(TKDialog)
- (void) _setUseModalAppearance: (BOOL) flag;
@end

@implementation TKApplication(TKDialog)

- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
	(void)sender;
	(void)url;
    return YES;
}

- (void)panel:(id)sender didChangeToDirectoryURL:(NSURL *)url {
    (void)sender;
    (void)url;
}

- (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError {
    (void)sender;
    (void)url;
    *outError = nil;
    return YES;
}

- (void) tkFilePanelDidEnd: (NSSavePanel *) panel
		returnCode: (NSModalResponse) returnCode
	       contextInfo: (const void *) contextInfo
	returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
{
    const FilePanelCallbackInfo *callbackInfo = (const FilePanelCallbackInfo *)contextInfo;
    FilePanelCallbackInfo *callbackInfo = contextInfo;

    if (returnCode == modalOK) {
    if (returnCode == NSFileHandlingPanelOKButton) {
	Tcl_Obj *resultObj;

	if (callbackInfo->multiple) {
	    resultObj = Tcl_NewListObj(0, NULL);
	    for (NSURL *url in [(NSOpenPanel*)panel URLs]) {
		Tcl_ListObjAppendElement(callbackInfo->interp, resultObj,
			Tcl_NewStringObj([[url path] UTF8String], TCL_INDEX_NONE));
			Tcl_NewStringObj([[url path] UTF8String], -1));
	    }
	} else {
	    resultObj = Tcl_NewStringObj([[[panel URL]path] UTF8String], TCL_INDEX_NONE);
	    resultObj = Tcl_NewStringObj([[[panel URL]path] UTF8String], -1);
	}
	if (callbackInfo->cmdObj) {
	    Tcl_Obj **objv, **tmpv;
	    Tcl_Size objc;
	    int result = Tcl_ListObjGetElements(callbackInfo->interp,
	    int objc, result = Tcl_ListObjGetElements(callbackInfo->interp,
		    callbackInfo->cmdObj, &objc, &objv);

	    if (result == TCL_OK && objc) {
		tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
		tmpv[objc] = resultObj;
		TkBackgroundEvalObjv(callbackInfo->interp, objc + 1, tmpv,
			TCL_EVAL_GLOBAL);
		ckfree(tmpv);
	    }
	} else {
	    Tcl_SetObjResult(callbackInfo->interp, resultObj);
	}
    } else if (returnCode == modalCancel) {
    } else if (returnCode == NSFileHandlingPanelCancelButton) {
	Tcl_ResetResult(callbackInfo->interp);
    }
    if (panel == [NSApp modalWindow]) {
    [NSApp stopModalWithCode:returnCode];
}

	[NSApp stopModalWithCode:returnCode];
    }
    if (callbackInfo->cmdObj) {
	Tcl_DecrRefCount(callbackInfo->cmdObj);
	ckfree(callbackInfo);
    }
}


- (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
	contextInfo: (const void *) contextInfo
	contextInfo: (void *) contextInfo
{
    AlertCallbackInfo *callbackInfo = (AlertCallbackInfo *)contextInfo;
    AlertCallbackInfo *callbackInfo = contextInfo;

    if (returnCode >= NSAlertFirstButtonReturn) {
	Tcl_Obj *resultObj = Tcl_NewStringObj(alertButtonStrings[
		alertNativeButtonIndexAndTypeToButtonIndex[callbackInfo->
		typeIndex][returnCode - NSAlertFirstButtonReturn]], TCL_INDEX_NONE);
		typeIndex][returnCode - NSAlertFirstButtonReturn]], -1);

	if (callbackInfo->cmdObj) {
	    Tcl_Obj **objv, **tmpv;
	    Tcl_Size objc;
	    int result = Tcl_ListObjGetElements(callbackInfo->interp,
	    int objc, result = Tcl_ListObjGetElements(callbackInfo->interp,
		    callbackInfo->cmdObj, &objc, &objv);

	    if (result == TCL_OK && objc) {
		tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
		tmpv[objc] = resultObj;
		TkBackgroundEvalObjv(callbackInfo->interp, objc + 1, tmpv,
			TCL_EVAL_GLOBAL);
		ckfree(tmpv);
	    }
	} else {
	    Tcl_SetObjResult(callbackInfo->interp, resultObj);
	}
    }
    if ([alert window] == [NSApp modalWindow]) {
	[NSApp stopModalWithCode:returnCode];
    }
    if (callbackInfo->cmdObj) {
	Tcl_DecrRefCount(callbackInfo->cmdObj);
	ckfree(callbackInfo);
}

    }
}

- (void)selectFormat:(id)sender  {
    NSPopUpButton *button      = (NSPopUpButton *)sender;
    filterInfo.fileTypeIndex   = (NSUInteger)[button indexOfSelectedItem];
    NSPopUpButton *button                 = (NSPopUpButton *)sender;
    filterInfo.fileTypeIndex      = [button indexOfSelectedItem];
    if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
	[openpanel setAllowsOtherFileTypes:YES];

	/*
	 * setAllowsOtherFileTypes might have no effect; it's inherited from
	 * the NSSavePanel, where it has the effect that it does not append an
	 * extension. Setting the allowed file types to nil allows selecting
	 * any file.
	 */

	setAllowedFileTypes(openpanel, nil);
    } else {
	NSMutableArray *allowedtypes =
    NSMutableArray *allowedtypes = filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex];
		[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
	setAllowedFileTypes(openpanel, allowedtypes);
	[openpanel setAllowsOtherFileTypes:NO];
    [openpanel setAllowedFileTypes:allowedtypes];
    }

    filterInfo.userHasSelectedFilter = true;

}

- (void)saveFormat:(id)sender  {
    NSPopUpButton *button     = (NSPopUpButton *)sender;
    filterInfo.fileTypeIndex  = (NSUInteger)[button indexOfSelectedItem];
    NSPopUpButton *button                 = (NSPopUpButton *)sender;
    filterInfo.fileTypeIndex      = [button indexOfSelectedItem];

    if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
	[savepanel setAllowsOtherFileTypes:YES];
	setAllowedFileTypes(savepanel, nil);
    } else {
	NSMutableArray *allowedtypes =
    NSMutableArray *allowedtypes = filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex];
		[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
	setAllowedFileTypes(savepanel, allowedtypes);
	[savepanel setAllowsOtherFileTypes:NO];
    }
    [savepanel setAllowedFileTypes:allowedtypes];
}

    filterInfo.userHasSelectedFilter = true;
}

@end

#pragma mark -

static NSInteger showOpenSavePanel(
    NSSavePanel *panel,
    NSWindow *parent,
    Tcl_Interp *interp,
    Tcl_Obj *cmdObj,
    int multiple)
{
    NSInteger modalReturnCode;
    int OSVersion = [NSApp macOSVersion];
    const FilePanelCallbackInfo callbackInfo = {interp, cmdObj, multiple};

    /*
     * Use a sheet if -parent is specified (unless there is already a sheet).
     */

    if (parent && ![parent attachedSheet]) {
	if (OSVersion < 101500) {
	    [panel beginSheetModalForWindow:parent
			  completionHandler:^(NSModalResponse returnCode) {
		    [NSApp tkFilePanelDidEnd:panel
				  returnCode:returnCode
				 contextInfo:&callbackInfo ];
		}];
	    modalReturnCode = [NSApp runModalForWindow:panel];
	} else if (OSVersion < 110000) {
	    [panel beginSheetModalForWindow:parent
			  completionHandler:^(NSModalResponse returnCode) {
		    [NSApp tkFilePanelDidEnd:panel
				  returnCode:returnCode
				 contextInfo:&callbackInfo ];
		}];
	    modalReturnCode = [panel runModal];
	} else {
	    [parent beginSheet: panel completionHandler:nil];
	    modalReturnCode = [panel runModal];
	    [NSApp tkFilePanelDidEnd:panel
			  returnCode:modalReturnCode
			 contextInfo:&callbackInfo ];
	    [parent endSheet:panel];
	}
    } else {
	modalReturnCode = [panel runModal];
	[NSApp tkFilePanelDidEnd:panel
		      returnCode:modalReturnCode
		     contextInfo:&callbackInfo ];
    }
    return cmdObj ? modalOther : modalReturnCode;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_ChooseColorObjCmd --
 *
 *	This procedure implements the color dialog box for the Mac platform.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ChooseColorObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int result = TCL_ERROR;
    Tk_Window parent, tkwin = (Tk_Window)clientData;
    Tk_Window parent, tkwin = clientData;
    const char *title = NULL;
    int i;
    NSColor *color = nil, *initialColor = nil;
    NSColorPanel *colorPanel;
    NSInteger returnCode, numberOfComponents = 0;

    for (i = 1; i < objc; i += 2) {
486
487
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
344
345
346
347
348
349
350


351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368







-
-
+









-
+







    colorPanel = [NSColorPanel sharedColorPanel];
    [colorPanel orderOut:NSApp];
    [colorPanel setContinuous:NO];
    [colorPanel setBecomesKeyOnlyIfNeeded:NO];
    [colorPanel setShowsAlpha: NO];
    [colorPanel _setUseModalAppearance:YES];
    if (title) {
	NSString *s = [[TKNSString alloc] initWithTclUtfBytes:title length:TCL_INDEX_NONE];

	NSString *s = [[NSString alloc] initWithUTF8String:title];
	[colorPanel setTitle:s];
	[s release];
    }
    if (initialColor) {
	[colorPanel setColor:initialColor];
    }
    returnCode = [NSApp runModalForWindow:colorPanel];
    if (returnCode == modalOK) {
	color = [[colorPanel color] colorUsingColorSpace:
		[NSColorSpace deviceRGBColorSpace]];
		[NSColorSpace genericRGBColorSpace]];
	numberOfComponents = [color numberOfComponents];
    }
    if (color && numberOfComponents >= 3 && numberOfComponents <= 4) {
	CGFloat components[4];
	char colorstr[8];

	[color getComponents:components];
519
520
521
522
523
524
525
526
527
528


529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566

567
568
569
570


571
572
573
574
575
576
577
578
579
580
581

582
583
584
585



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615




616
617
618
619
620
621
622

623
624
625

626
627
628
629

630
631
632
633

634
635

636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

691
692
693
694
695

696
697
698

699
700


701
702
703
704
705
706
707
376
377
378
379
380
381
382



383
384






385


386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403
404



405

406
407
408
409


410
411
412


413
414

415
416
417

418
419
420
421
422

423
424



425
426
427
428
429
430
431
432
433








434
435
436
437

438

439
440
441
442
443
444




445
446
447
448


449
450
451


452



453

454


455


456

457


458



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473


















474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492

493
494
495
496
497

498
499
500

501

502
503
504
505
506
507
508
509
510
511







-
-
-
+
+
-
-
-
-
-
-
+
-
-







-












-
-
-
+
-




-
-
+


-
-
+
+
-



-





-
+

-
-
-
+
+
+






-
-
-
-
-
-
-
-




-

-
+





-
-
-
-
+
+
+
+
-
-



-
-
+
-
-
-
+
-

-
-
+
-
-

-
+
-
-
+
-
-
-
+














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
+




-
+


-
+
-

+
+







    }
    result = TCL_OK;

end:
    return result;
}

/*
 * Dissect the -filetype nested lists and store the information in the
 * filterInfo structure.
/* dissect the -filetype nested lists and store the information
 * in the filterInfo structure */
 */

static int
parseFileFilters(
    Tcl_Interp *interp,
    Tcl_Obj *fileTypesPtr,
int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVariablePtr) {
    Tcl_Obj *typeVariablePtr)
{

    if (!fileTypesPtr) {
	filterInfo.doFileTypes = false;
	return TCL_OK;
    }

    FileFilterList fl;

    TkInitFileFilters(&fl);
    if (TkGetFileFilters(interp, &fl, fileTypesPtr, 0) != TCL_OK) {
	TkFreeFileFilters(&fl);
	return TCL_ERROR;
    }

    filterInfo.doFileTypes = (fl.filters != NULL);

    filterInfo.fileTypeIndex = 0;
    filterInfo.fileTypeExtensions = [NSMutableArray array];
    filterInfo.fileTypeNames = [NSMutableArray array];
    filterInfo.fileTypeLabels = [NSMutableArray array];
    filterInfo.fileTypeAllowsAll = [NSMutableArray array];

    filterInfo.allowedExtensions = [NSMutableArray array];
    filterInfo.allAllowedExtensions = [NSMutableArray array];
    filterInfo.allowedExtensionsAllowAll = NO;

    if (filterInfo.doFileTypes) {
	for (FileFilter *filterPtr = fl.filters; filterPtr;
		filterPtr = filterPtr->next) {
	    NSString *name = [[TKNSString alloc] initWithTclUtfBytes: filterPtr->name length:TCL_INDEX_NONE];

	    NSString * name = [[NSString alloc] initWithUTF8String: filterPtr -> name];
	    [filterInfo.fileTypeNames addObject:name];
	    [name release];
	    NSMutableArray *clauseextensions = [NSMutableArray array];
	    NSMutableArray *displayextensions = [NSMutableArray array];
	    NSMutableArray * clauseextensions = [NSMutableArray array];
	    NSMutableArray * displayextensions = [NSMutableArray array];
	    bool allowsAll = NO;

	    for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr;
		    clausePtr = clausePtr->next) {

		for (GlobPattern *globPtr = clausePtr->patterns; globPtr;
			globPtr = globPtr->next) {
		    const char *str = globPtr->pattern;
		    while (*str && (*str == '*' || *str == '.')) {
		    	str++;
		    }
		     }
		    if (*str) {
			NSString *extension = [[TKNSString alloc] initWithTclUtfBytes:str length:TCL_INDEX_NONE];
			if (![filterInfo.allowedExtensions containsObject:extension]) {
			    [filterInfo.allowedExtensions addObject:extension];
			NSString *extension = [[NSString alloc] initWithUTF8String:str];
			if (![filterInfo.allAllowedExtensions containsObject:extension]) {
			    [filterInfo.allAllowedExtensions addObject:extension];
			}

			[clauseextensions addObject:extension];
			[displayextensions addObject:[@"." stringByAppendingString:extension]];

			[extension release];
		    } else {
			/*
			 * It is the all pattern (*, .* or *.*)
			 */

			allowsAll = YES;
			filterInfo.allowedExtensionsAllowAll = YES;
			[displayextensions addObject:@"*"];
		    }
		}
	    }
	    [filterInfo.fileTypeExtensions addObject:clauseextensions];
	    [filterInfo.fileTypeAllowsAll addObject:[NSNumber numberWithBool:allowsAll]];

	    NSMutableString *label = [[NSMutableString alloc] initWithString:name];
	    NSMutableString * label = [[NSMutableString alloc] initWithString:name];
	    [label appendString:@" ("];
	    [label appendString:[displayextensions componentsJoinedByString:@", "]];
	    [label appendString:@")"];
	    [filterInfo.fileTypeLabels addObject:label];
	    [label release];
	}

	/*
	 * Check if the typevariable exists and matches one of the names.

	}

	/* Check if the typevariable exists and matches one of the names */
	 */

	filterInfo.preselectFilter = false;
	filterInfo.userHasSelectedFilter = false;
	if (typeVariablePtr) {
	    /*
	     * Extract the variable content as a NSString.
	    /* extract the variable content as a NSString */
	     */

	    Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp,
	    Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp, typeVariablePtr, NULL, TCL_GLOBAL_ONLY);
		    typeVariablePtr, NULL, TCL_GLOBAL_ONLY);

	    /*
	     * Check that the typevariable exists.
	    /* check that the typevariable exists */
	     */

	    if (selectedFileTypeObj != NULL) {
		const char *selectedFileType =
		const char *selectedFileType = Tcl_GetString(selectedFileTypeObj);
			Tcl_GetString(selectedFileTypeObj);
		NSString *selectedFileTypeStr =
		NSString *selectedFileTypeStr = [[NSString alloc] initWithUTF8String:selectedFileType];
			[[TKNSString alloc] initWithTclUtfBytes:selectedFileType length:TCL_INDEX_NONE];
		NSUInteger index =
			[filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];
		NSUInteger index = [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];

		if (index != NSNotFound) {
		    filterInfo.fileTypeIndex = index;
		    filterInfo.preselectFilter = true;
		}
	    }
	}

    }

    TkFreeFileFilters(&fl);
    return TCL_OK;
}

static bool
filterCompatible(
    NSString *extension,
	NSUInteger filterIndex)
{
    NSMutableArray *allowedExtensions =
	    [filterInfo.fileTypeExtensions objectAtIndex: filterIndex];

    /*
     * If this contains the all pattern, accept any extension.
     */

    if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterIndex] boolValue]) {
	return true;
    }

    return [allowedExtensions containsObject: extension];
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOpenFileObjCmd --
 *
 *	This procedure implements the "open file" dialog box for the Mac
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See user documentation.
 *----------------------------------------------------------------------
 */

int
Tk_GetOpenFileObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    char *str;
    int i, result = TCL_ERROR, haveParentOption = 0;
    int index, multiple = 0;
    int index, len, multiple = 0;
    Tcl_Size len;
    Tcl_Obj *cmdObj = NULL, *typeVariablePtr = NULL, *fileTypesPtr = NULL;
    FilePanelCallbackInfo callbackInfoStruct;
    FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
    NSString *directory = nil, *filename = nil;
    NSString *message = nil, *title = nil;
    NSWindow *parent;
    openpanel =  [NSOpenPanel openPanel];
    NSInteger modalReturnCode = modalError;
    BOOL parentIsKey = NO;

721
722
723
724
725
726
727
728

729
730
731
732
733
734
735

736

737
738
739
740
741

742

743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760

761

762
763
764
765
766
767
768
769
770
771
772
773
774
775
776


777
778
779
780
781






782
783
784
785
786
787





788
789
790
791
792
793
794
795
796
797

798
799
800
801
802
803

804

805
806
807
808
809
810
811
812

813
814
815


816
817
818

819
820
821
822
823
824
825



826
827
828

829
830
831

832
833
834
835

836
837
838

839
840

841
842
843
844


845
846
847
848

849
850
851
852

853

854
855
856
857
858

















859
860
861
862
863
864










865
866






867


868
869
870





871
872
873











874
875
876
877
878

879
880


881
882

883
884
885

886
887
888

889
890
891
892
893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908
909
910
911
912

913
914

915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934




935
936
937
938
939

940
941

942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962

963
964
965
966
967

968
969
970
971

972
973


974
975
976
977

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996

997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009

1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022
1023

1024

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036

1037

1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072






1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089


1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102

1103
1104

1105
1106
1107
1108
1109
1110
1111
1112


1113
1114
1115
1116
1117



1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135



1136












1137
1138
1139
1140









1141
1142
1143


1144
1145
1146
1147
1148
1149
1150
1151



















1152
1153
1154
1155
1156




1157
1158

1159
1160

1161
1162
1163
1164
1165
1166
1167

1168
1169
1170

1171
1172
1173

1174
1175



1176
1177

1178
1179

1180
1181
1182
1183
1184
1185
1186
525
526
527
528
529
530
531

532
533
534
535
536
537
538

539
540
541
542
543
544


545

546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562


563

564
565
566
567
568
569
570
571
572
573


574



575
576





577
578
579
580
581
582






583
584
585
586
587

588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603

604






605

606
607
608
609
610
611
612

613
614
615
616

617



618
619
620



621



622

623
624

625

626

627
628

629




630
631
632
633


634


635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661






662
663
664
665
666
667
668
669
670
671


672
673
674
675
676
677
678
679
680



681
682
683
684
685



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702


703
704
705

706

707

708



709












710












711


712




















713
714
715
716





717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739

740
741
742
743
744

745
746
747
748

749

750
751
752
753
754
755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774

775
776
777

778
779
780
781
782
783
784
785
786
787

788
789
790
791
792
793
794

795
796
797
798
799
800


801

802
803
804
805
806
807
808
809
810
811
812


813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832










833







834
835
836
837
838
839

840
841
842
843
844
845
846
847
848
849
850
851
852



853
854


855
856
857
858
859
860

861


862

863

864
865
866
867
868
869
870



871
872
873




874
875
876


877

878

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908




909
910
911
912
913
914
915
916
917



918
919








920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938





939
940
941
942


943


944
945
946
947
948
949
950

951

952

953

954

955


956
957
958
959

960

961
962
963
964
965
966
967
968
969







-
+






-
+

+



-
-
+
-
+
















-
-
+
-
+









-
-

-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-








-
+






+
-
+
-
-
-
-
-
-

-
+



+
+

-

+


-

-
-
-
+
+
+
-
-
-
+
-
-
-
+
-


-
+
-

-
+

-
+
-
-
-
-
+
+


-
-
+
-
-


+

+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+

+
+
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+





+
-
-
+
+

-
+
-

-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+


+














-





-
+




-
+



-
+
-

+
+



-
+


















-
+


-
+









-
+






-
+





-
-
+
-
+










-
-
+
-
+


















-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-













-
-
-
+
+
-
-






-
+
-
-

-
+
-

+





-
-
-
+
+

-
-
-
-
+
+
+
-
-

-

-
+







+





+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
+






-
+
-

-
+
-

-
+
-
-
+
+
+

-
+
-

+







	    break;
	case OPEN_FILETYPES:
	    fileTypesPtr = objv[i + 1];
	    break;
	case OPEN_INITDIR:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    if (len) {
		directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		directory = [[[NSString alloc] initWithUTF8String:str]
			autorelease];
	    }
	    break;
	case OPEN_INITFILE:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    if (len) {
		filename = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		filename = [[[NSString alloc] initWithUTF8String:str]
			autorelease];
	       	[openpanel setNameFieldStringValue:filename];
	    }
	    break;
	case OPEN_MESSAGE:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    message = [[TKNSString alloc] initWithTclUtfBytes:
	    message = [[NSString alloc] initWithUTF8String:
		    str length:len];
		    Tcl_GetString(objv[i + 1])];
	    break;
	case OPEN_MULTIPLE:
	    if (Tcl_GetBooleanFromObj(interp, objv[i + 1],
		    &multiple) != TCL_OK) {
		goto end;
	    }
	    break;
	case OPEN_PARENT:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    tkwin = Tk_NameToWindow(interp, str, tkwin);
	    if (!tkwin) {
		goto end;
	    }
	    haveParentOption = 1;
	    break;
	case OPEN_TITLE:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    title = [[TKNSString alloc] initWithTclUtfBytes:
	    title = [[NSString alloc] initWithUTF8String:
		    str length:len];
		    Tcl_GetString(objv[i + 1])];
	    break;
	case OPEN_TYPEVARIABLE:
	    typeVariablePtr = objv[i + 1];
	    break;
	case OPEN_COMMAND:
	    cmdObj = objv[i+1];
	    break;
	}
    }
    if (title) {
	[openpanel setTitle:title];

	/*
	 * From OSX 10.11, the title string is silently ignored in the open
	 * panel.  Prepend the title to the message in this case.
    /* From OSX 10.11, the title string is silently ignored.
     * Prepend the title to the message
	 */

	if ([NSApp macOSVersion] > 101000) {
	    if (message) {
		NSString *fullmessage =
     * NOTE should be conditional on OSX version, but
     * -mmacosx-version-min does not revert this behaviour*/
    if (title) {
	[openpanel setTitle:title];
	if (message) {
	    NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
		    [[NSString alloc] initWithFormat:@"%@\n%@", title, message];
		[message release];
		[title release];
		message = fullmessage;
	    } else {
		message = title;
	    [message release];
	    [title release];
	    message = fullmessage;
	} else {
	    message = title;
	    }
	}
    }

    if (message) {
	[openpanel setMessage:message];
	[message release];
    }

    [openpanel setAllowsMultipleSelection:multiple != 0];
    [openpanel setAllowsMultipleSelection:multiple];

    if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) {
	goto end;
    }

    if (filterInfo.doFileTypes) {
	NSView  *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)];
	NSTextField *label = [[NSTextField alloc]
	NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
		initWithFrame:NSMakeRect(0, 0, 60, 22)];
	NSPopUpButton *popupButton = [[NSPopUpButton alloc]
		initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO];
	NSView *accessoryView = [[NSView alloc]
		initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];

	[label setEditable:NO];
	[label setStringValue:@"Filter:"];
	[label setStringValue:@"Enable:"];
	[label setBordered:NO];
	[label setBezeled:NO];
	[label setDrawsBackground:NO];

	NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 140, 22.0) pullsDown:NO];
	[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
	[popupButton setTarget:NSApp];
	[popupButton setAction:@selector(selectFormat:)];

	[accessoryView addSubview:label];
	[accessoryView addSubview:popupButton];
	if (filterInfo.preselectFilter) {

	    /*
	     * A specific filter was selected from the typevariable. Select it
	     * and open the accessory view.
	if (filterInfo.preselectFilter) {
	    /* A specific filter was selected from the typevariable. Select it and
	     * open the accessory view */
	     */

	    [popupButton selectItemAtIndex:(NSInteger)filterInfo.fileTypeIndex];
	    [popupButton selectItemAtIndex:filterInfo.fileTypeIndex];

	    /*
	     * On OSX > 10.11, the options are not visible by default. Ergo
	    /* on OSX > 10.11, the optons are not visible by default. Ergo allow all file types
	     * allow all file types
	    [openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]];
	    */

	    [openpanel setAllowedFileTypes:filterInfo.allAllowedExtensions];
	    setAllowedFileTypes(openpanel, filterInfo.allowedExtensions);
	} else {
	    setAllowedFileTypes(openpanel, filterInfo.allowedExtensions);
	    [openpanel setAllowedFileTypes:filterInfo.allAllowedExtensions];
	}
	if (filterInfo.allowedExtensionsAllowAll) {

	    [openpanel setAllowsOtherFileTypes:YES];
	} else {
	    [openpanel setAllowsOtherFileTypes:NO];
	}
	[openpanel setAllowsOtherFileTypes:NO];

	[openpanel setAccessoryView:accessoryView];
    } else {
	/*
	 * No filters are given. Allow picking all files.
	/* No filters are given. Allow picking all files */
	 */

	[openpanel setAllowsOtherFileTypes:YES];
    }

    if (cmdObj) {
	callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
	if (Tcl_IsShared(cmdObj)) {
	    cmdObj = Tcl_DuplicateObj(cmdObj);
	}
	Tcl_IncrRefCount(cmdObj);
    }

    callbackInfo->cmdObj = cmdObj;
    callbackInfo->interp = interp;
    callbackInfo->multiple = multiple;
    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
	    parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	[openpanel beginSheetForDirectory:directory
	       file:filename
	       types:openFileTypes
	       modalForWindow:parent
	       modalDelegate:NSApp
	       didEndSelector:
		   @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
	       contextInfo:callbackInfo];
#else
    if (directory || filename) {
	NSURL *fileURL = getFileURL(directory, filename);

	[openpanel setDirectoryURL:fileURL];
    }
    if (haveParentOption) {
	if (directory) {
	    [openpanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	}
	/*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
	if (filename) {
	[openpanel setNameFieldStringValue:filename];
	} else {
	    [openpanel setNameFieldStringValue:@""];
	}
	[openpanel beginSheetModalForWindow:parent
	parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
	parentIsKey = parent && [parent isKeyWindow];
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:openpanel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];
#endif
	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel];
    } else {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	modalReturnCode = [openpanel runModalForDirectory:directory
	parent = nil;
	parentIsKey = False;
    }
				 file:filename];
#else
	if (directory) {
	    [openpanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	}
    modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, multiple);
    if (cmdObj) {
	Tcl_DecrRefCount(cmdObj);
	/*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
	if (filename) {
	    [openpanel setNameFieldStringValue:filename];
	} else {
	    [openpanel setNameFieldStringValue:@""];
	}

	modalReturnCode = [openpanel runModal];
#endif
	[NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }

    if ((typeVariablePtr && (modalReturnCode == NSOKButton))
	    && filterInfo.doFileTypes) {
    if ((typeVariablePtr && (modalReturnCode == NSOKButton)) &&
	filterInfo.doFileTypes && filterInfo.userHasSelectedFilter) {
	/*
	 * The -typevariable must be set to the selected file type, if the
	 * The -typevariable must be set to the selected file type, if the dialog was not cancelled
	 * dialog was not cancelled.
	 */

	#if 0
	NSUInteger selectedFilterIndex = filterInfo.fileTypeIndex;
	NSString *selectedFilter = NULL;

	NSLog(@"result: %i modal: %li", result, (long)modalReturnCode);
	if (filterInfo.userHasSelectedFilter) {
	    selectedFilterIndex = filterInfo.fileTypeIndex;
	    selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
	} else {
	    /*
	     * Difficult case: the user has not touched the filter settings,
	     * but we must return something in the typevariable. First check if
	     * the preselected type is compatible with the selected file,
	     * otherwise choose the first compatible type from the list,
	     * finally fall back to the empty string.
	     */

	#endif
	    NSURL *selectedFile;
	    NSString *extension;
	    if (multiple) {
		/*
		 * Use the first file in the case of multiple selection.
		 * Anyway it is not overly useful here.
		 */
		selectedFile = [[openpanel URLs] objectAtIndex:0];
	    } else {
		selectedFile = [openpanel URL];
	    }

	NSString * selectedFilter = filterInfo.fileTypeNames[filterInfo.fileTypeIndex];
	    extension = [selectedFile pathExtension];

	Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
	    if (filterInfo.preselectFilter &&
		    filterCompatible(extension, filterInfo.fileTypeIndex)) {
		selectedFilterIndex = filterInfo.fileTypeIndex;  // The preselection from the typevariable
		selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
	    } else {
		NSUInteger j;

		for (j = 0; j < [filterInfo.fileTypeNames count]; j++) {
		    if (filterCompatible(extension, j)) {
			selectedFilterIndex = j;
			break;
		    }
		}
		if (j == selectedFilterIndex) {
		    selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
		} else {
		    selectedFilter = @"";
		}
	    }
	}
		Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
    }


	Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
		Tcl_NewStringObj([selectedFilter UTF8String], TCL_INDEX_NONE),
		TCL_GLOBAL_ONLY);
    }
 end:
  end:
    return result;
}


/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSaveFileObjCmd --
 *
 *	This procedure implements the "save file" dialog box for the Mac
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See user documentation.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetSaveFileObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    char *str;
    int i, result = TCL_ERROR, haveParentOption = 0;
    int confirmOverwrite = 1;
    int index;
    int index, len;
    Tcl_Size len;
    Tcl_Obj *cmdObj = NULL, *typeVariablePtr = NULL, *fileTypesPtr = NULL;
    FilePanelCallbackInfo callbackInfoStruct;
    FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
    NSString *directory = nil, *filename = nil, *defaultType = nil;
    NSString *message = nil, *title = nil;
    NSWindow *parent;
    savepanel = [NSSavePanel savePanel];
    savepanel =  [NSSavePanel savePanel];
    NSInteger modalReturnCode = modalError;
    BOOL parentIsKey = NO;

    for (i = 1; i < objc; i += 2) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], saveOptionStrings,
		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
	    goto end;
	}
	if (i + 1 == objc) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL);
	    goto end;
	}
	switch (index) {
	    case SAVE_DEFAULT:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		while (*str && (*str == '*' || *str == '.')) {
		    str++; len--;
		    str++;
		}
		if (*str) {
		    defaultType = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		    defaultType = [[[NSString alloc] initWithUTF8String:str]
			    autorelease];
		}
		break;
	    case SAVE_FILETYPES:
		fileTypesPtr = objv[i + 1];
		break;
	    case SAVE_INITDIR:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		if (len) {
		    directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		    directory = [[[NSString alloc] initWithUTF8String:str]
			    autorelease];
		}
		break;
	    case SAVE_INITFILE:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		if (len) {
		    filename = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		    filename = [[[NSString alloc] initWithUTF8String:str]
			    autorelease];
		    [savepanel setNameFieldStringValue:filename];
		}
		break;
	    case SAVE_MESSAGE:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		message = [[TKNSString alloc] initWithTclUtfBytes:
		message = [[NSString alloc] initWithUTF8String:
			str length:len];
			Tcl_GetString(objv[i + 1])];
		break;
	    case SAVE_PARENT:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		tkwin = Tk_NameToWindow(interp, str, tkwin);
		if (!tkwin) {
		    goto end;
		}
		haveParentOption = 1;
		break;
	    case SAVE_TITLE:
		str = Tcl_GetStringFromObj(objv[i + 1], &len);
		title = [[TKNSString alloc] initWithTclUtfBytes:
		title = [[NSString alloc] initWithUTF8String:
			str length:len];
			Tcl_GetString(objv[i + 1])];
		break;
	    case SAVE_TYPEVARIABLE:
		typeVariablePtr = objv[i + 1];
		break;
	    case SAVE_COMMAND:
		cmdObj = objv[i+1];
		break;
	    case SAVE_CONFIRMOW:
		if (Tcl_GetBooleanFromObj(interp, objv[i + 1],
			&confirmOverwrite) != TCL_OK) {
		    goto end;
		}
		break;
	}
    }

    if (title) {
	[savepanel setTitle:title];

	/*
	 * From OSX 10.11, the title string is silently ignored, if the save
	 * panel is a sheet.  Prepend the title to the message in this case.
	 * NOTE: should be conditional on OSX version, but -mmacosx-version-min
	 * does not revert this behaviour.
	 */

	if (haveParentOption) {
	    if (message) {
	if (message) {
		NSString *fullmessage =
		    [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
		[message release];
		[title release];
		message = fullmessage;
	    } else {
		message = title;
	    NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
	    [message release];
	    [title release];
	    message = fullmessage;
	} else {
	    message = title;
	    }
	}
    }

    if (message) {
	[savepanel setMessage:message];
	[message release];
    }

    if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) {
	goto end;
    }

    if (filterInfo.doFileTypes) {
	NSView *accessoryView = [[NSView alloc]
		initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
	NSTextField *label = [[NSTextField alloc]
	NSView  *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)];
	NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
		initWithFrame:NSMakeRect(0, 0, 60, 22)];

	[label setEditable:NO];
	[label setStringValue:NSLocalizedString(@"Format:", nil)];
	[label setBordered:NO];
	[label setBezeled:NO];
	[label setDrawsBackground:NO];

	NSPopUpButton *popupButton = [[NSPopUpButton alloc]
	NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 140, 22.0) pullsDown:NO];
		initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO];

	[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
	[popupButton selectItemAtIndex:(NSInteger)filterInfo.fileTypeIndex];
	[popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
	[popupButton setTarget:NSApp];
	[popupButton setAction:@selector(saveFormat:)];

	[accessoryView addSubview:label];
	[accessoryView addSubview:popupButton];

	[savepanel setAccessoryView:accessoryView];

	setAllowedFileTypes(savepanel,
	    [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]);
	[savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll];
	[savepanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]];
	[savepanel setAllowsOtherFileTypes:NO];
    } else if (defaultType) {
	/*
	 * If no filetypes are given, defaultextension is an alternative way to
	 * specify the attached extension. Just propose this extension, but
	 * don't display an accessory view.
	/* If no filetypes are given, defaultextension is an alternative way
	 * to specify the attached extension. Just propose this extension,
	 * but don't display an accessory view */
	 */

	NSMutableArray *AllowedFileTypes = [NSMutableArray array];

	[AllowedFileTypes addObject:defaultType];
	setAllowedFileTypes(savepanel, AllowedFileTypes);
	[savepanel setAllowedFileTypes:AllowedFileTypes];
	[savepanel setAllowsOtherFileTypes:YES];
    }

    [savepanel setCanSelectHiddenExtension:YES];
    [savepanel setExtensionHidden:NO];

    if (cmdObj) {
	callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
	if (Tcl_IsShared(cmdObj)) {
	    cmdObj = Tcl_DuplicateObj(cmdObj);
	}
	Tcl_IncrRefCount(cmdObj);
    }
    callbackInfo->cmdObj = cmdObj;
    callbackInfo->interp = interp;
    callbackInfo->multiple = 0;

    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
       parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	[savepanel beginSheetForDirectory:directory
	       file:filename
	       modalForWindow:parent
	       modalDelegate:NSApp
	       didEndSelector:
		   @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
	       contextInfo:callbackInfo];
#else
    if (directory) {
	[savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
    }

	if (directory) {
	    [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	}
	   /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
	if (filename) {
	    [savepanel setNameFieldStringValue:filename];
	} else {
	    [savepanel setNameFieldStringValue:@""];
	}
    /*
     * Check for file name and set to the empty string if nil. This prevents a crash
     * with an uncaught exception.
	[savepanel beginSheetModalForWindow:parent
	       completionHandler:^(NSInteger returnCode)
     */

    if (filename) {
	[savepanel setNameFieldStringValue:filename];
    } else {
	[savepanel setNameFieldStringValue:@""];
    }
    if (haveParentOption) {
	       { [NSApp tkFilePanelDidEnd:savepanel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];
#endif
	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel];
    } else {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	modalReturnCode = [savepanel runModalForDirectory:directory file:filename];
#else
	if (directory) {
	    [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	}
	 /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
	if (filename) {
	    [savepanel setNameFieldStringValue:filename];
	} else {
	    [savepanel setNameFieldStringValue:@""];
	}
	modalReturnCode = [savepanel runModal];
	parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
	parentIsKey = parent && [parent isKeyWindow];
    } else {
	parent = nil;
	parentIsKey = False;
	#if 0
	NSLog(@"modal: %li", modalReturnCode);
	#endif
#endif
    }
    modalReturnCode = showOpenSavePanel(savepanel, parent, interp, cmdObj, 0);
	[NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode
    if (cmdObj) {
	Tcl_DecrRefCount(cmdObj);
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }

    if (typeVariablePtr && (modalReturnCode == NSOKButton)
    if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && filterInfo.doFileTypes) {
	    && filterInfo.doFileTypes) {
	/*
	 * The -typevariable must be set to the selected file type, if the
	 * The -typevariable must be set to the selected file type, if the dialog was not cancelled
	 * dialog was not cancelled.
	 */

	#if 0
	NSString *selectedFilter =
	    [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex];
	NSLog(@"result: %i modal: %li", result, (long)modalReturnCode);
	#endif
	NSString * selectedFilter = filterInfo.fileTypeNames[filterInfo.fileTypeIndex];
	Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
		Tcl_NewStringObj([selectedFilter UTF8String], TCL_INDEX_NONE),
		Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
		TCL_GLOBAL_ONLY);
    }


  end:
    return result;
}

/*
 *----------------------------------------------------------------------
1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210

1211
1212
1213

1214
1215


1216
1217
1218
1219
1220
1221
1222
981
982
983
984
985
986
987

988
989
990
991
992

993
994
995

996

997
998
999
1000
1001
1002
1003
1004
1005
1006







-
+




-
+


-
+
-

+
+







 *	A modal dialog window is created.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ChooseDirectoryObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    char *str;
    int i, result = TCL_ERROR, haveParentOption = 0;
    int index, mustexist = 0;
    int index, len, mustexist = 0;
    Tcl_Size len;
    Tcl_Obj *cmdObj = NULL;
    FilePanelCallbackInfo callbackInfoStruct;
    FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
    NSString *directory = nil;
    NSString *message, *title;
    NSWindow *parent;
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    NSInteger modalReturnCode = modalError;
    BOOL parentIsKey = NO;

1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244

1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266

1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285

1286
1287



1288
1289
1290
1291
1292
1293
1294
1295
1296













1297
1298






1299
1300
1301



1302
1303
1304



1305


1306
1307
1308
1309
1310
1311
1312
1015
1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026


1027

1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046


1047

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067

1068


1069
1070
1071



1072
1073
1074



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087


1088
1089
1090
1091
1092
1093
1094


1095
1096
1097



1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
1108
1109







-
+




-
-
+
-
+


















-
-
+
-
+













+





-
+
-
-
+
+
+
-
-
-



-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+

-
-
+
+
+
-
-
-
+
+
+
-
+
+







	    Tcl_SetErrorCode(interp, "TK", "DIRDIALOG", "VALUE", NULL);
	    goto end;
	}
	switch (index) {
	case CHOOSE_INITDIR:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    if (len) {
		directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len]
		directory = [[[NSString alloc] initWithUTF8String:str]
			autorelease];
	    }
	    break;
	case CHOOSE_MESSAGE:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    message = [[TKNSString alloc] initWithTclUtfBytes:
	    message = [[NSString alloc] initWithUTF8String:
		    str length:len];
		    Tcl_GetString(objv[i + 1])];
	    [panel setMessage:message];
	    [message release];
	    break;
	case CHOOSE_MUSTEXIST:
	    if (Tcl_GetBooleanFromObj(interp, objv[i + 1],
		    &mustexist) != TCL_OK) {
		goto end;
	    }
	    break;
	case CHOOSE_PARENT:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    tkwin = Tk_NameToWindow(interp, str, tkwin);
	    if (!tkwin) {
		goto end;
	    }
	    haveParentOption = 1;
	    break;
	case CHOOSE_TITLE:
	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
	    title = [[TKNSString alloc] initWithTclUtfBytes:
	    title = [[NSString alloc] initWithUTF8String:
		    str length:len];
		    Tcl_GetString(objv[i + 1])];
	    [panel setTitle:title];
	    [title release];
	    break;
	case CHOOSE_COMMAND:
	    cmdObj = objv[i+1];
	    break;
	}
    }
    [panel setPrompt:@"Choose"];
    [panel setCanChooseFiles:NO];
    [panel setCanChooseDirectories:YES];
    [panel setCanCreateDirectories:!mustexist];
    if (cmdObj) {
	callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
	if (Tcl_IsShared(cmdObj)) {
	    cmdObj = Tcl_DuplicateObj(cmdObj);
	}
	Tcl_IncrRefCount(cmdObj);
    }

    callbackInfo->cmdObj = cmdObj;
    /*
     * Check for directory value, set to root if not specified; otherwise
    callbackInfo->interp = interp;
    callbackInfo->multiple = 0;
    /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/
     * crashes with exception because of nil string parameter.
     */

    if (!directory) {
	directory = @"/";
    }
    parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
    [panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
    if (haveParentOption) {
    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
      parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	[panel beginSheetForDirectory:directory
		file:nil
		modalForWindow:parent
		modalDelegate:NSApp
		didEndSelector: @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
		contextInfo:callbackInfo];
#else
	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	[panel beginSheetModalForWindow:parent
	parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
	parentIsKey = parent && [parent isKeyWindow];
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:panel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];
#endif
	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
    } else {
	parent = nil;
	parentIsKey = False;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	modalReturnCode = [panel runModalForDirectory:directory file:nil];
#else
    }
    modalReturnCode = showOpenSavePanel(panel, parent, interp, cmdObj, 0);
    if (cmdObj) {
	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	modalReturnCode = [panel runModal];
#endif
	Tcl_DecrRefCount(cmdObj);
	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }
  end:
    return result;
1327
1328
1329
1330
1331
1332
1333














































1334

1335
1336

1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355

1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
+


















-
+








-
+







 *
 *----------------------------------------------------------------------
 */

void
TkAboutDlg(void)
{
    NSImage *image;
    NSString *path = [NSApp tkFrameworkImagePath: @"Tk.tiff"];

    if (path) {
	image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
    } else {
	image = [NSApp applicationIconImage];
    }

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setDateFormat:@"Y"];

    NSString *year = [dateFormatter stringFromDate:[NSDate date]];

    [dateFormatter release];

    NSMutableParagraphStyle *style =
	    [[[NSParagraphStyle defaultParagraphStyle] mutableCopy]
	    autorelease];

    [style setAlignment:NSCenterTextAlignment];

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
	    @"Tcl & Tk", @"ApplicationName",
	    @"Tcl " TCL_VERSION " & Tk " TK_VERSION, @"ApplicationVersion",
	    @TK_PATCH_LEVEL, @"Version",
	    image, @"ApplicationIcon",
	    [NSString stringWithFormat:@"Copyright %1$C 1987-%2$@.", 0xA9,
	    year], @"Copyright",
	    [[[NSAttributedString alloc] initWithString:
	    [NSString stringWithFormat:
	    @"%1$C 1987-%2$@ Tcl Core Team." "\n\n"
		"%1$C 1989-%2$@ Contributors." "\n\n"
		"%1$C 2011-%2$@ Kevin Walzer/WordTech Communications LLC." "\n\n"
		"%1$C 2014-%2$@ Marc Culler." "\n\n"
		"%1$C 2002-%2$@ Daniel A. Steffen." "\n\n"
		"%1$C 2001-2009 Apple Inc." "\n\n"
		"%1$C 2001-2002 Jim Ingham & Ian Reid" "\n\n"
		"%1$C 1998-2000 Jim Ingham & Ray Johnson" "\n\n"
		"%1$C 1998-2000 Scriptics Inc." "\n\n"
		"%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year] attributes:
	    [NSDictionary dictionaryWithObject:style
	    forKey:NSParagraphStyleAttributeName]] autorelease], @"Credits",
	    nil];
    [NSApp orderFrontStandardAboutPanel:nil];
    [NSApp orderFrontStandardAboutPanelWithOptions:options];
}


/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXStandardAboutPanelObjCmd --
 *
 *	Implements the ::tk::mac::standardAboutPanel command.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	none
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXStandardAboutPanelObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Unused. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    if (objc > 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
    [NSApp orderFrontStandardAboutPanel:nil];
    [NSApp orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionary]];
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MessageBoxObjCmd --
1379
1380
1381
1382
1383
1384
1385
1386

1387
1388
1389
1390
1391

1392
1393
1394
1395
1396
1397

1398
1399
1400
1401
1402
1403
1404
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233

1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247







-
+




-
+





-
+







 *	none
 *
 *----------------------------------------------------------------------
 */

int
Tk_MessageBoxObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    char *str;
    int i, result = TCL_ERROR, haveParentOption = 0;
    int index, typeIndex, iconIndex, indexDefaultOption = 0;
    int defaultNativeButtonIndex = 1; /* 1, 2, 3: right to left */
    Tcl_Obj *cmdObj = NULL;
    AlertCallbackInfo callbackInfo;
    AlertCallbackInfo callbackInfoStruct, *callbackInfo = &callbackInfoStruct;
    NSString *message, *title;
    NSWindow *parent;
    NSArray *buttons;
    NSAlert *alert = [NSAlert new];
    NSInteger modalReturnCode = 1;
    BOOL parentIsKey = NO;

1422
1423
1424
1425
1426
1427
1428

1429

1430
1431
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443

1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460

1461

1462
1463
1464
1465
1466
1467
1468
1469
1470

1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506
1507
1508

1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

1521
1522

1523
1524
1525
1526
1527
1528
1529
1530
1531




1532
1533
1534

1535
1536
1537
1538
1539




1540
1541
1542
1543
1544
1545

1546
1547
1548

1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574

1575
1576
1577
1578
1579
1580
1581
1582
1583

1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594










1595
1596

1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612

1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1265
1266
1267
1268
1269
1270
1271
1272

1273


1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286

1287


1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302

1303


1304
1305
1306
1307
1308
1309

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325

1326

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366
1367




1368
1369
1370
1371
1372
1373

1374
1375




1376
1377
1378
1379

1380
1381
1382
1383

1384
1385
1386

1387
1388
1389
1390

1391



1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409

1410
1411
1412
1413
1414
1415
1416
1417
1418

1419



1420
1421
1422
1423




1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450

1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470







+
-
+
-
-






-
+





+
-
+
-
-














+
-
+
-
-






-
+















-
+
-











-
+








-
+











-
+


+





-
-
-
-
+
+
+
+


-
+

-
-
-
-
+
+
+
+
-




-
+


-
+



-
+
-
-
-


















-
+








-
+
-
-
-




-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+















-
+



-
+








-







	     * know the '-type' as well.
	     */

	    indexDefaultOption = i;
	    break;

	case ALERT_DETAIL:
	    message = [[NSString alloc] initWithUTF8String:
	    str = Tcl_GetString(objv[i + 1]);
		    Tcl_GetString(objv[i + 1])];
	    message = [[TKNSString alloc] initWithTclUtfBytes:
		    str length:TCL_INDEX_NONE];
	    [alert setInformativeText:message];
	    [message release];
	    break;

	case ALERT_ICON:
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i + 1], alertIconStrings,
		    sizeof(char *), "-icon value", TCL_EXACT, &iconIndex) != TCL_OK) {
		    sizeof(char *), "value", TCL_EXACT, &iconIndex) != TCL_OK) {
		goto end;
	    }
	    break;

	case ALERT_MESSAGE:
	    message = [[NSString alloc] initWithUTF8String:
	    str = Tcl_GetString(objv[i + 1]);
		    Tcl_GetString(objv[i + 1])];
	    message = [[TKNSString alloc] initWithTclUtfBytes:
		    str length:TCL_INDEX_NONE];
	    [alert setMessageText:message];
	    [message release];
	    break;

	case ALERT_PARENT:
	    str = Tcl_GetString(objv[i + 1]);
	    tkwin = Tk_NameToWindow(interp, str, tkwin);
	    if (!tkwin) {
		goto end;
	    }
	    haveParentOption = 1;
	    break;

	case ALERT_TITLE:
	    title = [[NSString alloc] initWithUTF8String:
	    str = Tcl_GetString(objv[i + 1]);
		    Tcl_GetString(objv[i + 1])];
	    title = [[TKNSString alloc] initWithTclUtfBytes:
		    str length:TCL_INDEX_NONE];
	    [[alert window] setTitle:title];
	    [title release];
	    break;

	case ALERT_TYPE:
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i + 1], alertTypeStrings,
		    sizeof(char *), "-type value", TCL_EXACT, &typeIndex) != TCL_OK) {
		    sizeof(char *), "value", TCL_EXACT, &typeIndex) != TCL_OK) {
		goto end;
	    }
	    break;
	case ALERT_COMMAND:
	    cmdObj = objv[i+1];
	    break;
	}
    }
    if (indexDefaultOption) {
	/*
	 * Any '-default' option needs to know the '-type' option, which is
	 * why we do this here.
	 */

	if (Tcl_GetIndexFromObjStruct(interp, objv[indexDefaultOption + 1],
		alertButtonStrings, sizeof(char *), "-default value",
		alertButtonStrings, sizeof(char *), "value", TCL_EXACT, &index) != TCL_OK) {
		TCL_EXACT, &index) != TCL_OK) {
	    goto end;
	}

	/*
	 * Need to map from "ok" etc. to 1, 2, 3, right to left.
	 */

	defaultNativeButtonIndex =
		alertButtonIndexAndTypeToNativeButtonIndex[typeIndex][index];
	if (!defaultNativeButtonIndex) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj("Illegal default option", TCL_INDEX_NONE));
		    Tcl_NewStringObj("Illegal default option", -1));
	    Tcl_SetErrorCode(interp, "TK", "MSGBOX", "DEFAULT", NULL);
	    goto end;
	}
    }
    [alert setIcon:[NSApp applicationIconImage]];
    [alert setAlertStyle:alertStyles[iconIndex]];
    i = 0;
    while (i < 3 && alertButtonNames[typeIndex][i]) {
	[alert addButtonWithTitle:(NSString*) alertButtonNames[typeIndex][i++]];
	[alert addButtonWithTitle:(NSString*)alertButtonNames[typeIndex][i++]];
    }
    buttons = [alert buttons];
    for (NSButton *b in buttons) {
	NSString *ke = [b keyEquivalent];

	if (([ke isEqualToString:@"\r"] || [ke isEqualToString:@"\033"]) &&
		![b keyEquivalentModifierMask]) {
	    [b setKeyEquivalent:@""];
	}
    }
    [[buttons objectAtIndex: [buttons count]-1] setKeyEquivalent: @"\033"];
    [[buttons objectAtIndex: (NSUInteger)(defaultNativeButtonIndex-1)]
    [[buttons objectAtIndex: defaultNativeButtonIndex-1]
	    setKeyEquivalent: @"\r"];
    if (cmdObj) {
	callbackInfo = ckalloc(sizeof(AlertCallbackInfo));
	if (Tcl_IsShared(cmdObj)) {
	    cmdObj = Tcl_DuplicateObj(cmdObj);
	}
	Tcl_IncrRefCount(cmdObj);
    }
    callbackInfo.cmdObj = cmdObj;
    callbackInfo.interp = interp;
    callbackInfo.typeIndex = typeIndex;
    parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
    callbackInfo->cmdObj = cmdObj;
    callbackInfo->interp = interp;
    callbackInfo->typeIndex = typeIndex;
    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
	parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#if MAC_OS_X_VERSION_MIN_REQUIRED > 1090
 	[alert beginSheetModalForWindow:parent
	       completionHandler:^(NSModalResponse returnCode) {
	    [NSApp tkAlertDidEnd:alert
		    returnCode:returnCode
		    contextInfo:&callbackInfo];
	       completionHandler:^(NSModalResponse returnCode)
	       { [NSApp tkAlertDidEnd:alert
			returnCode:returnCode
			contextInfo:callbackInfo ]; } ];
	}];
#else
	[alert beginSheetModalForWindow:parent
	       modalDelegate:NSApp
	       didEndSelector:@selector(tkAlertDidEnd:returnCode:contextInfo:)
	       contextInfo:&callbackInfo];
	       contextInfo:callbackInfo];
#endif
	modalReturnCode = cmdObj ? 0 :
	    [alert runModal];
	    [NSApp runModalForWindow:[alert window]];
    } else {
	modalReturnCode = [alert runModal];
	[NSApp tkAlertDidEnd:alert returnCode:modalReturnCode
		contextInfo:&callbackInfo];
		contextInfo:callbackInfo];
    }
    if (cmdObj) {
	Tcl_DecrRefCount(cmdObj);
    }
    result = (modalReturnCode >= NSAlertFirstButtonReturn) ? TCL_OK : TCL_ERROR;
  end:
    [alert release];
    if (parentIsKey) {
	[parent makeKeyWindow];
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 */
#pragma mark [tk fontchooser] implementation (TIP 324)
/*
 *----------------------------------------------------------------------
 */

#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXFont.h"

typedef struct FontchooserData {
    Tcl_Obj *titleObj;
    Tcl_Obj *cmdObj;
    Tk_Window parent;
} FontchooserData;

enum FontchooserEvent {
enum FontchooserEvent { FontchooserClosed, FontchooserSelection };
    FontchooserClosed,
    FontchooserSelection
};

static void		FontchooserEvent(int kind);
static Tcl_Obj *	FontchooserCget(FontchooserData *fcdPtr,
			    int optionIndex);
static Tcl_ObjCmdProc2 FontchooserConfigureCmd;
static Tcl_ObjCmdProc2 FontchooserShowCmd;
static Tcl_ObjCmdProc2 FontchooserHideCmd;
static void		FontchooserParentEventHandler(void *clientData,
static int		FontchooserConfigureCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		FontchooserShowCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		FontchooserHideCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		FontchooserParentEventHandler(ClientData clientData,
			    XEvent *eventPtr);
static void		DeleteFontchooserData(void *clientData,
static void		DeleteFontchooserData(ClientData clientData,
			    Tcl_Interp *interp);

MODULE_SCOPE const TkEnsemble tkFontchooserEnsemble[];
const TkEnsemble tkFontchooserEnsemble[] = {
    { "configure", FontchooserConfigureCmd, NULL },
    { "show", FontchooserShowCmd, NULL },
    { "hide", FontchooserHideCmd, NULL },
    { NULL, NULL, NULL }
};

static Tcl_Interp *fontchooserInterp = NULL;
static NSFont *fontPanelFont = nil;
static NSMutableDictionary *fontPanelFontAttributes = nil;

static const char *const fontchooserOptionStrings[] = {
    "-command", "-font", "-parent", "-title",
    "-parent", "-title", "-font", "-command",
    "-visible", NULL
};
enum FontchooserOption {
    FontchooserCmd, FontchooserFont, FontchooserParent, FontchooserTitle,
    FontchooserParent, FontchooserTitle, FontchooserFont, FontchooserCmd,
    FontchooserVisible
};

@implementation TKApplication(TKFontPanel)

- (void) changeFont: (id) sender
{
    NSFontManager *fm = [NSFontManager sharedFontManager];
    (void)sender;

    if ([fm currentFontAction] == NSViaPanelFontAction) {
	NSFont *font = [fm convertFont:fontPanelFont];

	if (![fontPanelFont isEqual:font]) {
	    [fontPanelFont release];
	    fontPanelFont = [font retain];
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1657
1658

1659
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
1480
1481
1482
1483
1484
1485
1486

1487
1488


1489
1490
1491
1492
1493

1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510


1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535


1536
1537
1538
1539
1540
1541
1542
1543
1544
1545


1546
1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570


1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592

1593
1594

1595
1596
1597
1598
1599
1600
1601
1602







-
+

-
-





-
+


-
+













-
-
+
+





-
+














-
+


-
-
+
+








-
-
+





-
+







-
+










-
-
+
+
+



















-
+

-
+








    if (![fontPanelFontAttributes isEqual:attributes]) {
	[fontPanelFontAttributes setDictionary:attributes];
	FontchooserEvent(FontchooserSelection);
    }
}

- (NSUInteger) validModesForFontPanel: (NSFontPanel *)fontPanel
- (NSUInteger) validModesForFontPanel: (NSFontPanel *) fontPanel
{
    (void)fontPanel;

    return (NSFontPanelStandardModesMask & ~NSFontPanelAllEffectsModeMask) |
	    NSFontPanelUnderlineEffectModeMask |
	    NSFontPanelStrikethroughEffectModeMask;
}

- (void) windowDidOrderOffScreen: (NSNotification *)notification
- (void) windowDidOrderOffScreen: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    if ([[notification object] isEqual:[[NSFontManager sharedFontManager]
	    fontPanel:NO]]) {
	FontchooserEvent(FontchooserClosed);
    }
}
@end

/*
 *----------------------------------------------------------------------
 *
 * FontchooserEvent --
 *
 *	This processes events generated by user interaction with the font
 *	panel.
 *	This processes events generated by user interaction with the
 *	font panel.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue.
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

static void
FontchooserEvent(
    int kind)
{
    FontchooserData *fcdPtr;
    Tcl_Obj *fontObj;

    if (!fontchooserInterp) {
	return;
    }
    fcdPtr = (FontchooserData *)Tcl_GetAssocData(fontchooserInterp, "::tk::fontchooser", NULL);
    fcdPtr = Tcl_GetAssocData(fontchooserInterp, "::tk::fontchooser", NULL);
    switch (kind) {
    case FontchooserClosed:
	if (fcdPtr->parent != NULL) {
	    Tk_SendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL);
	if (fcdPtr->parent != None) {
	    TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL);
	    fontchooserInterp = NULL;
	}
	break;
    case FontchooserSelection:
	fontObj = TkMacOSXFontDescriptionForNSFontAndNSFontAttributes(
		fontPanelFont, fontPanelFontAttributes);
	if (fontObj) {
	    if (fcdPtr->cmdObj) {
		Tcl_Size objc;
		int result;
		int objc, result;
		Tcl_Obj **objv, **tmpv;

		result = Tcl_ListObjGetElements(fontchooserInterp,
			fcdPtr->cmdObj, &objc, &objv);
		if (result == TCL_OK) {
		    tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		    tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
		    memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
		    tmpv[objc] = fontObj;
		    TkBackgroundEvalObjv(fontchooserInterp, objc + 1, tmpv,
			    TCL_EVAL_GLOBAL);
		    ckfree(tmpv);
		}
	    }
	    Tk_SendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL);
	    TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL);
	}
	break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * FontchooserCget --
 *
 *	Helper for the FontchooserConfigure command to return the current value
 *	of any of the options (which may be NULL in the structure).
 *	Helper for the FontchooserConfigure command to return the
 *	current value of any of the options (which may be NULL in
 *	the structure)
 *
 * Results:
 *	Tcl object of option value.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
FontchooserCget(
    FontchooserData *fcdPtr,
    int optionIndex)
{
    Tcl_Obj *resObj = NULL;

    switch(optionIndex) {
    case FontchooserParent:
	if (fcdPtr->parent != NULL) {
	if (fcdPtr->parent != None) {
	    resObj = Tcl_NewStringObj(
		    ((TkWindow *)fcdPtr->parent)->pathName, TCL_INDEX_NONE);
		    ((TkWindow *) fcdPtr->parent)->pathName, -1);
	} else {
	    resObj = Tcl_NewStringObj(".", 1);
	}
	break;
    case FontchooserTitle:
	if (fcdPtr->titleObj) {
	    resObj = fcdPtr->titleObj;
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
1629
1630
1631
1632
1633
1634
1635


1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651

1652
1653
1654
1655

1656
1657


1658
1659
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







-
-
+
+












-
+

-
+



-
+

-
-
+










-
-
+
+









-
+
-







}

/*
 * ----------------------------------------------------------------------
 *
 * FontchooserConfigureCmd --
 *
 *	Implementation of the 'tk fontchooser configure' ensemble command.  See
 *	the user documentation for what it does.
 *	Implementation of the 'tk fontchooser configure' ensemble command.
 *	See the user documentation for what it does.
 *
 * Results:
 *	See the user documentation.
 *
 * Side effects:
 *	Per-interp data structure may be modified
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserConfigureCmd(
    void *clientData,	/* Main window */
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tk_Window tkwin = (Tk_Window)clientData;
    FontchooserData *fcdPtr = (FontchooserData *)Tcl_GetAssocData(interp, "::tk::fontchooser",
    FontchooserData *fcdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser",
	    NULL);
    Tcl_Size i;
    int r = TCL_OK;
    int i, r = TCL_OK;

    /*
     * With no arguments we return all the options in a dict
     */

    if (objc == 1) {
	Tcl_Obj *keyObj, *valueObj;
	Tcl_Obj *dictObj = Tcl_NewDictObj();

	for (i = 0; r == TCL_OK && fontchooserOptionStrings[i] != NULL; ++i) {
	    keyObj = Tcl_NewStringObj(fontchooserOptionStrings[i], TCL_INDEX_NONE);
	    valueObj = FontchooserCget(fcdPtr, (int)i);
	    keyObj = Tcl_NewStringObj(fontchooserOptionStrings[i], -1);
	    valueObj = FontchooserCget(fcdPtr, i);
	    r = Tcl_DictObjPut(interp, dictObj, keyObj, valueObj);
	}
	if (r == TCL_OK) {
	    Tcl_SetObjResult(interp, dictObj);
	}
	return r;
    }

    for (i = 1; i < objc; i += 2) {
	int optionIndex;
	int optionIndex, len;
	Tcl_Size len;

	if (Tcl_GetIndexFromObjStruct(interp, objv[i], fontchooserOptionStrings,
		sizeof(char *), "option", 0, &optionIndex) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (objc == 2) {
	    /*
1864
1865
1866
1867
1868
1869
1870
1871

1872
1873
1874
1875
1876
1877
1878
1879

1880
1881
1882
1883
1884
1885
1886
1698
1699
1700
1701
1702
1703
1704

1705
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
1720







-
+







-
+







	    return TCL_ERROR;
	}
	switch (optionIndex) {
	case FontchooserVisible: {
	    const char *msg = "cannot change read-only option "
		    "\"-visible\": use the show or hide command";

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
	    Tcl_SetErrorCode(interp, "TK", "FONTDIALOG", "READONLY", NULL);
	    return TCL_ERROR;
	}
	case FontchooserParent: {
	    Tk_Window parent = Tk_NameToWindow(interp,
		    Tcl_GetString(objv[i+1]), tkwin);

	    if (parent == NULL) {
	    if (parent == None) {
		return TCL_ERROR;
	    }
	    if (fcdPtr->parent) {
		Tk_DeleteEventHandler(fcdPtr->parent, StructureNotifyMask,
			FontchooserParentEventHandler, fcdPtr);
	    }
	    fcdPtr->parent = parent;
1899
1900
1901
1902
1903
1904
1905
1906

1907
1908
1909
1910
1911
1912
1913
1733
1734
1735
1736
1737
1738
1739

1740
1741
1742
1743
1744
1745
1746
1747







-
+







		    fcdPtr->titleObj = Tcl_DuplicateObj(fcdPtr->titleObj);
		}
		Tcl_IncrRefCount(fcdPtr->titleObj);
	    } else {
		fcdPtr->titleObj = NULL;
	    }
	    break;
	case FontchooserFont: {
	case FontchooserFont:
	    Tcl_GetStringFromObj(objv[i+1], &len);
	    if (len) {
		Tk_Font f = Tk_AllocFontFromObj(interp, tkwin, objv[i+1]);

		if (!f) {
		    return TCL_ERROR;
		}
1929
1930
1931
1932
1933
1934
1935
1936
1937

1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1763
1764
1765
1766
1767
1768
1769


1770
1771
1772

1773
1774
1775
1776
1777
1778
1779







-
-
+


-







	    NSFontPanel *fp = [fm fontPanel:NO];

	    [fp setPanelFont:fontPanelFont isMultiple:NO];
	    [fm setSelectedFont:fontPanelFont isMultiple:NO];
	    [fm setSelectedAttributes:fontPanelFontAttributes
		    isMultiple:NO];
	    if ([fp isVisible]) {
		Tk_SendVirtualEvent(fcdPtr->parent,
			"TkFontchooserFontChanged", NULL);
		TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL);
	    }
	    break;
	}
	case FontchooserCmd:
	    if (fcdPtr->cmdObj) {
		Tcl_DecrRefCount(fcdPtr->cmdObj);
	    }
	    Tcl_GetStringFromObj(objv[i+1], &len);
	    if (len) {
		fcdPtr->cmdObj = objv[i+1];
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
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







-
-
-
+
+
+












-
+

-
-
+
+

-
+


-
-
+
+



-


-





-
+











-
-
+
+












-
-
-
-
+
+
+
+


-







}

/*
 * ----------------------------------------------------------------------
 *
 * FontchooserShowCmd --
 *
 *	Implements the 'tk fontchooser show' ensemble command. The per-interp
 *	configuration data for the dialog is held in an interp associated
 *	structure.
 *	Implements the 'tk fontchooser show' ensemble command. The
 *	per-interp configuration data for the dialog is held in an interp
 *	associated structure.
 *
 * Results:
 *	See the user documentation.
 *
 * Side effects:
 *	Font Panel may be shown.
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserShowCmd(
    void *clientData,	/* Main window */
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    TCL_UNUSED(Tcl_Size),
    TCL_UNUSED(Tcl_Obj *const *))
    int objc,
    Tcl_Obj *const objv[])
{
    FontchooserData *fcdPtr = (FontchooserData *)Tcl_GetAssocData(interp, "::tk::fontchooser",
    FontchooserData *fcdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser",
	    NULL);

    if (fcdPtr->parent == NULL) {
	fcdPtr->parent = (Tk_Window)clientData;
    if (fcdPtr->parent == None) {
	fcdPtr->parent = (Tk_Window) clientData;
	Tk_CreateEventHandler(fcdPtr->parent, StructureNotifyMask,
		FontchooserParentEventHandler, fcdPtr);
    }

    NSFontManager *fm = [NSFontManager sharedFontManager];
    NSFontPanel *fp = [fm fontPanel:YES];

    if ([fp delegate] != NSApp) {
	[fp setDelegate:NSApp];
    }
    if (![fp isVisible]) {
	[fm orderFrontFontPanel:NSApp];
	Tk_SendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL);
	TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL);
    }
    fontchooserInterp = interp;

    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * FontchooserHideCmd --
 *
 *	Implementation of the 'tk fontchooser hide' ensemble. See the user
 *	documentation for details.
 *	Implementation of the 'tk fontchooser hide' ensemble. See the
 *	user documentation for details.
 *
 * Results:
 *	See the user documentation.
 *
 * Side effects:
 *	Font Panel may be hidden.
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserHideCmd(
    TCL_UNUSED(void *),	/* Main window */
    TCL_UNUSED(Tcl_Interp *),
    TCL_UNUSED(Tcl_Size),
    TCL_UNUSED(Tcl_Obj *const *))
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:NO];

    if ([fp isVisible]) {
	[fp orderOut:NSApp];
    }
    return TCL_OK;
}

/*
2054
2055
2056
2057
2058
2059
2060
2061

2062
2063
2064

2065
2066
2067
2068
2069

2070
2071
2072
2073
2074
2075
2076
1883
1884
1885
1886
1887
1888
1889

1890
1891
1892

1893
1894
1895
1896
1897

1898
1899
1900
1901
1902
1903
1904
1905







-
+


-
+




-
+







 *	Font chooser parent info is cleared and font panel is hidden.
 *
 * ----------------------------------------------------------------------
 */

static void
FontchooserParentEventHandler(
    void *clientData,
    ClientData clientData,
    XEvent *eventPtr)
{
    FontchooserData *fcdPtr = (FontchooserData *)clientData;
    FontchooserData *fcdPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	Tk_DeleteEventHandler(fcdPtr->parent, StructureNotifyMask,
		FontchooserParentEventHandler, fcdPtr);
	fcdPtr->parent = NULL;
	fcdPtr->parent = None;
	FontchooserHideCmd(NULL, NULL, 0, NULL);
    }
}

/*
 * ----------------------------------------------------------------------
 *
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
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







-
+


-
+



















-
-
+
+













-
+

-
+







 *	per-interp configuration data is destroyed.
 *
 * ----------------------------------------------------------------------
 */

static void
DeleteFontchooserData(
    void *clientData,
    ClientData clientData,
    Tcl_Interp *interp)
{
    FontchooserData *fcdPtr = (FontchooserData *)clientData;
    FontchooserData *fcdPtr = clientData;

    if (fcdPtr->titleObj) {
	Tcl_DecrRefCount(fcdPtr->titleObj);
    }
    if (fcdPtr->cmdObj) {
	Tcl_DecrRefCount(fcdPtr->cmdObj);
    }
    ckfree(fcdPtr);

    if (fontchooserInterp == interp) {
	fontchooserInterp = NULL;
    }
}

/*
 * ----------------------------------------------------------------------
 *
 * TkInitFontchooser --
 *
 *	Associate the font chooser configuration data with the Tcl interpreter.
 *	There is one font chooser per interp.
 *	Associate the font chooser configuration data with the Tcl
 *	interpreter. There is one font chooser per interp.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	per-interp configuration data is destroyed.
 *
 * ----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkInitFontchooser(
    Tcl_Interp *interp,
    TCL_UNUSED(void *))
    ClientData clientData)
{
    FontchooserData *fcdPtr = (FontchooserData *)ckalloc(sizeof(FontchooserData));
    FontchooserData *fcdPtr = ckalloc(sizeof(FontchooserData));

    bzero(fcdPtr, sizeof(FontchooserData));
    Tcl_SetAssocData(interp, "::tk::fontchooser", DeleteFontchooserData,
	    fcdPtr);
    if (!fontPanelFontAttributes) {
	fontPanelFontAttributes = [NSMutableDictionary new];
    }

Changes to macosx/tkMacOSXDraw.c.

1
2
3
4
5



6
7
8
9
10




11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54





55
56
57
58
59
60
61
1
2
3


4
5
6
7




8
9
10
11
12
13
14
15
16
17
18


19
20





21
22
23
24
25

26
27
28

29
30
31
32
33
34
35
36
37

38
39
40
41

42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59



-
-
+
+
+

-
-
-
-
+
+
+
+







-
-
+
+
-
-
-
-
-





-



-
+








-
+



-






-
+
+
+
+
+







/*
 * tkMacOSXDraw.c --
 *
 *	This file contains functions that draw to windows. Many of thees
 *	functions emulate Xlib functions.
 *	This file contains functions that perform drawing to
 *	Xlib windows. Most of the functions simple emulate
 *	Xlib functions.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2014-2020 Marc Culler.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2014 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXDebug.h"
#include "tkButton.h"

#include "xbytes.h"
#include "tkButton.h"
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
#define GET_CGCONTEXT [[NSGraphicsContext currentContext] CGContext]
#else
#define GET_CGCONTEXT [[NSGraphicsContext currentContext] graphicsPort]
#endif

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_DRAWING
#define TK_MAC_DEBUG_IMAGE_DRAWING
#define TK_MAC_DEBUG_CG
#endif
*/

#define radians(d)	((d) * (M_PI/180.0))
#define radians(d) ((d) * (M_PI/180.0))

/*
 * Non-antialiased CG drawing looks better and more like X11 drawing when using
 * very fine lines, so decrease all linewidths by the following constant.
 */
#define NON_AA_CG_OFFSET .999

static int cgAntiAliasLimit = 0;
#define notAA(w)	((w) < cgAntiAliasLimit)
#define notAA(w) ((w) < cgAntiAliasLimit)

static int useThemedToplevel = 0;
static int useThemedFrame = 0;
static unsigned long transparentColor;

/*
 * Prototypes for functions used only in this file.
 */

static void ClipToGC(Drawable d, GC gc, HIShapeRef *clipRgnPtr);
static NSImage *CreateNSImageFromPixmap(Pixmap pixmap, int width, int height);
static CGImageRef CreateCGImageWithXImage(XImage *ximage);
static CGContextRef GetCGContextForDrawable(Drawable d);
static void DrawCGImage(Drawable d, GC gc, CGContextRef context, CGImageRef image,
	unsigned long imageForeground, unsigned long imageBackground,
	CGRect imageBounds, CGRect srcBounds, CGRect dstBounds);


/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInitCGDrawing --
 *
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99

100
101
102
103

104
105
106
107
108
109
110
111
112
113





















































114
115
116





































































































































































































































































117
118
119

120
121
122
123
124
125
126




127
128


129
130

131
132
133








134
135
136
137
138










139
140
141







142
143
144










































145
146
147
148
149
150

151
152

153
154
155

156
157
158
159
160
161
162
163
164
165



166
167
168
169
170
171
172
173


174
175
176
177
178
179
180


181
182
183


184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203


204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229








































































230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245



246
247

248
249
250

251
252
253
254

255
256

257

258

259
260
261

262
263
264


265
266





267
268


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325

326
327
328
329

330
331
332
333

334
335
336
337
338

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96

97
98
99
100

101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
434
435
436
437
438


439
440


441


442
443
444
445
446
447
448
449
450





451
452
453
454
455
456
457
458
459
460



461
462
463
464
465
466
467



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

515
516

517
518
519

520
521
522
523
524
525
526
527



528
529
530




531



532
533

534





535
536



537
538
539
540
541
542
543

544
545
546
547
548
549
550
551
552
553
554
555
556


557
558
559
560
561
562
563
564
565

566


567



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658
659
660
661
662
663
664



665
666
667
668

669
670
671
672
673
674
675
676

677
678

679
680
681

682

683
684
685
686
687

688
689
690
691
692
693
694
695
696


697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758



759




760
761
762
763
764

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782
783
784

785
786
787
788
789
790
791







-
+












-
+









-
+



-
+


-







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+







+
+
+
+
-
-
+
+
-
-
+
-
-

+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+

-
+


-
+







-
-
-
+
+
+
-
-
-
-

-
-
-
+
+
-

-
-
-
-
-
+
+
-
-
-
+
+





-
+












-
-
+
+







-

-
-
+
-
-
-












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+












-
-
-
+
+
+

-
+



+



-
+

-
+

+
-
+
-


+


-
+
+


+
+
+
+
+
-
-
+
+















-
+













-
+










-
+















+

+

-
-
-
+
-
-
-
-
+




-
+














-





-







 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkMacOSXInitCGDrawing(
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    int enable,
    int limit)
{
    static Boolean initialized = FALSE;

    if (!initialized) {
	initialized = TRUE;

	if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
	    Tcl_ResetResult(interp);
	}

	if (Tcl_LinkVar(interp, "::tk::mac::CGAntialiasLimit",
		&cgAntiAliasLimit, TCL_LINK_INT) != TCL_OK) {
		(char *) &cgAntiAliasLimit, TCL_LINK_INT) != TCL_OK) {
	    Tcl_ResetResult(interp);
	}
	cgAntiAliasLimit = limit;

	/*
	 * Piggy-back the themed drawing var init here.
	 */

	if (Tcl_LinkVar(interp, "::tk::mac::useThemedToplevel",
		&useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
		(char *) &useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
	    Tcl_ResetResult(interp);
	}
	if (Tcl_LinkVar(interp, "::tk::mac::useThemedFrame",
		&useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
		(char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
	    Tcl_ResetResult(interp);
	}
	transparentColor = TkMacOSXClearPixel();
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * BitmapRepFromDrawableRect
 *
 *	Extract bitmap data from a MacOSX drawable as an NSBitmapImageRep.
 *
 * Results:
 *	Returns an autoreleased NSBitmapRep representing the image of the given
 *      rectangle of the given drawable.
 *
 *      NOTE: The x,y coordinates should be relative to a coordinate system with
 *      origin at the top left, as used by XImage and CGImage, not bottom
 *      left as used by NSView.
 *
 * Side effects:
 *     None
 *
 *----------------------------------------------------------------------
 */
NSBitmapImageRep*
BitmapRepFromDrawableRect(
        Drawable drawable,
	int x,
	int y,
	unsigned int width,
	unsigned int height)
{
    MacDrawable *mac_drawable = (MacDrawable *) drawable;
    CGContextRef cg_context=NULL;
    CGImageRef cg_image=NULL, sub_cg_image=NULL;
    NSBitmapImageRep *bitmap_rep=NULL;
    NSView *view=NULL;
    if ( mac_drawable->flags & TK_IS_PIXMAP ) {
	/*
	   This means that the MacDrawable is functioning as a Tk Pixmap, so its view
	   field is NULL.
	*/
	cg_context = GetCGContextForDrawable(drawable);
	CGRect image_rect = CGRectMake(x, y, width, height);
	cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context);
	sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect);
	if ( sub_cg_image ) {
	    /*This can be dealloc'ed prematurely if set for autorelease, causing crashes.*/
	    bitmap_rep = [NSBitmapImageRep alloc];
	    [bitmap_rep initWithCGImage:sub_cg_image];
	}
	if ( cg_image ) {
	    CGImageRelease(cg_image);
	}
    } else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) {
	/* convert top-left coordinates to NSView coordinates */
	int view_height = [view bounds].size.height;
	NSRect view_rect = NSMakeRect(x + mac_drawable->xOff,
				      view_height - height - y - mac_drawable->yOff,
				      width,height);
 * TkMacOSXGetNSImageFromTkImage --
 *
 *	Get autoreleased NSImage for Tk_Image.

	if ( [view lockFocusIfCanDraw] ) {
	    /*This can be dealloc'ed prematurely if set for autorelease, causing crashes.*/
	    bitmap_rep = [NSBitmapImageRep alloc];
	    bitmap_rep = [bitmap_rep initWithFocusedViewRect:view_rect];
	    [view unlockFocus];
	} else {
	    TkMacOSXDbgMsg("Could not lock focus on view.");
	}

    } else {
	TkMacOSXDbgMsg("Invalid source drawable");
    }
    return bitmap_rep;
}

/*
 *----------------------------------------------------------------------
 *
 * XCopyArea --
 *
 *	Copies data from one drawable to another.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Data is moved from a window or bitmap to a second window or
 *	bitmap.
 *
 *----------------------------------------------------------------------
 */

void
XCopyArea(
    Display *display,		/* Display. */
    Drawable src,		/* Source drawable. */
    Drawable dst,		/* Destination drawable. */
    GC gc,				/* GC to use. */
    int src_x,			/* X & Y, width & height */
    int src_y,			/* define the source rectangle */
    unsigned int width,	/* that will be copied. */
    unsigned int height,
    int dest_x,			/* Dest X & Y on dest rect. */
    int dest_y)
{
    TkMacOSXDrawingContext dc;
    MacDrawable *srcDraw = (MacDrawable *) src;
    NSBitmapImageRep *bitmap_rep = NULL;
    CGImageRef img = NULL;

    display->request++;

    if (!width || !height) {
	/* This happens all the time.
	TkMacOSXDbgMsg("Drawing of empty area requested");
	*/
	return;
    }

    if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
	return;
	/*TkMacOSXDbgMsg("Failed to setup drawing context.");*/
    }

    if ( dc.context ) {
	if (srcDraw->flags & TK_IS_PIXMAP) {
	    img = TkMacOSXCreateCGImageWithDrawable(src);
	}else if (TkMacOSXDrawableWindow(src)) {
	    bitmap_rep =  BitmapRepFromDrawableRect(src, src_x, src_y, width, height);
	    if ( bitmap_rep ) {
		img = [bitmap_rep CGImage];
	    }
	} else {
	    TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
	}

	if (img) {
	    DrawCGImage(dst, gc, dc.context, img, gc->foreground, gc->background,
			CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height),
			CGRectMake(src_x, src_y, width, height),
			CGRectMake(dest_x, dest_y, width, height));
	    CFRelease(img);


	} else {
	    TkMacOSXDbgMsg("Failed to construct CGImage.");
	}

    } else {
	TkMacOSXDbgMsg("Invalid destination drawable - no context.");
	return;
    }

    TkMacOSXRestoreDrawingContext(&dc);
}

/*
 *----------------------------------------------------------------------
 *
 * XCopyPlane --
 *
 *	Copies a bitmap from a source drawable to a destination
 *	drawable. The plane argument specifies which bit plane of
 *	the source contains the bitmap. Note that this implementation
 *	ignores the gc->function.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes the destination drawable.
 *
 *----------------------------------------------------------------------
 */

void
XCopyPlane(
    Display *display,		/* Display. */
    Drawable src,		/* Source drawable. */
    Drawable dst,		/* Destination drawable. */
    GC gc,				/* GC to use. */
    int src_x,			/* X & Y, width & height */
    int src_y,			/* define the source rectangle */
    unsigned int width,	/* that will be copied. */
    unsigned int height,
    int dest_x,			/* Dest X & Y on dest rect. */
    int dest_y,
    unsigned long plane)	/* Which plane to copy. */
{
    TkMacOSXDrawingContext dc;
    MacDrawable *srcDraw = (MacDrawable *) src;
    MacDrawable *dstDraw = (MacDrawable *) dst;

    display->request++;
    if (!width || !height) {
	/* TkMacOSXDbgMsg("Drawing of empty area requested"); */
	return;
    }
    if (plane != 1) {
	Tcl_Panic("Unexpected plane specified for XCopyPlane");
    }
    if (srcDraw->flags & TK_IS_PIXMAP) {
	if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
	    return;
	}
	CGContextRef context = dc.context;
	if (context) {
	    CGImageRef img = TkMacOSXCreateCGImageWithDrawable(src);
	    if (img) {
		TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
		unsigned long imageBackground  = gc->background;
                if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP){
		    CGRect srcRect = CGRectMake(src_x, src_y, width, height);
		    CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap);
		    CGImageRef submask = CGImageCreateWithImageInRect(img, srcRect);
		    CGRect rect = CGRectMake(dest_x, dest_y, width, height);
		    rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
		    CGContextSaveGState(context);
		    /* Move the origin of the destination to top left. */
		    CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect));
		    CGContextScaleCTM(context, 1, -1);
		    /* Fill with the background color, clipping to the mask. */
		    CGContextClipToMask(context, rect, submask);
		    TkMacOSXSetColorInContext(gc, gc->background, dc.context);
		    CGContextFillRect(context, rect);
		    /* Fill with the foreground color, clipping to the
		       intersection of img and mask. */
		    CGImageRef subimage = CGImageCreateWithImageInRect(img, srcRect);
		    CGContextClipToMask(context, rect, subimage);
		    TkMacOSXSetColorInContext(gc, gc->foreground, context);
		    CGContextFillRect(context, rect);
		    CGContextRestoreGState(context);
		    CGImageRelease(img);
		    CGImageRelease(mask);
		    CGImageRelease(submask);
		    CGImageRelease(subimage);
		} else {
		    DrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground,
				CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height),
				CGRectMake(src_x, src_y, width, height),
				CGRectMake(dest_x, dest_y, width, height));
		    CGImageRelease(img);
		}
	    } else { /* no image */
		TkMacOSXDbgMsg("Invalid source drawable");
	    }
	} else {
	    TkMacOSXDbgMsg("Invalid destination drawable - could not get a bitmap context.");
	}
	TkMacOSXRestoreDrawingContext(&dc);
    } else { /* source drawable is a window, not a Pixmap */
	XCopyArea(display, src, dst, gc, src_x, src_y, width, height, dest_x, dest_y);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkPutImage --
 *
 *	Copies a subimage from an in-memory image to a rectangle of
 *	of the specified drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws the image on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
TkPutImage(
    unsigned long *colors,	/* Unused on Macintosh. */
    int ncolors,			/* Unused on Macintosh. */
    Display* display,		/* Display. */
    Drawable d,			/* Drawable to place image on. */
    GC gc,				/* GC to use. */
    XImage* image,		/* Image to place. */
    int src_x,			/* Source X & Y. */
    int src_y,
    int dest_x,			/* Destination X & Y. */
    int dest_y,
    unsigned int width,	/* Same width & height for both */
    unsigned int height)	/* distination and source. */
{
    TkMacOSXDrawingContext dc;

    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return BadDrawable;
    }
    if (dc.context) {
	CGImageRef img = CreateCGImageWithXImage(image);

	if (img) {
	    /* If the XImage has big pixels, rescale the source dimensions.*/
	    int pp = image->pixelpower;
	    DrawCGImage(d, gc, dc.context, img, gc->foreground, gc->background,
		    CGRectMake(0, 0, image->width<<pp, image->height<<pp),
		    CGRectMake(src_x<<pp, src_y<<pp, width<<pp, height<<pp),
		    CGRectMake(dest_x, dest_y, width, height));
	    CFRelease(img);
	} else {
	    TkMacOSXDbgMsg("Invalid source drawable");
	}
    } else {
	TkMacOSXDbgMsg("Invalid destination drawable");
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * CreateCGImageWithXImage --
 *
 *	Create CGImage from XImage, copying the image data.
 *
 * Results:
 *	NSImage.
 *	CGImage, release after use.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void ReleaseData(void *info, const void *data, size_t size) {
    ckfree(info);
}

NSImage *
TkMacOSXGetNSImageFromTkImage(
CGImageRef
CreateCGImageWithXImage(
    Display *display,
    Tk_Image image,
    XImage *image)
    int width,
    int height)
{
    CGImageRef img = NULL;
    size_t bitsPerComponent, bitsPerPixel;
    size_t len = image->bytes_per_line * image->height;
    const CGFloat *decode = NULL;
    CGBitmapInfo bitmapInfo;
    CGDataProviderRef provider = NULL;
    char *data = NULL;
    CGDataProviderReleaseDataCallback releaseData = ReleaseData;
    Pixmap pixmap;
    NSImage *nsImage;
    if (width <= 0 || height <= 0) {
	return nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0,0)];
    }

    if (image->bits_per_pixel == 1) {
	/*
	 * BW image
	 */

	/* Reverses the sense of the bits */
	static const CGFloat decodeWB[2] = {1, 0};
	decode = decodeWB;

    pixmap = Tk_GetPixmap(display, None, width, height, 0);
    Tk_RedrawImage(image, 0, 0, width, height, pixmap, 0, 0);
    nsImage = CreateNSImageFromPixmap(pixmap, width, height);
	bitsPerComponent = 1;
	bitsPerPixel = 1;
	if (image->bitmap_bit_order != MSBFirst) {
	    char *srcPtr = image->data + image->xoffset;
	    char *endPtr = srcPtr + len;
	    char *destPtr = (data = ckalloc(len));

    Tk_FreePixmap(display, pixmap);

    return [nsImage autorelease];
	    while (srcPtr < endPtr) {
		*destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))];
	    }
	} else {
	    data = memcpy(ckalloc(len), image->data + image->xoffset, len);
	}
	if (data) {
	    provider = CGDataProviderCreateWithData(data, data, len, releaseData);
	}
	if (provider) {
	    img = CGImageMaskCreate(image->width, image->height, bitsPerComponent,
				    bitsPerPixel, image->bytes_per_line, provider, decode, 0);
	}
    } else if (image->format == ZPixmap && image->bits_per_pixel == 32) {
	/*
	 * Color image
	 */

	CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);

	bitsPerComponent = 8;
	bitsPerPixel = 32;
	bitmapInfo = (image->byte_order == MSBFirst ?
		kCGBitmapByteOrder32Big : kCGBitmapByteOrder32Little) |
		kCGImageAlphaNoneSkipFirst;
	data = memcpy(ckalloc(len), image->data + image->xoffset, len);
	if (data) {
	    provider = CGDataProviderCreateWithData(data, data, len, releaseData);
	}
	if (provider) {
	    img = CGImageCreate(image->width, image->height, bitsPerComponent,
		    bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo,
		    provider, decode, 0, kCGRenderingIntentDefault);
	    CFRelease(provider);
	}
	if (colorspace) {
	    CFRelease(colorspace);
	}
    } else {
	TkMacOSXDbgMsg("Unsupported image type");
    }
    return img;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSImageFromBitmap --
 * TkMacOSXCreateCGImageWithDrawable --
 *
 *	Get autoreleased NSImage for Bitmap.
 *	Create a CGImage from the given Drawable.
 *
 * Results:
 *	NSImage.
 *	CGImage, release after use.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

NSImage *
TkMacOSXGetNSImageFromBitmap(
    Display *display,
CGImageRef
TkMacOSXCreateCGImageWithDrawable(
    Drawable drawable)
    Pixmap bitmap,
    GC gc,
    int width,
    int height)
{
    Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0);
    NSImage *nsImage;

    CGImageRef img = NULL;
    CGContextRef context = GetCGContextForDrawable(drawable);
    unsigned long origBackground = gc->background;

    gc->background = transparentColor;
    XSetClipOrigin(display, gc, 0, 0);
    XCopyPlane(display, bitmap, pixmap, gc, 0, 0, (unsigned)width, (unsigned)height, 0, 0, 1);
    gc->background = origBackground;
    nsImage = CreateNSImageFromPixmap(pixmap, width, height);
    if (context) {
	img = CGBitmapContextCreateImage(context);
    Tk_FreePixmap(display, pixmap);

    return [nsImage autorelease];
    }
    return img;
}

/*
 *----------------------------------------------------------------------
 *
 * CreateNSImageFromPixmap --
 * CreateNSImageWithPixmap --
 *
 *	Create NSImage for Pixmap.
 *
 * Results:
 *	NSImage.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static NSImage *
CreateNSImageFromPixmap(
static NSImage*
CreateNSImageWithPixmap(
    Pixmap pixmap,
    int width,
    int height)
{
    CGImageRef cgImage;
    NSImage *nsImage;
    NSBitmapImageRep *bitmapImageRep;
    CGContextRef context = TkMacOSXGetCGContextForDrawable(pixmap);

    if (context) {
	cgImage = CGBitmapContextCreateImage(context);
    cgImage = TkMacOSXCreateCGImageWithDrawable(pixmap);
    } else {
	return NULL;
    }
    nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
    bitmapImageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
    [nsImage addRepresentation:bitmapImageRep];
    [bitmapImageRep release];
    CFRelease(cgImage);

    return nsImage;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSImageWithTkImage --
 *
 *	Get autoreleased NSImage for Tk_Image.
 *
 * Results:
 *	NSImage.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

NSImage*
TkMacOSXGetNSImageWithTkImage(
    Display *display,
    Tk_Image image,
    int width,
    int height)
{
    Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0);
    NSImage *nsImage;

    Tk_RedrawImage(image, 0, 0, width, height, pixmap, 0, 0);
    nsImage = CreateNSImageWithPixmap(pixmap, width, height);
    Tk_FreePixmap(display, pixmap);

    return [nsImage autorelease];
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSImageWithBitmap --
 *
 *	Get autoreleased NSImage for Bitmap.
 *
 * Results:
 *	NSImage.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

NSImage*
TkMacOSXGetNSImageWithBitmap(
    Display *display,
    Pixmap bitmap,
    GC gc,
    int width,
    int height)
{
    Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0);
    NSImage *nsImage;

    unsigned long origBackground = gc->background;

    gc->background = TRANSPARENT_PIXEL << 24;
    XSetClipOrigin(display, gc, 0, 0);
    XCopyPlane(display, bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1);
    gc->background = origBackground;
    nsImage = CreateNSImageWithPixmap(pixmap, width, height);
    Tk_FreePixmap(display, pixmap);

    return [nsImage autorelease];
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXGetCGContextForDrawable --
 * GetCGContextForDrawable --
 *
 *	Get CGContext for given Drawable, creating one if necessary.
 *
 * Results:
 *	CGContext.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
Tk_MacOSXGetCGContextForDrawable(
    Drawable drawable)
CGContextRef
GetCGContextForDrawable(
    Drawable d)
{
    MacDrawable *macDraw = (MacDrawable *)drawable;
    MacDrawable *macDraw = (MacDrawable *) d;

    if (macDraw && (macDraw->flags & TK_IS_PIXMAP) && !macDraw->context) {
	const size_t bitsPerComponent = 8;
	size_t bitsPerPixel, bytesPerRow, len;
	CGColorSpaceRef colorspace = NULL;
	CGBitmapInfo bitmapInfo =
#ifdef __LITTLE_ENDIAN__
		kCGBitmapByteOrder32Host;
	kCGBitmapByteOrder32Host;
#else
		kCGBitmapByteOrderDefault;
	kCGBitmapByteOrderDefault;
#endif
	char *data;
	CGRect bounds = CGRectMake(0, 0,
	CGRect bounds = CGRectMake(0, 0, macDraw->size.width, macDraw->size.height);
		macDraw->size.width, macDraw->size.height);

	if (macDraw->flags & TK_IS_BW_PIXMAP) {
	    bitsPerPixel = 8;
	    bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly;
	} else {
	    colorspace = CGColorSpaceCreateDeviceRGB();
	    colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
	    bitsPerPixel = 32;
	    bitmapInfo |= kCGImageAlphaPremultipliedFirst;
	}
	bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3
		& ~15;
	len = macDraw->size.height * bytesPerRow;
	data = ckalloc(len);
	bzero(data, len);
	macDraw->context = CGBitmapContextCreate(NULL, (unsigned)macDraw->size.width,
		(unsigned)macDraw->size.height, bitsPerComponent, 0,
	macDraw->context = CGBitmapContextCreate(data, macDraw->size.width,
		macDraw->size.height, bitsPerComponent, bytesPerRow,
		colorspace, bitmapInfo);
	if (macDraw->context) {
	    CGContextClearRect(macDraw->context, bounds);
	}
	if (colorspace) {
	    CFRelease(colorspace);
	}
    }

    return (macDraw ? macDraw->context : NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDrawCGImage --
 * DrawCGImage --
 *
 *	Draw CG image into drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXDrawCGImage(
DrawCGImage(
    Drawable d,
    GC gc,
    CGContextRef context,
    CGImageRef image,
    unsigned long imageForeground,
    unsigned long imageBackground,
    CGRect imageBounds,
    CGRect srcBounds,
    CGRect dstBounds)
{
    MacDrawable *macDraw = (MacDrawable *)d;
    MacDrawable *macDraw = (MacDrawable *) d;

    if (macDraw && context && image) {
	CGImageRef subImage = NULL;

	if (!CGRectEqualToRect(imageBounds, srcBounds)) {
	    if (!CGRectContainsRect(imageBounds, srcBounds)) {
		TkMacOSXDbgMsg("Mismatch of sub CGImage bounds");
	    }
	    subImage = CGImageCreateWithImageInRect(image, CGRectOffset(
		    srcBounds, -imageBounds.origin.x, -imageBounds.origin.y));
	    if (subImage) {
		image = subImage;
	    }
	}
	dstBounds = CGRectOffset(dstBounds, macDraw->xOff, macDraw->yOff);

	if (CGImageIsMask(image)) {
	    /*CGContextSaveGState(context);*/
	    if (macDraw->flags & TK_IS_BW_PIXMAP) {

		/*
		 * Set fill color to black; background comes from the context,
		/* Set fill color to black, background comes from the context, or is transparent. */
		 * or is transparent.
		 */

		if (imageBackground != transparentColor) {
		if (imageBackground != TRANSPARENT_PIXEL << 24) {
		    CGContextClearRect(context, dstBounds);
		}
		CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
	    } else {
		if (imageBackground != transparentColor) {
		if (imageBackground != TRANSPARENT_PIXEL << 24) {
		    TkMacOSXSetColorInContext(gc, imageBackground, context);
		    CGContextFillRect(context, dstBounds);
		}
		TkMacOSXSetColorInContext(gc, imageForeground, context);
	    }
	}

#ifdef TK_MAC_DEBUG_IMAGE_DRAWING
	CGContextSaveGState(context);
	CGContextSetLineWidth(context, 1.0);
	CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.1);
	CGContextSetRGBFillColor(context, 0, 1, 0, 0.1);
	CGContextFillRect(context, dstBounds);
	CGContextStrokeRect(context, dstBounds);

	CGPoint p[4] = {dstBounds.origin,
	    CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMaxY(dstBounds)),
	    CGPointMake(CGRectGetMinX(dstBounds), CGRectGetMaxY(dstBounds)),
	    CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMinY(dstBounds))
	};

	CGContextStrokeLineSegments(context, p, 4);
	CGContextRestoreGState(context);
	TkMacOSXDbgMsg("Drawing CGImage at (x=%f, y=%f), (w=%f, h=%f)",
		dstBounds.origin.x, dstBounds.origin.y,
		dstBounds.size.width, dstBounds.size.height);
#else /* TK_MAC_DEBUG_IMAGE_DRAWING */
	CGContextSaveGState(context);
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414


415
416
417
418
419
420
421
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837


838
839
840
841
842
843
844
845
846







-
+







-
-
+
+







    Display *display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    XPoint *points,		/* Array of points. */
    int npoints,		/* Number of points. */
    int mode)			/* Line drawing mode. */
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int i, lw = gc->line_width;

    if (npoints < 2) {
	return BadValue;
    }

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return BadDrawable;
    }
    if (dc.context) {
	double prevx, prevy;
	double o = (lw % 2) ? .5 : 0;

	CGContextBeginPath(dc.context);
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
854
855
856
857
858
859
860











861
862
863
864
865
866
867







-
-
-
-
-
-
-
-
-
-
-







			macWin->yOff + points[i].y + o);
	    } else {
		prevx += points[i].x;
		prevy += points[i].y;
		CGContextAddLineToPoint(dc.context, prevx, prevy);
	    }
	}

        /*
         * In the case of closed polylines, the first and last points are the
         * same. We want miter or bevel join be rendered also at this point,
         * this needs telling CoreGraphics that the path is closed.
         */

        if ((points[0].x == points[npoints-1].x) &&
                (points[0].y == points[npoints-1].y)) {
            CGContextClosePath(dc.context);
        }
	CGContextStrokePath(dc.context);
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

/*
470
471
472
473
474
475
476
477

478
479
480
481
482


483
484
485
486
487
488
489
884
885
886
887
888
889
890

891
892
893
894


895
896
897
898
899
900
901
902
903







-
+



-
-
+
+







XDrawSegments(
    Display *display,
    Drawable d,
    GC gc,
    XSegment *segments,
    int nsegments)
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int i, lw = gc->line_width;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return BadDrawable;
    }
    if (dc.context) {
	double o = (lw % 2) ? .5 : 0;

	for (i = 0; i < nsegments; i++) {
	    CGContextBeginPath(dc.context);
512
513
514
515
516
517
518
519

520
521

522
523
524

525
526

527
528
529

530
531
532
533
534
535



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557

558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589

590
591
592
593
594

595
596
597
598
599



600
601
602
603
604
605
606


607
608
609
610
611
612
613

614
615
616
617
618
619
620



621
622
623
624
625
626
627





628
629
630
631
632
633
634
635
636
637
638

639
640
641

642
643
644
645
646

647
648
649
650
651
652
653



654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

693
694
695
696
697
698

699
700
701
702
703
704


705
706
707
708
709
710
711
926
927
928
929
930
931
932

933
934

935
936
937

938
939

940
941
942

943
944
945
946



947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969


970

971
972

973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004

1005
1006
1007



1008
1009
1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030


1031
1032
1033
1034
1035
1036




1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054

1055
1056
1057
1058
1059

1060
1061
1062
1063
1064



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111

1112
1113
1114
1115
1116


1117
1118
1119
1120
1121
1122
1123
1124
1125







-
+

-
+


-
+

-
+


-
+



-
-
-
+
+
+




















-
-
+
-


-


















-
+








-
+




-
+


-
-
-
+
+
+






-
+
+




-


+





-
-
+
+
+



-
-
-
-
+
+
+
+
+










-
+


-
+




-
+




-
-
-
+
+
+

















-

+



















-
+





-
+




-
-
+
+







 *
 * Side effects:
 *	Draws a filled polygon on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XFillPolygon(
    Display *display,		/* Display. */
    Display* display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    XPoint *points,		/* Array of points. */
    XPoint* points,		/* Array of points. */
    int npoints,		/* Number of points. */
    TCL_UNUSED(int),		/* Shape to draw. */
    int shape,			/* Shape to draw. */
    int mode)			/* Drawing mode. */
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int i;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	double prevx, prevy;
	double o = (gc->line_width % 2) ? .5 : 0;

	CGContextBeginPath(dc.context);
	prevx = macWin->xOff + points[0].x + o;
	prevy = macWin->yOff + points[0].y + o;
	CGContextMoveToPoint(dc.context, prevx, prevy);
	for (i = 1; i < npoints; i++) {
	    if (mode == CoordModeOrigin) {
		CGContextAddLineToPoint(dc.context,
			macWin->xOff + points[i].x + o,
			macWin->yOff + points[i].y + o);
	    } else {
		prevx += points[i].x;
		prevy += points[i].y;
		CGContextAddLineToPoint(dc.context, prevx, prevy);
	    }
	}
	(gc->fill_rule == EvenOddRule)
		? CGContextEOFillPath(dc.context)
	CGContextEOFillPath(dc.context);
		: CGContextFillPath(dc.context);
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XDrawRectangle --
 *
 *	Draws a rectangle.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws a rectangle on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XDrawRectangle(
    Display *display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    int x, int y,		/* Upper left corner. */
    unsigned int width,		/* Width & height of rect. */
    unsigned int height)
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int lw = gc->line_width;

    if (width == 0 || height == 0) {
	return BadDrawable;
	return;
    }

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0;

	rect = CGRectMake(
		macWin->xOff + x + o, macWin->yOff + y + o,
		macWin->xOff + x + o,
		macWin->yOff + y + o,
		width, height);
	CGContextStrokeRect(dc.context, rect);
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

#ifdef TK_MACOSXDRAW_UNUSED
/*
 *----------------------------------------------------------------------
 *
 * XDrawRectangles --
 *
 *	Draws the outlines of the specified rectangles as if a five-point
 *	PolyLine protocol request were specified for each rectangle:
 *	Draws the outlines of the specified rectangles as if a
 *	five-point PolyLine protocol request were specified for each
 *	rectangle:
 *
 *	    [x,y] [x+width,y] [x+width,y+height] [x,y+height] [x,y]
 *
 *	For the specified rectangles, these functions do not draw a pixel more
 *	than once. XDrawRectangles draws the rectangles in the order listed in
 *	the array. If rectangles intersect, the intersecting pixels are drawn
 *	multiple times. Draws a rectangle.
 *	For the specified rectangles, these functions do not draw a
 *	pixel more than once. XDrawRectangles draws the rectangles in
 *	the order listed in the array. If rectangles intersect, the
 *	intersecting pixels are drawn multiple times. Draws a
 *	rectangle.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws rectangles on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XDrawRectangles(
    Display *display,
    Drawable d,
    Drawable drawable,
    GC gc,
    XRectangle *rectArr,
    int nRects)
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) drawable;
    TkMacOSXDrawingContext dc;
    XRectangle * rectPtr;
    int i, lw = gc->line_width;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0;

	for (i = 0, rectPtr = rectArr; i < nRects; i++, rectPtr++) {
	    if (rectPtr->width == 0 || rectPtr->height == 0) {
		continue;
	    }
	    rect = CGRectMake(
		    macWin->xOff + rectPtr->x + o,
		    macWin->yOff + rectPtr->y + o,
		    rectPtr->width, rectPtr->height);
	    CGContextStrokeRect(dc.context, rect);
	}
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * XFillRectangles --
 *
 *	Fill multiple rectangular areas in the given drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws onto the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
XFillRectangles(
    Display *display,		/* Display. */
    Display* display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    XRectangle *rectangles,	/* Rectangle array. */
    int n_rectangles)		/* Number of rectangles. */
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    XRectangle * rectPtr;
    int i;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return BadDrawable;
    }
    if (dc.context) {
	CGRect rect;

	for (i = 0, rectPtr = rectangles; i < n_rectangles; i++, rectPtr++) {
	    if (rectPtr->width == 0 || rectPtr->height == 0) {
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791

792
793
794
795
796
797
798
799
800

801
802
803
804
805

806
807
808
809
810



811
812
813
814
815
816
817
1135
1136
1137
1138
1139
1140
1141
















































1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154

1155
1156

1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170

1171
1172
1173



1174
1175
1176
1177
1178
1179
1180
1181
1182
1183







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
+

-
+








-
+




-
+


-
-
-
+
+
+







    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDrawSolidBorder --
 *
 *	Draws a border rectangle of specified thickness inside the bounding
 *      rectangle of a Tk Window.  The border rectangle can be inset within the
 *      bounding rectangle.  For a highlight border the inset should be 0, but
 *      for a solid border around the actual window the inset should equal the
 *      thickness of the highlight border.  The color of the border rectangle
 *      is the foreground color of the graphics context passed to the function.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws a rectangular border inside the bounding rectangle of a window.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void
TkMacOSXDrawSolidBorder(
    Tk_Window tkwin,
    GC gc,
    int inset,
    int thickness)
{
    Drawable d = Tk_WindowId(tkwin);
    TkMacOSXDrawingContext dc;
    CGRect outerRect, innerRect;

    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return;
    }
    if (dc.context) {
	outerRect = CGRectMake(Tk_X(tkwin), Tk_Y(tkwin),
			       Tk_Width(tkwin), Tk_Height(tkwin));
	outerRect = CGRectInset(outerRect, inset, inset);
	innerRect = CGRectInset(outerRect, thickness, thickness);
	CGContextBeginPath(dc.context);
	CGContextAddRect(dc.context, outerRect);
	CGContextAddRect(dc.context, innerRect);
	CGContextEOFillPath(dc.context);
    }
    TkMacOSXRestoreDrawingContext(&dc);
}

/*
 *----------------------------------------------------------------------
 *
 * XDrawArc --
 *
 *	Draw an arc.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws an arc on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XDrawArc(
    Display *display,		/* Display. */
    Display* display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    int x, int y,		/* Upper left of bounding rect. */
    unsigned int width,		/* Width & height. */
    unsigned int height,
    int angle1,			/* Staring angle of arc. */
    int angle2)			/* Extent of arc. */
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int lw = gc->line_width;

    if (width == 0 || height == 0 || angle2 == 0) {
	return BadDrawable;
	return;
    }

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0;

	rect = CGRectMake(
		macWin->xOff + x + o,
833
834
835
836
837
838
839
840
841
842

843
844
845
846
847
848
849
850
851
852
853
854








855
856
857
858
859
860
861
862
863
864
865

866
867
868
869
870
871
872

873

874
875
876
877
878
879
880



881
882
883
884
885
886
887
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213







1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245



1246
1247
1248
1249
1250
1251
1252
1253
1254
1255







-


+





-
-
-
-
-
-
-
+
+
+
+
+
+
+
+










-
+







+
-
+




-
-
-
+
+
+







		    radians(-(angle1 + angle2)/64.0), angle2 > 0);
	    CGContextAddPath(dc.context, p);
	    CGPathRelease(p);
	    CGContextStrokePath(dc.context);
	}
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

#ifdef TK_MACOSXDRAW_UNUSED
/*
 *----------------------------------------------------------------------
 *
 * XDrawArcs --
 *
 *	Draws multiple circular or elliptical arcs. Each arc is specified by a
 *	rectangle and two angles. The center of the circle or ellipse is the
 *	center of the rect- angle, and the major and minor axes are specified
 *	by the width and height.  Positive angles indicate counterclock- wise
 *	motion, and negative angles indicate clockwise motion. If the magnitude
 *	of angle2 is greater than 360 degrees, XDrawArcs truncates it to 360
 *	degrees.
 *	Draws multiple circular or elliptical arcs. Each arc is
 *	specified by a rectangle and two angles. The center of the
 *	circle or ellipse is the center of the rect- angle, and the
 *	major and minor axes are specified by the width and height.
 *	Positive angles indicate counterclock- wise motion, and
 *	negative angles indicate clockwise motion. If the magnitude
 *	of angle2 is greater than 360 degrees, XDrawArcs truncates it
 *	to 360 degrees.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws an arc for each array element on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XDrawArcs(
    Display *display,
    Drawable d,
    GC gc,
    XArc *arcArr,
    int nArcs)
{

    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    XArc *arcPtr;
    int i, lw = gc->line_width;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0;

	for (i=0, arcPtr = arcArr; i < nArcs; i++, arcPtr++) {
	    if (arcPtr->width == 0 || arcPtr->height == 0
914
915
916
917
918
919
920
921
922

923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940

941
942

943
944
945
946
947
948
949
950
951

952
953
954
955
956

957
958
959
960
961



962
963
964
965
966
967
968
1282
1283
1284
1285
1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309

1310
1311
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323

1324
1325
1326



1327
1328
1329
1330
1331
1332
1333
1334
1335
1336







-

+

















-
+

-
+








-
+




-
+


-
-
-
+
+
+







		CGContextAddPath(dc.context, p);
		CGPathRelease(p);
		CGContextStrokePath(dc.context);
	    }
	}
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * XFillArc --
 *
 *	Draw a filled arc.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws a filled arc on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XFillArc(
    Display *display,		/* Display. */
    Display* display,		/* Display. */
    Drawable d,			/* Draw on this. */
    GC gc,			/* Use this GC. */
    int x, int y,		/* Upper left of bounding rect. */
    unsigned int width,		/* Width & height. */
    unsigned int height,
    int angle1,			/* Staring angle of arc. */
    int angle2)			/* Extent of arc. */
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    int lw = gc->line_width;

    if (width == 0 || height == 0 || angle2 == 0) {
	return BadDrawable;
	return;
    }

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0, u = 0;

	if (notAA(lw)) {
	    o += NON_AA_CG_OFFSET/2;
993
994
995
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034



1035
1036
1037
1038
1039
1040
1041
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386

1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399



1400
1401
1402
1403
1404
1405
1406
1407
1408
1409







-


+
















-
+







-
+




-
-
-
+
+
+







	    CGPathCloseSubpath(p);
	    CGContextAddPath(dc.context, p);
	    CGPathRelease(p);
	    CGContextFillPath(dc.context);
	}
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

#ifdef TK_MACOSXDRAW_UNUSED
/*
 *----------------------------------------------------------------------
 *
 * XFillArcs --
 *
 *	Draw a filled arc.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws a filled arc for each array element on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

int
void
XFillArcs(
    Display *display,
    Drawable d,
    GC gc,
    XArc *arcArr,
    int nArcs)
{
    MacDrawable *macWin = (MacDrawable *)d;
    MacDrawable *macWin = (MacDrawable *) d;
    TkMacOSXDrawingContext dc;
    XArc * arcPtr;
    int i, lw = gc->line_width;

    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(d, gc, &dc)) {
	return BadDrawable;
    display->request++;
    if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
	return;
    }
    if (dc.context) {
	CGRect rect;
	double o = (lw % 2) ? .5 : 0, u = 0;

	if (notAA(lw)) {
	    o += NON_AA_CG_OFFSET/2;
1075
1076
1077
1078
1079
1080
1081
















1082

1083

1084
1085
1086
1087
1088
1089
1090
1091


1092
1093
1094
1095



1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110

1111
1112
1113
1114
1115
1116
1117





1118
1119
1120

1121
1122
1123

1124
1125
1126

1127
1128
1129




1130






1131

1132
1133




1134
















1135

1136
1137
1138
1139
1140















1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153







1154
1155
1156
1157
1158










1159
1160
1161
1162
1163
1164
1165
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465

1466
1467
1468
1469
1470
1471
1472
1473
1474


1475
1476
1477
1478


1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495

1496
1497
1498





1499
1500
1501
1502
1503
1504
1505

1506



1507


1508
1509



1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

1521


1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544




1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559













1560
1561
1562
1563
1564
1565
1566





1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

+






-
-
+
+


-
-
+
+
+










-
+



-
+


-
-
-
-
-
+
+
+
+
+


-
+
-
-
-
+
-
-

+
-
-
-
+
+
+
+

+
+
+
+
+
+
-
+
-
-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







		CGContextAddPath(dc.context, p);
		CGPathRelease(p);
		CGContextFillPath(dc.context);
	    }
	}
    }
    TkMacOSXRestoreDrawingContext(&dc);
}
#endif

#ifdef TK_MACOSXDRAW_UNUSED
/*
 *----------------------------------------------------------------------
 *
 * XMaxRequestSize --
 *
 *----------------------------------------------------------------------
 */

long
XMaxRequestSize(
    Display *display)
{
    return Success;
    return (SHRT_MAX / 4);
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * TkScrollWindow --
 *
 *	Scroll a rectangle of the specified window and accumulate a damage
 *	region.
 *	Scroll a rectangle of the specified window and accumulate
 *	a damage region.
 *
 * Results:
 *	Returns 0 if the scroll generated no additional damage. Otherwise, sets
 *	the region that needs to be repainted after scrolling and returns 1.
 *	Returns 0 if the scroll genereated no additional damage.
 *	Otherwise, sets the region that needs to be repainted after
 *	scrolling and returns 1.
 *
 * Side effects:
 *	Scrolls the bits in the window.
 *
 *----------------------------------------------------------------------
 */

int
TkScrollWindow(
    Tk_Window tkwin,		/* The window to be scrolled. */
    TCL_UNUSED(GC),			/* GC for window to be scrolled. */
    GC gc,			/* GC for window to be scrolled. */
    int x, int y,		/* Position rectangle to be scrolled. */
    int width, int height,
    int dx, int dy,		/* Distance rectangle should be moved. */
    Region damageRgn)		/* Region to accumulate damage in. */
    TkRegion damageRgn)		/* Region to accumulate damage in. */
{
    Drawable drawable = Tk_WindowId(tkwin);
    MacDrawable *macDraw = (MacDrawable *)drawable;
    TKContentView *view = (TKContentView *)TkMacOSXGetNSViewForDrawable(macDraw);
    HIShapeRef srcRgn, dstRgn;
    HIMutableShapeRef dmgRgn = HIShapeCreateMutable();
    NSRect bounds, viewSrcRect, srcRect, dstRect;
    MacDrawable *macDraw = (MacDrawable *) drawable;
    TKContentView *view = (TKContentView *)TkMacOSXDrawableView(macDraw);
    CGRect srcRect, dstRect;
    HIShapeRef dmgRgn = NULL, extraRgn = NULL;
    NSRect bounds, visRect, scrollSrc, scrollDst;
    int result = 0;

    if (view) {
    if ( view ) {

  	/*
	 * Get the scroll area in NSView coordinates (origin at bottom left).
  	/*  Get the scroll area in NSView coordinates (origin at bottom left). */
	 */

  	bounds = [view bounds];
 	scrollSrc = NSMakeRect(
 	viewSrcRect = NSMakeRect(macDraw->xOff + x,
		bounds.size.height - height - (macDraw->yOff + y),
		width, height);
			       macDraw->xOff + x,
			       bounds.size.height - height - (macDraw->yOff + y),
			       width, height);
 	scrollDst = NSOffsetRect(scrollSrc, dx, -dy);

  	/* Limit scrolling to the window content area. */
 	visRect = [view visibleRect];
 	scrollSrc = NSIntersectionRect(scrollSrc, visRect);
 	scrollDst = NSIntersectionRect(scrollDst, visRect);
 	if ( !NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst) ) {

	/*
  	    /*
	 * Scroll the rectangle.
	 */
  	     * Mark the difference between source and destination as damaged.
	     * This region is described in NSView coordinates (y=0 at the bottom)
	     * and converted to Tk coordinates later.
  	     */

	    srcRect = CGRectMake(x, y, width, height);
	    dstRect = CGRectOffset(srcRect, dx, dy);

	    /* Compute the damage. */
  	    dmgRgn = HIShapeCreateMutableWithRect(&srcRect);
 	    extraRgn = HIShapeCreateWithRect(&dstRect);
 	    ChkErr(HIShapeDifference, dmgRgn, extraRgn, (HIMutableShapeRef) dmgRgn);
	    result = HIShapeIsEmpty(dmgRgn) ? 0 : 1;

	    /* Convert to Tk coordinates. */
	    TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
	    if (extraRgn) {
		CFRelease(extraRgn);
	    }

 	    /* Scroll the rectangle. */
	[view scrollRect:viewSrcRect by:NSMakeSize(dx, -dy)];
 	    [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];

	/*
	 * Compute the damage region, using Tk coordinates (origin at top left).
	 */

	    /* Shift the Tk children which meet the source rectangle. */
	    TkWindow *winPtr = (TkWindow *)tkwin;
	    TkWindow *childPtr;
	    CGRect childBounds;
	    for (childPtr = winPtr->childList; childPtr != NULL; childPtr = childPtr->nextPtr) {
		if (Tk_IsMapped(childPtr) && !Tk_IsTopLevel(childPtr)) {
		    TkMacOSXWinCGBounds(childPtr, &childBounds);
		    if (CGRectIntersectsRect(srcRect, childBounds)) {
			MacDrawable *macChild = childPtr->privatePtr;
			if (macChild) {
			    macChild->yOff += dy;
			    macChild->xOff += dx;
			    childPtr->changes.y = macChild->yOff;
			    childPtr->changes.x = macChild->xOff;
			}
	srcRect = CGRectMake(x, y, width, height);
	dstRect = CGRectOffset(srcRect, dx, dy);
	srcRgn = HIShapeCreateWithRect(&srcRect);
	dstRgn = HIShapeCreateWithRect(&dstRect);
	ChkErr(HIShapeDifference, srcRgn, dstRgn, dmgRgn);
	CFRelease(dstRgn);
	CFRelease(srcRgn);
	result = HIShapeIsEmpty(dmgRgn) ? 0 : 1;

    }

    /*
     * Convert the HIShape dmgRgn into a TkRegion and store it.
		    }
		}
	    }

	    /* Queue up Expose events for the damage region. */
	    int oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE);
	    [view generateExposeEvents:dmgRgn childrenOnly:1];
     */

    TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);

    CFRelease(dmgRgn);
	    Tcl_SetServiceMode(oldMode);
  	}
    } else {
	dmgRgn = HIShapeCreateEmpty();
	TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
    }

    if (dmgRgn) {
	CFRelease(dmgRgn);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetUpGraphicsPort --
1173
1174
1175
1176
1177
1178
1179
1180
1181


1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195

1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207

1208
1209
1210

1211
1212
1213
1214


1215
1216

1217
1218






1219
1220

1221
1222
1223


1224
1225


1226
1227
1228
1229
1230


























1231
1232
1233
1234
1235

1236
1237
1238
1239
1240

1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252

1253
1254

1255
1256
1257
1258
1259
1260
1261


1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283

1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304

1305
1306
1307
1308

1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329
1330
1331
1332
1333
1334





1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358

1359
1360


1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385


















1386
1387
1388


1389
1390
1391
1392
1393
1394
1395
1396










1397
1398
1399

1400
1401
1402
1403
1404
1405
1406
1407
1408
1409








1410
1411

1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
















1427
1428
1429
1430
1431
1432
1433
1434
1435
1436

1437
1438
1439
1440
1441

1442
1443
1444
1445
1446
1447
1448
1591
1592
1593
1594
1595
1596
1597


1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612

1613
1614
1615
1616
1617

1618


1619
1620
1621
1622

1623
1624
1625
1626
1627
1628
1629


1630
1631

1632
1633


1634
1635
1636
1637
1638
1639


1640



1641
1642


1643
1644





1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
-
+
+










-
+


-
+




-
+
-
-




-
+



+


-
-
+
+
-

+
-
-
+
+
+
+
+
+
-
-
+
-
-
-
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-

-
-
+
-

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+




-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetUpGraphicsPort(
    TCL_UNUSED(GC),			/* GC to apply to current port. */
    TCL_UNUSED(void *))
    GC gc,			/* GC to apply to current port. */
    void *destPort)
{
    Tcl_Panic("TkMacOSXSetUpGraphicsPort: Obsolete, no more QD!");
}


/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetUpDrawingContext --
 *
 *	Set up a drawing context for the given drawable from an X GC.
 *	Set up a drawing context for the given drawable and GC.
 *
 * Results:
 *	Boolean indicating whether it is ok to draw; if false, the drawing
 *	Boolean indicating whether it is ok to draw; if false, drawing
 *	context was not setup, so do not attempt to draw and do not call
 *	TkMacOSXRestoreDrawingContext().
 *
 * Side effects:
 *	May modify or create the drawable's graphics context.  May expand the
 *	None.
 *      drawable's dirty rectangle.  When the result is true The dcPtr
 *      parameter is set to reference the new or updated drawing context.
 *
 *----------------------------------------------------------------------
 */

Bool
int
TkMacOSXSetupDrawingContext(
    Drawable d,
    GC gc,
    int useCG, /* advisory only ! */
    TkMacOSXDrawingContext *dcPtr)
{
    MacDrawable *macDraw = (MacDrawable *)d;
    Bool canDraw = true;
    MacDrawable *macDraw = ((MacDrawable*)d);
    int dontDraw = 0, isWin = 0;
    TKContentView *view = nil;
    TkMacOSXDrawingContext dc = {};
    CGRect clipBounds;
    CGFloat drawingHeight;


    dc.clipRgn = TkMacOSXGetClipRgn(d);
    if (!dontDraw) {
	ClipToGC(d, gc, &dc.clipRgn);
	dontDraw = dc.clipRgn ? HIShapeIsEmpty(dc.clipRgn) : 0;
    }
#ifdef TK_MAC_DEBUG_CG
    fprintf(stderr, "TkMacOSXSetupDrawingContext: %s\n",
    if (dontDraw) {
	    macDraw->winPtr ? Tk_PathName(macDraw->winPtr) : "None");
#endif

	goto end;
    }
    /*
     * If the drawable is not a pixmap, get the associated NSView.
    if (useCG) {
	dc.context = GetCGContextForDrawable(d);
     */

    if (!(macDraw->flags & TK_IS_PIXMAP)) {
	view = (TKContentView *)TkMacOSXGetNSViewForDrawable(d);
	if (!view) {
    }
    if (!dc.context || !(macDraw->flags & TK_IS_PIXMAP)) {
	isWin = (TkMacOSXDrawableWindow(d) != nil);
    }
    if (dc.context) {
	dc.portBounds = clipBounds = CGContextGetClipBoundingBox(dc.context);
    } else if (isWin) {
	NSView *view = TkMacOSXDrawableView(macDraw);
	if (view) {
	    if (view != [NSView focusView]) {
		dc.focusLocked = [view lockFocusIfCanDraw];
		dontDraw = !dc.focusLocked;
	    } else {
		dontDraw = ![view canDraw];
	    }
	    if (dontDraw) {
		goto end;
	    }
	    [[view window] disableFlushWindow];
	    dc.view = view;
	    dc.context = [[NSGraphicsContext currentContext] graphicsPort];
	    dc.portBounds = NSRectToCGRect([view bounds]);
	    if (dc.clipRgn) {
		clipBounds = CGContextGetClipBoundingBox(dc.context);
	    }
	} else {
	    Tcl_Panic("TkMacOSXSetupDrawingContext(): "
		    "no NSView to draw into !");
	}
    }

    } else {
    /*
     * Intersect the drawable's clipping region with the region stored in the
     * X GC.  If the resulting region is empty, don't do any drawing.
     */

	Tcl_Panic("TkMacOSXSetupDrawingContext(): "
    dc.clipRgn = TkMacOSXGetClipRgn(d);
    ClipToGC(d, gc, &dc.clipRgn);
    if (dc.clipRgn && HIShapeIsEmpty(dc.clipRgn)) {
	canDraw = false;
	goto end;
    }

		"no context to draw into !");
    /*
     * If the drawable already has a CGContext, use it.  Otherwise, we must be
     * drawing to a window and we use the current context of its ContentView.
     */

    }
    dc.context = TkMacOSXGetCGContextForDrawable(d);
    if (!dc.context) {
    if (dc.context) {
	NSRect drawingBounds, currentBounds;
	dc.view = view;
	dc.context = GET_CGCONTEXT;
	if (dc.clipRgn) {
	    CGRect clipBounds;
	    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
				    .ty = [view bounds].size.height};
	CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
		.ty = dc.portBounds.size.height};
	    HIShapeGetBounds(dc.clipRgn, &clipBounds);
	    clipBounds = CGRectApplyAffineTransform(clipBounds, t);
	    drawingBounds = NSRectFromCGRect(clipBounds);
	} else {
	    drawingBounds = [view bounds];
	}

	/*
	 * We can only draw into the NSView which is the current focusView.
	 * When the current [NSView focusView] is nil, the CGContext for
	 * [NSGraphicsContext currentContext] is nil.  Otherwise the current
	 * CGContext draws into the current focusView.  An NSView is guaranteed
	 * to be the focusView when its drawRect or setFrame methods are
	 * running.  Prior to OSX 10.14 it was also possible to call the
	 * lockFocus method to force an NSView to become the current focusView.
	 * But that method was deprecated in 10.14 and so is no longer used by
	 * Tk.  Instead, if the view is not the current focusView then we add
	 * the drawing bounds to its dirty rectangle and return false.  The
	 * part of the view inside the drawing bounds will get redrawn during
	 * the next call to its drawRect method.
	 */

	dc.portBounds.origin.x += macDraw->xOff;
	if (view != [NSView focusView]) {
	    [view addTkDirtyRect:drawingBounds];
	    canDraw = false;
	    goto end;
	}

	dc.portBounds.origin.y += macDraw->yOff;
	/*
	 * Drawing will also fail when the view is the current focusView but
	 * the clipping rectangle set by drawRect does not contain the clipping
	 * region of our drawing context.  (See bug [2a61eca3a8].)  If part of
	 * the drawing bounds will be clipped then we draw whatever we can, but
	 * we also add the drawing bounds to the view's dirty rectangle so it
	 * will get redrawn in the next call to its drawRect method.
	 */

	if (!dc.focusLocked) {
	currentBounds = NSRectFromCGRect(CGContextGetClipBoundingBox(dc.context));
	if (!NSContainsRect(currentBounds, drawingBounds)) {
	    [view addTkDirtyRect:drawingBounds];
	}
    }

	    CGContextSaveGState(dc.context);
    /*
     * Finish configuring the drawing context.
     */

	}
#ifdef TK_MAC_DEBUG_CG
    fprintf(stderr, "TkMacOSXSetupDrawingContext: pushing GState for %s\n",
	    macDraw->winPtr ? Tk_PathName(macDraw->winPtr) : "None");
#endif

    CGContextSaveGState(dc.context);
    CGContextSetTextDrawingMode(dc.context, kCGTextFill);
	CGContextSetTextDrawingMode(dc.context, kCGTextFill);
    { /* Restricted scope for t needed for C++ */
	drawingHeight = view ? [view bounds].size.height :
	    CGContextGetClipBoundingBox(dc.context).size.height;
	CGAffineTransform t = {
	    .a = 1, .b = 0,
	    .c = 0, .d = -1,
	    .tx = 0,
	    .ty = drawingHeight
	};
	CGContextConcatCTM(dc.context, t);
    }
    if (dc.clipRgn) {
	if (dc.clipRgn) {

#ifdef TK_MAC_DEBUG_DRAWING
	CGContextSaveGState(dc.context);
	ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);
	CGContextSetRGBFillColor(dc.context, 1.0, 0.0, 0.0, 0.1);
	CGContextEOFillPath(dc.context);
	CGContextRestoreGState(dc.context);
	    CGContextSaveGState(dc.context);
	    ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);
	    CGContextSetRGBFillColor(dc.context, 1.0, 0.0, 0.0, 0.1);
	    CGContextEOFillPath(dc.context);
	    CGContextRestoreGState(dc.context);
#endif /* TK_MAC_DEBUG_DRAWING */

	if (!HIShapeIsRectangular(dc.clipRgn)) {

	    /*
	     * We expect the clipping path dc.clipRgn to consist of the
	     * bounding rectangle of the drawable window, together with
	     * disjoint smaller rectangles inside of it which bound its
	     * geometric children.  In that case the even-odd rule will
	     * clip to the region inside the large rectangle and outside
	     * of the smaller rectangles.
	     */

	    ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);

#ifdef TK_MAC_DEBUG_CG
	    fprintf(stderr, "Setting complex clip for %s to:\n",
		    macDraw->winPtr ? Tk_PathName(macDraw->winPtr) : "None");
	    TkMacOSXPrintRectsInRegion(dc.clipRgn);
#endif

	    CGContextEOClip(dc.context);
	} else {
	    CGRect r;
	    if (!HIShapeIsRectangular(dc.clipRgn) || !CGRectContainsRect(
	    HIShapeGetBounds(dc.clipRgn, &r);

		    *HIShapeGetBounds(dc.clipRgn, &r),
		    CGRectApplyAffineTransform(clipBounds, t))) {
#ifdef TK_MAC_DEBUG_CG
	    fprintf(stderr, "Current clip BBox is %s\n",
		    NSStringFromRect(CGContextGetClipBoundingBox(GET_CGCONTEXT)).UTF8String);
	    fprintf(stderr, "Setting clip for %s to rect %s:\n",
		    macDraw->winPtr ? Tk_PathName(macDraw->winPtr) : "None",
		    NSStringFromRect(r).UTF8String);
#endif

	    CGContextClipToRect(dc.context, r);
	}
    }
    if (gc) {
	static const CGLineCap cgCap[] = {
	    [CapNotLast] = kCGLineCapButt,
	    [CapButt] = kCGLineCapButt,
	    [CapRound] = kCGLineCapRound,
	    [CapProjecting] = kCGLineCapSquare,
	};
	static const CGLineJoin cgJoin[] = {
	    [JoinMiter] = kCGLineJoinMiter,
	    [JoinRound] = kCGLineJoinRound,
	    [JoinBevel] = kCGLineJoinBevel,
	};
	bool shouldAntialias = !notAA(gc->line_width);
	double w = gc->line_width;
		ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);
		CGContextEOClip(dc.context);
	    }
	}
	if (gc) {
	    static const CGLineCap cgCap[] = {
		[CapNotLast] = kCGLineCapButt,
		[CapButt] = kCGLineCapButt,
		[CapRound] = kCGLineCapRound,
		[CapProjecting] = kCGLineCapSquare,
	    };
	    static const CGLineJoin cgJoin[] = {
		[JoinMiter] = kCGLineJoinMiter,
		[JoinRound] = kCGLineJoinRound,
		[JoinBevel] = kCGLineJoinBevel,
	    };
	    bool shouldAntialias;
	    double w = gc->line_width;

	TkMacOSXSetColorInContext(gc, gc->foreground, dc.context);
	if (view) {
	    TkMacOSXSetColorInContext(gc, gc->foreground, dc.context);
	    if (isWin) {
	    CGSize size = NSSizeToCGSize([view bounds].size);
	    CGContextSetPatternPhase(dc.context, size);
	}
	if (gc->function != GXcopy) {
	    TkMacOSXDbgMsg("Logical functions other than GXcopy are "
			   "not supported for CG drawing!");
	}
	if (!shouldAntialias) {
		CGContextSetPatternPhase(dc.context, CGSizeMake(
			dc.portBounds.size.width, dc.portBounds.size.height));
	    }
	    if(gc->function != GXcopy) {
		TkMacOSXDbgMsg("Logical functions other than GXcopy are "
			"not supported for CG drawing!");
	    }
	    /* When should we antialias? */
	    shouldAntialias = !notAA(gc->line_width);
	    if (!shouldAntialias) {

	    /*
	     * Make non-antialiased CG drawing look more like X11.
		/* Make non-antialiased CG drawing look more like X11 */
	     */

	    w -= (gc->line_width ? NON_AA_CG_OFFSET : 0);
	}
	CGContextSetShouldAntialias(dc.context, shouldAntialias);
	CGContextSetLineWidth(dc.context, w);
	if (gc->line_style != LineSolid) {
	    size_t num = 0;
	    char *p = &gc->dashes;
	    CGFloat dashOffset = gc->dash_offset;
		w -= (gc->line_width ? NON_AA_CG_OFFSET : 0);
	    }
	    CGContextSetShouldAntialias(dc.context, shouldAntialias);
	    CGContextSetLineWidth(dc.context, w);
	    if (gc->line_style != LineSolid) {
		int num = 0;
		char *p = &(gc->dashes);
		CGFloat dashOffset = gc->dash_offset;
	    dashOffset -= (gc->line_width % 2) ? 0.5 : 0.0;
	    CGFloat lengths[10];
		CGFloat lengths[10];

	    while (p[num] != '\0' && num < 10) {
		lengths[num] = p[num];
		num++;
	    }
	    CGContextSetLineDash(dc.context, dashOffset, lengths, num);
	}
	if ((unsigned) gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
	    CGContextSetLineCap(dc.context, cgCap[(unsigned) gc->cap_style]);
	}
	if ((unsigned)gc->join_style < sizeof(cgJoin)/sizeof(CGLineJoin)) {
	    CGContextSetLineJoin(dc.context, cgJoin[(unsigned) gc->join_style]);
	}
    }

		while (p[num] != '\0' && num < 10) {
		    lengths[num] = p[num];
		    num++;
		}
		CGContextSetLineDash(dc.context, dashOffset, lengths, num);
	    }
	    if ((unsigned)gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
		CGContextSetLineCap(dc.context,
			cgCap[(unsigned)gc->cap_style]);
	    }
	    if ((unsigned)gc->join_style < sizeof(cgJoin)/sizeof(CGLineJoin)) {
		CGContextSetLineJoin(dc.context,
			cgJoin[(unsigned)gc->join_style]);
	    }
	}
    }
end:

#ifdef TK_MAC_DEBUG_DRAWING
    if (!canDraw && macDraw->winPtr != NULL) {
	fprintf(stderr, "Cannot draw in %s - postponing.\n",
		Tk_PathName(macDraw->winPtr));
    }
#endif

    if (!canDraw && dc.clipRgn) {
    if (dontDraw && dc.clipRgn) {
	CFRelease(dc.clipRgn);
	dc.clipRgn = NULL;
    }
    *dcPtr = dc;
    return canDraw;
    return !dontDraw;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXRestoreDrawingContext --
 *
1459
1460
1461
1462
1463
1464
1465





1466
1467


1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480

1481
1482
1483
1484
1485
1486
1487
1488
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







+
+
+
+
+
-
-
+
+
-
-
-
-



-

-


-
+
-








void
TkMacOSXRestoreDrawingContext(
    TkMacOSXDrawingContext *dcPtr)
{
    if (dcPtr->context) {
	CGContextSynchronize(dcPtr->context);
	[[dcPtr->view window] setViewsNeedDisplay:YES];
	[[dcPtr->view window] enableFlushWindow];
	if (dcPtr->focusLocked) {
	    [dcPtr->view unlockFocus];
	} else {
	CGContextRestoreGState(dcPtr->context);

	    CGContextRestoreGState(dcPtr->context);
	}
#ifdef TK_MAC_DEBUG_CG
	fprintf(stderr, "TkMacOSXRestoreDrawingContext: popped GState\n");
#endif

    }
    if (dcPtr->clipRgn) {
	CFRelease(dcPtr->clipRgn);
	dcPtr->clipRgn = NULL;
    }

#ifdef TK_MAC_DEBUG
    bzero(dcPtr, sizeof(TkMacOSXDrawingContext));
#endif
#endif /* TK_MAC_DEBUG */

}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetClipRgn --
 *
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
1513
1514



1515
1516
1517
1518
1519
1520
1521
1522









1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536























1537

1538
1539
1540


1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553


1554
1555
1556
1557
1558


1559
1560
1561
1562
1563

1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577











1578
1579
1580
1581
1582
1583
1584
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







-
+






-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
-
+
+











-
-
+
+




-
+
+





+














+
+
+
+
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

HIShapeRef
TkMacOSXGetClipRgn(
    Drawable drawable)		/* Drawable. */
{
    MacDrawable *macDraw = (MacDrawable *)drawable;
    MacDrawable *macDraw = (MacDrawable *) drawable;
    HIShapeRef clipRgn = NULL;

    if (macDraw->winPtr && macDraw->flags & TK_CLIP_INVALID) {
	TkMacOSXUpdateClipRgn(macDraw->winPtr);
#ifdef TK_MAC_DEBUG_DRAWING
	TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName);

	NSView *view = TkMacOSXGetNSViewForDrawable(macDraw);
	CGContextRef context = GET_CGCONTEXT;
	NSView *view = TkMacOSXDrawableView(macDraw);
	if ([view lockFocusIfCanDraw]) {
	    CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

	CGContextSaveGState(context);
	CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
	      -1.0, 0.0, [view bounds].size.height));
	ChkErr(HIShapeReplacePathInCGContext, macDraw->visRgn, context);
	CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.1);
	CGContextEOFillPath(context);
	CGContextRestoreGState(context);
	    CGContextSaveGState(context);
	    CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
		    -1.0, 0.0, [view bounds].size.height));
	    ChkErr(HIShapeReplacePathInCGContext, macDraw->visRgn, context);
	    CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.1);
	    CGContextEOFillPath(context);
	    CGContextRestoreGState(context);
	    [view unlockFocus];
	}
#endif /* TK_MAC_DEBUG_DRAWING */
    }

    if (macDraw->drawRgn) {
	clipRgn = HIShapeCreateCopy(macDraw->drawRgn);
    } else if (macDraw->visRgn) {
	clipRgn = HIShapeCreateCopy(macDraw->visRgn);
    }
    return clipRgn;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetUpClippingRgn --
 *
 *	Set up the clipping region so that drawing only occurs on the
 *	specified X subwindow.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetUpClippingRgn(
    Drawable drawable)		/* Drawable to update. */
{
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_ClipDrawableToRect --
 * TkpClipDrawableToRect --
 *
 *	Clip all drawing into the drawable d to the given rectangle. If width
 *	or height are negative, reset to no clipping.
 *	Clip all drawing into the drawable d to the given rectangle.
 *	If width or height are negative, reset to no clipping.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Subsequent drawing into d is offset and clipped as specified.
 *
 *----------------------------------------------------------------------
 */

void
Tk_ClipDrawableToRect(
    TCL_UNUSED(Display *),
TkpClipDrawableToRect(
    Display *display,
    Drawable d,
    int x, int y,
    int width, int height)
{
    MacDrawable *macDraw = (MacDrawable *)d;
    MacDrawable *macDraw = (MacDrawable *) d;
    NSView *view = TkMacOSXDrawableView(macDraw);

    if (macDraw->drawRgn) {
	CFRelease(macDraw->drawRgn);
	macDraw->drawRgn = NULL;
    }

    if (width >= 0 && height >= 0) {
	CGRect clipRect = CGRectMake(x + macDraw->xOff, y + macDraw->yOff,
		width, height);
	HIShapeRef drawRgn = HIShapeCreateWithRect(&clipRect);

	if (macDraw->winPtr && macDraw->flags & TK_CLIP_INVALID) {
	    TkMacOSXUpdateClipRgn(macDraw->winPtr);
	}
	if (macDraw->visRgn) {
	    macDraw->drawRgn = HIShapeCreateIntersection(macDraw->visRgn,
		    drawRgn);
	    CFRelease(drawRgn);
	} else {
	    macDraw->drawRgn = drawRgn;
	}
	if (view && view != [NSView focusView] && [view lockFocusIfCanDraw]) {
	    clipRect.origin.y = [view bounds].size.height -
		    (clipRect.origin.y + clipRect.size.height);
	    NSRectClip(NSRectFromCGRect(clipRect));
	    macDraw->flags |= TK_FOCUSED_VIEW;
	}
    } else {
	if (view && (macDraw->flags & TK_FOCUSED_VIEW)) {
	    [view unlockFocus];
	    macDraw->flags &= ~TK_FOCUSED_VIEW;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608




1609
1610
1611

1612
1613
1614
1615
1616
1617
1618
1619
1620

1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631




1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645


1646
1647
1648
1649
1650
1651
1652
1653

1654
1655
1656


1657
1658
1659
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
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







-
-
-
-
+
+
+
+


-
+








-
+








-
-
-
+
+
+
+












-
-
+
+







-
+

-
-
+
+

-
-
-
+
+
+







-
-
+
+





-
+




















-
+

-
-
+
+











-
+

-

















-
-
-
+
+
+
+
+










static void
ClipToGC(
    Drawable d,
    GC gc,
    HIShapeRef *clipRgnPtr) /* must point to initialized variable */
{
    if (gc && gc->clip_mask &&
	    ((TkpClipMask *)gc->clip_mask)->type == TKP_CLIP_REGION) {
	Region gcClip = ((TkpClipMask *)gc->clip_mask)->value.region;
	int xOffset = ((MacDrawable *)d)->xOff + gc->clip_x_origin;
	int yOffset = ((MacDrawable *)d)->yOff + gc->clip_y_origin;
	    ((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) {
	TkRegion gcClip = ((TkpClipMask*)gc->clip_mask)->value.region;
	int xOffset = ((MacDrawable *) d)->xOff + gc->clip_x_origin;
	int yOffset = ((MacDrawable *) d)->yOff + gc->clip_y_origin;
	HIShapeRef clipRgn = *clipRgnPtr, gcClipRgn;

	XOffsetRegion(gcClip, xOffset, yOffset);
	TkMacOSXOffsetRegion(gcClip, xOffset, yOffset);
	gcClipRgn = TkMacOSXGetNativeRegion(gcClip);
	if (clipRgn) {
	    *clipRgnPtr = HIShapeCreateIntersection(gcClipRgn, clipRgn);
	    CFRelease(clipRgn);
	} else {
	    *clipRgnPtr = HIShapeCreateCopy(gcClipRgn);
	}
	CFRelease(gcClipRgn);
	XOffsetRegion(gcClip, -xOffset, -yOffset);
	TkMacOSXOffsetRegion(gcClip, -xOffset, -yOffset);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXMakeStippleMap --
 *
 *	Given a drawable and a stipple pattern this function draws the pattern
 *	repeatedly over the drawable. The drawable can then be used as a mask
 *	for bit-bliting a stipple pattern over an object.
 *	Given a drawable and a stipple pattern this function draws the
 *	pattern repeatedly over the drawable. The drawable can then
 *	be used as a mask for bit-bliting a stipple pattern over an
 *	object.
 *
 * Results:
 *	A BitMap data structure.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
TkMacOSXMakeStippleMap(
    TCL_UNUSED(Drawable),	/* Window to apply stipple. */
    TCL_UNUSED(Drawable))	/* The stipple pattern. */
    Drawable drawable,		/* Window to apply stipple. */
    Drawable stipple)		/* The stipple pattern. */
{
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DrawHighlightBorder --
 * TkpDrawHighlightBorder --
 *
 *	This procedure draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus.
 *	This procedure draws a rectangular ring around the outside of
 *	a widget to indicate that it has received the input focus.
 *
 *	On the Macintosh, this puts a 1 pixel border in the bgGC color between
 *	the widget and the focus ring, except in the case where highlightWidth
 *	is 1, in which case the border is left out.
 *	On the Macintosh, this puts a 1 pixel border in the bgGC color
 *	between the widget and the focus ring, except in the case where
 *	highlightWidth is 1, in which case the border is left out.
 *
 *	For proper Mac L&F, use highlightWidth of 3.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
 *	to the outer area of "tkwin".
 *	A rectangle "width" pixels wide is drawn in "drawable",
 *	corresponding to the outer area of "tkwin".
 *
 *----------------------------------------------------------------------
 */

void
Tk_DrawHighlightBorder (
TkpDrawHighlightBorder (
    Tk_Window tkwin,
    GC fgGC,
    GC bgGC,
    int highlightWidth,
    Drawable drawable)
{
    if (highlightWidth == 1) {
	TkDrawInsetFocusHighlight (tkwin, fgGC, highlightWidth, drawable, 0);
    } else {
	TkDrawInsetFocusHighlight (tkwin, bgGC, highlightWidth, drawable, 0);
	if (fgGC != bgGC) {
	    TkDrawInsetFocusHighlight (tkwin, fgGC, highlightWidth - 1,
		    drawable, 0);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDrawFrameEx --
 * TkpDrawFrame --
 *
 *	This procedure draws the rectangular frame area. If the user has
 *	requested themeing, it draws with the background theme.
 *	This procedure draws the rectangular frame area. If the user
 *	has requested themeing, it draws with the background theme.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws inside the tkwin area.
 *
 *----------------------------------------------------------------------
 */

void
TkpDrawFrameEx(
TkpDrawFrame(
    Tk_Window tkwin,
    Drawable drawable,
    Tk_3DBorder border,
    int highlightWidth,
    int borderWidth,
    int relief)
{
    if (useThemedToplevel && Tk_IsTopLevel(tkwin)) {
	static Tk_3DBorder themedBorder = NULL;

	if (!themedBorder) {
	    themedBorder = Tk_Get3DBorder(NULL, tkwin,
		    "systemWindowHeaderBackground");
	}
	if (themedBorder) {
	    border = themedBorder;
	}
    }

    Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth,
	    highlightWidth, Tk_Width(tkwin) - 2 * highlightWidth,
	    Tk_Height(tkwin) - 2 * highlightWidth, borderWidth, relief);
    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
	    border, highlightWidth, highlightWidth,
	    Tk_Width(tkwin) - 2 * highlightWidth,
	    Tk_Height(tkwin) - 2 * highlightWidth,
	    borderWidth, relief);
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXEmbed.c.

1
2
3
4
5
6
7
8
9
10
11
12



13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19









-
-
-
+
+
+







/*
 * tkMacOSXEmbed.c --
 *
 *	This file contains platform-specific procedures for theMac to provide
 *	basic operations needed for application embedding (where one
 *	application can use as its main window an internal window from some
 *	other application). Currently only Toplevel embedding within the same
 *	Tk application is allowed on the Macintosh.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkBusy.h"
39
40
41
42
43
44
45





46
47
48
49
50
51
52
53
54




55
56
57
58

59
60
61
62
63




































64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80



81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55




56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118



119
120
121
122
123

124
125
126

127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144







+
+
+
+
+





-
-
-
-
+
+
+
+



-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+













-
-
-
+
+
+


-



-
+









-
+







    struct Container *nextPtr;	/* Next in list of all containers in this
				 * process. */
} Container;

static Container *firstContainerPtr = NULL;
				/* First in list of all containers managed by
				 * this process. */
/*
 * Globals defined in this file:
 */

TkMacOSXEmbedHandler *tkMacOSXEmbedHandler = NULL;

/*
 * Prototypes for static procedures defined in this file:
 */

static void	ContainerEventProc(void *clientData, XEvent *eventPtr);
static void	EmbeddedEventProc(void *clientData, XEvent *eventPtr);
static void	EmbedActivateProc(void *clientData, XEvent *eventPtr);
static void	EmbedFocusProc(void *clientData, XEvent *eventPtr);
static void	ContainerEventProc(ClientData clientData, XEvent *eventPtr);
static void	EmbeddedEventProc(ClientData clientData, XEvent *eventPtr);
static void	EmbedActivateProc(ClientData clientData, XEvent *eventPtr);
static void	EmbedFocusProc(ClientData clientData, XEvent *eventPtr);
static void	EmbedGeometryRequest(Container *containerPtr, int width,
		    int height);
static void	EmbedSendConfigure(Container *containerPtr);
static void	EmbedStructureProc(void *clientData, XEvent *eventPtr);
static void	EmbedStructureProc(ClientData clientData, XEvent *eventPtr);
static void	EmbedWindowDeleted(TkWindow *winPtr);

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXSetEmbedHandler --
 *
 *	Registers a handler for an in process form of embedding, like Netscape
 *	plugins, where Tk is loaded into the process, but does not control the
 *	main window
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The embed handler is set.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MacOSXSetEmbedHandler(
    Tk_MacOSXEmbedRegisterWinProc *registerWinProc,
    Tk_MacOSXEmbedGetGrafPortProc *getPortProc,
    Tk_MacOSXEmbedMakeContainerExistProc *containerExistProc,
    Tk_MacOSXEmbedGetClipProc *getClipProc,
    Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc)
{
    if (tkMacOSXEmbedHandler == NULL) {
	tkMacOSXEmbedHandler = ckalloc(sizeof(TkMacOSXEmbedHandler));
    }
    tkMacOSXEmbedHandler->registerWinProc = registerWinProc;
    tkMacOSXEmbedHandler->getPortProc = getPortProc;
    tkMacOSXEmbedHandler->containerExistProc = containerExistProc;
    tkMacOSXEmbedHandler->getClipProc = getClipProc;
    tkMacOSXEmbedHandler->getOffsetProc = getOffsetProc;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeWindow --
 * TkpMakeWindow --
 *
 *	Creates an X Window (Mac subwindow).
 *
 * Results:
 *	The window id is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Window
Tk_MakeWindow(
    Tk_Window tkwin,
    TCL_UNUSED(Window))
TkpMakeWindow(
    TkWindow *winPtr,
    Window parent)
{
    MacDrawable *macWin;
    TkWindow *winPtr = (TkWindow *)tkwin;

    /*
     * If this window is marked as embedded then the window structure should
     * have already been created in the Tk_UseWindow function.
     * have already been created in the TkpUseWindow function.
     */

    if (Tk_IsEmbedded(winPtr)) {
	macWin = winPtr->privatePtr;
    } else {
	/*
	 * Allocate sub window
	 */

	macWin = (MacDrawable *)ckalloc(sizeof(MacDrawable));
	macWin = ckalloc(sizeof(MacDrawable));
	if (macWin == NULL) {
	    winPtr->privatePtr = NULL;
	    return None;
	}
	macWin->winPtr = winPtr;
	winPtr->privatePtr = macWin;
	macWin->visRgn = NULL;
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250



251
252
253






254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274
275










276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295



































296
297
298
299
300
301






302
303
304
305
306




307
308
309


310
311
312
313
314




315
316
317



318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274








275
276
277
278
279
280
281
282
283
284
285
286



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378






379
380
381
382
383
384
385




386
387
388
389
390


391
392
393




394
395
396
397
398


399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446







-
+



















-
+














-
+


















-
-
-
-
-
-
-
-
+








+
+
+
-
-
-
+
+
+
+
+
+















-
+






+
+
+
+
+
+
+
+
+
+











-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+
+







-
+
















-
+












-
+







    }
    return code;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_UseWindow --
 * TkpUseWindow --
 *
 *	This procedure causes a Tk window to use a given X window as its
 *	parent window, rather than the root window for the screen. It is
 *	invoked by an embedded application to specify the window in which it
 *	is embedded.
 *
 * Results:
 *	The return value is normally TCL_OK. If an error occurs (such as
 *	string not being a valid window spec), then the return value is
 *	TCL_ERROR and an error message is left in the interp's result if
 *	interp is non-NULL.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_UseWindow(
TkpUseWindow(
    Tcl_Interp *interp,		/* If not NULL, used for error reporting if
				 * string is bogus. */
    Tk_Window tkwin,		/* Tk window that does not yet have an
				 * associated X window. */
    const char *string)		/* String identifying an X window to use for
				 * tkwin; must be an integer value. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *usePtr;
    MacDrawable *parent, *macWin;
    Container *containerPtr;

    if (winPtr->window != None) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't modify container after widget is created", TCL_INDEX_NONE));
		"can't modify container after widget is created", -1));
	Tcl_SetErrorCode(interp, "TK", "EMBED", "POST_CREATE", NULL);
	return TCL_ERROR;
    }

    /*
     * Decode the container window ID, and look for it among the list of
     * available containers.
     *
     * N.B. For now, we are limiting the containers to be in the same Tk
     * application as tkwin, since otherwise they would not be in our list of
     * containers.
     */

    if (TkpScanWindowId(interp, string, (Window *)&parent) != TCL_OK) {
	return TCL_ERROR;
    }

    usePtr = (TkWindow *) Tk_IdToWindow(winPtr->display, (Window) parent);
    if (usePtr == NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't create child of window \"%s\"", string));
	    Tcl_SetErrorCode(interp, "TK", "EMBED", "NO_TARGET", NULL);
	}
	return TCL_ERROR;
    } else if (!(usePtr->flags & TK_CONTAINER)) {
    if (usePtr != NULL && !(usePtr->flags & TK_CONTAINER)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window \"%s\" doesn't have -container option set",
		usePtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "EMBED", "CONTAINER", NULL);
	return TCL_ERROR;
    }

    /*
     * The code below can probably be simplified given we have already
     * discovered 'usePtr' above.
     */
     * Since we do not allow embedding into windows belonging to a different
     * process, we know that a container will exist showing the parent window
     * as the parent.  This loop finds that container.

    /*
     * Save information about the container and the embedded window in a
     * Container structure. Currently, there must already be an existing
     * Container structure, since we only allow the case where both container
     * and embedded app. are in the same process.
     */

    for (containerPtr = firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if (containerPtr->parent == (Window) parent) {
	    winPtr->flags |= TK_BOTH_HALVES;
	    containerPtr->parentPtr->flags |= TK_BOTH_HALVES;
	    break;
	}
    }

    /*
     * Make the embedded window.
     */

    macWin = (MacDrawable *)ckalloc(sizeof(MacDrawable));
    macWin = ckalloc(sizeof(MacDrawable));
    if (macWin == NULL) {
	winPtr->privatePtr = NULL;
	return TCL_ERROR;
    }

    macWin->winPtr = winPtr;
    winPtr->privatePtr = macWin;

    /*
     * The grafPtr will be NULL for a Tk in Tk embedded window. It is none of
     * our business what it is for a Tk not in Tk embedded window, but we will
     * initialize it to NULL, and let the registerWinProc set it. In any case,
     * you must always use TkMacOSXGetDrawablePort to get the portPtr. It will
     * correctly find the container's port.
     */

    macWin->view = nil;
    macWin->context = NULL;
    macWin->size = CGSizeZero;
    macWin->visRgn = NULL;
    macWin->aboveVisRgn = NULL;
    macWin->drawRgn = NULL;
    macWin->referenceCount = 0;
    macWin->flags = TK_CLIP_INVALID;
    macWin->toplevel = macWin;
    macWin->toplevel->referenceCount++;

    winPtr->privatePtr = macWin;
    winPtr->flags |= TK_EMBEDDED;

    /*
     * Make a copy of the TK_EMBEDDED flag, since sometimes we need this to
     * get the port after the TkWindow structure has been freed.
     */

    macWin->flags |= TK_EMBEDDED;

    /*
     * Now check whether it is embedded in another Tk widget. If not (the
     * first case below) we see if there is an in-process embedding handler
     * registered, and if so, let that fill in the rest of the macWin.
     */

    if (containerPtr == NULL) {
	/*
	 * If someone has registered an in-process embedding handler, then
	 * see if it can handle this window...
	 */

	if (tkMacOSXEmbedHandler == NULL ||
		tkMacOSXEmbedHandler->registerWinProc((long) parent,
		(Tk_Window) winPtr) != TCL_OK) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "The window ID %s does not correspond to a valid Tk Window",
		    string));
	    Tcl_SetErrorCode(interp, "TK", "EMBED", "HANDLE", NULL);
	    return TCL_ERROR;
	}

	containerPtr = ckalloc(sizeof(Container));

	containerPtr->parentPtr = NULL;
	containerPtr->embedded = (Window) macWin;
	containerPtr->embeddedPtr = macWin->winPtr;
	containerPtr->nextPtr = firstContainerPtr;
	firstContainerPtr = containerPtr;
    } else {
	/*
	 * The window is embedded in another Tk window.
	 */

    macWin->xOff = parent->winPtr->privatePtr->xOff +
	    parent->winPtr->changes.border_width +
	    winPtr->changes.x;
    macWin->yOff = parent->winPtr->privatePtr->yOff +
	    parent->winPtr->changes.border_width +
	    winPtr->changes.y;
	macWin->xOff = parent->winPtr->privatePtr->xOff +
		parent->winPtr->changes.border_width +
		winPtr->changes.x;
	macWin->yOff = parent->winPtr->privatePtr->yOff +
		parent->winPtr->changes.border_width +
		winPtr->changes.y;

    /*
     * Finish filling up the container structure with the embedded window's
     * information.
     */
	/*
	 * Finish filling up the container structure with the embedded
	 * window's information.
	 */

    containerPtr->embedded = (Window) macWin;
    containerPtr->embeddedPtr = macWin->winPtr;
	containerPtr->embedded = (Window) macWin;
	containerPtr->embeddedPtr = macWin->winPtr;

    /*
     * Create an event handler to clean up the Container structure when
     * tkwin is eventually deleted.
     */
	/*
	 * Create an event handler to clean up the Container structure when
	 * tkwin is eventually deleted.
	 */

    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
	    EmbeddedEventProc, winPtr);
	Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc,
		winPtr);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeContainer --
 * TkpMakeContainer --
 *
 *	This procedure is called to indicate that a particular window will be
 *	a container for an embedded application. This changes certain aspects
 *	of the window's behavior, such as whether it will receive events
 *	anymore.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MakeContainer(
TkpMakeContainer(
    Tk_Window tkwin)		/* Token for a window that is about to become
				 * a container. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    Container *containerPtr;

    /*
     * Register the window as a container so that, for example, we can make
     * sure the argument to -use is valid.
     */

    Tk_MakeWindowExist(tkwin);
    containerPtr = (Container *)ckalloc(sizeof(Container));
    containerPtr = ckalloc(sizeof(Container));
    containerPtr->parent = Tk_WindowId(tkwin);
    containerPtr->parentPtr = winPtr;
    containerPtr->embedded = None;
    containerPtr->embeddedPtr = NULL;
    containerPtr->nextPtr = firstContainerPtr;
    firstContainerPtr = containerPtr;
    winPtr->flags |= TK_CONTAINER;
402
403
404
405
406
407
408
409

410
411
412
413

414
415
416
417
418
419
420
486
487
488
489
490
491
492

493
494
495
496

497
498
499
500
501
502
503
504







-
+



-
+







    TkWindow *winPtr)		/* Tk's structure for an embedded window. */
{
    Container *containerPtr;

    for (containerPtr = firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if (containerPtr->embeddedPtr == winPtr) {
	    return (MacDrawable *)containerPtr->parent;
	    return (MacDrawable *) containerPtr->parent;
	}
    }
    Tcl_Panic("TkMacOSXContainerId couldn't find window");
    return NULL;
    return None;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetHostToplevel --
 *
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

448
449
450
451
452



453
454
455
456
457
458
459
460
461
462



463
464
465
466
467
468
469
516
517
518
519
520
521
522




523
524
525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548
549
550
551
552
553
554







-
-
-
-




-
+





+
+
+









-
+
+
+








MacDrawable *
TkMacOSXGetHostToplevel(
    TkWindow *winPtr)		/* Tk's structure for a window. */
{
    TkWindow *contWinPtr, *topWinPtr;

    if (!(winPtr && winPtr->privatePtr)) {
	return NULL;
    }

    topWinPtr = winPtr->privatePtr->toplevel->winPtr;
    if (!Tk_IsEmbedded(topWinPtr)) {
	return winPtr->privatePtr->toplevel;
    }
    contWinPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)topWinPtr);
    contWinPtr = TkpGetOtherWindow(topWinPtr);

    /*
     * TODO: Here we should handle out of process embedding.
     */

    if (contWinPtr == NULL) {
	return None;
    }
    return TkMacOSXGetHostToplevel(contWinPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpClaimFocus --
 *
 *	This procedure is invoked when someone asks for the input focus to be
 *	put on a window in an embedded application.
 *	put on a window in an embedded application, but the application
 *	doesn't currently have the focus. It requests the input focus from the
 *	container application.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The input focus may change.
 *
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+







    event.xfocus.type = FocusIn;
    event.xfocus.serial = LastKnownRequestProcessed(topLevelPtr->display);
    event.xfocus.send_event = 1;
    event.xfocus.display = topLevelPtr->display;
    event.xfocus.window = containerPtr->parent;
    event.xfocus.mode = EMBEDDED_APP_WANTS_FOCUS;
    event.xfocus.detail = force;
    Tk_HandleEvent(&event);
    Tk_QueueWindowEvent(&event,TCL_QUEUE_TAIL);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpTestembedCmd --
 *
516
517
518
519
520
521
522
523

524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578

579
580


581
582
583
584



585
586
587
588
589



590
591
592
593
594
595
596
597
601
602
603
604
605
606
607

608
609

610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625









626





627
628
629


630
631
632
633
634






635

636
637
638
639
640

641


642
643




644
645
646





647
648
649

650
651
652
653
654
655
656







-
+

-
+






-









-
-
-
-
-
-
-
-
-

-
-
-
-
-



-
-
+




-
-
-
-
-
-
+
-





-
+
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkpTestembedCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    int all;
    Container *containerPtr;
    Tcl_DString dString;
    char buffer[50];
    Tcl_Interp *embeddedInterp = NULL, *parentInterp = NULL;

    if ((objc > 1) && (strcmp(Tcl_GetString(objv[1]), "all") == 0)) {
	all = 1;
    } else {
	all = 0;
    }
    Tcl_DStringInit(&dString);
    for (containerPtr = firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if (containerPtr->embeddedPtr != NULL) {
	    embeddedInterp = containerPtr->embeddedPtr->mainPtr->interp;
	}
	if (containerPtr->parentPtr != NULL) {
	    parentInterp = containerPtr->parentPtr->mainPtr->interp;
	}
	if (embeddedInterp != interp && parentInterp != interp) {
	    continue;
	}
	Tcl_DStringStartSublist(&dString);

	/*
	 * Parent id
	 */

	if (containerPtr->parent == None) {
	    Tcl_DStringAppendElement(&dString, "");
	} else if (all) {
	    snprintf(buffer, sizeof(buffer), "0x%" TCL_Z_MODIFIER "x",
		    (size_t) containerPtr->parent);
	    sprintf(buffer, "0x%x", (int) containerPtr->parent);
	    Tcl_DStringAppendElement(&dString, buffer);
	} else {
	    Tcl_DStringAppendElement(&dString, "XXX");
	}

	/*
	 * Parent pathName
	 */

	if (containerPtr->parentPtr == NULL ||
	if (containerPtr->parentPtr == NULL) {
	    parentInterp != interp) {
	    Tcl_DStringAppendElement(&dString, "");
	} else {
	    Tcl_DStringAppendElement(&dString,
		    containerPtr->parentPtr->pathName);
	}

	if (containerPtr->embedded == None) {
	/*
	 * On X11 embedded is a wrapper, which does not exist on macOS.
	    Tcl_DStringAppendElement(&dString, "");
	} else if (all) {
	 */

	Tcl_DStringAppendElement(&dString, "");

	    sprintf(buffer, "0x%x", (int) containerPtr->embedded);
	    Tcl_DStringAppendElement(&dString, buffer);
	} else {
	/*
	 * Embedded window pathName
	 */

	if (containerPtr->embeddedPtr == NULL ||
	    Tcl_DStringAppendElement(&dString, "XXX");
	}
	if (containerPtr->embeddedPtr == NULL) {
	    embeddedInterp != interp) {
	    Tcl_DStringAppendElement(&dString, "");
	} else {
	    Tcl_DStringAppendElement(&dString,
		    containerPtr->embeddedPtr->pathName);
	}
	Tcl_DStringEndSublist(&dString);
    }
619
620
621
622
623
624
625
626

627
628

629
630
631
632
633
634
635
636
637

638
639
640
641
642
643

644
645
646
647
648
649
650
651
652
653
654
655



656
657
658
659
660
661

662
663
664
665

666
667
668
669
670
671
672
673
674




675
676
677
678
679
680
681
678
679
680
681
682
683
684

685
686

687
688
689
690
691
692
693
694
695

696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711



712
713
714
715
716
717
718
719

720
721
722
723

724
725
726
727
728
729




730
731
732
733
734
735
736
737
738
739
740







-
+

-
+








-
+





-
+









-
-
-
+
+
+





-
+



-
+





-
-
-
-
+
+
+
+







 *	The event may get sent to a different application.
 *
 *----------------------------------------------------------------------
 */

void
TkpRedirectKeyEvent(
    TCL_UNUSED(TkWindow *),		/* Window to which the event was originally
    TkWindow *winPtr,		/* Window to which the event was originally
				 * reported. */
    TCL_UNUSED(XEvent *))		/* X event to redirect (should be KeyPress or
    XEvent *eventPtr)		/* X event to redirect (should be KeyPress or
				 * KeyRelease). */
{
    /* TODO: Implement this or decide it definitely needs no implementation */
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOtherWindow --
 * TkpGetOtherWindow --
 *
 *	If both the container and embedded window are in the same process,
 *	this procedure will return either one, given the other.
 *
 * Results:
 *	If tkwin is a container, the return value is the token for the
 *	If winPtr is a container, the return value is the token for the
 *	embedded window, and vice versa. If the "other" window isn't in this
 *	process, NULL is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_GetOtherWindow(
    Tk_Window tkwin)		/* Tk's structure for a container or embedded
TkWindow *
TkpGetOtherWindow(
    TkWindow *winPtr)		/* Tk's structure for a container or embedded
				 * window. */
{
    Container *containerPtr;

    /*
     * Tk_GetOtherWindow returns NULL if both windows are not in the same
     * TkpGetOtherWindow returns NULL if both windows are not in the same
     * process...
     */

    if (!(tkwin && (((TkWindow*)tkwin)->flags & TK_BOTH_HALVES))) {
    if (!(winPtr->flags & TK_BOTH_HALVES)) {
	return NULL;
    }

    for (containerPtr = firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if ((Tk_Window)containerPtr->embeddedPtr == tkwin) {
	    return (Tk_Window)containerPtr->parentPtr;
	} else if ((Tk_Window)containerPtr->parentPtr == tkwin) {
	    return (Tk_Window)containerPtr->embeddedPtr;
	if (containerPtr->embeddedPtr == winPtr) {
	    return containerPtr->parentPtr;
	} else if (containerPtr->parentPtr == winPtr) {
	    return containerPtr->embeddedPtr;
	}
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
694
695
696
697
698
699
700
701

702
703
704

705
706
707
708
709
710
711
753
754
755
756
757
758
759

760
761
762

763
764
765
766
767
768
769
770







-
+


-
+







 *	destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
EmbeddedEventProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	EmbedWindowDeleted(winPtr);
    }
}

/*
729
730
731
732
733
734
735
736

737
738
739

740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
788
789
790
791
792
793
794

795
796
797

798
799
800
801








802
803
804
805
806
807
808







-
+


-
+



-
-
-
-
-
-
-
-







 *	geometry information gets set for the container window.
 *
 *----------------------------------------------------------------------
 */

static void
ContainerEventProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    Container *containerPtr;
    Tk_ErrorHandler errHandler;

    if (!firstContainerPtr) {
	/*
	 * When the interpreter is being dismantled this can be nil.
	 */

	return;
    }

    /*
     * Ignore any X protocol errors that happen in this procedure (almost any
     * operation could fail, for example, if the embedded application has
     * deleted its window).
     */

    errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1,
806
807
808
809
810
811
812
813

814
815
816
817
818

819
820
821
822
823
824
825
857
858
859
860
861
862
863

864


865
866

867
868
869
870
871
872
873
874







-
+
-
-


-
+







	 * the screen.
	 */

	XMapWindow(eventPtr->xmaprequest.display,
		eventPtr->xmaprequest.window);
    } else if (eventPtr->type == DestroyNotify) {
	/*
	 * It is not clear whether the container should be destroyed
	 * The embedded application is gone. Destroy the container window.
	 * when an embedded window is destroyed.  See ticket [67384bce7d].
	 * Here we are following unix, by destroying the container.
	 */

	Tk_DestroyWindow((Tk_Window)winPtr);
	Tk_DestroyWindow((Tk_Window) winPtr);
    }
    Tk_DeleteErrorHandler(errHandler);
}

/*
 *----------------------------------------------------------------------
 *
837
838
839
840
841
842
843
844

845
846
847

848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869



870
871
872
873
874
875
876
886
887
888
889
890
891
892

893
894
895

896
897
898
899








900
901
902
903
904
905
906
907



908
909
910
911
912
913
914
915
916
917







-
+


-
+



-
-
-
-
-
-
-
-








-
-
-
+
+
+







 *	The embedded window gets resized to match the container.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedStructureProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = clientData;
    Tk_ErrorHandler errHandler;

    if (eventPtr->type == ConfigureNotify) {

	/*
         * Send a ConfigureNotify  to the embedded application.
         */

        if (containerPtr->embeddedPtr != NULL) {
            TkDoConfigureNotify(containerPtr->embeddedPtr);
        }
	if (containerPtr->embedded != None) {
	    /*
	     * Ignore errors, since the embedded application could have
	     * deleted its window.
	     */

	    errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1,
		    -1, -1, NULL, NULL);
	    Tk_MoveResizeWindow((Tk_Window)containerPtr->embeddedPtr, 0, 0,
		    Tk_Width((Tk_Window)containerPtr->parentPtr),
		    Tk_Height((Tk_Window)containerPtr->parentPtr));
	    Tk_MoveResizeWindow((Tk_Window) containerPtr->embeddedPtr, 0, 0,
		    (unsigned) Tk_Width((Tk_Window) containerPtr->parentPtr),
		    (unsigned) Tk_Height((Tk_Window)containerPtr->parentPtr));
	    Tk_DeleteErrorHandler(errHandler);
	}
    } else if (eventPtr->type == DestroyNotify) {
	EmbedWindowDeleted(containerPtr->parentPtr);
    }
}

891
892
893
894
895
896
897
898

899
900
901

902
903
904
905
906
907
908
932
933
934
935
936
937
938

939
940
941

942
943
944
945
946
947
948
949







-
+


-
+







 *	The X focus may change.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedActivateProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = clientData;

    if (containerPtr->embeddedPtr != NULL) {
	if (eventPtr->type == ActivateNotify) {
	    TkGenerateActivateEvents(containerPtr->embeddedPtr,1);
	} else if (eventPtr->type == DeactivateNotify) {
	    TkGenerateActivateEvents(containerPtr->embeddedPtr,0);
	}
926
927
928
929
930
931
932
933

934
935
936

937
938
939
940
941
942
943
967
968
969
970
971
972
973

974
975
976

977
978
979
980
981
982
983
984







-
+


-
+







 *	The X focus may change.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedFocusProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = clientData;
    Display *display;
    XEvent event;

    if (containerPtr->embeddedPtr != NULL) {
	display = Tk_Display(containerPtr->parentPtr);
	event.xfocus.serial = LastKnownRequestProcessed(display);
	event.xfocus.send_event = false;
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010





1011
1012
1013
1014




1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031


1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047
1048
1049
1050
1051
1041
1042
1043
1044
1045
1046
1047




1048
1049
1050
1051
1052
1053
1054


1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073


1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1095







-
-
-
-
+
+
+
+
+


-
-
+
+
+
+















-
-
+
+












-
+







    int width, int height)	/* Size that the child has requested. */
{
    TkWindow *winPtr = containerPtr->parentPtr;

    /*
     * Forward the requested size into our geometry management hierarchy via
     * the container window. We need to send a Configure event back to the
     * embedded application if we decide not to honor its request; to make this
     * happen, process all idle event handlers synchronously here (so that the
     * geometry managers have had a chance to do whatever they want to do), and
     * if the window's size didn't change then generate a configure event.
     * embedded application if we decide not to honor its request; to make
     * this happen, process all idle event handlers synchronously here (so
     * that the geometry managers have had a chance to do whatever they want
     * to do), and if the window's size didn't change then generate a
     * configure event.
     */

    Tk_GeometryRequest((Tk_Window)winPtr, width, height);
    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_TIMER_EVENTS|TCL_DONT_WAIT)) {}
    Tk_GeometryRequest((Tk_Window) winPtr, width, height);
    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {
	/* Empty loop body. */
    }
    if ((winPtr->changes.width != width)
	    || (winPtr->changes.height != height)) {
	EmbedSendConfigure(containerPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * EmbedSendConfigure --
 *
 *	This is currently a stub. It is called to notify an embedded
 *	application of its current size and location. This procedure is called
 *	when the embedded application made a geometry request that we did not
 *	grant, so that the embedded application knows that its geometry didn't
 *	change after all. It is a response to ConfigureRequest events, which we
 *	do not currently synthesize on the Mac
 *	change after all. It is a response to ConfigureRequest events, which
 *	we do not currently synthesize on the Mac
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedSendConfigure(
    TCL_UNUSED(Container *))	/* Information about the embedding. */
    Container *containerPtr)	/* Information about the embedding. */
{
}

/*
 *----------------------------------------------------------------------
 *
 * EmbedWindowDeleted --
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095


1096
1097
1098
1099
1100
1101
1102
1118
1119
1120
1121
1122
1123
1124



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134


1135
1136
1137
1138
1139
1140
1141
1142
1143







-
-
-










-
-
+
+







     * Find the Container structure for this window. Delete the information
     * about the embedded application and free the container's record.
     */

    prevPtr = NULL;
    containerPtr = firstContainerPtr;
    while (1) {
	if (containerPtr == NULL) {
	    return;
	}
	if (containerPtr->embeddedPtr == winPtr) {
	    /*
	     * We also have to destroy our parent, to clean up the container.
	     * Fabricate an event to do this.
	     */

	    if (containerPtr->parentPtr != NULL &&
		    containerPtr->parentPtr->flags & TK_BOTH_HALVES) {
		XEvent event;

		event.xany.serial = LastKnownRequestProcessed(
			Tk_Display(containerPtr->parentPtr));
		event.xany.serial =
			LastKnownRequestProcessed(Tk_Display(containerPtr->parentPtr));
		event.xany.send_event = False;
		event.xany.display = Tk_Display(containerPtr->parentPtr);

		event.xany.type = DestroyNotify;
		event.xany.window = containerPtr->parent;
		event.xdestroywindow.event = containerPtr->parent;
		Tk_QueueWindowEvent(&event, TCL_QUEUE_HEAD);
1147
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167


1168
1169
1170
1171
1172
1173
1174
1175
1176
1177





1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1188
1189
1190
1191
1192
1193
1194

1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206


1207
1208
1209
1210
1211
1212
1213





1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229







-
+





-
+





-
-
+
+





-
-
-
-
-
+
+
+
+
+











 *	Creates the platform-specific part of a busy window structure.
 *
 *----------------------------------------------------------------------
 */

void
TkpShowBusyWindow(
    TCL_UNUSED(TkBusy))
    TkBusy busy)
{
}

void
TkpHideBusyWindow(
    TCL_UNUSED(TkBusy))
    TkBusy busy)
{
}

void
TkpMakeTransparentWindowExist(
    TCL_UNUSED(Tk_Window),		/* Token for window. */
    TCL_UNUSED(Window))		/* Parent window. */
    Tk_Window tkwin,		/* Token for window. */
    Window parent)		/* Parent window. */
{
}

void
TkpCreateBusy(
    TCL_UNUSED(Tk_FakeWin *),
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(TkBusy))
    Tk_FakeWin *winPtr,
    Tk_Window tkRef,
    Window* parentPtr,
    Tk_Window tkParent,
    TkBusy busy)
{
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXEntry.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







/*
 * tkMacOSXEntry.c --
 *
 *	This file implements the native aqua entry widget.
 *
 * Copyright © 2001 Apple Computer, Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2008-2009 Apple Inc.
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2008-2009, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkEntry.h"
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102







-
+







    int isSpinbox)
{
    CGRect bounds;
    TkMacOSXDrawingContext dc;
    GC bgGC;
    Tk_Window tkwin = entryPtr->tkwin;
    int oldWidth = 0;
    MacDrawable *macDraw = (MacDrawable *)d;
    MacDrawable *macDraw = (MacDrawable *) d;
    const HIThemeFrameDrawInfo info = {
	.version = 0,
	.kind = kHIThemeFrameTextFieldSquare,
	.state = (entryPtr->state == STATE_DISABLED ? kThemeStateInactive :
		kThemeStateActive),
	.isFocused = (entryPtr->flags & GOT_FOCUS ? 1 : 0),
    };
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
119
120
121
122
123
124
125



126



127




128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

151









152
153
154
155
156
157
158







-
-
-
+
-
-
-

-
-
-
-
+
+
+
-




















-
+
-
-
-
-
-
-
-
-
-







     * space for one pixel to the right, 'cause it makes the buttons look
     * nicer.
     */

    if (isSpinbox) {
	int incDecWidth;

	/*
	 * If native spinbox buttons are going to be drawn, then temporarily
	 * change the width of the widget so that the same code can be used
	oldWidth = Tk_Width(tkwin);
	 * for drawing the Entry portion of the Spinbox as is used to draw
	 * an ordinary Entry.  The width must be restored before returning.
	 */

	oldWidth = Tk_Width(tkwin);
	if (ComputeIncDecParameters(Tk_Height(tkwin) - 2 * MAC_OSX_FOCUS_WIDTH,
		&incDecWidth) != 0) {
	    Tk_Width(tkwin) -= incDecWidth + 1;
	ComputeIncDecParameters(Tk_Height(tkwin) - 2 * MAC_OSX_FOCUS_WIDTH,
		&incDecWidth);
	Tk_Width(tkwin) -= incDecWidth + 1;
	}
    }

   /*
    * The focus ring is drawn with an Alpha at the outside part of the ring,
    * so we have to draw over the edges of the ring before drawing the focus
    * or the text will peep through.
    */

    bgGC = Tk_GCForColor(entryPtr->highlightBgColorPtr, d);
    TkDrawInsetFocusHighlight(entryPtr->tkwin, bgGC, MAC_OSX_FOCUS_WIDTH, d, 0);

    /*
     * Inset the entry Frame by the maximum width of the focus rect, which is
     * 3 according to the Carbon docs.
     */

    bounds.origin.x = macDraw->xOff + MAC_OSX_FOCUS_WIDTH;
    bounds.origin.y = macDraw->yOff + MAC_OSX_FOCUS_WIDTH;
    bounds.size.width = Tk_Width(tkwin) - 2*MAC_OSX_FOCUS_WIDTH;
    bounds.size.height = Tk_Height(tkwin) - 2*MAC_OSX_FOCUS_WIDTH;
    if (!TkMacOSXSetupDrawingContext(d, NULL, &dc)) {
    if (!TkMacOSXSetupDrawingContext(d, NULL, 1, &dc)) {

	/*
	 * No graphics context is available.  If the widget is a Spinbox, we
	 * must restore its width before returning 0. (Ticket [273b6a4996].)
	 */

	if (isSpinbox) {
	    Tk_Width(tkwin) = oldWidth;
	}
	return 0;
    }
    ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation);
    TkMacOSXRestoreDrawingContext(&dc);
    if (isSpinbox) {
	Tk_Width(tkwin) = oldWidth;
    }
183
184
185
186
187
188
189
190

191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
167
168
169
170
171
172
173

174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+


-
+

















-
+







 *	This procedure redraws the buttons of an spinbox widget. It overrides
 *	the generic button drawing code if the spinbox widget parameters are
 *	such that the native widget drawing is a good fit. This version just
 *	returns 0, so platforms that don't do special native drawing don't
 *	have to implement it.
 *
 * Results:
 *	1 if it has drawn the buttons, 0 if not.
 *	1 if it has drawn the border, 0 if not.
 *
 * Side effects:
 *	May draw the buttons into pixmap.
 *	May draw the entry border into pixmap.
 *
 *--------------------------------------------------------------
 */

int
TkpDrawSpinboxButtons(
    Spinbox *sbPtr,
    Drawable d)
{
    CGRect bounds;
    Tk_Window tkwin = sbPtr->entry.tkwin;
    int height = Tk_Height(tkwin);
    int buttonHeight = height - 2 * MAC_OSX_FOCUS_WIDTH;
    int incDecWidth;
    TkMacOSXDrawingContext dc;
    XRectangle rects[1];
    GC bgGC;
    MacDrawable *macDraw = (MacDrawable *)d;
    MacDrawable *macDraw = (MacDrawable *) d;
    HIThemeButtonDrawInfo info = {
	.version = 0,
	.adornment = kThemeAdornmentNone,
    };

    /*
     * FIXME: RAISED really makes more sense
255
256
257
258
259
260
261
262

263
264
265


266
267
268

269
270
271
272
273
274
275
239
240
241
242
243
244
245

246
247


248
249
250
251

252
253
254
255
256
257
258
259







-
+

-
-
+
+


-
+







    /*
     * We had to make the entry part of the window smaller so that we wouldn't
     * overdraw the spin buttons with the focus highlight. So now we have to
     * draw the highlightbackground.
     */

    bgGC = Tk_GCForColor(sbPtr->entry.highlightBgColorPtr, d);
    rects[0].x = (short)(Tk_Width(tkwin) - incDecWidth - 1);
    rects[0].x = bounds.origin.x;
    rects[0].y = 0;
    rects[0].width = (unsigned short)(incDecWidth + 1);
    rects[0].height = (unsigned short)Tk_Height(tkwin);
    rects[0].width = Tk_Width(tkwin);
    rects[0].height = Tk_Height(tkwin);
    XFillRectangles(Tk_Display(tkwin), d, bgGC, rects, 1);

    if (!TkMacOSXSetupDrawingContext(d, NULL, &dc)) {
    if (!TkMacOSXSetupDrawingContext(d, NULL, 1, &dc)) {
	return 0;
    }
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    TkMacOSXRestoreDrawingContext(&dc);
    return 1;
}


Changes to macosx/tkMacOSXEvent.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
1
2
3
4
5



6
7
8
9
10
11
12
13
14

15
16

17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36





-
-
-
+
+
+






-
+

-












-
+







/*
 * tkMacOSXEvent.c --
 *
 *	This file contains the basic Mac OS X Event handling routines.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXConstants.h"

#pragma mark TKApplication(TKEvent)

enum {
    NSWindowWillMoveEventType = 20
};

@implementation TKApplication(TKEvent)
/* TODO: replace by +[addLocalMonitorForEventsMatchingMask ? */
- (NSEvent *) tkProcessEvent: (NSEvent *) theEvent
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), theEvent);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
#endif
    NSEvent	    *processedEvent = theEvent;
    NSEventType	    type = [theEvent type];
    NSInteger	    subtype;

    switch ((NSInteger)type) {
    case NSAppKitDefined:
85
86
87
88
89
90
91

92
93
94
95
96
97
98

99
100
101
102
103
104
105
106

107
108

109
110
111
112
113
114
115






116
117
118
119
120







121
122

123
124

125
126

127




128
129
130








131
132
133
134
135
136
137
138
139
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110







111
112
113
114
115
116





117
118
119
120
121
122
123


124


125


126
127
128
129
130
131



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148







+







+








+

-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
+

+
+
+
+
-
-
-
+
+
+
+
+
+
+
+









    case NSApplicationDefined: {
	id win;
	win = [theEvent window];
	break;
	}
    case NSCursorUpdate:
        break;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
    case NSEventTypeGesture:
    case NSEventTypeMagnify:
    case NSEventTypeRotate:
    case NSEventTypeSwipe:
    case NSEventTypeBeginGesture:
    case NSEventTypeEndGesture:
        break;
#endif
#endif

    default:
	break; /* return theEvent */
    }
    return processedEvent;
}
@end

#pragma mark -


int
XSync(
    Display *display,
    TCL_UNUSED(Bool))
{
    /*
     *  The main use of XSync is by the update command, which alternates
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXFlushWindows --
 *
 *	This routine flushes all the visible windows of the application. It is
     *  between running an event loop to process all events without waiting and
     *  calling XSync on all displays until no events are left.  On X11 the
     *  call to XSync might cause the window manager to generate more events
     *  which would then get processed. Apparently this process stabilizes on
     *  X11, leaving the window manager in a state where all events have been
 *	called by XSync().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Flushes all visible Cocoa windows
     *  generated and no additional events can be genereated by updating widgets.
     *
 *
     *  It is not clear what the Aqua port should do when XSync is called, but
     *  currently the best option seems to be to do nothing.  (See ticket
 *----------------------------------------------------------------------
     *  [da5f2266df].)
     */
 */

MODULE_SCOPE void
TkMacOSXFlushWindows(void)
{
    NSArray *macWindows = [NSApp orderedWindows];
    LastKnownRequestProcessed(display)++;
    return 0;
}

    for (NSWindow *w in macWindows) {
	if (TkMacOSXGetXWindow(w)) {
	    [w flushWindow];
	}
    }
}


/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Added macosx/tkMacOSXEvent.h.
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * tkMacOSXEvent.h --
 *
 *	Declarations of Macintosh specific functions for implementing the
 *	Mac OS X Notifier.
 *
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMACEVENT
#define _TKMACEVENT

#ifndef _TKMACINT
#include "tkMacOSXInt.h"
#endif

MODULE_SCOPE void TkMacOSXFlushWindows(void);

#endif

Deleted macosx/tkMacOSXFileTypes.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115



















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
There are situations where a graphical user interface needs to know the file
type (i.e. data format) of a file.  The two main ones are when generating an
icon to represent a file, and when filtering the choice of files in a file
open or save dialog.

Early Macintosh systems used OSTypes as identifiers for file types.  An OSType
is a FourCC datatype - four bytes which can be packed into a 32 bit integer.  In
the HFS filesystem they were included in the file metadata.  The metadata also
included another OSType (the Creator Code) which identified the application
which created the file.

In OSX 10.4 the Uniform Type Identifier was introduced as an alternative way to
describe file types.  These are strings (NSStrings, actually) in a reverse DNS
format, such as "com.apple.application-bundle".  Apple provided a tool for
converting OSType codes to Uniform Type Identifiers, which they deprecated in
macOS 12.0 after introducing the UTType class in macOS 11.0.  An instance of the
UTType class has properties which give the Uniform Type Identifier as well as
the preferred file name extension for a given file type.

This module provides tools for working with file types which are meant to abstract
the many variants that Apple has used over the years, and which can be used
without generating deprecation warnings.
*/

#include "tkMacOSXPrivate.h"

#define CHARS_TO_OSTYPE(string) (OSType) string[0] << 24 | \
                                (OSType) string[1] << 16 | \
                                (OSType) string[2] <<  8 | \
                                (OSType) string[3]

MODULE_SCOPE NSString *TkMacOSXOSTypeToUTI(OSType ostype) {
    char string[5];
    string[4] = '\0';
    string[3] = ostype;
    string[2] = ostype >> 8;
    string[1] = ostype >> 16;
    string[0] = ostype >> 24;
    NSString *tag = [NSString stringWithCString:string encoding:NSMacOSRomanStringEncoding];
    if (tag == nil) {
	return nil;
    }
    NSString *result = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
    if (@available(macOS 11.0, *)) {
	return [UTType typeWithTag:tag tagClass:@"com.apple.ostype" conformingToType:nil].identifier;
    }
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
    result = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, (CFStringRef)tag, NULL);
#endif
    return result;
}

/*
 * The NSWorkspace method iconForFileType, which was deprecated in macOS 12.0, would
 * accept an NSString which could be an encoding of an OSType, or a file extension,
 * or a Uniform Type Idenfier.  This function can serve as a replacement.
 */
MODULE_SCOPE NSImage *TkMacOSXIconForFileType(NSString *filetype) {
#if MAC_OS_X_VERSION_MAX_ALLOWED < 110000
// We don't have UTType but iconForFileType is not deprecated, so use it.
    return [[NSWorkspace sharedWorkspace] iconForFileType:filetype];
#else
// We might have UTType but iconForFileType might be deprecated.
    if (@available(macOS 11.0, *)) {
	/* Yes, we do have UTType */
	if (filetype == nil) {
	    /*
	     * Bug 9be830f61b: match the behavior of
	     * [NSWorkspace.sharedWorkspace iconForFileType:nil]
	     */
	     filetype = @"public.data";
	}
	UTType *uttype = [UTType typeWithIdentifier: filetype];
	if (uttype == nil || !uttype.isDeclared) {
	    uttype = [UTType typeWithFilenameExtension: filetype];
	}
	if (uttype == nil || (!uttype.isDeclared && filetype.length == 4)) {
	    OSType ostype = CHARS_TO_OSTYPE(filetype.UTF8String);
	    NSString *UTI = TkMacOSXOSTypeToUTI(ostype);
	    if (UTI) {
		uttype = [UTType typeWithIdentifier:UTI];
	    }
	}
	if (uttype == nil || !uttype.isDeclared) {
	    return nil;
	}
	return [[NSWorkspace sharedWorkspace] iconForContentType:uttype];
    } else {
	/* No, we don't have UTType. */
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 110000
	/* but iconForFileType is not deprecated, so we can use it. */
    return [[NSWorkspace sharedWorkspace] iconForFileType:filetype];
 #else
    /*
     * Cannot be reached: MIN_REQUIRED >= 110000 yet 11.0 is not available.
     * But the compiler can't figure that out, so it will warn about an
     * execution path with no return value unless we put a return here.
     */
    return nil;
 #endif
    }
#endif
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXFont.c.

1
2
3
4
5


6
7
8
9



10
11
12
13
14
15
16
17
18

19
20





21



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56



57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

















98
99
100
101
102
103
104
105
106
107



108
109

110
111
112
113



114
115










116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
1
2
3


4
5
6



7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36




















37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67

68
69

















70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



94
95
96


97




98
99
100


101
102
103
104
105
106
107
108
109
110
111
112
113
114














































































115
116
117
118
119
120
121



-
-
+
+

-
-
-
+
+
+







-

+


+
+
+
+
+

+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+
+
+













-
+








-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * tkMacOSXFont.c --
 *
 *	Contains the Macintosh implementation of the platform-independent font
 *	package interface.
 *	Contains the Macintosh implementation of the platform-independant
 *	font package interface.
 *
 * Copyright © 2002-2004 Benjamin Riefenstahl, [email protected]
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2008-2009 Apple Inc.
 * Copyright 2002-2004 Benjamin Riefenstahl, [email protected]
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2008-2009, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXFont.h"
#include "tkMacOSXConstants.h"

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
#define defaultOrientation kCTFontDefaultOrientation
#define verticalOrientation kCTFontVerticalOrientation
#else
#define defaultOrientation kCTFontOrientationDefault
#define verticalOrientation kCTFontOrientationVertical
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
#define fixedPitch kCTFontUserFixedPitchFontType
#else
#define fixedPitch kCTFontUIFontUserFixedPitch
#endif

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_FONTS
#endif
*/

/*
 * TclNumUtfChars() is the same as Tcl_NumUtfChars(), but counting
 * in UTF-16 in stead of UTF-32. For Tcl 8.7 it's a little bit
 * tricky to get this function, because we are compiling with
 * TCL_UTF_MAX=4. Same for TclUtfAtIndex()
 */
#if TCL_MAJOR_VERSION < 9
#   undef TclNumUtfChars
#   undef TclUtfAtIndex
#   ifdef USE_TCL_STUBS
#	define TclNumUtfChars \
	    (tclStubsPtr->tcl_NumUtfChars) /* 312 */
#	define TclUtfAtIndex \
	    (tclStubsPtr->tcl_UtfAtIndex) /* 325 */
#   else
#	define TclNumUtfChars Tcl_NumUtfChars
#	define TclUtfAtIndex Tcl_UtfAtIndex
#   endif
#endif

/*
 * The following structure represents our Macintosh-specific implementation
 * of a font object.
 */

typedef struct {
    TkFont font;		/* Stuff used by generic font package. Must be
				 * first in structure. */
    TkFont font;		/* Stuff used by generic font package. Must
				 * be first in structure. */

    NSFont *nsFont;
    NSDictionary *nsAttributes;
} MacFont;

/*
 * The names for our "native" fonts.
 */

#define SYSTEMFONT_NAME		"system"
#define APPLFONT_NAME		"application"
#define MENUITEMFONT_NAME	"menu"

struct SystemFontMapEntry {
    ThemeFontID id;
    const ThemeFontID id;
    const char *systemName;
    const char *tkName;
    const char *tkName1;
};

#define ThemeFont(n, ...) { kTheme##n##Font, "system" #n "Font", ##__VA_ARGS__ }
static const struct SystemFontMapEntry systemFontMap[] = {
    ThemeFont(System, 			"TkDefaultFont", "TkIconFont"),
    ThemeFont(EmphasizedSystem,		"TkCaptionFont", NULL),
    ThemeFont(EmphasizedSystem,		"TkCaptionFont"),
    ThemeFont(SmallSystem,		"TkHeadingFont", "TkTooltipFont"),
    ThemeFont(SmallEmphasizedSystem, NULL, NULL),
    ThemeFont(Application,		"TkTextFont", NULL),
    ThemeFont(Label,			"TkSmallCaptionFont", NULL),
    ThemeFont(Views, NULL, NULL),
    ThemeFont(MenuTitle, NULL, NULL),
    ThemeFont(MenuItem,			"TkMenuFont", NULL),
    ThemeFont(MenuItemMark, NULL, NULL),
    ThemeFont(MenuItemCmdKey, NULL, NULL),
    ThemeFont(WindowTitle, NULL, NULL),
    ThemeFont(PushButton, NULL, NULL),
    ThemeFont(UtilityWindowTitle, NULL, NULL),
    ThemeFont(AlertHeader, NULL, NULL),
    ThemeFont(Toolbar, NULL, NULL),
    ThemeFont(MiniSystem, NULL, NULL),
    { kThemeSystemFontDetail,		"systemDetailSystemFont", NULL, NULL },
    { kThemeSystemFontDetailEmphasized,	"systemDetailEmphasizedSystemFont", NULL, NULL },
    { (ThemeFontID)-1, NULL, NULL, NULL }
    ThemeFont(SmallEmphasizedSystem),
    ThemeFont(Application,		"TkTextFont"),
    ThemeFont(Label,			"TkSmallCaptionFont"),
    ThemeFont(Views),
    ThemeFont(MenuTitle),
    ThemeFont(MenuItem,			"TkMenuFont"),
    ThemeFont(MenuItemMark),
    ThemeFont(MenuItemCmdKey),
    ThemeFont(WindowTitle),
    ThemeFont(PushButton),
    ThemeFont(UtilityWindowTitle),
    ThemeFont(AlertHeader),
    ThemeFont(Toolbar),
    ThemeFont(MiniSystem),
    { kThemeSystemFontDetail,		"systemDetailSystemFont" },
    { kThemeSystemFontDetailEmphasized,	"systemDetailEmphasizedSystemFont" },
    { -1, NULL }
};
#undef ThemeFont

static int antialiasedTextEnabled = -1;
static NSCharacterSet *whitespaceCharacterSet = nil;
static NSCharacterSet *lineendingCharacterSet = nil;

static void		GetTkFontAttributesForNSFont(NSFont *nsFont,
			    TkFontAttributes *faPtr);
static NSFont *		FindNSFont(const char *familyName,
static void GetTkFontAttributesForNSFont(NSFont *nsFont,
	TkFontAttributes *faPtr);
static NSFont *FindNSFont(const char *familyName, NSFontTraitMask traits,
			    NSFontTraitMask traits, NSInteger weight,
			    CGFloat size, int fallbackToDefault);
	NSInteger weight, CGFloat size, int fallbackToDefault);
static void		InitFont(NSFont *nsFont,
			    const TkFontAttributes *reqFaPtr,
			    MacFont *fontPtr);
static int		CreateNamedSystemFont(Tcl_Interp *interp,
static void InitFont(NSFont *nsFont, const TkFontAttributes *reqFaPtr,
	MacFont * fontPtr);
static int CreateNamedSystemFont(Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_Window tkwin, const char *name,
			    TkFontAttributes *faPtr);
	const char* name, TkFontAttributes *faPtr);
static void DrawCharsInContext(Display *display, Drawable drawable, GC gc,
	Tk_Font tkfont, const char *source, int numBytes, int rangeStart,
	int rangeLength, int x, int y, double angle);

@interface NSFont(TKFont)
- (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters
	length: (NSUInteger) length attributes: (NSDictionary *) attributes
	actualCoveredLength: (NSUInteger *) coveredLength;
@end

#pragma mark -
#pragma mark Font Helpers:

/*
 * To avoid an extra copy, a TKNSString object wraps a Tcl_DString with an
 * NSString that uses the DString's buffer as its character buffer.  It can be
 * constructed from a Tcl_DString and it has a DString property that handles
 * converting from an NSString to a Tcl_DString.
 */

@implementation TKNSString

- (instancetype)initWithTclUtfBytes:(const void *)bytes
		       length:(NSUInteger)len
{
    self = [self init];
    if (self) {
	Tcl_DStringInit(&_ds);
	Tcl_UtfToChar16DString((const char *)bytes, len, &_ds);
	_string = [[NSString alloc]
	     initWithCharactersNoCopy:(unichar *)Tcl_DStringValue(&_ds)
			       length:Tcl_DStringLength(&_ds)>>1
			 freeWhenDone:NO];
	self.UTF8String = _string.UTF8String;
    }
    return self;
}

- (instancetype)initWithString:(NSString *)aString
{
    self = [self init];
    if (self) {
	_string = [[NSString alloc] initWithString:aString];
	_UTF8String = _string.UTF8String;
    }
    return self;
}

- (void)dealloc
{
    Tcl_DStringFree(&_ds);
    [_string release];
    [super dealloc];
}

- (NSUInteger)length
{
    return _string.length;
}

- (unichar)characterAtIndex:(NSUInteger)index
{
    return [_string characterAtIndex:index];
}

- (Tcl_DString)DString
{
    if ( _ds.string == NULL) {

	/*
	 * The DString has not been initialized. Construct it from
	 * our string's unicode characters.
	 */
	char *p;
	NSUInteger index;

	Tcl_DStringInit(&_ds);
	Tcl_DStringSetLength(&_ds, 3 * [_string length]);
	p = Tcl_DStringValue(&_ds);
	for (index = 0; index < [_string length]; index++) {
	    p += Tcl_UniCharToUtf([_string characterAtIndex: index]|TCL_COMBINE, p);
	}
	Tcl_DStringSetLength(&_ds, (Tcl_Size)(p - Tcl_DStringValue(&_ds)));
    }
    return _ds;
}

@synthesize UTF8String = _UTF8String;
@synthesize DString = _ds;
@end

#define GetNSFontTraitsFromTkFontAttributes(faPtr) \
	((faPtr)->weight == TK_FW_BOLD ? NSBoldFontMask : NSUnboldFontMask) | \
	((faPtr)->slant == TK_FS_ITALIC ? NSItalicFontMask : NSUnitalicFontMask)

/*
 *---------------------------------------------------------------------------
 *
218
219
220
221
222
223
224

225
226
227

228
229
230
231
232
233
234
235
236
237
135
136
137
138
139
140
141
142
143


144
145
146

147
148
149
150
151
152
153







+

-
-
+


-







static void
GetTkFontAttributesForNSFont(
    NSFont *nsFont,
    TkFontAttributes *faPtr)
{
    NSFontTraitMask traits = [[NSFontManager sharedFontManager]
	    traitsOfFont:nsFont];

    faPtr->family = Tk_GetUid([[nsFont familyName] UTF8String]);
#define FACTOR 0.75
    faPtr->size = [nsFont pointSize] * FACTOR;
    faPtr->size = [nsFont pointSize];
    faPtr->weight = (traits & NSBoldFontMask ? TK_FW_BOLD : TK_FW_NORMAL);
    faPtr->slant = (traits & NSItalicFontMask ? TK_FS_ITALIC : TK_FS_ROMAN);

}

/*
 *---------------------------------------------------------------------------
 *
 * FindNSFont --
 *
259
260
261
262
263
264
265
266

267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
175
176
177
178
179
180
181

182
183
184
185
186

187
188
189












190
191
192
193
194
195
196







-
+




-
+


-
-
-
-
-
-
-
-
-
-
-
-







{
    NSFontManager *fm = [NSFontManager sharedFontManager];
    NSFont *nsFont, *dflt = nil;
    #define defaultFont (dflt ? dflt : (dflt = [NSFont systemFontOfSize:0]))
    NSString *family;

    if (familyName) {
	family = [[[TKNSString alloc] initWithTclUtfBytes:familyName length:TCL_INDEX_NONE] autorelease];
	family = [[[NSString alloc] initWithUTF8String:familyName] autorelease];
    } else {
	family = [defaultFont familyName];
    }
    if (size == 0.0) {
	size = [defaultFont pointSize] * FACTOR;
	size = [defaultFont pointSize];
    }
    nsFont = [fm fontWithFamily:family traits:traits weight:weight size:size];

    /*
     * A second bug in NSFontManager that Apple created for the Catalina OS
     * causes requests as above to sometimes return fonts with additional
     * traits that were not requested, even though fonts without those unwanted
     * traits exist on the system.  See bug [90d555e088].  As a workaround
     * we ask the font manager to remove any unrequested traits.
     */

    if (nsFont) {
	nsFont = [fm convertFont:nsFont toNotHaveTrait:~traits];
    }
    if (!nsFont) {
	NSArray *availableFamilies = [fm availableFontFamilies];
	NSString *caseFamily = nil;

	for (NSString *f in availableFamilies) {
	    if ([family caseInsensitiveCompare:f] == NSOrderedSame) {
		caseFamily = f;
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362

363
364
365
366
367
368
369
370
371
372
373



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260



261



262
263
264
265
266
267
268
269
270



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290


291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318







-
+











-
-
-
+
-
-
-
+








-
-
-
+
+
+

















-
-
+
+


















-
+







    NSDictionary *nsAttributes;
    NSRect bounds;
    CGFloat kern = 0.0;
    NSFontRenderingMode renderingMode = NSFontDefaultRenderingMode;
    int ascent, descent/*, dontAA*/;
    static const UniChar ch[] = {'.', 'W', ' ', 0xc4, 0xc1, 0xc2, 0xc3, 0xc7};
			/* ., W, Space, Auml, Aacute, Acirc, Atilde, Ccedilla */
#define nCh	(sizeof(ch) / sizeof(UniChar))
    #define nCh (sizeof(ch) / sizeof(UniChar))
    CGGlyph glyphs[nCh];
    CGRect boundingRects[nCh];

    fontPtr->font.fid = (Font) fontPtr;
    faPtr = &fontPtr->font.fa;
    if (reqFaPtr) {
	*faPtr = *reqFaPtr;
    } else {
	TkInitFontAttributes(faPtr);
    }
    fontPtr->nsFont = nsFont;

    /*
     * Some don't like antialiasing on fixed-width even if bigger than limit
    // some don't like antialiasing on fixed-width even if bigger than limit
     */

    // dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10;
//    dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10;
    if (antialiasedTextEnabled >= 0/* || dontAA*/) {
	renderingMode = (antialiasedTextEnabled == 0/* || dontAA*/) ?
		NSFontIntegerAdvancementsRenderingMode :
		NSFontAntialiasedRenderingMode;
    }
    nsFont = [nsFont screenFontWithRenderingMode:renderingMode];
    GetTkFontAttributesForNSFont(nsFont, faPtr);
    fmPtr = &fontPtr->font.fm;
    fmPtr->ascent = (int)floor([nsFont ascender] + [nsFont leading] + 0.5);
    fmPtr->descent = (int)floor(-[nsFont descender] + 0.5);
    fmPtr->maxWidth = (int)[nsFont maximumAdvancement].width;
    fmPtr->ascent = floor([nsFont ascender] + [nsFont leading] + 0.5);
    fmPtr->descent = floor(-[nsFont descender] + 0.5);
    fmPtr->maxWidth = [nsFont maximumAdvancement].width;
    fmPtr->fixed = [nsFont isFixedPitch];   /* Does not work for all fonts */

    /*
     * The ascent, descent and fixed fields are not correct for all fonts, as
     * a workaround deduce that info from the metrics of some typical glyphs,
     * along with screenfont kerning (space advance difference to printer font)
     */

    bounds = [nsFont boundingRectForFont];
    if (CTFontGetGlyphsForCharacters((CTFontRef) nsFont, ch, glyphs, nCh)) {
	fmPtr->fixed = [nsFont advancementForGlyph:glyphs[0]].width ==
		[nsFont advancementForGlyph:glyphs[1]].width;
	bounds = NSRectFromCGRect(CTFontGetBoundingRectsForGlyphs((CTFontRef)
		nsFont, defaultOrientation, ch, boundingRects, nCh));
	kern = [nsFont advancementForGlyph:glyphs[2]].width -
		[fontPtr->nsFont advancementForGlyph:glyphs[2]].width;
    }
    descent = (int)floor(-bounds.origin.y + 0.5);
    ascent = (int)floor(bounds.size.height + bounds.origin.y + 0.5);
    descent = floor(-bounds.origin.y + 0.5);
    ascent = floor(bounds.size.height + bounds.origin.y + 0.5);
    if (ascent > fmPtr->ascent) {
	fmPtr->ascent = ascent;
    }
    if (descent > fmPtr->descent) {
	fmPtr->descent = descent;
    }
    nsAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
	    nsFont, NSFontAttributeName,
	    [NSNumber numberWithInt:faPtr->underline ?
		NSUnderlineStyleSingle|NSUnderlinePatternSolid :
		NSUnderlineStyleNone], NSUnderlineStyleAttributeName,
	    [NSNumber numberWithInt:faPtr->overstrike ?
		NSUnderlineStyleSingle|NSUnderlinePatternSolid :
		NSUnderlineStyleNone], NSStrikethroughStyleAttributeName,
	    [NSNumber numberWithInt:fmPtr->fixed ? 0 : 1],
		NSLigatureAttributeName,
	    [NSNumber numberWithDouble:kern], NSKernAttributeName, nil];
    fontPtr->nsAttributes = [nsAttributes retain];
#undef nCh
    #undef nCh
}

/*
 *-------------------------------------------------------------------------
 *
 * CreateNamedSystemFont --
 *
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609

610
611
612
613
614

615
616
617
618
619
620
621
622
337
338
339
340
341
342
343





































































































































344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374


375

376
377


378

379
380
381
382
383
384
385







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+
















-
+




-
-
+
-


-
-
+
-







    TkFontAttributes *faPtr)
{
    TkDeleteNamedFont(NULL, tkwin, name);
    return TkCreateNamedFont(interp, tkwin, name, faPtr);
}

#pragma mark -

#pragma mark Grapheme Cluster indexing

/*
 *----------------------------------------------------------------------
 *
 * startOfClusterObjCmd --
 *
 *      This function is invoked to process the startOfCluster command.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      None
 *
 *----------------------------------------------------------------------
 */

static int
startOfClusterObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,         /* Current interpreter. */
    int objc,                   /* Number of arguments. */
    Tcl_Obj *const objv[])      /* Argument objects. */
{
    TKNSString *S;
    const char *stringArg;
    Tcl_Size len, idx;
    if ((unsigned)(objc - 3) > 1) {
	Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?");
	return TCL_ERROR;
    }
    stringArg = Tcl_GetStringFromObj(objv[1], &len);
    if (stringArg == NULL) {
	return TCL_ERROR;
    }
    Tcl_Size ulen = Tcl_GetCharLength(objv[1]);
    S = [[TKNSString alloc] initWithTclUtfBytes:stringArg length:len];
    len = [S length];
    if (TkGetIntForIndex(objv[2], ulen - 1, 0, &idx) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad index \"%s\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"",
		Tcl_GetString(objv[2])));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "INDEX", NULL);
	return TCL_ERROR;
    }
    if (idx > 0 && len != ulen) {
	/* The string contains codepoints > \uFFFF. Determine UTF-16 index */
	Tcl_Size newIdx = 0;
	for (Tcl_Size i = 0; i < idx; i++) {
	    newIdx += 1 + (((newIdx < len-1) && ([S characterAtIndex:newIdx]&0xFC00) == 0xD800) && (([S characterAtIndex:newIdx+1]&0xFC00) == 0xDC00));
	}
	idx = newIdx;
    }
    if (idx >= 0) {
	if (idx >= len) {
	    idx = len;
	} else {
	    NSRange range = [S rangeOfComposedCharacterSequenceAtIndex:idx];
	    idx = range.location;
	}
	if (idx > 0 && len != ulen) {
	    /* The string contains codepoints > \uFFFF. Determine UTF-32 index */
	    Tcl_Size newIdx = 1;
	    for (Tcl_Size i = 1; i < idx; i++) {
		if ((([S characterAtIndex:i-1]&0xFC00) != 0xD800) || (([S characterAtIndex:i]&0xFC00) != 0xDC00)) newIdx++;
	    }
	    idx = newIdx;
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(idx));
    }
    return TCL_OK;
}

static int
endOfClusterObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,         /* Current interpreter. */
    int objc,                   /* Number of arguments. */
    Tcl_Obj *const objv[])      /* Argument objects. */
{
    TKNSString *S;
    char *stringArg;
    Tcl_Size idx, len;

    if ((unsigned)(objc - 3) > 1) {
	Tcl_WrongNumArgs(interp, 1 , objv, "str start ?locale?");
	return TCL_ERROR;
    }
    stringArg = Tcl_GetStringFromObj(objv[1], &len);
    if (stringArg == NULL) {
	return TCL_ERROR;
    }
    Tcl_Size ulen = Tcl_GetCharLength(objv[1]);
    S = [[TKNSString alloc] initWithTclUtfBytes:stringArg length:len];
    len = [S length];
    if (TkGetIntForIndex(objv[2], ulen - 1, 0, &idx) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"bad index \"%s\": must be integer?[+-]integer?, end?[+-]integer?, or \"\"",
		Tcl_GetString(objv[2])));
	Tcl_SetErrorCode(interp, "TK", "VALUE", "INDEX", NULL);
	return TCL_ERROR;
    }
    if (idx > 0 && len != ulen) {
	/* The string contains codepoints > \uFFFF. Determine UTF-16 index */
	Tcl_Size newIdx = 0;
	for (Tcl_Size i = 0; i < idx; i++) {
	    newIdx += 1 + (((newIdx < len-1) && ([S characterAtIndex:newIdx]&0xFC00) == 0xD800) && (([S characterAtIndex:newIdx+1]&0xFC00) == 0xDC00));
	}
	idx = newIdx;
    }
    if (idx + 1 <= len) {
	if (idx < 0) {
	    idx = 0;
	} else {
	    NSRange range = [S rangeOfComposedCharacterSequenceAtIndex:idx];
	    idx = range.location + range.length;
	    if (idx > 0 && len != ulen) {
		/* The string contains codepoints > \uFFFF. Determine UTF-32 index */
		Tcl_Size newIdx = 1;
		for (Tcl_Size i = 1; i < idx; i++) {
		if ((([S characterAtIndex:i-1]&0xFC00) != 0xD800) || (([S characterAtIndex:i]&0xFC00) != 0xDC00)) newIdx++;
		}
		idx = newIdx;
	    }
	}
	Tcl_SetObjResult(interp, TkNewIndexObj(idx));
    }
    return TCL_OK;
}

#pragma mark -
#pragma mark Font handling:

/*
 *-------------------------------------------------------------------------
 *
 * TkpFontPkgInit --
 *
 *	This procedure is called when an application is created. It
 *	initializes all the structures that are used by the
 *	platform-dependent code on a per application basis.
 *	platform-dependant code on a per application basis.
 *	Note that this is called before TkpInit() !
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Initialize named system fonts.
 *
 *-------------------------------------------------------------------------
 */

void
TkpFontPkgInit(
    TkMainInfo *mainPtr)	/* The application being created. */
{
    Tcl_Interp *interp = mainPtr->interp;
    Tk_Window tkwin = (Tk_Window)mainPtr->winPtr;
    Tk_Window tkwin = (Tk_Window) mainPtr->winPtr;
    const struct SystemFontMapEntry *systemFont = systemFontMap;
    NSFont *nsFont;
    TkFontAttributes fa;
    NSMutableCharacterSet *cs;
    /*
     * Since we called before TkpInit, we need our own autorelease pool.
    /* Since we called before TkpInit, we need our own autorelease pool. */
     */
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    /*
     * Force this for now.
    /* force this for now */
     */
    if (!mainPtr->winPtr->mainPtr) {
	mainPtr->winPtr->mainPtr = mainPtr;
    }
    while (systemFont->systemName) {
	nsFont = (NSFont*) CTFontCreateUIFontForLanguage(
		HIThemeGetUIFontType(systemFont->id), 0, NULL);
	if (nsFont) {
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686



687
688
689


690
691
692
693
694



695
696
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721


722
723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741




742
743
744
745
746




747
748
749
750



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765




766
767
768
769
770
771

772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791

792
793

794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810



811
812
813
814
815
816
817
393
394
395
396
397
398
399










400



401
402

403

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419


420
421
422
423
424
425
426
427
428
429



430
431
432
433


434
435
436
437



438
439
440
441
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465


466
467
468

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484



485
486
487
488
489




490
491
492
493
494



495
496
497
498
499
500
501
502
503
504
505
506
507
508




509
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537

538
539

540
541
542
543
544
545
546
547
548
549
550
551
552
553
554



555
556
557
558
559
560
561
562
563
564







-
-
-
-
-
-
-
-
-
-

-
-
-


-

-
















-
-










-
-
-
+
+
+

-
-
+
+


-
-
-
+
+
+









-
+















-
-
+
+

-
+















-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+











-
-
-
-
+
+
+
+





-
+



















-
+

-
+














-
-
-
+
+
+







		CreateNamedSystemFont(interp, tkwin, systemFont->tkName1, &fa);
	    }
	    CFRelease(nsFont);
	}
	systemFont++;
    }
    TkInitFontAttributes(&fa);
#if 0

    /*
     * In macOS 10.15.1 Apple introduced a bug in NSFontManager which caused
     * it to not recognize the familyName ".SF NSMono" which is the familyName
     * of the default fixed pitch system fault on that system.  See bug [855049e799].
     * As a workaround we call [NSFont userFixedPitchFontOfSize:11] instead.
     * This returns a user font in the "Menlo" family.
     */

    nsFont = (NSFont*) CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL);
#else
    nsFont = [NSFont userFixedPitchFontOfSize:11];
#endif
    if (nsFont) {
	GetTkFontAttributesForNSFont(nsFont, &fa);
#if 0
	CFRelease(nsFont);
#endif
    } else {
	fa.family = Tk_GetUid("Monaco");
	fa.size = 11;
	fa.weight = TK_FW_NORMAL;
	fa.slant = TK_FS_ROMAN;
    }
    CreateNamedSystemFont(interp, tkwin, "TkFixedFont", &fa);
    if (!whitespaceCharacterSet) {
	whitespaceCharacterSet = [[NSCharacterSet
		whitespaceAndNewlineCharacterSet] retain];
	cs = [whitespaceCharacterSet mutableCopy];
	[cs removeCharactersInString:@" "];
	lineendingCharacterSet = [cs copy];
	[cs release];
    }
    [pool drain];
    Tcl_CreateObjCommand(interp, "::tk::startOfCluster", startOfClusterObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::endOfCluster", endOfClusterObjCmd, NULL, NULL);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpGetNativeFont --
 *
 *	Map a platform-specific native font name to a TkFont.
 *
 * Results:
 *	The return value is a pointer to a TkFont that represents the native
 *	font. If a native font by the given name could not be found, the return
 *	value is NULL.
 *	The return value is a pointer to a TkFont that represents the
 *	native font. If a native font by the given name could not be
 *	found, the return value is NULL.
 *
 *	Every call to this procedure returns a new TkFont structure, even if
 *	the name has already been seen before. The caller should call
 *	Every call to this procedure returns a new TkFont structure, even
 *	if the name has already been seen before. The caller should call
 *	TkpDeleteFont() when the font is no longer needed.
 *
 *	The caller is responsible for initializing the memory associated with
 *	the generic TkFont when this function returns and releasing the
 *	contents of the generics TkFont before calling TkpDeleteFont().
 *	The caller is responsible for initializing the memory associated
 *	with the generic TkFont when this function returns and releasing
 *	the contents of the generics TkFont before calling TkpDeleteFont().
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

TkFont *
TkpGetNativeFont(
    TCL_UNUSED(Tk_Window),		/* For display where font will be used. */
    Tk_Window tkwin,		/* For display where font will be used. */
    const char *name)		/* Platform-specific font name. */
{
    MacFont *fontPtr = NULL;
    ThemeFontID themeFontId;
    CTFontRef ctFont;

    if (strcmp(name, SYSTEMFONT_NAME) == 0) {
	themeFontId = kThemeSystemFont;
    } else if (strcmp(name, APPLFONT_NAME) == 0) {
	themeFontId = kThemeApplicationFont;
    } else if (strcmp(name, MENUITEMFONT_NAME) == 0) {
	themeFontId = kThemeMenuItemFont;
    } else {
	return NULL;
    }
    ctFont = CTFontCreateUIFontForLanguage(
	    HIThemeGetUIFontType(themeFontId), 0, NULL);
    ctFont = CTFontCreateUIFontForLanguage(HIThemeGetUIFontType(
	    themeFontId), 0, NULL);
    if (ctFont) {
	fontPtr = (MacFont *)ckalloc(sizeof(MacFont));
	fontPtr = ckalloc(sizeof(MacFont));
	InitFont((NSFont*) ctFont, NULL, fontPtr);
    }

    return (TkFont *) fontPtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpGetFontFromAttributes --
 *
 *	Given a desired set of attributes for a font, find a font with the
 *	closest matching attributes.
 *
 * Results:
 *	The return value is a pointer to a TkFont that represents the font with
 *	the desired attributes. If a font with the desired attributes could not
 *	be constructed, some other font will be substituted automatically.
 *	The return value is a pointer to a TkFont that represents the font
 *	with the desired attributes. If a font with the desired attributes
 *	could not be constructed, some other font will be substituted
 *	automatically.
 *
 *	Every call to this procedure returns a new TkFont structure, even if
 *	the specified attributes have already been seen before. The caller
 *	should call TkpDeleteFont() to free the platform- specific data when
 *	the font is no longer needed.
 *	Every call to this procedure returns a new TkFont structure, even
 *	if the specified attributes have already been seen before. The
 *	caller should call TkpDeleteFont() to free the platform- specific
 *	data when the font is no longer needed.
 *
 *	The caller is responsible for initializing the memory associated with
 *	the generic TkFont when this function returns and releasing the
 *	contents of the generic TkFont before calling TkpDeleteFont().
 *	The caller is responsible for initializing the memory associated
 *	with the generic TkFont when this function returns and releasing
 *	the contents of the generic TkFont before calling TkpDeleteFont().
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

TkFont *
TkpGetFontFromAttributes(
    TkFont *tkFontPtr,		/* If non-NULL, store the information in this
				 * existing TkFont structure, rather than
				 * allocating a new structure to hold the font;
				 * the existing contents of the font will be
				 * released. If NULL, a new TkFont structure is
				 * allocated. */
				 * allocating a new structure to hold the
				 * font; the existing contents of the font
				 * will be released. If NULL, a new TkFont
				 * structure is allocated. */
    Tk_Window tkwin,		/* For display where font will be used. */
    const TkFontAttributes *faPtr)
				/* Set of attributes to match. */
{
    MacFont *fontPtr;
    CGFloat points = floor(TkFontGetPoints(tkwin, faPtr->size / FACTOR) + 0.5);
    int points = (int)(TkFontGetPoints(tkwin, faPtr->size) + 0.5);
    NSFontTraitMask traits = GetNSFontTraitsFromTkFontAttributes(faPtr);
    NSInteger weight = (faPtr->weight == TK_FW_BOLD ? 9 : 5);
    NSFont *nsFont;

    nsFont = FindNSFont(faPtr->family, traits, weight, points, 0);
    if (!nsFont) {
	const char *const *aliases = TkFontGetAliasList(faPtr->family);

	while (aliases && !nsFont) {
	    nsFont = FindNSFont(*aliases++, traits, weight, points, 0);
	}
    }
    if (!nsFont) {
	nsFont = FindNSFont(faPtr->family, traits, weight, points, 1);
    }
    if (!nsFont) {
	Tcl_Panic("Could not determine NSFont from TkFontAttributes");
    }
    if (tkFontPtr == NULL) {
	fontPtr = (MacFont *)ckalloc(sizeof(MacFont));
	fontPtr = ckalloc(sizeof(MacFont));
    } else {
	fontPtr = (MacFont *)tkFontPtr;
	fontPtr = (MacFont *) tkFontPtr;
	TkpDeleteFont(tkFontPtr);
    }
    CFRetain(nsFont); /* Always needed to allow unconditional CFRelease below */
    InitFont(nsFont, faPtr, fontPtr);

    return (TkFont *) fontPtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpDeleteFont --
 *
 *	Called to release a font allocated by TkpGetNativeFont() or
 *	TkpGetFontFromAttributes(). The caller should have already released the
 *	fields of the TkFont that are used exclusively by the generic TkFont
 *	code.
 *	TkpGetFontFromAttributes(). The caller should have already
 *	released the fields of the TkFont that are used exclusively by the
 *	generic TkFont code.
 *
 * Results:
 *	TkFont is deallocated.
 *
 * Side effects:
 *	None.
 *
830
831
832
833
834
835
836
837
838


839
840
841
842
843
844
845
846
847
848
849
850
851
852
853

854
855
856
857
858
859
860

861
862
863
864
865
866
867
868
869
870
871


872
873
874
875


876
877
878
879
880
881
882
577
578
579
580
581
582
583


584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616


617
618
619
620


621
622
623
624
625
626
627
628
629







-
-
+
+














-
+






-
+









-
-
+
+


-
-
+
+







}

/*
 *---------------------------------------------------------------------------
 *
 * TkpGetFontFamilies --
 *
 *	Return information about the font families that are available on the
 *	display of the given window.
 *	Return information about the font families that are available on
 *	the display of the given window.
 *
 * Results:
 *	Modifies interp's result object to hold a list of all the available
 *	font families.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

void
TkpGetFontFamilies(
    Tcl_Interp *interp,		/* Interp to hold result. */
    TCL_UNUSED(Tk_Window))		/* For display to query. */
    Tk_Window tkwin)		/* For display to query. */
{
    Tcl_Obj *resultPtr = Tcl_NewListObj(0, NULL);
    NSArray *list = [[NSFontManager sharedFontManager] availableFontFamilies];

    for (NSString *family in list) {
	Tcl_ListObjAppendElement(NULL, resultPtr,
		Tcl_NewStringObj([family UTF8String], TCL_INDEX_NONE));
		Tcl_NewStringObj([family UTF8String], -1));
    }
    Tcl_SetObjResult(interp, resultPtr);
}

/*
 *-------------------------------------------------------------------------
 *
 * TkpGetSubFonts --
 *
 *	A function used by the testing package for querying the actual screen
 *	fonts that make up a font object.
 *	A function used by the testing package for querying the actual
 *	screen fonts that make up a font object.
 *
 * Results:
 *	Modifies interp's result object to hold a list containing the names of
 *	the screen fonts that make up the given font object.
 *	Modifies interp's result object to hold a list containing the names
 *	of the screen fonts that make up the given font object.
 *
 * Side effects:
 *	None.
 *
 *-------------------------------------------------------------------------
 */

893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908
909
910
911
912
913


914
915
916
917
918
919
920
921
922
923
924
925
926

927
928

929
930
931
932
933
934
935
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656
657
658


659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674

675
676
677
678
679
680
681
682







-
+











-
-
+
+












-
+

-
+







		objectForKey:NSFontCascadeListAttribute];

	for (NSFontDescriptor *subFontDesc in list) {
	    NSString *family = [subFontDesc objectForKey:NSFontFamilyAttribute];

	    if (family) {
		Tcl_ListObjAppendElement(NULL, resultPtr,
			Tcl_NewStringObj([family UTF8String], TCL_INDEX_NONE));
			Tcl_NewStringObj([family UTF8String], -1));
	    }
	}
    }
    Tcl_SetObjResult(interp, resultPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetFontAttrsForChar --
 *
 *	Retrieve the font attributes of the actual font used to render a given
 *	character.
 *	Retrieve the font attributes of the actual font used to render a
 *	given character.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The font attributes are stored in *faPtr.
 *
 *----------------------------------------------------------------------
 */

void
TkpGetFontAttrsForChar(
    TCL_UNUSED(Tk_Window),		/* Window on the font's display */
    Tk_Window tkwin,		/* Window on the font's display */
    Tk_Font tkfont,		/* Font to query */
    int c,	 		/* Character of interest */
    int c,         		/* Character of interest */
    TkFontAttributes* faPtr)	/* Output: Font attributes */
{
    MacFont *fontPtr = (MacFont *) tkfont;
    NSFont *nsFont = fontPtr->nsFont;
    *faPtr = fontPtr->font.fa;
    if (nsFont && ![[nsFont coveredCharacterSet] characterIsMember:c]) {
	UTF16Char ch = (UTF16Char) c;
973
974
975
976
977
978
979
980

981
982
983
984
985
986
987
720
721
722
723
724
725
726

727
728
729
730
731
732
733
734







-
+







 */

int
Tk_MeasureChars(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    Tcl_Size numBytes,		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length; don't consider any
				 * character that would cross this x-position.
				 * If < 0, then line length is unbounded and
				 * the flags argument is ignored. */
    int flags,			/* Various flag bits OR-ed together:
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017




1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033


1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047





1048
1049
1050
1051
1052
1053
1054
755
756
757
758
759
760
761



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777

778
779


780
781
782
783
784
785
786
787
788
789
790





791
792
793
794
795
796
797
798
799
800
801
802







-
-
-
+
+
+
+












-
+

-
-
+
+









-
-
-
-
-
+
+
+
+
+







 *	that TkpDrawCharsInContext() will be used to actually display the
 *	characters.
 *
 *	This one is almost the same as Tk_MeasureChars(), but with access to
 *	all the characters on the line for context.
 *
 * Results:
 *	The return value is the number of bytes from source that fit into the
 *	span that extends from 0 to maxLength. *lengthPtr is filled with the
 *	x-coordinate of the right edge of the last character that did fit.
 *	The return value is the number of bytes from source that
 *	fit into the span that extends from 0 to maxLength. *lengthPtr is
 *	filled with the x-coordinate of the right edge of the last
 *	character that did fit.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int
TkpMeasureCharsInContext(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    Tcl_Size numBytes,		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string in all. */
    Tcl_Size rangeStart,		/* Index of first byte to measure. */
    Tcl_Size rangeLength,		/* Length of range to measure in bytes. */
    int rangeStart,		/* Index of first byte to measure. */
    int rangeLength,		/* Length of range to measure in bytes. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length; don't consider any
				 * character that would cross this x-position.
				 * If < 0, then line length is unbounded and
				 * the flags argument is ignored. */
    int flags,			/* Various flag bits OR-ed together:
				 * TK_PARTIAL_OK means include the last char
				 * which only partially fits on this line.
				 * TK_WHOLE_WORDS means stop on a word
				 * boundary, if possible. TK_AT_LEAST_ONE means
				 * return at least one character even if no
				 * characters fit.  If TK_WHOLE_WORDS and
				 * TK_AT_LEAST_ONE are set and the first word
				 * doesn't fit, we return at least one
				 * boundary, if possible. TK_AT_LEAST_ONE
				 * means return at least one character even
				 * if no characters fit.  If TK_WHOLE_WORDS
				 * and TK_AT_LEAST_ONE are set and the first
				 * word doesn't fit, we return at least one
				 * character or whatever characters fit into
				 * maxLength.  TK_ISOLATE_END means that the
				 * last character should not be considered in
				 * context with the rest of the string (used
				 * for breaking lines). */
    int *lengthPtr)		/* Filled with x-location just after the
				 * terminating character. */
1067
1068
1069
1070
1071
1072
1073









1074
1075
1076
1077


1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088


1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173



1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213

1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235


1236
1237
1238

1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257


1258
1259
1260

1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844


845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862




863
864
865
866
867
868
869
870
871
872





873
874
875
876
877
878

















879
880
881





882
883
884
885
886
887
888
889
890
891
892
893
894
895
896




897
898
899


900
901
902
903
904
905
906
907
908
909
910
911
912

913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937

938
939
940

941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958


959
960
961
962

963
964
965
966

967
968
969
970
971
972
973
974
975
976
977
978
979
980


981
982
983
984

985
986
987
988
989

990
991
992
993
994
995
996
997







+
+
+
+
+
+
+
+
+



-
+
+









-
-
+
+
















-
-
-
-










-
-
-
-
-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-















-
-
-
-
+
+
+
-
-













-
+










+













-
+


-
+

















-
-
+
+


-
+



-
+













-
-
+
+


-
+




-
+








    if (rangeStart < 0 || rangeLength <= 0 ||
	    rangeStart + rangeLength > numBytes ||
	    (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) {
	*lengthPtr = 0;
	return 0;
    }
#if 0
    /* Back-compatibility with ATSUI renderer, appears not to be needed */
    if (rangeStart == 0 && maxLength == 1 && (flags & TK_ISOLATE_END) &&
	    !(flags & TK_AT_LEAST_ONE)) {
	length = 0;
	fit = 0;
	goto done;
    }
#endif
    if (maxLength > 32767) {
	maxLength = 32767;
    }
    string = [[TKNSString alloc] initWithTclUtfBytes:source length:numBytes];
    string = [[NSString alloc] initWithBytesNoCopy:(void*)source
		length:numBytes encoding:NSUTF8StringEncoding freeWhenDone:NO];
    if (!string) {
	length = 0;
	fit = rangeLength;
	goto done;
    }
    attributedString = [[NSAttributedString alloc] initWithString:string
	    attributes:fontPtr->nsAttributes];
    typesetter = CTTypesetterCreateWithAttributedString(
	    (CFAttributedStringRef)attributedString);
    start = TclNumUtfChars(source, rangeStart);
    len = TclNumUtfChars(source + rangeStart, rangeLength);
    start = Tcl_NumUtfChars(source, rangeStart);
    len = Tcl_NumUtfChars(source + rangeStart, rangeLength);
    if (start > 0) {
	range.length = start;
	line = CTTypesetterCreateLine(typesetter, range);
	offset = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
	CFRelease(line);
    }
    if (maxLength < 0) {
	index = len;
	range.length = len;
	line = CTTypesetterCreateLine(typesetter, range);
	width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
	CFRelease(line);
    } else {
	double maxWidth = maxLength + offset;
	NSCharacterSet *cs;

	/*
	 * Get a line breakpoint in the source string.
	 */

	index = start;
	if (flags & TK_WHOLE_WORDS) {
	    index = CTTypesetterSuggestLineBreak(typesetter, start, maxWidth);
	    if (index <= start && (flags & TK_AT_LEAST_ONE)) {
		flags &= ~TK_WHOLE_WORDS;
	    }
	}
	if (index <= start && !(flags & TK_WHOLE_WORDS)) {
	    index = CTTypesetterSuggestClusterBreak(typesetter, start, maxWidth);
	}

	/*
	 * Trim right whitespace/lineending characters.
	 */

	cs = (index <= len && (flags & TK_WHOLE_WORDS)) ?
		whitespaceCharacterSet : lineendingCharacterSet;
	while (index > start &&
		[cs characterIsMember:[string characterAtIndex:(index - 1)]]) {
	    index--;
	}

	/*
	 * If there is no line breakpoint in the source string between its
	 * start and the index position that fits in maxWidth, then
	 * CTTypesetterSuggestLineBreak() returns that very last index.
	 * However if the TK_WHOLE_WORDS flag is set, we want to break at a
	 * word boundary. In this situation, unless TK_AT_LEAST_ONE is set, we
	 * must report that zero chars actually fit (in other words the
	 * smallest word of the source string is still larger than maxWidth).
	 */

	if ((index >= start) && (index < len) &&
		(flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) &&
		![cs characterIsMember:[string characterAtIndex:index]]) {
	    index = start;
	}

	if (index <= start && (flags & TK_AT_LEAST_ONE)) {
	    index = start + 1;
	}

	/*
	 * Now measure the string width in pixels.
	 */

	if (index > 0) {
	    range.length = index;
	    line = CTTypesetterCreateLine(typesetter, range);
	    width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
	    CFRelease(line);
	} else {
	    width = 0;
	}
	if (width < maxWidth && (flags & TK_PARTIAL_OK) && index < len) {
	    range.length = ++index;
	    line = CTTypesetterCreateLine(typesetter, range);
	    width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
	    CFRelease(line);
	}

	/*
	 * The call to CTTypesetterSuggestClusterBreak above will always return
	 * at least one character regardless of whether it exceeded it or not.
	 * Clean that up now.
        /* The call to CTTypesetterSuggestClusterBreak above will always
           return at least one character regardless of whether it exceeded
           it or not.  Clean that up now. */
	 */

	while (width > maxWidth && !(flags & TK_PARTIAL_OK)
		&& index > start+(flags & TK_AT_LEAST_ONE)) {
	    range.length = --index;
	    line = CTTypesetterCreateLine(typesetter, range);
	    width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
	    CFRelease(line);
	}

    }
    CFRelease(typesetter);
    [attributedString release];
    [string release];
    length = ceil(width - offset);
    fit = (TclUtfAtIndex(source, index) - source) - rangeStart;
    fit = (Tcl_UtfAtIndex(source, index) - source) - rangeStart;
done:
#ifdef TK_MAC_DEBUG_FONTS
    TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
	    "flags='%s%s%s%s' -> width=%d bytesFit=%d\n", source, rangeLength,
	    source+rangeStart, maxLength,
	    flags & TK_PARTIAL_OK   ? "partialOk "  : "",
	    flags & TK_WHOLE_WORDS  ? "wholeWords " : "",
	    flags & TK_AT_LEAST_ONE ? "atLeastOne " : "",
	    flags & TK_ISOLATE_END  ? "isolateEnd " : "",
	    length, fit);
//if (!(rangeLength==1 && rangeStart == 0)) fprintf(stderr, "   measure len=%d (max=%d, w=%.0f) from %d (nb=%d): source=\"%s\": index=%d return %d\n",rangeLength,maxLength,width,rangeStart,numBytes, source+rangeStart, index, fit);
#endif
    *lengthPtr = length;
    return fit;
}

/*
 *---------------------------------------------------------------------------
 *
 * Tk_DrawChars --
 *
 *	Draw a string of characters on the screen.
 *
 *	With ATSUI we need the line context to do this right, so we have the
 *	actual implementation in TkpDrawAngledCharsInContext().
 *	actual implementation in TkpDrawCharsInContext().
 *
 * Results:
 *	None.
  *	None.
 *
 * Side effects:
 *	Information gets drawn on the screen.
 *
 *---------------------------------------------------------------------------
 */

void
Tk_DrawChars(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int x, int y)		/* Coordinates at which to place origin of the
				 * string when drawing. */
{
    TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
    DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
	    0, numBytes, x, y, 0.0);
}

void
TkDrawAngledChars(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn;
				 * must be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    double x, double y,		/* Coordinates at which to place origin of
				 * string when drawing. */
    double angle)		/* What angle to put text at, in degrees. */
{
    TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
    DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
	    0, numBytes, x, y, angle);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpDrawCharsInContext --
1292
1293
1294
1295
1296
1297
1298
1299
1300


1301
1302
1303
1304
1305



1306
1307
1308
1309
1310

1311
1312
1313
1314
1315
1316



1317
1318
1319
1320
1321
1322
1323
1324
1325


1326
1327
1328
1329
1330
1331




1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343



1344
1345
1346

1347
1348
1349

1350
1351
1352
1353



1354
1355
1356


1357
1358
1359
1360
1361
1362

1363
1364
1365
1366


1367
1368
1369


1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380





1381
1382
1383


1384
1385
1386
1387

1388
1389


1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402



1403


1404
1405

1406
1407
1408
1409

1410
1411
1412
1413
1414
1415
1416
1017
1018
1019
1020
1021
1022
1023


1024
1025
1026
1027



1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048


1049
1050
1051
1052




1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065



1066
1067
1068
1069
1070

1071
1072
1073

1074
1075



1076
1077
1078
1079
1080

1081
1082
1083
1084
1085

1086

1087
1088



1089
1090

1091

1092
1093
1094
1095
1096

1097
1098





1099
1100
1101
1102
1103
1104


1105
1106


1107
1108
1109


1110
1111

1112

1113










1114
1115
1116

1117
1118
1119

1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132







-
-
+
+


-
-
-
+
+
+




-
+



-
-
-
+
+
+







-
-
+
+


-
-
-
-
+
+
+
+


-
+






-
-
-
+
+
+


-
+


-
+

-
-
-
+
+
+


-
+
+



-

-
+

-
-
-
+
+
-

-
+
+



-


-
-
-
-
-
+
+
+
+
+

-
-
+
+
-
-


+
-
-
+
+
-

-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
+

-
+




+







    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    int numBytes,		/* Number of bytes in string. */
    int rangeStart,		/* Index of first byte to draw. */
    int rangeLength,		/* Length of range to draw in bytes. */
    int x, int y)		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
{
    TkpDrawAngledCharsInContext(display, drawable, gc, tkfont, source, numBytes,
    DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
	    rangeStart, rangeLength, x, y, 0.0);
}

void
TkpDrawAngledCharsInContext(
    TCL_UNUSED(Display *),		/* Display on which to draw. */
static void
DrawCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    double x, double y,		/* Coordinates at which to place origin of the
    int numBytes,		/* Number of bytes in string. */
    int rangeStart,		/* Index of first byte to draw. */
    int rangeLength,		/* Length of range to draw in bytes. */
    int x, int y,		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
    double angle)		/* What angle to put text at, in degrees. */
    double angle)
{
    const MacFont *fontPtr = (const MacFont *) tkfont;
    NSString *string;
    NSMutableDictionary *attributes;
    NSAttributedString *attributedString;
    CTTypesetterRef typesetter;
    CFIndex start, length;
    CTLineRef line, full=nil;
    MacDrawable *macWin = (MacDrawable *)drawable;
    CFIndex start, len;
    CTLineRef line;
    MacDrawable *macWin = (MacDrawable *) drawable;
    TkMacOSXDrawingContext drawingContext;
    CGContextRef context;
    CGColorRef fg = NULL;
    CGColorRef fg;
    NSFont *nsFont;
    CGAffineTransform t;
    CGFloat width, height, textX = (CGFloat) x, textY = (CGFloat) y;
    int h;

    if (rangeStart < 0 || rangeLength <= 0
	    || rangeStart + rangeLength > numBytes
	    || !TkMacOSXSetupDrawingContext(drawable, gc, &drawingContext)) {
    if (rangeStart < 0 || rangeLength <= 0 ||
	    rangeStart + rangeLength > numBytes ||
	    !TkMacOSXSetupDrawingContext(drawable, gc, 1, &drawingContext)) {
	return;
    }
    string = [[TKNSString alloc] initWithTclUtfBytes:source length:numBytes];
    string = [[NSString alloc] initWithBytesNoCopy:(void*)source
		length:numBytes encoding:NSUTF8StringEncoding freeWhenDone:NO];
    if (!string) {
	return;
    }

    context = drawingContext.context;
    TkSetMacColor(gc->foreground, &fg);
    fg = TkMacOSXCreateCGColor(gc, gc->foreground);
    attributes = [fontPtr->nsAttributes mutableCopy];
    if (fg) {
	[attributes setObject:(id)fg forKey:(id)kCTForegroundColorAttributeName];
	CGColorRelease(fg);
    [attributes setObject:(id)fg forKey:(id)kCTForegroundColorAttributeName];
    CFRelease(fg);
    }
    nsFont = [attributes objectForKey:NSFontAttributeName];
    [nsFont setInContext:GET_NSCONTEXT(context, NO)];
    [nsFont setInContext:[NSGraphicsContext graphicsContextWithGraphicsPort:
	    context flipped:NO]];
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    attributedString = [[NSAttributedString alloc] initWithString:string
	    attributes:attributes];
    [string release];
    typesetter = CTTypesetterCreateWithAttributedString(
	    (CFAttributedStringRef)attributedString);
    textX += (CGFloat) macWin->xOff;
    textY += (CGFloat) macWin->yOff;
    height = [drawingContext.view bounds].size.height;
    textY = height - textY;
    t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, height);
    x += macWin->xOff;
    y += macWin->yOff;
    h = drawingContext.portBounds.size.height;
    y = h - y;
    t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, h);
    if (angle != 0.0) {
	t = CGAffineTransformTranslate(
	     CGAffineTransformRotate(
	t = CGAffineTransformTranslate(CGAffineTransformRotate(
		CGAffineTransformTranslate(t, x, y), angle*PI/180.0), -x, -y);
		 CGAffineTransformTranslate(t, textX, textY), angle*PI/180.0),
	     -textX, -textY);
    }
    CGContextConcatCTM(context, t);
    CGContextSetTextPosition(context, x, y);
    start = TclNumUtfChars(source, rangeStart);
    length = TclNumUtfChars(source, rangeStart + rangeLength) - start;
    start = Tcl_NumUtfChars(source, rangeStart);
    len = Tcl_NumUtfChars(source, rangeStart + rangeLength);
    line = CTTypesetterCreateLine(typesetter, CFRangeMake(start, length));
    if (start > 0) {

	CGRect clipRect = CGRectInfinite, startBounds;
	/*
	 * We are only drawing part of the string.  To compute the x coordinate
	 * of the part we are drawing we subtract its typographical length from
	 * the typographical length of the full string.  This accounts for the
	 * kerning after the initial part of the string.
	 */

	full = CTTypesetterCreateLine(typesetter, CFRangeMake(0, start + length));
	width = CTLineGetTypographicBounds(full, NULL, NULL, NULL);
	CFRelease(full);
	line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, start));
	startBounds = CTLineGetImageBounds(line, context);
	CFRelease(line);
	textX += (width - CTLineGetTypographicBounds(line, NULL, NULL, NULL));
	clipRect.origin.x = startBounds.origin.x + startBounds.size.width;
	CGContextClipToRect(context, clipRect);
    }
    CGContextSetTextPosition(context, textX, textY);
    line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, len));
    CTLineDraw(line, context);
    CFRelease(line);
    CFRelease(typesetter);
    [attributedString release];
    [string release];
    [attributes release];
    TkMacOSXRestoreDrawingContext(&drawingContext);
}

#pragma mark -
#pragma mark Accessors:

1455
1456
1457
1458
1459
1460
1461

























1462
1463
1464
1465
1466
1467
1468
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








MODULE_SCOPE NSDictionary*
TkMacOSXNSFontAttributesForFont(
    Tk_Font tkfont)
{
    return tkfont ? ((MacFont *)tkfont)->nsAttributes : nil;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkMacOSXIsCharacterMissing --
 *
 *	Given a tkFont and a character determine whether the character has
 *	a glyph defined in the font or not.
 *
 * Results:
 *	Returns a 1 if the character is missing, a 0 if it is not.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int
TkMacOSXIsCharacterMissing(
    Tk_Font tkfont,		/* The font we are looking in. */
    unsigned int searchChar)	/* The character we are looking for. */
{
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXFontDescriptionForNSFontAndNSFontAttributes --
 *
 *	Get text description of a font specified by NSFont and attributes.
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498



1499
1500
1501
1502
1503
1504
1505
1229
1230
1231
1232
1233
1234
1235




1236
1237
1238
1239
1240
1241
1242
1243
1244
1245







-
-
-
-
+
+
+







    if (nsFont && familyName) {
	NSFontTraitMask traits = [[NSFontManager sharedFontManager]
		traitsOfFont:nsFont];
	id underline = [nsAttributes objectForKey:
		NSUnderlineStyleAttributeName];
	id strikethrough = [nsAttributes objectForKey:
		NSStrikethroughStyleAttributeName];

	objv[i++] = Tcl_NewStringObj(familyName, TCL_INDEX_NONE);
	objv[i++] = Tcl_NewWideIntObj((Tcl_WideInt)floor([nsFont pointSize] * FACTOR + 0.5));
#define S(s)    Tcl_NewStringObj(STRINGIFY(s), (sizeof(STRINGIFY(s))-1))
	objv[i++] = Tcl_NewStringObj(familyName, -1);
	objv[i++] = Tcl_NewIntObj([nsFont pointSize]);
#define S(s) Tcl_NewStringObj(STRINGIFY(s),(int)(sizeof(STRINGIFY(s))-1))
	objv[i++] = (traits & NSBoldFontMask)	? S(bold)   : S(normal);
	objv[i++] = (traits & NSItalicFontMask)	? S(italic) : S(roman);
	if ([underline respondsToSelector:@selector(intValue)] &&
		([underline intValue] & (NSUnderlineStyleSingle |
		NSUnderlineStyleThick | NSUnderlineStyleDouble))) {
	    objv[i++] = S(underline);
	}
1515
1516
1517
1518
1519
1520
1521
1522
1523


1524
1525
1526
1527
1528
1529
1530
1531
1255
1256
1257
1258
1259
1260
1261


1262
1263

1264
1265
1266
1267
1268
1269
1270







-
-
+
+
-








/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXUseAntialiasedText --
 *
 *	Enables or disables application-wide use of antialiased text (where
 *	available). Sets up a linked Tcl global variable to allow disabling of
 *	antialiased text from Tcl.
 *	available). Sets up a linked Tcl global variable to allow
 *	disabling of antialiased text from tcl.
 *
 *	The possible values for this variable are:
 *
 *	-1 - Use system default as configurable in "System Prefs" -> "General".
 *	 0 - Unconditionally disable antialiasing.
 *	 1 - Unconditionally enable antialiasing.
 *
 * Results:
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560
1561
1562
1563
1564
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303







-
+







    if (!initialized) {
	initialized = TRUE;

	if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) {
	    Tcl_ResetResult(interp);
	}
	if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
		&antialiasedTextEnabled,
		(char *) &antialiasedTextEnabled,
		TCL_LINK_INT) != TCL_OK) {
	    Tcl_ResetResult(interp);
	}
    }
    antialiasedTextEnabled = enable;
    return TCL_OK;
}

Changes to macosx/tkMacOSXFont.h.

1
2
3
4

5
6
7
8
9
10




11
12
13
14
15
16
17
1
2
3

4
5
6




7
8
9
10
11
12
13
14
15
16
17



-
+


-
-
-
-
+
+
+
+







/*
 * tkMacOSXFont.h --
 *
 *	Contains the Macintosh implementation of the platform-independent
 *	Contains the Macintosh implementation of the platform-independant
 *	font package interface.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef TKMACOSXFONT_H
#define TKMACOSXFONT_H 1

Changes to macosx/tkMacOSXHLEvents.c.

1
2
3
4


5
6
7
8
9




10
11
12
13
14
15
16
17
1
2
3

4
5
6




7
8
9
10

11
12
13
14
15
16
17



-
+
+

-
-
-
-
+
+
+
+
-







/*
 * tkMacOSXHLEvents.c --
 *
 *	Implements high level event support for the Macintosh.
 *	Implements high level event support for the Macintosh. Currently, the
 *	only event that really does anything is the Quit event.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2015-2019 Marc Culler
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2015 Marc Culler
 * Copyright © 2019 Kevin Walzer/WordTech Communications LLC.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include <sys/param.h>
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48




49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112

113
114
115

116
117
118

119
120
121
122
123
124
125
126
127

128
129
130
131





132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160


























































































































































161

162
163
164
165
166
167
168
169
170
171


172
173
174

175
176
177

178
179
180
181
182
183
184
25
26
27
28
29
30
31













32
33
34
35
36
37
38
39
40
41












42
43
44
45
46
47

48
49
50






51
52

53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80

81

82

83
84
85

86
87
88
89
90
91
92
93
94
95
96




97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114



115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

282
283
284
285
286
287
288
289
290


291
292
293
294

295
296
297

298
299
300
301
302
303
304
305







-
-
-
-
-
-
-
-
-
-
-
-
-




+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-






-



-
-
-
-
-
-


-







-
-










-
+










-
+
-

-
+


-
+









+
-
-
-
-
+
+
+
+
+



-
+









-
-
-



-
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+








-
-
+
+


-
+


-
+







typedef struct KillEvent {
    Tcl_Event header;		/* Information that is standard for all
				 * events. */
    Tcl_Interp *interp;		/* Interp that was passed to the Quit
				 * AppleEvent */
} KillEvent;

/*
 * When processing an AppleEvent as an idle task, a pointer to one
 * of these structs is passed as the clientData.
 */

typedef struct AppleEventInfo {
    Tcl_Interp *interp;
    const char *procedure;
    Tcl_DString command;
    NSAppleEventDescriptor *replyEvent; /* Only used for DoScriptText. */
    int retryCount;
} AppleEventInfo;

/*
 * Static functions used only in this file.
 */

static void tkMacOSXProcessFiles(NSAppleEventDescriptor* event,
				 NSAppleEventDescriptor* replyEvent,
				 Tcl_Interp *interp,
				 char* procedure);
static int  MissedAnyParameters(const AppleEvent *theEvent);
static int  ReallyKillMe(Tcl_Event *eventPtr, int flags);
static void ProcessAppleEvent(void *clientData);

/*
 * Names of the procedures which can be used to process AppleEvents.
 */

static const char openDocumentProc[] = "::tk::mac::OpenDocument";
static const char launchURLProc[] = "::tk::mac::LaunchURL";
static const char printDocProc[] = "::tk::mac::PrintDocument";
static const char scriptFileProc[] = "::tk::mac::DoScriptFile";
static const char scriptTextProc[] = "::tk::mac::DoScriptText";
static const char getSdefProc[] = "::tk::mac::GetDynamicSdef";

#pragma mark TKApplication(TKHLEvents)

@implementation TKApplication(TKHLEvents)
- (void) terminate: (id) sender
{
    (void)sender;
    [self handleQuitApplicationEvent:Nil withReplyEvent:Nil];
}

- (void) superTerminate: (id) sender
{
    (void) sender;
    [super terminate:nil];
}

- (void) preferences: (id) sender
{
    (void)sender;
    [self handleShowPreferencesEvent:Nil withReplyEvent:Nil];
}

- (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    KillEvent *eventPtr;
    (void)event;
    (void)replyEvent;

    if (_eventInterp) {
	/*
	 * Call the exit command from the event loop, since you are not
	 * supposed to call ExitToShell in an Apple Event Handler. We put this
	 * at the head of Tcl's event queue because this message usually comes
	 * when the Mac is shutting down, and we want to kill the shell as
	 * quickly as possible.
	 */

	eventPtr = (KillEvent *)ckalloc(sizeof(KillEvent));
	eventPtr = ckalloc(sizeof(KillEvent));
	eventPtr->header.proc = ReallyKillMe;
	eventPtr->interp = _eventInterp;

	Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);
    }
}

- (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    (void)event;
   Tcl_Interp *interp = _eventInterp;
    (void)replyEvent;

    if (_eventInterp &&
    if (interp &&
	Tcl_FindCommand(_eventInterp, "::tk::mac::OpenApplication", NULL, 0)){
	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::OpenApplication",
			      TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
			      -1, TCL_EVAL_GLOBAL);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
    }
}

- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
    (void)event;
    (void)replyEvent;

    [NSApp activateIgnoringOtherApps: YES];
    ProcessSerialNumber thePSN = {0, kCurrentProcess};
    SetFrontProcess(&thePSN);
#else
    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
#endif
    if (_eventInterp && Tcl_FindCommand(_eventInterp,
	    "::tk::mac::ReopenApplication", NULL, 0)) {
	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ReopenApplication",
			      TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
			      -1, TCL_EVAL_GLOBAL);
	if (code != TCL_OK){
	    Tcl_BackgroundException(_eventInterp, code);
	}
    }
}

- (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    (void)event;
    (void)replyEvent;

    if (_eventInterp &&
	    Tcl_FindCommand(_eventInterp, "::tk::mac::ShowPreferences", NULL, 0)){
	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ShowPreferences",
			      TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
			      -1, TCL_EVAL_GLOBAL);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
    }
}

- (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    tkMacOSXProcessFiles(event, replyEvent, _eventInterp, "::tk::mac::OpenDocument");
}

- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    tkMacOSXProcessFiles(event, replyEvent, _eventInterp, "::tk::mac::PrintDocument");
}

- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    OSStatus err;
    const AEDesc *theDesc = nil;
    DescType type = 0, initialType = 0;
    Size actual;
    int tclErr = -1;
    char URLBuffer[1 + URL_MAX_LENGTH];
    char errString[128];
    char typeString[5];

    /*
     * The DoScript event receives one parameter that should be text data or a
     * fileURL.
     */

    theDesc = [event aeDesc];
    if (theDesc == nil) {
	return;
    }

    err = AEGetParamPtr(theDesc, keyDirectObject, typeWildCard, &initialType,
			NULL, 0, NULL);
    if (err != noErr) {
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", (int)err);
	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
		      errString, strlen(errString));
	return;
    }

    if (MissedAnyParameters((AppleEvent*)theDesc)) {
    	sprintf(errString, "AEDoScriptHandler: extra parameters");
    	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
    		      errString, strlen(errString));
    	return;
    }

    if (initialType == typeFileURL || initialType == typeAlias) {
	/*
	 * The descriptor can be coerced to a file url.  Source the file, or
	 * pass the path as a string argument to ::tk::mac::DoScriptFile if
	 * that procedure exists.
	 */
	err = AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type,
			    (Ptr) URLBuffer, URL_MAX_LENGTH, &actual);
	if (err == noErr && actual > 0){
	    URLBuffer[actual] = '\0';
	    NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer];
	    NSURL *fileURL = [NSURL URLWithString:urlString];
	    Tcl_DString command;
	    Tcl_DStringInit(&command);
	    if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptFile", NULL, 0)){
		Tcl_DStringAppend(&command, "::tk::mac::DoScriptFile", -1);
	    } else {
		Tcl_DStringAppend(&command, "source", -1);
	    }
	    Tcl_DStringAppendElement(&command, [[fileURL path] UTF8String]);
	    tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&command),
				 Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
	}
    } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
			   NULL, 0, &actual)) {
	if (actual > 0) {
	    /*
	     * The descriptor can be coerced to UTF8 text.  Evaluate as Tcl, or
	     * or pass the text as a string argument to ::tk::mac::DoScriptText
	     * if that procedure exists.
	     */
	    char *data = ckalloc(actual + 1);
	    if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
			    data, actual, NULL)) {
		if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptText", NULL, 0)){
		    Tcl_DString command;
		    Tcl_DStringInit(&command);
		    Tcl_DStringAppend(&command, "::tk::mac::DoScriptText", -1);
		    Tcl_DStringAppendElement(&command, data);
		    tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&command),
				 Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
		} else {
		    tclErr = Tcl_EvalEx(_eventInterp, data, actual, TCL_EVAL_GLOBAL);
		}
	    }
	    ckfree(data);
	}
    } else {
	/*
	 * The descriptor can not be coerced to a fileURL or UTF8 text.
	 */
	for (int i = 0; i < 4; i++) {
	    typeString[i] = ((char*)&initialType)[3-i];
	}
	typeString[4] = '\0';
	sprintf(errString, "AEDoScriptHandler: invalid script type '%s', "
		"must be coercable to 'furl' or 'utf8'", typeString);
	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar, errString,
		      strlen(errString));
    }
    /*
     * If we ran some Tcl code, put the result in the reply.
     */
    if (tclErr >= 0) {
	int reslen;
	const char *result =
	    Tcl_GetStringFromObj(Tcl_GetObjResult(_eventInterp), &reslen);
	if (tclErr == TCL_OK) {
	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyDirectObject, typeChar,
			  result, reslen);
	} else {
	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
			  result, reslen);
	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorNumber, typeSInt32,
			  (Ptr) &tclErr,sizeof(int));
	}
    }
    return;
}
@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessFiles --
 *
 *	Extract a list of fileURLs from an AppleEvent and call the specified
 *      procedure with the file paths as arguments.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The event is handled by running the procedure.
 *
 *----------------------------------------------------------------------
 */

static void
tkMacOSXProcessFiles(
    NSAppleEventDescriptor* event,
    NSAppleEventDescriptor* replyEvent,
    Tcl_Interp *interp,
    char* procedure)
{
    Tcl_Encoding utf8;
    Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8");
    const AEDesc *fileSpecDesc = nil;
    AEDesc contents;
    char URLString[1 + URL_MAX_LENGTH];
    NSURL *fileURL;
    DescType type;
    Size actual;
    long count, index;
    AEKeyword keyword;
    Tcl_DString pathName;
    (void)replyEvent;
    Tcl_DString command, pathName;
    int code;

    /*
     * Do nothing if we don't have an interpreter.
     * Do nothing if we don't have an interpreter or the procedure doesn't exist.
     */

    if (!_eventInterp) {
    if (!interp || !Tcl_FindCommand(interp, procedure, NULL, 0)) {
	return;
    }

    fileSpecDesc = [event aeDesc];
    if (fileSpecDesc == nil ) {
    	return;
    }
200
201
202
203
204
205
206
207
208


209
210
211
212
213
214


215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456


457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472


473
474
475
476


477
478
479
480
481
482
483
321
322
323
324
325
326
327


328
329
330
331




332
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347

348


349
350
351


352









353
































354




355




























356
















































357

































































































358
359
















360
361
362



363
364
365
366
367
368
369
370
371







-
-
+
+


-
-
-
-
+
+
-














-
+
-
-
+


-
-

-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
+
+








    if (AECountItems(fileSpecDesc, &count) != noErr) {
	AEDisposeDesc(&contents);
    	return;
    }

    /*
     * Construct a Tcl expression which calls the ::tk::mac::OpenDocument
     * procedure, passing the paths contained in the AppleEvent as arguments.
     * Construct a Tcl command which calls the procedure, passing the
     * paths contained in the AppleEvent as arguments.
     */

    AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
    Tcl_DString *openCommand = &AEInfo->command;
    Tcl_DStringInit(openCommand);
    Tcl_DStringAppend(openCommand, openDocumentProc, TCL_INDEX_NONE);
    Tcl_DStringInit(&command);
    Tcl_DStringAppend(&command, procedure, -1);
    utf8 = Tcl_GetEncoding(NULL, "utf-8");

    for (index = 1; index <= count; index++) {
	if (noErr != AEGetNthPtr(fileSpecDesc, index, typeFileURL, &keyword,
				 &type, (Ptr) URLString, URL_MAX_LENGTH, &actual)) {
	    continue;
	}
	if (type != typeFileURL) {
	    continue;
	}
	URLString[actual] = '\0';
	fileURL = [NSURL URLWithString:[NSString stringWithUTF8String:(char*)URLString]];
	if (fileURL == nil) {
	    continue;
	}
	(void)Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], TCL_INDEX_NONE,
	Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], -1, &pathName);
		&pathName);
	Tcl_DStringAppendElement(openCommand, Tcl_DStringValue(&pathName));
	Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
	Tcl_DStringFree(&pathName);
    }

    Tcl_FreeEncoding(utf8);
    AEDisposeDesc(&contents);
    AEInfo->interp = _eventInterp;
    AEInfo->procedure = openDocumentProc;
    AEInfo->replyEvent = nil;
    AEInfo->retryCount = 0;
    if (Tcl_FindCommand(_eventInterp, "::tk::mac::OpenDocuments", NULL, 0)){
	ProcessAppleEvent((void *)AEInfo);
    } else {
	Tcl_CreateTimerHandler(500, ProcessAppleEvent, (void *)AEInfo);
    }

}

- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
		    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    NSString* file = [[event paramDescriptorForKeyword:keyDirectObject]
			 stringValue];
    const char *printFile = [file UTF8String];
    AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
    Tcl_DString *printCommand = &AEInfo->command;
    (void)replyEvent;

    Tcl_DStringInit(printCommand);
    Tcl_DStringAppend(printCommand, printDocProc, TCL_INDEX_NONE);
    Tcl_DStringAppendElement(printCommand, printFile);
    AEInfo->interp = _eventInterp;
    AEInfo->procedure = printDocProc;
    AEInfo->replyEvent = nil;
    AEInfo->retryCount = 0;
    ProcessAppleEvent((void *)AEInfo);
}

- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
	      withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
    OSStatus err;
    const AEDesc *theDesc = nil;
    DescType type = 0, initialType = 0;
    Size actual;
    char URLBuffer[1 + URL_MAX_LENGTH];
    char errString[128];

    /*
     * The DoScript event receives one parameter that should be text data or a
     * fileURL.
     */

     * Handle the event by evaluating the Tcl expression we constructed.
    theDesc = [event aeDesc];
    if (theDesc == nil) {
	return;
    }

    err = AEGetParamPtr(theDesc, keyDirectObject, typeWildCard, &initialType,
			NULL, 0, NULL);
    if (err != noErr) {
	snprintf(errString, sizeof(errString), "AEDoScriptHandler: GetParamDesc error %d", (int)err);
	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString,
		      typeChar, errString, strlen(errString));
	return;
    }

    if (MissedAnyParameters((AppleEvent*)theDesc)) {
    	snprintf(errString, sizeof(errString), "AEDoScriptHandler: extra parameters");
    	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString,
		      typeChar,errString, strlen(errString));
    	return;
    }

    if (initialType == typeFileURL || initialType == typeAlias) {

	/*
	 * This descriptor can be coerced to a file url.  Construct a Tcl
	 * expression which passes the file path as a string argument to
         * ::tk::mac::DoScriptFile.
	 */
     */

	if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type,
                                  (Ptr) URLBuffer, URL_MAX_LENGTH, &actual)) {
            if (actual > 0) {
                URLBuffer[actual] = '\0';
                NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer];
                NSURL *fileURL = [NSURL URLWithString:urlString];
                AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
                Tcl_DString *scriptFileCommand = &AEInfo->command;
                Tcl_DStringInit(scriptFileCommand);
                Tcl_DStringAppend(scriptFileCommand, scriptFileProc, TCL_INDEX_NONE);
                Tcl_DStringAppendElement(scriptFileCommand, [[fileURL path] UTF8String]);
                AEInfo->interp = _eventInterp;
                AEInfo->procedure = scriptFileProc;
                AEInfo->replyEvent = nil;
		AEInfo->retryCount = 0;
                ProcessAppleEvent((void *)AEInfo);
            }
        }
    } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
			       NULL, 0, &actual)) {
        /*
         * The descriptor cannot be coerced to a file URL but can be coerced to
         * text.  Construct a Tcl expression which passes the text as a string
         * argument to ::tk::mac::DoScriptText.
         */

	if (actual > 0) {
	    char *data = (char *)ckalloc(actual + 1);
	    if (noErr == AEGetParamPtr(theDesc, keyDirectObject,
				       typeUTF8Text, &type,
				       data, actual, NULL)) {
		data[actual] = '\0';
		AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
		Tcl_DString *scriptTextCommand = &AEInfo->command;
		Tcl_DStringInit(scriptTextCommand);
		Tcl_DStringAppend(scriptTextCommand, scriptTextProc, TCL_INDEX_NONE);
		Tcl_DStringAppendElement(scriptTextCommand, data);
		AEInfo->interp = _eventInterp;
		AEInfo->procedure = scriptTextProc;
		AEInfo->retryCount = 0;
                if (Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
                    AEInfo->replyEvent = replyEvent;
                    ProcessAppleEvent(AEInfo);
                } else {
                    AEInfo->replyEvent = nil;
                    ProcessAppleEvent(AEInfo);
                }

	    }
	}
    }
}

- (void)handleURLEvent:(NSAppleEventDescriptor*)event
        withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
    NSString* url = [[event paramDescriptorForKeyword:keyDirectObject]
                        stringValue];
    const char *cURL=[url UTF8String];
    AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
    Tcl_DString *launchCommand = &AEInfo->command;
    (void)replyEvent;

    Tcl_DStringInit(launchCommand);
    Tcl_DStringAppend(launchCommand, launchURLProc, TCL_INDEX_NONE);
    Tcl_DStringAppendElement(launchCommand, cURL);
    AEInfo->interp = _eventInterp;
    AEInfo->procedure = launchURLProc;
    AEInfo->replyEvent = nil;
    AEInfo->retryCount = 0;
    ProcessAppleEvent((void *)AEInfo);
}

- (void)handleGetSDEFEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
     AppleEventInfo *AEInfo = (AppleEventInfo *)ckalloc(sizeof(AppleEventInfo));
    Tcl_DString *sdefCommand = &AEInfo->command;
    (void)event;
    (void)replyEvent;

    Tcl_DStringInit(sdefCommand);
    Tcl_DStringAppend(sdefCommand, getSdefProc, TCL_INDEX_NONE);
    AEInfo->interp = _eventInterp;
    AEInfo->procedure =  getSdefProc;
    AEInfo->replyEvent = nil;
    AEInfo->retryCount = 0;
    ProcessAppleEvent((void *)AEInfo);

}

@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * ProcessAppleEvent --
 *
 *      Usually used as an idle task which evaluates a Tcl expression generated
 *      from an AppleEvent.  If the AppleEventInfo passed as the client data
 *      has a non-null replyEvent, the result of evaluating the expression will
 *      be added to the reply.  This must not be done when this function is
 *      called as an idle task, but is done when handling DoScriptText events
 *      when this function is called directly.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The expression will be evaluated and the clientData will be freed.
 *      The replyEvent may be modified to contain the result of evaluating
 *      a Tcl expression.
 *
 *----------------------------------------------------------------------
 */

static void ProcessAppleEvent(
    void *clientData)
{
    int code;
    AppleEventInfo *AEInfo = (AppleEventInfo*) clientData;

    if (!AEInfo->interp) {
	return;
    }

    /*
     * Apple events that are delivered during the app startup can arrive
     * before the Tcl procedure for handling the events has been defined.
     * If the command is not found we create a timer handler to process
     * the event later, hopefully after the command has been created.
     * We retry up to 2 times before giving up.
     */

    if (!Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
	if (AEInfo->retryCount < 2) {
	    AEInfo->retryCount++;
	    Tcl_CreateTimerHandler(200, ProcessAppleEvent, clientData);
	} else {
	    ckfree(clientData);
	}
	return;
    }
    code = Tcl_EvalEx(AEInfo->interp, Tcl_DStringValue(&AEInfo->command),
	    Tcl_DStringLength(&AEInfo->command), TCL_EVAL_GLOBAL);
    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);

    if (AEInfo->replyEvent && code >= 0) {
        Tcl_Size reslen;
        const char *result = Tcl_GetStringFromObj(Tcl_GetObjResult(AEInfo->interp),
                                                  &reslen);
        if (code == TCL_OK) {
            AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
                          keyDirectObject, typeChar, result, reslen);
        } else {
            AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
                          keyErrorString, typeChar, result, reslen);
            AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
                          keyErrorNumber, typeSInt32, (Ptr) &code, sizeof(int));
        }
    } else if (code != TCL_OK) {
	Tcl_BackgroundException(AEInfo->interp, code);
    if (code != TCL_OK) {
	Tcl_BackgroundException(interp, code);
    }

    Tcl_DStringFree(&AEInfo->command);
    ckfree(clientData);
    Tcl_DStringFree(&command);
    return;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInitAppleEvents --
 *
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXInitAppleEvents(
    TCL_UNUSED(Tcl_Interp *))
    Tcl_Interp *interp)   /* not used */
{
    NSAppleEventManager *aeManager = [NSAppleEventManager sharedAppleEventManager];
    static Boolean initialized = FALSE;

    if (!initialized) {
	initialized = TRUE;

520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
408
409
410
411
412
413
414

415
416
417
418
419
420














421
422
423
424
425
426
427







-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    forEventClass:kCoreEventClass andEventID:kAEShowPreferences];

	[aeManager setEventHandler:NSApp
	    andSelector:@selector(handleOpenDocumentsEvent:withReplyEvent:)
	    forEventClass:kCoreEventClass andEventID:kAEOpenDocuments];

	[aeManager setEventHandler:NSApp
	    andSelector:@selector(handlePrintDocumentsEvent:withReplyEvent:)
	    andSelector:@selector(handleOpenDocumentsEvent:withReplyEvent:)
	    forEventClass:kCoreEventClass andEventID:kAEPrintDocuments];

	[aeManager setEventHandler:NSApp
	    andSelector:@selector(handleDoScriptEvent:withReplyEvent:)
	    forEventClass:kAEMiscStandards andEventID:kAEDoScript];

	[aeManager setEventHandler:NSApp
	    andSelector:@selector(handleURLEvent:withReplyEvent:)
	    forEventClass:kInternetEventClass andEventID:kAEGetURL];

	/*
	 * We do not load our sdef dynamically but this event handler
         * is required to silence error messages from inline execution
         * of AppleScript at the Objective-C level.
	 */
	[aeManager setEventHandler:NSApp
	    andSelector:@selector(handleGetSDEFEvent:withReplyEvent:)
	    forEventClass:'ascr' andEventID:'gsdf'];

    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDoHLEvent --
610
611
612
613
614
615
616
617

618
619
620
621

622
623
624

625
626
627
628
629
630
631
632
633
634
635
484
485
486
487
488
489
490

491
492
493
494

495



496


497

498
499
500
501
502
503
504







-
+



-
+
-
-
-
+
-
-

-







 *
 *----------------------------------------------------------------------
 */

static int
ReallyKillMe(
    Tcl_Event *eventPtr,
    TCL_UNUSED(int))
    int flags)
{
    Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
    int quit = Tcl_FindCommand(interp, "::tk::mac::Quit", NULL, 0)!=NULL;

    int code = Tcl_EvalEx(interp, quit ? "::tk::mac::Quit" : "exit", -1, TCL_EVAL_GLOBAL);
    if (!quit) {
	Tcl_Exit(0);
    }


    int code = Tcl_EvalEx(interp, "::tk::mac::Quit", TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
    if (code != TCL_OK) {

	/*
	 * Should be never reached...
	 */

	Tcl_BackgroundException(interp, code);
    }
    return 1;
659
660
661
662
663
664
665
666


667
668
669
670
671
672
673
674
675
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545







-
+
+









   Size actualSize;
   OSStatus err;

   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
	    typeWildCard, &returnedType, NULL, 0, &actualSize);

   return (err != errAEDescNotFound);
}
}


/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXImage.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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


















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXImage.c --
 *
 *	The code in this file provides an interface for XImages, and
 *      implements the nsimage image type.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2017-2021 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXConstants.h"
#include "tkMacOSXImage.h"
#include "tkColor.h"
#include "xbytes.h"

/* Pixel formats
 *
 * Tk uses the XImage structure defined in Xlib.h for storing images.  The
 * image data in an XImage is a 32-bit aligned array of bytes.  Interpretation
 * of that data is not specified, but the structure includes parameters which
 * provide interpretation hints so that an application can use a family of
 * different data structures.
 *
 * The possible values for the XImage format field are XYBitmap, XYPixmap and
 * ZPixmap.  The macOS port does not support the XYPixmap format.  This means
 * that bitmap images are stored as a single bit plane (XYBitmap) and that
 * color images are stored as a sequence of pixel values (ZPixmap).
 *
 * For a ZPixmap, the number of bits allocated to each pixel is specified by
 * the bits_per_pixel field of the XImage structure.  The functions in this
 * module which convert between XImage and native CGImage or NSImage structures
 * only support XImages with 32 bits per pixel.  The ImageGetPixel and PutPixel
 * implementations in this file allow 1, 4, 8, 16 or 32 bits per pixel, however.
 *
 * In tkImgPhInstance.c the layout used for pixels is determined by the values
 * of the red_mask, blue_mask and green_mask fields in the XImage structure.
 * The Aqua port always sets red_mask = 0xFF0000, green_mask = 0xFF00, and
 * blue_mask = 0xFF. This means that a 32bpp ZPixmap XImage uses ARGB32 pixels,
 * with small-endian byte order BGRA. The data array for such an XImage can be
 * passed directly to construct a CGBitmapImageRep if one specifies the
 * bitmapInfo as kCGBitmapByteOrder32Big | kCGImageAlphaLast.
 *
 * The structures below describe the bitfields in two common 32 bpp pixel
 * layouts.  Note that bit field layouts are compiler dependent. The layouts
 * shown in the comments are those produced by clang and gcc.  Also note
 * that kCGBitmapByteOrder32Big is consistently set when creating CGImages or
 * CGImageBitmapReps.
 */

/* RGBA32 0xRRGGBBAA (Byte order is RGBA on big-endian systems.)
 * This is used by NSBitmapImageRep when the bitmapFormat property is 0,
 * the default value.
 */

typedef struct RGBA32pixel_t {
    unsigned red: 8;
    unsigned green: 8;
    unsigned blue: 8;
    unsigned alpha: 8;
} RGBA32pixel;

/*
 * ARGB32 0xAARRGGBB (Byte order is ARGB on big-endian systems.)
 * This is used by Aqua Tk for XImages and by NSBitmapImageReps whose
 * bitmapFormat property is NSAlphaFirstBitmapFormat.
 */

typedef struct ARGB32pixel_t {
    unsigned blue: 8;
    unsigned green: 8;
    unsigned red: 8;
    unsigned alpha: 8;
} ARGB32pixel;

typedef union pixel32_t {
    unsigned int uint;
    RGBA32pixel rgba;
    ARGB32pixel argb;
} pixel32;

#pragma mark XImage handling

int
_XInitImageFuncPtrs(
    TCL_UNUSED(XImage *)) /* image */
{
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXCreateCGImageWithXImage --
 *
 *	Create CGImage from XImage, copying the image data.  Called
 *      in Tk_PutImage and (currently) nowhere else.
 *
 * Results:
 *	CGImage, release after use.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void ReleaseData(
    void *info,
    TCL_UNUSED(const void *), /* data */
    TCL_UNUSED(size_t))        /* size */
{
    ckfree(info);
}

static CGImageRef
TkMacOSXCreateCGImageWithXImage(
    XImage *image,
    uint32_t bitmapInfo)
{
    CGImageRef img = NULL;
    size_t bitsPerComponent, bitsPerPixel;
    size_t len = image->bytes_per_line * image->height;
    const CGFloat *decode = NULL;
    CGDataProviderRef provider = NULL;
    char *data = NULL;
    CGDataProviderReleaseDataCallback releaseData = ReleaseData;

    if (image->bits_per_pixel == 1) {
	/*
	 * BW image
	 */

	/* Reverses the sense of the bits */
	static const CGFloat decodeWB[2] = {1, 0};
	decode = decodeWB;

	bitsPerComponent = 1;
	bitsPerPixel = 1;
	data = (char *)ckalloc(len);
	if (data) {
	    if (image->bitmap_bit_order != MSBFirst) {
		char *srcPtr = image->data + image->xoffset;
		char *endPtr = srcPtr + len;
		char *destPtr = data;

		while (srcPtr < endPtr) {
		    *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))];
		}
	    } else {
		memcpy(data, image->data + image->xoffset, len);
	    }
	    provider = CGDataProviderCreateWithData(data, data, len,
		    releaseData);
	    if (!provider) {
		ckfree(data);
	    }
	    img = CGImageMaskCreate(image->width, image->height,
		    bitsPerComponent, bitsPerPixel, image->bytes_per_line,
		    provider, decode, 0);
	    CGDataProviderRelease(provider);
	}
    } else if ((image->format == ZPixmap) && (image->bits_per_pixel == 32)) {

	/*
	 * Color image
	 */

	if (image->width == 0 && image->height == 0) {

	    /*
	     * CGCreateImage complains on early macOS releases.
	     */

	    return NULL;
	}
	CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
	bitsPerComponent = 8;
	bitsPerPixel = 32;
	data = (char *)ckalloc(len);
	if (data) {
	    memcpy(data, image->data + image->xoffset, len);
	    provider = CGDataProviderCreateWithData(data, data, len,
		    releaseData);
	    if (!provider) {
		ckfree(data);
	    }
	    img = CGImageCreate(image->width, image->height, bitsPerComponent,
		    bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo,
		    provider, decode, 0, kCGRenderingIntentDefault);
	    CGDataProviderRelease(provider);
	}
	if (colorspace) {
	    CFRelease(colorspace);
	}
    } else {
	TkMacOSXDbgMsg("Unsupported image type");
    }
    return img;
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyImage --
 *
 *	Destroys storage associated with an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Deallocates the image.
 *
 *----------------------------------------------------------------------
 */

static int
DestroyImage(
    XImage *image)
{
    if (image) {
	if (image->data) {
	    ckfree(image->data);
	}
	ckfree(image);
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageGetPixel --
 *
 *	Get a single pixel from an image.
 *
 * Results:
 *      The XColor structure contains an unsigned long field named pixel which
 *      identifies the color.  This function returns the unsigned long that
 *      would be used as the pixel value of an XColor that has the same red
 *      green and blue components as the XImage pixel at the specified
 *      location.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static unsigned long
ImageGetPixel(
    XImage *image,
    int x,
    int y)
{
    unsigned char r = 0, g = 0, b = 0;

    /*
     * Compute 8 bit red green and blue values, which are passed as inputs to
     * TkMacOSXRGBPixel to produce the pixel value.
     */

    if (image && image->data) {
	unsigned char *srcPtr = ((unsigned char*) image->data)
		+ (y * image->bytes_per_line)
		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);

	switch (image->bits_per_pixel) {
	case 32: /* 8 bits per channel */
	    {
		ARGB32pixel *pixel = (ARGB32pixel *)srcPtr;
		r = pixel->red;
		g = pixel->green;
		b = pixel->blue;
	    }
	    break;
	case 16: /* 5 bits per channel */
	    r = (*((unsigned short*) srcPtr) >> 7) & 0xf8;
	    g = (*((unsigned short*) srcPtr) >> 2) & 0xf8;
	    b = (*((unsigned short*) srcPtr) << 3) & 0xf8;
	    break;
	case 8: /* 2 bits per channel */
	    r = (*srcPtr << 2) & 0xc0;
	    g = (*srcPtr << 4) & 0xc0;
	    b = (*srcPtr << 6) & 0xc0;
	    r |= r >> 2 | r >> 4 | r >> 6;
	    g |= g >> 2 | g >> 4 | g >> 6;
	    b |= b >> 2 | b >> 4 | b >> 6;
	    break;
	case 4: { /* 1 bit per channel */
	    unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4);

	    r = (c & 0x04) ? 0xff : 0;
	    g = (c & 0x02) ? 0xff : 0;
	    b = (c & 0x01) ? 0xff : 0;
	    break;
	}
	case 1: /* Black-white bitmap. */
	    r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0;
	    break;
	}
    }

    return TkMacOSXRGBPixel(r, g, b);
}

/*
 *----------------------------------------------------------------------
 *
 * ImagePutPixel --
 *
 *	Set a single pixel in an image.  The pixel is provided as an unsigned
 *      32-bit integer.  The value of that integer is interpreted by assuming
 *      that its low-order N bits have the format specified by the XImage,
 *      where N is equal to the bits_per_pixel field of the XImage.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
ImagePutPixel(
    XImage *image,
    int x,
    int y,
    unsigned long pixel)
{
    if (image && image->data) {
	unsigned char *dstPtr = ((unsigned char*) image->data)
		+ (y * image->bytes_per_line)
		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);

	if (image->bits_per_pixel == 32) {
	    *((unsigned int*) dstPtr) = pixel;
	} else {
	    switch (image->bits_per_pixel) {
	    case 16:
		*((unsigned short*) dstPtr) = pixel & 0xffff;
		break;
	    case 8:
		*dstPtr = pixel & 0xff;
		break;
	    case 4: {
		*dstPtr = (x % 2) ? ((*dstPtr & 0xf0) | (pixel & 0x0f)) :
			((*dstPtr & 0x0f) | ((pixel << 4) & 0xf0));
		break;
		}
	    case 1:
		*dstPtr = pixel ? (*dstPtr | (0x80 >> (x % 8))) :
			(*dstPtr & ~(0x80 >> (x % 8)));
		break;
	    }
	}
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * XCreateImage --
 *
 *	Allocates storage for a new XImage.
 *
 * Results:
 *	Returns a newly allocated XImage.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

XImage *
XCreateImage(
    Display* display,
    TCL_UNUSED(Visual*), /* visual */
    unsigned int depth,
    int format,
    int offset,
    char* data,
    unsigned int width,
    unsigned int height,
    int bitmap_pad,
    int bytes_per_line)
{
    XImage *ximage;

    LastKnownRequestProcessed(display)++;
    ximage = (XImage *)ckalloc(sizeof(XImage));

    ximage->height = height;
    ximage->width = width;
    ximage->depth = depth;
    ximage->xoffset = offset;
    ximage->format = format;
    ximage->data = data;
    ximage->obdata = NULL;

    if (format == ZPixmap) {
	ximage->bits_per_pixel = 32;
	ximage->bitmap_unit = 32;
    } else {
	ximage->bits_per_pixel = 1;
	ximage->bitmap_unit = 8;
    }
    if (bitmap_pad) {
	ximage->bitmap_pad = bitmap_pad;
    } else {
	/*
	 * Use 16 byte alignment for best Quartz performance.
	 */

	ximage->bitmap_pad = 128;
    }
    if (bytes_per_line) {
	ximage->bytes_per_line = bytes_per_line;
    } else {
	ximage->bytes_per_line = ((width * ximage->bits_per_pixel +
		(ximage->bitmap_pad - 1)) >> 3) &
		~((ximage->bitmap_pad >> 3) - 1);
    }
#ifdef WORDS_BIGENDIAN
    ximage->byte_order = MSBFirst;
    ximage->bitmap_bit_order = MSBFirst;
#else
    ximage->byte_order = LSBFirst;
    ximage->bitmap_bit_order = LSBFirst;
#endif
    ximage->red_mask = 0x00FF0000;
    ximage->green_mask = 0x0000FF00;
    ximage->blue_mask = 0x000000FF;
    ximage->f.create_image = NULL;
    ximage->f.destroy_image = DestroyImage;
    ximage->f.get_pixel = ImageGetPixel;
    ximage->f.put_pixel = ImagePutPixel;
    ximage->f.sub_image = NULL;
    ximage->f.add_pixel = NULL;

    return ximage;
}

/*
 *----------------------------------------------------------------------
 *
 * TkPutImage, XPutImage, TkpPutRGBAImage --
 *
 *	These functions, which all have the same signature, copy a rectangular
 *      subimage of an XImage into a drawable.  TkPutImage is an alias for
 *      XPutImage, which assumes that the XImage data has the structure of a
 *      32bpp ZPixmap in which the image data is an array of 32bit integers
 *      packed with 8 bit values for the Red Green and Blue channels.  The
 *      fourth byte is ignored.  The function TkpPutRGBAImage assumes that the
 *      XImage data has been extended by using the fourth byte to store an
 *      8-bit Alpha value.  (The Alpha data is assumed not to pre-multiplied).
 *      The image is then drawn into the drawable using standard Porter-Duff
 *      Source Atop Composition (kCGBlendModeSourceAtop in Apple's Core
 *      Graphics).
 *
 *      The TkpPutRGBAImage function is used by TkImgPhotoDisplay to render photo
 *      images if the compile-time variable TK_CAN_RENDER_RGBA is defined in
 *      a platform's tkXXXXPort.h header, as is the case for the macOS Aqua port.
 *
 * Results:
 *	These functions return either BadDrawable or Success.
 *
 * Side effects:
 *	Draws the image on the specified drawable.
 *
 *----------------------------------------------------------------------
 */

#define USE_ALPHA (kCGImageAlphaLast | kCGBitmapByteOrder32Big)
#define IGNORE_ALPHA (kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little)

static int
TkMacOSXPutImage(
    uint32_t pixelFormat,
    Display* display,		/* Display. */
    Drawable drawable,		/* Drawable to place image on. */
    GC gc,			/* GC to use. */
    XImage* image,		/* Image to place. */
    int src_x,			/* Source X & Y. */
    int src_y,
    int dest_x,			/* Destination X & Y. */
    int dest_y,
    unsigned int width,	        /* Same width & height for both */
    unsigned int height)	/* destination and source. */
{
    TkMacOSXDrawingContext dc;
    MacDrawable *macDraw = (MacDrawable *)drawable;
    int result = Success;

    if (width <= 0 || height <= 0) {
	return Success; /* Is OK. Nothing to see here, literally. */
    }
    LastKnownRequestProcessed(display)++;
    if (!TkMacOSXSetupDrawingContext(drawable, gc, &dc)) {
	return BadDrawable;
    }
    if (dc.context) {
	CGRect bounds, srcRect, dstRect;
	CGImageRef img = TkMacOSXCreateCGImageWithXImage(image, pixelFormat);

	/*
	 * The CGContext for a pixmap is RGB only, with A = 0.
	 */

	if (!(macDraw->flags & TK_IS_PIXMAP)) {
	    CGContextSetBlendMode(dc.context, kCGBlendModeSourceAtop);
	}
	if (img) {
	    bounds = CGRectMake(0, 0, image->width, image->height);
	    srcRect = CGRectMake(src_x, src_y, width, height);
	    dstRect = CGRectMake(dest_x, dest_y, width, height);
	    TkMacOSXDrawCGImage(drawable, gc, dc.context,
				img, gc->foreground, gc->background,
				bounds, srcRect, dstRect);
	    CFRelease(img);
	} else {
	    TkMacOSXDbgMsg("Invalid source drawable");
	    result = BadDrawable;
	}
    } else {
	TkMacOSXDbgMsg("Invalid destination drawable");
	result = BadDrawable;
    }
    TkMacOSXRestoreDrawingContext(&dc);
    return result;
}

int XPutImage(
    Display* display,
    Drawable drawable,
    GC gc,
    XImage* image,
    int src_x,
    int src_y,
    int dest_x,
    int dest_y,
    unsigned int width,
    unsigned int height) {
    return TkMacOSXPutImage(IGNORE_ALPHA, display, drawable, gc, image,
			    src_x, src_y, dest_x, dest_y, width, height);
}

int TkpPutRGBAImage(
    Display* display,
    Drawable drawable,
    GC gc,
    XImage* image,
    int src_x,
    int src_y,
    int dest_x,
    int dest_y,
    unsigned int width,
    unsigned int height) {
    return TkMacOSXPutImage(USE_ALPHA, display, drawable, gc, image,
		     src_x, src_y, dest_x, dest_y, width, height);
}


/*
 *----------------------------------------------------------------------
 *
 * CreateCGImageFromDrawableRect
 *
 *	Extract image data from a MacOSX drawable as a CGImage.  The drawable
 *      may be either a pixmap or a window, but there issues in the case of
 *      a window.
 *
 *      CreateCGImageFromDrawableRect is called by XGetImage and XCopyArea.
 *      The Tk core uses these two functions on some platforms in order to
 *      implement explicit double-buffered drawing -- a pixmap is copied from a
 *      window, modified using CPU-based graphics composition, and then copied
 *      back to the window.  Platforms, such as macOS, on which the system
 *      provides double-buffered drawing and GPU-based composition operations
 *      can avoid calls to XGetImage and XCopyArea from the core by defining
 *      the compile-time variable TK_NO_DOUBLE_BUFFERING.  Nonetheless, these
 *      two functions are in the stubs table and therefore could be used by
 *      extensions.
 *
 *      The implementation here does not always work correctly when the source
 *      is a window.  The original version of this function relied on
 *      [NSBitmapImageRep initWithFocusedViewRect:view_rect] which was
 *      deprecated by Apple in OSX 10.14 and also required the use of other
 *      deprecated functions such as [NSView lockFocus]. Apple's suggested
 *      replacement is [NSView cacheDisplayInRect: toBitmapImageRep:] and that
 *      is being used here.  However, cacheDisplayInRect works by calling
 *      [NSView drawRect] after setting the current graphics context to be one
 *      which draws to a bitmap.  There are situations in which this can be
 *      used, e.g. when taking a screenshot of a window.  But it cannot be used
 *      as part of a normal display procedure, using the copy-modify-paste
 *      paradigm that is the basis of the explicit double-buffering.  Since the
 *      copy operation will call the same display procedure that is calling
 *      this function via XGetImage or XCopyArea, this would create an infinite
 *      recursion.
 *
 *      An alternative to the copy-modify-paste paradigm is to use GPU-based
 *      graphics composition, clipping to the specified rectangle.  That is
 *      the approach that must be followed by display procedures on macOS.
 *
 * Results:
 *	Returns an NSBitmapRep representing the image of the given rectangle of
 *      the given drawable. This object is retained. The caller is responsible
 *      for releasing it.
 *
 *      NOTE: The x,y coordinates should be relative to a coordinate system
 *      with origin at the top left, as used by XImage and CGImage, not bottom
 *      left as used by NSView.
 *
 * Side effects:
 *     None
 *
 *----------------------------------------------------------------------
 */

static CGImageRef
CreateCGImageFromDrawableRect(
    Drawable drawable,
    int x,
    int y,
    unsigned int width,
    unsigned int height)
{
    MacDrawable *mac_drawable = (MacDrawable *)drawable;
    CGContextRef cg_context = NULL;
    CGImageRef cg_image = NULL, result = NULL;
    if (mac_drawable->flags & TK_IS_PIXMAP) {
	cg_context = TkMacOSXGetCGContextForDrawable(drawable);
	CGContextRetain(cg_context);
    } else {
	NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable);
	if (view == nil) {
	    TkMacOSXDbgMsg("Invalid source drawable");
	    return NULL;
	}
	NSSize size = view.frame.size;
	NSUInteger view_width = size.width, view_height = size.height;
        NSUInteger bytesPerPixel = 4,
	    bytesPerRow = bytesPerPixel * view_width,
	    bitsPerComponent = 8;
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	cg_context = CGBitmapContextCreate(NULL, view_width, view_height,
			 bitsPerComponent, bytesPerRow, colorSpace,
			 kCGImageAlphaPremultipliedLast |
			 kCGBitmapByteOrder32Big);
	CFRelease(colorSpace);
	[view.layer renderInContext:cg_context];
    }
    if (cg_context) {
	cg_image = CGBitmapContextCreateImage(cg_context);
	CGContextRelease(cg_context);
    }
    if (cg_image) {
	CGRect rect = CGRectMake(x + mac_drawable->xOff, y + mac_drawable->yOff,
				 width, height);
	result = CGImageCreateWithImageInRect(cg_image, rect);
	CGImageRelease(cg_image);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * CreatePDFFromDrawableRect
 *
 *	Extract PDF data from a MacOSX drawable.
 *
 * Results:
 *	Returns a CFDataRef that can be written to a file.
 *
 *      NOTE: The x,y coordinates should be relative to a coordinate system
 *      with origin at the bottom left as used by NSView,  not top left
 *      as used by XImage and CGImage.
 *
 * Side effects:
 *     None
 *
 *----------------------------------------------------------------------
 */

CFDataRef
CreatePDFFromDrawableRect(
			  Drawable drawable,
			  int x,
			  int y,
			  unsigned int width,
			  unsigned int height)
{
    MacDrawable *mac_drawable = (MacDrawable *)drawable;
    NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable);
    if (view == nil) {
	TkMacOSXDbgMsg("Invalid source drawable");
	return NULL;
    }
    NSRect bounds, viewSrcRect;

    /*
     * Get the child window area in NSView coordinates
     * (origin at bottom left).
     */

    bounds = [view bounds];
    viewSrcRect = NSMakeRect(mac_drawable->xOff + x,
			     bounds.size.height - height - (mac_drawable->yOff + y),
			     width, height);
    NSData *viewData = [view dataWithPDFInsideRect:viewSrcRect];
    CFDataRef result = (CFDataRef)viewData;
    return result;
}


/*
 *----------------------------------------------------------------------
 *
 * CreateCGImageFromPixmap --
 *
 *	Create a CGImage from an X Pixmap.
 *
 * Results:
 *	CGImage, release after use.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static CGImageRef
CreateCGImageFromPixmap(
    Drawable pixmap)
{
    CGImageRef img = NULL;
    CGContextRef context = TkMacOSXGetCGContextForDrawable(pixmap);

    if (context) {
	img = CGBitmapContextCreateImage(context);
    }
    return img;
}

/*
 *----------------------------------------------------------------------
 *
 * XGetImage --
 *
 *	This function copies data from a pixmap or window into an XImage.  It
 *      is essentially never used. At one time it was called by
 *      pTkImgPhotoDisplay, but that is no longer the case. Currently it is
 *      called two places, one of which is requesting an XY image which we do
 *      not support.  It probably does not work correctly -- see the comments
 *      for CGImageFromDrawableRect.
 *
 * Results:
 *	Returns a newly allocated XImage containing the data from the given
 *	rectangle of the given drawable, or NULL if the XImage could not be
 *	constructed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

XImage *
XGetImage(
    Display *display,
    Drawable drawable,
    int x,
    int y,
    unsigned int width,
    unsigned int height,
    TCL_UNUSED(unsigned long),  /* plane_mask */
    int format)
{
    NSBitmapImageRep* bitmapRep = nil;
    NSUInteger bitmap_fmt = 0;
    XImage* imagePtr = NULL;
    char *bitmap = NULL;
    int depth = 32, offset = 0, bitmap_pad = 0;
    unsigned int bytes_per_row, size, row, n, m;

    if (format == ZPixmap) {
	CGImageRef cgImage;
	if (width == 0 || height == 0) {
	    return NULL;
	}

	cgImage = CreateCGImageFromDrawableRect(drawable, x, y, width, height);
	if (cgImage) {
	    bitmapRep = [NSBitmapImageRep alloc];
	    [bitmapRep initWithCGImage:cgImage];
	    CFRelease(cgImage);
	} else {
	    TkMacOSXDbgMsg("XGetImage: Failed to construct CGImage");
	    return NULL;
	}
	bitmap_fmt = [bitmapRep bitmapFormat];
	size = [bitmapRep bytesPerPlane];
	bytes_per_row = [bitmapRep bytesPerRow];
	if ((bitmap_fmt != 0 && bitmap_fmt != NSAlphaFirstBitmapFormat)
	    || [bitmapRep samplesPerPixel] != 4
	    || [bitmapRep isPlanar] != 0
	    || bytes_per_row < 4 * width
	    || size != bytes_per_row * height) {
	    TkMacOSXDbgMsg("XGetImage: Unrecognized bitmap format");
	    [bitmapRep release];
	    return NULL;
	}
	bitmap = (char *)ckalloc(size);
	memcpy(bitmap, (char *)[bitmapRep bitmapData], size);
	[bitmapRep release];

	for (row = 0, n = 0; row < height; row++, n += bytes_per_row) {
	    for (m = n; m < n + 4*width; m += 4) {
		pixel32 pixel = *((pixel32 *)(bitmap + m));
		if (bitmap_fmt == 0) { // default format

		    /*
		     * This pixel is in ARGB32 format.  We need RGBA32.
		     */

		    pixel32 flipped;
		    flipped.rgba.red = pixel.argb.red;
		    flipped.rgba.green = pixel.argb.green;
		    flipped.rgba.blue = pixel.argb.blue;
		    flipped.rgba.alpha = pixel.argb.alpha;
		    *((pixel32 *)(bitmap + m)) = flipped;
		} else { // bitmap_fmt = NSAlphaFirstBitmapFormat
		    *((pixel32 *)(bitmap + m)) = pixel;
		}
	    }
	}
	imagePtr = XCreateImage(display, NULL, depth, format, offset,
		(char*) bitmap, width, height,
		bitmap_pad, bytes_per_row);
    } else {

	/*
	 * There are some calls to XGetImage in the generic Tk code which pass
	 * an XYPixmap rather than a ZPixmap.  XYPixmaps should be handled
	 * here.
	 */

	TkMacOSXDbgMsg("XGetImage does not handle XYPixmaps at the moment.");
    }
    return imagePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * XCopyArea --
 *
 *	Copies image data from one drawable to another.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Image data is moved from a window or bitmap to a second window or bitmap.
 *
 *----------------------------------------------------------------------
 */

int
XCopyArea(
    Display *display,		/* Display. */
    Drawable src,		/* Source drawable. */
    Drawable dst,		/* Destination drawable. */
    GC gc,			/* GC to use. */
    int src_x,			/* X & Y, width & height */
    int src_y,			/* define the source rectangle */
    unsigned int width,		/* that will be copied. */
    unsigned int height,
    int dest_x,			/* Dest X & Y on dest rect. */
    int dest_y)
{
    TkMacOSXDrawingContext dc;
    MacDrawable *srcDraw = (MacDrawable *)src;
    CGImageRef img = NULL;
    CGRect bounds, srcRect, dstRect;

    LastKnownRequestProcessed(display)++;
    if (!width || !height) {
	return BadDrawable;
    }

    if (!TkMacOSXSetupDrawingContext(dst, gc, &dc)) {
	TkMacOSXDbgMsg("Failed to setup drawing context.");
	return BadDrawable;
    }

    if (!dc.context) {
	TkMacOSXDbgMsg("Invalid destination drawable - no context.");
	return BadDrawable;
    }

    if (srcDraw->flags & TK_IS_PIXMAP) {
	img = CreateCGImageFromPixmap(src);
    } else if (TkMacOSXGetNSWindowForDrawable(src)) {
	img = CreateCGImageFromDrawableRect(src, src_x, src_y, width, height);
    } else {
	TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
    }

    if (img) {
	bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
	srcRect = CGRectMake(src_x, src_y, width, height);
	dstRect = CGRectMake(dest_x, dest_y, width, height);
	TkMacOSXDrawCGImage(dst, gc, dc.context, img,
		gc->foreground, gc->background, bounds, srcRect, dstRect);
	CFRelease(img);
    } else {
	TkMacOSXDbgMsg("Failed to construct CGImage.");
    }

    TkMacOSXRestoreDrawingContext(&dc);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XCopyPlane --
 *
 *	Copies a bitmap from a source drawable to a destination drawable. The
 *	plane argument specifies which bit plane of the source contains the
 *	bitmap. Note that this implementation ignores the gc->function.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes the destination drawable.
 *
 *----------------------------------------------------------------------
 */

int
XCopyPlane(
    Display *display,		/* Display. */
    Drawable src,		/* Source drawable. */
    Drawable dst,		/* Destination drawable. */
    GC gc,				/* GC to use. */
    int src_x,			/* X & Y, width & height */
    int src_y,			/* define the source rectangle */
    unsigned int width,	/* that will be copied. */
    unsigned int height,
    int dest_x,			/* Dest X & Y on dest rect. */
    int dest_y,
    unsigned long plane)	/* Which plane to copy. */
{
    TkMacOSXDrawingContext dc;
    MacDrawable *srcDraw = (MacDrawable *)src;
    MacDrawable *dstDraw = (MacDrawable *)dst;
    CGRect bounds, srcRect, dstRect;
    LastKnownRequestProcessed(display)++;
    if (!width || !height) {
	/* TkMacOSXDbgMsg("Drawing of empty area requested"); */
	return BadDrawable;
    }
    if (plane != 1) {
	Tcl_Panic("Unexpected plane specified for XCopyPlane");
    }
    if (srcDraw->flags & TK_IS_PIXMAP) {
	if (!TkMacOSXSetupDrawingContext(dst, gc, &dc)) {
	    return BadDrawable;
	}

	CGContextRef context = dc.context;

	if (context) {
	    CGImageRef img = CreateCGImageFromPixmap(src);

	    if (img) {
		TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
		unsigned long imageBackground  = gc->background;

                if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) {
		    srcRect = CGRectMake(src_x, src_y, width, height);
		    CGImageRef mask = CreateCGImageFromPixmap(
			    clipPtr->value.pixmap);
		    CGImageRef submask = CGImageCreateWithImageInRect(
			    img, srcRect);
		    CGRect rect = CGRectMake(dest_x, dest_y, width, height);

		    rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
		    CGContextSaveGState(context);

		    /*
		     * Move the origin of the destination to top left.
		     */

		    CGContextTranslateCTM(context,
			    0, rect.origin.y + CGRectGetMaxY(rect));
		    CGContextScaleCTM(context, 1, -1);

		    /*
		     * Fill with the background color, clipping to the mask.
		     */

		    CGContextClipToMask(context, rect, submask);
		    TkMacOSXSetColorInContext(gc, gc->background, dc.context);
		    CGContextFillRect(context, rect);

		    /*
		     * Fill with the foreground color, clipping to the
		     * intersection of img and mask.
		     */

		    CGImageRef subimage = CGImageCreateWithImageInRect(
			    img, srcRect);
		    CGContextClipToMask(context, rect, subimage);
		    TkMacOSXSetColorInContext(gc, gc->foreground, context);
		    CGContextFillRect(context, rect);
		    CGContextRestoreGState(context);
		    CGImageRelease(img);
		    CGImageRelease(mask);
		    CGImageRelease(submask);
		    CGImageRelease(subimage);
		} else {
		    bounds = CGRectMake(0, 0,
			    srcDraw->size.width, srcDraw->size.height);
		    srcRect = CGRectMake(src_x, src_y, width, height);
		    dstRect = CGRectMake(dest_x, dest_y, width, height);
		    TkMacOSXDrawCGImage(dst, gc, dc.context, img,
			    gc->foreground, imageBackground, bounds,
			    srcRect, dstRect);
		    CGImageRelease(img);
		}
	    } else {
		/* no image */
		TkMacOSXDbgMsg("Invalid source drawable");
	    }
	} else {
	    TkMacOSXDbgMsg("Invalid destination drawable - "
		    "could not get a bitmap context.");
	}
	TkMacOSXRestoreDrawingContext(&dc);
	return Success;
    } else {
	/*
	 * Source drawable is a Window, not a Pixmap.
	 */

	return XCopyArea(display, src, dst, gc, src_x, src_y, width, height,
		dest_x, dest_y);
    }
}

/* ---------------------------------------------------------------------------*/

/*
 * Implementation of a Tk image type which provide access to NSImages
 * for use in buttons etc.
 */

/*
 * Forward declarations.
 */

typedef struct TkMacOSXNSImageInstance TkMacOSXNSImageInstance;
typedef struct TkMacOSXNSImageModel TkMacOSXNSImageModel;

/*
 * The following data structure represents a particular use of an nsimage
 * in a widget.
 */

struct TkMacOSXNSImageInstance {
    TkMacOSXNSImageModel *modelPtr;   /* Pointer to the model for the image. */
    NSImage *image;		  /* Pointer to an NSImage.*/
    TkMacOSXNSImageInstance *nextPtr;   /* First in the list of instances associated
				   * with this model. */
};

/*
 * The following data structure represents the model for an nsimage:
 */

struct TkMacOSXNSImageModel {
    Tk_ImageModel tkModel;	      /* Tk's token for image model. */
    Tcl_Interp *interp;		      /* Interpreter for application. */
    int width, height;		      /* Dimensions of the image. */
    int radius;                       /* Radius for rounded corners. */
    int ring;                         /* Thickness of the focus ring. */
    double alpha;                     /* Transparency, between 0.0 and 1.0*/
    char *imageName ;                 /* Malloc'ed image name. */
    char *source;       	      /* Malloc'ed string describing the image. */
    char *as;                         /* Malloc'ed interpretation of source */
    int	flags;			      /* Sundry flags, defined below. */
    bool pressed;                     /* Image is for use in a pressed button.*/
    bool templ;                       /* Image is for use as a template.*/
    TkMacOSXNSImageInstance *instancePtr;   /* Start of list of instances associated
				       * with this model. */
    NSImage *image;                   /* The underlying NSImage object. */
    NSImage *darkModeImage;           /* A modified image to use in Dark Mode. */
};

/*
 * Bit definitions for the flags field of a TkMacOSXNSImageModel.
 * IMAGE_CHANGED:		1 means that the instances of this image need
 *				to be redisplayed.
 */

#define IMAGE_CHANGED		1

/*
 * The type record for nsimage images:
 */

static int		TkMacOSXNSImageCreate(Tcl_Interp *interp,
			    const char *name, Tcl_Size objc, Tcl_Obj *const objv[],
			    const Tk_ImageType *typePtr, Tk_ImageModel model,
			    void **clientDataPtr);
static void *TkMacOSXNSImageGet(Tk_Window tkwin, void *clientData);
static void		TkMacOSXNSImageDisplay(void *clientData,
			    Display *display, Drawable drawable,
			    int imageX, int imageY, int width,
			    int height, int drawableX,
			    int drawableY);
static void		TkMacOSXNSImageFree(void *clientData, Display *display);
static void		TkMacOSXNSImageDelete(void *clientData);

static Tk_ImageType TkMacOSXNSImageType = {
    "nsimage",			/* name of image type */
    TkMacOSXNSImageCreate,		/* createProc */
    TkMacOSXNSImageGet,		/* getProc */
    TkMacOSXNSImageDisplay,		/* displayProc */
    TkMacOSXNSImageFree,		/* freeProc */
    TkMacOSXNSImageDelete,		/* deleteProc */
    NULL,			/* postscriptPtr */
    NULL,			/* nextPtr */
    NULL
};

/*
 * Default values used for parsing configuration specifications:
 */
#define DEF_SOURCE   ""
#define DEF_AS       "name"
#define DEF_HEIGHT   "0"
#define DEF_WIDTH    "0"
#define DEF_RADIUS   "0"
#define DEF_RING     "0"
#define DEF_ALPHA    "1.0"
#define DEF_PRESSED  "0"
#define DEF_TEMPLATE "0"

static const Tk_OptionSpec systemImageOptions[] = {
    {TK_OPTION_STRING, "-source", NULL, NULL, DEF_SOURCE,
     -1, offsetof(TkMacOSXNSImageModel, source), 0, NULL, 0},
    {TK_OPTION_STRING, "-as", NULL, NULL, DEF_AS,
     -1, offsetof(TkMacOSXNSImageModel, as), 0, NULL, 0},
    {TK_OPTION_INT, "-width", NULL, NULL, DEF_WIDTH,
     -1, offsetof(TkMacOSXNSImageModel, width), 0, NULL, 0},
    {TK_OPTION_INT, "-height", NULL, NULL, DEF_HEIGHT,
     -1, offsetof(TkMacOSXNSImageModel, height), 0, NULL, 0},
    {TK_OPTION_INT, "-radius", NULL, NULL, DEF_RADIUS,
     -1, offsetof(TkMacOSXNSImageModel, radius), 0, NULL, 0},
    {TK_OPTION_INT, "-ring", NULL, NULL, DEF_RING,
     -1, offsetof(TkMacOSXNSImageModel, ring), 0, NULL, 0},
    {TK_OPTION_DOUBLE, "-alpha", NULL, NULL, DEF_ALPHA,
     -1, offsetof(TkMacOSXNSImageModel, alpha), 0, NULL, 0},
    {TK_OPTION_BOOLEAN, "-pressed", NULL, NULL, DEF_PRESSED,
     -1, offsetof(TkMacOSXNSImageModel, pressed), TK_OPTION_VAR(bool), NULL, 0},
    {TK_OPTION_BOOLEAN, "-template", NULL, NULL, DEF_TEMPLATE,
     -1, offsetof(TkMacOSXNSImageModel, templ), TK_OPTION_VAR(bool), NULL, 0},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, NULL, 0}
};

/*
 * The -as option specifies how the string provided in the -source
 * option should be interpreted as a description of an NSImage.
 * Below are the possible values and their meanings.  (The last two
 * provide the macOS icon for a particular file type.)
 */

static const char *sourceInterpretations[] = {
    "name",       /* A name for a named NSImage. */
    "file",       /* A path to an image file. */
    "path",       /* A path to a file whose type should be examined. */
    "filetype",   /* A file extension or 4-byte OSCode. */
};

enum {NAME_SOURCE, FILE_SOURCE, PATH_SOURCE, FILETYPE_SOURCE};


/*
 *----------------------------------------------------------------------
 *
 * TintImage --
 *
 *      Modify an NSImage by blending it with a color.  The transparent part of
 *      the image remains transparent.  The opaque part of the image is painted
 *      with the color, using the specified alpha value for the transparency of
 *      the color.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The appearance of the NSImage changes.
 *
 *----------------------------------------------------------------------
 */

static void TintImage(
    NSImage *image,
    NSColor *color,
    double alpha)
{
    NSSize size = [image size];
    NSRect rect = {NSZeroPoint, size};
    NSImage *mask = [[[NSImage alloc] initWithSize:size] retain];
    [mask lockFocus];
    [color set];
    NSRectFillUsingOperation(rect, NSCompositeCopy);
    [image drawInRect:rect
	     fromRect:rect
	    operation:NSCompositeDestinationIn
	     fraction:1.0];
    [mask unlockFocus];
    [image lockFocus];
    [mask drawInRect:rect
	    fromRect:rect
	   operation:NSCompositeSourceOver
	    fraction:alpha];
    [image unlockFocus];
    [mask release];
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageConfigureModel --
 *
 *	This function is called when an nsimage image is created or
 *	reconfigured.  It processes configuration options and resets any
 *	instances of the image.
 *
 * Results:
 *	A standard Tcl return value. If TCL_ERROR is returned then an error
 *	message is left in the modelPtr->interp's result.
 *
 * Side effects:
 *	Existing instances of the image will be redisplayed to match the new
 *	configuration options.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXNSImageConfigureModel(
    Tcl_Interp *interp,		   /* Interpreter to use for reporting errors. */
    TkMacOSXNSImageModel *modelPtr,    /* Pointer to data structure describing
				    * overall photo image to (re)configure. */
    Tcl_Size objc,			   /* Number of entries in objv. */
    Tcl_Obj *const objv[])	   /* Pairs of configuration options for image. */
{
    Tk_OptionTable optionTable = Tk_CreateOptionTable(interp, systemImageOptions);
    NSImage *newImage;
    Tcl_Obj *objPtr;
    static Tcl_Obj *asOption = NULL;
    int sourceInterpretation;
    NSString *source;
    int oldWidth = modelPtr->width, oldHeight = modelPtr->height;

    if (asOption == NULL) {
	asOption = Tcl_NewStringObj("-as", TCL_INDEX_NONE);
	Tcl_IncrRefCount(asOption);
    }

    modelPtr->width = 0;
    modelPtr->height = 0;
    if (Tk_SetOptions(interp, modelPtr, optionTable, objc, objv,
		      NULL, NULL, NULL) != TCL_OK){
	goto errorExit;
    }
    if (modelPtr->width == 0 && modelPtr->height == 0) {
	modelPtr->width = oldWidth;
	modelPtr->height = oldHeight;
    }

    if (modelPtr->source == NULL || modelPtr->source[0] == '0') {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("-source is required.", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
	goto errorExit;
    }

    objPtr = Tk_GetOptionValue(interp, (char *) modelPtr, optionTable,
				asOption, NULL);
    if (Tcl_GetIndexFromObj(interp, objPtr, sourceInterpretations, "option",
			    0, &sourceInterpretation) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    "Unknown interpretation for source in -as option.  "
	    "Should be name, file, path, or filetype.", TCL_INDEX_NONE));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
	goto errorExit;
    }

    source = [[NSString alloc] initWithUTF8String: modelPtr->source];
    switch (sourceInterpretation) {
    case NAME_SOURCE:
	newImage = [[NSImage imageNamed:source] copy];
	break;
    case FILE_SOURCE:
	newImage = [[NSImage alloc] initWithContentsOfFile:source];
	break;
    case PATH_SOURCE:
	newImage = [[NSWorkspace sharedWorkspace] iconForFile:source];
	break;
    case FILETYPE_SOURCE:
	newImage = TkMacOSXIconForFileType(source);
	break;
    default:
	newImage = NULL;
	break;
    }
    [source release];
    if (newImage) {
	NSSize size = NSMakeSize(modelPtr->width - 2*modelPtr->ring,
				 modelPtr->height - 2*modelPtr->ring);
	[modelPtr->image release];
	[modelPtr->darkModeImage release];
	newImage.size = size;
	modelPtr->image = [newImage retain];
	if (modelPtr->templ) {
	    newImage.template = YES;
	}
	modelPtr->darkModeImage = [[newImage copy] retain];
	if ([modelPtr->darkModeImage isTemplate]) {

	    /*
	     * For a template image the Dark Mode version should be white.
	     */

	    NSRect rect = {NSZeroPoint, size};
	    [modelPtr->darkModeImage lockFocus];
	    [[NSColor whiteColor] set];
	    NSRectFillUsingOperation(rect, NSCompositeSourceAtop);
	    [modelPtr->darkModeImage unlockFocus];
	} else if (modelPtr->pressed) {

	    /*
	     * Non-template pressed images are darker in Light Mode and lighter
	     * in Dark Mode.
	     */

	    TintImage(modelPtr->image, [NSColor blackColor], 0.2);
	    TintImage(modelPtr->darkModeImage, [NSColor whiteColor], 0.5);
	}
    } else {
	switch(sourceInterpretation) {
	case NAME_SOURCE:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown named NSImage.\n"
		"Try omitting ImageName, "
	        "e.g. use NSCaution for NSImageNameCaution.", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
	    goto errorExit;
	case FILE_SOURCE:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Failed to load image file.\n", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
	    goto errorExit;
	default:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"Unrecognized file type.\n"
		"If using a filename extension, do not include the dot.\n", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
	    goto errorExit;
	}
    }

    /*
     * Set the width and height.  If only one is specified, set the other one
     * so as to preserve the aspect ratio.  If neither is specified, match the
     * size of the image.
     */

    if (modelPtr->width == 0 && modelPtr->height == 0) {
	CGSize size = [modelPtr->image size];
	modelPtr->width = (int) size.width;
	modelPtr->height = (int) size.height;
    } else {
	CGSize size = [modelPtr->image size], newsize;
	CGFloat aspect = size.width && size.height ?
	     size.height / size.width : 1;
	if (modelPtr->width == 0) {
	    modelPtr->width = (int) ((CGFloat)(modelPtr->height) / aspect);
	} else if (modelPtr->height == 0) {
	    modelPtr->height = (int) ((CGFloat)(modelPtr->width) * aspect);
	}
	newsize = NSMakeSize(modelPtr->width, modelPtr->height);
	modelPtr->image.size = newsize;
	modelPtr->darkModeImage.size = newsize;
    }

    /*
     * Inform the generic image code that the image has (potentially) changed.
     */

    Tk_ImageChanged(modelPtr->tkModel, 0, 0, modelPtr->width,
	    modelPtr->height, modelPtr->width, modelPtr->height);
    modelPtr->flags &= ~IMAGE_CHANGED;

    return TCL_OK;

  errorExit:
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageObjCmd --
 *
 *	This function implements the configure and cget commands for an
 *	nsimage instance.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	The image may be reconfigured.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXNSImageObjCmd(
    void *clientData,	/* Information about the image model. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkMacOSXNSImageModel *modelPtr = (TkMacOSXNSImageModel *)clientData;
    Tk_OptionTable optionTable = Tk_CreateOptionTable(interp, systemImageOptions);
    static const char *const options[] = {"cget", "configure", NULL};
    enum {CGET, CONFIGURE};
    Tcl_Obj *objPtr;
    int index;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], options,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    Tcl_Preserve(modelPtr);
    switch (index) {
    case CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "option");
	    return TCL_ERROR;
	}
	objPtr = Tk_GetOptionValue(interp, (char *)modelPtr, optionTable,
		objv[2], NULL);
	if (objPtr == NULL) {
            goto error;
        }
        Tcl_SetObjResult(interp, objPtr);
	break;
    case CONFIGURE:
	if (objc == 2) {
	    objPtr = Tk_GetOptionInfo(interp, (char *)modelPtr, optionTable,
				     NULL, NULL);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    break;
	} else if (objc == 3) {
	    objPtr = Tk_GetOptionInfo(interp, (char *)modelPtr, optionTable,
				     objv[2], NULL);
	    if (objPtr == NULL) {
		goto error;
	    }
	    Tcl_SetObjResult(interp, objPtr);
	    break;
	} else {
	    TkMacOSXNSImageConfigureModel(interp, modelPtr, objc - 2, objv + 2);
	    break;
	}
    default:
	break;
    }

    Tcl_Release(modelPtr);
    return TCL_OK;

 error:
    Tcl_Release(modelPtr);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageCreate --
 *
 *	Allocate and initialize an nsimage model.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	The data structure for a new image is allocated.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXNSImageCreate(
    Tcl_Interp *interp,		 /* Interpreter for application using image. */
    const char *name,		 /* Name to use for image. */
    Tcl_Size objc,			 /* Number of arguments. */
    Tcl_Obj *const objv[],	 /* Argument strings for options (not
				  * including image name or type). */
    TCL_UNUSED(const Tk_ImageType *), /* typePtr */
    Tk_ImageModel model,	 /* Token for image, to be used in callbacks. */
    void **clientDataPtr)	 /* Store manager's token for image here; it
				  * will be returned in later callbacks. */
{
    TkMacOSXNSImageModel *modelPtr;
    Tk_OptionTable optionTable = Tk_CreateOptionTable(interp, systemImageOptions);

    modelPtr = (TkMacOSXNSImageModel *)ckalloc(sizeof(TkMacOSXNSImageModel));
    modelPtr->tkModel = model;
    modelPtr->interp = interp;
    modelPtr->imageName = (char *)ckalloc(strlen(name) + 1);
    strcpy(modelPtr->imageName, name);
    modelPtr->flags = 0;
    modelPtr->instancePtr = NULL;
    modelPtr->image = NULL;
    modelPtr->darkModeImage = NULL;
    modelPtr->source = NULL;
    modelPtr->as = NULL;

    /*
     * Process configuration options given in the image create command.
     */

    if (Tk_InitOptions(interp, (char *) modelPtr, optionTable, NULL) != TCL_OK
	|| TkMacOSXNSImageConfigureModel(interp, modelPtr, objc, objv) != TCL_OK) {
	TkMacOSXNSImageDelete(modelPtr);
	return TCL_ERROR;
    }
    Tcl_CreateObjCommand(interp, name, TkMacOSXNSImageObjCmd, modelPtr, NULL);
    *clientDataPtr = modelPtr;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageGet --
 *
 *	Allocate and initialize an nsimage instance.
 *
 * Results:
 *	The return value is a token for the image instance, which is used in
 *	future callbacks to ImageDisplay and ImageFree.
 *
 * Side effects:
 *	A new new nsimage instance is created.
 *
 *----------------------------------------------------------------------
 */

static void *
TkMacOSXNSImageGet(
    TCL_UNUSED(Tk_Window),      /* tkwin */
    void *clientData)	/* Pointer to TkMacOSXNSImageModel for image. */
{
    TkMacOSXNSImageModel *modelPtr = (TkMacOSXNSImageModel *) clientData;
    TkMacOSXNSImageInstance *instPtr;

    instPtr = (TkMacOSXNSImageInstance *)ckalloc(sizeof(TkMacOSXNSImageInstance));
    instPtr->modelPtr = modelPtr;
    return instPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageDisplay --
 *
 *	Display or redisplay an nsimage in the given drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The image gets drawn.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXNSImageDisplay(
    void *clientData,	/* Pointer to TkMacOSXNSImageInstance for image. */
    TCL_UNUSED(Display *),      /* display */
    Drawable drawable,		/* Where to draw or redraw image. */
    int imageX, int imageY,	/* Origin of area to redraw, relative to
				 * origin of image. */
    int width, int height,	/* Dimensions of area to redraw. */
    int drawableX, int drawableY)
				/* Coordinates in drawable corresponding to
				 * imageX and imageY. */
{
    MacDrawable *macWin = (MacDrawable *) drawable;
    Tk_Window tkwin = (Tk_Window) macWin->winPtr;
    TkMacOSXNSImageInstance *instPtr = (TkMacOSXNSImageInstance *) clientData;
    TkMacOSXNSImageModel *modelPtr = instPtr->modelPtr;
    TkMacOSXDrawingContext dc;
    NSRect dstRect = NSMakeRect(macWin->xOff + drawableX,
				 macWin->yOff + drawableY, width, height);
    NSRect srcRect = NSMakeRect(imageX, imageY, width, height);
    NSImage *image = TkMacOSXInDarkMode(tkwin) ? modelPtr->darkModeImage :
	modelPtr->image;
    int ring = modelPtr->ring;
    int radius = modelPtr->radius;

    if (TkMacOSXSetupDrawingContext(drawable, NULL, &dc)) {
	if (dc.context) {
	    CGRect clipRect = CGRectMake(
		dstRect.origin.x - srcRect.origin.x + ring,
		dstRect.origin.y - srcRect.origin.y + ring,
		modelPtr->width - 2*ring,
		modelPtr->height - 2*ring);
	    CGPathRef path = CGPathCreateWithRoundedRect(clipRect, radius, radius, NULL);
	    CGContextSaveGState(dc.context);
	    CGContextBeginPath(dc.context);
	    CGContextAddPath(dc.context, path);
	    CGContextClip(dc.context);
	    NSGraphicsContext *savedContext = NSGraphicsContext.currentContext;
	    NSGraphicsContext.currentContext = [NSGraphicsContext
		graphicsContextWithCGContext:dc.context flipped:YES];
	    [image drawInRect:clipRect
		     fromRect:srcRect
		    operation:NSCompositeSourceOver
		     fraction:modelPtr->alpha
	       respectFlipped:YES
			hints:nil];
	    CGContextRestoreGState(dc.context);

	    /*
	     * Draw the focus ring.
	     */

	    if (ring) {
		CGRect ringRect = CGRectInset(clipRect, -ring, -ring);
		CGPathRef ringPath = CGPathCreateWithRoundedRect(ringRect,
		    radius + ring, radius + ring, NULL);
		CGContextSaveGState(dc.context);
		CGContextAddPath(dc.context, path);
		CGContextAddPath(dc.context, ringPath);
		CGContextSetFillColorWithColor(dc.context,
					       controlAccentColor().CGColor);
		CGContextEOFillPath(dc.context);
		CGContextRestoreGState(dc.context);
		CFRelease(ringPath);
	    }
	    CFRelease(path);
	    NSGraphicsContext.currentContext = savedContext;
	}
	TkMacOSXRestoreDrawingContext(&dc);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageFree --
 *
 *	Deallocate an instance of an nsimage.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information related to the instance is freed.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXNSImageFree(
    void *clientData,	/* Pointer to TkMacOSXNSImageInstance for instance. */
    TCL_UNUSED(Display *))	/* display */
{
    TkMacOSXNSImageInstance *instPtr = (TkMacOSXNSImageInstance *) clientData;
    ckfree(instPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImageDelete --
 *
 *	Deallocate an nsimage model.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	 NSImages are released and memory is freed.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXNSImageDelete(
    void *clientData)	/* Pointer to TkMacOSXNSImageModel for image. When
				 * this function is called, no more instances
				 * exist. */
{
    TkMacOSXNSImageModel *modelPtr = (TkMacOSXNSImageModel *) clientData;

    Tcl_DeleteCommand(modelPtr->interp, modelPtr->imageName);
    ckfree(modelPtr->imageName);
    ckfree(modelPtr->source);
    ckfree(modelPtr->as);
    [modelPtr->image release];
    [modelPtr->darkModeImage release];
    ckfree(modelPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXNSImage_Init --
 *
 *	Adds the TkMacOSXNSImage type to Tk.
 *
 * Results:
 *	Returns a standard Tcl completion code, and leaves an error message in
 *	the interp's result if an error occurs.
 *
 * Side effects:
 *	Creates the image create nsrect ...  command.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXNSImage_Init(
    TCL_UNUSED(Tcl_Interp *))	 /* interp */
{
    Tk_CreateImageType(&TkMacOSXNSImageType);
    return 1;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXImage.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22






















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 *  tkMacOSXImage.h --
 *
 *
 *	The code in this file provides an interface for XImages, and
 *      implements the nsimage image type.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2017-2021 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Function prototypes
 */

MODULE_SCOPE CFDataRef CreatePDFFromDrawableRect( Drawable drawable,
	   int x, int y, unsigned int width, unsigned int height);

Changes to macosx/tkMacOSXInit.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18


19
20
21



22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39


























40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125

126
127
128
129
130



131
132
133

134
135
136
137
138


139
140



141
142
143

144
145
146

147
148


149



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
1
2
3
4
5
6



7
8
9

10
11
12
13
14
15


16
17



18
19
20
21
22
23
24
25
26
27
28
29
30
31








32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60









































61
62






63
64
65

66
67
68




69








70
71
72
73

74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94

95





96
97


98
99
100
101
102

103
104


105


106
107

108
109
110
111
112
113
114
115
116






































































































































































117
118
119
120
121
122
123






-
-
-
+
+
+
-






-
-
+
+
-
-
-
+
+
+










+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-



-
+


-
-
-
-

-
-
-
-
-
-
-
-




-
+









-
+





+
+
+


-
+
-
-
-
-
-
+
+
-
-
+
+
+


-
+

-
-
+
-
-
+
+
-
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * tkMacOSXInit.c --
 *
 *	This file contains Mac OS X -specific interpreter initialization
 *	functions.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2017 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXConstants.h"
#include <dlfcn.h>

#include <sys/stat.h>
#include <objc/objc-auto.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/utsname.h>
#include <dlfcn.h>
#include <objc/objc-auto.h>

static char tkLibPath[PATH_MAX + 1] = "";

/*
 * If the App is in an App package, then we want to add the Scripts directory
 * to the auto_path.
 */

static char scriptPath[PATH_MAX + 1] = "";

long tkMacOSXMacOSXVersion = 0;
/*
 * Forward declarations...
 */

static Tcl_ObjCmdProc TkMacOSXGetAppPathObjCmd;
static Tcl_ObjCmdProc TkMacOSVersionObjCmd;

#pragma mark TKApplication(TKInit)

#pragma mark TKApplication(TKInit)

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#define NSTextInputContextKeyboardSelectionDidChangeNotification @"NSTextInputContextKeyboardSelectionDidChangeNotification"
static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
    [[NSNotificationCenter defaultCenter] postNotificationName:NSTextInputContextKeyboardSelectionDidChangeNotification object:nil userInfo:nil];
}
#endif

@interface TKApplication(TKKeyboard)
- (void) keyboardChanged: (NSNotification *) notification;
@end

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
#define TKApplication_NSApplicationDelegate <NSApplicationDelegate>
#else
#define TKApplication_NSApplicationDelegate
#endif
@interface TKApplication(TKWindowEvent) TKApplication_NSApplicationDelegate
- (void) _setupWindowNotifications;
@end

@interface TKApplication(TKMenus)
- (void) _setupMenus;
@end

@implementation TKApplication
@synthesize poolLock = _poolLock;
@synthesize poolProtected = _poolProtected;
@synthesize macOSVersion = _macOSVersion;
@synthesize isDrawing = _isDrawing;
@synthesize isSigned = _isSigned;
@synthesize tkLiveResizeEnded = _tkLiveResizeEnded;
@synthesize tkPointerWindow = _tkPointerWindow;
- (void) setTkPointerWindow: (TkWindow *)winPtr
{
    if (winPtr) {
	Tcl_Preserve(winPtr);
    }
    if (_tkPointerWindow) {
	Tcl_Release(_tkPointerWindow);
    }
    _tkPointerWindow = winPtr;
    return;
}
@synthesize tkEventTarget = _tkEventTarget;
- (void) setTkEventTarget: (TkWindow *)winPtr
{
    if (winPtr) {
	Tcl_Preserve(winPtr);
    }
    if (_tkEventTarget) {
	Tcl_Release(_tkEventTarget);
    }
    _tkEventTarget = winPtr;
    return;
}
@synthesize tkDragTarget = _tkDragTarget;
- (void) setTkDragTarget: (TkWindow *)winPtr
{
    if (winPtr) {
	Tcl_Preserve(winPtr);
    }
    if (_tkDragTarget) {
	Tcl_Release(_tkDragTarget);
    }
    _tkDragTarget = winPtr;
    return;
}
@synthesize tkButtonState = _tkButtonState;
@end

/*
 * #define this to see a message on stderr whenever _resetAutoreleasePool is
 * called while the pool is locked.
 */
#undef DEBUG_LOCK

@implementation TKApplication(TKInit)
- (void) _resetAutoreleasePool
{
    if ([self poolLock] == 0) {
    if(![self poolProtected]) {
	[_mainPool drain];
	_mainPool = [NSAutoreleasePool new];
    } else {
#ifdef DEBUG_LOCK
	fprintf(stderr, "Pool is locked with count %d!!!!\n", [self poolLock]);
#endif
    }
}
- (void) _lockAutoreleasePool
{
    [self setPoolLock:[self poolLock] + 1];
}
- (void) _unlockAutoreleasePool
{
    [self setPoolLock:[self poolLock] - 1];
}
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
- (void) _postedNotification: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
}
#endif

- (void) _setupApplicationNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
#define observe(n, s) \
	[nc addObserver:self selector:@selector(s) name:(n) object:nil]
    observe(NSApplicationDidBecomeActiveNotification, applicationActivate:);
    observe(NSApplicationWillResignActiveNotification, applicationDeactivate:);
    observe(NSApplicationDidResignActiveNotification, applicationDeactivate:);
    observe(NSApplicationDidUnhideNotification, applicationShowHide:);
    observe(NSApplicationDidHideNotification, applicationShowHide:);
    observe(NSApplicationDidChangeScreenParametersNotification, displayChanged:);
    observe(NSTextInputContextKeyboardSelectionDidChangeNotification, keyboardChanged:);
#undef observe
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
    CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &keyboardChanged, kTISNotifySelectedKeyboardInputSourceChanged, NULL, CFNotificationSuspensionBehaviorCoalesce);
#endif
}


- (void) _setupEventLoop
/*
 * Fix for 10b38a7a7c.
 */

- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
{
    return YES;
    [self finishLaunching];
    [self setWindowsNeedUpdate:YES];
    [pool drain];
}

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
- (void) _setup: (Tcl_Interp *) interp
{
    (void)aNotification;

    _eventInterp = interp;
    /*
     * Initialize notifications.
    _mainPool = [NSAutoreleasePool new];
    [NSApp setPoolProtected:NO];
     */
    _defaultMainMenu = nil;
    [self _setupMenus];
    [self setDelegate:self];
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    [[NSNotificationCenter defaultCenter] addObserver:self
	    selector:@selector(_postedNotification:) name:nil object:nil];
#endif
    [self _setupWindowNotifications];
    [self _setupApplicationNotifications];

    if ([NSApp macOSVersion] >= 110000) {

   /*
    * Initialize Apple Event processing. Apple's docs (see
    * https://developer.apple.com/documentation/appkit/nsapplication)
    * recommend doing this here, although historically we have
    * done this in applicationWillFinishLaunching. In response to
    * bug 7bb246b072.
    */

    TkMacOSXInitAppleEvents(_eventInterp);

    }
}

-(void)applicationDidFinishLaunching:(NSNotification *)notification
{
    (void)notification;

   if ([NSApp macOSVersion] < 110000) {

   /*
    * Initialize Apple Event processing on macOS versions
    * older than Big Sur (11).
    */

    TkMacOSXInitAppleEvents(_eventInterp);

    }


    /*
     * Initialize the graphics context.
     */

    TkMacOSXUseAntialiasedText(_eventInterp, -1);
    TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0);

    /*
     * Construct the menu bar.
     */

    _defaultMainMenu = nil;
    [self _setupMenus];

    /*
     * Run initialization routines that depend on the OS version.
     */

    Ttk_MacOSXInit();

    /*
     * It is not safe to force activation of the NSApp until this method is
     * called. Activating too early can cause the menu bar to be unresponsive.
     * The call to activateIgnoringOtherApps was moved here to avoid this.
     * However, with the release of macOS 10.15 (Catalina) that was no longer
     * sufficient.  (See ticket bf93d098d7.)  The call to setActivationPolicy
     * needed to be moved into this function as well.
     */

    [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
    [NSApp activateIgnoringOtherApps: YES];

    /*
     * Add an event monitor so we continue to receive NSMouseMoved and
     * NSMouseDragged events when the mouse moves outside of the key
     * window. The handler simply returns the events it receives, so
     * they can be processed in the same way as for other events.
     */

    [NSEvent addLocalMonitorForEventsMatchingMask:(NSMouseMovedMask |
						   NSLeftMouseDraggedMask)
	 handler:^NSEvent *(NSEvent *event)
	 {
	     return event;
	 }];

    /*
     * Process events to ensure that the root window is fully initialized. See
     * ticket 56a1823c73.
     */

    [NSApp _lockAutoreleasePool];
    while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {}
    [NSApp _unlockAutoreleasePool];
}

- (void) _setup: (Tcl_Interp *) interp
{
    /*
     * Remember our interpreter.
     */
    _eventInterp = interp;

    /*
     * Install the global autoreleasePool.
     */
    _mainPool = [NSAutoreleasePool new];
    [NSApp setPoolLock:0];

    /*
     * Record the OS version we are running on.
     */

    int minorVersion, majorVersion;

#if MAC_OS_X_VERSION_MAX_ALLOWED < 101000
    Gestalt(gestaltSystemVersionMinor, (SInt32*)&minorVersion);
    majorVersion = 10;
#else
    NSOperatingSystemVersion systemVersion;
    systemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
    majorVersion = (int)systemVersion.majorVersion;
    minorVersion = (int)systemVersion.minorVersion;
#endif

    if (majorVersion == 10 && minorVersion == 16) {

	/*
	 * If a program compiled with a macOS 10.XX SDK is run on macOS 11.0 or
	 * later then it will report majorVersion 10 and minorVersion 16, no
	 * matter what the actual OS version of the host may be. And of course
	 * Apple never released macOS 10.16. To work around this we guess the
	 * OS version from the kernel release number, as reported by uname.
	 */

	struct utsname name;
	char *endptr;
	if (uname(&name) == 0) {
	    majorVersion = (int)strtol(name.release, &endptr, 10) - 9;
	    minorVersion = 0;
	}
    }
    [NSApp setMacOSVersion: 10000*majorVersion + 100*minorVersion];

    /*
     * We are not drawing right now.
     */

    [NSApp setIsDrawing:NO];

    /*
     * Be our own delegate.
     */

    [self setDelegate:self];

    /*
     * If no icon has been set from an Info.plist file, use the Wish icon from
     * the Tk framework.
     */

    NSString *iconFile = [[NSBundle mainBundle] objectForInfoDictionaryKey:
						    @"CFBundleIconFile"];
    if (!iconFile) {
	NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"];
	if (path) {
	    NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
	    if (image) {
		[image setName:@"NSApplicationIcon"];
		[NSApp setApplicationIconImage:image];
		[image release];
	    }
	}
    }
}

- (NSString *) tkFrameworkImagePath: (NSString *) image
{
    NSString *path = nil;
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    if (tkLibPath[0] != '\0') {
364
365
366
367
368
369
370
































371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468



469
470
471




472
473
474


475
476
477
478
479
480
481
482


483
484
485
486
487













488

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518











519
520
521
522
523
524
525
526
527
528
529
530
531
532

533
534

535
536
537
538


539
540
541
542
543
544
545
546
547











548
549
550
551
552
553
554


555


556




557
558
559


560
561


562





563
564

565
566
567
568
569





570
571
572




573
574
575

576
577

578
579
580




581
582
583
584
585
586
587




588
589
590
591
592
593
594
595
596

597
598
599
600
601
602






603
604
605
606
607


608
609
610
611
612
613
614
615
616
617



618
619
620



621
622




623
624

625
626
627
628
629



630
631
632
633
634
635
636
637
638




639
640
641




642
643
644
645




646
647

648
649
650
651
652
653

654
655
656
657

658
659
660

661
662
663
664

665
666
667
668
669

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212










































































213
214
215
216
217
218
219


220
221
222
223
224
225
226
227
228
229
230


231
232

233
234
235
236
237


238
239
240
241



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266

267
268
269















270
271
272
273
274
275
276
277
278
279
280














281


282



283
284
285









286
287
288
289
290
291
292
293
294
295
296







297
298
299
300
301

302
303
304
305
306


307
308


309
310

311
312
313
314
315
316

317





318
319
320
321
322



323
324
325
326
327


328


329



330
331
332
333







334
335
336
337

338







339






340
341
342
343
344
345
346
347
348


349
350
351
352
353
354
355
356
357
358


359
360
361

362
363
364
365
366


367
368
369
370
371

372





373
374
375









376
377
378
379
380


381
382
383
384




385
386
387
388


389






390




391



392
393
394
395
396
397
398
399
400
401

402

403
404
405
406























































407
408
409
410
411
412
413







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
+
+
+



+
+
+
+

-
-
+
+
-





-
-
+
+


-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

+









-

-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-

+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+

+
+
-
+
+
+
+

-
-
+
+
-
-
+
+
-
+
+
+
+
+

-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+

-
-
+
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-

-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+



-
-
+
+








-
-
+
+
+
-


+
+
+
-
-
+
+
+
+

-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+




+




-
+
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * DoWindowActivate --
 *
 *	Idle handler that sets the application icon to the generic Tk icon.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
SetApplicationIcon(
    ClientData clientData)
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"];
    if (path) {
	NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
	if (image) {
	    [NSApp setApplicationIconImage:image];
	    [image release];
	}
    }
    [pool drain];
}

/*
 *----------------------------------------------------------------------
 *
 * TkpInit --
 *
 *	Performs Mac-specific interpreter initialization related to the
 *	tk_library variable.
 *
 * Results:
 *	Returns a standard Tcl result. Leaves an error message or result in
 *	the interp's result.
 *
 * Side effects:
 *	Sets "tk_library" Tcl variable, runs "tk.tcl" script.
 *
 *----------------------------------------------------------------------
 */

/*
 * Helper function which closes the shared NSFontPanel and NSColorPanel.
 */

static void closePanels(
    void)
{
    if ([NSFontPanel sharedFontPanelExists]) {
	[[NSFontPanel sharedFontPanel] orderOut:nil];
    }
    if ([NSColorPanel sharedColorPanelExists]) {
        [[NSColorPanel sharedColorPanel] orderOut:nil];
    }
}

/*
 * This custom exit procedure is called by Tcl_Exit in place of the exit
 * function from the C runtime.  It calls the terminate method of the
 * NSApplication class (superTerminate for a TKApplication).  The purpose of
 * doing this is to ensure that the NSFontPanel and the NSColorPanel are closed
 * before the process exits, and that the application state is recorded
 * correctly for all termination scenarios.
 *
 * TkpWantsExitProc tells Tcl_AppInit whether to install our custom exit proc,
 * which terminates the process by calling [NSApplication terminate].  This
 * does not work correctly if the process is part of an exec pipeline, so it is
 * only done if the process was launched by the launcher or if both stdin and
 * stdout are ttys.  To disable using the custom exit proc altogether, undefine
 * USE_CUSTOM_EXIT_PROC.
 */

#if defined(USE_CUSTOM_EXIT_PROC)
static Bool doCleanupFromExit = NO;

int TkpWantsExitProc(void) {
    return doCleanupFromExit == YES;
}

TCL_NORETURN void TkpExitProc(
    void *clientdata)
{
    Bool doCleanup = doCleanupFromExit;
    if (doCleanupFromExit) {
	doCleanupFromExit = NO; /* prevent possible recursive call. */
	closePanels();
    }

    /*
     * Tcl_Exit does not call Tcl_Finalize if there is an exit proc installed.
     */

    Tcl_Finalize();
    if (doCleanup == YES) {
	[(TKApplication *)NSApp superTerminate:nil]; /* Should not return. */
    }
    exit((int)PTR2INT(clientdata)); /* Convince the compiler that we don't return. */
}
#endif

/*
 * This signal handler is installed for the SIGINT, SIGHUP and SIGTERM signals
 * so that normal finalization occurs when a Tk app is killed by one of these
 * signals (e.g when ^C is pressed while running Wish in the shell).  It calls
 * Tcl_Exit instead of the C runtime exit function called by the default handler.
 * This is consistent with the Tcl_Exit manual page, which says that Tcl_Exit
 * should always be called instead of exit.  When Tk is killed by a signal we
 * return exit status 1.
 */

static void TkMacOSXSignalHandler(TCL_UNUSED(int)) {

    Tcl_Exit(1);
}

int
TkpInit(
    Tcl_Interp *interp)
{
    static int initialized = 0;

    /*
     * TkpInit can be called multiple times with different interpreters. But
     * The application initialization should only be done once.
     * Since it is possible for TkInit to be called multiple times and we
     * don't want to do the following initialization multiple times we protect
     * against doing it more than once.
     */

    if (!initialized) {
	int bundledExecutable = 0;
	CFBundleRef bundleRef;
	CFURLRef bundleUrl = NULL;
	struct utsname name;
	struct stat st;
	Bool shouldOpenConsole = NO;
        Bool stdinIsNullish = (!isatty(0) &&

	initialized = 1;
	    (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0)));

	/*
	 * Initialize/check OS version variable for runtime checks.
	 */

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#   error Mac OS X 10.6 required
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
#   error Mac OS X 10.5 required
#endif

	initialized = 1;

#ifdef TK_FRAMEWORK
	if (!uname(&name)) {
	    tkMacOSXMacOSXVersion = (strtod(name.release, NULL) + 96) * 10;
	}
       /*Check for new versioning scheme on Yosemite (10.10) and later.*/
	if (MAC_OS_X_VERSION_MIN_REQUIRED > 100000) {
		tkMacOSXMacOSXVersion = MAC_OS_X_VERSION_MIN_REQUIRED/100;
	    }
	if (tkMacOSXMacOSXVersion && MAC_OS_X_VERSION_MIN_REQUIRED < 100000 &&
		tkMacOSXMacOSXVersion/10 < MAC_OS_X_VERSION_MIN_REQUIRED/10) {
	    Tcl_Panic("Mac OS X 10.%d or later required !",
		    (MAC_OS_X_VERSION_MIN_REQUIRED/10)-100);
	}


#ifdef TK_FRAMEWORK
	/*
	 * When Tk is in a framework, force tcl_findLibrary to look in the
	 * framework scripts directory.
	 * FIXME: Should we come up with a more generic way of doing this?
	 */

	if (Tcl_MacOSXOpenVersionedBundleResources(interp,
		"com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 0, PATH_MAX,
		tkLibPath) != TCL_OK) {
            # if 0 /* This is not really an error.  Wish still runs fine. */
	    TkMacOSXDbgMsg("Tcl_MacOSXOpenVersionedBundleResources failed");
	    # endif
	}
#endif

	/*
	 * Instantiate our NSApplication object. This needs to be done before
	 * we check whether to open a console window.
	 */

	NSAutoreleasePool *pool = [NSAutoreleasePool new];
	[[NSUserDefaults standardUserDefaults] registerDefaults:
		[NSDictionary dictionaryWithObjectsAndKeys:
				  [NSNumber numberWithBool:YES],
			      @"_NSCanWrapButtonTitles",
				   [NSNumber numberWithInt:-1],
			      @"NSStringDrawingTypesetterBehavior",
			      nil]];
	[TKApplication sharedApplication];
	[pool drain];
	{
	    NSAutoreleasePool *pool = [NSAutoreleasePool new];
		[[NSUserDefaults standardUserDefaults] registerDefaults:
		     [NSDictionary dictionaryWithObjectsAndKeys:
		     [NSNumber numberWithBool:YES],
		     @"_NSCanWrapButtonTitles",
		     [NSNumber numberWithInt:-1],
		     @"NSStringDrawingTypesetterBehavior",
		     nil]];
	    [TKApplication sharedApplication];
	    [pool drain];

        /*
         * WARNING: The finishLaunching method runs asynchronously. This
         * creates a race between the initialization of the NSApplication and
         * the initialization of Tk.  If Tk wins the race bad things happen
         * with the root window (see below).  If the NSApplication wins then an
         * AppleEvent created during launch, e.g. by dropping a file icon on
         * the application icon, will be delivered before the procedure meant
         * to to handle the AppleEvent has been defined.  This is handled in
         * tkMacOSXHLEvents.c by scheduling a timer event to handle the
         * AppleEvent later, after the required procedure has been defined.
         */

	[NSApp _setup:interp];
	    [NSApp _setup:interp];
	[NSApp finishLaunching];

	}
        /*
         * Create a Tk event source based on the Appkit event queue.
         */

	/* Check whether we are a bundled executable: */
	bundleRef = CFBundleGetMainBundle();
	Tk_MacOSXSetupTkNotifier();

	/*
	 * If Tk initialization wins the race, the root window is mapped before
         * the NSApplication is initialized.  This can cause bad things to
         * happen.  The root window can open off screen with no way to make it
         * appear on screen until the app icon is clicked.  This will happen if
         * a Tk application opens a modal window in its startup script (see
         * ticket 56a1823c73).  In other cases, an empty root window can open
	if (bundleRef) {
	    bundleUrl = CFBundleCopyBundleURL(bundleRef);
	}
	if (bundleUrl) {
	    /*
	     * A bundled executable is two levels down from its main bundle
	     * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas an
	     * unbundled executable's main bundle directory is just the
	     * directory containing the executable. So to check whether we are
	     * bundled, we delete the last three path components of the
	     * executable's url and compare the resulting url with the main
         * on screen and remain visible for a noticeable amount of time while
         * the Tk initialization finishes (see ticket d1989fb7cf).  The call
         * below forces Tk to block until the Appkit event queue has been
         * created.  This seems to be sufficient to ensure that the
         * NSApplication initialization wins the race, avoiding these bad
         * window behaviors.
	 */
	     * bundle url.
	     */

	    int j = 3;
	    CFURLRef url = CFBundleCopyExecutableURL(bundleRef);
	Tcl_DoOneEvent(TCL_WINDOW_EVENTS | TCL_DONT_WAIT);

	    while (url && j--) {
		CFURLRef parent =
			CFURLCreateCopyDeletingLastPathComponent(NULL, url);

	/*
	 * Decide whether to open a console window.  If the TK_CONSOLE
		CFRelease(url);
		url = parent;
	 * environment variable is not defined we only show the console if
	 * stdin is not a tty and there is no startup script.
	    }
	    if (url) {
	 */
		bundledExecutable = CFEqual(bundleUrl, url);
		CFRelease(url);
	    }
	    CFRelease(bundleUrl);
	}

	if (getenv("TK_CONSOLE")) {
	if (!bundledExecutable) {
	    shouldOpenConsole = YES;
	} else if (stdinIsNullish && Tcl_GetStartupScript(NULL) == NULL) {
	    const char *intvar = Tcl_GetVar2(interp, "tcl_interactive",
					     NULL, TCL_GLOBAL_ONLY);
	    if (intvar == NULL) {
	    /*
	     * If we are loaded into an executable that is not a bundled
	     * application, the window server does not let us come to the
	     * foreground. For such an executable, notify the window server
	     * that we are now a full GUI application.
		Tcl_SetVar2(interp, "tcl_interactive", NULL, "1",
			    TCL_GLOBAL_ONLY);
	    }
	     */

	    OSStatus err = procNotFound;
	    ProcessSerialNumber psn = { 0, kCurrentProcess };

#if defined(USE_CUSTOM_EXIT_PROC)
	    doCleanupFromExit = YES;
	    err = ChkErr(TransformProcessType, &psn,
#endif

		    kProcessTransformToForegroundApplication);
	    shouldOpenConsole = YES;
	}
	if (shouldOpenConsole) {

	    /*
	     * Set application icon to generic Tk icon, do it at idle time
	     * instead of now to ensure tk_library is setup.
	    Tk_InitConsoleChannels(interp);
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
	    if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
		return TCL_ERROR;
	    }
	     */

	    Tcl_DoWhenIdle(SetApplicationIcon, NULL);
	}
	} else if (stdinIsNullish) {

	    /*
	     * When launched as a macOS application with no console,
	     * redirect stderr and stdout to /dev/null. This avoids waiting
	     * forever for those files to become writable if the underlying
	     * Tcl program tries to write to them with a puts command.
	     */

	{
	    FILE *null = fopen("/dev/null", "w");
	    dup2(fileno(null), STDOUT_FILENO);
	    dup2(fileno(null), STDERR_FILENO);
#if defined(USE_CUSTOM_EXIT_PROC)
	    doCleanupFromExit = YES;
#endif
	    NSAutoreleasePool *pool = [NSAutoreleasePool new];
	    [NSApp _setupEventLoop];
	    TkMacOSXInitAppleEvents(interp);
	    TkMacOSXUseAntialiasedText(interp, -1);
	    TkMacOSXInitCGDrawing(interp, TRUE, 0);
	    [pool drain];
	}

	/*
	 * FIXME: Close stdin & stdout for remote debugging if XCNOSTDIN is
	 * set.  Otherwise we will fight with gdb for stdin & stdout
	 * FIXME: Close stdin & stdout for remote debugging otherwise we will
	 * fight with gdb for stdin & stdout
	 */

	if (getenv("XCNOSTDIN") != NULL) {
	    close(0);
	    close(1);
	}

	/*
	 * Now we can run initialization routines which require that both the
	 * NSApplication and the Tcl interpreter have been created and
	 * If we don't have a TTY and stdin is a special character file of
	 * length 0, (e.g. /dev/null, which is what Finder sets when double
	 * clicking Wish) then use the Tk based console interpreter.
	 * initialized.
	 */

	if (getenv("TK_CONSOLE") ||
		(!isatty(0) && (fstat(0, &st) ||
		(S_ISCHR(st.st_mode) && st.st_blocks == 0)))) {
	TkMacOSXServices_Init(interp);
	TkMacOSXNSImage_Init(interp);
	    Tk_InitConsoleChannels(interp);
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));

	/*
	    /*
	 * The root window has been created and mapped, but XMapWindow deferred its
	 * call to makeKeyAndOrderFront because the first call to XMapWindow
	 * occurs too early in the initialization process for that.  Process idle
	 * tasks now, so the root window is configured, then order it front.
	 */
	     * Only show the console if we don't have a startup script
	     * and tcl_interactive hasn't been set already.
	     */

	while(Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {};
	for (NSWindow *window in [NSApp windows]) {
	    TkWindow *winPtr = TkMacOSXGetTkWindow(window);
	    if (winPtr && Tk_IsMapped(winPtr)) {
		[window makeKeyAndOrderFront:NSApp];
		break;
	    }
	}

	    if (Tcl_GetStartupScript(NULL) == NULL) {
		const char *intvar = Tcl_GetVar2(interp,
			"tcl_interactive", NULL, TCL_GLOBAL_ONLY);

# if defined(USE_CUSTOM_EXIT_PROC)

		if (intvar == NULL) {
		    Tcl_SetVar2(interp, "tcl_interactive", NULL, "1",
			    TCL_GLOBAL_ONLY);
		}
	if ((isatty(0) && isatty(1))) {
	    doCleanupFromExit = YES;
	}

	    }
	    if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
		return TCL_ERROR;
	    }
# endif

	}
	/*
	 * Install a signal handler for SIGINT, SIGHUP and SIGTERM which uses
	 * Tcl_Exit instead of exit so that normal cleanup takes place if a TK
	 * application is killed with one of these signals.
	 */

    }
	signal(SIGINT, TkMacOSXSignalHandler);
	signal(SIGHUP, TkMacOSXSignalHandler);
	signal(SIGTERM, TkMacOSXSignalHandler);
    }

    /*
     * Initialization steps that are needed for all interpreters.
     */
    Tk_MacOSXSetupTkNotifier();

    if (tkLibPath[0] != '\0') {
	Tcl_SetVar2(interp, "tk_library", NULL, tkLibPath, TCL_GLOBAL_ONLY);
    }

    if (scriptPath[0] != '\0') {
	Tcl_SetVar2(interp, "auto_path", NULL, scriptPath,
		TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
    }
    Tcl_CreateObjCommand(interp, "nsimage",

	    TkMacOSXNSImageObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::mac::standardAboutPanel",
	    TkMacOSXStandardAboutPanelObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap",
	    TkMacOSXIconBitmapObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath",
	    TkMacOSXGetAppPathObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::mac::macOSVersion",
           TkMacOSVersionObjCmd, NULL, NULL);
    MacSystrayInit(interp);
    MacPrint_Init(interp);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetAppPathObjCmd --
 *
 *	Returns the path of the Wish application bundle.
 *
 * Results:
 *	Returns the application path.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXGetAppPathObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    /*
     * Get the application path URL and convert it to a string path reference.
     */

    CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    CFStringRef appPath =
	    CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);

    /*
     * Convert (and copy) the string reference into a Tcl result.
     */

    Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    CFStringGetCStringPtr(appPath, CFStringGetSystemEncoding()), TCL_INDEX_NONE));

    CFRelease(mainBundleURL);
    CFRelease(appPath);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
438
439
440
441
442
443
444

445





































446
447
448
449
450
451
452







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	name = "tk";
    } else {
	p = strrchr(name, '/');
	if (p != NULL) {
	    name = p+1;
	}
    }
    Tcl_DStringAppend(namePtr, name, TCL_INDEX_NONE);
    Tcl_DStringAppend(namePtr, name, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSVersionObjCmd --
 *
 *	Tcl command which returns an integer encoding the major and minor
 *	version numbers of the currently running operating system in the
 *	form 10000*majorVersion + 100*minorVersion.
 *
 * Results:
 *	Returns the OS version.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSVersionObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    static char version[16] = "";
    if (objc > 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
    if (version[0] == '\0') {
	snprintf(version, 16, "%d", [NSApp macOSVersion]);
    }
    Tcl_SetResult(interp, version, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayWarning --
 *
826
827
828
829
830
831
832
833

834
835

836
837
838
839
840
841
842
466
467
468
469
470
471
472

473
474

475
476
477
478
479
480
481
482







-
+

-
+







TkpDisplayWarning(
    const char *msg,		/* Message to be displayed. */
    const char *title)		/* Title of warning. */
{
    Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);

    if (errChannel) {
	Tcl_WriteChars(errChannel, title, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, title, -1);
	Tcl_WriteChars(errChannel, ": ", 2);
	Tcl_WriteChars(errChannel, msg, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, msg, -1);
	Tcl_WriteChars(errChannel, "\n", 1);
    }
}

/*
 *----------------------------------------------------------------------
 *
867
868
869
870
871
872
873
874

875
876

877
878
879
880
881
882
883
507
508
509
510
511
512
513

514
515

516
517
518
519
520
521
522
523







-
+

-
+







	CFURLRef appMainURL = CFBundleCopyResourceURL(bundleRef,
		CFSTR("AppMain"), CFSTR("tcl"), CFSTR("Scripts"));

	if (appMainURL != NULL) {
	    CFURLRef scriptFldrURL;
	    char startupScript[PATH_MAX + 1];

	    if (CFURLGetFileSystemRepresentation(appMainURL, true,
	    if (CFURLGetFileSystemRepresentation (appMainURL, true,
		    (unsigned char *) startupScript, PATH_MAX)) {
		Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, TCL_INDEX_NONE), NULL);
		Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL);
		scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL,
			appMainURL);
		if (scriptFldrURL != NULL) {
		    CFURLGetFileSystemRepresentation(scriptFldrURL, true,
			    (unsigned char *) scriptPath, PATH_MAX);
		    CFRelease(scriptFldrURL);
		}
904
905
906
907
908
909
910
911
912


913
914
915
916
917
918
919
920








































921
922
923
924
925
926
927
928
929
544
545
546
547
548
549
550


551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608







-
-
+
+


-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void*
TkMacOSXGetNamedSymbol(
    TCL_UNUSED(const char *),
    const char *symbol)
    const char* module,
    const char* symbol)
{
    void *addr = dlsym(RTLD_NEXT, symbol);

    if (!addr) {
	(void) dlerror(); /* Clear dlfcn error state */
    }
    return addr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetStringObjFromCFString --
 *
 *	Get a string object from a CFString as efficiently as possible.
 *
 * Results:
 *	New string object or NULL if conversion failed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE Tcl_Obj*
TkMacOSXGetStringObjFromCFString(
    CFStringRef str)
{
    Tcl_Obj *obj = NULL;
    const char *c = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);

    if (c) {
	obj = Tcl_NewStringObj(c, -1);
    } else {
	CFRange all = CFRangeMake(0, CFStringGetLength(str));
	CFIndex len;

	if (CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, NULL,
		0, &len) > 0 && len < INT_MAX) {
	    obj = Tcl_NewObj();
	    Tcl_SetObjLength(obj, len);
	    CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false,
		    (UInt8*) obj->bytes, len, NULL);
	}
    }
    return obj;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXInt.h.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
20
21
22
23
24
25
26

27

28
29
30
31
32
33
34







-

-








/*
 * Include platform specific public interfaces.
 */

#ifndef _TKMAC
#include "tkMacOSX.h"
#define Cursor QDCursor
#import <Cocoa/Cocoa.h>
#undef Cursor
#endif

/*
 * Define compatibility platform types used in the structures below so that
 * this header can be included without pulling in the platform headers.
 */

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91



92
93
94
95
96
97
98
99
100
101
102

































103
104
105
106
107
108
109
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86



87
88
89


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138







-












+
-
-
-
+
+
+
-
-









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    HIShapeRef visRgn;		/* Visible region of window */
    HIShapeRef aboveVisRgn;	/* Visible region of window & its children */
    HIShapeRef drawRgn;		/* Clipped drawing region */
    int referenceCount;		/* Don't delete toplevel until children are
				 * gone. */
    struct TkWindowPrivate *toplevel;
				/* Pointer to the toplevel datastruct. */
    CGFloat fillRGBA[4];        /* Background used by the ttk FillElement */
    int flags;			/* Various state see defines below. */
};
typedef struct TkWindowPrivate MacDrawable;

/*
 * Defines use for the flags field of the MacDrawable data structure.
 */

#define TK_SCROLLBAR_GROW	0x01
#define TK_CLIP_INVALID		0x02
#define TK_HOST_EXISTS		0x04
#define TK_DRAWN_UNDER_MENU	0x08
#define TK_FOCUSED_VIEW		0x10
#define TK_IS_PIXMAP		0x10
#define TK_IS_BW_PIXMAP		0x20
#define TK_DO_NOT_DRAW          0x40
#define TK_IS_PIXMAP		0x20
#define TK_IS_BW_PIXMAP		0x40
#define TK_DO_NOT_DRAW          0x80
#define TTK_HAS_CONTRASTING_BG  0x80

/*
 * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags
 * This is defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the
 * TkWindow structure for the window, but in the MacWin. This way we can
 * still tell what the correct port is after the TKWindow structure has been
 * freed. This actually happens when you bind destroy of a toplevel to
 * Destroy of a child.
 */

/*
 * This structure is for handling Netscape-type in process
 * embedding where Tk does not control the top-level. It contains
 * various functions that are needed by Mac specific routines, like
 * TkMacOSXGetDrawablePort. The definitions of the function types
 * are in tkMacOSX.h.
 */

typedef struct {
    Tk_MacOSXEmbedRegisterWinProc *registerWinProc;
    Tk_MacOSXEmbedGetGrafPortProc *getPortProc;
    Tk_MacOSXEmbedMakeContainerExistProc *containerExistProc;
    Tk_MacOSXEmbedGetClipProc *getClipProc;
    Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc;
} TkMacOSXEmbedHandler;

MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler;

/*
 * GC CGColorRef cache for tkMacOSXColor.c
 */

typedef struct {
    unsigned long cachedForeground;
    CGColorRef cachedForegroundColor;
    unsigned long cachedBackground;
    CGColorRef cachedBackgroundColor;
} TkpGCCache;

MODULE_SCOPE TkpGCCache *TkpGetGCCache(GC gc);
MODULE_SCOPE void TkpInitGCCache(GC gc);
MODULE_SCOPE void TkpFreeGCCache(GC gc);

/*
 * Undef compatibility platform types defined above.
 */

#ifndef _TKMACPRIV
#   ifndef CGGEOMETRY_H_
#	ifndef CGFLOAT_DEFINED
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162






163
164



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203
204
205
206
207
















-
+










+
+
+
+
+
+
-
-
+
+
+







-
-
-
-
-
-
-
-
-

#define TK_LOCATION_CHANGED	1
#define TK_SIZE_CHANGED		2
#define TK_BOTH_CHANGED		3
#define TK_MACOSX_HANDLE_EVENT_IMMEDIATELY 1024

/*
 * Defines for tkTextDisp.c and tkFont.c
 * Defines for tkTextDisp.c
 */

#define TK_LAYOUT_WITH_BASE_CHUNKS	1
#define TK_DRAW_IN_CONTEXT		1

/*
 * Prototypes of internal procs not in the stubs table.
 */

MODULE_SCOPE void TkMacOSXDefaultStartupScript(void);
#if 0
MODULE_SCOPE int XSetClipRectangles(Display *d, GC gc, int clip_x_origin,
	int clip_y_origin, XRectangle* rectangles, int n, int ordering);
#endif
MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x,
	int y, int width, int height);
MODULE_SCOPE Bool TkTestLogDisplay(Drawable drawable);

MODULE_SCOPE void TkpRetainRegion(TkRegion r);
MODULE_SCOPE void TkpReleaseRegion(TkRegion r);
MODULE_SCOPE void TkpShiftButton(NSButton *button, NSPoint delta);
/*
 * Include the stubbed internal platform-specific API.
 */

#include "tkIntPlatDecls.h"

#endif /* _TKMACINT */

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXKeyEvent.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34








35

36

37

38

39
40
41



42
43
44
45
46
47
48
49
50

51
52

53
54
55
56


57
58
59

60
61
62


63
64

65
66


67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169


170
171
172


173
174
175
176
177
178





179
180

181
182
183
184
185


186
187
188
189
190
191
192
193





194
195
196
197

198
199
200
201
202
203

204
205

206
207
208



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277





































































278








279
280
281
282
283
284




















































285
286
287

288
289
290
291
292
293

294
295
296
297
298

299
300
301


302
303
304
305
306
307


308
309
310


311
312
313
314
315
316
317
318
319





320
321
322

323
324
325

326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

350
351

352
353
354
355
356
357

358
359
360
361
362
363

364
365
366
367


368
369

370
371
372


373
374
375
376
377
378

379
380
381
382
383
384
385



386
387
388
389
390
391



392
393
394
395

396
397
398
399

400
401
402
403
404
405

406
407

408
409
410
411
412
413
414
415


416
417
418
419
420
421
422
423
424
425

426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445





446
447
448


449
450
451
452
453



454
455
456
457
458
459
460

461
462
463
464



465

466
467
468
469

470

471
472
473
474
475


476
477
478
479


480
481

482
483

484
485
486
487


488
489
490


491
492
493
494
495
496
497

498
499
500
501
502


503
504
505
506
507


508
509
510
511



512
513
514
515
516




517
518

519
520
521

522

523
524
525
526
527


528
529
530
531







532
533






534
535

536
537
538
539
540


541
542

543
544
545
546


547
548

549
550
551
552
553
554




555
556

557
558
559
560
561
562
563




564
565

566
567
568
569

570
571
572
573

574
575
576


577
578

579
580
581

582
583
584
585
586

587
588
589
590
591
592
593
594
595


596
597
598
599
600



601
602
603
604
605



606
607
608
609



610
611

612
613

614
615
616

617
618
619

620
621
622
623
624

625
626
627
628

629
630
631
632
633


634
635

636
637
638
639
640
641
642
643
644
645
646
647


648
649
650
651


652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698
699
700
701
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16


17





18
19
20
21
22
23

24



25
26
27
28
29
30
31
32
33
34
35
36

37
38
39



40
41
42
43
44
45
46
47
48
49
50

51
52

53




54
55



56



57
58
59

60
61

62
63
64
65

66




































































































67
68



69
70






71
72
73
74
75


76





77
78








79
80
81
82
83




84






85


86



87
88
89









90
















































91
92
93








94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171






172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230



231



232

233



234
235

236

237


238
239



240
241

242







243
244
245
246
247



248



249


250
















251





252


253






254



255


256




257
258


259



260
261






262







263
264
265






266
267
268




269




270






271


272
273







274
275


276







277




278
















279
280
281
282
283



284
285





286
287
288







289




290
291
292
293
294
295
296
297

298
299
300
301
302
303


304
305




306
307


308
309
310
311
312
313


314
315



316
317
318
319




320
321
322

323


324
325


326


327
328
329



330
331
332
333




334
335
336
337
338
339
340
341
342

343
344
345
346
347
348


349
350




351
352
353
354
355
356
357


358
359
360
361
362
363
364
365
366
367
368
369


370
371


372




373
374


375
376
377
378



379
380
381
382


383
384
385
386




387
388
389
390


391
392
393
394

395




396



397
398


399
400


401
402
403
404
405

406





407
408


409
410





411
412
413





414
415
416




417
418
419


420


421



422



423



424

425
426

427

428
429




430
431


432










433

434
435
436
437
438

439
440
441
442
443




444

































445



446
447
448
449
450
451
452






-
-
-
-
+
+
+
+






-
-
+
-
-
-
-
-






-

-
-
-
+
+
+
+
+
+
+
+

+

+
-
+

+
-
-
-
+
+
+








-
+

-
+
-
-
-
-
+
+
-
-
-
+
-
-
-
+
+

-
+

-
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+



-
-
-
+
-
-
-

-
+
-
-
-
+
+
-

-

-
-
+
+
-
-
-
+
+
-

-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
+
-
-
-

-
-
+
-
-
-
-
+
+
-
-
+
-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+

-
-
-
-
-
-
-
+
+
-
-

-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+

+



-
+

+



-
-
+
+
-
-
-
-
+
+
-
-
+


+


-
-
+
+
-
-
-
+
+


-
-
-
-

+

-

-
-
+
+
-
-

-
-
+
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+


+


-
+

+



-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+


+



-
-
+
+
-
-
+
-
-
-
-
+
+
-
-
+



-
-
-
+
+
+
+
-
-
+



-
-
-
-
+
+
+
+
-
-
+



-
+
-
-
-
-
+
-
-
-
+
+
-
-
+

-
-
+




-
+
-
-
-
-
-


-
-
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
+
-
-
-
+
-
-
-

-
+

-

-
+

-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-

-
+
+



-
+
+



-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-







/*
 * tkMacOSXKeyEvent.c --
 *
 *	This file implements functions that decode & handle keyboard events on
 *	MacOS X.
 *
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2012 Adrian Robert.
 * Copyright © 2015-2020 Marc Culler.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2012 Adrian Robert.
 * Copyright 2015 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXConstants.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXWm.h"

/*
 * See tkMacOSXPrivate.h for macros related to key event processing.
 */

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_KEYBOARD
#endif
*/

#define NS_KEYLOG 0
#define XEVENT_MOD_MASK (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask)
static Tk_Window keyboardGrabWinPtr = NULL; /* Current keyboard grab window. */
static NSWindow *keyboardGrabNSWindow = nil; /* Its underlying NSWindow.*/


static Tk_Window grabWinPtr = NULL;
				/* Current grab window, NULL if no grab. */
static Tk_Window keyboardGrabWinPtr = NULL;
				/* Current keyboard grab window. */
static NSWindow *keyboardGrabNSWindow = nil;
                               /* NSWindow for the current keyboard grab window. */
static NSModalSession modalSession = nil;

static BOOL processingCompose = NO;
static BOOL finishedCompose = NO;
static Tk_Window composeWin = NULL;

static int caret_x = 0, caret_y = 0, caret_height = 0;

static void setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers);
static void setXEventPoint(XEvent *xEvent, Tk_Window tkwin, NSWindow *w);
static NSUInteger textInputModifiers;
static void setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state);
static unsigned isFunctionKey(unsigned int code);


#pragma mark TKApplication(TKKeyEvent)

@implementation TKApplication(TKKeyEvent)

- (NSEvent *) tkProcessKeyEvent: (NSEvent *) theEvent
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), theEvent);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
#endif
    NSWindow *w = [theEvent window];
    NSWindow*	    w;
    TkWindow *winPtr = TkMacOSXGetTkWindow(w), *grabWinPtr, *focusWinPtr;
    Tk_Window tkwin = (Tk_Window)winPtr;
    NSEventType type = [theEvent type];
    NSUInteger virt = [theEvent keyCode];
    NSEventType	    type = [theEvent type];
    NSUInteger	    modifiers, len = 0;
    NSUInteger modifiers = ([theEvent modifierFlags] &
			    NSDeviceIndependentModifierFlagsMask);
    XEvent xEvent;
    BOOL	    repeat = NO;
    MacKeycode macKC;
    UniChar keychar = 0;
    Bool can_input_text, has_modifiers = NO, use_text_input = NO;
    unsigned short  keyCode;
    NSString	    *characters = nil, *charactersIgnoringModifiers = nil;
    static NSUInteger savedModifiers = 0;
    static NSMutableArray *nsEvArray = nil;
    static NSMutableArray *nsEvArray;

    if (nsEvArray == nil) {
    if (nsEvArray == nil)
      {
        nsEvArray = [[NSMutableArray alloc] initWithCapacity: 1];
        processingCompose = NO;
    }
      }
    if (!winPtr) {
	return theEvent;
    }

    /*
     * Discard repeating KeyDown events if the repeat speed has been set to
     * "off" in System Preferences.  It is unclear why we get these, but we do.
     * See ticket [2ecb09d118].
     */

    if ([theEvent type] ==  NSKeyDown &&
	[theEvent isARepeat] &&
	[NSEvent keyRepeatDelay] < 0) {
            return theEvent;
	}

    /*
     * If a local grab is in effect, key events for windows in the
     * grabber's application are redirected to the grabber.  Key events
     * for other applications are delivered normally.  If a global
     * grab is in effect all key events are redirected to the grabber.
     */

    grabWinPtr = winPtr->dispPtr->grabWinPtr;
    if (grabWinPtr) {
	if (winPtr->dispPtr->grabFlags ||  /* global grab */
	    grabWinPtr->mainPtr == winPtr->mainPtr){ /* same application */
	    winPtr = winPtr->dispPtr->focusPtr;
	    if (!winPtr) {
		return theEvent;
	    }
	    tkwin = (Tk_Window)winPtr;
	}
    }

    /*
     * Extract the unicode character from KeyUp and KeyDown events.
     */

    if (type == NSKeyUp || type == NSKeyDown) {
	NSString *characters = [theEvent characters];
	if (characters.length > 0) {
	    keychar = [characters characterAtIndex:0];

	    /*
	     * Currently, real keys always send BMP characters, but who knows?
	     */

	    if (CFStringIsSurrogateHighCharacter(keychar)) {
		UniChar lowChar = [characters characterAtIndex:1];
		keychar = CFStringGetLongCharacterForSurrogatePair(
		    keychar, lowChar);
	    }
	} else {

	    /*
	     * This is a dead key, such as Option-e, so it usually should get
	     * passed to the TextInputClient.  But if it has a Command modifier
	     * then it is not functioning as a dead key and should not be
	     * handled by the TextInputClient.  See ticket [1626ed65b8] and the
	     * method performKeyEquivalent which is implemented in
	     * tkMacOSXMenu.c.
	     */

	    if (!(modifiers & NSCommandKeyMask)) {
		use_text_input = YES;
	    }
	}

	/*
	 * Apple uses 0x10 for unrecognized keys.
	 */

	if (keychar == 0x10) {
	    keychar = UNKNOWN_KEYCHAR;
	}

#if defined(TK_MAC_DEBUG_EVENTS) || NS_KEYLOG == 1
	TKLog(@"-[%@(%p) %s] repeat=%d mods=%x char=%x code=%lu c=%d type=%d",
	      [self class], self, sel_getName(_cmd),
	      (type == NSKeyDown) && [theEvent isARepeat], modifiers, keychar,
	      virt, w, type);
#endif

    }

    /*
     * Build a skeleton XEvent.  We need to build it here, even if we will not
     * send it, so we can pass it to TkFocusKeyEvent to determine whether the
     * target widget can input text.
     */

    setupXEvent(&xEvent, tkwin, modifiers);
    has_modifiers = xEvent.xkey.state & XEVENT_MOD_MASK;
    focusWinPtr = TkFocusKeyEvent(winPtr, &xEvent);
    if (focusWinPtr == NULL) {
	TKContentView *contentView = [w contentView];

	/*
	 * This NSEvent is being sent to a window which does not have focus.

    switch (type) {
	 * This could mean, for example, that the user deactivated the Tk app
	 * while the NSTextInputClient's popup character selection window was
	 * still open.  We attempt to abandon any ongoing composition operation
    case NSKeyUp:
      if (finishedCompose)
	 * and discard the event.
	 */

	[contentView cancelComposingText];
	return theEvent;
    }
        {
          // if we were composing, swallow the last release since we already sent
          finishedCompose = NO;
          return theEvent;
        }
    can_input_text = ((focusWinPtr->flags & TK_CAN_INPUT_TEXT) != 0);

    case NSKeyDown:
#if (NS_KEYLOG)
    TKLog(@"keyDown: %s compose sequence.\n",
	  processingCompose == YES ? "Continue" : "Begin");
#endif

	repeat = [theEvent isARepeat];
	characters = [theEvent characters];
    /*
     * Decide whether this event should be processed with the NSTextInputClient
     * protocol.
     */

    if (processingCompose ||
	(type == NSKeyDown && can_input_text && !has_modifiers &&
	 IS_PRINTABLE(keychar))
	charactersIgnoringModifiers = [theEvent charactersIgnoringModifiers];
        len = [charactersIgnoringModifiers length];
    case NSFlagsChanged:
	modifiers = [theEvent modifierFlags];
	keyCode = [theEvent keyCode];
	) {
	use_text_input = YES;
    }

	//	w = [self windowWithWindowNumber:[theEvent windowNumber]];
    /*
     * If we are processing this KeyDown event as an NSTextInputClient we do
     * not queue an XEvent.  We pass the NSEvent to our interpretKeyEvents
     * method.  When the composition sequence is complete, the callback method
     * insertText: replacementRange will be called.  That method generates a
     * keyPress XEvent with the selected character.
	w = [theEvent window];
     */

#if defined(TK_MAC_DEBUG_EVENTS) || NS_KEYLOG == 1
    if (use_text_input) {
	textInputModifiers = modifiers;

	NSLog(@"-[%@(%p) %s] r=%d mods=%u '%@' '%@' code=%u c=%d %@ %d", [self class], self, _cmd, repeat, modifiers, characters, charactersIgnoringModifiers, keyCode,([charactersIgnoringModifiers length] == 0) ? 0 : [charactersIgnoringModifiers characterAtIndex: 0], w, type);
#endif
	break;
	/*
	 * In IME the Enter key is used to terminate a composition sequence.
	 * When there are multiple choices of input text available, and the
	 * user's selected choice is not the default, it may be necessary to
	 * hit the Enter key multiple times before the text is accepted and
	 * rendered (See ticket 39de9677aa]). So when sending an Enter key
	 * during composition, we continue sending Enter keys until the
	 * inputText method has cleared the processingCompose flag.
	 */

	if (processingCompose && [theEvent keyCode] == 36) {
	    [nsEvArray addObject: theEvent];
	    while(processingCompose) {
		[[w contentView] interpretKeyEvents: nsEvArray];
	    }
	    [nsEvArray removeObject: theEvent];
	} else {
	    [nsEvArray addObject: theEvent];
	    [[w contentView] interpretKeyEvents: nsEvArray];
	    [nsEvArray removeObject: theEvent];
	}
	return theEvent;
    }

    /*
     * We are not handling this event as an NSTextInputClient, so we need to
     * finish constructing the XEvent and queue it.
     */

    macKC.v.o_s =  ((modifiers & NSShiftKeyMask ? INDEX_SHIFT : 0) |
		    (modifiers & NSAlternateKeyMask ? INDEX_OPTION : 0));
    macKC.v.virt = virt;
    switch (type) {
    case NSFlagsChanged:

	/*
	 * This XEvent is a simulated KeyPress or KeyRelease event for a
	 * modifier key.  To determine the type, note that the highest bit
	 * where the flags differ is 1 if and only if it is a KeyPress. The
	 * modifiers are saved so we can detect the next flag change.
	 */

	xEvent.xany.type = modifiers > savedModifiers ? KeyPress : KeyRelease;
	savedModifiers = modifiers;

	/*
	 * Set the keychar to MOD_KEYCHAR as a signal to TkpGetKeySym (see
	 * tkMacOSXKeyboard.c) that this is a modifier key event.
	 */

	keychar = MOD_KEYCHAR;
	break;
    case NSKeyUp:
	xEvent.xany.type = KeyRelease;
	break;
    case NSKeyDown:
	xEvent.xany.type = KeyPress;
	break;
    default:
	return theEvent; /* Unrecognized key event. */
    }
    macKC.v.keychar = keychar;
    xEvent.xkey.keycode = macKC.uint;
    setXEventPoint(&xEvent, tkwin, w);

    /*
     * Finally we can queue the XEvent, inserting a KeyRelease before a
     * repeated KeyPress.
     */

    /* Create an Xevent to add to the Tk queue. */
    if (!processingCompose) {
        unsigned int state = 0;

        if (modifiers & NSAlphaShiftKeyMask) {
          state |= LockMask;
        }
        if (modifiers & NSShiftKeyMask) {
          state |= ShiftMask;
        }
        if (modifiers & NSControlKeyMask) {
          state |= ControlMask;
        }
        if (modifiers & NSCommandKeyMask) {
          state |= Mod1Mask;		/* command key */
        }
        if (modifiers & NSAlternateKeyMask) {
          state |= Mod2Mask;		/* option key */
        }
        if (modifiers & NSNumericPadKeyMask) {
          state |= Mod3Mask;
        }
        if (modifiers & NSFunctionKeyMask) {
          state |= Mod4Mask;
        }

        /*
         * The focus must be in the FrontWindow on the Macintosh. We then query Tk
         * to determine the exact Tk window that owns the focus.
         */

        TkWindow *winPtr = TkMacOSXGetTkWindow(w);
        Tk_Window tkwin = (Tk_Window) winPtr;

        if (!tkwin) {
          TkMacOSXDbgMsg("tkwin == NULL");
          return theEvent;
        }
        tkwin = (Tk_Window) winPtr->dispPtr->focusPtr;
        if (!tkwin) {
          TkMacOSXDbgMsg("tkwin == NULL");
          return theEvent;  /* Give up. No window for this event. */
        }

        /*
         * If it's a function key, or we have modifiers other than Shift or Alt,
         * pass it straight to Tk.  Otherwise we'll send for input processing.
         */
        int code = (len == 0) ?
          0 : [charactersIgnoringModifiers characterAtIndex: 0];
        if (type != NSKeyDown || isFunctionKey(code)
            || (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) {

            XEvent xEvent;
            setupXEvent(&xEvent, w, state);

            if (type == NSFlagsChanged) {
              if (savedModifiers > modifiers) {
                xEvent.xany.type = KeyRelease;
              } else {
                xEvent.xany.type = KeyPress;
              }

              /*
               * Use special '-1' to signify a special keycode to our platform
               * specific code in tkMacOSXKeyboard.c. This is rather like what
               * happens on Windows.
               */

              xEvent.xany.send_event = -1;

              /*
               * Set keycode (which was zero) to the changed modifier
               */

              xEvent.xkey.keycode = (modifiers ^ savedModifiers);
            } else {
    if (type == NSKeyDown && [theEvent isARepeat]) {
	xEvent.xany.type = KeyRelease;
	Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	xEvent.xany.type = KeyPress;
    }
    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
              if (type == NSKeyUp || repeat) {
                xEvent.xany.type = KeyRelease;
              } else {
                xEvent.xany.type = KeyPress;
              }

              /* For command key, take input manager's word so things
                 like dvorak / qwerty layout work. */
              if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask
                  && (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask
                  && len > 0 && !isFunctionKey(code)) {
                // head off keycode-based translation in tkMacOSXKeyboard.c
                xEvent.xkey.nbytes = [characters length]; //len
              }

              if ([characters length] > 0) {
                xEvent.xkey.keycode =
                  (keyCode << 16) | (UInt16) [characters characterAtIndex:0];
                if (![characters getCString:xEvent.xkey.trans_chars
                                  maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) {
                  /* prevent SF bug 2907388 (crash on some composite chars) */
                  //PENDING: we might not need this anymore
                  TkMacOSXDbgMsg("characters too long");
                  return theEvent;
                }
              }

              if (repeat) {
                Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
                xEvent.xany.type = KeyPress;
                xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
              }
            }
            Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
            savedModifiers = modifiers;
            return theEvent;
          }  /* if send straight to TK */

      }  /* if not processing compose */

    if (type == NSKeyDown) {
        if (NS_KEYLOG)
          fprintf (stderr, "keyDown: %s compose sequence.\n",
                   processingCompose == YES ? "Continue" : "Begin");
        processingCompose = YES;
        [nsEvArray addObject: theEvent];
        [[w contentView] interpretKeyEvents: nsEvArray];
        [nsEvArray removeObject: theEvent];
      }

    savedModifiers = modifiers;

    return theEvent;
}
@end



@implementation TKContentView
@synthesize tkDirtyRect = _tkDirtyRect;
@synthesize tkNeedsDisplay = _tkNeedsDisplay;

/* <NSTextInput> implementation (called through interpretKeyEvents:]). */
/*
 * Implementation of the NSTextInputClient protocol.
 */

/* [NSTextInputClient inputText: replacementRange:] is called by
/* <NSTextInput>: called when done composing;
 * interpretKeyEvents when a composition sequence is complete.  It is also
 * called when we delete working text.  In that case the call is followed
 * immediately by doCommandBySelector: deleteBackward:
   NOTE: also called when we delete over working text, followed immed.
         by doCommandBySelector: deleteBackward: */
 */
- (void)insertText: (id)aString
  replacementRange: (NSRange)repRange
{
    int i, len, state;
    XEvent xEvent;
  int i, len = [(NSString *)aString length];
  XEvent xEvent;
    NSString *str, *keystr, *lower;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    Tk_Window tkwin = (Tk_Window)winPtr;
  TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
  Tk_Window tkwin = (Tk_Window) winPtr;
    Bool sendingIMEText = NO;

    str = ([aString isKindOfClass: [NSAttributedString class]]) ?
        [aString string] : aString;
    len = [str length];

    if (NS_KEYLOG) {
	TKLog(@"insertText '%@'\tlen = %d", aString, len);
    }
  if (NS_KEYLOG)
    NSLog (@"insertText '%@'\tlen = %d", aString, len);
  processingCompose = NO;
  finishedCompose = YES;


    /*
     * Clear any working text.
  /* first, clear any working text */
     */

    if (privateWorkingText != nil) {
  if (privateWorkingText != nil)
	sendingIMEText = YES;
    	[self deleteWorkingText];
    [self deleteWorkingText];
    }

    /*
     * Insert the string as a sequence of keystrokes.
     */

    setupXEvent(&xEvent, tkwin, textInputModifiers);
    setXEventPoint(&xEvent, tkwin, [self window]);
    xEvent.xany.type = KeyPress;

    /*
     * Apple evidently sets location to 0 to signal that an accented letter has
     * been selected from the accent menu.  An unaccented letter has already
     * been displayed and we need to erase it before displaying the accented
     * letter.
     */

    if (repRange.location == 0) {
	Tk_Window focusWin = (Tk_Window)winPtr->dispPtr->focusPtr;
	Tk_SendVirtualEvent(focusWin, "TkAccentBackspace", NULL);
    }

  /* now insert the string as keystrokes */
    /*
     * Next we generate an XEvent for each unicode character in our string.
  setupXEvent(&xEvent, [self window], 0);
     * This string could contain non-BMP characters, for example if the
     * emoji palette was used.
     *
     * NSString uses UTF-16 internally, which means that a non-BMP character is
     * represented by a sequence of two 16-bit "surrogates".  We record this in
     * the XEvent by setting the low order 21-bits of the keycode to the UCS-32
  xEvent.xany.type = KeyPress;
     * value value of the character and the virtual keycode in the high order
     * byte to the special value NON_BMP.
     */

    state = xEvent.xkey.state;
    for (i = 0; i < len; i++) {
  for (i =0; i<len; i++)
	UniChar keychar;
	MacKeycode macKC = {0};

	keychar = [str characterAtIndex:i];
    {
      xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i];
	macKC.v.keychar = keychar;
	if (CFStringIsSurrogateHighCharacter(keychar)) {
      [[aString substringWithRange: NSMakeRange(i,1)]
	    UniChar lowChar = [str characterAtIndex:++i];
	    macKC.v.keychar = CFStringGetLongCharacterForSurrogatePair(
				  (UniChar)keychar, lowChar);
        getCString: xEvent.xkey.trans_chars
         maxLength: XMaxTransChars encoding: NSUTF8StringEncoding];
	    macKC.v.virt = NON_BMP_VIRTUAL;
	} else if (repRange.location == 0 || sendingIMEText) {
	    macKC.v.virt = REPLACEMENT_VIRTUAL;
	} else {
	    macKC.uint = TkMacOSXAddVirtual(macKC.uint);
	    xEvent.xkey.state |= INDEX2STATE(macKC.x.xvirtual);
      xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars);
	}
	keystr = [[NSString alloc] initWithCharacters:&keychar length:1];
	lower = [keystr lowercaseString];
	if (![keystr isEqual: lower]) {
	    macKC.v.o_s |= INDEX_SHIFT;
	    xEvent.xkey.state |= ShiftMask;
	}
      xEvent.xany.type = KeyPress;
      Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);

	if (xEvent.xkey.state & Mod2Mask) {
	    macKC.v.o_s |= INDEX_OPTION;
	}
	xEvent.xkey.keycode = macKC.uint;
    	xEvent.xany.type = KeyPress;
    	Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
      xEvent.xany.type = KeyRelease;
      xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
      Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	xEvent.xkey.state = state;
    }
}

      xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
/*
 * This required method is allowed to return nil.
 */

    }
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)theRange
      actualRange:(NSRangePointer)thePointer
{
    (void)theRange;
    (void)thePointer;

}
    return nil;
}


/*
 * This method is supposed to insert (or replace selected text with) the string
 * argument. If the argument is an NSString, it should be displayed with a
 * distinguishing appearance, e.g underlined.
 */

- (void)setMarkedText: (id)aString
/* <NSTextInput>: inserts display of composing characters */
- (void)setMarkedText: (id)aString selectedRange: (NSRange)selRange
	selectedRange: (NSRange)selRange
     replacementRange: (NSRange)repRange
{
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    if (!winPtr) {
	return;
    }
    Tk_Window focusWin = (Tk_Window)winPtr->dispPtr->focusPtr;
    NSString *temp;
    NSString *str;
  NSString *str = [aString respondsToSelector: @selector (string)] ?
    (void)selRange;

    str = ([aString isKindOfClass: [NSAttributedString class]]) ?
        [aString string] : aString;
    [aString string] : aString;
    if (focusWin) {

	/*
	 * Remember the widget where the composition is happening, in case it
	 * gets defocussed during the composition.
	 */

	composeWin = focusWin;
    } else {
	return;
    }
    if (NS_KEYLOG) {
	TKLog(@"setMarkedText '%@' len =%lu range %lu from %lu", str,
	      (unsigned long) [str length], (unsigned long) selRange.length,
	      (unsigned long) selRange.location);
    }
  if (NS_KEYLOG)
    NSLog (@"setMarkedText '%@' len =%lu range %lu from %lu", str,
	   (unsigned long) [str length], (unsigned long) selRange.length,
	   (unsigned long) selRange.location);


    if (privateWorkingText != nil) {
	[self deleteWorkingText];
  if (privateWorkingText != nil)
    [self deleteWorkingText];
    }

    if ([str length] == 0) {
	return;
    }
  if ([str length] == 0)
    return;


    /*
     * Use our insertText method to display the marked text.
     */

    Tk_SendVirtualEvent(focusWin, "TkStartIMEMarkedText", NULL);
    processingCompose = YES;
  processingCompose = YES;
    temp = [str copy];
    [self insertText: temp replacementRange:repRange];
    privateWorkingText = temp;
    Tk_SendVirtualEvent(focusWin, "TkEndIMEMarkedText", NULL);
  privateWorkingText = [str copy];

  //PENDING: insert workingText underlined
}


- (BOOL)hasMarkedText
{
    return privateWorkingText != nil;
  return privateWorkingText != nil;
}


- (NSRange)markedRange
{
    NSRange rng = privateWorkingText != nil
	? NSMakeRange(0, [privateWorkingText length])
  NSRange rng = privateWorkingText != nil
    ? NSMakeRange (0, [privateWorkingText length]) : NSMakeRange (NSNotFound, 0);
	: NSMakeRange(NSNotFound, 0);

    if (NS_KEYLOG) {
	TKLog(@"markedRange request");
  if (NS_KEYLOG)
    NSLog (@"markedRange request");
    }
    return rng;
  return rng;
}


- (void)unmarkText
{
    if (NS_KEYLOG) {
	TKLog(@"unmarkText");
  if (NS_KEYLOG)
    NSLog (@"unmark (accept) text");
    }
    [self deleteWorkingText];
    processingCompose = NO;
  [self deleteWorkingText];
  processingCompose = NO;
}

/*
 * Called by the system to get a position for popup character selection windows
 * such as a Character Palette, or a selection menu for IME.
 */

/* used to position char selection windows, etc. */
- (NSRect)firstRectForCharacterRange: (NSRange)theRange
			 actualRange: (NSRangePointer)thePointer
{
    NSRect rect;
    NSPoint pt;
  NSRect rect;
  NSPoint pt;
    (void)theRange;
    (void)thePointer;

    pt.x = caret_x;
    pt.y = caret_y;
  pt.x = caret_x;
  pt.y = caret_y;

    pt = [self convertPoint: pt toView: nil];
    pt = [[self window] tkConvertPointToScreen: pt];
    pt.y -= caret_height;
  pt = [self convertPoint: pt toView: nil];
  pt = [[self window] convertPointToScreen: pt];
  pt.y -= caret_height;

    rect.origin = pt;
    rect.size.width = 0;
    rect.size.height = caret_height;
    return rect;
  rect.origin = pt;
  rect.size.width = caret_height;
  rect.size.height = caret_height;
  return rect;
}


- (NSInteger)conversationIdentifier
{
    return (NSInteger) self;
  return (NSInteger)self;
}


- (void)doCommandBySelector: (SEL)aSelector
{
    if (NS_KEYLOG) {
	TKLog(@"doCommandBySelector: %@", NSStringFromSelector(aSelector));
  if (NS_KEYLOG)
    NSLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector));
    }
    processingCompose = NO;
    if (aSelector == @selector (deleteBackward:)) {
	TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
  processingCompose = NO;
  if (aSelector == @selector (deleteBackward:))
    {
      /* happens when user backspaces over an ongoing composition:
         throw a 'delete' into the event queue */
      XEvent xEvent;
      setupXEvent(&xEvent, [self window], 0);
	Tk_Window focusWin = (Tk_Window)winPtr->dispPtr->focusPtr;
	Tk_SendVirtualEvent(focusWin, "TkAccentBackspace", NULL);
      xEvent.xany.type = KeyPress;
      xEvent.xkey.nbytes = 1;
      xEvent.xkey.keycode = (0x33 << 16) | 0x7F;
      xEvent.xkey.trans_chars[0] = 0x7F;
      xEvent.xkey.trans_chars[1] = 0x0;
      Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
    }
}


- (NSArray *)validAttributesForMarkedText
{
    static NSArray *arr = nil;
    if (arr == nil) {
  static NSArray *arr = nil;
  if (arr == nil) arr = [NSArray new];
	arr = [[NSArray alloc] initWithObjects:
	    NSUnderlineStyleAttributeName,
 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
	    NSUnderlineColorAttributeName,
	    nil];
	[arr retain];
    }
  return arr;
}
    return arr;
}


- (NSRange)selectedRange
{
    if (NS_KEYLOG) {
	TKLog(@"selectedRange request");
    }
  if (NS_KEYLOG)
    NSLog (@"selectedRange request");
  return NSMakeRange (NSNotFound, 0);
}
    return NSMakeRange(0, 0);
}


- (NSUInteger)characterIndexForPoint: (NSPoint)thePoint
{
    (void)thePoint;
    if (NS_KEYLOG) {
	TKLog(@"characterIndexForPoint request");
    }
  if (NS_KEYLOG)
    NSLog (@"characterIndexForPoint request");
  return 0;
}
    return NSNotFound;
}


- (NSAttributedString *)attributedSubstringFromRange: (NSRange)theRange
{
    static NSAttributedString *str = nil;
  static NSAttributedString *str = nil;
    (void)theRange;

    if (str == nil) {
	str = [NSAttributedString new];
  if (str == nil) str = [NSAttributedString new];
    }
    if (NS_KEYLOG) {
	TKLog(@"attributedSubstringFromRange request");
  if (NS_KEYLOG)
    NSLog (@"attributedSubstringFromRange request");
    }
    return str;
  return str;
}
/* End of NSTextInputClient implementation. */

/* End <NSTextInput> impl. */
@end


@implementation TKContentView(TKKeyEvent)

/* delete display of composing characters [not in <NSTextInput>] */
/*
 * Tell the widget to erase the displayed composing characters.  This
 * is not part of the NSTextInputClient protocol.
 */

- (void)deleteWorkingText
{
    if (privateWorkingText == nil) {
	return;
  if (privateWorkingText == nil)
    return;
    } else {

	if (NS_KEYLOG) {
	    TKLog(@"deleteWorkingText len = %lu\n",
		  (unsigned long)[privateWorkingText length]);
  if (NS_KEYLOG)
    NSLog(@"deleteWorkingText len = %lu\n",
	    (unsigned long)[privateWorkingText length]);
	}

	[privateWorkingText release];
	privateWorkingText = nil;
	processingCompose = NO;
  [privateWorkingText release];
  privateWorkingText = nil;
  processingCompose = NO;
	if (composeWin) {
	    Tk_SendVirtualEvent(composeWin, "TkClearIMEMarkedText", NULL);
	}
    }

  //PENDING: delete working text
}
}

@end
- (void)cancelComposingText
{

    if (NS_KEYLOG) {
	TKLog(@"cancelComposingText");
    }

    [self deleteWorkingText];
    processingCompose = NO;
}


@end

/*
 * Set up basic fields in xevent for keyboard input.
 *  Set up basic fields in xevent for keyboard input.
 */

static void
setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers)
setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state)
{
    unsigned int state = 0;
    Display *display;

    if (tkwin == NULL) {
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    Tk_Window tkwin = (Tk_Window) winPtr;
	return;
    }

    display = Tk_Display(tkwin);
    if (modifiers) {
	state = (modifiers & NSAlphaShiftKeyMask ? LockMask    : 0) |
	        (modifiers & NSShiftKeyMask      ? ShiftMask   : 0) |
	        (modifiers & NSControlKeyMask    ? ControlMask : 0) |
	        (modifiers & NSCommandKeyMask    ? Mod1Mask    : 0) |
	        (modifiers & NSAlternateKeyMask  ? Mod2Mask    : 0) |
	        (modifiers & NSNumericPadKeyMask ? Mod3Mask    : 0) |
	        (modifiers & NSFunctionKeyMask   ? Mod4Mask    : 0) ;
    }
    memset(xEvent, 0, sizeof(XEvent));
    xEvent->xany.serial = LastKnownRequestProcessed(display);
    xEvent->xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    xEvent->xany.send_event = false;
    xEvent->xany.display = Tk_Display(tkwin);
    xEvent->xany.window = Tk_WindowId(tkwin);

    xEvent->xkey.root = XRootWindow(display, 0);
    xEvent->xkey.root = XRootWindow(Tk_Display(tkwin), 0);
    xEvent->xkey.subwindow = None;
    xEvent->xkey.time = TkpGetMS();
    xEvent->xkey.state = state;
    xEvent->xkey.same_screen = true;
    /* No need to initialize other fields implicitly here,
     * because of the memset() above. */
}

    xEvent->xkey.trans_chars[0] = 0;
static void
setXEventPoint(
    XEvent *xEvent,
    Tk_Window tkwin,
    NSWindow *w)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    NSPoint local = [w  mouseLocationOutsideOfEventStream];
    NSPoint global = [w tkConvertPointToScreen: local];
    int win_x, win_y;

    if (Tk_IsEmbedded(winPtr)) {
	TkWindow *contPtr = (TkWindow *)Tk_GetOtherWindow(tkwin);
	if (Tk_IsTopLevel(contPtr)) {
	    local.x -= contPtr->wmInfoPtr->xInParent;
	    local.y -= contPtr->wmInfoPtr->yInParent;
	} else {
	    MacDrawable *topMacWin = TkMacOSXGetHostToplevel(winPtr);
	    if (topMacWin) {
		TkWindow *topPtr = topMacWin->winPtr;
		local.x -= (topPtr->wmInfoPtr->xInParent + contPtr->changes.x);
		local.y -= (topPtr->wmInfoPtr->yInParent + contPtr->changes.y);
	    }
	}
    } else if (winPtr->wmInfoPtr != NULL) {
	local.x -= winPtr->wmInfoPtr->xInParent;
	local.y -= winPtr->wmInfoPtr->yInParent;
    }
    tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y);
    local.x = win_x;
    local.y = win_y;
    global.y = TkMacOSXZeroScreenHeight() - global.y;
    xEvent->xbutton.x = local.x;
    xEvent->xkey.nbytes = 0;
    xEvent->xbutton.y = local.y;
    xEvent->xbutton.x_root = global.x;
    xEvent->xbutton.y_root = global.y;
}

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
712
713
714
715
716
717
718
719
720
721
722




723
724
725
726
727
728
729



730
731
732


733
734
735
736

737
738
739
740
741
742
743
744
463
464
465
466
467
468
469




470
471
472
473
474
475





476
477
478
479


480
481




482

483
484
485
486
487
488
489







-
-
-
-
+
+
+
+


-
-
-
-
-
+
+
+

-
-
+
+
-
-
-
-
+
-







 *----------------------------------------------------------------------
 */

int
XGrabKeyboard(
    Display* display,
    Window grab_window,
    TCL_UNUSED(Bool),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(Time))
    Bool owner_events,
    int pointer_mode,
    int keyboard_mode,
    Time time)
{
    keyboardGrabWinPtr = Tk_IdToWindow(display, grab_window);
    TkWindow *captureWinPtr = (TkWindow *) TkpGetCapture();

    if (keyboardGrabWinPtr && captureWinPtr) {
	NSWindow *w = TkMacOSXGetNSWindowForDrawable(grab_window);
	MacDrawable *macWin = (MacDrawable *)grab_window;
    if (keyboardGrabWinPtr && grabWinPtr) {
	NSWindow *w = TkMacOSXDrawableWindow(grab_window);
	MacDrawable *macWin = (MacDrawable *) grab_window;

	if (w && macWin->toplevel->winPtr == (TkWindow *) captureWinPtr) {
	    if (modalSession ) {
	if (w && macWin->toplevel->winPtr == (TkWindow*) grabWinPtr) {
	    if (modalSession) {
		if (keyboardGrabNSWindow == w) {
		    return GrabSuccess;
		} else {
		    Tcl_Panic("XGrabKeyboard: already grabbed");
		Tcl_Panic("XGrabKeyboard: already grabbed");
		}
	    }
	    keyboardGrabNSWindow = w;
	    [w retain];
	    modalSession = [NSApp beginModalSessionForWindow:w];
	}
    }
    return GrabSuccess;
756
757
758
759
760
761
762
763

764
765
766


767
768
769
770
771
772
773
774
775
776



















777

778
779
780
781
782
783
784
501
502
503
504
505
506
507

508
509


510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

541
542
543
544
545
546
547
548







-
+

-
-
+
+










+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







 *
 * Side effects:
 *	Sets the keyboard focus back to the value before the grab.
 *
 *----------------------------------------------------------------------
 */

int
void
XUngrabKeyboard(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Time))
    Display* display,
    Time time)
{
    if (modalSession) {
	[NSApp endModalSession:modalSession];
	modalSession = nil;
    }
    if (keyboardGrabNSWindow) {
	[keyboardGrabNSWindow release];
	keyboardGrabNSWindow = nil;
    }
    keyboardGrabWinPtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetCapture --
 *
 * Results:
 *	Returns the current grab window
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
TkMacOSXGetCapture(void)
{
    return Success;
    return grabWinPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetModalSession --
 *
796
797
798
799
800
801
802




























803
804
805

806
807

808
809
810
811
812

813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

834
835
836

837

838
839
840
841
842
843
844
845
846
847


848
849
850
851
852
853
854
855

856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873




874
875


876
877









































































878
879
880
881
882
883
884
885
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596

597


598





599
600
601
602
603
604

605


606
607
608
609
610
611
612
613
614
615
616


617

618
619
620

621


622
623






624
625
626
627
628





629
630
631
632
633
634


635
636
637

638
639
640
641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
+
-
-
-
-
-
+





-
+
-
-











-
-
+
-


+
-
+
-
-


-
-
-
-
-
-
+
+



-
-
-
-
-
+





-
-
+


-








+
+
+
+

-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








{
    return modalSession;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpSetCapture --
 *
 *	This function captures the mouse so that all future events will be
 *	reported to this window, even if the mouse is outside the window. If
 *	the specified window is NULL, then the mouse is released.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the capture flag and captures the mouse.
 *
 *----------------------------------------------------------------------
 */

void
TkpSetCapture(
    TkWindow *winPtr)		/* Capture window, or NULL. */
{
    while (winPtr && !Tk_IsTopLevel(winPtr)) {
	winPtr = winPtr->parentPtr;
    }
    grabWinPtr = (Tk_Window) winPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetCaretPos --
 *
 *	This enables correct placement of the popups used for character
 *	This enables correct placement of the XIM caret. This is called by
 *      selection by the NSTextInputClient.  It gets called by text entry
 *      widgets whenever the cursor is drawn.  It does nothing if the widget's
 *	widgets to indicate their cursor placement, and the caret location is
 *      NSWindow is not the current KeyWindow.  Otherwise it updates the
 *      display's caret structure and records the caret geometry in static
 *      variables for use by the NSTextInputClient implementation.  Any
 *      widget passed to this function will be marked as being able to input
 *      text by setting the TK_CAN_INPUT_TEXT flag.
 *	used by TkpGetString to place the XIM caret.
 *
 * Results:
 *	None
 *
 * Side effects:
 *      Sets the CAN_INPUT_TEXT flag on the widget passed as tkwin.  May update
 *	None
 *      the display's caret structure as well as the static variables caret_x,
 *      caret_y and caret_height.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetCaretPos(
    Tk_Window tkwin,
    int x,
    int y,
    int height)
 {
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkCaret *caretPtr = &(winPtr->dispPtr->caret);
    TkCaret *caretPtr = &(((TkWindow *) tkwin)->dispPtr->caret);
    NSWindow *w = TkMacOSXGetNSWindowForDrawable(Tk_WindowId(tkwin));

    /*
     * Prevent processing anything if the values haven't changed. Windows only
     * Register this widget as being capable of text input, so we know we
     * has one display, so we can do this with statics.
     * should process (appropriate) key events for this window with the
     * NSTextInputClient protocol.
     */

    winPtr->flags |= TK_CAN_INPUT_TEXT;
    if (w && ![w isKeyWindow]) {
	return;
    }
    if ((caretPtr->winPtr == winPtr
	 && caretPtr->x == x) && (caretPtr->y == y)) {
    if ((caretPtr->winPtr == ((TkWindow *) tkwin))
	    && (caretPtr->x == x) && (caretPtr->y == y)) {
	return;
    }

    /*
     * Update the display's caret information.
     */

    caretPtr->winPtr = winPtr;
    caretPtr->winPtr = ((TkWindow *) tkwin);
    caretPtr->x = x;
    caretPtr->y = y;
    caretPtr->height = height;

    /*
     * Record the caret geometry in static variables for use when processing
     * key events.  We use the TKContextView coordinate system for this.
     * As in Windows, adjust to the toplevel to get the coords right.
     */

    caret_height = height;
    while (!Tk_IsTopLevel(tkwin)) {
	x += Tk_X(tkwin);
	y += Tk_Y(tkwin);
	tkwin = Tk_Parent(tkwin);
	if (tkwin == NULL) {
	    return;
	}
    }

    /* But adjust for fact that NS uses flipped view. */
    y = Tk_Height(tkwin) - y;

    caret_x = x;
    caret_y = Tk_Height(tkwin) - y;
    caret_y = y;
    caret_height = height;
}


static unsigned convert_ns_to_X_keysym[] =
{
  NSHomeFunctionKey,            0x50,
  NSLeftArrowFunctionKey,       0x51,
  NSUpArrowFunctionKey,         0x52,
  NSRightArrowFunctionKey,      0x53,
  NSDownArrowFunctionKey,       0x54,
  NSPageUpFunctionKey,          0x55,
  NSPageDownFunctionKey,        0x56,
  NSEndFunctionKey,             0x57,
  NSBeginFunctionKey,           0x58,
  NSSelectFunctionKey,          0x60,
  NSPrintFunctionKey,           0x61,
  NSExecuteFunctionKey,         0x62,
  NSInsertFunctionKey,          0x63,
  NSUndoFunctionKey,            0x65,
  NSRedoFunctionKey,            0x66,
  NSMenuFunctionKey,            0x67,
  NSFindFunctionKey,            0x68,
  NSHelpFunctionKey,            0x6A,
  NSBreakFunctionKey,           0x6B,

  NSF1FunctionKey,              0xBE,
  NSF2FunctionKey,              0xBF,
  NSF3FunctionKey,              0xC0,
  NSF4FunctionKey,              0xC1,
  NSF5FunctionKey,              0xC2,
  NSF6FunctionKey,              0xC3,
  NSF7FunctionKey,              0xC4,
  NSF8FunctionKey,              0xC5,
  NSF9FunctionKey,              0xC6,
  NSF10FunctionKey,             0xC7,
  NSF11FunctionKey,             0xC8,
  NSF12FunctionKey,             0xC9,
  NSF13FunctionKey,             0xCA,
  NSF14FunctionKey,             0xCB,
  NSF15FunctionKey,             0xCC,
  NSF16FunctionKey,             0xCD,
  NSF17FunctionKey,             0xCE,
  NSF18FunctionKey,             0xCF,
  NSF19FunctionKey,             0xD0,
  NSF20FunctionKey,             0xD1,
  NSF21FunctionKey,             0xD2,
  NSF22FunctionKey,             0xD3,
  NSF23FunctionKey,             0xD4,
  NSF24FunctionKey,             0xD5,

  NSBackspaceCharacter,         0x08,  /* 8: Not on some KBs. */
  NSDeleteCharacter,            0xFF,  /* 127: Big 'delete' key upper right. */
  NSDeleteFunctionKey,          0x9F,  /* 63272: Del forw key off main array. */

  NSTabCharacter,		0x09,
  0x19,				0x09,  /* left tab->regular since pass shift */
  NSCarriageReturnCharacter,	0x0D,
  NSNewlineCharacter,		0x0D,
  NSEnterCharacter,		0x8D,

  0x1B,				0x1B   /* escape */
};


static unsigned isFunctionKey(unsigned code)
{
    const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym)
                                / sizeof (convert_ns_to_X_keysym[0]));
  unsigned keysym;
  for (keysym = 0; keysym < last_keysym; keysym += 2)
    if (code == convert_ns_to_X_keysym[keysym])
      return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
  return 0;
 }

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXKeyboard.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38











39
40
41


42
43
44
45



46
47
48



49
50

51
52
53
54


55
56
57






58
59
60



61
62
63
64
65

66
67
68
69
70
71
72
73


74
75
76
77
78








79
80
81
82
83
84
85
86


87
88
89
90
91
92
93







94
95
96
97
98
99
100





101
102
103
104
105
106


107
108
109
110
111
112
113
114
115
116

117
118










119
120

121
122
123






124
125
126
127
128




129
130
131
132
133


134
135
136
137

138
139
140
141
142
143
144
145
146





147
148
149
150
151
152
153
154
155
156

157
158

159
160
161
162
163
164
165
166
167
168

169
170




171
172
173
174
175
176
177
178
179
180
181
182

183
184
185

186
187

188
189
190
191


192
193
194
195
196
197
198


199
200
201
202


203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222




223
224
225

226
227
228
229
230
231

232
233
234
235
236

237
238



239
240
241
242
243
244
245

246
247
248
249
250
251


252
253
254
255




256
257
258
259
260
261

262
263

264



265
266







267
268
269
270
271
272
273
274
275




276
277

278
279

280
281
282
283



284
285
286
287




288
289

290
291

292
293
294
295
296
297
298
299
300

301
302
303


304
305
306
307
308
309

310
311

312
313
314
315


316
317
318

319
320
321
322
323
324
325

326
327
328
329

330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353

354
355
356
357
358

359

360
361
362
363
364

365

366
367
368
369

370
371

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390


391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407



408
409
410
411
412


413
414

415


416
417

418
419
420
421
422
423
424




425
426



427






428
429
430
431
432
433
434

435
436
437
438

439
440
441
442
443









444
445
446
447
448
449


450
451
452
453
454
455

456
457
458
459
460



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481
482

483
484
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509

510
511
512
513
514
515
516
517

518
519
520
521

522
523
524
525
526
527
528
529
530
531

532
533
534







535

536
537
538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554
1
2
3
4
5



6
7
8

9
10
11
12
13
14


15

16
17





18
19












20
21
22
23
24
25
26
27
28
29
30



31
32




33
34
35



36
37
38


39




40
41



42
43
44
45
46
47



48
49
50

51



52








53
54





55
56
57
58
59
60
61
62








63
64







65
66
67
68
69
70
71







72
73
74
75
76






77
78








79

80


81
82
83
84
85
86
87
88
89
90


91



92
93
94
95
96
97
98




99
100
101
102


103


104
105

106


107
108
109
110
111
112




113
114
115
116
117
118
119
120
121
122
123
124

125

126
127

128

129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157

158


159
160



161
162







163
164




165
166












167








168
169
170
171
172


173
174
175
176
177
178

179
180




181


182
183
184
185
186
187
188
189


190
191
192
193
194
195

196
197
198



199
200
201
202
203





204


205
206
207
208
209


210
211
212
213
214
215
216

217







218
219
220
221


222


223




224
225
226




227
228
229
230


231


232

233
234
235
236
237
238
239

240
241


242
243



244
245

246
247

248
249
250
251

252
253
254
255

256
257
258
259
260

261

262
263
264
265

266
267
268
269

270
271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289

290
291
292
293
294

295
296
297
298
299
300
301
302
303

304
305
306

307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327


328
329


330
331

332

333
334
335
336
337
338
339
340



341
342
343

344
345


346
347


348
349
350
351
352

353
354


355
356


357
358
359
360
361
362
363
364
365

366
367
368
369
370
371
372
373
374
375
376


377

378
379

380





381
382
383
384
385
386
387
388
389
390
391




392
393
394
395




396





397
398
399
400









401
402
403
404
405
406
407

408

409
410

411
412
413
414
415
416
417
418
419
420

421
422
423
424
425
426




427






428

429
430
431
432
433
434
435
436

437

438
439

440
441
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471

472

473
474
475
476
477
478
479





-
-
-
+
+
+
-






-
-
+
-


-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
-

-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-

-
+
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+
-
-

-
-
+
+
-

-
-
+





-
-
-
-
+
+
+
+
+







-

-
+

-
+
-








-
+


+
+
+
+











-
+


-
+
-
-
+

-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+

-
-
+





-
+

-
-
-
-
+
-
-
+
+
+





-
-
+





-
+
+

-
-
-
+
+
+
+

-
-
-
-
-
+
-
-
+

+
+
+
-
-
+
+
+
+
+
+
+
-

-
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
+
-







-
+

-
-
+
+
-
-
-


-
+

-
+



-
+
+


-
+




-

-
+



-
+



-
+












-
+






-
+




-
+

+





+
-
+


-

+

-
+

















-
-
+
+
-
-


-
+
-








-
-
-
+
+
+
-


-
-
+
+
-
-
+

+
+

-
+

-
-


-
-
+
+
+
+


+
+
+
-
+
+
+
+
+
+





-
-
+
-


-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
-
-
+
+


-
-
-
-
+
-
-
-
-
-
+
+
+

-
-
-
-
-
-
-
-
-







-
+
-


-
+









-
+





-
-
-
-
+
-
-
-
-
-
-

-
+







-
+
-


-
+









-
+



+
+
+
+
+
+
+
-
+










-
+
-







/*
 * tkMacOSXKeyboard.c --
 *
 *	Routines to support keyboard events on the Macintosh.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2020 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXConstants.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXKeysyms.h"

/*
 * About keyboards
 * ---------------
 * Keyboards are complicated.  This long comment is an attempt to provide
 * enough information about them to make it possible to read and understand
 * the code in this file.
 * A couple of simple definitions to make code a bit more self-explaining.
 *
 * Every key on a keyboard is identified by a number between 0 and 127.  In
 * macOS, pressing or releasing a key on the keyboard generates an NSEvent of
 * type KeyDown, KeyUp or FlagsChanged.  The 8-bit identifier of the key that
 * was involved in this event is provided in the attribute [NSEvent keyCode].
 * Apple also refers to this number as a "Virtual KeyCode".  In this file, to
 * avoid confusion with other uses of the word keycode, we will refer to this
 * key identifier as a "virtual keycode", usually the value of a variable named
 * "virtual".
 *
 * Some of the keys on a keyboard, such as the Shift, Option, Command or
 * Control keys, are "modifier" keys.  The effect of pressing or releasing a
 * key depends on three quantities:
 * For the assignments of Mod1==meta==command and Mod2==alt==option, see also
 * tkMacOSXMouseEvent.c.
 */

#define LATIN1_MAX	 255
#define MAC_KEYCODE_MAX	 0x7F
#define MAC_KEYCODE_MASK 0x7F
#define COMMAND_MASK	 Mod1Mask
#define OPTION_MASK	 Mod2Mask


 *     - which key is being pressed or released
 *     - which modifier keys are being held down at the moment
 *     - the current keyboard layout
/*
 * Tables enumerating the special keys defined on Mac keyboards. These are
 * If the key is a modifier key then the effect of pressing or releasing it is
 * only to change the list of which modifier keys are being held down.  Apple
 * reports this by sending an NSEvent of type FlagsChanged.  X11 reports this
 * as a KeyPress or KeyRelease event for the modifier key.  Note that there may
 * necessary for correct keysym mappings for all keys where the keysyms are
 * not identical with their ASCII or Latin-1 code points.
 */
 * be combinations of modifier key states and key presses which have no effect.
 *
 * In X11 every meaningful effect from a key action is identified by a 16 bit

typedef struct {
    int keycode;		/* Macintosh keycode. */
 * value known as a keysym.  Every keysym has an associated string name, also
 * known as a keysym.  The Tk bind command uses the X11 keysym string to
    KeySym keysym;		/* X windows keysym. */
 * specify a key event which should invoke a certain action and it provides the
 * numeric and symbolic keysyms to the bound proc as %N and %K respectively.
 * An X11 XEvent which reports a KeyPress or KeyRelease does not include the
 * keysym.  Instead it includes a platform-specific numerical value called a
} KeyInfo;

 * keycode which is available to the bound procedure as %k.  A platform port of
 * Tk must provide functions which convert between keycodes and numerical
 * keysyms.  Conversion between numerical and symbolic keysyms is provided by
/*
 * Notes on keyArray:
 *
 * 0x34, XK_Return - Powerbooks use this and some keymaps define it.
 *
 * 0x4C, XK_Return - XFree86 and Apple's X11 call this one XK_KP_Enter.
 * the generic Tk code, although platforms are allowed to provide their own by
 * defining the XKeysymToString and XStringToKeysym functions and undefining
 * the macro REDO_KEYSYM_LOOKUP.  This macOS port uses the conversion provided
 *
 * 0x47, XK_Clear - This key is NumLock when used on PCs, but Mac
 * applications don't use it like that, nor does Apple's X11.
 * by the generic code.
 *
 * When the keyboard focus is on a Tk widget which provides text input, there
 * are some X11 KeyPress events which cause text to be inserted.  We will call
 * these "printable" events. The UCS-32 character stored in the keycode field
 * All other keycodes are taken from the published ADB keyboard layouts.
 * of an XKeyEvent depends on more than the three items above.  It may also
 * depend on the sequence of keypresses that preceded the one being reported by
 * the XKeyEvent.  For example, on macOS an <Alt-e> event does not cause text
 * to be inserted but a following <a> event causes an accented 'a' to be
 * inserted.  The events in such a composition sequence, other than the final
 * one, are known as "dead-key" events.
 *
 * MacOS packages the information described above in a different way.  Every
 */

 * meaningful effect from a key action *other than changing the state of
 * modifier keys* is identified by a unicode string which is provided as the
 * [NSEvent characters] attribute of a KeyDown or KeyUp event.  FlagsChanged
 * events do not have characters.  In principle, the characters attribute could
 * be an arbitrary unicode string but in practice it is always a single UTF-16
static KeyInfo keyArray[] = {
    {0x24,	XK_Return},
    {0x30,	XK_Tab},
    {0x33,	XK_BackSpace},
    {0x34,	XK_Return},
    {0x35,	XK_Escape},

    {0x47,	XK_Clear},
 * character which we usually store in a variable named keychar.  While the
 * keychar is a legal unicode code point, it does not necessarily represent a
 * glyph. MacOS uses unicode code points in the private-use range 0xF700-0xF8FF
 * for non-printable events which have no associated ASCII code point.  For
 * example, pressing the F2 key generates an NSEvent with the character 0xF705,
 * the Backspace key produces 0x7F (ASCII del) and the Delete key produces
 * 0xF728.
 *
    {0x4C,	XK_KP_Enter},

 * With the exception of modifier keys, it is possible to translate between
 * numerical X11 keysyms and macOS keychars; this file constructs Tcl hash
 * tables to do this job, using data defined in the file tkMacOSXKeysyms.h.
 * The code here adopts the convention that the keychar of any modifier key
 * is MOD_KEYCHAR.  Keys which do not appear on any Macintosh keyboard, such
 * as the Menu key on PC keyboards, are assigned UNKNOWN_KEYCHAR.
 *
    {0x72,	XK_Help},
    {0x73,	XK_Home},
    {0x74,	XK_Page_Up},
    {0x75,	XK_Delete},
    {0x77,	XK_End},
    {0x79,	XK_Page_Down},

 * The macosx platform-specific scheme for generating a keycode when mapping an
 * NSEvent of type KeyUp, KeyDown or FlagsChanged to an XEvent of type KeyPress
 * or KeyRelease is as follows:
 *     keycode = (virtual << 24) | index << 22 | keychar
 * where index is a 2-bit quantity whose bits indicate the state of the Option
 * and Shift keys.
 *
    {0x7B,	XK_Left},
    {0x7C,	XK_Right},
    {0x7D,	XK_Down},
    {0x7E,	XK_Up},

 * A few remarks are in order.  First, we are using 32 bits for the keycode and
 * we are allowing room for up to 22 bits for the keychar.  This means that
 * there is enough room in the keycode to hold a UTF-32 character, which only
 * requires 21 bits.  Second, the KeyCode type for the keycode field in an
 * XEvent is currently defined as unsigned int, which was modified from the
 * unsigned short used in X11 in order to accomodate macOS. Finally, there is
    {0,		0}
};
 * no obstruction to generating KeyPress events for keys that represent letters
 * which do not exist on the current keyboard layout.  And different keyboard
 * layouts can assign a given letter to different keys.  So we need a
 * convention for what value to assign to "virtual" when computing the keycode
 * for a generated event.  The convention used here is as follows: If there is
 * a key on the current keyboard which produces the keychar, use the virtual
 * keycode of that key.  Otherwise set virtual = NO_VIRTUAL.
 */


static KeyInfo virtualkeyArray[] = {
/*
 * See tkMacOSXPrivate.h for macros and structures related to key event processing.
    {122,	XK_F1},
    {120,	XK_F2},
    {99,	XK_F3},
    {118,	XK_F4},
    {96,	XK_F5},
    {97,	XK_F6},
    {98,	XK_F7},
    {100,	XK_F8},
    {101,	XK_F9},
    {109,	XK_F10},
 */

    {103,	XK_F11},
/*
 * Hash tables and array used to translate between various key attributes.
 */
    {111,	XK_F12},
    {105,	XK_F13},
    {107,	XK_F14},
    {113,	XK_F15},
    {0,		0}
};

static Tcl_HashTable special2keysym;	/* Special virtual keycode to keysym */
static Tcl_HashTable keysym2keycode;	/* keysym to XEvent keycode */
static Tcl_HashTable keysym2unichar;	/* keysym to unichar */
static Tcl_HashTable unichar2keysym;	/* unichar to X11 keysym */
static int initialized = 0;
static Tcl_HashTable keycodeTable;	/* keyArray hashed by keycode value. */
static Tcl_HashTable vkeyTable;		/* virtualkeyArray hashed by virtual
					 * keycode value. */
static Tcl_HashTable unichar2xvirtual;	/* unichar to virtual with index */
static UniChar xvirtual2unichar[512];	/* virtual with index to unichar */

/*
 * Flags.
static int latin1Table[LATIN1_MAX+1];	/* Reverse mapping table for
					 * controls, ASCII and Latin-1. */
 */

static BOOL initialized = NO;
static BOOL keyboardChanged = YES;
static int keyboardChanged = 1;

/*
 * Prototypes for static functions used in this file.
 */

static void	InitHashTables(void);
static void     UpdateKeymaps(void);
static int	KeyDataToUnicode(UniChar *uniChars, int maxChars,
			UInt16 keyaction, UInt32 virt, UInt32 modifiers,
static void	InitKeyMaps (void);
static void	InitLatin1Table(Display *display);
static int	XKeysymToMacKeycode(Display *display, KeySym keysym);
static int	KeycodeToUnicode(UniChar * uniChars, int maxChars,
			UInt16 keyaction, UInt32 keycode, UInt32 modifiers,
			UInt32 * deadKeyStatePtr);

#pragma mark TKApplication(TKKeyboard)

@implementation TKApplication(TKKeyboard)
- (void) keyboardChanged: (NSNotification *) notification
{
    (void)notification;
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    keyboardChanged = YES;
    keyboardChanged = 1;
    UpdateKeymaps();
}
@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * InitHashTables --
 * InitKeyMaps --
 *
 *	Creates hash tables used by some of the functions in this file.
 *
 *	FIXME: As keycodes are defined to be in the limited range 0-127, it
 *	would be easier and more efficient to use directly initialized plain
 *	arrays and drop this function.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates memory & creates some hash tables.
 *
 *----------------------------------------------------------------------
 */

static void
InitHashTables(void)
InitKeyMaps(void)
{
    Tcl_HashEntry *hPtr;
    const KeyInfo *kPtr;
    KeyInfo *kPtr;
    const KeysymInfo *ksPtr;
    int dummy, index;
    int dummy;

    Tcl_InitHashTable(&special2keysym, TCL_ONE_WORD_KEYS);
    Tcl_InitHashTable(&keysym2keycode, TCL_ONE_WORD_KEYS);
    for (kPtr = keyArray; kPtr->virt != 0; kPtr++) {
    Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
	MacKeycode macKC;
	macKC.v.o_s = 0;
	hPtr = Tcl_CreateHashEntry(&special2keysym, INT2PTR(kPtr->virt),
				   &dummy);
	Tcl_SetHashValue(hPtr, INT2PTR(kPtr->keysym));
	hPtr = Tcl_CreateHashEntry(&keysym2keycode, INT2PTR(kPtr->keysym),
				   &dummy);
	hPtr = Tcl_CreateHashEntry(&keycodeTable, INT2PTR(kPtr->keycode),
		&dummy);
	macKC.v.virt = kPtr->virt;
	macKC.v.keychar = kPtr->keychar;
	Tcl_SetHashValue(hPtr, INT2PTR(macKC.uint));

	Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
	/*
	 * The Carbon framework does not work for finding the unicode character
	 * of a special key.  But that does not depend on the keyboard layout,
	 * so we can record the information here.
	 */

	for (index = 3; index >= 0; index--) {
	    macKC.v.o_s = index;
	    xvirtual2unichar[macKC.x.xvirtual] = macKC.x.keychar;
	}
    }
    Tcl_InitHashTable(&keysym2unichar, TCL_ONE_WORD_KEYS);
    Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
    Tcl_InitHashTable(&unichar2keysym, TCL_ONE_WORD_KEYS);
    for (ksPtr = keysymTable; ksPtr->keysym != 0; ksPtr++) {
	hPtr = Tcl_CreateHashEntry(&keysym2unichar, INT2PTR(ksPtr->keysym),
				   &dummy);
	Tcl_SetHashValue(hPtr, INT2PTR(ksPtr->keycode));
	hPtr = Tcl_CreateHashEntry(&unichar2keysym, INT2PTR(ksPtr->keycode),
				   &dummy);
	Tcl_SetHashValue(hPtr, INT2PTR(ksPtr->keysym));
    for (kPtr = virtualkeyArray; kPtr->keycode != 0; kPtr++) {
	hPtr = Tcl_CreateHashEntry(&vkeyTable, INT2PTR(kPtr->keycode),
		&dummy);
	Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
    UpdateKeymaps();
    initialized = YES;
    initialized = 1;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateKeymaps --
 * InitLatin1Table --
 *
 *	Called when the keyboard changes to update the hash tables that provide
 *      maps between unicode characters and virtual keycodes with indexes.  In
 *      order for the map from characters to virtual keycodes to be
 *      well-defined we have to ignore virtual keycodes for keypad keys, since
 *	Creates a simple table to be used for mapping from keysyms to keycodes.
 *      each keypad key has the same character as the corresponding key on the
 *      main keyboard.
 *	Always needs to be called before using latin1Table, because the
 *	keyboard layout may have changed, and than the table must be
 *	re-computed.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Initializes, if necessary, and updates the unichar2xvirtual hash table
 *      and the xvirtual2unichar array.
 *	Sets the global latin1Table.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateKeymaps()
InitLatin1Table(
    Display *display)
{
    static Bool keymapInitialized = false;
    Tcl_HashEntry *hPtr;
    int virt, index, dummy;
    int keycode;
    KeySym keysym;
    int state;
    int modifiers;

    if (!keymapInitialized) {
	Tcl_InitHashTable(&unichar2xvirtual, TCL_ONE_WORD_KEYS);
	keymapInitialized = true;
    } else {
	Tcl_DeleteHashTable(&unichar2xvirtual);
    memset(latin1Table, 0, sizeof(latin1Table));
	Tcl_InitHashTable(&unichar2xvirtual, TCL_ONE_WORD_KEYS);
    }

    /*
     * In the common X11 implementations, a keymap has four columns
     * "plain", "Shift", "Mode_switch" and "Mode_switch + Shift". We don't
     * use "Mode_switch", but we use "Option" instead. (This is similar to
     * This loop goes backwards so that a lookup by keychar will provide the
     * minimal modifier mask.  Simpler combinations will overwrite more complex
     * Apple's X11 implementation, where "Mode_switch" is used as an alias
     * for "Option".)
     *
     * So here we go through all 4 columns of the keymap and find all
     * Latin-1 compatible keycodes. We go through the columns back-to-front
     * from the more exotic columns to the more simple, so that simple
     * keycode-modifier combinations are preferred in the resulting table.
     * ones when constructing the table.
     */

    for (index = 3; index >= 0; index--) {
        for (virt = 0; virt < 128; virt++) {
	    MacKeycode macKC;
	    macKC.v = (keycode_v) {.virt = virt, .o_s = index, .keychar = 0};
	    int modifiers = INDEX2CARBON(index);
	    UniChar keychar = 0;

    for (state = 3; state >= 0; state--) {
	modifiers = 0;
	if (state & 1) {
	    KeyDataToUnicode(&keychar, 1, kUCKeyActionDown, virt,
				      modifiers, NULL);
	    modifiers |= shiftKey;
	    if (keychar == 0x10) {

	}
		/*
		 * This is a special key, handled in InitHashTables.
		 */

	if (state & 2) {
	    modifiers |= optionKey;
	}
		continue;
	    }
	    macKC.v.keychar = keychar;
	    if (! ON_KEYPAD(virt)) {

	for (keycode = 0; keycode <= MAC_KEYCODE_MAX; keycode++) {
	    keysym = XKeycodeToKeysym(display,keycode<<16,state);
	    if (keysym <= LATIN1_MAX) {
		hPtr = Tcl_CreateHashEntry(&unichar2xvirtual,
					   INT2PTR(macKC.x.keychar), &dummy);
		latin1Table[keysym] = keycode | modifiers;
		Tcl_SetHashValue(hPtr, INT2PTR(macKC.x.xvirtual));
            }
	    }
	    xvirtual2unichar[macKC.x.xvirtual] = macKC.x.keychar;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * KeyDataToUnicode --
 * KeycodeToUnicode --
 *
 *	Given MacOS key event data this function generates the keychar.  It
 *	does this by using OS resources from the Carbon framework.  Note that
 *	Given MacOS key event data this function generates the Unicode
 *	characters. It does this using OS resources and APIs.
 *      the Carbon functions used here are not aware of the keychars in the
 *      private-use range which macOS now uses for special keys.  For those
 *      keys this function returns 0x10 (ASCII dle).
 *
 *	The parameter deadKeyStatePtr can be NULL, if no deadkey handling is
 *	needed (which is always the case here).
 *	needed.
 *
 *	This function is called in XKeycodeToKeysym and UpdateKeymaps.
 *	This function is called from XKeycodeToKeysym() in tkMacOSKeyboard.c.
 *
 * Results:
 *	The number of characters generated if any, 0 if we are waiting for
 *	another byte of a dead-key sequence.
 *	another byte of a dead-key sequence. Fills in the uniChars array with a
 *	Unicode string.
 *
 * Side Effects:
 *	 Fills in the uniChars array with a Unicode string.
 *	None
 *
 *----------------------------------------------------------------------
 */


static int
KeyDataToUnicode(
KeycodeToUnicode(
    UniChar *uniChars,
    int maxChars,
    UInt16 keyaction,
    UInt32 virt,
    UInt32 keycode,
    UInt32 modifiers,
    UInt32 *deadKeyStatePtr)
{
    static const void *layoutData = NULL;
    static const void *uchr = NULL;
    static UInt32 keyboardType = 0;
    UniCharCount actuallength = 0;

    if (keyboardChanged) {
	TISInputSourceRef currentKeyboardLayout =
		TISCopyCurrentKeyboardLayoutInputSource();

	if (currentKeyboardLayout) {
	    CFDataRef keyLayoutData = (CFDataRef) TISGetInputSourceProperty(
		    currentKeyboardLayout, kTISPropertyUnicodeKeyLayoutData);

	    if (keyLayoutData) {
		layoutData = CFDataGetBytePtr(keyLayoutData);
		uchr = CFDataGetBytePtr(keyLayoutData);
		keyboardType = LMGetKbdType();
	    }
	    CFRelease(currentKeyboardLayout);
	}
	keyboardChanged = 0;
    }
    if (layoutData) {
    if (uchr) {
	OptionBits options = 0;
	UInt32 dummyState;
	OSStatus err;

	virt &= 0xFF;
	keycode &= 0xFF;
	modifiers = (modifiers >> 8) & 0xFF;

	if (!deadKeyStatePtr) {
	    options = kUCKeyTranslateNoDeadKeysMask;
	    dummyState = 0;
	    deadKeyStatePtr = &dummyState;
	}

	err = ChkErr(UCKeyTranslate, (const UCKeyboardLayout *)layoutData, virt, keyaction, modifiers,
	err = ChkErr(UCKeyTranslate, uchr, keycode, keyaction, modifiers,
		keyboardType, options, deadKeyStatePtr, maxChars,
		&actuallength, uniChars);
	if (!actuallength && *deadKeyStatePtr) {

	if (!actuallength && *deadKeyStatePtr) {
	    /*
	     * We are waiting for another key.
	     * More data later
	     */

	    return 0;
	}
	*deadKeyStatePtr = 0;
	if (err != noErr) {
	    actuallength = 0;
	}
    }
    return actuallength;
}

/*
 *----------------------------------------------------------------------
 *
 * XKeycodeToKeysym --
 *
 *	This is a stub function which translates from the keycode used in an
 *      XEvent to a numerical keysym.  On macOS, the display parameter is
 *	Translate from a system-dependent keycode to a system-independent
 *	keysym.
 *      ignored and only the the virtual keycode stored in the .virtual bitfield
 *      of a MacKeycode.v.
 *
 * Results:
 *      Returns the corresponding numerical keysym, or NoSymbol if the keysym
 *	Returns the translated keysym, or NoSymbol on failure.
 *      cannot be found.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

KeySym
XkbKeycodeToKeysym(
    TCL_UNUSED(Display *),
    unsigned int keycode,
XKeycodeToKeysym(
    Display* display,
    KeyCode keycode,
    TCL_UNUSED(int),
    int index)
{
    Tcl_HashEntry *hPtr;
    MacKeycode macKC;
    register Tcl_HashEntry *hPtr;
    int newKeycode;
    int modifiers, result;
    UniChar keychar = 0;
    UniChar newChar;

    (void) display; /*unused*/

    if (!initialized) {
	InitHashTables();
	InitKeyMaps();
    }
    macKC.uint = keycode;
    macKC.v.o_s = index;

    /*
     * First check if the virtual keycode corresponds to a special key, such as
     * an Fn function key or Tab, Backspace, Home, End, etc.
     * When determining what keysym to produce we first check to see if the key
     * is a function key. We then check to see if the character is another
     * non-printing key. Finally, we return the key syms for all ASCII and
     * Latin-1 chars.
     */

    newKeycode = keycode >> 16;

    if ((keycode & 0xFFFF) >= 0xF700) { /* NSEvent.h function key unicodes */
    hPtr = Tcl_FindHashEntry(&special2keysym, INT2PTR(macKC.v.virt));
	hPtr = Tcl_FindHashEntry(&vkeyTable, INT2PTR(newKeycode));
	if (hPtr != NULL) {
	    return (KeySym) Tcl_GetHashValue(hPtr);
	}
    }
    hPtr = Tcl_FindHashEntry(&keycodeTable, INT2PTR(newKeycode));
    if (hPtr != NULL) {
	return (KeySym) Tcl_GetHashValue(hPtr);
    }

    /*
     * If the virtual value in this keycode does not correspond to an actual
     * key in the current keyboard layout, try using its keychar to look up a
     * Add in the Mac modifier flags for shift and option.
     * keysym.
     */

    if (macKC.v.virt > 127) {
    if (index & 1) {
	hPtr = Tcl_FindHashEntry(&unichar2keysym, INT2PTR(macKC.v.keychar));
	if (hPtr != NULL) {
	    return (KeySym) Tcl_GetHashValue(hPtr);
	}
    }
	newKeycode |= shiftKey;
    }
    if (index & 2) {
	newKeycode |= optionKey;
    }

    newChar = 0;
    KeycodeToUnicode(&newChar, 1, kUCKeyActionDown, newKeycode & 0x00FF,
	    newKeycode & 0xFF00, NULL);

    /*
     * If the virtual keycode does belong to a key, use the virtual and the
     * Option-Shift from index to look up a keychar by using the Carbon
     * Framework; then translate the keychar to a keysym using the
     * unicode2keysym hash table.
     * X11 keysyms are identical to Unicode for ASCII and Latin-1. Give up for
     * other characters for now.
     */

    modifiers = INDEX2CARBON(macKC.v.o_s);
    result = KeyDataToUnicode(&keychar, 1, kUCKeyActionDown, macKC.v.virt,
			      modifiers, NULL);
    if (result) {
    if ((newChar >= XK_space) && (newChar <= LATIN1_MAX)) {
	hPtr = Tcl_FindHashEntry(&unichar2keysym, INT2PTR(keychar));
	if (hPtr != NULL) {
	    return (KeySym) Tcl_GetHashValue(hPtr);
	}
    }
	return newChar;
    }

    return NoSymbol;
}

KeySym
XKeycodeToKeysym(
    TCL_UNUSED(Display *),
    unsigned int keycode,
    int index)
{
    return XkbKeycodeToKeysym(NULL, keycode, 0, index);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetString --
 *
 *	This is a stub function which retrieves the string stored in the
 *	Retrieve the string equivalent for the given keyboard event.
 *      transchars field of an XEvent and converts it to a Tcl_DString.
 *
 * Results:
 *	Returns a pointer to the string value of the DString.
 *	Returns the UTF string.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

const char *
TkpGetString(
    TCL_UNUSED(TkWindow *),	/* Window where event occurred: Needed to get
    TkWindow *winPtr,		/* Window where event occurred: Needed to get
				 * input context. */
    XEvent *eventPtr,		/* X keyboard event. */
    Tcl_DString *dsPtr)		/* Uninitialized or empty string to hold
				 * result. */
{
    MacKeycode macKC;
    char utfChars[8];
    int length = 0;

    (void) winPtr; /*unused*/
    macKC.uint = eventPtr->xkey.keycode;
    if (IS_PRINTABLE(macKC.v.keychar)) {
	length = Tcl_UniCharToUtf(macKC.v.keychar, utfChars);
    }
    utfChars[length] = 0;

    Tcl_DStringInit(dsPtr);
    return Tcl_DStringAppend(dsPtr, utfChars, length);
    return Tcl_DStringAppend(dsPtr, eventPtr->xkey.trans_chars, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * XGetModifierMapping --
 *
 *	X11 stub function to get the keycodes used as modifiers.  This
 *	Fetch the current keycodes used as modifiers.
 *      is never called by the macOS port.
 *
 * Results:
 *	Returns a newly allocated modifier map.
 *	Returns a new modifier map.
 *
 * Side effects:
 *	Allocates a new modifier map data structure.
 *
 *----------------------------------------------------------------------
 */

XModifierKeymap *
XGetModifierMapping(
    TCL_UNUSED(Display *))
    Display *display)
{
    XModifierKeymap *modmap;

    (void) display; /*unused*/

    /*
     * MacOSX doesn't use the key codes for the modifiers for anything, and we
     * don't generate them either. So there is no modifier map.
     */

    modmap = (XModifierKeymap *)ckalloc(sizeof(XModifierKeymap));
    modmap = ckalloc(sizeof(XModifierKeymap));
    modmap->max_keypermod = 0;
    modmap->modifiermap = NULL;
    return modmap;
}

/*
 *----------------------------------------------------------------------
 *
 * XFreeModifiermap --
 *
 *	Deallocates a modifier map that was created by XGetModifierMapping.
 *	Deallocate a modifier map that was created by XGetModifierMapping.
 *      This is also never called by the macOS port.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frees the datastructure referenced by modmap.
 *
567
568
569
570
571
572
573
574
575
576
577




578
579
580
581
582
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597

598
599
600
601
602
603
604
605

606












607
608
609
610






















































611
612
613
614
615



616
617
618
619
620
621
622
623
624
625

626
627
628
629

630
631
632


633
634

635


636
637
638
639

640
641
642

643
644
645

646
647

648
649
650
651

652
653
654
655
656

657
658
659
660
661
662
663
664
665
666

667
668

669
670
671
672
673
674
675
676
677




678
679
680




681
682
683

684
685
686
687
688
689
690

691
692
693

694
695
696
697
698
699
700
701


702
703
704
705
706
707
708
709
710
711
712
713

714
715

716
717



718
719
720


721
722
723
724
725
726
727
728
729
730
731




732
733
734
735
736
737










738
739
740
741
742
743
744
745
746
747
748


749
750
751
752
753
754
755
756


757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780


781
782
783
784
785




786
787

788
789

790
791

792
793

794
795

796





797

798
799

800
801

802

803
804





805
806
807
808






809
810
811
812
813


814
815
816
817
818










819

820






821
822

823
824
825

826
827
828
829
830



831
832
833
834
835
836













837
838
839
840
841
842
843
844
845
846
847



848
849
850
851
852
853
854
855
856
857
858



859
860
861
862
863
864

865
866
867
868
869
870
871
872
873
874
875
876
877
878


879
880
881
882
883
884
885
886
887
888
889



890
891
892
893




894
895



896
897

898
899
900
901
902





903
904
905
906
907
908

909
910
911
912
913



914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
492
493
494
495
496
497
498




499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

515
516
517
518
519
520
521

522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543




544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599



600
601
602
603
604
605
606
607
608
609
610
611

612
613
614


615



616
617

618
619

620
621
622
623


624



625



626


627




628





629










630


631
632
633
634
635
636
637
638


639
640
641
642
643
644

645
646
647
648
649
650

651




652
653
654
655
656
657

658
659
660
661
662
663
664


665
666

667
668









669
670
671
672


673
674
675
676


677
678











679
680
681
682






683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700



701
702
703
704
705
706
707
708


709
710
711
712
713
714
715
716
717
718
719
720
721


722
723
724
725
726
727
728
729
730
731

732
733
734
735



736
737
738
739


740
741

742
743

744
745

746
747

748
749
750
751
752
753
754

755
756

757
758

759
760
761


762
763
764
765
766

767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782
783



784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803

804
805
806

807
808
809



810
811
812
813
814




815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835



836
837
838
839
840
841
842
843
844
845
846
847


848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
863
864
865
866
867
868


869
870


871
872
873
874



875
876
877
878
879




880
881
882
883
884
885
886
887
888
889
890
891
892
893



894
895
896
897
898
899
900
901
902
903

904





905
906
907














































908
909
910
911
912
913
914
915







-
-
-
-
+
+
+
+












-
+






-
+







-
+

+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+









-
+


-
-
+
-
-
-
+
+
-

+
-
+
+


-
-
+
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+







-
-
+
+
+
+


-
+
+
+
+


-
+
-
-
-
-



+


-
+






-
-
+
+
-


-
-
-
-
-
-
-
-
-
+


+
-
-
+
+
+

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+








-
-
-
+
+






-
-
+
+











-
-










-
+
+


-
-
-
+
+
+
+
-
-
+

-
+

-
+

-
+

-
+

+
+
+
+
+
-
+

-
+

-
+

+
-
-
+
+
+
+
+
-



+
+
+
+
+
+




-
+
+


-
-
-
+
+
+
+
+
+
+
+
+
+

+

+
+
+
+
+
+

-
+


-
+


-
-
-
+
+
+


-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
-
+
+
+









-
-
+
+
+





-
+












-
-
+
+
-
-




-
-
-


+
+
+
-
-
-
-
+
+
+
+


+
+
+


+


-
-
-
+
+
+
+
+





-
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








}

/*
 *----------------------------------------------------------------------
 *
 * XKeysymToString, XStringToKeysym --
 *
 *	These X11 stub functions map keysyms to strings & strings to keysyms.
 *      A platform can do its own conversion by defining these and undefining
 *      REDO_KEYSYM_LOOKUP.  The macOS port defines REDO_KEYSYM_LOOKUP so these
 *      are never called and Tk does the conversion for us.
 *	These X window functions map keysyms to strings & strings to keysyms.
 *	However, Tk already does this for the most common keysyms. Therefore,
 *	these functions only need to support keysyms that will be specific to
 *	the Macintosh. Currently, there are none.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

char *
XKeysymToString(
    TCL_UNUSED(KeySym))
    KeySym keysym)
{
    return NULL;
}

KeySym
XStringToKeysym(
    TCL_UNUSED(const char *))
    const char* string)
{
    return NoSymbol;
}

/*
 *----------------------------------------------------------------------
 *
 * XKeysymToKeycode --
 * XKeysymToMacKeycode --
 *
 *	An internal function like XKeysymToKeycode but only generating the Mac
 *	specific keycode plus the modifiers Shift and Option.
 *
 * Results:
 *	A Mac keycode with the actual keycode in the low byte and Mac-style
 *	modifier bits in the high byte.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
 *	This is a stub function which converts a numerical keysym to the
 *      platform-specific keycode used in a KeyPress or KeyRelease XEvent.
 *      For macOS the keycode is an unsigned int with bitfields described
 *      in the definition of the MacKeycode type.

static int
XKeysymToMacKeycode(
    Display *display,
    KeySym keysym)
{
    KeyInfo *kPtr;

    if (keysym <= LATIN1_MAX) {
	/*
	 * Handle keysyms in the Latin-1 range where keysym and Unicode
	 * character code point are the same.
	 */

	if (keyboardChanged) {
	    InitLatin1Table(display);
	    keyboardChanged = 0;
	}
	return latin1Table[keysym];
    }

    /*
     * Handle special keys from our exception tables. Don't mind if this is
     * slow, neither the test suite nor [event generate] need to be optimized
     * (we hope).
     */

    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
	if (kPtr->keysym == keysym) {
	    return kPtr->keycode;
	}
    }
    for (kPtr = virtualkeyArray; kPtr->keycode != 0; kPtr++) {
	if (kPtr->keysym == keysym) {
	    return kPtr->keycode;
	}
    }

    /*
     * For other keysyms (not Latin-1 and not special keys), we'd need a
     * generic keysym-to-unicode table. We don't have that, so we give up here.
     */

    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * XKeysymToKeycode --
 *
 *	The function XKeysymToKeycode takes an X11 keysym and converts it into
 *	a Mac keycode. It is in the stubs table for compatibility but not used
 *	anywhere in the core.
 *
 * Results:
 *
 *      A macOS KeyCode. See the description of keycodes at the top of this
 *	file and the definition of the MacKeycode type in tkMacOSXPrivate.h.
 *	A 32 bit keycode with the the mac keycode (without modifiers) in the
 *	higher 16 bits of the keycode and the ASCII or Latin-1 code in the
 *	lower 8 bits of the keycode.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

KeyCode
XKeysymToKeycode(
    TCL_UNUSED(Display *),
    Display* display,
    KeySym keysym)
{
    Tcl_HashEntry *hPtr;
    MacKeycode macKC;
    int macKeycode = XKeysymToMacKeycode(display, keysym);
    if (!initialized) {
	InitHashTables();
    }
    KeyCode result;


    /*
     * See also TkpSetKeycodeAndState. The 0x0010 magic is used in
     * First check for a special key.
     * XKeycodeToKeysym. For special keys like XK_Return the lower 8 bits of
     * the keysym are usually a related ASCII control code.
     */

    hPtr = Tcl_FindHashEntry(&keysym2keycode, INT2PTR(keysym));
    if (hPtr != NULL) {
    if ((keysym >= XK_F1) && (keysym <= XK_F35)) {
	return (KeyCode) PTR2INT(Tcl_GetHashValue(hPtr));
    }

	result = 0x0010;
    /*
     * Initialize the keycode as if the keysym cannot be converted to anything
     * else.
    } else {
     */

	result = 0x00FF & keysym;
    macKC.v.virt = NO_VIRTUAL;
    macKC.v.o_s = 0;
    macKC.v.keychar = 0;

    }
    /*
     * If the keysym is recognized fill in the keychar.  Also fill in the
     * xvirtual field if the key exists on the current keyboard.
     */

    result |= (macKeycode & MAC_KEYCODE_MASK) << 16;
    hPtr = (Tcl_HashEntry *) Tcl_FindHashEntry(&keysym2unichar,
					       INT2PTR(keysym));
    if (hPtr != NULL) {
	unsigned long data = (unsigned long) Tcl_GetHashValue(hPtr);
	macKC.x.keychar = (unsigned int) data;
	hPtr = Tcl_FindHashEntry(&unichar2xvirtual, INT2PTR(macKC.x.keychar));
	if (hPtr != NULL) {
	    data = (unsigned long) Tcl_GetHashValue(hPtr);
	    macKC.x.xvirtual = (unsigned int) data;
	}

    }
    return (KeyCode) macKC.uint;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpSetKeycodeAndState --
 *
 *	This function accepts a keysym and an XEvent and sets some fields of
 *	the XEvent.  It is used by the event generate command.
 *	The function TkpSetKeycodeAndState takes a keysym and fills in the
 *	appropriate members of an XEvent. It is similar to XKeysymToKeycode,
 *	but it also sets the modifier mask in the XEvent. It is used by [event
 *	generate] and it is in the stubs table.
 *
 * Results:
 *      None
 *	Fills an XEvent, sets the member xkey.keycode with a keycode
 *	formatted the same as XKeysymToKeycode and the member xkey.state with
 *	the modifiers implied by the keysym. Also fills in xkey.trans_chars,
 *	so that the actual characters can be retrieved later.
 *
 * Side effects:
 *
 *	None.
 *	Modifies the XEvent. Sets the xkey.keycode to a keycode value formatted
 *	by XKeysymToKeycode and updates the shift and option flags in
 *	xkey.state if either of those modifiers is required to generate the
 *	keysym.
 *
 *----------------------------------------------------------------------
 */

void
TkpSetKeycodeAndState(
    TCL_UNUSED(Tk_Window),
    Tk_Window tkwin,
    KeySym keysym,
    XEvent *eventPtr)
{
    if (keysym == NoSymbol) {
	eventPtr->xkey.keycode = 0;
    } else {
	int eventIndex = STATE2INDEX(eventPtr->xkey.state);
	MacKeycode macKC;
	Display *display = Tk_Display(tkwin);
	int macKeycode = XKeysymToMacKeycode(display, keysym);
	macKC.uint = XKeysymToKeycode(NULL, keysym);

	/*
	 * We have a virtual keycode and a minimal choice for Shift and Option
	 * modifiers which generates the keychar that corresponds to the
	 * specified keysym.  But we might not have the correct keychar yet,
	 * because the xEvent may have specified modifiers beyond our minimal
	 * set.  For example, the events described by <Oslash>, <Shift-oslash>,
	 * <Shift-Option-O> and <Shift-Option-o> should all produce the same
	 * uppercase Danish O.  So we may need to add the extra modifiers and
	 * do another lookup for the keychar.  We don't want to do this for
	 * special keys, however.
	 * See also XKeysymToKeycode.
	 */

	if ((keysym >= XK_F1) && (keysym <= XK_F35)) {
	if (macKC.v.o_s != eventIndex) {
	    macKC.v.o_s |= eventIndex;
	    eventPtr->xkey.keycode = 0x0010;
	} else {
	    eventPtr->xkey.keycode = 0x00FF & keysym;
	}
	if (macKC.v.keychar < 0xF700) {
	    UniChar keychar = macKC.v.keychar;
	eventPtr->xkey.keycode |= (macKeycode & MAC_KEYCODE_MASK) << 16;

	    NSString *str, *lower, *upper;
	    if (macKC.v.virt != NO_VIRTUAL) {
		macKC.x.keychar = xvirtual2unichar[macKC.x.xvirtual];
	    } else {
		str = [[NSString alloc] initWithCharacters:&keychar length:1];
		lower = [str lowercaseString];
		upper = [str uppercaseString];
		if (![str isEqual: lower]) {
		    macKC.v.o_s |= INDEX_SHIFT;
		}
		if (macKC.v.o_s & INDEX_SHIFT) {
	if (shiftKey & macKeycode) {
	    eventPtr->xkey.state |= ShiftMask;
	}
	if (optionKey & macKeycode) {
		    macKC.v.keychar = [upper characterAtIndex:0];
		}
	    }
	}
	eventPtr->xkey.keycode = macKC.uint;
	eventPtr->xkey.state |= INDEX2STATE(macKC.v.o_s);
	    eventPtr->xkey.state |= OPTION_MASK;
	}

	if (keysym <= LATIN1_MAX) {
	    int done = Tcl_UniCharToUtf(keysym, eventPtr->xkey.trans_chars);

	    eventPtr->xkey.trans_chars[done] = 0;
	} else {
	    eventPtr->xkey.trans_chars[0] = 0;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetKeySym --
 *
 *	This is a stub function called in tkBind.c.  Given a KeyPress or
 *	KeyRelease XEvent, it maps the keycode in the event to a numerical
 *      keysym.
 *	Given an X KeyPress or KeyRelease event, map the keycode in the event
 *	into a keysym.
 *
 * Results:
 *	The return value is the keysym corresponding to eventPtr, or NoSymbol
 *	if no matching keysym could be found.
 *
 * Side effects:
 *	In the first call for a given display, calls TkpInitKeymapInfo.
 *
 *	In the first call for a given display, keycode-to-keysym maps get
 *	loaded.
 *
 *----------------------------------------------------------------------
 */

KeySym
TkpGetKeySym(
    TkDisplay *dispPtr,		/* Display in which to map keycode. */
    XEvent *eventPtr)		/* Description of X event. */
{
    KeySym sym;
    int index;
    MacKeycode macKC;
    macKC.uint = eventPtr->xkey.keycode;

    /*
     * Refresh the mapping information if it's stale.
     */

    if (dispPtr->bindInfoStale) {
	TkpInitKeymapInfo(dispPtr);
    }

    /*
     * Modifier key events have a special mac keycode (see tkProcessKeyEvent).
     * Handle pure modifier keys specially. We use -1 as a signal for
     * this.
     */

    if (macKC.v.keychar == MOD_KEYCHAR) {
	switch (macKC.v.virt) {
	case 54:
    if (eventPtr->xany.send_event == -1) {

	int modifier = eventPtr->xkey.keycode & NSDeviceIndependentModifierFlagsMask;

	    return XK_Meta_R;
	case 55:
	if (modifier == NSCommandKeyMask) {
	    return XK_Meta_L;
	case 56:
	} else if (modifier == NSShiftKeyMask) {
	    return XK_Shift_L;
	case 57:
	} else if (modifier == NSAlphaShiftKeyMask) {
	    return XK_Caps_Lock;
	case 58:
	} else if (modifier == NSAlternateKeyMask) {
	    return XK_Alt_L;
	case 59:
	} else if (modifier == NSControlKeyMask) {
	    return XK_Control_L;
	} else if (modifier == NSNumericPadKeyMask) {
	    return XK_Num_Lock;
	} else if (modifier == NSFunctionKeyMask) {
	    return XK_Super_L;
/*
	case 60:
	} else if (modifier == rightShiftKey) {
	    return XK_Shift_R;
	case 61:
	} else if (modifier == rightOptionKey) {
	    return XK_Alt_R;
	case 62:
	} else if (modifier == rightControlKey) {
	    return XK_Control_R;
*/
	case 63:
	    return XK_Super_L;
	} else {
	    /*
	     * If we get here, we probably need to implement something new.
	     */

	default:
	    return NoSymbol;
	}
    }

    /* If nbytes has been set, it's not a function key, but a regular key that
       has been translated in tkMacOSXKeyEvent.c; just use that. */
    if (eventPtr->xkey.nbytes) {
      return eventPtr->xkey.keycode & 0xFFFF;
    }

    /*
     * Figure out which of the four slots in the keymap vector to use for this
     * key. Refer to Xlib documentation for more info on how this computation
     * works.
     * works. (Note: We use "Option" in keymap columns 2 and 3 where other
     * implementations have "Mode_switch".)
     */

    index = STATE2INDEX(eventPtr->xkey.state);
    if (eventPtr->xkey.state & LockMask) {
	index |= INDEX_SHIFT;
    index = 0;

    /*
     * We want Option key combinations to use their base chars as keysyms, so
     * we ignore the option modifier here.
     */

#if 0
    if (eventPtr->xkey.state & OPTION_MASK) {
	index |= 2;
    }
#endif

    if ((eventPtr->xkey.state & ShiftMask)
	    || (/* (dispPtr->lockUsage != LU_IGNORE)
	    && */ (eventPtr->xkey.state & LockMask))) {
	index |= 1;
    }

    /*
     * First do the straightforward lookup.
     * First try of the actual translation.
     */

    sym = XkbKeycodeToKeysym(dispPtr->display, macKC.uint, 0, index);
    sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, index);

    /*
     * Special handling: If the key was shifted because of Lock, which is only
     * caps lock on macOS, not shift lock, and if the shifted keysym isn't
     * upper-case alphabetic, then switch back to the unshifted keysym.
     * Special handling: If the key was shifted because of Lock, but lock is
     * only caps lock, not shift lock, and the shifted keysym isn't upper-case
     * alphabetic, then switch back to the unshifted keysym.
     */

    if ((index & INDEX_SHIFT) && !(eventPtr->xkey.state & ShiftMask)) {
	if ((sym == NoSymbol) || !Tcl_UniCharIsUpper(sym)) {
	    sym = XkbKeycodeToKeysym(dispPtr->display, macKC.uint, 0,
				   index & ~INDEX_SHIFT);
    if ((index & 1) && !(eventPtr->xkey.state & ShiftMask)
	    /*&& (dispPtr->lockUsage == LU_CAPS)*/ ) {
	/*
	 * FIXME: Keysyms are only identical to Unicode for ASCII and Latin-1,
	 * so we can't use Tcl_UniCharIsUpper() for keysyms outside that range.
	 * This may be a serious problem here.
	 */

	if ((sym == NoSymbol) || (sym > LATIN1_MAX)
		|| !Tcl_UniCharIsUpper(sym)) {
	    index &= ~1;
	    sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
		    index);
	}
    }

    /*
     * Another bit of special handling: If this is a shifted key and there is
     * no keysym defined, then use the keysym for the unshifted key.
     */

    if ((index & INDEX_SHIFT) && (sym == NoSymbol)) {
	sym = XkbKeycodeToKeysym(dispPtr->display, macKC.uint, 0,
			       index & ~INDEX_SHIFT);
    if ((index & 1) && (sym == NoSymbol)) {
	sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
		index & ~1);
    }
    return sym;
}

/*
 *--------------------------------------------------------------
 *
 * TkpInitKeymapInfo --
 *
 *	This procedure initializes fields in the display that pertain
 *      to modifier keys.
 *	This procedure is invoked to scan keymap information to recompute stuff
 *	that's important for binding, such as the modifier key (if any) that
 *	corresponds to the "Mode_switch" keysym.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Modifier key information in dispPtr is initialized.
 *	Keymap-related information in dispPtr is updated.
 *
 *--------------------------------------------------------------
 */

void
TkpInitKeymapInfo(
    TkDisplay *dispPtr)		/* Display for which to recompute keymap
				 * information. */
{
    dispPtr->bindInfoStale = 0;

    /*
     * On macOS the caps lock key is always interpreted to mean that alphabetic
     * keys become uppercase but other keys do not get shifted.  (X11 allows
     * Behaviours that are variable on X11 are defined constant on MacOSX.
     * lockUsage is only used above in TkpGetKeySym(), nowhere else currently.
     * a configuration option which makes the caps lock equivalent to holding
     * down the shift key.)
     * There is no offical "Mode_switch" key.
     */

    dispPtr->lockUsage = LU_CAPS;

    /* This field is no longer used by tkBind.c */

    dispPtr->modeModMask = 0;

#if 0
    /*
     * With this, <Alt> and <Meta> become synonyms for <Command> and <Option>
    /* The Alt and Meta keys are interchanged on Macintosh keyboards compared
     * to PC keyboards.  These fields could be set to make the Alt key on a PC
     * keyboard behave likd an Alt key. That would also require interchanging
     * Mod1Mask and Mod2Mask in tkMacOSXKeyEvent.c.
     * in bindings like they are (and always have been) in the keysyms that
     * are reported by KeyPress events. But the init scripts like text.tcl
     * have some disabling bindings for <Meta>, so we don't want this without
     * some changes in those scripts. See also bug #700311.
     */

    dispPtr->altModMask = OPTION_MASK;
    dispPtr->metaModMask = COMMAND_MASK;
#else
    dispPtr->altModMask = 0;
    dispPtr->metaModMask = 0;
#endif

    /*
     * The modKeyCodes table lists the keycodes that appear in KeyPress or
     * KeyRelease XEvents for modifier keys.  In tkBind.c this table is
     * searched to determine whether an XEvent corresponds to a modifier key.
     * MacOSX doesn't use the keycodes for the modifiers for anything, and we
     * don't generate them either (the keycodes actually given in the simulated
     * modifier events are bogus). So there is no modifier map. If we ever want
     * to simulate real modifier keycodes, the list will be constant in the
     * Carbon implementation.
     */

    if (dispPtr->modKeyCodes != NULL) {
	ckfree(dispPtr->modKeyCodes);
    }
    dispPtr->numModKeyCodes = NUM_MOD_KEYCODES;
    dispPtr->numModKeyCodes = 0;
    dispPtr->modKeyCodes = (KeyCode *)ckalloc(NUM_MOD_KEYCODES * sizeof(KeyCode));
    for (int i = 0; i < NUM_MOD_KEYCODES; i++) {
	dispPtr->modKeyCodes[i] = XKeysymToKeycode(NULL, modKeyArray[i]);
    }
}
    dispPtr->modKeyCodes = NULL;
}


/*
 *--------------------------------------------------------------
 *
 * TkMacOSXAddVirtual --
 *
 *	This procedure is an internal utility which accepts an unsigned int
 *      that has been partially filled as a MacKeycode, having the Option and
 *      Shift state set in the o_s field and the keychar field set but with the
 *      virtual keycode blank.  It looks up the virtual keycode for the keychar
 *      (possibly NO_VIRTUAL) and returns an unsigned int which is a complete
 *      MacKeycode with the looked up virtual keycode added.  This is used when
 *      creating XEvents for the unicode characters which are generated by the
 *      NSTextInputClient.
 *
 * Results:
 *      An unsigned int which is a complete MacKeycode, including a virtual
 *	keycode which matches the Option-Shift state and keychar.
 *
 * Side effects:
 *	None
 *
 *--------------------------------------------------------------
 */
unsigned
TkMacOSXAddVirtual(
    unsigned int keycode)
{
    MacKeycode macKC;
    Tcl_HashEntry *hPtr;
    macKC.uint = keycode;

    if (!initialized) {
	InitHashTables();
    }

    hPtr = (Tcl_HashEntry *) Tcl_FindHashEntry(&unichar2xvirtual,
					       INT2PTR(macKC.v.keychar));
    if (hPtr != NULL) {
	unsigned long data = (unsigned long) Tcl_GetHashValue(hPtr);
	macKC.x.xvirtual = (unsigned int) data;
    } else {
	macKC.v.virt = NO_VIRTUAL;
    }
    return macKC.uint;
}
/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXKeysyms.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308




























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXKeysyms.h --
 *
 *      Contains data used for processing key events, some of which was
 *      moved from tkMacOSXKeyboard.c.
 *
 * Copyright © 1990-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2020 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef TKMACOSXKEYSYMS_H
#define TKMACOSXKEYSYMS_H 1

/*
 * This table enumerates the keys on Mac keyboards which do not represent
 * letters.  This is static data -- these keys do not change when the keyboard
 * layout changes.  The unicode representation of a special key which is not a
 * modifier and does not have an ASCII code point lies in the reserved range
 * 0xF700 - 0xF8FF.
 *
 * The table includes every key listed in Apple's documentation of Function-Key
 * Unicodes which is not marked as "Not on most Macintosh keyboards", as well
 * as F20, which is reported to be usable in scripts even though it does not
 * appear on any Macintosh keyboard.
 */

typedef struct {
    int virt;	/* value of [NSEvent keyCode] */
    KeySym keysym;	/* X11 keysym */
    KeyCode keychar;	/* XEvent keycode & 0xFFFF */
} KeyInfo;

static const KeyInfo keyArray[] = {
    {36,	XK_Return,	NSNewlineCharacter},
    {48,	XK_Tab,		NSTabCharacter},
    {51,	XK_BackSpace,	NSDeleteCharacter},
    {52,	XK_Return,	NSNewlineCharacter},  /* Used on some Powerbooks */
    {53,	XK_Escape,	0x1B},
    {54,	XK_Meta_R,      MOD_KEYCHAR},
    {55,	XK_Meta_L,	MOD_KEYCHAR},
    {56,	XK_Shift_L,	MOD_KEYCHAR},
    {57,	XK_Caps_Lock,   MOD_KEYCHAR},
    {58,	XK_Alt_L,	MOD_KEYCHAR},
    {59,	XK_Control_L,	MOD_KEYCHAR},
    {60,	XK_Shift_R, 	MOD_KEYCHAR},
    {61,	XK_Alt_R,	MOD_KEYCHAR},
    {62,	XK_Control_R,	MOD_KEYCHAR},
    {63,	XK_Super_L,	MOD_KEYCHAR},
    {64,	XK_F17,		NSF17FunctionKey},
    {65,	XK_KP_Decimal,	'.'},
    {67,	XK_KP_Multiply, '*'},
    {69,	XK_KP_Add,	'+'},
    {71,	XK_Clear,       NSClearLineFunctionKey}, /* Numlock on PC */
    {75,	XK_KP_Divide,   '/'},
    {76,	XK_KP_Enter,	NSEnterCharacter},       /* Fn Return */
    {78,	XK_KP_Subtract, '-'},
    {79,	XK_F18,		NSF18FunctionKey},
    {80,	XK_F19,		NSF19FunctionKey},
    {81,	XK_KP_Equal,	'='},
    {82,	XK_KP_0,	'0'},
    {83,	XK_KP_1,	'1'},
    {84,	XK_KP_2,	'2'},
    {85,	XK_KP_3,	'3'},
    {86,	XK_KP_4,	'4'},
    {87,	XK_KP_5,	'5'},
    {88,	XK_KP_6,	'6'},
    {89,	XK_KP_7,	'7'},
    {90,	XK_F20,		NSF20FunctionKey}, /* For scripting only */
    {91,	XK_KP_8,	'8'},
    {92,	XK_KP_9,	'9'},
    {96,	XK_F5,		NSF5FunctionKey},
    {97,	XK_F6,		NSF6FunctionKey},
    {98,	XK_F7,		NSF7FunctionKey},
    {99,	XK_F3,		NSF3FunctionKey},
    {100,	XK_F8,		NSF8FunctionKey},
    {101,	XK_F9,		NSF9FunctionKey},
    {103,	XK_F11,		NSF11FunctionKey},
    {105,	XK_F13,		NSF13FunctionKey},
    {106,	XK_F16,		NSF16FunctionKey},
    {107,	XK_F14,		NSF14FunctionKey},
    {109,	XK_F10,		NSF10FunctionKey},
    {110,	XK_Menu,	UNKNOWN_KEYCHAR},
    {111,	XK_F12,		NSF12FunctionKey},
    {113,	XK_F15,		NSF15FunctionKey},
    {114,	XK_Help,	NSHelpFunctionKey},
    {115,	XK_Home,	NSHomeFunctionKey},     /* Fn Left */
    {116,	XK_Prior,	NSPageUpFunctionKey},   /* Fn Up */
    {117,	XK_Delete,	NSDeleteFunctionKey},   /* Fn Delete */
    {118,	XK_F4,		NSF4FunctionKey},
    {119,	XK_End,		NSEndFunctionKey},      /* Fn Right */
    {120,	XK_F2,		NSF2FunctionKey},
    {121,	XK_Next,	NSPageDownFunctionKey}, /* Fn Down */
    {122,	XK_F1,		NSF1FunctionKey},
    {123,	XK_Left,	NSLeftArrowFunctionKey},
    {124,	XK_Right,	NSRightArrowFunctionKey},
    {125,	XK_Down,	NSDownArrowFunctionKey},
    {126,	XK_Up,		NSUpArrowFunctionKey},
    {0, 0, 0}
};

/*
 * X11 keysyms for modifier keys, in order.  This list includes keys
 * which do not appear on Apple keyboards, such as Shift_Lock and
 * Super_R.  While most systems don't provide events for the "fn"
 * function key, Apple does.  We map it to Super_L when processing a
 * FlagsChanged NSEvent.
 */

#define NUM_MOD_KEYCODES 14
static const KeyCode modKeyArray[NUM_MOD_KEYCODES] = {
    XK_Shift_L,
    XK_Shift_R,
    XK_Control_L,
    XK_Control_R,
    XK_Caps_Lock,
    XK_Shift_Lock,
    XK_Meta_L,
    XK_Meta_R,
    XK_Alt_L,
    XK_Alt_R,
    XK_Super_L,
    XK_Super_R,
    XK_Hyper_L,
    XK_Hyper_R,
};

/*
 * This table pairs X11 Keysyms for alphanumeric characters with the
 * unicode code point for that letter.
 * The data comes from http://www.cl.cam.ac.uk/~mgk25/ucs/keysyms.txt
 */

typedef struct KeysymInfo {
    KeySym keysym;
    KeyCode keycode;
} KeysymInfo;

static const KeysymInfo keysymTable[] = {
    {0x0020, 0x0020}, /* space */
    {0x0021, 0x0021}, /* exclam */
    {0x0022, 0x0022}, /* quotedbl */
    {0x0023, 0x0023}, /* numbersign */
    {0x0024, 0x0024}, /* dollar */
    {0x0025, 0x0025}, /* percent */
    {0x0026, 0x0026}, /* ampersand */
    {0x0027, 0x0027}, /* apostrophe */
    {0x0028, 0x0028}, /* parenleft */
    {0x0029, 0x0029}, /* parenright */
    {0x002a, 0x002a}, /* asterisk */
    {0x002b, 0x002b}, /* plus */
    {0x002c, 0x002c}, /* comma */
    {0x002d, 0x002d}, /* minus */
    {0x002e, 0x002e}, /* period */
    {0x002f, 0x002f}, /* slash */
    {0x0030, 0x0030}, /* 0 */
    {0x0031, 0x0031}, /* 1 */
    {0x0032, 0x0032}, /* 2 */
    {0x0033, 0x0033}, /* 3 */
    {0x0034, 0x0034}, /* 4 */
    {0x0035, 0x0035}, /* 5 */
    {0x0036, 0x0036}, /* 6 */
    {0x0037, 0x0037}, /* 7 */
    {0x0038, 0x0038}, /* 8 */
    {0x0039, 0x0039}, /* 9 */
    {0x003a, 0x003a}, /* colon */
    {0x003b, 0x003b}, /* semicolon */
    {0x003c, 0x003c}, /* less */
    {0x003d, 0x003d}, /* equal */
    {0x003e, 0x003e}, /* greater */
    {0x003f, 0x003f}, /* question */
    {0x0040, 0x0040}, /* at */
    {0x0041, 0x0041}, /* A */
    {0x0042, 0x0042}, /* B */
    {0x0043, 0x0043}, /* C */
    {0x0044, 0x0044}, /* D */
    {0x0045, 0x0045}, /* E */
    {0x0046, 0x0046}, /* F */
    {0x0047, 0x0047}, /* G */
    {0x0048, 0x0048}, /* H */
    {0x0049, 0x0049}, /* I */
    {0x004a, 0x004a}, /* J */
    {0x004b, 0x004b}, /* K */
    {0x004c, 0x004c}, /* L */
    {0x004d, 0x004d}, /* M */
    {0x004e, 0x004e}, /* N */
    {0x004f, 0x004f}, /* O */
    {0x0050, 0x0050}, /* P */
    {0x0051, 0x0051}, /* Q */
    {0x0052, 0x0052}, /* R */
    {0x0053, 0x0053}, /* S */
    {0x0054, 0x0054}, /* T */
    {0x0055, 0x0055}, /* U */
    {0x0056, 0x0056}, /* V */
    {0x0057, 0x0057}, /* W */
    {0x0058, 0x0058}, /* X */
    {0x0059, 0x0059}, /* Y */
    {0x005a, 0x005a}, /* Z */
    {0x005b, 0x005b}, /* bracketleft */
    {0x005c, 0x005c}, /* backslash */
    {0x005d, 0x005d}, /* bracketright */
    {0x005e, 0x005e}, /* asciicircum */
    {0x005f, 0x005f}, /* underscore */
    {0x0060, 0x0060}, /* grave */
    {0x0061, 0x0061}, /* a */
    {0x0062, 0x0062}, /* b */
    {0x0063, 0x0063}, /* c */
    {0x0064, 0x0064}, /* d */
    {0x0065, 0x0065}, /* e */
    {0x0066, 0x0066}, /* f */
    {0x0067, 0x0067}, /* g */
    {0x0068, 0x0068}, /* h */
    {0x0069, 0x0069}, /* i */
    {0x006a, 0x006a}, /* j */
    {0x006b, 0x006b}, /* k */
    {0x006c, 0x006c}, /* l */
    {0x006d, 0x006d}, /* m */
    {0x006e, 0x006e}, /* n */
    {0x006f, 0x006f}, /* o */
    {0x0070, 0x0070}, /* p */
    {0x0071, 0x0071}, /* q */
    {0x0072, 0x0072}, /* r */
    {0x0073, 0x0073}, /* s */
    {0x0074, 0x0074}, /* t */
    {0x0075, 0x0075}, /* u */
    {0x0076, 0x0076}, /* v */
    {0x0077, 0x0077}, /* w */
    {0x0078, 0x0078}, /* x */
    {0x0079, 0x0079}, /* y */
    {0x007a, 0x007a}, /* z */
    {0x007b, 0x007b}, /* braceleft */
    {0x007c, 0x007c}, /* bar */
    {0x007d, 0x007d}, /* braceright */
    {0x007e, 0x007e}, /* asciitilde */
    {0x00a0, 0x00a0}, /* nobreakspace */
    {0x00a1, 0x00a1}, /* exclamdown */
    {0x00a2, 0x00a2}, /* cent */
    {0x00a3, 0x00a3}, /* sterling */
    {0x00a4, 0x00a4}, /* currency */
    {0x00a5, 0x00a5}, /* yen */
    {0x00a6, 0x00a6}, /* brokenbar */
    {0x00a7, 0x00a7}, /* section */
    {0x00a8, 0x00a8}, /* diaeresis */
    {0x00a9, 0x00a9}, /* copyright */
    {0x00aa, 0x00aa}, /* ordfeminine */
    {0x00ab, 0x00ab}, /* guillemotleft */
    {0x00ac, 0x00ac}, /* notsign */
    {0x00ad, 0x00ad}, /* hyphen */
    {0x00ae, 0x00ae}, /* registered */
    {0x00af, 0x00af}, /* macron */
    {0x00b0, 0x00b0}, /* degree */
    {0x00b1, 0x00b1}, /* plusminus */
    {0x00b2, 0x00b2}, /* twosuperior */
    {0x00b3, 0x00b3}, /* threesuperior */
    {0x00b4, 0x00b4}, /* acute */
    {0x00b5, 0x00b5}, /* mu */
    {0x00b6, 0x00b6}, /* paragraph */
    {0x00b7, 0x00b7}, /* periodcentered */
    {0x00b8, 0x00b8}, /* cedilla */
    {0x00b9, 0x00b9}, /* onesuperior */
    {0x00ba, 0x00ba}, /* masculine */
    {0x00bb, 0x00bb}, /* guillemotright */
    {0x00bc, 0x00bc}, /* onequarter */
    {0x00bd, 0x00bd}, /* onehalf */
    {0x00be, 0x00be}, /* threequarters */
    {0x00bf, 0x00bf}, /* questiondown */
    {0x00c0, 0x00c0}, /* Agrave */
    {0x00c1, 0x00c1}, /* Aacute */
    {0x00c2, 0x00c2}, /* Acircumflex */
    {0x00c3, 0x00c3}, /* Atilde */
    {0x00c4, 0x00c4}, /* Adiaeresis */
    {0x00c5, 0x00c5}, /* Aring */
    {0x00c6, 0x00c6}, /* AE */
    {0x00c7, 0x00c7}, /* Ccedilla */
    {0x00c8, 0x00c8}, /* Egrave */
    {0x00c9, 0x00c9}, /* Eacute */
    {0x00ca, 0x00ca}, /* Ecircumflex */
    {0x00cb, 0x00cb}, /* Ediaeresis */
    {0x00cc, 0x00cc}, /* Igrave */
    {0x00cd, 0x00cd}, /* Iacute */
    {0x00ce, 0x00ce}, /* Icircumflex */
    {0x00cf, 0x00cf}, /* Idiaeresis */
    {0x00d0, 0x00d0}, /* ETH */
    {0x00d1, 0x00d1}, /* Ntilde */
    {0x00d2, 0x00d2}, /* Ograve */
    {0x00d3, 0x00d3}, /* Oacute */
    {0x00d4, 0x00d4}, /* Ocircumflex */
    {0x00d5, 0x00d5}, /* Otilde */
    {0x00d6, 0x00d6}, /* Odiaeresis */
    {0x00d7, 0x00d7}, /* multiply */
    {0x00d8, 0x00d8}, /* Oslash */
    {0x00d9, 0x00d9}, /* Ugrave */
    {0x00da, 0x00da}, /* Uacute */
    {0x00db, 0x00db}, /* Ucircumflex */
    {0x00dc, 0x00dc}, /* Udiaeresis */
    {0x00dd, 0x00dd}, /* Yacute */
    {0x00de, 0x00de}, /* THORN */
    {0x00df, 0x00df}, /* ssharp */
    {0x00e0, 0x00e0}, /* agrave */
    {0x00e1, 0x00e1}, /* aacute */
    {0x00e2, 0x00e2}, /* acircumflex */
    {0x00e3, 0x00e3}, /* atilde */
    {0x00e4, 0x00e4}, /* adiaeresis */
    {0x00e5, 0x00e5}, /* aring */
    {0x00e6, 0x00e6}, /* ae */
    {0x00e7, 0x00e7}, /* ccedilla */
    {0x00e8, 0x00e8}, /* egrave */
    {0x00e9, 0x00e9}, /* eacute */
    {0x00ea, 0x00ea}, /* ecircumflex */
    {0x00eb, 0x00eb}, /* ediaeresis */
    {0x00ec, 0x00ec}, /* igrave */
    {0x00ed, 0x00ed}, /* iacute */
    {0x00ee, 0x00ee}, /* icircumflex */
    {0x00ef, 0x00ef}, /* idiaeresis */
    {0x00f0, 0x00f0}, /* eth */
    {0x00f1, 0x00f1}, /* ntilde */
    {0x00f2, 0x00f2}, /* ograve */
    {0x00f3, 0x00f3}, /* oacute */
    {0x00f4, 0x00f4}, /* ocircumflex */
    {0x00f5, 0x00f5}, /* otilde */
    {0x00f6, 0x00f6}, /* odiaeresis */
    {0x00f7, 0x00f7}, /* division */
    {0x00f8, 0x00f8}, /* oslash */
    {0x00f9, 0x00f9}, /* ugrave */
    {0x00fa, 0x00fa}, /* uacute */
    {0x00fb, 0x00fb}, /* ucircumflex */
    {0x00fc, 0x00fc}, /* udiaeresis */
    {0x00fd, 0x00fd}, /* yacute */
    {0x00fe, 0x00fe}, /* thorn */
    {0x00ff, 0x00ff}, /* ydiaeresis */
    {0x01a1, 0x0104}, /* Aogonek */
    {0x01a2, 0x02d8}, /* breve */
    {0x01a3, 0x0141}, /* Lstroke */
    {0x01a5, 0x013d}, /* Lcaron */
    {0x01a6, 0x015a}, /* Sacute */
    {0x01a9, 0x0160}, /* Scaron */
    {0x01aa, 0x015e}, /* Scedilla */
    {0x01ab, 0x0164}, /* Tcaron */
    {0x01ac, 0x0179}, /* Zacute */
    {0x01ae, 0x017d}, /* Zcaron */
    {0x01af, 0x017b}, /* Zabovedot */
    {0x01b1, 0x0105}, /* aogonek */
    {0x01b2, 0x02db}, /* ogonek */
    {0x01b3, 0x0142}, /* lstroke */
    {0x01b5, 0x013e}, /* lcaron */
    {0x01b6, 0x015b}, /* sacute */
    {0x01b7, 0x02c7}, /* caron */
    {0x01b9, 0x0161}, /* scaron */
    {0x01ba, 0x015f}, /* scedilla */
    {0x01bb, 0x0165}, /* tcaron */
    {0x01bc, 0x017a}, /* zacute */
    {0x01bd, 0x02dd}, /* doubleacute */
    {0x01be, 0x017e}, /* zcaron */
    {0x01bf, 0x017c}, /* zabovedot */
    {0x01c0, 0x0154}, /* Racute */
    {0x01c3, 0x0102}, /* Abreve */
    {0x01c5, 0x0139}, /* Lacute */
    {0x01c6, 0x0106}, /* Cacute */
    {0x01c8, 0x010c}, /* Ccaron */
    {0x01ca, 0x0118}, /* Eogonek */
    {0x01cc, 0x011a}, /* Ecaron */
    {0x01cf, 0x010e}, /* Dcaron */
    {0x01d0, 0x0110}, /* Dstroke */
    {0x01d1, 0x0143}, /* Nacute */
    {0x01d2, 0x0147}, /* Ncaron */
    {0x01d5, 0x0150}, /* Odoubleacute */
    {0x01d8, 0x0158}, /* Rcaron */
    {0x01d9, 0x016e}, /* Uring */
    {0x01db, 0x0170}, /* Udoubleacute */
    {0x01de, 0x0162}, /* Tcedilla */
    {0x01e0, 0x0155}, /* racute */
    {0x01e3, 0x0103}, /* abreve */
    {0x01e5, 0x013a}, /* lacute */
    {0x01e6, 0x0107}, /* cacute */
    {0x01e8, 0x010d}, /* ccaron */
    {0x01ea, 0x0119}, /* eogonek */
    {0x01ec, 0x011b}, /* ecaron */
    {0x01ef, 0x010f}, /* dcaron */
    {0x01f0, 0x0111}, /* dstroke */
    {0x01f1, 0x0144}, /* nacute */
    {0x01f2, 0x0148}, /* ncaron */
    {0x01f5, 0x0151}, /* odoubleacute */
    {0x01f8, 0x0159}, /* rcaron */
    {0x01f9, 0x016f}, /* uring */
    {0x01fb, 0x0171}, /* udoubleacute */
    {0x01fe, 0x0163}, /* tcedilla */
    {0x01ff, 0x02d9}, /* abovedot */
    {0x02a1, 0x0126}, /* Hstroke */
    {0x02a6, 0x0124}, /* Hcircumflex */
    {0x02a9, 0x0130}, /* Iabovedot */
    {0x02ab, 0x011e}, /* Gbreve */
    {0x02ac, 0x0134}, /* Jcircumflex */
    {0x02b1, 0x0127}, /* hstroke */
    {0x02b6, 0x0125}, /* hcircumflex */
    {0x02b9, 0x0131}, /* idotless */
    {0x02bb, 0x011f}, /* gbreve */
    {0x02bc, 0x0135}, /* jcircumflex */
    {0x02c5, 0x010a}, /* Cabovedot */
    {0x02c6, 0x0108}, /* Ccircumflex */
    {0x02d5, 0x0120}, /* Gabovedot */
    {0x02d8, 0x011c}, /* Gcircumflex */
    {0x02dd, 0x016c}, /* Ubreve */
    {0x02de, 0x015c}, /* Scircumflex */
    {0x02e5, 0x010b}, /* cabovedot */
    {0x02e6, 0x0109}, /* ccircumflex */
    {0x02f5, 0x0121}, /* gabovedot */
    {0x02f8, 0x011d}, /* gcircumflex */
    {0x02fd, 0x016d}, /* ubreve */
    {0x02fe, 0x015d}, /* scircumflex */
    {0x03a2, 0x0138}, /* kra */
    {0x03a3, 0x0156}, /* Rcedilla */
    {0x03a5, 0x0128}, /* Itilde */
    {0x03a6, 0x013b}, /* Lcedilla */
    {0x03aa, 0x0112}, /* Emacron */
    {0x03ab, 0x0122}, /* Gcedilla */
    {0x03ac, 0x0166}, /* Tslash */
    {0x03b3, 0x0157}, /* rcedilla */
    {0x03b5, 0x0129}, /* itilde */
    {0x03b6, 0x013c}, /* lcedilla */
    {0x03ba, 0x0113}, /* emacron */
    {0x03bb, 0x0123}, /* gcedilla */
    {0x03bc, 0x0167}, /* tslash */
    {0x03bd, 0x014a}, /* ENG */
    {0x03bf, 0x014b}, /* eng */
    {0x03c0, 0x0100}, /* Amacron */
    {0x03c7, 0x012e}, /* Iogonek */
    {0x03cc, 0x0116}, /* Eabovedot */
    {0x03cf, 0x012a}, /* Imacron */
    {0x03d1, 0x0145}, /* Ncedilla */
    {0x03d2, 0x014c}, /* Omacron */
    {0x03d3, 0x0136}, /* Kcedilla */
    {0x03d9, 0x0172}, /* Uogonek */
    {0x03dd, 0x0168}, /* Utilde */
    {0x03de, 0x016a}, /* Umacron */
    {0x03e0, 0x0101}, /* amacron */
    {0x03e7, 0x012f}, /* iogonek */
    {0x03ec, 0x0117}, /* eabovedot */
    {0x03ef, 0x012b}, /* imacron */
    {0x03f1, 0x0146}, /* ncedilla */
    {0x03f2, 0x014d}, /* omacron */
    {0x03f3, 0x0137}, /* kcedilla */
    {0x03f9, 0x0173}, /* uogonek */
    {0x03fd, 0x0169}, /* utilde */
    {0x03fe, 0x016b}, /* umacron */
    {0x047e, 0x203e}, /* overline */
    {0x04a1, 0x3002}, /* kana_fullstop */
    {0x04a2, 0x300c}, /* kana_openingbracket */
    {0x04a3, 0x300d}, /* kana_closingbracket */
    {0x04a4, 0x3001}, /* kana_comma */
    {0x04a5, 0x30fb}, /* kana_conjunctive */
    {0x04a6, 0x30f2}, /* kana_WO */
    {0x04a7, 0x30a1}, /* kana_a */
    {0x04a8, 0x30a3}, /* kana_i */
    {0x04a9, 0x30a5}, /* kana_u */
    {0x04aa, 0x30a7}, /* kana_e */
    {0x04ab, 0x30a9}, /* kana_o */
    {0x04ac, 0x30e3}, /* kana_ya */
    {0x04ad, 0x30e5}, /* kana_yu */
    {0x04ae, 0x30e7}, /* kana_yo */
    {0x04af, 0x30c3}, /* kana_tsu */
    {0x04b0, 0x30fc}, /* prolongedsound */
    {0x04b1, 0x30a2}, /* kana_A */
    {0x04b2, 0x30a4}, /* kana_I */
    {0x04b3, 0x30a6}, /* kana_U */
    {0x04b4, 0x30a8}, /* kana_E */
    {0x04b5, 0x30aa}, /* kana_O */
    {0x04b6, 0x30ab}, /* kana_KA */
    {0x04b7, 0x30ad}, /* kana_KI */
    {0x04b8, 0x30af}, /* kana_KU */
    {0x04b9, 0x30b1}, /* kana_KE */
    {0x04ba, 0x30b3}, /* kana_KO */
    {0x04bb, 0x30b5}, /* kana_SA */
    {0x04bc, 0x30b7}, /* kana_SHI */
    {0x04bd, 0x30b9}, /* kana_SU */
    {0x04be, 0x30bb}, /* kana_SE */
    {0x04bf, 0x30bd}, /* kana_SO */
    {0x04c0, 0x30bf}, /* kana_TA */
    {0x04c1, 0x30c1}, /* kana_CHI */
    {0x04c2, 0x30c4}, /* kana_TSU */
    {0x04c3, 0x30c6}, /* kana_TE */
    {0x04c4, 0x30c8}, /* kana_TO */
    {0x04c5, 0x30ca}, /* kana_NA */
    {0x04c6, 0x30cb}, /* kana_NI */
    {0x04c7, 0x30cc}, /* kana_NU */
    {0x04c8, 0x30cd}, /* kana_NE */
    {0x04c9, 0x30ce}, /* kana_NO */
    {0x04ca, 0x30cf}, /* kana_HA */
    {0x04cb, 0x30d2}, /* kana_HI */
    {0x04cc, 0x30d5}, /* kana_FU */
    {0x04cd, 0x30d8}, /* kana_HE */
    {0x04ce, 0x30db}, /* kana_HO */
    {0x04cf, 0x30de}, /* kana_MA */
    {0x04d0, 0x30df}, /* kana_MI */
    {0x04d1, 0x30e0}, /* kana_MU */
    {0x04d2, 0x30e1}, /* kana_ME */
    {0x04d3, 0x30e2}, /* kana_MO */
    {0x04d4, 0x30e4}, /* kana_YA */
    {0x04d5, 0x30e6}, /* kana_YU */
    {0x04d6, 0x30e8}, /* kana_YO */
    {0x04d7, 0x30e9}, /* kana_RA */
    {0x04d8, 0x30ea}, /* kana_RI */
    {0x04d9, 0x30eb}, /* kana_RU */
    {0x04da, 0x30ec}, /* kana_RE */
    {0x04db, 0x30ed}, /* kana_RO */
    {0x04dc, 0x30ef}, /* kana_WA */
    {0x04dd, 0x30f3}, /* kana_N */
    {0x04de, 0x309b}, /* voicedsound */
    {0x04df, 0x309c}, /* semivoicedsound */
    {0x05ac, 0x060c}, /* Arabic_comma */
    {0x05bb, 0x061b}, /* Arabic_semicolon */
    {0x05bf, 0x061f}, /* Arabic_question_mark */
    {0x05c1, 0x0621}, /* Arabic_hamza */
    {0x05c2, 0x0622}, /* Arabic_maddaonalef */
    {0x05c3, 0x0623}, /* Arabic_hamzaonalef */
    {0x05c4, 0x0624}, /* Arabic_hamzaonwaw */
    {0x05c5, 0x0625}, /* Arabic_hamzaunderalef */
    {0x05c6, 0x0626}, /* Arabic_hamzaonyeh */
    {0x05c7, 0x0627}, /* Arabic_alef */
    {0x05c8, 0x0628}, /* Arabic_beh */
    {0x05c9, 0x0629}, /* Arabic_tehmarbuta */
    {0x05ca, 0x062a}, /* Arabic_teh */
    {0x05cb, 0x062b}, /* Arabic_theh */
    {0x05cc, 0x062c}, /* Arabic_jeem */
    {0x05cd, 0x062d}, /* Arabic_hah */
    {0x05ce, 0x062e}, /* Arabic_khah */
    {0x05cf, 0x062f}, /* Arabic_dal */
    {0x05d0, 0x0630}, /* Arabic_thal */
    {0x05d1, 0x0631}, /* Arabic_ra */
    {0x05d2, 0x0632}, /* Arabic_zain */
    {0x05d3, 0x0633}, /* Arabic_seen */
    {0x05d4, 0x0634}, /* Arabic_sheen */
    {0x05d5, 0x0635}, /* Arabic_sad */
    {0x05d6, 0x0636}, /* Arabic_dad */
    {0x05d7, 0x0637}, /* Arabic_tah */
    {0x05d8, 0x0638}, /* Arabic_zah */
    {0x05d9, 0x0639}, /* Arabic_ain */
    {0x05da, 0x063a}, /* Arabic_ghain */
    {0x05e0, 0x0640}, /* Arabic_tatweel */
    {0x05e1, 0x0641}, /* Arabic_feh */
    {0x05e2, 0x0642}, /* Arabic_qaf */
    {0x05e3, 0x0643}, /* Arabic_kaf */
    {0x05e4, 0x0644}, /* Arabic_lam */
    {0x05e5, 0x0645}, /* Arabic_meem */
    {0x05e6, 0x0646}, /* Arabic_noon */
    {0x05e7, 0x0647}, /* Arabic_ha */
    {0x05e8, 0x0648}, /* Arabic_waw */
    {0x05e9, 0x0649}, /* Arabic_alefmaksura */
    {0x05ea, 0x064a}, /* Arabic_yeh */
    {0x05eb, 0x064b}, /* Arabic_fathatan */
    {0x05ec, 0x064c}, /* Arabic_dammatan */
    {0x05ed, 0x064d}, /* Arabic_kasratan */
    {0x05ee, 0x064e}, /* Arabic_fatha */
    {0x05ef, 0x064f}, /* Arabic_damma */
    {0x05f0, 0x0650}, /* Arabic_kasra */
    {0x05f1, 0x0651}, /* Arabic_shadda */
    {0x05f2, 0x0652}, /* Arabic_sukun */
    {0x06a1, 0x0452}, /* Serbian_dje */
    {0x06a2, 0x0453}, /* Macedonia_gje */
    {0x06a3, 0x0451}, /* Cyrillic_io */
    {0x06a4, 0x0454}, /* Ukrainian_ie */
    {0x06a5, 0x0455}, /* Macedonia_dse */
    {0x06a6, 0x0456}, /* Ukrainian_i */
    {0x06a7, 0x0457}, /* Ukrainian_yi */
    {0x06a8, 0x0458}, /* Cyrillic_je */
    {0x06a9, 0x0459}, /* Cyrillic_lje */
    {0x06aa, 0x045a}, /* Cyrillic_nje */
    {0x06ab, 0x045b}, /* Serbian_tshe */
    {0x06ac, 0x045c}, /* Macedonia_kje */
    {0x06ae, 0x045e}, /* Byelorussian_shortu */
    {0x06af, 0x045f}, /* Cyrillic_dzhe */
    {0x06b0, 0x2116}, /* numerosign */
    {0x06b1, 0x0402}, /* Serbian_DJE */
    {0x06b2, 0x0403}, /* Macedonia_GJE */
    {0x06b3, 0x0401}, /* Cyrillic_IO */
    {0x06b4, 0x0404}, /* Ukrainian_IE */
    {0x06b5, 0x0405}, /* Macedonia_DSE */
    {0x06b6, 0x0406}, /* Ukrainian_I */
    {0x06b7, 0x0407}, /* Ukrainian_YI */
    {0x06b8, 0x0408}, /* Cyrillic_JE */
    {0x06b9, 0x0409}, /* Cyrillic_LJE */
    {0x06ba, 0x040a}, /* Cyrillic_NJE */
    {0x06bb, 0x040b}, /* Serbian_TSHE */
    {0x06bc, 0x040c}, /* Macedonia_KJE */
    {0x06be, 0x040e}, /* Byelorussian_SHORTU */
    {0x06bf, 0x040f}, /* Cyrillic_DZHE */
    {0x06c0, 0x044e}, /* Cyrillic_yu */
    {0x06c1, 0x0430}, /* Cyrillic_a */
    {0x06c2, 0x0431}, /* Cyrillic_be */
    {0x06c3, 0x0446}, /* Cyrillic_tse */
    {0x06c4, 0x0434}, /* Cyrillic_de */
    {0x06c5, 0x0435}, /* Cyrillic_ie */
    {0x06c6, 0x0444}, /* Cyrillic_ef */
    {0x06c7, 0x0433}, /* Cyrillic_ghe */
    {0x06c8, 0x0445}, /* Cyrillic_ha */
    {0x06c9, 0x0438}, /* Cyrillic_i */
    {0x06ca, 0x0439}, /* Cyrillic_shorti */
    {0x06cb, 0x043a}, /* Cyrillic_ka */
    {0x06cc, 0x043b}, /* Cyrillic_el */
    {0x06cd, 0x043c}, /* Cyrillic_em */
    {0x06ce, 0x043d}, /* Cyrillic_en */
    {0x06cf, 0x043e}, /* Cyrillic_o */
    {0x06d0, 0x043f}, /* Cyrillic_pe */
    {0x06d1, 0x044f}, /* Cyrillic_ya */
    {0x06d2, 0x0440}, /* Cyrillic_er */
    {0x06d3, 0x0441}, /* Cyrillic_es */
    {0x06d4, 0x0442}, /* Cyrillic_te */
    {0x06d5, 0x0443}, /* Cyrillic_u */
    {0x06d6, 0x0436}, /* Cyrillic_zhe */
    {0x06d7, 0x0432}, /* Cyrillic_ve */
    {0x06d8, 0x044c}, /* Cyrillic_softsign */
    {0x06d9, 0x044b}, /* Cyrillic_yeru */
    {0x06da, 0x0437}, /* Cyrillic_ze */
    {0x06db, 0x0448}, /* Cyrillic_sha */
    {0x06dc, 0x044d}, /* Cyrillic_e */
    {0x06dd, 0x0449}, /* Cyrillic_shcha */
    {0x06de, 0x0447}, /* Cyrillic_che */
    {0x06df, 0x044a}, /* Cyrillic_hardsign */
    {0x06e0, 0x042e}, /* Cyrillic_YU */
    {0x06e1, 0x0410}, /* Cyrillic_A */
    {0x06e2, 0x0411}, /* Cyrillic_BE */
    {0x06e3, 0x0426}, /* Cyrillic_TSE */
    {0x06e4, 0x0414}, /* Cyrillic_DE */
    {0x06e5, 0x0415}, /* Cyrillic_IE */
    {0x06e6, 0x0424}, /* Cyrillic_EF */
    {0x06e7, 0x0413}, /* Cyrillic_GHE */
    {0x06e8, 0x0425}, /* Cyrillic_HA */
    {0x06e9, 0x0418}, /* Cyrillic_I */
    {0x06ea, 0x0419}, /* Cyrillic_SHORTI */
    {0x06eb, 0x041a}, /* Cyrillic_KA */
    {0x06ec, 0x041b}, /* Cyrillic_EL */
    {0x06ed, 0x041c}, /* Cyrillic_EM */
    {0x06ee, 0x041d}, /* Cyrillic_EN */
    {0x06ef, 0x041e}, /* Cyrillic_O */
    {0x06f0, 0x041f}, /* Cyrillic_PE */
    {0x06f1, 0x042f}, /* Cyrillic_YA */
    {0x06f2, 0x0420}, /* Cyrillic_ER */
    {0x06f3, 0x0421}, /* Cyrillic_ES */
    {0x06f4, 0x0422}, /* Cyrillic_TE */
    {0x06f5, 0x0423}, /* Cyrillic_U */
    {0x06f6, 0x0416}, /* Cyrillic_ZHE */
    {0x06f7, 0x0412}, /* Cyrillic_VE */
    {0x06f8, 0x042c}, /* Cyrillic_SOFTSIGN */
    {0x06f9, 0x042b}, /* Cyrillic_YERU */
    {0x06fa, 0x0417}, /* Cyrillic_ZE */
    {0x06fb, 0x0428}, /* Cyrillic_SHA */
    {0x06fc, 0x042d}, /* Cyrillic_E */
    {0x06fd, 0x0429}, /* Cyrillic_SHCHA */
    {0x06fe, 0x0427}, /* Cyrillic_CHE */
    {0x06ff, 0x042a}, /* Cyrillic_HARDSIGN */
    {0x07a1, 0x0386}, /* Greek_ALPHAaccent */
    {0x07a2, 0x0388}, /* Greek_EPSILONaccent */
    {0x07a3, 0x0389}, /* Greek_ETAaccent */
    {0x07a4, 0x038a}, /* Greek_IOTAaccent */
    {0x07a5, 0x03aa}, /* Greek_IOTAdiaeresis */
    {0x07a7, 0x038c}, /* Greek_OMICRONaccent */
    {0x07a8, 0x038e}, /* Greek_UPSILONaccent */
    {0x07a9, 0x03ab}, /* Greek_UPSILONdieresis */
    {0x07ab, 0x038f}, /* Greek_OMEGAaccent */
    {0x07ae, 0x0385}, /* Greek_accentdieresis */
    {0x07af, 0x2015}, /* Greek_horizbar */
    {0x07b1, 0x03ac}, /* Greek_alphaaccent */
    {0x07b2, 0x03ad}, /* Greek_epsilonaccent */
    {0x07b3, 0x03ae}, /* Greek_etaaccent */
    {0x07b4, 0x03af}, /* Greek_iotaaccent */
    {0x07b5, 0x03ca}, /* Greek_iotadieresis */
    {0x07b6, 0x0390}, /* Greek_iotaaccentdieresis */
    {0x07b7, 0x03cc}, /* Greek_omicronaccent */
    {0x07b8, 0x03cd}, /* Greek_upsilonaccent */
    {0x07b9, 0x03cb}, /* Greek_upsilondieresis */
    {0x07ba, 0x03b0}, /* Greek_upsilonaccentdieresis */
    {0x07bb, 0x03ce}, /* Greek_omegaaccent */
    {0x07c1, 0x0391}, /* Greek_ALPHA */
    {0x07c2, 0x0392}, /* Greek_BETA */
    {0x07c3, 0x0393}, /* Greek_GAMMA */
    {0x07c4, 0x0394}, /* Greek_DELTA */
    {0x07c5, 0x0395}, /* Greek_EPSILON */
    {0x07c6, 0x0396}, /* Greek_ZETA */
    {0x07c7, 0x0397}, /* Greek_ETA */
    {0x07c8, 0x0398}, /* Greek_THETA */
    {0x07c9, 0x0399}, /* Greek_IOTA */
    {0x07ca, 0x039a}, /* Greek_KAPPA */
    {0x07cb, 0x039b}, /* Greek_LAMDA */
    {0x07cc, 0x039c}, /* Greek_MU */
    {0x07cd, 0x039d}, /* Greek_NU */
    {0x07ce, 0x039e}, /* Greek_XI */
    {0x07cf, 0x039f}, /* Greek_OMICRON */
    {0x07d0, 0x03a0}, /* Greek_PI */
    {0x07d1, 0x03a1}, /* Greek_RHO */
    {0x07d2, 0x03a3}, /* Greek_SIGMA */
    {0x07d4, 0x03a4}, /* Greek_TAU */
    {0x07d5, 0x03a5}, /* Greek_UPSILON */
    {0x07d6, 0x03a6}, /* Greek_PHI */
    {0x07d7, 0x03a7}, /* Greek_CHI */
    {0x07d8, 0x03a8}, /* Greek_PSI */
    {0x07d9, 0x03a9}, /* Greek_OMEGA */
    {0x07e1, 0x03b1}, /* Greek_alpha */
    {0x07e2, 0x03b2}, /* Greek_beta */
    {0x07e3, 0x03b3}, /* Greek_gamma */
    {0x07e4, 0x03b4}, /* Greek_delta */
    {0x07e5, 0x03b5}, /* Greek_epsilon */
    {0x07e6, 0x03b6}, /* Greek_zeta */
    {0x07e7, 0x03b7}, /* Greek_eta */
    {0x07e8, 0x03b8}, /* Greek_theta */
    {0x07e9, 0x03b9}, /* Greek_iota */
    {0x07ea, 0x03ba}, /* Greek_kappa */
    {0x07eb, 0x03bb}, /* Greek_lambda */
    {0x07ec, 0x03bc}, /* Greek_mu */
    {0x07ed, 0x03bd}, /* Greek_nu */
    {0x07ee, 0x03be}, /* Greek_xi */
    {0x07ef, 0x03bf}, /* Greek_omicron */
    {0x07f0, 0x03c0}, /* Greek_pi */
    {0x07f1, 0x03c1}, /* Greek_rho */
    {0x07f2, 0x03c3}, /* Greek_sigma */
    {0x07f3, 0x03c2}, /* Greek_finalsmallsigma */
    {0x07f4, 0x03c4}, /* Greek_tau */
    {0x07f5, 0x03c5}, /* Greek_upsilon */
    {0x07f6, 0x03c6}, /* Greek_phi */
    {0x07f7, 0x03c7}, /* Greek_chi */
    {0x07f8, 0x03c8}, /* Greek_psi */
    {0x07f9, 0x03c9}, /* Greek_omega */
    {0x08a1, 0x23b7}, /* leftradical */
    {0x08a4, 0x2320}, /* topintegral */
    {0x08a5, 0x2321}, /* botintegral */
    {0x08a7, 0x23a1}, /* topleftsqbracket */
    {0x08a8, 0x23a3}, /* botleftsqbracket */
    {0x08a9, 0x23a4}, /* toprightsqbracket */
    {0x08aa, 0x23a6}, /* botrightsqbracket */
    {0x08ab, 0x239b}, /* topleftparens */
    {0x08ac, 0x239d}, /* botleftparens */
    {0x08ad, 0x239e}, /* toprightparens */
    {0x08ae, 0x23a0}, /* botrightparens */
    {0x08af, 0x23a8}, /* leftmiddlecurlybrace */
    {0x08b0, 0x23ac}, /* rightmiddlecurlybrace */
    {0x08bc, 0x2264}, /* lessthanequal */
    {0x08bd, 0x2260}, /* notequal */
    {0x08be, 0x2265}, /* greaterthanequal */
    {0x08bf, 0x222b}, /* integral */
    {0x08c0, 0x2234}, /* therefore */
    {0x08c1, 0x221d}, /* variation */
    {0x08c2, 0x221e}, /* infinity */
    {0x08c5, 0x2207}, /* nabla */
    {0x08c8, 0x223c}, /* approximate */
    {0x08c9, 0x2243}, /* similarequal */
    {0x08cd, 0x21d4}, /* ifonlyif */
    {0x08ce, 0x21d2}, /* implies */
    {0x08cf, 0x2261}, /* identical */
    {0x08d6, 0x221a}, /* radical */
    {0x08da, 0x2282}, /* includedin */
    {0x08db, 0x2283}, /* includes */
    {0x08dc, 0x2229}, /* intersection */
    {0x08dd, 0x222a}, /* union */
    {0x08de, 0x2227}, /* logicaland */
    {0x08df, 0x2228}, /* logicalor */
    {0x08ef, 0x2202}, /* partialderivative */
    {0x08f6, 0x0192}, /* function */
    {0x08fb, 0x2190}, /* leftarrow */
    {0x08fc, 0x2191}, /* uparrow */
    {0x08fd, 0x2192}, /* rightarrow */
    {0x08fe, 0x2193}, /* downarrow */
    {0x09e0, 0x25c6}, /* soliddiamond */
    {0x09e1, 0x2592}, /* checkerboard */
    {0x09e2, 0x2409}, /* ht */
    {0x09e3, 0x240c}, /* ff */
    {0x09e4, 0x240d}, /* cr */
    {0x09e5, 0x240a}, /* lf */
    {0x09e8, 0x2424}, /* nl */
    {0x09e9, 0x240b}, /* vt */
    {0x09ea, 0x2518}, /* lowrightcorner */
    {0x09eb, 0x2510}, /* uprightcorner */
    {0x09ec, 0x250c}, /* upleftcorner */
    {0x09ed, 0x2514}, /* lowleftcorner */
    {0x09ee, 0x253c}, /* crossinglines */
    {0x09ef, 0x23ba}, /* horizlinescan1 */
    {0x09f0, 0x23bb}, /* horizlinescan3 */
    {0x09f1, 0x2500}, /* horizlinescan5 */
    {0x09f2, 0x23bc}, /* horizlinescan7 */
    {0x09f3, 0x23bd}, /* horizlinescan9 */
    {0x09f4, 0x251c}, /* leftt */
    {0x09f5, 0x2524}, /* rightt */
    {0x09f6, 0x2534}, /* bott */
    {0x09f7, 0x252c}, /* topt */
    {0x09f8, 0x2502}, /* vertbar */
    {0x0aa1, 0x2003}, /* emspace */
    {0x0aa2, 0x2002}, /* enspace */
    {0x0aa3, 0x2004}, /* em3space */
    {0x0aa4, 0x2005}, /* em4space */
    {0x0aa5, 0x2007}, /* digitspace */
    {0x0aa6, 0x2008}, /* punctspace */
    {0x0aa7, 0x2009}, /* thinspace */
    {0x0aa8, 0x200a}, /* hairspace */
    {0x0aa9, 0x2014}, /* emdash */
    {0x0aaa, 0x2013}, /* endash */
    {0x0aae, 0x2026}, /* ellipsis */
    {0x0aaf, 0x2025}, /* doubbaselinedot */
    {0x0ab0, 0x2153}, /* onethird */
    {0x0ab1, 0x2154}, /* twothirds */
    {0x0ab2, 0x2155}, /* onefifth */
    {0x0ab3, 0x2156}, /* twofifths */
    {0x0ab4, 0x2157}, /* threefifths */
    {0x0ab5, 0x2158}, /* fourfifths */
    {0x0ab6, 0x2159}, /* onesixth */
    {0x0ab7, 0x215a}, /* fivesixths */
    {0x0ab8, 0x2105}, /* careof */
    {0x0abb, 0x2012}, /* figdash */
    {0x0ac3, 0x215b}, /* oneeighth */
    {0x0ac4, 0x215c}, /* threeeighths */
    {0x0ac5, 0x215d}, /* fiveeighths */
    {0x0ac6, 0x215e}, /* seveneighths */
    {0x0ac9, 0x2122}, /* trademark */
    {0x0ad0, 0x2018}, /* leftsinglequotemark */
    {0x0ad1, 0x2019}, /* rightsinglequotemark */
    {0x0ad2, 0x201c}, /* leftdoublequotemark */
    {0x0ad3, 0x201d}, /* rightdoublequotemark */
    {0x0ad4, 0x211e}, /* prescription */
    {0x0ad6, 0x2032}, /* minutes */
    {0x0ad7, 0x2033}, /* seconds */
    {0x0ad9, 0x271d}, /* latincross */
    {0x0aec, 0x2663}, /* club */
    {0x0aed, 0x2666}, /* diamond */
    {0x0aee, 0x2665}, /* heart */
    {0x0af0, 0x2720}, /* maltesecross */
    {0x0af1, 0x2020}, /* dagger */
    {0x0af2, 0x2021}, /* doubledagger */
    {0x0af3, 0x2713}, /* checkmark */
    {0x0af4, 0x2717}, /* ballotcross */
    {0x0af5, 0x266f}, /* musicalsharp */
    {0x0af6, 0x266d}, /* musicalflat */
    {0x0af7, 0x2642}, /* malesymbol */
    {0x0af8, 0x2640}, /* femalesymbol */
    {0x0af9, 0x260e}, /* telephone */
    {0x0afa, 0x2315}, /* telephonerecorder */
    {0x0afb, 0x2117}, /* phonographcopyright */
    {0x0afc, 0x2038}, /* caret */
    {0x0afd, 0x201a}, /* singlelowquotemark */
    {0x0afe, 0x201e}, /* doublelowquotemark */
    {0x0bc2, 0x22a5}, /* downtack */
    {0x0bc4, 0x230a}, /* downstile */
    {0x0bca, 0x2218}, /* jot */
    {0x0bcc, 0x2395}, /* quad */
    {0x0bce, 0x22a4}, /* uptack */
    {0x0bcf, 0x25cb}, /* circle */
    {0x0bd3, 0x2308}, /* upstile */
    {0x0bdc, 0x22a2}, /* lefttack */
    {0x0bfc, 0x22a3}, /* righttack */
    {0x0cdf, 0x2017}, /* hebrew_doublelowline */
    {0x0ce0, 0x05d0}, /* hebrew_aleph */
    {0x0ce1, 0x05d1}, /* hebrew_bet */
    {0x0ce2, 0x05d2}, /* hebrew_gimel */
    {0x0ce3, 0x05d3}, /* hebrew_dalet */
    {0x0ce4, 0x05d4}, /* hebrew_he */
    {0x0ce5, 0x05d5}, /* hebrew_waw */
    {0x0ce6, 0x05d6}, /* hebrew_zain */
    {0x0ce7, 0x05d7}, /* hebrew_chet */
    {0x0ce8, 0x05d8}, /* hebrew_tet */
    {0x0ce9, 0x05d9}, /* hebrew_yod */
    {0x0cea, 0x05da}, /* hebrew_finalkaph */
    {0x0ceb, 0x05db}, /* hebrew_kaph */
    {0x0cec, 0x05dc}, /* hebrew_lamed */
    {0x0ced, 0x05dd}, /* hebrew_finalmem */
    {0x0cee, 0x05de}, /* hebrew_mem */
    {0x0cef, 0x05df}, /* hebrew_finalnun */
    {0x0cf0, 0x05e0}, /* hebrew_nun */
    {0x0cf1, 0x05e1}, /* hebrew_samech */
    {0x0cf2, 0x05e2}, /* hebrew_ayin */
    {0x0cf3, 0x05e3}, /* hebrew_finalpe */
    {0x0cf4, 0x05e4}, /* hebrew_pe */
    {0x0cf5, 0x05e5}, /* hebrew_finalzade */
    {0x0cf6, 0x05e6}, /* hebrew_zade */
    {0x0cf7, 0x05e7}, /* hebrew_qoph */
    {0x0cf8, 0x05e8}, /* hebrew_resh */
    {0x0cf9, 0x05e9}, /* hebrew_shin */
    {0x0cfa, 0x05ea}, /* hebrew_taw */
    {0x0da1, 0x0e01}, /* Thai_kokai */
    {0x0da2, 0x0e02}, /* Thai_khokhai */
    {0x0da3, 0x0e03}, /* Thai_khokhuat */
    {0x0da4, 0x0e04}, /* Thai_khokhwai */
    {0x0da5, 0x0e05}, /* Thai_khokhon */
    {0x0da6, 0x0e06}, /* Thai_khorakhang */
    {0x0da7, 0x0e07}, /* Thai_ngongu */
    {0x0da8, 0x0e08}, /* Thai_chochan */
    {0x0da9, 0x0e09}, /* Thai_choching */
    {0x0daa, 0x0e0a}, /* Thai_chochang */
    {0x0dab, 0x0e0b}, /* Thai_soso */
    {0x0dac, 0x0e0c}, /* Thai_chochoe */
    {0x0dad, 0x0e0d}, /* Thai_yoying */
    {0x0dae, 0x0e0e}, /* Thai_dochada */
    {0x0daf, 0x0e0f}, /* Thai_topatak */
    {0x0db0, 0x0e10}, /* Thai_thothan */
    {0x0db1, 0x0e11}, /* Thai_thonangmontho */
    {0x0db2, 0x0e12}, /* Thai_thophuthao */
    {0x0db3, 0x0e13}, /* Thai_nonen */
    {0x0db4, 0x0e14}, /* Thai_dodek */
    {0x0db5, 0x0e15}, /* Thai_totao */
    {0x0db6, 0x0e16}, /* Thai_thothung */
    {0x0db7, 0x0e17}, /* Thai_thothahan */
    {0x0db8, 0x0e18}, /* Thai_thothong */
    {0x0db9, 0x0e19}, /* Thai_nonu */
    {0x0dba, 0x0e1a}, /* Thai_bobaimai */
    {0x0dbb, 0x0e1b}, /* Thai_popla */
    {0x0dbc, 0x0e1c}, /* Thai_phophung */
    {0x0dbd, 0x0e1d}, /* Thai_fofa */
    {0x0dbe, 0x0e1e}, /* Thai_phophan */
    {0x0dbf, 0x0e1f}, /* Thai_fofan */
    {0x0dc0, 0x0e20}, /* Thai_phosamphao */
    {0x0dc1, 0x0e21}, /* Thai_moma */
    {0x0dc2, 0x0e22}, /* Thai_yoyak */
    {0x0dc3, 0x0e23}, /* Thai_rorua */
    {0x0dc4, 0x0e24}, /* Thai_ru */
    {0x0dc5, 0x0e25}, /* Thai_loling */
    {0x0dc6, 0x0e26}, /* Thai_lu */
    {0x0dc7, 0x0e27}, /* Thai_wowaen */
    {0x0dc8, 0x0e28}, /* Thai_sosala */
    {0x0dc9, 0x0e29}, /* Thai_sorusi */
    {0x0dca, 0x0e2a}, /* Thai_sosua */
    {0x0dcb, 0x0e2b}, /* Thai_hohip */
    {0x0dcc, 0x0e2c}, /* Thai_lochula */
    {0x0dcd, 0x0e2d}, /* Thai_oang */
    {0x0dce, 0x0e2e}, /* Thai_honokhuk */
    {0x0dcf, 0x0e2f}, /* Thai_paiyannoi */
    {0x0dd0, 0x0e30}, /* Thai_saraa */
    {0x0dd1, 0x0e31}, /* Thai_maihanakat */
    {0x0dd2, 0x0e32}, /* Thai_saraaa */
    {0x0dd3, 0x0e33}, /* Thai_saraam */
    {0x0dd4, 0x0e34}, /* Thai_sarai */
    {0x0dd5, 0x0e35}, /* Thai_saraii */
    {0x0dd6, 0x0e36}, /* Thai_saraue */
    {0x0dd7, 0x0e37}, /* Thai_sarauee */
    {0x0dd8, 0x0e38}, /* Thai_sarau */
    {0x0dd9, 0x0e39}, /* Thai_sarauu */
    {0x0dda, 0x0e3a}, /* Thai_phinthu */
    {0x0ddf, 0x0e3f}, /* Thai_baht */
    {0x0de0, 0x0e40}, /* Thai_sarae */
    {0x0de1, 0x0e41}, /* Thai_saraae */
    {0x0de2, 0x0e42}, /* Thai_sarao */
    {0x0de3, 0x0e43}, /* Thai_saraaimaimuan */
    {0x0de4, 0x0e44}, /* Thai_saraaimaimalai */
    {0x0de5, 0x0e45}, /* Thai_lakkhangyao */
    {0x0de6, 0x0e46}, /* Thai_maiyamok */
    {0x0de7, 0x0e47}, /* Thai_maitaikhu */
    {0x0de8, 0x0e48}, /* Thai_maiek */
    {0x0de9, 0x0e49}, /* Thai_maitho */
    {0x0dea, 0x0e4a}, /* Thai_maitri */
    {0x0deb, 0x0e4b}, /* Thai_maichattawa */
    {0x0dec, 0x0e4c}, /* Thai_thanthakhat */
    {0x0ded, 0x0e4d}, /* Thai_nikhahit */
    {0x0df0, 0x0e50}, /* Thai_leksun */
    {0x0df1, 0x0e51}, /* Thai_leknung */
    {0x0df2, 0x0e52}, /* Thai_leksong */
    {0x0df3, 0x0e53}, /* Thai_leksam */
    {0x0df4, 0x0e54}, /* Thai_leksi */
    {0x0df5, 0x0e55}, /* Thai_lekha */
    {0x0df6, 0x0e56}, /* Thai_lekhok */
    {0x0df7, 0x0e57}, /* Thai_lekchet */
    {0x0df8, 0x0e58}, /* Thai_lekpaet */
    {0x0df9, 0x0e59}, /* Thai_lekkao */
    {0x13bc, 0x0152}, /* OE */
    {0x13bd, 0x0153}, /* oe */
    {0x13be, 0x0178}, /* Ydiaeresis */
    {0x20a0, 0x20a0}, /* EcuSign */
    {0x20a1, 0x20a1}, /* ColonSign */
    {0x20a2, 0x20a2}, /* CruzeiroSign */
    {0x20a3, 0x20a3}, /* FFrancSign */
    {0x20a4, 0x20a4}, /* LiraSign */
    {0x20a5, 0x20a5}, /* MillSign */
    {0x20a6, 0x20a6}, /* NairaSign */
    {0x20a7, 0x20a7}, /* PesetaSign */
    {0x20a8, 0x20a8}, /* RupeeSign */
    {0x20a9, 0x20a9}, /* WonSign */
    {0x20aa, 0x20aa}, /* NewSheqelSign */
    {0x20ab, 0x20ab}, /* DongSign */
    {0x20ac, 0x20ac}, /* EuroSign */
    {0x06ad, 0x0491}, /* Ukrainian_ghe_with_upturn */
    {0x06bd, 0x0490}, /* Ukrainian_GHE_WITH_UPTURN */
    {0x14a2, 0x0587}, /* Armenian_ligature_ew */
    {0x14a3, 0x0589}, /* Armenian_verjaket */
    {0x14aa, 0x055d}, /* Armenian_but */
    {0x14ad, 0x058a}, /* Armenian_yentamna */
    {0x14af, 0x055c}, /* Armenian_amanak */
    {0x14b0, 0x055b}, /* Armenian_shesht */
    {0x14b1, 0x055e}, /* Armenian_paruyk */
    {0x14b2, 0x0531}, /* Armenian_AYB */
    {0x14b3, 0x0561}, /* Armenian_ayb */
    {0x14b4, 0x0532}, /* Armenian_BEN */
    {0x14b5, 0x0562}, /* Armenian_ben */
    {0x14b6, 0x0533}, /* Armenian_GIM */
    {0x14b7, 0x0563}, /* Armenian_gim */
    {0x14b8, 0x0534}, /* Armenian_DA */
    {0x14b9, 0x0564}, /* Armenian_da */
    {0x14ba, 0x0535}, /* Armenian_YECH */
    {0x14bb, 0x0565}, /* Armenian_yech */
    {0x14bc, 0x0536}, /* Armenian_ZA */
    {0x14bd, 0x0566}, /* Armenian_za */
    {0x14be, 0x0537}, /* Armenian_E */
    {0x14bf, 0x0567}, /* Armenian_e */
    {0x14c0, 0x0538}, /* Armenian_AT */
    {0x14c1, 0x0568}, /* Armenian_at */
    {0x14c2, 0x0539}, /* Armenian_TO */
    {0x14c3, 0x0569}, /* Armenian_to */
    {0x14c4, 0x053a}, /* Armenian_ZHE */
    {0x14c5, 0x056a}, /* Armenian_zhe */
    {0x14c6, 0x053b}, /* Armenian_INI */
    {0x14c7, 0x056b}, /* Armenian_ini */
    {0x14c8, 0x053c}, /* Armenian_LYUN */
    {0x14c9, 0x056c}, /* Armenian_lyun */
    {0x14ca, 0x053d}, /* Armenian_KHE */
    {0x14cb, 0x056d}, /* Armenian_khe */
    {0x14cc, 0x053e}, /* Armenian_TSA */
    {0x14cd, 0x056e}, /* Armenian_tsa */
    {0x14ce, 0x053f}, /* Armenian_KEN */
    {0x14cf, 0x056f}, /* Armenian_ken */
    {0x14d0, 0x0540}, /* Armenian_HO */
    {0x14d1, 0x0570}, /* Armenian_ho */
    {0x14d2, 0x0541}, /* Armenian_DZA */
    {0x14d3, 0x0571}, /* Armenian_dza */
    {0x14d4, 0x0542}, /* Armenian_GHAT */
    {0x14d5, 0x0572}, /* Armenian_ghat */
    {0x14d6, 0x0543}, /* Armenian_TCHE */
    {0x14d7, 0x0573}, /* Armenian_tche */
    {0x14d8, 0x0544}, /* Armenian_MEN */
    {0x14d9, 0x0574}, /* Armenian_men */
    {0x14da, 0x0545}, /* Armenian_HI */
    {0x14db, 0x0575}, /* Armenian_hi */
    {0x14dc, 0x0546}, /* Armenian_NU */
    {0x14dd, 0x0576}, /* Armenian_nu */
    {0x14de, 0x0547}, /* Armenian_SHA */
    {0x14df, 0x0577}, /* Armenian_sha */
    {0x14e0, 0x0548}, /* Armenian_VO */
    {0x14e1, 0x0578}, /* Armenian_vo */
    {0x14e2, 0x0549}, /* Armenian_CHA */
    {0x14e3, 0x0579}, /* Armenian_cha */
    {0x14e4, 0x054a}, /* Armenian_PE */
    {0x14e5, 0x057a}, /* Armenian_pe */
    {0x14e6, 0x054b}, /* Armenian_JE */
    {0x14e7, 0x057b}, /* Armenian_je */
    {0x14e8, 0x054c}, /* Armenian_RA */
    {0x14e9, 0x057c}, /* Armenian_ra */
    {0x14ea, 0x054d}, /* Armenian_SE */
    {0x14eb, 0x057d}, /* Armenian_se */
    {0x14ec, 0x054e}, /* Armenian_VEV */
    {0x14ed, 0x057e}, /* Armenian_vev */
    {0x14ee, 0x054f}, /* Armenian_TYUN */
    {0x14ef, 0x057f}, /* Armenian_tyun */
    {0x14f0, 0x0550}, /* Armenian_RE */
    {0x14f1, 0x0580}, /* Armenian_re */
    {0x14f2, 0x0551}, /* Armenian_TSO */
    {0x14f3, 0x0581}, /* Armenian_tso */
    {0x14f4, 0x0552}, /* Armenian_VYUN */
    {0x14f5, 0x0582}, /* Armenian_vyun */
    {0x14f6, 0x0553}, /* Armenian_PYUR */
    {0x14f7, 0x0583}, /* Armenian_pyur */
    {0x14f8, 0x0554}, /* Armenian_KE */
    {0x14f9, 0x0584}, /* Armenian_ke */
    {0x14fa, 0x0555}, /* Armenian_O */
    {0x14fb, 0x0585}, /* Armenian_o */
    {0x14fc, 0x0556}, /* Armenian_FE */
    {0x14fd, 0x0586}, /* Armenian_fe */
    {0x14fe, 0x055a}, /* Armenian_apostrophe */
    {0x15d0, 0x10d0}, /* Georgian_an */
    {0x15d1, 0x10d1}, /* Georgian_ban */
    {0x15d2, 0x10d2}, /* Georgian_gan */
    {0x15d3, 0x10d3}, /* Georgian_don */
    {0x15d4, 0x10d4}, /* Georgian_en */
    {0x15d5, 0x10d5}, /* Georgian_vin */
    {0x15d6, 0x10d6}, /* Georgian_zen */
    {0x15d7, 0x10d7}, /* Georgian_tan */
    {0x15d8, 0x10d8}, /* Georgian_in */
    {0x15d9, 0x10d9}, /* Georgian_kan */
    {0x15da, 0x10da}, /* Georgian_las */
    {0x15db, 0x10db}, /* Georgian_man */
    {0x15dc, 0x10dc}, /* Georgian_nar */
    {0x15dd, 0x10dd}, /* Georgian_on */
    {0x15de, 0x10de}, /* Georgian_par */
    {0x15df, 0x10df}, /* Georgian_zhar */
    {0x15e0, 0x10e0}, /* Georgian_rae */
    {0x15e1, 0x10e1}, /* Georgian_san */
    {0x15e2, 0x10e2}, /* Georgian_tar */
    {0x15e3, 0x10e3}, /* Georgian_un */
    {0x15e4, 0x10e4}, /* Georgian_phar */
    {0x15e5, 0x10e5}, /* Georgian_khar */
    {0x15e6, 0x10e6}, /* Georgian_ghan */
    {0x15e7, 0x10e7}, /* Georgian_qar */
    {0x15e8, 0x10e8}, /* Georgian_shin */
    {0x15e9, 0x10e9}, /* Georgian_chin */
    {0x15ea, 0x10ea}, /* Georgian_can */
    {0x15eb, 0x10eb}, /* Georgian_jil */
    {0x15ec, 0x10ec}, /* Georgian_cil */
    {0x15ed, 0x10ed}, /* Georgian_char */
    {0x15ee, 0x10ee}, /* Georgian_xan */
    {0x15ef, 0x10ef}, /* Georgian_jhan */
    {0x15f0, 0x10f0}, /* Georgian_hae */
    {0x15f1, 0x10f1}, /* Georgian_he */
    {0x15f2, 0x10f2}, /* Georgian_hie */
    {0x15f3, 0x10f3}, /* Georgian_we */
    {0x15f4, 0x10f4}, /* Georgian_har */
    {0x15f5, 0x10f5}, /* Georgian_hoe */
    {0x15f6, 0x10f6}, /* Georgian_fi */
    {0x12a1, 0x1e02}, /* Babovedot */
    {0x12a2, 0x1e03}, /* babovedot */
    {0x12a6, 0x1e0a}, /* Dabovedot */
    {0x12a8, 0x1e80}, /* Wgrave */
    {0x12aa, 0x1e82}, /* Wacute */
    {0x12ab, 0x1e0b}, /* dabovedot */
    {0x12ac, 0x1ef2}, /* Ygrave */
    {0x12b0, 0x1e1e}, /* Fabovedot */
    {0x12b1, 0x1e1f}, /* fabovedot */
    {0x12b4, 0x1e40}, /* Mabovedot */
    {0x12b5, 0x1e41}, /* mabovedot */
    {0x12b7, 0x1e56}, /* Pabovedot */
    {0x12b8, 0x1e81}, /* wgrave */
    {0x12b9, 0x1e57}, /* pabovedot */
    {0x12ba, 0x1e83}, /* wacute */
    {0x12bb, 0x1e60}, /* Sabovedot */
    {0x12bc, 0x1ef3}, /* ygrave */
    {0x12bd, 0x1e84}, /* Wdiaeresis */
    {0x12be, 0x1e85}, /* wdiaeresis */
    {0x12bf, 0x1e61}, /* sabovedot */
    {0x12d0, 0x0174}, /* Wcircumflex */
    {0x12d7, 0x1e6a}, /* Tabovedot */
    {0x12de, 0x0176}, /* Ycircumflex */
    {0x12f0, 0x0175}, /* wcircumflex */
    {0x12f7, 0x1e6b}, /* tabovedot */
    {0x12fe, 0x0177}, /* ycircumflex */
    {0x0590, 0x06f0}, /* Farsi_0 */
    {0x0591, 0x06f1}, /* Farsi_1 */
    {0x0592, 0x06f2}, /* Farsi_2 */
    {0x0593, 0x06f3}, /* Farsi_3 */
    {0x0594, 0x06f4}, /* Farsi_4 */
    {0x0595, 0x06f5}, /* Farsi_5 */
    {0x0596, 0x06f6}, /* Farsi_6 */
    {0x0597, 0x06f7}, /* Farsi_7 */
    {0x0598, 0x06f8}, /* Farsi_8 */
    {0x0599, 0x06f9}, /* Farsi_9 */
    {0x05a5, 0x066a}, /* Arabic_percent */
    {0x05a6, 0x0670}, /* Arabic_superscript_alef */
    {0x05a7, 0x0679}, /* Arabic_tteh */
    {0x05a8, 0x067e}, /* Arabic_peh */
    {0x05a9, 0x0686}, /* Arabic_tcheh */
    {0x05aa, 0x0688}, /* Arabic_ddal */
    {0x05ab, 0x0691}, /* Arabic_rreh */
    {0x05ae, 0x06d4}, /* Arabic_fullstop */
    {0x05b0, 0x0660}, /* Arabic_0 */
    {0x05b1, 0x0661}, /* Arabic_1 */
    {0x05b2, 0x0662}, /* Arabic_2 */
    {0x05b3, 0x0663}, /* Arabic_3 */
    {0x05b4, 0x0664}, /* Arabic_4 */
    {0x05b5, 0x0665}, /* Arabic_5 */
    {0x05b6, 0x0666}, /* Arabic_6 */
    {0x05b7, 0x0667}, /* Arabic_7 */
    {0x05b8, 0x0668}, /* Arabic_8 */
    {0x05b9, 0x0669}, /* Arabic_9 */
    {0x05f3, 0x0653}, /* Arabic_madda_above */
    {0x05f4, 0x0654}, /* Arabic_hamza_above */
    {0x05f5, 0x0655}, /* Arabic_hamza_below */
    {0x05f6, 0x0698}, /* Arabic_jeh */
    {0x05f7, 0x06a4}, /* Arabic_veh */
    {0x05f8, 0x06a9}, /* Arabic_keheh */
    {0x05f9, 0x06af}, /* Arabic_gaf */
    {0x05fa, 0x06ba}, /* Arabic_noon_ghunna */
    {0x05fb, 0x06be}, /* Arabic_heh_doachashmee */
    {0x05fc, 0x06cc}, /* Farsi_yeh */
    {0x05fd, 0x06d2}, /* Arabic_yeh_baree */
    {0x05fe, 0x06c1}, /* Arabic_heh_goal */
    {0x0680, 0x0492}, /* Cyrillic_GHE_bar */
    {0x0681, 0x0496}, /* Cyrillic_ZHE_descender */
    {0x0682, 0x049a}, /* Cyrillic_KA_descender */
    {0x0683, 0x049c}, /* Cyrillic_KA_vertstroke */
    {0x0684, 0x04a2}, /* Cyrillic_EN_descender */
    {0x0685, 0x04ae}, /* Cyrillic_U_straight */
    {0x0686, 0x04b0}, /* Cyrillic_U_straight_bar */
    {0x0687, 0x04b2}, /* Cyrillic_HA_descender */
    {0x0688, 0x04b6}, /* Cyrillic_CHE_descender */
    {0x0689, 0x04b8}, /* Cyrillic_CHE_vertstroke */
    {0x068a, 0x04ba}, /* Cyrillic_SHHA */
    {0x068c, 0x04d8}, /* Cyrillic_SCHWA */
    {0x068d, 0x04e2}, /* Cyrillic_I_macron */
    {0x068e, 0x04e8}, /* Cyrillic_O_bar */
    {0x068f, 0x04ee}, /* Cyrillic_U_macron */
    {0x0690, 0x0493}, /* Cyrillic_ghe_bar */
    {0x0691, 0x0497}, /* Cyrillic_zhe_descender */
    {0x0692, 0x049b}, /* Cyrillic_ka_descender */
    {0x0693, 0x049d}, /* Cyrillic_ka_vertstroke */
    {0x0694, 0x04a3}, /* Cyrillic_en_descender */
    {0x0695, 0x04af}, /* Cyrillic_u_straight */
    {0x0696, 0x04b1}, /* Cyrillic_u_straight_bar */
    {0x0697, 0x04b3}, /* Cyrillic_ha_descender */
    {0x0698, 0x04b7}, /* Cyrillic_che_descender */
    {0x0699, 0x04b9}, /* Cyrillic_che_vertstroke */
    {0x069a, 0x04bb}, /* Cyrillic_shha */
    {0x069c, 0x04d9}, /* Cyrillic_schwa */
    {0x069d, 0x04e3}, /* Cyrillic_i_macron */
    {0x069e, 0x04e9}, /* Cyrillic_o_bar */
    {0x069f, 0x04ef}, /* Cyrillic_u_macron */
    {0x16a3, 0x1e8a}, /* Xabovedot */
    {0x16a6, 0x012c}, /* Ibreve */
    {0x16a9, 0x01b5}, /* Zstroke */
    {0x16aa, 0x01e6}, /* Gcaron */
    {0x16af, 0x019f}, /* Obarred */
    {0x16b3, 0x1e8b}, /* xabovedot */
    {0x16b6, 0x012d}, /* ibreve */
    {0x16b9, 0x01b6}, /* zstroke */
    {0x16ba, 0x01e7}, /* gcaron */
    {0x16bd, 0x01d2}, /* ocaron */
    {0x16bf, 0x0275}, /* obarred */
    {0x16c6, 0x018f}, /* SCHWA */
    {0x16f6, 0x0259}, /* schwa */
    {0x16d1, 0x1e36}, /* Lbelowdot */
    {0x16e1, 0x1e37}, /* lbelowdot */
    {0x1ea0, 0x1ea0}, /* Abelowdot */
    {0x1ea1, 0x1ea1}, /* abelowdot */
    {0x1ea2, 0x1ea2}, /* Ahook */
    {0x1ea3, 0x1ea3}, /* ahook */
    {0x1ea4, 0x1ea4}, /* Acircumflexacute */
    {0x1ea5, 0x1ea5}, /* acircumflexacute */
    {0x1ea6, 0x1ea6}, /* Acircumflexgrave */
    {0x1ea7, 0x1ea7}, /* acircumflexgrave */
    {0x1ea8, 0x1ea8}, /* Acircumflexhook */
    {0x1ea9, 0x1ea9}, /* acircumflexhook */
    {0x1eaa, 0x1eaa}, /* Acircumflextilde */
    {0x1eab, 0x1eab}, /* acircumflextilde */
    {0x1eac, 0x1eac}, /* Acircumflexbelowdot */
    {0x1ead, 0x1ead}, /* acircumflexbelowdot */
    {0x1eae, 0x1eae}, /* Abreveacute */
    {0x1eaf, 0x1eaf}, /* abreveacute */
    {0x1eb0, 0x1eb0}, /* Abrevegrave */
    {0x1eb1, 0x1eb1}, /* abrevegrave */
    {0x1eb2, 0x1eb2}, /* Abrevehook */
    {0x1eb3, 0x1eb3}, /* abrevehook */
    {0x1eb4, 0x1eb4}, /* Abrevetilde */
    {0x1eb5, 0x1eb5}, /* abrevetilde */
    {0x1eb6, 0x1eb6}, /* Abrevebelowdot */
    {0x1eb7, 0x1eb7}, /* abrevebelowdot */
    {0x1eb8, 0x1eb8}, /* Ebelowdot */
    {0x1eb9, 0x1eb9}, /* ebelowdot */
    {0x1eba, 0x1eba}, /* Ehook */
    {0x1ebb, 0x1ebb}, /* ehook */
    {0x1ebc, 0x1ebc}, /* Etilde */
    {0x1ebd, 0x1ebd}, /* etilde */
    {0x1ebe, 0x1ebe}, /* Ecircumflexacute */
    {0x1ebf, 0x1ebf}, /* ecircumflexacute */
    {0x1ec0, 0x1ec0}, /* Ecircumflexgrave */
    {0x1ec1, 0x1ec1}, /* ecircumflexgrave */
    {0x1ec2, 0x1ec2}, /* Ecircumflexhook */
    {0x1ec3, 0x1ec3}, /* ecircumflexhook */
    {0x1ec4, 0x1ec4}, /* Ecircumflextilde */
    {0x1ec5, 0x1ec5}, /* ecircumflextilde */
    {0x1ec6, 0x1ec6}, /* Ecircumflexbelowdot */
    {0x1ec7, 0x1ec7}, /* ecircumflexbelowdot */
    {0x1ec8, 0x1ec8}, /* Ihook */
    {0x1ec9, 0x1ec9}, /* ihook */
    {0x1eca, 0x1eca}, /* Ibelowdot */
    {0x1ecb, 0x1ecb}, /* ibelowdot */
    {0x1ecc, 0x1ecc}, /* Obelowdot */
    {0x1ecd, 0x1ecd}, /* obelowdot */
    {0x1ece, 0x1ece}, /* Ohook */
    {0x1ecf, 0x1ecf}, /* ohook */
    {0x1ed0, 0x1ed0}, /* Ocircumflexacute */
    {0x1ed1, 0x1ed1}, /* ocircumflexacute */
    {0x1ed2, 0x1ed2}, /* Ocircumflexgrave */
    {0x1ed3, 0x1ed3}, /* ocircumflexgrave */
    {0x1ed4, 0x1ed4}, /* Ocircumflexhook */
    {0x1ed5, 0x1ed5}, /* ocircumflexhook */
    {0x1ed6, 0x1ed6}, /* Ocircumflextilde */
    {0x1ed7, 0x1ed7}, /* ocircumflextilde */
    {0x1ed8, 0x1ed8}, /* Ocircumflexbelowdot */
    {0x1ed9, 0x1ed9}, /* ocircumflexbelowdot */
    {0x1eda, 0x1eda}, /* Ohornacute */
    {0x1edb, 0x1edb}, /* ohornacute */
    {0x1edc, 0x1edc}, /* Ohorngrave */
    {0x1edd, 0x1edd}, /* ohorngrave */
    {0x1ede, 0x1ede}, /* Ohornhook */
    {0x1edf, 0x1edf}, /* ohornhook */
    {0x1ee0, 0x1ee0}, /* Ohorntilde */
    {0x1ee1, 0x1ee1}, /* ohorntilde */
    {0x1ee2, 0x1ee2}, /* Ohornbelowdot */
    {0x1ee3, 0x1ee3}, /* ohornbelowdot */
    {0x1ee4, 0x1ee4}, /* Ubelowdot */
    {0x1ee5, 0x1ee5}, /* ubelowdot */
    {0x1ee6, 0x1ee6}, /* Uhook */
    {0x1ee7, 0x1ee7}, /* uhook */
    {0x1ee8, 0x1ee8}, /* Uhornacute */
    {0x1ee9, 0x1ee9}, /* uhornacute */
    {0x1eea, 0x1eea}, /* Uhorngrave */
    {0x1eeb, 0x1eeb}, /* uhorngrave */
    {0x1eec, 0x1eec}, /* Uhornhook */
    {0x1eed, 0x1eed}, /* uhornhook */
    {0x1eee, 0x1eee}, /* Uhorntilde */
    {0x1eef, 0x1eef}, /* uhorntilde */
    {0x1ef0, 0x1ef0}, /* Uhornbelowdot */
    {0x1ef1, 0x1ef1}, /* uhornbelowdot */
    {0x1ef4, 0x1ef4}, /* Ybelowdot */
    {0x1ef5, 0x1ef5}, /* ybelowdot */
    {0x1ef6, 0x1ef6}, /* Yhook */
    {0x1ef7, 0x1ef7}, /* yhook */
    {0x1ef8, 0x1ef8}, /* Ytilde */
    {0x1ef9, 0x1ef9}, /* ytilde */
    {0x1efa, 0x01a0}, /* Ohorn */
    {0x1efb, 0x01a1}, /* ohorn */
    {0x1efc, 0x01af}, /* Uhorn */
    {0x1efd, 0x01b0}, /* uhorn */
    {0, 0}
};

#endif

Changes to macosx/tkMacOSXMenu.c.

1
2
3
4
5
6
7
8
9




10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44

45
46
47
48
49
50
51


52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67

68
69
70
71
72
73
74
1
2
3
4
5




6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42

43
44
45
46
47
48


49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65

66
67
68
69
70
71
72
73





-
-
-
-
+
+
+
+












-
















-
+




-
+





-
-
+
+









-
+





-
+







/*
 * tkMacOSXMenu.c --
 *
 *	This module implements the Mac-platform specific features of menus.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2012 Adrian Robert.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2012 Adrian Robert.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMenubutton.h"
#include "tkMenu.h"
#include "tkColor.h"
#include "tkFont.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXConstants.h"

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_MENUS
#endif
*/

#define ENTRY_HELP_MENU		ENTRY_PLATFORM_FLAG1
#define ENTRY_APPLE_MENU	ENTRY_PLATFORM_FLAG2
#define ENTRY_WINDOWS_MENU	ENTRY_PLATFORM_FLAG3

#define sl(s) ((int) (sizeof(s "") - 1))

#define SPECIALMENU(n, f) {.name = "." #n, .len = sl(#n) + 1, \
	.flag = ENTRY_##f##_MENU }
static const struct {
    const char *name; size_t len; int flag;
    const char *name; const size_t len; const int flag;
} specialMenus[] = {
    SPECIALMENU(help,	HELP),
    SPECIALMENU(apple,	APPLE),
    SPECIALMENU(window,	WINDOWS),
    {NULL, 0, 0}
    {NULL}
};
#undef SPECIALMENU

#define MODIFIER(n, f) {.name = #n, .len = sl(#n), .mask = f }
static const struct {
    const char *name; size_t len; NSUInteger mask;
} allModifiers[] = {
    const char *name; const size_t len; const NSUInteger mask;
} modifiers[] = {
    MODIFIER(Control,	NSControlKeyMask),
    MODIFIER(Ctrl,	NSControlKeyMask),
    MODIFIER(Option,	NSAlternateKeyMask),
    MODIFIER(Opt,	NSAlternateKeyMask),
    MODIFIER(Alt,	NSAlternateKeyMask),
    MODIFIER(Shift,	NSShiftKeyMask),
    MODIFIER(Command,	NSCommandKeyMask),
    MODIFIER(Cmd,	NSCommandKeyMask),
    MODIFIER(Meta,	NSCommandKeyMask),
    {NULL, 0, 0}
    {NULL}
};
#undef MODIFIER

#define ACCEL(n, c) {.name = #n, .len = sl(#n), .ch = c }
static const struct {
    const char *name; size_t len; UniChar ch;
    const char *name; const size_t len; const UniChar ch;
} specialAccelerators[] = {
    ACCEL(PageUp,	NSPageUpFunctionKey),
    ACCEL(PageDown,	NSPageDownFunctionKey),
    ACCEL(Left,		NSLeftArrowFunctionKey),
    ACCEL(Right,	NSRightArrowFunctionKey),
    ACCEL(Up,		NSUpArrowFunctionKey),
    ACCEL(Down,		NSDownArrowFunctionKey),
82
83
84
85
86
87
88
89

90
91
92
93



94


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179








180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250


251
252
253
254
255
256
257
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109




























































110
111





112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136







































137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155


156
157
158
159
160
161
162
163
164







-
+




+
+
+
-
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-



-
+


+
+
+
+
+
+
+
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
-
+
+







    ACCEL(Delete,	NSDeleteCharacter),
    ACCEL(Home,		NSHomeFunctionKey),
    ACCEL(End,		NSEndFunctionKey),
    ACCEL(Return,	NSCarriageReturnCharacter),
    ACCEL(Help,		NSHelpFunctionKey),
    ACCEL(Power,	0x233d),
    ACCEL(Eject,	0xf804),
    {NULL, 0, 0}
    {NULL}
};
#undef ACCEL
#undef sl

static int gNoTkMenus = 0;	/* This is used by Tk_MacOSXTurnOffMenus as
				 * the flag that Tk is not to draw any
				 * menus. */
static Bool   inPostMenu = false;
static int inPostMenu = 0;
static unsigned long defaultBg = 0, defaultFg = 0;
static SInt32 menuMarkColumnWidth = 0, menuIconTrailingEdgeMargin = 0;
static SInt32 menuTextLeadingEdgeMargin = 0, menuTextTrailingEdgeMargin = 0;
static SInt16 menuItemExtraHeight = 0, menuItemExtraWidth = 0;
static SInt16 menuSeparatorHeight = 0;

static void	CheckForSpecialMenu(TkMenu *menuPtr);
static NSString *ParseAccelerator(const char *accel, NSUInteger *maskPtr);
static int	GenerateMenuSelectEvent(TKMenu *menu, NSMenuItem *menuItem);
static void	MenuSelectEvent(TkMenu *menuPtr);
static void	RecursivelyClearActiveMenu(TkMenu *menuPtr);
static int	ModifierCharWidth(Tk_Font tkfont);

#pragma mark TkBackgroundLoop

/*
 * The function TkMacOSXEventsCheckProc (in tkMacOSXNotify.c) is the "check
 * proc" for the macOS event source.  Its job is to remove NSEvents from the
 * default event queue of the NSApplication.  It does this by calling the
 * method [NSApp nextEventMatchingMask: untilDate: inMode: dequeue:]. As a
 * rule, when the untilDate is set to the distant past this method returns
 * immediately.  An exception to that rule is when the next event is the button
 * press on a menu button.  In that case, the method starts running a nested
 * event loop in the mode NSEventTrackingRunLoopMode which does not return
 * until the menu has been dismissed.  In Tk 8.6.10 and earlier, this meant
 * that the Tk event loop would block in its call to the check proc as long as
 * the menu was posted.  For example, opening a menu during the Rube Goldberg
 * demo would cause the animation to stop.  This was also the case for
 * menubuttons.
 *
 * The TKBackgroundLoop object below works around this problem, and allows a Tk
 * event loop to run while a menu is open.  It is a subclass of NSThread which
 * inserts requests to call [NSApp _runBackgroundLoop] onto the queue
 * associated with the NSEventTrackingRunLoopMode.  One of these threads gets
 * started in the callback [NSApp menuBeginTracking] and cancelled in [NSApp
 * menuEndTracking].
 */

@interface TKBackgroundLoop: NSThread
@end

@implementation TKBackgroundLoop
- (void) main
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    NSArray *modeArray = [NSArray arrayWithObjects: NSEventTrackingRunLoopMode,
				  nil];
    while(1) {

	/*
	 * Queue a request to process Tk events during event tracking.
	 */

	[NSApp performSelectorOnMainThread:@selector(_runBackgroundLoop)
				withObject:nil
			     waitUntilDone:true
				     modes:modeArray];
	if ([self isCancelled]) {
	    [NSThread exit];
	}

	/*
	 * Allow the tracked events to be processed too.
	 */

	[NSThread sleepForTimeInterval:0.001];
    }
    [pool drain];
}
@end

TKBackgroundLoop *backgroundLoop = nil;

#pragma mark TKMenu

/*
 * This interface is not declared in tkMacOSXPrivate.h because it requires
 * tkMenu.h.
 */

@interface TKMenu(TKMenuPrivate)
- (id) initWithTkMenu: (TkMenu *) tkMenu;
- (TkMenu *) tkMenu;
- (Tcl_Size) tkIndexOfItem: (NSMenuItem *) menuItem;
- (int) tkIndexOfItem: (NSMenuItem *) menuItem;
- (void) insertItem: (NSMenuItem *) newItem atTkIndex: (NSInteger) index;
@end

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
#define TKMenu_NSMenuDelegate <NSMenuDelegate>
#else
#define TKMenu_NSMenuDelegate
#endif
@interface TKMenu(TKMenuDelegate) TKMenu_NSMenuDelegate
@end

@implementation TKMenu
- (void) setSpecial: (NSUInteger) special
{
    NSAssert(!_tkSpecial, @"Cannot change specialness of a special menu");
    _tkSpecial = special;
}
- (BOOL) isSpecial: (NSUInteger) special
{
    return (_tkSpecial == special);
}

/*
 * There are cases where a KeyEquivalent (aka menu accelerator) is defined for
 * a "dead key", i.e. a key which does not have an associated character but is
 * only meant to be the start of a composition sequence.  For example, on a
 * Spanish keyboard both the ' and the ` keys are dead keys used to place
 * accents over letters.  But ⌘` is a standard KeyEquivalent which cycles
 * through the open windows of an application, changing the focus to the next
 * window. This caused a bug reported in [1626ed65b8].  When a dead key that is
 * also as a KeyEquivalent is pressed, a KeyDown event with no characters would
 * be passed to performKeyEquivalent.  The default implementation provided by
 * Apple would cause that event to be routed to some private methods of NSMenu
 * which raise NSInvalidArgumentException, causing an abort. Returning NO in
 * such a case prevents the abort.  So the override below returns NO when the
 * event has no characters.
 *
 * In fact, however, we never want to handle accelerators because they are
 * handled by Tk.  Hence this method could always return NO.  But if we did
 * that then we would not see the menu flash when an accelerator is pressed.
 * The flash is a useful visual indicator. It turns out that the flash is an
 * undocumented side effect of calling the super method for
 * performKeyEquivalent.  The super method also calls the NSMenuItem's action
 * method - tkMenuItemInvoke in our case.  This is also not documented.
 *
 * To enable the flash we set up a flag that tells the action method to do
 * nothing, because it is being called by an accelerator. The override below
 * sets the flag and then calls super. See ticket [ead70921a9].
 */

static Bool runMenuCommand = true;
- (BOOL)performKeyEquivalent:(NSEvent *)event
{
    if ([[event characters] length] == 0) {
	return NO;
    }
    runMenuCommand = false;
    /* Make the menu flash and call tkMenuItemInvoke. */
    return [super performKeyEquivalent: event];
}
@end

@implementation TKMenu(TKMenuPrivate)

- (id) initWithTitle: (NSString *) aTitle
{
    self = [super initWithTitle:aTitle];
    if (self) {
	_tkMenu = NULL;
	_tkOffset = 0;
	_tkItemCount = 0;
	_tkSpecial = 0;
	[self setDelegate:self];
    }
    return self;
}

- (id) initWithTkMenu: (TkMenu *) tkMenu
{
    NSString *title = [[TKNSString alloc] initWithTclUtfBytes:
	    Tk_PathName(tkMenu->tkwin) length:TCL_INDEX_NONE];
    NSString *title = [[NSString alloc] initWithUTF8String:
	    Tk_PathName(tkMenu->tkwin)];

    self = [self initWithTitle:title];
    [title release];
    if (self) {
	_tkMenu = tkMenu;
    }
    return self;
267
268
269
270
271
272
273
274

275
276
277

278
279

280
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295

296
297
298

299
300
301
302
303
304
305
306
307
308

309
310

311
312
313
314
315
316
317
318
319
320
321
322
323

324
325
326
327
328

329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352

353
354
355
356

357
358


359
360
361
362
363
364



365
366
367




368
369

370

371
372
373
374
375
376
377
378
379
380
381
382
383






384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419


420
421
422
423


424
425
426


427
428
429

430
431
432


433

434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496




497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512

513
514
515
516
517

518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538




539
540
541
542
543
544
545
174
175
176
177
178
179
180

181
182
183

184
185

186




187
188
189
190

191
192
193
194
195
196
197

198
199
200

201
202
203
204
205
206
207
208
209
210

211
212

213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
238


239


240
241
242
243
244
245
246



247




248




249


250
251
252
253
254



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292


293





294
295
296
297
298
299





300













301
302




303
304



305
306
307
308
309
310
311


312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327


328
329
330
331
332
333
334
335
336


337

338
339
340
341
342
343


344
345
346
347
348
349
350
351

352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

381

382
383







384





385

386
387
388
389

390

391
392





393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410







-
+


-
+

-
+
-
-
-
-




-
+






-
+


-
+









-
+

-
+












-
+





+






-
-
+
-
-







-
-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
+
+



-
-
-
+
+
+



+
+
+
+


+

+













+
+
+
+
+
+




-
-
+
-
-
-
-
-






-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
+
+



+

-
-
+
+

+
-
+











-
-









-
-

-
+





-
-








-







-
+












+
+
+
+





-

-
+

-
-
-
-
-
-
-
+
-
-
-
-
-
+
-




-

-
+

-
-
-
-
-







+
+
+
+







    copy->_tkItemCount = _tkItemCount;
    copy->_tkSpecial = _tkSpecial;
    return copy;
}

- (TkMenu *) tkMenu
{
    return (TkMenu *)_tkMenu;
    return _tkMenu;
}

- (Tcl_Size) tkIndexOfItem: (NSMenuItem *) menuItem
- (int) tkIndexOfItem: (NSMenuItem *) menuItem
{
    NSInteger index = [self indexOfItem:menuItem];
    return [self indexOfItem:menuItem] - _tkOffset;
    if (index < 0 || (NSUInteger) index < _tkOffset) {
	return TCL_INDEX_NONE;
    }
    return ((Tcl_Size)index - (Tcl_Size)_tkOffset);
}

- (void) insertItem: (NSMenuItem *) newItem atTkIndex: (NSInteger) index
{
    [super insertItem:newItem atIndex:index + (NSInteger)_tkOffset];
    [super insertItem:newItem atIndex:index + _tkOffset];
    _tkItemCount++;
}

- (void) insertItem: (NSMenuItem *) newItem atIndex: (NSInteger) index
{
    if (_tkMenu && index >= 0) {
	if ((NSUInteger) index <= _tkOffset) {
	if ((NSUInteger)index <= _tkOffset) {
	    _tkOffset++;
	} else {
	    NSAssert((NSUInteger) index >= _tkItemCount + _tkOffset,
	    NSAssert((NSUInteger)index >= _tkItemCount + _tkOffset,
		    @"Cannot insert in the middle of Tk menu");
	}
    }
    [super insertItem:newItem atIndex:index];
}

- (void) removeItemAtIndex: (NSInteger) index
{
    if (_tkMenu && index >= 0) {
	if ((NSUInteger) index < _tkOffset) {
	if ((NSUInteger)index < _tkOffset) {
	    _tkOffset--;
	} else if ((NSUInteger) index < _tkItemCount + _tkOffset) {
	} else if ((NSUInteger)index < _tkItemCount + _tkOffset) {
	    _tkItemCount--;
	}
    }
    [super removeItemAtIndex:index];
}

- (NSMenuItem *) newTkMenuItem: (TkMenuEntry *) mePtr
{
    NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@""
	    action:@selector(tkMenuItemInvoke:) keyEquivalent:@""];

    [menuItem setTarget:self];
    [menuItem setTag:(NSInteger) mePtr];
    [menuItem setTag:(NSInteger)mePtr];
    return menuItem;
}
@end

@implementation TKMenu(TKMenuActions)
// target methods

- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
{
    return [menuItem isEnabled];
}

/*
 * Workaround for bug 3572016; leave menu items enabled during modal dialog.
// Workaround for bug 3572016; leaves menu items enabled during modal dialog.
 */

- (BOOL)worksWhenModal
{
    return YES;
}

- (void) tkMenuItemInvoke: (id) sender
{
    if (!runMenuCommand) {

    	/*
    /*
    	 * We are being called for a menu accelerator.  Tk will handle it.
    	 * Just update the runMenuCommand flag.
    	 */

     * With the delegate matching key equivalents, when a menu action is sent
    	runMenuCommand = true;
    	return;
    }

     * in response to a key equivalent, sender is the whole menu and not the
    /*
     * We are being called for an actual menu item selection; run the command.
     * the specific menu item, use this to ignore key equivalents for our
     * menus (as Tk handles them directly via bindings).
     */

    if ([sender isKindOfClass:[NSMenuItem class]]) {
	NSMenuItem *menuItem = (NSMenuItem *) sender;
	TkMenu *menuPtr = (TkMenu *) _tkMenu;
	TkMenuEntry *mePtr = (TkMenuEntry *) [menuItem tag];
	NSMenuItem *menuItem = (NSMenuItem *)sender;
	TkMenu *menuPtr = (TkMenu *)_tkMenu;
	TkMenuEntry *mePtr = (TkMenuEntry *)[menuItem tag];

	if (menuPtr && mePtr) {
	    Tcl_Interp *interp = menuPtr->interp;
	    /*Add time for errors to fire if necessary. This is sub-optimal
	     *but avoids issues with Tcl/Cocoa event loop integration.
	     */
	    Tcl_Sleep(100);
	    Tcl_Preserve(interp);
	    Tcl_Preserve(menuPtr);

	    int result = TkInvokeMenu(interp, menuPtr, mePtr->index);

	    if (result != TCL_OK && result != TCL_CONTINUE &&
		    result != TCL_BREAK) {
		Tcl_AddErrorInfo(interp, "\n    (menu invoke)");
		Tcl_BackgroundException(interp, result);
	    }
	    Tcl_Release(menuPtr);
	    Tcl_Release(interp);
	}
    }
}
@end

@implementation TKMenu(TKMenuDelegate)
#define keyEquivModifiersMatch(km, m) (( \
    ((km) & NSCommandKeyMask) != ((m) & NSCommandKeyMask) || \
    ((km) & NSAlternateKeyMask) != ((m) & NSAlternateKeyMask) || \
    ((km) & NSControlKeyMask) != ((m) & NSControlKeyMask) || \
    (((km) & NSShiftKeyMask) != ((m) & NSShiftKeyMask) && \
    ((m) & NSFunctionKeyMask))) ? NO : YES)

- (BOOL) menuHasKeyEquivalent: (NSMenu *) menu forEvent: (NSEvent *) event
	target: (id *) target action: (SEL *) action
{
    (void)menu;

    /*Use lowercaseString to keep "shift" from firing twice if bound to different procedure.*/
    /*
     * Use lowercaseString when comparing keyEquivalents since the notion of
     * a shifted upper case letter does not make much sense.
     */

    NSString *key = [[event charactersIgnoringModifiers] lowercaseString];
    NSUInteger modifiers = [event modifierFlags] &
	    NSDeviceIndependentModifierFlagsMask;

    if (modifiers == (NSCommandKeyMask | NSShiftKeyMask) &&
	    [key compare:@"?"] == NSOrderedSame) {
	/*
	 * Command-Shift-? has not been allowed as a keyboard equivalent since
	 * the first aqua port, for some mysterious reason.
	 */

	return NO;
    } else if (modifiers == (NSControlKeyMask | NSShiftKeyMask) &&
	    [event keyCode] == 48) {
	/*
	 * Starting with OSX 10.12 Control-Tab and Control-Shift-Tab are used
	 * to select window tabs.  But for some even more mysterious reason the
	 * Control-Shift-Tab event has character 0x19 = NSBackTabCharacter
	 * rather than 0x09 = NSTabCharacter.  At the same time, the
	 * keyEquivalent must be \0x09 in order for it to be displayed
	 * correctly in the menu. This makes it impossible for the standard
	 * "Select Previous Tab" to work correctly, unless we intervene.
	 */

	key = @"\t";
    }

    } else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) {
	/*
	 * If the command modifier is set, use the full character string so
	 * things like the dvorak / qwerty layout will work.
    // For command key, take input manager's word so things
    // like dvorak / qwerty layout work.
	 */

	key = [event characters];
    if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) {
      key = [event characters];
    }

    NSArray *itemArray = [self itemArray];

    for (NSMenuItem *item in itemArray) {
	if ([item isEnabled] &&
	    [[item keyEquivalent] compare:key] == NSOrderedSame) {
	if ([item isEnabled] && [[item keyEquivalent] compare:key] ==
		NSOrderedSame) {
	    NSUInteger keyEquivModifiers = [item keyEquivalentModifierMask];

	    if (keyEquivModifiers == modifiers) {
	    if (keyEquivModifiersMatch(keyEquivModifiers, modifiers)) {
		*target = [item target];
		*action = [item action];
		return YES;
	    }
	}
    }
    return NO;
}

- (void) menuWillOpen: (NSMenu *) menu
{
    (void)menu;

    if (_tkMenu) {
	//RecursivelyClearActiveMenu(_tkMenu);
	GenerateMenuSelectEvent((TKMenu *)[self supermenu],
		[self itemInSupermenu]);
    }
}

- (void) menuDidClose: (NSMenu *) menu
{
    (void)menu;

    if (_tkMenu) {
	RecursivelyClearActiveMenu((TkMenu *)_tkMenu);
	RecursivelyClearActiveMenu(_tkMenu);
    }
}

- (void) menu: (NSMenu *) menu willHighlightItem: (NSMenuItem *) item
{
    (void)menu;

    if (_tkMenu) {
	GenerateMenuSelectEvent(self, item);
    }
}

- (void) menuNeedsUpdate: (NSMenu *) menu
{
    TkMenu *menuPtr = (TkMenu *) _tkMenu;
    (void)menu;

    if (menuPtr) {
	Tcl_Interp *interp = menuPtr->interp;

	Tcl_Preserve(interp);
	Tcl_Preserve(menuPtr);

	int result = TkPostCommand(menuPtr);
	int result = TkPostCommand(_tkMenu);

	if (result!=TCL_OK && result!=TCL_CONTINUE && result!=TCL_BREAK) {
	      Tcl_AddErrorInfo(interp, "\n    (menu preprocess)");
	      Tcl_BackgroundException(interp, result);
	}
	Tcl_Release(menuPtr);
	Tcl_Release(interp);
    }
}
@end

#pragma mark TKApplication(TKMenu)

@interface NSApplication(TKMenu)
- (void) setAppleMenu: (NSMenu *) menu;
@end

@implementation TKApplication(TKMenu)

- (void) menuBeginTracking: (NSNotification *) notification
{
    (void)notification;
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    if (backgroundLoop) {
	[backgroundLoop cancel];
	[backgroundLoop release];
    }
    backgroundLoop = [[TKBackgroundLoop alloc] init];
    [backgroundLoop start];

    //TkMacOSXClearMenubarActive();
    /*
     * Make sure that we can run commands when actually using a menu.
     * See [412b80fcaf].
     */

    //TkMacOSXPreprocessMenu();
    runMenuCommand = true;
}

- (void) menuEndTracking: (NSNotification *) notification
{
    (void)notification;
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    if (backgroundLoop) {
	[backgroundLoop cancel];
	[backgroundLoop release];
	backgroundLoop = nil;
    }
    if (!inPostMenu) {
	TkMacOSXClearMenubarActive();
    }
}

- (void) tkSetMainMenu: (TKMenu *) menu
{
    if (gNoTkMenus) {
	return;
    }

    TKMenu *applicationMenu = nil;

    if (menu) {
	NSMenuItem *applicationMenuItem = [menu numberOfItems] ?
		[menu itemAtIndex:0] : nil;

	if (![menu isSpecial:tkMainMenu]) {
727
728
729
730
731
732
733

734
735
736
737


738
739
740
741
742
743
744
745
746
747
748
749

750
751

752
753
754
755
756
757

758
759
760
761
762
763
764
765
766


767
768
769
770
771
772
773
774

775
776

777
778
779
780
781
782
783


784
785
786
787
788
789
790
791
792
793
794
795
796
797


798
799
800


801
802
803
804
805
806





807
808
809


810
811

812
813

814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839

840
841
842
843
844
845
846
847
848
849
850
851
852
853



854
855
856
857
858
859




860
861
862






863

864
865
866
867
868
869
870
592
593
594
595
596
597
598
599
600
601


602
603








604
605
606

607
608

609
610
611
612
613
614

615
616

617
618
619
620



621
622
623
624
625
626
627
628
629

630


631







632
633














634
635



636
637






638
639
640
641
642



643
644


645


646


647


648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676
677
678





679
680
681






682
683
684
685



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700







+


-
-
+
+
-
-
-
-
-
-
-
-



-
+

-
+





-
+

-




-
-
-
+
+







-
+
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
+
-
-
+
-
-

-
-
+




















-
+









-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+

+







    NSMenuItem *menuItem = (NSMenuItem *) mePtr->platformEntryData;
    NSString *title = @"";
    NSAttributedString *attributedTitle = nil;
    NSImage *image = nil;
    NSString *keyEquivalent = @"";
    NSUInteger modifierMask = NSCommandKeyMask;
    NSMenu *submenu = nil;
    NSDictionary *attributes;
    int imageWidth, imageHeight;
    GC gc = (mePtr->textGC ? mePtr->textGC : mePtr->menuPtr->textGC);
    Tcl_Obj *fontPtr = (mePtr->fontPtr ?
			mePtr->fontPtr : mePtr->menuPtr->fontPtr);
    Tcl_Obj *fontPtr = (mePtr->fontPtr ? mePtr->fontPtr :
	    mePtr->menuPtr->fontPtr);
    static int initialized = 0;

    if (!initialized) {
	TkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_BG_COLOR);
	ckfree(tkColPtr);
	tkColPtr = TkpGetColor(NULL, DEF_MENU_FG);
	ckfree(tkColPtr);
    }

    if (mePtr->image) {
    	Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight);
	image = TkMacOSXGetNSImageFromTkImage(mePtr->menuPtr->display,
	image = TkMacOSXGetNSImageWithTkImage(mePtr->menuPtr->display,
		mePtr->image, imageWidth, imageHeight);
    } else if (mePtr->bitmapPtr != NULL) {
    } else if (mePtr->bitmapPtr != None) {
	Pixmap bitmap = Tk_GetBitmapFromObj(mePtr->menuPtr->tkwin,
		mePtr->bitmapPtr);

	Tk_SizeOfBitmap(mePtr->menuPtr->display, bitmap, &imageWidth,
		&imageHeight);
	image = TkMacOSXGetNSImageFromBitmap(mePtr->menuPtr->display, bitmap,
	image = TkMacOSXGetNSImageWithBitmap(mePtr->menuPtr->display, bitmap,
		gc, imageWidth, imageHeight);
	[image setTemplate:YES];
    }
    [menuItem setImage:image];
    if ((!image || mePtr->compound != COMPOUND_NONE) && mePtr->labelPtr &&
	    mePtr->labelLength) {
	title = [[[TKNSString alloc]
		    initWithTclUtfBytes:Tcl_GetString(mePtr->labelPtr)
				length:mePtr->labelLength]
	title = [[[NSString alloc] initWithBytes:Tcl_GetString(mePtr->labelPtr)
		length:mePtr->labelLength encoding:NSUTF8StringEncoding]
		autorelease];
	if ([title hasSuffix:@"..."]) {
	    title = [NSString stringWithFormat:@"%@%C",
		    [title substringToIndex:[title length] - 3], 0x2026];
	}
    }
    [menuItem setTitle:title];

    if (strcmp(Tcl_GetString(fontPtr), "menu") || gc->foreground != defaultFg
#if 0

	    || gc->background != defaultBg) {
    /*
     * The -background and -foreground options are now ignored in Aqua.
     * See ticket [635167af14].
     */

    NSDictionary fontAttributes = TkMacOSXNSFontAttributesForFont(
	Tk_GetFontFromObj(mePtr->menuPtr->tkwin, fontPtr));
	attributes = TkMacOSXNSFontAttributesForFont(Tk_GetFontFromObj(
		mePtr->menuPtr->tkwin, fontPtr));
    NSMutableDictionary *attributes = [fontAttributes mutableCopy];
    static unsigned long defaultBg = 0, defaultFg = 0;
    if (defaultBg == 0) {
	tkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_BG_COLOR);
	defaultBg = tkColPtr->color.pixel;
	ckfree(tkColPtr);
    }
    if (defaultFg == 0) {
	tkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_FG);
	defaultFg = tkColPtr->color.pixel;
	ckfree(tkColPtr);
    }
    if (gc->foreground != defaultFg) {
	NSColor *fgcolor = TkMacOSXGetNSColor(gc, gc->foreground);
	if (gc->foreground != defaultFg || gc->background != defaultBg) {
	    NSColor *color = TkMacOSXGetNSColor(gc,
	[attributes setObject:fgcolor
		       forKey:NSForegroundColorAttributeName];
    }
		    gc->foreground!=defaultFg? gc->foreground:gc->background);

    if (gc->background != defaultBg) {
	NSColor *bgcolor = TkMacOSXGetNSColor(gc, gc->background);
	[attributes setObject:bgcolor
	 	       forKey:NSBackgroundColorAttributeName];
    }

	    attributes = [[attributes mutableCopy] autorelease];
	    [(NSMutableDictionary *)attributes setObject:color
		    forKey:NSForegroundColorAttributeName];
	}
	if (attributes) {
#else

    NSDictionary *attributes = TkMacOSXNSFontAttributesForFont(
	    attributedTitle = [[[NSAttributedString alloc]
		    initWithString:title attributes:attributes] autorelease];
	Tk_GetFontFromObj(mePtr->menuPtr->tkwin, fontPtr));

	}
#endif

    }
    attributedTitle = [[NSAttributedString alloc] initWithString:title
	attributes:attributes];
    [menuItem setAttributedTitle:attributedTitle];
    [attributedTitle release];
    [menuItem setEnabled:(mePtr->state != ENTRY_DISABLED)];
    [menuItem setEnabled:!(mePtr->state == ENTRY_DISABLED)];
    [menuItem setState:((mePtr->type == CHECK_BUTTON_ENTRY ||
	    mePtr->type == RADIO_BUTTON_ENTRY) && mePtr->indicatorOn &&
	    (mePtr->entryFlags & ENTRY_SELECTED) ? NSOnState : NSOffState)];
    if (mePtr->type != CASCADE_ENTRY && mePtr->accelPtr && mePtr->accelLength) {
	keyEquivalent = ParseAccelerator(Tcl_GetString(mePtr->accelPtr),
		&modifierMask);
    }
    [menuItem setKeyEquivalent:keyEquivalent];
    [menuItem setKeyEquivalentModifierMask:modifierMask];
    if (mePtr->type == CASCADE_ENTRY && mePtr->namePtr) {
	TkMenuReferences *menuRefPtr;

	menuRefPtr = TkFindMenuReferencesObj(mePtr->menuPtr->interp,
		mePtr->namePtr);
	if (menuRefPtr && menuRefPtr->menuPtr) {
	    CheckForSpecialMenu(menuRefPtr->menuPtr);
	    submenu = (TKMenu *) menuRefPtr->menuPtr->platformData;
	    if ([submenu supermenu] && [menuItem submenu] != submenu) {
		/*
		 * This happens during a clone, where the parent menu is
		 * cloned before its children, so just ignore this temporary
		 * cloned before its children, so just ignore this temprary
		 * setting, it will be changed shortly (c.f. tkMenu.c
		 * CloneMenu())
		 */

		submenu = nil;
	    } else {
		[submenu setTitle:title];

    		if ([menuItem isEnabled]) {

		    /*
		     * This menuItem might have been previously disabled which
		     * would have disabled all of its entries; we must re-enable the
		     * entries here.  It is important to iterate though the Tk
		  /* This menuItem might have been previously disabled (XXX:
		     track this), which would have disabled entries; we must
		     re-enable the entries here. */
		     * entries, not the NSMenuItems, since some NSMenuItems may
		     * have been added by the system.  See [7185d26cf4].
		     */

		    for (Tcl_Size i = 0; i < menuRefPtr->menuPtr->numEntries; i++) {
			TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i];
		  int i = 0;
		  NSArray *itemArray = [submenu itemArray];
		  for (NSMenuItem *item in itemArray) {
		    TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i];
			NSMenuItem *item = (NSMenuItem *) submePtr->platformEntryData;
			[item setEnabled:(submePtr->state != ENTRY_DISABLED)];
		    }
		    /* Work around an apparent bug where itemArray can have
                      more items than the menu's entries[] array. */
                    if (i >= menuRefPtr->menuPtr->numEntries) break;
		    [item setEnabled: !(submePtr->state == ENTRY_DISABLED)];
		    i++;
		  }
		}

	    }
	}
    }
    [menuItem setSubmenu:submenu];

    return TCL_OK;
}
889
890
891
892
893
894
895
896

897
898
899
900



901
902
903
904



905
906
907
908
909
910
911
912
913
914
915
916
917

918
919
920
921
922
923

924
925
926
927
928
929
930
931
932
933

934
935
936
937
938




939
940
941
942




943
944

945
946
947
948
949




950
951
952
953
954
955
956
957
958



959
960
961
962



963

964





965
966
967
968
969
970

971
972
973
974
975
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038

1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050

1051
1052
1053
1054

1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066

1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
719
720
721
722
723
724
725

726




727
728
729
730



731
732
733


734
735
736
737
738
739
740
741
742
743

744



745
746

747
748
749
750
751
752
753
754
755
756

757
758




759
760
761
762
763



764
765
766
767


768





769
770
771
772









773
774
775




776
777
778

779
780
781
782
783
784
785
786





787













788




















































789



790







791





792




793





794







795

















796





















797
798
799
800
801
802
803







-
+
-
-
-
-
+
+
+

-
-
-
+
+
+
-
-










-
+
-
-
-


-
+









-
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
-
+

+
+
+
+
+

-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







TkpDestroyMenuEntry(
    TkMenuEntry *mePtr)
{
    NSMenuItem *menuItem;
    TKMenu *menu;
    NSInteger index;

    if (mePtr->platformEntryData) {
    if (mePtr->platformEntryData && mePtr->menuPtr->platformData) {
	menuItem = (NSMenuItem *) mePtr->platformEntryData;
	if (mePtr->menuPtr->platformData) {
	    menu = (TKMenu *) mePtr->menuPtr->platformData;
	    index = [menu indexOfItem:menuItem];
	menu = (TKMenu *) mePtr->menuPtr->platformData;
	menuItem = (NSMenuItem *) mePtr->platformEntryData;
	index = [menu indexOfItem:menuItem];

	    if (index > -1) {
		[menu removeItemAtIndex:index];
	    }
	if (index > -1) {
	    [menu removeItemAtIndex:index];
	}
	}
	[menuItem setTag:(NSInteger) NULL];
	[menuItem release];
	mePtr->platformEntryData = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostMenu --
 *
 *	Posts a menu on the screen. If entry is < 0 then the menu is drawn so
 *	Posts a menu on the screen
 *      its top left corner is located at the point with screen coordinates
 *      (x,y).  Otherwise the top left corner of the specified entry is located
 *      at that point.
 *
 * Results:
 *	Returns a standard Tcl result.
 *	None.
 *
 * Side effects:
 *	The menu is posted and handled.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostMenu(
    TCL_UNUSED(Tcl_Interp *),		/* The interpreter this menu lives in */
    Tcl_Interp *interp,		/* The interpreter this menu lives in */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y,		/* The screen coordinates where the top left
				 * corner of the menu, or of the specified
				 * entry, will be located. */
    Tcl_Size index)
    int x,			/* The global x-coordinate of the top, left-
				 * hand corner of where the menu is supposed
				 * to be posted. */
    int y)			/* The global y-coordinate */
{
    int result;
    Tk_Window realWin = menuPtr->tkwin;
    TkWindow *realWinPtr;


    /* Get the object that holds this Tk Window.*/
    Tk_Window root;
    NSView *realWinView;

    root = Tk_MainWindow(interp);
    while (1) {
	if (realWin == NULL) {
	    return TCL_ERROR;
	}
	/*
    if (root == NULL) {
	return TCL_ERROR;
    }

	 * Fix for bug 07cfc9f03e: use the view for the parent real (non-menu)
	 * toplevel window, rather than always using the root window.
	 * This allows menus to appear on a separate monitor than the root
	 * window, and to use the appearance of their parent real window
	 * rather than the appearance of the root window.
	 */
	realWinPtr = (TkWindow*) realWin;
	realWinView = TkMacOSXGetNSViewForDrawable(realWinPtr->privatePtr);
	if (realWinView != nil) {
    Drawable d = Tk_WindowId(root);
    NSView *rootview = TkMacOSXGetRootControl(d);
    NSWindow *win = [rootview window];
	    break;
	}
	realWin = Tk_Parent(realWin);
    }

    inPostMenu = 1;

    NSWindow *win = [realWinView window];
    int oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE);
    NSView *view = [win contentView];
    NSRect frame = NSMakeRect(x + 9, tkMacOSXZeroScreenHeight - y - 9, 1, 1);

    frame.origin = [view convertPoint:
	    [win convertPointFromScreen:frame.origin] fromView:nil];

    NSMenu *menu = (NSMenu *) menuPtr->platformData;
    NSInteger itemIndex = index;
    NSInteger numItems = [menu numberOfItems];
    NSMenuItem *item = nil;
    NSPoint location = NSMakePoint(x, TkMacOSXZeroScreenHeight() - y);

    NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc]
    inPostMenu = true;
    result = TkPreprocessMenu(menuPtr);
    if (result != TCL_OK) {
        inPostMenu = false;
        return result;
    }
    if (itemIndex >= numItems) {
    	itemIndex = numItems - 1;
    }
    if (itemIndex >= 0) {
	item = [menu itemAtIndex:itemIndex];
    }

	    initTextCell:@"" pullsDown:NO];
    /*
     * The post commands could have deleted the menu, which means we are dead
     * and should go away.
     */

    if (menuPtr->tkwin == NULL) {
    	return TCL_OK;
    }

    [menu popUpMenuPositioningItem:item
			atLocation:[win tkConvertPointFromScreen:location]
			    inView:view];
    inPostMenu = false;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostTearoffMenu --
 *
 *	Tearoff menus are not supported on the Mac.  This placeholder function,
 *      which is simply a copy of the unix function, posts a completely useless
 *      window with a black background on the screen. If entry is < 0 then the
 *      window is positioned so that its top left corner is located at the
 *      point with screen coordinates (x, y).  Otherwise the window position is
 *      offset so that top left corner of the specified entry would be located
 *      at that point, if there actually were a menu.
 *
 *      Mac menus steal all mouse or keyboard input from the application until
 *      the menu is dismissed, with or without a selection, by a mouse or key
 *      event.  Posting a Mac menu in a regression test will cause the test to
 *      halt waiting for user input.  This is why the TkpPostMenu function is
 *      not being used as the placeholder.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A useless window is posted.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostTearoffMenu(
    TCL_UNUSED(Tcl_Interp *),	/* The interpreter this menu lives in */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y, Tcl_Size index)	/* The screen coordinates where the top left
				 * corner of the menu, or of the specified
				 * entry, will be located. */
{

    int vRootX, vRootY, vRootWidth, vRootHeight;
    int result;

    [popUpButtonCell setAltersStateOfSelectedItem:NO];
    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }

    [popUpButtonCell setMenu:menu];
    /*
     * The post commands could have deleted the menu, which means we are dead
     * and should go away.
     */

    [popUpButtonCell selectItem:nil];
    if (menuPtr->tkwin == NULL) {
    	return TCL_OK;
    }

    [popUpButtonCell performClickWithFrame:frame inView:view];
    /*
     * Adjust the menu y position so that the specified entry will be located
     * at the given coordinates.
     */

    [popUpButtonCell release];
    if (index < 0 || index >= menuPtr->numEntries) {
	index = menuPtr->numEntries - 1;
    }
    if (index >= 0) {
	y -= menuPtr->entries[index]->y;
    }

    Tcl_SetServiceMode(oldMode);
    /*
     * Adjust the position of the menu if necessary to keep it visible on the
     * screen. There are two special tricks to make this work right:
     *
     * 1. If a virtual root window manager is being used then the coordinates
     *    are in the virtual root window of menuPtr's parent; since the menu
     *    uses override-redirect mode it will be in the *real* root window for
     *    the screen, so we have to map the coordinates from the virtual root
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.
     */

    inPostMenu = 0;
    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);
    vRootWidth -= Tk_ReqWidth(menuPtr->tkwin);
    if (x > vRootX + vRootWidth) {
	x = vRootX + vRootWidth;
    }
    if (x < vRootX) {
	x = vRootX;
    }
    vRootHeight -= Tk_ReqHeight(menuPtr->tkwin);
    if (y > vRootY + vRootHeight) {
	y = vRootY + vRootHeight;
    }
    if (y < vRootY) {
	y = vRootY;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpSetWindowMenuBar --
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143


1144
1145
1146
1147


1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183



1184
1185
1186

1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223


1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
1246


1247
1248
1249
1250
1251

1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
825
826
827
828
829
830
831

832
833


834
835
836
837


838
839
840
841
842
843
844
845
846
847
848
849
850
851

852
853
854
855
856
857
858

859









860

861
862



863
864
865



866





867

868
869
870
871
872
873
874
875
876
877
878






879
880
881
882
883
884
885
886
887
888
889
890


891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906

907
908
909
910
911
912
913


914
915
916
917
918
919

920
921
922
923
924

925
926
927
928
929
930
931
932







-
+

-
-
+
+


-
-
+
+












-
+






-

-
-
-
-
-
-
-
-
-

-
+

-
-
-
+
+
+
-
-
-
+
-
-
-
-
-
+
-











-
-
-
-
-
-












-
-
+
+














-
+






-
-
+
+




-
+




-
+







	winPtr->wmInfoPtr->menuPtr = menuPtr;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetMainMenubar --
 * TkpSetMainMenubar --
 *
 *	Puts the menu associated with a window into the menubar. Should only be
 *	called when the window is in front.
 *	Puts the menu associated with a window into the menubar. Should only
 *	be called when the window is in front.
 *
 *      This is a no-op on all other platforms.  On OS X it is a no-op when
 *      passed a NULL menuName or a nonexistent menuName, with an exception for
 *      the first call in a new interpreter.  In that special case, passing a
 *      passed a NULL menuName or a nonexistent menuName, with an exception
 *      for the first call in a new interpreter.  In that special case, passing a
 *      NULL menuName installs the default menu.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The menubar may be changed.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetMainMenubar(
TkpSetMainMenubar(
    Tcl_Interp *interp,		/* The interpreter of the application */
    Tk_Window tkwin,		/* The frame we are setting up */
    const char *menuName)	/* The name of the menu to put in front. */
{
    static Tcl_Interp *currentInterp = NULL;
    TKMenu *menu = nil;
    TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * We will be called when an embedded window receives an ActivationNotify
     * event, but we should not change the menubar in that case.
     */

    if (Tk_IsEmbedded(winPtr)) {
	return;
    }

    if (menuName) {
	Tk_Window menubar = NULL;
	TkWindow *winPtr = (TkWindow *) tkwin;

	if (winPtr->wmInfoPtr &&
		winPtr->wmInfoPtr->menuPtr &&
		winPtr->wmInfoPtr->menuPtr->mainMenuPtr) {
	if (winPtr->wmInfoPtr && winPtr->wmInfoPtr->menuPtr &&
		winPtr->wmInfoPtr->menuPtr->masterMenuPtr &&
		winPtr->wmInfoPtr->menuPtr->masterMenuPtr->tkwin &&
	    menubar = winPtr->wmInfoPtr->menuPtr->mainMenuPtr->tkwin;
	}

		!strcmp(menuName, Tk_PathName(
	/*
	 * Attempt to find the NSMenu directly.  If that fails, ask Tk to find
	 * it.
	 */

		winPtr->wmInfoPtr->menuPtr->masterMenuPtr->tkwin))) {
	if (menubar != NULL && strcmp(menuName, Tk_PathName(menubar)) == 0) {
	    menu = (TKMenu *) winPtr->wmInfoPtr->menuPtr->platformData;
	} else {
	    TkMenuReferences *menuRefPtr = TkFindMenuReferences(interp,
		    menuName);

	    if (menuRefPtr && menuRefPtr->menuPtr &&
		    menuRefPtr->menuPtr->platformData) {
		menu = (TKMenu *) menuRefPtr->menuPtr->platformData;
	    }
	}
    }

    /*
     * If we couldn't find a menu, do nothing unless the window belongs to a
     * different application.  In that case, install the default menubar.
     */

    if (menu || interp != currentInterp) {
	[NSApp tkSetMainMenu:menu];
    }
    currentInterp = interp;
}

/*
 *----------------------------------------------------------------------
 *
 * CheckForSpecialMenu --
 *
 *	Given a menu, check to see whether or not it is a cascade in a menubar
 *	with one of the special names ".apple", ".help" or ".window". If it is,
 *	the entry that points to this menu will be marked.
 *	with one of the special names .apple, .help or .window If it is, the
 *	entry that points to this menu will be marked.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Will set entryFlags appropriately.
 *
 *----------------------------------------------------------------------
 */

static void
CheckForSpecialMenu(
    TkMenu *menuPtr)		/* The menu we are checking */
{
    if (!menuPtr->mainMenuPtr->tkwin) {
    if (!menuPtr->masterMenuPtr->tkwin) {
	return;
    }
    for (TkMenuEntry *cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
	    cascadeEntryPtr;
	    cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
	if (cascadeEntryPtr->menuPtr->menuType == MENUBAR
		&& cascadeEntryPtr->menuPtr->mainMenuPtr->tkwin) {
	    TkMenu *mainMenuPtr = cascadeEntryPtr->menuPtr->mainMenuPtr;
		&& cascadeEntryPtr->menuPtr->masterMenuPtr->tkwin) {
	    TkMenu *masterMenuPtr = cascadeEntryPtr->menuPtr->masterMenuPtr;
	    int i = 0;
	    Tcl_DString ds;

	    Tcl_DStringInit(&ds);
	    Tcl_DStringAppend(&ds, Tk_PathName(mainMenuPtr->tkwin), TCL_INDEX_NONE);
	    Tcl_DStringAppend(&ds, Tk_PathName(masterMenuPtr->tkwin), -1);
	    while (specialMenus[i].name) {
		Tcl_DStringAppend(&ds, specialMenus[i].name,
			specialMenus[i].len);
		if (strcmp(Tcl_DStringValue(&ds),
			Tk_PathName(menuPtr->mainMenuPtr->tkwin)) == 0) {
			Tk_PathName(menuPtr->masterMenuPtr->tkwin)) == 0) {
		    cascadeEntryPtr->entryFlags |= specialMenus[i].flag;
		} else {
		    cascadeEntryPtr->entryFlags &= ~specialMenus[i].flag;
		}
		Tcl_DStringSetLength(&ds, Tcl_DStringLength(&ds) -
			specialMenus[i].len);
		i++;
1291
1292
1293
1294
1295
1296
1297
1298
1299


1300
1301

1302
1303

1304
1305
1306
1307
1308
1309

1310
1311
1312
1313
1314
1315
1316
960
961
962
963
964
965
966


967
968
969

970
971

972
973
974
975
976
977

978
979
980
981
982
983
984
985







-
-
+
+

-
+

-
+





-
+







    unichar ch = 0;
    size_t len;
    int i;

    *maskPtr = 0;
    while (1) {
	i = 0;
	while (allModifiers[i].name) {
	    size_t l = allModifiers[i].len;
	while (modifiers[i].name) {
	    int l = modifiers[i].len;

	    if (!strncasecmp(accel, allModifiers[i].name, l) &&
	    if (!strncasecmp(accel, modifiers[i].name, l) &&
		    (accel[l] == '-' || accel[l] == '+')) {
		*maskPtr |= allModifiers[i].mask;
		*maskPtr |= modifiers[i].mask;
		accel += l+1;
		break;
	    }
	    i++;
	}
	if (!allModifiers[i].name || !*accel) {
	if (!modifiers[i].name || !*accel) {
	    break;
	}
    }
    len = strlen(accel);
    if (len > 1) {
	i = 0;
	if (accel[0] == 'F' && len < 4 && accel[1] > '0' && accel[1] <= '9') {
1335
1336
1337
1338
1339
1340
1341
1342

1343
1344
1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028







-
+









-
+







	    }
	    i++;
	}
    }
    if (ch) {
	return [[[NSString alloc] initWithCharacters:&ch length:1] autorelease];
    } else {
	return [[[[TKNSString alloc] initWithTclUtfBytes:accel length:TCL_INDEX_NONE] autorelease]
	return [[[[NSString alloc] initWithUTF8String:accel] autorelease]
		lowercaseString];
    }
}

/*
 *--------------------------------------------------------------
 *
 * ModifierCharWidth --
 *
 *	Helper measuring width of command char in given font.
 *	Helper mesuring width of command char in given font.
 *
 * Results:
 *	Width of command char.
 *
 * Side effects:
 *	None.
 *
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405

1406

1407
1408

1409
1410
1411
1412
1413
1414
1415

1416
1417
1418
1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1433
1434
1435



1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459
1460

1461
1462


















1463
1464

1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502





1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522

1523
1524
1525
1526
1527
1528
1529
1530
1531

1532
1533
1534
1535



1536
1537
1538

1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558


1559
1560















1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1062
1063
1064
1065
1066
1067
1068

1069

1070
1071
1072

1073

1074
1075

1076
1077
1078





1079
1080
1081
1082

1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1095



1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114



1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178


1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198



1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209

1210
1211



1212
1213
1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233

1234
1235
1236
1237


1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262







-

-
+


-
+
-
+

-
+


-
-
-
-
-
+



-





-
+







-
-
-
+
+
+
















-
-
-


+




+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

















-






-











-
-
+
+
+
+
+















-
-
-


+








-
+

-
-
-
+
+
+


-
+














-


-


+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-







 *--------------------------------------------------------------
 */

void
TkpComputeStandardMenuGeometry(
    TkMenu *menuPtr)		/* Structure describing menu. */
{
    NSSize menuSize;
    Tk_Font tkfont, menuFont;
    Tk_FontMetrics menuMetrics, entryMetrics;
    Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
    int modifierCharWidth, menuModifierCharWidth;
    int x, y, modifierWidth, labelWidth, indicatorSpace;
    int windowWidth, maxWidth, windowHeight, accelWidth;
    int windowWidth, windowHeight, accelWidth;
    Tcl_Size i;
    int i, j, lastColumnBreak, maxWidth;
    int entryWidth, maxIndicatorSpace, borderWidth, activeBorderWidth;
    TkMenuEntry *mePtr;
    TkMenuEntry *mePtr, *columnEntryPtr;
    int haveAccel = 0;

    /*
     * Do nothing if this menu is a clone.
     */

    if (menuPtr->tkwin == NULL || menuPtr->mainMenuPtr != menuPtr) {
    if (menuPtr->tkwin == NULL) {
	return;
    }

    menuSize = [(NSMenu *) menuPtr->platformData size];
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
	    &borderWidth);
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
	    &activeBorderWidth);
    x = y = borderWidth;
    windowHeight = maxWidth = 0;
    windowHeight = maxWidth = lastColumnBreak = 0;
    maxIndicatorSpace = 0;

    /*
     * On the Mac especially, getting font metrics can be quite slow, so we
     * want to do it intelligently. We are going to precalculate them and pass
     * them down to all of the measuring and drawing routines. We will measure
     * the font metrics of the menu once. If an entry does not have its own
     * font set, then we give the geometry/drawing routines the menu's font and
     * metrics. If an entry has its own font, we will measure that font and
     * give all of the geometry/drawing the entry's font and metrics.
     * font set, then we give the geometry/drawing routines the menu's font
     * and metrics. If an entry has its own font, we will measure that font
     * and give all of the geometry/drawing the entry's font and metrics.
     */

    menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
    Tk_GetFontMetrics(menuFont, &menuMetrics);
    menuModifierCharWidth = ModifierCharWidth(menuFont);

    for (i = 0; i < menuPtr->numEntries; i++) {
	mePtr = menuPtr->entries[i];
	if (mePtr->type == CASCADE_ENTRY || mePtr->accelLength > 0) {
	    haveAccel = 1;
	    break;
	}
    }

    for (i = 0; i < menuPtr->numEntries; i++) {
	mePtr = menuPtr->entries[i];
	if (mePtr->type == TEAROFF_ENTRY) {
	    continue;
	}
	if (mePtr->fontPtr == NULL) {
	    tkfont = menuFont;
	    fmPtr = &menuMetrics;
	    modifierCharWidth = menuModifierCharWidth;
	} else {
	    tkfont = Tk_GetFontFromObj(menuPtr->tkwin, mePtr->fontPtr);
	    Tk_GetFontMetrics(tkfont, &entryMetrics);
	    fmPtr = &entryMetrics;
	    modifierCharWidth = ModifierCharWidth(tkfont);
	}

	if ((i > 0) && mePtr->columnBreak) {
	    if (maxIndicatorSpace != 0) {
		maxIndicatorSpace += 2;
	    }
	    for (j = lastColumnBreak; j < i; j++) {
		columnEntryPtr = menuPtr->entries[j];
		columnEntryPtr->indicatorSpace = maxIndicatorSpace;
		columnEntryPtr->width = maxIndicatorSpace + maxWidth
			+ 2 * activeBorderWidth;
		columnEntryPtr->x = x;
		columnEntryPtr->entryFlags &= ~ENTRY_LAST_COLUMN;
	    }
	    x += maxIndicatorSpace + maxWidth + 2 * borderWidth;
	    maxWidth = maxIndicatorSpace = 0;
	    lastColumnBreak = i;
	    y = borderWidth;
	}
	accelWidth = modifierWidth = indicatorSpace = 0;
	if (mePtr->type == SEPARATOR_ENTRY) {
	if (mePtr->type == SEPARATOR_ENTRY || mePtr->type == TEAROFF_ENTRY) {
	    mePtr->height = menuSeparatorHeight;
	} else {
	    /*
	     * For each entry, compute the height required by that particular
	     * entry, plus three widths: the width of the label, the width to
	     * allow for an indicator to be displayed to the left of the label
	     * (if any), and the width of the accelerator to be displayed to
	     * the right of the label (if any). These sizes depend, of course,
	     * on the type of the entry.
	     */

	    NSMenuItem *menuItem = (NSMenuItem *) mePtr->platformEntryData;
	    int haveImage = 0, width = 0, height = 0;

	    if (mePtr->image) {
		Tk_SizeOfImage(mePtr->image, &width, &height);
		haveImage = 1;
		height += 2; /* tweak */
	    } else if (mePtr->bitmapPtr) {
		Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin,
			mePtr->bitmapPtr);

		Tk_SizeOfBitmap(menuPtr->display, bitmap, &width, &height);
		haveImage = 1;
		height += 2; /* tweak */
	    }
	    if (!haveImage || (mePtr->compound != COMPOUND_NONE)) {
		NSAttributedString *attrTitle = [menuItem attributedTitle];
		NSSize size;

		if (attrTitle) {
		    size = [attrTitle size];
		} else {
		    size = [[menuItem title] sizeWithAttributes:
			TkMacOSXNSFontAttributesForFont(tkfont)];
		}
		size.width += menuTextLeadingEdgeMargin + menuTextTrailingEdgeMargin;
		size.height -= 1; /* tweak */
		size.width += menuTextLeadingEdgeMargin +
			menuTextTrailingEdgeMargin;
		if (size.height < fmPtr->linespace) {
		    size.height = fmPtr->linespace;
		}
		if (haveImage && (mePtr->compound != COMPOUND_NONE)) {
		    int margin = width + menuIconTrailingEdgeMargin;

		    if (margin > menuTextLeadingEdgeMargin) {
			margin = menuTextLeadingEdgeMargin;
		    }
		    width += size.width + menuIconTrailingEdgeMargin - margin;
		    if (size.height > height) {
			height = size.height;
		    }
		} else {
		    width = size.width;
		    height = size.height;
		}
	    }
	    else {
		/* image only. */
	    }
	    labelWidth = width + menuItemExtraWidth;
	    mePtr->height = height + menuItemExtraHeight;

	    if (mePtr->type == CASCADE_ENTRY) {
		modifierWidth = modifierCharWidth;
	    } else if (mePtr->accelLength == 0) {
		if (haveAccel && !mePtr->hideMargin) {
		    modifierWidth = modifierCharWidth;
		}
	    } else {
		NSUInteger modifMask = [menuItem keyEquivalentModifierMask];
		int j = 0;
		int i = 0;

		while (allModifiers[j].name) {
		    if (modifMask & allModifiers[j].mask) {
			modifMask &= ~allModifiers[j].mask;
		while (modifiers[i].name) {
		    if (modifMask & modifiers[i].mask) {
			modifMask &= ~modifiers[i].mask;
			modifierWidth += modifierCharWidth;
		    }
		    j++;
		    i++;
		}
		accelWidth = [[menuItem keyEquivalent] sizeWithAttributes:
			TkMacOSXNSFontAttributesForFont(tkfont)].width;
	    }
	    if (!mePtr->hideMargin) {
		indicatorSpace = menuMarkColumnWidth;
	    }
	    if (indicatorSpace > maxIndicatorSpace) {
		maxIndicatorSpace = indicatorSpace;
	    }
	    entryWidth = labelWidth + modifierWidth + accelWidth;
	    if (entryWidth > maxWidth) {
		maxWidth = entryWidth;
	    }
	    menuPtr->entries[i]->width = entryWidth;
	    mePtr->height += 2 * activeBorderWidth;
	}
	mePtr->x = x;
	mePtr->y = y;
	y += menuPtr->entries[i]->height + borderWidth;
	if (y > windowHeight) {
	    windowHeight = y;
    }
    windowWidth = menuSize.width;
	}
    }

    for (j = lastColumnBreak; j < menuPtr->numEntries; j++) {
	columnEntryPtr = menuPtr->entries[j];
	columnEntryPtr->indicatorSpace = maxIndicatorSpace;
	columnEntryPtr->width = maxIndicatorSpace + maxWidth
		+ 2 * activeBorderWidth;
	columnEntryPtr->x = x;
	columnEntryPtr->entryFlags |= ENTRY_LAST_COLUMN;
    }
    windowWidth = x + maxIndicatorSpace + maxWidth
	    + 2 * activeBorderWidth + borderWidth;
    windowHeight += borderWidth;

    if (windowWidth <= 0) {
	windowWidth = 1;
    }
    windowHeight = menuSize.height;
    if (windowHeight <= 0) {
	windowHeight = 1;
    }
    menuPtr->totalWidth = windowWidth;
    menuPtr->totalHeight = windowHeight;
}

1589
1590
1591
1592
1593
1594
1595
1596

1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290

1291
1292
1293
1294
1295
1296
1297
1298







-
+



-
+







GenerateMenuSelectEvent(
    TKMenu *menu,
    NSMenuItem *menuItem)
{
    TkMenu *menuPtr = [menu tkMenu];

    if (menuPtr) {
	Tcl_Size index = [menu tkIndexOfItem:menuItem];
	int index = [menu tkIndexOfItem:menuItem];

	if (index < 0 || index >= menuPtr->numEntries ||
		(menuPtr->entries[index])->state == ENTRY_DISABLED) {
	    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
	    TkActivateMenuEntry(menuPtr, -1);
	} else {
	    TkActivateMenuEntry(menuPtr, index);
	    MenuSelectEvent(menuPtr);
	    return true;
	}
    }
    return false;
1624
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645













1646
1647
1648

1649
1650

1651
1652
1653
1654
1655
1656
1657
1315
1316
1317
1318
1319
1320
1321

1322
1323













1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338

1339
1340

1341
1342
1343
1344
1345
1346
1347
1348







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+

-
+







 *----------------------------------------------------------------------
 */

void
MenuSelectEvent(
    TkMenu *menuPtr)		/* the menu we have selected. */
{
    union {XEvent general; XVirtualEvent virt;} event;
    XVirtualEvent event;

    bzero(&event, sizeof(event));
    event.virt.type = VirtualEvent;
    event.virt.serial = LastKnownRequestProcessed(menuPtr->display);
    event.virt.send_event = false;
    event.virt.display = menuPtr->display;
    event.virt.event = Tk_WindowId(menuPtr->tkwin);
    event.virt.root = XRootWindow(menuPtr->display, 0);
    event.virt.subwindow = None;
    event.virt.time = TkpGetMS();
    XQueryPointer(NULL, None, NULL, NULL, &event.virt.x_root, &event.virt.y_root, NULL,
	    NULL, &event.virt.state);
    event.virt.same_screen = true;
    event.virt.name = Tk_GetUid("MenuSelect");
    bzero(&event, sizeof(XVirtualEvent));
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(menuPtr->display);
    event.send_event = false;
    event.display = menuPtr->display;
    event.event = Tk_WindowId(menuPtr->tkwin);
    event.root = XRootWindow(menuPtr->display, 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    XQueryPointer(NULL, None, NULL, NULL, &event.x_root, &event.y_root, NULL,
	    NULL, &event.state);
    event.same_screen = true;
    event.name = Tk_GetUid("MenuSelect");
    Tk_MakeWindowExist(menuPtr->tkwin);
    if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	Tk_HandleEvent(&event.general);
	Tk_HandleEvent((XEvent *) &event);
    } else {
	Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
	Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RecursivelyClearActiveMenu --
1667
1668
1669
1670
1671
1672
1673
1674

1675
1676

1677
1678
1679
1680
1681
1682
1683
1358
1359
1360
1361
1362
1363
1364

1365
1366

1367
1368
1369
1370
1371
1372
1373
1374







-
+

-
+







 *----------------------------------------------------------------------
 */

void
RecursivelyClearActiveMenu(
    TkMenu *menuPtr)		/* The menu to reset. */
{
    Tcl_Size i;
    int i;

    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
    TkActivateMenuEntry(menuPtr, -1);
    for (i = 0; i < menuPtr->numEntries; i++) {
	TkMenuEntry *mePtr = menuPtr->entries[i];

	if (mePtr->type == CASCADE_ENTRY
		&& (mePtr->childMenuRefPtr != NULL)
		&& (mePtr->childMenuRefPtr->menuPtr != NULL)) {
	    RecursivelyClearActiveMenu(mePtr->childMenuRefPtr->menuPtr);
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
1396
1397
1398
1399
1400
1401
1402

1403



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476







-
+
-
-
-




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















+
+









+
+
+
+
+
+
+







TkMacOSXClearMenubarActive(void)
{
    NSMenu *mainMenu = [NSApp mainMenu];

    if (mainMenu && [mainMenu isKindOfClass:[TKMenu class]]) {
	TkMenu *menuPtr = [(TKMenu *) mainMenu tkMenu];

	if (menuPtr &&
	if (menuPtr && menuPtr->numEntries && menuPtr->entries) {
	    !(menuPtr->menuFlags & MENU_DELETION_PENDING) &&
	    menuPtr->numEntries > 0 &&
	    menuPtr->entries != NULL) {
	    RecursivelyClearActiveMenu(menuPtr);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXTurnOffMenus --
 *
 *	Turns off all the menu drawing code. This is more than just disabling
 *	the "menu" command, this means that Tk will NEVER touch the menubar.
 *	It is needed in the Plugin, where Tk does not own the menubar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A flag is set which will disable all menu drawing.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MacOSXTurnOffMenus(void)
{
    gNoTkMenus = 1;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMenuInit --
 *
 *	Initializes Mac-specific menu data.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates a hash table.
 *
 *----------------------------------------------------------------------
 */

void
TkpMenuInit(void)
{
    TkColor *tkColPtr;

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

#define observe(n, s) \
	[nc addObserver:NSApp selector:@selector(s) name:(n) object:nil]
    observe(NSMenuDidBeginTrackingNotification, menuBeginTracking:);
    observe(NSMenuDidEndTrackingNotification, menuEndTracking:);
#undef observe

    [NSMenuItem setUsesUserKeyEquivalents:NO];
    tkColPtr = TkpGetColor(None, DEF_MENU_BG_COLOR);
    defaultBg = tkColPtr->color.pixel;
    ckfree(tkColPtr);
    tkColPtr = TkpGetColor(None, DEF_MENU_FG);
    defaultFg = tkColPtr->color.pixel;
    ckfree(tkColPtr);

    ChkErr(GetThemeMetric, kThemeMetricMenuMarkColumnWidth,
	    &menuMarkColumnWidth);
    ChkErr(GetThemeMetric, kThemeMetricMenuTextLeadingEdgeMargin,
	    &menuTextLeadingEdgeMargin);
    ChkErr(GetThemeMetric, kThemeMetricMenuTextTrailingEdgeMargin,
	    &menuTextTrailingEdgeMargin);
    ChkErr(GetThemeMetric, kThemeMetricMenuIconTrailingEdgeMargin,
1802
1803
1804
1805
1806
1807
1808
1809
1810


1811
1812
1813
1814
1815
1816
1817
1523
1524
1525
1526
1527
1528
1529


1530
1531
1532
1533
1534
1535
1536
1537
1538







-
-
+
+







 *	An idle handler is set up to do the reconfiguration.
 *
 *----------------------------------------------------------------------
 */

void
TkpMenuNotifyToplevelCreate(
    TCL_UNUSED(Tcl_Interp *),	/* The interp the menu lives in. */
    TCL_UNUSED(const char *))	/* The name of the menu to reconfigure. */
    Tcl_Interp *interp,		/* The interp the menu lives in. */
    const char *menuName)	/* The name of the menu to reconfigure. */
{
    /*
     * Nothing to do.
     */
}

/*
1831
1832
1833
1834
1835
1836
1837
1838
1839


1840
1841
1842
1843
1844
1845
1846
1552
1553
1554
1555
1556
1557
1558


1559
1560
1561
1562
1563
1564
1565
1566
1567







-
-
+
+







 *	Alt-key bindings.
 *
 *--------------------------------------------------------------
 */

void
TkpInitializeMenuBindings(
    TCL_UNUSED(Tcl_Interp *),		/* The interpreter to set. */
    TCL_UNUSED(Tk_BindingTable))
    Tcl_Interp *interp,		/* The interpreter to set. */
    Tk_BindingTable bindingTable)
				/* The table to add to. */
{
    /*
     * Nothing to do.
     */
}

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
1593
1594
1595
1596
1597
1598
1599

1600




1601
1602
1603
1604
1605

1606
1607
1608
1609
1610
1611
1612




1613
1614
1615
1616
1617







1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632







-
+
-
-
-
-





-
+






-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+








/*
 *----------------------------------------------------------------------
 *
 * TkpDrawMenuEntry --
 *
 *	Draws the given menu entry at the given coordinates with the given
 *	attributes.  This is a no-op on macOS since the menus are drawn by
 *	attributes.
 *      the Apple window manager, which also handles all events related to
 *      selecting menu items.  This function is only called for tearoff
 *      menus, which are not supported on macOS but do get drawn as nearly
 *      invisible 1 pixel wide windows on macOS
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None
 *	X Server commands are executed to display the menu entry.
 *
 *----------------------------------------------------------------------
 */

void
TkpDrawMenuEntry(
    TCL_UNUSED(TkMenuEntry *),		/* The entry to draw */
    TCL_UNUSED(Drawable),			/* What to draw into */
    TCL_UNUSED(Tk_Font),		/* Precalculated font for menu */
    TCL_UNUSED(const Tk_FontMetrics *),
    TkMenuEntry *mePtr,		/* The entry to draw */
    Drawable d,			/* What to draw into */
    Tk_Font tkfont,		/* Precalculated font for menu */
    const Tk_FontMetrics *menuMetricsPtr,
				/* Precalculated metrics for menu */
    TCL_UNUSED(int),			/* X-coordinate of topleft of entry */
    TCL_UNUSED(int),			/* Y-coordinate of topleft of entry */
    TCL_UNUSED(int),			/* Width of the entry rectangle */
    TCL_UNUSED(int),			/* Height of the current rectangle */
    TCL_UNUSED(int),		/* Boolean flag */
    TCL_UNUSED(int))		/* Whether or not to draw the cascade arrow
				 * for cascade items. */
    int x,			/* X-coordinate of topleft of entry */
    int y,			/* Y-coordinate of topleft of entry */
    int width,			/* Width of the entry rectangle */
    int height,			/* Height of the current rectangle */
    int strictMotif,		/* Boolean flag */
    int drawArrow)		/* Whether or not to draw the cascade arrow
				 * for cascade items. Only applies to
				 * Windows. */
{
}

#pragma mark Obsolete

/*
 *----------------------------------------------------------------------
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
1651
1652
1653
1654
1655
1656
1657

1658
1659
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







-
+














-
+









-
+
+












-
-
+
+








/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXUseID --
 *
 *	Take the ID out of the available list for new menus. Used by the
 *	default menu bar's menus so that they do not get created at the Tk
 *	default menu bar's menus so that they do not get created at the tk
 *	level. See TkMacOSXGetNewMenuID for more information.
 *
 * Results:
 *	Returns TCL_OK if the id was not in use. Returns TCL_ERROR if the id
 *	was in use.
 *
 * Side effects:
 *	A hash table entry in the command table is created with a NULL value.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXUseMenuID(
    TCL_UNUSED(short))		/* The id to take out of the table */
    short macID)		/* The id to take out of the table */
{
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDispatchMenuEvent --
 *
 *	Given a menu id and an item, dispatches the command associated with it.
 *	Given a menu id and an item, dispatches the command associated with
 *	it.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands for the event are scheduled for execution at idle time.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXDispatchMenuEvent(
    TCL_UNUSED(int),			/* The menu id of the menu we are invoking */
    TCL_UNUSED(int))			/* The one-based index of the item that was
    int menuID,			/* The menu id of the menu we are invoking */
    int index)			/* The one-based index of the item that was
				 * selected. */
{
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
2008
2009
2010
2011
2012
2013
2014
2015
2016


2017
2018

2019
2020
2021
2022
2023
2024
2025
1727
1728
1729
1730
1731
1732
1733


1734
1735


1736
1737
1738
1739
1740
1741
1742
1743







-
-
+
+
-
-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetHelpMenuItemCount --
 *
 *	Has to be called after the first call to InsertMenu. Sets up the global
 *	variable for the number of items in the unmodified help menu.
 *	Has to be called after the first call to InsertMenu. Sets up the
 *	global variable for the number of items in the unmodified help menu.
 *
 *	NB: Nobody uses this any more, since you can get the number of system
 *	NB. Nobody uses this any more, since you can get the number of system
 *	help items from HMGetHelpMenu trivially. But it is in the stubs
 *	table...
 *
 * Results:
 *	None.
 *
 * Side effects:

Changes to macosx/tkMacOSXMenubutton.c.

1
2
3
4
5


6
7
8
9
10
11





12
13
14
15
16
17
18
1
2
3


4
5
6





7
8
9
10
11
12
13
14
15
16
17
18



-
-
+
+

-
-
-
-
-
+
+
+
+
+







/*
 * tkMacOSXMenubutton.c --
 *
 *	This file implements the Macintosh specific portion of the menubutton
 *	widget.
 *	This file implements the Macintosh specific portion of the
 *	menubutton widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 2001 Apple Computer, Inc.
 * Copyright © 2006-2007 Daniel A. Steffen <[email protected]>
 * Copyright © 2007 Revar Desmera.
 * Copyright © 2015 Kevin Walzer/WordTech Communications LLC.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
 * Copyright 2007 Revar Desmera.
 * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include "tkMacOSXPrivate.h"
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53

54
55

56
57
58

59
60
61
62


63
64
65
66


67
68
69


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140


141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159


160
161
162
163
164
165
166

167
168
169
170



171
172

173
174
175
176
177
178
179
180
181
182
183

184

185
186



187
188
189
190

191
192
193
194
195
196
197





198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213

214
215
216
217
218
219
220

221
222
223
224
225
226
227
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52


53


54



55




56
57




58
59



60
61
62
63
64
65
66
67
68
69
70


71
72







73




























74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124

125
126



127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151


152


153




154
155
156
157
158
159
160
161
162
163
164
165
166

167

168
169
170
171
172

173
174
175
176
177
178
179

180
181
182
183
184
185
186
187







+















-
+


-
-
+
-
-
+
-
-
-
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
+
+









-
-


-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+
















-
+

-
+
+




+














-
+
+






-
+

-
-
-
+
+
+

-
+











+
-
+


+
+
+


-
-
+
-
-

-
-
-
-
+
+
+
+
+








-
+
-





-
+






-
+








typedef struct {
    Tk_3DBorder border;
    int relief;
    GC gc;
    int hasImageOrBitmap;
} DrawParams;


/*
 * Declaration of Mac specific button structure.
 */

typedef struct MacMenuButton {
    TkMenuButton info;		/* Generic button info. */
    int flags;
    ThemeButtonKind btnkind;
    HIThemeButtonDrawInfo drawinfo;
    HIThemeButtonDrawInfo lastdrawinfo;
    DrawParams drawParams;
} MacMenuButton;

/*
 * Forward declarations for static functions defined later in this file:
 * Forward declarations for procedures defined later in this file:
 */

static void		MenuButtonEventProc(void *clientData,
			    XEvent *eventPtr);
static void MenuButtonEventProc(ClientData clientData, XEvent *eventPtr);
static void		MenuButtonBackgroundDrawCB(MacMenuButton *ptr,
			    SInt16 depth, Boolean isColorDev);
static void MenuButtonBackgroundDrawCB ( MacMenuButton *ptr, SInt16 depth, Boolean isColorDev);
static void		MenuButtonContentDrawCB(ThemeButtonKind kind,
			    const HIThemeButtonDrawInfo *info,
			    MacMenuButton *ptr, SInt16 depth,
static void MenuButtonContentDrawCB ( ThemeButtonKind kind, const HIThemeButtonDrawInfo * info, MacMenuButton *ptr, SInt16 depth, Boolean isColorDev);
			    Boolean isColorDev);
static void		MenuButtonEventProc(void *clientData,
			    XEvent *eventPtr);
static void		TkMacOSXComputeMenuButtonParams(TkMenuButton *butPtr,
static void MenuButtonEventProc ( ClientData clientData, XEvent *eventPtr);
static void TkMacOSXComputeMenuButtonParams (TkMenuButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo* drawinfo);
			    ThemeButtonKind *btnkind,
			    HIThemeButtonDrawInfo *drawinfo);
static void		TkMacOSXComputeMenuButtonDrawParams(
			    TkMenuButton *butPtr, DrawParams *dpPtr);
static int TkMacOSXComputeMenuButtonDrawParams (TkMenuButton * butPtr, DrawParams * dpPtr);
static void TkMacOSXDrawMenuButton (MacMenuButton *butPtr,
static void		TkMacOSXDrawMenuButton(MacMenuButton *butPtr, GC gc,
			    Pixmap pixmap);
static void		DrawMenuButtonImageAndText(TkMenuButton *butPtr);
       GC gc, Pixmap pixmap);
static void DrawMenuButtonImageAndText(TkMenuButton* butPtr);

/*
 * The structure below defines menubutton class behavior by means of
 * procedures that can be invoked from generic window code.
 */

Tk_ClassProcs tkpMenubuttonClass = {
    sizeof(Tk_ClassProcs),	/* size */
    TkMenuButtonWorldChanged,	/* worldChangedProc */
	NULL,
	NULL
};

/*
 * We use Apple's Pop-Up Button widget to represent the Tk Menubutton.
 * However, we do not use the NSPopUpButton class for this control.  Instead we
 * render the Pop-Up Button using the HITheme library.  This imposes some
 * constraints on what can be done.  The HITheme renderer allows only specific
 * dimensions for the button.
 *

 * The HITheme library allows drawing a Pop-Up Button with an arbitrary bounds
 * rectangle.  However the button is always drawn as a rounded box which is 22
 * pixels high.  If the bounds rectangle is less than 22 pixels high, the
 * button is drawn at the top of the rectangle and the bottom of the button is
 * clipped away.  So we set a minimum height of 22 pixels for a Menubutton.  If
 * the bounds rectangle is more than 22 pixels high, then the button is drawn
 * centered vertically in the bounds rectangle.
 *
 * The content rectangle of the button is inset by 14 pixels on the left and 28
 * pixels on the right.  The rightmost part of the button contains the blue
 * double-arrow symbol which is 28 pixels wide.
 *
 * To maintain compatibility with code that runs on multiple operating systems,
 * the width and height of the content rectangle includes the borderWidth, the
 * highlightWidth and the padX and padY dimensions of the Menubutton.  However,
 * to be consistent with the standard Apple appearance, the content is always
 * be drawn at the left side of the content rectangle.  All of the excess space
 * appears on the right side of the content, and the anchor property is
 * ignored.  The easiest way to comply with Apple's Human Interface Guidelines
 * would be to set bd = highlightthickness = padx = 0 and to specify an
 * explicit width for the button.  Apple also recommends using the same width
 * for all Pop-Up Buttons in a given window.
 */

#define LEFT_INSET 8
#define RIGHT_INSET 28
#define MIN_HEIGHT 22

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateMenuButton  --
 * TkpCreateMenuButton --
 *
 *	Allocate a new TkMenuButton structure.
 *
 * Results:
 *	Returns a newly allocated TkMenuButton structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkMenuButton *
TkpCreateMenuButton(
    Tk_Window tkwin)
{
    MacMenuButton *mbPtr = (MacMenuButton *)ckalloc(sizeof(MacMenuButton));
    MacMenuButton *mbPtr = (MacMenuButton *) ckalloc(sizeof(MacMenuButton));

    Tk_CreateEventHandler(tkwin, ActivateMask, MenuButtonEventProc, mbPtr);
    Tk_CreateEventHandler(tkwin, ActivateMask,
	    MenuButtonEventProc, (ClientData) mbPtr);
    mbPtr->flags = FIRST_DRAW;
    mbPtr->btnkind = kThemePopupButton;
    bzero(&mbPtr->drawinfo, sizeof(mbPtr->drawinfo));
    bzero(&mbPtr->lastdrawinfo, sizeof(mbPtr->lastdrawinfo));

    return (TkMenuButton *) mbPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayMenuButton --
 *
 *	This procedure is invoked to display a menubutton widget.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands are output to X to display the menubutton in its current mode.
 *	Commands are output to X to display the menubutton in its
 *	current mode.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayMenuButton(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    MacMenuButton *mbPtr = (MacMenuButton *)clientData;
    TkMenuButton *butPtr = (TkMenuButton *)clientData;
    Tk_Window tkwin = butPtr->tkwin;
    MacMenuButton *mbPtr    = (MacMenuButton *)clientData;
    TkMenuButton  *butPtr   = (TkMenuButton *) clientData;
    Tk_Window tkwin         = butPtr->tkwin;
    Pixmap pixmap;
    DrawParams *dpPtr = &mbPtr->drawParams;
    DrawParams* dpPtr = &mbPtr->drawParams;

    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
        return;
    }

    pixmap = (Pixmap) Tk_WindowId(tkwin);

    TkMacOSXComputeMenuButtonDrawParams(butPtr, dpPtr);

    /*
     * set up clipping region.  Make sure the we are using the port
     * Draw the native portion of the buttons.
     * for this button, or we will set the wrong window's clip.
     */

    TkMacOSXSetUpClippingRgn(pixmap);

    /* Draw the native portion of the buttons. */
    TkMacOSXDrawMenuButton(mbPtr,  dpPtr->gc, pixmap);

    /*
     * Draw highlight border, if needed.
    /* Draw highlight border, if needed. */
     */

    if (butPtr->highlightWidth < 3) {
        if (butPtr->flags & GOT_FOCUS) {
	    GC gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
	    TkMacOSXDrawSolidBorder(tkwin, gc, 0, butPtr->highlightWidth);
	}
        if ((butPtr->flags & GOT_FOCUS)) {
            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
                Tk_Width(tkwin), Tk_Height(tkwin),
                butPtr->highlightWidth, TK_RELIEF_SOLID);
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyMenuButton --
 *
 *	Free data structures associated with the menubutton control. This is a
 *	Free data structures associated with the menubutton control.
 *      no-op on the Mac.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *	Restores the default control state.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyMenuButton(
    TCL_UNUSED(TkMenuButton *))
    TkMenuButton *mbPtr)
{
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeMenuButtonGeometry --
236
237
238
239
240
241
242
243
244


245
246

247
248
249



250
251
252

253
254
255
256
257
258
259


260
261
262
263
264
265
266
267
268
269

270
271
272
273

274

275
276
277
278

279
280
281
282
283
284
285




286
287
288

289
290
291
292
293
294





295
296
297
298
299
300
301
302
303









304
305
306
307
308
309
310
311








312
313
314
315
316





317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335

336
337
338
339

340
341
342

343
344
345


346










347
348
349
350







































351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380
381
















382
383
384
385
386
387
388


389

390

391
392
393
394
395
396
397








398
399
400
401




402
403
404
405
406
407
408
409


410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

















430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
















446
447
448
449
450
451
452
453
454
455











456
457
458
459
460


461
462

463
464
465
466
467
468


469
470
471
472
473
474
475
476
477
478
479
480
481
482


483
484
485
486
487


488
489
490
491
492
493
494
495
496






497
498
499
500
501
502
503




504
505
506



507

508
509

510
511

512
513

514
515
516



517
518
519
520
521
522
523
524



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544









545
546

547


548
549
550
551
552




553
554
555
556
557
558
559



560
561

562
563
564
565

566
567
568
569
570
571
572
573
574
575
576
577
578
579

580
581
582

583
584
585
586
587
588


589
590

591
592


593
594
595
596
597
598
599
600
601
602
603
604


605
606
607

608
609
610

611
612
613
614
615
616
617
618
619


620
621
622


623
624
625
626
627
628


629
630

631
632
633
634
635
636
637
638

639
640
641

642
643
644

645
646
647
648
649
650
651
652


653
654
655


656
657
658


659
660
661
662

663

664
665
666
667
668
669
670
671
672


673
674
675
676
677
678
679
680
681
682
683
684
685

686
687
688
689


690
691
692
693
694
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
710
711
712
713
714
715



716
717
718
719
720
721
722
723
724
725
726
727

728
729
730
731
732

733
734

735
736
737
738






739
740
741
742
743
744
745
196
197
198
199
200
201
202


203
204
205
206
207
208
209

210
211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234

235
236

237
238
239
240
241
242
243
244
245
246
247




248
249
250
251
252
253

254
255





256
257
258
259
260
261








262
263
264
265
266
267
268
269
270
271







272
273
274
275
276
277
278
279
280




281
282
283
284
285

286
287
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302

303
304
305
306

307
308
309

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326




327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384
385
386

387
388








389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409


410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429




430
431
432
433
434
435
436
437
438
439


440
441


442


















443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460















461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477









478
479
480
481
482
483
484
485
486
487
488

489
490
491

492
493
494

495
496
497
498
499


500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

515
516
517
518


519
520
521
522
523
524
525





526
527
528
529
530
531
532
533
534




535
536
537
538
539
540
541
542
543
544

545
546

547
548

549
550

551
552
553

554
555
556
557
558
559
560
561



562
563
564
565
566
567
568
569
570
571
572
573

574
575
576







577
578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593


594
595
596
597
598
599
600
601
602


603
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619







620



621



622


623
624
625

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640


641
642
643
644

645
646
647

648
649
650
651

652
653
654


655
656
657


658
659
660

661
662
663

664
665
666

667
668
669
670
671
672
673
674

675
676
677

678
679
680

681
682
683
684

685
686


687
688
689


690
691
692


693
694
695
696
697
698
699

700
701
702
703
704
705
706
707


708
709
710
711
712
713
714
715
716
717
718
719
720
721

722
723
724


725
726
727
728
729
730
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748
749



750
751
752
753
754
755
756
757
758
759
760
761
762
763

764



765

766
767

768
769
770


771
772
773
774
775
776
777
778
779
780
781
782
783







-
-
+
+


+


-
+
+
+


-
+







+
+









-
+
-


-
+

+




+



-
-
-
-
+
+
+
+


-
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+
+
-










-
+






-
+



-
+


-
+



+
+

+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+











-
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+

+
-
+







+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+






-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-



-
+
+

-
+




-
-
+
+













-
+
+


-
-

+
+




-
-
-
-
-
+
+
+
+
+
+



-
-
-
-
+
+
+
+



+
+
+
-
+

-
+

-
+

-
+


-
+
+
+





-
-
-
+
+
+









-



-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+

+
+



-
-
+
+
+
+





-
-
+
+
+


+



-
+







-
-
-
-
-
-
-
+
-
-
-
+
-
-
-

-
-
+
+

-
+


+
+










-
-
+
+


-
+


-
+



-



-
-
+
+

-
-
+
+

-



-
+
+

-
+







-
+


-
+


-
+



-


-
-
+
+

-
-
+
+

-
-
+
+




+
-
+







-
-
+
+












-
+


-
-
+
+












-
+










-
-
-
+
+
+











-
+
-
-
-

-
+

-
+


-
-
+
+
+
+
+
+







 * Side effects:
 *	The menu button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeMenuButtonGeometry(
    TkMenuButton *butPtr)	/* Widget record for menu button. */
TkpComputeMenuButtonGeometry(butPtr)
    register TkMenuButton *butPtr;	/* Widget record for menu button. */
{
    int width, height, avgWidth, haveImage = 0, haveText = 0;
    MacMenuButton *mbPtr = (MacMenuButton*)butPtr;
    int txtWidth, txtHeight;
    Tk_FontMetrics fm;
    int highlightWidth = butPtr->highlightWidth > 0 ? butPtr->highlightWidth : 0;
    DrawParams drawParams;
    int paddingx = 0;
    int paddingy = 0;

    /*
     * First compute the size of the contents of the button.
     * First figure out the size of the contents of the button.
     */

    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;

    TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);

    if (butPtr->image != NULL) {
        Tk_SizeOfImage(butPtr->image, &width, &height);
        haveImage = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        haveImage = 1;
    }

    if (butPtr->text && strlen(butPtr->text) > 0) {
    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
	haveText = 1;
        Tk_FreeTextLayout(butPtr->textLayout);
        butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
                butPtr->text, TCL_INDEX_NONE, butPtr->wrapLength,
                butPtr->text, -1, butPtr->wrapLength,
                butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

        txtWidth = butPtr->textWidth;
        txtHeight = butPtr->textHeight;
        avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(butPtr->tkfont, &fm);
        haveText = (txtWidth != 0 && txtHeight != 0);
    }

    /*
     * If the button is compound (ie, it shows both an image and text), the new
     * geometry is a combination of the image and text geometry. We only honor
     * the compound bit if the button has both text and an image, because
     * otherwise it is not really a compound button.
     * If the button is compound (ie, it shows both an image and text),
     * the new geometry is a combination of the image and text geometry.
     * We only honor the compound bit if the button has both text and an
     * image, because otherwise it is not really a compound button.
     */

    if (haveImage && haveText) {
    if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        switch ((enum compound) butPtr->compound) {
	case COMPOUND_TOP:
	case COMPOUND_BOTTOM:
	    /*
	     * Image is above or below text
	     */
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
                /*
                 * Image is above or below text
                 */

	    height += txtHeight + butPtr->padY;
	    width = (width > txtWidth ? width : txtWidth);
	    break;
	case COMPOUND_LEFT:
	case COMPOUND_RIGHT:
	    /*
	     * Image is left or right of text
	     */
                height += txtHeight + butPtr->padY;
                width = (width > txtWidth ? width : txtWidth);
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /*
                 * Image is left or right of text
                 */

	    width += txtWidth + butPtr->padX;
	    height = (height > txtHeight ? height : txtHeight);
	    break;
	case COMPOUND_CENTER:
	    /*
	     * Image and text are superimposed
	     */
                width += txtWidth + butPtr->padX;
                height = (height > txtHeight ? height : txtHeight);
                break;
            }
            case COMPOUND_CENTER: {
                /*
                 * Image and text are superimposed
                 */

	    width = (width > txtWidth ? width : txtWidth);
	    height = (height > txtHeight ? height : txtHeight);
	    break;
	case COMPOUND_NONE:
                width = (width > txtWidth ? width : txtWidth);
                height = (height > txtHeight ? height : txtHeight);
                break;
            }
            case COMPOUND_NONE: {break;}
	    break;
        }

        if (butPtr->width > 0) {
            width = butPtr->width;
        }
        if (butPtr->height > 0) {
            height = butPtr->height;
        }

    } else {
        if (haveImage) { /* Image only */
        if (haveImage) {
            if (butPtr->width > 0) {
                width = butPtr->width;
            }
            if (butPtr->height > 0) {
                height = butPtr->height;
            }
        } else { /* Text only */
        } else {
            width = txtWidth;
            height = txtHeight;
            if (butPtr->width > 0) {
                width = butPtr->width * avgWidth + 2*butPtr->padX;
                width = butPtr->width * avgWidth;
            }
            if (butPtr->height > 0) {
                height = butPtr->height * fm.linespace + 2*butPtr->padY;
                height = butPtr->height * fm.linespace;
            }
        }
    }
    width  += 2 * butPtr->padX - 2;
    height += 2 * butPtr->padY - 2;

    /*Add padding for button arrows.*/
    width += 22;

    /*
     * Now figure out the size of the border decorations for the button.
     */

    if (butPtr->highlightWidth < 0) {
        butPtr->highlightWidth = 0;
    }
    butPtr->inset = highlightWidth + butPtr->borderWidth;
    width += LEFT_INSET + RIGHT_INSET + 2*butPtr->inset;
    height += 2*butPtr->inset;
    height = height < MIN_HEIGHT ? MIN_HEIGHT : height;
    butPtr->inset = 0;
    butPtr->inset += butPtr->highlightWidth;

    TkMacOSXComputeMenuButtonDrawParams(butPtr,&drawParams);

        HIRect tmpRect;
	HIRect contBounds;

	tmpRect = CGRectMake(0, 0, width, height);

	HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);



        /* If the content region has a minimum height, match it. */
        if (height < contBounds.size.height) {
	  height = contBounds.size.height;
        }

        /* If the content region has a minimum width, match it. */
        if (width < contBounds.size.width) {
	  width = contBounds.size.width;
        }

        /* Pad to fill difference between content bounds and button bounds. */
        paddingx = tmpRect.origin.x - contBounds.origin.x;
        paddingy = tmpRect.origin.y - contBounds.origin.y;

    if (paddingx > 0) {
        width += paddingx;
    }
    if (paddingy > 0) {
        height += paddingy;
    }

    width += butPtr->inset*2;
    height += butPtr->inset*2;


    Tk_GeometryRequest(butPtr->tkwin, width, height);
    Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}

/*
 *----------------------------------------------------------------------
 *
 * DrawMenuButtonImageAndText --
 *
 *        Draws the image and text associated with a button or label.
 *        Draws the image and text associated witha button or label.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        The image and text are drawn.
 *
 *----------------------------------------------------------------------
 */
void
DrawMenuButtonImageAndText(
    TkMenuButton *butPtr)
    TkMenuButton* butPtr)
{
    MacMenuButton *mbPtr = (MacMenuButton *) butPtr;
    Tk_Window tkwin  = butPtr->tkwin;
    Pixmap pixmap;
    int haveImage = 0, haveText = 0;
    int imageXOffset = 0, imageYOffset = 0;
    int textXOffset = 0, textYOffset = 0;
    int width = 0, height = 0;
    int fullWidth = 0, fullHeight = 0;
    MacMenuButton *mbPtr = (MacMenuButton*)butPtr;
    Tk_Window  tkwin  = butPtr->tkwin;
    Pixmap     pixmap;
    int        haveImage = 0;
    int        haveText = 0;
    int        imageWidth = 0;
    int        imageHeight = 0;
    int        imageXOffset = 0;
    int        imageYOffset = 0;
    int        textXOffset = 0;
    int        textYOffset = 0;
    int        width = 0;
    int        height = 0;
    int        fullWidth = 0;
    int        fullHeight = 0;
    int        pressed;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }

    DrawParams *dpPtr = &mbPtr->drawParams;
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    DrawParams* dpPtr = &mbPtr->drawParams;
    pixmap = (Pixmap)Tk_WindowId(tkwin);


    if (butPtr->image != NULL) {
    if (butPtr->image != None) {
        Tk_SizeOfImage(butPtr->image, &width, &height);
        haveImage = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        haveImage = 1;
    }

    imageWidth  = width;
    imageHeight = height;

    if (mbPtr->drawinfo.state == kThemeStatePressed) {
        /* Offset bitmaps by a bit when the button is pressed. */
        pressed = 1;
    }

    haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
    if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        int x = 0, y = 0;

  haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
   if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        int x = 0;
        int y = 0;
        textXOffset = 0;
        textYOffset = 0;
        fullWidth = 0;
        fullHeight = 0;

        switch ((enum compound) butPtr->compound) {
	case COMPOUND_TOP:
	case COMPOUND_BOTTOM:
            case COMPOUND_TOP:
            case COMPOUND_BOTTOM: {
	    /*
	     * Image is above or below text.
                /* Image is above or below text */
	     */

	    if (butPtr->compound == COMPOUND_TOP) {
		textYOffset = height + butPtr->padY;
	    } else {
		imageYOffset = butPtr->textHeight + butPtr->padY;
	    }
	    fullHeight = height + butPtr->textHeight + butPtr->padY;
	    fullWidth = (width > butPtr->textWidth ?
		     width : butPtr->textWidth);
	    textXOffset = (fullWidth - butPtr->textWidth)/2;
	    imageXOffset = (fullWidth - width)/2;
	    break;
	case COMPOUND_LEFT:
	case COMPOUND_RIGHT:
	    /*
	     * Image is left or right of text
	     */
                if (butPtr->compound == COMPOUND_TOP) {
                    textYOffset = height + butPtr->padY;
                } else {
                    imageYOffset = butPtr->textHeight + butPtr->padY;
                }
                fullHeight = height + butPtr->textHeight + butPtr->padY;
                fullWidth = (width > butPtr->textWidth ? width :
                        butPtr->textWidth);
                textXOffset = (fullWidth - butPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                break;
            }
            case COMPOUND_LEFT:
            case COMPOUND_RIGHT: {
                /*
                 * Image is left or right of text
                 */

	    if (butPtr->compound == COMPOUND_LEFT) {
		textXOffset = width + butPtr->padX - 2;
	    } else {
		imageXOffset = butPtr->textWidth + butPtr->padX;
	    }
	    fullWidth = butPtr->textWidth + butPtr->padX + width;
	    fullHeight = (height > butPtr->textHeight ? height :
                    butPtr->textHeight);
	    textYOffset = (fullHeight - butPtr->textHeight)/2;
	    imageYOffset = (fullHeight - height)/2;
	    break;
	case COMPOUND_CENTER:
	    /*
	     * Image and text are superimposed
	     */
                if (butPtr->compound == COMPOUND_LEFT) {
                    textXOffset = width + butPtr->padX - 2;
                } else {
                    imageXOffset = butPtr->textWidth + butPtr->padX;
                }
                fullWidth = butPtr->textWidth + butPtr->padX + width;
                fullHeight = (height > butPtr->textHeight ? height :
                        butPtr->textHeight);
                textYOffset = (fullHeight - butPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_CENTER: {
                /*
                 * Image and text are superimposed
                 */

	    fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth);
	    fullHeight = (height > butPtr->textHeight ? height :
                    butPtr->textHeight);
	    textXOffset = (fullWidth - butPtr->textWidth) / 2;
	    imageXOffset = (fullWidth - width) / 2;
	    textYOffset = (fullHeight - butPtr->textHeight) / 2;
	    imageYOffset = (fullHeight - height) / 2;
	    break;
	case COMPOUND_NONE:
                fullWidth = (width > butPtr->textWidth ? width :
                        butPtr->textWidth);
                fullHeight = (height > butPtr->textHeight ? height :
                        butPtr->textHeight);
                textXOffset = (fullWidth - butPtr->textWidth)/2;
                imageXOffset = (fullWidth - width)/2;
                textYOffset = (fullHeight - butPtr->textHeight)/2;
                imageYOffset = (fullHeight - height)/2;
                break;
            }
            case COMPOUND_NONE: {break;}
	    break;
	}

        TkComputeAnchor(butPtr->anchor, tkwin,
                butPtr->padX + butPtr->inset, butPtr->padY + butPtr->inset,
                butPtr->padX + butPtr->borderWidth,
                butPtr->padY + butPtr->borderWidth,
                fullWidth, fullHeight, &x, &y);
        imageXOffset = LEFT_INSET;
        imageXOffset += x;
        imageYOffset += y;
        textYOffset -= 1;

        if (butPtr->image != NULL) {
	    Tk_RedrawImage(butPtr->image, 0, 0, width,
                    height, pixmap, imageXOffset, imageYOffset);
                Tk_RedrawImage(butPtr->image, 0, 0, width,
                        height, pixmap, imageXOffset, imageYOffset);
        } else {
            XSetClipOrigin(butPtr->display, dpPtr->gc,
                    imageXOffset, imageYOffset);
            XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
                    0, 0, (unsigned int) width, (unsigned int) height,
                    imageXOffset, imageYOffset, 1);
            XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
        }

        Tk_DrawTextLayout(butPtr->display, pixmap,
                dpPtr->gc, butPtr->textLayout,
                x + textXOffset, y + textYOffset, 0, -1);
        Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
                butPtr->textLayout, x + textXOffset, y + textYOffset,
                butPtr->textLayout,
                x + textXOffset, y + textYOffset,
                butPtr->underline);
    } else {
	int x, y;

        if (haveImage) {
            int x = 0;
            int y;
            TkComputeAnchor(butPtr->anchor, tkwin,
                    butPtr->padX + butPtr->borderWidth,
                    butPtr->padY + butPtr->borderWidth,
                    width, height, &x, &y);
	    imageXOffset = LEFT_INSET;
	    imageYOffset += y;
	    if (butPtr->image != NULL) {
		Tk_RedrawImage(butPtr->image, 0, 0, width, height,
			       pixmap, imageXOffset, imageYOffset);
	        imageXOffset += x;
	    	imageYOffset += y;

               if (butPtr->image != NULL) {
		     Tk_RedrawImage(butPtr->image, 0, 0, width, height,
		         pixmap, imageXOffset, imageYOffset);
            } else {
                XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
                XCopyPlane(butPtr->display, butPtr->bitmap,
			   pixmap, dpPtr->gc,
			   0, 0, (unsigned int) width,
			   (unsigned int) height,
			   imageXOffset, imageYOffset, 1);
                        pixmap, dpPtr->gc,
                        0, 0, (unsigned int) width,
                        (unsigned int) height,
                        imageXOffset, imageYOffset, 1);
                XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
            }
        } else {
	  /*Move x back by eight pixels to give the menubutton arrows room.*/
	  int x = 0;
	  int y;
	    textXOffset = LEFT_INSET;
	  textXOffset = 8;
	    TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
		    butPtr->textWidth, butPtr->textHeight, &x, &y);
			    butPtr->textWidth, butPtr->textHeight, &x, &y);
	    Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
		    butPtr->textLayout, textXOffset, y, 0, -1);
			      butPtr->textLayout, x - textXOffset, y, 0, -1);
	    y += butPtr->textHeight/2;
	}
	  }
   }
}




/*
 *--------------------------------------------------------------
 *
 * TkMacOSXDrawMenuButton --
 *
 *        This function draws the tk menubutton using Mac controls. In
 *        addition, this code may apply custom colors passed in the
 *        TkMenubutton.
 *        This function draws the tk menubutton using Mac controls
 *        In addition, this code may apply custom colors passed
 *        in the TkMenubutton.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        None.
 *
 *--------------------------------------------------------------
 */

static void
TkMacOSXDrawMenuButton(
    MacMenuButton *mbPtr, /* Mac menubutton. */
    TCL_UNUSED(GC),       /* The GC we are drawing into - not used */
    Pixmap pixmap)        /* The pixmap we are drawing into - needed for the
                           * bevel button */
{
    TkMenuButton *butPtr = (TkMenuButton *) mbPtr;
    TkWindow *winPtr = (TkWindow *) butPtr->tkwin;
    HIRect cntrRect;
    GC gc,                /* The GC we are drawing into - needed for
                           * the bevel button */
    Pixmap pixmap)        /* The pixmap we are drawing into - needed
                           * for the bevel button */

{
    TkMenuButton * butPtr = ( TkMenuButton *)mbPtr;
    TkWindow * winPtr;
    HIRect       cntrRect;
    TkMacOSXDrawingContext dc;
    DrawParams *dpPtr = &mbPtr->drawParams;
    DrawParams* dpPtr = &mbPtr->drawParams;
    int useNewerHITools = 1;

    winPtr = (TkWindow *)butPtr->tkwin;

    TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);

    cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff,
	    Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin));
    cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, Tk_Width(butPtr->tkwin),Tk_Height(butPtr->tkwin));

     cntrRect = CGRectInset(cntrRect,  butPtr->inset, butPtr->inset);


    if (useNewerHITools == 1) {
        HIRect contHIRec;
        static HIThemeButtonDrawInfo hiinfo;

        MenuButtonBackgroundDrawCB(mbPtr, 32, true);
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) {
        MenuButtonBackgroundDrawCB((MacMenuButton*) mbPtr, 32, true);

	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}


        hiinfo.version = 0;
        hiinfo.state = mbPtr->drawinfo.state;
        hiinfo.kind = mbPtr->btnkind;
        hiinfo.kind  = mbPtr->btnkind;
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
            hiinfo.animation.time.start = hiinfo.animation.time.current;
        }

	/*
	 * To avoid menubuttons with white text on a white background, we
	 * always set the state to inactive in Dark Mode.  It isn't perfect but
	 * it is usable.  Using a ttk::menubutton would be a better choice,
	 * however.
	 */

        HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, &contHIRec);
	if (TkMacOSXInDarkMode(butPtr->tkwin)) {
	    hiinfo.state = kThemeStateInactive;
	}


        HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
		kHIThemeOrientationNormal, &contHIRec);
	TkMacOSXRestoreDrawingContext(&dc);
        MenuButtonContentDrawCB(mbPtr->btnkind, &mbPtr->drawinfo,
		mbPtr, 32, true);

        MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo, (MacMenuButton *)mbPtr, 32, true);
    } else {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}


	TkMacOSXRestoreDrawingContext(&dc);
    }
    mbPtr->lastdrawinfo = mbPtr->drawinfo;
}

/*
 *--------------------------------------------------------------
 *
 * MenuButtonBackgroundDrawCB --
 *
 *      This function draws the background that lies under checkboxes and
 *      radiobuttons.
 *        This function draws the background that
 *        lies under checkboxes and radiobuttons.
 *
 * Results:
 *      None.
 *        None.
 *
 * Side effects:
 *      The background gets updated to the current color.
 *        The background gets updated to the current color.
 *
 *--------------------------------------------------------------
 */

static void
MenuButtonBackgroundDrawCB (
    MacMenuButton *ptr,
    TCL_UNUSED(SInt16),
    TCL_UNUSED(Boolean))
    SInt16 depth,
    Boolean isColorDev)
{
    TkMenuButton* butPtr = (TkMenuButton *) ptr;
    Tk_Window tkwin = butPtr->tkwin;
    TkMenuButton* butPtr = (TkMenuButton*)ptr;
    Tk_Window tkwin  = butPtr->tkwin;
    Pixmap pixmap;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    pixmap = (Pixmap)Tk_WindowId(tkwin);

    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
            Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
        Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
}

/*
 *--------------------------------------------------------------
 *
 * MenuButtonContentDrawCB --
 *
 *      This function draws the label and image for the button.
 *        This function draws the label and image for the button.
 *
 * Results:
 *      None.
 *        None.
 *
 * Side effects:
 *      The content of the button gets updated.
 *        The content of the button gets updated.
 *
 *--------------------------------------------------------------
 */

static void
MenuButtonContentDrawCB (
    TCL_UNUSED(ThemeButtonKind),
    TCL_UNUSED(const HIThemeButtonDrawInfo *),
    ThemeButtonKind kind,
    const HIThemeButtonDrawInfo *drawinfo,
    MacMenuButton *ptr,
    TCL_UNUSED(SInt16),
    TCL_UNUSED(Boolean))
    SInt16 depth,
    Boolean isColorDev)
{
    TkMenuButton *butPtr = (TkMenuButton *) ptr;
    Tk_Window tkwin = butPtr->tkwin;
    TkMenuButton  *butPtr = (TkMenuButton *)ptr;
    Tk_Window  tkwin  = butPtr->tkwin;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
        return;
    }

    DrawMenuButtonImageAndText(butPtr);
    DrawMenuButtonImageAndText( butPtr);
}

/*
 *--------------------------------------------------------------
 *
 * MenuButtonEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for various events on
 *	buttons.
 *	This procedure is invoked by the Tk dispatcher for various
 *	events on buttons.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
MenuButtonEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkMenuButton *buttonPtr = (TkMenuButton *)clientData;
    MacMenuButton *mbPtr = (MacMenuButton *)clientData;
    TkMenuButton *buttonPtr = (TkMenuButton *) clientData;
    MacMenuButton *mbPtr = (MacMenuButton *) clientData;

    if (eventPtr->type == ActivateNotify
	    || eventPtr->type == DeactivateNotify) {
	if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
	    return;
	}
	if (eventPtr->type == ActivateNotify) {
	    mbPtr->flags |= ACTIVE;
	} else {
	    mbPtr->flags &= ~ACTIVE;
	}
	if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
	    Tcl_DoWhenIdle(TkpDisplayMenuButton, buttonPtr);
	    Tcl_DoWhenIdle(TkpDisplayMenuButton, (ClientData) buttonPtr);
	    buttonPtr->flags |= REDRAW_PENDING;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXComputeMenuButtonParams --
 *
 *      This procedure computes the various parameters used when creating a
 *      Carbon Appearance control. These are determined by the various Tk
 *      button parameters
 *      This procedure computes the various parameters used
 *        when creating a Carbon Appearance control.
 *      These are determined by the various tk button parameters
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Sets the btnkind and drawinfo parameters
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonParams(
TkMacOSXComputeMenuButtonParams(TkMenuButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo *drawinfo)
    TkMenuButton *butPtr,
    ThemeButtonKind *btnkind,
    HIThemeButtonDrawInfo *drawinfo)
{
    MacMenuButton *mbPtr = (MacMenuButton *) butPtr;
    MacMenuButton *mbPtr = (MacMenuButton *)butPtr;

    if (butPtr->image || butPtr->bitmap || butPtr->text) {
    if (butPtr->image || butPtr->bitmap) {
	/* TODO: allow for Small and Mini menubuttons. */
	*btnkind = kThemePopupButton;
    } else { /* This should never happen. */
	*btnkind = kThemeArrowButton;
    } else {
        if (!butPtr->text || !*butPtr->text) {
            *btnkind = kThemeArrowButton;
        } else {
            *btnkind = kThemePopupButton;
        }
    }

    drawinfo->value = kThemeButtonOff;

    if ((mbPtr->flags & FIRST_DRAW) != 0) {
	mbPtr->flags &= ~FIRST_DRAW;
	if (Tk_MacOSXIsAppInFront()) {
770
771
772
773
774
775
776
777
778



779
780
781

782
783
784

785
786
787
788
789
790


791
792
793
794
795


796
797
798
799
800
801
802
803
804
805
806
807




808
809
810
811
812
813
814
808
809
810
811
812
813
814


815
816
817
818
819

820
821
822

823
824
825
826
827


828
829


830


831
832
833
834
835
836
837
838
839
840
841



842
843
844
845














-
-
+
+
+


-
+


-
+




-
-
+
+
-
-

-
-
+
+









-
-
-
+
+
+
+
-
-
-
-
-
-
-
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXComputeMenuButtonDrawParams --
 *
 *      This procedure selects an appropriate drawing context for drawing a
 *      menubutton.
 *        This procedure computes the various parameters used
 *        when drawing a button
 *      These are determined by the various tk button parameters
 *
 * Results:
 *      None.
 *        1 if control will be used, 0 otherwise.
 *
 * Side effects:
 *      Sets the button draw parameters.
 *        Sets the button draw parameters
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonDrawParams(
static int
TkMacOSXComputeMenuButtonDrawParams(TkMenuButton * butPtr, DrawParams * dpPtr)
    TkMenuButton *butPtr,
    DrawParams *dpPtr)
{
    dpPtr->hasImageOrBitmap =
	    ((butPtr->image != NULL) || (butPtr->bitmap != None));
    dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
            || (butPtr->bitmap != None));
    dpPtr->border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
        dpPtr->gc = butPtr->disabledGC;
    } else if (butPtr->state == STATE_ACTIVE) {
        dpPtr->gc = butPtr->activeTextGC;
        dpPtr->border = butPtr->activeBorder;
    } else {
        dpPtr->gc = butPtr->normalTextGC;
    }
}

/*

    return 1;
}

 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXMenus.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15

16
17
18

19
20
21
22
23
24
25





-
-
-
+
+
+







-



-







/*
 * tkMacOSXMenus.c --
 *
 *	These calls set up the default menus for Tk.
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMenu.h"
#include "tkMacOSXConstants.h"

static void		GenerateEditEvent(const char *name);
static Tcl_Obj *	GetWidgetDemoPath(Tcl_Interp *interp);


#pragma mark TKApplication(TKMenus)

@implementation TKApplication(TKMenus)
- (void) _setupMenus
{
    if (_defaultMainMenu) {
66
67
68
69
70
71
72
73
74



75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108






109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139


140
141
142
143
144
145


146
147
148
149
150

151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79
80

81



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98






99
100
101
102
103
104











105








106
107












108
109




110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155







-
-
+
+
+







-
+
-
-
-

















-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-

-
+
+





+


+


















-








+







	    nil] retain];
    _defaultApplicationMenu = [TKMenu menuWithTitle:applicationName
	    menuItems:_defaultApplicationMenuItems];
    [_defaultApplicationMenu insertItem:
	    [NSMenuItem itemWithTitle:
		    [NSString stringWithFormat:@"About %@", aboutName]
		    action:@selector(orderFrontStandardAboutPanel:)] atIndex:0];
    _defaultFileMenuItems =
	    [[NSArray arrayWithObjects:

    TKMenu *fileMenu = [TKMenu menuWithTitle:@"File" menuItems:
	    [NSArray arrayWithObjects:
	    [NSMenuItem itemWithTitle:
		   [NSString stringWithFormat:@"Source%C", 0x2026]
		   action:@selector(tkSource:)],
	    [NSMenuItem itemWithTitle:@"Run Widget Demo"
		   action:@selector(tkDemo:)],
	    [NSMenuItem itemWithTitle:@"Close" action:@selector(performClose:)
		   target:nil keyEquivalent:@"w"],
	    nil] retain];
	    nil]];
    _demoMenuItem = [_defaultFileMenuItems objectAtIndex:1];
    TKMenu *fileMenu = [TKMenu menuWithTitle:@"File"
	    menuItems: _defaultFileMenuItems];
    TKMenu *editMenu = [TKMenu menuWithTitle:@"Edit" menuItems:
	    [NSArray arrayWithObjects:
	    [NSMenuItem itemWithTitle:@"Undo" action:@selector(undo:)
		   target:nil keyEquivalent:@"z"],
	    [NSMenuItem itemWithTitle:@"Redo" action:@selector(redo:)
		   target:nil keyEquivalent:@"y"],
	    [NSMenuItem separatorItem],
	    [NSMenuItem itemWithTitle:@"Cut" action:@selector(cut:)
		   target:nil keyEquivalent:@"x"],
	    [NSMenuItem itemWithTitle:@"Copy" action:@selector(copy:)
		   target:nil keyEquivalent:@"c"],
	    [NSMenuItem itemWithTitle:@"Paste" action:@selector(paste:)
		   target:nil keyEquivalent:@"v"],
	    [NSMenuItem itemWithTitle:@"Delete" action:@selector(delete:)
		   target:nil],
	    nil]];

    _defaultWindowsMenuItems = [NSArray arrayWithObjects:
    	    [NSMenuItem itemWithTitle:@"Minimize"
    	    	   action:@selector(performMiniaturize:) target:nil
    	    	   keyEquivalent:@"m"],
    	    [NSMenuItem itemWithTitle:@"Zoom" action:@selector(performZoom:)
    	    	   target:nil],
    _defaultWindowsMenuItems = [[NSArray arrayWithObjects:
	    [NSMenuItem itemWithTitle:@"Minimize"
		   action:@selector(performMiniaturize:) target:nil
		   keyEquivalent:@"m"],
	    [NSMenuItem itemWithTitle:@"Zoom" action:@selector(performZoom:)
		   target:nil],
	    nil];

    /*
     * On OS X 10.12 we get duplicate tab control items if we create them here.
     */

    if ([NSApp macOSVersion] > 101200) {
	_defaultWindowsMenuItems = [_defaultWindowsMenuItems
	     arrayByAddingObjectsFromArray:
	     [NSArray arrayWithObjects:
        	    [NSMenuItem separatorItem],
	    [NSMenuItem separatorItem],
    	            [NSMenuItem itemWithTitle:@"Show Previous Tab"
		           action:@selector(selectPreviousTab:)
		           target:nil
			   keyEquivalent:@"\t"
		           keyEquivalentModifierMask:
		    	       NSControlKeyMask|NSShiftKeyMask],
	            [NSMenuItem itemWithTitle:@"Show Next Tab"
		           action:@selector(selectNextTab:)
	    [NSMenuItem itemWithTitle:@"Bring All to Front"
		   action:@selector(arrangeInFront:)],
		           target:nil
			   keyEquivalent:@"\t"
		           keyEquivalentModifierMask:NSControlKeyMask],
    	            [NSMenuItem itemWithTitle:@"Move Tab To New Window"
    	    	           action:@selector(moveTabToNewWindow:)
    	    	           target:nil],
    	            [NSMenuItem itemWithTitle:@"Merge All Windows"
    	    	           action:@selector(mergeAllWindows:)
    	    	           target:nil],
    	            [NSMenuItem separatorItem],
	            nil]];
    }
	    nil] retain];

    _defaultWindowsMenuItems = [_defaultWindowsMenuItems arrayByAddingObject:
	    [NSMenuItem itemWithTitle:@"Bring All to Front"
		   action:@selector(arrangeInFront:)]];
    [_defaultWindowsMenuItems retain];
    TKMenu *windowsMenu = [TKMenu menuWithTitle:@"Window" menuItems:
    				      _defaultWindowsMenuItems];
	    _defaultWindowsMenuItems];

    _defaultHelpMenuItems = [[NSArray arrayWithObjects:
	    [NSMenuItem itemWithTitle:
		   [NSString stringWithFormat:@"%@ Help", applicationName]
		   action:@selector(showHelp:) keyEquivalent:@"?"],
	    nil] retain];

    TKMenu *helpMenu = [TKMenu menuWithTitle:@"Help" menuItems:
	    _defaultHelpMenuItems];

    [self setServicesMenu:_servicesMenu];
    [self setWindowsMenu:windowsMenu];
    _defaultMainMenu = [[TKMenu menuWithTitle:@"" submenus:[NSArray
	    arrayWithObjects:_defaultApplicationMenu, fileMenu, editMenu,
	    windowsMenu, helpMenu, nil]] retain];
    [_defaultMainMenu setSpecial:tkMainMenu];
    [_defaultApplicationMenu setSpecial:tkApplicationMenu];
    [windowsMenu setSpecial:tkWindowsMenu];
    [helpMenu setSpecial:tkHelpMenu];
    [self tkSetMainMenu:nil];
}

- (void) dealloc
{
    [_defaultMainMenu release];
    [_defaultHelpMenuItems release];
    [_defaultWindowsMenuItems release];
    [_defaultApplicationMenuItems release];
    [_defaultFileMenuItems release];
    [super dealloc];
}

- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>) anItem
{
    SEL action = [anItem action];

    if (sel_isEqual(action, @selector(preferences:))) {

	return (_eventInterp && Tcl_FindCommand(_eventInterp,
		"::tk::mac::ShowPreferences", NULL, 0));
    } else if (sel_isEqual(action, @selector(tkDemo:))) {
	BOOL haveDemo = NO;

	if (_eventInterp) {
	    Tcl_Obj *path = GetWidgetDemoPath(_eventInterp);
195
196
197
198
199
200
201
202
203
204
205
206

207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
164
165
166
167
168
169
170


171
172

173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200
201
202


203
204
205

206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227


228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


252
253
254
255
256
257
258







-
-


-
+

-
+















-
+











-
-



-
+

-
+



















-
-






-


















-
-







    } else {
        return [super validateUserInterfaceItem:anItem];
    }
}

- (void) orderFrontStandardAboutPanel: (id) sender
{
    (void)sender;

    if (!_eventInterp || !Tcl_FindCommand(_eventInterp, "tkAboutDialog",
	    NULL, 0) || (GetCurrentEventKeyModifiers() & optionKey)) {
	[super orderFrontStandardAboutPanel:nil];
	TkAboutDlg();
    } else {
	int code = Tcl_EvalEx(_eventInterp, "tkAboutDialog", TCL_INDEX_NONE,
	int code = Tcl_EvalEx(_eventInterp, "tkAboutDialog", -1,
		TCL_EVAL_GLOBAL);

	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
	Tcl_ResetResult(_eventInterp);
    }
}

- (void) showHelp: (id) sender
{
    if (!_eventInterp || !Tcl_FindCommand(_eventInterp,
	    "::tk::mac::ShowHelp", NULL, 0)) {
	[super showHelp:sender];
    } else {
	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ShowHelp", TCL_INDEX_NONE,
	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ShowHelp", -1,
		TCL_EVAL_GLOBAL);

	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
	Tcl_ResetResult(_eventInterp);
    }
}

- (void) tkSource: (id) sender
{
    (void)sender;

    if (_eventInterp) {
	if (Tcl_EvalEx(_eventInterp, "tk_getOpenFile -filetypes {"
		"{{TCL Scripts} {.tcl} TEXT} {{Text Files} {} TEXT}}",
		TCL_INDEX_NONE, TCL_EVAL_GLOBAL) == TCL_OK) {
		-1, TCL_EVAL_GLOBAL) == TCL_OK) {
	    Tcl_Obj *path = Tcl_GetObjResult(_eventInterp);
	    Tcl_Size len;
	    int len;

	    Tcl_GetStringFromObj(path, &len);
	    if (len) {
		Tcl_IncrRefCount(path);

		int code = Tcl_FSEvalFileEx(_eventInterp, path, NULL);

		if (code != TCL_OK) {
		    Tcl_BackgroundException(_eventInterp, code);
		}
		Tcl_DecrRefCount(path);
	    }
	}
	Tcl_ResetResult(_eventInterp);
    }
}

- (void) tkDemo: (id) sender
{
	(void)sender;

    if (_eventInterp) {
	Tcl_Obj *path = GetWidgetDemoPath(_eventInterp);

	if (path) {
	    Tcl_IncrRefCount(path);

	    [_demoMenuItem setHidden:YES];
	    int code = Tcl_FSEvalFileEx(_eventInterp, path, NULL);

	    if (code != TCL_OK) {
		Tcl_BackgroundException(_eventInterp, code);
	    }
	    Tcl_DecrRefCount(path);
	    Tcl_ResetResult(_eventInterp);
	}
    }
}
@end

#pragma mark TKContentView(TKMenus)

@implementation TKContentView(TKMenus)

- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>) anItem
{
    (void)anItem;

    return YES;
}

#define EDIT_ACTION(a, e) \
    - (void) a: (id) sender \
    { \
	if ([sender isKindOfClass:[NSMenuItem class]]) { \
326
327
328
329
330
331
332
333

334
335
336
337




338
339
340
341
342

343
344
345
346



347
348
349
350
351
352
353
286
287
288
289
290
291
292

293
294



295
296
297
298
299

300


301

302


303
304
305
306
307
308
309
310
311
312







-
+

-
-
-
+
+
+
+

-

-
-
+
-

-
-
+
+
+







 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetWidgetDemoPath(
    Tcl_Interp *interp)
{
    Tcl_Obj *result = NULL;
    Tcl_Obj *libpath, *result = NULL;

    if (Tcl_EvalEx(interp, "::tk::pkgconfig get demodir,runtime",
		   TCL_INDEX_NONE, TCL_EVAL_GLOBAL) == TCL_OK) {
	Tcl_Obj *libpath, *demo[1] = { Tcl_NewStringObj("widget", 6) };
    libpath = Tcl_GetVar2Ex(interp, "tk_library", NULL, TCL_GLOBAL_ONLY);
    if (libpath) {
	Tcl_Obj *demo[2] = {	Tcl_NewStringObj("demos", 5),
				Tcl_NewStringObj("widget", 6) };

	libpath = Tcl_GetObjResult(interp);
	Tcl_IncrRefCount(libpath);
	Tcl_IncrRefCount(demo[0]);
	result = Tcl_FSJoinToPath(libpath, 1, demo);
	result = Tcl_FSJoinToPath(libpath, 2, demo);
	Tcl_DecrRefCount(demo[0]);
	Tcl_DecrRefCount(libpath);
    }
    Tcl_ResetResult(interp);
    } else {
	Tcl_ResetResult(interp);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXHandleMenuSelect --
361
362
363
364
365
366
367
368
369
370



371
372
373























374
375
376
377
378
379
380
320
321
322
323
324
325
326



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362







-
-
-
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXHandleMenuSelect(
    TCL_UNUSED(short),
    TCL_UNUSED(unsigned short),
    TCL_UNUSED(int))
    short theMenu,
    unsigned short theItem,
    int optionKeyPressed)
{
    Tcl_Panic("TkMacOSXHandleMenuSelect: Obsolete, no more Carbon!");
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInitMenus --
 *
 *	This procedure initializes the Macintosh menu bar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXInitMenus(
    Tcl_Interp *interp)
{
    [NSApp _setupMenus];
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateEditEvent --
 *
 *	Takes an edit menu item and posts the corasponding a virtual event to
389
390
391
392
393
394
395
396

397
398
399

400
401

402
403
404
405


406
407
408
409
410
411
412
413
414
415
416









417
418
419
420
421
422





423
424
425
426
427
428
429
371
372
373
374
375
376
377

378
379
380

381
382

383
384
385


386
387
388
389









390
391
392
393
394
395
396
397
398
399





400
401
402
403
404
405
406
407
408
409
410
411







-
+


-
+

-
+


-
-
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+







 *----------------------------------------------------------------------
 */

static void
GenerateEditEvent(
    const char *name)
{
    union {XEvent general; XVirtualEvent virt;} event;
    XVirtualEvent event;
    int x, y;
    TkWindow *winPtr = TkMacOSXGetTkWindow([NSApp keyWindow]);
    Tk_Window tkwin;
    Tk_Window tkwin = (Tk_Window) winPtr;

    if (!winPtr) {
    if (tkwin == NULL) {
	return;
    }
    tkwin = (Tk_Window)winPtr->dispPtr->focusPtr;
    if (!tkwin) {
    tkwin = (Tk_Window) winPtr->dispPtr->focusPtr;
    if (tkwin == NULL) {
	return;
    }
    bzero(&event, sizeof(event));
    event.virt.type = VirtualEvent;
    event.virt.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.virt.send_event = false;
    event.virt.display = Tk_Display(tkwin);
    event.virt.event = Tk_WindowId(tkwin);
    event.virt.root = XRootWindow(Tk_Display(tkwin), 0);
    event.virt.subwindow = None;
    event.virt.time = TkpGetMS();
    bzero(&event, sizeof(XVirtualEvent));
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.send_event = false;
    event.display = Tk_Display(tkwin);
    event.event = Tk_WindowId(tkwin);
    event.root = XRootWindow(Tk_Display(tkwin), 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    XQueryPointer(NULL, winPtr->window, NULL, NULL,
	    &event.virt.x_root, &event.virt.y_root, &x, &y, &event.virt.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.virt.x, &event.virt.y);
    event.virt.same_screen = true;
    event.virt.name = Tk_GetUid(name);
    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
	    &event.x_root, &event.y_root, &x, &y, &event.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.x, &event.y);
    event.same_screen = true;
    event.name = Tk_GetUid(name);
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

#pragma mark -

#pragma mark NSMenu & NSMenuItem Utilities

@implementation NSMenu(TKUtils)

Changes to macosx/tkMacOSXMouseEvent.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43



44
45
46

47
48

49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



94
95
96
97
98
99

100
101

102
103

104
105
106
107
108
109
110
111
112

113
114
115
116


117
118
119
120

121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190


191
192

193
194
195
196

197
198
199
200
201

202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218

219
220

221
222

223
224
225
226
227

228
229

230
231
232
233
234

235
236
237
238
239
240
241
242
243
244

245
246
247

248
249
250
251
252
253
254




255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273

274
275
276
277


278
279
280
281
282

283
284
285
286
287
288

289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304
305
306
307


308
309
310
311

312
313
314



315
316
317
318



319
320

321
322
323


324
325


326
327
328
329
330
331
332
333




334
335

336
337
338
339
340
341
342
343
344





345
346
347
348


349
350
351
352
353
354
355

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379



380
381
382

383
384

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410








411
412
413


414
415


416
417
418

419
420
421
422
423
424




425
426
427
428


429
430
431
432
433
434
435

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452



453
454
455
456

457
458

459
460
461
462
463
464
465
466
467
468
469
470
471
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15

16
17

18
19
20
21
22
23
24
25
26



27
28
29
30
31
32
33
34
35

36
37



38
39
40



41


42













43











44




















45
46
47






48
49

50
51

52









53




54
55




56





57








58



























59






60


61




62















63
64


65




66





67







68










69


70


71





72


73





74










75



76







77
78
79
80










81









82




83
84





85






86








87











88
89




90



91
92
93




94
95
96


97



98
99


100
101








102
103
104
105


106




107




108
109
110
111
112

113


114
115







116


















117






118
119
120



121


122

















123









124
125
126
127
128
129
130
131
132


133
134


135
136



137






138
139
140
141




142
143







144

















145
146
147




148


149



150


151
152
153
154
155
156
157






-
-
+
+







-
+

-









-
-
-

+
+






-


-
-
-
+
+
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+

-
+

-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-

-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
+
+
+
-
-
-
-
+
+
+
-
-
+
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-

-
-
-
-
+
+
+
+
+
-

-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+
-
-
+
+
-
-
-
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
-
-
+
-
-
-

-
-







/*
 * tkMacOSXMouseEvent.c --
 *
 *	This file implements functions that decode & handle mouse events on
 *	MacOS X.
 *
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXConstants.h"

typedef struct {
    unsigned int state;
    long delta;
    Window window;
    Point global;
    Point local;
} MouseEventData;

static Tk_Window captureWinPtr = NULL;	/* Current capture window; may be
					 * NULL. */

static int		GenerateButtonEvent(MouseEventData *medPtr);
static unsigned int	ButtonModifiers2State(UInt32 buttonState,
					      UInt32 keyModifiers);

#pragma mark TKApplication(TKMouseEvent)

enum {
    NSWindowWillMoveEventType = 20
};

/*
 * In OS X 10.6 an NSEvent of type NSMouseMoved would always have a non-Nil
 * window attribute pointing to the key window.  As of 10.8 this behavior had
 * changed.  The new behavior was that if the mouse were ever moved outside of
 * a window, all subsequent NSMouseMoved NSEvents would have a Nil window
 * window attribute pointing to the active window.  As of 10.8 this behavior
 * had changed.  The new behavior was that if the mouse were ever moved outside
 * of a window, all subsequent NSMouseMoved NSEvents would have a Nil window
 * attribute until the mouse returned to the window.  In 11.1 it changed again.
 * The window attribute can be non-nil, but referencing a window which does not
 * belong to the application.
 * attribute.  To work around this the TKApplication remembers the last non-Nil
 */

 * window that it received in a mouse event. If it receives an NSEvent with a
/* The basic job of tkProcessMouseEvent is to generate a call to
 * Tk_UpdatePointer.  That function receives a Tk_Window which (ignoring cases
 * when a grab is in effect) should be the highest window within the focused
 * toplevel that contains the pointer, as well as the pointer location in
 * screen coordinates and the current button state.  Tk maintains a cache of
 * these three values.  A change in any of these values causes Tk_UpdatePointer
 * to generate, respectively, Enter/Leave events, or Motion events, or
 * button Press/Release events. The Tk_Window value is allowed to be NULL,
 * which indicates that the pointer is not in the focused toplevel.
 *
 * Enter or Leave events for toplevel windows are generated when the Tk_Window
 * value changes to or from NULL.  This is problematic on macOS due to the fact
 * that Tk_UpdatePointer does not generate Motion events when the Tk_Window
 * Nil window attribute then the saved window is used.
 * value is NULL.  A consequence of this is that Tk_UpdatePointer will either
 * fail to generate correct Enter/Leave events for toplevels or else be unable
 * to generate Motion events when the pointer is outside of the focus window.
 * It is important to be able to generate such events because otherwise a
 * scrollbar on the edge of a toplevel becomes unusable.  Any time that the
 * pointer wanders out of the window during a scroll, the scroll will stop.
 * That is an extremely annoying and unexpected behavior.  Much of the code in
 * this module, including the trickiest parts, is devoted to working around
 * this problem.  The other tricky parts are related to transcribing Apple's
 * NSMouseEntered, NSMouseExited, and NSLeftMouseDragged events into a form
 * that makes sense to Tk.
 */


@implementation TKApplication(TKMouseEvent)

- (NSEvent *) tkProcessMouseEvent: (NSEvent *) theEvent
{
    NSWindow *eventWindow = [theEvent window];
    NSEventType eventType = [theEvent type];
    TKContentView *contentView = [eventWindow contentView];
    NSPoint location = [theEvent locationInWindow];
    //NSPoint viewLocation = [contentView convertPoint:location fromView:nil];
    TkWindow *winPtr = NULL, *grabWinPtr, *scrollTarget = NULL;
    Tk_Window tkwin = NULL, capture, target;
    NSPoint local, global;
    NSInteger button;
    TkWindow *newFocus = NULL;
    int win_x, win_y;
    unsigned int buttonState = 0;
    Bool isTestingEvent = NO;
    Bool isMotionEvent = NO;

@implementation TKApplication(TKMouseEvent)
- (NSEvent *) tkProcessMouseEvent: (NSEvent *) theEvent
    Bool isOutside = NO;
    Bool firstDrag = NO;
    static Bool ignoreDrags = NO;
    static Bool ignoreUpDown = NO;
    static NSTimeInterval timestamp = 0;

{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), theEvent);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
#endif

    NSWindow*    eventWindow = [theEvent window];
    /*
     * If this event is not for a Tk toplevel, it should normally just be
     * passed up the responder chain.  However, there is are two exceptions.
     * One is for synthesized events, which are used in testing.  Those events
     * are recognized by having their timestamp set to 0.  The other is for
     * motion events sent by the local event monitor, which will have their
     * window attribute set to nil.
     */

    NSEventType	 eventType = [theEvent type];
    if (![eventWindow isMemberOfClass:[TKWindow class]] &&
	![eventWindow isMemberOfClass:[TKPanel class]]) {
	if ([theEvent timestamp] == 0) {
	    isTestingEvent = YES;
#if 0
    NSTrackingArea  *trackingArea = nil;
	    eventWindow = [NSApp keyWindow];
	}
	if (eventType == NSLeftMouseDragged ||
	    eventType == NSMouseMoved) {
    NSInteger eventNumber, clickCount, buttonNumber;
	    eventWindow = [NSApp keyWindow];
	    isMotionEvent = YES;
	}
	if (!isTestingEvent && !isMotionEvent) {
	    return theEvent;
#endif
	}
    } else if (!NSPointInRect(location, [contentView bounds])) {
	isOutside = YES;
    }
    button = [theEvent buttonNumber] + Button1;
    if ((button & -2) == Button2) {
	button ^= 1; /* Swap buttons 2/3 */
    }
    switch (eventType) {
    case NSRightMouseUp:
    case NSOtherMouseUp:
	buttonState &= ~Tk_GetButtonMask(button);
	break;
    case NSLeftMouseDragged:
	buttonState |= Tk_GetButtonMask(button);
	if (![NSApp tkDragTarget]) {
	    if (isOutside) {
		ignoreDrags = YES;
	    } else {
		firstDrag = YES;
	    }
	}
	if (ignoreDrags) {
	    return theEvent;
	}
	if (![NSApp tkDragTarget]) {
	    [NSApp setTkDragTarget: [NSApp tkEventTarget]];
	}
	break;
    case NSRightMouseDragged:
    case NSOtherMouseDragged:
	isMotionEvent = YES;
    case NSRightMouseDown:
    case NSOtherMouseDown:
	buttonState |= Tk_GetButtonMask(button);
	break;
    case NSMouseEntered:
	if (![eventWindow isKeyWindow] || isOutside) {
	    return theEvent;
	}
	[NSApp setTkLiveResizeEnded:NO];
	[NSApp setTkPointerWindow:[NSApp tkEventTarget]];
	break;
    case NSMouseExited:
	if (![eventWindow isKeyWindow] || !isOutside) {
	    return theEvent;
    case NSCursorUpdate:
	}
	[NSApp setTkPointerWindow:nil];
	break;
    case NSLeftMouseUp:
    case NSLeftMouseDown:
	[NSApp setTkDragTarget: nil];
	if ([theEvent clickCount] == 2) {
	    ignoreUpDown = NO;
	}
	if (ignoreUpDown) {
	    return theEvent;
	}
	if (ignoreDrags) {
	    ignoreDrags = NO;
	    return theEvent;
	}
	buttonState &= ~Tk_GetButtonMask(Button1);
	break;
    case NSLeftMouseDown:

    case NSLeftMouseUp:
    case NSRightMouseDown:
	/*
	 * There are situations where Apple does not send NSLeftMouseUp events
    case NSRightMouseUp:
	 * even though the mouse button has been released.  One of these is
	 * whenever a menu is posted on the screen.  This causes Tk to have an
	 * inaccurate idea of the current button state and to behave strangely.
	 * (See ticket[a132b5507e].)  As a work-around we watch for NSButtonDown
    case NSOtherMouseDown:
	 * events that arrive when Tk thinks the button is already down and
	 * we attempt to correct Tk's cached button state by insering a call to
	 * Tk_UpdatePointer showing the button as up.
	 */

    case NSOtherMouseUp:
	if ([NSApp tkButtonState] & Tk_GetButtonMask(Button1)) {
	    int fakeState = [NSApp tkButtonState] & ~Tk_GetButtonMask(Button1);
	    int x = location.x;
	    int y = floor(TkMacOSXZeroScreenHeight() - location.y);
	    Tk_UpdatePointer((Tk_Window) [NSApp tkEventTarget], x, y, fakeState);
	}

    case NSLeftMouseDragged:
	/*
	 * Ignore left mouse button events which are in an NSWindow but outside
	 * of its contentView (see tickets [d72abe6b54] and [39cbacb9e8]).
	 * Ignore the first left button press after a live resize ends. (Apple
	 * sends the button press event that started the resize after the
	 * resize ends.  It should not be seen by Tk.  See tickets [d72abe6b54]
	 * and [39cbacb9e8]).  Ignore button press events when ignoreUpDown is
	 * set.  These are extraneous events which appear when double-clicking
	 * in a window without focus, causing duplicate Double-1 events (see
	 * ticket [7bda9882cb]).  When a LeftMouseDown event with clickCount 2
    case NSRightMouseDragged:
	 * is received we set the ignoreUpDown flag and we clear it when the
	 * matching LeftMouseUp with click count 2 is received.
    case NSOtherMouseDragged:
	 */

    case NSMouseMoved:
	/*
	 * Make sure we don't ignore LeftMouseUp and LeftMouseDown forever.
	 * Currently tkBind.c sets NEARBY_MS to 500 (the Windows default).
	 */

    case NSTabletPoint:
	if ([theEvent timestamp] - timestamp > 1) {
	    ignoreUpDown = NO;
    case NSTabletProximity:
	}
	if ([theEvent clickCount] == 2) {
	    if (ignoreUpDown == YES) {
		return theEvent;
	    } else {
    case NSScrollWheel:
		timestamp = [theEvent timestamp];
		ignoreUpDown = YES;
	    }
	}
	if (!isTestingEvent) {
	    NSRect bounds = [contentView bounds];
	    NSRect grip = NSMakeRect(bounds.size.width - 10, 0, 10, 10);
	    bounds = NSInsetRect(bounds, 2.0, 2.0);
	    if (!NSPointInRect(location, bounds)) {
		return theEvent;
        break;
	    }
	    if (NSPointInRect(location, grip)) {
		return theEvent;
    default: /* Unrecognized mouse event. */
	    }
	    if ([NSApp tkLiveResizeEnded]) {
		[NSApp setTkLiveResizeEnded:NO];
		return theEvent;
	    }
	}

	return theEvent;
    }

    /* Remember the window in case we need it next time. */
	/*
	 * If this click will change the focus, the Tk event should
	 * be sent to the toplevel which will be receiving focus rather than to
	 * the current focus window.  So reset tkEventTarget.
	 */

	if (eventWindow != [NSApp keyWindow]) {
	    NSWindow *w;

	    if (eventWindow && isOutside) {
    if (eventWindow && eventWindow != _windowWithMouse) {
		return theEvent;
	    }
	    for (w in [NSApp orderedWindows]) {
		if (NSPointInRect([NSEvent mouseLocation], [w frame])) {
		    newFocus = TkMacOSXGetTkWindow(w);
		    break;
		}
	    }
	    if (newFocus) {
	if (_windowWithMouse) {
		[NSApp setTkEventTarget: newFocus];
		[NSApp setTkPointerWindow: newFocus];
		target = (Tk_Window) newFocus;
	    }
	    [_windowWithMouse release];
	}
	}
	buttonState |= Tk_GetButtonMask(Button1);
	break;
    case NSMouseMoved:
	if (eventWindow && eventWindow != [NSApp keyWindow]) {
	_windowWithMouse = eventWindow;
	    return theEvent;
	}
	isMotionEvent = YES;
	break;
    case NSScrollWheel:

	[_windowWithMouse retain];
	/*
	 * Scroll wheel events are sent to the window containing the pointer,
	 * or ignored if no window contains the pointer.  See TIP #171.  Note,
	 * however, that TIP #171 proposed sending scroll wheel events to the
	 * focus window when no window contains the pointer.  That proposal was
	 * ultimately rejected.
	 */

    }
	scrollTarget = TkMacOSXGetTkWindow(eventWindow);
#if 0
    case NSCursorUpdate:
    case NSTabletPoint:
    case NSTabletProximity:
#endif
	break;
    default: /* This type of event is ignored. */
	return theEvent;
    }


    /* Create an Xevent to add to the Tk queue. */
    /*
     * Find the toplevel window for the event.
     */

    NSPoint global, local = [theEvent locationInWindow];
    if ([NSApp tkDragTarget]) {
	TkWindow *dragPtr = (TkWindow *) [NSApp tkDragTarget];
	TKWindow *dragWindow = nil;
    if (eventWindow) { /* local will be in window coordinates. */
	global = [eventWindow convertPointToScreen: local];
	local.y = [eventWindow frame].size.height - local.y;
	MacDrawable *topMacWin;
	if (dragPtr) {
	    dragWindow = (TKWindow *)TkMacOSXGetNSWindowForDrawable(
			    dragPtr->window);
	global.y = tkMacOSXZeroScreenHeight - global.y;
    } else { /* local will be in screen coordinates. */
	if (_windowWithMouse ) {
	}
	if (!dragWindow) {
	    eventWindow = _windowWithMouse;
	    [NSApp setTkDragTarget: nil];
	    target = NULL;
	    return theEvent;
	    global = local;
	    local = [eventWindow convertPointFromScreen: local];
	}
	topMacWin = TkMacOSXGetHostToplevel(dragPtr);
	    local.y = [eventWindow frame].size.height - local.y;
	    global.y = tkMacOSXZeroScreenHeight - global.y;
	if (topMacWin) {
	    winPtr = topMacWin->winPtr;
	}
    } else if (eventType == NSScrollWheel) {
	winPtr = scrollTarget;
    } else {
	winPtr = [NSApp tkEventTarget];
    }
	} else { /* We have no window. Use the screen???*/
	    local.y = tkMacOSXZeroScreenHeight - local.y;
	    global = local;
	}
    if (!winPtr) {

    }
	/*
	 * If we couldn't find a toplevel for this event we have to ignore it.
	 * (But this should never happen.)
	 */

#ifdef TK_MAC_DEBUG_EVENTS
	TkMacOSXDbgMsg("Event received with no Tk window.");
#endif

    Window window = TkMacOSXGetXWindow(eventWindow);
    Tk_Window tkwin = window ? Tk_IdToWindow(TkGetDisplayList()->display,
	    window) : NULL;
    if (!tkwin) {
	tkwin = TkMacOSXGetCapture();
	return theEvent;
    }
    tkwin = (Tk_Window) winPtr;

    if (!tkwin) {
	return theEvent; /* Give up.  No window for this event. */
    /*
     * Compute the mouse position in local (toplevel) and global (screen)
     * coordinates.  These are Tk coordinates, meaning that the local origin is
     * at the top left corner of the containing toplevel and the global origin
     * is at top left corner of the primary screen.
     */

    }
    global = [NSEvent mouseLocation];
    local = [eventWindow tkConvertPointFromScreen: global];
    global.x = floor(global.x);
    global.y = floor(TkMacOSXZeroScreenHeight() - global.y);
    local.x = floor(local.x);
    local.y = floor(eventWindow.frame.size.height - local.y);
    if (Tk_IsEmbedded(winPtr)) {
	TkWindow *contPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	if (Tk_IsTopLevel(contPtr)) {
	    local.x -= contPtr->wmInfoPtr->xInParent;
	    local.y -= contPtr->wmInfoPtr->yInParent;
	} else {
	    MacDrawable *topMacWin = TkMacOSXGetHostToplevel(winPtr);
	    if (topMacWin) {
		TkWindow* topPtr = topMacWin->winPtr;
		local.x -= (topPtr->wmInfoPtr->xInParent + contPtr->changes.x);
		local.y -= (topPtr->wmInfoPtr->yInParent + contPtr->changes.y);
	    }

	}
    }
    else {
    	if (winPtr && winPtr->wmInfoPtr) {
    	    local.x -= winPtr->wmInfoPtr->xInParent;
    	    local.y -= winPtr->wmInfoPtr->yInParent;
    TkWindow  *winPtr = (TkWindow *) tkwin;
    local.x -= winPtr->wmInfoPtr->xInParent;
    local.y -= winPtr->wmInfoPtr->yInParent;
    	} else {
    	    return theEvent;
    	}

    }

    int win_x, win_y;
    /*
     * Use the toplevel coordinates to decide which Tk window should receive
     * this event.  Also convert the toplevel coordinates into the coordinate
     * system of that window.  These converted coordinates are needed for
     * XEvents that we generate, namely ScrollWheel events and Motion events
     * when the mouse is outside of the focused toplevel.
     */

    if ([NSApp tkDragTarget]) {
	Tk_Window dragTarget = (Tk_Window) [NSApp tkDragTarget];
	Tk_Window dragWidget = NULL;
	int x, y;
	Tk_GetRootCoords(dragTarget, &x, &y);
	win_x = global.x - x;
	win_y = global.y - y;
	if (firstDrag) {
	    dragWidget = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &x, &y);
    tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y,
	    if (dragWidget) {
		[NSApp setTkDragTarget: (TkWindow *) dragWidget];
	    }
	}
	target = (Tk_Window) [NSApp tkDragTarget];
    } else {
	target = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y);
    }

		&win_x, &win_y);

    unsigned int state = 0;
    NSInteger button = [theEvent buttonNumber];
    EventRef eventRef = (EventRef)[theEvent eventRef];
    UInt32 buttons;
    OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord,
				     typeUInt32, NULL, sizeof(UInt32), NULL, &buttons);

    grabWinPtr = winPtr->dispPtr->grabWinPtr;

    if (err == noErr) {
    	state |= (buttons & ((1<<5) - 1)) << 8;
    /*
     * Ignore the event if a local grab is in effect and the Tk window is
    } else if (button < 5) {
	switch (eventType) {
     * not in the grabber's subtree.
     */

	case NSLeftMouseDown:
    if (grabWinPtr && /* There is a grab in effect ... */
	!winPtr->dispPtr->grabFlags && /* and it is a local grab ... */
	grabWinPtr->mainPtr == winPtr->mainPtr){ /* in the same application. */
	Tk_Window w;
	if (!target) {
	    return theEvent;
	case NSRightMouseDown:
	case NSLeftMouseDragged:
	case NSRightMouseDragged:
	case NSOtherMouseDown:
	}
	for (w = target; !Tk_IsTopLevel(w); w = Tk_Parent(w)) {
	    if (w == (Tk_Window)grabWinPtr) {
		break;
	    state |= 1 << (button + 8);
	    break;
	    }
	}
	if (w != (Tk_Window)grabWinPtr) {
	    return theEvent;
	}
    }

	default:
    /*
     * Ignore the event if a global grab is in effect and the Tk window is
     * not in the grabber's subtree.
     */

    if (grabWinPtr && /* There is a grab in effect ... */
	winPtr->dispPtr->grabFlags && /* and it is a global grab ... */
	grabWinPtr->mainPtr == winPtr->mainPtr) { /* in the same application. */
	Tk_Window w;
	if (!target) {
	    return theEvent;
	}
	for (w = target; !Tk_IsTopLevel(w); w = Tk_Parent(w)) {
	    if (w == (Tk_Window)grabWinPtr) {
		break;
	    }
	}
	    break;
	}
    }
	if (w != (Tk_Window)grabWinPtr) {
	    /* Force the focus back to the grab window. */
	    TkpChangeFocus(grabWinPtr, 1);
	}

    }

    NSUInteger modifiers = [theEvent modifierFlags];
    /*
     *  Translate the current button state into Tk's format.
     */

    unsigned int state = buttonState;
    NSUInteger modifiers = [theEvent modifierFlags];
    if (modifiers & NSAlphaShiftKeyMask) {
	state |= LockMask;
    }
    if (modifiers & NSShiftKeyMask) {
	state |= ShiftMask;
    }
    if (modifiers & NSControlKeyMask) {
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
504
505
506
507
508

509
510

511
512
513


514
515
516
517
518
519
520
521



522
523

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552


553
554
555
556
557


558
559
560
561
562
563
564
565
566
567
568

569
570
571
572
573
574
575


576
577
578
579
580
581
582
583









584
585
586
587
588






589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616




























617
618
619
620
621
622
623
165
166
167
168
169
170
171

172






173


174












175


176



177
178








179
180
181
182

183





























184
185
186
187
188


189
190











191







192
193








194
195
196
197
198
199
200
201
202





203
204
205
206
207
208





















209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250







-

-
-
-
-
-
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+



-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    }
    if (modifiers & NSNumericPadKeyMask) {
	state |= Mod3Mask;
    }
    if (modifiers & NSFunctionKeyMask) {
	state |= Mod4Mask;
    }
    [NSApp setTkButtonState:state];

    /*
     * Send XEvents.  We do this here for Motion events outside of the focused
     * toplevel and for MouseWheel events.  In other cases the XEvents will be
     * sent when we call Tk_UpdatePointer.
     */

    if (eventType != NSScrollWheel) {
	if ([NSApp tkDragTarget]) {

#ifdef TK_MAC_DEBUG_EVENTS
	    /*
	     * When dragging the mouse into the resize area Apple shows the
	     * left button to be up, which confuses Tk_UpdatePointer.  So
	     * we make sure that the button state appears the way that Tk
	     * expects.
	     */

	    state |= Tk_GetButtonMask(Button1);
	}
	if (eventType == NSMouseEntered) {
	    Tk_UpdatePointer((Tk_Window) [NSApp tkPointerWindow],
				 global.x, global.y, state);
	TKLog(@"UpdatePointer %p x %f.0 y %f.0 %d", tkwin, global.x, global.y, state);
	} else if (eventType == NSMouseExited) {
	    if ([NSApp tkDragTarget]) {
#endif
	    	Tk_UpdatePointer((Tk_Window) [NSApp tkDragTarget],
	    			 global.x, global.y, state);
	    } else {
	Tk_UpdatePointer(tkwin, global.x, global.y, state);
    } else { /* handle scroll wheel event */
	    Tk_UpdatePointer(NULL, global.x, global.y, state);
	    }
	} else if (eventType == NSMouseMoved ||
		   eventType == NSLeftMouseDragged) {
	    if ([NSApp tkPointerWindow]) {
		Tk_UpdatePointer(target, global.x, global.y, state);
	    } else {
		XEvent xEvent = {0};
	CGFloat delta;
	int coarseDelta;
	XEvent xEvent;

		xEvent.type = MotionNotify;
	xEvent.type = MouseWheelEvent;
		xEvent.xany.send_event = false;
		xEvent.xany.display = Tk_Display(target);
		xEvent.xany.window = Tk_WindowId(target);
		xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
		xEvent.xmotion.x = win_x;
		xEvent.xmotion.y = win_y;
		xEvent.xmotion.x_root = global.x;
		xEvent.xmotion.y_root = global.y;
		xEvent.xmotion.state = state;
		Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);

		/*
		 * Tk_UpdatePointer must not be called in this case.  Doing so
		 * will break scrollbars; dragging will stop when the mouse
		 * leaves the window.
		 */

	    }
	} else {
	    Tk_UpdatePointer(target, global.x, global.y, state);
	}
    } else {
	static unsigned long scrollCounter = 0;
	int delta;
	CGFloat Delta;
	Bool deltaIsPrecise = [theEvent hasPreciseScrollingDeltas];
	XEvent xEvent = {0};
	xEvent.xbutton.x = win_x;
	xEvent.xbutton.y = win_y;
	xEvent.xbutton.x = local.x;
	xEvent.xbutton.y = local.y;
	xEvent.xbutton.x_root = global.x;
	xEvent.xbutton.y_root = global.y;
	xEvent.xany.send_event = false;
	xEvent.xany.display = Tk_Display(target);
	xEvent.xany.window = Tk_WindowId(target);
	xEvent.xany.display = Tk_Display(tkwin);
	xEvent.xany.window = Tk_WindowId(tkwin);
	if (deltaIsPrecise) {
	    int deltaX = [theEvent scrollingDeltaX];
	    int deltaY = [theEvent scrollingDeltaY];
	    delta = (deltaX << 16) | (deltaY & 0xffff);
	    if (delta != 0) {
	     	xEvent.type = TouchpadScroll;
	     	xEvent.xbutton.state = state;
	     	xEvent.xkey.keycode = delta;
	     	xEvent.xany.serial = scrollCounter++;
	     	Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	    }

	} else {
	    /*
	     * A low precision scroll is 120 or -120 wheel units per click.
	     * Each click generates one event.
	     */
	    Delta = [theEvent scrollingDeltaY];
	    if (Delta != 0.0) {
	delta = [theEvent deltaY];
	if (delta != 0.0) {
		xEvent.type = MouseWheelEvent;
		xEvent.xbutton.state = state;
		xEvent.xkey.keycode = Delta > 0.0 ? 120 : -120;
		xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
		Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	    }
	    Delta = [theEvent scrollingDeltaX];
	    if (Delta != 0.0) {
	    coarseDelta = (delta > -1.0 && delta < 1.0) ?
		(signbit(delta) ? -1 : 1) : lround(delta);
	    xEvent.xbutton.state = state;
	    xEvent.xkey.keycode = coarseDelta;
	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	}
	delta = [theEvent deltaX];
	if (delta != 0.0) {
		xEvent.type = MouseWheelEvent;
		xEvent.xbutton.state = state | ShiftMask;
		xEvent.xkey.keycode = Delta > 0 ? 120 : -120;
		xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
		Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	    coarseDelta = (delta > -1.0 && delta < 1.0) ?
		(signbit(delta) ? -1 : 1) : lround(delta);
	    xEvent.xbutton.state = state | ShiftMask;
	    xEvent.xkey.keycode = coarseDelta;
	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	    }
	}
    }

    /*
     * If button events are being captured, and the target is not in the
     * subtree below the capturing window, then the NSEvent should not be sent
     * up the responder chain.  This avoids, for example, beeps when clicking
     * the mouse button outside of a posted combobox.  See ticket [eb26d4ec8e].
     */

    capture = TkpGetCapture();
    if (capture && eventType == NSLeftMouseDown) {
	Tk_Window w;
	for (w = target; w != NULL;  w = Tk_Parent(w)) {
	    if (w == capture) {
		break;
	    }
	}
	if (w != capture) {
	    return nil;
	}
    }
    return theEvent;
}
@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXKeyModifiers --
 *
 *	Returns the current state of the modifier keys.
 *
 * Results:
 *	An OS Modifier state.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

EventModifiers
TkMacOSXModifierState(void)
{
    UInt32 keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return (EventModifiers) (keyModifiers & USHRT_MAX);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXButtonKeyState --
 *
 *	Returns the current state of the button & modifier keys.
631
632
633
634
635
636
637































































638

639
640
641
642
643
644
645
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







 *
 *----------------------------------------------------------------------
 */

unsigned int
TkMacOSXButtonKeyState(void)
{
    UInt32 buttonState = 0, keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    buttonState = isFrontProcess ? GetCurrentEventButtonState() :
	    GetCurrentButtonState();
    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return ButtonModifiers2State(buttonState, keyModifiers);
}

/*
 *----------------------------------------------------------------------
 *
 * ButtonModifiers2State --
 *
 *	Converts Carbon mouse button state and modifier values into a Tk
 *	button/modifier state.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static unsigned int
ButtonModifiers2State(
    UInt32 buttonState,
    UInt32 keyModifiers)
{
    unsigned int state;

    /*
     * Tk supports at most 5 buttons.
     */

    state = (buttonState & ((1<<5) - 1)) << 8;

    if (keyModifiers & alphaLock) {
	state |= LockMask;
    }
    if (keyModifiers & shiftKey) {
	state |= ShiftMask;
    }
    if (keyModifiers & controlKey) {
	state |= ControlMask;
    }
    if (keyModifiers & cmdKey) {
	state |= Mod1Mask;		/* command key */
    }
    if (keyModifiers & optionKey) {
	state |= Mod2Mask;		/* option key */
    }
    if (keyModifiers & kEventKeyModifierNumLockMask) {
	state |= Mod3Mask;
    }
    if (keyModifiers & kEventKeyModifierFnMask) {
	state |= Mod4Mask;
    }

    return [NSApp tkButtonState];
    return state;
}

/*
 *----------------------------------------------------------------------
 *
 * XQueryPointer --
 *
655
656
657
658
659
660
661
662

663
664
665


666
667
668
669
670
671
672
673
674
675
676
677
678
679
680


681
682
683
684
685

686
687
688
689
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718

719
720
721
722
723
724
725
345
346
347
348
349
350
351

352
353


354
355
356
357
358
359
360
361
362
363
364
365
366
367
368


369
370
371
372
373
374

375
376
377
378
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415







-
+

-
-
+
+













-
-
+
+




-
+











-
+




















-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

Bool
XQueryPointer(
    TCL_UNUSED(Display *),
    Display *display,
    Window w,
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window *),
    Window *root_return,
    Window *child_return,
    int *root_x_return,
    int *root_y_return,
    int *win_x_return,
    int *win_y_return,
    unsigned int *mask_return)
{
    int getGlobal = (root_x_return && root_y_return);
    int getLocal = (win_x_return && win_y_return && w != None);

    if (getGlobal || getLocal) {
	NSPoint global = [NSEvent mouseLocation];

	if (getLocal) {
	    MacDrawable *macWin = (MacDrawable *)w;
	    NSWindow *win = TkMacOSXGetNSWindowForDrawable(w);
	    MacDrawable *macWin = (MacDrawable *) w;
	    NSWindow *win = TkMacOSXDrawableWindow(w);

	    if (win) {
		NSPoint local;

		local = [win tkConvertPointFromScreen:global];
		local = [win convertPointFromScreen:global];
		local.y = [win frame].size.height - local.y;
		if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
		    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
		    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
		}
		*win_x_return = local.x;
		*win_y_return = local.y;
	    }
	}
	if (getGlobal) {
	    *root_x_return = global.x;
	    *root_y_return = TkMacOSXZeroScreenHeight() - global.y;
	    *root_y_return = tkMacOSXZeroScreenHeight - global.y;
	}
    }
    if (mask_return) {
	*mask_return = TkMacOSXButtonKeyState();
    }
    return True;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenerateButtonEventForXPointer --
 *
 *	This procedure generates an X button event for the current pointer
 *	state as reported by XQueryPointer().
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue. Grab state may
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkGenerateButtonEventForXPointer(
742
743
744
745
746
747
748
749

750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769
770


771
772
773
774
775
776
777
778
779
780
781

782
783

784
785
786
787
788
789
790

791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808

809
810
811
812
813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
842
843
844
845

846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871

872
873
874

875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892

893
894


895
896

897
898
899
900
901
902
903
904
905


906
907
908
909

910
911
912
913
914
915
916
917
918
919

920
921
922
923

924
925
926
927
928
929

930
931
932
933

934
935


936
937
938
939
940
941
942
943
944
945
946
947
432
433
434
435
436
437
438

439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
455
456
457
458


459
460
461
462
463
464
465
466
467
468
469
470

471
472

473
474
475
476
477
478
479

480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511

512

513
514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539

















540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557










558


559
560


561









562
563




564










565




566






567




568


569
570


571
572
573
574
575
576
577
578
579
580







-
+






-
+












-
-
+
+










-
+

-
+






-
+

















-
+













-
+
-










-
+











+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





+



+








-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
+
+
-
-











/*
 *----------------------------------------------------------------------
 *
 * TkGenerateButtonEvent --
 *
 *	Given a global x & y position and the button key status this procedure
 *	generates the appropriate X button event. It also handles the state
 *	generates the appropiate X button event. It also handles the state
 *	changes needed to implement implicit grabs.
 *
 * Results:
 *	True if event(s) are generated, false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue. Grab state may
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

int
TkGenerateButtonEvent(
    int x,			/* X location of mouse, */
    int y,			/* Y location of mouse. */
    Window window,		/* X Window containing button event. */
    unsigned int state)		/* Button Key state suitable for X event. */
{
    MacDrawable *macWin = (MacDrawable *)window;
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(window);
    MacDrawable *macWin = (MacDrawable *) window;
    NSWindow *win = TkMacOSXDrawableWindow(window);
    MouseEventData med;

    bzero(&med, sizeof(MouseEventData));
    med.state = state;
    med.window = window;
    med.global.h = x;
    med.global.v = y;
    med.local = med.global;

    if (win) {
	NSPoint local = NSMakePoint(x, TkMacOSXZeroScreenHeight() - y);
	NSPoint local = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);

	local = [win tkConvertPointFromScreen:local];
	local = [win convertPointFromScreen:local];
	local.y = [win frame].size.height - local.y;
	if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
	    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
	    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
	}
	med.local.h = local.x;
	med.local.v = TkMacOSXZeroScreenHeight() - local.y;
	med.local.v = tkMacOSXZeroScreenHeight - local.y;
    }

    return GenerateButtonEvent(&med);
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateButtonEvent --
 *
 *	Generate an X button event from a MouseEventData structure. Handles
 *	the state changes needed to implement implicit grabs.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue. Grab state may
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateButtonEvent(
    MouseEventData *medPtr)
{
    Tk_Window tkwin;
    int dummy;
    TkDisplay *dispPtr;

#ifdef UNUSED
#if UNUSED

    /*
     * ButtonDown events will always occur in the front window. ButtonUp
     * events, however, may occur anywhere on the screen. ButtonUp events
     * should only be sent to Tk if in the front window or during an implicit
     * grab.
     */

    if ((medPtr->activeNonFloating == NULL)
	    || ((!(TkpIsWindowFloating(medPtr->whichWin))
	    && (medPtr->activeNonFloating != medPtr->whichWin))
	    && TkpGetCapture() == NULL)) {
	    && TkMacOSXGetCapture() == NULL)) {
	return false;
    }
#endif

    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window);

    if (tkwin != NULL) {
	tkwin = Tk_TopCoordsToWindow(tkwin, medPtr->local.h, medPtr->local.v,
		&dummy, &dummy);
    }

    Tk_UpdatePointer(tkwin, medPtr->global.h, medPtr->global.v, medPtr->state);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpWarpPointer --
 *
 *	Move the mouse cursor to the screen location specified by the warpX and
 *	warpY fields of a TkDisplay.
 *
 * Results:
 *	None
 *
 * Side effects:
 *	The mouse cursor is moved.
 *
 *----------------------------------------------------------------------
 */

void
TkpWarpPointer(
    TkDisplay *dispPtr)
{
    CGPoint pt;
    UInt32 buttonState;

    if (dispPtr->warpWindow) {
	int x, y;

	Tk_GetRootCoords(dispPtr->warpWindow, &x, &y);
	pt.x = x + dispPtr->warpX;
	pt.y = y + dispPtr->warpY;
    } else {
	pt.x = dispPtr->warpX;
	pt.y = dispPtr->warpY;
    }

    CGWarpMouseCursorPosition(pt);

    if (dispPtr->warpWindow) {
        TkGenerateButtonEventForXPointer(Tk_WindowId(dispPtr->warpWindow));
    } else {
        TkGenerateButtonEventForXPointer(None);
    }
}

/*
    /*
 *----------------------------------------------------------------------
 *
     * Tell the OSX core to generate the events to make it happen.
     */
 * TkpSetCapture --
 *

 *	This function captures the mouse so that all future events will be
 *	reported to this window, even if the mouse is outside the window. If
 *	the specified window is NULL, then the mouse is released.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the capture flag and captures the mouse.
    buttonState = [NSEvent pressedMouseButtons];
    CGEventType type = kCGEventMouseMoved;
 *
 *----------------------------------------------------------------------
 */

    CGEventRef theEvent = CGEventCreateMouseEvent(NULL,
void
TkpSetCapture(
    TkWindow *winPtr)		/* Capture window, or NULL. */
{
    while (winPtr && !Tk_IsTopLevel(winPtr)) {
	winPtr = winPtr->parentPtr;
    }
    captureWinPtr = (Tk_Window)winPtr;
}

						  type,
/*
 *----------------------------------------------------------------------
 *
 * TkpGetCapture --
						  pt,
 *
 * Results:
 *	Returns the current grab window
 *
 * Side effects:
 *	None.
						  buttonState);
 *
 *----------------------------------------------------------------------
 */

    CGWarpMouseCursorPosition(pt);
Tk_Window
TkpGetCapture(void)
    CGEventPost(kCGHIDEventTap, theEvent);
    CFRelease(theEvent);
{
    return captureWinPtr;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXNotify.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18



19
20
21
22
23
24
25
26
27

28
29
30
31
32



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119









120
121
122
123

124
125
126
127







128
129
130








131
132



133
134
135



136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25
26
27

28
29
30



31
32
33















































































34
35
36





37
38
39
40
41
42
43
44
45




46




47
48
49
50
51
52
53



54
55
56
57
58
59
60
61


62
63
64



65
66
67
68



69
70
71
72




































73
74













75
76
77
78
79
80
81






-
-
-
-
+
+
+
+






-
-
+
+
+








-
+


-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
+
+
+

-
-
-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * tkMacOSXNotify.c --
 *
 *	This file contains the implementation of a tcl event source
 *	for the AppKit event loop.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2015 Marc Culler.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2015 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXConstants.h"
#include "tkMacOSXEvent.h"
#include <tclInt.h>
#include <pthread.h>
#import <objc/objc-auto.h>

/* This is not used for anything at the moment. */
typedef struct ThreadSpecificData {
    int initialized;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

#define TSD_INIT() ThreadSpecificData *tsdPtr = (ThreadSpecificData *) \
#define TSD_INIT() ThreadSpecificData *tsdPtr = \
	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData))

static void TkMacOSXNotifyExitHandler(void *clientData);
static void TkMacOSXEventsSetupProc(void *clientData, int flags);
static void TkMacOSXEventsCheckProc(void *clientData, int flags);
static void TkMacOSXNotifyExitHandler(ClientData clientData);
static void TkMacOSXEventsSetupProc(ClientData clientData, int flags);
static void TkMacOSXEventsCheckProc(ClientData clientData, int flags);

#ifdef TK_MAC_DEBUG_EVENTS
static const char *Tk_EventName[39] = {
    "",
    "",
    "KeyPress",		/*2*/
    "KeyRelease",      	/*3*/
    "ButtonPress",     	/*4*/
    "ButtonRelease",	/*5*/
    "MotionNotify",    	/*6*/
    "EnterNotify",     	/*7*/
    "LeaveNotify",     	/*8*/
    "FocusIn",		/*9*/
    "FocusOut",		/*10*/
    "KeymapNotify",    	/*11*/
    "Expose",		/*12*/
    "GraphicsExpose",	/*13*/
    "NoExpose",		/*14*/
    "VisibilityNotify",	/*15*/
    "CreateNotify",    	/*16*/
    "DestroyNotify",	/*17*/
    "UnmapNotify",     	/*18*/
    "MapNotify",       	/*19*/
    "MapRequest",      	/*20*/
    "ReparentNotify",	/*21*/
    "ConfigureNotify",	/*22*/
    "ConfigureRequest",	/*23*/
    "GravityNotify",	/*24*/
    "ResizeRequest",	/*25*/
    "CirculateNotify",	/*26*/
    "CirculateRequest",	/*27*/
    "PropertyNotify",	/*28*/
    "SelectionClear",	/*29*/
    "SelectionRequest",	/*30*/
    "SelectionNotify",	/*31*/
    "ColormapNotify",	/*32*/
    "ClientMessage",	/*33*/
    "MappingNotify",	/*34*/
    "VirtualEvent",    	/*35*/
    "ActivateNotify",	/*36*/
    "DeactivateNotify",	/*37*/
    "MouseWheelEvent"	/*38*/
};

static Tk_RestrictAction
InspectQueueRestrictProc(
     void *arg,
     XEvent *eventPtr)
{
    XVirtualEvent* ve = (XVirtualEvent*) eventPtr;
    const char *name;
    long serial = ve->serial;
    long time = eventPtr->xkey.time;

    if (eventPtr->type == VirtualEvent) {
	name = ve->name;
    } else {
	name = Tk_EventName[eventPtr->type];
    }
    fprintf(stderr, "    > %s;serial = %lu; time=%lu)\n",
	    name, serial, time);
    return TK_DEFER_EVENT;
}

/*
 * Debugging tool which prints the current Tcl queue.
 */

void DebugPrintQueue(void)
{
    void *oldArg;
    Tk_RestrictProc *oldProc;

    oldProc = Tk_RestrictEvents(InspectQueueRestrictProc, NULL, &oldArg);
    fprintf(stderr, "Current queue:\n");
    while (Tcl_DoOneEvent(TCL_ALL_EVENTS|TCL_DONT_WAIT)) {};
    Tk_RestrictEvents(oldProc, oldArg, &oldArg);
}
# endif

#pragma mark TKApplication(TKNotify)

@implementation TKApplication(TKNotify)
/*
 * Earlier versions of Tk would override nextEventMatchingMask here, adding a
 * call to displayIfNeeded on all windows after calling super. This would cause
 * windows to be redisplayed (if necessary) each time that an event was
@interface NSApplication(TKNotify)
/* We need to declare this hidden method. */
- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
@end

@implementation NSWindow(TKNotify)
- (id) tkDisplayIfNeeded
{
    if (![self isAutodisplay]) {
 * received.  This was intended to replace Apple's default autoDisplay
 * mechanism, which the earlier versions of Tk would disable.  When autoDisplay
 * is set to the default value of YES, the Apple event loop will call
 * displayIfNeeded on all windows at the beginning of each iteration of their
	[self displayIfNeeded];
 * event loop.  Since Tk does not call the Apple event loop, it was thought
 * that the autoDisplay behavior needed to be replicated.
 *
 * However, as of OSX 10.14 (Mojave) the autoDisplay property became
    }
    return nil;
}
@end

@implementation TKApplication(TKNotify)
/* Display all windows each time an event is removed from the queue.*/
 * deprecated.  Luckily it turns out that, even though we don't ever start the
 * Apple event loop, the Apple window manager still calls displayIfNeeded on
 * all windows on a regular basis, perhaps each time the queue is empty.  So we
- (NSEvent *) nextEventMatchingMask: (NSUInteger) mask
	untilDate: (NSDate *) expiration inMode: (NSString *) mode
	dequeue: (BOOL) deqFlag
{
    NSEvent *event = [super nextEventMatchingMask:mask
					untilDate:expiration
					   inMode:mode
					  dequeue:deqFlag];
 * no longer, and perhaps never did need to set autoDisplay to NO, nor call
 * displayIfNeeded on our windows.  We can just leave all of that to the window
    /* Retain this event for later use. Must be released.*/
    [event retain];
    [NSApp makeWindowsPerform:@selector(tkDisplayIfNeeded) inOrder:NO];
 * manager.
 */

    return event;
}

/*
 * Since the contentView is the first responder for a Tk Window, it is
 * responsible for sending events up the responder chain.  We also check the
 * pasteboard here.
 * Call super then check the pasteboard.
 */
- (void) sendEvent: (NSEvent *) theEvent
{

    /*
     * Workaround for an Apple bug.  When an accented character is selected
     * from an NSTextInputClient popup character viewer with the mouse, Apple
     * sends an event of type NSAppKitDefined and subtype 21. If that event is
     * sent up the responder chain it causes Apple to print a warning to the
     * console log and, extremely obnoxiously, also to stderr, which says
     * "Window move completed without beginning."  Apparently they are sending
     * the "move completed" event without having sent the "move began" event of
     * subtype 20, and then announcing their error on our stderr.  Also, of
     * course, no movement is occurring.  The popup is not movable and is just
     * being closed.  The bug has been reported to Apple.  If they ever fix it,
     * this block should be removed.
     */

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
    if ([theEvent type] == NSAppKitDefined) {
	static Bool aWindowIsMoving = NO;
	switch([theEvent subtype]) {
	case 20:
	    aWindowIsMoving = YES;
	    break;
	case 21:
	    if (aWindowIsMoving) {
		aWindowIsMoving = NO;
		break;
	    } else {
		// printf("Bug!!!!\n");
		return;
	    }
	default:
	    break;
	}
    }
#endif

    [super sendEvent:theEvent];
    [NSApp tkCheckPasteboard];

#ifdef TK_MAC_DEBUG_EVENTS
    fprintf(stderr, "Sending event of type %d\n", (int)[theEvent type]);
    DebugPrintQueue();
#endif

}

- (void) _runBackgroundLoop
{
    while(Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_TIMER_EVENTS|TCL_DONT_WAIT)){
	TkMacOSXDrawAllViews(NULL);
    }
}
@end

#pragma mark -

/*
 *----------------------------------------------------------------------
213
214
215
216
217
218
219


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236


237
238
239
240
241
242
243
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117


118
119
120
121
122
123
124
125
126







+
+















-
-
+
+







static NSString *
GetRunLoopMode(NSModalSession modalSession)
{
    NSString *runLoopMode = nil;

    if (modalSession) {
	runLoopMode = NSModalPanelRunLoopMode;
    } else if (TkMacOSXGetCapture()) {
	runLoopMode = NSEventTrackingRunLoopMode;
    }
    if (!runLoopMode) {
	runLoopMode = [[NSRunLoop currentRunLoop] currentMode];
    }
    if (!runLoopMode) {
	runLoopMode = NSDefaultRunLoopMode;
    }
    return runLoopMode;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXSetupTkNotifier --
 *
 *	This procedure is called during Tk initialization to create the event
 *	source for TkAqua events.
 *	This procedure is called during Tk initialization to create
 *	the event source for TkAqua events.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A new event source is created.
 *
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269


270

271
272


273
274
275
276
277
278
279
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151

152
153
154
155


156
157
158
159
160
161
162
163
164







-
+








-
+
+

+
-
-
+
+







	tsdPtr->initialized = 1;

	/*
	 * Install TkAqua event source in main event loop thread.
	 */

	if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) {
	    if (![NSThread isMainThread]) {
	    if (!pthread_main_np()) {
		/*
		 * Panic if main runloop is not on the main application thread.
		 */

		Tcl_Panic("Tk_MacOSXSetupTkNotifier: %s",
		    "first [load] of TkAqua has to occur in the main thread!");
	    }
	    Tcl_CreateEventSource(TkMacOSXEventsSetupProc,
		    TkMacOSXEventsCheckProc, NULL);
				  TkMacOSXEventsCheckProc,
				  GetMainEventQueue());
	    TkCreateExitHandler(TkMacOSXNotifyExitHandler, NULL);
	    Tcl_SetServiceMode(TCL_SERVICE_ALL);
	    Tcl_MacOSXNotifierAddRunLoopMode(NSEventTrackingRunLoopMode);
	    Tcl_MacOSXNotifierAddRunLoopMode(NSModalPanelRunLoopMode);
	    TclMacOSXNotifierAddRunLoopMode(NSEventTrackingRunLoopMode);
	    TclMacOSXNotifierAddRunLoopMode(NSModalPanelRunLoopMode);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
289
290
291
292
293
294
295
296

297
298
299
300
301


302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396





397
398
399
400
401
402
403
404
405


406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433

434
435
436
437

438
439

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456







457
458
459
460

461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478
479
480


481
482
483
484
485
486
487


488
489
490
491
492
493

494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519
520
521



522
523
524

525
526

527
528
529





530
531
532
533



534
535
536
537

538
539

540

541

542
543
544
545
546
547
548
549
550
551
552

553
554
555
556
557

558
559
560
561

562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
174
175
176
177
178
179
180

181
182
183
184
185

186
187
188
189


















































































190
191
192
193
194
195





196
197
198
199
200
201
202
203
204
205
206



207
208
209
210
211
212



213












214

215
216
217
218



219


220

221


222

















223
224
225
226
227
228
229




230








231

232
233
234
235
236
237
238
239
240


241
242
243
244
245
246
247


248
249
250
251
252
253
254

255
256
257
258



259


260
261
262
263
264









265
266
267
268



269
270
271



272


273
274
275
276
277
278
279
280
281
282



283
284
285
286



287


288
289
290

291

292
293
294

295
296
297
298
299
300
301
302
303
304
305

306




307

308




















309
310
311
312
313
314
315
316
317







-
+




-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
-
-
-
+
+
+
+
+






-
-
-
+
+




-
-
-

-
-
-
-
-
-
-
-
-
-
-
-

-
+



-
-
-
+
-
-

-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-









-
-
+
+





-
-
+
+





-
+



-
-
-
+
-
-





-
-
-
-
-
-
-
-
-

+


-
-
-
+
+
+
-
-
-
+
-
-
+



+
+
+
+
+

-
-
-
+
+
+

-
-
-
+
-
-
+

+
-
+
-



-






+




-
+
-
-
-
-
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXNotifyExitHandler(
    TCL_UNUSED(void *))	/* Not used. */
    ClientData clientData)	/* Not used. */
{
    TSD_INIT();

    Tcl_DeleteEventSource(TkMacOSXEventsSetupProc,
	    TkMacOSXEventsCheckProc, NULL);
			  TkMacOSXEventsCheckProc,
			  GetMainEventQueue());
    tsdPtr->initialized = 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDrawAllViews --
 *
 *       This static function is meant to be run as an idle task.  It attempts
 *       to redraw all views which have the tkNeedsDisplay property set to YES.
 *       This relies on a feature of [NSApp nextEventMatchingMask: ...] which
 *       is undocumented, namely that it sometimes blocks and calls drawRect
 *       for all views that need display before it returns.  We call it with
 *       deQueue=NO so that it will not change anything on the AppKit event
 *       queue, because we only want the side effect that it runs drawRect. The
 *       only times when any NSViews have the needsDisplay property set to YES
 *       are during execution of this function or in the addTkDirtyRect method
 *       of TKContentView.
 *
 *       The reason for running this function as an idle task is to try to
 *       arrange that all widgets will be fully configured before they are
 *       drawn.  Any idle tasks that might reconfigure them should be higher on
 *       the idle queue, so they should be run before the display procs are run
 *       by drawRect.
 *
 *       If this function is called directly with non-NULL clientData parameter
 *       then the int which it references will be set to the number of windows
 *       that need display, but the needsDisplay property of those windows will
 *       not be changed.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Parts of windows may get redrawn.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXDrawAllViews(
    void *clientData)
{
       int count = 0, *dirtyCount = (int *)clientData;

    for (NSWindow *window in [NSApp windows]) {
	if ([[window contentView] isMemberOfClass:[TKContentView class]]) {
	    TKContentView *view = [window contentView];
	    if ([view tkNeedsDisplay]) {
		count++;
		if (dirtyCount) {
		   continue;
		}
		[[view layer] setNeedsDisplayInRect:[view tkDirtyRect]];
		[view setNeedsDisplay:YES];
	    }
	} else {
	    [window displayIfNeeded];
	}
    }
    if (dirtyCount) {
    	*dirtyCount = count;
    }
    [NSApp nextEventMatchingMask:NSAnyEventMask
		       untilDate:[NSDate distantPast]
			  inMode:GetRunLoopMode(TkMacOSXGetModalSession())
			 dequeue:NO];
    for (NSWindow *window in [NSApp windows]) {
	if ([[window contentView] isMemberOfClass:[TKContentView class]]) {
	    TKContentView *view = [window contentView];

	    /*
	     * If we did not run drawRect, we set needsDisplay back to NO.
	     * Note that if drawRect did run it may have added to Tk's dirty
	     * rect, due to attempts to draw outside of drawRect's dirty rect.
	     */

	    if ([view needsDisplay]) {
		[view setNeedsDisplay: NO];
	    }
	}
    }
    [NSApp setNeedsToDraw:NO];
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXEventsSetupProc --
 *
 *	This procedure implements the setup part of the MacOSX event source. It
 *	is invoked by Tcl_DoOneEvent before calling TkMacOSXEventsCheckProc to
 *	process all queued NSEvents.  In our case, all we need to do is to set
 *	the Tcl MaxBlockTime to 0 before starting the loop to process all
 *	queued NSEvents.
 *	This procedure implements the setup part of the MacOSX event
 *	source. It is invoked by Tcl_DoOneEvent before calling
 *      TkMacOSXEventsProc to process all queued NSEvents.  In our
 *      case, all we need to do is to set the Tcl MaxBlockTime to
 *      0 before starting the loop to process all queued NSEvents.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *
 *	If NSEvents are queued, or if there is any drawing that needs to be
 *      done, then the maximum block time will be set to 0 to ensure that
 *      Tcl_WaitForEvent returns immediately.
 *	If NSEvents are queued, then the maximum block time will be set
 *	to 0 to ensure that control returns immediately to Tcl.
 *
 *----------------------------------------------------------------------
 */

#define TICK 200
static Tcl_TimerToken ticker = NULL;

static void
Heartbeat(
    TCL_UNUSED(void *))
{

    if (ticker) {
	ticker = Tcl_CreateTimerHandler(TICK, Heartbeat, NULL);
    }
}

static const Tcl_Time zeroBlockTime = { 0, 0 };

static void
TkMacOSXEventsSetupProc(
    TCL_UNUSED(void *),
    ClientData clientData,
    int flags)
{
    NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode];

    /*
     * runloopMode will be nil if we are in a Tcl event loop.
    /* runloopMode will be nil if we are in the Tcl event loop. */
     */

    if (flags & TCL_WINDOW_EVENTS && !runloopMode) {

	static const Tcl_Time zeroBlockTime = { 0, 0 };
	[NSApp _resetAutoreleasePool];

	/* Call this with dequeue=NO -- just checking if the queue is empty. */
 	/*
	 * After calling this setup proc, Tcl_DoOneEvent will call
 	 * Tcl_WaitForEvent.  Then it will call check proc to collect the
 	 * events and translate them into XEvents.
	 *
 	 * If we have any events waiting or if there is any drawing to be done
	 * we want Tcl_WaitForEvent to return immediately.  So we set the block
	 * time to 0 and stop the heartbeat.
  	 */

	NSEvent *currentEvent =
	        [NSApp nextEventMatchingMask:NSAnyEventMask
			untilDate:[NSDate distantPast]
			inMode:GetRunLoopMode(TkMacOSXGetModalSession())
			dequeue:NO];
	if ((currentEvent) || [NSApp needsToDraw] ) {
	    Tcl_SetMaxBlockTime(&zeroBlockTime);
	NSEvent *currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
				       untilDate:[NSDate distantPast]
				       inMode:GetRunLoopMode(TkMacOSXGetModalSession())
				       dequeue:NO];
	if (currentEvent) {
	    if (currentEvent.type > 0) {
		Tcl_SetMaxBlockTime(&zeroBlockTime);
	    Tcl_DeleteTimerHandler(ticker);
	    ticker = NULL;
	} else if (ticker == NULL) {

	    }
	    /*
	     * When the user is not generating events we schedule a "heartbeat"
	     * TimerHandler to fire every 200 milliseconds.  The handler does
	     * nothing, but when its timer fires it causes Tcl_WaitForEvent to
	     * return.  This helps avoid hangs when calling vwait during the
	     * non-regression tests.
	     */

	    [currentEvent release];
	    ticker = Tcl_CreateTimerHandler(TICK, Heartbeat, NULL);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXEventsCheckProc --
 *
 *	This procedure loops through all NSEvents waiting in the TKApplication
 *      event queue, generating X events from them.
 *	This procedure loops through all NSEvents waiting in the
 *      TKApplication event queue, generating X events from them.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	NSevents are used to generate X events, which are added to the Tcl
 *      event queue.
 *	NSevents are used to generate X events, which are added to the
 *      Tcl event queue.
 *
 *----------------------------------------------------------------------
 */
static void
TkMacOSXEventsCheckProc(
    TCL_UNUSED(void *),
    ClientData clientData,
    int flags)
{
    NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode];

    /*
     * runloopMode will be nil if we are in a Tcl event loop.
    /* runloopMode will be nil if we are in the Tcl event loop. */
     */

    if (flags & TCL_WINDOW_EVENTS && !runloopMode) {
	NSEvent *currentEvent = nil;
	NSEvent *testEvent = nil;
	NSModalSession modalSession;

	/*
	 * It is possible for the SetupProc to be called before this function
	 * returns.  This happens, for example, when we process an event which
	 * opens a modal window.  To prevent premature release of our
	 * application-wide autorelease pool by a nested call to the SetupProc,
	 * we must lock it here.
	 */

	[NSApp _lockAutoreleasePool];
	do {
	    [NSApp _resetAutoreleasePool];
	    modalSession = TkMacOSXGetModalSession();
	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
		    untilDate:[NSDate distantPast]
		    inMode:GetRunLoopMode(modalSession)
		    dequeue:NO];
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:NO];

	    /*
	     * We must not steal any events during LiveResize.
	    /* We must not steal any events during LiveResize. */
	     */

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	    if (testEvent && [[testEvent window] inLiveResize]) {
		break;
	    }
#else
	    if (testEvent && [[[testEvent window] contentView] inLiveResize]) {
		break;
	    }
#endif
	    currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
		    untilDate:[NSDate distantPast]
		    inMode:GetRunLoopMode(modalSession)
		    dequeue:YES];
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:YES];
	    if (currentEvent) {

		/*
		 * Generate Xevents.
		/* Generate Xevents. */
		 */

		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
		NSEvent *processedEvent = [NSApp tkProcessEvent:currentEvent];
		Tcl_SetServiceMode(oldServiceMode);
		if (processedEvent) {
		if (processedEvent) { /* Should always be non-NULL. */

#ifdef TK_MAC_DEBUG_EVENTS
		    TKLog(@"   event: %@", currentEvent);
#endif

		    if (modalSession) {
			[NSApp _modalSession:modalSession sendEvent:currentEvent];
		    } else {
			[NSApp sendEvent:currentEvent];
		    }
		}
		[currentEvent release];
	    } else {
		break;
	    }
	} while (1);

    }
	/*
	 * Now we can unlock the pool.
	 */

}
	[NSApp _unlockAutoreleasePool];

	/*
	 * Add an idle task to the end of the idle queue which will redisplay
	 * all of our dirty windows.  We want this to happen after all other
	 * idle tasks have run so that all widgets will be configured before
	 * they are displayed.  The drawRect method "borrows" the idle queue
	 * while drawing views. That is, it sends expose events which cause
	 * display procs to be posted as idle tasks and then runs an inner
	 * event loop to processes those idle tasks.  We are trying to arrange
	 * for the idle queue to be empty when it starts that process and empty
	 * when it finishes.
	 */

	int dirtyCount = 0;
	TkMacOSXDrawAllViews(&dirtyCount);
	if (dirtyCount > 0) {
	    Tcl_CancelIdleCall(TkMacOSXDrawAllViews, NULL);
	    Tcl_DoWhenIdle(TkMacOSXDrawAllViews, NULL);
	}
    }
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXPort.h.

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25






26
27
28
29
30
31
32
33
34
35
36




37

38



39
40
41


42
43
44
45

46
47
48
49
50
51
52
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19






20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45


46
47



48
49
50
51
52
53
54
55
56



-
+















-
-
-
-
-
-
+
+
+
+
+
+

-









+
+
+
+
-
+

+
+
+

-
-
+
+
-
-
-

+







/*
 * tkMacOSXPort.h --
 *
 *	This file is included by all of the Tk C files.  It contains
 *	This file is included by all of the Tk C files. It contains
 *	information that may be configuration-dependent, such as
 *	#includes for system include files and a few other things.
 *
 * Copyright (c) 1994-1996 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMACPORT
#define _TKMACPORT

#include <stdio.h>
#include <pwd.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <math.h>
#include <ctype.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/file.h>
#ifdef HAVE_SYS_SELECT_H
#   include <sys/select.h>
#endif
#include <sys/stat.h>
#ifndef _TCL
#   include <tcl.h>
#endif
#if TIME_WITH_SYS_TIME
#   include <sys/time.h>
#   include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#   if HAVE_SYS_TIME_H
#	include <sys/time.h>
#   else
#	include <time.h>
#   endif
#endif
#include <time.h>
#include <inttypes.h>
#if HAVE_INTTYPES_H
#    include <inttypes.h>
#include <unistd.h>
#if defined(__GNUC__) && !defined(__cplusplus)
#   pragma GCC diagnostic ignored "-Wc++-compat"
#endif
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xfuncproto.h>
#include <X11/Xutil.h>

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
68
69
70
71
72
73
74













75
76
77
78
79
80
81







-
-
-
-
-
-
-
-
-
-
-
-
-







#   if defined(_IBMR2)
#	define SELECT_MASK void
#   else
#	define SELECT_MASK int
#   endif
#endif

/*
 * Used to tag functions that are only to be visible within the module being
 * built and not outside it (where this is supported by the linker).
 */

#ifndef MODULE_SCOPE
#   ifdef __cplusplus
#	define MODULE_SCOPE extern "C"
#   else
#	define MODULE_SCOPE extern
#   endif
#endif

/*
 * The following macro defines the number of fd_masks in an fd_set:
 */

#ifndef FD_SETSIZE
#   ifdef OPEN_MAX
#	define FD_SETSIZE OPEN_MAX
110
111
112
113
114
115
116













117
118
119
120
121
122
123
124
125











126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147

148
149
150
151
152

153
154

155
156
157
158


159
160
161
162

163
164
165
166


167
168
169
170
171
172









173

174
175
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152


153
154




155


156





157


158
159
160


161
162




163




164
165






166
167
168
169
170
171
172
173
174

175
176
177







+
+
+
+
+
+
+
+
+
+
+
+
+









+
+
+
+
+
+
+
+
+
+
+





-
+






-
-


-
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
+


-
-
+
+
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+



/*
 * The following define causes Tk to use its internal keysym hash table
 */

#define REDO_KEYSYM_LOOKUP

/*
 * Defines for X functions that are used by Tk but are treated as
 * no-op functions on the Macintosh.
 */

#define XFlush(display)
#define XFree(data) {if ((data) != NULL) ckfree(data);}
#define XGrabServer(display)
#define XNoOp(display) {display->request++;}
#define XUngrabServer(display)
#define XSynchronize(display, bool) {display->request++;}
#define XVisualIDFromVisual(visual) (visual->visualid)

/*
 * The following functions are not used on the Mac, so we stub them out.
 */

#define TkpCmapStressed(tkwin,colormap) (0)
#define TkpFreeColor(tkColPtr)
#define TkSetPixmapColormap(p,c) {}
#define TkpSync(display)

/*
 * The following macro returns the pixel value that corresponds to the
 * RGB values in the given XColor structure.
 */

#define PIXEL_MAGIC ((unsigned char) 0x69)
#define TkpGetPixel(p) ((((((PIXEL_MAGIC << 8) \
	| (((p)->red >> 8) & 0xff)) << 8) \
	| (((p)->green >> 8) & 0xff)) << 8) \
	| (((p)->blue >> 8) & 0xff))

/*
 * This macro stores a representation of the window handle in a string.
 */

#define TkpPrintWindowId(buf,w) \
	snprintf((buf), TCL_INTEGER_SPACE, "0x%lx", (unsigned long) (w))
	sprintf((buf), "0x%lx", (unsigned long) (w))

/*
 * Turn off Tk double-buffering as Aqua windows are already double-buffered.
 */

#define TK_NO_DOUBLE_BUFFERING 1
#define TK_HAS_DYNAMIC_COLORS 1
#define TK_DYNAMIC_COLORMAP 0x0fffffff

/*
 * Inform tkImgPhInstance.c that we implement TkpPutRGBAImage to render RGBA
 * images directly into a window.
 */

 * Magic pixel code values for system colors.
#define TK_CAN_RENDER_RGBA

 *
MODULE_SCOPE int TkpPutRGBAImage(
		     Display* display, Drawable drawable, GC gc,XImage* image,
		     int src_x, int src_y, int dest_x, int dest_y,
		     unsigned int width, unsigned int height);

 * NOTE: values must be kept in sync with indices into the
/*
 * Inform tkCanvas.c that our XGetImage returns a 32pp pixmap packed as 0xAABBGGRR
 *	 systemColorMap array in tkMacOSXColor.c !
 */

#define TK_XGETIMAGE_USES_ABGR32

#define TRANSPARENT_PIXEL		30
#define HIGHLIGHT_PIXEL			31
/*
 * Used by xcolor.c
 */

#define HIGHLIGHT_SECONDARY_PIXEL	32
MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned long red, unsigned long green,
					    unsigned long blue);
#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red >> 8, p->green >> 8, p->blue >> 8))

#define HIGHLIGHT_TEXT_PIXEL		33
#define HIGHLIGHT_ALTERNATE_PIXEL	34
/*
 * Used by tkAppInit
 */

#define USE_CUSTOM_EXIT_PROC
EXTERN int TkpWantsExitProc(void);
#define CONTROL_TEXT_PIXEL		35
#define CONTROL_BODY_PIXEL		37
#define CONTROL_FRAME_PIXEL		39
#define WINDOW_BODY_PIXEL		41
#define MENU_ACTIVE_PIXEL		43
#define MENU_ACTIVE_TEXT_PIXEL		45
#define MENU_BACKGROUND_PIXEL		47
#define MENU_DISABLED_PIXEL		49
#define MENU_TEXT_PIXEL			51
EXTERN TCL_NORETURN void TkpExitProc(void *);
#define APPEARANCE_PIXEL		52

#endif /* _TKMACPORT */

Deleted macosx/tkMacOSXPrint.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410


























































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXPrint.c --
 *
 *      This module implements native printing dialogs for macOS.
 *
 * Copyright © 2006 Apple Inc.
 * Copyright © 2011-2021 Kevin Walzer/WordTech Communications LLC.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include <tcl.h>
#include <tk.h>
#include <tkInt.h>
#include <Cocoa/Cocoa.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
#include <tkMacOSXInt.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include "tkMacOSXImage.h"
#include "tkMacOSXPrivate.h"

NSString * fileName = nil;
CFStringRef urlFile = NULL;

/*Forward declaration of functions.*/
static Tcl_ObjCmdProc StartPrint;
static OSStatus	FinishPrint(NSString *file, int buttonValue);
static Tcl_ObjCmdProc MakePDF;
int			MacPrint_Init(Tcl_Interp * interp);

/* Delegate class for print dialogs. */
@interface PrintDelegate: NSObject
    - (id) init;
    - (void) printPanelDidEnd: (NSPrintPanel *) printPanel
		   returnCode: (int) returnCode
		  contextInfo: (void *) contextInfo;
@end

@implementation PrintDelegate
- (id) init {
    self = [super init];
    return self;
}

- (void) printPanelDidEnd: (NSPrintPanel *) printPanel
	       returnCode: (int) returnCode
	      contextInfo: (void *) contextInfo {
    (void) printPanel;
    (void) contextInfo;

    /*
     * Pass returnCode to FinishPrint function to determine how to
     * handle.
     */

    FinishPrint(fileName, returnCode);
}
@end

/*
 *----------------------------------------------------------------------
 *
 * StartPrint --
 *
 * 	Launch native print dialog.
 *
 * Results:
 *	Configures values and starts print process.
 *
 *----------------------------------------------------------------------
 */

int
StartPrint(
    TCL_UNUSED(void *),
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj *const objv[])
{
    NSPrintInfo * printInfo = [NSPrintInfo sharedPrintInfo];
    NSPrintPanel * printPanel = [NSPrintPanel printPanel];
    int accepted;
    PMPrintSession printSession;
    PMPrintSettings printSettings;
    OSStatus status = noErr;

    /* Check for proper number of arguments. */
    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "file");
        return TCL_ERROR;
    }

    fileName = [NSString stringWithUTF8String: Tcl_GetString(objv[1])];
    urlFile = (CFStringRef) fileName;
    CFRetain(urlFile);

    /* Initialize the delegate for the callback from the page panel. */
    PrintDelegate * printDelegate = [[PrintDelegate alloc] init];

    status = PMCreateSession( & printSession);
    if (status != noErr) {
        NSLog(@ "Error creating print session.");
        return TCL_ERROR;
    }

    status = PMCreatePrintSettings( & printSettings);
    if (status != noErr) {
        NSLog(@ "Error creating print settings.");
        return TCL_ERROR;
    }

    status = PMSessionDefaultPrintSettings(printSession, printSettings);
    if (status != noErr) {
        NSLog(@ "Error creating default print settings.");
        return TCL_ERROR;
    }

    printSession = (PMPrintSession)[printInfo PMPrintSession];
    (void)(PMPageFormat)[printInfo PMPageFormat];
    printSettings = (PMPrintSettings)[printInfo PMPrintSettings];

    accepted = (int)[printPanel runModalWithPrintInfo: printInfo];
    [printDelegate printPanelDidEnd: printPanel
			 returnCode: accepted
			contextInfo: printInfo];

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FinishPrint --
 *
 * 	Handles print process based on input from dialog.
 *
 * Results:
 *	Completes print process.
 *
 *----------------------------------------------------------------------
 */

OSStatus
FinishPrint(
    NSString *file,
    int buttonValue)
{
    NSPrintInfo * printInfo = [NSPrintInfo sharedPrintInfo];
    PMPrintSession printSession;
    PMPageFormat pageFormat;
    PMPrintSettings printSettings;
    OSStatus status = noErr;
    CFStringRef mimeType = NULL;

    /*
     * If value passed here is NSCancelButton, return noErr;
     * otherwise printing will occur regardless of value.
     */
    if (buttonValue == NSModalResponseCancel) {
        return noErr;
    }

    status = PMCreateSession( & printSession);
    if (status != noErr) {
        NSLog(@ "Error creating print session.");
        return status;
    }

    status = PMCreatePrintSettings( & printSettings);
    if (status != noErr) {
        NSLog(@ "Error creating print settings.");
        return status;
    }

    status = PMSessionDefaultPrintSettings(printSession, printSettings);
    if (status != noErr) {
        NSLog(@ "Error creating default print settings.");
        return status;
    }

    printSession = (PMPrintSession)[printInfo PMPrintSession];
    pageFormat = (PMPageFormat)[printInfo PMPageFormat];
    printSettings = (PMPrintSettings)[printInfo PMPrintSettings];

    /*Handle print operation.*/
    if (buttonValue == NSModalResponseOK) {

        if (urlFile == NULL) {
            NSLog(@ "Could not get file to print.");
            return noErr;
        }

        fileName = file;

        CFURLRef printURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlFile, kCFURLPOSIXPathStyle, false);

        PMPrinter currentPrinter;
        PMDestinationType printDestination;

        /*Get the intended destination.*/
        status = PMSessionGetDestinationType(printSession, printSettings, & printDestination);

        /*Destination is printer. Send file to printer.*/
        if (status == noErr && printDestination == kPMDestinationPrinter) {

            status = PMSessionGetCurrentPrinter(printSession, & currentPrinter);
            if (status == noErr) {
                CFArrayRef mimeTypes;
                status = PMPrinterGetMimeTypes(currentPrinter, printSettings, & mimeTypes);
                if (status == noErr && mimeTypes != NULL) {
                    mimeType = CFSTR("application/pdf");
                    if (CFArrayContainsValue(mimeTypes, CFRangeMake(0, CFArrayGetCount(mimeTypes)), mimeType)) {
                        status = PMPrinterPrintWithFile(currentPrinter, printSettings, pageFormat, mimeType, printURL);
                        CFRelease(urlFile);
                        return status;
                    }
                }
            }
        }

        /* Destination is file. Determine how to handle. */
        if (status == noErr && printDestination == kPMDestinationFile) {
            CFURLRef outputLocation = NULL;

            status = PMSessionCopyDestinationLocation(printSession, printSettings, & outputLocation);
            if (status == noErr) {
                /*Get the source file and target destination, convert to strings.*/
                CFStringRef sourceFile = CFURLCopyFileSystemPath(printURL, kCFURLPOSIXPathStyle);
                CFStringRef savePath = CFURLCopyFileSystemPath(outputLocation, kCFURLPOSIXPathStyle);
                NSString * sourcePath = (NSString * ) sourceFile;
                NSString * finalPath = (NSString * ) savePath;
                NSString * pathExtension = [finalPath pathExtension];
                NSFileManager * fileManager = [NSFileManager defaultManager];
		NSError * error = nil;

        /*
		 * Is the target file a PDF? If so, copy print file
		 * to output location.
		 */
                if ([pathExtension isEqualToString: @ "pdf"]) {

		    /*Make sure no file conflict exists.*/
		    if ([fileManager fileExistsAtPath: finalPath]) {
			[fileManager removeItemAtPath: finalPath error: &error];
		    }
                    if ([fileManager fileExistsAtPath: sourcePath]) {
                        error = nil;
                        [fileManager copyItemAtPath: sourcePath toPath: finalPath error: & error];
                    }
		    return status;
                }

                /*
                 * Is the target file PostScript? If so, run print file
                 * through CUPS filter to convert back to PostScript.
                 */

              if ([pathExtension isEqualToString: @ "ps"]) {
                    char source[5012];
                    char target[5012];
                    [sourcePath getCString: source maxLength: (sizeof source) encoding: NSUTF8StringEncoding];
                    [finalPath getCString: target maxLength: (sizeof target) encoding: NSUTF8StringEncoding];
		    /*Make sure no file conflict exists.*/
		    if ([fileManager fileExistsAtPath: finalPath]) {
			[fileManager removeItemAtPath: finalPath error: &error];
		    }

		    /*
		     *  Fork and start new process with command string. Thanks to Peter da Silva
		     *  for assistance.
		     */
  		    pid_t pid;
		    if ((pid = fork()) == -1) {
		      return -1;
		    } else if (pid == 0) {
		      /* Redirect output to file and silence debugging output.*/
		      dup2(open(target, O_RDWR | O_CREAT, 0777), 1);
		      dup2(open("/dev/null", O_WRONLY), 2);
		      execl("/usr/sbin/cupsfilter", "/usr/sbin/cupsfilter", "-m", "application/postscript", source, NULL);
		      exit(0);
		    }
	      return status;
	      }
	    }
	}

        /* Destination is preview. Open file in default application for PDF. */
        if ((status == noErr) && (printDestination == kPMDestinationPreview)) {
            CFStringRef urlpath = CFURLCopyFileSystemPath(printURL, kCFURLPOSIXPathStyle);
            NSString * path = (NSString * ) urlpath;
            NSURL * url = [NSURL fileURLWithPath: path];
            NSWorkspace * ws = [NSWorkspace sharedWorkspace];
            [ws openURL: url];
            status = noErr;
            return status;
        }

        /*
         * If destination is not printer, file or preview,
         * we do not support it. Display alert.
         */

	if (((status == noErr) && (printDestination != kPMDestinationPreview)) || ((status == noErr) && (printDestination != kPMDestinationFile)) || ((status == noErr) &&  (printDestination != kPMDestinationPrinter))) {

            NSAlert * alert = [[[NSAlert alloc] init] autorelease];
            [alert addButtonWithTitle: @ "OK"];

            [alert setMessageText: @ "Unsupported Printing Operation"];
            [alert setInformativeText: @ "This printing operation is not supported."];
            [alert setAlertStyle: NSAlertStyleInformational];
            [alert runModal];
            return status;
        }
    }

    /* Return because cancel button was clicked. */
    if (buttonValue == NSModalResponseCancel) {
        PMRelease(printSession);
        return status;
    }

    return status;
}


/*
 *----------------------------------------------------------------------
 *
 * MakePDF--
 *
 * 	Converts a Tk canvas to PDF data.
 *
 * Results:
 *	Outputs PDF file.
 *
 *----------------------------------------------------------------------
 */

int MakePDF(
 TCL_UNUSED(void *),
 Tcl_Interp *ip,
 int objc,
 Tcl_Obj *const objv[])
{
    Tk_Window path;
    Drawable d;
    unsigned int width, height;
    CFDataRef pdfData;

    if (objc != 2) {
	Tcl_WrongNumArgs(ip, 1, objv, "path?");
	return TCL_ERROR;
    }

    /*Get window and render to PDF.*/

    path = Tk_NameToWindow(ip, Tcl_GetString(objv[1]), Tk_MainWindow(ip));
    if (path == NULL) {
	return TCL_ERROR;
    }

    Tk_MakeWindowExist(path);
    Tk_MapWindow(path);
    d = Tk_WindowId(path);
    width = Tk_Width(path);
    height = Tk_Height(path);

    pdfData = CreatePDFFromDrawableRect(d, 0, 0, width, height);

    NSData *viewData = (NSData*)pdfData;
    [viewData writeToFile:@"/tmp/tk_canvas.pdf" atomically:YES];
    return TCL_OK;

}

/*
 *----------------------------------------------------------------------
 *
 * MacPrint_Init--
 *
 * 	Initializes the printing module.
 *
 * Results:
 *	Printing module initialized.
 *
 *----------------------------------------------------------------------
 */

int MacPrint_Init(Tcl_Interp * interp) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    Tcl_CreateObjCommand(interp, "::tk::print::_print", StartPrint, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_printcanvas", MakePDF, NULL, NULL);
    [pool release];
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXPrivate.h.

1
2
3
4
5
6

7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1
2
3
4
5

6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21




22

23

24




25
26
27
28
29
30
31





-
+
-
-
+














-
-
-
-

-

-

-
-
-
-







/*
 * tkMacOSXPrivate.h --
 *
 *	Macros and declarations that are purely internal & private to TkAqua.
 *
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2008-2009 Apple Inc.
 * Copyright © 2020 Marc Culler
 * Copyright 2008-2009, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id$
 */

#ifndef _TKMACPRIV
#define _TKMACPRIV

#if !__OBJC__
#error Objective-C compiler required
#endif

#ifndef __clang__
#define instancetype id
#endif

#define TextStyle MacTextStyle
#define Cursor QDCursor
#import <ApplicationServices/ApplicationServices.h>
#undef Cursor
#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#endif
#ifndef NO_CARBON_H
#import <Carbon/Carbon.h>
#endif
#undef TextStyle
#import <objc/runtime.h> /* for sel_isEqual() */

#ifndef _TKMACINT
66
67
68
69
70
71
72





















73
74
75
76
77
78
79
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	if ((chk) && (cond)) { __VA_ARGS__
#define tk_else_mac_os_x_chk(...) \
	} else { __VA_ARGS__
#define tk_if_mac_os_x_no(chk, cond, ...) \
	if (0) {
#define tk_else_mac_os_x_no(...) \
	} else { __VA_ARGS__
/* Private mapping macros defined according to Mac OS X version requirements */
/* 10.5 Leopard */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
#define tk_if_mac_os_x_min_10_5		tk_if_mac_os_x_yes
#define tk_else_mac_os_x_min_10_5	tk_else_mac_os_x_yes
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_yes
#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_yes
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
#define tk_if_mac_os_x_min_10_5		tk_if_mac_os_x_chk
#define tk_else_mac_os_x_min_10_5	tk_else_mac_os_x_chk
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_chk
#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_chk
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_no
#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_no
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */

/*
 * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
 */

#undef kComponentSignatureString
#undef COMPONENT_SIGNATURE
105
106
107
108
109
110
111
112
113
114



115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212


213
214








215
216
217
218




219
220


221











222
223


224
225



226
227
228
229
230
231
232
233
234
235
236
237
238



239
240
241
242
243



244
245
246

247
248
249
250
251
252
253
254







255
256
257
258

259

260
261

262

263


264
265
266
267
268
269
270

271
272
273
274
275
276
277
278




279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318


319
320
321



322
323
324
325
326
327

328
329
330
331

332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406





407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424




425
426
427
428
429
430




431
432
433
434
435
436
437
438
439
440

441
442
443

444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
115
116
117
118
119
120
121



122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138

139


140
141
142
143
144
145




































































146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191


192
193
194
195
196
197
198
199
200
201


202
203
204
205
206
207
208
209
210



211
212
213

214

215
216
217
218
219




220
221
222
223
224
225
226
227
228
229
230
231

232
233

234
235
236
237
238
239
240
241
242
243
244
245

246








247
248
249
250








251



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268



269
270
271
272
273
274

275

276
277
278


279
280
281






282




283





284
285
286
287
288





















289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322


323
324
325






326

327
328
329
330
331
332
333



334


335
336
337
338

339
340
341



342
343
344
345
346





347
348
349
350
351
352
353
354



355
356

357



358







359




360
361



362
363
364
365
366
367
368







-
-
-
+
+
+

-
+












-

-
-
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








+
+


+
+
+
+
+
+
+
+




+
+
+
+
-
-
+
+

+
+
+
+
+
+
+
+
+
+
+


+
+
-
-
+
+
+







-
-




+
+
+


-
-
-
+
+
+
-

-
+




-
-
-
-
+
+
+
+
+
+
+




+
-
+

-
+

+

+
+






-
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
-
-
-

















-
-
-






-

-
+
+

-
-
+
+
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










+
+
+






-















-
-



-
-
-
-
-
-
+
-

+
+
+
+
+

-
-
-

-
-




-



-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+




-
-
-


-
+
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-


-
-
-







    } while (0)

/*
 * Macro to do very common check for noErr return from given API and output
 * debug message in case of failure.
 */
#define ChkErr(f, ...) ({ \
	OSStatus err_ = f(__VA_ARGS__); \
	if (err_ != noErr) { \
	    TkMacOSXDbgOSErr(f, err_); \
	OSStatus err = f(__VA_ARGS__); \
	if (err != noErr) { \
	    TkMacOSXDbgOSErr(f, err); \
	} \
	err_;})
	err;})

#else /* TK_MAC_DEBUG */
#define TKLog(f, ...)
#define TkMacOSXDbgMsg(m, ...)
#define TkMacOSXDbgOSErr(f, err)
#define ChkErr(f, ...) ({f(__VA_ARGS__);})
#endif /* TK_MAC_DEBUG */

/*
 * Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols.
 */

#define UNINITIALISED_SYMBOL	((void*)(-1L))
#define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \
    static ret (* symbol)(__VA_ARGS__) = UNINITIALISED_SYMBOL; \
    if (symbol == UNINITIALISED_SYMBOL) { \
    static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \
    if (symbol == (void*)(-1L)) { \
	symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \
		STRINGIFY(symbol)); \
    }

/*
 *  The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
 *  an unsigned int or as having either two or three bitfields.
 */

typedef struct keycode_v_t {
    unsigned keychar: 22;    /* UCS-32 character */
    unsigned o_s: 2;         /* State of Option and Shift keys. */
    unsigned virt: 8;     /* 8-bit virtual keycode - identifies a key. */
} keycode_v;

typedef struct keycode_x_t {
    unsigned keychar: 22;     /* UCS-32 character */
    unsigned xvirtual: 10;    /* Combines o_s and virtual. This 10-bit integer
			       * is used as a key for looking up the character
			       * produced when pressing a key with a particular
			       * Shift and Option modifier state. */
} keycode_x;

typedef union MacKeycode_t {
  unsigned int uint;
  keycode_v v;
  keycode_x x;
} MacKeycode;

/*
 * Macros used in tkMacOSXKeyboard.c and tkMacOSXKeyEvent.c.
 * Note that 0x7f is del and 0xF8FF is the Apple Logo character.
 */

#define ON_KEYPAD(virt) ((virt >= 0x41) && (virt <= 0x5C))
#define IS_PRINTABLE(keychar) ((keychar >= 0x20) && (keychar != 0x7f) && \
                               ((keychar < 0xF700) || keychar >= 0xF8FF))

/*
 * An "index" is 2-bit bitfield showing the state of the Option and Shift
 * keys.  It is used as an index when building the keymaps and it
 * is the value of the o_s bitfield of a keycode_v.
 */

#define INDEX_SHIFT 1
#define INDEX_OPTION 2
#define INDEX2STATE(index) ((index & INDEX_SHIFT ? ShiftMask : 0) |	\
			    (index & INDEX_OPTION ? Mod2Mask : 0))
#define INDEX2CARBON(index) ((index & INDEX_SHIFT ? shiftKey : 0) |	\
			     (index & INDEX_OPTION ? optionKey : 0))
#define STATE2INDEX(state) ((state & ShiftMask ? INDEX_SHIFT : 0) |	\
			    (state & Mod2Mask ? INDEX_OPTION : 0))

/*
 * Special values for the virtual bitfield.  Actual virtual keycodes are < 128.
 */

#define NO_VIRTUAL 0xFF /* Not generated by a key or the NSText"InputClient. */
#define REPLACEMENT_VIRTUAL 0x80 /* A BMP char sent by the NSTextInputClient. */
#define NON_BMP_VIRTUAL 0x81 /* A non-BMP char sent by the NSTextInputClient. */

/*
 * A special character is used in the keycode for simulated modifier KeyPress
 * or KeyRelease XEvents.  It is near the end of the private-use range but
 * different from the UniChar 0xF8FF which Apple uses for their logo character.
 * A different special character is used for keys, like the Menu key, which do
 * not appear on Macintosh keyboards.
 */

#define MOD_KEYCHAR 0xF8FE
#define UNKNOWN_KEYCHAR 0xF8FD

/*
 * Structure encapsulating current drawing environment.
 */

typedef struct TkMacOSXDrawingContext {
    CGContextRef context;
    NSView *view;
    HIShapeRef clipRgn;
    CGRect portBounds;
    int focusLocked;
} TkMacOSXDrawingContext;

/*
 * Variables internal to TkAqua.
 */

MODULE_SCOPE CGFloat tkMacOSXZeroScreenHeight;
MODULE_SCOPE CGFloat tkMacOSXZeroScreenTop;
MODULE_SCOPE long tkMacOSXMacOSXVersion;

/*
 * Prototypes for TkMacOSXRegion.c.
 */

#if 0
MODULE_SCOPE void	TkMacOSXEmtpyRegion(TkRegion r);
MODULE_SCOPE int	TkMacOSXIsEmptyRegion(TkRegion r);
#endif
MODULE_SCOPE HIShapeRef	TkMacOSXGetNativeRegion(Region r);
MODULE_SCOPE void	TkMacOSXSetWithNativeRegion(Region r,
MODULE_SCOPE HIShapeRef	TkMacOSXGetNativeRegion(TkRegion r);
MODULE_SCOPE void	TkMacOSXSetWithNativeRegion(TkRegion r,
			    HIShapeRef rgn);
MODULE_SCOPE void	TkMacOSXOffsetRegion(TkRegion r, short dx, short dy);
MODULE_SCOPE HIShapeRef	TkMacOSXHIShapeCreateEmpty(void);
MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
			    const CGRect *inRect);
MODULE_SCOPE OSStatus	TkMacOSXHIShapeSetWithShape(
			    HIMutableShapeRef inDestShape,
			    HIShapeRef inSrcShape);
#if 0
MODULE_SCOPE OSStatus	TkMacOSXHIShapeSetWithRect(HIMutableShapeRef inShape,
			    const CGRect *inRect);
#endif
MODULE_SCOPE OSStatus	TkMacOSHIShapeDifferenceWithRect(
			    HIMutableShapeRef inShape, const CGRect *inRect);
MODULE_SCOPE OSStatus	TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
			    const CGRect *inRect);
MODULE_SCOPE int	TkMacOSXCountRectsInRegion(HIShapeRef shape);
MODULE_SCOPE void       TkMacOSXPrintRectsInRegion(HIShapeRef shape);
MODULE_SCOPE OSStatus	TkMacOSHIShapeUnion(HIShapeRef inShape1,
			    HIShapeRef inShape2, HIMutableShapeRef outResult);

/*
 * Prototypes of TkAqua internal procs.
 */

MODULE_SCOPE void *	TkMacOSXGetNamedSymbol(const char *module,
			    const char *symbol);
MODULE_SCOPE void	TkMacOSXDisplayChanged(Display *display);
MODULE_SCOPE CGFloat	TkMacOSXZeroScreenHeight();
MODULE_SCOPE CGFloat	TkMacOSXZeroScreenTop();
MODULE_SCOPE int	TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
			    int enable);
MODULE_SCOPE int	TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
			    int antiAlias);
MODULE_SCOPE int	TkMacOSXGenerateFocusEvent(TkWindow *winPtr,
			    int activeFlag);
MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr);
MODULE_SCOPE int	TkMacOSXIsWindowZoomed(TkWindow *winPtr);
MODULE_SCOPE int	TkGenerateButtonEventForXPointer(Window window);
MODULE_SCOPE void       TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context,
			    CGImageRef image, unsigned long imageForeground,
			    unsigned long imageBackground, CGRect imageBounds,
MODULE_SCOPE EventModifiers TkMacOSXModifierState(void);
MODULE_SCOPE NSBitmapImageRep* BitmapRepFromDrawableRect(Drawable drawable,
			    int x, int y, unsigned int width, unsigned int height);
			    CGRect srcBounds, CGRect dstBounds);
MODULE_SCOPE int	TkMacOSXSetupDrawingContext(Drawable d, GC gc,
			    TkMacOSXDrawingContext *dcPtr);
			    int useCG, TkMacOSXDrawingContext *dcPtr);
MODULE_SCOPE void	TkMacOSXRestoreDrawingContext(
			    TkMacOSXDrawingContext *dcPtr);
MODULE_SCOPE void	TkMacOSXSetColorInContext(GC gc, unsigned long pixel,
			    CGContextRef context);
#define TkMacOSXGetTkWindow(window) ((TkWindow *)Tk_MacOSXGetTkWindow(window))
#define TkMacOSXGetNSWindowForDrawable(drawable) ((NSWindow *)Tk_MacOSXGetNSWindowForDrawable(drawable))
#define TkMacOSXGetNSViewForDrawable(macWin) ((NSView *)Tk_MacOSXGetNSViewForDrawable((Drawable)(macWin)))
#define TkMacOSXGetCGContextForDrawable(drawable) ((CGContextRef)Tk_MacOSXGetCGContextForDrawable(drawable))
MODULE_SCOPE int	TkMacOSXMakeFullscreen(TkWindow *winPtr,
			    NSWindow *window, int fullscreen,
			    Tcl_Interp *interp);
MODULE_SCOPE void	TkMacOSXEnterExitFullscreen(TkWindow *winPtr,
			    int active);
MODULE_SCOPE NSWindow*	TkMacOSXDrawableWindow(Drawable drawable);
MODULE_SCOPE NSView*	TkMacOSXDrawableView(MacDrawable *macWin);
MODULE_SCOPE void	TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds);
MODULE_SCOPE HIShapeRef	TkMacOSXGetClipRgn(Drawable drawable);
MODULE_SCOPE void	TkMacOSXInvalidateViewRegion(NSView *view,
			    HIShapeRef rgn);
MODULE_SCOPE CGImageRef	TkMacOSXCreateCGImageWithDrawable(Drawable drawable);
MODULE_SCOPE NSImage*	TkMacOSXGetNSImageFromTkImage(Display *display,
MODULE_SCOPE NSImage*	TkMacOSXGetNSImageWithTkImage(Display *display,
			    Tk_Image image, int width, int height);
MODULE_SCOPE NSImage*	TkMacOSXGetNSImageFromBitmap(Display *display,
MODULE_SCOPE NSImage*	TkMacOSXGetNSImageWithBitmap(Display *display,
			    Pixmap bitmap, GC gc, int width, int height);
MODULE_SCOPE CGColorRef	TkMacOSXCreateCGColor(GC gc, unsigned long pixel);
MODULE_SCOPE NSColor*	TkMacOSXGetNSColor(GC gc, unsigned long pixel);
MODULE_SCOPE Tcl_Obj *	TkMacOSXGetStringObjFromCFString(CFStringRef str);
MODULE_SCOPE TkWindow*	TkMacOSXGetTkWindow(NSWindow *w);
MODULE_SCOPE NSFont*	TkMacOSXNSFontForFont(Tk_Font tkfont);
MODULE_SCOPE NSDictionary* TkMacOSXNSFontAttributesForFont(Tk_Font tkfont);
MODULE_SCOPE NSModalSession TkMacOSXGetModalSession(void);
MODULE_SCOPE void	TkMacOSXSelDeadWindow(TkWindow *winPtr);
MODULE_SCOPE void	TkMacOSXApplyWindowAttributes(TkWindow *winPtr,
			    NSWindow *macWindow);
MODULE_SCOPE Tcl_ObjCmdProc TkMacOSXStandardAboutPanelObjCmd;
MODULE_SCOPE int	TkMacOSXStandardAboutPanelObjCmd(ClientData clientData,
MODULE_SCOPE Tcl_ObjCmdProc TkMacOSXIconBitmapObjCmd;
MODULE_SCOPE Tcl_ObjCmdProc TkMacOSXNSImageObjCmd;
MODULE_SCOPE void       TkMacOSXDrawSolidBorder(Tk_Window tkwin, GC gc,
			    int inset, int thickness);
MODULE_SCOPE int 	TkMacOSXServices_Init(Tcl_Interp *interp);
MODULE_SCOPE Tcl_ObjCmdProc TkMacOSXRegisterServiceWidgetObjCmd;
MODULE_SCOPE unsigned   TkMacOSXAddVirtual(unsigned int keycode);
MODULE_SCOPE int 	TkMacOSXNSImage_Init(Tcl_Interp *interp);
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int	TkMacOSXIconBitmapObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
MODULE_SCOPE void       TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view,
					    NSRect *bounds);
MODULE_SCOPE Bool       TkMacOSXInDarkMode(Tk_Window tkwin);
MODULE_SCOPE void	TkMacOSXDrawAllViews(void *clientData);
MODULE_SCOPE NSColor*   controlAccentColor(void);
MODULE_SCOPE void       Ttk_MacOSXInit(void);
MODULE_SCOPE unsigned long TkMacOSXClearPixel(void);
MODULE_SCOPE int MacSystrayInit(Tcl_Interp *);
			    Tcl_Obj *const objv[]);
MODULE_SCOPE int MacPrint_Init(Tcl_Interp *);
MODULE_SCOPE NSString*  TkMacOSXOSTypeToUTI(OSType ostype);
MODULE_SCOPE NSImage*   TkMacOSXIconForFileType(NSString *filetype);

#pragma mark Private Objective-C Classes

#define VISIBILITY_HIDDEN __attribute__((visibility("hidden")))

enum { tkMainMenu = 1, tkApplicationMenu, tkWindowsMenu, tkHelpMenu};

VISIBILITY_HIDDEN
@interface TKMenu : NSMenu {
@private
    void *_tkMenu;
    NSUInteger _tkOffset, _tkItemCount, _tkSpecial;
}
- (void)setSpecial:(NSUInteger)special;
- (BOOL)isSpecial:(NSUInteger)special;
@end

@interface TKMenu(TKMenuDelegate) <NSMenuDelegate>
@end

VISIBILITY_HIDDEN
@interface TKApplication : NSApplication {
@private
    Tcl_Interp *_eventInterp;
    NSMenu *_servicesMenu;
    TKMenu *_defaultMainMenu, *_defaultApplicationMenu;
    NSMenuItem *_demoMenuItem;
    NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
    NSArray *_defaultHelpMenuItems, *_defaultFileMenuItems;
    NSArray *_defaultHelpMenuItems;
    NSWindow *_windowWithMouse;
    NSAutoreleasePool *_mainPool;
}
@property int poolLock;
#ifdef __i386__
    /* The Objective C runtime used on i386 requires this. */
    BOOL _poolProtected;
@property int macOSVersion;
@property Bool isDrawing;
@property Bool needsToDraw;
@property Bool isSigned;
@property Bool tkLiveResizeEnded;

#endif
/*
 * Persistent state variables used by processMouseEvent.
 */

}
@property(nonatomic) TkWindow *tkPointerWindow;
@property(nonatomic) TkWindow *tkEventTarget;
@property(nonatomic) TkWindow *tkDragTarget;
@property unsigned int tkButtonState;

@property BOOL poolProtected;
@end
@interface TKApplication(TKInit)
- (NSString *)tkFrameworkImagePath:(NSString*)image;
- (void)_resetAutoreleasePool;
- (void)_lockAutoreleasePool;
- (void)_unlockAutoreleasePool;
@end
@interface TKApplication(TKKeyboard)
- (void) keyboardChanged: (NSNotification *) notification;
@end
@interface TKApplication(TKWindowEvent) <NSApplicationDelegate>
- (void) _setupWindowNotifications;
@end
@interface TKApplication(TKDialog) <NSOpenSavePanelDelegate>
@end
@interface TKApplication(TKMenu)
- (void)tkSetMainMenu:(TKMenu *)menu;
@end
@interface TKApplication(TKMenus)
- (void) _setupMenus;
@end
@interface NSApplication(TKNotify)
/* We need to declare this hidden method. */
- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
- (void) _runBackgroundLoop;
@end
@interface TKApplication(TKEvent)
- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent;
@end
@interface TKApplication(TKMouseEvent)
- (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent;
@end
@interface TKApplication(TKKeyEvent)
- (NSEvent *)tkProcessKeyEvent:(NSEvent *)theEvent;
@end
@interface TKApplication(TKMenu)
- (void)tkSetMainMenu:(TKMenu *)menu;
@end
@interface TKApplication(TKClipboard)
- (void)tkProvidePasteboard:(TkDisplay *)dispPtr;
- (void)tkCheckPasteboard;
@end
@interface TKApplication(TKHLEvents)
- (void) terminate: (id) sender;
- (void) superTerminate: (id) sender;
- (void) preferences: (id) sender;
- (void) handleQuitApplicationEvent:   (NSAppleEventDescriptor *)event
		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
- (void) handleOpenApplicationEvent:   (NSAppleEventDescriptor *)event
		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
		       withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
- (void) handleShowPreferencesEvent:   (NSAppleEventDescriptor *)event
		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
- (void) handleOpenDocumentsEvent:     (NSAppleEventDescriptor *)event
		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
- (void) handlePrintDocumentsEvent:    (NSAppleEventDescriptor *)event
		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
- (void) handleDoScriptEvent:          (NSAppleEventDescriptor *)event
		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
- (void)handleURLEvent:                (NSAppleEventDescriptor*)event
	           withReplyEvent:     (NSAppleEventDescriptor*)replyEvent;
@end

VISIBILITY_HIDDEN
/*
 * Subclass TKContentView from NSTextInputClient to enable composition and
 * input from the Character Palette.
 */

@interface TKContentView : NSView <NSTextInputClient>
@interface TKContentView : NSView <NSTextInput> {
{
@private
  /*Remove private API calls.*/
#if 0
    id _savedSubviews;
    BOOL _subviewsSetAside;
#endif
    NSString *privateWorkingText;
    Bool _tkNeedsDisplay;
    NSRect _tkDirtyRect;
    NSTrackingArea *trackingArea;
}
@property Bool tkNeedsDisplay;
@property NSRect tkDirtyRect;
@end

@interface TKContentView(TKKeyEvent)
- (void) deleteWorkingText;
- (void) cancelComposingText;
@end

@interface TKContentView(TKWindowEvent)
- (void) addTkDirtyRect: (NSRect) rect;
- (void) clearTkDirtyRect;
- (void) generateExposeEvents: (NSRect) rect;
- (void) drawRect: (NSRect) rect;
- (void) generateExposeEvents: (HIShapeRef) shape;
- (void) generateExposeEvents: (HIShapeRef) shape childrenOnly: (int) childrenOnly;
- (void) viewDidEndLiveResize;
- (void) tkToolbarButton: (id) sender;
@end

@interface NSWindow(TKWm)
- (NSPoint) tkConvertPointToScreen:(NSPoint)point;
- (NSPoint) tkConvertPointFromScreen:(NSPoint)point;
- (BOOL) isOpaque;
- (BOOL) wantsDefaultClipping;
- (BOOL) acceptsFirstResponder;
- (void) keyDown: (NSEvent *) theEvent;
@end

VISIBILITY_HIDDEN
@interface TKWindow : NSWindow
{
}
@property Window tkWindow;
@end

@interface TKWindow(TKWm)
@interface NSWindow(TKWm)
- (void)    tkLayoutChanged;
@end

- (NSPoint) convertPointToScreen:(NSPoint)point;
@interface TKDrawerWindow : NSWindow
{
    id _i1, _i2;
}
@property Window tkWindow;
@end

- (NSPoint) convertPointFromScreen:(NSPoint)point;
@interface TKPanel : NSPanel
{
}
@property Window tkWindow;
@end

@interface TKPanel(TKWm)
- (void)    tkLayoutChanged;
@end
#pragma mark NSMenu & NSMenuItem Utilities

@interface NSMenu(TKUtils)
+ (id)menuWithTitle:(NSString *)title;
+ (id)menuWithTitle:(NSString *)title menuItems:(NSArray *)items;
+ (id)menuWithTitle:(NSString *)title submenus:(NSArray *)submenus;
- (NSMenuItem *)itemWithSubmenu:(NSMenu *)submenu;
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
383
384
385
386
387
388
389


























































390
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
	keyEquivalent:(NSString *)keyEquivalent
	keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
+ (id)itemWithTitle:(NSString *)title action:(SEL)action
	target:(id)target keyEquivalent:(NSString *)keyEquivalent
	keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
@end

@interface NSColorPanel(TKDialog)
- (void) _setUseModalAppearance: (BOOL) flag;
@end

@interface NSFont(TKFont)
- (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters
	length: (NSUInteger) length attributes: (NSDictionary *) attributes
	actualCoveredLength: (NSUInteger *) coveredLength;
@end

/*
 * This method of NSApplication is not declared in NSApplication.h so we
 * declare it here to be a method of the TKMenu category.
 */

@interface NSApplication(TKMenu)
- (void) setAppleMenu: (NSMenu *) menu;
@end

/*
 * These methods are exposed because they are needed to prevent zombie windows
 * on systems with a TouchBar.  The TouchBar Key-Value observer holds a
 * reference to the key window, which prevents deallocation of the key window
 * when it is closed.
 */

@interface NSApplication(TkWm)
- (id) _setKeyWindow: (NSWindow *) window;
- (id) _setMainWindow: (NSWindow *) window;
@end


/*
 *---------------------------------------------------------------------------
 *
 * TKNSString --
 *
 * Tcl uses modified UTF-8 as internal encoding.  Apple's NSString class
 * does not provide a constructor which accepts a modified UTF-8 encoded
 * byte sequence as initial data.  So we add a new class which does provide
 * such a constructor.  It also has a DString property which is a DString whose
 * string pointer is a byte sequence encoding the NSString with modified UTF-8.
 *
 *---------------------------------------------------------------------------
 */

@interface TKNSString:NSString {
@private
    Tcl_DString _ds;
    NSString *_string;
    const char *_UTF8String;
}
@property const char *UTF8String;
@property (readonly) Tcl_DString DString;
- (instancetype)initWithTclUtfBytes:(const void *)bytes
			     length:(NSUInteger)len;
@end

#endif /* _TKMACPRIV */

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXRegion.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31

32
33
34
35
36
37
38
39
40
41
42
43
44


45
46

47
48
49
50
51
52
53
54
55

56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71



72
73
74
75

76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101





102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129





130
131
132
133
134
135
136
137
138
139

140
141

142
143
144
145
146
147
148
149
150
151
152
153
154


155
156
157


158
159
160
161
162
163

164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193

194
195
196
197
198
199
200
201

202
203

204
205
206
207
208


209
210
211
212
213
214
215
216
217
218


219
220
221
222
223
224
225
226




227
228
229
230

231
232
233
234
235
236
237

238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254




255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
1
2
3
4
5



6
7
8
9
10
11
12
13
14









15
16
17
18
19

20
21

22
23
24
25
26
27
28
29
30
31
32
33


34
35
36

37



38
39
40
41
42

43
44

45
46
47
48
49
50
51
52
53
54
55
56



57
58
59
60
61


62
63

64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82





83
84
85
86
87
88
89
90

91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109





110
111
112
113
114
115
116
117

118
119
120
121
122

123
124

125
126
127
128
129
130
131
132
133
134
135
136


137
138
139


140
141
142
143
144
145
146

147
148
149
150
151

152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176
177
178
179
180
181
182
183

184
185

186
187
188
189


190
191
192
193
194
195
196
197
198
199


200
201
202
203
204
205
206



207
208
209
210
211

212

213
214
215
216
217
218
219

220
221

222
223
224
225
226
227
228
229
230
231
232
233




234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252





-
-
-
+
+
+






-
-
-
-
-
-
-
-
-





-
+

-
+











-
-
+
+

-
+
-
-
-





-
+

-
+











-
-
-
+
+
+


-
-
+

-





-
+













-
-
-
-
-
+
+
+
+
+



-





-
+













-
-
-
-
-
+
+
+
+
+



-





-
+

-
+











-
-
+
+

-
-
+
+





-
+




-
+



-


















-
+

-
+







-
+

-
+



-
-
+
+








-
-
+
+





-
-
-
+
+
+
+

-

-
+






-
+

-
+











-
-
-
-
+
+
+
+








-







/*
 * tkMacOSXRegion.c --
 *
 *	Implements X window calls for manipulating regions
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
static void ReleaseRegion(TkRegion r);

#ifdef DEBUG
static int totalRegions = 0;
static int totalRegionRetainCount = 0;
#define DebugLog(msg, ...) fprintf(stderr, (msg), ##__VA_ARGS__)
#else
#define DebugLog(msg, ...)
#endif


/*
 *----------------------------------------------------------------------
 *
 * XCreateRegion --
 * TkCreateRegion --
 *
 *	Implements the equivalent of the X window function XCreateRegion. See
 *	Implements the equivelent of the X window function XCreateRegion. See
 *	Xwindow documentation for more details.
 *
 * Results:
 *	Returns an allocated region handle.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Region
XCreateRegion(void)
TkRegion
TkCreateRegion(void)
{
    Region region = (Region) HIShapeCreateMutable();
    return (TkRegion) HIShapeCreateMutable();
    DebugLog("Created region: total regions = %d, total count is %d\n",
	++totalRegions, ++totalRegionRetainCount);
    return region;
}

/*
 *----------------------------------------------------------------------
 *
 * XDestroyRegion --
 * TkDestroyRegion --
 *
 *	Implements the equivalent of the X window function XDestroyRegion. See
 *	Implements the equivelent of the X window function XDestroyRegion. See
 *	Xwindow documentation for more details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory is freed.
 *
 *----------------------------------------------------------------------
 */

int
XDestroyRegion(
    Region r)
void
TkDestroyRegion(
    TkRegion r)
{
    if (r) {
	DebugLog("Destroyed region: total regions = %d\n", --totalRegions);
	ReleaseRegion(r);
	CFRelease(r);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XIntersectRegion --
 * TkIntersectRegion --
 *
 *	Implements the equivalent of the X window function XIntersectRegion.
 *	See Xwindow documentation for more details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XIntersectRegion(
    Region sra,
    Region srb,
    Region dr_return)
void
TkIntersectRegion(
    TkRegion sra,
    TkRegion srb,
    TkRegion dr_return)
{
    ChkErr(HIShapeIntersect, (HIShapeRef) sra, (HIShapeRef) srb,
	   (HIMutableShapeRef) dr_return);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XSubtractRegion --
 * TkSubtractRegion --
 *
 *	Implements the equivalent of the X window function XSubtractRegion.
 *	See X window documentation for more details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XSubtractRegion(
    Region sra,
    Region srb,
    Region dr_return)
void
TkSubtractRegion(
    TkRegion sra,
    TkRegion srb,
    TkRegion dr_return)
{
    ChkErr(HIShapeDifference, (HIShapeRef) sra, (HIShapeRef) srb,
	   (HIMutableShapeRef) dr_return);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XUnionRectWithRegion --
 * TkUnionRectWithRegion --
 *
 *	Implements the equivalent of the X window function
 *	Implements the equivelent of the X window function
 *	XUnionRectWithRegion. See Xwindow documentation for more details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XUnionRectWithRegion(
void
TkUnionRectWithRegion(
    XRectangle* rectangle,
    Region src_region,
    Region dest_region_return)
    TkRegion src_region,
    TkRegion dest_region_return)
{
    const CGRect r = CGRectMake(rectangle->x, rectangle->y,
	    rectangle->width, rectangle->height);

    if (src_region == dest_region_return) {
	ChkErr(HIShapeUnionWithRect,
	ChkErr(TkMacOSHIShapeUnionWithRect,
		(HIMutableShapeRef) dest_region_return, &r);
    } else {
	HIShapeRef rectRgn = HIShapeCreateWithRect(&r);

	ChkErr(HIShapeUnion, rectRgn, (HIShapeRef) src_region,
	ChkErr(TkMacOSHIShapeUnion, rectRgn, (HIShapeRef) src_region,
		(HIMutableShapeRef) dest_region_return);
	CFRelease(rectRgn);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXIsEmptyRegion --
 *
 *	Return native region for given tk region.
 *
 * Results:
 *	1 if empty, 0 otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
int
TkMacOSXIsEmptyRegion(
    Region r)
    TkRegion r)
{
    return HIShapeIsEmpty((HIMutableShapeRef) r) ? 1 : 0;
}

/*
 *----------------------------------------------------------------------
 *
 * XRectInRegion --
 * TkRectInRegion --
 *
 *	Implements the equivalent of the X window function XRectInRegion. See
 *	Implements the equivelent of the X window function XRectInRegion. See
 *	Xwindow documentation for more details.
 *
 * Results:
 *	Returns RectanglePart or RectangleOut. Note that this is not a complete
 *	implementation since it doesn't test for RectangleIn.
 *	Returns RectanglePart or RectangleOut. Note that this is not a
 *	complete implementation since it doesn't test for RectangleIn.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XRectInRegion(
    Region region,
TkRectInRegion(
    TkRegion region,
    int x,
    int y,
    unsigned int width,
    unsigned int height)
{
    if (TkMacOSXIsEmptyRegion(region)) {
	return RectangleOut;
    } else {
    if ( TkMacOSXIsEmptyRegion(region) ) {
	    return RectangleOut;
	}
    else {
	const CGRect r = CGRectMake(x, y, width, height);

	return HIShapeIntersectsRect((HIShapeRef) region, &r) ?
		RectanglePart : RectangleOut;
	    RectanglePart : RectangleOut;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * XClipBox --
 * TkClipBox --
 *
 *	Implements the equivalent of the X window function XClipBox. See
 *	Implements the equivelent of the X window function XClipBox. See
 *	Xwindow documentation for more details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XClipBox(
    Region r,
    XRectangle *rect_return)
void
TkClipBox(
    TkRegion r,
    XRectangle* rect_return)
{
    CGRect rect;

    HIShapeGetBounds((HIShapeRef) r, &rect);
    rect_return->x = rect.origin.x;
    rect_return->y = rect.origin.y;
    rect_return->width = rect.size.width;
    rect_return->height = rect.size.height;
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpBuildRegionFromAlphaData --
 *
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274







-
+







 *	The region is updated, with extra pixels added to it.
 *
 *----------------------------------------------------------------------
 */

void
TkpBuildRegionFromAlphaData(
    Region region,			/* Region to update. */
    TkRegion region,			/* Region to update. */
    unsigned int x,			/* Where in region to update. */
    unsigned int y,			/* Where in region to update. */
    unsigned int width,			/* Size of rectangle to update. */
    unsigned int height,		/* Size of rectangle to update. */
    unsigned char *dataPtr,		/* Data to read from. */
    unsigned int pixelStride,		/* num bytes from one piece of alpha
					 * data to the next in the line. */
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335























336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353



354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+












-
-
-
+
+
+


-




















-
+







		lineDataPtr += pixelStride;
	    }
	    if (end > x1) {
		rect.x = x + x1;
		rect.y = y + y1;
		rect.width = end - x1;
		rect.height = 1;
		XUnionRectWithRegion(&rect, region, region);
		TkUnionRectWithRegion(&rect, region, region);
	    }
	}
	dataPtr += lineStride;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpRetainRegion --
 *
 *	Increases reference count of region.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpRetainRegion(
    TkRegion r)
{
    CFRetain(r);
}

/*
 *----------------------------------------------------------------------
 *
 * ReleaseRegion --
 * TkpReleaseRegion --
 *
 *	Decreases reference count of region.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May free memory.
 *
 *----------------------------------------------------------------------
 */

static void
ReleaseRegion(
    Region r)
void
TkpReleaseRegion(
    TkRegion r)
{
    CFRelease(r);
    DebugLog("Released region: total count is %d\n", --totalRegionRetainCount);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetEmptyRegion --
 *
 *	Set region to emtpy.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetEmptyRegion(
    Region r)
    TkRegion r)
{
    ChkErr(HIShapeSetEmpty, (HIMutableShapeRef) r);
}

/*
 *----------------------------------------------------------------------
 *
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

HIShapeRef
TkMacOSXGetNativeRegion(
    Region r)
    TkRegion r)
{
    return (HIShapeRef) CFRetain(r);
}

/*
 *----------------------------------------------------------------------
 *
414
415
416
417
418
419
420
421

422
423
424

425
426
427
428
429
430

431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447





448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470
471
472
473
474

475
476

477
478
479
480

481
482
483
484
485














































486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501


502
503
504
505
506
507
508
509
510
511
512

513
514
515
516
517


518
519
520

521
522
523



524
525
526
527
528





529
530

531
532
533
534
535
536



537
538

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
418
419
420
421
422
423
424

425
426
427

428
429
430
431
432
433

434
435
436
437
438
439
440
441
442
443
444
445
446





447
448
449
450
451
452
453

454
455
456
457
458













459






460


461




462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527


528
529











530





531
532

533

534



535
536
537
538
539



540
541
542
543
544
545

546






547
548
549
550

551











552
553
554
555
556
557
558
559







-
+


-
+





-
+












-
-
-
-
-
+
+
+
+
+


-





-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
-

-
+
-
-
-
+
+
+


-
-
-
+
+
+
+
+

-
+
-
-
-
-
-
-
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-








 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetWithNativeRegion(
    Region r,
    TkRegion r,
    HIShapeRef rgn)
{
    ChkErr(HIShapeSetWithShape, (HIMutableShapeRef) r, rgn);
    ChkErr(TkMacOSXHIShapeSetWithShape, (HIMutableShapeRef) r, rgn);
}

/*
 *----------------------------------------------------------------------
 *
 * XOffsetRegion --
 * TkMacOSXOffsetRegion --
 *
 *	Offsets region by given distances.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XOffsetRegion(
    Region r,
    int dx,
    int dy)
void
TkMacOSXOffsetRegion(
    TkRegion r,
    short dx,
    short dy)
{
    ChkErr(HIShapeOffset, (HIMutableShapeRef) r, dx, dy);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCopyRegion --
 *
 *  Makes the destination region a copy of the source region.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

 * TkMacOSXHIShapeCreateEmpty, TkMacOSXHIShapeCreateMutableWithRect,
void
TkpCopyRegion(
    TkRegion dst,
    TkRegion src)
{
    ChkErr(HIShapeSetWithShape, (HIMutableShapeRef)dst, (HIShapeRef)src);
 * TkMacOSXHIShapeSetWithShape, TkMacOSXHIShapeSetWithRect,
}

 * TkMacOSHIShapeDifferenceWithRect, TkMacOSHIShapeUnionWithRect,
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSHIShapeDifferenceWithRect --
 * TkMacOSHIShapeUnion --
 *
 *	Wrapper functions for missing/buggy HIShape API
 *
 *----------------------------------------------------------------------
 */

HIShapeRef
TkMacOSXHIShapeCreateEmpty(void)
{
    HIShapeRef result;

    result = HIShapeCreateEmpty();
    return result;
}

HIMutableShapeRef
TkMacOSXHIShapeCreateMutableWithRect(
    const CGRect *inRect)
{
    HIMutableShapeRef result;

    result = HIShapeCreateMutableWithRect(inRect);
    return result;
}

OSStatus
TkMacOSXHIShapeSetWithShape(
    HIMutableShapeRef inDestShape,
    HIShapeRef inSrcShape)
{
    OSStatus result;

    result = HIShapeSetWithShape(inDestShape, inSrcShape);
    return result;
}

#if 0
OSStatus
TkMacOSXHIShapeSetWithRect(
    HIMutableShapeRef inShape,
    const CGRect *inRect)
{
    OSStatus result;
    HIShapeRef rgn = HIShapeCreateWithRect(inRect);

    result = TkMacOSXHIShapeSetWithShape(inShape, rgn);
    CFRelease(rgn);

    return result;
}
#endif

OSStatus
TkMacOSHIShapeDifferenceWithRect(
    HIMutableShapeRef inShape,
    const CGRect *inRect)
{
    OSStatus result;
    HIShapeRef rgn = HIShapeCreateWithRect(inRect);

    result = HIShapeDifference(inShape, rgn, inShape);
    CFRelease(rgn);

    return result;
}

static OSStatus

OSStatus
rectCounter(
    TCL_UNUSED(int),
    TCL_UNUSED(HIShapeRef),
    TCL_UNUSED(const CGRect *),
    void *ref)
{
    int *count = (int *)ref;
    (*count)++;
    return noErr;
}

TkMacOSHIShapeUnionWithRect(
static OSStatus
rectPrinter(
    TCL_UNUSED(int),
    TCL_UNUSED(HIShapeRef),
    const CGRect *rect,
    HIMutableShapeRef inShape,
    const CGRect *inRect)
    TCL_UNUSED(void *))
{
    if (rect) {
    OSStatus result;
	fprintf(stderr, "    %s\n", NSStringFromRect(*rect).UTF8String);
    }
    return noErr;

    result = HIShapeUnionWithRect(inShape, inRect);
    return result;
}

int
TkMacOSXCountRectsInRegion(
    HIShapeRef shape)
OSStatus
TkMacOSHIShapeUnion(
    HIShapeRef inShape1,
    HIShapeRef inShape2,
    HIMutableShapeRef outResult)
{
    int rect_count = 0;
    OSStatus result;
    if (!HIShapeIsEmpty(shape)) {
	HIShapeEnumerate(shape,
	    kHIShapeParseFromBottom|kHIShapeParseFromLeft,
	    (HIShapeEnumerateProcPtr) rectCounter, (void *) &rect_count);
    }
    return rect_count;

    result = HIShapeUnion(inShape1, inShape2, outResult);
    return result;
}


void
TkMacOSXPrintRectsInRegion(
    HIShapeRef shape)
{
    if (!HIShapeIsEmpty(shape)) {
	HIShapeEnumerate( shape,
	    kHIShapeParseFromBottom|kHIShapeParseFromLeft,
	    (HIShapeEnumerateProcPtr) rectPrinter, NULL);
    }
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXScale.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17






-
-
-
-
+
+
+
+







/*
 * tkMacOSXScale.c --
 *
 *	This file implements the Macintosh specific portion of the
 *	scale widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2008-2009 Apple Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2008-2009, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkScale.h"
47
48
49
50
51
52
53
54
55
56
57




58
59
60
61
62
63
64
47
48
49
50
51
52
53




54
55
56
57
58
59
60
61
62
63
64







-
-
-
-
+
+
+
+







 */
static ControlActionUPP scaleActionProc = NULL; /* Pointer to func. */

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

static void		MacScaleEventProc(void *clientData,
			    XEvent *eventPtr);
static pascal void	ScaleActionProc(ControlRef theControl,
			    ControlPartCode partCode);
static void MacScaleEventProc(ClientData clientData, XEvent *eventPtr);
static pascal void ScaleActionProc(ControlRef theControl,
	ControlPartCode partCode);


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateScale --
 *
 *	Allocate a new TkScale structure.
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94







-
+







-
+







 *----------------------------------------------------------------------
 */

TkScale *
TkpCreateScale(
    Tk_Window tkwin)
{
    MacScale *macScalePtr = (MacScale *)ckalloc(sizeof(MacScale));
    MacScale *macScalePtr = ckalloc(sizeof(MacScale));

    macScalePtr->scaleHandle = NULL;
    if (scaleActionProc == NULL) {
	scaleActionProc = NewControlActionUPP(ScaleActionProc);
    }

    Tk_CreateEventHandler(tkwin, ButtonPressMask,
	    MacScaleEventProc, macScalePtr);
	    MacScaleEventProc, (ClientData) macScalePtr);

    return (TkScale *) macScalePtr;
}

/*
 *----------------------------------------------------------------------
 *
121
122
123
124
125
126
127
128
129


130
131
132
133
134
135
136
137
138
139
140
141
142

143
144

145
146
147
148
149

150
151


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171

172
173

174
175
176
177
178
179
180




181
182
183
184
185
186

187
188
189
190

191
192
193

194
195
196
197



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217





218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143

144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172

173


174


175




176
177
178
179
180
181
182
183
184

185
186
187
188

189
190
191

192
193
194


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256







-
-
+
+












-
+

-
+




-
+


+
+

















-
+

-
+
-
-
+
-
-

-
-
-
-
+
+
+
+





-
+



-
+


-
+


-
-
+
+
+


















-
-
+
+
+
+
+








-
+










-
+








-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayScale --
 *
 *	This procedure is invoked as an idle handler to redisplay the contents
 *	of a scale widget.
 *	This procedure is invoked as an idle handler to redisplay
 *	the contents of a scale widget.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The scale gets redisplayed.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayScale(
    void *clientData)	/* Widget record for scale. */
    ClientData clientData)	/* Widget record for scale. */
{
    TkScale *scalePtr = clientData;
    TkScale *scalePtr = (TkScale *) clientData;
    Tk_Window tkwin = scalePtr->tkwin;
    Tcl_Interp *interp = scalePtr->interp;
    int result;
    char string[TCL_DOUBLE_SPACE];
    MacScale *macScalePtr = clientData;
    MacScale *macScalePtr = (MacScale *) clientData;
    Rect r;
    WindowRef windowRef;
    CGrafPtr destPort, savePort;
    Boolean portChanged;
    MacDrawable *macDraw;
    SInt32 initialValue, minValue, maxValue;
    UInt16 numTicks;
    Tcl_DString buf;

#ifdef TK_MAC_DEBUG_SCALE
    TkMacOSXDbgMsg("TkpDisplayScale");
#endif
    scalePtr->flags &= ~REDRAW_PENDING;
    if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) {
	goto done;
    }

    /*
     * Invoke the scale's command if needed.
     */

    Tcl_Preserve(scalePtr);
    Tcl_Preserve((ClientData) scalePtr);
    if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
	Tcl_Preserve(interp);
	Tcl_Preserve((ClientData) interp);
        if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format,
                scalePtr->value) < 0) {
	sprintf(string, scalePtr->format, scalePtr->value);
            string[TCL_DOUBLE_SPACE - 1] = '\0';
        }
	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, scalePtr->command, -1);
	Tcl_DStringAppend(&buf, " ", -1);
	Tcl_DStringAppend(&buf, string, -1);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	if (result != TCL_OK) {
	    Tcl_AddErrorInfo(interp, "\n    (command executed by scale)");
	    Tcl_BackgroundException(interp, result);
	}
	Tcl_Release(interp);
	Tcl_Release((ClientData) interp);
    }
    scalePtr->flags &= ~INVOKE_COMMAND;
    if (scalePtr->flags & SCALE_DELETED) {
	Tcl_Release(scalePtr);
	Tcl_Release((ClientData) scalePtr);
	return;
    }
    Tcl_Release(scalePtr);
    Tcl_Release((ClientData) scalePtr);

    /*
     * Now handle the part of redisplay that is the same for horizontal and
     * vertical scales: border and traversal highlight.
     * Now handle the part of redisplay that is the same for
     * horizontal and vertical scales: border and traversal
     * highlight.
     */

    if (scalePtr->highlightWidth != 0) {
	GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin));

	Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth,
		Tk_WindowId(tkwin));
    }
    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scalePtr->bgBorder,
	    scalePtr->highlightWidth, scalePtr->highlightWidth,
	    Tk_Width(tkwin) - 2*scalePtr->highlightWidth,
	    Tk_Height(tkwin) - 2*scalePtr->highlightWidth,
	    scalePtr->borderWidth, scalePtr->relief);

    /*
     * Set up port for drawing Macintosh control.
     */

    macDraw = (MacDrawable *)Tk_WindowId(tkwin);
    windowRef = TkMacOSXGetNSWindowForDrawable(Tk_WindowId(tkwin));
    macDraw = (MacDrawable *) Tk_WindowId(tkwin);
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
    windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin));
    portChanged = QDSwapPort(destPort, &savePort);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

    /*
     * Create Macintosh control.
     */

#define MAC_OSX_SCROLL_WIDTH 10

    if (scalePtr->orient == ORIENT_HORIZONTAL) {
	int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2;
	int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;

	if (offset < 0) {
	    offset = 0;
	}

	r.left = macDraw->xOff + scalePtr->inset;
	r.top = macDraw->yOff + offset;
	r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
	r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2;
    } else {
	int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2;
	int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;

	if (offset < 0) {
	    offset = 0;
	}

	r.left = macDraw->xOff + offset;
	r.top = macDraw->yOff + scalePtr->inset;
	r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2;
	r.bottom = macDraw->yOff + Tk_Height(tkwin) - scalePtr->inset;
	r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
    }

    if (macScalePtr->scaleHandle == NULL) {
#ifdef TK_MAC_DEBUG_SCALE
	TkMacOSXDbgMsg("Initialising scale");
#endif
	initialValue = scalePtr->value;
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288


289
290



291
292
293
294
295
296
297
298
299
300


301
302
303
304
305



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321


322
323
324
325


326
327
328
329
330
331
332
333
334
335




336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
















358
359
360
361
362
363
364
365
366
367


368
369
370
371
372
373
374


375
376
377
378
379
380
381

382
383
384
385
386
387


388
389
390
391
392
393
394
395
396



397
398








399
400
401
402
403
404
405
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

306
307
308
309



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
















357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380


381
382
383
384
385
386
387


388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430







-
+
















-
-
+
+


+
+
+









-
+
+


-
-
-
+
+
+
















+
+




+
+










+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
+
+





-
-
+
+






-
+






+
+






-
-
-
+
+
+


+
+
+
+
+
+
+
+







	    numTicks = 0;
	} else {
	    numTicks = (maxValue - minValue)/scalePtr->tickInterval;
	}

	CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue,
		kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc,
		&macScalePtr->scaleHandle);
		&(macScalePtr->scaleHandle));
	SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr);

	if (IsWindowActive(windowRef)) {
	    macScalePtr->flags |= ACTIVE;
	}
    } else {
	SetControlBounds(macScalePtr->scaleHandle, &r);
	SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value);
	SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue);
	SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue);
    }

    /*
     * Finally draw the control.
     */

    SetControlVisibility(macScalePtr->scaleHandle, true, true);
    HiliteControl(macScalePtr->scaleHandle, 0);
    SetControlVisibility(macScalePtr->scaleHandle,true,true);
    HiliteControl(macScalePtr->scaleHandle,0);
    Draw1Control(macScalePtr->scaleHandle);

    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }
done:
    scalePtr->flags &= ~REDRAW_ALL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpScaleElement --
 *
 *	Determine which part of a scale widget lies under a given point.
 *	Determine which part of a scale widget lies under a given
 *	point.
 *
 * Results:
 *	The return value is either TROUGH1, SLIDER, TROUGH2, or OTHER,
 *	depending on which of the scale's active elements (if any) is under the
 *	point at (x,y).
 *	The return value is either TROUGH1, SLIDER, TROUGH2, or
 *	OTHER, depending on which of the scale's active elements
 *	(if any) is under the point at (x,y).
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkpScaleElement(
    TkScale *scalePtr,		/* Widget record for scale. */
    int x, int y)		/* Coordinates within scalePtr's window. */
{
    MacScale *macScalePtr = (MacScale *) scalePtr;
    ControlPartCode part;
    Point where;
    Rect bounds;
    CGrafPtr destPort, savePort;
    Boolean portChanged;

#ifdef TK_MAC_DEBUG_SCALE
    TkMacOSXDbgMsg("TkpScaleElement");
#endif
    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(scalePtr->tkwin));
    portChanged = QDSwapPort(destPort, &savePort);

    /*
     * All of the calculations in this procedure mirror those in
     * DisplayScrollbar. Be sure to keep the two consistent.
     */

    TkMacOSXWinBounds((TkWindow *) scalePtr->tkwin, &bounds);
    where.h = x + bounds.left;
    where.v = y + bounds.top;
    part = TestControl(macScalePtr->scaleHandle, where);

    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }

#ifdef TK_MAC_DEBUG_SCALE
    fprintf (stderr,"ScalePart %d, pos ( %d %d )\n", part, where.h, where.v );
#endif

    switch (part) {
    case inSlider:
	return SLIDER;
    case inInc:
	if (scalePtr->orient == ORIENT_VERTICAL) {
	    return TROUGH1;
	} else {
	    return TROUGH2;
	}
    case inDecr:
	if (scalePtr->orient == ORIENT_VERTICAL) {
	    return TROUGH2;
	} else {
	    return TROUGH1;
	}
    default:
	return OTHER;
	case inSlider:
	    return SLIDER;
	case inInc:
	    if (scalePtr->orient == ORIENT_VERTICAL) {
		return TROUGH1;
	    } else {
		return TROUGH2;
	    }
	case inDecr:
	    if (scalePtr->orient == ORIENT_VERTICAL) {
		return TROUGH2;
	    } else {
		return TROUGH1;
	    }
	default:
	    return OTHER;
    }
}

/*
 *--------------------------------------------------------------
 *
 * MacScaleEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for ButtonPress events
 *	on scales.
 *	This procedure is invoked by the Tk dispatcher for
 *	ButtonPress events on scales.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the window gets deleted, internal structures get cleaned up. When
 *	it gets exposed, it is redisplayed.
 *	When the window gets deleted, internal structures get
 *	cleaned up. When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
MacScaleEventProc(
    void *clientData,	/* Information about window. */
    ClientData clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
{
    MacScale *macScalePtr = (MacScale *) clientData;
    Point where;
    Rect bounds;
    int part;
    CGrafPtr destPort, savePort;
    Boolean portChanged;

#ifdef TK_MAC_DEBUG_SCALE
    fprintf(stderr,"MacScaleEventProc\n" );
#endif

    /*
     * To call Macintosh control routines we must have the port set to the
     * window containing the control. We will then test which part of the
     * control was hit and act accordingly.
     * To call Macintosh control routines we must have the port
     * set to the window containing the control. We will then test
     * which part of the control was hit and act accordingly.
     */

    destPort = TkMacOSXGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin));
    portChanged = QDSwapPort(destPort, &savePort);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(macScalePtr->info.tkwin));

    TkMacOSXWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds);
    where.h = eventPtr->xbutton.x + bounds.left;
    where.v = eventPtr->xbutton.y + bounds.top;
#ifdef TK_MAC_DEBUG_SCALE
    TkMacOSXDbgMsg("calling TestControl");
#endif
    part = TestControl(macScalePtr->scaleHandle, where);
    if (part == 0) {
	return;
    }

417
418
419
420
421
422
423




424
425
426
427
428
429
430
431
432
433


434
435
436
437
438
439
440
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460


461
462
463
464
465
466
467
468
469







+
+
+
+








-
-
+
+








    /*
     * The HandleControlClick call will "eat" the ButtonUp event. We now
     * generate a ButtonUp event so Tk will unset implicit grabs etc.
     */

    TkGenerateButtonEventForXPointer(Tk_WindowId(macScalePtr->info.tkwin));

    if (portChanged) {
	QDSwapPort(savePort, NULL);
    }
}

/*
 *--------------------------------------------------------------
 *
 * ScaleActionProc --
 *
 *	Callback procedure used by the Macintosh toolbox call
 *	HandleControlClick. This call will update the display while the
 *	scrollbar is being manipulated by the user.
 *	HandleControlClick. This call will update the display
 *	while the scrollbar is being manipulated by the user.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May change the display.
 *
450
451
452
453
454
455
456
457

458
459

460
461
462
463
464
465
466
467
468
469
470
479
480
481
482
483
484
485

486
487

488
489
490
491
492
493
494
495
496
497
498
499







-
+

-
+











    TkScale *scalePtr = (TkScale *) GetControlReference(theControl);

#ifdef TK_MAC_DEBUG_SCALE
    TkMacOSXDbgMsg("ScaleActionProc");
#endif
    value = GetControlValue(theControl);
    TkScaleSetValue(scalePtr, value, 1, 1);
    Tcl_Preserve(scalePtr);
    Tcl_Preserve((ClientData) scalePtr);
    TkMacOSXRunTclEventLoop();
    Tcl_Release(scalePtr);
    Tcl_Release((ClientData) scalePtr);
}
#endif

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXScrlbr.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18
19
20



21
22
23
24
25
26

27
28
29
30

31
32
33
34

35
36

37
38
39
40
41
42
43

44
45
46

47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76



77
78
79
80


81
82
83
84
85
86
87
88
89
90
91



92






93

94
95

96
97
98
99

100
101
102
103



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

123

124
125
126
127


128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152


153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

248
249

250
251

252
253
254
255
256
257
258

259
260
261
262
263



264
265
266
267



268
269
270
271
272
273
274
275

276
277
278

279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297


298
299
300
301
302
303
304




305
306
307
308



309
310
311
312
313

314
315

316
317
318

319
320
321
322
323
324

325
326
327
328
329


330
331
332

333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354

355

356
357
358
359



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

375
376
377

378
379
380
381
382
383




384

385
386
387


388
389

390
391
392


393
394
395
396



397
398
399

400
401
402
403
404
405
406
407
408

409



410
411




412




413
414


415
416
417
418
419
420





421
422
423
424

425
426
427
428
429

430
431
432
433
434
435
436






437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

456
457

458
459

460
461
462

463
464
465
466




467
468
469
470
471
472
473
474



475
476
477
478
479
480

481
482
483
484
485
486
487



488
489

490
491

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

513
514
515

516
517


518
519



520
521
522



523
524
525
526



527
528
529
530
531
532






533
534

535
536
537



538
539
540
541
542
543
544


545
546
547
548


549
550
551

552
553
554


555
556

557
558
559
560
561
562

563
564
565
566



567
568
569
570
571
572
573
574
575





576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592

593
594
595



596
597

598
599
600
601
602

603
604
605
606
607

608

609



610
611
612
613
614
615
616

617
618

619
620

621
622
623
624
625
626
627
628
629
630
631
632

633
634
635
636






637
638
639
640



641
642
643


644
645

646
647
648
649
650



651
652

653
654

655
656
657



658
659
660
661

662
663
664


665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

691
692
693



694
695
696



697
698
699
700




701
702
703
704
705
706
707
708

709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769


770
771

772
773
774
775
776
777
778
779
780
781
782
783
784
785

786
787
788

789
790
791
792
793
794
795
796
797
798
799
1
2
3
4
5
6




7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27

28


29


30

31
32

33
34
35





36
37
38

39
40
41
42

43
44
45



46
47








48
49
50
51
52
53
54
55



56
57
58
59
60


61
62


63
64
65
66
67
68



69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84


85




86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109
110
111


112
113


114

115









116
117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132

133
134
135
136
137


















































































138
139

140
141

142


143
144
145
146
147
148
149

150
151
152



153
154
155




156
157
158
159
160




161

162



163


164
165




166
167
168
169
170
171
172
173
174
175


176
177
178
179
180




181
182
183
184
185



186
187
188
189




190
191

192



193



194


195





196
197



198

199
200

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

221
222



223
224
225
226












227

228
229
230

231
232
233




234
235
236
237

238
239


240
241
242

243
244


245
246
247
248


249
250
251
252
253

254









255
256
257
258
259


260
261
262
263
264
265
266
267
268


269
270
271





272
273
274
275
276
277
278
279

280



281

282



283
284


285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310

311
312

313
314
315

316
317
318


319
320
321
322
323
324
325
326
327



328
329
330
331
332
333
334
335

336
337
338
339
340
341
342

343
344
345
346

347
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374


375
376


377
378
379
380


381
382
383
384
385


386
387
388
389





390
391
392
393
394
395
396
397
398



399
400
401
402
403
404




405
406
407
408


409
410
411
412

413
414


415
416
417

418






419
420
421


422
423
424
425
426
427
428
429




430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

447
448

449

450
451


452
453
454
455

456
457
458

459

460
461
462
463
464

465
466
467

468
469
470
471
472
473
474
475
476

477
478

479
480

481
482
483
484
485
486
487
488
489
490
491
492
493
494




495
496
497
498
499
500
501



502
503
504



505
506
507

508
509
510



511
512
513
514

515


516
517


518
519
520
521
522
523

524
525


526
527

528
529
530
531
532


533

534

535














536



537
538
539



540
541
542




543
544
545
546








547



548



549








550























551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570


571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590

591
592
593















-
-
-
-
+
+
+
+
-
-








+
+
+





-
+
-

-
-
+
-
-

-
+

-
+


-
-
-
-
-
+


-
+



-
+


-
-
-


-
-
-
-
-
-
-
-








-
-
-
+
+
+


-
-
+
+
-
-






-
-
-
+
+
+

+
+
+
+
+
+

+

-
+


-
-
+
-
-
-
-
+
+
+


















-
+

+


-
-
+
+
-
-

-
+
-
-
-
-
-
-
-
-
-










-
-
+
+





-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+

-
+
-
-
+






-
+


-
-
-
+
+
+
-
-
-
-
+
+
+


-
-
-
-

-
+
-
-
-
+
-
-


-
-
-
-
+









-
-
+
+



-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
-
+

-
+
-
-
-
+
-
-
-

-
-
+
-
-
-
-
-
+
+
-
-
-
+
-


-
+


















+
-
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-

-
+


-
+


-
-
-
-
+
+
+
+
-
+

-
-
+
+

-
+

-
-
+
+


-
-
+
+
+


-
+
-
-
-
-
-
-
-
-
-
+

+
+
+
-
-
+
+
+
+

+
+
+
+
-
-
+
+

-
-
-
-
-
+
+
+
+
+



-
+
-
-
-

-
+
-
-
-


-
-
+
+
+
+
+
+


















-
+

-
+

-
+


-
+


-
-
+
+
+
+





-
-
-
+
+
+





-
+






-
+
+
+

-
+

-
+




















-
+



+
-
-
+
+
-
-
+
+
+

-
-
+
+
+


-
-
+
+
+

-
-
-
-
-
+
+
+
+
+
+


+
-
-
-
+
+
+



-
-
-
-
+
+


-
-
+
+


-
+

-
-
+
+

-
+
-
-
-
-
-
-
+


-
-
+
+
+





-
-
-
-
+
+
+
+
+












-
+

-

-
+

-
-
+
+
+

-
+


-

-
+




-
+

+
-
+
+
+






-
+

-
+

-
+












+
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
-
-
-
+
+

-
+


-
-
-
+
+
+

-
+
-
-
+

-
-
+
+
+



-
+

-
-
+
+
-





-
-
+
-

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
-
-
-

-
-
-

-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
-
+
+

-
+













-
+


-
+


-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXScrollbar.c --
 *
 *	This file implements the Macintosh specific portion of the scrollbar
 *	widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2015 Kevin Walzer/WordTech Commununications LLC.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2015 Kevin Walzer/WordTech Commununications LLC.
 * Copyright © 2018-2019 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkScrollbar.h"
#include "tkMacOSXPrivate.h"


#define MIN_SCROLLBAR_VALUE		0

/*
 * Minimum slider length, in pixels (designed to make sure that the slider is
 * always easy to grab with the mouse).
 */

#define MIN_SLIDER_LENGTH	18
#define MIN_SLIDER_LENGTH	5
#define MIN_GAP			4

/*
 * Borrowed from ttkMacOSXTheme.c to provide appropriate scaling.
/*Borrowed from ttkMacOSXTheme.c to provide appropriate scaling of scrollbar values.*/
 */

#ifdef __LP64__
#define RangeToFactor(maximum)	(((double) (INT_MAX >> 1)) / (maximum))
#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
#else
#define RangeToFactor(maximum)	(((double) (LONG_MAX >> 1)) / (maximum))
#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
#endif /* __LP64__ */

/*
 * Apple reversed the scroll direction with the release of OSX 10.7 Lion.
 */

#define SNOW_LEOPARD_STYLE	(NSAppKitVersionNumber < 1138)
#define MOUNTAIN_LION_STYLE (NSAppKitVersionNumber < 1138)

/*
 * Declaration of an extended scrollbar structure with Mac specific additions.
 * Declaration of Mac specific scrollbar structure.
 */

typedef struct MacScrollbar {
    TkScrollbar information;	/* Generic scrollbar info. */
    TkScrollbar information;	 /* Generic scrollbar info. */
    GC troughGC;		/* For drawing trough. */
    GC copyGC;			/* Used for copying from pixmap onto screen. */
    Bool buttonDown;            /* Is the mouse button down? */
    Bool mouseOver;             /* Is the pointer over the scrollbar. */
    HIThemeTrackDrawInfo info;	/* Controls how the scrollbar is drawn. */
} MacScrollbar;

/* Used to initialize a MacScrollbar's info field. */
HIThemeTrackDrawInfo defaultInfo = {
    .version = 0,
    .min = 0.0,
    .max = 100.0,
    .attributes = kThemeTrackShowThumb,
};

/*
 * The class procedure table for the scrollbar widget. All fields except size
 * are left initialized to NULL, which should happen automatically since the
 * variable is declared at this scope.
 */

const Tk_ClassProcs tkpScrollbarProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    NULL,			/* worldChangedProc */
    NULL,			/* createProc */
    NULL			/* modalProc */
    NULL,					/* worldChangedProc */
    NULL,					/* createProc */
    NULL					/* modalProc */
};

/*
 * Information on scrollbar layout, metrics, and draw info.

/*Information on scrollbar layout, metrics, and draw info.*/
 */

typedef struct ScrollbarMetrics {
    SInt32 width, minThumbHeight;
    int minHeight, topArrowHeight, bottomArrowHeight;
    NSControlSize controlSize;
} ScrollbarMetrics;

static ScrollbarMetrics metrics = {
    /* kThemeScrollBarMedium */
    15, MIN_SLIDER_LENGTH, 26, 14, 14, kControlSizeNormal
static ScrollbarMetrics metrics[2] = {
    {15, 54, 26, 14, 14, kControlSizeNormal}, /* kThemeScrollBarMedium */
    {11, 40, 20, 10, 10, kControlSizeSmall},  /* kThemeScrollBarSmall  */
};
HIThemeTrackDrawInfo info = {
    .version = 0,
    .min = 0.0,
    .max = 100.0,
    .attributes = kThemeTrackShowThumb,
};


/*
 * Declarations of static functions defined later in this file:
 * Forward declarations for procedures defined later in this file:
 */

static void		ScrollbarEventProc(void *clientData,
			    XEvent *eventPtr);
static void ScrollbarEventProc(ClientData clientData, XEvent *eventPtr);
static int		ScrollbarEvent(TkScrollbar *scrollPtr,
			    XEvent *eventPtr);
static void		UpdateControlValues(TkScrollbar *scrollPtr);

static int ScrollbarPress(TkScrollbar *scrollPtr, XEvent *eventPtr);
static void UpdateControlValues(TkScrollbar  *scrollPtr);

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateScrollbar --
 *
 *	Allocate a new TkScrollbar structure.
 *
 * Results:
 *	Returns a newly allocated TkScrollbar structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkScrollbar *
TkpCreateScrollbar(
    Tk_Window tkwin)
		   Tk_Window tkwin)
{

    MacScrollbar *scrollPtr = (MacScrollbar *)ckalloc(sizeof(MacScrollbar));

    scrollPtr->troughGC = NULL;
    scrollPtr->copyGC = NULL;
    scrollPtr->troughGC = None;
    scrollPtr->copyGC = None;
    scrollPtr->info = defaultInfo;
    scrollPtr->buttonDown = false;

    Tk_CreateEventHandler(tkwin,
    Tk_CreateEventHandler(tkwin,ExposureMask|StructureNotifyMask|FocusChangeMask|ButtonPressMask|ButtonReleaseMask|EnterWindowMask|LeaveWindowMask|VisibilityChangeMask, ScrollbarEventProc, scrollPtr);
	    ExposureMask        |
	    StructureNotifyMask |
	    FocusChangeMask     |
	    ButtonPressMask     |
	    ButtonReleaseMask   |
	    EnterWindowMask     |
	    LeaveWindowMask     |
	    VisibilityChangeMask,
	    ScrollbarEventProc, scrollPtr);

    return (TkScrollbar *) scrollPtr;
}

/*
 *--------------------------------------------------------------
 *
 * TkpDisplayScrollbar --
 *
 *	This procedure redraws the contents of a scrollbar window. It is
 *	invoked as a do-when-idle handler, so it only runs when there's nothing
 *	else for the application to do.
 *	invoked as a do-when-idle handler, so it only runs when there's
 *	nothing else for the application to do.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws a scrollbar on the screen.
 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080

/*
 * This stand-alone drawing function is used on macOS 10.9 and newer because
 * the HIToolbox does not draw the scrollbar thumb at the expected size on
 * those systems.  The thumb is drawn too large, causing a mouse click on the
 * thumb to be interpreted as a mouse click in the trough.
 */

static void drawMacScrollbar(
    TkScrollbar *scrollPtr,
    MacScrollbar *msPtr,
    CGContextRef context)
{
    Drawable d = Tk_WindowId(scrollPtr->tkwin);
    NSView *view = TkMacOSXGetNSViewForDrawable(d);
    CGPathRef path;
    CGPoint inner[2], outer[2], thumbOrigin;
    CGSize thumbSize;
    CGRect troughBounds = msPtr->info.bounds;
    troughBounds.origin.y = [view bounds].size.height -
	(troughBounds.origin.y + troughBounds.size.height);
    if (scrollPtr->vertical) {
	thumbOrigin.x = troughBounds.origin.x + MIN_GAP;
	thumbOrigin.y = troughBounds.origin.y + scrollPtr->sliderFirst;
	thumbSize.width = troughBounds.size.width - 2*MIN_GAP + 1;
	thumbSize.height = scrollPtr->sliderLast - scrollPtr->sliderFirst;
	inner[0] = troughBounds.origin;
	inner[1] = CGPointMake(inner[0].x,
			       inner[0].y + troughBounds.size.height);
	outer[0] = CGPointMake(inner[0].x + troughBounds.size.width - 1,
			       inner[0].y);
	outer[1] = CGPointMake(outer[0].x, inner[1].y);
    } else {
	thumbOrigin.x = troughBounds.origin.x + scrollPtr->sliderFirst;
	thumbOrigin.y = troughBounds.origin.y + MIN_GAP;
	thumbSize.width = scrollPtr->sliderLast - scrollPtr->sliderFirst;
	thumbSize.height = troughBounds.size.height - 2*MIN_GAP + 1;
	inner[0] = troughBounds.origin;
	inner[1] = CGPointMake(inner[0].x + troughBounds.size.width,
			       inner[0].y + 1);
	outer[0] = CGPointMake(inner[0].x,
			       inner[0].y + troughBounds.size.height);
	outer[1] = CGPointMake(inner[1].x, outer[0].y);
    }
    CGContextSetShouldAntialias(context, false);
    CGContextSetGrayFillColor(context, 250.0 / 255, 1.0);
    CGContextFillRect(context, troughBounds);
    CGContextSetGrayStrokeColor(context, 232.0 / 255, 1.0);
    CGContextStrokeLineSegments(context, inner, 2);
    CGContextSetGrayStrokeColor(context, 238.0 / 255, 1.0);
    CGContextStrokeLineSegments(context, outer, 2);

    /*
     * Do not display the thumb unless scrolling is possible, in accordance
     * with macOS behavior.
     *
     * Native scrollbars and Ttk scrollbars are always 15 pixels wide, but we
     * allow Tk scrollbars to have any width, even if it looks bad. To prevent
     * sporadic assertion errors when drawing skinny thumbs we must make sure
     * the radius is at most half the width.
     */

    if (scrollPtr->firstFraction > 0.0 || scrollPtr->lastFraction < 1.0) {
	CGRect thumbBounds = {thumbOrigin, thumbSize};
	int width = scrollPtr->vertical ? thumbSize.width : thumbSize.height;
	int radius = width >= 8 ? 4 : width >> 1;
	path = CGPathCreateWithRoundedRect(thumbBounds, radius, radius, NULL);
	CGContextBeginPath(context);
	CGContextAddPath(context, path);
	if (msPtr->info.trackInfo.scrollbar.pressState != 0) {
	    CGContextSetGrayFillColor(context, 133.0 / 255, 1.0);
	} else {
	    CGContextSetGrayFillColor(context, 200.0 / 255, 1.0);
	}
	CGContextSetShouldAntialias(context, true);
	CGContextFillPath(context);
	CFRelease(path);
    }
}
#endif

void
TkpDisplayScrollbar(
    void *clientData)	/* Information about window. */
		    ClientData clientData)	/* Information about window. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;
    Tk_Window tkwin = scrollPtr->tkwin;
    register Tk_Window tkwin = scrollPtr->tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkMacOSXDrawingContext dc;

    scrollPtr->flags &= ~REDRAW_PENDING;

    if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
	return;
  	return;
    }

    MacDrawable *macWin = (MacDrawable *)winPtr->window;
    NSView *view = TkMacOSXGetNSViewForDrawable(macWin);

    MacDrawable *macWin =  (MacDrawable *) winPtr->window;
    NSView *view = TkMacOSXDrawableView(macWin);
    if (!view ||
    if ((view == NULL)
	    || (macWin->flags & TK_DO_NOT_DRAW)
	    || !TkMacOSXSetupDrawingContext((Drawable)macWin, NULL, &dc)) {
	return;
	macWin->flags & TK_DO_NOT_DRAW ||
	!TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
      return;
    }

    /*
     * Transform NSView coordinates to CoreGraphics coordinates.
     */

    CGFloat viewHeight = [view bounds].size.height;
    CGAffineTransform t = {
    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
	.a = 1, .b = 0,
	.c = 0, .d = -1,
	.tx = 0, .ty = viewHeight
			    .ty = viewHeight};
    };

    CGContextConcatCTM(dc.context, t);

    /*
     * Draw a 3D rectangle to provide a base for the native scrollbar.
     */

    /*Draw Unix-style scroll trough to provide rect for native scrollbar.*/
    if (scrollPtr->highlightWidth != 0) {
    	GC fgGC, bgGC;

    	bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr, (Pixmap) macWin);
    	if (scrollPtr->flags & GOT_FOCUS) {
    	    fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr, (Pixmap) macWin);
    	} else {
    	    fgGC = bgGC;
    	}
    	Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
    		(Pixmap) macWin);
    	TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
    			       (Pixmap) macWin);
    }

    Tk_Draw3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder,
	    scrollPtr->highlightWidth, scrollPtr->highlightWidth,
	    Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
	    Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
	    scrollPtr->borderWidth, scrollPtr->relief);
    		       scrollPtr->highlightWidth, scrollPtr->highlightWidth,
    		       Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
    		       Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
    		       scrollPtr->borderWidth, scrollPtr->relief);
    Tk_Fill3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder,
	    scrollPtr->inset, scrollPtr->inset,
	    Tk_Width(tkwin) - 2*scrollPtr->inset,
	    Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT);
    		       scrollPtr->inset, scrollPtr->inset,
    		       Tk_Width(tkwin) - 2*scrollPtr->inset,
    		       Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT);

    /*
     * Update values and then draw the native scrollbar over the rectangle.
     */

    /*Update values and draw in native rect.*/
    UpdateControlValues(scrollPtr);

    if (MOUNTAIN_LION_STYLE) {
    if (SNOW_LEOPARD_STYLE) {
	HIThemeDrawTrack(&msPtr->info, 0, dc.context,
			 kHIThemeOrientationInverted);
      HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationInverted);
    } else if ([NSApp macOSVersion] <= 100800) {
	HIThemeDrawTrack(&msPtr->info, 0, dc.context,
			 kHIThemeOrientationNormal);
    } else {
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080

      HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal);
	/*
	 * Switch back to NSView coordinates and draw a modern scrollbar.
	 */

	CGContextConcatCTM(dc.context, t);
    }
    TkMacOSXRestoreDrawingContext(&dc);
	drawMacScrollbar(scrollPtr, msPtr, dc.context);
#endif
    }

    TkMacOSXRestoreDrawingContext(&dc);
    scrollPtr->flags &= ~REDRAW_PENDING;
}


/*
 *----------------------------------------------------------------------
 *
 * TkpComputeScrollbarGeometry --
 *
 *	After changes in a scrollbar's size or configuration, this procedure
 *	recomputes various geometry information used in displaying the
 *	scrollbar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The scrollbar will be displayed differently.
 *
 *----------------------------------------------------------------------
 */


extern void
 extern void
TkpComputeScrollbarGeometry(
    TkScrollbar *scrollPtr)
				/* Scrollbar whose geometry may have
				 * changed. */
			    register TkScrollbar *scrollPtr)
/* Scrollbar whose geometry may have
 * changed. */
{
    /*
     * The code below is borrowed from tkUnixScrlbr.c but has been adjusted to
     * account for some differences between macOS and X11. The Unix scrollbar
     * has an arrow button on each end.  On macOS 10.6 (Snow Leopard) the
     * scrollbars by default have both arrow buttons at the bottom or right.
     * (There is a preferences setting to use the Unix layout, but we are not
     * supporting that!)  On more recent versions of macOS there are no arrow
     * buttons at all. The case of no arrow buttons can be handled as a special
     * case of having both buttons at the end, but where scrollPtr->arrowLength
     * happens to be zero.  To adjust for having both arrows at the same end we
     * shift the scrollbar up by the arrowLength.
     */

    int fieldLength;
    int variant, fieldLength;

    if (scrollPtr->highlightWidth < 0) {
	scrollPtr->highlightWidth = 0;
    	scrollPtr->highlightWidth = 0;
    }
    scrollPtr->inset = scrollPtr->highlightWidth + scrollPtr->borderWidth;
    if ([NSApp macOSVersion] == 100600) {
	scrollPtr->arrowLength = scrollPtr->width;
    } else {
	scrollPtr->arrowLength = 0;
    variant = ((scrollPtr->vertical ? Tk_Width(scrollPtr->tkwin) :
		Tk_Height(scrollPtr->tkwin)) - 2 * scrollPtr->inset
	       < metrics[0].width) ? 1 : 0;
    scrollPtr->arrowLength = (metrics[variant].topArrowHeight +
    }
			      metrics[variant].bottomArrowHeight) / 2;
    fieldLength = (scrollPtr->vertical ? Tk_Height(scrollPtr->tkwin)
	    : Tk_Width(scrollPtr->tkwin))
	    - 2*(scrollPtr->arrowLength + scrollPtr->inset);
		   : Tk_Width(scrollPtr->tkwin))
	- 2 * (scrollPtr->arrowLength + scrollPtr->inset);
    if (fieldLength < 0) {
	fieldLength = 0;
    	fieldLength = 0;
    }
    scrollPtr->sliderFirst = fieldLength*scrollPtr->firstFraction;
    scrollPtr->sliderLast = fieldLength*scrollPtr->lastFraction;
    scrollPtr->sliderFirst = fieldLength * scrollPtr->firstFraction;
    scrollPtr->sliderLast = fieldLength * scrollPtr->lastFraction;

    /*
     * Adjust the slider so that it has at least a minimal size and so there
     * is a small gap on either end which can be used to scroll by one page.
     * Adjust the slider so that some piece of it is always
     * displayed in the scrollbar and so that it has at least
     * a minimal width (so it can be grabbed with the mouse).
     */

    if (scrollPtr->sliderFirst < MIN_GAP) {
    if (scrollPtr->sliderFirst > (fieldLength - 2*scrollPtr->borderWidth)) {
	scrollPtr->sliderFirst = MIN_GAP;
	scrollPtr->sliderLast += MIN_GAP;
    }
    if (scrollPtr->sliderLast > fieldLength - MIN_GAP) {
	scrollPtr->sliderLast = fieldLength - MIN_GAP;
	scrollPtr->sliderFirst -= MIN_GAP;
    }
    if (scrollPtr->sliderFirst > fieldLength - MIN_SLIDER_LENGTH) {
	scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH;
    	scrollPtr->sliderFirst = fieldLength - 2*scrollPtr->borderWidth;
    }
    if (scrollPtr->sliderFirst < 0) {
    	scrollPtr->sliderFirst = 0;
    }
    if (scrollPtr->sliderLast < scrollPtr->sliderFirst + MIN_SLIDER_LENGTH) {
	scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH;
    if (scrollPtr->sliderLast < (scrollPtr->sliderFirst +
				 metrics[variant].minThumbHeight)) {
    	scrollPtr->sliderLast = scrollPtr->sliderFirst +
	    metrics[variant].minThumbHeight;
    }
    if (scrollPtr->sliderLast > fieldLength) {
    	scrollPtr->sliderLast = fieldLength;
    }

    scrollPtr->sliderFirst += -scrollPtr->arrowLength + scrollPtr->inset;
    scrollPtr->sliderLast += scrollPtr->inset;
    scrollPtr->sliderFirst += scrollPtr->arrowLength + scrollPtr->inset;
    scrollPtr->sliderLast += scrollPtr->arrowLength + scrollPtr->inset;

    /*
     * Register the desired geometry for the window. Leave enough space for the
     * two arrows, if there are any arrows, plus a minimum-size slider, plus
     * border around the whole window, if any. Then arrange for the window to
     * be redisplayed.

    /* Register the desired geometry for the window (leave enough space
     * for the two arrows plus a minimum-size slider, plus border around
     * the whole window, if any). Then arrange for the window to be
     * redisplayed.
     */

    if (scrollPtr->vertical) {
	Tk_GeometryRequest(scrollPtr->tkwin,
    	Tk_GeometryRequest(scrollPtr->tkwin, scrollPtr->width + 2 * scrollPtr->inset, 2 * (scrollPtr->arrowLength + scrollPtr->borderWidth + scrollPtr->inset) +  metrics[variant].minThumbHeight);
		scrollPtr->width + 2*scrollPtr->inset,
		2*(scrollPtr->arrowLength + scrollPtr->borderWidth
		+ scrollPtr->inset) + metrics.minThumbHeight);
    } else {
	Tk_GeometryRequest(scrollPtr->tkwin,
    	Tk_GeometryRequest(scrollPtr->tkwin, 2 * (scrollPtr->arrowLength + scrollPtr->borderWidth + scrollPtr->inset) + metrics[variant].minThumbHeight, scrollPtr->width + 2 * scrollPtr->inset);
		2*(scrollPtr->arrowLength + scrollPtr->borderWidth
		+ scrollPtr->inset) + metrics.minThumbHeight,
		scrollPtr->width + 2*scrollPtr->inset);
    }
    Tk_SetInternalBorder(scrollPtr->tkwin, scrollPtr->inset);
}


}




/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyScrollbar --
 *
 *	Free data structures associated with the scrollbar control.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frees the GCs associated with the scrollbar.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyScrollbar(
    TkScrollbar *scrollPtr)
		    TkScrollbar *scrollPtr)
{
    MacScrollbar *macScrollPtr = (MacScrollbar *) scrollPtr;
    MacScrollbar *macScrollPtr = (MacScrollbar *)scrollPtr;

    if (macScrollPtr->troughGC != NULL) {
    if (macScrollPtr->troughGC != None) {
	Tk_FreeGC(scrollPtr->display, macScrollPtr->troughGC);
    }
    if (macScrollPtr->copyGC != NULL) {
    if (macScrollPtr->copyGC != None) {
	Tk_FreeGC(scrollPtr->display, macScrollPtr->copyGC);
    }
}


    macScrollPtr=NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpConfigureScrollbar --
 *
 *	This procedure is called after the generic code has finished processing
 *	configuration options, in order to configure platform specific options.
 *	There are no such option on the Mac, however.
 *	This procedure is called after the generic code has finished
 *	processing configuration options, in order to configure platform
 *	specific options.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Currently, none.
 *	Configuration info may get changed.
 *
 *----------------------------------------------------------------------
 */

void
TkpConfigureScrollbar(
    TCL_UNUSED(TkScrollbar *))
		      register TkScrollbar *scrollPtr)
/* Information about widget; may or may not
 * already have values for some fields. */
{
    /* empty */

}


/*
 *--------------------------------------------------------------
 *
 * TkpScrollbarPosition --
 *
 *	Determine the scrollbar element corresponding to a given position.
 *
 * Results:
 *	One of TOP_ARROW, TOP_GAP, etc., indicating which element of the
 *	scrollbar covers the position given by (x, y). If (x,y) is outside the
 *	scrollbar entirely, then OUTSIDE is returned.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkpScrollbarPosition(
    TkScrollbar *scrollPtr,
    register TkScrollbar *scrollPtr,
				/* Scrollbar widget record. */
    int x, int y)		/* Coordinates within scrollPtr's window. */
{

    /*
     * The code below is borrowed from tkUnixScrlbr.c and needs no adjustment
  /*
   * Using code from tkUnixScrlbr.c because Unix scroll bindings are
     * since it does not involve the arrow buttons.
     */
   * driving the display at the script level. All the Mac scrollbar
   * has to do is re-draw itself.
   */

    int length, width, tmp;
    const int inset = scrollPtr->inset;
    int length, fieldlength, width, tmp;
    register const int inset = scrollPtr->inset;
    register const int arrowSize = scrollPtr->arrowLength + inset;

    if (scrollPtr->vertical) {
	length = Tk_Height(scrollPtr->tkwin);
	width = Tk_Width(scrollPtr->tkwin);
  	length = Tk_Height(scrollPtr->tkwin);
  	fieldlength = length - 2 * arrowSize;
  	width = Tk_Width(scrollPtr->tkwin);
    } else {
	tmp = x;
	x = y;
	y = tmp;
	length = Tk_Width(scrollPtr->tkwin);
	width = Tk_Height(scrollPtr->tkwin);
  	tmp = x;
  	x = y;
  	y = tmp;
  	length = Tk_Width(scrollPtr->tkwin);
  	fieldlength = length - 2 * arrowSize;
  	width = Tk_Height(scrollPtr->tkwin);
    }

    fieldlength = fieldlength < 0 ? 0 : fieldlength;
    if (x < inset || x >= width - inset ||
	    y < inset || y >= length - inset) {
	return OUTSIDE;

    if (x<inset || x>=width-inset || y<inset || y>=length-inset) {
  	return OUTSIDE;
    }

    /*
     * Here we assume that the scrollbar is layed out with both arrow buttons
     * at the bottom (or right).  Except on 10.6, however, the arrows do not
     * actually exist, i.e. the arrowLength is 0.  These are the same
     * assumptions which are being made in TkpComputeScrollbarGeometry.
     * All of the calculations in this procedure mirror those in
     * TkpDisplayScrollbar. Be sure to keep the two consistent.
     */

    if (y < scrollPtr->sliderFirst + scrollPtr->arrowLength) {
	return TOP_GAP;
    if (y < scrollPtr->sliderFirst) {
  	return TOP_GAP;
    }
    if (y < scrollPtr->sliderLast) {
	return SLIDER;
  	return SLIDER;
    }
    if (y < length - (2*scrollPtr->arrowLength + inset)) {
	return BOTTOM_GAP;
    if (y < fieldlength){
  	return BOTTOM_GAP;
    }

    if (y < fieldlength + arrowSize) {
    /*
     * On systems newer than 10.6 we have already returned.
     */

    if (y < length - (scrollPtr->arrowLength + inset)) {
	return TOP_ARROW;
  	return TOP_ARROW;
    }
    return BOTTOM_ARROW;
}


}

/*
 *--------------------------------------------------------------
 *
 * UpdateControlValues --
 *
 *	This procedure updates the Macintosh scrollbar control to display the
 *	values defined by the Tk scrollbar. This is the key interface to the
 *	Mac-native scrollbar; the Unix bindings drive scrolling in the Tk
 *	window and all the Mac scrollbar has to do is redraw itself.
 *	This procedure updates the Macintosh scrollbar control to
 *	display the values defined by the Tk scrollbar. This is the
 *	key interface to the Mac-native * scrollbar; the Unix bindings
 *	drive scrolling in the Tk window and all the Mac scrollbar has
 *	to do is redraw itself.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The Macintosh control is updated.
 *
 *--------------------------------------------------------------
 */

static void
UpdateControlValues(
    TkScrollbar *scrollPtr)		/* Scrollbar data struct. */
		    TkScrollbar *scrollPtr)		/* Scrollbar data struct. */
{
    MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;
    Tk_Window tkwin = scrollPtr->tkwin;
    MacDrawable *macWin = (MacDrawable *)Tk_WindowId(scrollPtr->tkwin);
    MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin);
    double dViewSize;
    HIRect contrlRect;
    short height;
    HIRect  contrlRect;
    int variant;
    short width, height;

    NSView *view = TkMacOSXGetNSViewForDrawable(macWin);
    NSView *view = TkMacOSXDrawableView(macWin);
    CGFloat viewHeight = [view bounds].size.height;
    NSRect frame;

    frame = NSMakeRect(macWin->xOff, macWin->yOff, Tk_Width(tkwin),
	    Tk_Height(tkwin));
		       Tk_Height(tkwin));
    frame = NSInsetRect(frame, scrollPtr->inset, scrollPtr->inset);
    frame.origin.y = viewHeight - (frame.origin.y + frame.size.height);

    contrlRect = NSRectToCGRect(frame);
    msPtr->info.bounds = contrlRect;
    info.bounds = contrlRect;

    width = contrlRect.size.width;
    height = contrlRect.size.height - scrollPtr->arrowLength;
    height = contrlRect.size.height;

   variant = contrlRect.size.width < metrics[0].width ? 1 : 0;

    /*
     * Ensure we set scrollbar control bounds only once all size adjustments
     * have been computed.
     */

    msPtr->info.bounds = contrlRect;
    info.bounds = contrlRect;
    if (scrollPtr->vertical) {
	msPtr->info.attributes &= ~kThemeTrackHorizontal;
      info.attributes &= ~kThemeTrackHorizontal;
    } else {
	msPtr->info.attributes |= kThemeTrackHorizontal;
      info.attributes |= kThemeTrackHorizontal;
    }

    /*
     * Given the Tk parameters for the fractions of the start and end of the
     * thumb, the following calculation determines the location for the
     * Macintosh thumb. The Aqua scroll control works as follows. The
     * scrollbar's value is the position of the left (or top) side of the view
     * area in the content area being scrolled. The maximum value of the
     * control is therefore the dimension of the content area less the size of
     * the view area.
     */

    double maximum = 100,  factor;
    double factor = RangeToFactor(100.0);
    dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) * factor;
    msPtr->info.max = factor - dViewSize;
    msPtr->info.trackInfo.scrollbar.viewsize = dViewSize;
    factor = RangeToFactor(maximum);
    dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction)
	* factor;
    info.max =  MIN_SCROLLBAR_VALUE +
	factor - dViewSize;
    info.trackInfo.scrollbar.viewsize = dViewSize;
    if (scrollPtr->vertical) {
	if (SNOW_LEOPARD_STYLE) {
	    msPtr->info.value = factor * scrollPtr->firstFraction;
	} else {
      if (MOUNTAIN_LION_STYLE) {
	info.value = factor * scrollPtr->firstFraction;
      } else {
	    msPtr->info.value = msPtr->info.max -
		    factor * scrollPtr->firstFraction;
	}
	info.value = info.max - factor * scrollPtr->firstFraction;
      }
    } else {
	msPtr->info.value = factor * scrollPtr->firstFraction;
	 info.value =  MIN_SCROLLBAR_VALUE + factor * scrollPtr->firstFraction;
    }

    if ((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0)
	    || height <= metrics.minHeight) {
    	msPtr->info.enableState = kThemeTrackHideTrack;
    if((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0)
       || height <= metrics[variant].minHeight) {
    	info.enableState = kThemeTrackHideTrack;
    } else {
        msPtr->info.enableState = kThemeTrackActive;
    	info.enableState = kThemeTrackActive;
    	msPtr->info.attributes =
		kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost;
    	info.attributes = kThemeTrackShowThumb |  kThemeTrackThumbRgnIsNotGhost;
    }
}


}

/*
 *--------------------------------------------------------------
 *
 * ScrollbarEvent --
 * ScrollbarPress --
 *
 *	This procedure is invoked in response to <Button>,
 *      <ButtonRelease>, <EnterNotify>, and <LeaveNotify> events.  The
 *	This procedure is invoked in response to <ButtonPress>, <ButtonRelease>,
 *      <EnterNotify>, and <LeaveNotify> events. Scrollbar appearance is modified.
 *      Scrollbar appearance is modified for each event.
 *
 *--------------------------------------------------------------
 */

static int
ScrollbarEvent(
    TkScrollbar *scrollPtr,
ScrollbarPress(TkScrollbar *scrollPtr, XEvent *eventPtr)
    XEvent *eventPtr)
{
    MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;

    /*
     * The pressState does not indicate whether the moused button was pressed
     * at some location in the Scrollbar.  Rather, it indicates that the
     * scrollbar should appear as if it were pressed in that location. The
     * standard Mac behavior is that once the button is pressed inside the
     * Scrollbar the appearance should not change until the button is released,
     * even if the mouse moves outside of the scrollbar.  However, if the mouse
     * lies over the scrollbar but the button is not pressed then the
     * appearance should be the same as if the button had been pressed on the
     * slider, i.e. kThemeThumbPressed.  See the file Appearance.r, or
     * HIToolbox.bridgesupport on 10.14.
     */

    if (eventPtr->type == ButtonPress) {
  if (eventPtr->type == ButtonPress) {
	msPtr->buttonDown = true;
	UpdateControlValues(scrollPtr);

    UpdateControlValues(scrollPtr);
    info.trackInfo.scrollbar.pressState = 1;
  }
	int where = TkpScrollbarPosition(scrollPtr,
		eventPtr->xbutton.x, eventPtr->xbutton.y);

   if (eventPtr->type == EnterNotify) {
    info.trackInfo.scrollbar.pressState = 1;
  }
	switch (where) {
	case OUTSIDE:
	    msPtr->info.trackInfo.scrollbar.pressState = 0;
	    break;
  if (eventPtr->type == ButtonRelease || eventPtr->type == LeaveNotify) {
    info.trackInfo.scrollbar.pressState = 0;
  }
  return TCL_OK;
	case TOP_GAP:
	    msPtr->info.trackInfo.scrollbar.pressState = kThemeTopTrackPressed;
	    break;
	case SLIDER:
	    msPtr->info.trackInfo.scrollbar.pressState = kThemeThumbPressed;
	    break;
	case BOTTOM_GAP:
	    msPtr->info.trackInfo.scrollbar.pressState =
}
		    kThemeBottomTrackPressed;
	    break;
	case TOP_ARROW:

	    /*
	     * This looks wrong and the docs say it is wrong but it works.
	     */

	    msPtr->info.trackInfo.scrollbar.pressState =
		    kThemeTopInsideArrowPressed;
	    break;
	case BOTTOM_ARROW:
	    msPtr->info.trackInfo.scrollbar.pressState =
		    kThemeBottomOutsideArrowPressed;
	    break;
	}

    }
    if (eventPtr->type == ButtonRelease) {
	msPtr->buttonDown = false;
	if (!msPtr->mouseOver) {
	    msPtr->info.trackInfo.scrollbar.pressState = 0;
	}
    }
    if (eventPtr->type == EnterNotify) {
	msPtr->mouseOver = true;
	if (!msPtr->buttonDown) {
	    msPtr->info.trackInfo.scrollbar.pressState = kThemeThumbPressed;
	}
    }
    if (eventPtr->type == LeaveNotify) {
	msPtr->mouseOver = false;
	if (!msPtr->buttonDown) {
	    msPtr->info.trackInfo.scrollbar.pressState = 0;
	}
    }
    TkScrollbarEventuallyRedraw(scrollPtr);
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * ScrollbarEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for various events on
 *	scrollbars.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the window gets deleted, internal structures get cleaned up. When
 *	it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */

static void
ScrollbarEventProc(
    void *clientData,	/* Information about window. */
    XEvent *eventPtr)		/* Information about event. */
		   ClientData clientData,	/* Information about window. */
		   XEvent *eventPtr)		/* Information about event. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    TkScrollbar *scrollPtr = clientData;

    switch (eventPtr->type) {
    case UnmapNotify:
	TkMacOSXSetScrollbarGrow((TkWindow *) scrollPtr->tkwin, false);
	break;
    case ActivateNotify:
    case DeactivateNotify:
	TkScrollbarEventuallyRedraw(scrollPtr);
	break;
    case ButtonPress:
    case ButtonRelease:
    case EnterNotify:
    case LeaveNotify:
    	ScrollbarEvent(scrollPtr, eventPtr);
    	ScrollbarPress(clientData, eventPtr);
	break;
    default:
	TkScrollbarEventProc(scrollPtr, eventPtr);
	TkScrollbarEventProc(clientData, eventPtr);
    }
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXSend.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28




29
30
31
32
33
34
35
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24




25
26
27
28
29
30
31
32
33
34
35





-
+


















-
-
-
-
+
+
+
+







/*
 * tkMacOSXSend.c --
 *
 *	This file provides procedures that implement the "send" command,
 *	allowing commands to be passed from interpreter to interpreter. This
 *	current implementation for the Mac has most functionality stubbed out.
 *	current implementation for the Mac has most functionality stubed out.
 *
 *	The current plan, which we have not had time to implement, is for the
 *	first Wish app to create a gestalt of type 'WIsH'. This gestalt will
 *	point to a table, in system memory, of Tk apps. Each Tk app, when it
 *	starts up, will register their name, and process ID, in this table.
 *	This will allow us to implement "tk appname".
 *
 *	Then the send command will look up the process id of the target app in
 *	this table, and send an AppleEvent to that process. The AppleEvent
 *	handler is much like the do script handler, except that you have to
 *	specify the name of the tk app as well, since there may be many
 *	interps in one wish app, and you need to send it to the right one.
 *
 *	Implementing this has been on our list of things to do, but what with
 *	the demise of Tcl at Sun, and the lack of resources at Scriptics it
 *	may not get done for awhile. So this sketch is offered for the brave
 *	to attempt if they need the functionality...
 *
 * Copyright © 1989-1994 The Regents of the University of California.
 * Copyright © 1994-1998 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1989-1994 The Regents of the University of California.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXInt.h"

47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61







-
+







				 * list. */
} RegisteredInterp;

/*
 * A registry of all interpreters for a display is kept in a property
 * "InterpRegistry" on the root window of the display. It is organized as a
 * series of zero or more concatenated strings (in no particular order), each
 * of the form:
 * of the form
 *	window space name '\0'
 * where "window" is the hex id of the comm. window to use to talk to an
 * interpreter named "name".
 *
 * When the registry is being manipulated by an application (e.g. to add or
 * remove an entry), it is loaded into memory using a structure of the
 * following type:
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88







-
+







				 * none. See format description above; this is
				 * *not* terminated by the first null
				 * character. Dynamically allocated. */
    int allocedByX;		/* Non-zero means must free property with
				 * XFree; zero means use ckfree. */
} NameRegistry;

static int initialized = 0;	/* A flag to denote if we have initialized
static int initialized = 0; /* A flag to denote if we have initialized
				 * yet. */

static RegisteredInterp *interpListPtr = NULL;
				/* List of all interpreters registered by this
				 * process. */

/*
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
205
206
207
208
209
210
211

212

213
214
215
216
217
218
219







-
+
-







				 * application and the display. */
    const char *name)		/* The name that will be used to refer to the
				 * interpreter in later "send" commands. Must
				 * be globally unique. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    Tcl_Interp *interp = winPtr->mainPtr->interp;
    int suffix, result;
    int i, suffix, offset, result;
    Tcl_Size i, offset;
    RegisteredInterp *riPtr, *prevPtr;
    const char *actualName;
    Tcl_DString dString;
    Tcl_Obj *resultObjPtr, *interpNamePtr;
    char *interpName;

    if (!initialized) {
257
258
259
260
261
262
263
264

265
266
267

268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285

286
287

288
289
290
291
292
293
294
256
257
258
259
260
261
262

263
264
265

266
267
268
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285

286
287
288
289
290
291
292
293







-
+


-
+



-
+













-
+

-
+







	result = Tcl_ListObjIndex(NULL, resultObjPtr, i, &interpNamePtr);
	if (result != TCL_OK || interpNamePtr == NULL) {
	    break;
	}
	interpName = Tcl_GetString(interpNamePtr);
	if (strcmp(actualName, interpName) == 0) {
	    if (suffix == 1) {
		Tcl_DStringAppend(&dString, name, TCL_INDEX_NONE);
		Tcl_DStringAppend(&dString, name, -1);
		Tcl_DStringAppend(&dString, " #", 2);
		offset = Tcl_DStringLength(&dString);
		Tcl_DStringSetLength(&dString, offset + TCL_INTEGER_SPACE);
		Tcl_DStringSetLength(&dString, offset + 10);
		actualName = Tcl_DStringValue(&dString);
	    }
	    suffix++;
	    snprintf(Tcl_DStringValue(&dString) + offset, TCL_INTEGER_SPACE, "%d", suffix);
	    sprintf(Tcl_DStringValue(&dString) + offset, "%d", suffix);
	    i = 0;
	} else {
	    i++;
	}
    }

    Tcl_DecrRefCount(resultObjPtr);
    Tcl_ResetResult(interp);

    /*
     * We have found a unique name. Now add it to the registry.
     */

    riPtr = (RegisteredInterp *)ckalloc(sizeof(RegisteredInterp));
    riPtr = ckalloc(sizeof(RegisteredInterp));
    riPtr->interp = interp;
    riPtr->name = (char *)ckalloc(strlen(actualName) + 1);
    riPtr->name = ckalloc(strlen(actualName) + 1);
    riPtr->nextPtr = interpListPtr;
    interpListPtr = riPtr;
    strcpy(riPtr->name, actualName);

    /*
     * TODO: DeleteProc
     */
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332

333
334
335

336
337

338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353

354

355
356
357



358
359
360
361
362
363
364
365
366
316
317
318
319
320
321
322

323
324
325
326
327




328



329
330

331
332
333
334
335





336
337
338
339
340
341
342

343
344
345



346
347
348
349

350
351
352
353
354
355
356







-
+




-
-
-
-
+
-
-
-
+

-
+




-
-
-
-
-
+






-
+

+
-
-
-
+
+
+

-







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_SendObjCmd(
    TCL_UNUSED(void *),	/* Not used */
    ClientData clientData,	/* Used only for deletion */
    Tcl_Interp *interp,		/* The interp we are sending from */
    int objc,			/* Number of arguments */
    Tcl_Obj *const objv[])	/* The arguments */
{
    enum {
	SEND_ASYNC, SEND_DISPLAYOF, SEND_LAST
    };
    static const char *const sendOptions[] = {
    const char *const sendOptions[] = {"-async", "-displayof", "-", NULL};
	"-async",   "-displayof",   "--",  NULL
    };
    const char *stringRep, *destName;
    char *stringRep, *destName;
    /*int async = 0;*/
    int i, firstArg, index;
    int i, index, firstArg;
    RegisteredInterp *riPtr;
    Tcl_Obj *listObjPtr;
    int result = TCL_OK;

    /*
     * Process the command options.
     */

    for (i = 1; i < (objc - 1); i++) {
    for (i = 1; i < (objc - 1); ) {
	stringRep = Tcl_GetString(objv[i]);
	if (stringRep[0] == '-') {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
		    sizeof(char *), "option", 0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (index == SEND_ASYNC) {
	    if (index == 0) {
		/*async = 1;*/
		i++;
	    } else if (index == SEND_DISPLAYOF) {
		i++;
	    } else /* if (index == SEND_LAST) */ {
	    } else if (index == 1) {
		i += 2;
	    } else {
		i++;
		break;
	    }
	} else {
	    break;
	}
    }

    if (objc < (i + 2)) {
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
457
458
459
460
461
462
463

464
465
466
467
468
469
470
471
472
473

474
475
476
477
478
479
480
481







-
+









-
+







 *
 *----------------------------------------------------------------------
 */

int
TkGetInterpNames(
    Tcl_Interp *interp,		/* Interpreter for returning a result. */
    TCL_UNUSED(Tk_Window))		/* Window whose display is to be used for the
    Tk_Window tkwin)		/* Window whose display is to be used for the
				 * lookup. */
{
    Tcl_Obj *listObjPtr;
    RegisteredInterp *riPtr;

    listObjPtr = Tcl_NewListObj(0, NULL);
    riPtr = interpListPtr;
    while (riPtr != NULL) {
	Tcl_ListObjAppendElement(interp, listObjPtr,
		Tcl_NewStringObj(riPtr->name, TCL_INDEX_NONE));
		Tcl_NewStringObj(riPtr->name, -1));
	riPtr = riPtr->nextPtr;
    }

    Tcl_SetObjResult(interp, listObjPtr);
    return TCL_OK;
}

504
505
506
507
508
509
510
511



512
513
514
515
516
517
518
519
520
521
522
523
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515







-
+
+
+












 *	Sets up various data structures and windows.
 *
 *--------------------------------------------------------------
 */

static int
SendInit(
    TCL_UNUSED(Tcl_Interp *))		/* Not used */
    Tcl_Interp *interp)		/* Interpreter to use for error reporting (no
				 * errors are ever returned, but the
				 * interpreter is needed anyway). */
{
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXServices.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162


































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXServices.c --
 *\
 *	This file allows the integration of Tk and the Cocoa NSServices API.
 *
 * Copyright © 2010-2019 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2019 Marc Culler.
 * Copyright © 2010 Adrian Robert.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include <tkInt.h>
#include <tkMacOSXInt.h>

/*
 * Event proc which calls the PerformService procedure.
 */

static int
ServicesEventProc(
    TCL_UNUSED(Tcl_Event *),
    TCL_UNUSED(int))
{
    TkMainInfo *info = TkGetMainInfoList();

    Tcl_GlobalEval(info->interp, "::tk::mac::PerformService");
    return 1;
}

/*
 * The Wish application can send the current selection in the Tk clipboard
 * to other applications which accept messages of type NSString.  The TkService
 * object provides this service via its provideService method.  (The method
 * must be specified in the application's Info.plist file for this to work.)
 */

@interface TkService : NSObject {

}

+ (void) initialize;
- (void) provideService:(NSPasteboard *)pboard
	       userData:(NSString *)data
		  error:(NSString **)error;
- (BOOL) writeSelectionToPasteboard:(NSPasteboard *)pboard
			      types:(NSArray *)types;

@end

/*
 * Class methods.
 */

@implementation TkService

+ (void) initialize {
    NSArray *sendTypes = [NSArray arrayWithObjects:@"NSStringPboardType",
				  @"NSPasteboardTypeString", nil];
    [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:sendTypes];
    return;
}

/*
 * Get the current Tk selection and copy it to the system pasteboard.
 */

- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard
			     types:(NSArray *)types
{
    NSArray *typesDeclared = nil;
    NSString *pboardType = nil;
    TkMainInfo *info = TkGetMainInfoList();

    for (NSString *typeString in types) {
	if ([typeString isEqualToString:@"NSStringPboardType"] ||
	    [typeString isEqualToString:@"NSPasteboardTypeString"]) {
	    typesDeclared = [NSArray arrayWithObject:typeString];
	    pboardType = typeString;
	    break;
	}
    }
    if (!typesDeclared) {
	return NO;
    }
    Tcl_Eval(info->interp, "selection get");

    char *copystring = Tcl_GetString(Tcl_GetObjResult(info->interp));
    NSString *writestring = [NSString stringWithUTF8String:copystring];

    [pboard declareTypes:typesDeclared owner:nil];
    return [pboard setString:writestring forType:pboardType];
}

/*
 * This is the method that actually calls the Tk service; it must be specified
 * in Info.plist.
 */

- (void)provideService:(NSPasteboard *)pboard
	      userData:(NSString *)data
		 error:(NSString **)error
{
    NSString *pboardString = nil, *pboardType = nil;
    NSArray *types = [pboard types];
    Tcl_Event *event;
    (void)data;
    (void)error;

    /*
     * Get a string from the private pasteboard and copy it to the general
     * pasteboard to make it available to other applications.
     */

    for (NSString *typeString in types) {
	if ([typeString isEqualToString:@"NSStringPboardType"] ||
	    [typeString isEqualToString:@"NSPasteboardTypeString"]) {
	    pboardString = [pboard stringForType:typeString];
	    pboardType = typeString;
	    break;
	}
    }
    if (pboardString) {
	NSPasteboard *generalpasteboard = [NSPasteboard generalPasteboard];
	[generalpasteboard declareTypes:[NSArray arrayWithObjects:pboardType, nil]
				  owner:nil];
	[generalpasteboard setString:pboardString forType:pboardType];
	event = (Tcl_Event *)ckalloc(sizeof(Tcl_Event));
	event->proc = ServicesEventProc;
	Tcl_QueueEvent((Tcl_Event *)event, TCL_QUEUE_TAIL);
    }
}
@end

/*

 * Instantiate a TkService object and register it with the NSApplication.
 * This is called exactly one time from TkpInit.
 */

int
TkMacOSXServices_Init(
    TCL_UNUSED(Tcl_Interp *))
{
    /*
     * Initialize an instance of TkService and register it with the NSApp.
     */

    TkService *service = [[TkService alloc] init];
    [NSApp setServicesProvider:service];
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXSubwindows.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23





-
-
-
+
+
+








-







/*
 * tkMacOSXSubwindows.c --
 *
 *	Implements subwindows for the macintosh version of Tk.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXConstants.h"

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_CLIP_REGIONS
#endif
*/

35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53

54
55

56
57
58

59
60
61
62
63
64
65
66
67
68
69

70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126


127
128
129
130
131

132
133
134

135
136
137
138
139
140
141

142
143
144
145
146
147
148
149

150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170




171
172

173
174
175
176
177
178
179
180
181
182
183

184
185
186
187


188
189
190
191




192
193

194
195
196


197
198
199
200
201
202
203




204
205
206
207

208
209

210
211

212
213


214
215
216
217
218

219
220
221

222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244





245
246
247
248
249
250
251
252
253
254
255
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51

52
53

54
55
56

57
58
59
60
61
62
63
64
65
66
67

68
69
70

71
72
73
74

75
76
77

78
79
80

81
82
83
84
85

86

87
88
89
90

91
92
93

94
95
96

97
98

99
100

101
102
103
104
105
106
107

108
109
110
111
112
113
114


115
116


117
118

119
120
121

122


123
124
125
126

127
128
129
130
131




132




133

134
135
136
137
138
139
140
141
142
143
144
145
146



147
148
149
150


151











152




153
154




155
156
157
158
159

160



161
162







163
164
165
166
167



168


169


170


171
172
173

174


175
176
177

178


179








180
181
182
183
184
185







186
187
188
189
190




191
192
193
194
195
196
197







-
+










-
+

-
+


-
+










-
+


-
+



-



-



-





-

-
+



-



-



-


-


-
+






-







-
-
+
+
-
-


-
+


-
+
-
-




-
+




-
-
-
-
+
-
-
-
-
+
-













-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
+
+
+
+

-
+
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+

-
-
-
+
-
-
+
-
-
+
-
-
+
+

-

-
-
+


-
+
-
-
+
-
-
-
-
-
-
-
-






-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-









/*
 *----------------------------------------------------------------------
 *
 * XDestroyWindow --
 *
 *	Deallocates the given X Window.
 *	Dealocates the given X Window.
 *
 * Results:
 *	The window id is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XDestroyWindow(
    TCL_UNUSED(Display *),		/* Display. */
    Display *display,		/* Display. */
    Window window)		/* Window. */
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;

    /*
     * Remove any dangling pointers that may exist if the window we are
     * deleting is being tracked by the grab code.
     */

    TkPointerDeadWindow(macWin->winPtr);
    TkMacOSXSelDeadWindow(macWin->winPtr);
    macWin->toplevel->referenceCount--;

    if (!Tk_IsTopLevel(macWin->winPtr)) {
    if (!Tk_IsTopLevel(macWin->winPtr) ) {
	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
	if (macWin->winPtr->parentPtr != NULL) {
	    TkMacOSXInvalClipRgns((Tk_Window)macWin->winPtr->parentPtr);
	    TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
	}
	if (macWin->visRgn) {
	    CFRelease(macWin->visRgn);
            macWin->visRgn = NULL;
	}
	if (macWin->aboveVisRgn) {
	    CFRelease(macWin->aboveVisRgn);
            macWin->aboveVisRgn = NULL;
	}
	if (macWin->drawRgn) {
	    CFRelease(macWin->drawRgn);
            macWin->drawRgn = NULL;
	}

	if (macWin->toplevel->referenceCount == 0) {
	    ckfree(macWin->toplevel);
	}
	macWin->winPtr->privatePtr = NULL;
	ckfree(macWin);
	return Success;
	return;
    }
    if (macWin->visRgn) {
	CFRelease(macWin->visRgn);
        macWin->visRgn = NULL;
    }
    if (macWin->aboveVisRgn) {
	CFRelease(macWin->aboveVisRgn);
        macWin->aboveVisRgn = NULL;
    }
    if (macWin->drawRgn) {
	CFRelease(macWin->drawRgn);
        macWin->drawRgn = NULL;
    }
    macWin->view = nil;
    macWin->winPtr->privatePtr = NULL;

    /*
     * Delay deletion of a toplevel data structure until all children have
     * Delay deletion of a toplevel data structure untill all children have
     * been deleted.
     */

    if (macWin->toplevel->referenceCount == 0) {
	ckfree(macWin->toplevel);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XMapWindow --
 *
 *	This X11 stub maps the given X11 Window but does not update any of
 *      the Tk structures describing the window.  Tk applications should
 *	Map the given X Window to the screen. See X window documentation for
 *	more details.
 *	never call this directly, but it is called by Tk_MapWindow and
 *      Tk_WmMapWindow.
 *
 * Results:
 *	Always returns Success or BadWindow.
 *	None.
 *
 * Side effects:
 *	The subwindow or toplevel may appear on the screen.  VisibilityNotify
 *	The subwindow or toplevel may appear on the screen.
 *      events are generated.
 *
 *
 *----------------------------------------------------------------------
 */

int
void
XMapWindow(
    Display *display,		/* Display. */
    Window window)		/* Window. */
{
    if (!window) {
	return BadWindow;
    }
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;
    TkWindow *winPtr = macWin->winPtr;
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(window);
    static Bool initialized = NO;
    NSPoint mouse = [NSEvent mouseLocation];
    XEvent event;
    int x = mouse.x, y = TkMacOSXZeroScreenHeight() - mouse.y;

    /*
     * Under certain situations it's possible for this function to be called
     * before the toplevel window it's associated with has actually been
     * mapped. In that case we need to create the real Macintosh window now as
     * this function as well as other X functions assume that the portPtr is
     * valid.
     */

    if (!TkMacOSXHostToplevelExists(macWin->toplevel->winPtr)) {
	TkMacOSXMakeRealWindowExist(macWin->toplevel->winPtr);
    }

    LastKnownRequestProcessed(display)++;
    if (Tk_IsTopLevel(winPtr)) {
	if (!Tk_IsEmbedded(winPtr)) {
    display->request++;
    macWin->winPtr->flags |= TK_MAPPED;
    if (Tk_IsTopLevel(macWin->winPtr)) {
	if (!Tk_IsEmbedded(macWin->winPtr)) {
	    TKContentView *view = [win contentView];

	    NSWindow *win = TkMacOSXDrawableWindow(window);
	    /*
	     * We want to activate Tk when a toplevel is mapped but we must not
	     * supply YES here.  This is because during Tk initialization the
	     * root window is mapped before applicationDidFinishLaunching
	     * returns. Forcing the app to activate too early can make the menu
	     * bar unresponsive.
	     */

	    TkMacOSXApplyWindowAttributes(winPtr, win);
	    [win setExcludedFromWindowsMenu:NO];
	    [NSApp activateIgnoringOtherApps:initialized];
	    [NSApp activateIgnoringOtherApps:YES];
	    [view addTkDirtyRect: [view bounds]];
	    if (initialized) {
		if ([win canBecomeKeyWindow]) {
		    [win makeKeyAndOrderFront:NSApp];
	    if ( [win canBecomeKeyWindow] ) {
		[win makeKeyAndOrderFront:NSApp];
		} else {
		    [win orderFrontRegardless];
		}
	    }
	    }
	    TkMacOSXApplyWindowAttributes(macWin->winPtr, win);
	}
	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr);

	    /*
	/*
	     * Call Tk_UpdatePointer to tell Tk whether the pointer is in the
	     * new window.
	     */
	 * We only need to send the MapNotify event for toplevel windows.
	 */

	    NSPoint viewLocation = [view convertPoint:mouse fromView:nil];
	    if (NSPointInRect(viewLocation, NSInsetRect([view bounds], 2, 2))) {
		Tk_UpdatePointer((Tk_Window) winPtr, x, y, [NSApp tkButtonState]);
	    }
	} else {
	    Tk_Window contWinPtr = Tk_GetOtherWindow((Tk_Window)winPtr);

	event.xany.serial = LastKnownRequestProcessed(display);
	event.xany.send_event = False;
	event.xany.display = display;

	    /*
	     * Rebuild the container's clipping region and display
	     * the window.
	event.xmap.window = window;
	     */

	event.xmap.type = MapNotify;
	    TkMacOSXInvalClipRgns(contWinPtr);
	    TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
	event.xmap.event = window;
	}
	TkMacOSXInvalClipRgns((Tk_Window)winPtr);
	event.xmap.override_redirect = macWin->winPtr->atts.override_redirect;
	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    } else {

	/*
	 * For non-toplevel windows, rebuild the parent's clipping region
	 * and redisplay the window.
	 * Generate damage for that area of the window.
	 */

	TkMacOSXInvalClipRgns((Tk_Window)winPtr->parentPtr);
	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
    }

	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
    /*
     * Mark the toplevel as needing to be redrawn, unless the window is being
     * mapped while drawing is taking place.
     */

    TKContentView *view = [win contentView];
    if (view != [NSView focusView]) {
	[view addTkDirtyRect:[view bounds]];
    }

    /*
     * Generate VisibilityNotify events for window and all mapped children.
     */

    if (initialized) {
	XEvent event;
	event.xany.send_event = False;
	event.xany.display = display;
	event.xvisibility.type = VisibilityNotify;
	event.xvisibility.state = VisibilityUnobscured;
	NotifyVisibility(winPtr, &event);
    event.xany.send_event = False;
    event.xany.display = display;
    event.xvisibility.type = VisibilityNotify;
    event.xvisibility.state = VisibilityUnobscured;
    NotifyVisibility(macWin->winPtr, &event);
    } else {
	initialized = YES;
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * NotifyVisibility --
 *
283
284
285
286
287
288
289
290
291


292
293
294
295
296

297
298
299
300
301
302
303
304

305
306
307
308
309

310
311
312
313

314
315
316
317
318
319
320
321
322











323
324

325
326
327
328
329
330
331
332

333
334

335
336
337
338

339
340
341
342
343
344






345
346
347
348

349
350
351
352





353
354
355
356
357
358

359
360
361
362

363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401


402
403
404

405
406
407
408
409
410

411
412
413
414
415




416
417
418
419
420
421
422
423
424
425
426
427
428
429
430


431
432
433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449

450
451

452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
467
468
469
470









471
472

473
474
475
476
477
478
479
480
481
482
483
484
485


486
487
488
489
490
491
492
493
494
495
496

497
498
499
500
501
502

503
504

505
506
507
508
509

510
511
512
513
514
515
516
517
518
519
520
521
522
225
226
227
228
229
230
231


232
233


234
235

236
237
238
239
240
241
242
243

244
245
246
247
248

249




250









251
252
253
254
255
256
257
258
259
260
261


262








263


264

265


266






267
268
269
270
271
272




273




274
275
276
277
278
279

280



281
282
283


284




285

286





287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

306
307
308
309
310
311
312


313
314

315

316

317




318





319
320
321
322

323
324
325
326

327
328
329
330
331
332
333


334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353

354
355

356
357
358

359


360
361
362
363










364
365
366
367
368
369
370
371
372


373
374
375
376
377

378
379
380
381
382
383
384

385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402

403
404

405
406
407

408

409

410
411
412
413

414
415
416
417
418
419
420







-
-
+
+
-
-


-
+







-
+




-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
+
-
-
+
-

-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
+
+
+
+
+

-

-
-
-
+


-
-
+
-
-
-
-
+
-

-
-
-
-
-



















-
+






-
-
+
+
-

-
+
-

-
-
-
-
+
-
-
-
-
-
+
+
+
+
-




-







-
-
+
+










-
+







-
+

-
+


-

-
-
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+




-







-
+
+










-
+





-
+

-
+


-

-
+
-




-







}

/*
 *----------------------------------------------------------------------
 *
 * XUnmapWindow --
 *
 *	This X11 stub maps the given X11 Window but does not update any of
 *	The Tk structures describing the window.  Tk applications should
 *	Unmap the given X Window to the screen. See X window documentation for
 *	more details.
 *	never call this directly, but it is called by Tk_UnmapWindow and
 *      Tk_WmUnmapWindow.
 *
 * Results:
 *	Always returns Success or BadWindow.
 *	None.
 *
 * Side effects:
 *	The subwindow or toplevel may be removed from the screen.
 *
 *----------------------------------------------------------------------
 */

int
void
XUnmapWindow(
    Display *display,		/* Display. */
    Window window)		/* Window. */
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;
    TkWindow *winPtr = macWin->winPtr;
    TkWindow *parentPtr = winPtr->parentPtr;
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(window);

    XEvent event;
    if (!window) {
	return BadWindow;
    }
    LastKnownRequestProcessed(display)++;
    if (Tk_IsTopLevel(winPtr)) {
	if (!Tk_IsEmbedded(winPtr) &&
	    winPtr->wmInfoPtr->hints.initial_state!=IconicState) {
	    [win setExcludedFromWindowsMenu:YES];
	    [win orderOut:NSApp];

    display->request++;
    macWin->winPtr->flags &= ~TK_MAPPED;
    if (Tk_IsTopLevel(macWin->winPtr)) {
	if (!Tk_IsEmbedded(macWin->winPtr) &&
		macWin->winPtr->wmInfoPtr->hints.initial_state!=IconicState) {
	    NSWindow *win = TkMacOSXDrawableWindow(window);

	    if ([win isVisible]) {
		[[win parentWindow] removeChildWindow:win];
		[win orderOut:NSApp];
	    if ([win isKeyWindow]) {

	    }
		/*
		 * If we are unmapping the key window then we need to make sure
		 * that a new key window is assigned, if possible.  This is
		 * supposed to happen when a key window is ordered out, but as
		 * noted in tkMacOSXWm.c this does not happen, in spite of
		 * Apple's claims to the contrary.
		 */

	}
		for (NSWindow *w in [NSApp orderedWindows]) {
		    TkWindow *winPtr2 = TkMacOSXGetTkWindow(w);
	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr);
		    WmInfo *wmInfoPtr;

		    BOOL isOnScreen;

	/*
		    if (!winPtr2 || !winPtr2->wmInfoPtr) {
			continue;
		    }
		    wmInfoPtr = winPtr2->wmInfoPtr;
		    isOnScreen = (wmInfoPtr->hints.initial_state != IconicState &&
				  wmInfoPtr->hints.initial_state != WithdrawnState);
	 * We only need to send the UnmapNotify event for toplevel windows.
	 */

	event.xany.serial = LastKnownRequestProcessed(display);
	event.xany.send_event = False;
	event.xany.display = display;
		    if (w != win && isOnScreen && [w canBecomeKeyWindow]) {
			[w makeKeyAndOrderFront:NSApp];
			break;
		    }

		}
	    }
	}
	TkMacOSXInvalClipRgns((Tk_Window)winPtr);
	event.xunmap.type = UnmapNotify;
	event.xunmap.window = window;
	event.xunmap.event = window;
	event.xunmap.from_configure = false;
	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    } else {

	/*
	 * Rebuild the visRgn clip region for the parent so it will be allowed
	 * to draw in the space from which this subwindow was removed and then
	 * redraw the window.
	 * Generate damage for that area of the window.
	 */

	if (parentPtr && parentPtr->privatePtr->visRgn) {
	    TkMacOSXInvalidateViewRegion(
	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
		    TkMacOSXGetNSViewForDrawable(parentPtr->window),
		    parentPtr->privatePtr->visRgn);
	}
	TkMacOSXInvalClipRgns((Tk_Window)parentPtr);
	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
	TkMacOSXUpdateClipRgn(parentPtr);
    }
    TKContentView *view = [win contentView];
    if (view != [NSView focusView]) {
	[view addTkDirtyRect:[view bounds]];
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XResizeWindow --
 *
 *	Resize a given X window. See X windows documentation for further
 *	details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XResizeWindow(
    Display *display,		/* Display. */
    Window window,		/* Window. */
    unsigned int width,
    unsigned int height)
{
    MacDrawable *macWin = (MacDrawable *)window;

    MacDrawable *macWin = (MacDrawable *) window;
    display->request++;
    LastKnownRequestProcessed(display)++;
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	TKWindow *w = (TKWindow *)macWin->winPtr->wmInfoPtr->window;
	NSWindow *w = macWin->winPtr->wmInfoPtr->window;

	if (w) {
	    if ([w styleMask] & NSFullScreenWindowMask) {
		[(TKWindow *)w tkLayoutChanged];
	    } else {
		NSRect r = [w contentRectForFrameRect:[w frame]];
	    NSRect r = [w contentRectForFrameRect:[w frame]];

		r.origin.y += r.size.height - height;
		r.size.width = width;
		r.size.height = height;
		[w setFrame:[w frameRectForContentRect:r] display:NO];
	    r.origin.y += r.size.height - height;
	    r.size.width = width;
	    r.size.height = height;
	    [w setFrame:[w frameRectForContentRect:r] display:YES];
	    }
	}
    } else {
	MoveResizeWindow(macWin);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XMoveResizeWindow --
 *
 *	Move or resize a given X window. See X windows documentation for
 *	further details.
 *	Move or resize a given X window. See X windows documentation
 *	for further details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XMoveResizeWindow(
    Display *display,		/* Display. */
    Window window,		/* Window. */
    int x, int y,
    unsigned int width,
    unsigned int height)
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	NSWindow *w = macWin->winPtr->wmInfoPtr->window;

	if (w) {
	    /*
	     * We explicitly convert everything to doubles so we don't get
	    /* We explicitly convert everything to doubles so we don't get
	     * surprised (again) by what happens when you do arithmetic with
	     * unsigned ints.
	     */

	    CGFloat X = (CGFloat) x;
	    CGFloat Y = (CGFloat) y;
	    CGFloat Width = (CGFloat) width;
	    CGFloat Height = (CGFloat) height;
	    CGFloat XOff = (CGFloat) macWin->winPtr->wmInfoPtr->xInParent;
	    CGFloat YOff = (CGFloat) macWin->winPtr->wmInfoPtr->yInParent;
	    NSRect r = NSMakeRect(
		    X + XOff, TkMacOSXZeroScreenHeight() - Y - YOff - Height,
	    	    Width, Height);
	    CGFloat X = (CGFloat)x;
	    CGFloat Y = (CGFloat)y;
	    CGFloat Width = (CGFloat)width;
	    CGFloat Height = (CGFloat)height;
	    CGFloat XOff = (CGFloat)macWin->winPtr->wmInfoPtr->xInParent;
	    CGFloat YOff = (CGFloat)macWin->winPtr->wmInfoPtr->yInParent;
	    NSRect r = NSMakeRect(X + XOff,
	    			  tkMacOSXZeroScreenHeight - Y - YOff - Height,
	    			  Width, Height);

	    [w setFrame:[w frameRectForContentRect:r] display:NO];
	    [w setFrame:[w frameRectForContentRect:r] display:YES];
	}
    } else {
	MoveResizeWindow(macWin);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XMoveWindow --
 *
 *	Move a given X window. See X windows documentation for further details.
 *	Move a given X window. See X windows documentation for further
 *	details.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XMoveWindow(
    Display *display,		/* Display. */
    Window window,		/* Window. */
    int x, int y)
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	NSWindow *w = macWin->winPtr->wmInfoPtr->window;

	if (w) {
	    [w setFrameTopLeftPoint: NSMakePoint(
	    [w setFrameTopLeftPoint:NSMakePoint(x, tkMacOSXZeroScreenHeight - y)];
		    x, TkMacOSXZeroScreenHeight() - y)];
	}
    } else {
	MoveResizeWindow(macWin);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * MoveResizeWindow --
 *
533
534
535
536
537
538
539
540

541
542
543
544
545
546
547

548
549
550
551
552
553
554
431
432
433
434
435
436
437

438
439
440
441
442
443
444

445
446
447
448
449
450
451
452







-
+






-
+








static void
MoveResizeWindow(
    MacDrawable *macWin)
{
    int deltaX = 0, deltaY = 0, parentBorderwidth = 0;
    MacDrawable *macParent = NULL;
    NSWindow *macWindow = TkMacOSXGetNSWindowForDrawable((Drawable)macWin);
    NSWindow *macWindow = TkMacOSXDrawableWindow((Drawable) macWin);

    /*
     * Find the Parent window, for an embedded window it will be its container.
     */

    if (Tk_IsEmbedded(macWin->winPtr)) {
	TkWindow *contWinPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)macWin->winPtr);
	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr);

	if (contWinPtr) {
	    macParent = contWinPtr->privatePtr;
	} else {
	    /*
	     * Here we should handle out of process embedding. At this point,
	     * we are assuming that the changes.x,y is not maintained, if you
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482







-
+







		macWin->winPtr->changes.x - macWin->xOff;
	deltaY = macParent->yOff + parentBorderwidth +
		macWin->winPtr->changes.y - macWin->yOff;
    }
    if (macWindow) {
	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
	if (macParent) {
	    TkMacOSXInvalClipRgns((Tk_Window)macParent->winPtr);
	    TkMacOSXInvalClipRgns((Tk_Window) macParent->winPtr);
	}
    }
    UpdateOffsets(macWin->winPtr, deltaX, deltaY);
    if (macWindow) {
	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
    }
    GenerateConfigureNotify(macWin->winPtr, 0);
633
634
635
636
637
638
639
640

641
642
643
644
645

646
647

648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674

675
676
677
678
679

680
681

682
683
684
685
686
687
688
689
690

691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710

711
712
713
714
715

716
717

718
719
720

721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739



740
741
742
743






744
745
746
747
748
749


750
751
752
753
754
755
756
757
758
531
532
533
534
535
536
537

538
539
540
541
542

543
544

545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576

577
578

579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612

613
614

615
616
617

618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640
641


642
643
644
645
646
647
648
649
650



651
652


653
654
655
656
657
658
659







-
+




-
+

-
+







-


+
















-
+




-
+

-
+







-

+



















-
+




-
+

-
+


-
+


















-
+
+
+


-
-
+
+
+
+
+
+



-
-
-
+
+
-
-







 *
 * Side effects:
 *	Changes the stacking order of the specified window.
 *
 *----------------------------------------------------------------------
 */

int
void
XRaiseWindow(
    Display *display,		/* Display. */
    Window window)		/* Window. */
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	TkWmRestackToplevel(macWin->winPtr, Above, NULL);
    } else {
	/*
	 * TODO: this should generate damage
	 */
    }
    return Success;
}

#if 0
/*
 *----------------------------------------------------------------------
 *
 * XLowerWindow --
 *
 *	Change the stacking order of a window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes the stacking order of the specified window.
 *
 *----------------------------------------------------------------------
 */

int
void
XLowerWindow(
    Display *display,		/* Display. */
    Window window)		/* Window. */
{
    MacDrawable *macWin = (MacDrawable *)window;
    MacDrawable *macWin = (MacDrawable *) window;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
	TkWmRestackToplevel(macWin->winPtr, Below, NULL);
    } else {
	/*
	 * TODO: this should generate damage
	 */
    }
    return Success;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * XConfigureWindow --
 *
 *	Change the size, position, stacking, or border of the specified window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes the attributes of the specified window. Note that we ignore the
 *	passed in values and use the values stored in the TkWindow data
 *	structure.
 *
 *----------------------------------------------------------------------
 */

int
void
XConfigureWindow(
    Display *display,		/* Display. */
    Window w,			/* Window. */
    unsigned int value_mask,
    TCL_UNUSED(XWindowChanges *))
    XWindowChanges *values)
{
    MacDrawable *macWin = (MacDrawable *)w;
    MacDrawable *macWin = (MacDrawable *) w;
    TkWindow *winPtr = macWin->winPtr;

    LastKnownRequestProcessed(display)++;
    display->request++;

    /*
     * Change the shape and/or position of the window.
     */

    if (value_mask & (CWX|CWY|CWWidth|CWHeight)) {
	XMoveResizeWindow(display, w, winPtr->changes.x, winPtr->changes.y,
		winPtr->changes.width, winPtr->changes.height);
    }

    /*
     * Change the stacking order of the window. Tk actually keeps all the
     * information we need for stacking order. All we need to do is make sure
     * the clipping regions get updated and generate damage that will ensure
     * things get drawn correctly.
     */

    if (value_mask & CWStackMode) {
	NSView *view = TkMacOSXGetNSViewForDrawable(macWin);
	NSView *view = TkMacOSXDrawableView(macWin);
	Rect bounds;
	NSRect r;

	if (view) {
	    TkMacOSXInvalClipRgns((Tk_Window)winPtr->parentPtr);
	    TkpRedrawWidget((Tk_Window)winPtr);
	    TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr);
	    TkMacOSXWinBounds(winPtr, &bounds);
	    r = NSMakeRect(bounds.left,
		[view bounds].size.height - bounds.bottom,
		bounds.right - bounds.left, bounds.bottom - bounds.top);
	    [view setNeedsDisplayInRect:r];
	}
    }

#if 0
    TkGenWMMoveRequestEvent(macWin->winPtr,
	    macWin->winPtr->changes.x, macWin->winPtr->changes.y);
    /* TkGenWMMoveRequestEvent(macWin->winPtr,
	    macWin->winPtr->changes.x, macWin->winPtr->changes.y); */
#endif
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetDrawingEnabled --
 *
766
767
768
769
770
771
772
773
774


775
776
777
778
779
780

781
782
783
784
785
786
787
788
789


790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
667
668
669
670
671
672
673


674
675
676
677
678
679
680

681
682
683
684
685
686
687
688


689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713







-
-
+
+





-
+







-
-
+
+















-
+







 *	The clipping regions for the window and its children are cleared.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetDrawingEnabled(
    TkWindow *winPtr,
    int flag)
	TkWindow *winPtr,
	int flag)
{
    TkWindow *childPtr;
    MacDrawable *macWin = winPtr->privatePtr;

    if (macWin) {
	if (flag) {
	if (flag ) {
	    macWin->flags &= ~TK_DO_NOT_DRAW;
	} else {
	    macWin->flags |= TK_DO_NOT_DRAW;
	}
    }

    /*
     * Set the flag for all children & their descendants, excluding Toplevels.
     * (??? Do we need to exclude Toplevels?)
     * Set the flag for all children & their descendants, excluding
     * Toplevels. (??? Do we need to exclude Toplevels?)
     */

    childPtr = winPtr->childList;
    while (childPtr) {
	if (!Tk_IsTopLevel(childPtr)) {
	    TkMacOSXSetDrawingEnabled(childPtr, flag);
	}
	childPtr = childPtr->nextPtr;
    }

    /*
     * If the window is a container, set the flag for its embedded window.
     */

    if (Tk_IsContainer(winPtr)) {
	childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	childPtr = TkpGetOtherWindow(winPtr);

	if (childPtr) {
	    TkMacOSXSetDrawingEnabled(childPtr, flag);
	}
    }
}

851
852
853
854
855
856
857
858

859
860
861
862

863
864
865
866
867
868
869
870
871
872


873
874
875
876
877
878
879
880
881
882
883
884
885
886

887
888
889
890









891
892
893
894
895
896
897
752
753
754
755
756
757
758

759
760
761
762

763
764
765
766
767
768
769
770
771


772
773
774
775
776
777
778
779
780
781
782
783
784
785
786

787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807







-
+



-
+








-
-
+
+













-
+




+
+
+
+
+
+
+
+
+







	    HIMutableShapeRef rgn;

	    /*
	     * Start with a region defined by the window bounds.
	     */

	    TkMacOSXWinCGBounds(winPtr, &bounds);
	    rgn = HIShapeCreateMutableWithRect(&bounds);
	    rgn = TkMacOSXHIShapeCreateMutableWithRect(&bounds);

	    /*
	     * Clip away the area of any windows that may obscure this window.
	     * For a non-toplevel window, first, clip to the parent's visible
	     * For a non-toplevel window, first, clip to the parents visible
	     * clip region. Second, clip away any siblings that are higher in
	     * the stacking order. For an embedded toplevel, just clip to the
	     * container's visible clip region. Remember, we only allow one
	     * contained window in a frame, and don't support any other widgets
	     * in the frame either. This is not currently enforced, however.
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		if (winPtr->parentPtr) {
		    TkMacOSXUpdateClipRgn(winPtr->parentPtr);
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
		if (winPtr->parentPtr) {
		    ChkErr(HIShapeIntersect,
			    winPtr->parentPtr->privatePtr->aboveVisRgn,
			    rgn, rgn);
		}
		win2Ptr = winPtr;
		while ((win2Ptr = win2Ptr->nextPtr)) {
		    if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
			continue;
		    }
		    TkMacOSXWinCGBounds(win2Ptr, &bounds);
		    ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		}
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		    ChkErr(HIShapeIntersect,
			    win2Ptr->privatePtr->aboveVisRgn, rgn, rgn);
		} else if (tkMacOSXEmbedHandler != NULL) {
		    TkRegion r = TkCreateRegion();
		    HIShapeRef visRgn;

		    tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr, r);
		    visRgn = TkMacOSXGetNativeRegion(r);
		    ChkErr(HIShapeIntersect, visRgn, rgn, rgn);
		    CFRelease(visRgn);
		    TkpReleaseRegion(r);
		}

		/*
		 * TODO: Here we should handle out of process embedding.
		 */
	    }
	    macWin->aboveVisRgn = HIShapeCreateCopy(rgn);
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926
822
823
824
825
826
827
828

829
830
831
832
833
834
835
836







-
+







		TkMacOSXWinCGBounds(win2Ptr, &bounds);
		ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		rgnChanged = 1;
		win2Ptr = win2Ptr->nextPtr;
	    }

	    if (Tk_IsContainer(winPtr)) {
		win2Ptr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    if (Tk_IsMapped(win2Ptr)) {
			TkMacOSXWinCGBounds(win2Ptr, &bounds);
			ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
			rgnChanged = 1;
		    }
		}
946
947
948
949
950
951
952
953

954
955
956
957
958

959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974


975
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992

993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031

1032
1033
1034
1035
1036
1037
1038
1039
856
857
858
859
860
861
862

863
864
865
866
867

868
869
870
871
872
873
874
875
876
877
878
879
880
881
882


883
884
885
886
887
888
889
890
891
892
893
894

895
896
897
898
899
900
901

902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922





923

924

925
926
927
928
929
930
931
932
933
934
935

936

937
938
939
940
941
942
943







-
+




-
+














-
-
+
+










-
+






-
+



















-
+
-
-
-
-
-

-
+
-










+
-
+
-







	     * (erroneous) drawing into it or its children from becoming
	     * visible. [Bug 940117]
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		}
	    }
	    macWin->aboveVisRgn = HIShapeCreateEmpty();
	    macWin->aboveVisRgn = TkMacOSXHIShapeCreateEmpty();
	}
	if (!macWin->visRgn) {
	    macWin->visRgn = HIShapeCreateCopy(macWin->aboveVisRgn);
	}
	macWin->flags &= ~TK_CLIP_INVALID;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXVisableClipRgn --
 *
 *	This function returns the Macintosh clipping region for the given
 *	window. The caller is responsible for disposing of the returned region
 *	via XDestroyRegion().
 *	window. The caller is responsible for disposing of the returned
 *	region via TkDestroyRegion().
 *
 * Results:
 *	The region.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Region
TkRegion
TkMacOSXVisableClipRgn(
    TkWindow *winPtr)
{
    if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
	TkMacOSXUpdateClipRgn(winPtr);
    }
    return (Region) HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
    return (TkRegion)HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInvalidateViewRegion --
 *
 *	This function invalidates the given region of a view.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Damage is created.
 *
 *----------------------------------------------------------------------
 */

static OSStatus
InvalViewRect(
InvalViewRect(int msg, HIShapeRef rgn, const CGRect *rect, void *ref) {
    int msg,
    TCL_UNUSED(HIShapeRef),
    const CGRect *rect,
    void *ref)
{
    static CGAffineTransform t;
    TKContentView *view = (TKContentView *)ref;
    NSView *view = ref;
    NSRect dirtyRect;

    if (!view) {
	return paramErr;
    }
    switch (msg) {
    case kHIShapeEnumerateInit:
	t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0,
		NSHeight([view bounds]));
	break;
    case kHIShapeEnumerateRect:
	[view setNeedsDisplayInRect:NSRectFromCGRect(
	dirtyRect = NSRectFromCGRect(CGRectApplyAffineTransform(*rect, t));
		CGRectApplyAffineTransform(*rect, t))];
	[view addTkDirtyRect:dirtyRect];
	break;
    }
    return noErr;
}

void
TkMacOSXInvalidateViewRegion(
1071
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085

1086
1087

1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100


1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117




































































1118
1119

1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166


1167
1168

1169
1170
1171
1172
1173
1174
1175
975
976
977
978
979
980
981

982
983
984
985
986
987
988

989
990

991

992
993
994
995
996
997
998
999
1000
1001


1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018


1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092
1093
1094
1095
1096

1097
1098







1099

1100
1101

1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113



1114









1115



1116
1117


1118
1119
1120
1121
1122
1123
1124
1125







-
+






-
+

-
+
-










-
-
+
+


-
+












-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+








-
+

-
-
-
-
-
-
-
+
-


-
+











-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
+







{
#ifdef TK_MAC_DEBUG_CLIP_REGIONS
    TkMacOSXDbgMsg("%s", macWin->winPtr->pathName);
#endif
    if (macWin->flags & TK_CLIP_INVALID) {
	TkMacOSXUpdateClipRgn(macWin->winPtr);
    }
    TkMacOSXInvalidateViewRegion(TkMacOSXGetNSViewForDrawable(macWin),
    TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(macWin),
	    (flag == TK_WINDOW_ONLY) ? macWin->visRgn : macWin->aboveVisRgn);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSWindowForDrawable --
 * TkMacOSXDrawableWindow --
 *
 *	This function returns the NSWindow for a given X drawable, if the
 *	This function returns the NSWindow for a given X drawable.
 *      drawable is a window.  If the drawable is a pixmap it returns nil.
 *
 * Results:
 *	A NSWindow, or nil for off screen pixmaps.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
Tk_MacOSXGetNSWindowForDrawable(
NSWindow*
TkMacOSXDrawableWindow(
    Drawable drawable)
{
    MacDrawable *macWin = (MacDrawable *)drawable;
    MacDrawable *macWin = (MacDrawable *) drawable;
    NSWindow *result = nil;

    if (!macWin || macWin->flags & TK_IS_PIXMAP) {
	result = nil;
    } else if (macWin->toplevel && macWin->toplevel->winPtr &&
	    macWin->toplevel->winPtr->wmInfoPtr &&
	    macWin->toplevel->winPtr->wmInfoPtr->window) {
	result = macWin->toplevel->winPtr->wmInfoPtr->window;
    } else if (macWin->winPtr && macWin->winPtr->wmInfoPtr &&
	    macWin->winPtr->wmInfoPtr->window) {
	result = macWin->winPtr->wmInfoPtr->window;
    } else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) {
	TkWindow *contWinPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)macWin->toplevel->winPtr);

	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
	if (contWinPtr) {
	    result = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr);
	}
    }
    return result;
}

void *
TkMacOSXDrawable(
    Drawable drawable)
{
    return TkMacOSXDrawableWindow(drawable);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetDrawablePort --
 *
 *	This function returns the Graphics Port for a given X drawable.
 *
 * Results:
 *	NULL.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
TkMacOSXGetDrawablePort(
    Drawable drawable)
{
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDrawableView --
 *
 *	This function returns the NSView for a given X drawable.
 *
 * Results:
 *	A NSView* or nil.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

NSView*
TkMacOSXDrawableView(
    MacDrawable *macWin)
{
    NSView *result = nil;

    if (!macWin) {
	result = nil;
    } else if (!macWin->toplevel) {
	result = macWin->view;
    } else if (!(macWin->toplevel->flags & TK_EMBEDDED)) {
	result = macWin->toplevel->view;
    } else {
	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
	if (contWinPtr) {
	    result = TkMacOSXGetNSWindowForDrawable((Drawable)contWinPtr->privatePtr);
	    result = TkMacOSXDrawableView(contWinPtr->privatePtr);
	}
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetNSViewForDrawable/TkMacOSXGetRootControl --
 * TkMacOSXGetRootControl --
 *
 *	The function name TkMacOSXGetRootControl is being preserved only
 *      because it exists in a stubs table.  Nobody knows what it means to
 *      get a "RootControl".  The macro TkMacOSXGetNSViewForDrawable calls
 *      this function and should always be used rather than directly using
 *      the obscure official name of this function.
 *
 *      It returns the NSView for a given X drawable in the case that the
 *	This function returns the NSView for a given X drawable.
 *      drawable is a window.  If the drawable is a pixmap it returns nil.
 *
 * Results:
 *	A NSView* or nil.
 *	A NSView* .
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void *
TkMacOSXGetRootControl(
    Drawable drawable)
{
    void *result = NULL;
    MacDrawable *macWin = (MacDrawable *)drawable;

    /*
    if (!macWin) {
	result = NULL;
    } else if (!macWin->toplevel) {
	result = macWin->view;
    } else if (!(macWin->toplevel->flags & TK_EMBEDDED)) {
	result = macWin->toplevel->view;
    } else {
	TkWindow *contWinPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)macWin->toplevel->winPtr);

     * will probably need to fix this up for embedding
	if (contWinPtr) {
	    result = TkMacOSXGetRootControl((Drawable)contWinPtr->privatePtr);
	}
     */

    }
    return result;
    return TkMacOSXDrawableView((MacDrawable *) drawable);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInvalClipRgns --
 *
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269
1270

1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295




1296
1297
1298
1299
1300
1301

1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230

1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241



1242
1243
1244
1245
1246
1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

































1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1280







-
+









-
+


-
+













-
+








-
+









-
+
-











-
-
-
+
+
+
+





-
+














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+







     * Invalidate clip regions for all children & their descendants, unless the
     * child is a toplevel.
     */

    childPtr = winPtr->childList;
    while (childPtr) {
	if (!Tk_IsTopLevel(childPtr)) {
	    TkMacOSXInvalClipRgns((Tk_Window)childPtr);
	    TkMacOSXInvalClipRgns((Tk_Window) childPtr);
	}
	childPtr = childPtr->nextPtr;
    }

    /*
     * Also, if the window is a container, mark its embedded window.
     */

    if (Tk_IsContainer(winPtr)) {
	childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	childPtr = TkpGetOtherWindow(winPtr);

	if (childPtr) {
	    TkMacOSXInvalClipRgns((Tk_Window)childPtr);
	    TkMacOSXInvalClipRgns((Tk_Window) childPtr);
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXWinBounds --
 *
 *	Given a Tk window this function determines the window's bounds in
 *	Given a Tk window this function determines the windows bounds in
 *	relation to the Macintosh window's coordinate system. This is also the
 *	same coordinate system as the Tk toplevel window in which this window
 *	is contained.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Fills in a Rect.
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXWinBounds(
    TkWindow *winPtr,
    void *bounds)
{
    Rect *b = (Rect *) bounds;
    Rect *b = (Rect *)bounds;

    b->left = winPtr->privatePtr->xOff;
    b->top = winPtr->privatePtr->yOff;
    b->right = b->left + winPtr->changes.width;
    b->bottom = b->top + winPtr->changes.height;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXWinCGBounds --
 *
 *	Given a Tk window this function determines the window's bounds in
 *	the coordinate system of the Tk toplevel window in which this window
 *	is contained.  This fills in a CGRect struct.
 *	Given a Tk window this function determines the windows bounds in
 *	relation to the Macintosh window's coordinate system. This is also the
 *	same coordinate system as the Tk toplevel window in which this window
 *	is contained.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Fill in a CGRect.
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXWinCGBounds(
    TkWindow *winPtr,
    CGRect *bounds)
{
    bounds->origin.x = winPtr->privatePtr->xOff;
    bounds->origin.y = winPtr->privatePtr->yOff;
    bounds->size.width = winPtr->changes.width;
    bounds->size.height = winPtr->changes.height;
}
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXWinNSBounds --
 *
 *	Given a Tk window this function determines the window's bounds in
 *	the coordinate system of the TKContentView in which this Tk window
 *	is contained, which has the origin at the lower left corner.  This
 *      fills in an NSRect struct and requires the TKContentView as a
 *      parameter
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Fills in an NSRect.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXWinNSBounds(
    TkWindow *winPtr,
    NSView *view,
    NSRect *bounds)
{
    bounds->size.width = winPtr->changes.width;
    bounds->size.height = winPtr->changes.height;
    bounds->origin.x = winPtr->privatePtr->xOff;
    bounds->origin.y = ([view bounds].size.height -
		       bounds->size.height -
		       winPtr->privatePtr->yOff);
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateOffsets --
 *
 *	Updates the X & Y offsets of the given TkWindow from the TopLevel it is
 *	a descendant of.
 *	a decendant of.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The xOff & yOff fields for the Mac window datastructure is updated to
 *	the proper offset.
1392
1393
1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323







-
+







	if (!Tk_IsTopLevel(childPtr)) {
	    UpdateOffsets(childPtr, deltaX, deltaY);
	}
	childPtr = childPtr->nextPtr;
    }

    if (Tk_IsContainer(winPtr)) {
	childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	childPtr = TkpGetOtherWindow(winPtr);
	if (childPtr != NULL) {
	    UpdateOffsets(childPtr,deltaX,deltaY);
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437

1438
1439

1440
1441
1442
1443
1444
1445
1446
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350
1351
1352
1353

1354
1355

1356
1357
1358
1359
1360
1361
1362
1363







-
+







-
+

-
+







 *
 *----------------------------------------------------------------------
 */

Pixmap
Tk_GetPixmap(
    Display *display,	/* Display for new pixmap (can be null). */
    TCL_UNUSED(Drawable),		/* Drawable where pixmap will be used (ignored). */
    Drawable d,		/* Drawable where pixmap will be used (ignored). */
    int width,		/* Dimensions of pixmap. */
    int height,
    int depth)		/* Bits per pixel for pixmap. */
{
    MacDrawable *macPix;

    if (display != NULL) {
	LastKnownRequestProcessed(display)++;
	display->request++;
    }
    macPix = (MacDrawable *)ckalloc(sizeof(MacDrawable));
    macPix = ckalloc(sizeof(MacDrawable));
    macPix->winPtr = NULL;
    macPix->xOff = 0;
    macPix->yOff = 0;
    macPix->visRgn = NULL;
    macPix->aboveVisRgn = NULL;
    macPix->drawRgn = NULL;
    macPix->referenceCount = 0;
1470
1471
1472
1473
1474
1475
1476
1477

1478
1479

1480





1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1387
1388
1389
1390
1391
1392
1393

1394
1395

1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415







-
+

-
+

+
+
+
+
+













 */

void
Tk_FreePixmap(
    Display *display,		/* Display. */
    Pixmap pixmap)		/* Pixmap to destroy */
{
    MacDrawable *macPix = (MacDrawable *)pixmap;
    MacDrawable *macPix = (MacDrawable *) pixmap;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (macPix->context) {
	char *data = CGBitmapContextGetData(macPix->context);

	if (data) {
	    ckfree(data);
	}
	CFRelease(macPix->context);
    }
    ckfree(macPix);
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/tkMacOSXSysTray.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
















































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkMacOSXSysTray.c --
 *
 *	tkMacOSXSysTray.c implements a "systray" Tcl command which allows
 *      one to change the system tray/taskbar icon of a Tk toplevel
 *      window and a "sysnotify" command to post system notifications.
 *      In macOS the icon appears on the right hand side of the menu bar.
 *
 * Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2020 Jan Nijtmans.
 * Copyright © 2020 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include <tkInt.h>
#include <tkMacOSXInt.h>
#include "tkMacOSXPrivate.h"

/*
 * Class declaration for TkStatusItem.
 */

@interface TkStatusItem: NSObject {
    NSStatusItem * statusItem;
    NSStatusBar * statusBar;
    NSImage * icon;
    NSString * tooltip;
    Tcl_Interp * interp;
    Tcl_Obj * b1_callback;
    Tcl_Obj * b3_callback;
}

- (id) init : (Tcl_Interp *) interp;
- (void) setImagewithImage : (NSImage *) image;
- (void) setTextwithString : (NSString *) string;
- (void) setB1Callback : (Tcl_Obj *) callback;
- (void) setB3Callback : (Tcl_Obj *) callback;
- (void) clickOnStatusItem;
- (void) dealloc;

@end



/*
 * Class declaration for TkStatusItem. A TkStatusItem represents an icon posted
 * on the status bar located on the right side of the MenuBar.  Each interpreter
 * may have at most one TkStatusItem.  A pointer to the TkStatusItem belonging
 * to an interpreter is stored as the clientData of the MacSystrayObjCmd instance
 * in that interpreter.  It will be NULL until the tk systray command is executed
 * by the interpreter.
 */

@implementation TkStatusItem : NSObject

- (id) init : (Tcl_Interp *) interpreter {
    [super init];
    statusBar = [NSStatusBar systemStatusBar];
    statusItem = [[statusBar statusItemWithLength:NSVariableStatusItemLength] retain];
    statusItem.button.target = self;
    statusItem.button.action = @selector(clickOnStatusItem);
    [statusItem.button sendActionOn : NSEventMaskLeftMouseUp | NSEventMaskRightMouseUp];
    statusItem.visible = YES;
    interp = interpreter;
    b1_callback = NULL;
    b3_callback = NULL;
    return self;
}

- (void) setImagewithImage : (NSImage *) image
{
    icon = nil;
    icon = image;
    statusItem.button.image = icon;
}

- (void) setTextwithString : (NSString *) string
{
    tooltip = nil;
    tooltip = string;
    statusItem.button.toolTip = tooltip;
}

- (void) setB1Callback : (Tcl_Obj *) obj
{
    if (obj != NULL) {
	Tcl_IncrRefCount(obj);
    }
    if (b1_callback != NULL) {
	Tcl_DecrRefCount(b1_callback);
    }
    b1_callback = obj;
}

- (void) setB3Callback : (Tcl_Obj *) obj
{
    if (obj != NULL) {
	Tcl_IncrRefCount(obj);
    }
    if (b3_callback != NULL) {
	Tcl_DecrRefCount(b3_callback);
    }
    b3_callback = obj;
}

- (void) clickOnStatusItem
{
    NSEvent *event = [NSApp currentEvent];
    if (([event type] == NSEventTypeLeftMouseUp) && (b1_callback != NULL)) {
	int result = Tcl_EvalObjEx(interp, b1_callback, TCL_EVAL_GLOBAL);
	if (result != TCL_OK) {
	    Tcl_BackgroundException(interp, result);
	}
    } else {
	if (([event type] == NSEventTypeRightMouseUp) && (b3_callback != NULL)) {
	    int result = Tcl_EvalObjEx(interp, b3_callback, TCL_EVAL_GLOBAL);
	    if (result != TCL_OK) {
		Tcl_BackgroundException(interp, result);
	    }
	}
    }
}
- (void) dealloc
{
    [statusBar removeStatusItem: statusItem];
    if (b1_callback != NULL) {
	Tcl_DecrRefCount(b1_callback);
    }
    if (b3_callback != NULL) {
	Tcl_DecrRefCount(b3_callback);
    }
    [super dealloc];
}

@end

/*
 * Type used for the ClientData of a MacSystrayObjCmd instance.
 */

typedef TkStatusItem** StatusItemInfo;



/*
 *----------------------------------------------------------------------
 *
 * MacSystrayDestroy --
 *
 * 	Removes an intepreters icon from the status bar.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The icon is removed and memory is freed.
 *
 *----------------------------------------------------------------------
 */

static void
MacSystrayDestroy(
    void *clientData)
{
    StatusItemInfo info = (StatusItemInfo)clientData;
    if (info) {
	[*info release];
	ckfree(info);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MacSystrayObjCmd --
 *
 * 	Main command for creating, displaying, and removing icons from the
 * 	status bar.
 *
 * Results:
 *
 *      A standard Tcl result.
 *
 * Side effects:
 *
 *	Management of icon display in the status bar.
 *
 *----------------------------------------------------------------------
 */

static int
MacSystrayObjCmd(
    void *clientData,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj *const *objv)
{
    Tk_Image tk_image;
    int result, idx;
    static const char *options[] =
	{"create", "modify", "destroy", NULL};
    typedef enum {TRAY_CREATE, TRAY_MODIFY, TRAY_DESTROY} optionsEnum;
    static const char *modifyOptions[] =
	{"image", "text", "b1_callback", "b3_callback", NULL};
    typedef enum {TRAY_IMAGE, TRAY_TEXT, TRAY_B1_CALLBACK, TRAY_B3_CALLBACK
        } modifyOptionsEnum;

    if ([NSApp macOSVersion] < 101000) {
	Tcl_AppendResult(interp,
	    "StatusItem icons not supported on macOS versions lower than 10.10",
	    NULL);
	return TCL_OK;
    }

    StatusItemInfo info = (StatusItemInfo)clientData;
    TkStatusItem *statusItem = *info;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "create | modify | destroy");
	return TCL_ERROR;
    }

    result = Tcl_GetIndexFromObjStruct(interp, objv[1], options,
				       sizeof(char *), "command", 0, &idx);

    if (result != TCL_OK) {
    	return TCL_ERROR;
    }
    switch((optionsEnum)idx) {
    case TRAY_CREATE: {

	if (objc < 3 ||  objc > 6) {
	    Tcl_WrongNumArgs(interp, 1, objv, "create -image -text -button1 -button3");
	    return TCL_ERROR;
	}

	if (statusItem == NULL) {
	    statusItem = [[TkStatusItem alloc] init: interp];
	    *info = statusItem;
	} else {
	    Tcl_AppendResult(interp, "Only one system tray icon supported per interpreter", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Create the icon.
	 */

	int width, height;
	Tk_Window tkwin = Tk_MainWindow(interp);
	TkWindow *winPtr = (TkWindow *)tkwin;
	Display *d = winPtr->display;
	NSImage *icon;

	tk_image = Tk_GetImage(interp, tkwin, Tcl_GetString(objv[2]), NULL, NULL);
	if (tk_image == NULL) {
	    return TCL_ERROR;
	}

	Tk_SizeOfImage(tk_image, &width, &height);
	if (width != 0 && height != 0) {
	    icon = TkMacOSXGetNSImageFromTkImage(d, tk_image,
						 width, height);
	    [statusItem setImagewithImage: icon];
	    Tk_FreeImage(tk_image);
	}

	/*
	 * Set the text for the tooltip.
	 */

	NSString *tooltip = [NSString stringWithUTF8String: Tcl_GetString(objv[3])];
	if (tooltip == nil) {
	    Tcl_AppendResult(interp, " unable to set tooltip for systray icon", NULL);
	    return TCL_ERROR;
	}

	[statusItem setTextwithString: tooltip];

	/*
	 * Set the proc for the callback.
	 */

	[statusItem setB1Callback : (objc > 4) ? objv[4] : NULL];
	[statusItem setB3Callback : (objc > 5) ? objv[5] : NULL];
	break;

    }
    case TRAY_MODIFY: {
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 1, objv, "modify object item");
	    return TCL_ERROR;
	}

	/*
	 * Modify the icon.
	 */

	result = Tcl_GetIndexFromObjStruct(interp, objv[2], modifyOptions,
					   sizeof(char *), "option", 0, &idx);

	if (result != TCL_OK) {
	    return TCL_ERROR;
	}
	switch ((modifyOptionsEnum)idx) {
	case TRAY_IMAGE: {
	    Tk_Window tkwin = Tk_MainWindow(interp);
	    TkWindow *winPtr = (TkWindow *)tkwin;
	    Display *d = winPtr -> display;
	    NSImage *icon;
	    int width, height;

	    tk_image = Tk_GetImage(interp, tkwin, Tcl_GetString(objv[3]), NULL, NULL);
	    if (tk_image == NULL) {
		Tcl_AppendResult(interp, " unable to obtain image for systray icon",
				 NULL);
		return TCL_ERROR;
	    }

	    Tk_SizeOfImage(tk_image, &width, &height);
	    if (width != 0 && height != 0) {
		icon = TkMacOSXGetNSImageFromTkImage(d, tk_image,
						     width, height);
		[statusItem setImagewithImage: icon];
	    }
	    Tk_FreeImage(tk_image);
	    break;
	}

        /*
         * Modify the text for the tooltip.
         */

	case TRAY_TEXT: {
	    NSString *tooltip = [NSString stringWithUTF8String:Tcl_GetString(objv[3])];
	    if (tooltip == nil) {
		Tcl_AppendResult(interp, "unable to set tooltip for systray icon",
				 NULL);
		return TCL_ERROR;
	    }

	    [statusItem setTextwithString: tooltip];
	    break;
	}

        /*
         * Modify the proc for the callback.
         */

	case TRAY_B1_CALLBACK: {
	    [statusItem setB1Callback : objv[3]];
	    break;
	}
	case TRAY_B3_CALLBACK: {
	    [statusItem setB3Callback : objv[3]];
	    break;
	}
    }
    break;
    }

    case TRAY_DESTROY: {
	/*
	 * Set all properties to nil, and release statusItem.
	 */
        [statusItem setImagewithImage: nil];
        [statusItem setTextwithString: nil];
        [statusItem setB1Callback : NULL];
        [statusItem setB3Callback : NULL];
        [statusItem release];
        *info = NULL;
        statusItem = NULL;
        break;
    }
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * SysNotifyObjCmd --
 *
 *      Create system notification.
 *
 * Results:
 *
 *      A standard Tcl result.
 *
 * Side effects:
 *
 *      System notifications are posted.
 *
 *-------------------------------z---------------------------------------
 */

static int SysNotifyObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj *const *objv)
{
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "title message");
	return TCL_ERROR;
    }

    if ([NSApp macOSVersion] < 101000) {
	Tcl_AppendResult(interp,
	    "Notifications not supported on macOS versions lower than 10.10",
	     NULL);
	return TCL_OK;
    }

    /*
     * Using NSAppleScript API here allows us to use a single API rather
     * than multiple, some deprecated, API's, and also allows notifications
     * to work correctly without requiring Wish to be code-signed - an
     * undocumented but apparently consistent requirement. And by calling
     * NSAppleScript inline rather than shelling to out osascript,
     * Wish shows correctly as the calling app rather than Script Editor.
     */

    NSString *title = [NSString stringWithUTF8String: Tcl_GetString(objv[1])];
    NSString *message = [NSString stringWithUTF8String: Tcl_GetString(objv[2])];
    NSMutableString *notify = [NSMutableString new];
    [notify appendString: @"display notification "];
    [notify appendString:@"\""];
    [notify appendString:message];
    [notify appendString:@"\""];
    [notify appendString:@" with title \""];
    [notify appendString:title];
    [notify appendString:@"\""];
    NSAppleScript *scpt = [[[NSAppleScript alloc] initWithSource:notify] autorelease];
    NSDictionary *errorInfo;
    NSAppleEventDescriptor *result = [scpt executeAndReturnError:&errorInfo];
    NSString *info = [result stringValue];
    const char* output = [info UTF8String];

    Tcl_AppendResult(interp,
		     output,
		     NULL);

    return TCL_OK;
}


/*
 *----------------------------------------------------------------------
 *
 * MacSystrayInit --
 *
 * 	Initialize this package and create script-level commands.
 *      This is called from TkpInit for each interpreter.
 *
 * Results:
 *
 *      A standard Tcl result.
 *
 * Side effects:
 *
 *	The tk systray and tk sysnotify commands are installed in an
 *	interpreter
 *
 *----------------------------------------------------------------------
 */

int
MacSystrayInit(Tcl_Interp *interp)
{

    /*
     * Initialize the TkStatusItem for this interpreter.
     */

    StatusItemInfo info = (StatusItemInfo) ckalloc(sizeof(StatusItemInfo));
    *info = 0;

    Tcl_CreateObjCommand(interp, "::tk::systray::_systray", MacSystrayObjCmd, info,
	    MacSystrayDestroy);
    Tcl_CreateObjCommand(interp, "::tk::sysnotify::_sysnotify", SysNotifyObjCmd, NULL, NULL);
    return TCL_OK;
}


/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXTest.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31

32
33
34
35
36
37
38
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15



16
17
18
19
20


21






22
23
24
25
26
27
28
29






-
-
-
+
+
+






-
-
-





-
-
+
-
-
-
-
-
-
+







/*
 * tkMacOSXTest.c --
 *
 *	Contains commands for platform specific tests for
 *	the Macintosh platform.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1996 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXConstants.h"
#include "tkMacOSXWm.h"


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

#if !defined(NDEBUG) && MAC_OS_X_VERSION_MAX_ALLOWED < 1080
static Tcl_ObjCmdProc DebuggerObjCmd;
static int		DebuggerObjCmd (ClientData dummy, Tcl_Interp *interp,
#endif
static Tcl_ObjCmdProc PressButtonObjCmd;
static Tcl_ObjCmdProc MoveMouseObjCmd;
static Tcl_ObjCmdProc InjectKeyEventObjCmd;
static Tcl_ObjCmdProc MenuBarHeightObjCmd;

			    int objc, Tcl_Obj *const objv[]);

/*
 *----------------------------------------------------------------------
 *
 * TkplatformtestInit --
 *
 *	Defines commands that test platform specific functionality for
51
52
53
54
55
56
57
58
59
60



61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205

206
207
208
209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
42
43
44
45
46
47
48



49
50
51




52
53
54
55
56
57
58
59

60
































61
62
63
64
65
66
67
68
69
70
71


72
73
74












































































75










76




77























78



































79
80




















81








































































































































































82
83
84
85
86
87
88
89







-
-
-
+
+
+
-
-
-
-








-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








TkplatformtestInit(
    Tcl_Interp *interp)		/* Interpreter to add commands to. */
{
    /*
     * Add commands for platform specific tests on MacOS here.
     */

#if !defined(NDEBUG) && MAC_OS_X_VERSION_MAX_ALLOWED < 1080
    Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd, NULL, NULL);
#endif
    Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);

    Tcl_CreateObjCommand(interp, "pressbutton", PressButtonObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "movemouse", MoveMouseObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "injectkeyevent", InjectKeyEventObjCmd, NULL, NULL);
    Tcl_CreateObjCommand(interp, "menubarheight", MenuBarHeightObjCmd, NULL, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * DebuggerObjCmd --
 *
 *	This procedure simply calls the low level debugger, which was
 *	This procedure simply calls the low level debugger.
 *      deprecated in OSX 10.8.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#if !defined(NDEBUG) && MAC_OS_X_VERSION_MAX_ALLOWED < 1080
static int
DebuggerObjCmd(
    TCL_UNUSED(void *),
    TCL_UNUSED(Tcl_Interp *),
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    Debugger();
    return TCL_OK;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * MenuBarHeightObjCmd --
 *
 *	This procedure calls [NSMenu menuBarHeight] and returns the result
 *      as an integer.  Windows can never be placed to overlap the MenuBar,
 *      so tests need to be aware of its size.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
MenuBarHeightObjCmd(
    TCL_UNUSED(void *),		/* Not used. */
DebuggerObjCmd(
    ClientData clientData,		/* Not used. */
    Tcl_Interp *interp,			/* Not used. */
    TCL_UNUSED(int),				/* Not used. */
    TCL_UNUSED(Tcl_Obj *const *))		/* Not used. */
{
    static int height = 0;
    if (height == 0) {
	height = (int) [[NSApp mainMenu] menuBarHeight];
    }
    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(height));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkTestLogDisplay --
 *
 *      The test image display procedure calls this to determine whether it
 *      should write a log message recording that it has being run.
 *
 * Results:
 *      Returns true if and only if the NSView of the drawable is the
 *      current focusView, which on 10.14 and newer systems can only be the
 *      case when within [NSView drawRect].
 *
 * Side effects:
 *	None
 *
 *----------------------------------------------------------------------
 */
MODULE_SCOPE Bool
TkTestLogDisplay(
    Drawable drawable)
{
    MacDrawable *macWin = (MacDrawable *)drawable;
    NSWindow *win = nil;
    if (macWin->toplevel && macWin->toplevel->winPtr &&
	macWin->toplevel->winPtr->wmInfoPtr &&
	macWin->toplevel->winPtr->wmInfoPtr->window) {
	win = macWin->toplevel->winPtr->wmInfoPtr->window;
    } else if (macWin->winPtr && macWin->winPtr->wmInfoPtr &&
	       macWin->winPtr->wmInfoPtr->window) {
	win = macWin->winPtr->wmInfoPtr->window;
    }
    if (win) {
	return ([win contentView] == [NSView focusView]);
    } else {
	return True;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PressButtonObjCmd --
 *
 *	This Tcl command simulates a button press at a specific screen
 *      location.  It injects NSEvents into the NSApplication event queue, as
 *      opposed to adding events to the Tcl queue as event generate would do.
 *      One application is for testing the grab command. These events have
 *      their timestamp property set to 0 as a signal indicating that they
 *      should not be ignored by [NSApp tkProcessMouseEvent].
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
PressButtonObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    int objc,				/* Not used. */
    Tcl_Obj *const objv[])
{
    int x = 0, y = 0, i, value;
    CGPoint pt;
    NSPoint loc;
    NSEvent *motion, *press, *release;
    NSArray *screens = [NSScreen screens];
    CGFloat ScreenHeight = 0;
    enum {X=1, Y};

    Tcl_Obj *const objv[])			/* Not used. */
    if (screens && [screens count]) {
	ScreenHeight = [[screens objectAtIndex:0] frame].size.height;
    }

{
    if (objc != 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "x y");
        return TCL_ERROR;
    }
    for (i = 1; i < objc; i++) {
	if (Tcl_GetIntFromObj(interp,objv[i],&value) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch (i) {
	case X:
	    x = value;
	    break;
	case Y:
	    y = value;
	    break;
	default:
	    break;
	}
    }
    pt.x = loc.x = x;
    pt.y = y;
    loc.y = ScreenHeight - y;

    Debugger();
    /*
     *  We set the timestamp to 0 as a signal to tkProcessMouseEvent.
     */

    CGWarpMouseCursorPosition(pt);
    motion = [NSEvent mouseEventWithType:NSMouseMoved
	location:loc
	modifierFlags:0
	timestamp:0
	windowNumber:0
	context:nil
	eventNumber:0
	clickCount:1
	pressure:0];
    [NSApp postEvent:motion atStart:NO];
    press = [NSEvent mouseEventWithType:NSLeftMouseDown
	location:loc
	modifierFlags:0
	timestamp:0
	windowNumber:0
	context:nil
	eventNumber:0
	clickCount:1
	pressure:0];
    [NSApp postEvent:press atStart:NO];
    release = [NSEvent mouseEventWithType:NSLeftMouseUp
	location:loc
	modifierFlags:0
	timestamp:0
	windowNumber:0
	context:nil
	eventNumber:0
	clickCount:1
	pressure:0];
    [NSApp postEvent:release atStart:NO];
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * MoveMouseObjCmd --
 *
 *	This Tcl command simulates a mouse motion to a specific screen
 *      location.  It injects an NSEvent into the NSApplication event queue,
 *      as opposed to adding events to the Tcl queue as event generate would
 *      do.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */


static int
MoveMouseObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    int x = 0, y = 0, i, value;
    CGPoint pt;
    NSPoint loc;
    NSEvent *motion;
    NSArray *screens = [NSScreen screens];
    CGFloat ScreenHeight = 0;
    enum {X=1, Y};

    if (screens && [screens count]) {
	ScreenHeight = [[screens objectAtIndex:0] frame].size.height;
    }

    if (objc != 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "x y");
        return TCL_ERROR;
    }
    for (i = 1; i < objc; i++) {
	if (Tcl_GetIntFromObj(interp,objv[i],&value) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch (i) {
	case X:
	    x = value;
	    break;
	case Y:
	    y = value;
	    break;
	default:
	    break;
	}
    }
    pt.x = loc.x = x;
    pt.y = y;
    loc.y = ScreenHeight - y;

    /*
     *  We set the timestamp to 0 as a signal to tkProcessMouseEvent.
     */

    CGWarpMouseCursorPosition(pt);
    motion = [NSEvent mouseEventWithType:NSMouseMoved
	location:loc
	modifierFlags:0
	timestamp:0
	windowNumber:0
	context:nil
	eventNumber:0
	clickCount:1
	pressure:0];
    [NSApp postEvent:motion atStart:NO];
    return TCL_OK;
}

static int
InjectKeyEventObjCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    static const char *const optionStrings[] = {
	"flagschanged", "press", "release", NULL};
    NSUInteger types[3] = {NSFlagsChanged, NSKeyDown, NSKeyUp};
    static const char *const argStrings[] = {
	"-command", "-control", "-function", "-option", "-shift", "-x", "-y", NULL};
    enum args {KEYEVENT_COMMAND, KEYEVENT_CONTROL, KEYEVENT_FUNCTION, KEYEVENT_OPTION,
	       KEYEVENT_SHIFT, KEYEVENT_X, KEYEVENT_Y};
    int i, index, keysym, mods = 0, x = 0, y = 0;
    NSString *chars = nil, *unmod = nil, *upper, *lower;
    NSEvent *keyEvent;
    NSUInteger type;
    MacKeycode macKC;

    if (objc < 3) {
    wrongArgs:
        Tcl_WrongNumArgs(interp, 1, objv, "option keysym ?arg?");
        return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
            sizeof(char *), "option", 0, &index) != TCL_OK) {
        return TCL_ERROR;
    }
    type = types[index];
    if (Tcl_GetIntFromObj(interp, objv[2], &keysym) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			 "keysym must be an integer"));
	Tcl_SetErrorCode(interp, "TK", "TEST", "INJECT", "KEYSYM", NULL);
	return TCL_ERROR;
    }
    macKC.uint = XKeysymToKeycode(NULL, keysym);
    for (i = 3; i < objc; i++) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], argStrings,
                sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
            return TCL_ERROR;
        }
        switch ((enum args) index) {
	case KEYEVENT_SHIFT:
	    mods |= NSShiftKeyMask;
            break;
	case KEYEVENT_CONTROL:
	    mods |= NSControlKeyMask;
            break;
	case KEYEVENT_OPTION:
	    mods |= NSAlternateKeyMask;
            break;
	case KEYEVENT_COMMAND:
	    mods |= NSCommandKeyMask;
            break;
	case KEYEVENT_FUNCTION:
	    mods |= NSFunctionKeyMask;
            break;
	case KEYEVENT_X:
	    if (++i >= objc) {
                goto wrongArgs;
            }
	    if (Tcl_GetIntFromObj(interp,objv[i], &x) != TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	case KEYEVENT_Y:
	    if (++i >= objc) {
                goto wrongArgs;
            }
	    if (Tcl_GetIntFromObj(interp,objv[i], &y) != TCL_OK) {
		return TCL_ERROR;
	    }
	    break;
	}
    }
    if (type != NSFlagsChanged) {
	UniChar keychar = macKC.v.keychar;
	chars = [[NSString alloc] initWithCharacters: &keychar length:1];
	upper = [chars uppercaseString];
	lower = [chars lowercaseString];
	if (![upper isEqual: lower] && [chars isEqual: upper]) {
	    mods |= NSShiftKeyMask;
	}
	if (mods & NSShiftKeyMask) {
	    chars = upper;
	    unmod = lower;
	    macKC.v.o_s |= INDEX_SHIFT;
	} else {
	    unmod = chars;
	}
	if (macKC.v.o_s & INDEX_OPTION) {
	    mods |= NSAlternateKeyMask;
	}
    }
    keyEvent = [NSEvent keyEventWithType:type
	location:NSMakePoint(x, y)
        modifierFlags:mods
	timestamp:GetCurrentEventTime()
	windowNumber:0
	context:nil
	characters:chars
	charactersIgnoringModifiers:unmod
	isARepeat:NO
	keyCode:macKC.v.virt];
    [NSApp postEvent:keyEvent atStart:NO];
    return TCL_OK;
}
/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXWindowEvent.c.

1
2
3
4
5
6
7
8
9
10




11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36

37
38
39


40
41

42
43
44



45

46


47
48
49
50
51
52
53

54


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88

89
90
91





92
93
94
95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
110
111
112

113
114
115



116
117

118
119
120



121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138





139
140
141


142
143
144
145
146




147
148

149
150
151

152
153
154
155
156

157
158
159
160
161
162

163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212

213
214
215
216
217
218
219

220
221
222
223
224
225
226







227
228
229


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278























279
280
281
282
283

284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307

308
309
310
311
312
313
314


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

381
382

383
384
385
386
387
388
389

390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510



511
512
513
514
515
516
517

518
519
520
521
522
523

524
525
526
527
528
529

530
531
532
533
534


535


536
537

538
539








540




541
542
543
544
545
546
547


548
549
550
551

552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567

568
569
570
571
572
573
574
575

576
577

578
579
580
581
582
583
584
585
586


















































587
588
589
590
591
592
593
594
595
596
597
598
599
600

601
602
603
604
605

606
607
608
609
610
611
612
1
2
3
4
5
6




7
8
9
10
11
12
13
14
15
16
17

18
19

20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42

43
44


45
46
47
48
49

50
51
52
53
54
55
56
57

58
59
60
61
62
63










64












65

66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103



104
105
106
107

108



109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124





125
126
127
128
129
130


131
132
133




134
135
136
137
138

139



140





141






142


143



































144
145
146
147
148

149
150
151
152
153
154


155
156
157
158
159
160
161

162
163
164
165
166



167
168
169
170
171
172
173
174


175
176
177
178
179







































180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217

218
219
220

221
222
223
224
225
226
227
228

229
230
231
232
233
234
235

236

237
238




239
240




241
242
243

244
245
246










247
248
249
250
251
252


253

254
255
256

























257
258
259
260


261

262
263

264







265





266




















267
268
269

270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286
287


288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303




















































304
305



306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337
338
339

340
341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359


360
361
362
363
364

365
366
367

368
369
370
371
372
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388

389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

464
465
466
467
468

469
470
471
472
473
474
475
476






-
-
-
-
+
+
+
+







-
+

-












-
+



+



+
+

-
+

-
-
+
+
+

+
-
+
+






-
+

+
+


-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-

-
+






-
+



+
+
+
+
+









-
-
+
+










+
-
-
-
+
+
+

-
+
-
-
-
+
+
+





-
+







-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+

-
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+





-
-
+






-
+




-
-
-
+
+
+
+
+
+
+

-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+




-
+


-








-






+
-
+
-


-
-
-
-
+
+
-
-
-
-



-



-
-
-
-
-
-
-
-
-
-






-
-

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-

-
+

-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+






-
+










-
-

-
+














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
+
+
+






-
+






+






+





+
+
-
+
+

-
+


+
+
+
+
+
+
+
+
-
+
+
+
+





-
-
+
+



-
+


-
+












-
+







-
+

-
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+




-
+







/*
 * tkMacOSXWindowEvent.c --
 *
 *	This file defines the routines for both creating and handling Window
 *	Manager class events for Tk.
 *
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2015 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2015 Marc Culler.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2015 Kevin Walzer/WordTech Communications LLC.
 * Copyright (c) 2015 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXConstants.h"

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_EVENTS
#define TK_MAC_DEBUG_DRAWING
#endif
*/

/*
 * Declaration of functions used only in this file
 */

static int		GenerateUpdates(
static int		GenerateUpdates(HIShapeRef updateRgn,
			    CGRect *updateBounds, TkWindow *winPtr);
static int		GenerateActivateEvents(TkWindow *winPtr,
			    int activeFlag);
static void		DoWindowActivate(ClientData clientData);

#pragma mark TKApplication(TKWindowEvent)

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
extern NSString *NSWindowWillOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOnScreenNotification;
extern NSString *NSWindowWillOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOffScreenNotification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
extern NSString *NSWindowDidOrderOffScreenNotification;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#define NSWindowWillStartLiveResizeNotification @"NSWindowWillStartLiveResizeNotification"
#define NSWindowDidEndLiveResizeNotification  @"NSWindowDidEndLiveResizeNotification"
#endif
#endif


extern BOOL opaqueTag;

@implementation TKApplication(TKWindowEvent)

- (void) windowActivation: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    BOOL activate = [[notification name]
	    isEqualToString:NSWindowDidBecomeKeyNotification];
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    NSString *name = [notification name];
    Bool flag = [name isEqualToString:NSWindowDidBecomeKeyNotification];
    if (winPtr && flag) {
	NSPoint location = [NSEvent mouseLocation];
	int x = location.x;
	int y = floor(TkMacOSXZeroScreenHeight() - location.y);
	/*
	 * The Tk event target persists when there is no key window but
	 * gets reset when a new window becomes the key window.
	 */

	[NSApp setTkEventTarget: winPtr];

	/*
	 * Call Tk_UpdatePointer if the pointer is in the window.
	 */

	NSView *view = [w contentView];
	NSPoint viewLocation = [view convertPoint:location fromView:nil];
	if (NSPointInRect(viewLocation, NSInsetRect([view bounds], 2, 2))) {
	    Tk_UpdatePointer((Tk_Window) winPtr, x, y, [NSApp tkButtonState]);
	}
    }
    if (winPtr && Tk_IsMapped(winPtr)) {
	GenerateActivateEvents(winPtr, flag);
	GenerateActivateEvents(winPtr, activate);
    }
}

- (void) windowBoundsChanged: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    BOOL movedOnly = [[notification name]
	    isEqualToString:NSWindowDidMoveNotification];

    if (movedOnly) {
	/* constraining to screen after move not needed with AppKit */
    }

    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	WmInfo *wmPtr = winPtr->wmInfoPtr;
	NSRect bounds = [w frame];
	int x, y, width = -1, height = -1, flags = 0;

	x = bounds.origin.x;
	y = TkMacOSXZeroScreenHeight() - (bounds.origin.y + bounds.size.height);
	if (winPtr->changes.x != x || winPtr->changes.y != y) {
	y = tkMacOSXZeroScreenHeight - (bounds.origin.y + bounds.size.height);
	if (winPtr->changes.x != x || winPtr->changes.y != y){
	    flags |= TK_LOCATION_CHANGED;
	} else {
	    x = y = -1;
	}
	if (!movedOnly && (winPtr->changes.width != bounds.size.width ||
		winPtr->changes.height !=  bounds.size.height)) {
	    width = bounds.size.width - wmPtr->xInParent;
	    height = bounds.size.height - wmPtr->yInParent;
	    flags |= TK_SIZE_CHANGED;
	}
	if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	/*
	 * Propagate geometry changes immediately.
	 */
	    /*
	     * Propagate geometry changes immediately.
	     */

	flags |= TK_MACOSX_HANDLE_EVENT_IMMEDIATELY;
	    flags |= TK_MACOSX_HANDLE_EVENT_IMMEDIATELY;
	TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width, height, flags);
    }

	}
	TkGenWMConfigureEvent((Tk_Window) winPtr, x, y, width, height, flags);
    }
}

- (void) windowExpanded: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	winPtr->wmInfoPtr->hints.initial_state =
		TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : NormalState;
	Tk_MapWindow((Tk_Window)winPtr);

	/*
	 * Process all Tk events generated by Tk_MapWindow().
	 */
	Tk_MapWindow((Tk_Window) winPtr);
	if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	    /*
	     * Process all Tk events generated by Tk_MapWindow().
	     */

	while (Tcl_ServiceEvent(0)) {}
	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}
	    while (Tcl_ServiceEvent(0)) {}
	    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT)) {}

	/*
	 * NSWindowDidDeminiaturizeNotification is received after
	 * NSWindowDidBecomeKeyNotification, so activate manually
	 */
	    /*
	     * NSWindowDidDeminiaturizeNotification is received after
	     * NSWindowDidBecomeKeyNotification, so activate manually
	     */

	GenerateActivateEvents(winPtr, 1);
	    GenerateActivateEvents(winPtr, 1);
    }
}

	} else {
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window
                        defaultFrame:(NSRect)newFrame
{
    (void)window;

	    Tcl_DoWhenIdle(DoWindowActivate, winPtr);
    /*
     * This method needs to be implemented in order for [NSWindow isZoomed] to
     * give the correct answer. But it suffices to always validate every
     * request.
     */

	}
    return newFrame;
}
    }

- (NSSize)window:(NSWindow *)window
  willUseFullScreenContentSize:(NSSize)proposedSize
{
    (void)window;

    /*
     * We don't need to change the proposed size, but we do need to implement
     * this method.  Otherwise the full screen window will be sized to the
     * screen's visibleFrame, leaving black bands at the top and bottom.
     */

    return proposedSize;
}

- (void) windowEnteredFullScreen: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif
    if (![[notification object] respondsToSelector: @selector (tkLayoutChanged)]) {
	return;
    }
    [(TKWindow *)[notification object] tkLayoutChanged];
}

- (void) windowExitedFullScreen: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
#endif
    if (![[notification object] respondsToSelector: @selector (tkLayoutChanged)]) {
	return;
    }
    [(TKWindow *)[notification object] tkLayoutChanged];
}

- (void) windowCollapsed: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	winPtr->wmInfoPtr->hints.initial_state = IconicState;
	Tk_UnmapWindow((Tk_Window)winPtr);
	Tk_UnmapWindow((Tk_Window) winPtr);
    }
}

- (BOOL) windowShouldClose: (NSWindow *) w
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), w);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, w);
#endif
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	TkGenWMDestroyEvent((Tk_Window)winPtr);
    }

	TkGenWMDestroyEvent((Tk_Window) winPtr);
	if (_windowWithMouse == w) {
	    _windowWithMouse = nil;
	    [w release];
	}
    }

    /*
     * If necessary, TkGenWMDestroyEvent() handles [close]ing the window, so
     * can always return NO from -windowShouldClose: for a Tk window.
     * If necessary, TkGenWMDestroyEvent() handles [close]ing the window,
     * so can always return NO from -windowShouldClose: for a Tk window.
     */

    return (winPtr ? NO : YES);
}

- (void) windowBecameVisible: (NSNotification *) notification
{
    NSWindow *window = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(window);
    if (winPtr) {
	TKContentView *view = [window contentView];

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	if (@available(macOS 10.14, *)) {
	    [view viewDidChangeEffectiveAppearance];
	}
#endif
	[view addTkDirtyRect:[view bounds]];
	Tcl_CancelIdleCall(TkMacOSXDrawAllViews, NULL);
	Tcl_DoWhenIdle(TkMacOSXDrawAllViews, NULL);
    }
}

- (void) windowMapped: (NSNotification *) notification
{
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}
    }
}

- (void) windowLiveResize: (NSNotification *) notification
{
    NSString *name = [notification name];
    if ([name isEqualToString:NSWindowWillStartLiveResizeNotification]) {
	// printf("Starting live resize.\n");
    } else if ([name isEqualToString:NSWindowDidEndLiveResizeNotification]) {
	[self setTkLiveResizeEnded:YES];
	// printf("Ending live resize\n");
    }
}

#ifdef TK_MAC_DEBUG_NOTIFICATIONS

- (void) windowDragStart: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
}

- (void) windowLiveResize: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
    //BOOL start = [[notification name] isEqualToString:NSWindowWillStartLiveResizeNotification];
}

- (void) windowMapped: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	//Tk_MapWindow((Tk_Window) winPtr);
    }
}

- (void) windowBecameVisible: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
}

- (void) windowUnmapped: (NSNotification *) notification
{
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	//Tk_UnmapWindow((Tk_Window)winPtr);
	//Tk_UnmapWindow((Tk_Window) winPtr);
    }
}

#endif /* TK_MAC_DEBUG_NOTIFICATIONS */

- (void) _setupWindowNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

#define observe(n, s) \
	[nc addObserver:self selector:@selector(s) name:(n) object:nil]

    observe(NSWindowDidBecomeKeyNotification, windowActivation:);
    observe(NSWindowDidResignKeyNotification, windowActivation:);
    observe(NSWindowDidMoveNotification, windowBoundsChanged:);
    observe(NSWindowDidResizeNotification, windowBoundsChanged:);
    observe(NSWindowDidDeminiaturizeNotification, windowExpanded:);
    observe(NSWindowDidMiniaturizeNotification, windowCollapsed:);
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    observe(NSWindowWillOrderOnScreenNotification, windowMapped:);
    observe(NSWindowWillMoveNotification, windowDragStart:);
    observe(NSWindowDidOrderOnScreenNotification, windowBecameVisible:);
    observe(NSWindowWillStartLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEndLiveResizeNotification, windowLiveResize:);

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
    observe(NSWindowDidEnterFullScreenNotification, windowEnteredFullScreen:);
    observe(NSWindowDidExitFullScreenNotification, windowExitedFullScreen:);
    observe(NSWindowWillOrderOnScreenNotification, windowMapped:);
    observe(NSWindowDidOrderOnScreenNotification, windowBecameVisible:);
#endif

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    observe(NSWindowWillMoveNotification, windowDragStart:);
    observe(NSWindowDidOrderOffScreenNotification, windowUnmapped:);
#endif
#undef observe

}
@end


/*
 * Idle task which forces focus to a particular window.
 */

static void RefocusGrabWindow(void *data) {
    TkWindow *winPtr = (TkWindow *) data;
    TkpChangeFocus(winPtr, 1);
}

#pragma mark TKApplication(TKApplicationEvent)

@implementation TKApplication(TKApplicationEvent)

- (void) applicationActivate: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    [NSApp tkCheckPasteboard];

    /*
     * When the application is activated with Command-Tab it will create a
     * zombie window for every Tk window which has been withdrawn.  So iterate
     * through the list of windows and order out any withdrawn window.
     * If one of the windows is the grab window for its display we focus
     * it.  This is done as at idle, in case the app was reactivated by
     * clicking a different window.  In that case we need to wait until the
     * mouse event has been processed before focusing the grab window.
     */

    for (NSWindow *win in [NSApp windows]) {
	TkWindow *winPtr = TkMacOSXGetTkWindow(win);
	if (!winPtr || !winPtr->wmInfoPtr) {
	    continue;
	}
	if (winPtr->wmInfoPtr->hints.initial_state == WithdrawnState) {
	    [win orderOut:NSApp];
	}
	if (winPtr->dispPtr->grabWinPtr == winPtr) {
	    Tcl_DoWhenIdle(RefocusGrabWindow, winPtr);
	} else {
	    [[self keyWindow] orderFront: self];
	}
    }
}

- (void) applicationDeactivate: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif

    TkSuspendClipboard();
    /*
     * To prevent zombie windows on systems with a TouchBar, set the key window
     * to nil if the current key window is not visible.  This allows a closed
     * Help or About window to be deallocated so it will not reappear as a
     * zombie when the app is reactivated.
     */

}
    NSWindow *keywindow = [NSApp keyWindow];
    if (keywindow && ![keywindow isVisible]) {
	[NSApp _setKeyWindow:nil];
	[NSApp _setMainWindow:nil];
    }


}

- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender
                    hasVisibleWindows:(BOOL)flag
{
    (void)sender;
    (void)flag;

    /*
     * Allowing the default response means that withdrawn windows will get
     * displayed on the screen with unresponsive title buttons.  We don't
     * really want that.  Besides, we can write our own code to handle this
     * with ::tk::mac::ReopenApplication.  So we just say NO.
     */

    return NO;
}


- (void) applicationShowHide: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    const char *cmd = ([[notification name] isEqualToString:
	    NSApplicationDidUnhideNotification] ?
	    "::tk::mac::OnShow" : "::tk::mac::OnHide");

    if (_eventInterp && Tcl_FindCommand(_eventInterp, cmd, NULL, 0)) {
	int code = Tcl_EvalEx(_eventInterp, cmd, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	int code = Tcl_EvalEx(_eventInterp, cmd, -1, TCL_EVAL_GLOBAL);

	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
	Tcl_ResetResult(_eventInterp);
    }
}

- (void) displayChanged: (NSNotification *) notification
{
    (void)notification;

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), notification);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
#endif
    TkDisplay *dispPtr = TkGetDisplayList();

    if (dispPtr) {
	TkMacOSXDisplayChanged(dispPtr->display);
    }
}
@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkpWillDrawWidget --
 *
 *      A widget display procedure can call this to determine whether it is
 *      being run inside of the drawRect method. If not, it may be desirable
 *      for the display procedure to simply clear the REDRAW_PENDING flag
 *      and return.  The widget can be recorded in order to schedule a
 *      redraw, via an Expose event, from within drawRect.
 *
 *      This is also needed for some tests, especially of the Text widget,
 *      which record data in a global Tcl variable and assume that display
 *      procedures will be run in a predictable sequence as Tcl idle tasks.
 *
 * Results:
 *      True if called from the drawRect method of a TKContentView with
 *      tkwin NULL or pointing to a widget in the current focusView.
 *
 * Side effects:
 *	Currently none.  One day the tkwin parameter may be recorded to
 *      handle redrawing the widget later.
 *
 *----------------------------------------------------------------------
 */

int
TkpWillDrawWidget(Tk_Window tkwin) {
    int result;
    if (tkwin) {
	TkWindow *winPtr = (TkWindow *)tkwin;
	TKContentView *view = (TKContentView *)TkMacOSXGetNSViewForDrawable(
	    (Drawable)winPtr->privatePtr);
	result = ([NSApp isDrawing] && view == [NSView focusView]);
#if 0
	printf("TkpWillDrawWidget: %s %d  %d \n", Tk_PathName(tkwin),
	       [NSApp isDrawing], (view == [NSView focusView]));
	if (!result) {
	    NSRect dirtyRect;
	    TkMacOSXWinNSBounds(winPtr, view, &dirtyRect);
	    printf("TkpAppCanDraw: dirtyRect for %s is %s\n",
		   Tk_PathName(tkwin),
		   NSStringFromRect(dirtyRect).UTF8String);
	    [view addTkDirtyRect:dirtyRect];
	}
#endif
    } else {
	result = [NSApp isDrawing];
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateUpdates --
 *
 *	Given an update rectangle and a Tk window, this function generates
 *	an X Expose event for the window if it meets the update region. The
 *	function will then recursively have each damaged window generate Expose
 *	Given a Macintosh update region and a Tk window this function geneates
 *	a X Expose event for the window if it is within the update region. The
 *	function will then recursivly have each damaged window generate Expose
 *	events for its child windows.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue.
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateUpdates(
    HIShapeRef updateRgn,
    CGRect *updateBounds,
    TkWindow *winPtr)
{
    TkWindow *childPtr;
    XEvent event;
    CGRect bounds, damageBounds;
    HIShapeRef boundsRgn, damageRgn;

    TkMacOSXWinCGBounds(winPtr, &bounds);
    if (!CGRectIntersectsRect(bounds, *updateBounds)) {
	return 0;
    }
    if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	return 0;

    }

    /*
     * Compute the bounding box of the area that the damage occurred in.
     * Compute the bounding box of the area that the damage occured in.
     */

    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);
	return 0;
    }
    HIShapeGetBounds(damageRgn, &damageBounds);
    damageBounds = CGRectIntersection(bounds, *updateBounds);

    CFRelease(damageRgn);
    CFRelease(boundsRgn);

    event.xany.serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    event.xany.send_event = false;
    event.xany.window = Tk_WindowId(winPtr);
    event.xany.display = Tk_Display(winPtr);
    event.type = Expose;
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.x = damageBounds.origin.x;
    event.xexpose.y = damageBounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
    event.xexpose.count = 0;
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    Tk_HandleEvent(&event);

#ifdef TK_MAC_DEBUG_DRAWING
    TKLog(@"Exposed %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x,
    NSLog(@"Expose %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x,
	event.xexpose.y, event.xexpose.width, event.xexpose.height);
#endif

    /*
     * Generate updates for the children of this window
     */

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {
	if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
	    continue;
	}
	GenerateUpdates(updateBounds, childPtr);
	GenerateUpdates(updateRgn, updateBounds, childPtr);
    }

    /*
     * Generate updates for any contained windows
     */

    if (Tk_IsContainer(winPtr)) {
	childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	childPtr = TkpGetOtherWindow(winPtr);
	if (childPtr != NULL && Tk_IsMapped(childPtr)) {
	    GenerateUpdates(updateBounds, childPtr);
	    GenerateUpdates(updateRgn, updateBounds, childPtr);
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateActivateEvents --
 *
 *	Given a Macintosh window activate event this function generates all the
 *	X Activate events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
GenerateActivateEvents(
    TkWindow *winPtr,
    int activeFlag)
{
    TkGenerateActivateEvents(winPtr, activeFlag);
    TkMacOSXGenerateFocusEvent(winPtr, activeFlag);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * DoWindowActivate --
 *
 *	Idle handler that calls GenerateActivateEvents().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

void
DoWindowActivate(
    ClientData clientData)
{
    GenerateActivateEvents(clientData, 1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGenerateFocusEvent --
 *
 *	Given a Macintosh window activate event this function generates all
 *	the X Focus events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue.
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

static int
MODULE_SCOPE int
TkMacOSXGenerateFocusEvent(
    TkWindow *winPtr,		/* Root X window for event. */
    int activeFlag)
{
    XEvent event;

    /*
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
501
502
503
504
505
506
507





























508
509
510
511
512
513
514







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    event.xfocus.mode = NotifyNormal;
    event.xfocus.detail = NotifyDetailNone;

    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateActivateEvents --
 *
 *	Given a Macintosh window activate event this function generates all the
 *	X Activate events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be placed on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
GenerateActivateEvents(
    TkWindow *winPtr,
    int activeFlag)
{
    TkGenerateActivateEvents(winPtr, activeFlag);
    if (activeFlag || ![NSApp isActive]) {
	TkMacOSXGenerateFocusEvent(winPtr, activeFlag);
    }
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenWMConfigureEvent --
 *
 *	Generate a ConfigureNotify event for Tk. Depending on the value of flag
 *	the values of width/height, x/y, or both may be changed.
740
741
742
743
744
745
746

747
748
749
750
751
752
753
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589







+







     */

    if (Tk_IsTopLevel(winPtr)) {
	wmPtr = winPtr->wmInfoPtr;
	if (flags & TK_LOCATION_CHANGED) {
	    wmPtr->x = x;
	    wmPtr->y = y;
	    wmPtr->flags &= ~(WM_NEGATIVE_X | WM_NEGATIVE_Y);
	}
	if ((flags & TK_SIZE_CHANGED) && !(wmPtr->flags & WM_SYNC_PENDING) &&
		((width != Tk_Width(tkwin)) || (height != Tk_Height(tkwin)))) {
	    if ((wmPtr->width == -1) && (width == winPtr->reqWidth)) {
		/*
		 * Don't set external width, since the user didn't change it
		 * from what the widgets asked for.
780
781
782
783
784
785
786
787

788
789
790
791
792
793
794
616
617
618
619
620
621
622

623
624
625
626
627
628
629
630







-
+







	    wmPtr->configWidth = width;
	    wmPtr->configHeight = height;
	}
    }

    /*
     * Now set up the changes structure. Under X we wait for the
     * ConfigureNotify to set these values. On the Mac we know immediately that
     * ConfigureNotify to set these values. On the Mac we know imediatly that
     * this is what we want - so we just set them. However, we need to make
     * sure the windows clipping region is marked invalid so the change is
     * visible to the subwindow.
     */

    winPtr->changes.x = x;
    winPtr->changes.y = y;
867
868
869
870
871
872
873
874

875
876
877
878

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893


894
895
896
897
898
899
900
703
704
705
706
707
708
709

710
711
712
713

714
715
716
717
718
719
720
721
722
723
724
725
726
727


728
729
730
731
732
733
734
735
736







-
+



-
+













-
-
+
+







    protocol = (Atom) eventPtr->xclient.data.l[0];
    for (protPtr = wmPtr->protPtr; protPtr != NULL;
	    protPtr = protPtr->nextPtr) {
	if (protocol == protPtr->protocol) {
	    Tcl_Preserve(protPtr);
	    interp = protPtr->interp;
	    Tcl_Preserve(interp);
	    result = Tcl_EvalEx(interp, protPtr->command, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(interp, protPtr->command, -1, TCL_EVAL_GLOBAL);
	    if (result != TCL_OK) {
		Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
			"\n    (command for \"%s\" window manager protocol)",
			Tk_GetAtomName((Tk_Window)winPtr, protocol)));
			Tk_GetAtomName((Tk_Window) winPtr, protocol)));
		Tcl_BackgroundException(interp, result);
	    }
	    Tcl_Release(interp);
	    Tcl_Release(protPtr);
	    return;
	}
    }

    /*
     * No handler was present for this protocol. If this is a WM_DELETE_WINDOW
     * message then just destroy the window.
     */

    if (protocol == Tk_InternAtom((Tk_Window)winPtr, "WM_DELETE_WINDOW")) {
	Tk_DestroyWindow((Tk_Window)winPtr);
    if (protocol == Tk_InternAtom((Tk_Window) winPtr, "WM_DELETE_WINDOW")) {
	Tk_DestroyWindow((Tk_Window) winPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXIsAppInFront --
909
910
911
912
913
914
915








916



917
918
919
920
921
922
923
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

760
761
762
763
764
765
766
767
768
769







+
+
+
+
+
+
+
+
-
+
+
+







 *
 *----------------------------------------------------------------------
 */

int
Tk_MacOSXIsAppInFront(void)
{
    Boolean isFrontProcess = true;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};

    if (noErr == GetFrontProcess(&frontPsn)){
	SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
    }
#else
    return ([NSRunningApplication currentApplication].active == true);
    isFrontProcess = [NSRunningApplication currentApplication].active;
#endif
    return (isFrontProcess == true);
}

#pragma mark TKContentView

#import <ApplicationServices/ApplicationServices.h>

/*
935
936
937
938
939
940
941
942
943

944
945
946
947
948

949
950
951
952
953
954
955
956

957
958
959
960
961

962
963
964
965
966
967
968
969

970
971
972
973
974
975
976

977
978
979
980
981
982

983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999

1000
1001
1002

1003
1004
1005
1006

1007
1008
1009



1010
1011

1012
1013
1014
1015


1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027


1028
1029
1030
1031
1032
1033
1034
1035
1036


1037
1038
1039
1040
1041
1042


1043
1044
1045
1046

1047
1048
1049
1050
1051
1052

1053
1054

1055
1056
1057
1058
1059
1060


1061
1062
1063
1064



1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098



1099
1100

1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143







1144
1145
1146
1147
1148



1149
1150
1151
1152
1153





1154
1155
1156

1157
1158
1159

1160
1161
1162


1163
1164
1165








1166
1167

1168
1169
1170
1171
1172
1173

1174
1175
1176

1177
1178
1179




1180
1181
1182
1183
1184







1185
1186
1187
1188
1189
1190
1191
1192

1193
1194


1195
1196
1197





1198
1199
1200
1201






1202
1203
1204
1205
1206
1207
1208




1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224

1225
1226
1227
1228
1229
1230







1231
1232
1233
1234
1235
1236






1237
1238

1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275


1276
1277
1278
1279
1280
1281

1282





1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300








1301
1302
1303
1304
1305
1306





1307
1308



1309

1310
1311
1312








1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
781
782
783
784
785
786
787


788


789
790

791
792
793
794
795
796
797


798


799
800

801
802
803
804
805
806
807
808

809
810






811






812




813



814









815



816




817



818
819
820


821




822
823






824
825





826
827









828
829






830
831




832






833


834






835
836




837
838
839
840
841





842



843
844
845
846
847
848



849
850
851







852
853

854
855
856




857
858
859
860

861

862
863



864































865





866
867
868
869
870
871
872





873
874
875





876
877
878
879
880



881



882



883
884



885
886
887
888
889
890
891
892


893






894

895

896



897
898
899
900
901




902
903
904
905
906
907
908








909


910
911



912
913
914
915
916




917
918
919
920
921
922







923
924
925
926


927


928






929





930






931
932
933
934
935
936
937






938
939
940
941
942
943


944
945



946












947


















948


949
950
951

952
953
954

955
956
957
958
959
960
961


















962
963
964
965
966
967
968
969
970





971
972
973
974
975
976
977
978
979
980

981



982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000





1001
1002


1003

1004
1005
1006
1007

















1008
1009
1010
1011
1012
1013
1014
1015
1016
1017







-
-
+
-
-


-
+






-
-
+
-
-


-
+







-
+

-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-

-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
-
+

-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+


-
-
-
-
-
+
-
-
-





+
-
-
-
+
+
+
-
-
-
-
-
-
-


-
+


-
-
-
-
+
+
+

-
+
-


-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
-
+
-
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
-

-
+
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
-
-

-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+

-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+

-



-
+

+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+


+
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+











-
-
-
-
-


-
-

-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










 * Widgets it was necessary to use Apple private API calls.  In order to avoid
 * using private API calls, the NSView-based widgets have been replaced with
 * normal Tk widgets which draw themselves as native widgets by using the
 * HITheme API.
 *
 */

/*
 * Restrict event processing to Expose events.
/*Restrict event processing to Expose events.*/
 */

static Tk_RestrictAction
ExposeRestrictProc(
    void *arg,
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==Expose && eventPtr->xany.serial==PTR2UINT(arg)
	    ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

/*
 * Restrict event processing to ConfigureNotify events.
/*Restrict event processing to ConfigureNotify events.*/
 */

static Tk_RestrictAction
ConfigureRestrictProc(
    TCL_UNUSED(void *),
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==ConfigureNotify ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

@implementation TKContentView(TKWindowEvent)

- (id)initWithFrame:(NSRect)frame
- (void) drawRect: (NSRect) rect
{
    self = [super initWithFrame:frame];
    if (self) {
	/*
	 * The layer must exist before we set wantsLayer to YES.
	 */

    const NSRect *rectsBeingDrawn;
	self.layer = [CALayer layer];
	self.wantsLayer = YES;
	self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
	self.layer.contentsGravity = self.layer.contentsAreFlipped ?
	    kCAGravityTopLeft : kCAGravityBottomLeft;

    NSInteger rectsBeingDrawnCount;
	/*
	 * Nothing gets drawn at all if the layer does not have a delegate.
	 * Currently, we do not implement any methods of the delegate, however.
	 */

	self.layer.delegate = (id) self;
	trackingArea = [[NSTrackingArea alloc]
			   initWithRect:[self bounds]
    [self getRectsBeingDrawn:&rectsBeingDrawn count:&rectsBeingDrawnCount];
				options:(NSTrackingMouseEnteredAndExited |
					 NSTrackingMouseMoved |
					 NSTrackingEnabledDuringMouseDrag |
					 NSTrackingInVisibleRect |
					 NSTrackingActiveAlways)
				  owner:self
			       userInfo:nil];
        [self addTrackingArea:trackingArea];
    }

    return self;
}

#ifdef TK_MAC_DEBUG_DRAWING
/*
 * We will just use drawRect.
 */

    TKLog(@"-[%@(%p) %s%@]", [self class], self, _cmd, NSStringFromRect(rect));
- (BOOL) wantsUpdateLayer
{
    return NO;
    [[NSColor colorWithDeviceRed:0.0 green:1.0 blue:0.0 alpha:.1] setFill];
    NSRectFillListUsingOperation(rectsBeingDrawn, rectsBeingDrawnCount,
	    NSCompositeSourceOver);
}

#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- (void) viewDidChangeBackingProperties
{


    CGFloat height = [self bounds].size.height;
    /*
     * Make sure that the layer uses a contentScale that matches the
     * backing scale factor of the screen.  This avoids blurry text when
     * the view is on a Retina display, as well as incorrect size when
     * the view is on a normal display.
     */
    HIMutableShapeRef drawShape = HIShapeCreateMutable();

    self.layer.contentsScale = self.window.screen.backingScaleFactor;
}
#endif

- (void) addTkDirtyRect: (NSRect) rect
    while (rectsBeingDrawnCount--) {
	CGRect r = NSRectToCGRect(*rectsBeingDrawn++);
{
    _tkNeedsDisplay = YES;
    _tkDirtyRect = NSUnionRect(_tkDirtyRect, rect);
    [NSApp setNeedsToDraw:YES];
    [self setNeedsDisplay:YES];
    [[self layer] setNeedsDisplay];
}

- (void) clearTkDirtyRect
	r.origin.y = height - (r.origin.y + r.size.height);
	HIShapeUnionWithRect(drawShape, &r);
{
    _tkNeedsDisplay = NO;
    _tkDirtyRect = NSZeroRect;
    [NSApp setNeedsToDraw:NO];
}

    }
    if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) {
- (void) drawRect: (NSRect) rect
{
    (void)rect;

	[self generateExposeEvents:(HIShapeRef)drawShape];
#ifdef TK_MAC_DEBUG_DRAWING
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    if (winPtr) {
	fprintf(stderr, "drawRect: drawing %s in %s\n",
	    Tk_PathName(winPtr), NSStringFromRect(rect).UTF8String);
    }
    } else {
#endif

	[self performSelectorOnMainThread:@selector(generateExposeEvents:)
    /*
     * We do not allow recursive calls to drawRect, but we only log them on OSX
     * > 10.13, where they should never happen.
     */

    if ([NSApp isDrawing]) {
		withObject:(id)drawShape waitUntilDone:NO
		modes:[NSArray arrayWithObjects:NSRunLoopCommonModes,
	if ([NSApp macOSVersion] > 101300) {
	    TKLog(@"WARNING: a recursive call to drawRect was aborted.");
	}
	return;

			NSEventTrackingRunLoopMode, NSModalPanelRunLoopMode,
			nil]];
    }

    [NSApp setIsDrawing: YES];
    [self clearTkDirtyRect];
    [self generateExposeEvents:rect];
    [NSApp setIsDrawing:NO];

    CFRelease(drawShape);
#ifdef TK_MAC_DEBUG_DRAWING
    fprintf(stderr, "drawRect: done.\n");
#endif
}

-(void) setFrameSize: (NSSize)newsize
{
    [super setFrameSize: newsize];
    if ([self inLiveResize]) {
    NSWindow *w = [self window];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    Tk_Window tkwin = (Tk_Window)winPtr;
	NSWindow *w = [self window];
	TkWindow *winPtr = TkMacOSXGetTkWindow(w);
	Tk_Window tkwin = (Tk_Window) winPtr;

    if (![self inLiveResize] &&
	[w respondsToSelector: @selector (tkLayoutChanged)]) {
	[(TKWindow *)w tkLayoutChanged];
    }

    if (winPtr) {
	unsigned int width = (unsigned int)newsize.width;
	unsigned int height=(unsigned int)newsize.height;
	void *oldArg;
	ClientData oldArg;
    	Tk_RestrictProc *oldProc;

	/*
	 * This can be called from outside the Tk event loop.  Since it calls
	 * Tcl_DoOneEvent, we need to make sure we don't clobber the
	 * AutoreleasePool set up by the caller.
	/* This can be called from outside the Tk event loop.
	 * Since it calls Tcl_DoOneEvent, we need to make sure we
	 * don't clobber the AutoreleasePool set up by the caller.
	 */

	[NSApp setPoolProtected:YES];
	[NSApp _lockAutoreleasePool];

	/*
	 * Disable Tk drawing until the window has been completely configured.
	 */

	 * Try to prevent flickers and flashes.
	TkMacOSXSetDrawingEnabled(winPtr, 0);

	 /*
	  * Generate and handle a ConfigureNotify event for the new size.
	  */

	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
		TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
    	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);

	/*
	 * Now that Tk has configured all subwindows, create the clip regions.
	 */

	TkMacOSXSetDrawingEnabled(winPtr, 1);
	TkMacOSXInvalClipRgns(tkwin);
	TkMacOSXUpdateClipRgn(winPtr);

	 /*
	  * Generate and process expose events to redraw the window.  To avoid
	  * crashes, only do this if we are being called from drawRect.  See
	  * ticket [1fa8c3ed8d].
	  */

	if([NSApp isDrawing] || [self inLiveResize]) {
	    [self generateExposeEvents: [self bounds]];
	}

	/*
	 * Finally, unlock the main autoreleasePool.
	 */

	[NSApp _unlockAutoreleasePool];
    }
}

	[w disableFlushWindow];
	NSDisableScreenUpdates();

	/* Disable Tk drawing until the window has been completely configured.*/
	TkMacOSXSetDrawingEnabled(winPtr, 0);

	 /* Generate and handle a ConfigureNotify event for the new size.*/
/*
 * Core method of this class: generates expose events for redrawing.  The
 * expose events are immediately removed from the Tcl event loop and processed.
 * This causes drawing procedures to be scheduled as idle events.  Then all
 * pending idle events are processed so the drawing will actually take place.
	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
			      TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
    	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
 */

- (void) generateExposeEvents: (NSRect) rect
{
    unsigned long serial;
	while (Tk_DoOneEvent(TK_X_EVENTS|TK_DONT_WAIT)) {}
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);

	/* Now that Tk has configured all subwindows we can create the clip regions. */
	TkMacOSXSetDrawingEnabled(winPtr, 1);
    int updatesNeeded;
    CGRect updateBounds;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
	TkMacOSXInvalClipRgns(tkwin);
    void *oldArg;
    Tk_RestrictProc *oldProc;
    if (!winPtr) {
	TkMacOSXUpdateClipRgn(winPtr);
	return;
    }


	 /* Finally, generate and process expose events to redraw the window. */
    /*
     * Generate Tk Expose events.  All of these events will share the same
     * serial number.
	HIRect bounds = NSRectToCGRect([self bounds]);
	HIShapeRef shape = HIShapeCreateWithRect(&bounds);
	[self generateExposeEvents: shape];
	while (Tk_DoOneEvent(TK_ALL_EVENTS|TK_DONT_WAIT)) {}
	[w enableFlushWindow];
	[w flushWindowIfNeeded];
	NSEnableScreenUpdates();
	[NSApp setPoolProtected:NO];
     */

    }
    updateBounds = NSRectToCGRect(rect);
    updateBounds.origin.y = ([self bounds].size.height - updateBounds.origin.y
			     - updateBounds.size.height);
    updatesNeeded = GenerateUpdates(&updateBounds, winPtr);
    if (updatesNeeded) {

}
	serial = LastKnownRequestProcessed(Tk_Display(winPtr));

	/*
/*
	 * Use the ExposeRestrictProc to process only the expose events.  This
	 * will create idle drawing tasks, which we handle before we return.
	 */
 * As insurance against bugs that might cause layout glitches during a live
 * resize, we redraw the window one more time at the end of the resize
 * operation.
 */

    	oldProc = Tk_RestrictEvents(ExposeRestrictProc, UINT2PTR(serial), &oldArg);
    	while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {};
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);

- (void)viewDidEndLiveResize
{
    HIRect bounds = NSRectToCGRect([self bounds]);
    HIShapeRef shape = HIShapeCreateWithRect(&bounds);
    [super viewDidEndLiveResize];
    [self generateExposeEvents: shape];
}
	/*
	 * Starting with OSX 10.14, which uses Core Animation to draw windows,
	 * all drawing must be done within the drawRect method.  (The CGContext
	 * which draws to the backing CALayer is created by the NSView before
	 * calling drawRect, and destroyed when drawRect returns.  Drawing done
	 * with the current CGContext outside of the drawRect method has no
	 * effect.)
	 *

	 * Fortunately, Tk schedules all drawing to be done while Tcl is idle.
	 * So to run any display procs which were scheduled by the expose
/* Core method of this class: generates expose events for redrawing.  If the
 * Tcl_ServiceMode is set to TCL_SERVICE_ALL then the expose events will be
	 * events we process all idle events before returning.
	 */

 * immediately removed from the Tcl event loop and processed.  Typically, they
 * should be queued, however.
 */
- (void) generateExposeEvents: (HIShapeRef) shape
{
	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}
    }
}

    [self generateExposeEvents:shape childrenOnly:0];
}

- (void) generateExposeEvents: (HIShapeRef) shape
		 childrenOnly: (int) childrenOnly
{
/*
 * In macOS 10.14 and later this method is called when a user changes between
 * light and dark mode or changes the accent color. The implementation
 * generates two virtual events.  The first is either <<LightAqua>> or
 * <<DarkAqua>>, depending on the view's current effective appearance.  The
 * second is <<AppearnceChanged>> and has a data string describing the
 * effective appearance of the view and the current accent and highlight
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    unsigned long serial;
    CGRect updateBounds;
    int updatesNeeded;
 * colors.
 */

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400

    if (!winPtr) {
static const char *const accentNames[] = {
    "Graphite",
    "Red",
    "Orange",
    "Yellow",
    "Green",
		return;
    "Blue",
    "Purple",
    "Pink"
};

    }
- (void) viewDidChangeEffectiveAppearance
{
    Tk_Window tkwin = (Tk_Window)TkMacOSXGetTkWindow([self window]);
    if (!tkwin) {
	return;
    }

    /* Generate Tk Expose events. */
    HIShapeGetBounds(shape, &updateBounds);
    /* All of these events will share the same serial number. */
    serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    updatesNeeded = GenerateUpdates(shape, &updateBounds, winPtr);

    NSAppearanceName effectiveAppearanceName = [[self effectiveAppearance] name];
    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
    static const char *defaultColor = NULL;

    if (effectiveAppearanceName == NSAppearanceNameAqua) {
	Tk_SendVirtualEvent(tkwin, "LightAqua", NULL);
    /* Process the Expose events if the service mode is TCL_SERVICE_ALL */
    if (updatesNeeded && Tcl_GetServiceMode() == TCL_SERVICE_ALL) {
	ClientData oldArg;
    	Tk_RestrictProc *oldProc = Tk_RestrictEvents(ExposeRestrictProc,
						     UINT2PTR(serial), &oldArg);
    	while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {}
    } else if (effectiveAppearanceName == NSAppearanceNameDarkAqua) {
	Tk_SendVirtualEvent(tkwin, "DarkAqua", NULL);
    	Tk_RestrictEvents(oldProc, oldArg, &oldArg);
    }
    if (!defaultColor) {
	defaultColor = [NSApp macOSVersion] < 110000 ? "Blue" : "Multicolor";
    }
}
    NSString *accent = [preferences stringForKey:@"AppleAccentColor"];
    NSArray *words = [[preferences stringForKey:@"AppleHighlightColor"]
			        componentsSeparatedByString: @" "];
    NSString *highlight = [words count] > 3 ? [words objectAtIndex:3] : nil;
    const char *accentName = accent ? accentNames[1 + accent.intValue] : defaultColor;
    const char *highlightName = highlight ? highlight.UTF8String: defaultColor;
    char data[256];
    snprintf(data, 256, "Appearance %s Accent %s Highlight %s",
	     effectiveAppearanceName.UTF8String, accentName,
	     highlightName);
    Tk_SendVirtualEvent(tkwin, "AppearanceChanged", Tcl_NewStringObj(data, TCL_INDEX_NONE));
}


- (void)observeValueForKeyPath:(NSString *)keyPath
		      ofObject:(id)object
			change:(NSDictionary *)change
		       context:(void *)context
{
    (void) change;
    (void) context;
    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
    if (object == preferences && [keyPath isEqualToString:@"AppleHighlightColor"]) {
	if (@available(macOS 10.14, *)) {
	    [self viewDidChangeEffectiveAppearance];
	}
    }
}

#endif

/*
 * This is no-op on 10.7 and up because Apple has removed this widget, but we
 * are leaving it here for backwards compatibility.
 * This is no-op on 10.7 and up because Apple has removed this widget,
 * but we are leaving it here for backwards compatibility.
 */

- (void) tkToolbarButton: (id) sender
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), sender);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd);
#endif
    XVirtualEvent event;
    int x, y;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    Tk_Window tkwin = (Tk_Window) winPtr;
    bzero(&event, sizeof(XVirtualEvent));
    union {XEvent general; XVirtualEvent virt;} event;
    int x, y;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    Tk_Window tkwin = (Tk_Window)winPtr;
    (void)sender;

    if (!winPtr){
	return;
    }
    bzero(&event, sizeof(event));
    event.virt.type = VirtualEvent;
    event.virt.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.virt.send_event = false;
    event.virt.display = Tk_Display(tkwin);
    event.virt.event = Tk_WindowId(tkwin);
    event.virt.root = XRootWindow(Tk_Display(tkwin), 0);
    event.virt.subwindow = None;
    event.virt.time = TkpGetMS();
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.send_event = false;
    event.display = Tk_Display(tkwin);
    event.event = Tk_WindowId(tkwin);
    event.root = XRootWindow(Tk_Display(tkwin), 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    XQueryPointer(NULL, winPtr->window, NULL, NULL,
	    &event.virt.x_root, &event.virt.y_root, &x, &y, &event.virt.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.virt.x, &event.virt.y);
    event.virt.same_screen = true;
    event.virt.name = Tk_GetUid("ToolbarButton");
    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
	    &event.x_root, &event.y_root, &x, &y, &event.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.x, &event.y);
    event.same_screen = true;
    event.name = Tk_GetUid("ToolbarButton");
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

- (BOOL) isOpaque
{
    NSWindow *w = [self window];
/*

 * On Catalina this is never called and drawRect clips to the rect that
 * is passed to it by AppKit.
 */
    if (opaqueTag) {
      return YES;
	} else {

     return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
    	    ![w isOpaque]) ? NO : YES);
    }
}

- (BOOL) wantsDefaultClipping
{
    return NO;
}

- (BOOL) acceptsFirstResponder
{
    return YES;
}

/*
 * This keyDown method does nothing, which is a huge improvement over the
 * default keyDown method which beeps every time a key is pressed.
 */

- (void) keyDown: (NSEvent *) theEvent
{
    (void)theEvent;

#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, sel_getName(_cmd), theEvent);
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
#endif
}

/*
 * When the services menu is opened this is called for each Responder in
 * the Responder chain until a service provider is found.  The TKContentView
 * should be the first (and generally only) Responder in the chain.  We
 * return the TkServices object that was created in TkpInit.
 */

- (id)validRequestorForSendType:(NSString *)sendType
		     returnType:(NSString *)returnType
{
    if ([sendType isEqualToString:@"NSStringPboardType"] ||
	[sendType isEqualToString:@"NSPasteboardTypeString"]) {
	return [NSApp servicesProvider];
    }
    return [super validRequestorForSendType:sendType returnType:returnType];
}

@end

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXWm.c.

1
2
3
4
5
6


7
8
9
10
11




12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
1
2
3
4
5

6
7
8




9
10
11
12

13
14
15
16
17
18
19
20

21
22







23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40





-
+
+

-
-
-
-
+
+
+
+
-








-
+

-
-
-
-
-
-
-










-
+







/*
 * tkMacOSXWm.c --
 *
 *	This module takes care of the interactions between a Tk-based
 *	application and the window manager. Among other things, it implements
 *	the "wm" command and passes geometry information to the window manager.
 *	the "wm" command and passes geometry information to the window
 *	manager.
 *
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2010 Kevin Walzer/WordTech Communications LLC.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2017-2019 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkMacOSXPrivate.h"
#include "tkScrollbar.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
#include "tkMacOSXConstants.h"

/*
 * Setting this to 1 prints when each window is freed, setting it to 2 adds
 * dumps of the autorelease pools, and setting it to 3 also shows each retain
 * and release.
 */

#define DEBUG_ZOMBIES 0

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_WINDOWS
#endif
*/

/*
 * Carbon window attributes and classes.
 * Window attributes and classes
 */

#define WM_NSMASK_SHIFT 36
#define tkWindowDoesNotHideAttribute \
	((UInt64) 1 << kHIWindowBitDoesNotHide)
#define tkCanJoinAllSpacesAttribute \
	((UInt64) NSWindowCollectionBehaviorCanJoinAllSpaces << 34)
55
56
57
58
59
60
61




62
63
64
65
66
67
68
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65







+
+
+
+







	| kWindowNoActivatesAttribute	    | kWindowHideOnSuspendAttribute \
	| kWindowHideOnFullScreenAttribute  | kWindowNoConstrainAttribute \
	| kWindowNoShadowAttribute	    | kWindowLiveResizeAttribute \
	| kWindowOpaqueForEventsAttribute   | kWindowIgnoreClicksAttribute \
	| kWindowDoesNotCycleAttribute	    | tkWindowDoesNotHideAttribute \
	| tkCanJoinAllSpacesAttribute	    | tkMoveToActiveSpaceAttribute \
	| tkNonactivatingPanelAttribute	    | tkHUDWindowAttribute)

/*Objects for use in setting background color and opacity of window.*/
NSColor *colorName = NULL;
BOOL opaqueTag = FALSE;

static const struct {
    const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs;
    int flags; NSUInteger styleMask;
} macClassAttrs[] = {
    [kAlertWindowClass] = {
	.defaultAttrs = kWindowDoesNotCycleAttribute, },
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
104
105
106
107
108
109
110

111

112
113
114
115
116
117
118







-
+
-







	.forceOffAttrs = kWindowCollapseBoxAttribute,
	.flags = WM_TOPMOST,
	.styleMask = NSUtilityWindowMask, },
    [kHelpWindowClass] = {
	.defaultAttrs = kWindowHideOnSuspendAttribute,
	.forceOnAttrs = kWindowNoTitleBarAttribute |
		kWindowDoesNotCycleAttribute,
	.flags = WM_TOPMOST,
	.flags = WM_TOPMOST, },
        .styleMask = 0},
    [kSheetWindowClass] = {
	.validAttrs = kWindowResizableAttribute,
	.forceOnAttrs = kWindowNoTitleBarAttribute |
		kWindowDoesNotCycleAttribute,
	.styleMask = NSDocModalWindowMask, },
    [kToolbarWindowClass] = {
	.defaultAttrs = kWindowHideOnSuspendAttribute,
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300


301
302

303
304
305
306
307
308



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329

330
331
332
333
334
335
336
337
338


339










340
341






































342
343
344
345
346

347
348
349
350

351
352
353
354

355
356
357

358
359
360

361
362
363

364
365
366

367
368
369

370
371
372

373
374
375

376
377
378

379
380
381

382
383
384

385
386
387

388
389
390
391
392
393

394
395
396

397
398
399

400
401
402

403
404
405

406
407
408

409
410
411

412
413
414

415
416
417

418
419
420

421
422
423

424
425
426

427
428
429

430
431
432

433
434
435

436
437
438

439
440
441

442
443
444

445
446
447

448
449
450

451
452
453
454

455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612



613
614
615
616

617
618
619
620
621
622
623

624
625
626
627
628
629
630
631


632
633
634


635
636
637




638
639
640
641
642
643
644
645
646
647
648
649



650
651
652
653
654
655
656
657
658
659
660
661


662
663
664
665
666
667
668

669
670
671
672
673
674
675


676
677
678
679
680
681
682
683
684
685
686
687


688
689
690
691
692
693
694
695
696
697
698
699


700
701
702
703

704
705
706
707
708
709
710
143
144
145
146
147
148
149



150




















































151

















152







































































153


154
155


156
157
158
159



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252

253
254
255
256

257
258
259

260
261
262

263
264
265

266
267
268

269
270
271

272
273
274

275
276
277

278
279
280

281
282
283

284
285
286

287
288
289

290
291



292

293
294
295

296
297
298

299
300
301

302
303
304

305
306
307

308
309
310

311
312
313

314
315
316

317
318
319

320
321
322

323
324
325

326
327
328

329
330
331

332
333
334

335
336
337

338
339
340

341
342
343

344
345
346

347
348
349

350
351
352
353

354


355
356
357

358
359
360
361
362
363
364
365

366

























































































367















368





369





















370
371
372









373
374
375




376




377
378

379

380






381
382



383
384



385
386
387
388
389
390
391
392
393







394
395
396
397
398
399
400
401
402
403
404
405
406


407
408

409
410
411
412
413
414
415
416
417
418
419
420


421
422

423
424
425
426
427
428
429
430
431


432
433

434
435
436
437
438
439
440
441
442


443
444

445
446
447
448
449
450
451
452
453
454
455







-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+
-
-
+



-
-
-
+
+
+















-
+




-
+









+
+
-
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+



-
+



-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+

-
-
-

-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+



-
+
-
-



-
+







-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
-
-
-
-


-
+
-

-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
+
+
+
+





-
-
-
-
-
-
-
+
+
+










-
-
+
+
-






+





-
-
+
+
-









-
-
+
+
-









-
-
+
+
-



+







};

#define ForceAttributes(attributes, class) \
	((attributes) & (~macClassAttrs[(class)].forceOffAttrs | \
	(macClassAttrs[(class)].forceOnAttrs & ~kWindowResizableAttribute)))

/*
 * Structures and data for the wm attributes command (macOS 10.13 and later):
 */

 * Data for [wm attributes] command:
/* Hash tables for attributes which can be set before a window exists */
static Tcl_HashTable pathnameToSubclass;
static Tcl_HashTable pathnameToTabbingId;
static Tcl_HashTable pathnameToTabbingMode;

enum NSWindowSubclass {
    subclassNSWindow = 0,
    subclassNSPanel = 1
};
/* This array must be indexed by the enum above.*/
static const char *subclassNames[] = {"nswindow", "nspanel", NULL};

typedef struct buttonField_t {
    unsigned zoom: 1;
    unsigned miniaturize: 1;
    unsigned close: 1;
} buttonField;

/* The order of these names must match the order of the bits above! */
static const char *buttonNames[] = {"zoom", "miniaturize", "close", NULL};

typedef union windowButtonState_t {
    int intvalue;
    buttonField bits;
} windowButtonState;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
enum NSWindowClass {
    NSWindowClass_any = 0,
    NSWindowClass_window = 1,
    NSWindowClass_panel = 2
};
typedef struct styleMaskBit_t {
    const char *bitname;
    unsigned long bitvalue;
    enum NSWindowClass allowed;
} styleMaskBit;

static const styleMaskBit styleMaskBits[] = {
    /* Make the titlebar visible and use round corners. */
    {"titled", NSWindowStyleMaskTitled, NSWindowClass_window},
    /* Enable the close button. */
    {"closable", NSWindowStyleMaskClosable, NSWindowClass_window},
    /* Enable the miniaturize button. */
    {"miniaturizable", NSWindowStyleMaskMiniaturizable, NSWindowClass_window},
    /* Allow the user to resize the window. */
    {"resizable", NSWindowStyleMaskResizable, NSWindowClass_window},
    /*
     * Make the content view extend under the titlebar.  We force
     * titlebarAppearsTransparent when this bit is set.  Otherwise it is
     * pretty useless.
     */
 */
    {"fullsizecontentview", NSWindowStyleMaskFullSizeContentView, NSWindowClass_window},
    /* Rounded corners, cannot have a titlebar (overrides titled bit). */
    {"docmodal", NSWindowStyleMaskDocModalWindow, NSWindowClass_any},
    /* ============================================
     * The following bits are only valid for panels.
     */
    /* Make the title bar thinner. */
    {"utility", NSWindowStyleMaskUtilityWindow, NSWindowClass_panel},
    /* Do not activate the app when the window is activated. */
    {"nonactivatingpanel", NSWindowStyleMaskNonactivatingPanel, NSWindowClass_panel},
    /*
     * Requires utility.  Cannot be resizable.  Close button is an X; no other buttons.
     * Cannot be a docmodal.
     */
    {"HUDwindow", NSWindowStyleMaskHUDWindow, NSWindowClass_panel},
    {NULL, 0, NSWindowClass_any}
};

typedef struct tabbingMode_t {
    const char *modeName;
    long modeValue;
} tabbingMode;

static const tabbingMode tabbingModes[] = {
    {"auto",  NSWindowTabbingModeAutomatic},
    {"disallowed", NSWindowTabbingModeDisallowed},
    {"preferred", NSWindowTabbingModePreferred},
    {NULL, -1}
};

static const char *const appearanceStrings[] = {
    "aqua", "auto", "darkaqua", NULL
};
enum appearances {
    APPEARANCE_AQUA, APPEARANCE_AUTO, APPEARANCE_DARKAQUA
};

static Bool wantsToBeTab(NSWindow *macWindow) {
    Bool result;
    switch ([macWindow tabbingMode]) {
    case NSWindowTabbingModeDisallowed:
	result = False;
	break;
    case NSWindowTabbingModePreferred:
	result = True;
	break;
    case NSWindowTabbingModeAutomatic:
	result = ([NSWindow userTabbingPreference] ==
		NSWindowUserTabbingPreferenceAlways);
	break;
    default:
	result = False;
	break;
    }
    return result;
}

/*
 * Helper for the tkLayoutChanged methods.  Synchronizes Tk's understanding of
 * the bounds of a contentView with the window's.  It is needed because there
 * are situations when the window manager can change the layout of an NSWindow
 * without having been requested to do so by Tk.  Examples are when a window
 * goes FullScreen or shows a tab bar.  NSWindow methods which involve such
 * layout changes should be overridden or protected by methods which call this.
 */

static void syncLayout(NSWindow *macWindow)
{
    TkWindow *winPtr = TkMacOSXGetTkWindow(macWindow);

    if (winPtr) {
	// Using screen coordinates with origin at bottom left.
	NSRect frameRect = [macWindow frame];
	// This accounts for the tab bar, if there is one.
	NSRect contentRect = [macWindow contentRectForFrameRect: frameRect];
	WmInfo *wmPtr = winPtr->wmInfoPtr;

	// The parent includes the title bar, tab bar and window frame.
	wmPtr->xInParent = frameRect.origin.x - contentRect.origin.x;
	wmPtr->yInParent = (frameRect.origin.y + frameRect.size.height -
	    contentRect.origin.y - contentRect.size.height);
	wmPtr->parentWidth = winPtr->changes.width + frameRect.size.width -
	    contentRect.size.width;
	wmPtr->parentHeight = winPtr->changes.height + frameRect.size.height -
	    contentRect.size.height;
    }
}
#endif

typedef enum {
    WMATT_ALPHA, WMATT_APPEARANCE, WMATT_BUTTONS, WMATT_FULLSCREEN,
    WMATT_ISDARK, WMATT_MODIFIED, WMATT_NOTIFY, WMATT_TITLEPATH, WMATT_TOPMOST,
    WMATT_ALPHA, WMATT_FULLSCREEN, WMATT_MODIFIED, WMATT_NOTIFY,
    WMATT_TITLEPATH, WMATT_TOPMOST, WMATT_TRANSPARENT,
    WMATT_TRANSPARENT, WMATT_STYLEMASK, WMATT_CLASS, WMATT_TABBINGID,
    WMATT_TABBINGMODE, WMATT_TYPE, _WMATT_LAST_ATTRIBUTE
    _WMATT_LAST_ATTRIBUTE
} WmAttribute;

static const char *const WmAttributeNames[] = {
    "-alpha", "-appearance", "-buttons", "-fullscreen", "-isdark", "-modified",
    "-notify", "-titlepath", "-topmost", "-transparent", "-stylemask", "-class",
    "-tabbingid", "-tabbingmode", "-type", NULL
    "-alpha", "-fullscreen", "-modified", "-notify",
    "-titlepath", "-topmost", "-transparent",
    NULL
};

/*
 * The variable below is used to enable or disable tracing in this module. If
 * tracing is enabled, then information is printed on standard output about
 * interesting interactions with the window manager.
 */

static int wmTracing = 0;

/*
 * The following structure is the official type record for geometry management
 * of top-level windows.
 */

static void TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void TopLevelReqProc(ClientData dummy, Tk_Window tkwin);

static const Tk_GeomMgr wmMgrType = {
    "wm",			/* name */
    TopLevelReqProc,		/* requestProc */
    NULL,			/* lostContentProc */
    NULL,			/* lostSlaveProc */
};

/*
 * The following keeps state for Aqua dock icon bounce notification.
 */

static int tkMacOSXWmAttrNotifyVal = 0;

/*
 * Hash table for Mac Window -> TkWindow mapping.
 */
 * Declarations of static functions defined in this file:

static Tcl_HashTable windowTable;
static int windowHashInit = false;



#pragma mark NSWindow(TKWm)

/*
 * Conversion of coordinates between window and screen.
 */

@implementation NSWindow(TKWm)
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
- (NSPoint) convertPointToScreen: (NSPoint) point
{
    return [self convertBaseToScreen:point];
}
- (NSPoint) convertPointFromScreen: (NSPoint)point
{
    return [self convertScreenToBase:point];
}
@end
#else
- (NSPoint) convertPointToScreen: (NSPoint) point
{
    NSRect pointrect;
    pointrect.origin = point;
    pointrect.size.width = 0;
    pointrect.size.height = 0;
    return [self convertRectToScreen:pointrect].origin;
}
- (NSPoint) convertPointFromScreen: (NSPoint)point
{
    NSRect pointrect;
    pointrect.origin = point;
    pointrect.size.width = 0;
    pointrect.size.height = 0;
    return [self convertRectFromScreen:pointrect].origin;
}
@end
#endif

#pragma mark -


/*
 * Forward declarations for procedures defined in this file:
 */

static NSRect		InitialWindowBounds(TkWindow *winPtr,
			    NSWindow *macWindow);
static int		ParseGeometry(Tcl_Interp *interp, char *string,
			    TkWindow *winPtr);
static void		TopLevelEventProc(void *clientData,
static void		TopLevelEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		WmStackorderToplevelWrapperMap(TkWindow *winPtr,
			    Display *display, Tcl_HashTable *table);
static void		UpdateGeometryInfo(void *clientData);
static void		UpdateGeometryInfo(ClientData clientData);
static void		UpdateSizeHints(TkWindow *winPtr);
static void		UpdateVRootGeometry(WmInfo *wmPtr);
static int		WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmClientCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmColormapwindowsCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGridCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbadgeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmManageCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmOverrideredirectCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStateCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
static int		WmWinStyle(Tcl_Interp *interp, TkWindow *winPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
			    int objc, Tcl_Obj *const objv[]);
static int		WmWinAppearance(Tcl_Interp *interp, TkWindow *winPtr,
			    Tcl_Size objc, Tcl_Obj *const objv[]);
static void		ApplyWindowAttributeFlagChanges(TkWindow *winPtr,
			    NSWindow *macWindow, UInt64 oldAttributes,
			    int oldFlags, int create, int initial);
static void		ApplyContainerOverrideChanges(TkWindow *winPtr,
static void		ApplyMasterOverrideChanges(TkWindow *winPtr,
			    NSWindow *macWindow);
static void		GetMinSize(TkWindow *winPtr, int *minWidthPtr,
			    int *minHeightPtr);
static void		GetMaxSize(TkWindow *winPtr, int *maxWidthPtr,
			    int *maxHeightPtr);
static void		RemapWindows(TkWindow *winPtr,
			    MacDrawable *parentWin);
static void             RemoveTransient(TkWindow *winPtr);

#if MAC_OS_X_VERSION_MAX_ALLOWED > 101300

/*
 * Add a window as a tab in the group specified by its tabbingid, or
 * make it a standalone window if it is the only window with that
 * tabbingid.  Adjust the window size if a tab bar appeared or
 * disappeared.
 */

static void placeAsTab(TKWindow *macWindow) {
    TkWindow *winPtr = NULL, *winPtr2 = NULL;
    TKWindow *target = NULL, *sibling = NULL;
    NSString *identifier = [macWindow tabbingIdentifier];
    if (!wantsToBeTab(macWindow)) {
	[macWindow moveTabToNewWindow:NSApp];
	[(TKWindow *)target tkLayoutChanged];
	return;
    }
    for (NSWindow *window in [NSApp windows]) {
	if (window == macWindow) {
	    continue;
	}
	if ([identifier isEqualTo: [window tabbingIdentifier]] &&
	    wantsToBeTab(window)) {
	    target = (TKWindow*) window;
	    syncLayout(target);
	    break;
	}
    }
    syncLayout(macWindow);
    NSArray<NSWindow *> *tabs = [macWindow tabbedWindows];
    if ([tabs count] == 2) {
	sibling = tabs[0] == macWindow ? (TKWindow *)tabs[1] : (TKWindow *)tabs[0];
	syncLayout(sibling);
	winPtr2 = TkMacOSXGetTkWindow(sibling);
    }
    if (target) {
	CGFloat winHeight = [macWindow contentRectForFrameRect:
				[macWindow frame]].size.height;
	CGFloat winDelta = 0, targetHeight, targetDelta = 0;
	targetHeight =  [target contentRectForFrameRect:
			    [target frame]].size.height;
	[target addTabbedWindow:macWindow ordered:NSWindowAbove];
	targetDelta = targetHeight - [target contentRectForFrameRect:
					 [target frame]].size.height;
	winDelta = winHeight - [target contentRectForFrameRect:
				   [target frame]].size.height;
	if (winDelta) {
	    winPtr = TkMacOSXGetTkWindow(macWindow);
	    XMoveResizeWindow(winPtr->display, winPtr->window,
			      winPtr->changes.x, winPtr->changes.y,
			      winPtr->changes.width, winPtr->changes.height + winDelta );
	    if (sibling) {
		winPtr = TkMacOSXGetTkWindow(sibling);
		XMoveResizeWindow(winPtr->display, winPtr->window,
				  winPtr->changes.x, winPtr->changes.y,
				  winPtr->changes.width, winPtr->changes.height - winDelta );
	    }
	}
	if (targetDelta) {
	    winPtr = TkMacOSXGetTkWindow(target);
	    XMoveResizeWindow(winPtr->display, winPtr->window,
			      winPtr->changes.x, winPtr->changes.y,
			      winPtr->changes.width, winPtr->changes.height + targetDelta );
	}
    } else {
	CGFloat height = [macWindow contentRectForFrameRect:
			     [macWindow frame]].size.height;
	[macWindow moveTabToNewWindow:NSApp];
	CGFloat delta = height - [macWindow contentRectForFrameRect:
			    [macWindow frame]].size.height;
	winPtr = TkMacOSXGetTkWindow(macWindow);
	XMoveResizeWindow(winPtr->display, winPtr->window,
			  winPtr->changes.x, winPtr->changes.y,
			  winPtr->changes.width, winPtr->changes.height + delta);
	if (winPtr2) {
	    XMoveResizeWindow(winPtr2->display, winPtr2->window,
			      winPtr2->changes.x, winPtr2->changes.y,
			      winPtr2->changes.width, winPtr2->changes.height + delta );
	}
    }
}
#endif

#pragma mark NSWindow(TKWm)

@implementation NSWindow(TKWm)

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- (NSPoint) tkConvertPointToScreen: (NSPoint) point
{
    return [self convertBaseToScreen:point];
}
- (NSPoint) tkConvertPointFromScreen: (NSPoint)point
{
    return [self convertScreenToBase:point];
}
#else
- (NSPoint) tkConvertPointToScreen: (NSPoint) point
{
    NSRect pointrect = {point, {0,0}};
    return [self convertRectToScreen:pointrect].origin;
}

#define TK_GOT_AT_LEAST_SNOW_LEOPARD 1
- (NSPoint) tkConvertPointFromScreen: (NSPoint)point
{
    NSRect pointrect = {point, {0,0}};
    return [self convertRectFromScreen:pointrect].origin;
}
#endif
@end

#pragma mark -

@implementation TKPanel: NSPanel
@synthesize tkWindow = _tkWindow;

- (void) tkLayoutChanged
{
    syncLayout(self);
}

@end

@implementation TKDrawerWindow: NSWindow
@synthesize tkWindow = _tkWindow;
@end

@implementation TKWindow: NSWindow
@synthesize tkWindow = _tkWindow;
@end

#pragma mark TKWindow(TKWm)

@implementation TKWindow(TKWm)

- (void) tkLayoutChanged
{
    syncLayout(self);
}

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
- (void)toggleTabBar:(id)sender
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
@interface NSWindow(TkWm)
- (void) setCanCycle: (BOOL) canCycleFlag;
{
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);
    if (!winPtr) {
	return;
@end
    }
    [super toggleTabBar:sender];
    [self tkLayoutChanged];
}
#endif

- (NSSize)windowWillResize:(NSWindow *)sender
@interface NSDrawerWindow : NSWindow
                    toSize:(NSSize)frameSize
{
    NSRect currentFrame = [sender frame];
    TkWindow *winPtr = TkMacOSXGetTkWindow(sender);
    if (winPtr) {
	if (winPtr->wmInfoPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
	    frameSize.width = currentFrame.size.width;
	}
    id _i1, _i2;
}
	if (winPtr->wmInfoPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
	    frameSize.height = currentFrame.size.height;
	}
@end

    }
    return frameSize;
}
@implementation TKWindow
@end

@implementation TKWindow(TKWm)

- (BOOL) canBecomeKeyWindow
{
    TkWindow *winPtr = TkMacOSXGetTkWindow(self);

    if (!winPtr || !winPtr->wmInfoPtr) {
	return NO;
    }
    return (winPtr->wmInfoPtr &&
	    (winPtr->wmInfoPtr->macClass == kHelpWindowClass ||
	     winPtr->wmInfoPtr->attributes & kWindowNoActivatesAttribute)
	    ) ? NO : YES;
    return (winPtr && winPtr->wmInfoPtr && (winPtr->wmInfoPtr->macClass ==
	    kHelpWindowClass || winPtr->wmInfoPtr->attributes &
	    kWindowNoActivatesAttribute)) ? NO : YES;
}

#if DEBUG_ZOMBIES
- (id) retain
{
    id result = [super retain];
    const char *title = [[self title] UTF8String];
    if (title == nil) {
	title = "unnamed window";
    }
    if (DEBUG_ZOMBIES > 2) {
	fprintf(stderr, "Retained <%s>. Count is: %lu\n",
    if (DEBUG_ZOMBIES > 1){
	printf("Retained <%s>. Count is: %lu\n", title, [self retainCount]);
		title, [self retainCount]);
    }
    return result;
}

- (id) autorelease
{
    static int xcount = 0;
    id result = [super autorelease];
    const char *title = [[self title] UTF8String];
    if (title == nil) {
	title = "unnamed window";
    }
    if (DEBUG_ZOMBIES > 2) {
	fprintf(stderr, "Autoreleased <%s>. Count is %lu\n",
    if (DEBUG_ZOMBIES > 1){
	printf("Autoreleased <%s>. Count is %lu\n", title, [self retainCount]);
		title, [self retainCount]);
    }
    return result;
}

- (oneway void) release {
    const char *title = [[self title] UTF8String];
    if (title == nil) {
	title = "unnamed window";
    }
    if (DEBUG_ZOMBIES > 2) {
	fprintf(stderr, "Releasing <%s>. Count is %lu\n",
    if (DEBUG_ZOMBIES > 1){
	printf("Releasing <%s>. Count is %lu\n", title, [self retainCount]);
		title, [self retainCount]);
    }
    [super release];
}

- (void) dealloc {
    const char *title = [[self title] UTF8String];
    if (title == nil) {
	title = "unnamed window";
    }
    if (DEBUG_ZOMBIES > 0) {
	fprintf(stderr, ">>>> Freeing <%s>. Count is %lu\n",
    if (DEBUG_ZOMBIES > 0){
	printf(">>>> Freeing <%s>. Count is %lu\n", title, [self retainCount]);
		title, [self retainCount]);
    }
    [super dealloc];
}


#endif
@end

#pragma mark -

/*
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482







-
+







 *----------------------------------------------------------------------
 */

static void
SetWindowSizeLimits(
    TkWindow *winPtr)
{
    NSWindow *macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    NSWindow *macWindow = TkMacOSXDrawableWindow(winPtr->window);
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int minWidth, minHeight, maxWidth, maxHeight, base;

    if (!macWindow) {
	return;
    }
    GetMinSize(winPtr, &minWidth, &minHeight);
796
797
798
799
800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817

818
819
820

821
822

823
824

825

826
827
828
829
830

831
832
833
834
835
836
837

838
839
840
841
842
843
844

845
846
847
848

849
850
851
852
853
854
855
541
542
543
544
545
546
547

548

549
550
551
552
553
554
555
556
557
558
559
560

561

562

563
564

565
566
567
568

569





570







571







572




573
574
575
576
577
578
579
580







-
+
-












-
+
-

-
+

-
+


+
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
+







}

/*
 *----------------------------------------------------------------------
 *
 * FrontWindowAtPoint --
 *
 *	Find frontmost toplevel window at a given screen location which has the
 *	Find frontmost toplevel window at a given screen location.
 *      specified mainPtr.  If the location is in the title bar, return NULL.
 *
 * Results:
 *	TkWindow*.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static TkWindow*
FrontWindowAtPoint(
    int x,
    int x, int y)
    int y)
{
    NSPoint p = NSMakePoint(x, TkMacOSXZeroScreenHeight() - y);
    NSPoint p = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);
    NSArray *windows = [NSApp orderedWindows];
    TkWindow *winPtr = NULL;
    TkWindow *front = NULL;

    for (NSWindow *w in windows) {
	    if (w && NSMouseInRect(p, [w frame], NO)) {
	winPtr = TkMacOSXGetTkWindow(w);
		front = TkMacOSXGetTkWindow(w);
	if (winPtr) {
	    WmInfo *wmPtr = winPtr->wmInfoPtr;
	    NSRect windowFrame = [w frame];
	    NSRect contentFrame = [w frame];

		break;
	    contentFrame.size.height = [[w contentView] frame].size.height;
	    /*
	     * For consistency with other platforms, points in the
	     * title bar are not considered to be contained in the
	     * window.
	     */

	    }
	    if ((wmPtr->hints.initial_state == NormalState ||
		    wmPtr->hints.initial_state == ZoomState)) {
		if (NSMouseInRect(p, contentFrame, NO)) {
		    return winPtr;
		} else if (NSMouseInRect(p, windowFrame, NO)) {
		    return NULL;
		}
	}
	    }
	}
    }
    return NULL;
    return front;
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmNewWindow --
 *
865
866
867
868
869
870
871
872

873
874
875
876
877
878

879
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
895
896
897
590
591
592
593
594
595
596

597
598
599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622







-
+





-
+









+


-







 *----------------------------------------------------------------------
 */

void
TkWmNewWindow(
    TkWindow *winPtr)		/* Newly-created top-level window. */
{
    WmInfo *wmPtr = (WmInfo *)ckalloc(sizeof(WmInfo));
    WmInfo *wmPtr = ckalloc(sizeof(WmInfo));

    wmPtr->winPtr = winPtr;
    wmPtr->reparent = None;
    wmPtr->titleUid = NULL;
    wmPtr->iconName = NULL;
    wmPtr->container = NULL;
    wmPtr->master = None;
    wmPtr->hints.flags = InputHint | StateHint;
    wmPtr->hints.input = True;
    wmPtr->hints.initial_state = NormalState;
    wmPtr->hints.icon_pixmap = None;
    wmPtr->hints.icon_window = None;
    wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
    wmPtr->hints.icon_mask = None;
    wmPtr->hints.window_group = None;
    wmPtr->leaderName = NULL;
    wmPtr->masterWindowName = NULL;
    wmPtr->icon = NULL;
    wmPtr->iconFor = NULL;
    wmPtr->transientPtr = NULL;
    wmPtr->sizeHintsFlags = 0;
    wmPtr->minWidth = wmPtr->minHeight = 1;
    wmPtr->maxWidth = 0;
    wmPtr->maxHeight = 0;
    wmPtr->gridWin = NULL;
    wmPtr->widthInc = wmPtr->heightInc = 1;
    wmPtr->minAspect.x = wmPtr->minAspect.y = 1;
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946

947
948
949
950
951
952
953
647
648
649
650
651
652
653


654
655
656
657
658
659
660

661
662
663
664
665
666
667
668

669
670
671
672
673
674
675
676







-
-







-
+







-
+







    wmPtr->macClass = kDocumentWindowClass;
    wmPtr->attributes = macClassAttrs[kDocumentWindowClass].defaultAttrs;
    wmPtr->scrollWinPtr = NULL;
    wmPtr->menuPtr = NULL;
    wmPtr->window = nil;
    winPtr->wmInfoPtr = wmPtr;

    // initialize wmPtr->NSWindowSubclass here

    UpdateVRootGeometry(wmPtr);

    /*
     * Tk must monitor structure events for top-level windows, in order to
     * detect size and position changes caused by window managers.
     */

    Tk_CreateEventHandler((Tk_Window)winPtr, StructureNotifyMask,
    Tk_CreateEventHandler((Tk_Window) winPtr, StructureNotifyMask,
	    TopLevelEventProc, winPtr);

    /*
     * Arrange for geometry requests to be reflected from the window to the
     * window manager.
     */

    Tk_ManageGeometry((Tk_Window)winPtr, &wmMgrType, NULL);
    Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmMapWindow --
 *
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
694
695
696
697
698
699
700

701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724







-
















-
+








void
TkWmMapWindow(
    TkWindow *winPtr)		/* Top-level window that's about to be
				 * mapped. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    XEvent event;

    if (wmPtr->flags & WM_NEVER_MAPPED) {
	/*
	 * Create the underlying Mac window for this Tk window.
	 */

	if (!TkMacOSXHostToplevelExists(winPtr)) {
	    TkMacOSXMakeRealWindowExist(winPtr);
	}

	wmPtr->flags &= ~WM_NEVER_MAPPED;

	/*
	 * Generate configure event when we first map the window.
	 */

	TkGenWMConfigureEvent((Tk_Window)winPtr, wmPtr->x, wmPtr->y, -1, -1,
	TkGenWMConfigureEvent((Tk_Window) winPtr, wmPtr->x, wmPtr->y, -1, -1,
		TK_LOCATION_CHANGED);

	/*
	 * This is the first time this window has ever been mapped. Store all
	 * the window-manager-related information for the window.
	 */

1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
758
759
760
761
762
763
764

765
766
767

768

769







770
771
772
773
774
775
776







-
+


-

-
+
-
-
-
-
-
-
-







    if (wmPtr->flags & WM_UPDATE_PENDING) {
	Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
    }
    UpdateGeometryInfo(winPtr);
    wmPtr->flags &= ~WM_ABOUT_TO_MAP;

    /*
     * Map the window and process a MapNotify event for it.
     * Map the window.
     */

    winPtr->flags |= TK_MAPPED;
    XMapWindow(winPtr->display, winPtr->window);
    event.xany.serial = LastKnownRequestProcessed(winPtr->display);

    event.xany.send_event = False;
    event.xany.display = winPtr->display;
    event.xmap.window = winPtr->window;
    event.xmap.type = MapNotify;
    event.xmap.event = winPtr->window;
    event.xmap.override_redirect = winPtr->atts.override_redirect;
    Tk_HandleEvent(&event);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmUnmapWindow --
 *
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
787
788
789
790
791
792
793



794











795
796
797
798
799
800
801







-
-
-
+
-
-
-
-
-
-
-
-
-
-
-







 */

void
TkWmUnmapWindow(
    TkWindow *winPtr)		/* Top-level window that's about to be
				 * unmapped. */
{
    winPtr->flags &= ~TK_MAPPED;
    if ((winPtr->window != None)
	    && (XUnmapWindow(winPtr->display, winPtr->window) == Success)) {
    XUnmapWindow(winPtr->display, winPtr->window);
	XEvent event;

	event.xany.serial = LastKnownRequestProcessed(winPtr->display);
	event.xany.send_event = False;
	event.xany.display = winPtr->display;
	event.xunmap.type = UnmapNotify;
	event.xunmap.window = winPtr->window;
	event.xunmap.event = winPtr->window;
	event.xunmap.from_configure = false;
	Tk_HandleEvent(&event);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmDeadWindow --
 *
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130


1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143



1144
1145

1146
1147
1148
1149

1150
1151
1152
1153
1154

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183

1184
1185
1186

1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207



1208
1209


1210
1211
1212
1213

1214
1215
1216

1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235

1236
1237

1238
1239
1240
1241

1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267



1268
1269

1270
1271
1272
1273
1274
1275
1276
1277


1278
1279
1280
1281
1282

1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301

1302
1303
1304
1305

1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
812
813
814
815
816
817
818

819
820
821
822








823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

842
843
844
845

846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866




867





868






869



870









871
872


873








874
875
876


877
878




879



880






881



882

883
884







885
886

887
888
889
890

891

892
893

894













895
896








897
898
899


900








901
902


903
904

905

906

















907
908
909
910

911






912
913
914
915
916
917
918







-




-
-
-
-
-
-
-
-
+
+













+
+
+

-
+



-
+





+














-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-


-
-
+
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
+
-
-
-

-
+

-
-
-
-
-
-
-
+

-
+



-
+
-


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-


-
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+



-
+
-
-
-
-
-
-







 */

void
TkWmDeadWindow(
    TkWindow *winPtr)		/* Top-level window that's being deleted. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr, *wmPtr2;
    TKWindow *deadNSWindow;

    if (wmPtr == NULL) {
	return;
    }

    /*
     *If the dead window is a transient, remove it from the container's list.
     */

    RemoveTransient(winPtr);
    Tk_ManageGeometry((Tk_Window)winPtr, NULL, NULL);
    Tk_DeleteEventHandler((Tk_Window)winPtr, StructureNotifyMask,
    Tk_ManageGeometry((Tk_Window) winPtr, NULL, NULL);
    Tk_DeleteEventHandler((Tk_Window) winPtr, StructureNotifyMask,
	    TopLevelEventProc, winPtr);
    if (wmPtr->hints.flags & IconPixmapHint) {
	Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
    }
    if (wmPtr->hints.flags & IconMaskHint) {
	Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
    }
    if (wmPtr->iconName != NULL) {
	ckfree(wmPtr->iconName);
    }
    if (wmPtr->leaderName != NULL) {
	ckfree(wmPtr->leaderName);
    }
    if (wmPtr->masterWindowName != NULL) {
	ckfree(wmPtr->masterWindowName);
    }
    if (wmPtr->icon != NULL) {
	wmPtr2 = ((TkWindow *)wmPtr->icon)->wmInfoPtr;
	wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
	wmPtr2->iconFor = NULL;
    }
    if (wmPtr->iconFor != NULL) {
	wmPtr2 = ((TkWindow *)wmPtr->iconFor)->wmInfoPtr;
	wmPtr2 = ((TkWindow *) wmPtr->iconFor)->wmInfoPtr;
	wmPtr2->icon = NULL;
	wmPtr2->hints.flags &= ~IconWindowHint;
    }
    while (wmPtr->protPtr != NULL) {
	ProtocolHandler *protPtr = wmPtr->protPtr;

	wmPtr->protPtr = protPtr->nextPtr;
	Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
    }
    if (wmPtr->commandObj != NULL) {
	Tcl_DecrRefCount(wmPtr->commandObj);
    }
    if (wmPtr->clientMachine != NULL) {
	ckfree(wmPtr->clientMachine);
    }
    if (wmPtr->flags & WM_UPDATE_PENDING) {
	Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
    }

    /*
     * If the dead window has a transient, remove references to it from
     * the transient.
     */

     * Delete the Mac window and remove it from the windowTable. The window
    for (Transient *transientPtr = wmPtr->transientPtr;
	    transientPtr != NULL; transientPtr = transientPtr->nextPtr) {
    	TkWindow *winPtr2 = transientPtr->winPtr;
    	TkWindow *containerPtr = (TkWindow *)TkMacOSXGetContainer(winPtr2);

     * could be nil if the window was never mapped. However, we don't do this
    	if (containerPtr == winPtr) {
    	    wmPtr2 = winPtr2->wmInfoPtr;
    	    wmPtr2->container = NULL;
    	}
    }

     * for embedded windows, they don't go in the window list, and they do not
    while (wmPtr->transientPtr != NULL) {
	Transient *transientPtr = wmPtr->transientPtr;

     * own their portPtr's.
	wmPtr->transientPtr = transientPtr->nextPtr;
	ckfree(transientPtr);
    }

    deadNSWindow = (TKWindow *)wmPtr->window;

    /*
     * Remove references to the Tk window from the mouse event processing
     * state which is recorded in the NSApplication object.
     */

    if (winPtr == [NSApp tkPointerWindow]) {
	NSWindow *w;
    NSWindow *window = wmPtr->window;
	NSPoint mouse = [NSEvent mouseLocation];
	[NSApp setTkPointerWindow:nil];
	for (w in [NSApp orderedWindows]) {
	    if (w == deadNSWindow) {
		continue;
	    }
	    if (NSPointInRect(mouse, [w frame])) {
		TkWindow *winPtr2 = TkMacOSXGetTkWindow(w);

    if (window && !Tk_IsEmbedded(winPtr) ) {
	NSWindow *parent = [window parentWindow];
		int x = mouse.x, y = TkMacOSXZeroScreenHeight() - mouse.y;
		[NSApp setTkPointerWindow:winPtr2];
	if (parent) {
	    [parent removeChildWindow:window];
		Tk_UpdatePointer((Tk_Window) winPtr2, x, y,
				 [NSApp tkButtonState]);
		break;
	    }
	}
	}
    }

	[window close];
    /*
     * Unregister the NSWindow and remove all references to it from the Tk
     * data structures.  If the NSWindow is a child, disassociate it from
     * the parent.  Then close and release the NSWindow.
     */

	TkMacOSXUnregisterMacWindow(window);
    if (deadNSWindow && !Tk_IsEmbedded(winPtr)) {
	NSWindow *parent = [deadNSWindow parentWindow];
	[deadNSWindow setTkWindow:None];
        if (winPtr->window) {
            ((MacDrawable *)winPtr->window)->view = nil;
            ((MacDrawable *) winPtr->window)->view = nil;
        }
	wmPtr->window = NULL;

	if (parent) {
	    [parent removeChildWindow:deadNSWindow];
	}

#if DEBUG_ZOMBIES > 1
#if DEBUG_ZOMBIES > 0
	{
	    const char *title = [[deadNSWindow title] UTF8String];
	    const char *title = [[window title] UTF8String];
	    if (title == nil) {
		title = "unnamed window";
	    }
	    fprintf(stderr, ">>>> Closing <%s>. Count is: %lu\n", title,
	    printf(">>>> Closing <%s>. Count is: %lu\n", title, [window retainCount]);
		    [deadNSWindow retainCount]);
	}
#endif

        [window release];
	/*
	 * When a window is closed we want to move the focus to the next
	 * highest window.  Apple's documentation says that calling the
	 * orderOut method of the key window will accomplish this.  But
	 * experiment shows that this is not the case.  So we have to reset the
	 * key window ourselves.  When the window is the last one on the screen
	 * there is no choice for a new key window.  Moreover, if the host
	 * computer has a TouchBar then the TouchBar holds a reference to the
	 * key window which prevents it from being deallocated until it stops
	 * being the key window.  On these systems the only option for
	 * preventing zombies is to set the key window to nil.
	 */

	wmPtr->window = NULL;

	/*
	 * Fix bug 5692042764:
	 * set tkEventTarget to NULL when there is no window to send Tk events to.
	 */
	TkWindow *newTkEventTarget = NULL;

	for (NSWindow *w in [NSApp orderedWindows]) {
	    TkWindow *winPtr2 = TkMacOSXGetTkWindow(w);
	/* Activate the highest window left on the screen. */
	NSArray *windows = [NSApp orderedWindows];
	if ( [windows count] > 0 ) {
	    BOOL isOnScreen;

	    NSWindow *front = [windows objectAtIndex:0];
	    if (!winPtr2 || !winPtr2->wmInfoPtr) {
		continue;
	    }
	    wmPtr2 = winPtr2->wmInfoPtr;
	    isOnScreen = (wmPtr2->hints.initial_state != IconicState &&
			  wmPtr2->hints.initial_state != WithdrawnState);
	    if (w != deadNSWindow && isOnScreen && [w canBecomeKeyWindow]) {
		[w makeKeyAndOrderFront:NSApp];
	    if ( front && [front canBecomeKeyWindow] ) {
		[front makeKeyAndOrderFront:NSApp];
		newTkEventTarget = TkMacOSXGetTkWindow(w);
		break;
	    }
	}

	[NSApp _resetAutoreleasePool];
	[NSApp setTkEventTarget:newTkEventTarget];

	/*
	 * Prevent zombies on systems with a TouchBar.
	 */

	if (deadNSWindow == [NSApp keyWindow]) {
	    [NSApp _setKeyWindow:nil];
	    [NSApp _setMainWindow:nil];
	}
	[deadNSWindow close];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
	[preferences removeObserver:deadNSWindow.contentView
		      forKeyPath:@"AppleHighlightColor"];
#endif
	[deadNSWindow release];

#if DEBUG_ZOMBIES > 1
#if DEBUG_ZOMBIES > 0
	fprintf(stderr, "================= Pool dump ===================\n");
	[NSAutoreleasePool showPools];
#endif

    }
    }

    /*
     * Deallocate the wmInfo and clear the wmInfoPtr.
     */

    ckfree(wmPtr);
    winPtr->wmInfoPtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
930
931
932
933
934
935
936

937
938
939
940
941
942
943
944







-
+







 *	A window property may get updated.
 *
 *----------------------------------------------------------------------
 */

void
TkWmSetClass(
    TCL_UNUSED(TkWindow *))		/* Newly-created top-level window. */
    TkWindow *winPtr)		/* Newly-created top-level window. */
{
    return;
}

/*
 *----------------------------------------------------------------------
 *
1352
1353
1354
1355
1356
1357
1358

1359
1360
1361

1362
1363
1364
1365
1366

1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387

1388
1389
1390
1391
1392
1393
1394
1395
952
953
954
955
956
957
958
959
960
961

962
963
964
965
966

967
968
969
970

971
972
973
974
975
976
977
978
979
980

981
982
983
984
985
986
987

988

989
990
991
992
993
994
995







+


-
+




-
+



-
+









-
+






-
+
-







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

/* ARGSUSED */
int
Tk_WmObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = (Tk_Window) clientData;
    static const char *const optionStrings[] = {
	"aspect", "attributes", "client", "colormapwindows",
	"command", "deiconify", "focusmodel", "forget",
	"frame", "geometry", "grid", "group", "iconbadge",
	"frame", "geometry", "grid", "group",
	"iconbitmap", "iconify", "iconmask", "iconname",
	"iconphoto", "iconposition", "iconwindow",
	"manage", "maxsize", "minsize", "overrideredirect",
	"positionfrom", "protocol", "resizable", "sizefrom",
	"stackorder", "state", "title", "transient",
	"withdraw", NULL };
    enum options {
	WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
	WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FORGET,
	WMOPT_FRAME, WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP,  WMOPT_ICONBADGE,
	WMOPT_FRAME, WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP,
	WMOPT_ICONBITMAP, WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME,
	WMOPT_ICONPHOTO, WMOPT_ICONPOSITION, WMOPT_ICONWINDOW,
	WMOPT_MANAGE, WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT,
	WMOPT_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM,
	WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT,
	WMOPT_WITHDRAW };
    int index;
    int index, length;
    Tcl_Size length;
    char *argv1;
    TkWindow *winPtr;

    if (objc < 2) {
    wrongNumArgs:
	Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
	return TCL_ERROR;
1409
1410
1411
1412
1413
1414
1415

1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445


1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019










1020

















1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032







+



-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+


-
+







	return Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing);
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    if (objc < 3) {
	goto wrongNumArgs;
    }
    if (index == WMOPT_ATTRIBUTES && objc == 5 &&
	strcmp(Tcl_GetString(objv[3]), "-class") == 0) {
	if (TkGetWindowFromObj(NULL, tkwin, objv[2], (Tk_Window *) &winPtr)
	    == TCL_OK) {
	    if (winPtr->wmInfoPtr->window != NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Cannot change the class after the mac window is created.",-1));
		Tcl_SetErrorCode(interp, "TK", "CLASS_CHANGE", NULL);
		return TCL_ERROR;
	    }

	} else {
		winPtr = NULL;
	}
    } else if (index == WMOPT_ATTRIBUTES && objc == 5 &&
	       strcmp(Tcl_GetString(objv[3]), "-tabbingid") == 0) {
	    if (TkGetWindowFromObj(NULL, tkwin, objv[2], (Tk_Window *) &winPtr)
		!= TCL_OK) {
		winPtr = NULL;
	    }
    } else if (index == WMOPT_ATTRIBUTES && objc == 5 &&
	       strcmp(Tcl_GetString(objv[3]), "-tabbingmode") == 0) {
	    if (TkGetWindowFromObj(NULL, tkwin, objv[2], (Tk_Window *) &winPtr)
		!= TCL_OK) {
		winPtr = NULL;
	    }
    } else if (TkGetWindowFromObj(interp, tkwin, objv[2], (Tk_Window *) &winPtr)
	       != TCL_OK) {
    if (TkGetWindowFromObj(interp, tkwin, objv[2], (Tk_Window *) &winPtr)
	!= TCL_OK) {
	return TCL_ERROR;
    }
    if (winPtr && !Tk_IsTopLevel(winPtr)
    if (!Tk_IsTopLevel(winPtr)
	    && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window \"%s\" isn't a top-level window", winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TOPLEVEL", winPtr->pathName,
		NULL);
	return TCL_ERROR;
    }
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1052
1053
1054
1055
1056
1057
1058


1059
1060
1061
1062
1063
1064
1065







-
-







	return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GEOMETRY:
	return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GRID:
	return WmGridCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GROUP:
	return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBADGE:
	return WmIconbadgeCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBITMAP:
	return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONIFY:
	return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONMASK:
	return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONNAME:
1542
1543
1544
1545
1546
1547
1548
1549

1550
1551
1552

1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570




1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126

1127
1128
1129

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141




1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169







-
+


-
+


-
+











-
-
-
-
+
+
+
+
















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmAspectCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int numer1, denom1, numer2, denom2;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?minNumer minDenom maxNumer maxDenom?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PAspect) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewWideIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewWideIntObj(wmPtr->maxAspect.y);
	    results[0] = Tcl_NewIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewIntObj(wmPtr->maxAspect.y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~PAspect;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) {
	    return TCL_ERROR;
	}
	if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) ||
		(denom2 <= 0)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "aspect number can't be <= 0", TCL_INDEX_NONE));
		    "aspect number can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ASPECT", NULL);
	    return TCL_ERROR;
	}
	wmPtr->minAspect.x = numer1;
	wmPtr->minAspect.y = denom1;
	wmPtr->maxAspect.x = numer2;
	wmPtr->maxAspect.y = denom2;
1620
1621
1622
1623
1624
1625
1626
1627

1628
1629
1630
1631
1632
1633
1634
1635
1195
1196
1197
1198
1199
1200
1201

1202

1203
1204
1205
1206
1207
1208
1209







-
+
-







    TkWindow *winPtr,		/* Toplevel to work with */
    NSWindow *macWindow,
    Tcl_Interp *interp,		/* Current interpreter */
    WmAttribute attribute,	/* Code of attribute to set */
    Tcl_Obj *value)		/* New value */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int boolValue;
    int boolean;
    NSString *identifier;

    switch (attribute) {
    case WMATT_ALPHA: {
	double dval;

	if (Tcl_GetDoubleFromObj(interp, value, &dval) != TCL_OK) {
	    return TCL_ERROR;
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1217
1218
1219
1220
1221
1222
1223

























1224














1225
1226
1227















1228
1229
1230
1231
1232






1233
1234
1235

1236
1237
1238


1239
1240
1241
1242
1243

1244
1245
1246

1247
1248
1249
1250
1251
1252
1253

1254
1255
1256

1257
1258
1259



















































































































1260

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270

1271
1272
1273

1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289

1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300
1301
1302



1303
1304
1305
1306
1307
1308





1309
1310
1311
1312
1313
1314
1315







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-



-
+


-
-
+
+



-
+


-
+






-
+


-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+









-
+


-
+


-
+









-
+


-
+



-
+








-
-
-
+
+
+



-
-
-
-
-







	    dval = 0.0;
	} else if (dval > 1.0) {
	    dval = 1.0;
	}
	[macWindow setAlphaValue:dval];
	break;
    }
    case WMATT_APPEARANCE: {
	int index;
	if (Tcl_GetIndexFromObjStruct(interp, value, appearanceStrings,
	    sizeof(char *), "appearancename", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch ((enum appearances) index) {
	case APPEARANCE_AQUA:
	    macWindow.appearance = [NSAppearance appearanceNamed:
		NSAppearanceNameAqua];
	    break;
	case APPEARANCE_DARKAQUA:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	    if (@available(macOS 10.14, *)) {
		macWindow.appearance = [NSAppearance appearanceNamed:
		    NSAppearanceNameDarkAqua];
	    }
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	    break;
	default:
	    macWindow.appearance = nil;
	}
	break;
    }
    case WMATT_BUTTONS: {
    case WMATT_FULLSCREEN:
	windowButtonState state = {0};
	Tcl_Obj **elements;
	Tcl_Size nElements, i;
	if (Tcl_ListObjGetElements(interp, value, &nElements, &elements) == TCL_OK) {
	    int index = 0;
	    for (i = 0; i < nElements; i++) {
		if (Tcl_GetIndexFromObjStruct(interp, elements[i], buttonNames,
		       sizeof(char *), "window button name", 0, &index) != TCL_OK) {
		    return TCL_ERROR;
		} else {
		    state.intvalue |= (1 << index);
		}
	    }
	} else if (Tcl_GetIntFromObj(interp, value, &state.intvalue) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
	    return TCL_ERROR;
	}
	NSButton *closer = [macWindow standardWindowButton:
			       NSWindowCloseButton];
	NSButton *miniaturizer = [macWindow standardWindowButton:
				     NSWindowMiniaturizeButton];
	NSButton *zoomer = [macWindow standardWindowButton:
			      NSWindowZoomButton];
	closer.enabled = (state.bits.close != 0);
	miniaturizer.enabled = (state.bits.miniaturize != 0);
	zoomer.enabled = (state.bits.zoom != 0);
	break;
    }
    case WMATT_FULLSCREEN:
	if (Tcl_GetBooleanFromObj(interp, value, &boolValue) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (boolean != ((wmPtr->flags & WM_FULLSCREEN) != 0)) {
	    if (TkMacOSXMakeFullscreen(winPtr, macWindow, boolean, interp)
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	if (boolValue != (([macWindow styleMask] & NSFullScreenWindowMask) != 0)) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
	    [macWindow toggleFullScreen:macWindow];
#else
	    TKLog(@"The fullscreen attribute is ignored on this system.");
#endif
	}
	break;
    case WMATT_MODIFIED:
	if (Tcl_GetBooleanFromObj(interp, value, &boolValue) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (boolValue != [macWindow isDocumentEdited]) {
	    [macWindow setDocumentEdited:(BOOL)boolValue];
	if (boolean != [macWindow isDocumentEdited]) {
	    [macWindow setDocumentEdited:boolean];
	}
	break;
    case WMATT_NOTIFY:
	if (Tcl_GetBooleanFromObj(interp, value, &boolValue) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (boolValue == !tkMacOSXWmAttrNotifyVal) {
	if (boolean == !tkMacOSXWmAttrNotifyVal) {
	    static NSInteger request = -1;

	    if (request >= 0) {
		[NSApp cancelUserAttentionRequest:request];
		request = -1;
	    }
	    if (boolValue) {
	    if (boolean) {
		request = [NSApp requestUserAttention:NSCriticalRequest];
	    }
	    tkMacOSXWmAttrNotifyVal = boolValue;
	    tkMacOSXWmAttrNotifyVal = boolean;
	}
	break;
    case WMATT_STYLEMASK: {
	unsigned long styleMaskValue = 0;
	Tcl_Obj **elements;
	Tcl_Size nElements, i;
	if (Tcl_ListObjGetElements(interp, value, &nElements, &elements) == TCL_OK) {
	    int index;
	    for (i = 0; i < nElements; i++) {
		if (Tcl_GetIndexFromObjStruct(interp, elements[i], styleMaskBits,
		       sizeof(styleMaskBit), "styleMask bit", 0, &index) != TCL_OK) {
		    return TCL_ERROR;
		} else if (![macWindow isKindOfClass: [NSPanel class]] &&
			   styleMaskBits[index].allowed == NSWindowClass_panel) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		        "styleMask bit \"%s\" can only be used with an NSPanel",
			styleMaskBits[index].bitname));
		    Tcl_SetErrorCode(interp, "TK", "INVALID_STYLEMASK_BIT", NULL);
		    return TCL_ERROR;
		} else {
		    styleMaskValue |= styleMaskBits[index].bitvalue;
		}
		/*
		 * Be sure not to change the fullscreen bit.
		 */
		styleMaskValue |= (NSWindowStyleMaskFullScreen & macWindow.styleMask);
	    }
	    /*
	     * A resizable docmodal NSWindow or NSPanel does not work
	     * correctly.  It cannot be resized from the top edge.  Other bits,
	     * such as titled are ignored for docmodals.  To be safe, we clear
	     * all other bits when the docmodal bit is set.
	     */
	    if (styleMaskValue & NSDocModalWindowMask) {
		styleMaskValue &= ~NSWindowStyleMaskResizable;
	    }
	    if ([macWindow isKindOfClass: [NSPanel class]]) {
		/*
		 * We always make NSPanels titled, nonactivating utility windows,
		 * even if these bits are not requested in the command.
		 */
		if (!(styleMaskValue & NSWindowStyleMaskTitled) ) {
		    styleMaskValue |= NSWindowStyleMaskTitled;
		    styleMaskValue |= NSWindowStyleMaskUtilityWindow;
		    styleMaskValue |= NSWindowStyleMaskNonactivatingPanel;
		}
	    }
	    if (styleMaskValue & NSWindowStyleMaskFullSizeContentView) {
		macWindow.titlebarAppearsTransparent = YES;
	    } else {
		macWindow.titlebarAppearsTransparent = NO;
	    }
	} else {
	    return TCL_ERROR;
	}
	NSRect oldFrame = [macWindow frame];
#ifdef DEBUG
	fprintf(stderr, "Current styleMask: %lx\n", [macWindow styleMask]);
	fprintf(stderr, "Setting styleMask to %lx\n", styleMaskValue);
#endif
        macWindow.styleMask = (unsigned long) styleMaskValue;
	NSRect newFrame = [macWindow frame];
	int heightDiff = newFrame.size.height - oldFrame.size.height;
	int newHeight = heightDiff < 0 ? newFrame.size.height :
	    newFrame.size.height - heightDiff;
	[(TKWindow *)macWindow tkLayoutChanged];
	if (heightDiff) {
	    //Calling XMoveResizeWindow twice is a hack to force a relayout
	    //of the window.
	    XMoveResizeWindow(winPtr->display, winPtr->window,
	 		  winPtr->changes.x, winPtr->changes.y,
			  newFrame.size.width, newHeight - 1);
	    XMoveResizeWindow(winPtr->display, winPtr->window,
	 		  winPtr->changes.x, winPtr->changes.y,
			  newFrame.size.width, newHeight);
	}
	break;
    }
    case WMATT_TABBINGID: {
	NSString *oldId = [macWindow tabbingIdentifier];
	char *valueString;
	Tcl_Size length;
	if ([NSApp macOSVersion] < 101300) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		  "Tabbing identifiers require macOS 10.13", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TABBINGID", NULL);
	    return TCL_ERROR;
	}
	valueString = Tcl_GetStringFromObj(value, &length);
	identifier = [NSString stringWithUTF8String:valueString];
	[macWindow setTabbingIdentifier: identifier];

	/*
	 * If the tabbingIdentifier of a tab is changed we move it into
	 * the tab group with that identifier.
	 */

	if ([oldId compare:identifier] != NSOrderedSame) {
	    placeAsTab((TKWindow *)macWindow);
	}
	break;
    }
    case WMATT_TABBINGMODE: {
	int index;
	tabbingMode mode;
	if (Tcl_GetIndexFromObjStruct(interp, value, tabbingModes,
	   sizeof(tabbingMode), "NSWindow Tabbing Mode", 0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }
	mode = tabbingModes[index];
	[macWindow setTabbingMode: mode.modeValue];
	placeAsTab((TKWindow *)macWindow);
	break;
    }
    case WMATT_ISDARK: {
	break;
    }
    case WMATT_TITLEPATH: {
	const char *path = (const char *)Tcl_FSGetNativePath(value);
	const char *path = Tcl_FSGetNativePath(value);
	NSString *filename = @"";

	if (path && *path) {
	    filename = [NSString stringWithUTF8String:path];
	}
	[macWindow setRepresentedFilename:filename];
	break;
    }
    case WMATT_TOPMOST:
	if (Tcl_GetBooleanFromObj(interp, value, &boolValue) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (boolValue != ((wmPtr->flags & WM_TOPMOST) != 0)) {
	if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) {
	    int oldFlags = wmPtr->flags;

	    if (boolValue) {
	    if (boolean) {
		wmPtr->flags |= WM_TOPMOST;
	    } else {
		wmPtr->flags &= ~WM_TOPMOST;
	    }
	    ApplyWindowAttributeFlagChanges(winPtr, macWindow,
		    wmPtr->attributes, oldFlags, 1, 0);
	}
	break;
    case WMATT_TRANSPARENT:
	if (Tcl_GetBooleanFromObj(interp, value, &boolValue) != TCL_OK) {
	if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (boolValue != ((wmPtr->flags & WM_TRANSPARENT) != 0)) {
	if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) {
	    UInt64 oldAttributes = wmPtr->attributes;
	    int oldFlags = wmPtr->flags;

	    if (boolValue) {
	    if (boolean) {
		wmPtr->flags |= WM_TRANSPARENT;
		wmPtr->attributes |= kWindowNoShadowAttribute;
	    } else {
		wmPtr->flags &= ~WM_TRANSPARENT;
		wmPtr->attributes &= ~kWindowNoShadowAttribute;
	    }
	    ApplyWindowAttributeFlagChanges(winPtr, macWindow, oldAttributes,
		    oldFlags, 1, 0);
	    [macWindow setBackgroundColor:boolValue ? [NSColor clearColor] : nil];
	    [macWindow setOpaque:!boolValue];
	    TkMacOSXInvalidateWindow((MacDrawable *)winPtr->window,
	    [macWindow setBackgroundColor:boolean ? [NSColor clearColor] : nil];
	    [macWindow setOpaque:!boolean];
	    TkMacOSXInvalidateWindow((MacDrawable *) winPtr->window,
		    TK_PARENT_WINDOW);
	    }
	break;
    case WMATT_CLASS:
	break;
    case WMATT_TYPE:
	TKLog(@"The type attribute is ignored on macOS.");
	break;
    case _WMATT_LAST_ATTRIBUTE:
    default:
	return TCL_ERROR;
    }
    return TCL_OK;
}

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
1332
1333
1334
1335
1336
1337
1338
1339










































1340




1341
1342
1343
1344
1345
1346
1347
1348














1349
1350
1351
















1352
1353
1354
1355
1356
1357
1358



1359
1360
1361
1362
1363
1364
1365








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-







{
    Tcl_Obj *result = NULL;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    switch (attribute) {
    case WMATT_ALPHA:
	result = Tcl_NewDoubleObj([macWindow alphaValue]);
	break;
    case WMATT_APPEARANCE: {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
	NSAppearanceName appearance;
#else
	NSString *appearance;
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
	const char *resultString = "unrecognized";
	appearance = macWindow.appearance.name;
	if (appearance == nil) {
	    resultString = appearanceStrings[APPEARANCE_AUTO];
	} else if (appearance == NSAppearanceNameAqua) {
	    resultString = appearanceStrings[APPEARANCE_AQUA];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	} else if (@available(macOS 10.14, *)) {
	    if (appearance == NSAppearanceNameDarkAqua) {
		resultString = appearanceStrings[APPEARANCE_DARKAQUA];
	    }
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	}
	result = Tcl_NewStringObj(resultString, TCL_INDEX_NONE);
	break;
    }
    case WMATT_BUTTONS: {
	result = Tcl_NewListObj(3, NULL);
	if ([macWindow standardWindowButton:NSWindowCloseButton].enabled) {
	    Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj("close", TCL_INDEX_NONE));
	}
	if ([macWindow standardWindowButton:NSWindowMiniaturizeButton].enabled) {
	    Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj("miniaturize", TCL_INDEX_NONE));
	}
	if ([macWindow standardWindowButton:NSWindowZoomButton].enabled) {
	    Tcl_ListObjAppendElement(NULL, result, Tcl_NewStringObj("zoom", TCL_INDEX_NONE));
	}
	break;
    }
    case WMATT_CLASS:
	if ([macWindow isKindOfClass:[NSPanel class]]) {
	    result = Tcl_NewStringObj(subclassNames[subclassNSPanel], TCL_INDEX_NONE);
	} else {
	    result = Tcl_NewStringObj(subclassNames[subclassNSWindow], TCL_INDEX_NONE);
	}
	break;
    case WMATT_FULLSCREEN:
	result = Tcl_NewBooleanObj([macWindow styleMask] & NSFullScreenWindowMask);
	break;
    case WMATT_ISDARK:
	result = Tcl_NewBooleanObj(TkMacOSXInDarkMode((Tk_Window)winPtr));
	result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN);
	break;
    case WMATT_MODIFIED:
	result = Tcl_NewBooleanObj([macWindow isDocumentEdited]);
	break;
    case WMATT_NOTIFY:
	result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal);
	break;
    case WMATT_STYLEMASK: {
	unsigned long styleMaskValue = [macWindow styleMask];
	const styleMaskBit *bit;
	result = Tcl_NewListObj(9, NULL);
	for (bit = styleMaskBits; bit->bitname != NULL; bit++) {
	    if (styleMaskValue & bit->bitvalue) {
		Tcl_ListObjAppendElement(NULL, result,
		    Tcl_NewStringObj(bit->bitname, TCL_INDEX_NONE));
	    }
	}
	break;
    }
    case WMATT_TABBINGID:
	result = Tcl_NewStringObj([[macWindow tabbingIdentifier] UTF8String],
    case WMATT_TITLEPATH:
	result = Tcl_NewStringObj([[macWindow representedFilename] UTF8String],
		-1);
	break;
    case WMATT_TABBINGMODE: {
	long mode = [macWindow tabbingMode];
	const char *name = "unrecognized";
	for (const tabbingMode *m = tabbingModes; m->modeName != NULL; m++) {
	    if (m->modeValue == mode) {
		name = m->modeName;
		break;
	    }
	}
	result = Tcl_NewStringObj(name, TCL_INDEX_NONE);
	break;
    }
    case WMATT_TITLEPATH:
	result = Tcl_NewStringObj([[macWindow representedFilename] UTF8String],
		TCL_INDEX_NONE);
	break;
    case WMATT_TOPMOST:
	result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST);
	break;
    case WMATT_TRANSPARENT:
	result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT);
	break;
    case WMATT_TYPE:
	result = Tcl_NewStringObj("unsupported", TCL_INDEX_NONE);
	break;
    case _WMATT_LAST_ATTRIBUTE:
    default:
	break;
    }
    return result;
}

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
1378
1379
1380
1381
1382
1383
1384

1385
1386
1387

1388
1389
1390
1391
1392



1393


















































1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406

1407
1408

1409
1410
1411

1412
1413
1414
1415
1416

1417
1418

1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1433







-
+


-
+




-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+




-
+






-
+

-
+


-
+




-
+

-
+






-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmAttributesCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int attribute = 0;
    NSWindow *macWindow;
    if (winPtr == NULL && objc == 5) {
	int index, isNew = 0;
	Tcl_Size length;

	/*
	 * If we are setting an atttribute of a future window, save the value
	 * in a hash table so we can look it up when the window is actually
	 * created.
	 */

	if (strcmp(Tcl_GetString(objv[3]), "-class") == 0) {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[4], subclassNames,
		    sizeof(char *), "NSWindow subclass", 0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }
	    Tcl_HashEntry *hPtr = Tcl_CreateHashEntry(&pathnameToSubclass,
		Tcl_GetString(objv[2]), &isNew);
	    if (hPtr) {
		Tcl_SetHashValue(hPtr, INT2PTR(index));
		return TCL_OK;
	    }
	} else if (strcmp(Tcl_GetString(objv[3]), "-tabbingid") == 0) {
	    char *identifier = Tcl_GetStringFromObj(objv[4], &length);
	    char *value = (char *)ckalloc(length + 1);
	    strncpy(value, identifier, length + 1);
	    Tcl_HashEntry *hPtr = Tcl_CreateHashEntry(&pathnameToTabbingId,
				      Tcl_GetString(objv[2]), &isNew);
	    if (hPtr) {
		Tcl_SetHashValue(hPtr, value);
		return TCL_OK;
	    }
	} else if (strcmp(Tcl_GetString(objv[3]), "-tabbingmode") == 0) {
	    long value = NSWindowTabbingModeAutomatic;
	    int modeIndex;
	    if (Tcl_GetIndexFromObjStruct(interp, objv[4], tabbingModes,
	       sizeof(tabbingMode), "NSWindow Tabbing Mode", 0, &modeIndex) == TCL_OK) {
		value = tabbingModes[modeIndex].modeValue;
	    }
	    Tcl_HashEntry *hPtr = Tcl_CreateHashEntry(&pathnameToTabbingMode,
		Tcl_GetString(objv[2]), &isNew);
	    if (hPtr) {
		Tcl_SetHashValue(hPtr, value);
		return TCL_OK;
	    }
	}
    }
    if (!winPtr) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	   "Only -class, -tabbingid, or -tabbingmode can be set before the window exists."));
	Tcl_SetErrorCode(interp, "TK", "NO_WINDOW", NULL);
	return TCL_ERROR;
    }
    if (winPtr && winPtr->window == None) {
	Tk_MakeWindowExist((Tk_Window)winPtr);
    if (winPtr->window == None) {
	Tk_MakeWindowExist((Tk_Window) winPtr);
    }
    if (!TkMacOSXHostToplevelExists(winPtr)) {
	TkMacOSXMakeRealWindowExist(winPtr);
    }
    macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    macWindow = TkMacOSXDrawableWindow(winPtr->window);

    if (objc == 3) {		/* wm attributes $win */
	Tcl_Obj *result = Tcl_NewObj();

	for (attribute = 0; attribute < _WMATT_LAST_ATTRIBUTE; ++attribute) {
	    Tcl_ListObjAppendElement(NULL, result,
		    Tcl_NewStringObj(WmAttributeNames[attribute], TCL_INDEX_NONE));
		    Tcl_NewStringObj(WmAttributeNames[attribute], -1));
	    Tcl_ListObjAppendElement(NULL, result,
		    WmGetAttribute(winPtr, macWindow, (WmAttribute)attribute));
		    WmGetAttribute(winPtr, macWindow, attribute));
	}
	Tcl_SetObjResult(interp, result);
    } else if (objc == 4) {	/* wm attributes $win -attribute */
    } else if (objc == 4)  {	/* wm attributes $win -attribute */
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], WmAttributeNames,
		sizeof(char *), "attribute", 0, &attribute) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, WmGetAttribute(winPtr, macWindow, (WmAttribute)attribute));
	Tcl_SetObjResult(interp, WmGetAttribute(winPtr, macWindow, attribute));
    } else if ((objc - 3) % 2 == 0) {	/* wm attributes $win -att value... */
	Tcl_Size i;
	int i;

	for (i = 3; i < objc; i += 2) {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], WmAttributeNames,
		    sizeof(char *), "attribute", 0, &attribute) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (WmSetAttribute(winPtr, macWindow, interp, (WmAttribute)attribute, objv[i+1])
	    if (WmSetAttribute(winPtr, macWindow, interp, attribute, objv[i+1])
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	}
    } else {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?-attribute ?value ...??");
	return TCL_ERROR;
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
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459

1460
1461
1462

1463
1464

1465
1466
1467
1468
1469
1470
1471
1472
1473

1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488

1489
1490
1491
1492
1493
1494
1495
1496







-
+


-
+


-
+

-
+








-
+














-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmClientCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    char *argv3;
    Tcl_Size length;
    int length;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->clientMachine != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(wmPtr->clientMachine, TCL_INDEX_NONE));
		    Tcl_NewStringObj(wmPtr->clientMachine, -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    if (argv3[0] == 0) {
	if (wmPtr->clientMachine != NULL) {
	    ckfree(wmPtr->clientMachine);
	    wmPtr->clientMachine = NULL;
	}
	return TCL_OK;
    }
    if (wmPtr->clientMachine != NULL) {
	ckfree(wmPtr->clientMachine);
    }
    wmPtr->clientMachine = (char *)ckalloc(length + 1);
    wmPtr->clientMachine = ckalloc(length + 1);
    strcpy(wmPtr->clientMachine, argv3);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
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
1509
1510
1511
1512
1513
1514
1515

1516
1517
1518

1519
1520


1521
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1536

1537
1538
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556

1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575

1576
1577
1578
1579
1580
1581
1582
1583







-
+


-
+

-
-
+







-
+







-
+








-
+










-
+


















-
+







 */

static int
WmColormapwindowsCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow **cmapList, *winPtr2;
    Tcl_Size i, windowObjc;
    int gotToplevel = 0;
    int i, windowObjc, gotToplevel = 0;
    Tcl_Obj **windowObjv, *resultObj;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tk_MakeWindowExist((Tk_Window)winPtr);
	Tk_MakeWindowExist((Tk_Window) winPtr);
	resultObj = Tcl_NewObj();
	for (i = 0; i < wmPtr->cmapCount; i++) {
	    if ((i == (wmPtr->cmapCount-1))
		    && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
		break;
	    }
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    Tk_NewWindowObj((Tk_Window)wmPtr->cmapList[i]));
		    TkNewWindowObj((Tk_Window) wmPtr->cmapList[i]));
	}
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
    }
    if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
	    != TCL_OK) {
	return TCL_ERROR;
    }
    cmapList = (TkWindow **)ckalloc((windowObjc+1) * sizeof(TkWindow*));
    cmapList = ckalloc((windowObjc+1) * sizeof(TkWindow*));
    for (i = 0; i < windowObjc; i++) {
	if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
		(Tk_Window *) &winPtr2) != TCL_OK) {
	    ckfree(cmapList);
	    return TCL_ERROR;
	}
	if (winPtr2 == winPtr) {
	    gotToplevel = 1;
	}
	if (winPtr2->window == None) {
	    Tk_MakeWindowExist((Tk_Window)winPtr2);
	    Tk_MakeWindowExist((Tk_Window) winPtr2);
	}
	cmapList[i] = winPtr2;
    }
    if (!gotToplevel) {
	wmPtr->flags |= WM_ADDED_TOPLEVEL_COLORMAP;
	cmapList[windowObjc] = winPtr;
	windowObjc++;
    } else {
	wmPtr->flags &= ~WM_ADDED_TOPLEVEL_COLORMAP;
    }
    wmPtr->flags |= WM_COLORMAPS_EXPLICIT;
    if (wmPtr->cmapList != NULL) {
	ckfree(wmPtr->cmapList);
    }
    wmPtr->cmapList = cmapList;
    wmPtr->cmapCount = windowObjc;

    /*
     * On the Macintosh all of this is just an excercise in compatibility as
     * On the Macintosh all of this is just an excercise in compatability as
     * we don't support colormaps. If we did they would be installed here.
     */

    return TCL_OK;
}

/*
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
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604

1605
1606
1607


1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620

1621
1622
1623
1624
1625
1626
1627
1628







-
+


-
+


-
-
+
+











-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmCommandCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tcl_Size len;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int len;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->commandObj != NULL) {
	    Tcl_SetObjResult(interp, wmPtr->commandObj);
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
    if (Tcl_GetString(objv[3])[0] == 0) {
	if (wmPtr->commandObj != NULL) {
	    Tcl_DecrRefCount(wmPtr->commandObj);
	    wmPtr->commandObj = NULL;
	}
	return TCL_OK;
    }
    if (Tcl_ListObjLength(interp, objv[3], &len) != TCL_OK) {
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
1652
1653
1654
1655
1656
1657
1658

1659
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







-
+


-
+


-
+
-





+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmDeiconifyCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(winPtr->window);

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }

    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't deiconify %s: it is an icon for %s",
		Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "DEICONIFY", "ICON", NULL);
	return TCL_ERROR;
    } else if (winPtr->flags & TK_EMBEDDED) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't deiconify %s: it is an embedded window",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "DEICONIFY", "EMBEDDED", NULL);
	return TCL_ERROR;
    }

    TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
	    ZoomState : NormalState);
    [win setExcludedFromWindowsMenu:NO];
    TkMacOSXApplyWindowAttributes(winPtr, win);
    [win orderFront:NSApp];
    if (wmPtr->icon) {
	Tk_UnmapWindow((Tk_Window)wmPtr->icon);
    }

    /*
     * If this window has a transient, the transient must also be deiconified if
     * it was withdrawn by the container.
     */

    for (Transient *transientPtr = wmPtr->transientPtr;
	    transientPtr != NULL; transientPtr = transientPtr->nextPtr) {
	TkWindow *winPtr2 = transientPtr->winPtr;
	WmInfo *wmPtr2 = winPtr2->wmInfoPtr;
	TkWindow *containerPtr = (TkWindow *)TkMacOSXGetContainer(winPtr2);

    	if (containerPtr == winPtr) {
	    if ((wmPtr2->hints.initial_state == WithdrawnState) &&
		    ((transientPtr->flags & WITHDRAWN_BY_CONTAINER) != 0)) {
		TkpWmSetState(winPtr2, NormalState);
		transientPtr->flags &= ~WITHDRAWN_BY_CONTAINER;
	    }
	}
    }

    [[win contentView] setNeedsDisplay:YES];
    Tcl_DoWhenIdle(TkMacOSXDrawAllViews, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmFocusmodelCmd --
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
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







-
+


-
+


-
+












-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFocusmodelCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"active", "passive", NULL };
    enum options {
	OPT_ACTIVE, OPT_PASSIVE };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?active|passive?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		wmPtr->hints.input ? "passive" : "active", TCL_INDEX_NONE));
		wmPtr->hints.input ? "passive" : "active", -1));
	return TCL_OK;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
	    sizeof(char *), "argument", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
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
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







-
+

-
-
-
+
+
+

-
+







-
+










-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmForgetCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel or Frame to work with */
    TCL_UNUSED(Tcl_Interp *),	/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),			/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))	/* Argument objects. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window)winPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;

    if (Tk_IsTopLevel(frameWin)) {
	MacDrawable *macWin;

	Tk_MakeWindowExist(frameWin);
	Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);

	macWin = (MacDrawable *)winPtr->window;
	macWin = (MacDrawable *) winPtr->window;

    	TkFocusJoin(winPtr);
    	Tk_UnmapWindow(frameWin);

	macWin->toplevel->referenceCount--;
	macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel;
	macWin->toplevel->referenceCount++;
	macWin->flags &= ~TK_HOST_EXISTS;

	TkWmDeadWindow(winPtr);
	RemapWindows(winPtr, (MacDrawable *)winPtr->parentPtr->window);
	RemapWindows(winPtr, (MacDrawable *) winPtr->parentPtr->window);

        /*
         * Make sure wm no longer manages this window
         */
        Tk_ManageGeometry(frameWin, NULL, NULL);

	winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
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
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







-
+


-
+


-
+

-







-
+

-
-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFrameCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Window window;
    char buf[TCL_INTEGER_SPACE];

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    window = wmPtr->reparent;
    if (window == None) {
	window = Tk_WindowId((Tk_Window)winPtr);
	window = Tk_WindowId((Tk_Window) winPtr);
    }
    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)window);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("0x%x", (unsigned) window));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmGeometryCmd --
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
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







-
+


-
+


-
+
-
-
-
+
+







+
+









-
-
-
-
-
-
-
-
-
-
-
-

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGeometryCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    char xSign = '+', ySign = '+';
    int width, height, x = wmPtr->x, y= wmPtr->y;
    char xSign, ySign;
    int width, height;
    char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newGeometry?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	xSign = (wmPtr->flags & WM_NEGATIVE_X) ? '-' : '+';
	ySign = (wmPtr->flags & WM_NEGATIVE_Y) ? '-' : '+';
	if (wmPtr->gridWin != NULL) {
	    width = wmPtr->reqGridWidth + (winPtr->changes.width
		    - winPtr->reqWidth)/wmPtr->widthInc;
	    height = wmPtr->reqGridHeight + (winPtr->changes.height
		    - winPtr->reqHeight)/wmPtr->heightInc;
	} else {
	    width = winPtr->changes.width;
	    height = winPtr->changes.height;
	}
	if (win) {
	    if (wmPtr->flags & WM_NEGATIVE_X) {
		xSign = '-';
		x = wmPtr->vRootWidth - wmPtr->x
		    - (width + (wmPtr->parentWidth - winPtr->changes.width));
	    }
	    if (wmPtr->flags & WM_NEGATIVE_Y) {
		ySign = '-';
		y = wmPtr->vRootHeight - wmPtr->y
		    - (height + (wmPtr->parentHeight - winPtr->changes.height));
	    }
	}
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%dx%d%c%d%c%d",
		width, height, xSign, x, ySign, y));
		width, height, xSign, wmPtr->x, ySign, wmPtr->y));
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (*argv3 == '\0') {
	wmPtr->width = -1;
	wmPtr->height = -1;
	WmUpdateGeom(wmPtr, winPtr);
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
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







-
+


-
+


-
+

-
+










-
-
-
-
+
+
+
+










-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGridCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int reqWidth, reqHeight, widthInc, heightInc;
    const char *errorMsg;
    char *errorMsg;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?baseWidth baseHeight widthInc heightInc?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PBaseSize) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewWideIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewWideIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewWideIntObj(wmPtr->heightInc);
	    results[0] = Tcl_NewIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewIntObj(wmPtr->heightInc);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	/*
	 * Turn off gridding and reset the width and height to make sense as
	 * ungridded numbers.
	 */

	wmPtr->sizeHintsFlags &= ~PBaseSize;
	wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
	if (wmPtr->width != -1) {
	    wmPtr->width = winPtr->reqWidth + (wmPtr->width
		    - wmPtr->reqGridWidth)*wmPtr->widthInc;
	    wmPtr->height = winPtr->reqHeight + (wmPtr->height
		    - wmPtr->reqGridHeight)*wmPtr->heightInc;
	}
	wmPtr->widthInc = 1;
2754
2755
2756
2757
2758
2759
2760
2761

2762
2763
2764
2765
2766
2767
2768
2769

2770
2771
2772
2773
2774
2775
2776
1985
1986
1987
1988
1989
1990
1991

1992
1993
1994
1995
1996
1997
1998
1999

2000
2001
2002
2003
2004
2005
2006
2007







-
+







-
+







	} else if (widthInc <= 0) {
	    errorMsg = "widthInc can't be <= 0";
	    goto error;
	} else if (heightInc <= 0) {
	    errorMsg = "heightInc can't be <= 0";
	    goto error;
	}
	Tk_SetGrid((Tk_Window)winPtr, reqWidth, reqHeight, widthInc,
	Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
		heightInc);
    }
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;

  error:
    Tcl_SetObjResult(interp, Tcl_NewStringObj(errorMsg, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(errorMsg, -1));
    Tcl_SetErrorCode(interp, "TK", "WM", "GRID", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
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
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







-
+


-
+


-
+







-
+







 */

static int
WmGroupCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    char *argv3;
    Tcl_Size length;
    int length;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & WindowGroupHint) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, -1));
	}
	return TCL_OK;
    }

    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    if (*argv3 == '\0') {
	wmPtr->hints.flags &= ~WindowGroupHint;
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
2056
2057
2058
2059
2060
2061
2062

2063
2064
2065




































































2066
2067
2068
2069
2070
2071
2072







-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	}
	Tk_MakeWindowExist(tkwin2);
	if (wmPtr->leaderName != NULL) {
	    ckfree(wmPtr->leaderName);
	}
	wmPtr->hints.window_group = Tk_WindowId(tkwin2);
	wmPtr->hints.flags |= WindowGroupHint;
	wmPtr->leaderName = (char *)ckalloc(length + 1);
	wmPtr->leaderName = ckalloc(length + 1);
	strcpy(wmPtr->leaderName, argv3);
    }
    return TCL_OK;
}

 /*----------------------------------------------------------------------
 *
 * WmIconbadgeCmd --
 *
 *	This procedure is invoked to process the "wm iconbadge" Tcl command.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbadgeCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    (void) winPtr;
    NSString *label;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv,"window badge");
	return TCL_ERROR;
    }

    label = [NSString stringWithUTF8String:Tcl_GetString(objv[3])];

    int number = [label intValue];
    NSDockTile *dockicon = [NSApp dockTile];

    /*
     * First, check that the label is not a decimal. If it is,
     * return an error.
     */

    if ([label containsString:@"."]) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't use \"%s\" as icon badge", Tcl_GetString(objv[3])));
	return TCL_ERROR;
    }

    /*
     * Next, check that label is an int, empty string, or exclamation
     * point. If so, set the icon badge on the Dock icon. Otherwise,
     * return an error.
     */

    NSArray *array = @[@"", @"!"];
    if ([array containsObject: label]) {
	[dockicon setBadgeLabel:label];
    } else if (number > 0) {
	NSString *str = [@(number) stringValue];
	[dockicon setBadgeLabel:str];
    } else {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't use \"%s\" as icon badge", Tcl_GetString(objv[3])));
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconbitmapCmd --
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
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







-
+


-
+


-
+


-
+















-
+




-
+









-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbitmapCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Pixmap pixmap;
    char *str;
    Tcl_Size len;
    int len;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & IconPixmapHint) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    Tk_NameOfBitmap(winPtr->display,wmPtr->hints.icon_pixmap),
		    -1));
	}
	return TCL_OK;
    }
    str = Tcl_GetStringFromObj(objv[3], &len);
    if (winPtr->window == None) {
	Tk_MakeWindowExist((Tk_Window)winPtr);
	Tk_MakeWindowExist((Tk_Window) winPtr);
    }
    if (!TkMacOSXHostToplevelExists(winPtr)) {
	TkMacOSXMakeRealWindowExist(winPtr);
    }
    if (WmSetAttribute(winPtr, TkMacOSXGetNSWindowForDrawable(winPtr->window), interp,
    if (WmSetAttribute(winPtr, TkMacOSXDrawableWindow(winPtr->window), interp,
	    WMATT_TITLEPATH, objv[3]) == TCL_OK) {
	if (!len) {
	    if (wmPtr->hints.icon_pixmap != None) {
		Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
		wmPtr->hints.icon_pixmap = None;
	    }
	    wmPtr->hints.flags &= ~IconPixmapHint;
	}
    } else {
	pixmap = Tk_GetBitmap(interp, (Tk_Window)winPtr, Tk_GetUid(str));
	pixmap = Tk_GetBitmap(interp, (Tk_Window) winPtr, Tk_GetUid(str));
	if (pixmap == None) {
	    return TCL_ERROR;
	}
	wmPtr->hints.icon_pixmap = pixmap;
	wmPtr->hints.flags |= IconPixmapHint;
    }
    return TCL_OK;
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
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







-
+


-
+


-
+





-
+






-
+






-
+





-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconifyCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }

    if (Tk_Attributes((Tk_Window)winPtr)->override_redirect) {
    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": override-redirect flag is set",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "OVERRIDE_REDIRECT",
		NULL);
	return TCL_ERROR;
    } else if (wmPtr->container != NULL) {
    } else if (wmPtr->master != None) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is a transient", winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "TRANSIENT", NULL);
	return TCL_ERROR;
    } else if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is an icon for \"%s\"",
		"can't iconify %s: it is an icon for %s",
		winPtr->pathName, Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "ICON", NULL);
	return TCL_ERROR;
    } else if (winPtr->flags & TK_EMBEDDED) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is an embedded window",
		"can't iconify %s: it is an embedded window",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "EMBEDDED", NULL);
	return TCL_ERROR;
    }

    TkpWmSetState(winPtr, IconicState);
    if (wmPtr->icon) {
	Tk_MapWindow((Tk_Window)wmPtr->icon);
    }

    /*
     * If this window has a transient the transient must be withdrawn when
     * the container is iconified.
     */

    for (Transient *transientPtr = wmPtr->transientPtr;
	    transientPtr != NULL; transientPtr = transientPtr->nextPtr) {
	TkWindow *winPtr2 = transientPtr->winPtr;
	TkWindow *containerPtr = (TkWindow *)TkMacOSXGetContainer(winPtr2);
    	if (containerPtr == winPtr &&
		winPtr2->wmInfoPtr->hints.initial_state != WithdrawnState) {
	    TkpWmSetState(winPtr2, WithdrawnState);
	    transientPtr->flags |= WITHDRAWN_BY_CONTAINER;
	}
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconmaskCmd --
3071
3072
3073
3074
3075
3076
3077
3078

3079
3080
3081

3082
3083
3084
3085
3086
3087
3088
2214
2215
2216
2217
2218
2219
2220

2221
2222
2223

2224
2225
2226
2227
2228
2229
2230
2231







-
+


-
+







 */

static int
WmIconmaskCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Pixmap pixmap;
    char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
	return TCL_ERROR;
    }
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
3171
3172
3173
3174


3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191

3192
3193
3194
3195


3196
3197
3198
3199
3200

3201
3202
3203
3204
3205
3206
3207
3208

3209
3210
3211
3212
3213
3214
3215
3216
3217
3218


3219
3220
3221
3222
3223
3224
3225










3226
3227
3228
3229


3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
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







-
+


-
+


-
+

-
+







-
+








-
+













-
+
+






-









-
+


-
-
+
+
-



-
+


-
-
-
-
-

+








-
-
+
+


-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconnameCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size length;
    int length;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->iconName != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->iconName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->iconName, -1));
	}
	return TCL_OK;
    }

    if (wmPtr->iconName != NULL) {
	ckfree(wmPtr->iconName);
    }
    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    wmPtr->iconName = (char *)ckalloc(length + 1);
    wmPtr->iconName = ckalloc(length + 1);
    strcpy(wmPtr->iconName, argv3);
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconphotoCmd --
 *
 *	This procedure is invoked to process the "wm iconphoto" Tcl command.
 *	See the user documentation for details on what it does.
 *	See the user documentation for details on what it does. Not yet
 *	implemented for OS X.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *
 *----------------------------------------------------------------------
 */

static int
WmIconphotoCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Image tk_icon;
    int width, height;
    Tk_PhotoHandle photo;
    int i, width, height, isDefault = 0;
    NSImage *newIcon = NULL;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv,
			 "window ?-default? image1 ?image2 ...?");
		"window ?-default? image1 ?image2 ...?");
	return TCL_ERROR;
    }

    /*
     * Parse args.
     */

    if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) {
	isDefault = 1;
	if (objc == 4) {
	    Tcl_WrongNumArgs(interp, 2, objv,
		    "window ?-default? image1 ?image2 ...?");
	    return TCL_ERROR;
	}
    }

    /*
     * Get icon name. We only use the first icon name because macOS does not
     * support multiple images in Tk photos.
     * Iterate over all images to retrieve their sizes, in order to allocate a
     * buffer large enough to hold all images.
     */

    char *icon;
    if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) {
	icon = Tcl_GetString(objv[4]);
    } else {
	icon = Tcl_GetString(objv[3]);
    for (i = 3 + isDefault; i < objc; i++) {
	photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
	if (photo == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't use \"%s\" as iconphoto: not a photo image",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL);
	    return TCL_ERROR;
	}
	Tk_PhotoGetSize(photo, &width, &height);
    }

    /*
     * Get image and convert to NSImage that can be displayed as icon.
     * TODO: This requires implementation for OS X, but we silently return for
     * now.
     */

    tk_icon = Tk_GetImage(interp, tkwin, icon, NULL, NULL);
    if (tk_icon == NULL) {
    	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	      "can't use \"%s\" as iconphoto: not a photo image",
	      icon));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL);
	return TCL_ERROR;
    }

    Tk_SizeOfImage(tk_icon, &width, &height);
    if (width != 0 && height != 0) {
	newIcon = TkMacOSXGetNSImageFromTkImage(winPtr->display, tk_icon,
						width, height);
    }
    Tk_FreeImage(tk_icon);
    if (newIcon == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "failed to create an iconphoto with image \"%s\"", icon));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL);
	return TCL_ERROR;
    }
    [NSApp setApplicationIconImage: newIcon];
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconpositionCmd --
3269
3270
3271
3272
3273
3274
3275
3276

3277
3278
3279

3280
3281
3282

3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295


3296
3297
3298
3299
3300
3301
3302
3303
3304
3305

3306
3307
3308
3309
3310
3311
3312
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







-
+


-
+


-
+











-
-
+
+









-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconpositionCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?x y?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	if (wmPtr->hints.flags & IconPositionHint) {
	    Tcl_Obj *results[2];

	    results[0] = Tcl_NewWideIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->hints.icon_y);
	    results[0] = Tcl_NewIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewIntObj(wmPtr->hints.icon_y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	}
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->hints.flags &= ~IconPositionHint;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
	    || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){
	    return TCL_ERROR;
	}
	wmPtr->hints.icon_x = x;
	wmPtr->hints.icon_y = y;
	wmPtr->hints.flags |= IconPositionHint;
    }
    return TCL_OK;
3330
3331
3332
3333
3334
3335
3336
3337

3338
3339
3340

3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351

3352
3353
3354
3355
3356
3357
3358
3359

3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376

3377
3378
3379
3380
3381
3382
3383
3384
3385
3386

3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402

3403
3404
3405

3406
3407
3408
3409
3410
3411

3412
3413
3414
3415
3416
3417
3418
3419
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







-
+


-
+










-
+







-
+
















-
+








-
-
+
-

-
-
-
-
-
-
-






-
+


-
+
-


-
-
-
+
-







 */

static int
WmIconwindowCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    WmInfo *wmPtr2;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	if (wmPtr->icon != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj(wmPtr->icon));
	    Tcl_SetObjResult(interp, TkNewWindowObj(wmPtr->icon));
	}
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->hints.flags &= ~IconWindowHint;
	if (wmPtr->icon != NULL) {
	    wmPtr2 = ((TkWindow *)wmPtr->icon)->wmInfoPtr;
	    wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
	    wmPtr2->iconFor = NULL;
	    wmPtr2->hints.initial_state = WithdrawnState;
	}
	wmPtr->icon = NULL;
    } else {
	if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (!Tk_IsTopLevel(tkwin2)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't use %s as icon window: not at top level",
		    Tk_PathName(tkwin2)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONWINDOW", "TOPLEVEL",
		    NULL);
	    return TCL_ERROR;
	}
	wmPtr2 = ((TkWindow *)tkwin2)->wmInfoPtr;
	wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
	if (wmPtr2->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "%s is already an icon for %s",
		    Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONWINDOW", "ICON", NULL);
	    return TCL_ERROR;
	}
	if (wmPtr->icon != NULL) {
	    TkWindow *oldIcon = (TkWindow *)wmPtr->icon;
	    WmInfo *wmPtr3 = oldIcon->wmInfoPtr;
	    WmInfo *wmPtr3 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
	    NSWindow *win = TkMacOSXGetNSWindowForDrawable(oldIcon->window);

	    /*
	     * The old icon should be withdrawn.
	     */

	    TkpWmSetState(oldIcon, WithdrawnState);
	    [win orderOut:NSApp];
    	    [win setExcludedFromWindowsMenu:YES];
	    wmPtr3->iconFor = NULL;
	}
	Tk_MakeWindowExist(tkwin2);
	wmPtr->hints.icon_window = Tk_WindowId(tkwin2);
	wmPtr->hints.flags |= IconWindowHint;
	wmPtr->icon = tkwin2;
	wmPtr2->iconFor = (Tk_Window)winPtr;
	wmPtr2->iconFor = (Tk_Window) winPtr;
	if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
	    /*
	     * If the window is in normal or zoomed state, the icon should be
	     * Don't have iconwindows on the Mac. We just withdraw.
	     * unmapped.
	     */

	    if (wmPtr->hints.initial_state == NormalState ||
		    wmPtr->hints.initial_state == ZoomState) {
		Tk_UnmapWindow(tkwin2);
	    Tk_UnmapWindow(tkwin2);
	    }
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441





3442
3443
3444


3445
3446
3447

3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475


3476


3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
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







-
-
-
-
-
+
+
+
+
+

-
-
+
+


-
+









-
-
-
-
-
-
-
-
-
-
-
-





-
-
+
+

+
+










-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmManageCmd(
    TCL_UNUSED(Tk_Window),	        /* Main window of the application. */
    TkWindow *winPtr,           	/* Toplevel or Frame to work with */
    Tcl_Interp *interp,			/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),			/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))	/* Argument objects. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,           /* Toplevel or Frame to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window)winPtr;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!Tk_IsTopLevel(frameWin)) {
	MacDrawable *macWin = (MacDrawable *)winPtr->window;
	MacDrawable *macWin = (MacDrawable *) winPtr->window;

	if (!Tk_IsManageable(frameWin)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" is not manageable: must be a"
		    " frame, labelframe or toplevel",
		    Tk_PathName(frameWin)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "MANAGE", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Draw the managed widget at the top left corner of its toplevel.
	 * See [4a40c6cace].
	 */

	if (macWin) {
	    winPtr->changes.x -= macWin->xOff;
	    winPtr->changes.y -= macWin->yOff;
	    XMoveWindow(winPtr->display, winPtr->window, 0, 0);
	}

	TkFocusSplit(winPtr);
	Tk_UnmapWindow(frameWin);
	if (wmPtr == NULL) {
	    TkWmNewWindow(winPtr);
	    if (winPtr->window == None) {
		Tk_MakeWindowExist((Tk_Window)winPtr);
		macWin = (MacDrawable *)winPtr->window;
		Tk_MakeWindowExist((Tk_Window) winPtr);
		macWin = (MacDrawable *) winPtr->window;
	    }
	    TkWmMapWindow(winPtr);
	    Tk_UnmapWindow(frameWin);
	}
	wmPtr = winPtr->wmInfoPtr;
	winPtr->flags &= ~TK_MAPPED;
	macWin->toplevel->referenceCount--;
	macWin->toplevel = macWin;
	macWin->toplevel->referenceCount++;
	RemapWindows(winPtr, macWin);
	winPtr->flags |=
		(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
	TkMapTopFrame(frameWin);
	TkWmMapWindow(winPtr);
    } else if (Tk_IsTopLevel(frameWin)) {
	/* Already managed by wm - ignore it */
    }
    return TCL_OK;
}

/*
3506
3507
3508
3509
3510
3511
3512
3513

3514
3515
3516

3517
3518
3519

3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532


3533
3534
3535
3536
3537
3538


3539
3540
3541
3542
3543
3544
3545
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







-
+


-
+


-
+











-
-
+
+




-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmMaxsizeCmd(
    Tk_Window tkwin,	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	Tcl_Obj *results[2];

	GetMaxSize(winPtr, &width, &height);
	results[0] = Tcl_NewWideIntObj(width);
	results[1] = Tcl_NewWideIntObj(height);
	results[0] = Tcl_NewIntObj(width);
	results[1] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }

    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->maxWidth = width;
    wmPtr->maxHeight = height;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;
3563
3564
3565
3566
3567
3568
3569
3570

3571
3572
3573

3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586


3587
3588
3589
3590
3591
3592


3593
3594
3595
3596
3597
3598
3599
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







-
+


-
+











-
-
+
+




-
-
+
+







 */

static int
WmMinsizeCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	Tcl_Obj *results[2];

	GetMinSize(winPtr, &width, &height);
	results[0] = Tcl_NewWideIntObj(width);
	results[1] = Tcl_NewWideIntObj(height);
	results[0] = Tcl_NewIntObj(width);
	results[1] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }

    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->minWidth = width;
    wmPtr->minHeight = height;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;
3614
3615
3616
3617
3618
3619
3620
3621

3622
3623
3624

3625
3626
3627

3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638

3639
3640
3641
3642

3643
3644
3645
3646


3647
3648
3649
3650
3651
3652
3653
3654

3655
3656
3657
3658
3659
3660
3661
3662
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







-
+


-
+


-
+

-








-
+



-
+


-
-
+
+
-
-
-
-
-
-
-
-
+
-







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmOverrideredirectCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Bool boolValue;
    int boolean;
    XSetWindowAttributes atts;
    TKWindow *win = (TKWindow *)TkMacOSXGetNSWindowForDrawable(winPtr->window);

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		Tk_Attributes((Tk_Window)winPtr)->override_redirect));
		Tk_Attributes((Tk_Window) winPtr)->override_redirect));
	return TCL_OK;
    }

    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolValue) != TCL_OK) {
    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) {
	return TCL_ERROR;
    }
    atts.override_redirect = boolValue;
    Tk_ChangeWindowAttributes((Tk_Window)winPtr, CWOverrideRedirect, &atts);
    atts.override_redirect = (boolean) ? True : False;
    Tk_ChangeWindowAttributes((Tk_Window) winPtr, CWOverrideRedirect, &atts);
    if ([NSApp macOSVersion] >= 101300) {
	if (boolValue) {
	    win.styleMask |= NSWindowStyleMaskDocModalWindow;
	} else {
	    win.styleMask &= ~NSWindowStyleMaskDocModalWindow;
	}
    } else {
	ApplyContainerOverrideChanges(winPtr, win);
    ApplyMasterOverrideChanges(winPtr, NULL);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmPositionfromCmd --
3671
3672
3673
3674
3675
3676
3677
3678

3679
3680
3681

3682
3683
3684

3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698

3699
3700

3701
3702
3703
3704
3705
3706
3707
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







-
+


-
+


-
+













-
+

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmPositionfromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL };
    enum options {
	OPT_PROGRAM, OPT_USER };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user/program?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & USPosition) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("user", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("user", -1));
	} else if (wmPtr->sizeHintsFlags & PPosition) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("program", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("program", -1));
	}
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USPosition|PPosition);
    } else {
3737
3738
3739
3740
3741
3742
3743
3744

3745
3746
3747

3748
3749
3750
3751


3752
3753
3754

3755
3756
3757
3758
3759
3760
3761
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







-
+


-
+


-
-
+
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmProtocolCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    ProtocolHandler *protPtr, *prevPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    register ProtocolHandler *protPtr, *prevPtr;
    Atom protocol;
    char *cmd;
    Tcl_Size cmdLength;
    int cmdLength;
    Tcl_Obj *resultObj;

    if ((objc < 3) || (objc > 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name? ?command?");
	return TCL_ERROR;
    }

3770
3771
3772
3773
3774
3775
3776
3777

3778
3779
3780
3781
3782
3783
3784
3785
3786
3787

3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800

3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815

3816
3817
3818
3819
3820

3821
3822
3823
3824
3825
3826
3827
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







-
+









-
+












-
+














-
+




-
+







	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    Tk_GetAtomName((Tk_Window)winPtr, protPtr->protocol),-1));
	}
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
    }

    protocol = Tk_InternAtom((Tk_Window)winPtr, Tcl_GetString(objv[3]));
    protocol = Tk_InternAtom((Tk_Window) winPtr, Tcl_GetString(objv[3]));
    if (objc == 4) {
	/*
	 * Return the command to handle a given protocol.
	 */

	for (protPtr = wmPtr->protPtr; protPtr != NULL;
		protPtr = protPtr->nextPtr) {
	    if (protPtr->protocol == protocol) {
		Tcl_SetObjResult(interp,
			Tcl_NewStringObj(protPtr->command, TCL_INDEX_NONE));
			Tcl_NewStringObj(protPtr->command, -1));
		return TCL_OK;
	    }
	}
	return TCL_OK;
    }

    /*
     * Delete any current protocol handler, then create a new one with the
     * specified command, unless the command is empty.
     */

    for (protPtr = wmPtr->protPtr, prevPtr = NULL; protPtr != NULL;
	    prevPtr = protPtr, protPtr = protPtr->nextPtr) {
	prevPtr = protPtr, protPtr = protPtr->nextPtr) {
	if (protPtr->protocol == protocol) {
	    if (prevPtr == NULL) {
		wmPtr->protPtr = protPtr->nextPtr;
	    } else {
		prevPtr->nextPtr = protPtr->nextPtr;
	    }
	    if (protPtr->command)
		ckfree(protPtr->command);
	    Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
	    break;
	}
    }
    cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
    if (cmdLength > 0) {
	protPtr = (ProtocolHandler *)ckalloc(sizeof(ProtocolHandler));
	protPtr = ckalloc(sizeof(ProtocolHandler));
	protPtr->protocol = protocol;
	protPtr->nextPtr = wmPtr->protPtr;
	wmPtr->protPtr = protPtr;
	protPtr->interp = interp;
	protPtr->command = (char *)ckalloc(cmdLength+1);
	protPtr->command = ckalloc(cmdLength+1);
	strcpy(protPtr->command, cmd);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
3838
3839
3840
3841
3842
3843
3844
3845

3846
3847
3848

3849
3850
3851

3852
3853
3854
3855
3856
3857
3858
2927
2928
2929
2930
2931
2932
2933

2934
2935
2936

2937
2938
2939

2940
2941
2942
2943
2944
2945
2946
2947







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmResizableCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;
    UInt64 oldAttributes = wmPtr->attributes;
    int oldFlags = wmPtr->flags;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
3915
3916
3917
3918
3919
3920
3921
3922

3923
3924
3925

3926
3927
3928

3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942

3943
3944

3945
3946
3947
3948
3949
3950
3951
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







-
+


-
+


-
+













-
+

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmSizefromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL };
    enum options {
	OPT_PROGRAM, OPT_USER };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user|program?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & USSize) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("user", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("user", -1));
	} else if (wmPtr->sizeHintsFlags & PSize) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("program", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("program", -1));
	}
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USSize|PSize);
    } else {
3984
3985
3986
3987
3988
3989
3990
3991

3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019












4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
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







-
+



















-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-







 */

static int
WmStackorderCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkWindow **windows, **windowPtr;
    static const char *const optionStrings[] = {
	"isabove", "isbelow", NULL
    };
    enum options {
	OPT_ISABOVE, OPT_ISBELOW
    };
    Tcl_Obj *resultObj;
    int index;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?isabove|isbelow window?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	windows = TkWmStackorderToplevel(winPtr);
	if (windows != NULL) {
	    resultObj = Tcl_NewObj();
	    for (windowPtr = windows; *windowPtr ; windowPtr++) {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tk_NewWindowObj((Tk_Window)*windowPtr));
	    }
	    Tcl_SetObjResult(interp, resultObj);
	    ckfree(windows);
	    return TCL_OK;
	if (windows == NULL) {
	    Tcl_Panic("TkWmStackorderToplevel failed");
	}

	resultObj = Tcl_NewObj();
	for (windowPtr = windows; *windowPtr ; windowPtr++) {
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    TkNewWindowObj((Tk_Window) *windowPtr));
	}
	Tcl_SetObjResult(interp, resultObj);
	ckfree(windows);
	return TCL_OK;
	} else {
	    return TCL_ERROR;
	}
    } else {
	TkWindow *winPtr2;
	int index1 = -1, index2 = -1, result;

	if (TkGetWindowFromObj(interp, tkwin, objv[4], (Tk_Window *) &winPtr2)
		!= TCL_OK) {
	    return TCL_ERROR;
4053
4054
4055
4056
4057
4058
4059
4060

4061
4062
4063
4064
4065
4066
4067
3142
3143
3144
3145
3146
3147
3148

3149
3150
3151
3152
3153
3154
3155
3156







-
+







	 * Lookup stacking order of all toplevels that are children of "." and
	 * find the position of winPtr and winPtr2 in the stacking order.
	 */

	windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
	if (windows == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "TkWmStackorderToplevel failed", TCL_INDEX_NONE));
		    "TkWmStackorderToplevel failed", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "STACK", "FAIL", NULL);
	    return TCL_ERROR;
	}

	for (windowPtr = windows; *windowPtr ; windowPtr++) {
	    if (*windowPtr == winPtr) {
		index1 = windowPtr - windows;
4107
4108
4109
4110
4111
4112
4113
4114

4115
4116
4117

4118
4119
4120

4121
4122

4123
4124

4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135

4136
4137
4138
4139
4140
4141
4142

4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154

4155
4156
4157
4158
4159
4160
4161
4162
4163
4164


4165
4166
4167
4168
4169
4170
4171
4172

4173
4174
4175
4176
4177
4178
4179
4180
4181
4182

4183
4184
4185

4186
4187
4188
4189
4190

4191
4192
4193
4194
4195
4196
4197
4198
4199

4200
4201
4202

4203
4204
4205

4206
4207
4208

4209
4210
4211
4212
4213
4214
4215
3196
3197
3198
3199
3200
3201
3202

3203
3204
3205

3206
3207
3208

3209
3210

3211
3212

3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223

3224
3225
3226
3227
3228
3229
3230

3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241


3242
3243
3244
3245
3246
3247
3248




3249
3250
3251
3252
3253
3254
3255
3256
3257

3258
3259
3260
3261
3262
3263
3264
3265
3266


3267
3268


3269
3270

3271
3272

3273
3274
3275
3276
3277
3278
3279
3280
3281

3282
3283
3284

3285
3286
3287

3288
3289
3290

3291
3292
3293
3294
3295
3296
3297
3298







-
+


-
+


-
+

-
+

-
+










-
+






-
+










-
-
+






-
-
-
-
+
+







-
+








-
-
+

-
-
+

-


-
+








-
+


-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmStateCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"iconic", "normal", "withdrawn", "zoomed", NULL };
	"normal", "iconic", "withdrawn", "zoomed", NULL };
    enum options {
	OPT_ICONIC, OPT_NORMAL, OPT_WITHDRAWN, OPT_ZOOMED };
	OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN, OPT_ZOOMED };
    int index;

    if ((objc < 3) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?state?");
	return TCL_ERROR;
    }

    if (objc == 4) {
	if (wmPtr->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't change state of \"%s\": it is an icon for \"%s\"",
		    "can't change state of %s: it is an icon for %s",
		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "ICON", NULL);
	    return TCL_ERROR;
	}
	if (winPtr->flags & TK_EMBEDDED) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't change state of \"%s\": it is an embedded window",
		    "can't change state of %s: it is an embedded window",
		    winPtr->pathName));
	    Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "EMBEDDED", NULL);
	    return TCL_ERROR;
	}

	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}

	switch (index) {
	case OPT_NORMAL:
	if (index == OPT_NORMAL) {
	    TkpWmSetState(winPtr, NormalState);

	    /*
	     * This varies from 'wm deiconify' because it does not force the
	     * window to be raised and receive focus
	     */

	    break;
	case OPT_ICONIC:
	    if (Tk_Attributes((Tk_Window)winPtr)->override_redirect) {
	} else if (index == OPT_ICONIC) {
	    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": override-redirect flag is set",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE",
			"OVERRIDE_REDIRECT", NULL);
		return TCL_ERROR;
	    }
	    if (wmPtr->container != NULL) {
	    if (wmPtr->master != None) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": it is a transient",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "TRANSIENT",
			NULL);
		return TCL_ERROR;
	    }
	    TkpWmSetState(winPtr, IconicState);
	    break;
	case OPT_WITHDRAWN:
	} else if (index == OPT_WITHDRAWN) {
	    TkpWmSetState(winPtr, WithdrawnState);
	    break;
	default: /* OPT_ZOOMED */
	} else { /* OPT_ZOOMED */
	    TkpWmSetState(winPtr, ZoomState);
	    break;
	}
    } else if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("icon", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("icon", -1));
    } else {
	if (wmPtr->hints.initial_state == NormalState ||
		wmPtr->hints.initial_state == ZoomState) {
	    wmPtr->hints.initial_state = (TkMacOSXIsWindowZoomed(winPtr) ?
		    ZoomState : NormalState);
	}
	switch (wmPtr->hints.initial_state) {
	case NormalState:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("normal", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("normal", -1));
	    break;
	case IconicState:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("iconic", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("iconic", -1));
	    break;
	case WithdrawnState:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("withdrawn", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("withdrawn", -1));
	    break;
	case ZoomState:
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("zoomed", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("zoomed", -1));
	    break;
	}
    }
    return TCL_OK;
}

/*
4227
4228
4229
4230
4231
4232
4233
4234

4235
4236
4237

4238
4239
4240

4241
4242

4243
4244
4245
4246
4247
4248
4249
4250
4251

4252
4253
4254
4255
4256
4257
4258
3310
3311
3312
3313
3314
3315
3316

3317
3318
3319

3320
3321
3322

3323
3324

3325
3326
3327
3328
3329
3330
3331
3332
3333

3334
3335
3336
3337
3338
3339
3340
3341







-
+


-
+


-
+

-
+








-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmTitleCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    char *argv3;
    Tcl_Size length;
    int length;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newTitle?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		wmPtr->titleUid ? wmPtr->titleUid : winPtr->nameUid, TCL_INDEX_NONE));
		wmPtr->titleUid ? wmPtr->titleUid : winPtr->nameUid, -1));
	return TCL_OK;
    }

    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    wmPtr->titleUid = Tk_GetUid(argv3);
    if (!(wmPtr->flags & WM_NEVER_MAPPED) && !Tk_IsEmbedded(winPtr)) {
	TkSetWMName(winPtr, wmPtr->titleUid);
4278
4279
4280
4281
4282
4283
4284
4285

4286
4287
4288
4289


4290
4291

4292

4293
4294
4295

4296
4297
4298
4299

4300
4301

4302
4303
4304
4305
4306






4307
4308

4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320

4321
4322
4323
4324
4325
4326
4327
4328
4329
4330

4331
4332
4333

4334
4335
4336
4337
4338

4339
4340
4341
4342
4343
4344
4345
4346
4347


4348
4349
4350
4351
4352




4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394

4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405

4406
4407
4408

4409
4410
4411


4412
4413
4414


4415

4416
4417
4418
4419
4420


4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
3361
3362
3363
3364
3365
3366
3367

3368
3369
3370


3371
3372

3373
3374

3375
3376
3377

3378
3379
3380
3381

3382
3383

3384
3385
3386
3387


3388
3389
3390
3391
3392
3393
3394

3395
3396
3397










3398
3399
3400
3401
3402
3403
3404
3405
3406
3407

3408
3409


3410


3411
3412

3413
3414
3415
3416
3417
3418




3419
3420





3421
3422
3423
3424










































3425











3426



3427



3428
3429



3430
3431

3432
3433




3434
3435





















3436
3437
3438
3439
3440
3441
3442







-
+


-
-
+
+
-

+
-
+


-
+



-
+

-
+



-
-
+
+
+
+
+
+

-
+


-
-
-
-
-
-
-
-
-
-
+









-
+

-
-
+
-
-


-
+





-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
+
+
-
-
-
+
+
-
+

-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 */

static int
WmTransientCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window container;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window master;
    TkWindow *containerPtr, *w;
    WmInfo *wmPtr2;
    char *masterWindowName;
    Transient *transient;
    int length;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?window?");
	Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->container != NULL) {
	if (wmPtr->master != None) {
	    Tcl_SetObjResult(interp,
		Tcl_NewStringObj(Tk_PathName(wmPtr->container), TCL_INDEX_NONE));
		    Tcl_NewStringObj(wmPtr->masterWindowName, -1));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	RemoveTransient(winPtr);
    if (Tcl_GetString(objv[3])[0] == '\0') {
	wmPtr->master = None;
	if (wmPtr->masterWindowName != NULL) {
	    ckfree(wmPtr->masterWindowName);
	}
	wmPtr->masterWindowName = NULL;
    } else {
	if (TkGetWindowFromObj(interp, tkwin, objv[3], &container) != TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[3], &master) != TCL_OK) {
	    return TCL_ERROR;
	}
	RemoveTransient(winPtr);
	containerPtr = (TkWindow*) container;
	while (!Tk_TopWinHierarchy(containerPtr)) {
            /*
             * Ensure that the container window is actually a Tk toplevel.
             */

            containerPtr = containerPtr->parentPtr;
        }
	Tk_MakeWindowExist((Tk_Window)containerPtr);
	Tk_MakeWindowExist(master);

	if (wmPtr->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a transient: it is an icon for %s",
		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}

	wmPtr2 = containerPtr->wmInfoPtr;
	wmPtr2 = ((TkWindow *) master)->wmInfoPtr;

	/*
	 * Under some circumstances, wmPtr2 is NULL here.
	/* Under some circumstances, wmPtr2 is NULL here */
	 */

	if (wmPtr2 != NULL && wmPtr2->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a container: it is an icon for %s",
		    "can't make \"%s\" a master: it is an icon for %s",
		    Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}

	for (w = containerPtr; w != NULL && w->wmInfoPtr != NULL;
	    w = (TkWindow *)w->wmInfoPtr->container) {
	    if (w == winPtr) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	if ((TkWindow *) master == winPtr) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't set \"%s\" as container: would cause management loop",
		    Tk_PathName(containerPtr)));
		Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
		return TCL_ERROR;
	    }
		    "can't make \"%s\" its own master", Tk_PathName(winPtr)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
	    return TCL_ERROR;
	}
	}

	/*
	 * Add the transient to the container's list, if it not already there.
	 */

	for (transient = wmPtr2->transientPtr;
	     transient != NULL && transient->winPtr != winPtr;
	     transient = transient->nextPtr) {}
	if (transient == NULL) {
	    transient = (Transient *)ckalloc(sizeof(Transient));
	    transient->winPtr = winPtr;
	    transient->flags = 0;
	    transient->nextPtr = wmPtr2->transientPtr;
	    wmPtr2->transientPtr = transient;
	}

	/*
	 * If the container is withdrawn or iconic then withdraw the transient.
	 */

	if ((wmPtr2->hints.initial_state == WithdrawnState ||
		wmPtr2->hints.initial_state == IconicState) &&
		wmPtr->hints.initial_state != WithdrawnState) {
	    TkpWmSetState(winPtr, WithdrawnState);
	    transient->flags |= WITHDRAWN_BY_CONTAINER;
	}

	wmPtr->container = (Tk_Window)containerPtr;
    }
    ApplyContainerOverrideChanges(winPtr, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * RemoveTransient --
 *
 *      Clears the transient's container record and removes the transient from the
 *      container's list.
 *

 * Results:
 *	None
 *
 * Side effects:
 *      References to a container are removed from the transient's wmInfo
 *	structure and references to the transient are removed from its container's
 *	wmInfo.
 *
 *----------------------------------------------------------------------
 */

	wmPtr->master = Tk_WindowId(master);
static void
RemoveTransient(
    TkWindow *winPtr)
	masterWindowName = Tcl_GetStringFromObj(objv[3], &length);
{
    WmInfo *wmPtr = winPtr->wmInfoPtr, *wmPtr2;
    TkWindow *containerPtr;
	if (wmPtr->masterWindowName != NULL) {
	    ckfree(wmPtr->masterWindowName);
    Transient *transPtr, *temp;

    if (wmPtr == NULL || wmPtr->container == NULL) {
	}
	wmPtr->masterWindowName = ckalloc(length+1);
	return;
	strcpy(wmPtr->masterWindowName, masterWindowName);
    }
    containerPtr = (TkWindow *)wmPtr->container;
    wmPtr2 = containerPtr->wmInfoPtr;
    if (wmPtr2 == NULL) {
	return;
    ApplyMasterOverrideChanges(winPtr, NULL);
    return TCL_OK;
    }
    wmPtr->container= NULL;
    transPtr = wmPtr2->transientPtr;
    while (transPtr != NULL) {
	if (transPtr->winPtr != winPtr) {
	    break;
	}
	temp = transPtr->nextPtr;
	ckfree(transPtr);
	transPtr = temp;
    }
    wmPtr2->transientPtr = transPtr;
    while (transPtr != NULL) {
	if (transPtr->nextPtr && transPtr->nextPtr->winPtr == winPtr) {
	    temp = transPtr->nextPtr;
	    transPtr->nextPtr = temp->nextPtr;
	    ckfree(temp);
	} else {
	    transPtr = transPtr->nextPtr;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * WmWithdrawCmd --
 *
4456
4457
4458
4459
4460
4461
4462
4463

4464
4465
4466

4467
4468
4469

4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504

4505
4506
4507


4508
4509
4510
4511
4512
4513
4514
3450
3451
3452
3453
3454
3455
3456

3457
3458
3459

3460
3461
3462

3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476

3477

















3478
3479

3480
3481


3482
3483
3484
3485
3486
3487
3488
3489
3490







-
+


-
+


-
+













-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+

-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmWithdrawCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }

    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't withdraw %s: it is an icon for %s",
		Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "WITHDRAW", "ICON", NULL);
	return TCL_ERROR;
    }

    TkpWmSetState(winPtr, WithdrawnState);

    /*
     * If this window has a transient, the transient must also be withdrawn.
     */

    for (Transient *transientPtr = wmPtr->transientPtr;
	    transientPtr != NULL; transientPtr = transientPtr->nextPtr) {
	TkWindow *winPtr2 = transientPtr->winPtr;
	TkWindow *containerPtr = (TkWindow *)TkMacOSXGetContainer(winPtr2);

    	if (containerPtr == winPtr &&
		winPtr2->wmInfoPtr->hints.initial_state != WithdrawnState) {
	    TkpWmSetState(winPtr2, WithdrawnState);
	    transientPtr->flags |= WITHDRAWN_BY_CONTAINER;
	}
    }

    return TCL_OK;
}


/*
 * Invoked by those wm subcommands that affect geometry.  Schedules a geometry
 * update.
 * Invoked by those wm subcommands that affect geometry.
 * Schedules a geometry update.
 */

static void
WmUpdateGeom(
    WmInfo *wmPtr,
    TkWindow *winPtr)
{
4548
4549
4550
4551
4552
4553
4554
4555

4556
4557
4558
4559
4560
4561
4562
3524
3525
3526
3527
3528
3529
3530

3531
3532
3533
3534
3535
3536
3537
3538







-
+







    int reqWidth,		/* Width (in grid units) corresponding to the
				 * requested geometry for tkwin. */
    int reqHeight,		/* Height (in grid units) corresponding to the
				 * requested geometry for tkwin. */
    int widthInc, int heightInc)/* Pixel increments corresponding to a change
				 * of one grid unit. */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;

    /*
     * Ensure widthInc and heightInc are greater than 0
     */

    if (widthInc <= 0) {
4580
4581
4582
4583
4584
4585
4586
4587


4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599








4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617

4618
4619
4620
4621
4622
4623
4624
3556
3557
3558
3559
3560
3561
3562

3563
3564
3565
3566
3567
3568
3569







3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594

3595
3596
3597
3598
3599
3600
3601
3602







-
+
+





-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

















-
+







	return;
    }

    if ((wmPtr->reqGridWidth == reqWidth)
	    && (wmPtr->reqGridHeight == reqHeight)
	    && (wmPtr->widthInc == widthInc)
	    && (wmPtr->heightInc == heightInc)
	    && ((wmPtr->sizeHintsFlags & PBaseSize) == PBaseSize)) {
	    && ((wmPtr->sizeHintsFlags & (PBaseSize|PResizeInc))
		    == (PBaseSize|PResizeInc))) {
	return;
    }

    /*
     * If gridding was previously off, then forget about any window size
     * requests made by the user or via "wm geometry": these are in pixel units
     * and there's no easy way to translate them to grid units since the new
     * requested size of the top-level window in pixels may not yet have been
     * registered yet (it may filter up the hierarchy in DoWhenIdle handlers).
     * However, if the window has never been mapped yet then just leave the
     * window size alone: assume that it is intended to be in grid units but
     * just happened to have been specified before this procedure was called.
     * requests made by the user or via "wm geometry": these are in pixel
     * units and there's no easy way to translate them to grid units since the
     * new requested size of the top-level window in pixels may not yet have
     * been registered yet (it may filter up the hierarchy in DoWhenIdle
     * handlers). However, if the window has never been mapped yet then just
     * leave the window size alone: assume that it is intended to be in grid
     * units but just happened to have been specified before this procedure
     * was called.
     */

    if ((wmPtr->gridWin == NULL) && !(wmPtr->flags & WM_NEVER_MAPPED)) {
	wmPtr->width = -1;
	wmPtr->height = -1;
    }

    /*
     * Set the new gridding information, and start the process of passing all
     * of this information to the window manager.
     */

    wmPtr->gridWin = tkwin;
    wmPtr->reqGridWidth = reqWidth;
    wmPtr->reqGridHeight = reqHeight;
    wmPtr->widthInc = widthInc;
    wmPtr->heightInc = heightInc;
    wmPtr->sizeHintsFlags |= PBaseSize;
    wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
}

4641
4642
4643
4644
4645
4646
4647
4648

4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665

4666
4667
4668
4669
4670
4671
4672
3619
3620
3621
3622
3623
3624
3625

3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642

3643
3644
3645
3646
3647
3648
3649
3650







-
+
















-
+







 */

void
Tk_UnsetGrid(
    Tk_Window tkwin)		/* Token for window that is currently
				 * controlling gridding. */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;

    /*
     * Find the top-level window for tkwin, plus the window manager
     * information.
     */

    while (!(winPtr->flags & TK_TOP_LEVEL)) {
	winPtr = winPtr->parentPtr;
    }
    wmPtr = winPtr->wmInfoPtr;
    if (tkwin != wmPtr->gridWin) {
	return;
    }

    wmPtr->gridWin = NULL;
    wmPtr->sizeHintsFlags &= ~PBaseSize;
    wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
    if (wmPtr->width != -1) {
	wmPtr->width = winPtr->reqWidth + (wmPtr->width
		- wmPtr->reqGridWidth)*wmPtr->widthInc;
	wmPtr->height = winPtr->reqHeight + (wmPtr->height
		- wmPtr->reqGridHeight)*wmPtr->heightInc;
    }
    wmPtr->widthInc = 1;
4695
4696
4697
4698
4699
4700
4701
4702

4703
4704
4705

4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721

4722
4723
4724
4725
4726
4727
4728

4729
4730
4731
4732
4733
4734
4735
3673
3674
3675
3676
3677
3678
3679

3680
3681
3682

3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698

3699
3700
3701
3702
3703
3704
3705

3706
3707
3708
3709
3710
3711
3712
3713







-
+


-
+















-
+






-
+







 *	the structural change.
 *
 *----------------------------------------------------------------------
 */

static void
TopLevelEventProc(
    void *clientData,	/* Window for which event occurred. */
    ClientData clientData,	/* Window for which event occurred. */
    XEvent *eventPtr)		/* Event that just happened. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;

    winPtr->wmInfoPtr->flags |= WM_VROOT_OFFSET_STALE;
    if (eventPtr->type == DestroyNotify) {
	if (!(winPtr->flags & TK_ALREADY_DEAD)) {
	    /*
	     * A top-level window was deleted externally (e.g., by the window
	     * manager). This is probably not a good thing, but cleanup as
	     * best we can. The error handler is needed because
	     * Tk_DestroyWindow will try to destroy the window, but of course
	     * it's already gone.
	     */

	    Tk_ErrorHandler handler = Tk_CreateErrorHandler(winPtr->display,
		    -1, -1, -1, NULL, NULL);

	    Tk_DestroyWindow((Tk_Window)winPtr);
	    Tk_DestroyWindow((Tk_Window) winPtr);
	    Tk_DeleteErrorHandler(handler);
	}
	if (wmTracing) {
	    TkMacOSXDbgMsg("TopLevelEventProc: %s deleted", winPtr->pathName);
	}
    } else if (eventPtr->type == ReparentNotify) {
	Tcl_Panic("received unwanted reparent event");
	Tcl_Panic("recieved unwanted reparent event");
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TopLevelReqProc --
4743
4744
4745
4746
4747
4748
4749

4750
4751
4752

4753
4754
4755

4756
4757
4758
4759
4760
4761
4762
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730

3731
3732
3733

3734
3735
3736
3737
3738
3739
3740
3741







+


-
+


-
+







 * Side effects:
 *	Arrange for the window to be resized to satisfy the request (this
 *	happens as a when-idle action).
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
TopLevelReqProc(
    TCL_UNUSED(void *),		/* Not used. */
    ClientData dummy,		/* Not used. */
    Tk_Window tkwin)		/* Information about window. */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;

    wmPtr = winPtr->wmInfoPtr;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
4782
4783
4784
4785
4786
4787
4788
4789

4790
4791

4792
4793
4794
4795
4796
4797
4798
3761
3762
3763
3764
3765
3766
3767

3768
3769

3770
3771
3772
3773
3774
3775
3776
3777







-
+

-
+







 *	from happening.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateGeometryInfo(
    void *clientData)	/* Pointer to the window's record. */
    ClientData clientData)	/* Pointer to the window's record. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y, width, height, min, max;

    wmPtr->flags &= ~WM_UPDATE_PENDING;

    if (wmPtr->flags & WM_FULLSCREEN) {
	return;
4872
4873
4874
4875
4876
4877
4878










4879
4880











4881
4882
4883
4884
4885
4886
4887
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867


3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885







+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+







	max = wmPtr->maxHeight;
    }
    if (height < min) {
	height = min;
    } else if ((max > 0) && (height > max)) {
	height = max;
    }

    /*
     * Compute the new position for the upper-left pixel of the window's
     * decorative frame. This is tricky, because we need to include the border
     * widths supplied by a reparented parent in this calculation, but can't
     * use the parent's current overall size since that may change as a result
     * of this code.
     */

    if (wmPtr->flags & WM_NEGATIVE_X) {
    x = wmPtr->x;
    y = wmPtr->y;
	x = wmPtr->vRootWidth - wmPtr->x
	    - (width + (wmPtr->parentWidth - winPtr->changes.width));
    } else {
	x =  wmPtr->x;
    }
    if (wmPtr->flags & WM_NEGATIVE_Y) {
	y = wmPtr->vRootHeight - wmPtr->y
	    - (height + (wmPtr->parentHeight - winPtr->changes.height));
    } else {
	y =  wmPtr->y;
    }

    /*
     * If the window's size is going to change and the window is supposed to
     * not be resizable by the user, then we have to update the size hints.
     * There may also be a size-hint-update request pending from somewhere
     * else, too.
     */
4911
4912
4913
4914
4915
4916
4917
4918

4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935

4936
4937
4938
4939
4940
4941
4942
3909
3910
3911
3912
3913
3914
3915

3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932

3933
3934
3935
3936
3937
3938
3939
3940







-
+
















-
+







     *    This is because of "features" in some window managers (e.g. twm, as
     *    of 4/24/91) where they don't interpret coordinates according to
     *    ICCCM. Moving a window to its current location may cause it to shift
     *    position on the screen.
     */

    if (Tk_IsEmbedded(winPtr)) {
	Tk_Window contWinPtr = Tk_GetOtherWindow((Tk_Window)winPtr);
	TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);

	/*
	 * TODO: Here we should handle out of process embedding.
	 */

	if (contWinPtr != NULL) {
	    /*
	     * This window is embedded and the container is also in this
	     * process, so we don't need to do anything special about the
	     * geometry, except to make sure that the desired size is known by
	     * the container. Also, zero out any position information, since
	     * embedded windows are not allowed to move.
	     */

	    wmPtr->x = wmPtr->y = 0;
	    wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
	    Tk_GeometryRequest(contWinPtr, width, height);
	    Tk_GeometryRequest((Tk_Window) contWinPtr, width, height);
	}
	return;
    }
    if (wmPtr->flags & WM_MOVE_PENDING) {
	wmPtr->configWidth = width;
	wmPtr->configHeight = height;
	if (wmTracing) {
5034
5035
5036
5037
5038
5039
5040
5041
5042


5043
5044
5045
5046
5047
5048
5049
4032
4033
4034
4035
4036
4037
4038


4039
4040
4041
4042
4043
4044
4045
4046
4047







-
-
+
+







     * Parse the width and height, if they are present. Don't actually update
     * any of the fields of wmPtr until we've successfully parsed the entire
     * geometry string.
     */

    width = wmPtr->width;
    height = wmPtr->height;
    x = -1;
    y = -1;
    x = wmPtr->x;
    y = wmPtr->y;
    flags = wmPtr->flags;
    if (isdigit(UCHAR(*p))) {
	width = strtoul(p, &end, 10);
	p = end;
	if (*p != 'x') {
	    goto error;
	}
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125

5126
5127

5128
5129
5130

5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145









5146

5147
5148
5149
5150
5151
5152
5153
4097
4098
4099
4100
4101
4102
4103






4104
4105
4106
4107










4108


4109



4110















4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128







-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

+







	}
    }

    /*
     * Everything was parsed OK. Update the fields of *wmPtr and arrange for
     * the appropriate information to be percolated out to the window manager
     * at the next idle moment.
     *
     * Computing the new position for the upper-left pixel of the window's
     * decorative frame is tricky because we need to include the border
     * widths supplied by a reparented parent in the calculation, but we can't
     * use the parent's current overall size since that may change as a result
     * of this code.
     */

    wmPtr->width = width;
    wmPtr->height = height;
    if (flags & WM_NEGATIVE_X) {
	int borderwidth = wmPtr->parentWidth - winPtr->changes.width;
	int newWidth = width == -1 ? winPtr->changes.width : width;

	x = (x == -1) ?
		wmPtr->x + winPtr->changes.width - newWidth :
		wmPtr->vRootWidth - x - newWidth - borderwidth;
    }
    if (x == -1) {
	x = wmPtr->x;
    if ((x != wmPtr->x) || (y != wmPtr->y)
    }
    if (flags & WM_NEGATIVE_Y) {
	    || ((flags & (WM_NEGATIVE_X|WM_NEGATIVE_Y))
	int borderheight = wmPtr->parentHeight - winPtr->changes.height;
	int newHeight = height == -1 ? winPtr->changes.height : height;

		    != (wmPtr->flags & (WM_NEGATIVE_X|WM_NEGATIVE_Y)))) {
	y = (y == -1) ?
		wmPtr->y + winPtr->changes.height - newHeight :
		wmPtr->vRootHeight - y - newHeight - borderheight;
    }
    if (y == -1) {
	y = wmPtr->y;
    }
    if (wmPtr->flags & WM_FULLSCREEN) {
	wmPtr->configX = x;
	wmPtr->configY = y;
    } else {
	wmPtr->x = x;
	wmPtr->y = y;
    }
    flags |= WM_MOVE_PENDING;
	if (wmPtr->flags & WM_FULLSCREEN) {
	    wmPtr->configX = x;
	    wmPtr->configY = y;
	} else {
	    wmPtr->x = x;
	    wmPtr->y = y;
	}
	flags |= WM_MOVE_PENDING;
    }
    wmPtr->flags = flags;

    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
    return TCL_OK;

  error:
5181
5182
5183
5184
5185
5186
5187
5188

5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208

5209





















5210
5211
5212
5213
5214
5215
5216
5217
5218
5219









5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239


5240
5241
5242
5243
5244
5245
5246
4156
4157
4158
4159
4160
4161
4162

4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182

4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214

4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242

4243
4244
4245
4246
4247
4248
4249
4250
4251







-
+



















-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+
+
+
+
+
+
+
+
+



















-
+
+







void
Tk_GetRootCoords(
    Tk_Window tkwin,		/* Token for window. */
    int *xPtr,			/* Where to store x-displacement of (0,0). */
    int *yPtr)			/* Where to store y-displacement of (0,0). */
{
    int x, y;
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * Search back through this window's parents all the way to a top-level
     * window, combining the offsets of each window within its parent.
     */

    x = y = 0;
    while (1) {
	x += winPtr->changes.x + winPtr->changes.border_width;
	y += winPtr->changes.y + winPtr->changes.border_width;
	if (winPtr->flags & TK_TOP_LEVEL) {
	    TkWindow *otherPtr;

	    if (!(Tk_IsEmbedded(winPtr))) {
		x += winPtr->wmInfoPtr->xInParent;
		y += winPtr->wmInfoPtr->yInParent;
		break;
	    }

	    otherPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	    otherPtr = TkpGetOtherWindow(winPtr);
	    if (otherPtr == NULL) {
		if (tkMacOSXEmbedHandler->getOffsetProc != NULL) {
		    Point theOffset;

		    /*
		     * We do not require that the changes.x & changes.y for a
		     * non-Tk master window be kept up to date. So we first
		     * subtract off the possibly bogus values that have been
		     * added on at the top of this pass through the loop, and
		     * then call out to the getOffsetProc to give us the
		     * correct offset.
		     */

		    x -= winPtr->changes.x + winPtr->changes.border_width;
		    y -= winPtr->changes.y + winPtr->changes.border_width;

		    tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr,
			    &theOffset);

		    x += theOffset.h;
		    y += theOffset.v;
		}
		break;
	    }

	    /*
	     * The container window is in the same application. Query its
	     * coordinates.
	     */

	    winPtr = otherPtr;
            continue;

	    /*
	     * Remember to offset by the container window here, since at the
	     * end of this if branch, we will pop out to the container's
	     * parent...
	     */

	    x += winPtr->changes.x + winPtr->changes.border_width;
	    y += winPtr->changes.y + winPtr->changes.border_width;
	}
	winPtr = winPtr->parentPtr;
    }
    *xPtr = x;
    *yPtr = y;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_CoordsToWindow --
 *
 *	This is a Macintosh specific implementation of this function. Given
 *	the root coordinates of a point, this procedure returns the token for
 *	the top-most window covering that point, if there exists such a window
 *	in this application.
 *
 * Results:
 *	The return result is either a token for the window corresponding to
 *	rootX and rootY, or else NULL to indicate that there is no such window.
 *	rootX and rootY, or else NULL to indicate that there is no such
 *	window.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

5284
5285
5286
5287
5288
5289
5290
5291

5292
5293
5294
5295
5296
5297
5298
4289
4290
4291
4292
4293
4294
4295

4296
4297
4298
4299
4300
4301
4302
4303







-
+








	/*
	 * Container windows cannot have children. So if it is a container,
	 * look there, otherwise inspect the children.
	 */

	if (Tk_IsContainer(winPtr)) {
	    childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	    childPtr = TkpGetOtherWindow(winPtr);
	    if (childPtr != NULL) {
		if (Tk_IsMapped(childPtr)) {
		    tmpx = x - childPtr->changes.x;
		    tmpy = y - childPtr->changes.y;
		    bd = childPtr->changes.border_width;

		    if ((tmpx >= -bd) && (tmpy >= -bd)
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334

5335
5336
5337
5338
5339
5340
5341
4329
4330
4331
4332
4333
4334
4335




4336
4337
4338
4339
4340
4341
4342
4343







-
-
-
-
+







	    }
	}
	if (nextPtr == NULL) {
	    break;
	}
	winPtr = nextPtr;
    }
    if (winPtr->mainPtr != ((TkWindow *)tkwin)->mainPtr) {
	return NULL;
    }
    return (Tk_Window)winPtr;
    return (Tk_Window) winPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_TopCoordsToWindow --
 *
5365
5366
5367
5368
5369
5370
5371

5372
5373

5374
5375
5376
5377

5378
5379
5380
5381
5382
5383
5384
5385

5386
5387
5388
5389
5390
5391
5392
4367
4368
4369
4370
4371
4372
4373
4374
4375

4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388

4389
4390
4391
4392
4393
4394
4395
4396







+

-
+




+







-
+







    int *newX, int *newY)	/* Coordinates of point in the upperMost child
				 * of tkWin containing (rootX,rootY) */
{
    TkWindow *winPtr, *childPtr;
    TkWindow *nextPtr;		/* Coordinates of highest child found so far
				 * that contains point. */
    int x, y;			/* Coordinates in winPtr. */
    Window *children;		/* Children of winPtr, or NULL. */

    winPtr = (TkWindow *)tkwin;
    winPtr = (TkWindow *) tkwin;
    x = rootX;
    y = rootY;
    while (1) {
	nextPtr = NULL;
	children = NULL;

	/*
	 * Container windows cannot have children. So if it is a container,
	 * look there, otherwise inspect the children.
	 */

	if (Tk_IsContainer(winPtr)) {
	    childPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	    childPtr = TkpGetOtherWindow(winPtr);
	    if (childPtr != NULL) {
		if (Tk_IsMapped(childPtr) &&
			x > childPtr->changes.x &&
			x < childPtr->changes.x + childPtr->changes.width &&
			y > childPtr->changes.y &&
			y < childPtr->changes.y + childPtr->changes.height) {
		    nextPtr = childPtr;
5418
5419
5420
5421
5422
5423
5424
5425

5426
5427
5428
5429
5430
5431
5432
4422
4423
4424
4425
4426
4427
4428

4429
4430
4431
4432
4433
4434
4435
4436







-
+







	}
	winPtr = nextPtr;
	x -= winPtr->changes.x;
	y -= winPtr->changes.y;
    }
    *newX = x;
    *newY = y;
    return (Tk_Window)winPtr;
    return (Tk_Window) winPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateVRootGeometry --
 *
5519
5520
5521
5522
5523
5524
5525
5526

5527
5528
5529
5530
5531
5532
5533
4523
4524
4525
4526
4527
4528
4529

4530
4531
4532
4533
4534
4535
4536
4537







-
+







				 * queried. */
    int *xPtr, int *yPtr,	/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr,		/* Store dimensions of virtual root here. */
    int *heightPtr)
{
    WmInfo *wmPtr;
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * Find the top-level window for tkwin, and locate the window manager
     * information for that window.
     */

    while (!(winPtr->flags & TK_TOP_LEVEL)) {
5570
5571
5572
5573
5574
5575
5576
5577

5578
5579
5580
5581
5582
5583
5584
5585

5586
5587
5588
5589
5590
5591
5592
4574
4575
4576
4577
4578
4579
4580

4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597







-
+








+







 */

void
Tk_MoveToplevelWindow(
    Tk_Window tkwin,		/* Window to move. */
    int x, int y)		/* New location for window (within parent). */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!(winPtr->flags & TK_TOP_LEVEL)) {
	Tcl_Panic("Tk_MoveToplevelWindow called with non-toplevel window");
    }
    wmPtr->x = x;
    wmPtr->y = y;
    wmPtr->flags |= WM_MOVE_PENDING;
    wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
    if (!(wmPtr->sizeHintsFlags & (USPosition|PPosition))) {
	wmPtr->sizeHintsFlags |= USPosition;
	wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    }

    /*
     * If the window has already been mapped, must bring its geometry
5626
5627
5628
5629
5630
5631
5632
5633

5634
5635
5636
5637
5638
5639

5640
5641
5642

5643
5644
5645
5646
5647
5648

5649
5650
5651

5652
5653
5654



5655
5656



5657
5658
5659
5660
5661
5662

5663
5664
5665
5666
5667
5668
5669
5670



5671

5672
5673
5674






5675
5676
5677




5678
5679
5680



5681
5682
5683
5684
5685
5686
5687
4631
4632
4633
4634
4635
4636
4637

4638



4639
4640

4641
4642
4643

4644






4645

4646

4647
4648


4649
4650
4651
4652
4653
4654
4655
4656






4657








4658
4659
4660
4661
4662



4663
4664
4665
4666
4667
4668



4669
4670
4671
4672



4673
4674
4675
4676
4677
4678
4679
4680
4681
4682







-
+
-
-
-


-
+


-
+
-
-
-
-
-
-
+
-

-
+

-
-
+
+
+


+
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+

+
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+







    int aboveBelow,		/* Gives relative position for restacking;
				 * must be Above or Below. */
    TkWindow *otherPtr)		/* Window relative to which to restack; if
				 * NULL, then winPtr gets restacked above or
				 * below *all* siblings. */
{
    NSWindow *macWindow;
    NSWindow *otherMacWindow;
    NSInteger otherMacWindowNumber;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int macAboveBelow = (aboveBelow == Above ? NSWindowAbove : NSWindowBelow);
    int otherNumber = 0; /* 0 will be used when otherPtr is NULL. */

    /*
     * If the Tk windows has no drawable, or is withdrawn do nothing.
     * Get the mac window. Make sure it exists & is mapped.
     */

    if (winPtr->window == None ||
    if (winPtr->window == None) {
	    wmPtr == NULL      ||
	    wmPtr->hints.initial_state == WithdrawnState) {
	return;
    }
    macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    if (macWindow == nil) {
	Tk_MakeWindowExist((Tk_Window) winPtr);
	return;
    }
    if (otherPtr) {
    if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
	/*
	 * When otherPtr is non-NULL, if the other window has no drawable or is
	 * withdrawn, do nothing.
	 * Can't set stacking order properly until the window is on the screen
	 * (mapping it may give it a reparent window), so make sure it's on
	 * the screen.
	 */

	TkWmMapWindow(winPtr);
    }
    macWindow = TkMacOSXDrawableWindow(winPtr->window);
	WmInfo *otherWmPtr = otherPtr->wmInfoPtr;
	if (winPtr->window == None ||
		otherWmPtr == NULL ||
		otherWmPtr->hints.initial_state == WithdrawnState) {
	    return;
	}

	otherMacWindow = TkMacOSXGetNSWindowForDrawable(otherPtr->window);
	if (otherMacWindow == nil) {
	    return;
	}

	/*
	 * If the other window is OK, get its number.
	 */
    /*
     * Get the window in which a raise or lower is in relation to.
     */

    if (otherPtr != NULL) {
	otherNumber = [otherMacWindow windowNumber];
    }

	if (otherPtr->window == None) {
	    Tk_MakeWindowExist((Tk_Window) otherPtr);
	}
	if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
	    TkWmMapWindow(otherPtr);
	}
    /*
     * Just let the Mac window manager deal with all the subtleties of keeping
     * track of off-screen windows, etc.
	otherMacWindowNumber = [TkMacOSXDrawableWindow(otherPtr->window)
		windowNumber];
    } else {
	otherMacWindowNumber = 0;
     */

    [macWindow orderWindow:macAboveBelow relativeTo:otherNumber];
    }
    [macWindow orderWindow:(aboveBelow == Above ? NSWindowAbove : NSWindowBelow)
	    relativeTo:otherMacWindowNumber];
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmAddToColormapWindows --
 *
5745
5746
5747
5748
5749
5750
5751
5752

5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769

5770
5771
5772
5773
5774
5775
5776
4740
4741
4742
4743
4744
4745
4746

4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763

4764
4765
4766
4767
4768
4769
4770
4771







-
+
















-
+







    }

    /*
     * Make a new bigger array and use it to reset the property. Automatically
     * add the toplevel itself as the last element of the list.
     */

    newPtr = (TkWindow **)ckalloc((count+2) * sizeof(TkWindow *));
    newPtr = ckalloc((count+2) * sizeof(TkWindow *));
    if (count > 0) {
	memcpy(newPtr, oldPtr, count * sizeof(TkWindow *));
    }
    if (count == 0) {
	count++;
    }
    newPtr[count-1] = winPtr;
    newPtr[count] = topPtr;
    if (oldPtr != NULL) {
	ckfree(oldPtr);
    }

    topPtr->wmInfoPtr->cmapList = newPtr;
    topPtr->wmInfoPtr->cmapCount = count+1;

    /*
     * On the Macintosh all of this is just an excercise in compatibility as
     * On the Macintosh all of this is just an excercise in compatability as
     * we don't support colormaps. If we did they would be installed here.
     */
}

/*
 *----------------------------------------------------------------------
 *
5857
5858
5859
5860
5861
5862
5863
5864

5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879


5880
5881
5882
5883
5884
5885
5886
4852
4853
4854
4855
4856
4857
4858

4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872


4873
4874
4875
4876
4877
4878
4879
4880
4881







-
+













-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkGetPointerCoords(
    TCL_UNUSED(Tk_Window),	/* Toplevel window that identifies screen on
    Tk_Window tkwin,		/* Toplevel window that identifies screen on
				 * which lookup is to be done. */
    int *xPtr, int *yPtr)	/* Store pointer coordinates here. */
{
    XQueryPointer(NULL, None, NULL, NULL, xPtr, yPtr, NULL, NULL, NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * InitialWindowBounds --
 *
 *	This function calculates the initial bounds for a new Mac toplevel
 *	window. Unless the geometry is specified by the user this code will
 *	auto place the windows in a cascade diagonially across the main monitor
 *	of the Mac.
 *	auto place the windows in a cascade diagonially across the main
 *	monitor of the Mac.
 *
 * Results:
 *	Window bounds.
 *
 * Side effects:
 *	None.
 *
5897
5898
5899
5900
5901
5902
5903
5904

5905
5906
5907
5908
5909
5910
5911
4892
4893
4894
4895
4896
4897
4898

4899
4900
4901
4902
4903
4904
4905
4906







-
+







    if (!(wmPtr->sizeHintsFlags & (USPosition | PPosition))) {
	static NSPoint cascadePoint = { .x = 0, .y = 0 };
	NSRect frame;

	cascadePoint = [macWindow cascadeTopLeftFromPoint:cascadePoint];
	frame = [macWindow frame];
	wmPtr->x = frame.origin.x;
	wmPtr->y = TkMacOSXZeroScreenHeight() - (frame.origin.y +
	wmPtr->y = tkMacOSXZeroScreenHeight - (frame.origin.y +
		frame.size.height);
    }
    return NSMakeRect(wmPtr->x, wmPtr->y, winPtr->changes.width,
	    winPtr->changes.height);
}

/*
5965
5966
5967
5968
5969
5970
5971
5972
5973


5974
5975
5976
5977
5978
5979
5980
4960
4961
4962
4963
4964
4965
4966


4967
4968
4969
4970
4971
4972
4973
4974
4975







-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXGrowToplevel(
    TCL_UNUSED(void *),
    TCL_UNUSED(XPoint))
    void *whichWindow,
    XPoint start)
{
    return false;
}

/*
 *----------------------------------------------------------------------
 *
5997
5998
5999
6000
6001
6002
6003
6004
6005


6006
6007
6008
6009
6010
6011
6012

6013
6014
6015

6016
6017
6018

6019
6020
6021
6022
6023
6024
6025
6026
6027


6028
6029
6030
6031

6032
6033

6034
6035
6036
6037
6038
6039
6040
6041

6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060




6061


6062



6063
6064
6065
6066
6067
6068

6069
6070

6071
6072
6073
6074
6075
6076

6077
6078
6079
6080
6081
6082
6083
6084
6085
6086



6087
6088
6089


6090
6091
6092


6093
6094

6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106


6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122

6123
6124
6125
6126
6127
6128
6129
6130
4992
4993
4994
4995
4996
4997
4998


4999
5000
5001
5002
5003
5004
5005
5006

5007
5008
5009

5010
5011
5012

5013
5014
5015
5016
5017
5018
5019
5020


5021
5022
5023
5024
5025

5026
5027

5028
5029
5030
5031
5032
5033
5034
5035

5036

5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050




5051
5052
5053
5054
5055
5056
5057

5058
5059
5060
5061
5062
5063
5064
5065

5066
5067

5068


5069
5070


5071
5072
5073
5074
5075
5076
5077
5078



5079
5080
5081
5082


5083
5084



5085
5086


5087



5088
5089
5090
5091
5092
5093
5094


5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111

5112

5113
5114
5115
5116
5117
5118
5119







-
-
+
+






-
+


-
+


-
+







-
-
+
+



-
+

-
+







-
+
-














-
-
-
-
+
+
+
+

+
+
-
+
+
+





-
+

-
+
-
-


-
-
+







-
-
-
+
+
+

-
-
+
+
-
-
-
+
+
-
-
+
-
-
-







-
-
+
+















-
+
-







    TkWindow *winPtr,
    Tk_Uid titleUid)
{
    if (Tk_IsEmbedded(winPtr)) {
	return;
    }

    NSString *title = [[TKNSString alloc] initWithTclUtfBytes:titleUid length:TCL_INDEX_NONE];
    [TkMacOSXGetNSWindowForDrawable(winPtr->window) setTitle:title];
    NSString *title = [[NSString alloc] initWithUTF8String:titleUid];
    [TkMacOSXDrawableWindow(winPtr->window) setTitle:title];
    [title release];
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetContainer --
 * TkGetTransientMaster --
 *
 *	If the passed window has the TRANSIENT_FOR property set this will
 *	return the container window. Otherwise it will return None.
 *	return the master window. Otherwise it will return None.
 *
 * Results:
 *	The container window or None.
 *	The master window or None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
TkMacOSXGetContainer(
Window
TkGetTransientMaster(
    TkWindow *winPtr)
{
    if (winPtr->wmInfoPtr != NULL) {
	return (Tk_Window)winPtr->wmInfoPtr->container;
	return winPtr->wmInfoPtr->master;
    }
    return NULL;
    return None;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetXWindow --
 *
 *	Stub function that returns the X window Id associated with the
 *	Returns the X window Id associated with the given NSWindow*.
 *      given NSWindow*.
 *
 * Results:
 *	The window id is returned. None is returned if not a Tk window.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Window
TkMacOSXGetXWindow(
    void *macWinPtr)
{
    Window window = None;
    TKWindow *w = (TKWindow *)macWinPtr;
    if ([w respondsToSelector: @selector (tkWindow)]) {
	window = [w tkWindow];
    Tcl_HashEntry *hPtr;

    if (!macWinPtr || !windowHashInit) {
	return None;
    }
    hPtr = Tcl_FindHashEntry(&windowTable, macWinPtr);
    if (hPtr == NULL) {
    return window ? window : None;
	return None;
    }
    return (Window) Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXGetTkWindow --
 * TkMacOSXGetTkWindow --
 *
 *	Returns the Tk_Window associated with the given NSWindow*.  This
 *	Returns the TkWindow* associated with the given NSWindow*.
 *      function is a stub, so the NSWindow* parameter must be declared as
 *      void*.
 *
 * Results:
 *	A Tk_Window, or NULL if the NSWindow is not associated with
 *      any Tk window.
 *	The TkWindow* returned. NULL is returned if not a Tk window.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_MacOSXGetTkWindow(
    void *w)
TkWindow*
TkMacOSXGetTkWindow(
    NSWindow *w)
{
    Window window = None;
    if ([(NSWindow *)w respondsToSelector: @selector (tkWindow)]) {
    Window window = TkMacOSXGetXWindow(w);
    TkDisplay *dispPtr = TkGetDisplayList();
	window = [(TKWindow *)w tkWindow];
    }
    if (window) {

    return (window != None ?
	TkDisplay *dispPtr = TkGetDisplayList();
	return Tk_IdToWindow(dispPtr->display, window);
	    (TkWindow *)Tk_IdToWindow(dispPtr->display, window) : NULL);
    } else {
	return NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXIsWindowZoomed --
 *
 *	Ask Cocoa if the given window is in the zoomed out state. Because
 *	dragging & growing a window can change the Cocoa zoom state, we
 *	Ask Carbon if the given window is in the zoomed out state. Because
 *	dragging & growing a window can change the Carbon zoom state, we
 *	cannot rely on wmInfoPtr->hints.initial_state for this information.
 *
 * Results:
 *	True if window is zoomed out, false otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkMacOSXIsWindowZoomed(
    TkWindow *winPtr)
{
    NSWindow *macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    return [TkMacOSXDrawableWindow(winPtr->window) isZoomed];
    return [macWindow isZoomed];
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXZoomToplevel --
 *
6143
6144
6145
6146
6147
6148
6149
6150
6151


6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167

6168
6169
6170
6171
6172
6173

6174
6175
6176
6177
6178
6179
6180

6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194

6195
6196
6197

6198
6199
6200
6201
6202
6203

6204
6205
6206

6207
6208

6209
6210

6211
6212
6213
6214
6215










































6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233

6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246

6247
6248
6249
6250
6251
6252
6253

6254
6255
6256

6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
5132
5133
5134
5135
5136
5137
5138


5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155

5156
5157
5158
5159

5160

5161
5162
5163
5164
5165
5166
5167

5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185

5186
5187
5188
5189
5190
5191

5192
5193
5194

5195
5196

5197
5198

5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263

5264

5265
5266
5267
5268
5269







5270







5271



5272













5273
5274
5275
5276
5277
5278
5279







-
-
+
+















-
+



-

-
+






-
+














+


-
+





-
+


-
+

-
+

-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

















-
+
-





-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-







 */

int
TkMacOSXZoomToplevel(
    void *whichWindow,		/* The Macintosh window to zoom. */
    short zoomPart)		/* Either inZoomIn or inZoomOut */
{
    NSWindow *window = (NSWindow *)whichWindow;
    TkWindow *winPtr = (TkWindow *)TkMacOSXGetTkWindow(window);
    NSWindow *window = whichWindow;
    TkWindow *winPtr = TkMacOSXGetTkWindow(window);
    WmInfo *wmPtr;

    if (!winPtr || !winPtr->wmInfoPtr) {
	return false;
    }
    wmPtr = winPtr->wmInfoPtr;
    if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
	    (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
	return false;
    }

    /*
     * Do nothing if already in desired zoom state.
     */

    if (([window isZoomed] == (zoomPart == inZoomOut))) {
    if (![window isZoomed] == (zoomPart == inZoomIn)) {
	return false;
    }
    [window zoom:NSApp];

    wmPtr->hints.initial_state =
	(zoomPart == inZoomIn ? NormalState : ZoomState);
	    (zoomPart == inZoomIn ? NormalState : ZoomState);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkUnsupported1ObjCmd --
 * TkUnsupported1Cmd --
 *
 *	This procedure is invoked to process the
 *	"::tk::unsupported::MacWindowStyle" Tcl command. This command allows
 *	you to set the style of decoration for a Macintosh window.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	Changes the style of a new Mac window.
 *
 *----------------------------------------------------------------------
 */

/* ARGSUSED */
int
TkUnsupported1ObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    static const char *const subcmds[] = {
	"appearance", "isdark", "style", NULL
	"style", NULL
    };
    enum SubCmds {
	TKMWS_APPEARANCE, TKMWS_ISDARK, TKMWS_STYLE
	TKMWS_STYLE
    };
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    TkWindow *winPtr;
    int index;
    int index, i;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
	return TCL_ERROR;
    }

    /*
     * Iterate through objc/objv to set correct background color and toggle
     * opacity of window.
     */

    for (i= 0; i < objc; i++) {
    	if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*black*")) {
    	    colorName = [NSColor blackColor];	// use #000000 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*dark*")) {
    	    colorName = [NSColor darkGrayColor]; //use #545454 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*")) {
    	    colorName = [NSColor lightGrayColor]; //use #ababab in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*white*")) {
    	    colorName = [NSColor whiteColor];	//use #ffffff in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "gray*")) {
    	    colorName = [NSColor grayColor];	//use #7f7f7f in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*red*")) {
    	    colorName = [NSColor redColor];	//use #ff0000 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*green*")) {
    	    colorName = [NSColor greenColor];	//use #00ff00 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*blue*")) {
    	    colorName = [NSColor blueColor];	//use #0000ff in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*cyan*")) {
    	    colorName = [NSColor cyanColor];	//use #00ffff in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*yellow*")) {
    	    colorName = [NSColor yellowColor];	//use #ffff00 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*magenta*")) {
    	    colorName = [NSColor magentaColor];	//use #ff00ff in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*orange*")) {
    	    colorName = [NSColor orangeColor];	//use #ff8000 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*purple*")) {
    	    colorName = [NSColor purpleColor];	//use #800080 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*brown*")){
    	    colorName = [NSColor brownColor];	//use #996633 in Tk scripts to match
    	} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*clear*")) {
    	    colorName = [NSColor clearColor];	//use systemTransparent in Tk scripts to match
    	}
    	if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*opacity*")) {
    	    opaqueTag = YES;
    	}
    }

    winPtr = (TkWindow *)
	    Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }
    if (!(winPtr->flags & TK_TOP_LEVEL)) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"window \"%s\" isn't a top-level window", winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "TOPLEVEL", NULL);
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], subcmds,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    switch((enum SubCmds) index) {
    if (((enum SubCmds) index) == TKMWS_STYLE) {
    case TKMWS_STYLE:
	if ((objc < 3) || (objc > 5)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?class attributes?");
	    return TCL_ERROR;
	}
	return WmWinStyle(interp, winPtr, objc, objv);
    case TKMWS_APPEARANCE:
	if ([NSApp macOSVersion] < 100900) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
                "Window appearances did not exist until OSX 10.9.", TCL_INDEX_NONE));
	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
	    return TCL_ERROR;
	}
    }
	if ((objc < 3) || (objc > 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?appearancename?");
	    return TCL_ERROR;
	}
	if (objc == 4 && [NSApp macOSVersion] < 101400) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Window appearances cannot be changed before OSX 10.14.",
    /* won't be reached */
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
	    return TCL_ERROR;
    return TCL_ERROR;
	}
	return WmWinAppearance(interp, winPtr, objc, objv);
    case TKMWS_ISDARK:
	if ((objc != 3)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window");
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		TkMacOSXInDarkMode((Tk_Window)winPtr)));
	return TCL_OK;
    default:
	return TCL_ERROR;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * WmWinStyle --
 *
6287
6288
6289
6290
6291
6292
6293
6294

6295
6296
6297
6298
6299
6300
6301
5290
5291
5292
5293
5294
5295
5296

5297
5298
5299
5300
5301
5302
5303
5304







-
+







 *----------------------------------------------------------------------
 */

static int
WmWinStyle(
    Tcl_Interp *interp,		/* Current interpreter. */
    TkWindow *winPtr,		/* Window to be manipulated. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj * const objv[])	/* Argument objects. */
{
    struct StrIntMap {
	const char *strValue;
	UInt64 intValue;
    };
    static const struct StrIntMap classMap[] = {
6311
6312
6313
6314
6315
6316
6317
6318

6319
6320
6321
6322
6323
6324
6325

6326
6327
6328
6329
6330
6331
6332
5314
5315
5316
5317
5318
5319
5320

5321
5322
5323
5324
5325
5326
5327

5328
5329
5330
5331
5332
5333
5334
5335







-
+






-
+







	{ "toolbar",		kToolbarWindowClass			     },
	{ "plain",		kPlainWindowClass			     },
	{ "overlay",		kOverlayWindowClass			     },
	{ "sheetAlert",		kSheetAlertWindowClass			     },
	{ "altPlain",		kAltPlainWindowClass			     },
	{ "simple",		kSimpleWindowClass			     },
	{ "drawer",		kDrawerWindowClass			     },
	{ NULL, 0 }
	{ NULL }
    };
    static const struct StrIntMap compositeAttrMap[] = {
	{ "none",		kWindowNoAttributes			     },
	{ "standardDocument",	kWindowStandardDocumentAttributes	     },
	{ "standardFloating",	kWindowStandardFloatingAttributes	     },
	{ "fullZoom",		kWindowFullZoomAttribute		     },
	{ NULL, 0 }
	{ NULL }
    };

    /*
     * Map window attributes. Color and opacity are mapped to NULL; these are
     * parsed from the objv in TkUnsupported1ObjCmd.
     */

6355
6356
6357
6358
6359
6360
6361















6362

6363
6364
6365

6366
6367
6368
6369
6370
6371
6372
6373
6374
6375

6376
6377
6378
6379
6380
6381
6382
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379

5380
5381
5382

5383

5384
5385
5386
5387
5388
5389
5390
5391

5392
5393
5394
5395
5396
5397
5398
5399







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+


-
+
-








-
+







	{ "ignoreClicks",	kWindowIgnoreClicksAttribute		     },
	{ "noConstrain",	kWindowNoConstrainAttribute		     },
	{ "doesNotHide",	tkWindowDoesNotHideAttribute		     },
	{ "canJoinAllSpaces",	tkCanJoinAllSpacesAttribute		     },
	{ "moveToActiveSpace",	tkMoveToActiveSpaceAttribute		     },
	{ "nonActivating",	tkNonactivatingPanelAttribute		     },
	{ "hud",		tkHUDWindowAttribute			     },
	{ "black",		0			                     },
	{ "dark",		0			                     },
	{ "light",		0			                     },
	{ "gray",		0			                     },
	{ "red",		0 			                     },
	{ "green",		0                			     },
	{ "blue",		0           			             },
	{ "cyan",		0			                     },
	{ "yellow",		0			                     },
	{ "magenta",		0  			                     },
	{ "orange",		0 			                     },
	{ "purple",		0			                     },
	{ "brown",		0			                     },
	{ "clear",		0			                     },
	{ "opacity",		0			                     },
	{ NULL, 0 }
	{ NULL }
    };

    int index;
    int index, i;
    Tcl_Size i;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc == 3) {
	Tcl_Obj *attributeList, *newResult = NULL;
	UInt64 attributes;

	for (i = 0; classMap[i].strValue != NULL; i++) {
	    if (wmPtr->macClass == classMap[i].intValue) {
		newResult = Tcl_NewStringObj(classMap[i].strValue, TCL_INDEX_NONE);
		newResult = Tcl_NewStringObj(classMap[i].strValue, -1);
		break;
	    }
	}
	if (newResult == NULL) {
	    Tcl_Panic("invalid class");
	}

6393
6394
6395
6396
6397
6398
6399
6400

6401
6402
6403
6404
6405
6406

6407
6408
6409
6410
6411
6412
6413
5410
5411
5412
5413
5414
5415
5416

5417
5418
5419
5420
5421
5422

5423
5424
5425
5426
5427
5428
5429
5430







-
+





-
+







		attributes &= ~intValue;
		break;
	    }
	}
	for (i = 0; attrMap[i].strValue != NULL; i++) {
	    if (attributes & attrMap[i].intValue) {
		Tcl_ListObjAppendElement(NULL, attributeList,
			Tcl_NewStringObj(attrMap[i].strValue, TCL_INDEX_NONE));
			Tcl_NewStringObj(attrMap[i].strValue, -1));
	    }
	}
	Tcl_ListObjAppendElement(NULL, newResult, attributeList);
	Tcl_SetObjResult(interp, newResult);
    } else {
	Tcl_Size attrObjc;
	int attrObjc;
	Tcl_Obj **attrObjv = NULL;
	WindowClass macClass;
	UInt64 oldAttributes = wmPtr->attributes;
	int oldFlags = wmPtr->flags;

	if (Tcl_GetIndexFromObjStruct(interp, objv[3], classMap,
		sizeof(struct StrIntMap), "class", 0, &index) != TCL_OK) {
6437
6438
6439
6440
6441
6442
6443

6444
6445

6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473





































































































5474
5475
5476
5477
5478
5479
5480







+


+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	} else {
	    wmPtr->attributes = macClassAttrs[macClass].defaultAttrs;
	}
	wmPtr->attributes &= (tkAlwaysValidAttributes |
		macClassAttrs[macClass].validAttrs);
	wmPtr->flags |= macClassAttrs[macClass].flags;
	wmPtr->macClass = macClass;

	ApplyWindowAttributeFlagChanges(winPtr, NULL, oldAttributes, oldFlags,
		0, 1);

	return TCL_OK;

    badClassAttrs:
	wmPtr->attributes = oldAttributes;
	return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmWinAppearance --
 *
 *	This procedure is invoked to process the
 *	"::tk::unsupported::MacWindowStyle appearance" subcommand. The command
 *	allows you to get or set the appearance for the NSWindow associated
 *	with a Tk Window.  The syntax is:
 *
 *	    tk::unsupported::MacWindowStyle appearance window ?newAppearance?
 *
 *      Allowed appearance names are "aqua", "darkaqua", and "auto".
 *
 * Results:
 *      Returns the appearance setting of the window prior to calling this
 *	function.
 *
 * Side effects:
 *      The underlying NSWindow's appearance property is set to the specified
 *      value if the optional newAppearance argument is supplied. Otherwise the
 *      window's appearance property is not changed.  If the appearance is set
 *      to aqua or darkaqua then the window will use the associated
 *      NSAppearance even if the user has selected a different appearance with
 *      the system preferences.  If it is set to auto then the appearance
 *      property is set to nil, meaning that the preferences will determine the
 *      appearance.
 *
 *----------------------------------------------------------------------
 */

static int
WmWinAppearance(
    Tcl_Interp *interp,		/* Current interpreter. */
    TkWindow *winPtr,		/* Window to be manipulated. */
    Tcl_Size objc,			/* Number of arguments. */
    Tcl_Obj * const objv[])	/* Argument objects. */
{
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1090
    (void) interp;
    (void) winPtr;
    (void) objc;
    (void) objv;
    return TCL_OK;
#else
    Tcl_Obj *result = NULL;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
    NSAppearanceName appearance;
#else
    NSString *appearance;
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101300

    const char *resultString = "unrecognized";
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    if (win) {
	appearance = win.appearance.name;
	if (appearance == nil) {
	    resultString = appearanceStrings[APPEARANCE_AUTO];
	} else if (appearance == NSAppearanceNameAqua) {
	    resultString = appearanceStrings[APPEARANCE_AQUA];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	} else if (@available(macOS 10.14, *)) {
	    if (appearance == NSAppearanceNameDarkAqua) {
		resultString = appearanceStrings[APPEARANCE_DARKAQUA];
	    }
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	}
	result = Tcl_NewStringObj(resultString, strlen(resultString));
    }
    if (result == NULL) {
	NSLog(@"Failed to read appearance name; try calling update idletasks before getting/setting the appearance of the window.");
	return TCL_OK;
    }
    if (objc == 4) {
	int index;
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], appearanceStrings,
		sizeof(char *), "appearancename", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	switch ((enum appearances) index) {
	case APPEARANCE_AQUA:
	    win.appearance = [NSAppearance appearanceNamed:
		NSAppearanceNameAqua];
	    break;
	case APPEARANCE_DARKAQUA:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	    if (@available(macOS 10.14, *)) {
		win.appearance = [NSAppearance appearanceNamed:
		    NSAppearanceNameDarkAqua];
	    }
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	    break;
	default:
	    win.appearance = nil;
	}
    }
    Tcl_SetObjResult(interp, result);
    return TCL_OK;
#endif
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMakeMenuWindow --
 *
 *	Configure the window to be either a undecorated pull-down (or pop-up)
6575
6576
6577
6578
6579
6580
6581
6582

6583
6584
6585
6586
6587
6588
6589
5493
5494
5495
5496
5497
5498
5499

5500
5501
5502
5503
5504
5505
5506
5507







-
+







TkpMakeMenuWindow(
    Tk_Window tkwin,		/* New window. */
    int transient)		/* 1 means menu is only posted briefly as a
				 * popup or pulldown or cascade. 0 means menu
				 * is always visible, e.g. as a floating
				 * menu. */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;

    if (transient) {
	winPtr->wmInfoPtr->macClass = kSimpleWindowClass;
	winPtr->wmInfoPtr->attributes = kWindowNoActivatesAttribute;
    } else {
	winPtr->wmInfoPtr->macClass = kFloatingWindowClass;
	winPtr->wmInfoPtr->attributes = kWindowStandardFloatingAttributes;
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632

6633
6634
6635
6636


6637
6638
6639
6640

6641
6642
6643
6644
6645
6646
6647
6648

6649







6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722




6723
6724
6725
6726



6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
















6744
6745
6746
6747
6748

6749
6750
6751
6752
6753

6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790

6791

6792
6793

6794
6795
6796
6797
6798
6799


6800
6801
6802















6803
6804
6805
6806

6807
6808

6809
6810

6811
6812

6813
6814

6815

6816
6817
6818
6819
6820
6821
6822
6823
6824
6825

































6826
6827

6828
6829
6830
6831
6832
6833

6834
6835
6836


6837
6838
6839
6840

6841
6842
6843

6844
6845
6846
6847
6848
6849

6850
6851

6852
6853
6854

6855
6856
6857


6858
6859

6860
6861

6862
6863
6864
6865
6866
6867





6868
6869


6870
6871
6872
6873
6874
6875
6876
5529
5530
5531
5532
5533
5534
5535









5536
5537
5538
5539
5540

5541
5542
5543


5544
5545
5546
5547
5548

5549
5550
5551
5552
5553
5554
5555
5556
5557
5558

5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571



































































5572
5573
5574
5575
5576



5577
5578
5579
5580
















5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596

5597
5598
5599

5600
5601




5602
5603
5604
5605
5606












5607
5608















5609
5610
5611

5612
5613
5614
5615

5616
5617
5618
5619
5620


5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646

5647
5648

5649
5650

5651


5652
5653
5654










5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688

5689
5690
5691
5692
5693
5694

5695
5696


5697
5698

5699
5700

5701
5702
5703

5704
5705
5706
5707
5708
5709

5710


5711



5712



5713
5714


5715


5716





5717
5718
5719
5720
5721
5722


5723
5724
5725
5726
5727
5728
5729
5730
5731







-
-
-
-
-
-
-
-
-





-
+


-
-
+
+



-
+








+
-
+
+
+
+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-



-
+

-
-
-
-
+




-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+

+

-
+




-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




+

-
+

-
+

-
+
-
-
+

+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+





-
+

-
-
+
+
-


-
+


-
+





-
+
-
-
+
-
-
-
+
-
-
-
+
+
-
-
+
-
-
+
-
-
-
-
-

+
+
+
+
+
-
-
+
+








void
TkMacOSXMakeRealWindowExist(
    TkWindow *winPtr)		/* Tk window. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    MacDrawable *macWin;
    WindowClass macClass;
    Class winClass = nil;
    Bool overrideRedirect = Tk_Attributes((Tk_Window)winPtr)->override_redirect;
    Tcl_HashEntry *hPtr = NULL;
    NSUInteger styleMask;
    NSString *identifier;
    char *tabbingId = NULL;
    long tabbingMode = NSWindowTabbingModeAutomatic;
    static int initialized = 0;

    if (TkMacOSXHostToplevelExists(winPtr)) {
	return;
    }

    macWin = (MacDrawable *)winPtr->window;
    macWin = (MacDrawable *) winPtr->window;

    /*
     * If this is embedded, make sure its container's toplevel exists, then
     * return...
     * If this is embedded, make sure its container's toplevel exists,
     * then return...
     */

    if (Tk_IsEmbedded(winPtr)) {
	TkWindow *contWinPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)winPtr);
	TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);

	if (contWinPtr != NULL) {
	    TkMacOSXMakeRealWindowExist(
		    contWinPtr->privatePtr->toplevel->winPtr);
	    macWin->flags |= TK_HOST_EXISTS;
	    return;
	}

	if (tkMacOSXEmbedHandler == NULL) {
	Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container");
	    Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container");
	}
	if (tkMacOSXEmbedHandler->containerExistProc &&
		tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr)
		!= TCL_OK) {
	    Tcl_Panic("ContainerExistProc could not make container");
	}
	return;

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }

    if ([NSApp macOSVersion] >= 101300) {
	/*
	 * Prior to macOS 10.12 the styleMask was readonly.  From macOS 10.12
	 * onward, the styleMask can replace the Carbon window classes and
	 * attributes.
	 */
	int index;
	if (!initialized) {
	    Tcl_InitHashTable(&pathnameToSubclass, TCL_STRING_KEYS);
	    Tcl_InitHashTable(&pathnameToTabbingId, TCL_STRING_KEYS);
	    Tcl_InitHashTable(&pathnameToTabbingMode, TCL_STRING_KEYS);
	    initialized = 1;
	}
	hPtr = Tcl_FindHashEntry(&pathnameToSubclass, Tk_PathName(winPtr));
	index = hPtr ? PTR2INT(Tcl_GetHashValue(hPtr)) : subclassNSWindow;
	switch(index) {
	case subclassNSPanel:
	    winClass = [TKPanel class];
	    styleMask =  (NSWindowStyleMaskTitled        |
			  NSWindowStyleMaskClosable      |
			  NSWindowStyleMaskResizable     |
			  NSWindowStyleMaskUtilityWindow |
			  NSWindowStyleMaskNonactivatingPanel );
		break;
	default:
	    winClass = [TKWindow class];
	    styleMask =  (NSWindowStyleMaskTitled         |
			  NSWindowStyleMaskClosable       |
			  NSWindowStyleMaskMiniaturizable |
			  NSWindowStyleMaskResizable );
		break;
	}
	if (overrideRedirect) {
	    styleMask |= NSWindowStyleMaskDocModalWindow;
	}
	/* Help windows (used for tooltips) should have stylemask 0. */
	if (wmPtr->macClass == kHelpWindowClass) {
	    styleMask = 0;
	}
	if (hPtr) {
	    Tcl_DeleteHashEntry(hPtr);
	}
	hPtr = Tcl_FindHashEntry(&pathnameToTabbingId, Tk_PathName(winPtr));
	if (hPtr) {
	    tabbingId = (char *)Tcl_GetHashValue(hPtr);
	    Tcl_DeleteHashEntry(hPtr);
	}
	hPtr = Tcl_FindHashEntry(&pathnameToTabbingMode, Tk_PathName(winPtr));
	if (hPtr) {
	    tabbingMode = PTR2INT(Tcl_GetHashValue(hPtr));
	    Tcl_DeleteHashEntry(hPtr);
	}
    } else {

	/*
	 * If this is an override-redirect window, the NSWindow is created first as
	 * a document window then converted to a simple window.
	 */

	if (overrideRedirect) {
	    wmPtr->macClass = kDocumentWindowClass;
	}
	macClass = wmPtr->macClass;
	wmPtr->attributes &= (tkAlwaysValidAttributes |
			      macClassAttrs[macClass].validAttrs);
	wmPtr->flags |= macClassAttrs[macClass].flags |
    WindowClass macClass = wmPtr->macClass;
    wmPtr->attributes &= (tkAlwaysValidAttributes |
	    macClassAttrs[macClass].validAttrs);
    wmPtr->flags |= macClassAttrs[macClass].flags |
	    ((wmPtr->attributes & kWindowResizableAttribute) ? 0 :
	     WM_WIDTH_NOT_RESIZABLE|WM_HEIGHT_NOT_RESIZABLE);
	UInt64 attributes = (wmPtr->attributes &
			     ~macClassAttrs[macClass].forceOffAttrs) |
	    WM_WIDTH_NOT_RESIZABLE|WM_HEIGHT_NOT_RESIZABLE);
    UInt64 attributes = (wmPtr->attributes &
	    ~macClassAttrs[macClass].forceOffAttrs) |
	    macClassAttrs[macClass].forceOnAttrs;
	styleMask = macClassAttrs[macClass].styleMask |
	    ((attributes & kWindowNoTitleBarAttribute) ? 0 : NSTitledWindowMask) |
	    ((attributes & kWindowCloseBoxAttribute) ? NSClosableWindowMask : 0) |
	    ((attributes & kWindowCollapseBoxAttribute) ?
	     NSMiniaturizableWindowMask : 0) |
	    ((attributes & kWindowResizableAttribute) ? NSResizableWindowMask : 0) |
	    ((attributes & kWindowMetalAttribute) ?
	     NSTexturedBackgroundWindowMask : 0) |
	    ((attributes & kWindowUnifiedTitleAndToolbarAttribute) ?
	     NSUnifiedTitleAndToolbarWindowMask : 0) |
	    ((attributes & kWindowSideTitlebarAttribute) ? 1 << 9 : 0) |
	    (attributes >> WM_NSMASK_SHIFT);
	winClass = (macClass == kDrawerWindowClass ? [TKDrawerWindow class] :
		    (styleMask & (NSUtilityWindowMask|NSDocModalWindowMask|
				  NSNonactivatingPanelMask|NSHUDWindowMask)) ?
		    [TKPanel class] : [TKWindow class]);
    NSUInteger styleMask = macClassAttrs[macClass].styleMask |
	((attributes & kWindowNoTitleBarAttribute) ? 0 : NSTitledWindowMask) |
	((attributes & kWindowCloseBoxAttribute) ? NSClosableWindowMask : 0) |
	((attributes & kWindowCollapseBoxAttribute) ?
		NSMiniaturizableWindowMask : 0) |
	((attributes & kWindowResizableAttribute) ? NSResizableWindowMask : 0) |
	((attributes & kWindowMetalAttribute) ?
		NSTexturedBackgroundWindowMask : 0) |
	((attributes & kWindowUnifiedTitleAndToolbarAttribute) ?
		NSUnifiedTitleAndToolbarWindowMask : 0) |
	((attributes & kWindowSideTitlebarAttribute) ? 1 << 9 : 0) |
	(attributes >> WM_NSMASK_SHIFT);
    Class winClass = (macClass == kDrawerWindowClass ? [NSDrawerWindow class] :
	    (styleMask & (NSUtilityWindowMask|NSDocModalWindowMask|
	    NSNonactivatingPanelMask|NSHUDWindowMask)) ? [NSPanel class] :
	    [TKWindow class]);
    }
    NSRect structureRect = [winClass frameRectForContentRect:NSZeroRect
	    styleMask:styleMask];
    NSRect contentRect = NSMakeRect(5 - structureRect.origin.x,
	    TkMacOSXZeroScreenHeight() - (TkMacOSXZeroScreenTop() + 5 +
	    tkMacOSXZeroScreenHeight - (tkMacOSXZeroScreenTop + 5 +
	    structureRect.origin.y + structureRect.size.height + 200), 200, 200);
    if (wmPtr->hints.initial_state == WithdrawnState) {
	//// ???????
    }
    TKWindow *window = [[winClass alloc] initWithContentRect:contentRect
    NSWindow *window = [[winClass alloc] initWithContentRect:contentRect
	    styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
    if (!window) {
    	Tcl_Panic("couldn't allocate new Mac window");
    }
#if MAC_OS_X_VERSION_MAX_ALLOWED > 101200
    if (tabbingId) {
	identifier = [NSString stringWithUTF8String:tabbingId];
    } else {
	identifier = [NSString stringWithUTF8String:Tk_PathName(winPtr)];
    }
    [window setTabbingIdentifier: identifier];
    [window setTabbingMode: tabbingMode];
#endif
    if (tabbingId) {
	ckfree(tabbingId);
    }
    TKContentView *contentView = [[TKContentView alloc]
				     initWithFrame:NSZeroRect];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];

    /*
     * AppKit calls the viewDidChangeEffectiveAppearance method when the
     * user changes the Accent Color but not when the user changes the
     * Highlight Color.  So we register to receive KVO notifications for
     * Highlight Color as well.
     */

    [preferences addObserver:contentView
		  forKeyPath:@"AppleHighlightColor"
		     options:NSKeyValueObservingOptionNew
		     context:NULL];
#endif
    [window setContentView:contentView];
    [contentView release];
    [window setDelegate:NSApp];
    [window setAcceptsMouseMovedEvents:NO];
    [window setAcceptsMouseMovedEvents:YES];
    [window setReleasedWhenClosed:NO];
    [window setAutodisplay:NO];
    if (styleMask & NSUtilityWindowMask) {
	[(TKPanel*)window setFloatingPanel:YES];
	[(NSPanel*)window setFloatingPanel:YES];
    }
    if ((styleMask & (NSTexturedBackgroundWindowMask|NSHUDWindowMask)) &&
	    !(styleMask & NSDocModalWindowMask)) {
        /*
	 * Workaround for [Bug 2824538]: Textured windows are draggable from
	 *                               opaque content.
	 * Workaround for [Bug 2824538]: Texured windows are draggable
	 *                               from opaque content.
	 */
	[window setMovableByWindowBackground:NO];
    }


    /* Set background color and opacity of window if those flags are set.  */
    if (colorName != NULL) {
    	[window setBackgroundColor: colorName];
    }

    if (opaqueTag) {
#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD
    	[window setOpaque: opaqueTag];
#else
	[window setOpaque: YES];
#endif
    }

    [window setDocumentEdited:NO];
    wmPtr->window = window;
    macWin->view = window.contentView;
    TkMacOSXApplyWindowAttributes(winPtr, window);

    NSRect geometry = InitialWindowBounds(winPtr, window);
    geometry.size.width += structureRect.size.width;
    geometry.size.width +=  structureRect.size.width;
    geometry.size.height += structureRect.size.height;
    geometry.origin.y = TkMacOSXZeroScreenHeight() - (geometry.origin.y +
    geometry.origin.y = tkMacOSXZeroScreenHeight - (geometry.origin.y +
	    geometry.size.height);
    [window setFrame:geometry display:YES];
    [window setFrame:geometry display:NO];
    [window setTkWindow: (Window) macWin];

    TkMacOSXRegisterOffScreenWindow((Window) macWin, window);
    macWin->flags |= TK_HOST_EXISTS;
}
    if (overrideRedirect) {
    	XSetWindowAttributes atts;

    	atts.override_redirect = True;
    	Tk_ChangeWindowAttributes((Tk_Window)winPtr, CWOverrideRedirect, &atts);
	if ([NSApp macOSVersion] >= 101300) {
	    window.styleMask |= NSWindowStyleMaskDocModalWindow;
	} else {
	    ApplyContainerOverrideChanges(winPtr, NULL);
	}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXRegisterOffScreenWindow --
 *
 *	This function adds the passed in Off Screen Port to the hash table
 *	that maps Mac windows to root X windows.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	An entry is added to the windowTable hash table.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXRegisterOffScreenWindow(
    Window window,		/* Window structure. */
    void *portPtr)		/* Pointer to a Mac Window. */
{
    Tcl_HashEntry *valueHashPtr;
    int isNew;

    if (!windowHashInit) {
	Tcl_InitHashTable(&windowTable, TCL_ONE_WORD_KEYS);
	windowHashInit = true;
    }
    valueHashPtr = Tcl_CreateHashEntry(&windowTable, (char *) portPtr, &isNew);
    if (!isNew) {
	Tcl_Panic("Same macintosh window allocated twice!");
    }
    [window display];
    Tcl_SetHashValue(valueHashPtr, window);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpRedrawWidget --
 * TkMacOSXUnregisterMacWindow --
 *
 *      Mark the bounding rectangle of this widget as needing display so the
 *      widget will be drawn by [NSView drawRect:].  If this is called within
 *	Given a macintosh port window, this function removes the association
 *	between this window and the root X window that Tk cares about.
 *      the drawRect method, do nothing.
 *
 * Results:
 *      None.
 *	None.
 *
 * Side effects:
 *      The widget's bounding rectangle is marked as dirty.
 *	An entry is removed from the windowTable hash table.
 *
 *----------------------------------------------------------------------
 */

void
TkpRedrawWidget(Tk_Window tkwin) {
TkMacOSXUnregisterMacWindow(
    TkWindow *winPtr = (TkWindow *)tkwin;
    NSWindow *w;
    void *macWinPtr)	/* Reference to a Mac Window */
    Rect tkBounds;
    NSRect bounds;

{
    if ([NSApp isDrawing]) {
	return;
    }
    Tcl_HashEntry *entryPtr;

    w = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    if (w) {
    if (!windowHashInit) {
	TKContentView *view = [w contentView];
	TkMacOSXWinBounds(winPtr, &tkBounds);
	Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited");
	bounds = NSMakeRect(tkBounds.left,
			    [view bounds].size.height - tkBounds.bottom,
			    tkBounds.right - tkBounds.left,
			    tkBounds.bottom - tkBounds.top);
	[view addTkDirtyRect:bounds];
    }
    entryPtr = Tcl_FindHashEntry(&windowTable, macWinPtr);
    if (!entryPtr) {
	TkMacOSXDbgMsg("Failed to find window %p", macWinPtr);
    } else {
	Tcl_DeleteHashEntry(entryPtr);
}

    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetScrollbarGrow --
 *
 *	Sets a flag for a toplevel window indicating that the passed Tk
6976
6977
6978
6979
6980
6981
6982
6983

6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994

6995
6996
6997

6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013

7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025

7026
7027
7028




7029
7030
7031
7032


7033
7034
7035
7036


7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
5831
5832
5833
5834
5835
5836
5837

5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848

5849
5850
5851

5852
5853













5854

5855
5856

5857
5858
5859
5860
5861
5862
5863
5864
5865

5866
5867


5868
5869
5870
5871




5872
5873




5874
5875



5876
5877
5878
5879
5880
5881
5882







-
+










-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-









-
+

-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-







 *
 * Side effects:
 *	May maximize, minimize, restore, or withdraw a window.
 *
 *----------------------------------------------------------------------
 */

int
void
TkpWmSetState(
    TkWindow *winPtr,		/* Toplevel window to operate on. */
    int state)			/* One of IconicState, ZoomState, NormalState,
				 * or WithdrawnState. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    NSWindow *macWin;

    wmPtr->hints.initial_state = state;
    if (wmPtr->flags & WM_NEVER_MAPPED) {
	goto setStateEnd;
	return;
    }

    macWin = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    macWin = TkMacOSXDrawableWindow(winPtr->window);

    /*
     * Make sure windows are updated before the state change.  As an exception,
     * do not process idle tasks before withdrawing a window.  The purpose of
     * this is to support the common paradigm of immediately withdrawing the
     * root window.  Processing idle tasks before changing the state causes the
     * root to briefly flash on the screen, which users of this paradigm find
     * annoying.  Not processing the events does not guarantee that the window
     * will not appear but makes it more likely.
     */

    if (state != WithdrawnState) {
	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {};
    }
    if (state == WithdrawnState) {
	Tk_UnmapWindow((Tk_Window)winPtr);
	Tk_UnmapWindow((Tk_Window) winPtr);
    } else if (state == IconicState) {

	/*
	 * The window always gets unmapped. If we can show the icon version of
	 * the window we also collapse it.
	 */

	if (macWin && ([macWin styleMask] & NSMiniaturizableWindowMask) &&
		![macWin isMiniaturized]) {
	    [macWin miniaturize:NSApp];
	}
	Tk_UnmapWindow((Tk_Window)winPtr);
	Tk_UnmapWindow((Tk_Window) winPtr);
    } else if (state == NormalState || state == ZoomState) {
	Tk_MapWindow((Tk_Window)winPtr);
	[macWin deminiaturize:NSApp];
	Tk_MapWindow((Tk_Window) winPtr);
	if (macWin && ([macWin styleMask] & NSMiniaturizableWindowMask) &&
		[macWin isMiniaturized]) {
	    [macWin deminiaturize:NSApp];
	[macWin orderFront:NSApp];
	TkMacOSXZoomToplevel(macWin, state == NormalState ? inZoomIn : inZoomOut);
    }

	}
	TkMacOSXZoomToplevel(macWin, state == NormalState ? inZoomIn :
    /*
     * Make sure windows are updated after the state change too.
     */

		inZoomOut);
    }
    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)){}
setStateEnd:
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpIsWindowFloating --
 *
7057
7058
7059
7060
7061
7062
7063























7064
7065
7066
7067
7068
7069
7070
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








int
TkpIsWindowFloating(
    void *wRef)
{
    return [(NSWindow *)wRef level] == kCGFloatingWindowLevel;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXWindowClass --
 *
 *	Returns OS X window class of window
 *
 * Results:
 *	1 or 0 depending on window's floating attribute.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE WindowClass
TkMacOSXWindowClass(
    TkWindow *winPtr)
{
    return winPtr->wmInfoPtr->macClass;
}

/*
 *--------------------------------------------------------------
 *
 * TkMacOSXWindowOffset --
 *
 *	Determines the x and y offset from the orgin of the toplevel window
7135
7136
7137
7138
7139
7140
7141
7142

7143
7144
7145
7146
7147




7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160

7161
7162
7163

7164
7165
7166
7167
7168
7169
7170
5994
5995
5996
5997
5998
5999
6000

6001
6002




6003
6004
6005
6006
6007
6008
6009
6010

6011
6012
6013
6014
6015
6016
6017

6018



6019
6020
6021
6022
6023
6024
6025
6026







-
+

-
-
-
-
+
+
+
+




-







-
+
-
-
-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XSetInputFocus(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    TCL_UNUSED(Time))
    Display* display,
    Window focus,
    int revert_to,
    Time time)
{
    /*
     * Don't need to do a thing. Tk manages the focus for us.
     */
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpChangeFocus --
 *
 *	This function is called when Tk moves focus from one window to another.
 *	This procedure is a stub on the Mac because we always own the focus if
 *      It should be passed a non-embedded TopLevel. That toplevel gets raised
 *      to the top of the Tk stacking order and the associated NSWindow is
 *      ordered Front.
 *	we are a front most application.
 *
 * Results:
 *	The return value is the serial number of the command that changed the
 *	focus. It may be needed by the caller to filter out focus change
 *	events that were queued before the command. If the procedure doesn't
 *	actually change the focus then it returns 0.
 *
7181
7182
7183
7184
7185
7186
7187
7188
7189


7190
7191
7192

7193
7194
7195

7196
7197
7198
7199
7200
7201
7202
7203
7204
6037
6038
6039
6040
6041
6042
6043


6044
6045

6046

6047
6048
6049

6050
6051

6052
6053
6054
6055
6056
6057
6058







-
-
+
+
-

-
+


-
+

-







				 * didn't originally belong to topLevelPtr's
				 * application. */
{
    if (winPtr->atts.override_redirect) {
	return 0;
    }

    if (Tk_IsTopLevel(winPtr) && !Tk_IsEmbedded(winPtr)) {
    	NSWindow *win = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    if (Tk_IsTopLevel(winPtr) && !Tk_IsEmbedded(winPtr) ){
    	NSWindow *win = TkMacOSXDrawableWindow(winPtr->window);

    	TkWmRestackToplevel(winPtr, Above, NULL);
    	if (force) {
    	if (force ) {
    	    [NSApp activateIgnoringOtherApps:YES];
    	}
	if (win && [win canBecomeKeyWindow]) {
	if ( win && [win canBecomeKeyWindow] ) {
	    [win makeKeyAndOrderFront:NSApp];
	    [NSApp setTkEventTarget:TkMacOSXGetTkWindow(win)];
	}
    }

    /*
     * Remember the current serial number for the X server and issue a dummy
     * server request. This marks the position at which we changed the focus,
     * so we can distinguish FocusIn and FocusOut events on either side of the
7235
7236
7237
7238
7239
7240
7241
7242

7243
7244
7245

7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264


7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278



























7279
7280
7281
7282
7283
7284
7285





7286
7287


7288
7289
7290
7291


7292
7293
7294

7295
7296







7297
7298
7299
7300
7301
7302
7303
6089
6090
6091
6092
6093
6094
6095

6096
6097
6098

6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116


6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160

6161
6162



6163
6164
6165
6166
6167


6168
6169
6170
6171


6172
6173
6174
6175

6176


6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190







-
+


-
+

















-
-
+
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-


-
-
-
+
+
+
+
+
-
-
+
+


-
-
+
+


-
+
-
-
+
+
+
+
+
+
+







    Display *display,		/* X display of parent window */
    Tcl_HashTable *table)	/* Maps mac window to TkWindow */
{
    TkWindow *childPtr;
    Tcl_HashEntry *hPtr;
    int newEntry;

    if (Tk_IsMapped(winPtr) && Tk_IsTopLevel(winPtr) && !Tk_IsEmbedded(winPtr)
    if (Tk_IsMapped(winPtr) && Tk_IsTopLevel(winPtr)
	    && (winPtr->display == display)) {
	hPtr = Tcl_CreateHashEntry(table,
		(void *)TkMacOSXGetNSWindowForDrawable(winPtr->window), &newEntry);
		(char*) TkMacOSXDrawableWindow(winPtr->window), &newEntry);
	Tcl_SetHashValue(hPtr, winPtr);
    }

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {
	WmStackorderToplevelWrapperMap(childPtr, display, table);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmStackorderToplevel --
 *
 *	This procedure returns the stack order of toplevel windows.
 *
 * Results:
 *	A NULL terminated array of pointers to tk window objects in stacking
 *	order or else NULL if there was an error.
 *	An array of pointers to tk window objects in stacking order or else
 *	NULL if there was an error.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

TkWindow **
TkWmStackorderToplevel(
    TkWindow *parentPtr)	/* Parent toplevel window. */
{
    TkWindow *childWinPtr, **windows, **windowPtr;
    Tcl_HashTable table;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    /*
     * Map mac windows to a TkWindow of the wrapped toplevel.
     */

    Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
    WmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);

    windows = ckalloc((table.numEntries+1) * sizeof(TkWindow *));

    /*
     * Special cases: If zero or one toplevels were mapped there is no need to
     * enumerate Windows.
     */

    switch (table.numEntries) {
    case 0:
	windows[0] = NULL;
	goto done;
    case 1:
	hPtr = Tcl_FirstHashEntry(&table, &search);
	windows[0] = Tcl_GetHashValue(hPtr);
	windows[1] = NULL;
	goto done;
    }

    NSArray *macWindows = [NSApp orderedWindows];
    NSArray* backToFront = [[macWindows reverseObjectEnumerator] allObjects];
    NSInteger windowCount = [macWindows count];

    windows = windowPtr = (TkWindow **)ckalloc((windowCount + 1) * sizeof(TkWindow *));
    if (windows != NULL) {
	Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
    if (!windowCount) {
	ckfree(windows);
	windows = NULL;
    } else {
	windowPtr = windows + table.numEntries;
	WmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);
	for (NSWindow *w in backToFront) {
	*windowPtr-- = NULL;
	for (NSWindow *w in macWindows) {
	    hPtr = Tcl_FindHashEntry(&table, (char*) w);
	    if (hPtr != NULL) {
		childWinPtr = (TkWindow *)Tcl_GetHashValue(hPtr);
		*windowPtr++ = childWinPtr;
		childWinPtr = Tcl_GetHashValue(hPtr);
		*windowPtr-- = childWinPtr;
	    }
	}
	*windowPtr = NULL;
	if (windowPtr != windows-1) {
	Tcl_DeleteHashTable(&table);
    }
	    Tcl_Panic("num matched toplevel windows does not equal num "
		      "children");
	}
    }

  done:
    Tcl_DeleteHashTable(&table);
    return windows;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXApplyWindowAttributes --
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325


7326
7327
7328
7329
7330
7331
7332
6202
6203
6204
6205
6206
6207
6208

6209


6210
6211
6212
6213
6214
6215
6216
6217
6218







-

-
-
+
+








void
TkMacOSXApplyWindowAttributes(
    TkWindow *winPtr,
    NSWindow *macWindow)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    ApplyWindowAttributeFlagChanges(winPtr, macWindow, 0, 0, 0, 1);
    if (wmPtr->container != NULL || winPtr->atts.override_redirect) {
	ApplyContainerOverrideChanges(winPtr, macWindow);
    if (wmPtr->master != None || winPtr->atts.override_redirect) {
	ApplyMasterOverrideChanges(winPtr, macWindow);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ApplyWindowAttributeFlagChanges --
7355
7356
7357
7358
7359
7360
7361
7362



7363
7364
7365
7366
7367
7368



7369
7370
7371
7372
7373

7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391



7392
7393

7394
7395
7396
7397
7398

7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
6241
6242
6243
6244
6245
6246
6247

6248
6249
6250
6251
6252

6253
6254

6255
6256
6257
6258
6259

6260

6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277


6278
6279
6280
6281

6282





6283
6284
6285
6286
6287
6288
6289
6290
6291
6292

6293
6294
6295
6296
6297
6298
6299







-
+
+
+


-


-
+
+
+


-

-
+
















-
-
+
+
+

-
+
-
-
-
-
-
+









-







    UInt64 newAttributes = ForceAttributes(wmPtr->attributes, wmPtr->macClass);
    UInt64 changedAttributes = newAttributes ^ ForceAttributes(oldAttributes,
	    wmPtr->macClass);

    if (changedAttributes || wmPtr->flags != oldFlags || initial) {
	if (!macWindow) {
	    if (winPtr->window == None) {
		if (!create) {
		if (create) {
		    Tk_MakeWindowExist((Tk_Window) winPtr);
		} else {
		    return;
		}
		Tk_MakeWindowExist((Tk_Window)winPtr);
	    }
	    if (!TkMacOSXHostToplevelExists(winPtr)) {
		if (!create) {
		if (create) {
		    TkMacOSXMakeRealWindowExist(winPtr);
		} else {
		    return;
		}
		TkMacOSXMakeRealWindowExist(winPtr);
	    }
	    macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
	    macWindow = TkMacOSXDrawableWindow(winPtr->window);
	}
	if ((changedAttributes & kWindowCloseBoxAttribute) || initial) {
	    [[macWindow standardWindowButton:NSWindowCloseButton]
		    setEnabled:!!(newAttributes & kWindowCloseBoxAttribute)];
	}
	if ((changedAttributes & kWindowCollapseBoxAttribute) || initial) {
	    [[macWindow standardWindowButton:NSWindowMiniaturizeButton]
		    setEnabled:!!(newAttributes & kWindowCollapseBoxAttribute)];
	}
	if ((changedAttributes & (kWindowResizableAttribute |
		kWindowFullZoomAttribute)) || initial) {
	    [macWindow setShowsResizeIndicator:
		    !!(newAttributes & kWindowResizableAttribute)];
	    [[macWindow standardWindowButton:NSWindowZoomButton]
		    setEnabled:(newAttributes & kWindowResizableAttribute) &&
		    (newAttributes & kWindowFullZoomAttribute)];
	    if (newAttributes & kWindowHorizontalZoomAttribute) {
		wmPtr->flags &= ~(WM_WIDTH_NOT_RESIZABLE);
	    if (newAttributes & kWindowResizableAttribute) {
		wmPtr->flags &= ~(WM_WIDTH_NOT_RESIZABLE |
			WM_HEIGHT_NOT_RESIZABLE);
	    } else {
		wmPtr->flags |= (WM_WIDTH_NOT_RESIZABLE);
		wmPtr->flags |= (WM_WIDTH_NOT_RESIZABLE |
	    }
	    if (newAttributes & kWindowVerticalZoomAttribute) {
		wmPtr->flags &= ~(WM_HEIGHT_NOT_RESIZABLE);
	    } else {
		wmPtr->flags |= (WM_HEIGHT_NOT_RESIZABLE);
			WM_HEIGHT_NOT_RESIZABLE);
	    }
	    WmUpdateGeom(wmPtr, winPtr);
	}
	if ((changedAttributes & kWindowToolbarButtonAttribute) || initial) {
	    [macWindow setShowsToolbarButton:
		    !!(newAttributes & kWindowToolbarButtonAttribute)];
	    if ((newAttributes & kWindowToolbarButtonAttribute) &&
		    ![macWindow toolbar]) {
		NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@""];

		[toolbar setVisible:NO];
		[macWindow setToolbar:toolbar];
		[toolbar release];
		NSCell *toolbarButtonCell = [[macWindow standardWindowButton:
			NSWindowToolbarButton] cell];
		[toolbarButtonCell setTarget:[macWindow contentView]];
		[toolbarButtonCell setAction:@selector(tkToolbarButton:)];
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485

7486
7487
7488
7489
7490

7491










7492
7493
7494
7495
7496

7497
7498
7499
7500
7501
7502

7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517

7518
7519

7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531

7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560

7561
7562
7563
7564
7565

7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578




7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593

7594
7595
7596
7597
7598
7599
7600
7601


7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614

7615
7616




7617
7618
7619
7620
7621




7622
7623
7624
7625
7626
7627
7628
7629
7630
7631

7632
7633

7634
7635
7636
7637
7638
7639
7640

7641
7642
7643
7644
7645
7646
7647






7648
7649
7650
7651



7652
7653
7654
7655
7656
7657
7658
7659
7660












































































































7661
7662
7663
7664
7665
7666
7667
6319
6320
6321
6322
6323
6324
6325







































6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352

6353
6354
6355
6356
6357
6358

6359
6360
6361
6362

6363
6364
6365
6366
6367
6368
6369
6370
6371
6372

6373
6374

6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386

6387
6388
6389
6390
6391
6392
6393









6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404



6405



6406

6407
6408
6409
6410
6411
6412








6413
6414
6415
6416
6417
6418













6419








6420
6421











6422
6423
6424


6425
6426
6427
6428
6429




6430
6431
6432
6433
6434









6435


6436







6437
6438
6439





6440
6441
6442
6443
6444
6445




6446
6447
6448




6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





+





+

+
+
+
+
+
+
+
+
+
+




-
+





-
+



-










-
+

-
+











-
+






-
-
-
-
-
-
-
-
-











-
-
-
+
-
-
-

-
+





-
-
-
-
-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-


+
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+


-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	    [macWindow setCanHide:
		    !(newAttributes & tkWindowDoesNotHideAttribute)];
	}
	if ((changedAttributes & (kWindowDoesNotCycleAttribute |
		tkCanJoinAllSpacesAttribute | tkMoveToActiveSpaceAttribute)) ||
		initial) {
	    NSWindowCollectionBehavior b = NSWindowCollectionBehaviorDefault;

	    /*
	     * This behavior, which makes the green button expand a window to
	     * full screen, was included in the default as of OSX 10.13.  For
	     * uniformity we use the new default in all versions of the OS
	     * after 10.10.
	     */

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
	    if (!(macWindow.styleMask & NSUtilityWindowMask)) {
		/*
		 * Exclude overrideredirect, transient, and "help"-styled
		 * windows from moving into their own fullscreen space.
		 */

		if ((winPtr->atts.override_redirect) ||
			(wmPtr->container != NULL) ||
			(winPtr->wmInfoPtr->macClass == kHelpWindowClass)) {
		    b |= (NSWindowCollectionBehaviorCanJoinAllSpaces |
			    NSWindowCollectionBehaviorFullScreenAuxiliary);
		} else {
		    b |= NSWindowCollectionBehaviorFullScreenPrimary;

		    /*
		     * The default max size has height less than the screen
		     * height. This causes the window manager to refuse to
		     * allow the window to be resized when it is a split
		     * window. To work around this we make the max size equal
		     * to the screen size.  (For 10.11 and up, only)
		     */

		    if ([NSApp macOSVersion] >= 101100) {
			NSSize screenSize = [[macWindow screen] frame].size;
			[macWindow setMaxFullScreenContentSize:screenSize];
		    }
		}
	    }
#endif

	    if (newAttributes & tkCanJoinAllSpacesAttribute) {
		b |= NSWindowCollectionBehaviorCanJoinAllSpaces;
	    } else if (newAttributes & tkMoveToActiveSpaceAttribute) {
		b |= NSWindowCollectionBehaviorMoveToActiveSpace;
	    }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
	    if (newAttributes & kWindowDoesNotCycleAttribute) {
		b |= NSWindowCollectionBehaviorIgnoresCycle;
	    } else {
		b |= NSWindowCollectionBehaviorParticipatesInCycle;
	    }
#endif
	    [macWindow setCollectionBehavior:b];
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	    if (((changedAttributes & kWindowDoesNotCycleAttribute) || initial)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
		    && tkMacOSXMacOSXVersion < 1060
#endif
	    ) {
		[macWindow setCanCycle:
			!(newAttributes & kWindowDoesNotCycleAttribute)];
	    }
#endif
	}
	if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) {
	    [macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ?
		    kCGUtilityWindowLevel : ([macWindow isKindOfClass:
		    [TKPanel class]] && [macWindow isFloatingPanel] ?
		    [NSPanel class]] && [macWindow isFloatingPanel] ?
		    kCGFloatingWindowLevel : kCGNormalWindowLevel)];
	}

	/*
	 * The change of window class/attributes might have changed the window
	 * frame geometry:
	 * structure widths:
	 */

	NSRect structureRect = [macWindow frameRectForContentRect:NSZeroRect];

	wmPtr->xInParent = -structureRect.origin.x;
	wmPtr->yInParent = structureRect.origin.y + structureRect.size.height;
	wmPtr->parentWidth = winPtr->changes.width + structureRect.size.width;
	wmPtr->parentHeight = winPtr->changes.height + structureRect.size.height;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ApplyContainerOverrideChanges --
 * ApplyMasterOverrideChanges --
 *
 *	This procedure applies changes to override_redirect or container.
 *	This procedure applies changes to override_redirect or master.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
ApplyContainerOverrideChanges(
ApplyMasterOverrideChanges(
    TkWindow *winPtr,
    NSWindow *macWindow)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    UInt64 oldAttributes = wmPtr->attributes;
    int oldFlags = wmPtr->flags;
    unsigned long styleMask;
    NSRect structureRect;
    NSWindow *parentWindow;

    if (!macWindow && winPtr->window != None &&
	    TkMacOSXHostToplevelExists(winPtr)) {
	macWindow = TkMacOSXGetNSWindowForDrawable(winPtr->window);
    }
    styleMask = [macWindow styleMask];

    /*
     * FIX: We need an UpdateWrapper equivalent to make this 100% correct
     */

    if (winPtr->atts.override_redirect) {
	if (wmPtr->macClass == kDocumentWindowClass) {
	    wmPtr->macClass = kSimpleWindowClass;
	    wmPtr->attributes = macClassAttrs[kSimpleWindowClass].defaultAttrs;
	}
	wmPtr->attributes |= kWindowNoActivatesAttribute;
	if ([NSApp macOSVersion] == 100600) {
	    styleMask = 0;
	} else {
    } else {
	    styleMask &= ~NSTitledWindowMask;
	}
    } else {
	if (wmPtr->macClass == kSimpleWindowClass &&
	    (oldAttributes & kWindowNoActivatesAttribute)) {
		oldAttributes == kWindowNoActivatesAttribute) {
	    wmPtr->macClass = kDocumentWindowClass;
	    wmPtr->attributes =
		    macClassAttrs[kDocumentWindowClass].defaultAttrs;
	}
	wmPtr->attributes &= ~kWindowNoActivatesAttribute;
	if ([NSApp macOSVersion] == 100600) {
	    styleMask = NSTitledWindowMask         |
		        NSClosableWindowMask       |
		        NSMiniaturizableWindowMask |
		        NSResizableWindowMask;
	} else {
	    styleMask |= NSTitledWindowMask;
	}
    }
    if (!macWindow && winPtr->window != None &&
	    TkMacOSXHostToplevelExists(winPtr)) {
	macWindow = TkMacOSXDrawableWindow(winPtr->window);
    }
    if (macWindow) {
	structureRect = [NSWindow frameRectForContentRect:NSZeroRect
		styleMask:styleMask];

	/*
	 * Synchronize the wmInfoPtr to match the new window configuration
	 * so windowBoundsChanged won't corrupt the window manager info.
	 */

	wmPtr->xInParent = -structureRect.origin.x;
	wmPtr->yInParent = structureRect.origin.y + structureRect.size.height;
	wmPtr->parentWidth = winPtr->changes.width + structureRect.size.width;
	wmPtr->parentHeight = winPtr->changes.height + structureRect.size.height;
	if (winPtr->atts.override_redirect) {
	if (winPtr->atts.override_redirect && wmPtr->master != None) {
	    [macWindow setExcludedFromWindowsMenu:YES];
	    [macWindow setStyleMask:styleMask];
	    if (wmPtr->hints.initial_state == NormalState) {
		[macWindow orderFront:NSApp];
	    }
	    if (wmPtr->container != NULL) {
		wmPtr->flags |= WM_TOPMOST;
	    } else {
	    wmPtr->flags |= WM_TOPMOST;
	} else {
		wmPtr->flags &= ~WM_TOPMOST;
	    }
	} else {
	    const char *title = winPtr->wmInfoPtr->titleUid;

	    if (!title) {
		title = winPtr->nameUid;
	    }
	    [macWindow setStyleMask:styleMask];
	    [macWindow setTitle:[NSString stringWithUTF8String:title]];
	    [macWindow setExcludedFromWindowsMenu:NO];
	    wmPtr->flags &= ~WM_TOPMOST;
	}
	NSWindow *parentWindow = [macWindow parentWindow];
	if (wmPtr->container != NULL) {
	    TkWindow *containerWinPtr = (TkWindow *)wmPtr->container;
	if (wmPtr->master != None) {
	    TkDisplay *dispPtr = TkGetDisplayList();
	    TkWindow *masterWinPtr = (TkWindow *)
		    Tk_IdToWindow(dispPtr->display, wmPtr->master);

	    if (containerWinPtr && (containerWinPtr->window != None)
		    && TkMacOSXHostToplevelExists(containerWinPtr)) {
		NSWindow *containerMacWin = TkMacOSXGetNSWindowForDrawable(
			containerWinPtr->window);
	    if (masterWinPtr && masterWinPtr->window != None &&
		    TkMacOSXHostToplevelExists(masterWinPtr)) {
		NSWindow *masterMacWin =
			TkMacOSXDrawableWindow(masterWinPtr->window);

		/*
		 * Try to add the transient window as a child window of the
		 * container. A child NSWindow retains its relative position
		 * with respect to the parent when the parent is moved.  This
		 * is pointless if the parent is offscreen, and adding a child
		 * to an offscreen window causes the parent to be displayed as
		 * a zombie.  So we only do this if the parent is visible.
		 */

		if (masterMacWin && masterMacWin != parentWindow &&
		if (containerMacWin && [containerMacWin isVisible]
			&& (winPtr->flags & TK_MAPPED)) {
			(winPtr->flags & TK_MAPPED)) {
		    /*
		     * If the transient is already a child of some other window,
		     * remove it.
		     */

		    parentWindow = [macWindow parentWindow];
		    if (parentWindow && parentWindow != containerMacWin) {
		    if (parentWindow) {
			[parentWindow removeChildWindow:macWindow];
		    }
		    [macWindow orderFront:NSApp];
		    [containerMacWin addChildWindow:macWindow
					    ordered:NSWindowAbove];
		}
	    }
		    [masterMacWin addChildWindow:macWindow
			    ordered:NSWindowAbove];
		    if (wmPtr->flags & WM_TOPMOST) {
			[macWindow setLevel:kCGUtilityWindowLevel];
		    }
		}
	} else {
	    parentWindow = [macWindow parentWindow];
	    if (parentWindow) {
		[parentWindow removeChildWindow:macWindow];
	    }
	} else if (parentWindow) {
	    [parentWindow removeChildWindow:macWindow];
	    }
	}
	if (wmPtr->flags & WM_TOPMOST) {
	    [macWindow setLevel:kCGUtilityWindowLevel];
	}
	ApplyWindowAttributeFlagChanges(winPtr, macWindow, oldAttributes,
		oldFlags, 0, 0);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXMakeFullscreen --
 *
 *	This procedure sets a fullscreen window to the size of the screen.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXMakeFullscreen(
    TkWindow *winPtr,
    NSWindow *window,
    int fullscreen,
    Tcl_Interp *interp)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int result = TCL_OK, wasFullscreen = (wmPtr->flags & WM_FULLSCREEN);
#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD
    static unsigned long prevMask = 0, prevPres = 0;
#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/

    if (fullscreen) {
	int screenWidth =  WidthOfScreen(Tk_Screen(winPtr));
	int screenHeight = HeightOfScreen(Tk_Screen(winPtr));

	/*
	 * Check max width and height if set by the user.
	 */

	if ((wmPtr->maxWidth > 0 && wmPtr->maxWidth < screenWidth)
		|| (wmPtr->maxHeight > 0 && wmPtr->maxHeight < screenHeight)) {
	    if (interp) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't set fullscreen attribute for \"%s\": max"
			" width/height is too small", winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "FULLSCREEN",
			"CONSTRAINT_FAILURE", NULL);
	    }
	    result = TCL_ERROR;
	    wmPtr->flags &= ~WM_FULLSCREEN;
	} else {
	    NSRect bounds = [window contentRectForFrameRect:[window frame]];
	    NSRect screenBounds = NSMakeRect(0, 0, screenWidth, screenHeight);

	    if (!NSEqualRects(bounds, screenBounds) && !wasFullscreen) {
		wmPtr->configX = wmPtr->x;
		wmPtr->configY = wmPtr->y;
		wmPtr->configAttributes = wmPtr->attributes;
		wmPtr->attributes &= ~kWindowResizableAttribute;
		ApplyWindowAttributeFlagChanges(winPtr, window,
			wmPtr->configAttributes, wmPtr->flags, 1, 0);
		wmPtr->flags |= WM_SYNC_PENDING;
		[window setFrame:[window frameRectForContentRect:
			screenBounds] display:YES];
		wmPtr->flags &= ~WM_SYNC_PENDING;
	    }
	    wmPtr->flags |= WM_FULLSCREEN;
	}

#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD
	/*
	 * We can't set these features on Leopard or earlier, as they don't
	 * exist (neither options nor API that uses them). This formally means
	 * that there's a bug with full-screen windows with Tk on old OSX, but
	 * it isn't worth blocking a build just for this.
	 */

	prevMask = [window styleMask];
	prevPres = [NSApp presentationOptions];
	[window setStyleMask: NSBorderlessWindowMask];
	[NSApp setPresentationOptions: NSApplicationPresentationAutoHideDock
	                          | NSApplicationPresentationAutoHideMenuBar];
#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/
    } else {
	wmPtr->flags &= ~WM_FULLSCREEN;

#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD
	[NSApp setPresentationOptions: prevPres];
	[window setStyleMask: prevMask];
#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/
    }

    if (wasFullscreen && !(wmPtr->flags & WM_FULLSCREEN)) {
	UInt64 oldAttributes = wmPtr->attributes;
	NSRect bounds = NSMakeRect(wmPtr->configX, tkMacOSXZeroScreenHeight -
		(wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight),
		wmPtr->xInParent + wmPtr->configWidth,
		wmPtr->yInParent + wmPtr->configHeight);

	wmPtr->attributes |= wmPtr->configAttributes &
		kWindowResizableAttribute;
	ApplyWindowAttributeFlagChanges(winPtr, window, oldAttributes,
		wmPtr->flags, 1, 0);
	wmPtr->flags |= WM_SYNC_PENDING;
	[window setFrame:[window frameRectForContentRect:bounds] display:YES];
	wmPtr->flags &= ~WM_SYNC_PENDING;
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * GetMinSize --
 *
 *	This function computes the current minWidth and minHeight values for a
7782
7783
7784
7785
7786
7787
7788
7789

7790
7791
7792
7793
7794
7795
7796
6683
6684
6685
6686
6687
6688
6689

6690
6691
6692
6693
6694
6695
6696
6697







-
+







    TkWindow *winPtr,		/* Toplevel window to operate on. */
    int *maxWidthPtr,		/* Where to store the current maximum width of
				 * the window. */
    int *maxHeightPtr)		/* Where to store the current maximum height
				 * of the window. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    NSRect *maxBounds = (NSRect*)(ScreenOfDisplay(winPtr->display, 0)->ext_data);
    NSRect *maxBounds = (NSRect*)(winPtr->display->screens->ext_data);

    if (wmPtr->maxWidth > 0) {
	*maxWidthPtr = wmPtr->maxWidth;
    } else {
	int maxWidth = maxBounds->size.width - wmPtr->xInParent;

	if (wmPtr->gridWin != NULL) {
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844

7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856

7857
7858
7859
7860
7861

7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
6731
6732
6733
6734
6735
6736
6737

6738
6739
6740
6741
6742
6743

6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754


6755


6756
6757

6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769







-






-
+










-
-
+
-
-


-
+












static void
RemapWindows(
    TkWindow *winPtr,
    MacDrawable *parentWin)
{
    TkWindow *childPtr;

    /*
     * Remove the OS specific window. It will get rebuilt when the window gets
     * Mapped.
     */

    if (winPtr->window != None) {
	MacDrawable *macWin = (MacDrawable *)winPtr->window;
	MacDrawable *macWin = (MacDrawable *) winPtr->window;

	macWin->toplevel->referenceCount--;
	macWin->toplevel = parentWin->toplevel;
	macWin->toplevel->referenceCount++;
	winPtr->flags &= ~TK_MAPPED;
#ifdef TK_REBUILD_TOPLEVEL
	winPtr->flags |= TK_REBUILD_TOPLEVEL;
#endif
    }

    /*
     * Repeat for all the children.
    /* Repeat for all the children */
     */

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {
	RemapWindows(childPtr, (MacDrawable *)winPtr->window);
	RemapWindows(childPtr, (MacDrawable *) winPtr->window);
    }
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/tkMacOSXWm.h.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkMacOSXWm.h --
 *
 *	Declarations of Macintosh specific window manager structures.
 *
 * Copyright © 2001-2009 Apple Inc.
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKMACWM
#define _TKMACWM
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


70
71
72
73
74
75




76
77
78
79
80
81
82
83
84
85
86
87
88
89
32
33
34
35
36
37
38











39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72



73
74
75
76
77
78
79







-
-
-
-
-
-
-
-
-
-
-


















-
-
+
+






+
+
+
+




-
-
-







    char* command;		/* Tcl command to invoke when a client message
				 * for this protocol arrives. The actual size
				 * of the structure varies to accommodate the
				 * needs of the actual command. THIS MUST BE
				 * THE LAST FIELD OF THE STRUCTURE. */
} ProtocolHandler;

/* The following data structure is used in the TkWmInfo to maintain a list of all of the
 * transient windows belonging to a given container.
 */

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

#define WITHDRAWN_BY_CONTAINER 0x1

/*
 * A data structure of the following type holds window-manager-related
 * information for each top-level window in an application.
 */

typedef struct TkWmInfo {
    TkWindow *winPtr;		/* Pointer to main Tk information for this
				 * window. */
    Window reparent;		/* If the window has been reparented, this
				 * gives the ID of the ancestor of the window
				 * that is a child of the root window (may not
				 * be window's immediate parent). If the window
				 * isn't reparented, this has the value
				 * None. */
    Tk_Uid titleUid;		/* Title to display in window caption. If NULL,
				 * use name of widget. */
    char *iconName;		/* Name to display in icon. */
    Tk_Window container;		/* Container window for TRANSIENT_FOR property,
				 * or None. */
    Window master;		/* Master window for TRANSIENT_FOR property, or
				 * None. */
    XWMHints hints;		/* Various pieces of information for window
				 * manager. */
    char *leaderName;		/* Path name of leader of window group
				 * (corresponds to hints.window_group).
				 * Malloc-ed. Note: this field doesn't get
				 * updated if leader is destroyed. */
    char *masterWindowName;	/* Path name of window specified as master in
				 * "wm transient" command, or NULL. Malloc-ed.
				 * Note: this field doesn't get updated if
				 * masterWindowName is destroyed. */
    Tk_Window icon;		/* Window to use as icon for this window, or
				 * NULL. */
    Tk_Window iconFor;		/* Window for which this window is icon, or
				 * NULL if this isn't an icon for anyone. */
    Transient *transientPtr;    /* First item in a list of all transient windows
				 * belonging to this window, or NULL if there
				 * are no transients. */

    /*
     * Information used to construct an XSizeHints structure for the window
     * manager:
     */

    int sizeHintsFlags;		/* Flags word for XSizeHints structure. If the
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171







-
+







				 * be. */

    /*
     * List of children of the toplevel which have private colormaps.
     */

    TkWindow **cmapList;	/* Array of window with private colormaps. */
    Tcl_Size cmapCount;		/* Number of windows in array. */
    int cmapCount;		/* Number of windows in array. */

    /*
     * Miscellaneous information.
     */

    ProtocolHandler *protPtr;	/* First in list of protocol handlers for this
				 * window (NULL means none). */
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
181
182
183
184
185
186
187









188
189
190
191
192
193
194







-
-
-
-
-
-
-
-
-







     */

    WindowClass macClass;
    UInt64 attributes, configAttributes;
    TkWindow *scrollWinPtr;	/* Ptr to scrollbar handling grow widget. */
    TkMenu *menuPtr;
    NSWindow *window;

    /*
     * Space to cache current window state when window becomes Fullscreen.
     */

    unsigned long cachedStyle;
    unsigned long cachedPresentation;
    NSRect cachedBounds;

} WmInfo;

/*
 * Flag values for WmInfo structures:
 *
 * WM_NEVER_MAPPED -		non-zero means window has never been mapped;
 *				need to update all info when window is first

Changes to macosx/tkMacOSXXCursors.h.

1
2
3
4
5
6
7
8
9
10



11
12
13
14
15
16
17
1
2
3
4
5
6
7



8
9
10
11
12
13
14
15
16
17







-
-
-
+
+
+







/*
 * tkMacOSXXCursors.h --
 *
 *	This file defines a set of Macintosh cursors that
 *	emulate the X cursor set. All of these cursors were
 *	constructed and donated by Grant Neufeld. ([email protected])
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * Copyright © 2008-2009 Apple Inc.
 * Copyright © 2008-2009 Daniel A. Steffen <[email protected]>
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright 2008-2009, Apple Inc.
 * Copyright (c) 2008-2009 Daniel A. Steffen <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

static const unsigned char tkMacOSXXCursors[][68] = {

Changes to macosx/tkMacOSXXStubs.c.

1
2
3
4
5
6

7
8
9
10
11
12




13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36



37
38
39
40
41
42
43

44
45
46
47

48
49
50
51
52
53
54
55
56








57
58
59
60
61
62
63
1
2
3
4
5

6
7
8




9
10
11
12
13
14
15
16
17

18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43

44
45



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70





-
+


-
-
-
-
+
+
+
+





-

-
+
















+
+
+




-

-
+

-
-
-
+









+
+
+
+
+
+
+
+







/*
 * tkMacOSXXStubs.c --
 *
 *	This file contains most of the X calls called by Tk. Many of these
 *	calls are just stubs and either don't make sense on the Macintosh or
 *	their implementation just doesn't do anything. Other calls will
 *	their implamentation just doesn't do anything. Other calls will
 *	eventually be moved into other files.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 2001-2009, Apple Inc.
 * Copyright © 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2014 Marc Culler.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2014 Marc Culler.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#define XLIB_ILLEGAL_ACCESS
#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"

#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDShared.h>

/*
 * Because this file is still under major development Debugger statements are
 * used through out this file. The define TCL_DEBUG will decide whether the
 * debugger statements actually call the debugger or not.
 */

#ifndef TCL_DEBUG
#   define Debugger()
#endif

#define ROOT_ID 10

CGFloat tkMacOSXZeroScreenHeight = 0;
CGFloat tkMacOSXZeroScreenTop = 0;

/*
 * Declarations of static variables used in this file.
 */

/* The unique Macintosh display. */
static TkDisplay *gMacDisplay = NULL;
/* The default name of the Macintosh display. */
				/* Macintosh display. */
static const char *macScreenName = ":0";
/* Timestamp showing the last reset of the inactivity timer. */
static Time lastInactivityReset = 0;

				/* Default name of macintosh display. */

/*
 * Forward declarations of procedures used in this file.
 */

static XID		MacXIdAlloc(Display *display);
static int		DefaultErrorHandler(Display *display,
			    XErrorEvent *err_evt);

/*
 * Other declarations
 */

static int		DestroyImage(XImage *image);
static unsigned long	ImageGetPixel(XImage *image, int x, int y);
static int		ImagePutPixel(XImage *image, int x, int y,
			    unsigned long pixel);

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDisplayChanged --
 *
 *	Called to set up initial screen info or when an event indicated
76
77
78
79
80
81
82
83

84
85
86

87
88
89
90
91

92
93




94
95
96
97
98





99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189






190
191
192

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238


239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299



300
301
302
303








304

305
306
307
308
309




















310



311

312
313
314
315
316
317
318
83
84
85
86
87
88
89

90
91
92

93
94
95
96
97

98
99
100
101
102
103
104





105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120






























































121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154








































155
156





157
158
159
160

161
162
163
164
165
166
167
168


















169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208





209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240







-
+


-
+




-
+


+
+
+
+
-
-
-
-
-
+
+
+
+
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


















+
+
+
+
+
+


-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-




-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

















-
+





-
-
-
+
+
+




+
+
+
+
+
+
+
+

+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
-
+







TkMacOSXDisplayChanged(
    Display *display)
{
    Screen *screen;
    NSArray *nsScreens;


    if (display == NULL || (((_XPrivDisplay)(display))->screens) == NULL) {
    if (display == NULL || display->screens == NULL) {
	return;
    }
    screen = (((_XPrivDisplay)(display))->screens);
    screen = display->screens;

    nsScreens = [NSScreen screens];
    if (nsScreens && [nsScreens count]) {
	NSScreen *s = [nsScreens objectAtIndex:0];
	NSRect bounds = [s frame];
	NSRect bounds = [s frame], visible = [s visibleFrame];
	NSRect maxBounds = NSZeroRect;

	tkMacOSXZeroScreenHeight = bounds.size.height;
	tkMacOSXZeroScreenTop = tkMacOSXZeroScreenHeight -
		(visible.origin.y + visible.size.height);

	DefaultDepthOfScreen(screen) = NSBitsPerPixelFromDepth([s depth]);
	WidthOfScreen(screen) = bounds.size.width;
	HeightOfScreen(screen) = bounds.size.height;
	WidthMMOfScreen(screen) = (bounds.size.width * 381 + 720) / 1440; /* = 3/4 * 254/720 */
	HeightMMOfScreen(screen) = (bounds.size.height * 381 + 720) / 1440; /* = 3/4 * 254/720 */
	screen->root_depth = NSBitsPerPixelFromDepth([s depth]);
	screen->width = bounds.size.width;
	screen->height = bounds.size.height;
	screen->mwidth = (bounds.size.width * 254 + 360) / 720;
	screen->mheight = (bounds.size.height * 254 + 360) / 720;

	for (s in nsScreens) {
	    maxBounds = NSUnionRect(maxBounds, [s visibleFrame]);
	}
	*((NSRect *)screen->ext_data) = maxBounds;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXZeroScreenHeight --
 *
 *	Replacement for the tkMacOSXZeroScreenHeight variable to avoid
 *	caching values from NSScreen (fixes bug aea00be199).
 *
 * Results:
 *	Returns the height of screen 0 (the screen assigned the menu bar
 *	in System Preferences), or 0.0 if getting [NSScreen screens] fails.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

CGFloat
TkMacOSXZeroScreenHeight()
{
    NSArray *nsScreens = [NSScreen screens];
    if (nsScreens && [nsScreens count]) {
	NSScreen *s = [nsScreens objectAtIndex:0];
	NSRect bounds = [s frame];
	return bounds.size.height;
    }
    return 0.0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXZeroScreenTop --
 *
 *	Replacement for the tkMacOSXZeroScreenTop variable to avoid
 *	caching values from visibleFrame.
 *
 * Results:
 *	Returns how far below the top of screen 0 to draw
 *	(i.e. the height of the menu bar if it is always shown),
 *	or 0.0 if getting [NSScreen screens] fails.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

CGFloat
TkMacOSXZeroScreenTop()
{
    NSArray *nsScreens = [NSScreen screens];
    if (nsScreens && [nsScreens count]) {
	NSScreen *s = [nsScreens objectAtIndex:0];
	NSRect bounds = [s frame], visible = [s visibleFrame];
	return bounds.size.height - (visible.origin.y + visible.size.height);
    }
    return 0.0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpOpenDisplay/XkbOpenDisplay --
 * TkpOpenDisplay --
 *
 *	Create the Display structure and fill it with device specific
 *	information.
 *
 * Results:
 *	Returns a Display structure on success or NULL on failure.
 *
 * Side effects:
 *	Allocates a new Display structure.
 *
 *----------------------------------------------------------------------
 */

TkDisplay *
TkpOpenDisplay(
    const char *display_name)
{
    Display *display;
    Screen *screen;
    int fd = 0;
    static NSRect maxBounds = {{0, 0}, {0, 0}};
    static char vendor[25] = "";
    NSArray *cgVers;
    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    if (gMacDisplay != NULL) {
	if (strcmp(DisplayString(gMacDisplay->display), display_name) == 0) {
	if (strcmp(gMacDisplay->display->display_name, display_name) == 0) {
	    return gMacDisplay;
	} else {
	    return NULL;
	}
    }

    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    display = XkbOpenDisplay(display_name, NULL, NULL, NULL, NULL, NULL);

    /*
     * Initialize screen bits that may change
     */

    TkMacOSXDisplayChanged(display);

    gMacDisplay = (TkDisplay *)ckalloc(sizeof(TkDisplay));

    /*
     * This is the quickest way to make sure that all the *Init flags get
     * properly initialized
     */

    bzero(gMacDisplay, sizeof(TkDisplay));
    gMacDisplay->display = display;
    [pool drain];

    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(gMacDisplay);

    return gMacDisplay;
}

Display *
XkbOpenDisplay(
    TCL_UNUSED(const char *),
	int *ev_rtrn,
	int *err_rtrn,
	int *major_rtrn,
	int *minor_rtrn,
	int *reason)
{
    _XPrivDisplay display = (_XPrivDisplay)ckalloc(sizeof(Display));
    Screen *screen = (Screen *)ckalloc(sizeof(Screen));
    display = ckalloc(sizeof(Display));
    screen  = ckalloc(sizeof(Screen));
    int fd = 0;
    NSArray *cgVers;
    static char vendor[25] = "";
    static NSRect maxBounds = {{0, 0}, {0, 0}};

    bzero(display, sizeof(Display));
    bzero(screen, sizeof(Screen));

    display->resource_alloc = MacXIdAlloc;
    LastKnownRequestProcessed(display) = 1;
    display->request	    = 0;
    display->qlen	    = 0;
    display->fd		    = fd;
    display->screens	    = screen;
    display->nscreens	    = 1;
    display->default_screen = 0;
    display->display_name   = (char *) macScreenName;

    /*
     * These screen bits never change
     */
    screen->root	= ROOT_ID;
    screen->display	= display;
    screen->black_pixel = 0x00000000;
    screen->white_pixel = 0x00FFFFFF;
    screen->ext_data	= (XExtData *) &maxBounds;

    screen->root_visual = (Visual *)ckalloc(sizeof(Visual));
    screen->root_visual->visualid     = 0;
    screen->root_visual->c_class      = TrueColor;
    screen->root_visual->red_mask     = 0x00FF0000;
    screen->root_visual->green_mask   = 0x0000FF00;
    screen->root_visual->blue_mask    = 0x000000FF;
    screen->root_visual->bits_per_rgb = 24;
    screen->root_visual->map_entries  = 256;

    cgVers = [[[NSBundle bundleWithIdentifier:@"com.apple.CoreGraphics"]
	    objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
	    componentsSeparatedByString:@"."];
    if ([cgVers count] >= 2) {
	display->proto_major_version = [[cgVers objectAtIndex:1] integerValue];
    }
    if ([cgVers count] >= 3) {
	display->proto_minor_version = [[cgVers objectAtIndex:2] integerValue];
    }
    if (!vendor[0]) {
	snprintf(vendor, sizeof(vendor), "Apple AppKit %g",
		NSAppKitVersionNumber);
    }
    display->vendor = vendor;
    {
	int major, minor, patch;

#if MAC_OS_X_VERSION_MAX_ALLOWED < 101000
#if MAC_OS_X_VERSION_MIN_REQUIRED < 10100
	Gestalt(gestaltSystemVersionMajor, (SInt32*)&major);
	Gestalt(gestaltSystemVersionMinor, (SInt32*)&minor);
	Gestalt(gestaltSystemVersionBugFix, (SInt32*)&patch);
#else
	NSOperatingSystemVersion systemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
	major = (int)systemVersion.majorVersion;
	minor = (int)systemVersion.minorVersion;
	patch = (int)systemVersion.patchVersion;
	major = systemVersion.majorVersion;
	minor = systemVersion.minorVersion;
	patch = systemVersion.patchVersion;
#endif
	display->release = major << 16 | minor << 8 | patch;
    }

    /*
     * These screen bits never change
     */
    screen->root	= ROOT_ID;
    screen->display	= display;
    screen->black_pixel = 0x00000000 | PIXEL_MAGIC << 24;
    screen->white_pixel = 0x00FFFFFF | PIXEL_MAGIC << 24;
    screen->ext_data	= (XExtData *) &maxBounds;

    screen->root_visual = ckalloc(sizeof(Visual));
    if (ev_rtrn) *ev_rtrn = 0;
    if (err_rtrn) *err_rtrn = 0;
    if (major_rtrn) *major_rtrn = 0;
    if (minor_rtrn) *minor_rtrn = 0;
    if (reason) *reason = 0;
    screen->root_visual->visualid     = 0;
    screen->root_visual->class	      = TrueColor;
    screen->root_visual->red_mask     = 0x00FF0000;
    screen->root_visual->green_mask   = 0x0000FF00;
    screen->root_visual->blue_mask    = 0x000000FF;
    screen->root_visual->bits_per_rgb = 24;
    screen->root_visual->map_entries  = 256;

    /*
     * Initialize screen bits that may change
     */

    TkMacOSXDisplayChanged(display);

    gMacDisplay = ckalloc(sizeof(TkDisplay));

    /*
     * This is the quickest way to make sure that all the *Init flags get
     * properly initialized
     */

    bzero(gMacDisplay, sizeof(TkDisplay));
    gMacDisplay->display = display;
    [pool drain];
    return display;
    return gMacDisplay;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCloseDisplay --
 *
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342
343


344
345
346
347
348
349
350
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263


264
265
266
267
268
269
270
271
272







-
+







-
-
+
+







 *----------------------------------------------------------------------
 */

void
TkpCloseDisplay(
    TkDisplay *displayPtr)
{
    _XPrivDisplay display = (_XPrivDisplay)displayPtr->display;
    Display *display = displayPtr->display;

    if (gMacDisplay != displayPtr) {
	Tcl_Panic("TkpCloseDisplay: tried to call TkpCloseDisplay on bad display");
    }

    gMacDisplay = NULL;
    if (display->screens != NULL) {
	if (DefaultVisualOfScreen(ScreenOfDisplay(display, 0)) != NULL) {
	    ckfree(DefaultVisualOfScreen(ScreenOfDisplay(display, 0)));
	if (display->screens->root_visual != NULL) {
	    ckfree(display->screens->root_visual);
	}
	ckfree(display->screens);
    }
    ckfree(display);
}

/*
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342







-
+







 *	was previously on the stack.
 *
 *----------------------------------------------------------------------
 */

static XID
MacXIdAlloc(
    TCL_UNUSED(Display *))		/* Display for which to allocate. */
    Display *display)		/* Display for which to allocate. */
{
    static long int cur_id = 100;
    /*
     * Some special XIds are reserved
     *   - this is why we start at 100
     */

436
437
438
439
440
441
442
443
444


445
446
447
448
449
450
451
452
453
454
455
456
457
458


459
460

461
462
463







464
465
466

467
468
469
470
471
472
473
474

475
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492

493
494

495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523
524








525
526
527
528
529
530

531
532
533
534



535
536
537
538
539
540
541
542
543


544
545
546
547
548
549
550
551
552
553
554



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
584
585
586
587
588
589
590





591
592
593
594
595
596

597
598
599


600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639









640
641
642
643
644

645
646
647


648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679

680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757


758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787








788
789
790
791
792
793
794
795
796
797
798
799
800
801






802
803
804
805
806

807
808

809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848

849
850
851
852
853
854
855

856
857
858
859


860
861
862
863
864
865
866
867

868
869
870
871
872
873
874
875
876

877
878
879

880
881
882
883
884
885
886


887
888









889
890



























891
892
893
894
895
896
897
358
359
360
361
362
363
364


365
366
367
368
369
370
371
372
373
374
375
376
377
378


379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402

403
404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422

423
424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441
442
443

444
445








446
447
448
449
450
451
452
453
454
455

456
457

458
459



460
461
462
463
464

465
466
467
468


469
470
471
472
473
474
475
476
477
478



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509
510
511
512





513
514
515
516
517
518
519
520
521
522

523
524


525
526
527

528
529
530
531
532
533
534
535
536
537
538

539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554









555
556
557
558
559
560
561
562
563
564
565
566
567

568
569


570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586

587
588














589











































































590


591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

612
613
614







615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630






631
632
633
634
635
636
637
638
639
640

641
642

643
644
645
646
647
648
649

650































651

652
653
654
655

656
657

658
659
660


661
662
663
664
665
666




667






668
669

670
671
672

673
674
675
676
677
678
679
680
681
682


683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727







-
-
+
+












-
-
+
+

-
+



+
+
+
+
+
+
+


-
+







-
+

-
+















-
+

-
+









-
+










-
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-


-
+

-
-
-
+
+
+


-




-
-
+
+








-
-
-
+
+
+




















-
+










-
-
-
-
-
+
+
+
+
+





-
+

-
-
+
+

-











-











-





-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-
+

-
-
+
+















-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+



















-



-
-
-
-
-
-
-
+
+
+
+
+
+
+
+








-
-
-
-
-
-
+
+
+
+
+
+




-
+

-
+






-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+



-


-
+


-
-
+
+




-
-
-
-
+
-
-
-
-
-
-


-
+


-
+







+
+
-
-
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *	This function will call panic and exit.
 *
 *----------------------------------------------------------------------
 */

static int
DefaultErrorHandler(
    TCL_UNUSED(Display *),
    TCL_UNUSED(XErrorEvent *))
    Display* display,
    XErrorEvent* err_evt)
{
    /*
     * This call should never be called. Tk replaces it with its own error
     * handler.
     */

    Tcl_Panic("Warning hit bogus error handler!");
    return 0;
}

char *
XGetAtomName(
    Display *display,
    TCL_UNUSED(Atom))
    Display * display,
    Atom atom)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    return NULL;
}

int
_XInitImageFuncPtrs(
    XImage *image)
{
    return 0;
}

XErrorHandler
XSetErrorHandler(
    TCL_UNUSED(XErrorHandler))
    XErrorHandler handler)
{
    return DefaultErrorHandler;
}

Window
XRootWindow(
    Display *display,
    TCL_UNUSED(int))
    int screen_number)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    return ROOT_ID;
}

int
XGetGeometry(
    Display *display,
    Drawable d,
    Window *root_return,
    int *x_return,
    int *y_return,
    unsigned int *width_return,
    unsigned int *height_return,
    unsigned int *border_width_return,
    unsigned int *depth_return)
{
    TkWindow *winPtr = ((MacDrawable *)d)->winPtr;
    TkWindow *winPtr = ((MacDrawable *) d)->winPtr;

    LastKnownRequestProcessed(display)++;
    display->request++;
    *root_return = ROOT_ID;
    if (winPtr) {
	*x_return = Tk_X(winPtr);
	*y_return = Tk_Y(winPtr);
	*width_return = Tk_Width(winPtr);
	*height_return = Tk_Height(winPtr);
	*border_width_return = winPtr->changes.border_width;
	*depth_return = Tk_Depth(winPtr);
    } else {
	CGSize size = ((MacDrawable *)d)->size;
	CGSize size = ((MacDrawable *) d)->size;
	*x_return = 0;
	*y_return =  0;
	*width_return = size.width;
	*height_return = size.height;
	*border_width_return = 0;
	*depth_return = 32;
    }
    return 1;
}

int
void
XChangeProperty(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom),
    TCL_UNUSED(Atom),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(_Xconst unsigned char *),
    TCL_UNUSED(int))
    Display* display,
    Window w,
    Atom property,
    Atom type,
    int format,
    int mode,
    _Xconst unsigned char* data,
    int nelements)
{
    Debugger();
    return Success;
}

int
void
XSelectInput(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(long))
    Display* display,
    Window w,
    long event_mask)
{
    Debugger();
    return Success;
}

int
XBell(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int))
    Display* display,
    int percent)
{
    NSBeep();
    return Success;
}

#if 0
void
XSetWMNormalHints(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(XSizeHints *))
    Display* display,
    Window w,
    XSizeHints* hints)
{
    /*
     * Do nothing. Shouldn't even be called.
     */
}

XSizeHints *
XAllocSizeHints(void)
{
    /*
     * Always return NULL. Tk code checks to see if NULL is returned & does
     * nothing if it is.
     */

    return NULL;
}
#endif

GContext
XGContextFromGC(
    TCL_UNUSED(GC))
    GC gc)
{
    /*
     * TODO: currently a no-op
     */

    return 0;
}

Status
XSendEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Bool),
    TCL_UNUSED(long),
    TCL_UNUSED(XEvent *))
    Display* display,
    Window w,
    Bool propagate,
    long event_mask,
    XEvent* event_send)
{
    Debugger();
    return 0;
}

int
void
XClearWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window))
    Display* display,
    Window w)
{
    return Success;
}

/*
int
XDrawPoint(
    Display* display,
    Drawable d,
    GC gc,
    int x,
    int y)
{
    return Success;
}

int
XDrawPoints(
    Display* display,
    Drawable d,
    GC gc,
    XPoint* points,
    int npoints,
    int mode)
{
    return Success;
}
*/

int
XWarpPointer(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
    Display* display,
    Window src_w,
    Window dest_w,
    int src_x,
    int src_y,
    unsigned int src_width,
    unsigned int src_height,
    int dest_x,
    int dest_y)
{
    return Success;
}

int
void
XQueryColor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    Display* display,
    Colormap colormap,
    XColor* def_in_out)
{
    unsigned long p;
    unsigned char r, g, b;
    XColor *d = def_in_out;

    p		= d->pixel;
    r		= (p & 0x00FF0000) >> 16;
    g		= (p & 0x0000FF00) >> 8;
    b		= (p & 0x000000FF);
    d->red	= (r << 8) | r;
    d->green	= (g << 8) | g;
    d->blue	= (b << 8) | b;
    d->flags	= DoRed|DoGreen|DoBlue;
    d->pad	= 0;
    return Success;
}

Bool
XTranslateCoordinates(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    TCL_UNUSED(Window *))
{
    return 0;
}

void
int
XSetCommand(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(char **),
    TCL_UNUSED(int))
{
    return Success;
}

int
XGetWindowAttributes(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(XWindowAttributes *))
{
    return Success;
}

Status
XGetWMColormapWindows(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window **),
    TCL_UNUSED(int *))
{
    return Success;
}

int
XIconifyWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int))
{
    return Success;
}

XHostAddress *
XListHosts(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int *),
    TCL_UNUSED(Bool *))
{
    return NULL;
}

int
XLookupColor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    TCL_UNUSED(_Xconst char *),
    TCL_UNUSED(XColor *),
    TCL_UNUSED(XColor *))
{
    return Success;
}

int
XNextEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(XEvent *))
{
    return Success;
}

int
XPutBackEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(XEvent *))
{
    return Success;
}

int
XQueryColors(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    Display* display,
    Colormap colormap,
    XColor* defs_in_out,
    int ncolors)
{
    int i;
    unsigned long p;
    unsigned char r, g, b;
    XColor *d = defs_in_out;

    for (i = 0; i < ncolors; i++, d++) {
	p		= d->pixel;
	r		= (p & 0x00FF0000) >> 16;
	g		= (p & 0x0000FF00) >> 8;
	b		= (p & 0x000000FF);
	d->red		= (r << 8) | r;
	d->green	= (g << 8) | g;
	d->blue		= (b << 8) | b;
	d->flags	= DoRed|DoGreen|DoBlue;
	d->pad		= 0;
    }
    return Success;
}

int
XQueryTree(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window **),
    TCL_UNUSED(unsigned int *))
XQueryTree(display, w, root_return, parent_return, children_return,
	nchildren_return)
    Display* display;
    Window w;
    Window* root_return;
    Window* parent_return;
    Window** children_return;
    unsigned int* nchildren_return;
{
    return 0;
}


int
XGetWindowProperty(
    Display *display,
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom),
    TCL_UNUSED(long),
    TCL_UNUSED(long),
    TCL_UNUSED(Bool),
    TCL_UNUSED(Atom),
    Window w,
    Atom property,
    long long_offset,
    long long_length,
    Bool delete,
    Atom req_type,
    Atom *actual_type_return,
    int *actual_format_return,
    unsigned long *nitems_return,
    unsigned long *bytes_after_return,
    TCL_UNUSED(unsigned char **))
    unsigned char ** prop_return)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    *actual_type_return = None;
    *actual_format_return = *bytes_after_return = 0;
    *nitems_return = 0;
    return 0;
}

int
void
XWindowEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(long),
    TCL_UNUSED(XEvent *))
{
    return Success;
}

int
XWithdrawWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int))
{
    return Success;
}

int
XmbLookupString(
    TCL_UNUSED(XIC),
    TCL_UNUSED(XKeyPressedEvent *),
    TCL_UNUSED(char *),
    TCL_UNUSED(int),
    TCL_UNUSED(KeySym *),
    TCL_UNUSED(Status *))
{
    return Success;
}

int
XRefreshKeyboardMapping(
    TCL_UNUSED(XMappingEvent *))
    XMappingEvent *x)
{
    /* used by tkXEvent.c */
    Debugger();
    return Success;
}

int
void
XSetIconName(
    Display* display,
    TCL_UNUSED(Window),
    TCL_UNUSED(const char *))
    Window w,
    const char *icon_name)
{
    /*
     * This is a no-op, no icon name for Macs.
     */
    LastKnownRequestProcessed(display)++;
    return Success;
}

    display->request++;
Bool
XFilterEvent(
    TCL_UNUSED(XEvent *),
    TCL_UNUSED(Window))
{
    return 0;
}

int
void
XForceScreenSaver(
    Display* display,
    TCL_UNUSED(int))
    int mode)
{
    /*
     * This function is just a no-op. It is defined to reset the screen saver.
     * However, there is no real way to do this on a Mac. Let me know if there
     * is!
     */

    display->request++;
}
    LastKnownRequestProcessed(display)++;
    return Success;

int
XSync(
    Display *display,
    Bool flag)
{
    TkMacOSXFlushWindows();
    display->request++;
    return 0;
}

#if 0
int
XSetClipRectangles(
    Display *d,
    GC gc,
    int clip_x_origin,
    int clip_y_origin,
    XRectangle* rectangles,
    int n,
    int ordering)
{
    TkRegion clipRgn = TkCreateRegion();

    while (n--) {
	XRectangle rect = *rectangles;

	rect.x += clip_x_origin;
	rect.y += clip_y_origin;
	TkUnionRectWithRegion(&rect, clipRgn, clipRgn);
	rectangles++;
    }
    TkSetRegion(d, gc, clipRgn);
    TkDestroyRegion(clipRgn);
    return 1;
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * TkGetServerInfo --
 *
 *	Given a window, this procedure returns information about the window
 *	server for that window. This procedure provides the guts of the "winfo
920
921
922
923
924
925
926






























































































































































































































































































































































































927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947

948
949
950
951
952




953
954
955
956
957

958
959
960
961



962
963
964
965
966

967
968
969
970



971
972
973
974
975

976
977
978
979



980
981
982
983
984

985
986
987
988



989
990
991
992
993

994
995
996
997



998
999
1000
1001
1002

1003
1004
1005
1006



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016



1017
1018
1019

1020
1021
1022
1023
1024
1025
1026



1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141

1142
1143
1144
1145


1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192









1193
1194
1195

1196



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158

1159
1160




1161
1162
1163
1164
1165

1166
1167

1168
1169



1170
1171
1172
1173

1174
1175

1176
1177



1178
1179
1180
1181

1182
1183

1184
1185



1186
1187
1188
1189

1190
1191

1192
1193



1194
1195
1196
1197

1198
1199

1200
1201



1202
1203
1204
1205

1206
1207

1208
1209



1210
1211
1212
1213
1214

1215
1216
1217
1218



1219
1220
1221
1222
1223

1224
1225
1226
1227
1228



1229
1230
1231
1232
1233
1234
1235
1236

1237
1238
1239
1240
1241
1242


















































































1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339









1340
1341
1342
1343
1344
1345
1346







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
+

-
-
-
-
+
+
+
+

-


-
+

-
-
-
+
+
+

-


-
+

-
-
-
+
+
+

-


-
+

-
-
-
+
+
+

-


-
+

-
-
-
+
+
+

-


-
+

-
-
-
+
+
+

-


-
+

-
-
-
+
+
+


-




-
-
-
+
+
+


-
+




-
-
-
+
+
+





-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
+


+




+
+




















-
+








-
+

















+
+
+
+
+
+
+
+
+



+

+
+
+




-
-
-
-
-
-
-
-
-







	    ProtocolVersion(Tk_Display(tkwin)),
	    ProtocolRevision(Tk_Display(tkwin)));
    snprintf(buffer2, sizeof(buffer2), " Mac OS X %x",
	    VendorRelease(Tk_Display(tkwin)));
    Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)),
	    buffer2, NULL);
}

#pragma mark XImage handling

/*
 *----------------------------------------------------------------------
 *
 * XCreateImage --
 *
 *	Allocates storage for a new XImage.
 *
 * Results:
 *	Returns a newly allocated XImage.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

XImage *
XCreateImage(
    Display* display,
    Visual* visual,
    unsigned int depth,
    int format,
    int offset,
    char* data,
    unsigned int width,
    unsigned int height,
    int bitmap_pad,
    int bytes_per_line)
{
    XImage *ximage;
    display->request++;
    ximage = ckalloc(sizeof(XImage));

    ximage->height = height;
    ximage->width = width;
    ximage->depth = depth;
    ximage->xoffset = offset;
    ximage->format = format;
    ximage->data = data;
    ximage->obdata = NULL;
    /* The default pixelpower is 0.  This must be explicitly set to 1 in the
     * case of an XImage extracted from a Retina display.
     */
    ximage->pixelpower = 0;

    if (format == ZPixmap) {
	ximage->bits_per_pixel = 32;
	ximage->bitmap_unit = 32;
    } else {
	ximage->bits_per_pixel = 1;
	ximage->bitmap_unit = 8;
    }
    if (bitmap_pad) {
	ximage->bitmap_pad = bitmap_pad;
    } else {
	/* Use 16 byte alignment for best Quartz perfomance */
	ximage->bitmap_pad = 128;
    }
    if (bytes_per_line) {
	ximage->bytes_per_line = bytes_per_line;
    } else {
	ximage->bytes_per_line = ((width * ximage->bits_per_pixel +
		(ximage->bitmap_pad - 1)) >> 3) &
		~((ximage->bitmap_pad >> 3) - 1);
    }
#ifdef WORDS_BIGENDIAN
    ximage->byte_order = MSBFirst;
    ximage->bitmap_bit_order = MSBFirst;
#else
    ximage->byte_order = LSBFirst;
    ximage->bitmap_bit_order = LSBFirst;
#endif
    ximage->red_mask = 0x00FF0000;
    ximage->green_mask = 0x0000FF00;
    ximage->blue_mask = 0x000000FF;
    ximage->f.create_image = NULL;
    ximage->f.destroy_image = DestroyImage;
    ximage->f.get_pixel = ImageGetPixel;
    ximage->f.put_pixel = ImagePutPixel;
    ximage->f.sub_image = NULL;
    ximage->f.add_pixel = NULL;

    return ximage;
}

/*
 *----------------------------------------------------------------------
 *
 * XGetImage --
 *
 *	This function copies data from a pixmap or window into an XImage.
 *
 * Results:
 *	Returns a newly allocated XImage containing the data from the given
 *	rectangle of the given drawable, or NULL if the XImage could not be
 *	constructed.  NOTE: If we are copying from a window on a Retina
 *	display, the dimensions of the XImage will be 2*width x 2*height.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

XImage *
XGetImage(
    Display *display,
    Drawable d,
    int x,
    int y,
    unsigned int width,
    unsigned int height,
    unsigned long plane_mask,
    int format)
{
    NSBitmapImageRep *bitmap_rep;
    NSUInteger         bitmap_fmt;
    XImage *       imagePtr = NULL;
    char *           bitmap = NULL;
    char *           image_data=NULL;
    int	        depth = 32;
    int	        offset = 0;
    int	        bitmap_pad = 0;
    int	        bytes_per_row = 4*width;
    int                size;
    MacDrawable *macDraw = (MacDrawable *) d; // Where is this variable used? May it be removed?
    int scalefactor = 1;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
    NSWindow *win = TkMacOSXDrawableWindow(d);
    /* This code assumes that backing scale factors are integers.  Currently
     * Retina displays use a scale factor of 2.0 and normal displays use 1.0.
     * We do not support any other values here.
     */
    if (win && [win respondsToSelector:@selector(backingScaleFactor)]) {
	scalefactor = ([win backingScaleFactor] == 2.0) ? 2 : 1;
    }
#endif
    int scaled_height = height * scalefactor;
    int scaled_width = width * scalefactor;

    if (format == ZPixmap) {
	if (width == 0 || height == 0) {
	    /* This happens all the time.
	    TkMacOSXDbgMsg("XGetImage: empty image requested");
	    */
	    return NULL;
	}

	bitmap_rep =  BitmapRepFromDrawableRect(d, x, y, width, height);
	bitmap_fmt = [bitmap_rep bitmapFormat];

	if ( bitmap_rep == Nil                        ||
	     (bitmap_fmt != 0 && bitmap_fmt != 1)     ||
	     [bitmap_rep samplesPerPixel] != 4 ||
	     [bitmap_rep isPlanar] != 0               ) {
	    TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep");
	    return NULL;
	}

	NSSize image_size = NSMakeSize(width, height);
	NSImage* ns_image = [[NSImage alloc]initWithSize:image_size];
	[ns_image addRepresentation:bitmap_rep];

	/* Assume premultiplied nonplanar data with 4 bytes per pixel.*/
	if ( [bitmap_rep isPlanar ] == 0 &&
	     [bitmap_rep samplesPerPixel] == 4 ) {
	    bytes_per_row = [bitmap_rep bytesPerRow];
	    assert(bytes_per_row == 4 * scaled_width);
	    assert([bitmap_rep bytesPerPlane] == bytes_per_row * scaled_height);
	    size = bytes_per_row*scaled_height;
	    image_data = (char*)[bitmap_rep bitmapData];
	    if ( image_data ) {
		int row, n, m;
		bitmap = ckalloc(size);
		/*
		  Oddly enough, the bitmap has the top row at the beginning,
		  and the pixels are in BGRA or ABGR format.
		*/
		if (bitmap_fmt == 0) {
		    /* BGRA */
		    for (row=0, n=0; row<scaled_height; row++, n+=bytes_per_row) {
			for (m=n; m<n+bytes_per_row; m+=4) {
			    *(bitmap+m)   = *(image_data+m+2);
			    *(bitmap+m+1) = *(image_data+m+1);
			    *(bitmap+m+2) = *(image_data+m);
			    *(bitmap+m+3) = *(image_data+m+3);
			}
		    }
		} else {
		    /* ABGR */
		    for (row=0, n=0; row<scaled_height; row++, n+=bytes_per_row) {
			for (m=n; m<n+bytes_per_row; m+=4) {
			    *(bitmap+m)   = *(image_data+m+3);
			    *(bitmap+m+1) = *(image_data+m+2);
			    *(bitmap+m+2) = *(image_data+m+1);
			    *(bitmap+m+3) = *(image_data+m);
			}
		    }
		}
	    }
	}
	if (bitmap) {
	    imagePtr = XCreateImage(display, NULL, depth, format, offset,
				    (char*)bitmap, scaled_width, scaled_height,
				    bitmap_pad, bytes_per_row);
	    if (scalefactor == 2) {
	    	imagePtr->pixelpower = 1;
	     }
	    [ns_image removeRepresentation:bitmap_rep]; /*releases the rep*/
	    [ns_image release];
	}
    } else {
	TkMacOSXDbgMsg("Could not extract image from drawable.");
    }
    return imagePtr;
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyImage --
 *
 *	Destroys storage associated with an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Deallocates the image.
 *
 *----------------------------------------------------------------------
 */

static int
DestroyImage(
    XImage *image)
{
    if (image) {
	if (image->data) {
	    ckfree(image->data);
	}
	ckfree(image);
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * ImageGetPixel --
 *
 *	Get a single pixel from an image.
 *
 * Results:
 *	Returns the 32 bit pixel value.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static unsigned long
ImageGetPixel(
    XImage *image,
    int x,
    int y)
{
    unsigned char r = 0, g = 0, b = 0;

    if (image && image->data) {
	unsigned char *srcPtr = ((unsigned char*) image->data)
		+ (y * image->bytes_per_line)
		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);

	switch (image->bits_per_pixel) {
	    case 32: {
		r = (*((unsigned int*) srcPtr) >> 16) & 0xff;
		g = (*((unsigned int*) srcPtr) >>  8) & 0xff;
		b = (*((unsigned int*) srcPtr)      ) & 0xff;
		/*if (image->byte_order == LSBFirst) {
		    r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0];
		} else {
		    r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3];
		}*/
		break;
	    }
	    case 16:
		r = (*((unsigned short*) srcPtr) >> 7) & 0xf8;
		g = (*((unsigned short*) srcPtr) >> 2) & 0xf8;
		b = (*((unsigned short*) srcPtr) << 3) & 0xf8;
		break;
	    case 8:
		r = (*srcPtr << 2) & 0xc0;
		g = (*srcPtr << 4) & 0xc0;
		b = (*srcPtr << 6) & 0xc0;
		r |= r >> 2 | r >> 4 | r >> 6;
		g |= g >> 2 | g >> 4 | g >> 6;
		b |= b >> 2 | b >> 4 | b >> 6;
		break;
	    case 4: {
		unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4);
		r = (c & 0x04) ? 0xff : 0;
		g = (c & 0x02) ? 0xff : 0;
		b = (c & 0x01) ? 0xff : 0;
		break;
		}
	    case 1:
		r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0;
		break;
	}
    }
    return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b;
}

/*
 *----------------------------------------------------------------------
 *
 * ImagePutPixel --
 *
 *	Set a single pixel in an image.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
ImagePutPixel(
    XImage *image,
    int x,
    int y,
    unsigned long pixel)
{
    if (image && image->data) {
	unsigned char r = ((pixel & image->red_mask)   >> 16) & 0xff;
	unsigned char g = ((pixel & image->green_mask) >>  8) & 0xff;
	unsigned char b = ((pixel & image->blue_mask)       ) & 0xff;
	unsigned char *dstPtr = ((unsigned char*) image->data)
		+ (y * image->bytes_per_line)
		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);

	switch (image->bits_per_pixel) {
	    case 32:
		*((unsigned int*) dstPtr) = (0xff << 24) | (r << 16) |
			(g << 8) | b;
		/*if (image->byte_order == LSBFirst) {
		    dstPtr[3] = 0xff; dstPtr[2] = r; dstPtr[1] = g; dstPtr[0] = b;
		} else {
		    dstPtr[0] = 0xff; dstPtr[1] = r; dstPtr[2] = g; dstPtr[3] = b;
		}*/
		break;
	    case 16:
		*((unsigned short*) dstPtr) = ((r & 0xf8) << 7) |
			((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
		break;
	    case 8:
		*dstPtr = ((r & 0xc0) >> 2) | ((g & 0xc0) >> 4) |
			((b & 0xc0) >> 6);
		break;
	    case 4: {
		unsigned char c = ((r & 0x80) >> 5) | ((g & 0x80) >> 6) |
			((b & 0x80) >> 7);
		*dstPtr = (x % 2) ? ((*dstPtr & 0xf0) | (c & 0x0f)) :
			((*dstPtr & 0x0f) | ((c << 4) & 0xf0));
		break;
		}
	    case 1:
		*dstPtr = ((r|g|b) & 0x80) ? (*dstPtr | (0x80 >> (x % 8))) :
			(*dstPtr & ~(0x80 >> (x % 8)));
		break;
	}
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * XChangeWindowAttributes, XSetWindowBackground,
 * XSetWindowBackgroundPixmap, XSetWindowBorder, XSetWindowBorderPixmap,
 * XSetWindowBorderWidth, XSetWindowColormap
 *
 *	These functions are all no-ops. They all have equivalent Tk calls that
 *	should always be used instead.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
XChangeWindowAttributes(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned long),
    TCL_UNUSED(XSetWindowAttributes *))
    Display *display,
    Window w,
    unsigned long value_mask,
    XSetWindowAttributes *attributes)
{
    return Success;
}

int
void
XSetWindowBackground(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned long))
    Display *display,
    Window window,
    unsigned long value)
{
    return Success;
}

int
void
XSetWindowBackgroundPixmap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Pixmap))
    Display *display,
    Window w,
    Pixmap background_pixmap)
{
    return Success;
}

int
void
XSetWindowBorder(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned long))
    Display *display,
    Window w,
    unsigned long border_pixel)
{
    return Success;
}

int
void
XSetWindowBorderPixmap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Pixmap))
    Display *display,
    Window w,
    Pixmap border_pixmap)
{
    return Success;
}

int
void
XSetWindowBorderWidth(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned int))
    Display *display,
    Window w,
    unsigned int width)
{
    return Success;
}

int
void
XSetWindowColormap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Colormap))
    Display *display,
    Window w,
    Colormap colormap)
{
    Debugger();
    return Success;
}

Status
XStringListToTextProperty(
    TCL_UNUSED(char **),
    TCL_UNUSED(int),
    TCL_UNUSED(XTextProperty *))
    char **list,
    int count,
    XTextProperty *text_prop_return)
{
    Debugger();
    return Success;
    return (Status) 0;
}

void
XSetWMClientMachine(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(XTextProperty *))
    Display *display,
    Window w,
    XTextProperty *text_prop)
{
    Debugger();
}

XIC
XCreateIC(TCL_UNUSED(XIM), ...)
XCreateIC(void)
{
    Debugger();
    return (XIC) 0;
}

int
XDeleteProperty(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom))
{
    return Success;
}

int
XGetInputFocus(
    Display *display,
    TCL_UNUSED(Window *),
    TCL_UNUSED(int *))
{
    LastKnownRequestProcessed(display)++;
    return Success;
}

VisualID
XVisualIDFromVisual(
    Visual *visual)
{
    return visual->visualid;
}

XAfterFunction
XSynchronize(
    Display *display,
    TCL_UNUSED(Bool))
{
    LastKnownRequestProcessed(display)++;
    return NULL;
}

int
XUngrabServer(
    TCL_UNUSED(Display *))
{
    return 0;
}

int
XFreeCursor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Cursor))
{
    return Success;
}

int
XNoOp(
    Display *display)
{
    LastKnownRequestProcessed(display)++;
    return 0;
}

int
XGrabServer(
    TCL_UNUSED(Display *))
{
    return 0;
}

int
XFree(
    void *data)
{
	if ((data) != NULL) {
		ckfree(data);
	}
    return 0;
}

int
XFlush(
    TCL_UNUSED(Display *))
{
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetDefaultScreenName --
 *
 *	Returns the name of the screen that Tk should use during
 *	initialization.
 *
 * Results:
 *	Returns a statically allocated string.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

const char *
TkGetDefaultScreenName(
    TCL_UNUSED(Tcl_Interp *),
    Tcl_Interp *interp,		/* Not used. */
    const char *screenName)		/* If NULL, use default string. */
{
#if 0
    if ((screenName == NULL) || (screenName[0] == '\0')) {
	screenName = macScreenName;
    }
    return screenName;
#endif
    return macScreenName;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetUserInactiveTime --
 *
 *	Return the number of milliseconds the user was inactive.
 *
 * Results:
 *	The number of milliseconds the user has been inactive, or -1 if
 *	querying the inactive time is not supported.
 *
 * Side effects:
 *	None.
 *----------------------------------------------------------------------
 */

long
Tk_GetUserInactiveTime(
    TCL_UNUSED(Display *))
    Display *dpy)
{
    io_registry_entry_t regEntry;
    CFMutableDictionaryRef props = NULL;
    CFTypeRef timeObj;
    long ret = -1l;
    uint64_t time;
    IOReturn result;

    regEntry = IOServiceGetMatchingService(0,
    regEntry = IOServiceGetMatchingService(kIOMasterPortDefault,
	    IOServiceMatching("IOHIDSystem"));

    if (regEntry == 0) {
	return -1l;
    }

    result = IORegistryEntryCreateCFProperties(regEntry, &props,
	    kCFAllocatorDefault, 0);
    IOObjectRelease(regEntry);

    if (result != KERN_SUCCESS || props == NULL) {
	return -1l;
    }

    timeObj = CFDictionaryGetValue(props, CFSTR("HIDIdleTime"));

    if (timeObj) {
	CFTypeID type = CFGetTypeID(timeObj);

	if (type == CFDataGetTypeID()) { /* Jaguar */
	    CFDataGetBytes((CFDataRef) timeObj,
		    CFRangeMake(0, sizeof(time)), (UInt8 *) &time);
	    /* Convert nanoseconds to milliseconds. */
	    /* ret /= kMillisecondScale; */
	    ret = (long) (time/kMillisecondScale);
	} else if (type == CFNumberGetTypeID()) { /* Panther+ */
	    CFNumberGetValue((CFNumberRef)timeObj,
		    kCFNumberSInt64Type, &time);
	    /* Convert nanoseconds to milliseconds. */
	    /* ret /= kMillisecondScale; */
	    ret = (long) (time/kMillisecondScale);
	} else {
	    ret = -1l;
	}
    }
    /* Cleanup */
    CFRelease(props);

    /*
     * If the idle time reported by the system is larger than the elapsed
     * time since the last reset, return the elapsed time.
     */
    long elapsed = (long)(TkpGetMS() - lastInactivityReset);
    if (ret > elapsed) {
    	ret = elapsed;
    }

    return ret;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_ResetUserInactiveTime --
1225
1226
1227
1228
1229
1230
1231
1232

1233





1234

















1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395







-
+

+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










 *	to zero.
 *
 *----------------------------------------------------------------------
 */

void
Tk_ResetUserInactiveTime(
    TCL_UNUSED(Display *))
    Display *dpy)
{
    IOGPoint loc;
    kern_return_t kr;
    NXEvent nullEvent = {NX_NULLEVENT, {0, 0}, 0, -1, 0};
    enum { kNULLEventPostThrottle = 10 };
    static io_connect_t io_connection = MACH_PORT_NULL;
    lastInactivityReset = TkpGetMS();

    if (io_connection == MACH_PORT_NULL) {
	io_service_t service = IOServiceGetMatchingService(
		kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));

	if (service == MACH_PORT_NULL) {
	    return;
	}
	kr = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType,
		&io_connection);
	IOObjectRelease(service);
	if (kr != KERN_SUCCESS) {
	    return;
	}
    }
    kr = IOHIDPostEvent(io_connection, NX_NULLEVENT, loc, &nullEvent.data,
	    FALSE, 0, FALSE);
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to macosx/ttkMacOSXTheme.c.

1
2
3
4

5
6
7
8
9
10





11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26






27
28
29



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73

74
75
76

77
78

79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172

173
174
175
176
177
178

179
180
181
182


183
184
185
186
187

188
189
190
191

192
193
194
195
196
197




198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

535
536
537
538

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568












569
570


571
572
573
574

575
576
577
578
579
580
581

582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663

664
665
666
667
668
669
670
671
672
673
674
675
676


677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720

721
722
723

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794

795
796
797
798
799
800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850

851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

866
867
868
869
870
871

872
873
874
875
876
877
878
879
880

881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

897
898
899
900
901
902

903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923

924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060

1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072

1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243

1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277

1278
1279
1280
1281

1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311

1312
1313


1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1372
1373

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415

1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458

1459
1460
1461


1462
1463
1464

1465
1466
1467
1468
1469
1470
1471

1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544

1545
1546
1547
1548
1549

1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577

1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589

1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655

1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211

3212
3213

3214
3215
3216
3217

3218
3219
3220
3221




3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232









3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278

3279
3280
3281

3282
3283
3284
3285

3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3314
3315
3316

3317
3318
3319
3320
3321


3322
3323
3324
3325
3326
3327
3328





3329

3330
3331

3332
3333
3334
3335
3336

3337
3338
3339
3340
3341

3342
3343

3344
3345
3346
3347
3348
3349
3350


3351
3352
3353
3354
3355
3356
3357
3358
3359
3360

3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379

3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395

3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406


3407
3408
3409
3410
3411


3412
3413
3414
3415
3416


3417
3418
3419
3420
3421


3422
3423
3424
3425
3426



3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477


3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500




3501
3502
3503

3504
3505
3506

3507
3508
3509
3510

3511
3512

3513
3514
3515
3516
3517
3518
3519



3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538

3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569

3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582

3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610


3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629

3630
3631

3632
3633
3634
3635

3636
3637
3638
3639
3640



3641
3642

3643
3644
3645
3646
3647
3648
3649
3650

3651
3652
3653

3654
3655
3656
3657

3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674



3675
3676

3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692

3693
3694
3695
3696
3697

3698
3699
3700
3701
3702
3703
3704
3705

1
2
3

4
5





6
7
8
9
10

11
12
13
14
15
16
17

18
19
20





21
22
23
24
25
26
27


28
29
30
31
32
33
34



35










36




37









38

39










40



41


42







43
















44







45










46
47




















48


























49

50






51
52
53
54
55
56

57
58



59
60


61


62


63

64
65
66




67
68
69
70
71
72
73
74
























































































75







76














77




























































































































































































































78

79




80






























81
82
83
84
85
86
87
88
89
90
91
92


93
94




95

96





97












98






































































99













100
101



































102

103







104



105

































106
































107






108









109












110

































111

112















113






114









115
















116






117









118












119













































































































120
























121




122







123





124





125






126





































































































































127






128




















129




130











131



















132




133











134



















135


136
137







































138










139

140









141




























142














143






144







145
























146






147



148
149



150







151























152


















































153





154


155










156
















157












158































































159


160





161











162


163



164
165
166
167

168





169
170


171
172

173

174

175

176




177
178
179



180



181
182
183


184
185



186




187
188
189
190
191
192
193






194
195








196
197






198






199
200

201
202
203

204



205


206



207
208
209

210









211















































































212

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232








233
234
235
236
237
238
239
240
241
242





243
244
245
246
247
248
249
250





251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

274

275
276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297

298





299
300
301

302
303
304
305
306




307
308


309
310















311
312
313
314
315
316
317
318
319



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

337

338





339
340
341
342
343
344




345
346


347
348
349
350
351
352
353
354
355
356
357
358
359
360














361

362
363
364
365
366
367
368
369
370
371
372


373
374




375
376
377
378
379
380
381
382

383

384





385
386

387
388
389
390




391
392


393
394










395
396
397
398
399


400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

415



416
417
418
419
420

421

422
423


424


425
426



427
428
429
430

431





432
433

434
435
436
437

438



439


440

441






442


443





444















445
446
447
448
449
450
451

452







453
454













455
456
457
458
459











460
461
462
463
464

465
466
467
468
469
470
471
472
473
474
475

476
477
478



479











480
481
482


483
484
485
486

487





488
489



490
491
492
493
494
495




496
497


498

499
500
501
502
503
504
505
506
507
508






509


510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527



528
529
530













531
532

533



534
535













536







537
538
539
540

541
542

543
544
545

546




547
548


549
550


551
























552








553



















554
555

556
557
558
559
560
561
562




563


564
565
566

567
568
569
570
571

572
573
574
575
576
577


578
579
580









581
582
583
584
585
586
587



588
589
590
591
592
593
594
595
596
597
598




599
600
601
602
603
604
605





606
607
608
609
610
611
612
613

614





615
616


617
618
619
620

621
622
623
624

625



626


627




628
629
630
631

632
633
634
635
636
637
638


639
640
641




642
643
644
645
646


647
648
649

650
651
652
653
654

655






656
657
658


659






660




661

662
663
664
665
666
667
668
669
670
671
672


673
674

675
676
677
678
679
680
681
682

683

684





685
686

687
688
689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
706





707
708
709
710
711
712
713
714











715
716
717
718
719
720
721
722
723
724
725
726
727
728

729





730
731

732
733
734

735
736
737
738


739


740


741


742
743

744



745
746
747
748
749

750

751











752
753
754


755
756
757
758
759
760


761
762
763
764
765
766
767




768

769
770
771
772
773
774
775
776
777
778
779
















































































































































































































































780
781
782



783
784
785
786
787
788

789





790
791

792
793
794
795




796
797


798
799
800
801


802
803

804
805
806




807


808
809
810
811
812
813
814
815
816
817
818
819

820
821

822

823
824
825

826





827
828
829
830
831
832
833
834
835
836
837
838


839
840
841
842
843

844



845


846
847
848
849


850
851

852
853
854
855
856
857

858

859
860
861
862
863
864
865
866
867
868
869
870

871
872


873



874




















875








876


877
878


879

880
881
882




883
884


885
886










887
888
889
890






891
892
893
894
895
896
897

898

899



900


901
902


903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925




926
927
928
929
930



931
932
933
934
935

936




937
938


939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958











































959


960


961
962
963




964
965
966
967
968










969
970
971
972
973
974
975
976
977
978
979










































980

981



982


983

984
985
986
987
988
989
990
991
992
993
994











995


996
997
998
999
1000
1001
1002

1003
1004
1005
1006


1007
1008
1009






1010
1011
1012
1013
1014
1015
1016
1017

1018





1019
1020
1021
1022
1023

1024
1025

1026
1027
1028
1029




1030
1031


1032
1033


1034
1035
1036

1037
1038
1039
1040
1041
1042
1043













1044


1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1065
1066
1067


1068
1069
1070
1071
1072


1073
1074
1075
1076
1077


1078
1079
1080
1081
1082


1083
1084
1085
1086



1087
1088
1089
1090













































1091
1092
1093


1094
1095



















1096
1097


1098
1099
1100
1101
1102


1103



1104
1105
1106
1107

1108
1109

1110
1111
1112
1113
1114



1115
1116
1117
1118














1119
1120
1121

1122
1123
1124





























1125

1126
1127
1128
1129
1130
1131
1132
1133
1134
1135


1136

1137

1138
1139
1140
1141
1142




1143
1144
1145
1146




1147
1148
1149
1150




1151
1152






1153
1154
1155
1156
1157
1158
1159


1160
1161
1162

1163


1164




1165

1166



1167
1168
1169
1170

1171
1172
1173
1174





1175



1176




1177












1178




1179
1180
1181


1182



1183
1184
1185
1186

1187
1188
1189
1190
1191
1192
1193

1194

1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205
1206
1207



-
+

-
-
-
-
-
+
+
+
+
+
-







-
+


-
-
-
-
-
+
+
+
+
+
+

-
-
+
+
+




-
-
-

-
-
-
-
-
-
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
+





-
+

-
-
-
+
+
-
-

-
-
+
-
-

-
+


-
-
-
-
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
-

-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-




-
+
-
-
-
-
-
+

-
-
+
+
-

-
+
-

-
+
-
-
-
-
+
+
+
-
-
-
+
-
-
-
+
+
+
-
-
+
+
-
-
-
+
-
-
-
-
+
+
+
+
+


-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-


-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
-



-
+
-
-
-
+
-
-

-
-
-
+
+
+
-

-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-















+

+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

+
-
-
-
-
-
+
+
+
+
+
+

+
-
-
-
-
-
+
+
+
+
+
+

















-
+
-













-










-
+
-
-
-
-
-
+

+
-
+
+



-
-
-
-
+
+
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+














-

-
+
-
-
-
-
-
+





-
-
-
-
+
+
-
-


+
+
+
+
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-











-
-
+
+
-
-
-
-
+
+
+
+

+
+

-

-
+
-
-
-
-
-
+

-
+



-
-
-
-
+
+
-
-


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+












-
+
-
-
-
+
+



-
+
-


-
-

-
-
+
+
-
-
-
+



-
+
-
-
-
-
-
+

-
+



-
+
-
-
-
+
-
-

-
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-











-
+


-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+


-
-
+
+


-
+
-
-
-
-
-
+

-
-
-
+
+
+



-
-
-
-
+
+
-
-

-
+









-
-
-
-
-
-
+
-
-











+
+
+
+

-
+

-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-




-
+

-
+


-
+
-
-
-
-
+
+
-
-


-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+






-
-
-
-
+
-
-



-
+




-
+

+



-
-
+


-
-
-
-
-
-
-
-
-
+
+
+
+



-
-
-
+
+
+






+

-
-
-
-
+
+
+
+



-
-
-
-
-
+
+
+
+
+

+

-
+
-
-
-
-
-
+

-
-
+
+


-
+



-
+
-
-
-
+
-
-

-
-
-
-
+
+
+
+
-





+

-
-



-
-
-
-
+
+
+
+

-
-
+
+

-
+




-
+
-
-
-
-
-
-
+
+
+
-
-

-
-
-
-
-
-
+
-
-
-
-
+
-











-
-
+
+
-




+
+
+

-

-
+
-
-
-
-
-
+

-
+











-
+







-
-
-
-
-
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

+

-
+
-
-
-
-
-
+

-
+


-
+



-
-
+
-
-
+
-
-

-
-
+
+
-

-
-
-





-
+
-

-
-
-
-
-
-
-
-
-
-
-


+
-
-
+
+




-
-
+
+





-
-
-
-
+
-











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
+
+
+



-
+
-
-
-
-
-
+

-
+



-
-
-
-
+
+
-
-




-
-
+
+
-



-
-
-
-
+
-
-












-
+

-

-
+


-
+
-
-
-
-
-
+











-
-
+
+



-
+
-
-
-
+
-
-




-
-
+
+
-






-
+
-












-
+

-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
+
+
-
-
+
-



-
-
-
-
+
+
-
-


-
-
-
-
-
-
-
-
-
-
+


+
-
-
-
-
-
-
+
+
+
+
+
+
+
-

-
+
-
-
-
+
-
-

+
-
-
+
+









+











-
-
-
-
+
+
+
+

-
-
-
+
+
+


-

-
-
-
-
+
+
-
-




















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-


+
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
+
-
-

-
+










-
-
-
-
-
-
-
-
-
-
-
+
-
-







-
+



-
-
+
+

-
-
-
-
-
-
+
+
+
+
+

+

-
+
-
-
-
-
-
+




-
+

-
+



-
-
-
-
+
+
-
-


-
-



-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-













-
+









-
-
+
+



-
-
+
+



-
-
+
+



-
-
+
+


-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+
+
+

-
-
+
-
-
-
+



-
+

-
+




-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-










-
-
+
-

-





-
-
-
-




-
-
-
-




-
-
-
-
+
+
-
-
-
-
-
-







-
-



-
+
-
-
+
-
-
-
-
+
-

-
-
-
+
+
+

-
+



-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
+
+
+
-
-
+
-
-
-




-







-
+
-



-
+








+
/*
 * ttkMacOSXTheme.c --
 *
 *      Tk theme engine for Mac OSX, using the Appearance Manager API.
 *	Tk theme engine for Mac OSX, using the Appearance Manager API.
 *
 * Copyright © 2004 Joe English
 * Copyright © 2005 Neil Madden
 * Copyright © 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright © 2008-2009 Apple Inc.
 * Copyright © 2009 Kevin Walzer/WordTech Communications LLC.
 * Copyright (c) 2004 Joe English
 * Copyright (c) 2005 Neil Madden
 * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
 * Copyright 2008-2009, Apple Inc.
 * Copyright 2009 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2019 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * See also:
 *
 * <URL: http://developer.apple.com/documentation/Carbon/Reference/
 *      Appearance_Manager/appearance_manager/APIIndex.html >
 *	Appearance_Manager/appearance_manager/APIIndex.html >
 *
 * Notes:
 *      "Active" means different things in Mac and Tk terminology --
 *      On Aqua, widgets are "Active" if they belong to the foreground window,
 *      "Inactive" if they are in a background window.  Tk uses the term
 *      "active" to mean that the mouse cursor is over a widget; aka "hover",
 *      "prelight", or "hot-tracked".  Aqua doesn't use this kind of feedback.
 *	"Active" means different things in Mac and Tk terminology --
 *	On Aqua, widgets are "Active" if they belong to the foreground window,
 *	"Inactive" if they are in a background window.
 *	Tk uses the term "active" to mean that the mouse cursor
 *	is over a widget; aka "hover", "prelight", or "hot-tracked".
 *	Aqua doesn't use this kind of feedback.
 *
 *      The QuickDraw/Carbon coordinate system is relative to the top-level
 *      window, not to the Tk_Window.  BoxToRect() accounts for this.
 *	The QuickDraw/Carbon coordinate system is relative to the
 *	top-level window, not to the Tk_Window.  BoxToRect()
 *	accounts for this.
 */

#include "tkMacOSXPrivate.h"
#include "ttk/ttkTheme.h"
#include "ttkMacOSXTheme.h"
#include "tkColor.h"
#include <math.h>

MODULE_SCOPE NSColor *controlAccentColor(void) {
    static int accentPixel = -1;
    if (accentPixel == -1) {
	TkColor *temp = TkpGetColor(NULL, "systemControlAccentColor");
	accentPixel = temp->color.pixel;
	ckfree(temp);
    }
    return TkMacOSXGetNSColor(NULL, accentPixel);
}

/*
 * Values which depend on the OS version.  These are initialized
 * in Ttk_MacOSXInit.
 */

 * Use this version in the core:
static Ttk_Padding entryElementPadding;
static CGFloat Ttk_ContrastDelta;

/*----------------------------------------------------------------------
 * +++ ComputeButtonDrawInfo --
 *
 *      Fill in an appearance manager HIThemeButtonDrawInfo record
 *      from a Ttk state and the ThemeButtonParams used as the
 *      clientData.
 */

#define BEGIN_DRAWING(d) { \
static inline HIThemeButtonDrawInfo ComputeButtonDrawInfo(
    ThemeButtonParams *params,
    Ttk_State state,
    TCL_UNUSED(Tk_Window))
{
    /*
     * See ButtonElementDraw for the explanation of why we always draw
     * some buttons in the active state.
     */

	TkMacOSXDrawingContext dc; \
    SInt32 HIThemeState;
    int adornment = 0;

	if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;}
    HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);

#define END_DRAWING \
    /*
     * HITheme uses the adornment to decide the direction of the
     * arrow on a Disclosure Button.  Also HITheme draws inactive
     * (TTK_STATE_BACKGROUND) buttons in a gray color but macOS
     * no longer does that.  So we adjust the HIThemeState.
     */

	TkMacOSXRestoreDrawingContext(&dc); }
    switch (params->kind) {
    case kThemeArrowButton:
	adornment = kThemeAdornmentDrawIndicatorOnly;
	if (state & TTK_STATE_SELECTED) {
	    adornment |= kThemeAdornmentArrowUpArrow;
	}
	/* Fall through. */
    case kThemeRadioButton:
	/*
	 * The gray color is better than the blue color for a
	 * background selected Radio Button.
	 */

	if (state & TTK_STATE_SELECTED) {
	    break;
	}

    default:
	if (state & TTK_STATE_BACKGROUND) {
	    HIThemeState |= kThemeStateActive;
	}
	break;
    }

#define HIOrientation kHIThemeOrientationNormal
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = HIThemeState,
	.kind = params ? params->kind : 0,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state) | adornment,
    };
    return info;
}


#ifdef __LP64__
/*
 * When we draw simulated Apple widgets we use the Core Graphics framework.
 * Core Graphics uses CGColorRefs, not NSColors.  A CGColorRef must be retained
 * and released explicitly while an NSColor is autoreleased.  In version 10.8
 * of macOS Apple introduced a CGColor property of an NSColor which is guaranteed
 * to be a valid CGColorRef for (approximately) the same color and is released
 * when the NSColor is autoreleased.
 *
 * When building on systems earlier than 10.8 there is no painless way to
 * convert an NSColor to a CGColor. On the other hand, on those systems we use
 * the HIToolbox to draw all widgets, so we never need to call Core Graphics
 * drawing routines directly.  This means that the functions and macros below
 * which construct CGColorRefs can be defined to return nil on systems before
 * 10.8.
 *
 * Similarly, those older systems did not have CGPathCreateWithRoundedRect, but
 * since we never need to draw rounded rectangles on those systems we can just
 * define it to return nil.
 */

#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
static CGColorRef
CGColorFromRGBA(
    CGFloat *rgba)
{
    NSColorSpace *colorSpace = [NSColorSpace sRGBColorSpace];
    NSColor *nscolor = [NSColor colorWithColorSpace: colorSpace
					 components: rgba
					      count: 4];
    return nscolor.CGColor;
}

static CGColorRef
CGColorFromGray(
    GrayColor g)
{
    CGFloat rgba[4] = {g.grayscale, g.grayscale, g.grayscale, g.alpha};
    NSColorSpace *colorSpace = [NSColorSpace sRGBColorSpace];
    NSColor *nscolor = [NSColor colorWithColorSpace: colorSpace
					 components: rgba
					      count: 4];
    return nscolor.CGColor;
}

#define CGCOLOR(nscolor) (nscolor).CGColor

#else

#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
#define CGCOLOR(nscolor) NULL
#define CGColorFromRGBA(rgba) NULL
#define CGColorFromGray(gray) NULL
#define CGPathCreateWithRoundedRect(w, x, y, z) NULL

#endif
#endif /* __LP64__ */

/*----------------------------------------------------------------------
 * +++ Utilities.
 */

/*----------------------------------------------------------------------
/*
 * BoxToRect --
 *
 *    Convert a Ttk_Box in Tk coordinates relative to the given Drawable to a
 *    native CGRect relative to the containing NSView.  (The coordinate system
 *	Convert a Ttk_Box in Tk coordinates relative to the given Drawable
 *	to a native Rect relative to the containing port.
 *    is the one used by CGContextRef, which has origin at the upper left
 *    corner, and y increasing downward.)
 */

static inline CGRect BoxToRect(
static inline CGRect BoxToRect(Drawable d, Ttk_Box b)
    Drawable d,
    Ttk_Box b)
{
    MacDrawable *md = (MacDrawable *)d;
    MacDrawable *md = (MacDrawable*)d;
    CGRect rect;

    rect.origin.y       = b.y + md->yOff;
    rect.origin.x       = b.x + md->xOff;
    rect.size.height    = b.height;
    rect.size.width     = b.width;
    rect.origin.y	= b.y + md->yOff;
    rect.origin.x	= b.x + md->xOff;
    rect.size.height	= b.height;
    rect.size.width	= b.width;

    return rect;
}

/*----------------------------------------------------------------------
 * LookupGrayPalette
 *
 * Retrieves the palette of grayscale colors needed to draw a particular
 * type of button, in a particular state, in light or dark mode.
 *
 */

static GrayPalette LookupGrayPalette(
    const ButtonDesign *design,
    Ttk_State state,
    int isDark)
{
    const PaletteStateTable *entry = design->palettes;
    while ((state & entry->onBits) != entry->onBits ||
           (~state & entry->offBits) != entry->offBits)
    {
        ++entry;
    }
    return isDark ? entry->dark : entry->light;
}

/*----------------------------------------------------------------------
 * NormalizeButtonBounds --
 *
 *      This function returns the actual bounding rectangle that will be used
 *      in drawing the button.
 *
 *      Apple only allows three specific heights for most buttons: regular,
 *      small and mini. We always use the regular size.  However, Ttk may
 *      provide a bounding rectangle with arbitrary height.  We draw the Mac
 *      button centered vertically in the Ttk rectangle, with the same width as
 *      the rectangle.  (But we take care to produce an integer y coordinate,
 *      to avoid unexpected anti-aliasing.)
 *
 *      In addition, the button types which are not known to HIToolbox need some
 *      adjustments to their bounds.
 *
 */

static CGRect NormalizeButtonBounds(
    ThemeButtonParams *params,
    CGRect bounds,
    int isDark)
{
    SInt32 height;

    if (params->heightMetric != NoThemeMetric) {
	ChkErr(GetThemeMetric, params->heightMetric, &height);
	height += 2;
	bounds.origin.y += round(1 + (bounds.size.height - height) / 2);
	bounds.size.height = height;
    }
    switch (params->kind) {
    case TkRoundedRectButton:
	bounds.size.height -= 1;
	break;
    case TkInlineButton:
	bounds.size.height -= 4;
	bounds.origin.y += 1;
	break;
    case TkRecessedButton:
	bounds.size.height -= 2;
	break;
    case TkSidebarButton:
	bounds.size.height += 8;
	break;
    case kThemeRoundButtonHelp:
	if (isDark) {
	    bounds.size.height = bounds.size.width = 22;
	} else {
	    bounds.size.height = bounds.size.width = 22;
	}
	break;
    default:
	break;
    }
    return bounds;
}

/*----------------------------------------------------------------------
 * +++ Background Colors
 *
 * Support for contrasting background colors when GroupBoxes or Tabbed
 * panes are nested inside each other.  Early versions of macOS used ridged
 * borders, so do not need contrasting backgrounds.
 */

/*
 * For systems older than 10.14, [NSColor windowBackgroundColor] generates
 * garbage when called from this function.  In 10.14 it works correctly, and
 * must be used in order to have a background color which responds to Dark
 * Mode.  So we use this hard-wired RGBA color on the older systems which don't
 * support Dark Mode anyway.
 */

 * Table mapping Tk states to Appearance manager ThemeStates
RGBACOLOR windowBackground[4] = RGBA256(235.0, 235.0, 235.0, 1.0);

/*----------------------------------------------------------------------
 * GetBackgroundColor --
 *
 *      Fills the array rgba with the color coordinates for a background color.
 *      Start with the background color of a window's container, or the
 *      standard ttk window background if there is no container. If the
 *      contrast parameter is nonzero, modify this color to be darker, for the
 *      aqua appearance, or lighter for the DarkAqua appearance.  This is
 *      primarily used by the Fill and Background elements.  The save parameter
 *      is normally YES, so the contrasting color is saved in the private
 *      data of the widget.  This behavior can be disabled in special cases,
 *      such as when drawing notebook tabs in macOS 11.
 */

static void GetBackgroundColorRGBA(
    TCL_UNUSED(CGContextRef),
    Tk_Window tkwin,
    int contrast,
    Bool save,
    CGFloat *rgba)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *containerPtr = (TkWindow *) TkGetContainer(tkwin);

    while (containerPtr && containerPtr->privatePtr) {
	if (containerPtr->privatePtr->flags & TTK_HAS_CONTRASTING_BG) {
	    break;
	}
	containerPtr = (TkWindow *)TkGetContainer(containerPtr);
    }
    if (containerPtr && containerPtr->privatePtr) {
	for (int i = 0; i < 4; i++) {
	    rgba[i] = containerPtr->privatePtr->fillRGBA[i];
	}
    } else {
	if ([NSApp macOSVersion] > 101300) {
	    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
	    NSColor *windowColor = [[NSColor windowBackgroundColor]
		colorUsingColorSpace: deviceRGB];
	    [windowColor getComponents: rgba];
	} else {
	    for (int i = 0; i < 4; i++) {
		rgba[i] = windowBackground[i];
	    }
	}
    }

    if (contrast) {
	int isDark = (rgba[0] + rgba[1] + rgba[2] < 1.5);

	if (isDark) {
	    for (int i = 0; i < 3; i++) {
		rgba[i] += Ttk_ContrastDelta*contrast / 255.0;
	    }
	} else {
	    for (int i = 0; i < 3; i++) {
		rgba[i] -= Ttk_ContrastDelta*contrast / 255.0;
	    }
	}
        if (save && winPtr->privatePtr) {
            winPtr->privatePtr->flags |= TTK_HAS_CONTRASTING_BG;
            for (int i = 0; i < 4; i++) {
                winPtr->privatePtr->fillRGBA[i] = rgba[i];
            }
        }
    }
}

static CGColorRef GetBackgroundCGColor(
    CGContextRef context,
    Tk_Window tkwin,
    int contrast,
    Bool save)
{
    CGFloat rgba[4];
    GetBackgroundColorRGBA(context, tkwin, contrast, save, rgba);
    return CGColorFromRGBA(rgba);
}

/*----------------------------------------------------------------------
 * +++ Buttons
 */

/*----------------------------------------------------------------------
 * FillRoundedRectangle --
 *
 *      Fill a rounded rectangle with a specified solid color.
 */

static void FillRoundedRectangle(
    CGContextRef context,
    CGRect bounds,
    CGFloat radius,
    CGColorRef color)
{
    CGPathRef path;
    CHECK_RADIUS(radius, bounds)

    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    if (!path) {
	return;
    }
    CGContextSetFillColorWithColor(context, color);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    CFRelease(path);
}

/*----------------------------------------------------------------------
 * FillBorder --
 *
 *      Draw a 1-pixel border around a rounded rectangle using a 3-step
 *      gradient of shades of gray.
 */

static void FillBorder(
    CGContextRef context,
    CGRect bounds,
    GrayPalette palette,
    CGFloat radius)
{
    if (bounds.size.width < 2) {
	return;
    }
    NSColorSpace *sRGB = [NSColorSpace sRGBColorSpace];
    CGPoint end = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
    CGFloat corner = (radius > 0 ? radius : 2.0) / bounds.size.height;
    CGFloat locations[4] = {0.0, corner, 1.0 - corner, 1.0};
    CGPathRef path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGFloat colors[16];
    colors[0] = colors[1] = colors[2] = palette.top / 255.0;
    colors[4] = colors[5] = colors[6] = palette.side / 255.0;
    colors[8] = colors[9] = colors[10] = palette.side / 255.0;
    colors[12] = colors[13] = colors[14] = palette.bottom / 255.0;
    colors[3] = colors[7] = colors[11] = colors[15] = 1.0;
    CGGradientRef gradient = CGGradientCreateWithColorComponents(
	 sRGB.CGColorSpace, colors, locations, 4);
    if (!gradient) {
	return;
    }
    CGContextSaveGState(context);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0.0);
    CGContextRestoreGState(context);
    CFRelease(path);
    CFRelease(gradient);
}

/*----------------------------------------------------------------------
 * DrawFocusRing --
 *
 *      Draw a 4-pixel wide rounded focus ring enclosing a rounded
 *      rectangle, using the current system accent color.
 */

static void DrawFocusRing(
    CGContextRef context,
    CGRect bounds,
    const ButtonDesign *design)
{
    CGColorRef highlightColor;
    CGFloat highlight[4] = {1.0, 1.0, 1.0, 0.2};
    CGColorRef focusColor;

    focusColor = CGCOLOR([controlAccentColor() colorWithAlphaComponent:0.6]);
    FillRoundedRectangle(context, bounds, design->radius, focusColor);
    bounds = CGRectInset(bounds, 3, 3);
    highlightColor = CGColorFromRGBA(highlight);
    CGContextSetFillColorWithColor(context, highlightColor);
    CGContextFillRect(context, bounds);
}

/*----------------------------------------------------------------------
 * DrawGrayButton --
 *
 *      Draw a button in normal gray colors.
 *
 *      Aqua buttons are normally drawn in a grayscale color.  The buttons,
 *      which are shaped as rounded rectangles have a 1-pixel border which is
 *      drawn in a 3-step gradient and a solid gray face.
 *
 *      Note that this will produce a round button if length = width =
 *      2*radius.
 */

static void DrawGrayButton(
    CGContextRef context,
    CGRect bounds,
    const ButtonDesign *design,
    Ttk_State state,
    Tk_Window tkwin)
{
    int isDark = TkMacOSXInDarkMode(tkwin);
    GrayPalette palette = LookupGrayPalette(design, state, isDark);
    GrayColor faceGray = {.grayscale = 0.0, .alpha = 1.0};
    CGFloat radius = 2 * design->radius <= bounds.size.height ?
	design->radius : bounds.size.height / 2;
    if (palette.top <= 255.0) {
	FillBorder(context, bounds, palette, radius);
    }
    if (palette.face <= 255.0) {
	faceGray.grayscale = palette.face / 255.0;
    } else {

	/*
	 * Color values > 255 are "transparent" which really means that we
	 * fill with the background color.
	 */

	CGFloat rgba[4], gray;
	GetBackgroundColorRGBA(context, tkwin, 0, NO, rgba);
	gray = (rgba[0] + rgba[1] + rgba[2]) / 3.0;
	faceGray.grayscale = gray;
    }
    FillRoundedRectangle(context, CGRectInset(bounds, 1, 1), radius - 1,
			 CGColorFromGray(faceGray));
}

/*----------------------------------------------------------------------
 * DrawAccentedButton --
 *
 *      The accent color is only used when drawing buttons in the active
 *      window.  Push Buttons and segmented Arrow Buttons are drawn in color
 *      when in the pressed state.  Selected Check Buttons, Radio Buttons and
 *      notebook Tabs are also drawn in color.  The color is based on the
 *      user's current choice for the controlAccentColor, but is actually a
 *      linear gradient with a 1-pixel darker line at the top and otherwise
 *      changing from lighter at the top to darker at the bottom.  This
 *      function draws a colored rounded rectangular button.
 */

static void DrawAccentedButton(
static Ttk_StateTable ThemeStateTable[] = {
    CGContextRef context,
    CGRect bounds,
    const ButtonDesign *design,
    int state,
    {kThemeStateUnavailable, TTK_STATE_DISABLED, 0},
    int isDark)
{
    NSColorSpace *sRGB = [NSColorSpace sRGBColorSpace];
    CGColorRef faceColor = CGCOLOR(controlAccentColor());
    CGFloat radius = design->radius;
    CGPathRef path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    // This gradient should only be used for PushButtons and Tabs, and it needs
    // to be lighter at the top.
    static CGFloat components[12] = {1.0, 1.0, 1.0, 0.05,
				     1.0, 1.0, 1.0, 0.2,
				     1.0, 1.0, 1.0, 0.0};
    CGFloat locations[3] = {0.0, 0.05, 1.0};
    CGGradientRef gradient = CGGradientCreateWithColorComponents(
				 sRGB.CGColorSpace, components, locations, 3);
    CGPoint end;
    if (bounds.size.height > 2*radius) {
	bounds.size.height -= 1;
    }
    end = CGPointMake(bounds.origin.x, bounds.origin.y + bounds.size.height);
    CGContextSaveGState(context);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextClip(context);
    FillRoundedRectangle(context, bounds, radius, faceColor);
    CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0.0);
    if (state & TTK_STATE_PRESSED &&
	state & TTK_STATE_ALTERNATE) {
	CGColorRef color = isDark ?
	    CGColorFromGray(darkPressedDefaultButton) :
	    CGColorFromGray(pressedDefaultButton);
    {kThemeStatePressed, TTK_STATE_PRESSED, 0},
    {kThemeStateInactive, TTK_STATE_BACKGROUND, 0},
    {kThemeStateActive, 0, 0}
/* Others: Not sure what these are supposed to mean.
   Up/Down have something to do with "little arrow" increment controls...
   Dunno what a "Rollover" is.
   NEM: Rollover is TTK_STATE_ACTIVE... but we don't handle that yet, by the
   looks of things
    {kThemeStateRollover, 0, 0},
    {kThemeStateUnavailableInactive, 0, 0}
    {kThemeStatePressedUp, 0, 0},
    {kThemeStatePressedDown, 0, 0}
	FillRoundedRectangle(context, bounds, radius, color);
    }
*/
};
    CGContextRestoreGState(context);
    CFRelease(path);
    CFRelease(gradient);
}


/*----------------------------------------------------------------------
 * DrawAccentedSegment --
 *
 *      Draw the colored ends of widgets like popup buttons and combo buttons.
 */

 * +++ Button element: Used for elements drawn with DrawThemeButton.
static void DrawAccentedSegment(
    CGContextRef context,
    CGRect bounds,
    const ButtonDesign *design,
    Ttk_State state,
    Tk_Window tkwin)
{
    /*
     * Clip to the bounds and then draw an accented button which is extended so
     * that the rounded corners on the left will be clipped off.  This assumes
     * that the bounds include room for the focus ring.
     */
 */
    int isDark = TkMacOSXInDarkMode(tkwin);
    GrayColor sepGray = isDark ? darkComboSeparator : lightComboSeparator;
    CGColorRef sepColor = CGColorFromGray(sepGray);
    CGRect clip = bounds;
    clip.size.height += 10;
    bounds.origin.x -= 10;
    bounds.size.width += 10;
    CGPoint separator[2] = {
	CGPointMake(clip.origin.x - 1, bounds.origin.y + 5),
	CGPointMake(clip.origin.x - 1,
		    bounds.origin.y + bounds.size.height - 3)};
    CGContextSaveGState(context);
    CGContextSetStrokeColorWithColor(context, sepColor);
    CGContextSetShouldAntialias(context, false);
    CGContextSetLineWidth(context, 0.5);
    CGContextAddLines(context, separator, 2);
    CGContextStrokePath(context);
    CGContextSetShouldAntialias(context, true);
    if (state & TTK_STATE_FOCUS) {
	CGRect focusClip = clip;
	clip.size.width += 4;
	CGContextClipToRect(context, focusClip);
	bounds = CGRectInset(bounds, 0, 1);
	DrawFocusRing(context, bounds, design);
    }
    bounds = CGRectInset(bounds, 4, 4);
    if (state & TTK_STATE_BACKGROUND) {
	bounds.size.height += 2;
    } else {
	bounds.size.height += 1;
    }
    CGContextClipToRect(context, clip);
    if ((state & TTK_STATE_BACKGROUND) || (state & TTK_STATE_DISABLED)) {
	DrawGrayButton(context, bounds, design, state, tkwin);
    } else {
	DrawAccentedButton(context, bounds, design, state | TTK_STATE_ALTERNATE,
			   isDark);
    }
    CGContextRestoreGState(context);
}

/*----------------------------------------------------------------------
 * +++ Entry boxes
 */

static void DrawEntry(
    CGContextRef context,
    CGRect bounds,
    const ButtonDesign *design,
    int state,
    Tk_Window tkwin)
{
    int isDark = TkMacOSXInDarkMode(tkwin);
    GrayPalette palette = LookupGrayPalette(design, state, isDark);
    CGColorRef backgroundColor;
    CGFloat bgRGBA[4];
    if (isDark) {
    	GetBackgroundColorRGBA(context, tkwin, 0, NO, bgRGBA);

	/*
	 * Lighten the entry background to provide contrast.
	 */

	for (int i = 0; i < 3; i++) {
		bgRGBA[i] += 8.0 / 255.0;
	    }
	backgroundColor = CGColorFromRGBA(bgRGBA);
    } else {
	backgroundColor = CG_WHITE;
    }

    if (state & TTK_STATE_FOCUS) {
	DrawFocusRing(context, bounds, design);
    } else {
	FillBorder(context, CGRectInset(bounds,3,3), palette, design->radius);
    }
    bounds = CGRectInset(bounds, 4, 4);
    FillRoundedRectangle(context, bounds, design->radius, backgroundColor);
}

/*----------------------------------------------------------------------
 * +++ Chevrons, CheckMarks, etc. --
 */

/*
 * Extra margins to account for drop shadow.
static void DrawDownArrow(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size,
    int state)
{
    CGColorRef strokeColor;
    CGFloat x, y;


    if (state & TTK_STATE_DISABLED) {
	strokeColor = CGCOLOR([NSColor disabledControlTextColor]);
    } else if (state & TTK_STATE_IS_ACCENTED) {
	strokeColor = CG_WHITE;
    } else {
	strokeColor = CGCOLOR([NSColor controlTextColor]);
    }
    CGContextSetStrokeColorWithColor(context, strokeColor);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height / 2) + 1;
    CGContextBeginPath(context);
    CGPoint arrow[3] = {
	{x, y - size / 4}, {x + size / 2, y + size / 4},
	{x + size, y - size / 4}
    };
    CGContextAddLines(context, arrow, 3);
    CGContextStrokePath(context);
}

/*----------------------------------------------------------------------
 * DrawUpArrow --
 *
 * Draws a single upward pointing arrow for ListHeaders and Disclosure Buttons.
 */

static Ttk_Padding ButtonMargins = {2,2,2,2};
static void DrawUpArrow(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size,
    int state)
{

    NSColor *strokeColor;
    CGFloat x, y;

#define NoThemeMetric 0xFFFFFFFF
    if (state & TTK_STATE_DISABLED) {
	strokeColor = [NSColor disabledControlTextColor];
    } else {
	strokeColor = [NSColor controlTextColor];
    }
    CGContextSetStrokeColorWithColor(context, CGCOLOR(strokeColor));
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height / 2);
    CGContextBeginPath(context);
    CGPoint arrow[3] = {
	{x, y + size / 4}, {x + size / 2, y - size / 4},
	{x + size, y + size / 4}
    };
    CGContextAddLines(context, arrow, 3);
    CGContextStrokePath(context);
}

/*----------------------------------------------------------------------
 * DrawUpDownArrows --
 *
 * Draws the double arrows used in menu buttons and spin buttons.
 */

static void DrawUpDownArrows(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size,
    CGFloat gap,
    int state,
    ThemeDrawState drawState)
{

    CGFloat x, y;
    NSColor *topStrokeColor, *bottomStrokeColor;
    if (drawState == BOTH_ARROWS && !(state & TTK_STATE_BACKGROUND)) {
	topStrokeColor = bottomStrokeColor = [NSColor whiteColor];
    } else if (drawState == kThemeStatePressedDown) {
	topStrokeColor = [NSColor controlTextColor];
	bottomStrokeColor = [NSColor whiteColor];
    } else if (drawState == kThemeStatePressedUp) {
	topStrokeColor = [NSColor whiteColor];
	bottomStrokeColor = [NSColor controlTextColor];
    } else if (state & TTK_STATE_DISABLED) {
	topStrokeColor = bottomStrokeColor = [NSColor disabledControlTextColor];
    } else {
	topStrokeColor = bottomStrokeColor = [NSColor controlTextColor];
    }
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height / 2);
    CGContextBeginPath(context);
    CGPoint bottomArrow[3] =
	{{x, y + gap}, {x + size / 2, y + gap + size / 2}, {x + size, y + gap}};
    CGContextAddLines(context, bottomArrow, 3);
    CGContextSetStrokeColorWithColor(context, CGCOLOR(bottomStrokeColor));
    CGContextStrokePath(context);
    CGContextBeginPath(context);
    CGPoint topArrow[3] =
	{{x, y - gap}, {x + size / 2, y - gap - size / 2}, {x + size, y - gap}};
    CGContextAddLines(context, topArrow, 3);
    CGContextSetStrokeColorWithColor(context, CGCOLOR(topStrokeColor));
    CGContextStrokePath(context);
}

typedef struct {
/*----------------------------------------------------------------------
 * DrawClosedDisclosure --
 *
 * Draws a disclosure chevron in the Big Sur style, for Treeviews.
 */

    ThemeButtonKind kind;
static void DrawClosedDisclosure(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size,
    CGFloat *rgba)
{
    CGFloat x, y;

    ThemeMetric heightMetric;
    CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height / 2);
    CGContextBeginPath(context);
    CGPoint arrow[3] = {
	{x, y - size / 4 - 1}, {x + size / 2, y}, {x, y + size / 4 + 1}
    };
    CGContextAddLines(context, arrow, 3);
    CGContextStrokePath(context);
}

} ThemeButtonParams;
/*----------------------------------------------------------------------
 * DrawOpenDisclosure --
 *
 * Draws an open disclosure chevron in the Big Sur style, for Treeviews.
 */

static void DrawOpenDisclosure(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size,
    CGFloat *rgba)
{
    CGFloat x, y;

    CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height / 2);
    CGContextBeginPath(context);
    CGPoint arrow[3] = {
	{x, y - size / 4}, {x + size / 2, y + size / 2}, {x + size, y - size / 4}
    };
    CGContextAddLines(context, arrow, 3);
    CGContextStrokePath(context);
}

/*----------------------------------------------------------------------
 * IndicatorColor --
 *
 * Returns a CGColorRef of the appropriate shade for a check button or
 * radio button in a given state.
 */

static CGColorRef IndicatorColor(
static ThemeButtonParams
   int state,
   int isDark)
{
    if (state & TTK_STATE_DISABLED) {
	return isDark ?
	    CGColorFromGray(darkDisabledIndicator) :
	    CGColorFromGray(lightDisabledIndicator);
    } else if ((state & TTK_STATE_SELECTED || state & TTK_STATE_ALTERNATE) &&
	       !(state & TTK_STATE_BACKGROUND)) {
	return CG_WHITE;
    } else {
	return CGCOLOR([NSColor controlTextColor]);
    }
}

    PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight },
/*----------------------------------------------------------------------
 * DrawCheckIndicator --
 *
 * Draws the checkmark or horizontal bar in a check box.
 */

    CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight },
static void DrawCheckIndicator(
    CGContextRef context,
    CGRect bounds,
    int state,
    int isDark)
{
    CGFloat x = bounds.origin.x, y = bounds.origin.y;
    CGColorRef strokeColor = IndicatorColor(state, isDark);

    RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight },
    CGContextSetStrokeColorWithColor(context, strokeColor);
    if (state & TTK_STATE_SELECTED) {
	CGContextSetLineWidth(context, 1.5);
	CGContextBeginPath(context);
	CGPoint check[3] = {{x + 3, y + 7}, {x + 6, y + 10}, {x + 10, y + 3}};
	CGContextAddLines(context, check, 3);
	CGContextStrokePath(context);
    } else if (state & TTK_STATE_ALTERNATE) {
	CGContextSetLineWidth(context, 2.0);
	CGContextBeginPath(context);
	CGPoint bar[2] = {{x + 3, y + 7}, {x + 11, y + 7}};
	CGContextAddLines(context, bar, 2);
	CGContextStrokePath(context);
    }
}

    BevelButtonParams = { kThemeBevelButton, NoThemeMetric },
/*----------------------------------------------------------------------
 * DrawRadioIndicator --
 *
 * Draws the dot in the middle of a selected radio button.
 */

    PopupButtonParams = { kThemePopupButton, kThemeMetricPopupButtonHeight },
static void DrawRadioIndicator(
    CGContextRef context,
    CGRect bounds,
    int state,
    int isDark)
{
    CGFloat x = bounds.origin.x, y = bounds.origin.y;
    CGColorRef fillColor = IndicatorColor(state, isDark);

    DisclosureParams = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight },
    CGContextSetFillColorWithColor(context, fillColor);
    if (state & TTK_STATE_SELECTED) {
	CGContextBeginPath(context);
	CGRect dot = {{x + 5, y + 5}, {6, 6}};
	CGContextAddEllipseInRect(context, dot);
	CGContextFillPath(context);
    } else if (state & TTK_STATE_ALTERNATE) {
	CGRect bar = {{x + 4, y + 7}, {8, 2}};
	CGContextFillRect(context, bar);
    }
}

    ListHeaderParams = { kThemeListHeaderButton, kThemeMetricListHeaderHeight };
static void
DrawHelpSymbol(
    CGContextRef context,
    CGRect bounds,
    int state)
{
    NSFont *font = [NSFont controlContentFontOfSize:15];
    NSColor *foreground = state & TTK_STATE_DISABLED ?
	[NSColor disabledControlTextColor] : [NSColor controlTextColor];
    NSDictionary *attrs = @{
        NSForegroundColorAttributeName : foreground,
        NSFontAttributeName : font
    };
    NSAttributedString *attributedString = [[NSAttributedString alloc]
						      initWithString:@"?"
							  attributes:attrs];
    CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString(
	       (CFAttributedStringRef)attributedString);
    CTLineRef line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, 1));
    CGAffineTransform t = CGAffineTransformMake(
			      1.0, 0.0, 0.0, -1.0, 0.0, bounds.size.height);
    CGContextSaveGState(context);
    CGContextSetTextMatrix(context, t);
    CGContextSetTextPosition(context,
			     bounds.origin.x + 6.5,
			     bounds.origin.y + bounds.size.height - 5);
    CTLineDraw(line, context);
    CGContextRestoreGState(context);
    CFRelease(line);
    CFRelease(typesetter);
    [attributedString release];
}



/*----------------------------------------------------------------------
 * +++ Progress bars.
 */

/*----------------------------------------------------------------------
 * DrawProgressBar --
 *
 * Draws a progress bar, with parameters supplied by a HIThemeTrackDrawInfo
 * struct.  Draws a rounded rectangular track overlayed by a colored
 * rounded rectangular indicator.  An indeterminate progress bar is
 * animated.
 */

static void DrawProgressBar(
    CGContextRef context,
    CGRect bounds,
    HIThemeTrackDrawInfo info,
    int state,
    Tk_Window tkwin)
{
    CGRect colorBounds;
    CGFloat rgba[4];
    CGColorRef trackColor, highlightColor, fillColor;
    NSColor *accent;
    CGFloat ratio = (CGFloat) info.value / (CGFloat) (info.max - info.min);

    GetBackgroundColorRGBA(context, tkwin, 0, NO, rgba);

    /*
     * Compute the bounds for the track and indicator.  The track is 6 pixels
     * wide in the center of the widget bounds.
     */

    if (info.attributes & kThemeTrackHorizontal) {
	bounds = CGRectInset(bounds, 1, bounds.size.height / 2 - 3);
	colorBounds = bounds;
	if (info.kind == kThemeIndeterminateBar) {
	    CGFloat width = 0.25*bounds.size.width;
	    CGFloat travel = 0.75*bounds.size.width;
	    CGFloat center = bounds.origin.x + (width / 2) + ratio*travel;
	    colorBounds.origin.x = center - width / 2;
	    colorBounds.size.width = width;
	} else {
	    colorBounds.size.width = ratio*bounds.size.width;
	}
	if (colorBounds.size.width > 0 && colorBounds.size.width < 6) {
	    colorBounds.size.width = 6;
	}
    } else {
	bounds = CGRectInset(bounds, bounds.size.width / 2 - 3, 1);
	colorBounds = bounds;
	if (info.kind == kThemeIndeterminateBar) {
	    CGFloat height = 0.25*bounds.size.height;
	    CGFloat travel = 0.75*bounds.size.height;
	    CGFloat center = bounds.origin.y + (height / 2) + ratio*travel;
	    colorBounds.origin.y = center - height / 2;
	    colorBounds.size.height = height;
	} else {
	    colorBounds.size.height = ratio*(bounds.size.height);
	}
	if (colorBounds.size.height > 0 && colorBounds.size.height < 6) {
	    colorBounds.size.height = 6;
	}
	colorBounds.origin.y += bounds.size.height - colorBounds.size.height;
    }

    /*
     * Compute the colors for the track and indicator.
     */

    if (TkMacOSXInDarkMode(tkwin)) {
	for(int i=0; i < 3; i++) {
	    rgba[i] += 30.0 / 255.0;
	}

	trackColor = CGColorFromRGBA(rgba);
	for(int i=0; i < 3; i++) {
	    rgba[i] -= 5.0 / 255.0;
	}
	highlightColor = CGColorFromRGBA(rgba);
	FillRoundedRectangle(context, bounds, 3, trackColor);
    } else {
	for(int i=0; i < 3; i++) {
	    rgba[i] -= 14.0 / 255.0;
	}
	trackColor = CGColorFromRGBA(rgba);
	for(int i=0; i < 3; i++) {
	    rgba[i] += 3.0 / 255.0;
	}
	highlightColor = CGColorFromRGBA(rgba);
	bounds.size.height -= 1;
	bounds = CGRectInset(bounds, 0, -1);
    }
    if (state & TTK_STATE_BACKGROUND) {
	accent = [NSColor colorWithRed:0.72 green:0.72 blue:0.72 alpha:0.72];
    } else {
	accent = controlAccentColor();
    }

static Ttk_StateTable ButtonValueTable[] = {
    /*
     * Draw the track, with highlighting around the edge.
     */

    { kThemeButtonMixed, TTK_STATE_ALTERNATE, 0 },
    FillRoundedRectangle(context, bounds, 3, trackColor);
    bounds = CGRectInset(bounds, 0, 0.5);
    FillRoundedRectangle(context, bounds, 2.5, highlightColor);
    bounds = CGRectInset(bounds, 0.5, 0.5);
    FillRoundedRectangle(context, bounds, 2, trackColor);
    bounds = CGRectInset(bounds, -0.5, -1);

    { kThemeButtonOn, TTK_STATE_SELECTED, 0 },
    /*
     * Draw the indicator.  Make it slightly transparent around the
     * edge so the highlightng shows through.
     */

    { kThemeButtonOff, 0, 0 }
    if (info.kind == kThemeIndeterminateBar &&
	(state & TTK_STATE_SELECTED) == 0) {
	return;
    }

/* Others: kThemeDisclosureRight, kThemeDisclosureDown, kThemeDisclosureLeft */
    fillColor = CGCOLOR([accent colorWithAlphaComponent:0.9]);
    FillRoundedRectangle(context, colorBounds, 3, fillColor);
    colorBounds = CGRectInset(colorBounds, 1, 1);
    fillColor = CGCOLOR([accent colorWithAlphaComponent:1.0]);
    FillRoundedRectangle(context, colorBounds, 2.5, fillColor);
}
};

/*----------------------------------------------------------------------
 * +++ Sliders.
 */

/*----------------------------------------------------------------------
 * DrawSlider --
 *
 * Draws a slider track and round thumb for a Ttk scale widget.  The accent
 * color is used on the left or top part of the track, so the fraction of
 * the track which is colored is equal to (value - from) / (to - from).
 *
 */

static void DrawSlider(
    CGContextRef context,
    CGRect bounds,
    HIThemeTrackDrawInfo info,
    int state,
    Tk_Window tkwin)
{
    CGColorRef trackColor;
    CGRect clipBounds, trackBounds, thumbBounds;
    CGPoint thumbPoint;
    CGFloat position;
    CGColorRef accentColor;
    Bool fromIsSmaller = info.reserved;
    double from = info.min, to = fabs((double) info.max), value = info.value;

    /*
     * info.min, info.max and info.value are integers.  When this is called
     * we will have arranged that min = 0 and max is a large positive integer.
     */

    double fraction = (from < to) ? (value - from) / (to - from) : 0.5;
    int isDark = TkMacOSXInDarkMode(tkwin);

    if (info.attributes & kThemeTrackHorizontal) {
	trackBounds = CGRectInset(bounds, 0, bounds.size.height / 2 - 3);
	trackBounds.size.height = 3;
	position = 8 + fraction * (trackBounds.size.width - 16);
	clipBounds = trackBounds;
	if (fromIsSmaller) {
	    clipBounds.size.width = position;
	} else {
	    clipBounds.origin.x += position;
	    clipBounds.size.width -= position;
	}
	thumbPoint = CGPointMake(trackBounds.origin.x + position,
				 trackBounds.origin.y + 1);
    } else {
	trackBounds = CGRectInset(bounds, bounds.size.width / 2 - 3, 0);
	trackBounds.size.width = 3;
	position = 8 + fraction * (trackBounds.size.height - 16);
	clipBounds = trackBounds;
	if (fromIsSmaller) {
	    clipBounds.size.height = position;
	} else {
	    clipBounds.origin.y += position;
	    clipBounds.size.height -= position;
	}
	thumbPoint = CGPointMake(trackBounds.origin.x + 1,
				 trackBounds.origin.y + position);
    }
    trackColor = isDark ? CGColorFromGray(darkTrack):
	CGColorFromGray(lightTrack);
    thumbBounds = CGRectMake(thumbPoint.x - 8, thumbPoint.y - 8, 17, 17);
    CGContextSaveGState(context);
    FillRoundedRectangle(context, trackBounds, 1.5, trackColor);
    CGContextClipToRect(context, clipBounds);
    if (state & (TTK_STATE_BACKGROUND | TTK_STATE_DISABLED)) {
	accentColor = isDark ? CGColorFromGray(darkInactiveTrack) :
	    CGColorFromGray(lightInactiveTrack);
    } else {
	accentColor = CGCOLOR(controlAccentColor());
    }
    FillRoundedRectangle(context, trackBounds, 1.5, accentColor);
    CGContextRestoreGState(context);
    DrawGrayButton(context, thumbBounds, &sliderDesign, state, tkwin);
}

/*----------------------------------------------------------------------
 * +++ Drawing procedures for native widgets.
 *
 *      The HIToolbox does not support Dark Mode, and apparently never will.
 *      It also draws some widgets in discontinued older styles even when used
 *      on new OS releases.  So to make widgets look "native" we have to provide
 *      analogues of the HIToolbox drawing functions to be used on newer systems.
 *      We continue to use NIToolbox for older versions of the OS.
 *
 *      Drawing the dark widgets requires NSColors that were introduced in OSX
 *      10.14, so we make some of these functions be no-ops when building on
 *      systems older than 10.14.
 */

/*----------------------------------------------------------------------
 * DrawButton --
 *
 * This is a standalone drawing procedure which draws most types of macOS
 * buttons for newer OS releases.  The button style is specified in the
 * "kind" field of a HIThemeButtonDrawInfo struct, although some of the
 * identifiers are not recognized by HIToolbox.
 */

static void DrawButton(
    CGRect bounds,
    HIThemeButtonDrawInfo info,
    Ttk_State state,
    CGContextRef context,
    Tk_Window tkwin)
{
    ThemeButtonKind kind = info.kind;
    ThemeDrawState drawState = info.state;
    CGRect arrowBounds = bounds = CGRectInset(bounds, 1, 1);
    int hasIndicator, isDark = TkMacOSXInDarkMode(tkwin);

    switch (kind) {
    case TkRoundedRectButton:
	DrawGrayButton(context, bounds, &roundedrectDesign, state, tkwin);
	break;
    case TkInlineButton:
	DrawGrayButton(context, bounds, &inlineDesign, state, tkwin);
	break;
    case TkRecessedButton:
	DrawGrayButton(context, bounds, &recessedDesign, state, tkwin);
	break;
    case TkSidebarButton:
	DrawGrayButton(context, bounds, &sidebarDesign, state, tkwin);
	break;
    case kThemeRoundedBevelButton:
	DrawGrayButton(context, bounds, &bevelDesign, state, tkwin);
	break;
    case kThemePushButton:

	/*
	 * The TTK_STATE_ALTERNATE bit means -default active.  Apple only
	 * indicates the default state (which means that the key equivalent is
	 * "\n") for Push Buttons.
	 */

static Ttk_StateTable ButtonAdornmentTable[] = {
	if ((state & TTK_STATE_PRESSED || state & TTK_STATE_ALTERNATE) &&
	    !(state & TTK_STATE_BACKGROUND)) {
	    DrawAccentedButton(context, bounds, &pushbuttonDesign, state, isDark);
	} else {
	    DrawGrayButton(context, bounds, &pushbuttonDesign, state, tkwin);
	}
	break;
    case kThemeRoundButtonHelp:
	DrawGrayButton(context, bounds, &helpDesign, state, tkwin);
	DrawHelpSymbol(context, bounds, state);
	break;
    case kThemePopupButton:
	drawState = 0;
	DrawGrayButton(context, bounds, &popupDesign, state, tkwin);
	arrowBounds.size.width = 17;
	arrowBounds.origin.x += bounds.size.width - 17;
	if (!(state & TTK_STATE_BACKGROUND) &&
	    !(state & TTK_STATE_DISABLED)) {
	    CGRect popupBounds = arrowBounds;

    { kThemeAdornmentDefault| kThemeAdornmentFocus,
	    /*
	     * Allow room for nonexistent focus ring.
	     */

	TTK_STATE_ALTERNATE| TTK_STATE_FOCUS, 0 },
	    popupBounds.size.width += 4;
	    popupBounds.origin.y -= 4;
	    popupBounds.size.height += 8;
	    DrawAccentedSegment(context, popupBounds, &popupDesign, state, tkwin);
	    drawState = BOTH_ARROWS;
	}
	arrowBounds.origin.x += 2;
	DrawUpDownArrows(context, arrowBounds, 3, 7, 2, state, drawState);
	break;
    case kThemeComboBox:
	if (state & TTK_STATE_DISABLED) {
    { kThemeAdornmentDefault, TTK_STATE_ALTERNATE, 0 },
	    // Need to add the disabled case to entryDesign.
	    DrawEntry(context, bounds, &entryDesign, state, tkwin);
	} else {
	    DrawEntry(context, bounds, &entryDesign, state, tkwin);
	}
	arrowBounds.size.width = 17;
	if (state & TTK_STATE_BACKGROUND) {
	    arrowBounds.origin.x += bounds.size.width - 20;
	    arrowBounds.size.width += 4;
	    arrowBounds.origin.y -= 1;
	} else {
	    arrowBounds.origin.y -= 1;
	    arrowBounds.origin.x += bounds.size.width - 20;
	    arrowBounds.size.width += 4;
	    arrowBounds.size.height += 2;
	}
	DrawAccentedSegment(context, arrowBounds, &comboDesign, state, tkwin);
	if (!(state & TTK_STATE_BACKGROUND)) {
	    state |= TTK_STATE_IS_ACCENTED;
    { kThemeAdornmentFocus, TTK_STATE_FOCUS, 0 },
	}
	DrawDownArrow(context, arrowBounds, 6, 6, state);
	break;
    case kThemeCheckBox:
    { kThemeAdornmentNone, 0, 0 }
	bounds = CGRectOffset(CGRectMake(0, bounds.size.height / 2 - 8, 16, 16),
			      bounds.origin.x, bounds.origin.y);
	bounds = CGRectInset(bounds, 1, 1);
	hasIndicator = state & TTK_STATE_SELECTED || state & TTK_STATE_ALTERNATE;
	if (hasIndicator &&
	    !(state & TTK_STATE_BACKGROUND) &&
	    !(state & TTK_STATE_DISABLED)) {
	    DrawAccentedButton(context, bounds, &checkDesign, 0, isDark);
	} else {
	    DrawGrayButton(context, bounds, &checkDesign, state, tkwin);
	}
};
	if (hasIndicator) {
	    DrawCheckIndicator(context, bounds, state, isDark);
	}
	break;
    case kThemeRadioButton:
	bounds = CGRectOffset(CGRectMake(0, bounds.size.height / 2 - 9, 18, 18),
					 bounds.origin.x, bounds.origin.y);
	bounds = CGRectInset(bounds, 1, 1);
	hasIndicator = state & TTK_STATE_SELECTED || state & TTK_STATE_ALTERNATE;
	if (hasIndicator &&
	    !(state & TTK_STATE_BACKGROUND) &&
	    !(state & TTK_STATE_DISABLED)) {
	    DrawAccentedButton(context, bounds, &radioDesign, 0, isDark);
	} else {
	    DrawGrayButton(context, bounds, &radioDesign, state, tkwin);
	}
	if (hasIndicator) {
	    DrawRadioIndicator(context, bounds, state, isDark);
	}

	break;
    case kThemeArrowButton:
/*
 * computeButtonDrawInfo --
	DrawGrayButton(context, bounds, &pushbuttonDesign, state, tkwin);
	arrowBounds.origin.x = bounds.origin.x + bounds.size.width - 17;
	arrowBounds.size.width = 16;
	arrowBounds.origin.y -= 1;
	if (state & TTK_STATE_SELECTED) {
	    DrawUpArrow(context, arrowBounds, 5, 6, state);
	} else {
	    DrawDownArrow(context, arrowBounds, 5, 6, state);
	}
	break;
    case kThemeIncDecButton:
	DrawGrayButton(context, bounds, &incdecDesign, state, tkwin);
	if (state & TTK_STATE_PRESSED) {
	    CGRect clip;
	    if (drawState == kThemeStatePressedDown) {
		clip = bounds;
		clip.size.height /= 2;
		clip.origin.y += clip.size.height;
		bounds.size.height += 1;
		clip.size.height += 1;
	    } else {
		clip = bounds;
		clip.size.height /= 2;
	    }
	    CGContextSaveGState(context);
	    CGContextClipToRect(context, clip);
	    DrawAccentedButton(context, bounds, &incdecDesign, 0, isDark);
	    CGContextRestoreGState(context);
	}
	{
	    CGFloat inset = (bounds.size.width - 5) / 2;
	    DrawUpDownArrows(context, bounds, inset, 5, 3, state, drawState);
	}
	break;
    default:
	break;
    }
}

 *	Fill in an appearance manager HIThemeButtonDrawInfo record.
/*----------------------------------------------------------------------
 * DrawGroupBox --
 *
 * This is a standalone drawing procedure which draws the contrasting rounded
 * rectangular box for LabelFrames and Notebook panes used in more recent
 * versions of macOS.  Normally the contrast is set to one, since the nesting
 * level of the Group Box is higher by 1 compared to its container.  But we
 * allow higher contrast for special cases, notably notebook tabs in macOS 11.
 * The save parameter is passed to GetBackgroundColor and should probably be
 * NO in such special cases.
 */

static inline HIThemeButtonDrawInfo computeButtonDrawInfo(
static void DrawGroupBox(
    CGRect bounds,
    CGContextRef context,
    Tk_Window tkwin,
    int contrast,
    Bool save)
{
    CHECK_RADIUS(5, bounds)

	ThemeButtonParams *params, Ttk_State state)
    CGPathRef path;
    CGColorRef backgroundColor, borderColor;

    backgroundColor = GetBackgroundCGColor(context, tkwin, contrast, save);
    borderColor = CGColorFromGray(boxBorder);
    CGContextSetFillColorWithColor(context, backgroundColor);
    path = CGPathCreateWithRoundedRect(bounds, 5, 5, NULL);
    CGContextClipToRect(context, bounds);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    CGContextSetFillColorWithColor(context, borderColor);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextReplacePathWithStrokedPath(context);
    CGContextFillPath(context);
    CFRelease(path);
}

/*----------------------------------------------------------------------
 * DrawListHeader --
 *
 * This is a standalone drawing procedure which draws column headers for a
 * Treeview in the Aqua appearance.  (The HIToolbox headers have not matched the
 * native ones since OSX 10.8)  Note that the header image is ignored, but we
 * draw arrows according to the state.
 */

{
static void DrawListHeader(
    CGRect bounds,
    CGContextRef context,
    Tk_Window tkwin,
    int state)
{
    int isDark = TkMacOSXInDarkMode(tkwin);
    CGFloat x = bounds.origin.x, y = bounds.origin.y;
    CGFloat w = bounds.size.width, h = bounds.size.height;
    CGPoint top[2] = {{x, y + 1}, {x + w, y + 1}};
    CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}};
    CGPoint separator[2] = {{x + w - 1, y + 3}, {x + w - 1, y + h - 3}};
    CGColorRef strokeColor, backgroundColor;

    const HIThemeButtonDrawInfo info = {
    /*
     * Apple changes the background color of a list header when the window is
     * not active.  But Ttk does not indicate that in the state of a
     * TreeHeader.  So we have to query the Apple window manager.
     */

	.version = 0,
    NSWindow *win = TkMacOSXGetNSWindowForDrawable(Tk_WindowId(tkwin));
    if (!isDark) {
	GrayColor bgGray = [win isKeyWindow] ?
	    listheaderActiveBG : listheaderInactiveBG;
	backgroundColor = CGColorFromGray(bgGray);
    }

	.state = Ttk_StateTableLookup(ThemeStateTable, state),
    CGContextSaveGState(context);
    CGContextSetShouldAntialias(context, false);
    if (!isDark) {
	CGContextBeginPath(context);
	CGContextSetFillColorWithColor(context, backgroundColor);
	CGContextAddRect(context, bounds);
	CGContextFillPath(context);
    }
    strokeColor = isDark ?
	CGColorFromGray(darkListheaderBorder) :
	CGColorFromGray(listheaderSeparator);
    CGContextSetStrokeColorWithColor(context, strokeColor);
    CGContextAddLines(context, separator, 2);
    CGContextStrokePath(context);
    strokeColor = isDark ?
	CGColorFromGray(darkListheaderBorder) :
	CGColorFromGray(lightListheaderBorder);
    CGContextSetStrokeColorWithColor(context, strokeColor);
    CGContextAddLines(context, top, 2);
    CGContextStrokePath(context);
    CGContextAddLines(context, bottom, 2);
    CGContextStrokePath(context);
    CGContextRestoreGState(context);

	.kind = params ? params->kind : 0,
    if (state & TTK_TREEVIEW_STATE_SORTARROW) {
	CGRect arrowBounds = bounds;
	arrowBounds.origin.x = bounds.origin.x + bounds.size.width - 16;
	arrowBounds.size.width = 16;
	if (state & TTK_STATE_ALTERNATE) {
	    DrawUpArrow(context, arrowBounds, 3, 8, state);
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	} else if (state & TTK_STATE_SELECTED) {
	    DrawDownArrow(context, arrowBounds, 3, 8, state);
	}
	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state),
    };
    }
}

    return info;
/*----------------------------------------------------------------------
 * DrawTab --
 *
 * This is a standalone drawing procedure which draws Tabbed Pane Tabs for the
 * notebook widget.
 */

}
static void
DrawTab(
    CGRect bounds,
    Ttk_State state,
    CGContextRef context,
    Tk_Window tkwin)
{
    CGRect originalBounds = bounds;
    CGColorRef strokeColor;
    int OSVersion = [NSApp macOSVersion];

    /*
     * Extend the bounds to one or both sides so the rounded part will be
     * clipped off if the right of the left tab, the left of the right tab,
     * and both sides of the middle tabs.
     */

    CGContextClipToRect(context, bounds);
    if (OSVersion < 110000 || !(state & TTK_STATE_SELECTED)) {
	if (!(state & TTK_STATE_FIRST_TAB)) {
	    bounds.origin.x -= 10;
	    bounds.size.width += 10;
	}

	if (!(state & TTK_STATE_LAST_TAB)) {
	    bounds.size.width += 10;
	}
    }
    /*
     * Fill the tab face with the appropriate color or gradient.  Use a solid
     * color if the tab is not selected, otherwise use the accent color with
     * highlights
     */

    if (!(state & TTK_STATE_SELECTED)) {
	DrawGrayButton(context, bounds, &tabDesign, state, tkwin);

        /*
         * Draw a separator line on the left side of the tab if it
         * not first.
         */

	if (!(state & TTK_STATE_FIRST_TAB)) {
	    CGContextSaveGState(context);
	    strokeColor = CGColorFromGray(darkTabSeparator);
	    CGContextSetStrokeColorWithColor(context, strokeColor);
	    CGContextBeginPath(context);
	    CGContextMoveToPoint(context, originalBounds.origin.x,
		originalBounds.origin.y + 1);
	    CGContextAddLineToPoint(context, originalBounds.origin.x,
		originalBounds.origin.y + originalBounds.size.height - 1);
	    CGContextStrokePath(context);
	    CGContextRestoreGState(context);
	}
    } else {

	/*
	 * This is the selected tab; paint it with the current accent color.
	 * If it is first, cover up the separator line drawn by the second one.
	 * (The selected tab is always drawn last.)
	 */

	if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
	    bounds.size.width += 1;
	}
	if (!(state & TTK_STATE_BACKGROUND)) {
	    DrawAccentedButton(context, bounds, &tabDesign, 0, 0);
	} else {
	    DrawGrayButton(context, bounds, &tabDesign, state, tkwin);
	}
    }
}

static void
static void ButtonElementSizeNoPadding(
DrawTab11(
    CGRect bounds,
    Ttk_State state,
    CGContextRef context,
    Tk_Window tkwin)
    void *clientData, void *elementRecord, Tk_Window tkwin,
{

    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    if (state & TTK_STATE_SELECTED) {
	DrawGrayButton(context, bounds, &pushbuttonDesign, state, tkwin);
    } else {
	CGRect clipRect = bounds;
	/*
	 * Draw a segment of a Group Box as a background for non-selected tabs.
	 * Clip the Group Box so that the segments fit together to form a long
	 * rounded rectangle behind the entire tab bar.
	 */

{
	if (!(state & TTK_STATE_FIRST_TAB)) {
	    clipRect.origin.x -= 5;
	    bounds.origin.x -= 5;
	    bounds.size.width += 5;
	}
	if (!(state & TTK_STATE_LAST_TAB)) {
	    clipRect.size.width += 5;
	    bounds.size.width += 5;
	}
	CGContextSaveGState(context);
	CGContextClipToRect(context, clipRect);
	DrawGroupBox(bounds, context, tkwin, 3, NO);
	CGContextRestoreGState(context);
    }
}

    ThemeButtonParams *params = clientData;
/*----------------------------------------------------------------------
 * DrawDarkSeparator --
 *
 * This is a standalone drawing procedure which draws a separator widget
 * in Dark Mode.  HIToolbox is used in light mode.
 */

static void DrawDarkSeparator(
    CGRect bounds,
    CGContextRef context,
    TCL_UNUSED(Tk_Window))
{

    CGColorRef sepColor = CGColorFromGray(darkSeparator);

    CGContextSetFillColorWithColor(context, sepColor);
    CGContextFillRect(context, bounds);
}

/*----------------------------------------------------------------------
 * +++ DrawGradientButton --
 *
 *      This is a standalone drawing procedure which draws a
 *      a Gradient Button.
 */

static void DrawGradientBorder(
    CGRect bounds,
    CGContextRef context,
    Tk_Window tkwin,
    Ttk_State state)
{
    CGColorRef faceColor, borderColor;
    GrayColor faceGray, borderGray;
    CGRect inside = CGRectInset(bounds, 1, 1);

    if (TkMacOSXInDarkMode(tkwin)) {
	if (state & TTK_STATE_DISABLED) {
	    faceGray = darkGradientDisabled;
	    borderGray = darkGradientBorderDisabled;
	} else {
	    faceGray = state & TTK_STATE_PRESSED ?
		darkGradientPressed : darkGradientNormal;
	    borderGray = darkGradientBorder;
	}
    } else {
	if (state & TTK_STATE_DISABLED) {
	    faceGray = lightGradientDisabled;
	    borderGray = lightGradientBorderDisabled;
	} else {
	    faceGray = state & TTK_STATE_PRESSED ?
		lightGradientPressed : lightGradientNormal;
	    borderGray = lightGradientBorder;
	}
    }
    faceColor = CGColorFromGray(faceGray);
    borderColor = CGColorFromGray(borderGray);
    CGContextSetFillColorWithColor(context, faceColor);
    CGContextFillRect(context, inside);
    CGContextSetFillColorWithColor(context, borderColor);
    CGContextAddRect(context, bounds);
    CGContextAddRect(context, inside);
    CGContextEOFillPath(context);
}

/*----------------------------------------------------------------------
 * +++ Button elements.
 */

static void ButtonElementMinSize(
    void *clientData,
    int *minWidth,
    int *minHeight)
{
    ThemeButtonParams *params = (ThemeButtonParams *)clientData;

    if (params->heightMetric != NoThemeMetric) {
	ChkErr(GetThemeMetric, params->heightMetric, minHeight);

	SInt32 height;
        /*
         * The theme height does not include the 1-pixel border around
         * the button, although it does include the 1-pixel shadow at
         * the bottom.
         */

	*minHeight += 2;

        /*
         * For buttons with labels the minwidth must be 0 to force the
         * correct text layout.  For example, a non-zero value will cause the
         * text to be left justified, no matter what -anchor setting is used in
         * the style.
         */

	if (params->widthMetric != NoThemeMetric) {
	    ChkErr(GetThemeMetric, params->widthMetric, minWidth);
	ChkErr(GetThemeMetric, params->heightMetric, &height);
	    *minWidth += 2;
	    *minHeight += 2;
	*heightPtr = height;
	} else {
	    *minWidth = 0;
	}
    }
}

static void ButtonElementSize(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    int *minWidth,
    int *minHeight,
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ThemeButtonParams *params = (ThemeButtonParams *)clientData;
    HIThemeButtonDrawInfo info =
    ThemeButtonParams *params = clientData;
    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0);
	ComputeButtonDrawInfo(params, 0, tkwin);
    static const CGRect scratchBounds = {{0, 0}, {100, 100}};
    CGRect contentBounds, backgroundBounds;
    CGRect contentBounds;
    int verticalPad;

    ButtonElementMinSize(clientData, minWidth, minHeight);
    ButtonElementSizeNoPadding(
    switch (info.kind) {
    case TkSidebarButton:
	*paddingPtr = Ttk_MakePadding(30, 10, 30, 10);
	return;
	clientData, elementRecord, tkwin,
	widthPtr, heightPtr, paddingPtr);

    case TkGradientButton:
	*paddingPtr = Ttk_MakePadding(1, 1, 1, 1);
        /* Fall through. */
    /*
    case kThemeArrowButton:
    case kThemeRoundButtonHelp:
        return;
     * To compute internal padding, query the appearance manager
     * for the content bounds of a dummy rectangle, then use
     * the difference as the padding.
	/* Buttons which are sized like PushButtons but unknown to HITheme. */
    case TkRoundedRectButton:
     */
    ChkErr(HIThemeGetButtonContentBounds,
    case TkRecessedButton:
    case TkInlineButton:
	info.kind = kThemePushButton;
	&scratchBounds, &info, &contentBounds);
	break;
    default:
        break;
    }

    paddingPtr->left = CGRectGetMinX(contentBounds);
    paddingPtr->top = CGRectGetMinY(contentBounds);
    paddingPtr->right = CGRectGetMaxX(scratchBounds) - CGRectGetMaxX(contentBounds) + 1;
    paddingPtr->bottom = CGRectGetMaxY(scratchBounds) - CGRectGetMaxY(contentBounds);

    /*
     * Given a hypothetical bounding rectangle for a button, HIToolbox will
     * compute a bounding rectangle for the button contents and a bounding
     * rectangle for the button background.  The background bounds are large
     * enough to contain the image of the button in any state, which might
     * include highlight borders, shadows, etc.  The content rectangle is not
     * centered vertically within the background rectangle, presumably because
     * Now add a little extra padding to account for drop shadows.
     * @@@ SHOULD: call GetThemeButtonBackgroundBounds() instead.
     * shadows only appear on the bottom.  Nonetheless, when HIToolbox is asked
     * to draw a button with a certain bounding rectangle it draws the button
     * centered within the rectangle.
     *
     * To compute the effective padding around a button we request the
     * content and bounding rectangles for a 100x100 button and use the
     * padding between those.  However, we symmetrize the padding on the
     * top and bottom, because that is how the button will be drawn.
     */

    ChkErr(HIThemeGetButtonContentBounds,
	&scratchBounds, &info, &contentBounds);
    ChkErr(HIThemeGetButtonBackgroundBounds,
	&scratchBounds, &info, &backgroundBounds);
    paddingPtr->left = contentBounds.origin.x - backgroundBounds.origin.x;
    paddingPtr->right =
    *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
	CGRectGetMaxX(backgroundBounds) - CGRectGetMaxX(contentBounds);
    verticalPad = backgroundBounds.size.height - contentBounds.size.height;
    paddingPtr->top = paddingPtr->bottom = verticalPad / 2;
    if (info.kind == kThemePopupButton) {
	paddingPtr->top += 1;
	paddingPtr->bottom -= 1;
    *widthPtr += Ttk_PaddingWidth(ButtonMargins);
    *heightPtr += Ttk_PaddingHeight(ButtonMargins);
    }
}

static void ButtonElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    ThemeButtonParams *params = (ThemeButtonParams *)clientData;
    CGRect bounds = BoxToRect(d, b);
    HIThemeButtonDrawInfo info = ComputeButtonDrawInfo(params, state, tkwin);
    ThemeButtonParams *params = clientData;
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state);
    int isDark = TkMacOSXInDarkMode(tkwin);

    switch (info.kind) {

    /*
     * A Gradient Button should have an image and no text.  The size is set to
     * that of the image.  All we need to do is draw a 1-pixel border.
     */

    case TkGradientButton:
	BEGIN_DRAWING(d)
    BEGIN_DRAWING(d)
	    DrawGradientBorder(bounds, dc.context, tkwin, state);
	END_DRAWING
	return;
    /*
     * Buttons with no height restrictions are ready to draw.
     */

    case kThemeArrowButton:
    case kThemeCheckBox:
    case kThemeRadioButton:
    case TkSidebarButton:
    	break;

    /*
     * Other buttons have a maximum height.   We have to deal with that.
     */

    default:
	bounds = NormalizeButtonBounds(params, bounds, isDark);
	break;
    }

    /* We do our own drawing on new systems.*/

    if ([NSApp macOSVersion] > 100800) {
	BEGIN_DRAWING(d)
	DrawButton(bounds, info, state, dc.context, tkwin);
	END_DRAWING
	return;
    }

    /*
     * If execution reaches here it means we should use HIToolbox to draw the
     * button.  Buttons that HIToolbox doesn't know are rendered as
     * PushButtons.
     */

    switch (info.kind) {
    case TkRoundedRectButton:
    case TkRecessedButton:
	info.kind = kThemePushButton;
	break;
    default:
	break;
    }

    /*
     * Apple's PushButton and PopupButton do not change their fill color
     * when the window is inactive.  However, except in 10.7 (Lion), the
     * color of the arrow button on a PopupButton does change.  For some
     * reason HITheme fills inactive buttons with a transparent color that
     * allows the window background to show through, leading to
     * inconsistent behavior.  We work around this by filling behind an
     * inactive PopupButton with a text background color before asking
     * HIToolbox to draw it. For PushButtons, we simply draw them in the
     * active state.
     */

    BEGIN_DRAWING(d)
    if (info.kind == kThemePopupButton  &&
	(state & TTK_STATE_BACKGROUND)) {
	CGRect innerBounds = CGRectInset(bounds, 1, 1);
	FillRoundedRectangle(dc.context, innerBounds, 4, CG_WHITE);
    }

    /*
     * A BevelButton with mixed value is drawn borderless, which does make
     * much sense for us.
     */

    if (info.kind == kThemeRoundedBevelButton &&
	info.value == kThemeButtonMixed) {
	info.value = kThemeButtonOff;
	info.state = kThemeStateInactive;
    }
    if (info.kind == kThemePushButton) {
	bounds.origin.y -= 2;
    }
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	   NULL);
    END_DRAWING
}

static Ttk_ElementSpec ButtonElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    ButtonElementSize,
    ButtonElementDraw
};

/*----------------------------------------------------------------------
 * +++ Notebook elements.
 */


/* Tab position logic, c.f. ttkNotebook.c TabState() */

#define TTK_STATE_NOTEBOOK_FIRST	TTK_STATE_USER1
#define TTK_STATE_NOTEBOOK_LAST 	TTK_STATE_USER2
static const Ttk_StateTable TabStyleTable[] = {
    {kThemeTabFrontInactive, TTK_STATE_SELECTED | TTK_STATE_BACKGROUND, 0},
    {kThemeTabNonFrontInactive, TTK_STATE_BACKGROUND, 0},
    {kThemeTabFrontUnavailable, TTK_STATE_DISABLED | TTK_STATE_SELECTED, 0},
    {kThemeTabNonFrontUnavailable, TTK_STATE_DISABLED, 0},
    {kThemeTabFront, TTK_STATE_SELECTED, 0},
    {kThemeTabNonFrontPressed, TTK_STATE_PRESSED, 0},
    {kThemeTabNonFront, 0, 0}
static Ttk_StateTable TabStyleTable[] = {
    { kThemeTabFrontInactive, TTK_STATE_SELECTED|TTK_STATE_BACKGROUND},
    { kThemeTabNonFrontInactive, TTK_STATE_BACKGROUND},
    { kThemeTabFrontUnavailable, TTK_STATE_DISABLED|TTK_STATE_SELECTED},
    { kThemeTabNonFrontUnavailable, TTK_STATE_DISABLED},
    { kThemeTabFront, TTK_STATE_SELECTED},
    { kThemeTabNonFrontPressed, TTK_STATE_PRESSED},
    { kThemeTabNonFront, 0}
};

static const Ttk_StateTable TabAdornmentTable[] = {
    {kHIThemeTabAdornmentNone, TTK_STATE_FIRST_TAB | TTK_STATE_LAST_TAB, 0},
    {kHIThemeTabAdornmentTrailingSeparator, TTK_STATE_FIRST_TAB, 0},
    {kHIThemeTabAdornmentNone, TTK_STATE_LAST_TAB, 0},
    {kHIThemeTabAdornmentTrailingSeparator, 0, 0},
static Ttk_StateTable TabAdornmentTable[] = {
    { kHIThemeTabAdornmentNone,
	    TTK_STATE_NOTEBOOK_FIRST|TTK_STATE_NOTEBOOK_LAST},
    {kHIThemeTabAdornmentTrailingSeparator, TTK_STATE_NOTEBOOK_FIRST},
    {kHIThemeTabAdornmentNone, TTK_STATE_NOTEBOOK_LAST},
    {kHIThemeTabAdornmentTrailingSeparator, 0 },
};

static const Ttk_StateTable TabPositionTable[] = {
    {kHIThemeTabPositionOnly, TTK_STATE_FIRST_TAB | TTK_STATE_LAST_TAB, 0},
    {kHIThemeTabPositionFirst, TTK_STATE_FIRST_TAB, 0},
    {kHIThemeTabPositionLast, TTK_STATE_LAST_TAB, 0},
    {kHIThemeTabPositionMiddle, 0, 0},
static Ttk_StateTable TabPositionTable[] = {
    { kHIThemeTabPositionOnly,
	    TTK_STATE_NOTEBOOK_FIRST|TTK_STATE_NOTEBOOK_LAST},
    { kHIThemeTabPositionFirst, TTK_STATE_NOTEBOOK_FIRST},
    { kHIThemeTabPositionLast, TTK_STATE_NOTEBOOK_LAST},
    { kHIThemeTabPositionMiddle, 0 },
};

/*
 * Apple XHIG Tab View Specifications:
 *
 * Control sizes: Tab views are available in regular, small, and mini sizes.
 * The tab height is fixed for each size, but you control the size of the pane
 * area. The tab heights for each size are listed below:
 *  - Regular size: 20 pixels.
 *  - Small: 17 pixels.
 *  - Mini: 15 pixels.
 *
 * Label spacing and fonts: The tab labels should be in a font that’s
 * proportional to the size of the tab view control. In addition, the label
 * should be placed so that there are equal margins of space before and after
 * it. The guidelines below provide the specifications you should use for tab
 * labels:
 *  - Regular size: System font. Center in tab, leaving 12 pixels on each
 *  - Regular size: System font. Center in tab, leaving 12 pixels on each side.
 *side.
 *  - Small: Small system font. Center in tab, leaving 10 pixels on each side.
 *  - Mini: Mini system font. Center in tab, leaving 8 pixels on each side.
 *
 * Control spacing: Whether you decide to inset a tab view in a window or
 * extend its edges to the window sides and bottom, you should place the top
 * edge of the tab view 12 or 14 pixels below the bottom edge of the title bar
 * (or toolbar, if there is one). If you choose to inset a tab view in a
 * window, you should leave a margin of 20 pixels between the sides and bottom
 * of the tab view and the sides and bottom of the window (although 16 pixels
 * is also an acceptable margin-width). If you need to provide controls below
 * the tab view, leave enough space below the tab view so the controls are 20
 * pixels above the bottom edge of the window and 12 pixels between the tab
 * view and the controls.
 *
 * If you choose to extend the tab view sides and bottom so that they meet the
 * window sides and bottom, you should leave a margin of at least 20 pixels
 * between the content in the tab view and the tab-view edges.
 *
 * <URL: http://developer.apple.com/documentation/userexperience/Conceptual/
 *       AppleHIGuidelines/XHIGControls/XHIGControls.html#//apple_ref/doc/uid/
 *       TP30000359-TPXREF116>
 */

static void TabElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    TCL_UNUSED(int *),     /* minWidth */
    TCL_UNUSED(int *),     /* minHeight */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    GetThemeMetric(kThemeMetricLargeTabHeight, (SInt32 *)heightPtr);
    *paddingPtr = Ttk_MakePadding(0, -2, 0, 1);
    *paddingPtr = Ttk_MakePadding(0, 0, 0, 2);

}

static void TabElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);
    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] >= 110000) {
	DrawTab11(bounds, state, dc.context, tkwin);
    } else if ([NSApp macOSVersion] > 100800) {
	DrawTab(bounds, state, dc.context, tkwin);
    } else {
	HIThemeTabDrawInfo info = {
	    .version = 1,
	    .style = Ttk_StateTableLookup(TabStyleTable, state),
	    .direction = kThemeTabNorth,
	    .size = kHIThemeTabSizeNormal,
	    .adornment = Ttk_StateTableLookup(TabAdornmentTable, state),
	    .kind = kHIThemeTabKindNormal,
	    .position = Ttk_StateTableLookup(TabPositionTable, state),
	};
    HIThemeTabDrawInfo info = {
	.version = 1,
	.style = Ttk_StateTableLookup(TabStyleTable, state),
	.direction = kThemeTabNorth,
	.size = kHIThemeTabSizeNormal,
	.adornment = Ttk_StateTableLookup(TabAdornmentTable, state),
	.kind = kHIThemeTabKindNormal,
	.position = Ttk_StateTableLookup(TabPositionTable, state),
    };
	ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation,
	    NULL);
    }

    BEGIN_DRAWING(d)
    ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation, NULL);
    END_DRAWING
}

static Ttk_ElementSpec TabElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TabElementSize,
    TabElementDraw
};

/*
 * Notebook panes:
 */

static void PaneElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    TCL_UNUSED(int *),     /* minWidth */
    TCL_UNUSED(int *),     /* minHeight */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = Ttk_MakePadding(9, 5, 9, 9);
}

static void PaneElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);
    HIThemeTabPaneDrawInfo info = {
	.version = 1,
	.state = Ttk_StateTableLookup(ThemeStateTable, state),
	.direction = kThemeTabNorth,
	.size = kHIThemeTabSizeNormal,
	.kind = kHIThemeTabKindNormal,
	.adornment = kHIThemeTabPaneAdornmentNormal,
    };

    bounds.origin.y -= kThemeMetricTabFrameOverlap;
    bounds.size.height += kThemeMetricTabFrameOverlap;
    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	DrawGroupBox(bounds, dc.context, tkwin, 1, YES);
    } else {
	HIThemeTabPaneDrawInfo info = {
	    .version = 1,
	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
	    .direction = kThemeTabNorth,
	    .size = kHIThemeTabSizeNormal,
	    .kind = kHIThemeTabKindNormal,
	    .adornment = kHIThemeTabPaneAdornmentNormal,
	    };
	bounds.origin.y -= kThemeMetricTabFrameOverlap;
	bounds.size.height += kThemeMetricTabFrameOverlap;
	ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation);
    ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation);
    }
    END_DRAWING
}

static Ttk_ElementSpec PaneElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    PaneElementSize,
    PaneElementDraw
};

/*----------------------------------------------------------------------
 * +++ Labelframe elements --
/*
 * Labelframe borders:
 *
 * Labelframe borders: Use "primary group box ..."  Quoth
 * DrawThemePrimaryGroup reference: "The primary group box frame is drawn
 * inside the specified rectangle and is a maximum of 2 pixels thick."
 * Use "primary group box ..."
 * Quoth DrawThemePrimaryGroup reference:
 * "The primary group box frame is drawn inside the specified
 * rectangle and is a maximum of 2 pixels thick."
 *
 * "Maximum of 2 pixels thick" is apparently a lie;
 * looks more like 4 to me with shading.
 */

static void GroupElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    TCL_UNUSED(int *),     /* minWidth */
    TCL_UNUSED(int *),     /* minHeight */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = Ttk_MakePadding(0, 0, 0, 0);
    *paddingPtr = Ttk_UniformPadding(4);
}

static void GroupElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);

    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	DrawGroupBox(bounds, dc.context, tkwin, 1, YES);
    } else {
	const HIThemeGroupBoxDrawInfo info = {
	    .version = 0,
	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
	    .kind = kHIThemeGroupBoxKindPrimaryOpaque,
	    };
    const HIThemeGroupBoxDrawInfo info = {
	.version = 0,
	.state = Ttk_StateTableLookup(ThemeStateTable, state),
	.kind = kHIThemeGroupBoxKindPrimaryOpaque,
    };
	ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation);
    }

    BEGIN_DRAWING(d)
    ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec GroupElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    GroupElementSize,
    GroupElementDraw
};

/*----------------------------------------------------------------------
 * +++ Entry elements --
 * +++ Entry element --
 *
 *    3 pixels padding for focus rectangle
 *    2 pixels padding for EditTextFrame
 *	3 pixels padding for focus rectangle
 *	2 pixels padding for EditTextFrame
 */

typedef struct {
    Tcl_Obj     *backgroundObj;
    Tcl_Obj	*backgroundObj;
    Tcl_Obj     *fieldbackgroundObj;
} EntryElement;

#define ENTRY_DEFAULT_BACKGROUND "systemTextBackgroundColor"

static Ttk_ElementOptionSpec EntryElementOptions[] = {
    {"-background", TK_OPTION_BORDER,
     offsetof(EntryElement, backgroundObj), ENTRY_DEFAULT_BACKGROUND},
    { "-background", TK_OPTION_BORDER,
	    Tk_Offset(EntryElement,backgroundObj), "white" },
    {"-fieldbackground", TK_OPTION_BORDER,
     offsetof(EntryElement, fieldbackgroundObj), ENTRY_DEFAULT_BACKGROUND},
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
    {0}
};

static void EntryElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    TCL_UNUSED(int *),     /* minWidth */
    TCL_UNUSED(int *),     /* minHeight */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = entryElementPadding;
    *paddingPtr = Ttk_UniformPadding(5);
}

static void EntryElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    EntryElement *e = (EntryElement *)elementRecord;
    EntryElement *e = elementRecord;
    ThemeFrameParams *params = (ThemeFrameParams *)clientData;
    HIThemeFrameKind kind = params ? params->kind :
	kHIThemeFrameTextFieldSquare;
    CGRect bounds = BoxToRect(d, b);
    CGColorRef background;
    Tk_3DBorder backgroundPtr = NULL;
    Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,e->backgroundObj);
    static const char *defaultBG = ENTRY_DEFAULT_BACKGROUND;

    Ttk_Box inner = Ttk_PadBox(b, Ttk_UniformPadding(3));
    if ([NSApp macOSVersion] > 100800) {
	BEGIN_DRAWING(d)
	    switch(kind) {
	    case kHIThemeFrameTextFieldRound:
		DrawEntry(dc.context, bounds, &searchDesign, state, tkwin);
    CGRect bounds = BoxToRect(d, inner);
		break;
	    case kHIThemeFrameTextFieldSquare:
		DrawEntry(dc.context, bounds, &entryDesign, state, tkwin);
		break;
	    default:
		return;
	    }
	END_DRAWING
    } else {
	const HIThemeFrameDrawInfo info = {
	    .version = 0,
	    .kind = params->kind,
	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
	    .isFocused = state & TTK_STATE_FOCUS,
	};
    const HIThemeFrameDrawInfo info = {
	.version = 0,
	.kind = kHIThemeFrameTextFieldSquare,
	.state = Ttk_StateTableLookup(ThemeStateTable, state),
	.isFocused = state & TTK_STATE_FOCUS,
    };

        /*
    /*
         * Earlier versions of the Aqua theme ignored the -fieldbackground
         * option and used the -background as if it were -fieldbackground.
         * Here we are enabling -fieldbackground.  For backwards
         * compatibility, if -fieldbackground is set to the default color and
         * -background is set to a different color then we use -background as
         * -fieldbackground.
         */
     * Erase w/background color:
     */

	if (0 != strcmp(Tcl_GetString(e->fieldbackgroundObj), defaultBG)) {
	    backgroundPtr =
		Tk_Get3DBorderFromObj(tkwin, e->fieldbackgroundObj);
	} else if (0 != strcmp(Tcl_GetString(e->backgroundObj), defaultBG)) {
	    backgroundPtr = Tk_Get3DBorderFromObj(tkwin, e->backgroundObj);
	}
	if (backgroundPtr != NULL) {
	    XFillRectangle(Tk_Display(tkwin), d,
		Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC),
		b.x, b.y, b.width, b.height);
	}
	BEGIN_DRAWING(d)
    XFillRectangle(Tk_Display(tkwin), d,
	    Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC),
	    inner.x,inner.y, inner.width, inner.height);

    BEGIN_DRAWING(d)
	if (backgroundPtr == NULL) {
	    if ([NSApp macOSVersion] > 100800) {
		background = CGCOLOR([NSColor textBackgroundColor]);
		CGContextSetFillColorWithColor(dc.context, background);
	    } else {
		CGContextSetRGBFillColor(dc.context, 1.0, 1.0, 1.0, 1.0);
	    }
	    CGContextFillRect(dc.context, bounds);
	}
	ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation);
	END_DRAWING
    ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation);
    /*if (state & TTK_STATE_FOCUS) {
	ChkErr(DrawThemeFocusRect, &bounds, 1);
    }*/
    END_DRAWING
    }
}

static Ttk_ElementSpec EntryElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(EntryElement),
    EntryElementOptions,
    EntryElementSize,
    EntryElementDraw
};

/*----------------------------------------------------------------------
 * +++ Combobox elements --
 * +++ Combobox:
 *
 * NOTES:
 *      The HIToolbox has incomplete and inconsistent support for ComboBoxes.
 *      There is no constant available to get the height of a ComboBox with
 *      GetThemeMetric. In fact, ComboBoxes are the same (fixed) height as
 *	kThemeMetricComboBoxLargeDisclosureWidth -> 17
 *      PopupButtons and PushButtons, but they have no shadow at the bottom.
 *      As a result, they are drawn 1 pixel above the center of the bounds
 *      rectangle rather than being centered like the other buttons.  One can
 *      request background bounds for a ComboBox, and it is reported with
 *      height 23, while the actual button face, including its 1-pixel border
 *      has height 21. Attempting to request the content bounds returns a 0x0
 *      rectangle.  Measurement indicates that the arrow button has width 18.
 *
 *      With no help available from HIToolbox, we have to use hard-wired
 *      constants for the padding. We shift the bounding rectangle downward by
 *      1 pixel to account for the fact that the button is not centered.
 *	Padding and margins guesstimated by trial-and-error.
 */

// OS dependent ???
static Ttk_Padding ComboboxPadding = {7, 5, 24, 5};
static Ttk_Padding ComboboxPadding = { 2, 3, 17, 1 };
static Ttk_Padding ComboboxMargins = { 3, 3, 4, 4 };

static void ComboboxElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    int *minWidth,
    int *minHeight,
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *minWidth = 24;
    *minHeight = 0;
    *paddingPtr = ComboboxPadding;
    *widthPtr = 0;
    *heightPtr = 0;
    *paddingPtr = Ttk_AddPadding(ComboboxMargins, ComboboxPadding);
}

static void ComboboxElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ComboboxMargins));
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = Ttk_StateTableLookup(ThemeStateTable, state),
	.kind = kThemeComboBox,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state),
    };

    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	bounds = CGRectInset(bounds, -1, -1);
	DrawButton(bounds, info, state, dc.context, tkwin);
    } else {
	bounds.origin.y += 1;
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	       NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec ComboboxElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    ComboboxElementSize,
    ComboboxElementDraw
};





/*----------------------------------------------------------------------
 * +++ Spinbutton elements --
 * +++ Spinbuttons.
 *
 *      From Apple HIG, part III, section "Controls", "The Stepper Control":
 *      there should be 2 pixels of space between the stepper control (AKA
 *      IncDecButton, AKA "little arrows") and the text field it modifies.
 * From Apple HIG, part III, section "Controls", "The Stepper Control":
 * there should be 2 pixels of space between the stepper control
 * (AKA IncDecButton, AKA "little arrows") and the text field it modifies.
 *
 *      Ttk expects the up and down arrows to be distinct elements but
 *      HIToolbox draws them as one widget with two different pressed states.
 *      We work around this by defining them as separate elements in the
 *      layout, but making each one have a drawing method which also draws the
 *      other one.  The down button does no drawing when not pressed, and when
 *      pressed draws the entire IncDecButton in its "pressed down" state.
 *      The up button draws the entire IncDecButton when not pressed and when
 *      pressed draws the IncDecButton in its "pressed up" state.  NOTE: This
 *      means that when the down button is pressed the IncDecButton will be
 *      drawn twice, first in unpressed state by the up arrow and then in
 *      "pressed down" state by the down button.  The drawing must be done in
 *      that order.  So the up button must be listed first in the layout.
 */

static Ttk_Padding SpinbuttonMargins = {2, 0, 0, 0};
static Ttk_Padding SpinbuttonMargins = {2,0,2,0};

static void SpinButtonReBounds(
    Tk_Window tkwin,
static void SpinButtonElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    CGRect *bounds)
{
    if (TkMacOSXInDarkMode(tkwin)) {
	bounds->origin.x -= 2;
	bounds->origin.y += 1;
	bounds->size.height -= 0.5;
    } else {
	bounds->origin.x -= 3;
	bounds->origin.y += 1;
	bounds->size.width += 1;
    }
}

    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
static void SpinButtonElementSize(
    TCL_UNUSED(void *),       /* clientdata */
    TCL_UNUSED(void *),       /* elementRecord */
    TCL_UNUSED(Tk_Window),    /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* PaddingPtr */
{
    SInt32 s;

    ChkErr(GetThemeMetric, kThemeMetricLittleArrowsWidth, &s);
    *minWidth = s + Ttk_PaddingWidth(SpinbuttonMargins);
    *widthPtr = s + Ttk_PaddingWidth(SpinbuttonMargins);
    ChkErr(GetThemeMetric, kThemeMetricLittleArrowsHeight, &s);
    *minHeight = 2 + (s + Ttk_PaddingHeight(SpinbuttonMargins)) / 2;
    *heightPtr = s + Ttk_PaddingHeight(SpinbuttonMargins);
}

static void SpinButtonUpElementDraw(
static void SpinButtonElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins));
    int infoState;

    /* @@@ can't currently distinguish PressedUp (== Pressed) from PressedDown;
    SpinButtonReBounds(tkwin, &bounds);
    bounds.size.height *= 2;
    if (state & TTK_STATE_PRESSED) {
	infoState = kThemeStatePressedUp;
    } else {
	infoState = Ttk_StateTableLookup(ThemeStateTable, state);
    }
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = infoState,
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };
    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	DrawButton(bounds, info, state, dc.context, tkwin);
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
	       NULL);
    }
    END_DRAWING
}

     * ignore this bit for now [see #2219588]
static Ttk_ElementSpec SpinButtonUpElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SpinButtonElementSize,
    SpinButtonUpElementDraw
};

     */
static void SpinButtonDownElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins));
    int infoState = 0;

    SpinButtonReBounds(tkwin, &bounds);
    bounds.origin.y -= bounds.size.height;
    bounds.size.height += bounds.size.height;
    if (state & TTK_STATE_PRESSED) {
	infoState = kThemeStatePressedDown;
    } else {
	return;
    }
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = infoState,
	.state = Ttk_StateTableLookup(ThemeStateTable, state & ~TTK_STATE_PRESSED),
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };

    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	DrawButton(bounds, info, state, dc.context, tkwin);
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	       NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec SpinButtonDownElementSpec = {
static Ttk_ElementSpec SpinButtonElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SpinButtonElementSize,
    SpinButtonDownElementDraw
    SpinButtonElementDraw
};


/*----------------------------------------------------------------------
 * +++ DrawThemeTrack-based elements --
 *
 *    Progress bars and scales. (See also: <<NOTE-TRACKS>>)
 * Progress bars and scales. (See also: <<NOTE-TRACKS>>)
 */

/*
 * Apple does not change the appearance of a slider when the window becomes
 * inactive.  So we shouldn't either.
 */

static const Ttk_StateTable ThemeTrackEnableTable[] = {
    {kThemeTrackDisabled, TTK_STATE_DISABLED, 0},
    {kThemeTrackActive, TTK_STATE_BACKGROUND, 0},
    {kThemeTrackActive, 0, 0}
static Ttk_StateTable ThemeTrackEnableTable[] = {
    { kThemeTrackDisabled, TTK_STATE_DISABLED, 0 },
    { kThemeTrackInactive, TTK_STATE_BACKGROUND, 0 },
    { kThemeTrackActive, 0, 0 }
    /* { kThemeTrackNothingToScroll, ?, ? }, */
};

typedef struct {        /* TrackElement client data */
    ThemeTrackKind kind;
    SInt32 thicknessMetric;
typedef struct {	/* TrackElement client data */
    ThemeTrackKind	kind;
    SInt32		thicknessMetric;
} TrackElementData;

static TrackElementData ScaleData = {
    kThemeSlider, kThemeMetricHSliderHeight
};


typedef struct {
    Tcl_Obj *fromObj;           /* minimum value */
    Tcl_Obj *toObj;             /* maximum value */
    Tcl_Obj *valueObj;          /* current value */
    Tcl_Obj *orientObj;         /* horizontal / vertical */
    Tcl_Obj *fromObj;		/* minimum value */
    Tcl_Obj *toObj;		/* maximum value */
    Tcl_Obj *valueObj;		/* current value */
    Tcl_Obj *orientObj;		/* horizontal / vertical */
} TrackElement;

static Ttk_ElementOptionSpec TrackElementOptions[] = {
    {"-from", TK_OPTION_DOUBLE, offsetof(TrackElement, fromObj), NULL},
    {"-to", TK_OPTION_DOUBLE, offsetof(TrackElement, toObj), NULL},
    {"-value", TK_OPTION_DOUBLE, offsetof(TrackElement, valueObj), NULL},
    {"-orient", TK_OPTION_STRING, offsetof(TrackElement, orientObj), NULL},
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
    { "-from", TK_OPTION_DOUBLE, Tk_Offset(TrackElement,fromObj) },
    { "-to", TK_OPTION_DOUBLE, Tk_Offset(TrackElement,toObj) },
    { "-value", TK_OPTION_DOUBLE, Tk_Offset(TrackElement,valueObj) },
    { "-orient", TK_OPTION_STRING, Tk_Offset(TrackElement,orientObj) },
    {0,0,0}
};

static void TrackElementSize(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),       /* elementRecord */
    TCL_UNUSED(Tk_Window),    /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TrackElementData *data = (TrackElementData *)clientData;
    SInt32 size = 24;   /* reasonable default ... */
    TrackElementData *data = clientData;
    SInt32 size = 24;	/* reasonable default ... */

    ChkErr(GetThemeMetric, data->thicknessMetric, &size);
    *minWidth = *minHeight = size;
    *widthPtr = *heightPtr = size;
}

static void TrackElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    TrackElementData *data = (TrackElementData *)clientData;
    TrackElement *elem = (TrackElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;
    double from = 0, to = 100, value = 0, fraction, max;
    TrackElementData *data = clientData;
    TrackElement *elem = elementRecord;
    int orientation = TTK_ORIENT_HORIZONTAL;
    double from = 0, to = 100, value = 0, factor;
    CGRect bounds = BoxToRect(d, b);

    Ttk_GetOrientFromObj(NULL, elem->orientObj, &orientation);
    Tcl_GetDoubleFromObj(NULL, elem->fromObj, &from);
    Tcl_GetDoubleFromObj(NULL, elem->toObj, &to);
    Tcl_GetDoubleFromObj(NULL, elem->valueObj, &value);
    factor = RangeToFactor(to - from);

    fraction = (value - from) / (to - from);
    max = RangeToFactor(fabs(to - from));
    HIThemeTrackDrawInfo info = {
	.version = 0,
	.kind = data->kind,
	.bounds = bounds,
	.min = 0,
	.max = max,
	.value = fraction * max,
	.bounds = BoxToRect(d, b),
	.min = from * factor,
	.max = to * factor,
	.value = value * factor,
	.attributes = kThemeTrackShowThumb |
	    (orientation == TTK_ORIENT_HORIZONTAL ?
	    kThemeTrackHorizontal : 0),
		(orientation == TTK_ORIENT_HORIZONTAL ?
		kThemeTrackHorizontal : 0),
	.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state),
	.trackInfo.progress.phase = 0
	.trackInfo.progress.phase = 0,
    };

    if (info.kind == kThemeSlider) {
	info.trackInfo.slider.pressState = state & TTK_STATE_PRESSED ?
	    kThemeThumbPressed : 0;
		kThemeThumbPressed : 0;
	if (state & TTK_STATE_ALTERNATE) {
	    info.trackInfo.slider.thumbDir = kThemeThumbDownward;
	} else {
	    info.trackInfo.slider.thumbDir = kThemeThumbPlain;
	}
    }
	info.trackInfo.slider.thumbDir = kThemeThumbPlain;
    }

    BEGIN_DRAWING(d)
    if (([NSApp macOSVersion] > 100800) && !(state & TTK_STATE_ALTERNATE)) {

	/*
	 * We use the reserved field to indicate whether "from" is less than
	 * "to".  It should be 0 if passing the info to HIThemeDrawInfo, but
	 * we aren't doing that.
	 */

    BEGIN_DRAWING(d)
	info.reserved = (from < to);
	DrawSlider(dc.context, bounds, info, state, tkwin);
    } else {
	ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    }
    END_DRAWING
}

static Ttk_ElementSpec TrackElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TrackElement),
    TrackElementOptions,
    TrackElementSize,
    TrackElementDraw
};

/*----------------------------------------------------------------------
 * Slider elements -- <<NOTE-TRACKS>>
/*
 * Slider element -- <<NOTE-TRACKS>>
 *
 * Has geometry only. The Scale widget adjusts the position of this element,
 * and uses it for hit detection. In the Aqua theme, the slider is actually
 * drawn as part of the trough element.
 *
 * Also buggy: The geometry here is a Wild-Assed-Guess; I can't
 * figure out how to get the Appearance Manager to tell me the
 * slider size.
 */

static void SliderElementSize(
    TCL_UNUSED(void *),        /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),        /* elementRecord */
    TCL_UNUSED(Tk_Window),     /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *minWidth = *minHeight = 24;
    *widthPtr = *heightPtr = 24;
}

static Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SliderElementSize,
    TtkNullElementDraw
};

/*----------------------------------------------------------------------
 * +++ Progress bar elements --
 * +++ Progress bar element (new):
 *
 * @@@ NOTE: According to an older revision of the Aqua reference docs,
 * @@@ the 'phase' field is between 0 and 4. Newer revisions say
 * @@@ that it can be any UInt8 value.
 */

typedef struct {
    Tcl_Obj *orientObj;         /* horizontal / vertical */
    Tcl_Obj *valueObj;          /* current value */
    Tcl_Obj *maximumObj;        /* maximum value */
    Tcl_Obj *phaseObj;          /* animation phase */
    Tcl_Obj *modeObj;           /* progress bar mode */
    Tcl_Obj *orientObj;		/* horizontal / vertical */
    Tcl_Obj *valueObj;		/* current value */
    Tcl_Obj *maximumObj;	/* maximum value */
    Tcl_Obj *phaseObj;		/* animation phase */
    Tcl_Obj *modeObj;		/* progress bar mode */
} PbarElement;

static Ttk_ElementOptionSpec PbarElementOptions[] = {
    {"-orient", TK_OPTION_STRING,
     offsetof(PbarElement, orientObj), "horizontal"},
    {"-value", TK_OPTION_DOUBLE,
     offsetof(PbarElement, valueObj), "0.0"},
    {"-maximum", TK_OPTION_DOUBLE,
     offsetof(PbarElement, maximumObj), "100.0"},
    {"-phase", TK_OPTION_INT,
     offsetof(PbarElement, phaseObj), "0"},
    {"-mode", TK_OPTION_STRING,
     offsetof(PbarElement, modeObj), "determinate"},
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
    { "-orient", TK_OPTION_STRING,
	Tk_Offset(PbarElement,orientObj), "horizontal" },
    { "-value", TK_OPTION_DOUBLE,
	Tk_Offset(PbarElement,valueObj), "0" },
    { "-maximum", TK_OPTION_DOUBLE,
	Tk_Offset(PbarElement,maximumObj), "100" },
    { "-phase", TK_OPTION_INT,
	Tk_Offset(PbarElement,phaseObj), "0" },
    { "-mode", TK_OPTION_STRING,
	Tk_Offset(PbarElement,modeObj), "determinate" },
    {0,0,0,0}
};

static void PbarElementSize(
    TCL_UNUSED(void *),        /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),        /* elementRecord */
    TCL_UNUSED(Tk_Window),     /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    SInt32 size = 24;           /* @@@ Check HIG for correct default */
    SInt32 size = 24;	/* @@@ Check HIG for correct default */

    ChkErr(GetThemeMetric, kThemeMetricLargeProgressBarThickness, &size);
    *minWidth = *minHeight = size;
    *widthPtr = *heightPtr = size;
}

static void PbarElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    PbarElement *pbar = (PbarElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;
    PbarElement *pbar = elementRecord;
    int orientation = TTK_ORIENT_HORIZONTAL, phase = 0;
    int phase;
    double value = 0, maximum = 100, factor;
    CGRect bounds = BoxToRect(d, b);
    int isIndeterminate = !strcmp("indeterminate",
				  Tcl_GetString(pbar->modeObj));

    Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orientation);
    Tcl_GetDoubleFromObj(NULL, pbar->valueObj, &value);
    Tcl_GetDoubleFromObj(NULL, pbar->maximumObj, &maximum);
    Tcl_GetIntFromObj(NULL, pbar->phaseObj, &phase);

    factor = RangeToFactor(maximum);
    if (isIndeterminate) {

	/*
	 * When an indeterminate progress bar is animated the phase is
	 * (currently) always 0 and the value increases from min to max
	 * and then decreases back to min.  We scale the value by 3 to
	 * speed the animation up a bit.
	 */

	double remainder = fmod(3*value, 2*maximum);
	value = remainder > maximum ? 2*maximum - remainder : remainder;
    }
    factor = RangeToFactor(maximum);
    HIThemeTrackDrawInfo info = {
	.version = 0,
	.kind = (!strcmp("indeterminate", Tcl_GetString(pbar->modeObj)) && value) ?
	.kind = isIndeterminate? kThemeIndeterminateBar : kThemeProgressBar,
	.bounds = bounds,
		kThemeIndeterminateBar : kThemeProgressBar,
	.bounds = BoxToRect(d, b),
	.min = 0,
	.max = maximum * factor,
	.value = value * factor,
	.attributes = kThemeTrackShowThumb |
	    (orientation == TTK_ORIENT_HORIZONTAL ?
	    kThemeTrackHorizontal : 0),
		(orientation == TTK_ORIENT_HORIZONTAL ?
		kThemeTrackHorizontal : 0),
	.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state),
	.trackInfo.progress.phase = phase,
    };

    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	DrawProgressBar(dc.context, bounds, info, state, tkwin);
    } else {
	ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    }
    END_DRAWING
}

static Ttk_ElementSpec PbarElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(PbarElement),
    PbarElementOptions,
    PbarElementSize,
    PbarElementDraw
};

/*----------------------------------------------------------------------
 * +++ Scrollbar elements
 */

typedef struct
{
    Tcl_Obj *orientObj;
} ScrollbarElement;

static Ttk_ElementOptionSpec ScrollbarElementOptions[] = {
    {"-orient", TK_OPTION_STRING,
     offsetof(ScrollbarElement, orientObj), "horizontal"},
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
};
static void TroughElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *elementRecord,
    TCL_UNUSED(Tk_Window), /* tkwin */
    int *minWidth,
    int *minHeight,
    Ttk_Padding *paddingPtr)
{
    ScrollbarElement *scrollbar = (ScrollbarElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;
    SInt32 thickness = 15;

    Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);
    ChkErr(GetThemeMetric, kThemeMetricScrollBarWidth, &thickness);
    if (orientation == TTK_ORIENT_HORIZONTAL) {
	*minHeight = thickness;
	if ([NSApp macOSVersion] > 100700) {
	    *paddingPtr = Ttk_MakePadding(4, 4, 4, 3);
	}
    } else {
	*minWidth = thickness;
	if ([NSApp macOSVersion] > 100700) {
	    *paddingPtr = Ttk_MakePadding(4, 4, 3, 4);
	}
    }
}

static void TroughElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State)) /* state */
{
    ScrollbarElement *scrollbar = (ScrollbarElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;
    CGRect bounds = BoxToRect(d, b);
    GrayColor bgGray;

    Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);
    if (orientation == TTK_ORIENT_HORIZONTAL) {
	bounds = CGRectInset(bounds, 0, 1);
    } else {
	bounds = CGRectInset(bounds, 1, 0);
    }
    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {
	bgGray = TkMacOSXInDarkMode(tkwin) ? darkTrough : lightTrough;
	CGContextSetFillColorWithColor(dc.context, CGColorFromGray(bgGray));
    } else {
	ChkErr(HIThemeSetFill, kThemeBrushDocumentWindowBackground, NULL,
	    dc.context, HIOrientation);
    }
    CGContextFillRect(dc.context, bounds);
    END_DRAWING
}

static Ttk_ElementSpec TroughElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    TroughElementSize,
    TroughElementDraw
};
static void ThumbElementSize(
    TCL_UNUSED(void *),        /* clientData */
    void *elementRecord,
    TCL_UNUSED(Tk_Window),     /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
{
    ScrollbarElement *scrollbar = (ScrollbarElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;

    Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);
    if (orientation == TTK_ORIENT_VERTICAL) {
	*minHeight = 18;
	*minWidth = 8;
    } else {
	*minHeight = 8;
	*minWidth = 18;
    }
}

static void ThumbElementDraw(
    TCL_UNUSED(void *),        /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    Ttk_State state)
{
    ScrollbarElement *scrollbar = (ScrollbarElement *)elementRecord;
    Ttk_Orient orientation = TTK_ORIENT_HORIZONTAL;

    Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);

    /*
     * In order to make ttk scrollbars work correctly it is necessary to be
     * able to display the thumb element at the size and location which the ttk
     * scrollbar widget requests.  The algorithm that HIToolbox uses to
     * determine the thumb geometry from the input values of min, max, value
     * and viewSize is undocumented.  A seemingly natural algorithm is
     * implemented below.  This code uses that algorithm for older OS versions,
     * because using HIToolbox also handles drawing the buttons and 3D thumb used
     * on those systems.  For newer systems the cleanest approach is to just
     * draw the thumb directly.
     */

    if ([NSApp macOSVersion] > 100800) {
	CGRect thumbBounds = BoxToRect(d, b);
	CGColorRef thumbColor;
	GrayColor bgGray;

	/*
	 * Apple does not draw the thumb when scrolling is not possible.
	 */

	if ((orientation == TTK_ORIENT_HORIZONTAL &&
	    thumbBounds.size.width >= Tk_Width(tkwin) - 8) ||
	    (orientation == TTK_ORIENT_VERTICAL &&
	    thumbBounds.size.height >= Tk_Height(tkwin) - 8)) {
	    return;
	}
	int isDark = TkMacOSXInDarkMode(tkwin);
	if ((state & TTK_STATE_PRESSED) ||
	    (state & TTK_STATE_HOVER)) {
	    bgGray = isDark ? darkActiveThumb : lightActiveThumb;
	} else {
	    bgGray = isDark ? darkInactiveThumb : lightInactiveThumb;
	}
	thumbColor = CGColorFromGray(bgGray);
	BEGIN_DRAWING(d)
	FillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor);
	END_DRAWING
    } else {
	double thumbSize, trackSize, visibleSize, factor, fraction;
	MacDrawable *macWin = (MacDrawable *)Tk_WindowId(tkwin);
	CGRect troughBounds = {{macWin->xOff, macWin->yOff},
			       {Tk_Width(tkwin), Tk_Height(tkwin)}};

        /*
         * The info struct has integer fields, which will be converted to
         * floats in the drawing routine.  All of values provided in the info
         * struct, namely min, max, value, and viewSize are only defined up to
         * an arbitrary scale factor.  To avoid roundoff error we scale so
         * that the viewSize is a large float which is smaller than the
         * largest int.
         */

	HIThemeTrackDrawInfo info = {
	    .version = 0,
	    .bounds = troughBounds,
	    .min = 0,
	    .attributes = kThemeTrackShowThumb |
		kThemeTrackThumbRgnIsNotGhost,
	    .enableState = kThemeTrackActive
	};
	factor = RangeToFactor(100.0);
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    trackSize = troughBounds.size.width;
	    thumbSize = b.width;
	    fraction = b.x / trackSize;
	} else {
	    trackSize = troughBounds.size.height;
	    thumbSize = b.height;
	    fraction = b.y / trackSize;
	}
	visibleSize = (thumbSize / trackSize) * factor;
	info.max = factor - visibleSize;
	info.trackInfo.scrollbar.viewsize = visibleSize;
	if ([NSApp macOSVersion] < 100800 ||
	    orientation == TTK_ORIENT_HORIZONTAL) {
	    info.value = factor * fraction;
	} else {
	    info.value = info.max - factor * fraction;
	}
	if ((state & TTK_STATE_PRESSED) ||
	    (state & TTK_STATE_HOVER)) {
	    info.trackInfo.scrollbar.pressState = kThemeThumbPressed;
	} else {
	    info.trackInfo.scrollbar.pressState = 0;
	}
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    info.attributes |= kThemeTrackHorizontal;
	} else {
	    info.attributes &= ~kThemeTrackHorizontal;
	}
	BEGIN_DRAWING(d)
	HIThemeDrawTrack(&info, 0, dc.context, kHIThemeOrientationNormal);
	END_DRAWING
    }
}

static Ttk_ElementSpec ThumbElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    ThumbElementSize,
    ThumbElementDraw
};
static void ArrowElementSize(
    TCL_UNUSED(void *),        /* clientData */
    TCL_UNUSED(void *),        /* elementRecord */
    TCL_UNUSED(Tk_Window),     /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
{
    if ([NSApp macOSVersion] < 100800) {
	*minHeight = *minWidth = 14;
    } else {
	*minHeight = *minWidth = -1;
    }
}

static Ttk_ElementSpec ArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ScrollbarElement),
    ScrollbarElementOptions,
    ArrowElementSize,
    TtkNullElementDraw
};

/*----------------------------------------------------------------------
 * +++ Separator element.
 *
 *    DrawThemeSeparator() guesses the orientation of the line from the width
 *    and height of the rectangle, so the same element can can be used for
 *    horizontal, vertical, and general separators.
 * DrawThemeSeparator() guesses the orientation of the line from
 * the width and height of the rectangle, so the same element can
 * can be used for horizontal, vertical, and general separators.
 */

static void SeparatorElementSize(
    TCL_UNUSED(void *),       /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),       /* elementRecord */
    TCL_UNUSED(Tk_Window),    /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *minWidth = *minHeight = 1;
    *widthPtr = *heightPtr = 1;
}

static void SeparatorElementDraw(
    TCL_UNUSED(void *),       /* clientData */
    TCL_UNUSED(void *),       /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);
    const HIThemeSeparatorDrawInfo info = {
	.version = 0,
        /* Separator only supports kThemeStateActive, kThemeStateInactive */
	.state = Ttk_StateTableLookup(ThemeStateTable,
	/* Separator only supports kThemeStateActive, kThemeStateInactive */
	.state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND),
	    state & TTK_STATE_BACKGROUND),
    };

    BEGIN_DRAWING(d)
    if (TkMacOSXInDarkMode(tkwin)) {
	DrawDarkSeparator(bounds, dc.context, tkwin);
    } else {
	ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context,
    ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context, HIOrientation);
	    HIOrientation);
    }
    END_DRAWING
}

static Ttk_ElementSpec SeparatorElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SeparatorElementSize,
    SeparatorElementDraw
};

/*----------------------------------------------------------------------
 * +++ Size grip elements -- (obsolete)
 * +++ Size grip element.
 */

static const ThemeGrowDirection sizegripGrowDirection
    = kThemeGrowRight | kThemeGrowDown;
	= kThemeGrowRight|kThemeGrowDown;

static void SizegripElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    HIThemeGrowBoxDrawInfo info = {
	.version = 0,
	.state = kThemeStateActive,
	.kind = kHIThemeGrowBoxKindNormal,
	.direction = sizegripGrowDirection,
	.size = kHIThemeGrowBoxSizeNormal,
    };
    CGRect bounds = CGRectZero;

    ChkErr(HIThemeGetGrowBoxBounds, &bounds.origin, &info, &bounds);
    *minWidth = bounds.size.width;
    *minHeight = bounds.size.height;
    *widthPtr = bounds.size.width;
    *heightPtr = bounds.size.height;
}

static void SizegripElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);
    HIThemeGrowBoxDrawInfo info = {
	.version = 0,
        /* Grow box only supports kThemeStateActive, kThemeStateInactive */
	.state = Ttk_StateTableLookup(ThemeStateTable,
	/* Grow box only supports kThemeStateActive, kThemeStateInactive */
	.state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND),
	    state & TTK_STATE_BACKGROUND),
	.kind = kHIThemeGrowBoxKindNormal,
	.direction = sizegripGrowDirection,
	.size = kHIThemeGrowBoxSizeNormal,
    };

    BEGIN_DRAWING(d)
    ChkErr(HIThemeDrawGrowBox, &bounds.origin, &info, dc.context,
    ChkErr(HIThemeDrawGrowBox, &bounds.origin, &info, dc.context, HIOrientation);
	HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec SizegripElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SizegripElementSize,
    SizegripElementDraw
};

/*----------------------------------------------------------------------
 * +++ Background and fill elements --
 * +++ Background and fill elements.
 *
 *      Before drawing any ttk widget, its bounding rectangle is filled with a
 *      background color.  This color must match the background color of the
 *	This isn't quite right: In Aqua, the correct background for
 *      containing widget to avoid looking ugly. The need for care when doing
 *      this is exacerbated by the fact that ttk enforces its "native look" by
 *      not allowing user control of the background or highlight colors of ttk
 *	a control depends on what kind of container it belongs to,
 *      widgets.
 *
 *      This job is made more complicated in recent versions of macOS by the
 *      fact that the Appkit GroupBox (used for ttk LabelFrames) and
 *      TabbedPane (used for the Notebook widget) both place their content
 *      inside a rectangle with rounded corners that has a color which
 *      contrasts with the dialog background color.  Moreover, although the
 *      Apple human interface guidelines recommend against doing so, there are
 *      times when one wants to nest these widgets, for example placing a
 *      GroupBox inside of a TabbedPane.  To have the right contrast, each
 *      level of nesting requires a different color.
 *
 *      Previous Tk releases used the HIThemeDrawGroupBox routine to draw
 *      GroupBoxes and TabbedPanes. This meant that the best that could be
 *      done was to set the GroupBox to be of kind
 *      kHIThemeGroupBoxKindPrimaryOpaque, and set its fill color to be the
 *      system background color.  If widgets inside the box were drawn with
 *      the system background color the backgrounds would match.  But this
 *      produces a GroupBox with no contrast, the only visual clue being a
 *      faint highlighting around the top of the GroupBox.  Moreover, the
 *	and the type of the top-level window.
 *      TabbedPane does not have an Opaque version, so while it is drawn
 *      inside a contrasting rounded rectangle, the widgets inside the pane
 *      needed to be enclosed in a frame with the system background
 *      color. This added a visual artifact since the frame's background color
 *      does not match the Pane's background color.  That code has now been
 *      replaced with the standalone drawing procedure macOSXDrawGroupBox,
 *      which draws a rounded rectangle with an appropriate contrasting
 *      background color.
 *
 *      Patterned backgrounds, which are now obsolete, should be aligned with
 *      the coordinate system of the top-level window.  Apparently failing to
 *	Also: patterned backgrounds should be aligned with the coordinate
 *	system of the top-level window.  If we're drawing into an
 *      do this used to cause graphics anomalies when drawing into an
 *      off-screen graphics port.  The code for handling this is currently
 *	off-screen graphics port this leads to alignment glitches.
 *      commented out.
 */

static void FillElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    CGRect bounds = BoxToRect(d, b);

    if ([NSApp macOSVersion] > 100800) {
	CGColorRef bgColor;
	BEGIN_DRAWING(d)
	bgColor = GetBackgroundCGColor(dc.context, tkwin, NO, 0);
	CGContextSetFillColorWithColor(dc.context, bgColor);
	CGContextFillRect(dc.context, bounds);
	END_DRAWING
    } else {
	ThemeBrush brush = (state & TTK_STATE_BACKGROUND)
    ThemeBrush brush = (state & TTK_STATE_BACKGROUND)
	    ? kThemeBrushModelessDialogBackgroundInactive
	    : kThemeBrushModelessDialogBackgroundActive;

	BEGIN_DRAWING(d)
	ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation);
	CGContextFillRect(dc.context, bounds);
	END_DRAWING
    }
}
    BEGIN_DRAWING(d)
    ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation);
    //QDSetPatternOrigin(PatternOrigin(tkwin, d));
    CGContextFillRect(dc.context, bounds);
    END_DRAWING
}


static void BackgroundElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    TCL_UNUSED(Ttk_Box),
    Ttk_State state)
{
    FillElementDraw(
    FillElementDraw(clientData, elementRecord, tkwin, d, Ttk_WinBox(tkwin),
	state);
	clientData, elementRecord, tkwin,
	d, Ttk_WinBox(tkwin), state);
}

static Ttk_ElementSpec FillElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TtkNullElementSize,
    FillElementDraw
};

static Ttk_ElementSpec BackgroundElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TtkNullElementSize,
    BackgroundElementDraw
};

/*----------------------------------------------------------------------
 * +++ ToolbarBackground element -- toolbar style for frames.
 *
 *    This is very similar to the normal background element, but uses a
 *    different ThemeBrush in order to get the lighter pinstripe effect
 *    used in toolbars. We use SetThemeBackground() rather than
 *    ApplyThemeBackground() in order to get the right style.
 *	This is very similar to the normal background element, but uses a
 *	different ThemeBrush in order to get the lighter pinstripe effect
 *	used in toolbars. We use SetThemeBackground() rather than
 *	ApplyThemeBackground() in order to get the right style.
 *
 *    <URL: http://developer.apple.com/documentation/Carbon/Reference/
 *    Appearance_Manager/appearance_manager/constant_7.html#/
 *    /apple_ref/doc/uid/TP30000243/C005321>
 * <URL: http://developer.apple.com/documentation/Carbon/Reference/
 *	Appearance_Manager/appearance_manager/constant_7.html#/
 *	/apple_ref/doc/uid/TP30000243/C005321>
 *
 */

static void ToolbarBackgroundElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    TCL_UNUSED(Ttk_Box),
    TCL_UNUSED(Ttk_State))
{
    ThemeBrush brush = kThemeBrushToolbarBackground;
    CGRect bounds = BoxToRect(d, Ttk_WinBox(tkwin));

    BEGIN_DRAWING(d)
    ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation);
    //QDSetPatternOrigin(PatternOrigin(tkwin, d));
    CGContextFillRect(dc.context, bounds);
    END_DRAWING
}

static Ttk_ElementSpec ToolbarBackgroundElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TtkNullElementSize,
    ToolbarBackgroundElementDraw
};

/*----------------------------------------------------------------------
 * +++ Field elements --
 *
 *      Used for the Treeview widget. This is like the BackgroundElement
 *      except that the fieldbackground color is configurable.
 */

typedef struct {
    Tcl_Obj     *backgroundObj;
} FieldElement;

static Ttk_ElementOptionSpec FieldElementOptions[] = {
    {"-fieldbackground", TK_OPTION_BORDER,
     offsetof(FieldElement, backgroundObj), "white"},
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
};

static void FieldElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    FieldElement *e = (FieldElement *)elementRecord;
    Tk_3DBorder backgroundPtr =
	Tk_Get3DBorderFromObj(tkwin, e->backgroundObj);

    XFillRectangle(Tk_Display(tkwin), d,
	Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC),
	b.x, b.y, b.width, b.height);
}

static Ttk_ElementSpec FieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    TtkNullElementSize,
    FieldElementDraw
};

/*----------------------------------------------------------------------
 * +++ Treeview headers --
 * +++ Treeview header
 *
 *    On systems older than 10.9 the header is a kThemeListHeaderButton drawn
 *	Redefine the header to use a kThemeListHeaderButton.
 *    by HIToolbox.  On newer systems those buttons do not match the Apple
 *    buttons, so we draw them from scratch.
 */

#define TTK_TREEVIEW_STATE_SORTARROW	TTK_STATE_USER1
static const Ttk_StateTable TreeHeaderValueTable[] = {
    {kThemeButtonOn, TTK_STATE_ALTERNATE, 0},
    {kThemeButtonOn, TTK_STATE_SELECTED, 0},
    {kThemeButtonOff, 0, 0}
static Ttk_StateTable TreeHeaderValueTable[] = {
    { kThemeButtonOn, TTK_STATE_ALTERNATE},
    { kThemeButtonOn, TTK_STATE_SELECTED},
    { kThemeButtonOff, 0}
};

static const Ttk_StateTable TreeHeaderAdornmentTable[] = {
    {kThemeAdornmentHeaderButtonSortUp,
     TTK_STATE_ALTERNATE | TTK_TREEVIEW_STATE_SORTARROW, 0},
    {kThemeAdornmentDefault,
     TTK_STATE_SELECTED | TTK_TREEVIEW_STATE_SORTARROW, 0},
    {kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_ALTERNATE, 0},
    {kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_SELECTED, 0},
    {kThemeAdornmentFocus, TTK_STATE_FOCUS, 0},
    {kThemeAdornmentNone, 0, 0}
static Ttk_StateTable TreeHeaderAdornmentTable[] = {
    { kThemeAdornmentHeaderButtonSortUp,
	    TTK_STATE_ALTERNATE|TTK_TREEVIEW_STATE_SORTARROW},
    { kThemeAdornmentDefault,
	    TTK_STATE_SELECTED|TTK_TREEVIEW_STATE_SORTARROW},
    { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_ALTERNATE},
    { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_SELECTED},
    { kThemeAdornmentFocus, TTK_STATE_FOCUS},
    { kThemeAdornmentNone, 0}
};

static void TreeAreaElementSize (
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    TCL_UNUSED(int *),     /* minWidth */
    TCL_UNUSED(int *),     /* minHeight */
    Ttk_Padding *paddingPtr)
{

    /*
     * Padding is needed to get the heading text to align correctly, since the
     * widget expects the heading to be the same height as a row.
     */

    if ([NSApp macOSVersion] > 100800) {
	*paddingPtr = Ttk_MakePadding(0, 4, 0, 0);
    }
}

static Ttk_ElementSpec TreeAreaElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TreeAreaElementSize,
    TtkNullElementDraw
};
static void TreeHeaderElementSize(
    void *clientData,
    void *elementRecord,
    Tk_Window tkwin,
    int *minWidth,
    int *minHeight,
    Ttk_Padding *paddingPtr)
{
    if ([NSApp macOSVersion] > 100800) {
	*minHeight = 24;
    } else {
	ButtonElementSize(clientData, elementRecord, tkwin, minWidth,
	    minHeight, paddingPtr);
    }
}

static void TreeHeaderElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    ThemeButtonParams *params = (ThemeButtonParams *)clientData;
    ThemeButtonParams *params = clientData;
    CGRect bounds = BoxToRect(d, b);
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = Ttk_StateTableLookup(ThemeStateTable, state),
	.kind = params->kind,
	.value = Ttk_StateTableLookup(TreeHeaderValueTable, state),
	.adornment = Ttk_StateTableLookup(TreeHeaderAdornmentTable, state),
    };

    BEGIN_DRAWING(d)
    if ([NSApp macOSVersion] > 100800) {

        /*
         * Compensate for the padding added in TreeHeaderElementSize, so
         * the larger heading will be drawn at the top of the widget.
         */

	bounds.origin.y -= 4;
	DrawListHeader(bounds, dc.context, tkwin, state);
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	    NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec TreeHeaderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TreeHeaderElementSize,
    ButtonElementSizeNoPadding,
    TreeHeaderElementDraw
};

/*----------------------------------------------------------------------
 * +++ Disclosure triangles --
/*
 * Disclosure triangle:
 */

#define TTK_TREEVIEW_STATE_OPEN         TTK_STATE_USER1
#define TTK_TREEVIEW_STATE_LEAF         TTK_STATE_USER2
static const Ttk_StateTable DisclosureValueTable[] = {
    {kThemeDisclosureDown, TTK_TREEVIEW_STATE_OPEN, 0},
    {kThemeDisclosureRight, 0, 0},
#define TTK_TREEVIEW_STATE_OPEN 	TTK_STATE_USER1
#define TTK_TREEVIEW_STATE_LEAF 	TTK_STATE_USER2
static Ttk_StateTable DisclosureValueTable[] = {
    { kThemeDisclosureDown, TTK_TREEVIEW_STATE_OPEN, 0 },
    { kThemeDisclosureRight, 0, 0 },
};

static void DisclosureElementSize(
    TCL_UNUSED(void *),    /* clientData */
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *),    /* elementRecord */
    TCL_UNUSED(Tk_Window), /* tkwin */
    int *minWidth,
    int *minHeight,
    TCL_UNUSED(Ttk_Padding *)) /* paddingPtr */
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    SInt32 s;

    ChkErr(GetThemeMetric, kThemeMetricDisclosureTriangleWidth, &s);
    *minWidth = s;
    *widthPtr = s;
    ChkErr(GetThemeMetric, kThemeMetricDisclosureTriangleHeight, &s);
    *minHeight = s;
    *heightPtr = s;
}

static void DisclosureElementDraw(
    TCL_UNUSED(void *),    /* clientData */
    TCL_UNUSED(void *),    /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Ttk_Box b,
    Ttk_State state)
{
    if (!(state & TTK_TREEVIEW_STATE_LEAF)) {
	int triangleState = TkMacOSXInDarkMode(tkwin) ?
	    kThemeStateInactive : kThemeStateActive;
	CGRect bounds = BoxToRect(d, b);
	const HIThemeButtonDrawInfo info = {
	    .version = 0,
	    .state = triangleState,
	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
	    .kind = kThemeDisclosureTriangle,
	    .value = Ttk_StateTableLookup(DisclosureValueTable, state),
	    .adornment = kThemeAdornmentDrawIndicatorOnly,
	};

	BEGIN_DRAWING(d)
	if ([NSApp macOSVersion] >= 110000) {
	    CGFloat rgba[4];
	    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
	    NSColor *stroke = [[NSColor textColor]
		colorUsingColorSpace: deviceRGB];
	    [stroke getComponents: rgba];
	    if (state & TTK_TREEVIEW_STATE_OPEN) {
		DrawOpenDisclosure(dc.context, bounds, 2, 8, rgba);
	    } else {
		DrawClosedDisclosure(dc.context, bounds, 2, 12, rgba);
	    }
	} else {
	    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	    NULL);
	}
	END_DRAWING
    }
}

static Ttk_ElementSpec DisclosureElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    DisclosureElementSize,
    DisclosureElementDraw
};

/*----------------------------------------------------------------------
 * +++ Widget layouts --
 * +++ Widget layouts.
 */

TTK_BEGIN_LAYOUT_TABLE(LayoutTable)

TTK_LAYOUT("Toolbar",
    TTK_NODE("Toolbar.background", TTK_FILL_BOTH))

TTK_LAYOUT("TButton",
    TTK_GROUP("Button.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))
	TTK_GROUP("Button.padding", TTK_FILL_BOTH,
	    TTK_NODE("Button.label", TTK_FILL_BOTH))))

TTK_LAYOUT("TRadiobutton",
    TTK_GROUP("Radiobutton.button", TTK_FILL_BOTH,
    TTK_GROUP("Radiobutton.padding", TTK_FILL_BOTH,
    TTK_NODE("Radiobutton.label", TTK_PACK_LEFT))))
	TTK_GROUP("Radiobutton.padding", TTK_FILL_BOTH,
	    TTK_NODE("Radiobutton.label", TTK_PACK_LEFT))))

TTK_LAYOUT("TCheckbutton",
    TTK_GROUP("Checkbutton.button", TTK_FILL_BOTH,
    TTK_GROUP("Checkbutton.padding", TTK_FILL_BOTH,
    TTK_NODE("Checkbutton.label", TTK_PACK_LEFT))))
	TTK_GROUP("Checkbutton.padding", TTK_FILL_BOTH,
	    TTK_NODE("Checkbutton.label", TTK_PACK_LEFT))))

TTK_LAYOUT("TMenubutton",
    TTK_GROUP("Menubutton.button", TTK_FILL_BOTH,
    TTK_GROUP("Menubutton.padding", TTK_FILL_BOTH,
    TTK_NODE("Menubutton.label", TTK_PACK_LEFT))))
	TTK_GROUP("Menubutton.padding", TTK_FILL_BOTH,
	    TTK_NODE("Menubutton.label", TTK_PACK_LEFT))))

TTK_LAYOUT("TCombobox",
    TTK_GROUP("Combobox.button", TTK_FILL_BOTH,
    TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
    TTK_NODE("Combobox.textarea", TTK_FILL_BOTH))))
    TTK_GROUP("Combobox.button", TTK_PACK_TOP|TTK_FILL_X,
	TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
	    TTK_NODE("Combobox.textarea", TTK_FILL_X))))

/* Image Button - no button */
TTK_LAYOUT("ImageButton",
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH)))

/* Inline Button */
TTK_LAYOUT("InlineButton",
    TTK_GROUP("InlineButton.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))

/* Rounded Rect Button -- transparent face */
TTK_LAYOUT("RoundedRectButton",
    TTK_GROUP("RoundedRectButton.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))

/* Gradient Button */
TTK_LAYOUT("GradientButton",
    TTK_GROUP("GradientButton.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))

/* Recessed Button - text only radio button */

TTK_LAYOUT("RecessedButton",
    TTK_GROUP("RecessedButton.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))

/* Sidebar Button - text only radio button for sidebars */

TTK_LAYOUT("SidebarButton",
    TTK_GROUP("SidebarButton.button", TTK_FILL_BOTH,
    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
    TTK_NODE("Button.label", TTK_FILL_BOTH))))

/* DisclosureButton (not a triangle) -- No label, no border*/
TTK_LAYOUT("DisclosureButton",
    TTK_NODE("DisclosureButton.button", TTK_FILL_BOTH))

/* HelpButton -- No label, no border*/
TTK_LAYOUT("HelpButton",
    TTK_NODE("HelpButton.button", TTK_FILL_BOTH))

/* Notebook tabs -- no focus ring */
TTK_LAYOUT("Tab",
    TTK_GROUP("Notebook.tab", TTK_FILL_BOTH,
    TTK_GROUP("Notebook.padding", TTK_FILL_BOTH,
    TTK_NODE("Notebook.label", TTK_FILL_BOTH))))
	TTK_GROUP("Notebook.padding", TTK_EXPAND|TTK_FILL_BOTH,
	    TTK_NODE("Notebook.label", TTK_EXPAND|TTK_FILL_BOTH))))

/* Spinbox -- buttons 2px to the right of the field. */
TTK_LAYOUT("TSpinbox",
    TTK_GROUP("Spinbox.buttons", TTK_PACK_RIGHT,
    TTK_NODE("Spinbox.uparrow", TTK_PACK_TOP | TTK_STICK_E)
    TTK_NODE("Spinbox.downarrow", TTK_PACK_BOTTOM | TTK_STICK_E))
    TTK_GROUP("Spinbox.field", TTK_FILL_X,
    TTK_NODE("Spinbox.textarea", TTK_FILL_X)))

TTK_LAYOUT("TEntry",
    TTK_GROUP("Entry.field", TTK_FILL_BOTH|TTK_BORDER,
        TTK_GROUP("Entry.padding", TTK_FILL_BOTH,
	    TTK_NODE("Entry.textarea", TTK_FILL_BOTH))))

/* Searchbox */
TTK_LAYOUT("Searchbox",
    TTK_GROUP("Searchbox.field", TTK_FILL_BOTH|TTK_BORDER,
        TTK_GROUP("Entry.padding", TTK_FILL_BOTH,
	    TTK_NODE("Entry.textarea", TTK_FILL_BOTH))))

/* Progress bars -- track only */
TTK_LAYOUT("TProgressbar",
    TTK_NODE("Progressbar.track", TTK_FILL_BOTH))
TTK_LAYOUT("TSpinbox",
    TTK_NODE("Spinbox.spinbutton", TTK_PACK_RIGHT|TTK_STICK_E)
    TTK_GROUP("Spinbox.field", TTK_EXPAND|TTK_FILL_X,
	TTK_NODE("Spinbox.textarea", TTK_EXPAND|TTK_FILL_X)))

/* Treeview -- no border. */
TTK_LAYOUT("Treeview",
TTK_LAYOUT("TProgressbar",
    TTK_GROUP("Treeview.field", TTK_FILL_BOTH,
    TTK_GROUP("Treeview.padding", TTK_FILL_BOTH,
    TTK_NODE("Treeview.treearea", TTK_FILL_BOTH))))
    TTK_NODE("Progressbar.track", TTK_EXPAND|TTK_FILL_BOTH))

/* Tree heading -- no border, fixed height */
TTK_LAYOUT("Heading",
    TTK_NODE("Treeheading.cell", TTK_FILL_BOTH)
    TTK_NODE("Treeheading.cell", TTK_FILL_X)
    TTK_NODE("Treeheading.image", TTK_PACK_RIGHT)
    TTK_NODE("Treeheading.text", TTK_PACK_TOP))
    TTK_NODE("Treeheading.text", 0))

/* Tree items -- omit focus ring */
TTK_LAYOUT("Item",
    TTK_GROUP("Treeitem.padding", TTK_FILL_BOTH,
    TTK_NODE("Treeitem.indicator", TTK_PACK_LEFT)
    TTK_NODE("Treeitem.image", TTK_PACK_LEFT)
    TTK_NODE("Treeitem.text", TTK_PACK_LEFT)))
	TTK_NODE("Treeitem.indicator", TTK_PACK_LEFT)
	TTK_NODE("Treeitem.image", TTK_PACK_LEFT)
	TTK_NODE("Treeitem.text", TTK_PACK_LEFT)))

/* Scrollbar Layout -- Buttons at the bottom (Snow Leopard and Lion only) */

TTK_LAYOUT("Vertical.TScrollbar",
    TTK_GROUP("Vertical.Scrollbar.trough", TTK_FILL_Y,
    TTK_NODE("Vertical.Scrollbar.thumb", TTK_FILL_BOTH)
    TTK_NODE("Vertical.Scrollbar.downarrow", TTK_PACK_BOTTOM)
    TTK_NODE("Vertical.Scrollbar.uparrow", TTK_PACK_BOTTOM)))

TTK_LAYOUT("Horizontal.TScrollbar",
    TTK_GROUP("Horizontal.Scrollbar.trough", TTK_FILL_X,
    TTK_NODE("Horizontal.Scrollbar.thumb", TTK_FILL_BOTH)
    TTK_NODE("Horizontal.Scrollbar.rightarrow", TTK_PACK_RIGHT)
    TTK_NODE("Horizontal.Scrollbar.leftarrow", TTK_PACK_RIGHT)))

TTK_END_LAYOUT_TABLE

/*----------------------------------------------------------------------
 * +++ Initialization --
 * +++ Initialization.
 */

/*----------------------------------------------------------------------
 * +++ Ttk_MacOSXInit --
 *
 *    Initialize variables which depend on [NSApp macOSVersion].  Called from
 *    [NSApp applicationDidFinishLaunching].
 */

MODULE_SCOPE
void Ttk_MacOSXInit(
    void)
{
    if ([NSApp macOSVersion] < 101400) {
	entryElementPadding = Ttk_MakePadding(7, 6, 7, 5);
    } else {
	entryElementPadding = Ttk_MakePadding(7, 5, 7, 6);
    }
    if ([NSApp macOSVersion] < 110000) {
	Ttk_ContrastDelta = 8.0;
    } else {

	/*
	 * The subtle contrast became event more subtle in 11.0.
	 */

	Ttk_ContrastDelta = 5.0;
    }
}

static int AquaTheme_Init(
static int AquaTheme_Init(Tcl_Interp *interp)
    Tcl_Interp *interp)
{
    Ttk_Theme themePtr = Ttk_CreateTheme(interp, "aqua", NULL);

    if (!themePtr) {
	return TCL_ERROR;
    }

    /*
     * Elements:
     */

    Ttk_RegisterElementSpec(themePtr, "background", &BackgroundElementSpec,
    Ttk_RegisterElementSpec(themePtr, "background", &BackgroundElementSpec, 0);
	0);
    Ttk_RegisterElementSpec(themePtr, "fill", &FillElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "field", &FieldElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Toolbar.background",
	&ToolbarBackgroundElementSpec, 0);

    Ttk_RegisterElementSpec(themePtr, "Button.button",
	&ButtonElementSpec, &PushButtonParams);
    Ttk_RegisterElementSpec(themePtr, "InlineButton.button",
	&ButtonElementSpec, &InlineButtonParams);
    Ttk_RegisterElementSpec(themePtr, "RoundedRectButton.button",
	&ButtonElementSpec, &RoundedRectButtonParams);
    Ttk_RegisterElementSpec(themePtr, "Checkbutton.button",
	&ButtonElementSpec, &CheckBoxParams);
    Ttk_RegisterElementSpec(themePtr, "Radiobutton.button",
	&ButtonElementSpec, &RadioButtonParams);
    Ttk_RegisterElementSpec(themePtr, "RecessedButton.button",
	&ButtonElementSpec, &RecessedButtonParams);
    Ttk_RegisterElementSpec(themePtr, "SidebarButton.button",
	&ButtonElementSpec, &SidebarButtonParams);
    Ttk_RegisterElementSpec(themePtr, "Toolbutton.border",
	&ButtonElementSpec, &BevelButtonParams);
    Ttk_RegisterElementSpec(themePtr, "Menubutton.button",
	&ButtonElementSpec, &PopupButtonParams);
    Ttk_RegisterElementSpec(themePtr, "DisclosureButton.button",
	&ButtonElementSpec, &DisclosureButtonParams);
    Ttk_RegisterElementSpec(themePtr, "HelpButton.button",
	&ButtonElementSpec, &HelpButtonParams);
    Ttk_RegisterElementSpec(themePtr, "Spinbox.spinbutton",
    	&SpinButtonElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "GradientButton.button",
	&ButtonElementSpec, &GradientButtonParams);
    Ttk_RegisterElementSpec(themePtr, "Spinbox.uparrow",
	&SpinButtonUpElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Spinbox.downarrow",
	&SpinButtonDownElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Combobox.button",
	&ComboboxElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Treeitem.indicator",
	&DisclosureElementSpec, &DisclosureParams);
    Ttk_RegisterElementSpec(themePtr, "Treeheading.cell",
	&TreeHeaderElementSpec, &ListHeaderParams);

    Ttk_RegisterElementSpec(themePtr, "Treeview.treearea",
	&TreeAreaElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Notebook.tab", &TabElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Notebook.client", &PaneElementSpec, 0);

    Ttk_RegisterElementSpec(themePtr, "Labelframe.border", &GroupElementSpec,
    Ttk_RegisterElementSpec(themePtr, "Labelframe.border",&GroupElementSpec,0);
	0);
    Ttk_RegisterElementSpec(themePtr, "Entry.field", &EntryElementSpec,
    Ttk_RegisterElementSpec(themePtr, "Entry.field",&EntryElementSpec,0);
			    &EntryFieldParams);
    Ttk_RegisterElementSpec(themePtr, "Searchbox.field", &EntryElementSpec,
			    &SearchboxFieldParams);
    Ttk_RegisterElementSpec(themePtr, "Spinbox.field", &EntryElementSpec,
    Ttk_RegisterElementSpec(themePtr, "Spinbox.field",&EntryElementSpec,0);
			    &EntryFieldParams);

    Ttk_RegisterElementSpec(themePtr, "separator", &SeparatorElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "hseparator", &SeparatorElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "vseparator", &SeparatorElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "separator",&SeparatorElementSpec,0);
    Ttk_RegisterElementSpec(themePtr, "hseparator",&SeparatorElementSpec,0);
    Ttk_RegisterElementSpec(themePtr, "vseparator",&SeparatorElementSpec,0);

    Ttk_RegisterElementSpec(themePtr, "sizegrip", &SizegripElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "sizegrip",&SizegripElementSpec,0);

    /*
     * <<NOTE-TRACKS>>
     * In some themes the Layouts for a progress bar has a trough element and a
     * pbar element.  But in our case the appearance manager draws both parts
     * of the progress bar, so we just have a single element called ".track".
     */

     * The Progressbar widget adjusts the size of the pbar element.
    Ttk_RegisterElementSpec(themePtr, "Progressbar.track", &PbarElementSpec,
	0);

     * In the Aqua theme, the appearance manager computes the bar geometry;
    Ttk_RegisterElementSpec(themePtr, "Scale.trough", &TrackElementSpec,
	&ScaleData);
    Ttk_RegisterElementSpec(themePtr, "Scale.slider", &SliderElementSpec, 0);

     * we do all the drawing in the ".track" element and leave the .pbar out.
    Ttk_RegisterElementSpec(themePtr, "Vertical.Scrollbar.trough",
	&TroughElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Vertical.Scrollbar.thumb",
	&ThumbElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Horizontal.Scrollbar.trough",
	&TroughElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Horizontal.Scrollbar.thumb",
	&ThumbElementSpec, 0);

    /*
     * If we are not in Snow Leopard or Lion the arrows won't actually be
     * displayed.
     */

    Ttk_RegisterElementSpec(themePtr, "Vertical.Scrollbar.uparrow",
	&ArrowElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Vertical.Scrollbar.downarrow",
    Ttk_RegisterElementSpec(themePtr,"Scale.trough",
	&TrackElementSpec, &ScaleData);
    Ttk_RegisterElementSpec(themePtr,"Scale.slider",&SliderElementSpec,0);
	&ArrowElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Horizontal.Scrollbar.leftarrow",
    Ttk_RegisterElementSpec(themePtr,"Progressbar.track", &PbarElementSpec, 0);
	&ArrowElementSpec, 0);
    Ttk_RegisterElementSpec(themePtr, "Horizontal.Scrollbar.rightarrow",
	&ArrowElementSpec, 0);

    /*
     * Layouts:
     */

    Ttk_RegisterLayouts(themePtr, LayoutTable);

    Tcl_PkgProvide(interp, "ttk::theme::aqua", TTK_VERSION);
    return TCL_OK;
}

MODULE_SCOPE
int Ttk_MacOSXPlatformInit(
int Ttk_MacOSXPlatformInit(Tcl_Interp *interp)
    Tcl_Interp *interp)
{
    return AquaTheme_Init(interp);
}


/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Deleted macosx/ttkMacOSXTheme.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585









































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * ttkMacOSXTheme.h --
 *
 *      Static data and macros used in ttkMacOSXTheme.c
 *
 * Copyright 2019 Marc Culler
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Macros for handling drawing contexts.
 */

#define BEGIN_DRAWING(d) {				    \
    TkMacOSXDrawingContext dc;				    \
    if (!TkMacOSXSetupDrawingContext((d), NULL, &dc)) {	    \
	return;						    \
    }							    \

#define END_DRAWING				\
    TkMacOSXRestoreDrawingContext(&dc);}


#define HIOrientation kHIThemeOrientationNormal
#define NoThemeMetric 0xFFFFFFFF

/*
 *  A scale factor used to map a range of non-negative doubles into a large
 *  range of non-negative 32-bit integers without losing too much information.
 *  (Use 1073741824 == 2^30 so we don't get surprised by roundoff.)
 */

#define RangeToFactor(max) ((double) (1073741824.0) / (max < 1.0 ? 1.0 : max))

/*
 * Meanings of Ttk states represented by User1 and User2.
 */

#define TTK_STATE_FIRST_TAB     TTK_STATE_USER1
#define TTK_STATE_LAST_TAB      TTK_STATE_USER2
#define TTK_STATE_IS_ACCENTED   TTK_STATE_USER2
#define TTK_TREEVIEW_STATE_SORTARROW    TTK_STATE_USER1

/*
 * Colors and gradients used when drawing buttons.
 */

typedef struct GrayColor {
    CGFloat grayscale;
    CGFloat alpha;
} GrayColor;

#define RGBACOLOR static CGFloat
#define RGBA256(r, g, b, a) {r / 255.0, g / 255.0, b / 255.0, a}
#define GRAYCOLOR static GrayColor
#define GRAY256(grayscale) {grayscale / 255.0, 1.0}

/*
 * Opaque Grays used for Gradient Buttons, Scrollbars and List Headers
 */

GRAYCOLOR darkDisabledIndicator = GRAY256(122.0);
GRAYCOLOR lightDisabledIndicator = GRAY256(152.0);

GRAYCOLOR darkGradientNormal = GRAY256(95.0);
GRAYCOLOR darkGradientPressed = GRAY256(118.0);
GRAYCOLOR darkGradientDisabled = GRAY256(82.0);
GRAYCOLOR darkGradientBorder = GRAY256(118.0);
GRAYCOLOR darkGradientBorderDisabled = GRAY256(94.0);
GRAYCOLOR lightGradientNormal = GRAY256(244.0);
GRAYCOLOR lightGradientPressed = GRAY256(175.0);
GRAYCOLOR lightGradientDisabled = GRAY256(235.0);
GRAYCOLOR lightGradientBorder = GRAY256(165.0);
GRAYCOLOR lightGradientBorderDisabled = GRAY256(204.0);

GRAYCOLOR lightTrough = GRAY256(250.0);
GRAYCOLOR darkTrough = GRAY256(47.0);
GRAYCOLOR lightInactiveThumb = GRAY256(200.0);
GRAYCOLOR lightActiveThumb = GRAY256(133.0);
GRAYCOLOR darkInactiveThumb = GRAY256(117.0);
GRAYCOLOR darkActiveThumb = GRAY256(158.0);

GRAYCOLOR lightListheaderBorder = GRAY256(200.0);
GRAYCOLOR listheaderSeparator = GRAY256(220.0);
GRAYCOLOR listheaderActiveBG = GRAY256(238.0);
GRAYCOLOR listheaderInactiveBG = GRAY256(246.0);

GRAYCOLOR lightComboSeparator = GRAY256(236.0);
GRAYCOLOR darkComboSeparator = GRAY256(66.0);

GRAYCOLOR darkTrack = GRAY256(84.0);
GRAYCOLOR darkInactiveTrack = GRAY256(107.0);
GRAYCOLOR lightTrack = GRAY256(177.0);
GRAYCOLOR lightInactiveTrack = GRAY256(139.0);

/*
 * Transparent Grays
 */

GRAYCOLOR boxBorder = {1.0, 0.20};
GRAYCOLOR darkSeparator = {1.0, 0.3};
GRAYCOLOR darkTabSeparator = {0.0, 0.25};
GRAYCOLOR darkListheaderBorder = {1.0, 0.125};
GRAYCOLOR pressedDefaultButton = {0.0, 0.1};
GRAYCOLOR darkPressedDefaultButton = {1.0, 0.1};

#define CG_WHITE CGColorGetConstantColor(kCGColorWhite)


/*
 * Structures which comprise a database of corner radii and state-dependent
 * colors used when drawing various types of buttons or entry widgets.
 */

typedef struct GrayPalette {
    CGFloat face;
    CGFloat top;
    CGFloat side;
    CGFloat bottom;
} GrayPalette;

typedef struct PaletteStateTable {
    GrayPalette light;          /* Light palette to use if this entry matches */
    GrayPalette dark;           /* dark palette to use if this entry matches */
    unsigned int onBits;        /* Bits which must be set */
    unsigned int offBits;       /* Bits which must be cleared */
} PaletteStateTable;

typedef struct ButtonDesign {
    CGFloat radius;
    PaletteStateTable palettes[];
} ButtonDesign;

/*
 * The data.
 */

static const ButtonDesign pushbuttonDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 213.0, .side = 210.0, .bottom = 200.0},
      .dark =  {.face = 94.0,  .top = 98.0,  .side = 94.0,  .bottom = 58.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0},
    {
      .light = {.face = 205.0, .top = 215.0, .side = 211.0, .bottom = 173.0},
      .dark =  {.face = 140.0, .top = 150.0, .side = 140.0, .bottom = 42.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 198.0, .side = 192.0, .bottom = 173.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign helpDesign = {
  .radius = 11,
  .palettes = {
    {
      .light = {.face = 241.0, .top = 218.0, .side = 217.0, .bottom = 206.0},
      .dark =  {.face = 83.0,  .top = 89.0,  .side = 82.0,  .bottom = 82.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0},
    {
      .light = {.face = 240.0, .top = 208.0, .side = 205.0, .bottom = 188.0},
      .dark =  {.face = 129.0, .top = 121.0, .side = 106.0, .bottom = 106.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 208.0, .side = 205.0, .bottom = 188.0},
      .dark =  {.face = 107.0, .top = 121.0, .side = 106.0, .bottom = 106.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign inlineDesign = {
  .radius = 8.0,
  .palettes = {
    {
      .light = {.face = 170.0, .top = 170.0, .side = 170.0, .bottom = 170.0},
      .dark =  {.face = 106.0,  .top = 106.0,  .side = 106.0,  .bottom = 106.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0},
    {
      .light = {.face = 34.0, .top = 34.0, .side = 34.0, .bottom = 34.0},
      .dark =  {.face = 225.0, .top = 225.0, .side = 225.0, .bottom = 225.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 113.0, .top = 113.0, .side = 113.0, .bottom = 113.0},
      .dark =  {.face = 165.0, .top = 165.0, .side = 165.0, .bottom = 165.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign roundedrectDesign = {
  .radius = 3.0,
  .palettes = {
    {
      .light = {.face = 256.0, .top = 192.0, .side = 192.0, .bottom = 192.0},
      .dark =  {.face = 256.0, .top = 165.0, .side = 163.0, .bottom = 42.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 204.0, .top = 158.0, .side = 158.0, .bottom = 158.0},
      .dark =  {.face = 85.0,  .top = 115.0, .side = 115.0, .bottom = 115.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 205.0, .top = 215.0, .side = 211.0, .bottom = 173.0},
      .dark =  {.face = 140.0, .top = 150.0, .side = 140.0, .bottom = 42.0},
      .onBits = TTK_STATE_ALTERNATE, .offBits = TTK_STATE_BACKGROUND
    },

    /*
     * Gray values > 255 are replaced by the background color.
     */

    {
      .light = {.face = 256.0, .top = 158.0, .side = 158.0, .bottom = 158.0},
      .dark =  {.face = 256.0, .top = 115.0, .side = 115.0, .bottom = 115.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign popupDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 213.0, .side = 210.0, .bottom = 200.0},
      .dark =  {.face = 94.0,  .top = 98.0,  .side = 94.0,  .bottom = 58.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 198.0, .side = 192.0, .bottom = 173.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign checkDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 192.0, .side = 199.0, .bottom = 199.0},
      .dark =  {.face = 80.0,  .top = 90.0,  .side = 80.0,  .bottom = 49.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 165.0, .side = 184.0, .bottom = 184.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign radioDesign = {
  .radius = 8.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 189.0, .side = 198.0, .bottom = 199.0},
      .dark =  {.face = 80.0,  .top = 84.0,  .side = 88.0,  .bottom = 60.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 165.0, .side = 184.0, .bottom = 184.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign recessedDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 117.0, .top = 117.0, .side = 117.0, .bottom = 117.0},
      .dark =  {.face = 129.0, .top = 129.0, .side = 129.0, .bottom = 129.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 182.0, .top = 182.0, .side = 182.0, .bottom = 182.0},
      .dark =  {.face = 105.0,  .top = 105.0, .side = 105.0, .bottom = 105.0},
      .onBits = TTK_STATE_ACTIVE, .offBits = TTK_STATE_SELECTED
    },
    {
      .light = {.face = 145.0, .top = 145.0, .side = 145.0, .bottom = 145.0},
      .dark =  {.face = 166.0, .top = 166.0, .side = 166.0, .bottom = 166.0},
      .onBits = TTK_STATE_SELECTED, .offBits = 0
    },
    {
      .light = {.face = 256.0, .top = 256.0, .side = 256.0, .bottom = 256.0},
      .dark =  {.face = 256.0, .top = 256.0, .side = 256.0, .bottom = 256.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign sidebarDesign = {
  .radius = 8.0,
  .palettes = {
    {
      .light = {.face = 210.0, .top = 210.0, .side = 210.0, .bottom = 210.0},
      .dark =  {.face = 129.0, .top = 129.0, .side = 129.0, .bottom = 129.0},
      .onBits = TTK_STATE_SELECTED, .offBits = 0
    },
    {
      .light = {.face = 210.0, .top = 210.0, .side = 210.0, .bottom = 210.0},
      .dark =  {.face = 129.0, .top = 129.0, .side = 129.0, .bottom = 129.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 256.0, .top = 256.0, .side = 256.0, .bottom = 256.0},
      .dark =  {.face = 256.0, .top = 256.0, .side = 256.0, .bottom = 256.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign incdecDesign = {
  .radius = 5.0,
  .palettes = {
    {
      .light = {.face = 246.0, .top = 236.0, .side = 227.0, .bottom = 213.0},
      .dark =  {.face = 80.0,  .top = 90.0,  .side = 80.0,  .bottom = 49.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 198.0, .side = 192.0, .bottom = 173.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign bevelDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 213.0, .side = 210.0, .bottom = 200.0},
      .dark =  {.face = 94.0,  .top = 98.0,  .side = 94.0,  .bottom = 58.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 205.0, .top = 215.0, .side = 211.0, .bottom = 173.0},
      .dark =  {.face = 140.0, .top = 150.0, .side = 140.0, .bottom = 42.0},
      .onBits = TTK_STATE_PRESSED, .offBits = 0
    },
    {
      .light = {.face = 228.0, .top = 215.0, .side = 211.0, .bottom = 173.0},
      .dark =  {.face = 163.0, .top = 150.0, .side = 140.0, .bottom = 42.0},
      .onBits = TTK_STATE_SELECTED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 198.0, .side = 192.0, .bottom = 173.0},
      .dark =  {.face = 118.0, .top = 132.0, .side = 118.0, .bottom = 48.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign tabDesign = {
  .radius = 4.0,
  .palettes = {

    /*
     * Apple does not have such a thing as a disabled tab.  If it is
     * disabled, it should be removed.  But we provide one based on the
     * disabled button.
     */

    {
      .light = {.face = 229.0, .top = 213.0, .side = 242.0, .bottom = 200.0},
      .dark =  {.face = 163.0,  .top = 90.0,  .side = 80.0,  .bottom = 49.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 229.0, .top = 205.0, .side = 211.0, .bottom = 183.0},
      .dark =  {.face = 163.0, .top = 165.0, .side = 163.0, .bottom = 42.0},
      .onBits = TTK_STATE_SELECTED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 215.0, .side = 211.0, .bottom = 183.0},
      .dark =  {.face = 108.0, .top = 129.0, .side = 108.0, .bottom = 47.0},
      .onBits = 0, .offBits = 0
    },
  }
};

static const ButtonDesign entryDesign = {
  .radius = 0.0,
  .palettes = {
    {
      .light = {.face = 256.0, .top = 198.0, .side = 198.0, .bottom = 198.0},
      .dark =  {.face = 256.0,  .top = 66.0,  .side = 66.0,  .bottom = 84.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign searchDesign = {
  .radius = 3.5,
  .palettes = {
    {
      .light = {.face = 256.0, .top = 198.0, .side = 198.0, .bottom = 198.0},
      .dark =  {.face = 256.0,  .top = 66.0,  .side = 66.0,  .bottom = 84.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign comboDesign = {
  .radius = 4.0,
  .palettes = {
    {
      .light = {.face = 256.0, .top = 190.0, .side = 190.0, .bottom = 190.0},
      .dark =  {.face = 256.0,  .top = 66.0,  .side = 66.0,  .bottom = 90.0},
      .onBits = 0, .offBits = 0
    }
  }
};

static const ButtonDesign sliderDesign = {
  .radius = 8.0,
  .palettes = {
    {
      .light = {.face = 242.0, .top = 189.0, .side = 198.0, .bottom = 199.0},
      .dark =  {.face = 80.0,  .top = 84.0,  .side = 88.0,  .bottom = 60.0},
      .onBits = TTK_STATE_DISABLED, .offBits = 0
    },
    {
      .light = {.face = 255.0, .top = 165.0, .side = 184.0, .bottom = 184.0},
      .dark =  {.face = 205.0, .top = 205.0, .side = 205.0, .bottom = 198.0},
      .onBits = 0, .offBits = 0
    }
  }
};


/*
 * Table mapping Tk states to Appearance manager ThemeStates
 */

static const Ttk_StateTable ThemeStateTable[] = {
    {kThemeStateActive, TTK_STATE_ALTERNATE | TTK_STATE_BACKGROUND, 0},
    {kThemeStateUnavailable, TTK_STATE_DISABLED, 0},
    {kThemeStatePressed, TTK_STATE_PRESSED, 0},
    {kThemeStateInactive, TTK_STATE_BACKGROUND, 0},
    {kThemeStateUnavailableInactive, TTK_STATE_DISABLED | TTK_STATE_BACKGROUND, 0},
    {kThemeStateActive, 0, 0}

    /* Others:
     * The kThemeStatePressedUp and kThemeStatePressedDown bits indicate
     * which of the two segments of an IncDec button is being pressed.
     * We don't use these. kThemeStateRollover roughly corresponds to
     * TTK_STATE_ACTIVE, but does not do what we want with the help button.
     *
     * {kThemeStatePressedUp, 0, 0},
     * {kThemeStatePressedDown, 0, 0}
     * {kThemeStateRollover, TTK_STATE_ACTIVE, 0},
     */
};

/*
 * Translation between Ttk and HIToolbox.
 */

static const Ttk_StateTable ButtonValueTable[] = {
    {kThemeButtonOff, TTK_STATE_ALTERNATE | TTK_STATE_BACKGROUND, 0},
    {kThemeButtonMixed, TTK_STATE_ALTERNATE, 0},
    {kThemeButtonOn, TTK_STATE_SELECTED, 0},
    {kThemeButtonOff, 0, 0}
};

static const Ttk_StateTable ButtonAdornmentTable[] = {
    {kThemeAdornmentNone, TTK_STATE_ALTERNATE | TTK_STATE_BACKGROUND, 0},
    {kThemeAdornmentDefault | kThemeAdornmentFocus,
     TTK_STATE_ALTERNATE | TTK_STATE_FOCUS, 0},
    {kThemeAdornmentFocus, TTK_STATE_FOCUS, 0},
    {kThemeAdornmentDefault, TTK_STATE_ALTERNATE, 0},
    {kThemeAdornmentNone, 0, 0}
};

/*
 * Our enums for button styles not known to HIToolbox.
 */

#define TkGradientButton    0x8001
#define TkRoundedRectButton 0x8002
#define TkRecessedButton    0x8003
#define TkInlineButton      0x8004
#define TkSidebarButton     0x8005
/*
 * The struct passed as clientData when drawing Ttk buttons.
 */

typedef struct {
    ThemeButtonKind kind;
    ThemeMetric heightMetric;
    ThemeMetric widthMetric;
} ThemeButtonParams;

static ThemeButtonParams
    PushButtonParams =  {kThemePushButton, kThemeMetricPushButtonHeight,
			 NoThemeMetric},
    CheckBoxParams =    {kThemeCheckBox, kThemeMetricCheckBoxHeight,
			 NoThemeMetric},
    RadioButtonParams = {kThemeRadioButton, kThemeMetricRadioButtonHeight,
			 NoThemeMetric},
    BevelButtonParams = {kThemeRoundedBevelButton, NoThemeMetric, NoThemeMetric},
    PopupButtonParams = {kThemePopupButton, kThemeMetricPopupButtonHeight,
			 NoThemeMetric},
    DisclosureParams =  {kThemeDisclosureButton,
			 kThemeMetricDisclosureTriangleHeight,
			 kThemeMetricDisclosureTriangleWidth},
    DisclosureButtonParams = {kThemeArrowButton,
			      kThemeMetricSmallDisclosureButtonHeight,
			      kThemeMetricSmallDisclosureButtonWidth},
    HelpButtonParams = {kThemeRoundButtonHelp, kThemeMetricRoundButtonSize,
			kThemeMetricRoundButtonSize},
    ListHeaderParams = {kThemeListHeaderButton, kThemeMetricListHeaderHeight,
			NoThemeMetric},
    GradientButtonParams = {TkGradientButton, NoThemeMetric, NoThemeMetric},
    RoundedRectButtonParams = {TkRoundedRectButton, kThemeMetricPushButtonHeight,
			       NoThemeMetric},
    RecessedButtonParams = {TkRecessedButton, kThemeMetricPushButtonHeight,
 			    NoThemeMetric},
    SidebarButtonParams = {TkSidebarButton, NoThemeMetric, NoThemeMetric},
    InlineButtonParams = {TkInlineButton,  kThemeMetricPushButtonHeight, NoThemeMetric};

    /*
     * Others: kThemeDisclosureRight, kThemeDisclosureDown,
     * kThemeDisclosureLeft
     */

/*
 *  The struct passed as clientData when drawing Ttk Entry widgets.
 */

typedef struct {
    HIThemeFrameKind kind;
    ThemeMetric heightMetric;
    ThemeMetric widthMetric;
} ThemeFrameParams;

static ThemeFrameParams
    EntryFieldParams = {kHIThemeFrameTextFieldSquare, NoThemeMetric, NoThemeMetric},
    SearchboxFieldParams = {kHIThemeFrameTextFieldRound, NoThemeMetric, NoThemeMetric};

/*
 * If we try to draw a rounded rectangle with too large of a radius, the Core
 * Graphics library will sometimes raise a fatal exception.  This macro
 * protects against this by returning if the width or height is less than
 * twice the radius.  Presumably this only happens when a widget has not yet
 * been configured and has size 1x1, so there is nothing to draw anyway.
 */

#define CHECK_RADIUS(radius, bounds)                                                 \
    if ((radius) > (bounds).size.width / 2 || (radius) > (bounds).size.height / 2) { \
        return;                                                                      \
    }

/*
 * The spinbox widget needs to draw the two arrows in different colors when
 * one half or the other is being pressed, but the menubutton always draws
 * them in the same color.  This constant is used to distinguish those two
 * situations.
 */

#define BOTH_ARROWS 1 << 30

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to tests/all.tcl.

1
2
3
4
5
6
7

8
9
10
11
12

13
14
15
16
17

18
19
20
21

1
2
3
4
5
6

7
8
9
10
11

12
13
14
15
16

17
18



19






-
+




-
+




-
+

-
-
-
+
# all.tcl --
#
# This file contains a top-level script to run all of the Tk
# tests.  Execute it by invoking "source all.tcl" when running tktest
# in this directory.
#
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require Tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [tcltest::testsDirectory] constraints.tcl]
	[file join [tcltest::testsDirectory] constraints.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}
tcltest::runAllTests

Changes to tests/arc.tcl.

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65

66
67

68
69
70
71
72
73
74
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64

65
66

67
68
69
70
71
72
73
74







-
+









-
+

-
+







.t.c create arc 340 450 460 570 -start 320 -extent 270 -fill $fill1 -width 14 \
	-style chord -outline {}
.t.c create arc 500 450 620 570 -start 350 -extent -110 -fill $fill1 -width 14 \
	-style chord -outline {}
.t.c addtag arc withtag all
.t.c addtag circle withtag [.t.c create oval 320 200 340 220 -fill MistyRose3]

.t.c bind arc <Enter> {
.t.c bind arc <Any-Enter> {
    set prevFill [lindex [.t.c itemconf current -fill] 4]
    set prevOutline [lindex [.t.c itemconf current -outline] 4]
    if {($prevFill != "") || ($prevOutline == "")} {
	.t.c itemconf current -fill $fill3
    }
    if {$prevOutline != ""} {
	.t.c itemconf current -outline $outline2
    }
}
.t.c bind arc <Leave> {.t.c itemconf current -fill $prevFill -outline $prevOutline}
.t.c bind arc <Any-Leave> {.t.c itemconf current -fill $prevFill -outline $prevOutline}

bind .t.c <Button-1> {markarea %x %y}
bind .t.c <1> {markarea %x %y}
bind .t.c <B1-Motion> {strokearea %x %y}

proc markarea {x y} {
    global areaX1 areaY1
    set areaX1 $x
    set areaY1 $y
}
85
86
87
88
89
90
91
92

93
94
95
96

97
98
99
100
101
102

103
104
105
106
107
108
109
85
86
87
88
89
90
91

92
93
94
95

96
97
98
99
100
101

102
103
104
105
106
107
108
109







-
+



-
+





-
+







}

bind .t.c <Control-f> {
    puts stdout "Enclosed: [.t.c find enclosed $areaX1 $areaY1 $areaX2 $areaY2]"
    puts stdout "Overlapping: [.t.c find overl $areaX1 $areaY1 $areaX2 $areaY2]"
}

bind .t.c <Button-3> {puts stdout "%x %y"}
bind .t.c <3> {puts stdout "%x %y"}

# The code below allows the circle to be move by shift-dragging.

bind .t.c <Shift-Button-1> {
bind .t.c <Shift-1> {
    set curx %x
    set cury %y
}

bind .t.c <Shift-B1-Motion> {
    .t.c move circle [expr {%x-$curx}] [expr {%y-$cury}]
    .t.c move circle [expr %x-$curx] [expr %y-$cury]
    set curx %x
    set cury %y
}

# The binding below flashes the closest item to the mouse.

bind .t.c <Control-c> {
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







	    set delta -5
	}
	if {$i <= 5} {
	    set delta 5
	}
	incr i $delta
	c -start $i
	c -extent [expr {360-2*$i}]
	c -extent [expr 360-2*$i]
	after 20
	update
    }
}

bind .t.c b {set go 0}

Changes to tests/bell.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test out Tk's "bell" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1998-2000 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1998-2000 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38







-
+








test bell-1.4 {bell command} -body {
    bell -nice -displayof
} -returnCodes {error} -result {wrong # args: should be "bell ?-displayof window? ?-nice?"}

test bell-1.5 {bell command} -body {
    bell -nice -nice -nice
} -returnCodes {ok} -result {}  ;#keep -result {} and -returnCodes {ok} for clarity?
} -returnCodes {ok} -result {}  ;#keep -result {} and -retutnCodes {ok} for clarity?

test bell-1.6 {bell command} -body {
    bell -displayof . -nice
} -returnCodes {ok} -result {}

test bell-1.7 {bell command} -body {
    bell -nice -displayof . -nice

Changes to tests/bgerror.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test the bgerror command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Changes to tests/bind.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
1
2
3
4



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50




-
-
-
+
+
+

















-
+

















-
+







# This file is a Tcl script to test out Tk's "bind" and "bindtags"
# commands plus the procedures in tkBind.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
tk useinputmethods 0

toplevel .t -width 100 -height 50
wm geom .t +0+0
update idletasks

foreach p [event info] {event delete $p}
foreach event [bind Test] {
    bind Test $event {}
}
foreach event [bind all] {
    bind all $event {}
   bind all $event {}
}

proc unsetBindings {} {
    bind all <Enter> {}
    bind Test <Enter> {}
    bind Toplevel <Enter> {}
    bind xyz <Enter> {}
    bind {a b} <Enter> {}
    bind .t <Enter> {}
}

# move the mouse pointer away of the testing area
# otherwise some spurious events may pollute the tests
toplevel .top
wm geometry .top 50x50-50-50
update
event generate .top <Button-1> -warp 1
controlPointerWarpTiming
update
destroy .top

test bind-1.1 {bind command} -body {
    bind
} -returnCodes error -result {wrong # args: should be "bind window ?pattern? ?command?"}
test bind-1.2 {bind command} -body {
    bind a b c d
293
294
295
296
297
298
299
300

301
302

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317



318
319
320
321
322
323
324
325


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349


350
351
352
353
354
355
356
357
358
359
360


361
362
363
364



365
366
367
368
369
370
371
293
294
295
296
297
298
299

300
301

302
303
304
305
306
307
308
309
310
311
312
313
314



315
316
317
318
319
320
321
322
323


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

345
346
347


348
349
350
351
352
353
354
355
356
357
358


359
360
361



362
363
364
365
366
367
368
369
370
371







-
+

-
+












-
-
-
+
+
+






-
-
+
+



















-
+


-
-
+
+









-
-
+
+

-
-
-
+
+
+







} -cleanup {
    destroy .t.c
} -result {}


test bind-6.1 {Tk_DeleteBindTable procedure} -body {
    canvas .t.c
    .t.c bind foo <Button-1> {string 1}
    .t.c bind foo <1> {string 1}
    .t.c create rectangle 0 0 100 100
    .t.c bind 1 <Button-2> {string 2}
    .t.c bind 1 <2> {string 2}
    destroy .t.c
} -cleanup {
    destroy .t.c
} -result {}
test bind-7.1 {Tk_CreateBinding procedure: bad binding} -body {
    canvas .t.c
    .t.c bind foo <
} -cleanup {
    destroy .t.c
} -returnCodes error -result {no event type or button # or keysym}
test bind-7.3 {Tk_CreateBinding procedure: append} -body {
    canvas .t.c
    .t.c bind foo <Button-1> "button 1"
    .t.c bind foo <Button-1> "+more button 1"
    .t.c bind foo <Button-1>
    .t.c bind foo <1> "button 1"
    .t.c bind foo <1> "+more button 1"
    .t.c bind foo <1>
} -cleanup {
    destroy .t.c
} -result {button 1
more button 1}
test bind-7.4 {Tk_CreateBinding procedure: append to non-existing} -body {
    canvas .t.c
    .t.c bind foo <Button-1> "+button 1"
    .t.c bind foo <Button-1>
    .t.c bind foo <1> "+button 1"
    .t.c bind foo <1>
} -cleanup {
    destroy .t.c
} -result {button 1}

test bind-8.1 {Tk_CreateBinding: error} -body {
    bind . <xyz> "xyz"
} -returnCodes error -result {bad event type or keysym "xyz"}

test bind-9.1 {Tk_DeleteBinding procedure} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <
} -cleanup {
    destroy .t.f
} -returnCodes ok
test bind-9.2 {Tk_DeleteBinding procedure} -setup {
    set result {}
} -body {
    frame .t.f -class Test -width 150 -height 100
    foreach i {a b c d} {
        bind .t.f $i "binding for $i"
	   bind .t.f $i "binding for $i"
    }
    foreach i {b d a c} {
        bind .t.f $i {}
        lappend result [lsort [bind .t.f]]
	   bind .t.f $i {}
	   lappend result [lsort [bind .t.f]]
    }
    return $result
} -cleanup {
    destroy .t.f
} -result {{a c d} {a c} c {}}
test bind-9.3 {Tk_DeleteBinding procedure} -setup {
    set result {}
} -body {
    frame .t.f -class Test -width 150 -height 100
    foreach i {<Button-1> <Meta-Button-1> <Control-Button-1> <Double-Alt-Button-1>} {
        bind .t.f $i "binding for $i"
    foreach i {<1> <Meta-1> <Control-1> <Double-Alt-1>} {
	   bind .t.f $i "binding for $i"
    }
    foreach i {<Control-Button-1> <Double-Alt-Button-1> <Button-1> <Meta-Button-1>} {
        bind .t.f $i {}
        lappend result [lsort [bind .t.f]]
    foreach i {<Control-1> <Double-Alt-1> <1> <Meta-1>} {
	   bind .t.f $i {}
	   lappend result [lsort [bind .t.f]]
    }
    return $result
} -cleanup {
    destroy .t.f
} -result {{<Button-1> <Double-Alt-Button-1> <Meta-Button-1>} {<Button-1> <Meta-Button-1>} <Meta-Button-1> {}}

test bind-10.1 {Tk_GetBinding procedure} -body {
380
381
382
383
384
385
386
387
388


389
390
391
392
393

394
395
396
397


398
399
400
401
402
403
404
405
406


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421


422
423
424
425
426
427
428
429
430
431
432
433
434


435
436
437
438
439
440
441



442
443
444
445
446


447
448
449

450
451
452
453
454
455
456
457
458
459


460
461
462

463
464
465
466
467
468



469
470
471
472
473
474
475
476
477
478

479
480

481
482
483
484
485

486
487

488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

510
511
512
513
514
515
516
380
381
382
383
384
385
386


387
388
389
390
391
392

393
394
395


396
397
398
399
400
401
402
403
404


405
406
407
408
409
410
411
412
413
414
415
416
417
418
419


420
421
422
423
424
425
426
427
428
429
430
431
432


433
434
435
436
437
438



439
440
441
442
443
444


445
446
447
448

449
450
451
452
453
454
455
456
457


458
459
460
461

462
463
464
465



466
467
468
469
470
471
472
473
474
475
476
477

478
479

480
481
482
483
484

485
486

487
488
489
490
491
492
493

494
495
496
497
498
499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516







-
-
+
+




-
+


-
-
+
+







-
-
+
+













-
-
+
+











-
-
+
+




-
-
-
+
+
+



-
-
+
+


-
+








-
-
+
+


-
+



-
-
-
+
+
+









-
+

-
+




-
+

-
+






-
+














-
+







    .t.c bind foo a
} -cleanup {
    destroy .t.c
} -result {Test}

test bind-11.1 {Tk_GetAllBindings procedure} -body {
    frame .t.f
    foreach i "! a \\\{ ~ <Delete> <space> <<Paste>> <Tab> <Linefeed> <Key-<> <Meta-a> <Â>" {
        bind .t.f $i Test
    foreach i "! a \\\{ ~ <Delete> <space> <<Paste>> <Tab> <Linefeed> <less> <Meta-a> <Acircumflex>" {
	   bind .t.f $i Test
    }
    lsort [bind .t.f]
} -cleanup {
    destroy .t.f
} -result "! <<Paste>> <Key-<> <Key-Delete> <Key-Linefeed> <Key-Tab> <Key-space> <Key-Â> <Meta-Key-a> a \\\{ ~"
} -result {! <<Paste>> <Key-Acircumflex> <Key-Delete> <Key-Linefeed> <Key-Tab> <Key-less> <Key-space> <Meta-Key-a> a \{ ~}
test bind-11.2 {Tk_GetAllBindings procedure} -body {
    frame .t.f
    foreach i "<Double-Button-1> <Triple-Button-1> <Meta-Control-a> <Double-Alt-Enter> <Button-1>" {
        bind .t.f $i Test
    foreach i "<Double-1> <Triple-1> <Meta-Control-a> <Double-Alt-Enter> <1>" {
	   bind .t.f $i Test
    }
    lsort [bind .t.f]
} -cleanup {
    destroy .t.f
} -result {<Button-1> <Control-Meta-Key-a> <Double-Alt-Enter> <Double-Button-1> <Triple-Button-1>}
test bind-11.3 {Tk_GetAllBindings procedure} -body {
    frame .t.f
    foreach i "<Double-Triple-Button-1> abcd a<Leave>b" {
        bind .t.f $i Test
    foreach i "<Double-Triple-1> abcd a<Leave>b" {
	   bind .t.f $i Test
    }
    lsort [bind .t.f]
} -cleanup {
    destroy .t.f
} -result {<Triple-Button-1> a<Leave>b abcd}


test bind-12.1 {Tk_DeleteAllBindings procedure} -body {
    frame .t.f -class Test -width 150 -height 100
    destroy .t.f
} -result {}
test bind-12.2 {Tk_DeleteAllBindings procedure} -body {
    frame .t.f -class Test -width 150 -height 100
    foreach i "a b c <Meta-Button-1> <Alt-a> <Control-a>" {
        bind .t.f $i x
    foreach i "a b c <Meta-1> <Alt-a> <Control-a>" {
	   bind .t.f $i x
    }
    destroy .t.f
} -result {}

test bind-13.1 {Tk_BindEvent procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind Test <Key> {lappend x "%W %K Test Key"}
    bind all <Key> {lappend x "%W %K all Key"}
    bind Test <KeyPress> {lappend x "%W %K Test KeyPress"}
    bind all <KeyPress> {lappend x "%W %K all KeyPress"}
    bind Test : {lappend x "%W %K Test :"}
    bind all  _ {lappend x "%W %K all _"}
    bind .t.f : {lappend x "%W %K .t.f :"}

    event generate .t.f <:>
    event generate .t.f <+>
    event generate .t.f <_>
    event generate .t.f <Key-colon>
    event generate .t.f <Key-plus>
    event generate .t.f <Key-underscore>
    return $x
} -cleanup {
    destroy .t.f
    bind all <Key> {}
    bind Test <Key> {}
    bind all <KeyPress> {}
    bind Test <KeyPress> {}
    bind all _ {}
    bind Test : {}
} -result {{.t.f : .t.f :} {.t.f : Test :} {.t.f : all Key} {.t.f + Test Key} {.t.f + all Key} {.t.f _ Test Key} {.t.f _ all _}}
} -result {{.t.f colon .t.f :} {.t.f colon Test :} {.t.f colon all KeyPress} {.t.f plus Test KeyPress} {.t.f plus all KeyPress} {.t.f underscore Test KeyPress} {.t.f underscore all _}}

test bind-13.2 {Tk_BindEvent procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind Test <Key> {lappend x "%W %K Test press any"; break}
    bind all <Key> {continue; lappend x "%W %K all press any"}
    bind Test <KeyPress> {lappend x "%W %K Test press any"; break}
    bind all <KeyPress> {continue; lappend x "%W %K all press any"}
    bind .t.f : {lappend x "%W %K .t.f pressed colon"}

    event generate .t.f <:>
    event generate .t.f <Key-colon>
    return $x
} -cleanup {
    destroy .t.f
    bind all <Key> {}
    bind Test <Key> {}
} -result {{.t.f : .t.f pressed colon} {.t.f : Test press any}}
    bind all <KeyPress> {}
    bind Test <KeyPress> {}
} -result {{.t.f colon .t.f pressed colon} {.t.f colon Test press any}}

test bind-13.3 {Tk_BindEvent procedure} -setup {
    proc bgerror args {}
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind Test <Key> {lappend x "%W %K Test press any"; error Test}
    bind Test <KeyPress> {lappend x "%W %K Test press any"; error Test}
    bind .t.f : {lappend x "%W %K .t.f pressed colon"}
    event generate .t.f <:>
    event generate .t.f <Key-colon>
    update
    list $x $errorInfo
} -cleanup {
    destroy .t.f
    bind Test <Key> {}
    bind Test <KeyPress> {}
    rename bgerror {}
}  -result {{{.t.f : .t.f pressed colon} {.t.f : Test press any}} {Test
}  -result {{{.t.f colon .t.f pressed colon} {.t.f colon Test press any}} {Test
    while executing
"error Test"
    (command bound to event)}}
test bind-13.4 {Tk_BindEvent procedure} -setup {
    proc foo {} {
        set x 44
        event generate .t.f <:>
        event generate .t.f <Key-colon>
    }
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind Test : {lappend x "%W %K Test"}
    bind .t.f : {lappend x "%W %K .t.f"}
    foo
    return $x
} -cleanup {
    destroy .t.f
    bind Test : {}
} -result {{.t.f : .t.f} {.t.f : Test}}
} -result {{.t.f colon .t.f} {.t.f colon Test}}

test bind-13.5 {Tk_BindEvent procedure} -body {
    bind all <Destroy> {lappend x "%W destroyed"}
    set x {}
    frame .t.g -gorp foo
} -cleanup {
    bind all <Destroy> {}
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570


571
572
573
574
575
576
577


578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
530
531
532
533
534
535
536

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568


569
570
571
572
573
574
575


576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600







-
+
















-
+














-
-
+
+





-
-
+
+















-
+







    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f : {lappend x "%W (.t.f binding)"}
    bind Test : {lappend x "%W (Test binding)"}
    bind all : {bind .t.f : {}; lappend x "%W (all binding)"}
    event generate .t.f <:>
    event generate .t.f <Key-colon>
    return $x
} -cleanup {
    bind Test : {}
    bind all : {}
    destroy .t.f
} -result {{.t.f (.t.f binding)} {.t.f (Test binding)} {.t.f (all binding)}}
test bind-13.8 {Tk_BindEvent procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f : {lappend x "%W (.t.f binding)"}
    bind Test : {lappend x "%W (Test binding)"}
    bind all : {destroy .t.f; lappend x "%W (all binding)"}
    event generate .t.f <:>
    event generate .t.f <Key-colon>
    return $x
} -cleanup {
    bind Test : {}
    bind all : {}
    destroy .t.f
} -result {{.t.f (.t.f binding)} {.t.f (Test binding)} {.t.f (all binding)}}

test bind-13.9 {Tk_BindEvent procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1> {lappend x "%W z (.t.f <Button-1> binding)"}
    bind .t.f <Button> {lappend x "%W z (.t.f <Button> binding)"}
    bind .t.f <1> {lappend x "%W z (.t.f <1> binding)"}
    bind .t.f <ButtonPress> {lappend x "%W z (.t.f <ButtonPress> binding)"}
    event generate .t.f <Button-1>
    event generate .t.f <Button-2>
    return $x
} -cleanup {
    destroy .t.f
} -result {{.t.f z (.t.f <Button-1> binding)} {.t.f z (.t.f <Button> binding)}}
test bind-13.10 {Tk_BindEvent procedure: don't ignore NotifyInferior - bug 47d4f29159} -setup {
} -result {{.t.f z (.t.f <1> binding)} {.t.f z (.t.f <ButtonPress> binding)}}
test bind-13.10 {Tk_BindEvent procedure: ignore NotifyInferior} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x Enter%#"
    bind .t.f <Leave> "lappend x Leave%#"
    event generate .t.f <Enter> -serial 100 -detail NotifyAncestor
    event generate .t.f <Enter> -serial 101 -detail NotifyInferior
    event generate .t.f <Leave> -serial 102 -detail NotifyAncestor
    event generate .t.f <Leave> -serial 103 -detail NotifyInferior
    return $x
} -cleanup {
    destroy .t.f
} -result {Enter100 Enter101 Leave102 Leave103}
} -result {Enter100 Leave102}
test bind-13.11 {Tk_BindEvent procedure: collapse Motions} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
612
613
614
615
616
617
618
619

620
621

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637


638
639
640
641

642
643
644
645
646
647
648
649
650
651
652


653
654
655
656
657
658
659
612
613
614
615
616
617
618

619
620

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635


636
637
638
639
640

641
642
643
644
645
646
647
648
649
650


651
652
653
654
655
656
657
658
659







-
+

-
+














-
-
+
+



-
+









-
-
+
+







    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> "lappend x %K%#"
    bind .t.f <KeyRelease> "lappend x %K%#"
    event generate .t.f <Shift_L> -serial 100 -when tail
    event generate .t.f <Key-Shift_L> -serial 100 -when tail
    event generate .t.f <KeyRelease-Shift_L> -serial 101 -when tail
    event generate .t.f <Shift_L> -serial 102 -when tail
    event generate .t.f <Key-Shift_L> -serial 102 -when tail
    event generate .t.f <KeyRelease-Shift_L> -serial 103 -when tail
    update
} -cleanup {
    destroy .t.f
} -result {}
test bind-13.13 {Tk_BindEvent procedure: valid key detail} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x Key%K"
    bind .t.f <KeyRelease> "lappend x Release%K"
    event generate .t.f <Key> -keysym :
    event generate .t.f <KeyRelease> -keysym :
    event generate .t.f <Key> -keysym colon
    event generate .t.f <KeyRelease> -keysym colon
    return $x
} -cleanup {
    destroy .t.f
} -result {Key: Release:}
} -result {Keycolon Releasecolon}
test bind-13.14 {Tk_BindEvent procedure: invalid key detail} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x Key%K"
    bind .t.f <KeyRelease> "lappend x Release%K"
    event generate .t.f <Key> -keycode -1
    event generate .t.f <KeyRelease> -keycode -1
    event generate .t.f <Key> -keycode 0
    event generate .t.f <KeyRelease> -keycode 0
    return $x
} -cleanup {
    destroy .t.f
} -result {Key?? Release??}
test bind-13.15 {Tk_BindEvent procedure: button detail} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
931
932
933
934
935
936
937
938
939


940
941

942
943
944

945
946
947
948
949
950
951
931
932
933
934
935
936
937


938
939
940

941
942
943

944
945
946
947
948
949
950
951







-
-
+
+

-
+


-
+







    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bindtags .t.f {a b c d e f g h i j k l m n o p}
    foreach p [bindtags .t.f] {
        bind $p <Button-1> "lappend x $p"
        foreach p [bindtags .t.f] {
        bind $p <1> "lappend x $p"
    }
    event generate .t.f <Button-1>
    event generate .t.f <1>
    return $x
} -cleanup {
    foreach p [bindtags .t.f] {bind $p <Button-1> {}}
    foreach p [bindtags .t.f] {bind $p <1> {}}
    destroy .t.f
} -result {a b c d e f g h i j k l m n o p}
test bind-13.34 {Tk_BindEvent procedure: multiple tags} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
962
963
964
965
966
967
968
969
970


971
972
973
974

975
976
977
978
979
980
981
982
983
984



985
986
987
988

989
990
991
992
993
994
995
962
963
964
965
966
967
968


969
970
971
972
973

974
975
976
977
978
979
980
981



982
983
984
985
986
987

988
989
990
991
992
993
994
995







-
-
+
+



-
+







-
-
-
+
+
+



-
+







test bind-13.35 {Tk_BindEvent procedure: execute binding} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1> {lappend x 1}
    event generate .t.f <Button-1>
    bind .t.f <1> {lappend x 1}
    event generate .t.f <1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-13.38 {Tk_BindEvent procedure: binding gets to run} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind Test <Button-1> {lappend x Test}
    bind .t.f <Button-1> {lappend x .t.f}
    event generate .t.f <Button-1>
    bind Test <1> {lappend x Test}
    bind .t.f <1> {lappend x .t.f}
    event generate .t.f <1>
    return $x
} -cleanup {
    destroy .t.f
    bind Test <Button-1> {}
    bind Test <1> {}
} -result {.t.f Test}
test bind-13.41 {Tk_BindEvent procedure: continue in script} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131

1132
1133
1134

1135
1136
1137
1138
1139
1140
1141

1142
1143
1144
1145
1146
1147
1148

1149
1150
1151

1152
1153
1154
1155
1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169



1170
1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181
1182

1183
1184
1185
1186

1187
1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212

1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227



1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
1239
1240
1241


1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1294
1295
1296

1297
1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388

1389
1390

1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1411


1412
1413
1414
1415
1416
1417
1418
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060

1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126
1127
1128

1129
1130
1131

1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145

1146
1147
1148

1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
1163
1164



1165
1166
1167
1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
1178
1179

1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222



1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233
1234
1235
1236
1237


1238
1239
1240
1241
1242

1243
1244
1245
1246
1247
1248
1249

1250
1251
1252
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274
1275
1276

1277
1278
1279
1280
1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310

1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
1325
1326
1327

1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351

1352
1353
1354
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385

1386
1387

1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1408

1409
1410
1411
1412
1413
1414
1415
1416
1417







-












-
+



-














-
+














-
+






-
+








-
+















-
+






-
+


-
+






-
+






-
+


-
+






-
+








-
-
-
+
+
+



-
+








-
+



-
+








-
+



-
+








-
+



-
+












-
-
-
+
+
+



-
+








-
-
+
+



-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+









-
+






-
+

-
+





-
+






-
+







-
+
+







    bind Test <Button-2> {}
    proc bgerror args {}
} -result {b1 {invalid command name "blap"}}

test bind-15.1 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    update idletasks
    focus -force .t.f
    update
} -body {
    bind .t.f 12 {set x 1}
    set x 0
    event generate .t.f <Key-1>
    event generate .t.f <KeyRelease-1>
    event generate .t.f <Key-2>
    event generate .t.f <KeyRelease-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.2 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    update idletasks
    focus -force .t.f
    update
} -body {
    bind .t.f 12 {set x 1}
    set x 0
    event generate .t.f <Key-1>
    event generate .t.f <Enter>
    event generate .t.f <KeyRelease-1>
    event generate .t.f <Leave>
    event generate .t.f <Key-2>
    event generate .t.f <KeyRelease-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.3 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f 12 {set x 1}
    set x 0
    event generate .t.f <Key-1>
    event generate .t.f <Button-1>
    event generate .t.f <Key-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.4 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.5 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-ButtonRelease> {set x 1}
    set x 0
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.6 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-1>
    event generate .t.f <a>
    event generate .t.f <Key-a>
    event generate .t.f <ButtonRelease-1>
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.7 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-1>
    event generate .t.f <Shift_L>
    event generate .t.f <Key-Shift_L>
    event generate .t.f <ButtonRelease-1>
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.8 {MatchPatterns procedure, ignoring type mismatches} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f ab {set x 1}
    set x 0
    event generate .t.f <a>
    event generate .t.f <c>
    event generate .t.f <b>
    event generate .t.f <Key-a>
    event generate .t.f <Key-c>
    event generate .t.f <Key-b>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.9 {MatchPatterns procedure, modifier checks} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <M1-M2-Key> {set x 1}
    set x 0
    event generate .t.f <a> -state 0x18
    event generate .t.f <Key-a> -state 0x18
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.10 {MatchPatterns procedure, modifier checks} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <M1-M2-Key> {set x 1}
    set x 0
    event generate .t.f <a> -state 0xfc
    event generate .t.f <Key-a> -state 0xfc
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.11 {MatchPatterns procedure, modifier checks} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <M1-M2-Key> {set x 1}
    set x 0
    event generate .t.f <a> -state 0x8
    event generate .t.f <Key-a> -state 0x8
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.12 {MatchPatterns procedure, ignore modifier presses and releases} -constraints {
    nonPortable
} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    # This test is non-portable because the Shift_L keysym may behave
    # differently on some platforms.
    bind .t.f aB {set x 1}
    set x 0
    event generate .t.f <a>
    event generate .t.f <Shift_L>
    event generate .t.f <b> -state 1
    event generate .t.f <Key-a>
    event generate .t.f <Key-Shift_L>
    event generate .t.f <Key-b> -state 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.13 {MatchPatterns procedure, checking detail} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f ab {set x 1}
    set x 0
    event generate .t.f <a>
    event generate .t.f <c>
    event generate .t.f <Key-a>
    event generate .t.f <Key-c>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.14 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 31 -y 39
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.15 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 29 -y 41
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.16 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 40 -y 40
    event generate .t.f <ButtonRelease-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.17 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 20 -y 40
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.18 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 30 -y 30
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.19 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -x 30 -y 40
    event generate .t.f <Button-1> -x 30 -y 50
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.20 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -time 300
    event generate .t.f <Button-1> -time 700
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.21 {MatchPatterns procedure, checking "nearby"} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-2>
    event generate .t.f <ButtonRelease-2>
    event generate .t.f <Button-1> -time 300
    event generate .t.f <Button-1> -time 900
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.22 {MatchPatterns procedure, time wrap-around} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-1> -time -100
    event generate .t.f <Button-1> -time [expr -100]
    event generate .t.f <Button-1> -time 200
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.23 {MatchPatterns procedure, time wrap-around} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Double-Button-1> {set x 1}
    bind .t.f <Double-1> {set x 1}
    set x 0
    event generate .t.f <Button-1> -time -100
    event generate .t.f <Button-1> -time 500
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}

test bind-15.24 {MatchPatterns procedure, virtual event} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508

1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526


1527
1528
1529
1530
1531
1532
1533

1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546
1547

1548
1549
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571



1572
1573
1574
1575
1576
1577
1578
1579
1580


1581
1582
1583
1584
1585
1586
1587
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475

1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486

1487
1488
1489

1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500

1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520


1521
1522
1523
1524
1525
1526
1527
1528

1529
1530
1531
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554
1555
1556

1557
1558
1559
1560
1561
1562
1563
1564



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574


1575
1576
1577
1578
1579
1580
1581
1582
1583







-



-
+






-
+



-



-
+






-
+



-



-
+
















-
-
+
+






-
+









-
+



-
+









-
+



-
+







-
-
-
+
+
+







-
-
+
+







    event delete <<V1>> <Button>
    event delete <<V2>> <Button-1>
    event delete <<V3>> <Shift-Button-1>
} -result {V2102 V2103 V2105 Shift-Button-1}
test bind-15.27 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    update idletasks
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x 0}
    bind .t.f <KeyPress> {set x 0}
    bind .t.f 1 {set x 1}
    set x none
    event generate .t.f <Key-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.28 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    update idletasks
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x 0}
    bind .t.f <KeyPress> {set x 0}
    bind .t.f 1 {set x 1}
    set x none
    event generate .t.f <Key-2>
    return $x
} -cleanup {
    destroy .t.f
} -result 0
} -result {0}
test bind-15.29 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    update idletasks
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {lappend x 0}
    bind .t.f <KeyPress> {lappend x 0}
    bind .t.f 1 {lappend x 1}
    bind .t.f 21 {lappend x 2}
    set x none
    event generate .t.f <Key-2>
    event generate .t.f <KeyRelease-2>
    event generate .t.f <Key-1>
    set x
} -cleanup {
    destroy .t.f
} -result {none 0 2}
test bind-15.30 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button> {set x 0}
    bind .t.f <Button-1> {set x 1}
    bind .t.f <ButtonPress> {set x 0}
    bind .t.f <1> {set x 1}
    set x none
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.31 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <M1-Key> {set x 0}
    bind .t.f <M2-Key> {set x 1}
    event generate .t.f <a> -state 0x18
    event generate .t.f <Key-a> -state 0x18
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.32 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <M2-Key> {set x 0}
    bind .t.f <M1-Key> {set x 1}
    set x none
    event generate .t.f <a> -state 0x18
    event generate .t.f <Key-a> -state 0x18
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-15.33 {MatchPatterns procedure, conflict resolution} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1> {lappend x single}
    bind Test <Button-1> {lappend x single(Test)}
    bind Test <Double-Button-1> {lappend x double(Test)}
    bind .t.f <1> {lappend x single}
    bind Test <1> {lappend x single(Test)}
    bind Test <Double-1> {lappend x double(Test)}
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    set x
} -cleanup {
    destroy .t.f
    bind Test <Button-1> {}
    bind Test <Double-Button-1> {}
    bind Test <1> {}
    bind Test <Double-1> {}
} -result {single single(Test) single double(Test) single double(Test)}


test bind-16.1 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
1602
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612
1613
1614
1615
1616
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612







-
+







} -body {
    bind .t.f <Enter> {set x %#}
    set x none
    event generate .t.f <Enter> -serial 1234
    set x
} -cleanup {
    destroy .t.f
} -result 1234
} -result {1234}
test bind-16.3 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Configure> {set x %a}
1629
1630
1631
1632
1633
1634
1635
1636

1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649

1650
1651
1652
1653
1654
1655
1656
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651
1652







-
+












-
+







    bind .t.f <Button> {set x %b}
    set x none
    event generate .t.f <Button-3>
    event generate .t.f <ButtonRelease-3>
    set x
} -cleanup {
    destroy .t.f
} -result 3
} -result {3}
test bind-16.5 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Expose> {set x %c}
    set x none
    event generate .t.f <Expose> -count 47
    set x
} -cleanup {
    destroy .t.f
} -result 47
} -result {47}
test bind-16.6 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Enter> {set x %d}
1746
1747
1748
1749
1750
1751
1752
1753

1754
1755
1756
1757
1758
1759
1760
1742
1743
1744
1745
1746
1747
1748

1749
1750
1751
1752
1753
1754
1755
1756







-
+







} -body {
    bind .t.f <Enter> {set x %f}
    set x none
    event generate .t.f <Enter> -focus 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-16.14 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Expose> {set x "%x %y %w %h"}
1785
1786
1787
1788
1789
1790
1791
1792

1793
1794
1795
1796
1797
1798
1799
1781
1782
1783
1784
1785
1786
1787

1788
1789
1790
1791
1792
1793
1794
1795







-
+







} -body {
    bind .t.f <Key> {set x "%k"}
    set x none
    event generate .t.f <Key> -keycode 146
    set x
} -cleanup {
    destroy .t.f
} -result 146
} -result {146}
test bind-16.17 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Enter> {set x "%m"}
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
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







-
+












-
+












-
+







} -body {
    bind .t.f <Map> {set x "%o"}
    set x none
    event generate .t.f <Map> -override 1 -window .t.f
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-16.22 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Reparent> {set x "%o"}
    set x none
    event generate .t.f <Reparent> -override true -window .t.f
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-16.23 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Configure> {set x "%o"}
    set x none
    event generate .t.f <Configure> -override 1 -window .t.f
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-16.24 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Circulate> {set x "%p"}
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
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







-
+






-
+












-
+







} -result {PlaceOnBottom}
test bind-16.26 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button-1> {set x "%s"}
    bind .t.f <1> {set x "%s"}
    set x none
    event generate .t.f <Button-1> -state 1402
    event generate .t.f <ButtonRelease-1>
    set x
} -cleanup {
    destroy .t.f
} -result 1402
} -result {1402}
test bind-16.27 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Enter> {set x "%s"}
    set x none
    event generate .t.f <Enter> -state 0x3ff
    set x
} -cleanup {
    destroy .t.f
} -result 1023
} -result {1023}
test bind-16.28 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Visibility> {set x "%s"}
1983
1984
1985
1986
1987
1988
1989
1990

1991
1992
1993
1994
1995
1996
1997
1979
1980
1981
1982
1983
1984
1985

1986
1987
1988
1989
1990
1991
1992
1993







-
+







    bind .t.f <Button> {set x "%t"}
    set x none
    event generate .t.f <Button> -time 4294
    event generate .t.f <ButtonRelease>
    set x
} -cleanup {
    destroy .t.f
} -result 4294
} -result {4294}
test bind-16.32 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button> {set x "%x %y"}
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
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







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+



-
+












-
+












-
+










-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+












-
+



-
+








-
+
















-
+







    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> {lappend x "%A"}
    event generate .t.f <a>
    event generate .t.f <A> -state 1
    event generate .t.f <Tab>
    event generate .t.f <Return>
    event generate .t.f <F1>
    event generate .t.f <Shift_L>
    event generate .t.f <space>
    event generate .t.f <dollar> -state 1
    event generate .t.f <braceleft> -state 1
    event generate .t.f <Multi_key>
    event generate .t.f <e>
    event generate .t.f <apostrophe>
    event generate .t.f <Key-a>
    event generate .t.f <Key-A> -state 1
    event generate .t.f <Key-Tab>
    event generate .t.f <Key-Return>
    event generate .t.f <Key-F1>
    event generate .t.f <Key-Shift_L>
    event generate .t.f <Key-space>
    event generate .t.f <Key-dollar> -state 1
    event generate .t.f <Key-braceleft> -state 1
    event generate .t.f <Key-Multi_key>
    event generate .t.f <Key-e>
    event generate .t.f <Key-apostrophe>
    set x
} -cleanup {
    destroy .t.f
} -result {a A {	} {\r} {{}} {{}} { } {\$} \\\{ {{}} {{}} é}
} -result {a A {	} {\r} {{}} {{}} { } {\$} \\\{ {{}} {{}} \u00e9}
test bind-16.36 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Configure> {set x "%B"}
    set x none
    event generate .t.f <Configure> -borderwidth 24 -window .t.f
    set x
} -cleanup {
    destroy .t.f
} -result 24
} -result {24}
test bind-16.37 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Enter> {set x "%E"}
    set x none
    event generate .t.f <Enter> -sendevent 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-16.38 {ExpandPercents procedure} -constraints {
    nonPortable
} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> {lappend x %K}
    event generate .t.f <a>
    event generate .t.f <A> -state 1
    event generate .t.f <Tab>
    event generate .t.f <F1>
    event generate .t.f <Shift_L>
    event generate .t.f <space>
    event generate .t.f <dollar> -state 1
    event generate .t.f <braceleft> -state 1
    event generate .t.f <Key-a>
    event generate .t.f <Key-A> -state 1
    event generate .t.f <Key-Tab>
    event generate .t.f <Key-F1>
    event generate .t.f <Key-Shift_L>
    event generate .t.f <Key-space>
    event generate .t.f <Key-dollar> -state 1
    event generate .t.f <Key-braceleft> -state 1
    set x
} -cleanup {
    destroy .t.f
} -result {a A Tab F1 Shift_L space dollar braceleft}
test bind-16.39 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x "%N"}
    set x none
    event generate .t.f <space>
    event generate .t.f <Key-space>
    set x
} -cleanup {
    destroy .t.f
} -result 32
} -result {32}
test bind-16.40 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x "%S"}
    set x none
    event generate .t.f <space> -subwindow .t
    event generate .t.f <Key-space> -subwindow .t
    set x
} -cleanup {
    destroy .t.f
} -result [winfo id .t]
test bind-16.41 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x "%T"}
    set x none
    event generate .t.f <Key>
    set x
} -cleanup {
    destroy .t.f
} -result 2
} -result {2}
test bind-16.42 {ExpandPercents procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
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
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







-
+




















-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
















-
+









-
+





-
+










-
-
+
+


-
-
+







    foreach p [event info] {event delete $p}
    update
} -body {
    bind .t.e <Key> {set x "%M"}
    bind Entry <Key> {set y "%M"}
    bind all <Key> {set z "%M"}
    set x none; set y none; set z none
    event gen .t.e <a>
    event gen .t.e <Key-a>
    list $x $y $z
} -cleanup {
    destroy .t.e
    bind all <Key> $savedBind(All)
    bind Entry <Key> $savedBind(Entry)
    unset savedBind
} -result {0 1 2}
test bind-16.46 {ExpandPercents procedure} -setup {
    set savedBind(All) [bind all <Key>]
    set savedBind(Entry) [bind Entry <Key>]
    entry .t.e
    pack .t.e
    focus -force .t.e
    foreach p [event info] {event delete $p}
    update
} -body {
    bind all <Key> {set z "%M"}
    bind Entry <Key> {set y "%M"}
    bind .t.e <Key> {set x "%M"}
    set x none; set y none; set z none
    event gen .t.e <a>
    event gen .t.e <Key-a>
    list $x $y $z
} -cleanup {
    destroy .t.e
    bind Entry <Key> $savedBind(Entry)
    bind all <Key> $savedBind(All)
    unset savedBind
} -result {0 1 2}
test bind-16.47 {ExpandPercents procedure} -constraints aquaOrWin32 -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> {set x "%K"}
    set x none
    event generate .t.f <Key> -keysym :
    set x
} -cleanup {
    destroy .t.f
} -result :

test bind-17.1 {event command} -body {
    event
} -returnCodes error -result {wrong # args: should be "event option ?arg?"}
test bind-17.2 {event command} -body {
    event xyz
} -returnCodes error -result {bad option "xyz": must be add, delete, generate, or info}
test bind-17.3 {event command: add} -body {
    event add
} -returnCodes error -result {wrong # args: should be "event add virtual sequence ?sequence ...?"}
test bind-17.4 {event command: add 1} -body {
    event delete <<Paste>>
    event add <<Paste>> <Control-v>
    event info <<Paste>>
} -cleanup {
    event delete <<Paste>> <Control-v>
} -result <Control-Key-v>
} -result {<Control-Key-v>}
test bind-17.5 {event command: add 2} -body {
    event delete <<Paste>>
    event add <<Paste>> <Control-v> <Button-2>
    lsort [event info <<Paste>>]
} -cleanup {
    event delete <<Paste>> <Control-v> <Button-2>
} -result {<Button-2> <Control-Key-v>}

test bind-17.6 {event command: add with error} -body {
    event add <<Paste>> <Control-v> <Button-2> abc <xyz> <Button-1>
    event add <<Paste>> <Control-v> <Button-2> abc <xyz> <1>
} -cleanup {
    event delete <<Paste>>
} -returnCodes error -result {bad event type or keysym "xyz"}
test bind-17.7 {event command: add with error} -body {
    event delete <<Paste>>
    catch {event add <<Paste>> <Control-v> <Button-2> abc <xyz> <Button-1>}
    catch {event add <<Paste>> <Control-v> <Button-2> abc <xyz> <1>}
    lsort [event info <<Paste>>]
} -cleanup {
    event delete <<Paste>>
} -result {<Button-2> <Control-Key-v> abc}

test bind-17.8 {event command: delete} -body {
    event delete
} -returnCodes error -result {wrong # args: should be "event delete virtual ?sequence ...?"}
test bind-17.9 {event command: delete many} -body {
    event delete <<Paste>>
    event add <<Paste>> <Button-3> <Button-1> <Button-2> t
    event delete <<Paste>> <Button-1> <Button-2>
    event add <<Paste>> <3> <1> <2> t
    event delete <<Paste>> <1> <2>
    lsort [event info <<Paste>>]
} -cleanup {
    event delete <<Paste>>
    event delete <<Paste>> <Button-3> t
    event delete <<Paste>> <3> t
} -result {<Button-3> t}
test bind-17.10 {event command: delete all} -body {
    event add <<Paste>> a b
    event delete <<Paste>>
    event info <<Paste>>
} -cleanup {
    event delete <<Paste>> a b
2330
2331
2332
2333
2334
2335
2336
2337
2338


2339
2340
2341
2342

2343
2344
2345
2346
2347
2348
2349
2312
2313
2314
2315
2316
2317
2318


2319
2320
2321
2322
2323

2324
2325
2326
2327
2328
2329
2330
2331







-
-
+
+



-
+







test bind-17.16 {event command: generate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1> "lappend x 1"
    event generate .t.f <Button-1>
    bind .t.f <1> "lappend x 1"
    event generate .t.f <1>
    set x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-17.17 {event command: generate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    event generate .t.f <xyz>
2363
2364
2365
2366
2367
2368
2369
2370

2371
2372
2373
2374
2375
2376
2377
2378

2379
2380
2381
2382
2383
2384
2385
2345
2346
2347
2348
2349
2350
2351

2352
2353
2354
2355
2356
2357
2358
2359

2360
2361
2362
2363
2364
2365
2366
2367







-
+







-
+







} -returnCodes error -result {bad event type or keysym "Ctrl"}
test bind-18.3 {CreateVirtualEvent procedure: new physical} -body {
    event delete <<xyz>>
    event add <<xyz>> <Control-v>
    event info <<xyz>>
} -cleanup {
    event delete <<xyz>>
} -result <Control-Key-v>
} -result {<Control-Key-v>}
test bind-18.4 {CreateVirtualEvent procedure: duplicate physical} -body {
    event delete <<xyz>>
    event add <<xyz>> <Control-v>
    event add <<xyz>> <Control-v>
    event info <<xyz>>
} -cleanup {
    event delete <<xyz>>
} -result <Control-Key-v>
} -result {<Control-Key-v>}
test bind-18.5 {CreateVirtualEvent procedure: existing physical} -body {
    foreach p [event info] {event delete $p}
    event add <<xyz>> <Control-v>
    event add <<abc>> <Control-v>
    list [lsort [event info]] [event info <<xyz>>] [event info <<abc>>]
} -cleanup {
    event delete <<xyz>>
2420
2421
2422
2423
2424
2425
2426
2427

2428
2429
2430
2431
2432
2433
2434
2402
2403
2404
2405
2406
2407
2408

2409
2410
2411
2412
2413
2414
2415
2416







-
+







} -result {}
test bind-19.4 {DeleteVirtualEvent procedure: delete 1, not owned} -setup {
    event delete <<xyz>>
} -body {
    event add <<xyz>> <Control-v>
    event delete <<xyz>> <Button-1>
    event info <<xyz>>
} -result <Control-Key-v>
} -result {<Control-Key-v>}
test bind-19.5 {DeleteVirtualEvent procedure: delete 1, badly formed} -body {
    event add <<xyz>> <Control-v>
    event delete <<xyz>> <xyz>
} -cleanup {
    event delete <<xyz>>
} -returnCodes error -result {bad event type or keysym "xyz"}
test bind-19.6 {DeleteVirtualEvent procedure: delete 1, badly formed} -body {
2477
2478
2479
2480
2481
2482
2483
2484

2485
2486
2487
2488
2489
2490
2491
2459
2460
2461
2462
2463
2464
2465

2466
2467
2468
2469
2470
2471
2472
2473







-
+







    event generate .t.f <ButtonRelease-2>
    event delete <<xyz>>
    event generate .t.f <Button-2> -serial 102
    event generate .t.f <ButtonRelease-2>
    set x
} -cleanup {
    destroy .t.f
} -result 101
} -result {101}
test bind-19.12 {DeleteVirtualEvent procedure: owned by 1, first in chain} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
    event delete <<xyz>>
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2561
2562
2563
2564
2565
2566
2567

2568
2569
2570
2571
2572
2573
2574







-







    event delete <<def>>
    event delete <<abc>>
} -result {{xyz abc def abc def} {} <Control-Button-2> <Shift-Button-2>}
test bind-19.15 {DeleteVirtualEvent procedure: owned by many, first} -setup {
    pack [frame .t.f -class Test -width 150 -height 100]
    pack [frame .t.g -class Test -width 150 -height 100]
    pack [frame .t.h -class Test -width 150 -height 100]
    after 250 ;# we need a bit time to ensure that .t.h is mapped (<TODO>: fix this race condition)
    focus -force .t.f
    update
    set x {}
    event delete <<def>>
    event delete <<xyz>>
    event delete <<abc>>
} -body {
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2597
2598
2599
2600
2601
2602
2603

2604
2605
2606
2607
2608
2609
2610







-







    event delete <<def>>
    event delete <<abc>>
} -result {{xyz abc def abc def} {} <Button-2> <Button-2>}
test bind-19.16 {DeleteVirtualEvent procedure: owned by many, middle} -setup {
    pack [frame .t.f -class Test -width 150 -height 100]
    pack [frame .t.g -class Test -width 150 -height 100]
    pack [frame .t.h -class Test -width 150 -height 100]
    after 250 ;# we need a bit time to ensure that .t.h is mapped (<TODO>: fix this race condition)
    focus -force .t.f
    update
    set x {}
    event delete <<def>>
    event delete <<xyz>>
    event delete <<abc>>
} -body {
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2633
2634
2635
2636
2637
2638
2639

2640
2641
2642
2643
2644
2645
2646







-







    event delete <<def>>
    event delete <<xyz>>
} -result {{xyz abc def xyz def} <Button-2> {} <Button-2>}
test bind-19.17 {DeleteVirtualEvent procedure: owned by many, last} -setup {
    pack [frame .t.f -class Test -width 150 -height 100]
    pack [frame .t.g -class Test -width 150 -height 100]
    pack [frame .t.h -class Test -width 150 -height 100]
    after 250 ;# we need a bit time to ensure that .t.h is mapped (<TODO>: fix this race condition)
    focus -force .t.f
    update
    set x {}
    event delete <<def>>
    event delete <<xyz>>
    event delete <<abc>>
} -body {
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
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







-
+



-
+




















-
+





-
+







test bind-20.2 {GetVirtualEvent procedure: non-existent event} -body {
    event delete <<asd>>
    event info <<asd>>
} -result {}
test bind-20.3 {GetVirtualEvent procedure: owns 1} -setup {
    event delete <<xyz>>
} -body {
    event add <<xyz>> <Control-v>
    event add <<xyz>> <Control-Key-v>
    event info <<xyz>>
} -cleanup {
    event delete <<xyz>>
} -result <Control-Key-v>
} -result {<Control-Key-v>}
test bind-20.4 {GetVirtualEvent procedure: owns many} -setup {
    event delete <<xyz>>
} -body {
    event add <<xyz>> <Control-v> <Button-2> spack
    event info <<xyz>>
} -cleanup {
    event delete <<xyz>>
} -result {<Control-Key-v> <Button-2> spack}


test bind-21.1 {GetAllVirtualEvents procedure: no events} -body {
    foreach p [event info] {event delete $p}
    event info
} -result {}
test bind-21.2 {GetAllVirtualEvents procedure: 1 event} -body {
    foreach p [event info] {event delete $p}
    event add <<xyz>> <Control-v>
    event info
} -cleanup {
    event delete <<xyz>>
} -result <<xyz>>
} -result {<<xyz>>}
test bind-21.3 {GetAllVirtualEvents procedure: many events} -body {
    foreach p [event info] {event delete $p}
    event add <<xyz>> <Control-v>
    event add <<xyz>> <Button-2>
    event add <<abc>> <Control-v>
    event add <<def>> <F6>
    event add <<def>> <Key-F6>
    lsort [event info]
} -cleanup {
    event delete <<xyz>>
    event delete <<abc>>
    event delete <<def>>
} -result {<<abc>> <<def>> <<xyz>>}

2766
2767
2768
2769
2770
2771
2772
2773

2774
2775
2776
2777
2778
2779
2780
2745
2746
2747
2748
2749
2750
2751

2752
2753
2754
2755
2756
2757
2758
2759







-
+







    destroy .t.f
} -result {260 1}
test bind-22.5 {HandleEventGenerate} -body {
    event generate . <xyz>
} -returnCodes error -result {bad event type or keysym "xyz"}
test bind-22.6 {HandleEventGenerate} -body {
    event generate . <Double-Button-1>
} -returnCodes error -result {Double, Triple, or Quadruple modifier not allowed}
} -returnCodes error -result {Double or Triple modifier not allowed}
test bind-22.7 {HandleEventGenerate} -body {
    event generate . xyz
} -returnCodes error -result {only one event specification allowed}
test bind-22.8 {HandleEventGenerate} -body {
    event generate . <Button> -button
} -returnCodes error -result {value for "-button" missing}
test bind-22.9 {HandleEventGenerate} -setup {
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
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







-
+
















-
+












-
+













-
+







    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> {set x "%s %K"}
    event generate .t.f <Control-space>
    event generate .t.f <Control-Key-space>
    set x
} -cleanup {
    destroy .t.f
} -result {4 space}
test bind-22.11 {HandleEventGenerate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> {set x "%s"}
    event generate .t.f <<Paste>> -state 1
    set x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}
test bind-22.12 {HandleEventGenerate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> {set x "%s"}
    event generate .t.f <Control-Motion>
    set x
} -cleanup {
    destroy .t.f
} -result 4
} -result {4}
test bind-22.13 {HandleEventGenerate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> {lappend x %#}
    event generate .t.f <Button> -when now -serial 100
    event generate .t.f <ButtonRelease> -when now
    set x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}
test bind-22.14 {HandleEventGenerate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
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
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







-
+













-
+







    set x {}
} -body {
    bind .t.f <Configure> "lappend x %B"
    event generate .t.f <Configure> -borderwidth xyz
    return $x
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.25 {HandleEventGenerate: options <Configure> -borderwidth 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %B"
    event generate .t.f <Configure> -borderwidth 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.26 {HandleEventGenerate: options <Key> -borderwidth 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3092
3093
3094
3095
3096
3097
3098
3099

3100
3101
3102
3103
3104
3105
3106
3071
3072
3073
3074
3075
3076
3077

3078
3079
3080
3081
3082
3083
3084
3085







-
+







    set x {}
} -body {
    bind .t.f <Expose> "lappend x %c"
    event generate .t.f <Expose> -count 20
    return $x
} -cleanup {
    destroy .t.f
} -result 20
} -result {20}

test bind-22.33 {HandleEventGenerate: options <Key> -count 20} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210
3211
3212
3213
3214
3179
3180
3181
3182
3183
3184
3185

3186
3187
3188
3189
3190
3191
3192
3193







-
+







    set x {}
} -body {
    bind .t.f <Enter> "lappend x %f"
    event generate .t.f <Enter> -focus 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.40 {HandleEventGenerate: options <Key> -focus 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3226
3227
3228
3229
3230
3231
3232
3233

3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247

3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261

3262
3263
3264
3265
3266
3267
3268
3205
3206
3207
3208
3209
3210
3211

3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225

3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239

3240
3241
3242
3243
3244
3245
3246
3247







-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %h"
    event generate .t.f <Expose> -height xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.42 {HandleEventGenerate: options <Expose> -height 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %h"
    event generate .t.f <Expose> -height 2i
    expr {$x eq [winfo pixels .t.f 2i]}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.43 {HandleEventGenerate: options <Configure> -height 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %h"
    event generate .t.f <Configure> -height 2i
    expr {$x eq [winfo pixels .t.f 2i]}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.44 {HandleEventGenerate: options <Key> -height 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3294
3295
3296
3297
3298
3299
3300
3301

3302
3303
3304
3305
3306
3307
3308
3273
3274
3275
3276
3277
3278
3279

3280
3281
3282
3283
3284
3285
3286
3287







-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %k"
    event generate .t.f <Key> -keycode 20
    return $x
} -cleanup {
    destroy .t.f
} -result 20
} -result {20}

test bind-22.47 {HandleEventGenerate: options <Button> -keycode 20} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3427
3428
3429
3430
3431
3432
3433
3434

3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448

3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462

3463
3464
3465
3466
3467
3468
3469
3406
3407
3408
3409
3410
3411
3412

3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426

3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440

3441
3442
3443
3444
3445
3446
3447
3448







-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Map> "lappend x %o"
    event generate .t.f <Map> -override 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.57 {HandleEventGenerate: options <Reparent> -override 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Reparent> "lappend x %o"
    event generate .t.f <Reparent> -override 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.58 {HandleEventGenerate: options <Configure> -override 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %o"
    event generate .t.f <Configure> -override 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.59 {HandleEventGenerate: options <Key> -override 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3535
3536
3537
3538
3539
3540
3541
3542

3543
3544
3545
3546
3547
3548
3549
3514
3515
3516
3517
3518
3519
3520

3521
3522
3523
3524
3525
3526
3527
3528







-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %R"
    event generate .t.f <Key> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.65 {HandleEventGenerate: options <Key> -root xyz} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3562
3563
3564
3565
3566
3567
3568
3569

3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583

3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597

3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611

3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625

3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639

3640
3641
3642
3643
3644
3645
3646
3541
3542
3543
3544
3545
3546
3547

3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561

3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575

3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589

3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603

3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617

3618
3619
3620
3621
3622
3623
3624
3625







-
+













-
+













-
+













-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %R"
    event generate .t.f <Key> -root [winfo id .t]
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.67 {HandleEventGenerate: options <Button> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %R"
    event generate .t.f <Button> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.68 {HandleEventGenerate: options <ButtonRelease> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %R"
    event generate .t.f <ButtonRelease> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.69 {HandleEventGenerate: options <Motion> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %R"
    event generate .t.f <Motion> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.70 {HandleEventGenerate: options <<Paste>> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %R"
    event generate .t.f <<Paste>> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.71 {HandleEventGenerate: options <Enter> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %R"
    event generate .t.f <Enter> -root .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.72 {HandleEventGenerate: options <Configure> -root .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3658
3659
3660
3661
3662
3663
3664
3665

3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679

3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693

3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707

3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721

3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735

3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749

3750
3751
3752
3753
3754
3755
3756
3637
3638
3639
3640
3641
3642
3643

3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657

3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671

3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685

3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699

3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713

3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727

3728
3729
3730
3731
3732
3733
3734
3735







-
+













-
+













-
+













-
+













-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %X"
    event generate .t.f <Key> -rootx xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.74 {HandleEventGenerate: options <Key> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %X"
    event generate .t.f <Key> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.75 {HandleEventGenerate: options <Button> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %X"
    event generate .t.f <Button> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.76 {HandleEventGenerate: options <ButtonRelease> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %X"
    event generate .t.f <ButtonRelease> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.77 {HandleEventGenerate: options <Motion> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %X"
    event generate .t.f <Motion> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.78 {HandleEventGenerate: options <<Paste>> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %X"
    event generate .t.f <<Paste>> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.79 {HandleEventGenerate: options <Enter> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %X"
    event generate .t.f <Enter> -rootx 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.80 {HandleEventGenerate: options <Configure> -rootx 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3768
3769
3770
3771
3772
3773
3774
3775

3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789

3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803

3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817

3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831

3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845

3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859

3860
3861
3862
3863
3864
3865
3866
3747
3748
3749
3750
3751
3752
3753

3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767

3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781

3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795

3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809

3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823

3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837

3838
3839
3840
3841
3842
3843
3844
3845







-
+













-
+













-
+













-
+













-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %Y"
    event generate .t.f <Key> -rooty xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.82 {HandleEventGenerate: options <Key> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %Y"
    event generate .t.f <Key> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.83 {HandleEventGenerate: options <Button> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %Y"
    event generate .t.f <Button> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.84 {HandleEventGenerate: options <ButtonRelease> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %Y"
    event generate .t.f <ButtonRelease> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.85 {HandleEventGenerate: options <Motion> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %Y"
    event generate .t.f <Motion> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.86 {HandleEventGenerate: options <<Paste>> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %Y"
    event generate .t.f <<Paste>> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.87 {HandleEventGenerate: options <Enter> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %Y"
    event generate .t.f <Enter> -rooty 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.88 {HandleEventGenerate: options <Configure> -rooty 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3892
3893
3894
3895
3896
3897
3898
3899

3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913

3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927

3928
3929
3930
3931
3932
3933
3934
3871
3872
3873
3874
3875
3876
3877

3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891

3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905

3906
3907
3908
3909
3910
3911
3912
3913







-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %E"
    event generate .t.f <Key> -sendevent 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.91 {HandleEventGenerate: options <Key> -sendevent yes} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %E"
    event generate .t.f <Key> -sendevent yes
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.92 {HandleEventGenerate: options <Key> -sendevent 43} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %E"
    event generate .t.f <Key> -sendevent 43
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {43}

test bind-22.93 {HandleEventGenerate: options <Key> -serial xyz} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3947
3948
3949
3950
3951
3952
3953
3954

3955
3956
3957
3958
3959
3960
3961
3926
3927
3928
3929
3930
3931
3932

3933
3934
3935
3936
3937
3938
3939
3940







-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %#"
    event generate .t.f <Key> -serial 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.95 {HandleEventGenerate: options <Key> -state xyz} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
3974
3975
3976
3977
3978
3979
3980
3981

3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995

3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009

4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023

4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037

4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051

4052
4053
4054
4055
4056
4057
4058
3953
3954
3955
3956
3957
3958
3959

3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973

3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987

3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001

4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015

4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029

4030
4031
4032
4033
4034
4035
4036
4037







-
+













-
+













-
+













-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %s"
    event generate .t.f <Key> -state 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.97 {HandleEventGenerate: options <Button> -state 1025} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %s"
    event generate .t.f <Button> -state 1025
    return $x
} -cleanup {
    destroy .t.f
} -result 1025
} -result {1025}

test bind-22.98 {HandleEventGenerate: options <ButtonRelease> -state 1025} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %s"
    event generate .t.f <ButtonRelease> -state 1025
    return $x
} -cleanup {
    destroy .t.f
} -result 1025
} -result {1025}

test bind-22.99 {HandleEventGenerate: options <Motion> -state 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %s"
    event generate .t.f <Motion> -state 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.100 {HandleEventGenerate: options <<Paste>> -state 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %s"
    event generate .t.f <<Paste>> -state 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.101 {HandleEventGenerate: options <Enter> -state 1} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %s"
    event generate .t.f <Enter> -state 1
    return $x
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.102 {HandleEventGenerate: options <Visibility> -state xyz} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4111
4112
4113
4114
4115
4116
4117
4118

4119
4120
4121
4122
4123
4124
4125
4090
4091
4092
4093
4094
4095
4096

4097
4098
4099
4100
4101
4102
4103
4104







-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %S"
    event generate .t.f <Key> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.107 {HandleEventGenerate: options <Key> -subwindow xyz} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4138
4139
4140
4141
4142
4143
4144
4145

4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159

4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173

4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187

4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201

4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215

4216
4217
4218
4219
4220
4221
4222
4117
4118
4119
4120
4121
4122
4123

4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137

4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151

4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165

4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179

4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193

4194
4195
4196
4197
4198
4199
4200
4201







-
+













-
+













-
+













-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %S"
    event generate .t.f <Key> -subwindow [winfo id .t]
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.109 {HandleEventGenerate: options <Button> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %S"
    event generate .t.f <Button> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.110 {HandleEventGenerate: options <ButtonRelease> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %S"
    event generate .t.f <ButtonRelease> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.111 {HandleEventGenerate: options <Motion> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %S"
    event generate .t.f <Motion> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.112 {HandleEventGenerate: options <<Paste>> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %S"
    event generate .t.f <<Paste>> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.113 {HandleEventGenerate: options <Enter> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %S"
    event generate .t.f <Enter> -subwindow .t
    expr {[winfo id .t] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.114 {HandleEventGenerate: options <Configure> -subwindow .t} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4248
4249
4250
4251
4252
4253
4254
4255

4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269

4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283

4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297

4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311

4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325

4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339

4340
4341
4342
4343
4344
4345
4346
4227
4228
4229
4230
4231
4232
4233

4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247

4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261

4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275

4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289

4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303

4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317

4318
4319
4320
4321
4322
4323
4324
4325







-
+













-
+













-
+













-
+













-
+













-
+













-
+







    set x {}
} -body {
    bind .t.f <Key> "lappend x %t"
    event generate .t.f <Key> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.117 {HandleEventGenerate: options <Button> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %t"
    event generate .t.f <Button> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.118 {HandleEventGenerate: options <ButtonRelease> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %t"
    event generate .t.f <ButtonRelease> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.119 {HandleEventGenerate: options <Motion> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %t"
    event generate .t.f <Motion> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.120 {HandleEventGenerate: options <<Paste>> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %t"
    event generate .t.f <<Paste>> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.121 {HandleEventGenerate: options <Enter> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %t"
    event generate .t.f <Enter> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.122 {HandleEventGenerate: options <Property> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Property> "lappend x %t"
    event generate .t.f <Property> -time 100
    return $x
} -cleanup {
    destroy .t.f
} -result 100
} -result {100}

test bind-22.123 {HandleEventGenerate: options <Configure> -time 100} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4358
4359
4360
4361
4362
4363
4364
4365

4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379

4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393

4394
4395
4396
4397
4398
4399
4400
4337
4338
4339
4340
4341
4342
4343

4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357

4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371

4372
4373
4374
4375
4376
4377
4378
4379







-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %w"
    event generate .t.f <Expose> -width xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.125 {HandleEventGenerate: options <Expose> -width 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %w"
    event generate .t.f <Expose> -width 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.126 {HandleEventGenerate: options <Configure> -width 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %w"
    event generate .t.f <Configure> -width 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.127 {HandleEventGenerate: options <Key> -width 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4563
4564
4565
4566
4567
4568
4569
4570

4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584

4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598

4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612

4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626

4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640

4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654

4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668

4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682

4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696

4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710

4711
4712
4713
4714
4715
4716
4717
4542
4543
4544
4545
4546
4547
4548

4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562

4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576

4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590

4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604

4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618

4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632

4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646

4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660

4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674

4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688

4689
4690
4691
4692
4693
4694
4695
4696







-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %x"
    event generate .t.f <Key> -x xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.140 {HandleEventGenerate: options <Key> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %x"
    event generate .t.f <Key> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.141 {HandleEventGenerate: options <Button> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %x"
    event generate .t.f <Button> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.142 {HandleEventGenerate: options <ButtonRelease> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %x"
    event generate .t.f <ButtonRelease> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.143 {HandleEventGenerate: options <Motion> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %x"
    event generate .t.f <Motion> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.144 {HandleEventGenerate: options <<Paste>> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %x"
    event generate .t.f <<Paste>> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.145 {HandleEventGenerate: options <Enter> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %x"
    event generate .t.f <Enter> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.146 {HandleEventGenerate: options <Expose> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %x"
    event generate .t.f <Expose> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.147 {HandleEventGenerate: options <Configure> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %x"
    event generate .t.f <Configure> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.148 {HandleEventGenerate: options <Gravity> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Gravity> "lappend x %x"
    event generate .t.f <Gravity> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.149 {HandleEventGenerate: options <Reparent> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Reparent> "lappend x %x"
    event generate .t.f <Reparent> -x 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.150 {HandleEventGenerate: options <Map> -x 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4729
4730
4731
4732
4733
4734
4735
4736

4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750

4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764

4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778

4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792

4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806

4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820

4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834

4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848

4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862

4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876

4877
4878
4879
4880
4881
4882
4883
4708
4709
4710
4711
4712
4713
4714

4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728

4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742

4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756

4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770

4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784

4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798

4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812

4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826

4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840

4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854

4855
4856
4857
4858
4859
4860
4861
4862







-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+













-
+







    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %y"
    event generate .t.f <Key> -y xyz
} -cleanup {
    destroy .t.f
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}

test bind-22.152 {HandleEventGenerate: options <Key> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> "lappend x %y"
    event generate .t.f <Key> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.153 {HandleEventGenerate: options <Button> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button> "lappend x %y"
    event generate .t.f <Button> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.154 {HandleEventGenerate: options <ButtonRelease> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <ButtonRelease> "lappend x %y"
    event generate .t.f <ButtonRelease> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.155 {HandleEventGenerate: options <Motion> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Motion> "lappend x %y"
    event generate .t.f <Motion> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.156 {HandleEventGenerate: options <<Paste>> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <<Paste>> "lappend x %y"
    event generate .t.f <<Paste>> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.157 {HandleEventGenerate: options <Enter> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Enter> "lappend x %y"
    event generate .t.f <Enter> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.158 {HandleEventGenerate: options <Expose> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Expose> "lappend x %y"
    event generate .t.f <Expose> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.159 {HandleEventGenerate: options <Configure> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Configure> "lappend x %y"
    event generate .t.f <Configure> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.160 {HandleEventGenerate: options <Gravity> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Gravity> "lappend x %y"
    event generate .t.f <Gravity> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.161 {HandleEventGenerate: options <Reparent> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Reparent> "lappend x %y"
    event generate .t.f <Reparent> -y 2i
    expr {[winfo pixels .t.f 2i] eq $x}
} -cleanup {
    destroy .t.f
} -result 1
} -result {1}

test bind-22.162 {HandleEventGenerate: options <Map> -y 2i} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
4934
4935
4936
4937
4938
4939
4940
4941

4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952




4953
4954
4955
4956
4957
4958
4959
4913
4914
4915
4916
4917
4918
4919

4920
4921
4922
4923
4924
4925
4926
4927




4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938







-
+







-
-
-
-
+
+
+
+







    set x {}
} -body {
    bind .t.f <<Paste>> test
} -cleanup {
    destroy .t.f
} -result  {}
test bind-24.4 {FindSequence procedure: virtual not allowed} -body {
    event add <<Paste>> <<Alive>>
   event add <<Paste>> <<Alive>>
} -returnCodes error -result {virtual event not allowed in definition of another virtual event}
test bind-24.5 {FindSequence procedure, multiple bindings} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button-1> {lappend x single}
    bind .t.f <Double-Button-1> {lappend x double}
    bind .t.f <Triple-Button-1> {lappend x triple}
    bind .t.f <Quadruple-Button-1> {lappend x quadruple}
    bind .t.f <1> {lappend x single}
    bind .t.f <Double-1> {lappend x double}
    bind .t.f <Triple-1> {lappend x triple}
    bind .t.f <Quadruple-1> {lappend x quadruple}
    set x press
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    lappend x press
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    lappend x press
5100
5101
5102
5103
5104
5105
5106
5107

5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120

5121
5122
5123
5124


5125
5126
5127

5128
5129
5130
5131
5132
5133
5134
5079
5080
5081
5082
5083
5084
5085

5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098

5099




5100
5101



5102
5103
5104
5105
5106
5107
5108
5109







-
+












-
+
-
-
-
-
+
+
-
-
-
+







} -cleanup {
    destroy .t.f
} -result test
test bind-25.2 {ParseEventDescription procedure: misinterpreted modifier} -setup {
    button .b
} -body {
    bind .b <Control-M> a
    bind .b <Meta-M> b
    bind .b <M-M> b
    lsort [bind .b]
} -cleanup {
    destroy .b
} -result {<Control-Key-M> <Meta-Key-M>}
test bind-25.3 {ParseEventDescription procedure} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <a---> {nothing}
    bind .t.f
} -cleanup {
    destroy .t.f
} -result a
test bind-25.4 {ParseEventDescription} -setup {
test bind-25.4 {ParseEventDescription} -body {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <<Shift-Paste>> {puts hi}
    bind .t.f
    bind .t <<Shift-Paste>> {puts hi}
    bind .t
} -cleanup {
    destroy .t.f
} -result <<Shift-Paste>>
} -result {<<Shift-Paste>>}

# Assorted error cases in event sequence parsing
test bind-25.5 {ParseEventDescription procedure error cases} -body {
    bind .t \x7 {puts hi}
} -returnCodes error -result {bad ASCII character 0x7}
test bind-25.6 {ParseEventDescription procedure error cases} -body {
    bind .t \x7f {puts hi}
5166
5167
5168
5169
5170
5171
5172
5173

5174
5175
5176

5177
5178

5179
5180
5181
5182

5183
5184
5185


5186
5187

5188
5189
5190
5191

5192
5193
5194


5195
5196

5197
5198
5199
5200

5201
5202
5203


5204
5205

5206
5207
5208
5209

5210
5211
5212


5213
5214

5215
5216
5217
5218

5219
5220
5221


5222
5223

5224
5225
5226
5227

5228
5229
5230


5231
5232

5233
5234
5235
5236

5237
5238
5239


5240
5241

5242
5243
5244
5245

5246
5247
5248


5249
5250

5251
5252
5253
5254

5255
5256
5257


5258
5259

5260
5261
5262
5263

5264
5265
5266


5267
5268

5269
5270
5271
5272

5273
5274
5275


5276
5277

5278
5279
5280
5281

5282
5283
5284


5285
5286

5287
5288
5289
5290

5291
5292
5293


5294
5295

5296
5297
5298
5299

5300
5301
5302


5303
5304

5305
5306
5307
5308

5309
5310
5311


5312
5313

5314
5315
5316
5317

5318
5319
5320


5321
5322

5323
5324
5325
5326

5327
5328
5329


5330
5331

5332
5333
5334
5335

5336
5337
5338


5339
5340

5341
5342
5343
5344

5345
5346
5347


5348
5349

5350
5351
5352
5353

5354
5355
5356


5357
5358

5359
5360
5361
5362

5363
5364
5365


5366
5367

5368
5369
5370
5371

5372
5373
5374


5375
5376

5377
5378
5379
5380

5381
5382
5383


5384
5385

5386
5387
5388
5389

5390
5391
5392


5393
5394

5395
5396
5397
5398

5399
5400
5401


5402
5403

5404
5405
5406
5407

5408
5409
5410


5411
5412

5413
5414
5415
5416

5417
5418
5419


5420
5421

5422
5423
5424
5425

5426
5427
5428


5429
5430

5431
5432
5433
5434

5435
5436
5437


5438
5439

5440
5441
5442
5443

5444
5445
5446


5447
5448

5449
5450
5451
5452

5453
5454
5455


5456
5457

5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516

5517
5518
5519
5520
5521

5522
5523
5524

5525
5526
5527
5528
5529

5530
5531
5532
5533
5534
5535
5536
5141
5142
5143
5144
5145
5146
5147

5148
5149
5150

5151
5152

5153
5154
5155
5156

5157
5158


5159
5160
5161

5162
5163
5164
5165

5166
5167


5168
5169
5170

5171
5172
5173
5174

5175
5176


5177
5178
5179

5180
5181
5182
5183

5184
5185


5186
5187
5188

5189
5190
5191
5192

5193
5194


5195
5196
5197

5198
5199
5200
5201

5202
5203


5204
5205
5206

5207
5208
5209
5210

5211
5212


5213
5214
5215

5216
5217
5218
5219

5220
5221


5222
5223
5224

5225
5226
5227
5228

5229
5230


5231
5232
5233

5234
5235
5236
5237

5238
5239


5240
5241
5242

5243
5244
5245
5246

5247
5248


5249
5250
5251

5252
5253
5254
5255

5256
5257


5258
5259
5260

5261
5262
5263
5264

5265
5266


5267
5268
5269

5270
5271
5272
5273

5274
5275


5276
5277
5278

5279
5280
5281
5282

5283
5284


5285
5286
5287

5288
5289
5290
5291

5292
5293


5294
5295
5296

5297
5298
5299
5300

5301
5302


5303
5304
5305

5306
5307
5308
5309

5310
5311


5312
5313
5314

5315
5316
5317
5318

5319
5320


5321
5322
5323

5324
5325
5326
5327

5328
5329


5330
5331
5332

5333
5334
5335
5336

5337
5338


5339
5340
5341

5342
5343
5344
5345

5346
5347


5348
5349
5350

5351
5352
5353
5354

5355
5356


5357
5358
5359

5360
5361
5362
5363

5364
5365


5366
5367
5368

5369
5370
5371
5372

5373
5374


5375
5376
5377

5378
5379
5380
5381

5382
5383


5384
5385
5386

5387
5388
5389
5390

5391
5392


5393
5394
5395

5396
5397
5398
5399

5400
5401


5402
5403
5404

5405
5406
5407
5408

5409
5410


5411
5412
5413

5414
5415
5416
5417

5418
5419


5420
5421
5422

5423
5424
5425
5426

5427
5428


5429
5430
5431

5432
5433
5434








5435








5436





































5437

5438
5439
5440
5441
5442

5443
5444
5445

5446
5447
5448
5449
5450

5451
5452
5453
5454
5455
5456
5457
5458







-
+


-
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+


-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+




-
+


-
+




-
+







test bind-25.17 {ParseEventDescription} -body {
    event add <<xyz>> <<abc>>
} -returnCodes error -result {virtual event not allowed in definition of another virtual event}

# Modifier canonicalization tests

test bind-25.18 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f {<Control- a>} foo
    bind .t.f
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Control-Key-a>

test bind-25.19 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Shift-a> foo
    bind .t.f
	bind .t.f <Shift-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Shift-Key-a>

test bind-25.20 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Lock-a> foo
    bind .t.f
	bind .t.f <Lock-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Lock-Key-a>

test bind-25.21 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Meta---a> foo
    bind .t.f
	bind .t.f <Meta---a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Meta-Key-a>

test bind-25.22 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Meta-a> foo
    bind .t.f
	bind .t.f <M-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Meta-Key-a>

test bind-25.23 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Alt-a> foo
    bind .t.f
	bind .t.f <Alt-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Alt-Key-a>

test bind-25.24 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <B1-a> foo
    bind .t.f
	bind .t.f <B1-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B1-Key-a>

test bind-25.25 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <B2-a> foo
    bind .t.f
	bind .t.f <B2-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B2-Key-a>

test bind-25.26 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <B3-a> foo
    bind .t.f
	bind .t.f <B3-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B3-Key-a>

test bind-25.27 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <B4-a> foo
    bind .t.f
	bind .t.f <B4-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B4-Key-a>

test bind-25.28 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <B5-a> foo
    bind .t.f
	bind .t.f <B5-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B5-Key-a>

test bind-25.29 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button1-a> foo
    bind .t.f
	bind .t.f <Button1-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B1-Key-a>

test bind-25.30 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button2-a> foo
    bind .t.f
	bind .t.f <Button2-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B2-Key-a>

test bind-25.31 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button3-a> foo
    bind .t.f
	bind .t.f <Button3-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B3-Key-a>

test bind-25.32 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button4-a> foo
    bind .t.f
	bind .t.f <Button4-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B4-Key-a>

test bind-25.33 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button5-a> foo
    bind .t.f
	bind .t.f <Button5-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <B5-Key-a>

test bind-25.34 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <M1-a> foo
    bind .t.f
	bind .t.f <M1-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod1-Key-a>

test bind-25.35 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <M2-a> foo
    bind .t.f
	bind .t.f <M2-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod2-Key-a>

test bind-25.36 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <M3-a> foo
    bind .t.f
	bind .t.f <M3-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod3-Key-a>

test bind-25.37 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <M4-a> foo
    bind .t.f
	bind .t.f <M4-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod4-Key-a>

test bind-25.38 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <M5-a> foo
    bind .t.f
	bind .t.f <M5-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod5-Key-a>

test bind-25.39 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Mod1-a> foo
    bind .t.f
	bind .t.f <Mod1-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod1-Key-a>

test bind-25.40 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Mod2-a> foo
    bind .t.f
	bind .t.f <Mod2-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod2-Key-a>

test bind-25.41 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Mod3-a> foo
    bind .t.f
	bind .t.f <Mod3-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod3-Key-a>

test bind-25.42 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Mod4-a> foo
    bind .t.f
	bind .t.f <Mod4-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod4-Key-a>

test bind-25.43 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Mod5-a> foo
    bind .t.f
	bind .t.f <Mod5-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Mod5-Key-a>

test bind-25.44 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Double-a> foo
    bind .t.f
	bind .t.f <Double-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Double-Key-a>

test bind-25.45 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Triple-a> foo
    bind .t.f
	bind .t.f <Triple-a> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Triple-Key-a>

test bind-25.46 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f {<Double 1>} foo
    bind .t.f
	bind .t.f {<Double 1>} foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Double-Button-1>

test bind-25.47 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Triple-1> foo
    bind .t.f
	bind .t.f <Triple-1> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Triple-Button-1>

test bind-25.48 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f {<M1-M2 M3-M4 B1-Control-a>} foo
    bind .t.f
	bind .t.f {<M1-M2 M3-M4 B1-Control-a>} foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Control-B1-Mod1-Mod2-Mod3-Mod4-Key-a>

test bind-25.49 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Extended-Return> foo
    bind .t.f
	bind .t.f <Extended-Return> foo
	bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <Extended-Key-Return>

test bind-25.50 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button6-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <B6-Key-a>

test bind-25.51 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button7-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <B7-Key-a>

test bind-25.52 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button8-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <B8-Key-a>

test bind-25.53 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Button9-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <B9-Key-a>

test bind-25.54 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Num-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Mod3-Key-a>

test bind-25.55 {modifier names} -setup {
    frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <Fn-a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Mod4-Key-a>


test bind-26.1 {event names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <FocusIn> {nothing}
    bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <FocusIn>
test bind-26.2 {event names} -setup {
    frame .t.f -class Test -width 150 -height 100
	frame .t.f -class Test -width 150 -height 100
} -body {
    bind .t.f <FocusOut> {nothing}
    bind .t.f
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result <FocusOut>
test bind-26.3 {event names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554




5555
5556

5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568




5569
5570

5571














5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582




5583
5584

5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596




5597
5598

5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610




5611
5612

5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624




5625
5626

5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638




5639
5640

5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652




5653
5654

5655














5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666




5667
5668

5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680




5681
5682

5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694




5695
5696

5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708




5709
5710

5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722




5723
5724

5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738




5739
5740

5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752




5753
5754

5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766




5767
5768

5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780




5781
5782

5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794




5795
5796

5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808




5809
5810

5811
5812
5813
5814
5815
5816
5817
5818
5819

5820
5821
5822
5823
5824
5825
5826
5466
5467
5468
5469
5470
5471
5472




5473
5474
5475
5476
5477

5478
5479
5480
5481
5482
5483
5484
5485
5486




5487
5488
5489
5490
5491

5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514




5515
5516
5517
5518
5519

5520
5521
5522
5523
5524
5525
5526
5527
5528




5529
5530
5531
5532
5533

5534
5535
5536
5537
5538
5539
5540
5541
5542




5543
5544
5545
5546
5547

5548
5549
5550
5551
5552
5553
5554
5555
5556




5557
5558
5559
5560
5561

5562
5563
5564
5565
5566
5567
5568
5569
5570




5571
5572
5573
5574
5575

5576
5577
5578
5579
5580
5581
5582
5583
5584




5585
5586
5587
5588
5589

5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612




5613
5614
5615
5616
5617

5618
5619
5620
5621
5622
5623
5624
5625
5626




5627
5628
5629
5630
5631

5632
5633
5634
5635
5636
5637
5638
5639
5640




5641
5642
5643
5644
5645

5646
5647
5648
5649
5650
5651
5652
5653
5654




5655
5656
5657
5658
5659

5660
5661
5662
5663
5664
5665
5666
5667
5668




5669
5670
5671
5672
5673

5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684




5685
5686
5687
5688
5689

5690
5691
5692
5693
5694
5695
5696
5697
5698




5699
5700
5701
5702
5703

5704
5705
5706
5707
5708
5709
5710
5711
5712




5713
5714
5715
5716
5717

5718
5719
5720
5721
5722
5723
5724
5725
5726




5727
5728
5729
5730
5731

5732
5733
5734
5735
5736
5737
5738
5739
5740




5741
5742
5743
5744
5745

5746
5747
5748
5749
5750
5751
5752
5753
5754




5755
5756
5757
5758
5759

5760
5761
5762
5763
5764
5765
5766
5767
5768

5769
5770
5771
5772
5773
5774
5775
5776







-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+










-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
-
-
-
+
+
+
+

-
+








-
+








test bind-26.4 {event names: Motion} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Motion> "set x {event Motion}"
    set x xyzzy
    event generate .t.f <Motion>
    list $x [bind .t.f]
	bind .t.f <Motion> "set x {event Motion}"
	set x xyzzy
	event generate .t.f <Motion>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Motion} <Motion>}

test bind-26.5 {event names: Button} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button> "set x {event Button}"
    set x xyzzy
    event generate .t.f <Button>
    list $x [bind .t.f]
	bind .t.f <Button> "set x {event Button}"
	set x xyzzy
	event generate .t.f <Button>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Button} <Button>}

test bind-26.6 {event names: ButtonPress} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
	bind .t.f <ButtonPress> "set x {event ButtonPress}"
	set x xyzzy
	event generate .t.f <ButtonPress>
	list $x [bind .t.f]
} -cleanup {
	destroy .t.f
} -result {{event ButtonPress} <Button>}

test bind-26.7 {event names: ButtonRelease} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <ButtonRelease> "set x {event ButtonRelease}"
    set x xyzzy
    event generate .t.f <ButtonRelease>
    list $x [bind .t.f]
	bind .t.f <ButtonRelease> "set x {event ButtonRelease}"
	set x xyzzy
	event generate .t.f <ButtonRelease>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event ButtonRelease} <ButtonRelease>}

test bind-26.8 {event names: Colormap} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Colormap> "set x {event Colormap}"
    set x xyzzy
    event generate .t.f <Colormap>
    list $x [bind .t.f]
	bind .t.f <Colormap> "set x {event Colormap}"
	set x xyzzy
	event generate .t.f <Colormap>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Colormap} <Colormap>}

test bind-26.9 {event names: Enter} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Enter> "set x {event Enter}"
    set x xyzzy
    event generate .t.f <Enter>
    list $x [bind .t.f]
	bind .t.f <Enter> "set x {event Enter}"
	set x xyzzy
	event generate .t.f <Enter>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Enter} <Enter>}

test bind-26.10 {event names: Leave} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Leave> "set x {event Leave}"
    set x xyzzy
    event generate .t.f <Leave>
    list $x [bind .t.f]
	bind .t.f <Leave> "set x {event Leave}"
	set x xyzzy
	event generate .t.f <Leave>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Leave} <Leave>}

test bind-26.11 {event names: Expose} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Expose> "set x {event Expose}"
    set x xyzzy
    event generate .t.f <Expose>
    list $x [bind .t.f]
	bind .t.f <Expose> "set x {event Expose}"
	set x xyzzy
	event generate .t.f <Expose>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Expose} <Expose>}

test bind-26.12 {event names: Key} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Key> "set x {event Key}"
    set x xyzzy
    event generate .t.f <Key>
    list $x [bind .t.f]
	bind .t.f <Key> "set x {event Key}"
	set x xyzzy
	event generate .t.f <Key>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Key} <Key>}

test bind-26.13 {event names: KeyPress} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
	bind .t.f <KeyPress> "set x {event KeyPress}"
	set x xyzzy
	event generate .t.f <KeyPress>
	list $x [bind .t.f]
} -cleanup {
	destroy .t.f
} -result {{event KeyPress} <Key>}

test bind-26.14 {event names: KeyRelease} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <KeyRelease> "set x {event KeyRelease}"
    set x xyzzy
    event generate .t.f <KeyRelease>
    list $x [bind .t.f]
	bind .t.f <KeyRelease> "set x {event KeyRelease}"
	set x xyzzy
	event generate .t.f <KeyRelease>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event KeyRelease} <KeyRelease>}

test bind-26.15 {event names: Property} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Property> "set x {event Property}"
    set x xyzzy
    event generate .t.f <Property>
    list $x [bind .t.f]
	bind .t.f <Property> "set x {event Property}"
	set x xyzzy
	event generate .t.f <Property>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Property} <Property>}

test bind-26.16 {event names: Visibility} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Visibility> "set x {event Visibility}"
    set x xyzzy
    event generate .t.f <Visibility>
    list $x [bind .t.f]
	bind .t.f <Visibility> "set x {event Visibility}"
	set x xyzzy
	event generate .t.f <Visibility>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Visibility} <Visibility>}

test bind-26.17 {event names: Activate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Activate> "set x {event Activate}"
    set x xyzzy
    event generate .t.f <Activate>
    list $x [bind .t.f]
	bind .t.f <Activate> "set x {event Activate}"
	set x xyzzy
	event generate .t.f <Activate>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Activate} <Activate>}

test bind-26.18 {event names: Deactivate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Deactivate> "set x {event Deactivate}"
    set x xyzzy
    event generate .t.f <Deactivate>
    list $x [bind .t.f]
	bind .t.f <Deactivate> "set x {event Deactivate}"
	set x xyzzy
	event generate .t.f <Deactivate>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Deactivate} <Deactivate>}


# These events require an extra argument to [event generate]
test bind-26.19 {event names: Circulate} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Circulate> "set x {event Circulate}"
    set x xyzzy
    event generate .t.f <Circulate>
    list $x [bind .t.f]
	bind .t.f <Circulate> "set x {event Circulate}"
	set x xyzzy
	event generate .t.f <Circulate>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Circulate} <Circulate>}

test bind-26.20 {event names: Configure} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Configure> "set x {event Configure}"
    set x xyzzy
    event generate .t.f <Configure>
    list $x [bind .t.f]
	bind .t.f <Configure> "set x {event Configure}"
	set x xyzzy
	event generate .t.f <Configure>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Configure} <Configure>}

test bind-26.21 {event names: Gravity} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Gravity> "set x {event Gravity}"
    set x xyzzy
    event generate .t.f <Gravity>
    list $x [bind .t.f]
	bind .t.f <Gravity> "set x {event Gravity}"
	set x xyzzy
	event generate .t.f <Gravity>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Gravity} <Gravity>}

test bind-26.22 {event names: Map} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Map> "set x {event Map}"
    set x xyzzy
    event generate .t.f <Map>
    list $x [bind .t.f]
	bind .t.f <Map> "set x {event Map}"
	set x xyzzy
	event generate .t.f <Map>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Map} <Map>}

test bind-26.23 {event names: Reparent} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Reparent> "set x {event Reparent}"
    set x xyzzy
    event generate .t.f <Reparent>
    list $x [bind .t.f]
	bind .t.f <Reparent> "set x {event Reparent}"
	set x xyzzy
	event generate .t.f <Reparent>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Reparent} <Reparent>}

test bind-26.24 {event names: Unmap} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Unmap> "set x {event Unmap}"
    set x xyzzy
    event generate .t.f <Unmap>
    list $x [bind .t.f]
	bind .t.f <Unmap> "set x {event Unmap}"
	set x xyzzy
	event generate .t.f <Unmap>
	list $x [bind .t.f]
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {{event Unmap} <Unmap>}


test bind-27.1 {button names} -body {
    bind .t <Expose-1> foo
} -returnCodes error -result {specified button "1" for non-button event}
test bind-27.2 {button names} -body {
    bind .t <Button-10> foo
} -returnCodes error -result {bad button number "10"}
} -returnCodes error -result {bad event type or keysym "10"}
test bind-27.3 {button names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Button-1> {lappend x "button 1"}
5947
5948
5949
5950
5951
5952
5953
5954

5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971


5972
5973

5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985


5986
5987

5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999


6000
6001

6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013


6014
6015

6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071

6072
6073
6074
6075
6076
6077
6078
5897
5898
5899
5900
5901
5902
5903

5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919


5920
5921
5922

5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933


5934
5935
5936

5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947


5948
5949
5950

5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961


5962
5963
5964

5965
5966
5967
5968
5969

















































5970
5971

5972
5973
5974
5975
5976
5977
5978
5979







-
+















-
-
+
+

-
+










-
-
+
+

-
+










-
-
+
+

-
+










-
-
+
+

-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+







test bind-28.1 {keysym names} -body {
    bind .t <Expose-a> foo
} -returnCodes error -result {specified keysym "a" for non-key event}
test bind-28.2 {keysym names} -body {
    bind .t <Gorp> foo
} -returnCodes error -result {bad event type or keysym "Gorp"}
test bind-28.3 {keysym names} -body {
    bind .t <Stupid> foo
    bind .t <Key-Stupid> foo
} -returnCodes error -result {bad event type or keysym "Stupid"}
test bind-28.4 {keysym names} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <a> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result {a}

test bind-28.5 {keysym names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <:> "lappend x \"keysym received\""
    bind .t.f <_> "lappend x {bad binding match}"
    bind .t.f <Key-colon> "lappend x \"keysym received\""
    bind .t.f <Key-underscore> "lappend x {bad binding match}"
    set x [lsort [bind .t.f]]
    event generate .t.f <:> ;# -state 0
    event generate .t.f <Key-colon> ;# -state 0
    set x
} -cleanup {
    destroy .t.f
} -result {: _ {keysym received}}
test bind-28.6 {keysym names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <Return> "lappend x \"keysym Return\""
    bind .t.f <x> "lappend x {bad binding match}"
    bind .t.f <Key-Return> "lappend x \"keysym Return\""
    bind .t.f <Key-x> "lappend x {bad binding match}"
    set x [lsort [bind .t.f]]
    event generate .t.f <Return> -state 0
    event generate .t.f <Key-Return> -state 0
    set x
} -cleanup {
    destroy .t.f
} -result {<Key-Return> x {keysym Return}}
test bind-28.7 {keysym names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <X> "lappend x \"keysym X\""
    bind .t.f <x> "lappend x {bad binding match}"
    bind .t.f <Key-X> "lappend x \"keysym X\""
    bind .t.f <Key-x> "lappend x {bad binding match}"
    set x [lsort [bind .t.f]]
    event generate .t.f <X> -state 1
    event generate .t.f <Key-X> -state 1
    set x
} -cleanup {
    destroy .t.f
} -result {X x {keysym X}}
test bind-28.8 {keysym names} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
} -body {
    bind .t.f <X> "lappend x \"keysym X\""
    bind .t.f <x> "lappend x {bad binding match}"
    bind .t.f <Key-X> "lappend x \"keysym X\""
    bind .t.f <Key-x> "lappend x {bad binding match}"
    set x [lsort [bind .t.f]]
    event generate .t.f <X> -state 1
    event generate .t.f <Key-X> -state 1
    set x
} -cleanup {
    destroy .t.f
} -result {X x {keysym X}}
test bind-28.9 {keysym names, Ð} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <Ð> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Key-Ð>
test bind-28.10 {keysym names, Ø} -constraints deprecated -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <Ø> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Key-Ø>
test bind-28.11 {keysym names, gcedilla} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <gcedilla> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Key-gcedilla>
test bind-28.12 {keysym names, Greek_IOTAdiaeresis -> Greek_IOTAdieresis} -constraints deprecated -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <Greek_IOTAdiaeresis> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result <Key-Greek_IOTAdieresis>
test bind-28.13 {keysym names, Unicode} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <€> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result "<Key-€>"
test bind-28.14 {keysym names, Emoji} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <\U1F44D> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result "<Key-\U1F44D>"
test bind-28.15 {keysym names, Emoji} -body {
    frame .t.f -class Test -width 150 -height 100
    bind .t.f <👍> foo
    bind .t.f
} -cleanup {
    destroy .t.f
} -result "<Key-👍>"


test bind-29.1 {Tcl_BackgroundError procedure} -setup {
test bind-29.1 {Tk_BackgroundError procedure} -setup {
    proc bgerror msg {
        global x errorInfo
        set x [list $msg $errorInfo]
    }
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
6088
6089
6090
6091
6092
6093
6094
6095

6096
6097
6098
6099
6100
6101
6102
5989
5990
5991
5992
5993
5994
5995

5996
5997
5998
5999
6000
6001
6002
6003







-
+







    destroy .t.f
    rename bgerror {}
} -result {{This is a test} {This is a test
    while executing
"error "This is a test""
    (command bound to event)}}

test bind-29.2 {Tcl_BackgroundError procedure} -setup {
test bind-29.2 {Tk_BackgroundError procedure} -setup {
    proc do {} {
        event generate .t.f <Button>
        event generate .t.f <ButtonRelease>
    }
    proc bgerror msg {
        global x errorInfo
        set x [list $msg $errorInfo]
6142
6143
6144
6145
6146
6147
6148
6149

6150
6151
6152
6153
6154
6155
6156
6043
6044
6045
6046
6047
6048
6049

6050
6051
6052
6053
6054
6055
6056
6057







-
+







    set x {}
} -body {
    bind .t.f <MouseWheel> {set x %D}
    event generate .t.f <MouseWheel> -delta 120
    set x
} -cleanup {
    destroy .t.f
} -result 120
} -result {120}
test bind-30.3 {MouseWheel events} -setup {
    frame .t.f -class Test -width 150 -height 100
    pack .t.f
    focus -force .t.f
    update
    set x {}
} -body {
6252
6253
6254
6255
6256
6257
6258
6259

6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288

6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
6153
6154
6155
6156
6157
6158
6159

6160


6161
6162
6163
6164
6165
6166

6167
6168
6169
6170
6171















6172













































































































































































































































































































































































































































































































































































































































































































































































































































6173
6174
6175
6176
6177

6178
6179
6180







-
+
-
-






-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-



    bind .t.f <<TestUserData>> {set x "TestUserData >%d<"}
    event generate .t.f <<TestUserData>> -data [string index abc 1] -when head
    list $x [update] $x
} -cleanup {
    destroy .t.f
} -result {{} {} {TestUserData >b<}}

test bind-32.1 {-warp, window was destroyed before the idle callback DoWarp} -setup {
test bind-32 {-warp, window was destroyed before the idle callback DoWarp} -setup {
    # note: this test is now essentially useless
    #       since DoWarp no longer exist, not even as an idle callback
    frame .t.f
    pack .t.f
    focus -force .t.f
    update
} -body {
    event generate .t.f <Button-1> -warp 1
    controlPointerWarpTiming
    event generate .t.f <ButtonRelease-1>
    destroy .t.f
    update  ;  # shall simply not crash
} -cleanup {
} -result {}
test bind-32.2 {detection of double click should not fail} -setup {
    pack [frame .t.f]
    focus -force .t.f
    bind .t.f <Double-Button-1> { set x "Double" }
    update
    set x {}
} -body {
    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    # Simulate a lot of intervening exposure events. The old implementation
    # that used an event ring overflowed, and the double click was not detected.
    # But new implementation should work properly.
    for {set i 0} {$i < 1000} {incr i} {
        event generate .t.f <Expose>
    }

    event generate .t.f <Button-1>
    event generate .t.f <ButtonRelease-1>
    set x
} -cleanup {
    destroy .t.f
} -result {Double}
test bind-32.3 {should trigger best match of modifier states} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Alt-Control-A> { lappend x "Alt-Control" }
    bind .t.f <Shift-Control-A> { lappend x "Shift-Control" }
    bind .t.f <Shift-A> { lappend x "Shift" }
    event generate .t.f <Alt-Control-A>
    set x
} -cleanup {
    destroy .t.f
} -result {Shift-Control}
test bind-32.4 {should not trigger Double-1} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-Button-1> { set x "Double" }
    event generate .t.f <Button-1> -time current
    after 1000
    event generate .t.f <Button-1> -time current
    set x
} -cleanup {
    destroy .t.f
} -result {}
test bind-32.5 {should trigger Quadruple-1} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Quadruple-Button-1> { set x "Quadruple" }
    bind .t.f <Triple-Button-1> { set x "Triple" }
    bind .t.f <Double-Button-1> { set x "Double" }
    bind .t.f <Button-1> { set x "Single" }
    # Old implementation triggered "Double", but new implementation
    # triggers "Quadruple", the latter behavior conforms to other toolkits.
    event generate .t.f <Button-1> -time 0
    event generate .t.f <Button-1> -time 400
    event generate .t.f <Button-1> -time 800
    event generate .t.f <Button-1> -time 1200
    set x
} -cleanup {
    destroy .t.f
} -result {Quadruple}
test bind-32.6 {problem with sendevent} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    # Old implementation was losing sendevent value
    bind .t.f <FocusIn> { set x "sendevent=%E" }
    event generate .t.f <FocusIn> -sendevent 1
    set x
} -cleanup {
    destroy .t.f
} -result {sendevent=1}
test bind-32.7 {test sequences} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-Button-1> { lappend x "Double" }
    bind .t.f <Button-1><Button-1><a> { lappend x "11" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result {Double 11}
test bind-32.8 {test sequences} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Button-1><Double-Button-1><Button-1><a> { lappend x "Double" }
    event generate .t.f <a>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result {Double}
test bind-32.9 {trigger events for modifier keys} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key> { set x "Key" }
    event generate .t.f <Key> -keysym Caps_Lock
    set x
} -cleanup {
    destroy .t.f
} -result {Key}
test bind-32.10 {reset key state when destroying window} -setup {
    set x {}
} -body {
    pack [frame .t.f]; update; focus -force .t.f
    bind .t.f <A> { set x "A" }
    event generate .t.f <A>
    event generate .t.f <A>
    destroy .t.f; update
    pack [frame .t.f]; update; focus -force .t.f
    bind .t.f <A> { set x "A" }
    bind .t.f <Double-A> { set x "AA" }
    event generate .t.f <A>
    destroy .t.f
    set x
} -result {A}
test bind-32.11 {match detailed virtual} -setup {
    pack [frame .t.f -class Test]
    focus -force .t.f
    update
    set x {}
} -body {
    event add <<TestControlButton1>> <Control-Button-1>
    bind Test <<TestControlButton1>> { set x "Control-Button-1" }
    bind Test <Button-1> { set x "Button-1" }
    bind .t.f <Button-1> { set x "Button-1" }
    event generate .t.f <Control-Button-1>
    set x
} -cleanup {
    destroy .t.f
    event delete <<TestControlButton1>>
    bind Test <Button-1> {#}
} -result {Control-Button-1}
test bind-32.12 {don't detect repetition when window has changed} -setup {
    pack [frame .t.f]
    pack [frame .t.g]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1> { set x "1" }
    bind .t.f <Double-Button-1> { set x "11" }
    event generate .t.f <Button-1>
    event generate .t.g <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
    destroy .t.g
} -result 1
test bind-32.13 {don't detect repetition when window has changed} -setup {
    pack [frame .t.f]
    pack [frame .t.g]
    update
    set x {}
} -body {
    bind .t.f <A> { set x "A" }
    bind .t.f <Double-A> { set x "AA" }
    focus -force .t.f; event generate .t.f <A>
    focus -force .t.g; event generate .t.g <A>
    focus -force .t.f; event generate .t.f <A>
    set x
} -cleanup {
    destroy .t.f
    destroy .t.g
} -result {A}
test bind-32.14 {don't detect repetition when window has changed} -setup {
    pack [frame .t.f]
    pack [frame .t.g]
    update
    set x {}
} -body {
    bind .t.f <Button-1> { set x "1" }
    bind .t.f <Double-Button-1> { set x "11" }
    focus -force .t.f; event generate .t.f <Button-1>
    focus -force .t.g; event generate .t.g <Button-1>
    focus -force .t.f; event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
    destroy .t.g
} -result 1
test bind-32.15 {reset button state when destroying window} -setup {
    set x {}
} -body {
    pack [frame .t.f]; update; focus -force .t.f
    bind .t.f <Button-1> { set x "1" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    destroy .t.f; update
    pack [frame .t.f]; update; focus -force .t.f
    bind .t.f <Button-1> { set x "1" }
    bind .t.f <Double-Button-1> { set x "11" }
    event generate .t.f <Button-1>
    destroy .t.f
    set x
} -result 1

test bind-33.1 {prefer longest match} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Button-1><Button-1> { lappend x "a11" }
    bind .t.f <Double-Button-1> { lappend x "Double" }
    event generate .t.f <a>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result {a11}
test bind-33.2 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-Button-1> { lappend x "Double" }
    bind .t.f <Button-1><Button-1> { lappend x "11" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result Double
test bind-33.3 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Double-Button-1><a> { lappend x "Double" }
    bind .t.f <a><Button-1><Button-1><a> { lappend x "11" }
    event generate .t.f <a>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result Double
test bind-33.4 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Button-1> { lappend x "11" }
    bind .t.f <Double-Button-1> { lappend x "Double" }
    event generate .t.f <Button-1> -time 0
    event generate .t.f <Button-1> -time 1000
    set x
} -cleanup {
    destroy .t.f
} -result 11
test bind-33.5 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Button-1> { lappend x "11" }
    bind .t.f <Double-Button> { lappend x "Double" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result 11
test bind-33.6 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <a><Button-1><Button-1><Button-1><Button-1><a> { lappend x "1111" }
    bind .t.f <a><Button><Double-Button><Button><a> { lappend x "Any-Double-Any" }
    event generate .t.f <a>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result 1111
test bind-33.7 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><a> { lappend x "1" }
    bind .t.f <Button><a> { lappend x "Any" }
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result 1
test bind-33.8 {prefer most specific event} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Double-Button-1><a> { lappend x "1" }
    bind .t.f <Button><Button><a> { lappend x "Any" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <a>
    set x
} -cleanup {
    destroy .t.f
} -result 1
test bind-33.9 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Button-2><Button-2><Double-Button-1> { lappend x "first" }
    bind .t.f <Button-1><Double-Button-2><Button-1><Button-1> { lappend x "last" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-2>
    event generate .t.f <Button-2>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result last
test bind-33.10 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Double-Button-2><Button-1><Button-1> { lappend x "first" }
    bind .t.f <Button-1><Button-2><Button-2><Double-Button-1> { lappend x "last" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-2>
    event generate .t.f <Button-2>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result last
test bind-33.11 {should prefer most specific} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-2><Double-Button-1><Double-Button-2><Double-Button-1><Button-2><Button-2> { lappend x "first" }
    bind .t.f <Button-2><Button-1><Button-1><Button-2><Button-2><Double-Button-1><Double-Button-2> { lappend x "last" }
    event generate .t.f <Button-2>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-2>
    event generate .t.f <Button-2>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-2>
    event generate .t.f <Button-2>
    set x
} -cleanup {
    destroy .t.f
} -result first
test bind-33.12 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Control-Button-1><Button-1> { lappend x "first" }
    bind .t.f <Button-1><Control-Button-1> { lappend x "last" }
    event generate .t.f <Control-Button-1>
    event generate .t.f <Control-Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result last
test bind-33.13 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Control-Button-1> { lappend x "first" }
    bind .t.f <Control-Button-1><Button-1> { lappend x "last" }
    event generate .t.f <Control-Button-1>
    event generate .t.f <Control-Button-1>
    set x
} -cleanup {
    destroy .t.f
    # Old implementation failed, and returned "first", but this was wrong,
    # because both bindings are homogeneous equal, so the most recently defined
    # must be preferred.
} -result last
test bind-33.14 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button-1><Button><Button-1><Button> { lappend x "first" }
    bind .t.f <Button><Button-1><Button><Button-1> { lappend x "last" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result last
test bind-33.15 {prefer last in case of homogeneous equal patterns} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Button><Button-1><Button><Button-1> { lappend x "first" }
    bind .t.f <Button-1><Button><Button-1><Button> { lappend x "last" }
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
    # Old implementation failed, and returned "first", but this was wrong,
    # because both bindings are homogeneous equal, so the most recently defined
    # must be preferred.
} -result last
test bind-33.16 {simulate use of the keyboard to trigger a pattern sequence with modifier - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Escape><Control-c> { lappend x "Esc_Control-c" }
    event generate .t.f <Escape>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control-c>
    set x
} -cleanup {
    destroy .t.f
} -result {Esc_Control-c}
test bind-33.17 {simulate use of the keyboard to trigger a pattern sequence with modifier - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Escape><Control-c> { lappend x "Esc_Control-c" }
    bind .t.f <Escape><Control_L><Control-c> { lappend x "Esc_Ctrl_L_Control-c" }
    event generate .t.f <Escape>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control-c>
    set x
} -cleanup {
    destroy .t.f
} -result {Esc_Ctrl_L_Control-c}
test bind-33.18 {simulate use of the keyboard to trigger a pattern sequence with modifier - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Escape><Control-c> { lappend x "Esc_Control-c" }
    bind .t.f <Escape><Control_L><Control-c> { lappend x "Esc_Ctrl_L_Control-c" }
    bind .t.f <Escape><Control_L><Control_L><Control-c> { lappend x "Esc_Ctrl_L(2)_Control-c" }
    event generate .t.f <Escape>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control-c>
    set x
} -cleanup {
    destroy .t.f
} -result {Esc_Ctrl_L(2)_Control-c}
test bind-33.19 {simulate use of the keyboard to trigger a pattern sequence with modifier - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Escape><Control-c> { lappend x "Esc_Control-c" }
    bind .t.f <Escape><Key><Key><Control-c> { lappend x "Esc_Key(2)_Control-c" }
    event generate .t.f <Escape>
    event generate .t.f <Alt_L>
    event generate .t.f <Control_L>
    event generate .t.f <Control-c>
    set x
} -cleanup {
    destroy .t.f
} -result {Esc_Key(2)_Control-c}
test bind-33.20 {simulate use of the keyboard to trigger a pattern sequence with mixed Key and Button types - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key-1><Button-1> { lappend x "1_Button1" }
    event generate .t.f <Key-1>
    event generate .t.f <KeyRelease-1>
    event generate .t.f <Button-1>
    set x
} -cleanup {
    destroy .t.f
} -result {1_Button1}
test bind-33.21 {simulate use of the keyboard to trigger a pattern sequence with mixed Key and Button types - bug [16ef161925]} -setup {
    pack [frame .t.f]
    focus -force .t.f
    update
    set x {}
} -body {
    bind .t.f <Key-1><Button-1> { lappend x "1_Button1" }
    bind .t.f <Key-1><Button-1><Key-2> { lappend x "1_Button1_2" }
    event generate .t.f <Key-1>
    event generate .t.f <KeyRelease-1>
    event generate .t.f <Button-1>
    event generate .t.f <Key-2>
    event generate .t.f <KeyRelease-2>
    set x
} -cleanup {
    destroy .t.f
} -result {1_Button1 1_Button1_2}

test bind-34.1 {-warp works relatively to a window} -setup {
    toplevel .top
    wm geometry .top +100+100
    after 10 ; update
} -body {
    # In order to avoid platform-dependent coordinate results due to
    # decorations and borders, this test warps the pointer twice
    # relatively to a window that moved in the meantime, and checks
    # how much the pointer moved
    wm geometry .top +200+200
    after 10 ; update
    event generate .top <Motion> -x 20 -y 20 -warp 1
    controlPointerWarpTiming
    set pointerPos1 [winfo pointerxy .top]
    wm geometry .top +600+600
    after 10 ; update
    event generate .top <Motion> -x 20 -y 20 -warp 1
    controlPointerWarpTiming
    set pointerPos2 [winfo pointerxy .top]
    # from the first warped position to the second one, the mouse
    # pointer should have moved the same amount as the window moved
    set res 1
    foreach pos1 $pointerPos1 pos2 $pointerPos2 {
        if {$pos1 != [expr {$pos2 - 400}]} {
            set res [list $pointerPos1 $pointerPos2]
        }
    }
    set res
} -cleanup {
    destroy .top
} -result 1
test bind-34.2 {-warp works relatively to the screen} -setup {
} -body {
    # Contrary to bind-34.1, we're directly checking screen coordinates
    event generate {} <Motion> -x 20 -y 20 -warp 1
    controlPointerWarpTiming
    set res [winfo pointerxy .]
    event generate {} <Motion> -x 200 -y 200 -warp 1
    controlPointerWarpTiming
    lappend res {*}[winfo pointerxy .]
} -cleanup {
} -result {20 20 200 200}
test bind-34.3 {-warp works with null or negative coordinates} -setup {
    # On some OS/WM, at least Linux with KDE, the "Screen edges" feature
    # provides hot spots that can be associated with some action.
    # When activated, the WM will not allow warping to happen on top of
    # a hot spot (which would trigger the corresponding action as an
    # unwanted effect) but will warp the pointer to the hot spot limit only.
    if {[tk windowingsystem] eq "x11"} {
        set halo 1
    } else {
        set halo 0
    }
    set res {}
} -body {
    event generate {} <Motion> -x 0 -y 0 -warp 1
    controlPointerWarpTiming
    foreach dim [winfo pointerxy .] {
        if {$dim <= $halo} {
            lappend res ok
        } else {
            lappend res $dim
        }
    }
    event generate {} <Motion> -x 100 -y 100 -warp 1
    controlPointerWarpTiming
    event generate {} <Motion> -x -1 -y -1 -warp 1
    controlPointerWarpTiming
    foreach dim [winfo pointerxy .] {
        if {$dim <= $halo} {
            lappend res ok
        } else {
            lappend res $dim
        }
    }
    set res
} -cleanup {
} -result {ok ok ok ok}

set keyInfo {}
set numericKeysym {}
proc testKey {window event type mods} {
    global keyInfo numericKeysym
    set keyInfo {}
    set numericKeysym {}
    bind $window <Key> {
	set keyInfo [format "%K,0x%%X,0x%%X,%A" %N %k]
	set numericKeysym %N
    }
    focus -force $window
    update
    event generate $window $event
    if {$keyInfo == {}} {
        vwait keyInfo
    }
    set save $keyInfo
    set keyInfo {}
    set injectcmd [list injectkeyevent $type $numericKeysym]
    foreach {option} $mods {
	lappend injectcmd $option
    }
    eval $injectcmd
    if {$keyInfo == {}} {
        vwait keyInfo
    }
    if {$save != $keyInfo} {
	return "[format "0x%x" $numericKeysym] ($mods): $save != $keyInfo"
    }
    return pass
}
proc testKeyWithMods {window keysym type} {
    set result [testKey $window "<$keysym>" $type {}]
    if {$result != {pass}} {
	return $result
    }
    set result [testKey $window "<Shift-$keysym>" $type {-shift}]
    if {$result != {pass}} {
	return $result
    }
    set result [testKey $window "<Option-$keysym>" $type {-option}]
    if {$result != {pass}} {
	return $result
    }
    set result [testKey $window "<Shift-Option-$keysym>" $type {-shift -option}]
    if {$result != {pass}} {
	return $result
    }
    return pass
}
test bind-35.0 {Generated and real key events agree} -constraints {aqua} -body {
    foreach k {o O F2 Home Right Greek_sigma Greek_ALPHA} {
	set result [testKeyWithMods . $k press]
	if {$result != "pass"} {
	    return $result
	}
    }
    return pass
} -cleanup {
} -result pass

test bind-35.1 {Key events agree for entry widgets} -constraints {aqua} -setup {
    toplevel .new
    entry .new.e
    pack .new.e
} -body {
    foreach k {o O F2 Home Right Greek_sigma Greek_ALPHA Menu} {
	set result [testKeyWithMods .new.e $k press]
	if {$result != "pass"} {
	    return $result
	}
    }
    return pass
} -cleanup {
    destroy .new.e
    destroy .new
} -result pass

test bind-35.2 {Can bind to function keys} -constraints {aqua} -body {
    global keyInfo numericKeysym
    bind . <Key> {}
    bind . <Key> {
	lappend keyInfo %K
	set numericKeysym %N
    }
    set keyInfo {}
    set numericKeysym {}
    focus -force .
    event generate . <F2>
    injectkeyevent press $numericKeysym -function
    vwait keyInfo
    return $keyInfo
} -cleanup {
} -result {F2 F2}

test bind-35.3 {Events agree for modifier keys} -constraints {aqua} -setup {
} -body {
    global keyInfo numericalKeysym
    set result {}
    bind . <Key> {
	set keyInfo [format "%K,0x%%X,0x%%X,%A" %N %k]
	set numericalKeysym [format "0x%x" %N]
    }
    foreach event {
	{<Control_L> -control}
	{<Control_R> -control}
	{<Alt_L> -option}
	{<Alt_R> -option}
	{<Meta_L> -command}
	{<Meta_R> -command}
	{<Shift_L> -shift}
	{<Shift_R> -shift}
    } {
	set keyInfo {}
	event generate . [lindex $event 0]
	if {$keyInfo == {}} {
	    vwait keyInfo
	}
	set save $keyInfo
	injectkeyevent flagschanged $numericKeysym [lindex $event 1]
	if {$keyInfo == {}} {
	    vwait keyInfo
	}
	if {$save != $keyInfo} {
	    return "$save != $keyInfo"
	}
    }
    return pass
} -cleanup {
} -result pass

test bind-36.1 {pointer warp with grab on toplevel, bug [e3888d5820]} -setup {
    event generate {} <Motion> -warp 1 -x 50 -y 50
    controlPointerWarpTiming
    toplevel .top
    grab release .top
    wm geometry .top 200x200+300+300
    label .top.l -height 5 -width 20 -highlightthickness 2 \
            -highlightbackground black -bg yellow -text "My label"
    pack .top.l -side bottom
    update
    # On KDE/Plasma _with_the_Aurorae_theme_ (at least), setting up the toplevel
    # and the label will not be finished after the above 'update'. The WM still
    # needs some time before the window is fully ready. For me 50 ms is enough,
    # but let's wait more (it depends on computer performance).
    after 100 ; update
} -body {
    grab .top
    event generate .top.l <Motion> -warp 1 -x 10 -y 10
    controlPointerWarpTiming
    foreach {x1 y1} [winfo pointerxy .top.l] {}
    event generate {} <Motion> -warp 1 -x 50 -y 50
    controlPointerWarpTiming
    grab release .top
    event generate .top.l <Motion> -warp 1 -x 10 -y 10
    controlPointerWarpTiming
    foreach {x2 y2} [winfo pointerxy .top.l] {}
    # success if the coords are the same with or without the grab, and if they
    # are at (10,10) inside the label widget as requested by the warping
    expr {$x1==$x2 && $y1==$y2 && $x1==[winfo rootx .top.l]+10 \
                               && $y1==[winfo rooty .top.l]+10}
} -cleanup {
    destroy .top
    unset x1 y1 x2 y2
} -result 1

test bind-37.1 {Promotion tables do not contain duplicate sequences, bug [43573999ca]} -body {
    proc A {} {
       bind .c <B1-Motion><Enter> {}
       set myv(a) 1
       set b [array get myv]
       bind .c <B1-Motion><Enter> "puts Trigger"
    }
    pack [canvas .c]
    bind .c <ButtonRelease-1>  "A"
    A
    update
    event generate .c <Button-1>
    event generate .c <B1-Motion>
    event generate .c <B1-Motion>
    event generate .c <B1-Motion>
    event generate .c <ButtonRelease-1>
    event generate .c <B1-Motion>
} -cleanup {
    destroy .c
} -returnCodes ok -result {}  ; # shall not crash (assertion failed)

# cleanup
cleanupTests
return

# vi:set ts=4 sw=4 et:
# Local Variables:
# mode: tcl
# End:

Changes to tests/bitmap.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in the file
# tkBitmap.c.  It is organized in the standard white-box fashion for
# Tcl tests.
#
# Copyright © 1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Changes to tests/border.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test out the procedures in the file
# tkBorder.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Added tests/bugs.tcl.










































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# This file is a Tcl script to test out various known bugs that will
# cause Tk to crash.  This file ends with .tcl instead of .test to make
# sure it isn't run when you type "source all".  We currently are not
# shipping this file with the rest of the source release.
#
# Copyright (c) 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.

if {[info procs test] != "test"} {
    source defs
}

test crash-1.0 {imgPhoto} {
    image create photo p1
    image create photo p2
    catch {image create photo p2 -file bogus}
    p1 copy p2
    label .l -image p1
    destroy .l
    set foo ""
} {}

test crash-1.1 {color} {
    . configure -bg rgb:345
    set foo ""
} {}













Changes to tests/busy.test.

1
2
3
4
5
6
7

8
9

10
11
12
13
14
15
16
17
18
19
20

21
22
23
24

25
26

27
28
29
30
31

32
33

34
35
36
37
38

39
40
41
42

43
44
45
46
47
48

49
50
51
52

53
54
55
56
57
58

59
60
61
62

63
64
65
66
67
68

69
70
71
72

73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88

89
90
91
92
93

94
95

96
97
98
99
100

101
102
103
104

105
106
107
108
109
110

111
112
113
114
115
116

117
118
119
120
121
122

123
124
125
126
127
128
129
1
2
3
4
5
6

7
8

9
10
11
12
13
14
15
16
17
18
19

20
21
22
23

24
25

26
27

28
29

30
31

32
33

34
35

36
37
38
39

40
41

42
43
44

45
46
47
48

49
50

51
52
53

54
55
56
57

58
59

60
61
62

63
64
65
66

67
68

69
70
71

72
73
74
75
76
77
78
79
80
81

82
83

84
85

86
87

88
89

90
91

92
93
94
95

96
97
98
99
100
101

102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119
120
121






-
+

-
+










-
+



-
+

-
+

-


-
+

-
+

-


-
+



-
+

-



-
+



-
+

-



-
+



-
+

-



-
+



-
+

-



-
+









-
+

-


-
+

-
+

-


-
+



-
+





-
+





-
+





-
+







# Tests for the tk busy command.
#
# This file contains a collection of tests for one or more of the Tk built-in
# commands. Sourcing this file runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright © 1998-2000 Jos Decoster. All rights reserved.
# Copyright (c) 1998-2000 by Jos Decoster. All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
tcltest::configure {*}$argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# There's currently no way to test the actual grab effect, per se, in an
# automated test. Therefore, this test suite only covers the interface to the
# grab command (ie, error messages, etc.)

test busy-1.1 {Tk_BusyObjCmd} -returnCodes error -body {
    tk busy
} -result {wrong # args: should be "tk busy options ?arg ...?"}
} -result {wrong # args: should be "tk busy options ?arg arg ...?"}

test busy-2.1 {tk busy hold} -returnCodes error -body {
    tk busy hold
} -result {wrong # args: should be "tk busy hold window ?-option value ...?"}
} -result {wrong # args: should be "tk busy hold window ?option value ...?"}
test busy-2.2 {tk busy hold root window} -body {
    set res [tk busy hold .]
    tk busy hold .
    update
    set res
} -cleanup {
    tk busy forget .
} -result {._Busy}
} -result {}
test busy-2.3 {tk busy hold root window with shortcut} -body {
    set res [tk busy .]
    tk busy .
    update
    set res
} -cleanup {
    tk busy forget .
} -result {._Busy}
} -result {}
test busy-2.4 {tk busy hold nested window} -setup {
    pack [frame .f]
} -body {
    set res [tk busy hold .f]
    tk busy hold .f
    update
    set res
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {.f_Busy}
} -result {}
test busy-2.5 {tk busy hold nested window with shortcut} -setup {
    pack [frame .f]
} -body {
    set res [tk busy .f]
    tk busy .f
    update
    set res
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {.f_Busy}
} -result {}
test busy-2.6 {tk busy hold toplevel window} -setup {
    toplevel .f
} -body {
    set res [tk busy hold .f]
    tk busy hold .f
    update
    set res
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {.f._Busy}
} -result {}
test busy-2.7 {tk busy hold toplevel window with shortcut} -setup {
    toplevel .f
} -body {
    set res [tk busy .f]
    tk busy .f
    update
    set res
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {.f._Busy}
} -result {}
test busy-2.8 {tk busy hold non existing window} -body {
    tk busy hold .f
    update
} -returnCodes error -result {bad window path name ".f"}
test busy-2.9 {tk busy hold (shortcut) non existing window} -body {
    tk busy .f
    update
} -returnCodes {error} -result {bad window path name ".f"}
test busy-2.10 {tk busy hold root window with cursor} -body {
    set res [tk busy hold . -cursor arrow]
    tk busy hold . -cursor arrow
    update
    set res
} -cleanup {
    tk busy forget .
} -result {._Busy}
} -result {}
test busy-2.11 {tk busy hold (shortcut) root window, cursor} -body {
    set res [tk busy . -cursor arrow]
    tk busy . -cursor arrow
    update
    set res
} -cleanup {
    tk busy forget .
} -result {._Busy}
} -result {}
test busy-2.12 {tk busy hold root window, invalid cursor} -body {
    tk busy hold . -cursor nonExistingCursor
    update
} -returnCodes error -cleanup {
} -constraints tempNotMac -returnCodes error -cleanup {
    tk busy forget .
} -result {bad cursor spec "nonExistingCursor"}
test busy-2.13 {tk busy hold (shortcut) root window, invalid cursor} -body {
    tk busy . -cursor nonExistingCursor
    update
} -returnCodes error -cleanup {
} -constraints tempNotMac -returnCodes error -cleanup {
    tk busy forget .
} -result {bad cursor spec "nonExistingCursor"}
test busy-2.14 {tk busy hold root window, invalid option} -body {
    tk busy hold . -invalidOption 1
    update
} -returnCodes error -cleanup {
} -constraints tempNotMac -returnCodes error -cleanup {
    tk busy forget .
} -result {unknown option "-invalidOption"}
test busy-2.15 {tk busy hold (shortcut) root window, invalid option} -body {
    tk busy . -invalidOption 1
    update
} -returnCodes error -cleanup {
} -constraints tempNotMac -returnCodes error -cleanup {
    tk busy forget .
} -result {unknown option "-invalidOption"}

test busy-3.1 {tk busy cget no window} -returnCodes error -body {
    tk busy cget
} -result {wrong # args: should be "tk busy cget window option"}
test busy-3.2 {tk busy cget no option} -returnCodes error -body {
174
175
176
177
178
179
180
181

182
183
184
185

186
187
188
189
190
191
192
166
167
168
169
170
171
172

173
174
175
176

177
178
179
180
181
182
183
184







-
+



-
+







    tk busy hold .f -cursor hand1
    update
} -body {
    tk busy cget .f -cursor
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {hand1}
} -result {hand1} -constraints tempNotMac

test busy-4.1 {tk busy configure no window} -returnCodes error -body {
    tk busy configure
} -result {wrong # args: should be "tk busy configure window ?-option value ...?"}
} -result {wrong # args: should be "tk busy configure window ?option? ?value ...?"}

test busy-4.2 {tk busy configure invalid window} -body {
    tk busy configure .f
} -returnCodes error -result {bad window path name ".f"}

test busy-4.3 {tk busy configure non-busy window} -setup {
    pack [frame .f]
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220







-
+







} -body {
    tk busy configure .f
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {{-cursor cursor Cursor wait wait}}

test busy-4.5 {tk busy configure} -constraints {nonwin} -setup {
test busy-4.5 {tk busy configure} -constraints {nonwin tempNotMac} -setup {
    pack [frame .f]
    tk busy hold .f -cursor hand2
    update
} -body {
    tk busy configure .f
} -cleanup {
    tk busy forget .f
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276







-
+







    tk busy configure .f -cursor
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {-cursor cursor Cursor wait wait}

test busy-4.8 {tk busy configure valid option} -constraints {
    nonwin
    nonwin tempNotMac
} -setup {
    pack [frame .f]
    tk busy hold .f -cursor circle
    update
} -body {
    tk busy configure .f -cursor
} -cleanup {
303
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317







-
+







-
+







    update
} -body {
    tk busy configure .f -cursor pencil
    tk busy cget .f -cursor
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {pencil}
} -result {pencil} -constraints tempNotMac

test busy-4.10 {tk busy configure valid option with invalid value} -setup {
    pack [frame .f]
    tk busy hold .f
    update
} -body {
    tk busy configure .f -cursor nonExistingCursor
} -returnCodes error -cleanup {
} -constraints tempNotMac -returnCodes error -cleanup {
    tk busy forget .f
    destroy .f
} -result {bad cursor spec "nonExistingCursor"}

test busy-5.1 {tk busy forget} -returnCodes error -body {
    tk busy forget
} -result {wrong # args: should be "tk busy forget window"}
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
338
339
340
341
342
343
344

345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+






-
+









-
+









-
+







} -result {1 0}

test busy-6.1 {tk busy status} -returnCodes error -body {
    tk busy status
} -result {wrong # args: should be "tk busy status window"}
test busy-6.2 {tk busy status non existing window} -body {
    tk busy status .f
} -result 0
} -result {0}
test busy-6.3 {tk busy status non busy window} -setup {
    pack [frame .f]
} -body {
    tk busy status .f
} -cleanup {
    destroy .f
} -result 0
} -result {0}
test busy-6.4 {tk busy status busy window} -setup {
    pack [frame .f]
    tk busy hold .f
    update
} -body {
    tk busy status .f
} -cleanup {
    tk busy forget .f
    destroy .f
} -result 1
} -result {1}
test busy-6.5 {tk busy status forgotten busy window} -setup {
    pack [frame .f]
    tk busy hold .f
    update
    tk busy forget .f
} -body {
    tk busy status .f
} -cleanup {
    destroy .f
} -result 0
} -result {0}

test busy-7.1 {tk busy current no busy} -body {
    tk busy current
} -result {}
test busy-7.2 {tk busy current 1 busy} -setup {
    pack [frame .f]
    tk busy hold .f
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
468
469
470
471
472
473
474
475
























476
477








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


    tk busy forget .f1
} -body {
    lsort [tk busy current *3*]
} -cleanup {
    tk busy forget .f2
    destroy .f1 .f2
} -result {}

test busy-8.1 {tk busy busywindow with a busy toplevel} -body {
    toplevel .top
    tk busy .top
    tk busy busywindow .top
} -cleanup {
    tk busy forget .top
    destroy .top
} -result {.top._Busy}
test busy-8.2 {tk busy busywindow with a busy widget} -body {
    pack [frame .f]
    tk busy .f
    tk busy busywindow .f
} -cleanup {
    tk busy forget .f
    destroy .f
} -result {.f_Busy}
test busy-8.3 {tk busy busywindow with a nonexisting widget} -body {
    tk busy .
    tk busy busywindow .nonExistingWidget
} -cleanup {
    tk busy forget .
} -result {}


::tcltest::cleanupTests
return

Changes to tests/butGeom2.tcl.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







# This file creates a visual test for button layout.  It is part of
# the Tk visual test suite, which is invoked via the "visual" script.

catch {destroy .t}
toplevel .t
wm title .t "Visual Tests for Button Geometry"
wm iconname .t "Button Geometry"
wm geom .t +0+0
wm minsize .t 1 1

label .t.l -text {This screen exercises the color options for various flavors of buttons.  Select display options below, and they will be applied to the appropriate button widgets.} -wraplength 5i
label .t.l -text {This screen exercises the color options for various flavors of buttons.  Select display options below, and they will be applied to the appropiate button widgets.} -wraplength 5i
pack .t.l -side top -fill both

button .t.quit -text Quit -command {destroy .t}
pack .t.quit -side bottom -pady 2m

set sepId 1
proc sep {} {

Changes to tests/button.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test labels, buttons, checkbuttons, and
# radiobuttons in Tk (i.e., all the widgets defined in tkButton.c).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365

366
367
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410







-
+








-
+









-
+








-
+









-
+








-
+









-
+








-
+







    pack .l
    update
} -body {
    .l configure -bd 4
    .l cget -bd
} -cleanup {
    destroy .l
} -result 4
} -result {4}
test button-1.34 {configuration option: "bd" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -bd badValue
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.35 {configuration option: "bd" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -bd 4
    .b cget -bd
} -cleanup {
    destroy .b
} -result 4
} -result {4}
test button-1.36 {configuration option: "bd" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -bd badValue
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.37 {configuration option: "bd" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -bd 4
    .c cget -bd
} -cleanup {
    destroy .c
} -result 4
} -result {4}
test button-1.38 {configuration option: "bd" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -bd badValue
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.39 {configuration option: "bd" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -bd 4
    .r cget -bd
} -cleanup {
    destroy .r
} -result 4
} -result {4}
test button-1.40 {configuration option: "bd" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -bd badValue
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test button-1.41 {configuration option: "bg" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -bg #ff0000
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633

634
635
636
637
638
639
640
641







-
+


















-
+


















-
+


















-
+







    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -borderwidth badValue
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.59 {configuration option: "borderwidth" for button} -setup {
    button .b -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -borderwidth 1.3
    .b cget -borderwidth
} -cleanup {
    destroy .b
} -result {1.3}
test button-1.60 {configuration option: "borderwidth" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -borderwidth badValue
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.61 {configuration option: "borderwidth" for checkbutton} -setup {
    checkbutton .c -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -borderwidth 1.3
    .c cget -borderwidth
} -cleanup {
    destroy .c
} -result {1.3}
test button-1.62 {configuration option: "borderwidth" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -borderwidth badValue
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.63 {configuration option: "borderwidth" for radiobutton} -setup {
    radiobutton .r -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -borderwidth 1.3
    .r cget -borderwidth
} -cleanup {
    destroy .r
} -result {1.3}
test button-1.64 {configuration option: "borderwidth" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -borderwidth badValue
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test button-1.65 {configuration option: "command" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -command {set x}
1161
1162
1163
1164
1165
1166
1167
1168

1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1161
1162
1163
1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186

1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224

1225
1226
1227
1228
1229
1230
1231
1232







-
+


















-
+


















-
+


















-
+







    pack .l
    update
} -body {
    .l configure -height 18
    .l cget -height
} -cleanup {
    destroy .l
} -result 18
} -result {18}
test button-1.120 {configuration option: "height" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -height 20.0
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected integer but got "20.0"}
test button-1.121 {configuration option: "height" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -height 18
    .b cget -height
} -cleanup {
    destroy .b
} -result 18
} -result {18}
test button-1.122 {configuration option: "height" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -height 20.0
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected integer but got "20.0"}
test button-1.123 {configuration option: "height" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -height 18
    .c cget -height
} -cleanup {
    destroy .c
} -result 18
} -result {18}
test button-1.124 {configuration option: "height" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -height 20.0
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected integer but got "20.0"}
test button-1.125 {configuration option: "height" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -height 18
    .r cget -height
} -cleanup {
    destroy .r
} -result 18
} -result {18}
test button-1.126 {configuration option: "height" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -height 20.0
} -cleanup {
1401
1402
1403
1404
1405
1406
1407
1408

1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427

1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465

1466
1467
1468
1469
1470
1471
1472
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426

1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1472







-
+


















-
+


















-
+


















-
+







    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -highlightthickness badValue
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.145 {configuration option: "highlightthickness" for button} -setup {
    button .b -borderwidth 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -highlightthickness 6m
    .b cget -highlightthickness
} -cleanup {
    destroy .b
} -result {6m}
test button-1.146 {configuration option: "highlightthickness" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -highlightthickness badValue
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.147 {configuration option: "highlightthickness" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -highlightthickness 6m
    .c cget -highlightthickness
} -cleanup {
    destroy .c
} -result {6m}
test button-1.148 {configuration option: "highlightthickness" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -highlightthickness badValue
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}
test button-1.149 {configuration option: "highlightthickness" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -highlightthickness 6m
    .r cget -highlightthickness
} -cleanup {
    destroy .r
} -result {6m}
test button-1.150 {configuration option: "highlightthickness" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -highlightthickness badValue
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test button-1.151 {configuration option: "image" for label} -constraints {
    testImageType
} -setup {
    image create test image1
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
1562
1563
1564
1565
1566
1567
1568
1569

1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1562
1563
1564
1565
1566
1567
1568

1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595







-
+


















-
+







    pack .c
    update
} -body {
    .c configure -indicatoron yes
    .c cget -indicatoron
} -cleanup {
    destroy .c
} -result 1
} -result {1}
test button-1.160 {configuration option: "indicatoron" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -indicatoron no_way
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected boolean value but got "no_way"}
test button-1.161 {configuration option: "indicatoron" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -indicatoron yes
    .r cget -indicatoron
} -cleanup {
    destroy .r
} -result 1
} -result {1}
test button-1.162 {configuration option: "indicatoron" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -indicatoron no_way
} -cleanup {
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
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







-
+


















-
+


















-
+



















-
+


















-
+


















-
+


















-
+



















-
+


















-
+


















-
+


















-
+










-
+



















-
+







    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -overrelief 1.5
} -cleanup {
    destroy .b
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
test button-1.179 {configuration option: "overrelief" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -overrelief ""
    .c cget -overrelief
} -cleanup {
    destroy .c
} -result {}
test button-1.180 {configuration option: "overrelief" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -overrelief 1.5
} -cleanup {
    destroy .c
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
test button-1.181 {configuration option: "overrelief" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -overrelief ""
    .r cget -overrelief
} -cleanup {
    destroy .r
} -result {}
test button-1.182 {configuration option: "overrelief" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -overrelief 1.5
} -cleanup {
    destroy .r
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes {error} -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}

test button-1.183 {configuration option: "padx" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -padx 12m
    .l cget -padx
} -cleanup {
    destroy .l
} -result {12m}
test button-1.184 {configuration option: "padx" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -padx 420x
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.185 {configuration option: "padx" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -padx 12m
    .b cget -padx
} -cleanup {
    destroy .b
} -result {12m}
test button-1.186 {configuration option: "padx" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -padx 420x
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.187 {configuration option: "padx" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -padx 12m
    .c cget -padx
} -cleanup {
    destroy .c
} -result {12m}
test button-1.188 {configuration option: "padx" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -padx 420x
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.189 {configuration option: "padx" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -padx 12m
    .r cget -padx
} -cleanup {
    destroy .r
} -result {12m}
test button-1.190 {configuration option: "padx" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -padx 420x
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}

test button-1.191 {configuration option: "pady" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -pady 12m
    .l cget -pady
} -cleanup {
    destroy .l
} -result {12m}
test button-1.192 {configuration option: "pady" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -pady 420x
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.193 {configuration option: "pady" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -pady 12m
    .b cget -pady
} -cleanup {
    destroy .b
} -result {12m}
test button-1.194 {configuration option: "pady" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -pady 420x
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.195 {configuration option: "pady" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -pady 12m
    .c cget -pady
} -cleanup {
    destroy .c
} -result {12m}
test button-1.196 {configuration option: "pady" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -pady 420x
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}
test button-1.197 {configuration option: "pady" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -pady 12m
    .r cget -pady
} -cleanup {
    destroy .r
} -result {12m}
test button-1.198 {configuration option: "pady" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -pady 420x
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}

test button-1.199 {configuration option: "repeatdelay" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -repeatdelay 100
    .b cget -repeatdelay
} -cleanup {
    destroy .b
} -result 100
} -result {100}
test button-1.200 {configuration option: "repeatdelay" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -repeatdelay foo
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected integer but got "foo"}

test button-1.201 {configuration option: "repeatinterval" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -repeatinterval 100
    .b cget -repeatinterval
} -cleanup {
    destroy .b
} -result 100
} -result {100}
test button-1.202 {configuration option: "repeatinterval" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -repeatinterval foo
} -cleanup {
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
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







-
+








-
+









-
+








-
+









-
+








-
+









-
+








-
+







    pack .l
    update
} -body {
    .l configure -underline 5
    .l cget -underline
} -cleanup {
    destroy .l
} -result 5
} -result {5}
test button-1.244 {configuration option: "underline" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -underline 3p
} -cleanup {
    destroy .l
} -returnCodes {error} -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.245 {configuration option: "underline" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -underline 5
    .b cget -underline
} -cleanup {
    destroy .b
} -result 5
} -result {5}
test button-1.246 {configuration option: "underline" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -underline 3p
} -cleanup {
    destroy .b
} -returnCodes {error} -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.247 {configuration option: "underline" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -underline 5
    .c cget -underline
} -cleanup {
    destroy .c
} -result 5
} -result {5}
test button-1.248 {configuration option: "underline" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -underline 3p
} -cleanup {
    destroy .c
} -returnCodes {error} -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.249 {configuration option: "underline" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -underline 5
    .r cget -underline
} -cleanup {
    destroy .r
} -result 5
} -result {5}
test button-1.250 {configuration option: "underline" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -underline 3p
} -cleanup {
    destroy .r
} -returnCodes {error} -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes {error} -result {expected integer but got "3p"}

test button-1.251 {configuration option: "tristatevalue" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -tristatevalue unknowable
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
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







-
+


















-
+


















-
+


















-
+



















-
+








-
+









-
+








-
+









-
+








-
+









-
+








-
+







    pack .l
    update
} -body {
    .l configure -width 402
    .l cget -width
} -cleanup {
    destroy .l
} -result 402
} -result {402}
test button-1.255 {configuration option: "width" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -width 3p
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.256 {configuration option: "width" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -width 402
    .b cget -width
} -cleanup {
    destroy .b
} -result 402
} -result {402}
test button-1.257 {configuration option: "width" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -width 3p
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.258 {configuration option: "width" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -width 402
    .c cget -width
} -cleanup {
    destroy .c
} -result 402
} -result {402}
test button-1.259 {configuration option: "width" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -width 3p
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected integer but got "3p"}
test button-1.260 {configuration option: "width" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -width 402
    .r cget -width
} -cleanup {
    destroy .r
} -result 402
} -result {402}
test button-1.261 {configuration option: "width" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -width 3p
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected integer but got "3p"}

test button-1.262 {configuration option: "wraplength" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -wraplength 100
    .l cget -wraplength
} -cleanup {
    destroy .l
} -result 100
} -result {100}
test button-1.263 {configuration option: "wraplength" for label} -setup {
    label .l -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .l
    update
} -body {
    .l configure -wraplength 6x
} -cleanup {
    destroy .l
} -returnCodes {error} -result {expected screen distance but got "6x"}
} -returnCodes {error} -result {bad screen distance "6x"}
test button-1.264 {configuration option: "wraplength" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -wraplength 100
    .b cget -wraplength
} -cleanup {
    destroy .b
} -result 100
} -result {100}
test button-1.265 {configuration option: "wraplength" for button} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .b
    update
} -body {
    .b configure -wraplength 6x
} -cleanup {
    destroy .b
} -returnCodes {error} -result {expected screen distance but got "6x"}
} -returnCodes {error} -result {bad screen distance "6x"}
test button-1.266 {configuration option: "wraplength" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -wraplength 100
    .c cget -wraplength
} -cleanup {
    destroy .c
} -result 100
} -result {100}
test button-1.267 {configuration option: "wraplength" for checkbutton} -setup {
    checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .c
    update
} -body {
    .c configure -wraplength 6x
} -cleanup {
    destroy .c
} -returnCodes {error} -result {expected screen distance but got "6x"}
} -returnCodes {error} -result {bad screen distance "6x"}
test button-1.268 {configuration option: "wraplength" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -wraplength 100
    .r cget -wraplength
} -cleanup {
    destroy .r
} -result 100
} -result {100}
test button-1.269 {configuration option: "wraplength" for radiobutton} -setup {
    radiobutton .r -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .r
    update
} -body {
    .r configure -wraplength 6x
} -cleanup {
    destroy .r
} -returnCodes {error} -result {expected screen distance but got "6x"}
} -returnCodes {error} -result {bad screen distance "6x"}

test button-1.270 {configuration options} -body {
# Additional check to make sure that -selectcolor may be empty in
# checkbox widgets
    checkbutton .c
    .c configure -selectcolor {}
} -cleanup {
2830
2831
2832
2833
2834
2835
2836
2837

2838
2839
2840
2841
2842
2843

2844
2845
2846
2847
2848
2849
2850
2830
2831
2832
2833
2834
2835
2836

2837
2838
2839
2840
2841
2842

2843
2844
2845
2846
2847
2848
2849
2850







-
+





-
+








# ex 4.6
test button-3.13 {ButtonWidgetCmd procedure, "configure" option} -body {
    button .b -highlightthickness 3
    lindex [.b configure -highlightthickness] 4
} -cleanup {
    destroy .b
}  -result 3
}  -result {3}
test button-3.14 {ButtonWidgetCmd procedure, "configure" option} -body {
    checkbutton .c
    llength [.c configure]
} -cleanup {
    destroy .c
} -result 41
} -result {41}
test button-3.15 {ButtonWidgetCmd procedure, "configure" option} -body {
    button .b
    .b configure -gorp
} -cleanup {
    destroy .b
} -returnCodes {error} -result {unknown option "-gorp"}
test button-3.16 {ButtonWidgetCmd procedure, "configure" option} -setup {
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
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







-
+




















-
+



-
+




-
+



-
+








-
+



-
+




-
+




-
+







test button-3.21 {ButtonWidgetCmd procedure, "deselect" option} -body {
    checkbutton .c -variable checkvar -onvalue 1 -offvalue 0
    set checkvar 1
    .c d
    return $checkvar
} -cleanup {
    destroy .c
} -result 0
} -result {0}
test button-3.22 {ButtonWidgetCmd procedure, "deselect" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar green
    .r deselect
    return $radiovar
} -cleanup {
    destroy .r
} -result {green}
test button-3.23 {ButtonWidgetCmd procedure, "deselect" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar red
    .r deselect
    return $radiovar
} -cleanup {
    destroy .r
} -result {}

test button-3.24 {ButtonWidgetCmd procedure, "deselect" option} -body {
    checkbutton .c -variable checkvar -onvalue 1 -offvalue 0
    set checkvar 1
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    .c deselect
} -cleanup {
    destroy .c
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
} -returnCodes {error} -result {can't set "checkvar": trace aborted}
test button-3.25 {ButtonWidgetCmd procedure, "deselect" option} -body {
    checkbutton .c -variable checkvar -onvalue 1 -offvalue 0
    set checkvar 1
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    catch {.c deselect}
    list $errorInfo $checkvar
} -cleanup {
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
    destroy .c
} -match {glob} -result {{*trace aborted
    while executing
*
".c deselect"} 0}
test button-3.26 {ButtonWidgetCmd procedure, "deselect" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar red
    trace add variable radiovar write bogusTrace
    trace variable radiovar w bogusTrace
    .r deselect
} -cleanup {
    destroy .r
    trace remove variable radiovar write bogusTrace
    trace vdelete radiovar w bogusTrace
} -match {glob} -returnCodes {error} -result {can't set "radiovar": trace aborted}
test button-3.27 {ButtonWidgetCmd procedure, "deselect" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar red
    trace add variable radiovar write bogusTrace
    trace variable radiovar w bogusTrace
    catch {.r deselect}
    list $errorInfo $radiovar
} -cleanup {
    destroy .r
    trace remove variable radiovar write bogusTrace
    trace vdelete radiovar w bogusTrace
} -match glob -result {{*trace aborted
    while executing
*
".r deselect"} {}}

test button-3.28 {ButtonWidgetCmd procedure, "flash" option} -body {
    button .b
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
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







-
+



-
+




-
+




-
+







    return $radiovar
} -cleanup {
    destroy .r
} -result  {red}
test button-3.44 {ButtonWidgetCmd procedure, "select" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar yellow
    trace add variable radiovar write bogusTrace
    trace variable radiovar w bogusTrace
    .r select
} -cleanup {
    destroy .r
    trace remove variable radiovar write bogusTrace
    trace vdelete radiovar w bogusTrace
} -returnCodes {error} -result {can't set "radiovar": trace aborted}
test button-3.45 {ButtonWidgetCmd procedure, "select" option} -body {
    radiobutton .r -variable radiovar -value red
    set radiovar yellow
    trace add variable radiovar write bogusTrace
    trace variable radiovar w bogusTrace
    catch {.r select}
    list $errorInfo $radiovar
} -cleanup {
    destroy .r
    trace remove variable radiovar write bogusTrace
    trace vdelete radiovar w bogusTrace
} -match {glob} -result {{*trace aborted
    while executing
*
".r select"} red}

# ex 4.43
test button-3.46 {ButtonWidgetCmd procedure, "toggle" option} -body {
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
3171
3172
3173
3174
3175
3176
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
3171
3172
3173
3174
3175
3176







-
+



-
+




-
+



-
+








-
+


-
+





-
+



-
+







    return $result
} -cleanup {
    destroy .c
} -result {sunshine rain sunshine}
test button-3.51 {ButtonWidgetCmd procedure, "toggle" option} -body {
    checkbutton .c -variable checkvar -onvalue xyz -offvalue abc
    set checkvar xyz
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    .c toggle
} -cleanup {
    destroy .c
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
} -returnCodes {error} -result {can't set "checkvar": trace aborted}
test button-3.52 {ButtonWidgetCmd procedure, "toggle" option} -body {
    checkbutton .c -variable checkvar -onvalue xyz -offvalue abc
    set checkvar xyz
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    catch {.c toggle}
    list $errorInfo $checkvar
} -cleanup {
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
    destroy .c
} -match {glob} -result {{*trace aborted
    while executing
*
".c toggle"} abc}
test button-3.53 {ButtonWidgetCmd procedure, "toggle" option} -body {
    checkbutton .c -variable checkvar -onvalue xyz -offvalue abc
    set checkvar abc
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    .c toggle
} -cleanup {
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
    destroy .c
} -returnCodes {error} -result {can't set "checkvar": trace aborted}
test button-3.54 {ButtonWidgetCmd procedure, "toggle" option} -body {
    checkbutton .c -variable checkvar -onvalue xyz -offvalue abc
    set checkvar abc
    trace add variable checkvar write bogusTrace
    trace variable checkvar w bogusTrace
    catch {.c toggle}
    list $errorInfo $checkvar
} -cleanup {
    trace remove variable checkvar write bogusTrace
    trace vdelete checkvar w bogusTrace
    destroy .c
} -match {glob} -result {{*trace aborted
    while executing
*
".c toggle"} xyz}
test button-3.55 {ButtonWidgetCmd procedure, "toggle" option} -setup {
    unset -nocomplain checkvar
3245
3246
3247
3248
3249
3250
3251
3252

3253
3254
3255
3256
3257
3258
3259
3245
3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259







-
+







    set y 1
    .c configure -textvariable y
    set x 0
    .c toggle
    return $y
} -cleanup {
    destroy .c
} -result 1
} -result {1}

test button-5.5 {ConfigureButton - image handling} -constraints {
    testImageType
} -setup {
    imageCleanup
    image create test image1
    image create test image2
3278
3279
3280
3281
3282
3283
3284
3285

3286
3287
3288
3289
3290
3291
3292
3278
3279
3280
3281
3282
3283
3284

3285
3286
3287
3288
3289
3290
3291
3292







-
+







    set y Shiny
    checkbutton .c -variable x
    .c configure -variable y -onvalue Shiny
    .c toggle
    return $y
} -cleanup {
    destroy .c
} -result 0
} -result {0}
test button-5.8 {ConfigureButton - setting selected state from variable} -setup {
    unset -nocomplain x
} -body {
    checkbutton .c -variable x -offvalue Bogus
    return $x
} -cleanup {
    destroy .c
3300
3301
3302
3303
3304
3305
3306
3307

3308
3309
3310
3311

3312
3313
3314
3315
3316
3317
3318
3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310

3311
3312
3313
3314
3315
3316
3317
3318







-
+



-
+







} -cleanup {
    destroy .r
} -result {}

test button-5.10 {ConfigureButton - error in setting variable} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    radiobutton .r -variable x
} -cleanup {
    destroy .r
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
} -returnCodes {error} -result {can't set "x": trace aborted}

test button-5.11 {ConfigureButton - bad image name} -body {
    button .b -image bogus
} -cleanup {
    destroy .b
} -returnCodes {error} -result {image "bogus" doesn't exist}
3333
3334
3335
3336
3337
3338
3339
3340

3341
3342
3343

3344
3345
3346
3347
3348
3349

3350
3351
3352
3353

3354
3355
3356
3357
3358
3359
3360
3333
3334
3335
3336
3337
3338
3339

3340
3341
3342

3343
3344
3345
3346
3347
3348

3349
3350
3351
3352

3353
3354
3355
3356
3357
3358
3359
3360







-
+


-
+





-
+



-
+







} -cleanup {
    destroy .b
} -result {Override}

test button-5.14 {ConfigureButton - variable handling} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    radiobutton .r -text foo -textvariable x
} -cleanup {
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
    destroy .r
} -returnCodes {error} -result {can't set "x": trace aborted}
test button-5.15 {ConfigureButton - variable handling} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    catch {radiobutton .r -text foo -textvariable x}
	return $x
} -cleanup {
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
    destroy .r
} -result {foo}

#ex 6.14
test button-5.16 {ConfigureButton - -width option} -body {
    button .b -text "Button 1"
    .b configure -width 1i
3389
3390
3391
3392
3393
3394
3395
3396

3397
3398
3399
3400
3401
3402
3403

3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417

3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430

3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447

3448
3449
3450
3451
3452

3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471

3472
3473
3474
3475

3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490

3491
3492
3493
3494
3495
3496
3497
3389
3390
3391
3392
3393
3394
3395

3396
3397
3398
3399
3400
3401
3402

3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416

3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429

3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446

3447
3448
3449
3450
3451

3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470

3471
3472
3473
3474

3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489

3490
3491
3492
3493
3494
3495
3496
3497







-
+






-
+













-
+












-
+
















-
+




-
+


















-
+



-
+














-
+







".b configure -height 0.5c"}
#ex 6.16
test button-5.20 {ConfigureButton - -width option} -body {
    button .b -bitmap questhead
    .b configure -width abc
} -cleanup {
    destroy .b
} -returnCodes {error} -result  {expected screen distance but got "abc"}
} -returnCodes {error} -result  {bad screen distance "abc"}
test button-5.21 {ConfigureButton - -width option} -body {
    button .b -bitmap questhead
    catch {.b configure -width abc}
    return $errorInfo
} -cleanup {
    destroy .b
} -result {expected screen distance but got "abc"
} -result {bad screen distance "abc"
    (processing -width option)
    invoked from within
".b configure -width abc"}
test button-5.22 {ConfigureButton - -height option} -constraints {
    testImageType
} -setup {
    image create test image1
} -body {
    button .b -image image1
    .b configure -height 0.5x
} -cleanup {
    destroy .b
    image delete image1
} -returnCodes {error} -result {expected screen distance but got "0.5x"}
} -returnCodes {error} -result {bad screen distance "0.5x"}
test button-5.23 {ConfigureButton - -height option} -constraints {
    testImageType
} -setup {
    image create test image1
} -body {
#ztestImageType
    button .b -image image1
    catch {.b configure -height 0.5x}
    return $errorInfo
} -cleanup {
    destroy .b
    image delete image1
} -result  {expected screen distance but got "0.5x"
} -result  {bad screen distance "0.5x"
    (processing -height option)
    invoked from within
".b configure -height 0.5x"}
#ex 6.18
test button-5.24 {ConfigureButton - computing geometry} -constraints {
    fonts
} -body {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
                -padx 30 -pady 20
    # 1. button with text
    .b configure -text "Sample text"
    pack .b
    set textwidth [font measure [.b cget -font] -displayof .b [.b cget -text]]
    set expectedwidth [expr {$textwidth + 2*[.b cget -borderwidth] \
            + 2*[.b cget -highlightthickness] + 2*[.b cget -padx]}]
    incr expectedwidth 2   ; # added (hardcoded) in tkUnixButton.c
    set result [expr {$expectedwidth == [winfo reqwidth .b]}]
    set result [expr $expectedwidth == [winfo reqwidth .b]]
    set linespace [lindex [font metrics [.b cget -font] -displayof .b] 5]
    set expectedheight [expr {$linespace + 2*[.b cget -borderwidth] \
            + 2*[.b cget -highlightthickness] + 2*[.b cget -pady]}]
    incr expectedheight 2   ; # added (hardcoded) in tkUnixButton.c
    lappend result [expr {$expectedheight == [winfo reqheight .b]}]
    lappend result [expr $expectedheight == [winfo reqheight .b]]
    # 2. button with a bitmap image
    # there is no access to characteristics the predefined bitmaps,
    # so define one as an image (copied from questhead.xbm)
    set myquesthead [image create bitmap -data {
        #define myquesthead_width 20
        #define myquesthead_height 22
        static unsigned char myquesthead_bits[] = {
           0xf8, 0x1f, 0x00, 0xac, 0x2a, 0x00, 0x56, 0x55, 0x00, 0xeb, 0xaf, 0x00,
           0xf5, 0x5f, 0x01, 0xfb, 0xbf, 0x00, 0x75, 0x5d, 0x01, 0xfb, 0xbe, 0x02,
           0x75, 0x5d, 0x05, 0xab, 0xbe, 0x0a, 0x55, 0x5f, 0x07, 0xab, 0xaf, 0x00,
           0xd6, 0x57, 0x01, 0xac, 0xab, 0x00, 0xd8, 0x57, 0x00, 0xb0, 0xaa, 0x00,
           0x50, 0x55, 0x00, 0xb0, 0x0b, 0x00, 0xd0, 0x17, 0x00, 0xb0, 0x0b, 0x00,
           0x58, 0x15, 0x00, 0xa8, 0x2a, 0x00};
    }]
    .b configure -image $myquesthead
    set expectedwidth [expr {[image width $myquesthead] + 2*[.b cget -borderwidth] \
            + 2*[.b cget -highlightthickness]}]
    incr expectedwidth 2   ; # added (hardcoded) in tkUnixButton.c
    lappend result [expr {$expectedwidth == [winfo reqwidth .b]}]
    lappend result [expr $expectedwidth == [winfo reqwidth .b]]
    set expectedheight [expr {[image height $myquesthead] + 2*[.b cget -borderwidth] \
            + 2*[.b cget -highlightthickness]}]
    incr expectedheight 2   ; # added (hardcoded) in tkUnixButton.c
    lappend result [expr {$expectedheight == [winfo reqheight .b]}]
    lappend result [expr $expectedheight == [winfo reqheight .b]]
} -cleanup {
    destroy .b
} -result {1 1 1 1}

test button-5.25 {ConfigureButton - computing geometry} -setup {
    button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
} -body {
    .b configure -text "Button 1"
    set old [winfo reqwidth .b]
    .b configure -text "Much longer text"
    set new [winfo reqwidth .b]
    expr {$old == $new}
} -cleanup {
    destroy .b
} -result 0
} -result {0}

test button-6.1 {ButtonEventProc procedure} -body {
    button .b -text "Test Button" -command {
	   destroy .b
	   set x [list [winfo exists .b] [info commands .b]]
}
    .b invoke
3534
3535
3536
3537
3538
3539
3540
3541

3542
3543
3544
3545

3546
3547
3548
3549
3550
3551

3552
3553
3554
3555
3556
3557


3558
3559
3560
3561
3562

3563
3564
3565
3566

3567
3568
3569
3570
3571
3572

3573
3574
3575
3576
3577
3578


3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596

3597
3598
3599
3600

3601
3602
3603
3604
3605

3606
3607
3608
3609
3610

3611
3612
3613
3614
3615
3616
3617
3534
3535
3536
3537
3538
3539
3540

3541
3542
3543
3544

3545
3546
3547
3548
3549
3550

3551
3552
3553
3554
3555


3556
3557
3558
3559
3560
3561

3562
3563
3564
3565

3566
3567
3568
3569
3570
3571

3572
3573
3574
3575
3576


3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595

3596
3597
3598
3599

3600
3601
3602
3603
3604

3605
3606
3607
3608
3609

3610
3611
3612
3613
3614
3615
3616
3617







-
+



-
+





-
+




-
-
+
+




-
+



-
+





-
+




-
-
+
+

















-
+



-
+




-
+




-
+







    destroy .c
} -result {0 1 0}

test button-8.2 {TkInvokeButton procedure} -setup {
    set x 0
} -body {
    checkbutton .c -variable x
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    .c invoke
} -cleanup {
    destroy .c
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
} -returnCodes {error} -result {can't set "x": trace aborted}
test button-8.3 {TkInvokeButton procedure} -setup {
    set x 0
} -body {
    checkbutton .c -variable x
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    catch {.c invoke}
    return $x
} -cleanup {
    destroy .c
    trace remove variable x write bogusTrace
} -result 1
    trace vdelete x w bogusTrace
} -result {1}
test button-8.4 {TkInvokeButton procedure} -setup {
    set x 1
} -body {
    checkbutton .c -variable x
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    .c invoke
} -cleanup {
    destroy .c
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
} -returnCodes {error} -result {can't set "x": trace aborted}
test button-8.5 {TkInvokeButton procedure} -setup {
    set x 1
} -body {
    checkbutton .c -variable x
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    catch {.c invoke}
    return $x
} -cleanup {
    destroy .c
    trace remove variable x write bogusTrace
} -result 0
    trace vdelete x w bogusTrace
} -result {0}

test button-8.6 {TkInvokeButton procedure} -setup {
    set x 0
} -body {
    radiobutton .r -variable x -value red
    set result $x
    .r invoke
    lappend result $x
    .r invoke
    lappend result $x
} -cleanup {
    destroy .r
} -result {0 red red}

test button-8.7 {TkInvokeButton procedure} -body {
    radiobutton .r -variable x -value red
    set x green
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    .r invoke
} -cleanup {
    destroy .r
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
} -returnCodes {error} -result {can't set "x": trace aborted}
test button-8.8 {TkInvokeButton procedure} -body {
    radiobutton .r -variable x -value red
    set x green
    trace add variable x write bogusTrace
    trace variable x w bogusTrace
    catch {.r invoke}
    list $errorInfo $x
} -cleanup {
    destroy .r
    trace remove variable x write bogusTrace
    trace vdelete x w bogusTrace
} -match {glob} -result {{*trace aborted
    while executing
*
".r invoke"} red}

#ex 9.6
test button-8.9 {TkInvokeButton procedure} -setup {
3661
3662
3663
3664
3665
3666
3667
3668

3669
3670
3671
3672
3673
3674
3675
3676
3677
3678

3679
3680
3681
3682
3683
3684
3685
3686
3687
3688

3689
3690
3691
3692
3693
3694
3695
3696
3697
3698

3699
3700
3701
3702
3703
3704
3705
3706
3707
3708

3709
3710
3711
3712
3713
3714
3715
3716
3717
3718

3719
3720
3721
3722
3723
3724
3725
3661
3662
3663
3664
3665
3666
3667

3668
3669
3670
3671
3672
3673
3674
3675
3676
3677

3678
3679
3680
3681
3682
3683
3684
3685
3686
3687

3688
3689
3690
3691
3692
3693
3694
3695
3696
3697

3698
3699
3700
3701
3702
3703
3704
3705
3706
3707

3708
3709
3710
3711
3712
3713
3714
3715
3716
3717

3718
3719
3720
3721
3722
3723
3724
3725







-
+









-
+









-
+









-
+









-
+









-
+







    set x 0
    checkbutton .c -variable x
    set x 44
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 1
} -result {1}
test button-9.3 {ButtonVarProc procedure} -setup {
    set x 1
} -body {
    checkbutton .c -variable x
    set x 44
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 1
} -result {1}
test button-9.4 {ButtonVarProc procedure} -setup {
    set x 0
} -body {
    checkbutton .c -variable x
    set x 1
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 0
} -result {0}
test button-9.5 {ButtonVarProc procedure} -setup {
    set x 1
} -body {
    checkbutton .c -variable x
    set x 1
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 0
} -result {0}
test button-9.6 {ButtonVarProc procedure} -setup {
    set x 0
} -body {
    checkbutton .c -variable x
    set x 0
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 1
} -result {1}
test button-9.7 {ButtonVarProc procedure} -setup {
    set x 1
} -body {
    checkbutton .c -variable x
    set x 0
    .c toggle
    return $x
} -cleanup {
    destroy .c
} -result 1
} -result {1}
test button-9.8 {ButtonVarProc procedure, can't read variable} -setup {
# This test does nothing but produce a core dump if there's a prbblem.
    unset -nocomplain a
} -body {
    checkbutton .c -variable a
    unset a
    set a(32) 0
3747
3748
3749
3750
3751
3752
3753
3754

3755
3756
3757
3758
3759
3760
3761
3747
3748
3749
3750
3751
3752
3753

3754
3755
3756
3757
3758
3759
3760
3761







-
+







    .b configure -textvariable x
    set old [winfo reqwidth .b]
    set x New
    set new [winfo reqwidth .b]
    expr {$old == $new}
} -cleanup {
    destroy .b
} -result 0
} -result {0}

test button-11.1 {ButtonImageProc procedure} -constraints {
    testImageType
} -setup {
    label .l -highlightthickness 0 -font {Helvetica -12 bold}
    image create test image1
} -body {
3776
3777
3778
3779
3780
3781
3782
3783

3784
3785
3786
3787
3788
3789
3790
3776
3777
3778
3779
3780
3781
3782

3783
3784
3785
3786
3787
3788
3789
3790







-
+







    destroy .b

    set res1 [list [winfo children .] [interp hidden]]
    set res2 [list {} $l]
    expr {$res1 == $res2}
} -cleanup {
    destroy .b
} -result 1
} -result {1}

test button-13.1 {size behavior: label} -setup {
    label .a -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    label .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    label .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    set result {}
} -body {
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
3953
3954
3955
3956
3957
3958
3959







































3960
3961
3962
3963
3964
3965
3966
3967







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    focus -force .top.b
    update
    event generate .top.b <space>
    update  ; # shall not trigger error  invalid command name ".top.b"
} -cleanup {
    destroy .top.b .top
} -result {}

test button-15.1 {Bug [5d991b822e]} {
    # Want this not to segfault
    set var INIT
    button .b -textvariable var
    trace add variable var unset {apply {args {
	.b configure -textvariable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
} {}
test button-15.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    button .b -textvariable var
    trace add variable var unset {apply {args {
	.b configure -textvariable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}
test button-15.3 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    checkbutton .b -variable var
    trace add variable var unset {apply {args {
	.b configure -variable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
} {}


imageFinish
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/canvImg.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test out the procedures in tkCanvImg.c,
# which implement canvas "image" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit
75
76
77
78
79
80
81
82

83
84
85
86
87

88
89
90
91
92
93
94
75
76
77
78
79
80
81

82
83
84
85
86

87
88
89
90
91
92
93
94







-
+




-
+







} -cleanup {
    .c delete all
} -result {center {} {}}
test canvImg-2.4 {CreateImage procedure} -body {
    .c create image xyz 40
} -cleanup {
    .c delete all
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test canvImg-2.5 {CreateImage procedure} -body {
    .c create image 50 qrs
} -cleanup {
    .c delete all
} -returnCodes {error} -result {expected screen distance but got "qrs"}
} -returnCodes {error} -result {bad screen distance "qrs"}
test canvImg-2.6 {CreateImage procedure} -constraints testImageType -body {
    .c create image 50 50 -gorp foo
} -cleanup {
    .c delete all
} -returnCodes {error} -result {unknown option "-gorp"}


105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129







-
+









-
+







	image create test foo
} -body {
    .c create image 50 100 -image foo -tags i1
    .c coords i1 dumb 100
} -cleanup {
	.c delete all
	image delete foo
} -returnCodes {error} -result {expected screen distance but got "dumb"}
} -returnCodes {error} -result {bad screen distance "dumb"}
test canvImg-3.3 {ImageCoords procedure} -constraints testImageType -setup {
	image create test foo
} -body {
    .c delete all
    .c create image 50 100 -image foo -tags i1
    .c coords i1 250 dumb0
} -cleanup {
	.c delete all
	image delete foo
} -returnCodes {error} -result {expected screen distance but got "dumb0"}
} -returnCodes {error} -result {bad screen distance "dumb0"}
test canvImg-3.4 {ImageCoords procedure} -constraints testImageType -setup {
	image create test foo
} -body {
    .c delete all
    .c create image 50 100 -image foo -tags i1
    .c coords i1 250
} -cleanup {
152
153
154
155
156
157
158
159

160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183




184
185
186
187
188
189
190
152
153
154
155
156
157
158

159
160
161

162
163
164
165
166
167
168

169

170





171
172




173
174
175
176
177
178
179
180
181
182
183







-
+


-
+






-

-

-
-
-
-
-


-
-
-
-
+
+
+
+







    .c itemconfigure i1 -image {}
    update
    list $x [.c bbox i1]
} -cleanup {
	.c delete all
	image delete foo
} -result {{{foo free}} {}}
test canvImg-4.2 {ConfigureImage procedure} -constraints testImageType -setup {
test canvImg-4.2 {ConfiugreImage procedure} -constraints testImageType -setup {
    .c delete all
} -body {
    image create test foo -variable x
	image create test foo -variable x
    image create test foo2 -variable y
    foo2 changed 0 0 0 0 80 60
    .c create image 50 100 -image foo -tags i1 -anchor nw
    update
    set x {}
    set y {}
    set timer [after 500 {lappend y "timed out"}]
    .c itemconfigure i1 -image foo2
    update idletasks
    update
    # On MacOS we need to wait for the test image display procedure to run.
    while {"timed out" ni $y && [lindex $y end 1] ne "display"} {
        vwait y
    }
    after cancel $timer
    list $x $y [.c bbox i1]
} -cleanup {
    .c delete all
    image delete foo
    image delete foo2
} -result {{{foo free}} {{foo2 get} {foo2 display 0 0 80 60}} {50 100 130 160}}
	.c delete all
	image delete foo
	image delete foo2
} -result {{{foo free}} {{foo2 get} {foo2 display 0 0 80 60 30 30}} {50 100 130 160}}
test canvImg-4.3 {ConfiugreImage procedure} -constraints testImageType -setup {
    .c delete all
} -body {
	image create test foo -variable x
    image create test foo2 -variable y
    foo2 changed 0 0 0 0 80 60
    .c create image 50 100 -image foo -tags i1 -anchor nw
357
358
359
360
361
362
363



364
365

366
367
368
369
370
371
372
373
374
375
376

377
378
379
380
381
382
383
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







+
+
+

-
+










-
+







    .c create image 20 30 -image foo -tags i1 -anchor center
    .c bbox i1
} -cleanup {
    .c delete all
    image delete foo
} -result {5 23 35 38}

# The following test is non-portable because of differences in
# coordinate rounding on some machines (does 0.5 round  up?).

test canvImg-7.1 {DisplayImage procedure} -constraints {
    testImageType
	nonPortable testImageType
} -setup {
    .c delete all
} -body {
    image create test foo -variable x
    .c create image 50 100 -image foo -tags i1 -anchor nw
    update
    set x {}
    .c create rect 55 110 65 115 -width 1 -outline black -fill white
    update
    set x
} -result {{foo display 4 9 12 6}}
} -result {{foo display 4 9 12 6 30 30}}
test canvImg-7.2 {DisplayImage procedure, no image} -body {
    .c delete all
    .c create image 50 100 -tags i1
    update
    .c create rect 55 110 65 115 -width 1 -outline black -fill white
    update
} -result {}
722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737

738
739
740
741
742
743



744
745
746
747
748
749

750
751
752
753
754
755
756
757
758
759
760
761
762



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786

787
788

789
790

791

792
793
794


795
796

797
798
799
800



801
802
803
804
805
806
807
808
809
718
719
720
721
722
723
724

725

726
727
728
729

730

731

732
733



734
735
736
737
738
739

740

741
742
743
744

745


746
747
748



749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766

767
768
769
770

771
772

773
774
775
776
777
778
779

780



781
782


783
784



785
786
787
788
789
790
791
792
793
794
795
796







-

-
+



-

-
+
-


-
-
-
+
+
+



-

-
+



-

-
-



-
-
-
+
+
+















-




-


-
+


+


+
-
+
-
-
-
+
+
-
-
+

-
-
-
+
+
+









} -cleanup {
	.c delete all
	image delete foo
} -result {75 150 105 165}

test canvImg-10.1 {TranslateImage procedure} -constraints testImageType -setup {
    .c delete all
    update
} -body {
    image create test foo -variable x
	image create test foo -variable x
    .c create image 50 100 -image foo -tags image -anchor nw
    update
    set x {}
    set timer [after 500 {lappend x "timed out"}]
    foo changed 2 4 6 8 30 15
    vwait x
    update
    after cancel $timer
    return $x
} -cleanup {
    .c delete all
    image delete foo
} -result {{foo display 2 4 6 8}}
	.c delete all
	image delete foo
} -result {{foo display 2 4 6 8 30 30}}

test canvImg-11.1 {TranslateImage procedure} -constraints testImageType -setup {
    .c delete all
    update
} -body {
    image create test foo -variable x
	image create test foo -variable x
    .c create image 50 100 -image foo -tags image -anchor nw
    update
    set x {}
    set timer [after 500 {lappend x "timed out"}]
    foo changed 2 4 6 8 40 50
    vwait x
    after cancel $timer
    update
    return $x
} -cleanup {
    .c delete all
    image delete foo
} -result {{foo display 0 0 40 50}}
	.c delete all
	image delete foo
} -result {{foo display 0 0 40 50 30 30}}
test canvImg-11.2 {ImageChangedProc procedure} -constraints {
	testImageType
} -setup {
    .c delete all
} -body {
    image create test foo -variable x
    .c create image 50 100 -image foo -tags image -anchor center
    update
    set x {}
    foo changed 0 0 0 0 40 50
    .c bbox image
} -cleanup {
	.c delete all
	image delete foo
} -result {30 75 70 125}

test canvImg-11.3 {ImageChangedProc procedure} -constraints {
	testImageType
} -setup {
    .c delete all
    update idletasks
} -body {
    image create test foo -variable x
    image create test foo2 -variable z
	image create test foo2 -variable y
    foo changed 0 0 0 0 40 50
    foo2 changed 0 0 0 0 80 60

    .c create image 50 100 -image foo -tags image -anchor nw
    .c create image 70 110 -image foo2 -anchor nw
    update
    set z {}
    set y {}
    set timer [after 500 {lappend z "timed out"}]
    image delete foo
    vwait z
    image create test foo -variable x
    update
    after cancel $timer
    return $z
    return $y
} -cleanup {
    .c delete all
    image delete foo2
} -result {{foo2 display 0 0 80 60}}
	.c delete all
	image delete foo foo2
} -result {{foo2 display 0 0 20 40 50 40}}

# cleanup
imageFinish
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/canvMoveto.test.

1
2
3
4
5
6



7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
1
2
3



4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35



-
-
-
+
+
+


-
+


















-
+







# This file is a Tcl script to test out the canvas "moveto" command. It is
# derived from canvRect.test.
#
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2004 Neil McKay.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2004 Neil McKay.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

canvas .c -width 400 -height 300 -bd 2 -relief sunken
.c create rectangle 20 20 80 80 -tag {test rect1}
.c create rectangle 40 40 90 100 -tag {test rect2}

test canvMoveto-1.1 {Bad args handling for "moveto" command} -body {
    .c moveto test
} -returnCodes error -result {wrong # args: should be ".c moveto tagOrId x y"}
test canvMoveto-1.2 {Bad args handling for "moveto" command} -body {
    .c moveto rect
} -returnCodes error -result {wrong # args: should be ".c moveto tagOrId x y"}
test canvMoveto-1.3 {Bad args handling for "moveto" command} -body {
    .c moveto test 12
} -returnCodes error -result {wrong # args: should be ".c moveto tagOrId x y"}
test canvMoveto-1.4 {Bad args handling for "moveto" command} -body {
    .c moveto test 12 y
} -returnCodes error -result {expected screen distance but got "y"}
} -returnCodes error -result {bad screen distance "y"}
test canvMoveto-1.5 {Bad args handling for "moveto" command} -body {
    .c moveto test 12 20 -anchor
} -returnCodes error -result {wrong # args: should be ".c moveto tagOrId x y"}

test canvMoveto-2.1 {Canvas "moveto" command coordinates} {
    .c moveto test 200 150
    .c bbox test

Changes to tests/canvPs.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27


28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58

59
60

61
62
63
64
65

66
67
68
69
70
71
72
1
2
3
4


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25


26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57

58
59

60
61
62
63
64

65
66
67
68
69
70
71
72




-
-
+
+















-
+



-
-
+
+




-
+


















-
+






-
+

-
+




-
+







# This file is a Tcl script to test out procedures to write postscript
# for canvases to files and channels. It exercises the procedure
# TkCanvPostscriptCmd in generic/tkCanvPs.c
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit

# canvas used in 1.* and 2.* test cases
canvas .c -width 400 -height 300 -bd 2 -relief sunken
.c create rectangle 20 20 80 80 -fill red
pack .c
update

test canvPs-1.1 {test writing to a file} -constraints {
    unixOrWin
    unixOrPc
} -setup {
    set foo [makeFile {} foo.ps]
} -body {
    set res [.c postscript -file $foo]
    lappend res [file exists $foo]
    .c postscript -file $foo
    file exists $foo
} -cleanup {
    removeFile foo.ps
} -result 1
test canvPs-1.2 {test writing to a file, idempotency} -constraints {
    unixOrWin
    unixOrPc
} -setup {
    set foo [makeFile {} foo.ps]
    set bar [makeFile {} bar.ps]
} -body {
    .c postscript -file $foo
    .c postscript -file $bar
    set status ok
    if {[file size $bar] != [file size $foo]} {
	set status broken
    }
    set status
} -cleanup {
    removeFile foo.ps
    removeFile bar.ps
} -result ok


test canvPs-2.1 {test writing to a channel} -constraints {
    unixOrWin
    unixOrPc
} -setup {
    set foo [makeFile {} foo.ps]
    file delete $foo
} -body {
    set chan [open $foo w]
    fconfigure $chan -translation lf
    set res [.c postscript -channel $chan]
    .c postscript -channel $chan
    close $chan
    lappend res [file exists $foo]
    file exists $foo
} -cleanup {
    removeFile foo.ps
} -result 1
test canvPs-2.2 {test writing to channel, idempotency} -constraints {
    unixOrWin
    unixOrPc
} -setup {
    set foo [makeFile {} foo.ps]
    set bar [makeFile {} bar.ps]
    file delete $foo
    file delete $bar
} -body {
    set c1 [open $foo w]
129
130
131
132
133
134
135
136



137
138
139
140
141
142
143
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145







-
+
+
+







} -cleanup {
    removeFile foo.ps
    removeFile bar.ps
} -result ok
destroy .c


test canvPs-3.1 {test ps generation with an embedded window} -setup {
test canvPs-3.1 {test ps generation with an embedded window} -constraints {
    notAqua
} -setup {
    set bar [makeFile {} bar.ps]
    file delete $bar
} -body {
    pack [canvas .c -width 200 -height 200 -background white]
    .c create rect 20 20 150 150 -tags rect0 -dash . -width 2
    .c create arc 0 50 200 200 -tags arc0 \
	    -dash {4 4} -stipple question -outline red -fill green
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182


















183
184
185
186
187
188
189







-
+













-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    update
    .c postscript -file $bar
    file exists $bar
} -cleanup {
    destroy .c
    imageCleanup
    removeFile bar.ps
} -result 1
} -result {1}
test canvPs-3.2 {test ps generation with an embedded window not mapped} -setup {
    set bar [makeFile {} bar.ps]
    file delete $bar
} -body {
    pack [canvas .c -width 200 -height 200 -background white]
    entry .c.e -background pink -foreground blue -width 14
    .c.e insert 0 "we gonna be postscripted"
    .c create window 50 180 -anchor nw -window .c.e
    .c postscript -file $bar
    file exists $bar
} -cleanup {
    destroy .c
    removeFile bar.ps
} -result 1
} -result {1}


test canvPs-4.1 {test ps generation with single-point uncolored poly, bug 734498} -body {
    pack [canvas .c]
    .c create poly 10 20 10 20
    .c postscript
} -cleanup {
    destroy .c
} -returnCodes ok -match glob -result *


test canvPs-5.1 {test ps generation with bitmap, bug 424773a00c} -body {
    pack [canvas .c]
    update
    .c create bitmap 50 50 -bitmap questhead
    .c postscript  ; # was crashing on macOS
} -cleanup {
    destroy .c
} -returnCodes ok -match glob -result *
test canvPs-5.2 {test ps generation with image} -body {
    pack [canvas .c]
    update
    .c create image 50 50 -image ::tk::icons::information
    .c postscript
} -cleanup {
    destroy .c
} -returnCodes ok -match glob -result *


# cleanup
unset -nocomplain foo bar
imageFinish

Changes to tests/canvRect.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in tkRectOval.c,
# which implement canvas "rectangle" and "oval" items.  It is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68

69
70
71

72
73
74

75
76
77

78
79
80
81
82
83
84
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67

68
69
70

71
72
73

74
75
76

77
78
79
80
81
82
83
84







-
+











-
+


-
+


-
+


-
+







} -result {test xyz}
test canvRect-1.9 {configuration options: good value for -width} -body {
    .c itemconfigure test -width 6.0
    list [.c itemcget test -width] [lindex [.c itemconfigure test -width] 4]
} -result {6.0 6.0}
test canvRect-1.10 {configuration options: bad value for -width} -body {
    .c itemconfigure test -width abc
} -returnCodes error -result {expected screen distance but got "abc"}
} -returnCodes error -result {bad screen distance "abc"}
.c delete withtag all


test canvRect-2.1 {CreateRectOval procedure} -body {
    .c create rect
} -returnCodes error -result {wrong # args: should be ".c create rect coords ?arg ...?"}
test canvRect-2.2 {CreateRectOval procedure} -body {
    .c create oval x y z
} -returnCodes error -result {wrong # coordinates: expected 0 or 4, got 3}
test canvRect-2.3 {CreateRectOval procedure} -body {
    .c create rectangle x 2 3 4
} -returnCodes error -result {expected screen distance but got "x"}
} -returnCodes error -result {bad screen distance "x"}
test canvRect-2.4 {CreateRectOval procedure} -body {
    .c create rectangle 1 y 3 4
} -returnCodes error -result {expected screen distance but got "y"}
} -returnCodes error -result {bad screen distance "y"}
test canvRect-2.5 {CreateRectOval procedure} -body {
    .c create rectangle 1 2 z 4
} -returnCodes error -result {expected screen distance but got "z"}
} -returnCodes error -result {bad screen distance "z"}
test canvRect-2.6 {CreateRectOval procedure} -body {
    .c create rectangle 1 2 3 q
} -returnCodes error -result {expected screen distance but got "q"}
} -returnCodes error -result {bad screen distance "q"}
test canvRect-2.7 {CreateRectOval procedure} -body {
    .c create rectangle 1 2 3 4 -tags x
    set result {}
    foreach element [.c coords x] {
	    lappend result [format %.1f $element]
    }
    set result
100
101
102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119

120
121
122
123
124
125
126




127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177


178
179
180
181
182
183
184



185
186
187
188
189
190
191
192


193
194
195
196
197
198
199
200


201
202
203
204
205
206
207
100
101
102
103
104
105
106

107
108
109
110
111
112

113
114
115
116
117
118

119
120
121
122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161


162
163
164
165
166
167
168
169
170
171
172
173








174
175
176
177
178
179
180


181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208







-
+





-
+





-
+





-
-
+
+
+
+

+


















-
+












-
-
+
+
+









-
-
-
-
-
-
-
-
+
+





-
-
+
+
+







-
+
+







-
+
+







    .c delete withtag all
} -result {10.0 20.0 30.0 40.0}
test canvRect-3.2 {RectOvalCoords procedure} -body {
    .c create rectangle 10 20 30 40 -tags x
    .c coords x a 2 3 4
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "a"}
} -returnCodes error -result {bad screen distance "a"}
test canvRect-3.3 {RectOvalCoords procedure} -body {
    .c create rectangle 10 20 30 40 -tags x
    .c coords x 1 b 3 4
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "b"}
} -returnCodes error -result {bad screen distance "b"}
test canvRect-3.4 {RectOvalCoords procedure} -body {
    .c create rectangle 10 20 30 40 -tags x
    .c coords x 1 2 c 4
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "c"}
} -returnCodes error -result {bad screen distance "c"}
test canvRect-3.5 {RectOvalCoords procedure} -body {
    .c create rectangle 10 20 30 40 -tags x
    .c coords x 1 2 3 d
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "d"}
test canvRect-3.6 {RectOvalCoords procedure} -body {
} -returnCodes error -result {bad screen distance "d"}
test canvRect-3.6 {RectOvalCoords procedure} -constraints {
    nonPortable
} -body {
    .c create rectangle 10 20 30 40 -tags x
    # Non-portable due to rounding differences.
    .c coords x 10 25 15 40
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result {9 24 16 41}
test canvRect-3.7 {RectOvalCoords procedure} -body {
    .c create rectangle 10 20 30 40 -tags x
    .c coords x 1 2 3 4 5
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {wrong # coordinates: expected 0 or 4, got 5}


test canvRect-4.1 {ConfigureRectOval procedure} -body {
    .c create rectangle 10 20 30 40 -tags x -width 1
    .c itemconfigure x -width abc
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "abc"}
} -returnCodes error -result {bad screen distance "abc"}
test canvRect-4.2 {ConfigureRectOval procedure} -body {
    .c create rectangle 10 20 30 40 -tags x -width 1
    catch {.c itemconfigure x -width abc}
	.c itemcget x -width
} -cleanup {
    .c delete withtag all
} -result {1.0}
test canvRect-4.3 {ConfigureRectOval procedure} -body {
    .c create rectangle 10 20 30 40 -tags x -width 1
    .c itemconfigure x -width -5
} -cleanup {
    .c delete withtag all
} -returnCodes error -result {expected screen distance but got "-5"}
test canvRect-4.4 {ConfigureRectOval procedure} -body {
} -returnCodes error -result {bad screen distance "-5"}
test canvRect-4.4 {ConfigureRectOval procedure} -constraints nonPortable -body {
    # Non-portable due to rounding differences
    .c create rectangle 10 20 30 40 -tags x -width 1
    .c itemconfigure x -width 10
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result {5 15 35 45}

# I can't come up with any good tests for DeleteRectOval.

# On Windows the bbox of rectangle items is 1 pixel larger at each border due
# to the "bloat" implemented in ComputeRectOvalBbox() in case -outline is {}
if {[tk windowingsystem] eq "win32"} {
    set result_5_1 {9 4 21 16}
} else {
    set result_5_1 {10 5 20 15}
}
test canvRect-5.1 {ComputeRectOvalBbox procedure} -body {
test canvRect-5.1 {ComputeRectOvalBbox procedure} -constraints nonPortable -body {
    # Non-portable due to rounding differences:
    .c create rectangle 10 20 30 40 -tags x -width 1 -outline {}
    .c coords x 20 15 10 5
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result $result_5_1
test canvRect-5.2 {ComputeRectOvalBbox procedure} -body {
} -result {10 5 20 15}
test canvRect-5.2 {ComputeRectOvalBbox procedure} -constraints nonPortable -body {
    # Non-portable due to rounding differences:
    .c create rectangle 10 20 30 40 -tags x -width 1 -outline {}
    .c coords x 10 20 30 10
    .c itemconfigure x -width 1 -outline red
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result {9 9 31 21}
test canvRect-5.3 {ComputeRectOvalBbox procedure} -body {
test canvRect-5.3 {ComputeRectOvalBbox procedure} -constraints nonPortable -body {
    # Non-portable due to rounding differences:
    .c create rectangle 10 20 30 40 -tags x -width 1 -outline {}
    .c coords x 10 20 30 10
    .c itemconfigure x -width 2 -outline red
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result {9 9 31 21}
test canvRect-5.4 {ComputeRectOvalBbox procedure} -body {
test canvRect-5.4 {ComputeRectOvalBbox procedure} -constraints nonPortable -body {
    # Non-portable due to rounding differences:
    .c create rectangle 10 20 30 40 -tags x -width 1 -outline {}
    .c coords x 10 20 30 10
    .c itemconfigure x -width 3 -outline red
    .c bbox x
} -cleanup {
    .c delete withtag all
} -result {8 8 32 22}
423
424
425
426
427
428
429
430

431
432
433


434
435
436


437
438
439
440
441
442
443
424
425
426
427
428
429
430

431
432
433
434
435
436
437


438
439
440
441
442
443
444
445
446







-
+



+
+

-
-
+
+







    .c create rect 100 300 200 350 -tags x
    .c move x 100 -10
    format {%.6g %.6g %.6g %.6g} {*}[.c coords x]
} -result {200 290 300 340}


test canvRect-11.1 {RectOvalToPostscript procedure} -constraints {
    nonPortable
     nonPortable macCrash
} -setup {
    .c delete withtag all
} -body {
    # Crashes on Mac because the XGetImage() call isn't implemented, causing a
    # dereference of NULL.
    # This test is non-portable because different color information
    # will get generated on different displays (e.g. mono displays
    # vs. color).
	# will get generated on different displays (e.g. mono displays
	# vs. color).
    .c configure -bd 0 -highlightthickness 0
    .c create rect 50 60 90 80 -fill black -stipple gray50 -outline {}
    .c create oval 100 150 200 200 -fill {} -outline #ff0000 -width 5
    update
    set x [.c postscript]
    string range $x [string first "-200 -150 translate" $x] end
} -result {-200 -150 translate

Changes to tests/canvText.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in tkCanvText.c,
# which implement canvas "text" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

51
52
53
54
55
56
57
58
59


60
61
62
63
64
65
66

67
68
69
70
71
72
73

74
75
76
77
78
79
80
51
52
53
54
55
56
57


58
59
60
61
62
63
64
65

66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
-
+
+






-
+






-
+







    .c itemconfigure test -justify xyz
} -returnCodes error -result {bad justification "xyz": must be left, right, or center}
test canvText-1.10 {configuration options: good value for "stipple"} -body {
    .c itemconfigure test -stipple gray50
    list [lindex [.c itemconfigure test -stipple] 4] [.c itemcget test -stipple]
} -result {gray50 gray50}
test canvasText-1.11 {configuration options: bad value for "stipple"} -body {
    .c itemconfigure test -stipple abcxyz
} -returnCodes error -result {bitmap "abcxyz" not defined}
    .c itemconfigure test -stipple xyz
} -returnCodes error -result {bitmap "xyz" not defined}
test canvText-1.12 {configuration options: good value for "underline"} -body {
    .c itemconfigure test -underline 0
    list [lindex [.c itemconfigure test -underline] 4] [.c itemcget test -underline]
} -result {0 0}
test canvasText-1.13 {configuration options: bad value for "underline"} -body {
    .c itemconfigure test -underline xyz
} -returnCodes error -result {bad index "xyz": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "xyz"}
test canvText-1.14 {configuration options: good value for "width"} -body {
    .c itemconfigure test -width 6
    list [lindex [.c itemconfigure test -width] 4] [.c itemcget test -width]
} -result {6 6}
test canvasText-1.15 {configuration options: bad value for "width"} -body {
    .c itemconfigure test -width xyz
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}
test canvText-1.16 {configuration options: good value for "tags"} -body {
    .c itemconfigure test -tags {test a b c}
    list [lindex [.c itemconfigure test -tags] 4] [.c itemcget test -tags]
} -result {{test a b c} {test a b c}}
test canvasText-1.17 {configuration options: bad value for "angle"} -body {
    .c itemconfigure test -angle xyz
} -returnCodes error -result {expected floating-point number but got "xyz"}
96
97
98
99
100
101
102
103

104
105
106
107
108

109
110
111
112
113
114
115
96
97
98
99
100
101
102

103
104
105
106
107

108
109
110
111
112
113
114
115







-
+




-
+







test canvText-2.1 {CreateText procedure: args} -body {
    .c create text
} -returnCodes {error} -result {wrong # args: should be ".c create text coords ?arg ...?"}
test canvText-2.2 {CreateText procedure: args} -body {
    .c create text xyz 0
} -cleanup {
    .c delete all
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test canvText-2.3 {CreateText procedure: args} -body {
    .c create text 0 xyz
} -cleanup {
    .c delete all
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test canvText-2.4 {CreateText procedure: args} -body {
    .c create text 0 0 -xyz xyz
} -cleanup {
    .c delete all
} -returnCodes {error} -result {unknown option "-xyz"}
test canvText-2.5 {CreateText procedure} -body {
    .c create text 0 0 -tags x
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143

144
145
146
147
148
149
150
129
130
131
132
133
134
135

136
137
138
139
140
141
142

143
144
145
146
147
148
149
150







-
+






-
+







} -result {0.0 0.0}
test canvText-3.2 {TextCoords procedure} -setup {
    .c create text 20 20 -tag test
} -body {
    .c coords test xyz 0
} -cleanup {
    .c delete test
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test canvText-3.3 {TextCoords procedure} -setup {
    .c create text 20 20 -tag test
} -body {
    .c coords test 0 xyz
} -cleanup {
    .c delete test
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test canvText-3.4 {TextCoords procedure} -setup {
    .c create text 20 20 -tag test
} -body {
    .c coords test 10 10
    set result {}
    foreach element [.c coords test] {
	lappend result [format %.1f $element]
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292







-
+


















-
+












-
+







} -body {
    .c itemconfig test -text "abcdefghi"
    .c icursor test 6
    .c dchars test 4 end
    .c index test insert
} -cleanup {
	.c delete test
} -result 4
} -result {4}


test canvText-5.1 {ConfigureText procedure: adjust cursor} -body {
    .c create text 10 10 -tag x -fill blue -font "times 40" -stipple gray50 \
	-text "xyz"
    .c delete x
} -result {}


test canvText-6.1 {ComputeTextBbox procedure} -constraints fonts -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor n; .c bbox test] \
	      eq "[expr {-$ax/2-1}] 0 [expr {$ax/2+1}] $ay"}
	      eq "[expr -$ax/2-1] 0 [expr $ax/2+1] $ay"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.2 {ComputeTextBbox procedure} -constraints fonts -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
    set ay [font metrics $font -linespace]
    set ax [font measure $font 0]
    .c create text 0 0 -tag test
    .c itemconfig test -font $font -text 0
    expr {[.c itemconfig test -anchor nw; .c bbox test] \
	      eq "-1 0 [expr {$ax+1}] $ay"}
	      eq "-1 0 [expr $ax+1] $ay"}
} -cleanup {
    .c delete test
} -result 1
test canvText-6.3 {ComputeTextBbox procedure} -constraints fonts -setup {
    .c delete test
} -body {
    set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+









-
+







    focus .c
    .c focus test
} -body {
    .c itemconfig test -text "abcdefg"
    .c icursor test 3
    .c insert test 2 "xyz"
    .c index test insert
} -result 6
} -result {6}
test canvText-8.9 {TextInsert procedure: inserting after cursor} -setup {
    .c create text 20 20 -tag test
    focus .c
    .c focus test
} -body {
    .c itemconfig test -text "abcdefg"
    .c icursor test 3
    .c insert test 4 "xyz"
    .c index test insert
} -result 3
} -result {3}

# Item used in 9.* tests
.c create text 20 20 -tag test
test canvText-9.1 {TextInsert procedure: before beginning/after end} -body {
    # Can't test this because GetTextIndex filters out those numbers.
} -result {}
test canvText-9.2 {TextInsert procedure: start > end} -body {
669
670
671
672
673
674
675
676

677
678
679
680
681
682

683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
669
670
671
672
673
674
675

676
677
678
679
680
681

682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705







-
+





-
+





-
+









-
+







    list [.c index test sel.first] [.c index test sel.last]
} -result {2 8}
test canvText-9.13 {TextInsert procedure: move cursor} -body {
    .c itemconfig test -text "abcdefghijk"
    .c icursor test 6
    .c dchars test 2 4
    .c index test insert
} -result 3
} -result {3}
test canvText-9.14 {TextInsert procedure: keep cursor >= first} -body {
    .c itemconfig test -text "abcdefghijk"
    .c icursor test 6
    .c dchars test 2 10
    .c index test insert
} -result 2
} -result {2}
test canvText-9.15 {TextInsert procedure: cursor doesn't move} -body {
    .c itemconfig test -text "abcdefghijk"
    .c icursor test 5
    .c dchars test 7 9
    .c index test insert
} -result 5
} -result {5}
.c delete test


test canvText-10.1 {TextToPoint procedure} -body {
    .c create text 0 0 -tag test
    .c itemconfig test -text 0 -anchor center
    .c index test @0,0
} -cleanup {
	.c delete test
} -result 0
} -result {0}


test canvText-11.1 {TextToArea procedure} -setup {
    .c create text 0 0 -tag test
    focus .c
    .c focus test
} -body {
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
749
750
751
752
753
754
755

756
757
758
759
760
761
762
763







-
+







    .c select from test 5
    .c select to test 8
    .c icursor test 12
    .c coords test 0 0
    list [.c index test end] [.c index test insert] \
	[.c index test sel.first] [.c index test sel.last] \
	[.c index test @0,0] \
	[.c index test {}] [.c index test 10] [.c index test 100]
	[.c index test -1] [.c index test 10] [.c index test 100]
} -cleanup {
    .c delete test
} -result {15 12 5 8 0 0 10 15}
test canvText-14.2 {GetTextIndex procedure: select error} -setup {
    .c create text 0 0 -tag test
    focus .c
    .c focus test
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
799
800
801
802
803
804
805



















806
807
808
809
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+







test canvText-14.6 {select clear errors} -setup {
    .c create text 0 0 -tag test
} -body {
    .c select clear test
} -cleanup {
    .c delete test
} -returnCodes error -result "wrong \# args: should be \".c select clear\""
test canvText-14.7 {GetTextIndex procedure: pixel index with non-default scrollregion} -setup {
    canvas .cc
    .cc create text 50 80 -tag test -text Hello -anchor nw -font "Arial 30"
    foreach {xmin ymin xmax ymax} [.cc bbox test] {}
} -body {
    # default -scrollregion
    set res [.cc index test @$xmin,$ymin]
    lappend res [.cc index test @$xmax,$ymax]
    # -scrollregion with positive upper left corner
    .cc configure -scrollregion {50 50 700 900}
    lappend res [.cc index test @$xmin,$ymin]
    lappend res [.cc index test @$xmax,$ymax]
    # -scrollregion with negative upper left corner
    .cc configure -scrollregion {-100 -100 700 900}
    lappend res [.cc index test @$xmin,$ymin]
    lappend res [.cc index test @$xmax,$ymax]
} -cleanup {
    destroy .cc
} -result {0 5 0 5 0 5}

test canvText-15.1 {SetTextCursor procedure} -setup {
    .c create text 0 0 -tag test
    focus .c
    .c focus test
} -body {
    .c itemconfig test -text "abcdefghijklmno" -anchor nw
    .c itemconfig -text "abcdefg"
    .c icursor test 3
    .c index test insert
} -cleanup {
    .c delete test
} -result 3
} -result {3}

test canvText-16.1 {GetSelText procedure} -setup {
    .c create text 0 0 -tag test
    focus .c
    .c focus test
} -body {
    .c itemconfig test -text "abcdefghijklmno" -anchor nw
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964
965
966
967
968



969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
924
925
926
927
928
929
930






931

932
933
934
935
936
937
938
939




940
941
942
943
944
945
946
947














948
949
950







-
-
-
-
-
-

-
+







-
-
-
-
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-



test canvText-20.1 {angled text bounding box} -setup {
    destroy .c
    canvas .c
    proc transpose {bbox} {
	lassign $bbox a b c d
	list $b $a $d $c
    }
    proc almosteq {b1 b2} {
        # check whether the two boxes are equal, with 1 unit tolerance on each x y w h
        lassign $b1 a b c d
        lassign $b2 e f g h
        expr {($e-$a)<=1 && ($f-$b)<=1 && ($g-$c)<=1 && ($h-$d)<=1}
    }
} -body {
    .c create text 2 2 -tag t -anchor center -text 0 -font {TkDefaultFont 24}
    .c create text 2 2 -tag t -anchor center -text 0 -font {Helvetica 24}
    set bb0 [.c bbox t]
    .c itemconf t -angle 90
    set bb1 [.c bbox t]
    .c itemconf t -angle 180
    set bb2 [.c bbox t]
    .c itemconf t -angle 270
    set bb3 [.c bbox t]
    # bboxes should be the same, possibly with a small (platform-specific) rounding difference
    list [expr {[almosteq $bb0 $bb2] ? "ok" : "$bb0,$bb2"}] \
	[expr {[almosteq $bb1 $bb3] ? "ok" : "$bb1,$bb3"}] \
	[expr {[almosteq $bb0 [transpose $bb1]] ? "ok" : "$bb0,$bb1"}]
    list [expr {$bb0 eq $bb2 ? "ok" : "$bb0,$bb2"}] \
	[expr {$bb1 eq $bb3 ? "ok" : "$bb1,$bb3"}] \
	[expr {$bb0 eq [transpose $bb1] ? "ok" : "$bb0,$bb1"}] \
} -cleanup {
    destroy .c
    rename transpose {}
} -result {ok ok ok}

test canvText-20.2 {crash on angled text selection (X11, without xft) - bug 2712f43f6e} -setup {
    destroy .c
    canvas .c -background bisque -selectforeground green2
    grid .c
    set id [.c create text 50 150 -anchor w -text "Angled text" \
	    -angle 30 -font {Helvetica 32} -fill darkblue]
} -body {
    .c select clear
    .c select from $id 0
    .c select to $id 8 ; update    ;  # used to crash on X11 (--disable-xft build only)
} -cleanup {
    destroy .c
} -result {}

# cleanup
cleanupTests
return

Changes to tests/canvWind.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in tkCanvWind.c,
# which implement canvas "window" items.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
135
136
137
138
139
140
141
















142
143
144







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



    .t.c xview scroll -1 units
    update
    lappend x [list [winfo ismapped $f] [winfo x $f]]
} -cleanup {
    destroy .t
} -result {{1 3} {1 -79} {0 -79} {1 255} {0 255}}

test canvWind-2.1 {DisplayWinItem, window gets destroyed during <Configure>} -setup {
    destroy .t
} -body {
    toplevel .t
    canvas .t.c
    pack .t.c
    frame .t.c.f -width 50 -height 50 -background red
    set id [.t.c create window 50 50 -window .t.c.f]
    update
    bind .t.c.f <Configure> {destroy .t.c.f}
    .t.c coords $id 60 60 ;  # was crashing
    update
} -cleanup {
    destroy .t
} -result {}

# cleanup
cleanupTests
return

Changes to tests/canvas.test.

1
2
3
4
5
6
7



8
9
10

11
12
13
14
15
16
17
1
2
3
4



5
6
7
8
9

10
11
12
13
14
15
16
17




-
-
-
+
+
+


-
+







# This file is a Tcl script to test out the procedures in tkCanvas.c, which
# implements generic code for canvases. It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1995-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright © 2008 Donal K. Fellows
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Ajuba Solutions.
# Copyright (c) 2008 Donal K. Fellows
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit

# XXX - This test file is woefully incomplete. At present, only a few of the
# features are tested.

33
34
35
36
37
38
39
40

41
42
43

44
45
46
47

48
49
50

51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99

100
101
102
103
104
105
106
107
108
109
110

111
112
113

114
115
116
117

118
119
120
121
122
123
124

125
126
127
128
129
130
131

132
133
134

135
136

137
138
139
140
141


142
143
144
145
146
147
148
149
150
151
152

153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173

174
175
176
177
178
179
180
33
34
35
36
37
38
39

40
41
42

43
44
45
46

47
48
49

50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98

99
100
101
102
103
104
105
106
107
108
109

110
111
112

113
114
115
116

117
118
119
120
121
122
123

124
125
126
127
128
129
130

131
132
133

134
135

136
137
138
139


140
141
142
143
144
145
146
147
148
149
150
151

152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172

173
174
175
176
177
178
179
180







-
+


-
+



-
+


-
+










-
+













-
+


-
+

















-
+


-
+










-
+


-
+



-
+






-
+






-
+


-
+

-
+



-
-
+
+










-
+


-
+














-
+


-
+







} -result {#ff0000}
test canvas-1.4 {configuration options: bad value for "bg"} -body {
    .c configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test canvas-1.5 {configuration options: good value for "bd"} -body {
    .c configure -bd 4
    .c cget -bd
} -result 4
} -result {4}
test canvas-1.6 {configuration options: bad value for "bd"} -body {
    .c configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test canvas-1.7 {configuration options: good value for "borderwidth"} -body {
    .c configure -borderwidth 1.3
    .c cget -borderwidth
} -result 1
} -result {1}
test canvas-1.8 {configuration options: bad value for "borderwidth"} -body {
    .c configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test canvas-1.9 {configuration options: good value for "closeenough"} -body {
    .c configure -closeenough 24
    .c cget -closeenough
} -result {24.0}
test canvas-1.10 {configuration options: bad value for "closeenough"} -body {
    .c configure -closeenough bogus
} -returnCodes error -result {expected floating-point number but got "bogus"}
test canvas-1.11 {configuration options: good value for "confine"} -body {
    .c configure -confine true
    .c cget -confine
} -result 1
} -result {1}
test canvas-1.12 {configuration options: bad value for "confine"} -body {
    .c configure -confine silly
} -returnCodes error -result {expected boolean value but got "silly"}
test canvas-1.13 {configuration options: good value for "cursor"} -body {
    .c configure -cursor arrow
    .c cget -cursor
} -result {arrow}
test canvas-1.14 {configuration options: bad value for "cursor"} -body {
    .c configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test canvas-1.15 {configuration options: good value for "height"} -body {
    .c configure -height 2.1
    .c cget -height
} -result 2
} -result {2}
test canvas-1.16 {configuration options: bad value for "height"} -body {
    .c configure -height x42
} -returnCodes error -result {expected screen distance but got "x42"}
} -returnCodes error -result {bad screen distance "x42"}
test canvas-1.17 {configuration options: good value for "highlightbackground"} -body {
    .c configure -highlightbackground #112233
    .c cget -highlightbackground
} -result {#112233}
test canvas-1.18 {configuration options: bad value for "highlightbackground"} -body {
    .c configure -highlightbackground ugly
} -returnCodes error -result {unknown color name "ugly"}
test canvas-1.19 {configuration options: good value for "highlightcolor"} -body {
    .c configure -highlightcolor #110022
    .c cget -highlightcolor
} -result {#110022}
test canvas-1.20 {configuration options: bad value for "highlightcolor"} -body {
    .c configure -highlightcolor bogus
} -returnCodes error -result {unknown color name "bogus"}
test canvas-1.21 {configuration options: good value for "highlightthickness"} -body {
    .c configure -highlightthickness 18
    .c cget -highlightthickness
} -result 18
} -result {18}
test canvas-1.22 {configuration options: bad value for "highlightthickness"} -body {
    .c configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test canvas-1.23 {configuration options: good value for "insertbackground"} -body {
    .c configure -insertbackground #110022
    .c cget -insertbackground
} -result {#110022}
test canvas-1.24 {configuration options: bad value for "insertbackground"} -body {
    .c configure -insertbackground bogus
} -returnCodes error -result {unknown color name "bogus"}
test canvas-1.25 {configuration options: good value for "insertborderwidth"} -body {
    .c configure -insertborderwidth 1.3
    .c cget -insertborderwidth
} -result 1
} -result {1}
test canvas-1.26 {configuration options: bad value for "insertborderwidth"} -body {
    .c configure -insertborderwidth 2.6x
} -returnCodes error -result {expected screen distance but got "2.6x"}
} -returnCodes error -result {bad screen distance "2.6x"}
test canvas-1.27 {configuration options: good value for "insertofftime"} -body {
    .c configure -insertofftime 100
    .c cget -insertofftime
} -result 100
} -result {100}
test canvas-1.28 {configuration options: bad value for "insertofftime"} -body {
    .c configure -insertofftime 3.2
} -returnCodes error -result {expected integer but got "3.2"}
test canvas-1.29 {configuration options: good value for "insertontime"} -body {
    .c configure -insertontime 100
    .c cget -insertontime
} -result 100
} -result {100}
test canvas-1.30 {configuration options: bad value for "insertontime"} -body {
    .c configure -insertontime 3.2
} -returnCodes error -result {expected integer but got "3.2"}
test canvas-1.31 {configuration options: good value for "insertwidth"} -body {
    .c configure -insertwidth 1.3
    .c cget -insertwidth
} -result 1
} -result {1}
test canvas-1.32 {configuration options: bad value for "insertwidth"} -body {
    .c configure -insertwidth 6x
} -returnCodes error -result {expected screen distance but got "6x"}
} -returnCodes error -result {bad screen distance "6x"}
test canvas-1.33 {configuration options: good value for "relief"} -body {
    .c configure -relief g
    .c configure -relief groove
    .c cget -relief
} -result {groove}
test canvas-1.34 {configuration options: bad value for "relief"} -body {
    .c configure -relief r
} -returnCodes error -result {bad relief "r": must be flat, groove, raised, ridge, solid, or sunken}
    .c configure -relief 1.5
} -returnCodes error -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
test canvas-1.35 {configuration options: good value for "selectbackground"} -body {
    .c configure -selectbackground #110022
    .c cget -selectbackground
} -result {#110022}
test canvas-1.36 {configuration options: bad value for "selectbackground"} -body {
    .c configure -selectbackground bogus
} -returnCodes error -result {unknown color name "bogus"}
test canvas-1.37 {configuration options: good value for "selectborderwidth"} -body {
    .c configure -selectborderwidth 1.3
    .c cget -selectborderwidth
} -result 1
} -result {1}
test canvas-1.38 {configuration options: bad value for "selectborderwidth"} -body {
    .c configure -selectborderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test canvas-1.39 {configuration options: good value for "selectforeground"} -body {
    .c configure -selectforeground #654321
    .c cget -selectforeground
} -result {#654321}
test canvas-1.40 {configuration options: bad value for "selectforeground"} -body {
    .c configure -selectforeground bogus
} -returnCodes error -result {unknown color name "bogus"}
test canvas-1.41 {configuration options: good value for "takefocus"} -body {
    .c configure -takefocus "any string"
    .c cget -takefocus
} -result {any string}
test canvas-1.42 {configuration options: good value for "width"} -body {
    .c configure -width 402
    .c cget -width
} -result 402
} -result {402}
test canvas-1.43 {configuration options: bad value for "width"} -body {
    .c configure -width xyz
} -returnCodes error -result {expected screen distance but got "xyz"}
} -returnCodes error -result {bad screen distance "xyz"}
test canvas-1.44 {configuration options: good value for "xscrollcommand"} -body {
    .c configure -xscrollcommand {Some command}
    .c cget -xscrollcommand
} -result {Some command}
test canvas-1.45 {configuration options: good value for "yscrollcommand"} -body {
    .c configure -yscrollcommand {Another command}
    .c cget -yscrollcommand
212
213
214
215
216
217
218
219



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229










230
231
232
233
234
235
236







-
+
+
+








-
-
-
-
-
-
-
-
-
-







    .c xview moveto 0
    update
    set x [list [.c xview]]
    .c xview scroll 2 units
    update
    lappend x [.c xview]
} -result {{0.0 0.3} {0.4 0.7}}
test canvas-2.4 {CanvasWidgetCmd, xview option} -body {
test canvas-2.4 {CanvasWidgetCmd, xview option} -constraints nonPortable -body {
    # This test gives slightly different results on platforms such as NetBSD.
    # I don't know why...
    .c configure -xscrollincrement 0 -yscrollincrement 5
    .c xview moveto 0.6
    update
    set x [list [.c xview]]
    .c xview scroll 2 units
    update
    lappend x [.c xview]
} -result {{0.6 0.9} {0.66 0.96}}
test canvas-2.5 {CanvasWidgetCmd, raise/lower option, no error on non-existing tags} -setup {
    .c create line 0 0 10 10 -tags aline
} -body {
    .c raise aline noline
    .c raise bline aline
    .c lower aline noline
    .c lower bline aline
} -cleanup {
    .c delete aline
} -result {}
catch {destroy .c}

# Canvas used in 3.* test cases
canvas .c -width 60 -height 40 -scrollregion {0 0 200 80} \
	-borderwidth 0 -highlightthickness 0
pack .c
update
344
345
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

384
385

386
387
388
389
390
391
392
336
337
338
339
340
341
342




343
344
















345
346
347
348
349
350
351
352
353
354
355
356

357
358

359
360
361
362
363
364
365
366







-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+

-
+







} -body {
    .c create arc -100 10 100 210 -start 10 -extent 50 -style arc -tags arc1
    set arcBox [.c bbox arc1]
    .c create arc 100 10 300 210 -start 10 -extent 50 -style chord -tags arc2
    set coordBox [.c bbox arc2]
    .c create arc 300 10 500 210 -start 10 -extent 50 -style pieslice -tags arc3
    set pieBox [.c bbox arc3]
    .c create arc 100 200 300 200 -height [expr {(1-0.5*sqrt(3))*200}] -style arc -tags arc4
    set arcSegBox [.c bbox arc4]
    list $arcBox $coordBox $pieBox $arcSegBox
} -result {{48 21 100 94} {248 21 300 94} {398 21 500 112} {98 171 302 202}}
    list $arcBox $coordBox $pieBox
} -result {{48 21 100 94} {248 21 300 94} {398 21 500 112}}
test canvas-8.2 {canvas very small arc} -setup {
    catch {destroy .c}
    canvas .c
} -body {
    # no Inf or NaN must be generated even for very small arcs
    .c create arc 0 100 0 100 -height 100 -style arc -outline "" -tags arc1
    set arcBox [.c bbox arc1]
    .c create arc 0 100 0 100 -height 100 -style arc -outline blue -tags arc2
    set outlinedArcBox [.c bbox arc2]
    set coords [.c coords arc1]
    set start [.c itemcget arc1 -start]
    set extent [.c itemcget arc1 -extent]
    set width [.c itemcget arc1 -width]
    set height [.c itemcget arc1 -height]
    list $arcBox $outlinedArcBox $coords $start $extent $width $height
} -result {{-1 99 1 101} {-2 98 2 102} {0.0 100.0 0.0 100.0} 0.0 0.0 1.0 0.0}

test canvas-9.1 {canvas id creation and deletion} -setup {
    catch {destroy .c}
    canvas .c
} -body {
    # With Tk 8.0.4 the ids are now stored in a hash table. You can use this
    # test as a performance test with older versions by changing the value of
    # size.
    set size 15
    for {set i 0} {$i < $size} {incr i} {
	set x [expr {-10 + 3*$i}]
	for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
	    .c create rect ${x}c ${y}c [expr {$x+2}]c [expr {$y+2}]c \
	    .c create rect ${x}c ${y}c [expr $x+2]c [expr $y+2]c \
		    -outline black -fill blue -tags rect
	    .c create text [expr {$x+1}]c [expr {$y+1}]c -text "$i,$j" \
	    .c create text [expr $x+1]c [expr $y+1]c -text "$i,$j" \
		    -anchor center -tags text
	}
    }
    # The actual bench mark - this code also exercises all the hash table
    # changes.
    set time [lindex [time {
	foreach id [.c find withtag all] {
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582







-
+







    }]
}
test canvas-13.1 {canvas delete during event, SF bug-228024} -body {
    kill_canvas .c
    set ::x {}
    # do this many times to improve chances of triggering the crash
    for {set i 0} {$i < 30} {incr i} {
	event generate .c <Button-1> -x 100 -y 100
	event generate .c <1> -x 100 -y 100
	event generate .c <ButtonRelease-1> -x 100 -y 100
    }
    return $::x
} -result {okokokokokokokokokokokokokokokokokokokokokokokokokokokokokok}

test canvas-14.1 {canvas scan SF bug 581560} -setup {
    destroy .c
749
750
751
752
753
754
755
756

757
758

759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
723
724
725
726
727
728
729

730
731

732
















733
734
735
736
737
738
739







-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







} -returnCodes error -body {
    .c create window 0
} -result {wrong # coordinates: expected 2, got 1}
test canvas-15.19 "basic coords check: centimeters are larger than pixels" -setup {
    destroy .c
    canvas .c
} -body {
    set id [.c create rect 0 0 1c 1c]
    set id [.c create rect 0 0 1cm 1cm]
    expr {[lindex [.c coords $id] 2]>1}
} -result 1
} -result {1}
test canvas-15.20 {bug [237971ce]} -setup {
    destroy .c
    canvas .c
} -body {
    set id [.c create line {0 0 50 50 100 50}]
    .c insert $id end {200 200}
    .c coords $id
} -result {0.0 0.0 50.0 50.0 100.0 50.0 200.0 200.0}
test canvas-15.21 {bug [237971ce]} -setup {
    destroy .c
    canvas .c
} -body {
    set id [.c create poly {0 0 50 50 100 50}]
    .c insert $id end {200 200}
    .c coords $id
} -result {0.0 0.0 50.0 50.0 100.0 50.0 200.0 200.0}
destroy .c

test canvas-16.1 {arc coords check} -setup {
    canvas .c
} -body {
    set id [.c create arc {0 10 20 30} -start 33]
    .c itemcget $id -start
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
895

896
897
898
899
900
901
902
838
839
840
841
842
843
844

845
846
847
848
849
850
851
852

853
854
855
856
857
858
859
860







-
+







-
+







test canvas-18.10 {imove method - errors} -setup {
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c imove $id 0 foobar 4
} -cleanup {
    destroy .c
} -returnCodes error -result {expected screen distance but got "foobar"}
} -returnCodes error -result {bad screen distance "foobar"}
test canvas-18.11 {imove method - errors} -setup {
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c imove $id 0 4 foobar
} -cleanup {
    destroy .c
} -returnCodes error -result {expected screen distance but got "foobar"}
} -returnCodes error -result {bad screen distance "foobar"}

test canvas-19.1 {rchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c rchars $id 2 4 {4 4}
    .c coords $id
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
946
947
948
949
950
951
952

























































































































































































































































































































953
954
955
956
957
958
959
960







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








} -body {
    set id [.c create line 0 0 1 1]
    .c rchars $id 1 foo {2 2}
} -cleanup {
    destroy .c
} -returnCodes error -result {bad index "foo"}

test canvas-20.1 {addtag/dtag - no shuffling of tag sequence} -setup {
    canvas .c
    .c create text 100 100 -text Hello
} -body {
    for {set i 1} {$i < 5} {incr i} {
        .c addtag tag$i all
    }
    # [.c addtags] only adds tags that are not already present
    .c addtag tag1 all   ; # no effect
    set res [list [.c gettags 1]]
    .c dtag 1 tag2
    lappend res [.c gettags 1]
} -cleanup {
    destroy .c
} -result {{tag1 tag2 tag3 tag4} {tag1 tag3 tag4}}
test canvas-20.2 {tag deletion - multiple tags with same name, no shuffling} -setup {
    canvas .c
    .c create text 100 100 -text Hello
} -body {
    # [.c itemconfigure -tags] lets the user add duplicate tags
    # this is not a problem although inconsistent with [.c addtags]
    .c itemconfigure 1 -tags {tagA tagB tagA tagA tagC tagA}
    set res [list [.c gettags 1]]
    .c dtag 1 tagA
    lappend res [.c gettags 1]
} -cleanup {
    destroy .c
} -result {{tagA tagB tagA tagA tagC tagA} {tagB tagC}}
test canvas-20.3 {tag deletion - all tags match} -setup {
    canvas .c
    .c create text 100 100 -text Hello
} -body {
    # [.c itemconfigure -tags] lets the user add duplicate tags
    # this is not a problem although inconsistent with [.c addtags]
    .c itemconfigure 1 -tags {tagA tagA tagA tagA tagA tagA}
    set res [list [.c gettags 1]]
    .c dtag 1 tagA
    lappend res [.c gettags 1]
} -cleanup {
    destroy .c
} -result {{tagA tagA tagA tagA tagA tagA} {}}

destroy .c
test canvas-21.1 {canvas rotate} -setup {
    pack [canvas .c]
} -body {
    .c create line 50 50 50 100 100 100
    .c rotate all 75 75 90
    lmap c [.c coords all] {format %.2f $c}
} -cleanup {
    destroy .c
} -result {50.00 100.00 100.00 100.00 100.00 50.00}
test canvas-21.2 {canvas rotate} -setup {
    pack [canvas .c]
} -body {
    .c create line 50 50 50 100 100 100
    .c rotate all 75 75 -10
    lmap c [.c coords all] {format %.2f $c}
} -cleanup {
    destroy .c
} -result {54.72 46.04 46.04 95.28 95.28 103.96}
test canvas-21.3 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate all 75 75
} -returnCodes error -cleanup {
    destroy .c
} -result {wrong # args: should be ".c rotate tagOrId x y angle"}
test canvas-21.4 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate all 75 75 123 123
} -returnCodes error -cleanup {
    destroy .c
} -result {wrong # args: should be ".c rotate tagOrId x y angle"}
test canvas-21.5 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate {!} 1 1 1
} -returnCodes error -cleanup {
    destroy .c
} -result {missing tag in tag search expression}
test canvas-21.6 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate all x 1 1
} -returnCodes error -cleanup {
    destroy .c
} -result {expected screen distance but got "x"}
test canvas-21.7 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate all 1 x 1
} -returnCodes error -cleanup {
    destroy .c
} -result {expected screen distance but got "x"}
test canvas-21.8 {canvas rotate: syntax} -setup {
    pack [canvas .c]
} -body {
    .c rotate all 1 1 x
} -returnCodes error -cleanup {
    destroy .c
} -result {expected floating-point number but got "x"}
test canvas-21.9 {canvas rotate: nothing to rotate} -setup {
    pack [canvas .c]
} -body {
    .c rotate all 75 75 10
} -cleanup {
    destroy .c
} -result {}
test canvas-21.10 {canvas rotate: multiple things to rotate} -setup {
    pack [canvas .c]
} -body {
    .c create line 50 50 50 100 -tag a
    .c create line 50 50 100 50 -tag b
    .c rotate all 75 75 45
    list [lmap c [.c coords a] {format %.2f $c}] [lmap c [.c coords b] {format %.2f $c}]
} -cleanup {
    destroy .c
} -result {{39.64 75.00 75.00 110.36} {39.64 75.00 75.00 39.64}}

test canvas-22.1 {canvas rotate: arc item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create arc 50 50 75 75 -start 45 -extent 90
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {-start -extent} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 125.00 75.00 150.00} {45.0 90.0} {52 123 73 140}}
test canvas-22.2 {canvas rotate: bitmap item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create bitmap 50 50 -bitmap info -anchor se
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {-bitmap -anchor} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 150.00} {info se} {42 129 50 150}}
test canvas-22.3 {canvas rotate: image item rotation behaviour} -setup {
    pack [canvas .c]
    image create photo dummy -width 50 -height 50
} -body {
    .c create image 50 50 -image dummy -anchor se
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {-image -anchor} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
    image delete dummy
} -result {{50.00 150.00} {dummy se} {0 100 50 150}}
test canvas-22.4 {canvas rotate: line item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create line 50 50 75 50 50 75 75 75
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 150.00 50.00 125.00 75.00 150.00 75.00 125.00} {} {48 123 77 152}}
test canvas-22.5 {canvas rotate: oval item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create oval 50 50 65 85
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{60.00 125.00 75.00 160.00} {} {59 124 76 161}}
test canvas-22.6 {canvas rotate: polygon item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create polygon 50 50 75 50 50 75 75 75
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 150.00 50.00 125.00 75.00 150.00 75.00 125.00} {} {48 123 77 152}}
test canvas-22.7 {canvas rotate: rectangle item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create rectangle 50 50 75 75
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 125.00 75.00 150.00} {} {49 124 76 151}}
test canvas-22.8 {canvas rotate: text item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create text 50 50 -text foo -angle 45
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {-text -angle} {.c itemcget all $o}]
    # [.c bbox all]
    # No testing of text bounding box; fonts too variable!
} -cleanup {
    destroy .c
} -result {{50.00 150.00} {foo 45.0}}
test canvas-22.9 {canvas rotate: window item rotation behaviour} -setup {
    pack [canvas .c]
} -body {
    .c create window 50 50 -window [frame .c.f -width 25 -height 25] \
	-anchor se
    .c rotate all 100 100 90
    list [lmap c [.c coords all] {format %.2f $c}] \
	[lmap o {} {.c itemcget all $o}] \
	[.c bbox all]
} -cleanup {
    destroy .c
} -result {{50.00 150.00} {} {25 125 50 150}}

# Procedure used in test cases 23.1 23.2 23.3
proc matchPixels {pixels expected} {
    set matched 1
    foreach pline $pixels eline $expected {
        foreach ppixel $pline epixel $eline {
            if {$ppixel != $epixel} {
                set matched 0
                break
            }
        }
    }
    return $matched
}

test canvas-23.1 {canvas image} -setup {
    canvas .c
    image create photo testimage
} -body  {
    .c configure -background #c0c0c0 -scrollregion {0 0 9 9}
    .c create rectangle 0 0 0 9 -fill #000080 -outline #000080
    .c image testimage
    matchPixels [testimage data] { \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
            {#000080 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0}}
} -cleanup {
    destroy .c
    image delete testimage
} -result 1

test canvas-23.2 {canvas image with subsample} -setup {
    canvas .c
    image create photo testimage
} -body  {
    .c configure -background #c0c0c0 -scrollregion {0 0 9 9}
    .c create rectangle 0 0 1 9 -fill #008000 -outline #008000
    .c image testimage 2
    matchPixels [testimage data] { \
        {#008000 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#008000 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#008000 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#008000 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#008000 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0}}
} -cleanup {
    destroy .c
    image delete testimage
} -result 1

test canvas-23.3 {canvas image with subsample and zoom} -setup {
    canvas .c
    image create photo testimage
} -body  {
    .c configure -background #c0c0c0 -scrollregion {0 0 9 9}
    .c create rectangle 0 0 9 0 -fill #800000 -outline #800000
    .c image testimage 1 2
    matchPixels [testimage data] { \
        {#800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000} \
        {#800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000 #800000} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0} \
        {#c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0 #c0c0c0}}
} -cleanup {
    destroy .c
    image delete testimage
} -result 1

# cleanup
imageCleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:

Changes to tests/choosedir.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test out Tk's "tk_chooseDir" and
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36







-
+








proc ToEnterDirsByKey {parent dirs} {
    after 100 [list EnterDirsByKey $parent $dirs]
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc EnterDirsByKey {parent dirs} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_choosedir
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91

92
93
94

95
96
97

98
99
100

101
102
103

104
105
106


107
108
109
110
111
112
113
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90

91
92
93

94
95
96

97
98
99

100



101
102


103
104
105
106
107
108
109
110
111







-
+
















-
+


-
+


-
+


-
+


-
+
-
-
-
+

-
-
+
+








    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
	event generate $w <KeyPress> -keysym Return
    }
}


#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------
# Make a dir for us to rely on for tests
set real [makeDirectory choosedirTest]
set dir [file dirname $real]
set fake [file join $dir non-existant]

set parent .

test choosedir-1.1 {tk_chooseDirectory command} -body {
test choosedir-1.1 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -initialdir
} -returnCodes error -result {value for "-initialdir" missing}
test choosedir-1.2 {tk_chooseDirectory command} -body {
test choosedir-1.2 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -mustexist
} -returnCodes error -result {value for "-mustexist" missing}
test choosedir-1.3 {tk_chooseDirectory command} -body {
test choosedir-1.3 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -parent
} -returnCodes error -result {value for "-parent" missing}
test choosedir-1.4 {tk_chooseDirectory command} -body {
test choosedir-1.4 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -title
} -returnCodes error -result {value for "-title" missing}
test choosedir-1.5.1 {tk_chooseDirectory command} -constraints notAqua -body {

    tk_chooseDirectory -foo bar
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test choosedir-1.5.2 {tk_chooseDirectory command} -constraints aqua -body {
test choosedir-1.5 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -foo bar
} -returnCodes error -result {bad option "-foo": must be -command, -initialdir, -message, -mustexist, -parent, or -title}
test choosedir-1.6 {tk_chooseDirectory command} -body {
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test choosedir-1.6 {tk_chooseDirectory command} -constraints unix -body {
    tk_chooseDirectory -parent foo.bar
} -returnCodes error -result {bad window path name "foo.bar"}


test choosedir-2.1 {tk_chooseDirectory command, cancel gives null} -constraints {
	unix notAqua
} -body {

Changes to tests/clipboard.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4


5
6
7
8
9
10
11
12
13





14
15
16
17
18
19
20




-
-
+
+







-
-
-
-
-







# This file is a Tcl script to test out Tk's clipboard management code,
# especially the "clipboard" command.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

#
# Note: Multiple display clipboard handling will only be tested if the
# environment variable TK_ALT_DISPLAY is set to an alternate display.
#

#################################################################
# Note that some of these tests may fail if another application #
# is grabbing the clipboard (e.g. an X server, or a VNC viewer) #
#################################################################

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# set up a very large buffer to test INCR retrievals
set longValue ""
162
163
164
165
166
167
168

169

170
171
172
173
174
175
176
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172







+
-
+







}  -returnCodes error -result {CLIPBOARD selection doesn't exist or form "STRING" not defined}
test clipboard-4.3 {ClipboardLostSel procedure} -setup {
    clipboard clear
} -body {
    clipboard append "Test"
    clipboard append -t TEST "Test2"
    selection clear -s CLIPBOARD
    catch {clipboard get}
    clipboard get -t TEST
	clipboard get -t TEST
} -cleanup {
    clipboard clear
}  -returnCodes error -result {CLIPBOARD selection doesn't exist or form "TEST" not defined}
test clipboard-4.4 {ClipboardLostSel procedure} -setup {
    clipboard clear
} -body {
    clipboard append "Test"
184
185
186
187
188
189
190

191

192
193
194
195
196
197
198
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195







+
-
+







test clipboard-4.5 {ClipboardLostSel procedure} -setup {
    clipboard clear
} -body {
    clipboard append "Test"
    clipboard append -t TEST "Test2"
    clipboard append "Test3"
    selection clear -s CLIPBOARD
    catch {clipboard get}
    clipboard get -t TEST
	clipboard get -t TEST
} -cleanup {
    clipboard clear
}  -returnCodes error -result {CLIPBOARD selection doesn't exist or form "TEST" not defined}



##############################################################################
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240







-
+







    clipboard append "first chunk"
    selection own -s CLIPBOARD .
	clipboard append " second chunk"
	clipboard get
} -cleanup {
    clipboard clear
}  -returnCodes ok -result {first chunk second chunk}
test clipboard-6.2 {Tk_ClipboardAppend procedure} -constraints x11 -setup {
test clipboard-6.2 {Tk_ClipboardAppend procedure} -constraints unix -setup {
    clipboard clear
} -body {
    setupbg
    clipboard append -f INTEGER -t TEST "16"
    set result [dobg {clipboard get TEST}]
    return $result
} -cleanup {

Changes to tests/clrpick.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test out Tk's "tk_chooseColor" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+







	    }
	}
	.c delete $i
	incr i
    }
    destroy .c
} else {
    testConstraint colorsLeftover 1
    testConstraint colorsLeftover 0
}

test clrpick-1.1 {tk_chooseColor command} -body {
    tk_chooseColor -foo
} -returnCodes error -result {bad option "-foo": must be -initialcolor, -parent, or -title}

test clrpick-1.2 {tk_chooseColor command } -body {
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107







-
+



















-
+







test clrpick-1.7 {tk_chooseColor command} -body {
    tk_chooseColor -initialcolor ##badbadbaadcolor
} -returnCodes error -result {invalid color name "##badbadbaadcolor"}


# tests 3.1 and 3.2 fail when individually run
# if there is no catch {tk_chooseColor -foo 1} msg
# before setting isNative
# before settin isNative
catch {tk_chooseColor -foo 1} msg
set isNative [expr {[info commands tk::dialog::color::] eq ""}]

proc ToPressButton {parent btn} {
    global isNative
    if {!$isNative} {
	after 200 "SendButtonPress . $btn mouse"
    }
}

proc ToChooseColorByKey {parent r g b} {
    global isNative
    if {!$isNative} {
	after 200 ChooseColorByKey . $r $g $b
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc ChooseColorByKey {parent r g b} {
    set w .__tk__color
    upvar ::tk::dialog::color::[winfo name $w] data

133
134
135
136
137
138
139
140

141
142

143
144
145
146
147
148













149
150
151
152
153
154
155
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168







-
+


+





-
+
+
+
+
+
+
+
+
+
+
+
+
+








    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
	event generate $w <KeyPress> -keysym Return
    }
}



test clrpick-2.1 {tk_chooseColor command} -constraints {
    nonUnixUserInteraction colorsLeftover
} -setup {
    set verylongstring [string repeat longstring: 100]
    set verylongstring longstring:
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    #set verylongstring $verylongstring$verylongstring
    # Interesting thing...when this is too long, the
    # delay caused in processing it kills the automated testing,
    # and makes a lot of the test cases fail.
    #set verylongstring $verylongstring$verylongstring
    #set verylongstring $verylongstring$verylongstring
    #set verylongstring $verylongstring$verylongstring
    #set verylongstring $verylongstring$verylongstring
} -body {
    ToPressButton . ok
    tk_chooseColor -title "Press Ok $verylongstring" -initialcolor #404040 \
        -parent .
} -result {#404040}
test clrpick-2.2 {tk_chooseColor command} -constraints {
    nonUnixUserInteraction colorsLeftover

Deleted tests/cluster.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246






















































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# This file is a Tcl script to test the [::tk::startOf|endOf]* functions in
# tk.tcl and tkIcu.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint needsICU [expr {[catch {info body ::tk::startOfCluster}]}]


test cluster-1.0 {::tk::startOfCluster} -body {
    ::tk::startOfCluster é -1
} -result {}
test cluster-1.1 {::tk::startOfCluster} -body {
    ::tk::startOfCluster é 0
} -result 0
test cluster-1.2 {::tk::startOfCluster} -constraints needsICU -body {
    ::tk::startOfCluster é 1
} -result 0
test cluster-1.3 {::tk::startOfCluster} -constraints needsICU -body {
    ::tk::startOfCluster é 2
} -result 2
test cluster-1.4 {::tk::startOfCluster} -constraints needsICU -body {
    ::tk::startOfCluster é 3
} -result 2
test cluster-1.5 {::tk::startOfCluster} -constraints needsICU -body {
    ::tk::startOfCluster é end
} -result 0
test cluster-1.6 {::tk::startOfCluster} -body {
    ::tk::startOfCluster é {}
} -result {}
test cluster-1.7 {::tk::startOfCluster} -constraints needsICU -body {
    ::tk::startOfCluster é end-1
} -result 0

test cluster-2.0 {::tk::endOfCluster} -body {
    ::tk::endOfCluster é -1
} -result 0
test cluster-2.1 {::tk::endOfCluster} -constraints needsICU -body {
    ::tk::endOfCluster é 0
} -result 2
test cluster-2.2 {::tk::endOfCluster} -constraints needsICU -body {
    ::tk::endOfCluster é 1
} -result 2
test cluster-2.3 {::tk::endOfCluster} -body {
    ::tk::endOfCluster é 2
} -result {}
test cluster-2.4 {::tk::endOfCluster} -body {
    ::tk::endOfCluster é 3
} -result {}
test cluster-2.5 {::tk::endOfCluster} -constraints needsICU -body {
    ::tk::endOfCluster é end
} -result 2
test cluster-2.6 {::tk::endOfCluster} -body {
    ::tk::endOfCluster é {}
} -result 0
test cluster-2.7 {::tk::endOfCluster} -constraints needsICU -body {
    ::tk::endOfCluster é end-1
} -result 2

test cluster-3.0 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" -1
} -result 2
test cluster-3.1 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 0
} -result 2
test cluster-3.2 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 1
} -result 2
test cluster-3.3 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 2
} -result {}
test cluster-3.4 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 3
} -result {}
test cluster-3.5 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 4
} -result {}
test cluster-3.6 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" 5
} -result {}
test cluster-3.7 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" end
} -result {}
test cluster-3.8 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" {}
} -result 2
test cluster-3.9 {::tk::endOfWord} -body {
    ::tk::endOfWord "ab cd" end-1
} -result {}

test cluster-4.0 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" -1
} -result {}
test cluster-4.1 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 0
} -result {}
test cluster-4.2 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 1
} -result 0
test cluster-4.3 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 2
} -result 0
test cluster-4.4 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 3
} -result 0
test cluster-4.5 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 4
} -result 3
test cluster-4.6 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" 5
} -result 3
test cluster-4.7 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" end
} -result 3
test cluster-4.8 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" {}
} -result {}
test cluster-4.9 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord "ab cd" end-1
} -result 0

test cluster-5.0 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" -1
} -result 3
test cluster-5.1 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 0
} -result 3
test cluster-5.2 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 1
} -result 3
test cluster-5.3 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 2
} -result 3
test cluster-5.4 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 3
} -result {}
test cluster-5.5 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 4
} -result {}
test cluster-5.6 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" 5
} -result {}
test cluster-5.7 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" end
} -result {}
test cluster-5.8 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" {}
} -result 3
test cluster-5.9 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord "ab cd" end-1
} -result {}

test cluster-6.0 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" -1
} -result {}
test cluster-6.1 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 0
} -result {}
test cluster-6.2 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 1
} -result {}
test cluster-6.3 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 2
} -result 2
test cluster-6.4 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 3
} -result 3
test cluster-6.5 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 4
} -result 3
test cluster-6.6 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" 5
} -result 3
test cluster-6.7 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" end
} -result 3
test cluster-6.8 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore "ab cd" {}
} -result {}
test cluster-6.9 {::tk::wordBreakBefore} -body {
    ::tk::startOfNextWord "ab cd" end-1
} -result {}

test cluster-7.0 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" -1
} -result 2
test cluster-7.1 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 0
} -result 2
test cluster-7.2 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 1
} -result 2
test cluster-7.3 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 2
} -result 3
test cluster-7.4 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 3
} -result {}
test cluster-7.5 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 4
} -result {}
test cluster-7.6 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" 5
} -result {}
test cluster-7.7 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" end
} -result {}
test cluster-7.8 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" {}
} -result 2
test cluster-7.9 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter "ab cd" end-1
} -result {}


test cluster-8.0 {::tk::startOfCluster} -body {
    ::tk::startOfCluster a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::startOfCluster str start ?locale?"}
test cluster-8.1 {::tk::endOfCluster} -body {
    ::tk::endOfCluster a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::endOfCluster str start ?locale?"}
test cluster-8.2 {::tk::startOfPreviousWord} -body {
    ::tk::startOfPreviousWord a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::startOfPreviousWord str start ?locale?"}
test cluster-8.3 {::tk::startOfNextWord} -body {
    ::tk::startOfNextWord a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::startOfNextWord str start ?locale?"}
test cluster-8.4 {::tk::endOfWord} -body {
    ::tk::endOfWord a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::endOfWord str start ?locale?"}
test cluster-8.5 {::tk::wordBreakBefore} -body {
    ::tk::wordBreakBefore a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::wordBreakBefore str start ?locale?"}
test cluster-8.6 {::tk::wordBreakAfter} -body {
    ::tk::wordBreakAfter a b c d
} -returnCodes 1 -result {wrong # args: should be "::tk::wordBreakAfter str start ?locale?"}

cleanupTests
return

Changes to tests/cmap.tcl.

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29







-
+







    set red 0
    set green 0
    set blue 0
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 8} {incr x} {
	    frame $w.f$x,$y -width 40 -height 40 -bd 2 -relief raised \
		    -bg [format #%02x%02x%02x $red $green $blue]
	    place $w.f$x,$y -x [expr {40*$x}] -y [expr {40*$y}]
	    place $w.f$x,$y -x [expr 40*$x] -y [expr 40*$y]
	    incr red $redInc
	    incr green $greenInc
	    incr blue $blueInc
	}
    }
}

Changes to tests/cmds.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test the procedures in the file
# tkCmds.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

Changes to tests/color.test.

1
2
3
4
5


6
7
8

9
10
11
12
13
14
15
1
2
3


4
5
6
7

8
9
10
11
12
13
14
15



-
-
+
+


-
+







# This file is a Tcl script to test out the procedures in the file
# tkColor.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995-1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

# cname --
# Returns a proper name for a color, given its intensities.
#
# Arguments:
158
159
160
161
162
163
164
165
166


167
168
169
170
171
172
173
158
159
160
161
162
163
164


165
166
167
168
169
170
171
172
173







-
-
+
+







    button .b2 -foreground $x -text Third
    pack .b2 -side top
    lappend result [testcolor purple]
} {{{1 1}} {{1 1} {1 0}} {{1 0} {2 1}}}
test color-1.5 {Color table} nonPortable {
    set fd [open ../xlib/rgb.txt]
    set result {}
    while {[gets $fd line] >= 0} {
	if {[string index $line 0] == "!"} continue
    while {[gets $fd line] != -1} {
    	if {[string index $line 0] == "!"} continue
	set rgb [c255 [winfo rgb . [lrange $line 3 end]]]
	if {$rgb != [lrange $line 0 2] } {
		append result $line\n
	}

    }
    return $result
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233







-
+













-
+







    winfo rgb . #abz
} -returnCodes error -result {invalid color name "#abz"}
test color-2.11 {Tk_GetColor, 6 hex digits, last one invalid} -body {
    winfo rgb . #12345g
} -returnCodes error -result {invalid color name "#12345g"}

test color-3.1 {Tk_FreeColor procedure, reference counting} colorsFree {
    destroy {*}[winfo children .t]
    eval destroy [winfo child .t]
    mkColors .t.c 40 6 0 240 240 0 -6 0 0 0 -40
    pack .t.c
    mkColors .t.c2 20 1 250 0 0 -10 0 0 0 0 0
    pack .t.c2
    update
    set last [.t.c2 create rectangle 50 50 70 60 -outline {} \
	    -fill [cname 0 240 240]]
    .t.c delete 1
    set result [colorsFree .t]
    .t.c2 delete $last
    lappend result [colorsFree .t]
} {0 1}
test color-3.2 {Tk_FreeColor procedure, flushing stressed cmap information} colorsFree {
    destroy {*}[winfo children .t]
    eval destroy [winfo child .t]
    mkColors .t.c 40 6 0 240 240 0 -6 0 0 0 -40
    pack .t.c
    mkColors .t.c2 20 1 250 0 0 -10 0 0 0 0 0
    mkColors .t.c2 20 1 250 250 0 -10 -10 0 0 0 0
    pack .t.c2
    update
    closest .t 241 241 1

Changes to tests/config.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test the procedures in tkConfig.c,
# which comprise the new new option configuration system.  It is
# organized in the standard "white-box" fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60







-
+







-
+







    testobjconfig alltypes .a
    lappend x [testobjconfig info alltypes]
    testobjconfig alltypes .b
    lappend x [testobjconfig info alltypes]
    set x
} -cleanup {
    killTables
} -result {{1 17 -boolean} {2 17 -boolean}}
} -result {{1 16 -boolean} {2 16 -boolean}}
test config-1.2 {Tk_CreateOptionTable - synonym initialization} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a -synonym green
    .a cget -color
} -cleanup {
    killTables
} -result green
} -result {green}
test config-1.3 {Tk_CreateOptionTable - option database initialization} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a
    option add *b.string different
    testobjconfig alltypes .b
    list [.a cget -string] [.b cget -string]
73
74
75
76
77
78
79
80

81
82
83

84
85
86
87
88
89
90
73
74
75
76
77
78
79

80
81
82

83
84
85
86
87
88
89
90







-
+


-
+







    killTables
    option clear
} -result {foo bar}
test config-1.5 {Tk_CreateOptionTable - default initialization} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a
    .a cget -anchor
    .a cget -relief
} -cleanup {
    killTables
} -result center
} -result {raised}
test config-1.6 {Tk_CreateOptionTable - chained tables} -constraints {
    testobjconfig
} -body {
    testobjconfig chain1 .a
    testobjconfig chain2 .b
    testobjconfig info chain2
} -cleanup {
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177

178
179
180
181
182

183
184
185
186
187
188
189
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176

177
178
179
180
181

182
183
184
185
186
187
188
189







-
+









-
+







-
+




-
+







} -body {
    option add *a.color blue
    testobjconfig alltypes .a
    list [.a cget -color]
} -cleanup {
    killTables
    option clear
} -result blue
} -result {blue}
test config-3.3 {Tk_InitOptions - initialize from database} -constraints {
    testobjconfig
} -body {
    option add *a.justify bogus
    testobjconfig alltypes .a
    list [.a cget -justify]
} -cleanup {
    killTables
    option clear
} -result left
} -result {left}
test config-3.4 {Tk_InitOptions - initialize from widget class} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a
    list [.a cget -color]
} -cleanup {
    killTables
} -result red
} -result {red}
test config-3.5 {Tk_InitOptions - no initial value} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a
    .a cget -relief
    .a cget -anchor
} -cleanup {
    killTables
} -result {}
test config-3.6 {Tk_InitOptions - bad initial value} -constraints {
    testobjconfig
} -body {
    option add *a.color non-existent
206
207
208
209
210
211
212
213

214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280

281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
206
207
208
209
210
211
212

213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279

280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305

306
307
308
309
310
311
312
313







-
+





-
+










-
+







-
+















-
+







-
+














-
+


-
+









-
+







-
+







-
+







    invoked from within
"testobjconfig alltypes .a"}

test config-3.8 {Tk_InitOptions - bad initial value} -constraints {
    testobjconfig
} -body {
    testobjconfig configerror
} -returnCodes error -result {expected integer or "" but got "bogus"}
} -returnCodes error -result {expected integer but got "bogus"}
test config-3.9 {Tk_InitOptions - bad initial value} -constraints {
    testobjconfig
} -body {
    catch {testobjconfig configerror}
    return $errorInfo
} -result {expected integer or "" but got "bogus"
} -result {expected integer but got "bogus"
    (default value for "-int")
    invoked from within
"testobjconfig configerror"}

test config-4.1 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 0
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.2 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 0
    .foo cget -boolean
} -cleanup {
    killTables
} -returnCodes ok -result 0
} -returnCodes ok -result {0}
test config-4.3 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 0
    .foo cget -boolean
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.4 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 1
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.5 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 1
    .foo cget -boolean
} -cleanup {
    killTables
} -returnCodes ok -result 1
} -returnCodes ok -result {1}
test config-4.6 {DoObjConfig - boolean} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean 1
    .foo cget -boolean
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.7 {DoObjConfig - invalid boolean} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -boolean foo
    testobjconfig alltypes .foo -boolean {}
} -cleanup {
    killTables
} -returnCodes error -result {expected boolean value or "" but got "foo"}
} -returnCodes error -result {expected boolean value but got ""}
test config-4.8 {DoObjConfig - boolean internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -boolean 0
    .foo cget -boolean
} -cleanup {
    killTables
} -result 0
} -result {0}

test config-4.9 {DoObjConfig - integer} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -integer 3
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.10 {DoObjConfig - integer} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -integer 3
    .foo cget -integer
} -cleanup {
    killTables
} -returnCodes ok -result 3
} -returnCodes ok -result {3}
test config-4.11 {DoObjConfig - integer} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -integer 3
    .foo cget -integer
    rename .foo {}
} -cleanup {
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359







-
+







-
+







-
+







} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -integer 421
    .foo cget -integer
} -cleanup {
    killTables
} -result 421
} -result {421}

test config-4.14 {DoObjConfig - double} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -double 3.14
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.15 {DoObjConfig - double} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -double 3.14
    .foo cget -double
} -cleanup {
    killTables
} -returnCodes ok -result 3.14
} -returnCodes ok -result {3.14}
test config-4.16 {DoObjConfig - double} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -double 3.14
    .foo cget -double
    rename .foo {}
} -cleanup {
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419







-
+







-
+







-
+















-
+







} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -double 62.75
    .foo cget -double
} -cleanup {
    killTables
} -result 62.75
} -result {62.75}

test config-4.19 {DoObjConfig - string} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -string test
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.20 {DoObjConfig - string} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -string test
    .foo cget -string
} -cleanup {
    killTables
} -returnCodes ok -result test
} -returnCodes ok -result {test}
test config-4.21 {DoObjConfig - string} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -string test
    .foo cget -string
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.22 {DoObjConfig - null string} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -string {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.23 {DoObjConfig - null string} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -string {}
    .foo cget -string
} -cleanup {
    killTables
439
440
441
442
443
444
445
446

447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467


468
469
470
471
472
473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516

517
518
519
520
521
522

523
524
525
526
527
528
529
439
440
441
442
443
444
445

446
447
448
449
450
451

452
453
454
455
456
457
458
459
460
461
462
463
464
465


466
467






468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503

504
505
506
507
508
509

510
511
512
513
514
515

516
517
518
519
520
521
522
523







-
+





-
+













-
-
+
+
-
-
-
-
-
-







-
+








-
+



















-
+





-
+





-
+







    killTables
} -result {this is a test}

test config-4.26 {DoObjConfig - string table} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -stringtable two
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.27 {DoObjConfig - string table} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -stringtable two
    .foo cget -stringtable
} -cleanup {
    killTables
} -returnCodes ok -result two
} -returnCodes ok -result {two}
test config-4.28 {DoObjConfig - string table} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -stringtable two
    .foo cget -stringtable
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.29 {DoObjConfig - invalid string table} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -stringtable foo
} -cleanup {
    killTables
} -returnCodes error -result {bad stringtable "foo": must be one, two, three, four, or ""}
test config-4.29a {DoObjConfig - invalid string table} -constraints {
} -returnCodes error -result {bad stringtable "foo": must be one, two, three, or four}

    testobjconfig
} -body {
    testobjconfig alltypes .foo -stringtable2 foo
} -cleanup {
    killTables
} -returnCodes error -result {bad stringtable2 "foo": must be one, two, or ""}
test config-4.30 {DoObjConfig - new string table} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -stringtable two
    .foo configure -stringtable three
} -cleanup {
    killTables
} -returnCodes ok -result 16
} -returnCodes ok -result {16}
test config-4.31 {DoObjConfig - new string table} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -stringtable two
    .foo configure -stringtable three
    .foo cget -stringtable
} -cleanup {
    killTables
} -returnCodes ok -result three
} -returnCodes ok -result {three}
test config-4.32 {DoObjConfig - new string table} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -stringtable two
    .foo configure -stringtable three
    .foo cget -stringtable
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.33 {DoObjConfig - stringtable internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -stringtable "four"
    .foo cget -stringtable
} -cleanup {
    killTables
} -result four
} -result {four}

test config-4.34 {DoObjConfig - color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color blue
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.35 {DoObjConfig - color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color blue
    .foo cget -color
} -cleanup {
    killTables
} -returnCodes ok -result blue
} -returnCodes ok -result {blue}
test config-4.36 {DoObjConfig - color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color blue
    .foo cget -color
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
539
540
541
542
543
544
545
546

547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
533
534
535
536
537
538
539

540
541
542
543
544
545

546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574







-
+





-
+




















-
+







} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -color purple
    .foo cget -color
} -cleanup {
    killTables
} -result purple
} -result {purple}

test config-4.39 {DoObjConfig - null color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.40 {DoObjConfig - null color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color {}
    .foo cget -color
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.41 {DoObjConfig - null color} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -color {}
    .foo cget -color
    rename .foo {}
} -cleanup {
    killTables
} -returnCodes ok
test config-4.42 {DoObjConfig - getting rid of old color} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -color #333333
    .foo configure -color #444444
} -cleanup {
    killTables
} -returnCodes ok -result 32
} -returnCodes ok -result {32}
test config-4.43 {DoObjConfig - getting rid of old color} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -color #333333
    .foo configure -color #444444
    .foo cget -color
} -cleanup {
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609

610
611
612
613
614
615
616
617







-
+















-
+








test config-4.45 {DoObjConfig - font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {Helvetica 72}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.46 {DoObjConfig - font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {Helvetica 72}
    .foo cget -font
} -cleanup {
    killTables
} -returnCodes ok -result {Helvetica 72}
test config-4.47 {DoObjConfig - new font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {Courier 12}
    .foo configure -font {Helvetica 72}
} -cleanup {
    killTables
} -returnCodes ok -result 64
} -returnCodes ok -result {64}
test config-4.48 {DoObjConfig - new font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {Courier 12}
    .foo configure -font {Helvetica 72}
    .foo cget -font
} -cleanup {
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642







-
+







} -returnCodes error -result {unknown font style "foo"}
test config-4.50 {DoObjConfig - null font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.51 {DoObjConfig - null font} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -font {}
    .foo cget -font
} -cleanup {
    killTables
658
659
660
661
662
663
664
665

666
667
668
669
670
671

672
673
674
675
676
677

678
679
680
681
682
683
684

685
686
687
688

689
690
691

692
693
694
695
696

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712

713
714
715
716
717
718

719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
652
653
654
655
656
657
658

659
660
661
662
663
664

665
666
667
668
669
670

671
672
673
674
675
676
677

678
679
680
681

682
683
684

685
686
687
688
689

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711

712
713
714
715
716
717

718
719
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
737







-
+





-
+





-
+






-
+



-
+


-
+




-
+















-
+





-
+





-
+











-
+







    killTables
} -result {Times 16}

test config-4.53 {DoObjConfig - bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap gray75
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.54 {DoObjConfig - bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap gray75
    .foo cget -bitmap
} -cleanup {
    killTables
} -returnCodes ok -result gray75
} -returnCodes ok -result {gray75}
test config-4.55 {DoObjConfig - new bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap gray75
    .foo configure -bitmap gray50
} -cleanup {
    killTables
} -returnCodes ok -result 128
} -returnCodes ok -result {128}
test config-4.56 {DoObjConfig - new bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap gray75
    .foo configure -bitmap gray50
    .foo cget -bitmap
} -cleanup {
    killTables
} -returnCodes ok -result gray50
} -returnCodes ok -result {gray50}
test config-4.57 {DoObjConfig - invalid bitmap} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -bitmap foobar
    testobjconfig alltypes .foo -bitmap foo
} -cleanup {
    killTables
} -returnCodes error -result {bitmap "foobar" not defined}
} -returnCodes error -result {bitmap "foo" not defined}
test config-4.58 {DoObjConfig - null bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.59 {DoObjConfig - null bitmap} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -bitmap {}
    .foo cget -bitmap
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.60 {DoObjConfig - bitmap internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -bitmap gray25
    .foo cget -bitmap
} -cleanup {
    killTables
} -result gray25
} -result {gray25}

test config-4.61 {DoObjConfig - border} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -border green
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.62 {DoObjConfig - border} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -border green
    .foo cget -border
} -cleanup {
    killTables
} -returnCodes ok -result green
} -returnCodes ok -result {green}
test config-4.63 {DoObjConfig - invalid border} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -border xxx
} -cleanup {
    killTables
} -returnCodes error -result {unknown color name "xxx"}
test config-4.64 {DoObjConfig - null border} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -border {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.65 {DoObjConfig - null border} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -border {}
    .foo cget -border
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.66 {DoObjConfig - border internal value} -constraints {
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

776
777
778
779
780
781

782
783
784
785
786
787
788

789
790
791
792
793
794
795
796

797
798
799
800
801
802

803
804
805
806
807
808
809

810
811
812
813
814
815

816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854

855
856
857
858
859
860
861
862
863
864

865
866
867
868
869
870

871
872
873
874
875
876

877
878
879
880
881

882
883
884
885
886
887

888
889
890
891
892
893
894

895
896
897
898
899
900
901
902
903
904

905
906
907
908
909
910

911
912
913
914
915
916

917
918
919
920
921

922
923
924
925
926
927

928
929
930
931
932
933
934

935
936
937
938
939
940
941
942
943
944

945
946
947
948
949

950
951
952
953
954
955

956
957
958
959
960

961
962
963
964
965
966

967
968
969
970
971
972
973

974
975
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992

993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
747
748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768

769
770
771
772
773
774

775
776
777
778
779
780
781

782
783
784
785
786
787
788
789

790
791
792
793
794
795

796
797
798
799
800
801
802

803
804
805
806
807
808

809
810
811
812
813
814

815
816
817
818
819
820
821
822
823
824
825
826

827
828
829
830
831
832
833
834
835
836
837
838
839
840

841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856
857

858
859
860
861
862
863

864
865
866
867
868
869

870
871
872
873
874

875
876
877
878
879
880

881
882
883
884
885
886
887

888
889
890
891
892
893
894
895
896
897

898
899
900
901
902
903

904
905
906
907
908
909

910
911
912
913
914

915
916
917
918
919
920

921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937

938
939
940
941
942

943
944
945
946
947
948

949
950
951
952
953

954
955
956
957
958
959

960
961
962
963
964
965
966

967
968
969
970
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985

986
987
988
989
990
991
992

993
994
995
996
997
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046







-
+














-
+





-
+






-
+







-
+





-
+






-
+





-
+





-
+











-
+













-
+






-
+









-
+





-
+





-
+




-
+





-
+






-
+









-
+





-
+





-
+




-
+





-
+






-
+









-
+




-
+





-
+




-
+





-
+






-
+











-
+






-
+






-
+











-
+














-
+








-
+









-
+







test config-4.67 {DoObjConfig - getting rid of old border} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -border #333333
    .foo configure -border #444444
} -cleanup {
    killTables
} -returnCodes ok -result 256
} -returnCodes ok -result {256}
test config-4.68 {DoObjConfig - getting rid of old border} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -border #333333
    .foo configure -border #444444
    .foo cget -border
} -cleanup {
    killTables
} -returnCodes ok -result {#444444}

test config-4.69 {DoObjConfig - relief} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -relief flat
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.70 {DoObjConfig - relief} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -relief flat
    .foo cget -relief
} -cleanup {
    killTables
} -returnCodes ok -result flat
} -returnCodes ok -result {flat}
test config-4.71 {DoObjConfig - invalid relief} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -relief foo
} -cleanup {
    killTables
} -returnCodes error -result {bad relief "foo": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes error -result {bad relief "foo": must be flat, groove, raised, ridge, solid, or sunken}
test config-4.72 {DoObjConfig - relief internal value} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -relief ridge
    .foo cget -relief
} -cleanup {
    killTables
} -result ridge
} -result {ridge}
test config-4.73 {DoObjConfig - new relief} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -relief raised
    .foo configure -relief flat
} -cleanup {
    killTables
} -returnCodes ok -result 512
} -returnCodes ok -result {512}
test config-4.74 {DoObjConfig - new relief} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -relief raised
    .foo configure -relief flat
    .foo cget -relief
} -cleanup {
    killTables
} -returnCodes ok -result flat
} -returnCodes ok -result {flat}

test config-4.75 {DoObjConfig - cursor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -cursor arrow
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.76 {DoObjConfig - cursor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -cursor arrow
    .foo cget -cursor
} -cleanup {
    killTables
} -returnCodes ok -result arrow
} -returnCodes ok -result {arrow}
test config-4.77 {DoObjConfig - invalid cursor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -cursor foo
} -cleanup {
    killTables
} -returnCodes error -result {bad cursor spec "foo"}
test config-4.78 {DoObjConfig - null cursor} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -cursor {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.79 {DoObjConfig - null cursor} -constraints testobjconfig -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig alltypes .foo -cursor {}
    .foo cget -cursor
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.80 {DoObjConfig - new cursor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -cursor xterm
    .foo configure -cursor arrow
} -cleanup {
    killTables
} -returnCodes ok -result 1024
} -returnCodes ok -result {1024}
test config-4.81 {DoObjConfig - new cursor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -cursor xterm
    .foo configure -cursor arrow
    .foo cget -cursor
} -cleanup {
    killTables
} -returnCodes ok -result arrow
} -returnCodes ok -result {arrow}
test config-4.82 {DoObjConfig - cursor internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -cursor watch
    .foo cget -cursor
} -cleanup {
    killTables
} -result watch
} -result {watch}

test config-4.83 {DoObjConfig - justify} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -justify center
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.84 {DoObjConfig - justify} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -justify center
    .foo cget -justify
} -cleanup {
    killTables
} -returnCodes ok -result center
} -returnCodes ok -result {center}
test config-4.85 {DoObjConfig - invalid justify} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -justify foo
} -cleanup {
    killTables
} -returnCodes error -result {bad justification "foo": must be left, right, center, or ""}
} -returnCodes error -result {bad justification "foo": must be left, right, or center}
test config-4.86 {DoObjConfig - new justify} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -justify left
    .foo configure -justify right
} -cleanup {
    killTables
} -returnCodes ok -result 2048
} -returnCodes ok -result {2048}
test config-4.87 {DoObjConfig - new justify} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -justify left
    .foo configure -justify right
    .foo cget -justify
} -cleanup {
    killTables
} -returnCodes ok -result right
} -returnCodes ok -result {right}
test config-4.88 {DoObjConfig - justify internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -justify center
    .foo cget -justify
} -cleanup {
    killTables
} -result center
} -result {center}

test config-4.89 {DoObjConfig - anchor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -anchor center
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.90 {DoObjConfig - anchor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -anchor center
    .foo cget -anchor
} -cleanup {
    killTables
} -returnCodes ok -result center
} -returnCodes ok -result {center}
test config-4.91 {DoObjConfig - invalid anchor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -anchor foo
} -cleanup {
    killTables
} -returnCodes error -result {bad anchor "foo": must be n, ne, e, se, s, sw, w, nw, center, or ""}
} -returnCodes error -result {bad anchor "foo": must be n, ne, e, se, s, sw, w, nw, or center}
test config-4.92 {DoObjConfig - new anchor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -anchor e
    .foo configure -anchor n
} -cleanup {
    killTables
} -returnCodes ok -result 4096
} -returnCodes ok -result {4096}
test config-4.93 {DoObjConfig - new anchor} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -anchor e
    .foo configure -anchor n
    .foo cget -anchor
} -cleanup {
    killTables
} -returnCodes ok -result n
} -returnCodes ok -result {n}
test config-4.94 {DoObjConfig - anchor internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -anchor sw
    .foo cget -anchor
} -cleanup {
    killTables
} -result sw
} -result {sw}
test config-4.95 {DoObjConfig - pixel} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -pixel 42
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.96 {DoObjConfig - pixel} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -pixel 42
    .foo cget -pixel
} -cleanup {
    killTables
} -returnCodes ok -result 42
} -returnCodes ok -result {42}
test config-4.97 {DoObjConfig - invalid pixel} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -pixel foo
} -cleanup {
    killTables
} -returnCodes error -result {expected screen distance or "" but got "foo"}
} -returnCodes error -result {bad screen distance "foo"}
test config-4.98 {DoObjConfig - new pixel} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -pixel 42m
    .foo configure -pixel 3c
} -cleanup {
    killTables
} -returnCodes ok -result 8192
} -returnCodes ok -result {8192}
test config-4.99 {DoObjConfig - new pixel} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -pixel 42m
    .foo configure -pixel 3c
    .foo cget -pixel
} -cleanup {
    killTables
} -returnCodes ok -result 3c
} -returnCodes ok -result {3c}
test config-4.100 {DoObjConfig - pixel internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -pixel [winfo screenmmwidth .]m
    set screenW [winfo screenwidth .]
    set result [.foo cget -pixel]
    expr {$screenW eq $result}
} -cleanup {
    killTables
} -result 1
} -result {1}

test config-4.101 {DoObjConfig - window} -constraints testobjconfig -body {
    toplevel .bar
    testobjconfig twowindows .foo -window .bar
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.102 {DoObjConfig - window} -constraints testobjconfig -body {
    toplevel .bar
    testobjconfig twowindows .foo -window .bar
    .foo cget -window
} -cleanup {
    killTables
} -returnCodes ok -result .bar
} -returnCodes ok -result {.bar}
test config-4.103 {DoObjConfig - invalid window} -constraints testobjconfig -body {
    toplevel .bar
    testobjconfig twowindows .foo -window foo
} -cleanup {
    killTables
} -returnCodes error -result {bad window path name "foo"}
test config-4.104 {DoObjConfig - null window} -constraints testobjconfig -body {
    toplevel .bar
    testobjconfig twowindows .foo -window {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.105 {DoObjConfig - null window} -constraints testobjconfig -body {
    toplevel .bar
    testobjconfig twowindows .foo -window {}
    .foo cget -window
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.106 {DoObjConfig - new window} -constraints testobjconfig -body {
    toplevel .bar
    toplevel .blamph
    testobjconfig twowindows .foo -window .bar
    .foo configure -window .blamph
} -cleanup {
    killTables
} -returnCodes ok -result 0
} -returnCodes ok -result {0}
test config-4.107 {DoObjConfig - new window} -constraints testobjconfig -body {
    toplevel .bar
    toplevel .blamph
    testobjconfig twowindows .foo -window .bar
    .foo configure -window .blamph
    .foo cget -window
} -cleanup {
    killTables
} -returnCodes ok -result .blamph
} -returnCodes ok -result {.blamph}
test config-4.108 {DoObjConfig - window internal value} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    testobjconfig internal .foo -window .
    .foo cget -window
} -cleanup {
    killTables
} -result .
} -result {.}

test config-4.109 {DoObjConfig - releasing old values} -constraints {
    testobjconfig
} -setup {
    catch {rename .foo {}}
} -body {
    # This test doesn't generate a useful value to check; if an
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102







-
+





-
+




-
+







    killTables
} -result {}

test config-4.111 {DoObjConfig - custom} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -custom test
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.112 {DoObjConfig - custom} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -custom test
    .foo cget -custom
} -cleanup {
    killTables
} -returnCodes ok -result TEST
} -returnCodes ok -result {TEST}
test config-4.113 {DoObjConfig - null custom} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -custom {}
} -cleanup {
    killTables
} -returnCodes ok -result .foo
} -returnCodes ok -result {.foo}
test config-4.114 {DoObjConfig - null custom} -constraints testobjconfig -body {
    testobjconfig alltypes .foo -custom {}
    .foo cget -custom
} -cleanup {
    killTables
} -returnCodes ok -result {}
test config-4.115 {DoObjConfig - custom internal value} -constraints {
1153
1154
1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168

1169
1170
1171
1172
1173
1174
1175
1147
1148
1149
1150
1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
1161

1162
1163
1164
1165
1166
1167
1168
1169







-
+







-
+







test config-6.2 {GetOptionFromObj - exact match} -constraints {
    testobjconfig
} -body {
    testobjconfig chain2 .a
    .a cget -one
} -cleanup {
    killTables
} -result one
} -result {one}
test config-6.3 {GetOptionFromObj - abbreviation} -constraints {
    testobjconfig
} -body {
    testobjconfig chain2 .a
    .a cget -fo
} -cleanup {
    killTables
} -result four
} -result {four}
test config-6.4 {GetOptionFromObj - ambiguous abbreviation} -constraints {
    testobjconfig
} -body {
    testobjconfig chain2 .a
    .a cget -on
} -cleanup {
    killTables
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227
1228
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214

1215
1216
1217
1218
1219
1220
1221
1222







-
+

















-
+










-
+







    killTables
} -result {two and a half}
test config-6.6 {GetOptionFromObj - synonym} -constraints testobjconfig -body {
    testobjconfig alltypes .b
    .b cget -synonym
} -cleanup {
    killTables
} -result red
} -result {red}


if {[testConstraint testobjconfig]} {
    testobjconfig alltypes .a
}
test config-7.1 {Tk_SetOptions - basics} -constraints testobjconfig -body {
    .a configure -color green -rel sunken
     list [.a cget -color] [.a cget -relief]
} -result {green sunken}
test config-7.2 {Tk_SetOptions - bogus option name} -constraints {
    testobjconfig
} -body {
    .a configure -bogus
} -returnCodes error -result {unknown option "-bogus"}
test config-7.3 {Tk_SetOptions - synonym} -constraints testobjconfig -body {
    .a configure -synonym blue
    .a cget -color
} -result blue
} -result {blue}
test config-7.4 {Tk_SetOptions - missing value} -constraints {
    testobjconfig
} -body {
    .a configure -color green -relief
} -returnCodes error -result {value for "-relief" missing}
test config-7.5 {Tk_SetOptions - missing value} -constraints {
    testobjconfig
} -body {
    catch {.a configure -color green -relief}
    .a cget -color
} -result green
} -result {green}
test config-7.6 {Tk_SetOptions - saving old values} -constraints {
    testobjconfig
} -body {
    .a configure -color red -int 7 -relief raised -double 3.14159
    .a csave -color green -int 432 -relief sunken -double 2.0 -color bogus
} -returnCodes error -result {unknown color name "bogus"}
test config-7.7 {Tk_SetOptions - saving old values} -constraints {
1260
1261
1262
1263
1264
1265
1266
1267

1268
1269
1270
1271
1272
1273
1274
1254
1255
1256
1257
1258
1259
1260

1261
1262
1263
1264
1265
1266
1267
1268







-
+







    return $errorInfo
} -result {unknown color name "bogus"
    (processing "-synonym" option)
    invoked from within
".a configure -synonym bogus"}
test config-7.12 {Tk_SetOptions - returning mask} -constraints testobjconfig -body {
    format %x [.a configure -color red -int 7 -relief raised -double 3.14159]
} -result 226
} -result {226}
test config-7.13 {Tk_SetOptions - error in DoObjConfig with custom option} -constraints {
    testobjconfig
} -body {
    .a configure -custom bad
} -returnCodes error -result {expected good value, got "BAD"}
test config-7.14 {Tk_SetOptions - error in DoObjConfig with custom option} -constraints {
    testobjconfig
1298
1299
1300
1301
1302
1303
1304
1305

1306
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1364
1365

1366
1367
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1409
1410
1411


1412
1413
1414
1415
1416


1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440
1441
1442

1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403


1404
1405
1406
1407
1408


1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429
1430

1431
1432
1433
1434
1435

1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465







-
+







-
+
















-
+
















-
+








-
+








-
+








-
+








-
+

















-
+








-
-
+
+



-
-
+
+


-
+








-
+








-
+




-
+



-
+








-
+








-
+







} -body {
    testobjconfig alltypes .a
    catch {.a csave -color green -color black -color blue \
	    -color #ffff00 -color #ff00ff -color bogus}
	.a cget -color
} -cleanup {
    killTables
} -result red
} -result {red}
test config-8.3 {Tk_RestoreSavedOptions - freeing object memory} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .a
    .a csave -color green -color black -color blue -color #ffff00 -color #ff00ff
} -cleanup {
    killTables
} -result 32
} -result {32}
test config-8.4 {Tk_RestoreSavedOptions - boolean internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    .a csave -boolean 0 -color bogus
} -cleanup {
    killTables
} -returnCodes error -match glob -result *
test config-8.5 {Tk_RestoreSavedOptions - boolean internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -boolean 0 -color bogus}
    .a cget -boolean
} -cleanup {
    killTables
} -result 1
} -result {1}
test config-8.6 {Tk_RestoreSavedOptions - integer internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    .a csave -integer 24 -color bogus
} -cleanup {
    killTables
} -returnCodes error -match glob -result *
test config-8.7 {Tk_RestoreSavedOptions - integer internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -integer 24 -color bogus}
    .a cget -integer
} -cleanup {
    killTables
} -result 148962237
} -result {148962237}
test config-8.8 {Tk_RestoreSavedOptions - double internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -double 62.4 -color bogus}
    .a cget -double
} -cleanup {
    killTables
} -result 3.14159
} -result {3.14159}
test config-8.9 {Tk_RestoreSavedOptions - string internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -string "A long string" -color bogus}
	.a cget -string
} -cleanup {
    killTables
} -result foo
} -result {foo}
test config-8.10 {Tk_RestoreSavedOptions - string table internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -stringtable three -color bogus}
	.a cget -stringtable
} -cleanup {
    killTables
} -result one
} -result {one}
test config-8.11 {Tk_RestoreSavedOptions - color internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -color green -color bogus}
    .a cget -color
} -cleanup {
    killTables
} -result red
} -result {red}
test config-8.12 {Tk_RestoreSavedOptions - font internal form} -constraints {
    testobjconfig nonPortable
} -body {
    testobjconfig internal .a
    catch {.a csave -font {Times 12} -color bogus}
    .a cget -font
} -cleanup {
    killTables
} -result {Helvetica 12}
test config-8.13 {Tk_RestoreSavedOptions - bitmap internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -bitmap questhead -color bogus}
    .a cget -bitmap
} -cleanup {
    killTables
} -result gray50
} -result {gray50}
test config-8.14 {Tk_RestoreSavedOptions - border internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -border brown -color bogus}
    .a cget -border
} -cleanup {
    killTables
} -result blue
test config-8.15 {Tk_RestoreSavedOptions - anchor internal form} -constraints {
} -result {blue}
test config-8.15 {Tk_RestoreSavedOptions - relief internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -anchor e -color bogus}
    .a cget -anchor
    catch {.a csave -relief sunken -color bogus}
    .a cget -relief
} -cleanup {
    killTables
} -result center
} -result {raised}
test config-8.16 {Tk_RestoreSavedOptions - cursor internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -cursor watch -color bogus}
    .a cget -cursor
} -cleanup {
    killTables
} -result xterm
} -result {xterm}
test config-8.17 {Tk_RestoreSavedOptions - justify internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -justify right -color bogus}
    .a cget -justify
} -cleanup {
    killTables
} -result left
} -result {left}
test config-8.18 {Tk_RestoreSavedOptions - anchor internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a
    catch {.a csave -anchor n -color bogus}
    catch {.a csave -anchor center -color bogus}
    .a cget -anchor
} -cleanup {
    killTables
} -result center
} -result {n}
test config-8.19 {Tk_RestoreSavedOptions - window internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a -window .a
    catch {.a csave -window .a -color bogus}
    .a cget -window
} -cleanup {
    killTables
} -result .a
} -result {.a}
test config-8.20 {Tk_RestoreSavedOptions - custom internal form} -constraints {
    testobjconfig
} -body {
    testobjconfig internal .a -custom "foobar"
    catch {.a csave -custom "barbaz" -color bogus}
    .a cget -custom
} -cleanup {
    killTables
} -result FOOBAR
} -result {FOOBAR}

# Most of the tests below will cause memory leakage if there is a
# problem.  This may not be evident unless the tests are run in
# conjunction with a memory usage analyzer such as Purify.

test config-9.1 {Tk_FreeConfigOptions/FreeResources - string internal form} -constraints {
    testobjconfig
1562
1563
1564
1565
1566
1567
1568
1569
1570


1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1556
1557
1558
1559
1560
1561
1562


1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583

1584
1585
1586
1587
1588
1589
1590
1591







-
-
+
+


-
+
















-
+







if {[testConstraint testobjconfig]} {
    killTables
}


test config-10.1 {Tk_GetOptionInfo - one item} -constraints testobjconfig -body {
    testobjconfig alltypes .foo
    .foo configure -anchor e
    .foo configure -anchor
    .foo configure -relief groove
    .foo configure -relief
} -cleanup {
    destroy .foo
} -result {-anchor anchor Anchor center e}
} -result {-relief relief Relief raised groove}
test config-10.2 {Tk_GetOptionInfo - one item, synonym} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo
    .foo configure -color black
    .foo configure -synonym
} -cleanup {
    destroy .foo
} -result {-color color Color red black}
test config-10.3 {Tk_GetOptionInfo - all items} -constraints {
    testobjconfig
} -body {
    testobjconfig alltypes .foo -font {Helvetica 18} -integer 13563
    .foo configure
} -cleanup {
    destroy .foo
} -result {{-boolean boolean Boolean {} {}} {-integer integer Integer 7 13563} {-double double Double 3.14159 3.14159} {-string string String foo foo} {-stringtable StringTable stringTable one one} {-stringtable2 StringTable2 stringTable2 two two} {-color color Color red red} {-font font Font {Helvetica 12} {Helvetica 18}} {-bitmap bitmap Bitmap gray50 gray50} {-border border Border blue blue} {-relief relief Relief {} {}} {-cursor cursor Cursor xterm xterm} {-justify {} {} left left} {-anchor anchor Anchor center center} {-pixel pixel Pixel 1 1} {-custom {} {} {} {}} {-synonym -color}}
} -result {{-boolean boolean Boolean 1 1} {-integer integer Integer 7 13563} {-double double Double 3.14159 3.14159} {-string string String foo foo} {-stringtable StringTable stringTable one one} {-color color Color red red} {-font font Font {Helvetica 12} {Helvetica 18}} {-bitmap bitmap Bitmap gray50 gray50} {-border border Border blue blue} {-relief relief Relief raised raised} {-cursor cursor Cursor xterm xterm} {-justify {} {} left left} {-anchor anchor Anchor {} {}} {-pixel pixel Pixel 1 1} {-custom {} {} {} {}} {-synonym -color}}
test config-10.4 {Tk_GetOptionInfo - chaining through tables} -constraints testobjconfig -body {
    testobjconfig chain2 .foo -one asdf -three xyzzy
    .foo configure
} -cleanup {
    destroy .foo
} -result {{-three three Three three xyzzy} {-four four Four four four} {-two two Two {two and a half} {two and a half}} {-oneAgain oneAgain OneAgain {one again} {one again}} {-one one One one asdf} {-two two Two two {two and a half}}}
if {[testConstraint testobjconfig]} {
1609
1610
1611
1612
1613
1614
1615
1616
1617


1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647

1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659

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
1603
1604
1605
1606
1607
1608
1609


1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

1623
1624
1625
1626

1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640

1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651
1652

1653
1654
1655
1656
1657
1658
1659
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







-
-
+
+











-
+



-
+













-
+



-
+







-
+









-
+





-
+





-
+



-
+



-
+



-
+



-
+







    testobjconfig
} -body {
    .a configure -justify
} -result {-justify {} {} left left}
test config-11.3 {GetConfigList - null default and current value} -constraints {
    testobjconfig
} -body {
    .a configure -relief
} -result {-relief relief Relief {} {}}
    .a configure -anchor
} -result {-anchor anchor Anchor {} {}}
if {[testConstraint testobjconfig]} {
    killTables
}


if {[testConstraint testobjconfig]} {
    testobjconfig internal .a
}
test config-12.1 {GetObjectForOption - boolean} -constraints testobjconfig -body {
    .a configure -boolean 0
    .a cget -boolean
} -result 0
} -result {0}
test config-12.2 {GetObjectForOption - integer} -constraints testobjconfig -body {
    .a configure -integer 1247
    .a cget -integer
} -result 1247
} -result {1247}
test config-12.3 {GetObjectForOption - double} -constraints testobjconfig -body {
    .a configure -double -88.82
    .a cget -double
} -result {-88.82}
test config-12.4 {GetObjectForOption - string} -constraints testobjconfig -body {
    .a configure -string "test value"
    .a cget -string
} -result {test value}
test config-12.5 {GetObjectForOption - stringTable} -constraints {
    testobjconfig
} -body {
    .a configure -stringtable "two"
    .a cget -stringtable
} -result two
} -result {two}
test config-12.6 {GetObjectForOption - color} -constraints testobjconfig -body {
    .a configure -color "green"
    .a cget -color
} -result green
} -result {green}
test config-12.7 {GetObjectForOption - font} -constraints testobjconfig -body {
    .a configure -font {Times 36}
    .a cget -font
} -result {Times 36}
test config-12.8 {GetObjectForOption - bitmap} -constraints testobjconfig -body {
    .a configure -bitmap "questhead"
    .a cget -bitmap
} -result questhead
} -result {questhead}
test config-12.9 {GetObjectForOption - border} -constraints testobjconfig -body {
    .a configure -border #33217c
    .a cget -border
} -result {#33217c}
test config-12.10 {GetObjectForOption - relief} -constraints {
    testobjconfig
} -body {
    .a configure -relief groove
    .a cget -relief
} -result groove
} -result {groove}
test config-12.11 {GetObjectForOption - cursor} -constraints {
    testobjconfig
} -body {
    .a configure -cursor watch
    .a cget -cursor
} -result watch
} -result {watch}
test config-12.12 {GetObjectForOption - justify} -constraints {
    testobjconfig
} -body {
    .a configure -justify right
    .a cget -justify
} -result right
} -result {right}
test config-12.13 {GetObjectForOption - anchor} -constraints testobjconfig -body {
    .a configure -anchor e
    .a cget -anchor
} -result e
} -result {e}
test config-12.14 {GetObjectForOption - pixels} -constraints testobjconfig -body {
    .a configure -pixel 193.2
    .a cget -pixel
} -result 193
} -result {193}
test config-12.15 {GetObjectForOption - window} -constraints testobjconfig -body {
    .a configure -window .a
    .a cget -window
} -result .a
} -result {.a}
test config-12.16 {GetObjectForOption -custom} -constraints testobjconfig -body {
    .a configure -custom foobar
    .a cget -custom
} -result FOOBAR
} -result {FOOBAR}
test config-12.17 {GetObjectForOption - null values} -constraints {
    testobjconfig
} -body {
    .a configure -string {} -color {} -font {} -bitmap {} -border {} \
	    -cursor {} -window {} -custom {}
    list [.a cget -string] [.a cget -color] [.a cget -font] \
	    [.a cget -bitmap] [.a cget -border] [.a cget -cursor] \

Changes to tests/constraints.tcl.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47







-
+











-
+



















-
+







if {[namespace exists tk::test]} {
    deleteWindows
    wm geometry . {}
    raise .
    return
}

package require tk
package require Tk 8.4
tk appname tktest
wm title . tktest
# If the main window isn't already mapped (e.g. because the tests are
# being run automatically) , specify a precise size for it so that the
# user won't have to position it manually.

if {![winfo ismapped .]} {
    wm geometry . +0+0
    update
}

package require tcltest 2.2
package require tcltest 2.1

namespace eval tk {
    namespace eval test {

	namespace export loadTkCommand
	proc loadTkCommand {} {
	    set tklib {}
	    foreach pair [info loaded {}] {
		foreach {lib pfx} $pair break
		if {$pfx eq "Tk"} {
		    set tklib $lib
		    break
		}
	    }
	    return [list load $tklib Tk]
	}

	namespace eval bg {
	    # Manage a background process.
	    # Replace with child interp or thread?
	    # Replace with slave interp or thread?
	    namespace import ::tcltest::interpreter
	    namespace import ::tk::test::loadTkCommand
	    namespace export setup cleanup do

	    proc cleanup {} {
		variable fd
		# catch in case the background process has closed $fd
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270
271
272
273
274
275


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355

356
357
358

359
360
361
362
363
364
365
117
118
119
120
121
122
123

124






125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174































































175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197

198




199


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237













238



239

240
















241

242
243
244
245
246
247
248
249

250
251
252

253
254
255
256
257
258
259
260







-
+
-
-
-
-
-
-














+






-
+








-
-
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-
+




-

-
-
-
-

-
-
+
+

















-
+


















-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







-
+


-
+







	}
	Export bg::setup as setupbg
	Export bg::cleanup as cleanupbg
	Export bg::do as dobg

	namespace export deleteWindows
	proc deleteWindows {} {
	    destroy {*}[winfo children .]
	    eval destroy [winfo children .]
	    # This update is needed to avoid intermittent failures on macOS in unixEmbed.test
	    # with the (GitHub Actions) CI runner.
	    # Reason for the failures is unclear but could have to do with window ids being deleted
	    # after the destroy command returns. The detailed mechanism of such delayed deletions
	    # is not understood, but it appears that this update prevents the test failures.
	    update
	}

	namespace export fixfocus
	proc fixfocus {} {
            catch {destroy .focus}
            toplevel .focus
            wm geometry .focus +0+0
            entry .focus.e
            .focus.e insert 0 "fixfocus"
            pack .focus.e
            update
            focus -force .focus.e
            destroy .focus
	}


        namespace export imageInit imageFinish imageCleanup imageNames
        variable ImageNames
        proc imageInit {} {
            variable ImageNames
            if {![info exists ImageNames]} {
                set ImageNames [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
                set ImageNames [lsort [image names]]
            }
            imageCleanup
            if {[lsort [image names]] ne $ImageNames} {
                return -code error "IMAGE NAMES mismatch: [image names] != $ImageNames"
            }
        }
        proc imageFinish {} {
            variable ImageNames
	    set imgs [lsearch -all -inline -glob -not [lsort [image names]] ::tk::icons::indicator*]
            if {$imgs ne $ImageNames} {
            if {[lsort [image names]] ne $ImageNames} {
                return -code error "images remaining: [image names] != $ImageNames"
            }
            imageCleanup
        }
        proc imageCleanup {} {
            variable ImageNames
            foreach img [image names] {
                if {$img ni $ImageNames} {image delete $img}
            }
        }
        proc imageNames {} {
            variable ImageNames
            set r {}
            foreach img [image names] {
                if {$img ni $ImageNames} {lappend r $img}
            }
            return $r
        }

	#
	#  CONTROL TIMING ASPECTS OF POINTER WARPING
	#
	# The proc [controlPointerWarpTiming] is intended to ensure that the (mouse)
	# pointer has actually been moved to its new position after a Tk test issued:
	#
	#    [event generate $w $event -warp 1 ...]
	#
	# It takes care of the following timing details of pointer warping:
	#
	# a. Allow pointer warping to happen if it was scheduled for execution at
	#    idle time. This happens synchronously if $w refers to the
	#    whole screen or if the -when option to [event generate] is "now".
	#
	# b. Work around a race condition associated with OS notification of
	#    mouse motion on Windows.
	#
	#    When calling [event generate $w $event -warp 1 ...], the following
	#    sequence occurs:
	#    - At some point in the processing of this command, either via a
	#      synchronous execution path, or asynchronously at idle time, Tk calls
	#      an OS function* to carry out the mouse cursor motion.
	#    - Tk has previously registered a callback function** with the OS, for
	#      the OS to call in order to notify Tk when a mouse move is completed.
	#    - Tk doesn't wait for the callback function to receive the notification
	#      from the OS, but continues processing. This suits most use cases
	#      because usually the notification arrives fast enough (within a few tens
	#      of microseconds). However ...
	#    - A problem arises if Tk performs some processing, immediately following
	#      up on [event generate $w $event -warp 1 ...], and that processing
	#      relies on the mouse pointer having actually moved. If such processing
	#      happens just before the notification from the OS has been received,
	#      Tk will be using not yet updated info (e.g. mouse coordinates).
	#
	#         Hickup, choke etc ... !
	#
	#            *  the function SendInput() of the Win32 API
	#            ** the callback function is TkWinChildProc()
	#
	#    This timing issue can be addressed by putting the Tk process on hold
	#    (do nothing at all) for a somewhat extended amount of time, while
	#    letting the OS complete its job in the meantime. This is what is
	#    accomplished by calling [after ms].
	#
	#    ----
	#    For the history of this issue please refer to Tk ticket [69b48f427e],
	#    specifically the comment on 2019-10-27 14:24:26.
	#
	#
	# Beware: there are cases, not (yet) exercised by the Tk test suite, where
	# [controlPointerWarpTiming] doesn't ensure the new position of the pointer.
	# For example, when issued under Tk8.7+, if the value for the -when option
	# to [event generate $w] is not "now", and $w refers to a Tk window, i.e. not
	# the whole screen.
	#
	proc controlPointerWarpTiming {{duration 50}} {
		update idletasks ;# see a. above
		if {[tk windowingsystem] eq "win32"} {
			after $duration ;# see b. above
		}
	}
	namespace export controlPointerWarpTiming

    }
}

namespace import -force tk::test::*

namespace import -force tcltest::testConstraint
testConstraint notAqua [expr {[tk windowingsystem] ne "aqua"}]
testConstraint aqua [expr {[tk windowingsystem] eq "aqua"}]
testConstraint x11 [expr {[tk windowingsystem] eq "x11"}]
testConstraint nonwin [expr {[tk windowingsystem] ne "win32"}]
testConstraint aquaOrWin32 [expr {
    ([tk windowingsystem] eq "win32") || [testConstraint aqua]
}]
testConstraint userInteraction 0
testConstraint nonUnixUserInteraction [expr {
    [testConstraint userInteraction] ||
    ([testConstraint unix] && [testConstraint notAqua])
}]
testConstraint haveDISPLAY [expr {[info exists env(DISPLAY)] && [testConstraint x11]}]
testConstraint haveDISPLAY [info exists env(DISPLAY)]
testConstraint altDisplay  [info exists env(TK_ALT_DISPLAY)]
testConstraint noExceed [expr {
    ![testConstraint unix] || [catch {font actual "\{xyz"}]
}]
testConstraint deprecated [expr {![::tk::build-info no-deprecate]}]

# constraint for running a test on all windowing system except aqua
# where the test fails due to a known bug
testConstraint aquaKnownBug [expr {[testConstraint notAqua] || [testConstraint knownBug]}]

# constraints for testing facilities defined in the tktest executable...
testConstraint testImageType [expr {"test" in [image types]}]
testConstraint testOldImageType [expr {"oldtest" in [image types]}]
testConstraint testImageType [expr {[lsearch [image types] test] >= 0}]
testConstraint testOldImageType [expr {[lsearch [image types] oldtest] >= 0}]
testConstraint testbitmap    [llength [info commands testbitmap]]
testConstraint testborder    [llength [info commands testborder]]
testConstraint testcbind     [llength [info commands testcbind]]
testConstraint testclipboard [llength [info commands testclipboard]]
testConstraint testcolor     [llength [info commands testcolor]]
testConstraint testcursor    [llength [info commands testcursor]]
testConstraint testembed     [llength [info commands testembed]]
testConstraint testfont      [llength [info commands testfont]]
testConstraint testmakeexist [llength [info commands testmakeexist]]
testConstraint testmenubar   [llength [info commands testmenubar]]
testConstraint testmetrics   [llength [info commands testmetrics]]
testConstraint testobjconfig [llength [info commands testobjconfig]]
testConstraint testsend      [llength [info commands testsend]]
testConstraint testtext      [llength [info commands testtext]]
testConstraint testwinevent  [llength [info commands testwinevent]]
testConstraint testwrapper   [llength [info commands testwrapper]]

# constraints about what sort of fonts are available
# constraint to see what sort of fonts are available
testConstraint fonts 1
destroy .e
entry .e -width 0 -font {Helvetica -12} -bd 1 -highlightthickness 1
.e insert end a.bcd
if {([winfo reqwidth .e] != 37) || ([winfo reqheight .e] != 20)} {
    testConstraint fonts 0
}
destroy .e
destroy .t
text .t -width 80 -height 20 -font {Times -14} -bd 1
pack .t
.t insert end "This is\na dot."
update
set x [list [.t bbox 1.3] [.t bbox 2.5]]
destroy .t
if {![string match {{22 3 6 15} {31 18 [34] 15}} $x]} {
    testConstraint fonts 0
}
# Although unexpected, some systems may have a very limited set of fonts available.
# The following constraints happen to evaluate to false at least on one system: the
# Github CI runner for Linux with --disable-xft, which has exactly ONE single font
# ([font families] returns a single element: "fixed"), for which [font actual]
# returns:
#    -family fixed -size 9 -weight normal -slant roman -underline 0
# and [font metrics] returns:
#    -ascent 11 -descent 2 -linespace 13 -fixed 1
# The following constraints are hence tailored to check exactly what is needed in the
# tests they constrain (that is: availability of any font having the given font
# attributes), so that these constrained tests will in fact run on all systems having
# reasonable font dotation.
testConstraint haveTimes12Font [expr {
testConstraint textfonts [expr {
    [font actual {times 12} -size] == 12
}]
testConstraint haveCourier37Font [expr {
    [testConstraint fonts] || [tk windowingsystem] eq "win32"
    [font actual {-family courier -size 37} -size] == 37
}]
testConstraint haveTimes14BoldFont [expr {
    ([font actual {times 14 bold} -size] == 14) &&
    ([font actual {times 14 bold} -weight] eq "bold")
}]
testConstraint haveTimes12BoldItalicUnderlineOverstrikeFont [expr {
    ([font actual {times 12 bold italic overstrike underline} -weight] eq "bold") &&
    ([font actual {times 12 bold italic overstrike underline} -slant] eq "italic") &&
    ([font actual {times 12 bold italic overstrike underline} -underline] eq "1") &&
    ([font actual {times 12 bold italic overstrike underline} -overstrike] eq "1")
}]
set fixedFont {Courier 12}   ; # warning: must be consistent with the files using the constraint below!
set bigFont   {Helvetica 24} ; # ditto
testConstraint haveBigFontTwiceLargerThanTextFont [expr {
    [font actual $fixedFont -size] * 2 <= [font actual $bigFont -size]
}]
unset fixedFont bigFont

# constraints for the visuals available
# constraints for the visuals available..
testConstraint pseudocolor8 [expr {
    ([catch {
	toplevel .t -visual {pseudocolor 8} -colormap new
    }] == 0) && ([winfo depth .t] == 8)
}]
destroy .t
testConstraint haveTruecolor24 [expr {
    {truecolor 24} in [winfo visualsavailable .]
    [lsearch -exact [winfo visualsavailable .] {truecolor 24}] >= 0
}]
testConstraint haveGrayscale8 [expr {
    {grayscale 8} in [winfo visualsavailable .]
    [lsearch -exact [winfo visualsavailable .] {grayscale 8}] >= 0
}]
testConstraint defaultPseudocolor8 [expr {
    ([winfo visual .] eq "pseudocolor") && ([winfo depth .] == 8)
}]

# constraint based on whether our display is secure
setupbg
384
385
386
387
388
389
390

279
280
281
282
283
284
285
286







+
namespace import -force tcltest::interpreter
namespace import -force tcltest::testsDirectory
namespace import -force tcltest::cleanupTests

deleteWindows
wm geometry . {}
raise .

Deleted tests/corruptMangled.gif.

cannot compute difference between binary files

Deleted tests/corruptMangled4G.gif.

1
2


-
-
GIF89a�f3��33�3�3�33����3���!�
,!x��-0Bw��ڥ���J�8U�kir/3Re7  ;

Deleted tests/corruptTruncated.gif.

cannot compute difference between binary files

Changes to tests/cursor.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in the file
# tkCursor.c.  It is organized in the standard white-box fashion for
# Tcl tests.
#
# Copyright © 1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Deleted tests/deferredClearCode.gif.

cannot compute difference between binary files

Changes to tests/dialog.test.

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44

45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63

64
65
66
67
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43

44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62

63
64
65
66
67







-
+










-
+




-
+









-
+








-
+





test dialog-2.1 {tk_dialog operation} -setup {
    proc PressButton {btn} {
        if {![winfo ismapped $btn]} {
            update
        }
        event generate $btn <Enter>
        event generate $btn <Button-1> -x 5 -y 5
        event generate $btn <1> -x 5 -y 5
        event generate $btn <ButtonRelease-1> -x 5 -y 5
    }
} -body {
    set x [after 5000 [list set tk::Priv(button) "no response"]]
    after 100 PressButton .d.button0
    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .d
} -result 0
} -result {0}
test dialog-2.2 {tk_dialog operation} -setup {
    proc HitReturn {w} {
        event generate $w <Enter>
        focus -force $w
        event generate $w <Key> -keysym Return
        event generate $w <KeyPress> -keysym Return
    }
} -body {
    set x [after 5000 [list set tk::Priv(button) "no response"]]
    after 100 HitReturn .d
    set res [tk_dialog .d foo foo info 1 click default]
    after cancel $x
    return $res
} -cleanup {
    destroy .d
} -result 1
} -result {1}
test dialog-2.3 {tk_dialog operation} -body {
    set x [after 5000 [list set tk::Priv(button) "no response"]]
    after 100 destroy .d
    set res [tk_dialog .d foo foo info 0 click]
    after cancel $x
    return $res
} -cleanup {
    destroy .b
} -result -1
} -result {-1}

cleanupTests
return

Changes to tests/earth.gif.

cannot compute difference between binary files

Changes to tests/embed.test.

1
2
3
4


5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2


3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20


-
-
+
+








-
+







# This file is a Tcl script to test out embedded Windows.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands


test embed-1.1 {Tk_UseWindow procedure, bad window identifier} -setup {
test embed-1.1 {TkpUseWindow procedure, bad window identifier} -setup {
    deleteWindows
} -body {
    toplevel .t -use xyz
} -cleanup {
    deleteWindows
} -returnCodes error -result {expected integer but got "xyz"}

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+










-
+











-
+










-
+







    toplevel .container -container 1
    toplevel .t -use [winfo id .container] -container 1
} -cleanup {
    deleteWindows
} -returnCodes error -result {windows cannot have both the -use and the -container option set}

# testing window embedding for win platforms
test embed-1.4.win {Tk_UseWindow procedure, -container must be set} -constraints {
test embed-1.4.win {TkpUseWindow procedure, -container must be set} -constraints {
	win
} -setup {
    deleteWindows
} -body {
    toplevel .container
    toplevel .embd -use [winfo id .container]
} -cleanup {
    deleteWindows
} -returnCodes error -result {the window to use is not a Tk container}
# testing window embedding for win platforms
test embed-1.5.win {Tk_UseWindow procedure, -container must be set} -constraints {
test embed-1.5.win {TkpUseWindow procedure, -container must be set} -constraints {
	win
} -setup {
    deleteWindows
} -body {
    frame .container
    toplevel .embd -use [winfo id .container]
} -cleanup {
    deleteWindows
} -returnCodes error -result {the window to use is not a Tk container}

# testing window embedding for other than win platforms
test embed-1.4.nonwin {Tk_UseWindow procedure, -container must be set} -constraints {
test embed-1.4.nonwin {TkpUseWindow procedure, -container must be set} -constraints {
	nonwin
} -setup {
    deleteWindows
} -body {
    toplevel .container
    toplevel .embd -use [winfo id .container]
} -cleanup {
    deleteWindows
} -returnCodes error -result {window ".container" doesn't have -container option set}
# testing window embedding for other than win platforms
test embed-1.5.nonwin {Tk_UseWindow procedure, -container must be set} -constraints {
test embed-1.5.nonwin {TkpUseWindow procedure, -container must be set} -constraints {
	nonwin
} -setup {
    deleteWindows
} -body {
    frame .container
    toplevel .embd -use [winfo id .container]
} -cleanup {

Changes to tests/entry.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
1
2
3



4
5
6
7
8
9
10
11
12
13
14

15
16
17
18

19
20
21
22
23
24
25
26



-
-
-
+
+
+








-




-
+







# This file is a Tcl script to test entry widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# For xscrollcommand
set scrollInfo {}
proc scroll args {
        global scrollInfo
        set scrollInfo $args
}
# For trace add variable
# For trace variable
proc override args {
        global x
        set x 12345
}

# Procedures used in widget VALIDATION tests
proc doval {W d i P s S v V} {
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73

74
75
76

77
78
79
80
81
82

83
84
85
86

87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113

114
115
116

117
118
119
120
121
122

123
124
125
126

127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193

194
195
196

197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313

314
315
316

317
318
319
320
321
322
323

324
325
326

327
328
329
330
331
332

333
334
335
336

337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356


357
358
359
360
361
362
363

364
365
366

367
368
369
370
371
372

373
374
375
376

377
378
379
380
381
382
383

384
385
386

387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403

404
405
406

407
408
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509

510
511
512
513
514
515
516

517
518
519

520
521
522
523
524
525

526
527
528
529

530
531
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609

610
611
612

613
614
615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71

72
73
74

75
76
77
78
79
80

81
82
83
84

85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111

112
113
114

115
116
117
118
119
120

121
122
123
124

125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191

192
193
194

195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311

312
313
314

315
316
317
318
319
320
321

322
323
324

325
326
327
328
329
330

331
332
333
334

335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353


354
355
356
357
358
359
360
361

362
363
364

365
366
367
368
369
370

371
372
373
374

375
376
377
378
379
380
381

382
383
384

385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401

402
403
404

405
406
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446

447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507

508
509
510
511
512
513
514

515
516
517

518
519
520
521
522
523

524
525
526
527

528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
555
556
557
558

559
560
561
562
563
564
565
566
567
568

569
570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607

608
609
610

611
612
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629

















630
631
632
633
634
635
636
637
638
639

640
641
642
643
644
645
646
647







-
+









-
+









-
+






-
+


-
+





-
+



-
+









-
+









-
+






-
+


-
+





-
+



-
+









-
+









-
+









-
+









-
+









-
+









-
+






-
+


-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+






-
+


-
+






-
+


-
+





-
+



-
+









-
+








-
-
+
+






-
+


-
+





-
+



-
+






-
+


-
+









-
+






-
+


-
+









-
+










-
+










-
+









-
+









-
+









-
+









-
+










-
+









-
+









-
+






-
+


-
+





-
+



-
+









-
+









-
+










-
+









-
+









-
+










-
+










-
+






-
+


-
+









-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
+







}

set cy [font metrics {Courier -12} -linespace]


test entry-1.1 {configuration option: "background" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -background #ff0000
    .e cget -background
} -cleanup {
    destroy .e
} -result {#ff0000}
test entry-1.2 {configuration option: "background" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -background non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.3 {configuration option: "bd" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -bd 4
    .e cget -bd
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-1.4 {configuration option: "bd" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -bd badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test entry-1.5 {configuration option: "bg" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -bg #ff0000
    .e cget -bg
} -cleanup {
    destroy .e
} -result {#ff0000}
test entry-1.6 {configuration option: "bg" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -bg non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.7 {configuration option: "borderwidth" for entry} -setup {
    entry .e -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -borderwidth 1.3
    .e cget -borderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-1.8 {configuration option: "borderwidth" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -borderwidth badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test entry-1.9 {configuration option: "cursor" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -cursor arrow
    .e cget -cursor
} -cleanup {
    destroy .e
} -result {arrow}
test entry-1.10 {configuration option: "cursor" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -cursor badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {bad cursor spec "badValue"}

test entry-1.11 {configuration option: "disabledbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -disabledbackground green
    .e cget -disabledbackground
} -cleanup {
    destroy .e
} -result {green}
test entry-1.12 {configuration option: "disabledbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -disabledbackground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.13 {configuration option: "disabledforeground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -disabledforeground blue
    .e cget -disabledforeground
} -cleanup {
    destroy .e
} -result {blue}
test entry-1.14 {configuration option: "disabledforeground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -disabledforeground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.15 {configuration option: "exportselection" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -exportselection yes
    .e cget -exportselection
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-1.16 {configuration option: "exportselection" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -exportselection xyzzy
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected boolean value but got "xyzzy"}

test entry-1.17 {configuration option: "fg" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -fg #110022
    .e cget -fg
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.18 {configuration option: "fg" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -fg non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.19 {configuration option: "font" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -font {Helvetica -12}
    .e cget -font
} -cleanup {
    destroy .e
} -result {Helvetica -12}
test entry-1.20 {configuration option: "font" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -font {}
} -cleanup {
    destroy .e
} -returnCodes {error} -result {font "" doesn't exist}

test entry-1.21 {configuration option: "foreground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -foreground #110022
    .e cget -foreground
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.22 {configuration option: "foreground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -foreground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.23 {configuration option: "highlightbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightbackground #110022
    .e cget -highlightbackground
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.24 {configuration option: "highlightbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightbackground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.25 {configuration option: "highlightcolor" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightcolor #110022
    .e cget -highlightcolor
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.26 {configuration option: "highlightcolor" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightcolor non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.27 {configuration option: "highlightthickness" for entry} -setup {
    entry .e -borderwidth 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightthickness 6
    .e cget -highlightthickness
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test entry-1.28 {configuration option: "highlightthickness" for entry} -setup {
    entry .e -borderwidth 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightthickness -2
    .e cget -highlightthickness
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test entry-1.29 {configuration option: "highlightthickness" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -highlightthickness badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test entry-1.30 {configuration option: "insertbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertbackground #110022
    .e cget -insertbackground
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.31 {configuration option: "insertbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertbackground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.32 {configuration option: "insertborderwidth" for entry} -setup {
    entry .e -borderwidth 2 -insertwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e
    update
} -body {
    .e configure -insertborderwidth 1.3
    .e cget -insertborderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-1.33 {configuration option: "insertborderwidth" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertborderwidth 2.6x
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "2.6x"}
} -returnCodes {error} -result {bad screen distance "2.6x"}

test entry-1.34 {configuration option: "insertofftime" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertofftime 100
    .e cget -insertofftime
} -cleanup {
    destroy .e
} -result 100
} -result {100}
test entry-1.35 {configuration option: "insertofftime" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertofftime 3.2
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected integer but got "3.2"}

test entry-1.36 {configuration option: "insertontime" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertontime 100
    .e cget -insertontime
} -cleanup {
    destroy .e
} -result 100
} -result {100}
test entry-1.37 {configuration option: "insertontime" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -insertontime 3.2
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected integer but got "3.2"}

test entry-1.38 {configuration option: "invalidcommand" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -invalidcommand "any string"
    .e cget -invalidcommand
} -cleanup {
    destroy .e
} -result {any string}

test entry-1.39 {configuration option: "invcmd" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -invcmd "any string"
    .e cget -invcmd
} -cleanup {
    destroy .e
} -result {any string}

test entry-1.40 {configuration option: "justify" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -justify right
    .e cget -justify
} -cleanup {
    destroy .e
} -result {right}
test entry-1.41 {configuration option: "justify" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -justify bogus
} -cleanup {
    destroy .e
} -returnCodes {error} -result {bad justification "bogus": must be left, right, or center}

test entry-1.42 {configuration option: "readonlybackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -readonlybackground green
    .e cget -readonlybackground
} -cleanup {
    destroy .e
} -result {green}
test entry-1.43 {configuration option: "readonlybackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -readonlybackground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.44 {configuration option: "relief" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -relief flat
    .e cget -relief
} -cleanup {
    destroy .e
} -result {flat}

test entry-1.45 {configuration option: "selectbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectbackground #110022
    .e cget -selectbackground
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.46 {configuration option: "selectbackground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectbackground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.47 {configuration option: "selectborderwidth" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectborderwidth 1.3
    .e cget -selectborderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-1.48 {configuration option: "selectborderwidth" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectborderwidth badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test entry-1.49 {configuration option: "selectforeground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectforeground #110022
    .e cget -selectforeground
} -cleanup {
    destroy .e
} -result {#110022}
test entry-1.50 {configuration option: "selectforeground" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -selectforeground non-existent
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "non-existent"}

test entry-1.51 {configuration option: "show" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -show *
    .e cget -show
} -cleanup {
    destroy .e
} -result {*}

test entry-1.52 {configuration option: "state" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -state n
    .e cget -state
} -cleanup {
    destroy .e
} -result {normal}
test entry-1.53 {configuration option: "state" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -state bogus
} -cleanup {
    destroy .e
} -returnCodes {error} -result {bad state "bogus": must be disabled, normal, or readonly}

test entry-1.54 {configuration option: "takefocus" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -takefocus "any string"
    .e cget -takefocus
} -cleanup {
    destroy .e
} -result {any string}

test entry-1.55 {configuration option: "textvariable" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -textvariable i
    .e cget -textvariable
} -cleanup {
    destroy .e
} -result {i}

test entry-1.56 {configuration option: "width" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -width 402
    .e cget -width
} -cleanup {
    destroy .e
} -result 402
} -result {402}
test entry-1.57 {configuration option: "width" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -width 3p
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected integer but got "3p"}

test entry-1.58 {configuration option: "xscrollcommand" for entry} -setup {
    entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -xscrollcommand {Some command}
    .e cget -xscrollcommand
} -cleanup {
    destroy .e
} -result {Some command}

test entry-1.59 {configuration option: "-placeholder"} -setup {
    pack [entry .e]
} -body {
    .e configure -placeholder {Some text}
    .e cget -placeholder
} -cleanup {
    destroy .e
} -result {Some text}

test entry-1.60 {configuration option: "-placeholderforeground"} -setup {
    pack [entry .e]
} -body {
    .e configure -placeholder {Some text} -placeholderforeground red
    .e cget -placeholderforeground
} -cleanup {
    destroy .e
} -result {red}


test entry-2.1 {Tk_EntryCmd procedure} -body {
    entry
} -returnCodes error -result {wrong # args: should be "entry pathName ?-option value ...?"}
test entry-2.2 {Tk_EntryCmd procedure} -body {
    entry gorp
} -returnCodes error -result {bad window path name "gorp"}
test entry-2.3 {Tk_EntryCmd procedure} -body {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
    list [winfo exists .e] [winfo class .e] [info commands .e]
} -cleanup {
    destroy .e
} -result {1 Entry .e}
test entry-2.4 {Tk_EntryCmd procedure} -body {
    entry .e -gorp foo
677
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
710
711

712
713
714
715
716
717
718
719
720

721
722
723
724
725
726
727
728
729
730
731
732
733
734
735

736
737
738
739
740
741
742
743
744
745
746
747
748

749
750
751
752

753
754
755
756
757
758
759
760
761

762
763
764
765

766
767
768
769
770
771
772

773
774
775
776
777
778
779
780
781
782
783
784

785
786
787

788
789
790
791
792
793
794
659
660
661
662
663
664
665

666
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682
683

684
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726
727
728
729

730
731
732
733

734
735
736
737
738
739
740
741
742

743
744
745
746

747
748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765

766
767
768

769
770
771
772
773
774
775
776







-
+








-
+








-
+








-
+








-
+














-
+












-
+



-
+








-
+



-
+






-
+











-
+


-
+







} -cleanup {
    destroy .e
} -result {.e}


test entry-3.1 {EntryWidgetCmd procedure} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e option ?arg ...?"}
test entry-3.2 {EntryWidgetCmd procedure, "bbox" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e bbox
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e bbox index"}
test entry-3.3 {EntryWidgetCmd procedure, "bbox" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e bbox a b
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e bbox index"}
test entry-3.4 {EntryWidgetCmd procedure, "bbox" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e bbox bogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "bogus"}
test entry-3.5 {EntryWidgetCmd procedure, "bbox" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
   .e bbox 0
} -cleanup {
    destroy .e
} -result [list 5 5 0 $cy]

# Previously the result was count using previousli counted font measurements
# and metrics. It was changed to less verbose solution - the result is the one
# that passes fonts constraint (this concerns tests 3.6, 3.7, 3.8, 3.10)
test entry-3.6 {EntryWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): no utf chars
    .e insert 0 "abc"
    list [.e bbox 3] [.e bbox end]
} -cleanup {
    destroy .e
} -result {{19 5 7 13} {19 5 7 13}}
test entry-3.7 {EntryWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): utf at end
    .e insert 0 "ab"
    .e insert 0 "ab\u4e4e"
    .e bbox end
} -cleanup {
    destroy .e
} -result {19 5 12 13}
test entry-3.8 {EntryWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): utf before index
    .e insert 0 "abc"
    .e insert 0 "ab\u4e4ec"
    .e bbox 3
} -cleanup {
    destroy .e
} -result {31 5 7 13}
test entry-3.9 {EntryWidgetCmd procedure, "bbox" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): no chars
    .e bbox end
} -cleanup {
    destroy .e
} -result "5 5 0 $cy"
test entry-3.10 {EntryWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert 0 "abcdefghijklmnop"
    .e insert 0 "abcdefghij\u4e4eklmnop"
    list [.e bbox 0] [.e bbox 1] [.e bbox 10] [.e bbox end]
} -cleanup {
    destroy .e
} -result {{5 5 7 13} {12 5 7 13} {75 5 12 13} {122 5 7 13}}
test entry-3.11 {EntryWidgetCmd procedure, "cget" widget command} -setup {
    entry .e
} -body {
813
814
815
816
817
818
819
820

821
822
823

824
825
826
827
828
829

830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

846
847
848
849
850
851
852
795
796
797
798
799
800
801

802
803
804

805
806
807
808
809
810

811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826

827
828
829
830
831
832
833
834







-
+


-
+





-
+















-
+







test entry-3.14 {EntryWidgetCmd procedure, "cget" widget command} -setup {
    entry .e
} -body {
    .e configure -bd 4
    .e cget -bd
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-3.15 {EntryWidgetCmd procedure, "configure" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    llength [.e configure]
} -cleanup {
    destroy .e
} -result 38
} -result {36}
test entry-3.16 {EntryWidgetCmd procedure, "configure" widget command} -setup {
    entry .e
} -body {
    .e configure -foo
} -cleanup {
    destroy .e
} -returnCodes error -result {unknown option "-foo"}
test entry-3.17 {EntryWidgetCmd procedure, "configure" widget command} -setup {
    entry .e
} -body {
    .e configure -bd 4
    .e configure -bg #ffffff
    lindex [.e configure -bd] 4
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-3.18 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
} -body {
    .e delete
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e delete firstIndex ?lastIndex?"}
869
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
892
893

894
895
896

897
898
899
900
901

902
903
904
905

906
907
908
909

910
911
912
913
914

915
916
917

918
919
920
921
922
923
924
925

926
927
928

929
930
931
932
933
934
935
936
937
938

939
940
941

942
943
944
945
946
947
948
949
950
951

952
953
954
955
956
957
958
851
852
853
854
855
856
857

858
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873
874

875
876
877

878
879
880
881
882

883
884
885
886

887
888
889
890

891
892
893
894
895

896
897
898

899
900
901
902
903
904
905
906

907
908
909

910
911
912
913
914
915
916
917
918
919

920
921
922

923
924
925
926
927
928
929
930
931
932

933
934
935
936
937
938
939
940







-
+







-
+








-
+


-
+




-
+



-
+



-
+




-
+


-
+







-
+


-
+









-
+


-
+









-
+







} -body {
    .e delete 0 bar
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "bar"}
test entry-3.22 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e delete 2 4
    .e get
} -cleanup {
    destroy .e
} -result 014567890
} -result {014567890}
test entry-3.23 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
} -body {
    .e insert end "01234567890"
    .e delete 6
    .e get
} -cleanup {
    destroy .e
} -result 0123457890
} -result {0123457890}
test entry-3.24 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
    set x {}
} -body {
# UTF
    .e insert end "0123467890"
    .e insert end "01234\u4e4e67890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123457890"
    .e insert end "012345\u4e4e7890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123456890"
    .e insert end "0123456\u4e4e890"
    .e delete 6
    lappend x [.e get]
} -cleanup {
    destroy .e
} -result [list "012347890" "0123457890" "012345890"]
} -result [list "01234\u4e4e7890" "0123457890" "012345\u4e4e890"]
test entry-3.25 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e delete 6 5
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test entry-3.26 {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state disabled
    .e delete 2 8
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test entry-3.26a {EntryWidgetCmd procedure, "delete" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state readonly
    .e delete 2 8
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test entry-3.27 {EntryWidgetCmd procedure, "get" widget command} -setup {
    entry .e
} -body {
    .e get foo
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e get"}
974
975
976
977
978
979
980
981

982
983
984
985
986
987
988
956
957
958
959
960
961
962

963
964
965
966
967
968
969
970







-
+







    entry .e
} -body {
    .e insert end "01234567890"
    .e icursor 4
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-3.31 {EntryWidgetCmd procedure, "index" widget command} -setup {
    entry .e
} -body {
    .e in
} -cleanup {
    destroy .e
} -returnCodes error -result {ambiguous option "in": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995

996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007







-
+








-
+



-
+







} -body {
    .e index foo
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "foo"}
test entry-3.34 {EntryWidgetCmd procedure, "index" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e index 0
} -cleanup {
    destroy .e
} -returnCodes {ok} -match glob -result {*}
test entry-3.35 {EntryWidgetCmd procedure, "index" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
# UTF
    .e insert 0 abc乎œdef
    .e insert 0 abc\u4e4e\u0153def
    list [.e index 3] [.e index 4] [.e index end]
} -cleanup {
    destroy .e
} -result {3 4 8}
test entry-3.36 {EntryWidgetCmd procedure, "insert" widget command} -setup {
    entry .e
} -body {
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070

1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110
1111
1112
1113
1114

1115
1116
1117

1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046
1047
1048

1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095

1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111

1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126
1127
1128
1129







-
+










-
+









-
+


-
+









-
+









-
+








-
+








-
+





-
+


-
+












-
+









-
+







} -body {
    .e insert foo Text
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "foo"}
test entry-3.39 {EntryWidgetCmd procedure, "insert" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e insert 3 xxx
    .e get
} -cleanup {
    destroy .e
} -result {012xxx34567890}
test entry-3.40 {EntryWidgetCmd procedure, "insert" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state disabled
    .e insert 3 xxx
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test entry-3.40a {EntryWidgetCmd procedure, "insert" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state readonly
    .e insert 3 xxx
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test entry-3.41 {EntryWidgetCmd procedure, "insert" widget command} -setup {
    entry .e
} -body {
    .e insert a b c
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e insert index text"}
test entry-3.42 {EntryWidgetCmd procedure, "scan" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e scan a
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e scan mark|dragto x"}
test entry-3.43 {EntryWidgetCmd procedure, "scan" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e scan a b c
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e scan mark|dragto x"}
test entry-3.44 {EntryWidgetCmd procedure, "scan" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e scan foobar 20
} -cleanup {
    destroy .e
} -returnCodes error -result {bad scan option "foobar": must be dragto or mark}
} -returnCodes error -result {bad scan option "foobar": must be mark or dragto}
test entry-3.45 {EntryWidgetCmd procedure, "scan" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e scan mark 20.1
} -cleanup {
    destroy .e
} -returnCodes error -result {expected integer but got "20.1"}

# This test is non-portable because character sizes vary.
test entry-3.46 {EntryWidgetCmd procedure, "scan" widget command} -constraints {
    fonts
} -setup {
    entry .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long string, in fact a "
    .e insert end "very very long string"
    .e scan mark 30
    .e scan dragto 28
    .e index @0
} -cleanup {
    destroy .e
} -result 2
} -result {2}
test entry-3.47 {EntryWidgetCmd procedure, "select" widget command} -setup {
    entry .e
} -body {
    .e select
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection option ?index?"}
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1152
1153
1154
1155
1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166







-
+







    .e select clear
    selection get
} -cleanup {
    destroy .e
} -returnCodes error -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test entry-3.50.1 {EntryWidgetCmd procedure, "select clear" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 4
    update
    .e select clear
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212

1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233
1234
1235

1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277

1278
1279
1280
1281
1282
1283
1284
1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266







-
+








-
+


-
+









-
+


-
+









-
+
















-
+










-
+


-
+










-
+







} -body {
    .e selection present foo
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection present"}
test entry-3.52 {EntryWidgetCmd procedure, "selection present" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e selection present
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-3.53 {EntryWidgetCmd procedure, "selection present" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e configure -exportselection false
    .e selection present
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-3.54 {EntryWidgetCmd procedure, "selection present" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e delete 0 end
    .e selection present
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test entry-3.55 {EntryWidgetCmd procedure, "selection adjust" widget command} -setup {
    entry .e
} -body {
    .e select adjust x
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "x"}
test entry-3.56 {EntryWidgetCmd procedure, "selection adjust" widget command} -setup {
    entry .e
} -body {
    .e select adjust 2 3
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection adjust index"}
test entry-3.57 {EntryWidgetCmd procedure, "selection adjust" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    update
    .e select adjust 4
    selection get
} -cleanup {
    destroy .e
} -result 123
} -result {123}
test entry-3.58 {EntryWidgetCmd procedure, "selection adjust" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    update
    .e select adjust 2
    selection get
} -cleanup {
    destroy .e
} -result 234
} -result {234}
test entry-3.59 {EntryWidgetCmd procedure, "selection from" widget command} -setup {
    entry .e
} -body {
    .e select from 2 3
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection from index"}
1306
1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385
1386
1387

1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450

1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480

1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508

1509
1510
1511
1512
1513
1514
1515
1516

1517
1518
1519

1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541

1542
1543
1544

1545
1546
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556

1557
1558
1559
1560

1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592

1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647

1648
1649
1650
1651
1652
1653
1654
1655
1656

1657
1658
1659
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
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359

1360
1361
1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382

1383
1384
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423

1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475

1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486

1487
1488
1489

1490
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518

1519
1520
1521
1522

1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534

1535
1536
1537

1538
1539
1540
1541

1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602

1603
1604
1605
1606
1607
1608
1609
1610

1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628

1629
1630
1631
1632
1633
1634
1635
1636
1637

1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655

1656
1657
1658
1659
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







-
+












-
+













-
+













-
+











-
+











-
+








-
+













-
+








-
+








-
+











-
+







-
+


-
+







-
+


-
+












-
+













-
+










-
+


-
+










-
+


-
+







-
+


-
+










-
+






-
+



-
+


-
+








-
+


-
+



-
+

















-
+













-
+











-
+
















-
+







-
+





-
+











-
+








-
+





-
+











-
+













-
+




-

-



-
+






-
+














-
+












-
+










-
+















-
+













-
+













-
+











-
+








-
+


-
+








-
+




-
+













-
+












-
+












-
+











-
+
















-
+







    .e select range 4 4
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-3.63 {EntryWidgetCmd procedure, "selection range" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 7
    .e select range 2 9
    list [.e index sel.first] [.e index sel.last] [.e index anchor]
} -cleanup {
    destroy .e
} -result {2 9 3}
test entry-3.64 {EntryWidgetCmd procedure, "selection" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e selection range 0 end
    .e configure -state disabled
    .e selection range 2 4
    .e configure -state normal
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {0 10}
test entry-3.64a {EntryWidgetCmd procedure, "selection" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e selection range 0 end
    .e configure -state readonly
    .e selection range 2 4
    .e configure -state normal
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 4}
test entry-3.64b {EntryWidgetCmd procedure, "selection to" widget command} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
} -body {
    .e select to 2 3
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection to index"}

test entry-3.65 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview 5
    format {%.7f %.7f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.0537634 0.2688172}
test entry-3.66 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e xview gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "gorp"}
test entry-3.67 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview 0
    .e icursor 10
    .e xview insert
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.107527 0.322581}
test entry-3.68 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e xview moveto foo bar
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e xview moveto fraction"}
test entry-3.69 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e xview moveto foo
} -cleanup {
    destroy .e
} -returnCodes error -result {expected floating-point number but got "foo"}
test entry-3.70 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview moveto 0.5
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.505376 0.720430}
test entry-3.71 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview scroll 24
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e xview scroll number pages|units"}
} -returnCodes error -result {wrong # args: should be ".e xview scroll number units|pages"}
test entry-3.72 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview scroll gorp units
} -cleanup {
    destroy .e
} -returnCodes error -result {expected floating-point number but got "gorp"}
} -returnCodes error -result {expected integer but got "gorp"}
test entry-3.73 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview moveto 0
    .e xview scroll 1 pages
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.193548 0.408602}
test entry-3.74 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview moveto .9
    update
    .e xview scroll -2 p
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.397849 0.612903}
test entry-3.75 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview 30
    update
    .e xview scroll 2 units
    .e index @0
} -cleanup {
    destroy .e
} -result 32
} -result {32}
test entry-3.76 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview 30
    update
    .e xview scroll -1 units
    .e index @0
} -cleanup {
    destroy .e
} -result 29
} -result {29}
test entry-3.77 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview scroll 23 foobars
} -cleanup {
    destroy .e
} -returnCodes error -result {bad argument "foobars": must be pages or units}
} -returnCodes error -result {bad argument "foobars": must be units or pages}
test entry-3.78 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview eat 23 hamburgers
} -cleanup {
    destroy .e
} -returnCodes error -result {unknown option "eat": must be moveto or scroll}
test entry-3.79 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview 0
    update
    .e xview {}
    .e xview -4
    .e index @0
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test entry-3.80 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview 300
    .e index @0
} -cleanup {
    destroy .e
} -result 73
} -result {73}
test entry-3.86 {EntryWidgetCmd procedure, "xview" widget command} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 
    .e insert 10 \u4e4e
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set x {}
    .e xview moveto .1
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .11
    lappend x [format {%.6f} [lindex [.e xview] 0]]
    .e xview moveto .12
    lappend x [format {%.6f} [lindex [.e xview] 0]]
} -cleanup {
    destroy .e
} -result {0.095745 0.106383 0.117021}

test entry-3.82 {EntryWidgetCmd procedure} -setup {
    entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e gorp
} -cleanup {
    destroy .e
} -returnCodes error -result {bad option "gorp": must be bbox, cget, configure, delete, get, icursor, index, insert, scan, selection, validate, or xview}

# The test below doesn't actually check anything directly, but if run
# with Purify or some other memory-allocation-checking program it will
# ensure that resources get properly freed.

test entry-4.1 {DestroyEntry procedure} -body {
    entry .e -textvariable x -show *
    pack .e ; update idletasks
    pack .e
    .e insert end "Sample text"
    update
    destroy .e
} -result {}

test entry-5.1 {ConfigureEntry procedure, -textvariable} -body {
    set x 12345
    entry .e -textvariable x
    .e get
} -cleanup {
    destroy .e
} -result 12345
} -result {12345}
test entry-5.2 {ConfigureEntry procedure, -textvariable} -body {
    set x 12345
    entry .e -textvariable x
    set y abcde
    .e configure -textvariable y
    set x 54321
    .e get
} -cleanup {
    destroy .e
} -result {abcde}
test entry-5.3 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain x
    entry .e
} -body {
    .e insert 0 "Some text"
    .e configure -textvariable x
    set x
    return $x
} -cleanup {
    destroy .e
} -result {Some text}
test entry-5.4 {ConfigureEntry procedure, -textvariable} -setup {
    unset -nocomplain x
    entry .e
} -body {
    trace add variable x write override
    trace variable x w override
    .e insert 0 "Some text"
    .e configure -textvariable x
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    trace vdelete x w override
    unset x;
} -result {12345 12345}

test entry-5.5 {ConfigureEntry procedure} -setup {
    set x {}
    entry .e1
    entry .e2
} -body {
    .e2 insert end "This is some sample text"
    .e1 configure -exportselection false
    .e1 insert end "0123456789"
    pack .e1 .e2 ; update idletasks
    pack .e1 .e2
    .e2 select from 0
    .e2 select to 10
    lappend x [selection get]
    .e1 select from 1
    .e1 select to 5
    lappend x [selection get]
    .e1 configure -exportselection 1
    lappend x [selection get]
    set x
    return $x
} -cleanup {
    destroy .e1 .e2
} -result {{This is so} {This is so} 1234}
test entry-5.6 {ConfigureEntry procedure} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    .e configure -exportselection 0
    selection get
} -cleanup {
    destroy .e
} -returnCodes error -result {PRIMARY selection doesn't exist or form "STRING" not defined}
test entry-5.6.1 {ConfigureEntry procedure} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    .e configure -exportselection 0
    catch {selection get}
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5}

test entry-5.7 {ConfigureEntry procedure} -setup {
    entry .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand scroll
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 0.454545}
} -result {0.000000 0.363636}


test entry-5.8 {ConfigureEntry procedure} -constraints {
    fonts
} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -width 0 -font {Helvetica -12}
    .e insert end "0123"
    update
    .e configure -font {Helvetica -24}
    update
    winfo geom .e
} -cleanup {
    destroy .e
} -result {62x37+0+0}
test entry-5.9 {ConfigureEntry procedure} -constraints {
    fonts
} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised
    .e insert end "0123"
    update
    list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
} -cleanup {
    destroy .e
} -result {0 0 1 1}
test entry-5.10 {ConfigureEntry procedure} -constraints {
    fonts
} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief flat
    .e insert end "0123"
    update
    list [.e index @10] [.e index @11] [.e index @12] [.e index @13]
} -cleanup {
    destroy .e
} -result {0 0 1 1}
test entry-5.11 {ConfigureEntry procedure} -setup {
    entry .e -borderwidth 2 -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
# If "0" in selected font had 0 width, caused divide-by-zero error.
    .e configure -font {{open look glyph}}
    .e scan dragto 30
    update
} -cleanup {
    destroy .e
} -result {}

# No tests for DisplayEntry.

test entry-6.1 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 20 \
        -highlightthickness 3
    .e insert end 012\t45
    update
    list [.e index @61] [.e index @62]
} -cleanup {
    destroy .e
} -result {3 4}
test entry-6.2 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 20 \
        -justify center -highlightthickness 3
    .e insert end 012\t45
    update
    list [.e index @96] [.e index @97]
} -cleanup {
    destroy .e
} -result {3 4}
test entry-6.3 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 20 \
        -justify right -highlightthickness 3
    .e insert end 012\t45
    update
    list [.e index @131] [.e index @132]
} -cleanup {
    destroy .e
} -result {3 4}
test entry-6.4 {EntryComputeGeometry procedure} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 5
    .e insert end "01234567890"
    update
    .e xview 6
    .e index @0
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test entry-6.5 {EntryComputeGeometry procedure} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 5
    .e insert end "01234567890"
    update
    .e xview 7
    .e index @0
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test entry-6.6 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 10
    .e insert end "01234\t67890"
    update
    .e xview 3
    list [.e index @39] [.e index @40]
} -cleanup {
    destroy .e
} -result {5 6}
test entry-6.7 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Helvetica -24} -bd 3 -relief raised -width 5
    .e insert end "01234567"
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} -cleanup {
    destroy .e
} -result {77 39}
test entry-6.8 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Helvetica -24} -bd 3 -relief raised -width 0
    .e insert end "01234567"
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} -cleanup {
    destroy .e
} -result {116 39}
test entry-6.9 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -font {Helvetica -24} -bd 3 -relief raised -width 0
    update
    list [winfo reqwidth .e] [winfo reqheight .e]
} -cleanup {
    destroy .e
} -result {25 39}
test entry-6.10 {EntryComputeGeometry procedure} -constraints {
    unix fonts
} -setup {
    entry .e -highlightthickness 2 -font {Helvetica -12}
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -bd 1 -relief raised -width 0 -show .
    .e insert 0 12345
    update
    set x [winfo reqwidth .e]
    .e configure -show X
    lappend x [winfo reqwidth .e]
    .e configure -show ""
    lappend x [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {23 53 43}
test entry-6.11 {EntryComputeGeometry procedure} -constraints {
    win
} -setup {
    entry .e -highlightthickness 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -bd 1 -relief raised -width 0 -show . -font {helvetica 12}
    .e insert 0 12345
    update
    set x1 [winfo reqwidth .e]
	set x2 [expr {8+5*[font measure {helvetica 12} .]}]
	set x [expr {$x1 eq $x2}]
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
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







-
+












-
+



-
-











-
+



-
-









-
+













-
+













-
+













-
+













-
+








-
+


-
+







-
+


-
+








-
+


-
+








-
+





-
+







-
+




-
+



-
-










-
+



-
-

-
+








-
+



-
-









-
+















-
+















-
+















-
+













-
+















-
+












-
+















-
+















-
+









-
+


-
+









-
+


-
+









-
+


-
+









-
+


-
+









-
+


-
+









-
+


-
+







    destroy .e
} -result {1 1 1}
test entry-6.12 {EntryComputeGeometry procedure} -constraints {
    fonts
} -setup {
    catch {destroy .e}
    entry .e -font {Courier -12} -bd 2 -relief raised -width 20
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert end "012\t456\t"
    update
    list [.e index @80] [.e index @81] [.e index @115] [.e index @116]
} -cleanup {
    destroy .e
} -result {6 7 7 8}


test entry-7.1 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test entry-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test entry-7.3 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 2 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {5 9 5 8}
test entry-7.4 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 3 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.5 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 5 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 9 2 8}
test entry-7.6 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789
    .e select from 2
    .e select to 6
    .e insert 6 XXX
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {2 6 2 5}
test entry-7.7 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -xscrollcommand scroll
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7
} -result {7}
test entry-7.8 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789
    .e icursor 4
    .e insert 5 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-7.9 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 3 XXX
    .e index @0
} -cleanup {
    destroy .e
} -result 7
} -result {7}
test entry-7.10 {InsertChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 4 XXX
    .e index @0
} -cleanup {
    destroy .e
} -result 4
} -result {4}

test entry-7.11 {InsertChars procedure} -constraints {
    fonts
} -setup {
    entry .e -width 0 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 "xyzzy"
    update
    .e insert 2 00
    winfo reqwidth .e
} -cleanup {
    destroy .e
} -result 59
} -result {59}

test entry-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test entry-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete {} 2
    .e delete -2 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test entry-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    update
    set scrollInfo wrong
    .e insert 0 abcde
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test entry-8.4 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 3
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6 1 5}
test entry-8.5 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 4
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 5 1 4}
test entry-8.6 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 5
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 2 1 5}
test entry-8.7 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 1 8
    update
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-8.8 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 7
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 4 3 8}
test entry-8.9 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 3
    .e select to 8
    .e delete 3 8
    update
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-8.10 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 5 8
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 8
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 5 5 8}
test entry-8.11 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e select from 8
    .e select to 3
    .e delete 8 10
    update
    set x "[.e index sel.first] [.e index sel.last]"
    .e select to 4
    lappend x [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {3 8 4 8}
test entry-8.12 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 4
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-8.13 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 5
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-8.14 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 4 6
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-8.15 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 4
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-8.16 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 5
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-8.17 {DeleteChars procedure} -setup {
    entry .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 4 6
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-8.18 {DeleteChars procedure} -setup {
    entry .e -width 0 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    focus .e
} -body {
    .e insert 0 "xyzzy"
    update
    .e delete 2 4
    # To check that deletion actually happened we measure the new width
    # of the widget, based on the measuring width of the remaining text ("xyy")
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
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







-
+





-
+








-
+










-
+












-
+












-
+












-
+










-
+



-
+


-
+








-
+



-
+



-
+






-
+



-
+


-
+






-
+



-
+







    destroy .e
    unset XPAD expected
} -result {1}

test entry-9.1 {EntryValueChanged procedure} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write override
    trace variable x w override
    entry .e -textvariable x -width 0
    .e insert 0 foo
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    trace vdelete x w override
    unset x
} -result {12345 12345}


test entry-10.1 {EntrySetValue procedure} -constraints fonts -body {
    set x abcde
    set y ab
    entry .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
    pack .e ; update idletasks
    pack .e
    .e configure -textvariable x
    .e configure -textvariable y
    update
    list [.e get] [winfo reqwidth .e]
} -cleanup {
    destroy .e
} -result {ab 24}
test entry-10.2 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "a"
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}
test entry-10.3 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefg"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 7}
test entry-10.4 {EntrySetValue procedure, updating selection} -setup {
    unset -nocomplain x
    entry .e -font {Helvetica -12} -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -textvariable x
    .e insert 0 "abcdefghjklmnopqrstu"
    .e selection range 4 10
    set x "abcdefghijklmn"
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {4 10}
test entry-10.5 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test entry-10.6 {EntrySetValue procedure, updating display position} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
} -result {10}
test entry-10.7 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
} -result {3}
test entry-10.8 {EntrySetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    entry .e -highlightthickness 2 -bd 2
    pack .e ; update idletasks
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e ; update idletasks
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5
} -result {5}

test entry-11.1 {EntryEventProc procedure} -setup {
    entry .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 abcdefg
    destroy .e
    update
} -cleanup {
    destroy .e
} -result {}
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
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







-
+







-
+








-
+









-
+


-
+









-
+


-
+










-
+









-
+








-
+









-
+
















-
+




-
+













-
+





-
+












-
+

-
+


-
+


















-
+
















-
+



















-
+



















-
+







} -cleanup {
    destroy .b
} -result {{} {}}


test entry-13.1 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index end
} -cleanup {
    destroy .e
} -result 21
} -result {21}
test entry-13.2 {GetEntryIndex procedure} -body {
    entry .e
    .e index abogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "abogus"}
test entry-13.3 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 1
    .e select to 6
    .e index anchor
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test entry-13.4 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 4
    .e select to 1
    .e index anchor
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-13.5 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 3
    .e select to 15
    .e select adjust 4
    .e index anchor
} -cleanup {
    destroy .e
} -result 15
} -result {15}
test entry-13.6 {GetEntryIndex procedure} -setup {
    entry .e
} -body {
    .e index ebogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "ebogus"}
test entry-13.7 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e icursor 2
    .e index insert
} -cleanup {
    destroy .e
} -result 2
} -result {2}
test entry-13.8 {GetEntryIndex procedure} -setup {
    entry .e
} -body {
    .e index ibogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "ibogus"}
test entry-13.9 {GetEntryIndex procedure} -setup {
    entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e ; update idletasks
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6}






test entry-13.10 {GetEntryIndex procedure} -constraints x11 -body {
test entry-13.10 {GetEntryIndex procedure} -constraints unix -body {
# On unix, when selection is cleared, entry widget's internal
# selection range is reset.
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}

test entry-13.11 {GetEntryIndex procedure} -constraints aquaOrWin32 -body {
test entry-13.11 {GetEntryIndex procedure} -constraints win -body {
# On mac and pc, when selection is cleared, entry widget remembers
# last selected range.  When selection ownership is restored to
# entry, the old range will be rehighlighted.
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    catch {selection get}
    .e index sel.first
} -cleanup {
    destroy .e
} -result 1
} -result {1}

test entry-13.12 {GetEntryIndex procedure} -constraints x11 -body {
test entry-13.12 {GetEntryIndex procedure} -constraints unix -body {
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    .e index sbogus
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}

# why when string in .e index changed to not beginning with s,
# it behaves differently?
test entry-13.12.1 {GetEntryIndex procedure} -constraints unix -body {
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    .e index bogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "bogus"}

test entry-13.13 {GetEntryIndex procedure} -constraints win -body {
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    .e index sbogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "sbogus"}

test entry-13.14 {GetEntryIndex procedure} -constraints win -body {
# On mac and pc, when selection is cleared, entry widget remembers
# last selected range.  When selection ownership is restored to
# entry, the old range will be rehighlighted.
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    selection get
} -cleanup {
    destroy .e
} -returnCodes error -match glob -result {*}

test entry-13.14.1 {GetEntryIndex procedure} -constraints win -body {
# On mac and pc, when selection is cleared, entry widget remembers
# last selected range.  When selection ownership is restored to
# entry, the old range will be rehighlighted.
# Previous settings:
	entry .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e ; update idletasks
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
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
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







-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+


-
+









-
+



-
+


-
+



-
+






-
+



-
+






-
+





-
+







} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "@xyz"}

test entry-13.16 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @4
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-13.17 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @11
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test entry-13.18 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @12
} -cleanup {
    destroy .e
} -result 5
} -result {5}
test entry-13.19 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @[expr {[winfo width .e] - 6}]
} -cleanup {
    destroy .e
} -result 8
} -result {8}
test entry-13.20 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @[expr {[winfo width .e] - 5}]
} -cleanup {
    destroy .e
} -result 9
} -result {9}
test entry-13.21 {GetEntryIndex procedure} -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @1000
} -cleanup {
    destroy .e
} -result 9
} -result {9}
test entry-13.22 {GetEntryIndex procedure} -setup {
    entry .e
    pack .e ; update idletasks
    pack .e
    update
} -body {
    .e index 1xyz
} -cleanup {
    destroy .e
} -returnCodes error -result {bad entry index "1xyz"}
test entry-13.23 {GetEntryIndex procedure} -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index {}
    .e index -10
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test entry-13.24 {GetEntryIndex procedure} -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index 12
} -cleanup {
    destroy .e
} -result 12
} -result {12}
test entry-13.25 {GetEntryIndex procedure} -body {
    entry .e -width 5 -relief sunken -highlightthickness 2 -bd 2\
        -font {Courier -12}
    pack .e ; update idletasks
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index 49
} -cleanup {
    destroy .e
} -result 21
} -result {21}
test entry-13.26 {GetEntryIndex procedure} -constraints fonts -body {
    entry .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    selection clear .e
    .e configure -show .
    .e insert 0 XXXYZZY
    pack .e ; update idletasks
    pack .e
    update
    list [.e index @7] [.e index @8]
} -cleanup {
    destroy .e
} -result {0 1}

# XXX Still need to write tests for EntryScanTo and EntrySelectTo.
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
3171

3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184

3185
3186
3187
3188
3189
3190
3191
3192

3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205

3206
3207
3208
3209
3210

3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223

3224
3225
3226
3227
3228
3229
3230
3231

3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244

3245
3246
3247
3248
3249

3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262

3263
3264
3265
3266
3267
3268

3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281

3282
3283
3284
3285
3286
3287

3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300

3301
3302
3303
3304
3305
3306
3307
3308
3309

3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323

3324
3325
3326
3327
3328
3329
3330
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

3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183

3184
3185
3186
3187
3188
3189
3190
3191

3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204

3205
3206
3207
3208
3209

3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222

3223
3224
3225
3226
3227
3228

3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241

3242
3243
3244
3245
3246
3247

3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260

3261
3262
3263
3264
3265
3266
3267
3268
3269

3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283

3284
3285
3286
3287
3288
3289
3290
3291







-
+


















-
+










-
+










-
+

















-
-










-
-










-
-













-
+


-
-
-



















-
+



















-
+

-
+












-
+















-
+


-
+












-
+















-
+


-
+












-
+



-
+












-
+



-
+












-
+





-
+












-
+







-
+












-
+




-
+












-
+







-
+












-
+




-
+












-
+





-
+












-
+





-
+












-
+








-
+













-
+







    entry .e
    .e insert end $x
    .e select from 0
    .e select to end
    string compare [selection get] $x
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-15.1 {EntryLostSelection} -body {
    entry .e
    .e insert 0 "Text"
    .e select from 0
    .e select to 4
    set result [selection get]
    selection clear
    .e select from 0
    .e select to 4
    lappend result [selection get]
} -cleanup {
    destroy .e
} -result {Text Text}

# is scrollcommand needed here??
test entry-16.1 {EntryVisibleRange procedure} -constraints fonts  -body {
    entry .e -width 10 -font {Helvetica -12}
    pack .e ; update idletasks
    pack .e
    update
    .e insert 0 "............................."
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 0.827586}
test entry-16.2 {EntryVisibleRange procedure} -constraints {
    unix fonts
} -body {
    entry .e -show X -width 10  -font {Helvetica -12}
    pack .e ; update idletasks
    pack .e
    update
    .e insert 0 "............................."
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 0.275862}
test entry-16.3 {EntryVisibleRange procedure} -constraints {
    win
} -body {
    entry .e -show . -width 10  -font {Helvetica -12}
	pack .e ; update idletasks
	pack .e
    update
    .e insert 0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 0.827586}
test entry-16.4 {EntryVisibleRange procedure} -body {
    entry .e -show ""
    format {%.6f %.6f} {*}[.e xview]
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}


test entry-17.1 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test entry-17.2 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 0123456789abcdef
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test entry-17.3 {EntryUpdateScrollbar procedure} -body {
    entry .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview 6
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.315789 0.842105}
test entry-17.4 {EntryUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global x
	set x $msg
}
} -body {
    entry .e -width 5
    entry .e -width 5 -xscrollcommand thisisnotacommand
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $x $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}


test entry-18.1 {Entry widget vs hiding} -setup {
    entry .e
} -body {
    set l [interp hidden]
    interp hide {} .e
    destroy .e
    set res1 [list [winfo children .] [interp hidden]]
    set res2 [list {} $l]
    expr {$res1 == $res2}
} -result 1
} -result {1}

##
## Entry widget VALIDATION tests
##
# The validation tests build each one upon the previous, so cascading
# failures aren't good
#

# 19.* test cases in previous version highly depended on the previous
# test cases. This was replaced by inserting recently set configurations
# that matters for the test case
test entry-19.1 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 a
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 1 0 a {} a all key}

test entry-19.2 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 a   ;# previous settings
    .e insert 1 b
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 1 1 ab a b all key}

test entry-19.3 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 ab   ;# previous settings
    .e insert end c
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 1 2 abc ab c all key}

test entry-19.4 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 abc   ;# previous settings
    .e insert 1 123
    list $::vVals $::e
} -cleanup {
    destroy .e
} -result {{.e 1 1 a123bc abc 123 all key} a123bc}

test entry-19.5 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 a123bc   ;# previous settings
    .e delete 2
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 0 2 a13bc a123bc 2 all key}

test entry-19.6 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 a13bc   ;# previous settings
    .e configure -validate key
    .e delete 1 3
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e 0 1 abc a13bc 13 key key}

test entry-19.7 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focus \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abc                 ;# previous settings
    set ::vVals {}
    .e insert end d
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.8 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e configure -validate focus    ;# previous settings
    .e insert end abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusin}

test entry-19.9 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focus \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd      ;# previous settings
    focus -force .e         ;# previous settings
    update                  ;# previous settings
# update necessary to process FocusIn event
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focus focusout}

test entry-19.10 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusin}

test entry-19.11 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd          ;# previous settings
    focus -force .e             ;# previous settings
# update necessary to process FocusIn event
    update                      ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} all focusout}

test entry-19.12 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focusin \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert 0 abcd              ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test entry-19.13 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focusin \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.14 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e
# update necessary to process FocusIn event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {}

test entry-19.15 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
    update
    set ::vVals
    return $::vVals
} -cleanup {
    destroy .e
} -result {.e -1 -1 abcd abcd {} focusout focusout}

# the same as 19.16 but added [.e validate] to returned list
test entry-19.16 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd              ;# previous settings
    set ::vVals {}                  ;# previous settings
    focus -force .e                 ;# previous settings
# update necessary to process FocusIn event
    update                          ;# previous settings
    focus -force .
# update necessary to process FocusOut event
3339
3340
3341
3342
3343
3344
3345
3346

3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364

3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384

3385
3386
3387
3388
3389
3390
3391
3392

3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451

3452
3453
3454
3455
3456
3457
3458
3459
3460
3461

3462
3463
3464
3465
3466
3467
3468
3469
3470

3471
3472
3473
3474
3475
3476
3477
3478
3479
3480

3481
3482
3483
3484
3485
3486
3487
3488

3489
3490
3491
3492
3493
3494
3495
3496
3497
3498

3499
3500
3501
3502
3503
3504

3505
3506
3507
3508
3509
3510

3511
3512
3513
3514
3515
3516
3517
3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324

3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344

3345
3346
3347
3348
3349
3350
3351
3352

3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367

3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378




















3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391

3392
3393
3394
3395
3396
3397
3398
3399
3400
3401

3402
3403
3404
3405
3406
3407
3408
3409
3410

3411
3412
3413
3414
3415
3416
3417
3418
3419
3420

3421
3422
3423
3424
3425
3426
3427
3428

3429
3430
3431
3432
3433
3434
3435
3436
3437
3438

3439
3440
3441
3442
3443
3444

3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3458







-
+

















-
+



















-
+







-
+














-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
+









-
+








-
+









-
+







-
+









-
+





-
+





-
+







    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate focuso \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    .e insert end abcd              ;# previous settings
    set ::e newdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {focusout {.e -1 -1 newdata abcd {} focusout forced}}


# proc doval changed - returns 0
test entry-19.18 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    set ::e newdata                 ;# previous settings
    .e configure -validate all
    set ::e nextdata
    list [.e cget -validate] $::vVals
} -cleanup {
    destroy .e
} -result {none {.e -1 -1 nextdata newdata {} all forced}}

## This sets validate to none because it shows that we prevent a possible
## loop condition in the validation, when the entry textvar is also set
# proc doval2 used
test entry-19.19 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval3 %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    set ::e nextdata                 ;# previous settings

    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V]
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}
} -result {none mydata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.20 {entry widget validation} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate all \
        -validatecommand [list doval %W %d %i %P %s %S %v %V] \
        -invalidcommand bell \
        -textvariable ::e \
        -background red -foreground white
    pack .e ; update idletasks
    pack .e
    set ::e nextdata                 ;# previous settings
    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V] ;# prev
    .e validate                     ;# previous settings

    .e configure -validate all
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test entry-19.21 {entry widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    entry .e -validate key \
        -validatecommand [list doval2 %W %d %i %P %s %S %v %V] \
        -textvariable ::e
    pack .e ; update idletasks
    set ::e origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##

test entry-20.1 {widget deletion while active} -body {
    entry .e -validate all \
	    -validatecommand { destroy %W ; return 1 } \
	    -invalidcommand bell
    update
    .e insert 0 abc
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.2 {widget deletion while active} -body {
    entry .e -validate all \
	    -validatecommand { return 0 } \
	    -invalidcommand { destroy %W }
    .e insert 0 abc
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.3 {widget deletion while active} -body {
    entry .e -validate all \
	    -validatecommand { rename .e {} ; return 1 }
    .e insert 0 abc
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.4 {widget deletion while active} -body {
    entry .e -validate all \
	    -validatecommand { return 0 } \
	    -invalidcommand { rename .e {} }
    .e insert 0 abc
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.5 {widget deletion while active} -body {
    entry .e -validatecommand { destroy .e ; return 0 }
    .e validate
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.6 {widget deletion while active} -body {
    pack [entry .e]
    update
    .e config -xscrollcommand { destroy .e }
    update idle
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test entry-20.7 {widget deletion with textvariable active} -body {
# SF bugs 607390 and 617446
    set FOO init
    entry .e -textvariable FOO -validate all \
	    -validatecommand {%W configure -bg white; format 1}
	    -vcmd {%W configure -bg white; format 1}
    bind .e <Destroy> { set FOO hello }
    destroy .e
    winfo exists .e
} -cleanup {
    destroy .e
} -result 0
} -result {0}


test entry-21.1 {selection present while disabled, bug 637828} -body {
    entry .e
    .e insert end 0123456789
    .e select from 3
    .e select to 6
3547
3548
3549
3550
3551
3552
3553
3554

3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3488
3489
3490
3491
3492
3493
3494

3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513















































3514
3515
3516
3517
3518
3519
3520







-
+


















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	{can't set "::test::foo": parent namespace doesn't exist} \
	{can't set "::test::foo": parent namespace doesn't exist} \
	{can't read "::test::foo": no such variable}]

test entry-23.1 {error in trace proc attached to the textvariable} -setup {
    destroy .e
} -body {
    trace add variable myvar write traceit
    trace variable myvar w traceit
    proc traceit args {error "Intentional error here!"}
    entry .e -textvariable myvar
    catch {.e insert end mystring} result1
    catch {.e delete 0} result2
    list $result1 $result2
} -cleanup {
    destroy .e
} -result [list {can't set "myvar": Intentional error here!} \
    {can't set "myvar": Intentional error here!}]

test entry-24.1 {textvariable lives in a non-existing namespace} -setup {
    destroy .e
} -body {
    catch {entry .e -textvariable thisnsdoesntexist::myvar} result1
    set result1
} -cleanup {
  destroy .e
} -result {can't trace "thisnsdoesntexist::myvar": parent namespace doesn't exist}

test entry-25.1 {Bug [5d991b822e]} {
    # Want this not to segfault, or write to variable with empty name
    set var INIT
    entry .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
    info exists {}
} 0
test entry-25.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    entry .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}
test entry-25.3 {Bug [2a32225cd1] - Navigation in a password made of several words} -setup {
    destroy .e
    pack [entry .e -show *]
    update
    set res {}
} -body {
    .e insert end "A sample password made of several words"
    .e icursor end
    event generate .e <<PrevWord>>  ; # shall move insert to index 0
    .e delete insert end
    lappend res [.e get]
    .e insert end "A sample password made of several words"
    .e icursor 2
    event generate .e <<NextWord>>  ; # shall move insert to index end
    .e delete 0 insert
    lappend res [.e get]
} -cleanup {
    destroy .e
} -result {{} {}}


# Gathered comments about lacks
# XXX Still need to write tests for EntryBlinkProc, EntryFocusProc,
# and EntryTextVarProc.
# No tests for DisplayEntry.
# XXX Still need to write tests for EntryScanTo and EntrySelectTo.
# No tests for EventuallyRedraw

Changes to tests/event.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25
26

















































27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


47
48
49
50
51
52
53
1
2
3



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24




25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99



-
-
-
+
+
+
















+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










-







-
-
+
+







# This file is a Tcl script to test the code in tkEvent.c.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# XXX This test file is woefully incomplete.  Right now it only tests
# a few of the procedures in tkEvent.c.  Please add more tests whenever
# possible.

# Setup table used to query key events.

proc _init_keypress_lookup {} {
    global keypress_lookup

    scan A %c start
    scan Z %c finish
    # Characters with meaning to Tcl...
    array set keypress_lookup [list \
	    -    minus \
	    >    greater \

    for {set i $start} {$i <= $finish} {incr i} {
        set l [format %c $i]
        set keypress_lookup($l) $l
    }

    scan a %c start
    scan z %c finish

    for {set i $start} {$i <= $finish} {incr i} {
        set l [format %c $i]
        set keypress_lookup($l) $l
    }

    scan 0 %c start
    scan 9 %c finish

    for {set i $start} {$i <= $finish} {incr i} {
        set l [format %c $i]
        set keypress_lookup($l) $l
    }

    # Most punctuation
    array set keypress_lookup {
        ! exclam
        % percent
        & ampersand
        ( parenleft
        ) parenright
        * asterisk
        + plus
        , comma
        - minus
        . period
        / slash
        : colon
        < less
        = equal
        > greater
        ? question
        @ at
        ^ asciicircum
        _ underscore
        | bar
        ~ asciitilde
        ' apostrophe
    }
    # Characters with meaning to Tcl...
    array set keypress_lookup [list \
	    \"   quotedbl \
	    \#   numbersign \
	    \$   dollar \
	    \;   semicolon \
	    \[   bracketleft \
	    \\   backslash \
	    \]   bracketright \
	    \{   braceleft \
	    \}   braceright \
	    " "  space \
	    \xA0 nobreakspace \
	    "\n" Return \
	    "\t" Tab]
}

# Lookup an event in the keypress table.
# For example:
# Q -> Q
# ; -> semicolon
# > -> greater
# . -> period
# / -> slash
# Delete -> Delete
# Escape -> Escape

proc _keypress_lookup {char} {
    global keypress_lookup

    if {! [info exists keypress_lookup]} {
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134







-
+












-
+







    if {[info exists keypress_lookup($char)]} {
        return $keypress_lookup($char)
    } else {
        return $char
    }
}

# Lookup and generate a pair of Key and KeyRelease events
# Lookup and generate a pair of KeyPress and KeyRelease events

proc _keypress {win key} {
    set keysym [_keypress_lookup $key]

    # Force focus to the window before delivering
    # each event so that a window manager using
    # a focus follows mouse will not steal away
    # the focus if the mouse is moved around.

    if {[focus] != $win} {
        focus -force $win
    }
    event generate $win <Key-$keysym>
    event generate $win <KeyPress-$keysym>
    _pause 50
    if {[focus] != $win} {
        focus -force $win
    }
    event generate $win <KeyRelease-$keysym>
    _pause 50
}
144
145
146
147
148
149
150
151

152
153
154

155
156
157
158
159
160
161
190
191
192
193
194
195
196

197
198
199

200
201
202
203
204
205
206
207







-
+


-
+







} -body {
    button .b -text Test
    pack .b
    bindtags .b .b
    update
    bind .b <Destroy> {
	    lappend x destroy
	    event generate .b <Button-1>
	    event generate .b <1>
	    event generate .b <ButtonRelease-1>
    }
    bind .b <Button-1> {
    bind .b <1> {
	    lappend x button
    }

    destroy .b
    return $x
} -cleanup {
    deleteWindows
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
241
242
243
244
245
246
247


248
249
250
251
252
253
254







-
-







test event-2.2(keypress) {type into entry widget and then delete some text} -setup {
	deleteWindows
} -body {
    set t [toplevel .t]
    set e [entry $t.e]
    pack $e
    tkwait visibility $e
    # Avoid a hang when macOS puts the mouse pointer on the green button
    wm geometry .t +200+100
    _keypress_string $e MELLO
    _keypress $e BackSpace
    _keypress $e BackSpace
    $e get
} -cleanup {
    deleteWindows
} -result {MEL}
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277







-
+







    _keypress_string $e JUMP

    set result [$e get]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
        _pause 100
        event generate $e <Button-1>
        event generate $e <ButtonPress-1>
        _pause 100
        event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get]
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331







-
+







    _keypress_string $e JUMP

    set result [$e get 1.0 1.end]

    event generate $e <Enter>
    for {set i 0} {$i < 3} {incr i} {
        _pause 100
        event generate $e <Button-1>
        event generate $e <ButtonPress-1>
        _pause 100
        event generate $e <ButtonRelease-1>
    }

    _keypress $e Delete
    _keypress_string $e UP
    lappend result [$e get 1.0 1.end]
305
306
307
308
309
310
311
312

313
314
315
316
317
318
319
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363







-
+







    lappend result [$e get 1.0 1.end]

    # Get the x,y coords of the second T in "Tcl/Tk"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down to set the insert cursor position
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Now drag until selend is highlighted, then click up

    set current $anchor
331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389







-
+







    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y
    event generate $e <ButtonPress-1> -x $current_x -y $current_y

    while {[$e compare $current >= [list $anchor - 4 char]]} {
        foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
        event generate $e <B1-Motion> -x $current_x -y $current_y
        set current [$e index [list $current - 1 char]]
        _pause 50
    }
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430







-
+







    lappend result [$e get]

    # Get the x,y coords of the second T in "Tcl/Tk"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down to set the insert cursor position
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y

    # Save the position of the insert cursor
    lappend result [$e index insert]

    # Now drag until selend is highlighted, then click up

    set current $anchor
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456







-
+







    lappend result [$e index insert]

    # Save the highlighted text
    lappend result [_get_selection $e]

    # Now click and click and drag to the left, over "Tcl/Tk selection"

    event generate $e <Button-1> -x $current_x -y $current_y
    event generate $e <ButtonPress-1> -x $current_x -y $current_y

    while {$current >= ($anchor - 4)} {
        foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
        event generate $e <B1-Motion> -x $current_x -y $current_y
        incr current -1
        _pause 50
    }
437
438
439
440
441
442
443
444

445
446
447
448

449
450
451
452
453
454
455
481
482
483
484
485
486
487

488
489
490
491

492
493
494
495
496
497
498
499







-
+



-
+







    set anchor 1.8

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50

    # Save the highlighted text
    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at beginning of "select"
508
509
510
511
512
513
514
515

516
517
518
519

520
521
522
523
524
525
526
552
553
554
555
556
557
558

559
560
561
562

563
564
565
566
567
568
569
570







-
+



-
+







    set anchor 8

    # Get the x,y coords of the second e in "select"
    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    # Click down, release, then click down again
    event generate $e <Enter>
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Insert cursor should be at the end of "select"
    lappend result [$e index insert]
580
581
582
583
584
585
586
587

588
589
590
591
592

593
594
595
596
597

598
599
600
601
602
603
604
624
625
626
627
628
629
630

631
632
633
634
635

636
637
638
639
640

641
642
643
644
645
646
647
648







-
+




-
+




-
+








    # Triple click one third line leaving mouse down

    foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break

    event generate $e <Enter>

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
    _pause 50

    event generate $e <Button-1> -x $anchor_x -y $anchor_y
    event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
    _pause 50

    set result [list]
    lappend result [_get_selection $e]

    # Drag up to second line

630
631
632
633
634
635
636
637

638
639
640
641
642
643
644
674
675
676
677
678
679
680

681
682
683
684
685
686
687
688







-
+







        destroyed, when the mouse is moved into another window it
        should not generate a <B1-motion> event since the mouse
        was not pressed down in that window} -setup {
	deleteWindows
} -body {
    set t [toplevel .t]

    event generate $t <Button-1>
    event generate $t <ButtonPress-1>
    destroy $t
    set t [toplevel .t]
    set motion nomotion
    bind $t <B1-Motion> {set motion inmotion}
    event generate $t <Motion>
    return $motion
} -cleanup {
669
670
671
672
673
674
675
676

677
678
679
680

681
682
683
684
685
686
687
688
689
690
691

692
693
694
695
696
697
698

699
700
701
702

703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
713
714
715
716
717
718
719

720
721
722
723

724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741

742
743
744
745

746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763







-
+



-
+










-
+






-
+



-
+










-








    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    event generate $e <ButtonPress-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    event generate $e <ButtonPress-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    event generate $e <ButtonPress-1> -x 0 -y 0
    _pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    _pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    event generate $e <ButtonPress-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    event generate $e <ButtonPress-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
    unset x1 y1 width height middle_y left_x left_y right_x right_y
} -result {1.3 A 1.3 A}
test event-7.2(double-click) {A double click on a lone character
    in an entry widget should select that character} -setup {
	deleteWindows
} -body {
    set t [toplevel .t]
    set e [entry $t.e]
736
737
738
739
740
741
742
743

744
745
746
747

748
749
750
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765

766
767
768
769

770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793

794
795
796
797
798
799
800
779
780
781
782
783
784
785

786
787
788
789

790
791
792
793
794
795
796
797
798
799
800

801
802
803
804
805
806
807

808
809
810
811

812
813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
842







-
+



-
+










-
+






-
+



-
+










-












-
+








    set right_x [expr {($x1 + $width) - 2}]
    set right_y $middle_y

    # Double click near left hand egde of the letter A

    event generate $e <Enter>
    event generate $e <Button-1> -x $left_x -y $left_y
    event generate $e <ButtonPress-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <Button-1> -x $left_x -y $left_y
    event generate $e <ButtonPress-1> -x $left_x -y $left_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $left_x -y $left_y
    _pause 50

    set result [list]
    lappend result [$e index insert]
    lappend result [_get_selection $e]

    # Clear selection by clicking at 0,0

    event generate $e <Button-1> -x 0 -y 0
    event generate $e <ButtonPress-1> -x 0 -y 0
    _pause 50
    event generate $e <ButtonRelease-1> -x 0 -y 0
    _pause 50

    # Double click near right hand edge of the letter A

    event generate $e <Button-1> -x $right_x -y $right_y
    event generate $e <ButtonPress-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <Button-1> -x $right_x -y $right_y
    event generate $e <ButtonPress-1> -x $right_x -y $right_y
    _pause 50
    event generate $e <ButtonRelease-1> -x $right_x -y $right_y
    _pause 50

    lappend result [$e index insert]
    lappend result [_get_selection $e]

    return $result
} -cleanup {
    deleteWindows
    unset x1 y1 width height middle_y left_x left_y right_x right_y
} -result {4 A 4 A}

test event-8 {event generate with keysyms corresponding to
              multi-byte virtual keycodes - bug
              e36963bfe8df9f5e528134707a91b9c0051de723} -constraints nonPortable -setup {
    deleteWindows
    set res [list ]
} -body {
    set t [toplevel .t]
    set e [entry $t.e]
    pack $e
    tkwait visibility $e
    bind $e <Key> {lappend res keycode: %k keysym: %K}
    bind $e <KeyPress> {lappend res keycode: %k keysym: %K}
    focus -force $e
    update
    event generate $e <diaeresis>
    # The value now contained in $res depends on the actual
    # physical keyboard layout and keycode generated, from
    # the hardware on which the test suite happens to run.
    # We don't need (and we can't really) check correctness
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
853
854
855
856
857
858
859



























































860

861
862
863
864
865
866
867
868
869
870
871
872







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-












                on which this test is run does NOT have a diaeresis \
                physical key - in this case, test is actually void."
    }
} -cleanup {
    deleteWindows
} -result {OK}

test event-9.1 {enter . window by destroying a toplevel - bug b1d115fa60} -setup {
    set EnterBind [bind . <Enter>]
} -body {
    wm geometry . 200x200+300+300
    wm deiconify .
    _pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .]+50}]+[expr {[winfo rooty .]+50}]
    update idletasks
    wm deiconify .top2
    update idletasks
    raise .top2
    _pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    _pause 100
    bind . <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    update idletasks
    _pause 200
    set res
} -cleanup {
    deleteWindows
    bind . <Enter> $EnterBind
} -result {.}
test event-9.2 {enter toplevel window by destroying a toplevel - bug b1d115fa60} -setup {
    set iconified false
    if {[winfo ismapped .]} {
        wm iconify .
        update
        set iconified true
    }
} -body {
    toplevel .top1
    wm geometry .top1 200x200+300+300
    wm deiconify .top1
    _pause 200
    toplevel .top2 -width 200 -height 200
    wm geometry .top2 +[expr {[winfo rootx .top1]+50}]+[expr {[winfo rooty .top1]+50}]
    _pause 200
    wm deiconify .top2
    update idletasks
    raise .top2
    _pause 400
    event generate .top2 <Motion> -warp 1 -x 50 -y 50
    _pause 100
    bind .top1 <Enter> {lappend res %W}
    set res [list ]
    destroy .top2
    _pause 200
    set res
} -cleanup {
    deleteWindows ; # destroy all children of ".", this already includes .top1
    if {$iconified} {
        wm deiconify .
        update
    }
} -result {.top1}

# cleanup
update
unset -nocomplain keypress_lookup
rename _init_keypress_lookup {}
rename _keypress_lookup {}
rename _keypress {}
rename _pause {}
rename _text_ind_to_x_y {}
rename _get_selection {}

cleanupTests
return


Changes to tests/filebox.test.

1
2
3
4
5
6


7
8
9

10
11
12
13
14
15
16
1
2
3
4


5
6
7
8

9
10
11
12
13
14
15
16




-
-
+
+


-
+







# This file is a Tcl script to test out Tk's "tk_getOpenFile" and
# "tk_getSaveFile" commands. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

test fileDialog-0.1 {GetFileName: file types: MakeFilter() fails} {
    # MacOS type that is too long

    set res [list [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0\0}}}} msg] $msg]
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-
+







    if {!$isNative} {
	after 100 EnterFileByKey $parent [list $fileName] [list $fileDir]
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc EnterFileByKey {parent fileName fileDir} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_filedialog
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114

115
116
117
118
119
120
121
122
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113


114

115
116
117
118
119
120
121







+


















-
+
















-
+
-
-
+
-







    }

    update
    SendButtonPress $parent ok mouse
}

proc SendButtonPress {parent btn type} {
    global tk_strictMotif
    if {$parent == "."} {
	set w .__tk_filedialog
    } else {
	set w $parent.__tk_filedialog
    }
    upvar ::tk::dialog::file::__tk_filedialog data

    set button $data($btn\Btn)
    if ![winfo ismapped $button] {
	update
    }

    if {$type == "mouse"} {
	PressButton $button
    } else {
	event generate $w <Enter>
	focus $w
	event generate $button <Enter>
	event generate $w <Key> -keysym Return
	event generate $w <KeyPress> -keysym Return
    }
}


#----------------------------------------------------------------------
#
# The test suite proper
#
#----------------------------------------------------------------------

if {$tcl_platform(platform) == "unix"} {
    set modes "0 1"
} else {
    set modes 1
}

set unknownOptionsMsg(tk_getOpenFile,notAqua) {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
set unknownOptionsMsg(tk_getOpenFile) {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
set unknownOptionsMsg(tk_getOpenFile,aqua) {bad option "-foo": must be -command, -defaultextension, -filetypes, -initialdir, -initialfile, -message, -multiple, -parent, -title, or -typevariable}
set unknownOptionsMsg(tk_getSaveFile,notAqua) {bad option "-foo": must be -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -parent, -title, or -typevariable}
set unknownOptionsMsg(tk_getSaveFile) {bad option "-foo": must be -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -parent, -title, or -typevariable}
set unknownOptionsMsg(tk_getSaveFile,aqua) {bad option "-foo": must be -command, -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -message, -parent, -title, or -typevariable}

set tmpFile "filebox.tmp"
makeFile {
    # this file can be empty!
} $tmpFile

array set filters {
152
153
154
155
156
157
158
159

160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

179
180

181
182
183
184
185
186
187
188
189
190
151
152
153
154
155
156
157

158
159

160



161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176



177
178
179
180
181
182
183







-
+

-
+
-
-
-













-
+

-
+
-
-
-







	# Extension adding is only done when using the non-motif file
	# box with an extension-less filename
	if {!$mode} {
	    set addedExtensions {NONE {} .txt .txt}
	}
    }

    test filebox-1.1.1-$mode "tk_getOpenFile command" -constraints notAqua -body {
    test filebox-1.1-$mode "tk_getOpenFile command" -body {
	tk_getOpenFile -foo
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile,notAqua)
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile)
    test filebox-1.1.2-$mode "tk_getOpenFile command" -constraints aqua -body {
	tk_getOpenFile -foo
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile,aqua)

    catch {tk_getOpenFile -foo 1} msg
    regsub -all ,      $msg "" options
    regsub \"-foo\" $options "" options

    foreach option $options {
        if {[string index $option 0] eq "-"} {
	    test filebox-1.2-$mode$option "tk_getOpenFile command" -body {
		tk_getOpenFile $option
	    } -returnCodes error -result "value for \"$option\" missing"
        }
    }

    test filebox-1.3.1-$mode "tk_getOpenFile command" -constraints notAqua -body {
    test filebox-1.3-$mode "tk_getOpenFile command" -body {
        tk_getOpenFile -foo bar
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile,notAqua)
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile)
    test filebox-1.3.2-$mode "tk_getOpenFile command" -constraints aqua -body {
        tk_getOpenFile -foo bar
    } -returnCodes error -result $unknownOptionsMsg(tk_getOpenFile,aqua)
    test filebox-1.4-$mode "tk_getOpenFile command" -body {
        tk_getOpenFile -initialdir
    } -returnCodes error -result {value for "-initialdir" missing}
    test filebox-1.5-$mode "tk_getOpenFile command" -body {
        tk_getOpenFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-1.6-$mode "tk_getOpenFile command" -body {
205
206
207
208
209
210
211

212
213
214
215
216
217
218
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212







+







    set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring

    set color #404040
    test filebox-2.1-$mode "tk_getOpenFile command" nonUnixUserInteraction {
        ToPressButton $parent cancel
        tk_getOpenFile -title "Press Cancel ($verylongstring)" -parent $parent
    } ""

    set fileName $tmpFile
    set fileDir [tcltest::temporaryDirectory]
275
276
277
278
279
280
281



282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334














335
336
337
338
339
340
341
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293

294



295
296
297
298
299
300
301
302
303
304
305
306
307

308
309

310



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346







+
+
+













-
+

-
+
-
-
-













-
+

-
+
-
-
-















+
+
+
+
+
+
+
+
+
+
+
+
+
+







    }
    foreach {x res} [list 1 "-unset-" 2 "Text files"] {
	set t [expr {$x + [llength [array names filters]]}]
        test filebox-3.$t-$mode "tk_getOpenFile command" nonUnixUserInteraction {
	    catch {unset tv}
	    catch {unset typeName}
	    ToPressButton $parent ok
	    if {[info exists tv]} {
	    } else {
	    }
	    set choice [tk_getOpenFile -title "Press Ok" \
		    -filetypes $filters($x) -parent $parent \
		    -initialfile $fileName -initialdir $fileDir \
		    -typevariable tv]
	    if {[info exists tv]} {
		set typeName $tv
	    } else {
		set typeName "-unset-"
	    }
	    set typeName
        } $res
    }

    test filebox-4.1.1-$mode "tk_getSaveFile command" -constraints notAqua -body {
    test filebox-4.1-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -foo
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile,notAqua)
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile)
    test filebox-4.1.2-$mode "tk_getSaveFile command" -constraints aqua -body {
	tk_getSaveFile -foo
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile,aqua)

    catch {tk_getSaveFile -foo 1} msg
    regsub -all ,      $msg "" options
    regsub \"-foo\" $options "" options

    foreach option $options {
	if {[string index $option 0] eq "-"} {
	    test filebox-4.2-$mode$option "tk_getSaveFile command" -body {
		tk_getSaveFile $option
	    } -returnCodes error -result "value for \"$option\" missing"
	}
    }

    test filebox-4.3.1-$mode "tk_getSaveFile command" -constraints notAqua -body {
    test filebox-4.3-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -foo bar
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile,notAqua)
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile)
    test filebox-4.3.2-$mode "tk_getSaveFile command" -constraints aqua -body {
	tk_getSaveFile -foo bar
    } -returnCodes error -result $unknownOptionsMsg(tk_getSaveFile,aqua)
    test filebox-4.4-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -initialdir
    } -returnCodes error -result {value for "-initialdir" missing}
    test filebox-4.5-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -parent foo.bar
    } -returnCodes error -result {bad window path name "foo.bar"}
    test filebox-4.6-$mode "tk_getSaveFile command" -body {
	tk_getSaveFile -filetypes {Foo}
    } -returnCodes error -result {bad file type "Foo", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"}

    set isNative [expr {
	[info commands ::tk::MotifFDialog] eq "" &&
	[info commands ::tk::dialog::file::] eq ""
    }]

    set parent .

    set verylongstring longstring:
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring
    # set verylongstring $verylongstring$verylongstring

    set color #404040
    test filebox-5.1-$mode "tk_getSaveFile command" nonUnixUserInteraction {
	ToPressButton $parent cancel
	tk_getSaveFile -title "Press Cancel ($verylongstring)" -parent $parent
    } ""

    set fileName "12x 455"
    set fileDir [pwd]

Changes to tests/focus.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4


5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20




-
-
+
+







-
-
-







# This file is a Tcl script to test out the "focus" command and the
# other procedures in the file tkFocus.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

proc focusSetup {} {
    destroy .t
    toplevel .t
    wm geom .t +0+0
    foreach i {b1 b2 b3 b4} {
	    button .t.$i -text .t.$i -relief raised -bd 2
	    pack .t.$i
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84







-
+










-







update
bind all <FocusIn> {
    append focusInfo "in %W %d\n"
}
bind all <FocusOut> {
    append focusInfo "out %W %d\n"
}
bind all <Key> {
bind all <KeyPress> {
    append focusInfo "press %W %K"
}
focusSetup
if {[testConstraint altDisplay]} {
    focusSetupAlt
}


test focus-1.1 {Tk_FocusCmd procedure} -constraints unix -body {
    focusClear
    after 100
    focus
} -result {}
test focus-1.2 {Tk_FocusCmd procedure} -constraints {
	unix altDisplay
} -body {
    focus .alt.b
    focus
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323

324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318

319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+







-
+



-
+




















-
+







    list $focusInfo [focus]
} -result {{out . NotifyNonlinear
in .t NotifyNonlinearVirtual
in .t.b1 NotifyNonlinear
} .t.b1}

test focus-2.6 {TkFocusFilterEvent procedure, FocusIn events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
    unix  testwrapper
} -body {
    focus .t.b1
    focus .
    update
    event gen [testwrapper .t] <FocusIn> -detail NotifyAncestor
    set focusInfo {}
    set x [focus]
    event gen . <x>
    event gen . <KeyPress-x>
    list $x $focusInfo
} -result {.t.b1 {press .t.b1 x}}
test focus-2.7 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
    unix  testwrapper
} -body {
    set result {}
    foreach detail {NotifyAncestor NotifyInferior NotifyNonlinear
	    NotifyNonlinearVirtual NotifyPointer NotifyPointerRoot
	    NotifyVirtual} {
	    focus -force .t.b1
	    event gen [testwrapper .t] <FocusOut> -detail $detail
	    update
	    lappend result [focus]
    }
    return $result
} -result {{} .t.b1 {} {} .t.b1 .t.b1 {}}
test focus-2.8 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper
} -body {
    focus -force .t.b1
    event gen .t.b1 <FocusOut> -detail NotifyAncestor
    focus
} -result {.t.b1}
test focus-2.9 {TkFocusFilterEvent procedure, FocusOut events} -constraints {
    unix  testwrapper failsOnUbuntu failsOnXQuarz
    unix  testwrapper
} -body {
    focus .t.b1
    event gen [testwrapper .] <FocusOut> -detail NotifyAncestor
    focus
} -result {}
test focus-2.10 {TkFocusFilterEvent procedure, Enter events} -constraints {
    unix  testwrapper
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627







-
+

















-
+









# I don't know how to test most of the remaining procedures of this file
# explicitly;  they've already been exercised by the preceding tests.

# Test 5.1 fails (before and after update)
test focus-5.1 {ChangeXFocus procedure, don't take focus unless have it} -constraints {
    unix testwrapper secureserver failsOnUbuntu failsOnXQuarz
    unix testwrapper secureserver
} -body {
    setupbg
    focusSetup
    focus -force .t
    update
    set result [focus]
    send [dobg {tk appname}] {focus -force .; update}
    lappend result [focus]
    focus .t.b2
    update
    lappend result [focus]
} -cleanup {
    cleanupbg
} -result {.t {} {}}
destroy .t
bind all <FocusIn> {}
bind all <FocusOut> {}
bind all <Key> {}
bind all <KeyPress> {}


fixfocus
test focus-6.1 {miscellaneous - embedded application in same process} -constraints {
    unix  testwrapper
} -setup {
    eval interp delete [interp slaves]
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
726
727
728
729
730
731
732




















733























734
735
736
737
738
739







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






} -cleanup {
    destroy .t
    cleanupbg
    bind all <FocusIn> {}
    bind all <FocusOut> {}
} -result {{.t.f2.e1 {} {focus out .t.f2.e1 NotifyNonlinear} {focus out .t.f2 NotifyNonlinearVirtual} {focus in .t.f1 NotifyNonlinear} | {focus out .t.f1 NotifyNonlinear} {focus in .t.f2 NotifyNonlinearVirtual} {focus in .t.f2.e1 NotifyNonlinear}} {{focus in . NotifyVirtual} {focus in .e1 NotifyAncestor} | {focus out .e1 NotifyAncestor} {focus out . NotifyVirtual}}}

test focus-7.1 {TkSetFocusWin procedure, unmapped windows} -setup {
    # TkSetFocusWin handles the case of not yet mapped windows
    # by not setting the focus on them right at the time it is
    # requested, but by scheduling an event handler that will
    # set the focus later once it gets mapped. The purpose of
    # this test is to check that event scheduling and deletion
    # work as expected (bug [08e2f8e6f0]).
    toplevel .top
    spinbox .top.s1
    spinbox .top.s2
    spinbox .top.s3
    grid .top.s1 .top.s2 .top.s3
} -body {
    focus -force .top.s2
    focus -force .top.s3
    update
    focus
} -cleanup {
    destroy .top
} -result {.top.s3}

test focus-8.1 {fdc0ed342d - segfault on focus -force} -body {
    pack [button .b0]
    toplevel .one
    update
    event generate .one <Motion> -warp 1 -x 175 -y 175
    update idletasks
    destroy {*}[winfo children .]
    toplevel .t
    pack [canvas .t.c]
    update
    destroy .t.c
    pack [label .t.l]
    update
    destroy .t.l
    destroy {*}[winfo children .]
    proc crashit {} {
	pack [listbox .l]
	update
	focus -force .l;  # This line segfaulted *with xvfb*
	set res Reached
    }
    crashit
} -result {Reached}

deleteWindows

# cleanup
cleanupTests
return

Changes to tests/focusTcl.test.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# This file is a Tcl script to test out the features of the script
# file focus.tcl, which includes the procedures tk_focusNext and
# tk_focusPrev, among other things.  This file is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

Changes to tests/font.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3
4


5
6
7
8
9
10
11
12
13




14
15
16
17
18
19
20




-
-
+
+







-
-
-
-







# This file is a Tcl script to test out Tk's "font" command
# plus the procedures in tkFont.c.  It is organized in the
# standard white-box fashion for Tcl tests.
#
# Copyright © 1996-1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Some tests require support for 4-byte UTF-8 sequences
testConstraint fullutf [expr {[format %c 0x010000] != "\uFFFD"}]
testConstraint utfcompat [expr {([string length "\U10000"] == 2) && [package vsatisfies [package provide Tcl] 8]}]
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]

set defaultfontlist [font names]

proc getnondefaultfonts {} {
    global defaultfontlist
    set nondeffonts [list ]
    foreach afont [font names] {
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86






87
88
89
90
91
92
93
94
95



96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122

123
124
125

126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153

154
155
156

157
158
159


160
161
162

163
164
165
166
167
168
169
170
171
172
173
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76






77
78
79
80
81
82
83
84
85
86
87
88



89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117

118
119
120

121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148

149
150
151

152
153


154
155
156
157

158
159



160
161
162
163
164
165
166







-
+



















-
-
-
+
+
+













-
-
-
-
-
-
+
+
+
+
+
+






-
-
-
+
+
+



-
+


















-
+



-
+


-
+






-
+








-
+











-
+


-
+

-
-
+
+


-
+

-
-
-







deleteWindows
# Toplevel used (in some tests) of the whole file
toplevel .t
wm geom .t +0+0
update idletasks

switch [tk windowingsystem] {
    x11	 	{set fixed "TkFixedFont"}
    x11	 	{set fixed "fixed"}
    win32	{set fixed "courier 12"}
    aqua	{set fixed "monaco 9"}
}


# Procedure used in tests: 24.15, 26.*, 28.*, 30.*, 31.*, 32.1
proc csetup {{str ""}} {
    focus -force .t.c
    .t.c dchars text 0 end
    .t.c insert text 0 $str
    .t.c focus text
}


test font-1.1 {TkFontPkgInit} -setup {
    catch {interp delete foo}
} -body {
    interp create foo
    foo eval {
	load {} Tk
	wm geometry . +0+0
	update
		load {} Tk
		wm geometry . +0+0
		update
    }
    interp delete foo
} -result {}


test font-2.1 {TkFontPkgFree} -setup {
    catch {interp delete foo}
    set x {}
} -body {
    interp create foo

    # Makes sure that named font was visible only to child interp.
    foo eval {
	load {} Tk
	wm geometry . +0+0
	button .b -font {times 16} -text "hi"
	pack .b
	font create wiggles -family courier -underline 1
	update
		load {} Tk
		wm geometry . +0+0
		button .b -font {times 16} -text "hi"
		pack .b
		font create wiggles -family courier -underline 1
		update
    }
    lappend x [catch {font configure wiggles} msg; set msg]

    # Tests cancelling the idle handler for TheWorldHasChanged,
    # because app goes away before idle serviced.
    foo eval {
	.b config -font wiggles
	font config wiggles -size 24
	destroy .
		.b config -font wiggles
		font config wiggles -size 24
		destroy .
    }
    lappend x [foo eval {catch {font families} msg; set msg}]
} -cleanup {
    interp delete foo
        interp delete foo
} -result {{named font "wiggles" doesn't exist} {can't invoke "font" command: application has been destroyed}}


test font-3.1 {font command: general} -body {
    font
} -returnCodes error -result {wrong # args: should be "font option ?arg?"}
test font-3.2 {font command: general} -body {
    font xyz
} -returnCodes error -result {bad option "xyz": must be actual, configure, create, delete, families, measure, metrics, or names}


test font-4.1 {font command: actual: arguments} -body {
    # (skip < 0)
    font actual xyz -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-4.2 {font command: actual: arguments} -body {
    # (objc < 3)
    font actual
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"}
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.3 {font command: actual: arguments} -body {
    # (objc - skip > 4) when skip == 0
    font actual xyz abc def
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"}
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.4 {font command: actual: displayof specified, so skip to next} -body {
    catch {font actual xyz -displayof . -size}
} -result 0
} -result {0}
test font-4.5 {font command: actual: displayof specified, so skip to next} -body {
    lindex [font actual xyz -displayof .] 0
} -result {-family}
test font-4.6 {font command: actual: arguments} -body {
    # (objc - skip > 4) when skip == 2
    font actual xyz -displayof . abc def
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"}
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.7 {font command: actual: arguments} -constraints noExceed -body {
    # (tkfont == NULL)
    font actual "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-4.8 {font command: actual: all attributes} -body {
    # not (objc > 3) so objPtr = NULL
    lindex [font actual {-family times}] 0
} -result {-family}
test font-4.9 {font command: actual} -constraints {unix noExceed failsOnUbuntu} -body {
test font-4.9 {font command: actual} -constraints {unix noExceed} -body {
    # (objc > 3) so objPtr = objv[3 + skip]
    string tolower [font actual {-family times} -family]
} -result {times}
test font-4.10 {font command: actual} -constraints win -body {
    # (objc > 3) so objPtr = objv[3 + skip]
    font actual {-family times} -family
} -result {times}
test font-4.11 {font command: bad option} -body {
    font actual xyz -style
} -returnCodes error -result {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}
test font-4.12 {font command: actual} -body {
    font actual {-family times} -- \uD800
    font actual {-family times} -- \ud800
} -match glob -result {*}
test font-4.13 {font command: actual} -body {
    font actual {-family times} -- \uDC00
    font actual {-family times} -- \udc00
} -match glob -result {*}
test font-4.14 {font command: actual} -constraints {utfcompat win knownBug} -body {
    font actual {-family times} -family -- \uD800\uDC00
test font-4.14 {font command: actual} -constraints win -body {
    font actual {-family times} -family -- \ud800\udc00
} -result {times}
test font-4.15 {font command: actual} -body {
    font actual {-family times} -- \uDC00\uD800
    font actual {-family times} -- \udc00\ud800
} -returnCodes 1 -match glob -result {expected a single character but got "*"}
test font-4.16 {font command: actual} -constraints {fullutf win knownBug} -body {
    font actual {-family times} -family -- \U10000
} -result {times}


test font-5.1 {font command: configure} -body {
    # (objc < 3)
    font configure
} -returnCodes error -result {wrong # args: should be "font configure fontname ?-option value ...?"}
test font-5.2 {font command: configure: non-existent font} -body {
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206

207
208

209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198

199
200

201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+







-
+

-
+










-
+







-
+



















-
+







test font-5.4 {font command: configure: get all options} -setup {
    catch {font delete xyz}
} -body {
    # (objc == 3) so objPtr = NULL
    font create xyz -family xyz
    lindex [font configure xyz] 1
} -cleanup {
    font delete xyz
	font delete xyz
} -result xyz
test font-5.5 {font command: configure: get one option} -setup {
    clearnondefaultfonts
} -body {
    # (objc == 4) so objPtr = objv[3]
    font create xyz -family xyz
    font configure xyz -family
    getnondefaultfonts
	getnondefaultfonts
} -cleanup {
    font delete xyz
	font delete xyz
} -result xyz
test font-5.6 {font command: configure: update existing font} -setup {
    catch {font delete xyz}
} -body {
    # else result = ConfigAttributesObj()
    font create xyz
    font configure xyz -family xyz
    update
    font configure xyz -family
} -cleanup {
    font delete xyz
	font delete xyz
} -result xyz
test font-5.7 {font command: configure: bad option} -setup {
    catch {font delete xyz}
} -body {
    font create xyz
    font configure xyz -style
} -cleanup {
    font delete xyz
	font delete xyz
} -returnCodes error -result {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}


test font-6.1 {font command: create: make up name} -setup {
    clearnondefaultfonts
} -body {
    # (objc < 3) so name = NULL
    font create
    getnondefaultfonts
} -cleanup {
    font delete font1
} -result {font1}
test font-6.2 {font command: create: name specified} -setup {
    clearnondefaultfonts
} -body {
    # not (objc < 3)
    font create xyz
    getnondefaultfonts
} -cleanup {
    font delete xyz
	font delete xyz
} -result {xyz}
test font-6.3 {font command: create: name not really specified} -setup {
    clearnondefaultfonts
} -body {
    # (name[0] == '-') so name = NULL
    font create -family xyz
    getnondefaultfonts
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
275
276
277
278
279
280
281

282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314







-
+








-
+















-
+







test font-6.7 {font command: create: already exists} -setup {
    catch {font delete xyz}
} -body {
    # (CreateNamedFont() != TCL_OK)
    font create xyz
    font create xyz
} -cleanup {
    font delete xyz
	font delete xyz
} -returnCodes error -result {named font "xyz" already exists}

test font-7.1 {font command: delete: arguments} -body {
    # (objc < 3)
    font delete
} -returnCodes error -result {wrong # args: should be "font delete fontname ?fontname ...?"}
test font-7.2 {font command: delete: loop test} -setup {
    clearnondefaultfonts
    set x {}
	set x {}
} -body {
    # for (i = 2; i < objc; i++)
    font create a -underline 1
    font create b -underline 1
    font create c -underline 1
    font create d -underline 1
    font create e -underline 1
    lappend x [lsort [getnondefaultfonts]]
    font delete a e c b
    lappend x [lsort [getnondefaultfonts]]
} -cleanup {
    getnondefaultfonts
} -result {{a b c d e} d}
test font-7.3 {font command: delete: loop test} -setup {
    clearnondefaultfonts
    set x {}
	set x {}
} -body {
    # (namedHashPtr == NULL) in middle of loop
    font create a -underline 1
    font create b -underline 1
    font create c -underline 1
    font create d -underline 1
    font create e -underline 1
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361







-
+













-
+







    # (nfPtr->refCount != 0)
    font create xyz
    .t.f configure -font xyz
    font delete xyz
    font actual xyz
    font configure xyz
} -cleanup {
    destroy .t.f
	destroy .t.f
} -returnCodes error -result {named font "xyz" doesn't exist}
test font-7.6 {font command: delete: mark for later deletion} -setup {
    destroy .t.f
    catch {font delete xyz}
    pack [label .t.f]
    update
} -body {
    # (nfPtr->refCount != 0)
    font create xyz
    .t.f configure -font xyz
    font delete xyz
    font actual xyz
    catch {font configure xyz}
    .t.f cget -font
	.t.f cget -font
} -cleanup {
	destroy .t.f
} -result xyz
test font-7.7 {font command: delete: actually delete} -setup {
    catch {font delete xyz}
} -body {
    # not (nfPtr->refCount != 0)
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387







-
+







    # (objc - skip != 2) when skip == 0
    font families xyz
} -returnCodes error -result {wrong # args: should be "font families ?-displayof window?"}
test font-8.3 {font command: families: arguments} -body {
    # (objc - skip != 2) when skip == 2
    font families -displayof . xyz
} -returnCodes error -result {wrong # args: should be "font families ?-displayof window?"}
test font-8.4 {font command: families} -constraints failsOnUbuntu -body {
test font-8.4 {font command: families} -body {
    # TkpGetFontFamilies()
    regexp -nocase times [font families]
} -result 1


test font-9.1 {font command: measure: arguments} -body {
    # (skip < 0)
427
428
429
430
431
432
433
434

435
436
437
438

439
440
441
442

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
420
421
422
423
424
425
426

427
428
429
430

431
432
433
434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459







-
+



-
+



-
+
















-
+







test font-10.2 {font command: metrics: arguments} -body {
    # (skip < 0)
    font metrics xyz -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-10.3 {font command: metrics: arguments} -body {
    # (objc < 3)
    font metrics
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?-option?"}
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"}
test font-10.4 {font command: metrics: arguments} -body {
    # (objc - skip) > 4) when skip == 0
    font metrics xyz abc def
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?-option?"}
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"}
test font-10.5 {font command: metrics: arguments} -body {
    # (objc - skip) > 4) when skip == 2
    font metrics xyz -displayof . abc
} -returnCodes error -result {bad metric "abc": must be -ascent, -descent, -fixed, or -linespace}
} -returnCodes error -result {bad metric "abc": must be -ascent, -descent, -linespace, or -fixed}
test font-10.6 {font command: metrics: bad font} -constraints noExceed -body {
    # (tkfont == NULL)
    font metrics "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-10.7 {font command: metrics: get all metrics} -setup {
    catch {unset a}
} -body {
    # (objc == 3)
    array set a [font metrics {-family xyz}]
    lsort [array names a]
} -cleanup {
    unset a
} -result {-ascent -descent -fixed -linespace}
test font-10.8 {font command: metrics: bad metric} -body {
    # (Tcl_GetIndexFromObj() != TCL_OK)
    font metrics $fixed -xyz
} -returnCodes error -result {bad metric "-xyz": must be -ascent, -descent, -fixed, or -linespace}
} -returnCodes error -result {bad metric "-xyz": must be -ascent, -descent, -linespace, or -fixed}
test font-10.9 {font command: metrics: get individual metrics} -body {
    font metrics $fixed -ascent
    font metrics $fixed -descent
    font metrics $fixed -linespace
    font metrics $fixed -fixed
} -result 1

512
513
514
515
516
517
518
519

520
521
522
523
524
525

526
527
528
529
530

531
532
533
534

535
536
537
538

539
540

541
542
543
544
545

546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586


587
588
589
590
591
592
593
594
595

596
597
598
599

600
601
602
603

604
605
606
607
608
609

610
611
612
613
614

615
616
617

618
619

620
621
622
623
624
625

626
627
628
629
630

631
632

633
634
635

636
637
638
639
640
641
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
505
506
507
508
509
510
511

512
513
514
515
516
517

518
519
520
521
522

523
524
525
526

527
528
529
530

531
532

533
534
535
536
537

538
539
540
541
542
543
544

545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572
573
574
575
576
577


578
579
580
581
582
583
584
585
586
587

588
589
590
591

592
593
594
595

596
597

598
599
600

601
602
603
604
605

606
607
608

609
610

611
612

613
614
615

616
617
618
619
620

621
622

623
624
625

626
627

628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669







-
+





-
+




-
+



-
+



-
+

-
+




-
+






-
+








-
+








-
+














-
-
+
+








-
+



-
+



-
+

-



-
+




-
+


-
+

-
+

-



-
+




-
+

-
+


-
+

-











-
+











-
+










-
+







test font-12.1 {UpdateDependantFonts procedure: no users} -setup {
    catch {font delete xyz}
} -body {
    # (nfPtr->refCount == 0)
    font create xyz
    font configure xyz -family times
} -cleanup {
    font delete xyz
	font delete xyz
} -result {}
test font-12.2 {UpdateDependantFonts procedure: pings the widgets} -setup {
    destroy .t.f
    catch {font delete xyz}
    pack [label .t.f]
    update idletasks
    update
} -body {
    font create xyz -family times -size 20
    .t.f config -font xyz -text "abcd" -padx 0 -bd 0 -highlightthickness 0
    set a1 [font measure xyz "abcd"]
    update idletasks
    update
    set b1 [winfo reqwidth .t.f]
    font configure xyz -family helvetica -size 20
    set a2 [font measure xyz "abcd"]
    update idletasks
    update
    set b2 [winfo reqwidth .t.f]
    expr {$a1==$b1 && $a2==$b2}
} -cleanup {
    destroy .t.f
	destroy .t.f
    font delete xyz
} -result 1
} -result {1}


test font-13.1 {CreateNamedFont: new named font} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    # not (new == 0)
    lappend x [getnondefaultfonts]
    font create xyz
    lappend x [getnondefaultfonts]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {{} xyz}
test font-13.2 {CreateNamedFont: named font already exists} -setup {
    catch {font delete xyz}
} -body {
    # (new == 0)
    font create xyz
    font create xyz
} -cleanup {
    font delete xyz
	font delete xyz
} -returnCodes error -result {named font "xyz" already exists}
test font-13.3 {CreateNamedFont: named font already exists} -setup {
    catch {font delete xyz}
} -body {
    # (nfPtr->deletePending == 0)
    font create xyz
    font create xyz
} -cleanup {
    font delete xyz
	font delete xyz
} -returnCodes error -result {named font "xyz" already exists}
test font-13.4 {CreateNamedFont: recreate "deleted" font} -setup {
    destroy .t.f
    catch {font delete xyz}
    pack [label .t.f]
    update
} -body {
    # not (nfPtr->deletePending == 0)
    font create xyz -family times
    .t.f configure -font xyz
    font delete xyz
    font create xyz -family courier
    font configure xyz -family
} -cleanup {
    font delete xyz
    destroy .t.f
	font delete xyz
	destroy .t.f
} -result {courier}


test font-14.1 {Tk_GetFont procedure} -body {
} -result {}


test font-15.1 {Tk_AllocFontFromObj - converting internal reps} -constraints {
    testfont
	testfont
} -setup {
    destroy .b1 .b2
} -body {
    set x [font create font-15.1_font -family Times -size 16]
    set x {Times 16}
    lindex $x 0
    button .b1 -font $x
    lindex $x 0
    testfont counts $x
    testfont counts {Times 16}
} -cleanup {
    font delete font-15.1_font
    destroy .b1 .b2
} -result {{1 0}}
test font-15.2 {Tk_AllocFontFromObj - discard stale font} -constraints {
    testfont
	testfont
} -setup {
    destroy .b1 .b2
    set result {}
} -body {
    set x [font create font-15.2_font -family Times -size 16]
    set x {Times 16}
    button .b1 -font $x
    destroy .b1
    lappend result [testfont counts $x]
    lappend result [testfont counts {Times 16}]
    button .b2 -font $x
    lappend result [testfont counts $x]
    lappend result [testfont counts {Times 16}]
} -cleanup {
    font delete font-15.2_font
    destroy .b2
} -result {{} {{1 1}}}
test font-15.3 {Tk_AllocFontFromObj - reuse existing font} -constraints {
    testfont
	testfont
} -setup {
    destroy .b1 .b2
    set result {}
} -body {
    set x [font create font-15.3_font -family Times -size 16]
    set x {Times 16}
    button .b1 -font $x
    lappend result [testfont counts $x]
    lappend result [testfont counts {Times 16}]
    button .b2 -font $x
    pack .b1 .b2 -side top
    lappend result [testfont counts $x]
    lappend result [testfont counts {Times 16}]
} -cleanup {
    font delete font-15.3_font
    destroy .b1 .b2
} -result {{{1 1}} {{2 1}}}
test font-15.4 {Tk_AllocFontFromObj procedure: bump ref count} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    # (new == 0)
    .t.f config -font {-family fixed}
    lindex [font actual {-family fixed}] 0
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {-family}
test font-15.5 {Tk_AllocFontFromObj procedure: get named font} -setup {
    destroy .t.f
    catch {font delete xyz}
    pack [label .t.f]
    update
} -body {
    # (namedHashPtr != NULL)
    font create xyz
    .t.f config -font xyz
} -cleanup {
    destroy .t.f
	destroy .t.f
    font delete xyz
} -result {}
test font-15.6 {Tk_AllocFontFromObj procedure: not a named font} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    # not (namedHashPtr != NULL)
    .t.f config -font {times 20}
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {-family} -result {}
test font-15.7 {Tk_AllocFontFromObj procedure: get native font} -constraints {
	unix
} -setup {
    destroy .t.f
    pack [label .t.f]
    update
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725

726
727
728
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744
745
746
747
748

749
750
751
752
753

754
755
756
757
758

759
760
761
762

763
764

765
766

767
768

769
770
771
772
773
774
775
776
777
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713
714

715
716
717
718
719
720
721
722
723
724
725

726
727
728
729
730
731
732
733
734
735
736
737

738
739
740
741
742

743
744
745
746
747

748
749
750
751

752
753

754
755

756
757

758


759
760
761
762
763
764
765







-
+








-
+










-
+











-
+




-
+




-
+



-
+

-
+

-
+

-
+
-
-







    font actual "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-15.11 {Tk_AllocFontFromObj procedure: get attribute font} -body {
    # not (ParseFontNameObj() != TCL_OK)
    lindex [font actual {plan 9}] 0
} -result {-family}
test font-15.12 {Tk_AllocFontFromObj procedure: setup tab width} -setup {
    destroy .l
	destroy .l
} -body {
    # Tk_MeasureChars(fontPtr, "0", ...)
    label .l -bd 0 -padx 0  -highlightthickness 0 -font $fixed -text "a\tb"
    update
    set res1 [winfo reqwidth .l]
	set res2 [expr [font measure $fixed "0"]*9]
	expr {$res1 eq $res2}
} -cleanup {
    destroy .l
	destroy .l
} -result 1
test font-15.13 {Tk_AllocFontFromObj procedure: underline position} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    # (fontPtr->underlineHeight == 0) because size was < 10
    .t.f config -text "underline" -font "times -8 underline"
    update
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {}


test font-16.1 {Tk_NameOfFont procedure} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    .t.f config -font -family\ fixed
    .t.f cget -font
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {-family fixed}


test font-17.1 {Tk_FreeFontFromObj - reference counts} -constraints {
    testfont
	testfont
} -setup {
    destroy .b1 .b2 .b3
    set result {}
} -body {
    set x [font create font-17.1_font -family Courier -size 12]
    set x {Courier 12}
    button .b1 -font $x
    button .b3 -font $x
    button .b2 -font $x
    lappend result [testfont counts $x]
    lappend result [testfont counts {Courier 12}]
    destroy .b1
    lappend result [testfont counts $x]
    lappend result [testfont counts {Courier 12}]
    destroy .b2
    lappend result [testfont counts $x]
    lappend result [testfont counts {Courier 12}]
    destroy .b3
    lappend result [testfont counts $x]
    lappend result [testfont counts {Courier 12}]
} -cleanup {
    font delete font-17.1_font
} -result {{{3 1}} {{2 1}} {{1 1}} {}}
test font-17.2 {Tk_FreeFont procedure: one ref} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    # (fontPtr->refCount == 0)
835
836
837
838
839
840
841
842
843

844
845

846
847

848
849

850
851

852
853

854
855

856
857
858
859
860
861
862
863
864
865
866
823
824
825
826
827
828
829


830
831

832
833

834
835

836
837

838
839

840
841

842
843
844


845
846
847
848
849
850
851







-
-
+

-
+

-
+

-
+

-
+

-
+

-
+


-
-







} -result {-family -family}


test font-18.1 {FreeFontObjProc} -constraints testfont -setup {
    destroy .b1
    set result {}
} -body {
    set f [font create font-18.1_font -family Courier -size 12]
    set x [join [list $f 50] { }]
    set x [join {Courier 12} { }]
    button .b1 -font $x
    set y [join [list $f 50] { }]
    set y [join {Courier 12} { }]
    .b1 configure -font $y
    set z [join [list $f 50] { }]
    set z [join {Courier 12} { }]
    .b1 configure -font $z
    lappend result [testfont counts [list $f 50]]
    lappend result [testfont counts {Courier 12}]
    set x red
    lappend result [testfont counts [list $f 50]]
    lappend result [testfont counts {Courier 12}]
    set z 32
    lappend result [testfont counts [list $f 50]]
    lappend result [testfont counts {Courier 12}]
    destroy .b1
    lappend result [testfont counts [list $f 50]]
    lappend result [testfont counts {Courier 12}]
    set y bogus
    return $result
} -cleanup {
    font delete font-18.1_font
} -result {{{1 3}} {{1 2}} {{1 1}} {}}


test font-19.1 {Tk_FontId} -setup {
    destroy .t.f
    pack [label .t.f]
    update
932
933
934
935
936
937
938
939

940
941
942
943
944
945
946
917
918
919
920
921
922
923

924
925
926
927
928
929
930
931







-
+







    if {[string match lucida*bright $x]} {
		psfontname "{lucida bright} 10"
    } else {
		set x {LucidaBright}
    }
} -result {LucidaBright}
test font-21.6 {Tk_PostscriptFontName procedure: spaces} -constraints {
	x11 failsOnUbuntu
	unix
} -body {
    psfontname "{new century schoolbook} 10"
} -result {NewCenturySchlbk-Roman}

test font-21.7 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
    unix
} -body {
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466




1467
1468
1469

1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501



1502
1503
1504
1505
1506
1507



1508
1509
1510
1511
1512
1513



1514
1515
1516
1517
1518
1519



1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530



1531
1532
1533
1534
1535
1536



1537
1538
1539
1540
1541

1542
1543

1544
1545

1546
1547

1548
1549
1550
1551
1552
1553
1554
1555

1556
1557

1558
1559
1560
1561



1562
1563
1564
1565
1566
1567
1568
1569
1570
1571



1572
1573
1574
1575



1576
1577
1578
1579
1580
1581
1582
1583
1584
1585



1586
1587
1588
1589



1590
1591
1592
1593
1594
1595
1596
1597
1598



1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610









1611
1612
1613
1614
1615
1616
1617
1618
1619
1620





1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661

1662
1663
1664
1665
1666
1667
1668
1439
1440
1441
1442
1443
1444
1445

1446
1447




1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483



1484
1485
1486
1487
1488
1489



1490
1491
1492
1493
1494
1495



1496
1497
1498
1499
1500
1501



1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512



1513
1514
1515
1516
1517
1518



1519
1520
1521
1522
1523
1524
1525

1526
1527

1528
1529

1530
1531

1532
1533
1534
1535
1536
1537
1538
1539

1540
1541

1542
1543



1544
1545
1546
1547
1548
1549
1550
1551
1552
1553



1554
1555
1556
1557



1558
1559
1560
1561
1562
1563
1564
1565
1566
1567



1568
1569
1570
1571



1572
1573
1574
1575
1576
1577
1578
1579
1580



1581
1582
1583
1584
1585
1586









1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600





1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628

1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645

1646
1647
1648
1649
1650
1651
1652
1653







-
+

-
-
-
-
+
+
+
+


-
+




-
+







-
+
















-
-
-
+
+
+



-
-
-
+
+
+



-
-
-
+
+
+



-
-
-
+
+
+








-
-
-
+
+
+



-
-
-
+
+
+




-
+

-
+

-
+

-
+







-
+

-
+

-
-
-
+
+
+







-
-
-
+
+
+

-
-
-
+
+
+







-
-
-
+
+
+

-
-
-
+
+
+






-
-
-
+
+
+



-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+





-
-
-
-
-
+
+
+
+
+











-
+











-
+
















-
+







    win
} -body {
    set x [psfontname {{times new roman} 12 italic bold}]
} -result {Times-BoldItalic}


test font-22.1 {Tk_TextWidth procedure} -setup {
    destroy .t.l
	destroy .t.l
} -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
	    -text "0" -font "Courier -12"
    pack .t.l
    set ax [winfo reqwidth .t.l]
	label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
		-text "0" -font "Courier -12"
	pack .t.l
	set ax [winfo reqwidth .t.l]
    expr {[font measure [.t.l cget -font] "000"] eq $ax*3}
} -cleanup {
    destroy .t.l
	destroy .t.l
} -result 1


test font-23.1 {Tk_UnderlineChars procedure} -setup {
    destroy .t.t
	destroy .t.t
} -body {
    text .t.t
    .t.t insert 1.0 abc\tdefg
    .t.t tag config sel -underline 1
    .t.t tag add sel 1.0 end
    update
} -cleanup {
    destroy .t.t
	destroy .t.t
} -result {}


# Data used in 24.* tests
destroy .t.l
label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
	-text "0" -font "Courier -12"
pack .t.l
update
set ax [winfo reqwidth .t.l]
set ay [winfo reqheight .t.l]
test font-24.1 {Tk_ComputeTextLayout: empty string} -body {
    .t.l config -text ""
} -result {}
test font-24.2 {Tk_ComputeTextLayout: simple string} -body {
    .t.l config -text "000"
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
	    [expr {[winfo reqheight .t.l] eq $ay}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
		[expr {[winfo reqheight .t.l] eq $ay}]
} -result {1 1}
test font-24.3 {Tk_ComputeTextLayout: find special chars} -body {
    .t.l config -text "000\n000"
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
	    [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
		[expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
} -result {1 1}
test font-24.4 {Tk_ComputeTextLayout: calls Tk_MeasureChars} -body {
    .t.l config -text "000\n000"
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
	    [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}] \
		[expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
} -result {1 1}
test font-24.5 {Tk_ComputeTextLayout: break line} -body {
    .t.l config -text "000\t00000" -wrap [expr 9 * $ax]
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 8}]}] \
	    [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 8}]}] \
		[expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
} -cleanup {
    .t.l config -wrap 0
} -result {1 1}
test font-24.6 {Tk_ComputeTextLayout: normal ended on special char} -body {
    .t.l config -text "000\n000"
} -result {}
test font-24.7 {Tk_ComputeTextLayout: special char was \n} -body {
    .t.l config -text "000\n0000"
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}] \
	    [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}] \
		[expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
} -result {1 1}
test font-24.8 {Tk_ComputeTextLayout: special char was \t} -body {
    .t.l config -text "000\t00"
    update
    list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 10}]}] \
	    [expr {[winfo reqheight .t.l] eq $ay}]
	update
	list [expr {[winfo reqwidth .t.l] eq [expr {$ax * 10}]}] \
		[expr {[winfo reqheight .t.l] eq $ay}]
} -result {1 1}
test font-24.9 {Tk_ComputeTextLayout: tab didn't cause break} -body {
    set x {}
    .t.l config -text "000\t000"
    update
	update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 11}]}]
    lappend x [expr {[winfo reqheight .t.l] eq $ay}]
	lappend x [expr {[winfo reqheight .t.l] eq $ay}]
    .t.l config -text "000\t000" -wrap [expr 100 * $ax]
    update
	update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 11}]}]
    lappend x [expr {[winfo reqheight .t.l] eq $ay}]
	lappend x [expr {[winfo reqheight .t.l] eq $ay}]
    return $x
} -cleanup {
    .t.l config -wrap 0
} -result {1 1 1 1}
test font-24.10 {Tk_ComputeTextLayout: tab caused break} -body {
    set x {}
    .t.l config -text "000\t"
    update
	update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 8}]}]
    lappend x [expr {[winfo reqheight .t.l] eq $ay}]
	lappend x [expr {[winfo reqheight .t.l] eq $ay}]
    .t.l config -text "000\t00" -wrap [expr $ax * 6]
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 8}]}]
    lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 8}]}]
	lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    return $x
} -cleanup {
    .t.l config -wrap 0
} -result {1 1 1 1}
test font-24.11 {Tk_ComputeTextLayout: absorb spaces at eol} -body {
    set x {}
    .t.l config -text "000            000" -wrap [expr {$ax * 5}]
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}]
    lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}]
	lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    .t.l config -text "000            "
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}]
    lappend x [expr {[winfo reqheight .t.l] eq $ay}]
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 3}]}]
	lappend x [expr {[winfo reqheight .t.l] eq $ay}]
    return $x
} -cleanup {
    .t.l config -wrap 0
} -result {1 1 1 1}
test font-24.12 {Tk_ComputeTextLayout: append non-printing spaces to chunk} -body {
    set x {}
    .t.l config -text "000            0000" -wrap [expr {$ax * 5}]
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
    lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
	lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    .t.l config -text "000\t00            0000" -wrap [expr {$ax * 12}]
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 10}]}]
    lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 10}]}]
	lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    return $x
} -cleanup {
    .t.l config -wrap 0
} -result {1 1 1 1}
test font-24.13 {Tk_ComputeTextLayout: many lines -> realloc line array} -body {
    .t.l config -text "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    update
    list [expr {[winfo reqwidth .t.l] eq 1}] \
	    [expr {[winfo reqheight .t.l] eq [expr {$ay * 129}]}]
	update
	list [expr {[winfo reqwidth .t.l] eq 1}] \
		[expr {[winfo reqheight .t.l] eq [expr {$ay * 129}]}]
} -result {1 1}
test font-24.14 {Tk_ComputeTextLayout: text ended with \n} -body {
    set x {}
    .t.l config -text "0000"
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
    lappend x [expr {[winfo reqheight .t.l] eq $ay}]
    .t.l config -text "0000\n"
    update
    lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
    lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    set x
	.t.l config -text "0000"
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
	lappend x [expr {[winfo reqheight .t.l] eq $ay}]
	.t.l config -text "0000\n"
	update
	lappend x [expr {[winfo reqwidth .t.l] eq [expr {$ax * 4}]}]
	lappend x [expr {[winfo reqheight .t.l] eq [expr {$ay * 2}]}]
    return $x
} -result {1 1 1 1}
destroy .t.l

test font-24.15 {Tk_ComputeTextLayout: justification} -setup {
    set x {}
    destroy .t.c
    canvas .t.c -closeenough 0
    .t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
    pack .t.c
    update
	destroy .t.c
	canvas .t.c -closeenough 0
	.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
	pack .t.c
	update
} -body {
    csetup "000\n00000"
    .t.c itemconfig text -just left
    lappend x [.t.c index text @[expr $ax*2],0]
    .t.c itemconfig text -just center
    lappend x [.t.c index text @[expr $ax*2],0]
    .t.c itemconfig text -just right
    lappend x [.t.c index text @[expr $ax*2],0]
    .t.c itemconfig text -just left
    return $x
} -cleanup {
    destroy .t.c
	destroy .t.c
} -result {2 1 0}


test font-25.1 {Tk_FreeTextLayout procedure} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    .t.f config -text foo
    .t.f config -text boo
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {}


# Canvas created for tests: 26.*
destroy .t.c
canvas .t.c -closeenough 0
.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
pack .t.c
update
test font-26.1 {Tk_DrawTextLayout procedure: auto-detect last char} -setup {
    destroy .t.f
    pack [label .t.f]
    update
} -body {
    .t.f config -text foo
} -cleanup {
    destroy .t.f
	destroy .t.f
} -result {}
test font-26.2 {Tk_DrawTextLayout procedure: multiple chunks} -body {
    csetup "000\t00\n000"
} -result {}
test font-26.3 {Tk_DrawTextLayout: draw subset of chunk: numDisplay <= 0} -body {
    csetup "000\t00"
    .t.c select from text 3
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
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







-
+






-
+














-
+











-
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+






-
+



-
+








-
+







destroy .t.c

#  Label used in 27.* tests
destroy .t.f
pack [label .t.f]
update
test font-27.1 {Tk_UnderlineTextLayout procedure: no underline chosen} -body {
    .t.f config -text "foo" -underline {}
    .t.f config -text "foo" -under -1
} -result {}
test font-27.2 {Tk_UnderlineTextLayout procedure: underline not visible} -body {
    .t.f config -text "000          00000" -wrap [expr $ax*7] -under 10
} -result {}
test font-27.3 {Tk_UnderlineTextLayout procedure: underline is visible} -body {
    .t.f config -text "000          00000" -wrap [expr $ax*7] -under 5
    .t.f config -wrap -1 -underline {}
    .t.f config -wrap -1 -under -1
} -result {}
destroy .t.f



# Canvas created for tests: 28.*
destroy .t.c
canvas .t.c -closeenough 0
.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
pack .t.c
update
test font-28.1 {Tk_PointToChar procedure: above all lines} -body {
    csetup "000"
    .t.c index text @-1,0
} -result 0
} -result {0}
test font-28.2 {Tk_PointToChar procedure: no chars} -body {
    # After fixing the following bug:
    #
    # In canvas text item, it was impossible to click to position the
    # insertion point just after the last character.
    #
    # introduced another bug that Tk_PointToChar() would return a character
    # index of 1 if TextLayout contained 0 characters.

    csetup ""
    .t.c index text @100,100
} -result 0
} -result {0}
test font-28.3 {Tk_PointToChar procedure: loop test} -body {
    csetup "000\n000\n000\n000"
    .t.c index text @10000,0
} -result 3
} -result {3}
test font-28.4 {Tk_PointToChar procedure: intersect line} -body {
    csetup "000\n000\n000"
    .t.c index text @0,$ay
} -result 4
} -result {4}
test font-28.5 {Tk_PointToChar procedure: to the left of all chunks} -body {
    csetup "000\n000\n000"
    .t.c index text @-100,$ay
} -result 4
} -result {4}
test font-28.6 {Tk_PointToChar procedure: past any possible chunk} -body {
    csetup "000\n000\n000"
    .t.c index text @100000,$ay
} -result 7
} -result {7}
test font-28.7 {Tk_PointToChar procedure: which chunk on this line} -body {
    csetup "000\n000\t000\t000\n000"
    .t.c index text @[expr $ax*2],$ay
} -result 6
} -result {6}
test font-28.8 {Tk_PointToChar procedure: which chunk on this line} -body {
    csetup "000\n000\t000\t000\n000"
    .t.c index text @[expr $ax*10],$ay
} -result 10
} -result {10}
test font-28.9 {Tk_PointToChar procedure: in special chunk} -body {
    csetup "000\n000\t000\t000\n000"
    .t.c index text @[expr $ax*6],$ay
} -result 7
} -result {7}
test font-28.10 {Tk_PointToChar procedure: past all chars in chunk} -body {
    csetup "000 0000000"
    .t.c itemconfig text -width [expr $ax*5]
    set x [.t.c index text @[expr $ax*5],0]
    .t.c itemconfig text -width 0
    return $x
} -result 3
} -result {3}
test font-28.11 {Tk_PointToChar procedure: below all chunks} -body {
    csetup "000 0000000"
    .t.c index text @0,1000000
} -result 11
} -result {11}
destroy .t.c


#  Label used in 29.* tests
destroy .t.f
pack [label .t.f]
update
test font-29.1 {Tk_CharBBox procedure: index < 0} -body {
    .t.f config -text "000" -underline {}
    .t.f config -text "000" -underline -1
} -result {}
test font-29.2 {Tk_CharBBox procedure: loop} -body {
    .t.f config -text "000\t000\t000\t000" -underline 9
} -result {}
test font-29.3 {Tk_CharBBox procedure: special char} -body {
    .t.f config -text "000\t000\t000" -underline 7
} -result {}
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
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







-
+





-
-
+
+


-
+





-
-
+
+


-
+





-
+



-
+





-
-
+
+


-
+





-
+




-
+






-
+




-
+





-
+



-
+





-
+



-
+





-
-
+
+


-
+





-
+



-
+









-
+






-
+



-
+





-
-
+
+







destroy .t.c
canvas .t.c -closeenough 0
.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
pack .t.c
update
test font-30.1 {Tk_DistanceToTextLayout procedure: loop once} -body {
    csetup "000\n000\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x 0 -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
} -result 0
	bind all <Enter> {}
} -result {0}
test font-30.2 {Tk_DistanceToTextLayout procedure: loop multiple} -body {
    csetup "000\n000\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x $ax -y $ay
    return $x
} -cleanup {
    bind all <Enter> {}
} -result 5
	bind all <Enter> {}
} -result {5}
test font-30.3 {Tk_DistanceToTextLayout procedure: loop to end} -body {
    csetup "000\n0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x [expr $ax*2] -y $ay
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
test font-30.4 {Tk_DistanceToTextLayout procedure: hit a special char (tab)} -body {
    csetup "000\t000\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x [expr $ax*6] -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
} -result 3
	bind all <Enter> {}
} -result {3}
test font-30.5 {Tk_DistanceToTextLayout procedure: ignore newline} -body {
    csetup "000\n0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x [expr $ax*2] -y $ay
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
test font-30.6 {Tk_DistanceToTextLayout procedure: ignore spaces at eol} -body {
    csetup "000\n000      000000000"
    .t.c itemconfig text -width [expr $ax*10]
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x [expr $ax*5] -y $ay
    .t.c itemconfig text -width 0
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
.t.c itemconfig text -justify center
test font-30.7 {Tk_DistanceToTextLayout procedure: on left side} -body {
    csetup "0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x 0 -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
test font-30.8 {Tk_DistanceToTextLayout procedure: on right side} -body {
    csetup "0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x [expr $ax*2] -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
test font-30.9 {Tk_DistanceToTextLayout procedure: inside line} -body {
    csetup "0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x $ax -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
} -result 0
	bind all <Enter> {}
} -result {0}
test font-30.10 {Tk_DistanceToTextLayout procedure: above line} -body {
    csetup "0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x 0 -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
	bind all <Enter> {}
} -result {}
test font-30.11 {Tk_DistanceToTextLayout procedure: below line} -body {
    csetup "000\n0"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x 0 -y $ay
    return $x
} -cleanup {
	bind all <Enter> {}
} -result {}
test font-30.12 {Tk_DistanceToTextLayout procedure: in line} -body {
    csetup "0\n000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x $ax -y $ay
    return $x
} -cleanup {
	bind all <Enter> {}
} -result 3
} -result {3}
.t.c itemconfig text -justify left
test font-30.13 {Tk_DistanceToTextLayout procedure: exact hit} -body {
    csetup "000"
    .t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
	.t.c bind all <Enter> {lappend x [.t.c index current @%x,%y]}
    set x {}
    event generate .t.c <Leave>
    event generate .t.c <Enter> -x $ax -y 0
    return $x
} -cleanup {
    bind all <Enter> {}
} -result 1
	bind all <Enter> {}
} -result {1}
destroy .t.c


# Canvas created for tests 31.*
destroy .t.c
canvas .t.c -closeenough 0
.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
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
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







-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
+
+
+
+
+












-
+







test font-31.6 {Tk_IntersectTextLayout procedure: ignore spaces at eol} -body {
    csetup "000\n000      000000000"
    .t.c itemconfig text -width [expr $ax*10]
    set x [.t.c find overlapping [expr $ax*5] $ay [expr $ax*5] $ay]
    .t.c itemconfig text -width 0
    return $x
} -result {}
test font-31.7 {TkIntersectAngledTextLayout procedure: bug [514ff64dd0]} -body {
    csetup "This is line one\nand line two\nand line three here"
    .t.c itemconfigure text -angle 90
    # Coordinates of the rectangle to check can be hardcoded:
    # The goal of this test is to check whether the overlap detection algorithm
    # works when the rectangle is entirely included in a chunk of the text layout.
    # The text has been rotated 90 degrees around it's upper left corner,
    # so it's enough to check with a small rectangle with small negative y coords.
    .t.c find overlapping 5 -7 7 -5
} -result 1
destroy .t.c


test font-32.1 {Tk_TextLayoutToPostscript: ensure buffer doesn't overflow} -setup {
    destroy .t.c
    canvas .t.c -closeenough 0
    .t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
    pack .t.c
    update
	destroy .t.c
	canvas .t.c -closeenough 0
	.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
	pack .t.c
	update
} -body {
    # If there were a whole bunch of returns or tabs in a row, then the
    # temporary buffer could overflow and write on the stack.
    csetup "qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm\n"
    .t.c itemconfig text -width 800
    .t.c insert text end "qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm\n"
    .t.c insert text end "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    .t.c insert text end "end"
    set x [.t.c postscript]
    set i [string first "(qwerty" $x]
    string range $x $i [expr {$i + 278}]
} -cleanup {
    destroy .t.c
	destroy .t.c
} -result {(qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm)]
[(qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm)]
[()]
[()]
[()]
[()]
[()]
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
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







-
+

-
-
-
-
+
+
+
+





-
+

-
-
-
-
+
+
+
+

-
+



-
+

-
-
-
-
+
+
+
+

-
+



-
+

-
-
-
-
+
+
+
+

-
+



-
+

-
-
-
-
+
+
+
+

-
+



-
+

-
-
-
-
+
+
+
+

-
+



-
+


-
+


-
+


-
+


-
+










-
+










-
+












-
+




-
-
+
+

-
+



-
+

-
-
+
+

-
-
+
+


-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
+



-
+

-
-
+
+

-
-
+
+


-
+

-
-
+
+

-
-
+
+







} -body {
    # (objc & 1)
    font create xyz -family
} -returnCodes error -result {value for "-family" option missing}

test font-34.3 {ConfigAttributesObj procedure: family} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -family xyz
    lappend x [font config xyz -family]
    font config xyz -family times
    lappend x [font config xyz -family]
	font create xyz -family xyz
	lappend x [font config xyz -family]
	font config xyz -family times
	lappend x [font config xyz -family]
} -cleanup {
	font delete xyz
} -result {xyz times}
test font-34.4 {ConfigAttributesObj procedure: size} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -size 20
    lappend x [font config xyz -size]
    font config xyz -size 40
    lappend x [font config xyz -size]
	font create xyz -size 20
	lappend x [font config xyz -size]
	font config xyz -size 40
	lappend x [font config xyz -size]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {20 40}
test font-34.5 {ConfigAttributesObj procedure: weight} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -weight normal
    lappend x [font config xyz -weight]
    font config xyz -weight bold
    lappend x [font config xyz -weight]
	font create xyz -weight normal
	lappend x [font config xyz -weight]
	font config xyz -weight bold
	lappend x [font config xyz -weight]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {normal bold}
test font-34.6 {ConfigAttributesObj procedure: slant} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -slant roman
    lappend x [font config xyz -slant]
    font config xyz -slant italic
    lappend x [font config xyz -slant]
	font create xyz -slant roman
	lappend x [font config xyz -slant]
	font config xyz -slant italic
	lappend x [font config xyz -slant]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {roman italic}
test font-34.7 {ConfigAttributesObj procedure: underline} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -underline 0
    lappend x [font config xyz -underline]
    font config xyz -underline 1
    lappend x [font config xyz -underline]
	font create xyz -underline 0
	lappend x [font config xyz -underline]
	font config xyz -underline 1
	lappend x [font config xyz -underline]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {0 1}
test font-34.8 {ConfigAttributesObj procedure: overstrike} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -overstrike 0
    lappend x [font config xyz -overstrike]
    font config xyz -overstrike 1
    lappend x [font config xyz -overstrike]
	font create xyz -overstrike 0
	lappend x [font config xyz -overstrike]
	font config xyz -overstrike 1
	lappend x [font config xyz -overstrike]
} -cleanup {
    font delete xyz
	font delete xyz
} -result {0 1}

test font-34.9 {ConfigAttributesObj procedure: size} -body {
    font create xyz -size xyz
	font create xyz -size xyz
} -returnCodes error -result {expected integer but got "xyz"}
test font-34.10 {ConfigAttributesObj procedure: weight} -body {
    font create xyz -weight xyz
	font create xyz -weight xyz
} -returnCodes error -result {bad -weight value "xyz": must be normal, or bold}
test font-34.11 {ConfigAttributesObj procedure: slant} -body {
    font create xyz -slant xyz
	font create xyz -slant xyz
} -returnCodes error -result {bad -slant value "xyz": must be roman, or italic}
test font-34.12 {ConfigAttributesObj procedure: underline} -body {
    font create xyz -underline xyz
	font create xyz -underline xyz
} -returnCodes error -result {expected boolean value but got "xyz"}
test font-34.13 {ConfigAttributesObj procedure: overstrike} -body {
    font create xyz -overstrike xyz
	font create xyz -overstrike xyz
} -returnCodes error -result {expected boolean value but got "xyz"}


test font-35.1 {GetAttributeInfoObj procedure: one attribute} -setup {
    catch {font delete xyz}
} -body {
    # (objPtr != NULL)
    font create xyz -family xyz
    font config xyz -family
} -cleanup {
    font delete xyz
	font delete xyz
} -result {xyz}


test font-36.1 {GetAttributeInfoObj procedure: unknown attribute} -setup {
    catch {font delete xyz}
} -body {
    # (Tcl_GetIndexFromObj() != TCL_OK)
    font create xyz
    font config xyz -xyz
} -cleanup {
    font delete xyz
	font delete xyz
} -returnCodes {
    error
} -result {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}


test font-37.1 {GetAttributeInfoObj procedure: all attributes} -setup {
    catch {font delete xyz}
} -body {
    # not (objPtr != NULL)
    font create xyz -family xyz
    font config xyz
} -cleanup {
    font delete xyz
	font delete xyz
} -result {-family xyz -size 0 -weight normal -slant roman -underline 0 -overstrike 0}
test font-37.2 {GetAttributeInfo procedure: family} -setup {
    catch {font delete xyz}
} -body {
    font create xyz -family xyz
    font config xyz -family
	font create xyz -family xyz
	font config xyz -family
} -cleanup {
    font delete xyz
	font delete xyz
} -result {xyz}
test font-37.3 {GetAttributeInfo procedure: size} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -size 20
    font config xyz -size
	font create xyz -size 20
	font config xyz -size
} -cleanup {
    font delete xyz
} -result 20
	font delete xyz
} -result {20}
test font-37.4 {GetAttributeInfo procedure: weight} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -weight normal
    font config xyz -weight
	font create xyz -weight normal
	font config xyz -weight
} -cleanup {
    font delete xyz
	font delete xyz
} -result {normal}
test font-37.5 {GetAttributeInfo procedure: slant} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -slant italic
    font config xyz -slant
	font create xyz -slant italic
	font config xyz -slant
} -cleanup {
    font delete xyz
	font delete xyz
} -result {italic}
test font-37.6 {GetAttributeInfo procedure: underline} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -underline yes
    font config xyz -underline
	font create xyz -underline yes
	font config xyz -underline
} -cleanup {
    font delete xyz
} -result 1
	font delete xyz
} -result {1}
test font-37.7 {GetAttributeInfo procedure: overstrike} -setup {
    catch {font delete xyz}
    set x {}
	set x {}
} -body {
    font create xyz -overstrike no
    font config xyz -overstrike
	font create xyz -overstrike no
	font config xyz -overstrike
} -cleanup {
    font delete xyz
} -result 0
	font delete xyz
} -result {0}


# In tests below, one field is set to "xyz" so that font name doesn't
# look like a native X font, so that ParseFontNameObj or TkParseXLFD will
# be called.

test font-38.1 {ParseFontNameObj procedure: begins with -} -body {
2261
2262
2263
2264
2265
2266
2267
2268

2269
2270
2271
2272
2273
2274
2275
2236
2237
2238
2239
2240
2241
2242

2243
2244
2245
2246
2247
2248
2249
2250







-
+







test font-38.9 {ParseFontNameObj procedure: arguments} -body {
    font actual {times 20 xyz xyz}
} -returnCodes error -result {unknown font style "xyz"}
test font-38.10 {ParseFontNameObj procedure: arguments} -body {
    font actual {times xyz xyz}
} -returnCodes error -result {expected integer but got "xyz"}
test font-38.11 {ParseFontNameObj procedure: stylelist loop} -constraints {
    unixOrWin haveTimes12BoldItalicUnderlineOverstrikeFont
	unixOrPc
} -body {
    lrange [font actual {times 12 bold italic overstrike underline}] 4 end
} -result {-weight bold -slant italic -underline 1 -overstrike 1}
test font-38.12 {ParseFontNameObj procedure: stylelist error} -body {
    font actual {times 12 bold xyz}
} -returnCodes error -result {unknown font style "xyz"}
test font-38.13 "ParseFontNameObj: options with hyphenated family: bug #2791352" -body {
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
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







-
+

-
-
-
+
+

-
-
-
-
+
+
+
+

-
+


-
-
+
+








-
+
-
-
+
-
-
-
-
+
+
-
-



-
+




-
+







    font actual -xyz-*-*-*-*-*-*-*-*-*-*-*-*-*
    font actual -xyz-?-*-*-*-*-*-*-*-*-*-*-*-*
    lindex [font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-*] 1
} -result [font actual {times 0} -family]


test font-44.1 {TkFontGetPixels: size < 0} -setup {
    set oldscale [tk scaling]
	set oldscale [tk scaling]
} -body {
    set oldsize [expr {-(-12.0 / $oldscale)}]
    tk scaling 0.5
    expr {round([font actual {times -12} -size] / $oldscale * 0.5) - round($oldsize) == 0}
	tk scaling 0.5
    font actual {times -12} -size
} -cleanup {
    tk scaling $oldscale
} -result 1
test font-44.2 {TkFontGetPoints: size >= 0} -constraints {noExceed haveTimes12Font} -setup {
    set oldscale [tk scaling]
	tk scaling $oldscale
} -result {24}
test font-44.2 {TkFontGetPoints: size >= 0} -constraints noExceed -setup {
	set oldscale [tk scaling]
} -body {
    tk scaling 0.5
	tk scaling 0.5
    font actual {times 12} -size
} -cleanup {
    tk scaling $oldscale
} -result 12
	tk scaling $oldscale
} -result {12}


test font-45.1 {TkFontGetAliasList: no match} -body {
    font actual {snarky 10} -family
} -result [font actual {-size 10} -family]
test font-45.2 {TkFontGetAliasList: match} -constraints win -body {
    font actual {times 10} -family
} -result {times}
test font-45.3 {TkFontGetAliasList: match} -constraints {noExceed failsOnUbuntu} -body {
test font-45.3 {TkFontGetAliasList: match} -constraints {unix noExceed} -body {
    if {[font actual {{times new roman} 10} -family] eq "Times New Roman"} {
        # avoid test failure on systems that have a real "times new roman" font
    # can fail on Unix systems that have a real "times new roman" font
        set res 1
    } else {
        set res [expr {[font actual {{times new roman} 10} -family] eq \
                       [font actual {times 10} -family]} ]
    font actual {{times new roman} 10} -family
} -result [font actual {times 10} -family]
    }
} -result 1


test font-46.1 {font actual, with character, no option, no --} -body {
    font actual {times 10} a
	font actual {times 10} a
} -match glob -result [list -family [font actual {times 10} -family] -size *\
		 -slant roman -underline 0 -overstrike 0]

test font-46.2 {font actual, with character introduced by --} -body {
    font actual {times 10} -- -
	font actual {times 10} -- -
} -match glob -result [list -family [font actual {times 10} -family] -size *\
		 -slant roman -underline 0 -overstrike 0]

test font-46.3 {font actual, with character and option} -body {
    font actual {times 10} -family a
} -result [font actual {times 10} -family]

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
2381
2382
2383
2384
2385
2386
2387












































































































































2388
2389
2390
2391
2392
2393
2394







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    load {} Tk two
    one eval menu .menubar
    two eval menu .menubar
    interp delete one
    interp delete two
} -result {}

test font-47.2 {Bug 3049518 - Canvas} -body {
    if {"MyFont" ni [font names]} {
	font create MyFont -family "Liberation Sans" -size 13
    }
    set text Hello!
    destroy .t.c
    set c [canvas .t.c]
    set textid [$c create text 20 20 -font MyFont -text $text -anchor nw]
    set twidth [font measure MyFont $text]
    set theight [font metrics MyFont -linespace]
    set circid [$c create polygon \
		    15                    15 \
		    [expr {15 + $twidth}] 15 \
		    [expr {15 + $twidth}] [expr {15 + $theight}] \
		    15                    [expr {15 + $theight}] \
		    -width 1 -joinstyle round -smooth true -fill {} -outline blue]
    pack $c -fill both -expand 1 -side top
    update

    # Lamda test functions
    set circle_text {{w user_data text circ} {
	if {[winfo class $w] ne "Canvas"} {
	    puts "Wrong widget type: $w"
	    return
	}
	if {$user_data ne "FontChanged"} {
	    return
	}
	lappend ::results called-$w
	lassign [$w bbox $text] x0 y0 x1 y1
	set offset 5
	set coord [lmap expr {
			      $x0-$offset $y0-$offset $x1+$offset $y0-$offset
			      $x1+$offset $y1+$offset $x0-$offset $y1+$offset
			  } {expr $expr}]
	if {[catch {$w coord $circ $coord} err]} {
	    puts Error:$err
	}
    }}
    set enclosed {{can id} {$can find enclosed {*}[$can bbox $id]}}

    set results {}
    apply $circle_text $c FontChanged $textid $circid
    update
    bind $c <<TkWorldChanged>> [list apply $circle_text %W %d $textid $circid]

    # Begin test:
    set results {}
    lappend results [apply $enclosed $c $circid]
    font configure MyFont -size 26
    update  ; # services the "TheWorldHasChanged" event, queues "TkWorldChanged" events
    update  ; # services the queued "TkWorldChanged" events
    lappend results [apply $enclosed $c $circid]
    font configure MyFont -size 9
    update idletasks
    update
    lappend results [apply $enclosed $c $circid]
    font configure MyFont -size 12
    update idletasks
    update
    lappend results [apply $enclosed $c $circid]
} -cleanup {
    destroy $c
    unset -nocomplain ::results
} -result {{1 2} called-.t.c {1 2} called-.t.c {1 2} called-.t.c {1 2}}

test font-47.3 {Bug 3049518 - Label} -body {
    if {"MyFont" ni [font names]} {
	font create MyFont -family "Liberation Sans" -size 13
    }
    set text "Label Test"
    destroy .t.l

    set make-img {{size} {
	set img [image create photo -width $size -height $size]
	$img blank
	set max [expr {$size - 1}]
	for {set x 0} {$x < $size} {incr x} {
	    $img put red -to $x $x
	    $img put black -to 0 $x
	    $img put black -to $x 0
	    $img put black -to $max $x
	    $img put black -to $x $max
	}
	return $img
    }}

    set testWorldChanged {{w user_data} {
	global make-img
	if {$user_data ne "FontChanged"} {
	    return
	}
	if {![winfo exists $w] || [winfo class $w] ne "Label"} {
	    return
	}
	if {[$w cget -image] ne ""} {
	    image delete [$w cget -image]
	}
	set size [font metrics [$w cget -font] -linespace]
	set img [apply ${make-img} $size]
	$w configure -image $img
    }}

    set check {{w} {
	global results
	set f [$w cget -font]
	set i [$w cget -image]
	set fs [font metrics $f -linespace]
	set ish [image height $i]
	set isw [image width $i]
	lappend results [list [expr {$fs == $ish ? 1 : [list $fs $ish]}] [expr {$fs == $isw ? 1 : [list $fs $isw]}]]
    }}

    set size [font metrics MyFont -linespace]
    set img [apply ${make-img} $size]
    set l [label .t.l -compound left -image $img -text $text -font MyFont]
    pack $l -side top -fill both -expand 1
    update
    bind $l <<TkWorldChanged>> [list apply $testWorldChanged %W %d]
    set ::results {}

    apply $check $l
    font configure MyFont -size 26
    update  ; # services the "TheWorldHasChanged" event, queues "TkWorldChanged" events
    update  ; # services the queued "TkWorldChanged" events
    apply $check $l
    font configure MyFont -size 9
    update idletasks
    update
    apply $check $l
    font configure MyFont -size 13
    update idletasks
    update
    apply $check $l
    set results
} -cleanup {
    destroy $l
    unset -nocomplain ::results
} -result {{1 1} {1 1} {1 1} {1 1}}

# cleanup
cleanupTests
return




Changes to tests/fontchooser.test.

1
2
3

4
5

6
7
8
9
10
11

12
13
14
15
16
17
18
1
2

3
4

5
6
7
8
9
10

11
12
13
14
15
16
17
18


-
+

-
+





-
+







# Test the "tk::fontchooser" command
#
# Copyright © 2008 Pat Thoyts
# Copyright (c) 2008 Pat Thoyts

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

# the following helper functions are related to the functions used
# in winDialog.test where they are used to send messages to the win32
# dialog (hence the weirdness).
# dialog (hence the wierdness).

proc start {cmd} {
    set ::tk_dialog {}
    set ::iter_after 0
    after 1 $cmd
}
proc then {cmd} {
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89







-
+








test fontchooser-1.7 {tk fontchooser: usage} -returnCodes error -body {
    tk fontchooser configure -parent abc
} -result {bad window path name "abc"}

test fontchooser-1.8 {tk fontchooser: usage} -returnCodes ok -body {
    tk fontchooser configure -visible
} -result 0
} -result {0}

test fontchooser-1.9 {tk fontchooser: usage} -returnCodes error -body {
    tk fontchooser configure -visible 1
} -match glob -result {*}

# -------------------------------------------------------------------------
#
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127







-
+







-
+







    }
    set x
} -result {Hello}

test fontchooser-2.1 {fontchooser -title (cyrillic)} -constraints scriptImpl -body {
    start {
        tk::fontchooser::Configure \
            -title "Привет"
            -title "\u041f\u0440\u0438\u0432\u0435\u0442"
        tk::fontchooser::Show
    }
    then {
        set x [wm title $::tk_dialog]
        Click cancel
    }
    set x
} -result "Привет"
} -result "\u041f\u0440\u0438\u0432\u0435\u0442"

test fontchooser-3.0 {fontchooser -parent} -constraints scriptImpl -body {
    start {
        tk::fontchooser::Configure -parent .
        tk::fontchooser::Show
    }
    then {
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177
178
179
180

181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179

180
181

182
183
184
185
186
187
188
189
190
191
192






193
194
195
196
197
198
199
200
201







-
+










-
+










-
+

-
+










-
-
-
-
-
-









        tk::fontchooser::Configure -command ApplyFont -font courier
        tk::fontchooser::Show
    }
    then {
        Click ok
    }
    expr {$::testfont ne {}}
} -result 1
} -result {1}

test fontchooser-4.2 {fontchooser -font} -constraints scriptImpl -body {
    start {
        tk::fontchooser::Configure -command ApplyFont -font TkDefaultFont
        tk::fontchooser::Show
    }
    then {
        Click ok
    }
    expr {$::testfont ne {}}
} -result 1
} -result {1}

test fontchooser-4.3 {fontchooser -font} -constraints scriptImpl -body {
    start {
        tk::fontchooser::Configure -command ApplyFont -font {times 14 bold}
        tk::fontchooser::Show
    }
    then {
        Click ok
    }
    expr {$::testfont ne {}}
} -result 1
} -result {1}

test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl haveTimes14BoldFont} -body {
test fontchooser-4.4 {fontchooser -font} -constraints scriptImpl -body {
    start {
        tk::fontchooser::Configure -command ApplyFont -font {times 14 bold}
        tk::fontchooser::Show
    }
    then {
        Click ok
    }
    lrange $::testfont 1 end
} -result {14 bold}

test fontchooser-5.1 {fontchooser multiple configure} -constraints {scriptImpl} -body {
    tk fontchooser configure -title TestTitle -command foo
    tk fontchooser configure -command bar
    tk fontchooser configure -title
} -result {TestTitle}

# -------------------------------------------------------------------------

cleanupTests
return

# Local Variables:
# mode: tcl
# indent-tabs-mode: nil
# End:

Changes to tests/frame.test.

1
2


3
4
5
6
7



8
9
10
11
12

13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35




36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
53


54
55

56
57
58
59
60
61
62
63
64
65
66

67
68

69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93

94
95


96
97

98
99
100
101
102
103
104
105
106
107
108
109

110
111


112
113

114
115
116
117
118
119
120
121
122
123
124
125

126
127


128
129

130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158

159
160
161
162

163
164

165
166

167
168
169
170
171
172
173
174
175
176

177
178

179
180

181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198

199
200
201

202
203
204
205
206
207

208
209
210
211
212
213
214
215
216

217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237

238
239
240
241
242
243

244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261

262
263
264

265
266
267
268
269
270

271
272
273

274
275
276
277
278
279

280
281
282

283
284
285
286
287
288
289

290
291

292
293
294
295
296
297
298
299
300
301
302
303

304
305
306

307
308

309
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326


327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344


345
346

347
348
349
350
351

352
353

354
355
356

357
358
359
360
361
362
363

364
365

366
367
368
369
370


371
372




373

374
375
376
377
378
379
380



381
382

383
384
385
386
387
388
389

390



391
392

393
394
395
396
397
398
399
400




401

402
403
404
405
406
407
408

409
410

411

412
413
414
415
416
417
418
419
420

421
422
423
424

425
426


427
428

429
430
431

432
433

434
435
436
437
438
439


440
441
442
443

444
445
446
447


448
449
450
451
452
453

454
455


456
457

458
459
460
461
462
463
464

465
466
467
468
469

470
471

472
473

474
475
476
477
478
479
480
481
482
483

484
485

486
487


488
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503

504
505
506

507
508
509
510

511
512
513
514
515
516
517

518
519
520

521
522
523
524
525
526
527
528
529
530
531

532
533
534

535
536
537
538

539
540
541
542
543
544
545

546
547
548

549
550
551
552

553
554
555

556
557
558
559

560
561
562

563
564
565
566
567

568
569

570
571
572
573

574
575
576

577
578

579

580
581

582
583

584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608
609
610

611
612
613
614











615
616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678

679
680
681




682
683
684
685
686

687
688

689
690
691
692
693
694
695
696


697
698

699
700

701
702
703
704
705
706
707
708


709
710

711
712

713
714
715
716
717
718
719
720
721
722
723


724
725

726
727

728
729
730
731
732
733
734
735
736
737
738


739
740
741
742

743
744
745
746
747
748
749
750
751
752
753

754
755

756
757
758
759
760
761
762
763


764
765

766
767

768
769
770
771
772
773
774
775
776


777
778

779
780

781
782
783
784
785
786
787
788


789
790

791
792

793
794
795
796
797
798
799
800
801
802

803
804
805

806
807

808

809
810
811
812
813
814
815
816
817

818
819
820

821
822

823

824
825
826
827
828
829
830


831
832
833

834
835

836
837
838
839
840
841
842


1
2
3
4



5
6
7
8
9
10
11

12
13
14


15


16
17
18
19
20
21
22
23
24
25
26
27
28
29




30
31
32
33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49


50
51


52











53


54
55










56

57
58
59
60
61
62
63
64
65
66
67
68

69
70

71
72
73

74
75
76
77
78
79
80
81
82
83
84
85

86
87

88
89
90

91
92
93
94
95
96
97
98
99
100
101
102

103
104

105
106
107

108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136

137
138
139
140

141
142

143
144

145
146
147
148
149
150
151
152
153
154

155

156
157
158

159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176

177
178
179

180
181
182
183
184
185

186
187
188
189
190
191
192
193
194

195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215

216
217
218
219
220
221

222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239

240
241
242

243
244
245
246
247
248

249
250
251

252
253
254
255
256
257

258
259
260

261
262
263
264
265
266
267

268
269

270
271
272
273
274
275
276
277
278
279
280
281

282
283
284

285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305

306
307
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324

325
326
327

328
329
330
331
332

333
334

335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356


357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394


395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427

428
429
430

431
432
433

434
435

436






437
438
439
440
441

442
443
444


445
446
447
448
449
450
451

452
453

454
455
456

457
458
459
460
461
462
463

464
465
466
467
468

469
470

471
472

473
474
475
476
477
478
479
480
481
482

483

484
485
486

487
488
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503

504
505
506

507
508
509
510

511
512
513
514
515
516
517

518
519
520

521
522
523
524
525
526
527
528
529
530
531

532
533
534

535
536
537
538

539
540
541
542
543
544
545

546
547
548

549
550
551
552

553
554
555

556
557
558
559

560
561
562

563
564
565
566
567

568
569

570
571
572
573

574
575
576

577
578
579
580

581
582

583
584

585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679

680
681
682

683
684
685
686
687
688
689
690



691
692
693
694
695
696
697
698

699
700

701
702
703
704
705
706
707


708
709
710

711
712

713
714
715
716
717
718
719


720
721
722

723
724

725
726
727
728
729
730
731
732
733
734


735
736
737

738
739

740
741
742
743
744
745
746
747
748
749


750
751
752
753
754

755
756
757
758
759
760
761
762
763
764
765

766
767

768
769
770
771
772
773
774


775
776
777

778
779

780
781
782
783
784
785
786
787


788
789
790

791
792

793
794
795
796
797
798
799


800
801
802

803
804

805
806
807
808
809
810
811
812
813
814

815
816
817

818
819

820
821
822
823
824
825
826
827
828
829
830

831
832
833

834
835

836
837
838
839
840
841
842
843


844
845
846
847
848
849
850

851
852
853
854
855
856
857
858
-
-
+
+


-
-
-
+
+
+




-
+


-
-

-
-
+
+












-
-
-
-
+
+
+
+







-
-
+
+







-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+

-
-
-
-
-
-
-
-
-
-

-
+











-
+

-
+
+

-
+











-
+

-
+
+

-
+











-
+

-
+
+

-
+






-
+














-
+






-
+



-
+

-
+

-
+









-
+
-

+

-
+








-
+








-
+


-
+





-
+








-
+


-
+














-
+


-
+





-
+








-
+








-
+


-
+





-
+


-
+





-
+


-
+






-
+

-
+











-
+


-
+


+

-
+













-
+

-
+
+

-
+













-
+

-
+
+

-
+




-
+

-
+



+







+

-
+





+
+
-
-
+
+
+
+

+






-
+
+
+


+







+
-
+
+
+


+






-
-
+
+
+
+

+







+

-
+

+









+



-
+

-
+
+

-
+


-
+

-
+
-
-
-
-
-
-
+
+



-
+


-
-
+
+





-
+

-
+
+

-
+






-
+




-
+

-
+

-
+









-
+
-

+

-
+
+








-
+






-
+


-
+



-
+






-
+


-
+










-
+


-
+



-
+






-
+


-
+



-
+


-
+



-
+


-
+




-
+

-
+



-
+


-
+


+
-
+

-
+

-
+







-
+








-
+










+



-
+
+
+
+
+
+
+
+
+
+
+









-
+










-
+












-
+


















-



-







+
-
-
-
+
+
+
+




-
+

-
+






-
-
+
+

-
+

-
+






-
-
+
+

-
+

-
+









-
-
+
+

-
+

-
+









-
-
+
+



-
+










-
+

-
+






-
-
+
+

-
+

-
+







-
-
+
+

-
+

-
+






-
-
+
+

-
+

-
+









-
+


-
+

-
+

+








-
+


-
+

-
+

+





-
-
+
+



+

-
+







# This file is a Tcl script to test out the "frame", "labelframe" and
# "toplevel" commands of Tk.  It is organized in the standard fashion for Tcl
# This file is a Tcl script to test out the "frame" and "toplevel"
# commands of Tk.  It is organized in the standard fashion for Tcl
# tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
eval tcltest::configure $argv
tcltest::loadTestedCommands

tcltest::testConstraint x11 [expr {[tk windowingsystem] eq "x11"}]

# eatColors --
# Creates a toplevel window and allocates enough colors in it to use up all
# the slots in an 8-bit colormap.
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -		Name of toplevel window to create.

proc eatColors {w} {
    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
	for {set x 0} {$x < 40} {incr x} {
	    set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
	    $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
		[expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
		-fill $color
	    set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
	    $w.c create rectangle [expr 10*$x] [expr 20*$y] \
		    [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
		    -fill $color
	}
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window, 0
# otherwise.
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -			Name of window in which to check.
# red, green, blue -	Intensities to use in a trial color allocation
#			to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    lassign [winfo rgb $w [format "#%02x%02x%02x" $red $green $blue]] r g b
    expr {($r/256 == $red) && ($g/256 == $green) && ($b/256 == $blue)}
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
}

	    && ([lindex $vals 2]/256 == $blue)
# uniq --
#
# Returns the unique items of a list in the order they first appear.
#
# Arguments:
# list -		The list to uniq-ify.
proc uniq {list} {
    set d {}
    foreach item $list {
	dict set d $item {}
    }
}
    return [dict keys $d]
}


# optnames --
#
# Returns the option names out of a list of option details.
#
# Arguments:
# options -		The option detail list.
proc optnames {options} {
    lsort [lmap desc $options {lindex $desc 0}]
}

test frame-1.1 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -class NewFrame
    .f configure -class
} -cleanup {
    deleteWindows
} -result {-class class Class Frame NewFrame}
test frame-1.2 {frame configuration options} -setup {
    deleteWindows
} -body {
    frame .f -class NewFrame
    .f configure -class Different
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -class option after widget is created}
} -returnCodes error -result {can't modify -class option after widget is created}

test frame-1.3 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -colormap new
    .f configure -colormap
} -cleanup {
    deleteWindows
} -result {-colormap colormap Colormap {} new}
test frame-1.4 {frame configuration options} -setup {
    deleteWindows
} -body {
    frame .f -colormap new
    .f configure -colormap .
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -colormap option after widget is created}
} -returnCodes error -result {can't modify -colormap option after widget is created}

test frame-1.5 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -visual default
    .f configure -visual
} -cleanup {
    deleteWindows
} -result {-visual visual Visual {} default}
test frame-1.6 {frame configuration options} -setup {
    deleteWindows
} -body {
    frame .f -visual default
    .f configure -visual best
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -visual option after widget is created}
} -returnCodes error -result {can't modify -visual option after widget is created}

test frame-1.7 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -screen bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown option "-screen"}
test frame-1.8 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -container true
} -cleanup {
    deleteWindows
} -result {.f}
test frame-1.9 {frame configuration options} -setup {
    deleteWindows
} -body {
    frame .f -container true
    .f configure -container
} -cleanup {
    deleteWindows
} -result {-container container Container 0 1}
test frame-1.10 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -container bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {expected boolean value but got "bogus"}
test frame-1.11 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f
    .f configure -container 1
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -container option after widget is created}
} -returnCodes error -result {can't modify -container option after widget is created}
test frame-1.12 {frame configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Make sure all options can be set to the default value
    frame .f
    set opts {}
    foreach opt [.f configure] {
        if {[llength $opt] == 5} {
            lappend opts [lindex $opt 0] [lindex $opt 4]
        }
    }
    frame .g {*}$opts
    eval frame .g $opts
} -cleanup {
    destroy .f .g
} -cleanup {
    deleteWindows
} -result .g
} -result {}

destroy .f
frame .f
test frame-1.13 {frame configuration options} -body {
    .f configure -background #ff0000
    lindex [.f configure -background] 4
} -cleanup {
    .f configure -background [lindex [.f configure -background] 3]
} -result "#ff0000"
} -result {#ff0000}
test frame-1.14 {frame configuration options} -body {
    .f configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-1.15 {frame configuration options} -body {
    .f configure -bd 4
    lindex [.f configure -bd] 4
} -cleanup {
    .f configure -bd [lindex [.f configure -bd] 3]
} -result 4
} -result {4}
test frame-1.16 {frame configuration options} -body {
    .f configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-1.17 {frame configuration options} -body {
    .f configure -bg #00ff00
    lindex [.f configure -bg] 4
} -cleanup {
    .f configure -bg [lindex [.f configure -bg] 3]
} -result "#00ff00"
} -result {#00ff00}
test frame-1.18 {frame configuration options} -body {
    .f configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-1.19 {frame configuration options} -body {
    .f configure -borderwidth 1.3
    lindex [.f configure -borderwidth] 4
} -cleanup {
    .f configure -borderwidth [lindex [.f configure -borderwidth] 3]
} -result 1
} -result {1}
test frame-1.20 {frame configuration options} -body {
    .f configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-1.21 {frame configuration options} -body {
    .f configure -cursor arrow
    lindex [.f configure -cursor] 4
} -cleanup {
    .f configure -cursor [lindex [.f configure -cursor] 3]
} -result {arrow}
test frame-1.22 {frame configuration options} -body {
    .f configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test frame-1.23 {frame configuration options} -body {
    .f configure -height 100
    lindex [.f configure -height] 4
} -cleanup {
    .f configure -height [lindex [.f configure -height] 3]
} -result 100
} -result {100}
test frame-1.24 {frame configuration options} -body {
    .f configure -height not_a_number
} -returnCodes error -result {expected screen distance but got "not_a_number"}
} -returnCodes error -result {bad screen distance "not_a_number"}
test frame-1.25 {frame configuration options} -body {
    .f configure -highlightbackground #112233
    lindex [.f configure -highlightbackground] 4
} -cleanup {
    .f configure -highlightbackground [lindex [.f configure -highlightbackground] 3]
} -result "#112233"
} -result {#112233}
test frame-1.26 {frame configuration options} -body {
    .f configure -highlightbackground ugly
} -returnCodes error -result {unknown color name "ugly"}
test frame-1.27 {frame configuration options} -body {
    .f configure -highlightcolor #123456
    lindex [.f configure -highlightcolor] 4
} -cleanup {
    .f configure -highlightcolor [lindex [.f configure -highlightcolor] 3]
} -result "#123456"
} -result {#123456}
test frame-1.28 {frame configuration options} -body {
    .f configure -highlightcolor non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-1.29 {frame configuration options} -body {
    .f configure -highlightthickness 6
    lindex [.f configure -highlightthickness] 4
} -cleanup {
    .f configure -highlightthickness [lindex [.f configure -highlightthickness] 3]
} -result 6
} -result {6}
test frame-1.30 {frame configuration options} -body {
    .f configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-1.31 {frame configuration options} -body {
    .f configure -padx 3
    lindex [.f configure -padx] 4
} -cleanup {
    .f configure -padx [lindex [.f configure -padx] 3]
} -result 3
} -result {3}
test frame-1.32 {frame configuration options} -body {
    .f configure -padx badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-1.33 {frame configuration options} -body {
    .f configure -pady 4
    lindex [.f configure -pady] 4
} -cleanup {
    .f configure -pady [lindex [.f configure -pady] 3]
} -result 4
} -result {4}
test frame-1.34 {frame configuration options} -body {
    .f configure -pady badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-1.35 {frame configuration options} -body {
    .f configure -relief ridge
    lindex [.f configure -relief] 4
} -cleanup {
    .f configure -relief [lindex [.f configure -relief] 3]
} -result {ridge}
test frame-1.36 {frame configuration options} -returnCodes error -body {
test frame-1.36 {frame configuration options} -body {
    .f configure -relief badValue
} -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test frame-1.37 {frame configuration options} -body {
    .f configure -takefocus {any string}
    lindex [.f configure -takefocus] 4
} -cleanup {
    .f configure -takefocus [lindex [.f configure -takefocus] 3]
} -result {any string}
test frame-1.38 {frame configuration options} -body {
    .f configure -width 32
    lindex [.f configure -width] 4
} -cleanup {
    .f configure -width [lindex [.f configure -width] 3]
} -result 32
} -result {32}
test frame-1.39 {frame configuration options} -body {
    .f configure -width badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
destroy .f


test frame-2.1 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -class NewClass
    wm geometry .t +0+0
    .t configure -class
} -cleanup {
    deleteWindows
} -result {-class class Class Toplevel NewClass}
test frame-2.2 {toplevel configuration options} -setup {
    deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -class NewClass
    wm geometry .t +0+0
    .t configure -class Another
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -class option after widget is created}
} -returnCodes error -result {can't modify -class option after widget is created}

test frame-2.3 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -colormap new
    wm geometry .t +0+0
    .t configure -colormap
} -cleanup {
    deleteWindows
} -result {-colormap colormap Colormap {} new}
test frame-2.4 {toplevel configuration options} -setup {
    deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -colormap new
    wm geometry .t +0+0
    .t configure -colormap .
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -colormap option after widget is created}
} -returnCodes error -result {can't modify -colormap option after widget is created}

test frame-2.5 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    .t configure -container 1
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -container option after widget is created}
} -returnCodes error -result {can't modify -container option after widget is created}
test frame-2.6 {toplevel configuration options} -setup {
    deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    catch {.t configure -container 1}
    .t configure -container
} -cleanup {
    deleteWindows
} -result {-container container Container 0 0}

test frame-2.7 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -colormap bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {bad window path name "bogus"}


test frame-2.8 {toplevel configuration options} -constraints win -setup {
    deleteWindows
test frame-2.8 {toplevel configuration options} -constraints {
    win
} -setup {
	deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    .t configure -use 0x44022
} -cleanup {
    deleteWindows
} -returnCodes error -result {window "0x44022" doesn't exist}
test frame-2.9 {toplevel configuration options} -constraints win -setup {
test frame-2.9 {toplevel configuration options} -constraints {
    win
} -setup {
    deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    catch {.t configure -use 0x44022}
    .t configure -use
} -cleanup {
    deleteWindows
} -result {-use use Use {} {}}

test frame-2.10 {toplevel configuration options} -constraints nonwin -setup {
test frame-2.10 {toplevel configuration options} -constraints {
    nonwin
} -setup {
    deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    .t configure -use 0x44022
} -cleanup {
    deleteWindows
} -returnCodes error -result {can't modify -use option after widget is created}
test frame-2.11 {toplevel configuration options} -constraints nonwin -setup {
    deleteWindows
test frame-2.11 {toplevel configuration options} -constraints {
    nonwin
} -setup {
	deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100
    wm geometry .t +0+0
    catch {.t configure -use 0x44022}
    .t configure -use
} -cleanup {
    deleteWindows
} -result {-use use Use {} {}}

test frame-2.12 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100 -visual default
    wm geometry .t +0+0
    .t configure -visual
} -cleanup {
    deleteWindows
} -result {-visual visual Visual {} default}
test frame-2.13 {toplevel configuration options} -setup {
    deleteWindows
} -body {
    catch {destroy .t}
    toplevel .t -width 200 -height 100 -visual default
    wm geometry .t +0+0
    .t configure -visual best
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -visual option after widget is created}
} -returnCodes error -result {can't modify -visual option after widget is created}

test frame-2.14 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -visual who_knows?
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {unknown or ambiguous visual name "who_knows?": class must be best, directcolor, grayscale, greyscale, pseudocolor, staticcolor, staticgray, staticgrey, truecolor, or default}
} -returnCodes error -result {unknown or ambiguous visual name "who_knows?": class must be best, directcolor, grayscale, greyscale, pseudocolor, staticcolor, staticgray, staticgrey, truecolor, or default}
set expectedScreen ""
if {[tcltest::testConstraint haveDISPLAY]} {
    set expectedScreen [list -screen screen Screen {} $env(DISPLAY)]
}
test frame-2.15 {toplevel configuration options} -constraints {x11 haveDISPLAY} -setup {
    deleteWindows
test frame-2.15 {toplevel configuration options} -constraints haveDISPLAY -setup {
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -screen $env(DISPLAY)
    wm geometry .t +0+0
    .t configure -screen
    string compare [.t configure -screen] "-screen screen Screen {} $env(DISPLAY)"
} -cleanup {
    deleteWindows
} -result $expectedScreen
test frame-2.16 {toplevel configuration options} -constraints {x11 haveDISPLAY} -setup {
} -result {0}
test frame-2.16 {toplevel configuration options} -constraints haveDISPLAY -setup {
    deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -screen $env(DISPLAY)
    wm geometry .t +0+0
    .t configure -screen another
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -screen option after widget is created}
} -returnCodes error -result {can't modify -screen option after widget is created}

test frame-2.17 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 200 -height 100 -screen bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {couldn't connect to display "bogus"}
test frame-2.18 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    toplevel .x -container 1 -use [winfo id .t]
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {windows cannot have both the -use and the -container option set}
} -returnCodes error -result {windows cannot have both the -use and the -container option set}
test frame-2.19 {toplevel configuration options} -setup {
    deleteWindows
	deleteWindows
    set opts {}
} -body {
    # Make sure all options can be set to the default value
    toplevel .f
    foreach opt [.f configure] {
        if {[llength $opt] == 5} {
            lappend opts [lindex $opt 0] [lindex $opt 4]
        }
    }
    toplevel .g {*}$opts
    eval toplevel .g $opts
} -cleanup {
    destroy .f .g
} -cleanup {
    deleteWindows
} -result .g
} -result {}


destroy .t
toplevel .t -width 300 -height 150
wm geometry .t +0+0
update
test frame-2.20 {toplevel configuration options} -body {
    .t configure -background #ff0000
    lindex [.t configure -background] 4
} -result "#ff0000"
} -result {#ff0000}
test frame-2.21 {toplevel configuration options} -body {
    .t configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-2.22 {toplevel configuration options} -body {
    .t configure -bd 4
    lindex [.t configure -bd] 4
} -result 4
} -result {4}
test frame-2.23 {toplevel configuration options} -body {
    .t configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-2.24 {toplevel configuration options} -body {
    .t configure -bg #00ff00
    lindex [.t configure -bg] 4
} -result "#00ff00"
} -result {#00ff00}
test frame-2.25 {toplevel configuration options} -body {
    .t configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-2.26 {toplevel configuration options} -body {
    .t configure -borderwidth 1.3
    lindex [.t configure -borderwidth] 4
} -result 1
} -result {1}
test frame-2.27 {toplevel configuration options} -body {
    .t configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-2.28 {toplevel configuration options} -body {
    .t configure -cursor arrow
    lindex [.t configure -cursor] 4
} -result {arrow}
test frame-2.29 {toplevel configuration options} -body {
    .t configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test frame-2.30 {toplevel configuration options} -body {
    .t configure -height 100
    lindex [.t configure -height] 4
} -result 100
} -result {100}
test frame-2.31 {toplevel configuration options} -body {
    .t configure -height not_a_number
} -returnCodes error -result {expected screen distance but got "not_a_number"}
} -returnCodes error -result {bad screen distance "not_a_number"}
test frame-2.32 {toplevel configuration options} -body {
    .t configure -highlightcolor #123456
    lindex [.t configure -highlightcolor] 4
} -result "#123456"
} -result {#123456}
test frame-2.33 {toplevel configuration options} -body {
    .t configure -highlightcolor non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-2.34 {toplevel configuration options} -body {
    .t configure -highlightthickness 3
    lindex [.t configure -highlightthickness] 4
} -result 3
} -result {3}
test frame-2.35 {toplevel configuration options} -body {
    .t configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-2.36 {toplevel configuration options} -body {
    .t configure -padx 3
    lindex [.t configure -padx] 4
} -result 3
} -result {3}
test frame-2.37 {toplevel configuration options} -body {
    .t configure -padx badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-2.38 {toplevel configuration options} -body {
    .t configure -pady 4
    lindex [.t configure -pady] 4
} -result 4
} -result {4}
test frame-2.39 {toplevel configuration options} -body {
    .t configure -pady badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test frame-2.40 {toplevel configuration options} -body {
    .t configure -relief ridge
    lindex [.t configure -relief] 4
} -result {ridge}
test frame-2.41 {toplevel configuration options} -returnCodes error -body {
test frame-2.41 {toplevel configuration options} -body {
    .t configure -relief badValue
} -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test frame-2.42 {toplevel configuration options} -body {
    .t configure -width 32
    lindex [.t configure -width] 4
} -result 32
} -result {32}
test frame-2.43 {toplevel configuration options} -body {
    .t configure -width badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
destroy .t


test frame-3.1 {TkCreateFrame procedure} -returnCodes error -body {
test frame-3.1 {TkCreateFrame procedure} -body {
    frame
} -result {wrong # args: should be "frame pathName ?-option value ...?"}
} -returnCodes error -result {wrong # args: should be "frame pathName ?-option value ...?"}
test frame-3.2 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
    frame .f
} -body {
    .f configure -class
} -cleanup {
    deleteWindows
} -result {-class class Class Frame Frame}
test frame-3.3 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
    toplevel .t
    wm geometry .t +0+0
} -body {
    .t configure -class
} -cleanup {
    deleteWindows
} -result {-class class Class Toplevel Toplevel}
test frame-3.4 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 350 -class NewClass -bg black -visual default -height 90
    wm geometry .t +0+0
    update
    list [lindex [.t configure -width] 4] \
	    [lindex [.t configure -background] 4] \
	    [lindex [.t configure -height] 4]
} -cleanup {
    deleteWindows
} -result {350 black 90}

# Be sure that the -class, -colormap, and -visual options are processed
# before configuring the widget.
test frame-3.5 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    option add *NewFrame.background #123456
    frame .f -class NewFrame
    lindex [.f configure -background] 4
} -cleanup {
    deleteWindows
    option clear
} -result {#123456}
test frame-3.6 {TkCreateFrame procedure} -setup {
	deleteWindows
} -body {
    option add *NewFrame.background #123456
    frame .f -class NewFrame
    lindex [.f configure -background] 4
} -cleanup {
    deleteWindows
    option clear
} -result {#123456}
test frame-3.7 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    option add *NewFrame.background #332211
    option add *f.class NewFrame
    frame .f
    list [lindex [.f configure -class] 4] [lindex [.f configure -background] 4]
} -cleanup {
    deleteWindows
    option clear
} -result {NewFrame #332211}
test frame-3.8 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    option add *Silly.background #122334
    option add *f.Class Silly
    frame .f
    list [lindex [.f configure -class] 4] [lindex [.f configure -background] 4]
} -cleanup {
    deleteWindows
    option clear
} -result {Silly #122334}
test frame-3.9 {TkCreateFrame procedure, -use option} -constraints {
    unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    toplevel .x -width 140 -height 300 -use [winfo id .t] -bg green
    tkwait visibility .x
    list [expr {[winfo rootx .x] - [winfo rootx .t]}] \
	    [expr {[winfo rooty .x] - [winfo rooty .t]}] \
	    [winfo width .t] [winfo height .t]
} -cleanup {
    deleteWindows
} -result {0 0 140 300}
test frame-3.10 {TkCreateFrame procedure, -use option} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    update
    option add *x.use [winfo id .t]
    toplevel .x -width 140 -height 300 -bg green
    tkwait visibility .x
    update
    list [expr {[winfo rootx .x] - [winfo rootx .t]}] \
	    [expr {[winfo rooty .x] - [winfo rooty .t]}] \
	    [winfo width .t] [winfo height .t]
} -cleanup {
    destroy .t
    option clear
} -result {0 0 140 300}

# The tests below require specific display characteristics (i.e. that they are
# run on a pseudocolor display of depth 8).  Even so, they are non-portable:
# some machines don't seem to ever run out of colors.
# The tests below require specific display characteristics (i.e. that
# they are run on a pseudocolor display of depth 8).  Even so, they
# are non-portable: some machines don't seem to ever run out of
# colors.
if {[testConstraint defaultPseudocolor8]} {
    eatColors .t1
}
test frame-3.11 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    toplevel .t -width 300 -height 200 -bg #475601
    wm geometry .t +0+0
    update
    colorsFree .t
} -cleanup {
    destroy .t
} -result 0
    deleteWindows
} -result {0}
test frame-3.12 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    toplevel .t -width 300 -height 200 -bg #475601 -colormap new
    wm geometry .t +0+0
    update
    colorsFree .t
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
test frame-3.13 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    option add *t.class Toplevel2
    option add *Toplevel2.colormap new
    toplevel .t -width 300 -height 200 -bg #475601
    wm geometry .t +0+0
    update
    option clear
    colorsFree .t
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
test frame-3.14 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    option add *t.class Toplevel3
    option add *Toplevel3.Colormap new
    toplevel .t -width 300 -height 200 -bg #475601 -colormap new
    wm geometry .t +0+0
    update
    option clear
    colorsFree .t
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
test frame-3.15 {TkCreateFrame procedure, -use and -colormap} -constraints {
    defaultPseudocolor8 unix nonPortable
} -setup {
    destroy .t
    deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    toplevel .x -width 140 -height 300 -use [winfo id .t] -bg green -colormap new
    tkwait visibility .x
    list [colorsFree .t] [colorsFree .x]
} -cleanup {
    destroy .t
} -result {0 1}
test frame-3.16 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    toplevel .t -width 300 -height 200 -bg #475601 -visual default
    wm geometry .t +0+0
    update
    colorsFree .t
} -cleanup {
    destroy .t
} -result 0
    deleteWindows
} -result {0}
test frame-3.17 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 nonPortable
	defaultPseudocolor8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    toplevel .t -width 300 -height 200 -bg #475601 -visual default \
	    -colormap new
    wm geometry .t +0+0
    update
    colorsFree .t
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
test frame-3.18 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 haveGrayscale8 nonPortable
	defaultPseudocolor8 haveGrayscale8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    toplevel .t -visual {grayscale 8} -width 300 -height 200 -bg #434343
    wm geometry .t +0+0
    update
    colorsFree .t 131 131 131
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
test frame-3.19 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 haveGrayscale8 nonPortable
	defaultPseudocolor8 haveGrayscale8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    option add *t.class T4
    option add *T4.visual {grayscale 8}
    toplevel .t -width 300 -height 200 -bg #434343
    wm geometry .t +0+0
    update
    option clear
    list [colorsFree .t 131 131 131] [lindex [.t configure -visual] 4]
} -cleanup {
    destroy .t
    deleteWindows
} -result {1 {grayscale 8}}
test frame-3.20 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 haveGrayscale8 nonPortable
	defaultPseudocolor8 haveGrayscale8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    set x ok
    option add *t.class T5
    option add *T5.Visual {grayscale 8}
    toplevel .t -width 300 -height 200 -bg #434343
    wm geometry .t +0+0
    update
    option clear
    list [colorsFree .t 131 131 131] [lindex [.t configure -visual] 4]
} -cleanup {
    destroy .t
    deleteWindows
} -result {1 {grayscale 8}}
test frame-3.21 {TkCreateFrame procedure} -constraints {
    defaultPseudocolor8 haveGrayscale8 nonPortable
	defaultPseudocolor8 haveGrayscale8 nonPortable
} -setup {
    destroy .t
	deleteWindows
} -body {
    set x ok
    toplevel .t -visual {grayscale 8} -width 300 -height 200 -bg #434343
    wm geometry .t +0+0
    update
    colorsFree .t 131 131 131
} -cleanup {
    destroy .t
} -result 1
    deleteWindows
} -result {1}
if {[testConstraint defaultPseudocolor8]} {
    destroy .t1
}

test frame-3.22 {TkCreateFrame procedure, default dimensions} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t
    wm geometry .t +0+0
    update
    set result "[winfo reqwidth .t] [winfo reqheight .t]"
    frame .t.f -bg red
    pack .t.f
852
853
854
855
856
857
858
859

860
861

862
863
864
865
866
867

868
869
870
871
872

873
874
875
876
877
878
879
868
869
870
871
872
873
874
875
876
877

878
879
880
881
882
883

884
885
886
887
888
889
890
891
892
893
894
895
896
897








+

-
+





-
+





+







} -returnCodes error -result {unknown option "-gorp"}
test frame-3.24 {TkCreateFrame procedure} -setup {
    deleteWindows
} -body {
    toplevel .t -width 300 -height 200 -colormap new -bogus option
    wm geometry .t +0+0
} -returnCodes error -result {unknown option "-bogus"}


test frame-4.1 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    catch {frame .f -gorp glob}
    winfo exists .f
} -result 0
test frame-4.2 {TkCreateFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    list [frame .f -width 200 -height 100] [winfo exists .f]
} -cleanup {
    deleteWindows
} -result {.f 1}


frame .f -highlightcolor black
test frame-5.1 {FrameWidgetCommand procedure} -body {
    .f
} -returnCodes error -result {wrong # args: should be ".f option ?arg ...?"}
test frame-5.2 {FrameWidgetCommand procedure, cget option} -body {
    .f cget
894
895
896
897
898
899
900

901
902
903


904
905
906
907
908
909
910
911
912
913
914
915
916
917
918


919
920
921
922

923
924
925
926
927
928
929
930

931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946
947
948
949
950
951
952

953
954
955
956
957
958
959
960

961
962
963
964
965
966
967
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996
997

998
999
1000
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012

1013
1014
1015
1016
1017

1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030

1031
1032

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046

1047

1048
1049

1050

1051
1052
1053
1054
1055




1056

1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095

1096
1097
1098
1099
1100
1101
1102




1103
1104

1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121



1122
1123
1124
1125
1126
1127
1128
1129

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141

1142
1143
1144
1145
1146
1147
1148

1149

1150
1151

1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165

1166
1167

1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206
1207
1208
1209
1210

1211
1212
1213
1214

1215
1216


1217
1218
1219
1220
1221
1222
1223
1224

1225
1226

1227
1228
1229
1230
1231
1232
1233

1234
1235
1236


1237
1238
1239
1240
1241
1242

1243
1244

1245
1246
1247
1248
1249
1250
1251

1252
1253
1254


1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268
1269

1270
1271

1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286

1287
1288
1289
1290
1291
1292
1293

1294
1295
1296


1297
1298
1299
1300
1301
1302

1303
1304

1305
1306
1307
1308
1309
1310
1311

1312
1313

1314
1315
1316
1317
1318
1319
1320

1321
1322
1323


1324
1325
1326
1327
1328
1329
1330
1331
1332



1333
1334
1335
1336
1337
1338

1339
1340
1341


1342
1343
1344
1345
1346
1347

1348
1349
1350


1351
1352
1353
1354
1355
1356
1357
1358
1359



1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377

1378
1379
1380


1381
1382

1383
1384

1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399

1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418

1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437

1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
912
913
914
915
916
917
918
919
920


921
922
923
924
925
926
927
928
929
930
931
932
933
934
935


936
937
938
939
940

941
942
943
944
945
946
947
948

949
950
951
952
953
954
955
956

957
958
959
960
961
962
963
964
965
966
967
968
969
970

971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
986
987
988
989
990
991
992

993
994
995
996
997
998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050

1051
1052

1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066

1067
1068
1069
1070

1071
1072
1073
1074
1075
1076


1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

1095

1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126
1127


1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148



1149
1150
1151

1152
1153
1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168


1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179

1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193

1194
1195

1196
1197
1198
1199
1200
1201
1202

1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242

1243
1244

1245
1246
1247
1248
1249
1250
1251
1252
1253

1254
1255

1256
1257
1258
1259
1260
1261
1262

1263
1264


1265
1266
1267
1268
1269
1270
1271

1272
1273

1274
1275
1276
1277
1278
1279
1280

1281
1282


1283
1284
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298

1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313

1314
1315

1316
1317
1318
1319
1320
1321
1322

1323
1324


1325
1326
1327
1328
1329
1330
1331

1332
1333

1334
1335
1336
1337
1338
1339
1340

1341
1342

1343
1344
1345
1346
1347
1348
1349

1350
1351


1352
1353
1354
1355
1356
1357
1358
1359



1360
1361
1362
1363
1364
1365
1366
1367

1368
1369


1370
1371
1372
1373
1374
1375
1376

1377
1378


1379
1380
1381
1382
1383
1384
1385
1386



1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406

1407
1408


1409
1410
1411
1412
1413
1414

1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481

1482
1483
1484
1485
1486
1487
1488
1489







+

-
-
+
+













-
-
+
+



-
+







-
+







-
+













-
+







-
+













-
+








-
+














+










+




-
+




-
+





-
+






-
+

-
+









-
+



-
+

+

-
+

+



-
-
+
+
+
+

+

-
+










-
+
-

+










+

-
+











-
+





-
-
+
+
+
+


+














-
-
-
+
+
+
-






-
+










-
-
+






-
+

+

-
+











-
+

-
+

-
+






-
+






-
+






-
+














-
+






-
+



-
+

-
+
+







-
+

-
+






-
+

-
-
+
+





-
+

-
+






-
+

-
-
+
+







-
+






-
+

-
+












-
+

-
+






-
+

-
-
+
+





-
+

-
+






-
+

-
+






-
+

-
-
+
+






-
-
-
+
+
+





-
+

-
-
+
+





-
+

-
-
+
+






-
-
-
+
+
+

















-
+

-
-
+
+


+

-
+














-
+


















-
+


















-
+













-
+







    destroy .t
} -body {
    toplevel .t
    .t cget -screen
} -cleanup {
    destroy .t
} -returnCodes ok -match glob -result *

test frame-5.8 {FrameWidgetCommand procedure, configure option} -body {
    optnames [.f configure]
} -result {-background -backgroundimage -bd -bg -bgimg -borderwidth -class -colormap -container -cursor -height -highlightbackground -highlightcolor -highlightthickness -padx -pady -relief -takefocus -tile -visual -width}
    llength [.f configure]
} -result {18}
test frame-5.9 {FrameWidgetCommand procedure, configure option} -body {
    .f configure -gorp
} -returnCodes error -result {unknown option "-gorp"}
test frame-5.10 {FrameWidgetCommand procedure, configure option} -body {
    .f configure -gorp bogus
} -returnCodes error -result {unknown option "-gorp"}
test frame-5.11 {FrameWidgetCommand procedure, configure option} -body {
    .f configure -width 200 -height
} -returnCodes error -result {value for "-height" missing}
test frame-5.12 {FrameWidgetCommand procedure} -body {
    .f swizzle
} -returnCodes error -result {bad option "swizzle": must be cget or configure}
test frame-5.13 {FrameWidgetCommand procedure, configure option} -body {
    optnames [. configure]
} -result {-background -backgroundimage -bd -bg -bgimg -borderwidth -class -colormap -container -cursor -height -highlightbackground -highlightcolor -highlightthickness -menu -padx -pady -relief -screen -takefocus -tile -use -visual -width}
    llength [. configure]
} -result {21}
destroy .f

test frame-6.1 {ConfigureFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -width 150
    list [winfo reqwidth .f] [winfo reqheight .f]
} -cleanup {
    deleteWindows
} -result {150 1}
test frame-6.2 {ConfigureFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f -height 97
    list [winfo reqwidth .f] [winfo reqheight .f]
} -cleanup {
    deleteWindows
} -result {1 97}
test frame-6.3 {ConfigureFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f
    set result {}
    lappend result [winfo reqwidth .f] [winfo reqheight .f]
    .f configure -width 100 -height 180
    lappend result [winfo reqwidth .f] [winfo reqheight .f]
    .f configure -width 0 -height 0
    lappend result [winfo reqwidth .f] [winfo reqheight .f]
} -cleanup {
    deleteWindows
} -result {1 1 100 180 100 180}

test frame-7.1 {FrameEventProc procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .frame2
    set result [info commands .frame2]
    destroy .frame2
    lappend result [info commands .frame2]
} -result {.frame2 {}}
test frame-7.2 {FrameEventProc procedure} -setup {
    deleteWindows
	deleteWindows
    set x {}
} -body {
    frame .f1 -bg #543210
    rename .f1 .f2
    lappend x [winfo children .]
    lappend x [.f2 cget -bg]
    destroy .f1
    lappend x [info command .f*] [winfo children .]
} -cleanup {
    deleteWindows
} -result {.f1 #543210 {} {}}

test frame-8.1 {FrameCmdDeletedProc procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1
    rename .f1 {}
    list [info command .f*] [winfo children .]
} -cleanup {
    deleteWindows
} -result {{} {}}
test frame-8.2 {FrameCmdDeletedProc procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .f1 -menu .m
    wm geometry .f1 +0+0
    update
    rename .f1 {}
    update
    list [info command .f*] [winfo children .]
} -cleanup {
    deleteWindows
} -result {{} {}}
#
# This one fails with the dash-patch!!!! Still don't know why  :-(
#
#test frame-8.3 {FrameCmdDeletedProc procedure} -setup {
#    eval destroy [winfo children .]
#    deleteWindows
#} -body {
#    toplevel .f1 -menu .m
#    wm geometry .f1 +0+0
#    menu .m
#    update
#    rename .f1 {}
#    update
#    list [info command .f*] [winfo children .]
#} -cleanup {
#    eval destroy [winfo children .]
#    deleteWindows
#} -result {{} .m}

test frame-9.1 {MapFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 100 -height 400
    wm geometry .t +0+0
    set result [winfo ismapped .t]
    update
    update idletasks
    lappend result [winfo ismapped .t]
} -cleanup {
    deleteWindows
} -result {0 1}
test frame-9.2 {MapFrame procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -width 100 -height 400
    wm geometry .t +0+0
    destroy .t
    update
    winfo exists .t
} -result 0
} -result {0}
test frame-9.3 {MapFrame procedure, window deleted while mapping} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -width 200 -height 200
    wm geometry .t2 +0+0
    tkwait visibility .t2
    toplevel .t -width 100 -height 400
    wm geometry .t +0+0
    frame .t2.f -width 50 -height 50
    bind .t2.f <Configure> {destroy .t}
    pack .t2.f -side top
    update
    update idletasks
    winfo exists .t
} -cleanup {
    deleteWindows
} -result 0
} -result {0}


test frame-10.1 {frame widget vs hidden commands} -setup {
    deleteWindows
	deleteWindows
} -body {
    set l [interp hidden]
    frame .t
    interp hide {} .t
    destroy .t
    list [winfo children .] [lsort [interp hidden]]
} -result [list {} [lsort [interp hidden]]]
    set res1 [list [winfo children .] [interp hidden]]
    set res2 [list {} $l]
    expr {$res1 eq $res2}
} -result 1


test frame-11.1 {TkInstallFrameMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m1.system
    menu .m1.system -tearoff 0
    .m1.system add command -label foo
    toplevel .t -menu .m1
} -cleanup {
    deleteWindows
} -result {.t}
test frame-11.2 {TkInstallFrameMenu - frame renamed} -setup {
    deleteWindows
	deleteWindows
    catch {rename foo {}}
} -body {
    catch {rename foo {}}
    menu .m1
    .m1 add cascade -menu .m1.system
    menu .m1.system -tearoff 0
    .m1.system add command -label foo
    toplevel .t
    rename .t foo
} -cleanup {
    deleteWindows
} -result {}


test frame-12.1 {FrameWorldChanged procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test -bd -padx and -pady
    frame .f -borderwidth 2 -padx 3 -pady 4
    place .f -x 0 -y 0 -width 40 -height 40
    pack [frame .f.f] -fill both -expand 1
    update
    list [winfo x .f.f] [winfo y .f.f] [winfo width .f.f] [winfo height .f.f]
} -cleanup {
    deleteWindows
} -result {5 6 30 28}
test frame-12.2 {FrameWorldChanged procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test all -labelanchor positions
    set font {helvetica 12}
    labelframe .f -highlightthickness 1 -bd 3 -padx 1 -pady 2 -font $font \
            -text "Mupp"
    set fh [expr {max([font metrics $font -linespace] + 2 - 3, 0)}]
    set fw [expr {max([font measure $font "Mupp"] + 2 - 3, 0)}]
    set fh [expr {[font metrics $font -linespace] + 2 - 3}]
    set fw [expr {[font measure $font "Mupp"] + 2 - 3}]
    if {$fw < 0} {set fw 0}
    if {$fh < 0} {set fh 0}
    place .f -x 0 -y 0 -width 100 -height 100
    pack [frame .f.f] -fill both -expand 1

    set result {}
    foreach lp {nw n ne en e es se s sw ws w wn} {
        .f configure -labelanchor $lp
        update
        set expx 5
        set expy 6
        set expw 90
        set exph 88
        switch -glob $lp {
            n* {incr expy $fh ; incr exph -$fh}
            s* {incr exph -$fh}
            w* {incr expx $fw ; incr expw -$fw}
            e* {incr expw -$fw}
        }
        lappend result [expr {
	    [winfo x .f.f] == $expx && [winfo y .f.f] == $expy &&
	    [winfo width .f.f] == $expw && [winfo height .f.f] == $exph
        lappend result [expr {\
                [winfo x .f.f] == $expx && [winfo y .f.f] == $expy &&\
                [winfo width .f.f] == $expw && [winfo height .f.f] == $exph}]
	}]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {1 1 1 1 1 1 1 1 1 1 1 1}
test frame-12.3 {FrameWorldChanged procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Check reaction on font change
    font create myfont -family courier -size 10
    labelframe .f -font myfont -text Mupp
    place .f -x 0 -y 0 -width 40 -height 40
    pack [frame .f.f] -fill both -expand 1
    update
    set h1 [font metrics myfont -linespace]
    set y1 [winfo y .f.f]
    font configure myfont -size 20
    update  ; # services the "TheWorldHasChanged" event, queues "TkWorldChanged" events
    update  ; # services the queued "TkWorldChanged" events
    update
    set h2 [font metrics myfont -linespace]
    set y2 [winfo y .f.f]
    expr {($h2 - $h1) - ($y2 - $y1)}
} -cleanup {
    deleteWindows
    font delete myfont
} -result 0
} -result {0}


test frame-13.1 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f -class NewFrame
    .f configure -class
} -cleanup {
    deleteWindows
} -result {-class class Class Labelframe NewFrame}
test frame-13.2 {labelframe configuration options} -setup {
    deleteWindows
} -body {
    labelframe .f -class NewFrame
    .f configure -class Different
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -class option after widget is created}
} -returnCodes error -result {can't modify -class option after widget is created}
test frame-13.3 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f -colormap new
} -cleanup {
    deleteWindows
} -result {.f}
test frame-13.4 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f -visual default
} -cleanup {
    deleteWindows
} -result {.f}
test frame-13.5 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f -screen bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {unknown option "-screen"}
test frame-13.6 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f -container true
} -cleanup {
    deleteWindows
} -result {.f}
test frame-13.7 {labelframe configuration options} -setup {
    deleteWindows
} -body {
    labelframe .f -container true
    .f configure -container
} -cleanup {
    deleteWindows
} -result {-container container Container 0 1}
test frame-13.8 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
     labelframe .f -container bogus
} -cleanup {
    deleteWindows
} -returnCodes error -result {expected boolean value but got "bogus"}
test frame-13.9 {labelframe configuration options} -setup {
    deleteWindows
	deleteWindows
} -body {
    labelframe .f
    .f configure -container 1
} -returnCodes error -cleanup {
} -cleanup {
    deleteWindows
} -result {can't modify -container option after widget is created}
} -returnCodes error -result {can't modify -container option after widget is created}

destroy .f
labelframe .f
test frame-13.10 {labelframe configuration options} -body {
    .f configure -background #ff0000
    lindex [.f configure -background] 4
} -cleanup {
    .f configure -background [lindex [.f configure -background] 3]
} -result "#ff0000"
} -result {#ff0000}
test frame-13.11 {labelframe configuration options} -body {
    .f configure -background non-existent
        .f configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-13.12 {labelframe configuration options} -body {
    .f configure -bd 4
    lindex [.f configure -bd] 4
} -cleanup {
    .f configure -bd [lindex [.f configure -bd] 3]
} -result 4
} -result {4}
test frame-13.13 {labelframe configuration options} -body {
    .f configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -bd badValue
} -returnCodes error -result {bad screen distance "badValue"}
test frame-13.14 {labelframe configuration options} -body {
    .f configure -bg #00ff00
    lindex [.f configure -bg] 4
} -cleanup {
    .f configure -bg [lindex [.f configure -bg] 3]
} -result "#00ff00"
} -result {#00ff00}
test frame-13.15 {labelframe configuration options} -body {
    .f configure -bg non-existent
        .f configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-13.16 {labelframe configuration options} -body {
    .f configure -borderwidth 1.3
    lindex [.f configure -borderwidth] 4
} -cleanup {
    .f configure -borderwidth [lindex [.f configure -borderwidth] 3]
} -result 1
} -result {1}
test frame-13.17 {labelframe configuration options} -body {
    .f configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -borderwidth badValue
} -returnCodes error -result {bad screen distance "badValue"}
test frame-13.18 {labelframe configuration options} -body {
    .f configure -cursor arrow
    lindex [.f configure -cursor] 4
} -cleanup {
    .f configure -cursor [lindex [.f configure -cursor] 3]
} -result {arrow}
test frame-13.19 {labelframe configuration options} -body {
    .f configure -cursor badValue
        .f configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test frame-13.20 {labelframe configuration options} -body {
    .f configure -fg #0000ff
    lindex [.f configure -fg] 4
} -cleanup {
    .f configure -fg [lindex [.f configure -fg] 3]
} -result "#0000ff"
} -result {#0000ff}
test frame-13.21 {labelframe configuration options} -body {
    .f configure -fg non-existent
        .f configure -fg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-13.22 {labelframe configuration options} -body {
    .f configure -font {courier 8}
    lindex [.f configure -font] 4
} -cleanup {
    .f configure -font [lindex [.f configure -font] 3]
} -result {courier 8}
test frame-13.23 {labelframe configuration options} -body {
    .f configure -foreground #ff0000
    lindex [.f configure -foreground] 4
} -cleanup {
    .f configure -foreground [lindex [.f configure -foreground] 3]
} -result "#ff0000"
} -result {#ff0000}
test frame-13.24 {labelframe configuration options} -body {
    .f configure -foreground non-existent
        .f configure -foreground non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-13.25 {labelframe configuration options} -body {
    .f configure -height 100
    lindex [.f configure -height] 4
} -cleanup {
    .f configure -height [lindex [.f configure -height] 3]
} -result 100
} -result {100}
test frame-13.26 {labelframe configuration options} -body {
    .f configure -height not_a_number
} -returnCodes error -result {expected screen distance but got "not_a_number"}
        .f configure -height not_a_number
} -returnCodes error -result {bad screen distance "not_a_number"}
test frame-13.27 {labelframe configuration options} -body {
    .f configure -highlightbackground #112233
    lindex [.f configure -highlightbackground] 4
} -cleanup {
    .f configure -highlightbackground [lindex [.f configure -highlightbackground] 3]
} -result "#112233"
} -result {#112233}
test frame-13.28 {labelframe configuration options} -body {
    .f configure -highlightbackground ugly
        .f configure -highlightbackground ugly
} -returnCodes error -result {unknown color name "ugly"}
test frame-13.29 {labelframe configuration options} -body {
    .f configure -highlightcolor #123456
    lindex [.f configure -highlightcolor] 4
} -cleanup {
    .f configure -highlightcolor [lindex [.f configure -highlightcolor] 3]
} -result "#123456"
} -result {#123456}
test frame-13.30 {labelframe configuration options} -body {
    .f configure -highlightcolor non-existent
        .f configure -highlightcolor non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test frame-13.31 {labelframe configuration options} -body {
    .f configure -highlightthickness 6
    lindex [.f configure -highlightthickness] 4
} -cleanup {
    .f configure -highlightthickness [lindex [.f configure -highlightthickness] 3]
} -result 6
} -result {6}
test frame-13.32 {labelframe configuration options} -body {
    .f configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -highlightthickness badValue
} -returnCodes error -result {bad screen distance "badValue"}
test frame-13.33 {labelframe configuration options} -body {
    .f configure -labelanchor se
    lindex [.f configure -labelanchor] 4
} -cleanup {
    .f configure -labelanchor [lindex [.f configure -labelanchor] 3]
} -result {se}
test frame-13.34 {labelframe configuration options} -returnCodes error -body {
    .f configure -labelanchor badValue
} -result {bad labelanchor "badValue": must be e, en, es, n, ne, nw, s, se, sw, w, wn, or ws}
test frame-13.34 {labelframe configuration options} -body {
        .f configure -labelanchor badValue
} -returnCodes error -result {bad labelanchor "badValue": must be e, en, es, n, ne, nw, s, se, sw, w, wn, or ws}
test frame-13.35 {labelframe configuration options} -body {
    .f configure -padx 3
    lindex [.f configure -padx] 4
} -cleanup {
    .f configure -padx [lindex [.f configure -padx] 3]
} -result 3
} -result {3}
test frame-13.36 {labelframe configuration options} -body {
    .f configure -padx badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -padx badValue
} -returnCodes error -result {bad screen distance "badValue"}
test frame-13.37 {labelframe configuration options} -body {
    .f configure -pady 4
    lindex [.f configure -pady] 4
} -cleanup {
    .f configure -pady [lindex [.f configure -pady] 3]
} -result 4
} -result {4}
test frame-13.38 {labelframe configuration options} -body {
    .f configure -pady badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -pady badValue
} -returnCodes error -result {bad screen distance "badValue"}
test frame-13.39 {labelframe configuration options} -body {
    .f configure -relief ridge
    lindex [.f configure -relief] 4
} -cleanup {
    .f configure -relief [lindex [.f configure -relief] 3]
} -result {ridge}
test frame-13.40 {labelframe configuration options} -returnCodes error -body {
    .f configure -relief badValue
} -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test frame-13.40 {labelframe configuration options} -body {
        .f configure -relief badValue
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test frame-13.41 {labelframe configuration options} -body {
    .f configure -takefocus {any string}
    lindex [.f configure -takefocus] 4
} -cleanup {
    .f configure -takefocus [lindex [.f configure -takefocus] 3]
} -result {any string}
test frame-13.42 {labelframe configuration options} -body {
    .f configure -text {any string}
    lindex [.f configure -text] 4
} -cleanup {
    .f configure -text [lindex [.f configure -text] 3]
} -result {any string}
test frame-13.43 {labelframe configuration options} -body {
    .f configure -width 32
    lindex [.f configure -width] 4
} -cleanup {
    .f configure -width [lindex [.f configure -width] 3]
} -result 32
} -result {32}
test frame-13.44 {labelframe configuration options} -body {
    .f configure -width badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
        .f configure -width badValue
} -returnCodes error -result {bad screen distance "badValue"}
destroy .f


test frame-14.1 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test that label is moved in stacking order
    label .l -text Mupp -font {helvetica 8}
    labelframe .f -labelwidget .l
    pack .f
    frame .f.f -width 50 -height 50
    pack .f.f
    update
    list [winfo children .] [winfo width .f] \
        [expr {[winfo height .f] - [winfo height .l]}]
} -cleanup {
    deleteWindows
} -result {{.f .l} 54 52}
test frame-14.2 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test the labelframe's reaction if the label is destroyed
    label .l -text Aratherlonglabel
    labelframe .f -labelwidget .l
    pack .f
    label .f.l -text Mupp
    pack .f.l
    update
    set res [list [.f cget -labelwidget]]
    lappend res [expr {[winfo width .f] - [winfo width .l]}]
    destroy .l
    lappend res [.f cget -labelwidget]
    update
    lappend res [expr {[winfo width .f] - [winfo width .f.l]}]
} -cleanup {
    deleteWindows
} -result {.l 12 {} 4}
test frame-14.3 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test the labelframe's reaction if the label is stolen
    label .l -text Aratherlonglabel
    labelframe .f -labelwidget .l
    pack .f
    label .f.l -text Mupp
    pack .f.l
    update
    set res [list [.f cget -labelwidget]]
    lappend res [expr {[winfo width .f] - [winfo width .l]}]
    pack .l
    lappend res [.f cget -labelwidget]
    update
    lappend res [expr {[winfo width .f] - [winfo width .f.l]}]
} -cleanup {
    deleteWindows
} -result {.l 12 {} 4}
test frame-14.4 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test the label's reaction if the labelframe is destroyed
    label .l -text Mupp
    labelframe .f -labelwidget .l
    pack .f
    update
    set res [list [winfo manager .l]]
    destroy .f
    lappend res [winfo manager .l]
} -cleanup {
    deleteWindows
} -result {labelframe {}}
test frame-14.5 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Test that the labelframe reacts on changes in label
    label .l -text Aratherlonglabel
    labelframe .f -labelwidget .l
    pack .f
    label .f.l -text Mupp
    pack .f.l
1467
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479




1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504

1505
1506

1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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



1498
1499
1500
1501
1502
1503
1504

1505
1506




1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518



1519














1520


1521































































































































1522









































































































































1523





1524
1525
1526



1527
1528
1529







-
+

-
-
-
-
+
+
+
+








-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-



-
-
-
+
+
+
    update
    lappend res [expr {[winfo width .f] - [winfo width .l]}]
    lappend res [expr {[winfo width .f] > $first}]
} -cleanup {
    deleteWindows
} -result {12 12 1 12 1}
test frame-14.6 {labelframe labelwidget option} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Destroying a labelframe with a child label caused a crash when not
    # handling mapping of the label correctly.
    # This test does not test anything directly, it's just ment to catch if
    # the same mistake is made again.
    # Destroying a labelframe with a child label caused a crash
    # when not handling mapping of the label correctly.
    # This test does not test anything directly, it's just ment
    # to catch if the same mistake is made again.
    labelframe .f
    pack .f
    label .f.l -text Mupp
    .f configure -labelwidget .f.l
    update
} -cleanup {
    deleteWindows
} -result {}

test frame-15.1 {TIP 262: frame background images} -setup {
    deleteWindows
deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    frame .f -width 100 -height 100
    pack .f
    list [image inuse gorp] [.f configure -backgroundimage gorp;update] \
	[image inuse gorp] [winfo width .f] [winfo height .f]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {0 {} 1 100 100}
test frame-15.2 {TIP 262: frame background images} -setup {
    deleteWindows
    catch {rename gorp ""}
rename eatColors {}
} -body {
    frame .f -width 100 -height 100
rename colorsFree {}
    pack .f
    update
    .f configure -backgroundimage gorp
} -returnCodes error -cleanup {
    deleteWindows
} -result {image "gorp" doesn't exist}
test frame-15.3 {TIP 262: frame background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    frame .f -width 100 -height 100 -backgroundimage gorp
    pack .f
    .f configure -tile yes
    update
    list [.f cget -bgimg] [.f cget -tile]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {gorp 1}
test frame-15.4 {TIP 262: frame background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    frame .f -width 100 -height 100 -backgroundimage gorp
    pack .f
    .f configure -tile yes
    update
    gorp put red -to 15 15 20 20
    update
    list [.f cget -bgimg] [.f cget -tile]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {gorp 1}
test frame-15.5 {TIP 262: frame background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
    set result {}
} -body {
    frame .f -width 100 -height 100 -backgroundimage gorp
    pack .f
    .f configure -tile yes
    update
    image delete gorp
    update
    set result [list [.f cget -bgimg] [.f cget -tile]]
    image create photo gorp -width 250 -height 250
    update
    lappend result [.f cget -backgroundimage]
} -cleanup {
    catch {image delete gorp}
    deleteWindows
} -result {gorp 1 gorp}
test frame-15.6 {TIP 262: frame background images} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 100 -height 100 -bgimg gorp]
    update idletasks; update
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15}}
test frame-15.6a {TIP 262: frame background images (offsets)} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 10 -height 10 -bgimg gorp]
    update idletasks; update
    # On MacOS must wait for the test image display procedure to run.
    set timer [after 300 {lappend result "timedout"}]
    while {"timedout" ni $result &&
	   "gorp display 10 2 10 10" ni $result} {
       vwait result
    }
    after cancel $timer
    update idletasks; update
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 10 2 10 10}}
test frame-15.7 {TIP 262: frame background images} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 50 -height 25 -bgimg gorp -tile 1]
    update idletasks; update
    # On MacOS must wait for the test image display procedure to run.
    set timer [after 300 {lappend result "timedout"}]
    while {"timedout" ni $result &&
	   "gorp display 0 0 20 10" ni $result} {
	vwait result
    }
    after cancel $timer
    if {[lindex $result end] eq "timedout"} {
	return [lreplace $result end end]
    }
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 10} {gorp display 0 0 20 15} {gorp display 0 0 20 10}}
test frame-15.7a {TIP 262: frame background images (offsets)} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 50 -height 25 -bgimg gorp -tile 1 -highlightthick 1]
    update idletasks; update
    # On MacOS must wait for the test image display procedure to run.
    set timer [after 300 {lappend result "timedout"}]
    while {"timedout" ni $result &&
	   "gorp display 0 0 18 8" ni $result} {
	vwait result
   }

    after cancel $timer
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 8} {gorp display 0 0 18 15} {gorp display 0 0 18 8}}
test frame-15.7b {TIP 262: frame background images (offsets)} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 50 -height 25 -bgimg gorp -tile 1 -bd 2]
    update idletasks; update
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 6} {gorp display 0 0 16 15} {gorp display 0 0 16 6}}
test frame-15.7c {TIP 262: frame background images (offsets)} -setup {
    deleteWindows
    set result {}
    . configure -width 200 -height 200
} -constraints testImageType -body {
    image create test gorp -variable result
    pack [frame .f -width 50 -height 25 -bgimg gorp -tile 1 -bd 2 -highlightthick 1]
    update idletasks; update
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 4} {gorp display 0 0 14 15} {gorp display 0 0 14 4}}
test frame-15.8 {TIP 262: toplevel background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    toplevel .t -width 100 -height 100
    update
    # Used to verify that setting a background image doesn't change the widget size
    set w [winfo width .t]
    set h [winfo height .t]
    list [image inuse gorp] [.t configure -backgroundimage gorp;update] \
	[image inuse gorp] \
	[expr {$w-[winfo width .t]}] [expr {$h-[winfo height .t]}]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {0 {} 1 0 0}
test frame-15.9 {TIP 262: toplevel background images} -setup {
    deleteWindows
    catch {rename gorp ""}
} -body {
    toplevel .t -width 100 -height 100
    update
    .t configure -backgroundimage gorp
} -returnCodes error -cleanup {
    deleteWindows
} -result {image "gorp" doesn't exist}
test frame-15.10 {TIP 262: toplevel background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    toplevel .t -width 100 -height 100 -backgroundimage gorp -tile yes
    update
    list [.t cget -bgimg] [.t cget -tile]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {gorp 1}
test frame-15.11 {TIP 262: toplevel background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
} -body {
    toplevel .t -width 100 -height 100 -backgroundimage gorp -tile yes
    update
    gorp put red -to 15 15 20 20
    update
    list [.t cget -bgimg] [.t cget -tile]
} -cleanup {
    image delete gorp
    deleteWindows
} -result {gorp 1}
test frame-15.12 {TIP 262: toplevel background images} -setup {
    deleteWindows
    image create photo gorp -width 10 -height 10
    gorp put black -to 2 2 7 7
    set result {}
} -body {
    toplevel .t -width 100 -height 100 -backgroundimage gorp -tile yes
    update
    image delete gorp
    update
    set result [list [.t cget -bgimg] [.t cget -tile]]
    image create photo gorp -width 250 -height 250
    update
    lappend result [.t cget -backgroundimage]
} -cleanup {
    catch {image delete gorp}
    deleteWindows
} -result {gorp 1 gorp}
test frame-15.13 {TIP 262: toplevel background images} -setup {
    deleteWindows
    set result {}
} -constraints testImageType -body {
    image create test gorp -variable result
    toplevel .t -width 100 -height 100 -bgimg gorp
    wm overrideredirect .t 1;	# Reduce trouble from window managers
    update idletasks; update
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15}}
test frame-15.14 {TIP 262: toplevel background images} -setup {
    deleteWindows
    set result {}
} -constraints testImageType -body {
    image create test gorp -variable result
    toplevel .t -width 50 -height 25 -bgimg gorp -tile 1
    wm overrideredirect .t 1;	# Reduce trouble from window managers
    update idletasks; update
    # On MacOS must wait for the test image display procedure to run.
    set timer [after 300 {lappend result "timedout"}]
    while {"timedout" ni $result &&
	   "gorp display 0 0 20 10" ni $result} {
	vwait result
   }
    after cancel $timer
    return [uniq $result]
} -cleanup {
    deleteWindows
    catch {image delete gorp}
} -result {{gorp get} {gorp display 0 0 30 15} {gorp display 0 0 30 10} {gorp display 0 0 20 15} {gorp display 0 0 20 10}}

# cleanup
deleteWindows
apply {cmds {foreach cmd $cmds {rename $cmd {}}}} {
    eatColors colorsFree uniq optnames
}

cleanupTests
return

# Local Variables:
# mode: tcl
# End:



Changes to tests/geometry.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test the procedures in the file
# tkGeometry.c (generic support for geometry managers).  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

proc getsize w {
    regexp {(^[^+-]*)} [wm geometry $w] foo x
    return $x
}

278
279
280
281
282
283
284
285

286
287
288
289
290
291
278
279
280
281
282
283
284

285
286
287
288
289
290
291







-
+






    after 500 {set x 1}
    tkwait variable x
    wm deiconify .t
    update
    winfo ismapped .t.quit
} -cleanup {
    destroy .t
} -result 1
} -result {1}


# cleanup
cleanupTests
return

Changes to tests/get.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the procedures in the file
# tkGet.c.  It is organized in the standard fashion for Tcl
# white-box tests.
#
# Copyright © 1998 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

Changes to tests/grab.test.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19



20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6

7
8
9
10
11
12
13
14





15
16
17

18

19
20
21
22
23
24
25






-
+







-
-
-
-
-
+
+
+
-

-







# Tests for the grab command.
#
# This file contains a collection of tests for one or more of the Tk
# built-in commands.  Sourcing this file runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# The macOS test module includes the pressbutton command to simulate a
# mouse button press event by injecting events into the NSApplication
# event queue.  On other platforms there is currently no way to test
# the actual grab effect, per se, in an automated test.  Therefore,
# this test suite only covers the interface to the grab command (ie,
# There's currently no way to test the actual grab effect, per se,
# in an automated test.  Therefore, this test suite only covers the
# interface to the grab command (ie, error messages, etc.)
# error messages, etc.) on platforms other than macOS.

testConstraint pressbutton [llength [info commands pressbutton]]

test grab-1.1 {Tk_GrabObjCmd} -body {
    grab
} -returnCodes error -result {wrong # args: should be "grab ?-global? window" or "grab option ?arg ...?"}
test grab-1.2 {Tk_GrabObjCmd} -body {
    rename grab grabTest1.2
    grabTest1.2
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
+







    set curr [grab current .]
    if { [string length $curr] > 0 } {
	grab release $curr
    }
    grab status .
} -cleanup {
    grab release .
} -result none
} -result {none}
test grab-2.2 {Tk_GrabObjCmd, grab status gives correct status} -body {
    set curr [grab current .]
    if { [string length $curr] > 0 } {
	grab release $curr
    }
    grab .
    grab status .
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
178
179
180
181
182
183
184


























185
186
187
188







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




    }
    grab set -global .
    list [grab current .] [grab status .]
} -cleanup {
    grab release .
} -result {. global}

test grab-6.1 {local grab on child window} -constraints {
    pressbutton
} -body {
    wm geometry . 100x200+200+100
    set result {}
    frame .f -background red -padx 10 -pady 10 -height 100 -width 80
    bind . <Button-1> {lappend result "outside"}
    bind .f <Button-1> {lappend result "inside"}
    pack .f
    update idletasks
    pressbutton 250 150
    update
    lappend result ":"
    pressbutton 250 250
    update
    lappend result ":"
    grab set .f
    pressbutton 250 150
    update
    lappend result ":"
    pressbutton 250 250
    update
    return $result
} -cleanup {
    grab release .f
} -result {inside outside : outside : inside outside :}

cleanupTests
return

Changes to tests/grid.test.

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
1
2
3


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33



-
-
+
+




















-
+







# This file is a Tcl script to test out the *NEW* "grid" command of Tk. It is
# (almost) organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# helper routine to return "." to a sane state after a test.
# The variable GRID_VERBOSE can be used to "look" at the result of one or all
# of the tests

proc grid_reset {{test ?} {top .}} {
    global GRID_VERBOSE
    if {[info exists GRID_VERBOSE]} {
	if {$GRID_VERBOSE eq "" || $GRID_VERBOSE eq $test} {
	    puts -nonewline "grid test $test: "
	    flush stdout
	    gets stdin
	}
    }
    destroy {*}[winfo children $top]
    eval destroy [winfo children $top]
    update
    foreach {cols rows} [grid size .] {}
    for {set i 0} {$i <= $cols} {incr i} {
	grid columnconfigure . $i -weight 0 -minsize 0 -pad 0 -uniform ""
    }
    for {set i 0} {$i <= $rows} {incr i} {
	grid rowconfigure . $i -weight 0 -minsize 0 -pad 0 -uniform ""
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102







-
+

















-
+


-
+













-












-
+







wm geometry . {}

test grid-1.1 {basic argument checking} -body {
    grid
} -returnCodes error -result {wrong # args: should be "grid option arg ?arg ...?"}
test grid-1.2 {basic argument checking} -body {
    grid foo bar
} -returnCodes error -result {bad option "foo": must be anchor, bbox, columnconfigure, configure, content, forget, info, location, propagate, remove, rowconfigure, or size}
} -returnCodes error -result {bad option "foo": must be anchor, bbox, columnconfigure, configure, forget, info, location, propagate, remove, rowconfigure, size, or slaves}
test grid-1.3 {basic argument checking} -body {
    button .b
    grid .b -row 0 -column
} -cleanup {
    grid_reset 1.3
} -returnCodes error -result {extra option or option with no value}
test grid-1.4 {basic argument checking} -body {
    button .b
    grid configure .b - foo
} -cleanup {
    grid_reset 1.4
} -returnCodes error -result {unexpected parameter "foo" in configure list: should be window name or option}
test grid-1.5 {basic argument checking} -body {
    grid .
} -returnCodes error -result {can't manage ".": it's a top-level window}
test grid-1.6 {basic argument checking} -body {
    grid x
} -returnCodes error -result {can't determine container window}
} -returnCodes error -result {can't determine master window}
test grid-1.7 {basic argument checking} -body {
    grid configure x
} -returnCodes error -result {can't determine container window}
} -returnCodes error -result {can't determine master window}
test grid-1.8 {basic argument checking} -body {
    button .b
    grid x .b
} -cleanup {
    grid_reset 1.8
} -returnCodes ok -result {}
test grid-1.9 {basic argument checking} -body {
    button .b
    grid configure x .b
} -cleanup {
    grid_reset 1.9
} -returnCodes ok -result {}


test grid-2.1 {bbox} -body {
    grid bbox .
} -result {0 0 0 0}
test grid-2.2 {bbox} -body {
    button .b
    grid .b
    destroy .b
    update
    grid bbox .
} -result {0 0 0 0}
test grid-2.3 {bbox: argument checking} -body {
    grid bbox . 0 0 5
} -returnCodes error -result {wrong # args: should be "grid bbox window ?column row ?column row??"}
} -returnCodes error -result {wrong # args: should be "grid bbox master ?column row ?column row??"}
test grid-2.4 {bbox} -body {
    grid bbox .bad 0 0
} -returnCodes error -result {bad window path name ".bad"}
test grid-2.5 {bbox} -body {
    grid bbox . x 0
} -returnCodes error -result {expected integer but got "x"}
test grid-2.6 {bbox} -body {
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154







-
+








test grid-3.1 {configure: basic argument checking} -body {
    grid configure foo
} -returnCodes error -result {bad argument "foo": must be name of window}
test grid-3.2 {configure: basic argument checking} -body {
    button .b
    grid configure .b
    grid content .
    grid slaves .
} -cleanup {
    grid_reset 3.2
} -result {.b}
test grid-3.3 {configure: basic argument checking} -body {
    button .b
    grid .b -row -1
} -cleanup {
175
176
177
178
179
180
181
182

183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229

230
231
232
233
234
235
236
174
175
176
177
178
179
180

181
182
183
184

185
186
187
188
189
190
191
192
193
194
























195
196
197
198
199
200
201

202
203

204
205
206
207
208
209
210
211







-
+



-
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+

-
+







} -returnCodes error -result {bad columnspan value "0": must be a positive integer}
test grid-3.7 {configure: basic argument checking} -body {
    frame .f
    button .f.b
    grid .f .f.b
} -cleanup {
    grid_reset 3.7
} -returnCodes error -result {can't put ".f.b" inside "."}
} -returnCodes error -result {can't put .f.b inside .}
test grid-3.8 {configure: basic argument checking} -body {
    button .b
    grid configure x .b
    grid content .
    grid slaves .
} -cleanup {
    grid_reset 3.8
} -result {.b}
test grid-3.9 {configure: basic argument checking} -body {
    button .b
    grid configure y .b
} -cleanup {
    grid_reset 3.9
} -returnCodes error -result {invalid window shortcut, "y" should be '-', 'x', or '^'}
test grid-3.10 {ConfigureContent procedure, bad -in option} -body {
    frame .f
    grid .f -in .f
} -cleanup {
    grid_reset 3.10
} -returnCodes error -result {window can't be managed in itself}
test grid-3.11 {prevent management loops} -body {
    frame .f1
    frame .f2
    grid .f1 -in .f2
    grid .f2 -in .f1
} -cleanup {
    grid_reset 3.11
} -returnCodes error -result {can't put ".f2" inside ".f1": would cause management loop}
test grid-3.12 {prevent management loops} -body {
    frame .f1
    frame .f2
    frame .f3
    grid .f1 -in .f2
    grid .f2 -in .f3
    grid .f3 -in .f1
} -cleanup {
    grid_reset 3.12
} -returnCodes error -result {can't put ".f3" inside ".f1": would cause management loop}

test grid-4.1 {forget: basic argument checking} -body {
    grid forget foo
} -returnCodes error -result {bad window path name "foo"}
test grid-4.2 {forget} -body {
    button .c
    grid [button .b]
    set a [grid content .]
    set a [grid slaves .]
    grid forget .b .c
    lappend a [grid content .]
    lappend a [grid slaves .]
    return $a
} -cleanup {
    grid_reset 4.2
} -result {.b {}}
test grid-4.3 {forget} -body {
    button .c
    grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx 3 -pady 4 -sticky ns
289
290
291
292
293
294
295
296

297
298
299
300
301
302

303
304
305

306
307
308
309
310
311
312
264
265
266
267
268
269
270

271
272
273
274
275
276

277
278
279

280
281
282
283
284
285
286
287







-
+





-
+


-
+







    grid info .1
} -cleanup {
    grid_reset 5.4
} -returnCodes ok -result {}

test grid-6.1 {location: basic argument checking} -body {
    grid location .
} -returnCodes error -result {wrong # args: should be "grid location window x y"}
} -returnCodes error -result {wrong # args: should be "grid location master x y"}
test grid-6.2 {location: basic argument checking} -body {
    grid location .bad 0 0
} -returnCodes error -result {bad window path name ".bad"}
test grid-6.3 {location: basic argument checking} -body {
    grid location . x y
} -returnCodes error -result {expected screen distance but got "x"}
} -returnCodes error -result {bad screen distance "x"}
test grid-6.4 {location: basic argument checking} -body {
    grid location . 1c y
} -returnCodes error -result {expected screen distance but got "y"}
} -returnCodes error -result {bad screen distance "y"}
test grid-6.5 {location: basic argument checking} -body {
    frame .f
    grid location .f 10 10
} -cleanup {
    grid_reset 6.5
} -result {-1 -1}
test grid-6.6 {location (x)} -body {
362
363
364
365
366
367
368
369



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395

396
397
398
399
400
401
402
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369
370
371

372
373
374
375
376
377
378
379







-
+
+
+




















-
+




-
+







	    set got $a
	}
    }
    return $result
} -cleanup {
    grid_reset 6.8
} -result {{-10->-1 -1} {0->0 0} {16->0 1} {201->1 1}}
test grid-6.9 {location: check updates pending} -body {
test grid-6.9 {location: check updates pending} -constraints {
    nonPortable
} -body {
    set a ""
    foreach i {0 1 2} {
	frame .$i -width 120 -height 75 -bg red
	lappend a [grid location . 150 90]
	grid .$i -row $i -column $i
    }
    return $a
} -cleanup {
    grid_reset 6.9
} -result {{0 0} {1 1} {1 1}}

test grid-7.1 {propagate} -body {
    grid propagate . 1 xxx
} -cleanup {
    grid_reset 7.1
} -returnCodes error -result {wrong # args: should be "grid propagate window ?boolean?"}
test grid-7.2 {propagate} -body {
    grid propagate .
} -cleanup {
    grid_reset 7.2
} -result 1
} -result {1}
test grid-7.3 {propagate} -body {
    grid propagate . 0;grid propagate .
} -cleanup {
    grid_reset 7.3
} -result 0
} -result {0}
test grid-7.4 {propagate} -body {
    grid propagate .x
} -cleanup {
    grid_reset 7.4
} -returnCodes error -result {bad window path name ".x"}
test grid-7.5 {propagate} -body {
    grid propagate . x
510
511
512
513
514
515
516
517
518


519
520
521


522
523
524
525
526
527





528
529
530


531
532
533


534
535
536


537
538
539


540
541
542


543
544

545
546
547
548
549

550
551
552
553

554
555
556
557
558
559
560
561
562

563
564
565

566
567
568
569
570
571
572
573
574
575
576
577

578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

613
614
615
616
617

618
619
620
621
622
623

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

640
641
642
643
644

645
646
647
648
649
650
651
652
653
654
655

656
657
658
659
660
661
662
487
488
489
490
491
492
493


494
495
496


497
498
499





500
501
502
503
504
505


506
507
508


509
510
511


512
513
514


515
516
517


518
519
520

521
522
523
524
525

526
527
528
529

530
531
532
533
534
535
536
537
538

539
540
541

542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558

559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593

594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620

621
622
623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639







-
-
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

-
+




-
+



-
+








-
+


-
+











-
+




-
+














-
+














-
+




-
+





-
+















-
+




-
+










-
+







    update
    lappend a [grid size .]
    return $a
} -cleanup {
    grid_reset 8.6
} -result {{51 11} {51 11} {31 11} {21 11} {16 1} {1 1}}

test grid-9.1 {content} -body {
    grid content .
test grid-9.1 {slaves} -body {
    grid slaves .
} -returnCodes ok -result {}
test grid-9.2 {content} -body {
    grid content .foo
test grid-9.2 {slaves} -body {
    grid slaves .foo
} -returnCodes error -result {bad window path name ".foo"}
test grid-9.3 {content} -body {
    grid content a b
} -returnCodes error -result {wrong # args: should be "grid content window ?-option value ...?"}
test grid-9.4 {content} -body {
    grid content . a b
test grid-9.3 {slaves} -body {
    grid slaves a b
} -returnCodes error -result {wrong # args: should be "grid slaves window ?-option value ...?"}
test grid-9.4 {slaves} -body {
    grid slaves . a b
} -returnCodes error -result {bad option "a": must be -column or -row}
test grid-9.5 {content} -body {
    grid content . -column x
test grid-9.5 {slaves} -body {
    grid slaves . -column x
} -returnCodes error -result {expected integer but got "x"}
test grid-9.6 {content} -body {
    grid content . -row -3
test grid-9.6 {slaves} -body {
    grid slaves . -row -3
} -returnCodes error -result {-3 is an invalid value: should NOT be < 0}
test grid-9.7 {content} -body {
    grid content . -foo 3
test grid-9.7 {slaves} -body {
    grid slaves . -foo 3
} -returnCodes error -result {bad option "-foo": must be -column or -row}
test grid-9.8 {content} -body {
    grid content .x -row 3
test grid-9.8 {slaves} -body {
    grid slaves .x -row 3
} -returnCodes error -result {bad window path name ".x"}
test grid-9.9 {content} -body {
    grid content . -row 3
test grid-9.9 {slaves} -body {
    grid slaves . -row 3
} -returnCodes ok -result {}
test grid-9.10 {content} -body {
test grid-9.10 {slaves} -body {
    foreach i {0 1 2} {
	label .$i -text $i
	grid .$i -row $i -column $i
    }
    grid content .
    grid slaves .
} -cleanup {
    grid_reset 9.10
} -result {.2 .1 .0}
test grid-9.11 {content} -body {
test grid-9.11 {slaves} -body {
    catch {unset a}
    foreach i {0 1 2} {
	label .$i -text $i
	label .$i-x -text $i-x
	grid .$i -row $i -column $i
	grid .$i-x -row $i -column [incr i]
    }
    foreach row {0 1 2 3} {
	lappend a $row{[grid content . -row $row]}
	lappend a $row{[grid slaves . -row $row]}
    }
    foreach col {0 1 2 3} {
	lappend a $col{[grid content . -column $col]}
	lappend a $col{[grid slaves . -column $col]}
    }
    return $a
} -cleanup {
    grid_reset 9.11
} -result {{0{.0-x .0}} {1{.1-x .1}} {2{.2-x .2}} 3{} 0{.0} {1{.1 .0-x}} {2{.2 .1-x}} 3{.2-x}}

# column/row configure
test grid-10.1 {column/row configure} -body {
    grid columnconfigure .
} -cleanup {
    grid_reset 10.1
} -returnCodes error -result {wrong # args: should be "grid columnconfigure window index ?-option value ...?"}
} -returnCodes error -result {wrong # args: should be "grid columnconfigure master index ?-option value ...?"}
test grid-10.2 {column/row configure} -body {
    grid columnconfigure . 0 -weight 0 -pad
} -cleanup {
    grid_reset 10.2
} -returnCodes error -result {wrong # args: should be "grid columnconfigure window index ?-option value ...?"}
} -returnCodes error -result {wrong # args: should be "grid columnconfigure master index ?-option value ...?"}
test grid-10.3 {column/row configure} -body {
    grid columnconfigure .f 0 -weight
} -cleanup {
    grid_reset 10.3
} -returnCodes error -result {bad window path name ".f"}
test grid-10.4 {column/row configure} -body {
    grid columnconfigure . nine -weight
} -cleanup {
    grid_reset 10.4
} -returnCodes error -result {expected integer but got "nine" (when retrieving options only integer indices are allowed)}
test grid-10.5 {column/row configure} -body {
    grid columnconfigure . 265 -weight
} -cleanup {
    grid_reset 10.5
} -result 0
} -result {0}
test grid-10.6 {column/row configure} -body {
    grid columnconfigure . 0
} -cleanup {
    grid_reset 10.6
} -result {-minsize 0 -pad 0 -uniform {} -weight 0}
test grid-10.7 {column/row configure} -body {
    grid columnconfigure . 0 -foo
} -cleanup {
    grid_reset 10.7
} -returnCodes error -result {bad option "-foo": must be -minsize, -pad, -uniform, or -weight}
test grid-10.8 {column/row configure} -body {
    grid columnconfigure . 0 -minsize foo
} -cleanup {
    grid_reset 10.8
} -returnCodes error -result {expected screen distance but got "foo"}
} -returnCodes error -result {bad screen distance "foo"}
test grid-10.9 {column/row configure} -body {
    grid columnconfigure . 0 -minsize foo
} -cleanup {
    grid_reset 10.9
} -returnCodes error -result {expected screen distance but got "foo"}
} -returnCodes error -result {bad screen distance "foo"}
test grid-10.10 {column/row configure} -body {
    grid columnconfigure . 0 -minsize 10
    grid columnconfigure . 0 -minsize
} -cleanup {
    grid_reset 10.10
} -result 10
} -result {10}
test grid-10.11 {column/row configure} -body {
    grid columnconfigure . 0 -weight bad
} -cleanup {
    grid_reset 10.11
} -returnCodes error -result {expected integer but got "bad"}
test grid-10.12 {column/row configure} -body {
    grid columnconfigure . 0 -weight -3
} -cleanup {
    grid_reset 10.12
} -returnCodes error -result {invalid arg "-weight": should be non-negative}
test grid-10.13 {column/row configure} -body {
    grid columnconfigure . 0 -weight 3
    grid columnconfigure . 0 -weight
} -cleanup {
    grid_reset 10.13
} -result 3
} -result {3}
test grid-10.14 {column/row configure} -body {
    grid columnconfigure . 0 -pad foo
} -cleanup {
    grid_reset 10.14
} -returnCodes error -result {expected screen distance but got "foo"}
} -returnCodes error -result {bad screen distance "foo"}
test grid-10.15 {column/row configure} -body {
    grid columnconfigure . 0 -pad -3
} -cleanup {
    grid_reset 10.15
} -returnCodes error -result {invalid arg "-pad": should be non-negative}
test grid-10.16 {column/row configure} -body {
    grid columnconfigure . 0 -pad 3
    grid columnconfigure . 0 -pad
} -cleanup {
    grid_reset 10.16
} -result 3
} -result {3}
test grid-10.17 {column/row configure} -body {
    frame .f
    set a ""
    grid columnconfigure .f 0 -weight 0
    lappend a [grid columnconfigure .f 0 -weight]
    grid columnconfigure .f 0 -weight 1
    lappend a [grid columnconfigure .f 0 -weight]
850
851
852
853
854
855
856
857

858
859
860
861
862
863

864
865
866
867
868
869
870
827
828
829
830
831
832
833

834
835
836
837
838
839

840
841
842
843
844
845
846
847







-
+





-
+







grid_reset 10.39

# auto-placement tests
test grid-11.1 {default widget placement} -body {
    grid ^
} -cleanup {
    grid_reset 11.1
} -returnCodes error -result {can't use '^', can't find container window}
} -returnCodes error -result {can't use '^', cant find master}
test grid-11.2 {default widget placement} -body {
    button .b
    grid .b ^
} -cleanup {
    grid_reset 11.2
} -returnCodes error -result {can't find content to extend with "^"}
} -returnCodes error -result {can't find slave to extend with "^"}
test grid-11.3 {default widget placement} -body {
    button .b
    grid .b - - .c
} -cleanup {
    grid_reset 11.3
} -returnCodes error -result {bad window path name ".c"}
test grid-11.4 {default widget placement} -body {
911
912
913
914
915
916
917
918

919
920
921
922
923
924
925
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902







-
+







} -returnCodes error -result {must specify window before shortcut '-'}
test grid-11.9 {default widget placement} -body {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid .f -row 5 -column 5
    grid .f x ^
} -cleanup {
    grid_reset 11.9
} -returnCodes error -result {can't find content to extend with "^"}
} -returnCodes error -result {can't find slave to extend with "^"}
test grid-11.10 {default widget placement} -body {
    foreach i {1 2 3} {
	frame .f$i -width 100 -height 50 -highlightthickness 0 -bg red
    }
    grid .f1 .f2  -sticky nsew
    grid .f3   ^  -sticky nsew
    update
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167
1168
1169
1170
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147







-
+







} -returnCodes error -result {bad window path name ".bad"}
test grid-13.4 {-in} -body {
    frame .f -bg red
    toplevel .top
    grid .f -in .top
} -cleanup {
    grid_reset 13.3
} -returnCodes error -result {can't put ".f" inside ".top"}
} -returnCodes error -result {can't put .f inside .top}
destroy .top
test grid-13.5 {-ipadx} -body {
    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
    grid .f -ipadx x
} -cleanup {
    grid_reset 13.4
} -returnCodes error -result {bad ipadx value "x": must be positive screen distance}
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309

1310
1311
1312
1313
1314
1315
1316
1276
1277
1278
1279
1280
1281
1282

1283
1284
1285

1286
1287
1288
1289
1290
1291
1292
1293







-
+


-
+







    frame .1
    frame .2
    button .b
    grid .1 .2
    grid .b -in .1
    set a ""
    catch {unset info}; array set info [grid info .b]
    lappend a [grid content .1],[grid content .2],$info(-in)
    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
    grid .b -in .2
    catch {unset info}; array set info [grid info .b]
    lappend a [grid content .1],[grid content .2],$info(-in)
    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
    unset info
    return $a
} -cleanup {
    grid_reset 13.13
} -result {.b,,.1 ,.b,.2}

test grid-14.1 {structure notify} -body {
1363
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373

1374
1375

1376
1377

1378
1379
1380
1381

1382
1383
1384
1385
1386

1387
1388

1389
1390

1391
1392
1393
1394
1395
1396
1397
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349

1350
1351

1352
1353

1354
1355
1356
1357

1358
1359
1360
1361
1362

1363
1364

1365
1366

1367
1368
1369
1370
1371
1372
1373
1374







-
+


-
+

-
+

-
+



-
+




-
+

-
+

-
+







    update
    bind . <Configure> {}
    array get A
} -cleanup {
    grid_reset 14.3
} -result {.2 2 .0 1 . 2 .1 1}

test grid-15.1 {lost content} -body {
test grid-15.1 {lost slave} -body {
    button .b
    grid .b
    set a [grid content .]
    set a [grid slaves .]
    pack .b
    lappend a [grid content .]
    lappend a [grid slaves .]
    grid .b
    lappend a [grid content .]
    lappend a [grid slaves .]
} -cleanup {
    grid_reset 15.1
} -result {.b {} .b}
test grid-15.2 {lost content} -body {
test grid-15.2 {lost slave} -body {
    frame .f
    grid .f
    button .b
    grid .b -in .f
    set a [grid content .f]
    set a [grid slaves .f]
    pack .b -in .f
    lappend a [grid content .f]
    lappend a [grid slaves .f]
    grid .b -in .f
    lappend a [grid content .f]
    lappend a [grid slaves .f]
} -cleanup {
    grid_reset 15.2
} -result {.b {} .b}

test grid-16.1 {layout centering} -body {
    foreach i {0 1 2} {
	frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
1818
1819
1820
1821
1822
1823
1824

1825
1826
1827
1828
1829
1830
1831
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809







+







    toplevel .t
    frame .t.f
    label .t.f.l -text foobar
    grid .t.f.l
    destroy .t
    set result ok
} -result ok


test grid-18.1 {test respect for internalborder} -body {
    toplevel .pack
    wm geometry .pack 200x200
    frame .pack.l -width 15 -height 10
    labelframe .pack.lf -labelwidget .pack.l
    pack .pack.lf -fill both -expand 1
1968
1969
1970
1971
1972
1973
1974
1975

1976
1977

1978
1979
1980
1981
1982
1983
1984
1946
1947
1948
1949
1950
1951
1952

1953
1954

1955
1956
1957
1958
1959
1960
1961
1962







-
+

-
+








test grid-22.1 {remove: basic argument checking} {
    list [catch {grid remove foo} msg] $msg
} {1 {bad window path name "foo"}}
test grid-22.2 {remove} {
    button .c
    grid [button .b]
    set a [grid content .]
    set a [grid slaves .]
    grid remove .b .c
    lappend a [grid content .]
    lappend a [grid slaves .]
    return $a
} {.b {}}
grid_reset 22.2
test grid-22.3 {remove} {
    button .c
    grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx 3 -pady 4 -sticky ns
    grid remove .c
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
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







-
+















-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    # is ignored.
    destroy .a
    grid .c -row 0 -column 0
    grid info .c
} {-in . -column 0 -row 0 -columnspan 2 -rowspan 2 -ipadx 0 -ipady 0 -padx {3 5} -pady {4 7} -sticky ns}
grid_reset 22.5

test grid-23 {grid configure -in leaked from previous container window - bug
test grid-23 {grid configure -in leaked from previous master - bug
              6aea69fccbb266b7f0437686379fbe5b55442958} {
    frame .f
    frame .g
    pack .f .g
    text .t
    grid .t -in .f
    pack forget .f
    update
    grid .t -in .g
    # .t is now managed by .g; following lines must have no effect on .t
    pack .f
    update
    pack forget .f
    update
    winfo ismapped .t ; # must return 1
} 1
} {1}
grid_reset 23

test grid-24.1 {<<NoManagedChild>> fires on last grid forget} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    update
    bind . <<NoManagedChild>> {set A 1}
    grid forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    grid_reset 24.1
} -result 1
test grid-24.2 {<<NoManagedChild>> fires on last grid remove} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    update
    bind . <<NoManagedChild>> {set A 1}
    grid remove .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    grid_reset 24.2
} -result 1
test grid-24.3 {<<NoManagedChild>> fires on last gridded child destruction} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    update
    bind . <<NoManagedChild>> {incr A}
    destroy .1
    update
    set A
} -cleanup {
    bind . <<NoManagedChild>> {}
    grid_reset 24.3
} -result 1
test grid-24.4 {<Configure> does not fire on last grid forget} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    update
    bind . <Configure> {set A 1}
    grid forget .1
    update
    info exists A
} -cleanup {
    bind . <Configure> {}
    grid_reset 24.4
} -result 0
test grid-24.5 {<Configure> fires on forelast grid forget} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    grid [frame .2]
    update
    bind . <Configure> {set A 1}
    grid forget .1
    update
    info exists A
} -cleanup {
    bind . <Configure> {}
    grid_reset 24.5
} -result 1
test grid-24.6 {<<NoManagedChild>> does not fire on forelast grid forget} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    grid [frame .2]
    update
    bind . <<NoManagedChild>> {set A 1}
    grid forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    grid_reset 24.6
} -result 0
test grid-24.7 {<<NoManagedChild>> does not fire on grid anchor} -setup {
    global A
    unset -nocomplain A
} -body {
    bind . <<NoManagedChild>> {set A 1}
    grid anchor . w
    update
    info exists A
} -cleanup {
    grid anchor . nw
    bind . <<NoManagedChild>> {}
    grid_reset 24.7
} -result 0
test grid-24.8 {<<NoManagedChild>> does not fire on last grid forget if propagation is off} -setup {
    global A
    unset -nocomplain A
} -body {
    grid [frame .1]
    grid propagate . 0
    update
    bind . <<NoManagedChild>> {set A 1}
    grid forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    grid_reset 24.8
} -result 0

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:

Deleted tests/iDOT.png.

cannot compute difference between binary files

Changes to tests/image.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test out the "image" command and the
# other procedures in the file tkImage.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

43
44
45
46
47
48
49
50

51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101

102
103
104
105
106
107
108
43
44
45
46
47
48
49

50
51
52

53
54
55
56
57
58
59
60
61
62
63
64

65

66








67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82

83

84

85
86
87
88

89
90
91
92
93
94
95
96







-
+


-
+











-

-

-
-
-
-
-
-
-
-



-
+












-

-
+
-




-
+







    testImageType
} -setup {
    imageCleanup
} -body {
    scan [image create test] image%d first
    image create test myimage
    scan [image create test -variable x] image%d second
    expr {$second-$first}
    expr $second-$first
} -cleanup {
    imageCleanup
} -result 1
} -result {1}

test image-1.7 {Tk_ImageCmd procedure, "create" option} -constraints {
    testImageType
} -setup {
    imageCleanup
} -body {
    image create test myimage -variable x
    .c create image 100 50 -image myimage
    .c create image 100 150 -image myimage
    update
    set x {}
    set timer [after 500 {lappend x "timed out"}]
    image create test myimage -variable x
    update idletasks
    update
    # On MacOS we need to wait for the test image display procedure to run.
    while {"timed out" ni $x && [lindex $x end 1] ne "display"} {
        vwait x
    }
    after cancel timer
    if {[lindex $x end] eq "timed out"} {
       return [lreplace $x end end]
    }
    return $x
} -cleanup {
    imageCleanup
} -result {{myimage free} {myimage free} {myimage delete} {myimage get} {myimage get} {myimage display 0 0 30 15} {myimage display 0 0 30 15}}
} -result {{myimage free} {myimage free} {myimage delete} {myimage get} {myimage get} {myimage display 0 0 30 15 30 30} {myimage display 0 0 30 15 30 130}}
test image-1.8 {Tk_ImageCmd procedure, "create" option} -constraints {
	testImageType
} -setup {
    .c delete all
    imageCleanup
} -body {
    image create test myimage -variable x
    .c create image 100 50 -image myimage
    .c create image 100 150 -image myimage
    image delete myimage
    update
    set x {}
    set timer [after 500 {lappend x "timed out"}]
    image create test myimage -variable x
    vwait x
    update
    after cancel $timer
    return $x
} -cleanup {
    .c delete all
    imageCleanup
} -result {{myimage get} {myimage get} {myimage display 0 0 30 15} {myimage display 0 0 30 15}}
} -result {{myimage get} {myimage get} {myimage display 0 0 30 15 30 30} {myimage display 0 0 30 15 30 130}}
test image-1.9 {Tk_ImageCmd procedure, "create" option} -constraints {
	testImageType
} -body {
    image create test -badName foo
} -returnCodes error -result {bad option name "-badName"}
test image-1.10 {Tk_ImageCmd procedure, "create" option} -constraints {
    testImageType
304
305
306
307
308
309
310
311

312
313
314
315
316



317
318

319
320
321
322
323
324
325
292
293
294
295
296
297
298

299


300
301

302
303
304
305

306
307
308
309
310
311
312
313







-
+
-
-


-
+
+
+

-
+







    image type myimage
} -cleanup {
    .c delete all
    imageCleanup
} -returnCodes error -result {image "myimage" doesn't exist}


test image-6.1 {Tk_ImageCmd procedure, "types" option} -constraints {
test image-6.1 {Tk_ImageCmd procedure, "types" option} -body {
    testImageType
} -body {
    image types x
} -returnCodes error -result {wrong # args: should be "image types"}
test image-6.2 {Tk_ImageCmd procedure, "types" option} -body {
test image-6.2 {Tk_ImageCmd procedure, "types" option} -constraints {
    testImageType
} -body {
    lsort [image types]
} -match glob -result {bitmap*photo test}
} -result {bitmap oldtest photo test}


test image-7.1 {Tk_ImageCmd procedure, "width" option} -body {
    image width
} -returnCodes error -result {wrong # args: should be "image width name"}
test image-7.2 {Tk_ImageCmd procedure, "width" option} -body {
    image width a b
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403


404
405
406
407
408
409
410
340
341
342
343
344
345
346
347
348
349
350
351

352
353
354
355
356

357

358





359
360
361
362

363

364
365
366

367
368
369
370
371
372
373



374

375
376
377
378

379
380
381
382
383
384
385
386
387







+




-





-

-

-
-
-
-
-




-
+
-



-







-
-
-
+
-




-
+
+







    lappend res [image inuse myimage2]
    button .b -image myimage2
    lappend res [image inuse myimage2]
} -cleanup {
    imageCleanup
    catch {destroy .b}
} -result [list 0 1]


test image-9.1 {Tk_ImageChanged procedure} -constraints testImageType -setup {
    .c delete all
    imageCleanup
    update
} -body {
    image create test foo -variable x
    .c create image 50 50 -image foo
    update
    set x {}
    set timer [after 500 {lappend x "timed out"}]
    foo changed 5 6 7 8 30 15
    update idletasks
    update
    # On MacOS we need to wait for the test image display procedure to run.
    while {"timed out" ni $x && [lindex $x end 1] ne "display"} {
        vwait x
    }
    after cancel $timer
    return $x
} -cleanup {
    .c delete all
    imageCleanup
} -result {{foo display 5 6 7 8}}
} -result {{foo display 5 6 7 8 30 30}}

test image-9.2 {Tk_ImageChanged procedure} -constraints testImageType -setup {
    .c delete all
    imageCleanup
    update
} -body {
    image create test foo -variable x
    .c create image 50 50 -image foo
    .c create image 90 100 -image foo
    update
    set x {}
    foo changed 5 6 7 8 30 15
    set timer [after 500 {lappend x "timed out"}]
    image create test myimage -variable x
    vwait x
    update
    after cancel $timer
    return $x
} -cleanup {
    .c delete all
    imageCleanup
} -result {{foo display 5 6 25 9} {foo display 0 0 12 14}}
} -result {{foo display 5 6 25 9 30 30} {foo display 0 0 12 14 65 74}}


test image-10.1 {Tk_GetImage procedure} -setup {
    imageCleanup
} -body {
    .c create image 100 10 -image bad_name
} -cleanup {
    imageCleanup
430
431
432
433
434
435
436
437
438
439

440
441
442
443
444
445

446
447
448
449
450
451
452
407
408
409
410
411
412
413

414

415

416
417
418
419

420
421
422
423
424
425
426
427







-

-
+
-




-
+







    image create test foo -variable x
    .c create image 50 50 -image foo -tags i1
    .c create image 90 100 -image foo -tags i2
    pack forget .c
    update
    set x {}
    .c delete i1
    set timer [after 500 {lappend x "timed out"}]
    pack .c
    vwait x
    update
    after cancel $timer
    list [imageNames] $x
} -cleanup {
    .c delete all
    imageCleanup
} -result {foo {{foo free} {foo display 0 0 30 15}}}
} -result {foo {{foo free} {foo display 0 0 30 15 103 121}}}
test image-11.2 {Tk_FreeImage procedure} -constraints testImageType -setup {
    .c delete all
    imageCleanup
} -body {
    image create test foo -variable x
    .c create image 50 50 -image foo -tags i1
    set names [imageNames]

Changes to tests/imgBmap.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test out images of type "bitmap" (i.e.,
# the procedures in the file tkImgBmap.c).  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit
133
134
135
136
137
138
139
140

141
142
143
144
145
146

147
148
149
150
151

152
153
154
155
156
157

158
159
160
161

162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
133
134
135
136
137
138
139

140
141
142
143
144
145

146
147
148
149
150

151
152
153
154
155
156

157
158
159
160

161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186







-
+





-
+




-
+





-
+



-
+








-
+








-
+







	    [lindex [image1 configure -foreground] 4] \
	    [lindex [image1 configure -background] 4]
} -cleanup {
    image delete image1
} -result {image1 image1 0 0 #000000 {}}


test imageBmap-3.1 {ImgBmapConfigureModel procedure, memory de-allocation} -body {
test imageBmap-3.1 {ImgBmapConfigureMaster procedure, memory de-allocation} -body {
    image create bitmap i1 -data $data1
    i1 configure -data $data1
} -cleanup {
	image delete i1
} -result {}
test imageBmap-3.2 {ImgBmapConfigureModel procedure} -body {
test imageBmap-3.2 {ImgBmapConfigureMaster procedure} -body {
    image create bitmap i1 -data $data1
    list [catch {i1 configure -data bogus} msg] $msg [image width i1] \
	    [image height i1]
} -result {1 {format error in bitmap data} 16 16}
test imageBmap-3.3 {ImgBmapConfigureModel procedure, memory de-allocation} -body {
test imageBmap-3.3 {ImgBmapConfigureMaster procedure, memory de-allocation} -body {
    image create bitmap i1 -data $data1 -maskdata $data2
    i1 configure -maskdata $data2
} -cleanup {
	image delete i1
} -result {}
test imageBmap-3.4 {ImgBmapConfigureModel procedure} -body {
test imageBmap-3.4 {ImgBmapConfigureMaster procedure} -body {
    image create bitmap i1
    i1 configure -maskdata $data2
} -returnCodes error -result {can't have mask without bitmap}
test imageBmap-3.5 {ImgBmapConfigureModel procedure} -body {
test imageBmap-3.5 {ImgBmapConfigureMaster procedure} -body {
    image create bitmap i1 -data $data1 -maskdata {
	#define foo_width 8
	#define foo_height 16
	static char foo_bits[] = {
	   0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
	   0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81};
	}
} -returnCodes error -result {bitmap and mask have different sizes}
test imageBmap-3.6 {ImgBmapConfigureModel procedure} -body {
test imageBmap-3.6 {ImgBmapConfigureMaster procedure} -body {
    image create bitmap i1 -data $data1 -maskdata {
	#define foo_width 16
	#define foo_height 8
	static char foo_bits[] = {
	   0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
	   0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81};
	}
} -returnCodes error -result {bitmap and mask have different sizes}
test imageBmap-3.7 {ImgBmapConfigureModel procedure} -setup {
test imageBmap-3.7 {ImgBmapConfigureMaster procedure} -setup {
    destroy .c
    pack [canvas .c]
} -body {
    image create bitmap i1 -data $data1
    .c create image 100 100 -image i1 -tags i1.1 -anchor nw
    .c create image 200 100 -image i1 -tags i1.2 -anchor nw
    update
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231







-
+







    destroy .c
} -result {}


test imageBmap-5.1 {GetBitmapData procedure} -body {
    list [catch {image create bitmap -file ~bad_user/a/b} msg] \
	    [string tolower $msg]
} -result {1 {couldn't read bitmap file "~bad_user/a/b": no such file or directory}}
} -result {1 {user "bad_user" doesn't exist}}
test imageBmap-5.2 {GetBitmapData procedure} -body {
    list [catch {image create bitmap -file bad_name} msg] [string tolower $msg]
} -result {1 {couldn't read bitmap file "bad_name": no such file or directory}}
test imageBmap-5.3 {GetBitmapData procedure} -setup {imageCleanup} -body {
    image create bitmap -data { }
} -returnCodes error -result {format error in bitmap data}
test imageBmap-5.4 {GetBitmapData procedure} -setup {imageCleanup} -body {
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
362
363
364
365
366
367
368

369
370
371
372
373
374
375
376







-
+







    i1 cget -foreground
} -result {#123456}
test imageBmap-7.5 {ImgBmapCmd procedure, "cget" option} -body {
    i1 cget -stupid
} -returnCodes error -result {unknown option "-stupid"}
test imageBmap-7.6 {ImgBmapCmd procedure} -body {
    llength [i1 configure]
} -result 6
} -result {6}
test imageBmap-7.7 {ImgBmapCmd procedure} -body {
    i1 co -foreground #001122
    i1 configure -foreground
} -result {-foreground {} {} #000000 #001122}
test imageBmap-7.8 {ImgBmapCmd procedure} -body {
    i1 configure -gorp
} -returnCodes error -result {unknown option "-gorp"}
499
500
501
502
503
504
505
506
507


508
509
510
511
512
513
514
515
516
517
518
519
520
499
500
501
502
503
504
505


506
507
508
509
510
511
512
513
514
515
516
517
518
519
520







-
-
+
+













    lappend x [info command new*]
} -result {{} newi2 foo.bm {}}


test imageBmap-12.1 {ImgBmapCmdDeletedProc procedure} -body {
    image create bitmap i2 -file foo.bm -maskfile foo2.bm
    rename i2 {}
    list [expr {"i2" in [imageNames]}] [catch {i2 foo} msg] $msg
} -result {0 1 {invalid command name "i2"}}
    list [lsearch -exact [imageNames] i2] [catch {i2 foo} msg] $msg
} -result {-1 1 {invalid command name "i2"}}

removeFile foo.bm
removeFile foo2.bm
imageFinish

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to tests/imgListFormat.test.

1
2
3
4
5

6
7
8
9
10
11
12
1
2
3
4

5
6
7
8
9
10
11
12




-
+







# This file is a Tcl script to test out the default image data format
# ("list format") implementend in the file tkImgListFormat.c.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 2017 Simon Bachmann
# Copyright (c) 2017 Simon Bachmann
# All rights reserved.
#
# Author: Simon Bachmann ([email protected])

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+







    imageCleanup
} -returnCodes error -result \
    {bad format option "-colorformat": no options allowed}
test imgListFormat-1.5 {ParseFormatOptions: no -colorformat value} -setup {
    image create photo photo1 -data black
} -body {
    photo1 data -format {default -colorformat}
} -returnCodes error -result {the "-colorformat" option requires a value}
} -returnCodes error -result {the "-colorformat" option requires a value}     
test imgListFormat-1.6 {ParseFormatOptions: bad -colorformat val #1} -setup {
    image create photo photo1
} -body {
    photo1 put yellow
    photo1 data -format {default -colorformat bogus}
} -cleanup {
    imageCleanup
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122

123
124
125
126


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147

148
149
150
151
152
153
154
155
156


157
158
159
160
161
162
163
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121

122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146

147
148
149
150
151
152
153
154


155
156
157
158
159
160
161
162
163







-
+









-
+


-
-
+
+















-
+




-
+







-
-
+
+







    set result
} -cleanup {
    imageCleanup
    unset result
} -result {{{#ffffff}} {{#ffffff78}} {{{255 255 255 120}}}}

# GetBadOptMsg: only use case already tested with imgListFormat-1.4

    
test imgListFormat-3.1 {StringMatchDef: data is not a list} -body {
    testphotostringmatch {not a " proper list}
    # " (this comment is here only for editor highlighting)
} -returnCodes error -result {unmatched open quote in list}
# empty data case tested with imgPhoto-4.95 (imgPhoto.test)
test imgListFormat-3.2 {StringMatchDef: \
        list element not a proper list} -body {
    testphotostringmatch {{red white} {not "} {blue green}}
    # "
} -returnCodes error -result {unmatched open quote in list}
} -returnCodes error -result {unmatched open quote in list} 
test imgListFormat-3.3 {StringMatchDef: \
        sublists with differen lengths} -body {
    testphotostringmatch {{#001122 #334455 #667788}
		{#99AABB #CCDDEE}
    testphotostringmatch {{#001122 #334455 #667788} 
		{#99AABB #CCDDEE} 
		{#FF0011 #223344 #556677}}
} -returnCodes error -result \
    {invalid row # 1: all rows must have the same number of elements}
test imgListFormat-3.4 {StringMatchDef: base64 data is not parsed as valid \
} -setup {
    image create photo photo1
} -body {
    photo1 put {
	iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCA
	YAAAEFsT2yAAAABGdBTUEAAYagMeiWXwAA
	ABdJREFUCJkFwQEBAAAAgiD6P9pACRoqDk
	fUBvt1wUFKAAAAAElFTkSuQmCC
    } -format default
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCA"}
} -returnCodes error -result {couldn't recognize image data}
test imgListFormat-3.5 {StringMatchDef: valid data} -setup {
    image create photo photo1
} -body {
    photo1 put {{blue green}
		{yellow magenta}
		{yellow magenta} 
	        {#000000 #FFFFFFFF}}
    list [image width photo1] [image height photo1] \
	[photo1 get 0 2 -withalpha]
} -cleanup {
    imageCleanup
} -result {2 3 {0 0 0 255}}

# ImgStringRead: most of the error cases cannot be tested with current code,
# as the errors are detected by StringMatchDef
# ImgStringRead: most of the error cases cannot be tested with current code, 
# as the errors are detected by StringMatchDef	
test imgListFormat-4.1 {StringReadDef: use with -format opt} -setup {
    image create photo photo1
} -body {
    photo1 put white -format "default"
    photo1 get 0 0
} -cleanup {
    imageCleanup
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+







} -body {
    set imgData [photo1 data]
    photo2 put $imgData
    string equal [photo1 data] [photo2 data]
} -cleanup {
    imageCleanup
    unset imgData
} -result 1
} -result {1}
test imgListFormat-4.5 {StringReadDef: correct compositing rule} -constraints {
    hasTranspTeapotPhoto
} -setup {
    image create photo photo1 -file $transpTeapotPhotoFile
    image create photo photo2
} -body {
    photo2 put #FF0000 -to 0 0 50 50
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283







-
+


















-
+







    set imgData [photo1 data]
    # note: with [lindex], the coords are inverted (y x)
    lappend result [lindex $imgData 0 0]
    lappend result [lindex $imgData 3 2]
    lappend result [lindex $imgData 107 53]
    lappend result [lindex $imgData 203 157]
    lappend result [lindex $imgData 255 255]
    set result
    set result 
} -cleanup {
    unset result
    unset imgData
    imageCleanup
} -result {{#135cc0} #135cc0 #a06d52 #e1c8ba #135cc0}
test imgListFormat-5.7 {StringWriteDef: test some pixels #2} -constraints {
    hasTeapotPhoto
} -setup {
    set result {}
    image create photo photo1 -file $teapotPhotoFile
} -body {
    set imgData [photo1 data -format {default -colorformat rgba}]
    # note: with [lindex], the coords are inverted (y x)
    lappend result [lindex $imgData 0 0]
    lappend result [lindex $imgData 3 2]
    lappend result [lindex $imgData 107 53]
    lappend result [lindex $imgData 203 157]
    lappend result [lindex $imgData 255 255]
    set result
    set result 
} -cleanup {
    unset result
    unset imgData
    imageCleanup
} -result {{#135cc0ff} #135cc0ff #a06d52ff #e1c8baff #135cc0ff}
test imgListFormat-5.8 {StringWriteDef: test some pixels #3} -constraints {
    hasTranspTeapotPhoto
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377







-
+







test imgListFormat-6.4 {ParseColor: #XXX color, different forms} -setup {
    image create photo photo1
} -body {
    photo1 put {{#A123 #334455} {#012 #fffefd#00}}
    photo1 data -format {default -colorformat rgba}
} -cleanup {
    imageCleanup
} -result {{#aa112233 #334455ff} {#001122ff #fffefd00}}
} -result {{#aa112233 #334455ff} {#001122ff #fffefd00}}        
test imgListFormat-6.5 {ParseColor: list format} -setup {
    image create photo photo1
} -body {
    photo1 put [list [list [list 255 255 255]]]
    photo1 get 0 0 -withalpha
} -cleanup {
    imageCleanup
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512







-
+







test imgListFormat-8.1 {ParseColorAsHex: RGB format} -setup {
    image create photo photo1
} -body {
    photo1 put {{#010 #001100}}
    photo1 data
} -cleanup {
    imageCleanup
} -result {{#001100 #001100}}
} -result {{#001100 #001100}}        
test imgListFormat-8.2 {ParseColorAsHex: invalid hex digit} -setup {
    image create photo photo1
} -body {
    photo1 put {#ABCD #ABCZ}
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "#ABCZ"}
525
526
527
528
529
530
531
532

533
534
535
536
537
538
539
525
526
527
528
529
530
531

532
533
534
535
536
537
538
539







-
+







    list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha]
} -cleanup {
    imageCleanup
} -result {{155 213 2 13} {119 170 204 255}}

test imgListFormat-9.1 {ParseColorAsStandard:
        Tk color, valid suffixes} -setup {
    image create photo photo1
    image create photo photo1 
    set result {}
} -body {
    photo1 put {{[email protected] #114433#C} {#8D4#1A magenta}}
    lappend result [photo1 get 0 0 -withalpha]
    lappend result [photo1 get 1 0 -withalpha]
    lappend result [photo1 get 0 1 -withalpha]
    lappend result [photo1 get 1 1 -withalpha]
567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581







-
+







} -body {
    photo1 put {{[email protected] blue@bogus}}
} -cleanup {
    imageCleanup
} -returnCodes error -result \
    {invalid alpha suffix "@bogus": expected floating-point value}
test imgListFormat-9.5 {ParseColorAsStandard: @A, value too low} -setup {
    image create photo photo1
    image create photo photo1 
} -body {
    photo1 put {[email protected] [email protected]}
} -cleanup {
    imageCleanup
} -returnCodes error -result \
    {invalid alpha suffix "@-0.1": value must be in the range from 0 to 1}
test imgListFormat-9.6 {ParseColorAsStandard: @A, value too high} -setup {

Changes to tests/imgPNG.test.

1
2
3
4
5
6
7
8




9
10
11
12
13
14
15
1
2
3
4




5
6
7
8
9
10
11
12
13
14
15




-
-
-
-
+
+
+
+







# This file is a Tcl script to test out the code in tkImgFmtPNG.c, which reads
# and write PNG-format image files for photo widgets. The files is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 1998 Willem van Schaik (images only)
# Copyright © 2008 Donal K. Fellows
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 1998 Willem van Schaik (images only)
# Copyright (c) 2008 Donal K. Fellows
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1052
1053
1054
1055
1056
1057
1058




1059
1060
1061
1062
1063
1064
1065
1066







-
-
-
-
+







PmSgZc0hPNhvYAruYN27V8n2gtXV8fOShnq5O9t+492kG9n2LQv65KWAaWAMUDPhEaG0oIFyOMgkhy
YOaz2HKRVHc4lqQbf3LMisUrWjrl9XhhBCkwnWnNLiFDVCParR5BeeRJE47aungOASE1gueu+OTh76
0dt3Gzx47dvzRUnHNQ8Cf2yQZE7mg+XtslqVWi5XocjlDu7K0pgS+dfbs2V8tFotPlUqlr+ZyuXNO+
duFtaSrZF3pfCpiGjN2imToJJ39m6BjG1XZRwrkAI8YUKSZWlEZQDAIrNArHnyvpXtmM/B7wJeAbwO
fBcxKuQMrzfLdBoz29fX9led5v6u1XnBJW7vnr/YlrXEoNo22LRYOYlxZ1S6rkOfDcLvPAY/hGmWC7
H68uFI+x0oSPg2MAN/L5/M/vtqSED/T5cMu9J4Wf7HMGsB/4TEv/DFwe3Y/NPN57VXh+5BWApwFLlh
r661tV1eju/ne8YJrkWtES0tmRe2VOviv2j2aBp5nHihiRaz/A4oCnsAsje/+AAAAAElFTkSuQmCC"
    dpi100aspect2
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAA9hAAAewgEw8YEEAAAA
FklEQVR4nGP4+vXrP11lJgYGhj9xSQAzOwXsETZ69QAAAABJRU5ErkJggg=="
	}
    }

# $encoded(basn0g08), $encoded(basn2c08), $encoded(basn3p08), $encoded(basn6a08)
test imgPNG-1.1 {reading basic images; grayscale} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $encoded(basn0g08)
    list [image width foo] [image height foo]
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1099
1100
1101
1102
1103
1104
1105

1106











1107














































1108
1109
1110
1111
1112
1113
1114
1115
1116







-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









    set i [image create photo]
} -body {
    $i put $encoded(MultiIDAT)
    return [image width $i]x[image height $i]
} -cleanup {
    image delete $i
} -result 223x212


test imgPNG-3.1 {reading image with unknown ancillary chunk - bug [1c659ef0f1]} -setup {
    set fileName [file join [file dirname [info script]] iDOT.png]
} -body {
    # the image contains an unknown chunk iDOT
    # since the name of this chunk starts with a lowercase letter,
    # it's an ancillary chunk that shall not trigger an error
    catch {set i [image create photo -file $fileName]}
} -cleanup {
    image delete $i
} -result 0

}
test imgPNG-4.1 {data image with metadata} -body {
    image create photo i1 -data $encoded(dpi100aspect2)
    i1 cget -metadata
} -cleanup {
    image delete i1
} -result {DPI 99.9998 aspect 2.0}

test imgPNG-4.2 {file image with metadata} -setup {
    set path [file join [configure -tmpdir] test.png]
    set h [open $path "WRONLY BINARY CREAT"]
    puts -nonewline $h [binary decode base64 $encoded(dpi100aspect2)]
    close $h
} -body {
    image create photo i1 -file $path
    i1 cget -metadata
} -cleanup {
    image delete i1
    file delete $path
} -result {DPI 99.9998 aspect 2.0}

test imgPNG-4.3 {data output with metadata} -setup {
    image create photo i1 -data $encoded(dpi100aspect2)
} -body {
    set imgData [i1 data -format png]
    image delete i1
    image create photo i1 -data $imgData
    i1 cget -metadata
} -cleanup {
    image delete i1
} -result {DPI 99.9998 aspect 2.0}

test imgPNG-4.4 {file output with metadata} -setup {
    image create photo i1 -data $encoded(dpi100aspect2)
    set path [file join [configure -tmpdir] test.png]
} -body {
    i1 write $path -format png
    image delete i1
    image create photo i1 -file $path
    i1 cget -metadata
} -cleanup {
    image delete i1
    file delete $path
} -result {DPI 99.9998 aspect 2.0}

}

namespace delete png
imageFinish
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to tests/imgPPM.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4


5
6
7
8
9
10
11
12
13




-
-
+
+







# This file is a Tcl script to test out the code in tkImgFmtPPM.c,
# which reads and write PPM-format image files for photo widgets.
# The files is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Changes to tests/imgPhoto.test.

1
2
3
4
5
6
7
8




9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55






56
57
58
59
60
61
62
1
2
3
4




5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


54
55
56
57
58
59
60
61
62
63
64
65
66




-
-
-
-
+
+
+
+















-
+










-
+


















-
-
+
+
+
+
+
+







# This file is a Tcl script to test out the "photo" image type and the other
# procedures in the file tkImgPhoto.c. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1994 The Australian National University
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2002-2008 Donal K. Fellows
# Copyright (c) 1994 The Australian National University
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2002-2008 Donal K. Fellows
# All rights reserved.
#
# Author: Paul Mackerras ([email protected])

#
# This file is somewhat caothic: the order of the tests does not
# really follow the order of the corresponding functions in
# tkImgPhoto.c. Probably, because early versions had only a few tests
# and over time test cases were added in bits and pieces.
# To be noted, also, that this file is not complete: large portions of
# code in tkImgPhoto.c have no test coverage.
#
# To help keeping the overview, the table below lists where to find
# tests for each of the functions in tkImgPhoto.c. The function are
# listed in the order as they appear in the source file.
#
# 

#
# Function name                         Tests for function
#--------------------------------------------------------------------------
# PhotoFormatThreadExitProc             no tests
# Tk_Create*PhotoImageFormat            no tests
# ImgPhotoCreate                        imgPhoto-2.*
# ImgPhotoCmd                           imgPhoto-4.*, imgPhoto-17.*
# GetExtension:                         no tests
# ParseSubcommandOptions:               imgPhoto-1.*
# ImgPhotoConfigureModel:              imgPhoto-3.*, imgPhoto-15.*
# ImgPhotoConfigureMaster:              imgPhoto-3.*, imgPhoto-15.*
# toggleComplexAlphaIfNeeded:           no tests
# ImgPhotoDelete:                       imgPhoto-8.*
# ImgPhotoCmdDeleteProc:                imgPhoto-9.*
# ImgPhotoSetSize:                      no tests
# MatchFileFormat:                      imgPhoto-18.*
# MatchSringFormat:                     imgPhoto-19.*
# Tk_FindPhoto:                         imgPhoto-11.*
# Tk_PhotoPutBlock:                     imgPhoto-10.*, imgPhoto-16.*
# Tk_PhotoPutZoomedBlock:               imgPhoto-12.*
# Tk_DitherPhoto:                       no tets
# Tk_PhotoBlank:                        no tests
# Tk_PhotoExpand:                       no tests
# Tk_PhotoGetSize:                      no tests
# Tk_PhotoSetSize:                      no tests
# TkGetPhotoValidRegion:                no tests
# ImgGetPhoto:                          no tests
# Tk_PhotoGetImage                      no tests
# ImgPostscriptPhoto                    no tests
# Tk_PhotoGetMetadata:                  imgPhoto-21.*
# Tk_PhotoSetMetadata:                  imgPhoto-22.*
# Tk_PhotoPutBlock_NoComposite          no tests, probably none needed
# Tk_PhotoPutZoomedBlock_NoComposite    no tests, probably none needed
# Tk_PhotoExpand_Panic                  no tests, probably none needed
# Tk_PhotoPutBlock_Panic                no tests, probably none needed
# Tk_PhotoPutZoomedBlock_Panic          no tests, probably none needed
# Tk_PhotoSetSize_Panic                 no tests, probably none needed
#--------------------------------------------------------------------------
#

#
# Some tests are not specific to a function in tkImgPhoto.c. They are:
#

74
75
76
77
78
79
80
81
82


83
84
85
86
87
88
89
78
79
80
81
82
83
84


85
86
87
88
89
90
91
92
93







-
-
+
+







#                       - which does not exist.
#

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

#

# 
# Used for imgPhoto-4.65 - imgPhoto-4.73
#
proc foreachPixel {img xVar yVar script} {
    upvar 1 $xVar x $yVar y
    set width [image width $img]
    set height [image height $img]
    for {set x 0} {$x<$width} {incr x} {
121
122
123
124
125
126
127
128
129


130
131
132
133
134
135
136
125
126
127
128
129
130
131


132
133
134
135
136
137
138
139
140







-
-
+
+








# find the teapot.ppm file for use in these tests
set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm]
testConstraint hasTeapotPhoto [file exists $teapotPhotoFile]
# let's see if we have the semi-transparent one as well
set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png]
testConstraint hasTranspTeapotPhoto [file exists $transpTeapotPhotoFile]
testConstraint needsTcl867 [package vsatisfies [package provide Tcl] 8.6.7-]


# ----------------------------------------------------------------------

test imgPhoto-1.1 {options for photo images} -body {
    image create photo photo1 -width 79 -height 83
    list [photo1 cget -width] [photo1 cget -height] \
	[image width photo1] [image height photo1]
} -cleanup {
    image delete photo1
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198



199
200
201
202
203
204
205







-
+








-
-
-







test imgPhoto-1.12 {option -alpha, normal use} -setup {
    image create photo photo1
} -body {
    photo1 put "white" -to 0 0
    photo1 transparency get 0 0 -alpha
} -cleanup {
    imageCleanup
} -result 255
} -result {255}
test imgPhoto-1.13 {option -withalpha, normal use} -setup {
    image create photo photo1
} -body {
    photo1 put {{blue green}}
    photo1 get 1 0 -withalpha
} -cleanup {
    imageCleanup
} -result {0 128 0 255}
test imgPhoto-1.14 {options for photo images - error case} -body {
    image create photo photo1 -metadata
} -returnCodes error -result {value for "-metadata" missing}

test imgPhoto-2.1 {ImgPhotoCreate procedure} -setup {
    imageCleanup
} -body {
    catch {image create photo -blah blah}
    imageNames
} -result {}
214
215
216
217
218
219
220
221
222


223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270


271
272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
215
216
217
218
219
220
221


222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268



269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287







-
-
+
+







-
+








-
+

















-
+










-
-
-
+
+









-
+







# test imgPhoto-2.3 {ImgPhotoCreate procedure: creation failure} {
#     image create photo photo1
#     image create photo photo2 -width 10 -height 10
#     catch {image create photo photo2 -file bogus.img} msg
#     photo1 copy photo2
#     set msg
# } {couldn't open "bogus.img": no such file or directory}

test imgPhoto-3.1 {ImgPhotoConfigureModel procedure} -constraints {

test imgPhoto-3.1 {ImgPhotoConfigureMaster procedure} -constraints {
    hasTeapotPhoto
} -body {
    image create photo photo1 -file $teapotPhotoFile
    photo1 configure -file $teapotPhotoFile
} -cleanup {
    image delete photo1
} -result {}
test imgPhoto-3.2 {ImgPhotoConfigureModel procedure} -constraints {
test imgPhoto-3.2 {ImgPhotoConfigureMaster procedure} -constraints {
    hasTeapotPhoto
} -body {
    image create photo photo1 -file $teapotPhotoFile
    list [catch {photo1 configure -file bogus} err] [string tolower $err] \
	[image width photo1] [image height photo1]
} -cleanup {
    image delete photo1
} -result {1 {couldn't open "bogus": no such file or directory} 256 256}
test imgPhoto-3.3 {ImgPhotoConfigureModel procedure} -constraints {
test imgPhoto-3.3 {ImgPhotoConfigureMaster procedure} -constraints {
    hasTeapotPhoto
} -setup {
    destroy .c
    pack [canvas .c]
    update
} -body {
    image create photo photo1
    .c create image 10 10 -image photo1 -tags photo1.1 -anchor nw
    .c create image 300 10 -image photo1 -tags photo1.2 -anchor nw
    update
    photo1 configure -file $teapotPhotoFile
    update
    list [image width photo1] [image height photo1] [.c bbox photo1.1] [.c bbox photo1.2]
} -cleanup {
    destroy .c
    image delete photo1
} -result {256 256 {10 10 266 266} {300 10 556 266}}
test imgPhoto-3.4 {ImgPhotoConfigureModel: -data <ppm>} -constraints {
test imgPhoto-3.4 {ImgPhotoConfigureMaster: -data <ppm>} -constraints {
    hasTeapotPhoto
} -setup {
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2
} -body {
    photo2 configure -data [photo1 data -format ppm -from 100 100 120 120]
    list [image width photo2] [image height photo2]
} -cleanup {
    imageCleanup
} -result {20 20}
# This testcase fails with Tcl < 8.6.7, due to [25842c]
test imgPhoto-3.5 {ImgPhotoConfigureModel: -data <png>} -constraints {
    hasTeapotPhoto needsTcl867
test imgPhoto-3.5 {ImgPhotoConfigureMaster: -data <png>} -constraints {
    hasTeapotPhoto
} -setup {
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2
} -body {
    photo2 configure -data [photo1 data -format png -from 120 120 140 140]
    list [image width photo2] [image height photo2]
} -cleanup {
    imageCleanup
} -result {20 20}
test imgPhoto-3.6 {ImgPhotoConfigureModel: -data <default>} -constraints {
test imgPhoto-3.6 {ImgPhotoConfigureMaster: -data <default>} -constraints {
    hasTeapotPhoto
} -setup {
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2
} -body {
    photo2 configure -data [photo1 data -from 80 90 100 110]
    list [image width photo2] [image height photo2]
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341







-
+







} -result {25 30}
test imgPhoto-4.6 {ImgPhotoCmd procedure: configure option} -setup {
    image create photo photo1
} -body {
    llength [photo1 configure]
} -cleanup {
    image delete photo1
} -result 8
} -result 7
test imgPhoto-4.7 {ImgPhotoCmd procedure: configure option} -setup {
    image create photo photo1
} -body {
    photo1 conf -palette 3/4/2
    photo1 configure -palette
} -cleanup {
    image delete photo1
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546

547
548
549
550
551
552
553
532
533
534
535
536
537
538

539
540
541
542
543
544
545

546
547
548
549
550
551
552
553







-
+






-
+







} -result {wrong # args: should be "photo1 put data ?-option value ...?"}
test imgPhoto-4.27 {ImgPhotoCmd procedure: put option} -setup {
    image create photo photo1
} -body {
    photo1 put {{white} {white white}}
} -returnCodes error -cleanup {
    image delete photo1
} -result {invalid row # 1: all rows must have the same number of elements}
} -result {couldn't recognize image data}
test imgPhoto-4.28 {ImgPhotoCmd procedure: put option} -setup {
    image create photo photo1
} -body {
    photo1 put {{blahgle}}
} -cleanup {
    image delete photo1
} -returnCodes error -result {invalid color name "blahgle"}
} -returnCodes error -result {couldn't recognize image data}
test imgPhoto-4.29 {ImgPhotoCmd procedure: put option} -setup {
    image create photo photo1
} -body {
    # SB: odd thing - this test passed with tk 8.6.6, even if the data
    # is in the wrong position:
    #photo1 put -to 10 10 20 20 {{white}}

569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583







-
+







    hasTeapotPhoto
} -setup {
    image create photo photo1
} -body {
    photo1 read $teapotPhotoFile -zoom 2
} -returnCodes error -cleanup {
    image delete photo1
} -result {unrecognized option "-zoom": must be -format, -from, -metadata, -shrink, or -to}
} -result {unrecognized option "-zoom": must be -format, -from, -shrink, or -to}
test imgPhoto-4.32 {ImgPhotoCmd procedure: read option} -setup {
    image create photo photo1
} -body {
    list [catch {photo1 read bogus} err] [string tolower $err]
} -cleanup {
    image delete photo1
} -result {1 {couldn't open "bogus": no such file or directory}}
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968

969
970
971
972
973
974
975
949
950
951
952
953
954
955













956
957
958
959
960
961
962
963







-
-
-
-
-
-
-
-
-
-
-
-
-
+







    file copy -force $teapotPhotoFile -teapotPhotoFile
    image create photo photo1
    photo1 read -teapotPhotoFile
} -cleanup {
    image delete photo1
    file delete ./-teapotPhotoFile
} -result {}
test imgPhoto-4.75.1 {ImgPhotoCmd procedure: copy to same image} -constraints {
    hasTeapotPhoto
} -setup {
    imageCleanup
    image create photo photo1 -file $teapotPhotoFile
} -body {
    # non-regression test for bug [5239fd749b] - shall just not crash
    photo1 copy photo1 -to 0 0 2000 1000
    photo1 copy photo1 -subsample 2 2 -shrink
} -cleanup {
    imageCleanup
} -result {}
test imgPhoto-4.76 {ImgPhotoCmd, transparency get: too many options} -setup {
test imgPhoto-4.76 {ImgPhotoCmd, transparancy get: too many options} -setup {
    image create photo photo1
} -body {
    photo1 put white -to 0 0 1 1
    photo1 transparency get 0 0 -alpha -bogus
} -cleanup {
    imageCleanup
} -returnCodes error -result \
1070
1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099

1100
1101
1102
1103
1104
1105
1106
1058
1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1094







-
+















-
+





-
+







    imageCleanup
} -result {255 0}
# deleted: test imgPhoto-4.88 {ImgPhotoCmd, transparency set: -boolean}
test imgPhoto-4.89 {ImgPhotoCmd, transparency set: -alpha} -setup {
    image create photo photo1
} -body {
    photo1 put white -to 0 0 2 2
    photo1 transparency set 0 0 0 -alpha
    photo1 transparency set 0 0 0 -alpha 
    photo1 transparency set 1 0 1 -alpha
    photo1 transparency set 0 1 254 -alpha
    photo1 transparency set 1 1 255 -alpha
    list [photo1 transparency get 0 0] [photo1 transparency get 1 0] \
	[photo1 transparency get 0 1] [photo1 transparency get 1 1]
} -cleanup {
    imageCleanup
} -result {1 0 0 0}
test imgPhoto-4.90 {ImgPhotoCmd put: existing but not allowed opt} -setup {
    image create photo photo1
} -body {
    photo1 put yellow -from 0 0 1 1
} -cleanup {
    imageCleanup
} -returnCodes error -result \
    {unrecognized option "-from": must be -format, -metadata, or -to}
    {unrecognized option "-from": must be -format, or -to}
test imgPhoto-4.91 {ImgPhotoCmd put: invalid option} -setup {
    image create photo photo1
} -body {
    photo1 put {{0 1 2 3}} -bogus x
} -returnCodes error -result \
    {unrecognized option "-bogus": must be -format, -metadata, or -to}
    {unrecognized option "-bogus": must be -format, or -to}
test imgPhoto-4.92 {ImgPhotocmd put: missing data} -setup {
    image create photo photo1
} -body {
    photo1 put -to 0 0
} -returnCodes error -result \
    {wrong # args: should be "photo1 put data ?-option value ...?"}
test imgPhoto-4.93 {ImgPhotoCmd put: data in ppm format} -constraints {
1139
1140
1141
1142
1143
1144
1145
1146

1147
1148
1149
1150
1151
1152
1153
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1141







-
+







test imgPhoto-4.95 {ImgPhotoCmd put: default fmt, invalid data} -setup {
    image create photo photo1
} -body {
    photo1 put {{red green blue} {red " blue}}
    #"
} -cleanup {
    imageCleanup
} -returnCodes error -result {unmatched open quote in list}
} -returnCodes error -result {couldn't recognize image data}
test imgPhoto-4.96 {ImgPhotoCmd put: "default" handler is selected} -setup {
    image create photo photo1
    image create photo photo2
    set imgData {{{1 2 3 4} {5 6 7 8} {9 10 11 12}}
        {{13 14 15 15} {17 18 19 20} {21 22 23 24}}}
} -body {
    photo1 put $imgData
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203







-
+







} -body {
    photo1 put {{brown blue} {cyan coral}}
    set imgData [photo1 data]
    photo1 put {}
    string equal $imgData [photo1 data]
} -cleanup {
    imageCleanup
} -result 1
} -result {1}
test imgPhoto-4.101 {ImgPhotoCmd get: too many args} -setup {
    image create photo photo1
} -body {
    photo1 get 0 0 -withalpha bogus
} -cleanup {
    imageCleanup
} -returnCodes error -result \
1232
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247

1248
1249

1250
1251
1252
1253
1254
1255
1256
1220
1221
1222
1223
1224
1225
1226

1227
1228
1229
1230
1231
1232
1233
1234

1235
1236

1237
1238
1239
1240
1241
1242
1243
1244







-
+







-
+

-
+







test imgPhoto-4.104 {ImgPhotoCmd data: existing but not accepted opt} -setup {
    image create photo photo1
} -body {
    photo1 data -to
} -cleanup {
    imageCleanup
} -returnCodes error -result \
{unrecognized option "-to": must be -background, -format, -from, -grayscale, or -metadata}
{unrecognized option "-to": must be -background, -format, -from, or -grayscale}
test imgPhoto-4.105 {ImgPhotoCmd data: invalid option} -setup {
    image create photo photo1
} -body {
    photo1 data -bogus
} -cleanup {
    imageCleanup
} -returnCodes error -result \
{unrecognized option "-bogus": must be -background, -format, -from, -grayscale, or -metadata}
{unrecognized option "-bogus": must be -background, -format, -from, or -grayscale}
test imgPhoto-4.106 {ImgPhotoCmd data: extra arg before options} -setup {
    image create photo photo1
    image create photo photo1 
} -body {
    photo1 data bogus -grayscale
} -cleanup {
    imageCleanup
} -returnCodes error -result \
    {wrong # args: should be "photo1 data ?-option value ...?"}
test imgPhoto-4.107 {ImgPhotoCmd data: extra arg after options} -setup {
1330
1331
1332
1333
1334
1335
1336
1337
1338

1339
1340


1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1318
1319
1320
1321
1322
1323
1324


1325
1326

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341
1342
1343
1344







-
-
+

-
+
+








-
+







    photo1 data -format {default -colorformat rgba}
} -result {{#ff0000ff #008000ff} {#0000ffff #ffffffff}}
test imgPhoto-4.117 {ImgPhotoCmd data: list colorformat} -setup {
    image create photo photo1 -data {{red#a green} {blue#c white#d}}
} -body {
    photo1 data -format {default -colorformat list}
} -result {{{255 0 0 170} {0 128 0 255}} {{0 0 255 204} {255 255 255 221}}}
# This testcase fails with Tcl < 8.6.7, due to [25842c]
test imgPhoto-4.118 {ImgPhotoCmd data: using data for new image
test imgPhoto-4.118 {ImgPhotoCmd data: using data for new image 
    results in same image as orignial } -constraints {
        hasTeapotPhoto hasTranspTeapotPhoto needsTcl867
        hasTeapotPhoto
        hasTranspTeapotPhoto
} -setup {
    image create photo teapot -file $teapotPhotoFile
    teapot copy teapot -from 50 60 70 80 -shrink
    image create photo teapotTransp -file $transpTeapotPhotoFile
    teapotTransp copy teapotTransp -from 100 110 120 130 -shrink
    image create photo photo1
} -body {
    set result {}
    # We don't test gif here, as there seems to be a problem with
    # We don't test gif here, as there seems to be a problem with 
    # <imgName> data and gif format ("too many colors", probably a bug)
    foreach fmt {ppm png {default -colorformat rgba} \
            {default -colorformat list}} {
        set imgData [teapotTransp data -format $fmt]
        photo1 blank
        photo1 put $imgData
        if { ! [string equal [photo1 data] [teapotTransp data]]} {
1388
1389
1390
1391
1392
1393
1394
1395

1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409

1410
1411
1412
1413
1414
1415
1416
1376
1377
1378
1379
1380
1381
1382

1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404







-
+













-
+







    .c delete i1.2
    photo1 configure -height 1
    update
    image delete photo1
} -cleanup {
    destroy .c
} -result {}


test imgPhoto-6.1 {ImgPhotoDisplay procedure, blank display} -setup {
    destroy .c
    pack [canvas .c]
    imageCleanup
} -body {
    image create photo photo1 -width 10 -height 10
    photo1 blank
    .c create image 10 10 -image photo1
    update
} -cleanup {
    destroy .c
    image delete photo1
} -result {}


test imgPhoto-7.1 {ImgPhotoFree procedure, resource freeing} -constraints {
    hasTeapotPhoto
} -setup {
    destroy .c
    pack [canvas .c]
    imageCleanup
} -body {
1463
1464
1465
1466
1467
1468
1469
1470

1471
1472
1473
1474
1475
1476
1477
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465







-
+







    destroy .b1
    update
    .f.b2 configure -image {}
    update
    destroy .f
    image delete photo1
} -result {}


test imgPhoto-8.1 {ImgPhotoDelete procedure} -constraints hasTeapotPhoto -body {
    image create photo photo2 -file $teapotPhotoFile
    image delete photo2
} -result {}
test imgPhoto-8.2 {ImgPhotoDelete procedure} -constraints {
    hasTeapotPhoto
} -setup {
1487
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502



1503
1504
1505
1506
1507
1508
1509
1475
1476
1477
1478
1479
1480
1481

1482
1483
1484
1485
1486
1487



1488
1489
1490
1491
1492
1493
1494
1495
1496
1497







-
+





-
-
-
+
+
+







    image create photo photo1
    image create photo photo2 -width 10 -height 10
    image delete photo2
    photo1 copy photo2
} -returnCodes error -cleanup {
    imageCleanup
} -result {image "photo2" doesn't exist or is not a photo image}


test imgPhoto-9.1 {ImgPhotoCmdDeletedProc procedure} -constraints {
    hasTeapotPhoto
} -body {
    image create photo photo2 -file $teapotPhotoFile
    rename photo2 {}
    list [expr {"photo2" in [imageNames]}] [catch {photo2 foo} msg] $msg
} -result {0 1 {invalid command name "photo2"}}

    list [lsearch -exact [imageNames] photo2] [catch {photo2 foo} msg] $msg
} -result {-1 1 {invalid command name "photo2"}}

test imgPhoto-10.1 {Tk_ImgPhotoPutBlock procedure} -setup {
    imageCleanup
} -body {
    image create photo photo1
    photo1 put "{#ff0000 #ff0000 #ff0000 #ff0000 #ff0000 #ff0000 #ff0000 #ff0000}" -to 0 0
    photo1 put "{#00ff00 #00ff00}" -to 2 0
    list [photo1 get 2 0] [photo1 get 3 0] [photo1 get 4 0]
1517
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542
1543
1544
1545
1546
1547

1548
1549
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560
1561
1562
1563
1564
1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553







-
+













-
+









+









-
+







    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2 -file $teapotPhotoFile
    photo2 copy photo1 -to 1 2
    photo1 copy photo1 -to 1 2
    string equal [photo1 data] [photo2 data]
} -cleanup {
    imageCleanup
} -result 1
} -result {1}
test imgPhoto-10.3 {Tk_ImgPhotoPutBlock, same source and dest img} -constraints {
    hasTeapotPhoto
} -setup {
    imageCleanup
} -body {
    # Test for bug e4336bef5d
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2 -file $teapotPhotoFile
    photo2 copy photo1 -from 2 1 -to 4 5 300 300
    photo1 copy photo1 -from 2 1 -to 4 5 300 300
    string equal [photo1 data] [photo2 data]
} -cleanup {
    imageCleanup
} -result 1
} -result {1}
test imgPhoto-10.4 {Tk_ImgPhotoPutBlock, empty image} -setup {
    imageCleanup
} -body {
    image create photo photo1
    photo1 copy photo1 -to 0 5 10 20
    list [image width photo1] [image height photo1]
} -cleanup {
    imageCleanup
} -result {0 0}

test imgPhoto-11.1 {Tk_FindPhoto} -setup {
    imageCleanup
} -body {
    image create bitmap i1
    image create photo photo1
    photo1 copy i1
} -cleanup {
    imageCleanup
} -returnCodes error -result {image "i1" doesn't exist or is not a photo image}


test imgPhoto-12.1 {Tk_PhotoPutZoomedBlock} -constraints hasTeapotPhoto -body {
    image create photo p3 -file $teapotPhotoFile
    set result [list [p3 get 50 50] [p3 get 100 100]]
    p3 copy p3 -zoom 2
    lappend result [image width p3] [image height p3] [p3 get 100 100]
} -cleanup {
    image delete p3
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591

1592
1593
1594
1595
1596
1597
1598
1561
1562
1563
1564
1565
1566
1567

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1587







-
+











-
+







    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2 -file $teapotPhotoFile
    photo2 copy photo1 -to 0 1 200 200 -zoom 2 3
    photo1 copy photo1 -to 0 1 200 200 -zoom 2 3
    string equal [photo1 data] [photo2 data]
} -cleanup {
    imageCleanup
} -result 1
} -result {1}
test imgPhoto-12.3 {Tk_ImgPhotoPutZoomedBlock, same source and dest img} -setup {
    imageCleanup
} -body {
    # Test for bug e4336bef5d
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2 -file $teapotPhotoFile
    photo2 copy photo1 -from 1 0 -to 4 5 300 300 -zoom 1 2
    photo1 copy photo1 -from 1 0 -to 4 5 300 300 -zoom 1 2
    string equal [photo1 data] [photo2 data]
} -cleanup {
    imageCleanup
} -result 1
} -result {1}
test imgPhoto-12.4 {Tk_ImgPhotoPutZoomedBlock, empty image} -setup {
    imageCleanup
} -body {
    image create photo photo1
    photo1 copy photo1 -to 0 5 10 20
    list [image width photo1] [image height photo1]
} -cleanup {
1639
1640
1641
1642
1643
1644
1645
1646

1647
1648
1649
1650
1651
1652
1653
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642







-
+







} -body {
    x1 eval [list image create photo T1_data -data $data]
    x2 eval [list image create photo T1_data -data $data]
} -cleanup {
    interp delete x1
    interp delete x2
} -result T1_data


test imgPhoto-14.1 {GIF writes work correctly} -setup {
    set data {
	R0lGODlhYwA5APcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgAysnGy8hKzM
	hASs3MTcjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
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
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







-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+










-
+







} -body {
    # This crashes Tk up to 8.4.17 and 8.5.0
    set i [image create photo]
    $i configure -data $data
} -cleanup {
    image delete $i
} -returnCodes error -result {malformed image}
test imgPhoto-14.5 {Bug [fbaed1f66b] - GIF decoder with deferred clear code} -setup {
    set fileName [file join [file dirname [info script]] deferredClearCode.gif]
} -body {
    # This erroneously produced "malformed image" error.
    # The animated GIF "deferredClearCode.gif" has two frames, and calling for -index 2
    # simply is an easy way to trigger the problem of improper management of a deferred
    # clear code. The effect was that the GIF decoder bailed out before the end of the
    # image reading, and produced the inappropriate "malformed image error".
    image create photo -file $fileName -format "gif -index 2"
} -returnCodes error -result {no image data for this index}


test imgPhoto-14.6 {Access Subimage after Subimage with buffer overflow. Ticket 4da2191b} -setup {
    set data {
	R0lGODlhYwA5APcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgAysnGy8hKzM
	hASs3MTcjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDAwP8AAAD/
	AP//AAAA//8A/wD//////ywAAAAAYwA5AAAI/wAZCBxIsKDBgwgTKlzIsKHD
	hxAjSpxIsaLFixgzatzIsaPHjyBDihxJsqTJkyhTqlzJsqXLlzBjypxJs6bN
	mzhz6tzJs6fPn0CDCh1KtKhRiwoSKEXAtGlTpUqPGkyagOmCq1edNsWalWkC
	BUSXIuDqFepBqFWtZv3KU+zYrkrBSqT6dgECtjOTbu16NwFHvV3lshRLti/J
	qlgRCE6ZuO9ik4Dt+k0ZVyZiyVIvXr77ODPEy5g9T4zMWfTEzXdNz1VbWvXn
	uqldP1TAOrbshqBb314Y2W7n3Qdpv7UNPCHpycUVbv6dnODy5sqzQldIe8H0
	hciva9/Ovbv37+BzBgE7ACH5BAFkAAMALAAAAAAEAAQAAAMEKLrckgA7
    }
} -body {
    image create photo photo1 -data $data -format "GIF -index 1"
} -cleanup {
    catch {image delete photo1}
} -result photo1

test imgPhoto-15.1 {photo images can fail to allocate memory gracefully} -constraints {
    nonPortable
} -body {
    # This is not portable to very large machines with more than around 3GB of
    # free memory available...
    image create photo -width 32000 -height 32000
} -returnCodes error -result {not enough free memory for image buffer}


test imgPhoto-16.1 {copying to self doesn't access freed memory} -setup {
    set i [image create photo]
} -body {
    # Bug 877950 makes this crash when trying to copy out of a deallocated
    # area.
    $i put red -to 0 0 1000 1000
    $i copy $i -from 0 0 1000 1000 -to 500 0
} -cleanup {
    image delete $i
} -result {}


# Check that we can guess our supported output formats [Bug 2983824]
test imgPhoto-17.1 {photo write: format guessing from filename} -setup {
    set i [image create photo -width 3 -height 3]
} -body {
    set f [makeFile {} test.png]
    $i write $f
    set fd [open $f]
1855
1856
1857
1858
1859
1860
1861
1862

1863
1864
1865
1866
1867
1868
1869
1801
1802
1803
1804
1805
1806
1807

1808
1809
1810
1811
1812
1813
1814
1815







-
+







    photo1 write $f
} -cleanup {
    imageCleanup
    catch {removeFile $f}
    unset f
} -returnCodes error -result \
    {image file format "default" has no file writing capability}


test imgPhoto-18.1 {MatchFileFormat: "default" format not supported} -setup {
    image create photo photo1
    set f [makeFile {} test.txt]
} -body {
    photo1 read $f -format default
} -cleanup {
    imageCleanup
1877
1878
1879
1880
1881
1882
1883
1884

1885
1886
1887
1888
1889
1890
1891
1823
1824
1825
1826
1827
1828
1829

1830
1831
1832
1833
1834
1835
1836
1837







-
+







    photo1 put {{red blue red} {yellow green yellow}} -format default
    list [image width photo1] [image height photo1]
} -cleanup {
    imageCleanup
} -result {3 2}
test imgPhoto-19.2 {MatchStringFormat: without -format option,
        default fmt} -body {
    image create photo photo1
    image create photo photo1 
    photo1 put {{red} {green}}
    list [image width photo1] [image height photo1]
} -cleanup {
    imageCleanup
} -result {1 2}
test imgPhoto-19.3 {MatchStringFormat: "-format ppm"} -setup {
    image create photo photo1
1899
1900
1901
1902
1903
1904
1905
1906

1907
1908
1909
1910
1911
1912
1913
1845
1846
1847
1848
1849
1850
1851

1852
1853
1854
1855
1856
1857
1858
1859







-
+







    unset imgData
    imageCleanup
} -result {1 2}
test imgPhoto-19.4 {MatchStringFormat: ppm fmt, without opt} -constraints {
    hasTeapotPhoto
} -setup {
    image create photo photo1 -file $teapotPhotoFile
    image create photo photo2
    image create photo photo2 
} -body {
    set imgData [photo1 data -format ppm]
    photo2 put $imgData
    list [image width photo2] [image height photo2]
} -cleanup {
    imageCleanup
    unset imgData
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
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







-
+






-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







} -returnCodes error -result {image format "bogus" is not supported}
test imgPhoto-19.6 {MatchStringFormat: invalid data for default} -setup {
    image create photo photo1
} -body {
    photo1 put bogus
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "bogus"}
} -returnCodes error -result {couldn't recognize image data}
test imgPhoto-19.7 {MatchStringFormat: invalid data for default} -setup {
    image create photo photo1
} -body {
    photo1 put bogus -format dEFault
} -cleanup {
    imageCleanup
} -returnCodes error -result {invalid color name "bogus"}
} -returnCodes error -result {couldn't recognize image data}
test imgPhoto-19.8 {MatchStirngFormat: invalid data for gif} -setup {
    image create photo photo1
} -body {
    photo1 put bogus -format giF
} -cleanup {
    imageCleanup
} -returnCodes error -result {couldn't recognize image data}

# Reject corrupted or truncated image [Bug b601ce3ab1].
# WARNING - tests 20.1-20.9 will cause a segfault on 8.5.19 and lower,
#           and on 8.6.6 and lower.
test imgPhoto-20.1 {Reject corrupted GIF (binary string)} -setup {
    set data [binary decode base64 {
	R0lGODlhAAQABP8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
	5qpraXIvM1JlNyAgOw==
    }]
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.2 {Reject corrupted GIF (base 64 string)} -setup {
    set data {
	R0lGODlhAAQABP8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
	5qpraXIvM1JlNyAgOw==
    }
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.3 {Reject corrupted GIF (file)} -setup {
    set fileName [file join [file dirname [info script]] corruptMangled.gif]
} -body {
    image create photo gif1 -file $fileName
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.4 {Reject truncated GIF (binary string)} -setup {
    set data [binary decode base64 {
	R0lGODlhEAAQAMIHAAAAADMz//8zM/8z/zP/MzP///8=
    }]
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map}
test imgPhoto-20.5 {Reject truncated GIF (base 64 string)} -setup {
    set data {
	R0lGODlhEAAQAMIHAAAAADMz//8zM/8z/zP/MzP///8=
    }
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map}
test imgPhoto-20.6 {Reject truncated GIF (file)} -setup {
    set fileName [file join [file dirname [info script]] corruptTruncated.gif]
} -body {
    image create photo gif1 -file $fileName
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map}
test imgPhoto-20.7 {Reject corrupted GIF (> 4Gb) (binary string)} -constraints {
    nonPortable
} -setup {
    # About the non portability constraint of this test: see ticket [cc42cc18a5]
    # If there is insufficient memory, the error message
    # {not enough free memory for image buffer} should be returned.
    # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
    set data [binary decode base64 {
	R0lGODlhwmYz//8zM/8z/zP/MzP/////M////yH5Ciwhe
	LrcLTBCd6Tv2qW16tdK4jhV5qpraXIvM1JlNyAgOw==
    }]
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.8 {Reject corrupted GIF (> 4Gb) (base 64 string)} -constraints {
    nonPortable
} -setup {
    # About the non portability constraint of this test: see ticket [cc42cc18a5]
    # If there is insufficient memory, the error message
    # {not enough free memory for image buffer} should be returned.
    # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
    set data {
	R0lGODlhwmYz//8zM/8z/zP/MzP/////M////yH5Ciwhe
	LrcLTBCd6Tv2qW16tdK4jhV5qpraXIvM1JlNyAgOw==
    }
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.9 {Reject corrupted GIF (> 4Gb) (file)} -constraints {
    nonPortable
} -setup {
    # About the non portability constraint of this test: see ticket [cc42cc18a5]
    # If there is insufficient memory, the error message
    # {not enough free memory for image buffer} should be returned.
    # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
    set fileName [file join [file dirname [info script]] corruptMangled4G.gif]
} -body {
    image create photo gif1 -file $fileName
} -cleanup {
    catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-20.10 {Valid GIF (binary string)} -setup {
    # Test the binary string reader with a valid GIF.
    # This is not tested elsewhere.
    # Tests 20.11, 20.12, with matching data, are included for completeness.
    set data [binary decode base64 {
	R0lGODlhEAAQAMIHAAAAADMz//8zM/8z/zP/MzP/////M////yH5BAEKAAcALAAA
	AAAQABAAAAMheLrcLTBCd6QV79qlterXB0riOFXmmapraXIvM1IdZTcJADs=
    }]
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -result gif1
test imgPhoto-20.11 {Valid GIF (base 64 string)} -setup {
    set data {
	R0lGODlhEAAQAMIHAAAAADMz//8zM/8z/zP/MzP/////M////yH5BAEKAAcALAAA
	AAAQABAAAAMheLrcLTBCd6QV79qlterXB0riOFXmmapraXIvM1IdZTcJADs=
    }
} -body {
    image create photo gif1 -data $data
} -cleanup {
    catch {image delete gif1}
} -result gif1
test imgPhoto-20.12 {Valid GIF (file)} -setup {
    set fileName [file join [file dirname [info script]] red.gif]
} -body {
    image create photo gif1 -file $fileName
} -cleanup {
    catch {image delete gif1}
} -result gif1

# ----------------------------------------------------------------------
# imgPhoto-21.x : Tk_PhotoGetMetadata

test imgPhoto-21.1 {option -metadata, get configure list} -setup {
    image create photo photo1 -metadata {dpi 100}
} -body {
    photo1 configure -metadata
} -cleanup {
    catch {image delete photo1}
} -result {-metadata {} {} {} {dpi 100}}

test imgPhoto-21.2 {option -metadata, get value} -setup {
    image create photo photo1 -metadata {dpi 100}
} -body {
    photo1 cget -metadata
} -cleanup {
    catch {image delete photo1}
} -result {dpi 100}

test imgPhoto-21.3 {option -metadata, get default value} -setup {
    image create photo photo1
} -body {
    photo1 cget -metadata
} -cleanup {
    catch {image delete photo1}
} -result {}

test imgPhoto-21.4 {bug daa10097: only 3 metadata list items on configure} -setup {
    image create photo photo1
} -body {
    set a {}
    foreach line [photo1 configure] {
        if {[lindex $line 0] eq {-metadata}} {
            set a $line
        }
    }
    set a
} -cleanup {
    catch {image delete photo1}
} -result {-metadata {} {} {} {}}


# imgPhoto-22.x : Tk_PhotoSetMetadata

test imgPhoto-22.1 {option -metadata, set value} -setup {
    image create photo photo1
} -body {
    photo1 configure -metadata {dpi 100}
    photo1 cget -metadata
} -cleanup {
    catch {image delete photo1}
} -result {dpi 100}

test imgPhoto-22.2 {option -metadata, change value} -setup {
    image create photo photo1 -metadata {dpi 200}
} -body {
    photo1 configure -metadata {dpi 100}
    photo1 cget -metadata
} -cleanup {
    catch {image delete photo1}
} -result {dpi 100}

test imgPhoto-22.3 {option -metadata, clear value} -setup {
    image create photo photo1 -metadata {dpi 200}
} -body {
    photo1 configure -metadata {}
    photo1 cget -metadata
} -cleanup {
    catch {image delete photo1}
} -result {}

# 23.x GIF images with metadata

# The following gif core data is used by the following data.
# N.B. this is the same image as test imgPhoto-18.10

# size 16x16, global color table size: 8
set gifstart "GIF89a\x10\x00\x10\x00\xc2\x07\x00"
# color table
append gifstart "\x00\x00\x00\x33\x33\xff\xff\x33\x33\xff\x33\xff\x33\xff\x33\x33\xff\xff\xff\xff\x33\xff\xff\xff"
# Graphic control extension: Transparent color index: 7 (not needed here)
# append gifdata "\x21\xf9\x04\x01\x0a\x00\x07\x00"
# Image descriptor: 16x16, no local color table
set gifdata "\x2c\x00\x00\x00\x00\x10\x00\x10\x00\x00"
# Image data
append gifdata "\x03\x21\x78\xba\xdc\x2d\x30\x42\x77\xa4\x15\xef\xda\xa5\xb5\xea\xd7\x07\x4a\xe2\x38\x55\xe6\x99\xaa\x6b\x69\x72\x2f\x33\x52\x1d\x65\x37\x09\x00"
set gifend "\x3b"

test imgPhoto-23.1 {GIF comment before image data (-data)} -setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {comment ABCD}

test imgPhoto-23.2 {GIF file comment before image data (-file)} -setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts -nonewline $h $data
    close $h
} -body {
    image create photo gif1 -file $path
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {comment ABCD}

test imgPhoto-23.3 {GIF comment after image data (-data)} -setup {
    set data $::gifstart
    append data $::gifdata
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {comment ABCD}

test imgPhoto-23.4 {GIF comment after image data (-file)} -setup {
    set data $::gifstart
    append data $::gifdata
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifend
    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    image create photo gif1 -file $path
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {comment ABCD}

test imgPhoto-23.5 {Two GIF comment blocks (-data)} -setup {
    set data $::gifstart
    # Append a comment extension block with data "1234"
    append data "\x21\xfe\x04" "1234" "\x0"
    append data $::gifdata
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {comment ABCD}

test imgPhoto-23.6 {Two GIF comment blocks (-file)} -setup {
    set data $::gifstart
    # Append a comment extension block with data "1234"
    append data "\x21\xfe\x04" "1234" "\x0"
    append data $::gifdata
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifend
    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    image create photo gif1 -file $path
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {comment ABCD}

test imgPhoto-23.7 {create: test if shared metadata object is not preserved\
	(-data)}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    image create photo gif1 -data $data -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.8 {create: test if shared metadata object is not preserved\
	(-file)}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend

    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    image create photo gif1 -file $path -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.9 {configure: test if shared metadata object is not\
	preserved (empty image, -data)}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    gif1 configure -data $data -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.10 {configure: test if shared metadata object is not preserved\
	(empty image, -file)}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend

    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    image create photo gif1
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    gif1 configure -file $path -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.11 {configure: test if shared metadata object is not preserved\
	(metadata replace, -data}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data "$::gifstart$::gifdata$::gifend"
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    gif1 configure -data $data -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.12 {configure: test if shared metadata object is not preserved\
	(metadata replace, -file}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend

    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    image create photo gif1 -data "$::gifstart$::gifdata$::gifend"
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    gif1 configure -file $path -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.13 {configure: test if shared metadata object is not preserved\
	(-data)}\
-setup {
    set data $::gifstart$::gifdata$::gifend
} -body {
    image create photo gif1 -data $data
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
    gif1 configure -data $data -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.14 {configure: test if shared metadata object is not preserved\
	(-file)}\
-setup {
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend

    set path [file join [configure -tmpdir] test.gif]
    set h [open $path "WRONLY BINARY CREAT"]
    puts $h $data
    close $h
} -body {
    image create photo gif1 -data "$::gifstart$::gifdata$::gifend"
    set metadataDict [dict create A 1]
    set metadataDict2 $metadataDict
    gif1 configure -file $path -format gif -metadata $metadataDict
    list [dict get [gif1 cget -metadata]] $metadataDict $metadataDict2
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {{A 1 comment ABCD} {A 1} {A 1}}

test imgPhoto-23.15 {output data with comment (from -metadata argument)}\
-setup {
    set data $::gifstart$::gifdata$::gifend
} -body {
    image create photo gif1 -data $data
    set gifData [gif1 data -format gif -metadata [dict create comment ABCD]]
} -cleanup {
    catch {image delete gif1}
} -match glob -result {*ABCD*}

test imgPhoto-23.16 {output data with comment (from -metadata property)}\
-setup {
    set data $::gifstart$::gifdata$::gifend
} -body {
    image create photo gif1 -data $data
    gif1 configure -metadata [dict create comment ABCD]
    set gifData [gif1 data -format gif]
} -cleanup {
    catch {image delete gif1}
} -match glob -result {*ABCD*}

test imgPhoto-23.17 {output file with comment (from -metadata property)}\
-setup {
    set data $::gifstart$::gifdata$::gifend
    set path [file join [configure -tmpdir] test.gif]
} -body {
    image create photo gif1 -data $data
    gif1 configure -metadata [dict create comment ABCD]
    gif1 write $path -format gif
    image delete gif1
    image create photo gif1 -file $path
    dict get [gif1 cget -metadata] comment
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {ABCD}

test imgPhoto-23.18 {configure: empty metadata parameter overwrites image metadata} -setup {
    image create photo gif1 -data $::gifstart$::gifdata$::gifend\
	    -metadata {foo bar}
    set data $::gifstart
    # Append a comment extension block with data "ABCD"
    append data "\x21\xfe\x04" "ABCD" "\x0"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    gif1 configure -data $data -metadata {}
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {comment ABCD}

test imgPhoto-23.19 {write: empty metadata parameter overwrites image metadata} -setup {
    image create photo gif1 -data $::gifstart$::gifdata$::gifend\
	    -metadata {comment bar}
    set path [file join [configure -tmpdir] test.gif]
} -body {
    gif1 write $path -format gif -metadata {}
    image delete gif1
    image create photo gif1 -file $path
    dict size [gif1 cget -metadata]
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {0}

test imgPhoto-23.20 {data: empty metadata parameter overwrites image metadata} -setup {
    image create photo gif1 -data $::gifstart$::gifdata$::gifend\
	    -metadata {comment bar}
} -body {
    set data [gif1 data -format gif -metadata {}]
    image delete gif1
    image create photo gif1 -data $data
    dict size [gif1 cget -metadata]
} -cleanup {
    catch {image delete gif1}
    file delete $path
} -result {0}

test imgPhoto-23.21 {GIF delay time metadata} -setup {
    set data $::gifstart
    # Graphic control extension: 10 1/100s delay time
    append data "\x21\xf9\x04\x00\x0a\x00\x00\x00"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{delay time} 10}

test imgPhoto-23.22 {GIF disposal method "do not dispose" metadata} -setup {
    set data $::gifstart
    # Graphic control extension: disposdal method:
    append data "\x21\xf9\x04\x04\x00\x00\x00\x00"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{disposal method} {do not dispose}}

test imgPhoto-23.23 {GIF disposal method "restore to background color" metadata} -setup {
    set data $::gifstart
    # Graphic control extension: disposdal method:
    append data "\x21\xf9\x04\x08\x00\x00\x00\x00"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{disposal method} {restore to background color}}

test imgPhoto-23.24 {GIF disposal method "restore to previous" metadata} -setup {
    set data $::gifstart
    # Graphic control extension: disposdal method:
    append data "\x21\xf9\x04\x0C\x00\x00\x00\x00"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{disposal method} {restore to previous}}

test imgPhoto-23.25 {GIF user input flag metadata} -setup {
    set data $::gifstart
    # Graphic control extension: disposdal method:
    append data "\x21\xf9\x04\x02\x00\x00\x00\x00"
    # Trailer
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{user interaction} 1}

test imgPhoto-23.26 {GIF update region metadata} -setup {
    # size 32x32, global color table size: 8
    set data "GIF89a\x20\x00\x20\x00\xc2\x07\x00"
    # color table
    append data "\x00\x00\x00\x33\x33\xff\xff\x33\x33\xff\x33\xff\x33\xff\x33\x33\xff\xff\xff\xff\x33\xff\xff\xff"
    # Trailer
    # As this is 16x16, we will get an update region setting
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{update region} {0 0 16 16}}

test imgPhoto-23.27 {GIF multiple options metadata} -setup {
    # size 32x32, global color table size: 8
    set data "GIF89a\x20\x00\x20\x00\xc2\x07\x00"
    # color table
    append data "\x00\x00\x00\x33\x33\xff\xff\x33\x33\xff\x33\xff\x33\xff\x33\x33\xff\xff\xff\xff\x33\xff\xff\xff"
    # Graphic control extension: do not dispose, user interaction, transparent color, delay time 10
    append data "\x21\xf9\x04\x07\x0a\x00\x01\x00"
    # Image data and trailer
    # As this is 16x16, we will get an update region setting
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{update region} {0 0 16 16} {delay time} 10 {disposal method} {do not dispose} {user interaction} 1}

test imgPhoto-23.28 {GIF multiple options metadata in -index 0} -setup {
    # size 32x32, global color table size: 8
    set data "GIF89a\x20\x00\x20\x00\xc2\x07\x00"
    # color table
    append data "\x00\x00\x00\x33\x33\xff\xff\x33\x33\xff\x33\xff\x33\xff\x33\x33\xff\xff\xff\xff\x33\xff\xff\xff"
    # Graphic control extension: do not dispose, user interaction, transparent color, delay time 4096
    append data "\x21\xf9\x04\x07\x00\x10\x01\x00"
    # Image data
    # As this is 16x16, we will get an update region setting
    append data $::gifdata
    # Graphic control extension: restore to background, delay time 1
    append data "\x21\xf9\x04\x08\x01\x00\x02\x00"
    # Image data and trailer
    # As this is 16x16, we will get an update region setting
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data -format "gif -index 0"
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{update region} {0 0 16 16} {delay time} 4096 {disposal method} {do not dispose} {user interaction} 1}

test imgPhoto-23.29 {GIF multiple options metadata in -index 1} -setup {
    # size 32x32, global color table size: 8
    set data "GIF89a\x20\x00\x20\x00\xc2\x07\x00"
    # color table
    append data "\x00\x00\x00\x33\x33\xff\xff\x33\x33\xff\x33\xff\x33\xff\x33\x33\xff\xff\xff\xff\x33\xff\xff\xff"
    # Graphic control extension: restore to background, delay time 1
    append data "\x21\xf9\x04\x08\x01\x00\x02\x00"
    # Image data
    # As this is 16x16, we will get an update region setting
    append data $::gifdata
    # Graphic control extension: do not dispose, user interaction, transparent color, delay time 4096
    append data "\x21\xf9\x04\x07\x00\x10\x01\x00"
    # Image data and trailer
    # As this is 16x16, we will get an update region setting
    append data $::gifdata $::gifend
} -body {
    image create photo gif1 -data $data -format "gif -index 1"
    gif1 cget -metadata
} -cleanup {
    catch {image delete gif1}
} -result {{update region} {0 0 16 16} {delay time} 4096 {disposal method} {do not dispose} {user interaction} 1}

unset -nocomplain gifstart gifdata gifend


catch {rename foreachPixel {}}
catch {rename checkImgTrans {}}
catch {rename checkImgTransLoop {}}
imageFinish

# cleanup

Deleted tests/imgSVGnano.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264








































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# This file is a Tcl script to test out the code in tkImgSVGnano.c, which reads
# and write SVG-format image files for photo widgets. The files is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 2018 Rene Zaumseil
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit

namespace eval svgnano {

    variable data

    set data(plus) {\
            <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
                <path fill="none" stroke="#000000" d="M0 0 h16 v16 h-16 z"/>
                <path fill="none" stroke="#000000" d="M8 4 v 8 M4 8 h 8"/>
                <circle fill="yellow" stroke="red" cx="10" cy="80" r="10" />
                <ellipse fill="none" stroke="blue" stroke-width="3" cx="60" cy="60" rx="10" ry="20" />
                <line x1="10" y1="90" x2="50" y2="99"/>
                <rect fill="none" stroke="green"  x="20" y="20" width="60" height="50" rx="3" ry="3"/>
                <polyline fill="red" stroke="purple" points="80,10 90,20 85,40"/>
                <polygon fill ="yellow" points="80,80 70,85 90,90"/>
                </svg>}
                set data(bad) {<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0:w">
            </svg>\
    }

    tcltest::makeFile $data(plus) plus.svg
    set data(plusFilePath) [file join [tcltest::configure -tmpdir] plus.svg]

    tcltest::makeFile $data(bad) bad.svg
    set data(badFilePath) [file join [tcltest::configure -tmpdir] bad.svg]


test imgSVGnano-1.1 {reading simple image} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $data(plus)
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {100 100}

test imgSVGnano-1.2 {simple image with options} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $data(plus) -format {svg -dpi 100 -scale 3}
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {300 300}

# test on crash found by Koen Danckaert
test imgSVGnano-1.3 {reformat image options} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $data(plus)
    catch {foo configure -format {svg -scale}}
    list {}
} -cleanup {
    rename foo ""
} -result {{}}

test imgSVGnano-1.4 {image options} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -data $data(plus)
    foo configure -format {svg -scale 2}
    foo configure -format {svg -dpi 600}
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {100 100}

test imgSVGnano-1.5 {reading simple image from file} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -file $data(plusFilePath)
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {100 100}
test imgSVGnano-1.6 {simple image from file with options} -setup {
    catch {rename foo ""}
} -body {
    image create photo foo -file $data(plusFilePath) -format {svg -dpi 100 -scale 3}
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {300 300}

test imgSVGnano-1.7 {very small scale gives 1x1 image} -body {
    image create photo foo -format "svg -scale 0.000001"\
	    -data $data(plus)
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {1 1}
test imgSVGnano-1.8 {very small scale gives 1x1 image, from file} -body {
    image create photo foo -format "svg -scale 0.000001"\
	    -file $data(plusFilePath)
    list [image width foo] [image height foo]
} -cleanup {
    rename foo ""
} -result {1 1}

test imgSVGnano-2.1 {reading a bad image} -body {
    image create photo foo -format svg -data $data(bad)
} -returnCodes error -result {couldn't recognize image data}
test imgSVGnano-2.2 {using bad option} -body {
    image create photo foo -data $data(plus) -format {svg -scale 0}
} -returnCodes error -result {-scale value must be positive}
test imgSVGnano-2.3 {using bad option} -body {
    image create photo foo -data $data(plus)
    foo configure -format {svg 1.0}
} -cleanup {
    rename foo ""
} -returnCodes error -result {bad option "1.0": must be -dpi, -scale, -scaletoheight, or -scaletowidth}
test imgSVGnano-2.4 {reading a bad image from file} -body {
    image create photo foo -format svg -file $data(badFilePath)
} -returnCodes error -match glob\
    -result {couldn't recognize data in image file "*/bad.svg"}

# -scaletoheight and -scaletowidth options
test imgSVGnano-3.1 {multiple scale options} -body {
    image create photo foo -format "svg -scale 1 -scaletowidth 20"\
	    -data $data(bad)
} -returnCodes error -result {only one of -scale, -scaletoheight, -scaletowidth may be given}

test imgSVGnano-3.2 {no number parameter to -scaletowidth} -body {
    image create photo foo -format "svg -scaletowidth invalid"\
	    -data $data(plus)
} -returnCodes error -result {expected integer but got "invalid"}

test imgSVGnano-3.3 {no number parameter to -scaletoheight} -body {
    image create photo foo -format "svg -scaletoheight invalid"\
	    -data $data(plus)
} -returnCodes error -result {expected integer but got "invalid"}

test imgSVGnano-3.4 {zero parameter to -scaletowidth} -body {
    image create photo foo -format "svg -scaletowidth 0"\
	    -data $data(plus)
} -returnCodes error -result {-scaletowidth value must be positive}

test imgSVGnano-3.5 {zero parameter to -scaletoheight} -body {
    image create photo foo -format "svg -scaletoheight 0"\
	    -data $data(plus)
} -returnCodes error -result {-scaletoheight value must be positive}

test imgSVGnano-3.6 {no number parameter to -scaletoheight} -body {
    image create photo foo -format "svg -scaletoheight invalid"\
	    -data $data(plus)
} -returnCodes error -result {expected integer but got "invalid"}

test imgSVGnano-3.7 {option -scaletowidth} -body {
    image create photo foo -format "svg -scaletowidth 20"\
	    -data $data(plus)
    image width foo
} -cleanup {
    rename foo ""
} -result 20

test imgSVGnano-3.8 {option -scaletoheight} -body {
    image create photo foo -format "svg -scaletoheight 20"\
	    -data $data(plus)
    image height foo
} -cleanup {
    rename foo ""
} -result 20

test imgSVGnano-3.10 {change from -scaletoheight to -scale} -body {
    set res {}
    image create photo foo -format "svg -scaletoheight 16"\
	    -data $data(plus)
    lappend res [image width foo] [image height foo]
    foo configure -format "svg -scale 2"
    lappend res [image width foo] [image height foo]
} -cleanup {
    rename foo ""
    unset res
} -result {16 16 200 200}

# svg file access
test imgSVGnano-4.1 {reread file on configure -scale} -setup {
    catch {rename foo ""}
    set res {}
} -body {
    image create photo foo -file $data(plusFilePath)
    lappend res [image width foo] [image height foo]
    foo configure -format "svg -scale 2"
    lappend res [image width foo] [image height foo]
} -cleanup {
    rename foo ""
    unset res
} -result {100 100 200 200}

test imgSVGnano-4.2 {error on file not accessible on reread due to configure} -setup {
    catch {rename foo ""}
    tcltest::makeFile $data(plus) tmpplus.svg
    image create photo foo -file [file join [tcltest::configure -tmpdir] tmpplus.svg]
    tcltest::removeFile tmpplus.svg
} -body {
    foo configure -format "svg -scale 2"
} -cleanup {
    rename foo ""
} -returnCodes error -match glob -result {couldn't open "*/tmpplus.svg": no such file or directory}

# Special images
test imgSVGnano-5.0 {image without any of  "width", "height" and "viewbox"} -body {
    image create photo foo -data\
			{<?xml version="1.0"?><!DOCTYPE svg PUBLIC\
			"-//W3C//DTD SVG 1.0//EN\"\
			"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\
			<svg xmlns="http://www.w3.org/2000/svg">\
			<g style="fill-opacity:0.7;">\
			<circle cx="6.5cm" cy="2cm" r="100" style="fill:green;\
			stroke:black; stroke-width:0.1cm" transform="translate(-70,150)"/>\
			</g></svg>}
} -cleanup {
    rename foo ""
} -result {foo}

test imgSVGnano-5.1 {bug ea665e08f3 - too many values in parameters of the transform attribute} -body {
    # shall not loop endlessly
    image create photo foo -data\
			{<?xml version="1.0"?><!DOCTYPE svg PUBLIC\
			"-//W3C//DTD SVG 1.0//EN\"\
			"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\
			<svg xmlns="http://www.w3.org/2000/svg">\
			<circle cx="6.5cm" cy="2cm" r="100" transform="skewX(1 1)"/>\
			</g></svg>}
} -cleanup {
    rename foo ""
} -result {foo}

test imgSVGnano-5.2 {bug d6e9b4db40 - "<svg" and ">" must be present} -body {
    image create photo foo -format svg -data\
			{<?xml version="1.0"?><!DOCTYPE svg PUBLIC\
			"-//W3C//DTD SVG 1.0//EN\" \
			"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\
			<sERRORvBADFILEg xmlns="http://www.w3.org/2000/svg">\
			<circle cx="6.5cm" cy="2cm" r="100" transform="skewX(1 1)"/>\
			</g></svg>}
} -returnCodes error -result {couldn't recognize image data}

    tcltest::removeFile plus.svg
    tcltest::removeFile bad.svg

};# end of namespace svgnano

namespace delete svgnano
imageFinish
cleanupTests
return

# Local Variables:
# mode: tcl
# fill-column: 78
# End:

Changes to tests/listbox.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test out the "listbox" command
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1993-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1993-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+

















-
+







    .l configure -bd 4
    list [lindex [.l configure -bd] 4] [.l cget -bd]
} -cleanup {
    .l configure -bd [lindex [.l configure -bd] 3]
} -result {4 4}
test listbox-1.6 {configuration options} -body {
    .l configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test listbox-1.7 {configuration options} -body {
    .l configure -bg #ff0000
    list [lindex [.l configure -bg] 4] [.l cget -bg]
} -cleanup {
    .l configure -bg [lindex [.l configure -bg] 3]
} -result {{#ff0000} #ff0000}
test listbox-1.8 {configuration options} -body {
    .l configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test listbox-1.9 {configuration options} -body {
    .l configure -borderwidth 1.3
    list [lindex [.l configure -borderwidth] 4] [.l cget -borderwidth]
} -cleanup {
    .l configure -borderwidth [lindex [.l configure -borderwidth] 3]
} -result {1 1}
test listbox-1.10 {configuration options} -body {
    .l configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test listbox-1.11 {configuration options} -body {
    .l configure -cursor arrow
    list [lindex [.l configure -cursor] 4] [.l cget -cursor]
} -cleanup {
    .l configure -cursor [lindex [.l configure -cursor] 3]
} -result {arrow arrow}
test listbox-1.12 {configuration options} -body {
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207







-
+







    .l configure -highlightthickness 6
    list [lindex [.l configure -highlightthickness] 4] [.l cget -highlightthickness]
} -cleanup {
    .l configure -highlightthickness [lindex [.l configure -highlightthickness] 3]
} -result {6 6}
test listbox-1.30 {configuration options} -body {
    .l configure -highlightthickness bogus
} -returnCodes error -result {expected screen distance but got "bogus"}
} -returnCodes error -result {bad screen distance "bogus"}
test listbox-1.31 {configuration options} -body {
    .l configure -highlightthickness -2
    list [lindex [.l configure -highlightthickness] 4] [.l cget -highlightthickness]
} -cleanup {
    .l configure -highlightthickness [lindex [.l configure -highlightthickness] 3]
} -result {0 0}
test listbox-1.32.1 {configuration options} -setup {
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+







    .l configure -selectborderwidth 1.3
    list [lindex [.l configure -selectborderwidth] 4] [.l cget -selectborderwidth]
} -cleanup {
    .l configure -selectborderwidth [lindex [.l configure -selectborderwidth] 3]
} -result {1 1}
test listbox-1.38 {configuration options} -body {
    .l configure -selectborderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test listbox-1.39 {configuration options} -body {
    .l configure -selectforeground #654321
    list [lindex [.l configure -selectforeground] 4] [.l cget -selectforeground]
} -cleanup {
    .l configure -selectforeground [lindex [.l configure -selectforeground] 3]
} -result {{#654321} #654321}
test listbox-1.40 {configuration options} -body {
364
365
366
367
368
369
370
371

372
373
374
375
376
377

378
379

380
381
382
383

384
385
386
387

388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
364
365
366
367
368
369
370

371
372
373
374
375
376

377
378

379
380
381
382

383
384
385
386

387
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403







-
+





-
+

-
+



-
+



-
+








-
+







    .l activate
} -returnCodes error -result {wrong # args: should be ".l activate index"}
test listbox-3.3 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate a b
} -returnCodes error -result {wrong # args: should be ".l activate index"}
test listbox-3.4 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate fooey
} -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}
test listbox-3.5 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate 3
    .l index active
} -result 3
test listbox-3.6 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate {}
    .l activate -1
    .l index active
} -result 0
} -result {0}
test listbox-3.7 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate 30
    .l index active
} -result 17
} -result {17}
test listbox-3.8 {ListboxWidgetCmd procedure, "activate" option} -body {
    .l activate end
    .l index active
} -result 17
} -result {17}
test listbox-3.9 {ListboxWidgetCmd procedure, "bbox" option} -body {
    .l bbox
} -returnCodes error -result {wrong # args: should be ".l bbox index"}
test listbox-3.10 {ListboxWidgetCmd procedure, "bbox" option} -body {
    .l bbox a b
} -returnCodes error -result {wrong # args: should be ".l bbox index"}
test listbox-3.11 {ListboxWidgetCmd procedure, "bbox" option} -body {
    .l bbox fooey
} -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}
test listbox-3.12 {ListboxWidgetCmd procedure, "bbox" option} -body {
    .l yview 3
    update
    list [.l bbox 2] [.l bbox 8]
} -result {{} {}}
test listbox-3.13 {ListboxWidgetCmd procedure, "bbox" option} -cleanup {
    destroy .l2
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436







-
+







    list [.l bbox 3] [.l bbox 4]
} -result {{7 7 17 14} {7 26 17 14}}
test listbox-3.15 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
	fonts
} -body {
    .l yview 0
    update
    list [.l bbox {}] [.l bbox 0]
    list [.l bbox -1] [.l bbox 0]
} -result {{} {7 7 17 14}}
test listbox-3.16 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
	fonts
} -body {
    .l yview end
    update
    list [.l bbox 17] [.l bbox end] [.l bbox 18]
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519
520
521
522
523

524
525
526

527
528
529
530
531
532
533
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518
519
520
521
522

523
524
525

526
527
528
529
530
531
532
533







-
+











-
+


-
+







    for {set i 0} {$i < [llength $lres]} {incr i 4} {
        set res [expr {$res * [expr {[lindex $lres $i] >= 0}] }]
    }
    set res
} -cleanup {
    destroy .top.l .top
    unset -nocomplain lres res
} -result 1
} -result {1}
test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body {
    .l cget
} -returnCodes error -result {wrong # args: should be ".l cget option"}
test listbox-3.20 {ListboxWidgetCmd procedure, "cget" option} -body {
    .l cget a b
} -returnCodes error -result {wrong # args: should be ".l cget option"}
test listbox-3.21 {ListboxWidgetCmd procedure, "cget" option} -body {
    .l cget -gorp
} -returnCodes error -result {unknown option "-gorp"}
test listbox-3.22 {ListboxWidgetCmd procedure, "cget" option} -body {
    .l cget -setgrid
} -result 0
} -result {0}
test listbox-3.23 {ListboxWidgetCmd procedure, "configure" option} -body {
    llength [.l configure]
} -result 28
} -result {28}
test listbox-3.24 {ListboxWidgetCmd procedure, "configure" option} -body {
    .l configure -gorp
} -returnCodes error -result {unknown option "-gorp"}
test listbox-3.25 {ListboxWidgetCmd procedure, "configure" option} -body {
    .l configure -setgrid
} -result {-setgrid setGrid SetGrid 0 0}
test listbox-3.26 {ListboxWidgetCmd procedure, "configure" option} -body {
554
555
556
557
558
559
560
561

562
563
564

565
566
567
568
569
570
571
554
555
556
557
558
559
560

561
562
563

564
565
566
567
568
569
570
571







-
+


-
+







    .l delete
} -returnCodes error -result {wrong # args: should be ".l delete firstIndex ?lastIndex?"}
test listbox-3.31 {ListboxWidgetCmd procedure, "delete" option} -body {
    .l delete a b c
} -returnCodes error -result {wrong # args: should be ".l delete firstIndex ?lastIndex?"}
test listbox-3.32 {ListboxWidgetCmd procedure, "delete" option} -body {
    .l delete badIndex
} -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}
test listbox-3.33 {ListboxWidgetCmd procedure, "delete" option} -body {
    .l delete 2 123ab
} -returnCodes error -result {bad listbox index "123ab": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "123ab": must be active, anchor, end, @x,y, or a number}
test listbox-3.34 {ListboxWidgetCmd procedure, "delete" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete 3
    list [.l2 get 2] [.l2 get 3] [.l2 index end]
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607







-
+









-
+







    destroy .l2
} -result {el1 el5 5}
test listbox-3.36 {ListboxWidgetCmd procedure, "delete" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete {} 2
    .l2 delete -3 2
    .l2 get 0 end
} -cleanup {
    destroy .l2
} -result {el3 el4 el5 el6 el7}
test listbox-3.37 {ListboxWidgetCmd procedure, "delete" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    .l2 delete {} {}
    .l2 delete -3 -1
    .l2 get 0 end
} -cleanup {
    destroy .l2
} -result {el0 el1 el2 el3 el4 el5 el6 el7}
test listbox-3.38 {ListboxWidgetCmd procedure, "delete" option} -setup {
    destroy .l2
} -body {
646
647
648
649
650
651
652
653

654
655
656

657
658
659
660
661
662
663
646
647
648
649
650
651
652

653
654
655

656
657
658
659
660
661
662
663







-
+


-
+







    .l get
} -returnCodes error -result {wrong # args: should be ".l get firstIndex ?lastIndex?"}
test listbox-3.43 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get a b c
} -returnCodes error -result {wrong # args: should be ".l get firstIndex ?lastIndex?"}
test listbox-3.44 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get 2.4
} -returnCodes error -result {bad listbox index "2.4": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "2.4": must be active, anchor, end, @x,y, or a number}
test listbox-3.45 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get end bogus
} -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}
test listbox-3.46 {ListboxWidgetCmd procedure, "get" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
    list [.l2 get 0] [.l2 get 3] [.l2 get end]
} -cleanup {
677
678
679
680
681
682
683
684

685
686
687

688
689
690

691
692
693
694
695
696
697
677
678
679
680
681
682
683

684
685
686

687
688
689

690
691
692
693
694
695
696
697







-
+


-
+


-
+







    listbox .l2
    .l2 insert 0 el0 el1 el2 "two words" el4 el5 el6 el7
    .l2 get 3 end
} -cleanup {
    destroy .l2
} -result {{two words} el4 el5 el6 el7}
test listbox-3.49 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get {}
    .l get -1
} -result {}
test listbox-3.50 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get {} {}
    .l get -2 -1
} -result {}
test listbox-3.51 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get {} 3
    .l get -2 3
} -result {el0 el1 el2 el3}
test listbox-3.52 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get 12 end
} -result {el12 el13 el14 el15 el16 el17}
test listbox-3.53 {ListboxWidgetCmd procedure, "get" option} -body {
    .l get 12 20
} -result {el12 el13 el14 el15 el16 el17}
708
709
710
711
712
713
714
715

716
717
718
719
720
721


722
723
724
725
726
727

728
729
730
731
732
733

734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

750
751
752
753
754
755
756
708
709
710
711
712
713
714

715
716
717
718
719


720
721
722
723
724
725
726

727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748

749
750
751
752
753
754
755
756







-
+




-
-
+
+





-
+





-
+















-
+







    .l index
} -returnCodes error -result {wrong # args: should be ".l index index"}
test listbox-3.58 {ListboxWidgetCmd procedure, "index" option} -body {
    .l index a b
} -returnCodes error -result {wrong # args: should be ".l index index"}
test listbox-3.59 {ListboxWidgetCmd procedure, "index" option} -body {
    .l index @
} -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or a number}
test listbox-3.60 {ListboxWidgetCmd procedure, "index" option} -body {
    .l index 2
} -result 2
test listbox-3.61 {ListboxWidgetCmd procedure, "index" option} -body {
    expr {[.l index {}]<0}
} -result 1
    .l index -1
} -result {-1}
test listbox-3.62 {ListboxWidgetCmd procedure, "index" option} -body {
    .l index end
} -result 18
test listbox-3.63 {ListboxWidgetCmd procedure, "index" option} -body {
    .l index 34
} -result 18
} -result 34
test listbox-3.64 {ListboxWidgetCmd procedure, "insert" option} -body {
    .l insert
} -returnCodes error -result {wrong # args: should be ".l insert index ?element ...?"}
test listbox-3.65 {ListboxWidgetCmd procedure, "insert" option} -body {
    .l insert badIndex
} -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}
test listbox-3.66 {ListboxWidgetCmd procedure, "insert" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert end a b c d e
    .l2 insert 3 x y z
    .l2 get 0 end
} -cleanup {
    destroy .l2
} -result {a b c x y z d e}
test listbox-3.67 {ListboxWidgetCmd procedure, "insert" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 insert end a b c
    .l2 insert 0 x
    .l2 insert -1 x
    .l2 get 0 end
} -cleanup {
    destroy .l2
} -result {x a b c}
test listbox-3.68 {ListboxWidgetCmd procedure, "insert" option} -setup {
    destroy .l2
} -body {
779
780
781
782
783
784
785
786

787
788
789
790
791
792
793
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793







-
+







} -returnCodes error -result {wrong # args: should be ".l nearest y"}
test listbox-3.72 {ListboxWidgetCmd procedure, "nearest" option} -body {
    .l nearest 20p
} -returnCodes error -result {expected integer but got "20p"}
test listbox-3.73 {ListboxWidgetCmd procedure, "nearest" option} -body {
    .l yview 3
    .l nearest 1000
} -result 7
} -result {7}
test listbox-3.74 {ListboxWidgetCmd procedure, "scan" option} -body {
    .l scan a b
} -returnCodes error -result {wrong # args: should be ".l scan mark|dragto x y"}
test listbox-3.75 {ListboxWidgetCmd procedure, "scan" option} -body {
    .l scan a b c d
} -returnCodes error -result {wrong # args: should be ".l scan mark|dragto x y"}
test listbox-3.76 {ListboxWidgetCmd procedure, "scan" option} -body {
812
813
814
815
816
817
818
819

820
821
822
823
824
825
826
827
828

829
830
831
832
833

834
835
836
837
838

839
840
841
842
843

844
845
846
847
848

849
850
851
852
853

854
855
856
857
858

859
860
861

862
863

864
865
866
867
868

869
870
871
872
873

874
875
876
877
878

879
880
881
882
883
884
885
886
887

888
889
890

891
892
893
894
895
896
897
898
899

900
901

902
903
904
905

906
907
908
909

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929


930
931
932
933
934

935
936
937
938

939
940
941
942
943
944
945
946

947
948
949
950
951
952
953
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827

828
829
830
831
832

833
834
835
836
837

838
839
840
841
842

843
844
845
846
847

848
849
850
851
852

853
854
855
856
857

858
859
860

861
862

863
864
865
866
867

868
869
870
871
872

873
874
875
876
877

878
879
880
881
882
883
884
885
886

887
888
889

890
891
892
893
894
895
896
897
898

899
900

901
902
903
904

905
906
907
908

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927


928
929
930
931
932
933

934
935
936
937

938
939
940
941
942
943
944
945

946
947
948
949
950
951
952
953







-
+








-
+




-
+




-
+




-
+




-
+




-
+




-
+


-
+

-
+




-
+




-
+




-
+








-
+


-
+








-
+

-
+



-
+



-
+


















-
-
+
+




-
+



-
+







-
+







    update
    list [format {%.6g %.6g} {*}[.t.l xview]] [format {%.6g %.6g} {*}[.t.l yview]]
} -cleanup {
    destroy .t
} -result {{0.249364 0.427481} {0.0714286 0.428571}}
test listbox-3.79 {ListboxWidgetCmd procedure, "scan" option} -body {
    .l scan foo 2 4
} -returnCodes error -result {bad option "foo": must be dragto or mark}
} -returnCodes error -result {bad option "foo": must be mark or dragto}
test listbox-3.80 {ListboxWidgetCmd procedure, "see" option} -body {
    .l see
} -returnCodes error -result {wrong # args: should be ".l see index"}
test listbox-3.81 {ListboxWidgetCmd procedure, "see" option} -body {
    .l see a b
} -returnCodes error -result {wrong # args: should be ".l see index"}
test listbox-3.82 {ListboxWidgetCmd procedure, "see" option} -body {
    .l see gorp
} -returnCodes error -result {bad listbox index "gorp": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "gorp": must be active, anchor, end, @x,y, or a number}
test listbox-3.83 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 7
    .l index @0,0
} -result 7
} -result {7}
test listbox-3.84 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 11
    .l index @0,0
} -result 7
} -result {7}
test listbox-3.85 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 6
    .l index @0,0
} -result 6
} -result {6}
test listbox-3.86 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 5
    .l index @0,0
} -result 3
} -result {3}
test listbox-3.87 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 12
    .l index @0,0
} -result 8
} -result {8}
test listbox-3.88 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 13
    .l index @0,0
} -result 11
} -result {11}
test listbox-3.89 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see {}
    .l see -1
    .l index @0,0
} -result 0
} -result {0}
test listbox-3.90 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see end
    .l index @0,0
} -result 13
} -result {13}
test listbox-3.91 {ListboxWidgetCmd procedure, "see" option} -body {
    .l yview 7
    .l see 322
    .l index @0,0
} -result 13
} -result {13}
test listbox-3.92 {ListboxWidgetCmd procedure, "see" option, partial last line} -body {
    mkPartial
    .partial.l see 4
    .partial.l index @0,0
} -result 1
} -result {1}
test listbox-3.93 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l select a
} -returnCodes error -result {wrong # args: should be ".l selection option index ?index?"}
test listbox-3.94 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l select a b c d
} -returnCodes error -result {wrong # args: should be ".l selection option index ?index?"}
test listbox-3.95 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection a bogus
} -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}
test listbox-3.96 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection a 0 lousy
} -returnCodes error -result {bad listbox index "lousy": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "lousy": must be active, anchor, end, @x,y, or a number}
test listbox-3.97 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection anchor 0 0
} -returnCodes error -result {wrong # args: should be ".l selection anchor index"}
test listbox-3.98 {ListboxWidgetCmd procedure, "selection" option} -body {
    list [.l selection anchor 5; .l index anchor] \
	    [.l selection anchor 0; .l index anchor]
} -result {5 0}
test listbox-3.99 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection anchor {}
    .l selection anchor -1
    .l index anchor
} -result 0
} -result {0}
test listbox-3.100 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection anchor end
    .l index anchor
} -result 17
} -result {17}
test listbox-3.101 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection anchor 44
    .l index anchor
} -result 17
} -result {17}
test listbox-3.102 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection clear 0 end
    .l selection set 2 8
    .l selection clear 3 4
    .l curselection
} -result {2 5 6 7 8}
test listbox-3.103 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection includes 0 0
} -returnCodes error -result {wrong # args: should be ".l selection includes index"}
test listbox-3.104 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection clear 0 end
    .l selection set 2 8
    .l selection clear 4
    list [.l selection includes 3] [.l selection includes 4] \
	    [.l selection includes 5]
} -result {1 0 1}
test listbox-3.105 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection set 0 end
    .l selection includes {}
} -result 0
    .l selection includes -1
} -result {0}
test listbox-3.106 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection clear 0 end
    .l selection set end
    .l selection includes end
} -result 1
} -result {1}
test listbox-3.107 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection set 0 end
    .l selection includes 44
} -result 0
} -result {0}
test listbox-3.108 {ListboxWidgetCmd procedure, "selection" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    .l2 selection includes 0
} -cleanup {
    destroy .l2
} -result 0
} -result {0}
test listbox-3.109 {ListboxWidgetCmd procedure, "selection" option} -body {
    .l selection clear 0 end
    .l selection set 2
    .l selection set 5 7
    .l curselection
} -result {2 5 6 7}
test listbox-3.110 {ListboxWidgetCmd procedure, "selection" option} -body {
961
962
963
964
965
966
967
968

969
970
971
972
973
974
975
961
962
963
964
965
966
967

968
969
970
971
972
973
974
975







-
+







    .l selection badOption 0 0
} -returnCodes error -result {bad option "badOption": must be anchor, clear, includes, or set}
test listbox-3.112 {ListboxWidgetCmd procedure, "size" option} -body {
    .l size a
} -returnCodes error -result {wrong # args: should be ".l size"}
test listbox-3.113 {ListboxWidgetCmd procedure, "size" option} -body {
    .l size
} -result 18
} -result {18}
test listbox-3.114 {ListboxWidgetCmd procedure, "xview" option} -setup {
    destroy .l2
} -body {
    listbox .l2
    update
    format {%.6g %.6g} {*}[.l2 xview]
} -cleanup {
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1131
1132
1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
1145







-
+







listbox .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2
pack .l
.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 \
	el15 el16 el17
update
test listbox-3.127 {ListboxWidgetCmd procedure, "xview" option} -body {
    .l yview foo
} -returnCodes error -result {bad listbox index "foo": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "foo": must be active, anchor, end, @x,y, or a number}
test listbox-3.128 {ListboxWidgetCmd procedure, "xview" option} -body {
    .l yview foo a b
} -returnCodes error -result {unknown option "foo": must be moveto or scroll}
test listbox-3.129 {ListboxWidgetCmd procedure, "xview" option} -setup {
    destroy .l2
    listbox .l2 -width 10 -height 5 -font $fixed
    pack .l2
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1252







-
+







    pack .l
    update
} -body {
    .l configure -highlightthickness -3
    .l cget -highlightthickness
} -cleanup {
    deleteWindows
} -result 0
} -result {0}
test listbox-4.3 {ConfigureListbox procedure} -setup {
    deleteWindows
    destroy .l
    listbox .l -setgrid 1 -width 25 -height 15
    pack .l
    update
} -body {
1569
1570
1571
1572
1573
1574
1575
1576

1577
1578
1579
1580
1581
1582
1583

1584
1585
1586
1587
1588
1589
1590
1591

1592
1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603
1604
1605
1606

1607
1608
1609
1610
1611
1612
1613

1614
1615
1616
1617
1618

1619
1620
1621
1622
1623

1624
1625
1626
1627
1628
1629
1630
1569
1570
1571
1572
1573
1574
1575

1576
1577
1578
1579
1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602
1603
1604
1605

1606
1607
1608
1609
1610
1611
1612

1613
1614
1615
1616
1617

1618
1619
1620
1621
1622

1623
1624
1625
1626
1627
1628
1629
1630







-
+






-
+







-
+







-
+






-
+






-
+




-
+




-
+







} -result {q r s a b A c d x y z}
test listbox-6.2 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l insert 2 A B
    .l index anchor
} -result 4
} -result {4}
test listbox-6.3 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l insert 3 A B
    .l index anchor
} -result 2
} -result {2}
test listbox-6.4 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l insert 2 A B
    .l index @0,0
} -result 5
} -result {5}
test listbox-6.5 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l insert 3 A B
    .l index @0,0
} -result 3
} -result {3}
test listbox-6.6 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 5
    .l insert 5 A B
    .l index active
} -result 7
} -result {7}
test listbox-6.7 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 5
    .l insert 6 A B
    .l index active
} -result 5
} -result {5}
test listbox-6.8 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c
    .l index active
} -result 2
} -result {2}
test listbox-6.9 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0
    .l index active
} -result 0
} -result {0}
test listbox-6.10 {InsertEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b "two words"  c d e f g h i j
    update
    set log {}
    .l insert 0 word
    update
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
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







-
+






-
+






-
+






-
+







-
+







-
+







-
+







-
+






-
+






-
+






-
+






-
+






-
+







} -result {8 h}
test listbox-7.5 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l delete 0 1
    .l index anchor
} -result 0
} -result {0}
test listbox-7.6 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 2
    .l delete 2
    .l index anchor
} -result 2
} -result {2}
test listbox-7.7 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 4
    .l delete 2 5
    .l index anchor
} -result 2
} -result {2}
test listbox-7.8 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l selection anchor 3
    .l delete 4 5
    .l index anchor
} -result 3
} -result {3}
test listbox-7.9 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 1 2
    .l index @0,0
} -result 1
} -result {1}
test listbox-7.10 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 3 4
    .l index @0,0
} -result 3
} -result {3}
test listbox-7.11 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 4 6
    .l index @0,0
} -result 3
} -result {3}
test listbox-7.12 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    .l delete 3 end
    .l index @0,0
} -result 1
} -result {1}
test listbox-7.13 {DeleteEls procedure, updating view with partial last line} -body {
    mkPartial
    .partial.l yview 8
    update
    .partial.l delete 10 13
    .partial.l index @0,0
} -result 7
} -result {7}
test listbox-7.14 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 3 4
    .l index active
} -result 4
} -result {4}
test listbox-7.15 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 5 7
    .l index active
} -result 5
} -result {5}
test listbox-7.16 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 5 end
    .l index active
} -result 4
} -result {4}
test listbox-7.17 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c d e f g h i j
    .l activate 6
    .l delete 0 end
    .l index active
} -result 0
} -result {0}
test listbox-7.18 {DeleteEls procedure} -body {
    .l delete 0 end
    .l insert 0 a b c "two words" d e f g h i j
    update
    set log {}
    .l delete 4 6
    update
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
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







-
+









-
+







} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index a
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "a": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "a": must be active, anchor, end, @x,y, or a number}
test listbox-10.5 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index end
} -cleanup {
    destroy .l
} -result 12
} -result {12}
test listbox-10.6 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l get end
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
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







-
+









-
+









-
+









-
+









-
+









-
+







} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or a number}
test listbox-10.9 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @foo
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@foo": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@foo": must be active, anchor, end, @x,y, or a number}
test listbox-10.10 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @1x3
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@1x3": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@1x3": must be active, anchor, end, @x,y, or a number}
test listbox-10.11 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @1,
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@1,": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@1,": must be active, anchor, end, @x,y, or a number}
test listbox-10.12 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @1,foo
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@1,foo": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@1,foo": must be active, anchor, end, @x,y, or a number}
test listbox-10.13 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index @1,2x
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "@1,2x": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "@1,2x": must be active, anchor, end, @x,y, or a number}
test listbox-10.14 {GetListboxIndex procedure} -constraints {
    fonts
} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
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
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







-
+









-
+









-
+
















-
+


-
+










-
+











-
+







} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index 1xy
} -cleanup {
    destroy .l
} -returnCodes error -result {bad listbox index "1xy": must be active, anchor, end, @x,y, or an index}
} -returnCodes error -result {bad listbox index "1xy": must be active, anchor, end, @x,y, or a number}
test listbox-10.16 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index 3
} -cleanup {
    destroy .l
} -result 3
} -result {3}
test listbox-10.17 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l index 20
} -cleanup {
    destroy .l
} -result 12
} -result {20}
test listbox-10.18 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    .l get 20
} -cleanup {
    destroy .l
} -result {}
test listbox-10.19 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    update
    expr {[.l index {}]<0}
    .l index -2
} -cleanup {
    destroy .l
} -result 1
} -result  -2
test listbox-10.20 {GetListboxIndex procedure} -setup {
    destroy .l
} -body {
    pack [listbox .l]
    .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
    .l delete 0 end
    update
    .l index 1
} -cleanup {
    destroy .l
} -result 0
} -result 1


test listbox-11.1 {ChangeListboxView procedure, boundary conditions for index} -setup {
    destroy .l
} -body {
    listbox .l -height 5
    pack .l
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    set x [.l index @0,0]
    .l yview {}
    .l yview -1
    update
    lappend x [.l index @0,0]
} -cleanup {
    destroy .l
} -result {3 0}
test listbox-11.2 {ChangeListboxView procedure, boundary conditions for index} -setup {
    destroy .l
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
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







-
















-
+







    destroy .l
} -result {{0.5 1} {{y 0.5 1}}}
test listbox-11.5 {ChangeListboxView procedure} -setup {
    destroy .l
} -body {
    listbox .l -height 5 -yscrollcommand "record y"
    pack .l
    update
    .l insert 0 a b c d e f g h i j
    .l yview 3
    update
    set log {}
    .l yview 3
    update
    list [format {%.6g %.6g} {*}[.l yview]] $log
} -cleanup {
    destroy .l
} -result {{0.3 0.8} {}}
test listbox-11.6 {ChangeListboxView procedure, partial last line} -body {
    mkPartial
    .partial.l yview 13
    .partial.l index @0,0
} -cleanup {
    destroy .l
} -result 11
} -result {11}


# Listbox used in 12.* tests
destroy .l
listbox .l -font $fixed -xscrollcommand "record x" -width 10
.l insert 0 0123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789
pack .l
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
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







-
+











-
+









-
+







    lappend x [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]
} -result {{0.8 1} {0.75 1} {0.6 0.8} {0.25 0.5}}


test listbox-14.1 {NearestListboxElement procedure, partial last line} -body {
    mkPartial
    .partial.l nearest [winfo height .partial.l]
} -result 4
} -result {4}
# Listbox used in 14.* tests
destroy .l
listbox .l -font $fixed -width 20 -height 10
.l insert 0 a b c d e f g h i j k l m n o p q r s t
.l yview 4
pack .l
update
test listbox-14.2 {NearestListboxElement procedure} -constraints {
	fonts
} -body {
    .l index @50,0
} -result 4
} -result {4}
test listbox-14.3 {NearestListboxElement procedure} -constraints {
	fonts
} -body {
    list [.l index @50,35] [.l index @50,36]
} -result {5 6}
test listbox-14.4 {NearestListboxElement procedure} -constraints {
	fonts
} -body {
    .l index @50,200
} -result 13
} -result {13}


# Listbox used in 15.* 16.* and 17.* tests
destroy .l
listbox .l -font $fixed -width 20 -height 10
pack .l
update
2374
2375
2376
2377
2378
2379
2380
2381

2382
2383
2384
2385
2386
2387
2388

2389
2390
2391
2392
2393
2394
2395
2373
2374
2375
2376
2377
2378
2379

2380
2381
2382
2383
2384
2385
2386

2387
2388
2389
2390
2391
2392
2393
2394







-
+






-
+







    .l select set 0 end
    .l curselection
} -result {}
test listbox-15.4 {ListboxSelect procedure, boundary conditions for indices} -body {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set {} {}
    .l select set -2 -1
    .l curselection
} -result {}
test listbox-15.5 {ListboxSelect procedure, boundary conditions for indices} -body {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set {} 3
    .l select set -1 3
    .l curselection
} -result {0 1 2 3}
test listbox-15.6 {ListboxSelect procedure, boundary conditions for indices} -body {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 2 4
2411
2412
2413
2414
2415
2416
2417
2418

2419
2420
2421
2422
2423
2424
2425
2410
2411
2412
2413
2414
2415
2416

2417
2418
2419
2420
2421
2422
2423
2424







-
+







} -result {4 5}
test listbox-15.9 {ListboxSelect procedure, boundary conditions for indices} -body {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set end 30
    .l curselection
} -result 5
} -result {5}
test listbox-15.10 {ListboxSelect procedure, boundary conditions for indices} -body {
    .l delete 0 end
    .l insert 0 a b c d e f
    .l select clear 0 end
    .l select set 20 25
    .l curselection
} -result {}
2447
2448
2449
2450
2451
2452
2453
2454

2455
2456
2457
2458
2459
2460
2461
2446
2447
2448
2449
2450
2451
2452

2453
2454
2455
2456
2457
2458
2459
2460







-
+







    .l delete 0 end
    .l insert 0 1$long 2$long 3$long 4$long 5$long
    .l selection set 0 end
    set sel [selection get]
    string compare 1$long\n2$long\n3$long\n4$long\n5$long $sel
} -cleanup {
    catch {unset long sel}
} -result 0
} -result {0}


test listbox-17.1 {ListboxLostSelection procedure} -setup {
    destroy .e
} -body {
    .l delete 0 end
    .l insert 0 a b c d e
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
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







-
+
+


-
+
-

-
+

-
+



-
+




+


-
+
-

-
+

-
+

-
+



-
+







    .l curselection
} -cleanup {
    destroy .l
} -result 2
test listbox-21.9 {ListboxListVarProc, test hscrollbar after listvar mod} -setup {
    destroy .l
} -body {
    set x {}
    catch {unset x}
    set log {}
    listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
    pack .l
    update idletasks
    update
    set log {}
    lappend x "0000000000"
    update idletasks
    update
    lappend x "00000000000000000000"
    update idletasks
    update
    set log
} -cleanup {
    destroy .l
} -result [list {x 0 1} {x 0 0.5}]
} -result [list {x 0 1} {x 0 1} {x 0 0.5}]
test listbox-21.10 {ListboxListVarProc, test hscrollbar after listvar mod} -setup {
    destroy .l
} -body {
    catch {unset x}
    set log {}
    listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
    pack .l
    update idletasks
    update
    set log {}
    lappend x "0000000000"
    update idletasks
    update
    lappend x "00000000000000000000"
    update idletasks
    update
    set x [list "0000000000"]
    update idletasks
    update
    set log
} -cleanup {
    destroy .l
} -result [list {x 0 1} {x 0 0.5} {x 0 1}]
} -result [list {x 0 1} {x 0 1} {x 0 0.5} {x 0 1}]
test listbox-21.11 {ListboxListVarProc, bad list} -setup {
    destroy .l
} -body {
    catch {unset x}
    listbox .l -listvar x
    set x [list a b c d]
    catch {set x "this is a \" bad list"} result
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
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







-
-

+

-
-


-
+



-







+




















+


-
+
-
-

-
+

-
+



-
-
+




















-
+


-
-
-
+
+
+








-
+









-
+







} -cleanup {
    destroy .l
} -result red
test listbox-21.15 {ListboxListVarProc, update vertical scrollbar} -setup {
    destroy .l
} -body {
    catch {unset x}
    listbox .l -font $fixed -height 3 -yscrollcommand "record y" -listvar x
    update
    set log {}
    listbox .l -listvar x -yscrollcommand "record y" -font fixed -height 3
    pack .l
    set timeout [after 500 {lappend log timeout3}]
    vwait log
    update
    lappend x a b c d e f
    vwait log
    update
    set log
} -cleanup {
    destroy .l
    after cancel $timeout
} -result [list {y 0 1} {y 0 0.5}]
test listbox-21.16 {ListboxListVarProc, update vertical scrollbar} -setup {
    destroy .l
} -body {
    catch {unset x}
    listbox .l -listvar x -height 3
    pack .l
    update
    set x [list 0 1 2 3 4 5]
    .l yview scroll 3 units
    update
    set result {}
    lappend result [format {%.6g %.6g} {*}[.l yview]]
    set x [lreplace $x 3 3]
    set x [lreplace $x 3 3]
    set x [lreplace $x 3 3]
    update
    lappend result [format {%.6g %.6g} {*}[.l yview]]
    set result
} -cleanup {
    destroy .l
} -result [list {0.5 1} {0 1}]


# UpdateHScrollbar
test listbox-22.1 {UpdateHScrollbar} -setup {
    destroy .l
} -body {
    set log {}
    listbox .l -font $fixed -width 10 -xscrollcommand "record x"
    pack .l
    update idletasks
    update
    set log {}
    set timeout [after 500 {lappend log timeout4}]
    .l insert end "0000000000"
    vwait log
    update
    .l insert end "00000000000000000000"
    vwait log
    update
    set log
} -cleanup {
    destroy .l
    after cancel $timeout
} -result [list {x 0 1} {x 0 0.5}]
} -result [list {x 0 1} {x 0 1} {x 0 0.5}]


# ConfigureListboxItem
test listbox-23.1 {ConfigureListboxItem} -setup {
    destroy .l
} -body {
    listbox .l
    catch {.l itemconfigure 0} result
    set result
} -cleanup {
    destroy .l
} -result {item number "0" out of range}
test listbox-23.2 {ConfigureListboxItem} -setup {
    destroy .l
} -body {
    listbox .l
    .l insert end a b c d
    .l itemconfigure 0
} -cleanup {
    destroy .l
} -result [list {-background {} {} {} {}} \
} -result [list {-background background Background {} {}} \
	{-bg -background} \
	{-fg -foreground} \
	{-foreground {} {} {} {}} \
	{-selectbackground {} {} {} {}} \
	{-selectforeground {} {} {} {}}]
	{-foreground foreground Foreground {} {}} \
	{-selectbackground selectBackground Foreground {} {}} \
	{-selectforeground selectForeground Background {} {}}]
test listbox-23.3 {ConfigureListboxItem, itemco shortcut} -setup {
    destroy .l
} -body {
    listbox .l
    .l insert end a b c d
    .l itemco 0 -background
} -cleanup {
    destroy .l
} -result {-background {} {} {} {}}
} -result {-background background Background {} {}}
test listbox-23.4 {ConfigureListboxItem, wrong num args} -setup {
    destroy .l
} -body {
    listbox .l
    .l insert end a
    catch {.l itemco} result
    set result
} -cleanup {
    destroy .l
} -result {wrong # args: should be ".l itemconfigure index ?-option value ...?"}
} -result {wrong # args: should be ".l itemconfigure index ?-option? ?value? ?-option value ...?"}
test listbox-23.5 {ConfigureListboxItem, multiple calls} -setup {
    destroy .l
} -body {
    listbox .l
    set i 0
    foreach color {red orange yellow green blue white violet} {
	.l insert end $color
3148
3149
3150
3151
3152
3153
3154
3155

3156
3157
3158
3159
3160
3161
3162
3142
3143
3144
3145
3146
3147
3148

3149
3150
3151
3152
3153
3154
3155
3156







-
+







    unset -nocomplain res
} -body {
    pack [listbox .l -state normal]
    update
    bind .l <<ListboxSelect>> {lappend res [%W curselection]}
    .l insert end a b c
    focus -force .l
    event generate .l <Button-1> -x 5 -y 5  ; # <<ListboxSelect>> fires
    event generate .l <1> -x 5 -y 5  ; # <<ListboxSelect>> fires
    .l configure -state disabled
    focus -force .l
    event generate .l <Control-Home> ; # <<ListboxSelect>> does NOT fire
    .l configure -state normal
    focus -force .l
    event generate .l <Control-End>  ; # <<ListboxSelect>> fires
    .l selection clear 0 end         ; # <<ListboxSelect>> does NOT fire
3171
3172
3173
3174
3175
3176
3177
3178

3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219





3165
3166
3167
3168
3169
3170
3171

3172
3173
3174
3175
3176
3177
3178
3179



























3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191







-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







+
+
+
+
+
    destroy .l
} -body {
    pack [listbox .l -exportselection true]
    update
    bind .l <<ListboxSelect>> {lappend res [list [selection own] [%W curselection]]}
    .l insert end a b c
    focus -force .l
    event generate .l <Button-1> -x 5 -y 5  ; # <<ListboxSelect>> fires
    event generate .l <1> -x 5 -y 5  ; # <<ListboxSelect>> fires
    selection clear                  ; # <<ListboxSelect>> fires again
    update
    set res
} -cleanup {
    destroy .l
} -result {{.l 0} {{} {}}}

test listbox-32.1 {Bug [5d991b822e]} {
    # Want this not to segfault, or write to variable with empty name
    set var INIT
    listbox .b -listvariable var
    trace add variable var unset {apply {args {
        .b configure -listvariable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
    info exists {}
} 0
test listbox-32.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    listbox .b -listvariable var
    trace add variable var unset {apply {args {
        .b configure -listvariable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}

resetGridInfo
deleteWindows
option clear

# cleanup
cleanupTests
return





Changes to tests/main.test.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







# This file contains tests for the tkMain.c file.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 by Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

23
24
25
26
27
28
29
30


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


47
48

49
50
51
52
53
54
55
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49

50
51
52
53
54
55
56
57







-
+
+















-
+
+

-
+








test main-2.1 {Tk_MainEx: -encoding option} -constraints stdio -setup {
	set script [makeFile {} script]
	file delete $script
	set f [open $script w]
	fconfigure $f -encoding utf-8
	puts $f {puts [list $argv0 $argv $tcl_interactive]}
	puts $f {puts [string equal \u20AC €]; exit}
	puts -nonewline $f {puts [string equal \u20ac }
	puts $f "\u20ac]; exit"
	close $f
	catch {set f [open "|[list [interpreter] -encoding utf-8 script]" r]}
} -body {
	read $f
} -cleanup {
	close $f
	removeFile script
} -result "script {} 0\n1\n"

test main-2.2 {Tk_MainEx: -encoding option} -constraints stdio -setup {
	set script [makeFile {} script]
	file delete $script
	set f [open $script w]
	fconfigure $f -encoding utf-8
	puts $f {puts [list $argv0 $argv $tcl_interactive]}
	puts $f {puts [string equal \u20AC €]; exit}
	puts -nonewline $f {puts [string equal \u20ac }
	puts $f "\u20ac]; exit"
	close $f
	catch {set f [open "|[list [interpreter] -encoding iso8859-1 script]" r]}
	catch {set f [open "|[list [interpreter] -encoding ascii script]" r]}
} -body {
	read $f
} -cleanup {
	close $f
	removeFile script
} -result "script {} 0\n0\n"

70
71
72
73
74
75
76
77


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+
+
















-
+








test main-2.3 {Tk_MainEx: -encoding option} -constraints stdio -setup {
	set script [makeFile {} script]
	file delete $script
	set f [open $script w]
	fconfigure $f -encoding utf-8
	puts $f {puts [list $argv0 $argv $tcl_interactive]}
	puts $f {puts [string equal \u20AC €]}
	puts -nonewline $f {puts [string equal \u20ac }
	puts $f "\u20ac]"
	close $f
	catch {set f [open "|[list [interpreter] -enc utf-8 script]" r+]}
} -body {
	type $f {
		puts $argv
		exit
	}
	gets $f
} -cleanup {
	close $f
	removeFile script
} -returnCodes ok -result {-enc utf-8 script}

test main-3.1 {Tk_ParseArgv: -help option} -constraints unix -body {
    # Run only on unix as Win32 pops up native dialog
    exec [interpreter] -help
} -returnCodes error -match glob -result {*application-specific initialization failed: Command-specific options:*}
} -returnCodes error -match glob -result {% application-specific initialization failed: Command-specific options:*}

test main-3.2 {Tk_ParseArgv: -help option} -setup {
    set maininterp [interp create]
} -body {
    $maininterp eval { set argc 1 ; set argv -help }
    load {} Tk $maininterp
} -cleanup {

Changes to tests/menu.test.

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43

44
45
46

47
48
49
50
51
52

53
54
55

56
57
58
59
60
61
62
63

64
65
66

67
68
69
70
71
72
73
74
75
76

77
78
79

80
81
82
83
84
85
86
87
88
89

90
91
92

93
94
95
96
97
98
99
100
101
102

103
104
105

106
107
108
109
110
111
112
113
114
115
116
117

118
119
120

121
122
123
124
125
126

127
128
129

130
131
132
133
134
135
136
137

138
139
140

141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
1
2
3


4
5
6
7
8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40

41
42
43

44
45
46
47
48
49

50
51
52

53
54
55
56
57
58
59
60

61
62
63

64
65
66
67
68
69
70
71
72
73

74
75
76

77
78
79
80
81
82
83
84
85
86

87
88
89

90
91
92
93
94
95
96
97
98
99

100
101
102

103
104
105
106
107
108
109
110
111
112
113
114

115
116
117

118
119
120
121
122
123

124
125
126

127
128
129
130
131
132
133
134

135
136
137

138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177








178
179
180
181
182
183
184



-
-
+
+











-
-















-
+








-
+


-
+





-
+


-
+







-
+


-
+









-
+


-
+









-
+


-
+









-
+


-
+











-
+


-
+





-
+


-
+







-
+


-
+









-
+



















-
+









-
-
-
-
-
-
-
-







# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1995-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit

# find the earth.gif file for use in these tests (tests 2.*)
set earthPhotoFile [file join [file dirname [info script]] earth.gif]
testConstraint hasEarthPhoto [file exists $earthPhotoFile]
testConstraint pressbutton [llength [info commands pressbutton]]
testConstraint movemouse [llength [info commands movemouse]]

test menu-1.1 {Tk_MenuCmd procedure} -body {
    menu
} -returnCodes error -result {wrong # args: should be "menu pathName ?-option value ...?"}
test menu-1.2 {Tk_MenuCmd procedure} -body {
    menu bogus
} -returnCodes error -result {bad window path name "bogus"}
test menu-1.3 {Tk_MenuCmd procedure} -body {
    destroy .m1
    menu .m1 foo
} -returnCodes error -result {unknown option "foo"}
test menu-1.4 {Tk_MenuCmd procedure} -body {
    destroy .m1
    menu .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}
test menu-1.5 {Tk_MenuCmd - creating menubar} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add cascade -label Test -menu ""
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-1.6 {Tk_MenuCmd procedure menu ref no cascade} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    menu .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}
test menu-1.7 {Tk_MenuCmd procedure one clone cascade} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    menu .m1
    .m1 add cascade -menu .m2
    menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}
test menu-1.8 {Tk_MenuCmd procedure two clone cascades} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}
test menu-1.9 {Tk_MenuCmd procedure two clone cascades different order} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    menu .m1
    .m1 add cascade -menu .m2
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    list [menu .m2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}
test menu-1.10 {Tk_MenuCmd procedure two clone cascades menus last} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    menu .m1
    .m1 add cascade -menu .m2
    list [menu .m2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}
test menu-1.11 {Tk_MenuCmd procedure three clones cascades} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    toplevel .t4 -menu .m1
    wm geometry .t4 +0+0
    menu .m1
    .m1 add cascade -menu .m2
    list [menu .m2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}
test menu-1.12 {Tk_MenuCmd procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    list [menu .m1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}
test menu-1.13 {Tk_MenuCmd procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    list [menu .m1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}
test menu-1.14 {Tk_MenuCmd procedure} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    toplevel .t4 -menu .m1
    wm geometry .t4 +0+0
    list [menu .m1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}

# Used for 2.1 - 2.30 tests
destroy .m1
menu .m1
test menu-2.1 {configuration options -activebackground #012345} -body {
    .m1 configure -activebackground #012345
    .m1 cget -activebackground
} -result {#012345}
test menu-2.2 {configuration options -activebackground non-existent} -body {
    .m1 configure -activebackground non-existent
} -returnCodes error -result {unknown color name "non-existent"}

test menu-2.3 {configuration options -activeborderwidth 1.3} -body {
    .m1 configure -activeborderwidth 1.3
    .m1 cget -activeborderwidth
} -result {1.3}
test menu-2.4 {configuration options -activeborderwidth badValue} -body {
    .m1 configure -activeborderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}

test menu-2.5 {configuration options -activeforeground #ff0000} -body {
    .m1 configure -activeforeground #ff0000
    .m1 cget -activeforeground
} -result {#ff0000}
test menu-2.6 {configuration options -activeforeground non-existent} -body {
    .m1 configure -activeforeground non-existent
} -returnCodes error -result {unknown color name "non-existent"}

test menu-2.6a {configuration options -activerelief sunken} -body {
    .m1 configure -activerelief sunken
    .m1 cget -activerelief
} -result {sunken}
test menu-2.6b {configuration options -activerelief badValue} -body {
    .m1 configure -activerelief badValue
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}

test menu-2.7 {configuration options -background #ff0000} -body {
    .m1 configure -background #ff0000
    .m1 cget -background
} -result {#ff0000}
test menu-2.8 {configuration options -background non-existent} -body {
    .m1 configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207







-
+








test menu-2.11 {configuration options -borderwidth 1.3} -body {
    .m1 configure -borderwidth 1.3
    .m1 cget -borderwidth
} -result {1.3}
test menu-2.12 {configuration options -borderwidth badValue} -body {
    .m1 configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}

test menu-2.13 {configuration options -cursor arrow} -body {
    .m1 configure -cursor arrow
    .m1 cget -cursor
} -result {arrow}
test menu-2.14 {configuration options -cursor badValue} -body {
    .m1 configure -cursor badValue
268
269
270
271
272
273
274
275

276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292

293
294

295
296
297
298
299
300
301
258
259
260
261
262
263
264

265
266
267
268

269
270
271
272
273
274
275
276
277
278
279
280
281

282
283

284
285
286
287
288
289
290
291







-
+



-
+












-
+

-
+







test menu-2.27 {configuration options -takefocus {any string}} -body {
    .m1 configure -takefocus {any string}
    .m1 cget -takefocus
} -result {any string}
test menu-2.28 {configuration options -tearoff 0} -body {
    .m1 configure -tearoff 0
    .m1 cget -tearoff
} -result 0
} -result {0}
test menu-2.29 {configuration options -tearoff 1} -body {
    .m1 configure -tearoff 1
    .m1 cget -tearoff
} -result 1
} -result {1}
test menu-2.30 {configuration options -tearoffcommand {any old string}} -body {
    .m1 configure -tearoffcommand {any old string}
    .m1 cget -tearoffcommand
} -result {any old string}
destroy .m1

# We need to test all of the options with all of the different types of
# menu entries. The following code sets up .m1 with 6 items. It then
# runs through the 2.31 - 2.228 tests below
# index 0 is tearoff, 1 command, 2 cascade, 3 separator, 4 checkbutton,
# 5 radiobutton
deleteWindows
menu .m1 -tearoff 1
menu .m1
.m1 add command -label "command"
menu .m2 -tearoff 1
menu .m2
.m2 add command -label "test"
.m1 add cascade -label "cascade" -menu .m2
.m1 add separator
.m1 add checkbutton -label "checkbutton" -variable check -onvalue on -offvalue off
.m1 add radiobutton -label "radiobutton" -variable radio

if {[testConstraint hasEarthPhoto]} {
543
544
545
546
547
548
549
550

551
552
553
554
555

556
557
558
559
560
561
562
563
564

565
566
567
568
569

570
571
572
573
574
575
576
533
534
535
536
537
538
539

540
541
542
543
544

545
546
547
548
549
550
551
552
553

554
555
556
557
558

559
560
561
562
563
564
565
566







-
+




-
+








-
+




-
+







test menu-2.85 {entry configuration options 0 -columnbreak 1 tearoff} -body {
    .m1 entryconfigure 0 -columnbreak 1
} -returnCodes error -result {unknown option "-columnbreak"}

test menu-2.86 {entry configuration options 1 -columnbreak 1 command} -body {
    .m1 entryconfigure 1 -columnbreak 1
    lindex [.m1 entryconfigure 1 -columnbreak] 4
} -result 1
} -result {1}

test menu-2.87 {entry configuration options 2 -columnbreak 1 cascade} -body {
    .m1 entryconfigure 2 -columnbreak 1
    lindex [.m1 entryconfigure 2 -columnbreak] 4
} -result 1
} -result {1}

test menu-2.88 {entry configuration options 3 -columnbreak 1 separator} -body {
    .m1 entryconfigure 3 -columnbreak 1
} -returnCodes error -result {unknown option "-columnbreak"}

test menu-2.89 {entry configuration options 4 -columnbreak 1 checkbutton} -body {
    .m1 entryconfigure 4 -columnbreak 1
    lindex [.m1 entryconfigure 4 -columnbreak] 4
} -result 1
} -result {1}

test menu-2.90 {entry configuration options 5 -columnbreak 1 radiobutton} -body {
    .m1 entryconfigure 5 -columnbreak 1
    lindex [.m1 entryconfigure 5 -columnbreak] 4
} -result 1
} -result {1}

test menu-2.91 {entry configuration options 0 -command beep tearoff} -body {
    .m1 entryconfigure 0 -command beep
} -returnCodes error -result {unknown option "-command"}

test menu-2.92 {entry configuration options 1 -command beep command} -body {
    .m1 entryconfigure 1 -command beep
827
828
829
830
831
832
833
834

835
836
837
838
839

840
841
842
843
844
845
846
817
818
819
820
821
822
823

824
825
826
827
828

829
830
831
832
833
834
835
836







-
+




-
+







test menu-2.142 {entry configuration options 3 -indicatoron 1 separator} -body {
    .m1 entryconfigure 3 -indicatoron 1
} -returnCodes error -result {unknown option "-indicatoron"}

test menu-2.143 {entry configuration options 4 -indicatoron 1 checkbutton} -body {
    .m1 entryconfigure 4 -indicatoron 1
    lindex [.m1 entryconfigure 4 -indicatoron] 4
} -result 1
} -result {1}

test menu-2.144 {entry configuration options 5 -indicatoron 1 radiobutton} -body {
    .m1 entryconfigure 5 -indicatoron 1
    lindex [.m1 entryconfigure 5 -indicatoron] 4
} -result 1
} -result {1}

test menu-2.145 {entry configuration options 0 -label test tearoff} -body {
    .m1 entryconfigure 0 -label test
} -returnCodes error -result {unknown option "-label"}

test menu-2.146 {entry configuration options 1 -label test command} -body {
    .m1 entryconfigure 1 -label test
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204

1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1216

1217
1218
1219
1220

1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235

1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249

1250
1251
1252
1253
1254
1255

1256
1257
1258

1259
1260
1261
1262
1263
1264

1265
1266
1267
1268
1269
1270
1271

1272
1273
1274

1275
1276
1277
1278
1279
1280
1281

1282
1283
1284

1285
1286
1287
1288
1289
1290

1291
1292
1293

1294
1295
1296
1297
1298

1299
1300
1301

1302
1303
1304
1305
1306

1307
1308
1309

1310
1311
1312
1313
1314
1315


1316
1317

1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329

1330
1331
1332
1333
1334
1335

1336
1337
1338

1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350

1351
1352
1353
1354
1355

1356
1357
1358

1359
1360
1361
1362
1363

1364
1365
1366

1367
1368
1369
1370
1371
1372


1373
1374

1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385

1386
1387
1388

1389
1390
1391
1392
1393
1394

1395
1396
1397

1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409

1410
1411

1412
1413
1414
1415

1416
1417
1418
1419
1420

1421
1422
1423

1424
1425
1426
1427
1428
1429

1430
1431
1432

1433
1434
1435
1436
1437
1438
1439
1440

1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502

1503
1504
1505

1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524


1525
1526

1527
1528
1529
1530
1531
1532

1533
1534
1535

1536
1537
1538
1539
1540
1541
1542

1543
1544
1545

1546
1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557

1558
1559

1560
1561
1562
1563
1564
1565
1566
1567
1568

1569
1570
1571

1572
1573
1574
1575
1576
1577

1578
1579
1580
1581
1582
1583

1584
1585
1586

1587
1588
1589
1590
1591

1592
1593
1594

1595
1596
1597
1598
1599

1600
1601
1602

1603
1604
1605
1606
1607
1608
1609

1610
1611
1612

1613
1614
1615
1616
1617
1618
1619


1620
1621

1622
1623
1624
1625
1626

1627
1628
1629

1630
1631
1632
1633
1634

1635
1636
1637

1638
1639

1640
1641
1642

1643
1644
1645

1646
1647
1648

1649
1650
1651
1652
1653

1654
1655
1656

1657
1658
1659
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
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179
1180

1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224

1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244

1245
1246
1247

1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260

1261
1262
1263

1264
1265
1266
1267
1268
1269
1270

1271
1272
1273

1274
1275
1276
1277
1278
1279

1280
1281
1282

1283
1284
1285
1286
1287

1288
1289
1290

1291
1292
1293
1294
1295

1296
1297
1298

1299
1300
1301
1302
1303


1304
1305
1306

1307
1308
1309
1310
1311
1312

1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324

1325
1326
1327

1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344

1345
1346
1347

1348
1349
1350
1351
1352

1353
1354
1355

1356
1357
1358
1359
1360


1361
1362
1363

1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374

1375
1376
1377

1378
1379
1380
1381
1382
1383

1384
1385
1386

1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398

1399
1400

1401
1402
1403
1404

1405
1406
1407
1408
1409

1410
1411
1412

1413
1414
1415
1416
1417
1418

1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432

1433
1434
1435
1436
1437
1438
1439
1440
1441

1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473

1474
1475
1476
1477
1478
1479

1480
1481
1482
1483
1484
1485

1486
1487
1488
1489
1490
1491

1492
1493
1494

1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506

1507
1508
1509
1510
1511
1512


1513
1514
1515

1516
1517
1518
1519
1520
1521

1522
1523
1524

1525
1526
1527
1528
1529
1530
1531

1532
1533
1534

1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546

1547
1548

1549
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560

1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572

1573
1574
1575

1576
1577
1578
1579
1580

1581
1582
1583

1584
1585
1586
1587
1588

1589
1590
1591

1592
1593
1594
1595
1596
1597
1598

1599
1600
1601

1602
1603
1604
1605
1606
1607


1608
1609
1610

1611
1612
1613
1614
1615

1616
1617
1618

1619
1620
1621
1622
1623

1624
1625
1626

1627
1628

1629
1630
1631

1632
1633
1634

1635
1636
1637

1638
1639
1640
1641
1642

1643
1644
1645

1646
1647
1648
1649
1650

1651
1652
1653

1654
1655

1656
1657
1658

1659
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







-
+




-
+








-
+




-
+







-
+



-
+







-
+



-
+














-
+


-
+










-
+





-
+


-
+





-
+






-
+


-
+






-
+


-
+





-
+


-
+




-
+


-
+




-
+


-
+




-
-
+
+

-
+





-
+





-
+





-
+


-
+





-
+





-
+




-
+


-
+




-
+


-
+




-
-
+
+

-
+





-
+




-
+


-
+





-
+


-
+





-
+





-
+

-
+



-
+




-
+


-
+





-
+


-
+







-
+


-
+








-
+


-
+








-
+













-
+





-
+





-
+





-
+





-
+


-
+





-
+





-
+





-
-
+
+

-
+





-
+


-
+






-
+


-
+





-
+





-
+

-
+








-
+


-
+





-
+





-
+


-
+




-
+


-
+




-
+


-
+






-
+


-
+





-
-
+
+

-
+




-
+


-
+




-
+


-
+

-
+


-
+


-
+


-
+




-
+


-
+




-
+


-
+

-
+


-
+





-
+


-
+





-
+

-
+


-
+




-
+


-
+




-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+

-
+


-
+


-
+




-
+


-
+

-
+


-
+



-
+


-
+




-
+

-
-
+
+

-
+


-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+




-
-
+
+

-
+

















-
+


















-
-
-
-
-
-
-
-








-
+








-
+

-
-
+
+







-
+







test menu-2.217 {entry configuration options 0 -underline 0 tearoff} -body {
    .m1 entryconfigure 0 -underline 0
} -returnCodes error -result {unknown option "-underline"}

test menu-2.218 {entry configuration options 1 -underline 0 command} -body {
    .m1 entryconfigure 1 -underline 0
    lindex [.m1 entryconfigure 1 -underline] 4
} -result 0
} -result {0}

test menu-2.219 {entry configuration options 2 -underline 0 cascade} -body {
    .m1 entryconfigure 2 -underline 0
    lindex [.m1 entryconfigure 2 -underline] 4
} -result 0
} -result {0}

test menu-2.220 {entry configuration options 3 -underline 0 separator} -body {
    .m1 entryconfigure 3 -underline 0
} -returnCodes error -result {unknown option "-underline"}

test menu-2.221 {entry configuration options 4 -underline 0 checkbutton} -body {
    .m1 entryconfigure 4 -underline 0
    lindex [.m1 entryconfigure 4 -underline] 4
} -result 0
} -result {0}

test menu-2.222 {entry configuration options 5 -underline 0 radiobutton} -body {
    .m1 entryconfigure 5 -underline 0
    lindex [.m1 entryconfigure 5 -underline] 4
} -result 0
} -result {0}

test menu-2.223 {entry configuration options 0 -underline 3p tearoff} -body {
    .m1 entryconfigure 0 -underline 3p
} -returnCodes error -result {unknown option "-underline"}

test menu-2.224 {entry configuration options 1 -underline 3p command} -body {
    .m1 entryconfigure 1 -underline 3p
} -returnCodes error -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "3p"}

test menu-2.225 {entry configuration options 2 -underline 3p cascade} -body {
    .m1 entryconfigure 2 -underline 3p
} -returnCodes error -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "3p"}

test menu-2.226 {entry configuration options 3 -underline 3p separator} -body {
    .m1 entryconfigure 3 -underline 3p
} -returnCodes error -result {unknown option "-underline"}

test menu-2.227 {entry configuration options 4 -underline 3p checkbutton} -body {
    .m1 entryconfigure 4 -underline 3p
} -returnCodes error -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "3p"}

test menu-2.228 {entry configuration options 5 -underline 3p radiobutton} -body {
    .m1 entryconfigure 5 -underline 3p
} -returnCodes error -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "3p"}

deleteWindows
if {[testConstraint hasEarthPhoto]} {
    image delete image1
}



test menu-3.1 {MenuWidgetCmd procedure} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 option ?arg ...?"}
test menu-3.2 {MenuWidgetCmd, Tcl_Preserve and Tcl_Release} -constraints {
    nonUnixUserInteraction
	nonUnixUserInteraction
} -setup {
    destroy .m1
} -body  {
    menu .m1 -postcommand "destroy .m1"
    .m1 add command -label "menu-3.2: Hit Escape"
    .m1 post 40 40
} -cleanup {
    destroy .m1
} -returnCodes ok -result {}
test menu-3.3 {MenuWidgetCmd procedure, "activate" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 activate
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 activate index"}
test menu-3.4 {MenuWidgetCmd procedure, "activate" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 activate "foo"
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.5 {MenuWidgetCmd procedure, "activate" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add separator
    .m1 activate 2
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.6 {MenuWidgetCmd procedure, "activate" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 entryconfigure 1 -state disabled
    .m1 activate 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.7 {MenuWidgetCmd procedure, "activate" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 activate 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.8 {MenuWidgetCmd procedure, "add" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 add type ?-option value ...?"}
test menu-3.9 {MenuWidgetCmd procedure, "add" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add foo
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {bad menu entry type "foo": must be cascade, checkbutton, command, radiobutton, or separator}
test menu-3.10 {MenuWidgetCmd procedure, "add" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add separator
} -cleanup {
    destroy .m1
} -result {e001}
	destroy .m1
} -result {}
test menu-3.11 {MenuWidgetCmd procedure, "cget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 cget
} -returnCodes error -result {wrong # args: should be ".m1 cget option"}
test menu-3.12 {MenuWidgetCmd procedure, "cget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 cget -gorp
} -returnCodes error -result {unknown option "-gorp"}
test menu-3.13 {MenuWidgetCmd procedure, "cget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 configure -postcommand "Some string"
    .m1 cget -postcommand
} -cleanup {
    destroy .m1
	destroy .m1
} -result {Some string}
test menu-3.14 {MenuWidgetCmd procedure, "clone" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 clone
} -returnCodes error -result {wrong # args: should be ".m1 clone newMenuName ?menuType?"}
test menu-3.15 {MenuWidgetCmd procedure, "clone" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 clone a b c d
} -returnCodes error -result {wrong # args: should be ".m1 clone newMenuName ?menuType?"}
test menu-3.16 {MenuWidgetCmd procedure, "clone" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 clone .m1.clone1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.17 {MenuWidgetCmd procedure, "clone" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 clone .m1.clone1 tearoff
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.18 {MenuWidgetCmd procedure, "configure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    llength [.m1 configure]
} -cleanup {
    destroy .m1
} -result 21
	destroy .m1
} -result {20}
test menu-3.19 {MenuWidgetCmd procedure, "configure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 configure -gorp
} -returnCodes error -result {unknown option "-gorp"}
test menu-3.20 {MenuWidgetCmd procedure, "configure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 configure -postcommand "A random String"
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.21 {MenuWidgetCmd procedure, "configure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 configure -postcommand "Another string"
    lindex [.m1 configure -postcommand] 4
} -cleanup {
    destroy .m1
	destroy .m1
} -result {Another string}
test menu-3.22 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 delete
} -returnCodes error -result {wrong # args: should be ".m1 delete first ?last?"}
test menu-3.23 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 delete foo
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.24 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 delete 0 "foo"
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.25 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 delete 0
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.26 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "foo"
    .m1 delete 1 0
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.27 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "1"
    .m1 add command -label "2"
    .m1 add command -label "3"
    .m1 delete 1 3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.28 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "1"
    .m1 add command -label "2"
    .m1 add command -label "3"
    .m1 activate 2
    .m1 delete 1 3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.29 {MenuWidgetCmd procedure, "delete" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "1"
    .m1 add command -label "2"
    .m1 add command -label "3"
    .m1 activate 3
    .m1 delete 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.29+1 {MenuWidgetCmd, "delete", Bug 220950} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "bogus"
    .m1 add command -label "ok"
    .m1 delete 10 20
    .m1 entrycget last -label
} -cleanup {
    destroy .m1
} -result ok
test menu-3.30 {MenuWidgetCmd procedure, "entrycget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 entrycget
} -returnCodes error -result {wrong # args: should be ".m1 entrycget index option"}
test menu-3.31 {MenuWidgetCmd procedure, "entrycget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 entrycget index option foo
} -returnCodes error -result {wrong # args: should be ".m1 entrycget index option"}
test menu-3.32 {MenuWidgetCmd procedure, "entrycget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 entrycget foo -label
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.33 {MenuWidgetCmd procedure, "entrycget" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 entrycget 1 -label
} -cleanup {
    destroy .m1
	destroy .m1
} -result {test}
test menu-3.34 {MenuWidgetCmd procedure, "entryconfigure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 entryconfigure
} -returnCodes error -result {wrong # args: should be ".m1 entryconfigure index ?-option value ...?"}
test menu-3.35 {MenuWidgetCmd procedure, "entryconfigure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 entryconfigure foo
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.36 {MenuWidgetCmd procedure, "entryconfigure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    llength [.m1 entryconfigure 1]
} -cleanup {
    destroy .m1
} -result 15
	destroy .m1
} -result {15}
test menu-3.37 {MenuWidgetCmd procedure, "entryconfigure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    lindex [.m1 entryconfigure 1 -label] 4
} -cleanup {
    destroy .m1
	destroy .m1
} -result {test}
test menu-3.38 {MenuWidgetCmd procedure, "entryconfigure" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 entryconfigure 1 -label "changed"
    lindex [.m1 entryconfigure 1 -label] 4
} -cleanup {
    destroy .m1
	destroy .m1
} -result {changed}
test menu-3.39 {MenuWidgetCmd procedure, "index" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 index
} -returnCodes error -result {wrong # args: should be ".m1 index string"}
test menu-3.40 {MenuWidgetCmd procedure, "index" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 index foo
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.41 {MenuWidgetCmd procedure, "index" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "3"
    .m1 add command -label "another label"
    .m1 add command -label "end"
    .m1 add command -label "3a"
    .m1 add command -label "final entry"
    list [.m1 index "test"] [.m1 index "3"] [.m1 index "3a"] [.m1 index "end"]
} -cleanup {
    destroy .m1
	destroy .m1
} -result {1 3 5 6}
test menu-3.42 {MenuWidgetCmd procedure, "insert" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 insert
} -returnCodes error -result {wrong # args: should be ".m1 insert index type ?-option value ...?"}
test menu-3.43 {MenuWidgetCmd procedure, "insert" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 insert 1 command -label "test"
    .m1 entrycget 1 -label
} -cleanup {
    destroy .m1
	destroy .m1
} -result {test}
test menu-3.44 {MenuWidgetCmd procedure, "invoke" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 invoke
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 invoke index"}
test menu-3.45 {MenuWidgetCmd procedure, "invoke" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 invoke foo
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.46 {MenuWidgetCmd procedure, "invoke" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add command -label "set foo" -command "set foo hello"
    list [.m1 invoke 1] [set foo] [unset foo]
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes ok -result {hello hello {}}
test menu-3.47 {MenuWidgetCmd procedure, "post" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "On Windows, hit Escape to get this menu to go away"
    .m1 post
} -cleanup {
    destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 post x y ?index?"}
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 post x y"}
test menu-3.48 {MenuWidgetCmd procedure, "post" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 post foo 40
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {expected integer but got "foo"}
test menu-3.49 {MenuWidgetCmd procedure, "post" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 post 40 bar
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {expected integer but got "bar"}
test menu-3.50 {MenuWidgetCmd procedure, "post" option} -constraints {
    nonUnixUserInteraction
	nonUnixUserInteraction
} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "menu-3.50: hit Escape" -command "puts hello"
    .m1 add command -label "menu-3.53: hit Escape" -command "puts hello"
    .m1 post 40 40
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.51 {MenuWidgetCmd procedure, "postcascade" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 postcascade
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 postcascade index"}
test menu-3.52 {MenuWidgetCmd procedure, "postcascade" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 postcascade foo
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.53 {MenuWidgetCmd procedure, "postcascade" option} -constraints {
    nonUnixUserInteraction
	nonUnixUserInteraction
} -setup {
    destroy .m1 .m2
	destroy .m1 .m2
} -body {
    menu .m1
    .m1 add command -label "menu-3.53 - hit Escape"
    .m1 add command -label "menu-3.56 - hit Escape"
    menu .m2
    .m1 post 40 40
    .m1 add cascade -menu .m2
    .m1 postcascade 1
} -cleanup {
    destroy .m1 .m2
	destroy .m1 .m2
} -result {}
test menu-3.54 {MenuWidgetCmd procedure, "postcascade" option} -setup {
    destroy .m1 .m2
	destroy .m1 .m2
} -body {
    menu .m1
    menu .m2
    .m1 add cascade -menu .m2 -label "menu-3.57 - hit Escape"
    .m1 postcascade 1
    .m1 postcascade {}
    .m1 postcascade none
} -cleanup {
    destroy .m1 .m2
	destroy .m1 .m2
} -result {}
test menu-3.55 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 type
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 type index"}
test menu-3.56 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 type foo
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {bad menu entry index "foo"}
test menu-3.57 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 type 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {command}
test menu-3.58 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add separator
    .m1 type 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {separator}
test menu-3.59 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add checkbutton -label "test"
    .m1 type 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {checkbutton}
test menu-3.60 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add radiobutton -label "test"
    .m1 type 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {radiobutton}
test menu-3.61 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add cascade -label "test"
    .m1 type 1
} -cleanup {
    destroy .m1
	destroy .m1
} -result {cascade}
test menu-3.62 {MenuWidgetCmd procedure, "type" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 type 0
} -cleanup {
    destroy .m1
	destroy .m1
} -result {tearoff}
test menu-3.63 {MenuWidgetCmd procedure, "unpost" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 unpost foo
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 unpost"}
test menu-3.64 {MenuWidgetCmd procedure, "unpost" option} -constraints {
    nonUnixUserInteraction
	nonUnixUserInteraction
} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 add command -label "menu-3.64 - hit Escape"
    .m1 add command -label "menu-3.68 - hit Escape"
    .m1 post 40 40
    .m1 unpost
} -cleanup {
    destroy .m1
	destroy .m1
} -result {}
test menu-3.65 {MenuWidgetCmd procedure, "yposition" option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 yposition
} -cleanup {
    destroy .m1
	destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 yposition index"}
test menu-3.66a {MenuWidgetCmd procedure, "yposition" option, no tearoff} -setup {
    destroy .m1
test menu-3.66 {MenuWidgetCmd procedure, "yposition" option} -setup {
	destroy .m1
} -body {
    menu .m1 -tearoff 0
    menu .m1
    .m1 yposition 1
} -cleanup {
    destroy .m1
} -result 0
	destroy .m1
} -result {1}
test menu-3.66b {MenuWidgetCmd procedure, "yposition" option, with tearoff} -constraints {
    notAqua
} -setup {
    destroy .m1
} -body {
    # on Win or Linux, tearoff menus are supported
    # see menu-3.66c for aqua
    menu .m1 -tearoff 1
    .m1 yposition 1
} -cleanup {
    destroy .m1
} -result 1
test menu-3.66c {MenuWidgetCmd procedure, "yposition" option, with tearoff} -constraints {
    aqua
} -setup {
    destroy .m1
} -body {
    # on OS X, tearoff menus are not supported
    # see menu-3.66b for win or linux
    menu .m1 -tearoff 1
    .m1 yposition 1
} -cleanup {
    destroy .m1
} -result 0
test menu-3.67 {MenuWidgetCmd procedure, bad option} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    .m1 foo
} -cleanup {
    destroy .m1
} -returnCodes error -result {bad option "foo": must be activate, add, cget, clone, configure, delete, entrycget, entryconfigure, id, index, insert, invoke, post, postcascade, type, unpost, xposition, or yposition}
	destroy .m1
} -returnCodes error -result {bad option "foo": must be activate, add, cget, clone, configure, delete, entrycget, entryconfigure, index, insert, invoke, post, postcascade, type, unpost, xposition, or yposition}
test menu-3.68 {MenuWidgetCmd procedure, fix for bug#508988} -setup {
    deleteWindows
	deleteWindows
} -body {
    set t .t
    set m1 .t.m1
    set c1 .t.c1
    set c2 .t.c2
    toplevel .t
    menu $m1 -tearoff 1
    menu $c1 -tearoff 1
    $c1 add command -label c1
    menu $c2 -tearoff 1
    $c2 add command -label c2
    $m1 add cascade -label c1 -menu $c1
    $t configure -menu $m1
    $m1 entryconfigure 1 -menu $c2 -label c2
    $t configure -menu ""
    list [winfo exists $c1] [winfo exists $c2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 1}
test menu-3.69 {MenuWidgetCmd procedure, "xposition" option} -setup {
    destroy .m1
    menu .m1
} -body {
    .m1 xposition
} -cleanup {
    destroy .m1
} -returnCodes error -result {wrong # args: should be ".m1 xposition index"}
test menu-3.70 {MenuWidgetCmd procedure, "xposition" option} -setup {
    destroy .m1
    menu .m1
} -body {
    .m1 xposition 1
    subst {} ;# just checking that the xposition does not produce an error...
} -cleanup {
    destroy .m1
} -result {}
test menu-3.71 {MenuWidgetCmd procedure, "index end" option, bug [f3cd942e9e]} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 index "end"
} -cleanup {
    destroy .m1
} -result {}


test menu-4.1 {TkInvokeMenu: disabled} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add checkbutton -label "test" -variable foo -onvalue on -offvalue off \
    -state disabled
	-state disabled
    list [catch {.m1 invoke 1} msg] $foo
} -cleanup {
    destroy .m1
} -result {0 off}
test menu-4.2 {TkInvokeMenu: tearoff} -setup {
    destroy .m1
} -body {
    menu .m1
    catch {.m1 invoke 0}
	catch {.m1 invoke 0}
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}
test menu-4.3 {TkInvokeMenu: checkbutton -on} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add checkbutton -label "test" -variable foo -onvalue on -offvalue off
    list [catch {.m1 invoke 1} msg] $msg [catch {set foo} msg2] $msg2 \
            [catch {unset foo} msg3] $msg3
		[catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
} -result {0 {} 0 on 0 {}}
test menu-4.4 {TkInvokeMenu: checkbutton -off} -setup {
    destroy .m1
} -body {
    catch {unset foo}
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
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







-
+





-
+





-
+





-
+





-
+











-
+











-
+









-
+








-
+




-
+



-
+







    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add checkbutton -label "test" -variable foo(1) -onvalue on
    list [catch {.m1 invoke 1} msg] $msg [catch {set foo(1)} msg2] $msg2 [catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 0 on 0 {}}
test menu-4.6 {TkInvokeMenu: radiobutton} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1 -tearoff 1
    menu .m1
    .m1 add radiobutton -label "1" -variable foo -value one
    .m1 add radiobutton -label "2" -variable foo -value two
    .m1 add radiobutton -label "3" -variable foo -value three
    list [catch {.m1 invoke 1} msg] $msg [catch {set foo} msg2] $msg2 [catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 0 one 0 {}}
test menu-4.7 {TkInvokeMenu: radiobutton} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1 -tearoff 1
    menu .m1
    .m1 add radiobutton -label "1" -variable foo -value one
    .m1 add radiobutton -label "2" -variable foo -value two
    .m1 add radiobutton -label "3" -variable foo -value three
    list [catch {.m1 invoke 2} msg] $msg [catch {set foo} msg2] $msg2 [catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 0 two 0 {}}
test menu-4.8 {TkInvokeMenu: radiobutton} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add radiobutton -label "1" -variable foo -value one
    .m1 add radiobutton -label "2" -variable foo -value two
    .m1 add radiobutton -label "3" -variable foo -value three
    list [catch {.m1 invoke 3} msg] $msg [catch {set foo} msg2] $msg2 [catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 0 three 0 {}}
test menu-4.9 {TkInvokeMenu: radiobutton array element} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add radiobutton -label "1" -variable foo(2) -value one
    .m1 add radiobutton -label "2" -variable foo(2) -value two
    .m1 add radiobutton -label "3" -variable foo(2) -value three
    list [catch {.m1 invoke 3} msg] $msg [catch {set foo(2)} msg2] $msg2 [catch {unset foo} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 0 three 0 {}}
test menu-4.10 {TkInvokeMenu} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add command -label "test" -command "set menu_test menu-4.8"
    list [catch {.m1 invoke 1} msg] $msg [catch {set menu_test} msg2] $msg2 [catch {unset menu_test} msg3] $msg3
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 menu-4.8 0 menu-4.8 0 {}}
test menu-4.11 {TkInvokeMenu} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add cascade -label "test" -menu .m1.m2
    list [catch {.m1 invoke 1} msg] $msg
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {}}
test menu-4.12 {TkInvokeMenu} -setup {
    destroy .m1
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "test" -command ".m1 delete 1"
    list [catch {.m1 invoke 1} msg] $msg [catch {.m1 type "test"} msg2] $msg2
} -cleanup {
    destroy .m1
	destroy .m1
} -result {0 {} 1 {bad menu entry index "test"}}

test menu-5.1 {DestroyMenuInstance} -setup {
    destroy .m1
} -body {
    menu .m1
    destroy .m1
2040
2041
2042
2043
2044
2045
2046
2047

2048
2049
2050
2051
2052
2053
2054
1998
1999
2000
2001
2002
2003
2004

2005
2006
2007
2008
2009
2010
2011
2012







-
+







    menu .m1
    menu .m2
    .m1 add cascade -menu .m2
    . configure -menu .m1
    list [destroy .m2] [.m1 entrycget 1 -menu] [. configure -menu ""] [destroy .m1]
} -returnCodes ok -result {{} .m2 {} {}}
test menu-5.6 {DestroyMenuInstance - cascades of cloned menus} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    menu .m2
    . configure -menu .m1
    toplevel .t2
    wm geometry .t2 +0+0
2066
2067
2068
2069
2070
2071
2072
2073

2074
2075
2076
2077
2078
2079
2080
2024
2025
2026
2027
2028
2029
2030

2031
2032
2033
2034
2035
2036
2037
2038







-
+







    destroy .m1
} -body {
    menu .m1
    set tearoff1 [tk::TearOffMenu .m1]
    set tearoff2 [tk::TearOffMenu .m1]
    list [destroy $tearoff1] [destroy .m1]
} -returnCodes ok -result {{} {}}
test menu-5.9 {DestroyMenuInstace - main menu} -setup {
test menu-5.9 {DestroyMenuInstace - master menu} -setup {
    destroy .m1
} -body {
    menu .m1
    tk::TearOffMenu .m1
    destroy .m1
} -returnCodes ok
test menu-5.10 {DestroyMenuInstance - freeing entries} -setup {
2136
2137
2138
2139
2140
2141
2142
2143

2144
2145
2146
2147
2148
2149
2150
2151
2152

2153
2154
2155
2156
2157
2158
2159
2094
2095
2096
2097
2098
2099
2100

2101
2102
2103
2104
2105
2106
2107
2108
2109

2110
2111
2112
2113
2114
2115
2116
2117







-
+








-
+







    destroy .m1 .m2
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m1.m3
    destroy .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes ok
test menu-6.5 {TkDestroyMenu} -setup {
    destroy .m1 .m2
} -body {
    menu .m1
    .m1 clone .m2
    destroy .m1
    winfo exists .m2
} -result 0
} -result {0}
test menu-6.6 {TkDestroyMenu} -setup {
    destroy .m1 .m2
} -body {
    menu .m1
    .m1 clone .m2 tearoff
    destroy .m1
} -result {}
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
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







-
+







-
+








-
+








-
+








-
+


-
+







} -result {0 0}
test menu-6.9 {TkDestroyMenu} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
    list [destroy .m2] [destroy .m3] [destroy .m1]
	list [destroy .m2] [destroy .m3] [destroy .m1]
} -returnCodes ok -result {{} {} {}}
test menu-6.10 {TkDestroyMenu} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
    list [destroy .m3] [destroy .m1]
	list [destroy .m3] [destroy .m1]
} -returnCodes ok -result {{} {}}
test menu-6.11 {TkDestroyMenu} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
    .m1 clone .m4
    list [destroy .m2] [destroy .m1]
	list [destroy .m2] [destroy .m1]
} -returnCodes ok -result {{} {}}
test menu-6.12 {TkDestroyMenu} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
    .m1 clone .m4
    list [destroy .m3] [destroy .m1]
	list [destroy .m3] [destroy .m1]
} -returnCodes ok -result {{} {}}
test menu-6.13 {TkDestroyMenu} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
    .m1 clone .m4
    list [destroy .m4] [destroy .m1]
	list [destroy .m4] [destroy .m1]
} -returnCodes ok -result {{} {}}
test menu-6.14 {TkDestroyMenu} -setup {
    destroy .m1
	destroy .m1
} -body {
    menu .m1
    . configure -menu .m1
    list [destroy .m1] [. configure -menu ""]
} -returnCodes ok -result {{} {}}
test menu-6.15 {TkDestroyMenu} -setup {
    deleteWindows
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2201
2202
2203
2204
2205
2206
2207








2208
2209
2210
2211
2212
2213
2214







-
-
-
-
-
-
-
-







    toplevel .t3
    wm geometry .t3 +0+0
    . configure -menu .m1
    .t2 configure -menu .m1
    .t3 configure -menu .m1
    list [destroy .m1] [destroy .t2] [destroy .t3] [. configure -menu ""]
} -result {{} {} {} {}}
test menu-6.17 {TkDestroyMenu - bug 14a9b62e1d} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -command {destroy .m1}
    .m1 invoke end
    winfo exists .m1
} -result {0}

test menu-7.1 {UnhookCascadeEntry} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    destroy .m1
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
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







-
+










-
+










-
+










-
+







    menu .m1
    menu .m2
    .m1 add cascade -menu .cascade
    .m2 add cascade -menu .cascade
    list [destroy .m1] [destroy .m2]
} -returnCodes ok -result {{} {}}
test menu-7.5 {UnhookCascadeEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    menu .m3
    .m1 add cascade -menu .cascade
    .m2 add cascade -menu .cascade
    .m3 add cascade -menu .cascade
    list [destroy .m1] [destroy .m2 .m3]
} -returnCodes ok -result {{} {}}
test menu-7.6 {UnhookCascadeEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    menu .m3
    .m1 add cascade -menu .cascade
    .m2 add cascade -menu .cascade
    .m3 add cascade -menu .cascade
    list [destroy .m2] [destroy .m1 .m3]
} -returnCodes ok -result {{} {}}
test menu-7.7 {UnhookCascadeEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    menu .m3
    .m1 add cascade -menu .cascade
    .m2 add cascade -menu .cascade
    .m3 add cascade -menu .cascade
    list [destroy .m3] [destroy .m1 .m2]
} -returnCodes ok -result {{} {}}
test menu-7.8 {UnhookCascadeEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    .m1 add cascade -menu .m2
    list [destroy .m1] [destroy .m2]
} -returnCodes ok -result {{} {}}
test menu-7.9 {UnhookCascadeEntry} -setup {
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
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







-
+





-
+
















-
+








-
+







-
+








-
+









-
+










-
+


-
+





-
+


-
+





-
+







-
+












-
+









-
+











-
+








-
+








-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+






-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+












-
+


-
+










-
+


-
+





-
+


-
+




-
-
+
+

-
+




-
-
+
+







    menu .m1
    .m1 add command -label "test"
    list [.m1 delete 1] [destroy .m1]
} -result {{} {}}
test menu-8.6 {DestroyMenuEntry} -setup {
    destroy .m1
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "one"
    .m1 add command -label "two"
    list [.m1 delete 1] [.m1 entrycget 1 -label] [destroy .m1]
} -result {{} two {}}
test menu-8.7 {DestroyMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "one"
    .m1 clone .m2 tearoff
    list [.m2 delete 1] [destroy .m1]
} -result {{} {}}


# test menu-9 - Can only change when fonts change on system, which cannot
# be done from tcl.
test menu-9.1 {ConfigureMenu} -setup {
    destroy .m1
} -body {
    menu .m1
    list [.m1 configure -postcommand "beep"] [.m1 cget -postcommand]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} beep}
test menu-9.2 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    list [.m1 configure -tearoff 0] [.m1 entrycget 1 -label]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} test}
test menu-9.3 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    list [.m1 configure -postcommand "beep"] [.m1 cget -postcommand]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} beep}
test menu-9.4 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -fg red
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-9.5 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "two"
    .m1 configure -fg red
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-9.6 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "two"
    .m1 add command -label "three"
    .m1 configure -fg red
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-9.7 {ConfigureMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 tearoff
    list [.m1 configure -fg red] [.m2 cget -fg]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} red}
test menu-9.8 {ConfigureMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 tearoff
    list [.m2 configure -fg red] [.m1 cget -fg]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} red}
test menu-9.9 {ConfigureMenu}  -setup {
    destroy .m1
} -body {
    menu .m1
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}


test menu-10.1 {PostProcessEntry: array variable} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    set foo(1) on
    .m1 add checkbutton -variable foo(1) -onvalue on -offvalue off -label "Nonsense"
    set foo(1)
} -cleanup {
    deleteWindows
	deleteWindows
} -result {on}
test menu-10.2 {PostProcessEntry: array variable} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add checkbutton -variable foo(1) -onvalue on -offvalue off -label "Nonsense"
    set foo(1)
} -cleanup {
    deleteWindows
	deleteWindows
} -result {off}


test menu-11.1 {ConfigureMenuEntry} -setup {
    destroy .m1
} -body {
    catch {unset foo}
    menu .m1
    .m1 add checkbutton -variable foo -onvalue on -offvalue off -label "Nonsense"
    list [.m1 entryconfigure 1 -variable bar] [.m1 entrycget 1 -variable]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} bar}
test menu-11.2 {ConfigureMenuEntry} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command -label "test"
    list [.m1 entryconfigure 1 -label ""] [.m1 entrycget 1 -label]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-11.3 {ConfigureMenuEntry} -setup {
    destroy .m1
} -body {
    menu .m1
    .m1 add command
    list [.m1 entryconfigure 1 -label "test"] [.m1 entrycget 1 -label]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} test}
test menu-11.4 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command
    list [.m1 entryconfigure 1 -accel "S"] [.m1 entrycget 1 -accel]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} S}
test menu-11.5 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command
    list [.m1 entryconfigure 1 -label "test"] [.m1 entrycget 1 -label]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} test}
test menu-11.6 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command
    .m1 entryconfigure 1 -label "test"
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.7 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m2
    menu .m1
    .m1 add cascade
    .m1 entryconfigure 1 -label "test" -menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.8 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade
    .m1 entryconfigure 1 -label "test" -menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.9 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m3
    .m1 entryconfigure 1 -label "test" -menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.10 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade
    .m1 entryconfigure 1 -label "test" -menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.11 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    .m1 entryconfigure 1 -label "test" -menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.12 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    .m2 add cascade -menu .m1
    menu .m3
    .m3 add cascade -menu .m1
    menu .m4
    .m4 add cascade -menu .m1
    menu .m5
    .m5 add cascade
    .m5 entryconfigure 1 -label "test" -menu .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.13 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    .m2 add cascade -menu .m1
    menu .m3
    .m3 add cascade -menu .m1
    menu .m4
    .m4 add cascade -menu .m1
    .m3 entryconfigure 1 -label "test" -menu .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-11.14 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add checkbutton
    list [.m1 entryconfigure 1 -variable "test"] [.m1 entrycget 1 -variable]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} test}
test menu-11.15 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    list [.m1 add checkbutton -label "test"] [.m1 entrycget 1 -variable]
} -cleanup {
    deleteWindows
} -result {e001 test}
	deleteWindows
} -result {{} test}
test menu-11.16 {ConfigureMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add radiobutton -label "test"
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-11.17 {ConfigureMenuEntry} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add checkbutton
    list [.m1 entryconfigure 1 -onvalue "test"] [.m1 entrycget 1 -onvalue]
} -cleanup {
2783
2784
2785
2786
2787
2788
2789
2790

2791
2792
2793
2794
2795
2796
2797
2733
2734
2735
2736
2737
2738
2739

2740
2741
2742
2743
2744
2745
2746
2747







-
+







    deleteWindows
} -result {}


test menu-13.1 {TkGetMenuIndex} -setup {
    deleteWindows
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "active"
    .m1 add command -label "test2"
    .m1 add command -label "test3"
    .m1 activate 2
    .m1 entrycget active -label
} -cleanup {
    deleteWindows
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


3171
3172

3173
3174
3175
3176
3177

3178
3179
3180


3181
3182

3183
3184
3185
3186
3187

3188
3189

3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204

3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222

3223
3224
3225
3226
3227
3228

3229
3230
3231

3232
3233
3234
3235
3236
3237

3238
3239
3240

3241
3242
3243
3244
3245
3246
3247
3248

3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259

3260
3261
3262
3263
3264

3265
3266
3267
3268
3269
3270

3271
3272
3273

3274
3275
3276
3277
3278
3279

3280
3281
3282
3283

3284
3285
3286
3287
3288

3289
3290
3291

3292
3293
3294
3295

3296
3297
3298

3299
3300
3301
3302
3303

3304
3305
3306

3307
3308
3309
3310
3311

3312
3313
3314

3315
3316
3317
3318

3319
3320

3321
3322
3323
3324
3325

3326
3327
3328

3329
3330
3331
3332
3333
3334

3335
3336
3337

3338
3339
3340
3341
3342
3343

3344
3345
3346

3347
3348
3349
3350
3351
3352
3353

3354
3355
3356

3357
3358

3359
3360
3361

3362
3363
3364

3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424

3425
3426
3427
3428
3429
3430

3431
3432
3433
3434
3435
3436

3437
3438
3439
3440

3441
3442
3443
3444
3445
3446
3447
3448


3449
3450

3451
3452
3453
3454
3455
3456
3457
3458


3459
3460
3461


3462
3463
3464
3465
3466
3467
3468
3469
3470


3471
3472
3473


3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484


3485
3486
3487


3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498

3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565

3566
3567
3568

3569
3570
3571
3572
3573
3574

3575
3576
3577

3578
3579
3580
3581
3582
3583
3584
3585
3586

3587
3588
3589
3590

3591
3592
3593
3594
3595

3596
3597
3598

3599
3600
3601
3602
3603
3604

3605
3606
3607

3608
3609
3610
3611
3612

3613
3614
3615
3616
3617


3618
3619
3620
3621
3622

3623
3624
3625


3626
3627
3628
3629
3630

3631
3632
3633


3634
3635
3636
3637
3638
3639
3640

3641
3642
3643


3644
3645
3646
3647
3648
3649
3650
3651

3652
3653
3654


3655
3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666


3667
3668
3669
3670
3671
3672
3673
3674
3675

3676
3677
3678


3679
3680
3681
3682
3683
3684
3685
3686
3687
3688

3689
3690
3691


3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702

3703
3704
3705


3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717

3718
3719
3720


3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732

3733
3734
3735


3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747

3748
3749
3750


3751
3752
3753
3754
3755
3756

3757
3758
3759


3760
3761
3762
3763
3764

3765
3766
3767


3768
3769
3770
3771
3772
3773

3774
3775
3776


3777
3778
3779
3780
3781

3782
3783
3784


3785
3786
3787
3788
3789
3790
3791

3792
3793
3794
3795
3796
3797

3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808

3809
3810
3811
3812
3813
3814

3815
3816
3817
3818
3819

3820
3821
3822
3823

3824
3825
3826

3827
3828
3829
3830
3831
3832

3833
3834
3835
3836
3837

3838
3839
3840
3841
3842
3843
3844

3845
3846
3847
3848
3849

3850
3851
3852
3853
3854
3855
3856
3857

3858
3859
3860
3861
3862

3863
3864
3865
3866
3867

3868
3869
3870

3871
3872
3873
3874
3875
3876
3877

3878
3879
3880

3881
3882
3883
3884
3885

3886
3887
3888

3889
3890
3891
3892
3893
3894
3895
3896

3897
3898
3899
3900
3901

3902
3903
3904
3905
3906
3907
3908

3909
3910
3911

3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922

3923
3924
3925

3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936

3937
3938
3939

3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950

3951
3952
3953

3954
3955
3956
3957
3958
3959
3960
3961
3962

3963
3964
3965

3966
3967
3968
3969

3970
3971
3972

3973
3974
3975

3976
3977
3978
3979
3980
3981

3982
3983
3984

3985
3986
3987
3988
3989
3990
3991
3992
3993


3994
3995
3996
3997
3998

3999
4000
4001
4002

4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020

4021
4022
4023
4024
4025

4026
4027

4028
4029
4030
4031
4032

4033
4034
4035
4036
4037
4038
4039
4040
4041

4042
4043

4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063

4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078

4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089



4090
4091
4092
4093
4094

4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129

4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
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
3171
3172

3173
3174
3175
3176
3177
3178
3179
3180

3181
3182
3183
3184
3185

3186
3187
3188
3189
3190
3191

3192
3193
3194

3195
3196
3197
3198
3199
3200

3201
3202
3203
3204

3205
3206
3207
3208
3209

3210
3211
3212

3213
3214
3215
3216

3217
3218
3219

3220
3221
3222
3223
3224

3225
3226
3227

3228
3229
3230
3231
3232

3233
3234
3235

3236
3237
3238
3239

3240
3241

3242
3243
3244
3245
3246

3247
3248
3249

3250
3251
3252
3253
3254
3255

3256
3257
3258

3259
3260
3261
3262
3263
3264

3265
3266
3267

3268
3269
3270
3271
3272
3273
3274

3275
3276
3277

3278
3279

3280
3281
3282

3283
3284
3285

3286
3287
3288
3289
3290
3291




















































3292
3293

3294
3295
3296
3297
3298
3299

3300
3301
3302
3303
3304
3305

3306
3307
3308
3309

3310
3311
3312
3313
3314
3315
3316


3317
3318
3319

3320
3321
3322
3323
3324
3325
3326


3327
3328
3329


3330
3331
3332
3333
3334
3335
3336
3337
3338


3339
3340
3341


3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352


3353
3354
3355


3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367

3368



































































3369
3370
3371

3372
3373
3374
3375
3376
3377

3378
3379
3380

3381
3382
3383
3384
3385
3386
3387
3388
3389

3390
3391
3392
3393

3394
3395
3396
3397
3398

3399
3400
3401

3402
3403
3404
3405
3406
3407

3408
3409
3410

3411
3412
3413
3414
3415

3416
3417
3418
3419


3420
3421
3422
3423
3424
3425

3426
3427


3428
3429
3430
3431
3432
3433

3434
3435


3436
3437
3438
3439
3440
3441
3442
3443

3444
3445


3446
3447
3448
3449
3450
3451
3452
3453
3454

3455
3456


3457
3458
3459
3460
3461
3462
3463
3464
3465
3466

3467
3468


3469
3470
3471
3472
3473
3474
3475
3476
3477
3478

3479
3480


3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491

3492
3493


3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505

3506
3507


3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520

3521
3522


3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535

3536
3537


3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550

3551
3552


3553
3554
3555
3556
3557
3558
3559

3560
3561


3562
3563
3564
3565
3566
3567

3568
3569


3570
3571
3572
3573
3574
3575
3576

3577
3578


3579
3580
3581
3582
3583
3584

3585
3586


3587
3588
3589
3590
3591
3592
3593
3594

3595
3596
3597
3598
3599
3600

3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611

3612
3613
3614
3615
3616
3617

3618
3619
3620
3621
3622

3623
3624
3625
3626

3627
3628
3629

3630
3631
3632
3633
3634
3635

3636
3637
3638
3639
3640

3641
3642
3643
3644
3645
3646
3647

3648
3649
3650
3651
3652

3653
3654
3655
3656
3657
3658
3659
3660

3661
3662
3663
3664
3665

3666
3667
3668
3669
3670

3671
3672
3673

3674
3675
3676
3677
3678
3679
3680

3681
3682
3683

3684
3685
3686
3687
3688

3689
3690
3691

3692
3693
3694
3695
3696
3697
3698
3699

3700
3701
3702
3703
3704

3705
3706
3707
3708
3709
3710
3711

3712
3713
3714

3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725

3726
3727
3728

3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739

3740
3741
3742

3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753

3754
3755
3756

3757
3758
3759
3760
3761
3762
3763
3764
3765

3766
3767
3768

3769
3770
3771
3772

3773
3774
3775

3776
3777
3778

3779
3780
3781
3782
3783
3784

3785
3786
3787

3788
3789
3790
3791
3792
3793
3794
3795


3796
3797
3798
3799
3800
3801

3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823

3824
3825
3826
3827
3828

3829
3830

3831
3832
3833
3834
3835

3836
3837
3838
3839
3840
3841
3842
3843
3844

3845
3846

3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866

3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881

3882
3883
3884
3885
3886
3887
3888
3889
3890
3891


3892
3893
3894
3895
3896
3897
3898

3899
3900
3901
3902
3903
3904
3905
3906
3907



























3908
3909
























































































































































































3910
3911
3912
3913
3914
3915
3916
3917
3918
3919







-
+








-
+








-
+







-
+















-
+






-
+


-
+





-
+


-
+





-
+


-
+







-
+



-
+




-
+


-
+





-
+



-
+




-
-
+
+

-
+






-
-
+
+

-
+





-
-
+
+

-
+




-
-
+
+


-
+





-
+





-
-
+
+

-
+





-
+

-
+




-
+


-
+




-
-
+
+

-
+




-
-
+
+

-
+




-
-
+
+

-
+




-
-
+
+

-
+




-
-
+
+

-
+





-
+




-
-
+
+

-
+






-
-
+
+

-
+






-
-
+
+

-
+


-
+


-
+







-
-
+
+

-
+






-
-
+
+

-
+







-
-
+
+

-
+







-
-
+
+

-
+








-
-
-
+
+
+

-
+




-
+





-
+

-
-
+
+


-
+




-
+

-
-
+
+

-
+





-
+

-
-
+
+

-
+




-
+

-
-
+
+

-
+




-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+





-
+


-
+





-
+


-
+







-
+


-
+







-
+




-
+





-
+


-
+





-
+



-
+




-
+


-
+



-
+


-
+




-
+


-
+




-
+


-
+



-
+

-
+




-
+


-
+





-
+


-
+





-
+


-
+






-
+


-
+

-
+


-
+


-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+





-
+





-
+



-
+






-
-
+
+

-
+






-
-
+
+

-
-
+
+







-
-
+
+

-
-
+
+









-
-
+
+

-
-
+
+










-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


-
+





-
+


-
+








-
+



-
+




-
+


-
+





-
+


-
+




-
+



-
-
+
+




-
+

-
-
+
+




-
+

-
-
+
+






-
+

-
-
+
+







-
+

-
-
+
+








-
+

-
-
+
+








-
+

-
-
+
+









-
+

-
-
+
+










-
+

-
-
+
+











-
+

-
-
+
+











-
+

-
-
+
+











-
+

-
-
+
+





-
+

-
-
+
+




-
+

-
-
+
+





-
+

-
-
+
+




-
+

-
-
+
+






-
+





-
+










-
+





-
+




-
+



-
+


-
+





-
+




-
+






-
+




-
+







-
+




-
+




-
+


-
+






-
+


-
+




-
+


-
+







-
+




-
+






-
+


-
+










-
+


-
+










-
+


-
+










-
+


-
+








-
+


-
+



-
+


-
+


-
+





-
+


-
+







-
-
+
+




-
+



-
+

















-
+




-
+

-
+




-
+








-
+

-
+



















-
+














-
+









-
-
+
+
+




-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    list [.m1 insert last command -label "test2"] [.m1 entrycget last -label]
} -cleanup {
    deleteWindows
} -result {e002 test2}
} -result {{} test2}
test menu-13.5 {TkGetMenuIndex} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    list [.m1 insert end command -label "test2"] [.m1 entrycget end -label]
} -cleanup {
    deleteWindows
} -result {e002 test2}
} -result {{} test2}
test menu-13.6 {TkGetMenuIndex} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "active"
    .m1 add command -label "test2"
    .m1 add command -label "test3"
    .m1 activate 2
    .m1 entrycget {} -label
    .m1 entrycget none -label
} -cleanup {
    deleteWindows
} -result {}
#test menu-13.7 - Need to add @test here.
test menu-13.7 {TkGetMenuIndex} -setup {
    deleteWindows
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "active"
    .m1 add command -label "test2"
    .m1 add command -label "test3"
    .m1 entrycget 1 -label
} -cleanup {
    deleteWindows
} -result {active}
test menu-13.8 {TkGetMenuIndex} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "active"
    .m1 entrycget -1 -label
} -returnCodes error -result {bad menu entry index "-1"}
test menu-13.9 {TkGetMenuIndex} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test2"
    .m1 entrycget 999 -label
} -cleanup {
    deleteWindows
	deleteWindows
} -result {test2}
test menu-13.10 {TkGetMenuIndex} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 insert 999 command -label "test"
    .m1 entrycget 1 -label
} -cleanup {
    deleteWindows
	deleteWindows
} -result {test}
test menu-13.11 {TkGetMenuIndex} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "1test"
    .m1 entrycget 1test -label
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1test}
test menu-13.12 {TkGetMenuIndex} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test2" -command "beep"
    .m1 add command -label "test3"
    .m1 entrycget test2 -command
} -cleanup {
    deleteWindows
	deleteWindows
} -result {beep}

test menu-14.1 {MenuCmdDeletedProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    destroy .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes ok
test menu-14.2 {MenuCmdDeletedProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    destroy .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes ok

test menu-15.1 {MenuNewEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-15.2 {MenuNewEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test3"
    .m1 insert 2 command -label "test2"
} -cleanup {
    deleteWindows
} -result {e003}
	deleteWindows
} -result {}
test menu-15.3 {MenuNewEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test2"
} -cleanup {
    deleteWindows
} -result {e002}
	deleteWindows
} -result {}
test menu-15.4 {MenuNewEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}

test menu-16.1 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 insert foo command -label "test"
} -returnCodes error -result {bad menu entry index "foo"}
test menu-16.2 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 insert test command -label "foo"
} -cleanup {
    deleteWindows
} -result {e002}
	deleteWindows
} -result {}
test menu-16.3 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 insert -1 command -label "test"
} -returnCodes error -result {bad menu entry index "-1"}
test menu-16.4 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1 -tearoff 1
    menu .m1
    .m1 add command -label "test"
    .m1 insert 0 command -label "test2"
    .m1 entrycget 1 -label
} -cleanup {
    deleteWindows
	deleteWindows
} -result {test2}
test menu-16.5 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.6 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add checkbutton
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.7 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.8 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add radiobutton
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.9 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add separator
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.10 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add blork
} -returnCodes error -result {bad menu entry type "blork": must be cascade, checkbutton, command, radiobutton, or separator}
test menu-16.11 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command
} -cleanup {
    deleteWindows
} -result {e001}
	deleteWindows
} -result {}
test menu-16.12 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m2 clone .m3
    list [.m2 add command -label "test"] [.m1 entrycget 1 -label] [.m3 entrycget 1 -label]
} -cleanup {
    deleteWindows
} -result {e001 test test}
	deleteWindows
} -result {{} test test}
test menu-16.13 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m2 clone .m3
    list [.m3 add command -label "test"] [.m1 entrycget 1 -label] [.m2 entrycget 1 -label]
} -cleanup {
    deleteWindows
} -result {e001 test test}
	deleteWindows
} -result {{} test test}
test menu-16.14 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -blork fish
    .m1 add command -blork
} -returnCodes error -result {unknown option "-blork"}
test menu-16.15 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "File"
    menu .container
    . configure -menu .container
    list [.container add cascade -label "File" -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
} -result {e001 {}}
	deleteWindows
} -result {{} {}}
test menu-16.16 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    set tearoff [tk::TearOffMenu .m2]
    list [.m2 add cascade -menu .m1] [$tearoff unpost]
} -cleanup {
    deleteWindows
} -result {e001 {}}
	deleteWindows
} -result {{} {}}
test menu-16.17 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .container
    . configure -menu .container
    set tearoff [tk::TearOffMenu .container]
    list [.container add cascade -label "File" -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
} -result {e001 {}}
	deleteWindows
} -result {{} {}}
test menu-16.18 {MenuAddOrInsert} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .container
    .container add cascade -menu .m1
    . configure -menu .container
    list [.container add cascade -label "File" -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
} -result {e002 {}}
	deleteWindows
} -result {{} {}}
test menu-16.19 {MenuAddOrInsert - Insert a cascade deep into the tree} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .menubar
    menu .menubar.test -tearoff 0
    .menubar add cascade -label Test -underline 0 -menu .menubar.test
    menu .menubar.test.cascade -tearoff 0
    .menubar.test.cascade add command -label SubItem -command "puts SubItemSelected"
    . configure -menu .menubar
    list [catch {.menubar.test add cascade -label SubMenu \
            -menu .menubar.test.cascade}] \
            [info commands .\#menubar.\#menubar\#test.\#menubar\#test\#cascade] \
            [. configure -menu ""]
		-menu .menubar.test.cascade}] \
		[info commands .\#menubar.\#menubar\#test.\#menubar\#test\#cascade] \
		[. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 .#menubar.#menubar#test.#menubar#test#cascade {}}


test menu-17.1 {MenuVarProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    catch {unset foo}
    menu .m1
    set foo "hello"
    list [.m1 add checkbutton -variable foo -onvalue hello -offvalue goodbye] \
            [unset foo]
		[unset foo]
} -cleanup {
    deleteWindows
} -result {e001 {}}
	deleteWindows
} -result {{} {}}
# menu-17.2 - Don't know how to generate the flags in the if
test menu-17.2 {MenuVarProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    catch {unset foo}
    menu .m1
    list [.m1 add checkbutton -variable foo -onvalue hello -offvalue goodbye] \
            [set foo ""]
		[set foo ""]
} -cleanup {
    deleteWindows
} -result {e001 {}}
	deleteWindows
} -result {{} {}}
test menu-17.3 {MenuVarProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    catch {unset foo}
    menu .m1
    set foo "hello"
    list [.m1 add checkbutton -variable foo -onvalue hello -offvalue goodbye] \
            [set foo "hello"] [unset foo]
		[set foo "hello"] [unset foo]
} -cleanup {
    deleteWindows
} -result {e001 hello {}}
	deleteWindows
} -result {{} hello {}}
test menu-17.4 {MenuVarProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    set foo "goodbye"
    list [.m1 add checkbutton -variable foo -onvalue hello -offvalue goodbye] \
            [set foo "hello"] [unset foo]
		[set foo "hello"] [unset foo]
} -cleanup {
    deleteWindows
} -result {e001 hello {}}
	deleteWindows
} -result {{} hello {}}
test menu-17.5 {MenuVarProc} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    set foo "hello"
    list [.m1 add checkbutton -variable foo -onvalue hello -offvalue goodbye] \
            [set foo "goodbye"] [unset foo]
		[set foo "goodbye"] [unset foo]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {e001 goodbye {}}
test menu-17.6 {MenuVarProc [5d991b822e]} -setup {
    deleteWindows
} -body {
    # Want this not to crash
    menu .b
    set var INIT
    .b add checkbutton -variable var
    trace add variable var unset {apply {args {
        .b entryconfigure 1 -variable {}
    }}}
    unset var
} -cleanup {
    deleteWindows
} -result {}
} -result {{} goodbye {}}
test menu-17.7 {MenuVarProc [5d991b822e]} -setup {
    deleteWindows
} -body {
    # Want this not to duplicate traces
    menu .b
    set var INIT
    .b add checkbutton -variable var
    trace add variable var unset {apply {args {
        .b entryconfigure 1 -variable new
    }}}
    unset var
} -cleanup {
    deleteWindows
} -result {}


test menu-18.1 {TkActivateMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 activate 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-18.2 {TkActivateMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 activate 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-18.3 {TkActivateMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test2"
    .m1 activate 1
    .m1 activate 2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-18.4 {TkActivateMenuEntry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 add command -label "test2"
    .m1 activate 1
    .m1 activate 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}


test menu-19.1 {TkPostCommand} -constraints nonUnixUserInteraction -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1 -postcommand "set menu_test menu-19.1"
    .m1 add command -label "menu-19.1 - hit Escape"
    list [.m1 post 40 40] [.m1 unpost] [set menu_test]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {menu-19.1 {} menu-19.1}
test menu-19.2 {TkPostCommand} -constraints nonUnixUserInteraction -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "menu-19.2 - hit Escape"
    list [.m1 post 40 40] [.m1 unpost]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}

test menu-20.1 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.2 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 normal
    deleteWindows
	deleteWindows
} -result {}
test menu-20.3 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 tearoff
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.4 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 menubar
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.5 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2 foo
} -returnCodes error -result {bad menu type "foo": must be menubar, normal, or tearoff}
} -returnCodes error -result {bad menu type "foo": must be normal, tearoff, or menubar}
test menu-20.6 {CloneMenu - hooking up bookeeping ptrs} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.7 {CloneMenu - hooking up bookeeping ptrs - multiple children} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 clone .m2
    .m1 clone .m3
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.8 {CloneMenu - cascade entries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    .m1 clone .foo
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.9 {CloneMenu - cascades entries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    menu .m2
    .m1 clone .foo
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-20.10 {CloneMenu - tearoff fields} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1 -tearoff 1
    menu .m1
    list [.m1 clone .m2 normal] [.m2 cget -tearoff]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} 1}
test menu-20.11 {CloneMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m2
    .m1 clone .m2
} -returnCodes error -result {window name "m2" already exists in parent}
test menu-20.12 {CloneMenu - copied bindings on empty menu} -setup {
    deleteWindows
    set x {}
} -body {
    menu .m1 -tearoff 0
    bind .m1 <<Test>> {append x <<Test>>}
    .m1 clone .m2 tearoff
    .m2 post 100 100
    event generate .m2 <<Test>>
    return $x
} -result {<<Test>>}
test menu-20.13 {CloneMenu - copied bindings on non-empty menu} -setup {
    deleteWindows
    set x {}
} -body {
    menu .m1 -tearoff 1
    bind .m1 <<Test>> {append x <<Test>>}
    .m1 clone .m2 tearoff
    .m2 post 100 100
    event generate .m2 <<Test>>
    return $x
} -result {<<Test>>}
test menu-20.14 {CloneMenu - new binding on empty menu} -setup {
    deleteWindows
    set x {}
} -body {
    menu .m1 -tearoff 0
    .m1 clone .m2 tearoff
    .m2 post 100 100
    bind .m1 <<Test>> {append x <<Test>>}
    event generate .m2 <<Test>>
    return $x
} -result {<<Test>>}
test menu-20.15 {CloneMenu - new binding on non-empty menu} -setup {
    deleteWindows
    set x {}
} -body {
    menu .m1 -tearoff 1
    .m1 clone .m2 tearoff
    .m2 post 100 100
    bind .m1 <<Test>> {append x <<Test>>}
    event generate .m2 <<Test>>
    return $x
} -result {<<Test>>}
test menu-20.16 {CloneMenu - bindtags} -setup {
    deleteWindows
} -body {
    menu .m1
    bindtags .m1 [linsert [bindtags .m1] 1 .m1.sub1]
    .m1 clone .m2
    bindtags .m2
} -result {.m2 .m1 .m1.sub1 Menu all}

test menu-21.1 {MenuDoYPosition} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 yposition glorp
} -returnCodes error -result {bad menu entry index "glorp"}
test menu-21.2 {MenuDoYPosition} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "Test"
    .m1 yposition 1
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes ok -match glob -result {*}

test menu-22.1 {GetIndexFromCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -tearoff 0
    .m1 index @5
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}
test menu-22.2 {GetIndexFromCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -tearoff 0
    .m1 index @5,5
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}
test menu-22.3 {GetIndexFromCoords: mapped window, y only} -setup {
    deleteWindows
} -constraints {x11} -body {
	deleteWindows
} -constraints {unix} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -tearoff 0
    tk_popup .m1 0 0
    tkwait visibility .m1
    .m1 index @5
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}
test menu-22.4 {GetIndexFromCoords: mapped window x,y} -setup {
    deleteWindows
} -constraints {x11} -body {
	deleteWindows
} -constraints {unix} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -tearoff 0
    tk_popup .m1 0 0
    tkwait visibility .m1
    update
    set x [expr {[winfo width .m1] - [.m1 cget -borderwidth] - 1}]
    .m1 index @$x,5
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}
test menu-22.5 {GetIndexFromCoords: mapped wide window} -setup {
    deleteWindows
} -constraints {x11} -body {
	deleteWindows
} -constraints {unix} -body {
    menu .m1
    .m1 add command -label "test"
    .m1 configure -tearoff 0
    tk_popup .m1 0 0
    tkwait visibility .m1
    wm geometry .m1 200x100
    update
    set x [expr {[winfo width .m1] - [.m1 cget -borderwidth] - 1}]
    .m1 index @$x,5
} -cleanup {
    deleteWindows
	deleteWindows
} -result 0
test menu-22.6 {GetIndexFromCoords: syntax error in @x,y indices} -setup {
    deleteWindows
} -body {
    menu .m
    .m add command -label "First entry"
    .m add command -label "Second entry"
    .m add command -label "Last entry"
    .m index @4bogus
} -cleanup {
    deleteWindows
}  -returnCodes error -result {bad menu entry index "@4bogus"}
test menu-22.7 {GetIndexFromCoords: syntax error in @x,y indices} -setup {
    deleteWindows
} -body {
    menu .m
    .m add command -label "First entry"
    .m add command -label "Second entry"
    .m add command -label "Last entry"
    .m index @10,4bogus
} -cleanup {
    deleteWindows
}  -returnCodes error -result {bad menu entry index "@10,4bogus"}
test menu-22.8 {GetIndexFromCoords: syntax error in @x,y indices} -setup {
    deleteWindows
} -body {
    menu .m
    .m add command -label "First entry"
    .m add command -label "Second entry"
    .m add command -label "Last entry"
    .m index @10,bogus
} -cleanup {
    deleteWindows
}  -returnCodes error -result {bad menu entry index "@10,bogus"}
test menu-22.9 {GetIndexFromCoords: index type pecedence} -setup {
    deleteWindows
} -body {
    menu .m -tearoff 0
    .m add command -label "First entry"
    .m add command -label "@42nd street"
    .m add command -label "Last entry"
    .m index "@42nd*"  ; # shall be interpreted as a pattern, not as @42
} -cleanup {
    deleteWindows
} -result {1}

test menu-22.10 {tk_popup on separator entry} -setup {
    deleteWindows
} -constraints {x11} -body {
    menu .m1
    label .l -text ClickMe!
    .m1 add command -label "Example 1" -command bell
    .m1 add command -label "Example 2" -command bell
    .m1 add separator
    .m1 add command -label "Example Other" -command "bell;bell"
    tk_popup .m1 100 100 2
    set waiting 0
    tkwait visibility .m1
    after 333 incr waiting
    vwait waiting
    .m1 invoke 4
    after 333 incr waiting
    vwait waiting
    destroy .m1
} -cleanup {
    deleteWindows
} -result {}
} -result {0}

test menu-23.1 {RecursivelyDeleteMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    . configure -menu .m1
    . configure -menu ""
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-23.2 {RecursivelyDeleteMenu} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m2
    .m2 add command -label "test2"
    menu .m1
    .m1 add cascade -label "test1" -menu .m2
    . configure -menu .m1
    . configure -menu ""
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}

test menu-24.1 {TkNewMenuName} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-24.2 {TkNewMenuName} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    menu .m1\#0
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-24.3 {TkNewMenuName} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .#m
    rename .#m hideme
    list [catch {. configure -menu [menu .m]}] [. configure -menu ""] [destroy .#m] \
            [destroy .m] [destroy hideme]
		[destroy .m] [destroy hideme]
} -result {0 {} {} {} {}}


test menu-25.1 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.1 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.2 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.2 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.3 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.3 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    destroy .m1
    menu .m1
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.4 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.4 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    . configure -menu .m1
    menu .m2
    list [. configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.5 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.5 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    . configure -menu .m1
    .m1 clone .m2
    menu .m3
    list [. configure -menu .m3] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.6 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.6 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    .m1 clone .m2
    . configure -menu .m2
    menu .m3
    list [. configure -menu .m3] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.7 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.7 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    . configure -menu .m1
    toplevel .t2
    .t2 configure -menu .m1
    list [.t2 configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.8 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.8 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    . configure -menu .m1
    toplevel .t2
    wm geometry .t2 +0+0
    .t2 configure -menu .m1
    list [. configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.9 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.9 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    . configure -menu .m1
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    list [.t3 configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.10 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.10 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    . configure -menu .m1
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    list [.t2 configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.11 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.11 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    . configure -menu .m1
    toplevel .t2 -menu .m1
    wm geometry .t2 +0+0
    toplevel .t3 -menu .m1
    wm geometry .t3 +0+0
    list [. configure -menu .m2] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.12 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.12 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.13 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.13 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.14 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.14 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.15 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.15 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}
test menu-25.16 {Tk_SetWindowMenubar} -setup {
    deleteWindows
test menu-25.16 {TkSetWindowMenuBar} -setup {
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    . configure -menu .m1
    list [toplevel .t2 -menu m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.t2 {}}


test menu-26.1 {DestroyMenuHashTable} -setup {
    catch {interp delete testinterp}
    deleteWindows
	deleteWindows
} -body {
    interp create testinterp
    load {} Tk testinterp
    interp eval testinterp {menu .m1}
    interp delete testinterp
} -returnCodes ok -result {}


test menu-27.1 {GetMenuHashTable} -setup {
    catch {interp delete testinterp}
    deleteWindows
	deleteWindows
} -body {
    interp create testinterp
    load {} Tk testinterp
    list [catch {interp eval testinterp {menu .m1}} msg] $msg [interp delete testinterp]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 .m1 {}}


test menu-28.1 {TkCreateMenuReferences - not there before} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m1}
test menu-28.2 {TkCreateMenuReferences - there already} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m2
    menu .m2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.m2}


test menu-29.1 {TkFindMenuReferences - not there} -setup {
    deleteWindows
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    .m1 add cascade -menu .m2
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}


test menu-30.1 {TkFindMenuReferences - there already} -setup {
    deleteWindows
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    menu .m2
    .m1 add cascade -menu .m2
    list [. configure -menu .m1] [. configure -menu ""]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{} {}}


test menu-31.1 {TkFreeMenuReferences - menuPtr} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    destroy .m1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-31.2 {TkFreeMenuReferences - cascadePtr} -setup {
    deleteWindows
	deleteWindows
} -body {
    . configure -menu ""
    menu .m1
    .m1 add cascade -menu .m2
    .m1 entryconfigure 1 -menu .m3
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-31.3 {TkFreeMenuReferences - topLevelListPtr} -setup {
    deleteWindows
	deleteWindows
} -body {
    . configure -menu .m1
    . configure -menu ""
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes ok -result {}
test menu-31.4 {TkFreeMenuReferences - not empty} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add cascade -menu .m3
    menu .m2
    .m2 add cascade -menu .m3
    .m2 entryconfigure 1 -menu ".foo"
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}


test menu-32.1 {DeleteMenuCloneEntries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label foo
    .m1 clone .m2
    .m1 delete 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.2 {DeleteMenuCloneEntries} -setup {
    deleteWindows
	deleteWindows
} -body {

    menu .m1
    .m1 add command -label one
    .m1 add command -label two
    .m1 add command -label three
    .m1 add command -label four
    .m1 clone .m2
    .m1 delete 2 3
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.3 {DeleteMenuCloneEntries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1 -tearoff 0
    .m1 add command -label one
    .m1 add command -label two
    .m1 add command -label three
    .m1 add command -label four
    .m1 clone .m2
    .m2 configure -tearoff 1
    .m1 delete 1 2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.4 {DeleteMenuCloneEntries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label one
    .m1 add command -label two
    .m1 add command -label three
    .m1 add command -label four
    .m1 clone .m2
    .m2 configure -tearoff 0
    .m1 delete 2 3
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.5 {DeleteMenuCloneEntries} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label one
    .m1 add command -label two
    .m1 clone .m2
    .m1 activate one
    .m1 delete one
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.6 {DeleteMenuCloneEntries - reentrancy - crashes tk8.0} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1
    .m1 add command -label test \
            -command ".m1 delete test ; .m1 add command -label test -command \".m1 delete test\"; .m1 delete test"
		-command ".m1 delete test ; .m1 add command -label test -command \".m1 delete test\"; .m1 delete test"
    .m1 invoke test
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.7 {DeleteMenuCloneEntries - one entry} -setup {
    deleteWindows
	deleteWindows
} -body {
    menu .m1 -tearoff 0
    .m1 add command -label Hello
    .m1 delete Hello
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.8 {Ensure all menu clone commands are deleted} -setup {
    deleteWindows
	deleteWindows
} -body {
    # SF bug #465324
    menu .menubar
    . configure -menu .menubar
    menu .menubar.test
    .menubar.test add command -label "hi"
    for {set i 0} {$i < 10} {incr i} {
        .menubar add cascade -menu .menubar.test -label "Test"
        .menubar delete Test
		.menubar add cascade -menu .menubar.test -label "Test"
		.menubar delete Test
    }

    info commands .#menubar*test*
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test menu-32.9 {Ensure deleting of clones doesn't corrupt menu refs} -setup {
    set res {}
    deleteWindows
	deleteWindows
} -body {
    menu .menubar
    . configure -menu .menubar
    menu .menubar.test
    .menubar add cascade -menu .menubar.test -label "Test"
    menu .menubar.cascade

    .menubar.test add cascade -menu .menubar.cascade -label "Cascade"
    lappend res [.menubar.test entrycget 1 -menu]
    lappend res [.#menubar.#menubar#test entrycget 1 -menu]
    destroy .menubar.test
    menu .menubar.test
    .menubar.test add cascade -menu .menubar.cascade -label "Cascade"
    lappend res [.menubar.test entrycget 1 -menu]
    lappend res [.#menubar.#menubar#test entrycget 1 -menu]
    return $res
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.menubar.cascade .#menubar.#menubar#test.#menubar#cascade .menubar.cascade .#menubar.#menubar#test.#menubar#cascade}


test menu-33.1 {menu vs command hiding} -setup {
    deleteWindows
	deleteWindows
} -body {
    set l [interp hidden]
	set l [interp hidden]
    menu .m
    interp hide {} .m
    destroy .m
    set result [list [winfo children .] [interp hidden]]
    expr {$result eq [list {} $l]}
	expr {$result eq [list {} $l]}
} -result 1

# menu-34 MenuInit only called at boot time

# creating menus on two different screens then deleting the
# menu from the first screen crashes Tk8.3.1
#
test menu-34.1 {menus on multiple screens - crashes tk8.3.1, Bug 5454} -constraints {
    altDisplay
	altDisplay
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .one
    menu .one.m
    toplevel .two -screen $::env(TK_ALT_DISPLAY)
    menu .two.m
    destroy .one
    destroy .two
} -result {}

test menu-35.1 {menu -underline string overruns Bug 1599877} -setup {
   destroy .m
} -body {
    # ensure that -underline does not do string overruns [Bug 1599877]
    menu .m
    .m add command -label "File" -underline [expr {1<<30}]
    . configure -menu .m
    update
    tk::TraverseToMenu . "e"
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}

test menu-37.1 {menubar menues cannot be posted - bug 2160206} -setup {
    catch {destroy .m}
} -body {
    # On Linux the following used to panic
    # It now returns an error (on all platforms)
    menu .m -type menubar
    list [catch ".m post 1 1" msg] $msg
} -cleanup {
    destroy .m
} -result {1 {a menubar menu cannot be posted}}

test menu-38.1 {Can't dismiss ttk::menubutton menu until mouse has hovered over it - bug fa32290898} -setup {
} -constraints {x11} -body {
} -constraints {userInteraction} -body {
    toplevel .top
    ttk::menubutton .top.mb -text "Some menu";
    menu .top.mb.m;
    .top.mb.m add command -label "Item 1";
    .top.mb.m add command -label "Item 2";
    .top.mb configure -menu .top.mb.m;
    pack .top.mb
    update
    # simulate mouse click on the menubutton, which posts its menu
    event generate .top.mb <Button-1> -warp 1
    controlPointerWarpTiming
    event generate .top.mb <ButtonPress-1> -warp 1
    update
    after 50
    event generate .top.mb <ButtonRelease-1>
    update
    # simulate mouse click on the menu again, i.e. without
    # entering/leaving the posted menu
    event generate .top.mb <Button-1>
    event generate .top.mb <ButtonPress-1>
    update
    after 50
    event generate .top.mb <ButtonRelease-1>
    update
    # the menu shall have been unposted by the second click
    winfo ismapped .top.mb.m
} -cleanup {
    destroy .top.mb.m .top.m .top
} -result 0

test menu-39.1 {empty -type - bug be8f5b9fc2} -setup {
    catch {destroy .m}
} -body {
    menu .m -type {}
} -cleanup {
    destroy .m
} -returnCodes error -result {ambiguous type "": must be menubar, normal, or tearoff}

test menu-39.2 {use-after-free fix - bug 1797555fff} -setup {
    toplevel .t
    menu .t.menubar -type menubar
    menu .t.menubar.select -title Select
    menu .t.menubar.select.chain -title Chain
    .t.menubar.select insert 1 cascade -menu .t.menubar.select.chain -label Chain
    .t.menubar add cascade -menu .t.menubar.select -label Select
    .t configure -menu .t.menubar
    .t.menubar.select.chain insert 1 command
    update idletasks
} -body {
    # The following two lines caused Tk to read from and write to freed memory
    destroy .t.menubar.select.chain
    .t.menubar.select delete 1
} -cleanup {
    destroy .t
} -result {}
} -result {0}

test menu-40.1 {Use-after-free if menu destroyed while posted - bug 09a11fb1228f} -setup {
} -constraints {pressbutton} -body {
    set done false
    event generate {} <Motion> -x 100 -y 100
    toplevel .t
    menu .t.m
    .t.m add command -command {puts Marco} -label Marco
    .t.m add command -command {puts Polo} -label Polo
    after 1000 {.t.m post 500 500}
    after 2000 {destroy .t}
    after 2500 {pressbutton 530 510}
    after 3000 {set done true}
    tkwait variable done
}

test menu-40.2 {Use-after-free if menu destroyed while posted - bug 09a11fb1228f} -setup {
} -constraints {movemouse} -body {
    set done false
    event generate {} <Motion> -x 100 -y 100
    toplevel .t
    menu .t.m
    .t.m add command -command {puts Marco} -label Marco
    .t.m add command -command {puts Polo} -label Polo
    after 1000 {.t.m post 500 500}
    after 2000 {movemouse 530 510}
    after 3000 {destroy .t}
    after 3500 {movemouse 530 530}
    after 4000 pressbutton 530 530
    after 4500 {set done true}
    tkwait variable done
    pressbutton 530 510
}

test menu-41.1 {identifiers - auto generated} -setup {
    destroy .m
} -body {
    menu .m
    list [.m add command -label 1] [.m add command -label 2] [.m add command -label 3]
} -cleanup {
    destroy .m
} -result {e001 e002 e003}
test menu-41.2 {identifiers - out of sequence} -setup {
    destroy .m
} -body {
    menu .m -tearoff 0
    .m add command -label 1
    .m insert 0 command -label 2
    .m add command -label 3
    list [.m index e001] [.m index e002] [.m index e003]
} -cleanup {
    destroy .m
} -result {1 0 2}
test menu-41.3 {identifiers - out of sequence with tearoff} -setup {
    destroy .m
} -body {
    menu .m -tearoff 1
    .m add command -label 1
    .m insert 0 command -label 2
    .m add command -label 3
    list [.m index e001] [.m index e002] [.m index e003]
} -cleanup {
    destroy .m
} -result {2 1 3}
test menu-41.4 {identifiers - entry id} -setup {
    destroy .m
} -body {
    menu .m -tearoff 1
    .m add command -label 1
    .m insert 0 command -label 2
    .m add command -label 3
    list [.m id 0] [.m id 1] [.m id 2] [.m id 3]
} -cleanup {
    destroy .m
} -result {{} e002 e001 e003}
test menu-41.5 {identifiers - assigned} -setup {
    destroy .m
} -body {
    menu .m
    list [.m add command cmd1 -label 1] [.m insert 0 command cmd2 -label 2] [.m add command cmd3 -label 3]
} -cleanup {
    destroy .m
} -result {cmd1 cmd2 cmd3}
test menu-41.6 {identifiers - mixed} -setup {
    destroy .m
} -body {
    menu .m
    list [.m add command -label 1] [.m insert 0 command cmd2 -label 2] [.m add command -label 3]
} -cleanup {
    destroy .m
} -result {e001 cmd2 e002}
test menu-41.7 {identifiers - conflict} -setup {
    destroy .m
} -body {
    menu .m
    list [.m add command e002 -label 1] [.m add command -label 2] [.m add command -label 3]
} -cleanup {
    destroy .m
} -result {e002 e001 e003}
test menu-41.8 {identifiers - clone of complete menu} -setup {
    destroy .m1 .m2
} -body {
    menu .m1 -tearoff 0
    .m1 add command -label 1
    .m1 insert 0 command -label 2
    .m1 add command cmd3 -label 3
    .m1 clone .m2
    list [.m2 index e001] [.m2 index e002] [.m2 index cmd3]
} -cleanup {
    destroy .m1 .m2
} -result {1 0 2}
test menu-41.9 {identifiers - modify after cloning} -setup {
    destroy .m1 .m2
} -body {
    menu .m1 -tearoff 0
    .m1 clone .m2
    .m1 add command -label 1
    .m1 insert 0 command -label 2
    .m1 add command cmd3 -label 3
    list [.m2 index e001] [.m2 index e002] [.m2 index cmd3]
} -cleanup {
    destroy .m1 .m2
} -result {1 0 2}
test menu-41.10 {identifiers - modify clone} -setup {
    destroy .m1 .m2
} -body {
    menu .m1 -tearoff 0
    .m1 clone .m2
    .m2 add command -label 1
    .m2 insert 0 command -label 2
    .m2 add command cmd3 -label 3
    list [.m1 index e001] [.m1 index e002] [.m1 index cmd3]
} -cleanup {
    destroy .m1 .m2
} -result {1 0 2}
test menu-41.11 {identifiers - entrycget by id} -setup {
    destroy .m
} -body {
    menu .m
    .m add command -label 1
    .m add command -label 2
    .m add command cmd3 -label 3
    list [.m entrycget e001 -label] [.m entrycget e002 -label] [.m entrycget cmd3 -label]
} -cleanup {
    destroy .m
} -result {1 2 3}
test menu-41.12 {identifiers - delete by id} -setup {
    destroy .m
} -body {
    menu .m
    .m add command -label 1
    .m add command -label 2
    .m add command -label 3
    .m add command -label 4
    .m add command -label 5
    .m add command -label 6
    .m add command -label 7
    .m add command cmd8 -label 8
    .m add command cmd9 -label 9
    .m delete e003 cmd8
    list [.m id 0] [.m id 1] [.m id 2]
} -cleanup {
    destroy .m
} -result {e001 e002 cmd9}
test menu-41.13 {identifiers - duplicate} -setup {
    destroy .m
} -body {
    menu .m
    .m add command foo -label 1
    .m add command bar -label 2
    .m add command foo -label 3
} -cleanup {
    destroy .m
} -returnCodes error -result {entry "foo" already exists}
test menu-41.14 {identifiers - reserved word} -setup {
    destroy .m
} -body {
    menu .m -tearoff 0
    .m add command last -label 1
    .m add command -label 2
    .m add command -label 3
    .m index last
} -cleanup {
    destroy .m
} -result {2}

# cleanup
imageFinish
deleteWindows
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/menuDraw.test.

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30

31
32
33
34
35
36
37
1
2
3


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29

30
31
32
33
34
35
36
37



-
-
+
+

















-
+






-
+







# This file is a Tcl script to test drawing of menus in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
imageInit

test menuDraw-1.1 {TkMenuInitializeDrawingFields} -setup {
    deleteWindows
} -body {
    menu .m1
} -cleanup {
    deleteWindows
} -result {.m1}


test menuDraw-2.1 {TkInitializeMenuEntryDrawingFields} -setup {
test menuDraw-2.1 {TkIntializeMenuEntryDrawingFields} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}


test menuDraw-3.1 {TkMenuFreeDrawOptions} -setup {
    deleteWindows
} -body {
    menu .m1
    destroy .m1
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+







-
+







test menuDraw-6.1 {TkMenuConfigureEntryDrawOptions - no tkfont specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.2 {TkMenuConfigureEntryDrawOptions - tkfont specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -font "Courier 12"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.3 {TkMenuConfigureEntryDrawOptions - active state - wrong entry} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo"
    .m1 entryconfigure 1 -state active
} -cleanup {
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190







-
+







-
+







-
+







-
+







-
+







-
+







-
+







    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo"
    .m1 entryconfigure 1 -state foo
} -cleanup {
    deleteWindows
} -returnCodes error -result {bad state "foo": must be active, disabled, or normal}
} -returnCodes error -result {bad state "foo": must be active, normal, or disabled}
test menuDraw-6.7 {TkMenuConfigureEntryDrawOptions - tkfont specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -font "Courier 12"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.8 {TkMenuConfigureEntryDrawOptions - border specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -background "red"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.9 {TkMenuConfigureEntryDrawOptions - foreground specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -foreground "red"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.10 {TkMenuConfigureEntryDrawOptions - activeBorder specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -activebackground "red"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.11 {TkMenuConfigureEntryDrawOptions - activeforeground specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -activeforeground "red"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.12 {TkMenuConfigureEntryDrawOptions - selectcolor specified} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add radiobutton -label "foo" -selectcolor "red"
} -cleanup {
    deleteWindows
} -result {e001}
} -result {}
test menuDraw-6.13 {TkMenuConfigureEntryDrawOptions - textGC disposal} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -font "Helvetica 12"
    .m1 entryconfigure 1 -font "Courier 12"
} -cleanup {
554
555
556
557
558
559
560
561

562
563
564

565
566
567
568
569
570
571
554
555
556
557
558
559
560

561
562
563

564
565
566
567
568
569
570
571







-
+


-
+







} -returnCodes ok -match glob -result *
test menuDraw-15.2 {TkPostTearoffMenu - Deactivation} -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add command -label "foo" -state active
    set tearoff [tk::TearOffMenu .m1 40 40]
    expr {[$tearoff index active]<0}
    $tearoff index active
} -cleanup {
    deleteWindows
} -result 1
} -result {none}
test menuDraw-15.3 {TkPostTearoffMenu - post command} -setup {
    deleteWindows
} -body {
    catch {unset foo}
    menu .m1 -postcommand "set foo .m1"
    .m1 add command -label "foo"
    list [catch {tk::TearOffMenu .m1 40 40}] [set foo] [unset foo] [destroy .m1]
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
643
644
645
646
647
648
649

650
651
652
653
654
655
656
657







-
+







    menu .m1
    .m1 add cascade -label test
    set tearoff [tk::TearOffMenu .m1 40 40]
    $tearoff postcascade 0
} -cleanup {
    deleteWindows
} -result {}
test menuDraw-16.5 {TkPostSubMenu} -setup {
test menuDraw-16.5 {TkPostSubMenu} -constraints unix -setup {
    deleteWindows
} -body {
    menu .m1
    .m1 add cascade -label test -menu .m2
    menu .m2 -postcommand "glorp"
    set tearoff [tk::TearOffMenu .m1 40 40]
    $tearoff postcascade test

Changes to tests/menubut.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test menubuttons in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

# XXX This test file is woefully incomplete right now.  If any part
# XXX of a procedure has tests then the whole procedure has tests,
# XXX but many procedures have no tests.

package require tcltest 2.2
67
68
69
70
71
72
73
74

75
76
77

78
79
80
81
82
83
84
67
68
69
70
71
72
73

74
75
76

77
78
79
80
81
82
83
84







-
+


-
+







    .mb configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test menubutton-1.9 {configuration options} -body {
    .mb configure -bd 4
    .mb cget -bd
} -cleanup {
    .mb configure -bd [lindex [.mb configure -bd] 3]
} -result 4
} -result {4}
test menubutton-1.10 {configuration options} -body {
    .mb configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test menubutton-1.11 {configuration options} -body {
    .mb configure -bg #ff0000
    .mb cget -bg
} -cleanup {
    .mb configure -bg [lindex [.mb configure -bg] 3]
} -result {#ff0000}
test menubutton-1.12 {configuration options} -body {
94
95
96
97
98
99
100
101

102
103
104

105
106
107
108
109
110
111
94
95
96
97
98
99
100

101
102
103

104
105
106
107
108
109
110
111







-
+


-
+







    .mb configure -bitmap badValue
} -returnCodes error -result {bitmap "badValue" not defined}
test menubutton-1.15 {configuration options} -body {
    .mb configure -borderwidth 1.3
    .mb cget -borderwidth
} -cleanup {
    .mb configure -borderwidth [lindex [.mb configure -borderwidth] 3]
} -result 1
} -result {1}
test menubutton-1.16 {configuration options} -body {
    .mb configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test menubutton-1.17 {configuration options} -body {
    .mb configure -cursor arrow
    .mb cget -cursor
} -cleanup {
    .mb configure -cursor [lindex [.mb configure -cursor] 3]
} -result {arrow}
test menubutton-1.18 {configuration options} -body {
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168







-
+







    .mb configure -foreground bogus
} -returnCodes error -result {unknown color name "bogus"}
test menubutton-1.28 {configuration options} -body {
    .mb configure -height 18
    .mb cget -height
} -cleanup {
    .mb configure -height [lindex [.mb configure -height] 3]
} -result 18
} -result {18}
test menubutton-1.29 {configuration options} -body {
    .mb configure -height 20.0
} -returnCodes error -result {expected integer but got "20.0"}
test menubutton-1.30 {configuration options} -body {
    .mb configure -highlightbackground #112233
    .mb cget -highlightbackground
} -cleanup {
181
182
183
184
185
186
187
188

189
190
191

192
193
194
195
196
197
198
181
182
183
184
185
186
187

188
189
190

191
192
193
194
195
196
197
198







-
+


-
+







    .mb configure -highlightcolor bogus
} -returnCodes error -result {unknown color name "bogus"}
test menubutton-1.34 {configuration options} -body {
    .mb configure -highlightthickness 18
    .mb cget -highlightthickness
} -cleanup {
    .mb configure -highlightthickness [lindex [.mb configure -highlightthickness] 3]
} -result 18
} -result {18}
test menubutton-1.35 {configuration options} -body {
    .mb configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test menubutton-1.36 {configuration options} -constraints {
    testImageType
} -setup {
    catch {image delete image1}
    image create test image1
} -body {
    .mb configure -image image1
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223







-
+







    .mb configure -image [lindex [.mb configure -image] 3]
} -returnCodes error -result {image "bogus" doesn't exist}
test menubutton-1.38 {configuration options} -body {
    .mb configure -indicatoron yes
    .mb cget -indicatoron
} -cleanup {
    .mb configure -indicatoron [lindex [.mb configure -indicatoron] 3]
} -result 1
} -result {1}
test menubutton-1.39 {configuration options} -body {
    .mb configure -indicatoron no_way
} -returnCodes error -result {expected boolean value but got "no_way"}
test menubutton-1.40 {configuration options} -body {
    .mb configure -justify right
    .mb cget -justify
} -cleanup {
233
234
235
236
237
238
239
240

241
242
243

244
245
246
247
248
249

250
251
252

253
254
255
256
257
258
259
233
234
235
236
237
238
239

240
241
242

243
244
245
246
247
248

249
250
251

252
253
254
255
256
257
258
259







-
+


-
+





-
+


-
+







    .mb configure -menu [lindex [.mb configure -menu] 3]
} -result {any old string}
test menubutton-1.43 {configuration options} -body {
    .mb configure -padx 12
    .mb cget -padx
} -cleanup {
    .mb configure -padx [lindex [.mb configure -padx] 3]
} -result 12
} -result {12}
test menubutton-1.44 {configuration options} -body {
    .mb configure -padx 420x
} -returnCodes error -result {expected screen distance but got "420x"}
} -returnCodes error -result {bad screen distance "420x"}
test menubutton-1.45 {configuration options} -body {
    .mb configure -pady 12
    .mb cget -pady
} -cleanup {
    .mb configure -pady [lindex [.mb configure -pady] 3]
} -result 12
} -result {12}
test menubutton-1.46 {configuration options} -body {
    .mb configure -pady 420x
} -returnCodes error -result {expected screen distance but got "420x"}
} -returnCodes error -result {bad screen distance "420x"}
test menubutton-1.47 {configuration options} -body {
    .mb configure -relief groove
    .mb cget -relief
} -cleanup {
    .mb configure -relief [lindex [.mb configure -relief] 3]
} -result {groove}
test menubutton-1.48 {configuration options} -body {
287
288
289
290
291
292
293
294

295
296
297

298
299
300
301
302
303

304
305
306
307
308
309
310
311
312

313
314
315

316
317
318
319
320
321
322
287
288
289
290
291
292
293

294
295
296

297
298
299
300
301
302

303
304
305
306
307
308
309
310
311

312
313
314

315
316
317
318
319
320
321
322







-
+


-
+





-
+








-
+


-
+







    .mb configure -textvariable [lindex [.mb configure -textvariable] 3]
} -result {i}
test menubutton-1.54 {configuration options} -body {
    .mb configure -underline 5
    .mb cget -underline
} -cleanup {
    .mb configure -underline [lindex [.mb configure -underline] 3]
} -result 5
} -result {5}
test menubutton-1.55 {configuration options} -body {
    .mb configure -underline 3p
} -returnCodes error -result {bad index "3p": must be integer?[+-]integer?, end?[+-]integer?, or ""}
} -returnCodes error -result {expected integer but got "3p"}
test menubutton-1.56 {configuration options} -body {
    .mb configure -width 402
    .mb cget -width
} -cleanup {
    .mb configure -width [lindex [.mb configure -width] 3]
} -result 402
} -result {402}
test menubutton-1.57 {configuration options} -body {
    .mb configure -width 3p
} -returnCodes error -result {expected integer but got "3p"}
test menubutton-1.58 {configuration options} -body {
    .mb configure -wraplength 100
    .mb cget -wraplength
} -cleanup {
    .mb configure -wraplength [lindex [.mb configure -wraplength] 3]
} -result 100
} -result {100}
test menubutton-1.59 {configuration options} -body {
    .mb configure -wraplength 6x
} -returnCodes error -result {expected screen distance but got "6x"}
} -returnCodes error -result {bad screen distance "6x"}


deleteWindows
menubutton .mb -text "Test"
pack .mb
update
test menubutton-2.1 {Tk_MenubuttonCmd procedure} -body {
360
361
362
363
364
365
366
367

368
369
370

371
372
373
374
375
376
377
360
361
362
363
364
365
366

367
368
369

370
371
372
373
374
375
376
377







-
+


-
+







} -returnCodes error -result {wrong # args: should be ".mb cget option"}
test menubutton-3.5 {ButtonWidgetCmd procedure, "cget" option} -body {
    .mb cget -gorp
} -returnCodes error -result {unknown option "-gorp"}
test menubutton-3.6 {ButtonWidgetCmd procedure, "cget" option} -body {
    .mb configure -highlightthickness 3
    .mb cget -highlightthickness
} -result 3
} -result {3}
test menubutton-3.7 {ButtonWidgetCmd procedure, "configure" option} -body {
    llength [.mb configure]
} -result 33
} -result {33}
test menubutton-3.8 {ButtonWidgetCmd procedure, "configure" option} -body {
    .mb configure -gorp
} -returnCodes error -result {unknown option "-gorp"}
test menubutton-3.9 {ButtonWidgetCmd procedure, "configure" option} -body {
    .mb co -bg #ffffff -fg
} -returnCodes error -result {value for "-fg" missing}
test menubutton-3.10 {ButtonWidgetCmd procedure, "configure" option} -body {
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486







-
+








-
+
















-
+













-
+







test menubutton-4.5 {ConfigureMenuButton procedure} -setup {
    deleteWindows
} -body {
    button .mb1 -bitmap questhead
    .mb1 configure -width abc
} -cleanup {
    deleteWindows
} -returnCodes error -result {expected screen distance but got "abc"}
} -returnCodes error -result {bad screen distance "abc"}
test menubutton-4.6 {ConfigureMenuButton procedure} -setup {
    deleteWindows
} -body {
    button .mb1 -bitmap questhead
    catch {.mb1 configure -width abc}
    return $errorInfo
} -cleanup {
    deleteWindows
} -result {expected screen distance but got "abc"
} -result {bad screen distance "abc"
    (processing -width option)
    invoked from within
".mb1 configure -width abc"}

test menubutton-4.7 {ConfigureMenuButton procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    imageCleanup
} -body {
    image create test image1
    button .mb1 -image image1
    .mb1 configure -height 0.5x
} -cleanup {
    deleteWindows
    imageCleanup
} -returnCodes error -result {expected screen distance but got "0.5x"}
} -returnCodes error -result {bad screen distance "0.5x"}
test menubutton-4.8 {ConfigureMenuButton procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    imageCleanup
} -body {
    image create test image1
    button .mb1 -image image1
    catch {.mb1 configure -height 0.5x}
    return $errorInfo
} -cleanup {
    deleteWindows
    imageCleanup
} -result {expected screen distance but got "0.5x"
} -result {bad screen distance "0.5x"
    (processing -height option)
    invoked from within
".mb1 configure -height 0.5x"}

test menubutton-4.9 {ConfigureMenuButton procedure} -constraints {
    nonPortable fonts
} -setup {
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569

570
571
572
573
574
575

576
577
578
579
580
581
582

583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634
635
636

637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
538
539
540
541
542
543
544





545
546
547
548
549
550
551
552
553
554
555
556
557

558
559
560
561
562
563
564

565
566
567
568
569
570

571
572
573
574
575
576
577

578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619
620
621

622
623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649







-
-
-
-
-
+












-
+






-
+





-
+






-
+





-
+













-
+













-
+









-
+









-
+









-
+







    menubutton .mb1
    rename .mb1 {}
    list [info command .mb*] [winfo children .]
} -cleanup {
    deleteWindows
} -result {{} {}}

if {[tk windowingsystem] eq "aqua"} {
    set extraWidth 36
} else {
    set extraWidth 0
}

test menubutton-7.1 {ComputeMenuButtonGeometry procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    image create test image1
} -body {
    menubutton .mb -image image1 -bd 4 -highlightthickness 0
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
    imageCleanup
} -result [list [expr {38 + $extraWidth}] 23]
} -result {38 23}
test menubutton-7.2 {ComputeMenuButtonGeometry procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    image create test image1
} -body {
    menubutton .mb -image image1 -bd 3 -highlightthickness 1
    menubutton .mb -image image1 -bd 1 -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
    imageCleanup
} -result [list [expr {38 + $extraWidth}] 23]
} -result {36 21}
test menubutton-7.3 {ComputeMenuButtonGeometry procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    image create test image1
} -body {
    menubutton .mb -image image1 -bd 1 -highlightthickness 3 -padx 5 -pady 5
    menubutton .mb -image image1 -bd 0 -highlightthickness 2 -padx 5 -pady 5
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
    imageCleanup
} -result [list [expr {38 + $extraWidth}] 23]
} -result {34 19}
test menubutton-7.4 {ComputeMenuButtonGeometry procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    image create test image1
} -body {
    menubutton .mb -image image1 -bd 2 -relief raised -width 40 \
        -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
    imageCleanup
} -result [list [expr {48 + $extraWidth}] 23]
} -result {48 23}
test menubutton-7.5 {ComputeMenuButtonGeometry procedure} -constraints {
    testImageType
} -setup {
    deleteWindows
    image create test image1
} -body {
    menubutton .mb -image image1 -bd 2 -relief raised -height 30 \
        -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
    imageCleanup
} -result [list [expr {38 + $extraWidth}] 38]
} -result {38 38}
test menubutton-7.6 {ComputeMenuButtonGeometry procedure} -setup {
    deleteWindows
} -body {
    menubutton .mb -bitmap question -bd 2 -relief raised \
        -highlightthickness 2
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
} -result [list [expr {25 + $extraWidth}] 35]
} -result {25 35}
test menubutton-7.7 {ComputeMenuButtonGeometry procedure} -setup {
    deleteWindows
} -body {
    menubutton .mb -bitmap question -bd 2 -relief raised -width 40 \
        -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
} -result [list [expr {46 + $extraWidth}] 33]
} -result {46 33}
test menubutton-7.8 {ComputeMenuButtonGeometry procedure} -setup {
    deleteWindows
} -body {
    menubutton .mb -bitmap question -bd 2 -relief raised -height 50 \
        -highlightthickness 1
    pack .mb
    list [winfo reqwidth .mb] [winfo reqheight .mb]
} -cleanup {
    deleteWindows
} -result [list [expr {23 + $extraWidth}] 56]
} -result {23 56}
test menubutton-7.9 {ComputeMenuButtonGeometry procedure} -constraints {
    fonts
} -setup {
    deleteWindows
} -body {
    menubutton .mb -text String -bd 2 -relief raised -padx 0 -pady 0 \
        -highlightthickness 1
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
742
743
744
745
746
747
748





























749
750
751
752
753
754
755







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    menubutton .mb
    interp hide {} .mb
    destroy .mb
    set res1 [list [winfo children .] [interp hidden]]
    set res2 [list {} $l]
    expr {$res1 eq $res2}
} -result 1

test menubutton-9.1 {Bug [5d991b822e]} {
    # Want this not to segfault, or write to variable with empty name
    unset -nocomplain {}
    set var INIT
    menubutton .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
    info exists {}
} 0
test menubutton-9.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    menubutton .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}




deleteWindows
option clear
imageFinish

Changes to tests/message.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test out the "message" command
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-2000 Ajuba Solutions.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::loadTestedCommands
eval tcltest::configure $argv

37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+







    pack .m
    update
} -body {
    .m configure -aspect 3
    .m cget -aspect
} -cleanup {
    destroy .m
} -result 3
} -result {3}
test message-1.4 {configuration option: "aspect"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -aspect bogus
} -cleanup {
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100







-
+








-
+







    pack .m
    update
} -body {
    .m configure -bd 4
    .m cget -bd
} -cleanup {
    destroy .m
} -result 4
} -result {4}
test message-1.8 {configuration option: "bd"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -bd badValue
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test message-1.9 {configuration option: "bg"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -bg #ff0000
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140







-
+








-
+







    pack .m
    update
} -body {
    .m configure -borderwidth 1.3
    .m cget -borderwidth
} -cleanup {
    destroy .m
} -result 1.3
} -result {1}
test message-1.12 {configuration option: "borderwidth"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -borderwidth badValue
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test message-1.13 {configuration option: "cursor"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -cursor arrow
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280







-
+








-
+







    pack .m
    update
} -body {
    .m configure -highlightthickness  2
    .m cget -highlightthickness
} -cleanup {
    destroy .m
} -result 2
} -result {2}
test message-1.26 {configuration option: "highlightthickness"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -highlightthickness  badValue
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test message-1.27 {configuration option: "justify"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -justify  right
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340







-
+



















-
+







    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -padx 420x
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance or "" but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}

test message-1.31 {configuration option: "pady"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -pady  12m
    .m cget -pady
} -cleanup {
    destroy .m
} -result {12m}
test message-1.32 {configuration option: "pady"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -pady 420x
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance or "" but got "420x"}
} -returnCodes {error} -result {bad screen distance "420x"}

test message-1.33 {configuration option: "relief"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -relief ridge
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422







-
+








-
+











-
+







-
+







    pack .m
    update
} -body {
    .m configure -width  2
    .m cget -width
} -cleanup {
    destroy .m
} -result 2
} -result {2}
test message-1.38 {configuration option: "width"} -setup {
    message .m -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
    pack .m
    update
} -body {
    .m configure -width badValue
} -cleanup {
    destroy .m
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}


test message-2.1 {Tk_MessageObjCmd procedure} -body {
    message
} -returnCodes {error} -result {wrong # args: should be "message pathName ?-option value ...?"}

test message-2.2 {Tk_MessageObjCmd procedure} -body {
    message foo
} -returnCodes {error} -result {bad window path name "foo"}
test message-2.3 {Tk_MessageObjCmd procedure} -body {
    catch {message foo}
    winfo children .
    winfo child .
} -result {}

test message-2.4 {Tk_MessageObjCmd procedure} -body {
    message .s -gorp dump
} -returnCodes {error} -result {unknown option "-gorp"}
test message-2.5 {Tk_MessageObjCmd procedure} -body {
    catch {message .s -gorp dump}
    winfo children .
    winfo child .
} -result {}


test message-3.1 {MessageWidgetObjCmd procedure} -setup {
    message .m
} -body {
    .m
448
449
450
451
452
453
454
455

456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472




























473
474







-
+















-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


} -result {foobar}
test message-3.5 {MessageWidgetObjCmd procedure, "configure"} -setup {
    message .m
} -body {
    llength [.m configure]
} -cleanup {
    destroy .m
} -result 21
} -result {21}
test message-3.6 {MessageWidgetObjCmd procedure, "configure"} -setup {
    message .m
} -body {
    .m configure -foo
} -cleanup {
    destroy .m
} -returnCodes error -result {unknown option "-foo"}
test message-3.7 {MessageWidgetObjCmd procedure, "configure"} -setup {
    message .m
} -body {
    .m configure -bd 4
    .m configure -bg #ffffff
    lindex [.m configure -bd] 4
} -cleanup {
    destroy .m
} -result 4
} -result {4}

test message-4.1 {Bug [5d991b822e]} {
    # Want this not to segfault, or write to variable with empty name
    unset -nocomplain {}
    set var INIT
    message .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
    info exists {}
} 0
test message-4.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    message .b -textvariable var
    trace add variable var unset {apply {args {
        .b configure -textvariable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}

cleanupTests
return

Changes to tests/msgbox.test.

1
2
3
4
5


6
7
8
9
10
11
12
13
14

15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
2
3


4
5
6
7
8
9
10
11
12
13

14
15
16

17



18
19



20
21
22
23
24
25
26



-
-
+
+








-
+


-
+
-
-
-


-
-
-







# This file is a Tcl script to test out Tk's "tk_messageBox" command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test


test msgbox-1.1.1 {tk_messageBox command} -constraints notAqua -body {
test msgbox-1.1 {tk_messageBox command} -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, or -type}
test msgbox-1.1.2 {tk_messageBox command} -constraints aqua -body {
test msgbox-1.2 {tk_messageBox command} -body {
    tk_messageBox -foo
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, -type, or -command}
test msgbox-1.2.1 {tk_messageBox command} -constraints notAqua -body {
    tk_messageBox -foo bar
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, or -type}
test msgbox-1.2.2 {tk_messageBox command} -constraints aqua -body {
    tk_messageBox -foo bar
} -returnCodes error -result {bad option "-foo": must be -default, -detail, -icon, -message, -parent, -title, -type, or -command}

test msgbox-1.3 {tk_messageBox command} -body {
    tk_messageBox -default
} -returnCodes error -result {value for "-default" missing}
test msgbox-1.4 {tk_messageBox command} -body {
    tk_messageBox -detail
} -returnCodes error -result {value for "-detail" missing}
50
51
52
53
54
55
56



57

58
59
60
61




62
63
64
65




66
67
68
69
70
71
72
73
74
75
76
77
78
79
44
45
46
47
48
49
50
51
52
53

54
55
56
57

58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81







+
+
+
-
+



-
+
+
+
+



-
+
+
+
+






-







    tk_messageBox -default
} -returnCodes error -result {value for "-default" missing}

test msgbox-1.11 {tk_messageBox command} -body {
    tk_messageBox -type foo
} -returnCodes error -result {bad -type value "foo": must be abortretryignore, ok, okcancel, retrycancel, yesno, or yesnocancel}

test msgbox-1.12 {tk_messageBox command} -constraints unix -body {
    tk_messageBox -default 1.1
} -returnCodes error -result {invalid default button "1.1"}
test msgbox-1.13 {tk_messageBox command} -body {
test msgbox-1.13 {tk_messageBox command} -constraints macOrWin -body {
    tk_messageBox -default 1.1
} -returnCodes error -result {bad -default value "1.1": must be abort, retry, ignore, ok, cancel, no, or yes}

test msgbox-1.14 {tk_messageBox command} -body {
test msgbox-1.14 {tk_messageBox command} -constraints unix -body {
    tk_messageBox -default foo
} -returnCodes error -result {invalid default button "foo"}
test msgbox-1.15 {tk_messageBox command} -constraints macOrWin -body {
    tk_messageBox -default foo
} -returnCodes error -result {bad -default value "foo": must be abort, retry, ignore, ok, cancel, no, or yes}

test msgbox-1.16 {tk_messageBox command} -body {
test msgbox-1.16 {tk_messageBox command} -constraints unix -body {
    tk_messageBox -type yesno -default 3
} -returnCodes error -result {invalid default button "3"}
test msgbox-1.17 {tk_messageBox command} -constraints macOrWin -body {
    tk_messageBox -type yesno -default 3
} -returnCodes error -result {bad -default value "3": must be abort, retry, ignore, ok, cancel, no, or yes}

test msgbox-1.18 {tk_messageBox command} -body {
    tk_messageBox -icon foo
} -returnCodes error -result {bad -icon value "foo": must be error, info, question, or warning}

test msgbox-1.19 {tk_messageBox command} -body {
    tk_messageBox -parent foo.bar
} -returnCodes error -result {bad window path name "foo.bar"}


catch {tk_messageBox -foo bar}
set isNative [expr {[info commands tk::MessageBox] == ""}]
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125







-
+


















-
+







    if {!$isNative} {
	after 100 SendEventToMsg $parent $btn key
    }
}

proc PressButton {btn} {
    event generate $btn <Enter>
    event generate $btn <Button-1> -x 5 -y 5
    event generate $btn <ButtonPress-1> -x 5 -y 5
    event generate $btn <ButtonRelease-1> -x 5 -y 5
}

proc SendEventToMsg {parent btn type} {
    if {$parent != "."} {
	set w $parent.__tk__messagebox
    } else {
	set w .__tk__messagebox
    }
    if ![winfo ismapped $w.$btn] {
	update
    }
    if {$type == "mouse"} {
	PressButton $w.$btn
    } else {
	event generate $w <Enter>
	focus $w
	event generate $w.$btn <Enter>
	event generate $w <Key> -keysym Return
	event generate $w <KeyPress> -keysym Return
    }
}
#
# Try out all combinations of (type) x (default button) and
# (type) x (icon).
#
test msgbox-2.1 {tk_messageBox command} -constraints {

Changes to tests/obj.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test new object types in Tk.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

Added tests/oldpack.test.









































































































































































































































































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# This file is a Tcl script to test out the old syntax of Tk's
# "pack" command (before release 3.3).  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright (c) 1991-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# First, test a single window packed in various ways in a parent

destroy .pack
frame .pack
place .pack -width 100 -height 100
frame .pack.red -width 10 -height 20
label .pack.red.l -text R -bd 2 -relief raised
place .pack.red.l -relwidth 1.0 -relheight 1.0
frame .pack.green -width 30 -height 40
label .pack.green.l -text G -bd 2 -relief raised
place .pack.green.l -relwidth 1.0 -relheight 1.0
frame .pack.blue -width 40 -height 40
label .pack.blue.l -text B -bd 2 -relief raised
place .pack.blue.l -relwidth 1.0 -relheight 1.0
frame .pack.violet -width 80 -height 20
label .pack.violet.l -text P -bd 2 -relief raised
place .pack.violet.l -relwidth 1.0 -relheight 1.0

test oldpack-1.1 {basic positioning} -body {
    pack ap .pack .pack.red top
    update
    winfo geometry .pack.red
} -result 10x20+45+0
test oldpack-1.2 {basic positioning} -body {
    pack append .pack .pack.red bottom
    update
    winfo geometry .pack.red
} -result 10x20+45+80
test oldpack-1.3 {basic positioning} -body {
    pack append .pack .pack.red left
    update
    winfo geometry .pack.red
} -result 10x20+0+40
test oldpack-1.4 {basic positioning} -body {
    pack append .pack .pack.red right
    update
    winfo geometry .pack.red
} -result 10x20+90+40

# Try adding padding around the window and make sure that the
# window gets a larger frame.

test oldpack-2.1 {padding} -body {
    pack append .pack .pack.red {t padx 20}
    update
    winfo geometry .pack.red
} -result 10x20+45+0
test oldpack-2.2 {padding} -body {
    pack append .pack .pack.red {top pady 20}
    update
    winfo geometry .pack.red
} -result 10x20+45+10
test oldpack-2.3 {padding} -body {
    pack append .pack .pack.red {l padx 20}
    update
    winfo geometry .pack.red
} -result 10x20+10+40
test oldpack-2.4 {padding} -body {
    pack append .pack .pack.red {left pady 20}
    update
    winfo geometry .pack.red
} -result 10x20+0+40

# Position the window at different positions in its frame to
# make sure they all work.  Try two differenet frame locations,
# to make sure that frame offsets are being added in correctly.

test oldpack-3.1 {framing} -body {
    pack append .pack .pack.red {b padx 20 pady 30}
    update
    winfo geometry .pack.red
} -result 10x20+45+65
test oldpack-3.2 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 fr n}
    update
    winfo geometry .pack.red
} -result 10x20+45+50
test oldpack-3.3 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame ne}
    update
    winfo geometry .pack.red
} -result 10x20+90+50
test oldpack-3.4 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame e}
    update
    winfo geometry .pack.red
} -result 10x20+90+65
test oldpack-3.5 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame se}
    update
    winfo geometry .pack.red
} -result 10x20+90+80
test oldpack-3.6 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame s}
    update
    winfo geometry .pack.red
} -result 10x20+45+80
test oldpack-3.7 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame sw}
    update
    winfo geometry .pack.red
} -result 10x20+0+80
test oldpack-3.8 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame w}
    update
    winfo geometry .pack.red
} -result 10x20+0+65
test oldpack-3.9 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame nw}
    update
    winfo geometry .pack.red
} -result 10x20+0+50
test oldpack-3.10 {framing} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 frame c}
    update
    winfo geometry .pack.red
} -result 10x20+45+65
test oldpack-3.11 {framing} -body {
    pack append .pack .pack.red {r padx 20 pady 30}
    update
    winfo geometry .pack.red
} -result 10x20+80+40
test oldpack-3.12 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame n}
    update
    winfo geometry .pack.red
} -result 10x20+80+0
test oldpack-3.13 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame ne}
    update
    winfo geometry .pack.red
} -result 10x20+90+0
test oldpack-3.14 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame e}
    update
    winfo geometry .pack.red
} -result 10x20+90+40
test oldpack-3.15 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame se}
    update
    winfo geometry .pack.red
} -result 10x20+90+80
test oldpack-3.16 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame s}
    update
    winfo geometry .pack.red
} -result 10x20+80+80
test oldpack-3.17 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame sw}
    update
    winfo geometry .pack.red
} -result 10x20+70+80
test oldpack-3.18 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame w}
    update
    winfo geometry .pack.red
} -result 10x20+70+40
test oldpack-3.19 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame nw}
    update
    winfo geometry .pack.red
} -result 10x20+70+0
test oldpack-3.20 {framing} -body {
    pack append .pack .pack.red {right padx 20 pady 30 frame center}
    update
    winfo geometry .pack.red
} -result 10x20+80+40

# Try out various filling combinations in a couple of different
# frame locations.

test oldpack-4.1 {filling} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 fillx}
    update
    winfo geometry .pack.red
} -result 100x20+0+65
test oldpack-4.2 {filling} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 filly}
    update
    winfo geometry .pack.red
} -result 10x50+45+50
test oldpack-4.3 {filling} -body {
    pack append .pack .pack.red {bottom padx 20 pady 30 fill}
    update
    winfo geometry .pack.red
} -result 100x50+0+50
test oldpack-4.4 {filling} -body {
    pack append .pack .pack.red {right padx 20 pady 30 fillx}
    update
    winfo geometry .pack.red
} -result 30x20+70+40
test oldpack-4.5 {filling} -body {
    pack append .pack .pack.red {right padx 20 pady 30 filly}
    update
    winfo geometry .pack.red
} -result 10x100+80+0
test oldpack-4.6 {filling} -body {
    pack append .pack .pack.red {right padx 20 pady 30 fill}
    update
    winfo geometry .pack.red
} -result 30x100+70+0

# Multiple windows:  make sure that space is properly subtracted
# from the cavity as windows are positioned inwards from all
# different sides.  Also make sure that windows get unmapped if
# there isn't enough space for them.

pack append .pack .pack.red top .pack.green top .pack.blue top \
    .pack.violet top
update
test oldpack-5.1 {multiple windows} -body {
    winfo geometry .pack.red
} -result 10x20+45+0
test oldpack-5.2 {multiple windows} -body {
    winfo geometry .pack.green
} -result 30x40+35+20
test oldpack-5.3 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x40+30+60
test oldpack-5.4 {multiple windows} -body {
    winfo ismapped .pack.violet
} -result 0

pack b .pack.blue .pack.violet top
update
test oldpack-5.5 {multiple windows} -body {
    winfo ismapped .pack.violet
} -result 1
test oldpack-5.6 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 80x20+10+60
test oldpack-5.7 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x20+30+80

pack after .pack.blue .pack.red top
update
test oldpack-5.8 {multiple windows} -body {
    winfo geometry .pack.green
} -result 30x40+35+0
test oldpack-5.9 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 80x20+10+40
test oldpack-5.10 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x40+30+60
test oldpack-5.11 {multiple windows} -body {
    winfo ismapped .pack.red
} -result 0

pack before .pack.green .pack.red right .pack.blue left
update
test oldpack-5.12 {multiple windows} -body {
    winfo ismapped .pack.red
} -result 1
test oldpack-5.13 {multiple windows} -body {
    winfo geometry .pack.red
} -result 10x20+90+40
test oldpack-5.14 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x40+0+30
test oldpack-5.15 {multiple windows} -body {
    winfo geometry .pack.green
} -result 30x40+50+0
test oldpack-5.16 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 50x20+40+40

pack append .pack .pack.violet left .pack.green bottom .pack.red bottom \
    .pack.blue bottom
update
test oldpack-5.17 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 80x20+0+40
test oldpack-5.18 {multiple windows} -body {
    winfo geometry .pack.green
} -result 20x40+80+60
test oldpack-5.19 {multiple windows} -body {
    winfo geometry .pack.red
} -result 10x20+85+40
test oldpack-5.20 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 20x40+80+0

pack after .pack.blue .pack.blue top .pack.red right .pack.green right \
    .pack.violet right
update
test oldpack-5.21 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x40+30+0
test oldpack-5.22 {multiple windows} -body {
    winfo geometry .pack.red
} -result 10x20+90+60
test oldpack-5.23 {multiple windows} -body {
    winfo geometry .pack.green
} -result 30x40+60+50
test oldpack-5.24 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 60x20+0+60

pack after .pack.blue .pack.red left .pack.green left .pack.violet left
update
test oldpack-5.25 {multiple windows} -body {
    winfo geometry .pack.blue
} -result 40x40+30+0
test oldpack-5.26 {multiple windows} -body {
    winfo geometry .pack.red
} -result 10x20+0+60
test oldpack-5.27 {multiple windows} -body {
    winfo geometry .pack.green
} -result 30x40+10+50
test oldpack-5.28 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 60x20+40+60

pack append .pack .pack.violet left .pack.green left .pack.blue left \
    .pack.red left
update
test oldpack-5.29 {multiple windows} -body {
    winfo geometry .pack.violet
} -result 80x20+0+40
test oldpack-5.30 {multiple windows} -body {
    winfo geometry .pack.green
} -result 20x40+80+30
test oldpack-5.31 {multiple windows} -body {
    winfo ismapped .pack.blue
} -result 0
test oldpack-5.32 {multiple windows} -body {
    winfo ismapped .pack.red
} -result 0


# Test the ability of the packer to propagate geometry information
# to its parent.  Make sure it computes the parent's needs both in
# the direction of packing (width for "left" and "right" windows,
# for example), and perpendicular to the pack direction (height for
# "left" and "right" windows).

pack append .pack .pack.red top .pack.green top .pack.blue top \
    .pack.violet top
update
test oldpack-6.1 {geometry propagation} -body {
    winfo reqwidth .pack} -result 80
test oldpack-6.2 {geometry propagation} -body {
    winfo reqheight .pack} -result 120
destroy .pack.violet
update
test oldpack-6.3 {geometry propagation} -body {
    winfo reqwidth .pack} -result 40
test oldpack-6.4 {geometry propagation} -body {
    winfo reqheight .pack} -result 100
frame .pack.violet -width 80 -height 20 -bg violet
label .pack.violet.l -text P -bd 2 -relief raised
place .pack.violet.l -relwidth 1.0 -relheight 1.0
pack append .pack .pack.red left .pack.green right .pack.blue bottom \
    .pack.violet top
update
test oldpack-6.5 {geometry propagation} -body {
    winfo reqwidth .pack} -result 120
test oldpack-6.6 {geometry propagation} -body {
    winfo reqheight .pack} -result 60
pack append .pack .pack.violet top .pack.green top .pack.blue left \
    .pack.red left
update
test oldpack-6.7 {geometry propagation} -body {
    winfo reqwidth .pack} -result 80
test oldpack-6.8 {geometry propagation} -body {
    winfo reqheight .pack} -result 100

# Test the "expand" option, and make sure space is evenly divided
# when several windows request expansion.

pack append .pack .pack.violet top .pack.green {left e} \
    .pack.blue {left expand} .pack.red {left expand}
update
test oldpack-7.1 {multiple expanded windows} -body {
    pack append .pack .pack.violet top .pack.green {left e} \
        .pack.blue {left expand} .pack.red {left expand}
    update
    list [winfo geometry .pack.green] [winfo geometry .pack.blue] \
        [winfo geometry .pack.red]
} -result {30x40+3+40 40x40+39+40 10x20+86+50}
test oldpack-7.2 {multiple expanded windows} -body {
    pack append .pack .pack.green left .pack.violet {bottom expand} \
        .pack.blue {bottom expand} .pack.red {bottom expand}
    update
    list [winfo geometry .pack.violet] [winfo geometry .pack.blue] \
        [winfo geometry .pack.red]
} -result {70x20+30+77 40x40+45+30 10x20+60+3}
test oldpack-7.3 {multiple expanded windows} -body {
    foreach i [winfo child .pack] {
    pack unpack $i
    }
    pack append .pack .pack.green {left e fill} .pack.red {left expand fill} \
        .pack.blue {top fill}
    update
    list [winfo geometry .pack.green] [winfo geometry .pack.red] \
        [winfo geometry .pack.blue]
} -result {40x100+0+0 20x100+40+0 40x40+60+0}
test oldpack-7.4 {multiple expanded windows} -body {
    foreach i [winfo child .pack] {
    pack unpack $i
    }
    pack append .pack .pack.red {top expand} .pack.violet {top expand} \
        .pack.blue {right fill}
    update
    list [winfo geometry .pack.red] [winfo geometry .pack.violet] \
        [winfo geometry .pack.blue]
} -result {10x20+45+5 80x20+10+35 40x40+60+60}
test oldpack-7.5 {multiple expanded windows} -body {
    foreach i [winfo child .pack] {
    pack unpack $i
    }
    pack append .pack .pack.green {right frame s} .pack.red {top expand}
    update
    list [winfo geometry .pack.green] [winfo geometry .pack.red]
} -result {30x40+70+60 10x20+30+40}
test oldpack-7.6 {multiple expanded windows} -body {
    foreach i [winfo child .pack] {
    pack unpack $i
    }
    pack append .pack .pack.violet {bottom frame e} .pack.red {right expand}
    update
    list [winfo geometry .pack.violet] [winfo geometry .pack.red]
} -result {80x20+20+80 10x20+45+30}

# Need more bizarre tests with combinations of expanded windows and
# windows in opposing directions!  Also, include padding in expanded
# (and unexpanded) windows.

# Syntax errors on pack commands

test oldpack-8.1 {syntax errors} -body {
    pack
} -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
test oldpack-8.2 {syntax errors} -body {
    pack append
} -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
test oldpack-8.3 {syntax errors} -body {
    pack gorp foo
} -returnCodes error -result {bad option "gorp": must be configure, forget, info, propagate, or slaves}
test oldpack-8.4 {syntax errors} -body {
    pack a .pack
} -returnCodes error -result {bad option "a": must be configure, forget, info, propagate, or slaves}
test oldpack-8.5 {syntax errors} -body {
    pack after foobar
} -returnCodes error -result {bad window path name "foobar"}
test oldpack-8.6 {syntax errors} -setup {
    destroy .pack.yellow
} -body {
    frame .pack.yellow -bg yellow
    pack after .pack.yellow
} -cleanup {
    destroy .pack.yellow
} -returnCodes error -result {window ".pack.yellow" isn't packed}
test oldpack-8.7 {syntax errors} -body {
    pack append foobar
} -returnCodes error -result {bad window path name "foobar"}
test oldpack-8.8 {syntax errors} -body {
    pack before foobar
} -returnCodes error -result {bad window path name "foobar"}
test oldpack-8.9 {syntax errors} -setup {
    destroy .pack.yellow
} -body {
    frame .pack.yellow -bg yellow
    pack before .pack.yellow
} -cleanup {
    destroy .pack.yellow
} -returnCodes error -result {window ".pack.yellow" isn't packed}
test oldpack-8.10 {syntax errors} -body {
    pack info .pack help
} -returnCodes error -result {wrong # args: should be "pack info window"}
test oldpack-8.11 {syntax errors} -body {
    pack info foobar
} -returnCodes error -result {bad window path name "foobar"}
test oldpack-8.12 {syntax errors} -body {
    pack append .pack .pack.blue
} -returnCodes error -result {wrong # args: window ".pack.blue" should be followed by options}
test oldpack-8.13 {syntax errors} -body {
    pack append . .pack.blue top
} -returnCodes error -result {can't pack .pack.blue inside .}
test oldpack-8.14 {syntax errors} -body {
    pack append .pack .pack.blue f
} -returnCodes error -result {bad option "f": should be top, bottom, left, right, expand, fill, fillx, filly, padx, pady, or frame}
test oldpack-8.15 {syntax errors} -body {
    pack append .pack .pack.blue pad
} -returnCodes error -result {bad option "pad": should be top, bottom, left, right, expand, fill, fillx, filly, padx, pady, or frame}
test oldpack-8.16 {syntax errors} -body {
    pack append .pack .pack.blue {frame south}
} -returnCodes error -result {bad anchor "south": must be n, ne, e, se, s, sw, w, nw, or center}
test oldpack-8.17 {syntax errors} -body {
    pack append .pack .pack.blue {padx -2}
} -returnCodes error -result {bad pad value "-2": must be positive screen distance}
test oldpack-8.18 {syntax errors} -body {
    pack append .pack .pack.blue {padx}
} -returnCodes error -result {wrong # args: "padx" option must be followed by screen distance}
test oldpack-8.19 {syntax errors} -body {
    pack append .pack .pack.blue {pady -2}
} -returnCodes error -result {bad pad value "-2": must be positive screen distance}
test oldpack-8.20 {syntax errors} -body {
    pack append .pack .pack.blue {pady}
} -returnCodes error -result {wrong # args: "pady" option must be followed by screen distance}
test oldpack-8.21 {syntax errors} -body {
    pack append .pack .pack.blue "\{abc"
} -returnCodes error -result {unmatched open brace in list}
test oldpack-8.22 {syntax errors} -body {
    pack append .pack .pack.blue frame
} -returnCodes error -result {wrong # args: "frame" option must be followed by anchor point}

# Test "pack info" command output.

test oldpack-9.1 {information output} -body {
    pack append .pack .pack.blue {top fillx frame n} \
    .pack.red {bottom filly frame s} .pack.green {left fill frame w} \
    .pack.violet {right expand frame e}
    list [pack slaves .pack] [pack info .pack.blue] [pack info .pack.red] \
        [pack info .pack.green] [pack info .pack.violet]
} -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor n -expand 0 -fill x -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor s -expand 0 -fill y -ipadx 0 -ipady 0 -padx 0 -pady 0 -side bottom} {-in .pack -anchor w -expand 0 -fill both -ipadx 0 -ipady 0 -padx 0 -pady 0 -side left} {-in .pack -anchor e -expand 1 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side right}}
test oldpack-9.2 {information output} -body {
    pack append .pack .pack.blue {padx 10 frame nw} \
    .pack.red {pady 20 frame ne} .pack.green {frame se} \
    .pack.violet {frame sw}
    list [pack slaves .pack] [pack info .pack.blue] [pack info .pack.red] \
        [pack info .pack.green] [pack info .pack.violet]
} -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor nw -expand 0 -fill none -ipadx 0 -ipady 0 -padx 5 -pady 0 -side top} {-in .pack -anchor ne -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 10 -side top} {-in .pack -anchor se -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor sw -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top}}
test oldpack-9.3 {information output} -body {
    pack append .pack .pack.blue {frame center} .pack.red {frame center} \
    .pack.green {frame c} .pack.violet {frame c}
    list [pack slaves .pack] [pack info .pack.blue] [pack info .pack.red] \
        [pack info .pack.green] [pack info .pack.violet]
} -result {{.pack.blue .pack.red .pack.green .pack.violet} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top} {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top}}

destroy .pack

# cleanup
cleanupTests
return

Changes to tests/option.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test out the option-handling facilities
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1991-1993 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1991-1993 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

357
358
359
360
361
362
363
364
365


366
367
368
369
370
371
372
357
358
359
360
361
362
363


364
365
366
367
368
369
370
371
372







-
-
+
+







test option-14.12 {error conditions} -body {
    option get .gorp.gorp a A
} -returnCodes error -result {bad window path name ".gorp.gorp"}


set option1 [file join [testsDirectory] option.file1]
test option-15.1 {database files} -body {
    list [catch {option read non-existent} msg] [string tolower $msg]
} -result {1 {couldn't open "non-existent": no such file or directory}}
    option read non-existent
} -returnCodes error -result {couldn't open "non-existent": no such file or directory}
test option-15.2 {database files} -body {
    option read $option1
    option get . x1 color
} -result blue
test option-15.3 {database files} -constraints appNameIsTktest -body {
    option read $option1
    option get . x2 color
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406

407
408
409
410
411
412
413
414
415
416
417


















418
419
420
421
422
423
424
425







-
+














-
+


-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








test option-15.6 {database files} -body {
    option read $option1
	option get . x6 color
} -result {}
test option-15.7 {database files} -body {
    option read $option1
	option get . x9 color
} -result " \\\t\\A\n"
} -result " \t\\A\n"
test option-15.8 {database files} -body {
    option read $option1 widget foo
} -returnCodes error -result {wrong # args: should be "option readfile fileName ?priority?"}
test option-15.9 {database files} -body {
    option add *x3 burgundy
    catch {option read $option1 userDefault}
    option get . x3 color
} -result burgundy
test option-15.10 {database files} -body {
    set option2 [file join [testsDirectory] option.file2]
    option read $option2
} -returnCodes error -result {missing colon on line 2}
set option3 [file join [testsDirectory] option.file3]
option read $option3
test option-15.11 {database files} {option get . {x 4} color} brówn
test option-15.11 {database files} {option get . {x 4} color} br\xf3wn

test option-16.1 {ReadOptionFile} -body {
    set option4 [makeFile {} option.file4]
    set option4 [makeFile {} option.file3]
    set file [open $option4 w]
    fconfigure $file -translation crlf
    puts $file "*x7: true\n*x8: false"
    close $file
    option read $option4 userDefault
    list [option get . x7 color] [option get . x8 color]
} -cleanup {
    removeFile $option4
} -result {true false}

set opt162val {label {
  foo bar
}
}
set opt162list [split $opt162val \n]

test option-16.2 {ticket 766ef52f3} -body {
    set option5 [makeFile {} option.file5]
    set file [open $option5 w]
    fconfigure $file -translation crlf
    puts $file "*notok: $opt162list"
    close $file
    option read $option5 userDefault
    option get . notok notok
} -cleanup {
    removeFile $option5
} -result $opt162list

deleteWindows

# cleanup
cleanupTests
return



Changes to tests/pack.test.

1
2


3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


1
2
3



4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
-
-
+
+

-
-
-
+
+
+







-
-







# This file is a Tcl script to test out the "pack" command of Tk.  It is
# organized in the standard fashion for Tcl tests.
# This file is a Tcl script to test out the "pack" command
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1993 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1993 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Create some test windows.

destroy .pack
toplevel .pack
wm geom .pack 300x200+0+0
wm minsize .pack 1 1
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260







+


















+







    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side top -ipadx 5 -padx {5 15} -fill x
    pack .pack.b -expand yes -fill both
    update
    list [winfo geometry .pack.a] [winfo geometry .pack.b]
} -result {280x40+5+0 300x160+0+40}

test pack-2.22 {x padding and filling} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -padx 1c
    set x [pack info .pack.a]
    set res1 [lindex $x [expr [lsearch -exact $x -padx]+1]]
    set res2 [winfo pixels .pack 1c]
    expr {$res1 eq $res2}
} -result 1
test pack-2.23 {x padding and filling} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -ipadx 1c
    set x [pack info .pack.a]
    set res1 [lindex $x [expr [lsearch -exact $x -ipadx]+1]]
    set res2 [winfo pixels .pack 1c]
    expr {$res1 eq $res2}
} -result 1


test pack-3.1 {y padding and filling} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side right -pady 20
    pack .pack.b -expand yes -fill both
    update
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449







+


















+







    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side top -ipady 5 -pady {1 19} -fill y
    pack .pack.b -expand yes -fill both
    update
    list [winfo geometry .pack.a] [winfo geometry .pack.b]
} -result {20x50+140+1 300x130+0+70}

test pack-3.22 {y padding and filling} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -pady 1c
    set x [pack info .pack.a]
    set res1 [lindex $x [expr [lsearch -exact $x -pady]+1]]
    set res2 [winfo pixels .pack 1c]
    expr {$res1 eq $res2}
} -result 1
test pack-3.23 {y padding and filling} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -ipady 1c
    set x [pack info .pack.a]
    set res1 [lindex $x [expr [lsearch -exact $x -ipady]+1]]
    set res2 [winfo pixels .pack 1c]
    expr {$res1 eq $res2}
} -result 1


test pack-4.1 {anchors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side top -ipadx 5 -padx 10 -ipady 15 -pady 20 -expand y -anchor n
    update
    winfo geometry .pack.a
498
499
500
501
502
503
504

505
506
507
508
509
510
511
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514







+







test pack-4.9 {anchors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side top -ipadx 5 -padx 10 -ipady 15 -pady 20 -expand y -anchor center
    update
    winfo geometry .pack.a
} -result {30x70+135+65}


# Repeat above tests, but with a frame that isn't at (0,0), so that
# we can be sure that the frame offset is being added in correctly.

test pack-5.1 {more anchors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
583
584
585
586
587
588
589

590
591
592
593
594
595
596
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600







+







} -body {
    pack .pack.a -side  top
    pack .pack.c -side left
    pack .pack.b -side top -ipadx 5 -padx 10 -ipady 15 -pady 20 -expand y -anchor center
    update
    winfo geometry .pack.b
} -result {60x60+160+90}


test pack-6.1 {-expand option} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side left
    update
    list [winfo geometry .pack.a] [winfo geometry .pack.b] \
689
690
691
692
693
694
695

696
697
698
699
700
701
702
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707







+







    pack .pack.b -side top -expand yes -fill both
    pack .pack.c -side right -expand 1 -fill both
    pack .pack.d -side bottom -expand yes -fill both
    update
    list [winfo geometry .pack.a] [winfo geometry .pack.b] \
        [winfo geometry .pack.c] [winfo geometry .pack.d]
} -result {100x200+0+0 200x100+100+0 160x100+140+100 40x100+100+100}

test pack-6.12 {-expand option} -setup {
    toplevel .pack2 -height 400 -width 400
    wm geometry .pack2 +0+0
    pack propagate .pack2 0
    foreach i {w1 w2 w3} {
        frame .pack2.$i -width 30 -height 30 -bd 2 -relief raised
        label .pack2.$i.l -text $i
722
723
724
725
726
727
728

729
730
731
732
733
734
735
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741







+







    pack .pack2.w1 .pack2.w2 .pack2.w3 -padx 5 -ipadx 4 -pady 2 \
        -ipady 6 -expand 1 -side top
    update
    list [winfo geometry .pack2.w1] [winfo geometry .pack2.w2] [winfo geometry .pack2.w3]
} -cleanup {
    destroy .pack2
} -result {38x42+181+45 38x42+181+178 38x42+181+312}


wm geometry .pack {}
test pack-7.1 {requesting size for parent} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side left -padx 5 -pady 10
    update
780
781
782
783
784
785
786

787
788
789
790
791
792
793
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800







+







} -body {
    pack .pack.a -side right
    pack .pack.c -side bottom
    pack .pack.d -side top
    update
    list [winfo reqwidth .pack] [winfo reqheight .pack]
} -result {100 110}


# For the tests below, create a couple of "pad" windows to shrink
# the available space for the remaining windows.  The tests have to
# be done this way rather than shrinking the whole window, because
# some window managers like mwm won't let a top-level window get
# very small.

860
861
862
863
864
865
866

867
868
869
870
871
872
873

874
875
876
877
878
879
880

881
882
883
884
885
886
887

888
889
890
891
892
893
894

895
896
897
898
899
900
901
902

903
904
905
906
907
908
909

910
911
912
913
914
915
916

917
918
919
920
921
922
923

924
925
926
927
928
929
930

931
932
933
934
935
936
937

938

939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964

965
966
967
968
969
970


971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
867
868
869
870
871
872
873
874
875
876
877
878
879
880

881
882
883
884
885
886
887

888
889
890
891
892
893
894

895
896
897
898
899
900
901

902
903
904
905
906
907
908
909

910
911
912
913
914
915
916

917
918
919
920
921
922
923

924
925
926
927
928
929
930

931
932
933
934
935
936
937

938
939
940
941
942
943
944

945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

966
967
968
969
970
971
972

973
974
975
976
977


978
979




















980
981
982
983
984
985
986







+






-
+






-
+






-
+






-
+







-
+






-
+






-
+






-
+






-
+






-
+

+


















-
+






-
+




-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







update
test pack-8.9 {insufficient space} -body {
    list [winfo geometry .pack.a] [winfo ismapped .pack.a] \
        [winfo geometry .pack.b] [winfo ismapped .pack.b] \
        [winfo geometry .pack.c] [winfo ismapped .pack.c]
} -result {20x40+0+20 1 50x30+100+25 1 80x80+20+0 1}
pack forget .pack.right .pack.bottom


test pack-9.1 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.a -after .pack.b
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.a .pack.c .pack.d}
test pack-9.2 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.a -after .pack.a
    pack content .pack
    pack slaves .pack
} -result {.pack.a .pack.b .pack.c .pack.d}
test pack-9.3 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.a -before .pack.d
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.c .pack.a .pack.d}
test pack-9.4 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.d -before .pack.a
    pack content .pack
    pack slaves .pack
} -result {.pack.d .pack.a .pack.b .pack.c}
test pack-9.5 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack propagate .pack.c 0
    pack .pack.a -in .pack.c
    list [pack content .pack] [pack content .pack.c]
    list [pack slaves .pack] [pack slaves .pack.c]
} -result {{.pack.b .pack.c .pack.d} .pack.a}
test pack-9.6 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.a -in .pack
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.c .pack.d .pack.a}
test pack-9.7 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d -side top
    pack .pack.a -padx 0
    pack content .pack
    pack slaves .pack
} -result {.pack.a .pack.b .pack.c .pack.d}
test pack-9.8 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c
    pack .pack.d
    pack content .pack
    pack slaves .pack
} -result {.pack.a .pack.b .pack.c .pack.d}
test pack-9.9 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d
    pack .pack.b .pack.d .pack.c -before .pack.a
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.d .pack.c .pack.a}
test pack-9.10 {window ordering} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d
    pack .pack.a .pack.c .pack.d .pack.b -after .pack.a
    pack content .pack
    pack slaves .pack
} -result {.pack.a .pack.c .pack.d .pack.b}


test pack-10.1 {retaining/clearing configuration state} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side bottom -anchor n -padx 1 -pady 2 -ipadx 3 -ipady 4 \
    -fill both -expand 1
    pack forget .pack.a
    pack .pack.a
    pack info .pack.a
} -result {-in .pack -anchor center -expand 0 -fill none -ipadx 0 -ipady 0 -padx 0 -pady 0 -side top}
test pack-10.2 {retaining/clearing configuration state} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side bottom -anchor n -padx 1 -pady 2 -ipadx 3 -ipady 4 \
    -fill both -expand 1
    pack .pack.a -pady 14
    pack info .pack.a
} -result {-in .pack -anchor n -expand 1 -fill both -ipadx 3 -ipady 4 -padx 1 -pady 14 -side bottom}
test pack-10.3 {bad -in window does not change container window} -setup {
test pack-10.3 {bad -in window does not change master} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    set result [list [winfo manager .pack.a]]
    catch {pack .pack.a -in .pack.a}
    lappend result [winfo manager .pack.a]
} -result {{} {}}
test pack-10.4 {bad -in window does not change container window} -setup {
test pack-10.4 {bad -in window does not change master} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    winfo manager .pack.a
    pack .pack.a -in .pack.a
} -returnCodes error -result {can't pack ".pack.a" inside itself}
test pack-10.5 {prevent management loops} -body {
} -returnCodes error -result {can't pack .pack.a inside itself}

    frame .f1
    frame .f2
    pack .f1 -in .f2
    pack .f2 -in .f1
} -cleanup {
    destroy .f1
    destroy .f2
} -returnCodes error -result {can't put ".f2" inside ".f1": would cause management loop}
test pack-10.6 {prevent management loops} -body {
    frame .f1
    frame .f2
    frame .f3
    pack .f1 -in .f2
    pack .f2 -in .f3
    pack .f3 -in .f1
} -cleanup {
    destroy .f1
    destroy .f2
    destroy .f3
} -returnCodes error -result {can't put ".f3" inside ".f1": would cause management loop}

test pack-11.1 {info option} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -in .pack
    set i [pack info .pack.a]
    lindex $i [expr [lsearch -exact $i -in]+1]
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136







+














-
+







test pack-11.19 {info option} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side right
    set i [pack info .pack.a]
    lindex $i [expr [lsearch -exact $i -side]+1]
} -result right


test pack-12.1 {command options and errors} -body {
    pack
} -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
test pack-12.2 {command options and errors} -body {
    pack foo
} -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
test pack-12.3 {command options and errors} -body {
    pack configure x
} -returnCodes error -result {bad argument "x": must be name of window}
test pack-12.4 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack configure .pack.b .pack.c
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.c}
test pack-12.5 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .foo
} -returnCodes error -result {bad window path name ".foo"}
test pack-12.6 {command options and errors} -setup {
1259
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297

1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279
1280
1281

1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297
1298
1299
1300







-
+



















-
+





-
+




-
+





-
+







} -body {
    pack .pack.a -ipady {5 5}
} -returnCodes error -result {bad ipady value "5 5": must be positive screen distance}
test pack-12.29 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -side bac
} -returnCodes error -result {bad side "bac": must be bottom, left, right, or top}
} -returnCodes error -result {bad side "bac": must be top, bottom, left, or right}
test pack-12.30 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -lousy bac
} -returnCodes error -result {bad option "-lousy": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side}
test pack-12.31 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -padx
} -returnCodes error -result {extra option "-padx" (option with no value?)}
test pack-12.32 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a ? 22
} -returnCodes error -result {bad option "?": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side}
test pack-12.33 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -in .
} -returnCodes error -result {can't pack ".pack.a" inside "."}
} -returnCodes error -result {can't pack .pack.a inside .}
test pack-12.34 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    frame .pack.a.a
    pack .pack.a.a -in .pack.b
} -returnCodes error -result {can't pack ".pack.a.a" inside ".pack.b"}
} -returnCodes error -result {can't pack .pack.a.a inside .pack.b}
test pack-12.35 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a -in .pack.a
} -returnCodes error -result {can't pack ".pack.a" inside itself}
} -returnCodes error -result {can't pack .pack.a inside itself}
test pack-12.36 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a .pack.b .pack.c .pack.d
    pack forget .pack.a .pack.d
    pack content .pack
    pack slaves .pack
} -result {.pack.b .pack.c}
test pack-12.37 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    .pack configure -width 300 -height 200
    pack propagate .pack 0
    pack .pack.a
1337
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350


1351
1352
1353
1354

1355
1356
1357
1358
1359

1360
1361
1362
1363
1364
1365


1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378

1379
1380
1381
1382
1383
1384
1385
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338


1339
1340
1341
1342
1343

1344
1345
1346
1347
1348

1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377







-
+




-
-
+
+



-
+




-
+





-
+
+










-
+


+







    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack propagate .pack foo bar
} -returnCodes error -result {wrong # args: should be "pack propagate window ?boolean?"}
test pack-12.42 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack content
    pack slaves
} -returnCodes error -result {wrong # args: should be "pack option arg ?arg ...?"}
test pack-12.43 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack content a b
} -returnCodes error -result {wrong # args: should be "pack content window"}
    pack slaves a b
} -returnCodes error -result {wrong # args: should be "pack slaves window"}
test pack-12.44 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack content .x
    pack slaves .x
} -returnCodes error -result {bad window path name ".x"}
test pack-12.45 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack content .pack.a
    pack slaves .pack.a
} -returnCodes ok -result {}
test pack-12.46 {command options and errors} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack lousy .pack
} -returnCodes error -result {bad option "lousy": must be configure, content, forget, info, or propagate}
} -returnCodes error -result {bad option "lousy": must be configure, forget, info, propagate, or slaves}


test pack-13.1 {window deletion} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d .pack.right .pack.bottom
} -body {
    pack .pack.right -side right
    pack .pack.bottom -side bottom
    pack .pack.a .pack.d .pack.b .pack.c -side top
    update
    destroy .pack.d
    update
    set result [list [pack content .pack] [winfo geometry .pack.a] \
    set result [list [pack slaves .pack] [winfo geometry .pack.a] \
        [winfo geometry .pack.b] [winfo geometry .pack.c]]
} -result {{.pack.right .pack.bottom .pack.a .pack.b .pack.c} 20x40+30+0 50x30+15+40 80x80+0+70}


test pack-14.1 {respond to changes in expansion} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d .pack.right .pack.bottom
} -body {
    pack .pack.right -side right
    pack .pack.bottom -side bottom
    wm geom .pack {}
1497
1498
1499
1500
1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515

1516

1517
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556

1557

1558
1559



1560
1561
1562

1563
1564






1565
1566
1567
1568
1569

1570
1571
1572
1573
1574


1575
1576
1577
1578
1579
1580
1581
1582


1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606

1607
1608
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620


1621
1622
1623
1624
1625

1626
1627

1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645

1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518

1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530









1531










1532

1533
1534

1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557


1558
1559
1560
1561
1562
1563




1564
1565




1566













1567


1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583


1584
1585
1586
1587
1588
1589
1590
1591
1592

1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610

1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
























































































1629
1630
1631
1632
1633


1634
1635








+












+
-
+








-
+











-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
+
-
+

-
+
+
+



+

-
+
+
+
+
+
+





+



-
-
+
+




-
-
-
-
+
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-

-
-



+

-







+



-
-
+
+





+

-
+

















-
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+




-
-
+
+
-
    lappend result [winfo geometry .pack.b] [winfo ismapped .pack.b]
    pack .pack.a -before .pack.b -side top
    update
    lappend result [winfo geometry .pack.b] [winfo ismapped .pack.b]
} -cleanup {
    destroy .pack.f1 .pack.f2
} -result {50x16+25+22 1 50x16+25+22 0}


test pack-16.1 {geometry manager name} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
    set result {}
} -body {
    lappend result [winfo manager .pack.a]
    pack .pack.a
    lappend result [winfo manager .pack.a]
    pack forget .pack.a
    lappend result [winfo manager .pack.a]
} -result {{} pack {}}


test pack-17.1 {PackLostContentProc procedure} -setup {
test pack-17.1 {PackLostSlaveProc procedure} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a
    update
    place .pack.a -x 40 -y 10
    update
    list [winfo manager .pack.a] [winfo geometry .pack.a]
} -result {place 20x40+40+10}
test pack-17.2 {PackLostContentProc procedure} -setup {
test pack-17.2 {PackLostSlaveProc procedure} -setup {
    pack forget .pack.a .pack.b .pack.c .pack.d
} -body {
    pack .pack.a
    update
    place .pack.a -x 40 -y 10
    update
    winfo manager .pack.a
    winfo geometry .pack.a
    pack info .pack.a
} -returnCodes error -result {window ".pack.a" isn't packed}

# Tests pack-18.1.1 and pack-18.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuarz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).

# Tests pack-18.1.* are constrained because on Windows, when the width/height
# is configured while the window is unmapped, the changes don't take
# effect until the window is remapped. This is apparently by design of the
# OS, and Tk accommodates this behavior (see UpdateGeometryInfo() and
# ConfigureTopLevel() in tkWinWm.c).
# pack-18.1.1 checks that, on Linux or macOS, width/height changes are taken
# into account while the window is unmapped.
# pack-18.1.2 checks that, on Windows, width/height changes are taken into
# account on window remapping.
test pack-18.1.1 {unmap content when container unmapped} -constraints {
test pack-18.1 {unmap slaves when master unmapped} -constraints {
    macOrUnix failsOnUbuntu failsOnXQuarz
    tempNotPc
} -setup {
    destroy {*}[winfo children .pack]
    eval destroy [winfo child .pack]
} -body {

    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).

    wm geometry .pack +100+100
} -body {

    # On the PC, when the width/height is configured while the window is
    # unmapped, the changes don't take effect until the window is remapped.
    # Who knows why?

    eval destroy [winfo child .pack]
    frame .pack.a -width 100 -height 50 -relief raised -bd 2
    pack .pack.a
    update
    set result [winfo ismapped .pack.a]
    wm iconify .pack
    update
    lappend result [winfo ismapped .pack.a]
    .pack.a configure -width 200 -height 75
    update
    lappend result [winfo width .pack.a] [winfo height .pack.a] \
            [winfo ismapped .pack.a]
    lappend result [winfo width .pack.a ] [winfo height .pack.a] \
    [winfo ismapped .pack.a]
    wm deiconify .pack
    update
    lappend result [winfo ismapped .pack.a]
} -result {1 0 200 75 0 1}
test pack-18.1.2 {unmap content when container unmapped} -constraints {
    win
} -setup {
    destroy {*}[winfo children .pack]
test pack-18.2 {unmap slaves when master unmapped} -setup {
    eval destroy [winfo child .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).
    wm geometry .pack +100+100
} -body {
    frame .pack.a -width 100 -height 50 -relief raised -bd 2
    pack .pack.a
    update
    set result [winfo ismapped .pack.a]
    wm iconify .pack
    lappend result [winfo ismapped .pack.a]
    .pack.a configure -width 200 -height 75
    update
    wm deiconify .pack
    update
    lappend result [winfo width .pack.a] [winfo height .pack.a]
    lappend result [winfo ismapped .pack.a]
} -result {1 0 200 75 1}

test pack-18.2 {unmap content when container unmapped} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
    destroy {*}[winfo children .pack]
    # adjust the position of .pack before test to avoid a screen switch
    # that occurs with window managers that have desktops four times as big
    # as the screen (screen switch causes scale and other tests to fail).

    wm geometry .pack +100+100
} -body {
    frame .pack.a -relief raised -bd 2
    frame .pack.b -width 70 -height 30 -relief sunken -bd 2
    pack .pack.a
    pack .pack.b -in .pack.a
    update
    set result [winfo ismapped .pack.b]
    wm iconify .pack
    update
    lappend result [winfo ismapped .pack.b]
    .pack.b configure -width 100 -height 30
    update
    lappend result [winfo width .pack.b] [winfo height .pack.b] \
            [winfo ismapped .pack.b]
    lappend result [winfo width .pack.b ] [winfo height .pack.b] \
    [winfo ismapped .pack.b]
    wm deiconify .pack
    update
    lappend result [winfo ismapped .pack.b]
} -result {1 0 100 30 0 1}


test pack-19.1 {test respect for internalborder} -setup {
    catch {pack forget {*}[pack content .pack]}
    catch {eval pack forget [pack slaves .pack]}
    destroy .pack.l .pack.lf
} -body {
    wm geometry .pack 200x200
    frame .pack.l -width 15 -height 10
    labelframe .pack.lf -labelwidget .pack.l
    pack .pack.lf -fill both -expand 1
    frame .pack.lf.f
    pack .pack.lf.f -fill both -expand 1
    update
    set res [list [winfo geometry .pack.lf.f]]
    .pack.lf configure -labelanchor e -padx 3 -pady 5
    update
    lappend res [winfo geometry .pack.lf.f]
} -cleanup {
    destroy .pack.l .pack.lf
} -result {196x188+2+10 177x186+5+7}
test pack-19.2 {test support for minreqsize} -setup {
    catch {pack forget {*}[pack content .pack]}
    catch {eval pack forget [pack slaves .pack]}
    destroy .pack.l .pack.lf
} -body {
    wm geometry .pack {}
    frame .pack.l -width 150 -height 100
    labelframe .pack.lf -labelwidget .pack.l
    pack .pack.lf -fill both -expand 1
    frame .pack.lf.f -width 20 -height 25
    pack .pack.lf.f
    update
    set res [list [winfo geometry .pack.lf]]
    .pack.lf configure -labelanchor ws
    update
    lappend res [winfo geometry .pack.lf]
} -cleanup {
    destroy .pack.l .pack.lf
} -result {162x127+0+0 172x112+0+0}

test pack-20.1 {<<NoManagedChild>> fires on last pack forget} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    update
    bind . <<NoManagedChild>> {set A 1}
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1
} -result 1
test pack-20.2 {<<NoManagedChild>> fires on last packed child destruction} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    update
    bind . <<NoManagedChild>> {incr A}
    destroy .1
    update
    set A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1
} -result 1
test pack-20.3 {<Configure> does not fire on last pack forget} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    update
    bind . <Configure> {set A 1}
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <Configure> {}
    destroy .1
} -result 0
test pack-20.4 {<<NoManagedChild>> does not fire on forelast pack forget} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    pack [frame .2]
    update
    bind . <<NoManagedChild>> {set A 1}
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1 .2
} -result 0
test pack-20.5 {<Configure> does not fire on last pack forget} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    pack [frame .2]
    update
    bind . <Configure> {set A 1}
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <Configure> {}
    destroy .1 .2
} -result 1
test pack-20.6 {<<NoManagedChild>> does not fire on last pack forget if propagation is off} -setup {
    global A
    unset -nocomplain A
} -body {
    pack [frame .1]
    pack propagate . 0
    update
    bind . <<NoManagedChild>> {set A 1}
    pack forget .1
    update
    info exists A
} -cleanup {
    bind . <<NoManagedChild>> {}
    destroy .1
} -result 0


# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl


# End:

Changes to tests/packgrid.test.

1
2
3
4
5

6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25

26
27

28
29
30
31
32
33
34
35
36
37
38
39

40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106

107
108
109
110
111
112

113
114
115
116
117
118
119
120
121

122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140

141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191

192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232

233
234

235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
1
2
3
4

5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24

25
26

27
28
29
30
31
32
33
34
35
36
37
38

39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105

106
107
108
109
110
111

112
113
114
115
116
117
118
119
120

121
122
123
124
125
126

127
128
129
130
131
132
133
134
135
136
137
138
139

140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231

232
233

234
235
236
237
238
239
240
241
242
243
244
245
246

247
248






























249
250




-
+







-
+











-
+

-
+











-
+

-
+













-
+













-
+













-
+













-
+








-
+





-
+








-
+





-
+












-
+

-
+













-
+

-
+














-
+

-
+













-
+

-
+













-
+













-
+












-
+

-
+












-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


# This file is a Tcl script to test out interaction between Tk's "pack" and
# "grid" commands.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 2008 Peter Spjuth
# Copyright (c) 2008 Peter Spjuth
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::*

test packgrid-1.1 {pack and grid in same container window} -setup {
test packgrid-1.1 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Basic conflict
    grid .g
    pack .p
} -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager pack inside . because grid is already managing it's content windows}
} -result {cannot use geometry manager pack inside . which already has slaves managed by grid}

test packgrid-1.2 {pack and grid in same container window} -setup {
test packgrid-1.2 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Basic conflict
    pack .p
    grid .g
} -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager grid inside . because pack is already managing it's content windows}
} -result {cannot use geometry manager grid inside . which already has slaves managed by pack}

test packgrid-1.3 {pack and grid in same container window} -setup {
test packgrid-1.3 {pack and grid in same master} -setup {
    grid propagate . false
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok if one is non-propagating
    grid .g
    pack .p
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-1.4 {pack and grid in same container window} -setup {
test packgrid-1.4 {pack and grid in same master} -setup {
    grid propagate . false
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok if one is non-propagating
    pack .p
    grid .g
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-1.5 {pack and grid in same container window} -setup {
test packgrid-1.5 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . false
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok if one is non-propagating
    grid .g
    pack .p
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-1.6 {pack and grid in same container window} -setup {
test packgrid-1.6 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . false
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok if one is non-propagating
    pack .p
    grid .g
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-1.7 {pack and grid in same container window} -setup {
test packgrid-1.7 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Basic conflict should stop widget from being handled
    grid .g
    catch { pack .p }
    pack content .
    pack slaves .
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-1.8 {pack and grid in same container window} -setup {
test packgrid-1.8 {pack and grid in same master} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Basic conflict should stop widget from being handled
    pack .p
    catch { grid .g }
    grid content .
    grid slaves .
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-2.1 {pack and grid in same container window, change propagation} -setup {
test packgrid-2.1 {pack and grid in same master, change propagation} -setup {
    grid propagate . false
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
    pack .p
    grid .g
    update
} -body {
    grid propagate . true
} -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager grid inside . because pack is already managing it's content windows}
} -result {cannot use geometry manager grid inside . which already has slaves managed by pack}

test packgrid-2.2 {pack and grid in same container window, change propagation} -setup {
test packgrid-2.2 {pack and grid in same master, change propagation} -setup {
    grid propagate . true
    pack propagate . false
    label .p -text PACK
    label .g -text GRID
    pack .p
    grid .g
    update
} -body {
    pack propagate . true
} -returnCodes error -cleanup {
    destroy .p
    update
    destroy .g
} -result {cannot use geometry manager pack inside . because grid is already managing it's content windows}
} -result {cannot use geometry manager pack inside . which already has slaves managed by grid}

test packgrid-2.3 {pack and grid in same container window, change propagation} -setup {
test packgrid-2.3 {pack and grid in same master, change propagation} -setup {
    grid propagate . false
    pack propagate . false
    label .p -text PACK
    label .g -text GRID
    pack .p
    grid .g
    update
} -body {
    grid propagate . true
    update
    pack propagate . true
} -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager pack inside . because grid is already managing it's content windows}
} -result {cannot use geometry manager pack inside . which already has slaves managed by grid}

test packgrid-2.4 {pack and grid in same container window, change propagation} -setup {
test packgrid-2.4 {pack and grid in same master, change propagation} -setup {
    grid propagate . false
    pack propagate . false
    label .p -text PACK
    label .g -text GRID
    pack .p
    grid .g
    update
} -body {
    pack propagate . true
    grid propagate . true
} -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager grid inside . because pack is already managing it's content windows}
} -result {cannot use geometry manager grid inside . which already has slaves managed by pack}

test packgrid-3.1 {stealing content} -setup {
test packgrid-3.1 {stealing slave} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok to steal if the other one is emptied
    grid .g
    pack .g
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-3.2 {stealing content} -setup {
test packgrid-3.2 {stealing slave} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Ok to steal if the other one is emptied
    pack .g
    grid .g
} -cleanup {
    destroy .p
    destroy .g
} -result {}

test packgrid-3.3 {stealing content} -setup {
test packgrid-3.3 {stealing slave} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Not ok to steal if the other one is not emptied
    grid .g
    grid .p
    pack .g
}  -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager pack inside . because grid is already managing it's content windows}
} -result {cannot use geometry manager pack inside . which already has slaves managed by grid}

test packgrid-3.4 {stealing content} -setup {
test packgrid-3.4 {stealing slave} -setup {
    grid propagate . true
    pack propagate . true
    label .p -text PACK
    label .g -text GRID
} -body {
    # Not ok to steal if the other one is not emptied
    pack .g
    pack .p
    grid .g
}  -returnCodes error -cleanup {
    destroy .p
    destroy .g
} -result {cannot use geometry manager grid inside . because pack is already managing it's content windows}
} -result {cannot use geometry manager grid inside . which already has slaves managed by pack}

test packgrid-4.1 {content stolen after container destruction - bug [aa7679685e]} -setup {
    frame .f
    button .b -text hello
} -body {
    pack .f
    grid .b -in .f
    destroy .f
    set res [winfo manager .b]
    # shall not crash
    pack .b
    set res
} -cleanup {
    destroy .b
} -result {}

test packgrid-4.2 {content stolen after container destruction - bug [aa7679685e]} -setup {
    frame .f
    button .b -text hello
} -body {
    pack .f
    pack .b -in .f
    destroy .f
    set res [winfo manager .b]
    # shall not crash
    grid .b
    set res
} -cleanup {
    destroy .b
} -result {}

cleanupTests
return

Changes to tests/panedwindow.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test entry widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89







-
+

















-
+

















-
+








-
+







    .p configure -bd 4
    list [lindex [.p configure -bd] 4] [.p cget -bd]
} -cleanup {
    .p configure -bd [lindex [.p configure -bd] 3]
} -result {4 4}
test panedwindow-1.4 {configuration options: -bd (bad)} -body {
    .p configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.5 {configuration options: -bg (good)} -body {
    .p configure -bg #ff0000
    list [lindex [.p configure -bg] 4] [.p cget -bg]
} -cleanup {
    .p configure -bg [lindex [.p configure -bg] 3]
} -result {{#ff0000} #ff0000}
test panedwindow-1.6 {configuration options: -bg (bad)} -body {
    .p configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test panedwindow-1.7 {configuration options: -borderwidth (good)} -body {
    .p configure -borderwidth 1.3
    list [lindex [.p configure -borderwidth] 4] [.p cget -borderwidth]
} -cleanup {
    .p configure -borderwidth [lindex [.p configure -borderwidth] 3]
} -result {1 1}
test panedwindow-1.8 {configuration options: -borderwidth (bad)} -body {
    .p configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.9 {configuration options: -cursor (good)} -body {
    .p configure -cursor arrow
    list [lindex [.p configure -cursor] 4] [.p cget -cursor]
} -cleanup {
    .p configure -cursor [lindex [.p configure -cursor] 3]
} -result {arrow arrow}
test panedwindow-1.10 {configuration options: -cursor (bad)} -body {
    .p configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test panedwindow-1.11 {configuration options: -handlesize (good)} -body {
    .p configure -handlesize 20
    list [lindex [.p configure -handlesize] 4] [.p cget -handlesize]
} -cleanup {
    .p configure -handlesize [lindex [.p configure -handlesize] 3]
} -result {20 20}
test panedwindow-1.12 {configuration options: -handlesize (bad)} -body {
    .p configure -handlesize badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.13 {configuration options: -height (good)} -body {
    .p configure -height 20
    list [lindex [.p configure -height] 4] [.p cget -height]
} -cleanup {
    .p configure -height [lindex [.p configure -height] 3]
} -result {20 20}
test panedwindow-1.14 {configuration options: -height (bad)} -body {
    .p configure -height badValue
} -returnCodes error -result {expected screen distance or "" but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.15 {configuration options: -opaqueresize (good)} -body {
    .p configure -opaqueresize true
    list [lindex [.p configure -opaqueresize] 4] [.p cget -opaqueresize]
} -cleanup {
    .p configure -opaqueresize [lindex [.p configure -opaqueresize] 3]
} -result {1 1}
test panedwindow-1.16 {configuration options: -opaqueresize (bad)} -body {
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134







-
+








-
+







    .p configure -proxyborderwidth 1.3
    list [lindex [.p configure -proxyborderwidth] 4] [.p cget -proxyborderwidth]
} -cleanup {
    .p configure -proxyborderwidth [lindex [.p configure -proxyborderwidth] 3]
} -result {1.3 1.3}
test panedwindow-1.22 {configuration options: -proxyborderwidth (bad)} -body {
    .p configure -proxyborderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.23 {configuration options: -proxyrelief (good)} -body {
    .p configure -proxyrelief groove
    list [lindex [.p configure -proxyrelief] 4] [.p cget -proxyrelief]
} -cleanup {
    .p configure -proxyrelief [lindex [.p configure -proxyrelief] 3]
} -result {groove groove}
test panedwindow-1.24 {configuration options: -proxyrelief (bad)} -body {
    .p configure -proxyrelief 1.5
} -returnCodes error -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes error -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
test panedwindow-1.25 {configuration options: -relief (good)} -body {
    .p configure -relief groove
    list [lindex [.p configure -relief] 4] [.p cget -relief]
} -cleanup {
    .p configure -relief [lindex [.p configure -relief] 3]
} -result {groove groove}
test panedwindow-1.26 {configuration options: -relief (bad)} -body {
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+

















-
+

















-
+







    .p configure -sashpad 1.3
    list [lindex [.p configure -sashpad] 4] [.p cget -sashpad]
} -cleanup {
    .p configure -sashpad [lindex [.p configure -sashpad] 3]
} -result {1 1}
test panedwindow-1.30 {configuration options: -sashpad (bad)} -body {
    .p configure -sashpad badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.31 {configuration options: -sashrelief (good)} -body {
    .p configure -sashrelief groove
    list [lindex [.p configure -sashrelief] 4] [.p cget -sashrelief]
} -cleanup {
    .p configure -sashrelief [lindex [.p configure -sashrelief] 3]
} -result {groove groove}
test panedwindow-1.32 {configuration options: -sashrelief (bad)} -body {
    .p configure -sashrelief 1.5
} -returnCodes error -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
test panedwindow-1.33 {configuration options: -sashwidth (good)} -body {
    .p configure -sashwidth 10
    list [lindex [.p configure -sashwidth] 4] [.p cget -sashwidth]
} -cleanup {
    .p configure -sashwidth [lindex [.p configure -sashwidth] 3]
} -result {10 10}
test panedwindow-1.34 {configuration options: -sashwidth (bad)} -body {
    .p configure -sashwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.35 {configuration options: -showhandle (good)} -body {
    .p configure -showhandle true
    list [lindex [.p configure -showhandle] 4] [.p cget -showhandle]
} -cleanup {
    .p configure -showhandle [lindex [.p configure -showhandle] 3]
} -result {1 1}
test panedwindow-1.36 {configuration options: -showhandle (bad)} -body {
    .p configure -showhandle foo
} -returnCodes error -result {expected boolean value but got "foo"}
test panedwindow-1.37 {configuration options: -width (good)} -body {
    .p configure -width 402
    list [lindex [.p configure -width] 4] [.p cget -width]
} -cleanup {
    .p configure -width [lindex [.p configure -width] 3]
} -result {402 402}
test panedwindow-1.38 {configuration options: -width (bad)} -body {
    .p configure -width badValue
} -returnCodes error -result {expected screen distance or "" but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}

test panedwindow-1.39 {configuration options: -after (good)} -body {
    .p paneconfigure .b -after .c
    list [lindex [.p paneconfigure .b -after] 4] \
        [.p panecget .b -after]
} -cleanup {
    .p paneconfig .b -after [lindex [.p paneconfig .b -after] 3]
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268







-
+



















-
+









-
+









-
+







    list [lindex [.p paneconfigure .b -height] 4] \
        [.p panecget .b -height]
} -cleanup {
    .p paneconfig .b -height [lindex [.p paneconfig .b -height] 3]
} -result {10 10}
test panedwindow-1.44 {configuration options: -height (bad)} -body {
    .p paneconfigure .b -height badValue
} -returnCodes error -result {expected screen distance or "" but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.45 {configuration options: -hide (good)} -body {
    .p paneconfigure .b -hide false
    list [lindex [.p paneconfigure .b -hide] 4] \
        [.p panecget .b -hide]
} -cleanup {
    .p paneconfig .b -hide [lindex [.p paneconfig .b -hide] 3]
} -result {0 0}
test panedwindow-1.46 {configuration options: -hide (bad)} -body {
    .p paneconfigure .b -hide foo
} -returnCodes error -result {expected boolean value but got "foo"}
test panedwindow-1.47 {configuration options: -minsize (good)} -body {
    .p paneconfigure .b -minsize 10
    list [lindex [.p paneconfigure .b -minsize] 4] \
        [.p panecget .b -minsize]
} -cleanup {
    .p paneconfig .b -minsize [lindex [.p paneconfig .b -minsize] 3]
} -result {10 10}
test panedwindow-1.48 {configuration options: -minsize (bad)} -body {
    .p paneconfigure .b -minsize badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.49 {configuration options: -padx (good)} -body {
    .p paneconfigure .b -padx 1.3
    list [lindex [.p paneconfigure .b -padx] 4] \
        [.p panecget .b -padx]
} -cleanup {
    .p paneconfig .b -padx [lindex [.p paneconfig .b -padx] 3]
} -result {1 1}
test panedwindow-1.50 {configuration options: -padx (bad)} -body {
    .p paneconfigure .b -padx badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.51 {configuration options: -pady (good)} -body {
    .p paneconfigure .b -pady 1.3
    list [lindex [.p paneconfigure .b -pady] 4] \
        [.p panecget .b -pady]
} -cleanup {
    .p paneconfig .b -pady [lindex [.p paneconfig .b -pady] 3]
} -result {1 1}
test panedwindow-1.52 {configuration options: -pady (bad)} -body {
    .p paneconfigure .b -pady badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test panedwindow-1.53 {configuration options: -sticky (good)} -body {
    .p paneconfigure .b -sticky nsew
    list [lindex [.p paneconfigure .b -sticky] 4] \
        [.p panecget .b -sticky]
} -cleanup {
    .p paneconfig .b -sticky [lindex [.p paneconfig .b -sticky] 3]
} -result {nesw nesw}
284
285
286
287
288
289
290
291

292
293
294
295
296

297
298
299
300
301

302
303
304
305
306

307
308
309
310
311
312
313
314
315

316
317
318
319
320

321
322
323
324
325

326
327
328

329
330
331
332
333
334
335
336
337

338
339
340

341
342
343
344
345
346
347
348
349
350
351

352
353
354

355
356
357
358
359
360
361
362
363
364
365

366
367
368

369
370
371
372
373
374
375
376
377
378
379
380

381
382
383

384
385
386
387
388
389
390
391

392
393
394
395
396

397
398
399
400
401

402
403
404

405
406
407
408
409

410
411
412
413
414

415
416
417
418
419

420
421
422

423
424
425
426
427

428
429
430

431
432
433
434
435

436
437
438

439
440
441
442
443


444
445
446

447
448
449

450
451
452
453
454


455
456
457

458
459
460

461
462
463
464
465
466


467
468
469

470
471
472

473
474
475
476
477
478


479
480
481

482
483
484

485
486
487
488
489
490
491

492
493
494

495
496
497
498
499
500
501


502
503

504
505
506

507
508
509
510
511
512
513
514



515
516

517
518
519
520
521

522
523
524
525
526

527
528
529

530
531
532
533
534

535
536
537

538
539
540
541
542

543
544
545

546
547
548
549
550
551

552
553
554

555
556
557
558
559
560

561
562
563

564
565
566
567
568
569

570
571
572

573
574
575
576
577
578
579

580
581
582
583
584

585
586
587
588
589

590
591
592

593
594
595
596
597

598
599
600

601
602
603
604
605

606
607
608

609
610
611
612
613
614

615
616
617

618
619
620
621
622
623

624
625
626
627
628

629
630
631
632
633
634
635
636

637
638
639

640
641
642
643
644
645
646
647
648

649
650
651

652
653
654
655
656
657
658
659

660
661
662
663
664

665
666
667
668
669

670
671
672

673
674
675
676
677

678
679
680

681
682
683
684
685

686
687
688

689
690
691
692
693
694

695
696
697

698
699
700
701
702
703

704
705
706

707
708
709
710
711
712
713

714
715
716

717
718
719
720
721
722
723

724
725
726

727
728
729
730
731
732
733

734
735
736

737
738
739
740
741
742

743
744
745
746
747

748
749
750
751
752
753
754
755
756
757

758
759
760
761
762
763
764
765
766
767
768

769
770
771

772
773
774
775
776
777
778
779

780
781
782
783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799
800
801
802
803
804

805
806
807

808
809
810
811
812
813
814
815
816
817

818
819
820

821
822
823
824
825
826
827
828
829

830
831
832

833
834
835
836
837
838
839
840
841
842

843
844
845
846
847
848
849
850
851
852
853

854
855
856
857
858
859
860
861

862
863
864

865
866
867
868

869
870
871
872

873
874
875

876
877
878
879

880
881
882
883

884
885
886

887
888
889
890

891
892
893
894
895
896
897

898
899
900

901
902
903
904

905
906
907
908
909
910
911

912
913
914

915
916
917
918

919
920
921
922
923
924
925
926

927
928
929
930
931

932
933
934
935
936
937
938
939
940
941

942
943
944

945
946
947
948
949
950
951
952
953
954
955

956
957
958

959
960
961
962
963


964
965
966
967
968
969
970
971
972
973
974
975

976
977
978

979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995

996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009

1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026


1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037


1038
1039
1040
1041
1042
1043
1044
1045
1046

1047
1048
1049

1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060

1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088

1089
1090
1091


1092
1093
1094
1095
1096
1097
1098
1099
1100

1101
1102
1103


1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116

1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133

1134
1135
1136

1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148


1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
284
285
286
287
288
289
290

291
292
293
294
295

296
297
298
299
300

301
302
303
304
305

306
307
308
309
310
311
312
313
314

315
316
317
318
319

320
321
322
323
324

325
326
327

328
329
330
331
332
333
334
335
336

337
338
339

340
341
342
343
344
345
346
347
348
349
350

351
352
353

354
355
356
357
358
359
360
361
362
363
364

365
366
367

368
369
370
371
372
373
374
375
376
377
378
379

380
381
382

383
384
385
386
387
388
389
390

391
392
393
394
395

396
397
398
399
400

401
402
403

404
405
406
407
408

409
410
411
412
413

414
415
416
417
418

419
420
421

422
423
424
425
426

427
428
429

430
431
432
433
434

435
436
437

438
439
440
441


442
443
444
445

446
447
448

449
450
451
452


453
454
455
456

457
458
459

460
461
462
463
464


465
466
467
468

469
470
471

472
473
474
475
476


477
478
479
480

481
482
483

484
485
486
487
488
489
490

491
492
493

494
495
496
497
498
499


500
501
502

503
504
505

506
507
508
509
510
511



512
513
514
515

516
517
518
519
520

521
522
523
524
525

526
527
528

529
530
531
532
533

534
535
536

537
538
539
540
541

542
543
544

545
546
547
548
549
550

551
552
553

554
555
556
557
558
559

560
561
562

563
564
565
566
567
568

569
570
571

572
573
574
575
576
577
578

579
580
581
582
583

584
585
586
587
588

589
590
591

592
593
594
595
596

597
598
599

600
601
602
603
604

605
606
607

608
609
610
611
612
613

614
615
616

617
618
619
620
621
622

623
624
625
626
627

628
629
630
631
632
633
634
635

636
637
638

639
640
641
642
643
644
645
646
647

648
649
650

651
652
653
654
655
656
657
658

659
660
661
662
663

664
665
666
667
668

669
670
671

672
673
674
675
676

677
678
679

680
681
682
683
684

685
686
687

688
689
690
691
692
693

694
695
696

697
698
699
700
701
702

703
704
705

706
707
708
709
710
711
712

713
714
715

716
717
718
719
720
721
722

723
724
725

726
727
728
729
730
731
732

733
734
735

736
737
738
739
740
741

742
743
744
745
746

747
748
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767

768
769
770

771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798
799
800
801
802
803

804
805
806

807
808
809
810
811
812
813
814
815
816

817
818
819

820
821
822
823
824
825
826
827
828

829
830
831

832
833
834
835
836
837
838
839
840
841

842
843
844
845
846
847
848
849
850
851
852

853
854
855
856
857
858
859
860

861
862
863

864
865
866
867

868
869
870
871

872
873
874

875
876
877
878

879
880
881
882

883
884
885

886
887
888
889

890
891
892
893
894
895
896

897
898
899

900
901
902
903

904
905
906
907
908
909
910

911
912
913

914
915
916
917

918
919
920
921
922
923
924
925

926
927
928
929
930

931
932
933
934
935
936
937
938
939
940

941
942
943

944
945
946
947
948
949
950
951
952
953
954

955
956
957

958
959
960
961


962
963
964
965
966
967
968
969
970
971
972
973
974

975
976
977

978
979
980
981
982

983
984
985
986
987
988
989
990
991
992
993
994

995
996
997

998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022

1023
1024


1025
1026
1027
1028
1029
1030
1031
1032
1033

1034
1035


1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087

1088
1089


1090
1091
1092
1093
1094
1095
1096
1097
1098
1099

1100
1101


1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112

1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

1128
1129
1130
1131
1132

1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146


1147
1148
1149
1150

1151
1152
1153
1154
1155
1156
1157
1158







-
+




-
+




-
+




-
+








-
+




-
+




-
+


-
+








-
+


-
+










-
+


-
+










-
+


-
+











-
+


-
+







-
+




-
+




-
+


-
+




-
+




-
+




-
+


-
+




-
+


-
+




-
+


-
+



-
-
+
+


-
+


-
+



-
-
+
+


-
+


-
+




-
-
+
+


-
+


-
+




-
-
+
+


-
+


-
+






-
+


-
+





-
-
+
+

-
+


-
+





-
-
-
+
+
+

-
+




-
+




-
+


-
+




-
+


-
+




-
+


-
+





-
+


-
+





-
+


-
+





-
+


-
+






-
+




-
+




-
+


-
+




-
+


-
+




-
+


-
+





-
+


-
+





-
+




-
+







-
+


-
+








-
+


-
+







-
+




-
+




-
+


-
+




-
+


-
+




-
+


-
+





-
+


-
+





-
+


-
+






-
+


-
+






-
+


-
+






-
+


-
+





-
+




-
+









-
+










-
+


-
+







-
+











-
+












-
+


-
+









-
+


-
+








-
+


-
+









-
+










-
+







-
+


-
+



-
+



-
+


-
+



-
+



-
+


-
+



-
+






-
+


-
+



-
+






-
+


-
+



-
+







-
+




-
+









-
+


-
+










-
+


-
+



-
-
+
+











-
+


-
+




-
+











-
+


-
+










-
+


-
+










-
+

-
-
+
+







-
+

-
-
+
+








-
+


-
+










-
+


-
+










-
+


-
+










-
+

-
-
+
+








-
+

-
-
+
+









-
+


-
+











-
+




-
+


-
+










-
-
+
+


-
+







    list [lindex [.p paneconfigure .b -width] 4] \
        [.p panecget .b -width]
} -cleanup {
    .p paneconfig .b -width [lindex [.p paneconfig .b -width] 3]
} -result {10 10}
test panedwindow-1.58 {configuration options: -width (bad)} -body {
    .p paneconfigure .b -width badValue
} -returnCodes error -result {expected screen distance or "" but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
deleteWindows


test panedwindow-2.1 {panedwindow widget command} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p foo
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {bad command "foo": must be add, cget, configure, forget, identify, panecget, paneconfigure, panes, proxy, or sash}


test panedwindow-3.1 {panedwindow panes subcommand} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    set result [list [.p panes]]
    .p forget .b
    lappend result [.p panes]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list .b .c] [list .c]]


test panedwindow-4.1 {forget subcommand} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p forget
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p forget widget ?widget ...?"}
test panedwindow-4.2 {forget subcommand, forget one from start} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    set result [list [.p panes]]
    .p forget .b
    lappend result [.p panes]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list {.b .c} .c]
test panedwindow-4.3 {forget subcommand, forget one from end} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    .p add [button .d]
    set result [list [.p panes]]
    .p forget .d
    update
    lappend result [.p panes]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list {.b .c .d} {.b .c}]
test panedwindow-4.4 {forget subcommand, forget multiple} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    .p add [button .d]
    set result [list [.p panes]]
    .p forget .b .c
    update
    lappend result [.p panes]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list {.b .c .d} .d]
test panedwindow-4.5 {forget subcommand, panes are unmapped} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    pack .p
    update
    set result [list [winfo ismapped .b] [winfo ismapped .c]]
    .p forget .b
    update
    lappend result [winfo ismapped .b] [winfo ismapped .c]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 1 1 0 1]
test panedwindow-4.6 {forget subcommand, changes reqsize of panedwindow} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -showhandle false
    .p add [frame .f -width 20 -height 20] [frame .g -width 20 -height 20]
    set result [list [winfo reqwidth .p]]
    .p forget .f
    lappend result [winfo reqwidth .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 44 20]


test panedwindow-5.1 {sash subcommand} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p sash option ?arg ...?"}
test panedwindow-5.2 {sash subcommand} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash foo
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {bad option "foo": must be coord, dragto, mark, or place}


test panedwindow-6.1 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash coord
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p sash coord index"}
test panedwindow-6.2 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {invalid sash index}
test panedwindow-6.3 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash coord foo
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-6.4 {sash coord subcommand sashes correctly placed} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 2 -sashwidth 4 -showhandle false
    .p add [frame .p.f -width 20 -height 20] \
            [frame .p.f2 -width 20 -height 20] \
            [frame .p.f3 -width 20 -height 20]
	    [frame .p.f2 -width 20 -height 20] \
	    [frame .p.f3 -width 20 -height 20]
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 22 0]
test panedwindow-6.5 {sash coord subcommand sashes correctly placed} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 2 -sashwidth 4 -showhandle false
    .p add [frame .p.f -width 20 -height 20] \
            [frame .p.f2 -width 20 -height 20] \
            [frame .p.f3 -width 20 -height 20]
	    [frame .p.f2 -width 20 -height 20] \
	    [frame .p.f3 -width 20 -height 20]
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 50 0]
test panedwindow-6.6 {sash coord subcommand, sashes correctly placed} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 2 -sashwidth 4 -orient vertical \
            -showhandle false
    .p add [frame .p.f -width 20 -height 20] \
            [frame .p.f2 -width 20 -height 20] \
            [frame .p.f3 -width 20 -height 20]
	    [frame .p.f2 -width 20 -height 20] \
	    [frame .p.f3 -width 20 -height 20]
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 22]
test panedwindow-6.7 {sash coord subcommand, sashes correctly placed} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 2 -sashwidth 4 -orient vertical \
            -showhandle false
    .p add [frame .p.f -width 20 -height 20] \
            [frame .p.f2 -width 20 -height 20] \
            [frame .p.f3 -width 20 -height 20]
	    [frame .p.f2 -width 20 -height 20] \
	    [frame .p.f3 -width 20 -height 20]
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 50]
test panedwindow-6.8 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    list [catch {.p sash coord -1} msg] $msg \
        [catch {.p sash coord  0} msg] $msg \
        [catch {.p sash coord  1} msg] $msg
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 1 "invalid sash index" 1 "invalid sash index" 1 "invalid sash index"]
test panedwindow-6.9 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    # There are no sashes until you have 2 panes
    panedwindow .p
    .p add [frame .p.f]
    list [catch {.p sash coord -1} msg] $msg \
            [catch {.p sash coord  0} msg] $msg \
            [catch {.p sash coord  1} msg] $msg
	    [catch {.p sash coord  0} msg] $msg \
	    [catch {.p sash coord  1} msg] $msg
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 1 "invalid sash index" 1 "invalid sash index" 1 "invalid sash index"]
test panedwindow-6.10 {sash coord subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    # There are no sashes until you have 2 panes
    panedwindow .p
    .p add [frame .p.f] [frame .p.f2]
    list [catch {.p sash coord -1} msg] $msg \
            [catch {.p sash coord  0} msg] \
            [catch {.p sash coord  1} msg] $msg \
            [catch {.p sash coord  2} msg] $msg
	    [catch {.p sash coord  0} msg] \
	    [catch {.p sash coord  1} msg] $msg \
	    [catch {.p sash coord  2} msg] $msg
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 1 "invalid sash index" 0 1 "invalid sash index" 1 "invalid sash index"]


test panedwindow-7.1 {sash mark subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash mark
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p sash mark index ?x y?"}
test panedwindow-7.2 {sash mark subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash mark foo
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-7.3 {sash mark subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash mark 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {invalid sash index}
test panedwindow-7.4 {sash mark subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash mark 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-7.5 {sash mark subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash mark 0 0 bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "bar"}
test panedwindow-7.6 {sash mark subcommand, mark defaults to 0 0} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash mark 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 0]
test panedwindow-7.7 {sash mark subcommand, set mark} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash mark 0 10 10
    .p sash mark 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 10]


test panedwindow-8.1 {sash dragto subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash dragto
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p sash dragto index x y"}
test panedwindow-8.2 {sash dragto subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash dragto foo bar baz
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-8.3 {sash dragto subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash dragto 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {invalid sash index}
test panedwindow-8.4 {sash dragto subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash dragto 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-8.5 {sash dragto subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash dragto 0 0 bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "bar"}


test panedwindow-9.1 {sash mark/sash dragto interaction} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -showhandle false
    .p add [frame .f -width 20 -height 20] [button .c -text foobar]
    .p sash mark 0 10 10
    .p sash dragto 0 20 10
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 30 0]
test panedwindow-9.2 {sash mark/sash dragto interaction} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -orient vertical \
            -showhandle false
    .p add [frame .p.f -width 20 -height 20] [button .p.c -text foobar]
    .p sash mark 0 10 10
    .p sash dragto 0 10 20
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 30]
test panedwindow-9.3 {sash mark/sash dragto, respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -showhandle false
    .p add [frame .f -width 20 -height 20] [button .c] -minsize 15
    .p sash mark 0 20 10
    .p sash dragto 0 10 10
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 15 0]


test panedwindow-10.1 {sash place subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash place
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p sash place index x y"}
test panedwindow-10.2 {sash place subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash place foo bar baz
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-10.3 {sash place subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p sash place 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {invalid sash index}
test panedwindow-10.4 {sash place subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash place 0 foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-10.5 {sash place subcommand, errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p sash place 0 0 bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "bar"}
test panedwindow-10.6 {sash place subcommand, moves sash} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 20] [button .c]
    .p sash place 0 10 0
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 0]
test panedwindow-10.7 {sash place subcommand, moves sash} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -orient vertical
    .p add [frame .f -width 20 -height 20] [button .c]
    .p sash place 0 0 10
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 10]
test panedwindow-10.8 {sash place subcommand, respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -showhandle false
    .p add [frame .f -width 20 -height 20] [button .c] -minsize 15
    .p sash place 0 10 0
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 15 0]
test panedwindow-10.9 {sash place subcommand, respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [frame .f -width 20 -height 20 -bg pink]
    .p sash place 0 2 0
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {invalid sash index}


test panedwindow-11.1 {moving sash changes size of pane to left} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 4 -showhandle false
    .p add [frame .f -width 20 -height 20] [button .c -text foobar] -sticky nsew
    .p sash place 0 30 0
    pack .p
    update
    winfo width .f
} -result 30
test panedwindow-11.2 {moving sash changes size of pane to right} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 20] [frame .f2 -width 20 -height 20]
    pack .p
    update
    set result [winfo width .f2]
    .p sash place 0 30 0
    update
    lappend result [winfo width .f2]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 10}
test panedwindow-11.3 {moving sash does not change reqsize of panedwindow} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 20] [frame .f2 -width 20 -height 20]
    .p sash place 0 30 0
    winfo reqwidth .p
} -result 44
test panedwindow-11.4 {moving sash changes size of pane above} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .f -width 20 -height 10] [button .c -text foobar] -sticky nsew
    .p sash place 0 0 20
    pack .p
    update
    set result [winfo height .f]
    set result
} -result 20
test panedwindow-11.5 {moving sash changes size of pane below} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .f -width 20 -height 10] [frame .f2 -width 20 -height 10]
    pack .p
    update
    set result [winfo height .f2]
    .p sash place 0 0 15
    update
    lappend result [winfo height .f2]
    set result
} -cleanup {
    deleteWindows
	deleteWindows
} -result {10 5}
test panedwindow-11.6 {moving sash does not change reqsize of panedwindow} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .f -width 20 -height 10] [frame .f2 -width 20 -height 10]
    set result [winfo reqheight .p]
    .p sash place 0 0 20
    lappend result [winfo reqheight .p]
    set result
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 24 24]
test panedwindow-11.7 {moving sash does not alter reqsize of widget} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .f -width 20 -height 10] [frame .f2 -width 20 -height 10]
    set result [winfo reqheight .f]
    .p sash place 0 0 20
    lappend result [winfo reqheight .f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 10]
test panedwindow-11.8 {moving sash restricted to minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 20] [button .c] -minsize 15
    .p sash place 0 10 0
    pack .p
    update
    winfo width .f
} -result 15
test panedwindow-11.9 {moving sash restricted to minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .f -width 20 -height 30] [button .c] -minsize 10
    .p sash place 0 0 5
    pack .p
    update
    winfo height .f
} -result 10
test panedwindow-11.10 {moving sash in unmapped window restricted to reqsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20]
    set result [list [.p sash coord 0]]
    .p sash place 0 100 0
    lappend result [.p sash coord 0]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list {20 0} {40 0}]
test panedwindow-11.11 {moving sash right pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20] \
            [frame .f3 -width 20 -height 30]
	    [frame .f3 -width 20 -height 30]
    .p sash place 0 80 0
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{60 0} {64 0}}
test panedwindow-11.12 {moving sash left pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20] \
            [frame .f3 -width 20 -height 30]
	    [frame .f3 -width 20 -height 30]
    .p sash place 1 0 0
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{0 0} {4 0}}
test panedwindow-11.13 {move sash in mapped window restricted to visible win} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20] \
            [frame .f3 -width 20 -height 30]
	    [frame .f3 -width 20 -height 30]
    place .p -width 50
    update
    .p sash place 1 100 0
    update
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {46 0}
test panedwindow-11.14 {move sash in mapped window restricted to visible win} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20] \
            [frame .f3 -width 20 -height 30]
	    [frame .f3 -width 20 -height 30]
    place .p -width 100
    update
    .p sash place 1 200 0
    update
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {96 0}
test panedwindow-11.15 {moving sash into "virtual" space on last pane increases reqsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .f -width 20 -height 30] [frame .f2 -width 20 -height 20] \
            [frame .f3 -width 20 -height 30]
	    [frame .f3 -width 20 -height 30]
    place .p -width 100
    set result [winfo reqwidth .p]
    update
    .p sash place 1 200 0
    update
    lappend result [winfo reqwidth .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {68 100}


test panedwindow-12.1 {horizontal panedwindow lays out widgets properly} -setup {
    deleteWindows
	deleteWindows
    set result {}
} -body {
    panedwindow .p -showhandle false -borderwidth 2 -sashpad 2 -sashwidth 2
    foreach win {.p.f .p.f2 .p.f3} {.p add [frame $win -width 20 -height 10]}
    pack .p
    update
    foreach w [.p panes] {lappend result [winfo x $w] [winfo y $w]}
    return $result
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 2 2 28 2 54 2]
test panedwindow-12.2 {vertical panedwindow lays out widgets properly} -setup {
    deleteWindows
	deleteWindows
    set result {}
} -body {
    panedwindow .p -showhandle false -borderwidth 2 -sashpad 2 -sashwidth 2 \
            -orient vertical
    foreach win {.p.f .p.f2 .p.f3} {.p add [frame $win -width 20 -height 10]}
    pack .p
    update
    foreach w [.p panes] {lappend result [winfo x $w] [winfo y $w]}
    return $result
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 2 2 2 18 2 34]
test panedwindow-12.3 {horizontal panedwindow lays out widgets properly} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    foreach {win color} {.p.f blue .p.f2 green} {
        .p add [frame $win -width 20 -height 20 -bg $color] -padx 10 -pady 5 \
                -sticky ""
	    .p add [frame $win -width 20 -height 20 -bg $color] -padx 10 -pady 5 \
            -sticky ""
    }
    pack .p
    update
    set result [list [winfo reqwidth .p] [winfo reqheight .p]]
    foreach win {.p.f .p.f2} {lappend result [winfo x $win] [winfo y $win]}
    .p paneconfigure .p.f -padx 0 -pady 0
    update
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
    foreach win {.p.f .p.f2} {lappend result [winfo x $win] [winfo y $win]}
    return $result
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 80 30 10 5 50 5 60 30 0 5 30 5]
test panedwindow-12.4 {vertical panedwindow lays out widgets properly} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0 \
            -orient vertical
    foreach win {.p.f .p.f2} {
        .p add [frame $win -width 20 -height 20] -padx 10 -pady 5 -sticky ""
	.p add [frame $win -width 20 -height 20] -padx 10 -pady 5 -sticky ""
    }
    pack .p
    update
    set result [list [winfo reqwidth .p] [winfo reqheight .p]]
    foreach win {.p.f .p.f2} {lappend result [winfo x $win] [winfo y $win]}
    .p paneconfigure .p.f -padx 0 -pady 0
    update
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
    foreach win {.p.f .p.f2} {lappend result [winfo x $win] [winfo y $win]}
    return $result
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 40 60 10 5 10 35 40 50 10 0 10 25]
test panedwindow-12.5 {panedwindow respects reqsize of panes when possible} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    .p add [frame .p.f -width 20 -height 20] -sticky ""
    place .p -width 40
    update
    set result [list [winfo width .p.f]]
    .p.f configure -width 30
    update
    lappend result [winfo width .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 20 30]
test panedwindow-12.6 {panedwindow takes explicit widget width over reqwidth} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    .p add [frame .p.f -width 20 -height 20] -width 20 -sticky ""
    place .p -width 40
    update
    set result [list [winfo width .p.f]]
    .p.f configure -width 30
    update
    lappend result [winfo width .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 20 20]
test panedwindow-12.7 {horizontal panedwindow reqheight is max pane height} -setup {
    deleteWindows
test panedwindow-12.7 {horizontal panedwindow reqheight is max slave height} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    .p add [frame .p.f -width 20 -height 20] [frame .p.f2 -width 20 -height 20]
    set result [winfo reqheight .p]
    .p.f config -height 40
    lappend result [winfo reqheight .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 40}
test panedwindow-12.8 {horizontal panedwindow reqheight is max pane height} -setup {
    deleteWindows
test panedwindow-12.8 {horizontal panedwindow reqheight is max slave height} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    foreach win {.p.f .p.f2} {.p add [frame $win -width 20 -height 20]}
    .p paneconfigure .p.f -height 15
    set result [winfo reqheight .p]
    .p.f config -height 40
    lappend result [winfo reqheight .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 20}
test panedwindow-12.9 {panedwindow pane width overrides widget width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4
    foreach win {.p.f .p.f2} {.p add [frame $win -width 20 -height 20]}
    .p sash place 0 10 0
    pack .p
    update
    set result [winfo width .p.f]
    .p paneconfigure .p.f -width 30
    lappend result [winfo width .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 10]
test panedwindow-12.10 {panedwindow respects reqsize of panes when possible} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    .p add [frame .p.f -width 20 -height 20] -sticky ""
    place .p -height 40
    update
    set result [list [winfo height .p.f]]
    .p.f configure -height 30
    update
    lappend result [winfo height .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 20 30]
test panedwindow-12.11 {panedwindow takes explicit height over reqheight} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    .p add [frame .p.f -width 20 -height 20] -height 20 -sticky ""
    place .p -height 40
    update
    set result [list [winfo height .p.f]]
    .p.f configure -height 30
    update
    lappend result [winfo height .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 20 20]
test panedwindow-12.12 {vertical panedwindow reqwidth is max pane width} -setup {
    deleteWindows
test panedwindow-12.12 {vertical panedwindow reqwidth is max slave width} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    .p add [frame .p.f -width 20 -height 20] [frame .p.f2 -width 20 -height 20]
    set result [winfo reqwidth .p]
    .p.f config -width 40
    lappend result [winfo reqwidth .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 40}
test panedwindow-12.13 {vertical panedwindow reqwidth is max pane width} -setup {
    deleteWindows
test panedwindow-12.13 {vertical panedwindow reqwidth is max slave width} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    foreach win {.p.f .p.f2} {.p add [frame $win -width 20 -height 20]}
    .p paneconfigure .p.f -width 15
    set result [winfo reqwidth .p]
    .p.f config -width 40
    lappend result [winfo reqwidth .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 20}
test panedwindow-12.14 {panedwindow pane height overrides widget width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 4 \
            -orient vertical
    foreach win {.p.f .p.f2} {.p add [frame $win -width 20 -height 20]}
    .p sash place 0 0 10
    pack .p
    update
    set result [winfo height .p.f]
    .p paneconfigure .p.f -height 30
    lappend result [winfo height .p.f]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 10]


test panedwindow-13.1 {PanestructureProc, widget yields managements} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Check that the panedwindow correctly yields geometry management of
    # a pane when the pane is destroyed.
    # a slave when the slave is destroyed.

    # This test should not cause a core dump, and it should not cause
    # a memory leak.
    panedwindow .p
    .p add [button .b]
    destroy .p
    pack .b
    destroy .b
    set result ""
} -result {}
test panedwindow-13.2 {PanedWindowLostPaneProc, widget yields management} -setup {
    deleteWindows
test panedwindow-13.2 {PanedWindowLostSlaveProc, widget yields management} -setup {
	deleteWindows
} -body {
    # Check that the paned window correctly yields geometry management of
    # a pane when some other geometry manager steals the pane from us.
    # a slave when some other geometry manager steals the slave from us.

    # This test should not cause a core dump, and it should not cause a
    # memory leak.
    panedwindow .p
    .p add [button .b]
    pack .p
    update
1491
1492
1493
1494
1495
1496
1497
1498

1499
1500
1501
1502
1503
1504
1505
1506

1507
1508
1509
1510
1511

1512
1513
1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530

1531
1532
1533

1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546

1547
1548
1549

1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569

1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586

1587
1588
1589

1590
1591
1592
1593

1594
1595
1596
1597
1598
1599
1600
1601
1602

1603
1604
1605

1606
1607
1608
1609

1610
1611
1612
1613
1614
1615
1616
1617

1618
1619
1620

















1621
1622
1623
1624

1625
1626
1627
1628
1629
1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652

1653
1654
1655
1656
1657


1658
1659
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
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510

1511
1512
1513
1514
1515

1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529

1530
1531
1532

1533
1534
1535
1536

1537
1538
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548

1549
1550
1551
1552

1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565

1566
1567
1568

1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588

1589
1590
1591
1592

1593
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604

1605
1606
1607
1608

1609
1610
1611
1612
1613
1614
1615
1616

1617
1618
1619

1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
1647
1648

1649
















1650
1651

1652
1653
1654
1655


1656
1657
1658
1659
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







-
+







-
+




-
+




-
+













-
+


-
+



-
+








-
+


-
+



-
+












-
+


-
+



-
+












-
+


-
+



-
+








-
+


-
+



-
+







-
+


-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+








-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+



-
-
+
+








-
+


-
+



-
-
+
+








-
+


-
+




-
+













-
+


-
+



-
+








-
+


-
+



-
+








-
+


-
+



-
+







-
+


-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+








-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+



-
-
+
+








-
+


-
+



-
-
+
+








-
+




-
+





-
+













-
+


-
+




-
+








-
+


-
+




-
+












-
+


-
+




-
+












-
+


-
+




-
+








-
+


-
+




-
+








-
+


-
+




-
+








-
+


-
+




-
+








-
+


-
+




-
-
+
+








-
+


-
+




-
-
+
+








-
+


-
+





-
+













-
+


-
+




-
+








-
+


-
+




-
+








-
+


-
+




-
+







-
+


-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+








-
-
-
-
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+








-
+


-
+




-
-
+
+








-
+








-
+



-
+





-
+



-
+



-
+





-
+



-
+



-
+





-
+



-
+




-
+





-
+



-
+




-
+





-
+



-
+




-
+





-
+


-
+


-
+







    list news [winfo x .p.f] [winfo y .p.f]  [winfo width .p.f] [winfo height .p.f]
} -cleanup {
    deleteWindows
} -result {news 0 0 40 40}


test panedwindow-16.1 {setting minsize when pane is too small snaps width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .p.f -height 20 -width 20 -bg red]
    set result [winfo reqwidth .p]
    .p paneconfigure .p.f -minsize 40
    lappend result [winfo reqwidth .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 20 40]


test panedwindow-17.1 {MoveSash, move right} -setup {
    deleteWindows
	deleteWindows
    set result {}
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Get the requested width of the paned window
    lappend result [winfo reqwidth .p]

    .p sash place 0 30 0

    # Get the reqwidth again, to make sure it hasn't changed
    lappend result [winfo reqwidth .p]

    # Check that the sash moved
    lappend result [.p sash coord 0]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 42 42 {30 0}]
test panedwindow-17.2 {MoveSash, move right (unmapped) clipped by reqwidth} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should be clipped by the reqwidth of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 40 0]
test panedwindow-17.3 {MoveSash, move right (mapped, width < reqwidth) clipped by width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Put the panedwindow up on the display and give it a width < reqwidth
    place .p -x 0 -y 0 -width 32
    update

    .p sash place 0 100 0

    # Get the new sash coord; it should be clipped by the visible width of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 30 0]
test panedwindow-17.4 {MoveSash, move right (mapped, width > reqwidth) clipped by width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Put the panedwindow up on the display and give it a width > reqwidth
    place .p -x 0 -y 0 -width 102
    update

    .p sash place 0 200 0

    # Get the new sash coord; it should be clipped by the visible width of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 100 0]
test panedwindow-17.5 {MoveSash, move right respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 30 0]
test panedwindow-17.6 {MoveSash, move right respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 40 0]
test panedwindow-17.7 {MoveSash, move right pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
	deleteWindows
} -result [list 62 0]
test panedwindow-17.8 {MoveSash, move right pushes other sashes, respects minsize} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 62 0]
test panedwindow-17.8 {MoveSash, move right pushes other sashes, respects minsize} -setup {
    deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
} -result [list 52 0]
test panedwindow-17.9 {MoveSash, move right respects minsize, exludes pad} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize 10 -padx 5
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize 10 -padx 5
    }

    .p sash place 0 100 0

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 50 0]
test panedwindow-17.10 {MoveSash, move right, negative minsize becomes 0} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize -50
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize -50
    }

    .p sash place 0 50 0

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 50 0] [list 52 0]]
test panedwindow-17.11 {MoveSash, move left} -setup {
    deleteWindows
	deleteWindows
} -body {
    set result {}
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Get the requested width of the paned window
    lappend result [winfo reqwidth .p]

    .p sash place 0 10 0

    # Get the reqwidth again, to make sure it hasn't changed
    lappend result [winfo reqwidth .p]

    # Check that the sash moved
    lappend result [.p sash coord 0]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 42 42 {10 0}]
test panedwindow-17.12 {MoveSash, move left, can't move outside of window} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 -100 0

    # Get the new sash coord; it should be clipped by the reqwidth of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 0]
test panedwindow-17.13 {MoveSash, move left respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 10 0]
test panedwindow-17.14 {MoveSash, move left respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 22 0]
test panedwindow-17.15 {MoveSash, move left pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
	deleteWindows
} -result [list 0 0]
test panedwindow-17.16 {MoveSash, move left pushes other sashes, respects minsize} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 0]
test panedwindow-17.16 {MoveSash, move left pushes other sashes, respects minsize} -setup {
    deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
} -result [list 10 0]
test panedwindow-17.17 {MoveSash, move left respects minsize, exludes pad} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize 10 -padx 5
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize 10 -padx 5
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 42 0]
test panedwindow-17.18 {MoveSash, move left, negative minsize becomes 0} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    foreach w {.f1 .f2 .f3} c {red blue green} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize -50
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize -50
    }

    .p sash place 1 10 0

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 8 0] [list 10 0]]


test panedwindow-18.1 {MoveSash, move down} -setup {
    deleteWindows
	deleteWindows
} -body {
    set result {}
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Get the requested width of the paned window
    lappend result [winfo reqheight .p]

    .p sash place 0 0 30

    # Get the reqwidth again, to make sure it hasn't changed
    lappend result [winfo reqheight .p]

    # Check that the sash moved
    lappend result [.p sash coord 0]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 42 42 {0 30}]
test panedwindow-18.2 {MoveSash, move down (unmapped) clipped by reqheight} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should be clipped by the reqheight of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 40]
test panedwindow-18.3 {MoveSash, move down (mapped, height < reqheight) clipped by height} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Put the panedwindow up on the display and give it a height < reqheight
    place .p -x 0 -y 0 -height 32
    update

    .p sash place 0 0 100

    # Get the new sash coord; it should be clipped by the visible height of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 30]
test panedwindow-18.4 {MoveSash, move down (mapped, height > reqheight) clipped by height} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Put the panedwindow up on the display and give it a width > reqwidth
    place .p -x 0 -y 0 -height 102
    update

    .p sash place 0 0 200

    # Get the new sash coord; it should be clipped by the visible width of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 100]
test panedwindow-18.5 {MoveSash, move down respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 30]
test panedwindow-18.6 {MoveSash, move down respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 40]
test panedwindow-18.7 {MoveSash, move down pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 62]
test panedwindow-18.8 {MoveSash, move down pushes other sashes, respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 52]
test panedwindow-18.9 {MoveSash, move down respects minsize, exludes pad} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize 10 -pady 5
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize 10 -pady 5
    }

    .p sash place 0 0 100

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 50]
test panedwindow-18.10 {MoveSash, move right, negative minsize becomes 0} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize -50
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize -50
    }

    .p sash place 0 0 50

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 0 50] [list 0 52]]
test panedwindow-18.11 {MoveSash, move up} -setup {
    deleteWindows
	deleteWindows
} -body {
    set result {}
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    # Get the requested width of the paned window
    lappend result [winfo reqheight .p]

    .p sash place 0 0 10

    # Get the reqwidth again, to make sure it hasn't changed
    lappend result [winfo reqheight .p]

    # Check that the sash moved
    lappend result [.p sash coord 0]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 42 42 {0 10}]
test panedwindow-18.12 {MoveSash, move up, can't move outside of window} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 0 0 -100

    # Get the new sash coord; it should be clipped by the reqwidth of
    # the panedwindow.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 0]
test panedwindow-18.13 {MoveSash, move up respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 0 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 10]
test panedwindow-18.14 {MoveSash, move up respects minsize} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 22]
test panedwindow-18.15 {MoveSash, move up pushes other sashes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
	deleteWindows
} -result [list 0 0]
test panedwindow-18.16 {MoveSash, move up pushes other sashes, respects minsize} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew
	    .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
} -result [list 0 0]
test panedwindow-18.16 {MoveSash, move up pushes other sashes, respects minsize} -setup {
    deleteWindows
	deleteWindows
} -result [list 0 10]
test panedwindow-18.17 {MoveSash, move up respects minsize, exludes pad} -setup {
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] -sticky nsew -minsize 10
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible while
    # respecting minsizes.
    .p sash coord 0
} -cleanup {
    deleteWindows
} -result [list 0 10]
test panedwindow-18.17 {MoveSash, move up respects minsize, exludes pad} -setup {
    deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize 10 -pady 5
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize 10 -pady 5
    }

    .p sash place 1 0 0

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    .p sash coord 1
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list 0 42]
test panedwindow-18.18 {MoveSash, move up, negative minsize becomes 0} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    foreach w {.f1 .f2 .f3} c {red blue green} {
        .p add [frame $w -height 20 -width 20 -bg $c] \
                -sticky nsew -minsize -50
	    .p add [frame $w -height 20 -width 20 -bg $c] \
		    -sticky nsew -minsize -50
    }

    .p sash place 1 0 10

    # Get the new sash coord; it should have moved as far as possible,
    # respecting minsizes.
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 0 8] [list 0 10]]


# The following tests check that the panedwindow is correctly computing its
# geometry based on the various configuration options that can affect the
# geometry.

test panedwindow-19.1 {ComputeGeometry, reqheight taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue]
	    .p add [frame $w -width 20 -height 20 -bg blue]
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .f3 configure -height 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 60 20] [list 60 40]]

test panedwindow-19.2 {ComputeGeometry, reqheight taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue]
	    .p add [frame $w -width 20 -height 20 -bg blue]
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .p paneconfigure .f3 -height 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 60 20] [list 60 40]]

test panedwindow-19.3 {ComputeGeometry, reqheight taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] -pady 20
	    .p add [frame $w -width 20 -height 20 -bg blue] -pady 20
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .p paneconfigure .f3 -height 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 60 60] [list 60 80]]

test panedwindow-19.4 {ComputeGeometry, reqwidth taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0 \
            -orient vertical
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue]
	.p add [frame $w -width 20 -height 20 -bg blue]
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .f3 configure -width 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 20 60] [list 40 60]]

test panedwindow-19.5 {ComputeGeometry, reqwidth taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0 \
            -orient vertical
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue]
	.p add [frame $w -width 20 -height 20 -bg blue]
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .p paneconfigure .f3 -width 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 20 60] [list 40 60]]

test panedwindow-19.6 {ComputeGeometry, reqwidth taken from widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 0 \
            -orient vertical
    foreach w {.f1 .f2 .f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] -padx 20
	.p add [frame $w -width 20 -height 20 -bg blue] -padx 20
    }
    set result [list [list [winfo reqwidth .p] [winfo reqheight .p]]]
    .p paneconfigure .f3 -width 40
    lappend result [list [winfo reqwidth .p] [winfo reqheight .p]]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list [list 60 60] [list 80 60]]

test panedwindow-19.7 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.7 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{20 0} {40 0}}

test panedwindow-19.10 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.10 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {53 3 20 20} {95 3 20 20}}

test panedwindow-19.11 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.11 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 20} {0 40}}

test panedwindow-19.14 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.14 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 53 20 20} {3 95 20 20}}
test panedwindow-19.15 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.15 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{23 0} {49 0}}

test panedwindow-19.18 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.18 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {59 3 20 20} {107 3 20 20}}

test panedwindow-19.19 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.19 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 23} {0 49}}

test panedwindow-19.22 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.22 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 59 20 20} {3 107 20 20}}
test panedwindow-19.23 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.23 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{20 0} {43 0}}

test panedwindow-19.26 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.26 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {56 3 20 20} {101 3 20 20}}

test panedwindow-19.27 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.27 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 20} {0 43}}

test panedwindow-19.30 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.30 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 56 20 20} {3 101 20 20}}
test panedwindow-19.31 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.31 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{21 0} {47 0}}

test panedwindow-19.34 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.34 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {59 3 20 20} {107 3 20 20}}

test panedwindow-19.35 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.35 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 21} {0 47}}

test panedwindow-19.38 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.38 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 59 20 20} {3 107 20 20}}
test panedwindow-19.39 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.39 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{25 0} {55 0}}

test panedwindow-19.42 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.42 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {63 3 20 20} {115 3 20 20}}

test panedwindow-19.43 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.43 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 25} {0 55}}

test panedwindow-19.46 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.46 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 63 20 20} {3 115 20 20}}
test panedwindow-19.47 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.47 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{28 0} {64 0}}

test panedwindow-19.50 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.50 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {69 3 20 20} {127 3 20 20}}

test panedwindow-19.51 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.51 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 28} {0 64}}

test panedwindow-19.54 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.54 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 69 20 20} {3 127 20 20}}
test panedwindow-19.55 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.55 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{25 0} {58 0}}

test panedwindow-19.58 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.58 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {66 3 20 20} {121 3 20 20}}

test panedwindow-19.59 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.59 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
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
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







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 25} {0 58}}

test panedwindow-19.62 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.62 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 66 20 20} {3 121 20 20}}
test panedwindow-19.63 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.63 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3181
3182
3183
3184
3185
3186
3187
3188

3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209

3210
3211
3212

3213
3214
3215
3216
3217
3218
3219
3181
3182
3183
3184
3185
3186
3187

3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208

3209
3210
3211

3212
3213
3214
3215
3216
3217
3218
3219







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{26 0} {62 0}}

test panedwindow-19.66 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.66 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{11 3 20 20} {69 3 20 20} {127 3 20 20}}

test panedwindow-19.67 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.67 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
3248
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276

3277
3278
3279

3280
3281
3282
3283
3284
3285
3286
3248
3249
3250
3251
3252
3253
3254

3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275

3276
3277
3278

3279
3280
3281
3282
3283
3284
3285
3286







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{0 26} {0 62}}

test panedwindow-19.70 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.70 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{3 11 20 20} {3 69 20 20} {3 127 20 20}}
test panedwindow-19.71 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.71 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3310
3311
3312
3313
3314
3315
3316
3317

3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338

3339
3340
3341

3342
3343
3344
3345
3346
3347
3348
3310
3311
3312
3313
3314
3315
3316

3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337

3338
3339
3340

3341
3342
3343
3344
3345
3346
3347
3348







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{22 2} {42 2}}

test panedwindow-19.74 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.74 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {55 5 20 20} {97 5 20 20}}

test panedwindow-19.75 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.75 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
3377
3378
3379
3380
3381
3382
3383
3384

3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405

3406
3407
3408

3409
3410
3411
3412
3413
3414
3415
3377
3378
3379
3380
3381
3382
3383

3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404

3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3415







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 22} {2 42}}

test panedwindow-19.78 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.78 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 55 20 20} {5 97 20 20}}
test panedwindow-19.79 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.79 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3439
3440
3441
3442
3443
3444
3445
3446

3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467

3468
3469
3470

3471
3472
3473
3474
3475
3476
3477
3439
3440
3441
3442
3443
3444
3445

3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466

3467
3468
3469

3470
3471
3472
3473
3474
3475
3476
3477







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{25 2} {51 2}}

test panedwindow-19.82 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.82 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {61 5 20 20} {109 5 20 20}}

test panedwindow-19.83 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.83 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
3506
3507
3508
3509
3510
3511
3512
3513

3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534

3535
3536
3537

3538
3539
3540
3541
3542
3543
3544
3506
3507
3508
3509
3510
3511
3512

3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533

3534
3535
3536

3537
3538
3539
3540
3541
3542
3543
3544







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 25} {2 51}}

test panedwindow-19.86 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.86 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 0 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 61 20 20} {5 109 20 20}}
test panedwindow-19.87 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.87 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3568
3569
3570
3571
3572
3573
3574
3575

3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596

3597
3598
3599

3600
3601
3602
3603
3604
3605
3606
3568
3569
3570
3571
3572
3573
3574

3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595

3596
3597
3598

3599
3600
3601
3602
3603
3604
3605
3606







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{22 2} {45 2}}

test panedwindow-19.90 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.90 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {58 5 20 20} {103 5 20 20}}

test panedwindow-19.91 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.91 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
3635
3636
3637
3638
3639
3640
3641
3642

3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666

3667
3668
3669
3670
3671
3672
3673
3635
3636
3637
3638
3639
3640
3641

3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662

3663
3664
3665

3666
3667
3668
3669
3670
3671
3672
3673







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 22} {2 45}}

test panedwindow-19.94 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.94 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 58 20 20} {5 103 20 20}}
test panedwindow-19.95 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.95 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3697
3698
3699
3700
3701
3702
3703
3704

3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725

3726
3727
3728

3729
3730
3731
3732
3733
3734
3735
3697
3698
3699
3700
3701
3702
3703

3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724

3725
3726
3727

3728
3729
3730
3731
3732
3733
3734
3735







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{23 2} {49 2}}

test panedwindow-19.98 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.98 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {61 5 20 20} {109 5 20 20}}

test panedwindow-19.99 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.99 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
3764
3765
3766
3767
3768
3769
3770
3771

3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792

3793
3794
3795

3796
3797
3798
3799
3800
3801
3802
3764
3765
3766
3767
3768
3769
3770

3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791

3792
3793
3794

3795
3796
3797
3798
3799
3800
3801
3802







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 23} {2 49}}

test panedwindow-19.102 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.102 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 0 \
        -sashwidth 3 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 61 20 20} {5 109 20 20}}
test panedwindow-19.103 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.103 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3826
3827
3828
3829
3830
3831
3832
3833

3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854

3855
3856
3857

3858
3859
3860
3861
3862
3863
3864
3826
3827
3828
3829
3830
3831
3832

3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853

3854
3855
3856

3857
3858
3859
3860
3861
3862
3863
3864







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{27 2} {57 2}}

test panedwindow-19.106 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.106 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {65 5 20 20} {117 5 20 20}}

test panedwindow-19.107 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.107 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
3893
3894
3895
3896
3897
3898
3899
3900

3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921

3922
3923
3924

3925
3926
3927
3928
3929
3930
3931
3893
3894
3895
3896
3897
3898
3899

3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920

3921
3922
3923

3924
3925
3926
3927
3928
3929
3930
3931







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 27} {2 57}}

test panedwindow-19.110 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.110 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 65 20 20} {5 117 20 20}}
test panedwindow-19.111 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.111 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
3955
3956
3957
3958
3959
3960
3961
3962

3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983

3984
3985
3986

3987
3988
3989
3990
3991
3992
3993
3955
3956
3957
3958
3959
3960
3961

3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982

3983
3984
3985

3986
3987
3988
3989
3990
3991
3992
3993







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{30 2} {66 2}}

test panedwindow-19.114 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.114 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {71 5 20 20} {129 5 20 20}}

test panedwindow-19.115 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.115 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -orient vertical -sashwidth 0 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
4022
4023
4024
4025
4026
4027
4028
4029

4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050

4051
4052
4053

4054
4055
4056
4057
4058
4059
4060
4022
4023
4024
4025
4026
4027
4028

4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049

4050
4051
4052

4053
4054
4055
4056
4057
4058
4059
4060







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 30} {2 66}}

test panedwindow-19.118 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.118 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 0 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 71 20 20} {5 129 20 20}}
test panedwindow-19.119 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.119 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 0 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
4084
4085
4086
4087
4088
4089
4090
4091

4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112

4113
4114
4115

4116
4117
4118
4119
4120
4121
4122
4084
4085
4086
4087
4088
4089
4090

4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111

4112
4113
4114

4115
4116
4117
4118
4119
4120
4121
4122







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{27 2} {60 2}}

test panedwindow-19.122 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.122 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {68 5 20 20} {123 5 20 20}}

test panedwindow-19.123 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.123 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 0
    .p add [frame .f -width 20 -height 20 -bg red] -pady 0 \
                    -sticky ""
4151
4152
4153
4154
4155
4156
4157
4158

4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179

4180
4181
4182

4183
4184
4185
4186
4187
4188
4189
4151
4152
4153
4154
4155
4156
4157

4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178

4179
4180
4181

4182
4183
4184
4185
4186
4187
4188
4189







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 27} {2 60}}

test panedwindow-19.126 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.126 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 0 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 11 -padx 3
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
        }
    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 68 20 20} {5 123 20 20}}
test panedwindow-19.127 {ComputeGeometry, one pane, reqsize set properly} -setup {
test panedwindow-19.127 {ComputeGeometry, one slave, reqsize set properly} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    .p add [frame .p.f -width 20 -height 20 -bg red] -padx 1 -sticky ""
    list [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
4213
4214
4215
4216
4217
4218
4219
4220

4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241

4242
4243
4244

4245
4246
4247
4248
4249
4250
4251
4213
4214
4215
4216
4217
4218
4219

4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240

4241
4242
4243

4244
4245
4246
4247
4248
4249
4250
4251







-
+




















-
+


-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{28 2} {64 2}}

test panedwindow-19.130 {ComputeGeometry/ArrangePanes, pane coords} -setup {
test panedwindow-19.130 {ComputeGeometry/ArrangePanes, slave coords} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
            -sticky nsew -pady 3 -padx 11
    }
    pack .p
    update
    set result {}
    foreach w {.p.f1 .p.f2 .p.f3} {
        lappend result [list [winfo x $w] [winfo y $w] \
            [winfo width $w] [winfo height $w]]
    }
    return $result
} -cleanup {
    deleteWindows
} -result {{13 5 20 20} {71 5 20 20} {129 5 20 20}}

test panedwindow-19.131 {ComputeGeometry, one pane, vertical} -setup {
test panedwindow-19.131 {ComputeGeometry, one slave, vertical} -setup {
    deleteWindows
} -body {
    # With just one pane, sashpad and sashwidth should not
    # With just one slave, sashpad and sashwidth should not
    # affect the panedwindow's geometry, since no sash should
    # ever be drawn.
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -orient vertical -sashwidth 3 -handlesize 6 \
        -showhandle 1
    .p add [frame .f -width 20 -height 20 -bg red] -pady 1 \
                    -sticky ""
4280
4281
4282
4283
4284
4285
4286
4287

4288
4289
4290
4291
4292
4293
4294
4280
4281
4282
4283
4284
4285
4286

4287
4288
4289
4290
4291
4292
4293
4294







-
+







                            -sticky ""
    }
    list [.p sash coord 0] [.p sash coord 1]
} -cleanup {
    deleteWindows
} -result {{2 28} {2 64}}

test panedwindow-19.134 {ComputeGeometry/ArrangePanes, pane coords, vert} -setup {
test panedwindow-19.134 {ComputeGeometry/ArrangePanes, slave coords, vert} -setup {
    deleteWindows
} -body {
    panedwindow .p -borderwidth 2 -sashpad 5 \
        -sashwidth 3 -handlesize 6 -showhandle 1 \
        -orient vertical
    foreach w {.p.f1 .p.f2 .p.f3} {
        .p add [frame $w -width 20 -height 20 -bg blue] \
4304
4305
4306
4307
4308
4309
4310
4311

4312
4313
4314
4315
4316
4317
4318

4319
4320
4321


4322
4323
4324
4325

4326
4327
4328
4329
4330
4331
4332
4333
4334

4335
4336
4337
4338

4339
4340
4341
4342
4343
4344
4345
4346

4347
4348
4349
4350
4351

4352
4353
4354
4355
4356
4357
4358
4359

4360
4361
4362
4363

4364
4365
4366
4367
4368
4369

4370
4371
4372

4373
4374
4375
4376

4377
4378
4379
4380
4381
4382

4383
4384
4385

4386
4387
4388
4389
4390

4391
4392
4393
4394
4395
4396

4397
4398
4399

4400
4401
4402
4403

4404
4405
4406
4407
4408
4409
4410
4411

4412
4413
4414
4415
4416

4417
4418
4419
4420
4421
4422
4423
4424

4425
4426
4427
4428

4429
4430
4431
4432
4433
4434
4435
4436

4437
4438
4439

4440
4441
4442
4443

4444
4445
4446
4447
4448
4449
4450
4451

4452
4453
4454

4455
4456
4457
4458

4459
4460
4461
4462
4463
4464
4465
4466

4467
4468
4469

4470
4471
4472
4473

4474
4475
4476
4477
4478
4479
4480
4481

4482
4483
4484
4485
4486

4487
4488
4489
4490
4491
4492
4493
4494

4495
4496
4497
4498
4499
4500
4501
4502







4503
4504
4505
4506
4507

4508
4509
4510
4511
4512
4513
4514
4515







4516
4517
4518
4519
4520

4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534













4535
4536
4537
4538
4539
4540
4541


4542
4543
4544
4545
4546

4547
4548
4549
4550
4551

4552
4553
4554


4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565


4566
4567
4568
4569

4570
4571
4572
4573
4574

4575
4576
4577

4578
4579
4580
4581
4582

4583
4584
4585

4586
4587
4588
4589
4590
4591
4592

4593
4594
4595

4596
4597
4598
4599
4600
4601
4602

4603
4604
4605

4606
4607
4608
4609
4610
4611
4612

4613
4614
4615

4616
4617
4618
4619
4620
4621
4622

4623
4624
4625

4626
4627
4628
4629
4630
4631
4632

4633
4634
4635

4636
4637
4638
4639
4640
4641
4642

4643
4644
4645

4646
4647
4648
4649
4650
4651

4652
4653
4654

4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668

4669
4670
4671
4672

4673
4674
4675
4676
4677
4678

4679
4680

4681
4682
4683

4684
4685
4686
4687
4688
4689
4690
4691

4692
4693
4694

4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705

4706
4707
4708

4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720

4721
4722
4723

4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735

4736
4737
4738

4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750

4751
4752
4753

4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765

4766
4767
4768

4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780

4781
4782
4783

4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795

4796
4797
4798

4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810

4811
4812
4813

4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825

4826
4827
4828


4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840

4841
4842
4843


4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856

4857
4858
4859

4860
4861
4862
4863
4864
4865

4866
4867
4868

4869
4870
4871
4872
4873
4874
4875

4876
4877
4878

4879
4880
4881
4882
4883
4884
4885

4886
4887
4888

4889
4890
4891
4892
4893
4894

4895
4896
4897

4898
4899
4900
4901
4902
4903
4904
4905
4906

4907
4908
4909

4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929



















4930
4931
4932
4933
4934

4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954



















4955
4956
4957
4958
4959

4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974




4975
4976
4977
4978



4979
4980
4981
4982



4983
4984
4985
4986



4987
4988
4989
4990
4991

4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003











5004
5005
5006
5007
5008
5009

5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023













5024
5025
5026
5027
5028
5029

5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045















5046
5047
5048
5049
5050

5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066















5067
5068
5069
5070
5071

5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087















5088
5089
5090
5091
5092

5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108















5109
5110
5111
5112
5113
5114
5115

5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132

5133
5134
5135
5136
5137

5138
5139
5140
5141
5142

5143
5144
5145

5146
5147
5148
5149

5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168

5169
5170
5171
5172
5173

5174
5175
5176
5177

5178
5179
5180

5181
5182
5183

5184
5185
5186
5187

5188
5189
5190

5191
5192
5193

5194
5195
5196
5197

5198
5199
5200

5201
5202
5203

5204
5205
5206
5207

5208
5209
5210

5211
5212
5213

5214
5215
5216
5217

5218
5219
5220

5221
5222
5223

5224
5225
5226
5227

5228
5229
5230

5231
5232
5233

5234
5235
5236
5237

5238
5239
5240

5241
5242
5243

5244
5245
5246

5247
5248

5249
5250
5251

5252
5253
5254

5255
5256
5257

5258
5259

5260
5261
5262

5263
5264
5265

5266
5267
5268

5269
5270

5271
5272
5273

5274
5275
5276

5277
5278
5279

5280
5281

5282
5283
5284

5285
5286
5287

5288
5289
5290
5291
5292


5293
5294
5295

5296
5297
5298

5299
5300
5301
5302
5303

5304
5305
5306

5307
5308
5309
5310
5311

5312
5313
5314

5315
5316
5317
5318
5319

5320
5321
5322

5323
5324
5325
5326

5327
5328
5329

5330
5331
5332

5333
5334
5335
5336

5337
5338
5339

5340
5341
5342

5343
5344
5345
5346

5347
5348
5349

5350
5351
5352

5353
5354
5355
5356

5357
5358
5359

5360
5361
5362

5363
5364
5365
5366

5367
5368
5369

5370
5371
5372

5373
5374
5375
5376

5377
5378
5379

5380
5381
5382

5383
5384
5385
5386

5387
5388
5389

5390
5391
5392

5393
5394
5395

5396
5397

5398
5399
5400

5401
5402
5403

5404
5405
5406

5407
5408

5409
5410
5411

5412
5413
5414

5415
5416
5417

5418
5419

5420
5421
5422

5423
5424
5425

5426
5427
5428

5429
5430

5431
5432
5433

5434
5435
5436

5437
5438
5439
5440
5441


5442
5443
5444

5445
5446
5447
5448
5449

5450
5451
5452
5453

5454
5455
5456

5457
5458
5459
5460
5461
5462
5463
5464


5465
5466
5467
5468

5469
5470
5471
5472
5473
5474
5475
4304
4305
4306
4307
4308
4309
4310

4311
4312
4313
4314
4315
4316
4317

4318
4319


4320
4321
4322
4323
4324

4325
4326
4327
4328
4329
4330
4331
4332
4333

4334
4335
4336
4337

4338
4339
4340
4341
4342
4343
4344
4345

4346
4347
4348
4349
4350

4351
4352
4353
4354
4355
4356
4357
4358

4359
4360
4361
4362

4363
4364
4365
4366
4367
4368

4369
4370
4371

4372
4373
4374
4375

4376
4377
4378
4379
4380
4381

4382
4383
4384

4385
4386
4387
4388
4389

4390
4391
4392
4393
4394
4395

4396
4397
4398

4399
4400
4401
4402

4403
4404
4405
4406
4407
4408
4409
4410

4411
4412
4413
4414
4415

4416
4417
4418
4419
4420
4421
4422
4423

4424
4425
4426
4427

4428
4429
4430
4431
4432
4433
4434
4435

4436
4437
4438

4439
4440
4441
4442

4443
4444
4445
4446
4447
4448
4449
4450

4451
4452
4453

4454
4455
4456
4457

4458
4459
4460
4461
4462
4463
4464
4465

4466
4467
4468

4469
4470
4471
4472

4473
4474
4475
4476
4477
4478
4479
4480

4481
4482
4483
4484
4485

4486
4487
4488
4489
4490
4491
4492
4493

4494
4495







4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506

4507
4508







4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519

4520
4521













4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539


4540
4541
4542
4543
4544
4545

4546
4547
4548
4549
4550

4551
4552


4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563


4564
4565
4566
4567
4568

4569
4570
4571
4572
4573

4574
4575
4576

4577
4578
4579
4580
4581

4582
4583
4584

4585
4586
4587
4588
4589
4590
4591

4592
4593
4594

4595
4596
4597
4598
4599
4600
4601

4602
4603
4604

4605
4606
4607
4608
4609
4610
4611

4612
4613
4614

4615
4616
4617
4618
4619
4620
4621

4622
4623
4624

4625
4626
4627
4628
4629
4630
4631

4632
4633
4634

4635
4636
4637
4638
4639
4640
4641

4642
4643
4644

4645
4646
4647
4648
4649
4650

4651
4652
4653

4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667

4668
4669
4670
4671

4672
4673
4674
4675
4676
4677

4678
4679

4680
4681
4682

4683
4684
4685
4686
4687
4688
4689
4690

4691
4692
4693

4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704

4705
4706
4707

4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719

4720
4721
4722

4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734

4735
4736
4737

4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749

4750
4751
4752

4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764

4765
4766
4767

4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779

4780
4781
4782

4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794

4795
4796
4797

4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809

4810
4811
4812

4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824

4825
4826


4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839

4840
4841


4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855

4856
4857
4858

4859
4860
4861
4862
4863
4864

4865
4866
4867

4868
4869
4870
4871
4872
4873
4874

4875
4876
4877

4878
4879
4880
4881
4882
4883
4884

4885
4886
4887

4888
4889
4890
4891
4892
4893

4894
4895
4896

4897
4898
4899
4900
4901
4902
4903
4904
4905

4906
4907
4908

4909
4910



















4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933

4934
4935



















4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958

4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970




4971
4972
4973
4974
4975



4976
4977
4978
4979



4980
4981
4982
4983



4984
4985
4986
4987
4988
4989
4990

4991
4992











4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008

5009
5010













5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028

5029
5030















5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049

5050
5051















5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070

5071
5072















5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091

5092
5093















5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114

5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131

5132
5133
5134
5135
5136

5137
5138
5139
5140
5141

5142
5143
5144

5145
5146
5147
5148

5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167

5168
5169
5170
5171
5172

5173
5174
5175
5176

5177
5178
5179

5180
5181
5182

5183
5184
5185
5186

5187
5188
5189

5190
5191
5192

5193
5194
5195
5196

5197
5198
5199

5200
5201
5202

5203
5204
5205
5206

5207
5208
5209

5210
5211
5212

5213
5214
5215
5216

5217
5218
5219

5220
5221
5222

5223
5224
5225
5226

5227
5228
5229

5230
5231
5232

5233
5234
5235
5236

5237
5238
5239

5240
5241
5242

5243
5244
5245

5246
5247

5248
5249
5250

5251
5252
5253

5254
5255
5256

5257
5258

5259
5260
5261

5262
5263
5264

5265
5266
5267

5268
5269

5270
5271
5272

5273
5274
5275

5276
5277
5278

5279
5280

5281
5282
5283

5284
5285
5286

5287
5288
5289
5290


5291
5292
5293
5294

5295
5296
5297

5298
5299
5300
5301
5302

5303
5304
5305

5306
5307
5308
5309
5310

5311
5312
5313

5314
5315
5316
5317
5318

5319
5320
5321

5322
5323
5324
5325

5326
5327
5328

5329
5330
5331

5332
5333
5334
5335

5336
5337
5338

5339
5340
5341

5342
5343
5344
5345

5346
5347
5348

5349
5350
5351

5352
5353
5354
5355

5356
5357
5358

5359
5360
5361

5362
5363
5364
5365

5366
5367
5368

5369
5370
5371

5372
5373
5374
5375

5376
5377
5378

5379
5380
5381

5382
5383
5384
5385

5386
5387
5388

5389
5390
5391

5392
5393
5394

5395
5396

5397
5398
5399

5400
5401
5402

5403
5404
5405

5406
5407

5408
5409
5410

5411
5412
5413

5414
5415
5416

5417
5418

5419
5420
5421

5422
5423
5424

5425
5426
5427

5428
5429

5430
5431
5432

5433
5434
5435

5436
5437
5438
5439


5440
5441
5442
5443

5444
5445
5446
5447
5448

5449
5450
5451
5452

5453
5454
5455

5456
5457
5458
5459
5460
5461
5462


5463
5464
5465
5466
5467

5468
5469
5470
5471
5472
5473
5474
5475







-
+






-
+

-
-
+
+



-
+








-
+



-
+







-
+




-
+







-
+



-
+





-
+


-
+



-
+





-
+


-
+




-
+





-
+


-
+



-
+







-
+




-
+







-
+



-
+







-
+


-
+



-
+







-
+


-
+



-
+







-
+


-
+



-
+







-
+




-
+







-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+




-
+




-
+

-
-
+
+









-
-
+
+



-
+




-
+


-
+




-
+


-
+






-
+


-
+






-
+


-
+






-
+


-
+






-
+


-
+






-
+


-
+






-
+


-
+





-
+


-
+













-
+



-
+





-
+

-
+


-
+







-
+


-
+










-
+


-
+











-
+


-
+











-
+


-
+











-
+


-
+











-
+


-
+











-
+


-
+











-
+


-
+











-
+


-
+











-
+

-
-
+
+











-
+

-
-
+
+












-
+


-
+





-
+


-
+






-
+


-
+






-
+


-
+





-
+


-
+








-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+











-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
-
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+
















-
+




-
+




-
+


-
+



-
+


















-
+




-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+



-
-
+
+


-
+


-
+




-
+


-
+




-
+


-
+




-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+



-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+


-
+

-
+


-
+


-
+



-
-
+
+


-
+




-
+



-
+


-
+






-
-
+
+



-
+







    return $result
} -cleanup {
    deleteWindows
} -result {{5 13 20 20} {5 71 20 20} {5 129 20 20}}


test panedwindow-20.1 {destroyed widgets are removed from panedwindow} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [frame .f -width 20 -height 20 -bg blue]
    destroy .f
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-20.2 {destroyed pane causes geometry recomputation} -setup {
    deleteWindows
test panedwindow-20.2 {destroyed slave causes geometry recomputation} -setup {
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red]
	    [frame .f2 -width 20 -height 20 -bg red]
    destroy .f
    winfo reqwidth .p
} -cleanup {
    deleteWindows
} -result 20


test panedwindow-21.1 {ArrangePanes, extra space is given to the last pane} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
	    [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
    place .p -width 100 -x 0 -y 0
    update
    winfo width .f2
} -cleanup {
    deleteWindows
} -result 78
test panedwindow-21.2 {ArrangePanes, extra space is given to the last pane} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
	    [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
    place .p -height 100 -x 0 -y 0
    update
    winfo height .f2
} -cleanup {
    deleteWindows
} -result 78
test panedwindow-21.3 {ArrangePanes, explicit height/width are preferred} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red] -sticky ""
	    [frame .f2 -width 20 -height 20 -bg red] -sticky ""
    .p paneconfigure .f1 -width 10 -height 15
    pack .p
    update
    list [winfo width .f1] [winfo height .f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {10 15}
test panedwindow-21.4 {ArrangePanes, panes clipped by size of pane} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red]
	    [frame .f2 -width 20 -height 20 -bg red]
    .p sash place 0 10 0
    pack .p
    update
    list [winfo width .f1] [winfo height .f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {10 20}
test panedwindow-21.5 {ArrangePanes, panes clipped by size of pane} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red]
	    [frame .f2 -width 20 -height 20 -bg red]
    .p sash place 0 0 10
    pack .p
    update
    list [winfo width .f1] [winfo height .f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {20 10}
test panedwindow-21.6 {ArrangePanes, height of pane taken from total height} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .p.f1 -width 20 -height 20 -bg blue] \
            [frame .p.f2 -width 20 -height 40 -bg red] -sticky ""
	    [frame .p.f2 -width 20 -height 40 -bg red] -sticky ""
    pack .p
    update
    winfo y .p.f1
} -cleanup {
    deleteWindows
} -result 10
test panedwindow-21.7 {ArrangePanes, width of pane taken from total width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    .p add [frame .p.f1 -width 20 -height 20 -bg blue] \
            [frame .p.f2 -width 40 -height 40 -bg red] -sticky ""
	    [frame .p.f2 -width 40 -height 40 -bg red] -sticky ""
    pack .p
    update
    winfo x .p.f1
} -cleanup {
    deleteWindows
} -result 10
test panedwindow-21.8 {ArrangePanes, panes with width <= 0 are unmapped} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 40 -bg red]
	    [frame .f2 -width 20 -height 40 -bg red]
    pack .p
    update
    set result [winfo ismapped .f1]
    .p sash place 0 0 0
    update
    lappend result [winfo ismapped .f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 0}
test panedwindow-21.9 {ArrangePanes, panes with width <= 0 are unmapped} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .p.f1 -width 20 -height 20 -bg blue] \
            [frame .p.f2 -width 20 -height 40 -bg red]
	    [frame .p.f2 -width 20 -height 40 -bg red]
    pack .p
    update
    set result [winfo ismapped .p.f1]
    .p sash place 0 0 0
    update
    lappend result [winfo ismapped .p.f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 0}
test panedwindow-21.10 {ArrangePanes, panes with width <= 0 are unmapped} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 -orient vertical
    .p add [frame .p.f1 -width 20 -height 20 -bg blue] \
            [frame .p.f2 -width 20 -height 40 -bg red]
	    [frame .p.f2 -width 20 -height 40 -bg red]
    pack .p
    update
    set result [winfo ismapped .p.f1]
    .p sash place 0 0 0
    update
    lappend result [winfo ismapped .p.f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 0}
test panedwindow-21.11 {ArrangePanes, last pane shrinks} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
	    [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
    place .p -width 40 -x 0 -y 0
    update
    winfo width .f2
} -cleanup {
    deleteWindows
} -result 18
test panedwindow-21.12 {ArrangePanes, last pane shrinks} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -borderwidth 0 -sashpad 0 -sashwidth 2 \
            -orient vertical
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
	    [frame .f2 -width 20 -height 20 -bg red] -sticky nsew
    place .p -height 40 -x 0 -y 0
    update
    winfo height .f2
} -cleanup {
    deleteWindows
} -result 18
test panedwindow-21.13 {ArrangePanes, panedwindow resizes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -width 200 -borderwidth 0
    frame .f1 -height 50 -bg blue
    set result [list]
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
    .p add .f1
    pack .p
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
	panedwindow .p -width 200 -borderwidth 0
	frame .f1 -height 50 -bg blue
	set result [list]
	lappend result [winfo reqwidth .p] [winfo reqheight .p]
	.p add .f1
	pack .p
	lappend result [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
    deleteWindows
} -result {200 1 200 50}
test panedwindow-21.14 {ArrangePanes, panedwindow resizes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -height 200 -borderwidth 0 -orient vertical
    frame .f1 -width 50 -bg blue
    set result [list]
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
    .p add .f1
    pack .p
    lappend result [winfo reqwidth .p] [winfo reqheight .p]
	panedwindow .p -height 200 -borderwidth 0 -orient vertical
	frame .f1 -width 50 -bg blue
	set result [list]
	lappend result [winfo reqwidth .p] [winfo reqheight .p]
	.p add .f1
	pack .p
	lappend result [winfo reqwidth .p] [winfo reqheight .p]
} -cleanup {
    deleteWindows
} -result {1 200 50 200}
test panedwindow-21.15 {ArrangePanes, last pane grows} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -height 50
    .p add [frame .f1 -width 50 -bg red] [frame .f2 -width 50 -bg white] \
            [frame .f3 -width 50 -bg blue] [frame .f4 -width 50 -bg green]
    .p sash place 1 250 0
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
    .p configure -width 300
    update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
	panedwindow .p -showhandle false -height 50
	.p add [frame .f1 -width 50 -bg red] [frame .f2 -width 50 -bg white] \
		[frame .f3 -width 50 -bg blue] [frame .f4 -width 50 -bg green]
	.p sash place 1 250 0
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
	.p configure -width 300
	update
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
} -cleanup {
    deleteWindows
} -result {50 150 1 1 211 50 150 1 89 300}


test panedwindow-22.1 {PanedWindowReqProc, react to pane geometry changes} -setup {
    deleteWindows
test panedwindow-22.1 {PanedWindowReqProc, react to slave geometry changes} -setup {
	deleteWindows
} -body {
    # Basically just want to make sure that the PanedWindowReqProc is called
    panedwindow .p -borderwidth 0 -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 20 -height 20 -bg blue] \
            [frame .f2 -width 20 -height 40 -bg red]
	    [frame .f2 -width 20 -height 40 -bg red]
    set result [winfo reqheight .p]
    .f1 configure -height 80
    lappend result [winfo reqheight .p]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {40 80}
test panedwindow-22.2 {PanedWindowReqProc, react to pane geometry changes} -setup {
    deleteWindows
test panedwindow-22.2 {PanedWindowReqProc, react to slave geometry changes} -setup {
	deleteWindows
} -body {
    panedwindow .p -orient horizontal -sashpad 0 -sashwidth 2
    .p add [frame .f1 -width 10] [frame .f2 -width 10]
    set result [winfo reqwidth .p]
    .f1 configure -width 20
    lappend result [winfo reqwidth .p]
    destroy .p .f1 .f2
    expr {[lindex $result 1] - [lindex $result 0]}
} -cleanup {
    deleteWindows
} -result 10
	deleteWindows
} -result {10}


test panedwindow-23.1 {ConfigurePanes, can't add panedwindow to itself} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add .p
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {can't add .p to itself}
test panedwindow-23.2 {ConfigurePanes, bad window throws error} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add .b
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {bad window path name ".b"}
test panedwindow-23.3 {ConfigurePanes, bad window aborts processing} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .b
    catch {.p add .b .a}
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-23.4 {ConfigurePanes, bad option aborts processing} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .b
    catch {.p add .b -sticky foobar}
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-23.5 {ConfigurePanes, after win isn't managed by panedwin} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .b
    button .c
    .p add .b -after .c
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {window ".c" is not managed by .p}
test panedwindow-23.6 {ConfigurePanes, before win isn't managed by panedwin} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .b
    button .c
    .p add .b -before .c
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {window ".c" is not managed by .p}
test panedwindow-23.7 {ConfigurePanes, -after {} is a no-op} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p paneconfigure .b -after {}
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b .c}
test panedwindow-23.8 {ConfigurePanes, -before {} is a no-op} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p paneconfigure .b -before {}
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b .c}
test panedwindow-23.9 {ConfigurePanes, new panes are added} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c]
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b .c}
test panedwindow-23.10 {ConfigurePanes, options applied to all panes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] [button .c] -sticky ne -height 5 -width 5 -minsize 10
    set result {}
    foreach w {.b .c} {
        set val {}
        foreach option {-sticky -height -width -minsize} {
            lappend val $option [.p panecget $w $option]
        }
        lappend result $w $val
    }
    return $result
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b {-sticky ne -height 5 -width 5 -minsize 10} .c {-sticky ne -height 5 -width 5 -minsize 10}}

test panedwindow-23.11 {ConfigurePanes, existing panes are reconfigured} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b] -sticky nw -height 10
    .p add .b [button .c] -sticky se -height 2
    list [.p panes] [.p panecget .b -sticky] [.p panecget .b -height] \
            [.p panecget .c -sticky] [.p panecget .c -height]
	    [.p panecget .c -sticky] [.p panecget .c -height]
} -cleanup {
    deleteWindows
	deleteWindows
} -result [list {.b .c} es 2 es 2]
test panedwindow-23.12 {ConfigurePanes, widgets added to end by default} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p add [button .b]
    .p add [button .c]
    .p add [button .d]
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b .c .d}
test panedwindow-23.13 {ConfigurePanes, -after, single addition} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c

    .p add .a .b
    .p add .c -after .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .c .b}
test panedwindow-23.14 {ConfigurePanes, -after, multiple additions} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b
    .p add .c .d -after .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .c .d .b}
test panedwindow-23.15 {ConfigurePanes, -after, relocates existing widget} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c .d
    .p add .d -after .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .d .b .c}
test panedwindow-23.16 {ConfigurePanes, -after, relocates existing widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c .d
    .p add .b .d -after .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .b .d .c}
test panedwindow-23.17 {ConfigurePanes, -after, relocates existing widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c .d
    .p add .d .a -after .b
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.b .d .a .c}
test panedwindow-23.18 {ConfigurePanes, -after, relocates existing widgets} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c .d
    .p add .d .a -after .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.d .a .b .c}
test panedwindow-23.19 {ConfigurePanes, -after, after last window} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c
    .p add .d -after .c
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .b .c .d}
test panedwindow-23.20 {ConfigurePanes, -before, before first window} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c
    .p add .d -before .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.d .a .b .c}
test panedwindow-23.21 {ConfigurePanes, -before, relocate existing windows} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .a
    button .b
    button .c
    button .d

    .p add .a .b .c
    .p add .d .b -before .a
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.d .b .a .c}
test panedwindow-23.22 {ConfigurePanes, pane specified multiple times} -setup {
    deleteWindows
test panedwindow-23.22 {ConfigurePanes, slave specified multiple times} -setup {
	deleteWindows
} -body {
    # This test should not cause a core dump

    panedwindow .p
    button .a
    button .b
    button .c

    .p add .a .a .b .c
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.a .b .c}
test panedwindow-23.23 {ConfigurePanes, pane specified multiple times} -setup {
    deleteWindows
test panedwindow-23.23 {ConfigurePanes, slave specified multiple times} -setup {
	deleteWindows
} -body {
    # This test should not cause a core dump

    panedwindow .p
    button .a
    button .b
    button .c

    .p add .a .a .b .c
    .p add .a .b .a -after .c
    .p panes
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.c .a .b}
test panedwindow-23.24 {ConfigurePanes, panedwindow cannot manage toplevels} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    toplevel .t
    .p add .t
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {can't add toplevel .t to .p}
test panedwindow-23.25 {ConfigurePanes, restrict possible panes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    frame .f
    button .f.b
   .p add .f.b
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {can't add .f.b to .p}
test panedwindow-23.26 {ConfigurePanes, restrict possible panes} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f
    panedwindow .f.p
    button .b
    .f.p add .b
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-23.27 {ConfigurePanes, restrict possible panes} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    button .p.b
    .p add .p.b
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-23.28 {ConfigurePanes, restrict possible panes} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f
    frame .f.f
    frame .f.f.f
    panedwindow .f.f.f.p
    button .b
    .f.f.f.p add .b
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-23.29 {ConfigurePanes, -hide works} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false
    frame .f1 -width 40 -height 100 -bg red
    frame .f2 -width 40 -height 100 -bg white
    frame .f3 -width 40 -height 100 -bg blue
    frame .f4 -width 40 -height 100 -bg green
    .p add .f1 .f2 .f3 .f4
    pack .p
    update
    set result [list]
    lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
            [winfo ismapped .f3] [winfo ismapped .f4]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
            [winfo ismapped .f3] [winfo ismapped .f4]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
	panedwindow .p -showhandle false
	frame .f1 -width 40 -height 100 -bg red
	frame .f2 -width 40 -height 100 -bg white
	frame .f3 -width 40 -height 100 -bg blue
	frame .f4 -width 40 -height 100 -bg green
	.p add .f1 .f2 .f3 .f4
	pack .p
	update
	set result [list]
	lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
		[winfo ismapped .f3] [winfo ismapped .f4]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
		[winfo ismapped .f3] [winfo ismapped .f4]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
} -cleanup {
    deleteWindows
} -result {1 1 1 1 40 40 40 40 171 1 0 1 1 40 40 40 40 128}
test panedwindow-23.30 {ConfigurePanes, -hide works} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -width 130 -height 100
    frame .f1 -width 40 -bg red
    frame .f2 -width 40 -bg white
    frame .f3 -width 40 -bg blue
    frame .f4 -width 40 -bg green
    .p add .f1 .f2 .f3 .f4
    pack .p
    update
    set result [list]
    lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
            [winfo ismapped .f3] [winfo ismapped .f4]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
            [winfo ismapped .f3] [winfo ismapped .f4]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4] [winfo width .p]
	panedwindow .p -showhandle false -width 130 -height 100
	frame .f1 -width 40 -bg red
	frame .f2 -width 40 -bg white
	frame .f3 -width 40 -bg blue
	frame .f4 -width 40 -bg green
	.p add .f1 .f2 .f3 .f4
	pack .p
	update
	set result [list]
	lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
		[winfo ismapped .f3] [winfo ismapped .f4]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo ismapped .f1] [winfo ismapped .f2] \
		[winfo ismapped .f3] [winfo ismapped .f4]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4] [winfo width .p]
} -cleanup {
    deleteWindows
} -result {1 1 1 0 39 40 40 1 130 1 0 1 1 40 40 40 42 130}
test panedwindow-23.30a {ConfigurePanes, hidden panes are unmapped} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p1 -sashrelief raised
    panedwindow .p2 -sashrelief raised
    label .l1 -text Label1
    label .l2 -text Label2
    label .l3 -text Label3
    .p2 add .l2 -sticky nsew
    .p2 add .l3 -sticky nsew
    .p1 add .p2 -sticky nsew
    .p1 add .l1 -sticky nsew
    pack .p1 -side top -expand 1 -fill both
    update
    set result [list]
    lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
            [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
	update
	set result [list]
	lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
		    [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
    .p2 paneconfigure .l1 -hide 1
    update
    lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
            [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
	update
	lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
		    [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
    .p1 paneconfigure .p2 -hide 1
    update
    lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
            [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
	update
	lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
		    [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
    .p1 paneconfigure .p2 -hide 0
    update
    lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
            [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
	update
	lappend result [list [winfo ismapped .p1] [winfo ismapped .p2] \
		    [winfo ismapped .l1] [winfo ismapped .l2] [winfo ismapped .l3]]
} -cleanup {
    deleteWindows
} -result {{1 1 1 1 1} {1 1 0 1 1} {1 0 0 0 0} {1 1 0 1 1}}
test panedwindow-23.31 {ConfigurePanes, -hide works, last pane stretches} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -width 200 -height 200 -borderwidth 0
    frame .f1 -width 50 -bg red
    frame .f2 -width 50 -bg green
    frame .f3 -width 50 -bg blue
    .p add .f1 .f2 .f3
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3]
    .p paneconfigure .f2 -hide 1
    update
	panedwindow .p -showhandle false -width 200 -height 200 -borderwidth 0
	frame .f1 -width 50 -bg red
	frame .f2 -width 50 -bg green
	frame .f3 -width 50 -bg blue
	.p add .f1 .f2 .f3
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3]
	.p paneconfigure .f2 -hide 1
	update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3]
} -cleanup {
    deleteWindows
} -result {50 50 94 50 50 147}
test panedwindow-23.32 {ConfigurePanes, -hide works, last pane stretches} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -width 200 -height 200 \
            -borderwidth 0 -orient vertical
    frame .f1 -height 50 -bg red
    frame .f2 -height 50 -bg green
    frame .f3 -height 50 -bg blue
    .p add .f1 .f2 .f3
    pack .p
    update
    set result [list]
    lappend result [winfo height .f1] [winfo height .f2] [winfo height .f3]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo height .f1] [winfo height .f2] [winfo height .f3]
	panedwindow .p -showhandle false -width 200 -height 200 \
		-borderwidth 0 -orient vertical
	frame .f1 -height 50 -bg red
	frame .f2 -height 50 -bg green
	frame .f3 -height 50 -bg blue
	.p add .f1 .f2 .f3
	pack .p
	update
	set result [list]
	lappend result [winfo height .f1] [winfo height .f2] [winfo height .f3]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo height .f1] [winfo height .f2] [winfo height .f3]
} -cleanup {
    deleteWindows
} -result {50 50 94 50 50 147}

test panedwindow-23.33 {ConfigurePanes, -stretch first} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -height 100 -width 182
    frame .f1 -width 40 -bg red
    frame .f2 -width 40 -bg white
    frame .f3 -width 40 -bg blue
    frame .f4 -width 40 -bg green
    .p add .f1 .f2 .f3 .f4 -stretch first
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
	panedwindow .p -showhandle false -height 100 -width 182
	frame .f1 -width 40 -bg red
	frame .f2 -width 40 -bg white
	frame .f3 -width 40 -bg blue
	frame .f4 -width 40 -bg green
	.p add .f1 .f2 .f3 .f4 -stretch first
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
} -cleanup {
    deleteWindows
} -result {51 40 40 40 94 40 40 40}
test panedwindow-23.34 {ConfigurePanes, -stretch middle} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -height 100 -width 182
    frame .f1 -width 40 -bg red
    frame .f2 -width 40 -bg white
    frame .f3 -width 40 -bg blue
    frame .f4 -width 40 -bg green
    .p add .f1 .f2 .f3 .f4 -stretch middle
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
	panedwindow .p -showhandle false -height 100 -width 182
	frame .f1 -width 40 -bg red
	frame .f2 -width 40 -bg white
	frame .f3 -width 40 -bg blue
	frame .f4 -width 40 -bg green
	.p add .f1 .f2 .f3 .f4 -stretch middle
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
} -cleanup {
    deleteWindows
} -result {40 45 46 40 40 45 94 40}
test panedwindow-23.35 {ConfigurePanes, -stretch always} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -height 100 -width 182
    frame .f1 -width 40 -bg red
    frame .f2 -width 40 -bg white
    frame .f3 -width 40 -bg blue
    frame .f4 -width 40 -bg green
    .p add .f1 .f2 .f3 .f4 -stretch always
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
	panedwindow .p -showhandle false -height 100 -width 182
	frame .f1 -width 40 -bg red
	frame .f2 -width 40 -bg white
	frame .f3 -width 40 -bg blue
	frame .f4 -width 40 -bg green
	.p add .f1 .f2 .f3 .f4 -stretch always
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
} -cleanup {
    deleteWindows
} -result {42 43 43 43 58 43 58 58}
test panedwindow-23.36 {ConfigurePanes, -stretch never} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -height 100 -width 182
    frame .f1 -width 40 -bg red
    frame .f2 -width 40 -bg white
    frame .f3 -width 40 -bg blue
    frame .f4 -width 40 -bg green
    .p add .f1 .f2 .f3 .f4 -stretch never
    pack .p
    update
    set result [list]
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
    .p paneconfigure .f2 -hide 1
    update
    lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
            [winfo width .f4]
	panedwindow .p -showhandle false -height 100 -width 182
	frame .f1 -width 40 -bg red
	frame .f2 -width 40 -bg white
	frame .f3 -width 40 -bg blue
	frame .f4 -width 40 -bg green
	.p add .f1 .f2 .f3 .f4 -stretch never
	pack .p
	update
	set result [list]
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
	.p paneconfigure .f2 -hide 1
	update
	lappend result [winfo width .f1] [winfo width .f2] [winfo width .f3] \
		[winfo width .f4]
} -cleanup {
    deleteWindows
} -result {40 40 40 40 40 40 40 40}


test panedwindow-24.1 {Unlink, remove a paned with -before/-after refs} -setup {
    deleteWindows
	deleteWindows
} -body {
    # Bug 928413
    set result {}
    panedwindow .pw
    label .pw.l1 -text Label1
    label .pw.l2 -text Label2
    label .pw.l3 -text Label3
    .pw add .pw.l1
    .pw add .pw.l3
    .pw add .pw.l2 -before .pw.l3
    lappend result [.pw panecget .pw.l2 -before]
    destroy .pw.l3
    lappend result [.pw panecget .pw.l2 -before]
    .pw paneconfigure .pw.l2 -before .pw.l1
    lappend result [.pw panecget .pw.l2 -before]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {.pw.l3 {} .pw.l1}


test panedwindow-25.1 {DestroyPanedWindow} -setup {
    deleteWindows
	deleteWindows
} -body {
    # This test should not result in any memory leaks.
    panedwindow .p
    foreach w {.a .b .c .d .e .f .g .h .i .j .k .l .m .n .o .q .r .s .t} {
        .p add [button $w]
	    .p add [button $w]
    }
    foreach w {.a .b .c .d .e .f .g .h .i .j .k .l .m .n .o .p .q .r .s .t} {
        destroy $w
	    destroy $w
    }
    set result {}
} -result {}
test panedwindow-25.2 {UnmapNotify and MapNotify events are propagated to panes} -setup {
test panedwindow-25.2 {UnmapNotify and MapNotify events are propagated to slaves} -setup {
    deleteWindows
} -body {
    panedwindow .pw
    .pw add [button .pw.b]
    pack .pw
    update
    set result [winfo ismapped .pw.b]
    pack forget .pw
    update
    lappend result [winfo ismapped .pw.b]
    lappend result [winfo ismapped .pw]
    pack .pw
    update
    lappend result [winfo ismapped .pw]
    lappend result [winfo ismapped .pw.b]
    destroy .pw .pw.b
    set result
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 0 0 1 1}


test panedwindow-26.1 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.2 {PanedWindowIdentifyCoords, padding is included} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 20 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.3 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 22 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.4 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 24 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.5 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 26 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.6 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 26 -1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.7 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 26 100
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.8 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 6
	    -handlesize 6
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 22 4
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.9 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 6
	    -handlesize 6
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 22 5
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 handle}
test panedwindow-26.10 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 8
	    -handlesize 8
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 20 5
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 handle}
test panedwindow-26.11 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 8
	    -handlesize 8
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 20 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.12 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -bd 0 -sashwidth 2 -sashpad 2
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20] \
            [frame .f3 -bg green -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20] \
	    [frame .f3 -bg green -width 20 -height 20]
    .p identify 48 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 sash}
test panedwindow-26.13 {identify subcommand errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -borderwidth 0 -sashpad 2 -sashwidth 4
    .p identify
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {wrong # args: should be ".p identify x y"}
test panedwindow-26.14 {identify subcommand errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p identify foo bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "foo"}
test panedwindow-26.15 {identify subcommand errors} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p
    .p identify 0 bar
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {expected integer but got "bar"}
test panedwindow-26.16 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 0
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.17 {PanedWindowIdentifyCoords, padding is included} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 20
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.18 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 22
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.19 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 24
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.20 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 26
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.21 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify -1 26
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.22 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 100 26
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test panedwindow-26.23 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 6 -orient vertical
	    -handlesize 6 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 4 22
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.24 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 6 -orient vertical
	    -handlesize 6 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 5 22
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 handle}
test panedwindow-26.25 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 8 -orient vertical
	    -handlesize 8 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 5 20
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 handle}
test panedwindow-26.26 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 0 -sashwidth 2 -sashpad 2 -showhandle 1 -handlepad 5 \
            -handlesize 8 -orient vertical
	    -handlesize 8 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20]
    .p identify 0 20
} -cleanup {
    deleteWindows
	deleteWindows
} -result {0 sash}
test panedwindow-26.27 {PanedWindowIdentifyCoords} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -showhandle false -bd 0 -sashwidth 2 -sashpad 2 -orient vertical
    .p add [frame .f -bg red -width 20 -height 20] \
            [frame .f2 -bg blue -width 20 -height 20] \
            [frame .f3 -bg green -width 20 -height 20]
	    [frame .f2 -bg blue -width 20 -height 20] \
	    [frame .f3 -bg green -width 20 -height 20]
    .p identify 0 48
} -cleanup {
    deleteWindows
	deleteWindows
} -result {1 sash}


test panedwindow-27.1 {destroy the window cleanly on error [Bug #616589]} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bogusopt bogus
} -cleanup {
    deleteWindows
	deleteWindows
} -returnCodes error -result {unknown option "-bogusopt"}
test panedwindow-27.2 {destroy the window cleanly on rename [Bug #616589]} -setup {
    deleteWindows
	deleteWindows
} -body {
    destroy .p
    panedwindow .p
    rename .p {}
    winfo exists .p
} -cleanup {
    deleteWindows
} -result 0
	deleteWindows
} -result {0}


test panedwindow-28.1 {resizing width} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -bd 5
    frame .f1 -width 100 -height 50 -bg blue
    frame .f2 -width 100 -height 50 -bg red

    .p add .f1 -sticky news
    .p add .f2 -sticky news
5484
5485
5486
5487
5488
5489
5490
5491

5492
5493
5494
5495
5496
5497
5498
5484
5485
5486
5487
5488
5489
5490

5491
5492
5493
5494
5495
5496
5497
5498







-
+







    update
    set b "$a [winfo width .f2]"
} -cleanup {
    deleteWindows
} -result {100 110}

test panedwindow-28.2 {resizing height} -setup {
    deleteWindows
	deleteWindows
} -body {
    panedwindow .p -orient vertical -bd 5
    frame .f1 -width 50 -height 100 -bg blue
    frame .f2 -width 50 -height 100 -bg red

    .p add .f1 -sticky news
    .p add .f2 -sticky news
5510
5511
5512
5513
5514
5515
5516
5517

5518
5519
5520
5521
5522
5523





5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541










5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5510
5511
5512
5513
5514
5515
5516

5517
5518





5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531










5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551







-
+

-
-
-
-
-
+
+
+
+
+








-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+










    deleteWindows
} -result {100 110}


test panedwindow-29.1 {display on depths other than the default one} -constraints {
    pseudocolor8 haveTruecolor24
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -visual {truecolor 24}
    pack [panedwindow .t.p]
    .t.p add [frame .t.p.f1] [frame .t.p.f2]
    update
    # If we got here, we didn't crash and that's good
	toplevel .t -visual {truecolor 24}
	pack [panedwindow .t.p]
	.t.p add [frame .t.p.f1] [frame .t.p.f2]
	update
	# If we got here, we didn't crash and that's good
} -cleanup {
    deleteWindows
} -result {}
test panedwindow-29.2 {display on depths other than the default one} -constraints {
    pseudocolor8 haveTruecolor24
} -setup {
    deleteWindows
} -body {
    toplevel .t -visual {pseudocolor 8}
    pack [frame .t.f -visual {truecolor 24}]
    pack [panedwindow .t.f.p]
    .t.f.p add [frame .t.f.p.f1 -width 5] [frame .t.f.p.f2 -width 5]
    update
    .t.f.p proxy place 1 1
    update
    .t.f.p proxy forget
    update
    # If we got here, we didn't crash and that's good
	toplevel .t -visual {pseudocolor 8}
	pack [frame .t.f -visual {truecolor 24}]
	pack [panedwindow .t.f.p]
	.t.f.p add [frame .t.f.p.f1 -width 5] [frame .t.f.p.f2 -width 5]
	update
	.t.f.p proxy place 1 1
	update
	.t.f.p proxy forget
	update
	# If we got here, we didn't crash and that's good
} -cleanup {
    deleteWindows
} -result {}


# cleanup
cleanupTests
return


Deleted tests/pkgconfig.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67



































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# -*- tcl -*-
# Commands covered:  pkgconfig
#
# This file contains a collection of tests for one or more of the Tk
# built-in commands.  Sourcing this file into Tk runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1991-1993 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2017 Stuart Cassoff <[email protected]>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

test pkgconfig-1.1 {query keys} -constraints {nonwin} -body {
    lsort [::tk::pkgconfig list]
} -match glob -result [list \
    *bindir,install bindir,runtime *demodir,install \
    demodir,runtime*docdir,install docdir,runtime fontsystem \
    includedir,install includedir,runtime \
    libdir,install libdir,runtime*\
    scriptdir,install scriptdir,runtime*\
]
test pkgconfig-1.2 {query keys multiple times} {
    string compare [::tk::pkgconfig list] [::tk::pkgconfig list]
} 0
test pkgconfig-1.3 {query value multiple times} {
    string compare \
	    [::tk::pkgconfig get fontsystem] \
	    [::tk::pkgconfig get fontsystem]
} 0


test pkgconfig-2.0 {error: missing subcommand} {
    catch {::tk::pkgconfig} msg
    set msg
} {wrong # args: should be "::tk::pkgconfig subcommand ?arg?"}
test pkgconfig-2.1 {error: illegal subcommand} {
    catch {::tk::pkgconfig foo} msg
    set msg
} {bad subcommand "foo": must be get or list}
test pkgconfig-2.2 {error: list with arguments} {
    catch {::tk::pkgconfig list foo} msg
    set msg
} {wrong # args: should be "::tk::pkgconfig list"}
test pkgconfig-2.3 {error: get without arguments} {
    catch {::tk::pkgconfig get} msg
    set msg
} {wrong # args: should be "::tk::pkgconfig get key"}
test pkgconfig-2.4 {error: query unknown key} {
    catch {::tk::pkgconfig get foo} msg
    set msg
} {key not known}
test pkgconfig-2.5 {error: query with to many arguments} {
    catch {::tk::pkgconfig get foo bar} msg
    set msg
} {wrong # args: should be "::tk::pkgconfig subcommand ?arg?"}

# cleanup
cleanupTests
return

Changes to tests/place.test.

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3


4
5
6
7
8
9
10
11
12
13
14
15



16
17
18
19
20
21
22



-
-
+
+










-
-
-







# This file is a Tcl script to test out the "place" command.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Used for constraining memory leak tests
testConstraint memory [llength [info commands memory]]

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# XXX - This test file is woefully incomplete.  At present, only a
# few of the features are tested.

# Widgets used in tests 1.* - 8.*
toplevel .t -width 300 -height 200 -bd 0
wm geom .t +0+0
frame .t.f -width 154 -height 84 -bd 2 -relief raised
52
53
54
55
56
57
58
59

60
61
62


63
64
65
66
67
68
69


70
71
72
73
74
75
76
77

78
79
80

81
82
83


84
85
86
87
88
89
90


91
92
93
94
95
96
97
98

99
100
101

102
103
104
105
106


107
108
109
110
111
112
113

114
115
116
117
118
119


120
121
122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148


149
150
151
152
153
154
155


156
157
158
159
160
161
162
163

164
165

166
167
168


169
170
171
172
173
174
175


176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
49
50
51
52
53
54
55

56
57


58
59
60
61
62
63
64


65
66
67
68
69
70
71
72
73

74
75
76

77
78


79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94

95
96
97

98
99
100
101


102
103
104
105
106
107
108
109

110
111
112
113
114


115
116
117
118
119


120
121



















122

123
124


125
126
127
128
129
130
131


132
133
134
135
136
137
138
139
140

141
142

143
144


145
146
147
148
149
150
151


152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168







-
+

-
-
+
+





-
-
+
+







-
+


-
+

-
-
+
+





-
-
+
+







-
+


-
+



-
-
+
+






-
+




-
-
+
+



-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
-
+
+





-
-
+
+







-
+

-
+

-
-
+
+





-
-
+
+







-
+







        -bordermode ignore
    place info .t.f2
} -cleanup {
    destroy ".t.a.b"
} -result {-in {.t.a b} -x 1 -relx 0.2 -y 2 -rely 0.2 -width {} -relwidth 0.3 -height 4 -relheight {} -anchor w -bordermode ignore}


test place-2.1 {ConfigureContent procedure, -height option} -body {
test place-2.1 {ConfigureSlave procedure, -height option} -body {
    place .t.f2 -height abcd
} -returnCodes error -result {expected screen distance or "" but got "abcd"}
test place-2.2 {ConfigureContent procedure, -height option} -setup {
} -returnCodes error -result {bad screen distance "abcd"}
test place-2.2 {ConfigureSlave procedure, -height option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -height 40
    update
    winfo height .t.f2
} -result 40
test place-2.3 {ConfigureContent procedure, -height option} -setup {
} -result {40}
test place-2.3 {ConfigureSlave procedure, -height option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -height 120
    update
    place .t.f2 -height {}
    update
    winfo height .t.f2
} -result 60
} -result {60}


test place-3.1 {ConfigureContent procedure, -relheight option} -body {
test place-3.1 {ConfigureSlave procedure, -relheight option} -body {
    place .t.f2 -relheight abcd
} -returnCodes error -result {expected floating-point number or "" but got "abcd"}
test place-3.2 {ConfigureContent procedure, -relheight option} -setup {
} -returnCodes error -result {expected floating-point number but got "abcd"}
test place-3.2 {ConfigureSlave procedure, -relheight option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -relheight .5
    update
    winfo height .t.f2
} -result 40
test place-3.3 {ConfigureContent procedure, -relheight option} -setup {
} -result {40}
test place-3.3 {ConfigureSlave procedure, -relheight option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -relheight .8
    update
    place .t.f2 -relheight {}
    update
    winfo height .t.f2
} -result 60
} -result {60}


test place-4.1 {ConfigureContent procedure, bad -in options} -setup {
test place-4.1 {ConfigureSlave procedure, bad -in options} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f2
} -returnCodes error -result {can't place ".t.f2" relative to itself}
test place-4.2 {ConfigureContent procedure, bad -in option} -setup {
} -returnCodes error -result {can't place .t.f2 relative to itself}
test place-4.2 {ConfigureSlave procedure, bad -in option} -setup {
    place forget .t.f2
} -body {
    set result [list [winfo manager .t.f2]]
    catch {place .t.f2 -in .t.f2}
    lappend result [winfo manager .t.f2]
} -result {{} {}}
test place-4.3 {ConfigureContent procedure, bad -in option} -setup {
test place-4.3 {ConfigureSlave procedure, bad -in option} -setup {
    place forget .t.f2
} -body {
    winfo manager .t.f2
    place .t.f2 -in .t.f2
} -returnCodes error -result {can't place ".t.f2" relative to itself}
test place-4.4 {ConfigureContent procedure, bad -in option} -setup {
} -returnCodes error -result {can't place .t.f2 relative to itself}
test place-4.4 {ConfigureSlave procedure, bad -in option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .
} -returnCodes error -result {can't place ".t.f2" relative to "."}
test place-4.5 {ConfigureContent procedure, bad -in option} -setup {
} -returnCodes error -result {can't place .t.f2 relative to .}

} -body {
    frame .t.f1
    place .t.f1 -in .t.f1
} -returnCodes error -result {can't place ".t.f1" relative to itself}
test place-4.6 {prevent management loops} -setup {
    place forget .t.f1
} -body {
    place .t.f1 -in .t.f2
    place .t.f2 -in .t.f1
} -returnCodes error -result {can't put ".t.f2" inside ".t.f1": would cause management loop}
test place-4.7 {prevent management loops} -setup {
    place forget .t.f1
    place forget .t.f2
} -body {
    frame .t.f3
    place .t.f1 -in .t.f2
    place .t.f2 -in .t.f3
    place .t.f3 -in .t.f1
} -returnCodes error -result {can't put ".t.f3" inside ".t.f1": would cause management loop}

test place-5.1 {ConfigureContent procedure, -relwidth option} -body {
test place-5.1 {ConfigureSlave procedure, -relwidth option} -body {
    place .t.f2 -relwidth abcd
} -returnCodes error -result {expected floating-point number or "" but got "abcd"}
test place-5.2 {ConfigureContent procedure, -relwidth option} -setup {
} -returnCodes error -result {expected floating-point number but got "abcd"}
test place-5.2 {ConfigureSlave procedure, -relwidth option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -relwidth .5
    update
    winfo width .t.f2
} -result 75
test place-5.3 {ConfigureContent procedure, -relwidth option} -setup {
} -result {75}
test place-5.3 {ConfigureSlave procedure, -relwidth option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -relwidth .8
    update
    place .t.f2 -relwidth {}
    update
    winfo width .t.f2
} -result 30
} -result {30}

test place-6.1 {ConfigureContent procedure, -width option} -body {
test place-6.1 {ConfigureSlave procedure, -width option} -body {
    place .t.f2 -width abcd
} -returnCodes error -result {expected screen distance or "" but got "abcd"}
test place-6.2 {ConfigureContent procedure, -width option} -setup {
} -returnCodes error -result {bad screen distance "abcd"}
test place-6.2 {ConfigureSlave procedure, -width option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -width 100
    update
    winfo width .t.f2
} -result 100
test place-6.3 {ConfigureContent procedure, -width option} -setup {
} -result {100}
test place-6.3 {ConfigureSlave procedure, -width option} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -width 120
    update
    place .t.f2 -width {}
    update
    winfo width .t.f2
} -result 30
} -result {30}


test place-7.1 {ReconfigurePlacement procedure, computing position} -setup {
    place forget .t.f2
} -body {
    place .t.f2 -in .t.f -x -2 -relx .5 -y 3 -rely .4
    update
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281

282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
235
236
237
238
239
240
241









242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276







-
-
-
-
-
-
-
-
-

-
+







+








-
+








+







} -body {
    place .t.f2 -in .t.f -width 10 -relwidth .4 -height -4 -relheight .5
    place .t.f2 -width {} -relwidth {} -height {} -relheight {}
    update
    list [winfo width .t.f2] [winfo height .t.f2]
} -result {30 60}

# Tests place-8.1 and place-8.2 are constrained with failsOnUbuntu
# because they are failing in the GitHub CI environment, using Linux Ubuntu.
# These tests are also constrained with failsOnXQuarz because they fail
# on macOS when building with clang --disable-aqua (which uses XQuartz)
# (this is the case both at GitHub CI and on a real Mac).
# Analysis shows that, on both cases, WaitForMapNotify is giving up on
# waiting for the MapNotify event that should show up when running
# 'wm iconify'. The timeout delay (2s) is exceeded without the unmapping
# having happened. The cause for this is unknown (see comments in WaitForMapNotify).

test place-8.1 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test place-8.1 {MasterStructureProc, mapping and unmapping slaves} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f2 -relx 1.0 -rely 1.0 -anchor sw
    update
    set result [winfo ismapped .t.f2]
    wm iconify .t
    update
    lappend result [winfo ismapped .t.f2]
    place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
    update
    lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
    wm deiconify .t
    update
    lappend result [winfo ismapped .t.f2]
} -result {1 0 40 30 0 1}
test place-8.2 {PlaceStructureProc, mapping and unmapping content} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test place-8.2 {MasterStructureProc, mapping and unmapping slaves} -setup {
    place forget .t.f2
    place forget .t.f
} -body {
    place .t.f -x 0 -y 0 -width 200 -height 100
    place .t.f2 -in .t.f -relx 1.0 -rely 1.0 -anchor sw -width 50 -height 20
    update
    set result [winfo ismapped .t.f2]
    wm iconify .t
    update
    lappend result [winfo ismapped .t.f2]
    place .t.f2 -x 40 -y 30 -relx 0 -rely 0 -anchor nw
    update
    lappend result [winfo x .t.f2] [winfo y .t.f2] [winfo ismapped .t.f2]
    wm deiconify .t
    update
    lappend result [winfo ismapped .t.f2]
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
299
300
301
302
303
304
305

306
307
308
309
310
311
312
313







-
+







test place-9.5 {PlaceObjCmd} -setup {
    destroy .foo
} -body {
    frame .foo
    place badopt .foo
} -cleanup {
    destroy .foo
} -returnCodes error -result {bad option "badopt": must be configure, content, forget, or info}
} -returnCodes error -result {bad option "badopt": must be configure, forget, info, or slaves}
test place-9.6 {PlaceObjCmd, configure errors} -setup {
    destroy .foo
} -body {
    frame .foo
    place configure .foo
} -cleanup {
    destroy .foo
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338







-
+







    destroy .foo
} -body {
    frame .foo
    place .foo -x 0 -y 0
    place configure .foo
} -cleanup {
    destroy .foo
} -result [list {-anchor {} {} nw nw} {-bordermode {} {} inside inside} {-height {} {} {} {}} {-in {} {} {} .} {-relheight {} {} {} {}} {-relwidth {} {} {} {}} {-relx {} {} 0.0 0.0} {-rely {} {} 0.0 0.0} {-width {} {} {} {}} {-x {} {} 0 0} {-y {} {} 0 0}]
} -result [list {-anchor {} {} nw nw} {-bordermode {} {} inside inside} {-height {} {} {} {}} {-in {} {} {} .} {-relheight {} {} {} {}} {-relwidth {} {} {} {}} {-relx {} {} 0 0.0} {-rely {} {} 0 0.0} {-width {} {} {} {}} {-x {} {} 0 0} {-y {} {} 0 0}]
test place-9.9 {PlaceObjCmd, configure} -setup {
    destroy .foo
} -body {
    frame .foo
    place .foo -x 0 -y 0
    place configure .foo -x
} -cleanup {
379
380
381
382
383
384
385
386

387
388
389
390

391
392
393

394
395
396

397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420


421
422
423
424
425
426
427
428
429
430

431
432
433
434

435
436
437
438

439
440
441
442
443
444

445
446
447
448
449
450
451
350
351
352
353
354
355
356

357
358
359
360

361
362
363

364
365
366

367
368
369
370
371
372
373
374

375
376
377
378
379
380
381
382

383
384
385
386
387
388
389


390
391
392
393
394
395
396
397
398
399
400

401
402
403
404

405
406
407
408

409
410
411
412
413
414

415
416
417
418
419
420
421
422







-
+



-
+


-
+


-
+







-
+







-
+






-
-
+
+









-
+



-
+



-
+





-
+







    destroy .foo
} -body {
    frame .foo
    place info .foo bar
} -cleanup {
    destroy .foo
} -returnCodes error -result {wrong # args: should be "place info pathName"}
test place-9.12 {PlaceObjCmd, content errors} -setup {
test place-9.12 {PlaceObjCmd, slaves errors} -setup {
    destroy .foo
} -body {
    frame .foo
    place content .foo bar
    place slaves .foo bar
} -cleanup {
    destroy .foo
} -returnCodes error -result {wrong # args: should be "place content pathName"}
} -returnCodes error -result {wrong # args: should be "place slaves pathName"}


test place-10.1 {ConfigureContent} -setup {
test place-10.1 {ConfigureSlave} -setup {
    destroy .foo
} -body {
    frame .foo
    place .foo -badopt
} -cleanup {
    destroy .foo
} -returnCodes error -result {unknown option "-badopt"}
test place-10.2 {ConfigureContent} -setup {
test place-10.2 {ConfigureSlave} -setup {
    destroy .foo
} -body {
    frame .foo
    place .foo -anchor
} -cleanup {
    destroy .foo
} -returnCodes error -result {value for "-anchor" missing}
test place-10.3 {ConfigureContent} -setup {
test place-10.3 {ConfigureSlave} -setup {
    destroy .foo
} -body {
    frame .foo
    place .foo -bordermode j
} -cleanup {
    destroy .foo
} -returnCodes error -result {bad bordermode "j": must be inside, ignore, or outside}
test place-10.4 {ConfigureContent} -setup {
} -returnCodes error -result {bad bordermode "j": must be inside, outside, or ignore}
test place-10.4 {ConfigureSlave} -setup {
    destroy .foo
} -body {
    frame .foo
    place configure .foo -x 0 -y
} -cleanup {
    destroy .foo
} -returnCodes error -result {value for "-y" missing}


test place-11.1 {PlaceObjCmd, content command} -setup {
test place-11.1 {PlaceObjCmd, slaves command} -setup {
    destroy .foo
} -body {
    frame .foo
    place content .foo
    place slaves .foo
} -cleanup {
    destroy .foo
} -result {}
test place-11.2 {PlaceObjCmd, content command} -setup {
test place-11.2 {PlaceObjCmd, slaves command} -setup {
    destroy .foo .bar
} -body {
    frame .foo
    frame .bar
    place .bar -in .foo
    place content .foo
    place slaves .foo
} -cleanup {
    destroy .foo .bar
} -result [list .bar]


test place-12.1 {PlaceObjCmd, forget command} -setup {
    destroy .foo
499
500
501
502
503
504
505
506

507
508
509
510
511


512
513
514


515
516
517
518
519
520




521
522
523
524
525
526
527
470
471
472
473
474
475
476

477
478
479
480


481
482
483


484
485

486




487
488
489
490
491
492
493
494
495
496
497







-
+



-
-
+
+

-
-
+
+
-

-
-
-
-
+
+
+
+







                set end [getbytes]
            }
            lappend res [expr {$end - $tmp}]
        }
        return $res
    }
} -body {
    # Test all manners of forgetting content
    # Test all manners of forgetting a slave
    frame .f
    frame .f.f
    stress {
	place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
	place forget .f.f
        place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
        place forget .f.f
    } {
	place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
	pack .f.f
        place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
        pack .f.f
	update; # Needed because of TIP #518, handle <<NoManagedChild>> event.
    } {
	place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
	destroy .f
	frame .f
	frame .f.f
        place .f.f -x [expr {1 + 1}] -y [expr {2 + 2}]
        destroy .f
        frame .f
        frame .f.f
    }
} -cleanup {
    destroy .f
    rename getbytes {}
    rename stress {}
} -result {0 0 0}

Changes to tests/raise.test.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19

20

21

22
23
24
25
26
27
28
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21

22
23
24
25
26
27
28
29





-
-
-
+
+
+











+
-
+
-
+







# This file is a Tcl script to test out Tk's "raise" and
# "lower" commands, plus associated code to manage window
# stacking order.  It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1993-1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1993-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# Procedure to create a bunch of overlapping windows, which should
# make it easy to detect differences in order.

proc raise_setup {} {
    foreach i [winfo child .raise] {
    destroy {*}[winfo children .raise]
	        destroy $i
    update idletasks
        }
    foreach i {a b c d e} {
	    label .raise.$i -text $i -relief raised -bd 2
    }
    place .raise.a -x 20 -y 60 -width 60 -height 80
    place .raise.b -x 60 -y 60 -width 60 -height 80
    place .raise.c -x 100 -y 60 -width 60 -height 80
    place .raise.d -x 40 -y 20 -width 100 -height 60

Deleted tests/red.gif.

cannot compute difference between binary files

Changes to tests/safe.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test the Safe Tk facility. It is organized in
# the standard fashion for Tk tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

24
25
26
27
28
29
30
31

32
33
34
35
36
37

38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59






60
61
62


63
64
65
66
67
68
69
24
25
26
27
28
29
30

31
32
33
34
35


36



37



38















39
40
41
42
43
44
45


46
47
48
49
50
51
52
53
54







-
+




-
-
+
-
-
-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+







#     invoked from within
# "uplevel #0 [list source $file]"
#
#
# This probably means that tk wasn't installed properly.

## it indicates that something went wrong sourcing tk.tcl.
## Ensure that any changes that occurred to tk.tcl will work or are properly
## Ensure that any changes that occured to tk.tcl will work or are properly
## prevented in a safe interpreter.  -- hobbs

# The set of hidden commands is platform dependent:

set hidden_cmds [list bell cd clipboard encoding exec exit \
	fconfigure glob grab load menu open pwd selection \
set hidden_cmds {bell cd clipboard encoding exec exit fconfigure glob grab load menu open pwd selection socket source tcl:encoding:dirs toplevel unload wm}
	socket source toplevel unload wm]
if {[package vsatisfies [package provide Tcl] 8.6.7-]} {
    lappend hidden_cmds tcl:encoding:dirs
lappend hidden_cmds {*}[apply {{} {
}
if {[package vsatisfies [package provide Tcl] 8.7-]} {
    lappend hidden_cmds file tcl:encoding:system tcl:file:tempdir
    foreach cmd {
	cmdtype nameofexecutable
    } {lappend hidden_cmds tcl:info:$cmd}
    foreach cmd {
	autopurge list purge status
    } {lappend hidden_cmds tcl:process:$cmd}
    foreach cmd {
	lmkimg lmkzip mkimg mkkey mkzip mount  mount_data unmount
    } {lappend hidden_cmds tcl:zipfs:$cmd}
}
foreach cmd {
    atime attributes copy delete dirname executable exists extension
    isdirectory isfile link lstat mkdir mtime nativename normalize
    owned readable readlink rename rootname size stat tail tempfile
    type volumes writable
} {lappend hidden_cmds tcl:file:$cmd}
	atime attributes copy delete dirname executable exists extension
	isdirectory isfile link lstat mkdir mtime nativename normalize owned
	readable readlink rename rootname size stat tail tempfile type
	volumes writable
    } {lappend result tcl:file:$cmd}; return $result
}}]
if {[tk windowingsystem] ne "x11"} {
    lappend hidden_cmds tk_chooseColor tk_chooseDirectory \
	tk_getOpenFile tk_getSaveFile tk_messageBox
    lappend hidden_cmds tk_chooseColor tk_chooseDirectory tk_getOpenFile \
	tk_getSaveFile tk_messageBox
}
if {[llength [info commands send]]} {
    lappend hidden_cmds send
}

set saveAutoPath $::auto_path
set auto_path [list [info library] $::tk_library]
137
138
139
140
141
142
143
144

145
146
147
148
149
150

151
152
153
154
155
156
157
122
123
124
125
126
127
128

129
130
131
132
133
134

135
136
137
138
139
140
141
142







-
+





-
+







} -result {ok {appname not accessible in a safe interpreter}}
test safe-2.4 {Unsafe subcommands not available} -setup {
    catch {safe::interpDelete a}
} -body {
    safe::interpCreate a
    safe::loadTk a
    set status broken
    if {[catch {interp eval a {tk scaling 1}} msg]} {
    if {[catch {interp eval a {tk scaling}} msg]} {
	set status ok
    }
    list $status $msg
} -cleanup {
    safe::interpDelete a
} -result {ok {setting the scaling not accessible in a safe interpreter}}
} -result {ok {scaling not accessible in a safe interpreter}}

test safe-3.1 {Unsafe commands are available hidden} -setup {
    catch {safe::interpDelete a}
} -body {
    safe::interpCreate a
    safe::loadTk a
    set status ok
193
194
195
196
197
198
199
200

201
202
203
204
205

206
207
208
209
210
211
212
178
179
180
181
182
183
184

185
186
187
188
189

190
191
192
193
194
195
196
197







-
+




-
+







    pack $w
    set i [safe::loadTk [safe::interpCreate] -use [winfo id $w]]
    interp eval $i {button .b -text "hello world!"; pack .b}
    safe::interpDelete $i
    destroy $w
} -result {}

test safe-5.1 {loading Tk in safe interps without parent's clearance} -body {
test safe-5.1 {loading Tk in safe interps without master's clearance} -body {
    set i [safe::interpCreate]
    interp eval $i {load {} Tk}
} -cleanup {
    safe::interpDelete $i
} -returnCodes error -match glob -result {*not allowed}
} -returnCodes error -result {not allowed}
test safe-5.2 {multi-level Tk loading with clearance} -setup {
    set safeParent [safe::interpCreate]
} -body {
    # No error shall occur in that test and no window shall remain at the end.
    set i [safe::interpCreate [list $safeParent x]]
    safe::loadTk $i
    interp eval $i {

Deleted tests/safePrimarySelection.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# This file is a Tcl script to test entry widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# ------------------------------------------------------------------------------
# Tests that a Safe Base interpreter cannot write to the PRIMARY selection.
# ------------------------------------------------------------------------------
# - Tests 3.*, 6.* test that the fix for ticket de156e9efe implemented in branch
#   bug-de156e9efe has been applied and still works.  They test that a Safe Base
#   child interpreter cannot write to the PRIMARY selection.
# - The other tests verify that the parent interpreter and an child interpreter
#   CAN write to the PRIMARY selection, and therefore that the test scripts
#   themselves are valid.
# - A text, entry, ttk::entry, listbox, spinbox or ttk::spinbox widget can have
#   option -exportselection 1, meaning (in an unsafe interpreter) that a
#   selection made in one of these widgets is automatically written to the
#   PRIMARY selection.
# - A safe interpreter must not write to the PRIMARY selection.
# - The spinbox, ttk::spinbox are variants of entry, ttk::entry respectively.
# ------------------------------------------------------------------------------

namespace eval ::_test_tmp {}

# ------------------------------------------------------------------------------
#  Proc ::_test_tmp::unsafeInterp
# ------------------------------------------------------------------------------
# Command that creates an child interpreter and tries to load Tk.
# - This is necessary for loading Tk if the tests are done in the build
#   directory without installing Tk.  In that case the usual auto_path loading
#   mechanism cannot work because the tk binary is not where pkgIndex.tcl says
#   it is.
# - This command is not needed for Safe Base children because safe::loadTk does
#   something similar and works correctly.
# - Based on scripts in winSend.test.
# ------------------------------------------------------------------------------

namespace eval ::_test_tmp {
    variable TkLoadCmd
}

foreach pkg [info loaded] {
    if {[lindex $pkg 1] eq "Tk"} {
	set ::_test_tmp::TkLoadCmd [list load {*}$pkg]
	break
    }
}

proc ::_test_tmp::unsafeInterp {name} {
    variable TkLoadCmd
    interp create $name
    $name eval [list set argv [list -name $name]]
    catch {{*}$TkLoadCmd $name}
}


set ::_test_tmp::script {
    package require tk
    namespace eval ::_test_tmp {}

    proc ::_test_tmp::getPrimarySelection {} {
        if {[catch {::tk::GetSelection . PRIMARY} sel]} {
            set sel {}
        }
        return $sel
    }

    proc ::_test_tmp::setPrimarySelection {} {
        destroy .preset
        text .preset -exportselection 1
        .preset insert end OLD_VALUE
        # pack .preset
        .preset tag add sel 1.0 end-1c
        update
        return
    }

    # Clearing the PRIMARY selection is troublesome.
    # The window need not be mapped.
    # However, the window must continue to exist, or some X11 servers
    # will set the PRIMARY selection to something else.
    proc ::_test_tmp::clearPrimarySelection {} {
        destroy .clear
        text .clear -exportselection 1
        .clear insert end TMP_VALUE
        # pack .clear
        .clear tag add sel 1.0 end-1c
        update
        .clear tag remove sel 1.0 end-1c
        update
        return
    }

    # If this interpreter can write to the PRIMARY
    # selection, the commands below will do so.

    proc ::_test_tmp::tryText {} {
        text .t -exportselection 1
        .t insert end PAYLOAD
        pack .t
        .t tag add sel 1.0 end-1c
        update
        return
    }

    proc ::_test_tmp::tryEntry {} {
        entry .t -exportselection 1
        .t insert end PAYLOAD
        pack .t
        .t selection range 0 end
        update
        return
    }

    proc ::_test_tmp::tryTtkEntry {} {
        ::ttk::entry .t -exportselection 1
        .t insert end PAYLOAD
        pack .t
        .t selection range 0 end
        update
        return
    }

    proc ::_test_tmp::tryListbox {} {
        listbox .t -exportselection 1
        .t insert end list1 PAYLOAD list3
        pack .t
        .t selection set 1
        update
        return
    }

    proc ::_test_tmp::trySpinbox {ver} {
        if {$ver == 1} {
            # spinbox as entry
            spinbox .t -exportselection 1 -values {1 2 3 4 5}
            .t delete 0 end
            .t insert end PAYLOAD
            pack .t
            .t selection range 0 end
            update
            return
            # selects PAYLOAD
        } elseif {$ver == 2} {
            # spinbox spun
            spinbox .t -exportselection 1 -values {1 2 3 4 5}
            .t invoke buttonup
            pack .t
            .t selection range 0 end
            update
            return
            # selects 2
        } else {
            # spinbox spun/selected/spun
            spinbox .t -exportselection 1 -values {1 2 3 4 5}
            .t invoke buttonup
            pack .t
            .t selection range 0 end
            update
            .t invoke buttonup
            update
            return
            # selects 3
        }
    }

    proc ::_test_tmp::tryTtkSpinbox {ver} {
        if {$ver == 1} {
            # ttk::spinbox as entry
            ::ttk::spinbox .t -exportselection 1 -values {1 2 3 4 5}
            .t delete 0 end
            .t insert end PAYLOAD
            pack .t
            .t selection range 0 end
            update
            return
        } elseif {$ver == 2} {
            # ttk::spinbox spun
            ::ttk::spinbox .t -exportselection 1 -values {1 2 3 4 5}
            ::ttk::spinbox::Spin .t +1
            ::ttk::spinbox::Spin .t +1
            pack .t
            # ttk::spinbox::Spin sets selection
            update
            return
            # selects 2
        } else {
            # ttk::spinbox spun/selected/spun
            ::ttk::spinbox .t -exportselection 1 -values {1 2 3 4 5}
            ::ttk::spinbox::Spin .t +1
            ::ttk::spinbox::Spin .t +1
            pack .t
            # ttk::spinbox::Spin sets selection
            update
            ::ttk::spinbox::Spin .t +1
            update
            return
            # selects 3
        }
    }
}

# Do this once for the parent interpreter.
eval $::_test_tmp::script

test safePrimarySelection-1.1 {parent interpreter, text, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryText
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.2 {parent interpreter, entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryEntry
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.3 {parent interpreter, ttk::entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryTtkEntry
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.4 {parent interpreter, listbox, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryListbox
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.5 {parent interpreter, spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 1
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.6 {parent interpreter, spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 2
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-1.7 {parent interpreter, spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 3
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-1.8 {parent interpreter, ttk::spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 1
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-1.9 {parent interpreter, ttk::spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 2
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-1.10 {parent interpreter, ttk::spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 3
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-2.1 {child interpreter, text, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryText
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.2 {child interpreter, entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryEntry
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.3 {child interpreter, ttk::entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkEntry
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.4 {child interpreter, listbox, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryListbox
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.5 {child interpreter, spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 1
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.6 {child interpreter, spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 2
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-2.7 {child interpreter, spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 3
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-2.8 {child interpreter, ttk::spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 1
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-2.9 {child interpreter, ttk::spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 2
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-2.10 {child interpreter, ttk::spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 3
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-3.1 {IMPORTANT, safe interpreter, text, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryText
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.2 {IMPORTANT, safe interpreter, entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryEntry
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.3 {IMPORTANT, safe interpreter, ttk::entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkEntry
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.4 {IMPORTANT, safe interpreter, listbox, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryListbox
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.5 {IMPORTANT, safe interpreter, spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 1
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.6 {IMPORTANT, safe interpreter, spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 2
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.7 {IMPORTANT, safe interpreter, spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 3
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.8 {IMPORTANT, safe interpreter, ttk::spinbox as entry, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 1
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.9 {IMPORTANT, safe interpreter, ttk::spinbox spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 2
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-3.10 {IMPORTANT, safe interpreter, ttk::spinbox spun/selected/spun, no existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 3
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {----}

test safePrimarySelection-4.1 {parent interpreter, text, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryText
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.2 {parent interpreter, entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryEntry
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.3 {parent interpreter, ttk::entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryTtkEntry
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.4 {parent interpreter, listbox, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryListbox
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.5 {parent interpreter, spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 1
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.6 {parent interpreter, spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 2
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-4.7 {parent interpreter, spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::trySpinbox 3
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-4.8 {parent interpreter, ttk::spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 1
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-4.9 {parent interpreter, ttk::spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 2
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-4.10 {parent interpreter, ttk::spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    ::_test_tmp::tryTtkSpinbox 3
    ::_test_tmp::getPrimarySelection
} -cleanup {
    destroy {*}[winfo children .]
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-5.1 {child interpreter, text, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryText
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.2 {child interpreter, entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryEntry
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.3 {child interpreter, ttk::entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkEntry
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.4 {child interpreter, listbox, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryListbox
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.5 {child interpreter, spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 1
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.6 {child interpreter, spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 2
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-5.7 {child interpreter, spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 3
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-5.8 {child interpreter, ttk::spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 1
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result {PAYLOAD}

test safePrimarySelection-5.9 {child interpreter, ttk::spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 2
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 2

test safePrimarySelection-5.10 {child interpreter, ttk::spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set int2 child2
    ::_test_tmp::unsafeInterp $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 3
    $int2 eval ::_test_tmp::getPrimarySelection
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2
    ::_test_tmp::clearPrimarySelection
} -result 3

test safePrimarySelection-6.1 {IMPORTANT, safe interpreter, text, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryText
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.2 {IMPORTANT, safe interpreter, entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryEntry
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.3 {IMPORTANT, safe interpreter, ttk::entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkEntry
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.4 {IMPORTANT, safe interpreter, listbox, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryListbox
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.5 {IMPORTANT, safe interpreter, spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 1
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.6 {IMPORTANT, safe interpreter, spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 2
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.7 {IMPORTANT, safe interpreter, spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::trySpinbox 3
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.8 {IMPORTANT, safe interpreter, ttk::spinbox as entry, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 1
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.9 {IMPORTANT, safe interpreter, ttk::spinbox spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 2
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}

test safePrimarySelection-6.10 {IMPORTANT, safe interpreter, ttk::spinbox spun/selected/spun, existing selection} -setup {
    catch {interp delete child2}
    destroy {*}[winfo children .]
    ::_test_tmp::setPrimarySelection
} -body {
    set res0 [::_test_tmp::getPrimarySelection]
    set int2 child2
    ::safe::interpCreate $int2
    ::safe::loadTk $int2
    $int2 eval $::_test_tmp::script
    $int2 eval ::_test_tmp::tryTtkSpinbox 3
    set res1 [$int2 eval ::_test_tmp::getPrimarySelection]
    set res2 [::_test_tmp::getPrimarySelection]
    set res3 $res0--$res1--$res2
} -cleanup {
    interp delete $int2
    destroy {*}[winfo children .]
    unset int2 res0 res1 res2 res3
    ::_test_tmp::clearPrimarySelection
} -result {OLD_VALUE----OLD_VALUE}


namespace delete ::_test_tmp

# option clear
# cleanup
cleanupTests
return

Changes to tests/scale.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test out the "scale" command
# of Tk.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

42
43
44
45
46
47
48
49

50
51
52

53
54
55
56
57
58
59
42
43
44
45
46
47
48

49
50
51

52
53
54
55
56
57
58
59







-
+


-
+







        .s configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test scale-1.5 {configuration options} -body {
    .s configure -bd 4
    .s cget -bd
} -cleanup {
    .s configure -bd [lindex [.s configure -bd] 3]
} -result 4
} -result {4}
test scale-1.6 {configuration options} -body {
        .s configure -bd badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test scale-1.7 {configuration options} -body {
    .s configure -bigincrement 12.5
    .s cget -bigincrement
} -cleanup {
    .s configure -bigincrement [lindex [.s configure -bigincrement] 3]
} -result {12.5}
test scale-1.8 {configuration options} -body {
69
70
71
72
73
74
75
76

77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
69
70
71
72
73
74
75

76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107







-
+


-
+




















-
+







        .s configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test scale-1.11 {configuration options} -body {
    .s configure -borderwidth 1.3
    .s cget -borderwidth
} -cleanup {
    .s configure -borderwidth [lindex [.s configure -borderwidth] 3]
} -result 1
} -result {1}
test scale-1.12 {configuration options} -body {
        .s configure -borderwidth badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test scale-1.13 {configuration options} -body {
    .s configure -command {set x}
    .s cget -command
} -cleanup {
    .s configure -command [lindex [.s configure -command] 3]
} -result {set x}
test scale-1.15 {configuration options} -body {
    .s configure -cursor arrow
    .s cget -cursor
} -cleanup {
    .s configure -cursor [lindex [.s configure -cursor] 3]
} -result {arrow}
test scale-1.16 {configuration options} -body {
        .s configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
test scale-1.17 {configuration options} -body {
    .s configure -digits 5
    .s cget -digits
} -cleanup {
    .s configure -digits [lindex [.s configure -digits] 3]
} -result 5
} -result {5}
test scale-1.18 {configuration options} -body {
        .s configure -digits badValue
} -returnCodes error -result {expected integer but got "badValue"}
test scale-1.19 {configuration options} -body {
    .s configure -fg #00ff00
    .s cget -fg
} -cleanup {
153
154
155
156
157
158
159
160

161
162
163

164
165
166
167
168
169
170
171
172
173
174
175

176
177
178

179
180
181
182
183
184
185
153
154
155
156
157
158
159

160
161
162

163
164
165
166
167
168
169
170
171
172
173
174

175
176
177

178
179
180
181
182
183
184
185







-
+


-
+











-
+


-
+







        .s configure -highlightcolor non-existent
} -returnCodes error -result {unknown color name "non-existent"}
test scale-1.31 {configuration options} -body {
    .s configure -highlightthickness 2
    .s cget -highlightthickness
} -cleanup {
    .s configure -highlightthickness [lindex [.s configure -highlightthickness] 3]
} -result 2
} -result {2}
test scale-1.32 {configuration options} -body {
        .s configure -highlightthickness badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test scale-1.33 {configuration options} -body {
    .s configure -label {Some text}
    .s cget -label
} -cleanup {
    .s configure -label [lindex [.s configure -label] 3]
} -result {Some text}
test scale-1.35 {configuration options} -body {
    .s configure -length 130
    .s cget -length
} -cleanup {
    .s configure -length [lindex [.s configure -length] 3]
} -result 130
} -result {130}
test scale-1.36 {configuration options} -body {
        .s configure -length badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test scale-1.37 {configuration options} -body {
    .s configure -orient horizontal
    .s cget -orient
} -cleanup {
    .s configure -orient [lindex [.s configure -orient] 3]
} -result {horizontal}
test scale-1.38 {configuration options} -body {
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244

245
246
247

248
249
250
251
252
253
254
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243

244
245
246

247
248
249
250
251
252
253
254







-
+








-
+

















-
+








-
+


-
+







        .s configure -relief badValue
} -returnCodes error -result {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}
test scale-1.43 {configuration options} -body {
    .s configure -repeatdelay 14
    .s cget -repeatdelay
} -cleanup {
    .s configure -repeatdelay [lindex [.s configure -repeatdelay] 3]
} -result 14
} -result {14}
test scale-1.44 {configuration options} -body {
        .s configure -repeatdelay bogus
} -returnCodes error -result {expected integer but got "bogus"}
test scale-1.45 {configuration options} -body {
    .s configure -repeatinterval 14
    .s cget -repeatinterval
} -cleanup {
    .s configure -repeatinterval [lindex [.s configure -repeatinterval] 3]
} -result 14
} -result {14}
test scale-1.46 {configuration options} -body {
        .s configure -repeatinterval bogus
} -returnCodes error -result {expected integer but got "bogus"}
test scale-1.47 {configuration options} -body {
    .s configure -resolution 2.0
    .s cget -resolution
} -cleanup {
    .s configure -resolution [lindex [.s configure -resolution] 3]
} -result {2.0}
test scale-1.48 {configuration options} -body {
        .s configure -resolution badValue
} -returnCodes error -result {expected floating-point number but got "badValue"}
test scale-1.49 {configuration options} -body {
    .s configure -showvalue 0
    .s cget -showvalue
} -cleanup {
    .s configure -showvalue [lindex [.s configure -showvalue] 3]
} -result 0
} -result {0}
test scale-1.50 {configuration options} -body {
        .s configure -showvalue badValue
} -returnCodes error -result {expected boolean value but got "badValue"}
test scale-1.51 {configuration options} -body {
    .s configure -sliderlength 86
    .s cget -sliderlength
} -cleanup {
    .s configure -sliderlength [lindex [.s configure -sliderlength] 3]
} -result 86
} -result {86}
test scale-1.52 {configuration options} -body {
        .s configure -sliderlength badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
test scale-1.53 {configuration options} -body {
    .s configure -sliderrelief raised
    .s cget -sliderrelief
} -cleanup {
    .s configure -sliderrelief [lindex [.s configure -sliderrelief] 3]
} -result {raised}
test scale-1.54 {configuration options} -body {
309
310
311
312
313
314
315
316

317
318
319

320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338

339
340
341
342
343
344
345
309
310
311
312
313
314
315

316
317
318

319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337

338
339
340
341
342
343
344
345







-
+


-
+











-
+






-
+







    .s configure -variable [lindex [.s configure -variable] 3]
} -result {x}
test scale-1.69 {configuration options} -body {
    .s configure -width 32
    .s cget -width
} -cleanup {
    .s configure -width [lindex [.s configure -width] 3]
} -result 32
} -result {32}
test scale-1.70 {configuration options} -body {
        .s configure -width badValue
} -returnCodes error -result {expected screen distance but got "badValue"}
} -returnCodes error -result {bad screen distance "badValue"}
destroy .s


test scale-2.1 {Tk_ScaleCmd procedure} -body {
    scale
} -returnCodes error -result {wrong # args: should be "scale pathName ?-option value ...?"}
test scale-2.2 {Tk_ScaleCmd procedure} -body {
    scale foo
} -returnCodes error -result {bad window path name "foo"}
test scale-2.3 {Tk_ScaleCmd procedure} -body {
    catch {scale foo}
    winfo children .
    winfo child .
} -result {}
test scale-2.4 {Tk_ScaleCmd procedure} -body {
    scale .s -gorp dumb
} -returnCodes error -result {unknown option "-gorp"}
test scale-2.5 {Tk_ScaleCmd procedure} -body {
    catch {scale .s -gorp dumb}
    winfo children .
    winfo child .
} -result {}


# Widget used in 3.* tests
destroy .s
scale .s -from 100 -to 200
pack .s
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369







-
+







} -returnCodes error -result {wrong # args: should be ".s cget option"}
test scale-3.4 {ScaleWidgetCmd procedure, cget option} -body {
    .s cget -gorp
} -returnCodes error -result {unknown option "-gorp"}
test scale-3.5 {ScaleWidgetCmd procedure, cget option} -body {
    .s configure -highlightthickness 2
    .s cget -highlightthickness
} -result 2
} -result {2}
test scale-3.6 {ScaleWidgetCmd procedure, configure option} -body {
    list [llength [.s configure]] [lindex [.s configure] 6]
} -result {33 {-command command Command {} {}}}
test scale-3.7 {ScaleWidgetCmd procedure, configure option} -body {
    .s configure -foo
} -returnCodes error -result {unknown option "-foo"}
test scale-3.8 {ScaleWidgetCmd procedure, configure option} -body {
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476







-
+







    .s configure -from 100 -to 200 -orient vertical -resolution 1
    update
    .s set 118
    .s configure -state disabled
    .s set 181
    .s configure -state normal
    .s get
} -result 118
} -result {118}
test scale-3.29 {ScaleWidgetCmd procedure} -body {
    .s dumb
} -returnCodes error -result {bad option "dumb": must be cget, configure, coords, get, identify, or set}
test scale-3.30 {ScaleWidgetCmd procedure} -body {
    .s c
} -returnCodes error -result {ambiguous option "c": must be cget, configure, coords, get, identify, or set}
test scale-3.31 {ScaleWidgetCmd procedure} -body {
584
585
586
587
588
589
590
591

592
593
594
595
596

597
598
599
600
601

602
603
604
605
606

607
608
609
610
611

612
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
584
585
586
587
588
589
590

591
592
593
594
595

596
597
598
599
600

601
602
603
604
605

606
607
608
609
610

611
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627







-
+




-
+




-
+




-
+




-
+








-
+







destroy .s
scale .s -orient horizontal -length 200
pack .s
test scale-6.1 {ComputeFormat procedure} -body {
    .s configure -from 10 -to 100 -resolution 10
    .s set 49.3
    .s get
} -result 50
} -result {50}
test scale-6.2 {ComputeFormat procedure} -body {
    .s configure -from 100 -to 1000 -resolution 100
    .s set 493
    .s get
} -result 500
} -result {500}
test scale-6.3 {ComputeFormat procedure} -body {
    .s configure -from 1000 -to 10000 -resolution 1000
    .s set 4930
    .s get
} -result 5000
} -result {5000}
test scale-6.4 {ComputeFormat procedure} -body {
    .s configure -from 10000 -to 100000 -resolution 10000
    .s set 49000
    .s get
} -result 50000
} -result {50000}
test scale-6.5 {ComputeFormat procedure} -body {
    .s configure -from 100000 -to 1000000 -resolution 100000
    .s set 493000
    .s get
} -result 500000
} -result {500000}
test scale-6.6 {ComputeFormat procedure} -constraints {
	nonPortable
} -body {
    # This test is non-portable because some platforms format the
    # result as 5e+06.
    .s configure -from 1000000 -to 10000000 -resolution 1000000
    .s set 4930000
    .s get
} -result 5000000
} -result {5000000}
test scale-6.7 {ComputeFormat procedure} -body {
    .s configure -from 1000000000 -to 10000000000 -resolution 1000000000
    .s set 4930000000
    expr {[.s get] == 5.0e+09}
} -result 1
test scale-6.8 {ComputeFormat procedure} -body {
    .s configure -from .1 -to 1 -resolution .1
648
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663
664
665

666
667
668
669
670

671
672
673
674
675

676
677
678
679
680
681
682
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
663
664

665
666
667
668
669

670
671
672
673
674

675
676
677
678
679
680
681
682







-
+









-
+




-
+




-
+







    .s set .00006
    .s get
} -result {0.00006}
test scale-6.13 {ComputeFormat procedure} -body {
    .s configure -from .000001 -to .00001 -resolution .000001
    .s set .000006
    expr {[.s get] == 6.0e-06}
} -result 1
} -result {1}
test scale-6.14 {ComputeFormat procedure} -body {
    .s configure -to .00001 -from .0001 -resolution .00001
    .s set .00006
    .s get
} -result {0.00006}
test scale-6.15 {ComputeFormat procedure} -body {
    .s configure -to .000001 -from .00001 -resolution .000001
    .s set .000006
    expr {[.s get] == 6.0e-06}
} -result 1
} -result {1}
test scale-6.16 {ComputeFormat procedure} -body {
    .s configure -from .00001 -to .0001 -resolution .00001 -digits 1
    .s set .00006
    expr {[.s get] == 6e-05}
} -result 1
} -result {1}
test scale-6.17 {ComputeFormat procedure} -body {
    .s configure -from 10000000 -to 100000000 -resolution 10000000 -digits 3
    .s set 49300000
    .s get
} -result 50000000
} -result {50000000}
test scale-6.18 {ComputeFormat procedure} -body {
    .s configure -length 200 -from 0 -to 10 -resolution 0 -digits 0
    .s set .111111111
    .s get
} -result {0.11}
test scale-6.19 {ComputeFormat procedure} -body {
    .s configure -length 200 -from 1000 -to 1002 -resolution 0 -digits 0
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107

1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139


1140
1141
1142
1143
1144

1145
1146

1147
1148
1149
1150
1151
1152


1153
1154
1155
1156
1157

1158
1159

1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172

1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112

1113
1114
1115
1116
1117
1118
1119

1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132

1133
1134
1135
1136
1137


1138
1139
1140
1141
1142
1143

1144
1145

1146
1147
1148
1149
1150


1151
1152
1153
1154
1155
1156

1157
1158

1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185



































1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202

1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231







-
+












-
+





-
+






-
+





-
+






-
+




-
-
+
+




-
+

-
+




-
-
+
+




-
+

-
+





-
+






-
+





-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
+








-
+




















-
+







        set traceInfo $args
    }
    .s configure -from 0 -to 100 -command {set x} -variable y
    update

    .s set 50
    update
    trace add variable y write varTrace
    trace variable y w varTrace
    set traceInfo empty
    set x untouched
    .s set 50
    update
    list $x $traceInfo
} -result {untouched empty}


# Widget used in 14.* tests
destroy .s
pack [scale .s]
update
test scale-14.1 {RoundValueToResolution procedure} -body {
test scale-14.1 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 100 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 84 152
} -result 72
test scale-14.2 {RoundValueToResolution procedure} -body {
test scale-14.2 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 100 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 86 152
} -result 76

test scale-14.3 {RoundValueToResolution procedure} -body {
test scale-14.3 {RoundToResolution procedure} -body {
    .s configure -from 100 -to 0 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 84 152
} -result 28
test scale-14.4 {RoundValueToResolution procedure} -body {
test scale-14.4 {RoundToResolution procedure} -body {
    .s configure -from 100 -to 0 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 86 152
} -result 24

test scale-14.5 {RoundValueToResolution procedure} -body {
test scale-14.5 {RoundToResolution procedure} -body {
    .s configure -from -100 -to 0 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 84 152
} -result -28
test scale-14.6 {RoundValueToResolution procedure} -body {
} -result {-28}
test scale-14.6 {RoundToResolution procedure} -body {
    .s configure -from -100 -to 0 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 86 152
} -result -24
} -result {-24}

test scale-14.7 {RoundValueToResolution procedure} -body {
test scale-14.7 {RoundToResolution procedure} -body {
    .s configure -from 0 -to -100 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 84 152
} -result -72
test scale-14.8 {RoundValueToResolution procedure} -body {
} -result {-72}
test scale-14.8 {RoundToResolution procedure} -body {
    .s configure -from 0 -to -100 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 4.0
    update
    .s get 86 152
} -result -76
} -result {-76}

test scale-14.9 {RoundValueToResolution procedure} -body {
test scale-14.9 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 2.25  -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 0
    update
    .s get 84 152
} -result {1.64}
test scale-14.10 {RoundValueToResolution procedure} -body {
test scale-14.10 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 2.25  -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 0
    update
    .s get 86 152
} -result {1.69}

test scale-14.11 {RoundValueToResolution procedure} -body {
test scale-14.11 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 225 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 0 -digits 5
    update
    .s get 84 152
} -result {164.25}
test scale-14.12 {RoundValueToResolution procedure} -body {
test scale-14.12 {RoundToResolution procedure} -body {
    .s configure -from 0 -to 225 -sliderlength 10 -length 114 -bd 2 \
        -orient horizontal -resolution 0 -digits 5
    update
    .s get 86 152
} -result {168.75}
destroy .s

test scale-14.13 {RoundValueToResolution procedure, round-off errors} -setup {
    # see [220665ffff], and duplicates [220265ffff] and [779559ffff]
    set x NotSet
    pack [scale .s -orient horizontal -resolution .1 -from -180 -to 180 -command "set x"]
    update
} -body {
    .s configure -background red
    update
    set x
} -cleanup {
    destroy .s
} -result {NotSet}

test scale-14a.1 {RoundValueToResolution, RoundIntervalToResolution procedures} -setup {
    pack [scale .s -orient horizontal]
    update
} -body {
    .s configure -length 400 -bd 0 -from 1 -to 9 -resolution 2 -tickinterval 1
    update
    .s get 200 0
} -cleanup {
    destroy .s
} -result 5
test scale-14a.2 {RoundValueToResolution, RoundIntervalToResolution procedures} -setup {
    pack [scale .s -orient horizontal]
    update
} -body {
    .s configure -length 400 -bd 0 -from -1.5 -to 1.5 -resolution 1 \
            -tickinterval 1 -digits 2
    update
    .s get 250 0
} -cleanup {
    destroy .s
} -result {0.5}


test scale-15.1 {ScaleVarProc procedure} -setup {
    deleteWindows
} -body {
    set y -130
    scale .s -from 0 -to -200 -variable y -orient horizontal -length 150
    pack .s
    return $y
} -result -130
} -result {-130}
test scale-15.2 {ScaleVarProc procedure} -setup {
    deleteWindows
} -body {
    set y -130
    scale .s -from -200 -to 0 -variable y -orient horizontal -length 150
    pack .s
    set y -87
    .s get
} -result -87
} -result {-87}
test scale-15.3 {ScaleVarProc procedure} -setup {
    deleteWindows
} -body {
    set y -130
    scale .s -from -200 -to 0 -variable y -orient horizontal -length 150
    pack .s
    set y 40q
} -cleanup {
    deleteWindows
} -returnCodes error -result {can't set "y": can't assign non-numeric value to scale variable}
test scale-15.4 {ScaleVarProc procedure} -setup {
    deleteWindows
} -body {
    set y -130
    scale .s -from -200 -to 0 -variable y -orient horizontal -length 150
    pack .s
    catch {set y 40q}
    .s get
} -cleanup {
    deleteWindows
} -result -130
} -result {-130}
test scale-15.5 {ScaleVarProc procedure} -setup {
    deleteWindows
} -body {
    set y 1
    scale .s -from 1 -to 0 -variable y -orient horizontal -length 150
    pack .s
    set y x
1340
1341
1342
1343
1344
1345
1346
1347

1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388

1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436

1437
1438
1439

1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331

1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363



















1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381

1382
1383
1384

1385
1386
1387

1388
1389
1390
1391
1392
1393
1394
1395







-
+



















-
+




















-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















-
+


-
+


-
+


-
+








    # Bug 4833 changed the result to realize that x should pick up
    # a value from the scale.  In an FPE occurs, it is due to the
    # lack of errno being set to 0 by some libc's. (see bug 4942)
    return $x
} -cleanup {
    deleteWindows
} -result 100
} -result {100}


test scale-18.1 {DestroyScale, -cursor option [Bug: 3897]} -setup {
    deleteWindows
} -body {
    scale .s -cursor trek
    destroy .s
} -result {}

test scale-18.2 {Scale button 1 events [Bug 787065]} -setup {
    destroy .s
    set ::error {}
    proc bgerror {args} {set ::error $args}
} -body {
    set y 5
    scale .s -from 0 -to 10 -variable y -orient horizontal -length 150
    pack .s
    tkwait visibility .s
    list [catch {
        event generate .s <Button-1> -x 0 -y 0
        event generate .s <1> -x 0 -y 0
        event generate .s <ButtonRelease-1> -x 0 -y 0
        update
        set ::error
    } msg] $msg
} -cleanup {
    unset ::error
    rename bgerror {}
    destroy .s
} -result {0 {}}

test scale-18.3 {Scale button 2 events [Bug 787065]} -setup {
    destroy .s
    set ::error {}
    proc bgerror {args} {set ::error $args}
} -body {
    set y 5
    scale .s -from 0 -to 10 -variable y -orient horizontal -length 150
    pack .s
    tkwait visibility .s
    list [catch {
        event generate .s <Button-2> -x 0 -y 0
        event generate .s <2> -x 0 -y 0
        event generate .s <ButtonRelease-2> -x 0 -y 0
        update
        set ::error
    } msg] $msg
} -cleanup {
    unset ::error
    rename bgerror {}
    destroy .s
} -result {0 {}}

test scale-18.4 {Bug [415415ffff] - Long callback: One click -> Several steps} -setup {
    catch {destroy .s}
    scale .s -from 0 -to 5 -resolution 1 -variable x1 -orient horizontal -length 100 \
            -command longCmd -repeatdelay 300
    pack .s
    update
    proc longCmd {unused} {
      after 500  ; # larger than -repeatdelay
    }
} -body {
    foreach {x y} [.s coord 50] {}
    event generate .s <Button-1> -x $x -y $y
    update
    event generate .s <ButtonRelease-1> -x $x -y $y
    update
    set x1
} -cleanup {
    destroy .s
} -result {1}

test scale-19 {Bug [3529885fff] - Click in through goes in wrong direction} \
    -setup {
        catch {destroy .s}
        catch {destroy .s1 .s2 .s3 .s4}
        unset -nocomplain x1 x2 x3 x4 x y
        scale .s1 -from 0 -to 100 -resolution 1  -variable x1 -digits 4 -orient horizontal -length 100
        scale .s2 -from 0 -to 100 -resolution -1 -variable x2 -digits 4 -orient horizontal -length 100
        scale .s3 -from 100 -to 0 -resolution 1  -variable x3 -digits 4 -orient horizontal -length 100
        scale .s4 -from 100 -to 0 -resolution -1 -variable x4 -digits 4 -orient horizontal -length 100
        pack .s1 .s2 .s3 .s4 -side left
        update
    } \
    -body {
        foreach {x y} [.s1 coord 50] {}
        event generate .s1 <Button-1> -x $x -y $y
        event generate .s1 <1> -x $x -y $y
        event generate .s1 <ButtonRelease-1> -x $x -y $y
        foreach {x y} [.s2 coord 50] {}
        event generate .s2 <Button-1> -x $x -y $y
        event generate .s2 <1> -x $x -y $y
        event generate .s2 <ButtonRelease-1> -x $x -y $y
        foreach {x y} [.s3 coord 50] {}
        event generate .s3 <Button-1> -x $x -y $y
        event generate .s3 <1> -x $x -y $y
        event generate .s3 <ButtonRelease-1> -x $x -y $y
        foreach {x y} [.s4 coord 50] {}
        event generate .s4 <Button-1> -x $x -y $y
        event generate .s4 <1> -x $x -y $y
        event generate .s4 <ButtonRelease-1> -x $x -y $y
        update
        list $x1 $x2 $x3 $x4
    } \
    -cleanup {
        unset x1 x2 x3 x4 x y
        destroy .s1 .s2 .s3 .s4
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502


1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550

1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567

1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443


1444



1445
1446
1447
1448

1449
1450
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473


1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485

1486


1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
1498
1499

1500


1501
1502
1503
1504

1505
1506














































1507
1508
1509
1510
1511







+


-
-

-
-
-
+
+


-









-














-


-
-
+



-








-

-
-
+



-









-

-
-
+



-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





    set res [list [.s get] $commandedVar]
} -cleanup {
    destroy .s
} -result {10 -1}
test scale-20.4 {Bug [2262543fff] - Scale widget unexpectedly fires command callback, case 4} -setup {
    catch {destroy .s}
    set res {}
    set commandedVar -1
} -body {
    scale .s -from 1 -to 50 -command {set commandedVar}
    pack .s
    update idletasks
    .s set 10
    set timeout [after 500 {set $commandedVar "timeout"}]
    set commandedVar -1
    vwait commandedVar  ; # -command callback shall fire
    pack .s
    update  ; # -command callback shall fire
    set res [list [.s get] $commandedVar]
} -cleanup {
    after cancel $timeout
    destroy .s
} -result {10 10}
test scale-20.5 {Bug [2262543fff] - Scale widget unexpectedly fires command callback, case 5} -setup {
    catch {destroy .s}
    set res {}
    set commandedVar -1
} -body {
    scale .s -from 1 -to 50
    pack .s
    update idletasks
    .s set 10
    .s configure -command {set commandedVar}
    update  ; # -command callback shall NOT fire
    set res [list [.s get] $commandedVar]
} -cleanup {
    destroy .s
} -result {10 -1}
test scale-20.6 {Bug [2262543fff] - Scale widget unexpectedly fires command callback, case 6} -setup {
    catch {destroy .s}
    set res {}
    set commandedVar -1
} -body {
    scale .s -from 1 -to 50
    pack .s
    update idletasks
    .s configure -command {set commandedVar}
    .s set 10
    set timeout [after 500 {set $commandedVar "timeout"}]
    vwait commandedVar  ; # -command callback shall fire
    update  ; # -command callback shall fire
    set res [list [.s get] $commandedVar]
} -cleanup {
    destroy .s
    after cancel $timeout
} -result {10 10}
test scale-20.7 {Bug [2262543fff] - Scale widget unexpectedly fires command callback, case 7} -setup {
    catch {destroy .s}
    set res {}
    set commandedVar -1
} -body {
    scale .s -from 1 -to 50 -command {set commandedVar}
    pack .s
    update idletasks
    .s set 10
    set timeout [after 500 {set $commandedVar "timeout"}]
    vwait commandedVar  ; # -command callback shall fire
    update  ; # -command callback shall fire
    set res [list [.s get] $commandedVar]
} -cleanup {
    destroy .s
    after cancel $timeout
} -result {10 10}
test scale-20.8 {Bug [2262543fff] - Scale widget unexpectedly fires command callback, case 8} -setup {
    catch {destroy .s}
    set res {}
    set commandedVar -1
    set scaleVar 7
} -body {
    scale .s -from 1 -to 50 -variable scaleVar -command {set commandedVar}
    pack .s
    update idletasks
    .s set 10
    set timeout [after 500 {set $commandedVar "timeout"}]
    vwait commandedVar  ; # -command callback shall fire
    update  ; # -command callback shall fire
    set res [list [.s get] $commandedVar]
} -cleanup {
    destroy .s
    after cancel $timeout
} -result {10 10}

test scale-21.1 {Bug [55b95f578a] - Associating variable with bignum value with scale crashes it} -setup {
    catch {destroy .s}
} -body {
    pack [scale .s]
    set foo 5.79e99
    # non-regression test for bug [55b95f578a] - shall just not crash
    .s configure -variable foo
} -cleanup {
    destroy .s
} -result {}
test scale-21.2 {Bug [55b95f578a] again - Bignum value for -from/-to with scale crashes it} -setup {
    catch {destroy .s}
} -body {
    pack [scale .s]
    # non-regression test for bug [55b95f578a] - shall just not crash
    .s configure -from -6.8e99 -to 8.8e99
} -cleanup {
    destroy .s
} -result {}

test scale-22.1 {Bug [5d991b822e]} {
    # Want this not to crash
    set var INIT
    scale .b -variable var
    trace add variable var unset {apply {args {
        .b configure -variable {}
    }}}
    pack .b
    bind .b <Configure> {unset var}
    update
    destroy .b
} {}
test scale-22.2 {Bug [5d991b822e]} {
    # Want this not to leak traces
    set var INIT
    scale .b -variable var
    trace add variable var unset {apply {args {
        .b configure -variable new
    }}}
    pack .b
    bind .b <Configure> {unset -nocomplain var}
    update
    destroy .b
    unset new
} {}

option clear

# cleanup
cleanupTests
return

Changes to tests/scrollbar.test.

1
2
3
4
5
6
7



8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23

24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40











41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81

82
83

84
85
86
87

88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
1
2
3
4



5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20

21

22
23

24
25
26













27
28
29
30
31
32
33
34
35
36
37












38
39
40
41
42
43
44
45


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65

66
67

68
69
70
71

72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90




-
-
-
+
+
+


-
+










-

-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-








-
-
+
+















-
+


-
+

-
+



-
+










-
+







# This file is a Tcl script to test out scrollbar widgets and
# the "scrollbar" command of Tk.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

proc getTroughSize {w} {
    if {[testConstraint testmetrics]} {
        # Only Windows has [testmetrics]
	if [string match v* [$w cget -orient]] {
	    return [expr {[winfo height $w] - 2*[testmetrics cyvscroll $w]}]
	    return [expr [winfo height $w] - 2*[testmetrics cyvscroll $w]]
	} else {
	    return [expr {[winfo width $w] - 2*[testmetrics cxhscroll $w]}]
	    return [expr [winfo width $w] - 2*[testmetrics cxhscroll $w]]
	}
    } else {
        if {[tk windowingsystem] eq "x11"} {
            # Calculations here assume that the arrow area is a square.
	    if [string match v* [$w cget -orient]] {
	        return [expr {[winfo height $w] \
		        - ([winfo width $w] \
			    - [$w cget -highlightthickness] \
			    - [$w cget -bd] + 1)*2}]
	    } else {
	        return [expr {[winfo width $w] \
		        - ([winfo height $w] \
			    - [$w cget -highlightthickness] \
			    - [$w cget -bd] + 1)*2}]
	    }
	if [string match v* [$w cget -orient]] {
	    return [expr [winfo height $w] \
		    - ([winfo width $w] \
			- [$w cget -highlightthickness] \
			- [$w cget -bd] + 1)*2]
	} else {
	    return [expr [winfo width $w] \
		    - ([winfo height $w] \
			- [$w cget -highlightthickness] \
			- [$w cget -bd] + 1)*2]
	}
        } else {
            # macOS aqua
	    if [string match v* [$w cget -orient]] {
	        return [expr {[winfo height $w] \
			- ([$w cget -highlightthickness] \
			  +[$w cget -bd])*2}]
	    } else {
	        return [expr {[winfo width $w] \
			- ([$w cget -highlightthickness] \
			  +[$w cget -bd])*2}]
	    }
        }
    }
}

# XXX Note: this test file is woefully incomplete.  Right now there are
# only bits and pieces of tests.  Please make this file more complete
# as you fix bugs and add features.

foreach {width height} [wm minsize .] {
    set height [expr {($height < 200) ? 200 : $height}]
    set width [expr {($width < 1) ? 1 : $width}]
    set height [expr ($height < 200) ? 200 : $height]
    set width [expr ($width < 1) ? 1 : $width]
}

frame .f -height $height -width $width
pack .f -side left
scrollbar .s
pack .s -side right -fill y
update
set i 1
foreach test {
    {-activebackground #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-activerelief sunken sunken non-existent
	    {bad relief "non-existent": must be flat, groove, raised, ridge, solid, or sunken}}
    {-background #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-bd 4 4 badValue {expected screen distance but got "badValue"}}
    {-bd 4 4 badValue {bad screen distance "badValue"}}
    {-bg #ff0000 #ff0000 non-existent
	    {unknown color name "non-existent"}}
    {-borderwidth 1.3 1 badValue {expected screen distance but got "badValue"}}
    {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
    {-command "set x" {set x} {} {}}
    {-elementborderwidth 4 4 badValue {expected screen distance but got "badValue"}}
    {-elementborderwidth 4 4 badValue {bad screen distance "badValue"}}
    {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
    {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
    {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}}
    {-highlightthickness 6 6 bogus {expected screen distance but got "bogus"}}
    {-highlightthickness 6 6 bogus {bad screen distance "bogus"}}
    {-highlightthickness -2 0 {} {}}
    {-jump true 1 silly {expected boolean value but got "silly"}}
    {-orient horizontal horizontal badValue
	    {bad orientation "badValue": must be vertical or horizontal}}
    {-orient horizontal horizontal bogus {bad orientation "bogus": must be vertical or horizontal}}
    {-relief ridge ridge badValue {bad relief "badValue": must be flat, groove, raised, ridge, solid, or sunken}}
    {-repeatdelay 140 140 129.3 {expected integer but got "129.3"}}
    {-repeatinterval 140 140 129.3 {expected integer but got "129.3"}}
    {-takefocus "any string" "any string" {} {}}
    {-troughcolor #432 #432 lousy {unknown color name "lousy"}}
    {-width 32 32 badValue {expected screen distance but got "badValue"}}
    {-width 32 32 badValue {bad screen distance "badValue"}}
} {
    lassign $test name value okResult badValue badResult
    # Assume $name is plain; true of all our in-use options!
    test scrollbar-1.$i {configuration options} \
	".s configure $name [list $value]; .s cget $name" $okResult
    incr i
    if {$badValue ne ""} {
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
178
179
180
181
182
183
184

185
186
187
188
189
190
191
192







-
+







} {}
test scrollbar-3.14.1 {ScrollbarWidgetCmd procedure, "cget" option} emptyTest {
    # empty test; duplicated scrollbar-3.13
} {}
destroy .s2
test scrollbar-3.15 {ScrollbarWidgetCmd procedure, "configure" option} {
    llength [.s configure]
} 20
} {20}
test scrollbar-3.16 {ScrollbarWidgetCmd procedure, "configure" option} {
    list [catch {.s configure -bad} msg] $msg
} {1 {unknown option "-bad"}}
test scrollbar-3.17 {ScrollbarWidgetCmd procedure, "configure" option} {
    .s configure -orient
} {-orient orient Orient vertical vertical}
test scrollbar-3.18 {ScrollbarWidgetCmd procedure, "configure" option} {
226
227
228
229
230
231
232
233

234
235
236

237
238
239

240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268

269
270
271
272
273



274
275

276
277
278
279
280



281
282
283

284
285
286
287
288




289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308

309
310
311
312
313
314

315
316
317
318




319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369
211
212
213
214
215
216
217

218
219
220

221
222
223

224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251
252

253
254
255



256
257
258
259

260

261



262
263
264
265


266
267




268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283


284
285





286

287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322




323
324
325
326
327
328
329
330
331
332

333
334
335




336
337
338
339
340
341
342







-
+


-
+


-
+







-
+

















-
+


-
+


-
-
-
+
+
+

-
+
-

-
-
-
+
+
+

-
-
+

-
-
-
-
+
+
+
+












-
-
+

-
-
-
-
-
+
-




-
+




+
+
+
+




















-
+


-
-
-
-










-
+


-
-
-
-







    list [catch {.s delta 18 xxyz} msg] $msg
} {1 {expected integer but got "xxyz"}}
test scrollbar-3.24 {ScrollbarWidgetCmd procedure, "delta" option} {
    list [catch {.s delta 18 xxyz} msg] $msg
} {1 {expected integer but got "xxyz"}}
test scrollbar-3.25 {ScrollbarWidgetCmd procedure, "delta" option} {
    format {%.6g} [.s delta 20 0]
} 0
} {0}
test scrollbar-3.26 {ScrollbarWidgetCmd procedure, "delta" option} {
    format {%.6g} [.s delta 0 20]
} [format %.6g [expr {20.0/([getTroughSize .s]-1)}]]
} [format %.6g [expr 20.0/([getTroughSize .s]-1)]]
test scrollbar-3.27 {ScrollbarWidgetCmd procedure, "delta" option} {
    format {%.6g} [.s delta 0 -20]
} [format %.6g [expr {-20.0/([getTroughSize .s]-1)}]]
} [format %.6g [expr -20.0/([getTroughSize .s]-1)]]
test scrollbar-3.28 {ScrollbarWidgetCmd procedure, "delta" option} {
    toplevel .t -width 250 -height 100
    wm geom .t +0+0
    scrollbar .t.s -orient horizontal -borderwidth 2
    place .t.s -width 201
    update
    set result [list [format {%.6g} [.t.s delta 0 20]] \
	    [format {%.6g} [.t.s delta [expr {[getTroughSize .t.s] - 1}] 0]]]
	    [format {%.6g} [.t.s delta [expr [getTroughSize .t.s] - 1] 0]]]
    destroy .t
    set result
} {0 1}
test scrollbar-3.29 {ScrollbarWidgetCmd procedure, "fraction" option} {
    list [catch {.s fraction 24} msg] $msg
} {1 {wrong # args: should be ".s fraction x y"}}
test scrollbar-3.30 {ScrollbarWidgetCmd procedure, "fraction" option} {
    list [catch {.s fraction 24 30 32} msg] $msg
} {1 {wrong # args: should be ".s fraction x y"}}
test scrollbar-3.31 {ScrollbarWidgetCmd procedure, "fraction" option} {
    list [catch {.s fraction silly 24} msg] $msg
} {1 {expected integer but got "silly"}}
test scrollbar-3.32 {ScrollbarWidgetCmd procedure, "fraction" option} {
    list [catch {.s fraction 24 bogus} msg] $msg
} {1 {expected integer but got "bogus"}}
test scrollbar-3.33 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.s fraction 0 0]
} 0
} {0}
test scrollbar-3.34 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.s fraction 0 1000]
} 1
} {1}
test scrollbar-3.35 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.s fraction 4 21]
} [format %.6g [expr {(21.0 - ([winfo height .s] - [getTroughSize .s])/2.0) \
       /([getTroughSize .s] - 1)}]]
test scrollbar-3.36 {ScrollbarWidgetCmd procedure, "fraction" option} {
} [format %.6g [expr (21.0 - ([winfo height .s] - [getTroughSize .s])/2.0) \
       /([getTroughSize .s] - 1)]]
test scrollbar-3.36 {ScrollbarWidgetCmd procedure, "fraction" option} unix {
    format {%.6g} [.s fraction 4 179]
} [format %.6g [expr {(179.0 - ([winfo height .s] - [getTroughSize .s])/2.0) \
} {1}
       /([getTroughSize .s] - 1)}]]
test scrollbar-3.37 {ScrollbarWidgetCmd procedure, "fraction" option} {testmetrics} {
    format {%.6g} [.s fraction 4 [expr {200 - [testmetrics cyvscroll .s]}]]
} 1
test scrollbar-3.38 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.s fraction 4 [expr 200 - [testmetrics cyvscroll .s]]]
} {1}
test scrollbar-3.38 {ScrollbarWidgetCmd procedure, "fraction" option} unix {
    format {%.6g} [.s fraction 4 178]
} [format %.6g [expr {(178.0 - ([winfo height .s] - [getTroughSize .s])/2.0) \
       /([getTroughSize .s] - 1)}]]
} {0.993711}
test scrollbar-3.39 {ScrollbarWidgetCmd procedure, "fraction" option} {testmetrics win} {
    expr {
    [format {%.6g} [.s fraction 4 [expr {200 - [testmetrics cyvscroll .s] - 2}]]]
	== [format %g [expr {(200.0 - [testmetrics cyvscroll .s]*2 - 2)
			   / ($height - 1 - [testmetrics cyvscroll .s]*2)}]]}
    expr \
    [format {%.6g} [.s fraction 4 [expr 200 - [testmetrics cyvscroll .s] - 2]]] \
	== [format %g [expr (200.0 - [testmetrics cyvscroll .s]*2 - 2) \
			   / ($height - 1 - [testmetrics cyvscroll .s]*2)]]
} 1

toplevel .t -width 250 -height 100
wm geom .t +0+0
scrollbar .t.s -orient horizontal -borderwidth 2
place .t.s -width 201
update

test scrollbar-3.41 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.t.s fraction 100 0]
} {0.5}
if {[testConstraint testmetrics]} {
    # Only Windows has [testmetrics]
    place configure .t.s -width [expr {2*[testmetrics cxhscroll .t.s]+1}]
    place configure .t.s -width [expr 2*[testmetrics cxhscroll .t.s]+1]
} else {
    if {[tk windowingsystem] eq "x11"} {
        place configure .t.s -width [expr {[winfo height .t.s] - 2*([.t.s cget -highlightthickness] + [.t.s cget -bd] + 1)}]
    } else {
        # macOS aqua
        place configure .t.s -width [expr {2*([.t.s cget -highlightthickness] + [.t.s cget -bd])}]
    place configure .t.s -width [expr [winfo reqwidth .t.s] - 4]
    }
}
update
test scrollbar-3.42 {ScrollbarWidgetCmd procedure, "fraction" option} {
    format {%.6g} [.t.s fraction 100 0]
} 0
} {0}
destroy .t
test scrollbar-3.43 {ScrollbarWidgetCmd procedure, "get" option} {
    list [catch {.s get a} msg] $msg
} {1 {wrong # args: should be ".s get"}}
test scrollbar-3.44 {ScrollbarWidgetCmd procedure, "get" option} {
    .s set 100 10 13 14
    .s get
} {100 10 13 14}
test scrollbar-3.45 {ScrollbarWidgetCmd procedure, "get" option} {
    .s set 0.6 0.8
    set result {}
    foreach element [.s get] {
	lappend result [format %.1f $element]
    }
    set result
} {0.6 0.8}
test scrollbar-3.46 {ScrollbarWidgetCmd procedure, "identify" option} {
    list [catch {.s identify 0} msg] $msg
} {1 {wrong # args: should be ".s identify x y"}}
test scrollbar-3.47 {ScrollbarWidgetCmd procedure, "identify" option} {
    list [catch {.s identify 0 0 1} msg] $msg
} {1 {wrong # args: should be ".s identify x y"}}
test scrollbar-3.48 {ScrollbarWidgetCmd procedure, "identify" option} {
    list [catch {.s identify bogus 2} msg] $msg
} {1 {expected integer but got "bogus"}}
test scrollbar-3.49 {ScrollbarWidgetCmd procedure, "identify" option} {
    list [catch {.s identify -1 bogus} msg] $msg
} {1 {expected integer but got "bogus"}}
test scrollbar-3.50.1 {ScrollbarWidgetCmd procedure, "identify" option} notAqua {
test scrollbar-3.50 {ScrollbarWidgetCmd procedure, "identify" option} {
    .s identify 5 5
} {arrow1}
test scrollbar-3.50.2 {ScrollbarWidgetCmd procedure, "identify" option} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 5 5
} {trough1}
test scrollbar-3.51 {ScrollbarWidgetCmd procedure, "identify" option} {
    .s identify 5 35
} {trough1}
test scrollbar-3.52 {ScrollbarWidgetCmd procedure, "identify" option} {
    .s set .3 .6
    .s identify 5 80
} {slider}
test scrollbar-3.53 {ScrollbarWidgetCmd procedure, "identify" option} {
    .s identify 5 145
} {trough2}
test scrollbar-3.54.1 {ScrollbarWidgetCmd procedure, "identify" option} notAqua {
test scrollbar-3.54 {ScrollbarWidgetCmd procedure, "identify" option} {unixOrPc} {
    .s identify 5 195
} {arrow2}
test scrollbar-3.54.2 {ScrollbarWidgetCmd procedure, "identify" option} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 5 195
} {trough2}
test scrollbar-3.56 {ScrollbarWidgetCmd procedure, "identify" option} unix {
    .s identify 0 0
} {}
test scrollbar-3.57 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set abc def} msg] $msg
} {1 {expected floating-point number but got "abc"}}
test scrollbar-3.58 {ScrollbarWidgetCmd procedure, "set" option} {
393
394
395
396
397
398
399
























400
401
402
403
404
405
406
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    .s set .4 .3
    set result {}
    foreach element [.s get] {
	lappend result [format %.1f $element]
    }
    set result
} {0.4 0.4}
test scrollbar-3.64 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set abc def ghi jkl} msg] $msg
} {1 {expected integer but got "abc"}}
test scrollbar-3.65 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set 1 def ghi jkl} msg] $msg
} {1 {expected integer but got "def"}}
test scrollbar-3.66 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set 1 2 ghi jkl} msg] $msg
} {1 {expected integer but got "ghi"}}
test scrollbar-3.67 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set 1 2 3 jkl} msg] $msg
} {1 {expected integer but got "jkl"}}
test scrollbar-3.68 {ScrollbarWidgetCmd procedure, "set" option} {
    .s set -10 50 20 30
    .s get
} {0 50 0 0}
test scrollbar-3.69 {ScrollbarWidgetCmd procedure, "set" option} {
    .s set 100 -10 20 30
    .s get
} {100 0 20 30}
test scrollbar-3.70 {ScrollbarWidgetCmd procedure, "set" option} {
    .s set 100 50 30 20
    .s get
} {100 50 30 30}
test scrollbar-3.71 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set 1 2 3} msg] $msg
} {1 {wrong # args: should be ".s set firstFraction lastFraction"}}
test scrollbar-3.72 {ScrollbarWidgetCmd procedure, "set" option} {
    list [catch {.s set 1 2 3 4 5} msg] $msg
} {1 {wrong # args: should be ".s set firstFraction lastFraction"}}
test scrollbar-3.73 {ScrollbarWidgetCmd procedure} {
443
444
445
446
447
448
449
450

451
452
453

454
455
456

457
458
459

460
461

462
463
464

465
466
467
468
469
470
471

472
473
474
475
476
477
478

479
480
481

482
483
484
485
486
487
488
489
490
491
492

493
494
495
496


497
498
499
500
501
502
503
504
505
506
507
508


509
510
511
512


513
514
515
516
517
518
519
520
521
522







523
524
525
526


527
528

529
530
531

532
533
534
535
536
537

538
539
540
541
542
543
544
545
546


547
548
549

550
551
552
553
554
555
556
557
558

559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583

584
585

586
587
588
589
590
591
592
593
594


595
596
597
598
599
600

601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632

633
634
635
636
637
638
639

640
641
642
643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686

687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729
730
731

732
733
734
735
736
737
738
739
740
741
742
743
744
745
746

747
748
749
750

751
752
753
754
755
756
757
758
759
760
761
440
441
442
443
444
445
446

447
448
449

450
451
452

453
454
455

456
457

458
459
460

461







462
463




464

465
466
467

468
469
470
471
472
473
474
475
476
477
478

479
480
481


482
483
484
485
486
487
488
489
490
491
492
493


494
495
496
497


498
499
500
501
502
503
504
505
506



507
508
509
510
511
512
513
514
515


516
517
518

519



520
521





522
523
524




525


526
527
528
529

530
531
532
533
534
535




536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552

553
554
555




556

557
558

559
560
561




562


563
564
565
566




567
568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584

585


586
587
588
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603

604


605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642

643
644
645
646
647

648
649

650
651
652
653
654
655
656
657

658
659
660
661
662

663















664
665
666
667
668
669
670
671
672

673
674
675
676

677
678
679
680
681
682
683
684
685
686
687
688
689
690
691

692
693
694
695

696
697
698
699
700
701
702
703
704
705
706
707







-
+


-
+


-
+


-
+

-
+


-
+
-
-
-
-
-
-
-
+

-
-
-
-

-
+


-
+










-
+


-
-
+
+










-
-
+
+


-
-
+
+







-
-
-
+
+
+
+
+
+
+


-
-
+
+

-
+
-
-
-
+

-
-
-
-
-
+


-
-
-
-

-
-
+
+


-
+





-
-
-
-
+





-
+










-
+


-
-
-
-

-
+

-
+


-
-
-
-

-
-
+
+


-
-
-
-
+


-
+














-
+
-
-











-
+






-
+
-
-











-
+


















-
+







-





-
+

-
+







-





-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+



-
+














-
+



-
+











test scrollbar-6.4 {ScrollbarPosition procedure} unix {
    .s identify 3 100
} {}
test scrollbar-6.6 {ScrollbarPosition procedure} unix {
    .s identify 19 100
} {}
test scrollbar-6.7 {ScrollbarPosition procedure} {
    .s identify [expr {[winfo width .s] / 2}] -1
    .s identify [expr [winfo width .s] / 2] -1
} {}
test scrollbar-6.8 {ScrollbarPosition procedure} {
    .s identify [expr {[winfo width .s] / 2}] [winfo height .s]
    .s identify [expr [winfo width .s] / 2] [expr [winfo height .s]]
} {}
test scrollbar-6.9 {ScrollbarPosition procedure} {
    .s identify -1 [expr {[winfo height .s] / 2}]
    .s identify -1 [expr [winfo height .s] / 2]
} {}
test scrollbar-6.10 {ScrollbarPosition procedure} {
    .s identify [winfo width .s] [expr {[winfo height .s] / 2}]
    .s identify [winfo width .s] [expr [winfo height .s] / 2]
} {}
test scrollbar-6.11.1 {ScrollbarPosition procedure} x11 {
test scrollbar-6.11 {ScrollbarPosition procedure} unix {
    .s identify 8 4
} {arrow1}
test scrollbar-6.11.2 {ScrollbarPosition procedure} aqua {
test scrollbar-6.12 {ScrollbarPosition procedure} unix {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 8 4
} {trough1}
test scrollbar-6.12.1 {ScrollbarPosition procedure} x11 {
    # x11 scrollbars have arrows 19 pixels height,
    # but on XQuartz they are 15 pixels height
    .s identify 8 15
    .s identify 8 19
} {arrow1}
test scrollbar-6.12.2 {ScrollbarPosition procedure} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 8 15
} {trough1}
test scrollbar-6.14 {ScrollbarPosition procedure} win {
    .s identify [expr {[winfo width .s] / 2}] 0
    .s identify [expr [winfo width .s] / 2] 0
} {arrow1}
test scrollbar-6.15 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [expr {[testmetrics cyvscroll .s] - 1}]
    .s identify [expr [winfo width .s] / 2] [expr [testmetrics cyvscroll .s] - 1]
} {arrow1}
test scrollbar-6.16 {ScrollbarPosition procedure} unix {
    .s identify 8 20
} {trough1}
test scrollbar-6.17 {ScrollbarPosition procedure} {unix nonPortable} {
    # Don't know why this is non-portable, but it doesn't work on
    # some platforms.
    .s identify 8 51
} {trough1}
test scrollbar-6.18 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [testmetrics cyvscroll .s]
    .s identify [expr [winfo width .s] / 2] [testmetrics cyvscroll .s]
} {trough1}
test scrollbar-6.19 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [expr {int(.2 / [.s delta 0 1])
						+ [testmetrics cyvscroll .s] - 1}]
    .s identify [expr [winfo width .s] / 2] [expr int(.2 / [.s delta 0 1]) \
						+ [testmetrics cyvscroll .s] - 1]
} {trough1}
test scrollbar-6.20 {ScrollbarPosition procedure} unix {
    .s identify 8 52
} {slider}
test scrollbar-6.21 {ScrollbarPosition procedure} {unix nonPortable} {
    # Don't know why this is non-portable, but it doesn't work on
    # some platforms.
    .s identify 8 83
} {slider}
test scrollbar-6.22 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] \
	[expr {int(.2 / [.s delta 0 1] + 0.5) + [testmetrics cyvscroll .s]}]
    .s identify [expr [winfo width .s] / 2] \
	[expr int(.2 / [.s delta 0 1] + 0.5) + [testmetrics cyvscroll .s]]
} {slider}
test scrollbar-6.23 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [expr {int(.4 / [.s delta 0 1])
						 + [testmetrics cyvscroll .s] - 1}]
    .s identify [expr [winfo width .s] / 2] [expr int(.4 / [.s delta 0 1]) \
						 + [testmetrics cyvscroll .s] - 1]
} {slider}
test scrollbar-6.24 {ScrollbarPosition procedure} unix {
    .s identify 8 84
} {trough2}
test scrollbar-6.25 {ScrollbarPosition procedure} unix {
    .s identify 8 179
} {trough2}
test scrollbar-6.27 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [expr {int(.4 / [.s delta 0 1])
						 + [testmetrics cyvscroll .s]}]
test scrollbar-6.27 {ScrollbarPosition procedure} {testmetrics win knownBug} {
    # This asks for 8,21, which is actually the slider, but there is a
    # bug in that GetSystemMetrics(SM_CYVTHUMB) actually returns a value
    # that is larger than the thumb displayed, skewing the ability to
    # calculate the trough2 area correctly (Win2k).  -- hobbs
    .s identify [expr [winfo width .s] / 2] [expr int(.4 / [.s delta 0 1]) \
						 + [testmetrics cyvscroll .s]]
} {trough2}
test scrollbar-6.28 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}] [expr {[winfo height .s]
						 - [testmetrics cyvscroll .s] - 1}]
    .s identify [expr [winfo width .s] / 2] [expr [winfo height .s] \
						 - [testmetrics cyvscroll .s] - 1]
} {trough2}
test scrollbar-6.29.1 {ScrollbarPosition procedure} x11 {
test scrollbar-6.29 {ScrollbarPosition procedure} unix {
    # x11 scrollbars have arrows at least 19 pixels height
    # but on XQuartz they are 15 pixels height
    .s identify 8 184
    .s identify 8 180
} {arrow2}
test scrollbar-6.29.2 {ScrollbarPosition procedure} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 8 184
} {trough2}
test scrollbar-6.30.1 {ScrollbarPosition procedure} x11 {
test scrollbar-6.30 {ScrollbarPosition procedure} unix {
    .s identify 8 195
} {arrow2}
test scrollbar-6.30.2 {ScrollbarPosition procedure} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 8 195
} {trough2}
test scrollbar-6.32 {ScrollbarPosition procedure} {testmetrics win} {
    .s identify [expr {[winfo width .s] / 2}]  [expr {[winfo height .s]
						  - [testmetrics cyvscroll .s]}]
    .s identify [expr [winfo width .s] / 2]  [expr [winfo height .s] \
						  - [testmetrics cyvscroll .s]]
} {arrow2}
test scrollbar-6.33 {ScrollbarPosition procedure} win {
    .s identify [expr {[winfo width .s] / 2}] [expr {[winfo height .s] - 1}]
    .s identify [expr [winfo width .s] / 2] [expr [winfo height .s] - 1]
} {arrow2}
test scrollbar-6.34 {ScrollbarPosition procedure} unix {
    .s identify 4 100
} {trough2}
test scrollbar-6.35 {ScrollbarPosition procedure} unix {
    # Linux x11 scrollbars have arrows 18 pixels width
    # macOS XQuartz scrollbars have arrows 14 pixels width
    # macOS aqua scrollbars have no arrows nowadays
    .s identify 14 100
    .s identify 18 100
} {trough2}
test scrollbar-6.37 {ScrollbarPosition procedure} win {
    .s identify 0 100
} {trough2}
test scrollbar-6.38 {ScrollbarPosition procedure} win {
    .s identify [expr {[winfo width .s] - 1}] 100
    .s identify [expr [winfo width .s] - 1] 100
} {trough2}

catch {destroy .t}
toplevel .t -width 250 -height 150
wm geometry .t +0+0
scrollbar .t.s -orient horizontal -relief sunken -bd 2 -highlightthickness 2
place .t.s -width 200
.t.s set .2 .4
update

test scrollbar-6.39.1 {ScrollbarPosition procedure} x11 {
test scrollbar-6.39 {ScrollbarPosition procedure} unix {
    .t.s identify 4 8
} {arrow1}
test scrollbar-6.39.2 {ScrollbarPosition procedure} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .t.s identify 4 8
} {trough1}
test scrollbar-6.40 {ScrollbarPosition procedure} win {
    .t.s identify 0 [expr {[winfo height .t.s] / 2}]
    .t.s identify 0 [expr [winfo height .t.s] / 2]
} {arrow1}
test scrollbar-6.41.1 {ScrollbarPosition procedure} x11 {
test scrollbar-6.41 {ScrollbarPosition procedure} unix {
    .t.s identify 82 8
} {slider}
test scrollbar-6.41.2 {ScrollbarPosition procedure} aqua {
    # macOS aqua scrollbars have no arrows nowadays
    .t.s identify 82 8
} {trough2}
test scrollbar-6.43 {ScrollbarPosition procedure} {testmetrics win} {
    .t.s identify [expr {int(.4 / [.t.s delta 1 0]) + [testmetrics cxhscroll .t.s]
		       - 1}] [expr {[winfo height .t.s] / 2}]
    .t.s identify [expr int(.4 / [.t.s delta 1 0]) + [testmetrics cxhscroll .t.s] \
		       - 1] [expr [winfo height .t.s] / 2]
} {slider}
test scrollbar-6.44 {ScrollbarPosition procedure} unix {
    # Linux x11 scrollbars have arrows 18 pixels height
    # macOS XQuartz scrollbars have arrows 14 pixels height
    # macOS aqua scrollbars have no arrows nowadays
    .t.s identify 100 14
    .t.s identify 100 18
} {trough2}
test scrollbar-6.46 {ScrollbarPosition procedure} win {
    .t.s identify 100 [expr {[winfo height .t.s] - 1}]
    .t.s identify 100 [expr [winfo height .t.s] - 1]
} {trough2}

test scrollbar-7.1 {EventuallyRedraw} {
    .s configure -orient horizontal
    update
    set result [.s cget -orient]
    .s configure -orient vertical
    update
    lappend result [.s cget -orient]
} {horizontal vertical}

catch {destroy .t}
toplevel .t
wm geometry .t +0+0
test scrollbar-8.1 {TkScrollbarEventProc: recursive deletion} notAqua {
test scrollbar-8.1 {TkScrollbarEventProc: recursive deletion} {
    # constrained by notAqua because this test clicks on an arrow of the
    # scrollbar - but macOS has no such arrows in modern scrollbars
    proc doit {args} { destroy .t.f }
    proc bgerror {args} {}
    destroy .t.f
    frame .t.f
    scrollbar .t.f.s -command doit
    pack .t.f -fill both -expand 1
    pack .t.f.s -fill y -expand 1 -side right
    wm geometry .t 100x100
    .t.f.s set 0 .5
    update
    set result [winfo exists .t.f.s]
    event generate .t.f.s <Button> -button 1 -x [expr {[winfo width .t.f.s] / 2}] -y 5
    event generate .t.f.s <ButtonPress> -button 1 -x [expr [winfo width .t.f.s] / 2] -y 5
    event generate .t <ButtonRelease> -button 1
    update
    lappend result [winfo exists .t.f.s] [winfo exists .t.f]
    rename bgerror {}
    set result
} {1 0 0}
test scrollbar-8.2 {TkScrollbarEventProc: recursive deletion} notAqua {
test scrollbar-8.2 {TkScrollbarEventProc: recursive deletion} {
    # constrained by notAqua because this test clicks on an arrow of the
    # scrollbar - but macOS has no such arrows in modern scrollbars
    proc doit {args} { destroy .t.f.s }
    proc bgerror {args} {}
    destroy .t.f
    frame .t.f
    scrollbar .t.f.s -command doit
    pack .t.f -fill both -expand 1
    pack .t.f.s -fill y -expand 1 -side right
    wm geometry .t 100x100
    .t.f.s set 0 .5
    update
    set result [winfo exists .t.f.s]
    event generate .t.f.s <Button> -button 1 -x [expr {[winfo width .t.f.s] / 2}] -y 5
    event generate .t.f.s <ButtonPress> -button 1 -x [expr [winfo width .t.f.s] / 2] -y 5
    event generate .t.f <ButtonRelease> -button 1
    update
    lappend result [winfo exists .t.f.s] [winfo exists .t.f]
    rename bgerror {}
    set result
} {1 0 1}

set l [interp hidden]
deleteWindows

test scrollbar-9.1 {scrollbar widget vs hidden commands} {
    catch {destroy .s}
    scrollbar .s
    interp hide {} .s
    destroy .s
    list [winfo children .] [interp hidden]
} [list {} $l]

test scrollbar-10.1 {<MouseWheel> event on scrollbar} -setup {
test scrollbar-10.1 {<MouseWheel> event on scrollbar} -constraints {win|unix} -setup {
    destroy .t .s
} -body {
    pack [text .t -yscrollcommand {.s set}] -side left
    for {set i 1} {$i < 100} {incr i} {.t insert end "Line $i\n"}
    pack [scrollbar .s -command {.t yview}] -fill y -expand 1 -side left
    update
    focus -force .s
    event generate .s <Enter>
    event generate .s <MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {4.0}
} -result {5.0}

test scrollbar-10.2 {<MouseWheel> event on scrollbar} -setup {
test scrollbar-10.2 {<MouseWheel> event on scrollbar} -constraints {win|unix} -setup {
    destroy .t .s
} -body {
    pack [text .t -xscrollcommand {.s set} -wrap none] -side top
    for {set i 1} {$i < 100} {incr i} {.t insert end "Char $i "}
    pack [scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top
    update
    focus -force .s
    event generate .s <Enter>
    event generate .s <Shift-MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {1.3}
} -result {1.4}
test scrollbar-10.3 {<MouseWheel> event on horizontal scrollbar} -setup {
    destroy .t .s
} -body {
    pack [text .t -xscrollcommand {.s set} -wrap none] -side top
    for {set i 1} {$i < 100} {incr i} {.t insert end "Char $i "}
    pack [scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top
    update
    focus -force .s
    event generate .s <Enter>
    event generate .s <MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {1.3}

test scrollbar-11.1 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destruction} -body {
    proc destroy_scrollbar {} {
        if {[winfo exists .top.s]} {
            destroy .top.s
        }
    }
    toplevel .top
    scrollbar .top.s
    bind .top.s <Button-2> {destroy_scrollbar}
    bind .top.s <2> {destroy_scrollbar}
    pack .top.s
    focus -force .top.s
    update
    event generate .top.s <Button-2>
    event generate .top.s <2>
    update  ; # shall not trigger error  invalid command name ".top.s"
} -cleanup {
    destroy .top.s .top
} -result {}
test scrollbar-11.2 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destruction} -body {
    proc destroy_scrollbar {{y 0}} {
        if {[winfo exists .top.s]} {
            destroy .top.s
        }
    }
    toplevel .top
    wm minsize .top 50 400
    update
    scrollbar .top.s
    bind .top.s <Button-2> {after idle destroy_scrollbar}
    bind .top.s <2> {after idle destroy_scrollbar}
    pack .top.s -expand true -fill y
    focus -force .top.s
    update
    event generate .top.s <Button-2> -x 2 -y [expr {[winfo height .top.s] / 2}]
    event generate .top.s <2> -x 2 -y [expr {[winfo height .top.s] / 2}]
    update  ; # shall not trigger error  invalid command name ".top.s"
} -cleanup {
    destroy .top.s .top
} -result {}

catch {destroy .s}
catch {destroy .t}

# cleanup
cleanupTests
return

Changes to tests/select.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
1
2
3
4


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19








20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89




-
-
+
+













-
-
-
-
-
-
-
-












-
+


















-
+














-
+















-
+







# This file is a Tcl script to test out Tk's selection management code,
# especially the "selection" command. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

#
# Note: Multiple display selection handling will only be tested if the
# environment variable TK_ALT_DISPLAY is set to an alternate display.
#

package require tcltest 2.2
namespace import ::tcltest::*
namespace import ::tk::test:loadTkCommand
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint cliboardManagerPresent 0
if {![catch {selection get -selection CLIPBOARD_MANAGER -type TARGETS}]} {
    if {"SAVE_TARGETS" in [selection get -selection CLIPBOARD_MANAGER -type TARGETS]} {
        testConstraint cliboardManagerPresent 1
    }
}
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]

global longValue selValue selInfo

set selValue {}
set selInfo {}

proc handler {type offset count} {
    global selValue selInfo
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
    string range $selValue $offset [expr $numBytes+$offset]
}

proc errIncrHandler {type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
	if {$pass == 0} {
	    # Just sizing the selection;  don't do anything here.
	    set pass 1
	} else {
	    # Fetching the selection;  wait long enough to cause a timeout.
	    after 6000
	}
    }
    lappend selInfo $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
    string range $selValue $offset [expr $numBytes+$offset]
}

proc errHandler args {
    error "selection handler aborted"
}

proc badHandler {path type offset count} {
    global selValue selInfo
    selection handle -type $type $path {}
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
    string range $selValue $offset [expr $numBytes+$offset]
}
proc reallyBadHandler {path type offset count} {
    global selValue selInfo pass
    if {$offset == 4000} {
	if {$pass == 0} {
	    set pass 1
	} else {
	    selection handle -type $type $path {}
	}
    }
    lappend selInfo $path $type $offset $count
    set numBytes [expr {[string length $selValue] - $offset}]
    if {$numBytes <= 0} {
	return ""
    }
    string range $selValue $offset [expr {$numBytes+$offset}]
    string range $selValue $offset [expr $numBytes+$offset]
}

# Eliminate any existing selection on the screen.  This is needed in case
# there is a selection in some other application, in order to prevent races
# from causing false errors in the tests below.

selection clear .
330
331
332
333
334
335
336
337

338
339
340
341
342
343
344
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336







-
+







    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    selection own -command { set lostSel {lost2} } .f1
    set result $lostSel
    selection clear .f1
    lappend result $lostSel
} -result {owned lost2}
test select-3.7 {Tk_OwnSelection procedure} -constraints x11 -setup {
test select-3.7 {Tk_OwnSelection procedure} -constraints unix -setup {
    global lostSel
    setup
    setupbg
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410







-
+







    selection own -selection CLIPBOARD
} -result {.f1}
test select-4.3 {Tk_ClearSelection procedure} -setup {
    setup
} -body {
    list [selection clear .f1] [selection clear .f1]
} -result {{} {}}
test select-4.4 {Tk_ClearSelection procedure} -constraints x11 -setup {
test select-4.4 {Tk_ClearSelection procedure} -constraints unix -setup {
    global lostSel
    setup
    setupbg
} -body {
    set lostSel {owned}
    selection own -command { set lostSel {lost1} } .f1
    update
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442







-
+







    selection own -command { set lostSel2 {lost2} } .f2
    update
    selection clear -displayof .f2
    update
    list $lostSel $lostSel2
} -result {owned lost2}
test select-4.6 {Tk_ClearSelection procedure} -constraints {
    x11 altDisplay
    unix altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    set lostSel {owned}
    set lostSel2 {owned2}
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542

543
544
545
546
547
548
549
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541







-
+












-
+







    set selInfo ""
    selection handle .f1 {apply {{type offset count} {
	selection clear
	handler $type $offset $count
    }} STRING}
    list [selection get] $selInfo [catch {selection get} msg] $msg
} -result "$longValue {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000} 1 {PRIMARY selection doesn't exist or form \"STRING\" not defined}"
test select-5.9 {Tk_GetSelection procedure} -constraints x11 -setup {
test select-5.9 {Tk_GetSelection procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{Test value} {TEST 0 4000}}
test select-5.10 {Tk_GetSelection procedure} -constraints x11 -setup {
test select-5.10 {Tk_GetSelection procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    update
    set selValue "Test value"
    set selInfo ""
583
584
585
586
587
588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610







-
+




















-
+







    set result [list [catch {selection get TEST} msg] $msg $selInfo]
    set selValue "Test value2"
    set selInfo ""
    lappend result [catch {selection get -displayof .f2 TEST} msg] $msg \
	    $selInfo
} -result {0 {Test value} {TEST 0 4000} 1 {PRIMARY selection doesn't exist or form "TEST" not defined} {}}
test select-5.13 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
    unix altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
    selection handle -selection PRIMARY .f2 {handler TEST2} TEST
    selection own .f2
    set selValue "Test value"
    set selInfo ""
    update
    set result ""
    lappend result [dobg "toplevel .t -screen $env(TK_ALT_DISPLAY); wm geom .t +0+0; selection get -displayof .t TEST"]
    set selValue "Test value2"
    lappend result [dobg "selection get TEST"]
    cleanupbg
    lappend result $selInfo
} -result {{Test value} {Test value2} {TEST2 0 4000 TEST 0 4000}}
test select-5.14 {Tk_GetSelection procedure} -constraints {
    x11 altDisplay
    unix altDisplay
} -setup {
    setup .f1
    setup .f2 $env(TK_ALT_DISPLAY)
    setupbg
} -body {
    selection handle -selection PRIMARY .f1 {handler TEST} TEST
    selection own .f1
861
862
863
864
865
866
867
868

869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
907
908
909
910
911
912

913
914
915
916
917
918
919
920
921
922
923
924
925

926
927
928
929
930
931
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956

957
958
959
960
961
962
963
853
854
855
856
857
858
859

860
861
862
863
864
865
866

867
868
869
870
871
872
873
874
875

876
877
878
879
880
881
882
883
884
885
886
887
888
889

890
891
892
893
894
895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911
912
913
914
915

916
917
918
919
920
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946

947
948
949
950
951
952
953
954







-
+






-









-
+













-
+












-
+












-
+












-
+

















-
+







    destroy .f1
    lappend result [selection own] [catch {selection get} msg] $msg
} -result {.f1 {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined}}

##############################################################################

# Check reentrancy on losing selection
test select-8.1 {TkSelEventProc procedure} -constraints x11 -setup {
test select-8.1 {TkSelEventProc procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    selection own -selection CLIPBOARD -command {destroy .f1} .f1
    update
    dobg {selection own -selection CLIPBOARD .}
    winfo children .
} -cleanup {
    cleanupbg
} -result {}

##############################################################################

test select-9.1 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints x11 -body {
} -constraints unix -body {
    set selValue "1024"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
        .f1 {handler TEST}
    update
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x400 } {TEST 0 4000}}
test select-9.2 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
} -constraints unix -body {
    set selValue "1024 0xffff  2048 -2  "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x400 0xffff 0x800 0xfffffffe } {TEST 0 4000}}
test select-9.3 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
} -constraints unix -body {
    set selValue "   "
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{ } {TEST 0 4000}}
test select-9.4 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints {x11 failsOnUbuntu} -body {
} -constraints unix -body {
    set selValue "16 foobar 32"
    set selInfo ""
    selection handle -selection PRIMARY -format INTEGER -type TEST \
	.f1 {handler TEST}
    set result ""
    lappend result [dobg {selection get TEST}]
    cleanupbg
    lappend result $selInfo
} -result {{0x10 0x0 0x20 } {TEST 0 4000}}
test select-9.5 {SelCvtToX and SelCvtFromX procedures} -setup {
    setup
    setupbg
} -constraints x11 -body {
} -constraints unix -body {
    # Ensure that lists of atoms are constructed correctly, even when the
    # atom names have spaces in. [Bug 1353414]
    set selValue "foo bar"
    set selInfo ""
    set selType {text/x-tk-test;detail="foo bar"}
    selection handle -selection PRIMARY -format STRING -type $selType \
    .f1 [list handler $selType]
    lsort [dobg {selection get TARGETS}]
} -cleanup {
    cleanupbg
} -result {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW {text/x-tk-test;detail="foo bar"}}

##############################################################################
# note, we are not testing MULTIPLE style selections

# most control paths have been exercised above
test select-10.1 {ConvertSelection procedure, race with selection clear} -constraints {
    x11
    unix
} -setup {
    setup
} -body {
    proc Ready {fd} {
	variable x
	lappend x [gets $fd]
    }
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116

1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1183
970
971
972
973
974
975
976

977
978
979
980
981
982
983
984
985
986
987
988

989
990
991
992
993
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046


1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085

1086
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150

1151













1152
1153
1154
1155
1156
1157
1158
1159
1160







-
+











-
+











-
+














-
+














-
+















-
-





-
+

















-
+







-
+







-
+








-
+









-
+


















-
+















-
+










-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+








    puts $fd {exit}
    flush $fd
    # Don't understand why, but the [loadTkCommand] above causes
    # a "broken pipe" error when Tk was actually [load]ed in the child.
    catch {close $fd}
    lappend x $selInfo
} -result {{1:PRIMARY selection doesn't exist or form "STRING" not defined} {}}
test select-10.2 {ConvertSelection procedure} -constraints x11 -setup {
test select-10.2 {ConvertSelection procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    set selValue [string range $longValue 0 3999]
    set selInfo ""
    selection handle .f1 {handler STRING}
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result [list [string range $longValue 0 3999] {STRING 0 4000 STRING 4000 4000 STRING 0 4000 STRING 4000 4000}]
test select-10.3 {ConvertSelection procedure} -constraints x11 -setup {
test select-10.3 {ConvertSelection procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    selection handle .f1 ERROR errHandler
    dobg {selection get ERROR}
} -cleanup {
    cleanupbg
} -result {PRIMARY selection doesn't exist or form "ERROR" not defined}
# testing timers
# This one hangs in Exceed
test select-10.4 {ConvertSelection procedure} -constraints {
    x11 noExceed failsOnUbuntu
    unix noExceed
} -setup {
    setup
    setupbg
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {errIncrHandler STRING}
    set result ""
    set pass 0
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{selection owner didn't respond} {STRING 0 4000 STRING 4000 4000 STRING 8000 4000 STRING 12000 4000 STRING 16000 4000 STRING 0 4000 STRING 4000 4000}}
test select-10.5 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
    unix
} -setup {
    setup
    setupbg
} -body {
    set selValue "Test value"
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { badHandler .f1 STRING }
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000}}
test select-10.6 {ConvertSelection procedure, reentrancy issues} -constraints {
    x11 failsOnUbuntu
    unix
} -setup {
    setup
    setupbg
} -body {
    proc weirdHandler {type offset count} {
	destroy .f1
	handler $type $offset $count
    }
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {weirdHandler STRING}
    set result ""
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -cleanup {
    rename weirdHandler {}
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {STRING 0 4000}}

##############################################################################

# testing reentrancy
test select-11.1 {TkSelPropProc procedure} -constraints {x11 failsOnUbuntu} -setup {
test select-11.1 {TkSelPropProc procedure} -constraints unix -setup {
    setup
    setupbg
} -body {
    set selValue $longValue
    set selInfo ""
    selection handle -type TEST .f1 { handler TEST }
    selection handle -type STRING .f1 { reallyBadHandler .f1 STRING }
    set result ""
    set pass 0
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{selection owner didn't respond} {.f1 STRING 0 4000 .f1 STRING 4000 4000 .f1 STRING 8000 4000 .f1 STRING 12000 4000 .f1 STRING 16000 4000 .f1 STRING 0 4000 .f1 STRING 4000 4000}}

##############################################################################

# Note, this assumes we are using CurrentTtime
test select-12.1 {DefaultSelection procedure} -constraints x11 -body {
test select-12.1 {DefaultSelection procedure} -constraints unix -body {
    setup
    set result [selection get -type TIMESTAMP]
    setupbg
    lappend result [dobg {selection get -type TIMESTAMP}]
    cleanupbg
    set result
} -result {0x0 {0x0 }}
test select-12.2 {DefaultSelection procedure} -constraints x11 -body {
test select-12.2 {DefaultSelection procedure} -constraints unix -body {
    setup
    set result [lsort [list [selection get -type TARGETS]]]
    setupbg
    lappend result [dobg {lsort [selection get -type TARGETS]}]
    cleanupbg
    set result
} -result {{MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.3 {DefaultSelection procedure} -constraints x11 -body {
test select-12.3 {DefaultSelection procedure} -constraints unix -body {
    setup
    selection handle .f1 {handler TEST} TEST
    set result [list [lsort [selection get -type TARGETS]]]
    setupbg
    lappend result [dobg {lsort [selection get -type TARGETS]}]
    cleanupbg
    set result
} -result {{MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW} {MULTIPLE TARGETS TEST TIMESTAMP TK_APPLICATION TK_WINDOW}}
test select-12.4 {DefaultSelection procedure} -constraints x11 -setup {
test select-12.4 {DefaultSelection procedure} -constraints unix -setup {
    setup
    set result ""
} -body {
    lappend result [selection get -type TK_APPLICATION]
    setupbg
    lappend result [dobg {selection get -type TK_APPLICATION}]
    cleanupbg
    set result
} -result [list [winfo name .] [winfo name .]]
test select-12.5 {DefaultSelection procedure} -constraints x11 -body {
test select-12.5 {DefaultSelection procedure} -constraints unix -body {
    setup
    set result [selection get -type TK_WINDOW]
    setupbg
    lappend result [dobg {selection get -type TK_WINDOW}]
    cleanupbg
    set result
} -result {.f1 .f1}
test select-12.6 {DefaultSelection procedure} -body {
    setup
    selection handle .f1 {handler TARGETS.f1} TARGETS
    set selValue "Targets value"
    set selInfo ""
    set result [list [selection get TARGETS] $selInfo]
    selection handle .f1 {} TARGETS
    lappend result [selection get TARGETS]
} -result {{Targets value} {TARGETS.f1 0 4000} {MULTIPLE TARGETS TIMESTAMP TK_APPLICATION TK_WINDOW}}

test select-13.1 {SelectionSize procedure, handler deleted} -constraints {
    x11 failsOnUbuntu
    unix
} -setup {
    setup
    setupbg
} -body {
    proc badHandler {path type offset count} {
	global selValue selInfo abortCount
	incr abortCount -1
	if {$abortCount == 0} {
	    selection handle -type $type $path {}
	}
	lappend selInfo $path $type $offset $count
	set numBytes [expr {[string length $selValue] - $offset}]
	if {$numBytes <= 0} {
	    return ""
	}
	string range $selValue $offset [expr {$numBytes+$offset}]
	string range $selValue $offset [expr $numBytes+$offset]
    }
    set selValue $longValue
    set selInfo ""
    selection handle .f1 {badHandler .f1 STRING}
    set result ""
    set abortCount 2
    lappend result [dobg {selection get}]
    cleanupbg
    lappend result $selInfo
} -result {{PRIMARY selection doesn't exist or form "STRING" not defined} {.f1 STRING 0 4000 .f1 STRING 4000 4000}}


test select-14.1 {Bug [73ba07efcd]: Use correct property type when handling MULTIPLE conversion requests} -constraints {
    cliboardManagerPresent
} -setup {
    proc get_clip {offset maxChars} {return abcd}
} -body {
    selection handle -selection CLIPBOARD . get_clip
    selection own -selection CLIPBOARD .
    selection get -selection CLIPBOARD_MANAGER -type SAVE_TARGETS
    clipboard get
} -cleanup {
    rename get_clip {}
} -result {abcd}

catch {rename weirdHandler {}}

# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:

Changes to tests/send.test.

1
2
3
4
5
6
7
8




9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
1
2
3
4




5
6
7
8
9
10
11
12

13
14
15
16
17


18
19
20
21
22
23
24




-
-
-
-
+
+
+
+




-
+




-
-







# This file is a Tcl script to test out the "send" command and the
# other procedures in the file tkSend.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2001 ActiveState Corporation.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2001 by ActiveState Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint xhost [llength [auto_execok xhost]]
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Compute a script that will load Tk into a child interpreter.

foreach pkg [info loaded] {
    if {[lindex $pkg 1] == "Tk"} {
	set loadTk "load $pkg"
	break
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
193
194
195
196
197
198
199


200
201
202
203
204
205
206
207







-
-
+







} "name2 {$commId name2\n}"
test send-7.4 {Tk_SetAppName procedure, name in use} {secureserver testsend} {
    tk appname name1
    testsend prop root InterpRegistry "$id foo\n$id foo #2\n$id foo #3\n"
    list [tk appname foo] [testsend prop root InterpRegistry]
} "{foo #4} {$commId foo #4\n$id foo\n$id foo #2\n$id foo #3\n}"

#macOS does not send to other processes
test send-8.1 {Tk_SendCmd procedure, options} {secureserver notAqua} {
test send-8.1 {Tk_SendCmd procedure, options} {secureserver} {
    setupbg
    set app [dobg {tk appname}]
    set a 66
    send -async $app [list send [tk appname] set a 77]
    set result $a
    after 200 set x 40
    tkwait variable x
221
222
223
224
225
226
227
228
229

230
231
232
233
234

235
236
237
238
239
240
241
218
219
220
221
222
223
224


225
226
227
228
229

230
231
232
233
234
235
236
237







-
-
+




-
+







    set a altDisplay
    tk appname xyzgorp
    list \[send xyzgorp set a\] \[send -displayof .t xyzgorp set a\]
    "]
    cleanupbg
    set result
} {altDisplay homeDisplay}
# Since macOS has no registry of interpreters, 8.3 and 8.10 will fail.
test send-8.3 {Tk_SendCmd procedure, options} {secureserver notAqua} {
test send-8.3 {Tk_SendCmd procedure, options} {secureserver} {
    list [catch {send -- -async foo bar baz} msg] $msg
} {1 {no application named "-async"}}
test send-8.4 {Tk_SendCmd procedure, options} {secureserver} {
    list [catch {send -gorp foo bar baz} msg] $msg
} {1 {bad option "-gorp": must be -async, -displayof, or --}}
} {1 {no application named "-gorp"}}
test send-8.5 {Tk_SendCmd procedure, options} {secureserver} {
    list [catch {send -async foo} msg] $msg
} {1 {wrong # args: should be "send ?-option value ...? interpName arg ?arg ...?"}}
test send-8.6 {Tk_SendCmd procedure, options} {secureserver} {
    list [catch {send foo} msg] $msg
} {1 {wrong # args: should be "send ?-option value ...? interpName arg ?arg ...?"}}
test send-8.7 {Tk_SendCmd procedure, local execution} {secureserver} {
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263







-
+







    string tolower [list [catch {send [tk appname] open bad_file} msg] \
	    $msg $errorInfo $errorCode]
} {1 {couldn't open "bad_file": no such file or directory} {couldn't open "bad_file": no such file or directory
    while executing
"open bad_file"
    invoked from within
"send [tk appname] open bad_file"} {posix enoent {no such file or directory}}}
test send-8.10 {Tk_SendCmd procedure, no such interpreter} {secureserver notAqua} {
test send-8.10 {Tk_SendCmd procedure, no such interpreter} {secureserver} {
    list [catch {send bogus_name bogus_command} msg] $msg
} {1 {no application named "bogus_name"}}

catch {
    newApp "" t_s_1 Test
    t_s_1 eval wm withdraw .
}
284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304







-
+









-
+







test send-8.14 {Tk_SendCmd procedure, local interp killed by send} {secureserver testsend} {
    newApp "" t_s_2 Test
    list [catch {send t_s_2 {destroy .; concat result}} msg] $msg
} {0 result}

catch {interp delete t_s_2}

test send-8.15 {Tk_SendCmd procedure, local interp, error info} {secureserver testsend failsOnUbuntu} {
test send-8.15 {Tk_SendCmd procedure, local interp, error info} {secureserver testsend} {
    catch {error foo}
    list [catch {send t_s_1 {if 1 {open bogus_file_name}}} msg] $msg $errorInfo $errorCode
} {1 {couldn't open "bogus_file_name": no such file or directory} {couldn't open "bogus_file_name": no such file or directory
    while executing
"open bogus_file_name"
    invoked from within
"if 1 {open bogus_file_name}"
    invoked from within
"send t_s_1 {if 1 {open bogus_file_name}}"} {POSIX ENOENT {no such file or directory}}}
test send-8.16 {Tk_SendCmd procedure, bogusCommWindow} {secureserver testsend failsOnUbuntu failsOnXQuarz} {
test send-8.16 {Tk_SendCmd procedure, bogusCommWindow} {secureserver testsend} {
    testsend prop root InterpRegistry "10234 bogus\n"
    set result [list [catch {send bogus bogus command} msg] $msg]
    winfo interps
    tk appname tktest
    set result
} {1 {no application named "bogus"}}

399
400
401
402
403
404
405
406

407
408
409
410
411
412
413

414
415
416
417
418
419
420
395
396
397
398
399
400
401

402
403
404
405
406
407
408

409
410
411
412
413
414
415
416







-
+






-
+







} {12345 newA newB}
test send-10.4 {SendEventProc procedure, leading nulls, bogus commands} {secureserver testsend} {
    testsend prop comm Comm \
	    "\n\nx\n-bogus\n\nc\n-n tktest\n-s set a 44\n"
    set a null
    update
    set a
} 44
} {44}
test send-10.5 {SendEventProc procedure, extraneous command options} {secureserver testsend} {
    testsend prop comm Comm \
	    "c\n-n tktest\n-x miscellanous\n-y who knows?\n-s set a new\n"
    set a null
    update
    set a
} new
} {new}
test send-10.6 {SendEventProc procedure, unknown interpreter} {secureserver testsend} {
    testsend prop [winfo id .f] Comm {}
    testsend prop comm Comm \
	    "c\n-n unknown\n-r $id 44\n-s set a new\n"
    set a null
    update
    list [testsend prop [winfo id .f] Comm] $a
438
439
440
441
442
443
444


445




446
447
448
449
450
451


452



453
454
455
456
457
458
459
434
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462
463
464







+
+
-
+
+
+
+






+
+
-
+
+
+







}
test send-10.8 {SendEventProc procedure, exceptional return} {secureserver testsend} {
    testsend prop [winfo id .f] Comm {}
    testsend prop comm Comm \
	    "c\n-n tktest\n-r $id 62\n-s break\n"
    update
    testsend prop [winfo id .f] Comm
} {
r
} "\nr\n-s 62\n-r \n-c 3\n"
-s 62
-r 
-c 3
}
test send-10.9 {SendEventProc procedure, empty return} {secureserver testsend} {
    testsend prop [winfo id .f] Comm {}
    testsend prop comm Comm \
	    "c\n-n tktest\n-r $id 62\n-s concat\n"
    update
    testsend prop [winfo id .f] Comm
} {
r
} "\nr\n-s 62\n-r \n"
-s 62
-r 
}
test send-10.10 {SendEventProc procedure, asynchronous calls} {secureserver testsend} {
    testsend prop [winfo id .f] Comm {}
    testsend prop comm Comm \
	    "c\n-n tktest\n-s foreach i {1 2 3} {error {test error} {Initial errorInfo} {test code}}\n"
    update
    testsend prop [winfo id .f] Comm
} {}
511
512
513
514
515
516
517
518

519
520
521


522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566

567
568
569
570
571
572
573
516
517
518
519
520
521
522

523
524


525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544


545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

560
561

562
563
564
565
566
567
568

569
570
571
572
573
574
575
576







-
+

-
-
+
+


















-
-
+














-


-
+






-
+







    setupbg
    dobg {tk appname t_s_3}
    set x [list [catch {send t_s_3 exit} msg] $msg]
    cleanupbg
    set x
} {1 {target application died}}

test send-11.1 {AppendPropCarefully and AppendErrorProc procedures} -constraints {secureserver testsend} -body {
test send-11.1 {AppendPropCarefully and AppendErrorProc procedures} {secureserver testsend} {
    testsend prop root InterpRegistry "0x21447 dummy\n"
    send dummy foo
} -returnCodes 1 -match regexp -result {^(target application died|no application named "dummy")$}
    list [catch {send dummy foo} msg] $msg
} {1 {no application named "dummy"}}
test send-11.2 {AppendPropCarefully and AppendErrorProc procedures} {secureserver testsend} {
    testsend prop comm Comm "c\n-r0x123 44\n-n tktest\n-s concat a b c\n"
    update
} {}

winfo interps
tk appname tktest
catch {destroy .f}
frame .f
set id [string range [winfo id .f] 2 end]

test send-12.1 {TimeoutProc procedure} {secureserver testsend} {
    testsend prop root InterpRegistry "$id dummy\n"
    list [catch {send dummy foo} msg] $msg
} {1 {target application died or uses a Tk version before 4.0}}

catch {testsend prop root InterpRegistry ""}

#macOS does not send to other processes
test send-12.2 {TimeoutProc procedure} {secureserver notAqua} {
test send-12.2 {TimeoutProc procedure} {secureserver} {
    winfo interps
    tk appname tktest
    update
    setupbg
    set app [dobg {
	after 10 {after 10 {after 5000; exit}}
	tk appname
    }]
    after 200
    set result [list [catch {send $app foo} msg] $msg]
    cleanupbg
    set result
} {1 {target application died}}

#macOS does not send to other processes
winfo interps
tk appname tktest
test send-13.1 {DeleteProc procedure} {secureserver notAqua} {
test send-13.1 {DeleteProc procedure} {secureserver} {
    setupbg
    set app [dobg {rename send {}; tk appname}]
    set result [list [catch {send $app foo} msg] $msg [winfo interps]]
    cleanupbg
    set result
} {1 {no application named "tktest #2"} tktest}
test send-13.2 {DeleteProc procedure} {secureserver notAqua} {
test send-13.2 {DeleteProc procedure} {secureserver} {
    winfo interps
    tk appname tktest
    rename send {}
    set result {}
    lappend result [winfo interps] [info commands send]
    tk appname foo
    lappend result [winfo interps] [info commands send]

Changes to tests/spinbox.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
1
2
3



4
5
6
7
8
9
10
11
12
13
14

15
16
17
18

19
20
21
22
23
24
25
26



-
-
-
+
+
+








-




-
+







# This file is a Tcl script to test spinbox widgets in Tk.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

# For xscrollcommand
set scrollInfo {}
proc scroll args {
        global scrollInfo
        set scrollInfo $args
}
# For trace add variable
# For trace variable
proc override args {
        global x
        set x 12345
}

# Procedures used in widget VALIDATION tests
proc doval {W d i P s S v V} {
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
+









-
+







    pack .e
    update
} -body {
    .e configure -bd 4
    .e cget -bd
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-1.6 {configuration option: "bd" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -bd badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test spinbox-1.7 {configuration option: "bg"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157







-
+









-
+







    pack .e
    update
} -body {
    .e configure -borderwidth 1.3
    .e cget -borderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-1.10 {configuration option: "borderwidth" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -borderwidth badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test spinbox-1.11 {configuration option: "buttonbackground"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







-
+







    pack .e
    update
} -body {
    .e configure -exportselection yes
    .e cget -exportselection
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-1.23 {configuration option: "exportselection" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -exportselection xyzzy
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489







-
+









-
+











-
+







    pack .e
    update
} -body {
    .e configure -highlightthickness 6
    .e cget -highlightthickness
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test spinbox-1.39 {configuration option: "highlightthickness" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -highlightthickness bogus
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "bogus"}
} -returnCodes {error} -result {bad screen distance "bogus"}

test spinbox-1.40 {configuration option: "highlightthickness"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -highlightthickness -2
    .e cget -highlightthickness
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test spinbox-1.41 {configuration option: "increment"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
523
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
522
523
524
525
526
527
528

529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
555
556
557
558
559

560
561
562
563
564
565
566
567







-
+








-
+









-
+











-
+







} -body {
    .e configure -insertbackground bogus
} -cleanup {
    destroy .e
} -returnCodes {error} -result {unknown color name "bogus"}

test spinbox-1.45 {configuration option: "insertborderwidth"} -setup {
        spinbox .e -borderwidth 2 -insertwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -insertborderwidth 1.3
    .e cget -insertborderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-1.46 {configuration option: "insertborderwidth" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -insertborderwidth 2.6x
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "2.6x"}
} -returnCodes {error} -result {bad screen distance "2.6x"}

test spinbox-1.47 {configuration option: "insertofftime"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -insertofftime 100
    .e cget -insertofftime
} -cleanup {
    destroy .e
} -result 100
} -result {100}
test spinbox-1.48 {configuration option: "insertofftime" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -insertofftime 3.2
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589







-
+







    pack .e
    update
} -body {
    .e configure -insertontime 100
    .e cget -insertontime
} -cleanup {
    destroy .e
} -result 100
} -result {100}
test spinbox-1.50 {configuration option: "insertontime" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -insertontime 3.2
688
689
690
691
692
693
694
695

696
697
698
699
700
701
702
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701







-
+







    pack .e
    update
} -body {
    .e configure -repeatdelay 500
    .e cget -repeatdelay
} -cleanup {
    destroy .e
} -result 500
} -result {500}
test spinbox-1.60 {configuration option: "repeatdelay" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -repeatdelay 3p
710
711
712
713
714
715
716
717

718
719
720
721
722
723
724
709
710
711
712
713
714
715

716
717
718
719
720
721
722
723







-
+







    pack .e
    update
} -body {
    .e configure -repeatinterval -500
    .e cget -repeatinterval
} -cleanup {
    destroy .e
} -result -500
} -result {-500}
test spinbox-1.62 {configuration option: "repeatinterval" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -repeatinterval 3p
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778
753
754
755
756
757
758
759

760
761
762
763
764
765
766
767
768
769

770
771
772
773
774
775
776
777







-
+









-
+







    pack .e
    update
} -body {
    .e configure -selectborderwidth 1.3
    .e cget -selectborderwidth
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-1.66 {configuration option: "selectborderwidth" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -selectborderwidth badValue
} -cleanup {
    destroy .e
} -returnCodes {error} -result {expected screen distance but got "badValue"}
} -returnCodes {error} -result {bad screen distance "badValue"}

test spinbox-1.67 {configuration option: "selectforeground"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
912
913
914
915
916
917
918
919

920
921
922
923
924
925
926


927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

942
943
944
945
946
947
948
911
912
913
914
915
916
917

918
919
920
921
922
923


924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939

940
941
942
943
944
945
946
947







-
+





-
-
+
+














-
+







    update
} -body {
    .e configure -values {bad {}list}
} -cleanup {
    destroy .e
} -returnCodes {error} -result {list element in braces followed by "list" instead of space}

test spinbox-1.80 {configuration option: "validatecommand"} -setup {
test spinbox-1.80 {configuration option: "vcmd"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -validatecommand "a command"
    .e cget -validatecommand
    .e configure -vcmd "a command"
    .e cget -vcmd
} -cleanup {
    destroy .e
} -result {a command}

test spinbox-1.81 {configuration option: "width"} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -width 402
    .e cget -width
} -cleanup {
    destroy .e
} -result 402
} -result {402}
test spinbox-1.82 {configuration option: "width" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -width 3p
956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
955
956
957
958
959
960
961

962
963
964
965
966
967
968
969







-
+







    pack .e
    update
} -body {
    .e configure -wrap yes
    .e cget -wrap
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-1.84 {configuration option: "wrap" for spinbox} -setup {
        spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
        -relief sunken
    pack .e
    update
} -body {
    .e configure -wrap xyzzy
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1082
1083
1084
1085
1086
1087
1088

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1109







-
+












-
+







	fonts
} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): utf at end
    .e insert 0 "ab"
    .e insert 0 "ab\u4e4e"
    .e bbox end
} -cleanup {
    destroy .e
} -result {19 5 12 13}
test spinbox-3.8 {SpinboxWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
# Tcl_UtfAtIndex(): utf before index
    .e insert 0 "abc"
    .e insert 0 "ab\u4e4ec"
    .e bbox 3
} -cleanup {
    destroy .e
} -result {31 5 7 13}
test spinbox-3.9 {SpinboxWidgetCmd procedure, "bbox" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127
1128
1129
1130
1131







-
+







test spinbox-3.10 {SpinboxWidgetCmd procedure, "bbox" widget command} -constraints {
	fonts
} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
    .e insert 0 "abcdefghijklmnop"
    .e insert 0 "abcdefghij\u4e4eklmnop"
    list [.e bbox 0] [.e bbox 1] [.e bbox 10] [.e bbox end]
} -cleanup {
    destroy .e
} -result {{5 5 7 13} {12 5 7 13} {75 5 12 13} {122 5 7 13}}
test spinbox-3.11 {SpinboxWidgetCmd procedure, "cget" widget command} -setup {
    spinbox .e
} -body {
1151
1152
1153
1154
1155
1156
1157
1158

1159
1160
1161
1162
1163
1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181

1182
1183
1184
1185
1186
1187
1188
1189







-
+








-
+















-
+







test spinbox-3.14 {SpinboxWidgetCmd procedure, "cget" widget command} -setup {
    spinbox .e
} -body {
    .e configure -bd 4
    .e cget -bd
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-3.15 {SpinboxWidgetCmd procedure, "configure" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    llength [.e configure]
} -cleanup {
    destroy .e
} -result 51
} -result {49}
test spinbox-3.16 {SpinboxWidgetCmd procedure, "configure" widget command} -setup {
    spinbox .e
} -body {
    .e configure -foo
} -cleanup {
    destroy .e
} -returnCodes error -result {unknown option "-foo"}
test spinbox-3.17 {SpinboxWidgetCmd procedure, "configure" widget command} -setup {
    spinbox .e
} -body {
    .e configure -bd 4
    .e configure -bg #ffffff
    lindex [.e configure -bd] 4
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-3.18 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
} -body {
    .e delete
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e delete firstIndex ?lastIndex?"}
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243

1244
1245
1246
1247

1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1214
1215
1216
1217
1218
1219
1220

1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241

1242
1243
1244
1245

1246
1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287

1288
1289
1290
1291
1292
1293
1294
1295







-
+








-
+







-
+



-
+



-
+




-
+










-
+












-
+












-
+







    update
} -body {
    .e insert end "01234567890"
    .e delete 2 4
    .e get
} -cleanup {
    destroy .e
} -result 014567890
} -result {014567890}
test spinbox-3.23 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
} -body {
    .e insert end "01234567890"
    .e delete 6
    .e get
} -cleanup {
    destroy .e
} -result 0123457890
} -result {0123457890}
test spinbox-3.24 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
    set x {}
} -body {
# UTF
    .e insert end "0123467890"
    .e insert end "01234\u4e4e67890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123457890"
    .e insert end "012345\u4e4e7890"
    .e delete 6
    lappend x [.e get]
    .e delete 0 end
    .e insert end "0123456890"
    .e insert end "0123456\u4e4e890"
    .e delete 6
    lappend x [.e get]
} -cleanup {
    destroy .e
} -result [list "012347890" "0123457890" "012345890"]
} -result [list "01234\u4e4e7890" "0123457890" "012345\u4e4e890"]
test spinbox-3.25 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e delete 6 5
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test spinbox-3.26 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state disabled
    .e delete 2 8
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test spinbox-3.26.1 {SpinboxWidgetCmd procedure, "delete" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state readonly
    .e delete 2 8
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test spinbox-3.27 {SpinboxWidgetCmd procedure, "get" widget command} -setup {
    spinbox .e
} -body {
    .e get foo
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e get"}
1312
1313
1314
1315
1316
1317
1318
1319

1320
1321
1322
1323
1324
1325
1326
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
1325







-
+







    spinbox .e
} -body {
    .e insert end "01234567890"
    .e icursor 4
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-3.31 {SpinboxWidgetCmd procedure, "index" widget command} -setup {
    spinbox .e
} -body {
    .e in
} -cleanup {
    destroy .e
} -returnCodes error -result {ambiguous option "in": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, invoke, scan, selection, set, validate, or xview}
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362







-
+







} -returnCodes {ok} -match glob -result {*}
test spinbox-3.35 {SpinboxWidgetCmd procedure, "index" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
# UTF
    .e insert 0 abc乎œdef
    .e insert 0 abc\u4e4e\u0153def
    list [.e index 3] [.e index 4] [.e index end]
} -cleanup {
    destroy .e
} -result {3 4 8}
test spinbox-3.36 {SpinboxWidgetCmd procedure, "insert" widget command} -setup {
    spinbox .e
} -body {
1398
1399
1400
1401
1402
1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418

1419
1420
1421
1422
1423
1424
1425
1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416

1417
1418
1419
1420
1421
1422
1423
1424







-
+












-
+







    .e insert end "01234567890"
    .e configure -state disabled
    .e insert 3 xxx
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test spinbox-3.40.1 {SpinboxWidgetCmd procedure, "insert" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end "01234567890"
    .e configure -state readonly
    .e insert 3 xxx
    .e configure -state normal
    .e get
} -cleanup {
    destroy .e
} -result 01234567890
} -result {01234567890}
test spinbox-3.41 {SpinboxWidgetCmd procedure, "insert" widget command} -setup {
    spinbox .e
} -body {
    .e insert a b c
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e insert index text"}
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1444
1445
1446
1447
1448
1449
1450

1451
1452
1453
1454
1455
1456
1457
1458







-
+







    spinbox .e
    pack .e
    update
} -body {
    .e scan foobar 20
} -cleanup {
    destroy .e
} -returnCodes error -result {bad scan option "foobar": must be dragto or mark}
} -returnCodes error -result {bad scan option "foobar": must be mark or dragto}
test spinbox-3.45 {SpinboxWidgetCmd procedure, "scan" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e scan mark 20.1
} -cleanup {
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1470
1471
1472
1473
1474
1475
1476

1477
1478
1479
1480
1481
1482
1483
1484







-
+







    .e insert end "This is quite a long string, in fact a "
    .e insert end "very very long string"
    .e scan mark 30
    .e scan dragto 28
    .e index @0
} -cleanup {
    destroy .e
} -result 2
} -result {2}
test spinbox-3.47 {SpinboxWidgetCmd procedure, "select" widget command} -setup {
    spinbox .e
} -body {
    .e select
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection option ?index?"}
1540
1541
1542
1543
1544
1545
1546
1547

1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560

1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573
1574
1575
1576
1577
1578
1579







-
+












-
+












-
+







} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e selection present
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-3.53 {SpinboxWidgetCmd procedure, "selection present" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e configure -exportselection false
    .e selection present
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-3.54 {SpinboxWidgetCmd procedure, "selection present" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    .e delete 0 end
    .e selection present
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test spinbox-3.55 {SpinboxWidgetCmd procedure, "selection adjust" widget command} -setup {
    spinbox .e
} -body {
    .e select adjust x
} -cleanup {
    destroy .e
} -returnCodes error -result {bad spinbox index "x"}
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620
1621
1622
1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613

1614
1615
1616
1617
1618
1619
1620
1621







-
+













-
+







    .e select from 1
    .e select to 5
    update
    .e select adjust 4
    selection get
} -cleanup {
    destroy .e
} -result 123
} -result {123}
test spinbox-3.58 {SpinboxWidgetCmd procedure, "selection adjust" widget command} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e insert end "0123456789"
    .e select from 1
    .e select to 5
    update
    .e select adjust 2
    selection get
} -cleanup {
    destroy .e
} -result 234
} -result {234}
test spinbox-3.59 {SpinboxWidgetCmd procedure, "selection from" widget command} -setup {
    spinbox .e
} -body {
    .e select from 2 3
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e selection from index"}
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
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







-
+










-
+







    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview scroll 24
} -cleanup {
    destroy .e
} -returnCodes error -result {wrong # args: should be ".e xview scroll number pages|units"}
} -returnCodes error -result {wrong # args: should be ".e xview scroll number units|pages"}
test spinbox-3.72 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview scroll gorp units
} -cleanup {
    destroy .e
} -returnCodes error -result {expected floating-point number but got "gorp"}
} -returnCodes error -result {expected integer but got "gorp"}
test spinbox-3.73 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
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
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







-
+













-
+










-
+




















-
+



-
+











-
+






-
+







    update
    .e xview 30
    update
    .e xview scroll 2 units
    .e index @0
} -cleanup {
    destroy .e
} -result 32
} -result {32}
test spinbox-3.76 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview 30
    update
    .e xview scroll -1 units
    .e index @0
} -cleanup {
    destroy .e
} -result 29
} -result {29}
test spinbox-3.77 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview scroll 23 foobars
} -cleanup {
    destroy .e
} -returnCodes error -result {bad argument "foobars": must be pages or units}
} -returnCodes error -result {bad argument "foobars": must be units or pages}
test spinbox-3.78 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview eat 23 hamburgers
} -cleanup {
    destroy .e
} -returnCodes error -result {unknown option "eat": must be moveto or scroll}
test spinbox-3.79 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
    update
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e xview 0
    update
    .e xview {}
    .e xview -4
    .e index @0
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test spinbox-3.80 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    update
    .e xview 300
    .e index @0
} -cleanup {
    destroy .e
} -result 73
} -result {73}
test spinbox-3.81 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
    spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e insert end "This is quite a long text string, so long that it "
    .e insert end "runs off the end of the window quite a bit."
    .e insert 10 
    .e insert 10 \u4e4e
    update
# UTF
# If Tcl_NumUtfChars wasn't used, wrong answer would be:
# 0.106383 0.117021 0.117021
    set x {}
    .e xview moveto .1
    lappend x [format {%.6f} [lindex [.e xview] 0]]
1923
1924
1925
1926
1927
1928
1929
1930

1931
1932
1933
1934
1935
1936
1937
1922
1923
1924
1925
1926
1927
1928

1929
1930
1931
1932
1933
1934
1935
1936







-
+








test spinbox-5.1 {ConfigureSpinbox procedure, -textvariable} -body {
    set x 12345
    spinbox .e -textvariable x
    .e get
} -cleanup {
    destroy .e
} -result 12345
} -result {12345}
test spinbox-5.2 {ConfigureSpinbox procedure, -textvariable} -body {
    set x 12345
    spinbox .e -textvariable x
    set y abcde
    .e configure -textvariable y
    set x 54321
    .e get
1948
1949
1950
1951
1952
1953
1954
1955

1956
1957
1958
1959
1960
1961

1962
1963
1964
1965
1966
1967
1968
1947
1948
1949
1950
1951
1952
1953

1954
1955
1956
1957
1958
1959

1960
1961
1962
1963
1964
1965
1966
1967







-
+





-
+







} -cleanup {
    destroy .e
} -result {Some text}
test spinbox-5.4 {ConfigureSpinbox procedure, -textvariable} -setup {
    unset -nocomplain x
    spinbox .e
} -body {
    trace add variable x write override
    trace variable x w override
    .e insert 0 "Some text"
    .e configure -textvariable x
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    trace vdelete x w override
} -result {12345 12345}

test spinbox-5.5 {ConfigureSpinbox procedure} -setup {
    set x {}
    spinbox .e1
    spinbox .e2
} -body {
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024

2025
2026
2027
2028
2029
2030
2031
2010
2011
2012
2013
2014
2015
2016

2017

2018
2019
2020

2021
2022
2023
2024
2025
2026
2027
2028







-

-



-
+







test spinbox-5.7 {ConfigureSpinbox procedure} -setup {
    spinbox .e -font {Helvetica -12} -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
    .e configure -font {Courier -12} -width 4 -xscrollcommand scroll
    .e insert end "01234567890"
    update
    set scrollInfo wrong
    .e configure -width 5
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 0.454545}
} -result {0.000000 0.363636}

test spinbox-5.8 {ConfigureSpinbox procedure} -constraints {
    fonts
} -setup {
    spinbox .e -borderwidth 2 -highlightthickness 2
    pack .e
} -body {
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
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







-
+











-
+







    .e configure -font {Courier -12} -bd 2 -relief raised -width 5
    .e insert end "01234567890"
    update
    .e xview 6
    .e index @0
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test spinbox-6.5 {SpinboxComputeGeometry procedure} -setup {
    spinbox .e -highlightthickness 2
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 5
    .e insert end "01234567890"
    update
    .e xview 7
    .e index @0
} -cleanup {
    destroy .e
} -result 6
} -result {6}
test spinbox-6.6 {SpinboxComputeGeometry procedure} -constraints {
    fonts
} -setup {
    spinbox .e -highlightthickness 2
    pack .e
} -body {
    .e configure -font {Courier -12} -bd 2 -relief raised -width 10
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
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







-
-















-
-







    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 2 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abXXXcde abXXXcde {0.000000 1.000000}}

test spinbox-7.2 {InsertChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e insert 500 XXX
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abcdeXXX abcdeXXX {0.000000 1.000000}}
test spinbox-7.3 {InsertChars procedure} -setup {
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
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







-
+










-
+











-
+











-
+













-
+









-
-














-
-
-
+













-
-







    .e configure -xscrollcommand scroll
    .e insert 0 0123456789
    .e icursor 4
    .e insert 4 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 7
} -result {7}
test spinbox-7.8 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 0123456789
    .e icursor 4
    .e insert 5 XXX
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-7.9 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 3 XXX
    .e index @0
} -cleanup {
    destroy .e
} -result 7
} -result {7}
test spinbox-7.10 {InsertChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 "This is a very long string"
    update
    .e xview 4
    .e insert 4 XXX
    .e index @0
} -cleanup {
    destroy .e
} -result 4
} -result {4}

test spinbox-7.11 {InsertChars procedure} -constraints {
    fonts
} -setup {
    spinbox .e -width 0 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e insert 0 "xyzzy"
    update
    .e insert 2 00
    winfo reqwidth .e
} -cleanup {
    destroy .e
} -result 70
} -result {70}

test spinbox-8.1 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 2 4
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abe abe {0.000000 1.000000}}
test spinbox-8.2 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete {} 2
    .e delete -2 2
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {cde cde {0.000000 1.000000}}
test spinbox-8.3 {DeleteChars procedure} -setup {
    unset -nocomplain contents
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e configure -textvariable contents -xscrollcommand scroll
    .e insert 0 abcde
    update
    set scrollInfo wrong
    .e delete 3 1000
    update
    list [.e get] $contents [format {%.6f %.6f} {*}$scrollInfo]
} -cleanup {
    destroy .e
} -result {abc abc {0.000000 1.000000}}
test spinbox-8.4 {DeleteChars procedure} -setup {
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
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







-
+












-
+












-
+












-
+












-
+












-
+







    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 4
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-8.13 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 1 5
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-8.14 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 0123456789abcde
    .e icursor 4
    .e delete 4 6
    update
    .e index insert
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-8.15 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 4
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-8.16 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 1 5
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-8.17 {DeleteChars procedure} -setup {
    spinbox .e -width 10 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 "This is a very long string"
    .e xview 4
    .e delete 4 6
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-8.18 {DeleteChars procedure} -setup {
    spinbox .e -width 0 -font {Courier -12} -highlightthickness 2 -bd 2
    pack .e
    focus .e
} -body {
    .e insert 0 "xyzzy"
    update
2639
2640
2641
2642
2643
2644
2645
2646

2647
2648
2649
2650
2651
2652

2653
2654
2655
2656
2657
2658
2659
2626
2627
2628
2629
2630
2631
2632

2633
2634
2635
2636
2637
2638

2639
2640
2641
2642
2643
2644
2645
2646







-
+





-
+







    destroy .e
    unset XPAD buttonWidth expected
} -result {1}

test spinbox-9.1 {SpinboxValueChanged procedure} -setup {
    unset -nocomplain x
} -body {
    trace add variable x write override
    trace variable x w override
    spinbox .e -textvariable x -width 0
    .e insert 0 foo
    list $x [.e get]
} -cleanup {
    destroy .e
    trace remove variable x write override
    trace vdelete x w override
} -result {12345 12345}


test spinbox-10.1 {SpinboxSetValue procedure} -constraints fonts -body {
    set x abcde
    set y ab
    spinbox .e  -font {Helvetica -12} -highlightthickness 2 -bd 2  -width 0
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
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







-
+















-
+














-
+













-
+







    .e xview 10
    update
    set x "abcdefg"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test spinbox-10.6 {SpinboxSetValue procedure, updating display position} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e xview 10
    update
    set x "1234567890123456789012"
    update
    .e index @0
} -cleanup {
    destroy .e
} -result 10
} -result {10}
test spinbox-10.7 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
    update
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123"
    .e index insert
} -cleanup {
    destroy .e
} -result 3
} -result {3}
test spinbox-10.8 {SpinboxSetValue procedure, updating insertion cursor} -setup {
    unset -nocomplain x
    spinbox .e -highlightthickness 2 -bd 2
    pack .e
} -body {
    .e configure -width 10 -font {Courier -12} -textvariable x
    pack .e
    .e insert 0 "abcdefghjklmnopqrstuvwxyz"
    .e icursor 5
    set x "123456"
    .e index insert
} -cleanup {
    destroy .e
} -result 5
} -result {5}

test spinbox-11.1 {SpinboxEventProc procedure} -setup {
    spinbox .e -highlightthickness 2 -bd 2 -font {Helvetica -12}
    pack .e
} -body {
    .e insert 0 abcdefg
    destroy .e
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
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







-
+


















-
+












-
+













-
+


















-
+







} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index end
} -cleanup {
    destroy .e
} -result 21
} -result {21}
test spinbox-13.2 {GetSpinboxIndex procedure} -body {
    spinbox .e
    .e index abogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad spinbox index "abogus"}
test spinbox-13.3 {GetSpinboxIndex procedure} -setup {
    spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 1
    .e select to 6
    .e index anchor
} -cleanup {
    destroy .e
} -result 1
} -result {1}
test spinbox-13.4 {GetSpinboxIndex procedure} -setup {
    spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 4
    .e select to 1
    .e index anchor
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-13.5 {GetSpinboxIndex procedure} -setup {
    spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e select from 3
    .e select to 15
    .e select adjust 4
    .e index anchor
} -cleanup {
    destroy .e
} -result 15
} -result {15}
test spinbox-13.6 {GetSpinboxIndex procedure} -setup {
    spinbox .e
} -body {
    .e index ebogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad spinbox index "ebogus"}
test spinbox-13.7 {GetSpinboxIndex procedure} -setup {
    spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
    pack .e
} -body {
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e icursor 2
    .e index insert
} -cleanup {
    destroy .e
} -result 2
} -result {2}
test spinbox-13.8 {GetSpinboxIndex procedure} -setup {
    spinbox .e
} -body {
    .e index ibogus
} -cleanup {
    destroy .e
} -returnCodes error -result {bad spinbox index "ibogus"}
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
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







-
+


















-
+


















-
+

-
+







    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
} -cleanup {
    destroy .e
} -result {1 6}

test spinbox-13.10 {GetSpinboxIndex procedure} -constraints x11 -body {
test spinbox-13.10 {GetSpinboxIndex procedure} -constraints unix -body {
# On unix, when selection is cleared, spinbox widget's internal
# selection range is reset.
# Previous settings:
	spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    .e index sel.first
} -cleanup {
    destroy .e
} -returnCodes error -result {selection isn't in widget .e}

test spinbox-13.11 {GetSpinboxIndex procedure} -constraints aquaOrWin32 -body {
test spinbox-13.11 {GetSpinboxIndex procedure} -constraints win -body {
# On mac and pc, when selection is cleared, spinbox widget remembers
# last selected range.  When selection ownership is restored to
# spinbox, the old range will be rehighlighted.
# Previous settings:
	spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
    .e select to 6
    list [.e index sel.first] [.e index sel.last]
# Testing:
    selection clear .e
    catch {selection get}
    .e index sel.first
} -cleanup {
    destroy .e
} -result 1
} -result {1}

test spinbox-13.12 {GetSpinboxIndex procedure} -constraints x11 -body {
test spinbox-13.12 {GetSpinboxIndex procedure} -constraints unix -body {
# Previous settings:
	spinbox .e -font {Courier -12} -width 5 -bd 2 -relief sunken
	pack .e
	.e insert 0 012345678901234567890
	.e xview 4
	update
    .e select from 1
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
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







-
+










-
+










-
+










-
+










-
+










-
+
















-
+


-
+










-
+










-
+







    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @4
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-13.17 {GetSpinboxIndex procedure} -constraints fonts -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @11
} -cleanup {
    destroy .e
} -result 4
} -result {4}
test spinbox-13.18 {GetSpinboxIndex procedure} -constraints fonts -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @12
} -cleanup {
    destroy .e
} -result 5
} -result {5}
test spinbox-13.19 {GetSpinboxIndex procedure} -constraints fonts -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @[expr {[winfo width .e] - 6-11}]
} -cleanup {
    destroy .e
} -result 8
} -result {8}
test spinbox-13.20 {GetSpinboxIndex procedure} -constraints fonts -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @[expr {[winfo width .e] - 5}]
} -cleanup {
    destroy .e
} -result 9
} -result {9}
test spinbox-13.21 {GetSpinboxIndex procedure} -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index @1000
} -cleanup {
    destroy .e
} -result 9
} -result {9}
test spinbox-13.22 {GetSpinboxIndex procedure} -setup {
    spinbox .e
    pack .e
    update
} -body {
    .e index 1xyz
} -cleanup {
    destroy .e
} -returnCodes error -result {bad spinbox index "1xyz"}
test spinbox-13.23 {GetSpinboxIndex procedure} -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index {}
    .e index -10
} -cleanup {
    destroy .e
} -result 0
} -result {0}
test spinbox-13.24 {GetSpinboxIndex procedure} -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index 12
} -cleanup {
    destroy .e
} -result 12
} -result {12}
test spinbox-13.25 {GetSpinboxIndex procedure} -body {
    spinbox .e -width 5 -relief sunken -highlightthickness 2 -bd 2 \
        -font {Courier -12}
    pack .e
    .e insert 0 012345678901234567890
    .e xview 4
    update
    .e index 49
} -cleanup {
    destroy .e
} -result 21
} -result {21}

# XXX Still need to write tests for SpinboxScanTo and SpinboxSelectTo.

test spinbox-14.1 {SpinboxFetchSelection procedure} -body {
    spinbox .e
    .e insert end "This is a test string"
    .e select from 1
3163
3164
3165
3166
3167
3168
3169
3170

3171
3172
3173
3174
3175
3176
3177
3150
3151
3152
3153
3154
3155
3156

3157
3158
3159
3160
3161
3162
3163
3164







-
+







    spinbox .e
    .e insert end $x
    .e select from 0
    .e select to end
    string compare [selection get] $x
} -cleanup {
    destroy .e
} -result 0
} -result {0}

test spinbox-15.1 {SpinboxLostSelection} -body {
    spinbox .e
    .e insert 0 "Text"
    .e select from 0
    .e select to 4
    set result [selection get]
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234

3235
3236
3237
3238
3239

3240
3241
3242
3243
3244
3245
3246

3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271

3272
3273
3274
3275
3276
3277
3278
3187
3188
3189
3190
3191
3192
3193


3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204


3205
3206
3207
3208
3209
3210
3211
3212
3213


3214

3215
3216
3217
3218
3219

3220
3221
3222
3223
3224
3225
3226

3227
3228
3229



3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248

3249
3250
3251
3252
3253
3254
3255
3256







-
-











-
-









-
-

-
+




-
+






-
+


-
-
-



















-
+







    destroy .e
} -result {0.000000 1.000000}


test spinbox-17.1 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e delete 0 end
    .e insert 0 123
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 1.000000}
test spinbox-17.2 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    .e insert 0 0123456789abcdef
    update
    set scrollInfo wrong
    .e xview 3
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.187500 0.812500}
test spinbox-17.3 {SpinboxUpdateScrollbar procedure} -body {
    spinbox .e -width 10 -xscrollcommand scroll -font {Courier -12}
    pack .e
    update
    set scrollInfo wrong
    .e insert 0 abcdefghijklmnopqrs
    .e xview
    .e xview 6
    update
    format {%.6f %.6f} {*}$scrollInfo
} -cleanup {
    destroy .e
} -result {0.000000 0.526316}
} -result {0.315789 0.842105}
test spinbox-17.4 {SpinboxUpdateScrollbar procedure} -setup {
    proc bgerror msg {
	global x
	set x $msg
}
} -body {
    spinbox .e -width 5
    spinbox .e -width 5 -xscrollcommand thisisnotacommand
    pack .e
    update
    set scrollInfo wrong
    .e configure -xscrollcommand thisisnotacommand
    update
    list $x $errorInfo
} -cleanup {
    destroy .e
    rename bgerror {}
} -result {{invalid command name "thisisnotacommand"} {invalid command name "thisisnotacommand"
    while executing
"thisisnotacommand 0.0 1.0"
    (horizontal scrolling command executed by .e)}}


test spinbox-18.1 {Spinbox widget vs hiding} -setup {
    spinbox .e
} -body {
    set l [interp hidden]
    interp hide {} .e
    destroy .e
    set res1 [list [winfo children .] [interp hidden]]
    set res2 [list {} $l]
    expr {$res1 == $res2}
} -result 1
} -result {1}

##
## Spinbox widget VALIDATION tests
##
# The validation tests build each one upon the previous, so cascading
# failures aren't good
#
3624
3625
3626
3627
3628
3629
3630
3631

3632
3633
3634
3635
3636
3637
3638
3602
3603
3604
3605
3606
3607
3608

3609
3610
3611
3612
3613
3614
3615
3616







-
+







    set ::e nextdata                 ;# previous settings

    .e configure -validatecommand [list doval2 %W %d %i %P %s %S %v %V]
    .e validate
    list [.e cget -validate] [.e get] $::vVals
} -cleanup {
    destroy .e
} -result {none nextdata {.e -1 -1 nextdata nextdata {} all forced}}
} -result {none mydata {.e -1 -1 nextdata nextdata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the spinbox widget shown as is in the textvar.
test spinbox-19.20 {spinbox widget validation} -setup {
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3628
3629
3630
3631
3632
3633
3634




















3635
3636
3637
3638
3639
3640
3641







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    .e configure -validate all
    set ::e testdata
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {all testdata mydata {.e -1 -1 testdata mydata {} all forced}}

## This leaves validate alone because we trigger validation through the
## textvar (a write trace), and the write during validation triggers
## nothing (by definition of avoiding loops on var traces).  This is
## one of those "dangerous" conditions where the user will have a
## different value in the entry widget shown as is in the textvar.
test spinbox-19.21 {spinbox widget validation - bug 40e4bf6198} -setup {
    unset -nocomplain ::e ::vVals
} -body {
    spinbox .e -validate key \
        -validatecommand [list doval2 %W %d %i %P %s %S %v %V] \
        -textvariable ::e
    pack .e
    set ::e origdata
    .e insert 0 A
    list [.e cget -validate] [.e get] $::e $::vVals
} -cleanup {
    destroy .e
} -result {none origdata mydata {.e 1 0 Aorigdata origdata A key key}}

##
## End validation tests
##

test spinbox-20.1 {spinbox config, -format specifier} -body {
    spinbox .e
    .e config -format %2f
3825
3826
3827
3828
3829
3830
3831
3832

3833
3834
3835
3836
3837
3838
3839
3840

3841
3842
3843
3844
3845
3846
3847
3848

3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868

3869
3870
3871
3872
3873
3874
3875
3783
3784
3785
3786
3787
3788
3789

3790
3791
3792
3793
3794
3795
3796
3797

3798
3799
3800
3801
3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825

3826
3827
3828
3829
3830
3831
3832
3833







-
+







-
+







-
+



















-
+








test spinbox-22.1 {spinbox config, -from changes SF bug 559078} -body {
    set val 5
    spinbox .e -from 1 -to 10 -textvariable val
    set val
} -cleanup {
    destroy .e
} -result 5
} -result {5}
test spinbox-22.2 {spinbox config, -from changes SF bug 559078} -body {
    set val 5
    spinbox .e -from 1 -to 10 -textvariable val
    .e configure -from 3 -to 10
    set val
} -cleanup {
    destroy .e
} -result 5
} -result {5}
test spinbox-22.3 {spinbox config, -from changes SF bug 559078} -body {
    set val 5
    spinbox .e -from 3 -to 10 -textvariable val
    .e configure -from 6 -to 10
    set val
} -cleanup {
    destroy .e
} -result 6
} -result {6}

test spinbox-23.1 {selection present while disabled, bug 637828} -body {
    spinbox .e
    .e insert end 0123456789
    .e select from 3
    .e select to 6
    set out [.e selection present]
    .e configure -state disabled
# still return 1 when disabled, because 'selection get' will work,
# but selection cannot be changed (new behavior since 8.4)
    .e select to 9
    lappend out [.e selection present] [selection get]
} -cleanup {
    destroy .e
} -result {1 1 345}

test spinbox-24.1 {error in trace proc attached to the textvariable} -setup {
    destroy .s
} -body {
    trace add variable myvar write traceit
    trace variable myvar w traceit
    proc traceit args {error "Intentional error here!"}
    spinbox .s -textvariable myvar -from 1 -to 10
    catch {.s set mystring} result1
    catch {.s insert 0 mystring} result2
    catch {.s delete 0} result3
    catch {.s invoke buttonup} result4
    list $result1 $result2 $result3 $result4
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3842
3843
3844
3845
3846
3847
3848




















3849
3850
3851
3852
3853
3854
3855







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    destroy .s
} -body {
    catch {spinbox .s -textvariable thisnsdoesntexist::myvar} result1
    set result1
} -cleanup {
    destroy .s
} -result {can't trace "thisnsdoesntexist::myvar": parent namespace doesn't exist}
test spinbox-25.3 {Bugs [2a32225cd1] and [9fa3e08243]} -setup {
    destroy .s
    pack [spinbox .s]
    update
    set res {}
} -body {
    .s insert end "A sample text"
    .s icursor end
    event generate .s <<PrevWord>>  ; # shall move insert to index 9
    .s delete insert end
    lappend res [.s get]
    .s delete 0 end
    .s insert end "A sample text"
    .s icursor 2
    event generate .s <<NextWord>>  ; # shall move insert to index 9
    .s delete 0 insert
    lappend res [.s get]
} -cleanup {
    destroy .s
} -result {{A sample } text}

# Collected comments about lacks from the test
# XXX Still need to write tests for SpinboxBlinkProc, SpinboxFocusProc,
# and SpinboxTextVarProc.
# No tests for DisplaySpinbox.
# XXX Still need to write tests for SpinboxScanTo and SpinboxSelectTo.
# No tests for EventuallyRedraw

Deleted tests/systray.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
















































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# This file is a Tcl script to test systray and sysnotify features in Tk.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
# Copyright © 2020 Francois Vogel.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

test systray-1 {systray icon creation, all options} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "Systray sample" \
            -button1 {puts "button 1 click"} -button3 {puts "button 3 click"}
} -cleanup {
    tk systray destroy
    image delete _book
} -result {}

test systray-2 {systray create, argument checking} -body {
    tk systray create
} -returnCodes {error} -result {missing required option "-image"}

test systray-3 {systray create, argument checking} -body {
    tk systray create -text Hell
} -returnCodes {error} -result {missing required option "-image"}

test systray-4 {systray create, argument checking} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -gorp invalidOption
} -returnCodes {error} -result {unknown option "-gorp": must be -image, -text, -button1 or -button3}

test systray-5 {systray icon creation, only required option present} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book
} -cleanup {
    tk systray destroy
    image delete _book
} -result {}

test systray-6 {systray icon creation, some options present} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -button3 {puts b3}
} -cleanup {
    tk systray destroy
    image delete _book
} -result {}

test systray-7 {systray icon, all parameters modification, introspection} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
    image create photo _page -data R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7
} -body {
    tk systray create -image _book -text "Systray icon text"
    tk systray configure -image _page
    tk systray configure -text "Another text for my icon"
    tk systray configure -button1 {set a 1}
    tk systray configure -button3 {set b 2}
    tk systray configure
} -cleanup {
    tk systray destroy
    image delete _book
    image delete _page
} -result {-image _page -text {Another text for my icon} -button1 {set a 1} -button3 {set b 2}}

test systray-8 {systray icon, single parameter modification, introspection} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "Systray icon text" -button1 {puts b1}
    tk systray configure -button1 {set a 1}
    tk systray configure -button1
} -cleanup {
    tk systray destroy
    image delete _book
} -result {set a 1}

test systray-9 {systray icon, several parameters modification at once, introspection} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "Systray icon text" -button1 {puts b1}
    tk systray configure -button1 {set a 1} -text NewText
    list [tk systray configure -button1] [tk systray configure -text]
} -cleanup {
    tk systray destroy
    image delete _book
} -result {{set a 1} NewText}

test systray-10 {configure non-existing systray icon} -setup {
    catch {tk systray destroy}
} -body {
    tk systray configure
} -returnCodes {error} -result {systray not created}

test systray-11 {destroy non-existing systray icon} -setup {
    catch {tk systray destroy}
} -body {
    tk systray destroy
} -returnCodes {error} -result {systray not created}

test systray-12 {destroy systray icon works} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book
    tk systray destroy
    tk systray create -image _book
} -result {}

test systray-13 {systray icon creation, attempt to create more than one in an interp} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book
    tk systray create -image _book
} -cleanup {
    tk systray destroy
    image delete _book
} -returnCodes {error} -result {only one system tray icon supported per interpeter}

test systray-14 {systray icon creation, create one per interp, visibiliy checks} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "first interp"
    interp create second
    # load Tk into the 'second' interp
    foreach pkg [info loaded] {
        if {[lindex $pkg 1] == "Tk"} {
        set loadTk "load $pkg"
        break
        }
    }
    eval $loadTk second
    # create the icon in the 'second' interp
    second eval {
        # should trigger an error: image _book unknown in 'second' interp'
        # image from higer interp should not be visible by 'tk systray'
        tk systray create -image _book -text "second interp"
    }
} -cleanup {
    tk systray destroy
    image delete _book
    interp delete second
} -returnCodes {error} -result {image "_book" doesn't exist}

test systray-15 {systray icon creation, create one per interp} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "first interp"
    interp create second
    # load Tk into the 'second' interp
    foreach pkg [info loaded] {
        if {[lindex $pkg 1] == "Tk"} {
        set loadTk "load $pkg"
        break
        }
    }
    eval $loadTk second
    # create the icon in the 'second' interp
    second eval {
        image create photo _page -data R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7
        tk systray create -image _page -text "second interp"
    }
} -cleanup {
    second eval {
        tk systray destroy
        image delete _page
    }
    interp delete second
    tk systray destroy
    image delete _book
} -result {}

test systray-16 {systray icon creation from a bitmap, on Linux and macOS only} -constraints {
    nonwin
} -setup {
    set data1 {
        #define foo_width 16
        #define foo_height 16
        static unsigned char foo_bits[] = {
           0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
           0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
           0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff, 0xff
        };
    }
    image create bitmap cross -data $data1
} -body {
    tk systray create -image cross
} -cleanup {
    tk systray destroy
    image delete cross
} -result {}

test systray-17 {systray icon existence check} -setup {
    catch {tk systray destroy}
} -body {
    tk systray exists
} -result {0}

test systray-18 {systray icon existence check} -setup {
    catch {tk systray destroy}
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
} -body {
    tk systray create -image _book -text "Systray test"
    tk systray exists
} -cleanup {
    tk systray destroy
    image delete _book
} -result {1}


test sysnotify-1 {system notification popup} -setup {
    image create photo _book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
    tk systray create -image _book -text "Systray sample"
} -body {
    tk sysnotify {Alert} {This is an alert}
} -cleanup {
    tk systray destroy
    image delete _book
} -result {}

test sysnotify-2.1 {system notification stems from a systray icon on Windows} -constraints {
    win
} -setup {
    catch {tk systray destroy}
} -body {
    tk sysnotify {Alert} {This is an alert}
} -returnCodes {error} -result {must create a system tray icon with the "tk systray" command first}
test sysnotify-2.2 {system notification is not linked to any systray icon on X11 or aqua} -constraints {
    nonwin
} -setup {
    catch {tk systray destroy}
} -body {
    tk sysnotify {Alert} {This is an alert}
} -result {}


cleanupTests

Changes to tests/text.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test the code in the file tkText.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47







-
+








-
+







    pack .t
    update
} -body {
    .t configure -autoseparators yes
    .t cget -autoseparators
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-1.1b {configuration option: "autoseparators", default} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t cget -autoseparators
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-1.2 {configuration option: "autoseparators"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -autoseparators nah
} -cleanup {
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+







    pack .t
    update
} -body {
    .t configure -bd 4
    .t cget -bd
} -cleanup {
    destroy .t
} -result 4
} -result {4}
test text-1.6 {configuration option: "bd"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -bd foo
} -cleanup {
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142







-
+


















-
+







    pack .t
    update
} -body {
    .t configure -blockcursor 0
    .t cget -blockcursor
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.10 {configuration option: "blockcursor"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -blockcursor xx
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.11 {configuration option: "borderwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -borderwidth 7
    .t cget -borderwidth
} -cleanup {
    destroy .t
} -result 7
} -result {7}
test text-1.12 {configuration option: "borderwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -borderwidth ++
} -cleanup {
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180







-
+







    pack .t
    update
} -body {
    .t configure -exportselection no
    .t cget -exportselection
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.16 {configuration option: "exportselection"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -exportselection maybe
} -cleanup {
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256







-
+







    pack .t
    update
} -body {
    .t configure -height 5
    .t cget -height
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-1.24 {configuration option: "height"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -height bad
} -cleanup {
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
299
300
301
302
303
304
305

306
307
308
309
310
311
312
313







-
+







    pack .t
    update
} -body {
    .t configure -highlightthickness -2
    .t cget -highlightthickness
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.30 {configuration option: "highlightthickness"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -highlightthickness bad
} -cleanup {
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493







-
+


















-
+


















-
+


















-
+


















-
+








-
+


















-
+


















-
+







    pack .t
    update
} -body {
    .t configure -insertborderwidth 45
    .t cget -insertborderwidth
} -cleanup {
    destroy .t
} -result 45
} -result {45}
test text-1.36 {configuration option: "insertborderwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertborderwidth bogus
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.37 {configuration option: "insertofftime"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertofftime 100
    .t cget -insertofftime
} -cleanup {
    destroy .t
} -result 100
} -result {100}
test text-1.38 {configuration option: "insertofftime"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertofftime 2.4
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.39 {configuration option: "insertontime"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertontime 47
    .t cget -insertontime
} -cleanup {
    destroy .t
} -result 47
} -result {47}
test text-1.40 {configuration option: "insertontime"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertontime e1
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.41 {configuration option: "insertwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertwidth 2.3
    .t cget -insertwidth
} -cleanup {
    destroy .t
} -result 2
} -result {2}
test text-1.42 {configuration option: "insertwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -insertwidth 47d
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.43 {configuration option: "maxundo"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -maxundo 5
    .t cget -maxundo
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-1.43b {configuration option: "maxundo", default} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t cget -maxundo
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.44 {configuration option: "maxundo"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -maxundo noway
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.45 {configuration option: "padx"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -padx 3.4
    .t cget -padx
} -cleanup {
    destroy .t
} -result 3
} -result {3}
test text-1.46 {configuration option: "padx"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -padx 2.4.
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.47 {configuration option: "pady"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -pady 82
    .t cget -pady
} -cleanup {
    destroy .t
} -result 82
} -result {82}
test text-1.48 {configuration option: "pady"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -pady bogus
} -cleanup {
536
537
538
539
540
541
542
543

544
545
546
547
548
549
550
536
537
538
539
540
541
542

543
544
545
546
547
548
549
550







-
+







    pack .t
    update
} -body {
    .t configure -selectborderwidth 21
    .t cget -selectborderwidth
} -cleanup {
    destroy .t
} -result 21
} -result {21}
test text-1.54 {configuration option: "selectborderwidth"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -selectborderwidth 3x
} -cleanup {
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637

638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683







-
+


















-
+


















-
+


















-
+


















-
+


















-
+







    pack .t
    update
} -body {
    .t configure -spacing1 20
    .t cget -spacing1
} -cleanup {
    destroy .t
} -result 20
} -result {20}
test text-1.58 {configuration option: "spacing1"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing1 1.3x
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.59 {configuration option: "spacing1"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing1 -5
    .t cget -spacing1
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.60 {configuration option: "spacing1"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing1 bogus
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.61 {configuration option: "spacing2"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing2 5
    .t cget -spacing2
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-1.62 {configuration option: "spacing2"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing2 bogus
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.63 {configuration option: "spacing2"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing2 -1
    .t cget -spacing2
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.64 {configuration option: "spacing2"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing2 bogus
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.65 {configuration option: "spacing3"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing3 20
    .t cget -spacing3
} -cleanup {
    destroy .t
} -result 20
} -result {20}
test text-1.66 {configuration option: "spacing3"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing3 bogus
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.67 {configuration option: "spacing3"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing3 -10
    .t cget -spacing3
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.68 {configuration option: "spacing3"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -spacing3 bogus
} -cleanup {
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

781
782
783
784
785
786
787
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782
783
784
785
786
787







-
+








-
+


















-
+







    pack .t
    update
} -body {
    .t configure -undo 1
    .t cget -undo
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-1.75b {configuration option: "undo", default} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t cget -undo
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-1.76 {configuration option: "undo"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -undo eh
} -cleanup {
    destroy .t
} -match glob -returnCodes {error} -result {*}
test text-1.77 {configuration option: "width"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -width 73
    .t cget -width
} -cleanup {
    destroy .t
} -result 73
} -result {73}
test text-1.78 {configuration option: "width"} -setup {
    text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold}
    pack .t
    update
} -body {
    .t configure -width 2.4
} -cleanup {
1000
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
1000
1001
1002
1003
1004
1005
1006

1007
1008
1009
1010
1011
1012
1013
1014







-
+







test text-5.4 {TextWidgetCmd procedure, "cget" option} -setup {
    text .t
} -body {
    .t configure -bd 17
    .t cget -bd
} -cleanup {
    destroy .t
} -result 17
} -result {17}


test text-6.1 {TextWidgetCmd procedure, "compare" option} -setup {
    text .t
} -body {
    .t compare a b
} -cleanup {
1194
1195
1196
1197
1198
1199
1200
1201

1202
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1216







-
+







-
+







test text-7.3 {TextWidgetCmd procedure, "debug" option} -setup {
    text .t
} -body {
    .t debug true
    .t deb
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-7.4 {TextWidgetCmd procedure, "debug" option} -setup {
    text .t
} -body {
    .t debug false
    .t debug
} -cleanup {
    destroy .t
} -result 0
} -result {0}


test text-8.1 {TextWidgetCmd procedure, "delete" option} -setup {
    text .t
} -body {
    .t delete
} -cleanup {
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1248
1249
1250
1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261
1262







-
+







12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t configure -state disabled
    .t delete 2.3
    .t get 2.0 2.end
    .t g 2.0 2.end
} -cleanup {
    destroy .t
} -result {abcdefghijklm}
test text-8.6 {TextWidgetCmd procedure, "delete" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1454
1455
1456
1457
1458
1459
1460

1461
1462
1463
1464
1465
1466
1467
1468







-
+







    .t configure -undo 1
    # Ensure it is treated as a single undo action
    .t replace 2.1 2.3 foo
    .t edit undo
    string equal [.t get 1.0 end-1c] $prevtext
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-8.22 {TextWidgetCmd procedure, "replace" option with undo} -setup {
    text .t
    set res {}
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519

1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546

1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572

1573
1574

1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1510
1511
1512
1513
1514
1515
1516

1517
1518

1519
1520
1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545

1546
1547
1548
1549
1550

1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573

1574
1575
1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599









1600
1601
1602
1603
1604
1605
1606







-
+

-
+




-
+


















-
+


-
+




-
+




















-
+

-
+




-
+




















-
-
-
-
-
-
-
-
-







Line 7"
    set prevtext [.t get 1.0 end-1c]
    .t configure -undo 0
    .t configure -undo 1
    # Ensure that undo (even composite undo like 'replace')
    # works when the widget shows nothing useful.
    .t replace 2.1 2.3 foo
    .t configure -startline 1 -endline 1
    .t configure -start 1 -end 1
    .t edit undo
    .t configure -startline {} -endline {}
    .t configure -start {} -end {}
    .t configure -undo 0
    string equal [.t get 1.0 end-1c] $prevtext
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-8.24 {TextWidgetCmd procedure, "replace" option with peers, undo} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    set prevtext [.t get 1.0 end-1c]
    .t configure -undo 0
    .t configure -undo 1
    .t peer create .tt -undo 1
# Ensure that undo (even composite undo like 'replace')
# works when the the event took place in one peer, which
# is then deleted, before the undo takes place in another peer.
    .tt replace 2.1 2.3 foo
    .tt configure -startline 1 -endline 1
    .tt configure -start 1 -end 1
    destroy .tt
    .t edit undo
    .t configure -startline {} -endline {}
    .t configure -start {} -end {}
    .t configure -undo 0
    string equal [.t get 1.0 end-1c] $prevtext
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-8.25 {TextWidgetCmd procedure, "replace" option with peers, undo} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    set prevtext [.t get 1.0 end-1c]
    .t configure -undo 0
    .t configure -undo 1
    .t peer create .tt -undo 1
# Ensure that undo (even composite undo like 'replace')
# works when the the event took place in one peer, which
# is then deleted, before the undo takes place in another peer
# which isn't showing everything.
    .tt replace 2.1 2.3 foo
    set res [.tt get 2.1 2.4]
    .tt configure -startline 1 -endline 1
    .tt configure -start 1 -end 1
    destroy .tt
    .t configure -startline 3 -endline 4
    .t configure -start 3 -end 4
# msg will actually be set to a silently ignored error message here,
# (that the .tt command doesn't exist), but that is not important.
    lappend res [catch {.t edit undo}]
    .t configure -undo 0
    .t configure -startline {} -endline {}
    .t configure -start {} -end {}
    lappend res [string equal [.t get 1.0 end-1c] $prevtext]
} -cleanup {
    destroy .t
} -result {foo 0 1}
test text-8.26 {TextWidgetCmd procedure, "replace" option crash} -setup {
    text .tt
} -body {
    .tt insert 0.0 foo\n
    .tt replace end-1l end bar
} -cleanup {
    destroy .tt
} -result {}
test text-8.27 {TextWidgetCmd procedure, "replace" option crash} -setup {
    text .tt
} -body {
    .tt insert 0.0 \na
    for {set i 0} {$i < 2} {incr i} {
        .tt replace 2.0 3.0 b
    }
} -cleanup {
    destroy .tt
} -result {}
test text-8.28 {TextWidgetCmd procedure, "replace" option crash} -setup {
    text .tt
} -body {
    .tt insert end "foo\n"
    .tt tag add sel 1.0 end
    .tt replace sel.first sel.last "bar"
} -cleanup {
    destroy .tt
} -result {}


test text-9.1 {TextWidgetCmd procedure, "get" option} -setup {
    text .t
} -body {
2064
2065
2066
2067
2068
2069
2070
2071

2072
2073
2074
2075
2076
2077
2078
2055
2056
2057
2058
2059
2060
2061

2062
2063
2064
2065
2066
2067
2068
2069







-
+







} -returnCodes {error} -result {wrong # args: should be ".t count ?-option value ...? index1 index2"}
test text-10.2 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t count blah 1.0 2.0
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad option "blah": must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}
} -returnCodes {error} -result {bad option "blah" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}
test text-10.3 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t count a b
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad text index "a"}
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
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







-
+













-
+













-
+













-
+













-
+













-
+







bOy GIrl .#@? x_yz
!@#$%
Line 7"
} -body {
    .t count 5.7 5.3
} -cleanup {
    destroy .t
} -result -4
} -result {-4}
test text-10.7 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
} -body {
    .t count 5.3 5.5
} -cleanup {
    destroy .t
} -result 2
} -result {2}
test text-10.8 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t count 5.3 end
} -cleanup {
    destroy .t
} -result 29
} -result {29}
test text-10.9 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
} -body {
    .t count 5.2 5.7
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-10.10 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
} -body {
    .t count 5.2 5.3
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-10.11 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
} -body {
    .t count 5.2 5.4
} -cleanup {
    destroy .t
} -result 2
} -result {2}
test text-10.12 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
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
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







-
+















-
+
















-
+















-
+






-
+















-
+






-
+

















-
+






-
+
















-
+






-
+
















-
+






-
+
















-
+






-
+

















-
+






-
+
















-
+






-
+
















-
+







!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t count -displayindices 2.0 3.0
} -cleanup {
    destroy .t
} -result 2
} -result {2}
test text-10.14 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t count -displayindices 2.2 3.0
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-10.15 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
    .t count -displayindices 2.0 4.2
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-10.16 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displayindices 2.0 3.0
} -cleanup {
    destroy .t
} -result 3
} -result {3}
test text-10.17 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displayindices 2.2 3.0
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-10.18 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
    .t mark set a 2.2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3, but 'a' is automatically moved to 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displayindices a 3.0
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-10.19 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displayindices 2.0 4.2
} -cleanup {
    destroy .t
} -result 6
} -result {6}
test text-10.20 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 3.0
} -cleanup {
    destroy .t
} -result 2
} -result {2}
test text-10.21 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.2 3.0
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-10.22 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
    .t mark set a 2.2
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3, but 'a' is automatically moved to 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars a 3.0
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-10.23 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 4.2
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-10.24 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 4.2
    list [.t count -indices 2.2 3.0] [.t count 2.2 3.0]
} -cleanup {
    destroy .t
2467
2468
2469
2470
2471
2472
2473
2474

2475
2476
2477
2478
2479
2480
2481
2458
2459
2460
2461
2462
2463
2464

2465
2466
2467
2468
2469
2470
2471
2472







-
+







    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
    .t mark set a 2.2
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3, but 'a' is automatically moved to 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    list [.t count -indices a 3.0] [.t count a 3.0]
} -cleanup {
    destroy .t
} -result {9 9}
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
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







-
+







-
+
















-
+







-
+

















-
+






-
+
















-
+







-
+









-
+









-
+









-
+









-
+









-
+









-
+









-
+










-
+







Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 4.2
    .t count -indices 2.0 4.2
} -cleanup {
    destroy .t
} -result 21
} -result {21}
test text-10.27 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 4.2
    .t count -chars 2.2 3.0
} -cleanup {
    destroy .t
} -result 10
} -result {10}
test text-10.28 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
    .t mark set a 2.2
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3, but 'a' is automatically moved to 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -chars a 3.0
} -cleanup {
    destroy .t
} -result 9
} -result {9}
test text-10.29 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert 1.0 "Line 1
aefghijklm
12345
Line 4
bOy GIrl .#@? x_yz
!@#$%
Line 7"
    .t tag configure elide -elide 1
    .t tag add elide 2.2 3.4
    .t tag add elide 4.0 4.1
# Create one visible and one invisible window
    frame .t.w1
    frame .t.w2
# Creating this window here means that the elided text
# Creating this window here means that the elidden text
# now starts at 2.3
    .t window create 2.1 -window .t.w1
    .t window create 3.1 -window .t.w2
    .t count -displaychars 2.0 4.2
    .t count -chars 2.0 4.2
} -cleanup {
    destroy .t
} -result 19
} -result {19}
test text-10.30 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines 1.0 end
} -cleanup {
    destroy .t
} -result 3
} -result {3}
test text-10.31 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines end 1.0
} -cleanup {
    destroy .t
} -result -3
} -result {-3}
test text-10.32 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines 1.0 2.0 3.0
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad option "1.0": must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}
} -returnCodes {error} -result {bad option "1.0" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels}
test text-10.33 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines end end
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-10.34 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines 1.5 2.5
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-10.35 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines 2.5 "2.5 lineend"
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-10.36 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t count -lines 2.7 "1.0 lineend"
} -cleanup {
    destroy .t
} -result -1
} -result {-1}
test text-10.37 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
} -body {
    .t insert end [string repeat "abcde " 50]\n
    .t insert end [string repeat "fghij " 50]\n
    .t insert end [string repeat "klmno " 50]
    .t configure -wrap none
    .t count -displaylines 1.0 end
} -cleanup {
    destroy .t
} -result 3
} -result {3}
test text-10.38 {TextWidgetCmd procedure, "count" option} -setup {
    text .t -font {Courier -12} -borderwidth 2 -highlightthickness 2
    pack .t -expand 1 -fill both
} -body {
    .t configure -width 20 -height 10
    update
    .t insert end [string repeat "abcde " 50]\n
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
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







-
+






-
+







-
-
+
+












-
+








-
+







    lappend res [.t count -displaylines 1.19 3.24] [.t count -displaylines 1.0 end]
    .t tag add hidden 2.9 3.17
    .t tag configure hidden -elide true
    lappend res [.t count -displaylines 1.19 3.24] [.t count -displaylines 1.0 end]
} -cleanup {
    destroy .t
} -result {2 6 1 5}
test text-10.40 {TextWidgetCmd procedure, "count" option} -setup {
test text-9.2.45 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    pack .t
    update
    set res {}
} -body {
    for {set i 1} {$i < 5} {incr i} {
      .t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr {64+$i}]]\n"
      .t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr 64+$i]]\n"
    }
    .t tag configure hidden -elide true
    .t tag add hidden 2.15 3.10
    .t configure -wrap none
    set res [.t count -displaylines 2.0 3.0]
} -cleanup {
    destroy .t
} -result 0
test text-10.41 {TextWidgetCmd procedure, "count" option} -setup {
} -result {0}
test text-9.2.46 {TextWidgetCmd procedure, "count" option} -setup {
    toplevel .mytop
    pack [text .mytop.t -font TkFixedFont -bd 0 -padx 0 -wrap char]
    set spec [font measure TkFixedFont "Line 1+++Line 1---Li"]  ; # 20 chars
    append spec x300+0+0
    wm geometry .mytop $spec
    .mytop.t delete 1.0 end
    update
    set res {}
} -body {
    for {set i 1} {$i < 5} {incr i} {
      #                    0          1          2          3          4
      #                    012345 678901234 567890123 456789012 34567890123456789
      .mytop.t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr {64+$i}]]\n"
      .mytop.t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr 64+$i]]\n"
    }
    .mytop.t tag configure hidden -elide true
    .mytop.t tag add hidden 2.30 3.10
    lappend res [.mytop.t count -displaylines 2.0 3.0]
    lappend res [.mytop.t count -displaylines 2.0 3.50]
} -cleanup {
    destroy .mytop
} -result {1 3}
test text-10.42 {TextWidgetCmd procedure, "count" option} -setup {
test text-9.2.47 {TextWidgetCmd procedure, "count" option} -setup {
    text .t
    pack .t
    update
    set res {}
} -body {
    for {set i 1} {$i < 25} {incr i} {
        .t insert end "Line $i\n"
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
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







-
+












-
+







} -body {
    .t insert end "hello"
    .t tag configure elide1 -elide 0
    .t tag add elide1 1.2 1.4
    .t count -displaychars 1.0 1.5
} -cleanup {
    destroy .t
} -result 5
} -result {5}
test text-11.3 {counting with tag priority eliding} -setup {
    text .t -font {Courier -12} -borderwidth 2 -highlightthickness 2
} -body {
    .t insert end "hello"
# Newer tags are higher priority
    .t tag configure elide1 -elide 0
    .t tag configure elide2 -elide 1
    .t tag add elide1 1.2 1.4
    .t tag add elide2 1.2 1.4
    .t count -displaychars 1.0 1.5
} -cleanup {
    destroy .t
} -result 3
} -result {3}
test text-11.4 {counting with tag priority eliding}  -setup {
    text .t -font {Courier -12} -borderwidth 2 -highlightthickness 2
    set res {}
} -body {
    .t insert end "hello"
# Newer tags are higher priority
    .t tag configure elide1 -elide 0
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2935
2936
2937
2938
2939
2940
2941

2942
2943
2944
2945
2946

2947
2948
2949
2950
2951
2952
2953







-





-







    destroy .yt
} -body {
    text .yt
    list [catch {.yt pendingsync mytext} msg] $msg
} -cleanup {
    destroy .yt
} -result {1 {wrong # args: should be ".yt pendingsync"}}

test text-11a.2 {TextWidgetCmd procedure, "pendingsync" option} -setup {
    destroy .top.yt .top
} -body {
    toplevel .top
    pack [text .top.yt]
    update
    set content {}
    for {set i 1} {$i < 300} {incr i} {
        append content [string repeat "$i " 15] \n
    }
    .top.yt insert 1.0 $content
    # wait for end of line metrics calculation to get correct $fraction1
    # as a reference
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999

3000
3001
3002
3003
3004
3005
3006
2977
2978
2979
2980
2981
2982
2983

2984

2985

2986
2987
2988
2989
2990
2991
2992
2993







-

-

-
+







    destroy .yt
} -result {1 {wrong # args: should be ".yt sync ?-command command?"}}
test text-11a.12 {TextWidgetCmd procedure, "sync" option} -setup {
    destroy .top.yt .top
} -body {
    toplevel .top
    pack [text .top.yt]
    update
    set content {}
    # Use long lines so the line metrics will need updating.
    for {set i 1} {$i < 30} {incr i} {
        append content [string repeat "$i " 200] \n
        append content [string repeat "$i " 15] \n
    }
    .top.yt insert 1.0 $content
    # wait for end of line metrics calculation to get correct $fraction1
    # as a reference
    .top.yt sync
    .top.yt yview moveto 1
    set fraction1 [lindex [.top.yt yview] 0]
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
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







-






-
+

-
+


-
+


-
+

-
+









-




-
-
+


+
+
-
+






-
+













+


-




-
-
-

-
-

-
+
-
+

-
+
+

-
-
+
-






-
+







-







test text-11a.22 {TextWidgetCmd procedure, "sync" option with -command} -setup {
    destroy .top.yt .top
} -body {
    set res {}
    set ::x 0
    toplevel .top
    pack [text .top.yt]
    update
    set content {}
    for {set i 1} {$i < 30} {incr i} {
        append content [string repeat "$i " 15] \n
    }
    .top.yt insert 1.0 $content
    # first case: line metrics calculation still running when launching 'sync -command'
    lappend res [.top.yt pendingsync]       ; # {1}
    lappend res [.top.yt pendingsync]
    .top.yt sync -command [list set ::x 1]
    lappend res $::x                        ; # {1 0}
    lappend res $::x
    # now finish line metrics calculations
    while {[.top.yt pendingsync]} {update}
    lappend res [.top.yt pendingsync] $::x  ; # {1 0 0 1}
    lappend res [.top.yt pendingsync] $::x
    # second case: line metrics calculation completed when launching 'sync -command'
    .top.yt sync -command [list set ::x 2]
    lappend res $::x                        ; # {1 0 0 1 1}
    lappend res $::x
    vwait ::x
    lappend res $::x                        ; # {1 0 0 1 1 2}
    lappend res $::x
} -cleanup {
    destroy .top.yt .top
} -result {1 0 0 1 1 2}

test text-11a.31 {"<<WidgetViewSync>>" event} -setup {
    destroy .top.yt .top
} -body {
    toplevel .top
    pack [text .top.yt]
    update
    set content {}
    for {set i 1} {$i < 300} {incr i} {
        append content [string repeat "$i " 15] \n
    }
    # Sync the widget and process <<WidgetViewSync>> events before binding.
    .top.yt sync
    .top.yt insert 1.0 $content
    update
    bind .top.yt <<WidgetViewSync>> { if {%d} {set yud(%W) 1} }
    # wait for end of line metrics calculation to get correct $fraction1
    # as a reference
    .top.yt insert 1.0 $content
    if {[.top.yt pendingsync]} {vwait yud(.top.yt)}
    .top.yt yview moveto 1
    set fraction1 [lindex [.top.yt yview] 0]
    set res [expr {$fraction1 > 0}]
    .top.yt delete 1.0 end
    .top.yt insert 1.0 $content
    # synchronously wait for completion of line metrics calculation
    # and verify that the fractions agree.
    # and ensure the test is relevant
    set waited 0
    if {[.top.yt pendingsync]} {set waited 1 ; vwait yud(.top.yt)}
    lappend res $waited
    .top.yt yview moveto $fraction1
    set fraction2 [lindex [.top.yt yview] 0]
    lappend res [expr {$fraction1 == $fraction2}]
} -cleanup {
    destroy .top.yt .top
} -result {1 1 1}

test text-11a.41 {"sync" "pendingsync" and <<WidgetViewSync>>} -setup {
    destroy .top.yt .top
} -body {
    set res {}
    toplevel .top
    pack [text .top.yt]
    update
    set content {}
    for {set i 1} {$i < 300} {incr i} {
        append content [string repeat "$i " 50] \n
    }
    # Sync the widget and process all <<WidgetViewSync>> events before binding.
    .top.yt sync
    update
    bind .top.yt <<WidgetViewSync>> {lappend res Sync:%d}
    set res {}
    # The next line triggers <<WidgetViewSync>> with %d==0 i.e. out of sync.
    .top.yt insert 1.0 $content
    vwait res
    vwait res  ; # event dealt with by the event loop, with %d==0 i.e. we're out of sync
    # Verify that the line metrics are not up-to-date (pendingsync is 1).
    # ensure the test is relevant
    lappend res "Pending:[.top.yt pendingsync]"
    # Update all line metrics by calling the sync command.
    # - <<WidgetViewSync>> fires when sync returns if there was pending syncs
    # - there is no more any pending sync after running 'sync'
    .top.yt sync
    # <<WidgetViewSync>> should fire with %d==1 i.e. back in sync.
    vwait res
    vwait res  ; # event dealt with by the event loop, with %d==1 i.e. we're in sync again
    # At this time the line metrics should be up-to-date (pendingsync is 0).
    lappend res "Pending:[.top.yt pendingsync]"
    set res
} -cleanup {
    destroy .top.yt .top
} -result {Sync:0 Pending:1 Sync:1 Pending:0}

test text-11a.51 {<<WidgetViewSync>> calls Tk_SendVirtualEvent(),
test text-11a.51 {<<WidgetViewSync>> calls TkSendVirtualEvent(),
                  NOT Tk_HandleEvent().
                  Bug [b362182e45704dd7bbd6aed91e48122035ea3d16]} -setup {
    destroy .top.t .top
} -body {
    set res {}
    toplevel .top
    pack [text .top.t]
    update
    for {set i 1} {$i < 10000} {incr i} {
        .top.t insert end "Hello world!\n"
    }
    bind .top.t <<WidgetViewSync>> {destroy .top.t}
    .top.t tag add mytag 1.5 8000.8    ; # shall not crash
    update
    set res "Still doing fine!"
3385
3386
3387
3388
3389
3390
3391
3392

3393
3394
3395
3396
3397
3398
3399
3364
3365
3366
3367
3368
3369
3370

3371
3372
3373
3374
3375
3376
3377
3378







-
+







} -result {}
test text-14.11 {ConfigureText procedure} -setup {
    text .t
} -body {
    .t configure -selectborderwidth foo
} -cleanup {
    destroy .t
} -returnCodes {error} -result {expected screen distance or "" but got "foo"}
} -returnCodes {error} -result {bad screen distance "foo"}
test text-14.12 {ConfigureText procedure} -body {
    text .t
    entry .t.e
    .t.e insert end abcdefg
    .t.e select from 0
    .t.e select to 2
    text .t2 -exportselection 1
3422
3423
3424
3425
3426
3427
3428
3429

3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443

3444
3445
3446
3447
3448
3449
3450
3401
3402
3403
3404
3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421

3422
3423
3424
3425
3426
3427
3428
3429







-
+













-
+







    .t.e select to 1
    text .t2 -exportselection 1
    .t2 insert insert 1234657890
    .t2 tag add sel 1.0 1.4
    selection get
} -cleanup {
    destroy .t .t2
} -result 1234
} -result {1234}
test text-14.15 {ConfigureText procedure} -body {
    text .t
    entry .t.e
    .t.e insert end abcdefg
    .t.e select from 0
    .t.e select to 1
    text .t2 -exportselection 0
    .t2 insert insert 1234657890
    .t2 tag add sel 1.0 1.4
    .t2 configure -exportselection 1
    selection get
} -cleanup {
    destroy .t2 .t
} -result 1234
} -result {1234}
test text-14.16 {ConfigureText procedure} -body {
    text .t
    entry .t.e
    .t.e insert end abcdefg
    .t.e select from 0
    text .t2 -exportselection 1
    .t2 insert insert 1234657890
3465
3466
3467
3468
3469
3470
3471
3472

3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502

3503
3504
3505
3506
3507

3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520

3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531

3532
3533
3534
3535
3536
3537
3538
3444
3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467






3468
3469
3470
3471
3472
3473
3474

3475
3476
3477
3478
3479

3480
3481
3482
3483
3484

3485
3486
3487
3488
3489
3490
3491

3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502

3503
3504
3505
3506
3507
3508
3509
3510







-
+
















-
-
-
-
-
-







-
+




-
+




-







-
+










-
+







    .t2 tag add sel 1.0 1.4
    set result [selection get]
    .t2 configure -exportselection 0
    catch {selection get}
    return $result
} -cleanup {
    destroy .t .t2
} -result 1234
} -result {1234}
test text-14.18 {ConfigureText procedure} -constraints fonts -setup {
    toplevel .top
    text .top.t -font {Courier -12} -borderwidth 2 -highlightthickness 2
} -body {
    .top.t configure -width 20 -height 10
    pack .top.t
    update
    set geom [wm geometry .top]
    set x [string range $geom 0 [string first + $geom]]
} -cleanup {
    destroy .top
} -result {150x140+}
# This test was failing Windows because the title bar on .t was a certain
# minimum size and it was interfering with the size requested by the -setgrid.
# The "overrideredirect" gets rid of the titlebar so the toplevel can shrink
# to the appropriate size.
# On macOS, however, there is no way to make the window overlap the menubar.
if {[tk windowingsystem] eq "aqua"} {
    set minY [expr [menubarheight] + 1]
} else {
    set minY 0
}
test text-14.19 {ConfigureText procedure} -setup {
    toplevel .top
    text .top.t -font {Courier -12} -borderwidth 2 -highlightthickness 2
} -body {
    .top.t configure -width 20 -height 10 -setgrid 1
    wm overrideredirect .top 1
    pack .top.t
    wm geometry .top +0+$minY
    wm geometry .top +0+0
    update
    wm geometry .top
} -cleanup {
    destroy .top
} -result "20x10+0+$minY"
} -result {20x10+0+0}
# This test was failing on Windows because the title bar on .t was a certain
# minimum size and it was interfering with the size requested by the -setgrid.
# The "overrideredirect" gets rid of the titlebar so the toplevel can shrink
# to the appropriate size.
# On macOS we again use minY as a workaround.
test text-14.20 {ConfigureText procedure} -setup {
    toplevel .top
    text .top.t -font {Courier -12} -borderwidth 2 -highlightthickness 2
} -body {
    .top.t configure -width 20 -height 10 -setgrid 1
    wm overrideredirect .top 1
    pack .top.t
    wm geometry .top +0+$minY
    wm geometry .top +0+0
    update
    set result [wm geometry .top]
    wm geometry .top 15x8
    update
    lappend result [wm geometry .top]
    .top.t configure -wrap word
    update
    lappend result [wm geometry .top]
} -cleanup {
    destroy .top
} -result "20x10+0+$minY 15x8+0+$minY 15x8+0+$minY"
} -result {20x10+0+0 15x8+0+0 15x8+0+0}


test text-15.1 {TextWorldChanged procedure, spacing options} -constraints {
    fonts
} -body {
    text .t -width 20 -height 10 -font {Courier -12} -borderwidth 2 -highlightthickness 2
    set result [winfo reqheight .t]
3968
3969
3970
3971
3972
3973
3974
3975

3976
3977
3978
3979
3980
3981
3982
3940
3941
3942
3943
3944
3945
3946

3947
3948
3949
3950
3951
3952
3953
3954







-
+







        append x "This is line $i, padded to just about 53 characters.\n"
    }
    .t insert end $x
    .t tag add sel 1.0 end
    expr {[selection get] eq "$x\n"}
} -cleanup {
    destroy .t
} -result 1
} -result {1}


test text-21.1 {TkTextLostSelection procedure} -constraints {x11} -setup {
    text .t
    .t insert 1.0 "Line 1"
    entry .t.e
    .t.e insert end "abcdefg"
4577
4578
4579
4580
4581
4582
4583
4584
4585


4586
4587
4588
4589
4590
4591
4592


4593
4594
4595
4596
4597
4598
4599

4600
4601
4602


4603
4604
4605
4606
4607
4608
4609
4549
4550
4551
4552
4553
4554
4555


4556
4557
4558
4559
4560
4561
4562


4563
4564
4565
4566
4567
4568
4569
4570

4571
4572


4573
4574
4575
4576
4577
4578
4579
4580
4581







-
-
+
+





-
-
+
+






-
+

-
-
+
+







    set p $p$p$p$p$p
    .t search -nocase $p 1.0
} -cleanup {
    destroy .t
} -result {}
test text-22.69 {TextSearchCmd, unicode} -body {
    text .t
    .t insert end "fooドナbar"
    .t search ドナ 1.0
    .t insert end "foo\u30c9\u30cabar"
    .t search \u30c9\u30ca 1.0
} -cleanup {
    destroy .t
} -result {1.3}
test text-22.70 {TextSearchCmd, unicode} -body {
    text .t
    .t insert end "fooドナbar"
    list [.t search -count n ドナ 1.0] $n
    .t insert end "foo\u30c9\u30cabar"
    list [.t search -count n \u30c9\u30ca 1.0] $n
} -cleanup {
    destroy .t
} -result {1.3 2}
test text-22.71 {TextSearchCmd, unicode with non-text segments} -body {
    text .t
    button .b1 -text baz
    .t insert end "foo"
    .t insert end "foo\u30c9"
    .t window create end -window .b1
    .t insert end "bar"
    list [.t search -count n ドナ 1.0] $n
    .t insert end "\u30cabar"
    list [.t search -count n \u30c9\u30ca 1.0] $n
} -cleanup {
    destroy .t .b1
} -result {1.3 3}
test text-22.72 {TextSearchCmd, hidden text does not affect match index} -body {
    pack [text .t]
    .t insert end "12345H7890"
    .t search 7 1.0
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083



5084
5085

5086
5087
5088
5089
5090
5091
5092
5046
5047
5048
5049
5050
5051
5052



5053
5054
5055
5056

5057
5058
5059
5060
5061
5062
5063
5064







-
-
-
+
+
+

-
+







} -result {1.31}
test text-22.132 {TextSearchCmd, multiline regexp matching} -body {
    pack [text .t]
    .t insert 1.0 {

void
Tcl_SetObjLength(objPtr, length)
    Tcl_Obj *objPtr;		/* Pointer to object.  This object must
				 * not currently be shared. */
    int length;			/* Number of bytes desired for string
    register Tcl_Obj *objPtr;	/* Pointer to object.  This object must
                                * not currently be shared. */
    register int length;	/* Number of bytes desired for string
				 * representation of object, not including
				 * terminating null byte. */
                            * terminating null byte. */
\{
    char *new;
}
    set markExpr "^(\[A-Za-z0-9~_\]+\[ \t\n\r\]*\\(|(\[^ \t\(#\n\r/@:\*\]\[^=\(\r\n\]*\[ \t\]+\\*?)?"
    append markExpr "(\[A-Za-z0-9~_\]+(<\[^>\]*>)?(::)?(\[A-Za-z0-9~_\]+::)*\[-A-Za-z0-9~_+ <>\|\\*/\]+|\[A-Za-z0-9~_\]+)"
    append markExpr "\[ \n\t\r\]*\\()"
    .t search -all -regexp -- $markExpr 1.0
5584
5585
5586
5587
5588
5589
5590
5591



5592
5593
5594
5595
5596
5597
5598
5599
5600



5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618



5619
5620
5621
5622

5623
5624
5625
5626



5627
5628
5629


5630
5631
5632
5633
5634
5635
5636
5556
5557
5558
5559
5560
5561
5562

5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573

5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593

5594
5595
5596
5597
5598
5599

5600
5601
5602
5603

5604
5605
5606
5607
5608

5609
5610
5611
5612
5613
5614
5615
5616
5617







-
+
+
+








-
+
+
+

















-
+
+
+



-
+



-
+
+
+


-
+
+







    .t insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
    set foo {}
    list [.t search -regexp -forward -all -count foo \
      -- {(b+\nc+\nb+)\na+} 1.0] $foo
} -cleanup {
    destroy .t
} -result {2.0 19}
test text-22.199 {TextSearchCmd, regexp search multi-line} -body {
test text-22.199 {TextSearchCmd, regexp search multi-line} -constraints {
    knownBug
} -body {
    pack [text .t]
    .t insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
    set foo {}
    list [.t search -regexp -forward -all -count foo \
      -- {(a+|b+\nc+\nb+)\na+} 1.0] $foo
} -cleanup {
    destroy .t
} -result {2.0 19}
test text-22.200 {TextSearchCmd, regexp search multi-line} -body {
test text-22.200 {TextSearchCmd, regexp search multi-line} -constraints {
    knownBug
} -body {
    pack [text .t]
    .t insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
    set foo {}
    list [.t search -regexp -forward -all -count foo \
      -- {(a+|b+\nc+\nb+)+\na+} 1.0] $foo
} -cleanup {
    destroy .t
} -result {2.0 19}
test text-22.201 {TextSearchCmd, regexp search multi-line} -body {
    pack [text .t]
    .t insert 1.0 "aaaa\nbbbb\ncccc\nbbbb\naaaa\n"
    set foo {}
    list [.t search -regexp -forward -all -count foo \
      -- {((a+|b+\nc+\nb+)+\n)+a+} 1.0] $foo
} -cleanup {
    destroy .t
} -result {1.0 24}
test text-22.202 {TextSearchCmd, regexp search multi-line} -body {
test text-22.202 {TextSearchCmd, regexp search multi-line} -constraints {
    knownBug
} -body {
    pack [text .t]
    .t insert 1.0 "aaaa\nbbbb\nbbbb\nbbbb\nbbbb\n"
    list [.t search -regexp -backward -all -count foo \
      -- {(b+\n|a+\n)(b+\n)+} end] $foo
      -- {b+\n|a+\n(b+\n)+} end] $foo
} -cleanup {
    destroy .t
} -result {1.0 25}
test text-22.203 {TextSearchCmd, regexp search multi-line} -body {
test text-22.203 {TextSearchCmd, regexp search multi-line} -constraints {
    knownBug
} -body {
    pack [text .t]
    .t insert 1.0 "aaaa\nbbbb\nbbbb\nbbbb\nbbbb\n"
    .t search -regexp -backward -- {(b+\n|a+\n)(b+\n)+} end
    .t search -regexp -backward -- {b+\n|a+\n(b+\n)+} end
# Should match at 1.0 for a true greedy match
} -cleanup {
    destroy .t
} -result {1.0}
test text-22.204 {TextSearchCmd, regexp search multi-line} -body {
    pack [text .t]
    .t insert 1.0 "line0\nline1\nline1\nline1\nline1\nline2\nline2\nline2\nline3\n"
    .t search -nolinestop -regexp -nocase -forwards -- {^(.*)\n(\1\n)+} 1.0 end
5820
5821
5822
5823
5824
5825
5826
5827

5828
5829
5830
5831
5832
5833
5834
5801
5802
5803
5804
5805
5806
5807

5808
5809
5810
5811
5812
5813
5814
5815







-
+







} -result {{} {} 1.0 2.1 2.0 3.1 2.0 3.0}
test text-22.217.1 {elide up to match, with UTF-8 chars before the match} -setup {
    pack [text .t]
    set res {}
} -body {
    .t tag configure e -elide 0
    .t insert end A {} xyz e bb\n
    .t insert end Ä {} xyz e bb
    .t insert end \u00c4 {} xyz e bb
    set res {}
    lappend res [.t search bb 1.0 "1.0 lineend"]
    lappend res [.t search bb 2.0 "2.0 lineend"]
    lappend res [.t search -regexp bb 1.0 "1.0 lineend"]
    lappend res [.t search -regexp bb 2.0 "2.0 lineend"]
    .t tag configure e -elide 1
    lappend res [.t search bb 1.0 "1.0 lineend"]
5891
5892
5893
5894
5895
5896
5897
5898

5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113

6114
6115
6116
6117
6118
6119
6120
6121
6122

6123
6124
6125
6126
6127
6128
6129

6130
6131

6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142

6143
6144
6145
6146
6147
6148

6149
6150

6151
6152
6153
6154
6155
6156

6157
6158
6159
6160
6161
6162

6163
6164

6165
6166
6167
6168
6169
6170

6171
6172
6173
6174
6175
6176
6177
6178
6179

6180
6181
6182
6183
6184
6185
6186

6187
6188
6189
6190
6191
6192
6193
5872
5873
5874
5875
5876
5877
5878

5879




















































































































































































































5880
5881

5882
5883
5884
5885
5886
5887
5888
5889
5890

5891
5892
5893
5894
5895
5896
5897

5898
5899

5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910

5911
5912
5913
5914
5915
5916

5917
5918

5919
5920
5921
5922
5923
5924

5925
5926
5927
5928
5929
5930

5931
5932

5933
5934
5935
5936
5937
5938

5939
5940
5941
5942
5943
5944
5945
5946
5947

5948
5949
5950
5951
5952
5953
5954

5955
5956
5957
5958
5959
5960
5961
5962







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+








-
+






-
+

-
+










-
+





-
+

-
+





-
+





-
+

-
+





-
+








-
+






-
+







test text-22.225 {TextSearchCmd, strict limits} -body {
    pack [text .t]
    .t insert 1.0 "Hello world!\nThis is a test\n"
    .t search -regexp -strictlimits -backward -- "world" 2.3 1.8
} -cleanup {
    destroy .t
} -result {}
test text-22.226 {TextSearchCmd, exact search for the empty string} -body {

    text .t
    set res [.t search -count C "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.227 {TextSearchCmd, exact search for the empty string} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C "" 2.5]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 0}
test text-22.228 {TextSearchCmd, exact search all empty strings} -body {
    text .t
    set res [.t search -count C -all "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.229 {TextSearchCmd, exact search all empty strings} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -all "" 2.5 2.8]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 2.6 2.7 {0 0 0}}
test text-22.230 {TextSearchCmd, exact search all empty strings, with overlap} -body {
    text .t
    set res [.t search -count C -all -overlap "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.231 {TextSearchCmd, exact search all empty strings, with overlap} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -all -overlap "" 2.5 2.8]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 2.6 2.7 {0 0 0}}
test text-22.232 {TextSearchCmd, regexp search for the empty string} -body {
    text .t
    set res [.t search -count C -regexp "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.233 {TextSearchCmd, regexp search for the empty string} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -regexp "" 2.5]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 0}
test text-22.234 {TextSearchCmd, regexp search all empty strings} -body {
    text .t
    set res [.t search -count C -all -regexp "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.235 {TextSearchCmd, regexp search all empty strings} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -all -regexp "" 2.5 2.8]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 2.6 2.7 {0 0 0}}
test text-22.236 {TextSearchCmd, regexp search all empty strings, with overlap} -body {
    text .t
    set res [.t search -count C -all -regexp -overlap "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.237 {TextSearchCmd, regexp search all empty strings, with overlap} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -all -regexp -overlap "" 2.5 2.8]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.5 2.6 2.7 {0 0 0}}
test text-22.238 {TextSearchCmd, exact backwards search for the empty string} -body {
    text .t
    set res [.t search -count C -backwards "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.239 {TextSearchCmd, exact backwards search for the empty string} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards "" 2.5]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 0}
test text-22.240 {TextSearchCmd, exact backwards search all empty strings} -body {
    text .t
    set res [.t search -count C -backwards -all "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.241 {TextSearchCmd, exact backwards search all empty strings} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards -all "" 2.5 2.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 2.3 2.2 2.1 2.0 {0 0 0 0 0}}
test text-22.242 {TextSearchCmd, exact backwards search all empty strings, with overlap} -body {
    text .t
    set res [.t search -count C -backwards -all -overlap "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.243 {TextSearchCmd, exact backwards search all empty strings, with overlap} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards -all -overlap "" 2.5 2.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 2.3 2.2 2.1 2.0 {0 0 0 0 0}}
test text-22.244 {TextSearchCmd, regexp backwards search for the empty string} -body {
    text .t
    set res [.t search -count C -backwards -regexp "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.245 {TextSearchCmd, regexpbackwards search for the empty string} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards -regexp "" 2.5]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 0}
test text-22.246 {TextSearchCmd, regexp backwards search all empty strings} -body {
    text .t
    set res [.t search -count C -backwards -all -regexp "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.247 {TextSearchCmd, regexp backwards search all empty strings} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards -all -regexp "" 2.5 2.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 2.3 2.2 2.1 2.0 {0 0 0 0 0}}
test text-22.248 {TextSearchCmd, regexp backwards search all empty strings, with overlap} -body {
    text .t
    set res [.t search -count C -backwards -all -regexp -overlap "" 1.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {1.0 0}
test text-22.249 {TextSearchCmd, regexp backwards search all empty strings, with overlap} -body {
    text .t
    .t insert end "Searching for the\nempty string!"
    set res [.t search -count C -backwards -all -regexp -overlap "" 2.5 2.0]
    lappend res $C
} -cleanup {
    destroy .t
    unset -nocomplain res C
} -result {2.4 2.3 2.2 2.1 2.0 {0 0 0 0 0}}
test text-22.250 {TextSearchCmd, backwards search all matching at start of line} -body {
    text .t
    .t insert end "abc"
    set res [.t search -backwards -all b end]      ; # works
    lappend res [.t search -backwards a end]       ; # works
    lappend res [.t search -backwards -all a end]  ; # used to hang
} -cleanup {
    destroy .t
} -result {1.1 1.0 1.0}

test text-23.1 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs "\{{}"
} -cleanup {
    destroy .t
} -returnCodes {error} -result {unmatched open brace in list}
test text-23.2 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs xyz
} -cleanup {
    destroy .t
} -returnCodes {error} -result {expected screen distance but got "xyz"}
} -returnCodes {error} -result {bad screen distance "xyz"}
test text-23.3 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs {100 200}
    update idletasks
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0]
} -cleanup {
    destroy .t
} -result {100 200}
test text-23.4 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs {100 right 200 left 300 center 400 numeric}
    update idletasks
    list [expr {[lindex [.t bbox 1.2] 0] + [lindex [.t bbox 1.2] 2]}] \
    list [expr [lindex [.t bbox 1.2] 0] + [lindex [.t bbox 1.2] 2]] \
	    [lindex [.t bbox 1.4] 0] \
	    [expr {[lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]/2}] \
	    [expr [lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]/2] \
	    [lindex [.t bbox 1.10] 0]
} -cleanup {
    destroy .t
} -result {100 200 300 400}
test text-23.5 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs {105 r 205 l 305 c 405 n}
    update idletasks
    list [expr {[lindex [.t bbox 1.2] 0] + [lindex [.t bbox 1.2] 2]}] \
    list [expr [lindex [.t bbox 1.2] 0] + [lindex [.t bbox 1.2] 2]] \
	    [lindex [.t bbox 1.4] 0] \
	    [expr {[lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]/2}] \
	    [expr [lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]/2] \
	    [lindex [.t bbox 1.10] 0]
} -cleanup {
    destroy .t
} -result {105 205 305 405}
test text-23.6 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs {100 left 200 lork}
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad tab alignment "lork": must be left, right, center, or numeric}
test text-23.7 {TkTextGetTabs procedure} -setup {
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 150
    text .t -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
    pack .t
} -body {
    .t insert end "1\t2\t3\t4\t55.5"
    .t configure -tabs {100 !44 200 lork}
} -cleanup {
    destroy .t
} -returnCodes {error} -result {expected screen distance but got "!44"}
} -returnCodes {error} -result {bad screen distance "!44"}


test text-24.1 {TextDumpCmd procedure, bad args} -body {
    pack [text .t]
    .t insert 1.0 "One Line"
    .t mark set insert 1.0
    .t dump
6427
6428
6429
6430
6431
6432
6433
6434

6435
6436
6437
6438

6439
6440
6441
6442

6443
6444
6445
6446

6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462

6463
6464
6465
6466
6467
6468
6469
6196
6197
6198
6199
6200
6201
6202

6203
6204
6205
6206

6207
6208
6209
6210

6211
6212
6213
6214

6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230

6231
6232
6233
6234
6235
6236
6237
6238







-
+



-
+



-
+



-
+















-
+







    return $x
} -cleanup {
    destroy .t
    rename Append {}
} -result {mark 1.0 current mark 1.0 insert mark 2.4 m}
test text-24.25 {TextDumpCmd procedure, unicode characters} -body {
    text .t
    .t insert 1.0 ±±±
    .t insert 1.0 \xb1\xb1\xb1
    .t dump -all 1.0 2.0
} -cleanup {
    destroy .t
} -result "text ±±± 1.0 mark insert 1.3 mark current 1.3 text {\n} 1.3"
} -result "text \xb1\xb1\xb1 1.0 mark insert 1.3 mark current 1.3 text {\n} 1.3"
test text-24.26 {TextDumpCmd procedure, unicode characters} -body {
    text .t
    .t delete 1.0 end
    .t insert 1.0 abc±±±
    .t insert 1.0 abc\xb1\xb1\xb1
    .t dump -all 1.0 2.0
} -cleanup {
    destroy .t
} -result "text abc±±± 1.0 mark insert 1.6 mark current 1.6 text {\n} 1.6"
} -result "text abc\xb1\xb1\xb1 1.0 mark insert 1.6 mark current 1.6 text {\n} 1.6"
test text-24.27 {TextDumpCmd procedure, peer present} -body {
    text .t
    .t peer create .t.t
    .t dump -all 1.0 end
} -cleanup {
    destroy .t
} -result "mark insert 1.0 mark current 1.0 text {\n} 1.0"

test text-25.1 {text widget vs hidden commands} -body {
    text .t
    set y [list {} [interp hidden]]
    interp hide {} .t
    destroy .t
    set x [list [winfo children .] [interp hidden]]
    expr {$x eq $y}
} -result 1
} -result {1}


test text-26.1 {bug fix - 1642} -body {
    pack [text .t]
    .t insert end "line 1\n"
    .t insert end "line 2\n"
    .t insert end "line 3\n"
6548
6549
6550
6551
6552
6553
6554
6555

6556
6557
6558
6559
6560
6561
6562
6563
6564

6565
6566
6567
6568
6569
6570
6571
6572

6573
6574
6575
6576

6577
6578
6579
6580
6581
6582
6583
6584
6585
6317
6318
6319
6320
6321
6322
6323

6324
6325
6326
6327
6328
6329
6330
6331
6332

6333
6334
6335
6336
6337
6338
6339
6340

6341
6342
6343
6344

6345
6346

6347
6348
6349
6350
6351
6352
6353







-
+








-
+







-
+



-
+

-







test text-27.8 {TextEditCmd procedure, modified flag} -body {
    text .t
    pack .t
    .t insert end "line 1\n"
    .t edit modified
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-27.9 {TextEditCmd procedure, reset modified flag} -body {
    text .t
    pack .t
    .t insert end "line 1\n"
    .t edit modified 0
    .t edit modified
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test text-27.10 {TextEditCmd procedure, set modified flag} -body {
    text .t
    pack .t
    .t edit modified 1
    .t edit modified
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-27.11 {TextEditCmd procedure, set modified flag repeat} -setup {
    text .t
    pack .t
# Make sure the Text is mapped before we start
    set ::retval {}
    update
    set ::retval {}
} -body {
    bind .t <<Modified>> "lappend ::retval modified"
# Shouldn't require [update idle] to trigger event [Bug 1809538]
    lappend ::retval [.t edit modified]
    .t edit modified 1
    update
    lappend ::retval [.t edit modified]
6635
6636
6637
6638
6639
6640
6641
6642
6643


6644
6645

6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761

6762
6763
6764
6765
6766
6767
6768
6403
6404
6405
6406
6407
6408
6409


6410
6411
6412

6413
6414
6415
6416
6417
6418
6419
6420
6421
6422









































































































6423

6424
6425
6426
6427
6428
6429
6430
6431







-
-
+
+

-
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







    bind .tt <<Modified>> {incr ::retval}
    .t insert end "This increments ::retval once for each peer, i.e. twice."
    .t edit modified 0  ; # shall increment twice as well, not just once
    update
    set ::retval
} -cleanup {
    destroy .t .tt
} -result 4
test text-27.15 {<<Selection>> virtual event on sel tagging} -body {
} -result {4}
test text-27.15 {<<Selection>> virtual event} -body {
    set ::retval no_selection
    pack [text .t]
    pack [text .t -undo 1]
    bind .t <<Selection>> "set ::retval selection_changed"
    update idletasks
    .t insert end "nothing special\n"
    .t tag add sel 1.0 1.1
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {selection_changed}
test text-27.15a {<<Selection>> virtual event on sel removal} -body {
    set ::retval no_selection
    pack [text .t]
    .t insert end "nothing special\n"
    .t tag add sel 1.0 1.1
    bind .t <<Selection>> "set ::retval selection_changed"
    update idletasks
    .t tag remove 1.0 end
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {selection_changed}
test text-27.15b {<<Selection>> virtual event on <<PasteSelection>> inside widget selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "and it will be impacted by the <<PasteSelection>> event received.\n"
    .t insert end "Therefore a <<Selection>> event must fire back."
    .t tag add sel 1.0 1.28
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    event generate .t <<PasteSelection>> -x 15 -y [lindex [.t dlineinfo 1.0] 1]
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {<<Selection>>_fired}
test text-27.15c {No <<Selection>> virtual event on <<PasteSelection>> outside widget selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "but it will not be impacted by the <<PasteSelection>> event received."
    .t tag add sel 1.0 1.28
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    event generate .t <<PasteSelection>> -x 15 -y [lindex [.t dlineinfo 2.0] 1]
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {no_<<Selection>>_event_fired}
test text-27.15d {<<Selection>> virtual event on <Delete> with cursor inside selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "and it will be impacted by the <Delete> event received.\n"
    .t insert end "Therefore a <<Selection>> event must fire back."
    .t tag add sel 1.0 1.28
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    .t mark set insert 1.15
    update idletasks
    focus -force .t
    event generate .t <Delete>
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {<<Selection>>_fired}
test text-27.15e {No <<Selection>> virtual event on <Delete> with cursor outside selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "but it will not be impacted by the <Delete> event received."
    .t tag add sel 1.0 1.28
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    .t mark set insert 2.15
    focus .t
    event generate .t <Delete>
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {no_<<Selection>>_event_fired}
test text-27.15f {<<Selection>> virtual event on <<Cut>> with a widget selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "and it will be impacted by the <<Cut>> event received.\n"
    .t insert end "Therefore a <<Selection>> event must fire back."
    .t tag add sel 1.0 1.28
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    event generate .t <<Cut>>
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {<<Selection>>_fired}
test text-27.15g {No <<Selection>> virtual event on <<Cut>> without widget selection} -body {
    pack [text .t]
    .t insert end "There is a selection in this text widget,\n"
    .t insert end "and it will be impacted by the <<Cut>> event received.\n"
    .t insert end "Therefore a <<Selection>> event must fire back."
    bind .t <<Selection>> "set ::retval <<Selection>>_fired"
    update
    set ::retval no_<<Selection>>_event_fired
    event generate .t <<Cut>>
    update
    set ::retval
} -cleanup {
    destroy .t
} -result {no_<<Selection>>_event_fired}
test text-27.16 {-maxundo configuration option} -body {
    text .t -undo 1 -autoseparators 1 -maxundo 2
    text .t -undo 1  -autoseparators 1 -maxundo 2
    pack .t
    .t insert end "line 1\n"
    .t delete 1.4 1.6
    .t insert end "line 2\n"
    catch {.t edit undo}
    catch {.t edit undo}
    catch {.t edit undo}
6818
6819
6820
6821
6822
6823
6824
6825

6826
6827
6828
6829
6830
6831
6832

6833
6834
6835
6836
6837
6838
6839
6481
6482
6483
6484
6485
6486
6487

6488
6489
6490
6491
6492
6493
6494

6495
6496
6497
6498
6499
6500
6501
6502







-
+






-
+







    .t edit modified 0
    .t edit undo
    .t insert end bar
    .t edit modified
} -cleanup {
    destroy .t
} -result 1
test text-27.19 {patch 1669632 (i) - undo after <Control-Button-1>} -setup {
test text-27.19 {patch 1669632 (i) - undo after <Control-1>} -setup {
    destroy .t
} -body {
    text .t -undo 1
    .t insert end foo\nbar
    .t edit reset
    .t insert 2.2 WORLD
    event generate .t <Control-Button-1> -x 1 -y 1
    event generate .t <Control-1> -x 1 -y 1
    .t insert insert HELLO
    .t edit undo
    .t get 2.2 2.7
} -cleanup {
    destroy .t
} -result WORLD
test text-27.20 {patch 1669632 (iv) - undo after <<SelectNone>>} -setup {
6858
6859
6860
6861
6862
6863
6864
6865

6866
6867
6868
6869
6870
6871
6872
6521
6522
6523
6524
6525
6526
6527

6528
6529
6530
6531
6532
6533
6534
6535







-
+







test text-27.21 {patch 1669632 (vii) - <<Undo>> shall not remove separators} -setup {
    destroy .t
} -body {
    text .t -undo 1
    .t insert end "This is an example text"
    .t edit reset
    .t insert 1.5 "WORLD "
    event generate .t <Control-Button-1> -x 1 -y 1
    event generate .t <Control-1> -x 1 -y 1
    .t insert insert HELLO
    event generate .t <<Undo>>
    .t insert insert E
    event generate .t <<Undo>>
    .t get 1.0 "1.0 lineend"
} -cleanup {
    destroy .t
7029
7030
7031
7032
7033
7034
7035
7036

7037
7038

7039
7040
7041
7042


7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068

7069
7070
7071
7072
7073
7074

7075
7076
7077
7078
7079
7080
7081
6692
6693
6694
6695
6696
6697
6698

6699
6700

6701
6702
6703


6704
6705














6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716

6717
6718
6719
6720
6721
6722

6723
6724
6725
6726
6727
6728
6729
6730







-
+

-
+


-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
+





-
+







    set res {}
} -body {
    pack [text .t -undo true -autoseparators false]
    .t insert end "Hello World.\n"
    .t edit separator
    .t insert end "Again hello.\n"
    .t edit undo
    lappend res [expr {[lsearch [.t mark names] tk::undoMark*]<0}]
    lappend res [lsearch [.t mark names] tk::undoMark*]
    .t edit redo
    lappend res [expr {[lsearch [.t mark names] tk::undoMark*]<0}]
    lappend res [lsearch [.t mark names] tk::undoMark*]
} -cleanup {
    destroy .t
} -result {1 1}
test text-27.29 {bug ab839efc5f - .text edit undo inserts separators} -setup {
} -result [list -1 -1]

    destroy .t
} -body {
    text .t -undo 1
    .t insert 1.0 "1. 123 5 789012  LINE-1\n2.\n3. 123 5 789012  LINE-3\n"
    .t tag add sel 3.0 3.end
    .t delete sel.first sel.last
    .t edit undo
    .t tag add sel 3.0 3.end
    .t delete sel.first sel.last
    .t edit undo
    .t get 3.0 3.end
} -cleanup {
    destroy .t
} -result {3. 123 5 789012  LINE-3}

test text-28.1 {bug fix - 624372, ControlUtfProc long lines} -body {
    pack [text .t -wrap none]
    .t insert end [string repeat "\1" 500]
} -cleanup {
    destroy .t
} -result {}


test text-29.1 {tabs - must be positive and must be increasing} -body {
    pack [text .t -wrap none]
    .t configure -tabs 0
    .t configure -tabs {0}
} -cleanup {
    destroy .t
} -returnCodes {error} -result {tab stop "0" is not at a positive distance}
test text-29.2 {tabs - must be positive and must be increasing} -body {
    pack [text .t -wrap none]
    .t configure -tabs -5
    .t configure -tabs {-5}
} -cleanup {
    destroy .t
} -returnCodes {error} -result {tab stop "-5" is not at a positive distance}
test text-29.3 {tabs - must be positive and must be increasing} -constraints {
    knownBug
} -body {
# This bug will be fixed in Tk 9.0, when we can allow a minor
7090
7091
7092
7093
7094
7095
7096
7097

7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110

7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121

7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132

7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143

7144
7145
7146
7147
7148
7149
7150
6739
6740
6741
6742
6743
6744
6745

6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758

6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769

6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780

6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791

6792
6793
6794
6795
6796
6797
6798
6799







-
+












-
+










-
+










-
+










-
+







    .t insert end "a\tb\tc\td\te"
    catch {.t configure -tabs {10c 5c}}
    update ; update ; update
# This test must simply not go into an infinite loop to succeed
    set result 1
} -cleanup {
    destroy .t
} -result 1
} -result {1}


test text-30.1 {repeated insert and scroll} -body {
    pack [text .t]
    for {set i 0} {$i < 30} {incr i} {
        .t insert end "blabla\n"
        eval .t yview moveto 1
    }
# This test must simply not crash to succeed
    set result 1
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-30.2 {repeated insert and scroll} -body {
    pack [text .t]
    for {set i 0} {$i < 30} {incr i} {
        .t insert end "blabla\n"
        eval .t yview scroll 1 pages
    }
# This test must simply not crash to succeed
    set result 1
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-30.3 {repeated insert and scroll} -body {
    pack [text .t]
    for {set i 0} {$i < 30} {incr i} {
        .t insert end "blabla\n"
        eval .t yview scroll 100 pixels
    }
# This test must simply not crash to succeed
    set result 1
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test text-30.4 {repeated insert and scroll} -body {
    pack [text .t]
    for {set i 0} {$i < 30} {incr i} {
        .t insert end "blabla\n"
        eval .t yview scroll 10 units
    }
# This test must simply not crash to succeed
    set result 1
} -cleanup {
    destroy .t
} -result 1
} -result {1}


test text-31.1 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    pack [.t peer create .top.t]
    destroy .t .top
7181
7182
7183
7184
7185
7186
7187
7188

7189
7190
7191
7192
7193
7194
7195
7196
7197
7198

7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213


7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226

7227
7228
7229
7230
7231
7232
7233

7234
7235
7236
7237
7238
7239
7240

7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253

7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266

7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282

7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297

7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312

7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328

7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348

7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368

7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389

7390
7391

7392
7393

7394
7395
7396
7397
7398
7399
7400
6830
6831
6832
6833
6834
6835
6836

6837
6838
6839
6840
6841
6842
6843
6844
6845
6846

6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860


6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874

6875
6876
6877
6878
6879
6880
6881

6882
6883
6884
6885
6886
6887
6888

6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901

6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914

6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930

6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945

6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960

6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976

6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996

6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016

7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037

7038
7039

7040
7041

7042
7043
7044
7045
7046
7047
7048
7049







-
+









-
+













-
-
+
+












-
+






-
+






-
+












-
+












-
+















-
+














-
+














-
+















-
+



















-
+



















-
+




















-
+

-
+

-
+







} -result {}
test text-31.4 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    update
    destroy .t .top
} -result {}
test text-31.5 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    pack [.top.t peer create .top.t2]
    set res [list [.top.t index end] [.top.t2 index end]]
    update
    return $res
} -cleanup {
    destroy .t .top
} -result {7.0 7.0}
test text-31.6 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.top.t peer create .top.t2 -startline {} -endline {}]
    pack [.t peer create .top.t -start 5 -end 11]
    pack [.top.t peer create .top.t2 -start {} -end {}]
    set res [list [.top.t index end] [.top.t2 index end]]
    update
    return $res
} -cleanup {
    destroy .t .top
} -result {7.0 21.0}
test text-31.7 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    update ; update
    set p1 [.top.t count -update -ypixels 1.0 end]
    set p2 [.t count -update -ypixels 5.0 11.0]
    expr {$p1 eq $p2}
} -cleanup {
    destroy .t .top
} -result 1
} -result {1}
test text-31.8 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    update ; update
    .t delete 3.0 6.0
    .top.t index end
} -cleanup {
    destroy .t .top
} -result {6.0}
test text-31.9 {peer widgets} -body {
    toplevel .top
    pack [text .t]
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    update ; update
    .t delete 8.0 12.0
    .top.t index end
} -cleanup {
    destroy .t .top
} -result {4.0}
test text-31.10 {peer widgets} -body {
    toplevel .top
    pack [text .t]
        for {set i 1} {$i < 20} {incr i} {
        .t insert end "Line $i\n"
    }
    pack [.t peer create .top.t -startline 5 -endline 11]
    pack [.t peer create .top.t -start 5 -end 11]
    update ; update
    .t delete 3.0 13.0
    .top.t index end
} -cleanup {
    destroy .t .top
} -result {1.0}
test text-31.11 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 100} {incr i} {
        .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 end-1c
    lappend res [.t tag ranges sel]
    .t configure -startline 10 -endline 20
    .t configure -start 10 -end 20
    lappend res [.t tag ranges sel]
    return $res
} -cleanup {
    destroy .t
} -result {{1.0 100.0} {1.0 11.0}}
test text-31.12 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 end-1c
    lappend res [.t tag ranges sel]
    .t configure -startline 11
    .t configure -start 11
    lappend res [.t tag ranges sel]
    return $res
} -cleanup {
    destroy .t
} -result {{1.0 100.0} {1.0 90.0}}
test text-31.13 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 end-1c
    lappend res [.t tag ranges sel]
    .t configure -endline 90
    .t configure -end 90
    lappend res [.t tag ranges sel]
    destroy .t
    return $res
} -cleanup {
    destroy .t
} -result {{1.0 100.0} {1.0 90.0}}
test text-31.14 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0
    lappend res [.t tag prevrange sel 1.0]
    .t configure -startline 6 -endline 12
    .t configure -start 6 -end 12
    lappend res [.t tag ranges sel]
    lappend res "next" [.t tag nextrange sel 4.0] \
      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
      [.t tag nextrange sel 7.0]
    lappend res "prev" [.t tag prevrange sel 1.0] \
      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
      [.t tag prevrange sel 4.0]
    return $res
} -cleanup {
    destroy .t
} -result {{} {1.0 2.0 4.0 6.0} next {4.0 6.0} {} {} {} prev {} {1.0 2.0} {1.0 2.0} {1.0 2.0}}
test text-31.15 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 3.0 9.0 11.0 13.0 15.0 17.0 19.0
    .t configure -startline 6 -endline 12
    .t configure -start 6 -end 12
    lappend res [.t tag ranges sel]
    lappend res "next" [.t tag nextrange sel 4.0] \
      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
      [.t tag nextrange sel 7.0]
    lappend res "prev" [.t tag prevrange sel 1.0] \
      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
      [.t tag prevrange sel 4.0]
    return $res
} -cleanup {
    destroy .t
} -result {{4.0 6.0} next {4.0 6.0} {} {} {} prev {} {} {} {}}
test text-31.16 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 20} {incr i} {
	.t insert end "Line $i\n"
    }
    .t tag add sel 1.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0
    .t configure -startline 6 -endline 12
    .t configure -start 6 -end 12
    lappend res [.t tag ranges sel]
    lappend res "next" [.t tag nextrange sel 4.0] \
      [.t tag nextrange sel 5.0] [.t tag nextrange sel 6.0] \
      [.t tag nextrange sel 7.0]
    lappend res "prev" [.t tag prevrange sel 1.0] \
      [.t tag prevrange sel 2.0] [.t tag prevrange sel 3.0] \
      [.t tag prevrange sel 4.0]
    return $res
} -cleanup {
    destroy .t
} -result {{1.0 2.0 4.0 6.0} next {4.0 6.0} {} {} {} prev {} {1.0 2.0} {1.0 2.0} {1.0 2.0}}
test text-31.17 {peer widgets} -setup {
    pack [text .t]
    set res {}
} -body {
    for {set i 1} {$i < 20} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 1.0 11.0
    lappend res [.t tag ranges sel]
    lappend res [catch {.t configure -startline 15 -endline 10}]
    lappend res [catch {.t configure -start 15 -end 10}]
    lappend res [.t tag ranges sel]
    .t configure -startline 6 -endline 12
    .t configure -start 6 -end 12
    lappend res [.t tag ranges sel]
    .t configure -startline {} -endline {}
    .t configure -start {} -end {}
    lappend res [.t tag ranges sel]
    return $res
} -cleanup {
    destroy .t
} -result {{1.0 11.0} 1 {1.0 11.0} {1.0 6.0} {1.0 11.0}}
test text-31.18 {peer widgets} -setup {
    pack [text .t]
7453
7454
7455
7456
7457
7458
7459






























7460
7461
7462









































































































7463
7464
7465
7466
7467
7468
7469
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138



7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    $w insert 1.0 "a"
    update
    set after [$w count -ypixels 1.0 2.0]
    destroy .g
    expr {$before eq $after}
} -cleanup {
    destroy .t
} -result {1}


test text-33.1 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer foo 1
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad peer option "foo": must be create or names}
test text-33.2 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer names foo
} -cleanup {
    destroy .t
} -returnCodes {error} -result {wrong # args: should be ".t peer names"}
test text-33.3 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t pee names
} -cleanup {
    destroy .t
} -returnCodes {ok} -result {}
test text-33.4 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer names
} -cleanup {
    destroy .t
} -result 1

test text-32.2 {peer widget -start, -endline and deletion (bug 1630262)} -setup {
} -result {}
test text-33.5 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer create foo
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad window path name "foo"}
test text-33.6 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
    set res {}
} -body {
    .t peer create .t2
    lappend res [.t peer names]
    lappend res [.t2 peer names]
    destroy .t2
    lappend res [.t peer names]
} -cleanup {
    destroy .t
} -result {.t2 .t {}}
test text-33.7 {peer widget -start, -end} -body {
    text .t
    set res [.t configure -start 10 -end 5]
    return $res
} -cleanup {
    destroy .t
} -returnCodes {2} -result {}
test text-33.8 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t configure -start 10 -end 5
} -cleanup {
    destroy .t
} -returnCodes {error} -result {-startline must be less than or equal to -endline}
test text-33.9 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	.t insert end "Line $i\n"
    }
    .t configure -start 5 -end 10
} -cleanup {
    destroy .t
} -returnCodes {ok} -result {}
test text-33.10 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    set res [.t index end]
    lappend res [catch {.t configure -start 5 -end 10 -tab foo}]
    lappend res [.t index end]
    lappend res [catch {.t configure -tab foo -start 15 -end 20}]
    lappend res [.t index end]
    .t configure -start {} -end {}
    lappend res [.t index end]
    return $res
} -cleanup {
    destroy .t
} -result {101.0 1 101.0 1 101.0 101.0}
test text-33.11 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    set res [.t index end]
    lappend res [catch {.t configure -start 5 -end 15}]
    lappend res [.t index end]
    lappend res [catch {.t configure -start 10 -end 40}]
    lappend res [.t index end]
    .t configure -start {} -end {}
    lappend res [.t index end]
    return $res
} -cleanup {
    destroy .t
} -result {101.0 0 11.0 0 31.0 101.0}

test text-34.1 {peer widget -start, -end and selection} -setup {
    text .t
    set res {}
} -body {
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 10.0 20.0
    lappend res [.t tag ranges sel]
    .t configure -start 5 -end 30
    lappend res [.t tag ranges sel]
    .t configure -start 5 -end 15
    lappend res [.t tag ranges sel]
    .t configure -start 15 -end 30
    lappend res [.t tag ranges sel]
    .t configure -start 15 -end 16
    lappend res [.t tag ranges sel]
    .t configure -start 25 -end 30
    lappend res [.t tag ranges sel]
    .t configure -start {} -end {}
    lappend res [.t tag ranges sel]
    return $res
} -cleanup {
    destroy .t
} -result {{10.0 20.0} {6.0 16.0} {6.0 11.0} {1.0 6.0} {1.0 2.0} {} {10.0 20.0}}

test text-32.2 {peer widget -start, -end and deletion (bug 1630262)} -setup {
    destroy .t .pt
    set res {}
} -body {
    text .t
    .t peer create .pt
    for {set i 1} {$i < 100} {incr i} {
      .t insert end "Line $i\n"
7483
7484
7485
7486
7487
7488
7489
7490

7491
7492

7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508

7509
7510
7511

7512
7513

7514
7515
7516
7517
7518
7519
7520
7264
7265
7266
7267
7268
7269
7270

7271
7272

7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288

7289
7290
7291

7292
7293

7294
7295
7296
7297
7298
7299
7300
7301







-
+

-
+















-
+


-
+

-
+







    # 4. delete to the end line: line1 < line2 in DeleteIndexRange,
    #    and resetView is true only for .t, not for .pt
    .pt delete 2.0 end
    # this test succeeds provided there is no crash
    set res 1
} -cleanup {
    destroy .pt
} -result 1
} -result {1}

test text-32.3 {peer widget -start, -endline and deletion (bug 1630262)} -setup {
test text-32.3 {peer widget -start, -end and deletion (bug 1630262)} -setup {
    destroy .t .pt
    set res {}
} -body {
    text .t
    .t peer create .pt
    for {set i 1} {$i < 100} {incr i} {
      .t insert end "Line $i\n"
    }
    .t configure -startline 5
    .pt configure -startline 3
    # the following delete shall not crash
    # (it did before fixing bug 1630262)
    .pt delete 2.0 3.0
    # moreover -startline shall be correct
    # (was wrong before fixing bug 1630262)
    lappend res [.t cget -start] [.pt cget -start] [.t get @0,0 "@0,0 lineend"]
    lappend res [.t cget -start] [.pt cget -start]
} -cleanup {
    destroy .pt
} -result {4 3 {Line 5}}
} -result {4 3}

test text-32.4 {peer widget -start, -endline and deletion (bug 1630262)} -setup {
test text-32.4 {peer widget -start, -end and deletion (bug 1630262)} -setup {
    destroy .t .pt
    set res {}
} -body {
    text .t
    .t peer create .pt
    for {set i 1} {$i < 100} {incr i} {
      .t insert end "Line $i\n"
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689

7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702

7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715

7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732

7733
7734
7735
7736
7737
7738


7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750

7751
7752
7753
7754
7755
7756


7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783

7784
7785
7786
7787
7788

7789
7790
7791

7792
7793
7794

7795
7796
7797


7798
7799
7800
7801

7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7330
7331
7332
7333
7334
7335
7336




































































































































7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381



7382
7383
7384
7385
7386


7387
7388
7389
7390
7391
7392



7393
7394



7395
7396
7397
7398
7399


7400
7401
7402


















7403
7404
7405



7406

7407





7408

7409

7410
7411


7412



7413
7414
7415
7416
7417

7418



7419
















7420
7421
7422
7423
7424
7425
7426
7427







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


+













+













+














-
-
-
+




-
-
+
+




-
-
-


-
-
-
+




-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-

-
+
-
-
-
-
-
+
-

-
+

-
-
+
-
-
-
+
+



-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








    # from .t, delete a range straddling the entire range of .pt
    .t delete 3.0 18.0
    lappend res [.t cget -start] [.t cget -end] [.pt cget -start] [.pt cget -end]
} -cleanup {
    destroy .pt .t
} -result {5 11 8 10 5 8 6 8 22 27 38 44 55 60 57 57}


test text-33.1 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer foo 1
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad peer option "foo": must be create or names}
test text-33.2 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer names foo
} -cleanup {
    destroy .t
} -returnCodes {error} -result {wrong # args: should be ".t peer names"}
test text-33.3 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer names
} -cleanup {
    destroy .t
} -returnCodes {ok} -result {}
test text-33.4 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer names
} -cleanup {
    destroy .t
} -result {}
test text-33.5 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
} -body {
    .t peer create foo
} -cleanup {
    destroy .t
} -returnCodes {error} -result {bad window path name "foo"}
test text-33.6 {TextWidgetCmd procedure, "peer" option} -setup {
    text .t
    set res {}
} -body {
    .t peer create .t2
    lappend res [.t peer names]
    lappend res [.t2 peer names]
    destroy .t2
    lappend res [.t peer names]
} -cleanup {
    destroy .t
} -result {.t2 .t {}}
test text-33.7 {peer widget -start, -end} -body {
    text .t
    set res [.t configure -startline 10 -endline 5]
    return $res
} -cleanup {
    destroy .t
} -returnCodes 2 -result {}
test text-33.8 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t configure -startline 10 -endline 5
} -cleanup {
    destroy .t
} -returnCodes {error} -result {-startline must be less than or equal to -endline}
test text-33.9 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	.t insert end "Line $i\n"
    }
    .t configure -startline 5 -endline 10
} -cleanup {
    destroy .t
} -returnCodes {ok} -result {}
test text-33.10 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    set res [.t index end]
    lappend res [catch {.t configure -startline 5 -endline 10 -tab foo}]
    lappend res [.t index end]
    lappend res [catch {.t configure -tab foo -startline 15 -endline 20}]
    lappend res [.t index end]
    .t configure -startline {} -endline {}
    lappend res [.t index end]
    return $res
} -cleanup {
    destroy .t
} -result {101.0 1 101.0 1 101.0 101.0}
test text-33.11 {peer widget -start, -end} -body {
    text .t
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    set res [.t index end]
    lappend res [catch {.t configure -startline 5 -endline 15}]
    lappend res [.t index end]
    lappend res [catch {.t configure -startline 10 -endline 40}]
    lappend res [.t index end]
    .t configure -startline {} -endline {}
    lappend res [.t index end]
    return $res
} -cleanup {
    destroy .t
} -result {101.0 0 11.0 0 31.0 101.0}

test text-34.1 {peer widget -start, -endline and selection} -setup {
    text .t
    set res {}
} -body {
    for {set i 1} {$i < 100} {incr i} {
	   .t insert end "Line $i\n"
    }
    .t tag add sel 10.0 20.0
    lappend res [.t tag ranges sel]
    .t configure -startline 5 -endline 30
    lappend res [.t tag ranges sel]
    .t configure -startline 5 -endline 15
    lappend res [.t tag ranges sel]
    .t configure -startline 15 -endline 30
    lappend res [.t tag ranges sel]
    .t configure -startline 15 -endline 16
    lappend res [.t tag ranges sel]
    .t configure -startline 25 -endline 30
    lappend res [.t tag ranges sel]
    .t configure -startline {} -endline {}
    lappend res [.t tag ranges sel]
    return $res
} -cleanup {
    destroy .t
} -result {{10.0 20.0} {6.0 16.0} {6.0 11.0} {1.0 6.0} {1.0 2.0} {} {10.0 20.0}}

test text-35.1 {widget dump -command alters tags} -setup {
     proc Dumpy {key value index} {
#puts "KK: $key, $value"
      .t tag add $value [list $index linestart] [list $index lineend]
    }
    text .t
} -body {
    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
    .t tag configure b -background red
    .t dump -all -command Dumpy 1.0 end
    set result "ok"
} -cleanup {
    destroy .t
} -result {ok}
test text-35.2 {widget dump -command makes massive changes} -setup {
    proc Dumpy {key value index} {
#puts "KK: $key, $value"
      .t delete 1.0 end
    }
    text .t
} -body {
    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
    .t tag configure b -background red
    .t dump -all -command Dumpy 1.0 end
    set result "ok"
} -cleanup {
    destroy .t
} -result {ok}
test text-35.3 {widget dump -command destroys widget} -setup {
    proc Dumpy {key value index} {
#puts "KK: $key, $value"
        destroy .t
    }
    text .t
} -body {
    .t insert end "abc\n" a "---" {} "def" b "   \n" {} "ghi\n" c
    .t tag configure b -background red
    .t dump -all -command Dumpy 1.0 end
    set result "ok"
} -cleanup {
    destroy .t
} -result {ok}


test text-36.1 "bug #1777362: event handling with hyphenated windows" -setup {
    set save [interp bgerror {}]
    interp bgerror {} returnerror-36.1
    proc returnerror-36.1 {m opts} {set ::my_error $m}
    proc bgerror {m} {set ::my_error $m}
    set ::my_error {}
    pack [set w [text .t-1]]
} -body {
    tkwait visibility $w
    event generate $w <Button-1>
    event generate $w <Button-1>
    event generate $w <1>
    event generate $w <1>
    update
    set ::my_error
} -cleanup {
    destroy .t-1
    rename returnerror-36.1 ""
    interp bgerror {} $save
    unset -nocomplain save ::my_error w
} -result {}
test text-36.2 "bug #1777362: event handling with hyphenated windows" -setup {
    set save [interp bgerror {}]
    interp bgerror {} returnerror-36.2
    proc returnerror-36.2 {m opts} {set ::my_error $m}
    proc bgerror {m} {set ::my_error $m}
    set ::my_error {}
    pack [set w [text .t+1]]
} -body {
    tkwait visibility $w
    event generate $w <Button-1>
    event generate $w <Button-1>
    event generate $w <1>
    event generate $w <1>
    update
    set ::my_error
} -cleanup {
    destroy $w
    rename returnerror-36.2 ""
    interp bgerror {} $save
    unset -nocomplain save ::my_error w
} -result {}
test text-36.3 "bug #1777362: event handling with hyphenated windows" -setup {
    set save [interp bgerror {}]
    interp bgerror {} returnerror-36.3
    proc returnerror-36.3 {m opts} {set ::my_error $m}
    set ::my_error {}
    pack [set w [text .t*1]]
} -body {
    tkwait visibility $w
    event generate $w <Button-1>
    event generate $w <Button-1>
    update
    set ::my_error
} -cleanup {
    destroy $w
    rename returnerror-36.3 ""
    interp bgerror {} $save
    unset -nocomplain save ::my_error w
} -result {}

test text-36.3 "bug #1777362: event handling with hyphenated windows" -setup {

test text-37.1 "bug #dd9667635d: text anchor not set" -setup {
    set save [interp bgerror {}]
    interp bgerror {} returnerror-37.1
    proc returnerror-37.1 {m opts} {set ::my_error $m}
    proc bgerror {m} {set ::my_error $m}
    destroy .t
    set ::my_error {}
    pack [text .t]
    pack [set w [text .t*1]]
} -body {
    .t insert end "Hello world!"
    .t tag add sel 1.0 end
    tkwait visibility $w
    # this line shall not trigger error:
    #     bad text index "tk::anchorN"
    event generate .t <<SelectPrevLine>>
    event generate $w <1>
    event generate $w <1>
    update
    set ::my_error
} -cleanup {
    destroy .t
    destroy $w
    rename returnerror-37.1 ""
    interp bgerror {} $save
    unset -nocomplain save ::my_error
} -result {}


test text-38.1 {Extending selection with mouse going outside the widget - Bug a9cf210a42} -setup {
    pack [text .t -width 40 -height 10]
    for {set n 1} {$n <= 5} {incr n} {
        .t insert end "This is line $i of text\n"
    }
    update
} -body {
    event generate .t <Button-1> -x 50 -y 50
    event generate .t <B1-Motion> -x 50 -y -50
    .t index sel.first
} -cleanup {
    destroy .t
} -result {1.0}


# cleanup
cleanupTests
return

# Local Variables:
# mode: tcl
# End:

Changes to tests/textBTree.test.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







# This file is a Tcl script to test out the B-tree facilities of
# Tk's text widget (the contents of the file "tkTextBTree.c".  There are
# several file with additional tests for other features of text widgets.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
253
254
255
256
257
258
259






























































260
261
262
263
264
265
266







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.21 {deleting with negative range} -body {
    .t delete 1.0 100000.0
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    .t delete 3.2 3.2
    .t get 1.0 1000000.0
} -result "Line 1\nLine 2\nLine 3\n"
test btree-2.22 {deleting into beginning of elided range} -setup {
    .t delete 1.0 end
} -body {
    for {set n 1} {$n <= 10} {incr n} {
        .t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 end
    .t delete 5.0 "5.0 + 8 chars"
    .t get 4.0 7.0
} -cleanup {
    .t tag delete Elided
    .t delete 1.0 end
} -result "Line 4\nine 6\nLine 7\n"
test btree-2.23 {deleting from within elided range} -body {
    for {set n 1} {$n <= 10} {incr n} {
        .t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 8.0
    .t delete 7.0 9.0
    .t get 6.0 8.0
} -cleanup {
    .t tag delete Elided
    .t delete 1.0 end
} -result "Line 6\nLine 9\n"
test btree-2.24 {deleting whole elided range} -body {
    for {set n 1} {$n <= 10} {incr n} {
        .t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 8.0
    .t delete 5.0 9.0
    .t get 4.0 6.0
} -cleanup {
    .t tag delete Elided
    .t delete 1.0 end
} -result "Line 4\nLine 9\n"
test btree-2.25 {deleting several elided ranges} -body {
    for {set n 1} {$n <= 10} {incr n} {
        .t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 6.2 6.4 6.5 7.2 7.6
    .t delete 5.0 9.0
    .t get 4.0 7.0
} -cleanup {
    .t tag delete Elided
    .t delete 1.0 end
} -result "Line 4\nLine 9\nLine 10\n"
test btree-2.26 {deleting first char of elided range} -body {
    for {set n 1} {$n <= 10} {incr n} {
        .t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 end
    .t delete 6.0 6.1
    .t get 5.0 7.0
} -cleanup {
    .t tag delete Elided
    .t delete 1.0 end
} -result "Line 5\nine 6\n"


test btree-3.1 {inserting with tags} -body {
    setup
    .t insert 1.0 XXX
    list [.t tag ranges x] [.t tag ranges y]
} -result {{1.4 1.5 1.8 1.16 2.2 2.6} {1.8 1.9}}
480
481
482
483
484
485
486
487
488


489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505


506
507
508
509
510

511
512
513
514
515
516
517
418
419
420
421
422
423
424


425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441


442
443
444
445
446
447

448
449
450
451
452
453
454
455







-
-
+
+















-
-
+
+




-
+







    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 100} {incr i} {
        set j [expr {$i+2}]
        set k [expr {1+2*$i}]
        set j [expr $i+2]
        set k [expr 1+2*$i]
        .t tag add x $j.1 $j.3
        .t tag add y $k.1 $k.6
    }
    .t delete 2.0 200.0
    list [.t tag ranges x] [.t tag ranges y]
} -result {{3.0 3.1 3.4 3.12 4.2 4.6} {1.1 1.6 3.4 3.5}}
test btree-6.6 {very large deletes, with tags} -setup {
    set bigText2 {}
    for {set i 0} {$i < 200} {incr i} {
        append bigText2 "Line $i\n"
    }
} -body {
    setup
    .t insert 1.1 $bigText2
    for {set i 0} {$i < 100} {incr i} {
        set j [expr {$i+2}]
        set k [expr {1+2*$i}]
        set j [expr $i+2]
        set k [expr 1+2*$i]
        .t tag add x $j.1 $j.3
        .t tag add y $k.1 $k.6
    }
    for {set i 199} {$i >= 2} {incr i -1} {
        .t delete $i.0 [expr {$i+1}].0
        .t delete $i.0 [expr $i+1].0
    }
    list [.t tag ranges x] [.t tag ranges y]
} -result {{3.0 3.1 3.4 3.12 4.2 4.6} {1.1 1.6 3.4 3.5}}


test btree-7.1 {tag addition and removal} -setup {
    .t delete 1.0 end

Changes to tests/textDisp.test.

1
2
3
4
5
6



7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54





55
56
57
58
59
60
61
62
63
64
65
66
67


68

69

70

71







72


73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
1
2
3



4
5
6
7
8

9
10
11
12
13








14
15
16
17
18
19
20
21
22
23
24
25
26
27















28



29
30
31
32
33


34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64

65

66





















67
68
69
70

71
72





























73
74
75
76
77
78
79



-
-
-
+
+
+


-
+




-
-
-
-
-
-
-
-














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
+
+
+
+
-
-










-
+
+

+

+

+

+
+
+
+
+
+
+
-
+
+

+

-

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







# This file is a Tcl script to test the code in the file tkTextDisp.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

# The delay procedure needs to wait long enough for the asynchronous updates
# performed by the text widget to run.
proc delay {} {
    update
    after 100
    update
}

# The procedure below is used as the scrolling command for the text;
# it just saves the scrolling information in a variable "scrollInfo".

proc scroll args {
    global scrollInfo
    set scrollInfo $args
}

# The procedure below is used to generate errors during scrolling commands.

proc scrollError args {
    error "scrolling error"
}

# Return 1 if the two given lists are the same, otherwise return the two lists.
# This is used to compare a test actual result with a test expected result.

proc lequal {res expected} {
    if {[llength $res] != [llength $expected]} {
        return [list "Lengths differ"  result: $res - expected: $expected]
    }
    for {set i 0} {$i < [llength $res]} {incr i} {
        if {[lindex $res $i] ne [lindex $expected $i]} {
	    return [list result: $res - expected: $expected]
	}
    }
    return 1
}

# Create entries in the option database to be sure that geometry options
# like border width have selected values.
option add *Text.borderWidth 2         ; # tests work with [1-3]
option add *Text.highlightThickness 2  ; # tests work with [0-5]
# like border width have predictable values.
set twbw 2
set twht 2
option add *Text.borderWidth $twbw
option add *Text.highlightThickness $twht
option add *Text.padX 1  ; # same padding in x and y, see proc bo; tests work with [0-4]
option add *Text.padY 1  ; # same padding in x and y, see proc bo; tests work with [0-4]

# The frame .f is needed to make sure that the overall window is always
# fairly wide, even if the text window is very narrow.  This is needed
# because some window managers don't allow the overall width of a window
# to get very narrow.

catch {destroy .f .t}
frame .f -width 100 -height 20
pack .f -side left

set fixedFont {Courier -12}
set fixedFont {"Courier New" -12}
# 15 on XP, 13 on Solaris 8
set fixedHeight [font metrics $fixedFont -linespace]
# 7 on all platforms
set fixedWidth [font measure $fixedFont m]
# 12 on XP
set fixedAscent [font metrics $fixedFont -ascent]
set fixedDiff [expr {$fixedHeight - 13}] ;# 2 on XP

set varFont {Times -14}
# 16 on XP, 15 on Solaris 8
set varHeight [font metrics $varFont -linespace]
# 13 on XP
set varAscent [font metrics $varFont -ascent]
set varDiff [expr {$varHeight - 15}] ;# 1 on XP

set bigFont {Helvetica -24}  ; # note: not a fixed-width font!
set bigFont {Helvetica -24}
# 27 on XP, 27 on Solaris 8
set bigHeight [font metrics $bigFont -linespace]
# 21 on XP
set bigAscent [font metrics $bigFont -ascent]

set ascentDiff [expr {$bigAscent - $fixedAscent}]
set heightDiff [expr {$bigHeight - $fixedHeight}]

# On Windows at least, the tests do work with {Courier -10}, {Courier -12} or {Courier -14} as fixedFont.
# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}
if {$fixedHeight < 12 || $fixedHeight > 17} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
is $fixedHeight pixels height while the tests expect between 12 and 17 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}
if {$fixedWidth < 6 || $fixedWidth > 8} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
is $fixedWidth pixels in width while the tests expect between 6 and 8 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}

# Option  -width 20  (characters) below is a fundamental assumption of many
# upcoming tests when wrapping enters in play
# Also  -height 10  (lines) is an important assumption
text .t -font $fixedFont -width 20 -height 10 -yscrollcommand scroll
pack .t -expand 1 -fill both
.t tag configure big -font $bigFont
.t debug on

wm geometry . {}

# full border size of the text widget, i.e. first x or y coordinate inside the text widget
# warning:  -padx  is supposed to be the same as  -pady  (same border size horizontally and
# vertically around the widget)
proc bo {{w .t}} {
    return [expr {[$w cget -borderwidth] + [$w cget -highlightthickness] + [$w cget -padx]}]
}
# x-width of $n chars, fixed width font
proc xw {n} {
    global fixedWidth
    return [expr {$n * $fixedWidth}]
}
# x-coordinate of the first pixel of $n-th char (count starts at zero), left justified
proc xchar {n {w .t}} {
    return [expr {[bo $w] + [xw $n]}]
}
# x-coordinate in widget $w of the first pixel of $n-th char counted from the right, right justified
proc xcharr {n {w .t}} {
    return [expr {[winfo width $w] - [bo $w] - [xw $n]}]
}
# y-coordinate of the first pixel of $l-th display line (count starts at 1)
proc yline {l {w .t}} {
    global fixedHeight
    return [expr {[bo $w] + ($l - 1) * $fixedHeight}]
}
# x-pixels of empty space in widget $w on a line containing $n chars
proc xe {n {w .t}} {
    return [expr {[winfo width $w] - (2 * [bo $w]) - [xw $n]}]
}

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.

wm withdraw .
wm minsize . 1 1
wm positionfrom . user
wm deiconify .
252
253
254
255
256
257
258
259

260
261

262
263
264
265
266
267
268
269

270
271
272
273

274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
300


301
302
303
304
305

306
307

308
309
310
311
312

313
314

315
316
317
318
319

320
321

322
323
324
325
326
327

328
329
330
331
332
333
334
335

336
337

338
339
340
341
342
343
344
345

346
347
348
349
350
351

352
353


354
355
356
357
358
359
360
361
362



363
364
365

366
367
368
369
370
371

372
373

374
375
376
377
378
379
380
381
382
383

384
385

386
387
388
389
390

391
392

393
394
395
396
397
398
399
400
401

402
403
404

405
406
407
408
409
410
411
412

413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428

429
430

431
432
433
434
435
436
437
438
439
440

441
442
443
444

445
446
447
448
449
450
451
452
453

454
455
456

457
458
459
460
461
462
463
464
465

466
467

468
469
470
471
472
473
474
475
476
477
478

479
480
481
482

483
484
485
486
487
488
489
490

491
492
493
494
495
496

497
498


499
500
501
502
503
504
505
506
507
508

509
510
511
512

513
514
515
516
517
518
519

520
521
522
523
524

525
526
527
528
529
530
531
532

533
534

535
536

537
538

539
540
541

542
543

544
545

546
547

548
549
550
551

552
553
554
555
556
557
558
559

560
561

562
563

564
565

566
567
568
569
570
571
572
573

574
575

576
577

578
579

580
581
582
583

584
585
586
587
588
589
590
591
592
593


594
595
596
597
598

599
600
601
602
603
604
605


606
607

608
609
610
611

612
613
614
615
616
617
618
619
620
621
622



623
624
625
626
627
628
629
630


631
632
633
634
635


636
637
638
639
640


641
642
643
644

645
646

647
648
649
650
651
652
653
654
655

656
657
658
659
660
661

662
663
664
665
666
667
668
669
670
671

672
673
674
675
676

677
678
679
680
681
682
683
684
685
686
687

688
689
690
691
692

693
694
695
696
697
698
699
700

701
702
703
704
705

706
707
708
709
710
711
712
713
714
715
716



717
718
719
720
721
722
723
724
725
726
727
728

729
730

731
732
733
734
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750
751
752
753
754

755

756
757
758
759
760
761




762
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
189
190
191
192
193
194
195

196
197

198
199
200
201
202
203
204
205

206
207
208
209

210
211

212
213
214
215
216
217
218
219
220
221
222
223
224


225

226
227
228
229
230
231
232



233
234
235
236
237
238

239


240
241
242
243
244

245


246
247
248
249
250

251


252
253
254
255
256


257


258
259
260
261
262

263


264
265
266
267
268
269
270


271

272
273
274


275


276
277
278
279
280
281
282
283



284
285
286



287
288
289
290
291


292


293
294
295
296
297
298
299
300
301


302


303
304
305
306
307

308


309
310
311
312
313
314
315
316


317



318
319
320
321
322
323
324
325

326




327
328
329
330
331
332
333
334
335
336



337


338
339
340
341
342
343
344
345
346
347

348




349
350
351
352
353
354
355
356


357



358
359
360
361
362
363
364



365


366
367
368
369
370
371
372
373
374
375
376

377

378
379

380
381
382
383





384
385





386


387
388
389
390
391
392
393
394
395
396
397

398




399
400
401
402
403
404
405

406


407
408

409
410
411
412
413
414
415
416

417
418

419
420

421
422

423
424
425

426
427

428
429

430
431

432
433
434
435

436
437
438
439
440
441
442
443

444
445

446
447

448
449

450
451
452
453
454
455
456
457

458
459

460
461

462
463

464
465
466
467

468
469
470
471
472
473
474
475
476


477
478
479
480



481
482
483
484
485



486
487


488




489
490
491
492
493
494
495
496
497



498
499
500
501
502
503
504
505
506


507
508
509
510
511


512
513
514
515
516


517
518
519
520
521

522
523

524
525
526
527
528
529
530
531
532

533



534


535
536
537
538
539
540
541
542
543
544

545





546
547
548
549
550
551
552
553
554
555
556

557





558
559
560
561
562
563
564
565

566



567

568
569
570
571
572
573






574
575
576
577
578
579
580
581
582
583
584
585



586


587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

613


614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637







-
+

-
+







-
+



-
+

-
+












-
-
+
-







-
-
-
+
+




-
+
-
-
+




-
+
-
-
+




-
+
-
-
+




-
-
+
-
-





-
+
-
-
+






-
-
+
-



-
-
+
-
-
+
+






-
-
-
+
+
+
-
-
-
+




-
-
+
-
-
+








-
-
+
-
-
+




-
+
-
-
+







-
-
+
-
-
-
+







-
+
-
-
-
-
+









-
-
-
+
-
-
+









-
+
-
-
-
-
+







-
-
+
-
-
-
+






-
-
-
+
-
-
+










-
+
-


-
+



-
-
-
-
-
+

-
-
-
-
-
+
-
-
+
+









-
+
-
-
-
-
+






-
+
-
-


-
+







-
+

-
+

-
+

-
+


-
+

-
+

-
+

-
+



-
+







-
+

-
+

-
+

-
+







-
+

-
+

-
+

-
+



-
+








-
-
+
+


-
-
-
+




-
-
-
+
+
-
-
+
-
-
-
-
+








-
-
-
+
+
+






-
-
+
+



-
-
+
+



-
-
+
+



-
+

-
+








-
+
-
-
-

-
-
+









-
+
-
-
-
-
-
+










-
+
-
-
-
-
-
+







-
+
-
-
-

-
+





-
-
-
-
-
-
+
+
+









-
-
-
+
-
-
+










-
+













+
-
+
-
-




+
+
+
+








-
+







    destroy .txt
} {}

test textDisp-1.1 {GetStyle procedure, priorities and tab stops} {
    .t delete 1.0 end
    .t insert 1.0 "x\ty"
    .t tag delete x y z
    .t tag configure x -tabs 50
    .t tag configure x -tabs {50}
    .t tag configure y -foreground black
    .t tag configure z -tabs 70
    .t tag configure z -tabs {70}
    .t tag add x 1.0 1.end
    .t tag add y 1.0 1.end
    .t tag add z 1.0 1.end
    update idletasks
    set x [lindex [.t bbox 1.2] 0]
    .t tag configure z -tabs {}
    lappend x [lindex [.t bbox 1.2] 0]
    .t tag configure z -tabs 30
    .t tag configure z -tabs {30}
    .t tag raise x
    update idletasks
    lappend x [lindex [.t bbox 1.2] 0]
} [list [expr {[bo]+70}] [expr {[bo]+50}] [expr {[bo]+50}]]
} [list 75 55 55]
.t tag delete x y z
test textDisp-1.2 {GetStyle procedure, wrapmode} {
test textDisp-1.2 {GetStyle procedure, wrapmode} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcd\nefg hijkl mnop qrstuv wxyz"
    .t tag configure x -wrap word
    .t tag configure y -wrap none
    .t tag raise y
    update
    set result [list [.t bbox 2.20]]
    .t tag add x 2.0 2.1
    lappend result [.t bbox 2.20]
    .t tag add y 1.end 2.2
    lappend result [.t bbox 2.20]
} [list [list [xchar 0] [yline 3] $fixedWidth $fixedHeight] \
        [list [xchar 5] [yline 3] $fixedWidth $fixedHeight] \
} [list [list 5 [expr {5+2*$fixedHeight}] 7 $fixedHeight] [list 40 [expr {5+2*$fixedHeight}] 7 $fixedHeight] {}]
	    {}]
.t tag delete x y

test textDisp-2.1 {LayoutDLine, basics} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "This is some sample text for testing."
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.2 {LayoutDLine, basics} {
} [list [list [expr 5 + $fixedWidth * 19] 5 $fixedWidth $fixedHeight] [list 5 [expr 5 + $fixedHeight] $fixedWidth $fixedHeight]]
test textDisp-2.2 {LayoutDLine, basics} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "This isx some sample text for testing."
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 138 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.3 {LayoutDLine, basics} {
test textDisp-2.3 {LayoutDLine, basics} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "This isxxx some sample text for testing."
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 138 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.4 {LayoutDLine, word wrap} {
test textDisp-2.4 {LayoutDLine, word wrap} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This is some sample text for testing."
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 138 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.5 {LayoutDLine, word wrap} {
test textDisp-2.5 {LayoutDLine, word wrap} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This isx some sample text for testing."
    list [.t bbox 1.13] [.t bbox 1.19] [.t bbox 1.20] [.t bbox 1.21]
} [list [list [xchar 13] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 96 5 $fixedWidth $fixedHeight] [list 138 5 $fixedWidth $fixedHeight] [list 145 5 0  $fixedHeight] [list 5 [expr {$fixedDiff + 18}] $fixedWidth $fixedHeight]]
	    [list [xchar 20] [yline 1] 0  $fixedHeight] \
	    [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.6 {LayoutDLine, word wrap} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This isxxx some sample text for testing."
    list [.t bbox 1.15] [.t bbox 1.16]
} [list [list [xchar 15] [yline 1] [xe 15] $fixedHeight] \
} [list [list 110 5 35 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.7 {LayoutDLine, marks and tags} {
test textDisp-2.7 {LayoutDLine, marks and tags} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This isxxx some sample text for testing."
    .t tag add foo 1.4 1.6
    .t mark set insert 1.8
    list [.t bbox 1.2] [.t bbox 1.5] [.t bbox 1.11]
} [list [list [xchar 2] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 5] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 19 5 7 $fixedHeight] [list 40 5 7 $fixedHeight] [list 82 5 7 $fixedHeight]]
	    [list [xchar 11] [yline 1] $fixedWidth $fixedHeight]]
foreach m [.t mark names] {
    catch {.t mark unset $m}
}
test textDisp-2.8 {LayoutDLine, extra chunk at end of dline} -setup {
    scan [wm geom .] %dx%d width height
scan [wm geom .] %dx%d width height
} -body {
    wm geom . [expr {$width+1}]x$height
test textDisp-2.8 {LayoutDLine, extra chunk at end of dline} {textfonts} {
    wm geom . [expr $width+1]x$height
    update
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "This isxx some sample text for testing."
    .t mark set foo 1.20
    list [.t bbox 1.19] [.t bbox 1.20]
} -cleanup {
    wm geom . {}
    update
} [list [list 138 5 8 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
wm geom . {}
update
} -result [list [list [xchar 19] [yline 1] [expr {$fixedWidth+1}] $fixedHeight] \
                [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.9 {LayoutDLine, marks and tags} {
test textDisp-2.9 {LayoutDLine, marks and tags} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This is a very_very_long_word_that_wraps."
    list [.t bbox 1.9] [.t bbox 1.10] [.t bbox 1.25]
} [list [list [xchar 9] [yline 1] [xe 9] $fixedHeight] \
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 68 5 77 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 110 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
	    [list [xchar 15] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.10 {LayoutDLine, marks and tags} {
test textDisp-2.10 {LayoutDLine, marks and tags} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This is a very_very_long_word_that_wraps."
    .t tag add foo 1.13
    .t tag add foo 1.15
    .t tag add foo 1.17
    .t tag add foo 1.19
    list [.t bbox 1.9] [.t bbox 1.10] [.t bbox 1.25]
} [list [list [xchar 9] [yline 1] [xe 9] $fixedHeight] \
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 68 5 77 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 110 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
	    [list [xchar 15] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-2.11 {LayoutDLine, newline width} {
test textDisp-2.11 {LayoutDLine, newline width} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a\nbb\nccc\ndddd"
    list [.t bbox 2.2] [.t bbox 3.3]
} [list [list [xchar 2] [yline 2] [xe 2] $fixedHeight] \
} [list [list 19 [expr {$fixedDiff + 18}] 126 $fixedHeight] [list 26 [expr {2*$fixedDiff + 31}] 119 $fixedHeight]]
        [list [xchar 3] [yline 3] [xe 3] $fixedHeight]]
test textDisp-2.12 {LayoutDLine, justification} {
test textDisp-2.12 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "\na\nbb\nccc\ndddd"
    .t tag configure x -justify center
    .t tag add x 1.0 end
    .t tag add y 3.0 3.2
    list [.t bbox 1.0] [.t bbox 2.0] [.t bbox 4.0] [.t bbox 4.2]
} [list [list [expr {[bo]+[xe 0]/2}] [yline 1] [expr {[xe 0]-[xe 0]/2}] $fixedHeight] \
        [list [expr {[bo]+[xe 1]/2}] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 75 5 70 $fixedHeight] [list 71 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 64 [expr {3*$fixedDiff + 44}] 7 $fixedHeight] [list 78 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [expr {[bo]+[xe 3]/2}] [yline 4] $fixedWidth $fixedHeight] \
        [list [expr {[bo]+[xe 3]/2+[xw 2]}] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.13 {LayoutDLine, justification} {
test textDisp-2.13 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "\na\nbb\nccc\ndddd"
    .t tag configure x -justify right
    .t tag add x 1.0 end
    .t tag add y 3.0 3.2
    list [.t bbox 1.0] [.t bbox 2.0] [.t bbox 4.0] [.t bbox 4.2]
} [list [list [xcharr 0] [yline 1] 0 $fixedHeight] \
} [list [list 145 5 0 $fixedHeight] [list 138 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 124 [expr {3*$fixedDiff + 44}] 7 $fixedHeight] [list 138 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [xcharr 1] [yline 2] $fixedWidth $fixedHeight] \
        [list [xcharr 3] [yline 4] $fixedWidth $fixedHeight] \
        [list [xcharr 1] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.14 {LayoutDLine, justification} {
test textDisp-2.14 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "\na\nbb\nccc\ndddd"
    .t tag configure x -justify center
    .t tag add x 2.0 3.1
    .t tag configure y -justify right
    .t tag add y 3.0 4.0
    .t tag raise y
    list [.t bbox 2.0] [.t bbox 3.0] [.t bbox 3.end] [.t bbox 4.0]
} [list [list [expr {[bo]+[xe 1]/2}] [yline 2] $fixedWidth $fixedHeight] \
        [list [xcharr 2] [yline 3] $fixedWidth $fixedHeight] \
        [list [xcharr 0] [yline 3] 0 $fixedHeight] \
} [list [list 71 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 131 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 145 [expr {2*$fixedDiff + 31}] 0 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [xchar 0] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.15 {LayoutDLine, justification} {
test textDisp-2.15 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "\na\nbb\nccc\ndddd"
    .t tag configure x -justify center
    .t tag add x 2.0 3.1
    .t tag configure y -justify right
    .t tag add y 3.0 4.0
    .t tag lower y
    list [.t bbox 2.0] [.t bbox 3.0] [.t bbox 3.end] [.t bbox 4.0]
} [list [list [expr {[bo]+[xe 1]/2}] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 71 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 68 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 82 [expr {2*$fixedDiff + 31}] 63 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [expr {[bo]+[xe 2]/2}] [yline 3] $fixedWidth $fixedHeight] \
        [list [expr {[bo]+[xe 2]/2+[xw 2]}] [yline 3] [expr {[xe 2]/2}] $fixedHeight] \
        [list [xchar 0] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.16 {LayoutDLine, justification} {
test textDisp-2.16 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines"
    .t tag configure x -justify center
    .t tag add x 1.1 1.20
    .t tag add x 1.21 1.end
    list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.41] [.t bbox 2.0]
} [list [list [xchar 0] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 5 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 61 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [expr {[bo]+[xe 4]/2}] [yline 3] $fixedWidth $fixedHeight] \
        [list [xchar 0] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.17 {LayoutDLine, justification} {
test textDisp-2.17 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Lots of very long words, enough to force word wrap\nThen\nmore lines"
    .t tag configure x -justify center
    .t tag add x 1.18
    list [.t bbox 1.0] [.t bbox 1.18] [.t bbox 1.35] [.t bbox 2.0]
} [list [list [xchar 0] [yline 1] $fixedWidth $fixedHeight] \
        [list [expr {[bo]+[xe 17]/2}] [yline 2] $fixedWidth $fixedHeight] \
        [list [xchar 0] [yline 3] $fixedWidth $fixedHeight] \
} [list [list 5 5 7 $fixedHeight] [list 15 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [xchar 0] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.18 {LayoutDLine, justification} {
test textDisp-2.18 {LayoutDLine, justification} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert 1.0 "Lots of long words, enough to extend out of the window\n"
    .t insert end "Then\nmore lines\nThat are shorter"
    .t tag configure x -justify center
    .t tag configure y -justify right
    .t tag add x 2.0
    .t tag add y 3.0
    .t xview scroll 5 units
    list [.t bbox 2.0] [.t bbox 3.0]
} [list [list [expr {[bo]+[xe 4]/2-[xw 5]}] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 26 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 40 [expr {2*$fixedDiff + 31}] 7 $fixedHeight]]
        [list [expr {[xcharr 10]-[xw 5]}] [yline 3] $fixedWidth $fixedHeight]]
.t tag delete x
.t tag delete y
test textDisp-2.19 {LayoutDLine, margins} {
test textDisp-2.19 {LayoutDLine, margins} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines"
    # margins in pixels depend on the font width for more flexibility
    set lm1 [expr {3*$fixedWidth}]
    set lm2 [expr {2*$lm1}]
    set rm [expr {2*$fixedWidth}]
    .t tag configure x -lmargin1 $lm1 -lmargin2 $lm2 -rmargin $rm
    .t tag configure x -lmargin1 20 -lmargin2 40 -rmargin 15
    .t tag add x 1.0 end
    set expected [list [list [expr {[bo]+$lm1}] [yline 1] $fixedWidth $fixedHeight] \
                       [list [expr {[bo]+$lm1+[xw 12]}] [yline 1] [expr {[xe 12]-$lm1}] $fixedHeight] \
                       [list [expr {[bo]+$lm2}] [yline 2] $fixedWidth $fixedHeight] \
                       [list [expr {[bo]+$lm1}] [yline 6] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.0] [.t bbox 1.12] [.t bbox 1.13] [.t bbox 2.0]] $expected
    list [.t bbox 1.0] [.t bbox 1.12] [.t bbox 1.13] [.t bbox 2.0]
} {1}
test textDisp-2.20 {LayoutDLine, margins} {
} [list [list 25 5 7 $fixedHeight] [list 109 5 36 $fixedHeight] [list 45 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 25 [expr {5*$fixedDiff + 70}] 7 $fixedHeight]]
test textDisp-2.20 {LayoutDLine, margins} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines"
    .t tag configure x -lmargin1 20 -lmargin2 10 -rmargin 3
    .t tag configure y -lmargin1 15 -lmargin2 5 -rmargin 0
    .t tag raise y
    .t tag add x 1.0 end
    .t tag add y 1.13
    list [.t bbox 1.0] [.t bbox 1.13] [.t bbox 1.30] [.t bbox 2.0]
} [list [list [expr {[bo]+20}] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 25 5 7 $fixedHeight] [list 10 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 15 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 25 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]]
        [list [expr {[bo]+5}] [yline 2] $fixedWidth $fixedHeight] \
        [list [expr {[bo]+10}] [yline 3] $fixedWidth $fixedHeight] \
        [list [expr {[bo]+20}] [yline 4] $fixedWidth $fixedHeight]]
test textDisp-2.21 {LayoutDLine, margins} {
test textDisp-2.21 {LayoutDLine, margins} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Sample text"
    .t tag configure x -lmargin1 80 -lmargin2 80 -rmargin 100
    .t tag add x 1.0 end
    list [.t bbox 1.0] [.t bbox 1.1] [.t bbox 1.2]
} [list [list [expr {[bo]+80}] [yline 1] [expr {[xe 0]-80}] $fixedHeight] \
} [list [list 85 5 60 $fixedHeight] [list 85 [expr {$fixedDiff + 18}] 60 $fixedHeight] [list 85 [expr {2*$fixedDiff + 31}] 60 $fixedHeight]]
        [list [expr {[bo]+80}] [yline 2] [expr {[xe 0]-80}] $fixedHeight] \
        [list [expr {[bo]+80}] [yline 3] [expr {[xe 0]-80}] $fixedHeight]]
.t tag delete x
.t tag delete y
test textDisp-2.22 {LayoutDLine, spacing options} {
test textDisp-2.22 {LayoutDLine, spacing options} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t tag delete x y
    .t insert end "Short line\nLine 2 is long enough "
    .t insert end "to wrap around a couple of times"
    .t insert end "\nLine 3\nLine 4"
    set i [.t dlineinfo 1.0]
    set b1 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b1 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 2.0]
    set b2 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b2 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 2.end]
    set b3 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b3 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 3.0]
    set b4 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b4 [expr [lindex $i 1] + [lindex $i 4]]
    .t configure -spacing1 2 -spacing2 1 -spacing3 3
    set i [.t dlineinfo 1.0]
    set b1 [expr {[lindex $i 1] + [lindex $i 4] - $b1}]
    set b1 [expr [lindex $i 1] + [lindex $i 4] - $b1]
    set i [.t dlineinfo 2.0]
    set b2 [expr {[lindex $i 1] + [lindex $i 4] - $b2}]
    set b2 [expr [lindex $i 1] + [lindex $i 4] - $b2]
    set i [.t dlineinfo 2.end]
    set b3 [expr {[lindex $i 1] + [lindex $i 4] - $b3}]
    set b3 [expr [lindex $i 1] + [lindex $i 4] - $b3]
    set i [.t dlineinfo 3.0]
    set b4 [expr {[lindex $i 1] + [lindex $i 4] - $b4}]
    set b4 [expr [lindex $i 1] + [lindex $i 4] - $b4]
    list $b1 $b2 $b3 $b4
} [list 2 7 10 15]
.t configure -spacing1 0 -spacing2 0 -spacing3 0
test textDisp-2.23 {LayoutDLine, spacing options} {
test textDisp-2.23 {LayoutDLine, spacing options} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t tag delete x y
    .t insert end "Short line\nLine 2 is long enough "
    .t insert end "to wrap around a couple of times"
    .t insert end "\nLine 3\nLine 4"
    set i [.t dlineinfo 1.0]
    set b1 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b1 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 2.0]
    set b2 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b2 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 2.end]
    set b3 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b3 [expr [lindex $i 1] + [lindex $i 4]]
    set i [.t dlineinfo 3.0]
    set b4 [expr {[lindex $i 1] + [lindex $i 4]}]
    set b4 [expr [lindex $i 1] + [lindex $i 4]]
    .t configure -spacing1 4 -spacing2 4 -spacing3 4
    .t tag configure x -spacing1 1 -spacing2 2 -spacing3 3
    .t tag add x 1.0 end
    .t tag configure y -spacing1 0 -spacing2 3
    .t tag add y 2.19 end
    .t tag raise y
    set i [.t dlineinfo 1.0]
    set b1 [expr {[lindex $i 1] + [lindex $i 4] - $b1}]
    set b1 [expr [lindex $i 1] + [lindex $i 4] - $b1]
    set i [.t dlineinfo 2.0]
    set b2 [expr {[lindex $i 1] + [lindex $i 4] - $b2}]
    set b2 [expr [lindex $i 1] + [lindex $i 4] - $b2]
    set i [.t dlineinfo 2.end]
    set b3 [expr {[lindex $i 1] + [lindex $i 4] - $b3}]
    set b3 [expr [lindex $i 1] + [lindex $i 4] - $b3]
    set i [.t dlineinfo 3.0]
    set b4 [expr {[lindex $i 1] + [lindex $i 4] - $b4}]
    set b4 [expr [lindex $i 1] + [lindex $i 4] - $b4]
    list $b1 $b2 $b3 $b4
} [list 1 5 13 16]
.t configure -spacing1 0 -spacing2 0 -spacing3 0
test textDisp-2.24 {LayoutDLine, tabs, saving from first chunk} {
test textDisp-2.24 {LayoutDLine, tabs, saving from first chunk} {textfonts} {
    .t delete 1.0 end
    .t tag delete x y
    .t tag configure x -tabs 70
    .t tag configure y -tabs 80
    .t insert 1.0 "ab\tcde"
    .t tag add x 1.0 end
    .t tag add y 1.1 end
    lindex [.t bbox 1.3] 0
} [expr {[bo]+70}]
test textDisp-2.25 {LayoutDLine, tabs, breaking chunks at tabs} {
} {75}
test textDisp-2.25 {LayoutDLine, tabs, breaking chunks at tabs} {textfonts} {
    .t delete 1.0 end
    .t tag delete x
    # compute a tab width allowing to let 4 tab stops (followed by a single char) on a single line
    set tw [expr {([winfo width .t]-2*[bo]-$fixedWidth)/4}]
    .t tag configure x -tabs [list $tw [expr {$tw*2}] [expr {$tw*3}] [expr {$tw*4}]]
    .t tag configure x -tabs [list 30 60 90 120]
    .t insert 1.0 "a\tb\tc\td\te"
    .t mark set dummy1 1.1
    .t mark set dummy2 1.2
    .t tag add x 1.0 end
    set expected [list [expr {[bo]+$tw}] [expr {[bo]+2*$tw}] [expr {[bo]+3*$tw}] [expr {[bo]+4*$tw}]]
    set res [list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \
	          [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]]
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \
	    [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]
    lequal $res $expected
} {1}
} [list 35 65 95 125]
# Next test is currently constrained to not run on mac (aqua) because on
# aqua it fails due to wrong implementation of tabs with right justification
# (the text is not rendered at all). This is a bug.
test textDisp-2.26 {LayoutDLine, tabs, breaking chunks at tabs} {notAqua} {
test textDisp-2.26 {LayoutDLine, tabs, breaking chunks at tabs} {textfonts} {
    .t delete 1.0 end
    .t tag delete x
    .t tag configure x -tabs [list 30 60 90 120] -justify right
    .t insert 1.0 "a\tb\tc\td\te"
    .t mark set dummy1 1.1
    .t mark set dummy2 1.2
    .t tag add x 1.0 end
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \
	     [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]
} [list [xcharr 4] [xcharr 3] [xcharr 2] [xcharr 1]]
test textDisp-2.27 {LayoutDLine, tabs, calling AdjustForTab} {
	    [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]
} [list 117 124 131 138]
test textDisp-2.27 {LayoutDLine, tabs, calling AdjustForTab} {textfonts} {
    .t delete 1.0 end
    .t tag delete x
    .t tag configure x -tabs [list 30 60]
    .t insert 1.0 "a\tb\tcd"
    .t tag add x 1.0 end
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0]
} [list [expr {[bo]+30}] [expr {[bo]+60}]]
test textDisp-2.28 {LayoutDLine, tabs, running out of space in dline} {
} [list 35 65]
test textDisp-2.28 {LayoutDLine, tabs, running out of space in dline} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 "a\tb\tc\td"
    .t bbox 1.6
} [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]
test textDisp-2.29 {LayoutDLine, tabs, running out of space in dline} {
} [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight]
test textDisp-2.29 {LayoutDLine, tabs, running out of space in dline} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 "a\tx\tabcd"
    .t bbox 1.4
} [list [xchar [expr {2*8}]] [yline 1] $fixedWidth $fixedHeight]
test textDisp-2.30 {LayoutDLine, tabs, running out of space in dline} {
} [list 117 5 7 $fixedHeight]
test textDisp-2.30 {LayoutDLine, tabs, running out of space in dline} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 "a\tx\tabc"
    .t bbox 1.4
} [list [xchar [expr {2*8}]] [yline 1] $fixedWidth $fixedHeight]
} [list 117 5 7 $fixedHeight]

test textDisp-3.1 {different character sizes} haveBigFontTwiceLargerThanTextFont {
test textDisp-3.1 {different character sizes} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert end "Some sample text, including both large\n"
    .t insert end "characters and\nsmall\n"
    .t insert end "abc\nd\ne\nfghij"
    .t tag add big 1.5 1.10
    .t tag add big 2.11 2.14
    list [.t bbox 1.1] [.t bbox 1.6] [.t dlineinfo 1.0] [.t dlineinfo 3.0]
} [list [list [xchar 1] [expr {[yline 1]+$ascentDiff}] $fixedWidth $fixedHeight] \
} [list [list 12 [expr {5+$ascentDiff}] 7 $fixedHeight] [list 52 5 13 27] [list 5 5 114 27 [font metrics $bigFont -ascent]] [list 5 [expr {2* $fixedDiff + 85}] 35 $fixedHeight [expr {$fixedDiff + 10}]]]
        [list [expr {[xchar 5]+[font measure $bigFont s]}] [yline 1] [font measure $bigFont a] $bigHeight] \
	[list [bo] [yline 1] [expr {[xw 5]+[font measure $bigFont sampl]+[xw 2]}] $bigHeight $bigAscent] \
	[list [bo] [expr {[bo]+2*$bigHeight+2*$fixedHeight}] [xw 5] $fixedHeight $fixedAscent]]
.t configure -wrap char

test textDisp-4.1 {UpdateDisplayInfo, basic} {
test textDisp-4.1 {UpdateDisplayInfo, basic} {textfonts} {
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2\nLine 3\n"
    update
    .t delete 2.0 2.end
    update
    set res $tk_textRelayout
    .t insert 2.0 "New Line 2"
    update
    lappend res [.t bbox 1.0] [.t bbox 2.0] [.t bbox 3.0] $tk_textRelayout
} [list 2.0 \
} [list 2.0 [list 5 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] 2.0]
        [list [xchar 0] [yline 1] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 3] $fixedWidth $fixedHeight] \
	2.0]
test textDisp-4.2 {UpdateDisplayInfo, re-use tail of text line} {
test textDisp-4.2 {UpdateDisplayInfo, re-use tail of text line} {textfonts} {
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    .t mark set x 2.21
    .t delete 2.2
    update
    set res $tk_textRelayout
    .t insert 2.0 X
    update
    lappend res [.t bbox 2.0] [.t bbox x] [.t bbox 3.0] $tk_textRelayout
} [list 2.0 2.20 \
} [list 2.0 2.20 [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 12 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight] {2.0 2.20}]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [xchar 1] [yline 3] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 4] $fixedWidth $fixedHeight] \
	{2.0 2.20}]
test textDisp-4.3 {UpdateDisplayInfo, tail of text line shifts} {
test textDisp-4.3 {UpdateDisplayInfo, tail of text line shifts} {textfonts} {
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    .t mark set x 2.21
    .t delete 2.2
    update
    list [.t bbox 2.0] [.t bbox x] [.t bbox 3.0] $tk_textRelayout
} [list [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight] {2.0 2.20}]
        [list [xchar 0] [yline 3] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 4] $fixedWidth $fixedHeight] \
	{2.0 2.20}]
.t mark unset x
test textDisp-4.4 {UpdateDisplayInfo, wrap-mode "none"} {
test textDisp-4.4 {UpdateDisplayInfo, wrap-mode "none"} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    list [.t bbox 2.0] [.t bbox 2.25] [.t bbox 3.0] $tk_textRelayout
} [list [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
        {} \
	[list [xchar 0] [yline 3] $fixedWidth  $fixedHeight] \
	{1.0 2.0 3.0}]
test textDisp-4.5 {UpdateDisplayInfo, tiny window} {
    if {[tk windowingsystem] eq "win32"} {
} [list [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] {} [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] {1.0 2.0 3.0}]
test textDisp-4.5 {UpdateDisplayInfo, tiny window} {textfonts} {
    if {$tcl_platform(platform) == "windows"} {
	wm overrideredirect . 1
    }
    wm geom . 103x$height
    update
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    list [.t bbox 2.0] [.t bbox 2.1] [.t bbox 3.0] $tk_textRelayout
} [list [list [xchar 0] [yline 2] 1 $fixedHeight] \
        {} \
	[list [xchar 0] [yline 3] 1 $fixedHeight] \
} [list [list 5 [expr {$fixedDiff + 18}] 1 $fixedHeight] {} [list 5 [expr {2*$fixedDiff + 31}] 1 $fixedHeight] {1.0 2.0 3.0}]
	{1.0 2.0 3.0}]
if {[tk windowingsystem] eq "win32"} {
if {$tcl_platform(platform) == "windows"} {
    wm overrideredirect . 0
}
test textDisp-4.6 {UpdateDisplayInfo, tiny window} {
    # This test was failing on Windows because the title bar on .
    # was a certain minimum size and it was interfering with the size
    # requested.  The "overrideredirect" gets rid of the titlebar so
    # the toplevel can shrink to the appropriate size.  On Unix, setting
    # the overrideredirect on "." confuses the window manager and
    # causes subsequent tests to fail.

    if {[tk windowingsystem] eq "win32"} {
    if {$tcl_platform(platform) == "windows"} {
	wm overrideredirect . 1
    }
    frame .f2 -width 20 -height 100
    pack .f2 -before .f
    wm geom . 103x103
    update
    .t configure -wrap none -borderwidth 2
    .t delete 1.0 end
    .t insert end "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    set x [list [.t bbox 1.0] [.t bbox 2.0] $tk_textRelayout]
    wm overrideredirect . 0
    update
    set x
    set expected [list [list [xchar 0] [yline 1] 1 1] {} 1.0]
} [list [list 5 5 1 1] {} 1.0]
    lequal $x $expected
} {1}
catch {destroy .f2}
.t configure -borderwidth 0 -wrap char
wm geom . {}
update
set bw [.t cget -borderwidth]
set px [.t cget -padx]
set py [.t cget -pady]
set hlth [.t cget -highlightthickness]
test textDisp-4.7 {UpdateDisplayInfo, filling in extra vertical space} {
    # This test was failing on Windows because the title bar on .
    # was a certain minimum size and it was interfering with the size
    # requested.  The "overrideredirect" gets rid of the titlebar so
    # the toplevel can shrink to the appropriate size.  On Unix, setting
    # the overrideredirect on "." confuses the window manager and
    # causes subsequent tests to fail.

    if {[tk windowingsystem] eq "win32"} {
    if {$tcl_platform(platform) == "windows"} {
	wm overrideredirect . 1
    }
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17"
    .t yview 1.0
    update
    .t yview 16.0
786
787
788
789
790
791
792
793

794
795
796
797
798
799
800

801
802
803
804
805
806
807
808
646
647
648
649
650
651
652

653
654
655
656
657
658
659

660

661
662
663
664
665
666
667







-
+






-
+
-







    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17"
    .t yview 16.0
    update
    .t delete 5.0 14.0
    update
    set x [list [.t index @0,0] $tk_textRelayout $tk_textRedraw]
} {1.0 {5.0 4.0 3.0 2.0 1.0} {1.0 2.0 3.0 4.0 5.0 eof}}
test textDisp-4.9 {UpdateDisplayInfo, filling in extra vertical space} {
test textDisp-4.9 {UpdateDisplayInfo, filling in extra vertical space} {textfonts} {
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17"
    .t yview 16.0
    update
    .t delete 15.0 end
    list [.t bbox 7.0] [.t bbox 12.0]
} [list [list [xchar 0] [yline 3] $fixedWidth $fixedHeight] \
} [list [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + 2 * $fixedHeight}] $fixedWidth $fixedHeight] [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + 7 * $fixedHeight}] $fixedWidth $fixedHeight]]
	[list [xchar 0] [yline 8] $fixedWidth $fixedHeight]]
test textDisp-4.10 {UpdateDisplayInfo, filling in extra vertical space} {
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\nLine 6 is such a long line that it wraps around.\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17"
    .t yview end
    update
    .t delete 13.0 end
    update
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
684
685
686
687
688
689
690

691
692
693
694
695
696
697
698







-
+







    .t yview moveto 1
    update
    .t yview moveto 0
    update
    .t yview moveto 1
    update
    winfo ismapped .b
} 0
} {0}
.t configure -wrap word
.t delete 1.0 end
.t insert end "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\n"
.t insert end "Line 8\nLine 9\nLine 10\nLine 11\nLine 12\nLine 13\n"
.t insert end "Line 14\nLine 15\nLine 16"
.t tag delete x
.t tag configure x -relief raised -borderwidth 2 -background white
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
880
881
882

883
884
885
886

887
888
889
890
891
892
893
894
895

896
897

898
899
900
901
902
903
904
905
906
907

908
909

910
911
912
913
914
915
916
917
918
919
920

921
922

923
924
925
926
927
928
929
930
931
932
933

934
935
936
937
938
939
940
941
942

943
944

945
946
947
948
949
950
951
952
953
954
955
956


957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973

974
975
976
977
978
979
980
981

982
983
984
985
986
987
988
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738
739
740

741




742
743
744
745
746
747
748
749
750

751


752
753
754
755
756
757
758
759
760
761

762


763
764
765
766
767
768
769
770
771
772
773

774


775
776
777
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794

795


796
797
798
799
800
801
802
803
804




805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

823



824
825
826
827
828
829
830
831
832
833
834
835
836







-
+









-
+
-
-
-
-
+








-
+
-
-
+









-
+
-
-
+










-
+
-
-
+










-
+








-
+
-
-
+








-
-
-
-
+
+
















-
+
-
-
-





+







    .t tag remove x 1.0 end
    .t yview 4.0
    update
    .t yview scroll -2 units
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 3.0} {2.0 3.0}}
test textDisp-4.17 {UpdateDisplayInfo, horizontal scrolling} {
test textDisp-4.17 {UpdateDisplayInfo, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    update
    .t xview scroll 3 units
    update
    list $tk_textRelayout $tk_textRedraw [.t bbox 2.0] [.t bbox 2.5] \
	    [.t bbox 2.23]
} [list {} {1.0 2.0 3.0 4.0} \
} [list {} {1.0 2.0 3.0 4.0} {} [list 17 [expr {$fixedDiff + 16}] 7 $fixedHeight] {}]
        {} \
        [list [expr {[xchar 5]-[xw 3]}] [yline 2] $fixedWidth $fixedHeight] \
	{}]
test textDisp-4.18 {UpdateDisplayInfo, horizontal scrolling} {
test textDisp-4.18 {UpdateDisplayInfo, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    update
    .t xview scroll 100 units
    update
    list $tk_textRelayout $tk_textRedraw [.t bbox 2.25]
} [list {} {1.0 2.0 3.0 4.0} \
} [list {} {1.0 2.0 3.0 4.0} [list 10 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
        [list [xcharr 19] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-4.19 {UpdateDisplayInfo, horizontal scrolling} {
test textDisp-4.19 {UpdateDisplayInfo, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    update
    .t xview moveto 0
    .t xview scroll -10 units
    update
    list $tk_textRelayout $tk_textRedraw [.t bbox 2.5]
} [list {} {1.0 2.0 3.0 4.0} \
} [list {} {1.0 2.0 3.0 4.0} [list 38 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
	[list [xchar 5] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-4.20 {UpdateDisplayInfo, horizontal scrolling} {
test textDisp-4.20 {UpdateDisplayInfo, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    .t xview moveto 0.0
    .t xview scroll 100 units
    update
    .t delete 2.30 2.44
    update
    list $tk_textRelayout $tk_textRedraw [.t bbox 2.25]
} [list 2.0 {1.0 2.0 3.0 4.0} \
} [list 2.0 {1.0 2.0 3.0 4.0} [list 108 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
        [list [xcharr 5] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-4.21 {UpdateDisplayInfo, horizontal scrolling} {
test textDisp-4.21 {UpdateDisplayInfo, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    .t xview moveto .9
    update
    .t xview moveto .6
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {}}
test textDisp-4.22 {UpdateDisplayInfo, no horizontal scrolling except for -wrap none} {
test textDisp-4.22 {UpdateDisplayInfo, no horizontal scrolling except for -wrap none} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    .t xview scroll 25 units
    update
    .t configure -wrap word
    list [.t bbox 2.0] [.t bbox 2.16]
} [list [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 10 [expr {2*$fixedDiff + 29}] 7 $fixedHeight]]
        [list [xchar 1] [yline 3] $fixedWidth $fixedHeight]]
test textDisp-4.23 {UpdateDisplayInfo, no horizontal scrolling except for -wrap none} {
test textDisp-4.23 {UpdateDisplayInfo, no horizontal scrolling except for -wrap none} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "Short line 1\nLine 2 is long enough to scroll horizontally"
    .t insert end "\nLine 3\nLine 4"
    .t xview scroll 25 units
    update
    .t configure -wrap char
    list [.t bbox 2.0] [.t bbox 2.16]
} [list [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [xchar 16] [yline 2] $fixedWidth $fixedHeight]]

test textDisp-5.1 {DisplayDLine, handling of spacing} {
} [list [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 115 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-5.1 {DisplayDLine, handling of spacing} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijkl\nmnopqrstuvwzyz"
    .t tag configure spacing -spacing1 8 -spacing3 2
    .t tag add spacing 1.0 end
    frame .t.f1 -width 10 -height 4 -bg black
    frame .t.f2 -width 10 -height 4 -bg black
    frame .t.f3 -width 10 -height 4 -bg black
    frame .t.f4 -width 10 -height 4 -bg black
    .t window create 1.3 -window .t.f1 -align top
    .t window create 1.7 -window .t.f2 -align center
    .t window create 2.1 -window .t.f3 -align bottom
    .t window create 2.10 -window .t.f4 -align baseline
    update
    list [winfo geometry .t.f1] [winfo geometry .t.f2] \
	    [winfo geometry .t.f3] [winfo geometry .t.f4]
} [list 10x4+[xchar 3]+[expr {[yline 1]+8}] \
} [list 10x4+24+11 10x4+55+[expr {$fixedDiff/2 + 15}] 10x4+10+[expr {2*$fixedDiff + 43}] 10x4+76+[expr {2*$fixedDiff + 40}]]
        10x4+[expr {[xchar 6]+10}]+[expr {[yline 1]+8+($fixedHeight-4)/2}] \
	10x4+[xchar 1]+[expr {[yline 2]+8+2+8+($fixedHeight-4)}] \
	10x4+[expr {[xchar 9]+10}]+[expr {[yline 2]+8+2+8+($fixedAscent-4)}]]
.t tag delete spacing

# Although the following test produces a useful result, its main
# effect is to produce a core dump if Tk doesn't handle display
# relayout that occurs during redisplay.

test textDisp-5.2 {DisplayDLine, line resizes during display} {
    .t delete 1.0 end
    frame .t.f -width 20 -height 20 -bd 2 -relief raised
    bind .t.f <Configure> {.t.f configure -width 30 -height 30}
    .t window create insert -window .t.f
    update
    list [winfo width .t.f] [winfo height .t.f]
1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116



1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141
1142
1143
1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155
1156


1157
1158
1159
1160
1161
1162
1163
1164
1165


1166
1167

1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235
1236
1237
881
882
883
884
885
886
887

888

889
890
891
892
893
894
895
896
897
898
899
900
901
902

903

904
905
906
907
908
909


910
911
912
913
914
915
916
917
918

919
920
921
922
923


924

925
926
927
928
929
930
931
932
933
934
935


936
937
938
939
940
941
942
943
944
945
946
947
948
949
950








951
952
953














954
955
956
957
958
959
960
961

962

963
964
965
966
967
968
969

970

971
972
973
974
975
976


977
978

979
980
981
982
983
984


985
986


987
988
989
990
991
992
993
994

995

996
997
998
999
1000
1001
1002
1003

1004

1005
1006
1007
1008
1009
1010
1011
1012

1013

1014
1015
1016
1017
1018
1019
1020
1021

1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034

1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
1053







-
+
-














-
+
-






-
-
+








-
+




-
-
+
-











-
-
+














-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







-
+
-







-
+
-






-
-
+
+
-






-
-
+
+
-
-
+







-
+
-








-
+
-








-
+
-








-
+
-












-
+










-
+







    }
    update
    .t insert 2.end "is so long that it wraps around, not once but three times"
    .t insert 4.end "is so long that it wraps"
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 2.20 2.40 2.60 4.0 4.20} {2.0 2.20 2.40 2.60 4.0 4.20 6.0}}
test textDisp-6.5 {scrolling in DisplayText, scroll source obscured} {aquaKnownBug} {
test textDisp-6.5 {scrolling in DisplayText, scroll source obscured} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    .t configure -wrap char
    frame .f2 -bg red
    place .f2 -in .t -relx 0.5 -rely 0.5 -relwidth 0.5 -relheight 0.5
    .t delete 1.0 end
    .t insert 1.0 "Line 1 is so long that it wraps around, a couple of times"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
    update
    .t delete 1.6 1.end
    update
    destroy .f2
    list $tk_textRelayout $tk_textRedraw
} {{1.0 9.0 10.0} {1.0 4.0 5.0 9.0 10.0}}
test textDisp-6.6 {scrolling in DisplayText, Expose events after scroll} {aquaKnownBug} {
test textDisp-6.6 {scrolling in DisplayText, Expose events after scroll} {unix nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    # this test depends on all of the expose events being handled at once
    .t configure -wrap char
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.2 -rely 0.5 -relwidth 0.5 -relheight 0.5
    .t configure -bd 2 -relief raised
    .t delete 1.0 end
    # Line 1 must wrap exactly twice to get the expected result
    .t insert 1.0 "Line 1 is so long that it occupies 3 display lines"
    .t insert 1.0 "Line 1 is so long that it wraps around, a couple of times"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
    update
    .t delete 1.6 1.end
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{1.0 9.0 10.0} {1.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0}}
} {{1.0 9.0 10.0} {borders 1.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0}}
.t configure -bd 0
test textDisp-6.7 {DisplayText, vertical scrollbar updates} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    .t count -update -ypixels 1.0 end
    update ; .t count -update -ypixels 1.0 end ; update
    update
    set scrollInfo
} {0.0 1.0}
test textDisp-6.8 {DisplayText, vertical scrollbar updates} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    update
    set scrollInfo "unchanged"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
	.t insert end "\nLine $i"
    }
    update
    .t count -update -ypixels 1.0 end ; update
    update ; .t count -update -ypixels 1.0 end ; update
    set scrollInfo
} [list 0.0 [expr {10.0/13}]]
.t configure -yscrollcommand {} -xscrollcommand scroll
test textDisp-6.9 {DisplayText, horizontal scrollbar updates} {
    .t configure -wrap none
    .t delete 1.0 end
    update
    set scrollInfo unchanged
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxx
    update
    set scrollInfo
} [list 0.0 [expr {4.0/11}]]
test textDisp-6.10 {DisplayText, redisplay embedded windows after scroll} {aqua} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4} {
	.t insert end "\nLine $i"
    }
    .t insert end "\n"

# The following group of tests is marked non-portable because
# they result in a lot of extra redisplay under Ultrix.  I don't
    .t window create end -create {
	button %W.button_one -text "Button 1"}
    .t insert end "\nLine 6\n"
    .t window create end -create {
	button %W.button_two -text "Button 2"}
    .t insert end "\nLine 8\n"
    .t window create end -create {
	button %W.button_three -text "Button 3"}
    update
    .t delete 2.0 3.0
    update
    list $tk_textEmbWinDisplay
} {{4.0 6.0}}

# know why this is so.

.t configure -bd 2 -relief raised -wrap char
.t delete 1.0 end
.t insert 1.0 "Line 1 is so long that it wraps around, a couple of times"
foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
    .t insert end "\nLine $i"
}
test textDisp-7.1 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.1 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.2 -relwidth 0.6 -rely 0.22 -relheight 0.55
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {1.40 2.0 3.0 4.0 5.0 6.0}}
test textDisp-7.2 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.2 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0 -relwidth 0.5 -rely 0 -relheight 0.5
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {1.0 1.20 1.40 2.0 3.0}}
test textDisp-7.3 {TkTextRedrawRegion} {aquaKnownBug} {
} {{} {borders 1.0 1.20 1.40 2.0 3.0}}
test textDisp-7.3 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.5 -relwidth 0.5 -rely 0.5 -relheight 0.5
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {4.0 5.0 6.0 7.0 8.0}}
test textDisp-7.4 {TkTextRedrawRegion} {aquaKnownBug} {
} {{} {borders 4.0 5.0 6.0 7.0 8.0}}
test textDisp-7.4 {TkTextRedrawRegion} {nonPortable} {
 # constrained by aquaKnownBug until ticket [aad0231f07] is fixed
   frame .f2 -bg #ff0000
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.4 -relwidth 0.2 -rely 0 -relheight 0.2 \
	    -bordermode ignore
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {borders 1.0 1.20}}
test textDisp-7.5 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.5 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.4 -relwidth 0.2 -rely 1.0 -relheight 0.2 \
	    -anchor s -bordermode ignore
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {borders 7.0 8.0}}
test textDisp-7.6 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.6 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0 -relwidth 0.2 -rely 0.55 -relheight 0.2 \
	    -anchor w -bordermode ignore
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {borders 3.0 4.0 5.0}}
test textDisp-7.7 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.7 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 1.0 -relwidth 0.2 -rely 0.55 -relheight 0.2 \
	    -anchor e -bordermode ignore
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {borders 3.0 4.0 5.0}}
test textDisp-7.8 {TkTextRedrawRegion} {aquaKnownBug} {
test textDisp-7.8 {TkTextRedrawRegion} {nonPortable} {
# constrained by aquaKnownBug until ticket [aad0231f07] is fixed
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\n"
    frame .f2 -bg #ff0000
    place .f2 -in .t -relx 0.0 -relwidth 0.4 -rely 0.35 -relheight 0.4 \
	    -anchor nw -bordermode ignore
    update
    destroy .f2
    update
    list $tk_textRelayout $tk_textRedraw
} {{} {borders 4.0 5.0 6.0 7.0 eof}}
.t configure -bd 0

test textDisp-8.1 {TkTextChanged: redisplay whole lines} {
test textDisp-8.1 {TkTextChanged: redisplay whole lines} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is so long that it wraps around, two times"
    foreach i {3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
    update
    .t delete 2.36 2.38
    update
    list $tk_textRelayout $tk_textRedraw [.t bbox 2.32]
} [list {2.0 2.18 2.38} {2.0 2.18 2.38} [list [xchar 14] [yline 3] $fixedWidth $fixedHeight]]
} [list {2.0 2.18 2.38} {2.0 2.18 2.38} [list 101 [expr {2*$fixedDiff + 29}] 7 $fixedHeight]]
.t configure -wrap char
test textDisp-8.2 {TkTextChanged, redisplay whole lines} {
    .t delete 1.0 end
    .t insert 1.0 "Line 1 is so long that it wraps around, two times"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
1313
1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154


1155

1156
1157
1158
1159
1160
1161
1162







-
+


















-
-
+
-







	.t insert end "\nLine $i"
    }
    update
    .t delete 2.0 3.0
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 8.0} {2.0 8.0}}
test textDisp-8.10 {TkTextChanged} haveBigFontTwiceLargerThanTextFont {
test textDisp-8.10 {TkTextChanged} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 2.19
    update
    .t delete 2.19
    update
    set tk_textRedraw
} {2.0 2.20 eof}
test textDisp-8.11 {TkTextChanged, scrollbar notification when changes are off-screen} {
    .t delete 1.0 end
    .t insert end "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n"
    .t configure -yscrollcommand scroll
    update
    set scrollInfo ""
    .t insert end "a\nb\nc\n"
    # We need to wait for our asychronous callbacks to update the
    # scrollbar
    update
    .t count -update -ypixels 1.0 end
    update ; .t count -update -ypixels 1.0 end ; update
    update
    .t configure -yscrollcommand ""
    set scrollInfo
} {0.0 0.625}
test textDisp-8.12 {TkTextChanged, moving the insert cursor redraws only past and new lines} {
    .t delete 1.0 end
    .t configure -wrap none
    for {set i 1} {$i < 25} {incr i} {
1373
1374
1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393


1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406


1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428

1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445


1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480


1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494


1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505


1506
1507
1508
1509
1510
1511
1512
1187
1188
1189
1190
1191
1192
1193

1194


1195
1196
1197
1198
1199
1200

1201




1202
1203


1204
1205
1206
1207
1208
1209
1210




1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

1234



1235

1236
1237
1238
1239
1240
1241
1242
1243





1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266


1267
1268
1269
1270
1271
1272
1273
1274




1275
1276


1277
1278
1279
1280
1281
1282
1283
1284




1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295


1296
1297
1298
1299
1300
1301
1302
1303
1304







-
+
-
-






-
+
-
-
-
-
+
+
-
-







-
-
-
-
+
+










-
+










-
+
-
-
-
+
-








-
-
-
-
-
+
+










-
+









-
+
-
-








-
-
-
-
+
+
-
-








-
-
-
-
+
+





-
+



-
-
+
+







    .t insert 1.0 \nLine2\nLine3\n
    update
    .t insert 3.0 ""
    .t delete 1.0 2.0
    update idletasks
} {}

test textDisp-9.1 {TkTextRedrawTag} -constraints {
test textDisp-9.1 {TkTextRedrawTag} {
    haveBigFontTwiceLargerThanTextFont
} -body {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap around\nLine 3\nLine 4"
    update
    .t tag add big 2.2 2.4
    update
   list $tk_textRelayout $tk_textRedraw
    list $tk_textRelayout $tk_textRedraw
# glob matching is to have some tolerance on actually used font size
# while still testing what we want to test
} -match glob -result {{2.0 2.1[78]} {2.0 2.1[78]}}
test textDisp-9.2 {TkTextRedrawTag} -constraints {
} {{2.0 2.18} {2.0 2.18}}
test textDisp-9.2 {TkTextRedrawTag} {textfonts} {
    haveBigFontTwiceLargerThanTextFont
} -body {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap around\nLine 3\nLine 4"
    update
    .t tag add big 1.2 2.4
    update
    list $tk_textRelayout $tk_textRedraw
# glob matching is to have some tolerance on actually used font size
# while still testing what we want to test
} -match glob -result {{1.0 2.0 2.1[678]} {1.0 2.0 2.1[678]}}
test textDisp-9.3 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
} {{1.0 2.0 2.17} {1.0 2.0 2.17}}
test textDisp-9.3 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap around\nLine 3\nLine 4"
    update
    .t tag add big 2.2 2.4
    update
    .t tag remove big 1.0 end
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 2.20} {2.0 2.20 eof}}
test textDisp-9.4 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
test textDisp-9.4 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap around\nLine 3\nLine 4"
    update
    .t tag add big 2.2 2.20
    update
    .t tag remove big 1.0 end
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 2.20} {2.0 2.20 eof}}
test textDisp-9.5 {TkTextRedrawTag} -constraints {
test textDisp-9.5 {TkTextRedrawTag} {
    haveBigFontTwiceLargerThanTextFont
} -setup {
    .t configure -wrap char -height [expr {[.t cget -height]+10}]
    .t configure -wrap char
} -body {
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap around\nLine 3\nLine 4"
    update
    .t tag add big 2.2 2.end
    update
    .t tag remove big 1.0 end
    update
    list $tk_textRelayout $tk_textRedraw
} -cleanup {
    .t configure -height [expr {[.t cget -height]-10}]
    update
} -result {{2.0 2.20} {2.0 2.20 eof}}
test textDisp-9.6 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
} {{2.0 2.20} {2.0 2.20 eof}}
test textDisp-9.6 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap"
    update
    .t tag add big 2.2 3.5
    update
    .t tag remove big 1.0 end
    update
    list $tk_textRelayout $tk_textRedraw
} {{2.0 2.20 3.0 3.20} {2.0 2.20 3.0 3.20 eof}}
test textDisp-9.7 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
test textDisp-9.7 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 2.19
    update
    .t tag remove big 2.19
    update
    set tk_textRedraw
} {2.0 2.20 eof}
test textDisp-9.8 {TkTextRedrawTag} -constraints {
test textDisp-9.8 {TkTextRedrawTag} {textfonts} {
    haveBigFontTwiceLargerThanTextFont
} -body {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 1.0 2.0
    update
    .t tag add big 2.0 2.5
    update
    set tk_textRedraw
# glob matching is to have some tolerance on actually used font size
# while still testing what we want to test
} -match glob -result {2.0 2.1[678]}
test textDisp-9.9 {TkTextRedrawTag} -constraints {
} {2.0 2.17}
test textDisp-9.9 {TkTextRedrawTag} {textfonts} {
    haveBigFontTwiceLargerThanTextFont
} -body {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 1.0 2.0
    update
    .t tag add big 1.5 2.5
    update
    set tk_textRedraw
# glob matching is to have some tolerance on actually used font size
# while still testing what we want to test
} -match glob -result {2.0 2.1[678]}
test textDisp-9.10 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
} {2.0 2.17}
test textDisp-9.10 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 1.0 2.0
    update
    set tk_textRedraw none
    set tk_textRedraw {none}
    .t tag add big 1.3 1.5
    update
    set tk_textRedraw
} none
test textDisp-9.11 {TkTextRedrawTag} haveBigFontTwiceLargerThanTextFont {
} {none}
test textDisp-9.11 {TkTextRedrawTag} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2 is long enough to wrap\nLine 3 is also long enough to wrap\nLine 4"
    .t tag add big 1.0 2.0
    update
    .t tag add big 1.0 2.0
    update
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535
1536
1537
1538
1539
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331







-
+







    update
    list $tk_textRelayout $tk_textRedraw
} {2.0 {2.0 eof}}
test textDisp-9.13 {TkTextRedrawTag} {
    .t configure -wrap none
    .t delete 1.0 end
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i - This is Line [format %c [expr {64+$i}]]\n"
        .t insert end "Line $i - This is Line [format %c [expr 64+$i]]\n"
    }
    .t tag add hidden 2.8 2.17
    .t tag add hidden 6.8 7.17
    .t tag configure hidden -background red
    .t tag configure hidden -elide true
    update
    .t tag configure hidden -elide false
1636
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442







-
+







    set tk_textRedraw {}
    .t yview -pickplace 28.0
    update
    list [.t index @0,0] $tk_textRedraw
} {28.0 {28.0 29.0}}
test textDisp-11.7 {TkTextSetYView} {
    .t yview 30.0
    update
    update ; update
    set tk_textRedraw {}
    .t yview -pickplace 26.0
    update
    list [.t index @0,0] $tk_textRedraw
} {21.0 {21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0}}
test textDisp-11.8 {TkTextSetYView} {
    .t yview 30.0
1696
1697
1698
1699
1700
1701
1702
1703

1704
1705
1706
1707
1708
1709
1710
1488
1489
1490
1491
1492
1493
1494

1495
1496
1497
1498
1499
1500
1501
1502







-
+







    pack .top.t
    .top.t insert end "Line 1"
    for {set i 2} {$i <= 100} {incr i} {
	.top.t insert end "\nLine $i"
    }
    update
    scan [wm geometry .top] "%dx%d" w2 h2
    wm geometry .top ${w2}x[expr {$h2-2}]
    wm geometry .top ${w2}x[expr $h2-2]
    update
    .top.t yview 1.0
    update
    set tk_textRedraw {}
    .top.t see 5.0
    update
    # Note, with smooth scrolling, the results of this test
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
1604
1605
1606
1607
1608
1609
1610















1611
1612
1613
1614
1615
1616
1617







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    }
    set lineheight [font metrics [.top.t cget -font] -linespace]
    wm geometry .top 200x[expr {$lineheight / 2}]
    update
    .top.t see 1.0
    .top.t index @0,[expr {$lineheight - 2}]
} {1.0}
test textDisp-11.22 {TkTextSetYView, peer has -startline} {
    .top.t delete 1.0 end
    for {set i 1} {$i <= 50} {incr i} {
        .top.t insert end "Line $i\n"
    }
    pack [.top.t peer create .top.p] -side left
    pack [scrollbar .top.sb -command {.top.p yview}] -side left -fill y
    .top.p configure -startline 5 -endline 35 -yscrollcommand {.top.sb set}
    update
    .top.p yview moveto 0
    update
    set res [.top.p get @0,0 "@0,0 lineend"]
    destroy .top.p
    set res
} {Line 5}

.t configure -wrap word
.t delete 50.0 51.0
.t insert 50.0 "This is a long line, one that will wrap around twice.\n"
test textDisp-12.1 {MeasureUp} {
    .t yview 100.0
    update
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
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







-
+















-
+
-
-
-
-
+













-
+
-
-
-
-
-
-
-
-
-
-
+
+













-
+
-
-
-
-
-
-
-
-
-
+


















+













-
+







    .t yview moveto 0
    update
    .t see 30.50
    set x [.t index @0,0]
    .t configure -wrap none
    set x
} {27.0}
test textDisp-13.7 {TkTextSeeCmd procedure} {
test textDisp-13.7 {TkTextSeeCmd procedure} {textfonts} {
    .t xview moveto 0
    .t yview moveto 0
    .t tag add sel 30.20
    .t tag add sel 30.40
    update
    .t see 30.50
    .t yview 25.0
    .t see 30.50
    set x [list [.t bbox 30.50]]
    .t see 30.39
    lappend x [.t bbox 30.39]
    .t see 30.38
    lappend x [.t bbox 30.38]
    .t see 30.20
    lappend x [.t bbox 30.20]
} [list [list [xchar 10] [yline 6] $fixedWidth $fixedHeight] \
} [list [list 73 [expr {5*$fixedDiff + 68}] 7 $fixedHeight] [list 3 [expr {5*$fixedDiff + 68}] 7 $fixedHeight] [list 3 [expr {5*$fixedDiff + 68}] 7 $fixedHeight] [list 73 [expr {5*$fixedDiff + 68}] 7 $fixedHeight]]
	[list [xchar 0] [yline 6] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 6] $fixedWidth $fixedHeight] \
	[list [xchar 10] [yline 6] $fixedWidth $fixedHeight]]
test textDisp-13.8 {TkTextSeeCmd procedure} {
test textDisp-13.8 {TkTextSeeCmd procedure} {textfonts} {
    .t xview moveto 0
    .t yview moveto 0
    .t tag add sel 30.20
    .t tag add sel 30.50
    update
    .t see 30.50
    set x [list [.t bbox 30.50]]
    .t see 30.60
    lappend x [.t bbox 30.60]
    .t see 30.65
    lappend x [.t bbox 30.65]
    .t see 30.90
    lappend x [.t bbox 30.90]
    # contrary to textDisp-13.7 above there is no yview command in this test
} [list [list 73 [expr {9*$fixedDiff/2 + 64}] 7 $fixedHeight] [list 136 [expr {9*$fixedDiff/2 + 64}] 7 $fixedHeight] [list 136 [expr {9*$fixedDiff/2 + 64}] 7 $fixedHeight] [list 73 [expr {9*$fixedDiff/2 + 64}] 7 $fixedHeight]]
    # therefore take into account that the top line is partially hidden
    set y [expr {[yline 6] + [lindex [.t bbox @0,0] 1] - [bo]}]
    set expected [list [list [xchar 10] $y $fixedWidth $fixedHeight] \
                       [list [xchar 19] $y $fixedWidth $fixedHeight] \
                       [list [xchar 19] $y $fixedWidth $fixedHeight] \
                       [list [xchar 10] $y $fixedWidth $fixedHeight]]
    lequal $x $expected
} {1}
test textDisp-13.9 {TkTextSeeCmd procedure} {
    wm geom . [expr {$width-2}]x$height
test textDisp-13.9 {TkTextSeeCmd procedure} {textfonts} {
    wm geom . [expr $width-2]x$height
    .t xview moveto 0
    .t yview moveto 0
    .t tag add sel 30.20
    .t tag add sel 30.50
    update
    .t see 30.50
    set x [list [.t bbox 30.50]]
    .t see 30.60
    lappend x [.t bbox 30.60]
    .t see 30.65
    lappend x [.t bbox 30.65]
    .t see 30.90
    lappend x [.t bbox 30.90]
    # contrary to textDisp-13.7 above there is no yview command in this test
} [list [list 74 [expr {9*$fixedDiff/2 + 66}] 7 $fixedHeight] [list 138 [expr {9*$fixedDiff/2 + 66}] 7 $fixedHeight] [list 138 [expr {9*$fixedDiff/2 + 66}] 7 $fixedHeight] [list 74 [expr {9*$fixedDiff/2 + 66}] 7 $fixedHeight]]
    # therefore take into account that the top line is partially hidden
    set y [expr {[yline 6] + [lindex [.t bbox @0,0] 1] - [bo]}]
    set expected [list [list [expr {[bo]+round([winfo width .t]-2*[bo])/2}] $y $fixedWidth $fixedHeight] \
                       [list [xcharr 1] $y $fixedWidth $fixedHeight] \
                       [list [xcharr 1] $y $fixedWidth $fixedHeight] \
                       [list [expr {[bo]+round([winfo width .t]-2*[bo])/2}] $y $fixedWidth $fixedHeight]]
    lequal $x $expected
} {1}
test textDisp-13.10 {TkTextSeeCmd procedure} {
test textDisp-13.10 {TkTextSeeCmd procedure} {} {
    # SF Bug 641778
    set w .tsee
    destroy $w
    text $w -font {Helvetica 8 normal} -bd 16
    $w insert end Hello
    $w see end
    set res [$w bbox end]
    destroy $w
    set res
} {}
test textDisp-13.11 {TkTextSeeCmd procedure} {} {
    # insertion of a character at end of a line containing multi-byte
    # characters and calling see at the line end shall actually show
    # this character
    toplevel .top2
    pack [text .top2.t2 -wrap none]
    for {set i 1} {$i < 5} {incr i} {
        .top2.t2 insert end [string repeat "Line $i: éèàçù" 5]\n

    }
    wm geometry .top2 300x200+0+0
    update
    .top2.t2 see "1.0 lineend"
    update
    set ref [.top2.t2 index @0,0]
    .top2.t2 insert "1.0 lineend" ç
    .top2.t2 see "1.0 lineend"
    update
    set new [.top2.t2 index @0,0]
    set res [.top2.t2 compare $ref == $new]
    destroy .top2
    set res
} 0
} {0}
wm geom . {}

.t configure -wrap none
test textDisp-14.1 {TkTextXviewCmd procedure} {
    .t delete 1.0 end
    update
    .t insert end xxxxxxxxx\n
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
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







-
+



-
+



-
+



-
+



-
+



-
+


-
+


-
+


-
+







} {1 {wrong # args: should be ".t xview moveto fraction"}}
test textDisp-14.6 {TkTextXviewCmd procedure} {
    list [catch {.t xview moveto a} msg] $msg
} {1 {expected floating-point number but got "a"}}
test textDisp-14.7 {TkTextXviewCmd procedure} {
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n" ; # 56 chars on this line
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n"
    .t insert end "xxxx xxxxxxxxx xxxxxxxxxxxxx"
    .t xview moveto .3
    .t xview
} [list [expr {round(0.3*(56*$fixedWidth))/(56.0*$fixedWidth)}] [expr {round(0.3*(56*$fixedWidth)+20*$fixedWidth)/(56.0*$fixedWidth)}]]
} [list [expr {118.0/392}] [expr {258.0/392}]]
test textDisp-14.8 {TkTextXviewCmd procedure} {
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n" ; # 56 chars on this line
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n"
    .t insert end "xxxx xxxxxxxxx xxxxxxxxxxxxx"
    .t xview moveto -.4
    .t xview
} [list 0.0 [expr {20.0/56}]]
} [list 0.0 [expr {5.0/14}]]
test textDisp-14.9 {TkTextXviewCmd procedure} {
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n" ; # 56 chars on this line
    .t insert end "xxxxx xxxxxxxxxxx xxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx\n"
    .t insert end "xxxx xxxxxxxxx xxxxxxxxxxxxx"
    .t xview m 1.4
    .t xview
} [list [expr {(56.0-20)/56}] 1.0]
} [list [expr {9.0/14}] 1.0]
test textDisp-14.10 {TkTextXviewCmd procedure} {
    list [catch {.t xview scroll a} msg] $msg
} {1 {wrong # args: should be ".t xview scroll number pages|pixels|units"}}
} {1 {wrong # args: should be ".t xview scroll number units|pages|pixels"}}
test textDisp-14.11 {TkTextXviewCmd procedure} {
    list [catch {.t xview scroll a b c} msg] $msg
} {1 {wrong # args: should be ".t xview scroll number pages|pixels|units"}}
} {1 {wrong # args: should be ".t xview scroll number units|pages|pixels"}}
test textDisp-14.12 {TkTextXviewCmd procedure} {
    list [catch {.t xview scroll gorp units} msg] $msg
} {1 {expected floating-point number but got "gorp"}}
} {1 {expected integer but got "gorp"}}
test textDisp-14.13 {TkTextXviewCmd procedure} {
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end "a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9\n"
    .t insert end "xxxx xxxxxxxxx xxxxxxxxxxxxx"
    .t xview moveto 0
    .t xview scroll 2 pa
2111
2112
2113
2114
2115
2116
2117
2118

2119
2120
2121
2122
2123
2124
2125
1870
1871
1872
1873
1874
1875
1876

1877
1878
1879
1880
1881
1882
1883
1884







-
+







    .t xview scroll 100 units
    lappend x [.t index @0,22]
    .t xview scroll -15 units
    lappend x [.t index @0,22]
} {2.21 2.20 2.99 2.84}
test textDisp-14.15 {TkTextXviewCmd procedure} {
    list [catch {.t xview scroll 14 globs} msg] $msg
} {1 {bad argument "globs": must be pages, pixels, or units}}
} {1 {bad argument "globs": must be units, pages, or pixels}}
test textDisp-14.16 {TkTextXviewCmd procedure} {
    list [catch {.t xview flounder} msg] $msg
} {1 {bad option "flounder": must be moveto or scroll}}

.t configure -wrap char
.t delete 1.0 end
for {set i 1} {$i < 99} {incr i} {
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
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







-
+








-
+









-
+
-
-
+
-
-
-
-
-
-




-
+







    .tf.f.t tag configure Header -font {Helvetica 14 bold italic} \
      -wrap word -spacing1 12 -spacing3 4

    .tf.f.t insert end "Foo" Header
    for {set i 1} {$i < $textheight} {incr i} {
	.tf.f.t insert end "\nLine $i"
    }
    update
    update ; after 1000 ; update
    set refind [.tf.f.t index @0,[winfo height .tf.f.t]]
    # Should scroll and should not crash!
    .tf.f.t yview scroll 1 unit
    # Check that it has scrolled
    set newind [.tf.f.t index @0,[winfo height .tf.f.t]]
    set res [.tf.f.t compare $newind > $refind]
    destroy .tf
    set res
} 1
} {1}

.t configure -wrap char
.t delete 1.0 end
.t insert insert "Line 1"
for {set i 2} {$i <= 200} {incr i} {
    .t insert end "\nLine $i"
}
.t tag add big 100.0 105.0
.t insert 151.end { has a lot of extra text, so that it wraps around on the screen several times over.}
.t insert 153.end { also has largely enough extra text to wrap.}
.t insert 153.end { also has enoug extra text to wrap.}
update
set totpix [.t count -update -ypixels 1.0 end]
update ; .t count -update -ypixels 1.0 end
# check that the wrapping lines wrap exactly 6 times in total (4 times for line 151, and twice for line 153),
# this is an assumption of the upcoming tests
if {[expr {double(($totpix-5*$heightDiff)/$fixedHeight)}] != 206.0} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual [.t cget -font]]\",\
is too different from the requested \"[.t cget -font]\". Some of the upcoming tests will probably fail."
}
test textDisp-16.1 {TkTextYviewCmd procedure} {
    .t yview 21.0
    set x [.t yview]
    .t yview 1.0
    list [expr {int([lindex $x 0]*100)}] [expr {int([lindex $x 1]*100)}]
    list [expr {int([lindex $x 0]*100)}] [expr {int ([lindex $x 1] * 100)}]
} {9 14}
test textDisp-16.2 {TkTextYviewCmd procedure} {
    list [catch {.t yview 2 3} msg] $msg
} {1 {bad option "2": must be moveto or scroll}}
test textDisp-16.3 {TkTextYviewCmd procedure} {
    list [catch {.t yview -pickplace} msg] $msg
} {1 {wrong # args: should be ".t yview -pickplace lineNum|index"}}
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
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







-
+
-












-

-
-
-
-
-
-
-
-
-
-
+
+

-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-



-
+















-
+


-
+

-
-
+
+

-
-
+
+








-
+












-
+
-
-
-
-
-









-
-
-
+












-
+


-
-
-
-
-

-
-
+
+
+
+
+
+







} {1 {bad text index "bad_mark_name"}}
test textDisp-16.9 {TkTextYviewCmd procedure, "moveto" option} {
    list [catch {.t yview moveto a b} msg] $msg
} {1 {wrong # args: should be ".t yview moveto fraction"}}
test textDisp-16.10 {TkTextYviewCmd procedure, "moveto" option} {
    list [catch {.t yview moveto gorp} msg] $msg
} {1 {expected floating-point number but got "gorp"}}
test textDisp-16.11 {TkTextYviewCmd procedure, "moveto" option} haveBigFontTwiceLargerThanTextFont {
test textDisp-16.11 {TkTextYviewCmd procedure, "moveto" option} {
# constrained because text tagged with the big font plays a role
    .t yview moveto 0.5
    .t index @0,0
} {103.0}
test textDisp-16.12 {TkTextYviewCmd procedure, "moveto" option} {
    .t yview moveto -1
    .t index @0,0
} {1.0}
test textDisp-16.13 {TkTextYviewCmd procedure, "moveto" option} {
    .t yview moveto 1.1
    .t index @0,0
} {191.0}
test textDisp-16.14 {TkTextYviewCmd procedure, "moveto" option} {
    # y move to 3/4 of text widget content height
    .t yview moveto .75
    # target y position is inside line 151, which wraps 4 times
    # exactly which display line depends on actual font size
    set ytargetline [expr {150*$fixedHeight+5*$heightDiff}]
    set expected 151.0
    while {[expr {$ytargetline+$fixedHeight}] <= [expr {round(0.75*$totpix)}]} {
        incr ytargetline $fixedHeight
	set expected [.t index "$expected + 1 display line"]
    }
    lequal [.t index @0,0] $expected
} {1}
    .t index @0,0
} {151.60}
test textDisp-16.15 {TkTextYviewCmd procedure, "moveto" option} {
    # y move to 3/4 of text widget content height plus just one line height minus one pixel
    .t yview moveto .75
    .t yview moveto .752
    set pixtonextline [expr {-[bo] + [lindex [.t bbox @0,0] 1] + [lindex [.t bbox @0,0] 3]}]
    .t yview moveto [expr {0.75 + ($pixtonextline-1)/double($totpix)}]
    # target y position is inside line 151, which wraps 4 times
    # exactly which display line depends on actual font size
    set ytargetline [expr {150*$fixedHeight+5*$heightDiff}]
    set expected 151.0
    while {[expr {$ytargetline+$fixedHeight}] <= [expr {round(0.75*$totpix + ($pixtonextline-1))}]} {
        incr ytargetline $fixedHeight
	set expected [.t index "$expected + 1 display line"]
    }
    lequal [.t index @0,0] $expected
} {1}
test textDisp-16.16 {TkTextYviewCmd procedure, "moveto" option} {
    .t index @0,0
} {151.60}
test textDisp-16.16 {TkTextYviewCmd procedure, "moveto" option} {textfonts} {
    # y move to 3/4 of text widget content height plus exactly one line height
    .t yview moveto .75
    set count [expr {5 * $bigHeight + 150 * $fixedHeight}]
    set extra [expr {0.04 * double($fixedDiff * 150) / double($count)}]
    .t yview moveto [expr {.753 - $extra}]
    set pixtonextline [expr {-[bo] + [lindex [.t bbox @0,0] 1] + [lindex [.t bbox @0,0] 3]}]
    .t yview moveto [expr {0.75 + $pixtonextline/double($totpix)}]
    # target y position is inside line 151, which wraps 4 times
    # exactly which display line depends on actual font size
    set ytargetline [expr {150*$fixedHeight+5*$heightDiff}]
    set expected 151.0
    while {[expr {$ytargetline+$fixedHeight}] <= [expr {round(0.75*$totpix + $pixtonextline)}]} {
        incr ytargetline $fixedHeight
	set expected [.t index "$expected + 1 display line"]
    }
    lequal [.t index @0,0] $expected
} {1}
test textDisp-16.17 {TkTextYviewCmd procedure, "moveto" option} haveBigFontTwiceLargerThanTextFont {
    .t index @0,0
} {151.60}
test textDisp-16.17 {TkTextYviewCmd procedure, "moveto" option} {
# constrained because text tagged with the big font plays a role
    .t yview moveto .755
    .t index @0,0
} {151.80}
test textDisp-16.18 {TkTextYviewCmd procedure, "moveto" roundoff} {
test textDisp-16.18 {TkTextYviewCmd procedure, "moveto" roundoff} {textfonts} {
    catch {destroy .top1}
    toplevel .top1
    wm geometry .top1 +0+0
    text .top1.t -height 3 -width 4 -wrap none -setgrid 1 -padx 6 \
	-spacing3 6
    pack .top1.t
    update
    .top1.t insert end "1\n2\n3\n4\n5\n6"
    .top1.t yview moveto 0.3333
    set result [.top1.t yview]
    destroy .top1
    set result
} [list [expr {1.0/3}] [expr {5.0/6}]]
test textDisp-16.19 {TkTextYviewCmd procedure, "scroll" option} {
    list [catch {.t yview scroll a} msg] $msg
} {1 {wrong # args: should be ".t yview scroll number pages|pixels|units"}}
} {1 {wrong # args: should be ".t yview scroll number units|pages|pixels"}}
test textDisp-16.20 {TkTextYviewCmd procedure, "scroll" option} {
    list [catch {.t yview scroll a b c} msg] $msg
} {1 {wrong # args: should be ".t yview scroll number pages|pixels|units"}}
} {1 {wrong # args: should be ".t yview scroll number units|pages|pixels"}}
test textDisp-16.21 {TkTextYviewCmd procedure, "scroll" option} {
    list [catch {.t yview scroll bogus bogus} msg] $msg
} {1 {bad argument "bogus": must be pages, pixels, or units}}
    list [catch {.t yview scroll badInt bogus} msg] $msg
} {1 {bad argument "bogus": must be units, pages, or pixels}}
test textDisp-16.21.2 {TkTextYviewCmd procedure, "scroll" option} {
    list [catch {.t yview scroll bogus units} msg] $msg
} {1 {expected floating-point number but got "bogus"}}
    list [catch {.t yview scroll badInt units} msg] $msg
} {1 {expected integer but got "badInt"}}
test textDisp-16.22 {TkTextYviewCmd procedure, "scroll" option, back pages} {
    .t yview 50.0
    update
    .t yview scroll -1 pages
    .t index @0,0
} {42.0}
test textDisp-16.22.1 {TkTextYviewCmd procedure, "scroll" option, back pages} {
    list [catch {.t yview scroll -3 p} res] $res
} {1 {ambiguous argument "p": must be pages, pixels, or units}}
} {1 {ambiguous argument "p": must be units, pages, or pixels}}
test textDisp-16.23 {TkTextYviewCmd procedure, "scroll" option, back pages} {
    .t yview 50.0
    update
    .t yview scroll -3 pa
    .t index @0,0
} {26.0}
test textDisp-16.24 {TkTextYviewCmd procedure, "scroll" option, back pages} {
    .t yview 5.0
    update
    .t yview scroll -3 pa
    .t index @0,0
} {1.0}
test textDisp-16.25 {TkTextYviewCmd procedure, "scroll" option, back pages} -setup {
test textDisp-16.25 {TkTextYviewCmd procedure, "scroll" option, back pages} {
    # this frame is needed because some window managers don't allow the overall
    # height of a window to get very narrow, triggering false test failure
    frame .f2 -height 20
    pack .f2 -side top
} -body {
    .t configure -height 1
    update
    .t yview 50.0
    update
    .t yview scroll -1 pages
    set x [.t index @0,0]
    .t configure -height 10
    update
    set x
} -cleanup {
    destroy .f2
} -result {49.0}
} {49.0}
test textDisp-16.26 {TkTextYviewCmd procedure, "scroll" option, forward pages} {
    .t yview 50.0
    update
    .t yview scroll 1 pages
    .t index @0,0
} {58.0}
test textDisp-16.27 {TkTextYviewCmd procedure, "scroll" option, forward pages} {
    .t yview 50.0
    update
    .t yview scroll 2 pages
    .t index @0,0
} {66.0}
test textDisp-16.28 {TkTextYviewCmd procedure, "scroll" option, forward pages} {
test textDisp-16.28 {TkTextYviewCmd procedure, "scroll" option, forward pages} {textfonts} {
    .t yview 98.0
    update
    # The man page does not say it but the code does: scrolling 1 page actually uses the
    # window height minus two lines, so that there's some overlap between adjacent pages.
    # Note: it's a bit tricky but we only need to subtract one [bo] from [winfo height .t] here
    # because the origin of @x,y coordinates is at borderwidth start, not at text area start.
    set expected [.t index @0,[expr {[winfo height .t]-[bo]-2*$fixedHeight}]]
    .t yview scroll 1 page
    lequal [.t index @0,0] $expected
} {1}
    set res [expr int([.t index @0,0])]
    if {$fixedDiff > 1} {
	incr res -1
    }
    set res
} {102}
test textDisp-16.29 {TkTextYviewCmd procedure, "scroll" option, forward pages} {
    .t configure -height 1
    update
    .t yview 50.0
    update
    .t yview scroll 1 pages
    set x [.t index @0,0]
2428
2429
2430
2431
2432
2433
2434
2435

2436
2437
2438
2439
2440
2441
2442
2141
2142
2143
2144
2145
2146
2147

2148
2149
2150
2151
2152
2153
2154
2155







-
+







    .t yview 149.0
    update
    .t yview scroll 4 units
    .t index @0,0
} {151.40}
test textDisp-16.32 {TkTextYviewCmd procedure} {
    list [catch {.t yview scroll 12 bogoids} msg] $msg
} {1 {bad argument "bogoids": must be pages, pixels, or units}}
} {1 {bad argument "bogoids": must be units, pages, or pixels}}
test textDisp-16.33 {TkTextYviewCmd procedure} {
    list [catch {.t yview bad_arg 1 2} msg] $msg
} {1 {bad option "bad_arg": must be moveto or scroll}}
test textDisp-16.34 {TkTextYviewCmd procedure} {
    set res {}
    .t yview 1.0
    lappend res [format %.12g [expr {[lindex [.t yview] 0]
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
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







-
+












-
+







    lappend res [expr {[lindex [.t yview] 0] * [.t count -ypixels 1.0 end]}]
} {0.0 0.0}
test textDisp-16.37 {TkTextYviewCmd procedure} {
    list [catch {.t yview scroll 1.3 pixels} msg] $msg
} {0 {}}
test textDisp-16.38 {TkTextYviewCmd procedure} {
    list [catch {.t yview scroll 1.3blah pixels} msg] $msg
} {1 {expected screen distance but got "1.3blah"}}
} {1 {bad screen distance "1.3blah"}}
test textDisp-16.39 {TkTextYviewCmd procedure} {
    list [catch {.t yview scroll 1.3i pixels} msg] $msg
} {0 {}}
test textDisp-16.40 {text count -xpixels} {
    set res {}
    lappend res [.t count -xpixels 1.0 1.5] \
      [.t count -xpixels 1.5 1.0] \
      [.t count -xpixels 1.0 13.0] \
      [.t count -xpixels 1.0 "1.0 displaylineend"] \
      [.t count -xpixels 1.0 "1.0 lineend"] \
      [.t count -xpixels 1.0 "1.0 displaylineend"] \
      [.t count -xpixels 1.0 end]
} [list [expr {5*$fixedWidth}] [expr {-5*$fixedWidth}] 0 [expr {6*$fixedWidth}] [expr {6*$fixedWidth}] [expr {6*$fixedWidth}] 0]
} {35 -35 0 42 42 42 0}
test textDisp-16.41 {text count -xpixels with indices in elided lines} {
    set res {}
    .t delete 1.0 end
    for {set i 1} {$i < 40} {incr i} {
        .t insert end [string repeat "Line $i" 20]
        .t insert end "\n"
    }
2553
2554
2555
2556
2557
2558
2559
2560

2561
2562
2563
2564
2565
2566
2567
2266
2267
2268
2269
2270
2271
2272

2273
2274
2275
2276
2277
2278
2279
2280







-
+







    .t delete 1.0 end
    foreach x [list 0 1 2 3 4 5 6 7 8 9 0] {
      .t insert end "$x aaa1\n$x bbb2\n$x ccc3\n$x ddd4\n$x eee5\n$x fff6"
      .t insert end "$x 1111\n$x 2222\n$x 3333\n$x 4444\n$x 5555\n$x 6666" hidden
    }
    .t tag configure hidden -elide true ; # 5 hidden lines
    update
    .t see [expr {5 + [winfo height .t] / $fixedHeight + 1}].0
    .t see [expr {5 + [winfo height .t] / $fixedHeight} + 1].0
    update
    .t index @0,0
} {2.0}

.t delete 1.0 end
foreach i {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
    .t insert end "\nLine $i 11111 $i 22222 $i 33333 $i 44444 $i 55555"
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
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







-
-
+
+


-
-


-
-
-
-
+
+
+
-
-
+

-
-
-

-


-
+

-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
+


+
-
-
-

-

-
-
-
-
+
+
+


-
-

-
-


-
-
-

-
-
-
+
+

-
+

-
-
-


-

-
-
+
-
-
-
+
+

-







    list [catch {.t scan stupid b 20} msg] $msg
} {1 {expected integer but got "b"}}
test textDisp-17.4 {TkTextScanCmd procedure} {
    list [catch {.t scan stupid -2 bogus} msg] $msg
} {1 {expected integer but got "bogus"}}
test textDisp-17.5 {TkTextScanCmd procedure} {
    list [catch {.t scan stupid 123 456} msg] $msg
} {1 {bad scan option "stupid": must be dragto or mark}}
test textDisp-17.6 {TkTextScanCmd procedure} {
} {1 {bad scan option "stupid": must be mark or dragto}}
test textDisp-17.6 {TkTextScanCmd procedure} {textfonts} {
    .t yview 1.0
    .t xview moveto 0
    update
    set expected [.t index @[expr {[bo]+50}],[expr {[bo]+50}]]
    .t scan mark 40 60
    .t scan dragto 35 55
    update
    lequal [.t index @0,0] $expected
} {1}
test textDisp-17.7 {TkTextScanCmd procedure} {
    .t index @0,0
} {4.7}
test textDisp-17.7 {TkTextScanCmd procedure} {textfonts} {
    # 1st result
    .t yview 1.0
    .t yview 10.0
    .t xview moveto 0
    update
    set expected [.t index @[expr {[bo]+20*$fixedWidth-50}],[expr {[bo]+9*$fixedHeight-50}]]
    .t yview 10.0
    .t xview scroll 20 units
    update
    .t scan mark -10 60
    .t scan dragto -5 65
    update
    .t index @0,0
    set x [.t index @0,0]
    # 2nd result
    .t yview 1.0
    .t xview moveto 0
    update
    lappend expected [.t index @[expr {[bo]+20*$fixedWidth-50-50}],[expr {[bo]+9*$fixedHeight-50-70}]]
    .t yview 10.0
    .t xview scroll 20 units
    update
    .t scan mark -10 60
    .t scan dragto -5 65
    update
    .t scan dragto 0 72
    .t scan dragto 0 [expr {70 + $fixedDiff}]
    update
    lequal [list $x [.t index @0,0]] $expected
} {1}
test textDisp-17.8 {TkTextScanCmd procedure} {
    list $x [.t index @0,0]
} {6.12 2.5}
test textDisp-17.8 {TkTextScanCmd procedure} {textfonts} {
    .t yview 1.0
    .t xview moveto 0
    .t scan mark 0 60
    update
    set expected [.t index @[expr {[bo]+50}],[expr {[bo]+50}]]
    .t scan mark 0 60
    .t scan dragto 30 100
    update
    .t scan dragto 25 95
    update
    lequal [.t index @0,0] $expected
} {1}
test textDisp-17.9 {TkTextScanCmd procedure} {
    .t index @0,0
} {4.7}
test textDisp-17.9 {TkTextScanCmd procedure} {textfonts} {
    .t yview end
    .t xview moveto 0
    update
    # this brings us at lower right corner of the text
    .t xview scroll 100 units
    update
    # this does not trigger any scroll, we're already at the corner
    .t scan mark 90 60
    .t scan dragto 10 0
    update
    set expected [.t index @[expr {[winfo width .t]-[bo]-40}],[expr {[winfo height .t]-[bo]-50}]]
    set expected [.t index "$expected - [.t cget -height] lines - [.t cget -width] chars"]
    .t scan dragto 14 5
    update
    lequal [.t index @0,0] $expected
} {1}
    .t index @0,0
} {18.44}
.t configure -wrap word
test textDisp-17.10 {TkTextScanCmd procedure, word wrapping} {
test textDisp-17.10 {TkTextScanCmd procedure, word wrapping} {textfonts} {
    .t yview 10.0
    update
    set origin [.t index @0,0]
    set expected [.t index "$origin - [expr {int(ceil(50.0/$fixedHeight))}] display lines"]
    .t scan mark -10 60
    .t scan dragto -5 65
    update
    set x [.t index @0,0]
    lappend expected [.t index "$origin - [expr {int(ceil((50.0+70.0)/$fixedHeight))}] display lines"]
    .t scan dragto 0 72
    .t scan dragto 0 [expr {70 + $fixedDiff}]
    update
    lequal [list $x [.t index @0,0]] $expected
} {1}
    list $x [.t index @0,0]
} {9.0 8.0}
.t configure -xscrollcommand scroll -yscrollcommand {}

test textDisp-18.1 {GetXView procedure} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end xxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n
    .t insert end xxxxxxxxxxxxxxxxxxxxxxxxxx
    update
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
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







+




















-
+







"error "scrolling error""
    (procedure "scrollError" line 2)
    invoked from within
"scrollError 0.0 1.0"
    (horizontal scrolling command executed by text)}}
catch {rename bgerror {}}
catch {rename bogus {}}
.t configure -xscrollcommand {} -yscrollcommand scroll

.t configure -xscrollcommand {} -yscrollcommand scroll
test textDisp-19.1 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    set scrollInfo
} {0.0 1.0}
test textDisp-19.2 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    set scrollInfo "unchanged"
    .t insert 1.0 "Line1\nLine2"
    update
    set scrollInfo
} {unchanged}
test textDisp-19.3 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    update
    update; after 10 ; update
    set scrollInfo "unchanged"
    .t insert 1.0 "Line 1\nLine 2 is so long that it wraps around\nLine 3"
    update
    set scrollInfo
} {unchanged}
test textDisp-19.4 {GetYView procedure} {
    .t configure -wrap char
2808
2809
2810
2811
2812
2813
2814
2815

2816
2817
2818
2819
2820
2821
2822
2483
2484
2485
2486
2487
2488
2489

2490
2491
2492
2493
2494
2495
2496
2497







-
+







    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
	.t insert end "\nLine $i"
    }
    .t insert 2.end " is really quite long; in fact it's so long that it wraps three times"
    update
    update ; after 100
    set x $scrollInfo
} {0.0 0.625}
test textDisp-19.6 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
2832
2833
2834
2835
2836
2837
2838
2839

2840
2841
2842
2843
2844
2845
2846
2507
2508
2509
2510
2511
2512
2513

2514
2515
2516
2517
2518
2519
2520
2521







-
+







    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
	.t insert end "\nLine $i"
    }
    .t insert 2.end " is really quite long; in fact it's so long that it wraps three times"
    .t yview 2.26
    update
    update; after 1; update
    set x $scrollInfo
} {0.125 0.75}
test textDisp-19.8 {GetYView procedure} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13} {
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
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







-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





-
+




-
+




-
+




-
+




-
+




















-
+







    .t yview insert
    update
    .t count -update -ypixels 1.0 end
    set scrollInfo
} {0.5 1.0}
test textDisp-19.11.2 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 1.0 end
} 20
} {20}
test textDisp-19.11.3 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines end 1.0
} -20
} {-20}
test textDisp-19.11.4 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 1.1 1.3
} 0
} {0}
test textDisp-19.11.5 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 16.1
} 0
} {0}
test textDisp-19.11.5.1 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 16.5
} 0
} {0}
test textDisp-19.11.6 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 16.24
} 1
} {1}
test textDisp-19.11.7 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 16.40
} 2
} {2}
test textDisp-19.11.8 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines "16.0 displaylineend +1c" "16.0 lineend"
} 3
} {3}
test textDisp-19.11.9 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 "16.0 lineend"
} 4
} {4}
test textDisp-19.11.10 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 "16.0 +4displaylines"
} 4
} {4}
test textDisp-19.11.11 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines 16.0 "16.0 +2displaylines"
} 2
} {2}
test textDisp-19.11.12 {TextWidgetCmd procedure, "count -displaylines"} {
    .t count -displaylines "16.0 +1displayline" "16.0 +2displaylines -1c"
} 0
} {0}
.t tag configure elide -elide 1
test textDisp-19.11.13 {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "16.0 +1displaylines" "16.0 +1displaylines +6c"
    .t count -displaylines 16.0 "16.0 +4displaylines"
} 4
} {4}
test textDisp-19.11.14 {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "16.0 +1displaylines" "16.0 +1displaylines displaylineend"
    .t count -displaylines 16.0 "16.0 +4displaylines"
} 4
} {4}
test textDisp-19.11.15 {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "16.0 +1displaylines" "16.0 +2displaylines"
    .t count -displaylines 16.0 "16.0 +4displaylines -1c"
} 3
} {3}
test textDisp-19.11.15a {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "16.0 +1displaylines" "16.0 +2displaylines"
    .t count -displaylines 16.0 "16.0 +4displaylines"
} 4
} {4}
test textDisp-19.11.16 {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "12.0" "14.0"
    .t count -displaylines 12.0 16.0
} 2
} {2}
test textDisp-19.11.17 {TextWidgetCmd procedure, "index +displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "12.0" "14.0"
    list [.t index "11.5 +2d lines"] \
      [.t index "12.0 +2d lines"] [.t index "11.0 +2d lines"] \
      [.t index "13.0 +2d lines"] [.t index "13.1 +3d lines"] \
      [.t index "13.0 +4d lines"]
} {15.5 16.0 15.0 16.0 16.21 16.39}
test textDisp-19.11.18 {TextWidgetCmd procedure, "index +displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "12.0" "14.0"
    list [.t index "15.5 -2d lines"] \
      [.t index "16.0 -2d lines"] [.t index "15.0 -2d lines"] \
      [.t index "16.0 -3d lines"] [.t index "16.23 -4d lines"] \
      [.t index "16.42 -5d lines"]
} {11.5 14.0 11.0 11.0 11.2 11.3}
test textDisp-19.11.19 {TextWidgetCmd procedure, "count -displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "12.0" "16.0 +1displaylines"
    .t count -displaylines 12.0 17.0
} 4
} {4}
test textDisp-19.11.20 {TextWidgetCmd procedure, "index +displaylines"} {
    .t tag remove elide 1.0 end
    .t tag add elide "12.0" "16.0 +1displaylines"
    list [.t index "11.5 +2d lines"] \
      [.t index "12.0 +2d lines"] [.t index "11.0 +2d lines"] \
      [.t index "13.0 +2d lines"] [.t index "13.0 +3d lines"] \
      [.t index "13.0 +4d lines"]
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
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







-
+

-
+



-
+







-
+

-
+














-
-
+
-
+







    catch {destroy .top}
    toplevel .top
    wm geometry .top +0+0
    text .top.t -width 40 -height 5 -font $fixedFont
    pack .top.t -expand yes -fill both
    .top.t insert end "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"
    # Need to wait for asychronous calculations to complete.
    update
    update ; after 10
    scan [wm geom .top] %dx%d twidth theight
    wm geom .top ${twidth}x[expr {$theight - 3}]
    wm geom .top ${twidth}x[expr $theight - 3]
    update
    .top.t yview
} [list 0.0 [expr {(5.0 * $fixedHeight - 3.0)/ (5.0 * $fixedHeight)}]]
test textDisp-19.13 {GetYView procedure, partially visible last line} {
test textDisp-19.13 {GetYView procedure, partially visible last line} {textfonts} {
    catch {destroy .top}
    toplevel .top
    wm geometry .top +0+0
    text .top.t -width 40 -height 5 -font $fixedFont
    pack .top.t -expand yes -fill both
    .top.t insert end "Line 1\nLine 2\nLine 3\nLine 4 has enough text to wrap around at least once"
    # Need to wait for asychronous calculations to complete.
    update
    update ; after 10
    scan [wm geom .top] %dx%d twidth theight
    wm geom .top ${twidth}x[expr {$theight - 3}]
    wm geom .top ${twidth}x[expr $theight - 3]
    update
    .top.t yview
} [list 0.0 [expr {(5.0 * $fixedHeight - 3.0)/ (5.0 * $fixedHeight)}]]
catch {destroy .top}
test textDisp-19.14 {GetYView procedure} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
    .t insert end "\nThis last line wraps around four "
    .t insert end "times with a little bit left on the last line."
    # Need to update so everything is calculated.
    update
    .t count -update -ypixels 1.0 end
    update ; .t count -update -ypixels 1.0 end
    delay
    update ; after 10 ; update
    set scrollInfo "unchanged"
    .t mark set insert 3.0
    .t tag configure x -background red
    .t tag add x 1.0 5.0
    update
    .t tag delete x
    set scrollInfo
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

3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188

3189
3190
3191

3192
3193
3194
3195
3196
3197
3198
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







-
-
+
-
-
+
+





-
+
-
-
-
-
+
-
-









-
+
-

-
+











-
+


-
+
-
-
-
-
-
-
-










-
+
-

-
+







    .t insert 1.0 "Line 1"
    foreach i {2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	.t insert end "\nLine $i"
    }
    .t insert end "\nThis last line wraps around four "
    .t insert end "times with a little bit left on the last line."
    # Need to update so everything is calculated.
    update
    .t count -update -ypixels 1.0 end
    update ; .t count -update -ypixels 1.0 end ; update
    update
    set res [list \
    set res {}
    lappend res \
      [.t count -ypixels 1.0 end] \
      [.t count -update -ypixels 1.0 end] \
      [.t count -ypixels 15.0 16.0] \
      [.t count -ypixels 15.0 "16.0 displaylineend +1c"] \
      [.t count -ypixels 16.0 "16.0 displaylineend +1c"] \
      [.t count -ypixels "16.0 +1 displaylines" "16.0 +4 displaylines +3c"] ]
      [.t count -ypixels "16.0 +1 displaylines" "16.0 +4 displaylines +3c"]
} [list [expr {20 * $fixedHeight}] \
        [expr {20 * $fixedHeight}] \
	$fixedHeight \
	[expr {2*$fixedHeight}] \
} [list [expr {260 + 20 * $fixedDiff}] [expr {260 + 20 * $fixedDiff}] $fixedHeight [expr {2*$fixedHeight}] $fixedHeight [expr {3*$fixedHeight}]]
	$fixedHeight \
	[expr {3*$fixedHeight}]]
test textDisp-19.17 {count -ypixels with indices in elided lines} {
    .t configure -wrap none
    .t delete 1.0 end
    for {set i 1} {$i < 100} {incr i} {
        .t insert end [string repeat "Line $i" 20]
        .t insert end "\n"
    }
    .t tag add hidden 5.15 20.15
    .t tag configure hidden -elide true
    update
    set res {}
    .t count -update -ypixels 1.0 end
    update
    set res [list \
    lappend res \
      [.t count -ypixels 1.0 6.0] \
      [.t count -ypixels 2.0 7.5] \
      [.t count -ypixels 5.0 8.5] \
      [.t count -ypixels 6.1 6.2] \
      [.t count -ypixels 6.1 18.8] \
      [.t count -ypixels 18.0 20.50] \
      [.t count -ypixels 5.2 20.60] \
      [.t count -ypixels 20.60 20.70] \
      [.t count -ypixels 5.0 25.0] \
      [.t count -ypixels 25.0 5.0] \
      [.t count -ypixels 25.4 27.50] \
      [.t count -ypixels 35.0 38.0] ]
      [.t count -ypixels 35.0 38.0]
    .t yview 35.0
    lappend res [.t count -ypixels 5.0 25.0]
} [list [expr {4 * $fixedHeight}] \
} [list [expr {4 * $fixedHeight}] [expr {3 * $fixedHeight}] 0 0 0 0 0 0 [expr {5 * $fixedHeight}] [expr {- 5 * $fixedHeight}] [expr {2 * $fixedHeight}] [expr {3 * $fixedHeight}] [expr {5 * $fixedHeight}]]
        [expr {3 * $fixedHeight}] \
	0 0 0 0 0 0 \
	[expr {5 * $fixedHeight}] \
	[expr {- 5 * $fixedHeight}] \
	[expr {2 * $fixedHeight}] \
	[expr {3 * $fixedHeight}] \
	[expr {5 * $fixedHeight}]]
test textDisp-19.18 {count -ypixels with indices in elided lines} {
    .t configure -wrap none
    .t delete 1.0 end
    for {set i 1} {$i < 100} {incr i} {
        .t insert end [string repeat "Line $i" 20]
        .t insert end "\n"
    }
    .t tag add hidden 5.15 20.15
    .t tag configure hidden -elide true
    .t yview 35.0
    update
    set res {}
    .t count -update -ypixels 1.0 end
    update
    set res [.t count -ypixels 5.0 25.0]
    lappend res [.t count -ypixels 5.0 25.0]
    .t yview scroll [expr {- 15 * $fixedHeight}] pixels
    update
    lappend res [.t count -ypixels 5.0 25.0]
} [list [expr {5 * $fixedHeight}] [expr {5 * $fixedHeight}]]
test textDisp-19.19 {count -ypixels with indices in elided lines} {
    .t configure -wrap char
    .t delete 1.0 end
3214
3215
3216
3217
3218
3219
3220
3221

3222
3223
3224
3225
3226
3227
3228
3229
3230

3231
3232

3233
3234
3235
3236
3237

3238
3239
3240
3241
3242
3243
3244

3245
3246
3247
3248
3249
3250
3251
3252

3253
3254
3255
3256
3257

3258
3259
3260
3261
3262



3263
3264

3265
3266
3267

3268
3269
3270

3271
3272

3273
3274
3275
3276
3277
3278
3279

3280
3281
3282
3283
3284
3285
3286
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







-
+



-
-
-
-
-
-
+
-
-
+




-
+
-
-




-
+
-
-





-
+
-
-


-
+

-
-
-
-
+
+
+

-
+

-
-
+
-
-
-
+

-
+





-
-
+







.t configure -wrap word
.t delete 50.0 51.0
.t insert 50.0 "This is a long line, one that will wrap around twice.\n"
test textDisp-20.1 {FindDLine} {
    .t yview 48.0
    list [.t dlineinfo 46.0] [.t dlineinfo 47.0] [.t dlineinfo 49.0] \
	    [.t dlineinfo 58.0]
} [list {} {} [list [bo] [yline 2] [xw 7] $fixedHeight $fixedAscent] {}]
} [list {} {} [list 3 [expr {$fixedDiff + 16}] 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}]
test textDisp-20.2 {FindDLine} {
    .t yview 100.0
    .t yview -pickplace 53.0
    set centlineY [lindex [.t bbox 53.0] 1]
    set expectedY [expr {$centlineY - int(($centlineY-[bo])/$fixedHeight)*$fixedHeight - $fixedHeight}]
    set expected [list [list [bo] $expectedY [xw 20] $fixedHeight $fixedAscent] \
                       [list [bo] $expectedY [xw 20] $fixedHeight $fixedAscent] \
	               [list [bo] [expr {$expectedY+$fixedHeight}] [xw 19] $fixedHeight $fixedAscent]]
    set res [list [.t dlineinfo 50.0] [.t dlineinfo 50.14] [.t dlineinfo 50.21]]
    list [.t dlineinfo 50.0] [.t dlineinfo 50.14] [.t dlineinfo 50.21]
    lequal $res $expected
} {1}
} [list [list 3 [expr {-1 - $fixedDiff/2}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {-1 - $fixedDiff/2}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {12 + $fixedDiff/2}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]]
test textDisp-20.3 {FindDLine} {
    .t yview 100.0
    .t yview 49.0
    list [.t dlineinfo 50.0] [.t dlineinfo 50.24] [.t dlineinfo 57.0]
} [list [list [bo] [yline 2] [xw 20] $fixedHeight $fixedAscent] \
} [list [list 3 [expr {$fixedDiff + 16}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {2*$fixedDiff + 29}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}]
        [list [bo] [yline 3] [xw 19] $fixedHeight $fixedAscent] \
	{}]
test textDisp-20.4 {FindDLine} {
    .t yview 100.0
    .t yview 42.0
    list [.t dlineinfo 50.0] [.t dlineinfo 50.24] [.t dlineinfo 50.40]
} [list [list [bo] [yline 9] [xw 20] $fixedHeight $fixedAscent] \
} [list [list 3 [expr {8*$fixedDiff + 107}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {9*$fixedDiff + 120}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}]
        [list [bo] [yline 10] [xw 19] $fixedHeight $fixedAscent] \
	{}]
.t config -wrap none
test textDisp-20.5 {FindDLine} {
    .t yview 100.0
    .t yview 48.0
    list [.t dlineinfo 50.0] [.t dlineinfo 50.20] [.t dlineinfo 50.40]
} [list [list [bo] [yline 3] [xw 53] $fixedHeight $fixedAscent] \
} [list [list 3 [expr {3+2*$fixedHeight}] 371 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {3+2*$fixedHeight}] 371 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {3+2*$fixedHeight}] 371 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]]
        [list [bo] [yline 3] [xw 53] $fixedHeight $fixedAscent] \
	[list [bo] [yline 3] [xw 53] $fixedHeight $fixedAscent]]

.t config -wrap word
test textDisp-21.1 {TkTextPixelIndex} {
test textDisp-21.1 {TkTextPixelIndex} {textfonts} {
    .t yview 48.0
    set off [expr {[bo]+3}]
    list [.t index @-10,-10] [.t index @$off,$off] [.t index @[expr {[xchar 2]+2}],$off] \
	    [.t index @[expr {[xchar 14]+1}],$off] [.t index @[xchar 5],[yline 5]]
} {48.0 48.0 48.2 48.7 50.45}
    list [.t index @-10,-10] [.t index @6,6] [.t index @22,6] \
	    [.t index @102,6] [.t index @38,[expr {$fixedHeight * 4 + 3}]] [.t index @44,67]
} {48.0 48.0 48.2 48.7 50.45 50.45}
.t insert end \n
test textDisp-21.2 {TkTextPixelIndex} {
test textDisp-21.2 {TkTextPixelIndex} {textfonts} {
    .t yview 195.0
    set off [expr {[xchar 1]+1}]
    list [.t index @$off,[expr {[yline 6]+2}]] \
    list [.t index @11,[expr {$fixedHeight * 5 + 5}]] [.t index @11,[expr {$fixedHeight * 6 + 5}]] [.t index @11,[expr {$fixedHeight * 7 + 5}]] \
         [.t index @$off,[expr {[yline 7]+2}]] \
	 [.t index @$off,[expr {[yline 8]+2}]] \
	 [.t index @$off,1002]
	    [.t index @11,1002]
} {197.1 198.1 199.1 201.0}
test textDisp-21.3 {TkTextPixelIndex, horizontal scrolling} {
test textDisp-21.3 {TkTextPixelIndex, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "12345\n"
    .t insert end "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .t xview scroll 2 units
    set off [expr {[yline 1]+4}]
    list [.t index @-5,$off] [.t index @[expr {[xchar 1]-2}],$off] [.t index @[expr {[xchar 4]+2}],[expr {[yline 2]+2}]]
    list [.t index @-5,7] [.t index @5,7] [.t index @33,20]
} {1.2 1.2 2.6}
test textDisp-21.4 {count -displaylines regression} {
    set message {
   QOTW:  "C/C++, which is used by 16% of users, is the most popular programming language, but Tcl, used by 0%, seems to be the language of choice for the highest scoring users."
(new line)
Use the Up (cursor) key to scroll up one line at a time.  At the second press, the cursor either gets locked or jumps several lines.

3298
3299
3300
3301
3302
3303
3304
3305

3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317

3318
3319
3320
3321
3322

3323
3324
3325
3326
3327

3328
3329
3330
3331

3332
3333
3334

3335
3336
3337
3338
3339
3340

3341
3342
3343
3344

3345
3346


3347
3348
3349
3350
3351
3352

3353
3354
3355
3356

3357
3358


3359
3360
3361
3362
3363

3364
3365
3366
3367


3368
3369
3370
3371
3372
3373
3374

3375
3376
3377
3378
3379

3380

3381
3382
3383

3384
3385
3386
3387
3388
3389

3390
3391
3392

3393
3394
3395
3396
3397
3398
3399
3400

3401
3402
3403
3404
3405
3406

3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423

3424
3425
3426
3427
3428
3429
3430

3431
3432
3433
3434

3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453

3454
3455
3456
3457

3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476

3477
3478
3479
3480
3481

3482
3483
3484
3485
3486
3487


3488
3489
3490
3491

3492
3493

3494
3495
3496
3497
3498

3499
3500

3501
3502
3503
3504
3505
3506

3507
3508
3509
3510

3511
3512


3513
3514
3515
3516
3517
3518

3519
3520
3521
3522

3523

3524
3525
3526

3527
3528
3529
3530
3531
3532
3533
3534
3535

3536
3537
3538
3539

3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550

3551
3552
3553
3554
3555

3556
3557
3558
3559
3560

3561
3562

3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574

3575
3576
3577
3578

3579
3580


3581
3582
3583
3584
3585
3586
3587

3588
3589
3590
3591

3592
3593


3594
3595
3596
3597
3598
3599
3600
3601

3602
3603

3604
3605
3606
3607
3608
3609
3610

3611
3612
3613
3614

3615
3616

3617
3618
3619
3620
3621
3622
3623

3624
3625

3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637

3638
3639
3640
3641

3642
3643


3644
3645
3646
3647
3648
3649
3650

3651
3652
3653
3654

3655
3656


3657
3658
3659
3660
3661
3662
3663

3664
3665
3666
3667

3668
3669


3670
3671
3672
3673
3674
3675
3676

3677
3678
3679
3680

3681
3682


3683
3684
3685
3686
3687
3688

3689

3690

3691
3692
3693
3694
3695

3696
3697
3698
3699

3700
3701
3702
3703
3704
3705
3706
3707

3708
3709


3710
3711
3712
3713
3714
3715
3716
3717


3718
3719
3720
3721
3722
3723
3724

3725
3726
3727
3728

3729
3730


3731
3732
3733
3734
3735
3736
3737

3738
3739
3740
3741

3742
3743
3744



3745
3746
3747
3748
3749
3750
3751
3752

3753
3754
3755
3756

3757
3758

3759
3760
3761

3762
3763
3764
3765
3766
3767
3768

3769
3770

3771
3772
3773
3774
3775
3776

3777
3778

3779
3780
3781

3782
3783
3784
3785
3786
3787
3788
3789

3790
3791

3792
3793
3794
3795
3796
3797
3798
3799
3800

3801
3802
3803
3804

3805
3806
3807
3808
3809
3810
3811
3812

3813
3814
3815
3816
3817
3818
3819
3820


3821
3822
3823
3824
3825
3826
3827
3828
3829



3830
3831
3832

3833
3834
3835
3836
3837
3838

3839
3840
3841
3842
3843
3844
3845

3846
3847
3848
3849
3850
3851

3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867

3868
3869
3870

3871
3872
3873
3874
3875
3876

3877
3878

3879
3880
3881

3882
3883
3884
3885
3886

3887
3888
3889

3890
3891
3892
3893
3894
3895
3896
3897

3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918



3919
3920
3921
3922
3923
3924
3925
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
3171


3172


3173
3174
3175
3176




3177
3178
3179


3180


3181
3182
3183
3184
3185
3186
3187

3188


3189



3190
3191
3192






3193
3194



3195


3196
3197



3198
3199
3200

3201
3202



3203


3204
3205



3206
3207
3208

3209
3210



3211


3212
3213



3214
3215
3216

3217
3218



3219


3220
3221
3222
3223
3224



3225
3226
3227

3228
3229
3230



3231




3232
3233
3234
3235
3236
3237



3238


3239
3240
3241
3242
3243
3244
3245
3246


3247
3248



3249
3250
3251

3252
3253



3254


3255
3256



3257
3258
3259

3260
3261



3262



3263
3264
3265
3266
3267
3268
3269
3270



3271
3272
3273


3274


3275
3276
3277

3278
3279
3280
3281
3282
3283
3284

3285


3286
3287
3288
3289
3290
3291

3292


3293



3294
3295
3296
3297
3298
3299
3300


3301


3302
3303
3304
3305
3306
3307
3308
3309
3310

3311
3312
3313
3314

3315





3316
3317

3318
3319
3320
3321
3322
3323
3324


3325
3326
3327
3328
3329
3330
3331
3332



3333
3334
3335
3336
3337

3338
3339
3340
3341
3342
3343

3344
3345
3346
3347




3348
3349
3350
3351
3352
3353

3354














3355

3356
3357
3358

3359
3360
3361
3362



3363
3364

3365
3366
3367

3368
3369
3370
3371
3372

3373



3374
3375
3376
3377
3378
3379
3380
3381

3382


3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398



3399
3400
3401
3402
3403
3404
3405
3406
3407
3408







-
+











-
+




-
+
-
-
-
-
-
+



-
+
-
-
-
+
-
-
-


-
+

-
-
-
+
-
-
+
+
-
-
-


-
+

-
-
-
+
-
-
+
+
-
-


-
+


-
-
+
+
-
-
-



-
+

-
-
-
-
+
-
+


-
+





-
+
-

-
+







-
+
-
-
-
-
-
-
+
















-
+
-
-
-
-
-

-
+



-
+


















-
+



-
+


















-
+




-
+
-
-
-
-
-
-
+
+



-
+

-
+




-
+
-
-
+
-
-
-


-
+

-
-
-
+
-
-
+
+
-
-
-


-
+

-
-
-
+
-
+


-
+








-
+
-
-

-
+










-
+
-
-


-
+




-
+
-
-
+
-
-
-



-
-
-
-
-
-
+

-
-
-
+
-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
+
+






-
-
+
-
-
+



-
-
-
-
+


-
-
+
-
-
+






-
+
-
-
+
-
-
-



-
-
-
-
-
-
+

-
-
-
+
-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
+
+



-
-
-
+

+
-
+


-
-
-
+
-
-
-
-
+





-
-
-
+
-
-
+
+






-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
+
+
-
-
-



-
+

-
-
-
+
-
-
-
+
+
+





-
-
-
+


-
-
+
-
-
+


-
+






-
+
-
-
+





-
+
-
-
+
-
-
-
+






-
-
+
-
-
+








-
+



-
+
-
-
-
-
-


-
+






-
-
+
+






-
-
-
+
+
+


-
+





-
+



-
-
-
-
+





-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+


-
+



-
-
-
+

-
+


-
+




-
+
-
-
-
+







-
+
-
-
















-
-
-
+
+
+







.tt.u insert end $message
.tt.u mark set insert 3.10
tkwait visibility .tt.u
set res [.tt.u count -displaylines 3.10 2.173]
destroy .tt
unset message
set res
} -1
} {-1}

.t delete 1.0 end
.t insert end "Line 1"
for {set i 2} {$i <= 200} {incr i} {
    .t insert end "\nLine $i"
}
.t configure -wrap word
.t delete 50.0 51.0
.t insert 50.0 "This is a long line, one that will wrap around twice.\n"
update
.t tag add x 50.1
test textDisp-22.1 {TkTextCharBbox} {
test textDisp-22.1 {TkTextCharBbox} {textfonts} {
    .t config -wrap word
    .t yview 48.0
    list [.t bbox 47.2] [.t bbox 48.0] [.t bbox 50.5] [.t bbox 50.40] \
	    [.t bbox 58.0]
} [list {} \
} [list {} [list 3 3 7 $fixedHeight] [list 38 [expr {3+2*$fixedHeight}] 7 $fixedHeight] [list 3 [expr {3+4*$fixedHeight}] 7 $fixedHeight] {}]
        [list [xchar 0] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 5] [yline 3] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 5] $fixedWidth $fixedHeight] \
	{}]
test textDisp-22.2 {TkTextCharBbox} {
test textDisp-22.2 {TkTextCharBbox} {textfonts} {
    .t config -wrap none
    .t yview 48.0
    list [.t bbox 50.5] [.t bbox 50.40] [.t bbox 57.0]
} [list [list [xchar 5] [yline 3] $fixedWidth $fixedHeight] \
} [list [list 38 [expr {3+2*$fixedHeight}] 7 $fixedHeight] {} [list 3 [expr {3+9*$fixedHeight}] 7 $fixedHeight]]
        {} \
	[list [xchar 0] [yline 10] $fixedWidth $fixedHeight]]
test textDisp-22.3 {TkTextCharBbox, cut-off lines} {
test textDisp-22.3 {TkTextCharBbox, cut-off lines} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t config -wrap char
    .t yview 10.0
    wm geom . ${width}x[expr {$height-1}]
    wm geom . ${width}x[expr $height-1]
    update
    set expected [list [list [xchar 1] [yline 10] $fixedWidth $fixedHeight] \
                       [list [xchar 1] [yline 11] $fixedWidth [expr {($height-1)-$oriHeight}]]]
    lequal [list [.t bbox 19.1] [.t bbox 20.1]] $expected
    list [.t bbox 19.1] [.t bbox 20.1]
} {1}
test textDisp-22.4 {TkTextCharBbox, cut-off lines} {
} [list [list 10 [expr {3+9*$fixedHeight}] 7 $fixedHeight] [list 10 [expr {3+10*$fixedHeight}] 7 3]]
test textDisp-22.4 {TkTextCharBbox, cut-off lines} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t config -wrap char
    .t yview 10.0
    wm geom . ${width}x[expr {$height+1}]
    wm geom . ${width}x[expr $height+1]
    update
    set expected [list [list [xchar 1] [yline 10] $fixedWidth $fixedHeight] \
                       [list [xchar 1] [yline 11] $fixedWidth [expr {($height+1)-$oriHeight}]]]
    lequal [list [.t bbox 19.1] [.t bbox 20.1]] $expected
    list [.t bbox 19.1] [.t bbox 20.1]
} {1}
test textDisp-22.5 {TkTextCharBbox, cut-off char} {
} [list [list 10 [expr {3+9*$fixedHeight}] 7 $fixedHeight] [list 10 [expr {3+10*$fixedHeight}] 7 5]]
test textDisp-22.5 {TkTextCharBbox, cut-off char} {textfonts} {
    wm geometry . {}
    update
    .t config -wrap none
    .t yview 10.0
    wm geom . [expr {$width-(20-7)*$fixedWidth}]x$height
    wm geom . [expr $width-95]x$height
    update
    .t bbox 15.6
} [list [xchar 6] [yline 6] $fixedWidth $fixedHeight]
test textDisp-22.6 {TkTextCharBbox, line visible but not char} haveBigFontTwiceLargerThanTextFont {
} [list 45 [expr {3+5*$fixedHeight}] 7 $fixedHeight]
test textDisp-22.6 {TkTextCharBbox, line visible but not char} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t config -wrap char
    .t yview 10.0
    .t tag add big 20.2 20.5
    wm geom . ${width}x[expr {$height+3}]
    wm geom . ${width}x[expr $height+3]
    update
    set expected [list [list [xchar 1] [yline 10] $fixedWidth $fixedHeight] \
                       {} \
	               [list [xchar 2] [yline 11] [font measure $bigFont "n"] [expr {($height+3)-$oriHeight}]]]
    lequal [list [.t bbox 19.1] [.t bbox 20.1] [.t bbox 20.2]] $expected
    list [.t bbox 19.1] [.t bbox 20.1] [.t bbox 20.2]
} {1}
} [list [list 10 [expr {3+9*$fixedHeight}] 7 $fixedHeight] {} [list 17 [expr {3+10*$fixedHeight}] 14 7]]
wm geom . {}
update
test textDisp-22.7 {TkTextCharBbox, different character sizes} haveBigFontTwiceLargerThanTextFont {
test textDisp-22.7 {TkTextCharBbox, different character sizes} {textfonts} {
    .t config -wrap char
    .t yview 10.0
    .t tag add big 12.2 12.5
    update
    list [.t bbox 12.1] [.t bbox 12.2]
} [list [list [xchar 1] [expr {[yline 3]+$ascentDiff}] $fixedWidth $fixedHeight] \
} [list [list 10 [expr {3 + 2*$fixedHeight + $ascentDiff}] 7 $fixedHeight] [list 17 [expr {3+ 2*$fixedHeight}] 14 27]]
        [list [xchar 2] [yline 3] [font measure $bigFont "n"] $bigHeight]]
.t tag remove big 1.0 end
test textDisp-22.8 {TkTextCharBbox, horizontal scrolling} {
test textDisp-22.8 {TkTextCharBbox, horizontal scrolling} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert end "12345\n"
    .t insert end "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .t xview scroll 4 units
    list [.t bbox 1.3] [.t bbox 1.4] [.t bbox 2.3] [.t bbox 2.4] \
	    [.t bbox 2.23] [.t bbox 2.24]
} [list {} \
} [list {} [list 3 3 7 $fixedHeight] {} [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 136 [expr {$fixedDiff + 16}] 7 $fixedHeight] {}]
        [list [xchar 0] [yline 1] $fixedWidth $fixedHeight] \
	{} \
	[list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [xchar 19] [yline 2] $fixedWidth $fixedHeight] \
	{}]
test textDisp-22.9 {TkTextCharBbox, handling of spacing} {
test textDisp-22.9 {TkTextCharBbox, handling of spacing} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijkl\nmnopqrstuvwzyz"
    .t tag configure spacing -spacing1 8 -spacing3 2
    .t tag add spacing 1.0 end
    frame .t.f1 -width 10 -height 4 -bg black
    frame .t.f2 -width 10 -height 4 -bg black
    frame .t.f3 -width 10 -height 4 -bg black
    frame .t.f4 -width 10 -height 4 -bg black
    .t window create 1.3 -window .t.f1 -align top
    .t window create 1.7 -window .t.f2 -align center
    .t window create 2.1 -window .t.f3 -align bottom
    .t window create 2.10 -window .t.f4 -align baseline
    update
    list [.t bbox .t.f1] [.t bbox .t.f2] [.t bbox .t.f3] [.t bbox .t.f4] \
	    [.t bbox 1.1] [.t bbox 2.9]
} [list [list [xchar 3] [expr {[yline 1]+8}] 10 4] \
} [list [list 24 11 10 4] [list 55 [expr {$fixedDiff/2 + 15}] 10 4] [list 10 [expr {2*$fixedDiff + 43}] 10 4] [list 76 [expr {2*$fixedDiff + 40}] 10 4] [list 10 11 7 $fixedHeight] [list 69 [expr {$fixedDiff + 34}] 7 $fixedHeight]]
        [list [expr {[xchar 3]+10+[xw 3]}] [expr {[yline 1]+8+($fixedHeight-4)/2}] 10 4] \
	[list [xchar 1] [expr {[yline 2]+8+2+8+($fixedHeight-4)}] 10 4] \
	[list [expr {[xchar 1]+10+[xw 8]}] [expr {[yline 2]+8+2+8+($fixedAscent-4)}] 10 4] \
	[list [xchar 1] [expr {[yline 1]+8}] $fixedWidth $fixedHeight] \
	[list [expr {[xchar 1]+10+[xw 7]}] [expr {[yline 2]+8+2+8}] $fixedWidth $fixedHeight]]
.t tag delete spacing
test textDisp-22.10 {TkTextCharBbox, handling of elided lines} {
test textDisp-22.10 {TkTextCharBbox, handling of elided lines} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i - Line [format %c [expr {64+$i}]]\n"
        .t insert end "Line $i - Line [format %c [expr 64+$i]]\n"
    }
    .t tag add hidden 2.8 2.13
    .t tag add hidden 6.8 7.13
    .t tag configure hidden -elide true
    update
    list \
        [expr {[lindex [.t bbox 2.9]  0] - [lindex [.t bbox 2.8] 0]}] \
        [expr {[lindex [.t bbox 2.10] 0] - [lindex [.t bbox 2.8] 0]}] \
        [expr {[lindex [.t bbox 2.13] 0] - [lindex [.t bbox 2.8] 0]}] \
        [expr {[lindex [.t bbox 6.9]  0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 6.10] 0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 6.13] 0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 6.14] 0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 6.15] 0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 7.0]  0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 7.1]  0] - [lindex [.t bbox 6.8] 0]}] \
        [expr {[lindex [.t bbox 7.12] 0] - [lindex [.t bbox 6.8] 0]}]
} [list 0 0 0 0 0 0 0 0 0 0 0]
test textDisp-22.11 {TkTextCharBbox, handling of wrapped elided lines} {
test textDisp-22.11 {TkTextCharBbox, handling of wrapped elided lines} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    for {set i 1} {$i < 10} {incr i} {
        .t insert end "Line $i - Line _$i - Lines .$i - Line [format %c [expr {64+$i}]]\n"
        .t insert end "Line $i - Line _$i - Lines .$i - Line [format %c [expr 64+$i]]\n"
    }
    .t tag add hidden 1.30 2.5
    .t tag configure hidden -elide true
    update
    list \
        [expr {[lindex [.t bbox 1.30] 0] - [lindex [.t bbox 2.4]  0]}] \
        [expr {[lindex [.t bbox 1.30] 0] - [lindex [.t bbox 2.5]  0]}]
} [list 0 0]

.t delete 1.0 end
.t insert end "Line 1"
for {set i 2} {$i <= 200} {incr i} {
    .t insert end "\nLine $i"
}
.t configure -wrap word
.t delete 50.0 51.0
.t insert 50.0 "This is a long line, one that will wrap around twice.\n"
update
test textDisp-23.1 {TkTextDLineInfo} {
test textDisp-23.1 {TkTextDLineInfo} {textfonts} {
    .t config -wrap word
    .t yview 48.0
    list [.t dlineinfo 47.3] [.t dlineinfo 48.0] [.t dlineinfo 50.40] \
	    [.t dlineinfo 56.0]
} [list {} \
} [list {} [list 3 3 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {4*$fixedDiff + 55}] 91 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}]
        [list [bo] [yline 1] [xw 7] $fixedHeight $fixedAscent] \
	[list [bo] [yline 5] [xw 13] $fixedHeight $fixedAscent] \
	{}]
.t config -bd 4
test textDisp-23.2 {TkTextDLineInfo} {
    .t config -wrap word
test textDisp-23.2 {TkTextDLineInfo} {textfonts} {
    .t config -bd 4 -wrap word
    update
    .t yview 48.0
    .t dlineinfo 50.40
} [list [bo] [yline 5] [xw 13] $fixedHeight $fixedAscent]
} [list 7 [expr {4*$fixedDiff + 59}] 91 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]
.t config -bd 0
test textDisp-23.3 {TkTextDLineInfo} {
test textDisp-23.3 {TkTextDLineInfo} {textfonts} {
    .t config -wrap none
    update
    .t yview 48.0
    list [.t dlineinfo 50.40] [.t dlineinfo 57.3]
} [list [list [bo] [yline 3] [xw 53] $fixedHeight $fixedAscent] \
} [list [list 3 [expr {2*$fixedDiff + 29}] 371 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {9*$fixedDiff + 120}] 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]]
        [list [bo] [yline 10] [xw 7] $fixedHeight $fixedAscent]]
test textDisp-23.4 {TkTextDLineInfo, cut-off lines} {
test textDisp-23.4 {TkTextDLineInfo, cut-off lines} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t config -wrap char
    .t yview 10.0
    wm geom . ${width}x[expr {$height-1}]
    wm geom . ${width}x[expr $height-1]
    update
    set expected [list [list [bo] [yline 10] [xw 7] $fixedHeight $fixedAscent] \
                       [list [bo] [yline 11] [xw 7] [expr {($height-1)-$oriHeight}] $fixedAscent]]
    lequal [list [.t dlineinfo 19.0] [.t dlineinfo 20.0]] $expected
    list [.t dlineinfo 19.0] [.t dlineinfo 20.0]
} {1}
test textDisp-23.5 {TkTextDLineInfo, cut-off lines} {
} [list [list 3 [expr {9*$fixedDiff + 120}] 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {10*$fixedDiff + 133}] 49 3 [expr {$fixedDiff + 10}]]]
test textDisp-23.5 {TkTextDLineInfo, cut-off lines} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t config -wrap char
    .t yview 10.0
    wm geom . ${width}x[expr {$height+1}]
    wm geom . ${width}x[expr $height+1]
    update
    set expected [list [list [bo] [yline 10] [xw 7] $fixedHeight $fixedAscent] \
                       [list [bo] [yline 11] [xw 7] [expr {($height+1)-$oriHeight}] $fixedAscent]]
    lequal [list [.t dlineinfo 19.0] [.t dlineinfo 20.0]] $expected
    list [.t dlineinfo 19.0] [.t dlineinfo 20.0]
} {1}
} [list [list 3 [expr {9*$fixedDiff + 120}] 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {10*$fixedDiff + 133}] 49 5 [expr {$fixedDiff + 10}]]]
wm geom . {}
update
test textDisp-23.6 {TkTextDLineInfo, horizontal scrolling} {
test textDisp-23.6 {TkTextDLineInfo, horizontal scrolling} {textfonts} {
    .t config -wrap none
    .t delete 1.0 end
    .t insert end "First line\n"
    .t insert end "Second line is a very long one that doesn't all fit.\n"
    .t insert end "Third"
    .t xview scroll 6 units
    update
    list [.t dlineinfo 1.0] [.t dlineinfo 2.0] [.t dlineinfo 3.0]
} [list [list [expr {[xw -6]+[bo]}] [yline 1] [xw 10] $fixedHeight $fixedAscent] \
} [list [list -39 3 70 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list -39 [expr {$fixedDiff + 16}] 364 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list -39 [expr {2*$fixedDiff + 29}] 35 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]]
        [list [expr {[xw -6]+[bo]}] [yline 2] [xw 52] $fixedHeight $fixedAscent] \
	[list [expr {[xw -6]+[bo]}] [yline 3] [xw 5] $fixedHeight $fixedAscent]]
.t xview moveto 0
test textDisp-23.7 {TkTextDLineInfo, centering} {
test textDisp-23.7 {TkTextDLineInfo, centering} {textfonts} {
    .t config -wrap word
    .t delete 1.0 end
    .t insert end "First line\n"
    .t insert end "Second line is a very long one that doesn't all fit.\n"
    .t insert end "Third"
    .t tag configure x -justify center
    .t tag configure y -justify right
    .t tag add x 1.0
    .t tag add y 3.0
    list [.t dlineinfo 1.0] [.t dlineinfo 2.0] [.t dlineinfo 3.0]
} [list [list [expr {[bo]+[xe 10]/2}] [yline 1] [xw 10] $fixedHeight $fixedAscent] \
} [list [list 38 3 70 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {$fixedDiff + 16}] 119 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 108 [expr {4*$fixedDiff + 55}] 35 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]]
        [list [bo] [yline 2] [xw 17] $fixedHeight $fixedAscent] \
	[list [xcharr 5] [yline 5] [xw 5] $fixedHeight $fixedAscent]]
.t tag delete x y

test textDisp-24.1 {TkTextCharLayoutProc} {
test textDisp-24.1 {TkTextCharLayoutProc} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 136 3 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-24.2 {TkTextCharLayoutProc} {
test textDisp-24.2 {TkTextCharLayoutProc} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    # be tolerant about borderwidth et al. - don't let another char fit on the line
    set wi $width
    while {$wi+1-$oriWidth >= $fixedWidth} {
        incr wi -$fixedWidth
    }
    wm geom . [expr {$wi+1}]x$height
    wm geom . [expr $width+1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($wi+1-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.3 {TkTextCharLayoutProc} {
} [list [list 136 3 12 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.3 {TkTextCharLayoutProc} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    wm geom . [expr {$width-1}]x$height
    wm geom . [expr $width-1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($width-1-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.4 {TkTextCharLayoutProc, newline not visible} {
} [list [list 136 3 10 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.4 {TkTextCharLayoutProc, newline not visible} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 01234567890123456789\n012345678901234567890
    wm geom . {}
    update
    list [.t bbox 1.19] [.t bbox 1.20] [.t bbox 2.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 20] [yline 1] 0 $fixedHeight] \
} [list [list 136 3 7 $fixedHeight] [list 143 3 0 $fixedHeight] [list 3 [expr {2*$fixedDiff + 29}] 7 $fixedHeight]]
	[list [xchar 0] [yline 3] $fixedWidth $fixedHeight]]
test textDisp-24.5 {TkTextCharLayoutProc, char doesn't fit, newline not visible} {nonwin} {
test textDisp-24.5 {TkTextCharLayoutProc, char doesn't fit, newline not visible} {unix textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 0\n1\n
    # set text widget width to 1-char width minus [bo] pixels
    # note: windows refuses to shrink enough therefore the constraint
    set wi [expr {[winfo width .f]+[bo]+[xw 1]}]
    wm geom . ${wi}x$height
    wm geom . 110x$height
    update
    list [.t bbox 1.0] [.t bbox 1.1] [.t bbox 2.0]
} [list [list [xchar 0] [yline 1] [expr {$fixedWidth-[bo]}] $fixedHeight] \
        [list [expr {[xchar 1]-[bo]}] [yline 1] 0 $fixedHeight] \
} [list [list 3 3 4 $fixedHeight] [list 7 3 0 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 4 $fixedHeight]]
	[list [xchar 0] [yline 2] [expr {$fixedWidth-[bo]}] $fixedHeight]]
test textDisp-24.6 {TkTextCharLayoutProc, line ends with space} {
test textDisp-24.6 {TkTextCharLayoutProc, line ends with space} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a b c d e f g h i j k l m n o p"
    wm geom . {}
    update
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 136 3 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-24.7 {TkTextCharLayoutProc, line ends with space} {
test textDisp-24.7 {TkTextCharLayoutProc, line ends with space} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a b c d e f g h i j k l m n o p"
    # be tolerant about borderwidth et al. - don't let another char fit on the line
    set wi $width
    while {$wi+1-$oriWidth >= $fixedWidth} {
        incr wi -$fixedWidth
    }
    wm geom . [expr {$wi+1}]x$height
    wm geom . [expr $width+1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($wi+1-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.8 {TkTextCharLayoutProc, line ends with space} {
} [list [list 136 3 12 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.8 {TkTextCharLayoutProc, line ends with space} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a b c d e f g h i j k l m n o p"
    wm geom . [expr {$width-1}]x$height
    wm geom . [expr $width-1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($width-1-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.9 {TkTextCharLayoutProc, line ends with space} {
} [list [list 136 3 10 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.9 {TkTextCharLayoutProc, line ends with space} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a b c d e f g h i j k l m n o p"
    wm geom . [expr {$width-6}]x$height
    wm geom . [expr $width-6]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($width-6-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.10 {TkTextCharLayoutProc, line ends with space} {
} [list [list 136 3 5 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.10 {TkTextCharLayoutProc, line ends with space} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "a b c d e f g h i j k l m n o p"
    wm geom . [expr {$width-7}]x$height
    wm geom . [expr $width-7]x$height
    update
    set expected [list [list [xchar 19] [yline 1] [expr {$fixedWidth+($width-7-$oriWidth)}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.11 {TkTextCharLayoutProc, line ends with space that doesn't quite fit} {
} [list [list 136 3 4 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.11 {TkTextCharLayoutProc, line ends with space that doesn't quite fit} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "01234567890123456789 \nabcdefg"
    # set text widget width to 2 pixels more than 20-char width
    set wi [expr {[winfo width .f]+2*[bo]+[xw 20]+2}]
    wm geom . ${wi}x$height
    wm geom . [expr $width-2]x$height
    update
    set result {}
    set result [list [.t bbox 1.21] [.t bbox 2.0]]
    lappend result [.t bbox 1.21] [.t bbox 2.0]
    .t mark set insert 1.21
    lappend result [.t bbox 1.21] [.t bbox 2.0]
} [list [list [expr {[xchar 20]+2}] [yline 1] 0 $fixedHeight] \
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [expr {[xchar 20]+2}] [yline 1] 0 $fixedHeight] \
} [list [list 145 3 0 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 145 3 0 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
	[list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
wm geom . {}
update
test textDisp-24.12 {TkTextCharLayoutProc, tab causes wrap} {
test textDisp-24.12 {TkTextCharLayoutProc, tab causes wrap} {textfonts} {
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghi"
    .t mark set insert 1.4
    .t insert insert \t\t\t
    set expected [list [list [expr {[xchar 0]+2*8*$fixedWidth}] [yline 1] [expr {[winfo width .t]-([xchar 0]+2*8*$fixedWidth)-[bo]}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox {insert -1c}] [.t bbox insert]] $expected
    list [.t bbox {insert -1c}] [.t bbox insert]
} {1}
test textDisp-24.13 {TkTextCharLayoutProc, -wrap none} {
} [list [list 115 3 30 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
test textDisp-24.13 {TkTextCharLayoutProc, -wrap none} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    wm geom . {}
    update
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] {}]
test textDisp-24.14 {TkTextCharLayoutProc, -wrap none} {
} [list [list 136 3 7 $fixedHeight] {}]
test textDisp-24.14 {TkTextCharLayoutProc, -wrap none} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap none
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    wm geom . [expr {$width+1}]x$height
    wm geom . [expr $width+1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
                       [list [xchar 20] [yline 1] [expr {$width+1-$oriWidth}] $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.15 {TkTextCharLayoutProc, -wrap none} {
} [list [list 136 3 7 $fixedHeight] [list 143 3 5 $fixedHeight]]
test textDisp-24.15 {TkTextCharLayoutProc, -wrap none} {textfonts} {
    wm geometry . {}
    update
    scan [wm geom .] %dx%d oriWidth oriHeight
    .t configure -wrap none
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    wm geom . [expr {$width-1}]x$height
    wm geom . [expr $width-1]x$height
    update
    set expected [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
                       [list [xchar 20] [yline 1] [expr {$width-1-$oriWidth}] $fixedHeight]]
    lequal [list [.t bbox 1.19] [.t bbox 1.20]] $expected
    list [.t bbox 1.19] [.t bbox 1.20]
} {1}
test textDisp-24.16 {TkTextCharLayoutProc, no chars fit} {
    if {[tk windowingsystem] eq "win32"} {
} [list [list 136 3 7 $fixedHeight] [list 143 3 3 $fixedHeight]]
test textDisp-24.16 {TkTextCharLayoutProc, no chars fit} {textfonts} {
    if {$tcl_platform(platform) == "windows"} {
	wm overrideredirect . 1
    }
    .t configure -wrap char
    .t delete 1.0 end
    .t insert 1.0 "abcdefghijklmnopqrstuvwxyz"
    # set text widget width to [bo] pixels (no chars fit in the widget at all)
    set wi [expr {[winfo width .f]+[bo]}]
    wm geom . ${wi}x$height
    wm geom . 103x$height
    update
    list [.t bbox 1.0] [.t bbox 1.1] [.t bbox 1.2]
} [list [list [xchar 0] [yline 1] 1 $fixedHeight] \
        [list [xchar 0] [yline 2] 1 $fixedHeight] \
} [list [list 3 3 1 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 1 $fixedHeight] [list 3 [expr {2*$fixedDiff + 29}] 1 $fixedHeight]]
	[list [xchar 0] [yline 3] 1 $fixedHeight]]
if {[tk windowingsystem] eq "win32"} {
if {$tcl_platform(platform) == "windows"} {
    wm overrideredirect . 0
}
test textDisp-24.17 {TkTextCharLayoutProc, -wrap word} {
test textDisp-24.17 {TkTextCharLayoutProc, -wrap word} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "This is a line that wraps around"
    wm geom . {}
    update
    list [.t bbox 1.19] [.t bbox 1.20]
} [list [list [xchar 19] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 136 3 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
        [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-24.18 {TkTextCharLayoutProc, -wrap word} {
test textDisp-24.18 {TkTextCharLayoutProc, -wrap word} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "xxThis is a line that wraps around"
    wm geom . {}
    update
    list [.t bbox 1.15] [.t bbox 1.16] [.t bbox 1.17] [.t bbox 1.21]
    list [.t bbox 1.15] [.t bbox 1.16] [.t bbox 1.17]
} [list [list [xchar 15] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 16] [yline 1] [xe 16] $fixedHeight] \
} [list [list 108 3 7 $fixedHeight] [list 115 3 28 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]]
	[list [xchar 0] [yline 2] $fixedWidth $fixedHeight] \
	[list [xchar 4] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-24.19 {TkTextCharLayoutProc, -wrap word} {
test textDisp-24.19 {TkTextCharLayoutProc, -wrap word} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "xxThis is a line that wraps around"
    wm geom . {}
    update
    list [.t bbox 1.14] [.t bbox 1.15] [.t bbox 1.16]
} [list [list [xchar 14] [yline 1] $fixedWidth $fixedHeight] \
        [list [xchar 15] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 101 3 7 $fixedHeight] [list 108 3 7 $fixedHeight] [list 115 3 28 $fixedHeight]]
	[list [xchar 16] [yline 1] [xe 16] $fixedHeight]]
test textDisp-24.20 {TkTextCharLayoutProc, vertical offset} {
test textDisp-24.20 {TkTextCharLayoutProc, vertical offset} {textfonts} {
    .t configure -wrap none
    .t delete 1.0 end
    .t insert 1.0 "Line 1\nLine 2\nLine 3"
    set result {}
    lappend result [.t bbox 2.1] [.t dlineinfo 2.1]
    .t tag configure up -offset 6
    .t tag add up 2.1
    lappend result [.t bbox 2.1] [.t dlineinfo 2.1]
    .t tag configure up -offset -2
    .t tag configure  up -offset -2
    lappend result [.t bbox 2.1] [.t dlineinfo 2.1]
    .t tag delete up
    set result
} [list [list [xchar 1] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 10 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 42 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 10 [expr {$fixedDiff + 16}] 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 42 [expr {$fixedDiff + 19}] [expr {$fixedDiff + 16}]] [list 10 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 42 [expr {$fixedDiff + 15}] [expr {$fixedDiff + 10}]]]
        [list [bo] [yline 2] [xw 6] $fixedHeight $fixedAscent] \
	[list [xchar 1] [yline 2] $fixedWidth $fixedHeight] \
        [list [bo] [yline 2] [xw 6] [expr {$fixedHeight+6}] [expr {$fixedAscent+6}]] \
	[list [xchar 1] [expr {[yline 2]+2}] $fixedWidth $fixedHeight] \
        [list [bo] [yline 2] [xw 6] [expr {$fixedHeight+2}] $fixedAscent]]
.t configure -width 30
update
test textDisp-24.21 {TkTextCharLayoutProc, word breaks} {
test textDisp-24.21 {TkTextCharLayoutProc, word breaks} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    .t insert 1.0 "Sample text xxxxxxx yyyyy zzzzzzz qqqqq rrrr ssss tt u vvvvv"
    frame .t.f -width 30 -height 20 -bg black
    .t window create 1.36 -window .t.f
    .t bbox 1.26
} [list [xchar 0] [expr {[yline 2]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]
test textDisp-24.22 {TkTextCharLayoutProc, word breaks} {
} [list 3 [expr {$fixedDiff/2 + 19}] 7 $fixedHeight]
test textDisp-24.22 {TkTextCharLayoutProc, word breaks} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    frame .t.f -width 30 -height 20 -bg black
    .t insert 1.0 "Sample text xxxxxxx yyyyyyy"
    .t window create end -window .t.f
    .t insert end "zzzzzzz qqqqq rrrr ssss tt u vvvvv"
   .t bbox 1.28
} [list [expr {[bo]+30}] [expr {[yline 2]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]
test textDisp-24.23 {TkTextCharLayoutProc, word breaks} {
    .t bbox 1.28
} [list 33 [expr {$fixedDiff/2 + 19}] 7 $fixedHeight]
test textDisp-24.23 {TkTextCharLayoutProc, word breaks} {textfonts} {
    .t configure -wrap word
    .t delete 1.0 end
    frame .t.f -width 50 -height 20 -bg black
    frame .t.f -width 30 -height 20 -bg black
    .t insert 1.0 "Sample text xxxxxxx yyyyyyy "
    .t insert end "zzzzzzz qqqqq rrrr ssss tt"
    .t window create end -window .t.f
    .t insert end "u vvvvv"
    .t bbox .t.f
} [list [xchar 0] [yline 3] 50 20]
} [list 3 [expr {2*$fixedDiff + 29}] 30 20]
catch {destroy .t.f}
.t configure -width 20
update
# Next test is currently constrained to not run on mac (aqua) because on
# aqua it fails due to wrong implementation of tabs with right justification
# (the text is not rendered at all). This is a bug.
test textDisp-24.24 {TkTextCharLayoutProc, justification and tabs} notAqua {
test textDisp-24.24 {TkTextCharLayoutProc, justification and tabs} {textfonts} {
    .t delete 1.0 end
    .t tag configure x -justify center
    .t insert 1.0 aa\tbb\tcc\tdd\t
    .t tag add x 1.0 end
    list [.t bbox 1.0] [.t bbox 1.10]
} [list [list [expr {[bo]+[xe 8]/2}] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 45 3 7 $fixedHeight] [list 94 3 7 $fixedHeight]]
        [list [expr {[bo]+[xe 8]/2+[xw 7]}] [yline 1] $fixedWidth $fixedHeight]]
test textDisp-24.25 {TkTextCharLayoutProc, justification and tabs} -setup {
    text .tt -tabs {40 right} -wrap none -font $fixedFont
    pack .tt
} -body {
    .tt insert end \t9\n\t99\n\t999
    update
    set expected [list [list [expr {[bo .tt]+40-$fixedWidth}] [yline 1 .tt] $fixedWidth $fixedHeight] \
                       [list [expr {[bo .tt]+40-$fixedWidth}] [yline 2 .tt] $fixedWidth $fixedHeight] \
                       [list [expr {[bo .tt]+40-$fixedWidth}] [yline 3 .tt] $fixedWidth $fixedHeight]]
    lequal [list [.tt bbox 1.1] [.tt bbox 2.2] [.tt bbox 3.3]] $expected
} -cleanup {
    destroy .tt
} -result {1}

.t configure -width 40 -bd 0 -relief flat -highlightthickness 0 \
.t configure -width 40 -bd 0 -relief flat -highlightthickness 0 -padx 0 \
    -tabs 100
update
test textDisp-25.1 {CharBboxProc procedure, check tab width} {
test textDisp-25.1 {CharBboxProc procedure, check tab width} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 abc\td\tfgh
    list [.t bbox 1.3] [.t bbox 1.5] [.t bbox 1.6]
} [list [list [xchar 3] [yline 1] [expr {100-3*$fixedWidth}] $fixedHeight] \
        [list [expr {[bo]+100+$fixedWidth}] [yline 1] [expr {200-(100+$fixedWidth)}] $fixedHeight] \
	[list [expr {[bo]+200}] [yline 1] $fixedWidth $fixedHeight]]
} [list [list 21 1 79 $fixedHeight] [list 107 1 93 $fixedHeight] [list 200 1 7 $fixedHeight]]

.t configure -width 40 -bd 0 -relief flat -highlightthickness 0 -padx 0 -pady 0 \
.t configure -width 40 -bd 0 -relief flat -highlightthickness 0 -padx 0 \
	-tabs {}
update
test textDisp-26.1 {AdjustForTab procedure, no tabs} {
test textDisp-26.1 {AdjustForTab procedure, no tabs} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\tbcdefghij\tc\td
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.12] 0] \
	    [lindex [.t bbox 1.14] 0]
} [list [expr {[bo]+8*$fixedWidth}] \
} [list 56 126 168]
        [expr {[bo]+2*8*$fixedWidth+2*$fixedWidth}] \
	[expr {[bo]+3*8*$fixedWidth}]]
test textDisp-26.1.2 {AdjustForTab procedure, no tabs} {
test textDisp-26.1.2 {AdjustForTab procedure, no tabs} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\tbcdefghij\tc\td
    .t configure -tabstyle wordprocessor
    set res [list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.12] 0] \
      [lindex [.t bbox 1.14] 0]]
    .t configure -tabstyle tabular
    set res
} [list [expr {[bo]+8*$fixedWidth}] \
} [list 56 168 224]
        [expr {[bo]+3*8*$fixedWidth}] \
	[expr {[bo]+4*8*$fixedWidth}]]
test textDisp-26.2 {AdjustForTab procedure, not enough tabs specified} {
    .t delete 1.0 end
    .t insert 1.0 a\tb\tc\td
    .t tag delete x
    .t tag configure x -tabs 40
    .t tag add x 1.0 end
    list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \
	    [lindex [.t bbox 1.6] 0]
} [list 40 80 120]
test textDisp-26.3 {AdjustForTab procedure, not enough tabs specified} {
    .t delete 1.0 end
    .t insert 1.0 a\tb\tc\td\te
    .t tag delete x
    .t tag configure x -tabs {40 70 right}
    .t tag add x 1.0 end
    list [lindex [.t bbox 1.2] 0] \
	    [expr {[lindex [.t bbox 1.4] 0] + [lindex [.t bbox 1.4] 2]}] \
	    [expr {[lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]}] \
	    [expr {[lindex [.t bbox 1.8] 0] + [lindex [.t bbox 1.8] 2]}]
	    [expr [lindex [.t bbox 1.4] 0] + [lindex [.t bbox 1.4] 2]] \
	    [expr [lindex [.t bbox 1.6] 0] + [lindex [.t bbox 1.6] 2]] \
	    [expr [lindex [.t bbox 1.8] 0] + [lindex [.t bbox 1.8] 2]]
} [list 40 70 100 130]
test textDisp-26.4 {AdjustForTab procedure, different alignments} {
    .t delete 1.0 end
    .t insert 1.0 a\tbc\tde\tfg\thi
    .t tag delete x
    .t tag configure x -tabs {40 center 80 left 130 right}
    .t tag add x 1.0 end
3934
3935
3936
3937
3938
3939
3940
3941

3942
3943
3944
3945
3946
3947
3948
3949
3950

3951
3952
3953
3954
3955
3956
3957
3958
3959

3960
3961
3962
3963
3964
3965
3966
3967
3968

3969
3970
3971
3972
3973
3974
3975
3976
3977

3978
3979
3980
3981
3982
3983
3984
3985
3986

3987
3988
3989
3990
3991
3992
3993
3994
3995
3996

3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010


4011
4012
4013
4014
4015
4016
4017
4018

4019
4020
4021
4022


4023
4024
4025


4026
4027
4028
4029
4030
4031
4032
4033

4034
4035
4036
4037
4038
4039
4040
4041



4042
4043
4044
4045
4046
4047
4048
4049
4050


4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061

4062
4063
4064
4065
4066

4067
4068
4069
4070

4071
4072
4073

4074
4075
4076
4077
4078
4079
4080

4081
4082
4083

4084
4085
4086
4087
4088
4089
4090

4091
4092
4093
4094

4095
4096


4097
4098
4099
4100
4101
4102
4103

4104
4105
4106
4107

4108
4109


4110
4111
4112
4113
4114
4115
4116

4117
4118
4119
4120

4121
4122


4123
4124
4125
4126
4127
4128
4129

4130
4131
4132
4133

4134
4135


4136
4137
4138
4139

4140
4141
4142

4143
4144

4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155

4156
4157
4158

4159
4160
4161
4162
4163
4164




4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176

4177
4178
4179

4180
4181
4182
4183

4184

4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201

4202
4203
4204
4205

4206
4207
4208
4209

4210
4211
4212

4213
4214

4215
4216
4217
4218

4219
4220
4221
4222
4223


4224
4225
4226
4227

4228
4229
4230
4231
4232


4233
4234
4235
4236

4237
4238
4239
4240

4241
4242
4243
4244
4245

4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261

4262
4263

4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280

4281
4282
4283
4284


4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303

4304
4305
4306
4307


4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326


4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345

4346
4347
4348
4349


4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368

4369
4370
4371
4372


4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391

4392
4393
4394
4395


4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410

4411
4412
4413
4414
4415
4416

4417
4418
4419
4420
4421
4422
4423
4424
4425


4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444

4445
4446
4447
4448
4449


4450
4451
4452
4453
4454
4455
4456
4457
4458


4459
4460

4461
4462
4463
4464


4465
4466
4467
4468
4469
4470
4471
4472
4473


4474
4475

4476
4477
4478

4479
4480
4481
4482
4483
4484
4485
4486
4487
4488

4489
4490
4491
4492
4493
4494
4495
4496



4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511

4512
4513
4514


4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530

4531
4532
4533
4534
4535

4536
4537
4538
4539
4540
4541


4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555


4556
4557
4558
4559
4560

4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575


4576
4577
4578
4579
4580
4581
4582
4583
4584

4585
4586
4587
4588
4589
4590

4591
4592
4593
4594
4595

4596
4597
4598
4599
4600
4601


4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615

4616
4617
4618
4619

4620
4621
4622

4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635

4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647

4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661

4662
4663
4664
4665
4666
4667
4668
4669
4670

4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681

4682
4683
4684
4685
4686
4687
4688
4689
4690

4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703

4704
4705
4706
4707
4708
4709
4710
4711
4712

4713
4714
4715
4716
4717
4718
4719
4720
3417
3418
3419
3420
3421
3422
3423

3424
3425
3426
3427
3428
3429
3430
3431
3432

3433
3434
3435
3436
3437
3438
3439
3440
3441

3442
3443
3444
3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3458
3459

3460
3461
3462
3463
3464
3465
3466
3467
3468

3469
3470
3471
3472
3473
3474
3475
3476
3477
3478

3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491


3492
3493
3494
3495
3496





3497
3498



3499
3500



3501
3502
3503
3504
3505





3506
3507

3508
3509
3510



3511
3512
3513
3514
3515
3516
3517
3518
3519
3520


3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532

3533
3534
3535
3536
3537

3538
3539
3540
3541

3542



3543
3544
3545
3546
3547
3548
3549

3550



3551
3552
3553
3554




3555
3556



3557


3558
3559
3560
3561
3562




3563
3564



3565


3566
3567
3568
3569
3570




3571
3572



3573


3574
3575
3576
3577
3578




3579
3580



3581


3582
3583
3584
3585
3586

3587
3588
3589

3590


3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601

3602
3603
3604

3605
3606
3607




3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622

3623
3624
3625

3626
3627
3628
3629
3630
3631

3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648

3649
3650
3651
3652

3653
3654
3655
3656

3657
3658
3659

3660


3661
3662
3663
3664

3665
3666
3667



3668
3669
3670
3671
3672

3673
3674
3675



3676
3677
3678
3679
3680

3681
3682
3683


3684
3685
3686
3687
3688

3689
3690

3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701



3702
3703

3704
3705

3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716




3717




3718
3719
3720

3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733




3734




3735
3736
3737

3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750




3751
3752
3753

3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766




3767




3768
3769
3770

3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783




3784




3785
3786
3787

3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800




3801




3802
3803
3804

3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816

3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829




3830
3831
3832

3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845




3846





3847
3848





3849
3850


3851
3852


3853




3854
3855





3856
3857


3858
3859


3860



3861
3862
3863
3864
3865
3866
3867
3868
3869
3870

3871
3872
3873
3874
3875
3876



3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893

3894



3895
3896

3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910

3911
3912
3913
3914
3915

3916
3917
3918




3919
3920

3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931


3932
3933

3934
3935
3936

3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948




3949
3950

3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964

3965
3966
3967
3968
3969

3970
3971
3972




3973
3974

3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986

3987
3988
3989
3990

3991
3992
3993

3994





3995
3996
3997
3998
3999
4000
4001

4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013

4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027

4028

4029
4030
4031
4032
4033
4034
4035

4036

4037
4038
4039
4040
4041
4042
4043
4044
4045

4046

4047
4048
4049
4050
4051
4052
4053

4054

4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065

4066

4067
4068
4069
4070
4071
4072
4073

4074

4075
4076
4077
4078
4079
4080
4081







-
+








-
+








-
+








-
+








-
+








-
+









-
+












-
-
+
+



-
-
-
-
-
+

-
-
-
+
+
-
-
-
+
+



-
-
-
-
-
+

-



-
-
-
+
+
+







-
-
+
+










-
+




-
+



-
+
-
-
-
+






-
+
-
-
-
+



-
-
-
-
+

-
-
-
+
-
-
+
+



-
-
-
-
+

-
-
-
+
-
-
+
+



-
-
-
-
+

-
-
-
+
-
-
+
+



-
-
-
-
+

-
-
-
+
-
-
+
+



-
+


-
+
-
-
+










-
+


-
+


-
-
-
-
+
+
+
+











-
+


-
+




+
-
+
















-
+



-
+



-
+


-
+
-
-
+



-
+


-
-
-
+
+



-
+


-
-
-
+
+



-
+


-
-
+




-
+

-











-
-
-
+

-
+

-











-
-
-
-
+
-
-
-
-
+
+

-













-
-
-
-
+
-
-
-
-
+
+

-













-
-
-
-
+
+

-













-
-
-
-
+
-
-
-
-
+
+

-













-
-
-
-
+
-
-
-
-
+
+

-













-
-
-
-
+
-
-
-
-
+
+

-












-
+






+





-
-
-
-
+
+

-













-
-
-
-
+
-
-
-
-
-
+
+
-
-
-
-
-


-
-
+
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-


-
-
+
+
-
-
+
-
-
-
+









-
+





-
-
-
+
+
+














-
+
-
-
-
+
+
-














-
+




-
+


-
-
-
-
+
+
-











-
-
+
+
-



-
+











-
-
-
-
+
+
-








+





-
+




-
+


-
-
-
-
+
+
-












-
+



-
+


-
+
-
-
-
-
-







-
+











-
+













-
+
-







-
+
-









-
+
-







-
+
-











-
+
-







-
+
-







    .t insert 1.0 a\t1.234
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.2
    .t tag add y 1.5
    lindex [.t bbox 1.3] 0
} 120
} {120}
test textDisp-26.6 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\t1,456.234
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.2
    lindex [.t bbox 1.7] 0
} 120
} {120}
test textDisp-26.7 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\t1.456.234,7
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.2
    lindex [.t bbox 1.11] 0
} 120
} {120}
test textDisp-26.8 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\ttest
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.2
    lindex [.t bbox 1.6] 0
} 120
} {120}
test textDisp-26.9 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\t1234
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.2
    lindex [.t bbox 1.6] 0
} 120
} {120}
test textDisp-26.10 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\t1.234567
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.5
    lindex [.t bbox 1.3] 0
} 120
} {120}
test textDisp-26.11 {AdjustForTab procedure, numeric alignment} {
    .t delete 1.0 end
    .t insert 1.0 a\tx=1.234567
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.7
    .t tag add y 1.9
    lindex [.t bbox 1.5] 0
} 120
} {120}
test textDisp-26.12 {AdjustForTab procedure, adjusting chunks} {
    .t delete 1.0 end
    .t insert 1.0 a\tx1.234567
    .t tag delete x
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    .t tag add y 1.7
    .t tag add y 1.9
    button .b -text "="
    .t window create 1.3 -window .b
    update
    lindex [.t bbox 1.5] 0
} 120
test textDisp-26.13 {AdjustForTab procedure, not enough space} {
} {120}
test textDisp-26.13 {AdjustForTab procedure, not enough space} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 "abc\txyz\tqrs\txyz\t0"
    .t tag delete x
    set t1 [expr {   $fixedWidth+3}]
    set t2 [expr { 4*$fixedWidth+2}]
    set t3 [expr { 7*$fixedWidth+1}]
    set t4 [expr {17*$fixedWidth+1}]
    .t tag configure x -tabs "$t1 $t2 center $t3 right $t4"
    .t tag configure x -tabs {10 30 center 50 right 120}
    .t tag add x 1.0 end
    set expected [list [xchar 4] [xchar 8] [xchar 12] $t4]
    set res [list [lindex [.t bbox 1.4] 0] [lindex [.t bbox 1.8] 0] \
            [lindex [.t bbox 1.12] 0] [lindex [.t bbox 1.16] 0]]
    list [lindex [.t bbox 1.4] 0] [lindex [.t bbox 1.8] 0] \
	    [lindex [.t bbox 1.12] 0] [lindex [.t bbox 1.16] 0]
    lequal $res $expected
} {1}
test textDisp-26.13.2 {AdjustForTab procedure, not enough space} {
} [list 28 56 84 120]
test textDisp-26.13.2 {AdjustForTab procedure, not enough space} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 "abc\txyz\tqrs\txyz\t0"
    .t tag delete x
    set t1 [expr {   $fixedWidth+3}]
    set t2 [expr { 4*$fixedWidth+2}]
    set t3 [expr { 7*$fixedWidth+1}]
    set t4 [expr {17*$fixedWidth+1}]
    .t tag configure x -tabs "$t1 $t2 center $t3 right $t4" -tabstyle wordprocessor
    .t tag configure x -tabs {10 30 center 50 right 120} -tabstyle wordprocessor
    .t tag add x 1.0 end
    set expected [list [xchar 4] [xchar 8] $t4 [expr {$t4+($t4-$t3)}]]
    set res [list [lindex [.t bbox 1.4] 0] [lindex [.t bbox 1.8] 0] \
      [lindex [.t bbox 1.12] 0] [lindex [.t bbox 1.16] 0]]
    .t tag configure x -tabstyle tabular
    lequal $res $expected
} {1}
test textDisp-26.14 {AdjustForTab procedure, not enough space} {
    set res
} [list 28 56 120 190]
test textDisp-26.14 {AdjustForTab procedure, not enough space} {textfonts} {
    .t delete 1.0 end
    .t insert end "a \tb \tc \td \te \tf \tg\n"
    .t insert end "Watch the \tX and the \t\t\tY\n"
    .t tag configure moop -tabs [expr {8*$fixedWidth}]
    .t insert end "Watch the \tX and the \t\t\tY\n" moop
    list [lindex [.t bbox 2.11] 0] [lindex [.t bbox 2.24] 0] \
	    [lindex [.t bbox 3.11] 0] [lindex [.t bbox 3.24] 0]
} [list [xchar 11] [xchar 32] [xchar 11] [xchar 32]]
test textDisp-26.14.2 {AdjustForTab procedure, not enough space} {
} [list 77 224 77 224]
test textDisp-26.14.2 {AdjustForTab procedure, not enough space} {textfonts} {
    .t delete 1.0 end
    .t configure -tabstyle wordprocessor
    .t insert end "a \tb \tc \td \te \tf \tg\n"
    .t insert end "Watch the \tX and the \t\t\tY\n"
    .t tag configure moop -tabs [expr {8*$fixedWidth}]
    .t insert end "Watch the \tX and the \t\t\tY\n" moop
    set res [list [lindex [.t bbox 2.11] 0] [lindex [.t bbox 2.24] 0] \
      [lindex [.t bbox 3.11] 0] [lindex [.t bbox 3.24] 0]]
    .t configure -tabstyle tabular
    set res
} [list [xchar 16] [xchar 8] [xchar 16] [xchar 8]]
} [list 112 56 112 56]

.t configure -width 20 -bd 2 -highlightthickness 2 -relief sunken -tabs {} \
	-wrap char
update
test textDisp-27.1 {SizeOfTab procedure, old-style tabs} {
test textDisp-27.1 {SizeOfTab procedure, old-style tabs} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\tbcdefghij\tc\td
    list [.t bbox 1.2] [.t bbox 1.10] [.t bbox 1.12]
} [list [list [xchar 8] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 60 5 7 $fixedHeight] [list 116 5 7 $fixedHeight] [list 130 5 7 $fixedHeight]]
        [list [xchar [expr {8+8}]] [yline 1] $fixedWidth $fixedHeight] \
	[list [xchar [expr {8+8+1+1}]] [yline 1] $fixedWidth $fixedHeight]]
test textDisp-27.1.1 {SizeOfTab procedure, old-style tabs} {
test textDisp-27.1.1 {SizeOfTab procedure, old-style tabs} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\tbcdefghij\tc\td
    .t configure -tabstyle wordprocessor
    set res [list [.t bbox 1.2] [.t bbox 1.10] [.t bbox 1.12]]
    .t configure -tabstyle tabular
    set res
} [list [list [xchar 8] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 60 5 7 $fixedHeight] [list 116 5 7 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar [expr {8+8}]] [yline 1] $fixedWidth $fixedHeight] \
	[list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-27.2 {SizeOfTab procedure, choosing tabX and alignment} {
test textDisp-27.2 {SizeOfTab procedure, choosing tabX and alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\tbcd
    .t tag delete x
    # compute a tab width such that the first display line is just not large enough
    # to show the last char 'd', which then wraps on display line 2
    set tw [expr {(20-2)*$fixedWidth-($fixedWidth-1)}]
    .t tag configure x -tabs $tw
    .t tag configure x -tabs 120
    .t tag add x 1.0 end
    set expected [list [list [expr {[bo]+$tw+[xw 1]}] [yline 1] [expr {[winfo width .t]-([bo]+$tw+[xw 1])-[bo]}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.3] [.t bbox 1.4]] $expected
    list [.t bbox 1.3] [.t bbox 1.4]
} {1}
test textDisp-27.3 {SizeOfTab procedure, choosing tabX and alignment} {
} [list [list 131 5 13 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.3 {SizeOfTab procedure, choosing tabX and alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\t\t\tbcd
    .t tag delete x
    # compute a tab width such that the first display line is just not large enough
    # to show the last char 'd', which then wraps on display line 2
    set tw [expr {int(ceil(((20-2)*$fixedWidth-($fixedWidth-1))/3.0))}]
    .t tag configure x -tabs $tw
    .t tag configure x -tabs 40
    .t tag add x 1.0 end
    set expected [list [list [expr {[bo]+3*$tw+[xw 1]}] [yline 1] [expr {[winfo width .t]-([bo]+3*$tw+[xw 1])-[bo]}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.5] [.t bbox 1.6]] $expected
    list [.t bbox 1.5] [.t bbox 1.6]
} {1}
test textDisp-27.4 {SizeOfTab procedure, choosing tabX and alignment} {
} [list [list 131 5 13 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.4 {SizeOfTab procedure, choosing tabX and alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\t\t\tbcd
    .t tag delete x
    # compute a tab width such that the first display line is just not large enough
    # to show the last char 'd', which then wraps on display line 2
    set tw [expr {int(ceil(((20-2)*$fixedWidth-($fixedWidth-1) + 20)/2.0))}]
    .t tag configure x -tabs "20 center $tw left"
    .t tag configure x -tabs {20 center 70 left}
    .t tag add x 1.0 end
    set expected [list [list [expr {[bo]+$tw+($tw-20)+[xw 1]}] [yline 1] [expr {[winfo width .t]-([bo]+$tw+($tw-20)+[xw 1])-[bo]}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.5] [.t bbox 1.6]] $expected
    list [.t bbox 1.5] [.t bbox 1.6]
} {1}
test textDisp-27.5 {SizeOfTab procedure, center alignment} {
} [list [list 131 5 13 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.5 {SizeOfTab procedure, center alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\txyzzyabc
    .t tag delete x
    # compute a tab width such that the last y on the first display line is the last displayed char
    # while 'xyzzyabc' is centered at the tab stop; the 'abc" part of the line wraps on display line 2
    set tw [expr {[winfo width .t]-2*[bo]-3*$fixedWidth+1}]
    .t tag configure x -tabs "$tw center"
    .t tag configure x -tabs {120 center}
    .t tag add x 1.0 end
    set expected [list [list [expr {[bo]+$tw+round(1.5*$fixedWidth)}] [yline 1] [expr {[winfo width .t]-([bo]+$tw+round(1.5*$fixedWidth))-[bo]}] $fixedHeight] \
                       [list [xchar 0] [yline 2] $fixedWidth $fixedHeight]]
    lequal [list [.t bbox 1.6] [.t bbox 1.7]] $expected
    list [.t bbox 1.6] [.t bbox 1.7]
} {1}
test textDisp-27.6 {SizeOfTab procedure, center alignment} {
} [list [list 135 5 9 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.6 {SizeOfTab procedure, center alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\txyzzyabc
    .t tag delete x
    .t tag configure x -tabs "[expr {round(21.4*$fixedWidth)}] center"
    .t tag configure x -tabs {150 center}
    .t tag add x 1.0 end
    list [.t bbox 1.6] [.t bbox 1.7]
} [list [list [xchar 4] [yline 2] $fixedWidth $fixedHeight] \
} [list [list 32 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 39 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [xchar 5] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-27.7 {SizeOfTab procedure, center alignment, wrap -none (potential numerical problems)} {
test textDisp-27.7 {SizeOfTab procedure, center alignment, wrap -none (potential numerical problems)} {textfonts} {
    .t delete 1.0 end
    set cm [winfo fpixels .t 1c]
    .t configure -tabs {1c 2c center 3c 4c 5c 6c 7c 8c} -wrap none -width 40
    .t insert 1.0 a\tb\tc\td\te\n012345678934567890a\tbb\tcc\tdd
    set width [expr {$fixedWidth * 19}]
    set tab $cm
    while {$tab < $width} {
	set tab [expr {$tab + $cm}]
    }
    # Now we've calculated to the end of the tab after 'a', add one
    # more for 'bb\t' and we're there, with some pixels for the border.  Since
    # more for 'bb\t' and we're there, with 4 for the border.  Since
    # Tk_GetPixelsFromObj uses the standard 'int(0.5 + float)' rounding,
    # so must we.
    set tab [expr {[bo] + int(0.5 + $tab + $cm)}]
    set tab [expr {4 + int(0.5 + $tab + $cm)}]
    update
    set res [.t bbox 2.23]
    set expected [list [expr {[xchar 23]-$tab}] [yline 2] $fixedWidth $fixedHeight]
    lequal [lset res 0 [expr {[lindex $res 0] - $tab}]] $expected
} {1}
test textDisp-27.7.1 {SizeOfTab procedure, center alignment, wrap -none (potential numerical problems)} {
    lset res 0 [expr {[lindex $res 0] - $tab}]
    set res
} [list -28 [expr {$fixedDiff + 18}] 7 $fixedHeight]
test textDisp-27.7.1 {SizeOfTab procedure, center alignment, wrap -none (potential numerical problems)} {textfonts} {
    .t delete 1.0 end
    .t configure -tabstyle wordprocessor
    set cm [winfo fpixels .t 1c]
    .t configure -tabs {1c 2c center 3c 4c 5c 6c 7c 8c} -wrap none -width 40
    .t insert 1.0 a\tb\tc\td\te\n012345678934567890a\tbb\tcc\tdd
    set width [expr {$fixedWidth * 19}]
    set tab $cm
    while {$tab < $width} {
	set tab [expr {$tab + $cm}]
    }
    # Now we've calculated to the end of the tab after 'a', add one
    # more for 'bb\t' and we're there, with some pixels for the border.  Since
    # more for 'bb\t' and we're there, with 4 for the border.  Since
    # Tk_GetPixelsFromObj uses the standard 'int(0.5 + float)' rounding,
    # so must we.
    set tab [expr {[bo] + int(0.5 + $tab + $cm)}]
    set tab [expr {4 + int(0.5 + $tab + $cm)}]
    update
    set res [.t bbox 2.23]
    .t configure -tabstyle tabular
    lset res 0 [expr {[lindex $res 0] - $tab}]
    set res
} [list 0 [yline 2] $fixedWidth $fixedHeight]
} [list 0 [expr {$fixedDiff + 18}] 7 $fixedHeight]
test textDisp-27.7.2 {SizeOfTab procedure, fractional tab interpolation problem} {
    .t delete 1.0 end
    set interpolatetab {1c 2c}
    set precisetab {}
    for {set i 1} {$i < 20} {incr i} {
	lappend precisetab "${i}c"
    }
    .t configure -tabs $interpolatetab -wrap none -width 150
    .t insert 1.0 [string repeat "a\t" 20]
    update
    set res [.t bbox 1.20]
    # Now, Tk's interpolated tabs should be the same as
    # non-interpolated.
    .t configure -tabs $precisetab
    update
    expr {[lindex $res 0] - [lindex [.t bbox 1.20] 0]}
} 0
} {0}

.t configure -wrap char -tabs {} -width 20
update
test textDisp-27.8 {SizeOfTab procedure, right alignment} {
test textDisp-27.8 {SizeOfTab procedure, right alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\t\txyzzyabc
    .t tag delete x
    .t tag configure x -tabs "[expr {14.3*$fixedWidth}] left [expr {[.t cget -width]*$fixedWidth}] right"
    .t tag configure x -tabs {100 left 140 right}
    .t tag add x 1.0 end
    list [.t bbox 1.6] [.t bbox 1.7]
} [list [list [xcharr 1] [yline 1] $fixedWidth $fixedHeight] \
} [list [list 137 5 7 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
        [list [bo] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-27.9 {SizeOfTab procedure, left alignment} {
test textDisp-27.9 {SizeOfTab procedure, left alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\txyzzyabc
    .t tag delete x
    .t tag configure x -tabs "[expr {17.14*$fixedWidth}]"
    .t tag configure x -tabs {120}
    .t tag add x 1.0 end
    list [.t bbox 1.3] [.t bbox 1.4]
} [list [list [expr {round([bo]+17.14*$fixedWidth+$fixedWidth)}] [yline 1] [expr {[winfo width .t]-round([bo]+17.14*$fixedWidth+$fixedWidth)-[bo]}] $fixedHeight] \
        [list [bo] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-27.10 {SizeOfTab procedure, numeric alignment} {
} [list [list 131 5 13 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.10 {SizeOfTab procedure, numeric alignment} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 a\t123.4
    .t tag delete x
    .t tag configure x -tabs "[expr {17.14*$fixedWidth}] numeric"
    .t tag configure x -tabs {120 numeric}
    .t tag add x 1.0 end
    list [.t bbox 1.3] [.t bbox 1.4]
} [list [list [expr {round([bo]+17.14*$fixedWidth-$fixedWidth)}] [yline 1] [expr {[winfo width .t]-round([bo]+17.14*$fixedWidth-$fixedWidth)-[bo]}] $fixedHeight] \
        [list [bo] [yline 2] $fixedWidth $fixedHeight]]
test textDisp-27.11 {SizeOfTab procedure, making tabs at least as wide as a space} {
} [list [list 117 5 27 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]
test textDisp-27.11 {SizeOfTab procedure, making tabs at least as wide as a space} {textfonts} {
    .t delete 1.0 end
    .t insert 1.0 abc\tdefghijklmnopqrst
    .t tag delete x
    .t tag configure x -tabs "[expr {17.14*$fixedWidth}]"
    .t tag configure x -tabs {120}
    .t tag add x 1.0 end
    list [.t bbox 1.5] [.t bbox 1.6]
} [list [list [expr {round([bo]+17.14*$fixedWidth+$fixedWidth)}] [yline 1] [expr {[winfo width .t]-round([bo]+17.14*$fixedWidth+$fixedWidth)-[bo]}] $fixedHeight] \
        [list [bo] [yline 2] $fixedWidth $fixedHeight]]
} [list [list 131 5 13 $fixedHeight] [list 4 [expr {$fixedDiff + 18}] 7 $fixedHeight]]

proc bizarre_scroll args {
    .t2.t delete 5.0 end
}
test textDisp-28.1 {"yview" option with bizarre scroll command} -setup {
test textDisp-28.1 {"yview" option with bizarre scroll command} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    text .t2.t -width 40 -height 4
    .t2.t insert end "1\n2\n3\n4\n5\n6\n7\n8\n"
    pack .t2.t
    wm geometry .t2 +0+0
    update
    .t2.t configure -yscrollcommand bizarre_scroll
    .t2.t yview 100.0
    set result [.t2.t index @0,0]
    update
    lappend result [.t2.t index @0,0]
} -cleanup {
    destroy .t2
} -result {6.0 1.0}
} {6.0 1.0}

test textDisp-29.1 {miscellaneous: lines wrap but are still too long} -setup {
test textDisp-29.1 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    set expected [list [list 0.0 [expr {20.0*$fixedWidth/300}]] \
                       300x50+[bo .t2.t]+[yline 2 .t2.t] \
	               [list [xchar 1 .t2.t] [expr {[yline 2 .t2.t]+50}] $fixedWidth $fixedHeight]]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-29.2 {miscellaneous: lines wrap but are still too long} -setup {
} [list [list 0.0 [expr {20.0*$fixedWidth/300}]] 300x50+[expr {$twbw + $twht + 1}]+[expr {$twbw + $twht + $fixedHeight + 1}] [list [expr {$twbw + $twht + $fixedWidth + 1}] [expr {$twbw + $twht + $fixedHeight + 50 + 1}] $fixedWidth $fixedHeight]]
test textDisp-29.2 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    .t2.t xview scroll 1 unit
    update
    set expected [list [list [expr {1.0*$fixedWidth/300}] [expr {21.0*$fixedWidth/300}]] \
                       300x50+[expr {[bo .t2.t]-$fixedWidth}]+[yline 2 .t2.t] \
	               [list [expr {[bo .t2.t]-$fixedWidth+$fixedWidth}] [expr {[yline 2 .t2.t]+50}] $fixedWidth $fixedHeight]]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-29.2.1 {miscellaneous: lines wrap but are still too long} -setup {
} [list [list [expr {1.0*$fixedWidth/300}] [expr {21.0*$fixedWidth/300}]] 300x50+[expr {$twbw + $twht + 1 - $fixedWidth}]+[expr {$twbw + $twht + $fixedHeight + 1}] [list [expr {$twbw + $twht + $fixedWidth + 1 - $fixedWidth}] [expr {$twbw + $twht + $fixedHeight + 50 + 1}] $fixedWidth $fixedHeight]]
test textDisp-29.2.1 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap none -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 1\n
    .t2.t insert end [string repeat "abc" 30]
    update
    .t2.t xview scroll 5 unit
    update
    .t2.t xview
} -cleanup {
    destroy .t2
} -result [list [expr {5.0/90}] [expr {25.0/90}]]
test textDisp-29.2.2 {miscellaneous: lines wrap but are still too long} -setup {
} [list [expr {5.0/90}] [expr {25.0/90}]]
test textDisp-29.2.2 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    .t2.t xview scroll 2 unit
    update
    set expected [list [list [expr {2.0*$fixedWidth/300}] [expr {22.0*$fixedWidth/300}]] \
                       300x50+[expr {[bo .t2.t]-2*$fixedWidth}]+[yline 2 .t2.t] \
	               {}]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-29.2.3 {miscellaneous: lines wrap but are still too long} -setup {
} [list [list [expr {2.0*$fixedWidth/300}] [expr {22.0*$fixedWidth/300}]] 300x50+[expr {$twbw + $twht + 1 - 2*$fixedWidth}]+[expr {$twbw + $twht + $fixedHeight + 1}] {}]
test textDisp-29.2.3 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    .t2.t xview scroll 7 pixels
    update
    set expected [list [list [expr {7.0/300}] [expr {(20.0*$fixedWidth+7)/300}]] \
                       300x50+[expr {[bo .t2.t]-7}]+[yline 2 .t2.t] \
	               [list [expr {[bo .t2.t]+$fixedWidth-7}] [expr {[yline 2 .t2.t]+50}] $fixedWidth $fixedHeight]]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-29.2.4 {miscellaneous: lines wrap but are still too long} -setup {
} [list [list [expr {7.0/300}] [expr {(20.0*$fixedWidth + 7)/300}]] 300x50+[expr {$twbw + $twht + 1 - 7}]+[expr {$twbw + $twht + $fixedHeight + 1}] [list [expr {$twbw + $twht + $fixedWidth + 1 - 7}] [expr {$twbw + $twht + $fixedHeight + 50 + 1}] $fixedWidth $fixedHeight]]
test textDisp-29.2.4 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    .t2.t xview scroll 17 pixels
    update
    set expected [list [list [expr {17.0/300}] [expr {(20.0*$fixedWidth+17)/300}]] \
                       300x50+[expr {[bo .t2.t]-17}]+[yline 2 .t2.t] \
	               {}]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-29.2.5 {miscellaneous: can show last character} -setup {
} [list [list [expr {17.0/300}] [expr {(20.0*$fixedWidth + 17)/300}]] 300x50+[expr {$twbw + $twht + 1 - 17}]+[expr {$twbw + $twht + $fixedHeight + 1}] {}]
test textDisp-29.2.5 {miscellaneous: can show last character} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 121x141+200+200
    text .t2.t -width 5 -height 5 -font {Arial 10} \
      -wrap none -xscrollcommand ".t2.s set" \
      -bd 2 -highlightthickness 0 -padx 1
    .t2.t insert end "WWWWWWWWWWWWi"
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    grid .t2.t -row 0 -column 0 -sticky nsew
    grid .t2.s -row 1 -column 0 -sticky ew
    grid columnconfigure .t2 0 -weight 1
    grid rowconfigure .t2 0 -weight 1
    grid rowconfigure .t2 1 -weight 0
    update
    update ; update
    set xv [.t2.t xview]
    set xd [expr {[lindex $xv 1] - [lindex $xv 0]}]
    .t2.t xview moveto [expr {1.0-$xd}]
    set iWidth [lindex [.t2.t bbox end-2c] 2]
    .t2.t xview scroll 2 units
    set iWidth2 [lindex [.t2.t bbox end-2c] 2]

    if {($iWidth == $iWidth2) && $iWidth >= 2} {
	set result "correct"
    } else {
	set result "last character is not completely visible when it should be"
    }
} -cleanup {
    destroy .t2
} -result {correct}
test textDisp-29.3 {miscellaneous: lines wrap but are still too long} -setup {
} {correct}
test textDisp-29.3 {miscellaneous: lines wrap but are still too long} {textfonts} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    wm geometry .t2 +0+0
    text .t2.t -width 20 -height 10 -font $fixedFont \
	    -wrap char -xscrollcommand ".t2.s set"
    pack .t2.t -side top
    scrollbar .t2.s -orient horizontal -command ".t2.t xview"
    pack .t2.s -side bottom -fill x
    .t2.t insert end 123
    frame .t2.t.f -width 300 -height 50 -bd 2 -relief raised
    .t2.t window create 1.1 -window .t2.t.f
    update
    .t2.t xview scroll 200 units
    update
    set expected [list [list [expr {double(300-20*$fixedWidth)/300}] 1.0] \
                       300x50+[expr {-(300-20*$fixedWidth-[bo .t2.t])}]+[yline 2 .t2.t] \
	               {}]
    lequal [list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]] $expected
    list [.t2.t xview] [winfo geom .t2.t.f] [.t2.t bbox 1.3]
} -cleanup {
    destroy .t2
} -result {1}

test textDisp-30.1 {elided text joining multiple logical lines} -setup {
} [list [list [expr {16.0/30}] 1.0] 300x50+-155+[expr {$fixedDiff + 18}] {}]
test textDisp-30.1 {elidden text joining multiple logical lines} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    text .t2.t -width 20 -height 10 -font $fixedFont
    pack .t2.t -side top
    .t2.t delete 1.0 end
    .t2.t insert 1.0 "1111\n2222\n3333"
    .t2.t tag configure elided -elide 1 -background red
    .t2.t tag add elided 1.2 3.2
    .t2.t tag configure elidden -elide 1 -background red
    .t2.t tag add elidden 1.2 3.2
    update
    .t2.t count -update -displaylines 1.0 end
    .t2.t count -displaylines 1.0 end
} -cleanup {
    destroy .t2
} -result {1}
test textDisp-30.2 {elided text joining multiple logical lines} -setup {
} {1}
test textDisp-30.2 {elidden text joining multiple logical lines} {
    catch {destroy .t2}
} -body {
    toplevel .t2
    text .t2.t -width 20 -height 10 -font $fixedFont
    pack .t2.t -side top
    .t2.t delete 1.0 end
    .t2.t insert 1.0 "1111\n2222\n3333"
    .t2.t tag configure elided -elide 1 -background red
    .t2.t tag add elided 1.2 2.2
    .t2.t tag configure elidden -elide 1 -background red
    .t2.t tag add elidden 1.2 2.2
    update
    .t2.t count -update -displaylines 1.0 end
    .t2.t count -displaylines 1.0 end
} -cleanup {
    destroy .t2
} -result {2}
} {2}
catch {destroy .t2}

.t configure -height 1
update

test textDisp-31.1 {line embedded window height update} {
    set res {}
    .t delete 1.0 end
    .t insert end "abcd\nefgh\nijkl\nmnop\nqrst\nuvwx\nyx"
    frame .t.f -background red -width 50 -height 100
    frame .t.f -background red -width 100 -height 100
    .t window create 3.0 -window .t.f
    lappend res [.t count -update -ypixels 1.0 end]
    .t.f configure -height 10
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
} [list [expr {100+$fixedHeight*6}] \
        [expr {100+$fixedHeight*6}] \
	[expr {$fixedHeight*7}]]
    set res
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 6}] [expr {$fixedHeight * 7}]]

test textDisp-31.2 {line update index shifting} {
    set res {}
    .t.f configure -height 100
    update
    lappend res [.t count -update -ypixels 1.0 end]
    .t.f configure -height 10
    .t insert 1.0 "abc\n"
    .t insert 1.0 "abc\n"
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
    .t.f configure -height 100
    .t delete 1.0 3.0
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
} [list [expr {100+$fixedHeight*6}] \
    set res
        [expr {100+$fixedHeight*8}] \
	[expr {$fixedHeight*9}] \
	[expr {$fixedHeight*7}] \
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 8}] [expr {$fixedHeight * 9}] [expr {$fixedHeight * 7}] [expr {100 + $fixedHeight * 6}]]

	[expr {100+$fixedHeight*6}]]
test textDisp-31.3 {line update index shifting} {
    # Should do exactly the same as the above, as long
    # as we are correctly tagging the correct lines for
    # recalculation.  The 'update' and 'delay' must be
    # long enough to ensure all asynchronous updates
    # have been performed.
    set res {}
    .t.f configure -height 100
    update
    lappend res [.t count -update -ypixels 1.0 end]
    .t.f configure -height 10
    .t insert 1.0 "abc\n"
    .t insert 1.0 "abc\n"
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    .t.f configure -height 100
    .t delete 1.0 3.0
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    set res
} [list [expr {100+$fixedHeight*6}] \
        [expr {100+$fixedHeight*8}] \
	[expr {$fixedHeight*9}] \
	[expr {$fixedHeight*7}] \
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 8}] [expr {$fixedHeight * 9}] [expr {$fixedHeight * 7}] [expr {100 + $fixedHeight * 6}]]

	[expr {100+$fixedHeight*6}]]
test textDisp-31.4 {line embedded image height update} {
    set res {}
    image create photo textest -height 100 -width 10
    .t delete 3.0
    .t image create 3.0 -image textest
    update
    lappend res [.t count -update -ypixels 1.0 end]
    textest configure -height 10
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
    set res
} [list [expr {100+$fixedHeight*6}] \
        [expr {100+$fixedHeight*6}] \
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 6}] [expr {$fixedHeight * 7}]]

	[expr {$fixedHeight*7}]]
test textDisp-31.5 {line update index shifting} {
    set res {}
    textest configure -height 100
    update
    update ; after 1000 ; update
    lappend res [.t count -update -ypixels 1.0 end]
    textest configure -height 10
    .t insert 1.0 "abc\n"
    .t insert 1.0 "abc\n"
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
    textest configure -height 100
    .t delete 1.0 3.0
    lappend res [.t count -ypixels 1.0 end]
    lappend res [.t count -update -ypixels 1.0 end]
    set res
} [list [expr {100+$fixedHeight*6}] \
        [expr {100+$fixedHeight*8}] \
	[expr {$fixedHeight*9}] \
	[expr {$fixedHeight*7}] \
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 8}] [expr {$fixedHeight * 9}] [expr {$fixedHeight * 7}] [expr {100 + $fixedHeight * 6}]]

	[expr {100+$fixedHeight*6}]]
test textDisp-31.6 {line update index shifting} {
    # Should do exactly the same as the above, as long
    # as we are correctly tagging the correct lines for
    # recalculation.  The 'update' and 'delay' must be
    # long enough to ensure all asynchronous updates
    # have been performed.
    set res {}
    textest configure -height 100
    update ; after 1000 ; update
    lappend res [.t count -update -ypixels 1.0 end]
    textest configure -height 10
    .t insert 1.0 "abc\n"
    .t insert 1.0 "abc\n"
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    textest configure -height 100
    .t delete 1.0 3.0
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    set res
} [list [expr {100+$fixedHeight*6}] \
        [expr {100+$fixedHeight*8}] \
	[expr {$fixedHeight*9}] \
	[expr {$fixedHeight*7}] \
} [list [expr {100 + $fixedHeight * 6}] [expr {100 + $fixedHeight * 8}] [expr {$fixedHeight * 9}] [expr {$fixedHeight * 7}] [expr {100 + $fixedHeight * 6}]]

	[expr {100+$fixedHeight*6}]]
test textDisp-31.7 {line update index shifting, elided} {
    # The 'update' and 'delay' must be long enough to ensure all
    # asynchronous updates have been performed.
    set res {}
    .t delete 1.0 end
    lappend res [.t count -update -ypixels 1.0 end]
    .t insert 1.0 "abc\nabc"
    .t insert 1.0 "abc\n"
    lappend res [.t count -update -ypixels 1.0 end]
    .t tag configure elide -elide 1
    .t tag add elide 1.3 2.1
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    .t delete 1.0 3.0
    lappend res [.t count -ypixels 1.0 end]
    delay
    update ; after 1000 ; update
    lappend res [.t count -ypixels 1.0 end]
    set res
} [list [expr {$fixedHeight*1}] \
} [list [expr {$fixedHeight * 1}] [expr {$fixedHeight * 3}] [expr {$fixedHeight * 3}] [expr {$fixedHeight * 2}] [expr {$fixedHeight * 1}] [expr {$fixedHeight * 1}]]
        [expr {$fixedHeight*3}] \
	[expr {$fixedHeight*3}] \
	[expr {$fixedHeight*2}] \
	[expr {$fixedHeight*1}] \
	[expr {$fixedHeight*1}]]

test textDisp-32.0 {everything elided} {
    # Must not crash
    pack [text .tt]
    .tt insert 0.0 HELLO
    .tt tag configure HIDE -elide 1
    .tt tag add HIDE 0.0 end
    update
    update ; update ; update ; update
    destroy .tt
} {}
test textDisp-32.1 {everything elided} {
    # Must not crash
    pack [text .tt]
    update
    .tt insert 0.0 HELLO
    update
    .tt tag configure HIDE -elide 1
    update
    .tt tag add HIDE 0.0 end
    update
    update ; update ; update ; update
    destroy .tt
} {}
test textDisp-32.2 {elide and tags} {
    pack [text .tt -height 30 -width 100 -bd 0 \
      -highlightthickness 0 -padx 0]
    .tt insert end \
      {test text using tags 1 and 3 } \
      {testtag1 testtag3} \
      {[this bit here uses tags 2 and 3]} \
      {testtag2 testtag3}
    update
    # indent left margin of tag 1 by 20 pixels
    # text should be indented
    .tt tag configure testtag1 -lmargin1 20
    .tt tag configure testtag1 -lmargin1 20 ; update
    update
    #1
    set res {}
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    # hide tag 1, remaining text should not be indented, since
    # the indented tag and character is hidden.
    .tt tag configure testtag1 -elide 1
    .tt tag configure testtag1 -elide 1 ; update
    update
    #2
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    # reset
    .tt tag configure testtag1 -lmargin1 0
    .tt tag configure testtag1 -elide 0
    # indent left margin of tag 2 by 20 pixels
    # text should not be indented, since tag1 has lmargin1 of 0.
    .tt tag configure testtag2 -lmargin1 20
    .tt tag configure testtag2 -lmargin1 20 ; update
    update
    #3
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    # hide tag 1, remaining text should now be indented, but
    # the bbox of 1.0 should have zero width and zero indent,
    # since it is elided at that position.
    .tt tag configure testtag1 -elide 1
    .tt tag configure testtag1 -elide 1 ; update
    update
    #4
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    # reset
    .tt tag configure testtag2 -lmargin1 {}
    .tt tag configure testtag1 -elide 0
    # indent left margin of tag 3 by 20 pixels
    # text should be indented, since this tag takes
    # precedence over testtag1, and is applied to the
    # start of the text.
    .tt tag configure testtag3 -lmargin1 20
    .tt tag configure testtag3 -lmargin1 20 ; update
    update
    #5
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    # hide tag 1, remaining text should still be indented,
    # since it still has testtag3 on it.  Again the
    # bbox of 1.0 should have 0.
    .tt tag configure testtag1 -elide 1
    .tt tag configure testtag1 -elide 1 ; update
    update
    #6
    lappend res [list [.tt index "1.0 + 0 displaychars"] \
      [lindex [.tt bbox 1.0] 0] \
      [lindex [.tt bbox "1.0 + 0 displaychars"] 0]]
    .tt tag configure testtag3 -lmargin1 {} -elide 0
    .tt tag configure testtag1 -elide 1 -lmargin1 20
    #7
4744
4745
4746
4747
4748
4749
4750
4751

4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775

4776
4777
4778
4779
4780
4781
4782
4783
4784

4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802


4803
4804

4805
4806
4807

4808
4809
4810

4811
4812

4813
4814

4815
4816
4817


4818
4819

4820
4821
4822
4823
4824
4825
4826
4827

4828
4829
4830
4831
4832
4833
4834
4105
4106
4107
4108
4109
4110
4111

4112
4113
4114
4115
4116














4117
4118
4119

4120

4121
4122
4123
4124
4125
4126
4127

4128

4129
4130

4131
4132
4133
4134
4135
4136
4137
4138
4139
4140

4141

4142


4143
4144
4145

4146
4147
4148
4149
4150
4151
4152

4153

4154
4155
4156

4157
4158
4159
4160
4161
4162
4163

4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180







-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-



-

-
+






-

-
+

-










-

-

-
-
+
+

-
+



+


-
+
-

+

-
+



+
+

-
+








+







    .tt tag configure emoticon -elide 1
    .tt insert end X
    .tt mark set MSGLEFT "end - 1 char"
    .tt mark gravity MSGLEFT left
    .tt insert end ":)" emoticon
    .tt image create end -image $img
    pack .tt
    update
    update; update; update
} -cleanup {
    image delete $img
    destroy .tt
}
test textDisp-32.4 {Button-1 click with elided lines - Bug 18371b7ce7} -setup {
    pack [text .tt -borderwidth 0 -highlightthickness 0]
    for {set n 1} {$n <= 5} {incr n} {
	.tt insert end "Line $n\n"
    }
    .tt tag configure Elided -elide 1
    .tt tag add Elided 1.2 4.0
    update
} -body {
    event generate .tt <Button-1> -x 1 -y 1
    .tt index insert
} -cleanup {
    destroy .tt
} -result {1.0}

test textDisp-33.0 {one line longer than fits in the widget} {
    pack [text .tt -wrap char]
    update
    .tt insert 1.0 [string repeat "more wrap + " 300]
    update
    update ; update ; update
    .tt see 1.0
    lindex [.tt yview] 0
} {0.0}
test textDisp-33.1 {one line longer than fits in the widget} {
    destroy .tt
    pack [text .tt -wrap char]
    update
    .tt insert 1.0 [string repeat "more wrap + " 300]
    update
    update ; update ; update
    .tt yview "1.0 +1 displaylines"
    update
    if {[lindex [.tt yview] 0] > 0.1} {
	set result "window should be scrolled to the top"
    } else {
	set result "ok"
    }
} {ok}
test textDisp-33.2 {one line longer than fits in the widget} {
    destroy .tt
    pack [text .tt -wrap char]
    .tt debug 1
    update
    set tk_textHeightCalc ""
    set timer [after 200 lappend tk_textHeightCalc "Timed out"]
    .tt insert 1.0 [string repeat "more wrap + " 1]
    vwait tk_textHeightCalc
    after cancel $timer
    after 100 ; update idletasks
    # Nothing should have been recalculated.
    set tk_textHeightCalc
} {1.0}
} {}
test textDisp-33.3 {one line longer than fits in the widget} {
    destroy .tt
    pack [text .tt -wrap char]
    .tt debug 1
    set tk_textHeightCalc ""
    .tt insert 1.0 [string repeat "more wrap + " 300]
    update
    update ; .tt count -update -ypixels 1.0 end ; update
    .tt sync
    # Each line should have been recalculated just once
    .tt debug 0
    expr {[llength $tk_textHeightCalc] == [.tt count -displaylines 1.0 end]}
} 1
} {1}
test textDisp-33.4 {one line longer than fits in the widget} {
    destroy .tt
    pack [text .tt -wrap char]
    .tt debug 1
    set tk_textHeightCalc ""
    .tt insert 1.0 [string repeat "more wrap + " 300]
    update
    update ; update ; update
    set idx [.tt index "1.0 + 1 displaylines"]
    .tt yview $idx
    if {[lindex [.tt yview] 0] > 0.1} {
	set result "window should be scrolled to the top"
    } else {
	set result "ok"
    }
    set idx [.tt index "1.0 + 1 displaylines"]
    .tt debug 0
    set result
} {ok}
destroy .tt
test textDisp-33.5 {bold or italic fonts} win {
    destroy .tt
    pack [text .tt -wrap char -font {{MS Sans Serif} 15}]
    font create no -family [lindex [.tt cget -font] 0] -size 24
4857
4858
4859
4860
4861
4862
4863

4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881

4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227

4228
4229
4230
4231





4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242

4243
4244
4245
















4246
4247
4248
4249
4250
4251







+

















-
+



-
-
-
-
-











-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






    set txt ""
    for {set i 1} {$i < 100} {incr i} {
        append txt "Line $i\n"
    }
    set result {}
} -body {
    .t1 insert end $txt
    .t1 debug 1
    set ge [winfo geometry .]
    scan $ge "%dx%d+%d+%d" width height left top
    update
    .t1 sync
    set negative 0
    bind .t1 <<WidgetViewSync>> { if {%d < 0} {set negative 1} }
    # Without the fix for bug 2677890, changing the width of the toplevel
    # will launch recomputation of the line heights, but will produce negative
    # number of still remaining outdated lines, which is obviously wrong.
    # Thus we use this way to check for regression regarding bug 2677890,
    # i.e. to check that the fix for this bug really is still in.
    wm geometry . "[expr {$width * 2}]x$height+$left+$top"
    update
    .t1 sync
    set negative
} -cleanup {
    destroy .t1
} -result 0
} -result {0}

test textDisp-35.1 {Init value of charHeight - Dancing scrollbar bug 1499165} -setup {
    pack [text .t1] -fill both -expand y -side left
    # We don't want debug for this test case, because it takes some hours
    # if valgrind check is fully enabled. In this test case only the scrollbar
    # behavior is relevant, all other involved functions (insert, see, ...) are
    # already tested with debug mode in other test cases.
    .t debug off
    .t insert end "[string repeat a\nb\nc\n 500000]THE END\n"
    set res {}
} -body {
    .t see 10000.0
    after 300 {set fr1 [.t yview] ; set done 1}
    vwait done
    after 300 {set fr2 [.t yview] ; set done 1}
    vwait done
    lappend res [expr {[lindex $fr1 0] == [lindex $fr2 0]}]
    lappend res [expr {[lindex $fr1 1] == [lindex $fr2 1]}]
} -cleanup {
    .t debug on ;# re-enable debugging
    destroy .t1
} -result {1 1}

test textDisp-36.1 {Display bug with 'yview insert'} -constraints {knownBug} -setup {
   text .t1 -font $fixedFont -width 20 -height 3 -wrap word
   pack .t1
   .t1 delete 1.0 end
   .t1 tag configure elide -elide 1
   .t1 insert end "Line 1\nThis line is wrapping around two times."
} -body {
   .t1 tag add elide 1.3 2.0
   .t1 yview insert
   update
   # wish now panics: "CalculateDisplayLineHeight called with bad indexPtr"
   .t1 yview scroll -1 pixels
} -cleanup {
    destroy .t1
} -result {}

deleteWindows
option clear

# cleanup
cleanupTests
return

Changes to tests/textImage.test.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







# textImage.test -- test images embedded in text widgets
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
imageInit
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278







-
+







    .t image create end -image small -name small
    .t image create end -image small -name small#6342
    .t image create end -image small -name small
    lsort [.t image names]
} -cleanup {
    destroy .t
    image delete small
} -result {small small#1 small#2 small#6342}
} -result {small small#1 small#6342 small#6343}

test textImage-2.1 {debug} -setup {
    destroy .t
} -body {
    catch {
        image create photo small -width 5 -height 5
        small put red -to 0 0 4 4
382
383
384
385
386
387
388
389
390
391
392
393
394


395
396
397
398
399
400





401
402

403
404
405
406
407
408
409
382
383
384
385
386
387
388

389
390
391


392
393






394
395
396
397
398
399

400
401
402
403
404
405
406
407







-



-
-
+
+
-
-
-
-
-
-
+
+
+
+
+

-
+







    }
    font create test_font2 -size 5
    text .t -font test_font2 -bd 0 -highlightthickness 0 -padx 0 -pady 0
    pack .t
    .t image create end -image large
    .t image create end -image small -align baseline
    .t insert end test
    update
    # Sizes larger than 25 can be too big and lead to a negative 'norm',
    # at least on Windows XP with certain settings.
    foreach size {10 15 20 25} {
        font configure test_font2 -size $size
        array set Metrics [font metrics test_font2]
    font configure test_font2 -size $size
    array set Metrics [font metrics test_font2]
        update  ; # services the idle "TheWorldHasChanged" event, queues "TkWorldChanged" events
        update  ; # services the queued "TkWorldChanged" events
        foreach {x y w h} [.t bbox small] {}
        set norm [expr {
                (([image height large] - $Metrics(-linespace))/2
                + $Metrics(-ascent) - [image height small] - $y)
    update
    foreach {x y w h} [.t bbox small] {}
    set norm [expr {
            (([image height large] - $Metrics(-linespace))/2
            + $Metrics(-ascent) - [image height small] - $y)
        }]
        lappend result "$size $norm"
            lappend result "$size $norm"
    }
    return $result
} -cleanup {
    destroy .t
    image delete small large
    font delete test_font2
    unset Metrics

Changes to tests/textIndex.test.

1
2
3
4
5
6



7
8
9

10
11
12
13
14
15
16
1
2
3



4
5
6
7
8

9
10
11
12
13
14
15
16



-
-
-
+
+
+


-
+







# This file is a Tcl script to test the code in the file tkTextIndex.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

catch {destroy .t}
text .t -font {Courier -12} -width 20 -height 10
pack .t -expand 1 -fill both
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40







-
+







wm positionfrom . user
wm deiconify .

.t insert 1.0 "Line 1
abcdefghijklm
12345
Line 4
by GIrl .#@? x_yz
b\u4e4fy GIrl .#@? x_yz
!@#$%
Line 7"

image create photo textimage -width 10 -height 10
textimage put red -to 0 0 9 9

test textIndex-1.1 {TkTextMakeByteIndex} {testtext} {
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
+









-
+







} {3.4 4}
test textIndex-1.16 {TkTextMakeByteIndex: UTF-8 characters} {testtext} {
    testtext .t byteindex 5 100
} {5.18 20}
test textIndex-1.17 {TkTextMakeByteIndex: prevent splitting UTF-8 character} \
	{testtext} {
    # ((byteIndex > index) && (segPtr->typePtr == &tkTextCharType))
    # Wrong answer would be ¹ (the 2nd byte of UTF rep of 0x4e4f).
    # Wrong answer would be \xb9 (the 2nd byte of UTF rep of 0x4e4f).

    set x [testtext .t byteindex 5 2]
    list $x [.t get insert]
} {{5.2 4} y}
test textIndex-1.18 {TkTextMakeByteIndex: prevent splitting UTF-8 character} \
	{testtext} {
    # ((byteIndex > index) && (segPtr->typePtr == &tkTextCharType))
    testtext .t byteindex 5 1
    .t get insert
} ""
} "\u4e4f"

test textIndex-2.1 {TkTextMakeCharIndex} {
    # (lineIndex < 0)
    .t index -1.3
} 1.0
test textIndex-2.2 {TkTextMakeCharIndex} {
    # (lineIndex < 0), because lineIndex == strtol(argv[2]) - 1
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193







-
+







} 3.5
test textIndex-2.11 {TkTextMakeCharIndex: verify index is in range} {
    # not (segPtr == NULL)
    .t index 3.4
} 3.4
test textIndex-2.12 {TkTextMakeCharIndex: verify index is in range} {
    # (segPtr->typePtr == &tkTextCharType)
    # Wrong answer would be ¹ (the 2nd byte of UTF rep of 0x4e4f).
    # Wrong answer would be \xb9 (the 2nd byte of UTF rep of 0x4e4f).

    .t mark set insert 5.2
    .t get insert
} y
test textIndex-2.13 {TkTextMakeCharIndex: verify index is in range} {
    # not (segPtr->typePtr == &tkTextCharType)

264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278







-
+







test textIndex-4.8 {TkTextGetIndex, tags} {
    .t tag add z 1.0
    set result [list [.t index z.first] [.t index z.last]]
    .t tag delete z
    set result
} {1.0 1.1}

test textIndex-5.1 {TkTextGetIndex, "@"} {fonts} {
test textIndex-5.1 {TkTextGetIndex, "@"} {nonPortable fonts} {
    .t index @12,9
} 1.1
test textIndex-5.2 {TkTextGetIndex, "@"} {fonts} {
    .t index @-2,7
} 1.0
test textIndex-5.3 {TkTextGetIndex, "@"} {fonts} {
    .t index @10,-7
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618







-
+







    .t index {2.5 - 6 chars}
} 1.6
test textIndex-14.15 {TkTextIndexBackChars: UTF} {
    .t get {5.3 - 1 chars}
} y
test textIndex-14.16 {TkTextIndexBackChars: UTF} {
    .t get {5.3 - 2 chars}
} 
} \u4e4f
test textIndex-14.17 {TkTextIndexBackChars: UTF} {
    .t get {5.3 - 3 chars}
} b

proc getword index {
    .t get [.t index "$index wordstart"] [.t index "$index wordend"]
}
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
750
751
752
753
754
755
756

757
758
759
760
761
762
763







-







}

set str [string repeat "hello " 20]

.t insert end "$str one two three four five six seven height nine ten\n"
.t insert end "$str one two three four five six seven height nine ten\n"
.t insert end "$str one two three four five six seven height nine ten\n"
update

test textIndex-19.1 {Display lines} {
    .t index "2.7 displaylinestart"
} {2.0}

test textIndex-19.2 {Display lines} {
    .t index "2.7 displaylineend"
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

817
818
819
820
821
822
823
799
800
801
802
803
804
805








806

807
808
809
810
811
812
813
814







-
-
-
-
-
-
-
-

-
+







    .t index "2.40 +1displaylines"
} {2.60}

test textIndex-19.12 {Display lines} {
    .t index "2.40 -1displaylines"
} {2.20}

test textIndex-19.12.1 {Display lines} {
    .t index "2.50 - 100 displaylines"
} {1.0}

test textIndex-19.12.2 {Display lines} {
    .t compare [.t index "2.50 + 100 displaylines"] == "end - 1 c"
} 1

test textIndex-19.13 {Display lines} {
    destroy {*}[pack content .]
    destroy {*}[pack slaves .]
    text .txt -height 1 -wrap word -yscroll ".sbar set" -width 400
    scrollbar .sbar -command ".txt yview"
    grid .txt .sbar -sticky news
    grid configure .sbar -sticky ns
    grid rowconfigure    . 0 -weight 1
    grid columnconfigure . 0 -weight 1
    .txt configure -width 10
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
822
823
824
825
826
827
828












829
830
831
832
833
834
835







-
-
-
-
-
-
-
-
-
-
-
-







    .txt insert HISTORY {[23:51]	} STAMP
    .txt insert HISTORY "\n" {NICK NICK-tick}
    # Must not crash
    .txt index "2.0 - 2 display lines"
    destroy .txt .sbar
} {}

test textIndex-19.14 {Display lines with elided lines} {
    catch {destroy .t}
    pack [text .t]
    for {set n 1} {$n <= 1000} {incr n} {
	.t insert end "Line $n\n"
    }
    .t tag configure Elided -elide 1
    .t tag add Elided 6.0 951.0
    update
    set res [.t index "951.0 + 1 displaylines"]
} {952.0}

proc text_test_word {startend chars start} {
    destroy .t
    text .t
    .t insert end $chars
    if {[regexp {end} $start]} {
	set start [.t index "${start}chars -2c"]
    } else {
880
881
882
883
884
885
886
887

888
889
890

891
892
893

894
895
896

897
898
899

900
901
902
903
904
905
906
859
860
861
862
863
864
865

866
867
868

869
870
871

872
873
874

875
876
877

878
879
880
881
882
883
884
885







-
+


-
+


-
+


-
+


-
+







test textIndex-21.8 {text index wordend} {
    text_test_word worde "x.y" 0
} 1
test textIndex-21.9 {text index wordend} {
    text_test_word worde "x.y" end-1
} 2
test textIndex-21.10 {text index wordend, unicode} {
    text_test_word wordend "xyzÇde fg" 0
    text_test_word wordend "xyz\u00c7de fg" 0
} 6
test textIndex-21.11 {text index wordend, unicode} {
    text_test_word wordend "xyzde fg" 0
    text_test_word wordend "xyz\uc700de fg" 0
} 6
test textIndex-21.12 {text index wordend, unicode} {
    text_test_word wordend "xyzde fg" 0
    text_test_word wordend "xyz\u203fde fg" 0
} 6
test textIndex-21.13 {text index wordend, unicode} {
    text_test_word wordend "xyzde fg" 0
    text_test_word wordend "xyz\u2045de fg" 0
} 3
test textIndex-21.14 {text index wordend, unicode} {
    text_test_word wordend "윀윀 abc" 8
    text_test_word wordend "\uc700\uc700 abc" 8
} 6

test textIndex-22.5 {text index wordstart} {
    text_test_word wordstart "one two three_words" 400
} 8
test textIndex-22.6 {text index wordstart} {
    text_test_word wordstart "one two three_words" 2
914
915
916
917
918
919
920
921

922
923
924

925
926
927

928
929
930
931
932
933


934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
893
894
895
896
897
898
899

900
901
902

903
904
905

906
907
908
909
910


911
912
913
914
915
916
917
918
919
920
921
922










923
924
925
926
927
928
929







-
+


-
+


-
+




-
-
+
+










-
-
-
-
-
-
-
-
-
-







test textIndex-22.9 {text index wordstart} {
    text_test_word wordstart "one two three" 4
} 4
test textIndex-22.10 {text index wordstart} {
    text_test_word wordstart "one two three" end-5
} 7
test textIndex-22.11 {text index wordstart, unicode} {
    text_test_word wordstart "one twÇo three" 7
    text_test_word wordstart "one tw\u00c7o three" 7
} 4
test textIndex-22.12 {text index wordstart, unicode} {
    text_test_word wordstart "ab윀윀 cdef ghi" 12
    text_test_word wordstart "ab\uc700\uc700 cdef ghi" 12
} 10
test textIndex-22.13 {text index wordstart, unicode} {
    text_test_word wordstart "윀윀 abc" 8
    text_test_word wordstart "\uc700\uc700 abc" 8
} 3
test textIndex-22.14 {text index wordstart, unicode, start index at internal segment start} {
    catch {destroy .t}
    text .t
    .t insert end "C'est du texte en français\n"
    .t insert end "Это текст на русском"
    .t insert end "C'est du texte en fran\u00e7ais\n"
    .t insert end "\u042D\u0442\u043E\u0020\u0442\u0435\u043A\u0441\u0442\u0020\u043D\u0430\u0020\u0440\u0443\u0441\u0441\u043A\u043E\u043C"
    .t mark set insert 1.23
    set res [.t index "1.23 wordstart"]
    .t mark set insert 2.16
    lappend res [.t index "2.16 wordstart"] [.t index "2.15 wordstart"]
} {1.18 2.13 2.13}
test textIndex-22.15 {text index display wordstart} {
    catch {destroy .t}
    text .t
    .t index "1.0 display wordstart"  ; # used to crash
} 1.0
test textIndex-22.16 {text index wordstart, bug [57b821d2db]} {
    catch {destroy .t}
    text .t
    .t insert 1.0 " 123 5 789012  LINE-1\n\n 123 5 789000 LINE-3\n\n0123 5 789012  LINE-5"
    set res [.t index "1.1 wordstart"]
    lappend res [.t index "5.0 wordstart"]
    .t mark set insert 1.1
    lappend res [.t index "insert wordstart"]
    lappend res [.t index "5.1 wordstart"]
} {1.1 5.0 1.1 5.0}

test textIndex-23.1 {text paragraph start} {
    pack [text .t2]
    .t2 insert end " Text"
    set res 2.0
    for {set i 0} {$i < 2} {incr i} {
	lappend res [::tk::TextPrevPara .t2 [lindex $res end]]
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
952
953
954
955
956
957
958





































959
960
961
962
963







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





    .t2 insert end "32\n33\n34\n36\n37\n38\n39" elided
    # then this used to crash Tk:
    .t2 see end
    focus -force .t2   ; # to see the cursor blink
    destroy .t2
} {}

test textIndex-26.1 {GetIndex restricts the returned index to -startline/-endline in peers, bug [34db75c0ac]} {
    set res {}
    pack [text .t2]
    .t2 insert end "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n"
    pack [.t2 peer create .p2 -startline 2 -endline 3]
    lappend res [.p2 index "end"]
    lappend res [.p2 index "end lineend"]
    lappend res [.p2 index "end display lineend"]
    destroy .t2 .p2
    set res
} {2.0 2.0 2.0}
test textIndex-26.2 {GetIndex errors out if mark, image, window, or tag is outside peer -startline/-endline, bug [34db75c0ac]} {
    set res {}
    pack [text .t2]
    .t2 insert end "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n"
    pack [.t2 peer create .p2 -startline 2 -endline 3]
    .p2 configure -startline 3 -endline {}
    .t2 mark set mymark 1.0
    catch {.p2 index mymark} msg
    lappend res [.t2 index mymark] $msg
    image create photo redsquare -width 5 -height 5
    redsquare put red -to 0 0 4 4
    .t2 image create 1.0 -image redsquare
    catch {.p2 index redsquare} msg
    lappend res [.t2 index redsquare] $msg
    frame .f -width 10 -height 10 -bg blue
    .t2 window create 1.2 -window .f
    catch {.p2 index .f} msg
    lappend res [.t2 index .f] $msg
    .t2 tag add mytag 1.3
    catch {.p2 index mytag.first} msg
    lappend res [.t2 index mytag.first] $msg
    destroy .t2 .p2
    set res
} {1.0 {bad text index "mymark"} 1.0 {bad text index "redsquare"} 1.2\
   {bad text index ".f"} 1.3 {text doesn't contain any characters tagged with "mytag"}}

# cleanup
rename textimage {}
catch {destroy .t}
cleanupTests
return

Changes to tests/textMark.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test the code in the file tkTextMark.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+







test textMark-1.4 {TkTextMarkCmd - "gravity" option} -body {
    .t mark set x 1.3
    .t insert 1.3 x
    list [.t mark gravity x] [.t index x]
} -result {right 1.4}
test textMark-1.5 {TkTextMarkCmd - "gravity" option} -body {
    .t mark set x 1.3
    .t mark gr x left
    .t mark g x left
    .t insert 1.3 x
    list [.t mark gravity x] [.t index x]
} -result {left 1.3}
test textMark-1.6 {TkTextMarkCmd - "gravity" option} -body {
    .t mark set x 1.3
    .t mark gravity x right
    .t insert 1.3 x
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
173
174
175
176
177
178
179

180
181
182
183
184











185
186
187
188
189
190
191







-
+




-
-
-
-
-
-
-
-
-
-
-







} -cleanup {
  .t configure -startline {} -endline {}
  .pt configure -startline {} -endline {}
  .t mark unset mymark
} -result {1 {bad text index "mymark"} 1.0 1.0 1 {bad text index "mymark"} L 1 {bad text index "mymark"}}
test textMark-6.5 {insert and current marks in an empty peer - bug 3487407} -body {
  .t mark set insert 1.0
  .t configure -startline 5 -endline 5
  .t configure -start 5 -end 5
  set res [.t index insert]
} -cleanup {
  .t configure -startline {} -endline {}
} -result {1.0}
test textMark-6.6 {attempt to move the insert mark beyond peer -endline - bug 34db75c0ac} -body {
  .t peer create .p -startline 1 -endline 2
  pack .p
  update
  .p mark set insert 1.2
  focus -force .p
  event generate .p <<NextLine>>  ; # shall not error out
  set res [.p index insert]
} -cleanup {
  destroy .p
} -result {1.9}

test textMark-7.1 {MarkFindNext - invalid mark name} -body {
    .t mark next bogus
} -returnCodes error -result {bad text index "bogus"}
test textMark-7.2 {MarkFindNext - marks at same location} -body {
    .t mark set insert 2.0
    .t mark set current 2.0

Changes to tests/textTag.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15


16







17
18
19



20
21
22
23


24
25

26
27
28
29
30
31
32
1
2
3



4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
23



24
25
26




27
28
29

30
31
32
33
34
35
36
37



-
-
-
+
+
+







-
-
+
+

+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+

-
+







# This file is a Tcl script to test the code in the file tkTextTag.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

set fixedFont {Courier 12}
set bigFont   {Helvetica 24}
set textWidgetFont {Courier 12}
set bigFont        {Courier 24}

# what is needed is a font that is both fixed-width and featuring a
# specific size because in some tests (that will be constrained by
# haveFontSizes), a tag applying the $bigFont will be set to some
# characters, which action has the effect of changing what character
# is under the mouse pointer, which is the purpose of the tests
testConstraint haveFontSizes [expr {
    [font metrics $textWidgetFont -fixed] &&
# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
    [font actual  $textWidgetFont -size] == 12 &&
    [font metrics $bigFont -fixed] &&
    [font actual  $bigFont -size] == 24 }
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}

]

destroy .t
text .t -width 20 -height 10 -font $fixedFont
text .t -width 20 -height 10

pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}

74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93







-
+







} -cleanup {
    .t tag configure x -borderwidth [lindex [.t tag configure x -borderwidth] 3]
} -result {2}
test textTag-1.6 {configuration options} -body {
    .t tag configure x -borderwidth 46q
} -cleanup {
    .t tag configure x -borderwidth [lindex [.t tag configure x -borderwidth] 3]
} -returnCodes error -result {expected screen distance or "" but got "46q"}
} -returnCodes error -result {bad screen distance "46q"}
test textTag-1.7 {tag configuration options} -body {
    .t tag configure x -fgstipple gray25
    .t tag cget x -fgstipple
} -cleanup {
    .t tag configure x -fgstipple [lindex [.t tag configure x -fgstipple] 3]
} -result {gray25}
test textTag-1.8 {configuration options} -body {
109
110
111
112
113
114
115
116
117


118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
114
115
116
117
118
119
120


121
122


123
124

125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154







-
-
+
+
-
-


-
+










-
+










-
+







} -returnCodes error -result {unknown color name "silly color"}
test textTag-1.12 {tag configuration options} -body {
    .t tag configure x -justify left
    .t tag cget x -justify
} -cleanup {
    .t tag configure x -justify [lindex [.t tag configure x -justify] 3]
} -result {left}
test textTag-1.13 {configuration options, bug [026e2bb685]} -body {
    .t tag configure x -justify right
test textTag-1.13 {configuration options} -body {
    .t tag configure x -justify middle
    catch {.t tag configure x -justify middle} msg
    list $msg [.t tag configure x -justify]
} -cleanup {
    .t tag configure x -justify [lindex [.t tag configure x -justify] 3]
} -result {{bad justification "middle": must be left, right, center, or ""} {-justify {} {} {} right}}
} -returnCodes error -result {bad justification "middle": must be left, right, or center}
test textTag-1.14 {tag configuration options} -body {
    .t tag configure x -lmargin1 10
    .t tag cget x -lmargin1
} -cleanup {
    .t tag configure x -lmargin1 [lindex [.t tag configure x -lmargin1] 3]
} -result {10}
test textTag-1.15 {configuration options} -body {
    .t tag configure x -lmargin1 bad
} -cleanup {
    .t tag configure x -lmargin1 [lindex [.t tag configure x -lmargin1] 3]
} -returnCodes error -result {expected screen distance or "" but got "bad"}
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.16 {tag configuration options} -body {
    .t tag configure x -lmargin2 10
    .t tag cget x -lmargin2
} -cleanup {
    .t tag configure x -lmargin2 [lindex [.t tag configure x -lmargin2] 3]
} -result {10}
test textTag-1.17 {configuration options} -body {
    .t tag configure x -lmargin2 bad
} -cleanup {
    .t tag configure x -lmargin2 [lindex [.t tag configure x -lmargin2] 3]
} -returnCodes error -result {expected screen distance or "" but got "bad"}
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.17a {tag configuration options} -body {
    .t tag configure x -lmargincolor lightgreen
    .t tag cget x -lmargincolor
} -cleanup {
    .t tag configure x -lmargincolor [lindex [.t tag configure x -lmargincolor] 3]
} -result {lightgreen}
test textTag-1.17b {configuration options} -body {
159
160
161
162
163
164
165
166

167
168
169
170
171
172

173
174
175
176
177

178
179
180
181
182
183
184
162
163
164
165
166
167
168

169
170
171
172
173
174

175
176
177
178
179

180
181
182
183
184
185
186
187







-
+





-
+




-
+







} -cleanup {
    .t tag configure x -offset [lindex [.t tag configure x -offset] 3]
} -result {2}
test textTag-1.19 {configuration options} -body {
    .t tag configure x -offset 100xyz
} -cleanup {
    .t tag configure x -offset [lindex [.t tag configure x -offset] 3]
} -returnCodes error -result {expected screen distance or "" but got "100xyz"}
} -returnCodes error -result {bad screen distance "100xyz"}
test textTag-1.20 {tag configuration options} -body {
    .t tag configure x -overstrike on
    .t tag cget x -overstrike
} -cleanup {
    .t tag configure x -overstrike [lindex [.t tag configure x -overstrike] 3]
} -result 1
} -result {on}
test textTag-1.21 {configuration options} -body {
    .t tag configure x -overstrike stupid
} -cleanup {
    .t tag configure x -overstrike [lindex [.t tag configure x -overstrike] 3]
} -returnCodes error -result {expected boolean value or "" but got "stupid"}
} -returnCodes error -result {expected boolean value but got "stupid"}
test textTag-1.21a {tag configuration options} -body {
    .t tag configure x -overstrikefg red
    .t tag cget x -overstrikefg
} -cleanup {
    .t tag configure x -overstrikefg [lindex [.t tag configure x -overstrikefg] 3]
} -result {red}
test textTag-1.21b {configuration options} -body {
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220







-
+










-
+







} -cleanup {
    .t tag configure x -relief [lindex [.t tag configure x -relief] 3]
} -result {raised}
test textTag-1.23 {configuration options} -body {
    .t tag configure x -relief stupid
} -cleanup {
    .t tag configure x -relief [lindex [.t tag configure x -relief] 3]
} -returnCodes error -result {bad relief "stupid": must be flat, groove, raised, ridge, solid, sunken, or ""}
} -returnCodes error -result {bad relief "stupid": must be flat, groove, raised, ridge, solid, or sunken}
test textTag-1.24 {tag configuration options} -body {
    .t tag configure x -rmargin 10
    .t tag cget x -rmargin
} -cleanup {
    .t tag configure x -rmargin [lindex [.t tag configure x -rmargin] 3]
} -result {10}
test textTag-1.25 {configuration options} -body {
    .t tag configure x -rmargin bad
} -cleanup {
    .t tag configure x -rmargin [lindex [.t tag configure x -rmargin] 3]
} -returnCodes error -result {expected screen distance or "" but got "bad"}
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.25a {tag configuration options} -body {
    .t tag configure x -rmargincolor darkblue
    .t tag cget x -rmargincolor
} -cleanup {
    .t tag configure x -rmargincolor [lindex [.t tag configure x -rmargincolor] 3]
} -result {darkblue}
test textTag-1.25b {configuration options} -body {
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262


263
264
265
266


267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

295
296
297
298
299

300
301
302
303
304
305
306
250
251
252
253
254
255
256

257
258
259
260
261
262
263


264
265

266


267
268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297
298
299
300

301
302
303
304
305
306
307
308







-
+






-
-
+
+
-

-
-
+
+










-
+
















-
+




-
+







} -cleanup {
    .t tag configure x -spacing1 [lindex [.t tag configure x -spacing1] 3]
} -result {10}
test textTag-1.27 {configuration options} -body {
    .t tag configure x -spacing1 bad
} -cleanup {
    .t tag configure x -spacing1 [lindex [.t tag configure x -spacing1] 3]
} -returnCodes error -result {expected screen distance or "" but got "bad"}
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.28 {tag configuration options} -body {
    .t tag configure x -spacing2 10
    .t tag cget x -spacing2
} -cleanup {
    .t tag configure x -spacing2 [lindex [.t tag configure x -spacing2] 3]
} -result {10}
test textTag-1.29 {configuration options, bug [026e2bb685]} -body {
    catch {.t tag configure x -spacing3 5 -spacing2 bad -spacing1 morebad} msg
test textTag-1.29 {configuration options} -body {
    .t tag configure x -spacing2 bad
    list $msg [.t tag configure x -spacing1] [.t tag configure x -spacing2] [.t tag configure x -spacing3]
} -cleanup {
    .t tag configure x -spacing1 [lindex [.t tag configure x -spacing1] 3] -spacing2 [lindex [.t tag configure x -spacing2] 3] -spacing3 [lindex [.t tag configure x -spacing3] 3]
} -result {{expected screen distance or "" but got "bad"} {-spacing1 {} {} {} {}} {-spacing2 {} {} {} {}} {-spacing3 {} {} {} 5}}
    .t tag configure x -spacing2 [lindex [.t tag configure x -spacing2] 3]
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.30 {tag configuration options} -body {
    .t tag configure x -spacing3 10
    .t tag cget x -spacing3
} -cleanup {
    .t tag configure x -spacing3 [lindex [.t tag configure x -spacing3] 3]
} -result {10}
test textTag-1.31 {configuration options} -body {
    .t tag configure x -spacing3 bad
} -cleanup {
    .t tag configure x -spacing3 [lindex [.t tag configure x -spacing3] 3]
} -returnCodes error -result {expected screen distance or "" but got "bad"}
} -returnCodes error -result {bad screen distance "bad"}
test textTag-1.32 {tag configuration options} -body {
    .t tag configure x -tabs {10 20 30}
    .t tag cget x -tabs
} -cleanup {
    .t tag configure x -tabs [lindex [.t tag configure x -tabs] 3]
} -result {10 20 30}
test textTag-1.33 {configuration options} -body {
    .t tag configure x -tabs {10 fork}
} -cleanup {
    .t tag configure x -tabs [lindex [.t tag configure x -tabs] 3]
} -returnCodes error -result {bad tab alignment "fork": must be left, right, center, or numeric}
test textTag-1.34 {tag configuration options} -body {
    .t tag configure x -underline no
    .t tag cget x -underline
} -cleanup {
    .t tag configure x -underline [lindex [.t tag configure x -underline] 3]
} -result 0
} -result {no}
test textTag-1.35 {configuration options} -body {
    .t tag configure x -underline stupid
} -cleanup {
    .t tag configure x -underline [lindex [.t tag configure x -underline] 3]
} -returnCodes error -result {expected boolean value or "" but got "stupid"}
} -returnCodes error -result {expected boolean value but got "stupid"}
test textTag-1.36 {tag configuration options} -body {
    .t tag configure x -underlinefg red
    .t tag cget x -underlinefg
} -cleanup {
    .t tag configure x -underlinefg [lindex [.t tag configure x -underlinefg] 3]
} -result {red}
test textTag-1.37 {configuration options} -body {
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402







-
+







    .t tag remove sel 1.0 end
} -result {1.1 1.5 2.4 2.5}
test textTag-2.14 {tag add before -startline - Bug 1615425} -body {
    text .tt
    for {set i 1} {$i <10} {incr i} {
        .tt insert end "Line $i\n"
    }
    .tt tag configure mytag -offset 2
    .tt tag configure mytag -font {Courier 12 bold}
    .tt peer create .ptt
    .ptt configure -startline 3 -endline 7
    # the test succeeds if next line does not crash
    .tt tag add mytag 1.0 1.end
    destroy .ptt .tt
    set res 1
} -result {1}
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
526
527
528
529
530

531
532
533
534
535
536

537
538
539
540
541
542
543
544
545
546



547
548
549
550

551
552
553
554
555
556

557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633

634
635
636
637
638
639

640
641
642
643
644
645
646
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519

520
521
522
523
524
525
526
527
528
529
530
531

532
533
534
535
536
537

538
539
540
541
542
543
544
545



546
547
548

549
550

551
552
553
554
555
556

557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633

634
635
636
637
638
639

640
641
642
643
644
645
646
647







-
+














-
+













-
+











-
+





-
+







-
-
-
+
+
+
-


-
+





-
+












-
+


















-
+





-
+











-
+




















-
+





-
+





-
+







} -cleanup {
    .t tag delete x
} -result {red}


test textTag-5.1 {TkTextTagCmd - "configure" option} -body {
    .t tag configure
} -returnCodes error -result {wrong # args: should be ".t tag configure tagName ?-option value ...?"}
} -returnCodes error -result {wrong # args: should be ".t tag configure tagName ?-option? ?value? ?-option value ...?"}
test textTag-5.2 {TkTextTagCmd - "configure" option} -body {
    .t tag configure x -foo
} -returnCodes error -result {unknown option "-foo"}
test textTag-5.3 {TkTextTagCmd - "configure" option} -body {
    .t tag configure x -background red -underline
} -cleanup {
    .t tag delete x
} -returnCodes error -result {value for "-underline" missing}
test textTag-5.4 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -underline yes
    .t tag configure x -underline
} -cleanup {
    .t tag delete x
} -result {-underline {} {} {} 1}
} -result {-underline {} {} {} yes}
test textTag-5.4a {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -underlinefg lightgreen
    .t tag configure x -underlinefg
} -cleanup {
    .t tag delete x
} -result {-underlinefg {} {} {} lightgreen}
test textTag-5.5 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -overstrike on
    .t tag cget x -overstrike
} -cleanup {
    .t tag delete x
} -result 1
} -result {on}
test textTag-5.5a {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -overstrikefg lightgreen
    .t tag configure x -overstrikefg
} -cleanup {
    .t tag delete x
} -result {-overstrikefg {} {} {} lightgreen}
test textTag-5.6 {TkTextTagCmd - "configure" option} -body {
    .t tag configure x -overstrike foo
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected boolean value or "" but got "foo"}
} -returnCodes error -result {expected boolean value but got "foo"}
test textTag-5.7 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -underline stupid
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected boolean value or "" but got "stupid"}
} -returnCodes error -result {expected boolean value but got "stupid"}
test textTag-5.8 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -justify left
    .t tag configure x -justify
} -cleanup {
    .t tag delete x
} -result {-justify {} {} {} left}
test textTag-5.9 {TkTextTagCmd - "configure" option, bug [026e2bb685]} -body {
   .t tag delete x
    catch {.t tag configure x -justify bogus} msg
test textTag-5.9 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -justify bogus
    list $msg [.t tag configure x -justify]
} -cleanup {
    .t tag delete x
} -result {{bad justification "bogus": must be left, right, center, or ""} {-justify {} {} {} {}}}
} -returnCodes error -result {bad justification "bogus": must be left, right, or center}
test textTag-5.10 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -justify fill
} -cleanup {
    .t tag delete x
} -returnCodes error -result {bad justification "fill": must be left, right, center, or ""}
} -returnCodes error -result {bad justification "fill": must be left, right, or center}
test textTag-5.11 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -offset 2
    .t tag configure x -offset
} -cleanup {
    .t tag delete x
} -result {-offset {} {} {} 2}
test textTag-5.12 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -offset 1.0q
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "1.0q"}
} -returnCodes error -result {bad screen distance "1.0q"}
test textTag-5.13 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -lmargin1 2 -lmargin2 4 -rmargin 5 \
        -lmargincolor darkblue -rmargincolor lightgreen
    list [.t tag configure x -lmargin1] [.t tag configure x -lmargin2] \
        [.t tag configure x -rmargin] [.t tag configure x -lmargincolor] \
        [.t tag configure x -rmargincolor]
} -cleanup {
    .t tag delete x
} -result [list {-lmargin1 {} {} {} 2} {-lmargin2 {} {} {} 4} \
                {-rmargin {} {} {} 5} \
                {-lmargincolor {} {} {} darkblue} {-rmargincolor {} {} {} lightgreen} \
          ]
test textTag-5.14 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -lmargin1 2.0x
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "2.0x"}
} -returnCodes error -result {bad screen distance "2.0x"}
test textTag-5.15 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -lmargin2 gorp
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "gorp"}
} -returnCodes error -result {bad screen distance "gorp"}
test textTag-5.15a {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -lmargincolor rainbow
} -cleanup {
    .t tag delete x
} -returnCodes error -result {unknown color name "rainbow"}
test textTag-5.16 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -rmargin 140.1.1
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "140.1.1"}
} -returnCodes error -result {bad screen distance "140.1.1"}
test textTag-5.16a {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -rmargincolor rainbow
} -cleanup {
    .t tag delete x
} -returnCodes error -result {unknown color name "rainbow"}
.t tag delete x
test textTag-5.17 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -spacing1 2 -spacing2 4 -spacing3 6
    list [.t tag configure x -spacing1] [.t tag configure x -spacing2] \
        [.t tag configure x -spacing3]
} -cleanup {
    .t tag delete x
} -result {{-spacing1 {} {} {} 2} {-spacing2 {} {} {} 4} {-spacing3 {} {} {} 6}}
test textTag-5.18 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -spacing1 2.0x
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "2.0x"}
} -returnCodes error -result {bad screen distance "2.0x"}
test textTag-5.19 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -spacing1 lousy
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "lousy"}
} -returnCodes error -result {bad screen distance "lousy"}
test textTag-5.20 {TkTextTagCmd - "configure" option} -body {
    .t tag delete x
    .t tag configure x -spacing1 4.2.3
} -cleanup {
    .t tag delete x
} -returnCodes error -result {expected screen distance or "" but got "4.2.3"}
} -returnCodes error -result {bad screen distance "4.2.3"}
test textTag-5.21 {TkTextTagCmd - "configure" option} -body {
    .t configure -selectborderwidth 2 -selectforeground blue \
        -selectbackground black
    .t tag configure sel -borderwidth 4 -foreground green -background yellow
    set x {}
    foreach i {-selectborderwidth -selectforeground -selectbackground} {
        lappend x [lindex [.t configure $i] 4]
1204
1205
1206
1207
1208
1209
1210



1211
1212
1213


1214
1215
1216


1217
1218
1219











1220
1221
1222
1223
1224

1225
1226
1227
1228
1229
1230
1231
1232
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215


1216
1217
1218


1219
1220
1221


1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235


1236

1237
1238
1239
1240
1241
1242
1243







+
+
+

-
-
+
+

-
-
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+



-
-
+
-







        .t tag add x$i 2.0 2.2
    }
    .t tag names 2.1
} -cleanup {
    .t tag delete {*}[.t tag names]
} -result {x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29}


set curFont [.t cget -font]
set curWrap [.t cget -wrap]
set c [.t bbox 2.1]
set x1 [expr {[lindex $c 0] + [lindex $c 2]/2}]
set y1 [expr {[lindex $c 1] + [lindex $c 3]/2}]
set x1 [expr [lindex $c 0] + [lindex $c 2]/2]
set y1 [expr [lindex $c 1] + [lindex $c 3]/2]
set c [.t bbox 3.2]
set x2 [expr {[lindex $c 0] + [lindex $c 2]/2}]
set y2 [expr {[lindex $c 1] + [lindex $c 3]/2}]
set x2 [expr [lindex $c 0] + [lindex $c 2]/2]
set y2 [expr [lindex $c 1] + [lindex $c 3]/2]
set c [.t bbox 4.3]
set x3 [expr {[lindex $c 0] + [lindex $c 2]/2}]
set y3 [expr {[lindex $c 1] + [lindex $c 3]/2}]
set x3 [expr [lindex $c 0] + [lindex $c 2]/2]
set y3 [expr [lindex $c 1] + [lindex $c 3]/2]
.t configure -font $textWidgetFont -wrap none
update
set c [.t bbox 2.1]
set x4 [expr [lindex $c 0] + [lindex $c 2]/2]
set y4 [expr [lindex $c 1] + [lindex $c 3]/2]
set c [.t bbox 3.2]
set x5 [expr [lindex $c 0] + [lindex $c 2]/2]
set y5 [expr [lindex $c 1] + [lindex $c 3]/2]
.t configure -font $curFont -wrap $curWrap

test textTag-15.1 {TkTextBindProc} -setup {
    .t tag delete x y
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    bind .t <ButtonRelease> {lappend x up}
    .t tag bind x <ButtonRelease> {lappend x x-up}
    .t tag bind y <ButtonRelease> {lappend x y-up}
    set x {}
    .t tag add x 2.0 2.4
    .t tag add y 4.3
1243
1244
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255

1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281

1282
1283
1284
1285
1286


1287
1288
1289
1290


1291
1292
1293
1294
1295
1296
1297
1254
1255
1256
1257
1258
1259
1260


1261

1262
1263

1264
1265
1266
1267

1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288


1289

1290
1291


1292
1293
1294
1295


1296
1297
1298
1299
1300
1301
1302
1303
1304







-
-
+
-


-
+



-
+




















-
-
+
-


-
-
+
+


-
-
+
+







} -cleanup {
    .t tag delete x y
    bind .t <ButtonRelease> {}
} -result {x-up up up y-up up}

test textTag-15.2 {TkTextBindProc} -setup {
    .t tag delete x y
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    .t tag bind x <Enter> {lappend x x-enter}
    .t tag bind x <Button> {lappend x x-down}
    .t tag bind x <ButtonPress> {lappend x x-down}
    .t tag bind x <ButtonRelease> {lappend x x-up}
    .t tag bind x <Leave> {lappend x x-leave}
    .t tag bind y <Enter> {lappend x y-enter}
    .t tag bind y <Button> {lappend x y-down}
    .t tag bind y <ButtonPress> {lappend x y-down}
    .t tag bind y <ButtonRelease> {lappend x y-up}
    .t tag bind y <Leave> {lappend x y-leave}
    event gen .t <Motion> -x 0 -y 0
    set x {}
    .t tag add x 2.0 2.4
    .t tag add y 4.3
    event gen .t <Motion> -x $x1 -y $y1
    lappend x |
    event gen .t <Button> -x $x1 -y $y1
    lappend x |
    event gen .t <Motion> -x $x3 -y $y3 -state 0x100
    lappend x |
    event gen .t <ButtonRelease> -x $x3 -y $y3
    return $x
} -cleanup {
    .t tag delete x y
} -result {x-enter | x-down | | x-up x-leave y-enter}

test textTag-15.3 {TkTextBindProc} -setup {
    .t tag delete x y
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    .t tag bind x <Enter> {lappend x x-enter}
    .t tag bind x <Button-1> {lappend x x-down}
    .t tag bind x <ButtonRelease-1> {lappend x x-up}
    .t tag bind x <Any-ButtonPress-1> {lappend x x-down}
    .t tag bind x <Any-ButtonRelease-1> {lappend x x-up}
    .t tag bind x <Leave> {lappend x x-leave}
    .t tag bind y <Enter> {lappend x y-enter}
    .t tag bind y <Button-1> {lappend x y-down}
    .t tag bind y <ButtonRelease-1> {lappend x y-up}
    .t tag bind y <Any-ButtonPress-1> {lappend x y-down}
    .t tag bind y <Any-ButtonRelease-1> {lappend x y-up}
    .t tag bind y <Leave> {lappend x y-leave}
    event gen .t <Motion> -x 0 -y 0
    set x {}
    .t tag add x 2.0 2.4
    .t tag add y 4.3
    event gen .t <Motion> -x $x1 -y $y1
    lappend x |
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358

1359

1360
1361
1362
1363
1364
1365


1366
1367
1368
1369
1370
1371

1372
1373
1374
1375
1376
1377
1378
1379

1380
1381
1382
1383
1384
1385
1386
1387
1312
1313
1314
1315
1316
1317
1318


















1319
1320
1321


1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343


1344

1345
1346
1347




1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362


1363

1364
1365
1366
1367
1368
1369
1370







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
+
-


















-
+


-
-
+
-
+


-
-
-
-
+
+






+






-
-
+
-







    lappend x |
    event gen .t <ButtonRelease-2> -x $x3 -y $y3 -state 0x200
    return $x
} -cleanup {
    .t tag delete x y
} -result {x-enter | x-down | | | x-up | x-leave y-enter}

test textTag-15.4 {TkTextBindProc, key event with mouse outside the widget} -setup {
    .t tag delete {*}[.t tag names]
    wm geometry . +200+200 ; update
} -body {
    set res {}
    .t tag add tag1 1.0 end
    .t tag bind tag1 <Key> {lappend res %K}
    .t mark set insert 1.2
    update
    event generate .t <Motion> -warp 1 -x -50 -y -50
    controlPointerWarpTiming
    focus -force .t
    event generate .t <Key> -keysym a
    set res
} -cleanup {
    .t tag delete tag1
} -result {a}


test textTag-16.1 {TkTextPickCurrent procedure} -setup {
    .t tag delete {*}[.t tag names]
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    event gen .t <ButtonRelease-1> -state 0x100 -x $x1 -y $y1
    set x [.t index current]
    event gen .t <Motion> -x $x2 -y $y2
    lappend x [.t index current]
    event gen .t <Button-1> -x $x2 -y $y2
    lappend x [.t index current]
    event gen .t <Motion> -x $x3 -y $y3 -state 0x100
    lappend x [.t index current]
    event gen .t <Button-3> -state 0x100 -x $x3 -y $y3
    lappend x [.t index current]
    event gen .t <ButtonRelease-3> -state 0x300 -x $x3 -y $y3
    lappend x [.t index current]
    event gen .t <ButtonRelease-1> -state 0x100 -x $x3 -y $y3
    lappend x [.t index current]
} -result {2.1 3.2 3.2 3.2 3.2 3.2 4.3}

test textTag-16.2 {TkTextPickCurrent procedure} -constraints {
    haveBigFontTwiceLargerThanTextFont
    haveFontSizes
} -setup {
    .t tag delete {*}[.t tag names]
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
    .t configure -font $textWidgetFont -wrap none
} -body {
    .t tag configure big -font $bigFont
    # update needed here to stabilize the test
    update
    event gen .t <ButtonRelease-1> -state 0x100 -x $x1 -y $y1
    event gen .t <Motion> -x $x2 -y $y2
    event gen .t <ButtonRelease-1> -state 0x100 -x $x4 -y $y4
    event gen .t <Motion> -x $x5 -y $y5
    set x [.t index current]
    .t tag add big 3.0
    update
    lappend x [.t index current]
} -cleanup {
    .t tag delete big
    .t configure -font $curFont -wrap $curWrap
} -result {3.2 3.1}

test textTag-16.3 {TkTextPickCurrent procedure} -setup {
    foreach i {a b c d} {
        .t tag remove $i 1.0 end
    }
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    foreach i {a b c d} {
        .t tag bind $i <Enter> "lappend x enter-$i"
        .t tag bind $i <Leave> "lappend x leave-$i"
    }
    .t tag lower b
    .t tag lower a
1400
1401
1402
1403
1404
1405
1406
1407
1408

1409
1410
1411
1412
1413
1414
1415
1416
1383
1384
1385
1386
1387
1388
1389


1390

1391
1392
1393
1394
1395
1396
1397







-
-
+
-







    .t tag delete {*}[.t tag names]
} -result {enter-a enter-b | leave-b enter-c | leave-a leave-c}

test textTag-16.4 {TkTextPickCurrent procedure} -setup {
    foreach i {a b c d} {
        .t tag remove $i 1.0 end
    }
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    foreach i {a b c d} {
        .t tag bind $i <Enter> "lappend x enter-$i"
        .t tag bind $i <Leave> "lappend x leave-$i"
    }
    .t tag lower b
    .t tag lower a
1424
1425
1426
1427
1428
1429
1430
1431



1432
1433
1434
1435
1436

1437

1438
1439
1440

1441
1442
1443

1444
1445
1446

1447
1448
1449
1450

1451
1452
1453
1454
1455
1456

1457

1458
1459
1460

1461
1462
1463

1464
1465
1466
1467

1468
1469
1470
1471

1472
1473
1474
1475
1476
1477

1478

1479
1480
1481
1482
1483
1484

1485
1486
1487

1488
1489
1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417


1418

1419
1420
1421

1422
1423
1424

1425
1426
1427
1428
1429
1430
1431
1432

1433
1434
1435
1436
1437


1438

1439
1440
1441

1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458


1459

1460
1461
1462
1463
1464
1465

1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490


1491

1492
1493
1494
1495

1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507




1508
1509
1510
1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523







-
+
+
+



-
-
+
-
+


-
+


-
+



+



-
+




-
-
+
-
+


-
+


-
+




+



-
+




-
-
+
-
+





-
+


-
+




+
















-
-
+
-




-









+


-
-
-
-






-
+









    .t tag lower c
    event gen .t <Motion> -x $x2 -y $y2
    return $x
} -cleanup {
    .t tag delete {*}[.t tag names]
} -result {enter-a enter-b enter-c | leave-c leave-b}

test textTag-16.5 {TkTextPickCurrent procedure} -setup {
test textTag-16.5 {TkTextPickCurrent procedure} -constraints {
    haveFontSizes
} -setup {
    foreach i {big a b c d} {
        .t tag remove $i 1.0 end
    }
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
    .t configure -font $textWidgetFont -wrap none
} -body {
    .t tag configure big -font $bigFont
    event gen .t <Motion> -x $x1 -y $y1
    event gen .t <Motion> -x $x4 -y $y4
    .t tag bind a <Enter> {.t tag add big 3.0 3.2}
    .t tag add a 3.2
    event gen .t <Motion> -x $x2 -y $y2
    event gen .t <Motion> -x $x5 -y $y5
    .t index current
} -cleanup {
    .t tag delete a big
    .t configure -font $curFont -wrap $curWrap
} -result {3.2}

test textTag-16.6 {TkTextPickCurrent procedure} -constraints {
    haveBigFontTwiceLargerThanTextFont
    haveFontSizes
} -setup {
    foreach i {big a b c d} {
        .t tag remove $i 1.0 end
    }
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
    .t configure -font $textWidgetFont -wrap none
} -body {
    .t tag configure big -font $bigFont
    event gen .t <Motion> -x $x1 -y $y1
    event gen .t <Motion> -x $x4 -y $y4
    .t tag bind a <Enter> {.t tag add big 3.0 3.2}
    .t tag add a 3.2
    event gen .t <Motion> -x $x2 -y $y2
    event gen .t <Motion> -x $x5 -y $y5
    update
    .t index current
} -cleanup {
    .t tag delete a big
    .t configure -font $curFont -wrap $curWrap
} -result {3.1}

test textTag-16.7 {TkTextPickCurrent procedure} -constraints {
    haveBigFontTwiceLargerThanTextFont
    haveFontSizes
} -setup {
    foreach i {big a b c d} {
        .t tag remove $i 1.0 end
    }
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
    .t configure -font $textWidgetFont -wrap none
} -body {
    .t tag configure big -font $bigFont
    .t tag bind a <Enter> {.t tag add big 3.0 3.2}
    .t tag add a 3.2

    event gen .t <Motion> -x $x1 -y $y1
    event gen .t <Motion> -x $x4 -y $y4
    .t tag bind a <Leave> {.t tag add big 3.0 3.2}
    .t tag add a 2.1
    event gen .t <Motion> -x $x2 -y $y2
    event gen .t <Motion> -x $x5 -y $y5
    update
    .t index current
} -cleanup {
    .t tag delete a big
    .t configure -font $curFont -wrap $curWrap
} -result {3.1}


test textTag-17.1 {insert procedure inserts tags} -setup {
    .t delete 1.0 end
} -body {
    # Objectification of the text widget had a problem
    # with inserting tags when using 'end'. Check that
    # bug has been fixed.
    .t insert end abcd {x} \n {} efgh {y} \n {}
    .t dump -tag 1.0 end
} -result {tagon x 1.0 tagoff x 1.4 tagon y 2.0 tagoff y 2.4}


test textTag-18.1 {TkTextPickCurrent tag bindings} -setup {
    destroy .t
    wm geometry . +200+200 ; update
    event generate {} <Motion> -warp 1 -x 5 -y 5
    event generate {} <Motion> -warp 1 -x -1 -y -1; update
    controlPointerWarpTiming
} -body {
    text .t -width 30 -height 4 -relief sunken -borderwidth 10 \
      -highlightthickness 10 -pady 2
    pack .t
    update ; # map the window, otherwise -warp can't be done

    .t insert end " Tag here " TAG " no tag here"
    .t tag configure TAG -borderwidth 4 -relief raised
    .t tag bind TAG <Enter>  {lappend res "%x %y tag-Enter"}
    .t tag bind TAG <Leave>  {lappend res "%x %y tag-Leave"}
    bind .t <Enter> {lappend res Enter}
    bind .t <Leave> {lappend res Leave}

    set res {}
    update
    # Bindings must not trigger on the widget border, only over
    # the actual tagged characters themselves.
    # Note that we don't need to call controlPointerWarpTiming
    # in the following six calls because we're not checking that
    # the mouse pointer has actually moved but rather that the
    # tag binding mechanism of the text widget correctly triggers.
    event gen .t <Motion> -warp 1 -x 0 -y 0 ; update
    event gen .t <Motion> -warp 1 -x 10 -y 10 ; update
    event gen .t <Motion> -warp 1 -x 25 -y 25 ; update
    event gen .t <Motion> -warp 1 -x 20 -y 20 ; update
    event gen .t <Motion> -warp 1 -x 10 -y 10 ; update
    event gen .t <Motion> -warp 1 -x 25 -y 25 ; update
    set res
    return $res
} -cleanup {
    destroy .t
} -result {Enter {25 25 tag-Enter} {20 20 tag-Leave} {25 25 tag-Enter}}

destroy .t

# cleanup
cleanupTests
return

Changes to tests/textWind.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15

16
17
18
19
20

21
22
23
24
25
26
27
28



29
30
31
32


33
34
35
36
37
38
39



40
41
42
43
44
45

46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72

73


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
139
140
141
142
143

144
145
146

147
148
149
150
151
152
153
154
155
156
157

158
159
160

161
162
163
164
165
166
167
168
169
170


171
172
173
174
175
176
177
178
1
2
3



4
5
6
7
8
9
10
11
12
13


14





15








16
17
18




19
20







21
22
23






24
25
26
27
28


29


















30



31
32
33
34
35
36
37
38
39
40
41
42
43





44
45

46
47
48
49
50
51
52
53
54
55





56


57
58
59
60
61
62
63
64
65
66





67

68
69
70
71
72
73
74
75


76
77
78
79
80

81
82
83
84



85



86
87
88
89
90
91
92
93
94



95



96
97
98
99
100
101
102
103
104


105
106

107
108
109
110
111
112
113



-
-
-
+
+
+







-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+




-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+

+
+









-
-
-
-
-


-
+









-
-
-
-
-
+
-
-
+









-
-
-
-
-
+
-








-
-
+




-




-
-
-
+
-
-
-
+








-
-
-
+
-
-
-
+








-
-
+
+
-







# This file is a Tcl script to test the code in the file tkTextWind.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

deleteWindows

# Create entries in the option database to be sure that geometry options
set fixedFont {Courier -12}
set fixedHeight [font metrics $fixedFont -linespace]
set fixedWidth [font measure $fixedFont m]
set fixedAscent [font metrics $fixedFont -ascent]

# like border width have predictable values.
# On Windows at least, the tests do work with {Courier -10}, {Courier -12} or {Courier -14} as fixedFont.
# Warn the user if the actual font is too different from what was requested.
if {[font metrics [font actual $fixedFont] -fixed] != 1} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
does not seem to be a fixed-width font as expected. If this is really the case, many upcoming\
tests will fail."
}
if {$fixedHeight < 12 || $fixedHeight > 17} {

option add *Text.borderWidth 2
option add *Text.highlightThickness 2
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
is $fixedHeight pixels height while the tests expect between 12 and 17 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}
option add *Text.font {"Courier New" -12}

if {$fixedWidth < 6 || $fixedWidth > 8} {
    puts "---> Warning: the font actually used by the tests, which is \"[font actual $fixedFont]\",\
is $fixedWidth pixels in width while the tests expect between 6 and 8 (inclusive) pixels.\
Some of the upcoming tests will probably fail."
}

# Widget used in almost all tests

deleteWindows
# Widget used in tests 1.* - 16.*
# Option  -width 30  (characters) below is a fundamental assumption of many
# upcoming tests when wrapping enters in play
# Also  -height 6  (lines) is an important assumption
# Moreover the widget must have the same padding in x and y (see proc bo)
# However the tests are not sensitive to  -borderwidth  and  -highlightthickness
text .t -font $fixedFont -width 30 -height 6 -borderwidth 2 -highlightthickness 2
text .t -width 30 -height 6 -bd 2 -highlightthickness 2
pack .t -expand 1 -fill both
update
.t debug on

wm geometry . {}

# 15 on XP, 13 on Solaris 8
# full border size of the text widget, i.e. first x or y coordinate inside the text widget
# warning:  -padx  is supposed to be the same as  -pady  (same border size horizontally and
# vertically around the widget)
proc bo {{w .t}} {
    return [expr {[$w cget -borderwidth] + [$w cget -highlightthickness] + [$w cget -padx]}]
}
# x-width of $n chars, fixed width font
proc xw {n} {
    global fixedWidth
    return [expr {$n * $fixedWidth}]
}
# x-coordinate of the first pixel of $n-th char (count starts at zero), left justified
proc xchar {n {w .t}} {
    return [expr {[bo $w] + [xw $n]}]
}
# y-coordinate of the first pixel of $l-th display line (count starts at 1)
proc yline {l {w .t}} {
    global fixedHeight
set fixedHeight [font metrics {"Courier New" -12} -linespace]
    return [expr {[bo $w] + ($l - 1) * $fixedHeight}]
}

set fixedDiff [expr {$fixedHeight - 13}] ;# 2 on XP
set color [expr {[winfo depth .t] > 1 ? "green" : "black"}]

wm geometry . {}

# The statements below reset the main window;  it's needed if the window
# manager is mwm to make mwm forget about a previous minimum size setting.

wm withdraw .
wm minsize . 1 1
wm positionfrom . user
wm deiconify .

# This update is needed on MacOS to make sure that the window is mapped
# when the tests begin.

update

# ----------------------------------------------------------------------

test textWind-1.1 {basic tests of options} -setup {
test textWind-1.1 {basic tests of options} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    frame .f -width 3 -height 3 -bg $color
    .t window create 2.2 -window .f
    update
    list [winfo ismapped .f] [winfo geom .f] [.t bbox .f] \
        [.t window configure .f -window]
} -result [list \
    1 \
    3x3+[xchar 2]+[expr {[yline 2]+($fixedHeight-3)/2}] \
    [list [xchar 2] [expr {[yline 2]+($fixedHeight-3)/2}] 3 3] \
    {-window {} {} {} .f}]
} -result {1 3x3+19+23 {19 23 3 3} {-window {} {} {} .f}}

test textWind-1.2 {basic tests of options} -setup {
test textWind-1.2 {basic tests of options} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    frame .f -width 3 -height 3 -bg $color
    .t window create 2.2 -window .f -align top
    update
    list [winfo ismapped .f] [winfo geom .f] [.t bbox .f] \
        [.t window configure .f -align]
} -result [list \
    1 \
    3x3+[xchar 2]+[yline 2] \
    [list [xchar 2] [yline 2] 3 3] \
    {-align {} {} center top}]
} -result {1 3x3+19+18 {19 18 3 3} {-align {} {} center top}}

test textWind-1.3 {basic tests of options} -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    .t window create 2.2 -create "Test script"
    .t window configure 2.2 -create
} -result {-create {} {} {} {Test script}}

test textWind-1.4 {basic tests of options} -setup {
test textWind-1.4 {basic tests of options} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    # the window .f should be wider than the fixed width
    frame .f -width 10 -height 20 -bg $color
    .t window create 2.2 -window .f -padx 5
    update
    list [winfo geom .f] [.t window configure .f -padx] [.t bbox 2.3]
} -result [list \
    10x20+[expr {[xchar 2]+5}]+[yline 2] \
    {-padx {} {} 0 5} \
} -result {10x20+24+18 {-padx {} {} 0 5} {39 21 7 13}}
    [list [expr {[xchar 2]+10+2*5}] [expr {[yline 2]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]]

test textWind-1.5 {basic tests of options} -setup {
test textWind-1.5 {basic tests of options} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    frame .f -width 10 -height 20 -bg $color
    .t window create 2.2 -window .f -pady 4
    update
    list [winfo geom .f] [.t window configure .f -pady] [.t bbox 2.31]
} -result [list \
    10x20+[xchar 2]+[expr {[yline 2]+4}] \
    {-pady {} {} 0 4} \
} -result {10x20+19+22 {-pady {} {} 0 4} {19 46 7 13}}
    [list [xchar 2] [expr {[yline 2]+20+2*4}] $fixedWidth $fixedHeight]]

test textWind-1.6 {basic tests of options} -setup {
test textWind-1.6 {basic tests of options} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    frame .f -width 5 -height 5 -bg $color
    .t window create 2.2 -window .f -stretch 1
    update
    list [winfo geom .f] [.t window configure .f -stretch]
} -result [list \
    5x$fixedHeight+[xchar 2]+[yline 2] \
} -result {5x13+19+18 {-stretch {} {} 0 1}}

    {-stretch {} {} 0 1}]

.t delete 1.0 end
.t insert end "This is the first line"
test textWind-2.1 {TkTextWindowCmd procedure} -body {
    .t window
} -returnCodes error -result {wrong # args: should be ".t window option ?arg ...?"}
test textWind-2.2 {TkTextWindowCmd procedure, "cget" option} -body {
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149







-
+







    destroy .f
} -body {
    frame .f -width 10 -height 6 -bg $color
    .t window create 1.3 -window .f -padx 1 -pady 2
    .t window cget .f -pady
} -cleanup {
    destroy .f
} -returnCodes ok -result 2
} -returnCodes ok -result {2}
test textWind-2.8 {TkTextWindowCmd procedure} -body {
    .t window co
} -returnCodes error -result {wrong # args: should be ".t window configure index ?-option value ...?"}
test textWind-2.9 {TkTextWindowCmd procedure} -body {
    .t window configure gorp
} -returnCodes error -result {bad text index "gorp"}
test textWind-2.10 {TkTextWindowCmd procedure} -body {
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193







+















+







    .t window create 2.2 -window .f -align baseline -padx 1 -pady 2 -create foo
    update
    .t window configure .f
} -cleanup {
    destroy .f
} -result  {{-align {} {} center baseline} {-create {} {} {} foo} {-padx {} {} 0 1} {-pady {} {} 0 2} {-stretch {} {} 0 0} {-window {} {} {} .f}}
test textWind-2.12 {TkTextWindowCmd procedure} -setup {
# I kept this as it "influenced" the test case in previous releases
    destroy .f
    frame .f -width 10 -height 6 -bg $color
    .t window create 2.2 -window .f -align baseline -padx 1 -pady 2 -create foo
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
    frame .f -width 10 -height 6 -bg $color
    .t window create 2.2 -window .f -align baseline -padx 1 -pady 2 -create foo
    update
    list [.t window configure .f -padx 33] [.t window configure .f -padx]
} -cleanup {
    destroy .f
} -result {{} {-padx {} {} 0 33}}
test textWind-2.13 {TkTextWindowCmd procedure} -setup {
# I kept this as it "influenced" the test case in previous releases
    destroy .f
    frame .f -width 10 -height 6 -bg $color
    .t window create 2.2 -window .f -align baseline -padx 1 -pady 2 -create foo
    .t delete 1.0 end
} -body {
    .t insert end "This is the first line"
    .t insert end "\nAnd this is a second line, which wraps around"
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247







+
















+









+







} -returnCodes error -result {wrong # args: should be ".t window create index ?-option value ...?"}
test textWind-2.15 {TkTextWindowCmd procedure} -setup {
    .t delete 1.0 end
} -body {
    .t window create gorp
} -returnCodes error -result {bad text index "gorp"}
test textWind-2.16 {TkTextWindowCmd procedure, don't insert after end} -setup {
# I kept this as it "influenced" the test case in previous releases
    destroy .f
    frame .f -width 10 -height 6 -bg $color
    .t window create 2.2 -window .f -align baseline -padx 1 -pady 2
    .t delete 1.0 end
} -body {
    .t insert end "Line 1\nLine 2"
    frame .f -width 20 -height 10 -bg $color
    .t window create end -window .f
    .t index .f
} -result {2.6}
test textWind-2.17 {TkTextWindowCmd procedure} -setup {
    .t delete 1.0 end
} -body {
    list [catch {.t window create 1.0} msg] $msg [.t window configure 1.0]
} -result {0 {} {{-align {} {} center center} {-create {} {} {} {}} {-padx {} {} 0 0} {-pady {} {} 0 0} {-stretch {} {} 0 0} {-window {} {} {} {}}}}
test textWind-2.18 {TkTextWindowCmd procedure} -setup {
# I kept this as it "influenced" the test case in previous releases
    destroy .f
    frame .f -width 20 -height 10 -bg $color
    .t window create end -window .f
    .t delete 1.0 end
} -body {
    frame .f -width 10 -height 6 -bg $color
    .t window create 1.0 -window .f -gorp stupid
} -returnCodes error -result {unknown option "-gorp"}
test textWind-2.19 {TkTextWindowCmd procedure} -setup {
# I kept this as it "influenced" the test case in previous releases
    destroy .f
    frame .f -width 20 -height 10 -bg $color
    .t window create end -window .f
    .t delete 1.0 end
} -body {
    frame .f -width 10 -height 6 -bg $color
    catch {.t window create 1.0 -window .f -gorp stupid}
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
387

388

389
390
391

392
393
394

395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417

418

419
420
421

422
423
424

425
426
427
428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501
502
503
504
505
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303


304
305
306
307
308
309
310
311
312
313
314
315
316


317
318
319
320
321
322
323

324
325
326

327
328
329

330



331
332
333
334
335
336
337
338
339
340
341
342
343


344
345
346
347
348
349
350

351
352
353

354
355
356

357



358
359
360
361
362
363
364
365
366
367
368
369

370


371
372
373
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433







+










-
-
+












-
-
+






-


+
-
+


-
+
-
-
-
+












-
-
+






-


+
-
+


-
+
-
-
-
+











-
+
-
-











-










-











-







-












+




-







        frame $i -width 20 -height 20
        .t window create end -window $i
    }
    lsort [.t window names]
} -cleanup {
    destroy .f .f2 .t.f .t.f2
} -result {.f .f2 .t.f .t.f2}


test textWind-3.1 {EmbWinConfigure procedure} -setup {
    destroy .f
} -body {
    frame .f -width 10 -height 6 -bg $color
    .t window create 1.0 -window .f
    .t window configure 1.0 -foo bar
} -cleanup {
    destroy .f
} -returnCodes error -result {unknown option "-foo"}

test textWind-3.2 {EmbWinConfigure procedure} -setup {
test textWind-3.2 {EmbWinConfigure procedure} -constraints fonts -setup {
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.3 -window .f
    update
    .t window configure 1.3 -window {}
    update
    .t index .f
} -cleanup {
    destroy .f
} -returnCodes error -result {bad text index ".f"}

test textWind-3.3 {EmbWinConfigure procedure} -setup {
test textWind-3.3 {EmbWinConfigure procedure} -constraints fonts -setup {
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.3 -window .f
    update
    set res [winfo ismapped .f]
    .t window configure 1.3 -window {}
    update
    catch {.t index .f}
    lappend res [winfo ismapped .f] [.t bbox 1.4]
    list [winfo ismapped .f] [.t bbox 1.4]
} -cleanup {
    destroy .f
} -result [list 1 0 \
} -result {0 {26 5 7 13}}
    [list [xchar 3] [yline 1] $fixedWidth $fixedHeight]]

test textWind-3.4 {EmbWinConfigure procedure} -setup {
test textWind-3.4 {EmbWinConfigure procedure} -constraints fonts -setup {
    destroy .t.f
} -body {
    .t insert 1.0 "Some sample text"
    frame .t.f -width 10 -height 20 -bg $color
    .t window create 1.3 -window .t.f
    update
    .t window configure 1.3 -window {}
    update
    .t index .t.f
} -cleanup {
    destroy .t.f
} -returnCodes error -result {bad text index ".t.f"}

test textWind-3.5 {EmbWinConfigure procedure} -setup {
test textWind-3.5 {EmbWinConfigure procedure} -constraints fonts -setup {
    destroy .t.f
} -body {
    .t insert 1.0 "Some sample text"
    frame .t.f -width 10 -height 20 -bg $color
    .t window create 1.3 -window .t.f
    update
    set res [winfo ismapped .t.f]
    .t window configure 1.3 -window {}
    update
    catch {.t index .t.f}
    lappend res [winfo ismapped .t.f] [.t bbox 1.4]
    list [winfo ismapped .t.f] [.t bbox 1.4]
} -cleanup {
    destroy .t.f
} -result [list 1 0 \
} -result {0 {26 5 7 13}}
    [list [xchar 3] [yline 1] $fixedWidth $fixedHeight]]

test textWind-3.6 {EmbWinConfigure procedure} -setup {
test textWind-3.6 {EmbWinConfigure procedure} -constraints fonts -setup {
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.3
    update
    .t window configure 1.3 -window .f
    update
    list [catch {.t index .f} msg] $msg [winfo ismapped .f] [.t bbox 1.4]
} -cleanup {
    destroy .f
} -result [list 0 1.3 1 \
} -result {0 1.3 1 {36 8 7 13}}
    [list [expr {[xchar 3]+10}] [expr {[yline 1]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]]

test textWind-3.7 {EmbWinConfigure procedure} -setup {
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f
    frame .f.f -width 15 -height 20 -bg $color
    pack .f.f
    .t window create 1.3 -window .f.f
} -cleanup {
    destroy .f
} -returnCodes error -result {can't embed .f.f in .t}

test textWind-3.8 {EmbWinConfigure procedure} -setup {
    destroy .t2
} -body {
    .t insert 1.0 "Some sample text"
    toplevel .t2 -width 20 -height 10 -bg $color
    .t window create 1.3
    .t window configure 1.3 -window .t2
} -cleanup {
    destroy .t2
} -returnCodes error -result {can't embed .t2 in .t}

test textWind-3.9 {EmbWinConfigure procedure} -setup {
    destroy .t2
} -body {
    .t insert 1.0 "Some sample text"
    toplevel .t2 -width 20 -height 10 -bg $color
    .t window create 1.3
    catch {.t window configure 1.3 -window .t2}
    .t window configure 1.3 -window
} -cleanup {
    destroy .t2
} -result {-window {} {} {} {}}

test textWind-3.10 {EmbWinConfigure procedure} -setup {
    .t delete 1.0 end
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.3
    .t window configure 1.3 -window .t
} -returnCodes error -result {can't embed .t in .t}

test textWind-3.11 {EmbWinConfigure procedure} -setup {
    .t delete 1.0 end
} -body {
    # This test checks for various errors when the text claims
    # a window away from itself.
    .t insert 1.0 "Some sample text"
    button .t.b -text "Hello!"
    .t window create 1.4 -window .t.b
    .t window create 1.6 -window .t.b
    update
    .t index .t.b
} -result {1.6}


.t delete 1.0 end
frame .f -width 10 -height 20 -bg $color
.t window create 1.0 -window .f

test textWind-4.1 {AlignParseProc and AlignPrintProc procedures} -body {
    .t window configure 1.0 -align baseline
    .t window configure 1.0 -align
} -result {-align {} {} center baseline}
test textWind-4.2 {AlignParseProc and AlignPrintProc procedures} -body {
    .t window configure 1.0 -align bottom
    .t window configure 1.0 -align
518
519
520
521
522
523
524

525

526
527
528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548

549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573
574
575
576

577
578
579
580

581
582
583
584
585
586
587
588
589
590
591
592


593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609


610
611
612
613
614



615
616
617
618
619
620
621
622
623
624
625
626
627
628


629
630
631


632
633
634
635
636
637
638
639
640
641
642
643
644
645


646
647
648

649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664


665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704



705
706
707
708
709
710
711
712

713
714
715
716
717
718
719
720
721

722
723
724



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744













745
746
747
748

749


750
751
752
753
754
755
756
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462
463
464


465
466
467
468
469
470
471
472
473
474
475

476




477
478
479
480
481
482
483
484
485
486
487
488


489
490
491
492
493
494
495
496
497
498
499

500




501
502
503
504
505
506
507
508
509
510
511


512
513

514

515
516
517
518
519
520
521
522
523
524
525
526
527


528
529



530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545


546
547



548
549
550
551
552
553
554
555
556
557
558
559
560
561


562
563

564

565
566
567
568
569
570
571
572
573
574
575






576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617


618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
635


636



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654





655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681







+
-
+










-
-
+










-
+
-
-
-
-
+











-
-
+










-
+
-
-
-
-
+










-
-
+
+
-

-
+












-
-
+
+
-
-
-

-
+
+
+












-
-
+
+
-
-
-
+
+












-
-
+
+
-

-
+










-
-
-
-
-
-
+
+











+













+














-
-
+
+
+







-
+







-
-
+
-
-
-
+
+
+















-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+




+
-
+
+







} -returnCodes error -result {bad align "gorp": must be baseline, bottom, center, or top}
test textWind-4.6 {AlignParseProc and AlignPrintProc procedures} -body {
    .t window configure 1.0 -align top
    catch {.t window configure 1.0 -align gorp}
    .t window configure 1.0 -align
} -result {-align {} {} center top}


test textWind-5.1 {EmbWinStructureProc procedure} -setup {
test textWind-5.1 {EmbWinStructureProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    destroy .f
    .t index .f
} -returnCodes error -result {bad text index ".f"}

test textWind-5.2 {EmbWinStructureProc procedure} -setup {
test textWind-5.2 {EmbWinStructureProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    destroy .f
    catch {.t index .f}
    list [.t bbox 1.2] [.t bbox 1.3]
} -result [list \
} -result {{19 11 0 0} {19 5 7 13}}
    [list [xchar 2] [expr {[yline 1]+$fixedHeight/2}] 0 0] \
    [list [xchar 2] [yline 1] $fixedWidth $fixedHeight]]

test textWind-5.3 {EmbWinStructureProc procedure} -setup {
test textWind-5.3 {EmbWinStructureProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -align bottom
    .t window configure 1.2 -window .f
    update
    destroy .f
    .t index .f
} -returnCodes error -result {bad text index ".f"}

test textWind-5.4 {EmbWinStructureProc procedure} -setup {
test textWind-5.4 {EmbWinStructureProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -align bottom
    .t window configure 1.2 -window .f
    update
    destroy .f
    catch {.t index .f}
    list [.t bbox 1.2] [.t bbox 1.3]
} -result [list \
} -result {{19 18 0 0} {19 5 7 13}}
    [list [xchar 2] [yline 2] 0 0] \
    [list [xchar 2] [yline 1] $fixedWidth $fixedHeight]]

test textWind-5.5 {EmbWinStructureProc procedure} -setup {
test textWind-5.5 {EmbWinStructureProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.2 -create {frame .f -width 10 -height 20 -bg $color}
    update
    .t window configure 1.2 -create {frame .f -width 20 -height 10 -bg $color}
    destroy .f
    update
    list [catch {.t index .f} msg] $msg [.t bbox 1.2] [.t bbox 1.3]
} -result [list 0 1.2 \
    [list [xchar 2] [expr {[yline 1]+($fixedHeight-10)/2}] 20 10] \
} -result {0 1.2 {19 6 20 10} {39 5 7 13}}

    [list [expr {[xchar 2]+20}] [yline 1] $fixedWidth $fixedHeight]]

test textWind-6.1 {EmbWinRequestProc procedure} -setup {
test textWind-6.1 {EmbWinRequestProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
    set result {}
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    lappend result [.t bbox 1.2] [.t bbox 1.3]
    .f configure -width 25 -height 30
    lappend result [.t bbox 1.2] [.t bbox 1.3]
} -cleanup {
    destroy .f
} -result [list \
    [list [xchar 2] [yline 1] 10 20] \
} -result {{19 5 10 20} {29 8 7 13} {19 5 25 30} {44 13 7 13}}

    [list [expr {[xchar 2]+10}] [expr {[yline 1]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight] \
    [list [xchar 2] [yline 1] 25 30] \
    [list [expr {[xchar 2]+25}] [expr {[yline 1]+(30-$fixedHeight)/2}] $fixedWidth $fixedHeight]]

test textWind-7.1 {EmbWinLostContentProc procedure} -setup {
test textWind-7.1 {EmbWinLostSlaveProc procedure} -constraints {
    textfonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    place .f -in .t -x 100 -y 50
    update
    list [winfo geom .f] [.t bbox 1.2]
} -cleanup {
    destroy .f
} -result [list \
    10x20+[expr {[bo]+100}]+[expr {[bo]+50}] \
} -result [list 10x20+105+55 [list 19 [expr {11+$fixedDiff/2}] 0 0]]
test textWind-7.2 {EmbWinLostSlaveProc procedure} -constraints {
    [list [xchar 2] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-7.2 {EmbWinLostContentProc procedure} -setup {
    textfonts
} -setup {
    .t delete 1.0 end
    destroy .t.f
} -body {
    .t insert 1.0 "Some sample text"
    frame .t.f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .t.f
    update
    place .t.f -x 100 -y 50
    update
    list [winfo geom .t.f] [.t bbox 1.2]
} -cleanup {
    destroy .t.f
} -result [list \
    10x20+[expr {[bo]+100}]+[expr {[bo]+50}] \
} -result [list 10x20+105+55 [list 19 [expr {11+$fixedDiff/2}] 0 0]]

    [list [xchar 2] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-8.1 {EmbWinDeleteProc procedure} -setup {
test textWind-8.1 {EmbWinDeleteProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    bind .f <Destroy> {set x destroyed}
    set x XXX
    .t delete 1.2
    list $x [.t bbox 1.2] [.t bbox 1.3] [winfo exists .f]
} -result [list destroyed \
    [list [xchar 2] [yline 1] $fixedWidth $fixedHeight] \
    [list [xchar 3] [yline 1] $fixedWidth $fixedHeight] \
    0]

test textWind-8.2 {EmbWinDeleteProc procedure} -setup {
} -result {destroyed {19 5 7 13} {26 5 7 13} 0}
test textWind-8.2 {EmbWinDeleteProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 10 -height 20 -bg $color
    .t window create 1.2 -window .f
    bind .f <Destroy> {set x destroyed}
    set x XXX
    .t delete 1.2
    .t index .f
} -returnCodes error -result {bad text index ".f"}


test textWind-9.1 {EmbWinCleanupProc procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text\nA second line."
    frame .f -width 10 -height 20 -bg $color
    .t window create 2.3 -window .f
    .t delete 1.5 2.1
    .t index .f
} -cleanup {
    destroy .f
} -result {1.7}


test textWind-10.1 {EmbWinLayoutProc procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.5 -create {
        frame .f -width 10 -height 20 -bg $color
    }
    update
    list [winfo exists .f] [winfo width .f] [winfo height .f] [.t index .f]
} -cleanup {
    destroy .f
} -result {1 10 20 1.5}

test textWind-10.2 {EmbWinLayoutProc procedure, error in creating window} -setup {
test textWind-10.2 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    proc bgerror args {
        global msg
        set msg $args
    }
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.5 -create {
        .t window create 1.5 -create {
        error "couldn't create window"
    }
    set msg xyzzy
    update
    list $msg [.t bbox 1.5]
} -cleanup {
    rename bgerror {}
} -result [list \
    {{couldn't create window}} \
} -result {{{couldn't create window}} {40 11 0 0}}
    [list [xchar 5] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-10.3 {EmbWinLayoutProc procedure, error in creating window} -setup {
test textWind-10.3 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    proc bgerror args {
        global msg
        set msg $args
    }
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.5 -create {
        concat gorp
    }
    set msg xyzzy
    update
    list $msg [.t bbox 1.5]
} -cleanup {
    rename bgerror {}
} -result [list \
    {{bad window path name "gorp"}} \
    [list [xchar 5] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-10.4 {EmbWinLayoutProc procedure, error in creating window} -setup {
} -result {{{bad window path name "gorp"}} {40 11 0 0}}
    .t delete 1.0 end
    destroy .t.f
    proc bgerror args {
        global msg
        if {[lsearch -exact $msg $args] == -1} {
            lappend msg $args
        }
    }

test textWind-10.4 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    textfonts
} -setup {
    .t delete 1.0 end
    destroy .t.f
    proc bgerror args {
        global msg
        if {[lsearch -exact $msg $args] == -1} {
	lappend msg $args
            lappend msg $args
        }
    }
} -body {
    .t insert 1.0 "Some sample text"
    set msg {}
    after idle {
        .t window create 1.5 -create {
            frame .t.f
764
765
766
767
768
769
770
771
772

773
774
775
776



777
778
779
780
781
782
783



784
785
786
787
788
789
790
791

792

793
794
795
796
797
798
799




800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819

820
821
822



823
824
825
826

827


828
829
830
831
832
833
834
835
836
837

838
839
840
841
842

843
844
845
846
847
848
849

850


851
852
853
854
855
856
857
689
690
691
692
693
694
695


696




697
698
699
700
701
702
703



704
705
706
707
708
709

710
711
712
713
714

715
716
717
718
719
720


721
722
723
724
725
726
727

728
729
730
731
732
733

734
735
736
737
738
739
740
741


742



743
744
745
746
747
748
749
750

751
752
753
754
755
756
757
758
759
760
761

762
763
764
765


766


767
768
769
770
771
772

773
774
775
776
777
778
779
780
781







-
-
+
-
-
-
-
+
+
+




-
-
-
+
+
+



-




+
-
+





-
-
+
+
+
+



-
+





-








-
-
+
-
-
-
+
+
+




+
-
+
+









-
+



-
-
+
-
-





+
-
+
+







        .t bbox 1.5
        after 10
    }
    lappend msg [.t bbox 1.5] [winfo exists .t.f.f]
} -cleanup {
    destroy .t.f
    rename bgerror {}
} -result [list \
    {{can't embed .t.f.f relative to .t}} {{window name "f" already exists in parent}} \
} -result [list {{can't embed .t.f.f relative to .t}} {{window name "f" already exists in parent}} [list 40 [expr {11+$fixedDiff/2}] 0 0] 1]
    [list [xchar 5] [expr {[yline 1]+$fixedHeight/2}] 0 0] \
    1]

test textWind-10.5 {EmbWinLayoutProc procedure, error in creating window} -setup {
test textWind-10.5 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    textfonts
} -setup {
    .t delete 1.0 end
    destroy .t.f
    proc bgerror args {
        global msg
        if {$msg == ""} {
	    lappend msg $args
	}
        if {[lsearch -exact $msg $args] == -1} {
            lappend msg $args
        }
    }
} -body {
    .t insert 1.0 "Some sample text"
    set msg {}
    .t window create 1.5 -create {
        frame .t.f
        frame .t.f.f -width 10 -height 20 -bg $color
    }
    set msg {}
    update
    update idletasks
    lappend msg [winfo exists .t.f.f]
} -cleanup {
    destroy .t.f
    rename bgerror {}
} -result {{{can't embed .t.f.f relative to .t}} 1}

test textWind-10.6 {EmbWinLayoutProc procedure, error in creating window} -setup {
catch {destroy .t.f}
test textWind-10.6 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    textfonts
} -setup {
    .t delete 1.0 end
    proc bgerror args {
        global msg
        if {[lsearch -exact $msg $args] < 0} {
        if {[lsearch -exact $msg $args] == -1} {
            lappend msg $args
        }
    }
} -body {
    .t insert 1.0 "Some sample text"
    update
    .t window create 1.5 -create {
        concat .t
    }
    set msg {}
    update
    lappend msg [.t bbox 1.5]
} -cleanup {
    rename bgerror {}
} -result [list \
    {{can't embed .t relative to .t}} \
} -result [list {{can't embed .t relative to .t}} [list 40 [expr {11+$fixedDiff/2}] 0 0]]
    [list [xchar 5] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-10.7 {EmbWinLayoutProc procedure, error in creating window} -setup {
test textWind-10.7 {EmbWinLayoutProc procedure, error in creating window} -constraints {
    textfonts
} -setup {
    .t delete 1.0 end
    destroy .t2
    proc bgerror args {
        global msg
        if {[lsearch -exact $msg $args] == -1} {
	lappend msg $args
            lappend msg $args
        }
    }
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.5 -create {
        toplevel .t2 -width 100 -height 150
        wm geom .t2 +0+0
        concat .t2
    }
    set msg {}
    update idletasks ; after 100 ; update
    update
    lappend msg [.t bbox 1.5]
} -cleanup {
    rename bgerror {}
} -result [list \
    {{can't embed .t2 relative to .t}} {{window name "t2" already exists in parent}} \
} -result [list {{can't embed .t2 relative to .t}} {{window name "t2" already exists in parent}} [list 40 [expr {11+$fixedDiff/2}] 0 0]]
    [list [xchar 5] [expr {[yline 1]+$fixedHeight/2}] 0 0]]

test textWind-10.8 {EmbWinLayoutProc procedure, error in creating window} -setup {
    .t delete 1.0 end
    destroy .t2
    proc bgerror args {
        global msg
        if {[lsearch -exact $msg $args] == -1} {
	lappend msg $args
            lappend msg $args
        }
    }
} -body {
    .t insert 1.0 "Some sample text"
    .t window create 1.5 -create {
        toplevel .t2 -width 100 -height 150
        wm geom .t2 +0+0
        concat .t2
876
877
878
879
880
881
882
883
884



885
886
887
888
889
890

891
892
893
894
895

896
897
898
899



900
901
902
903
904
905

906
907
908
909
910
911

912
913
914
915



916
917
918
919
920
921

922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937

938
939
940
941
942
943

944
945
946
947



948
949
950
951
952
953

954
955
956
957
958
959

960
961
962
963



964
965
966
967
968
969
970
971
972
973
974
975
976


977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046



1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064

1065
1066
1067
1068
1069



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089




1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212

1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

1239
1240
1241
1242



1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257


1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1338

1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353


1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421

1422

1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462

1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585



1586
1587
1588
1589
1590
1591
1592
1593
1594

1595
1596

1597
1598

1599
1600

1601
1602
1603

1604
1605

1606
1607
1608
1609
1610
1611

1612
1613
1614
1615
1616

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
800
801
802
803
804
805
806


807
808
809
810
811
812
813
814

815
816
817
818
819

820




821
822
823
824
825
826
827
828

829
830
831
832
833
834

835




836
837
838
839
840
841
842
843

844
845
846
847
848
849

850



851
852
853
854
855
856

857
858
859
860
861
862

863




864
865
866
867
868
869
870
871

872
873
874
875
876
877

878




879
880
881
882
883
884
885
886
887
888
889
890
891
892


893
894

895
896
897
898
899
900


901
902
903
904

905
906
907
908
909
910
911


912
913
914
915
916
917


918
919
920
921

922
923
924
925
926
927
928
929


930
931
932
933
934
935


936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951


952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971

972





973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992



993
994
995
996


997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038




1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049

1050




1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

1062




1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074




1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085

1086




1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097

1098




1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109

1110




1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122




1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136

1137


1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215


1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229


1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266





1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382

1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444

1445










1446
1447
1448









1449


1450


1451


1452



1453
1454

1455






1456


1457
1458

1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475
1476
1477

































1478
1479
1480
1481
1482







-
-
+
+
+





-
+




-
+
-
-
-
-
+
+
+





-
+





-
+
-
-
-
-
+
+
+





-
+





-
+
-
-
-






-
+





-
+
-
-
-
-
+
+
+





-
+





-
+
-
-
-
-
+
+
+











-
-
+
+
-






-
-




-







-
-
+





-
-




-








-
-
+





-
-
















-
-
+
+
+

















-
+
-
-
-
-
-
+
+
+

















-
-
-
+
+
+
+
-
-


















-










+












-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+










-
+
-
-
-
-
+
+
+











-

-
-
+
+
-




















-



















-















-















+






-
-
+













-
-
+
+
















-


















-
+
-
-
-
-
-












-














+
-
+










-
+


-
+










-
+














-
+















-
+

















-
+














-
+















-
+














-
+















-
+









-





-

-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
+

-
+
-
-
-
-
-
-
+
-
-


-
+













-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





    update
    .t window create 1.3 -create {concat .t.b}
    update
    .t index .t.b
} -cleanup {
    destroy .t.b
} -result {1.3}

test textWind-10.10 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
test textWind-10.10 {EmbWinLayoutProc procedure, doesn't fit on line} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap char
    .t insert 1.0 "Some sample text"
    frame .f -width [expr {([.t cget -width]-12)*$fixedWidth-1}] -height 20 -bg $color -bd 2 -relief raised
    frame .f -width 125 -height 20 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
} -result {{89 5 126 20} {5 25 7 13}}
    [list [xchar 12] [yline 1] [xw [expr {[.t cget -width]-12}]] 20] \
    [list [xchar 0] [expr {[yline 1]+20}] $fixedWidth $fixedHeight]]

test textWind-10.11 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
test textWind-10.11 {EmbWinLayoutProc procedure, doesn't fit on line} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap char
    .t insert 1.0 "Some sample text"
    frame .f -width [expr {([.t cget -width]-12)*$fixedWidth}] -height 20 -bg $color -bd 2 -relief raised
    frame .f -width 126 -height 20 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    update
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
} -result {{89 5 126 20} {5 25 7 13}}
    [list [xchar 12] [yline 1] [xw [expr {[.t cget -width]-12}]] 20] \
    [list [xchar 0] [expr {[yline 1]+20}] $fixedWidth $fixedHeight]]

test textWind-10.12 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
test textWind-10.12 {EmbWinLayoutProc procedure, doesn't fit on line} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap char
    .t insert 1.0 "Some sample text"
    frame .f -width [expr {([.t cget -width]-12)*$fixedWidth+1}] -height 20 -bg $color -bd 2 -relief raised
    frame .f -width 127 -height 20 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    update
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
} -result {{5 18 127 20} {132 21 7 13}}
    [list [xchar 0] [yline 2] [expr {[xw [expr {[.t cget -width]-12}]]+1}] 20] \
    [list [expr {[xchar 0]+[expr {[xw [expr {[.t cget -width]-12}]]+1}]}] [expr {[yline 2]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]]

test textWind-10.13 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap none
    .t insert 1.0 "Some sample text"
    frame .f -width [expr {([.t cget -width]-12)*$fixedWidth+5}] -height 20 -bg $color -bd 2 -relief raised
    frame .f -width 130 -height 20 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    update
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
} -result {{89 5 126 20} {}}
    [list [xchar 12] [yline 1] [xw [expr {[.t cget -width]-12}]] 20] \
    {}]

test textWind-10.14 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
test textWind-10.14 {EmbWinLayoutProc procedure, doesn't fit on line} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap none
    .t insert 1.0 "Some sample text"
    frame .f -width [expr {([.t cget -width]-12)*$fixedWidth+5}] -height 220 -bg $color -bd 2 -relief raised
    frame .f -width 130 -height 220 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    update
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
} -result {{89 5 126 78} {}}
    [list [xchar 12] [yline 1] [xw [expr {[.t cget -width]-12}]] [expr {[.t cget -height]*$fixedHeight}]] \
    {}]

test textWind-10.15 {EmbWinLayoutProc procedure, doesn't fit on line} -setup {
test textWind-10.15 {EmbWinLayoutProc procedure, doesn't fit on line} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap char
    .t insert 1.0 "Some sample text"
    frame .f -width 250 -height 220 -bg $color -bd 2 -relief raised
    .t window create 1.12 -window .f
    update
    list [.t bbox .f] [.t bbox 1.13]
} -cleanup {
    destroy .f
} -result [list \
    [list [xchar 0] [yline 2] [xw [.t cget -width]] [expr {([.t cget -height]-1)*$fixedHeight}]] \
} -result {{5 18 210 65} {}}

    {}]

test textWind-11.1 {EmbWinDisplayProc procedure, geometry transforms} -setup {
    .t delete 1.0 end
    destroy .f
    place forget .t
    pack .t
    # Make sure the Text is mapped before we start
    update
} -body {
    .t insert 1.0 "Some sample text"
    pack forget .t
    place .t -x 30 -y 50
    update
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.12 -window .f
    update
    winfo geom .f
} -cleanup {
    destroy .f
    place forget .t
} -result [list 30x20+[expr {[xchar 12]+30}]+[expr {[yline 1]+50}]]

} -result {30x20+119+55}
test textWind-11.2 {EmbWinDisplayProc procedure, geometry transforms} -setup {
    .t delete 1.0 end
    destroy .t.f
    place forget .t
    pack .t
    # Make sure the Text is mapped before we start
    update
} -body {
    .t insert 1.0 "Some sample text"
    pack forget .t
    place .t -x 30 -y 50
    update
    frame .t.f -width 30 -height 20 -bg $color
    .t window create 1.12 -window .t.f
    update
    winfo geom .t.f
} -cleanup {
    destroy .t.f
    place forget .t
    pack .t
} -result [list 30x20+[xchar 12]+[yline 1]]

} -result {30x20+89+5}
test textWind-11.3 {EmbWinDisplayProc procedure, configuration optimization} -setup {
    .t delete 1.0 end
    destroy .f
    place forget .t
    pack .t
    # Make sure the Text is mapped before we start
    update
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.12 -window .f
    update
    bind .f <Configure> {set x ".f configured"}
    set x {no configures}
    .t delete 1.0
    .t insert 1.0 "X"
    update
    return $x
} -cleanup {
    destroy .f
    place forget .t
    pack .t
} -result {no configures}

test textWind-11.4 {EmbWinDisplayProc procedure, horizontal scrolling} -setup {
test textWind-11.4 {EmbWinDisplayProc procedure, horizontal scrolling} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f .f2
} -body {
    .t insert 1.0 "xyzzy\nFirst window here: "
    .t configure -wrap none
    frame .f -width 30 -height 20 -bg $color
    .t window create end -window .f
    .t insert end " and second here: "
    frame .f2 -width 40 -height 10 -bg $color
    .t window create end -window .f2
    .t insert end " with junk after it."
    .t xview moveto 0
    .t xview scroll 5 units
    update
    list [winfo ismapped .f] [winfo geom .f] [.t bbox .f] [winfo ismapped .f2]
} -cleanup {
    destroy .f .f2
} -result [list 1 \
} -result {1 30x20+103+18 {103 18 30 20} 0}
    30x20+[xchar 14]+[yline 2] \
    [list [xchar 14] [yline 2] 30 20] \
    0]

test textWind-11.5 {EmbWinDisplayProc procedure, horizontal scrolling} -setup {
test textWind-11.5 {EmbWinDisplayProc procedure, horizontal scrolling} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f .f2
} -body {
    .t insert 1.0 "xyzzy\nFirst window here: "
    .t configure -wrap none
    frame .f -width 30 -height 20 -bg $color
    .t window create end -window .f
    .t insert end " and second here: "
    frame .f2 -width 40 -height 10 -bg $color
    .t window create end -window .f2
    .t insert end " with junk after it."
    update
    .t xview moveto 0
    .t xview scroll 25 units
    update
    list [winfo ismapped .f] [winfo ismapped .f2] [winfo geom .f2] [.t bbox .f2]
} -cleanup {
  destroy .f .f2
  .t configure -wrap char
} -result [list 0 1 \
    destroy .f .f2
} -result {0 1 40x10+119+23 {119 23 40 10}}
.t configure -wrap char

    40x10+[expr {[xchar [expr {37-25}]]+30}]+[expr {[yline 2]+(20-10)/2}] \
    [list [expr {[xchar [expr {37-25}]]+30}] [expr {[yline 2]+(20-10)/2}] 40 10]]

test textWind-12.1 {EmbWinUndisplayProc procedure, mapping/unmapping} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.2 -window .f
    bind .f <Map> {lappend x mapped}
    bind .f <Unmap> {lappend x unmapped}
    set x created
    update
    lappend x modified
    .t delete 1.0
    update
    lappend x replaced
    .t window configure .f -window {}
    .t delete 1.1
    update
    .t window create 1.4 -window .f
    update
    lappend x off-screen
    .t configure -wrap none
    .t insert 1.0 "Enough text to make the line run off-screen"
    update
    return $x
} -cleanup {
    destroy .f
} -result {created mapped modified replaced unmapped mapped off-screen unmapped}


test textWind-13.1 {EmbWinBboxProc procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align top -padx 2 -pady 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x5+21+6 {21 6 5 5}}
    5x5+[expr {[xchar 2]+2}]+[expr {[yline 1]+1}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1}] 5 5]]

test textWind-13.2 {EmbWinBboxProc procedure} -setup {
test textWind-13.2 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align center -padx 2 -pady 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x5+21+9 {21 9 5 5}}
    5x5+[expr {[xchar 2]+2}]+[expr {[yline 1]+1+(($fixedHeight-7)/2)}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1+(($fixedHeight-7)/2)}] 5 5]]

test textWind-13.3 {EmbWinBboxProc procedure} -setup {
test textWind-13.3 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align baseline -padx 2 -pady 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x5+21+10 {21 10 5 5}}
    5x5+[expr {[xchar 2]+2}]+[expr {[yline 1]+1+($fixedAscent-6)}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1+($fixedAscent-6)}] 5 5]]

test textWind-13.4 {EmbWinBboxProc procedure} -setup {
test textWind-13.4 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align bottom -padx 2 -pady 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x5+21+12 {21 12 5 5}}
    5x5+[expr {[xchar 2]+2}]+[expr {[yline 1]+1+($fixedHeight-7)}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1+($fixedHeight-7)}] 5 5]]

test textWind-13.5 {EmbWinBboxProc procedure} -setup {
test textWind-13.5 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align top -padx 2 -pady 1 -stretch 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x11+21+6 {21 6 5 11}}
    5x[expr {$fixedHeight-2}]+[expr {[xchar 2]+2}]+[expr {[yline 1]+1}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1}] 5 [expr {$fixedHeight-2}]]]

test textWind-13.6 {EmbWinBboxProc procedure} -setup {
test textWind-13.6 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align center -padx 2 -pady 1 -stretch 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x11+21+6 {21 6 5 11}}
    5x[expr {$fixedHeight-2}]+[expr {[xchar 2]+2}]+[expr {[yline 1]+1}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1}] 5 [expr {$fixedHeight-2}]]]

test textWind-13.7 {EmbWinBboxProc procedure} -setup {
test textWind-13.7 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align baseline -padx 2 -pady 1 -stretch 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x9+21+6 {21 6 5 9}}
    5x[expr {$fixedAscent-1}]+[expr {[xchar 2]+2}]+[expr {[yline 1]+1}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1}] 5 [expr {$fixedAscent-1}]]]

test textWind-13.8 {EmbWinBboxProc procedure} -setup {
test textWind-13.8 {EmbWinBboxProc procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align bottom -padx 2 -pady 1 -stretch 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f
} -result [list \
} -result {5x11+21+6 {21 6 5 11}}
    5x[expr {$fixedHeight-2}]+[expr {[xchar 2]+2}]+[expr {[yline 1]+1}] \
    [list [expr {[xchar 2]+2}] [expr {[yline 1]+1}] 5 [expr {$fixedHeight-2}]]]

test textWind-13.9 {EmbWinBboxProc procedure, spacing options} -setup {
test textWind-13.9 {EmbWinBboxProc procedure, spacing options} -constraints {
    fonts
} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -spacing1 5 -spacing3 2
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    frame .f -width 5 -height 5 -bg $color
    .t window create 1.2 -window .f -align center -padx 2 -pady 1
    update
    list [winfo geom .f] [.t bbox .f]
} -cleanup {
    .t configure -spacing1 0 -spacing3 0
    destroy .f
} -result [list \
    5x5+[expr {[xchar 2]+2}]+[expr {[yline 1]+5+(($fixedHeight-5)/2)}] \
} -result {5x5+21+14 {21 14 5 5}}

    [list [expr {[xchar 2]+2}] [expr {[yline 1]+5+(($fixedHeight-5)/2)}] 5 5]]

test textWind-14.1 {EmbWinDelayedUnmap procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    bind .f <Unmap> {lappend x unmapped}
    set x modified
    .t insert 1.0 x
    lappend x removed
    .t window configure .f -window {}
    lappend x updated
    update
    return $x
} -cleanup {
    destroy .f
} -result {modified removed unmapped updated}

test textWind-14.2 {EmbWinDelayedUnmap procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    bind .f <Unmap> {lappend x unmapped}
    set x modified
    .t insert 1.0 x
    lappend x deleted
    .t delete .f
    lappend x updated
    update
    return $x
} -cleanup {
    destroy .f
} -result {modified deleted updated}

test textWind-14.3 {EmbWinDelayedUnmap procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t insert 1.0 "Some sample text\nAnother line\n3\n4\n5\n6\n7\n8\n9"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.2 -window .f
    update
    .t yview 2.0
    set result [winfo ismapped .f]
    update ; after 10
    list $result [winfo ismapped .f]
} -cleanup {
    destroy .f
} -result {1 0}

test textWind-14.4 {EmbWinDelayedUnmap procedure} -setup {
    .t delete 1.0 end
    destroy .t.f
} -body {
    .t insert 1.0 "Some sample text\nAnother line\n3\n4\n5\n6\n7\n8\n9"
    frame .t.f -width 30 -height 20 -bg $color
    .t window create 1.2 -window .t.f
    update
    .t yview 2.0
    set result [winfo ismapped .t.f]
    update
    list $result [winfo ismapped .t.f]
} -cleanup {
    destroy .t.f
} -result {1 0}


test textWind-15.1 {TkTextWindowIndex procedure} -setup {
    .t delete 1.0 end
} -body {
    .t index .foo
} -returnCodes error -result {bad text index ".foo"}

test textWind-15.2 {TkTextWindowIndex procedure} -setup {
test textWind-15.2 {TkTextWindowIndex procedure} -constraints fonts -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -spacing1 0 -spacing2 0 -spacing3 0 \
        -wrap none
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.6 -window .f
    .t tag add a 1.1
    .t tag add a 1.3
    list [.t index .f] [.t bbox 1.7]
} -cleanup {
    destroy .f
} -result [list 1.6 \
    [list [expr {[xchar 6]+30}] [expr {[yline 1]+(20-$fixedHeight)/2}] $fixedWidth $fixedHeight]]
} -result {1.6 {77 8 7 13}}


test textWind-16.1 {EmbWinTextStructureProc procedure} -setup {
    .t delete 1.0 end
    destroy .f
} -body {
    .t configure -wrap none
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.6 -window .f
    update
    pack forget .t
    update
    winfo ismapped .f
} -cleanup {
    pack .t
} -result 0

test textWind-16.2 {EmbWinTextStructureProc procedure} -setup {
    .t delete 1.0 end
    destroy .f .f2
} -body {
    .t configure -spacing1 0 -spacing2 0 -spacing3 0 \
        -wrap none
    .t insert 1.0 "Some sample text"
    frame .f -width 30 -height 20 -bg $color
    .t window create 1.6 -window .f
    update
    set result {}
    lappend result [winfo geom .f] [.t bbox .f]
    frame .f2 -width 150 -height 30 -bd 2 -relief raised
    pack .f2 -before .t
    update
    lappend result [winfo geom .f] [.t bbox .f]
} -cleanup {
    destroy .f .f2
} -result [list \
} -result {30x20+47+5 {47 5 30 20} 30x20+47+35 {47 5 30 20}}
    30x20+[expr {[xchar 6]}]+[yline 1] \
    [list [expr {[xchar 6]}] [yline 1] 30 20] \
    30x20+[expr {[xchar 6]}]+[expr {[yline 1]+30}] \
    [list [expr {[xchar 6]}] [yline 1] 30 20]]

test textWind-16.3 {EmbWinTextStructureProc procedure} -setup {
    .t delete 1.0 end
} -body {
    .t configure -wrap none
    .t insert 1.0 "Some sample text"
    .t window create 1.6
    update
    pack forget .t
    update
} -cleanup {
    pack .t
} -result {}

test textWind-16.4 {EmbWinTextStructureProc procedure} -setup {
    .t delete 1.0 end
} -body {
    .t configure -spacing1 0 -spacing2 0 -spacing3 0 \
        -wrap none
    .t insert 1.0 "Some sample text"
    frame .t.f -width 30 -height 20 -bg $color
    .t window create 1.6 -window .t.f
    update
    pack forget .t
    update
    list [winfo ismapped .t.f] [.t bbox .t.f]
} -cleanup {
    pack .t
} -result {1 {47 5 30 20}}
} -result [list 1 [list [expr {[xchar 6]}] [yline 1] 30 20]]


test textWind-17.1 {peer widgets and embedded windows} -setup {
    destroy .t .tt .f
} -body {
    pack [text .t]
    .t insert end "Line 1"
    frame .f -width 20 -height 10 -bg blue
    .t window create 1.3 -window .f
    toplevel .tt
    pack [.t peer create .tt.t]
    update
    update ; update
    destroy .t .tt
    winfo exists .f
} -result 0
} -result {0}

test textWind-17.2 {peer widgets and embedded windows} -setup {
    destroy .t .f .tt
} -body {
    pack [text .t]
    .t insert end "Line 1\nLine 2"
    frame .f -width 20 -height 10 -bg blue
    .t window create 1.4 -window .f
    toplevel .tt
    pack [.t peer create .tt.t]
    update
    update ; update
    destroy .t
    .tt.t insert 1.0 "foo"
    update
    destroy .tt
} -result {}

test textWind-17.3 {peer widget and -create} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    update
    update ; update
    .t window create 1.2 -create {frame %W.f -width 10 -height 20 -bg blue}
    update
    destroy .t .tt
} -result {}

test textWind-17.4 {peer widget deleted one window shouldn't delete others} -setup {
    destroy .t .tt
    set res {}
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -create {frame %W.f -width 10 -height 20 -bg blue}
    update
    update ; update
    destroy .tt
    lappend res [.t get 1.2]
    update
    lappend res [.t get 1.2]
} -cleanup {
    destroy .t
} -result {{} {}}

test textWind-17.5 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -create {frame %W.f -width 10 -height 20 -bg blue}
    update
    update ; update
    list [.t window cget 1.2 -window] [.tt.t window cget 1.2 -window]
} -cleanup {
    destroy .tt .t
} -result {.t.f .tt.t.f}

test textWind-17.6 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -create {frame %W.f -width 10 -height 20 -bg blue}
    update
    update ; update
    list [.t window configure 1.2 -window] \
        [.tt.t window configure 1.2 -window]
} -cleanup {
    destroy .tt .t
}  -result {{-window {} {} {} .t.f} {-window {} {} {} .tt.t.f}}

test textWind-17.7 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -window [frame .t.f -width 10 -height 20 -bg blue]
    update
    update ; update
    list [.t window cget 1.2 -window] [.tt.t window cget 1.2 -window]
} -cleanup {
    destroy .tt .t
}  -result {.t.f {}}

test textWind-17.8 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -window [frame .t.f -width 10 -height 20 -bg blue]
    update
    update ; update
    list [.t window configure 1.2 -window] \
        [.tt.t window configure 1.2 -window]
} -cleanup {
    destroy .tt .t
}  -result {{-window {} {} {} .t.f} {-window {} {} {} {}}}

test textWind-17.9 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    .t window create 1.2 -window [frame .t.f -width 10 -height 20 -bg blue]
    update
    update ; update
    .tt.t window configure 1.2 -window [frame .tt.t.f -width 10 -height 20 -bg red]
    list [.t window configure 1.2 -window] [.tt.t window configure 1.2 -window]
} -cleanup {
    destroy .tt .t
}  -result {{-window {} {} {} .t.f} {-window {} {} {} .tt.t.f}}

test textWind-17.10 {peer widget window configuration} -setup {
    destroy .t .tt
} -body {
    set res {}
    pack [text .t]
    .t delete 1.0 end
    .t insert 1.0 "Some sample text"
    toplevel .tt
    pack [.t peer create .tt.t]
    update
    .t window create 1.2 -window [frame .t.f -width 10 -height 20 -bg blue]
    update
    # There is a blue window in the main widget .t but not in the peer .tt.t
    lappend res [.t window cget 1.2 -window]
    lappend res [.tt.t window cget 1.2 -window]
    # Insert a green window in the peer. Warning: the blue window previously
    # inserted in .t at index 1.2 will now be found in .t at index 1.3
    # The underlying linked segments are common in a text widget and its peers.
    .tt.t window create 1.2 -window [frame .tt.t.f -width 25 -height 20 -bg green]
    update
    lappend res [.t window cget 1.2 -window]
    .tt.t window create 1.2 -window [frame .tt.t.f -width 25 -height 20 -bg blue]
    update ; update
    .t window configure 1.2 -create \
    lappend res [.t window cget 1.3 -window]
    # In the peer, the green window still is at 1.2, and there is no window at 1.3
    lappend res [.tt.t window cget 1.2 -window]
    lappend res [.tt.t window cget 1.3 -window]
    # Insert a red window in .t at index 1.2. This replaces the blue window originally at 1.2
    # in .t, because the green window inserted in the peer is not visible from .t, therefore
    # the embedded window found at index 1.2 in .t is the one originally at 1.2 in .t, i.e.
    # the blue one
    .t window configure 1.2 -create {destroy %W.f ; update ; frame %W.f -width 50 -height 7 -bg red}
      {destroy %W.f ; frame %W.f -width 50 -height 7 -bg red}
    update
    # The main widget .t still has a window named .t.f at 1.2. This is NOT the blue
    .tt.t window configure 1.2 -window {}
    # frame but the red frame from the -create script, which bears the same name.
    lappend res [.t window cget 1.2 -window]
    .t window configure 1.2 -window {}
    # The peer still has its green .tt.t.f at 1.2
    lappend res [.tt.t window cget 1.2 -window]
    set res [list [.t window configure 1.2 -window] \
    # When removing the -window option the create script plays, therefore .t still has
    # the red frame .t.f at 1.2
    .t window configure 1.2 -window {}
        [.tt.t window configure 1.2 -window]]
    update
    lappend res [.t window cget 1.2 -window]
    lappend res [.t window configure 1.2 -window] \
    # The -create script associated to index 1.2 applies to all peers (that's the reason
    # why the manual states that "If multiple peer widgets are in use, it is usually simpler
    # to use the -create option if embedded windows are desired in each peer."). Therefore
    # when removing the -window option in the peer, the -create script is run, which replaces
    # the green frame by the red one named as per the -create script, i.e. .tt.t.f
    .tt.t window configure 1.2 -window {}
        [.tt.t window configure 1.2 -window]
    update
    lappend res [.tt.t window cget 1.2 -window]
} -cleanup {
    destroy .tt .t
}  -result {.t.f {} {} .t.f .tt.t.f {} .t.f .tt.t.f .t.f .tt.t.f}
}  -result {{-window {} {} {} {}} {-window {} {} {} {}} {-window {} {} {} .t.f} {-window {} {} {} .tt.t.f}}

test textWind-18.1 {embedded window deletion triggered by a script bound to <Map>} -setup {
    catch {destroy .t .f .f2}
} -body {
    pack [text .t]
    for {set i 1} {$i < 100} {incr i} {.t insert end "Line $i\n"}
    .t window create end -window [frame .f -background red -width 80 -height 80]
    .t window create end -window [frame .f2 -background blue -width 80 -height 80]
    bind .f <Map> {.t delete .f}
    update
    # this shall not crash (bug 1501749)
    after 100 {.t yview end}
    tkwait visibility .f2
    after 200
    update
} -cleanup {
    destroy .t .f .f2
} -result {}

test textWind-18.2 {text widget deletion triggered by a script bound to embedded window mapping} -setup {
    catch {destroy .t .f}
} -body {
    pack [text .t]
    for {set i 1} {$i < 100} {incr i} {.t insert end "Line $i\n"}
    .t window create end -window [frame .f -background red -width 80 -height 80]
    bind .f <Map> {destroy .t}
    update
    # this shall not crash (bug 1501749)
    after 100 {.t yview end}
    tkwait window .t
} -cleanup {
    destroy .t .f
} -result {}

test textWind-18.3 {embedded window destruction in cascade} -setup {
    catch {destroy .t .f}
    set x 0
} -body {
    pack [text .t]
    button .t.b1
    .t window create 1.0 -window .t.b1
    bind .t.b1 <Destroy> {destroy .t.b2 ; set x 1}
    button .t.b2
    .t window create 2.0 -window .t.b2
    update
    # this shall not crash (bug 54fe7a5e71)
    after 100 {.t delete 1.0 end}
    tkwait variable x
} -cleanup {
    destroy .t .f
} -result {}

option clear

# cleanup
cleanupTests
return

Changes to tests/tk.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
1
2
3



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40



-
-
-
+
+
+













-
+












-
+







# This file is a Tcl script to test the tk command.
# It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 2002 ActiveState Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 2002 ActiveState Corporation.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint testprintf [llength [info command testprintf]]

test tk-1.1 {tk command: general} -body {
    tk
} -returnCodes error -result {wrong # args: should be "tk subcommand ?arg ...?"}
test tk-1.2 {tk command: general} -body {
    tk xyz
} -returnCodes error -result {unknown or ambiguous subcommand "xyz": must be appname, busy, caret, fontchooser, inactive, print, scaling, sysnotify, systray, useinputmethods, or windowingsystem}
} -returnCodes error -result {unknown or ambiguous subcommand "xyz": must be appname, busy, caret, fontchooser, inactive, scaling, useinputmethods, or windowingsystem}

# Value stored to restore default settings after 2.* tests
set appname [tk appname]
test tk-2.1 {tk command: appname} -body {
    tk appname xyz abc
} -returnCodes error -result {wrong # args: should be "tk appname ?newName?"}
test tk-2.2 {tk command: appname} -body {
    tk appname foobazgarply
} -result {foobazgarply}
test tk-2.3 {tk command: appname} -constraints unix -body {
    tk appname bazfoogarply
    expr {[lsearch -exact [winfo interps] [tk appname]] >= 0}
} -result 1
} -result {1}
test tk-2.4 {tk command: appname} -body {
    tk appname [tk appname]
} -result [tk appname]
tk appname $appname

# Value stored to restore default settings after 3.* tests
set scaling [tk scaling]
62
63
64
65
66
67
68
69

70
71
72
73

74
75
76
77
78

79
80
81
82
83

84
85
86
87
88
89
90
62
63
64
65
66
67
68

69
70
71
72

73
74
75
76
77

78
79
80
81
82

83
84
85
86
87
88
89
90







-
+



-
+




-
+




-
+







test tk-3.7 {tk command: scaling: set new} -body {
    tk scaling -displayof . 1.25
    format %.3g [tk scaling]
} -result 1.25
test tk-3.8 {tk command: scaling: negative} -body {
    tk scaling -1
    expr {[tk scaling] > 0}
} -result 1
} -result {1}
test tk-3.9 {tk command: scaling: too big} -body {
    tk scaling 1000000
    expr {[tk scaling] < 10000}
} -result 1
} -result {1}
test tk-3.10 {tk command: scaling: widthmm} -body {
    tk scaling 1.25
    expr {int((25.4*[winfo screenwidth .])/(72*1.25) + 0.5) \
        - [winfo screenmmwidth .]}
} -result 0
} -result {0}
test tk-3.11 {tk command: scaling: heightmm} -body {
    tk scaling 1.25
    expr {int((25.4*[winfo screenheight .])/(72*1.25) + 0.5) \
        - [winfo screenmmheight .]}
} -result 0
} -result {0}
tk scaling $scaling

# Value stored to restore default settings after 4.* tests
set useim [tk useinputmethods]
test tk-4.1 {tk command: useinputmethods} -body {
    tk useinputmethods -displayof
} -returnCodes error -result {value for "-displayof" missing}
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169







-
+



















-
+







    tk caret . -x 0 -y
} -returnCodes error -result {wrong # args: should be "tk caret window ?-x x? ?-y y? ?-height height?"}
test tk-5.5 {tk caret} -body {
    tk caret . -x 10 -y 11 -h 12; tk caret .
} -result {-height 12 -x 10 -y 11}
test tk-5.6 {tk caret} -body {
    tk caret . -x 20 -y 25 -h 30; tk caret . -hei
} -result 30
} -result {30}

# tk inactive
test tk-6.1 {tk inactive} -body {
    string is integer [tk inactive]
} -result 1
test tk-6.2 {tk inactive reset} -body {
    tk inactive reset
} -returnCodes ok -match glob -result *
test tk-6.3 {tk inactive wrong argument} -body {
    tk inactive foo
} -returnCodes 1 -result {bad option "foo": must be reset}
test tk-6.4 {tk inactive too many arguments} -body {
    tk inactive reset foo
} -returnCodes 1 -result {wrong # args: should be "tk inactive ?-displayof window? ?reset?"}
test tk-6.5 {tk inactive} -body {
    tk inactive reset
    update
    after 100
    set i [tk inactive]
    expr {$i < 0 || ( $i > 90 && $i < 300 )}
    expr {$i == -1 || ( $i > 90 && $i < 200 )}
} -result 1

test tk-7.1 {tk inactive in a safe interpreter} -body {
# tk inactive in safe interpreters
    safe::interpCreate foo
    safe::loadTk foo
    foo eval {tk inactive}

Changes to tests/ttk/all.tcl.

1
2
3
4
5
6
7

8
9
10
11
12

13
14
15
16
17
18
19
20
21


1
2
3
4
5
6

7
8
9
10
11

12
13
14
15
16
17
18



19
20






-
+




-
+






-
-
-
+
+
# all.tcl --
#
# This file contains a top-level script to run all of the ttk
# tests.  Execute it by invoking "source all.tcl" when running tktest
# in this directory.
#
# Copyright © 2007 the Tk developers.
# Copyright (c) 2007 by the Tk developers.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tk ;# This is the Tk test suite; fail early if no Tk!
package require Tk ;# This is the Tk test suite; fail early if no Tk!
package require tcltest 2.2
tcltest::configure {*}$argv
tcltest::configure -testdir [file normalize [file dirname [info script]]]
tcltest::configure -loadfile \
    [file join [file dirname [tcltest::testsDirectory]] constraints.tcl]
tcltest::configure -singleproc 1
set ErrorOnFailures [info exists env(ERROR_ON_FAILURES)]
encoding system utf-8
if {[tcltest::runAllTests] && $ErrorOnFailures} {exit 1}
tcltest::runAllTests

Changes to tests/ttk/checkbutton.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
1
2
3
4


5
6

7
8
9
10
11
12
13




-
-
+
+
-







#
# ttk::checkbutton widget tests.
#

package require tk
package require tcltest 2.2
package require Tk
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test checkbutton-1.1 "Checkbutton check" -body {
    pack [ttk::checkbutton .cb -text "TCheckbutton" -variable cb]
}
test checkbutton-1.2 "Checkbutton invoke" -body {
    .cb invoke
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
52
53
54
55
56
57
58

59
60
61
62
63























64







-
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

    }
    toplevel .top
    ttk::menubutton .top.mb -text Button -style TLabel
    bind .top.mb <ButtonRelease-1> destroy_button
    pack .top.mb
    focus -force .top.mb
    update
    event generate .top.mb <Button-1>
    event generate .top.mb <1>
    event generate .top.mb <ButtonRelease-1>
    update  ; # shall not trigger error  invalid command name ".top.b"
} -result {}

# Bug [fa8de77936]
test checkbutton-1.8 "Empty -variable" -body {
    # shall simply not crash
    ttk::checkbutton .cbev -variable {}
    .cbev invoke
} -cleanup {
    destroy .cbev
} -result {}

test checkbutton-2.1 "style command" -body {
    ttk::checkbutton .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TCheckbutton TCheckbutton}
test checkbutton-2.2 "style command" -body {
    ttk::style configure customStyle.TCheckbutton
    ttk::checkbutton .w -style customStyle.TCheckbutton
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TCheckbutton customStyle.TCheckbutton TCheckbutton}

tcltest::cleanupTests

Changes to tests/ttk/combobox.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
1
2
3
4


5
6

7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42






43


44















45
46
47
48
49
50

51





52
53
54
55
56
57

58

59
60

61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76














77




-
-
+
+
-








-
+







-
-
+
+


















-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-

-
-
-
-
-






-
+
-


-


-
+













-
-
-
-
-
-
-
-
-
-
-
-
-
-

#
# ttk::combobox widget tests
#

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test combobox-1.0 "Combobox tests -- setup" -body {
    ttk::combobox .cb
} -result .cb

test combobox-1.1 "Bad -values list" -body {
    .cb configure -values "bad \{list"
} -result "unmatched open brace in list" -returnCodes error
} -result "unmatched open brace in list" -returnCodes 1

test combobox-1.end "Combobox tests -- cleanup" -body {
    destroy .cb
}

test combobox-2.0 "current command" -body {
    ttk::combobox .cb -values [list a b c d e a]
    expr {[.cb current]<0}
} -result 1
    .cb current
} -result -1

test combobox-2.1 "current -- set index" -body {
    .cb current 5
    .cb get
} -result a

test combobox-2.2 "current -- change -values" -body {
    .cb configure -values [list c b a d e]
    .cb current
} -result 2

test combobox-2.3 "current -- change value" -body {
    .cb set "b"
    .cb current
} -result 1

test combobox-2.4 "current -- value not in list" -body {
    .cb set "z"
    expr {[.cb current]<0}
} -result 1

test combobox-2.5 "current -- set to end index" -body {
    .cb configure -values [list a b c d e thelastone]
    .cb current end
    .cb current
    .cb get
} -result thelastone
} -result -1

test combobox-2.6 "current -- set to unknown index" -body {
    .cb configure -values [list a b c d e]
    .cb current notanindex
} -returnCodes error -result {bad index "notanindex"}

test combobox-2.7 {current -- set to 0 index when empty [bug 924835c36d]} -body {
    .cb configure -values {}
    .cb current 0
} -returnCodes error -result {index "0" out of range}

test combobox-2.8 "current -- set to end index in an empty combobox" -body {
    .cb configure -values {}
    .cb current end
} -returnCodes error -result {index "end" out of range}

test combobox-2.end "Cleanup" -body { destroy .cb }

test combobox-3 "Read postoffset value dynamically from current style" -body {
    ttk::combobox .cb -values [list a b c] -style "DerivedStyle.TCombobox"
    pack .cb -expand true -fill both
    update idletasks
    ttk::style configure DerivedStyle.TCombobox -postoffset [list 25 0 0 0]
    if {[tk windowingsystem] == "aqua"} {
	after 500 {
	    pressbutton [expr {[winfo rootx .cb] + 25}] [expr {[winfo rooty .cb] + 25}]
	}
    }
    ttk::combobox::Post .cb
    expr {[winfo rootx .cb.popdown] - [winfo rootx .cb]}
} -result 25 -cleanup {
    destroy .cb
}

test combobox-1890211 "ComboboxSelected event after listbox unposted" \
test combobox-1890211 "ComboboxSelected event after listbox unposted" -body {
    -constraints {notAqua} -body {
    # whitebox test...
    pack [ttk::combobox .cb -values [list a b c]]
    update idletasks
    set result [list]
    bind .cb <<ComboboxSelected>> {
	lappend result Event [winfo ismapped .cb.popdown] [.cb get]
    	lappend result Event [winfo ismapped .cb.popdown] [.cb get]
    }
    lappend result Start 0 [.cb get]
    ttk::combobox::Post .cb
    lappend result Post [winfo ismapped .cb.popdown] [.cb get]
    .cb.popdown.f.l selection clear 0 end; .cb.popdown.f.l selection set 1
    ttk::combobox::LBSelected .cb.popdown.f.l
    lappend result Select [winfo ismapped .cb.popdown] [.cb get]
    update
    set result
} -result [list Start 0 {} Post 1 {} Select 0 b Event 0 b] -cleanup {
    destroy .cb
}

test combobox-4.1 "style command" -body {
    ttk::combobox .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TCombobox TCombobox}
test combobox-4.2 "style command" -body {
    ttk::style configure customStyle.TCombobox
    ttk::combobox .w -style customStyle.TCombobox
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TCombobox customStyle.TCombobox TCombobox}

tcltest::cleanupTests

Changes to tests/ttk/entry.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
1
2
3
4


5
6

7
8
9
10
11
12
13




-
-
+
+
-







#
# Tile package: entry widget tests
#

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

variable scrollInfo
proc scroll args {
    global scrollInfo
    set scrollInfo $args
}
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
59
60
61
62
63
64
65






66
67
68
69
70
71
72
73

74
75
76













77
78
79

80


81




82
83
84
85
86
87

88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105



106






107
108
109





















110
111
112
113
114
115
116







-
-
-
-
-
-








-
+


-
-
-
-
-
-
-
-
-
-
-
-
-



-
+
-
-

-
-
-
-
+





-
+


-
-
+
+













-
-
-
+
-
-
-
-
-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







test entry-1.7 "Deletion - insert cursor in the middle " -body {
    .e insert end abcde
    .e icursor 3
    .e delete 0 end
    .e index insert
} -result 0

test entry-1.8 "Index is between 0 and end" -body {
    .e delete 0 end
    .e insert end abcde
    set res [list [.e index -1] [.e index -4] [.e index 999]]
} -result {0 0 5}

test entry-1.done "Cleanup" -body { destroy .e }

# Scrollbar tests.

test entry-2.1 "Create entry before scrollbar" -body {
    pack [ttk::entry .te -xscrollcommand [list .tsb set]] \
	-expand true -fill both
    pack [ttk::scrollbar .tsb -orient horizontal -command [list .te xview]] \
	-expand false -fill x
    	-expand false -fill x
}  -cleanup {destroy .te .tsb}

test entry-2.1.1 "Create entry before scrollbar - scrollbar catches up" -body {
    pack [ttk::entry .te -xscrollcommand [list .tsb set]] \
	    -expand true -fill both
    .te insert end [string repeat "abc" 50]
    catch {update} ; # error triggers because the -xscrollcommand callback
                     # errors out: invalid command name ".tsb"
    focus -force .te ; # needed on some systems such as Ubuntu (see ticket [3c2a3a988f])
    pack [ttk::scrollbar .tsb -orient horizontal -command [list .te xview]] \
	    -expand false -fill x
    update ; # no error
    set res [expr [lindex [.tsb get] 1] < 1] ; # scrollbar did update
} -result 1 -cleanup {destroy .te .tsb}

test entry-2.2 "Initial scroll position" -body {
    ttk::entry .e -font fixed -width 5 -xscrollcommand scroll
    .e insert end "0123456789"
    pack .e;
    pack .e; update
    set timeout [after 500 {set $scrollInfo "timeout"}]
    vwait scrollInfo
    set scrollInfo
} -cleanup {
    destroy .e
    after cancel $timeout
} -result {0.0 0.5}
} -result {0.0 0.5} -cleanup { destroy .e }
# NOTE: result can vary depending on font.

# Bounding box / scrolling tests.
test entry-3.0 "Series 3 setup" -body {
    ttk::style theme use default
    variable fixed TkFixedFont
    variable fixed fixed
    variable cw [font measure $fixed a]
    variable ch [font metrics $fixed -linespace]
    variable bd 3	;# border + padding + extra space for focus ring
    variable ux [font measure $fixed ]
    variable bd 2	;# border + padding
    variable ux [font measure $fixed \u4e4e]

    pack [ttk::entry .e -font $fixed -width 20]
    update
}

test entry-3.1 "bbox widget command" -body {
    .e delete 0 end
    .e bbox 0
} -result [list $bd $bd 0 $ch]

test entry-3.2 "xview" -body {
    .e delete 0 end;
    .e insert end [string repeat "0" 40]
    set result [.e xview]
} -result {0.0 0.5}

    update idletasks
test entry-3.3 "xview" -body {
    .e delete 0 end;
    .e insert end abcdefghijklmnopqrstuvwxyz
    .e xview end
    set result [.e index @0]
} -result 7
    set result [.e xview]
} -result {0.0 0.5}

test entry-3.4 "xview" -body {
    .e delete 0 end;
    .e insert end abcdefghijklmnopqrstuvwxyz
    .e xview moveto 1.0
    set result [.e index @0]
} -result 7

test entry-3.5 "xview" -body {
    .e delete 0 end;
    .e insert end abcdefghijklmnopqrstuvwxyz
    .e xview scroll 5 units
    set result [.e index @0]
} -result 5

test entry-3.6 "xview" -body {
    .e delete 0 end;
    .e insert end [string repeat abcdefghijklmnopqrstuvwxyz 5]
    .e xview scroll 2 pages
    set result [.e index @0]
} -result 40

test entry-3.last "Series 3 cleanup" -body {
    destroy .e
}

# Selection tests:

test entry-4.0 "Selection test - setup" -body {
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+







test entry-6.1 {Update linked variable in write trace} -body {
    proc override args {
	global x
	set x "Overridden!"
    }
    catch {destroy .e}
    set x ""
    trace add variable x write override
    trace variable x w override
    ttk::entry .e -textvariable x
    .e insert 0 "Some text"
    set result [list $x [.e get]]
    set result
} -result {Overridden! Overridden!} -cleanup {
    unset x
    rename override {}
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282











































































283







-
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

    .e cget -textvariable
} -result ::test::foo -cleanup { destroy .e }
# For 8.2a, -result {} would also be sensible.

test entry-9.1 "Index range invariants" -setup {
    # See bug#1721532 for discussion
    proc entry-9.1-trace {n1 n2 op} {
	set ::V NO!
    	set ::V NO!
    }
    variable V
    trace add variable V write entry-9.1-trace
    ttk::entry .e -textvariable V
} -body {
    set result [list]
    .e insert insert a ; lappend result [.e index insert] [.e index end]
    .e insert insert b ; lappend result [.e index insert] [.e index end]
    .e insert insert c ; lappend result [.e index insert] [.e index end]
    .e insert insert d ; lappend result [.e index insert] [.e index end]
    .e insert insert e ; lappend result [.e index insert] [.e index end]
    set result
} -result [list 1 3  2 3  3 3  3 3  3 3] -cleanup {
    unset V
    destroy .e
}

test entry-10.1 {configuration option: "-placeholder"} -setup {
    pack [ttk::entry .e]
} -body {
    .e configure -placeholder {Some text}
    .e cget -placeholder
} -cleanup {
    destroy .e
} -result {Some text}

test entry-10.2 {configuration option: "-placeholderforeground"} -setup {
    pack [ttk::entry .e]
} -body {
    .e configure -placeholder {Some text} -placeholderforeground red
    .e cget -placeholderforeground
} -cleanup {
    destroy .e
} -result {red}

test entry-10.3 {styling option: "-placeholderforeground"} -setup {
    pack [ttk::entry .e]
} -body {
    set current [ttk::style configure TEntry -placeholderforeground]
    ttk::style configure TEntry -placeholderforeground blue
    set res [ttk::style configure TEntry -placeholderforeground]
    ttk::style configure TEntry -placeholderforeground $current
    set res
} -cleanup {
    destroy .e
} -result {blue}

test entry-11.1 {Bug [2830360fff] - Don't loose invalid at focus events} -setup {
    pack [ttk::entry .e]
    update
} -body {
    .e state invalid
    set res [.e state]
    event generate .e <FocusOut>
    lappend res [.e state]
} -result {invalid invalid} -cleanup {
    destroy .e
}
test entry-11.2 {Bug [2a32225cd1] - Navigation in a password made of several words} -setup {
    destroy .e
    pack [ttk::entry .e -show *]
    update
    set res {}
} -body {
    .e insert end "A sample password made of several words"
    .e icursor end
    event generate .e <<PrevWord>>  ; # shall move insert to index 0
    .e delete insert end
    lappend res [.e get]
    .e insert end "A sample password made of several words"
    .e icursor 2
    event generate .e <<NextWord>>  ; # shall move insert to index end
    .e delete 0 insert
    lappend res [.e get]
} -cleanup {
    destroy .e
} -result {{} {}}

test entry-12.1 "style command" -body {
    ttk::entry .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TEntry TEntry}
test entry-12.2 "style command" -body {
    ttk::style configure customStyle.TEntry
    ttk::entry .w -style customStyle.TEntry
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TEntry customStyle.TEntry TEntry}

tcltest::cleanupTests

Changes to tests/ttk/image.test.

1
2


3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22


1
2

3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
-
-
+
+
-











-
+







package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test image-1.1 "Bad image element" -body {
    ttk::style element create BadImage image badimage
} -returnCodes error -result {image "badimage" doesn't exist}

test image-1.2 "Duplicate element" -setup {
    image create photo test.element -width 10 -height 10
    ttk::style element create testElement image test.element
} -body {
    ttk::style element create testElement image test.element
} -returnCodes error -result "Duplicate element testElement"
} -returnCodes 1 -result "Duplicate element testElement"

test image-2.0 "Deletion of displayed image (label)" -setup {
     image create photo test.image -width 10 -height 10
} -body {
    pack [set w [ttk::label .ttk_image20 -image test.image]]
    tkwait visibility $w
    image delete test.image

Changes to tests/ttk/labelframe.test.

1
2


3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20

21
22
23
24
25

26
27
28
29

30
31
32
33
34
35

36
37
38
39
40
41

42
43
44
45
46

47
48
49
50
51

52
53
54
55
56

57
58
59
60
61

62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85

86
87
88
89
90
91

92
93
94
95
96

97
98
99

100
101
102
103

104
105
106

107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


1
2

3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18

19
20
21
22
23

24
25
26
27

28
29
30
31
32
33

34
35
36
37
38
39

40
41
42
43
44

45
46
47
48
49

50
51
52
53
54

55
56
57
58
59

60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83

84
85
86
87
88
89

90
91
92
93
94

95
96
97

98
99
100
101

102
103
104

105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129














130
-
-
+
+
-










-
+





-
+




-
+



-
+





-
+





-
+




-
+




-
+




-
+




-
+





-
+









-
+







-
+





-
+




-
+


-
+



-
+


-
+



-
+




















-
-
-
-
-
-
-
-
-
-
-
-
-
-

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test labelframe-1.0 "Setup" -body {
    pack [ttk::labelframe .lf] -expand true -fill both
}

test labelframe-2.1 "Can't use indirect descendant as labelwidget" -body {
    ttk::frame .lf.t
    ttk::checkbutton .lf.t.cb
    .lf configure -labelwidget .lf.t.cb
} -returnCodes error -result "can't *" -match glob \
} -returnCodes 1 -result "can't *" -match glob \
  -cleanup { destroy .lf.t } ;

test labelframe-2.2 "Can't use toplevel as labelwidget" -body {
    toplevel .lf.t
    .lf configure -labelwidget .lf.t
} -returnCodes error -result "can't *" -match glob \
} -returnCodes 1 -result "can't *" -match glob \
  -cleanup { destroy .lf.t } ;

test labelframe-2.3 "Can't use non-windows as -labelwidget" -body {
    .lf configure -labelwidget BogusWindowName
} -returnCodes error -result {bad window path name "BogusWindowName"}
} -returnCodes 1 -result {bad window path name "BogusWindowName"}

test labelframe-2.4 "Can't use nonexistent-windows as -labelwidget" -body {
    .lf configure -labelwidget .nosuchwindow
} -returnCodes error -result {bad window path name ".nosuchwindow"}
} -returnCodes 1 -result {bad window path name ".nosuchwindow"}


###
# See also series labelframe-4.x
#
test labelframe-3.1 "Add child content" -body {
test labelframe-3.1 "Add child slave" -body {
    checkbutton .lf.cb -text "abcde"
    .lf configure -labelwidget .lf.cb
    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
} -result [list 1 labelframe]

test labelframe-3.2 "Remove child content" -body {
test labelframe-3.2 "Remove child slave" -body {
    .lf configure -labelwidget {}
    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
} -result [list 0 {}]

test labelframe-3.3 "Re-add child content" -body {
test labelframe-3.3 "Re-add child slave" -body {
    .lf configure -labelwidget .lf.cb
    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
} -result [list 1 labelframe]

test labelframe-3.4 "Re-manage child content" -body {
test labelframe-3.4 "Re-manage child slave" -body {
    pack .lf.cb -side right
    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb] [.lf cget -labelwidget]
} -result [list 1 pack {}]

test labelframe-3.5 "Re-add child content" -body {
test labelframe-3.5 "Re-add child slave" -body {
    .lf configure -labelwidget .lf.cb
    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
} -result [list 1 labelframe]

test labelframe-3.6 "Destroy child content" -body {
test labelframe-3.6 "Destroy child slave" -body {
    destroy .lf.cb
    .lf cget -labelwidget
} -result {}

###
# Re-run series labelframe-3.x with nonchild content.
# Re-run series labelframe-3.x with nonchild slaves.
#
# @@@ ODDITY, 14 Nov 2005:
# @@@ labelframe-4.1 fails if .cb is a [checkbutton],
# @@@ but seems to succeed if it's some other widget class.
# @@@ I suspect a race condition; unable to track it down ATM.
#
# @@@ FOLLOWUP: This *may* have been caused by a bug in ManagerIdleProc
# @@@ (see manager.c r1.11). There's still probably a race condition in here.
#
test labelframe-4.1 "Add nonchild content" -body {
test labelframe-4.1 "Add nonchild slave" -body {
    checkbutton .cb -text "abcde"
    .lf configure -labelwidget .cb
    update
    list [winfo ismapped .cb] [winfo viewable .cb] [winfo manager .cb]

} -result [list 1 1 labelframe]

test labelframe-4.2 "Remove nonchild content" -body {
test labelframe-4.2 "Remove nonchild slave" -body {
    .lf configure -labelwidget {}
    update;
    list [winfo ismapped .cb] [winfo viewable .cb] [winfo manager .cb]
} -result [list 0 0 {}]

test labelframe-4.3 "Re-add nonchild content" -body {
test labelframe-4.3 "Re-add nonchild slave" -body {
    .lf configure -labelwidget .cb
    list [update; winfo viewable .cb] [winfo manager .cb]
} -result [list 1 labelframe]

test labelframe-4.4 "Re-manage nonchild content" -body {
test labelframe-4.4 "Re-manage nonchild slave" -body {
    pack .cb -side right
    list [update; winfo viewable .cb] \
	[winfo manager .cb] \
    	[winfo manager .cb] \
	[.lf cget -labelwidget]
} -result [list 1 pack {}]

test labelframe-4.5 "Re-add nonchild content" -body {
test labelframe-4.5 "Re-add nonchild slave" -body {
    .lf configure -labelwidget .cb
    list [update; winfo viewable .cb] \
	[winfo manager .cb] \
    	[winfo manager .cb] \
	[.lf cget -labelwidget]
} -result [list 1 labelframe .cb]

test labelframe-4.6 "Destroy nonchild content" -body {
test labelframe-4.6 "Destroy nonchild slave" -body {
    destroy .cb
    .lf cget -labelwidget
} -result {}

test labelframe-5.0 "Cleanup" -body {
    destroy .lf
}

# 1342876 -- labelframe should raise sibling -labelwidget above self.
#
test labelframe-6.1 "Stacking order" -body {
    toplevel .t
    pack [ttk::checkbutton .t.x1]
    pack [ttk::labelframe .t.lf -labelwidget [ttk::label .t.lb]]
    pack [ttk::checkbutton .t.x2]
    winfo children .t
} -cleanup {
    destroy .t
} -result [list .t.x1 .t.lf .t.lb .t.x2]

test labelframe-7.1 "style command" -body {
    ttk::labelframe .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TLabelframe TLabelframe}
test labelframe-7.2 "style command" -body {
    ttk::style configure customStyle.TLabelframe
    ttk::labelframe .w -style customStyle.TLabelframe
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TLabelframe customStyle.TLabelframe TLabelframe}

tcltest::cleanupTests

Changes to tests/ttk/layout.test.

1
2


3
4
5
6
7
8
9
10


1
2

3
4
5
6
7
8
9
-
-
+
+
-







package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test layout-1.1 "Size computations for mixed-orientation layouts" -body {
    ttk::style theme use default

    set block [image create photo -width 10 -height 10]
    ttk::style element create block image $block
18
19
20
21
22
23
24
25
26
27
28
29
17
18
19
20
21
22
23



24
25







-
-
-



    pack .b -expand true -fill both

    list [winfo reqwidth .b] [winfo reqheight .b]

} -cleanup { destroy .b } -result [list 24 24]

test layout-2 "Empty -children not allowed" -body {
    ttk::style layout Test.Tentry {Entry.field -children {}}
} -returnCodes error -result {Invalid -children value}

tcltest::cleanupTests

Changes to tests/ttk/notebook.test.

1
2


3
4
5
6
7
8
9
10


1
2

3
4
5
6
7
8
9
-
-
+
+
-







package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test notebook-1.0 "Setup" -body {
    ttk::notebook .nb
} -result .nb

#
21
22
23
24
25
26
27
28

29
30
31
32

33
34
35
36
37
38
39
20
21
22
23
24
25
26

27
28
29
30

31
32
33
34
35
36
37
38







-
+



-
+







    .nb add [frame .sibling]
} -returnCodes error -result "*" -match glob

test notebook-1.3 "Cannot add toplevel" -body {
    .nb add [toplevel .nb.t]
} -cleanup {
    destroy .t.nb
} -returnCodes error -match glob -result "can't add .nb.t*"
} -returnCodes 1 -match glob -result "can't add .nb.t*"

test notebook-1.4 "Try to select bad tab" -body {
    .nb select @6000,6000
} -returnCodes error -match glob -result "* not found"
} -returnCodes 1 -match glob -result "* not found"

#
# Now add stuff:
#
test notebook-2.0 "Add children" -body {
    pack .nb -expand true -fill both
    .nb add [frame .nb.foo] -text "Foo"
63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
62
63
64
65
66
67
68

69
70
71

72
73
74
75
76
77
78
79







-



-
+








test notebook-2.4 "tab - set value" -body {
    .nb tab .nb.foo -text "Changed Foo"
    .nb tab .nb.foo -text
} -result "Changed Foo"

test notebook-2.5 "tab - get all options" -body {
    .nb tab .nb.foo -underline 0
    .nb tab .nb.foo
} -result [list \
    -padding 0 -sticky nsew \
    -state normal -text "Changed Foo" -image "" -compound {} -underline 0]
    -state normal -text "Changed Foo" -image "" -compound none -underline -1]

test notebook-4.1 "Test .nb index end" -body {
    .nb index end
} -result 2

test notebook-4.2 "'end' is not a selectable index" -body {
    .nb select end
93
94
95
96
97
98
99
100

101
102
103
104


105
106
107
108
109
110
111
91
92
93
94
95
96
97

98
99
100


101
102
103
104
105
106
107
108
109







-
+


-
-
+
+








test notebook-5.1 "Virtual events" -body {
    toplevel .t
    set ::events [list]
    bind .t <<NotebookTabChanged>> { lappend events changed %W }

    pack [set nb [ttk::notebook .t.nb]] -expand true -fill both; update
    $nb add [frame $nb.f1] ;  # triggers <<NotebookTabChanged>> (first tab gets autoselected)
    $nb add [frame $nb.f1]
    $nb add [frame $nb.f2]
    $nb add [frame $nb.f3]
    update
    $nb select $nb.f1 ; # does not trigger <<NotebookTabChanged>> (tab to select is already selected)

    $nb select $nb.f1
    update; set events
} -result [list changed .t.nb]

test notebook-5.2 "Virtual events, continued" -body {
    set events [list]
    $nb select $nb.f3
    update ; set events
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
151
152
153
154
155
156
157

158

159
160
161
162
163
164
165
166







-

-
+







    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb hide $nb.f2
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    lappend result [winfo ismapped $nb.f3]
    update idletasks; lappend result [winfo ismapped $nb.f3]
} -result [list 1 1 2 0 1]

# See 1370833
test notebook-6.2 "Forget selected tab" -setup {
    ttk::notebook .n
    pack .n
    label .n.l -text abc
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

324
325

326
327
328
329
330
331
332







-















-















-















-















-















-















-















-















-















-


-







    $nb select $nb.f1
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f1]
    $nb hide $nb.f1
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f1]
} -result [list 0 1 1 0]

test notebook-6.4 "Forget first tab when it's the current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f1
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f1]
    $nb forget $nb.f1
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f1]
} -result [list 0 1 0 0]

test notebook-6.5 "Hide last tab when it's the current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f3
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f3]
    $nb hide $nb.f3
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f3]
} -result [list 2 1 1 0]

test notebook-6.6 "Forget a middle tab when it's the current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb forget $nb.f2
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 1 0]

test notebook-6.7 "Hide a middle tab when it's the current" -setup {
    pack [set nb [ttk::notebook .nb]]; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb hide $nb.f2
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 2 0]

test notebook-6.8 "Forget a non-current tab < current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb forget $nb.f1
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 0 1]

test notebook-6.9 "Hide a non-current tab < current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb hide $nb.f1
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 1 1]

test notebook-6.10 "Forget a non-current tab > current" -setup {
    pack [set nb [ttk::notebook .nb]] ; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb forget $nb.f3
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 1 1]

test notebook-6.11 "Hide a non-current tab > current" -setup {
    pack [set nb [ttk::notebook .nb]]; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [winfo ismapped $nb.f2]
    $nb hide $nb.f3
    update idletasks
    lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 1 1]

test notebook-6.12 "Hide and re-add a tab" -setup {
    pack [set nb [ttk::notebook .nb]]; update
    $nb add [ttk::frame $nb.f1]
    $nb add [ttk::frame $nb.f2]
    $nb add [ttk::frame $nb.f3]
    $nb select $nb.f2
} -cleanup  {
    destroy $nb
} -body {
    set result [list]
    lappend result [$nb index current] [$nb tab $nb.f2 -state]
    $nb hide $nb.f2
    update idletasks
    lappend result [$nb index current] [$nb tab $nb.f2 -state]
    $nb add $nb.f2
    update idletasks
    lappend result [$nb index current] [$nb tab $nb.f2 -state]
} -result [list 1 normal 2 hidden 2 normal]

#
# Insert:
#
unset nb
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406







-
+







    .nb insert 1 3
    .nb index current
} -result 4

test notebook-7.8a "move tabs - current tab undisturbed - exhaustive" -body {
    .nb select .nb.f0
    foreach i {0 1 2 3 4} {
	.nb insert $i .nb.f$i
    	.nb insert $i .nb.f$i
    }

    foreach i {0 1 2 3 4} {
	.nb select .nb.f$i
	foreach j {0 1 2 3 4} {
	    foreach k {0 1 2 3 4} {
		.nb insert $j $k
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
449
450
451
452
453
454
455

456
457
458
459
460
461
462
463







-
+







} -result [list "" .nb.l1] -cleanup { destroy .nb }

test notebook-1817596-2 "error in insert should have no effect" -body {
    pack [ttk::notebook .nb]
    .nb insert end [ttk::label .nb.l1]
    .nb insert end [ttk::label .nb.l2]
    list \
	[catch { .nb insert .l2 0 -badoption badvalue } err] \
    	[catch { .nb insert .l2 0 -badoption badvalue } err] \
	[.nb tabs] \
} -result [list 1 [list .nb.l1 .nb.l2]] -cleanup { destroy .nb }

test notebook-1817596-3 "insert/configure" -body {
    pack [ttk::notebook .nb]
    .nb insert end [ttk::label .nb.l0] -text "L0"
    .nb insert end [ttk::label .nb.l1] -text "L1"
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
507
508
509
510
511
512
513




























514







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

test notebook-1343984-2 "don't autoselect on destroy" -body {
    set ::history [list]
    destroy .nb
    update
    set ::history
} -result [list DESTROY .nb.frame1 DESTROY .nb.frame2 DESTROY .nb.frame3]

test notebook-198376af5a {moving tab position to a different edge} -body {
    destroy .nb
    ttk::notebook .nb -width 200 -height 100 -padding 0
    ttk::frame .nb.f1
    ttk::frame .nb.f2
    .nb add .nb.f1 -text "One"
    .nb add .nb.f2 -text "Two"
    pack .nb
    update
    ttk::style configure TNotebook -tabposition s
    update
    expr {[winfo y .nb.f1] < 10}
} -result 1

test notebook-8.1 "style command" -body {
    ttk::notebook .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TNotebook TNotebook}
test notebook-8.2 "style command" -body {
    ttk::style configure customStyle.TNotebook
    ttk::notebook .w -style customStyle.TNotebook
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TNotebook customStyle.TNotebook TNotebook}

tcltest::cleanupTests

Changes to tests/ttk/panedwindow.test.

1
2


3
4
5
6
7
8
9
10


1
2

3
4
5
6
7
8
9
-
-
+
+
-







package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

proc propagate-geometry {} { update idletasks }

# Basic sanity checks:
#
test panedwindow-1.0 "Setup" -body {
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56







-
+








test panedwindow-1.7 "Make sure empty panedwindow still still doesn't crash" -body {
    update
}

test panedwindow-1.8 "Re-forget pane" -body {
    .pw forget .pw.f1
} -returnCodes error -result ".pw.f1 is not managed by .pw"
} -returnCodes 1 -result ".pw.f1 is not managed by .pw"

test panedwindow-1.end "Cleanup" -body {
    destroy .pw
}

# Resize behavior:
#
115
116
117
118
119
120
121
122

123
124
125
126

127
128
129
130
131
132
133
114
115
116
117
118
119
120

121
122
123
124

125
126
127
128
129
130
131
132







-
+



-
+







    .pw add [listbox .pw.lb2]
    .pw pane 1 -weight 2
    .pw pane 1 -weight
} -result 2

test panedwindow-3.1 "configure pane -- errors" -body {
    .pw pane 1 -weight -4
} -returnCodes error -match glob -result "-weight must be nonnegative"
} -returnCodes 1 -match glob -result "-weight must be nonnegative"

test panedwindow-3.2 "add pane -- errors" -body {
    .pw add [ttk::label .pw.l] -weight -1
} -returnCodes error -match glob -result "-weight must be nonnegative"
} -returnCodes 1 -match glob -result "-weight must be nonnegative"


test panedwindow-3.end "cleanup" -body { destroy .pw }


test panedwindow-4.1 "forget" -body {
    pack [ttk::panedwindow .pw -orient vertical] -expand true -fill both
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165







-
+








-
+







    .pw forget .pw.l3
    .pw forget .pw.l4
    update
}

test panedwindow-4.2 "forget forgotten" -body {
    .pw forget .pw.l1
} -returnCodes error -result ".pw.l1 is not managed by .pw"
} -returnCodes 1 -result ".pw.l1 is not managed by .pw"

# checkorder $winlist --
#	Ensure that Y coordinates windows in $winlist are strictly increasing.
#
proc checkorder {winlist} {
    set pos -1
    set positions [list]
    foreach win $winlist {
	lappend positions [set nextpos [winfo y $win]]
    	lappend positions [set nextpos [winfo y $win]]
	if {$nextpos <= $pos} {
	    error "window $win out of order ($positions)"
	}
	set pos $nextpos
    }
}

199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212







-
+








### sashpos tests.
#
proc sashpositions {pw} {
    set positions [list]
    set npanes [llength [winfo children $pw]]
    for {set i 0} {$i < $npanes - 1} {incr i} {
	lappend positions [$pw sashpos $i]
    	lappend positions [$pw sashpos $i]
    }
    return $positions
}

test paned-sashpos-setup "Setup for sash position test" -body {
    ttk::style theme use default
    ttk::style configure -sashthickness 5
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277
278

279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282

283
284
285
286
287
288
289
290


















291







-
+











-
+





-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

test paned-propagation-1 "Initial request size" -body {
    .pw add .pw.f1
    .pw add .pw.f2
    propagate-geometry
    list [winfo reqwidth .pw] [winfo reqheight .pw]
} -result [list 100 105]

test paned-propagation-2 "Pane change before map" -body {
test paned-propagation-2 "Slave change before map" -body {
    .pw.f1 configure -width 200 -height 100
    propagate-geometry
    list [winfo reqwidth .pw] [winfo reqheight .pw]
} -result [list 200 155]

test paned-propagation-3 "Map window" -body {
    pack .pw -expand true -fill both
    update
    list [winfo width .pw] [winfo height .pw] [.pw sashpos 0]
} -result [list 200 155 100]

test paned-propagation-4 "Pane change after map, off-axis" -body {
test paned-propagation-4 "Slave change after map, off-axis" -body {
    .pw.f1 configure -width 100 ;# should be granted
    propagate-geometry
    list [winfo reqwidth .pw] [winfo reqheight .pw] [.pw sashpos 0]
} -result [list 100 155 100]

test paned-propagation-5 "Pane change after map, on-axis" -body {
test paned-propagation-5 "Slave change after map, on-axis" -body {
    .pw.f1 configure -height 50 ;# should be denied
    propagate-geometry
    list [winfo reqwidth .pw] [winfo reqheight .pw] [.pw sashpos 0]
} -result [list 100 155 100]

test paned-propagation-cleanup "Clean up." -body { destroy .pw }

test panedwindow-6.1 "style command" -body {
    # Contrary to ttk::scrollbar, ttk::progressbar and ttk::scale,
    # ttk::panedwindow has same style TPanedwindow whatever -orient is
    ttk::panedwindow .wv  ; # default is  -orient vertical
    ttk::panedwindow .wh -orient horizontal
    list [.wv cget -style] [.wv style] [winfo class .wv]\
         [.wh cget -style] [.wh style] [winfo class .wh]
} -cleanup {
    destroy .wv .wh
} -result {{} TPanedwindow TPanedwindow {} TPanedwindow TPanedwindow}
test panedwindow-6.2 "style command" -body {
    ttk::style configure customStyle.TPanedwindow
    ttk::panedwindow .w -style customStyle.TPanedwindow
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TPanedwindow customStyle.TPanedwindow TPanedwindow}

tcltest::cleanupTests

Deleted tests/ttk/pb_image.svg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76












































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="30"
   height="14"
   viewBox="0 0 30 14"
   version="1.1"
   id="svg8"
   sodipodi:docname="slider-hn.svg"
   inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
   style="shape-rendering:crispEdges">
  <defs
     id="defs2" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="24.766586"
     inkscape:cx="15.000049"
     inkscape:cy="7.0000477"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1315"
     inkscape:window-height="617"
     inkscape:window-x="155"
     inkscape:window-y="185"
     inkscape:window-maximized="0"
     fit-margin-top="0"
     fit-margin-left="0"
     fit-margin-right="0"
     fit-margin-bottom="0"
     units="px"
     showguides="false"
     showborder="false"
     inkscape:pagecheckerboard="true" />
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-97.353746,-141.48839)">
    <rect
       style="opacity:1;fill:#0044ff;fill-opacity:1;stroke:#222222;stroke-width:0.7;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
       id="rect815"
       width="13.3"
       height="29.3"
       x="141.98839"
       y="-126.85384"
       ry="0"
       transform="rotate(90)" />
  </g>
</svg>

Changes to tests/ttk/progressbar.test.

1
2


3
4
5
6
7
8
9
10


1
2

3
4
5
6
7
8
9
-
-
+
+
-







package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands


test progressbar-1.1 "Setup" -body {
    ttk::progressbar .pb
} -result .pb

70
71
72
73
74
75
76
77

78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
69
70
71
72
73
74
75

76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105







-
+


-
+


















-
+







    .pb configure -variable PB		;# @@@
    set PB 5
    .pb step
    set PB
} -result 6.0

test progressbar-2.5 "error in write trace" -body {
    trace add variable PB write { error "YIPES!" ;# }
    trace variable PB w { error "YIPES!" ;# }
    .pb step
    set PB		;# NOTREACHED
} -cleanup { unset PB } -returnCodes error -match glob -result "*YIPES!"
} -cleanup { unset PB } -returnCodes 1 -match glob -result "*YIPES!"

test progressbar-end "Cleanup" -body {
    destroy .pb
}

# check existence and default value of each non-core option of the widget
test progressbar-3.1 "progressbar non-core options" -setup {
    set res {}
    ttk::progressbar .defaultpb
} -body {
    foreach option {-anchor -foreground -justify -style -text -wraplength \
                    -length -maximum -mode -orient -phase -value -variable} {
        lappend res [.defaultpb cget $option]
    }
    set res
} -cleanup {
    unset res
    destroy .defaultpb
} -result {w black left {} {} 0 75p 100.0 determinate horizontal 0 0.0 {}}
} -result {w black left {} {} 0 100 100 determinate horizontal 0 0.0 {}}

test progressbar-3.2 "TIP #442 options are taken into account" -setup {
    set res {}
    pack [ttk::progressbar .p -value 0 -maximum 50 -orient horizontal -mode determinate -length 500]
    set thefont [font actual {Arial 10}]
} -body {
    .p configure -anchor c -foreground blue -justify right \
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
117
118
119
120
121
122
123






































124







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

    }
    set res
} -cleanup {
    unset res thefont
    destroy .p
} -result {{-anchor e} {-foreground green} {-justify center} {-text {Cannot be seen}} {-wraplength 250}}

test progressbar-3.3 {horizontal progressbar height with no -text (TIP #442) specified - Bug [8bee4b2009]} -setup {
    set res {}
    set oldTheme [ttk::style theme use]
} -body {
    ttk::style theme use default
    set imga [image create photo -file [file join [file dirname [info script]] pb_image.svg] -format {svg -scale 0.8}]
    ::ttk::style element create Horizontal.Progressbar.pbar image $imga
    # -text "": progressbar height does not depend on font height
    pack [ttk::progressbar .p -orient horizontal -font {TkDefaultFont 24}]
    .p step 25
    update
    set res [expr {[winfo reqheight .p] == [image height $imga] + 2}]
    # -text "something": progressbar height adjusts to contain the font height
    .p configure -text Hello -font {TkDefaultFont 24}
    update
    lappend res [expr {[winfo reqheight .p] == [font metrics [.p cget -font] -linespace] + 2}]
} -cleanup {
    destroy .p
    ttk::style theme use $oldTheme
    # there's no way I know to undo  '::ttk::style element create...'
} -result {1 1}

test progressbar-4.1 "style command" -body {
    ttk::progressbar .wh  ; # default is  -orient horizontal
    ttk::progressbar .wv -orient vertical
    list [.wh cget -style] [.wh style] [winfo class .wh]\
         [.wv cget -style] [.wv style] [winfo class .wv]
} -cleanup {
    destroy .wh .wv
} -result {{} Horizontal.TProgressbar TProgressbar {} Vertical.TProgressbar TProgressbar}
test progressbar-4.2 "style command" -body {
    ttk::style configure customStyle.Vertical.TProgressbar
    ttk::progressbar .w -orient vertical -style customStyle.Vertical.TProgressbar
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.Vertical.TProgressbar Vertical.customStyle.Vertical.TProgressbar TProgressbar}

tcltest::cleanupTests

Changes to tests/ttk/radiobutton.test.

1
2
3
4
5
6


7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4


5
6

7
8
9
10

11
12
13
14
15
16
17
18




-
-
+
+
-




-
+







#
# ttk::radiobutton widget tests.
#

package require tk
package require tcltest 2.2
package require Tk
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test radiobutton-1.1 "Radiobutton check" -body {
    pack \
	[ttk::radiobutton .rb1 -text "One" -variable choice -value 1] \
    	[ttk::radiobutton .rb1 -text "One" -variable choice -value 1] \
	[ttk::radiobutton .rb2 -text "Two" -variable choice -value 2] \
	[ttk::radiobutton .rb3 -text "Three" -variable choice -value 3] \
	;
}
test radiobutton-1.2 "Radiobutton invoke" -body {
    .rb1 invoke
    set ::choice
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
41
42
43
44
45
46
47














48







-
-
-
-
-
-
-
-
-
-
-
-
-
-

} -result {0 1 1}

test radiobutton-1.8 "Reset radiobutton variable" -body {
    set ::choice 2
    list [info exists ::choice] [.rb1 instate alternate] [.rb2 instate alternate]
} -result {1 0 0}

test radiobutton-2.1 "style command" -body {
    ttk::radiobutton .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TRadiobutton TRadiobutton}
test radiobutton-2.2 "style command" -body {
    ttk::style configure customStyle.TRadiobutton
    ttk::radiobutton .w -style customStyle.TRadiobutton
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TRadiobutton customStyle.TRadiobutton TRadiobutton}

tcltest::cleanupTests

Deleted tests/ttk/scale.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53





















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands

test scale-1.0 "Self-destruction" -body {
    trace add variable v write { destroy .s ;# }
    ttk::scale .s -variable v
    pack .s ; update
    .s set 1 ; update
} -returnCodes error -match glob -result "*"

test scale-2.1 "-state option" -setup {
    ttk::scale .s
    set res ""
} -body {
    # defaults
    lappend res [.s instate disabled] [.s cget -state]
    # set -state: instate returns accordingly
    .s configure -state disabled
    lappend res [.s instate disabled] [.s cget -state]
    # back to normal
    .s configure -state normal
    lappend res [.s instate disabled] [.s cget -state]
    # use state command: -state does NOT reflect it
    .s state disabled
    lappend res [.s instate disabled] [.s cget -state]
    # further use state command
    .s state readonly
    lappend res [.s state] [.s cget -state]
} -cleanup {
    destroy .s
    unset -nocomplain res
} -result {0 normal 1 disabled 0 normal 1 normal {disabled readonly} normal}

test scale-3.1 "style command" -body {
    ttk::scale .wh  ; # default is  -orient horizontal
    ttk::scale .wv -orient vertical
    list [.wh cget -style] [.wh style] [winfo class .wh] \
         [.wv cget -style] [.wv style] [winfo class .wv]
} -cleanup {
    destroy .wh .wv
} -result {{} Horizontal.TScale TScale {} Vertical.TScale TScale}
test scale-3.2 "style command" -body {
    ttk::style configure customStyle.Vertical.TScale
    ttk::scale .w -orient vertical -style customStyle.Vertical.TScale
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.Vertical.TScale Vertical.customStyle.Vertical.TScale TScale}

tcltest::cleanupTests

Changes to tests/ttk/scrollbar.test.

1
2


3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18

19
20
21
22

23
24
25
26

27
28
29
30
31

32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70

71
72
73
74
75


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92





93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138


1
2

3
4
5
6









7


8
9
10
11

12
13
14
15

16

17
18
19

20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46




47
48
49
50
51
52




53
54
55
56


57
58

















59
60
61
62
63




64















65









66















67
68
69
-
-
+
+
-




-
-
-
-
-
-
-
-
-
+
-
-
+



-
+



-
+
-



-
+






-
+



















-
-
-
-
+





-
-
-
-
+



-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

testConstraint coreScrollbar [expr {[tk windowingsystem] eq "aqua"}]

# Before 2019 the code in library/ttk/scrollbar.tcl would replace the
# constructor of ttk::scrollbar with the constructor of tk::scrollbar
# unless the -class or -style options were specified..
# Now there is an implementation of ttk::scrollbar for macOS.  The
# tests are left in place, though, except that scrollbar-swapout-1
# test was changed to expect the class to be TScrollbar instead of
# Scrollbar.

test scrollbar-swapout-1 "Don't use core scrollbars on OSX..." \
test scrollbar-swapout-1 "Use core scrollbars on OSX..." -constraints {
 -constraints {
     coreScrollbar
    coreScrollbar
} -body {
    ttk::scrollbar .sb -command "yadda"
    list [winfo class .sb] [.sb cget -command]
} -result [list TScrollbar yadda] -cleanup {
} -result [list Scrollbar yadda] -cleanup {
    destroy .sb
}

test scrollbar-swapout-2 "... regardless of whether -style ..." \
test scrollbar-swapout-2 "... unless -style is specified ..." -constraints {
-constraints {
    coreScrollbar
} -body {
    ttk::style layout Vertical.Custom.TScrollbar \
	[ttk::style layout Vertical.TScrollbar] ; # See #1833339
    	[ttk::style layout Vertical.TScrollbar] ; # See #1833339
    ttk::scrollbar .sb -command "yadda" -style Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command] [.sb cget -style]
} -result [list TScrollbar yadda Custom.TScrollbar] -cleanup {
    destroy .sb
}

test scrollbar-swapout-3 "... or -class is specified." -constraints {
test scrollbar-swapout-3 "... or -class." -constraints {
    coreScrollbar
} -body {
    ttk::scrollbar .sb -command "yadda" -class Custom.TScrollbar
    list [winfo class .sb] [.sb cget -command]
} -result [list Custom.TScrollbar yadda] -cleanup {
    destroy .sb
}

test scrollbar-1.0 "Setup" -body {
    ttk::scrollbar .tsb
} -result .tsb

test scrollbar-1.1 "Set method" -body {
    .tsb set 0.2 0.4
    .tsb get
} -result [list 0.2 0.4]

test scrollbar-1.2 "Set orientation" -body {
    .tsb configure -orient vertical
    pack .tsb -side right -anchor e -expand 1 -fill y
    wm geometry . 200x200
    update
    set w [winfo width .tsb] ; set h [winfo height .tsb]
    set w [winfo reqwidth .tsb] ; set h [winfo reqheight .tsb]
    expr {$h > $w}
} -result 1

test scrollbar-1.3 "Change orientation" -body {
    .tsb configure -orient horizontal
    pack .tsb -side bottom -anchor s -expand 1 -fill x
    wm geometry . 200x200
    update
    set w [winfo width .tsb] ; set h [winfo height .tsb]
    set w [winfo reqwidth .tsb] ; set h [winfo reqheight .tsb]
    expr {$h < $w}
} -result 1

test scrollbar-10.1.1 {<MouseWheel> event on scrollbar} -setup {
    destroy .t .s
#
# Scale tests:
} -body {
    pack [text .t -yscrollcommand {.s set}] -side left
    for {set i 1} {$i < 100} {incr i} {.t insert end "Line $i\n"}
    pack [ttk::scrollbar .s -command {.t yview}] -fill y -expand 1 -side left
    update
    focus -force .s
    event generate .s <Enter>
    event generate .s <MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {4.0}

test scrollbar-10.2.1 {<Shift-MouseWheel> event on horizontal scrollbar} -setup {
    destroy .t .s
} -body {
#

test scale-1.0 "Self-destruction" -body {
    trace variable v w { destroy .s ;# }
    ttk::scale .s -variable v
    pack [text .t -xscrollcommand {.s set} -wrap none] -side top
    for {set i 1} {$i < 100} {incr i} {.t insert end "Char $i "}
    pack [ttk::scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top
    update
    pack .s ; update
    focus -force .s
    event generate .s <Enter>
    event generate .s <Shift-MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {1.3}
test scrollbar-10.2.2 {<MouseWheel> event on horizontal scrollbar} -setup {
    destroy .t .s
} -body {
    pack [text .t -xscrollcommand {.s set} -wrap none] -side top
    for {set i 1} {$i < 100} {incr i} {.t insert end "Char $i "}
    pack [ttk::scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top
    update
    .s set 1 ; update
    focus -force .s
    event generate .s <Enter>
    event generate .s <MouseWheel> -delta -120
    after 200 {set eventprocessed 1} ; vwait eventprocessed
    .t index @0,0
} -cleanup {
    destroy .t .s
} -result {1.3}

} -returnCodes 1 -match glob -result "*"
test scrollbar-11.1 "style command" -body {
    ttk::scrollbar .wv  ; # default is  -orient vertical
    ttk::scrollbar .wh -orient horizontal
    list [.wv cget -style] [.wv style] [winfo class .wv] \
         [.wh cget -style] [.wh style] [winfo class .wh]
} -cleanup {
    destroy .wv .wh
} -result {{} Vertical.TScrollbar TScrollbar {} Horizontal.TScrollbar TScrollbar}
test scrollbar-11.2 "style command" -body {
    ttk::style configure customStyle.Horizontal.TScrollbar
    ttk::scrollbar .w -orient horizontal -style customStyle.Horizontal.TScrollbar
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.Horizontal.TScrollbar Horizontal.customStyle.Horizontal.TScrollbar TScrollbar}

tcltest::cleanupTests

Changes to tests/ttk/spinbox.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
1
2
3
4


5
6

7
8
9
10
11
12
13




-
-
+
+
-







#
# ttk::spinbox widget tests
#

package require tk
package require tcltest 2.2
package require Tk
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

test spinbox-1.0 "Spinbox tests -- setup" -body {
    ttk::spinbox .sb
} -cleanup { destroy .sb } -result .sb

test spinbox-1.1 "Bad -values list" -setup {
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142

143
144

145
146
147
148
149
150
151

152
153
154
155
156

157
158
159
160
161
162
163
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139

140
141
142

143
144

145
146



147

148
149
150

151
152
153
154
155
156
157
158







-
+










-

+

-
+

-


-
-
-
+
-



-
+







    .sb configure -validate focus
    .sb configure -validate focusin
    .sb configure -validate focusout
    .sb configure -validate none
    .sb cget -validate
} -cleanup {
    destroy .sb
} -result none
} -result {none}

test spinbox-1.8.3 "option -validate" -setup {
    ttk::spinbox .sb -from 0 -to 100
} -body {
    .sb configure -validate bogus
} -cleanup {
    destroy .sb
} -returnCodes error -result {bad validate "bogus": must be all, key, focus, focusin, focusout, or none}

test spinbox-1.8.4 "-validate option: " -setup {
    ttk::spinbox .sb -from 0 -to 100
    set ::spinbox_test {}
    ttk::spinbox .sb -from 0 -to 100
} -body {
    .sb configure -validate all -validatecommand {set ::spinbox_test %P}
    .sb configure -validate all -validatecommand {lappend ::spinbox_test %P}
    pack .sb
    update idletasks
    .sb set 50
    focus -force .sb
    set ::spinbox_wait 0
    set timer [after 100 {set ::spinbox_wait 1}]
    vwait ::spinbox_wait
    after 500 {set ::spinbox_wait 1} ; vwait ::spinbox_wait
    after cancel $timer
    set ::spinbox_test
} -cleanup {
    destroy .sb
} -result 50
} -result {50}


test spinbox-2.0 "current command -- unset should be 0" -constraints nyi -setup {
    ttk::spinbox .sb -values [list a b c d e a]
} -body {
    .sb current
} -cleanup {
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219

220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
200
201
202
203
204
205
206
207
208


209
210
211


212
213
214
215


216
217
218
219
220
221

















































































222
223
224
225
226
227
228







+

-
-



-
-
+



-
-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







} -result -1

test spinbox-3.0 "textarea should expand to fill widget" -setup {
    set SBV 5
    set ::spinbox_test {}
    ttk::spinbox .sb -from 0 -to 10 -textvariable SBV
} -body {
    grid .sb -sticky ew
    grid columnconfigure . 0 -weight 1
    update idletasks
    set timer [after 500 {set ::spinbox_test timedout}]
    bind . <Map> {
        after idle {
            wm geometry . "210x80"
	    update idletasks
            set ::spinbox_test [.sb identify element 25 5]
            after 100 {set ::spinbox_test [.sb identify element 5 5]}
        }
        bind . <Map> {}
    }
    grid .sb -sticky ew
    vwait ::spinbox_test
    after 500 {set ::spinbox_wait 1} ; vwait ::spinbox_wait
    set ::spinbox_test
} -cleanup {
    destroy .sb
    unset -nocomplain ::spinbox_test SBV
} -result {textarea}

test spinbox-4.0 "Increment with duplicates in -values, wrap" -setup {
    ttk::spinbox .sb -values {one two three 4 5 two six} -wrap true
    set max [expr {[llength [.sb cget -values]] + 2}]
} -body {
    set ::spinbox_test [.sb get]
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Increment>>
        lappend ::spinbox_test [.sb get]
    }
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Decrement>>
        lappend ::spinbox_test [.sb get]
    }
    set ::spinbox_test
} -cleanup {
    destroy .sb
    unset -nocomplain ::spinbox_test max
} -result {one two three 4 5 two six one two one six two 5 4 three two one six}

test spinbox-4.1 "Increment with duplicates in -values, wrap, initial value set" -setup {
    ttk::spinbox .sb -values {one two three 4 5 two six} -wrap true
    set max [expr {[llength [.sb cget -values]] + 2}]
} -body {
    .sb set three
    set ::spinbox_test [.sb get]
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Increment>>
        lappend ::spinbox_test [.sb get]
    }
    .sb set two    ; # the first "two" in the -values list becomes the current value
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Decrement>>
        lappend ::spinbox_test [.sb get]
    }
    set ::spinbox_test
} -cleanup {
    destroy .sb
    unset -nocomplain ::spinbox_test max
} -result {three 4 5 two six one two three 4 5 one six two 5 4 three two one six}

test spinbox-4.2 "Increment with duplicates in -values, no wrap" -setup {
    ttk::spinbox .sb -values {one two three 4 5 two six} -wrap false
    set max [expr {[llength [.sb cget -values]] + 2}]
} -body {
    set ::spinbox_test [.sb get]
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Increment>>
        lappend ::spinbox_test [.sb get]
    }
    for {set i 0} {$i < $max} {incr i} {
        event generate .sb <<Decrement>>
        lappend ::spinbox_test [.sb get]
    }
    set ::spinbox_test
} -cleanup {
    destroy .sb
    unset -nocomplain ::spinbox_test max
} -result {one two three 4 5 two six six six two 5 4 three two one one one one}

test spinbox-11.2 {Bugs [2a32225cd1] and [9fa3e08243]} -setup {
    destroy .s
    pack [ttk::spinbox .s]
    update
    set res {}
} -body {
    .s insert end "A sample text"
    .s icursor end
    event generate .s <<PrevWord>>  ; # shall move insert to index 9
    .s delete insert end
    lappend res [.s get]
    .s delete 0 end
    .s insert end "A sample text"
    .s icursor 2
    event generate .s <<NextWord>>  ; # shall move insert to index 9
    .s delete 0 insert
    lappend res [.s get]
} -cleanup {
    destroy .s
} -result {{A sample } text}


# nostomp: NB intentional difference between ttk::spinbox and tk::spinbox;
# see also #1439266
#
test spinbox-nostomp-1 "don't stomp on -variable (init; -from/to)" -body {
    set SBV 55
    ttk::spinbox .sb -textvariable SBV -from 0 -to 100 -increment 5
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
290
291
292
293
294
295
296














297
298
299
300
301







-
-
-
-
-
-
-
-
-
-
-
-
-
-





    event generate .sb <<Increment>> ; lappend result [.sb get]
    .sb set asdfasdf ; lappend result [.sb get]
    event generate .sb <<Decrement>> ; lappend result [.sb get]
} -result [list asdfasdf 000 asdfasdf 000] -cleanup {
    destroy .sb
}

test spinbox-5.1 "style command" -body {
    ttk::spinbox .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} TSpinbox TSpinbox}
test spinbox-5.2 "style command" -body {
    ttk::style configure customStyle.TSpinbox
    ttk::spinbox .w -style customStyle.TSpinbox
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.TSpinbox customStyle.TSpinbox TSpinbox}

tcltest::cleanupTests

# Local variables:
# mode: tcl
# End:

Changes to tests/ttk/treetags.test.

1
2
3


4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
1


2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48

-
-
+
+
-










+




-
+











-
+









-
+








package require tk
package require tcltest 2.2
package require Tk
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

### treeview tag invariants:
#

proc assert {expr {message ""}} {
    if {![uplevel 1 [list expr $expr]]} {
        error "PANIC: $message ($expr failed)"
    }
}
proc in {e l} { expr {[lsearch -exact $l $e] >= 0} }

proc itemConstraints {tv item} {
    # $tag in [$tv item $item -tags] <==> [$tv tag has $tag $item]
    foreach tag [$tv item $item -tags] {
	assert {$item in [$tv tag has $tag]}
	assert {[in $item [$tv tag has $tag]]}
    }
    foreach child [$tv children $item] {
	itemConstraints $tv $child
    }
}

proc treeConstraints {tv} {
    # $item in [$tv tag has $tag] <==> [$tv tag has $tag $item]
    #
    foreach tag [$tv tag names] {
	foreach item [$tv tag has $tag] {
	    assert {$tag in [$tv item $item -tags]}
	    assert {[in $tag [$tv item $item -tags]]}
	}
    }

    itemConstraints $tv {}
}
#
###

test treetags-1.0 "Setup" -body {
    set tv [ttk::treeview .tv -columns "A B C"]
    set tv [ttk::treeview .tv]
    .tv insert {} end -id item1 -text "Item 1"
    pack .tv
} -cleanup {
    treeConstraints $tv
}

test treetags-1.1 "Bad tag list" -body {
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-
+







    treeConstraints $tv
} -result [list tag1]

test treetags-1.3 "tag has - test" -body {
    $tv insert {} end -id item2 -text "Item 2" -tags tag2
    set result [list]
    foreach item {item1 item2} {
	foreach tag {tag1 tag2 tag3} {
    	foreach tag {tag1 tag2 tag3} {
	    lappend result $item $tag [$tv tag has $tag $item]
	}
    }
    set result
} -cleanup {
    treeConstraints $tv
} -result [list \
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133


134
135
136
137
138
139

140
141

142
143
144
145
146
147
148

149
150
151

152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
110
111
112
113
114
115
116






117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132

133
134

135
136
137
138
139
140
141

142
143
144

145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187






188





189











































190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211







-
-
-
-
-
-









-
-
+
+





-
+

-
+






-
+


-
+

-
+




















-
+



















-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-
+







} -result [list tag1 tag2 tag3 tag4]

test treetags-1.10 "tag names - tag configured" -body {
    $tv tag configure tag5
    lsort [$tv tag names]
} -result [list tag1 tag2 tag3 tag4 tag5]

test treetags-1.11 "tag delete" -body {
    $tv tag delete tag5
    $tv tag delete tag4
    lsort [$tv tag names]
} -result [list tag1 tag2 tag3]

test treetags-1.end "cleanup" -body {
    $tv item item1 -tags tag1
    $tv item item2 -tags tag2
    list [$tv tag has tag1] [$tv tag has tag2] [$tv tag has tag3]
} -cleanup {
    treeConstraints $tv
} -result [list [list item1] [list item2] [list]]

test treetags-2.0 "tag bind" -body {
    $tv tag bind tag1 <Key> {set ::KEY %A}
    $tv tag bind tag1 <Key>
    $tv tag bind tag1 <KeyPress> {set ::KEY %A}
    $tv tag bind tag1 <KeyPress>
} -cleanup {
    treeConstraints $tv
} -result {set ::KEY %A}

test treetags-2.1 "Events delivered to tags" -body {
    focus -force $tv ; update	;# needed so [event generate] delivers Key
    focus -force $tv ; update	;# needed so [event generate] delivers KeyPress
    $tv focus item1
    event generate $tv <a>
    event generate $tv <KeyPress-a>
    set ::KEY
} -cleanup {
    treeConstraints $tv
} -result a

test treetags-2.2 "Events delivered to correct tags" -body {
    $tv tag bind tag2 <Key> [list set ::KEY2 %A]
    $tv tag bind tag2 <KeyPress> [list set ::KEY2 %A]

    $tv focus item1
    event generate $tv <b>
    event generate $tv <KeyPress-b>
    $tv focus item2
    event generate $tv <c>
    event generate $tv <KeyPress-c>

    list $::KEY $::KEY2
} -cleanup {
    treeConstraints $tv
} -result [list b c]

test treetags-2.3 "Virtual events delivered to focus item" -body {
    set ::bong 0
    $tv tag bind tag2 <<Bing>> { incr bong }
    $tv focus item2
    event generate $tv <<Bing>>
    $tv focus item1
    event generate $tv <<Bing>>
    set bong
} -cleanup {
    treeConstraints $tv
} -result 1

test treetags-2.4 "Bad events" -body {
    $tv tag bind bad <Enter> { puts "Entered!" }
} -returnCodes error -result "unsupported event <Enter>*" -match glob
} -returnCodes 1 -result "unsupported event <Enter>*" -match glob

test treetags-3.0 "tag configure - set" -body {
    $tv tag configure tag1 -foreground blue -background red
} -cleanup {
    treeConstraints $tv
} -result {}

test treetags-3.1 "tag configure - get" -body {
    $tv tag configure tag1 -foreground
} -cleanup {
    treeConstraints $tv
} -result blue

# @@@ fragile test
test treetags-3.2 "tag configure - enumerate" -body {
    $tv tag configure tag1
} -cleanup {
    treeConstraints $tv
} -result [list \
    -image {} -imageanchor {} -background red -stripedbackground {} -foreground blue -font {} -padding {} \
                  ]
test treetags-4.1 "tag cell add" -body {
    $tv tag cell add _thetag
} -returnCodes 1 -result {wrong # args: should be ".tv tag cell add tagName cells"}

    -text {} -image {} -anchor {} -background red -foreground blue -font {} \
test treetags-4.2 "tag cell remove" -body {
    $tv tag cell remove _thetag
    $tv tag cell remove
} -returnCodes 1 -result {wrong # args: should be ".tv tag cell remove tagName ?cells?"}

]
test treetags-4.3 "tag cell has" -body {
    $tv tag cell has _thetag
    $tv tag cell has
} -returnCodes 1 -result {wrong # args: should be ".tv tag cell has tagName ?cell?"}

test treetags-4.3.1 "tag cell has" -body {
    $tv tag cell add tag1 "item1 #2"
    set res [$tv tag cell has tag1 "item1 #2"]
    lappend res [$tv tag cell has tag1 "item1 #1"]
    lappend res [$tv tag cell has tag1 "item1 #3"]
    lappend res {*}[$tv tag cell has tag1]
    $tv tag cell remove tag1 "item1 B"
    lappend res {*}[$tv tag cell has tag1]
    lappend res [$tv tag cell has tag1 "item1 #2"]
} -result {1 0 0 {item1 B} 0}

test treetags-4.4 "tag cell add" -body {
    $tv tag cell add tag1 "item1 A"
    $tv tag cell add tag1 "item1 #3"
    $tv tag cell has tag1
} -result {{item1 A} {item1 C}}

test treetags-4.5 "tag cell add" -body {
    $tv tag cell add tag2 "item1 A"
    $tv tag cell add tag2 "item1 #2"
    $tv tag cell has tag2
} -result {{item1 A} {item1 B}}

test treetags-4.6 "tag cell remove" -body {
    $tv tag cell remove tag1 "item1 A"
    $tv tag cell has tag1
} -result {{item1 C}}

test treetags-4.7 "tag cell remove" -body {
    $tv tag cell remove tag2
    $tv tag cell has tag2
} -result {}

test treetags-4.8 "tag delete with tagged cells" -body {
    $tv tag cell add tag6 "item1 A"
    $tv tag delete tag6
    $tv tag cell has tag6
} -result {}

# The next test exercises tag resource management.
# If options are not properly freed, the message:
# Test file error: "Font times 20 still in cache."
# will show up on stderr at program exit.
#
test treetags-3.3 "tag configure - set font" -body {
    $tv tag configure tag2 -font {times 20}
}

test treetags-3.4 "stomp tags in tag binding procedure" -body {
    set result [list]
    $tv tag bind rm1 <<Remove>> { lappend ::result rm1 [%W focus] <<Remove>> }
    $tv tag bind rm2 <<Remove>> {
	lappend ::result rm2 [%W focus] <<Remove>>
    	lappend ::result rm2 [%W focus] <<Remove>>
	%W item [%W focus] -tags {tag1}
    }
    $tv tag bind rm3 <<Remove>> { lappend ::result rm3 [%W focus] <<Remove>> }

    $tv item item1 -tags {rm1 rm2 rm3}
    $tv focus item1
    event generate $tv <<Remove>>

Changes to tests/ttk/treeview.test.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78

79
80
81
82

83
84
85
86


87
88
89
90
91
92

93
94
95
96

97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118


119
120
121
122
123
124
125
1
2
3
4
5


6
7

8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34


35
36
37






38


39













40



41

42
43
44
45
46
47

48
49
50
51

52
53
54
55

56
57
58


59
60
61
62
63
64
65

66
67
68
69

70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101





-
-
+
+
-










-
+











-
+




-
-
+


-
-
-
-
-
-

-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-

-






-
+



-
+



-
+


-
-
+
+





-
+



-
+



-
+











-
+






+
+







#
# [7Jun2005] TO CHECK: [$tv see {}] -- shouldn't work (at least, shouldn't do
# what it currently does)
#

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

# consistencyCheck --
#	Traverse the tree to make sure the item data structures
#	are properly linked.
#
#	Since [$tv children] follows ->next links and [$tv index]
#	follows ->prev links, this should cover all invariants.
#
proc consistencyCheck {tv {item {}}} {
    set i 0
    set i 0;
    foreach child [$tv children $item] {
	assert {[$tv parent $child] == $item} "parent $child = $item"
	assert {[$tv index $child] == $i} "index $child [$tv index $child]=$i"
	incr i
	consistencyCheck $tv $child
    }
}

proc assert {expr {message ""}} {
    if {![uplevel 1 [list expr $expr]]} {
        set error "PANIC! PANIC! PANIC: $message ($expr failed)"
	puts stderr $error
    	puts stderr $error
	error $error
    }
}

proc tvSetup {} {
    destroy .tv
test treeview-0 "treeview test - setup" -body {
    ttk::treeview .tv -columns {a b c}
    pack .tv -expand true -fill both
    .tv column #0 -width 50
    .tv column a -width 50
    .tv column b -width 50
    .tv column c -width 50
    # Make sure everything is created and updated
    tkwait visibility .tv
    update
    after 10
    update
}
proc tvSetupWithItems {} {
    tvSetup
    .tv insert {} end -id nn -text "nn"
    .tv insert nn end -id nn.n1 -text "nn.1"
    .tv insert nn end -id nn.n2 -text "nn.3"
    .tv insert nn end -id nn.n3 -text "nn.3"
    for {set t 2} {$t < 100} {incr t} {
        .tv insert {} end -id nn$t -text "nn$t"
        if {$t % 3 == 0} {
            .tv insert nn$t end -id nn$t.n1 -text "nn$t.n1"
            .tv insert nn$t end -id nn$t.n2 -text "nn$t.n2"
            .tv insert nn$t end -id nn$t.n3 -text "nn$t.n3"
        }

    }
}

test treeview-1.1 "columns" -body {
    tvSetup
    .tv configure -columns {a b c}
}

test treeview-1.2 "Bad columns" -body {
    #.tv configure -columns {illegal "list"value}
    ttk::treeview .badtv -columns {illegal "list"value}
} -returnCodes error -result "list element in quotes followed by*" -match glob
} -returnCodes 1 -result "list element in quotes followed by*" -match glob

test treeview-1.3 "bad displaycolumns" -body {
    .tv configure -displaycolumns {a b d}
} -returnCodes error -result "Invalid column index d"
} -returnCodes 1 -result "Invalid column index d"

test treeview-1.4 "more bad displaycolumns" -body {
    .tv configure -displaycolumns {1 2 3}
} -returnCodes error -result {Column index "3" out of bounds}
} -returnCodes 1 -result "Column index 3 out of bounds"

test treeview-1.5 "Don't forget to check negative numbers" -body {
    .tv configure -displaycolumns {1 {} 3}
} -returnCodes error -result {Column index "" out of bounds}
    .tv configure -displaycolumns {1 -2 3}
} -returnCodes 1 -result "Column index -2 out of bounds"

# Item creation.
#
test treeview-2.1 "insert -- not enough args" -body {
    .tv insert
} -returnCodes error -result "wrong # args: *" -match glob
} -returnCodes 1 -result "wrong # args: *" -match glob

test treeview-2.3 "insert -- bad integer index" -body {
    .tv insert {} badindex
} -returnCodes error -result "expected integer *" -match glob
} -returnCodes 1 -result "expected integer *" -match glob

test treeview-2.4 "insert -- bad parent node" -body {
    .tv insert badparent end
} -returnCodes error -result "Item badparent not found" -match glob
} -returnCodes 1 -result "Item badparent not found" -match glob

test treeview-2.5 "insert -- finaly insert a node" -body {
    .tv insert {} end -id newnode -text "New node"
} -result newnode

test treeview-2.6 "insert -- make sure node was inserted" -body {
    .tv children {}
} -result [list newnode]

test treeview-2.7 "insert -- prevent duplicate node names" -body {
    .tv insert {} end -id newnode
} -returnCodes error -result "Item newnode already exists"
} -returnCodes 1 -result "Item newnode already exists"

test treeview-2.8 "insert -- new node at end" -body {
    .tv insert {} end -id lastnode
    consistencyCheck .tv
    .tv children {}
} -result [list newnode lastnode]

consistencyCheck .tv

test treeview-2.9 "insert -- new node at beginning" -body {
    .tv insert {} 0 -id firstnode
    consistencyCheck .tv
    .tv children {}
} -result [list firstnode newnode lastnode]

145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135







-
+







    .tv insert {} 0 -id newfirstone
    consistencyCheck .tv
    .tv children {}
} -result [list newfirstone firstnode newnode anotherone onemore lastnode newlastone]

test treeview-2.14 "insert -- bad options" -body {
    .tv insert {} end -badoption foo
} -returnCodes error -result {unknown option "-badoption"}
} -returnCodes 1 -result {unknown option "-badoption"}

test treeview-2.15 "insert -- at position 0 w/no children" -body {
    .tv insert newnode 0 -id newnode.n2 -text "Foo"
    .tv children newnode
} -result newnode.n2	;# don't crash

test treeview-2.16 "insert -- insert way past end" -body {
187
188
189
190
191
192
193
194
195
196
197
198


199
200
201
202
203
204
205
163
164
165
166
167
168
169

170
171


172
173
174
175
176
177
178
179
180







-


-
-
+
+







    foreach item [.tv children {}] {
	lappend result [.tv index $item]
    }
    set result
} -result [list 0 1 2 3 4 5 6]

test treeview-3.6 "detach" -body {
    set before [.tv detached newnode]
    .tv detach newnode
    consistencyCheck .tv
    list [.tv children {}] [.tv detached] $before [.tv detached newnode]
} -result {{newfirstone firstnode anotherone onemore lastnode newlastone} newnode 0 1}
    .tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone]
# XREF: treeview-2.13

test treeview-3.7 "detach didn't screw up internal links" -body {
    consistencyCheck .tv
    set result [list]
    foreach item [.tv children {}] {
	lappend result [.tv index $item]
220
221
222
223
224
225
226
227
228
229
230


231
232
233
234
235
236
237


238
239
240
241
242
243
244
245


246
247
248
249
250
251
252
195
196
197
198
199
200
201

202
203

204
205
206
207

208
209


210
211
212
213
214

215
216


217
218
219
220
221
222
223
224
225







-


-
+
+


-


-
-
+
+



-


-
-
+
+







    .tv detach newnode
    consistencyCheck .tv
    .tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone]

test treeview-3.11 "Can't detach root item" -body {
    .tv detach [list {}]
} -cleanup {
    update
    consistencyCheck .tv
} -returnCodes error -result "Cannot detach root item"
} -returnCodes 1 -result "Cannot detach root item"
consistencyCheck .tv

test treeview-3.12 "Reattach" -body {
    set before [.tv detached newnode]
    .tv move newnode {} end
    consistencyCheck .tv
    list [.tv children {}] $before [.tv detached newnode] [.tv detached]
} -result {{newfirstone firstnode anotherone onemore lastnode newlastone newnode} 1 0 {}}
    .tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone newnode]

# Bug # ?????
test treeview-3.13 "Re-reattach" -body {
    set before [.tv detached newnode]
    .tv move newnode {} end
    consistencyCheck .tv
    list [.tv children {}] $before [.tv detached newnode]
} -result {{newfirstone firstnode anotherone onemore lastnode newlastone newnode} 0 0}
    .tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone newnode]

catch {
    .tv insert newfirstone end -id x1
    .tv insert newfirstone end -id x2
    .tv insert newfirstone end -id x3
}

297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284







-
+







test treeview-4.3 "opened - closed node" -body {
    .tv item newnode -open 0
    .tv item newnode -open
} -result 0

test treeview-5.1 "item -- error checks" -body {
    .tv item newnode -text "Bad values" -values "{bad}list"
} -returnCodes error -result "list element in braces followed by*" -match glob
} -returnCodes 1 -result "list element in braces followed by*" -match glob

test treeview-5.2 "item -- error leaves options unchanged " -body {
    .tv item newnode -text
} -result "New node"

test treeview-5.3 "Heading" -body {
    .tv heading #0 -text "Heading"
320
321
322
323
324
325
326
327

328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389


390
391
392
393
394
395
396
293
294
295
296
297
298
299

300
301
302
303

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336












337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359







-
+



-
+















-
+
















-
-
-
-
-
-
-
-
-
-
-
-














+
+







test treeview-5.5 "set cell" -body {
    .tv set newnode 1 XXX
    .tv item newnode -values
} -result [list a XXX c]

test treeview-5.6 "set illegal cell" -body {
    .tv set newnode #0 YYY
} -returnCodes error -result "Display column #0 cannot be set"
} -returnCodes 1 -result "Display column #0 cannot be set"

test treeview-5.7 "set illegal cell" -body {
    .tv set newnode 3 YY	;# 3 == current #columns
} -returnCodes error -result {Column index "3" out of bounds}
} -returnCodes 1 -result "Column index 3 out of bounds"

test treeview-5.8 "set display columns" -body {
    .tv configure -displaycolumns [list 2 1 0]
    .tv set newnode #1 X
    .tv set newnode #2 Y
    .tv set newnode #3 Z
    .tv item newnode -values
} -result [list Z Y X]

test treeview-5.9 "display columns part 2" -body {
    list [.tv column #1 -id] [.tv column #2 -id] [.tv column #3 -id]
} -result [list c b a]

test treeview-5.10 "cannot set column -id" -body {
    .tv column #1 -id X
} -returnCodes error -result "Attempt to change read-only option"
} -returnCodes 1 -result "Attempt to change read-only option"

test treeview-5.11 "get" -body {
    .tv set newnode #1
} -result X

test treeview-5.12 "get dictionary" -body {
    .tv set newnode
} -result [list a Z b Y c X]

test treeview-5.13 "get, no value" -body {
    set newitem [.tv insert {} end]
    set result [.tv set $newitem #1]
    .tv delete $newitem
    set result
} -result {}

test treeview-5.14 "set illegal height" -body {
    # For now, -height can only be integer
    .tv item newnode -height 1.5
} -returnCodes 1 -result {expected integer but got "1.5"}

test treeview-5.15 "set illegal height" -body {
    .tv item newnode -height 0
} -returnCodes 1 -result "Invalid item height 0"

test treeview-5.16 "no change after illegal attempt" -body {
    .tv item newnode -height
} -result 1

test treeview-6.1 "deletion - setup" -body {
    .tv insert {} end -id dtest
    foreach id [list a b c d e] {
	.tv insert dtest end -id $id
    }
    .tv children dtest
} -result [list a b c d e]

test treeview-6.1.1 "delete" -body {
    .tv delete b
    consistencyCheck .tv
    list [.tv exists b] [.tv children dtest]
} -result [list 0 [list a c d e]]

consistencyCheck .tv

test treeview-6.2 "delete - duplicate items in list" -body {
    .tv delete [list a e a e]
    consistencyCheck .tv
    .tv children dtest
} -result [list c d]

438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467


468
469
470
471
472
473
474
475
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429


430
431

432
433
434
435
436
437
438







-
+




















+
-
-
+
+
-







    .tv move d3 d 0
    consistencyCheck .tv
    .tv children d
} -result [list d3 d1 d2]

test treeview-7.2 "illegal move" -body {
   .tv move d d2 end
} -returnCodes error -result "Cannot insert d as descendant of d2"
} -returnCodes 1 -result "Cannot insert d as descendant of d2"

test treeview-7.3 "illegal move has no effect" -body {
    consistencyCheck .tv
    .tv children d
} -result [list d3 d1 d2]

test treeview-7.4 "Replace children" -body {
    .tv children d [list d3 d2 d1]
    consistencyCheck .tv
    .tv children d
} -result [list d3 d2 d1]

test treeview-7.5 "replace children - precondition" -body {
    # Just check to make sure the test suite so far has left
    # us in the state we expect to be in:
    list [.tv parent newnode] [.tv children newnode]
} -result [list {} [list newnode.n1 newnode.n2 newnode.n3]]

test treeview-7.6 "Replace children - illegal move" -body {
    .tv children newnode.n1 [list newnode.n1 newnode.n2 newnode.n3]
} -returnCodes 1 -result "Cannot insert newnode.n1 as descendant of newnode.n1"
} -cleanup {
    consistencyCheck .tv

consistencyCheck .tv
} -returnCodes error -result "Cannot insert newnode.n1 as descendant of newnode.n1"

test treeview-8.0 "Selection set" -body {
    .tv selection set [list newnode.n1 newnode.n3 newnode.n2]
    .tv selection
} -result [list newnode.n1 newnode.n2 newnode.n3]

test treeview-8.1 "Selection add" -body {
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
453
454
455
456
457
458
459

460
461



















































































































462
463
464
465
466
467

468
469
470
471
472





















































































































































































































































































473
474
475
476
477
478
479







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







test treeview-8.4 "Selection - clear" -body {
    .tv selection set {}
    .tv selection
} -result {}

test treeview-8.5 "Selection - bad operation" -body {
    .tv selection badop foo
} -returnCodes error -match glob -result {bad selection operation "badop": must be *}
} -returnCodes 1 -match glob -result {bad selection operation "badop": must be *}

test treeview-8.7 "<<TreeviewSelect>> when deleting items" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv insert "" end -id myItem2 -text SecondItem
    .tv selection add myItem1
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv delete myItem2  ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 2
    .tv delete myItem1  ; # <<TreeviewSelect>> triggers
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2}

test treeview-8.8 "<<TreeviewSelect>> when setting the selection" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv insert "" end -id myItem2 -text SecondItem
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv selection set ""       ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 2
    .tv selection set myItem1  ; # <<TreeviewSelect>> triggers
    update
    # Current implementation generates an event for this case
    set val 3
    .tv selection set myItem1  ; # (already selected)
    update
    set val 4
    .tv selection set {myItem1 myItem2}  ; # <<TreeviewSelect>> triggers
    update
    set val 5
    .tv selection set {myItem2}  ; # <<TreeviewSelect>> triggers
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2 3 4 5}

test treeview-8.9 "<<TreeviewSelect>> when removing items from the selection" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv selection set myItem1
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv selection remove ""       ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 2
    .tv selection remove myItem1  ; # <<TreeviewSelect>> triggers
    update
    set val 3
    .tv selection remove myItem1  ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2}

test treeview-8.10 "<<TreeviewSelect>> when adding items in the selection" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv insert "" end -id myItem2 -text SecondItem
    .tv insert "" end -id myItem3 -text ThirdItem
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv selection add myItem2  ; # <<TreeviewSelect>> triggers
    update
    set val 2
    .tv selection add myItem2  ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 3
    .tv selection add myItem3  ; # <<TreeviewSelect>> triggers
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {1 3}

test treeview-8.11 "<<TreeviewSelect>> when toggling" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv insert "" end -id myItem2 -text SecondItem
    .tv insert "" end -id myItem3 -text ThirdItem
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv selection toggle ""  ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 2
    .tv selection toggle {myItem1 myItem3}  ; # <<TreeviewSelect>> triggers
    update
    set val 3
    .tv selection toggle {myItem3 myItem2}  ; # <<TreeviewSelect>> triggers
    update
    set val 4
    .tv selection toggle {myItem3 myItem2}  ; # <<TreeviewSelect>> triggers
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2 3 4}

### NEED: more tests for see/yview/scrolling

proc scrollcallback {args} {
    set ::scrolldata $args
}
test treeview-9.0 "scroll callback - empty tree" -body {
    tvSetup
    .tv configure -yscrollcommand scrollcallback
    .tv delete [.tv children {}]
    update
    set ::scrolldata
} -result [list 0.0 1.0]

test treeview-9.1 "scrolling" -setup {
    pack [ttk::treeview .tree -show tree] -fill y
    for {set i 1} {$i < 100} {incr i} {
        .tree insert {} end -text $i
    }
} -body {
    .tree yview scroll 5 units
    # This is sensitive to the exact layout of a tree.
    # It assumes that (8,8) should be far enough in to be in the tree,
    # while still being in the first item.
    .tree identify item 8 8
} -cleanup {
    destroy .tree
} -result {I006}

test treeview-9.2 {scrolling on see command - bug [14188104c3]} -setup {
    toplevel .top
    ttk::treeview .top.tree -show {} -height 10 -columns {label} \
            -yscrollcommand [list .top.vs set]
    ttk::scrollbar .top.vs -command {.top.tree yview}
    grid .top.tree -row 0 -column 0 -sticky ns
    grid .top.vs -row 0 -column 1 -sticky ns
    update
    proc setrows {n} {
        .top.tree delete [.top.tree children {}]
        for {set i 1} {$i <= $n} {incr i} {
            .top.tree insert {} end -id row$i \
                    -values [list [format "Row %2.2d" $i]]
        }
        .top.tree see row1
        update idletasks
    }
} -body {
    setrows 10
    set res [.top.vs get]
    setrows 20
    lappend res [expr [lindex [.top.vs get] 1] < 1]
} -cleanup {
    destroy .top
} -result {0.0 1.0 1}

test treeview-9.3 {scrolling on see command, requested item is closed} -setup {
    toplevel .top
    ttk::treeview .top.tree -show tree -height 10 -columns {label} \
            -yscrollcommand [list .top.vs set]
    ttk::scrollbar .top.vs -command {.top.tree yview}
    grid .top.tree -row 0 -column 0 -sticky ns
    grid .top.vs -row 0 -column 1 -sticky ns

    .top.tree insert {} end -id a -text a
    .top.tree insert a  end -id b -text b
    .top.tree insert b  end -id c -text c
    .top.tree insert c  end -id d -text d
    .top.tree insert d  end -id e -text e
    for {set i 6} {$i <= 15} {incr i} {
        .top.tree insert {} end -id row$i \
                -values [list [format "Row %2.2d" $i]]
    }
    update
} -body {
    set before [lindex [.top.vs get] 1]
    .top.tree see e
    update idletasks
    set after [lindex [.top.vs get] 1]
    expr $after < $before
} -cleanup {
    destroy .top
} -result 1

test treeview-10.0 "See command" -setup {
    # Setup common for all 10.* tests
    ttk::style configure Treeview -rowheight 20
    tvSetupWithItems
    set ::baseBbY [lindex [.tv bbox nn "#1"] 1]
    proc bbY {item} {
        set bb [.tv bbox $item "#1"]
        set y [lindex $bb 1]
        if {$y eq ""} {return "_"}
        return [expr {$y - $::baseBbY}]
    }
} -body {
    set res ""
    lappend res [bbY nn99]
    .tv see nn99
    lappend res [bbY nn99]
    set res
} -result {_ 180}

test treeview-10.1 "See command, auto-open" -body {
    set res ""
    lappend res [bbY nn96]
    # Not yet visible
    lappend res [bbY nn96.n1]
    .tv see nn96.n1
    lappend res [bbY nn96.n1]
    # Pushed out by the opening, not visible
    lappend res [bbY nn99]
    set res
} -result {120 _ 140 _}

test treeview-10.2 "See command, height" -setup {
    .tv item nn34 -height 4
    .tv item nn55 -height 30
    .tv item nn76 -height 5
} -body {
    set res ""
    lappend res [bbY nn34]
    .tv see nn34
    lappend res [bbY nn34]
    .tv see nn33
    lappend res [bbY nn34]

    lappend res [bbY nn76]
    .tv see nn76
    lappend res [bbY nn76]

    .tv see nn53
    lappend res [bbY nn53]
    # Partly visible
    lappend res [bbY nn55]
    .tv see nn55
    # Scrolled to top
    lappend res [bbY nn55]
    set res
} -result {_ 0 20 _ 100 0 40 0}

test treeview-11.0 "Cellselection set rectangle" -setup {
    # Setup common for all 11.* tests
    tvSetupWithItems
    .tv configure -columns {a b c d}
    .tv configure -displaycolumns {a b c}
} -body {
    .tv cellselection set "nn.n3 #2" "nn.n1 a"
    .tv cellselection
} -result [list "nn.n1 a" "nn.n1 b" "nn.n2 a" "nn.n2 b" "nn.n3 a" "nn.n3 b"]

test treeview-11.1 "Cellselection set" -body {
    .tv cellselection set [list "nn.n1 a" "nn.n2 a" "nn.n3 #2" "nn.n2 d"]
    .tv cellselection
} -result [list "nn.n1 a" "nn.n2 a" "nn.n2 d" "nn.n3 b"]

test treeview-11.2 "Cellselection add" -body {
    .tv cellselection add "nn b"
    .tv cellselection
} -result [list "nn b" "nn.n1 a" "nn.n2 a" "nn.n2 d" "nn.n3 b"]

test treeview-11.3 "Cellselection toggle" -body {
    .tv cellselection toggle [list "nn.n2 a" "nn2 b" "nn2 #0"]
    .tv cellselection
} -result [list "nn b" "nn.n1 a" "nn.n2 d" "nn.n3 b" "nn2 b" "nn2 #0"]

test treeview-11.4 "Cellselection remove" -body {
    .tv cellselection remove [list "nn.n2 d" "nn b" "nn2 #0"]
    .tv cellselection
} -result [list "nn.n1 a" "nn.n3 b" "nn2 b"]

test treeview-11.5 "Cellselection add rectangle" -body {
    .tv cellselection add "nn a" "nn.n1 c"
    .tv cellselection
} -result [list \
                   "nn a" "nn b" "nn c" \
                   "nn.n1 a" "nn.n1 b" "nn.n1 c" \
                   "nn.n3 b" \
                   "nn2 b"]

test treeview-11.6 "Cellselection toggle rectangle" -body {
    .tv cellselection toggle "nn.n1 b" "nn.n3 c"
    .tv cellselection
} -result [list \
                   "nn a" "nn b" "nn c" \
                   "nn.n1 a" \
                   "nn.n2 b" "nn.n2 c" \
                   "nn.n3 c" \
                   "nn2 b"]

test treeview-11.7 "Cellselection remove rectangle" -body {
    .tv cellselection remove "nn.n1 a" "nn.n3 b"
    .tv cellselection
} -result [list \
                   "nn a" "nn b" "nn c" \
                   "nn.n2 c" \
                   "nn.n3 c" \
                   "nn2 b"]

test treeview-11.8 "Cellselection set rectangle" -body {
    # This tests that "set" clears out all old selections
    .tv cellselection set "nn b" "nn.n1 c"
    .tv cellselection
} -result [list "nn b" "nn c" "nn.n1 b" "nn.n1 c"]

test treeview-11.9 "Cellselection - clear" -body {
    .tv cellselection set {}
    .tv cellselection
} -result {}

test treeview-11.10 "Cellselection - bad operation" -body {
    .tv cellselection badop foo
} -returnCodes 1 -match glob -result {bad cellselection operation "badop": must be *}

test treeview-11.11 "Cellselection - <<TreeviewSelect>> on cellselection add" -body {
    .tv cellselection set {}
    bind .tv <<TreeviewSelect>> {set res 1}
    set res 0
    .tv cellselection add {"nn.n1 b"}
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result 1

test treeview-11.12 "<<TreeviewSelect>> on selected cell deletion" -body {
    .tv cellselection set {}
    .tv insert "" end -id selectedDoomed -text DeadItem
    .tv insert "" end -id doomed -text AlsoDead
    .tv cellselection add {"selectedDoomed c"}
    .tv cellselection add {"doomed c"}
    .tv cellselection remove {"doomed c"}
    update
    bind .tv <<TreeviewSelect>> {lappend res 1}
    set res 0
    .tv delete doomed
    update
    set res [expr {$res == 0}]
    .tv delete selectedDoomed
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {1 1}

test treeview-11.13 "Cellselection - error" -body {
    .tv cellselection set [list "apa a"]
} -returnCodes 1 -match glob -result {Item apa not found}

test treeview-11.14 "Cellselection - error" -body {
    .tv cellselection set [list "nn xx "]
} -returnCodes 1 -match glob -result {Invalid column index xx}

test treeview-11.15 "Cellselection - error" -body {
    .tv cellselection set "nn c" "nn d"
} -returnCodes 1 -match glob -result {Cell id must be in a visible column}

test treeview-11.16 "Cellselection - non visible" -body {
    .tv cellselection set [list "nn d"]
    .tv cellselection
} -result {{nn d}}

# Same as 8.8, but for cell selection
test treeview-11.17 "<<TreeviewSelect>> when setting the selection" -body {
    .tv delete [.tv children {}]
    .tv insert "" end -id myItem1 -text FirstItem
    .tv insert "" end -id myItem2 -text SecondItem
    update
    bind .tv <<TreeviewSelect>> {lappend res $val}
    set res {}
    set val 1
    .tv cellselection set ""   ; # no <<TreeviewSelect>> (selection unchanged)
    update
    set val 2
    .tv cellselection set "myItem1 a"  ; # <<TreeviewSelect>> triggers
    update
    # Current implementation generates an event for this case
    set val 3
    .tv cellselection set "myItem1 a"  ; # (already selected)
    update
    set val 4
    .tv cellselection set {{myItem1 a} {myItem2 a}} ; # <<TreeviewSelect>>
    update
    set val 5
    .tv cellselection set {myItem2 a}  ; # <<TreeviewSelect>> triggers
    update
    set res
} -cleanup {
    bind .tv <<TreeviewSelect>> {}
} -result {2 3 4 5}


### identify tests:
#
proc identify* {tv comps args} {
    foreach {x y} $args {
	foreach comp $comps {
	    lappend result [$tv identify $comp $x $y]
925
926
927
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974
975
976
977


978
979
980
981
982

983
984
985
986
987
988
989


990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217

1218
1219

1220
1221
1222
1223
1224
1225
1226
495
496
497
498
499
500
501

502
503

504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531

532
533
534
535
536
537
538
539
540
541
542
543


544
545
546
547
548
549

550
551
552
553
554
555


556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571







572
573
574
575
576
577

578
579
580
581
582
583
584
585
586
587
588
589
590






























































































591
592
593
594








































































595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610

611
612

613
614
615
616
617
618
619
620







-


-
+


-



















-
+





-
+











-
-
+
+




-
+





-
-
+
+














-
-
-
-
-
-
-






-













-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+










-
+

-
+







    }
    return $result
}

test treeview-identify-setup "identify series - setup" -body {
    destroy .tv
    ttk::setTheme default
    ttk::style configure Treeview -rowheight 20
    ttk::treeview .tv -columns [list A B C]
    .tv insert {} end -id branch -text branch -open true
    .tv insert branch end -id item1 -text item1 -height 2
    .tv insert branch end -id item1 -text item1
    .tv insert branch end -id item2 -text item2
    .tv insert branch end -id item3 -text item3
    .tv insert {} end -id item4 -text item4

    .tv column #0 -width 50	;# 0-50
    .tv column A -width 50	;# 50-100
    .tv column B -width 50	;# 100-150
    .tv column C -width 50	;# 150-200 (plus slop for margins)

    wm geometry . {} ; pack .tv ; update
}

test treeview-identify-1 "identify heading" -body {
    .tv configure -show {headings tree}
    update idletasks
    identify* .tv {region column} 10 10
} -result [list heading #0]

test treeview-identify-2 "identify columns" -body {
    .tv configure -displaycolumns #all
    update idletasks
    columnids .tv [identify* .tv column 25 10  75 10  125 10  175 10]
} -result [list \#0 A B C]
} -result [list {} A B C]

test treeview-identify-3 "reordered columns" -body {
    .tv configure -displaycolumns {B A C}
    update idletasks
    columnids .tv [identify* .tv column 25 10  75 10  125 10  175 10]
} -result [list \#0 B A C]
} -result [list {} B A C]

test treeview-identify-4 "no tree column" -body {
    .tv configure -displaycolumns #all -show {headings}
    update idletasks
    identify* .tv {region column} 25 10  75 10  125 10  175 10
} -result [list heading #1 heading #2 heading #3 nothing {}]

# Item height in default theme is 20px
test treeview-identify-5 "vertical scan - no headings" -body {
    .tv configure -displaycolumns #all -show {tree}
    update idletasks
    identify* .tv {region item} 25 10  25 30  25 70  25 90  25 110  25 130
} -result [list tree branch tree item1 tree item2 tree item3 tree item4 nothing {}]
    identify* .tv {region item} 25 10  25 30  25 50  25 70  25 90
} -result [list tree branch tree item1 tree item2 tree item3 nothing {}]

test treeview-identify-6 "vertical scan - with headings" -body {
    .tv configure -displaycolumns #all -show {tree headings}
    update idletasks
    identify* .tv {region item} 25 10  25 30  25 50  25 90  25 110
    identify* .tv {region item} 25 10  25 30  25 50  25 70  25 90
} -result [list heading {} tree branch tree item1 tree item2 tree item3]

test treeview-identify-7 "vertical scan - headings, no tree" -body {
    .tv configure -displaycolumns #all -show {headings}
    update idletasks
    identify* .tv {region item cell} 25 10  25 30  25 50  75 90  25 110
} -result [list heading {} {} cell branch {branch #1} cell item1 {item1 #1} cell item2 {item2 #2} cell item3 {item3 #1}]
    identify* .tv {region item} 25 10  25 30  25 50  25 70  25 90
} -result [list heading {} cell branch cell item1 cell item2 cell item3]

# In default theme, -indent and -itemheight both 20px
# Disclosure element name is "Treeitem.indicator"
set disclosure "*.indicator"
test treeview-identify-8 "identify element" -body {
    .tv configure -show {tree}
    .tv insert branch  0 -id branch2 -open true
    .tv insert branch2 0 -id branch3 -open true
    .tv insert branch3 0 -id leaf3
    update idletasks;
    identify* .tv {item element} 10 10  30 30  50 50
} -match glob -result [list \
	branch $disclosure branch2 $disclosure branch3 $disclosure]

test treeview-identify-8.1 "identify element" -body {
    .tv configure -show {tree headings}
    update
    identify* .tv element 1 1  10 10  25 25
    # Heading elements are currently not reported
} -result [list {} {} text]

# See #2381555
test treeview-identify-9 "identify works when horizontally scrolled" -setup {
    .tv configure -show {tree headings}
    foreach column {#0 A B C} {
	.tv column $column -stretch 0 -width 50
    }
    # Scrollable area is 200, visible is 100
    place .tv -x 0 -y 0 -width 100
} -body {
    set result [list]
    foreach xoffs {0 50 100} {
	.tv xview $xoffs ; update
	lappend result [identify* .tv {region column} 10 10 60 10]
    }
    set result
} -result [list \
	[list heading #0 heading #1] \
	[list heading #1 heading #2] \
	[list heading #2 heading #3] ]

test treeview-identify-10 "identify works when horizontally scrolled" -setup {
    .tv configure -show {tree headings}
    .tv configure -titlecolumns 1
    foreach column {"#0" A B C} {
	.tv column $column -stretch 0 -width 50
    }
    # Scrollable area is 200, visible is 150
    place .tv -x 0 -y 0 -width 150
} -body {
    set result [list]
    foreach xoffs {0 25 50} {
	.tv xview $xoffs
        update
	lappend result [identify* .tv {region column} 10 10 60 10]
	lappend result [identify* .tv {region column} 10 50 60 50]
    }
    set result
} -result [list \
	[list heading #0 heading #1] [list tree #0 cell #1] \
	[list heading #0 heading #1] [list tree #0 cell #1] \
	[list heading #0 heading #2] [list tree #0 cell #2] ]

# Hijack the setup above to check bbox too
test treeview-identify-10b "bbox works when horizontally scrolled" -body {
    # Establish a point of reference
    .tv configure -titlecolumns 0
    .tv xview 0
    update
    set base [lindex [.tv bbox branch "#0"] 0]
    set result [list]
    foreach tc {0 1 2 3} {
        .tv configure -titlecolumns $tc
        foreach xoffs {0 25 50} {
            .tv xview $xoffs
            update
            # Extract x coordinate for each column
            lappend result [expr {[lindex [.tv bbox branch "#0"] 0] - $base}]
            lappend result [expr {[lindex [.tv bbox branch A   ] 0] - $base}]
            lappend result [expr {[lindex [.tv bbox branch B   ] 0] - $base}]
            lappend result [expr {[lindex [.tv bbox branch C   ] 0] - $base}]
        }
    }
    set result
} -result [list 0 50 100 150  -25 25  75 125   -50  0  50 100 \
                0 50 100 150    0 25  75 125     0  0  50 100 \
                0 50 100 150    0 50  75 125     0 50  50 100 \
                0 50 100 150    0 50 100 125     0 50 100 101]

# Followup to trigger crash that happened when title > display
test treeview-identify-10c "title more than display" -body {
    .tv configure -titlecolumns 10
    .tv xview 0
    update
    set x1 [.tv xview]
    # It shouldn't be possible to scroll
    .tv xview 50
    update
    set x2 [.tv xview]
    set result [list $x1 $x2]
} -result {{0.0 1.0} {0.0 1.0}}


test treeview-identify-11 "bbox supporting -height" -body {
    .tv configure -titlecolumns 0
    .tv xview 0
    .tv item branch2 -open false
    # Add extra items to make sure it scrolls
    .tv insert {} end -id item5 -text item5
    .tv insert {} end -id item6 -text item6
    # Height needs to be big enough to show the items we measure
    # and small enough to make scrolling happen.
    .tv configure -height 6
    pack .tv -side top
    update
    set base [lindex [.tv bbox branch A] 1]
    set result {}
    foreach yv {0 1} {
        .tv yview $yv
        update
        foreach item {item1 item2 item3} {
            set bb [.tv bbox $item A]
            set y [lindex $bb 1]
            if {$y eq ""} {
                # This is to get a clearer error if this goes wrong
                lappend result {}
            } else {
                lappend result [expr {$y - $base}]
            }
            lappend result [lindex $bb 3]
        }
    }
    set result
} -result [list 40 40 80 20 100 20  20 40 60 20 80 20]

test treeview-identify-cleanup "identify - cleanup" -body {
    destroy .tv
}


test treeview-rowheight-1 "rowheight - setup" -body {
    destroy .tv
    ttk::setTheme default
    # Test that style rowheight is in control
    ttk::style configure Treeview -rowheight 73
    tvSetupWithItems
    lindex [.tv bbox nn a] 3
} -result 73

test treeview-rowheight-2 "rowheight change" -body {
    # Reacts to style changes
    ttk::style configure Treeview -rowheight 25
    update
    lindex [.tv bbox nn a] 3
} -cleanup {
    ttk::style configure Treeview -rowheight {}
} -result 25

test treeview-rowheight-3 "rowheight adapts to font" -constraints haveBigFontTwiceLargerThanTextFont -body {
    ttk::style configure Treeview -font "Courier 12"
    update
    set baseline [lindex [.tv bbox nn a] 3]
    ttk::style configure Treeview -font "Helvetica 24"
    update
    set after [lindex [.tv bbox nn a] 3]
    set diff [expr {$after - $baseline}]
    # We only want to check there is an increase,
    # its exact magnitude does not matter
    expr {0 < $diff ? "OK" : $diff}
} -result OK

test treeview-rowheight-3b "rowheight adapts to named font" -constraints haveBigFontTwiceLargerThanTextFont -body {
    font create __tf -family Courier -size 12
    ttk::style configure Treeview -font __tf
    update
    set baseline [lindex [.tv bbox nn a] 3]
    font configure __tf -family Helvetica -size 24
    update
    set after [lindex [.tv bbox nn a] 3]
    set diff [expr {$after - $baseline}]
    # We only want to check there is an increase,
    # its exact magnitude does not matter
    expr {0 < $diff ? "OK" : $diff}
} -result OK

test treeview-rowheight-4 "rowheight adapts to item padding" -body {
    # Test that things from Item style is picked up.
    ttk::style configure Item -padding "2 2 2 2"
    update
    set baseline [lindex [.tv bbox nn a] 3]
    ttk::style configure Item -padding "2 3 2 5"
    update
    set after [lindex [.tv bbox nn a] 3]
    set diff [expr {$after - $baseline}]
} -cleanup {
    ttk::style configure Item -padding {}
} -result [expr {3-2 + 5-2}]

test treeview-rowheight-5 "rowheight adapts to cell padding" -body {
    # Test that things from Cell style is picked up.
    ttk::style configure Cell -padding "2 5 2 5"
    update
    set baseline [lindex [.tv bbox nn a] 3]
    ttk::style configure Cell -padding "2 8 2 9"
    update
    set after [lindex [.tv bbox nn a] 3]
    set diff [expr {$after - $baseline}]
} -cleanup {
    ttk::style configure Cell -padding {}
} -result [expr {8-5 + 9-5}]

### NEED: tests for focus item, selection

### Misc. tests:

destroy .tv
test treeview-1541739 "Root node properly initialized (#1541739)" -setup {
test treeview-10.1 "Root node properly initialized (#1541739)" -setup {
    ttk::treeview .tv
    .tv insert {} end -id a
    .tv see a
} -cleanup {
    destroy .tv
}

test treeview-3006842 "Null bindings" -setup {
    ttk::treeview .tv -show tree
} -body {
    .tv tag bind empty <Button-1> {}
    .tv tag bind empty <ButtonPress-1> {}
    .tv insert {} end -text "Click me" -tags empty
    event generate .tv <Button-1> -x 10 -y 10
    event generate .tv <ButtonPress-1> -x 10 -y 10
    .tv tag bind empty
} -result {} -cleanup {
    destroy .tv
}

test treeview-3085489-1 "tag add, no -tags" -setup {
    ttk::treeview .tv
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
632
633
634
635
636
637
638





































































































































































































































639







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

    set item [.tv insert {} end]
    .tv tag remove foo $item
    .tv item $item -tags
} -cleanup {
    destroy .tv
} -result [list]

test treeview-368fa4561e "indicators cannot be clicked on leafs" -setup {
    pack [ttk::treeview .tv]
    .tv insert {} end -id foo -text "<-- (1) Click the blank space to my left"
    update
} -body {
    foreach {x y w h} [.tv bbox foo #0] {}
    set res [.tv item foo -open]
    # using $h even for x computation is intentional here in order to simulate
    # a mouse click on the (invisible since we're on a leaf) indicator
    event generate .tv <Button-1> \
            -x [expr {$x + $h / 2}] \
            -y [expr {$y + $h / 2}]
    lappend res [.tv item foo -open]
    .tv insert foo end -text "sub"
    lappend res [.tv item foo -open]
} -cleanup {
    destroy .tv
} -result {0 0 0}

test treeview-ce470f20fd-1 "dragging further than the right edge of the treeview is allowed" -setup {
    pack [ttk::treeview .tv]
    .tv heading #0 -text "Drag my right edge -->"
    update
} -body {
    set res [.tv column #0 -width]
    .tv drag #0 400
    lappend res [expr {[.tv column #0 -width] > $res}]
} -cleanup {
    destroy .tv
} -result {200 1}

proc nostretch {tv} {
    foreach col [$tv cget -columns] {
        $tv column $col -stretch 0
    }
    $tv column #0 -stretch 0
    update idletasks ; # redisplay $tv
}

test treeview-ce470f20fd-2 "changing -stretch resizes columns" -setup {
    pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
    foreach col [.tv cget -columns] {
        .tv heading $col -text $col
    }
    nostretch .tv
    .tv column colA -width 50 ; .tv column colB -width 50 ; # slack created
    update idletasks ; # redisplay treeview
} -body {
    # when no column is stretchable and one of them becomes stretchable
    # the stretchable column takes the slack and the widget is redisplayed
    # automatically at idle time
    set res [.tv column colA -width]
    .tv column colA -stretch 1
    update idletasks ; # no slack anymore, widget redisplayed
    lappend res [expr {[.tv column colA -width] > $res}]
} -cleanup {
    destroy .tv
} -result {50 1}

test treeview-ce470f20fd-3 "changing -stretch resizes columns" -setup {
    pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
    foreach col [.tv cget -columns] {
        .tv heading $col -text $col
    }
    .tv configure -displaycolumns {colB colA colC}
    nostretch .tv
    .tv column colA -width 50 ; .tv column colB -width 50 ; # slack created
    update idletasks ; # redisplay treeview
} -body {
    # only some columns are displayed (and in a different order than declared
    # in -columns), a displayed column becomes stretchable  --> the stretchable
    # column expands
    set res [.tv column colA -width]
    .tv column colA -stretch 1
    update idletasks ; # no slack anymore, widget redisplayed
    lappend res [expr {[.tv column colA -width] > $res}]
} -cleanup {
    destroy .tv
} -result {50 1}

test treeview-ce470f20fd-4 "changing -stretch resizes columns" -setup {
    pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
    foreach col [.tv cget -columns] {
        .tv heading $col -text $col
    }
    .tv configure -displaycolumns {colB colA colC}
    nostretch .tv
    .tv column colA -width 50 ; .tv column bar -width 60 ; # slack created
    update idletasks ; # redisplay treeview
} -body {
    # only some columns are displayed (and in a different order than declared
    # in -columns), a non-displayed column becomes stretchable  --> nothing
    # happens
    set origTreeWidth [winfo width .tv]
    set res [list [.tv column bar -width] [.tv column colA -width]]
    .tv column bar -stretch 1
    update idletasks ; # no change, widget redisplayed
    lappend res [.tv column bar -width] [.tv column colA -width]
    # this column becomes visible  --> widget resizes
    .tv configure -displaycolumns {bar colC colA colB}
    update idletasks ; # no slack anymore because the widget resizes (shrinks)
    lappend res [.tv column bar -width] [.tv column colA -width] \
                [expr {[winfo width .tv] < $origTreeWidth}]
} -cleanup {
    destroy .tv
} -result {60 50 60 50 60 50 1}

test treeview-bc602049ab "treeview with custom background does not change size when switching themes" -setup {
    image create photo tvbg -data {
	iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAnXAAAJ1wG
	xbhe3AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAACJJREFUOI
	1jPLF9+38GKgImaho2auCogaMGjho4auBQMhAAyR0DXUEyypsAAAAASUVORK5CYII=
    }
    ttk::style theme create foo-bc602049ab -parent clam -settings {
      ttk::style element create Treeview.field image tvbg -width 0 -height 0
    }
    ttk::style theme use foo-bc602049ab
    pack [ttk::treeview .tv]
    update idletasks
} -body {
    set g1 [winfo geometry .tv]
    ttk::style theme use foo-bc602049ab
    update idletasks
    set g2 [winfo geometry .tv]
    expr {$g1 eq $g2 ? 1 : "$g1 --> $g2"}
} -cleanup {
    destroy .tv
    image delete tvbg
} -result {1}

test treeview-6ee162c3d9 "style configure Treeview -rowheight 0" -setup {
    tvSetupWithItems
} -body {
    ttk::style configure Treeview -rowheight 0  ; # shall not crash
    update
} -result {}

test treeview-column0-leak "Test for leak in tree column" -setup {
    destroy .ttt
    set heading [string range _Hej_ 1 3]
} -body {
    for {set t 0} {$t < 3} {incr t} {
        ttk::treeview .tapa -columns "hej hopp"
        .tapa heading #0 -text $heading
        destroy .tapa
    }
    tcl::unsupported::representation $heading
} -match glob -result {*refcount of 3,*}

test treeview-21.1 "style command" -body {
    ttk::treeview .w
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {{} Treeview Treeview}
test treeview-21.2 "style command" -body {
    ttk::style configure customStyle.Treeview
    ttk::treeview .w -style customStyle.Treeview
    list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
    destroy .w
} -result {customStyle.Treeview customStyle.Treeview Treeview}

test treeview-22.1 "tag bindings" -setup {
    tvSetupWithItems
    .tv tag configure t1 -background red
    .tv tag configure t2 -background blue
    .tv item nn -open 1
    # Tags on item and cell to spot the difference
    .tv tag add t1 "nn.n1"
    .tv tag cell add t2 "nn.n1 a"
    .tv tag cell add t2 "nn.n2 c"
    update
    proc cellEvent {item col} {
        # Find midpoint of cell
        lassign [.tv bbox $item $col] aX aY aW aH
        set aX [expr {$aX + $aW / 2}]
        set aY [expr {$aY + $aH / 2}]
        event generate .tv <Button-1> -x $aX -y $aY
    }
} -body {
    .tv tag bind t1 <Button-1> {lappend ::tagtest t1}
    .tv tag bind t2 <Button-1> {lappend ::tagtest t2}
    # Cell with both binds
    set ::tagtest a
    cellEvent nn.n1 a
    # Cell with just item tag
    lappend ::tagtest b
    cellEvent nn.n1 b
    # Cell with just cell tag
    lappend ::tagtest c
    cellEvent nn.n2 c
    # Same tag on both cell and item should fire once
    .tv tag cell add t1 "nn.n1 b"
    lappend ::tagtest b
    cellEvent nn.n1 b
    # Break in first bind
    .tv tag bind t1 <Button-1> {lappend ::tagtest t1;break}
    lappend ::tagtest a
    cellEvent nn.n1 a
    set ::tagtest
} -cleanup {
    rename cellEvent {}
    destroy .tv
} -result {a t1 t2 b t1 c t2 b t1 a t1}
test treeview-12.2 "tag bindings deletion on tag delete" -setup {
    tvSetupWithItems
    .tv tag bind nn.n1 <Button-1> {puts Triggered}
} -body {
    .tv tag delete nn.n1
    .tv tag bind nn.n1
} -cleanup {
    destroy .tv
} -result {}

test treeview-23.1 "cell padding" -setup {
    tvSetupWithItems
} -body {
    .tv tag cell add mytag "nn b"
    set redcross [image create photo -format gif -data {R0lGODlhBwAHAIABAP8AAP///
            yH5BAEKAAEALAAAAAAHAAcAAAIMBIKmsWrIXnLxuDMLADs=}]
    .tv tag configure mytag -image $redcross
    .tv tag configure mytag -imageanchor nw
    .tv tag configure mytag -padding {2 4 6 8}
    .tv tag configure mytag -padding
} -cleanup {
    destroy .tv
} -result {2 4 6 8}

tcltest::cleanupTests

Changes to tests/ttk/ttk.test.

1
2
3


4
5
6
7
8
9
10
11
1


2
3

4
5
6
7
8
9
10

-
-
+
+
-








package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

proc skip args {}
proc ok {} { return }

variable widgetClasses {
    button checkbutton radiobutton menubutton label entry
25
26
27
28
29
30
31
32

33
34
35

36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
24
25
26
27
28
29
30

31
32
33

34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50







-
+


-
+








-
+







# Do these early, so any memory corruption has a longer time to cause a crash.
#
proc selfdestruct {w args} {
    destroy $w
}
test ttk-6.1 "Self-destructing checkbutton" -body {
    pack [ttk::checkbutton .sd -text "Self-destruction" -variable ::sd]
    trace add variable sd write [list selfdestruct .sd]
    trace variable sd w [list selfdestruct .sd]
    update
    .sd invoke
} -returnCodes error
} -returnCodes 1
test ttk-6.2 "Checkbutton self-destructed" -body {
    winfo exists .sd
} -result 0

# test ttk-6.3 not applicable [see #2175411]

test ttk-6.4 "Destroy widget in configure" -setup {
    set OUCH ouch
    trace add variable OUCH read { kill.b }
    trace variable OUCH r { kill.b }
    proc kill.b {args} { destroy .b }
} -cleanup {
    unset OUCH
} -body {
    pack [ttk::checkbutton .b]
    set rc [catch { .b configure -variable OUCH } msg]
    list $rc $msg [winfo exists .b] [info commands .b]
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96







-
+







    .b invoke
    destroy .b
    set ::A
} -result {it worked}

test ttk-6.9 "Bad font spec in styles" -setup {
    ttk::style theme create badfont -settings {
	ttk::style configure . -font {Helvetica 12 Bogus}
    	ttk::style configure . -font {Helvetica 12 Bogus}
    }
    ttk::style theme use badfont
} -cleanup {
    ttk::style theme use default
} -body {
    pack [ttk::label .l -text Hi! -font {}]
    event generate .l <Expose>
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128







-
+







-
+







} -body {
    catch {ttk::label .l} errmsg
    list $errmsg [info commands .l] [winfo exists .l]
} -result [list {bad cursor spec "badCursor"} {} 0]

test ttk-construction-failure-2 "Destroy widget in constructor" -setup {
    set OUCH ouch
    trace add variable OUCH read { kill.b }
    trace variable OUCH r { kill.b }
    proc kill.b {args} { destroy .b }
} -cleanup {
    unset OUCH
} -body {
    list \
	[catch { ttk::checkbutton .b -variable OUCH } msg] \
	$msg \
	[winfo exists .b] \
    	[winfo exists .b] \
	[info commands .b] \
	;
} -result [list 1 "widget has been destroyed" 0 {}]

test ttk-selfdestruct-ok-1 "Intentional self-destruction" -body {
    # see #2298720
    toplevel .t
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161

162
163
164

165
166
167
168
169
170
171
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159

160
161
162

163
164
165
166
167
168
169
170







-
+











-
+


-
+








test ttk-1.2 "Check style" -body {
    .t cget -style
} -result {}

test ttk-1.3 "Set bad style" -body {
    .t configure -style "nosuchstyle"
} -returnCodes error -result {Layout nosuchstyle not found}
} -returnCodes 1 -result {Layout nosuchstyle not found}

test ttk-1.4 "Original style preserved" -body {
    .t cget -style
} -result ""

proc checkstate {w} {
    foreach statespec {
	{!active !disabled}
	{!active disabled}
	{active !disabled}
	{active disabled}
	active
    	active
	disabled
    } {
	lappend result [$w instate $statespec]
    	lappend result [$w instate $statespec]
    }
    set result
}

# NB: this will fail if the top-level window pops up underneath the cursor
test ttk-2.0 "Check state" -body {
    checkstate .t
203
204
205
206
207
208
209
210
211
212
213
214



215
216
217
218
219
220
221
202
203
204
205
206
207
208

209



210
211
212
213
214
215
216
217
218
219







-

-
-
-
+
+
+







    set x
} -result 1

test ttk-2.8 "bug 3223850: button state disabled during click" -setup {
    destroy .b
    set ttk28 {}
    pack [ttk::button .b -command {set ::ttk28 failed}]
    update
} -body {
    bind .b <Button-1> {after 0 {.b configure -state disabled}}
    after 1 {event generate .b <Button-1>}
    after 50 {event generate .b <ButtonRelease-1>}
    bind .b <ButtonPress-1> {after 0 {.b configure -state disabled}}
    after 1 {event generate .b <ButtonPress-1>}
    after 20 {event generate .b <ButtonRelease-1>}
    set aid [after 100 {set ::ttk28 [.b instate {disabled !pressed}]}]
    vwait ::ttk28
    after cancel $aid
    set ttk28
} -cleanup {
    destroy .b
    unset -nocomplain ttk28 aid
231
232
233
234
235
236
237
238

239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
229
230
231
232
233
234
235

236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279







-
+



-
+












-
+


















-
+







	catch {destroy .w}
    }
}

# misc. error detection
test ttk-3.0 "Bad option" -body {
    ttk::button .bad -badoption foo
} -returnCodes error -result {unknown option "-badoption"} -match glob
} -returnCodes 1 -result {unknown option "-badoption"} -match glob

test ttk-3.1 "Make sure widget command not created" -body {
    .bad state disabled
} -returnCodes error -result {invalid command name ".bad"} -match glob
} -returnCodes 1 -result {invalid command name ".bad"} -match glob

test ttk-3.2 "Propagate errors from variable traces" -body {
    set A 0
    trace add variable A write {error "failure" ;# }
    ttk::checkbutton .cb -variable A
    .cb invoke
} -cleanup {
    unset ::A ; destroy .cb
} -returnCodes error -result {can't set "A": failure}

test ttk-3.3 "Constructor failure with cursor" -body {
    ttk::button .b -cursor bottom_right_corner -style BadStyle
} -returnCodes error -result "Layout BadStyle not found"
} -returnCodes 1 -result "Layout BadStyle not found"

test ttk-3.4 "SF#2009213" -body {
    ttk::style configure TScale -sliderrelief {}
    pack [ttk::scale .s]
    update
} -cleanup {
    ttk::style configure TScale -sliderrelief raised
    destroy .s
}

# Test resource allocation
# (@@@ "-font" is a compatibility option now, so tests 4.1-4.3
# don't really test anything useful at the moment.)
#

test ttk-4.0 "Setup" -body {
    catch { destroy .t }
    pack [ttk::label .t -text "Button 1"]
    testConstraint fontOption [expr {![catch { set prevFont [.t cget -font] }]}]
    testConstraint fontOption [expr ![catch { set prevFont [.t cget -font] }]]
    ok
}

test ttk-4.1 "Change font" -constraints fontOption -body {
    .t configure -font "Helvetica 18 bold"
}
test ttk-4.2 "Check font" -constraints fontOption -body {
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305







-
+







	# @@@ but that's not really feasible in the current framework.
    }
    pack [ttk::button .tb1 -text "Ouch"]
    ttk::style theme use alt
    update;
    # As long as we haven't crashed, everything's OK
    ttk::style theme settings alt {
	ttk::style configure TButton -font TkDefaultFont
    	ttk::style configure TButton -font TkDefaultFont
    }
    ttk::style theme use default
    destroy .tb1
}

#
# -compound tests:
384
385
386
387
388
389
390
391

392
393
394
395
396

397
398
399
400
401
402
403
382
383
384
385
386
387
388

389
390
391
392
393

394
395
396
397
398
399
400
401







-
+




-
+







    icon blank
} -cleanup { destroy .b }

#------------------------------------------------------------------------

test ttk-9.1 "Traces on nonexistant namespaces" -body {
    ttk::checkbutton .tcb -variable foo::bar
} -returnCodes error -result "*parent namespace doesn't exist*" -match glob
} -returnCodes 1 -result "*parent namespace doesn't exist*" -match glob

test ttk-9.2 "Traces on nonexistant namespaces II" -body {
    ttk::checkbutton .tcb -variable X
    .tcb configure -variable foo::bar
} -returnCodes error -result "*parent namespace doesn't exist*" -match glob
} -returnCodes 1 -result "*parent namespace doesn't exist*" -match glob

test ttk-9.3 "Restore saved options on configure error" -body {
    .tcb cget -variable
} -result X

test ttk-9.4 "Textvariable tests" -body {
    set tcbLabel "Testing..."
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
434
435
436
437
438
439
440









441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466







-
-
-
-
-
-
-
-
-


















-
+







test ttk-9.8 "-textvariable overrides -text" -body {
    ttk::label .tl -textvariable TV
    set TV Foo
    .tl configure -text Bar
    .tl cget -text
} -cleanup { destroy .tl } -result "Foo"

test ttk-9.9 "default for -justify" -body {
    ttk::label .tl
    .tl cget -justify
} -cleanup { destroy .tl } -result "left"
test ttk-9.10 "default for -anchor" -body {
    ttk::label .tl
    .tl cget -anchor
} -cleanup { destroy .tl } -result "w"

#
# Frame widget tests:
#

test ttk-10.1 "ttk::frame -class resource" -body {
    ttk::frame .f -class Foo
} -result .f

test ttk-10.2 "Check widget class" -body {
    winfo class .f
} -result Foo

test ttk-10.3 "Check class resource" -body {
    .f cget -class
} -result Foo

test ttk-10.4 "Try to modify class resource" -body {
    .f configure -class Bar
} -returnCodes error -match glob -result "*read-only option*"
} -returnCodes 1 -match glob -result "*read-only option*"

test ttk-10.5 "Check class resource again" -body {
    .f cget -class
} -result Foo

test ttk-11.1 "-state test, setup" -body {
    ttk::button .b
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
502
503
504
505
506
507
508













509
510
511
512
513
514
515







-
-
-
-
-
-
-
-
-
-
-
-
-







} -result {}

test ttk-12.2 "-cursor option" -body {
    .b configure -cursor arrow
    .b cget -cursor
} -result arrow

test ttk-12.2.1 "-cursor option, widget doesn't overwrite it" -setup {
    ttk::treeview .tr
    pack .tr
    update
} -body {
    .tr configure -cursor X_cursor
    event generate .tr <Motion>
    update
    .tr cget -cursor
} -cleanup {
    destroy .tr
} -result {X_cursor}

test ttk-12.3 "-borderwidth frame option" -body {
    destroy .t
    toplevel .t
    raise .t
    pack [set t [ttk::frame .t.f]] -expand true -fill x ;
    pack [ttk::label $t.l -text "ASDF QWERTY"] -expand true -fill both
    foreach theme {default alt} {
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567

568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583
584
585

586
587
588
589
590

591
592
593
594
595

596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
529
530
531
532
533
534
535

536
537
538
539
540
541
542

543
544
545
546

547
548
549
550
551
552
553
554
555
556
557
558
559
560

561
562
563
564
565

566
567
568
569
570

571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586







-
+






-
+



-
+













-
+




-
+




-
+







-
+







    .t.f configure -borderwidth 1
    ttk::style theme use alt
    update
}

test ttk-13.1 "Custom styles -- bad -style option" -body {
    ttk::button .tb1 -style badstyle
} -returnCodes error -result "*badstyle not found*" -match glob
} -returnCodes 1 -result "*badstyle not found*" -match glob

test ttk-13.4 "Custom styles -- bad -style option" -body {
    ttk::button .tb1
    .tb1 configure -style badstyle
} -cleanup {
    destroy .tb1
} -returnCodes error -result "*badstyle not found*" -match glob
} -returnCodes 1 -result "*badstyle not found*" -match glob

test ttk-13.5 "Custom layouts -- missing element definition" -body {
    ttk::style layout badstyle {
	NoSuchElement
    	NoSuchElement
    }
    ttk::button .tb1 -style badstyle
} -cleanup {
    destroy .tb1
} -result .tb1
# @@@ Should: signal an error, possibly a background error.

#
# See #793909
#

test ttk-14.1 "-variable in nonexistant namespace" -body {
    ttk::checkbutton .tw -variable ::nsn::foo
} -returnCodes error -result {can't trace *: parent namespace doesn't exist} \
} -returnCodes 1 -result {can't trace *: parent namespace doesn't exist} \
  -match glob -cleanup { destroy .tw }

test ttk-14.2 "-textvariable in nonexistant namespace" -body {
    ttk::label .tw -textvariable ::nsn::foo
} -returnCodes error -result {can't trace *: parent namespace doesn't exist} \
} -returnCodes 1 -result {can't trace *: parent namespace doesn't exist} \
  -match glob -cleanup { destroy .tw }

test ttk-14.3 "-textvariable in nonexistant namespace" -body {
    ttk::entry .tw -textvariable ::nsn::foo
} -returnCodes error -result {can't trace *: parent namespace doesn't exist} \
} -returnCodes 1 -result {can't trace *: parent namespace doesn't exist} \
  -match glob -cleanup { destroy .tw }

test ttk-15.1 {Bug 3062331} -setup {
    destroy .b
} -body {
    set Y {}
    ttk::button .b -textvariable Y
    trace add variable Y unset "destroy .b; #"
    trace variable Y u "destroy .b; #"
    unset Y
} -cleanup {
    destroy .b
} -result {}

test ttk-15.2 {Bug 3341056} -setup {
    proc foo {} {
634
635
636
637
638
639
640
641

642
643
644
645
646

647
648
649
650
651

652
653
654
655
656

657
658
659
660
661

662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678

679
680
681
682
610
611
612
613
614
615
616

617
618
619
620
621

622
623
624
625
626

627
628
629
630
631

632
633
634
635
636

637
638
639
640
641
642












643
644
645
646
647







-
+




-
+




-
+




-
+




-
+





-
-
-
-
-
-
-
-
-
-
-
-
+




    set usage $args
    append usage " ?$varpart ...?"
    return "wrong # args: should be \"$usage\""
}

test ttk-ensemble-0 "style element create: insufficient args" -body {
     ttk::style
} -returnCodes error -result \
} -returnCodes 1 -result \
    [wrong#varargs arg ttk::style option]

test ttk-ensemble-1 "style element create: insufficient args" -body {
     ttk::style element
} -returnCodes error -result \
} -returnCodes 1 -result \
    [wrong#varargs arg ttk::style element option]

test ttk-ensemble-2 "style element create: insufficient args" -body {
     ttk::style element create
} -returnCodes error -result \
} -returnCodes 1 -result \
    [wrong#varargs {-option value} ttk::style element create name type]

test ttk-ensemble-3 "style element create: insufficient args" -body {
     ttk::style element create plain.background
} -returnCodes error -result \
} -returnCodes 1 -result \
    [wrong#varargs {-option value} ttk::style element create name type]

test ttk-ensemble-4 "style element create: insufficient args" -body {
     ttk::style element create plain.background from
} -returnCodes error -result [wrong#args theme ?element?]
} -returnCodes 1 -result [wrong#args theme ?element?]

test ttk-ensemble-5 "style element create: valid" -body {
     ttk::style element create plain.background from default
} -returnCodes 0 -result ""

test ttk-16.1 {ttk::style theme styles - no such theme} -body {
    ttk::style theme styles noSuchTheme
} -returnCodes 1 -result {theme "noSuchTheme" doesn't exist}
test ttk-16.2 {ttk::style theme styles - theme exists} -body {
    # simply check this produces a list with some style names,
    # without checking exact content (not needed, and may vary
    # depending on platform, versions, improvements...)
    expr {[llength [ttk::style theme styles alt]] > 0}
} -result 1


destroy {*}[winfo children .]
eval destroy [winfo children .]

tcltest::cleanupTests

#*EOF*

Changes to tests/ttk/validate.test.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







##
## Entry widget validation tests
## Derived from core test suite entry-19.1 through entry-19.20
##

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest 2.1
namespace import -force tcltest::*

loadTestedCommands

testConstraint ttkEntry 1
testConstraint coreEntry [expr {![testConstraint ttkEntry]}]

74
75
76
77
78
79
80
81
82
83

84

85
86
87
88
89
90
91
92

93

94
95
96
97
98
99
100
101
102

103

104
105
106
107
108
109
110
111

112

113
114
115
116
117
118
119
120
121

122

123
124
125
126
127
128
129

130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
74
75
76
77
78
79
80


81
82

83

84
85
86
87


88
89

90

91
92
93
94
95


96
97

98

99
100
101
102


103
104

105

106
107
108
109
110


111
112

113

114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134
135







-
-

+
-
+
-




-
-

+
-
+
-





-
-

+
-
+
-




-
-

+
-
+
-





-
-

+
-
+
-






+






-

+







    set ::vVals {}
    .e configure -validate focus
    .e insert end d
    set ::vVals
} -result {}

test validate-1.8 {entry widget validation - vmode focus} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    # update necessary to process FocusIn event
    vwait ::vVals
    update
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focus focusin}

test validate-1.9 {entry widget validation - vmode focus} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .
    # update necessary to process FocusOut event
    vwait ::vVals
    update
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focus focusout}

.e configure -validate all
test validate-1.10 {entry widget validation - vmode all} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    # update necessary to process FocusIn event
    vwait ::vVals
    update
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} all focusin}

test validate-1.11 {entry widget validation} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .
    # update necessary to process FocusOut event
    vwait ::vVals
    update
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} all focusout}
.e configure -validate focusin

test validate-1.12 {entry widget validation} -body {
    set ::vVals {}
    set timer [after 300 lappend ::vVals timeout]
    focus -force .e
    # update necessary to process FocusIn event
    vwait ::vVals
    update
    after cancel $timer
    set ::vVals
} -result {.e -1 -1 abcd abcd {} focusin focusin}

test validate-1.13 {entry widget validation} -body {
    set ::vVals {}
    focus -force .
    # update necessary to process FocusOut event
    update
    set ::vVals
} -result {}
.e configure -validate focuso

test validate-1.14 {entry widget validation} -body {
    set ::vVals {}
    focus -force .e
    # update necessary to process FocusIn event
    update
    set ::vVals
} -result {}

test validate-1.15 {entry widget validation} -body {
    focus -force .
    # update necessary to process FocusOut event
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239







-
+








### invalid state behavior
#

test validate-3.0 "Setup" -body {
    set ::E "123"
    ttk::entry .e \
	-validatecommand {string is integer -strict %P} \
    	-validatecommand {string is integer -strict %P} \
	-validate all \
	-textvariable ::E \
	;
    return [list [.e get] [.e state]]
} -result [list 123 {}]

test validate-3.1 "insert - valid" -body {

Changes to tests/ttk/vsapi.test.

1
2
3
4
5


6
7
8
9
10

11
12
13
14
15
16
17
1
2
3


4
5

6
7
8

9
10
11
12
13
14
15
16



-
-
+
+
-



-
+







# -*- tcl -*-
#

package require tk
package require tcltest 2.2
package require Tk 8.5
package require tcltest ; namespace import -force tcltest::*
namespace import -force tcltest::*
loadTestedCommands

testConstraint xpnative \
    [expr {"xpnative" in [ttk::style theme names]}]
    [expr {[lsearch -exact [ttk::style theme names] xpnative] != -1}]

test vsapi-1.1 "WINDOW WP_SMALLCLOSEBUTTON" -constraints {xpnative} -body {
    ttk::style element create smallclose vsapi \
        WINDOW 19 {disabled 4 pressed 3 active 2 {} 1}
    ttk::style layout CloseButton {CloseButton.smallclose -sticky news}
    ttk::button .b -style CloseButton
    pack .b -expand true -fill both

Changes to tests/unixButton.test.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







# This file is a Tcl script to test the Unix specific behavior of
# labels, buttons, checkbuttons, and radiobuttons in Tk (i.e., all the
# widgets defined in tkUnixButton.c).  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
imageInit
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
31
32
33
34
35
36
37









38
39
40
41
42
43
44
45







-
-
-
-
-
-
-
-
-
+







option add *Radiobutton.font {Helvetica -12 bold}


proc bogusTrace args {
    error "trace aborted"
}

if {[tk windowingsystem] eq "aqua"} {
    set smallIndicator 20
    set bigIndicator 20
    set defaultBorder 10
} else {
    set smallIndicator 27
    set bigIndicator 40
    set defaultBorder 20
}

test unixbutton-1.1 {TkpComputeButtonGeometry procedure} -constraints {
    unix testImageType
} -setup {
    deleteWindows
    imageCleanup
} -body {
    image create test image1
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
53
54
55
56
57
58
59

60



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78



79
80
81
82
83
84
85







-
+
-
-
-

















-
+
-
-
-







    list [winfo reqwidth .b1] [winfo reqheight .b1] \
        [winfo reqwidth .b2] [winfo reqheight .b2] \
        [winfo reqwidth .b3] [winfo reqheight .b3] \
        [winfo reqwidth .b4] [winfo reqheight .b4]
} -cleanup {
    deleteWindows
    image delete image1
} -result [list 68 48 \
} -result {68 48 74 54 112 52 112 52}
                74 54 \
	        [expr {72 + $bigIndicator}] 52 \
	        [expr {72 + $bigIndicator}] 52]
test unixbutton-1.2 {TkpComputeButtonGeometry procedure} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    label .b1 -bitmap question -bd 3 -padx 0 -pady 2
    button .b2 -bitmap question -bd 3 -padx 0 -pady 2
    checkbutton .b3 -bitmap question -bd 3 -padx 1 -pady 1
    radiobutton .b4 -bitmap question -bd 3 -padx 2 -pady 0
    pack .b1 .b2 .b3 .b4
    update
    list [winfo reqwidth .b1] [winfo reqheight .b1] \
        [winfo reqwidth .b2] [winfo reqheight .b2] \
        [winfo reqwidth .b3] [winfo reqheight .b3] \
        [winfo reqwidth .b4] [winfo reqheight .b4]
} -cleanup {
    deleteWindows
} -result [list 23 33 \
} -result {23 33 29 39 54 37 54 37}
	        29 39 \
	        [expr {27 + $smallIndicator}] 37 \
	        [expr {27 + $smallIndicator}] 37]
test unixbutton-1.3 {TkpComputeButtonGeometry procedure} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    label .b1 -bitmap question -bd 3 -highlightthickness 4
    button .b2 -bitmap question -bd 3 -highlightthickness 0
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206







-
+









-
+







} -setup {
    deleteWindows
} -body {
    button .b2 -bitmap question -default active
    list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
    deleteWindows
} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
} -result {37 47}
test unixbutton-1.10 {TkpComputeButtonGeometry procedure} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    button .b2 -bitmap question -default normal
    list [winfo reqwidth .b2] [winfo reqheight .b2]
} -cleanup {
    deleteWindows
} -result [list [expr {17 + $defaultBorder}] [expr {27 + $defaultBorder}]]
} -result {37 47}
test unixbutton-1.11 {TkpComputeButtonGeometry procedure} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    button .b2 -bitmap question -default disabled
    list [winfo reqwidth .b2] [winfo reqheight .b2]

Changes to tests/unixEmbed.test.

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
1
2
3
4


5
6
7
8
9
10
11
12
13


































14
15
16
17
18
19
20




-
-
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







# This file is a Tcl script to test out the procedures in the file
# tkUnixEmbed.c.  It is organized in the standard fashion for Tcl
# tests.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

namespace eval ::_test_tmp {}

# ------------------------------------------------------------------------------
#  Proc ::_test_tmp::testInterp
# ------------------------------------------------------------------------------
# Command that creates an child interpreter and tries to load Tk.
# This code is borrowed from safePrimarySelection.test
# This is necessary for loading Tktest if the tests are done in the build
# directory without installing Tk.  In that case the usual auto_path loading
# mechanism cannot work because the tk binary is not where pkgIndex.tcl says
# it is.
# ------------------------------------------------------------------------------

namespace eval ::_test_tmp {
    variable TkLoadCmd
}

foreach pkg [info loaded] {
    if {[lindex $pkg 1] eq "Tk"} {
	set ::_test_tmp::TkLoadCmd [list load {*}$pkg]
	break
    }
}

proc ::_test_tmp::testInterp {name} {
    variable TkLoadCmd
    interp create $name
    $name eval [list set argv [list -name $name]]
    catch {{*}$TkLoadCmd $name}
}

setupbg
dobg {wm withdraw .}

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
84
85
86
87
88
89
90
91
92
93
94


95
96

97
98
99
100
101


102
103

104
105
106
107
108


109
110

111
112
113
114
115
116
117
118
119
120
121
122




123
124

125
126
127
128
129
130
131
132
133


134
135
136


137
138

139
140
141
142
143
144
145

146
147
148
149
150

151
152
153


154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187




188
189
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216


217
218

219
220
221
222
223
224
225
226
227

228
229
230
231


232
233
234
235

236
237

238
239
240
241
242
243
244
245



246
247
248
249
250

251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

281
282

283
284
285
286
287
288
289
290
291
292





293
294
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

321
322

323
324
325
326
327
328
329
330
331
332

333
334

335
336


337
338
339
340

341
342

343
344
345


346
347
348
349
350
351
352
353
354
355
356
357
358



359
360
361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388

389
390
391
392
393
394
395
396
397

398
399
400

401
402

403
404
405
406
407
408
409
410
411




412
413
414
415

416
417
418

419
420
421


422
423

424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455




456
457
458
459

460
461
462

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488

489
490

491
492
493
494
495
496
497


498
499
500
501

502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531

532
533

534
535
536
537
538
539
540
541
542




543
544
545
546
547
548



549
550
551

552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579

580
581

582
583
584
585
586
587
588
589
590


591
592
593
594

595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627
628

629
630

631
632
633
634
635
636
637


638
639
640
641

642
643
644
645

646
647
648

649
650
651


652
653

654
655
656
657
658
659
660
661
662
663
664






665
666
667


668

669
670
671
672
673
674






675
676

677
678
679
680
681
682
683


684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732



733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768

769
770

771
772
773
774
775
776
777

778
779
780
781
782

783
784
785
786
787
788

789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

817
818

819
820
821
822
823
824
825
826
827
828
829





830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
867
868
869
870
871
872
873

874
875

876
877
878
879
880
881
882
883
884
885
886
887
888










889
890
891

892
893
894


895
896

897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934











935
936
937

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

961
962
963

964
965
966
967
968
969

970
971

972
973
974
975
976
977
978
979


980
981
982

983
984
985
986
987
988
989





990
991
992
993
994
995


996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033

1034
1035

1036
1037
1038
1039
1040
1041
1042


1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054





1055
1056
1057
1058
1059
1060


1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
1108


1109
1110
1111
1112
1113
1114
1115
1116
1117
1118






1119
1120
1121

1122
1123
1124


1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171
1172




1173
1174
1175

1176
1177
1178

1179
1180

1181
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193


1194
1195
1196
1197

1198
1199
1200

1201
1202

1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214






1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247

1248
1249
1250
1251
1252
1253
1254
1255
1256
1257

1258
1259
1260

1261
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332

50
51
52
53
54
55
56




57
58
59

60
61
62
63


64
65
66

67
68
69
70


71
72
73

74
75
76
77
78
79
80
81
82




83
84
85
86
87

88
89
90
91
92
93
94
95


96
97
98


99
100
101

102
103
104
105
106
107
108

109
110
111
112
113

114
115


116
117
118

119





















120
121
122
123
124
125
126




127
128
129
130
131
132

133
134

























135
136
137

138
139
140
141
142
143
144
145
146

147
148
149


150
151
152
153
154

155
156

157
158
159
160
161
162



163
164
165
166
167
168
169

170
171
172

173
174
























175

176
177

178
179
180
181
182
183





184
185
186
187
188
189
190

191
192






















193

194
195

196
197
198
199
200
201
202
203
204
205

206
207

208
209

210
211
212

213
214
215
216

217
218


219
220
221
222
223
224
225
226
227
228
229
230



231
232
233
234
235
236

237
238





















239

240
241

242

243
244
245
246
247
248
249

250
251
252

253
254

255
256
257
258
259
260




261
262
263
264
265
266
267

268
269
270

271
272


273
274
275

276























277
278
279
280
281




282
283
284
285
286
287
288

289
290
291

292
293























294

295
296

297
298
299
300
301
302


303
304
305
306
307

308
309
310
311
312

313
314






















315

316
317

318
319
320
321
322
323




324
325
326
327
328
329
330



331
332
333
334
335

336
337

























338

339
340

341
342
343
344
345
346
347
348


349
350
351
352
353

354
355
356
357
358

359
360



















361






362
363

364
365

366
367
368
369
370
371


372
373
374
375
376

377
378
379
380

381
382
383

384
385


386
387
388

389



390
391
392





393
394
395
396
397
398



399
400

401
402





403
404
405
406
407
408
409

410
411
412
413
414
415


416
417

















































418
419
420
421
422
423
424
425

426
427



























428

429
430

431
432
433
434

435
436

437
438
439
440
441

442
443
444
445
446
447

448
449

























450

451
452

453
454
455
456

457
458





459
460
461
462
463
464
465
466
467
468
469
470
471

472
473




















474










475

476

477
478

479
480
481
482
483
484








485
486
487
488
489
490
491
492
493
494
495
496

497
498


499
500
501

502



503
504






















505
506
507








508
509
510
511
512
513
514
515
516
517
518
519
520

521
522






















523



524

525

526
527

528
529

530
531
532
533
534
535
536


537
538
539
540

541
542
543





544
545
546
547
548
549
550
551
552


553
554
555



































556

557
558

559
560
561
562
563
564


565
566
567
568
569
570

571
572
573





574
575
576
577
578
579
580
581
582


583
584
585















586



















587

588



589
590
591
592
593
594
595


596
597
598
599
600
601






602
603
604
605
606
607
608
609

610
611


612
613
614























615





616
617
618
619

620

621
622
623

624
625
626
627
628




629
630
631
632
633
634

635
636
637
638
639
640

641
642

643
644
645
646
647
648
649
650
651
652


653
654
655
656
657

658
659
660

661
662

663
664
665
666

667
668






669
670
671
672
673
674
675
676

677























678
679
680
681

682
683

684
685
686
687
688
689
690
691
692
693

694
695
696

697
698

699
700
701
702

703
704
705
706
707
708

709
710
711




















































712
713
714
715
716
717







-
-
-
-
+
+

-
+



-
-
+
+

-
+



-
-
+
+

-
+








-
-
-
-
+
+
+
+

-
+







-
-
+
+

-
-
+
+

-
+






-
+




-
+

-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
-
+
+
+
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
+








-
+


-
-
+
+



-
+

-
+





-
-
-
+
+
+




-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+





-
-
-
-
-
+
+
+
+
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+









-
+

-
+

-
+
+

-


+

-
+

-
-
+
+










-
-
-
+
+
+



-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+
-







-
+


-
+

-
+





-
-
-
-
+
+
+
+



-
+


-
+

-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
-
-
-
+
+
+
+



-
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+





-
-
+
+



-
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+





-
-
-
-
+
+
+
+



-
-
-
+
+
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+







-
-
+
+



-
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-


-
+

-
+





-
-
+
+



-
+



-
+


-
+

-
-
+
+

-
+
-
-
-



-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
+

-
-
-
-
-
+
+
+
+
+
+

-
+





-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+



-


-
+




-
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+



-


-
-
-
-
-
+
+
+
+
+








-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-

-

-
+

-
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+

-
-
+
+

-
+
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-

-


-
+

-
+






-
-
+
+


-
+


-
-
-
-
-
+
+
+
+
+




-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+





-
-
+
+




-
+


-
-
-
-
-
+
+
+
+
+




-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
+






-
-
+
+




-
-
-
-
-
-
+
+
+
+
+
+


-
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-




-
+
-



-
+




-
-
-
-
+
+
+
+


-
+



+

-
+

-
+









-
-
+
+



-
+


-
+

-
+



-


-
-
-
-
-
-
+
+
+
+
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+

-
+









-
+


-
+

-
+



-






-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





+

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
	    && ([lindex $vals 2]/256 == $blue)
}

testConstraint pressbutton [llength [info commands pressbutton]]

test unixEmbed-1.1 {Tk_UseWindow procedure, bad window identifier} -constraints {
    unix
test unixEmbed-1.1 {TkpUseWindow procedure, bad window identifier} -constraints {
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -use xyz
} -returnCodes error -result {expected integer but got "xyz"}
test unixEmbed-1.2 {Tk_UseWindow procedure, bad window identifier} -constraints {
    unix
test unixEmbed-1.2 {TkpUseWindow procedure, bad window identifier} -constraints {
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -use 47
} -returnCodes error -result {couldn't create child of window "47"}
test unixEmbed-1.3 {Tk_UseWindow procedure, inheriting colormap} -constraints {
    unix nonPortable
test unixEmbed-1.3 {TkpUseWindow procedure, inheriting colormap} -constraints {
	unix nonPortable
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -colormap new
    wm geometry .t +0+0
    eatColors .t.t
    frame .t.f -container 1
    toplevel .x -use [winfo id .t.f]
    colorsFree .x
} -cleanup {
    deleteWindows
} -result 0
test unixEmbed-1.4 {Tk_UseWindow procedure, inheriting colormap} -constraints {
    unix nonPortable
	deleteWindows
} -result {0}
test unixEmbed-1.4 {TkpUseWindow procedure, inheriting colormap} -constraints {
	unix nonPortable
} -setup {
    deleteWindows
	deleteWindows
} -body {
    toplevel .t -container 1 -colormap new
    wm geometry .t +0+0
    eatColors .t2
    toplevel .x -use [winfo id .t]
    colorsFree .x
} -cleanup {
    deleteWindows
} -result 1
	deleteWindows
} -result {1}

test unixEmbed-1.5 {Tk_UseWindow procedure, creating Container records} -constraints {
    unix testembed notAqua
test unixEmbed-1.5 {TkpUseWindow procedure, creating Container records} -constraints {
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    dobg "set w [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	eval destroy [winfo child .]
	toplevel .t -use $w
	list [testembed] [expr [lindex [lindex [testembed all] 0] 0] - $w]
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{XXX {} {} .t}} 0}
test unixEmbed-1.5a {Tk_UseWindow procedure, creating Container records} -constraints {
    unix testembed
test unixEmbed-1.6 {TkpUseWindow procedure, creating Container records} -constraints {
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    child alias w winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t -use [w]
        list [testembed] [expr {[lindex [lindex [testembed all] 0] 0] - [w]}]
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {{{XXX {} {} .t}} 0}
test unixEmbed-1.6 {Tk_UseWindow procedure, creating Container records} -constraints {
    unix testembed notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    dobg "set w1 [winfo id .f1]"
    dobg "set w2 [winfo id .f2]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	toplevel .t2 -use $w2
	testembed
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    toplevel .t2 -use $w2
	    testembed
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{XXX {} {} .t2} {XXX {} {} .t1}}
test unixEmbed-1.6a {Tk_UseWindow procedure, creating Container records} -constraints {
    unix testembed
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    child alias w1 winfo id .f1
    child alias w2 winfo id .f2
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        toplevel .t2 -use [w2]
        testembed
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {{XXX {} {} .t2} {XXX {} {} .t1}}
test unixEmbed-1.7 {Tk_UseWindow procedure, container and embedded in same app} -constraints {
    unix testembed
test unixEmbed-1.7 {TkpUseWindow procedure, container and embedded in same app} -constraints {
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    pack .f1 .f2
    toplevel .t1 -use [winfo id .f1]
    toplevel .t2 -use [winfo id .f2]
    testembed
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{XXX .f2 {} .t2} {XXX .f1 {} .t1}}

# Can't think of any way to test the procedures Tk_MakeWindow,
# Tk_MakeContainer, or EmbedErrorProc.
# Can't think of any way to test the procedures TkpMakeWindow,
# TkpMakeContainer, or EmbedErrorProc.


test unixEmbed-2.1 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    testembed
    }
    destroy .f1
    update
    dobg {
	testembed
	    testembed
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test unixEmbed-2.1a {EmbeddedEventProc procedure} -constraints {
    unix testembed
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        testembed
    }
    destroy .f1
    update
    child eval {
        testembed
    }
} -cleanup {
    deleteWindows
} -result {}
test unixEmbed-2.2 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	testembed
	destroy .t1
	testembed
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    testembed
	    destroy .t1
	    testembed
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test unixEmbed-2.2a {EmbeddedEventProc procedure} -constraints {
    unix testembed
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        testembed
        destroy .t1
        testembed
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {}
test unixEmbed-2.3 {EmbeddedEventProc procedure} -constraints {
    unix testembed notAqua
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    toplevel .t1 -use [winfo id .f1]
    update
    destroy .f1
    testembed
} -result {}
test unixEmbed-2.4 {EmbeddedEventProc procedure} -constraints {
    unix testembed
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    pack [frame .f1 -container 1 -width 200 -height 50]
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    toplevel .t1 -use [winfo id .f1]
    set x [testembed]
    update
    destroy .t1
    set x [testembed]
    update
    list $x [winfo exists .t1] [winfo exists .f1] [testembed]
    list $x [testembed]
} -cleanup {
    deleteWindows
} -result "{{XXX .f1 {} .t1}} 0 0 {}"
	deleteWindows
} -result {{{XXX .f1 {} {}}} {}}


test unixEmbed-3.1 {ContainerEventProc procedure, detect creation} -constraints {
    unix testembed nonPortable
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    set x [testembed]
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	wm withdraw .t1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    wm withdraw .t1
    }
    list $x [testembed]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{XXX .f1 {} {}}} {{XXX .f1 XXX {}}}}
test unixEmbed-3.1a {ContainerEventProc procedure, detect creation} -constraints {
    unix testembed
} -setup {
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    set x [testembed]
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        wm withdraw .t1
    }
    list $x [testembed]
} -cleanup {
    interp delete child
    deleteWindows
} -result {{{XXX .f1 {} {}}} {{XXX .f1 {} {}}}}
test unixEmbed-3.2 {ContainerEventProc procedure, set size on creation} -constraints {
    unix
	unix
} -setup {
    deleteWindows
	deleteWindows
    update
} -body {
    toplevel .t1 -container 1
    wm geometry .t1 +0+0
    toplevel .t2 -use [winfo id .t1] -bg red
    update
    wm geometry .t2
} -cleanup {
    deleteWindows
	deleteWindows
} -result {200x200+0+0}
test unixEmbed-3.3 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -bd 2 -relief raised
	update
	wm geometry .t1 +30+40
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1 -bd 2 -relief raised
	    update
	    wm geometry .t1 +30+40
    }
    update
    dobg {
        wm geometry .t1
	    wm geometry .t1
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {200x200+0+0}
test unixEmbed-3.3a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix
test unixEmbed-3.4 {ContainerEventProc procedure, disallow position changes} -constraints {
	unix
} -setup {
    deleteWindows
	deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1] -bd 2 -relief raised
        update
        wm geometry .t1 +30+40
        update
        wm geometry .t1
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {200x200+0+0}
test unixEmbed-3.4 {ContainerEventProc procedure, disallow position changes} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	wm geometry .t1 300x100+30+40
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    update
	    wm geometry .t1 300x100+30+40
    }
    update
    dobg {
        wm geometry .t1
	    wm geometry .t1
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {300x100+0+0}
test unixEmbed-3.4a {ContainerEventProc procedure, disallow position changes} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
        wm geometry .t1 300x100+30+40
        update
        wm geometry .t1
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {300x100+0+0}
test unixEmbed-3.5 {ContainerEventProc procedure, geometry requests} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    dobg {
	.t1 configure -width 300 -height 80
	    .t1 configure -width 300 -height 80
    }
    update
    list [winfo width .f1] [winfo height .f1] [dobg {wm geometry .t1}]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {300 80 300x80+0+0}
test unixEmbed-3.5a {ContainerEventProc procedure, geometry requests} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        .t1 configure -width 300 -height 80
        update
    }
    list [winfo width .f1] [winfo height .f1] [child eval {wm geometry .t1}]
} -cleanup {
    interp delete child
    deleteWindows
} -result {300 80 300x80+0+0}
test unixEmbed-3.6 {ContainerEventProc procedure, map requests} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	set x unmapped
	bind .t1 <Map> {set x mapped}
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    set x unmapped
	    bind .t1 <Map> {set x mapped}
    }
    update
    dobg {
	after 100
	update
	set x
	    after 100
	    update
	    set x
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {mapped}
test unixEmbed-3.6a {ContainerEventProc procedure, map requests} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        set x unmapped
        bind .t1 <Map> {set x mapped}
        update
        after 100
        update
        set x
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {mapped}
test unixEmbed-3.7 {ContainerEventProc procedure, destroy events} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    bind .f1 <Destroy> {set x dead}
    set x alive
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    dobg {
	destroy .t1
	    destroy .t1
    }
    update
    list $x [winfo exists .f1]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {dead 0}
test unixEmbed-3.7a {ContainerEventProc procedure, destroy events} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    bind .f1 <Destroy> {set x dead}
    set x alive
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
        destroy .t1
    }

    update
    list $x [winfo exists .f1]
} -cleanup {
    interp delete child
    deleteWindows
} -result {dead 0}

test unixEmbed-4.1 {EmbedStructureProc procedure, configure events} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    dobg {
	.t1 configure -width 180 -height 100
	    .t1 configure -width 180 -height 100
    }
    update
    dobg {
	winfo geometry .t1
	    winfo geometry .t1
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {180x100+0+0}
test unixEmbed-4.1a {EmbedStructureProc procedure, configure events} -constraints {
    unix
test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} -constraints {
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
    dobg "set w1 [winfo id .f1]"
    dobg {
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
        .t1 configure -width 180 -height 100
        update
        winfo geometry .t1
    set x [testembed]
    destroy .f1
    }
    list $x [testembed]
} -cleanup {
    interp delete child
    deleteWindows
} -result {180x100+0+0}
test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} -constraints {
    unix testembed notAqua
	deleteWindows
} -result {{{XXX .f1 XXX {}}} {}}


test unixEmbed-5.1 {EmbedFocusProc procedure, FocusIn events} -constraints {
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    set x [testembed]
    destroy .f1
    update
    list $x [testembed]
} -cleanup {
    deleteWindows
} -result {{{XXX .f1 XXX {}}} {}}
test unixEmbed-4.2a {EmbedStructureProc procedure, destroy events} -constraints {
    unix testembed
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
    }
    set x [testembed]
    destroy .f1
    list $x [testembed]
} -cleanup {
    interp delete child
    deleteWindows
} -result "{{XXX .f1 {} {}}} {}"


test unixEmbed-5.1 {EmbedFocusProc procedure, FocusIn events} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
	    bind .t1 <FocusIn> {lappend x "focus in %W"}
	    bind .t1 <FocusOut> {lappend x "focus out %W"}
	    set x {}
    }
    focus -force .f1
    update
    dobg {set x}
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{focus in .t1}}
test unixEmbed-5.1a {EmbedFocusProc procedure, FocusIn events} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        bind .t1 <FocusIn> {lappend x "focus in %W"}
        bind .t1 <FocusOut> {lappend x "focus out %W"}
        update
        set x {}
    }
    focus -force .f1
    update
    child eval {set x}
} -cleanup {
    interp delete child
    deleteWindows
} -result {{focus in .t1}}
test unixEmbed-5.2 {EmbedFocusProc procedure, focusing on dead window} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	eval destroy [winfo child .]
	toplevel .t1 -use $w1
    }
    update
    dobg {
	after 200 {destroy .t1}
	    after 200 {destroy .t1}
    }
    after 400
    focus -force .f1
    update
} -cleanup {
    deleteWindows
	deleteWindows
} -result {}
test unixEmbed-5.2a {EmbedFocusProc procedure, focusing on dead window} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
        after 200 {destroy .t1}
    }
    after 400
    focus -force .f1
    update
} -cleanup {
    interp delete child
    deleteWindows
} -result {}
test unixEmbed-5.3 {EmbedFocusProc procedure, FocusOut events} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	bind .t1 <FocusIn> {lappend x "focus in %W"}
	bind .t1 <FocusOut> {lappend x "focus out %W"}
	set x {}
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
	    bind .t1 <FocusIn> {lappend x "focus in %W"}
	    bind .t1 <FocusOut> {lappend x "focus out %W"}
	    set x {}
    }
    focus -force .f1
    update
    set x [dobg {update; set x}]
    focus .
    update
    list $x [dobg {update; set x}]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}
test unixEmbed-5.3a {EmbedFocusProc procedure, FocusOut events} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        set x {}
        bind .t1 <FocusIn> {lappend x "focus in %W"}
        bind .t1 <FocusOut> {lappend x "focus out %W"}
        update
    }

    focus -force .f1
    update
    set x [child eval {update; set x }]
    focus .
    update
    list $x [child eval {update; set x}]
} -cleanup {
    interp delete child
    deleteWindows
} -result {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}


test unixEmbed-6.1 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update
	list $x [winfo geom .t1]
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    dobg {
	    bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	    set x {}
	    .t1 configure -width 300 -height 120
	    update
	    list $x [winfo geom .t1]
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{configure .t1 300 120}} 300x120+0+0}
test unixEmbed-6.1a {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix
test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} -constraints {
	unix
} -setup {
    deleteWindows
	deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
        bind .t1 <Configure> {set x {configure .t1 %w %h}}
        set x {}
        .t1 configure -width 300 -height 120
        update
        list $x [winfo geom .t1]
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {{configure .t1 300 120} 300x120+0+0}
test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix notAqua
} -setup {
    deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    place .f1 -width 200 -height 200
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	update
	bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	set x {}
	.t1 configure -width 300 -height 120
	update
	list $x [winfo geom .t1]
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    after 300 {set x done}
    vwait x
    dobg {
	    bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
	    set x {}
	    .t1 configure -width 300 -height 120
	    update
	    list $x [winfo geom .t1]
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{configure .t1 200 200}} 200x200+0+0}
test unixEmbed-6.2a {EmbedGeometryRequest procedure, window changes size} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    place .f1 -width 200 -height 200
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
        update
        bind .t1 <Configure> {set x {configure .t1 %w %h}}
	set x {}
        .t1 configure -width 300 -height 120
        update
        list $x [winfo geom .t1]
    }

} -cleanup {
    interp delete child
    deleteWindows
# Can't think up any tests for TkpGetOtherWindow procedure.
} -result {{configure .t1 200 200} 200x200+0+0}

# Can't think up any tests for Tk_GetOtherWindow procedure.

test unixEmbed-7.1 {TkpRedirectKeyEvent procedure, forward keystroke} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    deleteWindows
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    focus -force .
    bind . <Key> {lappend x {key %A %E}}
    bind . <KeyPress> {lappend x {key %A %E}}
    set x {}
    set y [dobg {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym a
	set y
	    update
	    bind .t1 <KeyPress> {lappend y {key %A}}
	    set y {}
	    event generate .t1 <KeyPress> -keysym a
	    set y
    }]
    update
    list $x $y
} -cleanup {
    deleteWindows
    bind . <Key> {}
	deleteWindows
    bind . <KeyPress> {}
} -result {{{key a 1}} {}}
# TkpRedirectKeyEvent is not implemented in win or aqua.  If someone
# implements it they should change the constraints for this test.
test unixEmbed-7.1a {TkpRedirectKeyEvent procedure, forward keystroke} -constraints {
    unix notAqua failsOnXQuarz
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    deleteWindows
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
    }
    focus -force .
    bind . <Key> {lappend x {key %A %E}}
    set x {}
    set y [child eval {
        update
        bind .t1 <Key> {lappend y {key %A}}
        set y {}
        event generate .t1 <Key> -keysym a
        set y
    }]
    update
    list $x $y
} -cleanup {
    interp delete child
    deleteWindows
    bind . <Key> {}
} -result {{{key a 1}} {}}
test unixEmbed-7.2 {TkpRedirectKeyEvent procedure, don't forward keystroke width} -constraints {
    unix notAqua
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1
    }
    update
    focus -force .f1
    update
    bind . <Key> {lappend x {key %A}}
    bind . <KeyPress> {lappend x {key %A}}
    set x {}
    set y [dobg {
	update
	bind .t1 <Key> {lappend y {key %A}}
	set y {}
	event generate .t1 <Key> -keysym b
	set y
	    update
	    bind .t1 <KeyPress> {lappend y {key %A}}
	    set y {}
	    event generate .t1 <KeyPress> -keysym b
	    set y
    }]
    update
    list $x $y
} -cleanup {
    deleteWindows
    bind . <Key> {}
	deleteWindows
    bind . <KeyPress> {}
} -result {{} {{key b}}}
test unixEmbed-7.2a {TkpRedirectKeyEvent procedure, don't forward keystroke width} -constraints {
    unix
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1]
    }

    update
    focus -force .f1
    update
    bind . <Key> {lappend x {key %A}}
    set x {}
    set y [child eval {
        update
        bind .t1 <Key> {lappend y {key %A}}
        set y {}
        event generate .t1 <Key> -keysym b
        set y
    }]
    update
    list $x $y
} -cleanup {
    interp delete child
    deleteWindows
    bind . <Key> {}
} -result {{} {{key b}}}

test unixEmbed-8.1 {TkpClaimFocus procedure} -constraints {
test unixEmbed-8.1 {TkpClaimFocus procedure} -constraints unix -setup {
    unix notAqua failsOnUbuntu failsOnXQuarz
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -width 200 -height 50
    pack .f1 .f2
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
    }
    focus -force .f2
    update
    list [dobg {
	focus .t1
	set x [list [focus]]
	update
	after 500
	update
	lappend x [focus]
	    focus .t1
	    set x [list [focus]]
	    update
	    after 500
	    update
	    lappend x [focus]
    }] [focus]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{} .t1} .f1}
test unixEmbed-8.1a {TkpClaimFocus procedure} -constraints unix -setup {
    deleteWindows
test unixEmbed-8.2 {TkpClaimFocus procedure} -constraints unix -setup {
	deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -width 200 -height 50
    pack .f1 .f2
    update
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1] -highlightthickness 2 -bd 2 -relief sunken
    }
    # This should clear focus from the application embedded in .f1
    focus -force .f2
    update
    list [child eval {
        set x [list [focus]]
        focus .t1
	update
        lappend x [focus]
    }] [focus]
} -cleanup {
    interp delete child
    deleteWindows
} -result {{{} .t1} .f1}
test unixEmbed-8.2 {TkpClaimFocus procedure} -constraints unix -setup {
    deleteWindows
    catch {interp delete child}
    interp create child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -width 200 -height 50
    pack .f1 .f2
    update
    interp create child
    set w1 [winfo id .f1]
    child eval "set argv {-use [winfo id .f1]}"
    load {} Tk child
    child eval {
	. configure -bd 2 -highlightthickness 2 -relief sunken
	    . configure -bd 2 -highlightthickness 2 -relief sunken
    }
    focus -force .f2
    update
    list [child eval {
	focus .
	set x [list [focus]]
	update
	lappend x [focus]
	    focus .
	    set x [list [focus]]
	    update
	    lappend x [focus]
    }] [focus]
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{} .} .f1}
catch {interp delete child}


test unixEmbed-9.1 {EmbedWindowDeleted procedure, check parentPtr} -constraints {
    unix testembed
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    frame .f2 -container 1 -width 200 -height 50
    frame .f3 -container 1 -width 200 -height 50
    frame .f4 -container 1 -width 200 -height 50
    pack .f1 .f2 .f3 .f4
    set x {}
    lappend x [testembed]
    foreach w {.f3 .f4 .f1 .f2} {
	destroy $w
	lappend x [testembed]
	    destroy $w
	    lappend x [testembed]
    }
    set x
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{XXX .f4 {} {}} {XXX .f3 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f4 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}}} {}}
test unixEmbed-9.2 {EmbedWindowDeleted procedure, check embeddedPtr} -constraints {
    unix testembed notAqua
	unix testembed
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    dobg "set w1 [winfo id .f1]"
    dobg {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	set x {}
	lappend x [testembed]
	destroy .t1
	lappend x [testembed]
	    eval destroy [winfo child .]
	    toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	    set x {}
	    lappend x [testembed]
	    destroy .t1
	    lappend x [testembed]
    }
} -cleanup {
    deleteWindows
	deleteWindows
} -result {{{XXX {} {} .t1}} {}}
test unixEmbed-9.2a {EmbedWindowDeleted procedure, check embeddedPtr} -constraints {
    unix testembed
} -setup {
    deleteWindows
    catch {interp delete child}
    ::_test_tmp::testInterp child
    load {} Tktest child
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    child alias w1 winfo id .f1
    child eval {
        destroy {*}[winfo children .]
        toplevel .t1 -use [w1] -highlightthickness 2 -bd 2 -relief sunken
        set x {}
        lappend x [testembed]
        destroy .t1
        lappend x [testembed]
    }
} -cleanup {
    interp delete child
    deleteWindows
} -result {{{XXX {} {} .t1}} {}}


test unixEmbed-10.1 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} -constraints {
    unix
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    toplevel .t1 -use [winfo id .f1] -width 150 -height 80
    update
    wm geometry .t1 +40+50
    update
    wm geometry .t1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {150x80+0+0}
test unixEmbed-10.2 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} -constraints {
    unix
	unix
} -setup {
    deleteWindows
	deleteWindows
} -body {
    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    toplevel .t1 -use [winfo id .f1] -width 150 -height 80
    update
    wm geometry .t1 70x300+10+20
    update
    wm geometry .t1
} -cleanup {
    deleteWindows
	deleteWindows
} -result {70x300+0+0}

test unixEmbed-11.1 {focus -force works for embedded toplevels} -constraints {
    unix
} -setup {
    deleteWindows
} -body {
    toplevel .t
    pack [frame .t.f -container 1 -width 200 -height 200] -fill both
    update
    toplevel .embed -use [winfo id .t.f] -bg green
    update
    focus -force .t
    focus -force .embed
    focus
} -cleanup {
    deleteWindows
} -result .embed
test unixEmbed-11.2 {mouse coordinates in embedded toplevels} -constraints {
    unix pressbutton
} -setup {
    deleteWindows
} -body {
    set result {}
    toplevel .main
    update
    frame .main.f -container 1 -width 200 -height 200
    button .main.b -text "Main Button" -command {lappend result "pushed .main.b"}
    wm geometry .main 200x400+100+100
    pack .main.f -fill both
    pack .main.b -padx 30 -pady 30
    update
    toplevel .embed -use [winfo id .main.f] -bg green
    button .embed.b -text "Emb Button" -command {lappend result "pushed .embed.b"}
    pack .embed.b -padx 30 -pady 30
    update
    focus -force .main
    update
    set x [expr {[winfo rootx .main.b] + [winfo width .main.b]/2}]
    set y [expr {[winfo rooty .main.b] + [winfo height .main.b]/2}]
    lappend result [winfo containing $x $y]
    pressbutton $x $y
    update
    set x [expr {[winfo rootx .embed.b] + [winfo width .embed.b]/2}]
    set y [expr {[winfo rooty .embed.b] + [winfo height .embed.b]/2}]
    lappend result [winfo containing $x $y]
    pressbutton $x $y
    update
    set result
} -cleanup {
    deleteWindows
} -result {.main.b {pushed .main.b} .embed.b {pushed .embed.b}}


# cleanup
deleteWindows
cleanupbg
cleanupTests
return

Changes to tests/unixFont.test.

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10


11
12
13
14

15
16
17
18



19
20
21
22
23
24
25










-
-
+
+


-
+



-
-
-







# This file is a Tcl script to test out the procedures in tkUnixFont.c.
# It is organized in the standard fashion for Tcl tests.
#
# Many of these tests are visually oriented and cannot be checked
# programmatically (such as "does an underlined font appear to be
# underlined?"); these tests attempt to exercise the code in question,
# but there are no results that can be checked.  Some tests depend on the
# fonts having or not having certain properties, which may not be valid
# at all sites.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

if {[tk windowingsystem] eq "x11"} {
    set xlsf [auto_execok xlsfonts]
}
foreach {constraint font} {
    hasArial	arial
    hasCourierNew	"courier new"
    hasTimesNew	"times new roman"
65
66
67
68
69
70
71
72

73
74
75

76
77

78
79

80
81
82
83
84

85
86
87
88
89
90
91

92
93
94
95
96
97
98

99
100
101
102
103
104

105
106
107
108

109
110
111

112
113
114

115
116
117

118
119
120

121
122
123


124
125
126
127
128
129
130
131
132

133
134
135
136
137

138
139
140
141
142

143
144
145
146

147
148
149

150
151
152
153
154
155
156

157
158
159
160

161
162
163
164

165
166
167
168

169
170
171
172

173
174
175
176

177
178
179
180
181


182
183
184
185

186
187
188
189
190
191
192

193
194
195
196
197

198
199
200
201

202
203
204
205

206
207
208
209

210
211
212
213

214
215
216
217

218
219
220
221
222

223
224
225
226

227
228
229
230
231
232

233
234
235
236
237
238
239

240
241
242
243
244
245
246
247

248
249
250


251
252
253
254
255
256
257
258
259

260
261

262
263
264
265
266
267

268
269
270


271
272
273
274
275
276
277

278
279
280
281

282
283
284
285

286
287
288
289

290
291
292
293

294
295
296
297
298

299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
62
63
64
65
66
67
68

69
70
71

72
73

74
75

76
77
78
79
80

81
82
83
84
85
86
87

88
89
90
91
92
93
94

95
96
97
98
99
100

101
102
103
104

105
106
107

108
109
110

111
112
113

114
115
116

117
118


119
120
121
122
123
124
125
126
127
128

129
130
131
132
133

134
135
136
137
138

139
140
141
142

143
144
145

146
147
148
149
150
151
152

153
154
155
156

157
158
159
160

161
162
163
164

165
166
167
168

169
170
171
172

173
174
175
176


177
178
179
180
181

182
183
184
185
186
187
188

189
190
191
192
193

194
195
196
197

198
199
200
201

202
203
204
205

206
207
208
209

210
211
212
213

214
215
216
217
218

219
220
221
222

223
224
225
226
227
228

229
230
231
232
233
234
235

236
237
238
239
240
241
242
243

244
245


246
247
248
249
250
251
252
253
254
255

256
257

258
259
260
261
262
263

264
265


266
267
268
269
270
271
272
273

274
275
276
277

278
279
280
281

282
283
284
285

286
287
288
289

290
291
292
293
294

295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311







-
+


-
+

-
+

-
+




-
+






-
+






-
+





-
+



-
+


-
+


-
+


-
+


-
+

-
-
+
+








-
+




-
+




-
+



-
+


-
+






-
+



-
+



-
+



-
+



-
+



-
+



-
-
+
+



-
+






-
+




-
+



-
+



-
+



-
+



-
+



-
+




-
+



-
+





-
+






-
+







-
+

-
-
+
+








-
+

-
+





-
+

-
-
+
+






-
+



-
+



-
+



-
+



-
+




-
+








-
+







set ax [winfo reqwidth .b.l]
set ay [winfo reqheight .b.l]
proc getsize {} {
    update
    return "[winfo reqwidth .b.l] [winfo reqheight .b.l]"
}

test unixfont-1.1 {TkpGetNativeFont procedure: not native} {x11 noExceed} {
test unixfont-1.1 {TkpGetNativeFont procedure: not native} {unix noExceed} {
    list [catch {font measure {} xyz} msg] $msg
} {1 {font "" doesn't exist}}
test unixfont-1.2 {TkpGetNativeFont procedure: native} {x11 failsOnUbuntu} {
test unixfont-1.2 {TkpGetNativeFont procedure: native} unix {
    font measure fixed 0
} 6
} {6}

test unixfont-2.1 {TkpGetFontFromAttributes procedure: no family} x11 {
test unixfont-2.1 {TkpGetFontFromAttributes procedure: no family} unix {
    font actual {-size 10}
    set x {}
} {}
test unixfont-2.2 {TkpGetFontFromAttributes procedure: Times relatives} \
	{x11 noExceed hasTimesNew failsOnUbuntu} {
	{unix noExceed hasTimesNew} {
    set x {}
    lappend x [lindex [font actual {-family "Times New Roman"}] 1]
    lappend x [lindex [font actual {-family "New York"}] 1]
    lappend x [lindex [font actual {-family "Times"}] 1]
} {times times times}
test unixfont-2.3 {TkpGetFontFromAttributes procedure: Courier relatives} \
	{x11 noExceed hasCourierNew failsOnUbuntu} {
	{unix noExceed hasCourierNew} {
    set x {}
    lappend x [lindex [font actual {-family "Courier New"}] 1]
    lappend x [lindex [font actual {-family "Monaco"}] 1]
    lappend x [lindex [font actual {-family "Courier"}] 1]
} {courier courier courier}
test unixfont-2.4 {TkpGetFontFromAttributes procedure: Helvetica relatives} \
	{x11 noExceed hasArial failsOnUbuntu} {
	{unix noExceed hasArial} {
    set x {}
    lappend x [lindex [font actual {-family "Arial"}] 1]
    lappend x [lindex [font actual {-family "Geneva"}] 1]
    lappend x [lindex [font actual {-family "Helvetica"}] 1]
} {helvetica helvetica helvetica}
test unixfont-2.5 {TkpGetFontFromAttributes procedure: fallback} x11 {
test unixfont-2.5 {TkpGetFontFromAttributes procedure: fallback} unix {
    font actual {-xyz-xyz-*-*-*-*-*-*-*-*-*-*-*-*}
    set x {}
} {}
test unixfont-2.6 {TkpGetFontFromAttributes: fallback to fixed family} {x11 failsOnUbuntu} {
test unixfont-2.6 {TkpGetFontFromAttributes: fallback to fixed family} unix {
    lindex [font actual {-family fixed -size 10}] 1
} {fixed}
test unixfont-2.7 {TkpGetFontFromAttributes: fixed family not available!} x11 {
test unixfont-2.7 {TkpGetFontFromAttributes: fixed family not available!} unix {
    # no test available
} {}
test unixfont-2.8 {TkpGetFontFromAttributes: loop over returned font names} {x11 failsOnUbuntu} {
test unixfont-2.8 {TkpGetFontFromAttributes: loop over returned font names} unix {
    lindex [font actual {-family fixed -size 31}] 1
} {fixed}
test unixfont-2.9 {TkpGetFontFromAttributes: reject adobe courier if possible} {x11 noExceed failsOnUbuntu} {
test unixfont-2.9 {TkpGetFontFromAttributes: reject adobe courier if possible} {unix noExceed} {
    lindex [font actual {-family courier}] 1
} {courier}
test unixfont-2.10 {TkpGetFontFromAttributes: scalable font found} {x11 haveCourier37Font} {
test unixfont-2.10 {TkpGetFontFromAttributes: scalable font found} unix {
    lindex [font actual {-family courier -size 37}] 3
} 37
test unixfont-2.11 {TkpGetFontFromAttributes: font cannot be loaded} x11 {
} {37}
test unixfont-2.11 {TkpGetFontFromAttributes: font cannot be loaded} unix {
    # On Linux, XListFonts() was returning names for fonts that do not
    # actually exist, causing the subsequent XLoadQueryFont() to fail
    # unexpectedly.  Now falls back to another font if that happens.

    font actual {-size 14}
    set x {}
} {}

test unixfont-3.1 {TkpDeleteFont procedure} x11 {
test unixfont-3.1 {TkpDeleteFont procedure} unix {
    font actual {-family xyz}
    set x {}
} {}

test unixfont-4.1 {TkpGetFontFamilies procedure} x11 {
test unixfont-4.1 {TkpGetFontFamilies procedure} unix {
    font families
    set x {}
} {}

test unixfont-5.1 {Tk_MeasureChars procedure: no chars to be measured} x11 {
test unixfont-5.1 {Tk_MeasureChars procedure: no chars to be measured} unix {
    .b.l config -text "000000" -wrap [expr $ax*3]
    .b.l config -wrap 0
} {}
test unixfont-5.2 {Tk_MeasureChars procedure: no right margin} x11 {
test unixfont-5.2 {Tk_MeasureChars procedure: no right margin} unix {
    .b.l config -text "000000"
} {}
test unixfont-5.3 {Tk_MeasureChars procedure: loop over chars} x11 {
test unixfont-5.3 {Tk_MeasureChars procedure: loop over chars} unix {
    .b.l config -text "0"
    .b.l config -text "\377"
    .b.l config -text "0\3770\377"
    .b.l config -text "000000000000000"
} {}
.b.l config -wrap [expr $ax*10]
test unixfont-5.4 {Tk_MeasureChars procedure: reached right edge} x11 {
test unixfont-5.4 {Tk_MeasureChars procedure: reached right edge} unix {
    .b.l config -text "0000000000000"
    getsize
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.5 {Tk_MeasureChars procedure: ran out of chars} x11 {
test unixfont-5.5 {Tk_MeasureChars procedure: ran out of chars} unix {
    .b.l config -text "000000"
    getsize
} "[expr $ax*6] $ay"
test unixfont-5.6 {Tk_MeasureChars procedure: find last word} x11 {
test unixfont-5.6 {Tk_MeasureChars procedure: find last word} unix {
    .b.l config -text "000000 00000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.7 {Tk_MeasureChars procedure: already saw space in line} x11 {
test unixfont-5.7 {Tk_MeasureChars procedure: already saw space in line} unix {
    .b.l config -text "000000     00000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test unixfont-5.8 {Tk_MeasureChars procedure: internal spaces significant} {x11 failsOnUbuntu} {
test unixfont-5.8 {Tk_MeasureChars procedure: internal spaces significant} unix {
    .b.l config -text "00  000     00000"
    getsize
} "[expr $ax*7] [expr $ay*2]"
test unixfont-5.9 {Tk_MeasureChars procedure: TK_PARTIAL_OK} {x11 failsOnUbuntu} {
test unixfont-5.9 {Tk_MeasureChars procedure: TK_PARTIAL_OK} unix {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0000"
    .b.c index $t @[expr int($ax*2.5)],1
} 2
test unixfont-5.10 {Tk_MeasureChars procedure: TK_AT_LEAST_ONE} x11 {
} {2}
test unixfont-5.10 {Tk_MeasureChars procedure: TK_AT_LEAST_ONE} unix {
    .b.l config -text "000000000000"
    getsize
} "[expr $ax*10] [expr $ay*2]"
test unixfont-5.11 {Tk_MeasureChars: TK_AT_LEAST_ONE + not even one char fit!} x11 {
test unixfont-5.11 {Tk_MeasureChars: TK_AT_LEAST_ONE + not even one char fit!} unix {
    set a [.b.l cget -wrap]
    .b.l config -text "000000" -wrap 1
    set x [getsize]
    .b.l config -wrap $a
    set x
} "$ax [expr $ay*6]"
test unixfont-5.12 {Tk_MeasureChars procedure: include eol spaces} {x11 failsOnUbuntu} {
test unixfont-5.12 {Tk_MeasureChars procedure: include eol spaces} unix {
    .b.l config -text "000   \n000"
    getsize
} "[expr $ax*6] [expr $ay*2]"

test unixfont-6.1 {Tk_DrawChars procedure: loop test} x11 {
test unixfont-6.1 {Tk_DrawChars procedure: loop test} unix {
    .b.l config -text "a"
    update
} {}
test unixfont-6.2 {Tk_DrawChars procedure: loop test} x11 {
test unixfont-6.2 {Tk_DrawChars procedure: loop test} unix {
    .b.l config -text "abcd"
    update
} {}
test unixfont-6.3 {Tk_DrawChars procedure: special char} x11 {
test unixfont-6.3 {Tk_DrawChars procedure: special char} unix {
    .b.l config -text "\001"
    update
} {}
test unixfont-6.4 {Tk_DrawChars procedure: normal then special} x11 {
test unixfont-6.4 {Tk_DrawChars procedure: normal then special} unix {
    .b.l config -text "ab\001"
    update
} {}
test unixfont-6.5 {Tk_DrawChars procedure: ends with special} x11 {
test unixfont-6.5 {Tk_DrawChars procedure: ends with special} unix {
    .b.l config -text "ab\001"
    update
} {}
test unixfont-6.6 {Tk_DrawChars procedure: more normal chars at end} x11 {
test unixfont-6.6 {Tk_DrawChars procedure: more normal chars at end} unix {
    .b.l config -text "ab\001def"
    update
} {}

test unixfont-7.1 {DrawChars procedure: no effects} x11 {
test unixfont-7.1 {DrawChars procedure: no effects} unix {
    .b.l config -text "abc"
    update
} {}
test unixfont-7.2 {DrawChars procedure: underlining} x11 {
test unixfont-7.2 {DrawChars procedure: underlining} unix {
    set f [.b.l cget -font]
    .b.l config -text "abc" -font "courier 10 underline"
    update
    .b.l config -font $f
} {}
test unixfont-7.3 {DrawChars procedure: overstrike} x11 {
test unixfont-7.3 {DrawChars procedure: overstrike} unix {
    set f [.b.l cget -font]
    .b.l config -text "abc" -font "courier 10 overstrike"
    update
    .b.l config -font $f
} {}

test unixfont-8.1 {InitFont procedure: use old font} x11 {
test unixfont-8.1 {AllocFont procedure: use old font} unix {
    font create xyz
    button .c -font xyz
    font configure xyz -family times
    update
    destroy .c
    font delete xyz
} {}
test unixfont-8.2 {InitFont procedure: parse information from XLFD} x11 {
test unixfont-8.2 {AllocFont procedure: parse information from XLFD} unix {
    expr {[lindex [font actual {-family times -size 0}] 3] == 0}
} 0
test unixfont-8.3 {InitFont procedure: can't parse info from name} x11 {
} {0}
test unixfont-8.3 {AllocFont procedure: can't parse info from name} unix {
    catch {unset fontArray}
    # check that font actual returns the correct attributes.
    # the values of those attributes are system dependent.
    array set fontArray [font actual a12biluc]
    set result [lsort [array names fontArray]]
    catch {unset fontArray}
    set result
} {-family -overstrike -size -slant -underline -weight}
test unixfont-8.4 {InitFont procedure: classify characters} {x11 failsOnUbuntu failsOnXQuarz} {
test unixfont-8.4 {AllocFont procedure: classify characters} unix {
    set x 0
    incr x [font measure $courier "䀀"]   ;# 6
    incr x [font measure $courier "\u4000"]   ;# 6
    incr x [font measure $courier "\002"]   ;# 4
    incr x [font measure $courier "\012"]   ;# 2
    incr x [font measure $courier "\101"]   ;# 1
    set x
} [expr $cx*13]
test unixfont-8.5 {InitFont procedure: setup widths of normal chars} x11 {
test unixfont-8.5 {AllocFont procedure: setup widths of normal chars} unix {
    font metrics $courier -fixed
} 1
test unixfont-8.6 {InitFont procedure: setup widths of special chars} {x11 failsOnUbuntu failsOnXQuarz} {
} {1}
test unixfont-8.6 {AllocFont procedure: setup widths of special chars} unix {
    set x 0
    incr x [font measure $courier "\001"]   ;# 4
    incr x [font measure $courier "\002"]   ;# 4
    incr x [font measure $courier "\012"]   ;# 2
    set x
} [expr $cx*10]
test unixfont-8.7 {InitFont procedure: XA_UNDERLINE_POSITION} x11 {
test unixfont-8.7 {AllocFont procedure: XA_UNDERLINE_POSITION} unix {
    catch {font actual -adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1}
    set x {}
} {}
test unixfont-8.8 {InitFont procedure: no XA_UNDERLINE_POSITION} x11 {
test unixfont-8.8 {AllocFont procedure: no XA_UNDERLINE_POSITION} unix {
    catch {font actual --symbol-medium-r-normal--0-0-0-0-p-0-sun-fontspecific}
    set x {}
} {}
test unixfont-8.9 {InitFont procedure: XA_UNDERLINE_THICKNESS} x11 {
test unixfont-8.9 {AllocFont procedure: XA_UNDERLINE_THICKNESS} unix {
    catch {font actual -adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1}
    set x {}
} {}
test unixfont-8.10 {InitFont procedure: no XA_UNDERLINE_THICKNESS} x11 {
test unixfont-8.10 {AllocFont procedure: no XA_UNDERLINE_THICKNESS} unix {
    catch {font actual --symbol-medium-r-normal--0-0-0-0-p-0-sun-fontspecific}
    set x {}
} {}
test unixfont-8.11 {InitFont procedure: XA_UNDERLINE_POSITION was 0} x11 {
test unixfont-8.11 {AllocFont procedure: XA_UNDERLINE_POSITION was 0} unix {
    catch {font actual -adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1}
    set x {}
} {}

test unixfont-9.1 {GetControlCharSubst procedure: 2 chars subst} {x11 failsOnUbuntu failsOnXQuarz} {
test unixfont-9.1 {GetControlCharSubst procedure: 2 chars subst} unix {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0\a0"
    set x {}
    lappend x [.b.c index $t @[expr $ax*0],0]
    lappend x [.b.c index $t @[expr $ax*1],0]
    lappend x [.b.c index $t @[expr $ax*2],0]
    lappend x [.b.c index $t @[expr $ax*3],0]
} {0 1 1 2}
test unixfont-9.2 {GetControlCharSubst procedure: 4 chars subst} {x11 failsOnUbuntu failsOnXQuarz} {
test unixfont-9.2 {GetControlCharSubst procedure: 4 chars subst} unix {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0\0010"
    set x {}
    lappend x [.b.c index $t @[expr $ax*0],0]
    lappend x [.b.c index $t @[expr $ax*1],0]
    lappend x [.b.c index $t @[expr $ax*2],0]
    lappend x [.b.c index $t @[expr $ax*3],0]

Changes to tests/unixMenu.test.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests. This
# file tests the Macintosh-specific features of the menu
# system.
#
# Copyright © 1995-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands

71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+







} -body {
    menu .m1
    .m1 add cascade -label foo
    list [. configure -menu .m1] [. configure -menu ""] [destroy .m1]
} -returnCodes ok -result {{} {} {}}


test unixMenu-7.1 {Tk_SetMainMenubar - nothing to do} -constraints unix -body {}
test unixMenu-7.1 {TkpSetMainMenubar - nothing to do} -constraints unix -body {}


test unixMenu-8.1 {GetMenuIndicatorGeometry - indicator off} -constraints {
    unix
} -setup {
    destroy .m1
} -body {

Changes to tests/unixSelect.test.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







# This file contains tests for the tkUnixSelect.c file.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1999 Scriptics Corporation.
# Copyright (c) 1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118

119
120
121
122
123
124

125
126
127

128
129
130
131
132
133
134

135
136
137
138
139
140

141
142
143

144
145
146
147
148
149
150
151

152
153
154
155

156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175

176
177
178
179
180

181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197

198
199
200
201

202
203
204
205
206
207
208
209

210
211
212
213
214

215
216
217
218
219
220
221














222



















223
224
225
226
227
228
229

230
231
232
233
234
235




236
237

238

239
240
241
242
243
244
245

246
247
248

249
250
251

252
253

254

255
256
257
258
259
260
261

262
263
264

265
266
267

268
269
270
271
272

273

274
275
276
277
278
279
280

281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328

329
330
331
332
333
334

335
336
337

338
339
340
341
342
343
344

345
346
347
348
349
350

351
352
353

354
355
356
357
358
359
360

361
362
363
364
365
366

367
368
369

370
371
372
373
374
375
376

377
378
379
380
381
382

383
384
















385



386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
104
105
106
107
108
109
110

111
112
113
114
115
116
117

118
119
120
121
122
123

124
125
126

127
128
129
130
131
132
133

134
135
136
137
138
139

140
141
142

143
144
145
146
147
148
149
150

151
152
153
154

155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179

180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196

197
198
199
200

201
202
203
204
205
206
207
208

209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266

267
268
269
270
271

272

273
274
275
276
277
278
279

280
281
282

283
284
285

286
287

288

289
290
291
292
293
294
295

296
297
298

299
300
301

302



303

304

305
306
307
308
309
310
311

312
313
314
315
316
317

318
319
































320

321
322
323
324
325
326
327

328
329
330
331
332
333

334
335
336

337
338
339
340
341
342
343

344
345
346
347
348
349

350
351
352

353
354
355
356
357
358
359

360
361
362
363
364
365

366
367
368

369
370
371
372
373
374
375

376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417



















418
419
420
421
422
423
424
425







-
+






-
+





-
+


-
+






-
+





-
+


-
+







-
+



-
+







-
+











-
+




-
+








-
+







-
+



-
+







-
+




-
+







+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+





-
+
+
+
+

-
+
-
+






-
+


-
+


-
+

-
+
-
+






-
+


-
+


-
+
-
-
-

-
+
-
+






-
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+






-
+





-
+


-
+






-
+





-
+


-
+






-
+





-
+


-
+






-
+





-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+






-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







    set j $i.1$i.2$i.3$i.4$i.5$i.6$i.7$i.8$i.9$i.10$i.11$i.12$i.13$i.14
    append longValue A$j B$j C$j D$j E$j F$j G$j H$j I$j K$j L$j M$j N$j
}

# ----------------------------------------------------------------------

test unixSelect-1.1 {TkSelGetSelection procedure: simple i18n text} -constraints {
    x11
    unix
} -setup {
    destroy .e
    setupbg
} -body {
    pack [entry .e]
    update
    .e insert 0 über
    .e insert 0 \u00fcber
    .e selection range 0 end
    dobg {string length [selection get]}
} -cleanup {
    cleanupbg
    destroy .e
} -result 4
} -result {4}

test unixSelect-1.2 {TkSelGetSelection procedure: simple i18n text, iso8859-1} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 üф
        .e insert 0 \u00fc\u0444
        .e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result ü?
} -result \u00fc?

test unixSelect-1.3 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
    unix
} -setup {
    setupbg
    setup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
        {handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selValue \u00fc\u0444
    set selInfo {}
    set result [dobg {
        set x [selection get -type COMPOUND_TEXT]
        list [string equal üф $x] [string length $x]
        list [string equal \u00fc\u0444 $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.4 {TkSelGetSelection procedure: INCR i18n text, iso2022} -constraints {
    x11
    unix
} -setup {
    setupbg
    setup
} -body {
    # This test is subtle.  The selection ends up getting fetched twice by
    # Tk:  once to compute the length, and again to actually send the data.
    # The first time through, we don't convert the data to ISO2022, so the
    # buffer boundaries end up being different in the two passes.
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
        {handler COMPOUND_TEXT}
    selection own .
    set selValue [string repeat x 3999]üф[string repeat x 3999]
    set selValue [string repeat x 3999]\u00fc\u0444[string repeat x 3999]
    set selInfo {}
    set result [dobg {
        set x [selection get -type COMPOUND_TEXT]
        list [string equal \
            [string repeat x 3999]üф[string repeat x 3999] $x] \
            [string repeat x 3999]\u00fc\u0444[string repeat x 3999] $x] \
            [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 8000 {COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3999 COMPOUND_TEXT 7998 4000 COMPOUND_TEXT 0 4000 COMPOUND_TEXT 4000 3998 COMPOUND_TEXT 7997 4000}}

test unixSelect-1.5 {TkSelGetSelection procedure: simple i18n text, iso2022} -constraints {
    x11
    unix
} -setup {
    setupbg
    setup
} -body {
    selection handle -type COMPOUND_TEXT -format COMPOUND_TEXT . \
        {handler COMPOUND_TEXT}
    selection own .
    set selValue üф
    set selValue \u00fc\u0444
    set selInfo {}
    set result [dobg {
        set x [selection get -type COMPOUND_TEXT]
        list [string equal üф $x] [string length $x]
        list [string equal \u00fc\u0444 $x] [string length $x]
    }]
    lappend result $selInfo
} -cleanup {
    cleanupbg
} -result {1 2 {COMPOUND_TEXT 0 4000}}

test unixSelect-1.6 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg [subst -nobackslashes {entry .e; pack .e; update
    .e insert 0 über$longValue
    .e insert 0 \u00fcber$longValue
    .e selection range 0 end}]
    string length [selection get]
} -cleanup {
    cleanupbg
} -result [expr {4 + [string length $longValue]}]

test unixSelect-1.7 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat x 3999]\u00fc
        .e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]\u00fc
    x11

test unixSelect-1.8 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 \u00fc[string repeat x 3999]
        .e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result \u00fc[string repeat x 3999]

test unixSelect-1.9 {TkSelGetSelection procedure: INCR i18n text} -constraints {
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat x 3999]ü
        .e insert 0 [string repeat x 3999]\u00fc[string repeat x 4000]
        .e selection range 0 end
    }
    selection get
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü
} -result [string repeat x 3999]\u00fc[string repeat x 4000]
# Now some tests to make sure that the right thing is done when
# transferring UTF8 selections, to prevent [Bug 614650] and its ilk
# from rearing its ugly head again.

test unixSelect-1.8 {TkSelGetSelection procedure: INCR i18n text} -constraints {
test unixSelect-1.10 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 ü[string repeat x 3999]
        .e insert 0 [string repeat x 3999]\u00fc
        .e selection range 0 end
    }
    selection get
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result ü[string repeat x 3999]
} -result [string repeat x 3999]\u00fc

test unixSelect-1.9 {TkSelGetSelection procedure: INCR i18n text} -constraints {
test unixSelect-1.11 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat x 3999]ü[string repeat x 4000]
        .e insert 0 \u00fc[string repeat x 3999]
        .e selection range 0 end
    }
    selection get
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü[string repeat x 4000]
} -result \u00fc[string repeat x 3999]
# Now some tests to make sure that the right thing is done when
# transferring UTF8 selections, to prevent [Bug 614650] and its ilk
# from rearing its ugly head again.

test unixSelect-1.10 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
test unixSelect-1.12 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat x 3999]ü
        .e insert 0 [string repeat x 3999]\u00fc[string repeat x 4000]
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü
} -result [string repeat x 3999]\u00fc[string repeat x 4000]

test unixSelect-1.11 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 ü[string repeat x 3999]
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result ü[string repeat x 3999]

test unixSelect-1.12 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat x 3999]ü[string repeat x 4000]
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat x 3999]ü[string repeat x 4000]

test unixSelect-1.13 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    destroy .e
    setupbg
} -body {
    pack [entry .e]
    update
    .e insert 0 überф
    .e insert 0 \u00fcber\u0444
    .e selection range 0 end
    dobg {string length [selection get -type UTF8_STRING]}
} -cleanup {
    destroy .e
    cleanupbg
} -result 5
} -result {5}

test unixSelect-1.14 {TkSelGetSelection procedure: simple i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 üф
        .e insert 0 \u00fc\u0444
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result üф
} -result \u00fc\u0444

test unixSelect-1.15 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 [string repeat [string repeat Ää 50]\n 21]
        .e insert 0 [string repeat [string repeat \u00c4\u00e4 50]\n 21]
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat [string repeat Ää 50]\n 21]
} -result [string repeat [string repeat \u00c4\u00e4 50]\n 21]

test unixSelect-1.16 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [entry .e]
        update
        .e insert 0 i[string repeat [string repeat Ää 50]\n 21]
        .e insert 0 i[string repeat [string repeat \u00c4\u00e4 50]\n 21]
        .e selection range 0 end
    }
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result i[string repeat [string repeat Ää 50]\n 21]
} -result i[string repeat [string repeat \u00c4\u00e4 50]\n 21]

test unixSelect-1.17 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [text .t]
        update
        .t insert 1.0 [string repeat [string repeat \u00c4\u00e4 50]\n 21]
        # Has to be selected in a separate stage
        .t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat [string repeat \u00c4\u00e4 50]\n 21]
    x11

test unixSelect-1.18 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    unix
} -setup {
    setupbg
} -body {
    dobg {
        pack [text .t]
        update
        .t insert 1.0 [string repeat [string repeat Ää 50]\n 21]
        .t insert 1.0 i[string repeat [string repeat \u00c4\u00e4 50]\n 21]
        # Has to be selected in a separate stage
        .t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result [string repeat [string repeat Ää 50]\n 21]

test unixSelect-1.18 {TkSelGetSelection procedure: INCR i18n text, utf-8} -constraints {
    x11
} -setup {
    setupbg
} -body {
    dobg {
        pack [text .t]
        update
        .t insert 1.0 i[string repeat [string repeat Ää 50]\n 21]
        # Has to be selected in a separate stage
        .t tag add sel 1.0 21.end+1c
    }
    after 10
    selection get -type UTF8_STRING
} -cleanup {
    cleanupbg
} -result i[string repeat [string repeat Ää 50]\n 21]
} -result i[string repeat [string repeat \u00c4\u00e4 50]\n 21]

test unixSelect-1.19 {Automatic UTF8_STRING support for selection handle} -constraints {
    unix
} -setup {
    destroy .l
} -body {
    # See Bug #666346 "Selection handling crashes under KDE 3.0"

Changes to tests/unixWm.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
1
2
3
4



5
6
7
8
9
10
11
12
13
14
15















16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32



















33

34
35
36
37
38
39
40
41




-
-
-
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+







# This file is a Tcl script to test out Tk's interactions with
# the window manager, including the "wm" command.  It is organized
# in the standard fashion for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands

namespace import -force ::tk::test:loadTkCommand

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# Starting with macOS Ventura it became necessary to wait for windows to be restacked
# or to be raised after creation.

if {[tk windowingsystem] eq "aqua"} {
    proc restackDelay {} {
	after 200;
	update idletasks
    }
} else {
    proc restackDelay {} {}
}

proc sleep ms {
    global x
    after $ms {set x 1}
    vwait x
}

# Procedure to set up a collection of top-level windows

proc makeToplevels {} {
    deleteWindows
    foreach i {.raise1 .raise2 .raise3} {
	toplevel $i
	wm geom $i 150x100+0+0
	update
    }
}

# On macOS windows are not allowed to overlap the menubar at the top of the
# screen or the dock.  So tests which move a window and then check whether it
# got moved to the requested location should use a y coordinate larger than the
# height of the menubar (normally 23 pixels) and an x coordinate larger than the
# width of the dock, if it happens to be on the left.

if {[tk windowingsystem] eq "aqua"} {
    set mb [expr [menubarheight] + 1]
    set X  100
    set Y0 $mb
    set Y2 [expr $mb + 2]
    set Y5 [expr $mb + 5]
} else {
    set X  20
    set Y0 0
    set Y2 2
    set Y5 5
}

set i 1
foreach geom "+$X+80 +80+$Y0 +$X+$Y0" {
foreach geom {+20+80 +80+20 +0+0} {
    destroy .t
    test unixWm-1.$i {initial window position} unix {
	toplevel .t -width 200 -height 150
	wm geom .t $geom
	update
	wm geom .t
    } 200x150$geom
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106

107
108
109

110
111

112
113
114
115
116
117
118
119
120
121
122

123
124
125

126
127

128
129
130
131
132
133
134
135
136
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71

72
73
74

75
76

77
78

79
80
81
82
83
84
85
86

87
88
89

90
91

92
93

94
95
96
97
98
99
100







-
+











-
+


-
+

-
+

-








-
+


-
+

-
+

-







wm geom .t +200+200
update
wm geom .t +150+150
update
scan [wm geom .t] %dx%d+%d+%d width height x y
set xerr [expr 150-$x]
set yerr [expr 150-$y]
foreach geom "+20+80 +80+$Y0 +0+$Y0 -0-0 +0-0 -0+$Y0 -10-5 -10+$Y5 +10-5" {
foreach geom {+20+80 +80+20 +0+0 -0-0 +0-0 -0+0 -10-5 -10+5 +10-5} {
    test unixWm-2.$i {moving window while mapped} unix {
	wm geom .t $geom
	update
	scan [wm geom .t] %dx%d%1s%d%1s%d width height xsign x ysign y
	format "%s%d%s%d" $xsign [eval expr $x$xsign$xerr] $ysign \
		[eval expr $y$ysign$yerr]
    } $geom
    incr i
}

set i 1
foreach geom "+20+80 +80+$Y0 +0+$Y0 -0-0 +0-0 -0+$Y0 -10-5 -10+$Y5 +10-5" {
foreach geom {+20+80 +80+20 +0+0 -0-0 +0-0 -0+0 -10-5 -10+5 +10-5} {
    test unixWm-3.$i {moving window while iconified} unix {
	wm iconify .t
	update idletasks
	sleep 200
	wm geom .t $geom
	update idletasks
	update
	wm deiconify .t
	update idletasks
	scan [wm geom .t] %dx%d%1s%d%1s%d width height xsign x ysign y
	format "%s%d%s%d" $xsign [eval expr $x$xsign$xerr] $ysign \
		[eval expr $y$ysign$yerr]
    } $geom
    incr i
}

set i 1
foreach geom "+$X+80 +$X+40 +$X+$Y0" {
foreach geom {+20+80 +100+40 +0+0} {
    test unixWm-4.$i {moving window while withdrawn} unix {
	wm withdraw .t
	sleep 10
	sleep 200
	wm geom .t $geom
	update idletasks
	update
	wm deiconify .t
	sleep 10
	wm geom .t
    } 100x150$geom
    incr i
}

test unixWm-5.1 {compounded state changes} {unix nonPortable} {
    destroy .t
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213

214
215
216
217
218
219

220
221
222
223
224
225
226

227
228
229
230
231
232
233
163
164
165
166
167
168
169

170
171
172
173
174
175
176

177
178
179
180
181
182

183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+






-
+





-
+






-
+







    wm withdraw .t
    wm iconify .t
    list [winfo ismapped .t] [wm state .t]
} {0 iconic}

destroy .t
toplevel .t -width 200 -height 100
wm geom .t +100+$Y0
wm geom .t +10+10
wm minsize .t 1 1
update
test unixWm-6.1 {size changes} unix {
    .t config -width 180 -height 150
    update
    wm geom .t
} 180x150+100+$Y0
} 180x150+10+10
test unixWm-6.2 {size changes} unix {
    wm geom .t 250x60
    .t config -width 170 -height 140
    update
    wm geom .t
} 250x60+100+$Y0
} 250x60+10+10
test unixWm-6.3 {size changes} unix {
    wm geom .t 250x60
    .t config -width 170 -height 140
    wm geom .t {}
    update
    wm geom .t
} 170x140+100+$Y0
} 170x140+10+10
test unixWm-6.4 {size changes} {unix nonPortable userInteraction} {
    wm minsize .t 1 1
    update
    puts stdout "Please resize window \"t\" with the mouse (but don't move it!),"
    puts -nonewline stdout "then hit return: "
    flush stdout
    gets stdin
242
243
244
245
246
247
248




249
250
251
252
253
254
255
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223







+
+
+
+







    update
    set w2 [winfo width .t]
    set h2 [winfo height .t]
    .t config -width 114 -height 261
    update
    list $width $height $w2 $h2 [wm geom .t]
} {0 0 230 110 114x261+10+10}

# I don't know why the wait below is needed, but without it the test
# fails under twm.
sleep 200

test unixWm-6.5 {window initially iconic} {unix nonPortable} {
    destroy .t
    toplevel .t -width 100 -height 30
    wm geometry .t +0+0
    wm title .t 2
    wm iconify .t
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
265
266
267
268
269
270
271

272
273
274
275
276

277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293







-
+




-









-
+







    list [catch {wm iconwindow} msg] $msg
} {1 {wrong # args: should be "wm option window ?arg ...?"}}
test unixWm-8.3 {icon windows} unix {
    destroy .t
    toplevel .t -width 100 -height 30
    list [catch {wm iconwindow .t b c} msg] $msg
} {1 {wrong # args: should be "wm iconwindow window ?pathName?"}}
test unixWm-8.4 {icon windows} {unix failsOnUbuntu failsOnXQuarz} {
test unixWm-8.4 {icon windows} unix {
    destroy .t
    destroy .icon
    toplevel .t -width 100 -height 30
    wm geom .t +0+0
    update idletasks
    set result [wm iconwindow .t]
    toplevel .icon -width 50 -height 50 -bg red
    wm iconwindow .t .icon
    lappend result [wm iconwindow .t] [wm state .icon]
    wm iconwindow .t {}
    lappend result [wm iconwindow .t] [wm state .icon]
    update
    lappend result [winfo ismapped .t] [winfo ismapped .icon]
    wm iconify .t
    update idletasks
    update
    lappend result [winfo ismapped .t] [winfo ismapped .icon]
} {.icon icon {} withdrawn 1 0 0 0}
test unixWm-8.5 {icon windows} unix {
    destroy .t
    toplevel .t -width 100 -height 30
    list [catch {wm iconwindow .t .gorp} msg] $msg
} {1 {bad window path name ".gorp"}}
350
351
352
353
354
355
356

357
358
359
360
361
362
363
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331







+







    wm geom .icon +0+0
    update
    set result [winfo ismapped .icon]
    toplevel .t -width 100 -height 30
    wm geom .t +0+0
    tkwait visibility .t	;# Needed to keep tvtwm happy.
    wm iconwindow .t .icon
    sleep 500
    lappend result [winfo ismapped .t] [winfo ismapped .icon]
} {1 1 0}
test unixWm-8.9 {icon windows} {unix nonPortable} {
    # This test is non-portable because some window managers will
    # destroy an icon window when it's associated window is destroyed.

    destroy .t
421
422
423
424
425
426
427

428
429

430
431

432
433
434
435
436
437

438
439
440
441
442
443
444

445
446
447
448
449
450
451
389
390
391
392
393
394
395
396
397

398
399
400
401
402

403
404
405

406
407
408
409
410
411
412

413
414
415
416
417
418
419
420







+

-
+


+

-



-
+






-
+







command
}
test unixWm-9.3 {TkWmMapWindow procedure, iconic windows} unix {
    destroy .t
    toplevel .t -width 100 -height 300 -bg blue
    wm geom .t +0+0
    wm iconify .t
    sleep 500
    winfo ismapped .t
} 0
} {0}
test unixWm-9.4 {TkWmMapWindow procedure, icon windows} unix {
    destroy .t
    sleep 500
    toplevel .t -width 100 -height 50 -bg blue
    tkwait visibility .t
    wm iconwindow . .t
    update
    set result [winfo ismapped .t]
} 0
} {0}
test unixWm-9.5 {TkWmMapWindow procedure, normal windows} unix {
    destroy .t
    toplevel .t -width 200 -height 20
    wm geom .t +0+0
    update
    winfo ismapped .t
} 1
} {1}

test unixWm-10.1 {TkWmDeadWindow procedure, canceling UpdateGeometry idle handler} unix {
    destroy .t
    toplevel .t -width 100 -height 50
    wm geom .t +0+0
    update
    .t configure -width 200 -height 100
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
611
612
613
614
615
616
617

618
619
620
621
622
623
624
625







-
+







    destroy .icon
    toplevel .icon -width 50 -height 50 -bg red
    wm iconwindow .t .icon
    set result [list [catch {wm deiconify .icon} msg] $msg]
    destroy .icon
    set result
} {1 {can't deiconify .icon: it is an icon for .t}}
test unixWm-16.3 {Tk_WmCmd procedure, "deiconify" option} {unix failsOnUbuntu failsOnXQuarz} {
test unixWm-16.3 {Tk_WmCmd procedure, "deiconify" option} unix {
    wm iconify .t
    set result {}
    lappend result [winfo ismapped .t] [wm state .t]
    wm deiconify .t
    lappend result [winfo ismapped .t] [wm state .t]
} {0 iconic 1 normal}

671
672
673
674
675
676
677
678

679
680
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664







-
+









-
+







} {passive active passive}

test unixWm-18.1 {Tk_WmCmd procedure, "frame" option} unix {
    list [catch {wm frame .t 12} msg] $msg
} {1 {wrong # args: should be "wm frame window"}}
test unixWm-18.2 {Tk_WmCmd procedure, "frame" option} {unix nonPortable} {
    expr [wm frame .t] == [winfo id .t]
} 0
} {0}
test unixWm-18.3 {Tk_WmCmd procedure, "frame" option} {unix nonPortable} {
    destroy .t2
    toplevel .t2
    wm geom .t2 +0+0
    wm overrideredirect .t2 1
    update
    set result [expr [wm frame .t2] == [winfo id .t2]]
    destroy .t2
    set result
} 1
} {1}

test unixWm-19.1 {Tk_WmCmd procedure, "geometry" option} unix {
    list [catch {wm geometry .t 12 13} msg] $msg
} {1 {wrong # args: should be "wm geometry window ?newGeometry?"}}
test unixWm-19.2 {Tk_WmCmd procedure, "geometry" option} {unix nonPortable} {
    wm geometry .t -1+5
    update
792
793
794
795
796
797
798
799

800
801
802
803
804
805
806
761
762
763
764
765
766
767

768
769
770
771
772
773
774
775







-
+







    toplevel .t2
    wm geom .t2 +0+0
    wm group .t .t2
    set hints [testprop [testwrapper .t] WM_HINTS]
    set result [expr [testwrapper .t2] - [lindex $hints 8]]
    destroy .t2
    set result
} 0
} {0}
test unixWm-21.5 {Tk_WmCmd procedure, "group" option, create leader wrapper} {unix testwrapper} {
    destroy .t2
    destroy .t3
    toplevel .t2 -width 120 -height 300
    wm geometry .t2 +0+0
    toplevel .t3 -width 120 -height 300
    wm geometry .t2 +0+0
822
823
824
825
826
827
828
829
830
831
832
833
834

835
836
837

838
839
840
841
842
843
844
791
792
793
794
795
796
797






798

799

800
801
802
803
804
805
806
807







-
-
-
-
-
-
+
-

-
+







	    WM_HINTS] 0]]]
    lappend result [wm iconbitmap .t] $bit
    wm iconbitmap .t {}
    set bit [format 0x%x [expr 0x4 & [lindex [testprop [testwrapper .t] \
	    WM_HINTS] 0]]]
    lappend result [wm iconbitmap .t] $bit
} {{} questhead 0x4 {} 0x0}
if {[tk windowingsystem] eq "aqua"} {
    set result_22_3 {0 {}}
} else {
    set result_22_3 {1 {bitmap "bad-bitmap" not defined}}
}
test unixWm-22.3 {Tk_WmCmd procedure, "iconbitmap" option for unix only} \
test unixWm-22.3 {Tk_WmCmd procedure, "iconbitmap" option} unix {
unix {
    list [catch {wm iconbitmap .t bad-bitmap} msg] $msg
} $result_22_3
} {1 {bitmap "bad-bitmap" not defined}}

test unixWm-23.1 {Tk_WmCmd procedure, "iconify" option} unix {
    list [catch {wm iconify .t 12} msg] $msg
} {1 {wrong # args: should be "wm iconify window"}}
test unixWm-23.2 {Tk_WmCmd procedure, "iconify" option} unix {
    destroy .t2
    toplevel .t2
860
861
862
863
864
865
866
867
868


869
870
871
872

873
874

875
876
877
878
879


880
881
882
883

884
885
886

887
888
889
890
891
892
893
823
824
825
826
827
828
829


830
831
832
833
834

835
836

837
838
839
840


841
842
843
844
845

846
847
848

849
850
851
852
853
854
855
856







-
-
+
+



-
+

-
+



-
-
+
+



-
+


-
+







    destroy .t2
    toplevel .t2
    wm geom .t2 +0+0
    wm iconwindow .t .t2
    set result [list [catch {wm iconify .t2} msg] $msg]
    destroy .t2
    set result
} {1 {can't iconify ".t2": it is an icon for ".t"}}
test unixWm-23.5 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuarz} {
} {1 {can't iconify .t2: it is an icon for .t}}
test unixWm-23.5 {Tk_WmCmd procedure, "iconify" option} unix {
    destroy .t2
    toplevel .t2
    wm geom .t2 +0+0
    update idletasks
    update
    wm iconify .t2
    update idletasks
    update
    set result [winfo ismapped .t2]
    destroy .t2
    set result
} 0
test unixWm-23.6 {Tk_WmCmd procedure, "iconify" option} {unix failsOnUbuntu failsOnXQuarz} {
} {0}
test unixWm-23.6 {Tk_WmCmd procedure, "iconify" option} unix {
    destroy .t2
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    update
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks
    update
    lappend result [winfo ismapped .t2]
    destroy .t2
    set result
} {1 0}

test unixWm-24.1 {Tk_WmCmd procedure, "iconmask" option} unix {
    list [catch {wm iconmask .t 12 13} msg] $msg
906
907
908
909
910
911
912
913

914
915
916
917
918
919
920
869
870
871
872
873
874
875

876
877
878
879
880
881
882
883







-
+







} {{} questhead 0x20 {} 0x0}
test unixWm-24.3 {Tk_WmCmd procedure, "iconmask" option} unix {
    list [catch {wm iconmask .t bogus} msg] $msg
} {1 {bitmap "bogus" not defined}}

test unixWm-25.1 {Tk_WmCmd procedure, "iconname" option} unix {
    list [catch {wm icon .t} msg] $msg
} {1 {ambiguous option "icon": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbadge, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}}
} {1 {ambiguous option "icon": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}}
test unixWm-25.2 {Tk_WmCmd procedure, "iconname" option} unix {
    list [catch {wm iconname .t 12 13} msg] $msg
} {1 {wrong # args: should be "wm iconname window ?newName?"}}
test unixWm-25.3 {Tk_WmCmd procedure, "iconname" option} {unix testwrapper} {
    set result {}
    lappend result [wm iconname .t]
    wm iconname .t test_name
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245


1246
1247

1248
1249
1250
1251
1252
1253
1254
1196
1197
1198
1199
1200
1201
1202






1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213







-
-
-
-
-
-
+
+

-
+







    set bit [format 0x%x [expr 0xa & [lindex [testprop [testwrapper .t] \
	    WM_NORMAL_HINTS] 0]]]
    lappend result [wm sizefrom .t] $bit
} {{} program 0x8 user 0x2}
test unixWm-34.3 {Tk_WmCmd procedure, "sizefrom" option} unix {
    list [catch {wm sizefrom .t none} msg]  $msg
} {1 {bad argument "none": must be program or user}}
if {[tk windowingsystem] eq "aqua"} {
    set result_35_1 {1 {bad argument "1": must be iconic, normal, withdrawn, or zoomed}}
} else {
    set result_35_1 {1 {bad argument "1": must be iconic, normal, or withdrawn}}
}
test unixWm-35.1 {Tk_WmCmd procedure, "state" option} {unix notAqua} {

test unixWm-35.1 {Tk_WmCmd procedure, "state" option} unix {
    list [catch {wm state .t 1} msg]  $msg
} $result_35_1
} {1 {bad argument "1": must be normal, iconic, or withdrawn}}
test unixWm-35.2 {Tk_WmCmd procedure, "state" option} unix {
    list [catch {wm state .t iconic 1} msg]  $msg
} {1 {wrong # args: should be "wm state window ?state?"}}
test unixWm-35.3 {Tk_WmCmd procedure, "state" option} unix {
    set result {}
    destroy .t2
    toplevel .t2 -width 120 -height 300
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326

1327
1328
1329
1330
1331
1332
1333
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
1292







-
+










-
+







    lappend result [wm transient .t2] [expr [testwrapper .t] - $transient]
    wm transient .t2 {}
    lappend result [wm transient .t2] \
	    [testprop [testwrapper .t2] WM_TRANSIENT_FOR]
    destroy .t2
    set result
} {{} {} .t 0 {} {}}
test unixWm-37.4 {TkWmDeadWindow, destroy on toplevel should clear transient} {unix testwrapper} {
test unixWm-37.4 {TkWmDeadWindow, destroy on master should clear transient} {unix testwrapper} {
    destroy .t2
    toplevel .t2
    destroy .t3
    toplevel .t3
    wm transient .t2 .t3
    update
    destroy .t3
    update
    list [wm transient .t2] [testprop [testwrapper .t2] WM_TRANSIENT_FOR]
} {{} {}}
test unixWm-37.5 {Tk_WmCmd procedure, "transient" option, create toplevel wrapper} {unix testwrapper} {
test unixWm-37.5 {Tk_WmCmd procedure, "transient" option, create master wrapper} {unix testwrapper} {
    destroy .t2
    destroy .t3
    toplevel .t2 -width 120 -height 300
    wm geometry .t2 +0+0
    toplevel .t3 -width 120 -height 300
    wm geometry .t2 +0+0
    set result [list [testwrapper .t2]]
1355
1356
1357
1358
1359
1360
1361
1362

1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341
1342
1343

1344
1345
1346
1347
1348

1349

1350
1351
1352
1353

1354
1355
1356
1357
1358
1359
1360
1361







-
+















-
+






-
+




-

-
+



-
+







    lappend result [wm state .t] [winfo ismapped .t]
    wm deiconify .t
    lappend result [wm state .t] [winfo ismapped .t]
} {withdrawn 0 normal 1}

test unixWm-39.1 {Tk_WmCmd procedure, miscellaneous} unix {
    list [catch {wm unknown .t} msg] $msg
} {1 {bad option "unknown": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbadge, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}}
} {1 {bad option "unknown": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}}

destroy .t .icon

test unixWm-40.1 {Tk_SetGrid procedure, set grid dimensions before turning on grid} {unix nonPortable} {
    destroy .t
    toplevel .t
    wm geometry .t 30x10+0+0
    listbox .t.l -height 20 -width 20 -setgrid 1
    pack .t.l -fill both -expand 1
    update
    wm geometry .t
} {30x10+0+0}
test unixWm-40.2 {Tk_SetGrid procedure, turning on grid when dimensions already set} unix {
    destroy .t
    toplevel .t
    wm geometry .t 200x100+100+$Y0
    wm geometry .t 200x100+0+0
    listbox .t.l -height 20 -width 20
    pack .t.l -fill both -expand 1
    update
    .t.l configure -setgrid 1
    update
    wm geometry .t
} "20x20+100+$Y0"
} {20x20+0+0}

test unixWm-41.1 {ConfigureEvent procedure, internally generated size changes} unix {
    destroy .t
    toplevel .t -width 400 -height 150
    tkwait visibility .t
    wm geometry .t +0+0
    update idletasks
    tkwait visibility .t
    set result {}
    lappend result [winfo width .t] [winfo height .t]
    .t configure -width 200 -height 300
    update idletasks
    sleep 500
    lappend result [winfo width .t] [winfo height .t]
} {400 150 200 300}
test unixWm-41.2 {ConfigureEvent procedure, menubars} {nonPortable testmenubar} {
    destroy .t
    toplevel .t -width 300 -height 200 -bd 2 -relief raised
    wm geom .t +0+0
    update
1443
1444
1445
1446
1447
1448
1449
1450

1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417

1418
1419
1420

1421
1422
1423
1424
1425
1426
1427







-
+









-



-







    update
    set result
} {configured: 130 200}

# No tests for ReparentEvent or ComputeReparentGeometry; I can't figure
# out how to exercise these procedures reliably.

test unixWm-42.1 {WrapperEventProc procedure, map and unmap events} {unix failsOnUbuntu failsOnXQuarz} {
test unixWm-42.1 {WrapperEventProc procedure, map and unmap events} unix {
    destroy .t
    toplevel .t -width 400 -height 150
    wm geometry .t +0+0
    tkwait visibility .t
    set result {}
    bind .t <Map> {set x "mapped"}
    bind .t <Unmap> {set x "unmapped"}
    set x {no event}
    wm iconify .t
    update idletasks
    lappend result $x [winfo ismapped .t]
    set x {no event}
    wm deiconify .t
    update idletasks
    lappend result $x [winfo ismapped .t]
} {unmapped 0 mapped 1}

test unixWm-43.1 {TopLevelReqProc procedure, embedded in same process} unix {
    destroy .t
    toplevel .t -width 200 -height 200
    wm geom .t +0+0
1547
1548
1549
1550
1551
1552
1553

1554
1555


1556
1557
1558
1559
1560
1561
1562
1563
1564

1565
1566
1567


1568
1569
1570
1571
1572
1573
1574

1575
1576
1577


1578
1579
1580
1581
1582
1583
1584

1585
1586
1587
1588
1589
1590
1591
1503
1504
1505
1506
1507
1508
1509
1510


1511
1512

1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527



1528
1529
1530
1531
1532

1533
1534
1535
1536



1537

1538
1539
1540
1541
1542
1543
1544
1545







+
-
-
+
+
-








+


-
+
+


-
-
-


+


-
+
+


-
-
-

-
+







    wm geometry .t +30+40
    wm overrideredirect .t 1
    tkwait visibility .t
    wm geometry .t 5x8
    update
    list [winfo width .t] [winfo height .t]
} {1 72}
test unixWm-44.6 {UpdateGeometryInfo procedure, negative height} unix {
destroy .t
toplevel .t -width 80 -height 60
    destroy .t
    toplevel .t -width 80 -height 60
test unixWm-44.6 {UpdateGeometryInfo procedure, negative height} unix {
    wm grid .t 18 7 10 12
    wm geometry .t +30+40
    wm overrideredirect .t 1
    tkwait visibility .t
    wm geometry .t 20x1
    update
    list [winfo width .t] [winfo height .t]
} {100 1}

destroy .t
toplevel .t -width 80 -height 60
test unixWm-44.7 {UpdateGeometryInfo procedure, computing position} {unix} {
test unixWm-44.7 {UpdateGeometryInfo procedure, computing position} unix {
    wm geometry .t +5-10
    wm overrideredirect .t 1
    tkwait visibility .t
    update
    wm geometry .t +5-10
    update
    list [winfo x .t] [winfo y .t]
} [list 5 [expr [winfo screenheight .t] - 70]]

destroy .t
toplevel .t -width 80 -height 60
test unixWm-44.8 {UpdateGeometryInfo procedure, computing position} {unix} {
test unixWm-44.8 {UpdateGeometryInfo procedure, computing position} unix {
    wm geometry .t -30+2
    wm overrideredirect .t 1
    tkwait visibility .t
    update
    wm geometry .t -30+$Y2
    update
    list [winfo x .t] [winfo y .t]
} [list [expr [winfo screenwidth .t] - 110] $Y2]
} [list [expr [winfo screenwidth .t] - 110] 2]
destroy .t

test unixWm-44.9 {UpdateGeometryInfo procedure, updating fixed dimensions} {unix testwrapper} {
    destroy .t
    toplevel .t -width 80 -height 60
    wm resizable .t 0 0
    wm geometry .t +0+0
1744
1745
1746
1747
1748
1749
1750
1751

1752
1753
1754

1755
1756
1757
1758
1759
1760
1761
1698
1699
1700
1701
1702
1703
1704

1705
1706
1707

1708
1709
1710
1711
1712
1713
1714
1715







-
+


-
+







    list [catch {wm geometry .t +20-} msg] $msg
} {1 {bad geometry specifier "+20-"}}
test unixWm-48.10 {ParseGeometry procedure} unix {
    list [catch {wm geometry .t +20+10z} msg] $msg
} {1 {bad geometry specifier "+20+10z"}}
test unixWm-48.11 {ParseGeometry procedure} unix {
    catch {wm geometry .t +-10+20}
} 0
} {0}
test unixWm-48.12 {ParseGeometry procedure} unix {
    catch {wm geometry .t +30+-10}
} 0
} {0}
test unixWm-48.13 {ParseGeometry procedure, resize causes window to move} unix {
    destroy .t
    toplevel .t -width 200 -height 200
    wm geom .t +0+0
    update
    wm geom .t -0-0
    update
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
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







-
+
-
-
-
-
-
-
-
-
-
+
+

-
+

-
-
+
+


-


-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+


-
+
+

-
-
-
-
+

+

-
-

-



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
+

-
-

-
-
+
+


-
+
-
-
+
-
-
+

-
-
+
+
-
-
-
+
+
+
-
-
-
+
+
-
+



-
-
-
+
+
+
+


-
-
+

+

-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
















-
-
-
-
-
-
-
+
+
+
+
+
+
+







    testmenubar window .t .t.m
    update
    list [expr [winfo rootx .t.m.f] - $x] [expr [winfo rooty .t.m.f] - $y] \
	    [expr [winfo rootx .t.f] - $x] [expr [winfo rooty .t.f] - $y]
} {52 7 12 62}

deleteWindows
wm withdraw .
wm iconify .
if {[tk windowingsystem] eq "aqua"} {
    # Modern mac windows have no border.
    set result_50_1 {{} {} .t .t .t2 {} .t2 .t .t}
} else {
    # Windows are assumed to have a border (invisible in Gnome 3).
    set result_50_1 {{} {} .t {} .t2 {} .t2 {} .t}
}
test unixWm-50.1 {Tk_CoordsToWindow procedure, finding a toplevel, x-coords, title bar} {unix failsOnUbuntu failsOnXQuarz} {
    update
test unixWm-50.1 {Tk_CoordsToWindow procedure, finding a toplevel, x-coords} unix {
    deleteWindows
    toplevel .t -width 300 -height 400 -bg green
    wm geom .t +100+100
    wm geom .t +40+0
    tkwait visibility .t
    toplevel .t2 -width 100 -height 200 -bg red
    wm geom .t2 +200+200
    toplevel .t2 -width 100 -height 80 -bg red
    wm geom .t2 +140+200
    tkwait visibility .t2
    raise .t2
    update
    set x [winfo rootx .t]
    set y [winfo rooty .t]
    list [winfo containing [expr $x - 30]  [expr $y + 250]] \
	 [winfo containing [expr $x - 1]   [expr $y + 250]] \
	 [winfo containing $x              [expr $y + 250]] \
	 [winfo containing [expr $x + 99]  [expr $y + 250]] \
	 [winfo containing [expr $x + 100] [expr $y + 250]] \
    list [winfo containing [expr $x - 30] [expr $y + 250]] \
	    [winfo containing [expr $x - 1] [expr $y + 250]] \
	    [winfo containing $x [expr $y + 250]] \
	    [winfo containing [expr $x + 99] [expr $y + 250]] \
	    [winfo containing [expr $x + 100] [expr $y + 250]] \
	 [winfo containing [expr $x + 150] [expr $y + 90]] \
	 [winfo containing [expr $x + 199] [expr $y + 250]] \
	 [winfo containing [expr $x + 200] [expr $y + 250]] \
	 [winfo containing [expr $x + 220] [expr $y + 250]] \
} $result_50_1
	    [winfo containing [expr $x + 199] [expr $y + 250]] \
	    [winfo containing [expr $x + 200] [expr $y + 250]] \
	    [winfo containing [expr $x + 220] [expr $y + 250]]
} {{} {} .t {} .t2 .t2 {} .t}
test unixWm-50.2 {Tk_CoordsToWindow procedure, finding a toplevel, y-coords and overrideredirect} unix {
    deleteWindows
    toplevel .t -width 400 -height 300 -bg yellow
    toplevel .t -width 300 -height 400 -bg yellow
    wm geom .t +0+50
    tkwait visibility .t
    wm geom .t +100+100
    update
    restackDelay
    toplevel .t2 -width 200 -height 100 -bg blue
    toplevel .t2 -width 100 -height 80 -bg blue
    wm overrideredirect .t2 1
    wm geom .t2 +100+200
    tkwait visibility .t2
    wm geom .t2 +200+200
    update
    raise .t2
    restackDelay
    set x [winfo rootx .t]
    set y [winfo rooty .t]
    set y2 [winfo rooty .t2]
    list [winfo containing [expr $x +200] [expr $y - 30]] \
	 [winfo containing [expr $x +200] [expr $y - 1]] \
	 [winfo containing [expr $x +200] $y] \
	 [winfo containing [expr $x +200] [expr $y2 - 1]] \
	 [winfo containing [expr $x +200] $y2] \
	 [winfo containing [expr $x +200] [expr $y2 + 99]] \
	 [winfo containing [expr $x +200] [expr $y2 + 100]] \
	 [winfo containing [expr $x +200] [expr $y + 450]]
    list [winfo containing [expr $x +150] 10] \
	    [winfo containing [expr $x +150] [expr $y - 1]] \
	    [winfo containing [expr $x +150] $y] \
	    [winfo containing [expr $x +150] [expr $y2 - 1]] \
	    [winfo containing [expr $x +150] $y2] \
	    [winfo containing [expr $x +150] [expr $y2 + 79]] \
	    [winfo containing [expr $x +150] [expr $y2 + 80]] \
	    [winfo containing [expr $x +150] [expr $y + 450]]
} {{} {} .t .t .t2 .t2 .t {}}
test unixWm-50.3 {
	Tk_CoordsToWindow procedure, finding a toplevel with embedding
} tempNotWin {
} -constraints tempNotWin -setup {
    deleteWindows
    catch {interp delete child}

    toplevel .t -width 300 -height 400 -bg blue
    wm geom .t +100+100
    frame .t.f -container 1 -bg red
    wm geom .t +0+50
    frame .t.f -container 1
    place .t.f -x 150 -y 50
    tkwait visibility .t.f
    update
    setupbg
    interp create child
    load {} Tk child
} -body {
    child alias frameid winfo id .t.f
    child eval {
    dobg "
	wm withdraw .
        toplevel .x -width 100 -height 80 -use [frameid] -bg yellow
        tkwait visibility .x
	toplevel .x -width 100 -height 80 -use [winfo id .t.f] -bg yellow
	tkwait visibility .x"
        update
        set x [winfo rootx .x]
        set y [winfo rooty .x]
    set result [dobg {
	set x [winfo rootx .x]
	set y [winfo rooty .x]
    }
    set result [list [child eval {winfo containing [expr $x - 1]  [expr $y + 50]}] \
	[child eval {winfo containing $x [expr $y + 50]}]]
	list [winfo containing [expr $x - 1] [expr $y + 50]] \
		[winfo containing $x [expr $y +50]]
    interp delete child
    }]
    set x [winfo rootx .t]
    set y [winfo rooty .t]
    lappend result [winfo containing [expr $x + 200] [expr $y + 49]] \
	[winfo containing [expr $x + 200] [expr $y +50]]
    set result
} {{} .x .t .t.f}
		[winfo containing [expr $x + 200] [expr $y +50]]
} -cleanup {
    cleanupbg
} -result {{} .x .t .t.f}
test unixWm-50.4 {Tk_CoordsToWindow procedure, window in other application} unix {
    destroy .t

    catch {interp delete child}
    catch {interp delete slave}
    toplevel .t -width 200 -height 200 -bg green
    wm geometry .t +0+0
    tkwait visibility .t
    wm geometry .t +100+100
    update
    interp create child
    load {} Tk child
    child eval {wm geometry . 200x200+100+100; update}
    interp create slave
    load {} Tk slave
    slave eval {wm geometry . 200x200+0+0; tkwait visibility .}
    restackDelay
    set result [list [winfo containing 200 200] \
	    [child eval {winfo containing 200 200}]]
    interp delete child
    set result [list [winfo containing 100 100] \
	    [slave eval {winfo containing 100 100}]]
    interp delete slave
    set result
} {{} .}
test unixWm-50.5 {Tk_CoordsToWindow procedure, handling menubars} {unix testmenubar} {
    deleteWindows
    toplevel .t -width 300 -height 400 -bd 2 -relief raised
    frame .t.f -width 150 -height 120 -bg green
    place .t.f -x 10 -y 150
    wm geom .t +0+50
    frame .t.menu -width 100 -height 30 -bd 2 -relief raised
    frame .t.menu.f -width 40 -height 20 -bg purple
    place .t.menu.f -x 30 -y 10
    testmenubar window .t .t.menu
    tkwait visibility .t.menu
    update
    set x [winfo rootx .t]
    set y [winfo rooty .t]
    list [winfo containing $x             [expr $y - 31]] \
	 [winfo containing $x             [expr $y - 30]] \
	 [winfo containing [expr $x + 50] [expr $y - 19]] \
	 [winfo containing [expr $x + 50] [expr $y - 18]] \
	 [winfo containing [expr $x + 50] $y] \
	 [winfo containing [expr $x + 11] [expr $y + 152]] \
	 [winfo containing [expr $x + 12] [expr $y + 152]]
    list [winfo containing $x [expr $y - 31]] \
		[winfo containing $x [expr $y - 30]] \
		[winfo containing [expr $x + 50] [expr $y - 19]] \
		[winfo containing [expr $x + 50] [expr $y - 18]] \
		[winfo containing [expr $x + 50] $y] \
		[winfo containing [expr $x + 11] [expr $y + 152]] \
		[winfo containing [expr $x + 12] [expr $y + 152]]
} {{} .t.menu .t.menu .t.menu.f .t .t .t.f}
test unixWm-50.6 {Tk_CoordsToWindow procedure, embedding within one app.} unix {
    deleteWindows
    toplevel .t -width 300 -height 400 -bg orange
    wm geom .t +0+50
    frame .t.f -container 1
    place .t.f -x 150 -y 50
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
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







-
+





-
+







-
+


+

-
-

-
+

-
-

-
-
+


-









-


-
+







	    [winfo containing $x [expr $y + 250]] \
	    [winfo containing $x [expr $y + 350]] \
	    [winfo containing $x [expr $y + 450]]
} {.t .t.f .t.f.f .t {}}
test unixWm-50.8 {Tk_CoordsToWindow procedure, more basics} unix {
    destroy .t
    toplevel .t -width 400 -height 300 -bg green
    wm geom .t +0+30
    wm geom .t +0+0
    frame .t.f -width 200 -height 100 -bd 2 -relief raised
    place .t.f -x 100 -y 100
    frame .t.f.f -width 200 -height 100 -bd 2 -relief raised
    place .t.f.f -x 100 -y 0
    update
    set x [winfo rootx .t]
    set x [winfo rooty .t]
    set y [expr [winfo rooty .t] + 150]
    list [winfo containing [expr $x + 50] $y] \
	    [winfo containing [expr $x + 150] $y] \
	    [winfo containing [expr $x + 250] $y] \
	    [winfo containing [expr $x + 350] $y] \
	    [winfo containing [expr $x + 450] $y]
} {.t .t.f .t.f.f .t {}}
test unixWm-50.9 {Tk_CoordsToWindow procedure, unmapped windows} {unix failsOnUbuntu failsOnXQuarz} {
test unixWm-50.9 {Tk_CoordsToWindow procedure, unmapped windows} unix {
    destroy .t
    destroy .t2
    sleep 500		;# Give window manager time to catch up.
    toplevel .t -width 200 -height 200 -bg green
    tkwait visibility .t
    update
    wm geometry .t +0+0
    update
    tkwait visibility .t
    toplevel .t2 -width 200 -height 200 -bg red
    tkwait visibility .t2
    update
    wm geometry .t2 +0+0
    update
    restackDelay
    tkwait visibility .t2
    set result [list [winfo containing 100 100]]
    wm iconify .t2
    update
    lappend result [winfo containing 100 100]
} {.t2 .t}
test unixWm-50.10 {Tk_CoordsToWindow procedure, unmapped windows} unix {
    destroy .t
    toplevel .t -width 200 -height 200 -bg green
    wm geometry .t +0+0
    frame .t.f -width 150 -height 150 -bd 2 -relief raised
    place .t.f -x 25 -y 25
    tkwait visibility .t.f
    update idletasks
    set result [list [winfo containing 100 100]]
    place forget .t.f
    update idletasks
    update
    lappend result [winfo containing 100 100]
} {.t.f .t}
deleteWindows
wm deiconify .

# No tests for UpdateVRootGeometry, Tk_GetVRootGeometry,
# Tk_MoveToplevelWindow, UpdateWmProtocols, or TkWmProtocolEventProc.
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
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







+










+














+





-

-

-

-
-
+


-
+


-
+



-
-
+
-


-
+

-
+

-
-
-
+
+












-










-


-


-
-
-
-



-




-


-











-


-
-
-







    update
    raise .raise3
    raise .raise2
    raise .raise1 .raise3
    set result [winfo containing [winfo rootx .raise1] \
	    [winfo rooty .raise1]]
    destroy .raise2
    sleep 500
    list $result [winfo containing [winfo rootx .raise1] \
	    [winfo rooty .raise1]]
} {.raise2 .raise1}
test unixWm-51.4 {TkWmRestackToplevel procedure, basic tests} {unix nonPortable} {
    makeToplevels
    raise .raise2
    raise .raise1
    lower .raise3 .raise1
    set result [winfo containing 100 100]
    destroy .raise1
    sleep 500
    lappend result [winfo containing 100 100]
} {.raise1 .raise3}
test unixWm-51.5 {TkWmRestackToplevel procedure, basic tests} {unix nonPortable} {
    makeToplevels
    update
    raise .raise2
    raise .raise1
    raise .raise3
    frame .raise1.f1
    frame .raise1.f1.f2
    lower .raise3 .raise1.f1.f2
    set result [winfo containing [winfo rootx .raise1] \
	    [winfo rooty .raise1]]
    destroy .raise1
    sleep 500
    list $result [winfo containing [winfo rootx .raise2] \
	    [winfo rooty .raise2]]
} {.raise1 .raise3}
deleteWindows
test unixWm-51.6 {TkWmRestackToplevel procedure, window to be stacked isn't mapped} unix {
    wm geometry . +300+300
    destroy .t
    update idletasks
    toplevel .t -width 200 -height 200 -bg green
    tkwait visibility .t
    wm geometry .t +0+0
    update
    restackDelay
    tkwait visibility .t
    destroy .t2
    toplevel .t2 -width 200 -height 200 -bg red
    # This test assumes that .t2 is not mapped yet, but that is not really guaranteed.
    wm geometry .t2 +0+0
    winfo containing 100 100
} {.t}
test unixWm-51.7 {TkWmRestackToplevel procedure, other window isn't mapped} {unix failsOnXQuarz} {
test unixWm-51.7 {TkWmRestackToplevel procedure, other window isn't mapped} unix {
    foreach w {.t .t2 .t3} {
	destroy $w
	toplevel $w -width 200 -height 200 -bg green
	tkwait visibility $w
	wm geometry $w +100+100
	wm geometry $w +0+0
	update
    }
    raise .t .t2
    restackDelay
    sleep 2000
    update
    set result [list [winfo containing 200 200]]
    set result [list [winfo containing 100 100]]
    lower .t3
    restackDelay
    sleep 10
    lappend result [winfo containing 200 200]
    sleep 2000
    lappend result [winfo containing 100 100]
} {.t3 .t}
test unixWm-51.8 {TkWmRestackToplevel procedure, overrideredirect windows} unix {
    destroy .t
    toplevel .t -width 200 -height 200 -bg green
    wm overrideredirect .t 1
    wm geometry .t +0+0
    tkwait visibility .t
    destroy .t2
    toplevel .t2 -width 200 -height 200 -bg red
    wm overrideredirect .t2 1
    wm geometry .t2 +0+0
    tkwait visibility .t2
    restackDelay

    # Need to use vrootx and vrooty to make tests work correctly with
    # virtual root window measures managers: overrideredirect windows
    # come up at (0,0) in display coordinates, not virtual root
    # coordinates.

    set x [expr 100-[winfo vrootx .]]
    set y [expr 100-[winfo vrooty .]]
    set result [list [winfo containing $x $y]]
    raise .t
    restackDelay
    lappend result [winfo containing $x $y]
    raise .t2
    restackDelay
    lappend result [winfo containing $x $y]
} {.t2 .t .t2}
# The mac won't put an overrideredirect window above the root,
if {[tk windowingsystem] eq "aqua"} {
    wm withdraw .
}
test unixWm-51.9 {TkWmRestackToplevel procedure, other window overrideredirect} unix {
    foreach w {.t .t2 .t3} {
	destroy $w
	update
	toplevel $w -width 200 -height 200 -bg green
	wm overrideredirect $w 1
	wm geometry $w +0+0
	tkwait visibility $w
	update
    }
    lower .t3 .t2
    restackDelay
    update

    # Need to use vrootx and vrooty to make tests work correctly with
    # virtual root window measures managers: overrideredirect windows
    # come up at (0,0) in display coordinates, not virtual root
    # coordinates.

    set x [expr 100-[winfo vrootx .]]
    set y [expr 100-[winfo vrooty .]]
    set result [list [winfo containing $x $y]]
    lower .t2
    restackDelay
    lappend result [winfo containing $x $y]
} {.t2 .t3}
if {[tk windowingsystem] eq "aqua"} {
    wm deiconify .
}
test unixWm-51.10 {TkWmRestackToplevel procedure, don't move window that's already in the right place} unix {
    makeToplevels
    raise .raise1
    set time [lindex [time {raise .raise1}] 0]
    expr {$time < 2000000}
} 1
test unixWm-51.11 {TkWmRestackToplevel procedure, don't move window that's already in the right place} unix {
2268
2269
2270
2271
2272
2273
2274
2275

2276
2277
2278
2279
2280
2281
2282
2178
2179
2180
2181
2182
2183
2184

2185
2186
2187
2188
2189
2190
2191
2192







-
+







    .m add command -label Second
    .m add command -label Third
    .m post 30 30
    update
    set result [wm overrideredirect .m]
    destroy .m
    set result
} 1
} {1}

# No tests for TkGetPointerCoords, CreateWrapper, or GetMaxSize.

test unixWm-55.1 {TkUnixSetMenubar procedure} {unix testmenubar} {
    destroy .t
    toplevel .t -width 300 -height 200 -bd 2 -relief raised
    wm geom .t +0+0
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
2436
2437
2438
2439
2440
2441
2442







2443
2444
2445
2446

2447
2448
2449
2450
2451
2452
2453
2454







-
-
-
-
-
-
-




-
+








#
# wm attributes tests:
#
# NOTE: since [wm attributes] is not guaranteed to have any effect,
# the only thing we can really test here is the syntax.
#
if {[tk windowingsystem] eq "aqua"} {
    set match_60_1 glob
    set result_60_1 {-alpha 1.0 -appearance auto -buttons {close miniaturize zoom} -fullscreen 0 -isdark [01] -modified 0 -notify 0 -titlepath {} -topmost 0 -transparent 0 -stylemask {titled closable miniaturizable resizable} -class nswindow -tabbingid .t -tabbingmode auto -type unsupported}
} else {
    set match_60_1 exact
    set result_60_1 {-alpha 1.0 -fullscreen 0 -topmost 0 -type {} -zoomed 0}
}
test unixWm-60.1 {wm attributes - test} -constraints unix -body {
    destroy .t
    toplevel .t
    wm attributes .t
} -match $match_60_1 -result $result_60_1
} -result [list -alpha 1.0 -topmost 0 -zoomed 0 -fullscreen 0 -type {}]

test unixWm-60.2 {wm attributes - test} -constraints unix -body {
    destroy .t
    toplevel .t
    wm attributes .t -topmost
} -result 0

Changes to tests/util.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
1
2
3



4
5
6
7
8
9
10
11
12
13



-
-
-
+
+
+







# This file is a Tcl script to test out the procedures in the file
# tkUtil.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

24
25
26
27
28
29
30
31

32
33
34

35
36
37

38
39
40
41
42

43
44
45
46
47

48
49
50
51
52

53
54
55
56
57

58
59
60

61
62
63
64
65
66
67
68
24
25
26
27
28
29
30

31
32
33

34
35
36

37
38
39
40
41

42
43
44
45
46

47
48
49
50
51

52
53
54
55
56

57
58
59

60
61
62
63
64
65
66
67
68







-
+


-
+


-
+




-
+




-
+




-
+




-
+


-
+








test util-1.3 {Tk_GetScrollInfo procedure} -body {
    .l yview 0
    .l yview moveto .5
    .l yview
} -result {0.5 0.75}
test util-1.4 {Tk_GetScrollInfo procedure} -body {
    .l yview scroll a
} -returnCodes error -result {wrong # args: should be ".l yview scroll number pages|units"}
} -returnCodes error -result {wrong # args: should be ".l yview scroll number units|pages"}
test util-1.5 {Tk_GetScrollInfo procedure} -body {
    .l yview scroll a b c
} -returnCodes error -result {wrong # args: should be ".l yview scroll number pages|units"}
} -returnCodes error -result {wrong # args: should be ".l yview scroll number units|pages"}
test util-1.6 {Tk_GetScrollInfo procedure} -body {
    .l yview scroll xyz units
} -returnCodes error -result {expected floating-point number but got "xyz"}
} -returnCodes error -result {expected integer but got "xyz"}
test util-1.7 {Tk_GetScrollInfo procedure} -body {
    .l yview 0
    .l yview scroll 2 pages
    .l nearest 0
} -result 6
} -result {6}
test util-1.8 {Tk_GetScrollInfo procedure} -body {
    .l yview 15
    .l yview scroll -2 pages
    .l nearest 0
} -result 9
} -result {9}
test util-1.9 {Tk_GetScrollInfo procedure} -body {
    .l yview 0
    .l yview scroll 2 units
    .l nearest 0
} -result 2
} -result {2}
test util-1.10 {Tk_GetScrollInfo procedure} -body {
    .l yview 15
    .l yview scroll -2 units
    .l nearest 0
} -result 13
} -result {13}
test util-1.11 {Tk_GetScrollInfo procedure} -body {
    .l yview scroll 3 zips
} -returnCodes error -result {bad argument "zips": must be pages or units}
} -returnCodes error -result {bad argument "zips": must be units or pages}
test util-1.12 {Tk_GetScrollInfo procedure} -body {
    .l yview dropdead 3 times
} -returnCodes error -result {unknown option "dropdead": must be moveto or scroll}

# cleanup
cleanupTests
return

Changes to tests/visual.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
1
2
3
4



5
6
7
8
9
10
11
12
13
14




-
-
-
+
+
+







# This file is a Tcl script to test the visual- and colormap-handling
# procedures in the file tkVisual.c.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

25
26
27
28
29
30
31
32
33
34



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
25
26
27
28
29
30
31



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56
57
58
59
60
61







-
-
-
+
+
+


















-
-
+
+







    catch {destroy $w}
    toplevel $w
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
        for {set x 0} {$x < 40} {incr x} {
            set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
            $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
                [expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
            set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
            $w.c create rectangle [expr 10*$x] [expr 20*$y] \
                [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
                -fill $color
        }
    }
    update
}

# colorsFree --
#
# Returns 1 if there appear to be free colormap entries in a window,
# 0 otherwise.
#
# Arguments:
# w -            Name of window in which to check.
# red, green, blue -    Intensities to use in a trial color allocation
#            to see if there are colormap entries free.

proc colorsFree {w {red 31} {green 245} {blue 192}} {
    set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
    expr {([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green)
        && ([lindex $vals 2]/256 == $blue)}
    expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) \
        && ([lindex $vals 2]/256 == $blue)
}

# If more than one visual type is available for the screen, pick one
# that is *not* the default.

set default "[winfo visual .] [winfo depth .]"
set avail [winfo visualsavailable .]
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503

504
505
506
507
508
509
510
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510







-
+












-
+















-
+















-
+







    eatColors .t1
    toplevel .t2 -width 30 -height 20
    wm geom .t2 +0+0
    update
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result 0
} -result {0}
test visual-7.2 {Tk_GetColormap, "new"} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t2 -width 30 -height 20 -colormap new
    wm geom .t2 +0+0
    update
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result 1
} -result {1}
test visual-7.3 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t3 -width 400 -height 50 -colormap new
    wm geom .t3 +0+0
    toplevel .t2 -width 30 -height 20 -colormap .t3
    wm geom .t2 +0+0
    update
    destroy .t3
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result 1
} -result {1}
test visual-7.4 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    eatColors .t1
    toplevel .t3 -width 400 -height 50 -colormap new
    wm geom .t3 +0+0
    toplevel .t2 -width 30 -height 20 -colormap .
    wm geom .t2 +0+0
    update
    destroy .t3
    colorsFree .t2
} -cleanup {
    deleteWindows
} -result 0
} -result {0}
test visual-7.5 {Tk_GetColormap, copy from other window} -constraints {
    defaultPseudocolor8 nonPortable
} -setup {
    deleteWindows
} -body {
    toplevel .t1 -width 400 -height 50 -colormap .choke.lots
} -cleanup {

Changes to tests/visual_bb.test.

19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33







-
+








# Each menu entry invokes a visual test file

proc runTest {file} {
    global testNum

    test "2.$testNum" "testing $file" {userInteraction} {
    uplevel #0 [list source [file join [testsDirectory] $file]]
    uplevel \#0 source [file join [testsDirectory] $file]
    concat ""
    } {}
    incr testNum
}

# The following procedure is invoked to print the contents of a canvas:

90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116







-
+









-
+









    .menu.ps.m add command -label "Arcs" \
        -command {runTest canvPsArc.tcl}

    pack .menu.file .menu.group1 .menu.ps -side left -padx 1m

    # Set up for keyboard-based menu traversal

    bind . <FocusIn> {
    bind . <Any-FocusIn> {
    if {("%d" == "NotifyVirtual") && ("%m" == "NotifyNormal")} {
        focus .menu
    }
    }
    tk_menuBar .menu .menu.file .menu.group1 .menu.ps

    # Set up a class binding to allow objects to be deleted from a canvas
    # by clicking with mouse button 1:

    bind Canvas <Button-1> {%W delete [%W find closest %x %y]}
    bind Canvas <1> {%W delete [%W find closest %x %y]}

    concat ""
} -result {}

if {![testConstraint userInteraction]} {
    cleanupTests
} else {
    vwait EndOfVisualTests
}

Changes to tests/winButton.test.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15





-
-
-
+
+
+







# This file is a Tcl script to test the Windows specific behavior of
# labels, buttons, checkbuttons, and radiobuttons in Tk (i.e., all the
# widgets defined in tkWinButton.c).  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
imageInit

Changes to tests/winClipboard.test.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17



18
19

20
21
22
23
24
25
26








-
-
+
+







-
-
-
+
+
-







# This file is a Tcl script to test out Tk's Windows specific
# clipboard code.  It is organized in the standard fashion for Tcl
# tests.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-2000 Scriptics Corporation.
# Copyright (c) 1997 by Sun Microsystems, Inc.
# Copyright (c) 1998-2000 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test

#################################################################
# Note that some of these tests may fail if another application #
# is grabbing the clipboard (e.g. an X server, or a VNC viewer) #
# Note that these tests may fail if another application is grabbing the
# clipboard (e.g. an X server)
#################################################################

test winClipboard-1.1 {TkSelGetSelection} -constraints win -setup {
    clipboard clear
} -body {
    selection get -selection CLIPBOARD
} -cleanup {
    clipboard clear
66
67
68
69
70
71
72
73

74
75
76
77
78

79
80
81
82
83
84
85

86
87
88
89


90
91
92
93
94
95
96
64
65
66
67
68
69
70

71
72
73
74
75

76
77
78
79
80
81
82

83
84
85
86

87
88
89
90
91
92
93
94
95







-
+




-
+






-
+



-
+
+








test winClipboard-1.5 {TkSelGetSelection & TkWinClipboardRender} -constraints {
    win testclipboard
} -setup {
    clipboard clear
} -body {
    set map [list "\r" "\\r" "\n" "\\n"]
    clipboard append "line 1Ç\nline 2"
    clipboard append "line 1\u00c7\nline 2"
    list [string map $map [selection get -selection CLIPBOARD]]\
        [string map $map [testclipboard]]
} -cleanup {
    clipboard clear
} -result [list "line 1Ç\\nline 2" "line 1Ç\\nline 2"]
} -result [list "line 1\u00c7\\nline 2" "line 1\u00c7\\nline 2"]

test winClipboard-1.6 {TkSelGetSelection & TkWinClipboardRender} -constraints {
    win testclipboard
} -setup {
    clipboard clear
} -body {
    clipboard append "привет миф"
    clipboard append "\u043f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0444"
    list [selection get -selection CLIPBOARD] [testclipboard]
} -cleanup {
    clipboard clear
} -result [list "привет миф" "привет миф"]
} -result [list "\u043f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0444"\
              "\u043f\u0440\u0438\u0432\u0435\u0442 \u043c\u0438\u0444"]

test winClipboard-2.1 {TkSelUpdateClipboard reentrancy problem} -constraints {
    win testclipboard
} -setup {
    clipboard clear
} -body {
    clipboard append -type OUR_ACTION "action data"

Changes to tests/winDialog.test.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5



6
7
8
9
10
11
12
13
14
15
16
17
18


19
20
21
22
23
24
25





-
-
-
+
+
+










-
-







# -*- tcl -*-
# This file is a Tcl script to test the Windows specific behavior of
# the common dialog boxes.  It is organized in the standard
# fashion for Tcl tests.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright © 1998-1999 ActiveState Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Copyright (c) 1998-1999 ActiveState Corporation.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

if {[testConstraint testwinevent]} {
    catch {testwinevent debug 1}
}

testConstraint tcl8 [package vsatisfies [package provide Tcl] 8]

# Locale identifier LANG_ENGLISH is 0x09
testConstraint english [expr {
    [llength [info commands testwinlocale]]
    && (([testwinlocale] & 0xff) == 9)
}]

proc vista? {{prevista 0} {postvista 1}} {
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128







-
+







test winDialog-1.1 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    start {tk_chooseColor}
    then {
        Click cancel
    }
} -result 0
} -result {0}
test winDialog-1.2 {Tk_ChooseColorObjCmd} -constraints {
    testwinevent
} -body {
    start {set clr [tk_chooseColor -initialcolor "#ff9933"]}
    then {
        set x [Click cancel]
    }
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181







-
+









-
+







    testwinevent
} -setup {
    catch {unset a x}
} -body {
    set x {}
    start {
        set clr [tk_chooseColor -initialcolor "#ff9933" \
                     -title "Привет"]
                     -title "\u041f\u0440\u0438\u0432\u0435\u0442"]
    }
    then {
        if {[catch {
            array set a [testgetwindowinfo $::tk_dialog]
            if {[info exists a(text)]} {lappend x $a(text)}
        } err]} { lappend x $err }
        lappend x [Click ok]
    }
    lappend x $clr
} -result [list "Привет" 0 "#ff9933"]
} -result [list "\u041f\u0440\u0438\u0432\u0435\u0442" 0 "#ff9933"]
test winDialog-1.6 {Tk_ChooseColorObjCmd: -parent} -constraints {
    testwinevent
} -setup {
    catch {unset a x}
} -body {
    start {set clr [tk_chooseColor -initialcolor "#ff9933" -parent .]}
    set x {}
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261

262
263
264

265
266
267
268
269
270
271
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260
261

262
263
264
265
266
267
268
269







-
+












-
+













-
+


-
+







test winDialog-5.1 {GetFileName: no arguments} -constraints {
    nt testwinevent
} -body {
    start {tk_getOpenFile -title Open}
    then {
        Click cancel
    }
} -result 0
} -result {0}
test winDialog-5.2 {GetFileName: one argument} -constraints {
    nt
} -body {
    tk_getOpenFile -foo
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.3 {GetFileName: many arguments} -constraints {
    nt testwinevent
} -body {
    start {tk_getOpenFile -initialdir [initialdir] -parent . -title test -initialfile foo}
    then {
        Click cancel
    }
} -result 0
} -result {0}
test winDialog-5.4 {GetFileName: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_getOpenFile -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -defaultextension, -filetypes, -initialdir, -initialfile, -multiple, -parent, -title, or -typevariable}
test winDialog-5.5 {GetFileName: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getOpenFile -title bar]}
    set y [then {
        Click cancel
    }]
    # Note this also tests fix for
    # https://core.tcl-lang.org/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
    # http://core.tcl.tk/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
    # $x is expected to be empty
    append x $y
} -result 0
} -result {0}
test winDialog-5.6 {GetFileName: valid option, but missing value} -constraints {
    nt
} -body {
    tk_getOpenFile -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}

test winDialog-5.7 {GetFileName: extension begins with .} -constraints {
374
375
376
377
378
379
380
381
382


383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400

401
402

403
404
405
406
407
408
409

410
411
412
413
414
415

416
417

418
419

420
421
422
423
424

425
426
427
428
429
430
431
372
373
374
375
376
377
378


379
380
381
382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397

398
399

400
401
402
403
404
405
406

407
408
409
410
411
412

413
414

415
416

417
418
419
420
421

422
423
424
425
426
427
428
429







-
-
+
+











-
+





-
+

-
+






-
+





-
+

-
+

-
+




-
+







    unset msg
} -result bar.c


test winDialog-5.7.6 {GetFileName: All/extension } -constraints {
    nt testwinevent
} -body {
    # In 8.6.4 this combination resulted in bar.aaa.aaa which is bad
    start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {aaa} -title Save]}
    # In 8.6.4 this combination resulted in bar.ext.ext which is bad
    start {set x [tk_getSaveFile -filetypes {{All *}} -defaultextension {ext} -title Save]}
    set msg {}
    then {
	if {[catch {SetText [vista? 0x47C 0x3e9] bar} msg]} {
	    Click cancel
	} else {
	    Click ok
	}
    }
    set x "[file tail $x]$msg"
} -cleanup {
    unset msg
} -result bar.aaa
} -result bar.ext

test winDialog-5.7.7 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 7.aaa" [initialdir]
    tcltest::makeFile "" "5 7 7.ext" [initialdir]
    start {set x [tk_getOpenFile \
                      -defaultextension aaa \
                      -defaultextension ext \
                      -initialdir [file nativename [initialdir]] \
                      -initialfile "5 7 7" -title Foo]}
    then {
        Click ok
    }
    return $x
} -result [file join [initialdir] "5 7 7.aaa"]
} -result [file join [initialdir] "5 7 7.ext"]

test winDialog-5.7.8 {tk_getOpenFile: -defaultextension} -constraints {
    nt testwinevent
} -body {
    unset -nocomplain x
    tcltest::makeFile "" "5 7 8.aaa" [initialdir]
    tcltest::makeFile "" "5 7 8.ext" [initialdir]
    start {set x [tk_getOpenFile \
                      -defaultextension aaa \
                      -defaultextension ext \
                      -initialdir [file nativename [initialdir]] \
                      -initialfile "5 7 8.aaa" -title Foo]}
                      -initialfile "5 7 8.ext" -title Foo]}
    then {
        Click ok
    }
    return $x
} -result [file join [initialdir] "5 7 8.aaa"]
} -result [file join [initialdir] "5 7 8.ext"]

test winDialog-5.8 {GetFileName: extension doesn't begin with .} -constraints {
    nt testwinevent
} -body {
    start {set x [tk_getSaveFile -defaultextension foo -title Save]}
    set msg {}
    then {
479
480
481
482
483
484
485
486

487


488
489
490
491
492

493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512







-
+

+
+




-
+












-
+







    then {
        Click ok
    }
    return $x
} -result [file join [initialdir] "12x 455"]

test winDialog-5.12 {GetFileName: initial directory: Tcl_TranslateFilename()} -constraints {
    nt tcl8
    nt
} -body {
#        if (Tcl_TranslateFileName(interp, string, &ds) == NULL)

    tk_getOpenFile -initialdir ~12x/455
} -returnCodes error -result {user "12x" doesn't exist}

test winDialog-5.12.1 {tk_getSaveFile: initial directory: ~} -constraints {
    nt testwinevent tcl8
    nt testwinevent
} -body {
    unset -nocomplain x
    start {set x [tk_getSaveFile \
                      -initialdir ~ \
                      -initialfile "5 12 1" -title Foo]}
    then {
        Click ok
    }
    return $x
} -result [file normalize [file join ~ "5 12 1"]]

test winDialog-5.12.2 {tk_getSaveFile: initial directory: ~user} -constraints {
    nt testwinevent tcl8
    nt testwinevent
} -body {

    # Note: this test will fail on Tcl versions 8.6.4 and earlier due
    # to a bug in file normalize for names of the form ~xxx that
    # returns the wrong dir on Windows.  In particular (in Win8 at
    # least) it returned /users/Default instead of /users/USERNAME...

541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
541
542
543
544
545
546
547

548
549
550
551
552
553
554
555







-
+







    }
    string equal $x [file join $newdir testfile]
} -result 1

test winDialog-5.12.4 {tk_getSaveFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    set dir [tcltest::makeDirectory "\u0167\u00e9\u015d\u0167"]
    unset -nocomplain x
    start {set x [tk_getSaveFile \
                      -initialdir $dir \
                      -initialfile "testfile" -title Foo]}
    then {
        Click ok
    }
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
587
588
589
590
591
592
593

594












595
596
597
598
599
600
601
602
603
604
605




606
607
608
609
610
611
612







-
+
-
-
-
-
-
-
-
-
-
-
-
-
+










-
-
-
-







        }
    } finally {
        cd $cur
    }
    string equal $x [file join $dir testfile]
} -result 1

test winDialog-5.12.7 {tk_getOpenFile: initial directory: ~} -setup {
test winDialog-5.12.7 {tk_getOpenFile: initial directory: ~} -constraints {
    # Ensure there's at least one file in the home directory in CI environments
    set makeEmpty [expr {![llength [glob -nocomplain -type f -directory ~ *]]}]
    if {$makeEmpty} {
	for {set i 1} {$i < 1000} {incr i} {
	    # Technically a race condition...
	    set actualFilename [format "~/tkWinDialog5_12_7_%03d" $i]
	    if {![file exists $actualFilename]} break
	}
	close [open $actualFilename w]
    }
} -constraints {
    nt testwinevent tcl8
    nt testwinevent
} -body {
    set fn [file tail [lindex [glob -types f ~/*] 0]]
    unset -nocomplain x
    start {set x [tk_getOpenFile \
                      -initialdir ~ \
                      -initialfile $fn -title Foo]}
    then {
        Click ok
    }
    string equal $x [file normalize [file join ~ $fn]]
} -cleanup {
    if {$makeEmpty} {
	file delete $actualFilename
    }
} -result 1

test winDialog-5.12.8 {tk_getOpenFile: initial directory: .} -constraints {
    nt testwinevent
} -body {
    # Windows remembers dirs from previous selections so use
    # a subdir for this test, not [initialdir] itself
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
627
628
629
630
631
632
633

634
635
636
637
638
639
640
641







-
+







    }
    string equal $x $path
} -result 1

test winDialog-5.12.9 {tk_getOpenFile: initial directory: unicode} -constraints {
    nt testwinevent
} -body {
    set dir [tcltest::makeDirectory "ŧéŝŧ"]
    set dir [tcltest::makeDirectory "\u0167\u00e9\u015d\u0167"]
    set path [tcltest::makeFile "" testfile $dir]
    unset -nocomplain x
    start {set x [tk_getOpenFile \
                      -initialdir $dir \
                      -initialfile "testfile" -title Foo]}
    then {
        Click ok
703
704
705
706
707
708
709
710

711
712
713
714
715
716
717
688
689
690
691
692
693
694

695
696
697
698
699
700
701
702







-
+







    start {set x [tk_getSaveFile -initialfile "12x 456" -title Foo]}
    then {
        Click ok
    }
    file tail $x
} -result "12x 456"
test winDialog-5.14 {GetFileName: initial file: Tcl_TranslateFileName()} -constraints {
    nt tcl8
    nt
} -body {
#        if (Tcl_TranslateFileName(interp, string, &ds) == NULL)
    tk_getOpenFile -initialfile ~12x/455
} -returnCodes error -result {user "12x" doesn't exist}
if {![vista?]} {
    # XXX - disabled for Vista because the new dialogs allow long file
    # names to be specified but force the user to change it.
737
738
739
740
741
742
743
744

745
746
747
748
749
750
751
752
753
754

755
756
757
758
759
760
761
722
723
724
725
726
727
728

729
730
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746







-
+









-
+







    toplevel .t
    set x 0
    start {tk_getOpenFile -parent .t -title Parent; set x 1}
    then {
        destroy .t
    }
    return $x
} -result 1
} -result {1}
test winDialog-5.17 {GetFileName: title} -constraints {
    nt testwinevent
} -body {
#        case FILE_TITLE:

    start {tk_getOpenFile -title Narf}
    then {
        Click cancel
    }
} -result 0
} -result {0}
if {[vista?]} {
    # In the newer file dialogs, the file type widget does not even exist
    # if no file types specified
    test winDialog-5.18 {GetFileName: no filter specified} -constraints {
        nt testwinevent
    } -body {
        #    if (ofn.lpstrFilter == NULL)
852
853
854
855
856
857
858
859

860
861
862
863
864
865

866
867
868
869
870

871
872
873
874
875
876
877
837
838
839
840
841
842
843

844
845
846
847
848
849

850
851
852
853
854

855
856
857
858
859
860
861
862







-
+





-
+




-
+







    # MacOS type that is correct, but has embedded nulls.

    start {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {\0\0\0\0}}}}]}
    then {
        Click cancel
    }
    return $x
} -result 0
} -result {0}
test winDialog-5.25 {GetFileName: file types: MakeFilter() succeeds} -constraints {
    nt
} -body {
    # MacOS type that is correct, but has embedded high-bit chars.

    start {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {••••}}}}]}
    start {set x [catch {tk_getSaveFile -filetypes {{"foo" .foo {\u2022\u2022\u2022\u2022}}}}]}
    then {
        Click cancel
    }
    return $x
} -result 0
} -result {0}


test winDialog-6.1 {MakeFilter} -constraints {emptyTest nt} -body {}


test winDialog-7.1 {Tk_MessageBoxObjCmd} -constraints {emptyTest nt} -body {}

888
889
890
891
892
893
894
895

896
897
898
899
900
901
902
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921
922
923

924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

942
943
944
945
946
947
948
873
874
875
876
877
878
879

880
881
882
883
884
885
886
887
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902
903
904
905
906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925

926
927
928
929
930
931
932
933







-
+














-
+












-
+

















-
+







} -body {
    start {set x [tk_chooseDirectory]}
    set y [then {
        Click cancel
    }]
    # $x should be "" on a Cancel
    append x $y
} -result 0
} -result {0}
test winDialog-9.2 {Tk_ChooseDirectoryObjCmd: one argument} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.3 {Tk_ChooseDirectoryObjCmd: many arguments} -constraints {
    nt testwinevent
} -body {
    start {
        tk_chooseDirectory -initialdir [initialdir] -mustexist 1 -parent . -title test
    }
    then {
        Click cancel
    }
} -result 0
} -result {0}
test winDialog-9.4 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() != TCL_OK} -constraints {
    nt
} -body {
    tk_chooseDirectory -foo bar -abc
} -returnCodes error -result {bad option "-foo": must be -initialdir, -mustexist, -parent, or -title}
test winDialog-9.5 {Tk_ChooseDirectoryObjCmd: Tcl_GetIndexFromObj() == TCL_OK} -constraints {
    nt testwinevent
} -body {
    start {tk_chooseDirectory -title bar}
    then {
        Click cancel
    }
} -result 0
} -result {0}
test winDialog-9.6 {Tk_ChooseDirectoryObjCmd: valid option, but missing value} -constraints {
    nt
} -body {
    tk_chooseDirectory -initialdir bar -title
} -returnCodes error -result {value for "-title" missing}
test winDialog-9.7 {Tk_ChooseDirectoryObjCmd: -initialdir} -constraints {
    nt testwinevent
} -body {
#        case DIR_INITIAL:

    start {set x [tk_chooseDirectory -initialdir [initialdir] -title Foo]}
    then {
        Click ok
    }
    string tolower [set x]
} -result [string tolower [initialdir]]
test winDialog-9.8 {Tk_ChooseDirectoryObjCmd: initial directory: Tcl_TranslateFilename()} -constraints {
    nt tcl8
    nt
} -body {
#        if (Tcl_TranslateFileName(interp, string,
#            &utfDirString) == NULL)

    tk_chooseDirectory -initialdir ~12x/455
} -returnCodes error -result {user "12x" doesn't exist}

1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057







-
+







-
+













test winDialog-10.9 {Tk_FontchooserObjCmd: -title} -constraints {
    nt testwinevent
} -setup {
    array set a {text failed}
} -body {
    start {
        tk fontchooser configure -command ApplyFont \
            -title  "Привет"
            -title  "\u041f\u0440\u0438\u0432\u0435\u0442"
        tk fontchooser show
    }
    then {
        array set a [testgetwindowinfo $::tk_dialog]
        Click cancel
    }
    set a(text)
} -result "Привет"
} -result "\u041f\u0440\u0438\u0432\u0435\u0442"

if {[testConstraint testwinevent]} {
    catch {testwinevent debug 0}
}

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winFont.test.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17








-
-
+
+







# This file is a Tcl script to test out the procedures in tkWinFont.c.
# It is organized in the standard fashion for Tcl tests.
#
# Many of these tests are visually oriented and cannot be checked
# programmatically (such as "does an underlined font appear to be
# underlined?"); these tests attempt to exercise the code in question,
# but there are no results that can be checked.
#
# Copyright © 1996-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

33
34
35
36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
33
34
35
36
37
38
39

40
41
42
43
44

45
46
47
48
49
50
51
52







-
+




-
+







} -result {}


test winfont-2.1 {TkpGetFontFromAttributes procedure: pointsize} -constraints {
    win
} -body {
    expr {[font actual {-size -10} -size] > 0}
} -result 1
} -result {1}
test winfont-2.2 {TkpGetFontFromAttributes procedure: pointsize} -constraints {
    win
} -body {
    expr {[font actual {-family Arial} -size] > 0}
} -result 1
} -result {1}
test winfont-2.3 {TkpGetFontFromAttributes procedure: normal weight} -constraints {
    win
} -body {
    font actual {-weight normal} -weight
} -result {normal}
test winfont-2.4 {TkpGetFontFromAttributes procedure: bold weight} -constraints {
    win
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99







-
+








-
+







    win
} -setup {
    set x {}
} -body {
    lappend x [font actual {-family "Courier"} -family]
    lappend x [font actual {-family "Monaco"} -family]
    lappend x [font actual {-family "Courier New"} -family]
} -match regexp -result {Courier (Courier|Monaco) {Courier New}}
} -result {Courier Courier {Courier New}}
test winfont-2.9 {TkpGetFontFromAttributes procedure: Helvetica fonts} -constraints {
    win
} -setup {
    set x {}
} -body {
    lappend x [font actual {-family "Helvetica"} -family]
    lappend x [font actual {-family "Geneva"} -family]
    lappend x [font actual {-family "Arial"} -family]
} -match regexp -result {Helvetica (Helvetica|Geneva) Arial}
} -result {Helvetica Helvetica Arial}
test winfont-2.10 {TkpGetFontFromAttributes procedure: fallback} -constraints {
    win
} -body {
    # No way to get it to fail! Any font name is acceptable.
} -result {}


176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224

225
226
227
228
229
230
231
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

221
222
223

224
225
226
227
228
229
230
231







-
+


















-
+


















-
+


-
+







    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*10}] -text "00000000"
    .t.l config -wrap [expr $ax*10] -text "00000000"
    list [expr {[winfo reqwidth .t.l] eq 8*$ax}] \
        [expr {[winfo reqheight .t.l] eq $ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.4 {Tk_MeasureChars procedure: not all chars fit} -constraints {
    win
} -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*6}] -text "00000000"
    .t.l config -wrap [expr $ax*6] -text "00000000"
    list [expr {[winfo reqwidth .t.l] eq 6*$ax}] \
        [expr {[winfo reqheight .t.l] eq 2*$ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.5 {Tk_MeasureChars procedure: include last partial char} -constraints {
    win
} -setup {
    destroy .t.c
}  -body {
    canvas .t.c -closeenough 0
    set t [.t.c create text 0 0 -anchor nw -just left -font $courier]
    pack .t.c
    update

    .t.c dchars $t 0 end
    .t.c insert $t 0 "0000"
    .t.c index $t @[expr {int($cx*2.5)}],1
    .t.c index $t @[expr int($cx*2.5)],1
} -cleanup {
    destroy .t.c
} -result 2
} -result {2}

test winfont-5.6 {Tk_MeasureChars procedure: at least one char on line} -constraints {
    win
} -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321







-
+


















-
+


















-
+


















-
+







    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*8}] -text "000000 0000"
    .t.l config -wrap [expr $ax*8] -text "000000 0000"
    list [expr {[winfo reqwidth .t.l] eq 6*$ax}] \
        [expr {[winfo reqheight .t.l] eq 2*$ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.8 {Tk_MeasureChars procedure: already saw space in line} -constraints {
    win
} -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*12}] -text "000000    0000000"
    .t.l config -wrap [expr $ax*12] -text "000000    0000000"
    list [expr {[winfo reqwidth .t.l] eq 7*$ax}] \
        [expr {[winfo reqheight .t.l] eq 2*$ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.9 {Tk_MeasureChars procedure: internal spaces significant} -constraints {
    win
} -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*12}] -text "000  00   00000"
    .t.l config -wrap [expr $ax*12] -text "000  00   00000"
    list [expr {[winfo reqwidth .t.l] eq 7*$ax}] \
        [expr {[winfo reqheight .t.l] eq 2*$ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.10 {Tk_MeasureChars procedure: make first part of word fit} -constraints {
    win
} -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    set ax [winfo reqwidth .t.l]
    set ay [winfo reqheight .t.l]

    .t.l config -wrap [expr {$ax*12}] -text "0000000000000000"
    .t.l config -wrap [expr $ax*12] -text "0000000000000000"
    list [expr {[winfo reqwidth .t.l] eq 12*$ax}] \
        [expr {[winfo reqheight .t.l] eq 2*$ay}]
} -cleanup {
    destroy .t.l
} -result {1 1}

test winfont-5.11 {Tk_MeasureChars procedure: check for kerning} -constraints {
330
331
332
333
334
335
336
337

338
339
340

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374

375
376
377
378
379


380
381
382
383

384
385
386
387
388
389
390
391
392
330
331
332
333
334
335
336

337
338
339

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368

369
370
371
372
373

374
375
376
377


378
379
380
381
382

383
384
385
386
387
388
389
390
391
392







-
+


-
+
















-
+











-
+




-
+



-
-
+
+



-
+










    set font [.t.l cget -font]
    .t.l config -font {{MS Sans Serif} 8} -text "W"
    set width [winfo reqwidth .t.l]
    .t.l config -text "XaYoYaKaWx"
    set x [lindex [getsize] 0]
    .t.l config -font $font
    expr {$x < ($width*10)}
    expr $x < ($width*10)
} -cleanup {
    destroy .t.l
} -result 1
} -result {1}


test winfont-6.1 {Tk_DrawChars procedure: loop test} -constraints win -setup {
    destroy .t.l
}  -body {
    label .t.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left \
        -text "0" -font systemfixed
    pack .t.l
    update
    .t.l config -text "a"
    update
} -cleanup {
    destroy .t.l
} -result {}


test winfont-7.1 {InitFont procedure: use old font} -constraints win -setup {
test winfont-7.1 {AllocFont procedure: use old font} -constraints win -setup {
    destroy .c
} -setup {
    catch {font delete xyz}
} -body {
    font create xyz
    button .c -font xyz
    font configure xyz -family times
    update
    destroy .c
    font delete xyz
} -result {}
test winfont-7.2 {InitFont procedure: extract info from logfont} -constraints {
test winfont-7.2 {AllocFont procedure: extract info from logfont} -constraints {
    win
} -body {
    font actual {arial 10 bold italic underline overstrike}
} -result {-family Arial -size 10 -weight bold -slant italic -underline 1 -overstrike 1}
test winfont-7.3 {InitFont procedure: extract info from textmetric} -constraints {
test winfont-7.3 {AllocFont procedure: extract info from textmetric} -constraints {
    win
} -body {
    font metric {arial 10 bold italic underline overstrike} -fixed
} -result 0
test winfont-7.4 {InitFont procedure: extract info from textmetric} -constraints {
} -result {0}
test winfont-7.4 {AllocFont procedure: extract info from textmetric} -constraints {
    win
} -body {
    font metric systemfixed -fixed
} -result 1
} -result {1}

# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winMenu.test.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







# This file is a Tcl script to test menus in Tk.  It is
# organized in the standard fashion for Tcl tests. This
# file tests the Macintosh-specific features of the menu
# system.
#
# Copyright © 1995-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

89
90
91
92
93
94
95
96

97
98
99
100
101
102

103
104
105
106
107
108

109
110
111
112
113
114

115
116
117
118
119
120

121
122
123
124
125
126

127
128
129
130
131
132

133
134
135
136
137
138

139
140
141
142
143
144

145
146
147
148
149
150

151
152
153
154
155
156

157
158
159
160
161
162

163
164
165
166
167
168

169
170
171
172
173
174

175
176
177
178
179
180

181
182
183
184
185
186
187
89
90
91
92
93
94
95

96
97
98
99
100
101

102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119

120
121
122
123
124
125

126
127
128
129
130
131

132
133
134
135
136
137

138
139
140
141
142
143

144
145
146
147
148
149

150
151
152
153
154
155

156
157
158
159
160
161

162
163
164
165
166
167

168
169
170
171
172
173

174
175
176
177
178
179

180
181
182
183
184
185
186
187







-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+





-
+







} -setup {
    destroy .m1
} -body {
    catch {image delete image1}
    menu .m1
    image create test image1
    list [catch {.m1 add command -image image1} msg] $msg [destroy .m1] [image delete image1]
} -result {0 e001 {} {}}
} -result {0 {} {} {}}
test winMenu-6.3 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -bitmap questhead} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.4 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.5 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "foo"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.6 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "This string has one & in it"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.7 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The & should be underlined." -underline 4} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.8 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The * should be underlined." -underline 4} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.9 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "foo" -accel "bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.10 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "This string has one & in it" -accel "bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.11 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The & should be underlined." -underline 4 -accel "bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.12 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The * should be underlined." -underline 4 -accel "bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.13 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "foo" -accel "&bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.14 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "This string has one & in it" -accel "&bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.15 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The & should be underlined." -underline 4 -accel "&bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}
test winMenu-6.16 {GetEntryText} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command -label "The * should be underlined." -underline 4 -accel "&bar"} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}

test winMenu-7.1 {ReconfigureWindowsMenu - system menu item removal} -constraints {
    win
} -setup {
    destroy .m1
} -body {
    menu .m1
423
424
425
426
427
428
429
430

431
432
433
434
435
436
437
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437







-
+









test winMenu-9.1 {TkpMenuNewEntry} -constraints win -setup {
    destroy .m1
} -body {
    menu .m1
    list [catch {.m1 add command} msg] $msg [destroy .m1]
} -result {0 e001 {}}
} -result {0 {} {}}


test winMenu-10.1 {TkwinMenuProc} -constraints {
    win userInteraction
} -setup {
    destroy .m1
} -body {
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572







-
+







    menu .m1 -tearoff 0
    .m1 add command -label foo
    update idletasks
    list [catch {. configure -menu .m1} msg] $msg [. configure -menu ""] [destroy .m1]
} -result {0 {} {} {}}


test winMenu-13.1 {Tk_SetMainMenubar - nothing to do} -constraints {
test winMenu-13.1 {TkpSetMainMenubar - nothing to do} -constraints {
    emptyTest win
} -body {}


test winMenu-14.1 {GetMenuIndicatorGeometry} -constraints win -setup {
    destroy .m1
} -body {
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
855
856
857
858
859
860
861

862
863
864
865
866
867
868
869
870
871

872
873
874
875
876
877
878
879







-
+









-
+







    win
} -setup {
    destroy .m1
} -body {
    menu .m1 -tearoff 0
    .m1 add command -label Hello
    list [catch {.m1 add command -label Two} msg] $msg [destroy .m1]
} -result {0 e002 {}}
} -result {0 {} {}}
test winMenu-28.2 {TkpConfigureMenuEntry - update not pending} -constraints {
    win
} -setup {
    destroy .m1
} -body {
    menu .m1 -tearoff 0
    .m1 add command -label One
    update idletasks
    list [catch {.m1 add command -label Two} msg] $msg [destroy .m1]
} -result {0 e002 {}}
} -result {0 {} {}}


test winMenu-29.1 {TkpDrawMenuEntry - gc for active and not strict motif} -constraints {
    win
} -setup {
    destroy .m1
} -body {

Changes to tests/winMsgbox.test.

1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







# This file is a Tcl script to test the Windows specific message box
#
# Copyright © 2007 Pat Thoyts <[email protected]>
# Copyright (c) 2007 Pat Thoyts <[email protected]>

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

testConstraint getwindowinfo [expr {[llength [info command ::testgetwindowinfo]] > 0}]
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234

235
236
237
238
239
240
241
220
221
222
223
224
225
226

227
228
229
230
231
232
233

234
235
236
237
238
239
240
241







-
+






-
+







    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-2.2 [pid]"
    set message "Поиск страниц"
    set message "\u041f\u043e\u0438\u0441\u043a\u0020\u0441\u0442\u0440\u0430\u043d\u0438\u0446"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "Поиск страниц"]
} -result [list ok "\u041f\u043e\u0438\u0441\u043a\u0020\u0441\u0442\u0440\u0430\u043d\u0438\u0446"]

test winMsgbox-2.4 {tk_messageBox message (empty)} -constraints {
    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
272
273
274
275
276
277
278
279
280


281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
298
299
300
272
273
274
275
276
277
278


279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300







-
-
+
+






-
+













    win getwindowinfo
} -setup {
    wm iconify .
    unset -nocomplain info
} -body {
    global windowInfo
    set title "winMsgbox-3.1 [pid]"
    set message "Поиск"
    set detail "страниц"
    set message "\u041f\u043e\u0438\u0441\u043a"
    set detail "\u0441\u0442\u0440\u0430\u043d\u0438\u0446"
    after 100 [list GetWindowInfo $title 2]
    set r [tk_messageBox -type ok -title $title -message $message -detail $detail]
    array set info $windowInfo
    lappend r $info(childtext)
} -cleanup {
    wm deiconify .
} -result [list ok "Поиск\n\nстраниц"]
} -result [list ok "\u041f\u043e\u0438\u0441\u043a\n\n\u0441\u0442\u0440\u0430\u043d\u0438\u0446"]

# -------------------------------------------------------------------------

if {[testConstraint testwinevent]} {
    catch {testwinevent debug 0}
}
cleanupTests
return

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:

Changes to tests/winSend.test.

1
2
3
4
5
6
7



8
9
10

11
12
13
14
15
16
17
1
2
3
4



5
6
7
8
9

10
11
12
13
14
15
16
17




-
-
-
+
+
+


-
+







# This file is a Tcl script to test out the "send" command and the
# other procedures in the file tkSend.c.  It is organized in the
# standard fashion for Tcl tests.
#
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1994-1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

# Compute a script that will load Tk into a child interpreter.

foreach pkg [info loaded] {
    if {[lindex $pkg 1] == "Tk"} {
114
115
116
117
118
119
120
121
122


123
124
125
126
127
128
129
114
115
116
117
118
119
120


121
122
123
124
125
126
127
128
129







-
-
+
+







} {a}
test winSend-2.3 {Tk_SendObjCmd - sending to ourselves in a different interpreter} winSend {
    newApp testApp
    list [catch {send testApp {set foo b}} msg] $msg [interp delete testApp]
} {0 b {}}
test winSend-2.4 {Tk_SendObjCmd - sending to ourselves in a different interp with errors} winSend {
    newApp testApp
    list [catch {send testApp {expr {2 / 0}}} msg] $msg $errorCode $errorInfo [interp delete testApp]
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr {2 / 0}\"\n    invoked from within\n\"send testApp {expr {2 / 0}}\"} {}"
    list [catch {send testApp {expr 2 / 0}} msg] $msg $errorCode $errorInfo [interp delete testApp]
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr 2 / 0\"\n    invoked from within\n\"send testApp {expr 2 / 0}\"} {}"
test winSend-2.5 {Tk_SendObjCmd - sending to another app async} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
141
142
143
144
145
146
147
148
149


150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174


175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
141
142
143
144
145
146
147


148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172


173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189







-
-
+
+





-
+

















-
-
+
+







-
+







test winSend-2.7 {Tk_SendObjCmd - sending to another app - error} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send $interp {expr {2 / 0}}} msg] $msg $errorCode $errorInfo
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr {2 / 0}\"\n    invoked from within\n\"send \$interp {expr {2 / 0}}\"}"
    list [catch {send $interp {expr 2 / 0}} msg] $msg $errorCode $errorInfo
} "1 {divide by zero} {ARITH DIVZERO {divide by zero}} {divide by zero\n    while executing\n\"expr 2 / 0\"\n    invoked from within\n\"send \$interp {expr 2 / 0}\"}"

test winSend-3.1 {TkGetInterpNames} winSend {
    set origLength [llength $currentInterps]
    set newLength [llength [winfo interps]]
    expr {($newLength - 2) == $origLength}
} 1
} {1}

test winSend-4.1 {DeleteProc - changing name of app} winSend {
    newApp a
    list [a eval tk appname foo] [interp delete a]
} {foo {}}
test winSend-4.2 {DeleteProc - normal} winSend {
    newApp a
    list [interp delete a]
} {{}}

test winSend-5.1 {ExecuteRemoteObject - no error} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [send $interp {send [tk appname] {expr {2 / 1}}}]
} 2
    list [send $interp {send [tk appname] {expr 2 / 1}}]
} {2}
test winSend-5.2 {ExecuteRemoteObject - error} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    list [catch {send $interp {send [tk appname] {expr {2 / 0}}}} msg] $msg
    list [catch {send $interp {send [tk appname] {expr 2 / 0}}} msg] $msg
} {1 {divide by zero}}

test winSend-6.1 {SendDDEServer - XTYP_CONNECT} winSend {
    set foo "Hello, World"
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278







-
+









-
+











-
+







    set foo 3
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "send [tk appname] {expr {$foo + 1}}"
    set command "send [tk appname] {expr $foo + 1}"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 4}
test winSend-6.7 {SendDDEServer - XTYP_EXECUTE} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "send [tk appname] {expr {4 / 2}}"
    set command "send [tk appname] {expr 4 / 2}"
    list [catch "send \{$interp\} \{$command\}" msg] $msg
} {0 2}
test winSend-6.8 {SendDDEServer - XTYP_WILDCONNECT} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
    set command "dde services Tk {}"
    list [catch "send \{$interp\} \{$command\}"]
} 0
} {0}

test winSend-7.1 {DDEExitProc} winSend {
    newApp testApp
    list [interp delete testApp]
} {{}}

test winSend-8.1 {SendDdeConnect} winSend {
308
309
310
311
312
313
314
315

316
317
318

319
320
321
322
323
324
325
308
309
310
311
312
313
314

315
316
317

318
319
320
321
322
323
324
325







-
+


-
+







    list [catch {dde request} msg] $msg
} {1 {wrong # args: should be "dde request serviceName topicName value"}}
test winSend-10.7 {Tk_DDEObjCmd - services wrong num args} winSend {
    list [catch {dde services} msg] $msg
} {1 {wrong # args: should be "dde services serviceName topicName"}}
test winSend-10.8 {Tk_DDEObjCmd - null service name} winSend {
    list [catch {dde services {} {tktest #2}}]
} 0
} {0}
test winSend-10.9 {Tk_DDEObjCmd - null topic name} winSend {
    list [catch {dde services {Tk} {}}]
} 0
} {0}
test winSend-10.10 {Tk_DDEObjCmd - execute - nothing to execute} winSend {
    set newInterps [winfo interps]
    foreach interp $newInterps {
	if {[lsearch $currentInterps $interp] < 0} {
	    break
	}
    }
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396







-
+







	}
    }
    send $interp {set foo winSend-10.17}
    list [catch {dde request Tk $interp foo} msg] $msg
} {0 winSend-10.17}
test winSend-10.18 {Tk_DDEObjCmd - services} winSend {
    set currentService [list Tk [tk appname]]
    list [catch {dde services Tk {}} msg] [expr {[lsearch $msg $currentService] >= 0}]
    list [catch {dde services Tk {}} msg] [expr [lsearch $msg $currentService] >= 0]
} {0 1}

# Get rid of the other app and all of its interps

set newInterps [winfo interps]
while {[llength $newInterps] != [llength $currentInterps]} {
    foreach interp $newInterps {

Changes to tests/winWm.test.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23







-
-
+
+







-
-







# This file tests  is a Tcl script to test the procedures in the file
# tkWinWm.c.  It is organized in the standard fashion for Tcl tests.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright © 1996 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1996 by Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

test winWm-1.1 {TkWmMapWindow} -constraints win -setup {
    destroy .t
} -body {
    toplevel .t
    wm override .t 1
    wm geometry .t +0+0
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+







    toplevel .t
    frame .t.f -width 150 -height 50 -background red
    pack .t.f
    wm geometry .t -0-0
    update
    set y [winfo rooty .t]
    lappend result [winfo height .t]
    menu .t.m -tearoff 1
    menu .t.m
    .t configure -menu .t.m
    .t.m add command -label foo
    .t.m add command -label "thisisreallylong"
    .t.m add command -label "thisisreallylong"
    update
    lappend result [winfo height .t]
    lappend result [expr {$y - [winfo rooty .t]}]
272
273
274
275
276
277
278
279

280
281
282

283
284
285
286
287

288
289
290
291
292
293
294
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293







-
+



+




-
+







test winWm-6.2 {wm attributes} -constraints win -setup {
    destroy .t
} -body {
    toplevel .t
    wm attributes .t -disabled
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test winWm-6.3 {wm attributes} -constraints win -setup {
    destroy .t
} -body {
    # This isn't quite the correct error message yet, but it works.
    toplevel .t
    wm attributes .t -foo
} -cleanup {
    destroy .t
} -returnCodes error -result {bad attribute "-foo": must be -alpha, -disabled, -fullscreen, -toolwindow, -topmost, or -transparentcolor}
} -returnCodes error -result {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}

test winWm-6.4 {wm attributes -alpha} -constraints win -setup {
    destroy .t
} -body {
    # Expect this to return all 1.0 {} on pre-2K/XP
    toplevel .t
    set res [wm attributes .t -alpha]
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458







-
+







} -result {}

test winWm-9.0 "Bug #2799589 - delayed activation of destroyed window" -constraints win -setup {
    proc winwm90click {w} {
        if {![winfo ismapped $w]} { update }
        event generate $w <Enter>
        focus -force $w
        event generate $w <Button-1> -x 5 -y 5
        event generate $w <ButtonPress-1> -x 5 -y 5
        event generate $w <ButtonRelease-1> -x 5 -y 5
    }
    proc winwm90proc3 {} {
        global winwm90done winwm90check
        set w .sd
        toplevel $w
        pack [button $w.b -text "OK" -command {set winwm90check 1}]
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496

497
498
499
500
501
502
503
481
482
483
484
485
486
487

488
489
490
491
492
493
494

495
496
497
498
499
500
501
502







-
+






-
+







    vwait winwm90done
    set winwm90done
} -cleanup {
    foreach cmd {proc1 proc2 proc3 click} {
        rename winwm90$cmd {}
    }
    destroy .tx .t .sd
} -result ok
} -result {ok}

test winWm-9.1 "delayed activation of grabbed destroyed window" -constraints win -setup {
    proc winwm91click {w} {
        if {![winfo ismapped $w]} { update }
        event generate $w <Enter>
        focus -force $w
        event generate $w <Button-1> -x 5 -y 5
        event generate $w <ButtonPress-1> -x 5 -y 5
        event generate $w <ButtonRelease-1> -x 5 -y 5
    }
    proc winwm91proc3 {} {
        global winwm91done winwm91check
        set w .sd
        toplevel $w
        pack [button $w.b -text "OK" -command {set winwm91check 1}]
527
528
529
530
531
532
533
534

535
536

537
538
539
540
541
542
543
544
545

546
547
548

549
550
551

552
553

554
555
556
557
558
559
560
526
527
528
529
530
531
532

533
534

535
536
537
538
539
540
541
542
543

544
545
546

547
548
549

550
551

552
553
554
555
556
557
558
559







-
+

-
+








-
+


-
+


-
+

-
+







    vwait winwm91done
    set winwm91done
} -cleanup {
    foreach cmd {proc1 proc2 proc3 click} {
        rename winwm91$cmd {}
    }
    destroy .tx .t .sd
} -result ok
} -result {ok}

test winWm-9.2 "check wm forget for unmapped parent (#3205464,#2967911)" -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test winWm-9.2 "check wm forget for unmapped parent (#3205464,#2967911)" -setup {
    destroy .t
    toplevel .t
    set winwm92 {}
    frame .t.f -background blue -height 200 -width 200
    frame .t.f.x -background red -height 100 -width 100
} -body {
    pack .t.f.x
    pack .t.f
    lappend aid [after 5000 {set ::winwm92 timeout}] [after 500 {
    lappend aid [after 2000 {set ::winwm92 timeout}] [after 100 {
        wm manage .t.f
        wm iconify .t
        lappend aid [after 500 {
        lappend aid [after 100 {
            wm forget .t.f
            wm deiconify .t
            lappend aid [after 500 {
            lappend aid [after 100 {
                pack .t.f
                lappend aid [after 500 {
                lappend aid [after 100 {
		    set ::winwm92 [expr {
			    [winfo rooty .t.f.x] == 0 ? "failed" : "ok"}]}]
            }]
        }]
    }]
    vwait ::winwm92
    foreach id $aid {

Changes to tests/window.test.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







# This file is a Tcl script to test the procedures in the file
# tkWindow.c.  It is organized in the standard fashion for Tcl tests.
#
# Copyright © 1995 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
namespace import ::tk::test::loadTkCommand
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
259
260
261
262
263
264
265
































266
267
268
269
270
271
272







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    } else {
        set error 0
    }
    removeFile script
    list $error $msg
} -result {0 YES}

test window-2.12 {Test for ticket [9b6065d1fd] - restore Tcl [update] command} -constraints {
    unixOrWin
} -body {
    set code [loadTkCommand]
    append code {
	after 1000 {set forever 1}
	after 100 {destroy .}
	after 200 {catch bell msg; puts "ringing the bell -> $msg"}
	after 250 {update idletasks}
	after 300 {update}
	puts "waiting"
	vwait forever
	puts "done waiting"
	catch {bell} msg
	puts "bell -> $msg"
	catch update msg
	puts "update -> $msg"
    }
    set script [makeFile $code script]
    if {[catch {exec [interpreter] $script -geometry 10x10+0+0} msg]} {
        set error 1
    } else {
        set error 0
    }
    removeFile script
    list $error $msg
} -result {0 {waiting
ringing the bell -> can't invoke "bell" command: application has been destroyed
done waiting
bell -> can't invoke "bell" command: application has been destroyed
update -> }}


test window-3.1 {Tk_MakeWindowExist procedure, stacking order and menubars} -constraints {
    unix testmenubar
} -setup {
    destroy .t
} -body {
    toplevel .t -width 300 -height 200
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
351







-









    update
    lower .t.e2 .t.f
    update
    # If stacking order isn't handled properly, generates an X error.
} -cleanup {
    destroy .t
} -result {}



# cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to tests/winfo.test.

1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35



36
37
38
39
40
41
42
1
2
3



4
5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29



30
31
32
33
34
35
36
37
38
39



-
-
-
+
+
+







-
-
-
















-
-
-
+
+
+







# This file is a Tcl script to test out the "winfo" command.  It is
# organized in the standard fashion for Tcl tests.
#
# Copyright © 1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# eatColors --
# Creates a toplevel window and allocates enough colors in it to
# use up all the slots in the colormap.
#
# Arguments:
# w -        Name of toplevel window to create.
# options -    Options for w, such as "-colormap new".

proc eatColors {w {options ""}} {
    destroy $w
    eval toplevel $w $options
    wm geom $w +0+0
    canvas $w.c -width 400 -height 200 -bd 0
    pack $w.c
    for {set y 0} {$y < 8} {incr y} {
        for {set x 0} {$x < 40} {incr x} {
            set color [format #%02x%02x%02x [expr {$x*6}] [expr {$y*30}] 0]
            $w.c create rectangle [expr {10*$x}] [expr {20*$y}] \
                [expr {10*$x + 10}] [expr {20*$y + 20}] -outline {} \
            set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
            $w.c create rectangle [expr 10*$x] [expr 20*$y] \
                [expr 10*$x + 10] [expr 20*$y + 20] -outline {} \
                -fill $color
        }
    }
    update
}

# XXX - This test file is woefully incomplete.  At present, only a
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176


177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194

195
196
197

198
199
200
201
202
203
204
205
206
207
208

209
210
211

212
213
214
215
216
217
218
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171


172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193

194
195
196
197
198
199
200
201
202
203
204

205
206
207

208
209
210
211
212
213
214
215







-
+












-
-
+
+



-
+













-
+


-
+










-
+


-
+







} -body {
    toplevel .t -width 550 -height 400
    frame .t.f -width 80 -height 60 -bd 2 -relief raised
    place .t.f -x 50 -y 50
    wm geom .t +0+0
    update

    winfo containing [expr {[winfo rootx .t.f]-1}] [expr {[winfo rooty .t.f]-1}]
    winfo containing [expr [winfo rootx .t.f]-1] [expr [winfo rooty .t.f]-1]
} -cleanup {
    destroy .t
} -result .t
test winfo-4.7 {"winfo containing" command} -setup {
    destroy .t
} -body {
    toplevel .t -width 550 -height 400
    frame .t.f -width 80 -height 60 -bd 2 -relief raised
    place .t.f -x 50 -y 50
    wm geom .t +0+0
    update

    set x [winfo containing -display .t.f [expr {[winfo rootx .t]+600}] \
        [expr {[winfo rooty .t.f]+450}]]
    set x [winfo containing -display .t.f [expr [winfo rootx .t]+600] \
        [expr [winfo rooty .t.f]+450]]
    expr {($x == ".") || ($x == "")}
} -cleanup {
    destroy .t
} -result 1
} -result {1}


test winfo-5.1 {"winfo interps" command} -body {
    winfo interps a
} -returnCodes error -result {wrong # args: should be "winfo interps ?-displayof window?"}
test winfo-5.2 {"winfo interps" command} -body {
    winfo interps a b c
} -returnCodes error -result {wrong # args: should be "winfo interps ?-displayof window?"}
test winfo-5.3 {"winfo interps" command} -body {
    winfo interps -displayof geek
} -returnCodes error -result {bad window path name "geek"}
test winfo-5.4 {"winfo interps" command} -constraints unix -body {
    expr {[lsearch -exact [winfo interps] [tk appname]] >= 0}
} -result 1
} -result {1}
test winfo-5.5 {"winfo interps" command} -constraints unix -body {
    expr {[lsearch -exact [winfo interps -displayof .] [tk appname]] >= 0}
} -result 1
} -result {1}


test winfo-6.1 {"winfo exists" command} -body {
    winfo exists
} -returnCodes error -result {wrong # args: should be "winfo exists window"}
test winfo-6.2 {"winfo exists" command} -body {
    winfo exists a b
} -returnCodes error -result {wrong # args: should be "winfo exists window"}
test winfo-6.3 {"winfo exists" command} -body {
    winfo exists gorp
} -result 0
} -result {0}
test winfo-6.4 {"winfo exists" command} -body {
    winfo exists .
} -result 1
} -result {1}
test winfo-6.5 {"winfo exists" command} -setup {
    destroy .b
} -body {
    button .b -text "Test button"
    set x [winfo exists .b]
    pack .b
    update
289
290
291
292
293
294
295
296
297


298
299
300
301
302

303
304
305
306
307
308
309
286
287
288
289
290
291
292


293
294
295
296
297
298

299
300
301
302
303
304
305
306







-
-
+
+




-
+







    winfo viewable
} -returnCodes error -result {wrong # args: should be "winfo viewable window"}
test winfo-9.2 {"winfo viewable" command} -body {
    winfo viewable foo
} -returnCodes error -result {bad window path name "foo"}
test winfo-9.3 {"winfo viewable" command} -body {
    winfo viewable .
} -result 1
test winfo-9.4 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuarz} -body {
} -result {1}
test winfo-9.4 {"winfo viewable" command} -body {
    wm iconify .
    winfo viewable .
} -cleanup {
    wm deiconify .
} -result 0
} -result {0}
test winfo-9.5 {"winfo viewable" command} -setup {
    deleteWindows
} -body {
    frame .f1 -width 100 -height 100 -relief raised -bd 2
    place .f1 -x 0 -y 0
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330







-
+







    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update
    list [winfo viewable .f1] [winfo viewable .f1.f2]
} -cleanup {
    deleteWindows
} -result {0 0}
test winfo-9.7 {"winfo viewable" command} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test winfo-9.7 {"winfo viewable" command} -setup {
    deleteWindows
} -body {
    frame .f1 -width 100 -height 100 -relief raised -bd 2
    place .f1 -x 0 -y 0
    frame .f1.f2 -width 50 -height 50 -relief raised -bd 2
    place .f1.f2 -x 0 -y 0
    update
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364

365
366
367

368
369
370
371


372
373
374
375
376
377
378
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363

364
365
366


367
368
369
370
371
372
373
374
375







-
+













-
+


-
+


-
-
+
+







    winfo visualid
} -returnCodes error -result {wrong # args: should be "winfo visualid window"}
test winfo-10.2 {"winfo visualid" command} -body {
    winfo visualid gorp
} -returnCodes error -result {bad window path name "gorp"}
test winfo-10.3 {"winfo visualid" command} -body {
    expr {2 + [winfo visualid .] - [winfo visualid .]}
} -result 2
} -result {2}


test winfo-11.1 {"winfo visualid" command} -body {
    winfo visualsavailable
} -returnCodes error -result {wrong # args: should be "winfo visualsavailable window ?includeids?"}
test winfo-11.2 {"winfo visualid" command} -body {
    winfo visualsavailable gorp
} -returnCodes error -result {bad window path name "gorp"}
test winfo-11.3 {"winfo visualid" command} -body {
    winfo visualsavailable . includeids foo
} -returnCodes error -result {wrong # args: should be "winfo visualsavailable window ?includeids?"}
test winfo-11.4 {"winfo visualid" command} -body {
    llength [lindex [winfo visualsa .] 0]
} -result 2
} -result {2}
test winfo-11.5 {"winfo visualid" command} -body {
    llength [lindex [winfo visualsa . includeids] 0]
} -result 3
} -result {3}
test winfo-11.6 {"winfo visualid" command} -body {
    set x [lindex [lindex [winfo visualsa . includeids] 0] 2]
    expr {$x + 2 - $x}
} -result 2
    expr $x + 2 - $x
} -result {2}


test winfo-12.1 {GetDisplayOf procedure} -body {
    winfo atom - foo x
} -returnCodes error -result {wrong # args: should be "winfo atom ?-displayof window? name"}
test winfo-12.2 {GetDisplayOf procedure} -body {
    winfo atom -d bad_window x
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
390
391
392
393
394
395
396







397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419







-
-
-
-
-
-
-















-
+








    list rootx [expr {[winfo rootx .emb] == [winfo rootx .con]}] \
        rooty [expr {[winfo rooty .emb] == [winfo rooty .con]}]
} -cleanup {
    deleteWindows
} -result {rootx 1 rooty 1}

# Windows does not destroy the container when an embedded window is
# destroyed.  Unix and macOS do destroy it.  See ticket [67384bce7d].
if {[tk windowingsystem] eq "win32"} {
   set result_13_2 {embedded 0 container 1}
} else {
   set result_13_2 {embedded 0 container 0}
}
test winfo-13.2 {destroying embedded toplevel} -setup {
    deleteWindows
} -body {
    frame .con -container 1
    pack .con -expand yes -fill both
    toplevel .emb -use [winfo id .con] -bd 0 -highlightthickness 0
    button .emb.b
    pack .emb.b -expand yes -fill both
    update

    destroy .emb
    update
    list embedded [winfo exists .emb.b] container [winfo exists .con]
} -cleanup {
    deleteWindows
} -result $result_13_2
} -result {embedded 0 container 1}

test winfo-13.3 {destroying container window} -setup {
    deleteWindows
} -body {
    frame .con -container 1
    pack .con -expand yes -fill both
    toplevel .emb -use [winfo id .con] -bd 0 -highlightthickness 0

Changes to tests/wm.test.

1
2
3
4
5
6
7



8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
1
2
3
4



5
6
7
8
9
10
11
12
13

14
15
16
17

































































18
19
20
21
22
23
24
25
26
27
28
29



30
31
32
33
34
35

36


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64




-
-
-
+
+
+






-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
-
-






-
+
-
-




















-
+







# This file is a Tcl script to test out Tk's interactions with the window
# manager, including the "wm" command. It is organized in the standard fashion
# for Tcl tests.
#
# Copyright © 1992-1994 The Regents of the University of California.
# Copyright © 1994-1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

# This file tests window manager interactions that work across platforms.
# Window manager tests that only work on a specific platform should be placed
# in unixWm.test or winWm.test.

package require tcltest 2.2
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands

image create photo icon -data {
    iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAA
    CBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/w
    D/AP+gvaeTAAAACXBIWXMAArQNAAK0DQEdFIm+AAAJQElEQVRYw+WXW2xdV5nHf/ty7lc
    f2/FxYsdOnMSNC0HTpDiRKJWAQjWCEQNUSEAFfUOiQqrEC2+IxwpemDLSzNBBCCQeQEKq
    RJgBSikiuGlN22TqhsR27OPL8eWc43Pdt7X22osHHydOm4FBPM6Slr69paX9/32Xtb614
    f/7MP6vC3O5f8L3G7HJyZPHBwfz5wrF7HQ6nRwxLTOhQuU4PW+z3eq9Xa+33rq9cms7k8
    pHjvfS3w8wOfk52u1u8oHpiUff897JJ8+dO/nI6LHho6OjQ3ahkMYwTTZ2O2zXutS3G/7
    ayubq7Vtr/7Ve2f7RytLam4ViXq1t/vRvB0ilPsjzz3+LZ5/9j7MzM5Nf/8hj5//5H97/
    YNbK5hkfTFLMxAEQQvD766v0yBGIEBEEuPUGi9dv7lx77cb3Vm9vfqc0WNi9evUKWr/xL
    h3rfuLj45+l0bjM7m768U98/OJ/fulLH/3wiemxeCafxRcKw7TJxKC+12RpbYdAx7HsOC
    rSRNpg+sQQj1w8nS0N5h8JAvm+rWr99ZmZB2qWdZq9vWt/GWBm5im+9rUn6HRGPv7EE4/
    ++2P/eOFkV0FkJTDQgCaXTbO1tcV2R2EmCxBJQixs2+R9EwV00MFAceJE2ZiZOT7VaTsP
    LyxU5orFTK1cfphq9bX7A8zOfoV8Ps3c3NsXPvWpD37vc5//0ETNt8gNjDAzlsdAE0vli
    TCRxEhnC2CaRIZNMmZiaonv9mh1PcrDJQZzCfK5OGNjQ8e2tvZO37y5+ctk0naq1fn7A4
    yOnmd5uVp4/PGHn/vylz8xe+zoEIP5JAMpA0OHeK6DG4TEk2li8ThaQxRpIg0q6DGUNjg
    6UuLYSInhYoYoigiCgHQ6TrGYnlpd3Q1ffvk3L128+ITe2Hj1XoBLl55menqcbDb1haee
    evyrDz102tJaE7ctLBMqG1X23Ag7kcKOJzAADSilCVWEZdmMDaXJJCxSiRimaaK1RkqJ7
    /uUSlk6Hed0oxG9HI9bm+Pjs2xsvIp5AKC15oUX/lA8f/7MF2dnz8YADMNASslypYqrUx
    SHyqSy+f31hzaRZRpMDKVYr+7y4usVri1WWavWCWSIZZkYhoFSIRcuTI1MTAw9OTf33Tu
    7zz54SCRinD17/Pzs7AMPFQqZPlTE8vo2DlmGhgbo12BffD/8SmukitiuNxHKoDwyzPJG
    nTdXmtiWwdnRNCN5GxWGDA/nOH26/NGpqSfHgPU7AJcuPc0nP/kBrl698YGZmYmMEIJmx
    6Hn+my0DUZGC6gIzEOnhu4Lh2GEbRocGyxRSO/7c3QgiRuEVOtdEvEQrSN8IVEq5MSJ4Y
    lSKX3OMKJ14G4KnnnmM9bkZPk92VyKy3M3eentJjd3FUYyjxuEeELt7/NoP+eBVAipCFX
    EsYE4xcydYFIeSHKynOXhUwM0mh32egH1tsdL16oo007kcskHs7kYly49fRcALqby+fQo
    pklkZ4jHY3g6gQgjHF/QcgQdV+7DHJoGmnzSQuvD0QGlIsJQkU4luLXR4kgxxcRgjM1mQ
    CyZHrv0sUe4JwKFXMmu7/VSXV9xaXqI0YzC8328QOJ4gq4raHQDGt2AtitwfIEbSAwibO
    vdJ7pSCiElR3IxGh2X5Y0GV66v0wnAsq3MN5759L1FqKMoCkQoX19u0QkkD47lKSYiTh1
    NoSLYafu0ehrTNNBaE2mNUop2z+DEUJKBbPxecSEIgoAoUjwwmmZpdZPlmuL4oIFWkbx8
    rXIvQMfZ9p2e1xBCstOJcFe6nB1NcWokhW1ZHMkazK90qXXDfZFII0NFIBW/XQiZHraoN
    bsU81mmjhbxfZ8gCAiCgELKQitJGCoIQ6SQO//2ze/fm4Kf/Px50dzr3Aoch1Ap2o4kn8
    tgW/sHynAxzcVTBQYzFp4v6boBjidwfcFCpcmPf7/Oz+ZrvPBalb12D9/370DUGk1evr6
    NacWIfD/yveDmXq3F3NxzdwH+5dkfUq8155rb9dA2QcqQcjFx57DRGgaySR47d4RHZ0pY
    eh/C9QSOJ3EECGWw3fJZ323j+x6e5xH4Pgu3d6g0FMWUjdvu7bo9/5oK1d0IzM09hwhCG
    rvNubXFylI2pum4AZXtDqEURFGE1hoNxGMW5ZyB22nS8wQ9r1+QvsDzBc1uQGW7jee6eN
    4+RMfxMdHkYgatWmtur9ZaOnD8TgQMA27c+uH68s3KT8O9BoYBv3pjkxuVGo7Tw+1/MAh
    83lreYm1P9r3fT4XjSVxf4voC1/NwHAfXdXFcB891KGVjhO2e16q3fzR2cjQwDPPeZrSx
    8SqXL2/RqDU2EnH7I8dPjQ8v7Tqs1RwmSzEsQoQQSBHw1lKVha0AEUb4IiQQIb4I8YUkk
    CHTQwa5WIjne9xY2mT+VouRfI7NxfVfrK8sfTuRSAavXP3Xd7fjavWPRq1+3TeiQTVcGn
    h0oHwktlZzmBq0SNsRQgiuXLvNL/+nQU/aBFL1xSW+kAghEb5PEkE5q3Bdl7dv72LGCrT
    Xdzf+9Nb8N5dXfrG6Wf1jeNDP3nkjigOFWm2xpvx0+tjI8LnMYMnMxQT5eIjruVye36LS
    TRAqRSD3vZdCIqUgEj5R4CEDj2O5kMZei3rHoLXV6Sy88cp3Fhf/ew6IAAGE9wOIARmtw
    9Tu7vKa1yY+Wiqeee+ZYdsi4HdvrjK/HiKUiZQhoZREQhDJAC18tPSIhEfouwSuQ9cx2V
    xpNK/PX/n+4uKvXwQdAAHgA/J+AAaQABJRJOydnVsrzZ1O13eMcSuezC61LJzQRgY+KvC
    JhI+WPpH0IAywIkEhaVIupAhdHS0t3F66Nv/iD9bW/nAFtAM4QA9wAXX3RnEvQBoYODSL
    +fzEmalTsx+emjl3YWjsaMlMpcwg0ggZEimFoSNsI8JSCtF1wtpmdWt1aeGVSuW133leY
    wNoA01gr297BzVwv/8CA0gBBaDYtzkw87ns6PhI+czM0JHjp/PFUjmZSmUM07RCKUPP6X
    Vae/Vqfbdys1ZbvOX5ja2+ULcP0Opbt18H/G8Ah+shDWQPzVQ/RSnLTGRsO5U0TMuMVKj
    C0PUjLd1+fgPAOxTybl9YcvdC9VcBDobV3x0JINm3MfYbmdX/hu57FfZFDgot6Fe8eqfw
    3wLwzvVmX9jsvx8AHEAcnn91/BlySEFKTpuCtgAAABN0RVh0QXV0aG9yAHdhcnN6YXdpY
    W5rYQy+S5cAAABYdEVYdENvcHlyaWdodABDQzAgUHVibGljIERvbWFpbiBEZWRpY2F0aW
    9uIGh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL3B1YmxpY2RvbWFpbi96ZXJvLzEuMC/
    G4735AAAAIXRFWHRDcmVhdGlvbiBUaW1lADIwMTAtMDMtMjlUMDg6MDg6MzD47LxwAAAA
    JXRFWHRkYXRlOmNyZWF0ZQAyMDIxLTA4LTE1VDIwOjU0OjM5LTA0OjAwNBT3DQAAACV0R
    Vh0ZGF0ZTptb2RpZnkAMjAyMS0wOC0xNVQyMDo1NDoxMS0wNDowMDSDBqsAAADIelRYdE
    Rlc2NyaXB0aW9uAAAY042OwQqCQBCGn6B3GOy+Cl0qTAjEc1HRJVhWHXUrd2pmLXr7tDr
    VpcMP838w/F+wxxxyprsgB2ALclAxtRAbaBirRdB4f5mHoTeuJlUxYoly8nRRxHW4HahO
    30SvmI5Y+CCBF4dPhzg0CYwOLs45GdKfG+sKhBuy2H4xUlM1i76+BhcBwwirLj/bAlJqj
    XXzP9UyxmuHzp8feiknLPW6Q/H9moy3yK1oqvROUE2yH99suX45PwEyf2MTOoCNrQAAAB
    l0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABWdEVYdFNvdXJjZQBodHR
    wczovL29wZW5jbGlwYXJ0Lm9yZy9kZXRhaWwvMzUyMzMvdGFuZ28taW5ldHJuZXQtd2Vi
    LWJyb3dzZXItYnktd2Fyc3phd2lhbmth5nAuRgAAACB0RVh0VGl0bGUAdGFuZ28gaW5ld
    HJuZXQgd2ViIGJyb3dzZXLyr62TAAAAAElFTkSuQmCC
}

wm deiconify .
if {![winfo ismapped .]} {
    tkwait visibility .
}

proc stdWindow {} {
    destroy .t
    toplevel .t -width 100 -height 50
    wm geom .t +0+0
    update
}

testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
testConstraint failsOnXQuarz [expr {$tcl_platform(os) ne "Darwin" || [tk windowingsystem] ne "x11" }]

# [raise] and [lower] may return before the window manager has completed the
# operation. The raiseDelay procedure idles for a while to give the operation
# a chance to complete.
#

proc raiseDelay {} {
    after 250;
    after 100; update
    update idletasks
    update
}

# How to carry out a small delay while processing events

proc eventDelay {{delay 200}} {
    after $delay "set done 1" ; vwait done
}

deleteWindows

##############################################################################

stdWindow

test wm-1.1 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {
    wm
} -result {wrong # args: should be "wm option window ?arg ...?"}
# Next test will fail every time set of subcommands is changed
test wm-1.2 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {
    wm foo
} -result {bad option "foo": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbadge, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}
} -result {bad option "foo": must be aspect, attributes, client, colormapwindows, command, deiconify, focusmodel, forget, frame, geometry, grid, group, iconbitmap, iconify, iconmask, iconname, iconphoto, iconposition, iconwindow, manage, maxsize, minsize, overrideredirect, positionfrom, protocol, resizable, sizefrom, stackorder, state, title, transient, or withdraw}
test wm-1.3 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {
    wm command
} -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-1.4 {Tk_WmObjCmd procedure, miscellaneous errors} -returnCodes error -body {
    wm aspect bogus
} -result {bad window path name "bogus"}
test wm-1.5 {Tk_WmObjCmd procedure, miscellaneous errors} -body {
189
190
191
192
193
194
195


196
197

198
199
200
201


202
203

204
205
206

207
208
209
210
211

212

213
214
215
216
217
218
219
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136

137
138
139

140



141
142
143

144
145
146
147
148
149
150
151







+
+

-
+




+
+

-
+


-
+
-
-
-


+
-
+









### wm attributes ###
test wm-attributes-1.1 {usage} -returnCodes error -body {
    wm attributes
} -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-attributes-1.2.1 {usage} -constraints win -returnCodes error -body {
    # This is the wrong error to output - unix has it right, but it's
    # not critical.
    wm attributes . _
} -result {bad attribute "_": must be -alpha, -disabled, -fullscreen, -toolwindow, -topmost, or -transparentcolor}
} -result {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}
test wm-attributes-1.2.2 {usage} -constraints win -returnCodes error -body {
    wm attributes . -alpha 1.0 -disabled
} -result {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}
test wm-attributes-1.2.3 {usage} -constraints win -returnCodes error -body {
    # This is the wrong error to output - unix has it right, but it's
    # not critical.
    wm attributes . -to
} -result {bad attribute "-to": must be -alpha, -disabled, -fullscreen, -toolwindow, -topmost, or -transparentcolor}
} -result {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}
test wm-attributes-1.2.4 {usage} -constraints {unix notAqua} -returnCodes error -body {
    wm attributes . _
} -result {bad attribute "_": must be -alpha, -fullscreen, -topmost, -type, or -zoomed}
} -result {bad attribute "_": must be -alpha, -topmost, -zoomed, -fullscreen, or -type}
if {[tk windowingsystem] eq "aqua"} {
    set result_1_2_5 {bad attribute "_": must be -alpha, -appearance, -buttons, -fullscreen, -isdark, -modified, -notify, -titlepath, -topmost, -transparent, -stylemask, -class, -tabbingid, -tabbingmode, or -type}
} else {set result_1_2_5 {bad attribute "_": must be -alpha, -fullscreen, -modified, -notify, -titlepath, -topmost, -transparent, or -type}}
test wm-attributes-1.2.5 {usage} -constraints aqua -returnCodes error -body {
    wm attributes . _
} -result {bad attribute "_": must be -alpha, -modified, -notify, or -titlepath}
} -result $result_1_2_5


### wm client ###
test wm-client-1.1 {usage} -returnCodes error -body {
    wm client
} -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-client-1.2 {usage} -returnCodes error -body {
    wm client . _ _
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881

882
883
884
885

886
887
888
889
890
891
892
719
720
721
722
723
724
725









































































726
727
728
729
730
731
732
733
734
735
736
737
738
739

740
741
742
743

744
745
746
747
748
749
750
751







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-
+



-
+







    lappend result [wm group .t]
    wm group .t .
    lappend result [wm group .t]
    wm group .t {}
    lappend result [wm group .t]
} -result [list {} . {}]


### wm iconbadge ###
test wm-iconbadge-1.1 {usage} -body {
    wm iconbadge
} -returnCodes error -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-iconbadge-1.2 {usage} -body {
    frame .f
    set ::tk::icons::base_icon(.f) icon
    wm iconbadge .f icon
} -cleanup {
    destroy .f
    unset ::tk::icons::base_icon(.f)
} -returnCodes error -result {window ".f" isn't a top-level window}
test wm-iconbadge-1.3 {::tk::icons::base_icon($win) must be set on X11} -constraints {
    x11
} -setup {
    unset -nocomplain ::tk::icons::base_icon(.)
} -body {
    wm iconbadge . !
} -returnCodes error -result {::tk::icons::base_icon(.) must be set on X11}
test wm-iconbadge-1.4 {::tk::icons::base_icon($win) must be a Tk photo on X11} -constraints {
    x11
} -setup {
    catch {image delete book}
} -body {
    set ::tk::icons::base_icon(.) book
    wm iconbadge . 27
} -returnCodes error -result {can't use "book" as iconphoto: not a photo image}
test wm-iconbadge-1.5 {illegal badge number} -body {
    image create photo book -data {
        R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAAC
        wAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IM
        QCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc
        0yv+DVSEUuFxIAOw==
    }
    set ::tk::icons::base_icon(.) book
    wm iconbadge . illegal
} -cleanup {
    image delete book
} -returnCodes error -result {can't use "illegal" as icon badge}
test wm-iconbadge-1.6 {non-integer badge number} -body {
    image create photo book -data {
        R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAAC
        wAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IM
        QCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc
        0yv+DVSEUuFxIAOw==
    }
    set ::tk::icons::base_icon(.) book
    wm iconbadge . 3.2
} -cleanup {
    image delete book
} -returnCodes error -result {can't use "3.2" as icon badge}
test wm-iconbadge-1.7 {negative or zero badge number} -body {
    image create photo book -data {
        R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAAC
        wAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IM
        QCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc
        0yv+DVSEUuFxIAOw==
    }
    set ::tk::icons::base_icon(.) book
    wm iconbadge . 0
} -cleanup {
    image delete book
} -returnCodes error -result {can't use "0" as icon badge}
test wm-iconbadge-1.8 {usage, no need to call iconphoto on aqua or win32} -constraints {
    aquaOrWin32
} -body {
    wm iconbadge . 3
    wm iconbadge . 5000
    wm iconbadge . !
    wm iconbadge . ""
} -result {}


### wm iconbitmap ###
test wm-iconbitmap-1.1 {usage} -returnCodes error -body {
    wm iconbitmap
} -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-iconbitmap-1.2.1 {usage} -constraints unix -returnCodes error -body {
    wm iconbitmap .t 12 13
} -result {wrong # args: should be "wm iconbitmap window ?bitmap?"}
test wm-iconbitmap-1.2.2 {usage} -constraints win -returnCodes error -body {
    wm iconbitmap .t 12 13 14
} -result {wrong # args: should be "wm iconbitmap window ?-default? ?image?"}
test wm-iconbitmap-1.3 {usage} -constraints win -returnCodes error -body {
    wm iconbitmap .t 12 13
} -result {illegal option "12" must be "-default"}
test wm-iconbitmap-1.4 {usage} -constraints notAqua -returnCodes error -body {
test wm-iconbitmap-1.4 {usage} -returnCodes error -body {
    wm iconbitmap .t bad-bitmap
} -result {bitmap "bad-bitmap" not defined}

test wm-iconbitmap-2.1 {setting and reading values} -constraints notAqua -setup {
test wm-iconbitmap-2.1 {setting and reading values} -setup {
    set result {}
} -body {
    lappend result [wm iconbitmap .t]
    wm iconbitmap .t hourglass
    lappend result [wm iconbitmap .t]
    wm iconbitmap .t {}
    lappend result [wm iconbitmap .t]
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
936
937

938
939
940
941
942
943
944
945
946
947

948
949

950
951
952

953
954
955

956
957
958
959
960
961
962
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794
795

796
797
798
799
800
801
802
803
804
805

806
807

808
809
810

811
812
813

814
815
816
817
818
819
820
821







-
+









-
+









-
+

-
+


-
+


-
+







test wm-iconify-2.3 {Misc errors} -body {
    toplevel .t2
    wm geom .t2 +0+0
    wm iconwindow .t .t2
    wm iconify .t2
} -returnCodes error -cleanup {
    destroy .t2
} -result {can't iconify ".t2": it is an icon for ".t"}
} -result {can't iconify .t2: it is an icon for .t}
# test embedded window for Windows
test wm-iconify-2.4.1 {Misc errors} -constraints win -setup {
    destroy .t2
} -body {
    frame .t.f -container 1
    toplevel .t2 -use [winfo id .t.f]
    wm iconify .t2
} -returnCodes error -cleanup {
    destroy .t2 .r.f
} -result {can't iconify ".t2": the container does not support the request}
} -result {can't iconify .t2: the container does not support the request}
# test embedded window for other platforms
test wm-iconify-2.4.2 {Misc errors} -constraints !win -setup {
    destroy .t2
} -body {
    frame .t.f -container 1
    toplevel .t2 -use [winfo id .t.f]
    wm iconify .t2
} -returnCodes error -cleanup {
    destroy .t2 .r.f
} -result {can't iconify ".t2": it is an embedded window}
} -result {can't iconify .t2: it is an embedded window}

test wm-iconify-3.1 {iconify behavior} -constraints {failsOnUbuntu failsOnXQuarz} -body {
test wm-iconify-3.1 {iconify behavior} -body {
    toplevel .t2
    wm geom .t2 -0+0
    update idletasks
    update
    set result [winfo ismapped .t2]
    wm iconify .t2
    update idletasks
    update
    lappend result [winfo ismapped .t2]
} -cleanup {
    destroy .t2
} -result {1 0}


### wm iconmask ###
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
869
870
871
872
873
874
875







876
877
878
879
880
881
882







-
-
-
-
-
-
-







test wm-iconphoto-1.3 {usage} -returnCodes error -body {
    wm iconphoto . notanimage
} -result {can't use "notanimage" as iconphoto: not a photo image}
test wm-iconphoto-1.4 {usage} -returnCodes error -body {
    # we currently have no return info
    wm iconphoto . -default
} -result {wrong # args: should be "wm iconphoto window ?-default? image1 ?image2 ...?"}
test wm-iconphoto-1.5.1 {usage} -constraints aquaOrWin32 -returnCodes error -body {
    wm iconphoto . -default [image create photo -file {}]
} -match {glob} -result {failed to create an iconphoto with image *}
test wm-iconphoto-1.5.2 {usage} -constraints x11 -body {
    wm iconphoto . -default [image create photo -file {}]
} -result {}


# All other iconphoto tests are platform specific


### wm iconposition ###
test wm-iconposition-1.1 {usage} -returnCodes error -body {
    wm iconposition
1105
1106
1107
1108
1109
1110
1111
1112

1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
957
958
959
960
961
962
963

964
965
966

967
968
969
970
971
972
973
974







-
+


-
+







    wm maxsize . a
} -result {wrong # args: should be "wm maxsize window ?width height?"}
test wm-maxsize-1.3 {usage} -returnCodes error -body {
    wm maxsize . a b c
} -result {wrong # args: should be "wm maxsize window ?width height?"}
test wm-maxsize-1.4 {usage} -returnCodes error -body {
    wm maxsize . x 100
} -result {expected screen distance but got "x"}
} -result {expected integer but got "x"}
test wm-maxsize-1.5 {usage} -returnCodes error -body {
    wm maxsize . 100 bogus
} -result {expected screen distance but got "bogus"}
} -result {expected integer but got "bogus"}
test wm-maxsize-1.6 {usage} -setup {
    destroy .t2
} -body {
    toplevel .t2
    wm maxsize .t2 300 200
    wm maxsize .t2
} -cleanup {
1205
1206
1207
1208
1209
1210
1211
1212

1213
1214
1215

1216
1217
1218
1219
1220
1221
1222
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066

1067
1068
1069
1070
1071
1072
1073
1074







-
+


-
+







    wm minsize . a
} -result {wrong # args: should be "wm minsize window ?width height?"}
test wm-minsize-1.3 {usage} -returnCodes error -body {
    wm minsize . a b c
} -result {wrong # args: should be "wm minsize window ?width height?"}
test wm-minsize-1.4 {usage} -returnCodes error -body {
    wm minsize . x 100
} -result {expected screen distance but got "x"}
} -result {expected integer but got "x"}
test wm-minsize-1.5 {usage} -returnCodes error -body {
    wm minsize . 100 bogus
} -result {expected screen distance but got "bogus"}
} -result {expected integer but got "bogus"}
test wm-minsize-1.6 {usage} -setup {
    destroy .t2
} -body {
    toplevel .t2
    wm minsize .t2 300 200
    wm minsize .t2
} -cleanup {
1386
1387
1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405
1406
1407
1408
1238
1239
1240
1241
1242
1243
1244

1245
1246


1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258







-
+

-
-




-
+







    wm resizable .t bad 0
} -result {expected boolean value but got "bad"}
test wm-resizable-1.5 {usage} -returnCodes error -body {
    wm resizable .t 1 bad
} -result {expected boolean value but got "bad"}

test wm-resizable-2.1 {setting and reading values} {
    wm resizable .t 0 0
    wm resizable .t 0 1
    set result [wm resizable .t]
    wm resizable .t 0 1
    lappend result [wm resizable .t]
    wm resizable .t 1 0
    lappend result [wm resizable .t]
    wm resizable .t 1 1
    lappend result [wm resizable .t]
} {0 0 {0 1} {1 0} {1 1}}
} {0 1 {1 0} {1 1}}


### wm sizefrom ###
test wm-sizefrom-1.1 {usage} -returnCodes error -body {
    wm sizefrom
} -result {wrong # args: should be "wm option window ?arg ...?"}
test wm-sizefrom-1.2 {usage} -returnCodes error -body {
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507

1508
1509
1510
1511
1512
1513
1514
1515
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353

1354


1355

1356
1357
1358
1359
1360
1361
1362







-













-
+
-
-
+
-







} -cleanup {
    destroy .t
} -returnCodes error -result {window ".t" isn't mapped}
deleteWindows

test wm-stackorder-2.1 {stacking order} -body {
    toplevel .t ; update
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t
} -result {. .t}
test wm-stackorder-2.2 {stacking order} -body {
    toplevel .t ; update
    raise .
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t
} -result {.t .}
test wm-stackorder-2.3 {stacking order} -body {
    toplevel .t
    toplevel .t ; update
    tkwait visibility .t
    toplevel .t2
    toplevel .t2 ; update
    tkwait visibility .t2
    raise .
    raiseDelay
    raise .t2
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t .t2
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562

1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426







-















-
+



-








-







    raiseDelay
    wm stackorder .parent
} -cleanup {
    deleteWindows
} -result {.parent.child2 .parent.child1 .parent}
test wm-stackorder-2.6 {stacking order: non-toplevel widgets ignored} -body {
    toplevel .t1
    raiseDelay
    button .t1.b
    pack .t1.b
    update
    wm stackorder .
} -cleanup {
    destroy .t1
} -result {. .t1}
test wm-stackorder-2.7 {stacking order: no children returns self} -setup {
    deleteWindows
} -body {
    wm stackorder .
} -result {.}

deleteWindows

test wm-stackorder-3.1 {unmapped toplevel} -constraints {failsOnUbuntu failsOnXQuarz} -body {
test wm-stackorder-3.1 {unmapped toplevel} -body {
    toplevel .t1 ; update
    toplevel .t2 ; update
    wm iconify .t1
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t1 .t2
} -result {. .t2}
test wm-stackorder-3.2 {unmapped toplevel} -body {
    toplevel .t1 ; update
    toplevel .t2 ; update
    wm withdraw .t2
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t1 .t2
} -result {. .t1}
test wm-stackorder-3.3 {unmapped toplevel} -body {
    toplevel .t1 ; update
    toplevel .t2 ; update
1598
1599
1600
1601
1602
1603
1604
1605

1606
1607

1608
1609

1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1442
1443
1444
1445
1446
1447
1448

1449


1450


1451

1452

1453
1454
1455
1456
1457
1458
1459







-
+
-
-
+
-
-
+
-

-







    toplevel .t1.t2 ; update
    wm withdraw .t1
    wm stackorder .t1
} -cleanup {
    destroy .t1
} -result {.t1.t2}
test wm-stackorder-3.6 {unmapped toplevel} -body {
    toplevel .t1
    toplevel .t1 ; update
    tkwait visibility .t1
    toplevel .t1.t2
    toplevel .t1.t2 ; update
    tkwait visibility .t1.t2
    toplevel .t1.t2.t3
    toplevel .t1.t2.t3 ; update
    tkwait visibility .t1.t2.t3
    wm withdraw .t1.t2
    raiseDelay
    wm stackorder .t1
} -cleanup {
    destroy .t1
} -result {.t1 .t1.t2.t3}
test wm-stackorder-3.7 {unmapped toplevel, mapped children returned} -body {
    toplevel .t1 ; update
    toplevel .t1.t2 ; update
1632
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646

1647
1648

1649
1650
1651
1652

1653
1654
1655

1656
1657
1658
1659
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
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481
1482
1483
1484
1485

1486
1487

1488

1489
1490

1491
1492
1493

1494
1495
1496
1497
1498
1499
1500
1501

1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516


1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527












1528
1529
1530
1531

1532
1533
1534
1535
1536
1537
1538
1539


1540
1541
1542

1543

1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556







-
+






-
+

-
+
-


-
+


-
+







-
+














-
-
+
+


-







-
-
-
-
-
-
-
-
-
-
-
-




-








-
-
+
+

-

-
+




+








test wm-stackorder-4.1 {wm stackorder isabove|isbelow} -body {
    toplevel .t ; update
    raise .t
    wm stackorder . isabove .t
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test wm-stackorder-4.2 {wm stackorder isabove|isbelow} -body {
    toplevel .t ; update
    raise .t
    wm stackorder . isbelow .t
} -cleanup {
    destroy .t
} -result 1
} -result {1}
test wm-stackorder-4.3 {wm stackorder isabove|isbelow} -body {
    toplevel .t
    toplevel .t ; update
    tkwait visibility .t
    raise .
    raiseDelay
    wm stackorder .t isabove .
    wm stackorder .t isa .
} -cleanup {
    destroy .t
} -result 0
} -result {0}
test wm-stackorder-4.4 {wm stackorder isabove|isbelow} -body {
    toplevel .t ; update
    raise .
    raiseDelay
    wm stackorder .t isb .
} -cleanup {
    destroy .t
} -result 1
} -result {1}
deleteWindows

test wm-stackorder-5.1 {a menu is not a toplevel} -body {
    toplevel .t
    menu .t.m -type menubar
    .t.m add cascade -label "File"
    .t configure -menu .t.m
    update
    raise .
    raiseDelay
    wm stackorder .
} -cleanup {
    destroy .t
} -result {.t .}
test wm-stackorder-5.2 {A normal toplevel can't be raised above an \
    overrideredirect toplevel on unix} -constraints {x11 failsOnUbuntu failsOnXQuarz} -body {
test wm-stackorder-5.2 {A normal toplevel can't be\
        raised above an overrideredirect toplevel} -body {
    toplevel .t
    wm overrideredirect .t 1
    tkwait visibility .t
    raise .
    update
    raiseDelay
    wm stackorder . isabove .t
} -cleanup {
    destroy .t
} -result 0
test wm-stackorder-5.2.1 {A normal toplevel can be raised above an \
    overrideredirect toplevel on macOS or win} -constraints aquaOrWin32 -body {
    toplevel .t
    wm overrideredirect .t 1
    tkwait visibility .t
    raise .
    update
    raiseDelay
    wm stackorder . isabove .t
} -cleanup {
    destroy .t
} -result 1
test wm-stackorder-5.3 {An overrideredirect window\
        can be explicitly lowered} -body {
    toplevel .t
    wm overrideredirect .t 1
    tkwait visibility .t
    lower .t
    update
    raiseDelay
    wm stackorder .t isbelow .
} -cleanup {
    destroy .t
} -result 1

test wm-stackorder-6.1 {An embedded toplevel does not appear in the \
	 stacking order} -body {
test wm-stackorder-6.1 {An embedded toplevel does not\
        appear in the stacking order} -body {
    toplevel .real -container 1
    raiseDelay
    toplevel .embd -bg blue -use [winfo id .real]
    raiseDelay
    update
    wm stackorder .
} -cleanup {
    deleteWindows
} -result {. .real}


stdWindow

### wm title ###
test wm-title-1.1 {usage} -returnCodes error -body {
    wm title
} -result {wrong # args: should be "wm option window ?arg ...?"}
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
1570
1571
1572
1573
1574
1575
1576

1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589

1590
1591
1592
1593
1594
1595
1596
1597







-
+










-
+

-
+







} -result {t Apa {}}


### wm transient ###
test wm-transient-1.1 {usage} -returnCodes error -body {
    catch {destroy .t} ; toplevel .t
    wm transient .t 1 2
} -result {wrong # args: should be "wm transient window ?window?"}
} -result {wrong # args: should be "wm transient window ?master?"}
test wm-transient-1.2 {usage} -returnCodes error -body {
    catch {destroy .t} ; toplevel .t
    wm transient .t foo
} -result {bad window path name "foo"}
test wm-transient-1.3 {usage} -returnCodes error -body {
    catch {destroy .t} ; toplevel .t
    wm transient foo .t
} -result {bad window path name "foo"}
deleteWindows
test wm-transient-1.4 {usage} -returnCodes error -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    wm transient .subject .top
    wm transient .subject .master
    wm iconify .subject
} -cleanup {
    deleteWindows
} -result {can't iconify ".subject": it is a transient}
test wm-transient-1.5 {usage} -returnCodes error -body {
    toplevel .icon -bg blue
    toplevel .top
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
1605
1606
1607
1608
1609
1610
1611

1612
1613


1614
1615
1616
1617

1618
1619

1620












1621
1622
1623
1624

1625
1626

1627
1628
1629

1630
1631
1632

1633
1634
1635
1636
1637
1638




1639
1640
1641
1642
1643

1644
1645
1646
1647

1648
1649
1650



1651
1652
1653
1654
1655

1656
1657
1658
1659
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







-
+

-
-
+
+


-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+


-
+

-
+


-
+


-
+





-
-
-
-
+
+
+
+

-
+



-
+


-
-
-
+
+
+


-
+






-
-
-
+
+
+



-
+





-
+



-
+


-
-
+
+


-
+







-
-
-
+
+
+


-
+






-
-
+
+

-
-
+
+

-
-
-
+
+
+




-
-
+
+


-
+

-
-
-
-
+
+
+
+

-
-
+
+









-
+


-
+


-
+


-
+





-
+

-
+

-
+

-
+






-
-
+
+

-
-
+
+






-
-
+
+


-
+

-
-
+
+







-
+


-
+


-
+

-
-
+
+





-
+

-
+







-
-
+
+




-
-
-
+
+
+







-
+













-
-
+
+

-
-
+
+




-
+











-
+







    toplevel .icon -bg blue
    toplevel .top
    wm iconwindow .top .icon
    toplevel .dummy
    wm transient .dummy .icon
} -cleanup {
    deleteWindows
} -result {can't make ".icon" a container: it is an icon for .top}
} -result {can't make ".icon" a master: it is an icon for .top}
test wm-transient-1.7 {usage} -returnCodes error -body {
    toplevel .top
    wm transient .top .top
    toplevel .master
    wm transient .master .master
} -cleanup {
    deleteWindows
} -result {can't set ".top" as container: would cause management loop}
} -result {can't make ".master" its own master}
test wm-transient-1.8 {usage} -returnCodes error -body {
    toplevel .t1
    toplevel .master
    toplevel .t2
    toplevel .t3
    wm transient .t2 .t1
    wm transient .t3 .t2
    wm transient .t1 .t3
} -cleanup {
    deleteWindows
} -result {can't set ".t3" as container: would cause management loop}
test wm-transient-1.9 {usage} -returnCodes error -body {
    toplevel .top
    frame .top.f
    wm transient .top .top.f
    frame .master.f
    wm transient .master .master.f
} -cleanup {
    deleteWindows
} -result {can't set ".top" as container: would cause management loop}
} -result {can't make ".master" its own master}

test wm-transient-2.1 {basic get/set of toplevel} -setup {
test wm-transient-2.1 {basic get/set of master} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    lappend results [wm transient .subject]
    wm transient .subject .top
    wm transient .subject .master
    lappend results [wm transient .subject]
    wm transient .subject {}
    lappend results [wm transient .subject]
} -cleanup {
    deleteWindows
} -result {{} .top {}}
test wm-transient-2.2 {first toplevel parent of non-toplevel container window is used} -body {
    toplevel .top
    frame .top.f
} -result {{} .master {}}
test wm-transient-2.2 {first toplevel parent of non-toplevel master is used} -body {
    toplevel .master
    frame .master.f
    toplevel .subject
    wm transient .subject .top.f
    wm transient .subject .master.f
    wm transient .subject
} -cleanup {
    deleteWindows
} -result {.top}
} -result {.master}

test wm-transient-3.1 {transient toplevel is withdrawn
        when mapped if toplevel is withdrawn} -body {
    toplevel .top
    wm withdraw .top
        when mapped if master is withdrawn} -body {
    toplevel .master
    wm withdraw .master
    update
    toplevel .subject
    wm transient .subject .top
    wm transient .subject .master
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-3.2 {already mapped transient toplevel
        takes on withdrawn state of toplevel} -body {
    toplevel .top
    wm withdraw .top
        takes on withdrawn state of master} -body {
    toplevel .master
    wm withdraw .master
    update
    toplevel .subject
    update
    wm transient .subject .top
    wm transient .subject .master
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-3.3 {withdraw/deiconify on the toplevel
test wm-transient-3.3 {withdraw/deiconify on the master
        also does a withdraw/deiconify on the transient} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    update
    wm transient .subject .top
    wm withdraw .top
    wm transient .subject .master
    wm withdraw .master
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
    wm deiconify .top
    wm deiconify .master
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0 normal 1}

test wm-transient-4.1 {transient toplevel is withdrawn
        when mapped if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .top
    wm iconify .top
        when mapped if master is iconic} -body {
    toplevel .master
    wm iconify .master
    update
    toplevel .subject
    wm transient .subject .top
    wm transient .subject .master
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.2 {already mapped transient toplevel
        is withdrawn if toplevel is iconic} -constraints {failsOnUbuntu failsOnXQuarz} -body {
    toplevel .top
        is withdrawn if master is iconic} -body {
    toplevel .master
    raiseDelay
    wm iconify .top
    update idletasks
    wm iconify .master
    update
    toplevel .subject
    update idletasks
    wm transient .subject .top
    update idletasks
    update
    wm transient .subject .master
    update
    list [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0}
test wm-transient-4.3 {iconify/deiconify on the toplevel
        does a withdraw/deiconify on the transient} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test wm-transient-4.3 {iconify/deiconify on the master
        does a withdraw/deiconify on the transient} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    update idletasks
    wm transient .subject .top
    wm iconify .top
    update idletasks
    update
    wm transient .subject .master
    wm iconify .master
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
    wm deiconify .top
    update idletasks
    wm deiconify .master
    update
    lappend results [wm state .subject] [winfo ismapped .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn 0 normal 1}

test wm-transient-5.1 {an error during transient command should not
        cause the map/unmap binding to be deleted} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    update
    wm transient .subject .top
    wm transient .subject .master
    # Expect a bad window path error here
    lappend results [catch {wm transient .subject .bad}]
    wm withdraw .top
    wm withdraw .master
    update
    lappend results [wm state .subject]
    wm deiconify .top
    wm deiconify .master
    update
    lappend results [wm state .subject]
} -cleanup {
    deleteWindows
} -result {1 withdrawn normal}
test wm-transient-5.2 {remove transient property when toplevel
test wm-transient-5.2 {remove transient property when master
        is destroyed} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    wm transient .subject .top
    wm transient .subject .master
    update
    destroy .top
    destroy .master
    update
    wm transient .subject
} -cleanup {
    deleteWindows
} -result {}
test wm-transient-5.3 {remove transient property from window
        that had never been mapped when toplevel is destroyed} -body {
    toplevel .top
        that had never been mapped when master is destroyed} -body {
    toplevel .master
    toplevel .subject
    wm transient .subject .top
    destroy .top
    wm transient .subject .master
    destroy .master
    wm transient .subject
} -cleanup {
    deleteWindows
} -result {}

test wm-transient-6.1 {a withdrawn transient does not track
        state changes in the toplevel} -body {
    toplevel .top
        state changes in the master} -body {
    toplevel .master
    toplevel .subject
    update
    wm transient .subject .top
    wm transient .subject .master
    wm withdraw .subject
    wm withdraw .top
    wm deiconify .top
    wm withdraw .master
    wm deiconify .master
    # idle handler should not map the transient
    update
    wm state .subject
} -cleanup {
    deleteWindows
} -result {withdrawn}
test wm-transient-6.2 {a withdrawn transient does not track
        state changes in the toplevel} -setup {
        state changes in the master} -setup {
    set results [list]
} -body {
    toplevel .top
    toplevel .master
    toplevel .subject
    update
    wm transient .subject .top
    wm transient .subject .master
    wm withdraw .subject
    wm withdraw .top
    wm deiconify .top
    wm withdraw .master
    wm deiconify .master
    # idle handler should not map the transient
    update
    lappend results [wm state .subject]
    wm deiconify .subject
    lappend results [wm state .subject]
    wm withdraw .top
    wm withdraw .master
    lappend results [wm state .subject]
    wm deiconify .top
    wm deiconify .master
    # idle handler should map transient
    update
    lappend results [wm state .subject]
} -cleanup {
    deleteWindows
} -result {withdrawn normal withdrawn normal}
test wm-transient-6.3 {a withdrawn transient does not track
        state changes in the toplevel} -body {
    toplevel .top
        state changes in the master} -body {
    toplevel .master
    toplevel .subject
    update
    # withdraw before making window a transient
    wm withdraw .subject
    wm transient .subject .top
    wm withdraw .top
    wm deiconify .top
    wm transient .subject .master
    wm withdraw .master
    wm deiconify .master
    # idle handler should not map the transient
    update
    wm state .subject
} -cleanup {
    deleteWindows
} -result {withdrawn}

# wm-transient-7.*: See SF Tk Bug #592201 "wm transient fails with two toplevels"
# wm-transient-7.*: See SF Tk Bug #592201 "wm transient fails with two masters"
# wm-transient-7.3 through 7.5 all caused panics on Unix in Tk 8.4b1.
# 7.1 and 7.2 added to catch (potential) future errors.
#
test wm-transient-7.1 {Destroying transient} -body {
    toplevel .t
    toplevel .transient
    wm transient .transient .t
    destroy .transient
    destroy .t
    # OK: the above did not cause a panic.
} -cleanup {
    deleteWindows
}
test wm-transient-7.2 {Destroying toplevel} -body {
    toplevel .top
test wm-transient-7.2 {Destroying master} -body {
    toplevel .t
    toplevel .transient
    wm transient .transient .top
    destroy .top
    wm transient .transient .t
    destroy .t
    wm transient .transient
} -cleanup {
    deleteWindows
} -result {}
test wm-transient-7.3 {Reassign transient, destroy old toplevel} -body {
test wm-transient-7.3 {Reassign transient, destroy old master} -body {
    toplevel .t1
    toplevel .t2
    toplevel .transient
    wm transient .transient .t1
    wm transient .transient .t2
    destroy .t1	;# Caused panic in 8.4b1
    destroy .t2
    destroy .transient
} -cleanup {
    deleteWindows
}
test wm-transient-7.4 {Reassign transient, destroy new toplevel} -body {
test wm-transient-7.4 {Reassign transient, destroy new master} -body {
    toplevel .t1
    toplevel .t2
    toplevel .transient
    wm transient .transient .t1
    wm transient .transient .t2
    destroy .t2 	;# caused panic in 8.4b1
    destroy .t1
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
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







-
+



-
-
+
+





-
+







    destroy .transient
    destroy .t2 	;# caused panic in 8.4b1
    destroy .t1		;# so did this
} -cleanup {
    deleteWindows
}

test wm-transient-8.1 {transient to withdrawn window, Bug 1163496} -constraints {failsOnUbuntu failsOnXQuarz} -setup {
test wm-transient-8.1 {transient to withdrawn window, Bug 1163496} -setup {
    deleteWindows
    set result {}
} -body {
    # Verifies that transients stay on top of their toplevels, even if they were
    # made transients when those toplevels were withdrawn.
    # Verifies that transients stay on top of their masters, even if they were
    # made transients when those masters were withdrawn.
    toplevel .t1; wm withdraw  .t1;     update
    toplevel .t2; wm transient .t2 .t1; update
    lappend result [winfo ismapped .t1] [winfo ismapped .t2]
    wm deiconify .t1; update
    lappend result [winfo ismapped .t1] [winfo ismapped .t2]
    raise .t1; raiseDelay; update
    raise .t1; update
    lappend result [lsearch -all -inline -glob [wm stackorder .] ".t?"]
} -cleanup {
    deleteWindows
} -result {0 0 1 1 {.t1 .t2}}


### wm state ###
2151
2152
2153
2154
2155
2156
2157
2158

2159
2160
2161
2162
2163
2164
2165
2166

2167
2168
2169
2170
2171
2172
2173
1966
1967
1968
1969
1970
1971
1972

1973
1974
1975
1976
1977
1978
1979
1980

1981
1982
1983
1984
1985
1986
1987
1988







-
+







-
+







test wm-state-2.7 {state change before map} -body {
    toplevel .t
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.8 {state change after map} -constraints {failsOnUbuntu failsOnXQuarz} -body {
test wm-state-2.8 {state change after map} -body {
    toplevel .t
    update
    wm state .t iconic
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
test wm-state-2.9 {state change after map} -constraints {failsOnUbuntu failsOnXQuarz} -body {
test wm-state-2.9 {state change after map} -body {
    toplevel .t
    update
    wm iconify .t
    wm state .t
} -cleanup {
    deleteWindows
} -result {iconic}
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
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







-
+








-
+








-
+







test wm-forget-1.1 "bug #2009788: forget toplevel can cause crash" -body {
    toplevel .parent
    toplevel .parent.child
    wm forget .parent.child
    winfo exists .parent.child
} -cleanup {
    deleteWindows
}  -result 1
}  -result {1}
test wm-forget-1.2 "bug #2009788: forget toplevel can cause crash" -body {
    toplevel .parent
    update
    toplevel .parent.child
    wm forget .parent.child
    winfo exists .parent.child
} -cleanup {
    deleteWindows
}  -result 1
}  -result {1}
test wm-forget-1.3 "bug #2009788: forget toplevel can cause crash" -body {
    toplevel .parent
    toplevel .parent.child
    wm forget .parent.child
    wm manage .parent.child
    winfo exists .parent.child
} -cleanup {
    deleteWindows
}  -result 1
}  -result {1}
test wm-forget-1.4 "pack into unmapped toplevel causes crash" -body {
    toplevel .parent
    toplevel .parent.child
    wm forget .parent.child
    pack [button .parent.child.button -text Hello]
    after 250 {destroy .parent}
    tkwait window .parent
2467
2468
2469
2470
2471
2472
2473

2474
2475
2476
2477
2478
2479
2480
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296







+







} -body {
    label .l -text "Top Dot"
    frame .f
    button .f.b -text Hello -command "puts Hello!"
    pack .l -side top
    pack .f.b
    pack .f -side bottom
    update
    set res [winfo manager .f]
    pack forget .f
    update
    lappend res [winfo manager .f]
    wm manage .f
    update
    lappend res [winfo manager .f]

Changes to tests/xmfbox.test.

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







# xmfbox.test --
#
#	This file is a Tcl script to test the file dialog that's used
#	when the tk_strictMotif flag is set. Because the file dialog
#	runs in a modal loop, the only way to test it sufficiently is
#	to call the internal Tcl procedures in xmfbox.tcl directly.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# Copyright (c) 1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# Contributions from Don Porter, NIST, 2002.  (not subject to US copyright)
# All rights reserved.

package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113
87
88
89
90
91
92
93


94
95
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113







-
-
+
+









-
-
+
+







    unix
} -body {
    cleanup
    file mkdir ./~nosuchuser1
    set x [tk::MotifFDialog_Create foo open {}]
    $::tk::dialog::file::foo(fEnt) delete 0 end
    $::tk::dialog::file::foo(fEnt) insert 0 [pwd]/~nosuchuser1
    file normalize [file join {*}[tk::MotifFDialog_InterpFilter $x]]
} -result "$testPWD/~nosuchuser1/*"
    set kk [tk::MotifFDialog_InterpFilter $x]
} -result "$testPWD/~nosuchuser1 *"

test xmfbox-2.2 {tk::MotifFDialog_InterpFilter, ~ in file names} -constraints {
    unix
} -body {
    cleanup
    close [open ./~nosuchuser1 {CREAT TRUNC WRONLY}]
    set x [tk::MotifFDialog_Create foo open {}]
    $::tk::dialog::file::foo(fEnt) delete 0 end
    $::tk::dialog::file::foo(fEnt) insert 0 [pwd]/~nosuchuser1
    file normalize [file join {*}[tk::MotifFDialog_InterpFilter $x]]
} -result "$testPWD/~nosuchuser1"
    set kk [tk::MotifFDialog_InterpFilter $x]
} -result "$testPWD ./~nosuchuser1"

test xmfbox-2.3 {tk::MotifFDialog_Update, ~ in file names} -constraints {
    unix
} -body {
    cleanup
    close [open ./~nosuchuser1 {CREAT TRUNC WRONLY}]
    set x [tk::MotifFDialog_Create foo open {}]
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
165
166







-
+














-
+










    cleanup
    close [open ./~nosuchuser1 {CREAT TRUNC WRONLY}]
    set x [tk::MotifFDialog_Create foo open {}]
    set i [lsearch [$::tk::dialog::file::foo(fList) get 0 end] ~nosuchuser1]
    $::tk::dialog::file::foo(fList) selection clear 0 end
    $::tk::dialog::file::foo(fList) selection set $i
    tk::MotifFDialog_BrowseFList $x
    file normalize [$::tk::dialog::file::foo(sEnt) get]
    $::tk::dialog::file::foo(sEnt) get
} -result "$testPWD/~nosuchuser1"

test xmfbox-2.6 {tk::MotifFDialog_ActivateFList, ~ in file names} -constraints {
    unix
} -body {
    cleanup
    close [open ./~nosuchuser1 {CREAT TRUNC WRONLY}]
    set x [tk::MotifFDialog_Create foo open {}]
    set i [lsearch [$::tk::dialog::file::foo(fList) get 0 end] ~nosuchuser1]
    $::tk::dialog::file::foo(fList) selection clear 0 end
    $::tk::dialog::file::foo(fList) selection set $i
    tk::MotifFDialog_BrowseFList $x
    tk::MotifFDialog_ActivateFList $x
    list $::tk::dialog::file::foo(selectPath) \
	    $::tk::dialog::file::foo(selectFile) [file normalize $tk::Priv(selectFilePath)]
	    $::tk::dialog::file::foo(selectFile) $tk::Priv(selectFilePath)
} -result "$testPWD ~nosuchuser1 $testPWD/~nosuchuser1"

# cleanup
cleanup
cleanupTests
return

# Local variables:
# mode: tcl
# End:

Changes to unix/Makefile.in.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
31
32
33
34
35
36
37

38
39
40
41
42
43
44







-








prefix			= @prefix@
exec_prefix		= @exec_prefix@
bindir			= @bindir@
libdir			= @libdir@
includedir		= @includedir@
datarootdir		= @datarootdir@
runstatedir		= @runstatedir@
mandir			= @mandir@

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
92
93
94
95
96
97
98
99

100
101
102
103
104
105

106
107
108
109

110
111
112
113
114
115

116
117
118
119
120
121
122
91
92
93
94
95
96
97

98
99
100
101
102


103
104
105
106

107
108
109
110
111
112

113
114
115
116
117
118
119
120







-
+




-
-
+



-
+





-
+







# Directory in which to install html documentation:
HTML_INSTALL_DIR	= $(INSTALL_ROOT)$(HTML_DIR)

# Directory in which to install the configuration file tkConfig.sh:
CONFIG_INSTALL_DIR	= $(INSTALL_ROOT)$(libdir)

# Directory in which to install the demo files:
DEMO_INSTALL_DIR	= $(INSTALL_ROOT)@DEMO_DIR@
DEMO_INSTALL_DIR	= $(INSTALL_ROOT)$(TK_LIBRARY)/demos

# The directory containing the Tcl sources and headers appropriate
# for this version of Tk ("srcdir" will be replaced or has already
# been replaced by the configure script):
TCLDIR   = @TCL_SRC_DIR@
TCL_GENERIC_DIR		= $(TCLDIR)/generic
TCL_GENERIC_DIR		= @TCL_SRC_DIR@/generic

# The directory containing the platform specific Tcl sources and headers
# appropriate for this version of Tk:
TCL_PLATFORM_DIR	= $(TCLDIR)/unix
TCL_PLATFORM_DIR	= @TCL_SRC_DIR@/unix

# The directory containing the Tcl library archive file appropriate
# for this version of Tk:
TCL_BIN_DIR		= @TCL_BIN_DIR@

# The linker flags needed to link in the Tcl library (ex: -ltcl9.0)
# The linker flags needed to link in the Tcl library (ex: -ltcl8.2)
TCL_LIB_FLAG		= @TCL_LIB_FLAG@

# Flag, 1: we're building a shared lib, 0 we're not
TK_SHARED_BUILD		= @TK_SHARED_BUILD@

# Subdirectory of $(libdir) containing the pkgIndex.tcl file for loadable Tk
TK_PKG_DIR		= @TK_PKG_DIR@
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+







# XStringToKeysym is plenty fast, so you needn't define REDO_KEYSYM_LOOKUP.
KEYSYM_FLAGS		=
#KEYSYM_FLAGS		= -DREDO_KEYSYM_LOOKUP

# Tk does not used deprecated Tcl constructs so it should
# compile fine with -DTCL_NO_DEPRECATED. To remove its own
# set of deprecated code uncomment the second line.
NO_DEPRECATED_FLAGS	=
NO_DEPRECATED_FLAGS	= -DTCL_NO_DEPRECATED
#NO_DEPRECATED_FLAGS	= -DTCL_NO_DEPRECATED -DTK_NO_DEPRECATED

# Some versions of make, like SGI's, use the following variable to
# determine which shell to use for executing commands:
SHELL			= @SHELL@

# BUILD_TCLSH is the fully qualified path name of the tclsh shell
215
216
217
218
219
220
221
222
223


224
225
226
227
228
229
230
213
214
215
216
217
218
219


220
221
222
223
224
225
226
227
228







-
-
+
+







TKTEST_EXE		= tktest${EXE_SUFFIX}

# Tk used to let the configure script choose which program to use
# for installing, but there are just too many different versions of
# "install" around;  better to use the install-sh script that comes
# with the distribution, which is slower but guaranteed to work.

INSTALL_STRIP_PROGRAM	= strip
INSTALL_STRIP_LIBRARY	= strip -x
INSTALL_STRIP_PROGRAM   = -s
INSTALL_STRIP_LIBRARY   = -S -x

INSTALL			= $(SHELL) $(UNIX_DIR)/install-sh -c
INSTALL_PROGRAM		= ${INSTALL}
INSTALL_LIBRARY		= ${INSTALL}
INSTALL_DATA		= ${INSTALL} -m 644
INSTALL_DATA_DIR	= ${INSTALL} -d -m 755

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
241
242
243
244
245
246
247


248
249
250
251
252
253
254







-
-







# Generic stub lib name used in rules that apply to tcl and tk
STUB_LIB_FILE		= ${TK_STUB_LIB_FILE}

TK_STUB_LIB_FLAG	= @TK_STUB_LIB_FLAG@
#TK_STUB_LIB_FLAG	= -ltkstub

TK_LIB_FILE		= @TK_LIB_FILE@
TK_LIB_FILE_TCL8	= @TK_LIB_FILE_TCL8@
TK_LIB_FILE_TCL9	= @TK_LIB_FILE_TCL9@
#TK_LIB_FILE		= libtk.a

# Generic lib name used in rules that apply to tcl and tk
LIB_FILE		= ${TK_LIB_FILE}

TK_LIB_FLAG		= @TK_LIB_FLAG@
#TK_LIB_FLAG		= -ltk
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
279
280
281
282
283
284
285

286
287
288
289
290
291
292
293







-
+







# Additional search flags needed to find the various shared libraries
# at run-time.  The first symbol is for use when creating a binary
# with cc, and the second is for use when running ld directly.
CC_SEARCH_FLAGS	= @CC_SEARCH_FLAGS@
LD_SEARCH_FLAGS	= @LD_SEARCH_FLAGS@

# support for embedded libraries on Darwin / Mac OS X
DYLIB_INSTALL_DIR	= $(libdir)
DYLIB_INSTALL_DIR	= ${LIB_RUNTIME_DIR}

# support for building the Aqua resource file
TK_RSRC_FILE		= @TK_RSRC_FILE@
WISH_RSRC_FILE		= @WISH_RSRC_FILE@
REZ			= @REZ@
REZ_SWITCHES = @REZ_FLAGS@ -i $(GENERIC_DIR) -i $(TCL_GENERIC_DIR)

310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

334
335


336
337
338

339
340
341
342
343
344
345
346
347




348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397

398
399
400
401
402
403
404



405
406
407
408
409





410
411
412
413
414
415
416
306
307
308
309
310
311
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330


331
332

333

334
335
336
337
338
339




340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371


372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

389
390
391

392
393
394
395
396



397
398
399





400
401
402
403
404
405
406
407
408
409
410
411







-
+
















+
-
-
+
+
-

-
+





-
-
-
-
+
+
+
+



-
+











-
+












-
-
+
+
-















-
+


-
+




-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+







RANLIB			= @RANLIB@
SRC_DIR			= @srcdir@
TOP_DIR			= $(SRC_DIR)/..
GENERIC_DIR		= $(TOP_DIR)/generic
TTK_DIR			= $(GENERIC_DIR)/ttk
UNIX_DIR		= $(TOP_DIR)/unix
BMAP_DIR		= $(TOP_DIR)/bitmaps
TOOL_DIR		= $(TCLDIR)/tools
TOOL_DIR		= @TCL_SRC_DIR@/tools
TEST_DIR		= $(TOP_DIR)/tests
MAC_OSX_DIR		= $(TOP_DIR)/macosx
XLIB_DIR		= $(TOP_DIR)/xlib

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------

# Flags to be passed to installManPage to control how the manpages
# should be installed (symlinks, compression, package name suffix).
MAN_FLAGS               = @MAN_FLAGS@

CC			= @CC@

CC_SWITCHES_NO_STUBS = ${CFLAGS} ${CFLAGS_WARNING} ${SHLIB_CFLAGS} \
CC_SWITCHES_NO_STUBS = -I${UNIX_DIR} -I${GENERIC_DIR} -I${BMAP_DIR} \
${@TK_WINDOWINGSYSTEM@_INCLUDES} ${CFLAGS} ${CFLAGS_WARNING} \
-I${UNIX_DIR} -I${GENERIC_DIR} -I${BMAP_DIR} -I${TCL_GENERIC_DIR} \
-I${TCL_PLATFORM_DIR} ${@TK_WINDOWINGSYSTEM@_INCLUDES} ${AC_FLAGS} \
${SHLIB_CFLAGS} -I${TCL_GENERIC_DIR} -I${TCL_PLATFORM_DIR} ${AC_FLAGS} \
${PROTO_FLAGS} ${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} ${KEYSYM_FLAGS} \
${NO_DEPRECATED_FLAGS} -DTCL_UTF_MAX=4 @EXTRA_CC_SWITCHES@
${NO_DEPRECATED_FLAGS} @EXTRA_CC_SWITCHES@

CC_SWITCHES = $(CC_SWITCHES_NO_STUBS) @TCL_STUB_FLAGS@

APP_CC_SWITCHES = $(CC_SWITCHES_NO_STUBS) @EXTRA_APP_CC_SWITCHES@

DEPEND_SWITCHES = -I${UNIX_DIR} -I${GENERIC_DIR} -I${BMAP_DIR} \
${@TK_WINDOWINGSYSTEM@_INCLUDES} ${CFLAGS} -I${TCL_GENERIC_DIR} \
-I${TCL_PLATFORM_DIR} ${AC_FLAGS} ${PROTO_FLAGS} ${SECURITY_FLAGS} \
${MEM_DEBUG_FLAGS} ${KEYSYM_FLAGS} @EXTRA_CC_SWITCHES@
DEPEND_SWITCHES = ${CFLAGS} -I${UNIX_DIR} -I${GENERIC_DIR} -I${BMAP_DIR} \
-I${TCL_GENERIC_DIR} -I${TCL_PLATFORM_DIR} ${@TK_WINDOWINGSYSTEM@_INCLUDES} \
${AC_FLAGS} ${PROTO_FLAGS} ${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} \
${KEYSYM_FLAGS} @EXTRA_CC_SWITCHES@

WISH_OBJS = tkAppInit.o

TKTEST_OBJS = tkTestInit.o tkTest.o tkSquare.o \
TKTEST_OBJS = tkTestInit.o tkTest.o tkSquare.o tkOldTest.o \
	$(@TK_WINDOWINGSYSTEM@_TKTEST_OBJS)

WIDG_OBJS = tkButton.o tkEntry.o tkFrame.o tkListbox.o \
	tkMenu.o tkMenubutton.o tkMenuDraw.o tkMessage.o \
	tkPanedWindow.o tkScale.o tkScrollbar.o

CANV_OBJS = tkCanvas.o tkCanvArc.o tkCanvBmap.o tkCanvImg.o \
	tkCanvLine.o tkCanvPoly.o tkCanvPs.o tkCanvText.o \
	tkCanvUtil.o tkCanvWind.o tkRectOval.o tkTrig.o

IMAGE_OBJS = tkImage.o tkImgBmap.o tkImgGIF.o tkImgPNG.o tkImgPPM.o \
	tkImgPhoto.o tkImgPhInstance.o tkImgListFormat.o tkImgSVGnano.o
	tkImgPhoto.o tkImgPhInstance.o tkImgListFormat.o

TEXT_OBJS = tkText.o tkTextBTree.o tkTextDisp.o tkTextImage.o tkTextIndex.o \
	tkTextMark.o tkTextTag.o tkTextWind.o

# either tkUnixFont.o (default) or tkUnixRFont.o (if --enable-xft)
#
FONT_OBJS = @UNIX_FONT_OBJS@

GENERIC_OBJS = tk3d.o tkArgv.o tkAtom.o tkBind.o tkBitmap.o tkBusy.o \
	tkClipboard.o \
	tkCmds.o tkColor.o tkConfig.o tkConsole.o tkCursor.o tkError.o \
	tkEvent.o tkFocus.o tkFont.o tkGet.o tkGC.o tkGeometry.o tkGrab.o \
	tkGrid.o tkMain.o tkObj.o tkOldConfig.o tkOption.o tkPack.o \
	tkPkgConfig.o tkPlace.o	tkSelect.o tkStyle.o tkUndo.o tkUtil.o \
	tkGrid.o tkMain.o tkObj.o tkOldConfig.o tkOption.o tkPack.o tkPlace.o \
	tkSelect.o tkStyle.o tkUndo.o tkUtil.o tkVisual.o tkWindow.o
	tkVisual.o tkWindow.o

TTK_OBJS = \
	ttkBlink.o ttkButton.o ttkCache.o ttkClamTheme.o ttkClassicTheme.o \
	ttkDefaultTheme.o ttkElements.o ttkEntry.o ttkFrame.o ttkImage.o \
	ttkInit.o ttkLabel.o ttkLayout.o ttkManager.o ttkNotebook.o \
	ttkPanedwindow.o ttkProgress.o ttkScale.o ttkScrollbar.o ttkScroll.o \
	ttkSeparator.o ttkSquare.o ttkState.o \
	ttkTagSet.o ttkTheme.o ttkTrace.o ttkTrack.o ttkTreeview.o \
	ttkWidget.o ttkStubInit.o

STUB_OBJS = tkStubInit.o

STUB_LIB_OBJS = tkStubLib.o ttkStubLib.o

X11_OBJS = tkUnix.o tkUnix3d.o tkUnixButton.o tkUnixColor.o tkUnixConfig.o \
	tkUnixCursor.o tkUnixDraw.o tkUnixEmbed.o tkUnixEvent.o tkIcu.o \
	tkUnixCursor.o tkUnixDraw.o tkUnixEmbed.o tkUnixEvent.o \
	tkUnixFocus.o  $(FONT_OBJS) tkUnixInit.o tkUnixKey.o tkUnixMenu.o \
	tkUnixMenubu.o tkUnixScale.o tkUnixScrlbr.o tkUnixSelect.o \
	tkUnixSend.o tkUnixSysNotify.o tkUnixSysTray.o tkUnixWm.o tkUnixXId.o
	tkUnixSend.o tkUnixWm.o tkUnixXId.o

AQUA_OBJS = tkMacOSXBitmap.o tkMacOSXButton.o tkMacOSXClipboard.o \
	tkMacOSXColor.o tkMacOSXConfig.o tkMacOSXCursor.o tkMacOSXDebug.o \
	tkMacOSXDialog.o tkMacOSXDraw.o tkMacOSXEmbed.o tkMacOSXEntry.o \
	tkMacOSXEvent.o tkMacOSXFileTypes.o tkMacOSXFont.o tkMacOSXHLEvents.o \
        tkMacOSXImage.o tkMacOSXInit.o tkMacOSXKeyboard.o tkMacOSXKeyEvent.o \
	tkMacOSXMenu.o tkMacOSXMenubutton.o tkMacOSXMenus.o \
	tkMacOSXEvent.o tkMacOSXFont.o tkMacOSXHLEvents.o tkMacOSXInit.o \
	tkMacOSXKeyboard.o tkMacOSXKeyEvent.o tkMacOSXMenu.o \
	tkMacOSXMenubutton.o tkMacOSXMenus.o tkMacOSXMouseEvent.o \
        tkMacOSXMouseEvent.o tkMacOSXNotify.o tkMacOSXPrint.o tkMacOSXRegion.o \
	tkMacOSXScrlbr.o tkMacOSXSend.o tkMacOSXServices.o \
	tkMacOSXSubwindows.o tkMacOSXSysTray.o tkMacOSXWindowEvent.o tkMacOSXWm.o \
	tkMacOSXXStubs.o tkFileFilter.o tkMacWinMenu.o tkPointer.o tkUnix3d.o \
	tkUnixScale.o xcolors.o xdraw.o xgc.o ximage.o xutil.o \
	tkMacOSXNotify.o tkMacOSXRegion.o tkMacOSXScrlbr.o tkMacOSXSend.o \
	tkMacOSXSubwindows.o tkMacOSXWindowEvent.o \
	tkMacOSXWm.o tkMacOSXXStubs.o \
	tkFileFilter.o tkMacWinMenu.o tkPointer.o tkUnix3d.o tkUnixScale.o \
	xcolors.o xdraw.o xgc.o ximage.o xutil.o \
	ttkMacOSXTheme.o

AQUA_TKTEST_OBJS = tkMacOSXTest.o

OBJS =  $(GENERIC_OBJS) $(WIDG_OBJS) $(CANV_OBJS) $(IMAGE_OBJS) $(TEXT_OBJS) \
	$(STUB_OBJS) $(TTK_OBJS) \
	$(@TK_WINDOWINGSYSTEM@_OBJS) @PLAT_OBJS@
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
427
428
429
430
431
432
433

434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

452
453
454
455
456
457

458
459
460
461
462
463
464
465







-


















-






-
+







	$(GENERIC_DIR)/tkError.c $(GENERIC_DIR)/tkEvent.c \
	$(GENERIC_DIR)/tkFocus.c $(GENERIC_DIR)/tkFont.c \
	$(GENERIC_DIR)/tkGet.c $(GENERIC_DIR)/tkGC.c \
	$(GENERIC_DIR)/tkGeometry.c $(GENERIC_DIR)/tkGrab.c \
	$(GENERIC_DIR)/tkGrid.c $(GENERIC_DIR)/tkConsole.c \
	$(GENERIC_DIR)/tkMain.c $(GENERIC_DIR)/tkOption.c \
	$(GENERIC_DIR)/tkPack.c $(GENERIC_DIR)/tkPlace.c \
	$(GENERIC_DIR)/tkPkgConfig.c \
	$(GENERIC_DIR)/tkSelect.c $(GENERIC_DIR)/tkStyle.c \
	$(GENERIC_DIR)/tkUndo.c $(GENERIC_DIR)/tkUtil.c \
	$(GENERIC_DIR)/tkVisual.c $(GENERIC_DIR)/tkWindow.c \
	$(GENERIC_DIR)/tkButton.c $(GENERIC_DIR)/tkObj.c \
	$(GENERIC_DIR)/tkEntry.c $(GENERIC_DIR)/tkFrame.c \
	$(GENERIC_DIR)/tkListbox.c $(GENERIC_DIR)/tkMenu.c \
	$(GENERIC_DIR)/tkMenubutton.c $(GENERIC_DIR)/tkMenuDraw.c \
	$(GENERIC_DIR)/tkMessage.c $(GENERIC_DIR)/tkPanedWindow.c \
	$(GENERIC_DIR)/tkScale.c $(GENERIC_DIR)/tkScrollbar.c \
	$(GENERIC_DIR)/tkCanvas.c $(GENERIC_DIR)/tkCanvArc.c \
	$(GENERIC_DIR)/tkCanvBmap.c $(GENERIC_DIR)/tkCanvImg.c \
	$(GENERIC_DIR)/tkCanvLine.c $(GENERIC_DIR)/tkCanvPoly.c \
	$(GENERIC_DIR)/tkCanvPs.c $(GENERIC_DIR)/tkCanvText.c \
	$(GENERIC_DIR)/tkCanvUtil.c \
	$(GENERIC_DIR)/tkCanvWind.c $(GENERIC_DIR)/tkRectOval.c \
	$(GENERIC_DIR)/tkTrig.c $(GENERIC_DIR)/tkImage.c \
	$(GENERIC_DIR)/tkImgBmap.c $(GENERIC_DIR)/tkImgGIF.c \
	$(GENERIC_DIR)/tkImgPNG.c $(GENERIC_DIR)/tkImgPPM.c \
	$(GENERIC_DIR)/tkImgSVGnano.c $(GENERIC_DIR)/tkImgSVGnano.c \
	$(GENERIC_DIR)/tkImgPhoto.c $(GENERIC_DIR)/tkImgPhInstance.c \
	$(GENERIC_DIR)/tkImgListFormat.c $(GENERIC_DIR)/tkText.c \
	$(GENERIC_DIR)/tkTextBTree.c $(GENERIC_DIR)/tkTextDisp.c \
	$(GENERIC_DIR)/tkTextImage.c \
	$(GENERIC_DIR)/tkTextIndex.c $(GENERIC_DIR)/tkTextMark.c \
	$(GENERIC_DIR)/tkTextTag.c $(GENERIC_DIR)/tkTextWind.c \
	$(GENERIC_DIR)/tkOldConfig.c \
	$(GENERIC_DIR)/tkOldConfig.c $(GENERIC_DIR)/tkOldTest.c \
	$(GENERIC_DIR)/tkSquare.c $(GENERIC_DIR)/tkTest.c \
	$(GENERIC_DIR)/tkStubInit.c

TTK_SRCS = \
	$(TTK_DIR)/ttkBlink.c \
	$(TTK_DIR)/ttkButton.c \
	$(TTK_DIR)/ttkCache.c \
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519



520
521
522
523
524
525
526
527
528

529
530
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

602
603
604

605
606
607
608
609
610


611
612
613
614
615
616
617

618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654



655
656
657
658
659
660
661
497
498
499
500
501
502
503

504
505
506
507
508
509



510
511
512
513
514
515
516
517
518
519
520

521

522

523

524
525
526

527
528
529
530
531
532
533
534
535
536






















537
538
539
540
541
542
543
544
545
546
547
548
549

550

551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567

568
569
570

571
572
573
574
575
576

577
578
579






580

















581
582
583

584
585
586









587
588



589
590
591
592
593
594
595
596
597
598







-
+





-
-
-
+
+
+








-
+
-

-
+
-



-










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
+
-

















-
+


-
+





-
+
+

-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+


-
-
-
-
-
-
-
-
-


-
-
-
+
+
+







	$(UNIX_DIR)/tkAppInit.c $(UNIX_DIR)/tkUnix.c \
	$(UNIX_DIR)/tkUnix3d.c \
	$(UNIX_DIR)/tkUnixButton.c $(UNIX_DIR)/tkUnixColor.c \
	$(UNIX_DIR)/tkUnixConfig.c \
	$(UNIX_DIR)/tkUnixCursor.c \
	$(UNIX_DIR)/tkUnixDraw.c \
	$(UNIX_DIR)/tkUnixEmbed.c $(UNIX_DIR)/tkUnixEvent.c \
	$(UNIX_DIR)/tkUnixFocus.c $(GENERIC_DIR)/tkIcu.c \
	$(UNIX_DIR)/tkUnixFocus.c \
	$(UNIX_DIR)/tkUnixRFont.c \
	$(UNIX_DIR)/tkUnixFont.c $(UNIX_DIR)/tkUnixInit.c \
	$(UNIX_DIR)/tkUnixKey.c \
	$(UNIX_DIR)/tkUnixMenu.c $(UNIX_DIR)/tkUnixMenubu.c \
	$(UNIX_DIR)/tkUnixScale.c $(UNIX_DIR)/tkUnixScrlbr.c \
	$(UNIX_DIR)/tkUnixSelect.c $(UNIX_DIR)/tkUnixSend.c \
	$(UNIX_DIR)/tkUnixSysNotify $(UNIX_DIR)/tkUnixSysTray.c \
	$(UNIX_DIR)/tkUnixWm.c $(UNIX_DIR)/tkUnixXId.c
	$(UNIX_DIR)/tkUnixSelect.c \
	$(UNIX_DIR)/tkUnixSend.c $(UNIX_DIR)/tkUnixWm.c \
	$(UNIX_DIR)/tkUnixXId.c

AQUA_SRCS = \
	$(MAC_OSX_DIR)/tkMacOSXBitmap.c $(MAC_OSX_DIR)/tkMacOSXButton.c \
	$(MAC_OSX_DIR)/tkMacOSXClipboard.c $(MAC_OSX_DIR)/tkMacOSXColor.c \
	$(MAC_OSX_DIR)/tkMacOSXConfig.c $(MAC_OSX_DIR)/tkMacOSXCursor.c \
	$(MAC_OSX_DIR)/tkMacOSXDebug.c $(MAC_OSX_DIR)/tkMacOSXDialog.c \
	$(MAC_OSX_DIR)/tkMacOSXDraw.c $(MAC_OSX_DIR)/tkMacOSXEmbed.c \
	$(MAC_OSX_DIR)/tkMacOSXEntry.c $(MAC_OSX_DIR)/tkMacOSXEvent.c \
	$(MAC_OSX_DIR)/tkMacOSXFont.c $(MAC_OSX_DIR)/tkMacOSXFileTypes.c\
	$(MAC_OSX_DIR)/tkMacOSXFont.c $(MAC_OSX_DIR)/tkMacOSXHLEvents.c \
	$(MAC_OSX_DIR)/tkMacOSXHLEvents.c $(MAC_OSX_DIR)/tkMacOSXImage.c \
	$(MAC_OSX_DIR)/tkMacOSXInit.c $(MAC_OSX_DIR)/tkMacOSXKeyboard.c \
	$(MAC_OSX_DIR)/tkMacOSXKeyEvent.c \
	$(MAC_OSX_DIR)/tkMacOSXKeyEvent.c $(MAC_OSX_DIR)/tkMacOSXMenu.c \
	$(MAC_OSX_DIR)/tkMacOSXMenu.c \
	$(MAC_OSX_DIR)/tkMacOSXMenubutton.c $(MAC_OSX_DIR)/tkMacOSXMenus.c \
	$(MAC_OSX_DIR)/tkMacOSXMouseEvent.c $(MAC_OSX_DIR)/tkMacOSXNotify.c \
	$(MAC_OSX_DIR)/tkMacOSXRegion.c $(MAC_OSX_DIR)/tkMacOSXScrlbr.c \
	$(MAC_OSX_DIR)/tkMacOSXServices.c $(MAC_OSX_DIR)/tkMacOSXSysTray.c \
	$(MAC_OSX_DIR)/tkMacOSXSend.c $(MAC_OSX_DIR)/tkMacOSXSubwindows.c \
	$(MAC_OSX_DIR)/tkMacOSXTest.c $(MAC_OSX_DIR)/tkMacOSXWindowEvent.c \
	$(MAC_OSX_DIR)/tkMacOSXWm.c $(MAC_OSX_DIR)/tkMacOSXXStubs.c \
	$(GENERIC_DIR)/tkFileFilter.c $(GENERIC_DIR)/tkMacWinMenu.c \
	$(GENERIC_DIR)/tkPointer.c $(UNIX_DIR)/tkUnix3d.c \
	$(UNIX_DIR)/tkUnixScale.c $(XLIB_DIR)/xcolors.c $(XLIB_DIR)/xdraw.c \
	$(XLIB_DIR)/xgc.c $(XLIB_DIR)/ximage.c $(XLIB_DIR)/xutil.c \
	$(TTK_DIR)/ttkMacOSXTheme.c

SRCS = $(GENERIC_SRCS) $(@TK_WINDOWINGSYSTEM@_SRCS) @PLAT_SRCS@

###
# Tip 430 - ZipFS Modifications
###

TK_ZIP_FILE		= @TK_ZIP_FILE@
TK_VFS_ROOT		= libtk.vfs
TK_VFS_PATH		= ${TK_VFS_ROOT}/tk_library

HOST_CC			= @CC_FOR_BUILD@
HOST_EXEEXT		= @EXEEXT_FOR_BUILD@
HOST_OBJEXT		= @OBJEXT_FOR_BUILD@
ZIPFS_BUILD		= @ZIPFS_BUILD@
NATIVE_ZIP		= @ZIP_PROG@
ZIP_PROG_OPTIONS	= @ZIP_PROG_OPTIONS@
ZIP_PROG_VFSSEARCH	= @ZIP_PROG_VFSSEARCH@
SHARED_BUILD		= @SHARED_BUILD@
INSTALL_LIBRARIES	= @INSTALL_LIBRARIES@
INSTALL_MSGS		= @INSTALL_MSGS@

ZIP_INSTALL_OBJS	= @ZIP_INSTALL_OBJS@


AQUA_RESOURCES = \
	$(MAC_OSX_DIR)/tkAboutDlg.r $(MAC_OSX_DIR)/tkMacOSXCursors.r \
	$(MAC_OSX_DIR)/tkMacOSXXCursors.r

AQUA_WISH_RESOURCES = $(MAC_OSX_DIR)/tkMacOSXAETE.r

AQUA_HDRS = $(MAC_OSX_DIR)/tkMacOSX.h $(GENERIC_DIR)/tkIntXlibDecls.h

AQUA_XLIB_HDRS = $(XLIB_DIR)/X11/*.h $(XLIB_DIR)/xbytes.h

AQUA_PRIVATE_HDRS = $(MAC_OSX_DIR)/tkMacOSXPort.h $(MAC_OSX_DIR)/tkMacOSXInt.h

X11_PRIVATE_HDRS = $(UNIX_DIR)/tkUnixPort.h $(UNIX_DIR)/tkUnixInt.h $(GENERIC_DIR)/tkIntXlibDecls.h \
X11_PRIVATE_HDRS = $(UNIX_DIR)/tkUnixPort.h $(UNIX_DIR)/tkUnixInt.h $(GENERIC_DIR)/tkIntXlibDecls.h
	$(UNIX_DIR)/tkUnixDefault.h

# Currently private, eventually public
TTK_HDRS = $(TTK_DIR)/ttkTheme.h $(TTK_DIR)/ttkDecls.h

PUBLIC_HDRS = $(GENERIC_DIR)/tk.h $(GENERIC_DIR)/tkDecls.h \
	$(GENERIC_DIR)/tkPlatDecls.h $(@TK_WINDOWINGSYSTEM@_HDRS)

# The private headers we want installed for install-private-headers
PRIVATE_HDRS = $(GENERIC_DIR)/tkInt.h $(GENERIC_DIR)/tkIntDecls.h \
	$(GENERIC_DIR)/tkIntPlatDecls.h $(GENERIC_DIR)/tkPort.h \
	$(TTK_HDRS) $(@TK_WINDOWINGSYSTEM@_PRIVATE_HDRS)

DEMOPROGS = browse hello ixset rmt rolodex square tcolor timer widget

SHELL_ENV = \
	@LD_LIBRARY_PATH_VAR@="`pwd`:${TCL_BIN_DIR}:$${@LD_LIBRARY_PATH_VAR@}"; \
	export @LD_LIBRARY_PATH_VAR@; \
	TCL_LIBRARY=$(TCLDIR)/library; export TCL_LIBRARY; \
	TCL_LIBRARY=@TCL_SRC_DIR@/library; export TCL_LIBRARY; \
	TK_LIBRARY=@TK_SRC_DIR@/library; export TK_LIBRARY;

all: binaries libraries
all: binaries libraries doc

binaries: ${LIB_FILE} ${WISH_EXE}

libraries:

tkzipfile: ${TK_ZIP_FILE}
$(TOP_DIR)/doc/man.macros:
	$(INSTALL_DATA) @TCL_SRC_DIR@/doc/man.macros $(TOP_DIR)/doc/man.macros

${TK_ZIP_FILE}: ${ZIP_INSTALL_OBJS}
	@rm -rf ${TK_VFS_ROOT}
	@mkdir -p ${TK_VFS_PATH}
	@echo "creating ${TK_VFS_PATH} (prepare compression)"
	@if \
	    ln -s $(TOP_DIR)/library/* ${TK_VFS_PATH}/; \
doc: $(TOP_DIR)/doc/man.macros
	then : ; else \
	    cp -a $(TOP_DIR)/library/* ${TK_VFS_PATH}; \
	fi
	rm -rf ${TK_VFS_PATH}/demos
	@find ${TK_VFS_ROOT} -type d -empty -delete
	@echo "creating ${TK_ZIP_FILE} from ${TK_VFS_PATH}"
	-@if test "${ZIPFS_BUILD}" = "2" ; then \
	    cp ${TCL_BIN_DIR}/tclsh ${TK_VFS_ROOT}/../${TK_ZIP_FILE} || cp ${TCL_BIN_DIR}/../bin/tclsh${TCLVERSION} ${TK_VFS_ROOT}/../${TK_ZIP_FILE}; \
	    (zip=`(realpath '${NATIVE_ZIP}' || readlink -m '${NATIVE_ZIP}') 2>/dev/null || \
		(echo '${NATIVE_ZIP}' | sed "s?^\./?$$(pwd)/?")`; \
		cd ${TK_VFS_ROOT} && $$zip -J ../${TK_ZIP_FILE}) \
	fi
	@(zip=`(realpath '${NATIVE_ZIP}' || readlink -m '${NATIVE_ZIP}' || \
	    echo '${NATIVE_ZIP}' | sed "s?^\./?$$(pwd)/?")  2>/dev/null`; \
	    echo 'cd ${TK_VFS_ROOT} &&' $$zip '${ZIP_PROG_OPTIONS} ../${TK_ZIP_FILE} ${ZIP_PROG_VFSSEARCH}'; \
	    cd ${TK_VFS_ROOT} && \
	    $$zip ${ZIP_PROG_OPTIONS} ../${TK_ZIP_FILE} ${ZIP_PROG_VFSSEARCH} >/dev/null)

# The following target is configured by autoconf to generate either
# a shared library or non-shared library for Tk.
${LIB_FILE}: ${STUB_LIB_FILE} @LIB_RSRC_FILE@ ${OBJS} ${TK_ZIP_FILE}
${LIB_FILE}: ${STUB_LIB_FILE} @LIB_RSRC_FILE@ ${OBJS}
	rm -f $@
	@MAKE_LIB@
	@if test "${ZIPFS_BUILD}" = "1" ; then \
	    if test "x$(MACHER)" = "x" ; then \
		cat ${TK_ZIP_FILE} >> ${LIB_FILE}; \
	    else $(MACHER) append ${LIB_FILE} ${TK_ZIP_FILE} /tmp/macher_output; \
	         mv /tmp/macher_output ${LIB_FILE}; chmod u+x ${LIB_FILE}; \
	    fi; \
	    ${NATIVE_ZIP} -A ${LIB_FILE} \
	    || echo 'ignore zip-error by adjust sfx process (not executable?)'; \
	fi

${STUB_LIB_FILE}: ${STUB_LIB_OBJS}
	@if test "x${LIB_FILE}" = "xlibtcl9tk${MAJOR_VERSION}.${MINOR_VERSION}.dll"; then \
	    (cd ${TOP_DIR}/win; ${MAKE} tcl9tk${MAJOR_VERSION}${MINOR_VERSION}.dll); \
	    cp "${TOP_DIR}/win/tcl9tk${MAJOR_VERSION}${MINOR_VERSION}.dll" .; \
	@if test "x${LIB_FILE}" = "xlibtk${MAJOR_VERSION}.${MINOR_VERSION}.dll"; then \
	    (cd ${TOP_DIR}/win; ${MAKE} tk${MAJOR_VERSION}${MINOR_VERSION}.dll); \
	    cp "${TOP_DIR}/win/tk${MAJOR_VERSION}${MINOR_VERSION}.dll" .; \
	fi
	rm -f $@
	@MAKE_STUB_LIB@

# Build Aqua resource files
${TK_RSRC_FILE}: $(AQUA_RESOURCES)
	rm -f $@
674
675
676
677
678
679
680
681

682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704


705
706
707
708
709
710
711
712


713
714
715
716
717
718
719
611
612
613
614
615
616
617

618
619









620
621
622
623
624
625
626
627
628
629
630


631
632
633
634
635
636
637
638


639
640
641
642
643
644
645
646
647







-
+

-
-
-
-
-
-
-
-
-











-
-
+
+






-
-
+
+







	@echo ${OBJS}
# This targets actually build the objects needed for the lib in the above
# case
objs: ${OBJS}


${WISH_EXE}: $(TK_STUB_LIB_FILE) $(WISH_OBJS) $(TK_LIB_FILE) @APP_RSRC_FILE@
	${CC} ${CFLAGS} $(WISH_OBJS) @TK_BUILD_LIB_SPEC@ ${LDFLAGS} \
	${CC} ${CFLAGS} ${LDFLAGS} $(WISH_OBJS) @TK_BUILD_LIB_SPEC@ \
		$(WISH_LIBS) $(CC_SEARCH_FLAGS) -o ${WISH_EXE}
	@if test "${ZIPFS_BUILD}" = "2" ; then \
	    if test "x$(MACHER)" = "x" ; then \
		cat ${TK_ZIP_FILE} >> ${WISH_EXE}; \
	    else $(MACHER) append ${WISH_EXE} ${TK_ZIP_FILE} /tmp/macher_output; \
	         mv /tmp/macher_output ${LIB_FILE}; chmod u+x ${LIB_FILE}; \
	    fi; \
	    ${NATIVE_ZIP} -A ${WISH_EXE} \
	    || echo 'ignore zip-error by adjust sfx process (not executable?)'; \
	fi

# Resetting the LIB_RUNTIME_DIR below is required so that
# the generated tktest executable gets the build directory
# burned into its ld search path. This keeps tktest from
# picking up an already installed version of the Tcl or
# Tk shared libraries.

$(TKTEST_EXE): $(TKTEST_OBJS) $(TK_LIB_FILE)
	$(MAKE) tktest-real LIB_RUNTIME_DIR="`pwd`:$(TCL_BIN_DIR)"

tktest-real: ${TK_STUB_LIB_FILE}
	${CC} ${CFLAGS} $(TKTEST_OBJS) @TK_BUILD_LIB_SPEC@ ${LDFLAGS} $(WISH_LIBS) \
		${TK_STUB_LIB_FILE} ${TCL_STUB_LIB_SPEC} $(CC_SEARCH_FLAGS) -o $(TKTEST_EXE)
	${CC} ${CFLAGS} ${LDFLAGS} $(TKTEST_OBJS) ${TK_STUB_LIB_FILE} ${TCL_STUB_LIB_SPEC} @TK_BUILD_LIB_SPEC@ \
		$(WISH_LIBS) $(CC_SEARCH_FLAGS) -o $(TKTEST_EXE)

# # FIXME: This xttest rule seems to be broken in a number of ways.  It should
# # use CC_SEARCH_FLAGS, it does not include the shared lib location logic from
# # tktest, and it is not clear where this test.o object file comes from.
#
# xttest: test.o tkTest.o tkSquare.o $(TK_LIB_FILE) ${TK_STUB_LIB_FILE}
# 	${CC} ${CFLAGS} test.o tkTest.o tkSquare.o \
# 		@TK_BUILD_LIB_SPEC@ ${LDFLAGS} ${TK_STUB_LIB_FILE}  ${TCL_STUB_LIB_SPEC} \
# 	${CC} ${CFLAGS} ${LDFLAGS} test.o tkTest.o tkSquare.o \
# 		@TK_BUILD_LIB_SPEC@ ${TK_STUB_LIB_FILE}  ${TCL_STUB_LIB_SPEC} \
# 		$(WISH_LIBS) $(LD_SEARCH_FLAGS) -lXt -o xttest

# Note, in the target below TCL_LIBRARY needs to be set or else
# "make test" won't work in the case where the compilation directory
# isn't the same as the source directory.
# Specifying TESTFLAGS on the command line is the standard way to pass
# args to tcltest, ie:
749
750
751
752
753
754
755
756

757
758
759
760
761
762
763
764
765
766
767
768
769

770
771
772
773
774
775
776
777
778
779
780
781
782


783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798

799
800
801
802

803
804
805
806
807
808
809
810

811
812
813
814
815
816
817
818

819
820
821

822
823
824
825
826
827
828
829
830


831
832
833
834
835
836
837
838
839
840
841
842
843


844
845
846
847
848
849
850
677
678
679
680
681
682
683

684
685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704
705
706
707
708


709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

726
727
728


729



730
731
732


733



734




735

736

737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758


759
760
761
762
763
764
765
766
767







-
+












-
+











-
-
+
+















-
+


-
-
+
-
-
-



-
-
+
-
-
-

-
-
-
-
+
-

-
+
-








+
+











-
-
+
+








demo:
	$(SHELL_ENV) ./${WISH_EXE} $(TOP_DIR)/library/demos/widget

# This target can be used to run wish inside either gdb or insight
gdb: ${WISH_EXE}
	@echo "set env @LD_LIBRARY_PATH_VAR@=\"`pwd`:${TCL_BIN_DIR}:$${@LD_LIBRARY_PATH_VAR@}\"" > gdb.run
	@echo "set env TCL_LIBRARY=$(TCLDIR)/library" >> gdb.run
	@echo "set env TCL_LIBRARY=@TCL_SRC_DIR@/library" >> gdb.run
	@echo "set env TK_LIBRARY=@TK_SRC_DIR@/library" >> gdb.run
	gdb ./${WISH_EXE} --command=gdb.run
	rm gdb.run

VALGRINDARGS=--tool=memcheck --num-callers=8 --leak-resolution=high --leak-check=yes --show-reachable=yes -v

valgrind: $(TKTEST_EXE)
	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./$(TKTEST_EXE) $(TEST_DIR)/all.tcl -geometry +0+0 -singleproc 1 $(TESTFLAGS)

valgrindshell: $(TKTEST_EXE)
	$(SHELL_ENV) valgrind $(VALGRINDARGS) ./$(TKTEST_EXE) $(SCRIPT)

INSTALL_BASE_TARGETS = install-binaries ${INSTALL_LIBRARIES}
INSTALL_BASE_TARGETS = install-binaries install-libraries
INSTALL_DOC_TARGETS = install-doc
INSTALL_DEV_TARGETS = install-headers
INSTALL_DEMO_TARGETS = install-demos
INSTALL_EXTRA_TARGETS = @EXTRA_INSTALL@
INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DOC_TARGETS) $(INSTALL_DEV_TARGETS) \
		$(INSTALL_DEMO_TARGETS) $(INSTALL_EXTRA_TARGETS)

install: $(INSTALL_TARGETS)

install-strip:
	$(MAKE) $(INSTALL_TARGETS) \
		INSTALL_PROGRAM="STRIPPROG='${INSTALL_STRIP_PROGRAM}' $(INSTALL_PROGRAM) -s" \
		INSTALL_LIBRARY="STRIPPROG='${INSTALL_STRIP_LIBRARY}' $(INSTALL_LIBRARY) -s"
		INSTALL_PROGRAM="$(INSTALL_PROGRAM) ${INSTALL_STRIP_PROGRAM}" \
		INSTALL_LIBRARY="$(INSTALL_LIBRARY) ${INSTALL_STRIP_LIBRARY}"

install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE) ${WISH_EXE}
	@for i in "$(LIB_INSTALL_DIR)" "$(BIN_INSTALL_DIR)" \
	    "$(PKG_INSTALL_DIR)" "$(CONFIG_INSTALL_DIR)" ; \
	    do \
	    if [ ! -d "$$i" ] ; then \
		echo "Making directory $$i"; \
		$(INSTALL_DATA_DIR) "$$i"; \
		else true; \
		fi; \
	    done;
	@if test "x$(TK_SHARED_BUILD)" = "x1"; then \
	    echo "Creating package index $(PKG_INDEX)"; \
	    rm -f "$(PKG_INDEX)"; \
	    (\
	    echo "if {![package vsatisfies [package provide Tcl] 8.7-]} return";\
	    echo "if {[catch {package present Tcl 8.6-}]} return";\
	    relative=`echo | awk '{ORS=" "; split("$(TK_PKG_DIR)",a,"/"); for (f in a) {print ".."}}'`;\
	    if test "x$(DLL_INSTALL_DIR)" != "x$(BIN_INSTALL_DIR)"; then \
	    echo "if {[package vsatisfies [package provide Tcl] 9.0]} {";\
	    echo "    package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}$(TK_LIB_FILE_TCL9)]]]";\
	    echo "package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}$(TK_LIB_FILE)]] Tk]";\
	    echo "} else {";\
	    echo "    package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}$(TK_LIB_FILE_TCL8)]]]";\
	    echo "}";\
	    else \
	    echo "if {(\$$::tcl_platform(platform) eq \"unix\") && ([info exists ::env(DISPLAY)]";\
	    echo "	|| ([info exists ::argv] && (\"-display\" in \$$::argv)))} {";\
	    echo "    if {[package vsatisfies [package provide Tcl] 9.0]} {";\
	    echo "	package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin $(TK_LIB_FILE_TCL9)]]]";\
	    echo "    package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin $(TK_LIB_FILE)]] Tk]";\
	    echo "    } else {";\
	    echo "	package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin $(TK_LIB_FILE_TCL8)]]]";\
	    echo "    }";\
	    echo "} else {";\
	    echo "    if {[package vsatisfies [package provide Tcl] 9.0]} {";\
	    echo "	package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin tcl9tk${MAJOR_VERSION}${MINOR_VERSION}.dll]]]";\
	    echo "    } else {";\
	    echo "	package ifneeded tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin tk${MAJOR_VERSION}${MINOR_VERSION}.dll]]]";\
	    echo "    package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir $${relative}.. bin tk${MAJOR_VERSION}${MINOR_VERSION}.dll]] Tk]";\
	    echo "    }";\
	    echo "}";\
	    fi; \
	    fi \
	    echo "package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL) [list package require -exact tk $(MAJOR_VERSION).$(MINOR_VERSION)$(PATCH_LEVEL)]"\
	    ) > "$(PKG_INDEX)"; \
	    fi
	@echo "Installing $(LIB_FILE) to $(DLL_INSTALL_DIR)/"
	@@INSTALL_LIB@
	@chmod 555 "$(DLL_INSTALL_DIR)/$(LIB_FILE)"
	@if test -f "tk${MAJOR_VERSION}${MINOR_VERSION}.dll"; then \
	    $(INSTALL_LIBRARY) "tk${MAJOR_VERSION}${MINOR_VERSION}.dll" "$(DLL_INSTALL_DIR)";\
	    chmod 555 "$(DLL_INSTALL_DIR)/tk${MAJOR_VERSION}${MINOR_VERSION}.dll";\
	    $(INSTALL_LIBRARY) "../win/libtk${MAJOR_VERSION}${MINOR_VERSION}.a" "$(LIB_INSTALL_DIR)";\
	    chmod 555 "$(LIB_INSTALL_DIR)/libtk${MAJOR_VERSION}${MINOR_VERSION}.a";\
	fi
	@echo "Installing ${WISH_EXE} as $(BIN_INSTALL_DIR)/wish$(VERSION)${EXE_SUFFIX}"
	@$(INSTALL_PROGRAM) ${WISH_EXE} "$(BIN_INSTALL_DIR)/wish$(VERSION)${EXE_SUFFIX}"
	@echo "Installing tkConfig.sh to $(CONFIG_INSTALL_DIR)/"
	@$(INSTALL_DATA) tkConfig.sh "$(CONFIG_INSTALL_DIR)/tkConfig.sh"
	@if test "$(STUB_LIB_FILE)" != "" ; then \
	    echo "Installing $(STUB_LIB_FILE) to $(LIB_INSTALL_DIR)/"; \
	    @INSTALL_STUB_LIB@ ; \
	fi
	@EXTRA_INSTALL_BINARIES@
	@echo "Installing pkg-config file to $(LIB_INSTALL_DIR)/pkgconfig/"
	@$(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/pkgconfig"
	@$(INSTALL_DATA) tk.pc "$(LIB_INSTALL_DIR)/pkgconfig/tk.pc"
	@$(INSTALL_DATA_DIR) $(LIB_INSTALL_DIR)/pkgconfig
	@$(INSTALL_DATA) tk.pc $(LIB_INSTALL_DIR)/pkgconfig/tk.pc

install-libraries: libraries
	@for i in "$(SCRIPT_INSTALL_DIR)" "$(SCRIPT_INSTALL_DIR)/images" \
		"$(SCRIPT_INSTALL_DIR)/msgs" "$(SCRIPT_INSTALL_DIR)/ttk"; \
	    do \
	    if [ -n "$$i" -a ! -d "$$i" ] ; then \
		echo "Making directory $$i"; \
977
978
979
980
981
982
983
984
985
986


987
988
989
990
991

992
993
994
995
996
997
998
894
895
896
897
898
899
900



901
902

903
904
905

906
907
908
909
910
911
912
913







-
-
-
+
+
-



-
+








Makefile: $(UNIX_DIR)/Makefile.in
	$(SHELL) config.status
#tkConfig.h: $(UNIX_DIR)/tkConfig.h.in
#	$(SHELL) config.status

clean:
	rm -rf *.vfs
	rm -f *.a *.o libtk* libtcl9tk* core errs *~ \#* TAGS *.E a.out \
		errors ${WISH_EXE} $(TKTEST_EXE) lib.exp Tk *.rsrc \
	rm -f *.a *.o libtk* core errs *~ \#* TAGS *.E a.out \
		errors ${WISH_EXE} $(TKTEST_EXE) lib.exp Tk *.rsrc
		 *.zip

distclean: clean
	rm -rf Makefile config.status config.cache config.log tkConfig.sh \
		tkConfig.h *.plist Tk.framework tk.pc tkUuid.h
		tkConfig.h *.plist Tk.framework tk.pc

depend:
	makedepend -- $(DEPEND_SWITCHES) -- $(SRCS)

# Test binaries.  The rule for tkTestInit.o is complicated because
# it is is compiled from tkAppInit.c.  Can't use the "-o" option
# because this doesn't work on some strange compilers (e.g. UnixWare).
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140


1141
1142
1143
1144
1145
1146
1147
1005
1006
1007
1008
1009
1010
1011



























1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026


1027
1028
1029
1030
1031
1032
1033
1034
1035







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















-
-
+
+








tkOption.o: $(GENERIC_DIR)/tkOption.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkOption.c

tkPack.o: $(GENERIC_DIR)/tkPack.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkPack.c

# TIP #59, embedding of configuration information into the binary library.
#
# Part of Tk's configuration information are the paths where it was installed
# and where it will look for its libraries (which can be different). We derive
# this information from the variables which can be overridden by the user. As
# every path can be configured separately we do not remember one general
# prefix/exec_prefix but all the different paths individually.

tkPkgConfig.o: $(GENERIC_DIR)/tkPkgConfig.c
	$(CC) -c $(CC_SWITCHES)					\
		-DCFG_INSTALL_LIBDIR="\"$(LIB_INSTALL_DIR)\"" \
		-DCFG_INSTALL_BINDIR="\"$(BIN_INSTALL_DIR)\"" \
		-DCFG_INSTALL_SCRDIR="\"$(SCRIPT_INSTALL_DIR)\"" \
		-DCFG_INSTALL_INCDIR="\"$(INCLUDE_INSTALL_DIR)\"" \
		-DCFG_INSTALL_DOCDIR="\"$(MAN_INSTALL_DIR)\"" \
		-DCFG_INSTALL_DEMODIR="\"$(DEMO_INSTALL_DIR)\"" \
		\
		-DCFG_RUNTIME_LIBDIR="\"$(libdir)\"" \
		-DCFG_RUNTIME_BINDIR="\"$(bindir)\"" \
		-DCFG_RUNTIME_SCRDIR="\"$(TK_LIBRARY)\"" \
		-DCFG_RUNTIME_INCDIR="\"$(includedir)\"" \
		-DCFG_RUNTIME_DOCDIR="\"$(mandir)\"" \
		-DCFG_RUNTIME_DLLFILE="\"$(TK_LIB_FILE)\"" \
		-DCFG_RUNTIME_DEMODIR="\"$(DEMO_INSTALL_DIR)\"" \
		\
		$(GENERIC_DIR)/tkPkgConfig.c

tkPlace.o: $(GENERIC_DIR)/tkPlace.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkPlace.c

tkSelect.o: $(GENERIC_DIR)/tkSelect.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkSelect.c

tkStyle.o: $(GENERIC_DIR)/tkStyle.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkStyle.c

tkUtil.o: $(GENERIC_DIR)/tkUtil.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkUtil.c

tkVisual.o: $(GENERIC_DIR)/tkVisual.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkVisual.c

tkWindow.o: $(GENERIC_DIR)/tkWindow.c tkUuid.h
	$(CC) -c $(CC_SWITCHES) -I. $(GENERIC_DIR)/tkWindow.c
tkWindow.o: $(GENERIC_DIR)/tkWindow.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkWindow.c

tkButton.o: $(GENERIC_DIR)/tkButton.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkButton.c

tkEntry.o: $(GENERIC_DIR)/tkEntry.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkEntry.c

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243



1244

1245
1246
1247
1248
1249
1250
1251
1095
1096
1097
1098
1099
1100
1101



1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119



1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136







-
-
-


















-
-
-






+
+
+
-
+








tkRectOval.o: $(GENERIC_DIR)/tkRectOval.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkRectOval.c

tkTrig.o: $(GENERIC_DIR)/tkTrig.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkTrig.c

tkIcu.o: $(GENERIC_DIR)/tkIcu.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkIcu.c

tkImage.o: $(GENERIC_DIR)/tkImage.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImage.c

tkImgBmap.o: $(GENERIC_DIR)/tkImgBmap.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgBmap.c

tkImgListFormat.o: $(GENERIC_DIR)/tkImgListFormat.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgListFormat.c

tkImgGIF.o: $(GENERIC_DIR)/tkImgGIF.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgGIF.c

tkImgPNG.o: $(GENERIC_DIR)/tkImgPNG.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgPNG.c

tkImgPPM.o: $(GENERIC_DIR)/tkImgPPM.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgPPM.c

tkImgSVGnano.o: $(GENERIC_DIR)/tkImgSVGnano.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgSVGnano.c

tkImgPhoto.o: $(GENERIC_DIR)/tkImgPhoto.c $(GENERIC_DIR)/tkImgPhoto.h
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgPhoto.c

tkImgPhInstance.o: $(GENERIC_DIR)/tkImgPhInstance.c $(GENERIC_DIR)/tkImgPhoto.h
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkImgPhInstance.c

tkOldTest.o: $(GENERIC_DIR)/tkOldTest.c
	$(CC) -c $(APP_CC_SWITCHES) $(GENERIC_DIR)/tkOldTest.c

tkTest.o: $(GENERIC_DIR)/tkTest.c tkUuid.h
tkTest.o: $(GENERIC_DIR)/tkTest.c
	$(CC) -c $(APP_CC_SWITCHES) $(GENERIC_DIR)/tkTest.c

tkText.o: $(GENERIC_DIR)/tkText.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkText.c

tkTextBTree.o: $(GENERIC_DIR)/tkTextBTree.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkTextBTree.c
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281
1282
1283
1284
1285
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
1170







-
+







tkStubInit.o: $(GENERIC_DIR)/tkStubInit.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkStubInit.c

# Stub library binaries, these must be compiled for use in a shared library
# even though they will be placed in a static archive

tkStubLib.o: $(GENERIC_DIR)/tkStubLib.c
	$(CC) -c $(CC_SWITCHES) @CFLAGS_NOLTO@ $(GENERIC_DIR)/tkStubLib.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkStubLib.c

tkUndo.o: $(GENERIC_DIR)/tkUndo.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkUndo.c

tkUnix.o: $(UNIX_DIR)/tkUnix.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnix.c

1314
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1199
1200
1201
1202
1203
1204
1205

1206
1207
1208
1209
1210
1211
1212
1213







-
+







	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixFont.c

# NB: tkUnixRFont.o uses nondefault CFLAGS
tkUnixRFont.o: $(UNIX_DIR)/tkUnixRFont.c
	$(CC) -c $(CC_SWITCHES) $(XFT_CFLAGS) $(UNIX_DIR)/tkUnixRFont.c

tkUnixInit.o: $(UNIX_DIR)/tkUnixInit.c tkConfig.sh
	$(CC) -c $(CC_SWITCHES) \
	$(CC) -c $(CC_SWITCHES) -DTK_LIBRARY=\"${TK_LIBRARY}\" \
	    $(UNIX_DIR)/tkUnixInit.c

tkUnixKey.o: $(UNIX_DIR)/tkUnixKey.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixKey.c

tkUnixMenu.o: $(UNIX_DIR)/tkUnixMenu.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixMenu.c
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1223
1224
1225
1226
1227
1228
1229






1230
1231
1232
1233
1234
1235
1236







-
-
-
-
-
-








tkUnixSelect.o: $(UNIX_DIR)/tkUnixSelect.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixSelect.c

tkUnixSend.o: $(UNIX_DIR)/tkUnixSend.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixSend.c

tkUnixSysNotify.o: $(UNIX_DIR)/tkUnixSysNotify.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixSysNotify.c

tkUnixSysTray.o: $(UNIX_DIR)/tkUnixSysTray.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixSysTray.c

tkUnixWm.o: $(UNIX_DIR)/tkUnixWm.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixWm.c

tkUnixXId.o: $(UNIX_DIR)/tkUnixXId.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tkUnixXId.c

tkMacOSXBitmap.o: $(MAC_OSX_DIR)/tkMacOSXBitmap.c
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413
1265
1266
1267
1268
1269
1270
1271



1272
1273
1274
1275
1276
1277



1278

1279
1280
1281
1282
1283
1284
1285
1286







-
-
-






-
-
-

-
+








tkMacOSXEntry.o: $(MAC_OSX_DIR)/tkMacOSXEntry.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXEntry.c

tkMacOSXEvent.o: $(MAC_OSX_DIR)/tkMacOSXEvent.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXEvent.c

tkMacOSXFileTypes.o: $(MAC_OSX_DIR)/tkMacOSXFileTypes.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXFileTypes.c

tkMacOSXFont.o: $(MAC_OSX_DIR)/tkMacOSXFont.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXFont.c

tkMacOSXHLEvents.o: $(MAC_OSX_DIR)/tkMacOSXHLEvents.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXHLEvents.c

tkMacOSXImage.o: $(MAC_OSX_DIR)/tkMacOSXImage.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXImage.c

tkMacOSXInit.o: $(MAC_OSX_DIR)/tkMacOSXInit.c tkConfig.sh
	$(CC) -c $(CC_SWITCHES) \
	$(CC) -c $(CC_SWITCHES) -DTK_LIBRARY=\"${TK_LIBRARY}\" \
	    $(MAC_OSX_DIR)/tkMacOSXInit.c

tkMacOSXKeyboard.o: $(MAC_OSX_DIR)/tkMacOSXKeyboard.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXKeyboard.c

tkMacOSXKeyEvent.o: $(MAC_OSX_DIR)/tkMacOSXKeyEvent.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXKeyEvent.c
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1296
1297
1298
1299
1300
1301
1302



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329



1330
1331
1332
1333
1334
1335
1336







-
-
-












-
-
-















-
-
-








tkMacOSXMouseEvent.o: $(MAC_OSX_DIR)/tkMacOSXMouseEvent.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXMouseEvent.c

tkMacOSXNotify.o: $(MAC_OSX_DIR)/tkMacOSXNotify.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXNotify.c

tkMacOSXPrint.o: $(MAC_OSX_DIR)/tkMacOSXPrint.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXPrint.c

tkMacOSXRegion.o: $(MAC_OSX_DIR)/tkMacOSXRegion.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXRegion.c

tkMacOSXScale.o: $(MAC_OSX_DIR)/tkMacOSXScale.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXScale.c

tkMacOSXScrlbr.o: $(MAC_OSX_DIR)/tkMacOSXScrlbr.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXScrlbr.c

tkMacOSXSend.o: $(MAC_OSX_DIR)/tkMacOSXSend.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXSend.c

tkMacOSXServices.o: $(MAC_OSX_DIR)/tkMacOSXServices.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXServices.c

tkMacOSXSubwindows.o: $(MAC_OSX_DIR)/tkMacOSXSubwindows.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXSubwindows.c

tkMacOSXTest.o: $(MAC_OSX_DIR)/tkMacOSXTest.c
	$(CC) -c $(APP_CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXTest.c

tkMacOSXWindowEvent.o: $(MAC_OSX_DIR)/tkMacOSXWindowEvent.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXWindowEvent.c

tkMacOSXWm.o: $(MAC_OSX_DIR)/tkMacOSXWm.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXWm.c

tkMacOSXXStubs.o: $(MAC_OSX_DIR)/tkMacOSXXStubs.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXXStubs.c

tkMacOSXSysTray.o: $(MAC_OSX_DIR)/tkMacOSXSysTray.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/tkMacOSXSysTray.c

tkFileFilter.o: $(GENERIC_DIR)/tkFileFilter.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkFileFilter.c

tkMacWinMenu.o: $(GENERIC_DIR)/tkMacWinMenu.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tkMacWinMenu.c

tkPointer.o: $(GENERIC_DIR)/tkPointer.c
1556
1557
1558
1559
1560
1561
1562
1563

1564
1565
1566
1567
1568
1569
1570
1420
1421
1422
1423
1424
1425
1426

1427
1428
1429
1430
1431
1432
1433
1434







-
+







ttkState.o: $(TTK_DIR)/ttkState.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkState.c

ttkStubInit.o: $(TTK_DIR)/ttkStubInit.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkStubInit.c

ttkStubLib.o: $(TTK_DIR)/ttkStubLib.c
	$(CC) -c $(CC_SWITCHES) @CFLAGS_NOLTO@ $(TTK_DIR)/ttkStubLib.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkStubLib.c

ttkTagSet.o: $(TTK_DIR)/ttkTagSet.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkTagSet.c

ttkTheme.o: $(TTK_DIR)/ttkTheme.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkTheme.c

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1443
1444
1445
1446
1447
1448
1449





1450
1451
1452
1453
1454
1455
1456







-
-
-
-
-








ttkWidget.o: $(TTK_DIR)/ttkWidget.c
	$(CC) -c $(CC_SWITCHES) $(TTK_DIR)/ttkWidget.c

ttkMacOSXTheme.o: $(MAC_OSX_DIR)/ttkMacOSXTheme.c
	$(CC) -c $(CC_SWITCHES) $(MAC_OSX_DIR)/ttkMacOSXTheme.c

tkUuid.h: $(TOP_DIR)/manifest.uuid
	echo "#define TK_VERSION_UUID \\" >$@
	cat $(TOP_DIR)/manifest.uuid >>$@
	echo "" >>$@

.c.o:
	$(CC) -c $(CC_SWITCHES) $<

#
# Target to regenerate header files and stub files from the *.decls tables.
#

1659
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
1518
1519
1520
1521
1522
1523
1524

1525
1526
1527
1528
1529
1530
1531
1532



1533
1534
1535
1536
1537
1538
1539
1540
1541





1542
1543

1544




1545
1546
1547
1548
1549

1550
1551
1552


1553
1554
1555
1556
1557
1558
1559
1560





1561
1562
1563
1564
1565
1566
1567
1568






1569
1570
1571
1572
1573
1574
1575
1576
1577
1578





1579
1580
1581
1582
1583
1584
1585




1586
1587
1588
1589
1590
1591

1592
1593




1594
1595
1596
1597
1598
1599
1600
1601
1602











1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616



1617
1618
1619
1620
1621

1622
1623
1624

1625
1626
1627

1628
1629
1630

1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646

1647
1648
1649






1650
1651
1652
1653
1654
1655
1656


1657
1658


1659
1660
1661
1662
1663
1664
1665







-
+







-
-
-
+








-
-
-
-
-
+

-
+
-
-
-
-
+
+
+
+

-
+


-
-
+
+






-
-
-
-
-
+
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
+
+

+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
+
+
+



-
+

-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+


-
+


-
+


-
+


-
+












-
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+
-
-







	mkdir -p RPMS/i386
	rpmbuild -bb THIS.TK.SPEC
	mv RPMS/i386/*.rpm .
	rm -rf RPMS THIS.TK.SPEC

#
# Target to create a proper Tk distribution from information in the
# source directory.  DISTDIR must be defined to indicate where
# master source directory.  DISTDIR must be defined to indicate where
# to put the distribution.  DISTDIR must be an absolute path name.
#

DISTROOT = /tmp/dist
DISTNAME = tk${VERSION}${PATCH_LEVEL}
ZIPNAME	 = tk${MAJOR_VERSION}${MINOR_VERSION}${PATCH_LEVEL}-src.zip
DISTDIR	 = $(DISTROOT)/$(DISTNAME)
DIST_INSTALL_DATA   = $(INSTALL) -p -m 644
DIST_INSTALL_SCRIPT = $(INSTALL) -p -m 755

TCLDIR   = @TCL_SRC_DIR@
$(UNIX_DIR)/configure: $(UNIX_DIR)/configure.ac $(UNIX_DIR)/tcl.m4 \
		$(UNIX_DIR)/aclocal.m4
	cd $(UNIX_DIR); autoconf
$(MAC_OSX_DIR)/configure: $(MAC_OSX_DIR)/configure.ac $(UNIX_DIR)/configure
	cd $(MAC_OSX_DIR); autoconf
$(UNIX_DIR)/tkConfig.h.in: $(MAC_OSX_DIR)/configure
	cd $(MAC_OSX_DIR); autoheader; touch $@

$(TOP_DIR)/manifest.uuid:
	printf "git-" >$(TOP_DIR)/manifest.uuid
	(cd $(TOP_DIR); git rev-parse HEAD >>$(TOP_DIR)/manifest.uuid || printf "unknown" >$(TOP_DIR)/manifest.uuid)

dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tkConfig.h.in $(UNIX_DIR)/tk.pc.in $(MAC_OSX_DIR)/configure $(TOP_DIR)/doc/man.macros $(TOP_DIR)/manifest.uuid
dist:   $(UNIX_DIR)/configure $(UNIX_DIR)/tkConfig.h.in $(UNIX_DIR)/tk.pc.in $(MAC_OSX_DIR)/configure genstubs
	rm -rf $(DISTDIR)
	$(INSTALL_DATA_DIR) $(DISTDIR)/unix
	mkdir -p $(DISTDIR)/unix
	$(DIST_INSTALL_DATA) $(TOP_DIR)/manifest.uuid $(DISTDIR)
	$(DIST_INSTALL_DATA) $(UNIX_DIR)/*.c $(UNIX_DIR)/*.h $(DISTDIR)/unix
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(UNIX_DIR)/Makefile.in $(DISTDIR)/unix
	$(DIST_INSTALL_DATA) $(UNIX_DIR)/configure.ac $(UNIX_DIR)/tk.spec \
	cp -p $(UNIX_DIR)/*.c $(UNIX_DIR)/*.h $(DISTDIR)/unix
	cp $(TOP_DIR)/license.terms $(UNIX_DIR)/Makefile.in $(DISTDIR)/unix
	chmod 664 $(DISTDIR)/unix/Makefile.in
	cp $(UNIX_DIR)/configure $(UNIX_DIR)/configure.ac $(UNIX_DIR)/tk.spec \
		$(UNIX_DIR)/aclocal.m4 $(UNIX_DIR)/tcl.m4 \
		$(UNIX_DIR)/tkConfig.sh.in $(UNIX_DIR)/install-sh \
		$(UNIX_DIR)/tkConfig.sh.in $(TCLDIR)/unix/install-sh \
		$(UNIX_DIR)/README $(UNIX_DIR)/installManPage \
		$(UNIX_DIR)/tkConfig.h.in $(UNIX_DIR)/tk.pc.in $(DISTDIR)/unix
	$(DIST_INSTALL_SCRIPT) $(UNIX_DIR)/configure $(DISTDIR)/unix
	$(INSTALL_DATA_DIR) $(DISTDIR)/bitmaps
	chmod 775 $(DISTDIR)/unix/configure $(DISTDIR)/unix/configure.ac
	mkdir $(DISTDIR)/bitmaps
	@(cd $(TOP_DIR); for i in bitmaps/* ; do \
	    if [ -f $$i ] ; then \
		sed -e 's/static char/static unsigned char/' \
		       $$i > $(DISTDIR)/$$i; \
	    fi; \
	done;)
	$(INSTALL_DATA_DIR) $(DISTDIR)/generic
	$(DIST_INSTALL_DATA) $(GENERIC_DIR)/*.[ch] $(DISTDIR)/generic
	$(DIST_INSTALL_DATA) $(GENERIC_DIR)/*.decls $(DISTDIR)/generic
	$(DIST_INSTALL_DATA) $(GENERIC_DIR)/README $(DISTDIR)/generic
	$(DIST_INSTALL_DATA) $(TOP_DIR)/changes.md $(TOP_DIR)/README.md \
	mkdir $(DISTDIR)/generic
	cp -p $(GENERIC_DIR)/*.[ch] $(DISTDIR)/generic
	cp -p $(GENERIC_DIR)/*.decls $(DISTDIR)/generic
	cp -p $(GENERIC_DIR)/README $(DISTDIR)/generic
	cp -p $(TOP_DIR)/changes $(TOP_DIR)/ChangeLog \
		$(TOP_DIR)/ChangeLog.2??? $(TOP_DIR)/README \
		$(TOP_DIR)/license.terms $(DISTDIR)
	rm -f $(DISTDIR)/generic/blt*.[ch]
	$(INSTALL_DATA_DIR) $(DISTDIR)/generic/ttk
	$(DIST_INSTALL_DATA) $(TTK_DIR)/*.[ch] $(TTK_DIR)/ttk.decls \
		$(DISTDIR)/generic/ttk
	$(INSTALL_DATA_DIR) $(DISTDIR)/win
	$(DIST_INSTALL_DATA) $(TOP_DIR)/win/*.in $(DISTDIR)/win
	$(DIST_INSTALL_DATA) $(TOP_DIR)/win/configure.ac \
	mkdir $(DISTDIR)/generic/ttk
	cp -p $(TTK_DIR)/*.[ch] $(TTK_DIR)/ttk.decls \
		$(TTK_DIR)/ttkGenStubs.tcl $(DISTDIR)/generic/ttk
	mkdir $(DISTDIR)/win
	cp $(TOP_DIR)/win/Makefile.in $(DISTDIR)/win
	cp $(TOP_DIR)/win/configure.ac \
		$(TOP_DIR)/win/configure \
		$(TOP_DIR)/win/tkConfig.sh.in \
		$(TOP_DIR)/win/aclocal.m4 $(TOP_DIR)/win/tcl.m4 \
		$(DISTDIR)/win
		$(TOP_DIR)/win/*.[ch] $(TOP_DIR)/win/*.bat \
		$(TOP_DIR)/win/*.vc $(TOP_DIR)/win/README \
		$(TOP_DIR)/license.terms \
		$(DISTDIR)/win
	$(DIST_INSTALL_SCRIPT) $(TOP_DIR)/win/configure $(DISTDIR)/win
	cp -p $(TOP_DIR)/win/*.[ch] $(TOP_DIR)/win/*.bat $(DISTDIR)/win
	cp -p $(TOP_DIR)/win/makefile.* $(DISTDIR)/win
	cp -p $(TOP_DIR)/win/rules.vc $(DISTDIR)/win
	cp -p $(TOP_DIR)/win/README $(DISTDIR)/win
	cp -p $(TOP_DIR)/license.terms $(DISTDIR)/win
	mkdir $(DISTDIR)/win/rc
	cp -p $(TOP_DIR)/win/wish.exe.manifest.in $(DISTDIR)/win/
	$(INSTALL_DATA_DIR) $(DISTDIR)/win/rc
	$(DIST_INSTALL_DATA) $(TOP_DIR)/win/rc/*.{rc,cur,ico} $(DISTDIR)/win/rc
	$(INSTALL_DATA_DIR) $(DISTDIR)/macosx
	$(DIST_INSTALL_DATA) $(MAC_OSX_DIR)/GNUmakefile $(MAC_OSX_DIR)/README \
	cp -p $(TOP_DIR)/win/rc/*.{rc,cur,ico,bmp} $(DISTDIR)/win/rc
	mkdir $(DISTDIR)/macosx
	cp -p $(MAC_OSX_DIR)/GNUmakefile $(MAC_OSX_DIR)/README \
		$(MAC_OSX_DIR)/*.icns $(MAC_OSX_DIR)/*.tiff \
		$(MAC_OSX_DIR)/*.[ch] $(MAC_OSX_DIR)/*.in \
		$(MAC_OSX_DIR)/*.ac $(MAC_OSX_DIR)/*.xcconfig \
		$(MAC_OSX_DIR)/*.sdef \
		$(MAC_OSX_DIR)/*.sdef $(MAC_OSX_DIR)/configure \
		$(DISTDIR)/macosx
	$(DIST_INSTALL_SCRIPT) $(MAC_OSX_DIR)/configure $(DISTDIR)/macosx
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(DISTDIR)/macosx
	$(INSTALL_DATA_DIR) $(DISTDIR)/macosx/Tk.xcodeproj
	$(DIST_INSTALL_DATA) $(MAC_OSX_DIR)/Tk.xcodeproj/project.pbxproj \
	cp -p $(TOP_DIR)/license.terms $(DISTDIR)/macosx
	mkdir $(DISTDIR)/macosx/Tk.xcode
	cp -p $(MAC_OSX_DIR)/Tk.xcode/project.pbxproj \
		$(MAC_OSX_DIR)/Tk.xcode/default.pbxuser \
		$(DISTDIR)/macosx/Tk.xcode
	mkdir $(DISTDIR)/macosx/Tk.xcodeproj
	cp -p $(MAC_OSX_DIR)/Tk.xcodeproj/project.pbxproj \
		$(MAC_OSX_DIR)/Tk.xcodeproj/default.pbxuser \
		$(DISTDIR)/macosx/Tk.xcodeproj
	$(INSTALL_DATA_DIR) $(DISTDIR)/compat
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms \
		$(TOP_DIR)/compat/stdbool.h $(DISTDIR)/compat
	$(INSTALL_DATA_DIR) $(DISTDIR)/xlib
	$(DIST_INSTALL_DATA) $(XLIB_DIR)/*.[ch] $(DISTDIR)/xlib
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(DISTDIR)/xlib
	$(INSTALL_DATA_DIR) $(DISTDIR)/xlib/X11
	$(DIST_INSTALL_DATA) $(XLIB_DIR)/X11/*.h $(DISTDIR)/xlib/X11
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(DISTDIR)/xlib/X11
	$(INSTALL_DATA_DIR) $(DISTDIR)/library
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(TOP_DIR)/library/*.tcl \
	mkdir $(DISTDIR)/compat
	cp -p $(TOP_DIR)/license.terms $(TCLDIR)/compat/unistd.h \
		$(TCLDIR)/compat/stdlib.h \
		$(DISTDIR)/compat
	mkdir $(DISTDIR)/xlib
	cp -p $(XLIB_DIR)/*.[ch] $(DISTDIR)/xlib
	cp -p $(TOP_DIR)/license.terms $(DISTDIR)/xlib
	mkdir $(DISTDIR)/xlib/X11
	cp -p $(XLIB_DIR)/X11/*.h $(DISTDIR)/xlib/X11
	cp -p $(TOP_DIR)/license.terms $(DISTDIR)/xlib/X11
	mkdir $(DISTDIR)/library
	cp -p $(TOP_DIR)/license.terms $(TOP_DIR)/library/*.tcl \
		$(TOP_DIR)/library/tclIndex \
		$(DISTDIR)/library
	$(INSTALL_DATA_DIR) $(DISTDIR)/library/ttk
	$(DIST_INSTALL_DATA) $(TOP_DIR)/library/ttk/*.tcl $(DISTDIR)/library/ttk
	$(INSTALL_DATA_DIR) $(DISTDIR)/library/images
	mkdir $(DISTDIR)/library/ttk
	cp -p $(TOP_DIR)/library/ttk/*.tcl $(DISTDIR)/library/ttk
	mkdir $(DISTDIR)/library/images
	@(cd $(TOP_DIR); for i in library/images/* ; do \
	    if [ -f $$i ] ; then \
		$(DIST_INSTALL_DATA) $$i $(DISTDIR)/$$i; \
		cp $$i $(DISTDIR)/$$i; \
	    fi; \
	done;)
	$(INSTALL_DATA_DIR) $(DISTDIR)/library/msgs
	mkdir $(DISTDIR)/library/msgs
	@(cd $(TOP_DIR); for i in library/msgs/*.msg ; do \
	    if [ -f $$i ] ; then \
		$(DIST_INSTALL_DATA) $$i $(DISTDIR)/$$i; \
		cp $$i $(DISTDIR)/$$i; \
	    fi; \
	done;)
	$(INSTALL_DATA_DIR) $(DISTDIR)/library/demos
	mkdir $(DISTDIR)/library/demos
	cp -pr $(TOP_DIR)/library/demos/*.tcl \
		$(TOP_DIR)/library/demos/*.msg \
		$(TOP_DIR)/library/demos/tclIndex \
		$(TOP_DIR)/library/demos/browse \
		$(TOP_DIR)/library/demos/hello $(TOP_DIR)/library/demos/ixset \
		$(TOP_DIR)/library/demos/rmt $(TOP_DIR)/library/demos/rolodex \
		$(TOP_DIR)/library/demos/square \
		$(TOP_DIR)/library/demos/tcolor \
		$(TOP_DIR)/library/demos/timer \
		$(TOP_DIR)/library/demos/widget \
		$(TOP_DIR)/library/demos/README \
		$(TOP_DIR)/license.terms $(DISTDIR)/library/demos
	$(INSTALL_DATA_DIR) $(DISTDIR)/library/demos/images
	mkdir $(DISTDIR)/library/demos/images
	@(cd $(TOP_DIR); for i in library/demos/images/* ; do \
	    if [ -f $$i ] ; then \
		$(DIST_INSTALL_DATA) $$i $(DISTDIR)/$$i; \
		cp $$i $(DISTDIR)/$$i; \
	    fi; \
	done;)
	$(INSTALL_DATA_DIR) $(DISTDIR)/doc
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(TOP_DIR)/doc/*.[13n] \
		$(TOP_DIR)/doc/man.macros $(DISTDIR)/doc
	$(INSTALL_DATA_DIR) $(DISTDIR)/tests
	$(DIST_INSTALL_DATA) $(TOP_DIR)/license.terms $(TEST_DIR)/*.{test,tcl} \
		$(TEST_DIR)/README $(TEST_DIR)/*.{gif,png,ppm,xbm} \
	mkdir $(DISTDIR)/doc
	cp -p $(TOP_DIR)/license.terms $(TOP_DIR)/doc/*.[13n] \
		$(TCLDIR)/doc/man.macros $(DISTDIR)/doc
	mkdir $(DISTDIR)/tests
	cp -p $(TOP_DIR)/license.terms $(TEST_DIR)/*.{test,tcl} \
		$(TEST_DIR)/README $(TEST_DIR)/*.{gif,ppm,xbm} \
		$(TEST_DIR)/option.file* $(DISTDIR)/tests
	$(INSTALL_DATA_DIR) $(DISTDIR)/tests/ttk
	$(DIST_INSTALL_DATA) $(TEST_DIR)/ttk/*.{svg,test,tcl} $(DISTDIR)/tests/ttk
	mkdir $(DISTDIR)/tests/ttk
	cp -p $(TEST_DIR)/ttk/*.{test,tcl} $(DISTDIR)/tests/ttk
	mkdir -p $(DISTDIR)/.github/workflows
	cp -p $(TOP_DIR)/.github/workflows/*.yml $(DISTDIR)/.github/workflows

alldist: dist
	rm -f $(DISTROOT)/$(DISTNAME)-src.tar.gz $(DISTROOT)/$(ZIPNAME)
	cd $(DISTROOT); tar cf $(DISTNAME)-src.tar $(DISTNAME); \
		gzip -9 $(DISTNAME)-src.tar; zip -qr8 $(ZIPNAME) $(DISTNAME)

#

Changes to unix/README.

1
2
3
4
5
6
7
8
9

10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8

9
10
11
12

13
14
15
16
17
18
19
20








-
+



-
+







Tk UNIX README
--------------

This is the directory where you configure, compile, test, and install UNIX
versions of Tk. This directory also contains source files for Tk that are
specific to UNIX.

The information in this file is maintained at:
	https://www.tcl-lang.org//doc/howto/compile.html
	http://www.tcl.tk/doc/howto/compile.html

For information on platforms where Tcl/Tk is known to compile, along with any
porting notes for getting it to work on those platforms, see:
	https://www.tcl-lang.org//software/tcltk/platforms.html
	http://www.tcl.tk/software/tcltk/platforms.html

The rest of this file contains instructions on how to do this. The release
should compile and run either "out of the box" or with trivial changes on any
UNIX-like system that approximates POSIX, BSD, or System V. We know that it
runs on workstations from Sun, H-P, DEC, IBM, and SGI, as well as PCs running
Linux, BSDI, and SCO UNIX. To compile for a PC running Windows, see the README
file in the directory ../win. To compile for MacOSX, see the README file in
47
48
49
50
51
52
53


54
55
56
57
58
59
60
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+
+







	--with-tcl=DIR		Specifies the directory containing the Tcl
				binaries and Tcl's platform-dependent
				configuration information. By default the Tcl
				directory is assumed to be in the location
				given by (a) above.
	--with-x=DIR		Tells configure where to find an installation
				of the X Window System. Not normally needed.
	--enable-threads	If this switch is set, Tk will compile itself
				with multithreading support.
	--enable-shared		If this switch is specified, Tk will compile
				itself as a shared library if it can figure
				out how to do that on this platform. This is
				the default on platforms where we know how to
				build shared libraries.
	--disable-shared	If this switch is specified, Tk will compile
				itself as a static library.

Changes to unix/configure.

1
2
3

4
5
6

7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47








48
49
50
51
52
53




















54
55
56

57
58
59




60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76

77
78
79
80
81
82
83
84







85
86
87
88
89
90
91
92
93
94

95
96
97
98

99
100
101
102
103
104

105
106
107
108
109
110

111
112
113




















114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136



137
138
139
140
141

142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174


175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190


191
192
193

194
195
196
197


198
199
200
201
202
203

204
205
206
207
208
209
210
211
212

213
214

215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


233
234
235
236
237


238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259


260
261
262
263

264
265
266
267
268
269





270
271

272
273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
1
2

3
4
5

6

7
8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23


24
25
26
27
28
29

30
31
32
33








34
35
36
37
38
39
40
41
42
43
44






45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64



65



66
67
68
69










70




71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96


97




98
99
100
101
102
103

104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153



154
155
156
157
158
159
160

161

162
163
164
165
166
167


168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187

188

189


190
191

192
193


194
195
196
197
198
199

200

201


202
203

204

205

206


207
208
209
210
211
212


213



214
215
216
217
218

219
220

221

222

223

224
225
226
227
228
229
230







231
232

233



234
235
236
237

238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254


255
256
257
258
259

260






261
262
263
264
265
266

267
268
269
270
271
272

273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299


-
+


-
+
-










-
+
-






-
-
+
+




-




-
-
-
-
-
-
-
-



+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-


-
+








+
+
+
+
+
+
+








-
-
+
-
-
-
-
+





-
+





-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
-
-
+
+
+




-
+
-






-
-
+
+




-














-
+
-

-
-
+
+
-


-
-






-
+
-

-
-
+
+
-

-
+
-

-
-
+
+




-
-
+
-
-
-





-
+

-
+
-

-
+
-







-
-
-
-
-
-
-
+
+
-

-
-
-
+
+


-
+
-
















-
-
+
+



-
+
-
-
-
-
-
-
+
+
+
+
+

-
+





-
+
-



















-







#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.72 for tk 9.0.
# Generated by GNU Autoconf 2.69 for tk 8.7.
#
#
# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation,
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
# Inc.
#
#
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
else
  case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
IFS=" ""	$as_nl"

PS1='$ '
PS2='> '
PS4='+ '

  as_echo='print -r --'
  as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    export as_echo_n_body
LANGUAGE=C
export LANGUAGE

    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

fi
# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if ${PATH_SEPARATOR+false} :; then
if test "${PATH_SEPARATOR+set}" != set; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

# Use a proper internal environment variable to ensure we don't fall
  # into an infinite loop, continuously re-executing ourselves.
  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
    _as_can_reexec=no; export _as_can_reexec;
    # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
as_fn_exit 255
  fi
  # We don't want this to propagate to other subprocesses.
          { _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
  as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '\${1+\"\$@\"}'='\"\$@\"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case \`(set -o) 2>/dev/null\` in #(
else
  case \`(set -o) 2>/dev/null\` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi
"
  as_required="as_fn_return () { (exit \$1); }
as_fn_success () { as_fn_return 0; }
as_fn_failure () { as_fn_return 1; }
as_fn_ret_success () { return 0; }
as_fn_ret_failure () { return 1; }

exitcode=0
as_fn_success || { exitcode=1; echo as_fn_success failed.; }
as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
if ( set x; as_fn_ret_success y && test x = \"\$1\" )
if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
then :

else case e in #(
  e) exitcode=1; echo positional parameters were not saved. ;;
else
  exitcode=1; echo positional parameters were not saved.
esac
fi
test x\$exitcode = x0 || exit 1
blah=\$(echo \$(echo blah))
test x\"\$blah\" = xblah || exit 1
test -x / || exit 1"
  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
test \$(( 1 + 1 )) = 2 || exit 1"
  if (eval "$as_required") 2>/dev/null
  if (eval "$as_required") 2>/dev/null; then :
then :
  as_have_required=yes
else case e in #(
  e) as_have_required=no ;;
else
  as_have_required=no
esac
fi
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
then :

else case e in #(
  e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
else
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
as_found=false
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
  as_found=:
  case $as_dir in #(
	 /*)
	   for as_base in sh bash ksh sh5; do
	     # Try only shells that exist, to save several forks.
	     as_shell=$as_dir$as_base
	     as_shell=$as_dir/$as_base
	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
		    as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null
		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
then :
  CONFIG_SHELL=$as_shell as_have_required=yes
		   if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null
		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
then :
  break 2
fi
fi
	   done;;
       esac
  as_found=false
done
IFS=$as_save_IFS
if $as_found
then :

else case e in #(
  e) if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null
$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
then :
  CONFIG_SHELL=$SHELL as_have_required=yes
fi ;;
esac
fi
fi; }
IFS=$as_save_IFS


      if test "x$CONFIG_SHELL" != x
      if test "x$CONFIG_SHELL" != x; then :
then :
  export CONFIG_SHELL
             # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
fi

    if test x$as_have_required = xno
    if test x$as_have_required = xno; then :
then :
  printf "%s\n" "$0: This script requires a shell more modern than all"
  printf "%s\n" "$0: the shells that I found on your system."
  if test ${ZSH_VERSION+y} ; then
    printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later."
  $as_echo "$0: This script requires a shell more modern than all"
  $as_echo "$0: the shells that I found on your system."
  if test x${ZSH_VERSION+set} = xset ; then
    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
  else
    printf "%s\n" "$0: Please tell [email protected] about your system,
    $as_echo "$0: Please tell [email protected] about your system,
$0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run
$0: the script under such a shell if you do have one."
  fi
  exit 1
fi ;;
fi
esac
fi
fi
SHELL=${CONFIG_SHELL-/bin/sh}
export SHELL
# Unset more variables known to interfere with behavior of common tools.
CLICOLOR_FORCE= GREP_OPTIONS=
unset CLICOLOR_FORCE GREP_OPTIONS

## --------------------- ##
## M4sh Shell Functions. ##
## --------------------- ##
# as_fn_unset VAR
# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
  return $1
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_dir" |
$as_echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386


387
388
389
390

391
392
393
394
395
396
397
398

399
400
401
402
403
404
405


406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425

426
427
428
429
430
431
432
366
367
368
369
370
371
372

373

374
375
376
377


378
379
380
381


382
383
384
385
386
387
388
389

390

391
392
393
394


395
396
397
398


399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414

415
416
417
418
419
420
421
422







-
+
-




-
-
+
+


-
-
+







-
+
-




-
-
+
+


-
-
+













-
+

-
+







} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else case e in #(
  e) as_fn_append ()
else
  as_fn_append ()
  {
    eval $1=\$$1\$2
  } ;;
esac
  }
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else case e in #(
  e) as_fn_arith ()
else
  as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  } ;;
esac
  }
fi # as_fn_arith


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  printf "%s\n" "$as_me: error: $2" >&2
  $as_echo "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error

if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X/"$0" |
$as_echo X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548



549
550
551
552
553
554
555
468
469
470
471
472
473
474


475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499




500
501
502
503
504
505
506
507
508
509
510
511
512






513
514
515
516
517
518
519
520
521
522
523



524
525
526
527
528
529
530
531
532
533







-
-











-
+













-
-
-
-













-
-
-
-
-
-











-
-
-
+
+
+







  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
  sed -n '
    p
    /[$]LINENO/=
  ' <$as_myself |
    sed '
      t clear
      :clear
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
    ' >$as_me.lineno &&
  chmod +x "$as_me.lineno" ||
    { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }

  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
  # already done that, so ensure we don't try to do so again and fall
  # in an infinite loop.  This has already happened in practice.
  _as_can_reexec=no; export _as_can_reexec
  # Don't try to exec as it changes $[0], causing all sort of problems
  # (the dirname of $[0] is not the place where we might find the
  # original and so on.  Autoconf is especially sensitive to this).
  . "./$as_me.lineno"
  # Exit status is that of the last command.
  exit
}


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
566
567
568
569
570
571
572
573

574
575
576
577

578
579
580
581
582
583
584
585
544
545
546
547
548
549
550

551

552
553

554

555
556
557
558
559
560
561







-
+
-


-
+
-







  as_mkdir_p=false
fi

as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


test -n "$DJDIR" || exec 7<&0 </dev/null
exec 6>&1

# Name of the host.
# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
597
598
599
600
601
602
603
604
605


606
607
608
609
610
611
612
613



614
615




616





617
618



619



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
573
574
575
576
577
578
579


580
581
582
583
584
585
586



587
588
589
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616









617
618
619
620

621
622
623
624
625
626
627







-
-
+
+





-
-
-
+
+
+

-
+
+
+
+

+
+
+
+
+


+
+
+

+
+
+







-
-
-
-
-
-
-
-
-




-







subdirs=
MFLAGS=
MAKEFLAGS=

# Identity of this package.
PACKAGE_NAME='tk'
PACKAGE_TARNAME='tk'
PACKAGE_VERSION='9.0'
PACKAGE_STRING='tk 9.0'
PACKAGE_VERSION='8.7'
PACKAGE_STRING='tk 8.7'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stddef.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_STDLIB_H
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif"

ac_header_c_list=
ac_subst_vars='LTLIBOBJS
REZ_FLAGS
REZ
APP_RSRC_FILE
LIB_RSRC_FILE
WISH_RSRC_FILE
TK_RSRC_FILE
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

735



736
737
738
739
740
741
742
651
652
653
654
655
656
657


658
659
660
661
662
663













664
665
666
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685

686
687
688
689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
706
707
708







-
-






-
-
-
-
-
-
-
-
-
-
-
-
-




-


















-












+
-
+
+
+







TK_INCLUDE_SPEC
TK_STUB_LIB_PATH
TK_STUB_LIB_SPEC
TK_STUB_LIB_FLAG
TK_STUB_LIB_FILE
TK_LIB_SPEC
TK_LIB_FLAG
TK_LIB_FILE_TCL9
TK_LIB_FILE_TCL8
TK_LIB_FILE
TK_YEAR
TK_PATCH_LEVEL
TK_MINOR_VERSION
TK_MAJOR_VERSION
TK_VERSION
TK_DEMO_DIR
DEMO_DIR
INSTALL_MSGS
INSTALL_LIBRARIES
TK_ZIP_FILE
ZIPFS_BUILD
ZIP_INSTALL_OBJS
ZIP_PROG_VFSSEARCH
ZIP_PROG_OPTIONS
ZIP_PROG
MACHER_PROG
EXEEXT_FOR_BUILD
CC_FOR_BUILD
UNIX_FONT_OBJS
XFT_LIBS
XFT_CFLAGS
XMKMF
CPP
LDFLAGS_DEFAULT
CFLAGS_DEFAULT
INSTALL_STUB_LIB
DLL_INSTALL_DIR
INSTALL_LIB
MAKE_STUB_LIB
MAKE_LIB
SHLIB_SUFFIX
SHLIB_CFLAGS
SHLIB_LD_LIBS
TK_SHLIB_LD_EXTRAS
TCL_SHLIB_LD_EXTRAS
SHLIB_LD
STLIB_LD
LD_SEARCH_FLAGS
CC_SEARCH_FLAGS
LDFLAGS_OPTIMIZE
LDFLAGS_DEBUG
CFLAGS_NOLTO
CFLAGS_WARNING
CFLAGS_OPTIMIZE
CFLAGS_DEBUG
LDAIX_SRC
PLAT_SRCS
PLAT_OBJS
DL_OBJS
DL_LIBS
TCL_LIBS
LIBOBJS
AR
RANLIB
TCL_THREADS
SHARED_BUILD
EGREP
GREP
CPP
OBJEXT
EXEEXT
ac_ct_CC
CPPFLAGS
LDFLAGS
CFLAGS
CC
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794

795
796
797
798
799
800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
734
735
736
737
738
739
740

741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758

759

760
761
762
763
764
765
766

767
768
769
770
771
772
773
774
775
776
777
778
779

780
781
782
783
784
785
786







-


















-
+
-







-
+












-







pdfdir
dvidir
htmldir
infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
datadir
datarootdir
libexecdir
sbindir
bindir
program_transform_name
prefix
exec_prefix
PACKAGE_URL
PACKAGE_BUGREPORT
PACKAGE_STRING
PACKAGE_VERSION
PACKAGE_TARNAME
PACKAGE_NAME
PATH_SEPARATOR
SHELL
SHELL'
OBJEXT_FOR_BUILD'
ac_subst_files=''
ac_user_opts='
enable_option_checking
with_tcl
enable_man_symlinks
enable_man_compression
enable_man_suffix
with_encoding
enable_threads
enable_shared
enable_64bit
enable_64bit_vis
enable_rpath
enable_corefoundation
enable_load
enable_symbols
enable_aqua
with_x
enable_xft
enable_xss
enable_framework
enable_zipfs
'
      ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
822
823
824
825
826
827
828

829
830
831
832
833
834
835







-







sbindir='${exec_prefix}/sbin'
libexecdir='${exec_prefix}/libexec'
datarootdir='${prefix}/share'
datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
infodir='${datarootdir}/info'
htmldir='${docdir}'
dvidir='${docdir}'
pdfdir='${docdir}'
888
889
890
891
892
893
894


895
896
897
898
899
900
901
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865







+
+







  fi

  case $ac_option in
  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
  *=)   ac_optarg= ;;
  *)    ac_optarg=yes ;;
  esac

  # Accept the important Cygnus configure options, so we can diagnose typos.

  case $ac_dashdash$ac_option in
  --)
    ac_dashdash=yes ;;

  -bindir | --bindir | --bindi | --bind | --bin | --bi)
    ac_prev=bindir ;;
929
930
931
932
933
934
935
936

937
938

939
940
941
942
943
944
945
893
894
895
896
897
898
899

900
901

902
903
904
905
906
907
908
909







-
+

-
+







  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
    datarootdir=$ac_optarg ;;

  -disable-* | --disable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: '$ac_useropt'"
      as_fn_error $? "invalid feature name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
955
956
957
958
959
960
961
962

963
964

965
966
967
968
969
970
971
919
920
921
922
923
924
925

926
927

928
929
930
931
932
933
934
935







-
+

-
+







  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
    dvidir=$ac_optarg ;;

  -enable-* | --enable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: '$ac_useropt'"
      as_fn_error $? "invalid feature name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1074
1075
1076
1077
1078
1079
1080









1081
1082
1083
1084
1085
1086
1087







-
-
-
-
-
-
-
-
-







  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
    psdir=$ac_optarg ;;

  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil)
    silent=yes ;;

  -runstatedir | --runstatedir | --runstatedi | --runstated \
  | --runstate | --runstat | --runsta | --runst | --runs \
  | --run | --ru | --r)
    ac_prev=runstatedir ;;
  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
  | --run=* | --ru=* | --r=*)
    runstatedir=$ac_optarg ;;

  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
    ac_prev=sbindir ;;
  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
  | --sbi=* | --sb=*)
    sbindir=$ac_optarg ;;

  -sharedstatedir | --sharedstatedir | --sharedstatedi \
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191

1192
1193

1194
1195
1196
1197
1198
1199
1200
1123
1124
1125
1126
1127
1128
1129

1130
1131

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145

1146
1147

1148
1149
1150
1151
1152
1153
1154
1155







-
+

-
+













-
+

-
+







  -version | --version | --versio | --versi | --vers | -V)
    ac_init_version=: ;;

  -with-* | --with-*)
    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: '$ac_useropt'"
      as_fn_error $? "invalid package name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
    eval with_$ac_useropt=\$ac_optarg ;;

  -without-* | --without-*)
    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: '$ac_useropt'"
      as_fn_error $? "invalid package name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1214
1215
1216
1217
1218
1219
1220
1221
1222


1223
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235
1236
1237

1238
1239

1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1169
1170
1171
1172
1173
1174
1175


1176
1177
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190
1191

1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242







-
-
+
+







-
+






-
+

-
+















-
+







-
+
















-
+







  -x-libraries | --x-libraries | --x-librarie | --x-librari \
  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
    ac_prev=x_libraries ;;
  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
    x_libraries=$ac_optarg ;;

  -*) as_fn_error $? "unrecognized option: '$ac_option'
Try '$0 --help' for more information"
  -*) as_fn_error $? "unrecognized option: \`$ac_option'
Try \`$0 --help' for more information"
    ;;

  *=*)
    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
    # Reject names that are not valid shell variable names.
    case $ac_envvar in #(
      '' | [0-9]* | *[!_$as_cr_alnum]* )
      as_fn_error $? "invalid variable name: '$ac_envvar'" ;;
      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
    esac
    eval $ac_envvar=\$ac_optarg
    export $ac_envvar ;;

  *)
    # FIXME: should be removed in autoconf 3.0.
    printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2
    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
      printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2
      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
    ;;

  esac
done

if test -n "$ac_prev"; then
  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
  as_fn_error $? "missing argument to $ac_option"
fi

if test -n "$ac_unrecognized_opts"; then
  case $enable_option_checking in
    no) ;;
    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
    *)     printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
  esac
fi

# Check all directory arguments for consistency.
for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
		datadir sysconfdir sharedstatedir localstatedir includedir \
		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
		libdir localedir mandir runstatedir
		libdir localedir mandir
do
  eval ac_val=\$$ac_var
  # Remove trailing slashes.
  case $ac_val in
    */ )
      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
      eval $ac_var=\$ac_val;;
  esac
  # Be sure to have absolute directory names.
  case $ac_val in
    [\\/$]* | ?:[\\/]* )  continue;;
    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
  esac
  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
done

# There might be people who depend on the old broken behavior: '$host'
# There might be people who depend on the old broken behavior: `$host'
# used to hold the argument of --host etc.
# FIXME: To remove some day.
build=$build_alias
host=$host_alias
target=$target_alias

# FIXME: To remove some day.
1312
1313
1314
1315
1316
1317
1318
1319

1320
1321
1322
1323
1324
1325
1326
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281







-
+







  ac_srcdir_defaulted=yes
  # Try the directory containing this script, then the parent directory.
  ac_confdir=`$as_dirname -- "$as_myself" ||
$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_myself" : 'X\(//\)[^/]' \| \
	 X"$as_myself" : 'X\(//\)$' \| \
	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_myself" |
$as_echo X"$as_myself" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
1341
1342
1343
1344
1345
1346
1347
1348

1349
1350
1351
1352
1353
1354
1355
1296
1297
1298
1299
1300
1301
1302

1303
1304
1305
1306
1307
1308
1309
1310







-
+







else
  ac_srcdir_defaulted=no
fi
if test ! -r "$srcdir/$ac_unique_file"; then
  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
fi
ac_msg="sources are in $srcdir, but 'cd $srcdir' does not work"
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_abs_confdir=`(
	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
	pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
  srcdir=.
fi
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390

1391
1392

1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405




1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344

1345
1346

1347
1348

1349
1350
1351
1352
1353
1354
1355
1356




1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377







-
+













-
+

-
+

-
+







-
-
-
-
+
+
+
+










-







#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
'configure' configures tk 9.0 to adapt to many kinds of systems.
\`configure' configures tk 8.7 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print 'checking ...' messages
  -q, --quiet, --silent   do not print \`checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for '--cache-file=config.cache'
  -C, --config-cache      alias for \`--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or '..']
      --srcdir=DIR        find the sources in DIR [configure dir or \`..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [$ac_default_prefix]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, 'make install' will install all the files in
'$ac_default_prefix/bin', '$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than '$ac_default_prefix' using '--prefix',
for instance '--prefix=\$HOME'.
By default, \`make install' will install all the files in
\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than \`$ac_default_prefix' using \`--prefix',
for instance \`--prefix=\$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
1435
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456

1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510

1511
1512

1513
1514
1515
1516
1517
1518
1519
1389
1390
1391
1392
1393
1394
1395

1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424

1425
1426
1427
1428
1429
1430

1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462

1463
1464

1465
1466
1467
1468
1469
1470
1471
1472







-
+














+













-






-













-
+


















-
+

-
+







  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of tk 9.0:";;
     short | recursive ) echo "Configuration of tk 8.7:";;
   esac
  cat <<\_ACEOF

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-man-symlinks   use symlinks for the manpages (default: off)
  --enable-man-compression=PROG
                          compress the manpages with PROG (default: off)
  --enable-man-suffix=STRING
                          use STRING as a suffix to manpage file names
                          (default: no, tk if enabled without
                          specifying STRING)
  --enable-threads        build with threads (default: on)
  --enable-shared         build and link with shared libraries (default: on)
  --enable-64bit          enable 64bit support (default: off)
  --enable-64bit-vis      enable 64bit Sparc VIS support (default: off)
  --disable-rpath         disable rpath support (default: on)
  --enable-corefoundation use CoreFoundation API on MacOSX (default: on)
  --enable-load           allow dynamic loading and "load" command (default:
                          on)
  --enable-symbols        build with debugging symbols (default: off)
  --enable-aqua=yes|no    use Aqua windowingsystem on Mac OS X (default: no)
  --enable-xft            use freetype/fontconfig/xft (default: on)
  --enable-xss            use XScreenSaver for activity timer (default: on)
  --enable-framework      package shared libraries in MacOSX frameworks
                          (default: off)
  --enable-zipfs          build with Zipfs support (default: on)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-tcl              directory containing tcl configuration
                          (tclConfig.sh)
  --with-encoding         encoding for configuration values (default: utf-8)
  --with-x                use the X Window System

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  XMKMF       Path to xmkmf, Makefile generator for X Window System

Use these variables to override the choices made by 'configure' or to help
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.
_ACEOF
ac_status=$?
fi

if test "$ac_init_help" = "recursive"; then
  # If there are subdirs, report their specific --help.
  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
    test -d "$ac_dir" ||
      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
      continue
    ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
1533
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546
1547
1548
1549

1550
1551
1552
1553
1554
1555
1556
1557
1558
1559


1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578

1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593

1594
1595
1596
1597

1598
1599
1600
1601


1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1486
1487
1488
1489
1490
1491
1492

1493

1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509


1510
1511
1512

1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529

1530
1531
1532
1533
1534
1535
1536

1537
1538
1539
1540
1541
1542
1543
1544

1545
1546
1547
1548

1549

1550


1551
1552
1553
1554

1555

1556
1557
1558
1559
1560
1561































































































































































































1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573

1574
1575
1576
1577
1578
1579
1580
1581

1582
1583
1584
1585


1586
1587


1588
1589
1590
1591

1592

1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
+
-







-
+








-
-
+
+

-
+
















-
+






-
+







-
+



-
+
-

-
-
+
+


-
+
-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+







-
+



-
-
+

-
-
+
+


-
+
-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
-
+
+
-
-
-
-
-
+
+
+
+




-
+







-
+
-




-
+







-
+
-

-
-
+
+
-

-
+

-
+
-


-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
+
+

-
+







    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
    ac_top_srcdir=$ac_top_build_prefix$srcdir
    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix

    cd "$ac_dir" || { ac_status=$?; continue; }
    # Check for configure.gnu first; this name is used for a wrapper for
    # Check for guested configure.
    # Metaconfig's "Configure" on case-insensitive file systems.
    if test -f "$ac_srcdir/configure.gnu"; then
      echo &&
      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
    elif test -f "$ac_srcdir/configure"; then
      echo &&
      $SHELL "$ac_srcdir/configure" --help=recursive
    else
      printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2
      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
    fi || ac_status=$?
    cd "$ac_pwd" || { ac_status=$?; break; }
  done
fi

test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
  cat <<\_ACEOF
tk configure 9.0
generated by GNU Autoconf 2.72
tk configure 8.7
generated by GNU Autoconf 2.69

Copyright (C) 2023 Free Software Foundation, Inc.
Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit
fi

## ------------------------ ##
## Autoconf initialization. ##
## ------------------------ ##

# ac_fn_c_try_compile LINENO
# --------------------------
# Try to compile conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest.beam
  rm -f conftest.$ac_objext
  if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest.$ac_objext
       } && test -s conftest.$ac_objext; then :
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1 ;;
	ac_retval=1
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_compile

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest$ac_exeext && {
	 test "$cross_compiling" = yes ||
	 test -x conftest$ac_exeext
       }
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1 ;;
esac
fi
  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  # interfere with the next link command; also delete a directory that is
  # left behind by Apple's compiler.  We do this before executing the actions.
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_link

# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  eval "$3=yes"
else case e in #(
  e) eval "$3=no" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_compile

# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_c_check_func ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define $2 innocuous_$2

/* System header to define __stub macros and hopefully few prototypes,
   which can conflict with char $2 (void); below.  */

#include <limits.h>
#undef $2

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char $2 (void);
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif

int
main (void)
{
return $2 ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
  eval "$3=yes"
else case e in #(
  e) eval "$3=no" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_func

# ac_fn_c_try_run LINENO
# ----------------------
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
# executables *can* be run.
ac_fn_c_try_run ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: program exited with status $ac_status" >&5
       printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

       ac_retval=$ac_status ;;
esac
fi
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_run

# ac_fn_c_try_cpp LINENO
# ----------------------
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_cpp ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_cpp conftest.$ac_ext"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } > conftest.i && {
	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
	 test ! -s conftest.err
       }
then :
       }; then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

    ac_retval=1 ;;
    ac_retval=1
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_cpp

# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
# the include files in INCLUDES and setting the cache variable VAR
# accordingly.
ac_fn_c_check_header_mongrel ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if eval \${$3+:} false; then :
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
else
  # Is the header compilable?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
$as_echo_n "checking $2 usability... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_header_compiler=yes
else
  ac_header_compiler=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
$as_echo "$ac_header_compiler" >&6; }

# Is the header present?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
$as_echo_n "checking $2 presence... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <$2>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  ac_header_preproc=yes
else
  ac_header_preproc=no
fi
rm -f conftest.err conftest.i conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
$as_echo "$ac_header_preproc" >&6; }

# So?  What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
  yes:no: )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
  no:yes:* )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
esac
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  eval "$3=\$ac_header_compiler"
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_mongrel

# ac_fn_c_try_run LINENO
# ----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_c_try_run ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then :
  ac_retval=0
else
  $as_echo "$as_me: program exited with status $ac_status" >&5
       $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

       ac_retval=$ac_status
fi
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_run

# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  eval "$3=yes"
else
  eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_compile

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest$ac_exeext
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest$ac_exeext && {
	 test "$cross_compiling" = yes ||
	 test -x conftest$ac_exeext
       }; then :
  ac_retval=0
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1
fi
  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  # interfere with the next link command; also delete a directory that is
  # left behind by Apple's compiler.  We do this before executing the actions.
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_link

# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_c_check_func ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define $2 innocuous_$2

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char $2 (); below.
    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    <limits.h> exists even on freestanding compilers.  */

#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif

#undef $2

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif

int
main ()
{
return $2 ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  eval "$3=yes"
else
  eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_func

# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
# variable VAR accordingly.
ac_fn_c_check_type ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) eval "$3=no"
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  eval "$3=no"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
int
main (void)
main ()
{
if (sizeof ($2))
	 return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
int
main (void)
main ()
{
if (sizeof (($2)))
	    return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :

else case e in #(
  e) eval "$3=yes" ;;
else
  eval "$3=yes"
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
eval ac_res=\$$3
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_type
ac_configure_args_raw=
for ac_arg
do
  case $ac_arg in
  *\'*)
    ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
  esac
  as_fn_append ac_configure_args_raw " '$ac_arg'"
done

case $ac_configure_args_raw in
  *$as_nl*)
    ac_safe_unquote= ;;
  *)
    ac_unsafe_z='|&;<>()$`\\"*?[ ''	' # This string ends in space, tab.
    ac_unsafe_a="$ac_unsafe_z#~"
    ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g"
    ac_configure_args_raw=`      printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;;
esac

cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by tk $as_me 9.0, which was
generated by GNU Autoconf 2.72.  Invocation command line was
It was created by tk $as_me 8.7, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ $0$ac_configure_args_raw
  $ $0 $@

_ACEOF
exec 5>>config.log
{
cat <<_ASUNAME
## --------- ##
## Platform. ##
1953
1954
1955
1956
1957
1958
1959
1960
1961

1962
1963
1964
1965

1966
1967
1968
1969
1970
1971
1972
1958
1959
1960
1961
1962
1963
1964


1965




1966
1967
1968
1969
1970
1971
1972
1973







-
-
+
-
-
-
-
+








_ASUNAME

as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    printf "%s\n" "PATH: $as_dir"
    $as_echo "PATH: $as_dir"
  done
IFS=$as_save_IFS

} >&5

cat >&5 <<_ACEOF

1993
1994
1995
1996
1997
1998
1999
2000

2001
2002
2003
2004
2005
2006
2007
1994
1995
1996
1997
1998
1999
2000

2001
2002
2003
2004
2005
2006
2007
2008







-
+







  do
    case $ac_arg in
    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
    | -silent | --silent | --silen | --sile | --sil)
      continue ;;
    *\'*)
      ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
    esac
    case $ac_pass in
    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
    2)
      as_fn_append ac_configure_args1 " '$ac_arg'"
      if test $ac_must_keep_next = true; then
	ac_must_keep_next=false # Got value, back to normal.
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
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







-
-




-
+










-
-
+
+








# When interrupted or exit'd, cleanup temporary files, and complete
# config.log.  We remove comments because anyway the quotes in there
# would cause problems or look ugly.
# WARNING: Use '\'' to represent an apostrophe within the trap.
# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
trap 'exit_status=$?
  # Sanitize IFS.
  IFS=" ""	$as_nl"
  # Save into config.log some information that might help in debugging.
  {
    echo

    printf "%s\n" "## ---------------- ##
    $as_echo "## ---------------- ##
## Cache variables. ##
## ---------------- ##"
    echo
    # The following way of writing the cache mishandles newlines in values,
(
  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
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
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







-
+







-
+

-
+




-
+







-
+

-
+





-
+







-
-
+
+













-
+



+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+




+
+

+
-
+
+
+
+
+

-
+
+

-
+
+

-
-
+

-
+
-
-
-
-
-
-
-
-
+
+
+


-
-
+
+

-
+







-
-
+
+






-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
+
+


-
-
+
+








-
-
+
+


-
-
+
+


-
-
-
-
+
+
+
+





-
+









-
-
-
-
+
+
+
+
-
-
+
















-
-
-
-
+
+
+
+



















-
+
-



-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
+







      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
)
    echo

    printf "%s\n" "## ----------------- ##
    $as_echo "## ----------------- ##
## Output variables. ##
## ----------------- ##"
    echo
    for ac_var in $ac_subst_vars
    do
      eval ac_val=\$$ac_var
      case $ac_val in
      *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      esac
      printf "%s\n" "$ac_var='\''$ac_val'\''"
      $as_echo "$ac_var='\''$ac_val'\''"
    done | sort
    echo

    if test -n "$ac_subst_files"; then
      printf "%s\n" "## ------------------- ##
      $as_echo "## ------------------- ##
## File substitutions. ##
## ------------------- ##"
      echo
      for ac_var in $ac_subst_files
      do
	eval ac_val=\$$ac_var
	case $ac_val in
	*\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	esac
	printf "%s\n" "$ac_var='\''$ac_val'\''"
	$as_echo "$ac_var='\''$ac_val'\''"
      done | sort
      echo
    fi

    if test -s confdefs.h; then
      printf "%s\n" "## ----------- ##
      $as_echo "## ----------- ##
## confdefs.h. ##
## ----------- ##"
      echo
      cat confdefs.h
      echo
    fi
    test "$ac_signal" != 0 &&
      printf "%s\n" "$as_me: caught signal $ac_signal"
    printf "%s\n" "$as_me: exit $exit_status"
      $as_echo "$as_me: caught signal $ac_signal"
    $as_echo "$as_me: exit $exit_status"
  } >&5
  rm -f core *.core core.conftest.* &&
    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
    exit $exit_status
' 0
for ac_signal in 1 2 13 15; do
  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
done
ac_signal=0

# confdefs.h avoids OS command line length limits that DEFS can exceed.
rm -f -r conftest* confdefs.h

printf "%s\n" "/* confdefs.h */" > confdefs.h
$as_echo "/* confdefs.h */" > confdefs.h

# Predefined preprocessor variables.

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h
#define PACKAGE_NAME "$PACKAGE_NAME"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h
#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h
#define PACKAGE_VERSION "$PACKAGE_VERSION"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h
#define PACKAGE_STRING "$PACKAGE_STRING"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h
#define PACKAGE_URL "$PACKAGE_URL"
_ACEOF


# Let the site file select an alternate cache file if it wants to.
# Prefer an explicitly selected file to automatically selected ones.
ac_site_file1=NONE
ac_site_file2=NONE
if test -n "$CONFIG_SITE"; then
  # We do not want a PATH search for config.site.
  ac_site_files="$CONFIG_SITE"
  case $CONFIG_SITE in #((
    -*)  ac_site_file1=./$CONFIG_SITE;;
    */*) ac_site_file1=$CONFIG_SITE;;
    *)   ac_site_file1=./$CONFIG_SITE;;
  esac
elif test "x$prefix" != xNONE; then
  ac_site_files="$prefix/share/config.site $prefix/etc/config.site"
  ac_site_file1=$prefix/share/config.site
  ac_site_file2=$prefix/etc/config.site
else
  ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
  ac_site_file1=$ac_default_prefix/share/config.site
  ac_site_file2=$ac_default_prefix/etc/config.site
fi

for ac_site_file in $ac_site_files
for ac_site_file in "$ac_site_file1" "$ac_site_file2"
do
  case $ac_site_file in #(
  test "x$ac_site_file" = xNONE && continue
  */*) :
     ;; #(
  *) :
    ac_site_file=./$ac_site_file ;;
esac
  if test -f "$ac_site_file" && test -r "$ac_site_file"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;}
  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
$as_echo "$as_me: loading site script $ac_site_file" >&6;}
    sed 's/^/| /' "$ac_site_file" >&5
    . "$ac_site_file" \
      || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "failed to load site script $ac_site_file
See 'config.log' for more details" "$LINENO" 5; }
See \`config.log' for more details" "$LINENO" 5; }
  fi
done

if test -r "$cache_file"; then
  # Some versions of bash will fail to source /dev/null (special files
  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
printf "%s\n" "$as_me: loading cache $cache_file" >&6;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
$as_echo "$as_me: loading cache $cache_file" >&6;}
    case $cache_file in
      [\\/]* | ?:[\\/]* ) . "$cache_file";;
      *)                      . "./$cache_file";;
    esac
  fi
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
printf "%s\n" "$as_me: creating cache $cache_file" >&6;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
$as_echo "$as_me: creating cache $cache_file" >&6;}
  >$cache_file
fi

# Test code for whether the C compiler supports C89 (global declarations)
ac_c_conftest_c89_globals='
/* Does the compiler advertise C89 conformance?
   Do not test the value of __STDC__, because some compilers set it to 0
   while being otherwise adequately conformant. */
#if !defined __STDC__
# error "Compiler does not advertise C89 conformance"
#endif

#include <stddef.h>
#include <stdarg.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7 src/conf.sh.  */
struct buf { int x; };
struct buf * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (char **p, int i)
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;
}

/* C89 style stringification. */
#define noexpand_stringify(a) #a
const char *stringified = noexpand_stringify(arbitrary+token=sequence);

/* C89 style token pasting.  Exercises some of the corner cases that
   e.g. old MSVC gets wrong, but not very hard. */
#define noexpand_concat(a,b) a##b
#define expand_concat(a,b) noexpand_concat(a,b)
extern int vA;
extern int vbee;
#define aye A
#define bee B
int *pvA = &expand_concat(v,aye);
int *pvbee = &noexpand_concat(v,bee);

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not \xHH hex character constants.
   These do not provoke an error unfortunately, instead are silently treated
   as an "x".  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously \x00 != x always comes out true, for an
   array size at least.  It is necessary to write \x00 == 0 to get something
   that is true only with -std.  */
int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) '\''x'\''
int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
               int, int);'

# Test code for whether the C compiler supports C89 (body of main).
ac_c_conftest_c89_main='
ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]);
'

# Test code for whether the C compiler supports C99 (global declarations)
ac_c_conftest_c99_globals='
/* Does the compiler advertise C99 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# error "Compiler does not advertise C99 conformance"
#endif

// See if C++-style comments work.

#include <stdbool.h>
extern int puts (const char *);
extern int printf (const char *, ...);
extern int dprintf (int, const char *, ...);
extern void *malloc (size_t);
extern void free (void *);

// Check varargs macros.  These examples are taken from C99 6.10.3.5.
// dprintf is used instead of fprintf to avoid needing to declare
// FILE and stderr.
#define debug(...) dprintf (2, __VA_ARGS__)
#define showlist(...) puts (#__VA_ARGS__)
#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
static void
test_varargs_macros (void)
{
  int x = 1234;
  int y = 5678;
  debug ("Flag");
  debug ("X = %d\n", x);
  showlist (The first, second, and third items.);
  report (x>y, "x is %d but y is %d", x, y);
}

// Check long long types.
#define BIG64 18446744073709551615ull
#define BIG32 4294967295ul
#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
#if !BIG_OK
  #error "your preprocessor is broken"
#endif
#if BIG_OK
#else
  #error "your preprocessor is broken"
#endif
static long long int bignum = -9223372036854775807LL;
static unsigned long long int ubignum = BIG64;

struct incomplete_array
{
  int datasize;
  double data[];
};

struct named_init {
  int number;
  const wchar_t *name;
  double average;
};

typedef const char *ccp;

static inline int
test_restrict (ccp restrict text)
{
  // Iterate through items via the restricted pointer.
  // Also check for declarations in for loops.
  for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
    continue;
  return 0;
}

// Check varargs and va_copy.
static bool
test_varargs (const char *format, ...)
{
  va_list args;
  va_start (args, format);
  va_list args_copy;
  va_copy (args_copy, args);

  const char *str = "";
  int number = 0;
  float fnumber = 0;

  while (*format)
    {
      switch (*format++)
	{
	case '\''s'\'': // string
	  str = va_arg (args_copy, const char *);
	  break;
	case '\''d'\'': // int
	  number = va_arg (args_copy, int);
	  break;
	case '\''f'\'': // float
	  fnumber = va_arg (args_copy, double);
	  break;
	default:
	  break;
	}
    }
  va_end (args_copy);
  va_end (args);

  return *str && number && fnumber;
}
'

# Test code for whether the C compiler supports C99 (body of main).
ac_c_conftest_c99_main='
  // Check bool.
  _Bool success = false;
  success |= (argc != 0);

  // Check restrict.
  if (test_restrict ("String literal") == 0)
    success = true;
  char *restrict newvar = "Another string";

  // Check varargs.
  success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
  test_varargs_macros ();

  // Check flexible array members.
  struct incomplete_array *ia =
    malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
  ia->datasize = 10;
  for (int i = 0; i < ia->datasize; ++i)
    ia->data[i] = i * 1.234;
  // Work around memory leak warnings.
  free (ia);

  // Check named initializers.
  struct named_init ni = {
    .number = 34,
    .name = L"Test wide string",
    .average = 543.34343,
  };

  ni.number = 58;

  int dynamic_array[ni.number];
  dynamic_array[0] = argv[0][0];
  dynamic_array[ni.number - 1] = 543;

  // work around unused variable warnings
  ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\''
	 || dynamic_array[ni.number - 1] != 543);
'

# Test code for whether the C compiler supports C11 (global declarations)
ac_c_conftest_c11_globals='
/* Does the compiler advertise C11 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
# error "Compiler does not advertise C11 conformance"
#endif

// Check _Alignas.
char _Alignas (double) aligned_as_double;
char _Alignas (0) no_special_alignment;
extern char aligned_as_int;
char _Alignas (0) _Alignas (int) aligned_as_int;

// Check _Alignof.
enum
{
  int_alignment = _Alignof (int),
  int_array_alignment = _Alignof (int[100]),
  char_alignment = _Alignof (char)
};
_Static_assert (0 < -_Alignof (int), "_Alignof is signed");

// Check _Noreturn.
int _Noreturn does_not_return (void) { for (;;) continue; }

// Check _Static_assert.
struct test_static_assert
{
  int x;
  _Static_assert (sizeof (int) <= sizeof (long int),
                  "_Static_assert does not work in struct");
  long int y;
};

// Check UTF-8 literals.
#define u8 syntax error!
char const utf8_literal[] = u8"happens to be ASCII" "another string";

// Check duplicate typedefs.
typedef long *long_ptr;
typedef long int *long_ptr;
typedef long_ptr long_ptr;

// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
struct anonymous
{
  union {
    struct { int i; int j; };
    struct { int k; long int l; } w;
  };
  int m;
} v1;
'

# Test code for whether the C compiler supports C11 (body of main).
ac_c_conftest_c11_main='
  _Static_assert ((offsetof (struct anonymous, i)
		   == offsetof (struct anonymous, w.k)),
		  "Anonymous union alignment botch");
  v1.i = 2;
  v1.w.k = 5;
  ok |= v1.i != 5;
'

# Test code for whether the C compiler supports C11 (complete).
ac_c_conftest_c11_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}
${ac_c_conftest_c11_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  ${ac_c_conftest_c11_main}
  return ok;
}
"

# Test code for whether the C compiler supports C99 (complete).
ac_c_conftest_c99_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  return ok;
}
"

# Test code for whether the C compiler supports C89 (complete).
ac_c_conftest_c89_program="${ac_c_conftest_c89_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  return ok;
}
"

as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H"
as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H"
as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H"
as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H"
as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H"
as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H"
as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H"
as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H"
as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H"
as_fn_append ac_header_c_list " sys/time.h sys_time_h HAVE_SYS_TIME_H"
# Check that the precious variables saved in the cache have kept the same
# value.
ac_cache_corrupted=false
for ac_var in $ac_precious_vars; do
  eval ac_old_set=\$ac_cv_env_${ac_var}_set
  eval ac_new_set=\$ac_env_${ac_var}_set
  eval ac_old_val=\$ac_cv_env_${ac_var}_value
  eval ac_new_val=\$ac_env_${ac_var}_value
  case $ac_old_set,$ac_new_set in
    set,)
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&2;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,set)
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was not set in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was not set in the previous run" >&2;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,);;
    *)
      if test "x$ac_old_val" != "x$ac_new_val"; then
	# differences in whitespace do not lead to failure.
	ac_old_val_w=`echo x $ac_old_val`
	ac_new_val_w=`echo x $ac_new_val`
	if test "$ac_old_val_w" != "$ac_new_val_w"; then
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' has changed since the previous run:" >&5
printf "%s\n" "$as_me: error: '$ac_var' has changed since the previous run:" >&2;}
	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
	  ac_cache_corrupted=:
	else
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&5
printf "%s\n" "$as_me: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&2;}
	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
	  eval $ac_var=\$ac_old_val
	fi
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   former value:  '$ac_old_val'" >&5
printf "%s\n" "$as_me:   former value:  '$ac_old_val'" >&2;}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   current value: '$ac_new_val'" >&5
printf "%s\n" "$as_me:   current value: '$ac_new_val'" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
      fi;;
  esac
  # Pass precious variables to config.status.
  if test "$ac_new_set" = set; then
    case $ac_new_val in
    *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *) ac_arg=$ac_var=$ac_new_val ;;
    esac
    case " $ac_configure_args " in
      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
    esac
  fi
done
if $ac_cache_corrupted; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
  as_fn_error $? "run '${MAKE-make} distclean' and/or 'rm $cache_file'
	    and start over" "$LINENO" 5
  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
fi
## -------------------- ##
## Main body of script. ##
## -------------------- ##

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu






TK_VERSION=9.0
TK_MAJOR_VERSION=9
TK_MINOR_VERSION=0
TK_PATCH_LEVEL="b2"
TK_VERSION=8.7
TK_MAJOR_VERSION=8
TK_MINOR_VERSION=7
TK_PATCH_LEVEL="a0"
VERSION=${TK_VERSION}
LOCALES="cs da de el en en_gb eo es fr hu it nl pl pt ru sv"

#--------------------------------------------------------------------
# Find and load the tclConfig.sh file
#--------------------------------------------------------------------


    #
    # Ok, lets find the tcl configuration
    # First, look for one uninstalled.
    # the alternative search directory is invoked by --with-tcl
    #

    if test x"${no_tcl}" = x ; then
	# we reset no_tcl in case something fails here
	no_tcl=true

# Check whether --with-tcl was given.
if test ${with_tcl+y}
if test "${with_tcl+set}" = set; then :
then :
  withval=$with_tcl; with_tclconfig="${withval}"
fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
printf %s "checking for Tcl configuration... " >&6; }
	if test ${ac_cv_c_tclconfig+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
$as_echo_n "checking for Tcl configuration... " >&6; }
	if ${ac_cv_c_tclconfig+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else


	    # First check to see if --with-tcl was specified.
	    if test x"${with_tclconfig}" != x ; then
		case "${with_tclconfig}" in
		    */tclConfig.sh )
			if test -f "${with_tclconfig}"; then
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
printf "%s\n" "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
$as_echo "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    with_tclconfig="`echo "${with_tclconfig}" | sed 's!/tclConfig\.sh$!!'`"
			fi ;;
		esac
		if test -f "${with_tclconfig}/tclConfig.sh" ; then
		    ac_cv_c_tclconfig="`(cd "${with_tclconfig}"; pwd)`"
		else
		    as_fn_error $? "${with_tclconfig} directory doesn't contain tclConfig.sh" "$LINENO" 5
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
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







+













-

+

-


-
-







	    fi

	    # on Darwin, check in Framework installation locations
	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then
		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
			`ls -d /Library/Frameworks 2>/dev/null` \
			`ls -d /Network/Library/Frameworks 2>/dev/null` \
			`ls -d /System/Library/Frameworks 2>/dev/null` \
			; do
		    if test -f "$i/Tcl.framework/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i/Tcl.framework; pwd)`"
			break
		    fi
		done
	    fi

	    # check in a few common install locations
	    if test x"${ac_cv_c_tclconfig}" = x ; then
		for i in `ls -d ${libdir} 2>/dev/null` \
			`ls -d ${exec_prefix}/lib 2>/dev/null` \
			`ls -d ${prefix}/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/contrib/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/pkg/lib 2>/dev/null` \
			`ls -d /usr/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/lib 2>/dev/null` \
			`ls -d /usr/lib64 2>/dev/null` \
			`ls -d /usr/local/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl9.0 2>/dev/null` \
			; do
		    if test -f "$i/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i; pwd)`"
			break
		    fi
		done
	    fi
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
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







-
+
-









-
-
+
+




-
-
+
+


-
-
+
+


-
-
+
+

+
+
+
+







			`ls -dr ${srcdir}/../tcl[8-9].[0-9]* 2>/dev/null` ; do
		    if test -f "$i/unix/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i/unix; pwd)`"
			break
		    fi
		done
	    fi
	 ;;

esac
fi


	if test x"${ac_cv_c_tclconfig}" = x ; then
	    TCL_BIN_DIR="# no Tcl configs found"
	    as_fn_error $? "Can't find Tcl configuration definitions. Use --with-tcl to specify a directory containing tclConfig.sh" "$LINENO" 5
	else
	    no_tcl=
	    TCL_BIN_DIR="${ac_cv_c_tclconfig}"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	fi
    fi


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf %s "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo_n "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }

    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: loading" >&5
printf "%s\n" "loading" >&6; }
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: loading" >&5
$as_echo "loading" >&6; }
	. "${TCL_BIN_DIR}/tclConfig.sh"
    else
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
    fi

    # eval is required to do the TCL_DBGX substitution
    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""

    # If the TCL_BIN_DIR is the build directory (not the install directory),
    # then set the common variable name to the value of the build variables.
    # For example, the variable TCL_LIB_SPEC will be set to the value
    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
    # installed and uninstalled version of Tcl.
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
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







+
+
+
+
+














+
-
+
-
-
+


+
+
+



-
-
-
+
+
+
-
-
-
-
+
+
+












-
+
-





-
-
+
+



-
-
+
+




-
-
+
+

-
-
+
+







		    TCL_STUB_LIB_SPEC="-L`echo "${TCL_BIN_DIR}"  | sed -e 's/ /\\\\ /g'` ${TCL_STUB_LIB_FLAG}"
		    TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"
		fi
		;;
	esac
    fi

    # eval is required to do the TCL_DBGX substitution
    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""















if test "${TCL_MAJOR_VERSION}" -lt 9 ; then
if test "${TCL_MAJOR_VERSION}" -ne 8 ; then
if test "${TCL_MINOR_VERSION}" -lt 7 ; then
    as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.7+
    as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+
Found config for Tcl ${TCL_VERSION}" "$LINENO" 5
fi
if test "${TCL_MINOR_VERSION}" -lt 6 ; then
    as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+
Found config for Tcl ${TCL_VERSION}" "$LINENO" 5
fi


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
printf %s "checking for tclsh... " >&6; }
    if test ${ac_cv_path_tclsh+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
$as_echo_n "checking for tclsh... " >&6; }
    if ${ac_cv_path_tclsh+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do
	    for j in `ls -r $dir/tclsh[8-9]* 2> /dev/null` \
		    `ls -r $dir/tclsh* 2> /dev/null` ; do
		if test x"$ac_cv_path_tclsh" = x ; then
		    if test -f "$j" ; then
			ac_cv_path_tclsh=$j
			break
		    fi
		fi
	    done
	done
     ;;

esac
fi


    if test -f "$ac_cv_path_tclsh" ; then
	TCLSH_PROG="$ac_cv_path_tclsh"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $TCLSH_PROG" >&5
printf "%s\n" "$TCLSH_PROG" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $TCLSH_PROG" >&5
$as_echo "$TCLSH_PROG" >&6; }
    else
	# It is not an error if an installed version of Tcl can't be located.
	TCLSH_PROG=""
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: No tclsh found on PATH" >&5
printf "%s\n" "No tclsh found on PATH" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: No tclsh found on PATH" >&5
$as_echo "No tclsh found on PATH" >&6; }
    fi



    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tclsh in Tcl build directory" >&5
printf %s "checking for tclsh in Tcl build directory... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh in Tcl build directory" >&5
$as_echo_n "checking for tclsh in Tcl build directory... " >&6; }
    BUILD_TCLSH="${TCL_BIN_DIR}"/tclsh
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $BUILD_TCLSH" >&5
printf "%s\n" "$BUILD_TCLSH" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BUILD_TCLSH" >&5
$as_echo "$BUILD_TCLSH" >&6; }



#------------------------------------------------------------------------
# Handle the --prefix=... option
#------------------------------------------------------------------------

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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182



3183
3184
3185
3186



3187
3188
3189
3190
3191
3192
3193
3194

3195
3196
3197
3198
3199

3200
3201

3202
3203
3204
3205
3206
3207
3208

3209
3210
3211
3212
3213
3214


3215
3216
3217


3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232



3233
3234
3235
3236



3237
3238
3239
3240
3241
3242
3243
3244

3245
3246
3247
3248
3249

3250
3251

3252
3253
3254
3255
3256
3257
3258

3259
3260
3261
3262
3263
3264


3265
3266
3267


3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280


3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397


3398
3399

3400
3401
3402

3403
3404
3405

3406
3407
3408
3409
3410
3411
3412

3413
3414
3415
3416
3417
3418
3419
3420
3421
3422

3423
3424
3425
3426
3427
3428
3429
3430

3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444



3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465

3466
3467
3468
3469


3470
3471
3472


3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487

3488
3489
3490
3491
3492

3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504


3505
3506
3507

3508
3509
3510
3511



3512
3513
3514
3515


3516
3517
3518
3519
3520




3521
3522
3523
3524
3525
3526




3527
3528
3529
3530
3531
3532


3533
3534
3535
3536
3537
3538
3539

3540
3541
3542
3543


3544
3545
3546
3547
3548




3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560



3561
3562

3563
3564
3565
3566
3567


3568
3569
3570
3571
3572
3573
3574
3575
3576

3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591


3592
3593
3594
3595
3596
3597
3598
3599

3600
3601
3602

3603
3604
3605
3606
3607
3608
3609
3610

3611
3612
3613

3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624





3625
3626
3627
3628
3629


3630
3631

3632
3633
3634
3635
3636



3637
3638
3639
3640



3641
3642
3643
3644

3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658

3659
3660
3661
3662


3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673


3674
3675
3676
3677


3678
3679

3680
3681
3682

3683
3684
3685
3686


3687
3688
3689
3690
3691



3692
3693
3694
3695



3696
3697
3698
3699

3700
3701
3702
3703
3704
3705
3706
3707
3708
3709

3710
3711
3712
3713


3714
3715
3716

3717
3718

3719
3720
3721
3722


3723
3724
3725
3726
3727
3728
3729
3730

3731
3732
3733
3734



3735
3736
3737
3738



3739
3740
3741
3742
3743
3744
3745
3746

3747
3748
3749
3750
3751
3752
3753

3754
3755
3756
3757


3758
3759
3760
3761
3762

3763
3764
3765
3766
3767
3768
3769

3770
3771
3772
3773


3774
3775
3776
3777
3778
3779

3780
3781
3782
3783
3784
3785
3786

3787
3788
3789
3790

3791
3792
3793

3794
3795
3796
3797


3798
3799
3800
3801
3802



3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822



3823
3824
3825
3826



3827
3828
3829
3830
3831
3832
3833


3834
3835
3836

3837
3838
3839
3840
3841
3842




3843
3844
3845
3846
3847
3848












3849
3850
3851

3852
3853
3854
3855
3856
3857
3858
3859
3860









3861
3862
3863
3864
3865
3866
3867








3868
3869
3870
3871



3872
3873
3874



3875
3876

3877
3878


3879



3880
3881


3882
3883
3884

3885
3886

3887
3888
3889


3890
3891
3892

3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927

3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948








3949
3950


3951
3952
3953
3954
3955
3956


3957
3958
3959
3960
3961


3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975



3976
3977
3978
3979



3980
3981
3982
3983
3984
3985
3986


3987
3988
3989
3990

3991
3992
3993
3994

3995
3996
3997

3998
3999
4000
4001


4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017







































































































































































































































































































































































































































































4018
4019
4020
4021
4022
4023
4024
4025
4026
4027



4028
4029
4030
4031



4032
4033
4034
4035
4036
4037

4038
4039
4040
4041
4042
4043
4044

4045
4046
4047
4048


4049
4050
4051
4052


4053
4054
4055
4056


4057
4058
4059
4060
4061
4062
4063

4064
4065
4066






4067
4068
4069
4070
4071
4072
































































































































































4073













4074































4075











4076































4077












4078



































4079
4080

4081
4082

4083
4084
4085
4086





4087
4088


4089
4090

4091
4092
4093
4094
4095
4096











4097
4098
4099
4100


4101
4102
4103
4104


4105
4106
4107

4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124



4125
4126
4127
4128



4129
4130
4131
4132
4133
4134
4135
4136

4137
4138
4139
4140
4141

4142
4143

4144
4145
4146
4147
4148
4149
4150

4151
4152
4153
4154
4155
4156


4157
4158
4159


4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170



4171
4172
4173
4174



4175
4176
4177
4178
4179
4180
4181
4182

4183
4184
4185
4186
4187

4188
4189

4190
4191
4192
4193
4194
4195
4196

4197
4198
4199
4200
4201
4202


4203
4204
4205


4206
4207
4208
4209
4210
4211
4212
4213
4214


4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257


4258
4259

4260
4261
4262
4263


4264
4265
4266
4267
4268


4269
4270
4271
4272
4273


4274
4275

4276
4277
4278
4279


4280
4281
4282
4283
4284


4285
4286

4287
4288
4289
4290
4291
4292
4293
4294
4295
4296



4297
4298
4299
4300



4301
4302
4303
4304
4305
4306
4307
4308

4309
4310
4311
4312
4313
4314
4315

4316
4317
4318
4319


4320
4321
4322

4323
4324

4325
4326
4327
4328
4329



4330
4331
4332
4333

4334
4335
4336

4337
4338
4339
4340
4341
4342
4343
4344


4345
4346

4347
4348
4349
4350


4351
4352
4353
4354
4355


4356
4357
4358
4359
4360
4361
4362
4363



4364
4365
4366
4367



4368
4369
4370
4371
4372
4373
4374


4375
4376
4377
4378
4379
4380
4381
4382
4383
4384



4385
4386
4387
4388
4389


4390
4391
4392
4393
4394
4395
4396
4397
4398



4399
4400
4401
4402



4403
4404
4405
4406
4407
4408
4409

4410
4411
4412
4413
4414
4415
4416

4417
4418

4419
4420
4421
4422
4423
4424
4425

4426
4427
4428
4429


4430
4431
4432

4433
4434

4435
4436
4437
4438
4439



4440
4441
4442
4443


4444
4445
4446
4447
4448
4449
4450
4451
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
3171
3172
3173

3174
3175
3176


3177
3178

3179
3180
3181
3182
3183
3184
3185
3186


3187
3188
3189
3190


3191
3192
3193

3194

3195

3196

3197


3198
3199
3200
3201



3202
3203
3204




3205
3206
3207
3208
3209
3210

3211
3212
3213
3214
3215
3216
3217
3218
3219
3220

3221

3222


3223
3224

3225

3226
3227

3228

3229


3230
3231


3232
3233
3234
3235
3236

3237
3238



3239
3240
3241




3242
3243
3244
3245
3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258

3259

3260


3261
3262
3263
3264
3265
3266

3267
3268
3269
3270
3271
3272
3273

3274

3275


3276
3277
3278
3279
3280
3281
3282

3283
3284
3285
3286
3287
3288
3289

3290

3291
3292

3293

3294

3295

3296


3297
3298

3299



3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316






3317
3318
3319




3320
3321
3322
3323
3324
3325




3326
3327



3328






3329
3330
3331
3332






3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344



3345









3346
3347
3348
3349
3350
3351
3352
3353
3354







3355
3356
3357
3358
3359
3360
3361
3362




3363
3364
3365



3366
3367
3368


3369


3370
3371

3372
3373
3374
3375

3376
3377
3378
3379

3380


3381
3382


3383
3384
3385
3386

3387



































3388








3389












3390
3391
3392
3393
3394
3395
3396
3397


3398
3399






3400
3401

3402



3403
3404


3405
3406
3407
3408
3409
3410
3411
3412
3413



3414
3415
3416




3417
3418
3419
3420
3421
3422
3423
3424


3425
3426
3427
3428
3429

3430

3431
3432

3433
3434
3435

3436

3437


3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917



3918
3919
3920




3921
3922
3923
3924
3925
3926
3927
3928

3929
3930
3931
3932
3933
3934
3935

3936

3937


3938
3939

3940


3941
3942

3943


3944
3945
3946
3947
3948
3949
3950
3951

3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962





3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168

4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211

4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260

4261


4262
4263
4264
4265
4266
4267
4268
4269
4270
4271


4272
4273
4274

4275

4276




4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289


4290
4291
4292
4293


4294
4295
4296
4297

4298
4299
4300

4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311



4312
4313
4314




4315
4316
4317
4318
4319
4320
4321
4322
4323


4324



4325

4326
4327

4328
4329
4330
4331
4332
4333
4334

4335

4336
4337
4338


4339
4340
4341


4342
4343
4344
4345
4346
4347
4348
4349
4350
4351



4352
4353
4354




4355
4356
4357
4358
4359
4360
4361
4362
4363


4364



4365

4366
4367

4368
4369
4370
4371
4372
4373
4374

4375

4376
4377
4378


4379
4380
4381


4382
4383
4384
4385
4386
4387
4388
4389
4390


4391
4392
4393
4394
4395
4396
4397
4398
4399
4400















4401
4402














4403
4404


4405
4406
4407

4408

4409


4410
4411

4412
4413


4414
4415
4416
4417
4418


4419
4420
4421

4422

4423


4424
4425

4426
4427


4428
4429
4430

4431

4432
4433
4434
4435
4436
4437



4438
4439
4440




4441
4442
4443
4444
4445
4446
4447
4448
4449
4450

4451
4452
4453
4454
4455
4456
4457

4458

4459


4460
4461

4462

4463
4464

4465

4466



4467
4468
4469

4470
4471

4472
4473
4474

4475
4476
4477
4478
4479
4480
4481


4482
4483
4484

4485

4486


4487
4488

4489
4490


4491
4492
4493
4494
4495
4496
4497



4498
4499
4500




4501
4502
4503
4504
4505
4506
4507
4508


4509
4510
4511
4512
4513
4514
4515





4516
4517
4518


4519


4520
4521
4522
4523
4524
4525
4526
4527



4528
4529
4530




4531
4532
4533
4534
4535
4536
4537
4538
4539

4540



4541
4542
4543

4544
4545

4546
4547
4548
4549
4550
4551
4552

4553

4554


4555
4556

4557

4558
4559

4560

4561



4562
4563
4564

4565


4566
4567

4568
4569
4570
4571
4572
4573
4574







-
-
+
+

-
+
-

-
-
+
+
-


-
-
+
+

-
-
+
+

-
+
-





-
-
+
+
-


-
-
+
+

-
-
+
+





-
-
+
+


-
-
+
+

-
+
-





-
-
+
+
-


-
-
+
+














-
-
-
-
-
-
-
-
-








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+












-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+







-
-
+
-
-
-

-
-
+
+




-
+















-
+


-
+
-



-
-
+
+

-
-
+
+










-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+












-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+











-
-
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
+


-
+


-
+






-
+









-
+







-
+











-
-
-
+
+
+




















-
+


-
-
+
+
-
-
-
+
+














-
+




-
+










-
-
+
+
-

-
+
-
-
-
-
+
+
+


-
-
+
+

-
-
-
-
+
+
+
+
-

-
-
-
-
+
+
+
+




-
-
+
+






-
+


-
-
+
+
-
-
-
-
-
+
+
+
+









-
-
-
+
+
+

-
+
-


-
-
+
+








-
+


-
-









-
-
+
+







-
+


-
+







-
+


-
+






-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+



-
+













-
+


-
-
+
+
-








-
-
+
+


-
-
+
+

-
+
-

-
+
-

-
-
+
+


-
-
-
+
+
+
-
-
-
-
+
+
+



-
+









-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
+
+
-
-





-
+

-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+




-
+






-
+
-

-
-
+
+





-
+






-
+
-


-
+
-

-
+
-

-
-
+
+
-

-
-
-
+
+
+














-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+



-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
-
-
+
+
-
+
+
+

-
+
+


-
+
-
-
+

-
-
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
-

-
-
-
+
+
-
-









-
-
-
+
+
+
-
-
-
-
+
+
+





-
-
+
+



-
+
-


-
+


-
+
-

-
-
+
+
















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
+
+
+
-
-
-
-
+
+
+





-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+






-
+



+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
+




+
+
+
+
+
-
-
+
+

-
+
-

-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+


-
-
+
+


-
+


-











-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
+
+

-
+
-

-
-
+
+
-


-
-
+
+



-
-
+
+

-
+
-

-
-
+
+
-


-
-
+
+

-
+
-






-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-


-
+


-
+






-
-
+
+

-
+
-

-
-
+
+
-


-
-
+
+





-
-
-
+
+
+
-
-
-
-
+
+
+





-
-
+
+





-
-
-
-
-
+
+
+
-
-

-
-
+
+






-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-

-
-
+
+
-







TK_SRC_DIR="`cd "$srcdir"/..; pwd`"

#------------------------------------------------------------------------
# Compress and/or soft link the manpages?
#------------------------------------------------------------------------


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use symlinks for manpages" >&5
printf %s "checking whether to use symlinks for manpages... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use symlinks for manpages" >&5
$as_echo_n "checking whether to use symlinks for manpages... " >&6; }
    # Check whether --enable-man-symlinks was given.
if test ${enable_man_symlinks+y}
if test "${enable_man_symlinks+set}" = set; then :
then :
  enableval=$enable_man_symlinks; test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks"
else case e in #(
  e) enableval="no" ;;
else
  enableval="no"
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
printf "%s\n" "$enableval" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
$as_echo "$enableval" >&6; }

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to compress the manpages" >&5
printf %s "checking whether to compress the manpages... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to compress the manpages" >&5
$as_echo_n "checking whether to compress the manpages... " >&6; }
    # Check whether --enable-man-compression was given.
if test ${enable_man_compression+y}
if test "${enable_man_compression+set}" = set; then :
then :
  enableval=$enable_man_compression; case $enableval in
	    yes) as_fn_error $? "missing argument to --enable-man-compression" "$LINENO" 5;;
	    no)  ;;
	    *)   MAN_FLAGS="$MAN_FLAGS --compress $enableval";;
	esac
else case e in #(
  e) enableval="no" ;;
else
  enableval="no"
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
printf "%s\n" "$enableval" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
$as_echo "$enableval" >&6; }
    if test "$enableval" != "no"; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for compressed file suffix" >&5
printf %s "checking for compressed file suffix... " >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compressed file suffix" >&5
$as_echo_n "checking for compressed file suffix... " >&6; }
	touch TeST
	$enableval TeST
	Z=`ls TeST* | sed 's/^....//'`
	rm -f TeST*
	MAN_FLAGS="$MAN_FLAGS --extension $Z"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $Z" >&5
printf "%s\n" "$Z" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $Z" >&5
$as_echo "$Z" >&6; }
    fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to add a package name suffix for the manpages" >&5
printf %s "checking whether to add a package name suffix for the manpages... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to add a package name suffix for the manpages" >&5
$as_echo_n "checking whether to add a package name suffix for the manpages... " >&6; }
    # Check whether --enable-man-suffix was given.
if test ${enable_man_suffix+y}
if test "${enable_man_suffix+set}" = set; then :
then :
  enableval=$enable_man_suffix; case $enableval in
	    yes) enableval="tk" MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
	    no)  ;;
	    *)   MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
	esac
else case e in #(
  e) enableval="no" ;;
else
  enableval="no"
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
printf "%s\n" "$enableval" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
$as_echo "$enableval" >&6; }




#------------------------------------------------------------------------
# Standard compiler checks
#------------------------------------------------------------------------

# If the user did not set CFLAGS, set it now to keep
# the AC_PROG_CC macro from adding "-g -O2".
if test "${CFLAGS+set}" != "set" ; then
    CFLAGS=""
fi










ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}gcc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="gcc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

if test -z "$CC"; then
          if test -n "$ac_tool_prefix"; then
    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
set dummy ${ac_tool_prefix}cc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}cc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


  fi
fi
if test -z "$CC"; then
  # Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
  ac_prog_rejected=no
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
       ac_prog_rejected=yes
       continue
     fi
    ac_cv_prog_CC="cc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

if test $ac_prog_rejected = yes; then
  # We found a bogon in the path, so make sure we never use it.
  set dummy $ac_cv_prog_CC
  shift
  if test $# != 0; then
    # We chose a different compiler from the bogus one.
    # However, it has the same basename, so the bogon will be chosen
    # first if we set CC to just the basename; use the full file name.
    shift
    ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@"
    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
  fi
fi
fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  for ac_prog in cl.exe
  do
    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


    test -n "$CC" && break
  done
fi
if test -z "$CC"; then
  ac_ct_CC=$CC
  for ac_prog in cl.exe
do
  # Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="$ac_prog"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


  test -n "$ac_ct_CC" && break
done

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
fi

fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args.
set dummy ${ac_tool_prefix}clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "clang", so it can be a program name with args.
set dummy clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

fi


test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "no acceptable C compiler found in \$PATH
See 'config.log' for more details" "$LINENO" 5; }
See \`config.log' for more details" "$LINENO" 5; }

# Provide some information about the compiler.
printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion -version; do
for ac_option in --version -v -V -qversion; do
  { { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    sed '10a\
... rest of stderr output deleted ...
         10q' conftest.err >conftest.er1
    cat conftest.er1 >&5
  fi
  rm -f conftest.er1 conftest.err
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
done

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
# Try to create an executable without -o first, disregard a.out.
# It will help us diagnose broken compilers, and finding out an intuition
# of exeext.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
printf %s "checking whether the C compiler works... " >&6; }
ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
$as_echo_n "checking whether the C compiler works... " >&6; }
ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`

# The possible output files:
ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"

ac_rmfiles=
for ac_file in $ac_files
do
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
  esac
done
rm -f $ac_rmfiles

if { { ac_try="$ac_link_default"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link_default") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'.
# So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no'
  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
# in a Makefile.  We should not override ac_cv_exeext if it was cached,
# so that the user can short-circuit this test for compilers unknown to
# Autoconf.
for ac_file in $ac_files ''
do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
	;;
    [ab].out )
	# We found the default executable, but exeext='' is most
	# certainly right.
	break;;
    *.* )
	if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no;
	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
	then :; else
	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	fi
	# We set ac_cv_exeext here because the later test for it is not
	# safe: cross compilers may not add the suffix if given an '-o'
	# safe: cross compilers may not add the suffix if given an `-o'
	# argument, so we may need to know it at that point already.
	# Even if this section looks crufty: it has the advantage of
	# actually working.
	break;;
    * )
	break;;
  esac
done
test "$ac_cv_exeext" = no && ac_cv_exeext=

else case e in #(
  e) ac_file='' ;;
else
  ac_file=''
esac
fi
if test -z "$ac_file"
if test -z "$ac_file"; then :
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
printf "%s\n" "$as_me: failed program was:" >&5
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "C compiler cannot create executables
See 'config.log' for more details" "$LINENO" 5; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; } ;;
See \`config.log' for more details" "$LINENO" 5; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
printf %s "checking for C compiler default output file name... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
printf "%s\n" "$ac_file" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
$as_echo_n "checking for C compiler default output file name... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
$as_echo "$ac_file" >&6; }
ac_exeext=$ac_cv_exeext

rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
ac_clean_files=$ac_clean_files_save
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
printf %s "checking for suffix of executables... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
$as_echo_n "checking for suffix of executables... " >&6; }
if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  # If both 'conftest.exe' and 'conftest' are 'present' (well, observable)
# catch 'conftest.exe'.  For instance with Cygwin, 'ls conftest' will
# work properly (i.e., refer to 'conftest.exe'), while it won't with
# 'rm'.
  # If both `conftest.exe' and `conftest' are `present' (well, observable)
# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
# work properly (i.e., refer to `conftest.exe'), while it won't with
# `rm'.
for ac_file in conftest.exe conftest conftest.*; do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	  break;;
    * ) break;;
  esac
done
else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of executables: cannot compile and link
See 'config.log' for more details" "$LINENO" 5; } ;;
See \`config.log' for more details" "$LINENO" 5; }
esac
fi
rm -f conftest conftest$ac_cv_exeext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
printf "%s\n" "$ac_cv_exeext" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
$as_echo "$ac_cv_exeext" >&6; }

rm -f conftest.$ac_ext
EXEEXT=$ac_cv_exeext
ac_exeext=$EXEEXT
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdio.h>
int
main (void)
main ()
{
FILE *f = fopen ("conftest.out", "w");
 if (!f)
  return 1;
 return ferror (f) || fclose (f) != 0;

  ;
  return 0;
}
_ACEOF
ac_clean_files="$ac_clean_files conftest.out"
# Check that the compiler produces executables we can run.  If not, either
# the compiler is broken, or we cross compile.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
printf %s "checking whether we are cross compiling... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
$as_echo_n "checking whether we are cross compiling... " >&6; }
if test "$cross_compiling" != yes; then
  { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  if { ac_try='./conftest$ac_cv_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then
    cross_compiling=no
  else
    if test "$cross_compiling" = maybe; then
	cross_compiling=yes
    else
	{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error 77 "cannot run C compiled programs.
If you meant to cross compile, use '--host'.
See 'config.log' for more details" "$LINENO" 5; }
	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run C compiled programs.
If you meant to cross compile, use \`--host'.
See \`config.log' for more details" "$LINENO" 5; }
    fi
  fi
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
printf "%s\n" "$cross_compiling" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
$as_echo "$cross_compiling" >&6; }

rm -f conftest.$ac_ext conftest$ac_cv_exeext \
rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
  conftest.o conftest.obj conftest.out
ac_clean_files=$ac_clean_files_save
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
printf %s "checking for suffix of object files... " >&6; }
if test ${ac_cv_objext+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
$as_echo_n "checking for suffix of object files... " >&6; }
if ${ac_cv_objext+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
rm -f conftest.o conftest.obj
if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  for ac_file in conftest.o conftest.obj conftest.*; do
  test -f "$ac_file" || continue;
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
       break;;
  esac
done
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of object files: cannot compile
See 'config.log' for more details" "$LINENO" 5; } ;;
See \`config.log' for more details" "$LINENO" 5; }
esac
fi
rm -f conftest.$ac_cv_objext conftest.$ac_ext ;;
rm -f conftest.$ac_cv_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
printf "%s\n" "$ac_cv_objext" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
$as_echo "$ac_cv_objext" >&6; }
OBJEXT=$ac_cv_objext
ac_objext=$OBJEXT
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5
printf %s "checking whether the compiler supports GNU C... " >&6; }
if test ${ac_cv_c_compiler_gnu+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
if ${ac_cv_c_compiler_gnu+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
#ifndef __GNUC__
       choke me
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_compiler_gnu=yes
else case e in #(
  e) ac_compiler_gnu=no ;;
else
  ac_compiler_gnu=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_cv_c_compiler_gnu=$ac_compiler_gnu
 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
$as_echo "$ac_cv_c_compiler_gnu" >&6; }
ac_compiler_gnu=$ac_cv_c_compiler_gnu

if test $ac_compiler_gnu = yes; then
  GCC=yes
else
  GCC=
fi
ac_test_CFLAGS=${CFLAGS+y}
ac_test_CFLAGS=${CFLAGS+set}
ac_save_CFLAGS=$CFLAGS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
printf %s "checking whether $CC accepts -g... " >&6; }
if test ${ac_cv_prog_cc_g+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
$as_echo_n "checking whether $CC accepts -g... " >&6; }
if ${ac_cv_prog_cc_g+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_save_c_werror_flag=$ac_c_werror_flag
  $as_echo_n "(cached) " >&6
else
  ac_save_c_werror_flag=$ac_c_werror_flag
   ac_c_werror_flag=yes
   ac_cv_prog_cc_g=no
   CFLAGS="-g"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_g=yes
else case e in #(
  e) CFLAGS=""
else
  CFLAGS=""
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :

else case e in #(
  e) ac_c_werror_flag=$ac_save_c_werror_flag
else
  ac_c_werror_flag=$ac_save_c_werror_flag
	 CFLAGS="-g"
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_g=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
printf "%s\n" "$ac_cv_prog_cc_g" >&6; }
if test $ac_test_CFLAGS; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
$as_echo "$ac_cv_prog_cc_g" >&6; }
if test "$ac_test_CFLAGS" = set; then
  CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
  if test "$GCC" = yes; then
    CFLAGS="-g -O2"
  else
    CFLAGS="-g"
  fi
else
  if test "$GCC" = yes; then
    CFLAGS="-O2"
  else
    CFLAGS=
  fi
fi
ac_prog_cc_stdc=no
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5
printf %s "checking for $CC option to enable C11 features... " >&6; }
if test ${ac_cv_prog_cc_c11+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
if ${ac_cv_prog_cc_c89+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c11=no
  $as_echo_n "(cached) " >&6
else
  ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c11_program
_ACEOF
for ac_arg in '' -std=gnu11
do
#include <stdarg.h>
#include <stdio.h>
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
struct stat;
  ac_cv_prog_cc_c11=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c11" != "xno" && break
done
rm -f conftest.$ac_ext
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c11" = xno
then :
     char **p;
     int i;
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  return s;
  e) if test "x$ac_cv_prog_cc_c11" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5
printf "%s\n" "$ac_cv_prog_cc_c11" >&6; }
     CC="$CC $ac_cv_prog_cc_c11" ;;
esac
}

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not '\xHH' hex character constants.
   These don't provoke an error unfortunately, instead are silently treated
   as 'x'.  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
   array size at least.  It's necessary to write '\x00'==0 to get something
   that's true only with -std.  */
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11
  ac_prog_cc_stdc=c11 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
int osf4_cc_array ['\x00' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];

int test (int i, double x);
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5
printf %s "checking for $CC option to enable C99 features... " >&6; }
if test ${ac_cv_prog_cc_c99+y}
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
then :
  printf %s "(cached) " >&6
else case e in #(
int argc;
char **argv;
int
  e) ac_cv_prog_cc_c99=no
ac_save_CC=$CC
main ()
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
{
return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
$ac_c_conftest_c99_program
  ;
  return 0;
}
_ACEOF
for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99=
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
  if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_c99=$ac_arg
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c99" != "xno" && break
rm -f core conftest.err conftest.$ac_objext
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
CC=$ac_save_CC
esac
fi

if test "x$ac_cv_prog_cc_c99" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c99" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5
printf "%s\n" "$ac_cv_prog_cc_c99" >&6; }
     CC="$CC $ac_cv_prog_cc_c99" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99
  ac_prog_cc_stdc=c99 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5
printf %s "checking for $CC option to enable C89 features... " >&6; }
if test ${ac_cv_prog_cc_c89+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

$ac_c_conftest_c89_program
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c89" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
# AC_CACHE_VAL
case "x$ac_cv_prog_cc_c89" in
  x)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
$as_echo "none needed" >&6; } ;;
  xno)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
$as_echo "unsupported" >&6; } ;;
else case e in #(
  e) if test "x$ac_cv_prog_cc_c89" = x
  *)
    CC="$CC $ac_cv_prog_cc_c89"
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
printf "%s\n" "$ac_cv_prog_cc_c89" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
     CC="$CC $ac_cv_prog_cc_c89" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89
  ac_prog_cc_stdc=c89 ;;
if test "x$ac_cv_prog_cc_c89" != xno; then :

esac
fi
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
printf %s "checking for inline... " >&6; }
if test ${ac_cv_c_inline+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
$as_echo_n "checking for inline... " >&6; }
if ${ac_cv_c_inline+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_c_inline=no
  $as_echo_n "(cached) " >&6
else
  ac_cv_c_inline=no
for ac_kw in inline __inline__ __inline; do
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifndef __cplusplus
typedef int foo_t;
static $ac_kw foo_t static_foo (void) {return 0; }
$ac_kw foo_t foo (void) {return 0; }
static $ac_kw foo_t static_foo () {return 0; }
$ac_kw foo_t foo () {return 0; }
#endif

_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_c_inline=$ac_kw
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  test "$ac_cv_c_inline" != no && break
done
 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
printf "%s\n" "$ac_cv_c_inline" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
$as_echo "$ac_cv_c_inline" >&6; }

case $ac_cv_c_inline in
  inline | yes) ;;
  *)
    case $ac_cv_c_inline in
      no) ac_val=;;
      *) ac_val=$ac_cv_c_inline;;
    esac
    cat >>confdefs.h <<_ACEOF
#ifndef __cplusplus
#define inline $ac_val
#endif
_ACEOF
    ;;
esac


#--------------------------------------------------------------------
# Supply a substitute for stdlib.h if it doesn't define strtol,
# strtoul, or strtod (which it doesn't in some versions of SunOS).
#--------------------------------------------------------------------

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
$as_echo_n "checking how to run the C preprocessor... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
  CPP=
fi
if test -z "$CPP"; then
  if ${ac_cv_prog_CPP+:} false; then :
  $as_echo_n "(cached) " >&6
else
      # Double quotes because CPP needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
    do
      ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :

else
  # Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
  break
fi

    done
    ac_cv_prog_CPP=$CPP

fi
  CPP=$ac_cv_prog_CPP
else
  ac_cv_prog_CPP=$CPP
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
$as_echo "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :

else
  # Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :

else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See \`config.log' for more details" "$LINENO" 5; }
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
if ${ac_cv_path_GREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -z "$GREP"; then
  ac_path_GREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in grep ggrep; do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
  # Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
*GNU*)
  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'GREP' >> "conftest.nl"
    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_GREP_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_GREP="$ac_path_GREP"
      ac_path_GREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_GREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_GREP"; then
    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_GREP=$GREP
fi

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
$as_echo "$ac_cv_path_GREP" >&6; }
 GREP="$ac_cv_path_GREP"


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
$as_echo_n "checking for egrep... " >&6; }
if ${ac_cv_path_EGREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
   then ac_cv_path_EGREP="$GREP -E"
   else
     if test -z "$EGREP"; then
  ac_path_EGREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in egrep; do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
  # Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
*GNU*)
  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'EGREP' >> "conftest.nl"
    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP="$ac_path_EGREP"
      ac_path_EGREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP"; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_EGREP=$EGREP
fi

   fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
$as_echo "$ac_cv_path_EGREP" >&6; }
 EGREP="$ac_cv_path_EGREP"


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>

int
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_cv_header_stdc=yes
else
  ac_cv_header_stdc=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

if test $ac_cv_header_stdc = yes; then
  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <string.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "memchr" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "free" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  if test "$cross_compiling" = yes; then :
  :
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ctype.h>
#include <stdlib.h>
#if ((' ' & 0x0FF) == 0x020)
# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
#else
# define ISLOWER(c) \
		   (('a' <= (c) && (c) <= 'i') \
		     || ('j' <= (c) && (c) <= 'r') \
		     || ('s' <= (c) && (c) <= 'z'))
# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
#endif

#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
int
main ()
{
  int i;
  for (i = 0; i < 256; i++)
    if (XOR (islower (i), ISLOWER (i))
	|| toupper (i) != TOUPPER (i))
      return 2;
  return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :

else
  ac_cv_header_stdc=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
$as_echo "$ac_cv_header_stdc" >&6; }
if test $ac_cv_header_stdc = yes; then

$as_echo "#define STDC_HEADERS 1" >>confdefs.h

fi

# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
		  inttypes.h stdint.h unistd.h
do :
  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF

fi

done


ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
if test "x$ac_cv_header_stdlib_h" = xyes; then :
  tk_ok=1
else
  tk_ok=0
fi


cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "strtol" >/dev/null 2>&1; then :

else
  tk_ok=0
fi
rm -f conftest*

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "strtoul" >/dev/null 2>&1; then :

else
  tk_ok=0
fi
rm -f conftest*

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "strtod" >/dev/null 2>&1; then :

else
  tk_ok=0
fi
rm -f conftest*

if test $tk_ok = 0; then

$as_echo "#define NO_STDLIB_H 1" >>confdefs.h

fi

#------------------------------------------------------------------------
# If we're using GCC, see if the compiler understands -pipe.  If so, use it.
# It makes compiling go faster.  (This is only a performance feature.)
#------------------------------------------------------------------------

if test -z "$no_pipe" && test -n "$GCC"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -pipe" >&5
printf %s "checking if the compiler understands -pipe... " >&6; }
if test ${tcl_cv_cc_pipe+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -pipe" >&5
$as_echo_n "checking if the compiler understands -pipe... " >&6; }
if ${tcl_cv_cc_pipe+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_cc_pipe=yes
else case e in #(
  e) tcl_cv_cc_pipe=no ;;
else
  tcl_cv_cc_pipe=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	CFLAGS=$hold_cflags ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_pipe" >&5
printf "%s\n" "$tcl_cv_cc_pipe" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_pipe" >&5
$as_echo "$tcl_cv_cc_pipe" >&6; }
    if test $tcl_cv_cc_pipe = yes; then
	CFLAGS="$CFLAGS -pipe"
    fi
fi

#------------------------------------------------------------------------
# Embedded configuration information, encoding to use for the values, TIP #59
# Threads support - this auto-enables if Tcl was compiled threaded
#------------------------------------------------------------------------


    # Check whether --enable-threads was given.
if test "${enable_threads+set}" = set; then :
  enableval=$enable_threads; tcl_ok=$enableval
else
  tcl_ok=yes
fi

# Check whether --with-encoding was given.
if test ${with_encoding+y}
then :
  withval=$with_encoding; with_tcencoding=${withval}
fi

    if test "${TCL_THREADS}" = 1; then
	tcl_threaded_core=1;
    fi

    if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then
	TCL_THREADS=1
	# USE_THREAD_ALLOC tells us to try the special thread-based
	# allocator that significantly reduces lock contention

$as_echo "#define USE_THREAD_ALLOC 1" >>confdefs.h


$as_echo "#define _REENTRANT 1" >>confdefs.h

	if test "`uname -s`" = "SunOS" ; then

$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h

	fi

$as_echo "#define _THREAD_SAFE 1" >>confdefs.h

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthread" >&5
$as_echo_n "checking for pthread_mutex_init in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
int
main ()
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_pthread_pthread_mutex_init=yes
else
  ac_cv_lib_pthread_pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthread_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread_pthread_mutex_init" = xyes; then :
  tcl_ok=yes
else
  tcl_ok=no
fi

	if test "$tcl_ok" = "no"; then
	    # Check a little harder for __pthread_mutex_init in the same
	    # library, as some systems hide it there until pthread.h is
	    # defined.  We could alternatively do an AC_TRY_COMPILE with
	    # pthread.h, but that will work with libpthread really doesn't
	    # exist, like AIX 4.2.  [Bug: 4359]
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __pthread_mutex_init in -lpthread" >&5
$as_echo_n "checking for __pthread_mutex_init in -lpthread... " >&6; }
if ${ac_cv_lib_pthread___pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char __pthread_mutex_init ();
int
main ()
{
return __pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_pthread___pthread_mutex_init=yes
else
  ac_cv_lib_pthread___pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread___pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthread___pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread___pthread_mutex_init" = xyes; then :
  tcl_ok=yes
else
  tcl_ok=no
fi

	fi

	if test "$tcl_ok" = "yes"; then
	    # The space is needed
	    THREADS_LIBS=" -lpthread"
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthreads" >&5
$as_echo_n "checking for pthread_mutex_init in -lpthreads... " >&6; }
if ${ac_cv_lib_pthreads_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthreads  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
int
main ()
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_pthreads_pthread_mutex_init=yes
else
  ac_cv_lib_pthreads_pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthreads_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthreads_pthread_mutex_init" = xyes; then :
  tcl_ok=yes
else
  tcl_ok=no
fi

	    if test "$tcl_ok" = "yes"; then
		# The space is needed
		THREADS_LIBS=" -lpthreads"
	    else
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc" >&5
$as_echo_n "checking for pthread_mutex_init in -lc... " >&6; }
if ${ac_cv_lib_c_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lc  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
int
main ()
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_c_pthread_mutex_init=yes
else
  ac_cv_lib_c_pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_c_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_pthread_mutex_init" = xyes; then :
  tcl_ok=yes
else
  tcl_ok=no
fi
    if test x"${with_tcencoding}" != x ; then

		if test "$tcl_ok" = "no"; then
		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc_r" >&5
$as_echo_n "checking for pthread_mutex_init in -lc_r... " >&6; }
if ${ac_cv_lib_c_r_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lc_r  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
int
main ()
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_c_r_pthread_mutex_init=yes
else
  ac_cv_lib_c_r_pthread_mutex_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_c_r_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_r_pthread_mutex_init" = xyes; then :
  tcl_ok=yes
else
  tcl_ok=no
fi
printf "%s\n" "#define TCL_CFGVAL_ENCODING \"${with_tcencoding}\"" >>confdefs.h

		    if test "$tcl_ok" = "yes"; then
			# The space is needed
			THREADS_LIBS=" -pthread"
		    else
			TCL_THREADS=0
			{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how to find pthread lib on your system - you must disable thread support or edit the LIBS in the Makefile..." >&5
$as_echo "$as_me: WARNING: Don't know how to find pthread lib on your system - you must disable thread support or edit the LIBS in the Makefile..." >&2;}
		    fi
		fi
	    fi
	fi

	# Does the pthread-implementation provide
	# 'pthread_attr_setstacksize' ?

	ac_saved_libs=$LIBS
	LIBS="$LIBS $THREADS_LIBS"
	for ac_func in pthread_attr_setstacksize pthread_atfork
do :
  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done

	LIBS=$ac_saved_libs
    else
	TCL_THREADS=0
    fi
    # Do checking message here to not mess up interleaved configure output
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for building with threads" >&5
$as_echo_n "checking for building with threads... " >&6; }
    if test "${TCL_THREADS}" = 1; then

$as_echo "#define TCL_THREADS 1" >>confdefs.h

	if test "${tcl_threaded_core}" = 1; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (threaded core)" >&5
$as_echo "yes (threaded core)" >&6; }
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	fi
    else

	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "#define TCL_CFGVAL_ENCODING \"utf-8\"" >>confdefs.h

$as_echo "no" >&6; }
    fi




# Add the threads support libraries
LIBS="$LIBS$THREADS_LIBS"


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
printf %s "checking how to build libraries... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
$as_echo_n "checking how to build libraries... " >&6; }
    # Check whether --enable-shared was given.
if test ${enable_shared+y}
if test "${enable_shared+set}" = set; then :
then :
  enableval=$enable_shared; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
esac
fi
else
  tcl_ok=yes
fi


    if test "${enable_shared+set}" = set; then
	enableval="$enable_shared"
	tcl_ok=$enableval
    else
	tcl_ok=yes
    fi

    if test "$tcl_ok" = "yes" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared" >&5
printf "%s\n" "shared" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: shared" >&5
$as_echo "shared" >&6; }
	SHARED_BUILD=1
    else
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5
printf "%s\n" "static" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: static" >&5
$as_echo "static" >&6; }
	SHARED_BUILD=0

printf "%s\n" "#define STATIC_BUILD 1" >>confdefs.h
$as_echo "#define STATIC_BUILD 1" >>confdefs.h

    fi



#--------------------------------------------------------------------
# The statements below define a collection of compile flags.  This
# macro depends on the value of SHARED_BUILD, and should be called
# after SC_ENABLE_SHARED checks the configure switches.
#--------------------------------------------------------------------

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RANLIB+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RANLIB+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RANLIB"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
printf "%s\n" "$RANLIB" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
$as_echo "$RANLIB" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RANLIB+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RANLIB"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
printf "%s\n" "$ac_ct_RANLIB" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
$as_echo "$ac_ct_RANLIB" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_RANLIB" = x; then
    RANLIB=":"
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RANLIB=$ac_ct_RANLIB
  fi
else
  RANLIB="$ac_cv_prog_RANLIB"
fi

ac_header= ac_cache=
for ac_item in $ac_header_c_list
do
  if test $ac_cache; then
    ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default"
    if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then
      printf "%s\n" "#define $ac_item 1" >> confdefs.h
    fi
    ac_header= ac_cache=
  elif test $ac_header; then
    ac_cache=$ac_item
  else
    ac_header=$ac_item
  fi
done








if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes
then :

printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h

fi


    # Step 0.a: Enable 64 bit support?

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
printf %s "checking if 64bit support is requested... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
$as_echo_n "checking if 64bit support is requested... " >&6; }
    # Check whether --enable-64bit was given.
if test ${enable_64bit+y}
if test "${enable_64bit+set}" = set; then :
then :
  enableval=$enable_64bit; do64bit=$enableval
else case e in #(
  e) do64bit=no ;;
else
  do64bit=no
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
printf "%s\n" "$do64bit" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
$as_echo "$do64bit" >&6; }

    # Step 0.b: Enable Solaris 64 bit VIS support?

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 64bit Sparc VIS support is requested" >&5
printf %s "checking if 64bit Sparc VIS support is requested... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit Sparc VIS support is requested" >&5
$as_echo_n "checking if 64bit Sparc VIS support is requested... " >&6; }
    # Check whether --enable-64bit-vis was given.
if test ${enable_64bit_vis+y}
if test "${enable_64bit_vis+set}" = set; then :
then :
  enableval=$enable_64bit_vis; do64bitVIS=$enableval
else case e in #(
  e) do64bitVIS=no ;;
else
  do64bitVIS=no
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $do64bitVIS" >&5
printf "%s\n" "$do64bitVIS" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bitVIS" >&5
$as_echo "$do64bitVIS" >&6; }
    # Force 64bit on with VIS
    if test "$do64bitVIS" = "yes"
    if test "$do64bitVIS" = "yes"; then :
then :
  do64bit=yes
fi

    # Step 0.c: Check if visibility support is available. Do this here so
    # that platform specific alternatives can be used below if this fails.

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler supports visibility \"hidden\"" >&5
printf %s "checking if compiler supports visibility \"hidden\"... " >&6; }
if test ${tcl_cv_cc_visibility_hidden+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler supports visibility \"hidden\"" >&5
$as_echo_n "checking if compiler supports visibility \"hidden\"... " >&6; }
if ${tcl_cv_cc_visibility_hidden+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	    extern __attribute__((__visibility__("hidden"))) void f(void);
	    void f(void) {}
int
main (void)
main ()
{
f();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_cc_visibility_hidden=yes
else case e in #(
  e) tcl_cv_cc_visibility_hidden=no ;;
else
  tcl_cv_cc_visibility_hidden=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
	CFLAGS=$hold_cflags ;;
	CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_visibility_hidden" >&5
printf "%s\n" "$tcl_cv_cc_visibility_hidden" >&6; }
    if test $tcl_cv_cc_visibility_hidden = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_visibility_hidden" >&5
$as_echo "$tcl_cv_cc_visibility_hidden" >&6; }
    if test $tcl_cv_cc_visibility_hidden = yes; then :
then :


printf "%s\n" "#define MODULE_SCOPE extern __attribute__((__visibility__(\"hidden\")))" >>confdefs.h
$as_echo "#define MODULE_SCOPE extern __attribute__((__visibility__(\"hidden\")))" >>confdefs.h


printf "%s\n" "#define HAVE_HIDDEN 1" >>confdefs.h
$as_echo "#define HAVE_HIDDEN 1" >>confdefs.h


fi

    # Step 0.d: Disable -rpath support?

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if rpath support is requested" >&5
printf %s "checking if rpath support is requested... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if rpath support is requested" >&5
$as_echo_n "checking if rpath support is requested... " >&6; }
    # Check whether --enable-rpath was given.
if test ${enable_rpath+y}
if test "${enable_rpath+set}" = set; then :
then :
  enableval=$enable_rpath; doRpath=$enableval
else case e in #(
  e) doRpath=yes ;;
else
  doRpath=yes
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5
printf "%s\n" "$doRpath" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5
$as_echo "$doRpath" >&6; }

    # Step 1: set the variable "system" to hold the name and version number
    # for the system.


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking system version" >&5
printf %s "checking system version... " >&6; }
if test ${tcl_cv_sys_version+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5
$as_echo_n "checking system version... " >&6; }
if ${tcl_cv_sys_version+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	if test "${TEA_PLATFORM}" = "windows" ; then
	    tcl_cv_sys_version=windows
	else
	    tcl_cv_sys_version=`uname -s`-`uname -r`
	    if test "$?" -ne 0 ; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
printf "%s\n" "$as_me: WARNING: can't find uname command" >&2;}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
$as_echo "$as_me: WARNING: can't find uname command" >&2;}
		tcl_cv_sys_version=unknown
	    else
		if test "`uname -s`" = "AIX" ; then
		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
		fi
		if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then
		    tcl_cv_sys_version=NetBSD-Debian
		fi
	    fi
	fi
	    fi
	fi

     ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
printf "%s\n" "$tcl_cv_sys_version" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
$as_echo "$tcl_cv_sys_version" >&6; }
    system=$tcl_cv_sys_version


    # Step 2: check for existence of -ldl library.  This is needed because
    # Linux can use either -ldl or -ldld for dynamic loading.

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
printf %s "checking for dlopen in -ldl... " >&6; }
if test ${ac_cv_lib_dl_dlopen+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
$as_echo_n "checking for dlopen in -ldl... " >&6; }
if ${ac_cv_lib_dl_dlopen+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-ldl  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char dlopen (void);
char dlopen ();
int
main (void)
main ()
{
return dlopen ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_dl_dlopen=yes
else case e in #(
  e) ac_cv_lib_dl_dlopen=no ;;
else
  ac_cv_lib_dl_dlopen=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; }
if test "x$ac_cv_lib_dl_dlopen" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
then :
  have_dl=yes
else case e in #(
  e) have_dl=no ;;
else
  have_dl=no
esac
fi


    # Require ranlib early so we can override it in special cases below.



4460
4461
4462
4463
4464
4465
4466
4467

4468
4469
4470
4471

4472
4473
4474
4475
4476
4477
4478
4479

4480
4481
4482
4483
4484
4485

4486
4487
4488
4489
4490
4491
4492
4493



4494
4495
4496
4497



4498
4499
4500
4501
4502
4503
4504
4505

4506
4507
4508
4509
4510

4511
4512

4513
4514
4515
4516
4517
4518
4519

4520
4521
4522
4523
4524
4525


4526
4527
4528


4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539



4540
4541
4542
4543



4544
4545
4546
4547
4548
4549
4550
4551

4552
4553
4554
4555
4556

4557
4558

4559
4560
4561
4562
4563
4564
4565

4566
4567
4568
4569
4570
4571


4572
4573
4574


4575
4576
4577
4578
4579
4580
4581
4582
4583


4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597

4598
4599
4600
4601
4602
4603

4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617


4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632

4633
4634
4635

4636
4637
4638
4639


4640
4641
4642


4643
4644
4645
4646
4647
4648
4649

4650
4651
4652
4653
4654
4655

4656
4657
4658
4659
4660
4661
4662

4663
4664
4665
4666
4667
4668


4669
4670

4671
4672
4673
4674
4675
4676
4677



4678
4679
4680
4681
4682
4683


4684
4685
4686

4687
4688
4689
4690
4691
4692
4693

4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711



4712
4713
4714
4715



4716
4717
4718
4719
4720
4721
4722

4723
4724
4725
4726
4727
4728
4729

4730
4731

4732
4733
4734
4735
4736
4737
4738

4739
4740
4741
4742


4743
4744
4745

4746
4747

4748
4749
4750
4751
4752



4753
4754
4755
4756
4757
4758
4759
4760
4583
4584
4585
4586
4587
4588
4589

4590

4591
4592

4593







4594
4595
4596


4597
4598

4599

4600
4601
4602
4603



4604
4605
4606




4607
4608
4609
4610
4611
4612
4613
4614
4615


4616



4617

4618
4619

4620
4621
4622
4623
4624
4625
4626

4627

4628
4629
4630


4631
4632
4633


4634
4635
4636
4637
4638
4639
4640
4641
4642
4643



4644
4645
4646




4647
4648
4649
4650
4651
4652
4653
4654
4655


4656



4657

4658
4659

4660
4661
4662
4663
4664
4665
4666

4667

4668
4669
4670


4671
4672
4673


4674
4675
4676
4677
4678
4679
4680
4681
4682


4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697

4698

4699
4700
4701
4702

4703

4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714


4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730

4731

4732

4733

4734


4735
4736
4737


4738
4739
4740
4741
4742
4743
4744
4745

4746

4747
4748
4749
4750

4751

4752
4753
4754
4755
4756

4757

4758
4759
4760


4761
4762
4763

4764

4765
4766
4767



4768
4769
4770

4771
4772
4773


4774
4775
4776
4777

4778

4779
4780
4781
4782
4783

4784

4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798



4799
4800
4801




4802
4803
4804
4805
4806
4807
4808
4809
4810

4811



4812
4813
4814

4815
4816

4817
4818
4819
4820
4821
4822
4823

4824

4825


4826
4827

4828

4829
4830

4831

4832



4833
4834
4835

4836
4837
4838
4839
4840
4841
4842







-
+
-


-
+
-
-
-
-
-
-
-

+

-
-


-
+
-




-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+













-
+
-




-
+
-











-
-
+
+














-
+
-

-
+
-

-
-
+
+

-
-
+
+






-
+
-




-
+
-





-
+
-



-
-
+
+

-
+
-



-
-
-
+
+
+
-



-
-
+
+


-
+
-





-
+
-














-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-







    # is disabled by the user. [Bug 1016796]
    LDFLAGS_ARCH=""
    UNSHARED_LIB_SUFFIX=""
    TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`'
    ECHO_VERSION='`echo ${VERSION}`'
    TCL_LIB_VERSIONS_OK=ok
    CFLAGS_DEBUG=-g
    if test "$GCC" = yes
    if test "$GCC" = yes; then :
then :

	CFLAGS_OPTIMIZE=-O2
	CFLAGS_WARNING="-Wall -Wextra -Wshadow -Wundef -Wwrite-strings -Wpointer-arith"
	CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement"
	case "${CC}" in
	    *++|*++-*)
		;;
	    *)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wc++-compat -fextended-identifiers"
		;;
	esac

else

else case e in #(
  e)
	CFLAGS_OPTIMIZE=-O
	CFLAGS_WARNING=""
     ;;

esac
fi
    if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
set dummy ${ac_tool_prefix}ar; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_AR+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_AR+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$AR"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$AR"; then
  ac_cv_prog_AR="$AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_AR="${ac_tool_prefix}ar"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
AR=$ac_cv_prog_AR
if test -n "$AR"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
printf "%s\n" "$AR" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
$as_echo "$AR" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_AR"; then
  ac_ct_AR=$AR
  # Extract the first word of "ar", so it can be a program name with args.
set dummy ar; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_AR+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_AR+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_AR"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_AR"; then
  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_AR="ar"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_AR=$ac_cv_prog_ac_ct_AR
if test -n "$ac_ct_AR"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
printf "%s\n" "$ac_ct_AR" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
$as_echo "$ac_ct_AR" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_AR" = x; then
    AR=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    AR=$ac_ct_AR
  fi
else
  AR="$ac_cv_prog_AR"
fi

    STLIB_LD='${AR} cr'
    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
    PLAT_OBJS=""
    PLAT_SRCS=""
    LDAIX_SRC=""
    if test "x${SHLIB_VERSION}" = x
    if test "x${SHLIB_VERSION}" = x; then :
then :
  SHLIB_VERSION="1.0"
fi
    case $system in
	AIX-*)
	    if test "$GCC" != "yes"
	    if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"; then :
then :

		# AIX requires the _r compiler when gcc isn't being used
		case "${CC}" in
		    *_r|*_r\ *)
			# ok ...
			;;
		    *)
			# Make sure only first arg gets _r
		    	CC=`echo "$CC" | sed -e 's/^\([^ ]*\)/\1_r/'`
			;;
		esac
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Using $CC for compiling with threads" >&5
printf "%s\n" "Using $CC for compiling with threads" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Using $CC for compiling with threads" >&5
$as_echo "Using $CC for compiling with threads" >&6; }

fi
	    LIBS="$LIBS -lc"
	    SHLIB_CFLAGS=""
	    SHLIB_SUFFIX=".so"

	    DL_OBJS="tclLoadDl.o"
	    LD_LIBRARY_PATH_VAR="LIBPATH"

	    # ldAix No longer needed with use of -bexpall/-brtl
	    # but some extensions may still reference it
	    LDAIX_SRC='$(UNIX_DIR)/ldAix'

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = yes
	    if test "$do64bit" = yes; then :
then :

		if test "$GCC" = yes
		if test "$GCC" = yes; then :
then :

		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
		    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}

else case e in #(
  e)
else

		    do64bit_ok=yes
		    CFLAGS="$CFLAGS -q64"
		    LDFLAGS_ARCH="-q64"
		    RANLIB="${RANLIB} -X64"
		    AR="${AR} -X64"
		    SHLIB_LD_FLAGS="-b64"
		 ;;

esac
fi

fi

	    if test "`uname -m`" = ia64
	    if test "`uname -m`" = ia64; then :
then :

		# AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC
		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
		# AIX-5 has dl* in libc.so
		DL_LIBS=""
		if test "$GCC" = yes
		if test "$GCC" = yes; then :
then :

		    CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'

else case e in #(
  e)
else

		    CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}'
		 ;;

esac
fi
		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'

else case e in #(
  e)
		if test "$GCC" = yes
else

		if test "$GCC" = yes; then :
then :

		    SHLIB_LD='${CC} -shared -Wl,-bexpall'

else case e in #(
  e)
else

		    SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry"
		    LDFLAGS="$LDFLAGS -brtl"
		 ;;

esac
fi
		SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}"
		DL_LIBS="-ldl"
		CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	     ;;

esac
fi
	    ;;
	BeOS*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD='${CC} -nostart'
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"

	    #-----------------------------------------------------------
	    # Check for inet_ntoa in -lbind, for BeOS (which also needs
	    # -lsocket, even if the network functions are in -lnet which
	    # is always linked to, for compatibility.
	    #-----------------------------------------------------------
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lbind" >&5
printf %s "checking for inet_ntoa in -lbind... " >&6; }
if test ${ac_cv_lib_bind_inet_ntoa+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lbind" >&5
$as_echo_n "checking for inet_ntoa in -lbind... " >&6; }
if ${ac_cv_lib_bind_inet_ntoa+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lbind  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char inet_ntoa (void);
char inet_ntoa ();
int
main (void)
main ()
{
return inet_ntoa ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_bind_inet_ntoa=yes
else case e in #(
  e) ac_cv_lib_bind_inet_ntoa=no ;;
else
  ac_cv_lib_bind_inet_ntoa=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_inet_ntoa" >&5
printf "%s\n" "$ac_cv_lib_bind_inet_ntoa" >&6; }
if test "x$ac_cv_lib_bind_inet_ntoa" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_inet_ntoa" >&5
$as_echo "$ac_cv_lib_bind_inet_ntoa" >&6; }
if test "x$ac_cv_lib_bind_inet_ntoa" = xyes; then :
then :
  LIBS="$LIBS -lbind -lsocket"
fi

	    ;;
	BSD/OS-2.1*|BSD/OS-3*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="shlicc -r"
4770
4771
4772
4773
4774
4775
4776
4777
4778


4779
4780
4781
4782
4783
4784
4785
4786



4787
4788
4789



4790
4791
4792
4793



4794
4795
4796
4797
4798
4799
4800
4801

4802
4803
4804
4805
4806
4807
4808

4809
4810
4811
4812


4813
4814
4815
4816


4817
4818
4819
4820


4821
4822
4823



4824
4825
4826

4827
4828

4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849

4850
4851
4852
4853
4854



4855
4856
4857
4858



4859
4860
4861
4862
4863
4864
4865

4866
4867
4868
4869
4870
4871
4872

4873
4874

4875
4876
4877
4878
4879
4880
4881

4882
4883
4884
4885


4886
4887
4888

4889
4890

4891
4892
4893
4894
4895



4896
4897
4898
4899
4900
4901
4902
4903
4904

4905
4906
4907

4908
4909
4910
4911

4912
4913
4914
4915
4916
4917


4918
4919

4920
4921
4922
4923
4924



4925
4926
4927
4928



4929
4930
4931
4932
4933
4934
4935

4936
4937
4938
4939
4940
4941
4942

4943
4944

4945
4946
4947
4948
4949
4950
4951

4952
4953
4954
4955


4956
4957
4958

4959
4960

4961
4962
4963
4964
4965



4966
4967
4968
4969


4970
4971
4972
4973

4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986

4987
4988
4989
4990
4991
4992
4993


4994
4995

4996
4997
4998
4999
5000
5001
5002
5003

5004
5005
5006

5007
5008
5009
5010
5011
5012
5013
5014

5015
5016
5017

5018
5019
5020
5021
5022
5023


5024
5025
5026
5027
5028


5029
5030
5031
5032

5033
5034
5035
5036
5037
5038
5039
5040
5041



5042
5043
5044
5045



5046
5047
5048
5049
5050
5051
5052

5053
5054
5055
5056
5057
5058
5059

5060
5061

5062
5063
5064
5065
5066
5067
5068

5069
5070
5071
5072


5073
5074
5075

5076
5077

5078
5079
5080
5081
5082



5083
5084
5085
5086


5087
5088
5089
5090

5091
5092
5093
5094
5095
5096
5097
5098
4852
4853
4854
4855
4856
4857
4858


4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871



4872
4873
4874




4875
4876
4877
4878
4879
4880
4881
4882
4883
4884

4885
4886
4887
4888
4889
4890
4891

4892

4893


4894
4895

4896


4897
4898

4899


4900
4901
4902
4903
4904
4905
4906
4907
4908
4909

4910
4911

4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932

4933
4934
4935



4936
4937
4938




4939
4940
4941
4942
4943
4944
4945
4946
4947

4948



4949
4950
4951

4952
4953

4954
4955
4956
4957
4958
4959
4960

4961

4962


4963
4964

4965

4966
4967

4968

4969



4970
4971
4972

4973
4974
4975
4976
4977
4978
4979

4980
4981
4982

4983
4984
4985
4986

4987

4988
4989
4990


4991
4992
4993

4994

4995



4996
4997
4998




4999
5000
5001
5002
5003
5004
5005
5006
5007

5008



5009
5010
5011

5012
5013

5014
5015
5016
5017
5018
5019
5020

5021

5022


5023
5024

5025

5026
5027

5028

5029



5030
5031
5032

5033


5034
5035

5036
5037

5038

5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049

5050

5051
5052
5053
5054


5055
5056
5057

5058

5059
5060
5061
5062
5063
5064

5065

5066

5067

5068
5069
5070
5071
5072
5073

5074

5075

5076
5077
5078
5079
5080


5081
5082
5083
5084
5085


5086
5087
5088
5089
5090

5091

5092
5093
5094
5095
5096



5097
5098
5099




5100
5101
5102
5103
5104
5105
5106
5107
5108

5109



5110
5111
5112

5113
5114

5115
5116
5117
5118
5119
5120
5121

5122

5123


5124
5125

5126

5127
5128

5129

5130



5131
5132
5133

5134


5135
5136

5137
5138

5139

5140
5141
5142
5143
5144
5145
5146







-
-
+
+








+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+



+
+
+


-
+

-
+




















-
+


-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-







-
+


-
+



-
+
-



-
-
+
+

-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-

-
-
+
+
-


-
+
-











-
+
-




-
-
+
+

-
+
-






-
+
-

-
+
-






-
+
-

-
+




-
-
+
+



-
-
+
+



-
+
-





-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-

-
-
+
+
-


-
+
-







	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	CYGWIN_*|MINGW32_*|MSYS_*)
	    SHLIB_CFLAGS="-fno-common"
	CYGWIN_*|MINGW32*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD='${CC} -shared'
	    SHLIB_SUFFIX=".dll"
	    DL_OBJS="tclLoadDl.o"
	    PLAT_OBJS='${CYGWIN_OBJS}'
	    PLAT_SRCS='${CYGWIN_SRCS}'
	    DL_LIBS="-ldl"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    TCL_NEEDS_EXP_FILE=1
	    TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.dll.a'
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\[email protected]"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Cygwin version of gcc" >&5
printf %s "checking for Cygwin version of gcc... " >&6; }
if test ${ac_cv_cygwin+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Cygwin version of gcc" >&5
$as_echo_n "checking for Cygwin version of gcc... " >&6; }
if ${ac_cv_cygwin+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		#ifdef __CYGWIN__
		    #error cygwin
		#endif

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_cygwin=no
else case e in #(
  e) ac_cv_cygwin=yes ;;
else
  ac_cv_cygwin=yes
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	     ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cygwin" >&5
printf "%s\n" "$ac_cv_cygwin" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cygwin" >&5
$as_echo "$ac_cv_cygwin" >&6; }
	    if test "$ac_cv_cygwin" = "no"; then
		as_fn_error $? "${CC} is not a cygwin compiler." "$LINENO" 5
	    fi
	    if test "x${TCL_THREADS}" = "x0"; then
		as_fn_error $? "CYGWIN compile is only supported with --enable-threads" "$LINENO" 5
	    fi
	    do64bit_ok=yes
	    if test "x${SHARED_BUILD}" = "x1"; then
		echo "running cd ../win; ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args --enable-64bit --host=x86_64-w64-mingw32"
		echo "running cd ../win; ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args"
		# The eval makes quoting arguments work.
		if cd ../win; eval ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args --enable-64bit --host=x86_64-w64-mingw32; cd ../unix
		if cd ../win; eval ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args; cd ../unix
		then :
		else
		    { echo "configure: error: configure failed for ../win" 1>&2; exit 1; }
		fi
	    fi
	    ;;
	dgux*)
	    SHLIB_CFLAGS="-K PIC"
	    SHLIB_LD='${CC} -G'
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	Haiku*)
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-lroot"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5
printf %s "checking for inet_ntoa in -lnetwork... " >&6; }
if test ${ac_cv_lib_network_inet_ntoa+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5
$as_echo_n "checking for inet_ntoa in -lnetwork... " >&6; }
if ${ac_cv_lib_network_inet_ntoa+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lnetwork  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char inet_ntoa (void);
char inet_ntoa ();
int
main (void)
main ()
{
return inet_ntoa ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_network_inet_ntoa=yes
else case e in #(
  e) ac_cv_lib_network_inet_ntoa=no ;;
else
  ac_cv_lib_network_inet_ntoa=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_inet_ntoa" >&5
printf "%s\n" "$ac_cv_lib_network_inet_ntoa" >&6; }
if test "x$ac_cv_lib_network_inet_ntoa" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_inet_ntoa" >&5
$as_echo "$ac_cv_lib_network_inet_ntoa" >&6; }
if test "x$ac_cv_lib_network_inet_ntoa" = xyes; then :
then :
  LIBS="$LIBS -lnetwork"
fi

	    ;;
	HP-UX-*.11.*)
	    # Use updated header definitions where possible

printf "%s\n" "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h
$as_echo "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h


printf "%s\n" "#define _XOPEN_SOURCE 1" >>confdefs.h
$as_echo "#define _XOPEN_SOURCE 1" >>confdefs.h

	    LIBS="$LIBS -lxnet"               # Use the XOPEN network library

	    if test "`uname -m`" = ia64
	    if test "`uname -m`" = ia64; then :
then :

		SHLIB_SUFFIX=".so"

else case e in #(
  e)
else

		SHLIB_SUFFIX=".sl"
	     ;;

esac
fi
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
printf %s "checking for shl_load in -ldld... " >&6; }
if test ${ac_cv_lib_dld_shl_load+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
$as_echo_n "checking for shl_load in -ldld... " >&6; }
if ${ac_cv_lib_dld_shl_load+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-ldld  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char shl_load (void);
char shl_load ();
int
main (void)
main ()
{
return shl_load ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_dld_shl_load=yes
else case e in #(
  e) ac_cv_lib_dld_shl_load=no ;;
else
  ac_cv_lib_dld_shl_load=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
then :
  tcl_ok=yes
else case e in #(
  e) tcl_ok=no ;;
else
  tcl_ok=no
esac
fi

	    if test "$tcl_ok" = yes
	    if test "$tcl_ok" = yes; then :
then :

		SHLIB_CFLAGS="+z"
		SHLIB_LD="ld -b"
		DL_OBJS="tclLoadShl.o"
		DL_LIBS="-ldld"
		LDFLAGS="$LDFLAGS -Wl,-E"
		CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.'
		LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.'
		LD_LIBRARY_PATH_VAR="SHLIB_PATH"

fi
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :

		SHLIB_LD='${CC} -shared'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

else case e in #(
  e)
else

		CFLAGS="$CFLAGS -z"
	     ;;

esac
fi

	    # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc
	    #CFLAGS="$CFLAGS +DAportable"

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = "yes"
	    if test "$do64bit" = "yes"; then :
then :

		if test "$GCC" = yes
		if test "$GCC" = yes; then :
then :

		    case `${CC} -dumpmachine` in
			hppa64*)
			    # 64-bit gcc in use.  Fix flags for GNU ld.
			    do64bit_ok=yes
			    SHLIB_LD='${CC} -shared'
			    if test $doRpath = yes
			    if test $doRpath = yes; then :
then :

				CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
				CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
			    ;;
			*)
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
			    ;;
		    esac

else case e in #(
  e)
else

		    do64bit_ok=yes
		    CFLAGS="$CFLAGS +DD64"
		    LDFLAGS_ARCH="+DD64"
		 ;;

esac
fi

fi ;;
	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
	    SHLIB_SUFFIX=".sl"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
printf %s "checking for shl_load in -ldld... " >&6; }
if test ${ac_cv_lib_dld_shl_load+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
$as_echo_n "checking for shl_load in -ldld... " >&6; }
if ${ac_cv_lib_dld_shl_load+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-ldld  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char shl_load (void);
char shl_load ();
int
main (void)
main ()
{
return shl_load ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_dld_shl_load=yes
else case e in #(
  e) ac_cv_lib_dld_shl_load=no ;;
else
  ac_cv_lib_dld_shl_load=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
then :
  tcl_ok=yes
else case e in #(
  e) tcl_ok=no ;;
else
  tcl_ok=no
esac
fi

	    if test "$tcl_ok" = yes
	    if test "$tcl_ok" = yes; then :
then :

		SHLIB_CFLAGS="+z"
		SHLIB_LD="ld -b"
		SHLIB_LD_LIBS=""
		DL_OBJS="tclLoadShl.o"
		DL_LIBS="-ldld"
		LDFLAGS="$LDFLAGS -Wl,-E"
5109
5110
5111
5112
5113
5114
5115
5116

5117
5118
5119

5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135

5136
5137
5138

5139
5140
5141

5142
5143
5144
5145
5146
5147
5148


5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159

5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175

5176
5177
5178

5179
5180
5181
5182
5183
5184

5185
5186
5187

5188
5189
5190
5191


5192
5193
5194


5195
5196
5197
5198
5199

5200
5201
5202
5203
5204
5205
5206


5207
5208
5209
5210
5211
5212
5213
5214
5215

5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229

5230
5231
5232

5233
5234
5235

5236
5237
5238
5239

5240
5241
5242
5243
5244



5245
5246
5247
5248



5249
5250
5251
5252
5253
5254
5255

5256
5257
5258
5259
5260
5261
5262

5263
5264
5265
5266


5267
5268
5269

5270
5271

5272
5273
5274
5275
5276



5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287

5288
5289
5290
5291
5292

5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305

5306
5307
5308
5309


5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322

5323
5324
5325
5326

5327
5328
5329

5330
5331
5332
5333
5334


5335
5336
5337
5338






5339
5340
5341
5342
5343
5344
5345
5346

5347
5348
5349
5350
5351

5352
5353
5354

5355
5356


5357
5358
5359
5360






5361































5362
5363

5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374

5375
5376
5377
5378
5379
5380
5381



5382
5383
5384
5385



5386
5387
5388
5389
5390
5391
5392

5393
5394
5395
5396
5397
5398
5399

5400
5401
5402
5403


5404
5405
5406

5407
5408

5409
5410
5411
5412
5413



5414
5415
5416
5417
5418
5419
5420
5421
5422
5423




5424
5425
5426
5427



5428
5429
5430
5431
5432
5433
5434

5435
5436
5437
5438
5439
5440
5441

5442
5443
5444
5445


5446
5447
5448

5449
5450

5451
5452
5453
5454
5455



5456
5457
5458
5459
5460
5461
5462
5463


5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474

5475
5476
5477
5478
5479
5480
5481




5482
5483
5484
5485


5486
5487
5488
5489
5490
5491
5492

5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518

5519
5520
5521
5522
5523
5524



5525
5526
5527
5528



5529
5530
5531
5532
5533
5534
5535

5536
5537
5538
5539
5540
5541
5542

5543
5544
5545
5546


5547
5548
5549

5550
5551

5552
5553
5554
5555
5556



5557
5558
5559
5560
5561
5562
5563
5564






5565
5566
5567
5568



5569
5570
5571
5572



5573
5574
5575
5576
5577
5578
5579

5580
5581
5582
5583
5584
5585
5586

5587
5588
5589
5590


5591
5592
5593

5594
5595

5596
5597
5598
5599
5600



5601
5602
5603
5604
5605
5606

5607
5608
5609
5610

5611
5612
5613
5614
5615
5616
5617

5618
5619

5620
5621
5622
5623
5624


5625
5626

5627
5628
5629
5630


5631
5632
5633
5634
5635
5636



5637
5638
5639
5640
5641



5642
5643
5644
5645



5646
5647

5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663

5664
5665
5666
5667
5668
5669
5670

5671
5672
5673
5674


5675
5676
5677

5678
5679

5680
5681
5682
5683
5684
5685
5686

5687
5688
5689
5690
5691



5692
5693
5694
5695
5696

5697
5698
5699
5700


5701
5702
5703

5704
5705
5706
5707
5708



5709
5710
5711
5712



5713
5714
5715
5716
5717
5718
5719
5720

5721
5722
5723
5724
5725
5726
5727

5728
5729
5730
5731


5732
5733
5734

5735
5736
5737
5738

5739
5740
5741
5742
5743



5744
5745
5746
5747

5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761

5762
5763
5764
5765
5766
5767

5768
5769
5770

5771
5772
5773
5774
5775




5776
5777
5778
5779
5780
5781

5782
5783
5784

5785
5786
5787

5788
5789
5790
5791
5792



5793
5794
5795


5796
5797
5798
5799




5800
5801
5802

5803
5804
5805
5806
5807
5808
5809







5810
5811
5812
5813
5814

5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828

5829
5830
5831
5832


5833
5834
5835
5836
5837
5838





5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856

5857
5858
5859

5860
5861
5862
5863
5864
5865
5866

5867
5868
5869
5870
5871
5872
5873
5874


5875
5876
5877
5878

5879
5880
5881
5882
5883
5884
5885
5886
5887

5888
5889
5890

5891
5892
5893
5894
5895
5896

5897
5898
5899
5900

5901
5902
5903

5904
5905
5906

5907
5908
5909
5910


5911
5912
5913


5914
5915
5916
5917
5918

5919
5920
5921
5922
5923


5924
5925

5926
5927
5928
5929
5930
5931
5932


5933
5934
5935

5936
5937
5938
5939
5940

5941
5942
5943
5944
5945


5946
5947
5948

5949
5950
5951
5952
5953
5954
5955
5956
5957
5958


5959
5960
5961
5962


5963
5964
5965
5966
5967
5968
5969
5970
5971
5972

5973
5974
5975
5976
5977
5978



5979
5980

5981
5982
5983
5984
5985
5986
5987
5988
5989
5990

5991
5992
5993
5994


5995
5996
5997
5998



5999
6000
6001
6002


6003
6004
6005


6006
6007
6008

6009
6010
6011
6012
6013
6014
6015




6016
6017

6018
6019
6020

6021
6022
6023
6024
6025
6026

6027
6028
6029
6030
6031
6032

6033
6034
6035

6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047


6048
6049
6050
6051
6052

6053
6054
6055
6056
6057
6058
6059
6060



6061
6062
6063
6064


6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075

6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090



6091
6092
6093
6094



6095
6096
6097
6098
6099
6100
6101

6102
6103
6104
6105
6106
6107
6108

6109
6110
6111
6112


6113
6114
6115

6116
6117

6118
6119
6120
6121
6122



6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133

6134
6135
6136
6137


6138
6139
6140
6141

6142
6143
6144
6145

6146
6147
6148
6149
6150
6151
6152
6153
6154
6155

6156
6157
6158
6159


6160
6161
6162
6163

6164
6165
6166
6167
6168

6169
6170
6171
6172
6173
6174




6175
6176
6177
6178
6179
6180
6181
6182
6183
6184

6185
6186
6187
6188
6189
6190
6191
6192
6193

6194
6195
6196
6197
6198
6199

6200
6201
6202
6203
6204
6205


6206
6207
6208
6209
6210
6211

6212
6213
6214
6215

6216
6217
6218
6219
6220

6221
6222
6223
6224
6225

6226
6227
6228
6229
6230
6231
6232

6233
6234
6235
6236
6237


6238
6239
6240

6241
6242
6243
6244


6245
6246

6247
6248
6249
6250
6251


6252
6253
6254

6255
6256
6257
6258
6259
6260


6261
6262

6263
6264
6265
6266

6267
6268
6269
6270
6271

6272
6273
6274
6275
6276
6277


6278
6279

6280
6281
6282
6283
6284
6285
6286
6287

6288
6289
6290
6291
6292
6293
6294
6295
6296



6297
6298
6299
6300



6301
6302
6303
6304



6305
6306
6307
6308

6309
6310
6311
6312


6313
6314
6315
6316
6317
6318

6319
6320
6321
6322


6323
6324
6325

6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403

6404
6405
6406
6407
6408

6409
6410
6411
6412

6413
6414
6415
6416

6417
6418
6419
6420
6421
6422
6423
6424

6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
5157
5158
5159
5160
5161
5162
5163

5164

5165

5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181

5182

5183

5184
5185
5186

5187

5188
5189
5190
5191


5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203

5204

5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218

5219

5220

5221
5222
5223
5224
5225
5226

5227

5228

5229

5230


5231
5232
5233


5234
5235
5236
5237
5238
5239

5240

5241
5242
5243
5244


5245
5246
5247
5248
5249
5250
5251
5252
5253
5254

5255
5256
5257
5258











5259

5260

5261
5262
5263

5264

5265
5266

5267

5268



5269
5270
5271




5272
5273
5274
5275
5276
5277
5278
5279
5280

5281
5282
5283
5284
5285
5286
5287

5288

5289


5290
5291

5292

5293
5294

5295

5296



5297
5298
5299

5300
5301
5302
5303
5304
5305
5306
5307
5308

5309
5310
5311
5312
5313

5314

5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325

5326

5327


5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341

5342
5343
5344
5345

5346

5347

5348
5349
5350
5351
5352
5353
5354
5355




5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368

5369
5370
5371
5372
5373

5374

5375

5376
5377
5378
5379
5380




5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419

5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430

5431

5432
5433
5434



5435
5436
5437




5438
5439
5440
5441
5442
5443
5444
5445
5446

5447
5448
5449
5450
5451
5452
5453

5454

5455


5456
5457

5458

5459
5460

5461

5462



5463
5464
5465

5466
5467
5468
5469
5470




5471
5472
5473
5474




5475
5476
5477
5478
5479
5480
5481
5482
5483

5484
5485
5486
5487
5488
5489
5490

5491

5492


5493
5494

5495

5496
5497

5498

5499



5500
5501
5502

5503
5504
5505
5506
5507


5508
5509











5510







5511
5512
5513
5514




5515
5516







5517






5518
















5519
5520

5521

5522
5523



5524
5525
5526




5527
5528
5529
5530
5531
5532
5533
5534
5535

5536
5537
5538
5539
5540
5541
5542

5543

5544


5545
5546

5547

5548
5549

5550

5551



5552
5553
5554

5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568



5569
5570
5571




5572
5573
5574
5575
5576
5577
5578
5579
5580

5581
5582
5583
5584
5585
5586
5587

5588

5589


5590
5591

5592

5593
5594

5595

5596



5597
5598
5599

5600
5601
5602
5603

5604

5605
5606

5607
5608

5609
5610
5611
5612

5613
5614

5615
5616
5617
5618


5619
5620
5621

5622

5623


5624
5625

5626
5627



5628
5629
5630

5631



5632
5633
5634




5635
5636
5637
5638

5639

5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653

5654
5655
5656
5657
5658
5659
5660

5661

5662


5663
5664

5665

5666
5667

5668

5669
5670
5671
5672
5673

5674

5675



5676
5677
5678

5679
5680
5681

5682
5683
5684


5685
5686

5687

5688

5689



5690
5691
5692




5693
5694
5695
5696
5697
5698
5699
5700
5701
5702

5703
5704
5705
5706
5707
5708
5709

5710

5711


5712
5713

5714

5715
5716
5717
5718

5719

5720



5721
5722
5723

5724
5725

5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739

5740
5741
5742
5743
5744
5745

5746

5747

5748
5749




5750
5751
5752
5753

5754
5755
5756
5757

5758

5759

5760
5761
5762

5763

5764



5765
5766
5767

5768
5769
5770
5771




5772
5773
5774
5775

5776

5777
5778






5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804

5805

5806


5807
5808
5809





5810
5811
5812
5813
5814

5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830

5831
5832
5833

5834
5835
5836
5837
5838
5839
5840

5841

5842
5843
5844
5845
5846


5847
5848
5849
5850
5851

5852

5853
5854
5855
5856
5857
5858
5859

5860
5861
5862

5863
5864
5865
5866
5867
5868

5869

5870
5871

5872

5873

5874

5875

5876

5877


5878
5879
5880


5881
5882
5883
5884
5885
5886

5887

5888
5889


5890
5891
5892

5893

5894
5895
5896
5897


5898
5899
5900
5901

5902

5903
5904
5905

5906

5907
5908


5909
5910

5911

5912

5913
5914
5915
5916
5917
5918
5919


5920
5921
5922
5923


5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934

5935

5936
5937



5938
5939
5940


5941

5942
5943
5944
5945
5946
5947
5948
5949

5950

5951


5952
5953
5954



5955
5956
5957

5958


5959
5960
5961


5962
5963

5964
5965
5966
5967
5968
5969




5970
5971
5972
5973
5974

5975

5976

5977

5978
5979
5980
5981

5982

5983
5984
5985
5986

5987

5988

5989

5990
5991
5992
5993
5994
5995
5996
5997
5998


5999
6000

6001
6002
6003

6004

6005
6006
6007
6008



6009
6010
6011

6012


6013
6014

6015
6016
6017
6018
6019
6020
6021
6022
6023

6024

6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035



6036
6037
6038




6039
6040
6041
6042
6043
6044
6045
6046
6047

6048
6049
6050
6051
6052
6053
6054

6055

6056


6057
6058

6059

6060
6061

6062

6063



6064
6065
6066

6067
6068
6069
6070
6071
6072
6073
6074
6075

6076

6077


6078
6079
6080
6081
6082

6083

6084
6085

6086
6087
6088
6089
6090
6091
6092
6093
6094
6095

6096

6097


6098
6099

6100
6101

6102

6103
6104
6105

6106

6107




6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120

6121

6122
6123
6124
6125
6126
6127
6128

6129

6130
6131
6132
6133

6134


6135



6136
6137
6138
6139
6140
6141
6142

6143

6144
6145

6146
6147
6148
6149
6150

6151

6152
6153
6154

6155

6156
6157
6158
6159
6160

6161

6162
6163


6164
6165

6166

6167
6168
6169


6170
6171
6172

6173

6174
6175


6176
6177
6178
6179

6180

6181
6182
6183


6184
6185
6186

6187

6188
6189

6190

6191
6192
6193

6194

6195
6196
6197


6198
6199
6200

6201

6202
6203
6204
6205
6206
6207

6208

6209
6210
6211
6212
6213



6214
6215
6216
6217



6218
6219
6220




6221
6222
6223
6224
6225
6226

6227
6228
6229


6230
6231
6232
6233
6234
6235
6236

6237

6238


6239
6240

6241

6242

























































6243














6244





6245





6246




6247

6248


6249
6250







6251



















6252
6253
6254
6255
6256
6257
6258







-
+
-

-
+















-
+
-

-
+


-
+
-




-
-
+
+










-
+
-














-
+
-

-
+





-
+
-

-
+
-

-
-
+
+

-
-
+
+




-
+
-




-
-
+
+








-
+



-
-
-
-
-
-
-
-
-
-
-
+
-

-
+


-
+
-


-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-









-
+




-
+
-











-
+
-

-
-
+
+












-
+



-
+
-

-
+





+
+
-
-
-
-
+
+
+
+
+
+







-
+




-
+
-

-
+


+
+
-
-
-
-
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+










-
+
-



-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-





-
-
-
-
+
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-





-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+
-


-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-







+
+
+
+
+
+

-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-




-
+
-


-
+

-




-
+

-
+



-
-
+
+

-
+
-

-
-
+
+
-


-
-
-
+
+
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+

-
+
-














-
+






-
+
-

-
-
+
+
-

-
+

-
+
-





-
+
-

-
-
-
+
+
+
-



-
+


-
-
+
+
-

-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+
-

-
+



-
+
-

-
-
-
+
+
+
-


-
+













-
+





-
+
-

-
+

-
-
-
-
+
+
+
+
-




-
+
-

-
+


-
+
-

-
-
-
+
+
+
-


+
+
-
-
-
-
+
+
+
+
-

-
+

-
-
-
-
-
-
+
+
+
+
+
+
+





+













-
+
-

-
-
+
+

-
-
-
-
-
+
+
+
+
+
-
















-
+


-
+






-
+
-





-
-
+
+



-
+
-







-
+


-
+





-
+
-


-
+
-

-
+
-

-
+
-

-
-
+
+

-
-
+
+




-
+
-


-
-
+
+

-
+
-




-
-
+
+


-
+
-



-
+
-


-
-
+
+
-

-
+
-







-
-
+
+


-
-
+
+









-
+
-


-
-
-
+
+
+
-
-
+
-








-
+
-

-
-
+
+

-
-
-
+
+
+
-

-
-
+
+

-
-
+
+
-


+



-
-
-
-
+
+
+
+

-
+
-

-
+
-




-
+
-




-
+
-

-
+
-









-
-
+
+
-



-
+
-




-
-
-
+
+
+
-

-
-
+
+
-









-
+
-











-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-









-
+
-

-
-
+
+



-
+
-


-
+









-
+
-

-
-
+
+
-


-
+
-



-
+
-

-
-
-
-
+
+
+
+









-
+
-







-
+
-




-
+
-
-

-
-
-
+
+





-
+
-


-
+




-
+
-



-
+
-





-
+
-


-
-
+
+
-

-
+


-
-
+
+

-
+
-


-
-
+
+


-
+
-



-
-
+
+

-
+
-


-
+
-



-
+
-



-
-
+
+

-
+
-






-
+
-





-
-
-
+
+
+

-
-
-
+
+
+
-
-
-
-
+
+
+



-
+


-
-
+
+





-
+
-

-
-
+
+
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-

-
-
+

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    DL_LIBS=""
	    case " $LIBOBJS " in
  *" mkstemp.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext"
 ;;
esac

	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'
fi
	    ;;
	IRIX-6.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    case " $LIBOBJS " in
  *" mkstemp.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext"
 ;;
esac

	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'
fi
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :

		CFLAGS="$CFLAGS -mabi=n32"
		LDFLAGS="$LDFLAGS -mabi=n32"

else case e in #(
  e)
else

		case $system in
		    IRIX-6.3)
			# Use to build 6.2 compatible binaries on 6.3.
			CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS"
			;;
		    *)
			CFLAGS="$CFLAGS -n32"
			;;
		esac
		LDFLAGS="$LDFLAGS -n32"
	     ;;

esac
fi
	    ;;
	IRIX64-6.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    case " $LIBOBJS " in
  *" mkstemp.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext"
 ;;
esac

	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'
fi

	    # Check to enable 64-bit flags for compiler/linker

	    if test "$do64bit" = yes
	    if test "$do64bit" = yes; then :
then :

	        if test "$GCC" = yes
	        if test "$GCC" = yes; then :
then :

	            { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported by gcc" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported by gcc" >&2;}
	            { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported by gcc" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported by gcc" >&2;}

else case e in #(
  e)
else

	            do64bit_ok=yes
	            SHLIB_LD="ld -64 -shared -rdata_shared"
	            CFLAGS="$CFLAGS -64"
	            LDFLAGS_ARCH="-64"
	         ;;

esac
fi

fi
	    ;;
	Linux*|GNU*|NetBSD-Debian|DragonFly-*|FreeBSD-*)
	    SHLIB_CFLAGS="-fPIC -fno-common"
	Linux*|GNU*|NetBSD-Debian)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"

	    CFLAGS_OPTIMIZE="-O2"
	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
	    # when you inline the string and math operations.  Turn this off to
	    # get rid of the warnings.
	    #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"

	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"

	    case $system in
	    DragonFly-*|FreeBSD-*)
		# The -pthread needs to go in the LDFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
	    ;;
	    esac

	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    if test "`uname -m`" = "alpha"
	    if test "`uname -m`" = "alpha"; then :
then :
  CFLAGS="$CFLAGS -mieee"
fi
	    if test $do64bit = yes
	    if test $do64bit = yes; then :
then :

		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -m64 flag" >&5
printf %s "checking if compiler accepts -m64 flag... " >&6; }
if test ${tcl_cv_cc_m64+y}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -m64 flag" >&5
$as_echo_n "checking if compiler accepts -m64 flag... " >&6; }
if ${tcl_cv_cc_m64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

		    hold_cflags=$CFLAGS
		    CFLAGS="$CFLAGS -m64"
		    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_cc_m64=yes
else case e in #(
  e) tcl_cv_cc_m64=no ;;
else
  tcl_cv_cc_m64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		    CFLAGS=$hold_cflags ;;
		    CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_m64" >&5
printf "%s\n" "$tcl_cv_cc_m64" >&6; }
		if test $tcl_cv_cc_m64 = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_m64" >&5
$as_echo "$tcl_cv_cc_m64" >&6; }
		if test $tcl_cv_cc_m64 = yes; then :
then :

		    CFLAGS="$CFLAGS -m64"
		    do64bit_ok=yes

fi

fi

	    # The combo of gcc + glibc has a bug related to inlining of
	    # functions like strtol()/strtoul(). The -fno-builtin flag should address
	    # functions like strtod(). The -fno-builtin flag should address
	    # this problem but it does not work. The -fno-inline flag is kind
	    # of overkill but it works. Disable inlining only when one of the
	    # files in compat/*.c is being linked in.

	    if test x"${USE_COMPAT}" != x
	    if test x"${USE_COMPAT}" != x; then :
then :
  CFLAGS="$CFLAGS -fno-inline"
fi
	    ;;
	Lynx*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    CFLAGS_OPTIMIZE=-02
	    SHLIB_LD='${CC} -shared'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-mshared -ldl"
	    LD_FLAGS="-Wl,--export-dynamic"
	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
	    ;;
	OpenBSD-*)
	    arch=`arch -s`
	    case "$arch" in
	    alpha|sparc64)
		SHLIB_CFLAGS="-fPIC"
		;;
	    *)
		SHLIB_CFLAGS="-fpic"
		;;
	    esac
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.${SHLIB_VERSION}'
	    LDFLAGS="-Wl,-export-dynamic"
	    CFLAGS_OPTIMIZE="-O2"
	    if test "${TCL_THREADS}" = "1"; then :

	    # On OpenBSD:	Compile with -pthread
	    #		Don't link with -lpthread
	    LIBS=`echo $LIBS | sed s/-lpthread//`
	    CFLAGS="$CFLAGS -pthread"
		# On OpenBSD:	Compile with -pthread
		#		Don't link with -lpthread
		LIBS=`echo $LIBS | sed s/-lpthread//`
		CFLAGS="$CFLAGS -pthread"

fi
	    # OpenBSD doesn't do version numbers with dots.
	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
	    TCL_LIB_VERSIONS_OK=nodots
	    ;;
	NetBSD-*)
	    # NetBSD has ELF and can use 'cc -shared' to build shared libs
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    if test "${TCL_THREADS}" = "1"; then :

	    # The -pthread needs to go in the CFLAGS, not LIBS
	    LIBS=`echo $LIBS | sed s/-pthread//`
	    CFLAGS="$CFLAGS -pthread"
	    LDFLAGS="$LDFLAGS -pthread"
		# The -pthread needs to go in the CFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS -pthread"
	    	LDFLAGS="$LDFLAGS -pthread"

fi
	    ;;
	FreeBSD-*)
	    # This configuration from FreeBSD Ports.
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD="${CC} -shared"
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,-soname,\$@"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    LDFLAGS=""
	    if test $doRpath = yes; then :

		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
fi
	    if test "${TCL_THREADS}" = "1"; then :

		# The -pthread needs to go in the LDFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
fi
	    case $system in
	    FreeBSD-3.*)
		# Version numbers are dot-stripped by system policy.
		TCL_TRIM_DOTS=`echo ${VERSION} | tr -d .`
		UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
		TCL_LIB_VERSIONS_OK=nodots
		;;
	    esac
	    ;;
	Darwin-*)
	    CFLAGS_OPTIMIZE="-O2"
	    CFLAGS_OPTIMIZE="-Os"
	    SHLIB_CFLAGS="-fno-common"
	    # To avoid discrepancies between what headers configure sees during
	    # preprocessing tests and compiling tests, move any -isysroot and
	    # -mmacosx-version-min flags from CFLAGS to CPPFLAGS:
	    CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if ($i~/^(isysroot|mmacosx-version-min)/) print "-"$i}'`"
	    CFLAGS="`echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if (!($i~/^(isysroot|mmacosx-version-min)/)) print "-"$i}'`"
	    if test $do64bit = yes
	    if test $do64bit = yes; then :
then :

		case `arch` in
		    ppc)
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch ppc64 flag" >&5
printf %s "checking if compiler accepts -arch ppc64 flag... " >&6; }
if test ${tcl_cv_cc_arch_ppc64+y}
			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch ppc64 flag" >&5
$as_echo_n "checking if compiler accepts -arch ppc64 flag... " >&6; }
if ${tcl_cv_cc_arch_ppc64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_cc_arch_ppc64=yes
else case e in #(
  e) tcl_cv_cc_arch_ppc64=no ;;
else
  tcl_cv_cc_arch_ppc64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
			    CFLAGS=$hold_cflags ;;
			    CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_ppc64" >&5
printf "%s\n" "$tcl_cv_cc_arch_ppc64" >&6; }
			if test $tcl_cv_cc_arch_ppc64 = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_ppc64" >&5
$as_echo "$tcl_cv_cc_arch_ppc64" >&6; }
			if test $tcl_cv_cc_arch_ppc64 = yes; then :
then :

			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    do64bit_ok=yes

fi;;
		    i386|x86_64)
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch x86_64 flag" >&5
printf %s "checking if compiler accepts -arch x86_64 flag... " >&6; }
if test ${tcl_cv_cc_arch_x86_64+y}
		    i386)
			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch x86_64 flag" >&5
$as_echo_n "checking if compiler accepts -arch x86_64 flag... " >&6; }
if ${tcl_cv_cc_arch_x86_64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch x86_64"
			    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_cc_arch_x86_64=yes
else case e in #(
  e) tcl_cv_cc_arch_x86_64=no ;;
else
  tcl_cv_cc_arch_x86_64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
			    CFLAGS=$hold_cflags ;;
			    CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_x86_64" >&5
printf "%s\n" "$tcl_cv_cc_arch_x86_64" >&6; }
			if test $tcl_cv_cc_arch_x86_64 = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_x86_64" >&5
$as_echo "$tcl_cv_cc_arch_x86_64" >&6; }
			if test $tcl_cv_cc_arch_x86_64 = yes; then :
then :

			    CFLAGS="$CFLAGS -arch x86_64"
			    do64bit_ok=yes

fi;;
		    arm64)
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch arm64 flag" >&5
		    *)
			{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&5
printf %s "checking if compiler accepts -arch arm64 flag... " >&6; }
if test ${tcl_cv_cc_arch_arm64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch arm64"
			    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

$as_echo "$as_me: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&2;};;
int
main (void)
{

  ;
  return 0;
}
		esac

else

_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_cc_arch_arm64=yes
		# Check for combined 32-bit and 64-bit fat build
		if echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \
else case e in #(
  e) tcl_cv_cc_arch_arm64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
			    CFLAGS=$hold_cflags ;;
		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '; then :
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_arm64" >&5
printf "%s\n" "$tcl_cv_cc_arch_arm64" >&6; }
			if test $tcl_cv_cc_arch_arm64 = yes
then :

			    CFLAGS="$CFLAGS -arch arm64"
			    do64bit_ok=yes

fi;;
		    *)
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&5
printf "%s\n" "$as_me: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&2;};;
		esac

else case e in #(
  e)
		# Check for combined 32-bit and 64-bit fat build
		if echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64|arm64) ' \
		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '
then :

		    fat_32_64=yes
fi
	     ;;

esac
fi
	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS}'
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ld accepts -single_module flag" >&5
printf %s "checking if ld accepts -single_module flag... " >&6; }
if test ${tcl_cv_ld_single_module+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -single_module flag" >&5
$as_echo_n "checking if ld accepts -single_module flag... " >&6; }
if ${tcl_cv_ld_single_module+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_ld_single_module=yes
else case e in #(
  e) tcl_cv_ld_single_module=no ;;
else
  tcl_cv_ld_single_module=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		LDFLAGS=$hold_ldflags ;;
		LDFLAGS=$hold_ldflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_single_module" >&5
printf "%s\n" "$tcl_cv_ld_single_module" >&6; }
	    if test $tcl_cv_ld_single_module = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_single_module" >&5
$as_echo "$tcl_cv_ld_single_module" >&6; }
	    if test $tcl_cv_ld_single_module = yes; then :
then :

		SHLIB_LD="${SHLIB_LD} -Wl,-single_module"

fi
	    SHLIB_SUFFIX=".dylib"
	    DL_OBJS="tclLoadDyld.o"
	    DL_LIBS=""
	    # Don't use -prebind when building for Mac OS X 10.4 or later only:
	    if test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int($2)}'`" -lt 4 -a \
		"`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int($2)}'`" -lt 4; then :

		LDFLAGS="$LDFLAGS -prebind"
fi
	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5
printf %s "checking if ld accepts -search_paths_first flag... " >&6; }
if test ${tcl_cv_ld_search_paths_first+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5
$as_echo_n "checking if ld accepts -search_paths_first flag... " >&6; }
if ${tcl_cv_ld_search_paths_first+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_ld_search_paths_first=yes
else case e in #(
  e) tcl_cv_ld_search_paths_first=no ;;
else
  tcl_cv_ld_search_paths_first=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		LDFLAGS=$hold_ldflags ;;
		LDFLAGS=$hold_ldflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_search_paths_first" >&5
printf "%s\n" "$tcl_cv_ld_search_paths_first" >&6; }
	    if test $tcl_cv_ld_search_paths_first = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_search_paths_first" >&5
$as_echo "$tcl_cv_ld_search_paths_first" >&6; }
	    if test $tcl_cv_ld_search_paths_first = yes; then :
then :

		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"

fi
	    if test "$tcl_cv_cc_visibility_hidden" != yes
	    if test "$tcl_cv_cc_visibility_hidden" != yes; then :
then :


printf "%s\n" "#define MODULE_SCOPE __private_extern__" >>confdefs.h
$as_echo "#define MODULE_SCOPE __private_extern__" >>confdefs.h

		tcl_cv_cc_visibility_hidden=yes

fi
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    LD_LIBRARY_PATH_VAR="DYLD_FALLBACK_LIBRARY_PATH"
	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"

printf "%s\n" "#define MAC_OSX_TCL 1" >>confdefs.h
$as_echo "#define MAC_OSX_TCL 1" >>confdefs.h

	    PLAT_OBJS='${MAC_OSX_OBJS}'
	    PLAT_SRCS='${MAC_OSX_SRCS}'
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use CoreFoundation" >&5
printf %s "checking whether to use CoreFoundation... " >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use CoreFoundation" >&5
$as_echo_n "checking whether to use CoreFoundation... " >&6; }
	    # Check whether --enable-corefoundation was given.
if test ${enable_corefoundation+y}
if test "${enable_corefoundation+set}" = set; then :
then :
  enableval=$enable_corefoundation; tcl_corefoundation=$enableval
else case e in #(
  e) tcl_corefoundation=yes ;;
else
  tcl_corefoundation=yes
esac
fi

	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_corefoundation" >&5
printf "%s\n" "$tcl_corefoundation" >&6; }
	    if test $tcl_corefoundation = yes
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_corefoundation" >&5
$as_echo "$tcl_corefoundation" >&6; }
	    if test $tcl_corefoundation = yes; then :
then :

		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for CoreFoundation.framework" >&5
printf %s "checking for CoreFoundation.framework... " >&6; }
if test ${tcl_cv_lib_corefoundation+y}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CoreFoundation.framework" >&5
$as_echo_n "checking for CoreFoundation.framework... " >&6; }
if ${tcl_cv_lib_corefoundation+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

		    hold_libs=$LIBS
		    if test "$fat_32_64" = yes
		    if test "$fat_32_64" = yes; then :
then :

			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    # On Tiger there is no 64-bit CF, so remove 64-bit
			    # archs from CFLAGS et al. while testing for
			    # presence of CF. 64-bit CF is disabled in
			    # tclUnixPort.h if necessary.
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
			done
fi
		    LIBS="$LIBS -framework CoreFoundation"
		    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <CoreFoundation/CoreFoundation.h>
int
main (void)
main ()
{
CFBundleRef b = CFBundleGetMainBundle();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_lib_corefoundation=yes
else case e in #(
  e) tcl_cv_lib_corefoundation=no ;;
else
  tcl_cv_lib_corefoundation=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		    if test "$fat_32_64" = yes
		    if test "$fat_32_64" = yes; then :
then :

			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
		        done
fi
		    LIBS=$hold_libs ;;
		    LIBS=$hold_libs
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_corefoundation" >&5
printf "%s\n" "$tcl_cv_lib_corefoundation" >&6; }
		if test $tcl_cv_lib_corefoundation = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_corefoundation" >&5
$as_echo "$tcl_cv_lib_corefoundation" >&6; }
		if test $tcl_cv_lib_corefoundation = yes; then :
then :

		    LIBS="$LIBS -framework CoreFoundation"

printf "%s\n" "#define HAVE_COREFOUNDATION 1" >>confdefs.h
$as_echo "#define HAVE_COREFOUNDATION 1" >>confdefs.h


else case e in #(
  e) tcl_corefoundation=no ;;
else
  tcl_corefoundation=no
esac
fi
		if test "$fat_32_64" = yes -a $tcl_corefoundation = yes
		if test "$fat_32_64" = yes -a $tcl_corefoundation = yes; then :
then :

		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit CoreFoundation" >&5
printf %s "checking for 64-bit CoreFoundation... " >&6; }
if test ${tcl_cv_lib_corefoundation_64+y}
		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit CoreFoundation" >&5
$as_echo_n "checking for 64-bit CoreFoundation... " >&6; }
if ${tcl_cv_lib_corefoundation_64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
			done
			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <CoreFoundation/CoreFoundation.h>
int
main (void)
main ()
{
CFBundleRef b = CFBundleGetMainBundle();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_lib_corefoundation_64=yes
else case e in #(
  e) tcl_cv_lib_corefoundation_64=no ;;
else
  tcl_cv_lib_corefoundation_64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
			done ;;
			done
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_corefoundation_64" >&5
printf "%s\n" "$tcl_cv_lib_corefoundation_64" >&6; }
		    if test $tcl_cv_lib_corefoundation_64 = no
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_corefoundation_64" >&5
$as_echo "$tcl_cv_lib_corefoundation_64" >&6; }
		    if test $tcl_cv_lib_corefoundation_64 = no; then :
then :


printf "%s\n" "#define NO_COREFOUNDATION_64 1" >>confdefs.h
$as_echo "#define NO_COREFOUNDATION_64 1" >>confdefs.h

                        LDFLAGS="$LDFLAGS -Wl,-no_arch_warnings"

fi

fi

fi
	    ;;
	OS/390-*)
	    SHLIB_LD_LIBS=""
	    CFLAGS_OPTIMIZE=""		# Optimizer is buggy

printf "%s\n" "#define _OE_SOCKETS 1" >>confdefs.h
$as_echo "#define _OE_SOCKETS 1" >>confdefs.h

	    ;;
	OSF1-V*)
	    # Digital OSF/1
	    SHLIB_CFLAGS=""
	    if test "$SHARED_BUILD" = 1
	    if test "$SHARED_BUILD" = 1; then :
then :

	        SHLIB_LD='${CC} -shared'
	        SHLIB_LD='ld -shared -expect_unresolved "*"'

else case e in #(
  e)
	        SHLIB_LD='${CC} -non_shared'
	     ;;
else

	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'

esac
fi
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    if test $doRpath = yes
	    if test $doRpath = yes; then :
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'
fi
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :
  CFLAGS="$CFLAGS -mieee"
else case e in #(
  e)
		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" ;;
else

		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"
esac
fi
	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
	    if test "${TCL_THREADS}" = 1; then :

	    CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
	    CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
	    LIBS=`echo $LIBS | sed s/-lpthreads//`
	    if test "$GCC" = yes
		CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
		CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
		LIBS=`echo $LIBS | sed s/-lpthreads//`
		if test "$GCC" = yes; then :
then :

		LIBS="$LIBS -lpthread -lmach -lexc"
		    LIBS="$LIBS -lpthread -lmach -lexc"

else case e in #(
  e)
		CFLAGS="$CFLAGS -pthread"
		LDFLAGS="$LDFLAGS -pthread"
	     ;;
esac
else

		    CFLAGS="$CFLAGS -pthread"
		    LDFLAGS="$LDFLAGS -pthread"

fi

fi
	    ;;
	QNX-6*)
	    # QNX RTP
	    # This may work for all QNX, but it was only reported for v6.
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD="ld -Bshareable -x"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    # dlopen is in -lc on QNX
	    DL_LIBS=""
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	SCO_SV-3.2*)
	    # Note, dlopen is available only on SCO 3.2.5 and greater. However,
	    # this test works, since "uname -s" was non-standard in 3.2.4 and
	    # below.
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :

		SHLIB_CFLAGS="-fPIC -melf"
		LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
	    	SHLIB_CFLAGS="-fPIC -melf"
	    	LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"

else case e in #(
  e)
		SHLIB_CFLAGS="-Kpic -belf"
		LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
	     ;;
else

	    	SHLIB_CFLAGS="-Kpic -belf"
	    	LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"

esac
fi
	    SHLIB_LD="ld -G"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	SunOS-5.[0-6])
	    # Careful to not let 5.10+ fall into this case

	    # Note: If _REENTRANT isn't defined, then Solaris
	    # won't define thread-safe library routines.


printf "%s\n" "#define _REENTRANT 1" >>confdefs.h
$as_echo "#define _REENTRANT 1" >>confdefs.h


printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h


	    SHLIB_CFLAGS="-KPIC"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :

		SHLIB_LD='${CC} -shared'
		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

else case e in #(
  e)
else

		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
		CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	     ;;

esac
fi
	    ;;
	SunOS-5*)
	    # Note: If _REENTRANT isn't defined, then Solaris
	    # won't define thread-safe library routines.


printf "%s\n" "#define _REENTRANT 1" >>confdefs.h
$as_echo "#define _REENTRANT 1" >>confdefs.h


printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h


	    SHLIB_CFLAGS="-KPIC"

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = yes
	    if test "$do64bit" = yes; then :
then :

		arch=`isainfo`
		if test "$arch" = "sparcv9 sparc"
		if test "$arch" = "sparcv9 sparc"; then :
then :

		    if test "$GCC" = yes
		    if test "$GCC" = yes; then :
then :

			if test "`${CC} -dumpversion | awk -F. '{print $1}'`" -lt 3
			if test "`${CC} -dumpversion | awk -F. '{print $1}'`" -lt 3; then :
then :

			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&2;}
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&2;}

else case e in #(
  e)
else

			    do64bit_ok=yes
			    CFLAGS="$CFLAGS -m64 -mcpu=v9"
			    LDFLAGS="$LDFLAGS -m64 -mcpu=v9"
			    SHLIB_CFLAGS="-fPIC"
			 ;;

esac
fi

else case e in #(
  e)
else

			do64bit_ok=yes
			if test "$do64bitVIS" = yes
			if test "$do64bitVIS" = yes; then :
then :

			    CFLAGS="$CFLAGS -xarch=v9a"
			    LDFLAGS_ARCH="-xarch=v9a"

else case e in #(
  e)
else

			    CFLAGS="$CFLAGS -xarch=v9"
			    LDFLAGS_ARCH="-xarch=v9"
			 ;;

esac
fi
			# Solaris 64 uses this as well
			#LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64"
		     ;;

esac
fi

else case e in #(
  e) if test "$arch" = "amd64 i386"
else
  if test "$arch" = "amd64 i386"; then :
then :

		    if test "$GCC" = yes
		    if test "$GCC" = yes; then :
then :

			case $system in
			    SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*)
				do64bit_ok=yes
				CFLAGS="$CFLAGS -m64"
				LDFLAGS="$LDFLAGS -m64";;
			    *)
				{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;};;
				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;};;
			esac

else case e in #(
  e)
else

			do64bit_ok=yes
			case $system in
			    SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*)
				CFLAGS="$CFLAGS -m64"
				LDFLAGS="$LDFLAGS -m64";;
			    *)
				CFLAGS="$CFLAGS -xarch=amd64"
				LDFLAGS="$LDFLAGS -xarch=amd64";;
			esac
		     ;;

esac
fi

else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported for $arch" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported for $arch" >&2;} ;;
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported for $arch" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported for $arch" >&2;}
esac
fi ;;
fi
esac
fi

fi

	    #--------------------------------------------------------------------
	    # On Solaris 5.x i386 with the sunpro compiler we need to link
	    # with sunmath to get floating point rounding control
	    #--------------------------------------------------------------------
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :
  use_sunmath=no
else case e in #(
  e)
else

		arch=`isainfo`
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use -lsunmath for fp rounding control" >&5
printf %s "checking whether to use -lsunmath for fp rounding control... " >&6; }
		if test "$arch" = "amd64 i386" -o "$arch" = "i386"
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use -lsunmath for fp rounding control" >&5
$as_echo_n "checking whether to use -lsunmath for fp rounding control... " >&6; }
		if test "$arch" = "amd64 i386" -o "$arch" = "i386"; then :
then :

			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
			MATH_LIBS="-lsunmath $MATH_LIBS"
			ac_fn_c_check_header_compile "$LINENO" "sunmath.h" "ac_cv_header_sunmath_h" "$ac_includes_default"
if test "x$ac_cv_header_sunmath_h" = xyes
			ac_fn_c_check_header_mongrel "$LINENO" "sunmath.h" "ac_cv_header_sunmath_h" "$ac_includes_default"
if test "x$ac_cv_header_sunmath_h" = xyes; then :
then :

fi


			use_sunmath=yes

else case e in #(
  e)
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
else

			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
			use_sunmath=no
		 ;;

esac
fi
	     ;;

esac
fi
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    if test "$GCC" = yes
	    if test "$GCC" = yes; then :
then :

		SHLIB_LD='${CC} -shared'
		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
		if test "$do64bit_ok" = yes
		if test "$do64bit_ok" = yes; then :
then :

		    if test "$arch" = "sparcv9 sparc"
		    if test "$arch" = "sparcv9 sparc"; then :
then :

			# We need to specify -static-libgcc or we need to
			# add the path to the sparv9 libgcc.
			SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc"
			# for finding sparcv9 libgcc, get the regular libgcc
			# path, remove so name and append 'sparcv9'
			#v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..."
			#CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir"

else case e in #(
  e) if test "$arch" = "amd64 i386"
else
  if test "$arch" = "amd64 i386"; then :
then :

			SHLIB_LD="$SHLIB_LD -m64 -static-libgcc"

fi ;;
fi
esac
fi

fi

else case e in #(
  e)
		if test "$use_sunmath" = yes
else

		if test "$use_sunmath" = yes; then :
then :
  textmode=textoff
else case e in #(
  e) textmode=text ;;
else
  textmode=text
esac
fi
		case $system in
		    SunOS-5.[1-9][0-9]*|SunOS-5.[7-9])
			SHLIB_LD="\${CC} -G -z $textmode \${LDFLAGS}";;
		    *)
			SHLIB_LD="/usr/ccs/bin/ld -G -z $textmode";;
		esac
		CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}'
	     ;;

esac
fi
	    ;;
	UNIX_SV* | UnixWare-5*)
	    SHLIB_CFLAGS="-KPIC"
	    SHLIB_LD='${CC} -G'
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
	    # that don't grok the -Bexport option.  Test that it does.
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld accepts -Bexport flag" >&5
printf %s "checking for ld accepts -Bexport flag... " >&6; }
if test ${tcl_cv_ld_Bexport+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld accepts -Bexport flag" >&5
$as_echo_n "checking for ld accepts -Bexport flag... " >&6; }
if ${tcl_cv_ld_Bexport+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-Bexport"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_ld_Bexport=yes
else case e in #(
  e) tcl_cv_ld_Bexport=no ;;
else
  tcl_cv_ld_Bexport=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
	        LDFLAGS=$hold_ldflags ;;
	        LDFLAGS=$hold_ldflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_Bexport" >&5
printf "%s\n" "$tcl_cv_ld_Bexport" >&6; }
	    if test $tcl_cv_ld_Bexport = yes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_Bexport" >&5
$as_echo "$tcl_cv_ld_Bexport" >&6; }
	    if test $tcl_cv_ld_Bexport = yes; then :
then :

		LDFLAGS="$LDFLAGS -Wl,-Bexport"

fi
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
    esac

    if test "$do64bit" = yes -a "$do64bit_ok" = no
    if test "$do64bit" = yes -a "$do64bit_ok" = no; then :
then :

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit support being disabled -- don't know magic for this platform" >&5
printf "%s\n" "$as_me: WARNING: 64bit support being disabled -- don't know magic for this platform" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit support being disabled -- don't know magic for this platform" >&5
$as_echo "$as_me: WARNING: 64bit support being disabled -- don't know magic for this platform" >&2;}

fi

    if test "$do64bit" = yes -a "$do64bit_ok" = yes
    if test "$do64bit" = yes -a "$do64bit_ok" = yes; then :
then :


printf "%s\n" "#define TCL_CFG_DO64BIT 1" >>confdefs.h
$as_echo "#define TCL_CFG_DO64BIT 1" >>confdefs.h


fi



    # Step 4: disable dynamic loading if requested via a command-line switch.

    # Check whether --enable-load was given.
if test ${enable_load+y}
if test "${enable_load+set}" = set; then :
then :
  enableval=$enable_load; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
else
  tcl_ok=yes
esac
fi

    if test "$tcl_ok" = no
    if test "$tcl_ok" = no; then :
then :
  DL_OBJS=""
fi

    if test "x$DL_OBJS" != x
    if test "x$DL_OBJS" != x; then :
then :
  BUILD_DLTEST="\$(DLTEST_TARGETS)"
else case e in #(
  e)
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Can't figure out how to do dynamic loading or shared libraries on this system." >&5
printf "%s\n" "$as_me: WARNING: Can't figure out how to do dynamic loading or shared libraries on this system." >&2;}
else

	{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Can't figure out how to do dynamic loading or shared libraries on this system." >&5
$as_echo "$as_me: WARNING: Can't figure out how to do dynamic loading or shared libraries on this system." >&2;}
	SHLIB_CFLAGS=""
	SHLIB_LD=""
	SHLIB_SUFFIX=""
	DL_OBJS="tclLoadNone.o"
	DL_LIBS=""
	LDFLAGS="$LDFLAGS_ORIG"
	CC_SEARCH_FLAGS=""
	LD_SEARCH_FLAGS=""
	BUILD_DLTEST=""
     ;;

esac
fi
    LDFLAGS="$LDFLAGS $LDFLAGS_ARCH"

    # If we're running gcc, then change the C flags for compiling shared
    # libraries to the right flags for gcc, instead of those for the
    # standard manufacturer compiler.

    if test "$DL_OBJS" != "tclLoadNone.o" -a "$GCC" = yes
    if test "$DL_OBJS" != "tclLoadNone.o" -a "$GCC" = yes; then :
then :

	case $system in
	    AIX-*) ;;
	    BSD/OS*) ;;
	    CYGWIN_*|MINGW32_*|MSYS_*) ;;
	    CYGWIN_*|MINGW32_*) ;;
	    HP-UX*) ;;
	    Darwin-*) ;;
	    IRIX*) ;;
	    Linux*|GNU*) ;;
	    NetBSD-*|OpenBSD-*) ;;
	    OSF1-*) ;;
	    NetBSD-*|FreeBSD-*|OpenBSD-*) ;;
	    Darwin-*) ;;
	    SCO_SV-3.2*) ;;
	    *) SHLIB_CFLAGS="-fPIC" ;;
	esac
fi

    if test "$tcl_cv_cc_visibility_hidden" != yes
    if test "$tcl_cv_cc_visibility_hidden" != yes; then :
then :


printf "%s\n" "#define MODULE_SCOPE extern" >>confdefs.h
$as_echo "#define MODULE_SCOPE extern" >>confdefs.h


fi

    if test "$SHARED_LIB_SUFFIX" = ""
    if test "$SHARED_LIB_SUFFIX" = ""; then :
then :

	SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}'
fi
    if test "$UNSHARED_LIB_SUFFIX" = ""
    if test "$UNSHARED_LIB_SUFFIX" = ""; then :
then :

	UNSHARED_LIB_SUFFIX='${VERSION}.a'
fi
    DLL_INSTALL_DIR="\$(LIB_INSTALL_DIR)"

    if test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""
    if test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""; then :
then :

        LIB_SUFFIX=${SHARED_LIB_SUFFIX}
        MAKE_LIB='${SHLIB_LD} -o $@ ${OBJS} ${LDFLAGS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
        if test "${SHLIB_SUFFIX}" = ".dll"
        MAKE_LIB='${SHLIB_LD} -o $@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
        if test "${SHLIB_SUFFIX}" = ".dll"; then :
then :

            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)"'
            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)";if test -f $(LIB_FILE).a; then $(INSTALL_DATA) $(LIB_FILE).a "$(LIB_INSTALL_DIR)"; fi;'
            DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)"

else case e in #(
  e)
else

            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)/$(LIB_FILE)"'
         ;;

esac
fi

else case e in #(
  e)
else

        LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}

        if test "$RANLIB" = ""
        if test "$RANLIB" = ""; then :
then :

            MAKE_LIB='$(STLIB_LD) $@ ${OBJS}'

else case e in #(
  e)
else

            MAKE_LIB='${STLIB_LD} $@ ${OBJS} ; ${RANLIB} $@'
         ;;

esac
fi
        INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)/$(LIB_FILE)"'
     ;;

esac
fi

    # Stub lib does not depend on shared/static configuration
    if test "$RANLIB" = ""
    if test "$RANLIB" = ""; then :
then :

        MAKE_STUB_LIB='${STLIB_LD} $@ ${STUB_LIB_OBJS}'

else case e in #(
  e)
else

        MAKE_STUB_LIB='${STLIB_LD} $@ ${STUB_LIB_OBJS} ; ${RANLIB} $@'
     ;;

esac
fi
    INSTALL_STUB_LIB='$(INSTALL_LIBRARY) $(STUB_LIB_FILE) "$(LIB_INSTALL_DIR)/$(STUB_LIB_FILE)"'

    # Define TCL_LIBS now that we know what DL_LIBS is.
    # The trick here is that we don't want to change the value of TCL_LIBS if
    # it is already set when tclConfig.sh had been loaded by Tk.
    if test "x${TCL_LIBS}" = x
    if test "x${TCL_LIBS}" = x; then :
then :

        TCL_LIBS="${DL_LIBS} ${LIBS} ${MATH_LIBS}"
fi


    # See if the compiler supports casting to a union type.
    # This is used to stop gcc from printing a compiler
    # warning when initializing a union member.
	# See if the compiler supports casting to a union type.
	# This is used to stop gcc from printing a compiler
	# warning when initializing a union member.

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
printf %s "checking for cast to union support... " >&6; }
if test ${tcl_cv_cast_to_union+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
$as_echo_n "checking for cast to union support... " >&6; }
if ${tcl_cv_cast_to_union+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

		union foo { int i; double d; };
		union foo f = (union foo) (int) 0;
		  union foo { int i; double d; };
		  union foo f = (union foo) (int) 0;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_cast_to_union=yes
else case e in #(
  e) tcl_cv_cast_to_union=no ;;
else
  tcl_cv_cast_to_union=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
printf "%s\n" "$tcl_cv_cast_to_union" >&6; }
    if test "$tcl_cv_cast_to_union" = "yes"; then

printf "%s\n" "#define HAVE_CAST_TO_UNION 1" >>confdefs.h

    fi
    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fno-lto"
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working -fno-lto" >&5
printf %s "checking for working -fno-lto... " >&6; }
if test ${ac_cv_nolto+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_nolto=yes
else case e in #(
  e) ac_cv_nolto=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
     ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_nolto" >&5
printf "%s\n" "$ac_cv_nolto" >&6; }
    CFLAGS=$hold_cflags
    if test "$ac_cv_nolto" = "yes" ; then
	CFLAGS_NOLTO="-fno-lto"
    else
	CFLAGS_NOLTO=""
    fi
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -finput-charset" >&5
printf %s "checking if the compiler understands -finput-charset... " >&6; }
if test ${tcl_cv_cc_input_charset+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -finput-charset=UTF-8"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_cc_input_charset=yes
else case e in #(
  e) tcl_cv_cc_input_charset=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	CFLAGS=$hold_cflags ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_input_charset" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
printf "%s\n" "$tcl_cv_cc_input_charset" >&6; }
    if test $tcl_cv_cc_input_charset = yes; then
	CFLAGS="$CFLAGS -finput-charset=UTF-8"
    fi

$as_echo "$tcl_cv_cast_to_union" >&6; }
    ac_fn_c_check_header_compile "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default"
if test "x$ac_cv_header_stdbool_h" = xyes
then :

	if test "$tcl_cv_cast_to_union" = "yes"; then
printf "%s\n" "#define HAVE_STDBOOL_H 1" >>confdefs.h

fi

$as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h

    # Check for vfork, posix_spawnp() and friends unconditionally
    ac_fn_c_check_func "$LINENO" "vfork" "ac_cv_func_vfork"
if test "x$ac_cv_func_vfork" = xyes
then :
  printf "%s\n" "#define HAVE_VFORK 1" >>confdefs.h

fi
	fi
ac_fn_c_check_func "$LINENO" "posix_spawnp" "ac_cv_func_posix_spawnp"
if test "x$ac_cv_func_posix_spawnp" = xyes
then :
  printf "%s\n" "#define HAVE_POSIX_SPAWNP 1" >>confdefs.h

fi
ac_fn_c_check_func "$LINENO" "posix_spawn_file_actions_adddup2" "ac_cv_func_posix_spawn_file_actions_adddup2"
if test "x$ac_cv_func_posix_spawn_file_actions_adddup2" = xyes
then :
  printf "%s\n" "#define HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1" >>confdefs.h

fi
ac_fn_c_check_func "$LINENO" "posix_spawnattr_setflags" "ac_cv_func_posix_spawnattr_setflags"
if test "x$ac_cv_func_posix_spawnattr_setflags" = xyes
then :
  printf "%s\n" "#define HAVE_POSIX_SPAWNATTR_SETFLAGS 1" >>confdefs.h

fi


    # FIXME: This subst was left in only because the TCL_DL_LIBS
    # entry in tclConfig.sh uses it. It is not clear why someone
    # would use TCL_DL_LIBS instead of TCL_LIBS.



6466
6467
6468
6469
6470
6471
6472
6473
6474



6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487


6488
6489

6490
6491
6492
6493


6494
6495
6496
6497

6498
6499
6500
6501
6502

6503
6504
6505


6506
6507

6508
6509
6510
6511
6512
6513
6514


6515
6516
6517
6518
6519
6520
6521
6522

6523
6524
6525
6526
6527
6528
6529
6530
6531


6532
6533
6534


6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545


6546
6547
6548

6549
6550
6551
6552



6553
6554
6555
6556

6557
6558
6559
6560
6561
6562
6563

6564
6565
6566
6567


6568
6569
6570
6571
6572

6573
6574
6575
6576
6577
6578
6579

6580
6581
6582
6583


6584
6585
6586

6587
6588
6589

6590
6591
6592
6593
6594
6595

6596
6597
6598
6599
6600
6601

6602
6603
6604
6605



6606
6607
6608
6609

6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623

6624
6625
6626
6627
6628
6629
6630
6631
6632

6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654

6655
6656
6657
6658


6659

6660
6661
6662

6663
6664
6665
6666
6667
6668
6669

6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689


6690
6691
6692

6693
6694
6695

6696
6697
6698
6699
6700
6701

6702
6703
6704
6705















































6706
6707
6708


6709
6710
6711


6712
6713
6714
6715
6716
6717
6718



6719
6720
6721
6722



6723


















6724

6725
6726
6727
6728
6729
6730
6731

6732
6733
6734

6735
6736
6737
6738
6739
6740

6741
6742

6743
6744

6745
6746
6747
6748
6749
6750

6751
6752
6753


6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804

6805
6806
6807
6808


6809
6810

6811
6812
6813
6814
6815
6816
6817
6818
6819
6820

6821
6822
6823

6824
6825
6826
6827
6828
6829
6830
6831




6832
6833
6834
6835



6836
6837
6838
6839
6840
6841

6842
6843
6844
6845
6846
6847
6848

6849
6850
6851
6852


6853
6854
6855

6856
6857
6858
6859


6860
6861
6862

6863
6864
6865
6866
6867
6868






6869
6870
6871
6872
6873
6874
6875

6876
6877
6878

6879
6880
6881


6882
6883
6884
6885
6886
6887
6888




6889
6890
6891
6892
6893

6894
6895
6896
6897
6898



6899
6900

6901
6902
6903



6904

6905
6906
6907




6908
6909
6910
6911
6912
6913
6914

6915
6916
6917
6918
6919



6920
6921
6922
6923



6924
6925
6926
6927
6928

6929
6930
6931
6932
6933
6934
6935
6936

6937
6938
6939
6940


6941
6942
6943

6944
6945
6946
6947
6948
6949
6950
6951

6952
6953
6954


6955
6956
6957


6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968



6969
6970
6971
6972



6973
6974
6975
6976
6977
6978
6979
6980
6981
6982

6983
6984
6985
6986
6987
6988
6989
6990
6274
6275
6276
6277
6278
6279
6280


6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294


6295
6296
6297

6298

6299


6300
6301

6302
6303
6304
6305
6306
6307
6308
6309

6310
6311


6312
6313
6314

6315
6316
6317
6318
6319
6320


6321
6322
6323
6324
6325
6326
6327
6328
6329

6330
6331
6332
6333
6334
6335
6336
6337


6338
6339
6340


6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351


6352
6353
6354
6355

6356




6357
6358
6359
6360
6361
6362

6363
6364
6365
6366
6367
6368
6369

6370

6371


6372
6373
6374
6375
6376
6377

6378
6379
6380
6381
6382
6383
6384

6385

6386


6387
6388

6389

6390

6391

6392

6393
6394
6395
6396

6397
6398
6399
6400
6401
6402

6403




6404
6405
6406
6407
6408
6409

6410
6411













6412




6413
6414
6415
6416

6417






















6418




6419
6420
6421
6422
6423
6424

6425
6426
6427
6428
6429
6430
6431

6432

















6433


6434
6435

6436

6437

6438

6439

6440
6441
6442
6443

6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496


6497
6498
6499


6500
6501
6502
6503
6504
6505



6506
6507
6508




6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530

6531
6532
6533
6534
6535
6536
6537

6538
6539
6540

6541
6542
6543
6544
6545
6546

6547


6548
6549

6550

6551
6552
6553
6554

6555
6556


6557
6558
6559


















































6560




6561
6562
6563

6564










6565



6566

6567






6568
6569
6570
6571




6572
6573
6574
6575
6576
6577
6578
6579

6580
6581
6582
6583
6584
6585
6586

6587

6588


6589
6590

6591

6592

6593


6594
6595
6596
6597

6598
6599
6600
6601



6602
6603
6604
6605
6606
6607




6608
6609

6610

6611

6612
6613


6614
6615
6616
6617
6618
6619



6620
6621
6622
6623



6624

6625

6626



6627
6628
6629
6630

6631
6632
6633
6634
6635
6636
6637

6638



6639
6640
6641
6642
6643
6644





6645

6646



6647
6648
6649




6650
6651
6652
6653
6654
6655
6656

6657
6658
6659
6660
6661
6662
6663
6664

6665

6666


6667
6668

6669

6670

6671
6672
6673
6674
6675
6676

6677
6678


6679
6680
6681


6682
6683
6684
6685
6686
6687
6688
6689
6690
6691



6692
6693
6694




6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706

6707

6708
6709
6710
6711
6712
6713
6714







-
-
+
+
+











-
-
+
+

-
+
-

-
-
+
+
-



+




-
+

-
-
+
+

-
+





-
-
+
+







-
+







-
-
+
+

-
-
+
+









-
-
+
+


-
+
-
-
-
-
+
+
+



-
+






-
+
-

-
-
+
+




-
+






-
+
-

-
-
+
+
-

-
+
-

-
+
-




-
+





-
+
-
-
-
-
+
+
+



-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-




-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+

+


-
+






-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+
-

-
+
-

-
+
-




-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
+
+




-
-
-
+
+
+
-
-
-
-
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+






-
+


-
+





-
+
-
-
+

-
+
-




-
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+

-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-

-
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+





-
+






-
+
-

-
-
+
+
-

-
+
-

-
-
+
+


-
+



-
-
-
+
+
+
+
+
+
-
-
-
-


-
+
-

-
+

-
-
+
+




-
-
-
+
+
+
+
-
-
-

-
+
-

-
-
-
+
+
+

-
+



+
+
+
-
+
-
-
-
+
+
+
+


-
-
-
-
-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+




-
+







-
+
-

-
-
+
+
-

-
+
-






-
+

-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+









-
+
-















printf "%s\n" "#define TCL_SHLIB_EXT \"${SHLIB_SUFFIX}\"" >>confdefs.h
cat >>confdefs.h <<_ACEOF
#define TCL_SHLIB_EXT "${SHLIB_SUFFIX}"
_ACEOF











    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
printf %s "checking for build with symbols... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
$as_echo_n "checking for build with symbols... " >&6; }
    # Check whether --enable-symbols was given.
if test ${enable_symbols+y}
if test "${enable_symbols+set}" = set; then :
then :
  enableval=$enable_symbols; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=no ;;
else
  tcl_ok=no
esac
fi

# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
    DBGX=""
    if test "$tcl_ok" = "no"; then
	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'

printf "%s\n" "#define NDEBUG 1" >>confdefs.h
$as_echo "#define NDEBUG 1" >>confdefs.h

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }

printf "%s\n" "#define TCL_CFG_OPTIMIZED 1" >>confdefs.h
$as_echo "#define TCL_CFG_OPTIMIZED 1" >>confdefs.h

    else
	CFLAGS_DEFAULT='$(CFLAGS_DEBUG)'
	LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)'
	if test "$tcl_ok" = "yes"; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
printf "%s\n" "yes (standard debugging)" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
$as_echo "yes (standard debugging)" >&6; }
	fi
    fi



    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then

printf "%s\n" "#define TCL_MEM_DEBUG 1" >>confdefs.h
$as_echo "#define TCL_MEM_DEBUG 1" >>confdefs.h

    fi



    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
	if test "$tcl_ok" = "all"; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem debugging" >&5
printf "%s\n" "enabled symbols mem debugging" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem debugging" >&5
$as_echo "enabled symbols mem debugging" >&6; }
	else
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
printf "%s\n" "enabled $tcl_ok debugging" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
$as_echo "enabled $tcl_ok debugging" >&6; }
	fi
    fi


#--------------------------------------------------------------------
#	Detect what compiler flags to set for 64-bit support.
#--------------------------------------------------------------------


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for required early compiler flags" >&5
printf %s "checking for required early compiler flags... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for required early compiler flags" >&5
$as_echo_n "checking for required early compiler flags... " >&6; }
    tcl_flags=""

    if test ${tcl_cv_flag__isoc99_source+y}
    if ${tcl_cv_flag__isoc99_source+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
int
main (void)
main ()
{
char *p = (char *)strtoll; char *q = (char *)strtoull;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_flag__isoc99_source=no
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _ISOC99_SOURCE 1
#include <stdlib.h>
int
main (void)
main ()
{
char *p = (char *)strtoll; char *q = (char *)strtoull;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_flag__isoc99_source=yes
else case e in #(
  e) tcl_cv_flag__isoc99_source=no ;;
else
  tcl_cv_flag__isoc99_source=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi

    if test "x${tcl_cv_flag__isoc99_source}" = "xyes" ; then

printf "%s\n" "#define _ISOC99_SOURCE 1" >>confdefs.h
$as_echo "#define _ISOC99_SOURCE 1" >>confdefs.h

	tcl_flags="$tcl_flags _ISOC99_SOURCE"
    fi


    if test ${tcl_cv_flag__file_offset_bits+y}
    if ${tcl_cv_flag__largefile64_source+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/stat.h>
int
main (void)
main ()
{
switch (0) { case 0: case (sizeof(off_t)==sizeof(long long)): ; }
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_flag__file_offset_bits=no
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _FILE_OFFSET_BITS 64
#include <sys/stat.h>
struct stat64 buf; int i = stat64("/", &buf);
int
main (void)
{
switch (0) { case 0: case (sizeof(off_t)==sizeof(long long)): ; }
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_flag__file_offset_bits=yes
else case e in #(
  e) tcl_cv_flag__file_offset_bits=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi

    if test "x${tcl_cv_flag__file_offset_bits}" = "xyes" ; then

printf "%s\n" "#define _FILE_OFFSET_BITS 64" >>confdefs.h

	tcl_flags="$tcl_flags _FILE_OFFSET_BITS"
    fi


    if test ${tcl_cv_flag__largefile64_source+y}
  tcl_cv_flag__largefile64_source=no
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _LARGEFILE64_SOURCE 1
#include <sys/stat.h>
int
main (void)
main ()
{
struct stat64 buf; int i = stat64("/", &buf);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_flag__largefile64_source=no
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _LARGEFILE64_SOURCE 1
#include <sys/stat.h>
int
main (void)
{
struct stat64 buf; int i = stat64("/", &buf);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_flag__largefile64_source=yes
else case e in #(
  e) tcl_cv_flag__largefile64_source=no ;;
else
  tcl_cv_flag__largefile64_source=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi

    if test "x${tcl_cv_flag__largefile64_source}" = "xyes" ; then

printf "%s\n" "#define _LARGEFILE64_SOURCE 1" >>confdefs.h
$as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h

	tcl_flags="$tcl_flags _LARGEFILE64_SOURCE"
    fi


    if ${tcl_cv_flag__largefile_source64+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/stat.h>
int
main ()
{
char *p = (char *)open64;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_flag__largefile_source64=no
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _LARGEFILE_SOURCE64 1
#include <sys/stat.h>
int
main ()
{
char *p = (char *)open64;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_flag__largefile_source64=yes
else
  tcl_cv_flag__largefile_source64=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi

    if test "x${tcl_cv_flag__largefile_source64}" = "xyes" ; then

$as_echo "#define _LARGEFILE_SOURCE64 1" >>confdefs.h

	tcl_flags="$tcl_flags _LARGEFILE_SOURCE64"
    fi

    if test "x${tcl_flags}" = "x" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5
printf "%s\n" "none" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
$as_echo "none" >&6; }
    else
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${tcl_flags}" >&5
printf "%s\n" "${tcl_flags}" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_flags}" >&5
$as_echo "${tcl_flags}" >&6; }
    fi



    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 'long' and 'long long' have the same size (64-bit)?" >&5
printf %s "checking if 'long' and 'long long' have the same size (64-bit)?... " >&6; }
    if test ${tcl_cv_type_64bit+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit integer type" >&5
$as_echo_n "checking for 64-bit integer type... " >&6; }
    if ${tcl_cv_type_64bit+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	tcl_cv_type_64bit=none
	# See if the compiler knows natively about __int64
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
{
__int64 value = (__int64) 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_type_64bit=__int64
else
  tcl_type_64bit="long long"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	# See if we could use long anyway  Note that we substitute in the
	# See if we should use long anyway  Note that we substitute in the
	# type that is our current guess for a 64-bit type inside this check
	# program, so it should be modified only carefully...
        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
switch (0) {
            case 1: case (sizeof(long long)==sizeof(long)): ;
            case 1: case (sizeof(${tcl_type_64bit})==sizeof(long)): ;
        }
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_type_64bit="long long"
  tcl_cv_type_64bit=${tcl_type_64bit}
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi

    if test "${tcl_cv_type_64bit}" = none ; then

printf "%s\n" "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h
$as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using long" >&5
$as_echo "using long" >&6; }
    else
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	# Now check for auxiliary declarations
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit time_t" >&5
printf %s "checking for 64-bit time_t... " >&6; }
if test ${tcl_cv_time_t_64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
int
main (void)
{
switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_time_t_64=yes
else case e in #(
  e) tcl_cv_time_t_64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_time_t_64" >&5
printf "%s\n" "$tcl_cv_time_t_64" >&6; }
	if test "x${tcl_cv_time_t_64}" = "xno" ; then
	    # Note that _TIME_BITS=64 requires _FILE_OFFSET_BITS=64
	    # which SC_TCL_EARLY_FLAGS has defined if necessary.
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if _TIME_BITS=64 enables 64-bit time_t" >&5
printf %s "checking if _TIME_BITS=64 enables 64-bit time_t... " >&6; }
if test ${tcl_cv__time_bits+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _TIME_BITS 64
#include <sys/types.h>
int
main (void)
{

switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}
  ;
  return 0;
}
cat >>confdefs.h <<_ACEOF
#define TCL_WIDE_INT_TYPE ${tcl_cv_type_64bit}
_ACEOF
if ac_fn_c_try_compile "$LINENO"

then :
  tcl_cv__time_bits=yes
else case e in #(
  e) tcl_cv__time_bits=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv__time_bits" >&5
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_cv_type_64bit}" >&5
printf "%s\n" "$tcl_cv__time_bits" >&6; }
	    if test "x${tcl_cv__time_bits}" = "xyes" ; then

$as_echo "${tcl_cv_type_64bit}" >&6; }
printf "%s\n" "#define _TIME_BITS 64" >>confdefs.h

	    fi
	fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct dirent64" >&5
printf %s "checking for struct dirent64... " >&6; }
if test ${tcl_cv_struct_dirent64+y}
	# Now check for auxiliary declarations
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct dirent64" >&5
$as_echo_n "checking for struct dirent64... " >&6; }
if ${tcl_cv_struct_dirent64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
#include <dirent.h>
int
main (void)
main ()
{
struct dirent64 p;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_struct_dirent64=yes
else case e in #(
  e) tcl_cv_struct_dirent64=no ;;
else
  tcl_cv_struct_dirent64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_dirent64" >&5
printf "%s\n" "$tcl_cv_struct_dirent64" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_dirent64" >&5
$as_echo "$tcl_cv_struct_dirent64" >&6; }
	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then

printf "%s\n" "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h
$as_echo "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h

	fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for DIR64" >&5
printf %s "checking for DIR64... " >&6; }
if test ${tcl_cv_DIR64+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5
$as_echo_n "checking for struct stat64... " >&6; }
if ${tcl_cv_struct_stat64+:} false; then :
  $as_echo_n "(cached) " >&6
else

then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
int
main (void)
main ()
{
struct dirent64 *p; DIR64 d = opendir64(".");
            p = readdir64(d); rewinddir64(d); closedir64(d);
struct stat64 p;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_DIR64=yes
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_struct_stat64=yes
else
  tcl_cv_struct_stat64=no
else case e in #(
  e) tcl_cv_DIR64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_DIR64" >&5
printf "%s\n" "$tcl_cv_DIR64" >&6; }
	if test "x${tcl_cv_DIR64}" = "xyes" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_stat64" >&5
$as_echo "$tcl_cv_struct_stat64" >&6; }
	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then

printf "%s\n" "#define HAVE_DIR64 1" >>confdefs.h
$as_echo "#define HAVE_STRUCT_STAT64 1" >>confdefs.h

	fi

	for ac_func in open64 lseek64
do :
  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
	ac_fn_c_check_func "$LINENO" "open64" "ac_cv_func_open64"
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if test "x$ac_cv_func_open64" = xyes
then :
  printf "%s\n" "#define HAVE_OPEN64 1" >>confdefs.h
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
ac_fn_c_check_func "$LINENO" "lseek64" "ac_cv_func_lseek64"
if test "x$ac_cv_func_lseek64" = xyes
then :
  printf "%s\n" "#define HAVE_LSEEK64 1" >>confdefs.h

done
fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for off64_t" >&5
printf %s "checking for off64_t... " >&6; }
	if test ${tcl_cv_type_off64_t+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for off64_t" >&5
$as_echo_n "checking for off64_t... " >&6; }
	if ${tcl_cv_type_off64_t+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
int
main (void)
main ()
{
off64_t offset;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_type_off64_t=yes
else case e in #(
  e) tcl_cv_type_off64_t=no ;;
else
  tcl_cv_type_off64_t=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi

			if test "x${tcl_cv_type_off64_t}" = "xyes" && \
	        test "x${ac_cv_func_lseek64}" = "xyes" && \
	        test "x${ac_cv_func_open64}" = "xyes" ; then

printf "%s\n" "#define HAVE_TYPE_OFF64_T 1" >>confdefs.h
$as_echo "#define HAVE_TYPE_OFF64_T 1" >>confdefs.h

	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	else
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
	fi
    fi


#--------------------------------------------------------------------
#	Check endianness because we can optimize some operations
#--------------------------------------------------------------------

 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
printf %s "checking whether byte ordering is bigendian... " >&6; }
if test ${ac_cv_c_bigendian+y}
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
$as_echo_n "checking whether byte ordering is bigendian... " >&6; }
if ${ac_cv_c_bigendian+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_c_bigendian=unknown
  $as_echo_n "(cached) " >&6
else
  ac_cv_c_bigendian=unknown
    # See if we're dealing with a universal compiler.
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifndef __APPLE_CC__
	       not a universal capable compiler
	     #endif
	     typedef int dummy;

_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :

	# Check for potential -arch flags.  It is not universal unless
	# there are at least two -arch flags with different values.
	ac_arch=
	ac_prev=
	for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
	 if test -n "$ac_prev"; then
7000
7001
7002
7003
7004
7005
7006
7007

7008
7009
7010
7011
7012
7013
7014
7015
7016

7017
7018
7019


7020
7021
7022
7023
7024
7025
7026
7027
7028

7029
7030
7031
7032
7033
7034
7035
7036
7037

7038
7039
7040
7041
7042
7043
7044
7045
7046
7047

7048
7049
7050
7051


7052
7053
7054

7055
7056

7057
7058
7059
7060
7061
7062
7063
7064
7065

7066
7067
7068
7069
7070
7071
7072
7073
7074
7075

7076
7077
7078
7079
7080
7081
7082
7083

7084
7085
7086
7087
7088
7089
7090
7091
7092
7093

7094
7095
7096
7097


7098
7099
7100

7101
7102

7103
7104
7105
7106

7107
7108
7109
7110
7111

7112
7113

7114
7115
7116
7117
7118

7119
7120

7121
7122
7123
7124


7125
7126
7127



7128
7129
7130
7131

7132
7133
7134



7135
7136

7137
7138

7139
7140
7141

7142
7143
7144
7145
7146
7147
7148
7149
7150

7151
7152
7153


7154
7155
7156
7157

7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173

7174
7175
7176
7177


7178
7179
7180
7181

7182
7183
7184
7185

7186
7187
7188
7189


7190
7191
7192

7193
7194
7195
7196
7197



7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217

7218
7219
7220


7221
7222

7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237



7238
7239
7240
7241



7242
7243
7244
7245
7246

7247
7248
7249
7250
7251
7252
7253

7254
7255
7256
7257


7258
7259
7260

7261
7262
7263
7264


7265
7266
7267
7268
7269
7270
7271
7272
7273


7274
7275
7276
7277
7278
7279
7280
7281


7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553

7554
7555
7556
7557


7558
7559
7560
7561


7562
7563
7564
7565


7566
7567
7568

7569
7570
7571
7572
7573
7574
7575

7576
7577
7578
7579
7580
7581
7582







7583

















































































































7584
7585
7586
7587
7588
7589
7590
7591
7592

7593
7594
7595
7596
7597
7598






7599
7600
7601
7602
7603

7604
7605

7606
7607
7608

7609
7610
7611
7612
7613
7614
7615

7616
7617
7618
7619

7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643



7644










7645
7646
7647
7648
7649
























7650
7651
7652
7653
7654










































7655



7656
7657
7658








7659
7660

7661







7662






7663

7664
7665
7666
7667
7668
7669






















7670
7671



7672

7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683



7684
7685
7686
7687



7688
7689
7690
7691
7692

7693
7694

7695
7696
7697
7698
7699

7700
7701
7702
7703


7704
7705
7706

7707
7708
7709
7710


7711
7712
7713

7714
7715
7716
7717
7718
7719
7720
7721
7722
7723


7724
7725

7726
7727
7728
7729


7730
7731
7732
7733
7734
7735
7736
7737


7738
7739
7740
7741
7742


7743
7744
7745
7746
7747
7748
7749
7750
7751
7752























































7753
7754
7755
7756
7757



7758
7759
7760
7761



7762
7763
7764
7765
7766
7767
7768

7769
7770
7771
7772
7773
7774
7775

7776
7777
7778
7779


7780
7781
7782

7783
7784

7785
7786
7787
7788


7789


7790
7791


7792
7793



7794
7795
7796


7797
7798
7799
7800



7801
7802
7803
7804



7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819

7820
7821
7822
7823
7824
7825
7826

7827
7828
7829
7830


7831
7832
7833

7834
7835

7836
7837
7838
7839


7840
7841
7842

7843
7844
7845
7846
7847



7848
7849
7850
7851



7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867

7868
7869
7870
7871
7872
7873
7874

7875
7876
7877
7878


7879
7880
7881
7882


7883
7884
7885
7886


7887
7888
7889

7890
7891
7892
7893
7894
7895
7896
7897
7898
7899

7900
7901

7902
7903
7904
7905
7906
7907
7908

7909
7910
7911
7912

7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927


7928
7929
7930
7931

7932
7933
7934
7935
7936

7937
7938
7939
7940
7941
7942
7943

7944
7945
7946
7947
7948




7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977

7978
7979
7980
7981
7982
7983
7984
6724
6725
6726
6727
6728
6729
6730

6731
6732
6733
6734
6735
6736
6737
6738
6739

6740
6741


6742
6743
6744
6745
6746
6747
6748
6749
6750
6751

6752

6753
6754
6755
6756
6757
6758
6759

6760
6761
6762
6763
6764
6765
6766
6767
6768
6769

6770

6771


6772
6773

6774

6775
6776

6777
6778
6779
6780
6781
6782
6783
6784
6785

6786
6787
6788
6789
6790
6791
6792
6793
6794
6795

6796

6797
6798
6799
6800
6801
6802

6803
6804
6805
6806
6807
6808
6809
6810
6811
6812

6813

6814


6815
6816

6817

6818
6819

6820
6821
6822
6823

6824

6825
6826
6827

6828
6829

6830
6831
6832
6833
6834

6835
6836

6837
6838
6839
6840
6841
6842
6843



6844
6845
6846




6847



6848
6849
6850
6851

6852


6853
6854
6855

6856
6857
6858
6859
6860
6861
6862
6863
6864

6865



6866
6867
6868
6869
6870

6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886

6887

6888


6889
6890

6891
6892

6893

6894
6895

6896

6897


6898
6899
6900
6901

6902
6903
6904
6905
6906

6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928

6929
6930


6931
6932
6933

6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946



6947
6948
6949




6950
6951
6952
6953
6954
6955
6956

6957
6958
6959
6960
6961
6962
6963

6964

6965


6966
6967

6968

6969

6970


6971
6972
6973
6974







6975
6976








6977
6978


























































6979




















































































































6980

























































































6981
6982
6983
6984
6985
6986

6987

6988


6989
6990

6991


6992
6993

6994


6995
6996
6997
6998

6999
7000
7001
7002
7003
7004
7005

7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142

7143

7144




7145
7146
7147
7148
7149
7150

7151
7152


7153


7154

7155

7156


7157




7158




7159




7160








7161




7162

7163
7164


7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178





7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205


7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251



7252
7253
7254
7255
7256
7257
7258
7259
7260

7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276

7277






7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300

7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313



7314
7315
7316




7317
7318
7319
7320
7321
7322
7323

7324
7325

7326
7327
7328
7329
7330

7331

7332


7333
7334

7335

7336

7337


7338
7339
7340
7341

7342
7343
7344
7345
7346
7347
7348
7349
7350


7351
7352
7353

7354

7355


7356
7357

7358
7359
7360
7361
7362


7363
7364
7365
7366
7367


7368
7369
7370
7371
7372







7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429



7430
7431
7432




7433
7434
7435
7436
7437
7438
7439
7440
7441

7442
7443
7444
7445
7446
7447
7448

7449

7450


7451
7452

7453

7454
7455

7456

7457


7458
7459
7460
7461
7462


7463
7464


7465
7466
7467
7468
7469
7470
7471
7472
7473



7474
7475
7476




7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493

7494
7495
7496
7497
7498
7499
7500

7501

7502


7503
7504

7505

7506
7507

7508

7509


7510
7511
7512
7513

7514
7515
7516



7517
7518
7519




7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537

7538
7539
7540
7541
7542
7543
7544

7545

7546


7547
7548

7549


7550
7551

7552


7553
7554
7555
7556

7557
7558
7559
7560
7561
7562
7563
7564
7565
7566

7567
7568

7569







7570
7571
7572
7573

7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587


7588
7589
7590
7591
7592

7593

7594
7595
7596

7597
7598
7599
7600
7601
7602
7603

7604





7605
7606
7607
7608





























7609
7610
7611
7612
7613
7614
7615
7616







-
+








-
+

-
-
+
+








-
+
-







-
+









-
+
-

-
-
+
+
-

-
+

-
+








-
+









-
+
-






-
+









-
+
-

-
-
+
+
-

-
+

-
+



-
+
-



-
+

-
+




-
+

-
+




+
+
-
-
-
+
+
+
-
-
-
-
+
-
-
-
+
+
+

-
+
-
-
+


-
+








-
+
-
-
-
+
+



-
+















-
+
-

-
-
+
+
-


-
+
-


-
+
-

-
-
+
+


-
+




-
+
+
+



















-
+

-
-
+
+

-
+












-
-
-
+
+
+
-
-
-
-
+
+
+




-
+






-
+
-

-
-
+
+
-

-
+
-

-
-
+
+


-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+


-
+






-
+







+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+
-

-
-
-
-
+
+
+
+
+
+
-


-
-
+
-
-
+
-

-
+
-
-

-
-
-
-
+
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-

-
-
-
-

-


-
-
+
+
+

+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
-
-
-
+
+
+
+
+
+
+
+

-
+

+
+
+
+
+
+
+

+
+
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
+
+

+








-
-
-
+
+
+
-
-
-
-
+
+
+




-
+

-
+




-
+
-

-
-
+
+
-

-
+
-

-
-
+
+


-
+








-
-
+
+

-
+
-

-
-
+
+
-





-
-
+
+



-
-
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
+
+

+
+
-
-
+
+
-
-
+
+
+



+
+

-
-
-
+
+
+
-
-
-
-
+
+
+














-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
+
+


-
+


-
-
-
+
+
+
-
-
-
-
+
+
+















-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+


-
+









-
+

-
+
-
-
-
-
-
-
-
+



-
+













-
-
+
+



-
+
-



-
+






-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







	   esac
	   ac_prev=
	 elif test "x$ac_word" = "x-arch"; then
	   ac_prev=arch
	 fi
       done
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    if test $ac_cv_c_bigendian = unknown; then
      # See if sys/param.h defines the BYTE_ORDER macro.
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
	     #include <sys/param.h>

int
main (void)
main ()
{
#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \\
		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
		     && LITTLE_ENDIAN)
	      bogus endian macros
	     #endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  # It does; now see whether it defined to BIG_ENDIAN or not.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
		#include <sys/param.h>

int
main (void)
main ()
{
#if BYTE_ORDER != BIG_ENDIAN
		 not big endian
		#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_c_bigendian=yes
else case e in #(
  e) ac_cv_c_bigendian=no ;;
else
  ac_cv_c_bigendian=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    fi
    if test $ac_cv_c_bigendian = unknown; then
      # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>

int
main (void)
main ()
{
#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
	      bogus endian macros
	     #endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  # It does; now see whether it defined to _BIG_ENDIAN or not.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>

int
main (void)
main ()
{
#ifndef _BIG_ENDIAN
		 not big endian
		#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_c_bigendian=yes
else case e in #(
  e) ac_cv_c_bigendian=no ;;
else
  ac_cv_c_bigendian=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    fi
    if test $ac_cv_c_bigendian = unknown; then
      # Compile a test program.
      if test "$cross_compiling" = yes
      if test "$cross_compiling" = yes; then :
then :
  # Try to guess by grepping values from an object file.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
unsigned short int ascii_mm[] =
short int ascii_mm[] =
		  { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
		unsigned short int ascii_ii[] =
		short int ascii_ii[] =
		  { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
		int use_ascii (int i) {
		  return ascii_mm[i] + ascii_ii[i];
		}
		unsigned short int ebcdic_ii[] =
		short int ebcdic_ii[] =
		  { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
		unsigned short int ebcdic_mm[] =
		short int ebcdic_mm[] =
		  { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
		int use_ebcdic (int i) {
		  return ebcdic_mm[i] + ebcdic_ii[i];
		}
		extern int foo;

		int
		main (int argc, char **argv)
		{
int
main ()
{
		  /* Intimidate the compiler so that it does not
		     optimize the arrays away.  */
		  char *p = argv[0];
		  ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
return use_ascii (foo) == use_ebcdic (foo);
		  ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
		  return use_ascii (argc) == use_ebcdic (*p);
		}
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
  if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
	      ac_cv_c_bigendian=yes
	    fi
	    if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
	    if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
	      if test "$ac_cv_c_bigendian" = unknown; then
		ac_cv_c_bigendian=no
	      else
		# finding both strings is unlikely to happen, but who knows?
		ac_cv_c_bigendian=unknown
	      fi
	    fi
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    conftest$ac_exeext conftest.$ac_ext
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main (void)
main ()
{

	     /* Are we little or big endian?  From Harbison&Steele.  */
	     union
	     {
	       long int l;
	       char c[sizeof (long int)];
	     } u;
	     u.l = 1;
	     return u.c[sizeof (long int) - 1] == 1;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"
if ac_fn_c_try_run "$LINENO"; then :
then :
  ac_cv_c_bigendian=no
else case e in #(
  e) ac_cv_c_bigendian=yes ;;
else
  ac_cv_c_bigendian=yes
esac
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
  conftest.$ac_objext conftest.beam conftest.$ac_ext
esac
fi

    fi ;;
    fi
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
printf "%s\n" "$ac_cv_c_bigendian" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
$as_echo "$ac_cv_c_bigendian" >&6; }
 case $ac_cv_c_bigendian in #(
   yes)
     printf "%s\n" "#define WORDS_BIGENDIAN 1" >>confdefs.h
     $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h
;; #(
   no)
      ;; #(
   universal)
     #

$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h

     ;; #(
   *)
     as_fn_error $? "unknown endianness
 presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
 esac


#------------------------------------------------------------------------
# If Tcl and Tk are installed in different places, adjust the library
# search path to reflect this.
#------------------------------------------------------------------------

LIB_RUNTIME_DIR='$(libdir)'

if test "$TCL_EXEC_PREFIX" != "$exec_prefix"; then
    LIB_RUNTIME_DIR="${LIB_RUNTIME_DIR}:${TCL_EXEC_PREFIX}/lib"
fi

if test "$TCL_PREFIX" != "$prefix"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING:
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
        Different --prefix selected for Tk and Tcl!
        [package require tk] may not work correctly in tclsh." >&5
printf "%s\n" "$as_me: WARNING:
        [package require Tk] may not work correctly in tclsh." >&5
$as_echo "$as_me: WARNING:
        Different --prefix selected for Tk and Tcl!
        [package require tk] may not work correctly in tclsh." >&2;}
        [package require Tk] may not work correctly in tclsh." >&2;}
fi

#--------------------------------------------------------------------
#	Include sys/select.h if it exists and if it supplies things
#	that appear to be useful and aren't already in sys/types.h.
#	This appears to be true only on the RS/6000 under AIX.  Some
#	systems like OSF/1 have a sys/select.h that's of no use, and
#	other systems like SCO UNIX have a sys/select.h that's
#	pernicious.  If "fd_set" isn't defined anywhere then set a
#	special flag.
#--------------------------------------------------------------------

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fd_set in sys/types" >&5
printf %s "checking for fd_set in sys/types... " >&6; }
if test ${tcl_cv_type_fd_set+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fd_set in sys/types" >&5
$as_echo_n "checking for fd_set in sys/types... " >&6; }
if ${tcl_cv_type_fd_set+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
int
main (void)
main ()
{
fd_set readMask, writeMask;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_type_fd_set=yes
else case e in #(
  e) tcl_cv_type_fd_set=no ;;
else
  tcl_cv_type_fd_set=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_type_fd_set" >&5
printf "%s\n" "$tcl_cv_type_fd_set" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_type_fd_set" >&5
$as_echo "$tcl_cv_type_fd_set" >&6; }
tk_ok=$tcl_cv_type_fd_set
if test $tk_ok = no; then
    ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
printf %s "checking how to run the C preprocessor... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fd_mask in sys/select" >&5
$as_echo_n "checking for fd_mask in sys/select... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
  CPP=
fi
if test -z "$CPP"; then
  if test ${ac_cv_prog_CPP+y}
then :
  printf %s "(cached) " >&6
if ${tcl_cv_grep_fd_mask+:} false; then :
  $as_echo_n "(cached) " >&6
else case e in #(
  e)     # Double quotes because $CC needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
    do
      ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :

else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok
then :
  break
fi

    done
    ac_cv_prog_CPP=$CPP
   ;;
esac
fi
  CPP=$ac_cv_prog_CPP
else
  ac_cv_prog_CPP=$CPP
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
printf "%s\n" "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :

else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok
then :

else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See 'config.log' for more details" "$LINENO" 5; } ;;
esac
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep -e" >&5
printf %s "checking for egrep -e... " >&6; }
if test ${ac_cv_path_EGREP_TRADITIONAL+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in grep ggrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" -E 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    :
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi

    if test "$ac_cv_path_EGREP_TRADITIONAL"
then :
  ac_cv_path_EGREP_TRADITIONAL="$ac_cv_path_EGREP_TRADITIONAL -E"
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in egrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi
 ;;
esac
fi ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP_TRADITIONAL" >&5
printf "%s\n" "$ac_cv_path_EGREP_TRADITIONAL" >&6; }
 EGREP_TRADITIONAL=$ac_cv_path_EGREP_TRADITIONAL

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fd_mask in sys/select" >&5
printf %s "checking for fd_mask in sys/select... " >&6; }
if test ${tcl_cv_grep_fd_mask+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/select.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP_TRADITIONAL "fd_mask" >/dev/null 2>&1
  $EGREP "fd_mask" >/dev/null 2>&1; then :
then :
  tcl_cv_grep_fd_mask=present
else case e in #(
  e) tcl_cv_grep_fd_mask=missing ;;
else
  tcl_cv_grep_fd_mask=missing
esac
fi
rm -rf conftest*
 ;;
rm -f conftest*

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_grep_fd_mask" >&5
printf "%s\n" "$tcl_cv_grep_fd_mask" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_grep_fd_mask" >&5
$as_echo "$tcl_cv_grep_fd_mask" >&6; }
    if test $tcl_cv_grep_fd_mask = present; then

printf "%s\n" "#define HAVE_SYS_SELECT_H 1" >>confdefs.h
$as_echo "#define HAVE_SYS_SELECT_H 1" >>confdefs.h

	tk_ok=yes
    fi
fi
if test $tk_ok = no; then

printf "%s\n" "#define NO_FD_SET 1" >>confdefs.h
$as_echo "#define NO_FD_SET 1" >>confdefs.h

fi

#------------------------------------------------------------------------------
#       Find out all about time handling differences.
#------------------------------------------------------------------------------

for ac_header in sys/time.h
do :
  ac_fn_c_check_header_mongrel "$LINENO" "sys/time.h" "ac_cv_header_sys_time_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_time_h" = xyes; then :
  cat >>confdefs.h <<_ACEOF
#define HAVE_SYS_TIME_H 1
_ACEOF

fi

done

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5
$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; }
if ${ac_cv_header_time+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>

int
main ()
{
if ((struct tm *) 0)
return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_cv_header_time=yes
else
  ac_cv_header_time=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5
$as_echo "$ac_cv_header_time" >&6; }
if test $ac_cv_header_time = yes; then

$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h

fi


#--------------------------------------------------------------------
#	Under Solaris 2.4, strtod returns the wrong value for the
#	terminating character under some conditions.  Check for this
#	and if the problem exists use a substitute procedure
#	"fixstrtod" (provided by Tcl) that corrects the error.
#--------------------------------------------------------------------


    ac_fn_c_check_func "$LINENO" "strtod" "ac_cv_func_strtod"
if test "x$ac_cv_func_strtod" = xyes; then :
  tcl_strtod=1
else
  tcl_strtod=0
fi

    if test "$tcl_strtod" = 1; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Solaris2.4/Tru64 strtod bugs" >&5
$as_echo_n "checking for Solaris2.4/Tru64 strtod bugs... " >&6; }
if ${tcl_cv_strtod_buggy+:} false; then :
  $as_echo_n "(cached) " >&6
else

	    if test "$cross_compiling" = yes; then :
  tcl_cv_strtod_buggy=buggy
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		extern double strtod();
		int main() {
		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
		    char *term;
		    double value;
		    value = strtod(infString, &term);
		    if ((term != infString) && (term[-1] == 0)) {
			exit(1);
		    }
		    value = strtod(nanString, &term);
		    if ((term != nanString) && (term[-1] == 0)) {
			exit(1);
		    }
		    value = strtod(spaceString, &term);
		    if (term == (spaceString+1)) {
			exit(1);
		    }
		    exit(0);
		}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
  tcl_cv_strtod_buggy=ok
else
  tcl_cv_strtod_buggy=buggy
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_strtod_buggy" >&5
$as_echo "$tcl_cv_strtod_buggy" >&6; }
	if test "$tcl_cv_strtod_buggy" = buggy; then
	    case " $LIBOBJS " in
  *" fixstrtod.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS fixstrtod.$ac_objext"
 ;;
esac

	    USE_COMPAT=1

$as_echo "#define strtod fixstrtod" >>confdefs.h

	fi
    fi


#--------------------------------------------------------------------
#	Check for various typedefs and provide substitutes if
#	they don't exist.
#--------------------------------------------------------------------

ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
if test "x$ac_cv_type_mode_t" = xyes
if test "x$ac_cv_type_mode_t" = xyes; then :
then :

else case e in #(
  e)
printf "%s\n" "#define mode_t int" >>confdefs.h
 ;;
else

cat >>confdefs.h <<_ACEOF
#define mode_t int
_ACEOF

esac
fi


  ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default
ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
"
if test "x$ac_cv_type_pid_t" = xyes
if test "x$ac_cv_type_pid_t" = xyes; then :
then :

else case e in #(
else
  e)                                         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

          #if defined _WIN64 && !defined __CYGWIN__
          LLP64
          #endif

cat >>confdefs.h <<_ACEOF
int
main (void)
{

#define pid_t int
  ;
  return 0;
}

_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  ac_pid_type='int'
else case e in #(
  e) ac_pid_type='__int64' ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext

printf "%s\n" "#define pid_t $ac_pid_type" >>confdefs.h

     ;;
esac
fi


ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
if test "x$ac_cv_type_size_t" = xyes
then :
if test "x$ac_cv_type_size_t" = xyes; then :

else

cat >>confdefs.h <<_ACEOF
#define size_t unsigned int
_ACEOF

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5
$as_echo_n "checking for uid_t in sys/types.h... " >&6; }
if ${ac_cv_type_uid_t+:} false; then :
  $as_echo_n "(cached) " >&6
else case e in #(
  e)
printf "%s\n" "#define size_t unsigned int" >>confdefs.h
 ;;
esac
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "uid_t" >/dev/null 2>&1; then :
  ac_cv_type_uid_t=yes
else
  ac_cv_type_uid_t=no
fi
rm -f conftest*

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
$as_echo "$ac_cv_type_uid_t" >&6; }
if test $ac_cv_type_uid_t = no; then

$as_echo "#define uid_t int" >>confdefs.h


$as_echo "#define gid_t int" >>confdefs.h

fi


ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "
#include <stdint.h>
ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "$ac_includes_default"
if test "x$ac_cv_type_intptr_t" = xyes; then :


$as_echo "#define HAVE_INTPTR_T 1" >>confdefs.h

else

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pointer-size signed integer type" >&5
$as_echo_n "checking for pointer-size signed integer type... " >&6; }
if ${tcl_cv_intptr_t+:} false; then :
  $as_echo_n "(cached) " >&6
else

    for tcl_cv_intptr_t in "int" "long" "long long" none; do
	if test "$tcl_cv_intptr_t" != none; then
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main ()
{
static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($tcl_cv_intptr_t))];
test_array [0] = 0;
return test_array [0];

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_ok=yes
else
  tcl_ok=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	    test "$tcl_ok" = yes && break; fi
    done
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_intptr_t" >&5
$as_echo "$tcl_cv_intptr_t" >&6; }
    if test "$tcl_cv_intptr_t" != none; then

cat >>confdefs.h <<_ACEOF
#define intptr_t $tcl_cv_intptr_t
_ACEOF
"
if test "x$ac_cv_type_intptr_t" = xyes
then :

    fi

fi

ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default"
if test "x$ac_cv_type_uintptr_t" = xyes; then :


printf "%s\n" "#define HAVE_INTPTR_T 1" >>confdefs.h
$as_echo "#define HAVE_UINTPTR_T 1" >>confdefs.h

else

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pointer-size unsigned integer type" >&5
$as_echo_n "checking for pointer-size unsigned integer type... " >&6; }
if ${tcl_cv_uintptr_t+:} false; then :
  $as_echo_n "(cached) " >&6
else

    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \
	    none; do
	if test "$tcl_cv_uintptr_t" != none; then
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
fi
int
ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "
#include <stdint.h>

"
if test "x$ac_cv_type_uintptr_t" = xyes
then :
main ()
{
static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($tcl_cv_uintptr_t))];
test_array [0] = 0;
return test_array [0];

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_ok=yes
else
  tcl_ok=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	    test "$tcl_ok" = yes && break; fi
    done
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_uintptr_t" >&5
$as_echo "$tcl_cv_uintptr_t" >&6; }
    if test "$tcl_cv_uintptr_t" != none; then

printf "%s\n" "#define HAVE_UINTPTR_T 1" >>confdefs.h
cat >>confdefs.h <<_ACEOF
#define uintptr_t $tcl_cv_uintptr_t
_ACEOF

    fi

fi


#-------------------------------------------
#     In OS/390 struct pwd has no pw_gecos field
#-------------------------------------------

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking pw_gecos in struct pwd" >&5
printf %s "checking pw_gecos in struct pwd... " >&6; }
if test ${tcl_cv_pwd_pw_gecos+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pw_gecos in struct pwd" >&5
$as_echo_n "checking pw_gecos in struct pwd... " >&6; }
if ${tcl_cv_pwd_pw_gecos+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <pwd.h>
int
main (void)
main ()
{
struct passwd pwd; (void)pwd.pw_gecos;
struct passwd pwd; pwd.pw_gecos;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_pwd_pw_gecos=yes
else case e in #(
  e) tcl_cv_pwd_pw_gecos=no ;;
else
  tcl_cv_pwd_pw_gecos=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_pwd_pw_gecos" >&5
printf "%s\n" "$tcl_cv_pwd_pw_gecos" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_pwd_pw_gecos" >&5
$as_echo "$tcl_cv_pwd_pw_gecos" >&6; }
if test $tcl_cv_pwd_pw_gecos = yes; then

printf "%s\n" "#define HAVE_PW_GECOS 1" >>confdefs.h
$as_echo "#define HAVE_PW_GECOS 1" >>confdefs.h

fi

#--------------------------------------------------------------------
#	On Mac OS X, we can build either with X11 or with Aqua
#--------------------------------------------------------------------

if test "`uname -s`" = "Darwin" ; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use Aqua" >&5
printf %s "checking whether to use Aqua... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use Aqua" >&5
$as_echo_n "checking whether to use Aqua... " >&6; }
    # Check whether --enable-aqua was given.
if test ${enable_aqua+y}
if test "${enable_aqua+set}" = set; then :
then :
  enableval=$enable_aqua; tk_aqua=$enableval
else case e in #(
  e) tk_aqua=no ;;
else
  tk_aqua=no
esac
fi

    if test $tk_aqua = yes -o $tk_aqua = cocoa; then
	tk_aqua=yes
	if test $tcl_corefoundation = no; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Aqua can only be used when CoreFoundation is available" >&5
printf "%s\n" "$as_me: WARNING: Aqua can only be used when CoreFoundation is available" >&2;}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Aqua can only be used when CoreFoundation is available" >&5
$as_echo "$as_me: WARNING: Aqua can only be used when CoreFoundation is available" >&2;}
	    tk_aqua=no
	fi
	if test ! -d /System/Library/Frameworks/Cocoa.framework; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Aqua can only be used when Cocoa is available" >&5
printf "%s\n" "$as_me: WARNING: Aqua can only be used when Cocoa is available" >&2;}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Aqua can only be used when Cocoa is available" >&5
$as_echo "$as_me: WARNING: Aqua can only be used when Cocoa is available" >&2;}
	    tk_aqua=no
	fi
	if test "`uname -r | awk -F. '{print $1}'`" -lt 9; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Aqua requires Mac OS X 10.5 or later" >&5
printf "%s\n" "$as_me: WARNING: Aqua requires Mac OS X 10.5 or later" >&2;}
	    tk_aqua=no
	fi
    fi
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tk_aqua" >&5
printf "%s\n" "$tk_aqua" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Aqua requires Mac OS X 10.5 or later" >&5
$as_echo "$as_me: WARNING: Aqua requires Mac OS X 10.5 or later" >&2;}
	    tk_aqua=no
	fi
    fi
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $tk_aqua" >&5
$as_echo "$tk_aqua" >&6; }
    if test "$fat_32_64" = yes; then
	if test $tk_aqua = no; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit X11" >&5
$as_echo_n "checking for 64-bit X11... " >&6; }
if ${tcl_cv_lib_x11_64+:} false; then :
  $as_echo_n "(cached) " >&6
else

		for v in CFLAGS CPPFLAGS LDFLAGS; do
		    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
		done
		CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
		LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
int
main ()
{
XrmInitialize();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  tcl_cv_lib_x11_64=yes
else
  tcl_cv_lib_x11_64=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		for v in CFLAGS CPPFLAGS LDFLAGS; do
		    eval $v'="$hold_'$v'"'
		done
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_x11_64" >&5
$as_echo "$tcl_cv_lib_x11_64" >&6; }
	fi
	# remove 64-bit arch flags from CFLAGS et al. for combined 32 & 64 bit
	# fat builds if configuration does not support 64-bit.
	if test "$tcl_cv_lib_x11_64" = no; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: Removing 64-bit architectures from compiler & linker flags" >&5
$as_echo "$as_me: Removing 64-bit architectures from compiler & linker flags" >&6;}
	    for v in CFLAGS CPPFLAGS LDFLAGS; do
		eval $v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
	    done
	fi
    fi
    if test $tk_aqua = no; then
	# check if weak linking whole libraries is possible.
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ld accepts -weak-l flag" >&5
printf %s "checking if ld accepts -weak-l flag... " >&6; }
if test ${tcl_cv_ld_weak_l+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -weak-l flag" >&5
$as_echo_n "checking if ld accepts -weak-l flag... " >&6; }
if ${tcl_cv_ld_weak_l+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	    hold_ldflags=$LDFLAGS
	    LDFLAGS="$LDFLAGS -Wl,-weak-lm"
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <math.h>
int
main (void)
main ()
{
double f = sin(1.0);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_ld_weak_l=yes
else case e in #(
  e) tcl_cv_ld_weak_l=no ;;
else
  tcl_cv_ld_weak_l=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
	    LDFLAGS=$hold_ldflags ;;
	    LDFLAGS=$hold_ldflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_weak_l" >&5
printf "%s\n" "$tcl_cv_ld_weak_l" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_weak_l" >&5
$as_echo "$tcl_cv_ld_weak_l" >&6; }
    fi
    for ac_header in AvailabilityMacros.h
do :
    ac_fn_c_check_header_compile "$LINENO" "AvailabilityMacros.h" "ac_cv_header_AvailabilityMacros_h" "$ac_includes_default"
if test "x$ac_cv_header_AvailabilityMacros_h" = xyes
  ac_fn_c_check_header_mongrel "$LINENO" "AvailabilityMacros.h" "ac_cv_header_AvailabilityMacros_h" "$ac_includes_default"
if test "x$ac_cv_header_AvailabilityMacros_h" = xyes; then :
then :
  printf "%s\n" "#define HAVE_AVAILABILITYMACROS_H 1" >>confdefs.h
  cat >>confdefs.h <<_ACEOF
#define HAVE_AVAILABILITYMACROS_H 1
_ACEOF

fi

done

    if test "$ac_cv_header_AvailabilityMacros_h" = yes; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if weak import is available" >&5
printf %s "checking if weak import is available... " >&6; }
if test ${tcl_cv_cc_weak_import+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if weak import is available" >&5
$as_echo_n "checking if weak import is available... " >&6; }
if ${tcl_cv_cc_weak_import+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
		    #endif
		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1020
		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1020
		    #endif
		    int rand(void) __attribute__((weak_import));

int
main (void)
main ()
{
rand();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_cc_weak_import=yes
else case e in #(
  e) tcl_cv_cc_weak_import=no ;;
else
  tcl_cv_cc_weak_import=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
	    CFLAGS=$hold_cflags ;;
	    CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_weak_import" >&5
printf "%s\n" "$tcl_cv_cc_weak_import" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_weak_import" >&5
$as_echo "$tcl_cv_cc_weak_import" >&6; }
	if test $tcl_cv_cc_weak_import = yes; then

printf "%s\n" "#define HAVE_WEAK_IMPORT 1" >>confdefs.h
$as_echo "#define HAVE_WEAK_IMPORT 1" >>confdefs.h

	fi
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if Darwin SUSv3 extensions are available" >&5
printf %s "checking if Darwin SUSv3 extensions are available... " >&6; }
if test ${tcl_cv_cc_darwin_c_source+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if Darwin SUSv3 extensions are available" >&5
$as_echo_n "checking if Darwin SUSv3 extensions are available... " >&6; }
if ${tcl_cv_cc_darwin_c_source+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
		    #endif
		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1050
		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1050
		    #endif
		    #define _DARWIN_C_SOURCE 1
		    #include <sys/cdefs.h>

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_cc_darwin_c_source=yes
else case e in #(
  e) tcl_cv_cc_darwin_c_source=no ;;
else
  tcl_cv_cc_darwin_c_source=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	    CFLAGS=$hold_cflags ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	    CFLAGS=$hold_cflags
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_darwin_c_source" >&5
printf "%s\n" "$tcl_cv_cc_darwin_c_source" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_darwin_c_source" >&5
$as_echo "$tcl_cv_cc_darwin_c_source" >&6; }
	if test $tcl_cv_cc_darwin_c_source = yes; then

printf "%s\n" "#define _DARWIN_C_SOURCE 1" >>confdefs.h
$as_echo "#define _DARWIN_C_SOURCE 1" >>confdefs.h

	fi
    fi
else
    tk_aqua=no
fi

if test $tk_aqua = yes; then

printf "%s\n" "#define MAC_OSX_TK 1" >>confdefs.h
$as_echo "#define MAC_OSX_TK 1" >>confdefs.h

    LIBS="$LIBS -framework Cocoa -framework Carbon -framework IOKit -framework QuartzCore -framework Security -framework CoreGraphics"
    LIBS="$LIBS -framework Cocoa -framework Carbon -framework IOKit"
    if test -d /System/Library/Frameworks/UserNotifications.framework; then
        LIBS="$LIBS -framework UserNotifications"
    fi
    if test -d "/System/Library/Frameworks/UniformTypeIdentifiers.framework"; then
        LIBS="$LIBS -weak_framework UniformTypeIdentifiers"
    fi
    EXTRA_CC_SWITCHES='-x objective-c'
    EXTRA_CC_SWITCHES='-std=gnu99 -x objective-c'
    TK_WINDOWINGSYSTEM=AQUA
    if test -n "${enable_symbols}" -a "${enable_symbols}" != no; then

printf "%s\n" "#define TK_MAC_DEBUG 1" >>confdefs.h
$as_echo "#define TK_MAC_DEBUG 1" >>confdefs.h

    fi
else
    #--------------------------------------------------------------------
    #	Locate the X11 header files and the X11 library archive.  Try
    #	the ac_path_x macro first, but if it doesn't find the X stuff
    #	(e.g. because there's no xmkmf program) then check through
    #	a list of possible directories.  Under some conditions the
    #	autoconf macro will return an include directory that contains
    #	no include files, so double-check its result just to be safe.
    #--------------------------------------------------------------------


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for X" >&5
printf %s "checking for X... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for X" >&5
$as_echo_n "checking for X... " >&6; }


# Check whether --with-x was given.
if test ${with_x+y}
if test "${with_x+set}" = set; then :
then :
  withval=$with_x;
fi

# $have_x is 'yes', 'no', 'disabled', or empty when we do not yet know.
# $have_x is `yes', `no', `disabled', or empty when we do not yet know.
if test "x$with_x" = xno; then
  # The user explicitly disabled X.
  have_x=disabled
else
  case $x_includes,$x_libraries in #(
    *\'*) as_fn_error $? "cannot use X directory names containing '" "$LINENO" 5;; #(
    *,NONE | NONE,*) if test ${ac_cv_have_x+y}
    *,NONE | NONE,*) if ${ac_cv_have_x+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) # One or both of the vars are not set, and there is no cached value.
ac_x_includes=no
  $as_echo_n "(cached) " >&6
else
  # One or both of the vars are not set, and there is no cached value.
ac_x_includes=no ac_x_libraries=no
ac_x_libraries=no
# Do we need to do anything special at all?
ac_save_LIBS=$LIBS
LIBS="-lX11 $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
int
main (void)
{
XrmInitialize ()
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
then :
  # We can compile and link X programs with no special options.
  ac_x_includes=
  ac_x_libraries=
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS="$ac_save_LIBS"
# If that didn't work, only try xmkmf and file system searches
# for native compilation.
if test x"$ac_x_includes" = xno && test "$cross_compiling" = no
then :
  rm -f -r conftest.dir
rm -f -r conftest.dir
if mkdir conftest.dir; then
  cd conftest.dir
  cat >Imakefile <<'_ACEOF'
incroot:
	@echo incroot='${INCROOT}'
usrlibdir:
	@echo usrlibdir='${USRLIBDIR}'
8009
8010
8011
8012
8013
8014
8015
8016

8017
8018
8019
8020
8021
8022
8023
7641
7642
7643
7644
7645
7646
7647

7648
7649
7650
7651
7652
7653
7654
7655







-
+







	*) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
    esac
  fi
  cd ..
  rm -f -r conftest.dir
fi

  # Standard set of common directories for X headers.
# Standard set of common directories for X headers.
# Check X11 before X11Rn because it is often a symlink to the current release.
ac_x_header_dirs='
/usr/X11/include
/usr/X11R7/include
/usr/X11R6/include
/usr/X11R5/include
/usr/X11R4/include
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
7668
7669
7670
7671
7672
7673
7674


7675
7676
7677
7678
7679
7680
7681







-
-








/usr/local/include/X11
/usr/local/include/X11R7
/usr/local/include/X11R6
/usr/local/include/X11R5
/usr/local/include/X11R4

/opt/X11/include

/usr/X386/include
/usr/x386/include
/usr/XFree86/include/X11

/usr/include
/usr/local/include
/usr/unsupported/include
8059
8060
8061
8062
8063
8064
8065
8066

8067
8068
8069
8070
8071


8072
8073
8074
8075
8076

8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092

8093
8094
8095
8096
8097
8098
8099

8100
8101
8102
8103
8104
8105
8106



8107
8108
8109
8110
8111
8112
8113
8114
8115

8116
8117
8118

8119
8120
8121
8122
8123
8124
8125

8126
8127
8128


8129
8130
8131
8132

8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144


8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155


8156
8157
8158
8159
8160
8161
8162
8163
8164
8165

8166
8167
8168
8169


8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181


8182
8183
8184
8185
8186
8187

8188
8189
8190
8191


8192
8193
8194
8195
8196
8197
8198
8199
8200


8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215


8216
8217
8218
8219
8220


8221
8222
8223
8224
8225
8226


8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242



8243
8244
8245
8246



8247
8248
8249
8250
8251
8252
8253

8254
8255
8256
8257
8258
8259
8260

8261
8262

8263
8264
8265
8266
8267
8268
8269

8270
8271
8272
8273


8274
8275
8276

8277
8278

8279
8280
8281
8282
8283



8284
8285
8286
8287
8288
8289
8290
8291


8292
8293
8294
8295
8296
8297
8298
7689
7690
7691
7692
7693
7694
7695

7696

7697
7698


7699
7700
7701
7702
7703
7704

7705

7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719

7720
7721
7722
7723
7724
7725
7726

7727

7728
7729
7730



7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741

7742

7743

7744
7745
7746
7747


7748

7749
7750


7751
7752
7753
7754
7755

7756

7757
7758
7759
7760
7761
7762
7763
7764
7765


7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776


7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787

7788

7789


7790
7791

7792
7793
7794
7795
7796
7797
7798
7799
7800


7801
7802
7803
7804
7805
7806
7807

7808

7809


7810
7811

7812
7813
7814
7815
7816
7817


7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832


7833
7834
7835
7836
7837


7838
7839
7840
7841
7842
7843


7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858



7859
7860
7861




7862
7863
7864
7865
7866
7867
7868
7869
7870

7871



7872
7873
7874

7875
7876

7877
7878
7879
7880
7881
7882
7883

7884

7885


7886
7887

7888

7889
7890

7891

7892



7893
7894
7895

7896
7897
7898
7899
7900


7901
7902
7903
7904
7905
7906
7907
7908
7909







-
+
-


-
-
+
+




-
+
-














-
+






-
+
-



-
-
-
+
+
+








-
+
-

-
+



-
-

-
+

-
-
+
+



-
+
-









-
-
+
+









-
-
+
+









-
+
-

-
-
+
+
-









-
-
+
+





-
+
-

-
-
+
+
-






-
-
+
+













-
-
+
+



-
-
+
+




-
-
+
+













-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-





-
-
+
+







if test "$ac_x_includes" = no; then
  # Guess where to find include files, by looking for Xlib.h.
  # First, try using that file with no special directory specified.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
if ac_fn_c_try_cpp "$LINENO"; then :
then :
  # We can compile using X headers with no special include directory.
ac_x_includes=
else case e in #(
  e) for ac_dir in $ac_x_header_dirs; do
else
  for ac_dir in $ac_x_header_dirs; do
  if test -r "$ac_dir/X11/Xlib.h"; then
    ac_x_includes=$ac_dir
    break
  fi
done ;;
done
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext
fi # $ac_x_includes = no

if test "$ac_x_libraries" = no; then
  # Check for the libraries.
  # See if we find them without any special options.
  # Don't add to $LIBS permanently.
  ac_save_LIBS=$LIBS
  LIBS="-lX11 $LIBS"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
int
main (void)
main ()
{
XrmInitialize ()
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  LIBS=$ac_save_LIBS
# We can link X programs with no special library path.
ac_x_libraries=
else case e in #(
  e) LIBS=$ac_save_LIBS
for ac_dir in `printf "%s\n" "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g`
else
  LIBS=$ac_save_LIBS
for ac_dir in `$as_echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g`
do
  # Don't even attempt the hair of trying to link an X program!
  for ac_extension in a so sl dylib la dll; do
    if test -r "$ac_dir/libX11.$ac_extension"; then
      ac_x_libraries=$ac_dir
      break 2
    fi
  done
done ;;
done
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
fi # $ac_x_libraries = no

fi
# Record the results.
case $ac_x_includes,$ac_x_libraries in #(
  no,* | *,no | *\'*) :
  no,* | *,no | *\'*)
    # Didn't find X, or a directory has "'" in its name.
    ac_cv_have_x="have_x=no" ;; #(
  *) :
    ac_cv_have_x="have_x=no";; #(
  *)
    # Record where we found X for the cache.
    ac_cv_have_x="have_x=yes\
	ac_x_includes='$ac_x_includes'\
	ac_x_libraries='$ac_x_libraries'" ;;
	ac_x_libraries='$ac_x_libraries'"
esac ;;
esac
fi
;; #(
    *) have_x=yes;;
  esac
  eval "$ac_cv_have_x"
fi # $with_x != no

if test "$have_x" != yes; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $have_x" >&5
printf "%s\n" "$have_x" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_x" >&5
$as_echo "$have_x" >&6; }
  no_x=yes
else
  # If each of the values was on the command line, it overrides each guess.
  test "x$x_includes" = xNONE && x_includes=$ac_x_includes
  test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
  # Update the cache value to reflect the command line values.
  ac_cv_have_x="have_x=yes\
	ac_x_includes='$x_includes'\
	ac_x_libraries='$x_libraries'"
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: libraries $x_libraries, headers $x_includes" >&5
printf "%s\n" "libraries $x_libraries, headers $x_includes" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: libraries $x_libraries, headers $x_includes" >&5
$as_echo "libraries $x_libraries, headers $x_includes" >&6; }
fi

    not_really_there=""
    if test "$no_x" = ""; then
	if test "$x_includes" = ""; then
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
if ac_fn_c_try_cpp "$LINENO"; then :
then :

else case e in #(
  e) not_really_there="yes" ;;
else
  not_really_there="yes"
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext
	else
	    if test ! -r $x_includes/X11/Xlib.h; then
		not_really_there="yes"
	    fi
	fi
    fi
    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for X11 header files" >&5
printf %s "checking for X11 header files... " >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for X11 header files" >&5
$as_echo_n "checking for X11 header files... " >&6; }
	found_xincludes="no"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
if ac_fn_c_try_cpp "$LINENO"; then :
then :
  found_xincludes="yes"
else case e in #(
  e) found_xincludes="no" ;;
else
  found_xincludes="no"
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext
	if test "$found_xincludes" = "no"; then
	    dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/X11R6/include /usr/X11R5/include /usr/include/X11R5 /usr/include/X11R4 /usr/openwin/include /usr/X11/include /usr/sww/include"
	    for i in $dirs ; do
		if test -r $i/X11/Xlib.h; then
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $i" >&5
printf "%s\n" "$i" >&6; }
		    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $i" >&5
$as_echo "$i" >&6; }
		    XINCLUDES=" -I$i"
		    found_xincludes="yes"
		    break
		fi
	    done
	fi
    else
	if test "$x_includes" != ""; then
	    XINCLUDES="-I$x_includes"
	    found_xincludes="yes"
	fi
    fi
    if test "$found_xincludes" = "no"; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: couldn't find any!" >&5
printf "%s\n" "couldn't find any!" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: couldn't find any!" >&5
$as_echo "couldn't find any!" >&6; }
    fi

    if test "$no_x" = yes; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for X11 libraries" >&5
printf %s "checking for X11 libraries... " >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for X11 libraries" >&5
$as_echo_n "checking for X11 libraries... " >&6; }
	XLIBSW=nope
	dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/X11R6/lib /usr/X11R5/lib /usr/lib/X11R5 /usr/lib/X11R4 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib"
	for i in $dirs ; do
	    if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl -o -r $i/libX11.dylib; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $i" >&5
printf "%s\n" "$i" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $i" >&5
$as_echo "$i" >&6; }
		XLIBSW="-L$i -lX11"
		x_libraries="$i"
		break
	    fi
	done
    else
	if test "$x_libraries" = ""; then
	    XLIBSW=-lX11
	else
	    XLIBSW="-L$x_libraries -lX11"
	fi
    fi
    if test "$XLIBSW" = nope ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for XCreateWindow in -lXwindow" >&5
printf %s "checking for XCreateWindow in -lXwindow... " >&6; }
if test ${ac_cv_lib_Xwindow_XCreateWindow+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XCreateWindow in -lXwindow" >&5
$as_echo_n "checking for XCreateWindow in -lXwindow... " >&6; }
if ${ac_cv_lib_Xwindow_XCreateWindow+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lXwindow  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char XCreateWindow (void);
char XCreateWindow ();
int
main (void)
main ()
{
return XCreateWindow ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_Xwindow_XCreateWindow=yes
else case e in #(
  e) ac_cv_lib_Xwindow_XCreateWindow=no ;;
else
  ac_cv_lib_Xwindow_XCreateWindow=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xwindow_XCreateWindow" >&5
printf "%s\n" "$ac_cv_lib_Xwindow_XCreateWindow" >&6; }
if test "x$ac_cv_lib_Xwindow_XCreateWindow" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xwindow_XCreateWindow" >&5
$as_echo "$ac_cv_lib_Xwindow_XCreateWindow" >&6; }
if test "x$ac_cv_lib_Xwindow_XCreateWindow" = xyes; then :
then :
  XLIBSW=-lXwindow
fi

    fi
    if test "$XLIBSW" = nope ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: could not find any!  Using -lX11." >&5
printf "%s\n" "could not find any!  Using -lX11." >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find any!  Using -lX11." >&5
$as_echo "could not find any!  Using -lX11." >&6; }
	XLIBSW=-lX11
    fi

    TK_WINDOWINGSYSTEM=X11
fi

#--------------------------------------------------------------------
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342



8343
8344
8345
8346



8347
8348
8349
8350
8351
8352
8353

8354
8355
8356
8357
8358
8359
8360

8361
8362
8363
8364


8365
8366
8367

8368
8369

8370
8371
8372
8373
8374



8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394


8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405

8406
8407
8408
8409
8410
8411
8412
8413
8414

8415
8416
8417
8418


8419
8420
8421
8422
8423
8424



8425
8426
8427

8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439


8440
8441

8442
8443
8444
8445


8446
8447
8448
8449
8450
8451
8452
8453


8454
8455
8456
8457
8458
8459
8460
8461


8462
8463
8464


8465
8466
8467
8468
8469
8470
8471
8472

8473
8474
8475
8476


8477
8478

8479
8480

8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492



8493
8494
8495
8496



8497
8498
8499
8500
8501
8502
8503

8504
8505
8506
8507
8508
8509
8510

8511
8512

8513
8514
8515
8516
8517
8518
8519

8520
8521
8522
8523


8524
8525
8526

8527
8528

8529
8530
8531
8532
8533



8534
8535



8536
8537
8538
8539
8540


8541
8542

8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556



8557
8558
8559
8560



8561
8562
8563
8564
8565
8566
8567

8568
8569
8570
8571
8572
8573
8574

8575
8576

8577
8578
8579
8580
8581
8582
8583

8584
8585
8586
8587


8588
8589
8590

8591
8592

8593
8594
8595
8596
8597



8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610


8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622

8623
8624
8625
8626
8627
8628
8629
8630




























































































































8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649


8650
8651

8652
8653
8654
8655


8656
8657
8658
8659
8660
8661


8662
8663
8664


8665
8666
8667

8668
8669
8670
8671
8672
8673

8674
8675

8676
8677
8678
8679
8680
8681
8682





8683
8684
8685
8686



8687
8688
8689
8690
8691
8692
8693

8694
8695
8696
8697
8698
8699
8700

8701
8702

8703
8704
8705
8706
8707
8708
8709

8710
8711
8712
8713


8714
8715
8716

8717
8718

8719
8720
8721
8722
8723



8724
8725
8726
8727
8728
8729
8730
8731
8732
8733





8734
8735
8736
8737



8738
8739
8740
8741
8742
8743
8744

8745
8746
8747
8748
8749
8750
8751

8752
8753

8754
8755
8756
8757
8758
8759
8760

8761
8762
8763
8764


8765
8766
8767

8768
8769

8770
8771
8772
8773
8774



8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788

8789
8790
8791
8792

8793
8794
8795
8796
8797
8798
8799

8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813



8814
8815
8816
8817



8818
8819
8820
8821

8822
8823
8824
8825
8826
8827
8828
8829
8830
8831

8832
8833
8834
8835


8836
8837
8838

8839
8840
8841
8842
8843
8844




8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874

8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890


8891
8892

8893
8894
8895
8896


8897
8898
8899
8900
8901
8902
8903


8904
8905
8906
8907
8908


8909
8910
8911
8912
8913
8914


8915
8916
8917
8918
8919


8920
8921
8922


8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935

8936
8937

8938
8939
8940
8941
8942
8943
8944
8945

8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957

8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006

9007
9008
9009
9010

9011
9012

9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232








9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
7944
7945
7946
7947
7948
7949
7950



7951
7952
7953




7954
7955
7956
7957
7958
7959
7960
7961
7962

7963
7964
7965
7966
7967
7968
7969

7970

7971


7972
7973

7974

7975
7976

7977

7978



7979
7980
7981

7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998


7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010

8011
8012
8013
8014
8015
8016
8017
8018
8019

8020

8021


8022
8023
8024
8025
8026



8027
8028
8029

8030

8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041


8042
8043
8044

8045

8046


8047
8048

8049
8050
8051
8052
8053


8054
8055
8056
8057
8058
8059
8060
8061


8062
8063
8064


8065
8066
8067
8068
8069
8070
8071
8072
8073

8074

8075


8076
8077
8078

8079

8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090



8091
8092
8093




8094
8095
8096
8097
8098
8099
8100
8101
8102

8103



8104
8105
8106

8107
8108

8109
8110
8111
8112
8113
8114
8115

8116

8117


8118
8119

8120

8121
8122

8123

8124



8125
8126
8127


8128
8129
8130
8131
8132
8133


8134
8135
8136

8137

8138
8139
8140
8141
8142
8143
8144
8145
8146
8147



8148
8149
8150




8151
8152
8153
8154
8155
8156
8157
8158
8159

8160



8161
8162
8163

8164
8165

8166
8167
8168
8169
8170
8171
8172

8173

8174


8175
8176

8177

8178
8179

8180

8181



8182
8183
8184

8185
8186
8187
8188
8189
8190
8191
8192
8193
8194


8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207

8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357


8358
8359
8360

8361

8362


8363
8364

8365
8366
8367


8368
8369
8370


8371
8372
8373
8374

8375

8376
8377
8378
8379
8380
8381
8382

8383

8384





8385
8386
8387
8388
8389




8390
8391
8392
8393
8394
8395
8396
8397
8398

8399



8400
8401
8402

8403
8404

8405
8406
8407
8408
8409
8410
8411

8412

8413


8414
8415

8416

8417
8418

8419

8420



8421
8422
8423

8424
8425
8426
8427





8428
8429
8430
8431
8432




8433
8434
8435
8436
8437
8438
8439
8440
8441

8442



8443
8444
8445

8446
8447

8448
8449
8450
8451
8452
8453
8454

8455

8456


8457
8458

8459

8460
8461

8462

8463



8464
8465
8466

8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478

8479

8480
8481

8482

8483
8484
8485
8486
8487

8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499



8500
8501
8502




8503
8504
8505
8506
8507
8508

8509
8510
8511
8512
8513
8514
8515
8516
8517
8518

8519

8520


8521
8522

8523

8524

8525




8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540


8541




8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552

8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567


8568
8569
8570

8571

8572


8573
8574

8575
8576
8577
8578


8579
8580
8581
8582
8583


8584
8585
8586
8587
8588
8589


8590
8591
8592
8593
8594


8595
8596
8597


8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609



8610


8611
8612
8613
8614
8615
8616
8617
8618

8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629


8630





8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644

8645
8646
8647
8648
8649
8650
8651
8652
8653

8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666




8667

8668
8669
8670
8671

8672
8673

8674
8675
8676
8677
8678
8679













































































































































































































8680
8681
8682
8683
8684
8685
8686



8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702













8703
8704
8705
8706
8707
8708


8709
8710
8711
8712
8713
8714
8715







-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-

















-
-
+
+










-
+








-
+
-

-
-
+
+



-
-
-
+
+
+
-

-
+










-
-
+
+

-
+
-

-
-
+
+
-





-
-
+
+






-
-
+
+

-
-
+
+







-
+
-

-
-
+
+

-
+
-

+









-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-
-
+
+
+



-
-
+
+

-
+
-










-
-
-
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-










-
-
+
+











-
+








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

















-
-
+
+

-
+
-

-
-
+
+
-



-
-
+
+

-
-
+
+


-
+
-





+

-
+
-

-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-




-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+






-
+
-
-
-



-
+

-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
-
+
+
+
-












-
+
-


-
+
-





-
+











-
-
-
+
+
+
-
-
-
-
+
+
+



-
+









-
+
-

-
-
+
+
-

-
+
-

-
-
-
-
+
+
+
+











-
-

-
-
-
-











-
+














-
-
+
+

-
+
-

-
-
+
+
-




-
-
+
+



-
-
+
+




-
-
+
+



-
-
+
+

-
-
+
+










-
-
-
+
-
-
+







-
+










-
-
+
-
-
-
-
-














-









-













-
-
-
-

-
+



-
+

-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
+
+
+
+
+
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-






-
-







#	   bogus:  they goof up name resolution if used.
#	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
#	   To get around this problem, check for both libraries together
#	   if -lsocket doesn't work by itself.
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for main in -lXbsd" >&5
printf %s "checking for main in -lXbsd... " >&6; }
if test ${ac_cv_lib_Xbsd_main+y}
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lXbsd" >&5
$as_echo_n "checking for main in -lXbsd... " >&6; }
if ${ac_cv_lib_Xbsd_main+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lXbsd  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */


int
main (void)
main ()
{
return main ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_Xbsd_main=yes
else case e in #(
  e) ac_cv_lib_Xbsd_main=no ;;
else
  ac_cv_lib_Xbsd_main=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xbsd_main" >&5
printf "%s\n" "$ac_cv_lib_Xbsd_main" >&6; }
if test "x$ac_cv_lib_Xbsd_main" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xbsd_main" >&5
$as_echo "$ac_cv_lib_Xbsd_main" >&6; }
if test "x$ac_cv_lib_Xbsd_main" = xyes; then :
then :
  LIBS="$LIBS -lXbsd"
fi

fi

#--------------------------------------------------------------------
# One more check related to the X libraries.  The standard releases
# of Ultrix don't support the "xauth" mechanism, so send won't work
# unless TK_NO_SECURITY is defined.  However, there are usually copies
# of the MIT X server available as well, which do support xauth.
# Check for the MIT stuff and use it if it exists.
#
# Note: can't use ac_check_lib macro (at least, not in Autoconf 2.1)
# because it can't deal with the "-" in the library name.
#--------------------------------------------------------------------

if test -d /usr/include/mit -a $tk_aqua = no; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking MIT X libraries" >&5
printf %s "checking MIT X libraries... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking MIT X libraries" >&5
$as_echo_n "checking MIT X libraries... " >&6; }
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS -I/usr/include/mit"
    tk_oldLibs=$LIBS
    LIBS="$LIBS -lX11-mit"
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	#include <X11/Xlib.h>

int
main (void)
main ()
{

	XOpenDisplay(0);

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	XLIBSW="-lX11-mit"
	XINCLUDES="-I/usr/include/mit"

else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; } ;;
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#--------------------------------------------------------------------
#	Check for freetype / fontconfig / Xft support.
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use xft" >&5
printf %s "checking whether to use xft... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use xft" >&5
$as_echo_n "checking whether to use xft... " >&6; }
    # Check whether --enable-xft was given.
if test ${enable_xft+y}
if test "${enable_xft+set}" = set; then :
then :
  enableval=$enable_xft; enable_xft=$enableval
else case e in #(
  e) enable_xft="default" ;;
else
  enable_xft="default"
esac
fi

    XFT_CFLAGS=""
    XFT_LIBS=""
    if test "$enable_xft" = "no" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_xft" >&5
printf "%s\n" "$enable_xft" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_xft" >&5
$as_echo "$enable_xft" >&6; }
    else
	found_xft="yes"
			XFT_CFLAGS=`xft-config --cflags 2>/dev/null` || found_xft="no"
	XFT_LIBS=`xft-config --libs 2>/dev/null` || found_xft="no"
	if test "$found_xft" = "no" ; then
	    found_xft=yes
	    XFT_CFLAGS=`pkg-config --cflags xft fontconfig 2>/dev/null` || found_xft="no"
	    XFT_LIBS=`pkg-config --libs xft fontconfig 2>/dev/null` || found_xft="no"
	    XFT_CFLAGS=`pkg-config --cflags xft 2>/dev/null` || found_xft="no"
	    XFT_LIBS=`pkg-config --libs xft 2>/dev/null` || found_xft="no"
	fi
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $found_xft" >&5
printf "%s\n" "$found_xft" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $found_xft" >&5
$as_echo "$found_xft" >&6; }
		if test "$found_xft" = "yes" ; then
	    tk_oldCFlags=$CFLAGS
	    CFLAGS="$CFLAGS $XINCLUDES $XFT_CFLAGS"
	    tk_oldLibs=$LIBS
	    LIBS="$tk_oldLIBS $XFT_LIBS $XLIBSW"
	    ac_fn_c_check_header_compile "$LINENO" "X11/Xft/Xft.h" "ac_cv_header_X11_Xft_Xft_h" "#include <X11/Xlib.h>
"
if test "x$ac_cv_header_X11_Xft_Xft_h" = xyes
if test "x$ac_cv_header_X11_Xft_Xft_h" = xyes; then :
then :

else case e in #(
  e)
else

		found_xft=no
	     ;;

esac
fi


	    CFLAGS=$tk_oldCFlags
	    LIBS=$tk_oldLibs
	fi
		if test "$found_xft" = "yes" ; then
	    tk_oldCFlags=$CFLAGS
	    CFLAGS="$CFLAGS $XINCLUDES $XFT_CFLAGS"
	    tk_oldLibs=$LIBS
	    LIBS="$tk_oldLIBS $XFT_LIBS $XLIBSW"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for XftFontOpen in -lXft" >&5
printf %s "checking for XftFontOpen in -lXft... " >&6; }
if test ${ac_cv_lib_Xft_XftFontOpen+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XftFontOpen in -lXft" >&5
$as_echo_n "checking for XftFontOpen in -lXft... " >&6; }
if ${ac_cv_lib_Xft_XftFontOpen+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lXft  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char XftFontOpen (void);
char XftFontOpen ();
int
main (void)
main ()
{
return XftFontOpen ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_Xft_XftFontOpen=yes
else case e in #(
  e) ac_cv_lib_Xft_XftFontOpen=no ;;
else
  ac_cv_lib_Xft_XftFontOpen=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xft_XftFontOpen" >&5
printf "%s\n" "$ac_cv_lib_Xft_XftFontOpen" >&6; }
if test "x$ac_cv_lib_Xft_XftFontOpen" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xft_XftFontOpen" >&5
$as_echo "$ac_cv_lib_Xft_XftFontOpen" >&6; }
if test "x$ac_cv_lib_Xft_XftFontOpen" = xyes; then :
then :
  printf "%s\n" "#define HAVE_LIBXFT 1" >>confdefs.h
  cat >>confdefs.h <<_ACEOF
#define HAVE_LIBXFT 1
_ACEOF

  LIBS="-lXft $LIBS"

else case e in #(
  e)
else

		found_xft=no
	     ;;

esac
fi

	    CFLAGS=$tk_oldCFlags
	    LIBS=$tk_oldLibs
	fi
		if test "$found_xft" = "yes" ; then
	    tk_oldCFlags=$CFLAGS
	    CFLAGS="$CFLAGS $XINCLUDES $XFT_CFLAGS"
	    tk_oldLibs=$LIBS
	    LIBS="$tk_oldLIBS $XFT_LIBS $XLIBSW -lfontconfig"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for FcFontSort in -lfontconfig" >&5
printf %s "checking for FcFontSort in -lfontconfig... " >&6; }
if test ${ac_cv_lib_fontconfig_FcFontSort+y}
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FcFontSort in -lfontconfig" >&5
$as_echo_n "checking for FcFontSort in -lfontconfig... " >&6; }
if ${ac_cv_lib_fontconfig_FcFontSort+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lfontconfig  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char FcFontSort (void);
char FcFontSort ();
int
main (void)
main ()
{
return FcFontSort ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_fontconfig_FcFontSort=yes
else case e in #(
  e) ac_cv_lib_fontconfig_FcFontSort=no ;;
else
  ac_cv_lib_fontconfig_FcFontSort=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fontconfig_FcFontSort" >&5
printf "%s\n" "$ac_cv_lib_fontconfig_FcFontSort" >&6; }
if test "x$ac_cv_lib_fontconfig_FcFontSort" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fontconfig_FcFontSort" >&5
$as_echo "$ac_cv_lib_fontconfig_FcFontSort" >&6; }
if test "x$ac_cv_lib_fontconfig_FcFontSort" = xyes; then :
then :

		XFT_LIBS="$XFT_LIBS -lfontconfig"

fi

	    CFLAGS=$tk_oldCFlags
	    LIBS=$tk_oldLibs
	fi
		if test "$found_xft" = "no" ; then
	    if test "$enable_xft" = "yes" ; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Can't find xft configuration, or xft is unusable" >&5
printf "%s\n" "$as_me: WARNING: Can't find xft configuration, or xft is unusable" >&2;}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Can't find xft configuration, or xft is unusable" >&5
$as_echo "$as_me: WARNING: Can't find xft configuration, or xft is unusable" >&2;}
	    fi
	    enable_xft=no
	    XFT_CFLAGS=""
	    XFT_LIBS=""
	else
            enable_xft=yes
	fi
    fi
    if test $enable_xft = "yes" ; then
	UNIX_FONT_OBJS=tkUnixRFont.o

printf "%s\n" "#define HAVE_XFT 1" >>confdefs.h
$as_echo "#define HAVE_XFT 1" >>confdefs.h

    else
	UNIX_FONT_OBJS=tkUnixFont.o
    fi



fi

#--------------------------------------------------------------------
#	Check for XkbKeycodeToKeysym.
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    tk_oldCFlags=$CFLAGS
    tk_oldLibs=$LIBS
    CFLAGS="$CFLAGS $XINCLUDES"
    LIBS="$LIBS $XLIBSW"
    ac_fn_c_check_header_compile "$LINENO" "X11/XKBlib.h" "ac_cv_header_X11_XKBlib_h" "#include <X11/Xlib.h>
"
if test "x$ac_cv_header_X11_XKBlib_h" = xyes; then :

	xkblib_header_found=yes

else

	xkblib_header_found=no

fi


    if test $xkblib_header_found = "yes" ; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XkbKeycodeToKeysym in -lX11" >&5
$as_echo_n "checking for XkbKeycodeToKeysym in -lX11... " >&6; }
if ${ac_cv_lib_X11_XkbKeycodeToKeysym+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lX11  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char XkbKeycodeToKeysym ();
int
main ()
{
return XkbKeycodeToKeysym ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_lib_X11_XkbKeycodeToKeysym=yes
else
  ac_cv_lib_X11_XkbKeycodeToKeysym=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_X11_XkbKeycodeToKeysym" >&5
$as_echo "$ac_cv_lib_X11_XkbKeycodeToKeysym" >&6; }
if test "x$ac_cv_lib_X11_XkbKeycodeToKeysym" = xyes; then :

	    xkbkeycodetokeysym_found=yes

else

	    xkbkeycodetokeysym_found=no

fi

    else
	xkbkeycodetokeysym_found=no
    fi
    if test $xkbkeycodetokeysym_found = "yes" ; then

$as_echo "#define HAVE_XKBKEYCODETOKEYSYM 1" >>confdefs.h

    fi
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#--------------------------------------------------------------------
# Check whether XKeycodeToKeysym is deprecated in X11 headers.
#--------------------------------------------------------------------

if test $tk_aqua = no && test "$GCC" = yes; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether XKeycodeToKeysym is deprecated" >&5
$as_echo_n "checking whether XKeycodeToKeysym is deprecated... " >&6; }
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS -Werror"
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	#include <X11/Xlib.h>

int
main ()
{

	XKeycodeToKeysym(0,0,0);

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :

	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }

else

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

$as_echo "#define XKEYCODETOKEYSYM_IS_DEPRECATED 1" >>confdefs.h


fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
    CFLAGS=$tk_oldCFlags
fi

#--------------------------------------------------------------------
# XXX Do this last.
# It might modify XLIBSW which could affect other tests.
#
# Check whether the header and library for the XScreenSaver
# extension are available, and set HAVE_XSS if so.
# XScreenSaver is needed for Tk_GetUserInactiveTime().
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS $XINCLUDES"
    tk_oldLibs=$LIBS
    LIBS="$tk_oldLibs $XLIBSW"
    xss_header_found=no
    xss_lib_found=no
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to try to use XScreenSaver" >&5
printf %s "checking whether to try to use XScreenSaver... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to try to use XScreenSaver" >&5
$as_echo_n "checking whether to try to use XScreenSaver... " >&6; }
    # Check whether --enable-xss was given.
if test ${enable_xss+y}
if test "${enable_xss+set}" = set; then :
then :
  enableval=$enable_xss; enable_xss=$enableval
else case e in #(
  e) enable_xss=yes ;;
else
  enable_xss=yes
esac
fi

    if test "$enable_xss" = "no" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_xss" >&5
printf "%s\n" "$enable_xss" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_xss" >&5
$as_echo "$enable_xss" >&6; }
    else
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_xss" >&5
printf "%s\n" "$enable_xss" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_xss" >&5
$as_echo "$enable_xss" >&6; }
	ac_fn_c_check_header_compile "$LINENO" "X11/extensions/scrnsaver.h" "ac_cv_header_X11_extensions_scrnsaver_h" "#include <X11/Xlib.h>
"
if test "x$ac_cv_header_X11_extensions_scrnsaver_h" = xyes
if test "x$ac_cv_header_X11_extensions_scrnsaver_h" = xyes; then :
then :

	    xss_header_found=yes

fi


	ac_fn_c_check_func "$LINENO" "XScreenSaverQueryInfo" "ac_cv_func_XScreenSaverQueryInfo"
if test "x$ac_cv_func_XScreenSaverQueryInfo" = xyes
if test "x$ac_cv_func_XScreenSaverQueryInfo" = xyes; then :
then :

else case e in #(
  e)
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for XScreenSaverQueryInfo in -lXext" >&5
printf %s "checking for XScreenSaverQueryInfo in -lXext... " >&6; }
if test ${ac_cv_lib_Xext_XScreenSaverQueryInfo+y}
else

	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XScreenSaverQueryInfo in -lXext" >&5
$as_echo_n "checking for XScreenSaverQueryInfo in -lXext... " >&6; }
if ${ac_cv_lib_Xext_XScreenSaverQueryInfo+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lXext  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char XScreenSaverQueryInfo (void);
char XScreenSaverQueryInfo ();
int
main (void)
main ()
{
return XScreenSaverQueryInfo ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_Xext_XScreenSaverQueryInfo=yes
else case e in #(
  e) ac_cv_lib_Xext_XScreenSaverQueryInfo=no ;;
else
  ac_cv_lib_Xext_XScreenSaverQueryInfo=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xext_XScreenSaverQueryInfo" >&5
printf "%s\n" "$ac_cv_lib_Xext_XScreenSaverQueryInfo" >&6; }
if test "x$ac_cv_lib_Xext_XScreenSaverQueryInfo" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xext_XScreenSaverQueryInfo" >&5
$as_echo "$ac_cv_lib_Xext_XScreenSaverQueryInfo" >&6; }
if test "x$ac_cv_lib_Xext_XScreenSaverQueryInfo" = xyes; then :
then :

		XLIBSW="$XLIBSW -lXext"
		xss_lib_found=yes

else case e in #(
  e)
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for XScreenSaverQueryInfo in -lXss" >&5
printf %s "checking for XScreenSaverQueryInfo in -lXss... " >&6; }
if test ${ac_cv_lib_Xss_XScreenSaverQueryInfo+y}
else

		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XScreenSaverQueryInfo in -lXss" >&5
$as_echo_n "checking for XScreenSaverQueryInfo in -lXss... " >&6; }
if ${ac_cv_lib_Xss_XScreenSaverQueryInfo+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
LIBS="-lXss -lXext $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.
   builtin and then its argument prototype would still apply.  */
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char XScreenSaverQueryInfo (void);
char XScreenSaverQueryInfo ();
int
main (void)
main ()
{
return XScreenSaverQueryInfo ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_lib_Xss_XScreenSaverQueryInfo=yes
else case e in #(
  e) ac_cv_lib_Xss_XScreenSaverQueryInfo=no ;;
else
  ac_cv_lib_Xss_XScreenSaverQueryInfo=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS ;;
LIBS=$ac_check_lib_save_LIBS
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xss_XScreenSaverQueryInfo" >&5
printf "%s\n" "$ac_cv_lib_Xss_XScreenSaverQueryInfo" >&6; }
if test "x$ac_cv_lib_Xss_XScreenSaverQueryInfo" = xyes
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xss_XScreenSaverQueryInfo" >&5
$as_echo "$ac_cv_lib_Xss_XScreenSaverQueryInfo" >&6; }
if test "x$ac_cv_lib_Xss_XScreenSaverQueryInfo" = xyes; then :
then :

		    if test "$tcl_cv_ld_weak_l" = yes; then
			# On Darwin, weak link libXss if possible,
			# as it is only available on Tiger or later.
			XLIBSW="$XLIBSW -Wl,-weak-lXss -lXext"
		    else
			XLIBSW="$XLIBSW -lXss -lXext"
		    fi
		    xss_lib_found=yes

fi

	     ;;

esac
fi

	 ;;

esac
fi

    fi
    if test $enable_xss = yes -a $xss_lib_found = yes -a $xss_header_found = yes; then

printf "%s\n" "#define HAVE_XSS 1" >>confdefs.h
$as_echo "#define HAVE_XSS 1" >>confdefs.h

    fi
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#--------------------------------------------------------------------
#	Figure out whether "char" is unsigned.  If so, set a
#	#define for __CHAR_UNSIGNED__.
#--------------------------------------------------------------------

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether char is unsigned" >&5
printf %s "checking whether char is unsigned... " >&6; }
if test ${ac_cv_c_char_unsigned+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether char is unsigned" >&5
$as_echo_n "checking whether char is unsigned... " >&6; }
if ${ac_cv_c_char_unsigned+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main (void)
main ()
{
static int test_array [1 - 2 * !(((char) -1) < 0)];
test_array [0] = 0;
return test_array [0];

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_c_char_unsigned=no
else case e in #(
  e) ac_cv_c_char_unsigned=yes ;;
else
  ac_cv_c_char_unsigned=yes
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_char_unsigned" >&5
printf "%s\n" "$ac_cv_c_char_unsigned" >&6; }
if test $ac_cv_c_char_unsigned = yes; then
  printf "%s\n" "#define __CHAR_UNSIGNED__ 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_char_unsigned" >&5
$as_echo "$ac_cv_c_char_unsigned" >&6; }
if test $ac_cv_c_char_unsigned = yes && test "$GCC" != yes; then
  $as_echo "#define __CHAR_UNSIGNED__ 1" >>confdefs.h

fi


#--------------------------------------------------------------------
#	The statements below define a collection of symbols related to
#	building libtk as a shared library instead of a static library.
#--------------------------------------------------------------------

eval eval "TK_UNSHARED_LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}"
eval eval "TK_SHARED_LIB_SUFFIX=${SHARED_LIB_SUFFIX}"
eval "TK_LIB_FILE_TCL8=libtk${LIB_SUFFIX}"
if test ${TCL_MAJOR_VERSION} = 8 ; then
eval "TK_LIB_FILE=libtk${LIB_SUFFIX}"
else
eval "TK_LIB_FILE=libtcl9tk${LIB_SUFFIX}"
fi
eval "TK_LIB_FILE_TCL9=libtcl9tk${LIB_SUFFIX}"

# tkConfig.sh needs a version of the _LIB_SUFFIX that has been eval'ed
# since on some platforms TK_LIB_FILE contains shell escapes.

eval "TK_LIB_FILE=${TK_LIB_FILE}"

if test "${SHARED_BUILD}" = "1" -a "${SHLIB_SUFFIX}" != ""; then
    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \${TCL_STUB_LIB_SPEC}"
    TCL_STUB_FLAGS="-DUSE_TCL_STUBS"
fi

test -z "$TK_LIBRARY" && TK_LIBRARY='$(prefix)/lib/tk$(VERSION)'
TK_LIBRARY='$(prefix)/lib/tk$(VERSION)'
PRIVATE_INCLUDE_DIR='$(includedir)'
HTML_DIR='$(DISTDIR)/html'
TK_PKG_DIR='tk$(VERSION)'
TK_RSRC_FILE='tk$(VERSION).rsrc'
WISH_RSRC_FILE='wish$(VERSION).rsrc'

# Note:  in the following variable, it's important to use the absolute
# path name of the Tcl directory rather than "..":  this is because
# AIX remembers this path and will attempt to use it at run-time to look
# up the Tcl library.

if test "`uname -s`" = "Darwin" ; then

    if test "`uname -s`" = "Darwin" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to package libraries" >&5
printf %s "checking how to package libraries... " >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to package libraries" >&5
$as_echo_n "checking how to package libraries... " >&6; }
	# Check whether --enable-framework was given.
if test ${enable_framework+y}
if test "${enable_framework+set}" = set; then :
then :
  enableval=$enable_framework; enable_framework=$enableval
else case e in #(
  e) enable_framework=no ;;
else
  enable_framework=no
esac
fi

	if test $enable_framework = yes; then
	    if test $SHARED_BUILD = 0; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Frameworks can only be built if --enable-shared is yes" >&5
printf "%s\n" "$as_me: WARNING: Frameworks can only be built if --enable-shared is yes" >&2;}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Frameworks can only be built if --enable-shared is yes" >&5
$as_echo "$as_me: WARNING: Frameworks can only be built if --enable-shared is yes" >&2;}
		enable_framework=no
	    fi
	    if test $tcl_corefoundation = no; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Frameworks can only be used when CoreFoundation is available" >&5
printf "%s\n" "$as_me: WARNING: Frameworks can only be used when CoreFoundation is available" >&2;}
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Frameworks can only be used when CoreFoundation is available" >&5
$as_echo "$as_me: WARNING: Frameworks can only be used when CoreFoundation is available" >&2;}
		enable_framework=no
	    fi
	fi
	if test $enable_framework = yes; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: framework" >&5
printf "%s\n" "framework" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: framework" >&5
$as_echo "framework" >&6; }
	    FRAMEWORK_BUILD=1
	else
	    if test $SHARED_BUILD = 1; then
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared library" >&5
printf "%s\n" "shared library" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: shared library" >&5
$as_echo "shared library" >&6; }
	    else
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static library" >&5
printf "%s\n" "static library" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: static library" >&5
$as_echo "static library" >&6; }
	    fi
	    FRAMEWORK_BUILD=0
	fi
    fi

    TK_SHLIB_LD_EXTRAS="-compatibility_version ${TK_VERSION} -current_version ${TK_VERSION}`echo ${TK_PATCH_LEVEL} | awk '{match($0, "\\\.[0-9]+"); print substr($0,RSTART,RLENGTH)}'`"
    TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -install_name "${DYLIB_INSTALL_DIR}/${TK_LIB_FILE}" -unexported_symbols_list $$(f=$(TK_LIB_FILE).E && nm -gp tkMacOSX*.o 2>/dev/null | awk "/^[0-9a-f]+ . \.objc/ {print \$$3}" > $$f && nm -gjp "$(TCL_BIN_DIR)"/$(TCL_STUB_LIB_FILE) | grep ^_[^_] >> $$f && echo $$f)'
    echo "$LDFLAGS " | grep -q -- '-prebind ' && TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -seg1addr 0xb000000'
    TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -sectcreate __TEXT __info_plist Tk-Info.plist'
    EXTRA_WISH_LIBS='-sectcreate __TEXT __info_plist Wish-Info.plist'
    EXTRA_WISH_LIBS=${EXTRA_WISH_LIBS}' -sectcreate __TEXT __credits_html Credits.html'
    if test "${SHARED_BUILD}" = "0"; then
	EXTRA_WISH_LIBS=${EXTRA_WISH_LIBS}' -ObjC'
    EXTRA_APP_CC_SWITCHES="${EXTRA_APP_CC_SWITCHES}"' -mdynamic-no-pic'
    fi
    ac_config_files="$ac_config_files Tk-Info.plist:../macosx/Tk-Info.plist.in Wish-Info.plist:../macosx/Wish-Info.plist.in Credits.html:../macosx/Credits.html.in"
    ac_config_files="$ac_config_files Tk-Info.plist:../macosx/Tk-Info.plist.in Wish-Info.plist:../macosx/Wish-Info.plist.in"

    for l in ${LOCALES}; do CFBUNDLELOCALIZATIONS="${CFBUNDLELOCALIZATIONS}<string>$l</string>"; done
    TK_YEAR="`date +%Y`"
fi

if test "$FRAMEWORK_BUILD" = "1" ; then

printf "%s\n" "#define TK_FRAMEWORK 1" >>confdefs.h
$as_echo "#define TK_FRAMEWORK 1" >>confdefs.h

    # Construct a fake local framework structure to make linking with
    # '-framework Tk' and running of tktest work
    ac_config_commands="$ac_config_commands Tk.framework"

    LD_LIBRARY_PATH_VAR="DYLD_FRAMEWORK_PATH"
    if test "${libdir}" = '${exec_prefix}/lib'; then
        # override libdir default
        libdir="/Library/Frameworks"
    fi
    if test ${TCL_MAJOR_VERSION} = 8 ; then
	TK_LIB_FILE="Tk"
    TK_LIB_FILE="Tk"
    else
	TK_LIB_FILE="Tk"
    fi
    TK_LIB_FILE_TCL8="Tk"
    TK_LIB_FILE_TCL9="Tk"
    TK_LIB_FLAG="-framework Tk"
    TK_BUILD_LIB_SPEC="-F`pwd | sed -e 's/ /\\\\ /g'` -framework Tk"
    TK_LIB_SPEC="-F${libdir} -framework Tk"
    libdir="${libdir}/Tk.framework/Versions/\${VERSION}"
    TK_LIBRARY="${libdir}/Resources/Scripts"
    TK_PKG_DIR="Resources/Scripts"
    TK_RSRC_FILE="Tk.rsrc"
    WISH_RSRC_FILE="Wish.rsrc"
    includedir="${libdir}/Headers"
    PRIVATE_INCLUDE_DIR="${libdir}/PrivateHeaders"
    HTML_DIR="${libdir}/Resources/Documentation/Reference/Tk"
    EXTRA_INSTALL="install-private-headers html-tk"
    EXTRA_BUILD_HTML='@ln -fs contents.htm "$(HTML_INSTALL_DIR)"/TkTOC.html'
    EXTRA_INSTALL_BINARIES='@echo "Installing Info.plist to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) Tk-Info.plist "$(LIB_INSTALL_DIR)/Resources/Info.plist"'
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Credits.html to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) Credits.html "$(LIB_INSTALL_DIR)/Resources"'
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing license.terms to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA) "$(TOP_DIR)/license.terms" "$(LIB_INSTALL_DIR)/Resources"'
    if test $tk_aqua = yes; then
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Images to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && for i in Tk.tiff Tk.icns; do $(INSTALL_DATA) "$(MAC_OSX_DIR)/$$i" "$(LIB_INSTALL_DIR)/Resources"; done'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing wish$(VERSION) script to $(INSTALL_ROOT)/'"${bindir}"'/" && $(INSTALL_DATA_DIR) "$(INSTALL_ROOT)/'"${bindir}"'" && printf > "$(INSTALL_ROOT)/'"${bindir}"'/wish$(VERSION)" "#!/bin/sh\n\"\$$(dirname \$$0)'"`eval d="${bindir}"; echo "$d" | sed -e 's#/[^/][^/]*#/..#g'`"'$(bindir)/Wish\" \"\$$@\"" && chmod +x "$(INSTALL_ROOT)/'"${bindir}"'/wish$(VERSION)"'
	bindir="${libdir}/Resources/Wish.app/Contents/MacOS"
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Info.plist to $(BIN_INSTALL_DIR)/.." && $(INSTALL_DATA) Wish-Info.plist "$(BIN_INSTALL_DIR)/../Info.plist" && mv -f "$(BIN_INSTALL_DIR)/wish$(VERSION)" "$(BIN_INSTALL_DIR)/Wish"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Wish.icns to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA_DIR) "$(BIN_INSTALL_DIR)/../Resources"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && $(INSTALL_DATA) "$(MAC_OSX_DIR)/Tk.icns" "$(BIN_INSTALL_DIR)/../Resources/Wish.icns"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Wish.sdef to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA) "$(MAC_OSX_DIR)/Wish.sdef" "$(BIN_INSTALL_DIR)/../Resources"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Credits.html to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA) Credits.html "$(BIN_INSTALL_DIR)/../Resources"'
    fi
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Finalizing Tk.framework" && rm -f "$(LIB_INSTALL_DIR)/../Current" && ln -s "$(VERSION)" "$(LIB_INSTALL_DIR)/../Current" && for f in "$(LIB_FILE)" tkConfig.sh Resources Headers PrivateHeaders; do rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/Current/$$f" "$(LIB_INSTALL_DIR)/../.."; done && f="$(STUB_LIB_FILE)" && rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/$(VERSION)/$$f" "$(LIB_INSTALL_DIR)/../.."'
    # Don't use AC_DEFINE for the following as the framework version define
    # needs to go into the Makefile even when using autoheader, so that we
    # can pick up a potential make override of VERSION. Also, don't put this
    # into CFLAGS as it should not go into tkConfig.sh
    EXTRA_CC_SWITCHES="$EXTRA_CC_SWITCHES"' -DTK_FRAMEWORK_VERSION=\"$(VERSION)\"'
else
    if test $tk_aqua = yes; then
        EXTRA_INSTALL_BINARIES='@echo "Installing Images to $(LIB_INSTALL_DIR)/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)" && for i in Tk.tiff Tk.icns; do $(INSTALL_DATA) "$(MAC_OSX_DIR)/$$i" "$(LIB_INSTALL_DIR)"; done'
    fi
    # libdir must be a fully qualified path and not ${exec_prefix}/lib
    eval libdir="$libdir"
    TK_LIB_FLAG="-l"
    if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
	TK_LIB_FLAG="${TK_LIB_FLAG}tcl9"
    fi
    if test "${ac_cv_cygwin}" = "yes" -a "$SHARED_BUILD" = "1"; then
	TK_LIB_FLAG="${TK_LIB_FLAG}tk`echo ${TK_VERSION} | tr -d .`"
	TK_LIB_FLAG="-ltk`echo ${TK_VERSION} | tr -d .`"
	TK_BUILD_LIB_SPEC="-L\$(TOP_DIR)/win ${TK_LIB_FLAG}"
    else
	if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
	    TK_LIB_FLAG="${TK_LIB_FLAG}tk${TK_VERSION}"
	    TK_LIB_FLAG="-ltk${TK_VERSION}"
	else
	    TK_LIB_FLAG="${TK_LIB_FLAG}tk`echo ${TK_VERSION} | tr -d .`"
	    TK_LIB_FLAG="-ltk`echo ${TK_VERSION} | tr -d .`"
	fi
	TK_BUILD_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TK_LIB_FLAG}"
    fi
    TK_LIB_SPEC="-L${libdir} ${TK_LIB_FLAG}"
fi

#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
# Check whether --enable-zipfs was given.
if test ${enable_zipfs+y}
then :
  enableval=$enable_zipfs; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
esac
fi

if test "$tcl_ok" = "yes" -a "x$enable_framework" != "xyes"; then
    #
    # Find a native compiler
    #
    # Put a plausible default for CC_FOR_BUILD in Makefile.
    if test -z "$CC_FOR_BUILD"; then
      if test "x$cross_compiling" = "xno"; then
        CC_FOR_BUILD='$(CC)'
      else
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gcc" >&5
printf %s "checking for gcc... " >&6; }
        if test ${ac_cv_path_cc+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
            search_path=`echo ${PATH} | sed -e 's/:/ /g'`
            for dir in $search_path ; do
                for j in `ls -r $dir/gcc 2> /dev/null` \
                        `ls -r $dir/gcc 2> /dev/null` ; do
                    if test x"$ac_cv_path_cc" = x ; then
                        if test -f "$j" ; then
                            ac_cv_path_cc=$j
                            break
                        fi
                    fi
                done
            done
         ;;
esac
fi

      fi
    fi

    # Also set EXEEXT_FOR_BUILD.
    if test "x$cross_compiling" = "xno"; then
      EXEEXT_FOR_BUILD='$(EXEEXT)'
      OBJEXT_FOR_BUILD='$(OBJEXT)'
    else
      OBJEXT_FOR_BUILD='.no'
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build system executable suffix" >&5
printf %s "checking for build system executable suffix... " >&6; }
if test ${bfd_cv_build_exeext+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) rm -f conftest*
         echo 'int main () { return 0; }' > conftest.c
         bfd_cv_build_exeext=
         ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
         for file in conftest.*; do
           case $file in
           *.c | *.o | *.obj | *.ilk | *.pdb) ;;
           *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
           esac
         done
         rm -f conftest*
         test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bfd_cv_build_exeext" >&5
printf "%s\n" "$bfd_cv_build_exeext" >&6; }
      EXEEXT_FOR_BUILD=""
      test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
    fi

    #
    # Find a native zip implementation
    #

    MACHER_PROG=""
    ZIP_PROG=""
    ZIP_PROG_OPTIONS=""
    ZIP_PROG_VFSSEARCH=""
    ZIP_INSTALL_OBJS=""

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for macher" >&5
printf %s "checking for macher... " >&6; }
    if test ${ac_cv_path_macher+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/macher 2> /dev/null` \
            `ls -r $dir/macher 2> /dev/null` ; do
        if test x"$ac_cv_path_macher" = x ; then
            if test -f "$j" ; then
            ac_cv_path_macher=$j
            break
            fi
        fi
        done
    done
     ;;
esac
fi

    if test -f "$ac_cv_path_macher" ; then
        MACHER_PROG="$ac_cv_path_macher"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MACHER_PROG" >&5
printf "%s\n" "$MACHER_PROG" >&6; }
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Found macher in environment" >&5
printf "%s\n" "Found macher in environment" >&6; }
    fi
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for zip" >&5
printf %s "checking for zip... " >&6; }
    if test ${ac_cv_path_zip+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/zip 2> /dev/null` \
            `ls -r $dir/zip 2> /dev/null` ; do
        if test x"$ac_cv_path_zip" = x ; then
            if test -f "$j" ; then
            ac_cv_path_zip=$j
            break
            fi
        fi
        done
    done
     ;;
esac
fi

    if test -f "$ac_cv_path_zip" ; then
        ZIP_PROG="$ac_cv_path_zip"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ZIP_PROG" >&5
printf "%s\n" "$ZIP_PROG" >&6; }
        ZIP_PROG_OPTIONS="-rq"
        ZIP_PROG_VFSSEARCH="*"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Found INFO Zip in environment" >&5
printf "%s\n" "Found INFO Zip in environment" >&6; }
        # Use standard arguments for zip
    else
        # It is not an error if an installed version of Zip can't be located.
        # We can use the locally distributed minizip instead
        ZIP_PROG="./minizip${EXEEXT_FOR_BUILD}"
        ZIP_PROG_OPTIONS="-o -r"
        ZIP_PROG_VFSSEARCH="*"
        ZIP_INSTALL_OBJS="minizip${EXEEXT_FOR_BUILD}"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: No zip found on PATH. Building minizip" >&5
printf "%s\n" "No zip found on PATH. Building minizip" >&6; }
    fi






	ZIPFS_BUILD=1
	TK_ZIP_FILE=libtk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${TK_PATCH_LEVEL}.zip
else
	ZIPFS_BUILD=0
	TK_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for building with zipfs" >&5
printf %s "checking for building with zipfs... " >&6; }
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;

printf "%s\n" "#define ZIPFS_BUILD 2" >>confdefs.h

       INSTALL_LIBRARIES=install-demos
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
     else

printf "%s\n" "#define ZIPFS_BUILD 1" >>confdefs.h
\
       INSTALL_LIBRARIES=install-demos
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
    fi
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi






#--------------------------------------------------------------------
#       The statements below define various symbols relating to Tk
#       stub support.
#--------------------------------------------------------------------

# Replace ${VERSION} with contents of ${TK_VERSION}
    TK_STUB_LIB_FILE="libtkstub.a"
    TK_STUB_LIB_FLAG="-ltkstub"
eval "TK_STUB_LIB_DIR=\"${libdir}\""
eval "TK_STUB_LIB_FILE=libtkstub${TK_UNSHARED_LIB_SUFFIX}"
eval "TK_STUB_LIB_DIR=${libdir}"

if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
    TK_STUB_LIB_FLAG="-ltkstub${TK_VERSION}"
else
    TK_STUB_LIB_FLAG="-ltkstub`echo ${TK_VERSION} | tr -d .`"
fi

TK_BUILD_STUB_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TK_STUB_LIB_FLAG}"
TK_STUB_LIB_SPEC="-L${TK_STUB_LIB_DIR} ${TK_STUB_LIB_FLAG}"
TK_BUILD_STUB_LIB_PATH="`pwd`/${TK_STUB_LIB_FILE}"
TK_STUB_LIB_PATH="${TK_STUB_LIB_DIR}/${TK_STUB_LIB_FILE}"

# Install time header dir can be set via --includedir
eval "TK_INCLUDE_SPEC=\"-I${includedir}\""

#------------------------------------------------------------------------
# Demo dir
#------------------------------------------------------------------------

if test x"${DEMO_DIR}" = x
then :
  DEMO_DIR='$(TK_LIBRARY)/demos'
fi
eval "TK_DEMO_DIR=\"`echo ${DEMO_DIR} | tr '()' '{}'`\""
eval "TK_DEMO_DIR=\"`echo ${TK_DEMO_DIR} | tr '()' '{}'`\""



#------------------------------------------------------------------------
# tkConfig.sh refers to this by a different name
#------------------------------------------------------------------------

TK_SHARED_BUILD=${SHARED_BUILD}









9319
9320
9321
9322
9323
9324
9325
9326
9327


9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344


9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357

9358
9359
9360
9361
9362
9363
9364

9365
9366
9367
9368
9369
9370
9371
9372
9373
9374

9375
9376
9377
9378
9379
9380
9381
9382


9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397


9398
9399
9400
9401
9402
9403
9404
8766
8767
8768
8769
8770
8771
8772


8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789


8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803

8804
8805
8806
8807
8808
8809
8810

8811
8812
8813
8814
8815
8816
8817
8818
8819
8820

8821
8822
8823
8824
8825
8826
8827


8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842


8843
8844
8845
8846
8847
8848
8849
8850
8851







-
-
+
+















-
-
+
+












-
+






-
+









-
+






-
-
+
+













-
-
+
+







# scripts and configure runs, see configure's option --config-cache.
# It is not useful on other systems.  If it contains results you don't
# want to keep, you may remove or edit it.
#
# config.status only pays attention to the cache file if you give it
# the --recheck option to rerun configure.
#
# 'ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* 'ac_cv_foo' will be assigned the
# `ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* `ac_cv_foo' will be assigned the
# following values.

_ACEOF

# The following way of writing the cache mishandles newlines in values,
# but we know of no workaround that is simple, portable, and efficient.
# So, we kill variables containing newlines.
# Ultrix sh set writes to stderr and can't be redirected directly,
# and sets the high bit in the cache file unless we assign to the vars.
(
  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
  done

  (set) 2>&1 |
    case $as_nl`(ac_space=' '; set) 2>&1` in #(
    *${as_nl}ac_space=\ *)
      # 'set' does not quote correctly, so add quotes: double-quote
      # `set' does not quote correctly, so add quotes: double-quote
      # substitution turns \\\\ into \\, and sed turns \\ into \.
      sed -n \
	"s/'/'\\\\''/g;
	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
      ;; #(
    *)
      # 'set' quotes correctly as required by POSIX, so do not add quotes.
      # `set' quotes correctly as required by POSIX, so do not add quotes.
      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
) |
  sed '
     /^ac_cv_env_/b end
     t clear
     :clear
     s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/
     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
     t end
     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
     :end' >>confcache
if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
  if test -w "$cache_file"; then
    if test "x$cache_file" != "x/dev/null"; then
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
printf "%s\n" "$as_me: updating cache $cache_file" >&6;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
$as_echo "$as_me: updating cache $cache_file" >&6;}
      if test ! -f "$cache_file" || test -h "$cache_file"; then
	cat confcache >"$cache_file"
      else
        case $cache_file in #(
        */* | ?:*)
	  mv -f confcache "$cache_file"$$ &&
	  mv -f "$cache_file"$$ "$cache_file" ;; #(
        *)
	  mv -f confcache "$cache_file" ;;
	esac
      fi
    fi
  else
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
  fi
fi
rm -f confcache

test "x$prefix" = xNONE && prefix=$ac_default_prefix
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
9421
9422
9423
9424
9425
9426
9427
9428



9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448

9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459

9460
9461
9462
9463
9464
9465
9466


9467
9468
9469
9470
9471
9472
9473
8868
8869
8870
8871
8872
8873
8874

8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896

8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914


8915
8916
8917
8918
8919
8920
8921
8922
8923







-
+
+
+



















-
+











+





-
-
+
+







:clear
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\)/-D\1=\2/g
t quote
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)/-D\1=\2/g
t quote
b any
:quote
s/[][	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/[	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/\[/\\&/g
s/\]/\\&/g
s/\$/$$/g
H
:any
${
	g
	s/^\n//
	s/\n/ /g
	p
}
'
DEFS=`sed -n "$ac_script" confdefs.h`


ac_libobjs=
ac_ltlibobjs=
U=
for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
  # 1. Remove the extension, and $U if already installed.
  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
  ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"`
  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
  #    will be set to the directory where LIBOBJS objects are built.
  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
done
LIBOBJS=$ac_libobjs

LTLIBOBJS=$ac_ltlibobjs


CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""


: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files $CONFIG_STATUS"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
as_write_fail=0
cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
#! $SHELL
# Generated by $as_me.
# Run this file to recreate the current configuration.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
9482
9483
9484
9485
9486
9487
9488
9489

9490
9491
9492
9493
9494
9495
9496
9497
9498


9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518








9519
9520
9521
9522
9523
9524




















9525
9526
9527

9528
9529
9530




9531
9532
9533
9534
9535
9536
9537
9538
9539
9540

9541
9542
9543
9544
9545
9546
9547

9548
9549
9550
9551
9552
9553
9554
9555







9556
9557
9558
9559
9560
9561
9562
9563
9564
9565

9566
9567
9568
9569

9570
9571
9572
9573
9574
9575

9576
9577
9578
9579
9580
9581

9582
9583
9584




















9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597

9598
9599

9600
9601
9602
9603
9604
9605
9606
8932
8933
8934
8935
8936
8937
8938

8939

8940
8941
8942
8943
8944
8945


8946
8947
8948
8949
8950
8951

8952
8953
8954
8955








8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966






8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986



8987



8988
8989
8990
8991










8992




8993
8994

8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018


9019




9020
9021
9022
9023
9024
9025

9026
9027
9028
9029
9030
9031

9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067

9068
9069

9070
9071
9072
9073
9074
9075
9076
9077







-
+
-






-
-
+
+




-




-
-
-
-
-
-
-
-



+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-


-
+








+
+
+
+
+
+
+








-
-
+
-
-
-
-
+





-
+





-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












-
+

-
+







cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
else
  case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
IFS=" ""	$as_nl"

PS1='$ '
PS2='> '
PS4='+ '

  as_echo='print -r --'
  as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    export as_echo_n_body
LANGUAGE=C
export LANGUAGE

    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

fi
# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if ${PATH_SEPARATOR+false} :; then
if test "${PATH_SEPARATOR+set}" != set; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  printf "%s\n" "$as_me: error: $2" >&2
  $as_echo "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637

9638
9639
9640
9641
9642
9643
9644


9645
9646
9647
9648

9649
9650
9651
9652
9653
9654
9655
9656

9657
9658
9659
9660
9661
9662
9663


9664
9665
9666
9667

9668
9669
9670
9671
9672
9673
9674
9094
9095
9096
9097
9098
9099
9100

9101
9102
9103
9104
9105
9106

9107

9108
9109
9110
9111


9112
9113
9114
9115


9116
9117
9118
9119
9120
9121
9122
9123

9124

9125
9126
9127
9128


9129
9130
9131
9132


9133
9134
9135
9136
9137
9138
9139
9140







-






-
+
-




-
-
+
+


-
-
+







-
+
-




-
-
+
+


-
-
+







# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset

# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else case e in #(
  e) as_fn_append ()
else
  as_fn_append ()
  {
    eval $1=\$$1\$2
  } ;;
esac
  }
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else case e in #(
  e) as_fn_arith ()
else
  as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  } ;;
esac
  }
fi # as_fn_arith


if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
9687
9688
9689
9690
9691
9692
9693
9694

9695
9696
9697
9698
9699
9700
9701
9153
9154
9155
9156
9157
9158
9159

9160
9161
9162
9163
9164
9165
9166
9167







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X/"$0" |
$as_echo X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752



9753
9754
9755
9756
9757
9758
9759
9175
9176
9177
9178
9179
9180
9181




9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194






9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205



9206
9207
9208
9209
9210
9211
9212
9213
9214
9215







-
-
-
-













-
-
-
-
-
-











-
-
-
+
+
+







# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
9773
9774
9775
9776
9777
9778
9779
9780

9781
9782
9783
9784
9785
9786
9787
9788
9789

9790
9791
9792
9793
9794
9795
9796
9229
9230
9231
9232
9233
9234
9235

9236
9237
9238
9239
9240
9241
9242
9243
9244

9245
9246
9247
9248
9249
9250
9251
9252







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_dir" |
$as_echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
9826
9827
9828
9829
9830
9831
9832
9833

9834
9835
9836
9837

9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854


9855
9856
9857
9858
9859
9860
9861
9282
9283
9284
9285
9286
9287
9288

9289

9290
9291

9292

9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306


9307
9308
9309
9310
9311
9312
9313
9314
9315







-
+
-


-
+
-














-
-
+
+







{
  test -f "$1" && test -x "$1"
} # as_fn_executable_p
as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


exec 6>&1
## ----------------------------------- ##
## Main body of $CONFIG_STATUS script. ##
## ----------------------------------- ##
_ASEOF
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by tk $as_me 9.0, which was
generated by GNU Autoconf 2.72.  Invocation command line was
This file was extended by tk $as_me 8.7, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@

9875
9876
9877
9878
9879
9880
9881
9882

9883
9884
9885
9886
9887
9888
9889
9329
9330
9331
9332
9333
9334
9335

9336
9337
9338
9339
9340
9341
9342
9343







-
+







config_files="$ac_config_files"
config_commands="$ac_config_commands"

_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
ac_cs_usage="\
'$as_me' instantiates files and other configuration actions
\`$as_me' instantiates files and other configuration actions
from templates according to the current configuration.  Unless the files
and actions are specified as TAGs, all are instantiated by default.

Usage: $0 [OPTION]... [TAG]...

  -h, --help       print this help, then exit
  -V, --version    print version number and configuration settings, then exit
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910

9911
9912
9913


9914
9915
9916

9917
9918
9919
9920
9921
9922
9923
9354
9355
9356
9357
9358
9359
9360


9361

9362
9363


9364
9365
9366
9367

9368
9369
9370
9371
9372
9373
9374
9375







-
-

-
+

-
-
+
+


-
+








Configuration commands:
$config_commands

Report bugs to the package provider."

_ACEOF
ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"`
ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"`
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
tk config.status 9.0
configured by $0, generated by GNU Autoconf 2.72,
tk config.status 8.7
configured by $0, generated by GNU Autoconf 2.69,
  with options \\"\$ac_cs_config\\"

Copyright (C) 2023 Free Software Foundation, Inc.
Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."

ac_pwd='$ac_pwd'
srcdir='$srcdir'
test -n "\$AWK" || AWK=awk
_ACEOF
9946
9947
9948
9949
9950
9951
9952
9953

9954
9955

9956
9957
9958
9959
9960
9961

9962
9963
9964
9965
9966
9967

9968
9969
9970
9971
9972
9973
9974


9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995

9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009

10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035

10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046


10047
10048
10049
10050
10051
10052
10053
10054

10055
10056
10057
10058
10059
10060
10061
9398
9399
9400
9401
9402
9403
9404

9405
9406

9407
9408
9409
9410
9411
9412

9413
9414
9415
9416
9417
9418

9419
9420
9421
9422
9423
9424


9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446

9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460

9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480

9481
9482
9483
9484
9485

9486
9487
9488
9489
9490
9491
9492
9493
9494
9495


9496
9497
9498
9499
9500
9501
9502
9503
9504

9505
9506
9507
9508
9509
9510
9511
9512







-
+

-
+





-
+





-
+





-
-
+
+




















-
+













-
+



















-





-
+









-
-
+
+







-
+







  esac

  case $ac_option in
  # Handling of the options.
  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
    ac_cs_recheck=: ;;
  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
    printf "%s\n" "$ac_cs_version"; exit ;;
    $as_echo "$ac_cs_version"; exit ;;
  --config | --confi | --conf | --con | --co | --c )
    printf "%s\n" "$ac_cs_config"; exit ;;
    $as_echo "$ac_cs_config"; exit ;;
  --debug | --debu | --deb | --de | --d | -d )
    debug=: ;;
  --file | --fil | --fi | --f )
    $ac_shift
    case $ac_optarg in
    *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    '') as_fn_error $? "missing file argument" ;;
    esac
    as_fn_append CONFIG_FILES " '$ac_optarg'"
    ac_need_defaults=false;;
  --he | --h |  --help | --hel | -h )
    printf "%s\n" "$ac_cs_usage"; exit ;;
    $as_echo "$ac_cs_usage"; exit ;;
  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil | --si | --s)
    ac_cs_silent=: ;;

  # This is an error.
  -*) as_fn_error $? "unrecognized option: '$1'
Try '$0 --help' for more information." ;;
  -*) as_fn_error $? "unrecognized option: \`$1'
Try \`$0 --help' for more information." ;;

  *) as_fn_append ac_config_targets " $1"
     ac_need_defaults=false ;;

  esac
  shift
done

ac_configure_extra_args=

if $ac_cs_silent; then
  exec 6>/dev/null
  ac_configure_extra_args="$ac_configure_extra_args --silent"
fi

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
  shift
  \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6
  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
  CONFIG_SHELL='$SHELL'
  export CONFIG_SHELL
  exec "\$@"
fi

_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
  printf "%s\n" "$ac_log"
  $as_echo "$ac_log"
} >&5

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
#
# INIT-COMMANDS
#
VERSION=${TK_VERSION} && tk_aqua=${tk_aqua}

_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1

# Handling of arguments.
for ac_config_target in $ac_config_targets
do
  case $ac_config_target in
    "Tk-Info.plist") CONFIG_FILES="$CONFIG_FILES Tk-Info.plist:../macosx/Tk-Info.plist.in" ;;
    "Wish-Info.plist") CONFIG_FILES="$CONFIG_FILES Wish-Info.plist:../macosx/Wish-Info.plist.in" ;;
    "Credits.html") CONFIG_FILES="$CONFIG_FILES Credits.html:../macosx/Credits.html.in" ;;
    "Tk.framework") CONFIG_COMMANDS="$CONFIG_COMMANDS Tk.framework" ;;
    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile:../unix/Makefile.in" ;;
    "tkConfig.sh") CONFIG_FILES="$CONFIG_FILES tkConfig.sh:../unix/tkConfig.sh.in" ;;
    "tk.pc") CONFIG_FILES="$CONFIG_FILES tk.pc:../unix/tk.pc.in" ;;

  *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;;
  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
  esac
done


# If the user did not use the arguments to specify the items to instantiate,
# then the envvar interface is used.  Set only those that are not.
# We use the long form for the default assignment because of an extremely
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
  test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files
  test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands
  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
fi

# Have a temporary directory for convenience.  Make it in the build tree
# simply because there is no reason against having it here, and in addition,
# creating and moving files from /tmp can sometimes cause problems.
# Hook for its removal unless debugging.
# Note that there is a small window in which the directory will not be cleaned:
# after its creation but before its name has been assigned to '$tmp'.
# after its creation but before its name has been assigned to `$tmp'.
$debug ||
{
  tmp= ac_tmp=
  trap 'exit_status=$?
  : "${ac_tmp:=$tmp}"
  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
' 0
10071
10072
10073
10074
10075
10076
10077
10078

10079
10080
10081
10082
10083
10084
10085
9522
9523
9524
9525
9526
9527
9528

9529
9530
9531
9532
9533
9534
9535
9536







-
+







  tmp=./conf$$-$RANDOM
  (umask 077 && mkdir "$tmp")
} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
ac_tmp=$tmp

# Set up the scripts for CONFIG_FILES section.
# No need to generate them if there are no CONFIG_FILES.
# This happens for instance with './config.status config.h'.
# This happens for instance with `./config.status config.h'.
if test -n "$CONFIG_FILES"; then


ac_cr=`echo X | tr X '\015'`
# On cygwin, bash can eat \r inside `` if the user requested igncr.
# But we know of no other shell where ac_cr would be empty at this
# point, so we can use a bashism as a fallback.
10237
10238
10239
10240
10241
10242
10243
10244

10245
10246
10247
10248
10249
10250
10251
9688
9689
9690
9691
9692
9693
9694

9695
9696
9697
9698
9699
9700
9701
9702







-
+







for ac_tag
do
  case $ac_tag in
  :[FHLC]) ac_mode=$ac_tag; continue;;
  esac
  case $ac_mode$ac_tag in
  :[FHL]*:*);;
  :L* | :C*:*) as_fn_error $? "invalid tag '$ac_tag'" "$LINENO" 5;;
  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
  :[FH]-) ac_tag=-:-;;
  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
  esac
  ac_save_IFS=$IFS
  IFS=:
  set x $ac_tag
  IFS=$ac_save_IFS
10259
10260
10261
10262
10263
10264
10265
10266

10267
10268
10269
10270
10271
10272

10273
10274

10275
10276
10277
10278

10279
10280
10281
10282

10283
10284
10285
10286
10287


10288
10289
10290
10291
10292

10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309

10310
10311
10312
10313
10314
10315
10316
9710
9711
9712
9713
9714
9715
9716

9717
9718
9719
9720
9721
9722

9723
9724

9725
9726
9727
9728

9729
9730
9731
9732

9733
9734
9735
9736


9737
9738
9739
9740
9741
9742

9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759

9760
9761
9762
9763
9764
9765
9766
9767







-
+





-
+

-
+



-
+



-
+



-
-
+
+




-
+
















-
+







    ac_file_inputs=
    for ac_f
    do
      case $ac_f in
      -) ac_f="$ac_tmp/stdin";;
      *) # Look for the file first in the build tree, then in the source tree
	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
	 # because $ac_f cannot contain ':'.
	 # because $ac_f cannot contain `:'.
	 test -f "$ac_f" ||
	   case $ac_f in
	   [\\/$]*) false;;
	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
	   esac ||
	   as_fn_error 1 "cannot find input file: '$ac_f'" "$LINENO" 5;;
	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
      esac
      case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      as_fn_append ac_file_inputs " '$ac_f'"
    done

    # Let's still pretend it is 'configure' which instantiates (i.e., don't
    # Let's still pretend it is `configure' which instantiates (i.e., don't
    # use $as_me), people would be surprised to read:
    #    /* config.h.  Generated by config.status.  */
    configure_input='Generated from '`
	  printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	`' by configure.'
    if test x"$ac_file" != x-; then
      configure_input="$ac_file.  $configure_input"
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
printf "%s\n" "$as_me: creating $ac_file" >&6;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
$as_echo "$as_me: creating $ac_file" >&6;}
    fi
    # Neutralize special characters interpreted by sed in replacement strings.
    case $configure_input in #(
    *\&* | *\|* | *\\* )
       ac_sed_conf_input=`printf "%s\n" "$configure_input" |
       ac_sed_conf_input=`$as_echo "$configure_input" |
       sed 's/[\\\\&|]/\\\\&/g'`;; #(
    *) ac_sed_conf_input=$configure_input;;
    esac

    case $ac_tag in
    *:-:* | *:-) cat >"$ac_tmp/stdin" \
      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
    esac
    ;;
  esac

  ac_dir=`$as_dirname -- "$ac_file" ||
$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$ac_file" : 'X\(//\)[^/]' \| \
	 X"$ac_file" : 'X\(//\)$' \| \
	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$ac_file" |
$as_echo X"$ac_file" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
10326
10327
10328
10329
10330
10331
10332
10333

10334
10335

10336
10337
10338
10339
10340
10341
10342
9777
9778
9779
9780
9781
9782
9783

9784
9785

9786
9787
9788
9789
9790
9791
9792
9793







-
+

-
+







	  s/.*/./; q'`
  as_dir="$ac_dir"; as_fn_mkdir_p
  ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
10381
10382
10383
10384
10385
10386
10387
10388
10389


10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402

10403
10404
10405
10406
10407
10408
10409
9832
9833
9834
9835
9836
9837
9838


9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852

9853
9854
9855
9856
9857
9858
9859
9860







-
-
+
+












-
+







/@docdir@/p
/@infodir@/p
/@localedir@/p
/@mandir@/p'
case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
*datarootdir*) ac_datarootdir_seen=yes;;
*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
  ac_datarootdir_hack='
  s&@datadir@&$datadir&g
  s&@docdir@&$docdir&g
  s&@infodir@&$infodir&g
  s&@localedir@&$localedir&g
  s&@mandir@&$mandir&g
  s&\\\${datarootdir}&$datarootdir&g' ;;
esac
_ACEOF

# Neutralize VPATH when '$srcdir' = '.'.
# Neutralize VPATH when `$srcdir' = `.'.
# Shell code in configure.ac might set extrasub.
# FIXME: do we really want to maintain this feature?
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_sed_extra="$ac_vpsub
$extrasub
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
10424
10425
10426
10427
10428
10429
10430
10431

10432
10433

10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446


10447
10448
10449
10450
10451
10452
10453
9875
9876
9877
9878
9879
9880
9881

9882
9883

9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895


9896
9897
9898
9899
9900
9901
9902
9903
9904







-
+

-
+











-
-
+
+







eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5

test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
      "$ac_tmp/out"`; test -z "$ac_out"; } &&
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable 'datarootdir'
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined.  Please make sure it is defined" >&5
printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable 'datarootdir'
$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined.  Please make sure it is defined" >&2;}

  rm -f "$ac_tmp/stdin"
  case $ac_file in
  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
  esac \
  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 ;;


  :C)  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
printf "%s\n" "$as_me: executing $ac_file commands" >&6;}
  :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
$as_echo "$as_me: executing $ac_file commands" >&6;}
 ;;
  esac


  case $ac_file$ac_mode in
    "Tk.framework":C) n=Tk &&
        f=$n.framework && v=Versions/$VERSION &&
10487
10488
10489
10490
10491
10492
10493
10494
10495


10496
10497
10498
10499
9938
9939
9940
9941
9942
9943
9944


9945
9946
9947
9948
9949








-
-
+
+



-
  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
  exec 5>>config.log
  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
  # would make configure fail if this is the last instruction.
  $ac_cs_success || as_fn_exit 1
fi
if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
fi



Changes to unix/configure.ac.

1

2
3
4
5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29




30
31
32
33
34
35
36
37
38
39
40

41
42

43
44



45
46
47
48
49
50
51

1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19


20
21

22
23
24




25
26
27
28
29
30
31
32
33
34
35
36
37
38

39


40
41
42
43
44
45
46
47
48
49
50
51
52
-
+




-
-
+
+












-
-
+
+
-



-
-
-
-
+
+
+
+










-
+
-
-
+


+
+
+







! /bin/bash -norc
#! /bin/bash -norc
dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during Tk installation
dnl	to configure the system for the local environment.

AC_INIT([tk],[9.0])
AC_PREREQ([2.69])
AC_INIT([tk],[8.7])
AC_PREREQ(2.69)

dnl This is only used when included from macosx/configure.ac
m4_ifdef([SC_USE_CONFIG_HEADERS], [
    AC_CONFIG_HEADERS([tkConfig.h:../unix/tkConfig.h.in])
    AC_CONFIG_COMMANDS_PRE([DEFS="-DHAVE_TK_CONFIG_H  -imacros tkConfig.h"])
    AH_TOP([
    #ifndef _TKCONFIG
    #define _TKCONFIG])
    AH_BOTTOM([
    /* Undef unused package specific autoheader defines so that we can
     * include both tclConfig.h and tkConfig.h at the same time: */
    /* override */ #undef PACKAGE_NAME
    /* override */ #undef PACKAGE_TARNAME
    /* override */ #undef PACKAGE_VERSION
    /* override */ #undef PACKAGE_STRING
    /* override */ #undef PACKAGE_TARNAME
    /* override */ #undef PACKAGE_STRING
    #endif /* _TKCONFIG */])
])

TK_VERSION=9.0
TK_MAJOR_VERSION=9
TK_MINOR_VERSION=0
TK_PATCH_LEVEL="b2"
TK_VERSION=8.7
TK_MAJOR_VERSION=8
TK_MINOR_VERSION=7
TK_PATCH_LEVEL="a0"
VERSION=${TK_VERSION}
LOCALES="cs da de el en en_gb eo es fr hu it nl pl pt ru sv"

#--------------------------------------------------------------------
# Find and load the tclConfig.sh file
#--------------------------------------------------------------------

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG

if test "${TCL_MAJOR_VERSION}" -lt 9 ; then
if test "${TCL_MAJOR_VERSION}" -ne 8 ; then
if test "${TCL_MINOR_VERSION}" -lt 7 ; then
    AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.7+
    AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+
Found config for Tcl ${TCL_VERSION}])
fi
if test "${TCL_MINOR_VERSION}" -lt 6 ; then
    AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+
Found config for Tcl ${TCL_VERSION}])
fi

SC_PROG_TCLSH
SC_BUILD_TCLSH

#------------------------------------------------------------------------
# Handle the --prefix=... option
75
76
77
78
79
80
81













82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100

101
102

103



104
105
106
107
108
109
110
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113

114
115
116
117

118
119
120
121
122
123
124
125
126
127







+
+
+
+
+
+
+
+
+
+
+
+
+










-
+







-
+


+
-
+
+
+







# the AC_PROG_CC macro from adding "-g -O2".
if test "${CFLAGS+set}" != "set" ; then
    CFLAGS=""
fi

AC_PROG_CC
AC_C_INLINE

#--------------------------------------------------------------------
# Supply a substitute for stdlib.h if it doesn't define strtol,
# strtoul, or strtod (which it doesn't in some versions of SunOS).
#--------------------------------------------------------------------

AC_CHECK_HEADER(stdlib.h, tk_ok=1, tk_ok=0)
AC_EGREP_HEADER(strtol, stdlib.h, , tk_ok=0)
AC_EGREP_HEADER(strtoul, stdlib.h, , tk_ok=0)
AC_EGREP_HEADER(strtod, stdlib.h, , tk_ok=0)
if test $tk_ok = 0; then
    AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
fi

#------------------------------------------------------------------------
# If we're using GCC, see if the compiler understands -pipe.  If so, use it.
# It makes compiling go faster.  (This is only a performance feature.)
#------------------------------------------------------------------------

if test -z "$no_pipe" && test -n "$GCC"; then
    AC_CACHE_CHECK([if the compiler understands -pipe],
	tcl_cv_cc_pipe, [
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[tcl_cv_cc_pipe=yes],[tcl_cv_cc_pipe=no])
	AC_TRY_COMPILE(,, tcl_cv_cc_pipe=yes, tcl_cv_cc_pipe=no)
	CFLAGS=$hold_cflags])
    if test $tcl_cv_cc_pipe = yes; then
	CFLAGS="$CFLAGS -pipe"
    fi
fi

#------------------------------------------------------------------------
# Embedded configuration information, encoding to use for the values, TIP #59
# Threads support - this auto-enables if Tcl was compiled threaded
#------------------------------------------------------------------------

SC_ENABLE_THREADS
SC_TCL_CFG_ENCODING

# Add the threads support libraries
LIBS="$LIBS$THREADS_LIBS"

SC_ENABLE_SHARED

#--------------------------------------------------------------------
# The statements below define a collection of compile flags.  This
# macro depends on the value of SHARED_BUILD, and should be called
# after SC_ENABLE_SHARED checks the configure switches.
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178











179
180
181
182
183
184
185
186
187

188
189
190
191































192
193
194
195
196
197


198

199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228























229
230
231
232
233
234
235


236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252


253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290

291
292
293
294
295
296
297
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315


316
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332


333
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364

365







366
367
368
369
370
371
372
373







-
+















-
+













-
+
+


















-
+
+
+
+
+
+
+
+
+
+
+









+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






+
+
-
+











-
+


















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+






-
+








-
-
+
+







-
+









-
+












-
+
-
-
-
-
-
-
-
+








SC_TCL_64BIT_FLAGS

#--------------------------------------------------------------------
#	Check endianness because we can optimize some operations
#--------------------------------------------------------------------

AC_C_BIGENDIAN(,,,[#])
AC_C_BIGENDIAN

#------------------------------------------------------------------------
# If Tcl and Tk are installed in different places, adjust the library
# search path to reflect this.
#------------------------------------------------------------------------

LIB_RUNTIME_DIR='$(libdir)'

if test "$TCL_EXEC_PREFIX" != "$exec_prefix"; then
    LIB_RUNTIME_DIR="${LIB_RUNTIME_DIR}:${TCL_EXEC_PREFIX}/lib"
fi

if test "$TCL_PREFIX" != "$prefix"; then
    AC_MSG_WARN([
        Different --prefix selected for Tk and Tcl!
        [[package require tk]] may not work correctly in tclsh.])
        [[package require Tk]] may not work correctly in tclsh.])
fi

#--------------------------------------------------------------------
#	Include sys/select.h if it exists and if it supplies things
#	that appear to be useful and aren't already in sys/types.h.
#	This appears to be true only on the RS/6000 under AIX.  Some
#	systems like OSF/1 have a sys/select.h that's of no use, and
#	other systems like SCO UNIX have a sys/select.h that's
#	pernicious.  If "fd_set" isn't defined anywhere then set a
#	special flag.
#--------------------------------------------------------------------

AC_CACHE_CHECK([for fd_set in sys/types], tcl_cv_type_fd_set, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]], [[fd_set readMask, writeMask;]])],[tcl_cv_type_fd_set=yes],[tcl_cv_type_fd_set=no])])
    AC_TRY_COMPILE([#include <sys/types.h>],[fd_set readMask, writeMask;],
	tcl_cv_type_fd_set=yes, tcl_cv_type_fd_set=no)])
tk_ok=$tcl_cv_type_fd_set
if test $tk_ok = no; then
    AC_CACHE_CHECK([for fd_mask in sys/select], tcl_cv_grep_fd_mask, [
	AC_EGREP_HEADER(fd_mask, sys/select.h,
	     tcl_cv_grep_fd_mask=present, tcl_cv_grep_fd_mask=missing)])
    if test $tcl_cv_grep_fd_mask = present; then
	AC_DEFINE(HAVE_SYS_SELECT_H, 1, [Should we include <sys/select.h>?])
	tk_ok=yes
    fi
fi
if test $tk_ok = no; then
    AC_DEFINE(NO_FD_SET, 1, [Do we have fd_set?])
fi

#------------------------------------------------------------------------------
#       Find out all about time handling differences.
#------------------------------------------------------------------------------

AC_CHECK_HEADERS_ONCE([sys/time.h])
AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME

#--------------------------------------------------------------------
#	Under Solaris 2.4, strtod returns the wrong value for the
#	terminating character under some conditions.  Check for this
#	and if the problem exists use a substitute procedure
#	"fixstrtod" (provided by Tcl) that corrects the error.
#--------------------------------------------------------------------

SC_BUGGY_STRTOD

#--------------------------------------------------------------------
#	Check for various typedefs and provide substitutes if
#	they don't exist.
#--------------------------------------------------------------------

AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T

AC_CHECK_TYPES([intptr_t, uintptr_t],,,[[
#include <stdint.h>
]])
AC_CHECK_TYPE([intptr_t], [
    AC_DEFINE([HAVE_INTPTR_T], 1, [Do we have the intptr_t type?])], [
    AC_CACHE_CHECK([for pointer-size signed integer type], tcl_cv_intptr_t, [
    for tcl_cv_intptr_t in "int" "long" "long long" none; do
	if test "$tcl_cv_intptr_t" != none; then
	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
		    [[sizeof (void *) <= sizeof ($tcl_cv_intptr_t)]])],
		[tcl_ok=yes], [tcl_ok=no])
	    test "$tcl_ok" = yes && break; fi
    done])
    if test "$tcl_cv_intptr_t" != none; then
	AC_DEFINE_UNQUOTED([intptr_t], [$tcl_cv_intptr_t], [Signed integer
	   type wide enough to hold a pointer.])
    fi
])
AC_CHECK_TYPE([uintptr_t], [
    AC_DEFINE([HAVE_UINTPTR_T], 1, [Do we have the uintptr_t type?])], [
    AC_CACHE_CHECK([for pointer-size unsigned integer type], tcl_cv_uintptr_t, [
    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \
	    none; do
	if test "$tcl_cv_uintptr_t" != none; then
	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
		    [[sizeof (void *) <= sizeof ($tcl_cv_uintptr_t)]])],
		[tcl_ok=yes], [tcl_ok=no])
	    test "$tcl_ok" = yes && break; fi
    done])
    if test "$tcl_cv_uintptr_t" != none; then
	AC_DEFINE_UNQUOTED([uintptr_t], [$tcl_cv_uintptr_t], [Unsigned integer
	   type wide enough to hold a pointer.])
    fi
])

#-------------------------------------------
#     In OS/390 struct pwd has no pw_gecos field
#-------------------------------------------

AC_CACHE_CHECK([pw_gecos in struct pwd], tcl_cv_pwd_pw_gecos, [
    AC_TRY_COMPILE([#include <pwd.h>],
	    [struct passwd pwd; pwd.pw_gecos;],
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <pwd.h>]], [[struct passwd pwd; (void)pwd.pw_gecos;]])],[tcl_cv_pwd_pw_gecos=yes],[tcl_cv_pwd_pw_gecos=no])])
	    tcl_cv_pwd_pw_gecos=yes, tcl_cv_pwd_pw_gecos=no)])
if test $tcl_cv_pwd_pw_gecos = yes; then
    AC_DEFINE(HAVE_PW_GECOS, 1, [Does struct password have a pw_gecos field?])
fi

#--------------------------------------------------------------------
#	On Mac OS X, we can build either with X11 or with Aqua
#--------------------------------------------------------------------

if test "`uname -s`" = "Darwin" ; then
    AC_MSG_CHECKING([whether to use Aqua])
    AC_ARG_ENABLE(aqua,
	AS_HELP_STRING([--enable-aqua=yes|no],
	AC_HELP_STRING([--enable-aqua=yes|no],
	    [use Aqua windowingsystem on Mac OS X (default: no)]),
	[tk_aqua=$enableval], [tk_aqua=no])
    if test $tk_aqua = yes -o $tk_aqua = cocoa; then
	tk_aqua=yes
	if test $tcl_corefoundation = no; then
	    AC_MSG_WARN([Aqua can only be used when CoreFoundation is available])
	    tk_aqua=no
	fi
	if test ! -d /System/Library/Frameworks/Cocoa.framework; then
	    AC_MSG_WARN([Aqua can only be used when Cocoa is available])
	    tk_aqua=no
	fi
	if test "`uname -r | awk -F. '{print [$]1}'`" -lt 9; then
	    AC_MSG_WARN([Aqua requires Mac OS X 10.5 or later])
	    tk_aqua=no
	fi
    fi
    AC_MSG_RESULT([$tk_aqua])
    if test "$fat_32_64" = yes; then
	if test $tk_aqua = no; then
	    AC_CACHE_CHECK([for 64-bit X11], tcl_cv_lib_x11_64, [
		for v in CFLAGS CPPFLAGS LDFLAGS; do
		    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
		done
		CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
		LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
		AC_TRY_LINK([#include <X11/Xlib.h>], [XrmInitialize();],
		    tcl_cv_lib_x11_64=yes, tcl_cv_lib_x11_64=no)
		for v in CFLAGS CPPFLAGS LDFLAGS; do
		    eval $v'="$hold_'$v'"'
		done])
	fi
	# remove 64-bit arch flags from CFLAGS et al. for combined 32 & 64 bit
	# fat builds if configuration does not support 64-bit.
	if test "$tcl_cv_lib_x11_64" = no; then
	    AC_MSG_NOTICE([Removing 64-bit architectures from compiler & linker flags])
	    for v in CFLAGS CPPFLAGS LDFLAGS; do
		eval $v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
	    done
	fi
    fi
    if test $tk_aqua = no; then
	# check if weak linking whole libraries is possible.
	AC_CACHE_CHECK([if ld accepts -weak-l flag], tcl_cv_ld_weak_l, [
	    hold_ldflags=$LDFLAGS
	    LDFLAGS="$LDFLAGS -Wl,-weak-lm"
	    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]], [[double f = sin(1.0);]])],
	    [tcl_cv_ld_weak_l=yes],[tcl_cv_ld_weak_l=no])
	    AC_TRY_LINK([#include <math.h>], [double f = sin(1.0);],
		tcl_cv_ld_weak_l=yes, tcl_cv_ld_weak_l=no)
	    LDFLAGS=$hold_ldflags])
    fi
    AC_CHECK_HEADERS(AvailabilityMacros.h)
    if test "$ac_cv_header_AvailabilityMacros_h" = yes; then
	AC_CACHE_CHECK([if weak import is available], tcl_cv_cc_weak_import, [
	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
	    AC_TRY_LINK([
		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1020
		    #endif
		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1020
		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1020
		    #endif
		    int rand(void) __attribute__((weak_import));
		]], [[rand();]])],
		[tcl_cv_cc_weak_import=yes],[tcl_cv_cc_weak_import=no])
		], [rand();],
		tcl_cv_cc_weak_import=yes, tcl_cv_cc_weak_import=no)
	    CFLAGS=$hold_cflags])
	if test $tcl_cv_cc_weak_import = yes; then
	    AC_DEFINE(HAVE_WEAK_IMPORT, 1, [Is weak import available?])
	fi
	AC_CACHE_CHECK([if Darwin SUSv3 extensions are available],
	    tcl_cv_cc_darwin_c_source, [
	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	    AC_TRY_COMPILE([
		    #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
		    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
		    #error __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
		    #endif
		    #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1050
		    #error MAC_OS_X_VERSION_MIN_REQUIRED < 1050
		    #endif
		    #define _DARWIN_C_SOURCE 1
		    #include <sys/cdefs.h>
		]], [[]])],[tcl_cv_cc_darwin_c_source=yes],[tcl_cv_cc_darwin_c_source=no])
		],,tcl_cv_cc_darwin_c_source=yes, tcl_cv_cc_darwin_c_source=no)
	    CFLAGS=$hold_cflags])
	if test $tcl_cv_cc_darwin_c_source = yes; then
	    AC_DEFINE(_DARWIN_C_SOURCE, 1,
		    [Are Darwin SUSv3 extensions available?])
	fi
    fi
else
    tk_aqua=no
fi

if test $tk_aqua = yes; then
    AC_DEFINE(MAC_OSX_TK, 1, [Are we building TkAqua?])
    LIBS="$LIBS -framework Cocoa -framework Carbon -framework IOKit -framework QuartzCore -framework Security -framework CoreGraphics"
    LIBS="$LIBS -framework Cocoa -framework Carbon -framework IOKit"
    if test -d /System/Library/Frameworks/UserNotifications.framework; then
        LIBS="$LIBS -framework UserNotifications"
    fi
    if test -d "/System/Library/Frameworks/UniformTypeIdentifiers.framework"; then
        LIBS="$LIBS -weak_framework UniformTypeIdentifiers"
    fi
    EXTRA_CC_SWITCHES='-x objective-c'
    EXTRA_CC_SWITCHES='-std=gnu99 -x objective-c'
    TK_WINDOWINGSYSTEM=AQUA
    if test -n "${enable_symbols}" -a "${enable_symbols}" != no; then
        AC_DEFINE(TK_MAC_DEBUG, 1, [Are TkAqua debug messages enabled?])
    fi
else
    #--------------------------------------------------------------------
    #	Locate the X11 header files and the X11 library archive.  Try
364
365
366
367
368
369
370
371

372
373

374
375

376
377
378
379

380
381
382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407


408
409
410
411
412
413
414
440
441
442
443
444
445
446

447
448

449
450

451
452
453
454

455
456
457
458
459
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474
475
476
477
478
479
480
481


482
483
484
485
486
487
488
489
490







-
+

-
+

-
+



-
+











-
+














-
-
+
+








if test -d /usr/include/mit -a $tk_aqua = no; then
    AC_MSG_CHECKING([MIT X libraries])
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS -I/usr/include/mit"
    tk_oldLibs=$LIBS
    LIBS="$LIBS -lX11-mit"
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_LINK([
	#include <X11/Xlib.h>
    ]], [[
    ], [
	XOpenDisplay(0);
    ]])],[
    ], [
	AC_MSG_RESULT([yes])
	XLIBSW="-lX11-mit"
	XINCLUDES="-I/usr/include/mit"
    ],[AC_MSG_RESULT(no)])
    ], AC_MSG_RESULT([no]))
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#--------------------------------------------------------------------
#	Check for freetype / fontconfig / Xft support.
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    AC_MSG_CHECKING([whether to use xft])
    AC_ARG_ENABLE(xft,
	AS_HELP_STRING([--enable-xft],
	AC_HELP_STRING([--enable-xft],
	    [use freetype/fontconfig/xft (default: on)]),
	[enable_xft=$enableval], [enable_xft="default"])
    XFT_CFLAGS=""
    XFT_LIBS=""
    if test "$enable_xft" = "no" ; then
	AC_MSG_RESULT([$enable_xft])
    else
	found_xft="yes"
	dnl make sure package configurator (xft-config or pkg-config
	dnl says that xft is present.
	XFT_CFLAGS=`xft-config --cflags 2>/dev/null` || found_xft="no"
	XFT_LIBS=`xft-config --libs 2>/dev/null` || found_xft="no"
	if test "$found_xft" = "no" ; then
	    found_xft=yes
	    XFT_CFLAGS=`pkg-config --cflags xft fontconfig 2>/dev/null` || found_xft="no"
	    XFT_LIBS=`pkg-config --libs xft fontconfig 2>/dev/null` || found_xft="no"
	    XFT_CFLAGS=`pkg-config --cflags xft 2>/dev/null` || found_xft="no"
	    XFT_LIBS=`pkg-config --libs xft 2>/dev/null` || found_xft="no"
	fi
	AC_MSG_RESULT([$found_xft])
	dnl make sure that compiling against Xft header file doesn't bomb
	if test "$found_xft" = "yes" ; then
	    tk_oldCFlags=$CFLAGS
	    CFLAGS="$CFLAGS $XINCLUDES $XFT_CFLAGS"
	    tk_oldLibs=$LIBS
461
462
463
464
465
466
467



















































468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
621







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-
+







    else
	UNIX_FONT_OBJS=tkUnixFont.o
    fi
    AC_SUBST(XFT_CFLAGS)
    AC_SUBST(XFT_LIBS)
    AC_SUBST(UNIX_FONT_OBJS)
fi

#--------------------------------------------------------------------
#	Check for XkbKeycodeToKeysym.
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    tk_oldCFlags=$CFLAGS
    tk_oldLibs=$LIBS
    CFLAGS="$CFLAGS $XINCLUDES"
    LIBS="$LIBS $XLIBSW"
    AC_CHECK_HEADER(X11/XKBlib.h, [
	xkblib_header_found=yes
    ], [
	xkblib_header_found=no
    ], [#include <X11/Xlib.h>])
    if test $xkblib_header_found = "yes" ; then
	AC_CHECK_LIB(X11, XkbKeycodeToKeysym, [
	    xkbkeycodetokeysym_found=yes
	], [
	    xkbkeycodetokeysym_found=no
	])
    else
	xkbkeycodetokeysym_found=no
    fi
    if test $xkbkeycodetokeysym_found = "yes" ; then
	AC_DEFINE(HAVE_XKBKEYCODETOKEYSYM, 1, [Do we have XkbKeycodeToKeysym?])
    fi
    CFLAGS=$tk_oldCFlags
    LIBS=$tk_oldLibs
fi

#--------------------------------------------------------------------
# Check whether XKeycodeToKeysym is deprecated in X11 headers.
#--------------------------------------------------------------------

if test $tk_aqua = no && test "$GCC" = yes; then
    AC_MSG_CHECKING([whether XKeycodeToKeysym is deprecated])
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS -Werror"
    AC_TRY_LINK([
	#include <X11/Xlib.h>
    ], [
	XKeycodeToKeysym(0,0,0);
    ], [
	AC_MSG_RESULT([no])
    ], [
    AC_MSG_RESULT([yes])
	AC_DEFINE(XKEYCODETOKEYSYM_IS_DEPRECATED, 1, [Is XKeycodeToKeysym deprecated?])
	])
    CFLAGS=$tk_oldCFlags
fi

#--------------------------------------------------------------------
# XXX Do this last.
# It might modify XLIBSW which could affect other tests.
#
# Check whether the header and library for the XScreenSaver
# extension are available, and set HAVE_XSS if so.
# XScreenSaver is needed for Tk_GetUserInactiveTime().
#--------------------------------------------------------------------

if test $tk_aqua = no; then
    tk_oldCFlags=$CFLAGS
    CFLAGS="$CFLAGS $XINCLUDES"
    tk_oldLibs=$LIBS
    LIBS="$tk_oldLibs $XLIBSW"
    xss_header_found=no
    xss_lib_found=no
    AC_MSG_CHECKING([whether to try to use XScreenSaver])
    AC_ARG_ENABLE(xss,
	AS_HELP_STRING([--enable-xss],
	AC_HELP_STRING([--enable-xss],
	    [use XScreenSaver for activity timer (default: on)]),
	[enable_xss=$enableval], [enable_xss=yes])
    if test "$enable_xss" = "no" ; then
	AC_MSG_RESULT([$enable_xss])
    else
	AC_MSG_RESULT([$enable_xss])
	AC_CHECK_HEADER(X11/extensions/scrnsaver.h, [
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

576
577

578
579
580
581
582
583
584
656
657
658
659
660
661
662


663




664
665
666
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693



694


695
696
697
698
699
700
701
702







-
-

-
-
-
-











-
+


















-
-
-
+
-
-
+







#--------------------------------------------------------------------
#	The statements below define a collection of symbols related to
#	building libtk as a shared library instead of a static library.
#--------------------------------------------------------------------

eval eval "TK_UNSHARED_LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}"
eval eval "TK_SHARED_LIB_SUFFIX=${SHARED_LIB_SUFFIX}"
eval "TK_LIB_FILE_TCL8=libtk${LIB_SUFFIX}"
if test ${TCL_MAJOR_VERSION} = 8 ; then
eval "TK_LIB_FILE=libtk${LIB_SUFFIX}"
else
eval "TK_LIB_FILE=libtcl9tk${LIB_SUFFIX}"
fi
eval "TK_LIB_FILE_TCL9=libtcl9tk${LIB_SUFFIX}"

# tkConfig.sh needs a version of the _LIB_SUFFIX that has been eval'ed
# since on some platforms TK_LIB_FILE contains shell escapes.

eval "TK_LIB_FILE=${TK_LIB_FILE}"

if test "${SHARED_BUILD}" = "1" -a "${SHLIB_SUFFIX}" != ""; then
    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \${TCL_STUB_LIB_SPEC}"
    TCL_STUB_FLAGS="-DUSE_TCL_STUBS"
fi

test -z "$TK_LIBRARY" && TK_LIBRARY='$(prefix)/lib/tk$(VERSION)'
TK_LIBRARY='$(prefix)/lib/tk$(VERSION)'
PRIVATE_INCLUDE_DIR='$(includedir)'
HTML_DIR='$(DISTDIR)/html'
TK_PKG_DIR='tk$(VERSION)'
TK_RSRC_FILE='tk$(VERSION).rsrc'
WISH_RSRC_FILE='wish$(VERSION).rsrc'

# Note:  in the following variable, it's important to use the absolute
# path name of the Tcl directory rather than "..":  this is because
# AIX remembers this path and will attempt to use it at run-time to look
# up the Tcl library.

if test "`uname -s`" = "Darwin" ; then
    SC_ENABLE_FRAMEWORK
    TK_SHLIB_LD_EXTRAS="-compatibility_version ${TK_VERSION} -current_version ${TK_VERSION}`echo ${TK_PATCH_LEVEL} | awk ['{match($0, "\\\.[0-9]+"); print substr($0,RSTART,RLENGTH)}']`"
    TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -install_name "${DYLIB_INSTALL_DIR}/${TK_LIB_FILE}" -unexported_symbols_list $$(f=$(TK_LIB_FILE).E && nm -gp tkMacOSX*.o 2>/dev/null | awk "/^[[0-9a-f]]+ . \.objc/ {print \$$3}" > $$f && nm -gjp "$(TCL_BIN_DIR)"/$(TCL_STUB_LIB_FILE) | grep ^_[[^_]] >> $$f && echo $$f)'
    echo "$LDFLAGS " | grep -q -- '-prebind ' && TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -seg1addr 0xb000000'
    TK_SHLIB_LD_EXTRAS="${TK_SHLIB_LD_EXTRAS}"' -sectcreate __TEXT __info_plist Tk-Info.plist'
    EXTRA_WISH_LIBS='-sectcreate __TEXT __info_plist Wish-Info.plist'
    EXTRA_WISH_LIBS=${EXTRA_WISH_LIBS}' -sectcreate __TEXT __credits_html Credits.html'
    if test "${SHARED_BUILD}" = "0"; then
	EXTRA_WISH_LIBS=${EXTRA_WISH_LIBS}' -ObjC'
    EXTRA_APP_CC_SWITCHES="${EXTRA_APP_CC_SWITCHES}"' -mdynamic-no-pic'
    fi
    AC_CONFIG_FILES([Tk-Info.plist:../macosx/Tk-Info.plist.in Wish-Info.plist:../macosx/Wish-Info.plist.in Credits.html:../macosx/Credits.html.in])
    AC_CONFIG_FILES([Tk-Info.plist:../macosx/Tk-Info.plist.in Wish-Info.plist:../macosx/Wish-Info.plist.in])
    for l in ${LOCALES}; do CFBUNDLELOCALIZATIONS="${CFBUNDLELOCALIZATIONS}<string>$l</string>"; done
    TK_YEAR="`date +%Y`"
fi

if test "$FRAMEWORK_BUILD" = "1" ; then
    AC_DEFINE(TK_FRAMEWORK, 1, [Is Tk built as a framework?])
    # Construct a fake local framework structure to make linking with
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

650
651
652
653

654
655

656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715








716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
710
711
712
713
714
715
716


717





718
719
720
721
722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
748
749
750
751
752
753




754

755
756
757
758

759
760

761
762
763
764
765
766













































767
768
769
770
771
772
773



774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790










791
792
793
794
795
796
797
798
799
800
801
802
803


804
805
806
807
808
809
810







-
-
+
-
-
-
-
-














-









-













-
-
-
-

-
+



-
+

-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-













-
-







        unset n f v
    ], VERSION=${TK_VERSION} && tk_aqua=${tk_aqua})
    LD_LIBRARY_PATH_VAR="DYLD_FRAMEWORK_PATH"
    if test "${libdir}" = '${exec_prefix}/lib'; then
        # override libdir default
        libdir="/Library/Frameworks"
    fi
    if test ${TCL_MAJOR_VERSION} = 8 ; then
	TK_LIB_FILE="Tk"
    TK_LIB_FILE="Tk"
    else
	TK_LIB_FILE="Tk"
    fi
    TK_LIB_FILE_TCL8="Tk"
    TK_LIB_FILE_TCL9="Tk"
    TK_LIB_FLAG="-framework Tk"
    TK_BUILD_LIB_SPEC="-F`pwd | sed -e 's/ /\\\\ /g'` -framework Tk"
    TK_LIB_SPEC="-F${libdir} -framework Tk"
    libdir="${libdir}/Tk.framework/Versions/\${VERSION}"
    TK_LIBRARY="${libdir}/Resources/Scripts"
    TK_PKG_DIR="Resources/Scripts"
    TK_RSRC_FILE="Tk.rsrc"
    WISH_RSRC_FILE="Wish.rsrc"
    includedir="${libdir}/Headers"
    PRIVATE_INCLUDE_DIR="${libdir}/PrivateHeaders"
    HTML_DIR="${libdir}/Resources/Documentation/Reference/Tk"
    EXTRA_INSTALL="install-private-headers html-tk"
    EXTRA_BUILD_HTML='@ln -fs contents.htm "$(HTML_INSTALL_DIR)"/TkTOC.html'
    EXTRA_INSTALL_BINARIES='@echo "Installing Info.plist to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) Tk-Info.plist "$(LIB_INSTALL_DIR)/Resources/Info.plist"'
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Credits.html to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && $(INSTALL_DATA) Credits.html "$(LIB_INSTALL_DIR)/Resources"'
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing license.terms to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA) "$(TOP_DIR)/license.terms" "$(LIB_INSTALL_DIR)/Resources"'
    if test $tk_aqua = yes; then
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Images to $(LIB_INSTALL_DIR)/Resources/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)/Resources" && for i in Tk.tiff Tk.icns; do $(INSTALL_DATA) "$(MAC_OSX_DIR)/$$i" "$(LIB_INSTALL_DIR)/Resources"; done'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing wish$(VERSION) script to $(INSTALL_ROOT)/'"${bindir}"'/" && $(INSTALL_DATA_DIR) "$(INSTALL_ROOT)/'"${bindir}"'" && printf > "$(INSTALL_ROOT)/'"${bindir}"'/wish$(VERSION)" "#!/bin/sh\n\"\$$(dirname \$$0)'"`eval d="${bindir}"; echo "$d" | sed -e 's#/[^/][^/]*#/..#g'`"'$(bindir)/Wish\" \"\$$@\"" && chmod +x "$(INSTALL_ROOT)/'"${bindir}"'/wish$(VERSION)"'
	bindir="${libdir}/Resources/Wish.app/Contents/MacOS"
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Info.plist to $(BIN_INSTALL_DIR)/.." && $(INSTALL_DATA) Wish-Info.plist "$(BIN_INSTALL_DIR)/../Info.plist" && mv -f "$(BIN_INSTALL_DIR)/wish$(VERSION)" "$(BIN_INSTALL_DIR)/Wish"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Wish.icns to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA_DIR) "$(BIN_INSTALL_DIR)/../Resources"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && $(INSTALL_DATA) "$(MAC_OSX_DIR)/Tk.icns" "$(BIN_INSTALL_DIR)/../Resources/Wish.icns"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Wish.sdef to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA) "$(MAC_OSX_DIR)/Wish.sdef" "$(BIN_INSTALL_DIR)/../Resources"'
	EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Installing Credits.html to $(BIN_INSTALL_DIR)/../Resources" && $(INSTALL_DATA) Credits.html "$(BIN_INSTALL_DIR)/../Resources"'
    fi
    EXTRA_INSTALL_BINARIES="$EXTRA_INSTALL_BINARIES"' && echo "Finalizing Tk.framework" && rm -f "$(LIB_INSTALL_DIR)/../Current" && ln -s "$(VERSION)" "$(LIB_INSTALL_DIR)/../Current" && for f in "$(LIB_FILE)" tkConfig.sh Resources Headers PrivateHeaders; do rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/Current/$$f" "$(LIB_INSTALL_DIR)/../.."; done && f="$(STUB_LIB_FILE)" && rm -f "$(LIB_INSTALL_DIR)/../../$$f" && ln -s "Versions/$(VERSION)/$$f" "$(LIB_INSTALL_DIR)/../.."'
    # Don't use AC_DEFINE for the following as the framework version define
    # needs to go into the Makefile even when using autoheader, so that we
    # can pick up a potential make override of VERSION. Also, don't put this
    # into CFLAGS as it should not go into tkConfig.sh
    EXTRA_CC_SWITCHES="$EXTRA_CC_SWITCHES"' -DTK_FRAMEWORK_VERSION=\"$(VERSION)\"'
else
    if test $tk_aqua = yes; then
        EXTRA_INSTALL_BINARIES='@echo "Installing Images to $(LIB_INSTALL_DIR)/" && $(INSTALL_DATA_DIR) "$(LIB_INSTALL_DIR)" && for i in Tk.tiff Tk.icns; do $(INSTALL_DATA) "$(MAC_OSX_DIR)/$$i" "$(LIB_INSTALL_DIR)"; done'
    fi
    # libdir must be a fully qualified path and not ${exec_prefix}/lib
    eval libdir="$libdir"
    TK_LIB_FLAG="-l"
    if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
	TK_LIB_FLAG="${TK_LIB_FLAG}tcl9"
    fi
    if test "${ac_cv_cygwin}" = "yes" -a "$SHARED_BUILD" = "1"; then
	TK_LIB_FLAG="${TK_LIB_FLAG}tk`echo ${TK_VERSION} | tr -d .`"
	TK_LIB_FLAG="-ltk`echo ${TK_VERSION} | tr -d .`"
	TK_BUILD_LIB_SPEC="-L\$(TOP_DIR)/win ${TK_LIB_FLAG}"
    else
	if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
	    TK_LIB_FLAG="${TK_LIB_FLAG}tk${TK_VERSION}"
	    TK_LIB_FLAG="-ltk${TK_VERSION}"
	else
	    TK_LIB_FLAG="${TK_LIB_FLAG}tk`echo ${TK_VERSION} | tr -d .`"
	    TK_LIB_FLAG="-ltk`echo ${TK_VERSION} | tr -d .`"
	fi
	TK_BUILD_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TK_LIB_FLAG}"
    fi
    TK_LIB_SPEC="-L${libdir} ${TK_LIB_FLAG}"
fi

#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
AC_ARG_ENABLE(zipfs,
    AS_HELP_STRING([--enable-zipfs],[build with Zipfs support (default: on)]),
    [tcl_ok=$enableval], [tcl_ok=yes])
if test "$tcl_ok" = "yes" -a "x$enable_framework" != "xyes"; then
    #
    # Find a native compiler
    #
    AX_CC_FOR_BUILD
    #
    # Find a native zip implementation
    #
    SC_ZIPFS_SUPPORT
	ZIPFS_BUILD=1
	TK_ZIP_FILE=libtk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${TK_PATCH_LEVEL}.zip
else
	ZIPFS_BUILD=0
	TK_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
AC_MSG_CHECKING([for building with zipfs])
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;
       AC_DEFINE(ZIPFS_BUILD, 2, [Are we building with zipfs enabled?])
       INSTALL_LIBRARIES=install-demos
       AC_MSG_RESULT([yes])
     else
       AC_DEFINE(ZIPFS_BUILD, 1, [Are we building with zipfs enabled?])\
       INSTALL_LIBRARIES=install-demos
       AC_MSG_RESULT([yes])
    fi
else
AC_MSG_RESULT([no])
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi
AC_SUBST(ZIPFS_BUILD)
AC_SUBST(TK_ZIP_FILE)
AC_SUBST(INSTALL_LIBRARIES)
AC_SUBST(INSTALL_MSGS)


#--------------------------------------------------------------------
#       The statements below define various symbols relating to Tk
#       stub support.
#--------------------------------------------------------------------

# Replace ${VERSION} with contents of ${TK_VERSION}
    TK_STUB_LIB_FILE="libtkstub.a"
    TK_STUB_LIB_FLAG="-ltkstub"
eval "TK_STUB_LIB_DIR=\"${libdir}\""
eval "TK_STUB_LIB_FILE=libtkstub${TK_UNSHARED_LIB_SUFFIX}"
eval "TK_STUB_LIB_DIR=${libdir}"

if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
    TK_STUB_LIB_FLAG="-ltkstub${TK_VERSION}"
else
    TK_STUB_LIB_FLAG="-ltkstub`echo ${TK_VERSION} | tr -d .`"
fi

TK_BUILD_STUB_LIB_SPEC="-L`pwd | sed -e 's/ /\\\\ /g'` ${TK_STUB_LIB_FLAG}"
TK_STUB_LIB_SPEC="-L${TK_STUB_LIB_DIR} ${TK_STUB_LIB_FLAG}"
TK_BUILD_STUB_LIB_PATH="`pwd`/${TK_STUB_LIB_FILE}"
TK_STUB_LIB_PATH="${TK_STUB_LIB_DIR}/${TK_STUB_LIB_FILE}"

# Install time header dir can be set via --includedir
eval "TK_INCLUDE_SPEC=\"-I${includedir}\""

#------------------------------------------------------------------------
# Demo dir
#------------------------------------------------------------------------

AS_IF([test x"${DEMO_DIR}" = x], [DEMO_DIR='$(TK_LIBRARY)/demos'])
eval "TK_DEMO_DIR=\"`echo ${DEMO_DIR} | tr '()' '{}'`\""
eval "TK_DEMO_DIR=\"`echo ${TK_DEMO_DIR} | tr '()' '{}'`\""
AC_SUBST(DEMO_DIR)
AC_SUBST(TK_DEMO_DIR)

#------------------------------------------------------------------------
# tkConfig.sh refers to this by a different name
#------------------------------------------------------------------------

TK_SHARED_BUILD=${SHARED_BUILD}

AC_SUBST(TK_VERSION)
AC_SUBST(TK_MAJOR_VERSION)
AC_SUBST(TK_MINOR_VERSION)
AC_SUBST(TK_PATCH_LEVEL)
AC_SUBST(TK_YEAR)

AC_SUBST(TK_LIB_FILE)
AC_SUBST(TK_LIB_FILE_TCL8)
AC_SUBST(TK_LIB_FILE_TCL9)
AC_SUBST(TK_LIB_FLAG)
AC_SUBST(TK_LIB_SPEC)
AC_SUBST(TK_STUB_LIB_FILE)
AC_SUBST(TK_STUB_LIB_FLAG)
AC_SUBST(TK_STUB_LIB_SPEC)
AC_SUBST(TK_STUB_LIB_PATH)
AC_SUBST(TK_INCLUDE_SPEC)

Changes to unix/install-sh.

1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







#!/bin/sh
# install - install a program, script, or datafile

scriptversion=2020-11-14.01; # UTC
scriptversion=2011-04-20.01; # UTC

# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47

48
49

50

51

52




53
54
55
56
57
58
59
60
61
62
63
64
65











66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150







151
152
153

154
155
156
157
158
159
160


161
162
163
164

165
166
167
168
169

170
171

172
173
174
175
176


177
178
179


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253

254
255
256
257
258

259
260

261
262
263
264
265
266
267
268

269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

296




297
298


299
300
301
302



303
304
305

306
307
308
309
310
311

312


























313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
















328
329
330
331
332
333
334







335
336
337


338
339
340







341
342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359







360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379




















380
381
382
383
384
385


386
387
388
389
390

391
392
393
394
395
396
397



398


399
400
401
402

403
404
405

406
407
408
409
410
411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431


















432
433
434
435
436
437
438
439





440
441
442
443
444
445
446
447
448
449
450
451
452
453


454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487





488
489
490


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524















525
526
527


528
529
530
531
532
533
534
535
536

537
538
539

540
541
31
32
33
34
35
36
37

38
39
40
41
42
43

44
45

46
47

48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86





87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121


122
123

124
125
126
127
128
129








130
131
132
133
134
135
136
137
138
139
140

141
142
143
144
145






146
147
148
149
150
151
152
153
154

155
156


157
158


159
160
161



162





163
164

165
166
167
168


169
170
171


172
173
174
175
176
177
178
179










180
181
182
183
184
185
186
187
188
189
190
191
192




193
194
195
196
197
198
199
200

201
202
203
204
205









206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223

224
225
226
227
228

229
230

231
232
233
234
235
236
237
238

239
240

241
242
243
244
245
246
247
248




249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272



273
274
275
276
277

278




279
280
281

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312





313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333







334
335
336
337
338
339
340
341


342
343



344
345
346
347
348
349
350





351





352








353
354
355
356
357
358
359




















360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383


384
385
386
387
388
389

390
391
392
393
394



395
396
397
398
399
400
401
402
403

404
405
406

407
408
409
410
411
412
413

414
415


















416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436





437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453


454
455
456
457
458
459
460












461
462
463
464
465
466
467
468
469
470
471
472
473
474
475



476
477
478
479
480
481
482

483
484
485
486
487
488
489







490
491
492
493
494
495
496















497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512


513
514
515
516
517
518
519
520
521
522

523
524
525

526
527
528







-
+





-


-
+

-
+

+

+
-
+
+
+
+













+
+
+
+
+
+
+
+
+
+
+






-
-
-
-
-













-
+
















-
+




-
-
+
+
-






-
-
-
-
-
-
-
-











-
+




-
-
-
-
-
-
+
+
+
+
+
+
+


-
+

-
-


-
-
+
+

-
-
-
+
-
-
-
-
-
+

-
+



-
-
+
+

-
-
+
+






-
-
-
-
-
-
-
-
-
-













-
-
-
-








-
+




-
-
-
-
-
-
-
-
-
















-
+

-
+




-
+

-
+







-
+

-
+







-
-
-
-














+

+
+
+
+

-
+
+

-
-
-
+
+
+


-
+
-
-
-
-


+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
-
-
-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-

-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
+




-
+




-
-
-
+
+
+

+
+



-
+


-
+






-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+












-
-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
+














-
-
-
+
+
+
+
+


-
+
+





-
-
-
-
-
-
-







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+








-
+


-
+


# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# 'make' implicit rules from creating a file called install from it
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.

tab='	'
nl='
'
IFS=" $tab$nl"
IFS=" ""	$nl"

# Set DOITPROG to "echo" to test this script.
# set DOITPROG to echo to test this script

# Don't use :- since 4.3BSD and earlier shells don't like it.
doit=${DOITPROG-}
if test -z "$doit"; then
doit_exec=${doit:-exec}
  doit_exec=exec
else
  doit_exec=$doit
fi

# Put in absolute file names if you don't have them in your path;
# or use environment vars.

chgrpprog=${CHGRPPROG-chgrp}
chmodprog=${CHMODPROG-chmod}
chownprog=${CHOWNPROG-chown}
cmpprog=${CMPPROG-cmp}
cpprog=${CPPROG-cp}
mkdirprog=${MKDIRPROG-mkdir}
mvprog=${MVPROG-mv}
rmprog=${RMPROG-rm}
stripprog=${STRIPPROG-strip}

posix_glob='?'
initialize_posix_glob='
  test "$posix_glob" != "?" || {
    if (set -f) 2>/dev/null; then
      posix_glob=
    else
      posix_glob=:
    fi
  }
'

posix_mkdir=

# Desired mode of installed file.
mode=0755

# Create dirs (including intermediate dirs) using mode 755.
# This is like GNU 'install' as of coreutils 8.32 (2020).
mkdir_umask=22

backupsuffix=
chgrpcmd=
chmodcmd=$chmodprog
chowncmd=
mvcmd=$mvprog
rmcmd="$rmprog -f"
stripcmd=

src=
dst=
dir_arg=
dst_arg=

copy_on_change=false
is_target_a_directory=possibly
no_target_directory=

usage="\
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
   or: $0 [OPTION]... SRCFILES... DIRECTORY
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
   or: $0 [OPTION]... -d DIRECTORIES...

In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.

Options:
     --help     display this help and exit.
     --version  display version info and exit.

  -c            (ignored)
  -C            install only if different (preserve data modification time)
  -C            install only if different (preserve the last data modification time)
  -d            create directories instead of installing files.
  -g GROUP      $chgrpprog installed files to GROUP.
  -m MODE       $chmodprog installed files to MODE.
  -o USER       $chownprog installed files to USER.
  -p            pass -p to $cpprog.
  -s            $stripprog installed files.
  -s            $stripprog installed files.
  -S            $stripprog installed files.
  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
  -t DIRECTORY  install into DIRECTORY.
  -T            report an error if DSTFILE is a directory.

Environment variables override the default commands:
  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
  RMPROG STRIPPROG

By default, rm is invoked with -f; when overridden with RMPROG,
it's up to you to specify -f if you want it.

If -S is not specified, no backups are attempted.

Email bug reports to [email protected].
Automake home page: https://www.gnu.org/software/automake/
"

while test $# -ne 0; do
  case $1 in
    -c) ;;

    -C) copy_on_change=true;;

    -d) dir_arg=true;;

    -g) chgrpcmd="$chgrpprog $2"
        shift;;
	shift;;

    --help) echo "$usage"; exit $?;;

    -m) mode=$2
        case $mode in
          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
            echo "$0: invalid mode: $mode" >&2
            exit 1;;
        esac
        shift;;
	case $mode in
	  *' '* | *'	'* | *'
'*	  | *'*'* | *'?'* | *'['*)
	    echo "$0: invalid mode: $mode" >&2
	    exit 1;;
	esac
	shift;;

    -o) chowncmd="$chownprog $2"
        shift;;
	shift;;

    -p) cpprog="$cpprog -p";;

    -s) stripcmd=$stripprog;;

    -S) backupsuffix="$2"
        shift;;
    -S) stripcmd="$stripprog $2"
	shift;;

    -t)
        is_target_a_directory=always
        dst_arg=$2
    -t) dst_arg=$2
        # Protect names problematic for 'test' and other utilities.
        case $dst_arg in
          -* | [=\(\)!]) dst_arg=./$dst_arg;;
        esac
        shift;;
	shift;;

    -T) is_target_a_directory=never;;
    -T) no_target_directory=true;;

    --version) echo "$0 $scriptversion"; exit $?;;

    --) shift
        break;;
    --)	shift
	break;;

    -*) echo "$0: invalid option: $1" >&2
        exit 1;;
    -*)	echo "$0: invalid option: $1" >&2
	exit 1;;

    *)  break;;
  esac
  shift
done

# We allow the use of options -d and -T together, by making -d
# take the precedence; this is for compatibility with GNU install.

if test -n "$dir_arg"; then
  if test -n "$dst_arg"; then
    echo "$0: target directory not allowed when installing a directory." >&2
    exit 1
  fi
fi

if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
  # When -d is used, all remaining arguments are directories to create.
  # When -t is used, the destination is already specified.
  # Otherwise, the last argument is the destination.  Remove it from $@.
  for arg
  do
    if test -n "$dst_arg"; then
      # $@ is not empty: it contains at least $arg.
      set fnord "$@" "$dst_arg"
      shift # fnord
    fi
    shift # arg
    dst_arg=$arg
    # Protect names problematic for 'test' and other utilities.
    case $dst_arg in
      -* | [=\(\)!]) dst_arg=./$dst_arg;;
    esac
  done
fi

if test $# -eq 0; then
  if test -z "$dir_arg"; then
    echo "$0: no input file specified." >&2
    exit 1
  fi
  # It's OK to call 'install-sh -d' without argument.
  # It's OK to call `install-sh -d' without argument.
  # This can happen when creating conditional directories.
  exit 0
fi

if test -z "$dir_arg"; then
  if test $# -gt 1 || test "$is_target_a_directory" = always; then
    if test ! -d "$dst_arg"; then
      echo "$0: $dst_arg: Is not a directory." >&2
      exit 1
    fi
  fi
fi

if test -z "$dir_arg"; then
  do_exit='(exit $ret); exit $ret'
  trap "ret=129; $do_exit" 1
  trap "ret=130; $do_exit" 2
  trap "ret=141; $do_exit" 13
  trap "ret=143; $do_exit" 15

  # Set umask so as not to create temps with too-generous modes.
  # However, 'strip' requires both read and write access to temps.
  case $mode in
    # Optimize common cases.
    *644) cp_umask=133;;
    *755) cp_umask=22;;

    *[0-7])
      if test -z "$stripcmd"; then
        u_plus_rw=
	u_plus_rw=
      else
        u_plus_rw='% 200'
	u_plus_rw='% 200'
      fi
      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
    *)
      if test -z "$stripcmd"; then
        u_plus_rw=
	u_plus_rw=
      else
        u_plus_rw=,u+rw
	u_plus_rw=,u+rw
      fi
      cp_umask=$mode$u_plus_rw;;
  esac
fi

for src
do
  # Protect names problematic for 'test' and other utilities.
  # Protect names starting with `-'.
  case $src in
    -* | [=\(\)!]) src=./$src;;
    -*) src=./$src;;
  esac

  if test -n "$dir_arg"; then
    dst=$src
    dstdir=$dst
    test -d "$dstdir"
    dstdir_status=$?
    # Don't chown directories that already exist.
    if test $dstdir_status = 0; then
      chowncmd=""
    fi
  else

    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
    # might cause directories to be created, which would be especially bad
    # if $src (and thus $dsttmp) contains '*'.
    if test ! -f "$src" && test ! -d "$src"; then
      echo "$0: $src does not exist." >&2
      exit 1
    fi

    if test -z "$dst_arg"; then
      echo "$0: no destination specified." >&2
      exit 1
    fi

    dst=$dst_arg
    # Protect names starting with `-'.
    case $dst in
      -*) dst=./$dst;;
    esac

    # If destination is a directory, append the input filename.
    # If destination is a directory, append the input filename; won't work
    # if double slashes aren't ignored.
    if test -d "$dst"; then
      if test "$is_target_a_directory" = never; then
        echo "$0: $dst_arg: Is a directory" >&2
        exit 1
      if test -n "$no_target_directory"; then
	echo "$0: $dst_arg: Is a directory" >&2
	exit 1
      fi
      dstdir=$dst
      dstbase=`basename "$src"`
      dst=$dstdir/`basename "$src"`
      case $dst in
	*/) dst=$dst$dstbase;;
	*)  dst=$dst/$dstbase;;
      esac
      dstdir_status=0
    else
      # Prefer dirname, but fall back on a substitute if dirname fails.
      dstdir=`dirname "$dst"`
      dstdir=`
	(dirname "$dst") 2>/dev/null ||
	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	     X"$dst" : 'X\(//\)[^/]' \| \
	     X"$dst" : 'X\(//\)$' \| \
	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
	echo X"$dst" |
	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
		   s//\1/
		   q
		 }
		 /^X\(\/\/\)[^/].*/{
		   s//\1/
		   q
		 }
		 /^X\(\/\/\)$/{
		   s//\1/
		   q
		 }
		 /^X\(\/\).*/{
		   s//\1/
		   q
		 }
		 s/.*/./; q'
      `

      test -d "$dstdir"
      dstdir_status=$?
    fi
  fi

  case $dstdir in
    */) dstdirslash=$dstdir;;
    *)  dstdirslash=$dstdir/;;
  esac

  obsolete_mkdir_used=false

  if test $dstdir_status != 0; then
    case $posix_mkdir in
      '')
	# Create intermediate dirs using mode 755 as modified by the umask.
	# This is like FreeBSD 'install' as of 1997-10-28.
	umask=`umask`
	case $stripcmd.$umask in
	  # Optimize common cases.
	  *[2367][2367]) mkdir_umask=$umask;;
	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;

	  *[0-7])
	    mkdir_umask=`expr $umask + 22 \
	      - $umask % 100 % 40 + $umask % 20 \
	      - $umask % 10 % 4 + $umask % 2
	    `;;
	  *) mkdir_umask=$umask,go-w;;
	esac

        # With -d, create the new directory with the user-specified mode.
        # Otherwise, rely on $mkdir_umask.
        if test -n "$dir_arg"; then
          mkdir_mode=-m$mode
        else
          mkdir_mode=
        fi
	# With -d, create the new directory with the user-specified mode.
	# Otherwise, rely on $mkdir_umask.
	if test -n "$dir_arg"; then
	  mkdir_mode=-m$mode
	else
	  mkdir_mode=
	fi

        posix_mkdir=false
	# The $RANDOM variable is not portable (e.g., dash).  Use it
	posix_mkdir=false
	case $umask in
	# here however when possible just to lower collision chance.
	tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$

	  *[123567][0-7][0-7])
	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
	    ;;
	  *)
	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
	trap '
	  ret=$?
	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
	  exit $ret
	' 0

	# Because "mkdir -p" follows existing symlinks and we likely work
	# directly in world-writeable /tmp, make sure that the '$tmpdir'
	# directory is successfully created first before we actually test
	# 'mkdir -p'.
	if (umask $mkdir_umask &&
	    if (umask $mkdir_umask &&
	    $mkdirprog $mkdir_mode "$tmpdir" &&
	    exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
	then
	  if test -z "$dir_arg" || {
	       # Check for POSIX incompatibilities with -m.
	       # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
	       # other-writable bit of parent directory when it shouldn't.
	       # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
	    then
	      if test -z "$dir_arg" || {
		   # Check for POSIX incompatibilities with -m.
		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
		   # other-writeable bit of parent directory when it shouldn't.
		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
	       test_tmpdir="$tmpdir/a"
	       ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
	       case $ls_ld_tmpdir in
		 d????-?r-*) different_mode=700;;
		 d????-?--*) different_mode=755;;
		 *) false;;
	       esac &&
	       $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
		 ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
		 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
	       }
	     }
	  then posix_mkdir=:
	  fi
	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
	else
	  # Remove any dirs left behind by ancient mkdir implementations.
	  rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
	fi
	trap '' 0;;
		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
		   case $ls_ld_tmpdir in
		     d????-?r-*) different_mode=700;;
		     d????-?--*) different_mode=755;;
		     *) false;;
		   esac &&
		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
		   }
		 }
	      then posix_mkdir=:
	      fi
	      rmdir "$tmpdir/d" "$tmpdir"
	    else
	      # Remove any dirs left behind by ancient mkdir implementations.
	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
	    fi
	    trap '' 0;;
	esac;;
    esac

    if
      $posix_mkdir && (
        umask $mkdir_umask &&
        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
	umask $mkdir_umask &&
	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
      )
    then :
    else

      # mkdir does not conform to POSIX,
      # The umask is ridiculous, or mkdir does not conform to POSIX,
      # or it failed possibly due to a race condition.  Create the
      # directory the slow way, step by step, checking for races as we go.

      case $dstdir in
        /*) prefix='/';;
        [-=\(\)!]*) prefix='./';;
        *)  prefix='';;
	/*) prefix='/';;
	-*) prefix='./';;
	*)  prefix='';;
      esac

      eval "$initialize_posix_glob"

      oIFS=$IFS
      IFS=/
      set -f
      $posix_glob set -f
      set fnord $dstdir
      shift
      set +f
      $posix_glob set +f
      IFS=$oIFS

      prefixes=

      for d
      do
        test X"$d" = X && continue
	test -z "$d" && continue

        prefix=$prefix$d
        if test -d "$prefix"; then
          prefixes=
        else
          if $posix_mkdir; then
            (umask $mkdir_umask &&
             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
            # Don't fail if two instances are running concurrently.
            test -d "$prefix" || exit 1
          else
            case $prefix in
              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
              *) qprefix=$prefix;;
            esac
            prefixes="$prefixes '$qprefix'"
          fi
        fi
        prefix=$prefix/
	prefix=$prefix$d
	if test -d "$prefix"; then
	  prefixes=
	else
	  if $posix_mkdir; then
	    (umask=$mkdir_umask &&
	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
	    # Don't fail if two instances are running concurrently.
	    test -d "$prefix" || exit 1
	  else
	    case $prefix in
	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
	      *) qprefix=$prefix;;
	    esac
	    prefixes="$prefixes '$qprefix'"
	  fi
	fi
	prefix=$prefix/
      done

      if test -n "$prefixes"; then
        # Don't fail if two instances are running concurrently.
        (umask $mkdir_umask &&
         eval "\$doit_exec \$mkdirprog $prefixes") ||
          test -d "$dstdir" || exit 1
        obsolete_mkdir_used=true
	# Don't fail if two instances are running concurrently.
	(umask $mkdir_umask &&
	 eval "\$doit_exec \$mkdirprog $prefixes") ||
	  test -d "$dstdir" || exit 1
	obsolete_mkdir_used=true
      fi
    fi
  fi

  if test -n "$dir_arg"; then
    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
  else

    # Make a couple of temp file names in the proper directory.
    dsttmp=${dstdirslash}_inst.$$_
    rmtmp=${dstdirslash}_rm.$$_
    dsttmp=$dstdir/_inst.$$_
    rmtmp=$dstdir/_rm.$$_

    # Trap to clean up those temp files at exit.
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0

    # Copy the file name to the temp name.
    (umask $cp_umask &&
     { test -z "$stripcmd" || {
	 # Create $dsttmp read-write so that cp doesn't create it read-only,
	 # which would cause strip to fail.
	 if test -z "$doit"; then
	   : >"$dsttmp" # No need to fork-exec 'touch'.
	 else
	   $doit touch "$dsttmp"
	 fi
       }
     } &&
     $doit_exec $cpprog "$src" "$dsttmp") &&
    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&

    # and set any options; do chmod last to preserve setuid bits.
    #
    # If any of these fail, we abort the whole thing.  If we want to
    # ignore errors from any of these, just make sure not to ignore
    # errors from the above "$doit $cpprog $src $dsttmp" command.
    #
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&

    # If -C, don't bother to copy if it wouldn't change the file.
    if $copy_on_change &&
       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
       set -f &&
       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&

       eval "$initialize_posix_glob" &&
       $posix_glob set -f &&
       set X $old && old=:$2:$4:$5:$6 &&
       set X $new && new=:$2:$4:$5:$6 &&
       set +f &&
       $posix_glob set +f &&

       test "$old" = "$new" &&
       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
    then
      rm -f "$dsttmp"
    else
      # If $backupsuffix is set, and the file being installed
      # already exists, attempt a backup.  Don't worry if it fails,
      # e.g., if mv doesn't support -f.
      if test -n "$backupsuffix" && test -f "$dst"; then
        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
      fi

      # Rename the file to the real destination.
      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||

      # The rename failed, perhaps because mv can't rename something else
      # to itself, or perhaps because mv is so ancient that it does not
      # support -f.
      {
        # Now remove or move aside any old file at destination location.
        # We try this two ways since rm can't unlink itself on some
        # systems and the destination file might be busy for other
        # reasons.  In this case, the final cleanup might fail but the new
        # file should still install successfully.
        {
          test ! -f "$dst" ||
          $doit $rmcmd "$dst" 2>/dev/null ||
          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
            { $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
          } ||
          { echo "$0: cannot unlink or rename $dst" >&2
            (exit 1); exit 1
          }
        } &&
	# Now remove or move aside any old file at destination location.
	# We try this two ways since rm can't unlink itself on some
	# systems and the destination file might be busy for other
	# reasons.  In this case, the final cleanup might fail but the new
	# file should still install successfully.
	{
	  test ! -f "$dst" ||
	  $doit $rmcmd -f "$dst" 2>/dev/null ||
	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
	  } ||
	  { echo "$0: cannot unlink or rename $dst" >&2
	    (exit 1); exit 1
	  }
	} &&

        # Now rename the file to the real destination.
        $doit $mvcmd "$dsttmp" "$dst"
	# Now rename the file to the real destination.
	$doit $mvcmd "$dsttmp" "$dst"
      }
    fi || exit 1

    trap '' 0
  fi
done

# Local variables:
# eval: (add-hook 'before-save-hook 'time-stamp)
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC0"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:

Changes to unix/installManPage.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15

16
17
18
19
20
21
22
1
2
3
4
5
6
7


8
9
10
11
12
13

14
15
16
17
18
19
20
21







-
-
+





-
+







#!/bin/sh

########################################################################
### Parse Options
###

Gzip=:
Sym=""
Loc=""
SymOrLoc=""
Gz=""
Suffix=""

while true; do
    case $1 in
        -s | --symlinks  )      Sym="-s "      ;;
        -s | --symlinks  ) SymOrLoc="-s "      ;;
        -z | --compress  )     Gzip=$2;  shift ;;
	-e | --extension )       Gz=$2;  shift ;;
	-x | --suffix    )   Suffix=$2;  shift ;;
	-*) cat <<EOF
Unknown option "$1". Supported options:
    -s         Use symbolic links for manpages with multiple names.
    -z PROG    Use PROG to compress manual pages.
40
41
42
43
44
45
46
47

48
49
50
51

52
53
54
55
56
57
58
39
40
41
42
43
44
45

46
47
48
49

50
51
52
53
54
55
56
57







-
+



-
+








ManPage=$1
Dir=$2
if test -f $ManPage ; then : ; else
    echo "source manual page file must exist"
    exit 1
fi
if test -d "$Dir" ; then : ; else
if test -d $Dir ; then : ; else
    echo "target directory must exist"
    exit 1
fi
test -z "$Sym" && Loc="$Dir/"
test -z "$SymOrLoc" && SymOrLoc="$Dir/"

########################################################################
### Extract Target Names from Manual Page
###

# A sed script to parse the alternative names out of a man page.
#
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119



120
121

122
123
124
125
126
88
89
90
91
92
93
94

95
96
97
98
99
100







101
102
103

104
105
106
107



108
109
110
111

112
113
114
115
116
117







-






-
-
-
-
-
-
-



-
+



-
-
-
+
+
+

-
+





    *.1) Section=1 ;;
    *.3) Section=3 ;;
    *.n) Section=n ;;
    *)	echo "unknown section for $ManPage"
	exit 2 ;;
esac

Name=`basename $ManPage .$Section`
SrcDir=`dirname $ManPage`

########################################################################
### Process Page to Create Target Pages
###

Specials="DString Thread Notifier RegExp library packagens pkgMkIndex safesock FindPhoto FontId MeasureChar"
for n in $Specials; do
    if [ "$Name" = "$n" ] ; then
	Names="$n $Names"
    fi
done

First=""
for Target in $Names; do
    Target=$Target.$Section$Suffix
    rm -f "$Dir/$Target" "$Dir/$Target.*"
    rm -f $Dir/$Target $Dir/$Target.*
    if test -z "$First" ; then
	First=$Target
	sed -e "/man\.macros/r $SrcDir/man.macros" -e "/man\.macros/d" \
	    $ManPage > "$Dir/$First"
	chmod 644 "$Dir/$First"
	$Gzip "$Dir/$First"
	    $ManPage > $Dir/$First
	chmod 444 $Dir/$First
	$Gzip $Dir/$First
    else
	ln $Sym"$Loc$First$Gz" "$Dir/$Target$Gz"
	ln $SymOrLoc$First$Gz $Dir/$Target$Gz
    fi
done

########################################################################
exit 0

Changes to unix/tcl.m4.

24
25
26
27
28
29
30
31

32
33

34
35
36
37
38
39
40
24
25
26
27
28
29
30

31
32

33
34
35
36
37
38
39
40







-
+

-
+







    # the alternative search directory is invoked by --with-tcl
    #

    if test x"${no_tcl}" = x ; then
	# we reset no_tcl in case something fails here
	no_tcl=true
	AC_ARG_WITH(tcl,
	    AS_HELP_STRING([--with-tcl],
	    AC_HELP_STRING([--with-tcl],
		[directory containing tcl configuration (tclConfig.sh)]),
	    [with_tclconfig="${withval}"])
	    with_tclconfig="${withval}")
	AC_MSG_CHECKING([for Tcl configuration])
	AC_CACHE_VAL(ac_cv_c_tclconfig,[

	    # First check to see if --with-tcl was specified.
	    if test x"${with_tclconfig}" != x ; then
		case "${with_tclconfig}" in
		    */tclConfig.sh )
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96

97
98


99
100
101
102
103
104
105







+













-

+

-


-
-







	    fi

	    # on Darwin, check in Framework installation locations
	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then
		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
			`ls -d /Library/Frameworks 2>/dev/null` \
			`ls -d /Network/Library/Frameworks 2>/dev/null` \
			`ls -d /System/Library/Frameworks 2>/dev/null` \
			; do
		    if test -f "$i/Tcl.framework/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i/Tcl.framework; pwd)`"
			break
		    fi
		done
	    fi

	    # check in a few common install locations
	    if test x"${ac_cv_c_tclconfig}" = x ; then
		for i in `ls -d ${libdir} 2>/dev/null` \
			`ls -d ${exec_prefix}/lib 2>/dev/null` \
			`ls -d ${prefix}/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/contrib/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/pkg/lib 2>/dev/null` \
			`ls -d /usr/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/lib 2>/dev/null` \
			`ls -d /usr/lib64 2>/dev/null` \
			`ls -d /usr/local/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl9.0 2>/dev/null` \
			; do
		    if test -f "$i/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i; pwd)`"
			break
		    fi
		done
	    fi
157
158
159
160
161
162
163
164

165
166

167
168
169
170
171
172
173
155
156
157
158
159
160
161

162
163

164
165
166
167
168
169
170
171







-
+

-
+







    # the alternative search directory is invoked by --with-tk
    #

    if test x"${no_tk}" = x ; then
	# we reset no_tk in case something fails here
	no_tk=true
	AC_ARG_WITH(tk,
	    AS_HELP_STRING([--with-tk],
	    AC_HELP_STRING([--with-tk],
		[directory containing tk configuration (tkConfig.sh)]),
	    [with_tkconfig="${withval}"])
	    with_tkconfig="${withval}")
	AC_MSG_CHECKING([for Tk configuration])
	AC_CACHE_VAL(ac_cv_c_tkconfig,[

	    # First check to see if --with-tkconfig was specified.
	    if test x"${with_tkconfig}" != x ; then
		case "${with_tkconfig}" in
		    */tkConfig.sh )
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226


227
228


229
230
231
232
233
234
235







+















-
-


-
-







	    fi

	    # on Darwin, check in Framework installation locations
	    if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tkconfig}" = x ; then
		for i in `ls -d ~/Library/Frameworks 2>/dev/null` \
			`ls -d /Library/Frameworks 2>/dev/null` \
			`ls -d /Network/Library/Frameworks 2>/dev/null` \
			`ls -d /System/Library/Frameworks 2>/dev/null` \
			; do
		    if test -f "$i/Tk.framework/tkConfig.sh" ; then
			ac_cv_c_tkconfig="`(cd $i/Tk.framework; pwd)`"
			break
		    fi
		done
	    fi

	    # check in a few common install locations
	    if test x"${ac_cv_c_tkconfig}" = x ; then
		for i in `ls -d ${libdir} 2>/dev/null` \
			`ls -d ${exec_prefix}/lib 2>/dev/null` \
			`ls -d ${prefix}/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/contrib/lib 2>/dev/null` \
			`ls -d /usr/pkg/lib 2>/dev/null` \
			`ls -d /usr/lib/tk9.0 2>/dev/null` \
			`ls -d /usr/lib 2>/dev/null` \
			`ls -d /usr/lib64 2>/dev/null` \
			`ls -d /usr/local/lib/tk9.0 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tk9.0 2>/dev/null` \
			; do
		    if test -f "$i/tkConfig.sh" ; then
			ac_cv_c_tkconfig="`(cd $i; pwd)`"
			break
		    fi
		done
	    fi
288
289
290
291
292
293
294




295
296
297
298
299
300
301
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300







+
+
+
+








    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
        AC_MSG_RESULT([loading])
	. "${TCL_BIN_DIR}/tclConfig.sh"
    else
        AC_MSG_RESULT([could not find ${TCL_BIN_DIR}/tclConfig.sh])
    fi

    # eval is required to do the TCL_DBGX substitution
    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""

    # If the TCL_BIN_DIR is the build directory (not the install directory),
    # then set the common variable name to the value of the build variables.
    # For example, the variable TCL_LIB_SPEC will be set to the value
    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
    # installed and uninstalled version of Tcl.
321
322
323
324
325
326
327






328
329
330
331
332
333
334
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339







+
+
+
+
+
+







		if test -f "${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"; then
		    TCL_STUB_LIB_SPEC="-L`echo "${TCL_BIN_DIR}"  | sed -e 's/ /\\\\ /g'` ${TCL_STUB_LIB_FLAG}"
		    TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"
		fi
		;;
	esac
    fi

    # eval is required to do the TCL_DBGX substitution
    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""

    AC_SUBST(TCL_VERSION)
    AC_SUBST(TCL_PATCH_LEVEL)
    AC_SUBST(TCL_BIN_DIR)
    AC_SUBST(TCL_SRC_DIR)

    AC_SUBST(TCL_LIB_FILE)
361
362
363
364
365
366
367




368
369
370
371
372
373
374
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383







+
+
+
+








    if test -f "${TK_BIN_DIR}/tkConfig.sh" ; then
        AC_MSG_RESULT([loading])
	. "${TK_BIN_DIR}/tkConfig.sh"
    else
        AC_MSG_RESULT([could not find ${TK_BIN_DIR}/tkConfig.sh])
    fi

    # eval is required to do the TK_DBGX substitution
    eval "TK_LIB_FILE=\"${TK_LIB_FILE}\""
    eval "TK_STUB_LIB_FILE=\"${TK_STUB_LIB_FILE}\""

    # If the TK_BIN_DIR is the build directory (not the install directory),
    # then set the common variable name to the value of the build variables.
    # For example, the variable TK_LIB_SPEC will be set to the value
    # of TK_BUILD_LIB_SPEC. An extension should make use of TK_LIB_SPEC
    # instead of TK_BUILD_LIB_SPEC since it will work with both an
    # installed and uninstalled version of Tcl.
394
395
396
397
398
399
400






401
402
403
404
405
406
407
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422







+
+
+
+
+
+







		if test -f "${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"; then
		    TK_STUB_LIB_SPEC="-L` echo "${TK_BIN_DIR}"  | sed -e 's/ /\\\\ /g'` ${TK_STUB_LIB_FLAG}"
		    TK_STUB_LIB_PATH="${TK_BIN_DIR}/${TK_STUB_LIB_FILE}"
		fi
		;;
	esac
    fi

    # eval is required to do the TK_DBGX substitution
    eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}\""
    eval "TK_LIB_SPEC=\"${TK_LIB_SPEC}\""
    eval "TK_STUB_LIB_FLAG=\"${TK_STUB_LIB_FLAG}\""
    eval "TK_STUB_LIB_SPEC=\"${TK_STUB_LIB_SPEC}\""

    AC_SUBST(TK_VERSION)
    AC_SUBST(TK_BIN_DIR)
    AC_SUBST(TK_SRC_DIR)

    AC_SUBST(TK_LIB_FILE)
    AC_SUBST(TK_LIB_FLAG)
504
505
506
507
508
509
510
511

512
513








514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548
549
550
551







-
+


+
+
+
+
+
+
+
+








-







#	Sets the following vars:
#		SHARED_BUILD	Value of 1 or 0
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_SHARED], [
    AC_MSG_CHECKING([how to build libraries])
    AC_ARG_ENABLE(shared,
	AS_HELP_STRING([--enable-shared],
	AC_HELP_STRING([--enable-shared],
	    [build and link with shared libraries (default: on)]),
	[tcl_ok=$enableval], [tcl_ok=yes])

    if test "${enable_shared+set}" = set; then
	enableval="$enable_shared"
	tcl_ok=$enableval
    else
	tcl_ok=yes
    fi

    if test "$tcl_ok" = "yes" ; then
	AC_MSG_RESULT([shared])
	SHARED_BUILD=1
    else
	AC_MSG_RESULT([static])
	SHARED_BUILD=0
	AC_DEFINE(STATIC_BUILD, 1, [Is this a static build?])
    fi
    AC_SUBST(SHARED_BUILD)
])

#------------------------------------------------------------------------
# SC_ENABLE_FRAMEWORK --
#
#	Allows the building of shared libraries into frameworks
#
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
561
562
563
564
565
566
567

568
569
570
571
572
573
574
575







-
+







#		FRAMEWORK_BUILD	Value of 1 or 0
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_FRAMEWORK], [
    if test "`uname -s`" = "Darwin" ; then
	AC_MSG_CHECKING([how to package libraries])
	AC_ARG_ENABLE(framework,
	    AS_HELP_STRING([--enable-framework],
	    AC_HELP_STRING([--enable-framework],
		[package shared libraries in MacOSX frameworks (default: off)]),
	    [enable_framework=$enableval], [enable_framework=no])
	if test $enable_framework = yes; then
	    if test $SHARED_BUILD = 0; then
		AC_MSG_WARN([Frameworks can only be built if --enable-shared is yes])
		enable_framework=no
	    fi
565
566
567
568
569
570
571











































































































572
573
574
575
576
577
578
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	    else
		AC_MSG_RESULT([static library])
	    fi
	    FRAMEWORK_BUILD=0
	fi
    fi
])

#------------------------------------------------------------------------
# SC_ENABLE_THREADS --
#
#	Specify if thread support should be enabled
#
# Arguments:
#	none
#
# Results:
#
#	Adds the following arguments to configure:
#		--enable-threads
#
#	Sets the following vars:
#		THREADS_LIBS	Thread library(s)
#
#	Defines the following vars:
#		TCL_THREADS
#		_REENTRANT
#		_THREAD_SAFE
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_THREADS], [
    AC_ARG_ENABLE(threads,
	AC_HELP_STRING([--enable-threads],
	    [build with threads (default: on)]),
	[tcl_ok=$enableval], [tcl_ok=yes])

    if test "${TCL_THREADS}" = 1; then
	tcl_threaded_core=1;
    fi

    if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then
	TCL_THREADS=1
	# USE_THREAD_ALLOC tells us to try the special thread-based
	# allocator that significantly reduces lock contention
	AC_DEFINE(USE_THREAD_ALLOC, 1,
	    [Do we want to use the threaded memory allocator?])
	AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
	if test "`uname -s`" = "SunOS" ; then
	    AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1,
		    [Do we really want to follow the standard? Yes we do!])
	fi
	AC_DEFINE(_THREAD_SAFE, 1, [Do we want the thread-safe OS API?])
	AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no)
	if test "$tcl_ok" = "no"; then
	    # Check a little harder for __pthread_mutex_init in the same
	    # library, as some systems hide it there until pthread.h is
	    # defined.  We could alternatively do an AC_TRY_COMPILE with
	    # pthread.h, but that will work with libpthread really doesn't
	    # exist, like AIX 4.2.  [Bug: 4359]
	    AC_CHECK_LIB(pthread, __pthread_mutex_init,
		tcl_ok=yes, tcl_ok=no)
	fi

	if test "$tcl_ok" = "yes"; then
	    # The space is needed
	    THREADS_LIBS=" -lpthread"
	else
	    AC_CHECK_LIB(pthreads, pthread_mutex_init,
		tcl_ok=yes, tcl_ok=no)
	    if test "$tcl_ok" = "yes"; then
		# The space is needed
		THREADS_LIBS=" -lpthreads"
	    else
		AC_CHECK_LIB(c, pthread_mutex_init,
		    tcl_ok=yes, tcl_ok=no)
		if test "$tcl_ok" = "no"; then
		    AC_CHECK_LIB(c_r, pthread_mutex_init,
			tcl_ok=yes, tcl_ok=no)
		    if test "$tcl_ok" = "yes"; then
			# The space is needed
			THREADS_LIBS=" -pthread"
		    else
			TCL_THREADS=0
			AC_MSG_WARN([Don't know how to find pthread lib on your system - you must disable thread support or edit the LIBS in the Makefile...])
		    fi
		fi
	    fi
	fi

	# Does the pthread-implementation provide
	# 'pthread_attr_setstacksize' ?

	ac_saved_libs=$LIBS
	LIBS="$LIBS $THREADS_LIBS"
	AC_CHECK_FUNCS(pthread_attr_setstacksize pthread_atfork)
	LIBS=$ac_saved_libs
    else
	TCL_THREADS=0
    fi
    # Do checking message here to not mess up interleaved configure output
    AC_MSG_CHECKING([for building with threads])
    if test "${TCL_THREADS}" = 1; then
	AC_DEFINE(TCL_THREADS, 1, [Are we building with threads enabled?])
	if test "${tcl_threaded_core}" = 1; then
	    AC_MSG_RESULT([yes (threaded core)])
	else
	    AC_MSG_RESULT([yes])
	fi
    else
	AC_MSG_RESULT([no])
    fi

    AC_SUBST(TCL_THREADS)
])

#------------------------------------------------------------------------
# SC_ENABLE_SYMBOLS --
#
#	Specify if debugging symbols should be used.
#	Memory (TCL_MEM_DEBUG) and compile (TCL_COMPILE_DEBUG) debugging
#	can also be enabled.
592
593
594
595
596
597
598


599
600
601
602
603
604

605
606
607

608
609
610
611
612
613
614
721
722
723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744
745
746







+
+





-
+



+







#		--enable-symbols
#
#	Defines the following vars:
#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
#				Sets to $(CFLAGS_OPTIMIZE) if false
#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
#				Sets to $(LDFLAGS_OPTIMIZE) if false
#		DBGX		Formerly used as debug library extension;
#				always blank now.
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_SYMBOLS], [
    AC_MSG_CHECKING([for build with symbols])
    AC_ARG_ENABLE(symbols,
	AS_HELP_STRING([--enable-symbols],
	AC_HELP_STRING([--enable-symbols],
	    [build with debugging symbols (default: off)]),
	[tcl_ok=$enableval], [tcl_ok=no])
# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
    DBGX=""
    if test "$tcl_ok" = "no"; then
	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'
	AC_DEFINE(NDEBUG, 1, [Is no debugging enabled?])
	AC_MSG_RESULT([no])
	AC_DEFINE(TCL_CFG_OPTIMIZED, 1, [Is this an optimized build?])
    else
656
657
658
659
660
661
662
663

664
665
666
667
668
669
670
671
672
673
674
675


676
677
678
679
680
681
682
788
789
790
791
792
793
794

795
796
797
798
799
800
801
802
803
804
805


806
807
808
809
810
811
812
813
814







-
+










-
-
+
+







#
#	Defines the following vars:
#		HAVE_LANGINFO	Triggers use of nl_langinfo if defined.
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_LANGINFO], [
    AC_ARG_ENABLE(langinfo,
	AS_HELP_STRING([--enable-langinfo],
	AC_HELP_STRING([--enable-langinfo],
	    [use nl_langinfo if possible to determine encoding at startup, otherwise use old heuristic (default: on)]),
	[langinfo_ok=$enableval], [langinfo_ok=yes])

    HAVE_LANGINFO=0
    if test "$langinfo_ok" = "yes"; then
	AC_CHECK_HEADER(langinfo.h,[langinfo_ok=yes],[langinfo_ok=no])
    fi
    AC_MSG_CHECKING([whether to use nl_langinfo])
    if test "$langinfo_ok" = "yes"; then
	AC_CACHE_VAL(tcl_cv_langinfo_h, [
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]], [[nl_langinfo(CODESET);]])],
		    [tcl_cv_langinfo_h=yes], [tcl_cv_langinfo_h=no])])
	    AC_TRY_COMPILE([#include <langinfo.h>], [nl_langinfo(CODESET);],
		    [tcl_cv_langinfo_h=yes],[tcl_cv_langinfo_h=no])])
	AC_MSG_RESULT([$tcl_cv_langinfo_h])
	if test $tcl_cv_langinfo_h = yes; then
	    AC_DEFINE(HAVE_LANGINFO, 1, [Do we have nl_langinfo()?])
	fi
    else
	AC_MSG_RESULT([$langinfo_ok])
    fi
708
709
710
711
712
713
714
715

716
717
718


719
720
721
722
723

724
725
726
727
728
729
730

731
732
733
734
735
736
737
738
739
740
741
742
743
744

745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
840
841
842
843
844
845
846

847
848


849
850
851
852
853
854

855
856
857
858
859
860
861

862
863
864
865
866
867
868
869
870
871
872
873
874
875

876
877
878
879
880
881
882

883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917



918
919
920
921
922
923
924







-
+

-
-
+
+




-
+






-
+













-
+






-
+



















-















-
-
-







#			according to the user's selection.
#
#--------------------------------------------------------------------

AC_DEFUN([SC_CONFIG_MANPAGES], [
    AC_MSG_CHECKING([whether to use symlinks for manpages])
    AC_ARG_ENABLE(man-symlinks,
	AS_HELP_STRING([--enable-man-symlinks],
	AC_HELP_STRING([--enable-man-symlinks],
	    [use symlinks for the manpages (default: off)]),
	[test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks"],
	[enableval="no"])
	test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks",
	enableval="no")
    AC_MSG_RESULT([$enableval])

    AC_MSG_CHECKING([whether to compress the manpages])
    AC_ARG_ENABLE(man-compression,
	AS_HELP_STRING([--enable-man-compression=PROG],
	AC_HELP_STRING([--enable-man-compression=PROG],
	    [compress the manpages with PROG (default: off)]),
	[case $enableval in
	    yes) AC_MSG_ERROR([missing argument to --enable-man-compression]);;
	    no)  ;;
	    *)   MAN_FLAGS="$MAN_FLAGS --compress $enableval";;
	esac],
	[enableval="no"])
	enableval="no")
    AC_MSG_RESULT([$enableval])
    if test "$enableval" != "no"; then
	AC_MSG_CHECKING([for compressed file suffix])
	touch TeST
	$enableval TeST
	Z=`ls TeST* | sed 's/^....//'`
	rm -f TeST*
	MAN_FLAGS="$MAN_FLAGS --extension $Z"
	AC_MSG_RESULT([$Z])
    fi

    AC_MSG_CHECKING([whether to add a package name suffix for the manpages])
    AC_ARG_ENABLE(man-suffix,
	AS_HELP_STRING([--enable-man-suffix=STRING],
	AC_HELP_STRING([--enable-man-suffix=STRING],
	    [use STRING as a suffix to manpage file names (default: no, AC_PACKAGE_NAME if enabled without specifying STRING)]),
	[case $enableval in
	    yes) enableval="AC_PACKAGE_NAME" MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
	    no)  ;;
	    *)   MAN_FLAGS="$MAN_FLAGS --suffix $enableval";;
	esac],
	[enableval="no"])
	enableval="no")
    AC_MSG_RESULT([$enableval])

    AC_SUBST(MAN_FLAGS)
])

#--------------------------------------------------------------------
# SC_CONFIG_SYSTEM
#
#	Determine what the system is (some things cannot be easily checked
#	on a feature-driven basis, alas). This can usually be done via the
#	"uname" command.
#
# Arguments:
#	none
#
# Results:
#	Defines the following var:
#
#	system -	System/platform/version identification code.
#
#--------------------------------------------------------------------

AC_DEFUN([SC_CONFIG_SYSTEM], [
    AC_CACHE_CHECK([system version], tcl_cv_sys_version, [
	if test "${TEA_PLATFORM}" = "windows" ; then
	    tcl_cv_sys_version=windows
	else
	    tcl_cv_sys_version=`uname -s`-`uname -r`
	    if test "$?" -ne 0 ; then
		AC_MSG_WARN([can't find uname command])
		tcl_cv_sys_version=unknown
	    else
		if test "`uname -s`" = "AIX" ; then
		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
		fi
		if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then
		    tcl_cv_sys_version=NetBSD-Debian
		fi
	    fi
	fi
    ])
    system=$tcl_cv_sys_version
])

#--------------------------------------------------------------------
881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897

898
899
900
901
902
903
904
905
906
907
908
909
910

911
912
913
914


915
916
917
918
919
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1061







-
+








-
+












-
+

-
-
-
+
+












-
+








AC_DEFUN([SC_CONFIG_CFLAGS], [

    # Step 0.a: Enable 64 bit support?

    AC_MSG_CHECKING([if 64bit support is requested])
    AC_ARG_ENABLE(64bit,
	AS_HELP_STRING([--enable-64bit],
	AC_HELP_STRING([--enable-64bit],
	    [enable 64bit support (default: off)]),
	[do64bit=$enableval], [do64bit=no])
    AC_MSG_RESULT([$do64bit])

    # Step 0.b: Enable Solaris 64 bit VIS support?

    AC_MSG_CHECKING([if 64bit Sparc VIS support is requested])
    AC_ARG_ENABLE(64bit-vis,
	AS_HELP_STRING([--enable-64bit-vis],
	AC_HELP_STRING([--enable-64bit-vis],
	    [enable 64bit Sparc VIS support (default: off)]),
	[do64bitVIS=$enableval], [do64bitVIS=no])
    AC_MSG_RESULT([$do64bitVIS])
    # Force 64bit on with VIS
    AS_IF([test "$do64bitVIS" = "yes"], [do64bit=yes])

    # Step 0.c: Check if visibility support is available. Do this here so
    # that platform specific alternatives can be used below if this fails.

    AC_CACHE_CHECK([if compiler supports visibility "hidden"],
	tcl_cv_cc_visibility_hidden, [
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_LINK([
	    extern __attribute__((__visibility__("hidden"))) void f(void);
	    void f(void) {}]], [[f();]])],
	    [tcl_cv_cc_visibility_hidden=yes],
	    [tcl_cv_cc_visibility_hidden=no])
	    void f(void) {}], [f();], tcl_cv_cc_visibility_hidden=yes,
	    tcl_cv_cc_visibility_hidden=no)
	CFLAGS=$hold_cflags])
    AS_IF([test $tcl_cv_cc_visibility_hidden = yes], [
	AC_DEFINE(MODULE_SCOPE,
	    [extern __attribute__((__visibility__("hidden")))],
	    [Compiler support for module scope symbols])
	AC_DEFINE(HAVE_HIDDEN, [1], [Compiler support for module scope symbols])
    ])

    # Step 0.d: Disable -rpath support?

    AC_MSG_CHECKING([if rpath support is requested])
    AC_ARG_ENABLE(rpath,
	AS_HELP_STRING([--disable-rpath],
	AC_HELP_STRING([--disable-rpath],
	    [disable rpath support (default: on)]),
	[doRpath=$enableval], [doRpath=yes])
    AC_MSG_RESULT([$doRpath])

    # Step 1: set the variable "system" to hold the name and version number
    # for the system.

956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971

972
973
974
975
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
1083
1084
1085
1086
1087
1088
1089









1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1111







-
-
-
-
-
-
-
-
-
+













-
+







    UNSHARED_LIB_SUFFIX=""
    TCL_TRIM_DOTS='`echo ${VERSION} | tr -d .`'
    ECHO_VERSION='`echo ${VERSION}`'
    TCL_LIB_VERSIONS_OK=ok
    CFLAGS_DEBUG=-g
    AS_IF([test "$GCC" = yes], [
	CFLAGS_OPTIMIZE=-O2
	CFLAGS_WARNING="-Wall -Wextra -Wshadow -Wundef -Wwrite-strings -Wpointer-arith"
	case "${CC}" in
	    *++|*++-*)
		;;
	    *)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wc++-compat -fextended-identifiers"
		;;
	esac

	CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement"
    ], [
	CFLAGS_OPTIMIZE=-O
	CFLAGS_WARNING=""
    ])
    AC_CHECK_TOOL(AR, ar)
    STLIB_LD='${AR} cr'
    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
    PLAT_OBJS=""
    PLAT_SRCS=""
    LDAIX_SRC=""
    AS_IF([test "x${SHLIB_VERSION}" = x], [SHLIB_VERSION="1.0"])
    case $system in
	AIX-*)
	    AS_IF([test "$GCC" != "yes"], [
	    AS_IF([test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"], [
		# AIX requires the _r compiler when gcc isn't being used
		case "${CC}" in
		    *_r|*_r\ *)
			# ok ...
			;;
		    *)
			# Make sure only first arg gets _r
1073
1074
1075
1076
1077
1078
1079
1080
1081


1082
1083
1084
1085
1086
1087
1088
1089



1090
1091
1092

1093
1094
1095
1096
1097
1098



1099
1100
1101
1102



1103
1104
1105

1106
1107

1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1192
1193
1194
1195
1196
1197
1198


1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213

1214
1215
1216
1217



1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229

1230
1231

1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1260







-
-
+
+








+
+
+


-
+



-
-
-
+
+
+




+
+
+


-
+

-
+




















-
+







	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	CYGWIN_*|MINGW32_*|MSYS_*)
	    SHLIB_CFLAGS="-fno-common"
	CYGWIN_*|MINGW32*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD='${CC} -shared'
	    SHLIB_SUFFIX=".dll"
	    DL_OBJS="tclLoadDl.o"
	    PLAT_OBJS='${CYGWIN_OBJS}'
	    PLAT_SRCS='${CYGWIN_SRCS}'
	    DL_LIBS="-ldl"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    TCL_NEEDS_EXP_FILE=1
	    TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.dll.a'
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$[@].a"
	    AC_CACHE_CHECK(for Cygwin version of gcc,
		ac_cv_cygwin,
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
		AC_TRY_COMPILE([
		#ifdef __CYGWIN__
		    #error cygwin
		#endif
		]], [[]])],
		[ac_cv_cygwin=no],
		[ac_cv_cygwin=yes])
		], [],
		ac_cv_cygwin=no,
		ac_cv_cygwin=yes)
	    )
	    if test "$ac_cv_cygwin" = "no"; then
		AC_MSG_ERROR([${CC} is not a cygwin compiler.])
	    fi
	    if test "x${TCL_THREADS}" = "x0"; then
		AC_MSG_ERROR([CYGWIN compile is only supported with --enable-threads])
	    fi
	    do64bit_ok=yes
	    if test "x${SHARED_BUILD}" = "x1"; then
		echo "running cd ../win; ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args --enable-64bit --host=x86_64-w64-mingw32"
		echo "running cd ../win; ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args"
		# The eval makes quoting arguments work.
		if cd ../win; eval ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args --enable-64bit --host=x86_64-w64-mingw32; cd ../unix
		if cd ../win; eval ${CONFIG_SHELL-/bin/sh} ./configure $ac_configure_args; cd ../unix
		then :
		else
		    { echo "configure: error: configure failed for ../win" 1>&2; exit 1; }
		fi
	    fi
	    ;;
	dgux*)
	    SHLIB_CFLAGS="-K PIC"
	    SHLIB_LD='${CC} -G'
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	Haiku*)
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-lroot"
	    AC_CHECK_LIB(network, inet_ntoa, [LIBS="$LIBS -lnetwork"])
	    ;;
	HP-UX-*.11.*)
	    # Use updated header definitions where possible
	    AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Do we want to use the XOPEN network library?])
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306







-
+







		AS_IF([test "$GCC" = yes], [
		    case `${CC} -dumpmachine` in
			hppa64*)
			    # 64-bit gcc in use.  Fix flags for GNU ld.
			    do64bit_ok=yes
			    SHLIB_LD='${CC} -shared'
			    AS_IF([test $doRpath = yes], [
				CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'])
				CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
			    ;;
			*)
			    AC_MSG_WARN([64bit mode not supported with GCC on $system])
			    ;;
		    esac
		], [
1202
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220

1221
1222
1223
1224
1225
1226
1227
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352







-
+










-
+







	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    AC_LIBOBJ(mkstemp)
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
	    ;;
	IRIX-6.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    AC_LIBOBJ(mkstemp)
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
	    AS_IF([test "$GCC" = yes], [
		CFLAGS="$CFLAGS -mabi=n32"
		LDFLAGS="$LDFLAGS -mabi=n32"
	    ], [
		case $system in
		    IRIX-6.3)
1239
1240
1241
1242
1243
1244
1245
1246

1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263


1264
1265
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287

1288
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321


1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335
1336
1337
1338

1339
1340
1341
1342

1343
1344
1345
1346





1347
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360

1361

1362
1363
1364
1365





1366



























1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387


1388
1389
1390
1391
1392
1393

1394
1395
1396
1397
1398
1399


1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422

1423
1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438




1439
1440
1441
1442
1443
1444
1445
1446


1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484




1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504




1505
1506
1507
1508
1509
1510
1511
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386


1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400










1401

1402
1403
1404
1405
1406
1407
1408


1409
1410
1411
1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433


1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457




1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475

1476
1477
1478




1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530


1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542


1543
1544
1545
1546
1547
1548
1549












1550
1551
1552
1553
1554

1555
1556
1557
1558
1559
1560
1561
1562


1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579



1580
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591

1592
1593
1594
1595
1596
1597

1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614




1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634




1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645







-
+















-
-
+
+








-
+



-
-
-
-
-
-
-
-
-
-

-
+






-
-
+








-
+















-
-
+
+











-
+




-
+




+
-
-
-
-
+
+
+
+
+







-
+





-
+

+
-
-
-
-
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

















-
-
+
+





-
+




-
-
+
+





-
-
-
-
-
-
-
-
-
-
-
-





-
+







-
-
+







+
+
+
+





-
-
-
+
+







-



-
+





-
+
















-
-
-
-
+
+
+
+
















-
-
-
-
+
+
+
+







	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    AC_LIBOBJ(mkstemp)
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])

	    # Check to enable 64-bit flags for compiler/linker

	    AS_IF([test "$do64bit" = yes], [
	        AS_IF([test "$GCC" = yes], [
	            AC_MSG_WARN([64bit mode not supported by gcc])
	        ], [
	            do64bit_ok=yes
	            SHLIB_LD="ld -64 -shared -rdata_shared"
	            CFLAGS="$CFLAGS -64"
	            LDFLAGS_ARCH="-64"
	        ])
	    ])
	    ;;
	Linux*|GNU*|NetBSD-Debian|DragonFly-*|FreeBSD-*)
	    SHLIB_CFLAGS="-fPIC -fno-common"
	Linux*|GNU*|NetBSD-Debian)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"

	    CFLAGS_OPTIMIZE="-O2"
	    # egcs-2.91.66 on Redhat Linux 6.0 generates lots of warnings
	    # when you inline the string and math operations.  Turn this off to
	    # get rid of the warnings.
	    #CFLAGS_OPTIMIZE="${CFLAGS_OPTIMIZE} -D__NO_STRING_INLINES -D__NO_MATH_INLINES"

	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"

	    case $system in
	    DragonFly-*|FreeBSD-*)
		# The -pthread needs to go in the LDFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
	    ;;
	    esac

	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'])
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    AS_IF([test "`uname -m`" = "alpha"], [CFLAGS="$CFLAGS -mieee"])
	    AS_IF([test $do64bit = yes], [
		AC_CACHE_CHECK([if compiler accepts -m64 flag], tcl_cv_cc_m64, [
		    hold_cflags=$CFLAGS
		    CFLAGS="$CFLAGS -m64"
		    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
			    [tcl_cv_cc_m64=yes],[tcl_cv_cc_m64=no])
		    AC_TRY_LINK(,, tcl_cv_cc_m64=yes, tcl_cv_cc_m64=no)
		    CFLAGS=$hold_cflags])
		AS_IF([test $tcl_cv_cc_m64 = yes], [
		    CFLAGS="$CFLAGS -m64"
		    do64bit_ok=yes
		])
	   ])

	    # The combo of gcc + glibc has a bug related to inlining of
	    # functions like strtol()/strtoul(). The -fno-builtin flag should address
	    # functions like strtod(). The -fno-builtin flag should address
	    # this problem but it does not work. The -fno-inline flag is kind
	    # of overkill but it works. Disable inlining only when one of the
	    # files in compat/*.c is being linked in.

	    AS_IF([test x"${USE_COMPAT}" != x],[CFLAGS="$CFLAGS -fno-inline"])
	    ;;
	Lynx*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    CFLAGS_OPTIMIZE=-02
	    SHLIB_LD='${CC} -shared'
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-mshared -ldl"
	    LD_FLAGS="-Wl,--export-dynamic"
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'])
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
	    ;;
	OpenBSD-*)
	    arch=`arch -s`
	    case "$arch" in
	    alpha|sparc64)
		SHLIB_CFLAGS="-fPIC"
		;;
	    *)
		SHLIB_CFLAGS="-fpic"
		;;
	    esac
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'])
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so.${SHLIB_VERSION}'
	    LDFLAGS="-Wl,-export-dynamic"
	    CFLAGS_OPTIMIZE="-O2"
	    AS_IF([test "${TCL_THREADS}" = "1"], [
	    # On OpenBSD:	Compile with -pthread
	    #		Don't link with -lpthread
	    LIBS=`echo $LIBS | sed s/-lpthread//`
	    CFLAGS="$CFLAGS -pthread"
		# On OpenBSD:	Compile with -pthread
		#		Don't link with -lpthread
		LIBS=`echo $LIBS | sed s/-lpthread//`
		CFLAGS="$CFLAGS -pthread"
	    ])
	    # OpenBSD doesn't do version numbers with dots.
	    UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
	    TCL_LIB_VERSIONS_OK=nodots
	    ;;
	NetBSD-*)
	    # NetBSD has ELF and can use 'cc -shared' to build shared libs
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}'
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'])
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    AS_IF([test "${TCL_THREADS}" = "1"], [
	    # The -pthread needs to go in the CFLAGS, not LIBS
	    LIBS=`echo $LIBS | sed s/-pthread//`
	    CFLAGS="$CFLAGS -pthread"
	    LDFLAGS="$LDFLAGS -pthread"
		# The -pthread needs to go in the CFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS -pthread"
	    	LDFLAGS="$LDFLAGS -pthread"
	    ])
	    ;;
	FreeBSD-*)
	    # This configuration from FreeBSD Ports.
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD="${CC} -shared"
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,-soname,\$[@]"
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    LDFLAGS=""
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'])
	    AS_IF([test "${TCL_THREADS}" = "1"], [
		# The -pthread needs to go in the LDFLAGS, not LIBS
		LIBS=`echo $LIBS | sed s/-pthread//`
		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		LDFLAGS="$LDFLAGS $PTHREAD_LIBS"])
	    case $system in
	    FreeBSD-3.*)
		# Version numbers are dot-stripped by system policy.
		TCL_TRIM_DOTS=`echo ${VERSION} | tr -d .`
		UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
		SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so'
		TCL_LIB_VERSIONS_OK=nodots
		;;
	    esac
	    ;;
	Darwin-*)
	    CFLAGS_OPTIMIZE="-O2"
	    CFLAGS_OPTIMIZE="-Os"
	    SHLIB_CFLAGS="-fno-common"
	    # To avoid discrepancies between what headers configure sees during
	    # preprocessing tests and compiling tests, move any -isysroot and
	    # -mmacosx-version-min flags from CFLAGS to CPPFLAGS:
	    CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if ([$]i~/^(isysroot|mmacosx-version-min)/) print "-"[$]i}'`"
	    CFLAGS="`echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if (!([$]i~/^(isysroot|mmacosx-version-min)/)) print "-"[$]i}'`"
	    AS_IF([test $do64bit = yes], [
		case `arch` in
		    ppc)
			AC_CACHE_CHECK([if compiler accepts -arch ppc64 flag],
				tcl_cv_cc_arch_ppc64, [
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
				    [tcl_cv_cc_arch_ppc64=yes],[tcl_cv_cc_arch_ppc64=no])
			    AC_TRY_LINK(,, tcl_cv_cc_arch_ppc64=yes,
				    tcl_cv_cc_arch_ppc64=no)
			    CFLAGS=$hold_cflags])
			AS_IF([test $tcl_cv_cc_arch_ppc64 = yes], [
			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    do64bit_ok=yes
			]);;
		    i386|x86_64)
		    i386)
			AC_CACHE_CHECK([if compiler accepts -arch x86_64 flag],
				tcl_cv_cc_arch_x86_64, [
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch x86_64"
			    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
				    [tcl_cv_cc_arch_x86_64=yes],[tcl_cv_cc_arch_x86_64=no])
			    AC_TRY_LINK(,, tcl_cv_cc_arch_x86_64=yes,
				    tcl_cv_cc_arch_x86_64=no)
			    CFLAGS=$hold_cflags])
			AS_IF([test $tcl_cv_cc_arch_x86_64 = yes], [
			    CFLAGS="$CFLAGS -arch x86_64"
			    do64bit_ok=yes
			]);;
		    arm64)
			AC_CACHE_CHECK([if compiler accepts -arch arm64 flag],
				tcl_cv_cc_arch_arm64, [
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch arm64"
			    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
				    [tcl_cv_cc_arch_arm64=yes],[tcl_cv_cc_arch_arm64=no])
			    CFLAGS=$hold_cflags])
			AS_IF([test $tcl_cv_cc_arch_arm64 = yes], [
			    CFLAGS="$CFLAGS -arch arm64"
			    do64bit_ok=yes
			]);;
		    *)
			AC_MSG_WARN([Don't know how enable 64-bit on architecture `arch`]);;
		esac
	    ], [
		# Check for combined 32-bit and 64-bit fat build
		AS_IF([echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64|arm64) ' \
		AS_IF([echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \
		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '], [
		    fat_32_64=yes])
	    ])
	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS}'
	    AC_CACHE_CHECK([if ld accepts -single_module flag], tcl_cv_ld_single_module, [
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
		AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int i;]])],[tcl_cv_ld_single_module=yes],
		    [tcl_cv_ld_single_module=no])
		AC_TRY_LINK(, [int i;], tcl_cv_ld_single_module=yes, tcl_cv_ld_single_module=no)
		LDFLAGS=$hold_ldflags])
	    AS_IF([test $tcl_cv_ld_single_module = yes], [
		SHLIB_LD="${SHLIB_LD} -Wl,-single_module"
	    ])
	    SHLIB_SUFFIX=".dylib"
	    DL_OBJS="tclLoadDyld.o"
	    DL_LIBS=""
	    # Don't use -prebind when building for Mac OS X 10.4 or later only:
	    AS_IF([test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int([$]2)}'`" -lt 4 -a \
		"`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int([$]2)}'`" -lt 4], [
		LDFLAGS="$LDFLAGS -prebind"])
	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
	    AC_CACHE_CHECK([if ld accepts -search_paths_first flag],
		    tcl_cv_ld_search_paths_first, [
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
		AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int i;]])],
			[tcl_cv_ld_search_paths_first=yes],
		    [tcl_cv_ld_search_paths_first=no])
		AC_TRY_LINK(, [int i;], tcl_cv_ld_search_paths_first=yes,
			tcl_cv_ld_search_paths_first=no)
		LDFLAGS=$hold_ldflags])
	    AS_IF([test $tcl_cv_ld_search_paths_first = yes], [
		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
	    ])
	    AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [
		AC_DEFINE(MODULE_SCOPE, [__private_extern__],
		    [Compiler support for module scope symbols])
		tcl_cv_cc_visibility_hidden=yes
	    ])
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    LD_LIBRARY_PATH_VAR="DYLD_FALLBACK_LIBRARY_PATH"
	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
	    AC_DEFINE(MAC_OSX_TCL, 1, [Is this a Mac I see before me?])
	    PLAT_OBJS='${MAC_OSX_OBJS}'
	    PLAT_SRCS='${MAC_OSX_SRCS}'
	    AC_MSG_CHECKING([whether to use CoreFoundation])
	    AC_ARG_ENABLE(corefoundation,
		AS_HELP_STRING([--enable-corefoundation],
		AC_HELP_STRING([--enable-corefoundation],
		    [use CoreFoundation API on MacOSX (default: on)]),
		[tcl_corefoundation=$enableval], [tcl_corefoundation=yes])
	    AC_MSG_RESULT([$tcl_corefoundation])
	    AS_IF([test $tcl_corefoundation = yes], [
		AC_CACHE_CHECK([for CoreFoundation.framework],
			tcl_cv_lib_corefoundation, [
		    hold_libs=$LIBS
		    AS_IF([test "$fat_32_64" = yes], [
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    # On Tiger there is no 64-bit CF, so remove 64-bit
			    # archs from CFLAGS et al. while testing for
			    # presence of CF. 64-bit CF is disabled in
			    # tclUnixPort.h if necessary.
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
			done])
		    LIBS="$LIBS -framework CoreFoundation"
		    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <CoreFoundation/CoreFoundation.h>]],
			[[CFBundleRef b = CFBundleGetMainBundle();]])],
			[tcl_cv_lib_corefoundation=yes],
			[tcl_cv_lib_corefoundation=no])
		    AC_TRY_LINK([#include <CoreFoundation/CoreFoundation.h>],
			[CFBundleRef b = CFBundleGetMainBundle();],
			tcl_cv_lib_corefoundation=yes,
			tcl_cv_lib_corefoundation=no)
		    AS_IF([test "$fat_32_64" = yes], [
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
		        done])
		    LIBS=$hold_libs])
		AS_IF([test $tcl_cv_lib_corefoundation = yes], [
		    LIBS="$LIBS -framework CoreFoundation"
		    AC_DEFINE(HAVE_COREFOUNDATION, 1,
			[Do we have access to Darwin CoreFoundation.framework?])
		], [tcl_corefoundation=no])
		AS_IF([test "$fat_32_64" = yes -a $tcl_corefoundation = yes],[
		    AC_CACHE_CHECK([for 64-bit CoreFoundation],
			    tcl_cv_lib_corefoundation_64, [
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
			done
			AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <CoreFoundation/CoreFoundation.h>]],
			    [[CFBundleRef b = CFBundleGetMainBundle();]])],
			    [tcl_cv_lib_corefoundation_64=yes],
			    [tcl_cv_lib_corefoundation_64=no])
			AC_TRY_LINK([#include <CoreFoundation/CoreFoundation.h>],
			    [CFBundleRef b = CFBundleGetMainBundle();],
			    tcl_cv_lib_corefoundation_64=yes,
			    tcl_cv_lib_corefoundation_64=no)
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
			done])
		    AS_IF([test $tcl_cv_lib_corefoundation_64 = no], [
			AC_DEFINE(NO_COREFOUNDATION_64, 1,
			    [Is Darwin CoreFoundation unavailable for 64-bit?])
                        LDFLAGS="$LDFLAGS -Wl,-no_arch_warnings"
1519
1520
1521
1522
1523
1524
1525
1526

1527
1528

1529
1530
1531
1532
1533
1534

1535
1536
1537
1538

1539
1540
1541
1542
1543
1544
1545
1546









1547
1548
1549
1550
1551

1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567


1568
1569
1570


1571
1572
1573
1574
1575
1576
1577
1653
1654
1655
1656
1657
1658
1659

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







-
+

-
+





-
+




+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+





+














-
-
+
+

-
-
+
+







	    AC_DEFINE(_OE_SOCKETS, 1,	# needed in sys/socket.h
		[Should OS/390 do the right thing with sockets?])
	    ;;
	OSF1-V*)
	    # Digital OSF/1
	    SHLIB_CFLAGS=""
	    AS_IF([test "$SHARED_BUILD" = 1], [
	        SHLIB_LD='${CC} -shared'
	        SHLIB_LD='ld -shared -expect_unresolved "*"'
	    ], [
	        SHLIB_LD='${CC} -non_shared'
	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'
	    ])
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    AS_IF([test $doRpath = yes], [
		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'])
	    AS_IF([test "$GCC" = yes], [CFLAGS="$CFLAGS -mieee"], [
		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"])
	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
	    AS_IF([test "${TCL_THREADS}" = 1], [
	    CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
	    CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
	    LIBS=`echo $LIBS | sed s/-lpthreads//`
	    AS_IF([test "$GCC" = yes], [
		LIBS="$LIBS -lpthread -lmach -lexc"
	    ], [
		CFLAGS="$CFLAGS -pthread"
		LDFLAGS="$LDFLAGS -pthread"
		CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
		CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
		LIBS=`echo $LIBS | sed s/-lpthreads//`
		AS_IF([test "$GCC" = yes], [
		    LIBS="$LIBS -lpthread -lmach -lexc"
		], [
		    CFLAGS="$CFLAGS -pthread"
		    LDFLAGS="$LDFLAGS -pthread"
		])
	    ])
	    ;;
	QNX-6*)
	    # QNX RTP
	    # This may work for all QNX, but it was only reported for v6.
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD="ld -Bshareable -x"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    # dlopen is in -lc on QNX
	    DL_LIBS=""
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	SCO_SV-3.2*)
	    # Note, dlopen is available only on SCO 3.2.5 and greater. However,
	    # this test works, since "uname -s" was non-standard in 3.2.4 and
	    # below.
	    AS_IF([test "$GCC" = yes], [
		SHLIB_CFLAGS="-fPIC -melf"
		LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
	    	SHLIB_CFLAGS="-fPIC -melf"
	    	LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"
	    ], [
		SHLIB_CFLAGS="-Kpic -belf"
		LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
	    	SHLIB_CFLAGS="-Kpic -belf"
	    	LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"
	    ])
	    SHLIB_LD="ld -G"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS=""
	    CC_SEARCH_FLAGS=""
1717
1718
1719
1720
1721
1722
1723
1724

1725
1726
1727
1728
1729
1730
1731
1854
1855
1856
1857
1858
1859
1860

1861
1862
1863
1864
1865
1866
1867
1868







-
+







	    DL_OBJS="tclLoadDl.o"
	    DL_LIBS="-ldl"
	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
	    # that don't grok the -Bexport option.  Test that it does.
	    AC_CACHE_CHECK([for ld accepts -Bexport flag], tcl_cv_ld_Bexport, [
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-Bexport"
		AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[int i;]])],[tcl_cv_ld_Bexport=yes],[tcl_cv_ld_Bexport=no])
		AC_TRY_LINK(, [int i;], tcl_cv_ld_Bexport=yes, tcl_cv_ld_Bexport=no)
	        LDFLAGS=$hold_ldflags])
	    AS_IF([test $tcl_cv_ld_Bexport = yes], [
		LDFLAGS="$LDFLAGS -Wl,-Bexport"
	    ])
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
1744
1745
1746
1747
1748
1749
1750
1751

1752
1753
1754
1755
1756
1757
1758
1881
1882
1883
1884
1885
1886
1887

1888
1889
1890
1891
1892
1893
1894
1895







-
+







dnl # both CPPFLAGS and CFLAGS (unlike our compile and link) but configure's
dnl # preprocessing tests use only CPPFLAGS.
    AC_CONFIG_COMMANDS_PRE([CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""])

    # Step 4: disable dynamic loading if requested via a command-line switch.

    AC_ARG_ENABLE(load,
	AS_HELP_STRING([--enable-load],
	AC_HELP_STRING([--enable-load],
	    [allow dynamic loading and "load" command (default: on)]),
	[tcl_ok=$enableval], [tcl_ok=yes])
    AS_IF([test "$tcl_ok" = no], [DL_OBJS=""])

    AS_IF([test "x$DL_OBJS" != x], [BUILD_DLTEST="\$(DLTEST_TARGETS)"], [
	AC_MSG_WARN([Can't figure out how to do dynamic loading or shared libraries on this system.])
	SHLIB_CFLAGS=""
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
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







-
+
-
-

-
-
-
+
+

















-
+

-
+







    # libraries to the right flags for gcc, instead of those for the
    # standard manufacturer compiler.

    AS_IF([test "$DL_OBJS" != "tclLoadNone.o" -a "$GCC" = yes], [
	case $system in
	    AIX-*) ;;
	    BSD/OS*) ;;
	    CYGWIN_*|MINGW32_*|MSYS_*) ;;
	    CYGWIN_*|MINGW32_*) ;;
	    HP-UX*) ;;
	    Darwin-*) ;;
	    IRIX*) ;;
	    Linux*|GNU*) ;;
	    NetBSD-*|OpenBSD-*) ;;
	    OSF1-*) ;;
	    NetBSD-*|FreeBSD-*|OpenBSD-*) ;;
	    Darwin-*) ;;
	    SCO_SV-3.2*) ;;
	    *) SHLIB_CFLAGS="-fPIC" ;;
	esac])

    AS_IF([test "$tcl_cv_cc_visibility_hidden" != yes], [
	AC_DEFINE(MODULE_SCOPE, [extern],
	    [No Compiler support for module scope symbols])
    ])

    AS_IF([test "$SHARED_LIB_SUFFIX" = ""], [
	SHARED_LIB_SUFFIX='${VERSION}${SHLIB_SUFFIX}'])
    AS_IF([test "$UNSHARED_LIB_SUFFIX" = ""], [
	UNSHARED_LIB_SUFFIX='${VERSION}.a'])
    DLL_INSTALL_DIR="\$(LIB_INSTALL_DIR)"

    AS_IF([test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""], [
        LIB_SUFFIX=${SHARED_LIB_SUFFIX}
        MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${LDFLAGS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
        MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
        AS_IF([test "${SHLIB_SUFFIX}" = ".dll"], [
            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)"'
            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)";if test -f $(LIB_FILE).a; then $(INSTALL_DATA) $(LIB_FILE).a "$(LIB_INSTALL_DIR)"; fi;'
            DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)"
        ], [
            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)/$(LIB_FILE)"'
        ])
    ], [
        LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}

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
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







-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-







    # Define TCL_LIBS now that we know what DL_LIBS is.
    # The trick here is that we don't want to change the value of TCL_LIBS if
    # it is already set when tclConfig.sh had been loaded by Tk.
    AS_IF([test "x${TCL_LIBS}" = x], [
        TCL_LIBS="${DL_LIBS} ${LIBS} ${MATH_LIBS}"])
    AC_SUBST(TCL_LIBS)

    # See if the compiler supports casting to a union type.
    # This is used to stop gcc from printing a compiler
    # warning when initializing a union member.
	# See if the compiler supports casting to a union type.
	# This is used to stop gcc from printing a compiler
	# warning when initializing a union member.

    AC_CACHE_CHECK(for cast to union support,
	tcl_cv_cast_to_union,
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
		union foo { int i; double d; };
		union foo f = (union foo) (int) 0;
	]])],
	[tcl_cv_cast_to_union=yes],
	[tcl_cv_cast_to_union=no])
    )
    if test "$tcl_cv_cast_to_union" = "yes"; then
	AC_DEFINE(HAVE_CAST_TO_UNION, 1,
		[Defined when compiler supports casting to union type.])
    fi
	AC_CACHE_CHECK(for cast to union support,
	    tcl_cv_cast_to_union,
	    AC_TRY_COMPILE([],
	    [
		  union foo { int i; double d; };
		  union foo f = (union foo) (int) 0;
	    ],
	    tcl_cv_cast_to_union=yes,
	    tcl_cv_cast_to_union=no)
	)
	if test "$tcl_cv_cast_to_union" = "yes"; then
	    AC_DEFINE(HAVE_CAST_TO_UNION, 1,
		    [Defined when compiler supports casting to union type.])
	fi
    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fno-lto"
    AC_CACHE_CHECK(for working -fno-lto,
	ac_cv_nolto,
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
	[ac_cv_nolto=yes],
	[ac_cv_nolto=no])
    )
    CFLAGS=$hold_cflags
    if test "$ac_cv_nolto" = "yes" ; then
	CFLAGS_NOLTO="-fno-lto"
    else
	CFLAGS_NOLTO=""
    fi
    AC_CACHE_CHECK([if the compiler understands -finput-charset],
	tcl_cv_cc_input_charset, [
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -finput-charset=UTF-8"
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[tcl_cv_cc_input_charset=yes],[tcl_cv_cc_input_charset=no])
	CFLAGS=$hold_cflags])
    if test $tcl_cv_cc_input_charset = yes; then
	CFLAGS="$CFLAGS -finput-charset=UTF-8"
    fi

    AC_CHECK_HEADER(stdbool.h, [AC_DEFINE(HAVE_STDBOOL_H, 1, [Do we have <stdbool.h>?])],)

    # Check for vfork, posix_spawnp() and friends unconditionally
    AC_CHECK_FUNCS(vfork posix_spawnp posix_spawn_file_actions_adddup2 posix_spawnattr_setflags)

    # FIXME: This subst was left in only because the TCL_DL_LIBS
    # entry in tclConfig.sh uses it. It is not clear why someone
    # would use TCL_DL_LIBS instead of TCL_LIBS.
    AC_SUBST(DL_LIBS)

    AC_SUBST(DL_OBJS)
    AC_SUBST(PLAT_OBJS)
    AC_SUBST(PLAT_SRCS)
    AC_SUBST(LDAIX_SRC)
    AC_SUBST(CFLAGS)
    AC_SUBST(CFLAGS_DEBUG)
    AC_SUBST(CFLAGS_OPTIMIZE)
    AC_SUBST(CFLAGS_WARNING)
    AC_SUBST(CFLAGS_NOLTO)

    AC_SUBST(LDFLAGS)
    AC_SUBST(LDFLAGS_DEBUG)
    AC_SUBST(LDFLAGS_OPTIMIZE)
    AC_SUBST(CC_SEARCH_FLAGS)
    AC_SUBST(LD_SEARCH_FLAGS)

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
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







-
-
+
+









+
+
+




+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
+







])

#--------------------------------------------------------------------
# SC_MISSING_POSIX_HEADERS
#
#	Supply substitutes for missing POSIX header files.  Special
#	notes:
#	    - stdlib.h doesn't define strtol or strtoul in some
#	      versions of SunOS
#	    - stdlib.h doesn't define strtol, strtoul, or
#	      strtod insome versions of SunOS
#	    - some versions of string.h don't declare procedures such
#	      as strstr
#
# Arguments:
#	none
#
# Results:
#
#	Defines some of the following vars:
#		NO_DIRENT_H
#		NO_VALUES_H
#		NO_STDLIB_H
#		NO_STRING_H
#		NO_SYS_WAIT_H
#		NO_DLFCN_H
#		HAVE_SYS_PARAM_H
#
#		HAVE_STRING_H ?
#
#--------------------------------------------------------------------

AC_DEFUN([SC_MISSING_POSIX_HEADERS], [
    AC_CACHE_CHECK([dirent.h], tcl_cv_dirent_h, [
    AC_TRY_LINK([#include <sys/types.h>
#include <dirent.h>], [
#ifndef _POSIX_SOURCE
#   ifdef __Lynx__
	/*
	 * Generate compilation error to make the test fail:  Lynx headers
	 * are only valid if really in the POSIX environment.
	 */

	missing_procedure();
#   endif
#endif
DIR *d;
struct dirent *entryPtr;
char *p;
d = opendir("foobar");
entryPtr = readdir(d);
p = entryPtr->d_name;
closedir(d);
], tcl_cv_dirent_h=yes, tcl_cv_dirent_h=no)])

    if test $tcl_cv_dirent_h = no; then
	AC_DEFINE(NO_DIRENT_H, 1, [Do we have <dirent.h>?])
    fi

    AC_CHECK_HEADER(float.h, , [AC_DEFINE(NO_FLOAT_H, 1, [Do we have <float.h>?])])
    AC_CHECK_HEADER(values.h, , [AC_DEFINE(NO_VALUES_H, 1, [Do we have <values.h>?])])
    AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
    AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
    AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
    AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
    if test $tcl_ok = 0; then
	AC_DEFINE(NO_STDLIB_H, 1, [Do we have <stdlib.h>?])
    fi
    AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
    AC_EGREP_HEADER(strstr, string.h, , tcl_ok=0)
    AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)

    # See also memmove check below for a place where NO_STRING_H can be
    # set and why.

    if test $tcl_ok = 0; then
	AC_DEFINE(NO_STRING_H, 1, [Do we have <string.h>?])
    fi

    AC_CHECK_HEADER(sys/wait.h, , [AC_DEFINE(NO_SYS_WAIT_H, 1, [Do we have <sys/wait.h>?])])
    AC_CHECK_HEADER(dlfcn.h, , [AC_DEFINE(NO_DLFCN_H, 1, [Do we have <dlfcn.h>?])])

    # OS/390 lacks sys/param.h (and doesn't need it, by chance).
    AC_CHECK_HEADERS([sys/param.h])
    AC_HAVE_HEADERS(sys/param.h)
])

#--------------------------------------------------------------------
# SC_PATH_X
#
#	Locate the X11 header files and the X11 library archive.  Try
#	the ac_path_x macro first, but if it doesn't find the X stuff
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
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







-
+









-
+







#--------------------------------------------------------------------

AC_DEFUN([SC_PATH_X], [
    AC_PATH_X
    not_really_there=""
    if test "$no_x" = ""; then
	if test "$x_includes" = ""; then
	    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <X11/Xlib.h>]])],[],[not_really_there="yes"])
	    AC_TRY_CPP([#include <X11/Xlib.h>], , not_really_there="yes")
	else
	    if test ! -r $x_includes/X11/Xlib.h; then
		not_really_there="yes"
	    fi
	fi
    fi
    if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
	AC_MSG_CHECKING([for X11 header files])
	found_xincludes="no"
	AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <X11/Xlib.h>]])],[found_xincludes="yes"],[found_xincludes="no"])
	AC_TRY_CPP([#include <X11/Xlib.h>], found_xincludes="yes", found_xincludes="no")
	if test "$found_xincludes" = "no"; then
	    dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/X11R6/include /usr/X11R5/include /usr/include/X11R5 /usr/include/X11R4 /usr/openwin/include /usr/X11/include /usr/sww/include"
	    for i in $dirs ; do
		if test -r $i/X11/Xlib.h; then
		    AC_MSG_RESULT([$i])
		    XINCLUDES=" -I$i"
		    found_xincludes="yes"
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
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







-
+




-
-
+
+
-





-
-
+
+
-









-
+
-
-
+

-
-
+
+







-
+
-
-
+

-
-
+
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+
-
-
+






-
-
-
-
-
-
-













+
+



+







#		HAVE_TM_TZADJ
#		HAVE_TIMEZONE_VAR
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TIME_HANDLER], [
    AC_CHECK_HEADERS(sys/time.h)
    AC_CHECK_HEADERS_ONCE([sys/time.h])
    AC_HEADER_TIME

    AC_CHECK_FUNCS(gmtime_r localtime_r mktime)

    AC_CACHE_CHECK([tm_tzadj in struct tm], tcl_cv_member_tm_tzadj, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct tm tm; (void)tm.tm_tzadj;]])],
	    [tcl_cv_member_tm_tzadj=yes],
	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_tzadj;],
	    tcl_cv_member_tm_tzadj=yes, tcl_cv_member_tm_tzadj=no)])
	    [tcl_cv_member_tm_tzadj=no])])
    if test $tcl_cv_member_tm_tzadj = yes ; then
	AC_DEFINE(HAVE_TM_TZADJ, 1, [Should we use the tm_tzadj field of struct tm?])
    fi

    AC_CACHE_CHECK([tm_gmtoff in struct tm], tcl_cv_member_tm_gmtoff, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct tm tm; (void)tm.tm_gmtoff;]])],
	    [tcl_cv_member_tm_gmtoff=yes],
	AC_TRY_COMPILE([#include <time.h>], [struct tm tm; tm.tm_gmtoff;],
	    tcl_cv_member_tm_gmtoff=yes, tcl_cv_member_tm_gmtoff=no)])
	    [tcl_cv_member_tm_gmtoff=no])])
    if test $tcl_cv_member_tm_gmtoff = yes ; then
	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Should we use the tm_gmtoff field of struct tm?])
    fi

    #
    # Its important to include time.h in this check, as some systems
    # (like convex) have timezone functions, etc.
    #
    AC_CACHE_CHECK([long timezone variable], tcl_cv_timezone_long, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>
	AC_TRY_COMPILE([#include <time.h>],
#include <stdlib.h>]],
	[[extern long timezone;
	    [extern long timezone;
	    timezone += 1;
	    exit (0);]])],
	    [tcl_cv_timezone_long=yes], [tcl_cv_timezone_long=no])])
	    exit (0);],
	    tcl_cv_timezone_long=yes, tcl_cv_timezone_long=no)])
    if test $tcl_cv_timezone_long = yes ; then
	AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
    else
	#
	# On some systems (eg IRIX 6.2), timezone is a time_t and not a long.
	#
	AC_CACHE_CHECK([time_t timezone variable], tcl_cv_timezone_time, [
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>
	    AC_TRY_COMPILE([#include <time.h>],
#include <stdlib.h>]],
	    [[extern time_t timezone;
		[extern time_t timezone;
		timezone += 1;
		exit (0);]])],
		[tcl_cv_timezone_time=yes], [tcl_cv_timezone_time=no])])
		exit (0);],
		tcl_cv_timezone_time=yes, tcl_cv_timezone_time=no)])
	if test $tcl_cv_timezone_time = yes ; then
	    AC_DEFINE(HAVE_TIMEZONE_VAR, 1, [Should we use the global timezone variable?])
	fi
    fi
])

#--------------------------------------------------------------------
# SC_BUGGY_STRTOD
#
#	Under Solaris 2.4, strtod returns the wrong value for the
#	terminating character under some conditions.  Check for this
#	and if the problem exists use a substitute procedure
#	"fixstrtod" (provided by Tcl) that corrects the error.
#	Also, on Compaq's Tru64 Unix 5.0,
#	strtod(" ") returns 0.0 instead of a failure to convert.
#
# Arguments:
#	none
#
# Results:
#
#	Might defines some of the following vars:
#		strtod (=fixstrtod)
#
#--------------------------------------------------------------------

AC_DEFUN([SC_BUGGY_STRTOD], [
    AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
    if test "$tcl_strtod" = 1; then
	AC_CACHE_CHECK([for Solaris2.4/Tru64 strtod bugs], tcl_cv_strtod_buggy,[
	    AC_TRY_RUN([
		extern double strtod();
		int main() {
		    char *infString="Inf", *nanString="NaN", *spaceString=" ";
		    char *term;
		    double value;
		    value = strtod(infString, &term);
		    if ((term != infString) && (term[-1] == 0)) {
			exit(1);
		    }
		    value = strtod(nanString, &term);
		    if ((term != nanString) && (term[-1] == 0)) {
			exit(1);
		    }
		    value = strtod(spaceString, &term);
		    if (term == (spaceString+1)) {
			exit(1);
		    }
		    exit(0);
		}], tcl_cv_strtod_buggy=ok, tcl_cv_strtod_buggy=buggy,
		    tcl_cv_strtod_buggy=buggy)])
	if test "$tcl_cv_strtod_buggy" = buggy; then
	    AC_LIBOBJ([fixstrtod])
	    USE_COMPAT=1
	    AC_DEFINE(strtod, fixstrtod, [Do we want to use the strtod() in compat?])
	fi
    fi
])

#--------------------------------------------------------------------
# SC_TCL_LINK_LIBS
#
#	Search for the libraries needed to link the Tcl shell.
#	Things like the math library (-lm), socket stuff (-lsocket vs.
#	Things like the math library (-lm) and socket stuff (-lsocket vs.
#	-lnsl), zlib (-lz) and libtommath (-ltommath) or thread library
#	(-lpthread) are dealt with here.
#	-lnsl) are dealt with here.
#
# Arguments:
#	None.
#
# Results:
#
#	Sets the following vars:
#		THREADS_LIBS	Thread library(s)
#
#	Defines the following vars:
#		_REENTRANT
#		_THREAD_SAFE
#
#	Might append to the following vars:
#		LIBS
#		MATH_LIBS
#
#	Might define the following vars:
#		HAVE_NET_ERRNO_H
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_LINK_LIBS], [
    #--------------------------------------------------------------------
    # On a few very rare systems, all of the libm.a stuff is
    # already in libc.a.  Set compiler flags accordingly.
    # Also, Linux requires the "ieee" library for math to work
    # right (and it must appear before "-lm").
    #--------------------------------------------------------------------

    AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
    AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])

    #--------------------------------------------------------------------
    # Interactive UNIX requires -linet instead of -lsocket, plus it
    # needs net/errno.h to define the socket-related error codes.
    #--------------------------------------------------------------------

    AC_CHECK_LIB(inet, main, [LIBS="$LIBS -linet"])
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















-
-
+
+





-
-
-
-
-
+
+
+
+
+

-
+









-
-


+
+



















+
-
+
+

-




-
+


+
+
+
-
+


-
-
-
+
+
+

-
-
+
+

+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+

-
-
-
+
+
+




-
-
-
+
+
+
-
-
-
-
+
+
+





-
-
-
+
+
+







    if test "$tcl_checkBoth" = 1; then
	tk_oldLibs=$LIBS
	LIBS="$LIBS -lsocket -lnsl"
	AC_CHECK_FUNC(accept, tcl_checkNsl=0, [LIBS=$tk_oldLibs])
    fi
    AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname,
	    [LIBS="$LIBS -lnsl"])])

    AC_DEFINE(_REENTRANT, 1, [Do we want the reentrant OS API?])
    AC_DEFINE(_THREAD_SAFE, 1, [Do we want the thread-safe OS API?])
    AC_CHECK_LIB(pthread,pthread_mutex_init,tcl_ok=yes,tcl_ok=no)
    if test "$tcl_ok" = "no"; then
	# Check a little harder for __pthread_mutex_init in the same
	# library, as some systems hide it there until pthread.h is
	# defined.  We could alternatively do an AC_TRY_COMPILE with
	# pthread.h, but that will work with libpthread really doesn't
	# exist, like AIX 4.2.  [Bug: 4359]
	AC_CHECK_LIB(pthread, __pthread_mutex_init,
		tcl_ok=yes, tcl_ok=no)
    fi

    if test "$tcl_ok" = "yes"; then
	# The space is needed
	THREADS_LIBS=" -lpthread"
    else
	AC_CHECK_LIB(pthreads, pthread_mutex_init,
	_ok=yes, tcl_ok=no)
	if test "$tcl_ok" = "yes"; then
	    # The space is needed
	    THREADS_LIBS=" -lpthreads"
	else
	    AC_CHECK_LIB(c, pthread_mutex_init,
		    tcl_ok=yes, tcl_ok=no)
	    if test "$tcl_ok" = "no"; then
		AC_CHECK_LIB(c_r, pthread_mutex_init,
			tcl_ok=yes, tcl_ok=no)
		if test "$tcl_ok" = "yes"; then
		    # The space is needed
		    THREADS_LIBS=" -pthread"
		else
		    AC_MSG_WARN([Don't know how to find pthread lib on your system - you must edit the LIBS in the Makefile...])
		fi
	    fi
	fi
    fi

    # Does the pthread-implementation provide
    # 'pthread_attr_setstacksize' ?

    ac_saved_libs=$LIBS
    LIBS="$LIBS $THREADS_LIBS"
    AC_CHECK_FUNCS(pthread_attr_setstacksize pthread_atfork)
    LIBS=$ac_saved_libs

    # TIP #509
    AC_CHECK_DECLS([PTHREAD_MUTEX_RECURSIVE],tcl_ok=yes,tcl_ok=no, [[#include <pthread.h>]])
])

#--------------------------------------------------------------------
# SC_TCL_EARLY_FLAGS
#
#	Check for what flags are needed to be passed so the correct OS
#	features are available.
#
# Arguments:
#	None
#
# Results:
#
#	Might define the following vars:
#		_ISOC99_SOURCE
#		_FILE_OFFSET_BITS
#		_LARGEFILE64_SOURCE
#		_LARGEFILE64_SOURCE
#		_LARGEFILE_SOURCE64
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_EARLY_FLAG],[
    AC_CACHE_VAL([tcl_cv_flag_]translit($1,[A-Z],[a-z]),
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$2]], [[$3]])],
	    [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[[#define ]$1[ ]m4_default([$4],[1])[
]$2]], [[$3]])],
	[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
	[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)]))
	AC_TRY_COMPILE([$2], $3, [tcl_cv_flag_]translit($1,[A-Z],[a-z])=no,
	    AC_TRY_COMPILE([[#define ]$1[ 1
]$2], $3,
		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=yes,
		[tcl_cv_flag_]translit($1,[A-Z],[a-z])=no)))
    if test ["x${tcl_cv_flag_]translit($1,[A-Z],[a-z])[}" = "xyes"] ; then
	AC_DEFINE($1, m4_default([$4],[1]), [Add the ]$1[ flag when building])
	AC_DEFINE($1, 1, [Add the ]$1[ flag when building])
	tcl_flags="$tcl_flags $1"
    fi
])

AC_DEFUN([SC_TCL_EARLY_FLAGS],[
    AC_MSG_CHECKING([for required early compiler flags])
    tcl_flags=""
    SC_TCL_EARLY_FLAG(_ISOC99_SOURCE,[#include <stdlib.h>],
	[char *p = (char *)strtoll; char *q = (char *)strtoull;])
    SC_TCL_EARLY_FLAG(_FILE_OFFSET_BITS,[#include <sys/stat.h>],
	[switch (0) { case 0: case (sizeof(off_t)==sizeof(long long)): ; }],64)
    SC_TCL_EARLY_FLAG(_LARGEFILE64_SOURCE,[#include <sys/stat.h>],
	[struct stat64 buf; int i = stat64("/", &buf);])
    SC_TCL_EARLY_FLAG(_LARGEFILE_SOURCE64,[#include <sys/stat.h>],
	[char *p = (char *)open64;])
    if test "x${tcl_flags}" = "x" ; then
	AC_MSG_RESULT([none])
    else
	AC_MSG_RESULT([${tcl_flags}])
    fi
])

#--------------------------------------------------------------------
# SC_TCL_64BIT_FLAGS
#
#	Check for what is defined in the way of 64-bit features.
#
# Arguments:
#	None
#
# Results:
#
#	Might define the following vars:
#		TCL_WIDE_INT_IS_LONG
#		TCL_WIDE_INT_TYPE
#		HAVE_STRUCT_DIRENT64, HAVE_DIR64
#		HAVE_STRUCT_DIRENT64
#		HAVE_STRUCT_STAT64
#		HAVE_TYPE_OFF64_T
#		_TIME_BITS
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_64BIT_FLAGS], [
    AC_MSG_CHECKING([if 'long' and 'long long' have the same size (64-bit)?])
    AC_MSG_CHECKING([for 64-bit integer type])
    AC_CACHE_VAL(tcl_cv_type_64bit,[
	tcl_cv_type_64bit=none
	# See if the compiler knows natively about __int64
	AC_TRY_COMPILE(,[__int64 value = (__int64) 0;],
	    tcl_type_64bit=__int64, tcl_type_64bit="long long")
	# See if we could use long anyway  Note that we substitute in the
	# See if we should use long anyway  Note that we substitute in the
	# type that is our current guess for a 64-bit type inside this check
	# program, so it should be modified only carefully...
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[switch (0) {
            case 1: case (sizeof(long long)==sizeof(long)): ;
        }]])],[tcl_cv_type_64bit="long long"],[])])
        AC_TRY_COMPILE(,[switch (0) {
            case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
        }],tcl_cv_type_64bit=${tcl_type_64bit})])
    if test "${tcl_cv_type_64bit}" = none ; then
	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Do 'long' and 'long long' have the same size (64-bit)?])
	AC_MSG_RESULT([yes])
	AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Are wide integers to be implemented with C 'long's?])
	AC_MSG_RESULT([using long])
    else
	AC_DEFINE_UNQUOTED(TCL_WIDE_INT_TYPE,${tcl_cv_type_64bit},
	    [What type should be used to define wide integers?])
	AC_MSG_RESULT([no])
	AC_MSG_RESULT([${tcl_cv_type_64bit}])
	# Now check for auxiliary declarations
	AC_CACHE_CHECK([for 64-bit time_t], tcl_cv_time_t_64,[
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]],
		[[switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}]])],
		[tcl_cv_time_t_64=yes],[tcl_cv_time_t_64=no])])
	if test "x${tcl_cv_time_t_64}" = "xno" ; then
	    # Note that _TIME_BITS=64 requires _FILE_OFFSET_BITS=64
	    # which SC_TCL_EARLY_FLAGS has defined if necessary.
	    AC_CACHE_CHECK([if _TIME_BITS=64 enables 64-bit time_t], tcl_cv__time_bits,[
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#define _TIME_BITS 64
#include <sys/types.h>]],
		    [[switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}]])],
		    [tcl_cv__time_bits=yes],[tcl_cv__time_bits=no])])
	    if test "x${tcl_cv__time_bits}" = "xyes" ; then
		AC_DEFINE(_TIME_BITS, 64, [_TIME_BITS=64 enables 64-bit time_t.])
	    fi
	fi

	# Now check for auxiliary declarations
	AC_CACHE_CHECK([for struct dirent64], tcl_cv_struct_dirent64,[
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <dirent.h>]], [[struct dirent64 p;]])],
		[tcl_cv_struct_dirent64=yes],[tcl_cv_struct_dirent64=no])])
	    AC_TRY_COMPILE([#include <sys/types.h>
#include <dirent.h>],[struct dirent64 p;],
		tcl_cv_struct_dirent64=yes,tcl_cv_struct_dirent64=no)])
	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then
	    AC_DEFINE(HAVE_STRUCT_DIRENT64, 1, [Is 'struct dirent64' in <sys/types.h>?])
	fi

	AC_CACHE_CHECK([for DIR64], tcl_cv_DIR64,[
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <dirent.h>]], [[struct dirent64 *p; DIR64 d = opendir64(".");
	AC_CACHE_CHECK([for struct stat64], tcl_cv_struct_stat64,[
	    AC_TRY_COMPILE([#include <sys/stat.h>],[struct stat64 p;
],
            p = readdir64(d); rewinddir64(d); closedir64(d);]])],
		[tcl_cv_DIR64=yes], [tcl_cv_DIR64=no])])
	if test "x${tcl_cv_DIR64}" = "xyes" ; then
	    AC_DEFINE(HAVE_DIR64, 1, [Is 'DIR64' in <sys/types.h>?])
		tcl_cv_struct_stat64=yes,tcl_cv_struct_stat64=no)])
	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then
	    AC_DEFINE(HAVE_STRUCT_STAT64, 1, [Is 'struct stat64' in <sys/stat.h>?])
	fi

	AC_CHECK_FUNCS(open64 lseek64)
	AC_MSG_CHECKING([for off64_t])
	AC_CACHE_VAL(tcl_cv_type_off64_t,[
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>]], [[off64_t offset;
]])],
		[tcl_cv_type_off64_t=yes], [tcl_cv_type_off64_t=no])])
	    AC_TRY_COMPILE([#include <sys/types.h>],[off64_t offset;
],
		tcl_cv_type_off64_t=yes,tcl_cv_type_off64_t=no)])
	dnl Define HAVE_TYPE_OFF64_T only when the off64_t type and the
	dnl functions lseek64 and open64 are defined.
	if test "x${tcl_cv_type_off64_t}" = "xyes" && \
	        test "x${ac_cv_func_lseek64}" = "xyes" && \
	        test "x${ac_cv_func_open64}" = "xyes" ; then
	    AC_DEFINE(HAVE_TYPE_OFF64_T, 1, [Is off64_t in <sys/types.h>?])
	    AC_MSG_RESULT([yes])
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438



2439
2440
2441
2442
2443
2444

2445
2446
2447
2448
2449
2450
2451
2560
2561
2562
2563
2564
2565
2566



2567
2568
2569
2570
2571
2572
2573
2574

2575
2576
2577
2578
2579
2580
2581
2582







-
-
-
+
+
+





-
+







#	Will define the following vars:
#		TCL_CFGVAL_ENCODING
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_CFG_ENCODING], [
    AC_ARG_WITH(encoding,
	AS_HELP_STRING([--with-encoding],
	    [encoding for configuration values (default: utf-8)]),
	[with_tcencoding=${withval}])
	AC_HELP_STRING([--with-encoding],
	    [encoding for configuration values (default: iso8859-1)]),
	with_tcencoding=${withval})

    if test x"${with_tcencoding}" != x ; then
	AC_DEFINE_UNQUOTED(TCL_CFGVAL_ENCODING,"${with_tcencoding}",
	    [What encoding should be used for embedded configuration info?])
    else
	AC_DEFINE(TCL_CFGVAL_ENCODING,"utf-8",
	AC_DEFINE(TCL_CFGVAL_ENCODING,"iso8859-1",
	    [What encoding should be used for embedded configuration info?])
    fi
])

#--------------------------------------------------------------------
# SC_TCL_CHECK_BROKEN_FUNC
#
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473


2474
2475
2476
2477
2478
2479
2480
2593
2594
2595
2596
2597
2598
2599





2600
2601
2602
2603
2604
2605
2606
2607
2608







-
-
-
-
-
+
+







#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_CHECK_BROKEN_FUNC],[
    AC_CHECK_FUNC($1, tcl_ok=1, tcl_ok=0)
    if test ["$tcl_ok"] = 1; then
	AC_CACHE_CHECK([proper ]$1[ implementation], [tcl_cv_]$1[_unbroken],
	    AC_RUN_IFELSE([AC_LANG_SOURCE([[[
#include <stdlib.h>
#include <string.h>
int main() {]$2[}]]])],[tcl_cv_$1_unbroken=ok],
		[tcl_cv_$1_unbroken=broken],[tcl_cv_$1_unbroken=unknown]))
	    AC_TRY_RUN([[int main() {]$2[}]],[tcl_cv_]$1[_unbroken]=ok,
		[tcl_cv_]$1[_unbroken]=broken,[tcl_cv_]$1[_unbroken]=unknown))
	if test ["$tcl_cv_]$1[_unbroken"] = "ok"; then
	    tcl_ok=1
	else
	    tcl_ok=0
	fi
    fi
    if test ["$tcl_ok"] = 0; then
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
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







-
+
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+










-
+






-
+

-
+










-
+







#	Might define the following vars:
#		HAVE_GETHOSTBYADDR_R
#		HAVE_GETHOSTBYADDR_R_7
#		HAVE_GETHOSTBYADDR_R_8
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETHOSTBYADDR_R], [
AC_DEFUN([SC_TCL_GETHOSTBYADDR_R], [AC_CHECK_FUNC(gethostbyaddr_r, [
    # Avoids picking hidden internal symbol from libc
    SC_TCL_GETHOSTBYADDR_R_DECL

    if test "$tcl_cv_api_gethostbyaddr_r" = yes; then
	SC_TCL_GETHOSTBYADDR_R_TYPE
    fi
])

AC_DEFUN([SC_TCL_GETHOSTBYADDR_R_DECL], [AC_CHECK_DECLS(gethostbyaddr_r, [
    tcl_cv_api_gethostbyaddr_r=yes],[tcl_cv_api_gethostbyaddr_r=no],[#include <netdb.h>])
])

AC_DEFUN([SC_TCL_GETHOSTBYADDR_R_TYPE], [AC_CHECK_FUNC(gethostbyaddr_r, [
    AC_CACHE_CHECK([for gethostbyaddr_r with 7 args], tcl_cv_api_gethostbyaddr_r_7, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <netdb.h>
    ]], [[
    ], [
	char *addr;
	int length;
	int type;
	struct hostent *result;
	char buffer[2048];
	int buflen = 2048;
	int h_errnop;

	(void) gethostbyaddr_r(addr, length, type, result, buffer, buflen,
			       &h_errnop);
    ]])],[tcl_cv_api_gethostbyaddr_r_7=yes],[tcl_cv_api_gethostbyaddr_r_7=no])])
    ], tcl_cv_api_gethostbyaddr_r_7=yes, tcl_cv_api_gethostbyaddr_r_7=no)])
    tcl_ok=$tcl_cv_api_gethostbyaddr_r_7
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1,
	    [Define to 1 if gethostbyaddr_r takes 7 args.])
    else
	AC_CACHE_CHECK([for gethostbyaddr_r with 8 args], tcl_cv_api_gethostbyaddr_r_8, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <netdb.h>
	]], [[
	], [
	    char *addr;
	    int length;
	    int type;
	    struct hostent *result, *resultp;
	    char buffer[2048];
	    int buflen = 2048;
	    int h_errnop;

	    (void) gethostbyaddr_r(addr, length, type, result, buffer, buflen,
				   &resultp, &h_errnop);
	]])],[tcl_cv_api_gethostbyaddr_r_8=yes],[tcl_cv_api_gethostbyaddr_r_8=no])])
	], tcl_cv_api_gethostbyaddr_r_8=yes, tcl_cv_api_gethostbyaddr_r_8=no)])
	tcl_ok=$tcl_cv_api_gethostbyaddr_r_8
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1,
		[Define to 1 if gethostbyaddr_r takes 8 args.])
	fi
    fi
    if test "$tcl_ok" = yes; then
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
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







-
-
-
-
+
+
+
+



-
+
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

-
+







-
+






-
+

-
+







-
+






-
+

-
+





-
+







#
# Arguments:
#	None
#
# Results:
#
#	Might define the following vars:
#		HAVE_GETHOSTBYNAME_R
#		HAVE_GETHOSTBYNAME_R_3
#		HAVE_GETHOSTBYNAME_R_5
#		HAVE_GETHOSTBYNAME_R_6
#		HAVE_GETHOSTBYADDR_R
#		HAVE_GETHOSTBYADDR_R_3
#		HAVE_GETHOSTBYADDR_R_5
#		HAVE_GETHOSTBYADDR_R_6
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETHOSTBYNAME_R], [
AC_DEFUN([SC_TCL_GETHOSTBYNAME_R], [AC_CHECK_FUNC(gethostbyname_r, [
    # Avoids picking hidden internal symbol from libc
    SC_TCL_GETHOSTBYNAME_R_DECL

    if test "$tcl_cv_api_gethostbyname_r" = yes; then
	SC_TCL_GETHOSTBYNAME_R_TYPE
    fi
])

AC_DEFUN([SC_TCL_GETHOSTBYNAME_R_DECL], [AC_CHECK_DECLS(gethostbyname_r, [
    tcl_cv_api_gethostbyname_r=yes],[tcl_cv_api_gethostbyname_r=no],[#include <netdb.h>])
])

AC_DEFUN([SC_TCL_GETHOSTBYNAME_R_TYPE], [AC_CHECK_FUNC(gethostbyname_r, [
    AC_CACHE_CHECK([for gethostbyname_r with 6 args], tcl_cv_api_gethostbyname_r_6, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <netdb.h>
    ]], [[
    ], [
	char *name;
	struct hostent *he, *res;
	char buffer[2048];
	int buflen = 2048;
	int h_errnop;

	(void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop);
    ]])],[tcl_cv_api_gethostbyname_r_6=yes],[tcl_cv_api_gethostbyname_r_6=no])])
    ], tcl_cv_api_gethostbyname_r_6=yes, tcl_cv_api_gethostbyname_r_6=no)])
    tcl_ok=$tcl_cv_api_gethostbyname_r_6
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1,
	    [Define to 1 if gethostbyname_r takes 6 args.])
    else
	AC_CACHE_CHECK([for gethostbyname_r with 5 args], tcl_cv_api_gethostbyname_r_5, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <netdb.h>
	]], [[
	], [
	    char *name;
	    struct hostent *he;
	    char buffer[2048];
	    int buflen = 2048;
	    int h_errnop;

	    (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop);
	]])],[tcl_cv_api_gethostbyname_r_5=yes],[tcl_cv_api_gethostbyname_r_5=no])])
	], tcl_cv_api_gethostbyname_r_5=yes, tcl_cv_api_gethostbyname_r_5=no)])
	tcl_ok=$tcl_cv_api_gethostbyname_r_5
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1,
		[Define to 1 if gethostbyname_r takes 5 args.])
	else
	    AC_CACHE_CHECK([for gethostbyname_r with 3 args], tcl_cv_api_gethostbyname_r_3, [
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	    AC_TRY_COMPILE([
		#include <netdb.h>
	    ]], [[
	    ], [
		char *name;
		struct hostent *he;
		struct hostent_data data;

		(void) gethostbyname_r(name, he, &data);
	    ]])],[tcl_cv_api_gethostbyname_r_3=yes],[tcl_cv_api_gethostbyname_r_3=no])])
	    ], tcl_cv_api_gethostbyname_r_3=yes, tcl_cv_api_gethostbyname_r_3=no)])
	    tcl_ok=$tcl_cv_api_gethostbyname_r_3
	    if test "$tcl_ok" = yes; then
		AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1,
		    [Define to 1 if gethostbyname_r takes 3 args.])
	    fi
	fi
    fi
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
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







-
+


-
+






-
+






-
+


-
+






-
+







#		HAVE_GETPWUID_R_4
#		HAVE_GETPWUID_R_5
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETPWUID_R], [AC_CHECK_FUNC(getpwuid_r, [
    AC_CACHE_CHECK([for getpwuid_r with 5 args], tcl_cv_api_getpwuid_r_5, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <sys/types.h>
	#include <pwd.h>
    ]], [[
    ], [
	uid_t uid;
	struct passwd pw, *pwp;
	char buf[512];
	int buflen = 512;

	(void) getpwuid_r(uid, &pw, buf, buflen, &pwp);
    ]])],[tcl_cv_api_getpwuid_r_5=yes],[tcl_cv_api_getpwuid_r_5=no])])
    ], tcl_cv_api_getpwuid_r_5=yes, tcl_cv_api_getpwuid_r_5=no)])
    tcl_ok=$tcl_cv_api_getpwuid_r_5
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETPWUID_R_5, 1,
	    [Define to 1 if getpwuid_r takes 5 args.])
    else
	AC_CACHE_CHECK([for getpwuid_r with 4 args], tcl_cv_api_getpwuid_r_4, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <sys/types.h>
	    #include <pwd.h>
	]], [[
	], [
	    uid_t uid;
	    struct passwd pw;
	    char buf[512];
	    int buflen = 512;

	    (void)getpwnam_r(uid, &pw, buf, buflen);
	]])],[tcl_cv_api_getpwuid_r_4=yes],[tcl_cv_api_getpwuid_r_4=no])])
	], tcl_cv_api_getpwuid_r_4=yes, tcl_cv_api_getpwuid_r_4=no)])
	tcl_ok=$tcl_cv_api_getpwuid_r_4
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETPWUID_R_4, 1,
		[Define to 1 if getpwuid_r takes 4 args.])
	fi
    fi
    if test "$tcl_ok" = yes; then
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
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







-
+


-
+






-
+






-
+


-
+






-
+







#		HAVE_GETPWNAM_R_4
#		HAVE_GETPWNAM_R_5
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETPWNAM_R], [AC_CHECK_FUNC(getpwnam_r, [
    AC_CACHE_CHECK([for getpwnam_r with 5 args], tcl_cv_api_getpwnam_r_5, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <sys/types.h>
	#include <pwd.h>
    ]], [[
    ], [
	char *name;
	struct passwd pw, *pwp;
	char buf[512];
	int buflen = 512;

	(void) getpwnam_r(name, &pw, buf, buflen, &pwp);
    ]])],[tcl_cv_api_getpwnam_r_5=yes],[tcl_cv_api_getpwnam_r_5=no])])
    ], tcl_cv_api_getpwnam_r_5=yes, tcl_cv_api_getpwnam_r_5=no)])
    tcl_ok=$tcl_cv_api_getpwnam_r_5
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETPWNAM_R_5, 1,
	    [Define to 1 if getpwnam_r takes 5 args.])
    else
	AC_CACHE_CHECK([for getpwnam_r with 4 args], tcl_cv_api_getpwnam_r_4, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <sys/types.h>
	    #include <pwd.h>
	]], [[
	], [
	    char *name;
	    struct passwd pw;
	    char buf[512];
	    int buflen = 512;

	    (void)getpwnam_r(name, &pw, buf, buflen);
	]])],[tcl_cv_api_getpwnam_r_4=yes],[tcl_cv_api_getpwnam_r_4=no])])
	], tcl_cv_api_getpwnam_r_4=yes, tcl_cv_api_getpwnam_r_4=no)])
	tcl_ok=$tcl_cv_api_getpwnam_r_4
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETPWNAM_R_4, 1,
		[Define to 1 if getpwnam_r takes 4 args.])
	fi
    fi
    if test "$tcl_ok" = yes; then
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
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







-
+


-
+






-
+






-
+


-
+






-
+







#		HAVE_GETGRGID_R_4
#		HAVE_GETGRGID_R_5
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETGRGID_R], [AC_CHECK_FUNC(getgrgid_r, [
    AC_CACHE_CHECK([for getgrgid_r with 5 args], tcl_cv_api_getgrgid_r_5, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <sys/types.h>
	#include <grp.h>
    ]], [[
    ], [
	gid_t gid;
	struct group gr, *grp;
	char buf[512];
	int buflen = 512;

	(void) getgrgid_r(gid, &gr, buf, buflen, &grp);
    ]])],[tcl_cv_api_getgrgid_r_5=yes],[tcl_cv_api_getgrgid_r_5=no])])
    ], tcl_cv_api_getgrgid_r_5=yes, tcl_cv_api_getgrgid_r_5=no)])
    tcl_ok=$tcl_cv_api_getgrgid_r_5
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETGRGID_R_5, 1,
	    [Define to 1 if getgrgid_r takes 5 args.])
    else
	AC_CACHE_CHECK([for getgrgid_r with 4 args], tcl_cv_api_getgrgid_r_4, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <sys/types.h>
	    #include <grp.h>
	]], [[
	], [
	    gid_t gid;
	    struct group gr;
	    char buf[512];
	    int buflen = 512;

	    (void)getgrgid_r(gid, &gr, buf, buflen);
	]])],[tcl_cv_api_getgrgid_r_4=yes],[tcl_cv_api_getgrgid_r_4=no])])
	], tcl_cv_api_getgrgid_r_4=yes, tcl_cv_api_getgrgid_r_4=no)])
	tcl_ok=$tcl_cv_api_getgrgid_r_4
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETGRGID_R_4, 1,
		[Define to 1 if getgrgid_r takes 4 args.])
	fi
    fi
    if test "$tcl_ok" = yes; then
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
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







-
+


-
+






-
+






-
+


-
+






-
+







#		HAVE_GETGRNAM_R_4
#		HAVE_GETGRNAM_R_5
#
#--------------------------------------------------------------------

AC_DEFUN([SC_TCL_GETGRNAM_R], [AC_CHECK_FUNC(getgrnam_r, [
    AC_CACHE_CHECK([for getgrnam_r with 5 args], tcl_cv_api_getgrnam_r_5, [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    AC_TRY_COMPILE([
	#include <sys/types.h>
	#include <grp.h>
    ]], [[
    ], [
	char *name;
	struct group gr, *grp;
	char buf[512];
	int buflen = 512;

	(void) getgrnam_r(name, &gr, buf, buflen, &grp);
    ]])],[tcl_cv_api_getgrnam_r_5=yes],[tcl_cv_api_getgrnam_r_5=no])])
    ], tcl_cv_api_getgrnam_r_5=yes, tcl_cv_api_getgrnam_r_5=no)])
    tcl_ok=$tcl_cv_api_getgrnam_r_5
    if test "$tcl_ok" = yes; then
	AC_DEFINE(HAVE_GETGRNAM_R_5, 1,
	    [Define to 1 if getgrnam_r takes 5 args.])
    else
	AC_CACHE_CHECK([for getgrnam_r with 4 args], tcl_cv_api_getgrnam_r_4, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #include <sys/types.h>
	    #include <grp.h>
	]], [[
	], [
	    char *name;
	    struct group gr;
	    char buf[512];
	    int buflen = 512;

	    (void)getgrnam_r(name, &gr, buf, buflen);
	]])],[tcl_cv_api_getgrnam_r_4=yes],[tcl_cv_api_getgrnam_r_4=no])])
	], tcl_cv_api_getgrnam_r_4=yes, tcl_cv_api_getgrnam_r_4=no)])
	tcl_ok=$tcl_cv_api_getgrnam_r_4
	if test "$tcl_ok" = yes; then
	    AC_DEFINE(HAVE_GETGRNAM_R_4, 1,
		[Define to 1 if getgrnam_r takes 4 args.])
	fi
    fi
    if test "$tcl_ok" = yes; then
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
3010
3011
3012
3013
3014
3015
3016


















































































































































3017
3018
3019







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



if test "x$NEED_FAKE_RFC2553" = "x1"; then
   AC_DEFINE([NEED_FAKE_RFC2553], 1,
        [Use compat implementation of getaddrinfo() and friends])
   AC_LIBOBJ([fake-rfc2553])
   AC_CHECK_FUNC(strlcpy)
fi
])

#------------------------------------------------------------------------
# SC_CC_FOR_BUILD
#	For cross compiles, locate a C compiler that can generate native binaries.
#
# Arguments:
#	none
#
# Results:
#	Substitutes the following vars:
#		CC_FOR_BUILD
#		EXEEXT_FOR_BUILD
#------------------------------------------------------------------------

dnl Get a default for CC_FOR_BUILD to put into Makefile.
AC_DEFUN([AX_CC_FOR_BUILD],[# Put a plausible default for CC_FOR_BUILD in Makefile.
    if test -z "$CC_FOR_BUILD"; then
      if test "x$cross_compiling" = "xno"; then
        CC_FOR_BUILD='$(CC)'
      else
        AC_MSG_CHECKING([for gcc])
        AC_CACHE_VAL(ac_cv_path_cc, [
            search_path=`echo ${PATH} | sed -e 's/:/ /g'`
            for dir in $search_path ; do
                for j in `ls -r $dir/gcc 2> /dev/null` \
                        `ls -r $dir/gcc 2> /dev/null` ; do
                    if test x"$ac_cv_path_cc" = x ; then
                        if test -f "$j" ; then
                            ac_cv_path_cc=$j
                            break
                        fi
                    fi
                done
            done
        ])
      fi
    fi
    AC_SUBST(CC_FOR_BUILD)
    # Also set EXEEXT_FOR_BUILD.
    if test "x$cross_compiling" = "xno"; then
      EXEEXT_FOR_BUILD='$(EXEEXT)'
      OBJEXT_FOR_BUILD='$(OBJEXT)'
    else
      OBJEXT_FOR_BUILD='.no'
      AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
        [rm -f conftest*
         echo 'int main () { return 0; }' > conftest.c
         bfd_cv_build_exeext=
         ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
         for file in conftest.*; do
           case $file in
           *.c | *.o | *.obj | *.ilk | *.pdb) ;;
           *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
           esac
         done
         rm -f conftest*
         test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
      EXEEXT_FOR_BUILD=""
      test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
    fi
    AC_SUBST(EXEEXT_FOR_BUILD)])dnl
    AC_SUBST(OBJEXT_FOR_BUILD)])dnl
])


#------------------------------------------------------------------------
# SC_ZIPFS_SUPPORT
#	Locate a zip encoder installed on the system path, or none.
#
# Arguments:
#	none
#
# Results:
#	Substitutes the following vars:
#       MACHER_PROG
#       ZIP_PROG
#       ZIP_PROG_OPTIONS
#       ZIP_PROG_VFSSEARCH
#       ZIP_INSTALL_OBJS
#------------------------------------------------------------------------

AC_DEFUN([SC_ZIPFS_SUPPORT], [
    MACHER_PROG=""
    ZIP_PROG=""
    ZIP_PROG_OPTIONS=""
    ZIP_PROG_VFSSEARCH=""
    ZIP_INSTALL_OBJS=""

    AC_MSG_CHECKING([for macher])
    AC_CACHE_VAL(ac_cv_path_macher, [
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/macher 2> /dev/null` \
            `ls -r $dir/macher 2> /dev/null` ; do
        if test x"$ac_cv_path_macher" = x ; then
            if test -f "$j" ; then
            ac_cv_path_macher=$j
            break
            fi
        fi
        done
    done
    ])
    if test -f "$ac_cv_path_macher" ; then
        MACHER_PROG="$ac_cv_path_macher"
        AC_MSG_RESULT([$MACHER_PROG])
        AC_MSG_RESULT([Found macher in environment])
    fi
    AC_MSG_CHECKING([for zip])
    AC_CACHE_VAL(ac_cv_path_zip, [
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/zip 2> /dev/null` \
            `ls -r $dir/zip 2> /dev/null` ; do
        if test x"$ac_cv_path_zip" = x ; then
            if test -f "$j" ; then
            ac_cv_path_zip=$j
            break
            fi
        fi
        done
    done
    ])
    if test -f "$ac_cv_path_zip" ; then
        ZIP_PROG="$ac_cv_path_zip"
        AC_MSG_RESULT([$ZIP_PROG])
        ZIP_PROG_OPTIONS="-rq"
        ZIP_PROG_VFSSEARCH="*"
        AC_MSG_RESULT([Found INFO Zip in environment])
        # Use standard arguments for zip
    else
        # It is not an error if an installed version of Zip can't be located.
        # We can use the locally distributed minizip instead
        ZIP_PROG="./minizip${EXEEXT_FOR_BUILD}"
        ZIP_PROG_OPTIONS="-o -r"
        ZIP_PROG_VFSSEARCH="*"
        ZIP_INSTALL_OBJS="minizip${EXEEXT_FOR_BUILD}"
        AC_MSG_RESULT([No zip found on PATH. Building minizip])
    fi
    AC_SUBST(MACHER_PROG)
    AC_SUBST(ZIP_PROG)
    AC_SUBST(ZIP_PROG_OPTIONS)
    AC_SUBST(ZIP_PROG_VFSSEARCH)
    AC_SUBST(ZIP_INSTALL_OBJS)
])

# Local Variables:
# mode: autoconf
# End:

Changes to unix/tk.pc.in.

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
1
2
3
4
5
6

7
8
9

10
11
12
13
14
15






-



-
+





# tk pkg-config source file

prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
demodir=@TK_DEMO_DIR@

Name: The Tk Toolkit
Description: Tk is a cross-platform graphical user interface toolkit, the standard GUI not only for Tcl, but for many other dynamic languages as well.
URL: https://www.tcl-lang.org/
URL: http://www.tcl.tk/
Version: @TK_VERSION@@TK_PATCH_LEVEL@
Requires: tcl >= 8.6
Libs: -L${libdir} @TK_LIB_FLAG@ @TK_STUB_LIB_FLAG@
Libs.private: @XFT_LIBS@ @XLIBSW@
Cflags: -I${includedir}

Changes to unix/tk.spec.

1
2
3
4
5
6
7

8
9
10
11
12

13
14
15


16
17
18
19
20
21
22
1
2
3
4
5
6

7
8
9
10
11

12
13


14
15
16
17
18
19
20
21
22






-
+




-
+

-
-
+
+







# This file is the basis for a binary Tk Linux RPM.

%{!?directory:%define directory /usr/local}

Name:          tk
Summary:       Tk graphical toolkit for the Tcl scripting language.
Version:       9.0b2
Version:       8.7a0
Release:       2
License:       BSD
Group:         Development/Languages
Source:        http://prdownloads.sourceforge.net/tcl/tk%{version}-src.tar.gz
URL:           https://www.tcl-lang.org/
URL:           http://www.tcl.tk/
Buildroot:     /var/tmp/%{name}%{version}
Buildrequires: XFree86-devel tcl >= 8.7.0
Requires:      tcl >= 8.7.0
Buildrequires: XFree86-devel tcl >= 8.6.0
Requires:      tcl >= 8.6.0

%description
The Tcl (Tool Command Language) provides a powerful platform for
creating integration applications that tie together diverse
applications, protocols, devices, and frameworks.  When paired with
the Tk toolkit, Tcl provides the fastest and most powerful way to
create GUI applications that run on PCs, Unix, and Mac OS X.  Tcl

Changes to unix/tkAppInit.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
8
9
10
11
12
13
14



















15
16
17





18
19




20



21
22
23
24
25
26
27
28
29
30
31
32




33

34
35
36
37
38
39
40







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-


-
-
-
-
+
-
-
-












-
-
-
-
+
-







 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Explanation on following undef USE_TCL_STUBS by JN 2023-12-19 on the core list:
 * What's going on is related to TIP #596:
 *  Stubs support for Embedding Tcl in other applications
 *
 * If an application using Tcl_Main() is compiled with USE_TCL_STUBS,
 * Tcl_Main() will be replaced by a stub function, which loads
 * libtcl9.0.so/tcl90.dll and then calls its Tcl_MainEx(). If
 * libtcl9.0.so/tcl90.dll is not present (at runtime), a crash is what happens.
 *
 * So ... tkAppInit.c should not be compiled with USE_TCL_STUBS
 * (unless you want to use the TIP #596 functionality)
 *
 * The proper solution is to make sure that Makefile.in doesn't use
 * TCL_USE_STUBS when compiling tkAppInit.c. But that's a
 * quite big re-organization just before a b1 release. Simpler
 * is just to #undef'ine USE_TCL_STUBS, it has the same effect.
 */
#undef USE_TCL_STUBS
#undef BUILD_tk
#undef STATIC_BUILD
#include "tk.h"
#include "tkPort.h"
#if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7
#   define Tcl_LibraryInitProc Tcl_PackageInitProc
#   define Tcl_StaticLibrary Tcl_StaticPackage
#endif

#ifdef TK_TEST
#ifdef __cplusplus
extern "C" {
#endif
extern Tcl_LibraryInitProc Tktest_Init;
extern Tcl_PackageInitProc Tktest_Init;
#ifdef __cplusplus
}
#endif
#endif /* TK_TEST */

/*
 * The following #if block allows you to change the AppInit function by using
 * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The
 * #if checks for that #define and uses Tcl_AppInit if it doesn't exist.
 */

#ifndef TK_LOCAL_APPINIT
#define TK_LOCAL_APPINIT Tcl_AppInit
#endif
#ifndef MODULE_SCOPE
#   ifdef __cplusplus
#	define MODULE_SCOPE extern "C"
#   else
#	define MODULE_SCOPE extern
#   define MODULE_SCOPE extern
#   endif
#endif
MODULE_SCOPE int TK_LOCAL_APPINIT(Tcl_Interp *);
MODULE_SCOPE int main(int, char **);

/*
 * The following #if block allows you to change how Tcl finds the startup
 * script, prime the library or encoding paths, fiddle with the argv, etc.,
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
69
70
71
72
73
74
75



76
77
78
79
80
81
82







-
-
-







int
main(
    int argc,			/* Number of command-line arguments. */
    char **argv)		/* Values of command-line arguments. */
{
#ifdef TK_LOCAL_MAIN_HOOK
    TK_LOCAL_MAIN_HOOK(&argc, &argv);
#elif (TCL_MAJOR_VERSION > 8) || (TCL_MINOR_VERSION > 6)
    /* This doesn't work with Tcl 8.6 */
    TclZipfs_AppHook(&argc, &argv);
#endif

    Tk_Main(argc, argv, TK_LOCAL_APPINIT);
    return 0;			/* Needed only to prevent compiler warning. */
}

/*
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
105
106
107
108
109
110
111

112






113
114
115
116
117

118
119
120
121
122
123
124
125







-
+
-
-
-
-
-
-





-
+







    if ((Tcl_Init)(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }

    if (Tk_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Tk", Tk_Init, Tk_SafeInit);
    Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);

#if defined(USE_CUSTOM_EXIT_PROC)
    if (TkpWantsExitProc()) {
	Tcl_SetExitProc(TkpExitProc);
    }
#endif

#ifdef TK_TEST
    if (Tktest_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Tktest", Tktest_Init, 0);
    Tcl_StaticPackage(interp, "Tktest", Tktest_Init, 0);
#endif /* TK_TEST */

    /*
     * Call the init procedures for included packages. Each call should look
     * like this:
     *
     * if (Mod_Init(interp) == TCL_ERROR) {

Changes to unix/tkConfig.h.in.

9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32



33
34
35
36
37
38


39
40
41


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98



99
100
101
102
103
104
105
9
10
11
12
13
14
15



16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36


37
38
39


40
41



42
43
44
45



46
47
48



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99







-
-
-



-
+










+
+
+




-
-
+
+

-
-
+
+
-
-
-




-
-
-



-
-
-











+
+
+
















-
+





-
-
-





+
+
+








/* Defined when compiler supports casting to union type. */
#undef HAVE_CAST_TO_UNION

/* Do we have access to Darwin CoreFoundation.framework? */
#undef HAVE_COREFOUNDATION

/* Is 'DIR64' in <sys/types.h>? */
#undef HAVE_DIR64

/* Compiler support for module scope symbols */
#undef HAVE_HIDDEN

/* Define to 1 if the system has the type `intptr_t'. */
/* Do we have the intptr_t type? */
#undef HAVE_INTPTR_T

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if you have the `Xft' library (-lXft). */
#undef HAVE_LIBXFT

/* Define to 1 if you have the `lseek64' function. */
#undef HAVE_LSEEK64

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the `open64' function. */
#undef HAVE_OPEN64

/* Define to 1 if you have the `posix_spawnattr_setflags' function. */
#undef HAVE_POSIX_SPAWNATTR_SETFLAGS
/* Define to 1 if you have the `pthread_atfork' function. */
#undef HAVE_PTHREAD_ATFORK

/* Define to 1 if you have the `posix_spawnp' function. */
#undef HAVE_POSIX_SPAWNP
/* Define to 1 if you have the `pthread_attr_setstacksize' function. */
#undef HAVE_PTHREAD_ATTR_SETSTACKSIZE

/* Define to 1 if you have the `posix_spawn_file_actions_adddup2' function. */
#undef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2

/* Does struct password have a pw_gecos field? */
#undef HAVE_PW_GECOS

/* Do we have <stdbool.h>? */
#undef HAVE_STDBOOL_H

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H

/* Define to 1 if you have the <stdio.h> header file. */
#undef HAVE_STDIO_H

/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H

/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H

/* Is 'struct dirent64' in <sys/types.h>? */
#undef HAVE_STRUCT_DIRENT64

/* Is 'struct stat64' in <sys/stat.h>? */
#undef HAVE_STRUCT_STAT64

/* Should we include <sys/select.h>? */
#undef HAVE_SYS_SELECT_H

/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H

/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H

/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H

/* Is off64_t in <sys/types.h>? */
#undef HAVE_TYPE_OFF64_T

/* Define to 1 if the system has the type `uintptr_t'. */
/* Do we have the uintptr_t type? */
#undef HAVE_UINTPTR_T

/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK

/* Is weak import available? */
#undef HAVE_WEAK_IMPORT

/* Have we turned on XFT (antialiased fonts)? */
#undef HAVE_XFT

/* Do we have XkbKeycodeToKeysym? */
#undef HAVE_XKBKEYCODETOKEYSYM

/* Is XScreenSaver available? */
#undef HAVE_XSS

/* Is this a Mac I see before me? */
#undef MAC_OSX_TCL

113
114
115
116
117
118
119



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167


168


169






170
171
172
173
174
175
176



177
178


179
180
181
182
183
184
185

186
187
188
189
190


191
192
193
194
195
196
197
198
199
200
201
202



203
204
205
206
207
208
209
210
211
212
213
214


215
216
217
218
219
220
221
222

223
224
225
226



227
228
229
230
231
232



233
234
235
236
237

238
239
240

241









242
243
244
245
246
247
248


249
250
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129



130
131
132
133
134
135

136


137
138



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177


178
179







180


181


182
183
184
185
186
187



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205


206
207
208
209
210
211
212
213
214

215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253


254
255

256







+
+
+













-
-
-






-
+
-
-


-
-
-


















+
+
-
+
+

+
+
+
+
+
+







+
+
+
-
-
+
+
-
-
-
-
-
-
-
+
-
-

-
-
+
+




-
-
-





+
+
+










-
-
+
+







-
+
-



+
+
+






+
+
+




-
+


-
+

+
+
+
+
+
+
+
+
+





-
-
+
+
-

#undef NDEBUG

/* Is Darwin CoreFoundation unavailable for 64-bit? */
#undef NO_COREFOUNDATION_64

/* Do we have fd_set? */
#undef NO_FD_SET

/* Do we have <stdlib.h>? */
#undef NO_STDLIB_H

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the home page for this package. */
#undef PACKAGE_URL

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Is this a static build? */
#undef STATIC_BUILD

/* Define to 1 if all of the C90 standard headers exist (not just the ones
/* Define to 1 if you have the ANSI C header files. */
   required in a freestanding environment). This macro is provided for
   backward compatibility; new code need not use it. */
#undef STDC_HEADERS

/* What encoding should be used for embedded configuration info? */
#undef TCL_CFGVAL_ENCODING

/* Is this a 64-bit build? */
#undef TCL_CFG_DO64BIT

/* Is this an optimized build? */
#undef TCL_CFG_OPTIMIZED

/* Is bytecode debugging enabled? */
#undef TCL_COMPILE_DEBUG

/* Are bytecode statistics enabled? */
#undef TCL_COMPILE_STATS

/* Is memory debugging enabled? */
#undef TCL_MEM_DEBUG

/* What is the default extension for shared libraries? */
#undef TCL_SHLIB_EXT

/* Are we building with threads enabled? */
#undef TCL_THREADS
/* Do 'long' and 'long long' have the same size (64-bit)? */

/* Are wide integers to be implemented with C 'long's? */
#undef TCL_WIDE_INT_IS_LONG

/* What type should be used to define wide integers? */
#undef TCL_WIDE_INT_TYPE

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME

/* Is Tk built as a framework? */
#undef TK_FRAMEWORK

/* Are TkAqua debug messages enabled? */
#undef TK_MAC_DEBUG

/* Do we want to use the threaded memory allocator? */
#undef USE_THREAD_ALLOC

/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
   significant byte first (like Motorola and SPARC, unlike Intel). */
/* Define to 1 if your processor stores words with the most significant byte
   first (like Motorola and SPARC, unlike Intel and VAX). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
#  define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
#  undef WORDS_BIGENDIAN
#undef WORDS_BIGENDIAN
# endif
#endif

/* Are we building with zipfs enabled? */
#undef ZIPFS_BUILD
/* Is XKeycodeToKeysym deprecated? */
#undef XKEYCODETOKEYSYM_IS_DEPRECATED

/* Are Darwin SUSv3 extensions available? */
#undef _DARWIN_C_SOURCE

/* Add the _FILE_OFFSET_BITS flag when building */
#undef _FILE_OFFSET_BITS

/* Add the _ISOC99_SOURCE flag when building */
#undef _ISOC99_SOURCE

/* Add the _LARGEFILE64_SOURCE flag when building */
#undef _LARGEFILE64_SOURCE

/* Add the _LARGEFILE_SOURCE64 flag when building */
#undef _LARGEFILE_SOURCE64

/* # needed in sys/socket.h Should OS/390 do the right thing with sockets? */
#undef _OE_SOCKETS

/* Do we really want to follow the standard? Yes we do! */
#undef _POSIX_PTHREAD_SEMANTICS

/* Do we want the reentrant OS API? */
#undef _REENTRANT

/* _TIME_BITS=64 enables 64-bit time_t. */
#undef _TIME_BITS
/* Do we want the thread-safe OS API? */
#undef _THREAD_SAFE

/* Do we want to use the XOPEN network library? */
#undef _XOPEN_SOURCE

/* Do we want to use the XOPEN network library? */
#undef _XOPEN_SOURCE_EXTENDED

/* Define to 1 if type `char' is unsigned and your compiler does not
/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
   predefine this macro.  */
#ifndef __CHAR_UNSIGNED__
# undef __CHAR_UNSIGNED__
#endif

/* Define to `int' if <sys/types.h> doesn't define. */
#undef gid_t

/* Define to `__inline__' or `__inline' if that's what the C compiler
   calls it, or to nothing if 'inline' is not supported under any name.  */
#ifndef __cplusplus
#undef inline
#endif

/* Signed integer type wide enough to hold a pointer. */
#undef intptr_t

/* Define to `int' if <sys/types.h> does not define. */
#undef mode_t

/* Define as a signed integer type capable of holding a process identifier. */
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t

/* Define to `unsigned int' if <sys/types.h> does not define. */
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t

/* Do we want to use the strtod() in compat? */
#undef strtod

/* Define to `int' if <sys/types.h> doesn't define. */
#undef uid_t

/* Unsigned integer type wide enough to hold a pointer. */
#undef uintptr_t


    /* Undef unused package specific autoheader defines so that we can
     * include both tclConfig.h and tkConfig.h at the same time: */
    /* override */ #undef PACKAGE_NAME
    /* override */ #undef PACKAGE_TARNAME
    /* override */ #undef PACKAGE_VERSION
    /* override */ #undef PACKAGE_STRING
    /* override */ #undef PACKAGE_TARNAME
    /* override */ #undef PACKAGE_STRING
    #endif /* _TKCONFIG */

Changes to unix/tkConfig.sh.in.

18
19
20
21
22
23
24

25
26
27
28
29
30
31
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32







+







TK_PATCH_LEVEL='@TK_PATCH_LEVEL@'

# -D flags for use with the C compiler.
TK_DEFS='@DEFS@'

# Flag, 1: we built a shared lib, 0 we didn't
TK_SHARED_BUILD=@TK_SHARED_BUILD@


# TK_DBGX used to be used to distinguish debug vs. non-debug builds.
# This was a righteous pain so the core doesn't do that any more.
TK_DBGX=

# The name of the Tk library (may be either a .a file or a shared library):
TK_LIB_FILE='@TK_LIB_FILE@'
90
91
92
93
94
95
96
97
98
99
91
92
93
94
95
96
97










-
-
-
TK_STUB_LIB_SPEC='@TK_STUB_LIB_SPEC@'

# Path to the Tk stub library in the build directory.
TK_BUILD_STUB_LIB_PATH='@TK_BUILD_STUB_LIB_PATH@'

# Path to the Tk stub library in the install directory.
TK_STUB_LIB_PATH='@TK_STUB_LIB_PATH@'

# Top-level directory in which Tk's demo files are installed.
TK_DEMO_DIR='@TK_DEMO_DIR@'

Changes to unix/tkUnix.c.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26







-
+










-
+







/*
 * tkUnix.c --
 *
 *	This file contains procedures that are UNIX/X-specific, and will
 *	probably have to be written differently for Windows or Macintosh
 *	platforms.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#ifdef HAVE_XSS
#   include <X11/extensions/scrnsaver.h>
#   ifdef __APPLE__
/* Support for weak-linked libXss. */
#	define HaveXSSLibrary()	(&XScreenSaverQueryInfo != NULL)
#	define HaveXSSLibrary()	(XScreenSaverQueryInfo != NULL)
#   else
/* Other platforms always link libXss. */
#	define HaveXSSLibrary()	(1)
#   endif
#endif

/*
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
104
105
106
107
108
109
110





111
112
113
114


























115
116
117
118
119
120
121







-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







void
Tk_UpdatePointer(
    Tk_Window tkwin,		/* Window to which pointer event is reported.
				 * May be NULL. */
    int x, int y,		/* Pointer location in root coords. */
    int state)			/* Modifier state mask. */
{
  (void)tkwin;
  (void)x;
  (void)y;
  (void)state;

  /*
   * This function intentionally left blank
   */
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCopyRegion --
 *
 *	Makes the destination region a copy of the source region.
 *	Currently unused on X11.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpCopyRegion(
    TkRegion dst,
    TkRegion src)
{
    /* XUnionRegion() in Xlib is optimized to detect copying */
    XUnionRegion((Region)src, (Region)src, (Region)dst);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpBuildRegionFromAlphaData --
 *
 *	Set up a rectangle of the given region based on the supplied alpha
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
195
196
197
198
199
200
201


202
203



204
205
206
207
208
209
210







-
-
+

-
-
-







 * Side effects:
 *	None.
 *----------------------------------------------------------------------
 */

long
Tk_GetUserInactiveTime(
 #ifdef HAVE_XSS
   Display *dpy)		/* The display for which to query the inactive
    Display *dpy)		/* The display for which to query the inactive
				 * time. */
#else
  TCL_UNUSED(Display *))
#endif /* HAVE_XSS */
{
    long inactiveTime = -1;
#ifdef HAVE_XSS
    int eventBase, errorBase, major, minor;

    /*
     * Calling XScreenSaverQueryVersion seems to be needed to prevent a crash

Changes to unix/tkUnix3d.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15

16


17
18
19
20
21
22
23






-
+








-
+
-
-







/*
 * tkUnix3d.c --
 *
 *	This file contains the platform specific routines for drawing 3d
 *	borders in the Motif style.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tk3d.h"

#if defined(MAC_OSX_TK)
#if !(defined(_WIN32) || defined(MAC_OSX_TK))
#include "tkMacOSXInt.h"
#else
#include "tkUnixInt.h"
#endif

/*
 * This structure is used to keep track of the extra colors used by Unix 3D
 * borders.
 */
44
45
46
47
48
49
50
51

52
53

54
55
56
57
58
59
60
42
43
44
45
46
47
48

49
50

51
52
53
54
55
56
57
58







-
+

-
+







 *
 *----------------------------------------------------------------------
 */

TkBorder *
TkpGetBorder(void)
{
    UnixBorder *borderPtr = (UnixBorder *)ckalloc(sizeof(UnixBorder));
    UnixBorder *borderPtr = ckalloc(sizeof(UnixBorder));

    borderPtr->solidGC = NULL;
    borderPtr->solidGC = None;
    return (TkBorder *) borderPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpFreeBorder --
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86







-
+







void
TkpFreeBorder(
    TkBorder *borderPtr)
{
    UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
    Display *display = DisplayOfScreen(borderPtr->screen);

    if (unixBorderPtr->solidGC != NULL) {
    if (unixBorderPtr->solidGC != None) {
	Tk_FreeGC(display, unixBorderPtr->solidGC);
    }
}
/*
 *--------------------------------------------------------------
 *
 * Tk_3DVerticalBevel --
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134







-
+







				 * TK_RELIEF_RAISED means interior of object
				 * should appear higher than exterior. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    GC left, right;
    Display *display = Tk_Display(tkwin);

    if ((borderPtr->lightGC == NULL) && (relief != TK_RELIEF_FLAT)) {
    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    if (relief == TK_RELIEF_RAISED) {
	XFillRectangle(display, drawable,
		(leftBevel) ? borderPtr->lightGC : borderPtr->darkGC,
		x, y, (unsigned) width, (unsigned) height);
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169







-
+







	right = borderPtr->lightGC;
	goto ridgeGroove;
    } else if (relief == TK_RELIEF_FLAT) {
	XFillRectangle(display, drawable, borderPtr->bgGC, x, y,
		(unsigned) width, (unsigned) height);
    } else if (relief == TK_RELIEF_SOLID) {
	UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
	if (unixBorderPtr->solidGC == NULL) {
	if (unixBorderPtr->solidGC == None) {
	    XGCValues gcValues;

	    gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
	    unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	}
	XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
		(unsigned) width, (unsigned) height);
214
215
216
217
218
219
220
221

222
223
224
225

226
227
228
229
230
231
232
212
213
214
215
216
217
218

219
220
221
222

223
224
225
226
227
228
229
230







-
+



-
+







				 * TK_RELIEF_RAISED means interior of object
				 * should appear higher than exterior. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    Display *display = Tk_Display(tkwin);
    int bottom, halfway, x1, x2, x1Delta, x2Delta;
    UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
    GC topGC = NULL, bottomGC = NULL;
    GC topGC = None, bottomGC = None;
				/* Initializations needed only to prevent
				 * compiler warnings. */

    if ((borderPtr->lightGC == NULL) && (relief != TK_RELIEF_FLAT) &&
    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT) &&
	    (relief != TK_RELIEF_SOLID)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    /*
     * Compute a GC for the top half of the bevel and a GC for the bottom half
     * (they're the same in many cases).
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256







-
+







	topGC = bottomGC = (topBevel? borderPtr->lightGC : borderPtr->darkGC);
	break;
    case TK_RELIEF_RIDGE:
	topGC = borderPtr->lightGC;
	bottomGC = borderPtr->darkGC;
	break;
    case TK_RELIEF_SOLID:
	if (unixBorderPtr->solidGC == NULL) {
	if (unixBorderPtr->solidGC == None) {
	    XGCValues gcValues;

	    gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
	    unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	}
	XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
		(unsigned) width, (unsigned) height);
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







-
+







				 * drawing. */
{
    XColor lightColor, darkColor;
    int stressed, tmp1, tmp2;
    int r, g, b;
    XGCValues gcValues;

    if (borderPtr->lightGC != NULL) {
    if (borderPtr->lightGC != None) {
	return;
    }
    stressed = TkpCmapStressed(tkwin, borderPtr->colormap);

    /*
     * First, handle the case of a color display with lots of colors. The
     * shadow colors get computed using whichever formula results in the
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453







-
+







	borderPtr->lightColorPtr = Tk_GetColorByValue(tkwin, &lightColor);
	gcValues.foreground = borderPtr->lightColorPtr->pixel;
	borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	return;
    }

    if (borderPtr->shadow == None) {
	borderPtr->shadow = Tk_GetBitmap(NULL, tkwin,
	borderPtr->shadow = Tk_GetBitmap((Tcl_Interp *) NULL, tkwin,
		Tk_GetUid("gray50"));
	if (borderPtr->shadow == None) {
	    Tcl_Panic("TkpGetShadows couldn't allocate bitmap for border");
	}
    }
    if (borderPtr->visual->map_entries > 2) {
	/*

Changes to unix/tkUnixButton.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkUnixButton.c --
 *
 *	This file implements the Unix specific portion of the button widgets.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkButton.h"
34
35
36
37
38
39
40
41
42


43
44
45












































































46

47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175



176
177
178
179
180
181





182
183
184
185
186
187

188
189
190

191
192
193

194
195
196
197
198
199
200
201
202
203
204
205


206

207

208
209
210
211
212
213
214
215




216
217
218
219
220
221





222
223
224
225
226
227




228
229
230
231
232
233





234
235
236
237
238
239



240
241

















242
243
244
245
246
247

248
249
250


251
252


253
254
255
256



257
258
259
260
261
262





263
264
265
266
267




268
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287


288
289
290
291
292




293
294
295
296
297
298
299





300
301
302
303



304
305

306
307
308

309
310
311
312
313
314
315
316
317
318

319
320
321
322

323
324
325
326
327

328
329
330
331

332
333
334
335
336
337

338
339
340
341
342

343
344
345

346
347
348


349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

370


371

372
373
374
375
376
377
378
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
125
126
127
128

129
130



































































131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146





















147
148
149
150
151
152
153
154
155
156
157
158
159
160



161
162
163
164





165
166
167
168
169






170
171
172

173
174
175

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193

194
195
196
197
198


199
200
201
202
203
204
205
206


207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
223


224
225
226
227
228
229
230
231

232
233
234
235
236


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257


258



259
260


261
262




263
264
265






266
267
268
269
270





271
272
273
274


275




276










277



278
279
280




281
282
283
284
285






286
287
288
289
290
291



292
293
294


295



296










297




298





299




300






301



302

303
304
305

306



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332

333
334
335
336
337
338
339
340







-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+






-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+


-
+


-
+












+
+

+
-
+
-





-
-
+
+
+
+




-
-
+
+
+
+
+




-
-
+
+
+
+




-
-
+
+
+
+
+



-


+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
-
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-

-
+


-
+
-
-
-
+
+




















-
+

+
+
-
+







/*
 * The class function table for the button widgets.
 */

const Tk_ClassProcs tkpButtonProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    TkButtonWorldChanged,	/* worldChangedProc */
    NULL,			/* createProc */
    NULL			/* modalProc */
    NULL,					/* createProc */
    NULL					/* modalProc */
};

/*
 * The button image.
 * The header info here is ignored, it's the image that's important. The
 * colors will be applied as follows:
 *   A = Background
 *   B = Background
 *   C = 3D light
 *   D = selectColor
 *   E = 3D dark
 *   F = Background
 *   G = Indicator Color
 *   H = disabled Indicator Color
 */

/* XPM */
static const char *const button_images[] = {
    /* width height ncolors chars_per_pixel */
    "52 26 7 1",
    /* colors */
    "A c #808000000000",
    "B c #000080800000",
    "C c #808080800000",
    "D c #000000008080",
    "E c #808000008080",
    "F c #000080808080",
    "G c #000000000000",
    "H c #000080800000",
    /* pixels */
    "AAAAAAAAAAAABAAAAAAAAAAAABAAAAAAAAAAAABAAAAAAAAAAAAB",
    "AEEEEEEEEEECBAEEEEEEEEEECBAEEEEEEEEEECBAEEEEEEEEEECB",
    "AEDDDDDDDDDCBAEDDDDDDDDDCBAEFFFFFFFFFCBAEFFFFFFFFFCB",
    "AEDDDDDDDDDCBAEDDDDDDDGDCBAEFFFFFFFFFCBAEFFFFFFFHFCB",
    "AEDDDDDDDDDCBAEDDDDDDGGDCBAEFFFFFFFFFCBAEFFFFFFHHFCB",
    "AEDDDDDDDDDCBAEDGDDDGGGDCBAEFFFFFFFFFCBAEFHFFFHHHFCB",
    "AEDDDDDDDDDCBAEDGGDGGGDDCBAEFFFFFFFFFCBAEFHHFHHHFFCB",
    "AEDDDDDDDDDCBAEDGGGGGDDDCBAEFFFFFFFFFCBAEFHHHHHFFFCB",
    "AEDDDDDDDDDCBAEDDGGGDDDDCBAEFFFFFFFFFCBAEFFHHHFFFFCB",
    "AEDDDDDDDDDCBAEDDDGDDDDDCBAEFFFFFFFFFCBAEFFFHFFFFFCB",
    "AEDDDDDDDDDCBAEDDDDDDDDDCBAEFFFFFFFFFCBAEFFFFFFFFFCB",
    "ACCCCCCCCCCCBACCCCCCCCCCCBACCCCCCCCCCCBACCCCCCCCCCCB",
    "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
    "FFFFAAAAFFFFFFFFFAAAAFFFFFFFFFAAAAFFFFFFFFFAAAAFFFFF",
    "FFAAEEEEAAFFFFFAAEEEEAAFFFFFAAEEEEAAFFFFFAAEEEEAAFFF",
    "FAEEDDDDEEBFFFAEEDDDDEEBFFFAEEFFFFEEBFFFAEEFFFFEEBFF",
    "FAEDDDDDDCBFFFAEDDDDDDCBFFFAEFFFFFFCBFFFAEFFFFFFCBFF",
    "AEDDDDDDDDCBFAEDDDGGDDDCBFAEFFFFFFFFCBFAEFFFHHFFFCBF",
    "AEDDDDDDDDCBFAEDDGGGGDDCBFAEFFFFFFFFCBFAEFFHHHHFFCBF",
    "AEDDDDDDDDCBFAEDDGGGGDDCBFAEFFFFFFFFCBFAEFFHHHHFFCBF",
    "AEDDDDDDDDCBFAEDDDGGDDDCBFAEFFFFFFFFCBFAEFFFHHFFFCBF",
    "FAEDDDDDDCBFFFAEDDDDDDCBFFFAEFFFFFFCBFFFAEFFFFFFCBFF",
    "FACCDDDDCCBFFFACCDDDDCCBFFFACCFFFFCCBFFFACCFFFFCCBFF",
    "FFBBCCCCBBFFFFFBBCCCCBBFFFFFBBCCCCBBFFFFFBBCCCCBBFFF",
    "FFFFBBBBFFFFFFFFFBBBBFFFFFFFFFBBBBFFFFFFFFFBBBBFFFFF",
    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
};

/*
 * Sizes and offsets into above XPM file.
 */

#define CHECK_BUTTON_DIM    13
#define CHECK_MENU_DIM       9
#define CHECK_START          9
#define CHECK_ON_OFFSET     13
#define CHECK_OFF_OFFSET     0
#define CHECK_DISON_OFFSET  39
#define CHECK_DISOFF_OFFSET 26
#define RADIO_BUTTON_DIM    12
#define RADIO_MENU_DIM       6
#define RADIO_WIDTH         13
#define RADIO_START         22
#define RADIO_ON_OFFSET     13
#define RADIO_OFF_OFFSET     0
#define RADIO_DISON_OFFSET  39
#define RADIO_DISOFF_OFFSET 26

/*
 * Indicator draw modes
 * Indicator Draw Modes
 */

#define CHECK_BUTTON 0
#define CHECK_MENU   1
#define RADIO_BUTTON 2
#define RADIO_MENU   3


/*
 * Indicator sizes
 */

#define CHECK_BUTTON_DIM 16
#define CHECK_MENU_DIM    8
#define RADIO_BUTTON_DIM 16
#define RADIO_MENU_DIM    8

/*
 * Data of the SVG images used for drawing the indicators
 */

static const char checkbtnOffData[] =
    "<svg id='checkbutton' width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <path id='borderdark' d='m0 0v16l1-1v-14h14l1-1h-16z' fill='#DARKKK'/>\n"
    " <path id='borderlight' d='m16 0-1 1v14h-14l-1 1h16v-16z' fill='#LIGHTT'/>\n"
    " <rect id='rectbackdrop' x='2' y='2' width='12' height='12' fill='#INTROR'/>\n"
    "</svg>";

static const char checkbtnOnData[] =
    "<svg id='checkbutton' width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <path id='borderdark' d='m0 0v16l1-1v-14h14l1-1h-16z' fill='#DARKKK'/>\n"
    " <path id='borderlight' d='m16 0-1 1v14h-14l-1 1h16v-16z' fill='#LIGHTT'/>\n"
    " <rect id='rectbackdrop' x='2' y='2' width='12' height='12' fill='#INTROR'/>\n"
    " <path id='indicator' d='m4.5 8 3 3 4-6' fill='none' stroke='#INDCTR' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/>\n"
    "</svg>";

static const char radiobtnOffData[] =
    "<svg id='radiobutton' width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <defs>\n"
    "  <linearGradient id='gradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n"
    "   <stop stop-color='#DARKKK' offset='0'/>\n"
    "   <stop stop-color='#LIGHTT' offset='1' stop-opacity='0'/>\n"
    "  </linearGradient>\n"
    " </defs>\n"
    " <circle cx='8' cy='8' r='8' fill='url(#gradient)'/>\n"
    " <circle cx='8' cy='8' r='6.5' fill='#INTROR'/>\n"
    "</svg>";

static const char radiobtnOnData[] =
    "<svg id='radiobutton' width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <defs>\n"
    "  <linearGradient id='gradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n"
    "   <stop stop-color='#DARKKK' offset='0'/>\n"
    "   <stop stop-color='#LIGHTT' offset='1' stop-opacity='0'/>\n"
    "  </linearGradient>\n"
    " </defs>\n"
    " <circle cx='8' cy='8' r='8' fill='url(#gradient)'/>\n"
    " <circle cx='8' cy='8' r='7' fill='#INTROR'/>\n"
    " <circle cx='8' cy='8' r='4' fill='#INDCTR'/>\n"
    "</svg>";

static const char menuOffData[] =
    "<svg width='8' height='8' version='1.1' xmlns='http://www.w3.org/2000/svg'></svg>";

static const char checkmenuOnData[] =
    "<svg width='8' height='8' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <path id='indicator' d='m1 3.5 2.5 3 3.5-5' fill='none' stroke='#INDCTR' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.975'/>\n"
    "</svg>";

static const char radiomenuOnData[] =
    "<svg width='8' height='8' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"
    " <circle cx='4' cy='4' r='3' fill='#INDCTR'/>\n"
    "</svg>";


/*
 *----------------------------------------------------------------------
 *
 * TkpDrawCheckIndicator -
 *
 *	Draws the checkbox image in the drawable at the (x,y) location, value,
 *	and state given. This routine is used by the button and menu widgets.
 *	and state given. This routine is use by the button and menu widgets
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	An image is drawn in the drawable at the location given.
 *
 *----------------------------------------------------------------------
 */

static void
ColorToStr(
    const XColor *colorPtr,	/* specifies a color */
    char *colorStr)		/* memory area to which the color is to be
				   output in the format "RRGGBB" */
{
    snprintf(colorStr, 7, "%02x%02x%02x",
	     colorPtr->red >> 8, colorPtr->green >> 8, colorPtr->blue >> 8);
}

static void
ImageChanged(			/* to be passed to Tk_GetImage() */
    void *clientData,
    int x, int y, int width, int height,
    int imageWidth, int imageHeight)
{
    (void)clientData;
    (void)x; (void)y; (void)width; (void)height;
    (void)imageWidth; (void)imageHeight;
}

void
TkpDrawCheckIndicator(
    Tk_Window tkwin,		/* handle for resource alloc */
    Display *display,
    Drawable d,			/* what to draw on */
    int x, int y,		/* where to draw */
    Tk_3DBorder bgBorder,	/* colors of the border */
    XColor *indicatorColor,	/* color of the indicator */
    XColor *selectColor,	/* color when selected */
    XColor *disableColor,	/* color when disabled */
    int on,			/* are we on? */
    int disabled,		/* are we disabled? */
    int mode)			/* kind of indicator to draw */
{
    const char *svgDataPtr;
    int hasBorder, hasInterior, dim;
    double scalingLevel = TkScalingLevel(tkwin);
    int ix, iy;
    int dim;
    int imgsel, imgstart;
    TkBorder *bg_brdr = (TkBorder*)bgBorder;
    char darkColorStr[7], lightColorStr[7], interiorColorStr[7], indicatorColorStr[7];
    Tcl_Interp *interp = Tk_Interp(tkwin);
    char imgName[60];
    Tk_Image img;
    size_t svgDataLen;
    XGCValues gcValues;
    GC copyGC;
    unsigned long imgColors[8];
    XImage *img;
    Pixmap pixmap;
    char *svgDataCopy;
    char *darkColorPtr, *lightColorPtr, *interiorColorPtr, *indicatorColorPtr;
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    int code;
    int depth;

    /*
     * Sanity check
     * Sanity check.
     */

    if (tkwin == NULL || display == NULL || d == None || bgBorder == NULL
    if (tkwin == NULL || display == None || d == None || bgBorder == NULL
	    || indicatorColor == NULL) {
	return;
    }

    if (disableColor == NULL) {
	disableColor = bg_brdr->bgColorPtr;
    }

    if (selectColor == NULL) {
	selectColor = bg_brdr->bgColorPtr;
    }

    depth = Tk_Depth(tkwin);

    /*
     * Compute starting point and dimensions of image inside button_images to
     * Determine the SVG data to use for the
     * be used.
     * photo image and the latter's dimensions
     */

    switch (mode) {
    default:
    case CHECK_BUTTON:
	svgDataPtr = (on == 0 ? checkbtnOffData : checkbtnOnData);
	hasBorder = 1; hasInterior = 1;
	imgsel = on == 2 ? CHECK_DISON_OFFSET :
		on == 1 ? CHECK_ON_OFFSET : CHECK_OFF_OFFSET;
	imgsel += disabled && on != 2 ? CHECK_DISOFF_OFFSET : 0;
	imgstart = CHECK_START;
	dim = CHECK_BUTTON_DIM;
	break;

    case CHECK_MENU:
	svgDataPtr = (on == 0 ? menuOffData : checkmenuOnData);
	hasBorder = 0; hasInterior = 0;
	imgsel = on == 2 ? CHECK_DISOFF_OFFSET :
		on == 1 ? CHECK_ON_OFFSET : CHECK_OFF_OFFSET;
	imgsel += disabled && on != 2 ? CHECK_DISOFF_OFFSET : 0;
	imgstart = CHECK_START + 2;
	imgsel += 2;
	dim = CHECK_MENU_DIM;
	break;

    case RADIO_BUTTON:
	svgDataPtr = (on == 0 ? radiobtnOffData : radiobtnOnData);
	hasBorder = 1; hasInterior = 1;
	imgsel = on == 2 ? RADIO_DISON_OFFSET :
		on==1 ? RADIO_ON_OFFSET : RADIO_OFF_OFFSET;
	imgsel += disabled && on != 2 ? RADIO_DISOFF_OFFSET : 0;
	imgstart = RADIO_START;
	dim = RADIO_BUTTON_DIM;
	break;

    case RADIO_MENU:
	svgDataPtr = (on == 0 ? menuOffData : radiomenuOnData);
	hasBorder = 0; hasInterior = 0;
	imgsel = on == 2 ? RADIO_DISOFF_OFFSET :
		on==1 ? RADIO_ON_OFFSET : RADIO_OFF_OFFSET;
	imgsel += disabled && on != 2 ? RADIO_DISOFF_OFFSET : 0;
	imgstart = RADIO_START + 3;
	imgsel += 3;
	dim = RADIO_MENU_DIM;
	break;
    }
    dim = (int)(dim * scalingLevel);

    /*
     * Allocate the drawing areas to use. Note that we use double-buffering
     * here because not all code paths leading to this function do so.
     */
     * Construct the color strings darkColorStr, lightColorStr,
     * interiorColorStr, and indicatorColorStr

    pixmap = Tk_GetPixmap(display, d, dim, dim, depth);
    if (pixmap == None) {
	return;
    }

    x -= dim/2;
    y -= dim/2;

    img = XGetImage(display, pixmap, 0, 0,
	    (unsigned int)dim, (unsigned int)dim, AllPlanes, ZPixmap);
    if (img == NULL) {
	return;
    }

    /*
     * Set up the color mapping table.
     */

    TkpGetShadows(bg_brdr, tkwin);

    if (bg_brdr->darkColorPtr == NULL) {
	strcpy(darkColorStr, "000000");
    imgColors[0 /*A*/] =
    } else {
	ColorToStr(Tk_GetColorByValue(tkwin, bg_brdr->darkColorPtr),
		   darkColorStr);
	    Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel;
    imgColors[1 /*B*/] =
    }
    if (bg_brdr->lightColorPtr == NULL) {
	    Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel;
    imgColors[2 /*C*/] = (bg_brdr->lightColorPtr != NULL) ?
	strcpy(lightColorStr, "ffffff");
    } else {
	ColorToStr(Tk_GetColorByValue(tkwin, bg_brdr->lightColorPtr),
		   lightColorStr);
	    Tk_GetColorByValue(tkwin, bg_brdr->lightColorPtr)->pixel :
	    WhitePixelOfScreen(bg_brdr->screen);
    imgColors[3 /*D*/] =
    }
    if (on == 2 || disabled) {			/* tri-state or disabled */
	ColorToStr(Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr),
		   interiorColorStr);
	ColorToStr(Tk_GetColorByValue(tkwin, disableColor),
		   indicatorColorStr);
	    Tk_GetColorByValue(tkwin, selectColor)->pixel;
    imgColors[4 /*E*/] = (bg_brdr->darkColorPtr != NULL) ?
	    Tk_GetColorByValue(tkwin, bg_brdr->darkColorPtr)->pixel :
	    BlackPixelOfScreen(bg_brdr->screen);
    imgColors[5 /*F*/] =
    } else {
	ColorToStr(Tk_GetColorByValue(tkwin, selectColor),
		   interiorColorStr);
	ColorToStr(Tk_GetColorByValue(tkwin, indicatorColor),
		   indicatorColorStr);
	    Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel;
    imgColors[6 /*G*/] =
	    Tk_GetColorByValue(tkwin, indicatorColor)->pixel;
    imgColors[7 /*H*/] =
    }

	    Tk_GetColorByValue(tkwin, disableColor)->pixel;
    /*
     * Check whether there is an SVG image of this size
     * for the value of mode and these color strings
     */

    snprintf(imgName, sizeof(imgName),
	     "::tk::icons::indicator%d_%d_%s_%s_%s_%s",
	     dim, mode,
	     hasBorder ? darkColorStr : "XXXXXX",
	     hasBorder ? lightColorStr : "XXXXXX",
	     hasInterior ? interiorColorStr : "XXXXXX",
	     on ? indicatorColorStr : "XXXXXX");
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
	/*
    /*
	 * Copy the string pointed to by svgDataPtr to
	 * a newly allocated memory area svgDataCopy
	 */
     * Create the image, painting it into an XImage one pixel at a time.
     */

	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
	    return;
    for (iy=0 ; iy<dim ; iy++) {
	for (ix=0 ; ix<dim ; ix++) {
	    XPutPixel(img, ix, iy,
		    imgColors[button_images[imgstart+iy][imgsel+ix] - 'A']);
	}
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	/*
	 * Update the colors within svgDataCopy
	 */
    }

    /*
     * Copy onto our target drawable surface.
     */

	darkColorPtr =      strstr(svgDataCopy, "DARKKK");
	lightColorPtr =     strstr(svgDataCopy, "LIGHTT");
	interiorColorPtr =  strstr(svgDataCopy, "INTROR");
    memset(&gcValues, 0, sizeof(gcValues));
    gcValues.background = bg_brdr->bgColorPtr->pixel;
    gcValues.graphics_exposures = False;
	indicatorColorPtr = strstr(svgDataCopy, "INDCTR");

    copyGC = Tk_GetGC(tkwin, 0, &gcValues);
	if (darkColorPtr != NULL) {
	    memcpy(darkColorPtr, darkColorStr, 6);
	}

	if (lightColorPtr != NULL) {
	    memcpy(lightColorPtr, lightColorStr, 6);
	}
	if (interiorColorPtr != NULL) {
	    memcpy(interiorColorPtr, interiorColorStr, 6);
	}
	if (indicatorColorPtr != NULL) {
	    memcpy(indicatorColorPtr, indicatorColorStr, 6);
	}

    XPutImage(display, pixmap, copyGC, img, 0, 0, 0, 0,
	/*
	 * Create an SVG photo image from svgDataCopy
	 */

	    (unsigned)dim, (unsigned)dim);
	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
    XCopyArea(display, pixmap, d, copyGC, 0, 0,
	    return;
	}
	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
	    (unsigned)dim, (unsigned)dim, x, y);
	code = Tcl_EvalEx(interp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	ckfree(script);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	    return;
	}

	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }

    /*
     * Adjust the image's coordinates in the drawable and display the image
     * Tidy up.
     */

    x -= dim/2;
    Tk_FreeGC(display, copyGC);
    y -= dim/2;
    Tk_RedrawImage(img, 0, 0, dim, dim, d, x, y);
    Tk_FreeImage(img);
    XDestroyImage(img);
    Tk_FreePixmap(display, pixmap);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateButton --
 *
 *	Allocate a new TkButton structure.
 *
 * Results:
 *	Returns a newly allocated TkButton structure.
 *
 * Side effects:
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkButton *
TkpCreateButton(
    TCL_UNUSED(Tk_Window))
    Tk_Window tkwin)
{
    UnixButton *butPtr = ckalloc(sizeof(UnixButton));

    return (TkButton *)ckalloc(sizeof(UnixButton));
    return (TkButton *) butPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayButton --
 *
428
429
430
431
432
433
434
435

436
437

438
439
440
441
442
443
444
390
391
392
393
394
395
396

397
398

399
400
401
402
403
404
405
406







-
+

-
+







	*x += shiftX;
	*y += shiftY;
    }
}

void
TkpDisplayButton(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = (TkButton *) clientData;
    GC gc;
    Tk_3DBorder border;
    Pixmap pixmap;
    int x = 0;			/* Initialization only needed to stop compiler
				 * warning. */
    int y, relief;
    Tk_Window tkwin = butPtr->tkwin;
719
720
721
722
723
724
725
726
727
728
729
730




















731
732
733
734
735
736
737
738
739
740
741
742
743











744
745
746
747
748
749
750
681
682
683
684
685
686
687





688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707


708










709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726







-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







    }

    /*
     * Draw the indicator for check buttons and radio buttons. At this point,
     * x and y refer to the top-left corner of the text or image or bitmap.
     */

    if ((butPtr->type == TYPE_CHECK_BUTTON || butPtr->type == TYPE_RADIO_BUTTON)
	    && butPtr->indicatorOn
	    && butPtr->indicatorDiameter > 2*butPtr->borderWidth) {
	TkBorder *selBorder = (TkBorder *) butPtr->selectBorder;
	XColor *selColor = NULL;
    if ((butPtr->type == TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
	if (butPtr->indicatorDiameter > 2*butPtr->borderWidth) {
	    TkBorder *selBorder = (TkBorder *) butPtr->selectBorder;
	    XColor *selColor = NULL;

	    if (selBorder != NULL) {
		selColor = selBorder->bgColorPtr;
	    }
	    x -= butPtr->indicatorSpace/2;
	    y = Tk_Height(tkwin)/2;
	    TkpDrawCheckIndicator(tkwin, butPtr->display, pixmap, x, y,
		    border, butPtr->normalFg, selColor, butPtr->disabledFg,
		    ((butPtr->flags & SELECTED) ? 1 :
			    (butPtr->flags & TRISTATED) ? 2 : 0),
		    (butPtr->state == STATE_DISABLED), CHECK_BUTTON);
	}
    } else if ((butPtr->type == TYPE_RADIO_BUTTON) && butPtr->indicatorOn) {
	if (butPtr->indicatorDiameter > 2*butPtr->borderWidth) {
	    TkBorder *selBorder = (TkBorder *) butPtr->selectBorder;
	    XColor *selColor = NULL;
	int btype = (butPtr->type == TYPE_CHECK_BUTTON ?
		     CHECK_BUTTON : RADIO_BUTTON);

	if (selBorder != NULL) {
	    selColor = selBorder->bgColorPtr;
	}
	x -= butPtr->indicatorSpace/2;
	y = Tk_Height(tkwin)/2;
	TkpDrawCheckIndicator(tkwin, butPtr->display, pixmap, x, y,
		border, butPtr->normalFg, selColor, butPtr->disabledFg,
		((butPtr->flags & SELECTED) ? 1 :
		 (butPtr->flags & TRISTATED) ? 2 : 0),
		 (butPtr->state == STATE_DISABLED), btype);
	    if (selBorder != NULL) {
		selColor = selBorder->bgColorPtr;
	    }
	    x -= butPtr->indicatorSpace/2;
	    y = Tk_Height(tkwin)/2;
	    TkpDrawCheckIndicator(tkwin, butPtr->display, pixmap, x, y,
		    border, butPtr->normalFg, selColor, butPtr->disabledFg,
		    ((butPtr->flags & SELECTED) ? 1 :
			    (butPtr->flags & TRISTATED) ? 2 : 0),
		    (butPtr->state == STATE_DISABLED), RADIO_BUTTON);
	}
    }

    /*
     * If the button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect. If the widget is
     * selected and we use a different background color when selected, must
     * temporarily modify the GC so the stippling is the right color.
827
828
829
830
831
832
833


834
835
836
837
838
839
840
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818







+
+







	 */

	Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset,
		Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
		butPtr->borderWidth, relief);
    }
    if (butPtr->highlightWidth > 0) {
	GC gc;

	if (butPtr->flags & GOT_FOCUS) {
	    gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap);
	} else {
	    gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder),
		    pixmap);
	}

878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870







-
+







 *	The button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeButtonGeometry(
    TkButton *butPtr)	/* Button whose geometry may have changed. */
    register TkButton *butPtr)	/* Button whose geometry may have changed. */
{
    int width, height, avgWidth, txtWidth, txtHeight;
    int haveImage = 0, haveText = 0;
    Tk_FontMetrics fm;

    butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth;

913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
891
892
893
894
895
896
897

898
899
900
901
902
903
904
905







-
+







	haveImage = 1;
    }

    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(butPtr->textLayout);

	butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
		Tcl_GetString(butPtr->textPtr), TCL_INDEX_NONE, butPtr->wrapLength,
		Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
		butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

	txtWidth = butPtr->textWidth;
	txtHeight = butPtr->textHeight;
	avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(butPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
1008
1009
1010
1011
1012
1013
1014




1015
1016
1017
1018
1019
1020
1021
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003







+
+
+
+







		width = butPtr->width * avgWidth;
	    }
	    if (butPtr->height > 0) {
		height = butPtr->height * fm.linespace;
	    }
	    if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) {
		butPtr->indicatorDiameter = fm.linespace;
		if (butPtr->type == TYPE_CHECK_BUTTON) {
		    butPtr->indicatorDiameter =
			(80*butPtr->indicatorDiameter)/100;
		}
		butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth;
	    }
	}
    }

    /*
     * When issuing the geometry request, add extra space for the indicator,

Changes to unix/tkUnixColor.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkUnixColor.c --
 *
 *	This file contains the platform specific color routines needed for X
 *	support.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkUnixInt.h"
#include "tkColor.h"
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







     * color is allocated twice in different places and then freed twice, the
     * second free generates an error (this bug existed as of 10/1/92). To get
     * around this problem, ignore errors that occur during the free
     * operation.
     */

    visual = tkColPtr->visual;
    if ((visual->c_class != StaticGray) && (visual->c_class != StaticColor)
    if ((visual->class != StaticGray) && (visual->class != StaticColor)
	    && (tkColPtr->color.pixel != BlackPixelOfScreen(screen))
	    && (tkColPtr->color.pixel != WhitePixelOfScreen(screen))) {
	Tk_ErrorHandler handler;

	handler = Tk_CreateErrorHandler(DisplayOfScreen(screen),
		-1, -1, -1, NULL, NULL);
	XFreeColors(DisplayOfScreen(screen), tkColPtr->colormap,
132
133
134
135
136
137
138
139
140
141



142
143
144
145
146

147
148
149

150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
132
133
134
135
136
137
138



139
140
141
142
143
144
145

146
147
148

149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167







-
-
-
+
+
+




-
+


-
+










-
+







     * XParseColor for non-# names: this saves a server round-trip for those
     * names.
     */

    if (*name != '#') {
	XColor screen;

	if (((*name - 'A') & 0xDF) < sizeof(tkWebColors)/sizeof(tkWebColors[0])) {
	    if (!((name[0] - 'G') & 0xDF) && !((name[1] - 'R') & 0xDF)
		    && !((name[2] - 'A') & 0xDB) && !((name[3] - 'Y') & 0xDF)
	if (((*name - 'A') & 0xdf) < sizeof(tkWebColors)/sizeof(tkWebColors[0])) {
	    if (!((name[0] - 'G') & 0xdf) && !((name[1] - 'R') & 0xdf)
		    && !((name[2] - 'A') & 0xdb) && !((name[3] - 'Y') & 0xdf)
		    && !name[4]) {
		name = "#808080808080";
		goto gotWebColor;
	    } else {
		const char *p = tkWebColors[((*name - 'A') & 0x1F)];
		const char *p = tkWebColors[((*name - 'A') & 0x1f)];
		if (p) {
		    const char *q = name;
		    while (!((*p - *(++q)) & 0xDF)) {
		    while (!((*p - *(++q)) & 0xdf)) {
			if (!*p++) {
			    name = p;
			    goto gotWebColor;
			}
		    }
		}
	}
	}
	if (strlen(name) > 99) {
	/* Don't bother to parse this. [Bug 2809525]*/
	return NULL;
	return (TkColor *) NULL;
    } else if (XAllocNamedColor(display, colormap, name, &screen, &color) != 0) {
	    DeleteStressedCmap(display, colormap);
	} else {
	    /*
	     * Couldn't allocate the color. Try translating the name to a
	     * color value, to see whether the problem is a bad color name or
	     * a full colormap. If the colormap is full, then pick an
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195







-
+







	if (XAllocColor(display, colormap, &color) != 0) {
	    DeleteStressedCmap(display, colormap);
	} else {
	    FindClosestColor(tkwin, &color, &color);
	}
    }

    tkColPtr = (TkColor *)ckalloc(sizeof(TkColor));
    tkColPtr = ckalloc(sizeof(TkColor));
    tkColPtr->color = color;

    return tkColPtr;
}

/*
 *----------------------------------------------------------------------
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230







-
+







TkpGetColorByValue(
    Tk_Window tkwin,		/* Window in which color will be used. */
    XColor *colorPtr)		/* Red, green, and blue fields indicate
				 * desired color. */
{
    Display *display = Tk_Display(tkwin);
    Colormap colormap = Tk_Colormap(tkwin);
    TkColor *tkColPtr = (TkColor *)ckalloc(sizeof(TkColor));
    TkColor *tkColPtr = ckalloc(sizeof(TkColor));

    tkColPtr->color.red = colorPtr->red;
    tkColPtr->color.green = colorPtr->green;
    tkColPtr->color.blue = colorPtr->blue;
    if (XAllocColor(display, colormap, &tkColPtr->color) != 0) {
	DeleteStressedCmap(display, colormap);
    } else {
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
280
281

282
283

284
285
286

287
288
289
290
291
292
293
294



295
296
297
298
299
300
301
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280

281
282

283
284
285

286
287
288
289
290
291



292
293
294
295
296
297
298
299
300
301







-
+








-
+

-
+


-
+





-
-
-
+
+
+







{
    TkStressedCmap *stressPtr;
    double tmp, distance, closestDistance;
    int i, closest, numFound;
    XColor *colorPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    Colormap colormap = Tk_Colormap(tkwin);
    XVisualInfo templ, *visInfoPtr;
    XVisualInfo template, *visInfoPtr;

    /*
     * Find the TkStressedCmap structure for this colormap, or create a new
     * one if needed.
     */

    for (stressPtr = dispPtr->stressPtr; ; stressPtr = stressPtr->nextPtr) {
	if (stressPtr == NULL) {
	    stressPtr = (TkStressedCmap *)ckalloc(sizeof(TkStressedCmap));
	    stressPtr = ckalloc(sizeof(TkStressedCmap));
	    stressPtr->colormap = colormap;
	    templ.visualid = XVisualIDFromVisual(Tk_Visual(tkwin));
	    template.visualid = XVisualIDFromVisual(Tk_Visual(tkwin));

	    visInfoPtr = XGetVisualInfo(Tk_Display(tkwin),
		    VisualIDMask, &templ, &numFound);
		    VisualIDMask, &template, &numFound);
	    if (numFound < 1) {
		Tcl_Panic("FindClosestColor couldn't lookup visual");
	    }

	    stressPtr->numColors = visInfoPtr->colormap_size;
	    XFree(visInfoPtr);
	    stressPtr->colorPtr = (XColor *)
		    ckalloc((size_t)stressPtr->numColors * sizeof(XColor));
	    XFree((char *) visInfoPtr);
	    stressPtr->colorPtr =
		    ckalloc(stressPtr->numColors * sizeof(XColor));
	    for (i = 0; i < stressPtr->numColors; i++) {
		stressPtr->colorPtr[i].pixel = (unsigned long) i;
	    }

	    XQueryColors(dispPtr->display, colormap, stressPtr->colorPtr,
		    stressPtr->numColors);

419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
419
420
421
422
423
424
425

426
427
428
429
430
431
432







-







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#undef TkpCmapStressed
int
TkpCmapStressed(
    Tk_Window tkwin,		/* Window that identifies the display
				 * containing the colormap. */
    Colormap colormap)		/* Colormap to check for stress. */
{
    TkStressedCmap *stressPtr;

Changes to unix/tkUnixConfig.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40




41
42
43
44
45
46
47






-
+











-
+





-
+










-
+




-
-
-
-







/*
 * tkUnixConfig.c --
 *
 *	This module implements the Unix system defaults for the configuration
 *	package.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"


/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSystemDefault --
 * TkpGetSystemDefault --
 *
 *	Given a dbName and className for a configuration option, return a
 *	string representation of the option.
 *
 * Results:
 *	Returns a Tcl_Obj* with the string identifier that identifies this
 *	Returns a Tk_Uid that is the string identifier that identifies this
 *	option. Returns NULL if there are no system defaults that match this
 *	pair.
 *
 * Side effects:
 *	None, once the package is initialized.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
Tk_GetSystemDefault(
TkpGetSystemDefault(
    Tk_Window tkwin,		/* A window to use. */
    const char *dbName,		/* The option database name. */
    const char *className)	/* The name of the option class. */
{
    (void)tkwin;
    (void)dbName;
    (void)className;

    return NULL;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4

Changes to unix/tkUnixCursor.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkUnixCursor.c --
 *
 *	This file contains X specific cursor manipulation routines.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkInt.h"

176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190







-
+







 */

#ifndef CURSORFONT
#define CURSORFONT "cursor"
#endif

static Cursor		CreateCursorFromTableOrFile(Tcl_Interp *interp,
			    Tk_Window tkwin, Tcl_Size argc, const char **argv,
			    Tk_Window tkwin, int argc, const char **argv,
			    const struct TkCursorName *tkCursorPtr);

/*
 *----------------------------------------------------------------------
 *
 * TkGetCursorByName --
 *
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220







-
+







    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    Tk_Uid string)		/* Description of cursor. See manual entry for
				 * details on legal syntax. */
{
    TkUnixCursor *cursorPtr = NULL;
    Cursor cursor = None;
    Tcl_Size argc;
    int argc;
    const char **argv = NULL;
    Display *display = Tk_Display(tkwin);
    int inTkTable = 0;
    const struct TkCursorName *tkCursorPtr = NULL;

    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
	return NULL;
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+







	    }
	}
    }

    if ((argv[0][0] != '@') && !inTkTable) {
	XColor fg, bg;
	unsigned int maskIndex;
	const struct CursorName *namePtr;
	register const struct CursorName *namePtr;
	TkDisplay *dispPtr;

	/*
	 * The cursor is to come from the standard cursor font. If one arg, it
	 * is cursor name (use black and white for fg and bg). If two args,
	 * they are name and fg color (ignore mask). If three args, they are
	 * name, fg, bg. Some of the code below is stolen from the
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322







-
+















-
+







	    }
	}
	dispPtr = ((TkWindow *) tkwin)->dispPtr;
	if (dispPtr->cursorFont == None) {
	    dispPtr->cursorFont = XLoadFont(display, CURSORFONT);
	    if (dispPtr->cursorFont == None) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"couldn't load cursor font", TCL_INDEX_NONE));
			"couldn't load cursor font", -1));
		Tcl_SetErrorCode(interp, "TK", "CURSOR", "FONT", NULL);
		goto cleanup;
	    }
	}
	cursor = XCreateGlyphCursor(display, dispPtr->cursorFont,
		dispPtr->cursorFont, namePtr->shape, maskIndex,
		&fg, &bg);
    } else {
	/*
	 * Prevent file system access in safe interpreters.
	 */

	if (!inTkTable && Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't get cursor from a file in a safe interpreter",
		    TCL_INDEX_NONE));
		    -1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "CURSOR_FILE", NULL);
	    cursorPtr = NULL;
	    goto cleanup;
	}

	/*
	 * If the cursor is to be created from bitmap files, then there should
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







	}

	cursor = CreateCursorFromTableOrFile(interp, tkwin, argc, argv,
		tkCursorPtr);
    }

    if (cursor != None) {
	cursorPtr = (TkUnixCursor *)ckalloc(sizeof(TkUnixCursor));
	cursorPtr = ckalloc(sizeof(TkUnixCursor));
	cursorPtr->info.cursor = (Tk_Cursor) cursor;
	cursorPtr->display = display;
    }

  cleanup:
    if (argv != NULL) {
	ckfree(argv);
377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391







-
+







 *----------------------------------------------------------------------
 */

static Cursor
CreateCursorFromTableOrFile(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    Tcl_Size argc,
    int argc,
    const char **argv,		/* Cursor spec parsed into elements. */
    const struct TkCursorName *tkCursorPtr)
				/* Non-NULL when cursor is defined in Tk
				 * table. */
{
    Cursor cursor = None;

428
429
430
431
432
433
434
435

436
437
438
439
440
441
442
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442







-
+







	if (data == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading bitmap data for \"%s\"", argv[0]));
	    Tcl_SetErrorCode(interp, "TK", "CURSOR", "BITMAP_DATA", NULL);
	    goto cleanup;
	}

	source = XCreateBitmapFromData(display, drawable, data, (unsigned)width, (unsigned)height);
	source = XCreateBitmapFromData(display, drawable, data, width,height);
	ckfree(data);
    } else {
	if (TkReadBitmapFile(display, drawable, &argv[0][1],
		(unsigned *) &width, (unsigned *) &height,
		&source, &xHot, &yHot) != BitmapSuccess) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "cleanup reading bitmap file \"%s\"", &argv[0][1]));
526
527
528
529
530
531
532
533
534


535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550

551
552
553
554
555
556
557
526
527
528
529
530
531
532


533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557







-
-
+
+















-
+







	if (data == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading bitmap mask data for \"%s\"", argv[0]));
	    Tcl_SetErrorCode(interp, "TK", "CURSOR", "MASK_DATA", NULL);
	    goto cleanup;
	}

	mask = XCreateBitmapFromData(display, drawable, data, (unsigned)maskWidth,
		(unsigned)maskHeight);
	mask = XCreateBitmapFromData(display, drawable, data, maskWidth,
		maskHeight);

	ckfree(data);
    } else {
	if (TkReadBitmapFile(display, drawable, argv[1],
		(unsigned int *) &maskWidth, (unsigned int *) &maskHeight,
		&mask, &dummy1, &dummy2) != BitmapSuccess) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "cleanup reading bitmap file \"%s\"", argv[1]));
	    Tcl_SetErrorCode(interp, "TK", "CURSOR", "MASK_FILE", NULL);
	    goto cleanup;
	}
    }

    if ((maskWidth != width) || (maskHeight != height)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"source and mask bitmaps have different sizes", TCL_INDEX_NONE));
		"source and mask bitmaps have different sizes", -1));
	Tcl_SetErrorCode(interp, "TK", "CURSOR", "SIZE_MATCH", NULL);
	goto cleanup;
    }

    cursor = XCreatePixmapCursor(display, source, mask,
	    &fg, &bg, (unsigned) xHot, (unsigned) yHot);

604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618







-
+







	    (unsigned) height);
    cursor = XCreatePixmapCursor(display, sourcePixmap,
	    maskPixmap, &fgColor, &bgColor, (unsigned) xHot, (unsigned) yHot);
    Tk_FreePixmap(display, sourcePixmap);
    Tk_FreePixmap(display, maskPixmap);

    if (cursor != None) {
	cursorPtr = (TkUnixCursor *)ckalloc(sizeof(TkUnixCursor));
	cursorPtr = ckalloc(sizeof(TkUnixCursor));
	cursorPtr->info.cursor = (Tk_Cursor) cursor;
	cursorPtr->display = display;
    }
    return (TkCursor *) cursorPtr;
}

/*

Changes to unix/tkUnixDefault.h.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
43
44
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33

34
35
36

37
38
39
40
41
42
43







-









-
+
+

-







 * The definitions below provide symbolic names for the default colors.
 * NORMAL_BG -		Normal background color.
 * ACTIVE_BG -		Background color when widget is active.
 * SELECT_BG -		Background color for selected text.
 * TROUGH -		Background color for troughs in scales and scrollbars.
 * INDICATOR -		Color for indicator when button is selected.
 * DISABLED -		Foreground color when widget is disabled.
 * PLACEHOLDER_FG -	Foreground color for placeholder text.
 */

#define BLACK		"#000000"
#define WHITE		"#ffffff"

#define NORMAL_BG	"#d9d9d9"
#define ACTIVE_BG	"#ececec"
#define SELECT_BG	"#c3c3c3"
#define TROUGH		"#b3b3b3"
#define INDICATOR	WHITE
#define CHECK_INDICATOR	WHITE
#define MENU_INDICATOR  BLACK
#define DISABLED	"#a3a3a3"
#define PLACEHOLDER_FG	"#b3b3b3"	/* grey70 */

/*
 * Defaults for labels, buttons, checkbuttons, and radiobuttons:
 */

#define DEF_BUTTON_ANCHOR		"center"
#define DEF_BUTTON_ACTIVE_BG_COLOR	ACTIVE_BG
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86

87
88
89

90
91

92
93
94
95
96
97
98
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83

84
85
86

87
88
89
90
91
92
93
94
95
96
97







-









-
+














-
+

-
+


-
+


+







#define DEF_BUTTON_BORDER_WIDTH		"1"
#define DEF_BUTTON_CURSOR		""
#define DEF_BUTTON_COMPOUND		"none"
#define DEF_BUTTON_COMMAND		""
#define DEF_BUTTON_DEFAULT		"disabled"
#define DEF_BUTTON_DISABLED_FG_COLOR	DISABLED
#define DEF_BUTTON_DISABLED_FG_MONO	""
#define DEF_LABEL_FG			BLACK
#define DEF_BUTTON_FG			BLACK
#define DEF_CHKRAD_FG			DEF_BUTTON_FG
#define DEF_BUTTON_FONT			"TkDefaultFont"
#define DEF_BUTTON_HEIGHT		"0"
#define DEF_BUTTON_HIGHLIGHT_BG_COLOR	DEF_BUTTON_BG_COLOR
#define DEF_BUTTON_HIGHLIGHT_BG_MONO	DEF_BUTTON_BG_MONO
#define DEF_BUTTON_HIGHLIGHT		BLACK
#define DEF_LABEL_HIGHLIGHT_WIDTH	"0"
#define DEF_BUTTON_HIGHLIGHT_WIDTH	"1"
#define DEF_BUTTON_IMAGE		NULL
#define DEF_BUTTON_IMAGE		((char *) NULL)
#define DEF_BUTTON_INDICATOR		"1"
#define DEF_BUTTON_JUSTIFY		"center"
#define DEF_BUTTON_OFF_VALUE		"0"
#define DEF_BUTTON_ON_VALUE		"1"
#define DEF_BUTTON_TRISTATE_VALUE	""
#define DEF_BUTTON_OVER_RELIEF		""
#define DEF_BUTTON_PADX			"3m"
#define DEF_LABCHKRAD_PADX		"1"
#define DEF_BUTTON_PADY			"1m"
#define DEF_LABCHKRAD_PADY		"1"
#define DEF_BUTTON_RELIEF		"raised"
#define DEF_LABCHKRAD_RELIEF		"flat"
#define DEF_BUTTON_REPEAT_DELAY		"0"
#define DEF_BUTTON_REPEAT_INTERVAL	"0"
#define DEF_BUTTON_SELECT_COLOR		INDICATOR
#define DEF_BUTTON_SELECT_COLOR		CHECK_INDICATOR
#define DEF_BUTTON_SELECT_MONO		BLACK
#define DEF_BUTTON_SELECT_IMAGE		NULL
#define DEF_BUTTON_SELECT_IMAGE		((char *) NULL)
#define DEF_BUTTON_STATE		"normal"
#define DEF_LABEL_TAKE_FOCUS		"0"
#define DEF_BUTTON_TAKE_FOCUS		NULL
#define DEF_BUTTON_TAKE_FOCUS		((char *) NULL)
#define DEF_BUTTON_TEXT			""
#define DEF_BUTTON_TEXT_VARIABLE	""
#define DEF_BUTTON_UNDERLINE		"-1"
#define DEF_BUTTON_VALUE		""
#define DEF_BUTTON_WIDTH		"0"
#define DEF_BUTTON_WRAP_LENGTH		"0"
#define DEF_RADIOBUTTON_VARIABLE	"selectedButton"
#define DEF_CHECKBUTTON_VARIABLE	""

/*
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+







#define DEF_CANVAS_SCROLL_REGION	""
#define DEF_CANVAS_SELECT_COLOR		SELECT_BG
#define DEF_CANVAS_SELECT_MONO		BLACK
#define DEF_CANVAS_SELECT_BD_COLOR	"1"
#define DEF_CANVAS_SELECT_BD_MONO	"0"
#define DEF_CANVAS_SELECT_FG_COLOR	BLACK
#define DEF_CANVAS_SELECT_FG_MONO	WHITE
#define DEF_CANVAS_TAKE_FOCUS		NULL
#define DEF_CANVAS_TAKE_FOCUS		((char *) NULL)
#define DEF_CANVAS_WIDTH		"10c"
#define DEF_CANVAS_X_SCROLL_CMD		""
#define DEF_CANVAS_X_SCROLL_INCREMENT	"0"
#define DEF_CANVAS_Y_SCROLL_CMD		""
#define DEF_CANVAS_Y_SCROLL_INCREMENT	"0"

/*
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
149
150
151
152
153
154
155


156
157
158
159
160
161
162
163
164
165

166
167

168
169
170
171
172
173
174
175
176

177

178
179
180
181
182
183
184







-
-










-
+

-
+








-

-







#define DEF_ENTRY_INSERT_BG		BLACK
#define DEF_ENTRY_INSERT_BD_COLOR	"0"
#define DEF_ENTRY_INSERT_BD_MONO	"0"
#define DEF_ENTRY_INSERT_OFF_TIME	"300"
#define DEF_ENTRY_INSERT_ON_TIME	"600"
#define DEF_ENTRY_INSERT_WIDTH		"2"
#define DEF_ENTRY_JUSTIFY		"left"
#define DEF_ENTRY_PLACEHOLDER		""
#define DEF_ENTRY_PLACEHOLDERFG		PLACEHOLDER_FG
#define DEF_ENTRY_READONLY_BG_COLOR	NORMAL_BG
#define DEF_ENTRY_READONLY_BG_MONO	WHITE
#define DEF_ENTRY_RELIEF		"sunken"
#define DEF_ENTRY_SCROLL_COMMAND	""
#define DEF_ENTRY_SELECT_COLOR		SELECT_BG
#define DEF_ENTRY_SELECT_MONO		BLACK
#define DEF_ENTRY_SELECT_BD_COLOR	"0"
#define DEF_ENTRY_SELECT_BD_MONO	"0"
#define DEF_ENTRY_SELECT_FG_COLOR	BLACK
#define DEF_ENTRY_SELECT_FG_MONO	WHITE
#define DEF_ENTRY_SHOW			NULL
#define DEF_ENTRY_SHOW			((char *) NULL)
#define DEF_ENTRY_STATE			"normal"
#define DEF_ENTRY_TAKE_FOCUS		NULL
#define DEF_ENTRY_TAKE_FOCUS		((char *) NULL)
#define DEF_ENTRY_TEXT_VARIABLE		""
#define DEF_ENTRY_WIDTH			"20"

/*
 * Defaults for frames:
 */

#define DEF_FRAME_BG_COLOR		NORMAL_BG
#define DEF_FRAME_BG_IMAGE		NULL
#define DEF_FRAME_BG_MONO		WHITE
#define DEF_FRAME_BG_TILE		"0"
#define DEF_FRAME_BORDER_WIDTH		"0"
#define DEF_FRAME_CLASS			"Frame"
#define DEF_FRAME_COLORMAP		""
#define DEF_FRAME_CONTAINER		"0"
#define DEF_FRAME_CURSOR		""
#define DEF_FRAME_HEIGHT		"0"
#define DEF_FRAME_HIGHLIGHT_BG		NORMAL_BG
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252





253
254

255
256
257


258
259

260
261
262


263
264
265

266
267
268


269
270


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296


297
298
299
300
301
302
303
229
230
231
232
233
234
235

236
237
238
239
240
241
242





243
244
245
246
247
248

249
250


251
252
253

254
255


256
257
258
259

260
261


262
263
264

265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286

287
288
289


290
291
292
293
294
295
296
297
298







-
+






-
-
-
-
-
+
+
+
+
+

-
+

-
-
+
+

-
+

-
-
+
+


-
+

-
-
+
+

-
+
+










-










-
+


-
-
+
+







#define DEF_LISTBOX_SELECT_MONO		BLACK
#define DEF_LISTBOX_SELECT_BD		"0"
#define DEF_LISTBOX_SELECT_FG_COLOR	BLACK
#define DEF_LISTBOX_SELECT_FG_MONO	WHITE
#define DEF_LISTBOX_SELECT_MODE		"browse"
#define DEF_LISTBOX_SET_GRID		"0"
#define DEF_LISTBOX_STATE		"normal"
#define DEF_LISTBOX_TAKE_FOCUS		NULL
#define DEF_LISTBOX_TAKE_FOCUS		((char *) NULL)
#define DEF_LISTBOX_WIDTH		"20"

/*
 * Defaults for individual entries of menus:
 */

#define DEF_MENU_ENTRY_ACTIVE_BG	NULL
#define DEF_MENU_ENTRY_ACTIVE_FG	NULL
#define DEF_MENU_ENTRY_ACCELERATOR	NULL
#define DEF_MENU_ENTRY_BG		NULL
#define DEF_MENU_ENTRY_BITMAP		NULL
#define DEF_MENU_ENTRY_ACTIVE_BG	((char *) NULL)
#define DEF_MENU_ENTRY_ACTIVE_FG	((char *) NULL)
#define DEF_MENU_ENTRY_ACCELERATOR	((char *) NULL)
#define DEF_MENU_ENTRY_BG		((char *) NULL)
#define DEF_MENU_ENTRY_BITMAP		None
#define DEF_MENU_ENTRY_COLUMN_BREAK	"0"
#define DEF_MENU_ENTRY_COMMAND		NULL
#define DEF_MENU_ENTRY_COMMAND		((char *) NULL)
#define DEF_MENU_ENTRY_COMPOUND 	"none"
#define DEF_MENU_ENTRY_FG		NULL
#define DEF_MENU_ENTRY_FONT		NULL
#define DEF_MENU_ENTRY_FG		((char *) NULL)
#define DEF_MENU_ENTRY_FONT		((char *) NULL)
#define DEF_MENU_ENTRY_HIDE_MARGIN	"0"
#define DEF_MENU_ENTRY_IMAGE		NULL
#define DEF_MENU_ENTRY_IMAGE		((char *) NULL)
#define DEF_MENU_ENTRY_INDICATOR	"1"
#define DEF_MENU_ENTRY_LABEL		NULL
#define DEF_MENU_ENTRY_MENU		NULL
#define DEF_MENU_ENTRY_LABEL		((char *) NULL)
#define DEF_MENU_ENTRY_MENU		((char *) NULL)
#define DEF_MENU_ENTRY_OFF_VALUE	"0"
#define DEF_MENU_ENTRY_ON_VALUE		"1"
#define DEF_MENU_ENTRY_SELECT_IMAGE	NULL
#define DEF_MENU_ENTRY_SELECT_IMAGE	((char *) NULL)
#define DEF_MENU_ENTRY_STATE		"normal"
#define DEF_MENU_ENTRY_VALUE		NULL
#define DEF_MENU_ENTRY_CHECK_VARIABLE	NULL
#define DEF_MENU_ENTRY_VALUE		((char *) NULL)
#define DEF_MENU_ENTRY_CHECK_VARIABLE	((char *) NULL)
#define DEF_MENU_ENTRY_RADIO_VARIABLE	"selectedButton"
#define DEF_MENU_ENTRY_SELECT		NULL
#define DEF_MENU_ENTRY_SELECT		((char *) NULL)
#define DEF_MENU_ENTRY_UNDERLINE	"-1"

/*
 * Defaults for menus overall:
 */

#define DEF_MENU_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_MENU_ACTIVE_BG_MONO		BLACK
#define DEF_MENU_ACTIVE_BORDER_WIDTH	"1"
#define DEF_MENU_ACTIVE_FG_COLOR	BLACK
#define DEF_MENU_ACTIVE_FG_MONO		WHITE
#define DEF_MENU_ACTIVE_RELIEF		"raised"
#define DEF_MENU_BG_COLOR		NORMAL_BG
#define DEF_MENU_BG_MONO		WHITE
#define DEF_MENU_BORDER_WIDTH		"1"
#define DEF_MENU_CURSOR			"arrow"
#define DEF_MENU_DISABLED_FG_COLOR	DISABLED
#define DEF_MENU_DISABLED_FG_MONO	""
#define DEF_MENU_FONT			"TkMenuFont"
#define DEF_MENU_FG			BLACK
#define DEF_MENU_POST_COMMAND		""
#define DEF_MENU_RELIEF			"raised"
#define DEF_MENU_SELECT_COLOR		BLACK
#define DEF_MENU_SELECT_COLOR		MENU_INDICATOR
#define DEF_MENU_SELECT_MONO		BLACK
#define DEF_MENU_TAKE_FOCUS		"0"
#define DEF_MENU_TEAROFF		"0"
#define DEF_MENU_TEAROFF_CMD		NULL
#define DEF_MENU_TEAROFF		"1"
#define DEF_MENU_TEAROFF_CMD		((char *) NULL)
#define DEF_MENU_TITLE			""
#define DEF_MENU_TYPE			"normal"

/*
 * Defaults for menubuttons:
 */

317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355


356
357
358
359
360
361
362
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349


350
351
352
353
354
355
356
357
358







-
+










+



















-
-
+
+







#define DEF_MENUBUTTON_FONT		"TkDefaultFont"
#define DEF_MENUBUTTON_FG		BLACK
#define DEF_MENUBUTTON_HEIGHT		"0"
#define DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR DEF_MENUBUTTON_BG_COLOR
#define DEF_MENUBUTTON_HIGHLIGHT_BG_MONO  DEF_MENUBUTTON_BG_MONO
#define DEF_MENUBUTTON_HIGHLIGHT	BLACK
#define DEF_MENUBUTTON_HIGHLIGHT_WIDTH	"0"
#define DEF_MENUBUTTON_IMAGE		NULL
#define DEF_MENUBUTTON_IMAGE		((char *) NULL)
#define DEF_MENUBUTTON_INDICATOR	"0"
#define DEF_MENUBUTTON_JUSTIFY		"center"
#define DEF_MENUBUTTON_MENU		""
#define DEF_MENUBUTTON_PADX		"4p"
#define DEF_MENUBUTTON_PADY		"3p"
#define DEF_MENUBUTTON_RELIEF		"flat"
#define DEF_MENUBUTTON_STATE		"normal"
#define DEF_MENUBUTTON_TAKE_FOCUS	"0"
#define DEF_MENUBUTTON_TEXT		""
#define DEF_MENUBUTTON_TEXT_VARIABLE	""
#define DEF_MENUBUTTON_UNDERLINE	"-1"
#define DEF_MENUBUTTON_WIDTH		"0"
#define DEF_MENUBUTTON_WRAP_LENGTH	"0"

/*
 * Defaults for messages:
 */

#define DEF_MESSAGE_ANCHOR		"center"
#define DEF_MESSAGE_ASPECT		"150"
#define DEF_MESSAGE_BG_COLOR		NORMAL_BG
#define DEF_MESSAGE_BG_MONO		WHITE
#define DEF_MESSAGE_BORDER_WIDTH	"1"
#define DEF_MESSAGE_CURSOR		""
#define DEF_MESSAGE_FG			BLACK
#define DEF_MESSAGE_FONT		"TkDefaultFont"
#define DEF_MESSAGE_HIGHLIGHT_BG	NORMAL_BG
#define DEF_MESSAGE_HIGHLIGHT		BLACK
#define DEF_MESSAGE_HIGHLIGHT_WIDTH	"0"
#define DEF_MESSAGE_JUSTIFY		"left"
#define DEF_MESSAGE_PADX		NULL
#define DEF_MESSAGE_PADY		NULL
#define DEF_MESSAGE_PADX		"-1"
#define DEF_MESSAGE_PADY		"-1"
#define DEF_MESSAGE_RELIEF		"flat"
#define DEF_MESSAGE_TAKE_FOCUS		"0"
#define DEF_MESSAGE_TEXT		""
#define DEF_MESSAGE_TEXT_VARIABLE	""
#define DEF_MESSAGE_WIDTH		"0"

/*
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
434
435



436
437
438
439
440
441
442
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428



429
430
431
432
433
434
435
436
437
438







-
+







-
+










-
+






-
-
-
+
+
+







 * Defaults for scales:
 */

#define DEF_SCALE_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_SCALE_ACTIVE_BG_MONO	BLACK
#define DEF_SCALE_BG_COLOR		NORMAL_BG
#define DEF_SCALE_BG_MONO		WHITE
#define DEF_SCALE_BIG_INCREMENT		"0.0"
#define DEF_SCALE_BIG_INCREMENT		"0"
#define DEF_SCALE_BORDER_WIDTH		"1"
#define DEF_SCALE_COMMAND		""
#define DEF_SCALE_CURSOR		""
#define DEF_SCALE_DIGITS		"0"
#define DEF_SCALE_FONT			"TkDefaultFont"
#define DEF_SCALE_FG_COLOR		BLACK
#define DEF_SCALE_FG_MONO		BLACK
#define DEF_SCALE_FROM			"0.0"
#define DEF_SCALE_FROM			"0"
#define DEF_SCALE_HIGHLIGHT_BG_COLOR	DEF_SCALE_BG_COLOR
#define DEF_SCALE_HIGHLIGHT_BG_MONO	DEF_SCALE_BG_MONO
#define DEF_SCALE_HIGHLIGHT		BLACK
#define DEF_SCALE_HIGHLIGHT_WIDTH	"1"
#define DEF_SCALE_LABEL			""
#define DEF_SCALE_LENGTH		"100"
#define DEF_SCALE_ORIENT		"vertical"
#define DEF_SCALE_RELIEF		"flat"
#define DEF_SCALE_REPEAT_DELAY		"300"
#define DEF_SCALE_REPEAT_INTERVAL	"100"
#define DEF_SCALE_RESOLUTION		"1.0"
#define DEF_SCALE_RESOLUTION		"1"
#define DEF_SCALE_TROUGH_COLOR		TROUGH
#define DEF_SCALE_TROUGH_MONO		WHITE
#define DEF_SCALE_SHOW_VALUE		"1"
#define DEF_SCALE_SLIDER_LENGTH		"30"
#define DEF_SCALE_SLIDER_RELIEF		"raised"
#define DEF_SCALE_STATE			"normal"
#define DEF_SCALE_TAKE_FOCUS		NULL
#define DEF_SCALE_TICK_INTERVAL		"0.0"
#define DEF_SCALE_TO			"100.0"
#define DEF_SCALE_TAKE_FOCUS		((char *) NULL)
#define DEF_SCALE_TICK_INTERVAL		"0"
#define DEF_SCALE_TO			"100"
#define DEF_SCALE_VARIABLE		""
#define DEF_SCALE_WIDTH			"15"

/*
 * Defaults for scrollbars:
 */

453
454
455
456
457
458
459
460

461
462
463
464
465
466
467
449
450
451
452
453
454
455

456
457
458
459
460
461
462
463







-
+







#define DEF_SCROLLBAR_HIGHLIGHT		BLACK
#define DEF_SCROLLBAR_HIGHLIGHT_WIDTH	"0"
#define DEF_SCROLLBAR_JUMP		"0"
#define DEF_SCROLLBAR_ORIENT		"vertical"
#define DEF_SCROLLBAR_RELIEF		"sunken"
#define DEF_SCROLLBAR_REPEAT_DELAY	"300"
#define DEF_SCROLLBAR_REPEAT_INTERVAL	"100"
#define DEF_SCROLLBAR_TAKE_FOCUS	NULL
#define DEF_SCROLLBAR_TAKE_FOCUS	((char *) NULL)
#define DEF_SCROLLBAR_TROUGH_COLOR	TROUGH
#define DEF_SCROLLBAR_TROUGH_MONO	WHITE
#define DEF_SCROLLBAR_WIDTH		"11"

/*
 * Defaults for texts:
 */
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511
512
513
514
515
516








517
518
519
520
521
522
523







-
+












-
-
-
-
-
-
-
-







#define DEF_TEXT_SET_GRID		"0"
#define DEF_TEXT_SPACING1		"0"
#define DEF_TEXT_SPACING2		"0"
#define DEF_TEXT_SPACING3		"0"
#define DEF_TEXT_STATE			"normal"
#define DEF_TEXT_TABS			""
#define DEF_TEXT_TABSTYLE		"tabular"
#define DEF_TEXT_TAKE_FOCUS		NULL
#define DEF_TEXT_TAKE_FOCUS		((char *) NULL)
#define DEF_TEXT_UNDO			"0"
#define DEF_TEXT_WIDTH			"80"
#define DEF_TEXT_WRAP			"char"
#define DEF_TEXT_XSCROLL_COMMAND	""
#define DEF_TEXT_YSCROLL_COMMAND	""

/*
 * Defaults for canvas text:
 */

#define DEF_CANVTEXT_FONT		"TkDefaultFont"

/*
 * Defaults for canvas items
 * (arcs, bitmaps, lines, polygons, rectangles, and ovals):
 */

#define DEF_CANVBMAP_FG			BLACK
#define DEF_CANVITEM_OUTLINE		BLACK

/*
 * Defaults for toplevels (most of the defaults for frames also apply
 * to toplevels):
 */

#define DEF_TOPLEVEL_CLASS		"Toplevel"
#define DEF_TOPLEVEL_MENU		""

Added unix/tkUnixDialog.c.


































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * tkUnixDialog.c --
 *
 *	Contains the Unix implementation of the common dialog boxes:
 *
 * Copyright (c) 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.
 */

#include "tkUnixInt.h"

/*
 * The wrapper code for Unix is actually set up in library/tk.tcl these days;
 * the procedure names used here are probably wrong too...
 */

#ifdef TK_OBSOLETE_UNIX_DIALOG_WRAPPERS

/*
 *----------------------------------------------------------------------
 *
 * EvalObjv --
 *
 *	Invokes the Tcl procedure with the arguments.
 *
 * Results:
 *	Returns the result of the evaluation of the command.
 *
 * Side effects:
 *	The command may be autoloaded.
 *
 *----------------------------------------------------------------------
 */

static int
EvalObjv(
    Tcl_Interp *interp,		/* Current interpreter. */
    char *cmdName,		/* Name of the TCL command to call */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const *objv)	/* Arguments. */
{
    Tcl_Obj *cmdObj, **objs;
    int result;

    cmdObj = Tcl_NewStringObj(cmdName, -1);
    Tcl_IncrRefCount(cmdObj);
    objs = ckalloc(sizeof(Tcl_Obj *) * (objc+1));
    objs[0] = cmdObj;
    memcpy(objs+1, objv, sizeof(Tcl_Obj *) * (unsigned)objc);

    result = Tcl_EvalObjv(interp, objc+1, objs, 0);

    Tcl_DecrRefCount(cmdObj);
    ckfree(objs);

    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_ChooseColorObjCmd --
 *
 *	This procedure implements the color dialog box for the Unix platform.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	See user documentation.
 *
 * Side effects:
 *	A dialog window is created the first time this procedure is called.
 *	This window is not destroyed and will be reused the next time the
 *	application invokes the "tk_chooseColor" command.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ChooseColorObjCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const *objv)	/* Arguments. */
{
    return EvalObjv(interp, "tk::ColorDialog", objc-1, objv+1);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOpenFileCmd --
 *
 *	This procedure implements the "open file" dialog box for the Unix
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	See user documentation.
 *
 * Side effects:
 *	A dialog window is created the first this procedure is called. This
 *	window is not destroyed and will be reused the next time the
 *	application invokes the "tk_getOpenFile" or "tk_getSaveFile" command.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetOpenFileObjCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const *objv)	/* Arguments. */
{
    Tk_Window tkwin = clientData;

    if (Tk_StrictMotif(tkwin)) {
	return EvalObjv(interp, "tk::MotifOpenFDialog", objc-1, objv+1);
    } else {
	return EvalObjv(interp, "tk::OpenFDialog", objc-1, objv+1);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSaveFileCmd --
 *
 *	Same as Tk_GetOpenFileCmd but opens a "save file" dialog box instead.
 *
 * Results:
 *	Same as Tk_GetOpenFileCmd.
 *
 * Side effects:
 *	Same as Tk_GetOpenFileCmd.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetSaveFileObjCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const *objv)	/* Arguments. */
{
    Tk_Window tkwin = clientData;

    if (Tk_StrictMotif(tkwin)) {
	return EvalObjv(interp, "tk::MotifSaveFDialog", objc-1, objv+1);
    } else {
	return EvalObjv(interp, "tk::SaveFDialog", objc-1, objv+1);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MessageBoxCmd --
 *
 *	This procedure implements the MessageBox window for the Unix
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	See user documentation.
 *
 * Side effects:
 *	None. The MessageBox window will be destroy before this procedure
 *	returns.
 *
 *----------------------------------------------------------------------
 */

int
Tk_MessageBoxCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const *objv)	/* Arguments. */
{
    return EvalObjv(interp, "tk::MessageBox", objc-1, objv+1);
}

#endif /* TK_OBSOLETE_UNIX_DIALOG_WRAPPERS */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixDraw.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34





-
+




















-
+







/*
 * tkUnixDraw.c --
 *
 *	This file contains X specific drawing routines.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#ifndef _WIN32
#include "tkUnixInt.h"
#endif

/*
 * The following structure is used to pass information to ScrollRestrictProc
 * from TkScrollWindow.
 */

typedef struct ScrollInfo {
    int done;			/* Flag is 0 until filtering is done. */
    Display *display;		/* Display to filter. */
    Window window;		/* Window to filter. */
    Region region;		/* Region into which damage is accumulated. */
    TkRegion region;		/* Region into which damage is accumulated. */
    int dx, dy;			/* Amount by which window was shifted. */
} ScrollInfo;

/*
 * Forward declarations for functions declared later in this file:
 */

57
58
59
60
61
62
63
64

65
66
67

68
69
70
71
72
73
74
57
58
59
60
61
62
63

64
65
66

67
68
69
70
71
72
73
74







-
+


-
+







int
TkScrollWindow(
    Tk_Window tkwin,		/* The window to be scrolled. */
    GC gc,			/* GC for window to be scrolled. */
    int x, int y, int width, int height,
				/* Position rectangle to be scrolled. */
    int dx, int dy,		/* Distance rectangle should be moved. */
    Region damageRgn)		/* Region to accumulate damage in. */
    TkRegion damageRgn)		/* Region to accumulate damage in. */
{
    Tk_RestrictProc *prevProc;
    void *prevArg;
    ClientData prevArg;
    ScrollInfo info;

    XCopyArea(Tk_Display(tkwin), Tk_WindowId(tkwin), Tk_WindowId(tkwin), gc,
	    x, y, (unsigned) width, (unsigned) height, x+dx, y+dy);

    info.done = 0;
    info.window = Tk_WindowId(tkwin);
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100







-
+







    TkpSync(info.display);
    prevProc = Tk_RestrictEvents(ScrollRestrictProc, &info, &prevArg);
    while (!info.done) {
	Tcl_ServiceEvent(TCL_WINDOW_EVENTS);
    }
    Tk_RestrictEvents(prevProc, prevArg, &prevArg);

    if (XEmptyRegion(damageRgn)) {
    if (XEmptyRegion((Region) damageRgn)) {
	return 0;
    } else {
	return 1;
    }
}

/*
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
115
116
117
118
119
120
121

122
123
124
125
126
127
128
129







-
+







 *	for a particular window.
 *
 *----------------------------------------------------------------------
 */

static Tk_RestrictAction
ScrollRestrictProc(
    void *arg,
    ClientData arg,
    XEvent *eventPtr)
{
    ScrollInfo *info = (ScrollInfo *) arg;
    XRectangle rect;

    /*
     * Defer events which aren't for the specified window.
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164


165
166
167
168


169
170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
137
138
139
140
141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162


163
164
165
166


167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204


205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224

225
226

227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243







-
-
+
+

















-
-
+
+


-
-
+
+









-
+



















-
+






-
-






-
+













-
+

-





-
+











    if (eventPtr->type == NoExpose) {
	info->done = 1;
    } else if (eventPtr->type == GraphicsExpose) {
	rect.x = eventPtr->xgraphicsexpose.x;
	rect.y = eventPtr->xgraphicsexpose.y;
	rect.width = eventPtr->xgraphicsexpose.width;
	rect.height = eventPtr->xgraphicsexpose.height;
	XUnionRectWithRegion(&rect, info->region,
		info->region);
	XUnionRectWithRegion(&rect, (Region) info->region,
		(Region) info->region);

	if (eventPtr->xgraphicsexpose.count == 0) {
	    info->done = 1;
	}
    } else if (eventPtr->type == Expose) {
	/*
	 * This case is tricky. This event was already queued before the
	 * XCopyArea was issued. If this area overlaps the area being copied,
	 * then some of the copied area may be invalid. The easiest way to
	 * handle this case is to mark both the original area and the shifted
	 * area as damaged.
	 */

	rect.x = eventPtr->xexpose.x;
	rect.y = eventPtr->xexpose.y;
	rect.width = eventPtr->xexpose.width;
	rect.height = eventPtr->xexpose.height;
	XUnionRectWithRegion(&rect, info->region,
		info->region);
	XUnionRectWithRegion(&rect, (Region) info->region,
		(Region) info->region);
	rect.x += info->dx;
	rect.y += info->dy;
	XUnionRectWithRegion(&rect, info->region,
		info->region);
	XUnionRectWithRegion(&rect, (Region) info->region,
		(Region) info->region);
    } else {
	return TK_DEFER_EVENT;
    }
    return TK_DISCARD_EVENT;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DrawHighlightBorder --
 * TkpDrawHighlightBorder --
 *
 *	This function draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus.
 *
 *      On Unix, we just draw the simple inset ring. On other sytems, e.g. the
 *      Mac, the focus ring is a little more complicated, so we need this
 *      abstraction.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
 *	to the outer area of "tkwin".
 *
 *----------------------------------------------------------------------
 */

void
Tk_DrawHighlightBorder(
TkpDrawHighlightBorder(
    Tk_Window tkwin,
    GC fgGC,
    GC bgGC,
    int highlightWidth,
    Drawable drawable)
{
    (void)bgGC;

    TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDrawFrameEx --
 * TkpDrawFrame --
 *
 *	This function draws the rectangular frame area.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws inside the tkwin area.
 *
 *----------------------------------------------------------------------
 */

void
TkpDrawFrameEx(
TkpDrawFrame(
    Tk_Window tkwin,
    Drawable drawable,
    Tk_3DBorder border,
    int highlightWidth,
    int borderWidth,
    int relief)
{
    Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth,
    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, highlightWidth,
	    highlightWidth, Tk_Width(tkwin) - 2*highlightWidth,
	    Tk_Height(tkwin) - 2*highlightWidth, borderWidth, relief);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixEmbed.c.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 * tkUnixEmbed.c --
 *
 *	This file contains platform-specific functions for UNIX to provide
 *	basic operations needed for application embedding (where one
 *	application can use as its main window an internal window from some
 *	other application). Also includes code to support busy windows.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-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.
 */

#include "tkUnixInt.h"
#include "tkBusy.h"
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56

57
58

59
60

61
62

63
64
65
66
67

68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113
114

115
116
117
118
119
120
121
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55

56
57

58
59

60
61

62
63
64
65
66

67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113

114
115
116
117
118
119
120
121







-
+










-
+

-
+

-
+

-
+




-
+






-
+



















-
+














-
+




-
+







				 * in this process. Note that this is *not*
				 * the same window as wrapper: wrapper is the
				 * parent of embeddedPtr. */
    struct Container *nextPtr;	/* Next in list of all containers in this
				 * process. */
} Container;

typedef struct {
typedef struct ThreadSpecificData {
    Container *firstContainerPtr;
				/* First in list of all containers managed by
				 * this process. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Prototypes for static functions defined in this file:
 */

static void		ContainerEventProc(void *clientData,
static void		ContainerEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EmbeddedEventProc(void *clientData,
static void		EmbeddedEventProc(ClientData clientData,
			    XEvent *eventPtr);
static int		EmbedErrorProc(void *clientData,
static int		EmbedErrorProc(ClientData clientData,
			    XErrorEvent *errEventPtr);
static void		EmbedFocusProc(void *clientData,
static void		EmbedFocusProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EmbedGeometryRequest(Container *containerPtr,
			    int width, int height);
static void		EmbedSendConfigure(Container *containerPtr);
static void		EmbedStructureProc(void *clientData,
static void		EmbedStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EmbedWindowDeleted(TkWindow *winPtr);

/*
 *----------------------------------------------------------------------
 *
 * Tk_UseWindow --
 * TkpUseWindow --
 *
 *	This function causes a Tk window to use a given X window as its parent
 *	window, rather than the root window for the screen. It is invoked by
 *	an embedded application to specify the window in which it is embedded.
 *
 * Results:
 *	The return value is normally TCL_OK. If an error occurs (such as
 *	string not being a valid window spec), then the return value is
 *	TCL_ERROR and an error message is left in the interp's result if
 *	interp is non-NULL.
 *
 * Side effects:
 *	Changes the colormap and other visual information to match that of the
 *	parent window given by "string".
 *
 *----------------------------------------------------------------------
 */

int
Tk_UseWindow(
TkpUseWindow(
    Tcl_Interp *interp,		/* If not NULL, used for error reporting if
				 * string is bogus. */
    Tk_Window tkwin,		/* Tk window that does not yet have an
				 * associated X window. */
    const char *string)		/* String identifying an X window to use for
				 * tkwin; must be an integer value. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *usePtr;
    int anyError;
    Window parent;
    Tk_ErrorHandler handler;
    Container *containerPtr;
    XWindowAttributes parentAtts;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->window != None) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't modify container after widget is created", TCL_INDEX_NONE));
		"can't modify container after widget is created", -1));
	Tcl_SetErrorCode(interp, "TK", "EMBED", "POST_CREATE", NULL);
	return TCL_ERROR;
    }
    if (TkpScanWindowId(interp, string, &parent) != TCL_OK) {
	return TCL_ERROR;
    }

174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213


214
215
216
217
218
219
220

221
222
223
224
225
226
227
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211


212
213
214
215
216
217
218


219
220
221
222
223
224
225
226







-
+















-
+














-
-
+
+





-
-
+







	if (containerPtr->parent == parent) {
	    winPtr->flags |= TK_BOTH_HALVES;
	    containerPtr->parentPtr->flags |= TK_BOTH_HALVES;
	    break;
	}
    }
    if (containerPtr == NULL) {
	containerPtr = (Container *)ckalloc(sizeof(Container));
	containerPtr = ckalloc(sizeof(Container));
	containerPtr->parent = parent;
	containerPtr->parentRoot = parentAtts.root;
	containerPtr->parentPtr = NULL;
	containerPtr->wrapper = None;
	containerPtr->nextPtr = tsdPtr->firstContainerPtr;
	tsdPtr->firstContainerPtr = containerPtr;
    }
    containerPtr->embeddedPtr = winPtr;
    winPtr->flags |= TK_EMBEDDED;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeWindow --
 * TkpMakeWindow --
 *
 *	Create an actual window system window object based on the current
 *	attributes of the specified TkWindow.
 *
 * Results:
 *	Returns the handle to the new window, or None on failure.
 *
 * Side effects:
 *	Creates a new X window.
 *
 *----------------------------------------------------------------------
 */

Window
Tk_MakeWindow(
    Tk_Window tkwin,		/* Tk's information about the window that is
TkpMakeWindow(
    TkWindow *winPtr,		/* Tk's information about the window that is
				 * to be instantiated. */
    Window parent)		/* Window system token for the parent in which
				 * the window is to be created. */
{
    Container *containerPtr;
    TkWindow *winPtr = (TkWindow *) tkwin;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->flags & TK_EMBEDDED) {
	/*
	 * This window is embedded. Don't create the new window in the given
	 * parent; instead, create it as a child of the root window of the
	 * container's screen. The window will get reparented into a wrapper
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276

277
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273
274

275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







-
+















-
+





-
+








-
+







	    InputOutput, winPtr->visual, winPtr->dirtyAtts,
	    &winPtr->atts);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeContainer --
 * TkpMakeContainer --
 *
 *	This function is called to indicate that a particular window will be a
 *	container for an embedded application. This changes certain aspects of
 *	the window's behavior, such as whether it will receive events anymore.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MakeContainer(
TkpMakeContainer(
    Tk_Window tkwin)		/* Token for a window that is about to become
				 * a container. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Register the window as a container so that, for example, we can find
     * out later if the embedded app. is in the same process.
     */

    Tk_MakeWindowExist(tkwin);
    containerPtr = (Container *)ckalloc(sizeof(Container));
    containerPtr = ckalloc(sizeof(Container));
    containerPtr->parent = Tk_WindowId(tkwin);
    containerPtr->parentRoot = RootWindowOfScreen(Tk_Screen(tkwin));
    containerPtr->parentPtr = winPtr;
    containerPtr->wrapper = None;
    containerPtr->embeddedPtr = NULL;
    containerPtr->nextPtr = tsdPtr->firstContainerPtr;
    tsdPtr->firstContainerPtr = containerPtr;
325
326
327
328
329
330
331
332

333
334
335
336

337
338
339
340
341
342
343
344
324
325
326
327
328
329
330

331
332
333
334

335

336
337
338
339
340
341
342







-
+



-
+
-







 *	The integer pointed to by the clientData argument is set to 1.
 *
 *----------------------------------------------------------------------
 */

static int
EmbedErrorProc(
    void *clientData,	/* Points to integer to set. */
    ClientData clientData,	/* Points to integer to set. */
    XErrorEvent *errEventPtr)	/* Points to information about error (not
				 * used). */
{
    int *iPtr = (int *)clientData;
    int *iPtr = clientData;
    (void)errEventPtr;

    *iPtr = 1;
    return 0;
}

/*
 *----------------------------------------------------------------------
357
358
359
360
361
362
363
364

365
366
367

368
369
370
371
372
373
374
355
356
357
358
359
360
361

362
363
364

365
366
367
368
369
370
371
372







-
+


-
+







 *	destroyed.
 *
 *----------------------------------------------------------------------
 */

static void
EmbeddedEventProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	EmbedWindowDeleted(winPtr);
    }
}

/*
389
390
391
392
393
394
395
396

397
398
399

400
401
402

403
404
405
406
407
408
409
387
388
389
390
391
392
393

394
395
396

397
398
399

400
401
402
403
404
405
406
407







-
+


-
+


-
+







 *	geometry information gets set for the container window.
 *
 *----------------------------------------------------------------------
 */

static void
ContainerEventProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    Container *containerPtr;
    Tk_ErrorHandler errHandler;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Ignore any X protocol errors that happen in this function (almost any
     * operation could fail, for example, if the embedded application has
     * deleted its window).
     */
494
495
496
497
498
499
500
501

502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
492
493
494
495
496
497
498

499
500
501

502
503
504
505







506

507
508
509
510
511
512
513







-
+


-
+



-
-
-
-
-
-
-

-







 *	The embedded window gets resized to match the container.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedStructureProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = clientData;
    Tk_ErrorHandler errHandler;

    if (eventPtr->type == ConfigureNotify) {
        /*
         * Send a ConfigureNotify  to the embedded application.
         */

        if (containerPtr->embeddedPtr != NULL) {
            TkDoConfigureNotify(containerPtr->embeddedPtr);
        }
	if (containerPtr->wrapper != None) {

	    /*
	     * Ignore errors, since the embedded application could have
	     * deleted its window.
	     */

	    errHandler = Tk_CreateErrorHandler(eventPtr->xfocus.display, -1,
		    -1, -1, NULL, NULL);
549
550
551
552
553
554
555
556

557
558
559

560
561
562
563
564
565
566
539
540
541
542
543
544
545

546
547
548

549
550
551
552
553
554
555
556







-
+


-
+







 *	The X focus may change.
 *
 *----------------------------------------------------------------------
 */

static void
EmbedFocusProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = clientData;
    Tk_ErrorHandler errHandler;
    Display *display;

    display = Tk_Display(containerPtr->parentPtr);
    if (eventPtr->type == FocusIn) {
	/*
	 * The focus just arrived at the container. Change the X focus to move
688
689
690
691
692
693
694
695

696
697
698
699
700
701

702
703
704
705
706
707
708
709
710
711
712
713



714
715
716
717

718
719
720
721
722
723
724
725
726




727
728
729
730
731
732
733
678
679
680
681
682
683
684

685
686
687
688
689
690

691
692
693
694
695
696
697
698
699
700



701
702
703
704
705
706

707
708
709
710
711
712




713
714
715
716
717
718
719
720
721
722
723







-
+





-
+









-
-
-
+
+
+



-
+





-
-
-
-
+
+
+
+







		(unsigned) winPtr->changes.height);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOtherWindow --
 * TkpGetOtherWindow --
 *
 *	If both the container and embedded window are in the same process,
 *	this function will return either one, given the other.
 *
 * Results:
 *	If tkwin is a container, the return value is the token for the
 *	If winPtr is a container, the return value is the token for the
 *	embedded window, and vice versa. If the "other" window isn't in this
 *	process, NULL is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_GetOtherWindow(
    Tk_Window tkwin)		/* Tk's structure for a container or embedded
TkWindow *
TkpGetOtherWindow(
    TkWindow *winPtr)		/* Tk's structure for a container or embedded
				 * window. */
{
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (containerPtr = tsdPtr->firstContainerPtr;
            containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if ((Tk_Window)containerPtr->embeddedPtr == tkwin) {
	    return (Tk_Window)containerPtr->parentPtr;
	} else if ((Tk_Window)containerPtr->parentPtr == tkwin) {
	    return (Tk_Window)containerPtr->embeddedPtr;
	if (containerPtr->embeddedPtr == winPtr) {
	    return containerPtr->parentPtr;
	} else if (containerPtr->parentPtr == winPtr) {
	    return containerPtr->embeddedPtr;
	}
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760







-
+







    TkWindow *winPtr,		/* Window to which the event was originally
				 * reported. */
    XEvent *eventPtr)		/* X event to redirect (should be KeyPress or
				 * KeyRelease). */
{
    Container *containerPtr;
    Window saved;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * First, find the top-level window corresponding to winPtr.
     */

    while (1) {
828
829
830
831
832
833
834
835

836
837
838
839
840
841
842
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832







-
+







				 * window; should be embedded. */
    int force)			/* One means that the container should claim
				 * the focus if it doesn't currently have
				 * it. */
{
    XEvent event;
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!(topLevelPtr->flags & TK_EMBEDDED)) {
	return;
    }

    for (containerPtr = tsdPtr->firstContainerPtr;
870
871
872
873
874
875
876
877

878
879

880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913

914
915
916
917
918
919

920
921
922
923
924
925
926
927
928
929
930

931
932
933
934
935
936

937
938
939
940
941
942
943
944
860
861
862
863
864
865
866

867
868

869
870
871
872
873
874
875


876
877

878
879
880
881
882
883
884
885
886









887

888
889
890

891
892
893
894
895


896

897
898
899
900
901

902
903
904

905
906
907
908
909


910

911
912
913
914
915
916
917







-
+

-
+






-
-
+

-









-
-
-
-
-
-
-
-
-

-



-
+




-
-
+
-





-



-
+




-
-
+
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkpTestembedCmd(
    void *dummy,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    int all;
    Container *containerPtr;
    Tcl_DString dString;
    char buffer[50];
    Tcl_Interp *embeddedInterp = NULL, *parentInterp = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    (void)dummy;

    if ((objc > 1) && (strcmp(Tcl_GetString(objv[1]), "all") == 0)) {
	all = 1;
    } else {
	all = 0;
    }
    Tcl_DStringInit(&dString);
    for (containerPtr = tsdPtr->firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if (containerPtr->embeddedPtr != NULL) {
	    embeddedInterp = containerPtr->embeddedPtr->mainPtr->interp;
	}
	if (containerPtr->parentPtr != NULL) {
	    parentInterp = containerPtr->parentPtr->mainPtr->interp;
	}
	if (embeddedInterp != interp && parentInterp != interp) {
	    continue;
	}
	Tcl_DStringStartSublist(&dString);
	/* Parent id */
	if (containerPtr->parent == None) {
	    Tcl_DStringAppendElement(&dString, "");
	} else if (all) {
	    snprintf(buffer, sizeof(buffer), "0x%" TCL_Z_MODIFIER "x", (size_t) containerPtr->parent);
	    sprintf(buffer, "0x%x", (int) containerPtr->parent);
	    Tcl_DStringAppendElement(&dString, buffer);
	} else {
	    Tcl_DStringAppendElement(&dString, "XXX");
	}
	/* Parent pathName */
	if (containerPtr->parentPtr == NULL ||
	if (containerPtr->parentPtr == NULL) {
	    parentInterp != interp) {
	    Tcl_DStringAppendElement(&dString, "");
	} else {
	    Tcl_DStringAppendElement(&dString,
		    containerPtr->parentPtr->pathName);
	}
        /* Wrapper */
	if (containerPtr->wrapper == None) {
	    Tcl_DStringAppendElement(&dString, "");
	} else if (all) {
	    snprintf(buffer, sizeof(buffer), "0x%" TCL_Z_MODIFIER "x", (size_t) containerPtr->wrapper);
	    sprintf(buffer, "0x%x", (int) containerPtr->wrapper);
	    Tcl_DStringAppendElement(&dString, buffer);
	} else {
	    Tcl_DStringAppendElement(&dString, "XXX");
	}
	/* Embedded window pathName */
	if (containerPtr->embeddedPtr == NULL ||
	if (containerPtr->embeddedPtr == NULL) {
	    embeddedInterp != interp) {
	    Tcl_DStringAppendElement(&dString, "");
	} else {
	    Tcl_DStringAppendElement(&dString,
		    containerPtr->embeddedPtr->pathName);
	}
	Tcl_DStringEndSublist(&dString);
    }
966
967
968
969
970
971
972
973

974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
939
940
941
942
943
944
945

946
947
948
949
950
951
952
953
954
955
956
957

958
959
960
961
962
963
964







-
+











-








static void
EmbedWindowDeleted(
    TkWindow *winPtr)		/* Tk's information about window that was
				 * deleted. */
{
    Container *containerPtr, *prevPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Find the Container structure for this window work. Delete the
     * information about the embedded application and free the container's
     * record.
     */

    prevPtr = NULL;
    containerPtr = tsdPtr->firstContainerPtr;
    while (1) {
	if (containerPtr == NULL) return;
	if (containerPtr->embeddedPtr == winPtr) {
	    containerPtr->wrapper = None;
	    containerPtr->embeddedPtr = NULL;
	    break;
	}
	if (containerPtr->parentPtr == winPtr) {
	    containerPtr->parentPtr = NULL;
1025
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
997
998
999
1000
1001
1002
1003

1004
1005
1006
1007
1008
1009
1010
1011







-
+







 */

Window
TkUnixContainerId(
    TkWindow *winPtr)		/* Tk's structure for an embedded window. */
{
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (containerPtr = tsdPtr->firstContainerPtr;
            containerPtr != NULL; containerPtr = containerPtr->nextPtr) {
	if (containerPtr->embeddedPtr == winPtr) {
	    return containerPtr->parent;
	}
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162
1163







-







    Tk_Window tkRef,
    Window *parentPtr,
    Tk_Window tkParent,
    TkBusy busy)
{
    Window root, parent, *dummy;
    unsigned int count;
    (void)busy;

    if (winPtr->flags & TK_REPARENTED) {
	/*
	 * This works around a bug in the implementation of menubars for
	 * non-MacIntosh window systems (Win32 and X11). Tk doesn't reset the
	 * pointers to the parent window when the menu is reparented (since
	 * winPtr->parentPtr points to the wrong window). We get around this

Changes to unix/tkUnixEvent.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15

16
17
18




19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37




38
39
40
41
42
43
44
1
2
3
4
5
6

7
8
9
10
11
12
13
14

15



16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34




35
36
37
38
39
40
41
42
43
44
45






-
+







-
+
-
-
-
+
+
+
+






-
+








-
-
-
-
+
+
+
+







/*
 * tkUnixEvent.c --
 *
 *	This file implements an event source for X displays for the UNIX
 *	version of Tk.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkUnixInt.h"
#include <signal.h>
#undef register /* Keyword "register" is used in XKBlib.h, so don't try tricky things here */
#ifdef HAVE_XKBKEYCODETOKEYSYM
#define XkbOpenDisplay XkbOpenDisplay_ /* Move out of the way, conflicting definitions */
#include <X11/XKBlib.h>
#undef XkbOpenDisplay
#  include <X11/XKBlib.h>
#else
#  define XkbOpenDisplay(D,V,E,M,m,R) ((V),(E),(M),(m),(R),(NULL))
#endif

/*
 * The following static indicates whether this module has been initialized in
 * the current thread.
 */

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Prototypes for functions that are referenced only in this file:
 */

static void		DisplayCheckProc(void *clientData, int flags);
static void		DisplayExitHandler(void *clientData);
static void		DisplayFileProc(void *clientData, int flags);
static void		DisplaySetupProc(void *clientData, int flags);
static void		DisplayCheckProc(ClientData clientData, int flags);
static void		DisplayExitHandler(ClientData clientData);
static void		DisplayFileProc(ClientData clientData, int flags);
static void		DisplaySetupProc(ClientData clientData, int flags);
static void		TransferXEventsToTcl(Display *display);
#ifdef TK_USE_INPUT_METHODS
static void		InstantiateIMCallback(Display *, XPointer client_data, XPointer call_data);
static void		DestroyIMCallback(XIM im, XPointer client_data, XPointer call_data);
static void		OpenIM(TkDisplay *dispPtr);
#endif

87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
88
89
90
91
92
93
94

95
96
97
98

99
100
101
102
103
104
105







-
+



-







 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayExitHandler(
    void *dummy)	/* Not used. */
    ClientData clientData)	/* Not used. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    (void)dummy;

    Tcl_DeleteEventSource(DisplaySetupProc, DisplayCheckProc, NULL);
    tsdPtr->initialized = 0;
}

/*
 *----------------------------------------------------------------------
125
126
127
128
129
130
131

132
133

134
135
136
137
138
139
140
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141







+

-
+







    TkDisplay *dispPtr;
    Display *display;
    int event = 0;
    int error = 0;
    int major = 1;
    int minor = 0;
    int reason = 0;
    unsigned int use_xkb = 0;
    /* Disabled, until we have a better test. See [Bug 3613668] */
#if 0
#if 0 && defined(XKEYCODETOKEYSYM_IS_DEPRECATED) && defined(TCL_THREADS)
    static int xinited = 0;
    static Tcl_Mutex xinitMutex = NULL;

    if (!xinited) {
	Tcl_MutexLock(&xinitMutex);
	if (!xinited) {
	    /* Necessary for threaded apps, of no consequence otherwise  */
149
150
151
152
153
154
155
156

157
158


159
160

161









162
163
164
165
166

167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
150
151
152
153
154
155
156

157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182

183
184
185
186
187
188

























189
190
191
192
193
194
195







-
+


+
+

-
+

+
+
+
+
+
+
+
+
+




-
+


+

-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	}
	Tcl_MutexUnlock(&xinitMutex);
    }
#endif

    /*
    ** Bug [3607830]: Before using Xkb, it must be initialized and confirmed
    **                that the server supports it.  The XkbOpenDisplay call
    **                that the serve supports it.  The XkbOpenDisplay call
    **                will perform this check and return NULL if the extension
    **                is not supported.
    **
    ** Work around un-const-ified Xkb headers using (char *) cast.
    */
    display = XkbOpenDisplay(displayNameStr, &event, &error, &major,
    display = XkbOpenDisplay((char *)displayNameStr, &event, &error, &major,
	    &minor, &reason);

    if (display == NULL) {
	/*fprintf(stderr,"event=%d error=%d major=%d minor=%d reason=%d\nDisabling xkb\n",
	event, error, major, minor, reason);*/
	display  = XOpenDisplay(displayNameStr);
    } else {
	use_xkb = TK_DISPLAY_USE_XKB;
	/*fprintf(stderr, "Using xkb %d.%d\n", major, minor);*/
    }

    if (display == NULL) {
	return NULL;
    }
    dispPtr = (TkDisplay *)ckalloc(sizeof(TkDisplay));
    dispPtr = ckalloc(sizeof(TkDisplay));
    memset(dispPtr, 0, sizeof(TkDisplay));
    dispPtr->display = display;
    dispPtr->flags |= use_xkb;
#ifdef TK_USE_INPUT_METHODS
    XSetLocaleModifiers("");
    OpenIM(dispPtr);
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
#endif
    Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE,
	    DisplayFileProc, dispPtr);

    /*
     * Observed weird WidthMMOfScreen() in X on Wayland on a
     * Fedora 30/i386 running in a VM. Fallback to 75 dpi,
     * otherwise many other strange things may happen later.
     * See: [https://core.tcl-lang.org/tk/tktview?name=a01b6f7227]
     */
    if (WidthMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = WidthOfScreen(DefaultScreenOfDisplay(display)) * (25.4 / 75.0);
	WidthMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }
    if (HeightMMOfScreen(DefaultScreenOfDisplay(display)) <= 0) {
	int mm;

	mm = HeightOfScreen(DefaultScreenOfDisplay(display)) * (25.4 / 75.0);
	HeightMMOfScreen(DefaultScreenOfDisplay(display)) = mm;
    }

    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(dispPtr);

    return dispPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCloseDisplay --
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310
311
312
313
314
282
283
284
285
286
287
288

289
290
291
292
293

294
295
296
297
298
299
300







-
+




-







 *	Tcl even if there is no more data on the X connection.
 *
 *----------------------------------------------------------------------
 */

static void
DisplaySetupProc(
    void *dummy,	/* Not used. */
    ClientData clientData,	/* Not used. */
    int flags)
{
    TkDisplay *dispPtr;
    static Tcl_Time blockTime = { 0, 0 };
    (void)dummy;

    if (!(flags & TCL_WINDOW_EVENTS)) {
	return;
    }

    for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
	    dispPtr = dispPtr->nextPtr) {
345
346
347
348
349
350
351



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

369

370
371
372


373

374
375
376
377
378
379
380
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358

359



360
361
362
363
364
365
366
367
368
369
370







+
+
+

















+
-
+
-
-
-
+
+

+







TransferXEventsToTcl(
    Display *display)
{
    union {
	int type;
	XEvent x;
	TkKeyEvent k;
#ifdef GenericEvent
	xGenericEvent xge;
#endif
    } event;
    Window w;
    TkDisplay *dispPtr = NULL;

    /*
     * Transfer events from the X event queue to the Tk event queue after XIM
     * event filtering. KeyPress and KeyRelease events need special treatment
     * so that they get directed according to Tk's focus rules during XIM
     * handling. Theoretically they can go to the wrong place still (if
     * there's a focus change in the queue) but if we push the handling off
     * until Tk_HandleEvent then many input methods actually cease to work
     * correctly. Most of the time, Tk processes its event queue fast enough
     * for this to not be an issue anyway. [Bug 1924761]
     */

    while (QLength(display) > 0) {
	XNextEvent(display, &event.x);
#ifdef GenericEvent
	if ((event.type >= VirtualEvent) && (event.type <= MouseWheelEvent)) {
	if (event.type == GenericEvent) {
	    /* See [fe87e9af39]. Those are internal Tk event types, if they come
	     * from an external source they most likely would be totally mis-interpreted */
	    continue;
	    Tcl_Panic("Wild GenericEvent; panic! (extension=%d,evtype=%d)",
		    event.xge.extension, event.xge.evtype);
	}
#endif
	w = None;
	if (event.type == KeyPress || event.type == KeyRelease) {
	    for (dispPtr = TkGetDisplayList(); ; dispPtr = dispPtr->nextPtr) {
		if (dispPtr == NULL) {
		    break;
		} else if (dispPtr->display == event.x.xany.display) {
		    if (dispPtr->focusPtr != NULL) {
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
445
446
447
448
420
421
422
423
424
425
426

427
428
429
430

431
432
433
434
435
436
437







-
+



-







 *	Moves queued events onto the Tcl event queue.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayCheckProc(
    void *dummy,	/* Not used. */
    ClientData clientData,	/* Not used. */
    int flags)
{
    TkDisplay *dispPtr;
    (void)dummy;

    if (!(flags & TCL_WINDOW_EVENTS)) {
	return;
    }

    for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
	    dispPtr = dispPtr->nextPtr) {
466
467
468
469
470
471
472
473

474
475
476

477
478
479
480
481
482
483
484
485
486
455
456
457
458
459
460
461

462
463
464

465
466
467

468
469
470
471
472
473
474







-
+


-
+


-







 *	all the displays.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayFileProc(
    void *clientData,	/* The display pointer. */
    ClientData clientData,	/* The display pointer. */
    int flags)			/* Should be TCL_READABLE. */
{
    TkDisplay *dispPtr = (TkDisplay *)clientData;
    TkDisplay *dispPtr = (TkDisplay *) clientData;
    Display *display = dispPtr->display;
    int numFound;
    (void)flags;

    XFlush(display);
    numFound = XEventsQueued(display, QueuedAfterReading);
    if (numFound == 0) {
	/*
	 * Things are very tricky if there aren't any events readable at this
	 * point (after all, there was supposedly data available on the
497
498
499
500
501
502
503
504

505
506

507
508
509
510
511
512
513
485
486
487
488
489
490
491

492
493

494
495
496
497
498
499
500
501







-
+

-
+







	 * such an error, generate a NoOp protocol request to exercise the
	 * connection to the server, then return. However, must disable
	 * SIGPIPE while sending the request, or else the process will die
	 * from the signal and won't invoke the X error function to print a
	 * nice (?!) message.
	 */

	void (*oldHandler)(int);
	void (*oldHandler)();

	oldHandler = (void (*)(int)) signal(SIGPIPE, SIG_IGN);
	oldHandler = (void (*)()) signal(SIGPIPE, SIG_IGN);
	XNoOp(display);
	XFlush(display);
	(void) signal(SIGPIPE, oldHandler);
    }

    TransferXEventsToTcl(display);
}
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
650
651
652
653
654
655
656

657
658
659
660
661
662
663







-







 *
 * Side effects:
 *	Places new events on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

#undef TkpSync
void
TkpSync(
    Display *display)		/* Display to sync. */
{
    XSync(display, False);

    /*
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
671
672
673
674
675
676
677


678
679
680
681
682
683
684
685
686
687
688
689
690
691


692
693
694
695
696
697
698







-
-














-
-







static void
InstantiateIMCallback(
    Display      *display,
    XPointer     client_data,
    XPointer     call_data)
{
    TkDisplay    *dispPtr;
    (void)display;
    (void)call_data;

    dispPtr = (TkDisplay *) client_data;
    OpenIM(dispPtr);
    XUnregisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
}

static void
DestroyIMCallback(
    XIM         im,
    XPointer    client_data,
    XPointer    call_data)
{
    TkDisplay   *dispPtr;
    (void)im;
    (void)call_data;

    dispPtr = (TkDisplay *) client_data;
    dispPtr->inputMethod = NULL;
    ++dispPtr->ximGeneration;
    XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL,
	    InstantiateIMCallback, (XPointer) dispPtr);
}
734
735
736
737
738
739
740




741
742
743
744
745
746
747
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734







+
+
+
+







static void
OpenIM(
    TkDisplay *dispPtr)		/* Tk's structure for the display. */
{
    int i;
    XIMStyles *stylePtr;
    XIMStyle bestStyle = 0;

    if (XSetLocaleModifiers("") == NULL) {
	return;
    }

    ++dispPtr->ximGeneration;
    dispPtr->inputMethod = XOpenIM(dispPtr->display, NULL, NULL, NULL);
    if (dispPtr->inputMethod == NULL) {
	return;
    }

Changes to unix/tkUnixFocus.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkUnixFocus.c --
 *
 *	This file contains platform specific functions that manage focus for
 *	Tk.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 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.
 */

#include "tkUnixInt.h"

Changes to unix/tkUnixFont.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14


15
16
17
18
19
20
21
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23






-
+







+
+







/*
 * tkUnixFont.c --
 *
 *	Contains the Unix implementation of the platform-independent font
 *	package interface.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-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.
 */

#include "tkUnixInt.h"
#include "tkFont.h"
#include <netinet/in.h>		/* for htons() prototype */
#include <arpa/inet.h>		/* inet_ntoa() */

/*
 * The preferred font encodings.
 */

static const char encodingList[][10] = {
    "iso8859-1", "jis0208", "jis0212"
29
30
31
32
33
34
35
36

37

38
39
40
41
42
43
44
45
46
47
31
32
33
34
35
36
37

38
39
40
41


42
43
44
45
46
47
48







-
+

+

-
-







 * character existence metrics, used to determine if a screen font can display
 * a given Unicode character.
 *
 * Under Unix, there are three attributes that uniquely identify a "font
 * family": the foundry, face name, and charset.
 */

#define FONTMAP_SHIFT		10
#define FONTMAP_SHIFT		12

#define FONTMAP_PAGES		(1 << (21 - FONTMAP_SHIFT))
#define FONTMAP_BITSPERPAGE	(1 << FONTMAP_SHIFT)
#define FONTMAP_NUMCHARS	0x40000
#define FONTMAP_PAGES		(FONTMAP_NUMCHARS / FONTMAP_BITSPERPAGE)

typedef struct FontFamily {
    struct FontFamily *nextPtr;	/* Next in list of all known font families. */
    size_t refCount;		/* How many SubFonts are referring to this
				 * FontFamily. When the refCount drops to
				 * zero, this FontFamily may be freed. */
    /*
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73







-
+








    int isTwoByteFont;		/* 1 if this is a double-byte font, 0
				 * otherwise. */
    char *fontMap[FONTMAP_PAGES];
				/* Two-level sparse table used to determine
				 * quickly if the specified character exists.
				 * As characters are encountered, more pages
				 * in this table are dynamically allocated. The
				 * in this table are dynamically alloced. The
				 * contents of each page is a bitmask
				 * consisting of FONTMAP_BITSPERPAGE bits,
				 * representing whether this font can be used
				 * to display the given character at the
				 * corresponding bit position. The high bits
				 * of the character are used to pick which
				 * page of the table is used. */
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
+







				/* Builtin space for a limited number of
				 * SubFonts. */
    int numSubFonts;		/* Length of following array. */
    SubFont *subFontArray;	/* Array of SubFonts that have been loaded in
				 * order to draw/measure all the characters
				 * encountered by this font so far. All fonts
				 * start off with one SubFont initialized by
				 * InitFont() from the original set of font
				 * AllocFont() from the original set of font
				 * attributes. Usually points to
				 * staticSubFonts, but may point to malloced
				 * space if there are lots of SubFonts. */
    SubFont controlSubFont;	/* Font to use to display control-character
				 * expansions. */

    Display *display;		/* Display that owns font. */
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163







-
+







 */

typedef struct FontAttributes {
    TkFontAttributes fa;
    TkXLFDAttributes xa;
} FontAttributes;

typedef struct {
typedef struct ThreadSpecificData {
    FontFamily *fontFamilyList; /* The list of font families that are
				 * currently loaded. As screen fonts are
				 * loaded, this list grows to hold information
				 * about what characters exist in each font
				 * family. */
    FontFamily controlFamily;	/* FontFamily used to handle control character
				 * expansions. The encoding of this FontFamily
181
182
183
184
185
186
187






188

189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







+
+
+
+
+
+

+







-
+









-
+







    {"jis0201",		"jisx0202*"},
    {"jis0208",		"jisc6226*"},
    {"jis0208",		"jisx0208*"},
    {"jis0212",		"jisx0212*"},
    {"tis620",		"tis620*"},
    {"ksc5601",		"ksc5601*"},
    {"dingbats",	"*dingbats"},
#ifdef WORDS_BIGENDIAN
    {"unicode",		"iso10646-1"},
#else
    /*
     * ucs-2be is needed if native order isn't BE.
     */
    {"ucs-2be",		"iso10646-1"},
#endif
    {NULL,		NULL}
};

/*
 * Functions used only in this file.
 */

static void		FontPkgCleanup(void *clientData);
static void		FontPkgCleanup(ClientData clientData);
static FontFamily *	AllocFontFamily(Display *display,
			    XFontStruct *fontStructPtr, int base);
static SubFont *	CanUseFallback(UnixFont *fontPtr,
			    const char *fallbackName, int ch,
			    SubFont **fixSubFontPtrPtr);
static SubFont *	CanUseFallbackWithAliases(UnixFont *fontPtr,
			    const char *fallbackName, int ch,
			    Tcl_DString *nameTriedPtr,
			    SubFont **fixSubFontPtrPtr);
static int		ControlUtfProc(void *clientData, const char *src,
static int		ControlUtfProc(ClientData clientData, const char *src,
			    int srcLen, int flags, Tcl_EncodingState*statePtr,
			    char *dst, int dstLen, int *srcReadPtr,
			    int *dstWrotePtr, int *dstCharsPtr);
static XFontStruct *	CreateClosestFont(Tk_Window tkwin,
			    const TkFontAttributes *faPtr,
			    const TkXLFDAttributes *xaPtr);
static SubFont *	FindSubFontForChar(UnixFont *fontPtr, int ch,
234
235
236
237
238
239
240










241
242
243
244
245
246
247
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265







+
+
+
+
+
+
+
+
+
+







static char **		ListFontOrAlias(Display *display, const char*faceName,
			    int *numNamesPtr);
static unsigned		RankAttributes(FontAttributes *wantPtr,
			    FontAttributes *gotPtr);
static void		ReleaseFont(UnixFont *fontPtr);
static void		ReleaseSubFont(Display *display, SubFont *subFontPtr);
static int		SeenName(const char *name, Tcl_DString *dsPtr);
#ifndef WORDS_BIGENDIAN
static int		Ucs2beToUtfProc(ClientData clientData, const char*src,
			    int srcLen, int flags, Tcl_EncodingState*statePtr,
			    char *dst, int dstLen, int *srcReadPtr,
			    int *dstWrotePtr, int *dstCharsPtr);
static int		UtfToUcs2beProc(ClientData clientData, const char*src,
			    int srcLen, int flags, Tcl_EncodingState*statePtr,
			    char *dst, int dstLen, int *srcReadPtr,
			    int *dstWrotePtr, int *dstCharsPtr);
#endif

/*
 *-------------------------------------------------------------------------
 *
 * FontPkgCleanup --
 *
 *	This function is called when an application is created. It initializes
255
256
257
258
259
260
261
262

263
264

265
266
267
268
269
270
271
273
274
275
276
277
278
279

280
281

282
283
284
285
286
287
288
289







-
+

-
+







 *	Releases thread-specific resources used by font pkg.
 *
 *-------------------------------------------------------------------------
 */

static void
FontPkgCleanup(
    TCL_UNUSED(void *))
    ClientData clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->controlFamily.encoding != NULL) {
	FontFamily *familyPtr = &tsdPtr->controlFamily;
	int i;

	Tcl_FreeEncoding(familyPtr->encoding);
294
295
296
297
298
299
300
301

302
303

304

305
306
307
308






309
310
311
312
313
314
315
316
317
318
319
320
321

322
323
324

325
326








327
328
329
330
331
332
333
312
313
314
315
316
317
318

319
320

321
322
323
324
325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366







-
+

-
+

+




+
+
+
+
+
+

-











+


-
+


+
+
+
+
+
+
+
+







 *	None.
 *
 *-------------------------------------------------------------------------
 */

void
TkpFontPkgInit(
    TCL_UNUSED(TkMainInfo *))	/* The application being created. */
    TkMainInfo *mainPtr)	/* The application being created. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_EncodingType type;
    SubFont dummy;
    int i;

    if (tsdPtr->controlFamily.encoding == NULL) {
	type.encodingName = "X11ControlChars";
	type.toUtfProc = ControlUtfProc;
	type.fromUtfProc = ControlUtfProc;
	type.freeProc = NULL;
	type.clientData = NULL;
	type.nullSize = 0;

	Tcl_EncodingType type = {"X11ControlChars", ControlUtfProc, ControlUtfProc, NULL, NULL, 0};
	tsdPtr->controlFamily.refCount = 2;
	tsdPtr->controlFamily.encoding = Tcl_CreateEncoding(&type);
	tsdPtr->controlFamily.isTwoByteFont = 0;

	dummy.familyPtr = &tsdPtr->controlFamily;
	dummy.fontMap = tsdPtr->controlFamily.fontMap;
	for (i = 0x00; i < 0x20; i++) {
	    FontMapInsert(&dummy, i);
	    FontMapInsert(&dummy, i + 0x80);
	}

#ifndef WORDS_BIGENDIAN
	/*
	 * UCS-2BE is unicode (UCS-2) in big-endian format. Define this if
	 * if it doesn't exist yet. It is used in iso10646 fonts.
	 * native order isn't BE. It is used in iso10646 fonts.
	 */

	type.encodingName = "ucs-2be";
	type.toUtfProc = Ucs2beToUtfProc;
	type.fromUtfProc = UtfToUcs2beProc;
	type.freeProc = NULL;
	type.clientData = NULL;
	type.nullSize = 2;
	Tcl_CreateEncoding(&type);
#endif
	Tcl_CreateThreadExitHandler(FontPkgCleanup, NULL);
    }
}

/*
 *-------------------------------------------------------------------------
 *
342
343
344
345
346
347
348
349

350
351
352
353


354
355
356
357
358
359
360
375
376
377
378
379
380
381

382
383
384


385
386
387
388
389
390
391
392
393







-
+


-
-
+
+







 *	None.
 *
 *-------------------------------------------------------------------------
 */

static int
ControlUtfProc(
    TCL_UNUSED(void *),	/* Not used. */
    ClientData clientData,	/* Not used. */
    const char *src,		/* Source string in UTF-8. */
    int srcLen,			/* Source string length in bytes. */
    TCL_UNUSED(int),			/* Conversion control flags. */
    TCL_UNUSED(Tcl_EncodingState *),/* Place for conversion routine to store state
    int flags,			/* Conversion control flags. */
    Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
				 * information used during a piecewise
				 * conversion. Contents of statePtr are
				 * initialized and/or reset by conversion
				 * routine under control of flags argument. */
    char *dst,			/* Output buffer in which converted string is
				 * stored. */
    int dstLen,			/* The maximum length of output buffer in
369
370
371
372
373
374
375
376
377



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

397
398

399
400
401

402
403
404


405
406

407
408
409
410
411




412
413
414
415
416
417
418
419




420
421
422
423
424
425
426
427
428















































































































































































429
430
431
432
433
434
435
402
403
404
405
406
407
408


409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431

432
433
434

435
436


437
438
439

440
441




442
443
444
445
446
447
448
449




450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644







-
-
+
+
+


















-
+

-
+


-
+

-
-
+
+

-
+

-
-
-
-
+
+
+
+




-
-
-
-
+
+
+
+









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				 * the conversion. */
    int *dstCharsPtr)		/* Filled with the number of characters that
				 * correspond to the bytes stored in the
				 * output buffer. */
{
    const char *srcStart, *srcEnd;
    char *dstStart, *dstEnd;
    int ch, result;
    static const char hexChars[] = "0123456789ABCDEF";
    int ch;
    int result;
    static const char hexChars[] = "0123456789abcdef";
    static const char mapChars[] = {
	0, 0, 0, 0, 0, 0, 0,
	'a', 'b', 't', 'n', 'v', 'f', 'r'
    };

    result = TCL_OK;

    srcStart = src;
    srcEnd = src + srcLen;

    dstStart = dst;
    dstEnd = dst + dstLen - 6;

    for ( ; src < srcEnd; ) {
	if (dst > dstEnd) {
	    result = TCL_CONVERT_NOSPACE;
	    break;
	}
	src += Tcl_UtfToUniChar(src, &ch);
	src += TkUtfToUniChar(src, &ch);
	dst[0] = '\\';
	if (((size_t)ch < sizeof(mapChars)) && (mapChars[ch] != 0)) {
	if (((size_t) ch < sizeof(mapChars)) && (mapChars[ch] != 0)) {
	    dst[1] = mapChars[ch];
	    dst += 2;
	} else if ((size_t)ch < 256) {
	} else if (ch < 256) {
	    dst[1] = 'x';
	    dst[2] = hexChars[(ch >> 4) & 0xF];
	    dst[3] = hexChars[ch & 0xF];
	    dst[2] = hexChars[(ch >> 4) & 0xf];
	    dst[3] = hexChars[ch & 0xf];
	    dst += 4;
	} else if ((size_t)ch < 0x10000) {
	} else if (ch < 0x10000) {
	    dst[1] = 'u';
	    dst[2] = hexChars[(ch >> 12) & 0xF];
	    dst[3] = hexChars[(ch >> 8) & 0xF];
	    dst[4] = hexChars[(ch >> 4) & 0xF];
	    dst[5] = hexChars[ch & 0xF];
	    dst[2] = hexChars[(ch >> 12) & 0xf];
	    dst[3] = hexChars[(ch >> 8) & 0xf];
	    dst[4] = hexChars[(ch >> 4) & 0xf];
	    dst[5] = hexChars[ch & 0xf];
	    dst += 6;
	} else {
	    /* TODO we can do better here */
	    dst[1] = 'u';
	    dst[2] = 'F';
	    dst[3] = 'F';
	    dst[4] = 'F';
	    dst[5] = 'D';
	    dst[2] = 'f';
	    dst[3] = 'f';
	    dst[4] = 'f';
	    dst[5] = 'd';
	    dst += 6;
	}
    }
    *srcReadPtr = src - srcStart;
    *dstWrotePtr = dst - dstStart;
    *dstCharsPtr = dst - dstStart;
    return result;
}

#ifndef WORDS_BIGENDIAN
/*
 *-------------------------------------------------------------------------
 *
 * Ucs2beToUtfProc --
 *
 *	Convert from UCS-2BE (big-endian 16-bit Unicode) to UTF-8.
 *	This is only defined on LE machines.
 *
 * Results:
 *	Returns TCL_OK if conversion was successful.
 *
 * Side effects:
 *	None.
 *
 *-------------------------------------------------------------------------
 */

static int
Ucs2beToUtfProc(
    ClientData clientData,	/* Not used. */
    const char *src,		/* Source string in Unicode. */
    int srcLen,			/* Source string length in bytes. */
    int flags,			/* Conversion control flags. */
    Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
				 * information used during a piecewise
				 * conversion. Contents of statePtr are
				 * initialized and/or reset by conversion
				 * routine under control of flags argument. */
    char *dst,			/* Output buffer in which converted string is
				 * stored. */
    int dstLen,			/* The maximum length of output buffer in
				 * bytes. */
    int *srcReadPtr,		/* Filled with the number of bytes from the
				 * source string that were converted. This may
				 * be less than the original source length if
				 * there was a problem converting some source
				 * characters. */
    int *dstWrotePtr,		/* Filled with the number of bytes that were
				 * stored in the output buffer as a result of
				 * the conversion. */
    int *dstCharsPtr)		/* Filled with the number of characters that
				 * correspond to the bytes stored in the
				 * output buffer. */
{
    const char *srcStart, *srcEnd;
    char *dstEnd, *dstStart;
    int result, numChars;

    result = TCL_OK;

    /* check alignment with ucs-2 (2 == sizeof(UCS-2)) */
    if ((srcLen % 2) != 0) {
	result = TCL_CONVERT_MULTIBYTE;
	srcLen--;
    }

    srcStart = src;
    srcEnd = src + srcLen;

    dstStart = dst;
    dstEnd = dst + dstLen - 4;

    for (numChars = 0; src < srcEnd; numChars++) {
	if (dst > dstEnd) {
	    result = TCL_CONVERT_NOSPACE;
	    break;
	}

	/*
	 * Need to swap byte-order on little-endian machines (x86) for
	 * UCS-2BE. We know this is an LE->BE swap.
	 */

	dst += Tcl_UniCharToUtf(htons(*((short *)src)), dst);
	src += 2 /* sizeof(UCS-2) */;
    }

    *srcReadPtr = src - srcStart;
    *dstWrotePtr = dst - dstStart;
    *dstCharsPtr = numChars;
    return result;
}

/*
 *-------------------------------------------------------------------------
 *
 * UtfToUcs2beProc --
 *
 *	Convert from UTF-8 to UCS-2BE (fixed 2-byte encoding).
 *
 * Results:
 *	Returns TCL_OK if conversion was successful.
 *
 * Side effects:
 *	None.
 *
 *-------------------------------------------------------------------------
 */

static int
UtfToUcs2beProc(
    ClientData clientData,	/* TableEncodingData that specifies
				 * encoding. */
    const char *src,		/* Source string in UTF-8. */
    int srcLen,			/* Source string length in bytes. */
    int flags,			/* Conversion control flags. */
    Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
				 * information used during a piecewise
				 * conversion. Contents of statePtr are
				 * initialized and/or reset by conversion
				 * routine under control of flags argument. */
    char *dst,			/* Output buffer in which converted string is
				 * stored. */
    int dstLen,			/* The maximum length of output buffer in
				 * bytes. */
    int *srcReadPtr,		/* Filled with the number of bytes from the
				 * source string that were converted. This may
				 * be less than the original source length if
				 * there was a problem converting some source
				 * characters. */
    int *dstWrotePtr,		/* Filled with the number of bytes that were
				 * stored in the output buffer as a result of
				 * the conversion. */
    int *dstCharsPtr)		/* Filled with the number of characters that
				 * correspond to the bytes stored in the
				 * output buffer. */
{
    const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
    int result, numChars;
    Tcl_UniChar ch;

    srcStart = src;
    srcEnd = src + srcLen;
    srcClose = srcEnd;
    if (!(flags & TCL_ENCODING_END)) {
	srcClose -= 4;
    }

    dstStart = dst;
    dstEnd = dst + dstLen - 2 /* sizeof(UCS-2) */;

    result = TCL_OK;
    for (numChars = 0; src < srcEnd; numChars++) {
	if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) {
	    /*
	     * If there is more string to follow, this will ensure that the
	     * last UTF-8 character in the source buffer hasn't been cut off.
	     */

	    result = TCL_CONVERT_MULTIBYTE;
	    break;
	}
	if (dst > dstEnd) {
	    result = TCL_CONVERT_NOSPACE;
	    break;
        }
	src += Tcl_UtfToUniChar(src, &ch);

	/*
	 * Ensure big-endianness (store big bits first).
	 * XXX: This hard-codes the assumed size of Tcl_UniChar as 2. Make
	 * sure to work in char* for Tcl_UtfToUniChar alignment. [Bug 1122671]
	 */

	*dst++ = (ch >> 8);
	*dst++ = (ch & 0xFF);
    }
    *srcReadPtr = src - srcStart;
    *dstWrotePtr = dst - dstStart;
    *dstCharsPtr = numChars;
    return result;
}
#endif /* WORDS_BIGENDIAN */

/*
 *---------------------------------------------------------------------------
 *
 * TkpGetNativeFont --
 *
 *	Map a platform-specific native font name to a TkFont.
 *
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
708
709
710
711
712
713
714

715
716
717
718
719
720
721
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
737







-
+














-
+







	 * out and lost. But make sure we don't have an "-option value" string
	 * since TkFontParseXLFD would return a false success when attempting
	 * to parse it.
	 */

	if (name[0] == '-') {
	    if (name[1] != '*') {
		const char *dash;
		char *dash;

		dash = strchr(name + 1, '-');
		if ((dash == NULL) || (isspace(UCHAR(dash[-1])))) {
		    return NULL;
		}
	    }
	} else if (name[0] != '*') {
	    return NULL;
	}
	if (TkFontParseXLFD(name, &fa.fa, &fa.xa) != TCL_OK) {
	    return NULL;
	}
	fontStructPtr = CreateClosestFont(tkwin, &fa.fa, &fa.xa);
    }
    fontPtr = (UnixFont *)ckalloc(sizeof(UnixFont));
    fontPtr = ckalloc(sizeof(UnixFont));
    InitFont(tkwin, fontStructPtr, fontPtr);

    return (TkFont *) fontPtr;
}

/*
 *---------------------------------------------------------------------------
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793







-
+







    XFontStruct *fontStructPtr;

    TkInitXLFDAttributes(&xa);
    fontStructPtr = CreateClosestFont(tkwin, faPtr, &xa);

    fontPtr = (UnixFont *) tkFontPtr;
    if (fontPtr == NULL) {
	fontPtr = (UnixFont *)ckalloc(sizeof(UnixFont));
	fontPtr = ckalloc(sizeof(UnixFont));
    } else {
	ReleaseFont(fontPtr);
    }
    InitFont(tkwin, fontStructPtr, fontPtr);

    fontPtr->font.fa.underline = faPtr->underline;
    fontPtr->font.fa.overstrike = faPtr->overstrike;
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
842
843
844
845
846
847
848

849
850
851
852
853
854
855
856







-
+







 */

void
TkpGetFontFamilies(
    Tcl_Interp *interp,		/* Interp to hold result. */
    Tk_Window tkwin)		/* For display to query. */
{
    int i, isNew, numNames;
    int i, new, numNames;
    char *family, **nameList;
    Tcl_HashTable familyTable;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    Tcl_Obj *resultPtr, *strPtr;

    Tcl_InitHashTable(&familyTable, TCL_STRING_KEYS);
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676

677
678
679
680
681
682
683
871
872
873
874
875
876
877

878
879
880
881
882
883
884

885
886
887
888
889
890
891
892







-
+






-
+







	}
	family++;			/* Advance to char after '-'. */
	familyEnd = strchr(family, '-');
	if (familyEnd == NULL) {
	    continue;			/* See comment above. */
	}
	*familyEnd = '\0';
	Tcl_CreateHashEntry(&familyTable, family, &isNew);
	Tcl_CreateHashEntry(&familyTable, family, &new);
    }
    XFreeFontNames(nameList);

    hPtr = Tcl_FirstHashEntry(&familyTable, &search);
    resultPtr = Tcl_NewObj();
    while (hPtr != NULL) {
	strPtr = Tcl_NewStringObj((const char *)Tcl_GetHashKey(&familyTable, hPtr), TCL_INDEX_NONE);
	strPtr = Tcl_NewStringObj(Tcl_GetHashKey(&familyTable, hPtr), -1);
	Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
	hPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_SetObjResult(interp, resultPtr);

    Tcl_DeleteHashTable(&familyTable);
}
710
711
712
713
714
715
716
717
718


719
720

721
722
723
724
725
726
727
919
920
921
922
923
924
925


926
927
928

929
930
931
932
933
934
935
936







-
-
+
+

-
+







    UnixFont *fontPtr;
    FontFamily *familyPtr;

    resultPtr = Tcl_NewObj();
    fontPtr = (UnixFont *) tkfont;
    for (i = 0; i < fontPtr->numSubFonts; i++) {
	familyPtr = fontPtr->subFontArray[i].familyPtr;
	objv[0] = Tcl_NewStringObj(familyPtr->faceName, TCL_INDEX_NONE);
	objv[1] = Tcl_NewStringObj(familyPtr->foundry, TCL_INDEX_NONE);
	objv[0] = Tcl_NewStringObj(familyPtr->faceName, -1);
	objv[1] = Tcl_NewStringObj(familyPtr->foundry, -1);
	objv[2] = Tcl_NewStringObj(
		Tcl_GetEncodingName(familyPtr->encoding), TCL_INDEX_NONE);
		Tcl_GetEncodingName(familyPtr->encoding), -1);
	listPtr = Tcl_NewListObj(3, objv);
	Tcl_ListObjAppendElement(NULL, resultPtr, listPtr);
    }
    Tcl_SetObjResult(interp, resultPtr);
}

/*
785
786
787
788
789
790
791
792

793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830

831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846

847
848
849
850

851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868

869
870
871
872
873
874
875
876
877
878
879
880
881
882
883

884
885
886
887
888
889
890
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020


1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100







-
+



















-
-
+

















+















-
+



-
+

















-
+















+







 */

int
Tk_MeasureChars(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    Tcl_Size numBytes,		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length in pixels; don't
				 * consider any character that would cross
				 * this x-position. If < 0, then line length
				 * is unbounded and the flags argument is
				 * ignored. */
    int flags,			/* Various flag bits OR-ed together:
				 * TK_PARTIAL_OK means include the last char
				 * which only partially fit on this line.
				 * TK_WHOLE_WORDS means stop on a word
				 * boundary, if possible. TK_AT_LEAST_ONE
				 * means return at least one character even if
				 * no characters fit. */
    int *lengthPtr)		/* Filled with x-location just after the
				 * terminating character. */
{
    UnixFont *fontPtr;
    SubFont *lastSubFontPtr;
    Tcl_Size curByte;
    int curX, ch;
    int curX, curByte;

    /*
     * Unix does not use kerning or fractional character widths when
     * displaying text on the screen. So that means we can safely measure
     * individual characters or spans of characters and add up the widths w/o
     * any "off-by-one-pixel" errors.
     */

    fontPtr = (UnixFont *) tkfont;

    lastSubFontPtr = &fontPtr->subFontArray[0];

    if (numBytes == 0) {
	curX = 0;
	curByte = 0;
    } else if (maxLength < 0) {
	const char *p, *end, *next;
	int ch;
	SubFont *thisSubFontPtr;
	FontFamily *familyPtr;
	Tcl_DString runString;

	/*
	 * A three step process:
	 * 1. Find a contiguous range of characters that can all be
	 *    represented by a single screen font.
	 * 2. Convert those chars to the encoding of that font.
	 * 3. Measure converted chars.
	 */

	curX = 0;
	end = source + numBytes;
	for (p = source; p < end; ) {
	    next = p + Tcl_UtfToUniChar(p, &ch);
	    next = p + TkUtfToUniChar(p, &ch);
	    thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
	    if (thisSubFontPtr != lastSubFontPtr) {
		familyPtr = lastSubFontPtr->familyPtr;
		(void)Tcl_UtfToExternalDString(familyPtr->encoding, source,
		Tcl_UtfToExternalDString(familyPtr->encoding, source,
			p - source, &runString);
		if (familyPtr->isTwoByteFont) {
		    curX += XTextWidth16(lastSubFontPtr->fontStructPtr,
			    (XChar2b *) Tcl_DStringValue(&runString),
			    Tcl_DStringLength(&runString) / 2);
		} else {
		    curX += XTextWidth(lastSubFontPtr->fontStructPtr,
			    Tcl_DStringValue(&runString),
			    Tcl_DStringLength(&runString));
		}
		Tcl_DStringFree(&runString);
		lastSubFontPtr = thisSubFontPtr;
		source = p;
	    }
	    p = next;
	}
	familyPtr = lastSubFontPtr->familyPtr;
	(void)Tcl_UtfToExternalDString(familyPtr->encoding, source, p - source,
	Tcl_UtfToExternalDString(familyPtr->encoding, source, p - source,
		&runString);
	if (familyPtr->isTwoByteFont) {
	    curX += XTextWidth16(lastSubFontPtr->fontStructPtr,
		    (XChar2b *) Tcl_DStringValue(&runString),
		    Tcl_DStringLength(&runString) >> 1);
	} else {
	    curX += XTextWidth(lastSubFontPtr->fontStructPtr,
		    Tcl_DStringValue(&runString),
		    Tcl_DStringLength(&runString));
	}
	Tcl_DStringFree(&runString);
	curByte = numBytes;
    } else {
	const char *p, *end, *next, *term;
	int newX, termX, sawNonSpace, dstWrote;
	Tcl_UniChar ch;
	FontFamily *familyPtr;
	XChar2b buf[8];

	/*
	 * How many chars will fit in the space allotted? This first version
	 * may be inefficient because it measures every character
	 * individually.
900
901
902
903
904
905
906
907

908
909
910
911
912
913
914
1110
1111
1112
1113
1114
1115
1116

1117
1118
1119
1120
1121
1122
1123
1124







-
+







	familyPtr = lastSubFontPtr->familyPtr;
	for (p = source; ; ) {
	    if ((ch < BASE_CHARS) && (fontPtr->widths[ch] != 0)) {
		newX += fontPtr->widths[ch];
	    } else {
		lastSubFontPtr = FindSubFontForChar(fontPtr, ch, NULL);
		familyPtr = lastSubFontPtr->familyPtr;
		Tcl_UtfToExternal(NULL, familyPtr->encoding, p, next - p, TCL_ENCODING_PROFILE_TCL8, NULL,
		Tcl_UtfToExternal(NULL, familyPtr->encoding, p, next - p, 0, NULL,
			(char *)&buf[0].byte1, sizeof(buf), NULL, &dstWrote, NULL);
		if (familyPtr->isTwoByteFont) {
		    newX += XTextWidth16(lastSubFontPtr->fontStructPtr,
			    buf, dstWrote >> 1);
		} else {
		    newX += XTextWidth(lastSubFontPtr->fontStructPtr,
			    (char *)&buf[0].byte1, dstWrote);
998
999
1000
1001
1002
1003
1004
1005

1006
1007
1008


1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
1208
1209
1210
1211
1212
1213
1214

1215
1216


1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244







-
+

-
-
+
+


















+







 */

int
TkpMeasureCharsInContext(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    TCL_UNUSED(Tcl_Size),		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string in all. */
    Tcl_Size rangeStart,		/* Index of first byte to measure. */
    Tcl_Size rangeLength,		/* Length of range to measure in bytes. */
    int rangeStart,		/* Index of first byte to measure. */
    int rangeLength,		/* Length of range to measure in bytes. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length; don't consider any
				 * character that would cross this x-position.
				 * If < 0, then line length is unbounded and
				 * the flags argument is ignored. */
    int flags,			/* Various flag bits OR-ed together:
				 * TK_PARTIAL_OK means include the last char
				 * which only partially fit on this line.
				 * TK_WHOLE_WORDS means stop on a word
				 * boundary, if possible. TK_AT_LEAST_ONE
				 * means return at least one character even if
				 * no characters fit. TK_ISOLATE_END means
				 * that the last character should not be
				 * considered in context with the rest of the
				 * string (used for breaking lines). */
    int *lengthPtr)		/* Filled with x-location just after the
				 * terminating character. */
{
    (void) numBytes; /*unused*/
    return Tk_MeasureChars(tkfont, source + rangeStart, rangeLength,
	    maxLength, flags, lengthPtr);
}

/*
 *---------------------------------------------------------------------------
 *
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070


1071
1072
1073
1074
1075
1076
1077
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283
1284
1285
1286
1287
1288
1289







-
+







-
+
+







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int x, int y)		/* Coordinates at which to place origin of
				 * string when drawing. */
{
    UnixFont *fontPtr = (UnixFont *) tkfont;
    SubFont *thisSubFontPtr, *lastSubFontPtr;
    Tcl_DString runString;
    const char *p, *end, *next;
    int xStart, needWidth, window_width, do_width, ch;
    int xStart, needWidth, window_width, do_width;
    Tcl_UniChar ch;
    FontFamily *familyPtr;
#ifdef TK_DRAW_CHAR_XWINDOW_CHECK
    int rx, ry;
    unsigned width, height, border_width, depth;
    Drawable root;
#endif

1110
1111
1112
1113
1114
1115
1116
1117

1118
1119
1120
1121
1122
1123
1124
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1336







-
+







	}
	if ((thisSubFontPtr != lastSubFontPtr)
		|| (p == end) || (p-source > 200)) {
	    if (p > source) {
		do_width = (needWidth || (p != end)) ? 1 : 0;
		familyPtr = lastSubFontPtr->familyPtr;

		(void)Tcl_UtfToExternalDString(familyPtr->encoding, source,
		Tcl_UtfToExternalDString(familyPtr->encoding, source,
			p - source, &runString);
		if (familyPtr->isTwoByteFont) {
		    XDrawString16(display, drawable, gc, x, y,
			    (XChar2b *) Tcl_DStringValue(&runString),
			    Tcl_DStringLength(&runString) / 2);
		    if (do_width) {
			x += XTextWidth16(lastSubFontPtr->fontStructPtr,
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1380
1381
1382
1383
1384
1385
1386



1387
1388
1389
1390
1391
1392
1393







-
-
-







 *
 * TkpDrawCharsInContext --
 *
 *	Draw a string of characters on the screen like Tk_DrawChars(), but
 *	with access to all the characters on the line for context. On X11 this
 *	context isn't consulted, so we just call Tk_DrawChars().
 *
 *      Note: TK_DRAW_IN_CONTEXT being currently defined only on macOS, this
 *            function is unused (and possibly unfinished). See [7655f65ae7].
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information gets drawn on the screen.
 *
 *---------------------------------------------------------------------------
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203



1204
1205
1206
1207
1208


1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1403
1404
1405
1406
1407
1408
1409



1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424































1425
1426
1427
1428
1429
1430
1431







-
-
-
+
+
+





+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    int numBytes,		/* Number of bytes in string. */
    int rangeStart,		/* Index of first byte to draw. */
    int rangeLength,		/* Length of range to draw in bytes. */
    int x, int y)		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
{
    int widthUntilStart;

    (void) numBytes; /*unused*/

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    Tk_DrawChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+widthUntilStart, y);
}

void
TkpDrawAngledCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength1,		/* Length of range to draw in bytes. */
    double x, double y,		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
    double angle)		/* What angle to put text at, in degrees. */
{
    int rangeLength = rangeLength1;
    int widthUntilStart;
    double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    TkDrawAngledChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+cosA*widthUntilStart, y-sinA*widthUntilStart, angle);
}

/*
 *-------------------------------------------------------------------------
 *
 * CreateClosestFont --
 *
 *	Helper for TkpGetNativeFont() and TkpGetFontFromAttributes(). Given a
1401
1402
1403
1404
1405
1406
1407
1408

1409
1410
1411
1412
1413
1414
1415
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595







-
+







static void
InitFont(
    Tk_Window tkwin,		/* For screen where font will be used. */
    XFontStruct *fontStructPtr,	/* X information about font. */
    UnixFont *fontPtr)		/* Filled with information constructed from
				 * the above arguments. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    unsigned long value;
    int minHi, maxHi, minLo, maxLo, fixed, width, limit, i, n;
    FontAttributes fa;
    TkFontAttributes *faPtr;
    TkFontMetrics *fmPtr;
    SubFont *controlPtr, *subFontPtr;
1507
1508
1509
1510
1511
1512
1513
1514

1515
1516
1517
1518
1519
1520
1521
1687
1688
1689
1690
1691
1692
1693

1694
1695
1696
1697
1698
1699
1700
1701







-
+







	/*
	 * If the XA_UNDERLINE_THICKNESS property does not exist, the X manual
	 * recommends using the width of the stem on a capital letter. I don't
	 * know of a way to get the stem width of a letter, so guess and use
	 * 1/3 the width of a capital I.
	 */

	fontPtr->barHeight = fontPtr->widths[(unsigned char)'I'] / 3;
	fontPtr->barHeight = fontPtr->widths['I'] / 3;
	if (fontPtr->barHeight == 0) {
	    fontPtr->barHeight = 1;
	}
    }
    if (fontPtr->underlinePos + fontPtr->barHeight > fontStructPtr->descent) {
	/*
	 * If this set of cobbled together values would cause the bottom of
1648
1649
1650
1651
1652
1653
1654
1655

1656
1657
1658
1659
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
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







-
+





-
+










-
-
+
-





-
+







 */

static FontFamily *
AllocFontFamily(
    Display *display,		/* Display in which font will be used. */
    XFontStruct *fontStructPtr,	/* Screen font whose FontFamily is to be
				 * returned. */
    TCL_UNUSED(int))			/* Non-zero if this font family is to be used
    int base)			/* Non-zero if this font family is to be used
				 * in the base font of a font object. */
{
    FontFamily *familyPtr;
    FontAttributes fa;
    Tcl_Encoding encoding;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    GetFontAttributes(display, fontStructPtr, &fa);
    encoding = Tcl_GetEncoding(NULL, GetEncodingAlias(fa.xa.charset));

    familyPtr = tsdPtr->fontFamilyList;
    for (; familyPtr != NULL; familyPtr = familyPtr->nextPtr) {
	if ((familyPtr->faceName == fa.fa.family)
		&& (familyPtr->foundry == fa.xa.foundry)
		&& (familyPtr->encoding == encoding)) {
	    if (encoding) {
		Tcl_FreeEncoding(encoding);
	    Tcl_FreeEncoding(encoding);
	    }
	    familyPtr->refCount++;
	    return familyPtr;
	}
    }

    familyPtr = (FontFamily *)ckalloc(sizeof(FontFamily));
    familyPtr = ckalloc(sizeof(FontFamily));
    memset(familyPtr, 0, sizeof(FontFamily));
    familyPtr->nextPtr = tsdPtr->fontFamilyList;
    tsdPtr->fontFamilyList = familyPtr;

    /*
     * Set key for this FontFamily.
     */
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
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







-
+









-
-
+
-







 */

static void
FreeFontFamily(
    FontFamily *familyPtr)	/* The FontFamily to delete. */
{
    FontFamily **familyPtrPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    int i;

    if (familyPtr == NULL) {
	return;
    }
    if (familyPtr->refCount-- > 1) {
	return;
    }
    if (familyPtr->encoding) {
	Tcl_FreeEncoding(familyPtr->encoding);
    Tcl_FreeEncoding(familyPtr->encoding);
    }
    for (i = 0; i < FONTMAP_PAGES; i++) {
	if (familyPtr->fontMap[i] != NULL) {
	    ckfree(familyPtr->fontMap[i]);
	}
    }

    /*
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
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







+
+
+
-
-
+
+
+
+
+




-
-
-
-
-
-







    const char *const *aliases;
    char **nameList;
    const char *const *anyFallbacks;
    const char *const *const *fontFallbacks;
    SubFont *subFontPtr;
    Tcl_DString ds;

    if (FontMapLookup(&fontPtr->subFontArray[0], ch)) {
	return &fontPtr->subFontArray[0];
    }
    if (ch < 0 || ch >= FONTMAP_NUMCHARS) {
	ch = 0xFFFD;

    for (i = 1; i < fontPtr->numSubFonts; i++) {
	if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
	    return &fontPtr->subFontArray[i];
	}
    }

    if (FontMapLookup(&fontPtr->controlSubFont, ch)) {
	return &fontPtr->controlSubFont;
    }

    for (i = 0; i < fontPtr->numSubFonts; i++) {
	if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
	    return &fontPtr->subFontArray[i];
	}
    }

    /*
     * Keep track of all face names that we check, so we don't check some name
     * multiple times if it can be reached by multiple paths.
     */

1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
2135
2136
2137
2138
2139
2140
2141



2142
2143
2144
2145
2146
2147
2148







-
-
-







FontMapLookup(
    SubFont *subFontPtr,	/* Contains font mapping cache to be queried
				 * and possibly updated. */
    int ch)			/* Character to be tested. */
{
    int row, bitOffset;

    if (ch < 0 ||  ch >= FONTMAP_NUMCHARS) {
	return 0;
    }
    row = ch >> FONTMAP_SHIFT;
    if (subFontPtr->fontMap[row] == NULL) {
	FontMapLoadPage(subFontPtr, row);
    }
    bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
    return (subFontPtr->fontMap[row][bitOffset >> 3] >> (bitOffset & 7)) & 1;
}
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015






2016
2017
2018
2019
2020
2021
2022
2023
2175
2176
2177
2178
2179
2180
2181







2182
2183
2184
2185
2186
2187

2188
2189
2190
2191
2192
2193
2194







-
-
-
-
-
-
-
+
+
+
+
+
+
-







FontMapInsert(
    SubFont *subFontPtr,	/* Contains font mapping cache to be
				 * updated. */
    int ch)			/* Character to be added to cache. */
{
    int row, bitOffset;

    if (ch >= 0 &&  ch < FONTMAP_NUMCHARS) {
	row = ch >> FONTMAP_SHIFT;
	if (subFontPtr->fontMap[row] == NULL) {
	    FontMapLoadPage(subFontPtr, row);
	}
	bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
	subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
    row = ch >> FONTMAP_SHIFT;
    if (subFontPtr->fontMap[row] == NULL) {
	FontMapLoadPage(subFontPtr, row);
    }
    bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
    subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
    }
}

/*
 *-------------------------------------------------------------------------
 *
 * FontMapLoadPage --
 *
2037
2038
2039
2040
2041
2042
2043
2044

2045
2046
2047
2048
2049
2050

2051
2052
2053

2054
2055
2056
2057
2058
2059
2060
2208
2209
2210
2211
2212
2213
2214

2215
2216
2217
2218
2219
2220

2221
2222
2223

2224
2225
2226
2227
2228
2229
2230
2231







-
+





-
+


-
+







static void
FontMapLoadPage(
    SubFont *subFontPtr,	/* Contains font mapping cache to be
				 * updated. */
    int row)			/* Index of the page to be loaded into the
				 * cache. */
{
    char buf[16], src[6];
    char buf[16], src[4];
    int minHi, maxHi, minLo, maxLo, scale, checkLo;
    int i, end, bitOffset, isTwoByteFont, n;
    Tcl_Encoding encoding;
    XFontStruct *fontStructPtr;
    XCharStruct *widths;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    subFontPtr->fontMap[row] = (char *)ckalloc(FONTMAP_BITSPERPAGE / 8);
    subFontPtr->fontMap[row] = ckalloc(FONTMAP_BITSPERPAGE / 8);
    memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8);

    if (subFontPtr->familyPtr == &tsdPtr->controlFamily) {
	return;
    }

    fontStructPtr = subFontPtr->fontStructPtr;
2076
2077
2078
2079
2080
2081
2082
2083

2084
2085
2086
2087
2088
2089
2090
2247
2248
2249
2250
2251
2252
2253

2254
2255
2256
2257
2258
2259
2260
2261







-
+







    }

    end = (row + 1) << FONTMAP_SHIFT;
    for (i = row << FONTMAP_SHIFT; i < end; i++) {
	int hi, lo;

	if (Tcl_UtfToExternal(NULL, encoding, src, Tcl_UniCharToUtf(i, src),
		TCL_ENCODING_PROFILE_STRICT, NULL, buf, sizeof(buf), NULL,
		TCL_ENCODING_STOPONERROR, NULL, buf, sizeof(buf), NULL,
		NULL, NULL) != TCL_OK) {
	    continue;
	}
	if (isTwoByteFont) {
	    hi = ((unsigned char *) buf)[0];
	    lo = ((unsigned char *) buf)[1];
	} else {
2241
2242
2243
2244
2245
2246
2247
2248

2249
2250
2251
2252
2253
2254
2255
2412
2413
2414
2415
2416
2417
2418

2419
2420
2421
2422
2423
2424
2425
2426







-
+







{
    int i, nameIdx, numNames, srcLen, numEncodings, bestIdx[2];
    Tk_Uid hateFoundry;
    const char *charset, *hateCharset;
    unsigned bestScore[2];
    char **nameList;
    char **nameListOrig;
    char src[6];
    char src[4];
    FontAttributes want, got;
    Display *display;
    SubFont subFont;
    XFontStruct *fontStructPtr;
    Tcl_DString dsEncodings;
    Tcl_Encoding *encodingCachePtr;

2284
2285
2286
2287
2288
2289
2290
2291

2292
2293
2294
2295
2296
2297
2298
2455
2456
2457
2458
2459
2460
2461

2462
2463
2464
2465
2466
2467
2468
2469







-
+







    want.fa.size = (double)-fontPtr->pixelSize;

    hateFoundry = NULL;
    hateCharset = NULL;
    numEncodings = 0;
    Tcl_DStringInit(&dsEncodings);

    charset = NULL;	/* numNames must be > 0 to get here. */
    charset = NULL;	/* lint, since numNames must be > 0 to get here. */

  retry:
    bestIdx[0] = -1;
    bestIdx[1] = -1;
    bestScore[0] = (unsigned) -1;
    bestScore[1] = (unsigned) -1;
    for (nameIdx = 0; nameIdx < numNames; nameIdx++) {
2350
2351
2352
2353
2354
2355
2356
2357

2358
2359
2360
2361
2362
2363
2364
2521
2522
2523
2524
2525
2526
2527

2528
2529
2530
2531
2532
2533
2534
2535







-
+







	    }

	    Tcl_DStringAppend(&dsEncodings, (char *) &encoding,
		    sizeof(encoding));
	    numEncodings++;
	}
	Tcl_UtfToExternal(NULL, encoding, src, srcLen,
		TCL_ENCODING_PROFILE_STRICT, NULL, dst, sizeof(dst), &srcRead,
		TCL_ENCODING_STOPONERROR, NULL, dst, sizeof(dst), &srcRead,
		&dstWrote, NULL);
	if (dstWrote == 0) {
	    goto crossout;
	}

	/*
	 * D. Rank each name and pick the best match.
2378
2379
2380
2381
2382
2383
2384
2385

2386
2387
2388
2389
2390
2391
2392
2549
2550
2551
2552
2553
2554
2555

2556
2557
2558
2559
2560
2561
2562
2563







-
+







    crossout:
	if (nameList == nameListOrig) {
	    /*
	     * Not allowed to change pointers to memory that X gives you, so
	     * make a copy.
	     */

	    nameList = (char **)ckalloc(numNames * sizeof(char *));
	    nameList = ckalloc(numNames * sizeof(char *));
	    memcpy(nameList, nameListOrig, numNames * sizeof(char *));
	}
	nameList[nameIdx] = NULL;
    }

    fontStructPtr = GetScreenFont(display, &want, nameList, bestIdx,
	    bestScore);
2423
2424
2425
2426
2427
2428
2429
2430

2431
2432
2433
2434

2435
2436
2437
2438
2439
2440
2441
2594
2595
2596
2597
2598
2599
2600

2601
2602
2603
2604

2605
2606
2607
2608
2609
2610
2611
2612







-
+



-
+







	ckfree(nameList);
    }
    XFreeFontNames(nameListOrig);

    if (fontPtr->numSubFonts >= SUBFONT_SPACE) {
	SubFont *newPtr;

	newPtr = (SubFont *)ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1));
	newPtr = ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1));
	memcpy(newPtr, fontPtr->subFontArray,
		fontPtr->numSubFonts * sizeof(SubFont));
	if (fixSubFontPtrPtr != NULL) {
	    SubFont *fixSubFontPtr = *fixSubFontPtrPtr;
	    register SubFont *fixSubFontPtr = *fixSubFontPtrPtr;

	    if (fixSubFontPtr != &fontPtr->controlSubFont) {
		*fixSubFontPtrPtr =
			newPtr + (fixSubFontPtr - fontPtr->subFontArray);
	    }
	}
	if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
2557
2558
2559
2560
2561
2562
2563
2564

2565
2566

2567
2568
2569
2570
2571
2572
2573
2728
2729
2730
2731
2732
2733
2734

2735
2736

2737
2738
2739
2740
2741
2742
2743
2744







-
+

-
+








static XFontStruct *
GetScreenFont(
    Display *display,		/* Display for new XFontStruct. */
    FontAttributes *wantPtr,	/* Contains desired actual pixel-size if the
				 * best font was scalable. */
    char **nameList,		/* Array of XLFDs. */
    int bestIdx[],		/* Indices into above array for XLFD of best
    int bestIdx[2],		/* Indices into above array for XLFD of best
				 * bitmapped and best scalable font. */
    unsigned bestScore[])	/* Scores of best bitmapped and best scalable
    unsigned bestScore[2])	/* Scores of best bitmapped and best scalable
				 * font. XLFD corresponding to lowest score
				 * will be constructed. */
{
    XFontStruct *fontStructPtr;

    if ((bestIdx[0] < 0) && (bestIdx[1] < 0)) {
	return NULL;
2596
2597
2598
2599
2600
2601
2602
2603

2604
2605
2606
2607
2608
2609
2610
2767
2768
2769
2770
2771
2772
2773

2774
2775
2776
2777
2778
2779
2780
2781







-
+







	    str = strchr(str + 1, '-');
	}
	rest = str;
	for (i = XLFD_PIXEL_SIZE; i < XLFD_CHARSET; i++) {
	    rest = strchr(rest + 1, '-');
	}
	*str = '\0';
	snprintf(buf, sizeof(buf), "%.200s-%d-*-*-*-*-*%s", nameList[bestIdx[1]],
	sprintf(buf, "%.200s-%d-*-*-*-*-*%s", nameList[bestIdx[1]],
		(int)(-wantPtr->fa.size+0.5), rest);
	*str = '-';
	fontStructPtr = XLoadQueryFont(display, buf);
	bestScore[1] = INT_MAX;
    }
    if (fontStructPtr == NULL) {
	fontStructPtr = XLoadQueryFont(display, nameList[bestIdx[0]]);
2734
2735
2736
2737
2738
2739
2740
2741

2742
2743
2744
2745
2746
2747
2748
2905
2906
2907
2908
2909
2910
2911

2912
2913
2914
2915
2916
2917
2918
2919







-
+







    Display *display,		/* Display to query. */
    const char *faceName,	/* Desired face name, or "*" for all. */
    int *numNamesPtr)		/* Filled with length of returned array, or 0
				 * if no names were found. */
{
    char buf[256];

    snprintf(buf, sizeof(buf), "-*-%.80s-*-*-*-*-*-*-*-*-*-*-*-*", faceName);
    sprintf(buf, "-*-%.80s-*-*-*-*-*-*-*-*-*-*-*-*", faceName);
    return XListFonts(display, buf, 10000, numNamesPtr);
}

static char **
ListFontOrAlias(
    Display *display,		/* Display to query. */
    const char *faceName,	/* Desired face name, or "*" for all. */
2842
2843
2844
2845
2846
2847
2848
2849

2850
2851
2852
2853
2854
2855
2856
3013
3014
3015
3016
3017
3018
3019

3020
3021
3022
3023
3024
3025
3026
3027







-
+







static const char *
GetEncodingAlias(
    const char *name)		/* The name to look up. */
{
    const EncodingAlias *aliasPtr;

    for (aliasPtr = encodingAliases; aliasPtr->aliasPattern != NULL; ) {
	if (Tcl_StringCaseMatch(name, aliasPtr->aliasPattern, 0)) {
	if (Tcl_StringMatch(name, aliasPtr->aliasPattern)) {
	    return aliasPtr->realName;
	}
	aliasPtr++;
    }
    return name;
}

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
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







-
+







-
+




-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
+
+
+
-














-
-
+
+



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+
-


















-
+







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int *realWidthPtr, int *realHeightPtr)
{
    int width, height;
    TkFont *fontPtr = (TkFont *) tkfont;
    Pixmap bitmap;
    GC bitmapGC;
    XGCValues values;
    XImage *image = NULL;
    XImage *image;

    (void) Tk_MeasureChars(tkfont, source, numBytes, -1, 0, &width);
    height = fontPtr->fm.ascent + fontPtr->fm.descent;

    if ((width > 0) && (height > 0)) {
	bitmap = Tk_GetPixmap(display, drawable, width, height, 1);
	values.graphics_exposures = False;
	values.foreground = BlackPixel(display, DefaultScreen(display));
	bitmapGC = XCreateGC(display, bitmap, GCGraphicsExposures|GCForeground,
		&values);
	XFillRectangle(display, bitmap, bitmapGC, 0, 0, width, height);
    bitmap = Tk_GetPixmap(display, drawable, width, height, 1);
    values.graphics_exposures = False;
    values.foreground = BlackPixel(display, DefaultScreen(display));
    bitmapGC = XCreateGC(display, bitmap, GCGraphicsExposures|GCForeground,
	    &values);
    XFillRectangle(display, bitmap, bitmapGC, 0, 0, width, height);

	values.font = Tk_FontId(tkfont);
	values.foreground = WhitePixel(display, DefaultScreen(display));
	values.background = BlackPixel(display, DefaultScreen(display));
	XChangeGC(display, bitmapGC, GCFont|GCForeground|GCBackground, &values);
	Tk_DrawChars(display, bitmap, bitmapGC, tkfont, source, numBytes, 0,
		fontPtr->fm.ascent);
	XFreeGC(display, bitmapGC);
    values.font = Tk_FontId(tkfont);
    values.foreground = WhitePixel(display, DefaultScreen(display));
    values.background = BlackPixel(display, DefaultScreen(display));
    XChangeGC(display, bitmapGC, GCFont|GCForeground|GCBackground, &values);
    Tk_DrawChars(display, bitmap, bitmapGC, tkfont, source, numBytes, 0,
	    fontPtr->fm.ascent);
    XFreeGC(display, bitmapGC);

	image = XGetImage(display, bitmap, 0, 0, width, height, AllPlanes,
		ZPixmap);
	Tk_FreePixmap(display, bitmap);
    image = XGetImage(display, bitmap, 0, 0, width, height, AllPlanes,
	    ZPixmap);
    Tk_FreePixmap(display, bitmap);
    }

    *realWidthPtr = width;
    *realHeightPtr = height;
    return image;
}

static inline XImage *
InitDestImage(
    Display *display,
    Drawable drawable,
    int width,
    int height,
    Pixmap *bitmapPtr)
{
    Pixmap bitmap = None;
    XImage *image = NULL;
    Pixmap bitmap;
    XImage *image;
    GC bitmapGC;
    XGCValues values;

    if ((width > 0) && (height > 0)) {
	bitmap = Tk_GetPixmap(display, drawable, width, height, 1);
	values.graphics_exposures = False;
	values.foreground = BlackPixel(display, DefaultScreen(display));
	bitmapGC = XCreateGC(display, bitmap, GCGraphicsExposures|GCForeground,
		&values);
	XFillRectangle(display, bitmap, bitmapGC, 0, 0, width, height);
	XFreeGC(display, bitmapGC);
    bitmap = Tk_GetPixmap(display, drawable, width, height, 1);
    values.graphics_exposures = False;
    values.foreground = BlackPixel(display, DefaultScreen(display));
    bitmapGC = XCreateGC(display, bitmap, GCGraphicsExposures|GCForeground,
	    &values);
    XFillRectangle(display, bitmap, bitmapGC, 0, 0, width, height);
    XFreeGC(display, bitmapGC);

	image = XGetImage(display, bitmap, 0, 0, width, height, AllPlanes,
		ZPixmap);
    image = XGetImage(display, bitmap, 0, 0, width, height, AllPlanes,
	    ZPixmap);
    }
    *bitmapPtr = bitmap;
    return image;
}

void
TkDrawAngledChars(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn;
				 * must be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    double x, double y,
    double angle)
{
    if (angle == 0.0) {
	Tk_DrawChars(display, drawable, gc, tkfont, source, numBytes, x, y);
    } else {
	double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

Changes to unix/tkUnixInit.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24





-
+










-
+







/*
 * tkUnixInit.c --
 *
 *	This file contains Unix-specific interpreter initialization functions.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkUnixInt.h"

#ifdef HAVE_COREFOUNDATION
static int		GetLibraryPath(Tcl_Interp *interp);
#else
#define GetLibraryPath(dummy)	(void)dummy
#define GetLibraryPath(dummy)	(void)0
#endif /* HAVE_COREFOUNDATION */

/*
 *----------------------------------------------------------------------
 *
 * TkpInit --
 *
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
37
38
39
40
41
42
43



44
45
46
47
48
49
50







-
-
-








int
TkpInit(
    Tcl_Interp *interp)
{
    TkCreateXEventSource();
    GetLibraryPath(interp);
    Tktray_Init(interp);
    (void)SysNotify_Init (interp);
    Icu_Init(interp);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetAppName --
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88







-
+







	name = "tk";
    } else {
	p = strrchr(name, '/');
	if (p != NULL) {
	    name = p+1;
	}
    }
    Tcl_DStringAppend(namePtr, name, TCL_INDEX_NONE);
    Tcl_DStringAppend(namePtr, name, -1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayWarning --
 *
105
106
107
108
109
110
111
112

113
114

115
116
117
118
119
120
121
102
103
104
105
106
107
108

109
110

111
112
113
114
115
116
117
118







-
+

-
+







TkpDisplayWarning(
    const char *msg,		/* Message to be displayed. */
    const char *title)		/* Title of warning. */
{
    Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);

    if (errChannel) {
	Tcl_WriteChars(errChannel, title, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, title, -1);
	Tcl_WriteChars(errChannel, ": ", 2);
	Tcl_WriteChars(errChannel, msg, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, msg, -1);
	Tcl_WriteChars(errChannel, "\n", 1);
    }
}

#ifdef HAVE_COREFOUNDATION

/*
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150




151

152
153
154
155
156
157
158
159
160
161
162







-




+










-

-
-
-
-

-

+









 *
 * Side effects:
 *	Same as for Tcl_MacOSXOpenVersionedBundleResources.
 *
 *----------------------------------------------------------------------
 */

#ifdef TK_FRAMEWORK
static int
GetLibraryPath(
    Tcl_Interp *interp)
{
#ifdef TK_FRAMEWORK
    int foundInFramework = TCL_ERROR;
    char tkLibPath[PATH_MAX + 1];

    foundInFramework = Tcl_MacOSXOpenVersionedBundleResources(interp,
	    "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 0, PATH_MAX,
	    tkLibPath);
    if (tkLibPath[0] != '\0') {
        Tcl_SetVar2(interp, "tk_library", NULL, tkLibPath, TCL_GLOBAL_ONLY);
    }
    return foundInFramework;
}
#else
static int
GetLibraryPath(
    TCL_UNUSED(Tcl_Interp *))
{
    return TCL_ERROR;
}
#endif
}
#endif /* HAVE_COREFOUNDATION */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixInt.h.

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
20
21
22
23
24
25
26



27

28
29
30
31
32
33
34







-
-
-

-







/*
 * Prototypes for procedures that are referenced in files other than the ones
 * they're defined in.
 */

#include "tkIntPlatDecls.h"

MODULE_SCOPE  int       Tktray_Init (Tcl_Interp* interp);
MODULE_SCOPE  int       SysNotify_Init (Tcl_Interp* interp);

#endif /* _TKUNIXINT */


/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:

Changes to unix/tkUnixKey.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18














19
20
21
22
23
24
25
1
2
3
4
5
6

7
8
9
10
11
12
13
14




15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35






-
+







-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







/*
 * tkUnixKey.c --
 *
 *	This file contains routines for dealing with international keyboard
 *	input.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#undef register /* Keyword "register" is used in XKBlib.h, so don't try tricky things here */
#define XkbOpenDisplay XkbOpenDisplay_ /* Move out of the way, conflicting definitions */
#include <X11/XKBlib.h>
#undef XkbOpenDisplay
/*
** Bug [3607830]: Before using Xkb, it must be initialized.  TkpOpenDisplay
**                does this and sets the USE_XKB flag if xkb is supported.
**                (should this be function ptr?)
*/
#ifdef HAVE_XKBKEYCODETOKEYSYM
#  include <X11/XKBlib.h>
#else
#  define XkbKeycodeToKeysym(D,K,G,L) XKeycodeToKeysym(D,K,L)
#endif
#define TkKeycodeToKeysym(D,K,G,L)		\
    ((D)->flags & TK_DISPLAY_USE_XKB) ?		\
      XkbKeycodeToKeysym((D)->display,K,G,L) :	\
      XKeycodeToKeysym((D)->display,K,L)

/*
 * Prototypes for local functions defined in this file:
 */

/*
 *----------------------------------------------------------------------
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131


132
133
134
135
136
137


138
139
140
141
142
143
144
145
146
147


148
149
150
151
152
153
154
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123

124
125
126
127











128
129

130
131
132
133
134
135


136
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
153
154







-
+










-
+



-
-
-
-
-
-
-
-
-
-
-


-
+
+




-
-
+
+








-
-
+
+








const char *
TkpGetString(
    TkWindow *winPtr,		/* Window where event occurred */
    XEvent *eventPtr,		/* X keyboard event. */
    Tcl_DString *dsPtr)		/* Initialized, empty string to hold result. */
{
    Tcl_Size len;
    int len;
    Tcl_DString buf;
    TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr;

    /*
     * If we have the value cached already, use it now. [Bug 1373712]
     */

    if (kePtr->charValuePtr != NULL) {
	Tcl_DStringSetLength(dsPtr, kePtr->charValueLen);
	memcpy(Tcl_DStringValue(dsPtr), kePtr->charValuePtr,
		kePtr->charValueLen+1);
		(unsigned) kePtr->charValueLen+1);
	return Tcl_DStringValue(dsPtr);
    }

    /*
     * Only do this for KeyPress events, otherwise
     * further Xlib function behavior might be undefined.
     */

    if (eventPtr->type != KeyPress) {
	len = 0;
	Tcl_DStringSetLength(dsPtr, len);
	goto done;
    }

#ifdef TK_USE_INPUT_METHODS
    if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM)
	    && (winPtr->inputContext != NULL)) {
	    && (winPtr->inputContext != NULL)
	    && (eventPtr->type == KeyPress)) {
	Status status;

#if X_HAVE_UTF8_STRING
	Tcl_DStringSetLength(dsPtr, TCL_DSTRING_STATIC_SIZE-1);
	len = (Tcl_Size)Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey,
		Tcl_DStringValue(dsPtr), (int)Tcl_DStringLength(dsPtr),
	len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey,
		Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr),
		&kePtr->keysym, &status);

	if (status == XBufferOverflow) {
	    /*
	     * Expand buffer and try again.
	     */

	    Tcl_DStringSetLength(dsPtr, len);
	    len =(Tcl_Size) Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey,
		    Tcl_DStringValue(dsPtr), (int)Tcl_DStringLength(dsPtr),
	    len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey,
		    Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr),
		    &kePtr->keysym, &status);
	}
	if ((status != XLookupChars) && (status != XLookupBoth)) {
	    len = 0;
	}
	Tcl_DStringSetLength(dsPtr, len);
#else /* !X_HAVE_UTF8_STRING */
179
180
181
182
183
184
185
186


187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+
+







-
+







	Tcl_DStringFree(&buf);
#endif /* X_HAVE_UTF8_STRING */
    } else
#endif /* TK_USE_INPUT_METHODS */
    {
	/*
	 * Fall back to convert a keyboard event to a UTF-8 string using
	 * XLookupString. This is used when input methods are turned off.
	 * XLookupString. This is used when input methods are turned off and
	 * for KeyRelease events.
	 *
	 * Note: XLookupString() normally returns a single ISO Latin 1 or
	 * ASCII control character.
	 */

	Tcl_DStringInit(&buf);
	Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1);
	len = (Tcl_Size)XLookupString(&eventPtr->xkey, Tcl_DStringValue(&buf),
	len = XLookupString(&eventPtr->xkey, Tcl_DStringValue(&buf),
		TCL_DSTRING_STATIC_SIZE, &kePtr->keysym, 0);
	Tcl_DStringValue(&buf)[len] = '\0';

	if (len == 1) {
	    len = Tcl_UniCharToUtf((unsigned char) Tcl_DStringValue(&buf)[0],
		    Tcl_DStringValue(dsPtr));
	    Tcl_DStringSetLength(dsPtr, len);
212
213
214
215
216
217
218
219
220

221
222

223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
213
214
215
216
217
218
219


220
221

222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246







-
-
+

-
+





-
+










-
+








    /*
     * Cache the string in the event so that if/when we return to this
     * function, we will be able to produce it without asking X. This stops us
     * from having to reenter the XIM engine. [Bug 1373712]
     */

done:
    kePtr->charValuePtr = (char *)ckalloc(len + 1);
    kePtr->charValuePtr = ckalloc(len + 1);
    kePtr->charValueLen = len;
    memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), len + 1);
    memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), (unsigned) len + 1);
    return Tcl_DStringValue(dsPtr);
}

/*
 * When mapping from a keysym to a keycode, need information about the
 * modifier state to be used so that when they call XbkKeycodeToKeysym taking
 * modifier state to be used so that when they call TkKeycodeToKeysym taking
 * into account the xkey.state, they will get back the original keysym.
 */

void
TkpSetKeycodeAndState(
    Tk_Window tkwin,
    KeySym keySym,
    XEvent *eventPtr)
{
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
    int state, mincode, maxcode;
    int state;
    KeyCode keycode;

    if (keySym == NoSymbol) {
	keycode = 0;
    } else {
	keycode = XKeysymToKeycode(dispPtr->display, keySym);
    }
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
254
255
256
257
258
259
260















261
262
263
264
265
266
267







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		if (state & 2) {
		    eventPtr->xkey.state |= dispPtr->modeModMask;
		}
		break;
	    }
	}
    }

    /*
     * Filter keycodes out of range, otherwise further Xlib function
     * behavior might be undefined, in particular XIM could cause crashes.
     */

    mincode = 0;
    maxcode = -1;
    XDisplayKeycodes(dispPtr->display, &mincode, &maxcode);
    if (keycode < (KeyCode)mincode) {
	keycode = mincode;
    } else if (keycode > (KeyCode)maxcode) {
	keycode = maxcode;
    }

    eventPtr->xkey.keycode = keycode;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetKeySym --
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
285
286
287
288
289
290
291








292
293
294
295
296
297
298







-
-
-
-
-
-
-
-







    TkDisplay *dispPtr,		/* Display in which to map keycode. */
    XEvent *eventPtr)		/* Description of X event. */
{
    KeySym sym;
    int index;
    TkKeyEvent* kePtr = (TkKeyEvent*) eventPtr;

    /*
     * X11 keycodes always lie in the inclusive range [8,255].
     */

    if (eventPtr->xkey.keycode > 0xff) {
        return NoSymbol;
    }

    /*
     * Refresh the mapping information if it's stale. This must happen before
     * we do any input method processing. [Bug 3599312]
     */

    if (dispPtr->bindInfoStale) {
	TkpInitKeymapInfo(dispPtr);
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

380
381

382
383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
332
333
334
335
336
337
338

339
340
341
342
343
344
345
346
347




348
349
350
351

352
353

354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372







-
+








-
-
-
-




-
+

-
+










-
+







	index = 2;
    }
    if ((eventPtr->xkey.state & ShiftMask)
	    || ((dispPtr->lockUsage != LU_IGNORE)
	    && (eventPtr->xkey.state & LockMask))) {
	index += 1;
    }
    sym = XkbKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, 0,
    sym = TkKeycodeToKeysym(dispPtr, eventPtr->xkey.keycode, 0,
	    index);

    /*
     * Special handling: if the key was shifted because of Lock, but lock is
     * only caps lock, not shift lock, and the shifted keysym isn't upper-case
     * alphabetic, then switch back to the unshifted keysym.
     */

#ifndef XK_Oslash
    /* XK_Oslash is the official name, but might not be present in older X11 headers */
#   define XK_Oslash XK_Ooblique
#endif
    if ((index & 1) && !(eventPtr->xkey.state & ShiftMask)
	    && (dispPtr->lockUsage == LU_CAPS)) {
	if (!(((sym >= XK_A) && (sym <= XK_Z))
		|| ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
		|| ((sym >= XK_Oslash) && (sym <= XK_Thorn)))) {
		|| ((sym >= XK_Ooblique) && (sym <= XK_Thorn)))) {
	    index &= ~1;
	    sym = XkbKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
	    sym = TkKeycodeToKeysym(dispPtr, eventPtr->xkey.keycode,
		    0, index);
	}
    }

    /*
     * Another bit of special handling: if this is a shifted key and there is
     * no keysym defined, then use the keysym for the unshifted key.
     */

    if ((index & 1) && (sym == NoSymbol)) {
	sym = XkbKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode,
	sym = TkKeycodeToKeysym(dispPtr, eventPtr->xkey.keycode,
		0, index & ~1);
    }
    return sym;
}

/*
 *--------------------------------------------------------------
417
418
419
420
421
422
423
424

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
390
391
392
393
394
395
396

397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422







-
+
-

















-
+







TkpInitKeymapInfo(
    TkDisplay *dispPtr)		/* Display for which to recompute keymap
				 * information. */
{
    XModifierKeymap *modMapPtr;
    KeyCode *codePtr;
    KeySym keysym;
    int count, i, max;
    int count, i, j, max, arraySize;
    Tcl_Size j, arraySize;
#define KEYCODE_ARRAY_SIZE 20

    dispPtr->bindInfoStale = 0;
    modMapPtr = XGetModifierMapping(dispPtr->display);

    /*
     * Check the keycodes associated with the Lock modifier. If any of them is
     * associated with the XK_Shift_Lock modifier, then Lock has to be
     * interpreted as Shift Lock, not Caps Lock.
     */

    dispPtr->lockUsage = LU_IGNORE;
    codePtr = modMapPtr->modifiermap + modMapPtr->max_keypermod*LockMapIndex;
    for (count = modMapPtr->max_keypermod; count > 0; count--, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}
	keysym = XkbKeycodeToKeysym(dispPtr->display, *codePtr, 0, 0);
	keysym = TkKeycodeToKeysym(dispPtr, *codePtr, 0, 0);
	if (keysym == XK_Shift_Lock) {
	    dispPtr->lockUsage = LU_SHIFT;
	    break;
	}
	if (keysym == XK_Caps_Lock) {
	    dispPtr->lockUsage = LU_CAPS;
	    break;
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
434
435
436
437
438
439
440

441

442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469







-
+
-




















-
+







    dispPtr->altModMask = 0;
    codePtr = modMapPtr->modifiermap;
    max = 8 * modMapPtr->max_keypermod;
    for (i = 0; i < max; i++, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}
	keysym = XkbKeycodeToKeysym(dispPtr->display, *codePtr, 0, 0);
	keysym = TkKeycodeToKeysym(dispPtr, *codePtr, 0, 0);

	if (keysym == XK_Mode_switch) {
	    dispPtr->modeModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Meta_L) || (keysym == XK_Meta_R)) {
	    dispPtr->metaModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Alt_L) || (keysym == XK_Alt_R)) {
	    dispPtr->altModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
    }

    /*
     * Create an array of the keycodes for all modifier keys.
     */

    if (dispPtr->modKeyCodes != NULL) {
	ckfree(dispPtr->modKeyCodes);
    }
    dispPtr->numModKeyCodes = 0;
    arraySize = KEYCODE_ARRAY_SIZE;
    dispPtr->modKeyCodes = (KeyCode *)ckalloc(KEYCODE_ARRAY_SIZE * sizeof(KeyCode));
    dispPtr->modKeyCodes = ckalloc(KEYCODE_ARRAY_SIZE * sizeof(KeyCode));
    for (i = 0, codePtr = modMapPtr->modifiermap; i < max; i++, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}

	/*
	 * Make sure that the keycode isn't already in the array.
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496







-
+







	    KeyCode *newCodes;

	    /*
	     * Ran out of space in the array; grow it.
	     */

	    arraySize *= 2;
	    newCodes = (KeyCode *)ckalloc(arraySize * sizeof(KeyCode));
	    newCodes = ckalloc(arraySize * sizeof(KeyCode));
	    memcpy(newCodes, dispPtr->modKeyCodes,
		    dispPtr->numModKeyCodes * sizeof(KeyCode));
	    ckfree(dispPtr->modKeyCodes);
	    dispPtr->modKeyCodes = newCodes;
	}
	dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr;
	dispPtr->numModKeyCodes++;

Changes to unix/tkUnixMenu.c.

1
2
3
4
5
6

7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19





-
+





+







/*
 * tkUnixMenu.c --
 *
 *	This module implements the UNIX platform-specific features of menus.
 *
 * Copyright © 1996-1998 Sun Microsystems, Inc.
 * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "default.h"
#include "tkUnixInt.h"
#include "tkMenu.h"

/*
 * Constants used for menu drawing.
 */

47
48
49
50
51
52
53
54
55


56
57
58
59
60
61
62
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63







-
-
+
+







 * Procedures used internally.
 */

static void		SetHelpMenu(TkMenu *menuPtr);
static void		DrawMenuEntryAccelerator(TkMenu *menuPtr,
			    TkMenuEntry *mePtr, Drawable d, GC gc,
			    Tk_Font tkfont, const Tk_FontMetrics *fmPtr,
			    Tk_3DBorder activeBorder, Tk_3DBorder bgBorder,
			    int x, int y, int width, int height, int drawArrow);
			    Tk_3DBorder activeBorder, int x, int y,
			    int width, int height, int drawArrow);
static void		DrawMenuEntryBackground(TkMenu *menuPtr,
			    TkMenuEntry *mePtr, Drawable d,
			    Tk_3DBorder activeBorder, Tk_3DBorder bgBorder,
			    int x, int y, int width, int heigth);
static void		DrawMenuEntryIndicator(TkMenu *menuPtr,
			    TkMenuEntry *mePtr, Drawable d,
			    Tk_3DBorder border, XColor *indicatorColor,
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155







-
+







 *	All platform-specific allocations are freed up.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyMenu(
    TCL_UNUSED(TkMenu *))
    TkMenu *menuPtr)
{
    /*
     * Nothing to do.
     */
}

/*
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181







-
+







 *	All platform specific allocations are freed up.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyMenuEntry(
    TCL_UNUSED(TkMenuEntry *))
    TkMenuEntry *mEntryPtr)
{
    /*
     * Nothing to do.
     */
}

/*
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209







-
+







 *	if any need it.
 *
 *----------------------------------------------------------------------
 */

int
TkpConfigureMenuEntry(
    TkMenuEntry *mePtr)/* Information about menu entry; may or may
    register TkMenuEntry *mePtr)/* Information about menu entry; may or may
				 * not already have values for some fields. */
{
    /*
     * If this is a cascade menu, and the child menu exists, check to see if
     * the child menu is a help menu.
     */

234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249







-
+







 *	None on Unix.
 *
 *----------------------------------------------------------------------
 */

int
TkpMenuNewEntry(
    TCL_UNUSED(TkMenuEntry *))
    TkMenuEntry *mePtr)
{
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
286
287
288
289
290
291
292
293
294
295
296




297
298
299
300
301
302
303
287
288
289
290
291
292
293




294
295
296
297
298
299
300
301
302
303
304







-
-
-
-
+
+
+
+







 * Side effects:
 *	Recompute geometry of given window.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetMainMenubar(
    TCL_UNUSED(Tcl_Interp *),
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(const char *))
TkpSetMainMenubar(
    Tcl_Interp *interp,
    Tk_Window tkwin,
    const char *menuName)
{
    /*
     * Nothing to do.
     */
}

/*
316
317
318
319
320
321
322
323
324
325
326
327
328






329
330
331
332
333
334
335
317
318
319
320
321
322
323






324
325
326
327
328
329
330
331
332
333
334
335
336







-
-
-
-
-
-
+
+
+
+
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
GetMenuIndicatorGeometry(
    TkMenu *menuPtr,			/* The menu we are drawing. */
    TkMenuEntry *mePtr,			/* The entry we are interested in. */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    TCL_UNUSED(const Tk_FontMetrics *),	/* The precalculated metrics */
    int *widthPtr,			/* The resulting width */
    int *heightPtr)			/* The resulting height */
    TkMenu *menuPtr,		/* The menu we are drawing. */
    TkMenuEntry *mePtr,		/* The entry we are interested in. */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    int borderWidth;

    if ((mePtr->type == CHECK_BUTTON_ENTRY)
	    || (mePtr->type == RADIO_BUTTON_ENTRY)) {
	if (!mePtr->hideMargin && mePtr->indicatorOn) {
	    if ((mePtr->image != NULL) || (mePtr->bitmapPtr != NULL)) {
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
388
389
390
391
392
393
394


395
396

397
398
399
400
401
402
403
404







-
-


-
+







    TkMenu *menuPtr,		/* The menu was are drawing */
    TkMenuEntry *mePtr,		/* The entry we are getting the geometry for */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int *widthPtr,		/* The width of the acclerator area */
    int *heightPtr)		/* The height of the accelerator area */
{
    double scalingLevel = TkScalingLevel(menuPtr->tkwin);

    *heightPtr = fmPtr->linespace;
    if (mePtr->type == CASCADE_ENTRY) {
    	*widthPtr = 2 * CASCADE_ARROW_WIDTH * scalingLevel;
    	*widthPtr = 2 * CASCADE_ARROW_WIDTH;
    } else if ((menuPtr->menuType != MENUBAR) && (mePtr->accelPtr != NULL)) {
	const char *accel = Tcl_GetString(mePtr->accelPtr);

	*widthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
    } else {
    	*widthPtr = 0;
    }
440
441
442
443
444
445
446
447

448

449
450
451
452
453
454
455
439
440
441
442
443
444
445

446
447
448
449
450
451
452
453
454
455







-
+

+







    	bgBorder = activeBorder;

	if ((menuPtr->menuType == MENUBAR)
		&& ((menuPtr->postedCascade == NULL)
		|| (menuPtr->postedCascade != mePtr))) {
	    relief = TK_RELIEF_FLAT;
	} else {
	    Tk_GetReliefFromObj(NULL, menuPtr->activeReliefPtr, &relief);
	    relief = TK_RELIEF_RAISED;
	}

	Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
		menuPtr->activeBorderWidthPtr, &activeBorderWidth);
	Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height,
		activeBorderWidth, relief);
    } else {
	Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height,
		0, TK_RELIEF_FLAT);
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513



514
515
516
517
518




519
520
521
522



523
524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491


492
493
494
495
496
497
498
499
500
501
502
503
504
505





506
507
508
509




510
511
512
513




514
515
516
517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
532







-








-
-














-
-
-
-
-
+
+
+

-
-
-
-
+
+
+
+
-
-
-
-
+
+
+








-
+







    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* The drawable we are drawing into */
    GC gc,			/* The precalculated gc to draw with */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated metrics */
    Tk_3DBorder activeBorder,	/* The border for an active item */
    Tk_3DBorder bgBorder,	/* The background border */
    int x,			/* Left coordinate of entry rect */
    int y,			/* Top coordinate of entry rect */
    int width,			/* Width of entry */
    int height,			/* Height of entry */
    int drawArrow)		/* Whether or not to draw arrow. */
{
    XPoint points[3];
    int borderWidth, activeBorderWidth;
    int arrowWidth = CASCADE_ARROW_WIDTH, arrowHeight = CASCADE_ARROW_HEIGHT;
    double scalingLevel = TkScalingLevel(menuPtr->tkwin);

    /*
     * Draw accelerator or cascade arrow.
     */

    if (menuPtr->menuType == MENUBAR) {
	return;
    }

    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
	    &borderWidth);
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
	    &activeBorderWidth);
    if ((mePtr->type == CASCADE_ENTRY) && drawArrow) {
	arrowWidth *= scalingLevel;
	arrowHeight *= scalingLevel;

    	points[0].x = x + width - borderWidth - activeBorderWidth - arrowWidth;
    	points[0].y = y + (height - arrowHeight)/2;
    	points[0].x = x + width - borderWidth - activeBorderWidth
		- CASCADE_ARROW_WIDTH;
    	points[0].y = y + (height - CASCADE_ARROW_HEIGHT)/2;
    	points[1].x = points[0].x;
    	points[1].y = points[0].y + arrowHeight;
    	points[2].x = points[0].x + arrowWidth;
    	points[2].y = points[0].y + arrowHeight/2;
    	Tk_Fill3DPolygon(menuPtr->tkwin, d,
    	points[1].y = points[0].y + CASCADE_ARROW_HEIGHT;
    	points[2].x = points[0].x + CASCADE_ARROW_WIDTH;
    	points[2].y = points[0].y + CASCADE_ARROW_HEIGHT/2;
    	Tk_Fill3DPolygon(menuPtr->tkwin, d, activeBorder, points, 3,
		(mePtr->state == ENTRY_ACTIVE) ? activeBorder : bgBorder,
		points, 3, DECORATION_BORDER_WIDTH,
	    	(menuPtr->postedCascade == mePtr) ?
		TK_RELIEF_SUNKEN : TK_RELIEF_RAISED);
		DECORATION_BORDER_WIDTH,
	    	(menuPtr->postedCascade == mePtr)
	    	? TK_RELIEF_SUNKEN : TK_RELIEF_RAISED);
    } else if (mePtr->accelPtr != NULL) {
	const char *accel = Tcl_GetString(mePtr->accelPtr);
	int left = x + mePtr->labelWidth + activeBorderWidth
		+ mePtr->indicatorSpace;

	if (menuPtr->menuType == MENUBAR) {
	    left += 5;
	}
	Tk_DrawChars(menuPtr->display, d, gc, tkfont, accel,
    	Tk_DrawChars(menuPtr->display, d, gc, tkfont, accel,
		mePtr->accelLength, left,
		(y + (height + fmPtr->ascent - fmPtr->descent) / 2));
    }
}

/*
 *----------------------------------------------------------------------
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566












567
568
569
570
571
572
573
542
543
544
545
546
547
548












549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







 *	Commands are output to X to display the menu in its current mode.
 *
 *----------------------------------------------------------------------
 */

static void
DrawMenuEntryIndicator(
    TkMenu *menuPtr,			/* The menu we are drawing */
    TkMenuEntry *mePtr,			/* The entry we are drawing */
    Drawable d,				/* The drawable to draw into */
    Tk_3DBorder border,			/* The background color */
    XColor *indicatorColor,		/* The color to draw indicators with */
    XColor *disableColor,		/* The color use use when disabled */
    TCL_UNUSED(Tk_Font),		/* The font to draw with */
    TCL_UNUSED(const Tk_FontMetrics *),	/* The font metrics of the font */
    int x,				/* The left of the entry rect */
    int y,				/* The top of the entry rect */
    TCL_UNUSED(int),			/* Width of menu entry */
    int height)				/* Height of menu entry */
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* The drawable to draw into */
    Tk_3DBorder border,		/* The background color */
    XColor *indicatorColor,	/* The color to draw indicators with */
    XColor *disableColor,	/* The color use use when disabled */
    Tk_Font tkfont,		/* The font to draw with */
    const Tk_FontMetrics *fmPtr,/* The font metrics of the font */
    int x,			/* The left of the entry rect */
    int y,			/* The top of the entry rect */
    int width,			/* Width of menu entry */
    int height)			/* Height of menu entry */
{
    /*
     * Draw check-button indicator.
     */

    if ((mePtr->type == CHECK_BUTTON_ENTRY) && mePtr->indicatorOn) {
	int top, left, activeBorderWidth;
622
623
624
625
626
627
628
629
630
631
632
633
634






635
636
637
638
639

640
641
642
643
644
645
646

647
648
649
650
651
652
653
616
617
618
619
620
621
622






623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648







-
-
-
-
-
-
+
+
+
+
+
+





+






-
+







 *	Commands are output to X to display the menu in its current mode.
 *
 *----------------------------------------------------------------------
 */

static void
DrawMenuSeparator(
    TkMenu *menuPtr,			/* The menu we are drawing */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are drawing */
    Drawable d,				/* The drawable we are using */
    TCL_UNUSED(GC),			/* The gc to draw into */
    TCL_UNUSED(Tk_Font),		/* The font to draw with */
    TCL_UNUSED(const Tk_FontMetrics *),	/* The font metrics from the font */
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* The drawable we are using */
    GC gc,			/* The gc to draw into */
    Tk_Font tkfont,		/* The font to draw with */
    const Tk_FontMetrics *fmPtr,/* The font metrics from the font */
    int x, int y,
    int width, int height)
{
    XPoint points[2];
    Tk_3DBorder border;

    if (menuPtr->menuType == MENUBAR) {
	return;
    }

    points[0].x = x;
    points[0].y = y + height/2;
    points[1].x = x + width - 1;
    points[1].x = width - 1;
    points[1].y = points[0].y;
    border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);
    Tk_Draw3DPolygon(menuPtr->tkwin, d, border, points, 2, 1,
	    TK_RELIEF_RAISED);
}

/*
789
790
791
792
793
794
795
796

797
798
799
800
801
802
803
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798







-
+







		    imageWidth, imageHeight, d, leftEdge + imageXOffset,
		    (int) (y + (mePtr->height-imageHeight)/2 + imageYOffset));
    	} else {
	    Tk_RedrawImage(mePtr->image, 0, 0, imageWidth,
		    imageHeight, d, leftEdge + imageXOffset,
		    (int) (y + (mePtr->height-imageHeight)/2 + imageYOffset));
    	}
    } else if (mePtr->bitmapPtr != NULL) {
    } else if (mePtr->bitmapPtr != None) {
	Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);

	XCopyPlane(menuPtr->display, bitmap, d,	gc, 0, 0,
		(unsigned) imageWidth, (unsigned) imageHeight,
		leftEdge + imageXOffset,
		(int) (y + (mePtr->height - imageHeight)/2 + imageYOffset), 1);
    }
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826







-
+







    }

    if (mePtr->state == ENTRY_DISABLED) {
	if (menuPtr->disabledFgPtr == NULL) {
	    XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,
		    (unsigned) width, (unsigned) height);
	} else if ((mePtr->image != NULL)
		&& (menuPtr->disabledImageGC != NULL)) {
		&& (menuPtr->disabledImageGC != None)) {
	    XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
		    leftEdge + imageXOffset,
		    (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset),
		    (unsigned) imageWidth, (unsigned) imageHeight);
	}
    }
}
851
852
853
854
855
856
857
858

859
860

861
862




863
864
865



866
867
868
869
870


871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909

910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037






1038
1039
1040
1041
1042
1043
1044
846
847
848
849
850
851
852

853
854

855
856
857
858
859
860
861



862
863
864
865
866
867


868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889

890



891
892
893
894
895
896
897
898
899
900
901
902
903
904

905
906

907




































































































908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927






928
929
930
931
932
933
934
935
936
937
938
939
940







-
+

-
+


+
+
+
+
-
-
-
+
+
+



-
-
+
+




















-
+
-
-
-














-
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
-
-
-
-
-
+
+
+
+
+
+







    TkMenu *menuPtr,		/* The menu to draw into */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    GC gc,			/* The gc to draw into */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int x, int y,
    TCL_UNUSED(int), int height)
    int width, int height)
{
    if (mePtr->labelPtr != NULL) {
    if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
	int len;

	/*
	 * Do the unicode call just to prevent overruns.
	 */

	len = Tcl_GetCharLength(mePtr->labelPtr);
	if (mePtr->underline < len && mePtr->underline >= -len) {
	    int activeBorderWidth, leftEdge, ch;
	Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
	if (mePtr->underline < len) {
	    int activeBorderWidth, leftEdge;
	    const char *label, *start, *end;

	    label = Tcl_GetString(mePtr->labelPtr);
	    start = Tcl_UtfAtIndex(label, (mePtr->underline < 0) ? mePtr->underline + len : mePtr->underline);
	    end = start + Tcl_UtfToUniChar(start, &ch);
	    start = Tcl_UtfAtIndex(label, mePtr->underline);
	    end = Tcl_UtfNext(start);

	    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
		    menuPtr->activeBorderWidthPtr, &activeBorderWidth);
	    leftEdge = x + mePtr->indicatorSpace + activeBorderWidth;
	    if (menuPtr->menuType == MENUBAR) {
		leftEdge += 5;
	    }

	    Tk_UnderlineChars(menuPtr->display, d, gc, tkfont, label, leftEdge,
		    y + (height + fmPtr->ascent - fmPtr->descent) / 2,
		    start - label, end - label);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostMenu --
 *
 *	Posts a menu on the screen so that the top left corner of the
 *	Posts a menu on the screen
 *      specified entry is located at the point (x, y) in screen coordinates.
 *      If the entry parameter is negative, the upper left corner of the
 *      menu itself is placed at the point.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The menu is posted and handled.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostMenu(
    Tcl_Interp *interp,
    TkMenu *menuPtr,
    int x, int y, Tcl_Size index)
    int x, int y)
{
    return TkpPostTearoffMenu(interp, menuPtr, x, y, index);
    return TkPostTearoffMenu(interp, menuPtr, x, y);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostTearoffMenu --
 *
 *	Posts a tearoff menu on the screen so that the top left corner of the
 *      specified entry is located at the point (x, y) in screen coordinates.
 *      If the index parameter is negative, the upper left corner of the menu
 *      itself is placed at the point.  On unix this is called when posting
 *      any menu.  Adjusts the menu's position so that it fits on the screen,
 *      and maps and raises the menu.
 *
 * Results:
 *	Returns a standard Tcl Error.
 *
 * Side effects:
 *	The menu is posted.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostTearoffMenu(
    TCL_UNUSED(Tcl_Interp *),	/* The interpreter of the menu */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y, Tcl_Size index)	/* The root X,Y coordinates where the
				 * specified entry will be posted */
{
    int vRootX, vRootY, vRootWidth, vRootHeight;
    int result;

    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }

    /*
     * The post commands could have deleted the menu, which means we are dead
     * and should go away.
     */

    if (menuPtr->tkwin == NULL) {
    	return TCL_OK;
    }

    /*
     * Adjust the menu y position so that the specified entry will be located
     * at the given coordinates.
     */

    if (index >= menuPtr->numEntries) {
	index = menuPtr->numEntries - 1;
    }
    if (index >= 0) {
	y -= menuPtr->entries[index]->y;
    }

    /*
     * Adjust the position of the menu if necessary to keep it visible on the
     * screen. There are two special tricks to make this work right:
     *
     * 1. If a virtual root window manager is being used then the coordinates
     *    are in the virtual root window of menuPtr's parent; since the menu
     *    uses override-redirect mode it will be in the *real* root window for
     *    the screen, so we have to map the coordinates from the virtual root
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.
     */

    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);
    vRootWidth -= Tk_ReqWidth(menuPtr->tkwin);
    if (x > vRootX + vRootWidth) {
	x = vRootX + vRootWidth;
    }
    if (x < vRootX) {
	x = vRootX;
    }
    vRootHeight -= Tk_ReqHeight(menuPtr->tkwin);
    if (y > vRootY + vRootHeight) {
	y = vRootY + vRootHeight;
    }
    if (y < vRootY) {
	y = vRootY;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GetMenuSeparatorGeometry --
 *
 *	Gets the width and height of the indicator area of a menu.
 *
 * Results:
 *	widthPtr and heightPtr are set.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
GetMenuSeparatorGeometry(
    TCL_UNUSED(TkMenu *),		/* The menu we are measuring */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are measuring */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,	/* The precalcualted font metrics */
    int *widthPtr,			/* The resulting width */
    int *heightPtr)			/* The resulting height */
    TkMenu *menuPtr,		/* The menu we are measuring */
    TkMenuEntry *mePtr,		/* The entry we are measuring */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalcualted font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    *widthPtr = 0;
    *heightPtr = fmPtr->linespace;
}

/*
 *----------------------------------------------------------------------
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066






1067
1068

1069
1070
1071
1072
1073
1074
1075
950
951
952
953
954
955
956






957
958
959
960
961
962
963

964
965
966
967
968
969
970
971







-
-
-
-
-
-
+
+
+
+
+
+

-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
GetTearoffEntryGeometry(
    TkMenu *menuPtr,			/* The menu we are drawing */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are measuring */
    Tk_Font tkfont,			/* The precalculated font */
    const Tk_FontMetrics *fmPtr,	/* The precalculated font metrics */
    int *widthPtr,			/* The resulting width */
    int *heightPtr)			/* The resulting height */
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are measuring */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    if (menuPtr->menuType != MAIN_MENU) {
    if (menuPtr->menuType != MASTER_MENU) {
	*heightPtr = 0;
	*widthPtr = 0;
    } else {
	*heightPtr = fmPtr->linespace;
	*widthPtr = Tk_TextWidth(tkfont, "W", 1);
    }
}
1094
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104


1105
1106
1107
1108
1109
1110


1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
990
991
992
993
994
995
996

997



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036







-
+
-
-
-
+
+






+
+










-
+










-
+








void
TkpComputeMenubarGeometry(
    TkMenu *menuPtr)		/* Structure describing menu. */
{
    Tk_Font tkfont, menuFont;
    Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
    int width, height, x, y, currentRowHeight, maxWidth;
    int width, height, i, j, x, y, currentRowHeight, maxWidth;
    Tcl_Size i, j, lastRowBreak;
    int maxWindowWidth, lastEntry;
    int activeBorderWidth, helpMenuIndex = -1;
    int maxWindowWidth, lastRowBreak, lastEntry;
    int borderWidth, activeBorderWidth, helpMenuIndex = -1;
    TkMenuEntry *mePtr;

    if (menuPtr->tkwin == NULL) {
	return;
    }

    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
	    &borderWidth);
    Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
	    &activeBorderWidth);
    maxWidth = 0;
    if (menuPtr->numEntries == 0) {
	height = 0;
    } else {
	int borderWidth;

	maxWindowWidth = Tk_Width(menuPtr->tkwin);
	if (maxWindowWidth == 1) {
	    maxWindowWidth = 0x7FFFFFF;
	    maxWindowWidth = 0x7ffffff;
	}
	currentRowHeight = 0;
	Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
		&borderWidth);
	x = y = borderWidth;
	lastRowBreak = 0;

	/*
	 * On the Mac especially, getting font metrics can be quite slow, so
	 * we want to do it intelligently. We are going to precalculate them
	 * and pass them down to all of the measuring and drawing routines.
	 * and pass them down to all of the measureing and drawing routines.
	 * We will measure the font metrics of the menu once, and if an entry
	 * has a font set, we will measure it as we come to it, and then we
	 * decide which set to give the geometry routines.
	 */

	menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
	Tk_GetFontMetrics(menuFont, &menuMetrics);
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283






1284
1285
1286
1287
1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298
1299

1300
1301
1302
1303
1304
1305
1306
1168
1169
1170
1171
1172
1173
1174






1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203







-
-
-
-
-
-
+
+
+
+
+
+







-
+







-
+







 *	Commands are output to X to display the menu in its current mode.
 *
 *----------------------------------------------------------------------
 */

static void
DrawTearoffEntry(
    TkMenu *menuPtr,			/* The menu we are drawing */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are drawing */
    Drawable d,				/* The drawable we are drawing into */
    TCL_UNUSED(GC),			/* The gc we are drawing with */
    TCL_UNUSED(Tk_Font),		/* The font we are drawing with */
    TCL_UNUSED(const Tk_FontMetrics *),	/* The metrics we are drawing with */
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* The drawable we are drawing into */
    GC gc,			/* The gc we are drawing with */
    Tk_Font tkfont,		/* The font we are drawing with */
    const Tk_FontMetrics *fmPtr,/* The metrics we are drawing with */
    int x, int y,
    int width, int height)
{
    XPoint points[2];
    int segmentWidth, maxX;
    Tk_3DBorder border;

    if (menuPtr->menuType != MAIN_MENU) {
    if (menuPtr->menuType != MASTER_MENU) {
	return;
    }

    points[0].x = x;
    points[0].y = y + height/2;
    points[1].y = points[0].y;
    segmentWidth = 6;
    maxX = x + width - 1;
    maxX = width - 1;
    border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);

    while (points[0].x < maxX) {
	points[1].x = points[0].x + segmentWidth;
	if (points[1].x > maxX) {
	    points[1].x = maxX;
	}
1327
1328
1329
1330
1331
1332
1333
1334
1335



1336
1337
1338
1339
1340
1341
1342
1224
1225
1226
1227
1228
1229
1230


1231
1232
1233
1234
1235
1236
1237
1238
1239
1240







-
-
+
+
+







 *	Alt-key bindings.
 *
 *--------------------------------------------------------------
 */

void
TkpInitializeMenuBindings(
    TCL_UNUSED(Tcl_Interp *),		/* The interpreter to set. */
    TCL_UNUSED(Tk_BindingTable))	/* The table to add to. */
    Tcl_Interp *interp,		/* The interpreter to set. */
    Tk_BindingTable bindingTable)
				/* The table to add to. */
{
    /*
     * Nothing to do.
     */
}

/*
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386





1387
1388

1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
1273
1274
1275
1276
1277
1278
1279





1280
1281
1282
1283
1284
1285

1286
1287
1288

1289
1290
1291
1292
1293
1294
1295
1296







-
-
-
-
-
+
+
+
+
+

-
+


-
+







	return;
    }

    for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;
	    cascadeEntryPtr != NULL;
	    cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {
	if ((cascadeEntryPtr->menuPtr->menuType == MENUBAR)
		&& (cascadeEntryPtr->menuPtr->mainMenuPtr->tkwin != NULL)
		&& (menuPtr->mainMenuPtr->tkwin != NULL)) {
	    TkMenu *mainMenuPtr = cascadeEntryPtr->menuPtr->mainMenuPtr;
	    char *helpMenuName = (char *)ckalloc(strlen(Tk_PathName(
		    mainMenuPtr->tkwin)) + strlen(".help") + 1);
		&& (cascadeEntryPtr->menuPtr->masterMenuPtr->tkwin != NULL)
		&& (menuPtr->masterMenuPtr->tkwin != NULL)) {
	    TkMenu *masterMenuPtr = cascadeEntryPtr->menuPtr->masterMenuPtr;
	    char *helpMenuName = ckalloc(strlen(Tk_PathName(
		    masterMenuPtr->tkwin)) + strlen(".help") + 1);

	    strcpy(helpMenuName, Tk_PathName(mainMenuPtr->tkwin));
	    strcpy(helpMenuName, Tk_PathName(masterMenuPtr->tkwin));
	    strcat(helpMenuName, ".help");
	    if (strcmp(helpMenuName,
		    Tk_PathName(menuPtr->mainMenuPtr->tkwin)) == 0) {
		    Tk_PathName(menuPtr->masterMenuPtr->tkwin)) == 0) {
		cascadeEntryPtr->entryFlags |= ENTRY_HELP_MENU;
	    } else {
		cascadeEntryPtr->entryFlags &= ~ENTRY_HELP_MENU;
	    }
	    ckfree(helpMenuName);
	}
    }
1424
1425
1426
1427
1428
1429
1430
1431


1432
1433
1434
1435
1436
1437
1438
1322
1323
1324
1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1336
1337







-
+
+







				/* Precalculated metrics for menu */
    int x,			/* X-coordinate of topleft of entry */
    int y,			/* Y-coordinate of topleft of entry */
    int width,			/* Width of the entry rectangle */
    int height,			/* Height of the current rectangle */
    int strictMotif,		/* Boolean flag */
    int drawArrow)		/* Whether or not to draw the cascade arrow
				 * for cascade items. */
				 * for cascade items. Only applies to
				 * Windows. */
{
    GC gc, indicatorGC;
    XColor *indicatorColor, *disableColor = NULL;
    TkMenu *menuPtr = mePtr->menuPtr;
    Tk_3DBorder bgBorder, activeBorder;
    const Tk_FontMetrics *fmPtr;
    Tk_FontMetrics entryMetrics;
1532
1533
1534
1535
1536
1537
1538
1539

1540
1541
1542
1543
1544
1545
1546
1547
1431
1432
1433
1434
1435
1436
1437

1438

1439
1440
1441
1442
1443
1444
1445







-
+
-







    } else if (mePtr->type == TEAROFF_ENTRY) {
	DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
		width, adjustedHeight);
    } else {
	DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,
		width, adjustedHeight);
	DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr,
		activeBorder, bgBorder, x, adjustedY, width, adjustedHeight,
		activeBorder, x, adjustedY, width, adjustedHeight, drawArrow);
		drawArrow);
	if (!mePtr->hideMargin) {
	    if (mePtr->state == ENTRY_ACTIVE) {
		bgBorder = activeBorder;
	    }
	    DrawMenuEntryIndicator(menuPtr, mePtr, d, bgBorder, indicatorColor,
		    disableColor, tkfont, fmPtr, x, adjustedY, width,
		    adjustedHeight);
1682
1683
1684
1685
1686
1687
1688
1689

1690
1691
1692
1693
1694
1695
1696
1697
1580
1581
1582
1583
1584
1585
1586

1587

1588
1589
1590
1591
1592
1593
1594







-
+
-







void
TkpComputeStandardMenuGeometry(
    TkMenu *menuPtr)		/* Structure describing menu. */
{
    Tk_Font tkfont, menuFont;
    Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
    int x, y, height, width, indicatorSpace, labelWidth, accelWidth;
    int windowWidth, windowHeight, accelSpace;
    int windowWidth, windowHeight, accelSpace, i, j, lastColumnBreak = 0;
    Tcl_Size i, j, lastColumnBreak = 0;
    TkMenuEntry *mePtr;
    int borderWidth, activeBorderWidth;

    if (menuPtr->tkwin == NULL) {
	return;
    }

1817
1818
1819
1820
1821
1822
1823
1824


1825
1826
1827
1828
1829
1830
1831
1714
1715
1716
1717
1718
1719
1720

1721
1722
1723
1724
1725
1726
1727
1728
1729







-
+
+







	menuPtr->entries[j]->labelWidth = labelWidth;
	menuPtr->entries[j]->width = indicatorSpace + labelWidth
		+ accelWidth + 2 * activeBorderWidth;
	menuPtr->entries[j]->x = x;
	menuPtr->entries[j]->entryFlags |= ENTRY_LAST_COLUMN;
    }
    windowWidth = x + indicatorSpace + labelWidth + accelWidth
	    + 2 * activeBorderWidth + borderWidth;
	    + 2 * activeBorderWidth + 2 * borderWidth;

    windowHeight += borderWidth;

    /*
     * The X server doesn't like zero dimensions, so round up to at least 1 (a
     * zero-sized menu should never really occur, anyway).
     */

1855
1856
1857
1858
1859
1860
1861
1862
1863


1864
1865
1866
1867
1868
1869
1870
1753
1754
1755
1756
1757
1758
1759


1760
1761
1762
1763
1764
1765
1766
1767
1768







-
-
+
+







 *	An idle handler is set up to do the reconfiguration.
 *
 *----------------------------------------------------------------------
 */

void
TkpMenuNotifyToplevelCreate(
    TCL_UNUSED(Tcl_Interp *),	/* The interp the menu lives in. */
    TCL_UNUSED(const char *))	/* The name of the menu to reconfigure. */
    Tcl_Interp *interp,		/* The interp the menu lives in. */
    const char *menuName)	/* The name of the menu to reconfigure. */
{
    /*
     * Nothing to do.
     */
}

/*

Changes to unix/tkUnixMenubu.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35

36
37

38
39
40
41
42
43
44
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34

35
36

37
38
39
40
41
42
43
44






-
+




















-
+






-
+

-
+







/*
 * tkUnixMenubu.c --
 *
 *	This file implements the Unix specific portion of the menubutton
 *	widget.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkMenubutton.h"


/*
 *----------------------------------------------------------------------
 *
 * TkpCreateMenuButton --
 *
 *	Allocate a new TkMenuButton structure.
 *
 * Results:
 *	Returns a newly allocated TkMenuButton structure.
 *
 * Side effects:
 *	None
 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkMenuButton *
TkpCreateMenuButton(
    TCL_UNUSED(Tk_Window))
    Tk_Window tkwin)
{
    return (TkMenuButton *)ckalloc(sizeof(TkMenuButton));
    return ckalloc(sizeof(TkMenuButton));
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayMenuButton --
 *
52
53
54
55
56
57
58
59

60
61

62
63
64
65
66
67
68

69
70
71
72
73
74
75
52
53
54
55
56
57
58

59
60

61
62
63
64
65
66
67

68
69
70
71
72
73
74
75







-
+

-
+






-
+







 *	mode.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayMenuButton(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkMenuButton *mbPtr = (TkMenuButton *)clientData;
    register TkMenuButton *mbPtr = (TkMenuButton *) clientData;
    GC gc;
    Tk_3DBorder border;
    Pixmap pixmap;
    int x = 0;			/* Initialization needed only to stop compiler
				 * warning. */
    int y = 0;
    Tk_Window tkwin = mbPtr->tkwin;
    register Tk_Window tkwin = mbPtr->tkwin;
    int fullWidth, fullHeight;
    int textXOffset, textYOffset;
    int imageWidth, imageHeight;
    int imageXOffset, imageYOffset;
    int width = 0, height = 0;
				/* Image information that will be used to
				 * restrict disabled pixmap as well */
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102







-
+







	gc = mbPtr->activeTextGC;
	border = mbPtr->activeBorder;
    } else {
	gc = mbPtr->normalTextGC;
	border = mbPtr->normalBorder;
    }

    if (mbPtr->image != NULL) {
    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }
    imageWidth	= width;
276
277
278
279
280
281
282


283
284
285
286
287
288
289
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291







+
+







	Tk_Draw3DRectangle(tkwin, pixmap, border,
		mbPtr->highlightWidth, mbPtr->highlightWidth,
		Tk_Width(tkwin) - 2*mbPtr->highlightWidth,
		Tk_Height(tkwin) - 2*mbPtr->highlightWidth,
		mbPtr->borderWidth, mbPtr->relief);
    }
    if (mbPtr->highlightWidth != 0) {
	GC gc;

	if (mbPtr->flags & GOT_FOCUS) {
	    gc = Tk_GCForColor(mbPtr->highlightColorPtr, pixmap);
	} else {
	    gc = Tk_GCForColor(mbPtr->highlightBgColorPtr, pixmap);
	}
	Tk_DrawFocusHighlight(tkwin, gc, mbPtr->highlightWidth, pixmap);
    }
313
314
315
316
317
318
319
320

321
322
323
324
325
326
327
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329







-
+







 *	Restores the default control state.
 *
 *----------------------------------------------------------------------
 */

void
TkpDestroyMenuButton(
    TCL_UNUSED(TkMenuButton *))
    TkMenuButton *mbPtr)
{
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeMenuButtonGeometry --
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380







-
+











-
+








    width = 0;
    height = 0;
    txtWidth = 0;
    txtHeight = 0;
    avgWidth = 0;

    if (mbPtr->image != NULL) {
    if (mbPtr->image != None) {
	Tk_SizeOfImage(mbPtr->image, &width, &height);
	haveImage = 1;
    } else if (mbPtr->bitmap != None) {
	Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height);
	haveImage = 1;
    }

    if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) {
	Tk_FreeTextLayout(mbPtr->textLayout);

	mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text,
		TCL_INDEX_NONE, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth,
		-1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth,
		&mbPtr->textHeight);
	txtWidth = mbPtr->textWidth;
	txtHeight = mbPtr->textHeight;
	avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1);
	Tk_GetFontMetrics(mbPtr->tkfont, &fm);
	haveText = (txtWidth != 0 && txtHeight != 0);
    }

Changes to unix/tkUnixPort.h.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28











29
30
31
32
33
34
35
36
37




38
39





40
41
42
43





44
45


46
47
48
49
50
51
52
14
15
16
17
18
19
20








21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45
46
47
48
49
50



51
52
53
54
55


56
57
58
59
60
61
62
63
64







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+









+
+
+
+
-
-
+
+
+
+
+

-
-
-
+
+
+
+
+
-
-
+
+








#ifndef _UNIXPORT
#define _UNIXPORT

#define __UNIX__ 1

#include <stdio.h>
#include <pwd.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <pwd.h>
#ifdef NO_STDLIB_H
#   include "../compat/stdlib.h"
#else
#   include <stdlib.h>
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/file.h>
#ifdef HAVE_SYS_SELECT_H
#   include <sys/select.h>
#endif
#include <sys/stat.h>
#ifndef _TCL
#   include <tcl.h>
#endif
#if TIME_WITH_SYS_TIME
#   include <sys/time.h>
#   include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#	include <sys/time.h>
#   if HAVE_SYS_TIME_H
#       include <sys/time.h>
#   else
#       include <time.h>
#   endif
#endif
#include <time.h>
#include <inttypes.h>
#include <unistd.h>
#if HAVE_INTTYPES_H
#    include <inttypes.h>
#endif
#ifndef NO_UNISTD_H
#   include <unistd.h>
#if defined(__GNUC__) && !defined(__cplusplus)
#   pragma GCC diagnostic ignored "-Wc++-compat"
#else
#   include "../compat/unistd.h"
#endif
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/Xresource.h>
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112

























113
114
115
116
117
118
119
105
106
107
108
109
110
111
112













113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144







+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 * Define "NBBY" (number of bits per byte) if it's not already defined.
 */

#ifndef NBBY
#   define NBBY 8
#endif

#ifdef __CYGWIN__
#include "tkIntXlibDecls.h"
#define UINT unsigned int
#define HWND void *
#define HDC void *
#define HINSTANCE void *
#define COLORREF void *
#define HMENU void *
#define TkWinDCState void
#define HPALETTE void *
#define WNDPROC void *
#define WPARAM void *
#define LPARAM void *
#define LRESULT void *
#   include "tkIntXlibDecls.h"
#   define UINT unsigned int
#   define HWND void *
#   define HDC void *
#   define HINSTANCE void *
#   define COLORREF void *
#   define HMENU void *
#   define TkWinDCState void
#   define HPALETTE void *
#   define WNDPROC void *
#   define WPARAM void *
#   define LPARAM void *
#   define LRESULT void *

#else /* !__CYGWIN__ */
    /*
     * The TkPutImage macro strips off the color table information, which isn't
     * needed for X.
     */

#   define TkPutImage(colors, ncolors, display, pixels, gc, image, srcx, srcy, destx, desty, width, height) \
		XPutImage(display, pixels, gc, image, srcx, srcy, destx, \
		desty, width, height);

#endif /* !__CYGWIN__ */

/*
 * Supply macros for seek offsets, if they're not already provided by
 * an include file.
 */

#ifndef SEEK_SET
141
142
143
144
145
146
147









148
149
150
151
152
153
154
155

156
157
158
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192







+
+
+
+
+
+
+
+
+







-
+



#define TkpButtonSetDefaults() {}
#define TkpDestroyButton(butPtr) {}
#define TkSelUpdateClipboard(a,b) {}
#ifndef __CYGWIN__
#define TkSetPixmapColormap(p,c) {}
#endif

/*
 * These calls implement native bitmaps which are not supported under
 * UNIX.  The macros eliminate the calls.
 */

#define TkpDefineNativeBitmaps()
#define TkpCreateNativeBitmap(display, source) None
#define TkpGetNativeAppBitmap(display, name, w, h) None

/*
 * This macro stores a representation of the window handle in a string.
 * This should perhaps use the real size of an XID.
 */

#ifndef __CYGWIN__
#define TkpPrintWindowId(buf,w) \
	snprintf((buf), TCL_INTEGER_SPACE, "0x%lx", (unsigned long) (w))
	sprintf((buf), "%#08lx", (unsigned long) (w))
#endif

#endif /* _UNIXPORT */

Changes to unix/tkUnixRFont.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22





-
+








+







/*
 * tkUnixRFont.c --
 *
 *	Alternate implementation of tkUnixFont.c using Xft.
 *
 * Copyright © 2002-2003 Keith Packard
 * Copyright (c) 2002-2003 Keith Packard
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkUnixInt.h"
#include "tkFont.h"
#include <X11/Xft/Xft.h>
#include <ctype.h>

#define MAX_CACHED_COLORS 16

typedef struct {
    XftFont *ftFont;
    XftFont *ft0Font;
    FcPattern *source;
45
46
47
48
49
50
51
52

53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68



69
70

71
72
73
74


75
76
77
78
79

80
81
82

83
84
85
86
87
88
89
90

91






92
93
94
95
96
97
98
46
47
48
49
50
51
52

53
54
55
56

57




58







59
60
61


62




63
64





65



66




67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84







-
+



-
+
-
-
-
-

-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-



-
+

+
+
+
+
+
+







} UnixFtFont;

/*
 * Used to describe the current clipping box. Can't be passed normally because
 * the information isn't retrievable from the GC.
 */

typedef struct {
typedef struct ThreadSpecificData {
    Region clipRegion;		/* The clipping region, or None. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;


TCL_DECLARE_MUTEX(xftMutex);
#define LOCK Tcl_MutexLock(&xftMutex)
#define UNLOCK Tcl_MutexUnlock(&xftMutex)

/*
 *-------------------------------------------------------------------------
 *
 * TkpFontPkgInit --
 *
 *	This procedure is called when an application is created. It
 *	initializes all the structures that are used by the
 *	platform-dependant code on a per application basis.
 * Package initialization:
 * 	Nothing to do here except register the fact that we're using Xft in
 * 	the TIP 59 configuration database.
 *	Note that this is called before TkpInit() !
 *
 */
 * Results:
 *	None.
 *
 * Side effects:

#ifndef TCL_CFGVAL_ENCODING
 *	None.
 *
 *-------------------------------------------------------------------------
 */

#define TCL_CFGVAL_ENCODING "ascii"
static Tcl_Size utf8ToUcs4(const char *source, FcChar32 *c, Tcl_Size numBytes)
{
    if (numBytes >= 6) {
#endif
    	return Tcl_UtfToUniChar(source, (int *)c);
    }
    return FcUtf8ToUcs4((const FcChar8 *)source, c, numBytes);
}

void
TkpFontPkgInit(
    TCL_UNUSED(TkMainInfo *))	/* The application being created. */
    TkMainInfo *mainPtr)	/* The application being created. */
{
    static const Tcl_Config cfg[] = {
	{ "fontsystem", "xft" },
	{ 0,0 }
    };

    Tcl_RegisterConfig(mainPtr->interp, "tk", cfg, TCL_CFGVAL_ENCODING);
}

static XftFont *
GetFont(
    UnixFtFont *fontPtr,
    FcChar32 ucs4,
    double angle)
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201


202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225

226
227
228
229
230
231
232
115
116
117
118
119
120
121

122

123
124
125
126
127
128
129
130

131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149

150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176

177
178


179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203

204
205
206
207
208
209
210
211







-

-








-





-














-

-

















-









-
+

-
-
+
+

-
+















-
+





-
+








	mat.xx = mat.yy = c;
	mat.xy = -(mat.yx = s);

	if (angle != 0.0) {
	    FcPatternAddMatrix(pat, FC_MATRIX, &mat);
	}
	LOCK;
	ftFont = XftFontOpenPattern(fontPtr->display, pat);
	UNLOCK;
	if (!ftFont) {
	    /*
	     * The previous call to XftFontOpenPattern() should not fail, but
	     * sometimes does anyway. Usual cause appears to be a
	     * misconfigured fontconfig installation; see [Bug 1090382]. Try a
	     * fallback:
	     */

	    LOCK;
	    ftFont = XftFontOpen(fontPtr->display, fontPtr->screen,
		    FC_FAMILY, FcTypeString, "sans",
		    FC_SIZE, FcTypeDouble, 12.0,
		    FC_MATRIX, FcTypeMatrix, &mat,
		    NULL);
	    UNLOCK;
	}
	if (!ftFont) {
	    /*
	     * The previous call should definitely not fail. Impossible to
	     * proceed at this point.
	     */

	    Tcl_Panic("Cannot find a usable font");
	}

	if (angle == 0.0) {
	    fontPtr->faces[i].ft0Font = ftFont;
	} else {
	    if (fontPtr->faces[i].ftFont) {
		LOCK;
		XftFontClose(fontPtr->display, fontPtr->faces[i].ftFont);
		UNLOCK;
	    }
	    fontPtr->faces[i].ftFont = ftFont;
	    fontPtr->faces[i].angle = angle;
	}
    }
    return (angle==0.0? fontPtr->faces[i].ft0Font : fontPtr->faces[i].ftFont);
}

/*
 *---------------------------------------------------------------------------
 *
 * GetTkFontAttributes --
 * 	Fill in TkFontAttributes from an XftFont.
 */

static void
GetTkFontAttributes(
    Tk_Window tkwin,
    XftFont *ftFont,
    TkFontAttributes *faPtr)
{
    const char *family = "Unknown";
    const char *const *familyPtr = &family;
    int weight, slant, pxsize;
    double size, ptsize;

    (void) XftPatternGetString(ftFont->pattern, XFT_FAMILY, 0, familyPtr);
    if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0,
    if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0,
	    &ptsize) == XftResultMatch) {
	size = -ptsize;
    } else if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0,
	size = ptsize;
    } else if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0,
	    &ptsize) == XftResultMatch) {
	size = ptsize;
	size = -ptsize;
    } else if (XftPatternGetInteger(ftFont->pattern, XFT_PIXEL_SIZE, 0,
	    &pxsize) == XftResultMatch) {
	size = (double)-pxsize;
    } else {
	size = 12.0;
    }
    if (XftPatternGetInteger(ftFont->pattern, XFT_WEIGHT, 0,
	    &weight) != XftResultMatch) {
	weight = XFT_WEIGHT_MEDIUM;
    }
    if (XftPatternGetInteger(ftFont->pattern, XFT_SLANT, 0,
	    &slant) != XftResultMatch) {
	slant = XFT_SLANT_ROMAN;
    }

#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
    printf("family %s size %d weight %d slant %d\n",
	    family, (int)size, weight, slant);
#endif /* DEBUG_FONTSEL */

    faPtr->family = Tk_GetUid(family);
    faPtr->size = TkFontGetPoints(tkwin, size);
    faPtr->size = size;
    faPtr->weight = (weight > XFT_WEIGHT_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
    faPtr->slant = (slant > XFT_SLANT_ROMAN) ? TK_FS_ITALIC : TK_FS_ROMAN;
    faPtr->underline = 0;
    faPtr->overstrike = 0;
}

/*
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

299
300
301
302

303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320

321
322
323
324
325
326
327
243
244
245
246
247
248
249

















250
251
252
253
254
255
256
257
258
259

260

261
262

263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280

281
282
283
284
285
286
287
288







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
+
-


-
+










-
+






-
+







 *
 * Results:
 * 	On error, frees fontPtr and returns NULL, otherwise returns fontPtr.
 *
 *---------------------------------------------------------------------------
 */

static void
FinishedWithFont(
    UnixFtFont *fontPtr);

static int
InitFontErrorProc(
    void *clientData,
    TCL_UNUSED(XErrorEvent *))
{
    int *errorFlagPtr = (int *)clientData;

    if (errorFlagPtr != NULL) {
	*errorFlagPtr = 1;
    }
    return 0;
}

static UnixFtFont *
InitFont(
    Tk_Window tkwin,
    FcPattern *pattern,
    UnixFtFont *fontPtr)
{
    FcFontSet *set;
    FcCharSet *charset;
    FcResult result;
    XftFont *ftFont;
    int i, iWidth, errorFlag;
    int i, iWidth;
    Tk_ErrorHandler handler;

    if (!fontPtr) {
	fontPtr = (UnixFtFont *)ckalloc(sizeof(UnixFtFont));
	fontPtr = ckalloc(sizeof(UnixFtFont));
    }

    FcConfigSubstitute(0, pattern, FcMatchPattern);
    XftDefaultSubstitute(Tk_Display(tkwin), Tk_ScreenNumber(tkwin), pattern);

    /*
     * Generate the list of fonts
     */

    set = FcFontSort(0, pattern, FcTrue, NULL, &result);
    if (!set || set->nfont == 0) {
    if (!set) {
	ckfree(fontPtr);
	return NULL;
    }

    fontPtr->fontset = set;
    fontPtr->pattern = pattern;
    fontPtr->faces = (UnixFtFace *)ckalloc(set->nfont * sizeof(UnixFtFace));
    fontPtr->faces = ckalloc(set->nfont * sizeof(UnixFtFace));
    fontPtr->nfaces = set->nfont;

    /*
     * Fill in information about each returned font
     */

    for (i = 0; i < set->nfont; i++) {
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371
372
373
374
375
304
305
306
307
308
309
310



311






312

313
314






315
316
317
318
319
320
321







-
-
-

-
-
-
-
-
-

-
+

-
-
-
-
-
-







    fontPtr->ncolors = 0;
    fontPtr->firstColor = -1;

    /*
     * Fill in platform-specific fields of TkFont.
     */

    errorFlag = 0;
    handler = Tk_CreateErrorHandler(Tk_Display(tkwin),
		    -1, -1, -1, InitFontErrorProc, (void *) &errorFlag);
    ftFont = GetFont(fontPtr, 0, 0.0);
    if ((ftFont == NULL) || errorFlag) {
	Tk_DeleteErrorHandler(handler);
	FinishedWithFont(fontPtr);
	ckfree(fontPtr);
	return NULL;
    }
    fontPtr->font.fid = XLoadFont(Tk_Display(tkwin), "fixed");
    GetTkFontAttributes(tkwin, ftFont, &fontPtr->font.fa);
    GetTkFontAttributes(ftFont, &fontPtr->font.fa);
    GetTkFontMetrics(ftFont, &fontPtr->font.fm);
    Tk_DeleteErrorHandler(handler);
    if (errorFlag) {
	FinishedWithFont(fontPtr);
	ckfree(fontPtr);
	return NULL;
    }

    /*
     * Fontconfig can't report any information about the position or thickness
     * of underlines or overstrikes. Thus, we use some defaults that are
     * hacked around from backup defaults in tkUnixFont.c, which are in turn
     * based on recommendations in the X manual. The comments from that file
     * leading to these computations were:
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
332
333
334
335
336
337
338



339






340
341
342
343
344
345
346







-
-
-

-
-
-
-
-
-







     * Fontconfig at all. [Bug 1961455]
     */

    {
	TkFont *fPtr = &fontPtr->font;

	fPtr->underlinePos = fPtr->fm.descent / 2;
	handler = Tk_CreateErrorHandler(Tk_Display(tkwin),
			-1, -1, -1, InitFontErrorProc, (void *) &errorFlag);
	errorFlag = 0;
	Tk_MeasureChars((Tk_Font) fPtr, "I", 1, -1, 0, &iWidth);
	Tk_DeleteErrorHandler(handler);
	if (errorFlag) {
	    FinishedWithFont(fontPtr);
	    ckfree(fontPtr);
	    return NULL;
	}
	fPtr->underlineHeight = iWidth / 3;
	if (fPtr->underlineHeight == 0) {
	    fPtr->underlineHeight = 1;
	}
	if (fPtr->underlineHeight + fPtr->underlinePos > fPtr->fm.descent) {
	    fPtr->underlineHeight = fPtr->fm.descent - fPtr->underlinePos;
	    if (fPtr->underlineHeight == 0) {
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
360
361
362
363
364
365
366

367

368
369

370

371
372
373
374
375
376
377







-

-


-

-







    Display *display = fontPtr->display;
    int i;
    Tk_ErrorHandler handler =
	    Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);

    for (i = 0; i < fontPtr->nfaces; i++) {
	if (fontPtr->faces[i].ftFont) {
	    LOCK;
	    XftFontClose(fontPtr->display, fontPtr->faces[i].ftFont);
	    UNLOCK;
	}
	if (fontPtr->faces[i].ft0Font) {
	    LOCK;
	    XftFontClose(fontPtr->display, fontPtr->faces[i].ft0Font);
	    UNLOCK;
	}
	if (fontPtr->faces[i].charset) {
	    FcCharSetDestroy(fontPtr->faces[i].charset);
	}
    }
    if (fontPtr->faces) {
	ckfree(fontPtr->faces);
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408







-
+







TkFont *
TkpGetNativeFont(
    Tk_Window tkwin,		/* For display where font will be used. */
    const char *name)		/* Platform-specific font name. */
{
    UnixFtFont *fontPtr;
    FcPattern *pattern;
#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
    printf("TkpGetNativeFont %s\n", name);
#endif /* DEBUG_FONTSEL */

    pattern = XftXlfdParse(name, FcFalse, FcFalse);
    if (!pattern) {
	return NULL;
    }
499
500
501
502
503
504
505
506

507
508

509
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
432
433
434
435
436
437
438

439
440

441
442
443
444
445
446
447
448
449

450
451
452
453
454
455
456
457







-
+

-
+








-
+







    const TkFontAttributes *faPtr)
				/* Set of attributes to match. */
{
    XftPattern *pattern;
    int weight, slant;
    UnixFtFont *fontPtr;

#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
    printf("TkpGetFontFromAttributes %s-%d %d %d\n", faPtr->family,
	    (int)faPtr->size, faPtr->weight, faPtr->slant);
	    faPtr->size, faPtr->weight, faPtr->slant);
#endif /* DEBUG_FONTSEL */
    pattern = XftPatternCreate();
    if (faPtr->family) {
	XftPatternAddString(pattern, XFT_FAMILY, faPtr->family);
    }
    if (faPtr->size > 0.0) {
	XftPatternAddDouble(pattern, XFT_SIZE, faPtr->size);
    } else if (faPtr->size < 0.0) {
	XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, -faPtr->size);
	XftPatternAddDouble(pattern, XFT_SIZE, TkFontGetPoints(tkwin, faPtr->size));
    } else {
	XftPatternAddDouble(pattern, XFT_SIZE, 12.0);
    }
    switch (faPtr->weight) {
    case TK_FW_NORMAL:
    default:
	weight = XFT_WEIGHT_MEDIUM;
609
610
611
612
613
614
615
616

617
618
619
620
621
622
623
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556







-
+







		(char *) 0,		/* pattern elements */
		XFT_FAMILY, (char*) 0);	/* fields */
    for (i = 0; i < list->nfont; i++) {
	char *family, **familyPtr = &family;

	if (XftPatternGetString(list->fonts[i], XFT_FAMILY, 0, familyPtr)
		== XftResultMatch) {
	    Tcl_Obj *strPtr = Tcl_NewStringObj(family, TCL_INDEX_NONE);
	    Tcl_Obj *strPtr = Tcl_NewStringObj(family, -1);

	    Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
	}
    }
    XftFontSetDestroy(list);

    Tcl_SetObjResult(interp, resultPtr);
657
658
659
660
661
662
663
664
665
666



667
668
669
670
671
672
673
590
591
592
593
594
595
596



597
598
599
600
601
602
603
604
605
606







-
-
-
+
+
+







    for (i = 0; i < fontPtr->nfaces ; ++i) {
 	pattern = FcFontRenderPrepare(0, fontPtr->pattern,
		fontPtr->faces[i].source);

	XftPatternGetString(pattern, XFT_FAMILY, 0, familyPtr);
	XftPatternGetString(pattern, XFT_FOUNDRY, 0, foundryPtr);
	XftPatternGetString(pattern, XFT_ENCODING, 0, encodingPtr);
	objv[0] = Tcl_NewStringObj(family, TCL_INDEX_NONE);
	objv[1] = Tcl_NewStringObj(foundry, TCL_INDEX_NONE);
	objv[2] = Tcl_NewStringObj(encoding, TCL_INDEX_NONE);
	objv[0] = Tcl_NewStringObj(family, -1);
	objv[1] = Tcl_NewStringObj(foundry, -1);
	objv[2] = Tcl_NewStringObj(encoding, -1);
	listPtr = Tcl_NewListObj(3, objv);
	Tcl_ListObjAppendElement(NULL, resultPtr, listPtr);
    }
    Tcl_SetObjResult(interp, resultPtr);
}

/*
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
706
707
708

709
710
711
712
713
714
715
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648







-
+









-
+







    UnixFtFont *fontPtr = (UnixFtFont *) tkfont;
				/* Structure describing the logical font */
    FcChar32 ucs4 = (FcChar32) c;
				/* UCS-4 character to map */
    XftFont *ftFont = GetFont(fontPtr, ucs4, 0.0);
				/* Actual font used to render the character */

    GetTkFontAttributes(tkwin, ftFont, faPtr);
    GetTkFontAttributes(ftFont, faPtr);
    faPtr->underline = fontPtr->font.fa.underline;
    faPtr->overstrike = fontPtr->font.fa.overstrike;
}

int
Tk_MeasureChars(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    Tcl_Size numBytes,		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length in pixels; don't
				 * consider any character that would cross
				 * this x-position. If < 0, then line length
				 * is unbounded and the flags argument is
				 * ignored. */
723
724
725
726
727
728
729
730
731
732


733
734

735
736
737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754

755

756
757
758
759
760
761
762
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777

778
779
780
781
782
783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799
800
801
802


803
804
805
806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827



828
829
830
831


832
833
834
835
836
837
838
656
657
658
659
660
661
662



663
664


665
666
667
668
669


670
671
672
673
674
675

676
677
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699

700
701
702
703
704



705





706
707
708
709
710
711
712
713

714











715
716

717
718
719
720
721
722
723



724
725
726
727
728
729
730
731
732
733
734
735



736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751







-
-
-
+
+
-
-
+




-
-






-
+







+
-
+














-
+




-
-
-
+
-
-
-
-
-








-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-







-
-
-
+











-
-
-
+
+
+




+
+







    int *lengthPtr)		/* Filled with x-location just after the
				 * terminating character. */
{
    UnixFtFont *fontPtr = (UnixFtFont *) tkfont;
    XftFont *ftFont;
    FcChar32 c;
    XGlyphInfo extents;
    Tcl_Size clen;
    int curX, newX, curByte, newByte, sawNonSpace;
    int termByte = 0, termX = 0, errorFlag = 0;
    int clen, curX, newX, curByte, newByte, sawNonSpace;
    int termByte = 0, termX = 0;
    Tk_ErrorHandler handler;
#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
    char string[256];
    int len = 0;
#endif /* DEBUG_FONTSEL */

    handler = Tk_CreateErrorHandler(fontPtr->display,
	    -1, -1, -1, InitFontErrorProc, &errorFlag);
    curX = 0;
    curByte = 0;
    sawNonSpace = 0;
    while (numBytes > 0) {
	int unichar;

	clen = Tcl_UtfToUniChar(source, &unichar);
	clen = TkUtfToUniChar(source, &unichar);
	c = (FcChar32) unichar;

	if (clen <= 0) {
	    /*
	     * This can't happen (but see #1185640)
	     */

	    *lengthPtr = curX;
	    goto measureCharsEnd;
	    return curByte;
	}

	source += clen;
	numBytes -= clen;
	if (c < 256 && isspace(c)) {		/* I18N: ??? */
	    if (sawNonSpace) {
		termByte = curByte;
		termX = curX;
		sawNonSpace = 0;
	    }
	} else {
	    sawNonSpace = 1;
	}

#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
	string[len++] = (char) c;
#endif /* DEBUG_FONTSEL */
	ftFont = GetFont(fontPtr, c, 0.0);

	if (!errorFlag) {
	    LOCK;
	    XftTextExtents32(fontPtr->display, ftFont, &c, 1, &extents);
	XftTextExtents32(fontPtr->display, ftFont, &c, 1, &extents);
	    UNLOCK;
	} else {
	    extents.xOff = 0;
	    errorFlag = 0;
	}

	newX = curX + extents.xOff;
	newByte = curByte + clen;
	if (maxLength >= 0 && newX > maxLength) {
	    if (flags & TK_PARTIAL_OK ||
		    (flags & TK_AT_LEAST_ONE && curByte == 0)) {
		curX = newX;
		curByte = newByte;
	    } else if (flags & TK_WHOLE_WORDS) {
	    } else if (flags & TK_WHOLE_WORDS && termX != 0) {
		if ((flags & TK_AT_LEAST_ONE) && (termX == 0)) {
		    /*
		     * No space was seen before reaching the right
		     * of the allotted maxLength space, i.e. no word
		     * boundary. Return the string that fills the
		     * allotted space, without overfill.
		     * curX and curByte are already the right ones:
		     */
		} else {
		    curX = termX;
		    curByte = termByte;
		curX = termX;
		curByte = termByte;
		}
	    }
	    break;
	}

	curX = newX;
	curByte = newByte;
    }
measureCharsEnd:
    Tk_DeleteErrorHandler(handler);
#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
    string[len] = '\0';
    printf("MeasureChars %s length %d bytes %d\n", string, curX, curByte);
#endif /* DEBUG_FONTSEL */
    *lengthPtr = curX;
    return curByte;
}

int
TkpMeasureCharsInContext(
    Tk_Font tkfont,
    const char *source,
    TCL_UNUSED(Tcl_Size),
    Tcl_Size rangeStart,
    Tcl_Size rangeLength,
    int numBytes,
    int rangeStart,
    int rangeLength,
    int maxLength,
    int flags,
    int *lengthPtr)
{
    (void) numBytes; /*unused*/

    return Tk_MeasureChars(tkfont, source + rangeStart, rangeLength,
	    maxLength, flags, lengthPtr);
}

/*
 *----------------------------------------------------------------------
 *
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
810
811
812
813
814
815
816

817
818
819
820
821
822
823
824







-
+







     */
    xcolor.pixel = pixel;
    XQueryColor(display, DefaultColormap(display, fontPtr->screen), &xcolor);

    fontPtr->colors[last].color.color.red = xcolor.red;
    fontPtr->colors[last].color.color.green = xcolor.green;
    fontPtr->colors[last].color.color.blue = xcolor.blue;
    fontPtr->colors[last].color.color.alpha = 0xFFFF;
    fontPtr->colors[last].color.color.alpha = 0xffff;
    fontPtr->colors[last].color.pixel = pixel;

    /*
     * Put at the front of the list.
     */
    if (last2 >= 0) {
	fontPtr->colors[last2].next = fontPtr->colors[last].next;
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952


953
954
955
956
957
958
959
960
961
962
963
964
965
966

967
968
969
970

971
972
973
974

975
976
977
978
979
980
981
982
983
984
985
986

987
988


989
990
991
992

993
994
995
996

997
998
999
1000
1001

1002
1003

1004
1005
1006


1007
1008
1009


1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023


1024
1025
1026
1027
1028
1029
1030
841
842
843
844
845
846
847

848
849
850
851
852

853
854
855
856
857
858
859
860
861
862


863
864
865
866
867
868
869
870
871
872
873
874
875
876
877

878
879
880
881

882
883
884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900

901
902
903
904


905




906





907


908



909
910



911
912



913
914
915

916

917
918
919


920
921
922
923
924
925
926
927
928







-
+




-










-
-
+
+













-
+



-
+



-
+












+

-
+
+


-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
-
+
+
-
-
-



-

-



-
-
+
+







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int x, int y)		/* Coordinates at which to place origin of
				 * string when drawing. */
{
    const int maxCoord = 0x7FFF;/* Xft coordinates are 16 bit values */
    const int minCoord = -maxCoord-1;
    UnixFtFont *fontPtr = (UnixFtFont *) tkfont;
    XGCValues values;
    XftColor *xftcolor;
    int clen, nspec, xStart = x;
    XftGlyphFontSpec specs[NUM_SPEC];
    XGlyphInfo metrics;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (fontPtr->ftDraw == 0) {
#ifdef DEBUG_FONTSEL
	printf("Switch to drawable 0x%lx\n", drawable);
#if DEBUG_FONTSEL
	printf("Switch to drawable 0x%x\n", drawable);
#endif /* DEBUG_FONTSEL */
	fontPtr->ftDraw = XftDrawCreate(display, drawable,
		DefaultVisual(display, fontPtr->screen),
		DefaultColormap(display, fontPtr->screen));
    } else {
	Tk_ErrorHandler handler =
		Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);

	XftDrawChange(fontPtr->ftDraw, drawable);
	Tk_DeleteErrorHandler(handler);
    }
    XGetGCValues(display, gc, GCForeground, &values);
    xftcolor = LookUpColor(display, fontPtr, values.foreground);
    if (tsdPtr->clipRegion != NULL) {
    if (tsdPtr->clipRegion != None) {
	XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion);
    }
    nspec = 0;
    while (numBytes > 0) {
    while (numBytes > 0 && x <= maxCoord && y <= maxCoord) {
	XftFont *ftFont;
	FcChar32 c;

	clen = utf8ToUcs4(source, &c, numBytes);
	clen = FcUtf8ToUcs4((FcChar8 *) source, &c, numBytes);
	if (clen <= 0) {
	    /*
	     * This should not happen, but it can.
	     */

	    goto doUnderlineStrikeout;
	}
	source += clen;
	numBytes -= clen;

	ftFont = GetFont(fontPtr, c, 0.0);
	if (ftFont) {
	    specs[nspec].font = ftFont;
	    specs[nspec].glyph = XftCharIndex(fontPtr->display, ftFont, c);
	    LOCK;
	    specs[nspec].x = x;
	    specs[nspec].y = y;
	    XftGlyphExtents(fontPtr->display, ftFont, &specs[nspec].glyph, 1,
		    &metrics);
	    UNLOCK;

	    x += metrics.xOff;
	    /*
	     * Draw glyph only when it fits entirely into 16 bit coords.
	     */

	    y += metrics.yOff;
	    if (x >= minCoord && y >= minCoord &&
		x <= maxCoord - metrics.width &&
		y <= maxCoord - metrics.height) {
		specs[nspec].font = ftFont;
		specs[nspec].x = x;
	    nspec++;
		specs[nspec].y = y;
		if (++nspec == NUM_SPEC) {
	    if (nspec == NUM_SPEC) {
		    LOCK;
		    XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor,
			    specs, nspec);
		XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor,
			specs, nspec);
		    UNLOCK;
		    nspec = 0;
		}
		nspec = 0;
	    }
	    }
	    x += metrics.xOff;
	    y += metrics.yOff;
	}
    }
    if (nspec) {
	LOCK;
	XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec);
	UNLOCK;
    }

  doUnderlineStrikeout:
    if (tsdPtr->clipRegion != NULL) {
	XftDrawSetClip(fontPtr->ftDraw, NULL);
    if (tsdPtr->clipRegion != None) {
	XftDrawSetClip(fontPtr->ftDraw, None);
    }
    if (fontPtr->font.fa.underline != 0) {
	XFillRectangle(display, drawable, gc, xStart,
		y + fontPtr->font.underlinePos, (unsigned) (x - xStart),
		(unsigned) fontPtr->font.underlineHeight);
    }
    if (fontPtr->font.fa.overstrike != 0) {
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
962
963
964
965
966
967
968

969
970
971
972
973
974

975
976
977
978
979
980
981
982
983
984
985
986
987
988
989

990
991
992
993
994
995
996
997







-
+





-
+














-
+







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    double x, double y,		/* Coordinates at which to place origin of
				 * string when drawing. */
    double angle)		/* What angle to put text at, in degrees. */
{
    const int maxCoord = 0x7FFF;/* Xft coordinates are 16 bit values */
    const int minCoord = -maxCoord-1;
    const int minCoord = -1000;	/* Should be good enough... */
    UnixFtFont *fontPtr = (UnixFtFont *) tkfont;
    XGCValues values;
    XftColor *xftcolor;
    int xStart = x, yStart = y;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
#ifdef XFT_HAS_FIXED_ROTATED_PLACEMENT
    int clen, nglyph;
    FT_UInt glyphs[NUM_SPEC];
    XGlyphInfo metrics;
    XftFont *currentFtFont;
    int originX, originY;

    if (fontPtr->ftDraw == 0) {
#ifdef DEBUG_FONTSEL
#if DEBUG_FONTSEL
	printf("Switch to drawable 0x%x\n", drawable);
#endif /* DEBUG_FONTSEL */
	fontPtr->ftDraw = XftDrawCreate(display, drawable,
		DefaultVisual(display, fontPtr->screen),
		DefaultColormap(display, fontPtr->screen));
    } else {
	Tk_ErrorHandler handler =
1107
1108
1109
1110
1111
1112
1113
1114

1115
1116


1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1005
1006
1007
1008
1009
1010
1011

1012
1013

1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







-
+

-
+
+



-
+







    xftcolor = LookUpColor(display, fontPtr, values.foreground);
    if (tsdPtr->clipRegion != None) {
	XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion);
    }

    nglyph = 0;
    currentFtFont = NULL;
    originX = originY = 0;
    originX = originY = 0;		/* lint */

    while (numBytes > 0) {
    while (numBytes > 0 && x <= maxCoord && x >= minCoord && y <= maxCoord
	    && y >= minCoord) {
	XftFont *ftFont;
	FcChar32 c;

	clen = utf8ToUcs4(source, &c, numBytes);
	clen = FcUtf8ToUcs4((FcChar8 *) source, &c, numBytes);
	if (clen <= 0) {
	    /*
	     * This should not happen, but it can.
	     */

	    goto doUnderlineStrikeout;
	}
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174


1175
1176

1177
1178
1179







1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199


1200
1201

1202
1203
1204

1205
1206
1207
1208
1209
1210
1211
1212


1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226

1227
1228
1229
1230


1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249


1250
1251
1252
1253

1254
1255
1256
1257

1258
1259
1260
1261

1262
1263
1264

1265
1266
1267


1268
1269
1270


1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285


1286
1287
1288
1289
1290
1291
1292
1037
1038
1039
1040
1041
1042
1043






























1044
1045


1046

1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060















1061
1062


1063

1064

1065

1066
1067
1068
1069
1070


1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085

1086
1087
1088
1089

1090
1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110

1111
1112
1113
1114


1115




1116




1117



1118



1119
1120



1121
1122



1123
1124
1125

1126

1127
1128
1129
1130


1131
1132
1133
1134
1135
1136
1137
1138
1139







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-


+
+
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
-

-
+
-





-
-
+
+













-
+



-
+
+



-
+













+

-
+
+


-
-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
+
-
-
-
+
+
-
-
-
+
+
-
-
-



-

-




-
-
+
+







		/*
		 * We pass multiple glyphs at once to enable the code to
		 * perform better rendering of sub-pixel inter-glyph spacing.
		 * If only the current Xft implementation could make use of
		 * this information... but we'll be ready when it does!
		 */

		LOCK;
		XftGlyphExtents(fontPtr->display, currentFtFont, glyphs,
			nglyph, &metrics);
		UNLOCK;

		/*
		 * Draw glyph only when it fits entirely into 16 bit coords.
		 */

		if (x >= minCoord && y >= minCoord &&
		    x <= maxCoord - metrics.width &&
		    y <= maxCoord - metrics.height) {

		    /*
		     * NOTE:
		     * The whole algorithm has a design problem, the choice of
		     * NUM_SPEC is arbitrary, and so the inter-glyph spacing could
		     * look arbitrary. This algorithm has to draw the whole string
		     * at once (or whole blocks with same font), this requires a
		     * dynamic 'glyphs' array. In case of overflow the array has to
		     * be divided until the maximal string will fit. (GC)
                     * Given the resolution of current displays though, this should
                     * not be a huge issue since NUM_SPEC is 1024 and thus able to
                     * cover about 6000 pixels for a 6 pixel wide font (which is
                     * a very small barely readable font)
		     */

		    LOCK;
		    XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont,
			    originX, originY, glyphs, nglyph);
		XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont,
			originX, originY, glyphs, nglyph);
		    UNLOCK;
		}
	    }
	    }
	    originX = ROUND16(x);
	    originY = ROUND16(y);
	    if (nglyph) {
		XftGlyphExtents(fontPtr->display, currentFtFont, glyphs,
			nglyph, &metrics);
		nglyph = 0;
		x += metrics.xOff;
		y += metrics.yOff;
	    }
	    currentFtFont = ftFont;
	}
	glyphs[nglyph++] = XftCharIndex(fontPtr->display, ftFont, c);
    }
    if (nglyph) {
	LOCK;
	XftGlyphExtents(fontPtr->display, currentFtFont, glyphs,
		nglyph, &metrics);
	UNLOCK;

	/*
	 * Draw glyph only when it fits entirely into 16 bit coords.
	 */

	if (x >= minCoord && y >= minCoord &&
	    x <= maxCoord - metrics.width &&
	    y <= maxCoord - metrics.height) {
	    LOCK;
	    XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont,
		    originX, originY, glyphs, nglyph);
	XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont,
		originX, originY, glyphs, nglyph);
	    UNLOCK;
	}
    }
    }
#else /* !XFT_HAS_FIXED_ROTATED_PLACEMENT */
    Tcl_Size clen;
    int clen, nspec;
    int nspec;
    XftGlyphFontSpec specs[NUM_SPEC];
    XGlyphInfo metrics;
    double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

    if (fontPtr->ftDraw == 0) {
#ifdef DEBUG_FONTSEL
	printf("Switch to drawable 0x%lx\n", drawable);
#if DEBUG_FONTSEL
	printf("Switch to drawable 0x%x\n", drawable);
#endif /* DEBUG_FONTSEL */
	fontPtr->ftDraw = XftDrawCreate(display, drawable,
		DefaultVisual(display, fontPtr->screen),
		DefaultColormap(display, fontPtr->screen));
    } else {
	Tk_ErrorHandler handler =
		Tk_CreateErrorHandler(display, -1, -1, -1, NULL, NULL);

	XftDrawChange(fontPtr->ftDraw, drawable);
	Tk_DeleteErrorHandler(handler);
    }
    XGetGCValues(display, gc, GCForeground, &values);
    xftcolor = LookUpColor(display, fontPtr, values.foreground);
    if (tsdPtr->clipRegion != NULL) {
    if (tsdPtr->clipRegion != None) {
	XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion);
    }
    nspec = 0;
    while (numBytes > 0) {
    while (numBytes > 0 && x <= maxCoord && x >= minCoord
	    && y <= maxCoord && y >= minCoord) {
	XftFont *ftFont, *ft0Font;
	FcChar32 c;

	clen = utf8ToUcs4(source, &c, numBytes);
	clen = FcUtf8ToUcs4((FcChar8 *) source, &c, numBytes);
	if (clen <= 0) {
	    /*
	     * This should not happen, but it can.
	     */

	    goto doUnderlineStrikeout;
	}
	source += clen;
	numBytes -= clen;

	ftFont = GetFont(fontPtr, c, angle);
	ft0Font = GetFont(fontPtr, c, 0.0);
	if (ftFont && ft0Font) {
	    specs[nspec].font = ftFont;
	    specs[nspec].glyph = XftCharIndex(fontPtr->display, ftFont, c);
	    LOCK;
	    specs[nspec].x = ROUND16(x);
	    specs[nspec].y = ROUND16(y);
	    XftGlyphExtents(fontPtr->display, ft0Font, &specs[nspec].glyph, 1,
		    &metrics);
	    UNLOCK;

	    x += metrics.xOff*cosA + metrics.yOff*sinA;
	    /*
	     * Draw glyph only when it fits entirely into 16 bit coords.
	     */

	    y += metrics.yOff*cosA - metrics.xOff*sinA;
	    if (x >= minCoord && y >= minCoord &&
		x <= maxCoord - metrics.width &&
		y <= maxCoord - metrics.height) {
		specs[nspec].font = ftFont;
	    nspec++;
		specs[nspec].x = ROUND16(x);
		specs[nspec].y = ROUND16(y);
		if (++nspec == NUM_SPEC) {
	    if (nspec == NUM_SPEC) {
		    LOCK;
		    XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor,
			    specs, nspec);
		XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor,
			specs, nspec);
		    UNLOCK;
		    nspec = 0;
		}
		nspec = 0;
	    }
	    }
	    x += metrics.xOff*cosA + metrics.yOff*sinA;
	    y += metrics.yOff*cosA - metrics.xOff*sinA;
	}
    }
    if (nspec) {
	LOCK;
	XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec);
	UNLOCK;
    }
#endif /* XFT_HAS_FIXED_ROTATED_PLACEMENT */

  doUnderlineStrikeout:
    if (tsdPtr->clipRegion != NULL) {
	XftDrawSetClip(fontPtr->ftDraw, NULL);
    if (tsdPtr->clipRegion != None) {
	XftDrawSetClip(fontPtr->ftDraw, None);
    }
    if (fontPtr->font.fa.underline || fontPtr->font.fa.overstrike) {
	XPoint points[5];
	double width = (x - xStart) * cosA + (yStart - y) * sinA;
	double barHeight = fontPtr->font.underlineHeight;
	double dy = fontPtr->font.underlinePos;

1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424

1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437
1182
1183
1184
1185
1186
1187
1188
1189





















1190


























































1191

1192
1193
1194
1195
1196

1197
1198
1199
1200
1201
1202
1203
1204
1205








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+




-
+








		XFillPolygon(display, drawable, gc, points, 5, Complex,
			CoordModeOrigin);
		XDrawLines(display, drawable, gc, points, 5, CoordModeOrigin);
	    }
	}
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpDrawCharsInContext --
 *
 *	Draw a string of characters on the screen like Tk_DrawChars(), but
 *	with access to all the characters on the line for context. On X11 this
 *	context isn't consulted, so we just call Tk_DrawChars().
 *
 *      Note: TK_DRAW_IN_CONTEXT being currently defined only on macOS, this
 *            function is unused (and possibly unfinished). See [7655f65ae7].
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Information gets drawn on the screen.
 *
 *---------------------------------------------------------------------------
 */

void
TkpDrawCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn;
				 * must be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    int x, int y)		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
{
    int widthUntilStart;

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    Tk_DrawChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+widthUntilStart, y);
}

void
TkpDrawAngledCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    double x, double y,		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
    double angle)		/* What angle to put text at, in degrees. */
{
    int widthUntilStart;
    double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    TkDrawAngledChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+cosA*widthUntilStart, y-sinA*widthUntilStart, angle);
}

void
TkUnixSetXftClipRegion(
    Region clipRegion)	/* The clipping region to install. */
    TkRegion clipRegion)	/* The clipping region to install. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    tsdPtr->clipRegion = clipRegion;
    tsdPtr->clipRegion = (Region) clipRegion;
}

/*
 * Local Variables:
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixScale.c.

1
2
3
4

5
6
7


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55

56
57
58
59
60
61
62
1
2
3

4
5


6
7
8
9
10
11
12
13
14
15




16
17
18
19
20
21
22

23

24
25
26

27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48

49
50
51
52
53
54
55
56



-
+

-
-
+
+








-
-
-
-







-
+
-



-
+
-



















-
+

-
+







/*
 * tkUnixScale.c --
 *
 *	This file implements the X specific portion of the scale widget.
 *	This file implements the X specific portion of the scrollbar widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkScale.h"

#ifdef _WIN32
#include "tkWinInt.h"
#endif

/*
 * Forward declarations for functions defined later in this file:
 */

static void		DisplayHorizontalScale(TkScale *scalePtr,
			    Drawable drawable, XRectangle *drawnAreaPtr);
static void		DisplayHorizontalValue(TkScale *scalePtr,
			    Drawable drawable, double value, int top,
			    Drawable drawable, double value, int top);
			    const char *format);
static void		DisplayVerticalScale(TkScale *scalePtr,
			    Drawable drawable, XRectangle *drawnAreaPtr);
static void		DisplayVerticalValue(TkScale *scalePtr,
			    Drawable drawable, double value, int rightEdge,
			    Drawable drawable, double value, int rightEdge);
			    const char *format);

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateScale --
 *
 *	Allocate a new TkScale structure.
 *
 * Results:
 *	Returns a newly allocated TkScale structure.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

TkScale *
TkpCreateScale(
    TCL_UNUSED(Tk_Window))
    Tk_Window tkwin)
{
    return (TkScale *)ckalloc(sizeof(TkScale));
    return ckalloc(sizeof(TkScale));
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDestroyScale --
 *
148
149
150
151
152
153
154
155

156
157
158
159

160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
142
143
144
145
146
147
148

149
150
151
152

153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182







-
+



-
+










-
+










-
+







		    / (double) scalePtr->fontHeight;
	    if (ticks > maxTicks) {
		tickInterval *= (ticks / maxTicks);
	    }
	    for (tickValue = scalePtr->fromValue; ;
		    tickValue += tickInterval) {
		/*
		 * The TkRoundValueToResolution call gets rid of accumulated
		 * The TkRoundToResolution call gets rid of accumulated
		 * round-off errors, if any.
		 */

		tickValue = TkRoundValueToResolution(scalePtr, tickValue);
		tickValue = TkRoundToResolution(scalePtr, tickValue);
		if (scalePtr->toValue >= scalePtr->fromValue) {
		    if (tickValue > scalePtr->toValue) {
			break;
		    }
		} else {
		    if (tickValue < scalePtr->toValue) {
			break;
		    }
		}
		DisplayVerticalValue(scalePtr, drawable, tickValue,
			scalePtr->vertTickRightX, scalePtr->tickFormat);
			scalePtr->vertTickRightX);
	    }
	}
    }

    /*
     * Display the value, if it is desired.
     */

    if (scalePtr->showValue) {
	DisplayVerticalValue(scalePtr, drawable, scalePtr->value,
		scalePtr->vertValueRightX, scalePtr->valueFormat);
		scalePtr->vertValueRightX);
    }

    /*
     * Display the trough and the slider.
     */

    Tk_Draw3DRectangle(tkwin, drawable,
226
227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
220
221
222
223
224
225
226


227
228
229
230
231
232
233
234
235







-
-
+
+








    if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
	Tk_FontMetrics fm;

	Tk_GetFontMetrics(scalePtr->tkfont, &fm);
	Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
		scalePtr->tkfont, scalePtr->label,
		scalePtr->labelLength, scalePtr->vertLabelX,
		scalePtr->inset + (3 * fm.ascent) / 2);
                scalePtr->labelLength, scalePtr->vertLabelX,
                scalePtr->inset + (3*fm.ascent)/2);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DisplayVerticalValue --
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266

267
268
269
270
271


272
273
274
275
276
277

278
279
280

281
282
283
284
285
286
287
288

289
290
291

292
293
294
295
296
297
298
246
247
248
249
250
251
252

253
254
255
256
257
258
259

260
261

262


263
264
265
266
267
268
269

270



271
272
273
274
275
276
277
278

279
280
281

282
283
284
285
286
287
288
289







-
+






-
+

-

-
-
+
+





-
+
-
-
-
+







-
+


-
+







 *	corresponds to "value".
 *
 *----------------------------------------------------------------------
 */

static void
DisplayVerticalValue(
    TkScale *scalePtr,	/* Information about widget in which to
    register TkScale *scalePtr,	/* Information about widget in which to
				 * display value. */
    Drawable drawable,		/* Pixmap or window in which to draw the
				 * value. */
    double value,		/* Y-coordinate of number to display,
				 * specified in application coords, not in
				 * pixels (we'll compute pixels). */
    int rightEdge,		/* X-coordinate of right edge of text,
    int rightEdge)		/* X-coordinate of right edge of text,
				 * specified in pixels. */
    const char *format)		/* Format string to use for the value */
{
    Tk_Window tkwin = scalePtr->tkwin;
    int y, width;
    register Tk_Window tkwin = scalePtr->tkwin;
    int y, width, length;
    char valueString[TCL_DOUBLE_SPACE];
    Tk_FontMetrics fm;

    Tk_GetFontMetrics(scalePtr->tkfont, &fm);
    y = TkScaleValueToPixel(scalePtr, value) + fm.ascent/2;
    if (snprintf(valueString, TCL_DOUBLE_SPACE, format, value) < 0) {
    sprintf(valueString, scalePtr->format, value);
	valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    Tcl_Size length = strlen(valueString);
    length = (int) strlen(valueString);
    width = Tk_TextWidth(scalePtr->tkfont, valueString, length);

    /*
     * Adjust the y-coordinate if necessary to keep the text entirely inside
     * the window.
     */

    if (y - fm.ascent < scalePtr->inset + SPACING) {
    if ((y - fm.ascent) < (scalePtr->inset + SPACING)) {
	y = scalePtr->inset + SPACING + fm.ascent;
    }
    if (y + fm.descent > Tk_Height(tkwin) - scalePtr->inset - SPACING) {
    if ((y + fm.descent) > (Tk_Height(tkwin) - scalePtr->inset - SPACING)) {
	y = Tk_Height(tkwin) - scalePtr->inset - SPACING - fm.descent;
    }
    Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
	    scalePtr->tkfont, valueString, length, rightEdge - width, y);
}

/*
321
322
323
324
325
326
327
328

329
330

331
332
333
334
335
336
337
312
313
314
315
316
317
318

319
320

321
322
323
324
325
326
327
328







-
+

-
+







    Drawable drawable,		/* Where to display scale (window or
				 * pixmap). */
    XRectangle *drawnAreaPtr)	/* Initally contains area of window; if only a
				 * part of the scale is redrawn, gets modified
				 * to reflect the part of the window that was
				 * redrawn. */
{
    Tk_Window tkwin = scalePtr->tkwin;
    register Tk_Window tkwin = scalePtr->tkwin;
    int x, y, width, height, shadowWidth;
    double tickInterval = scalePtr->tickInterval;
    double tickValue, tickInterval = scalePtr->tickInterval;
    Tk_3DBorder sliderBorder;

    /*
     * Display the information from bottom to top across the window.
     */

    if (!(scalePtr->flags & REDRAW_OTHER)) {
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363
364
365

366
367
368
369
370
371

372
373
374


375
376

377
378
379
380

381
382
383
384
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354


355


356
357
358

359
360


361
362
363

364
365
366
367

368
369
370
371
372
373
374
375
376
377
378

379

380
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397







-
+









-
-
+
-
-



-
+

-
-
+
+

-
+



-
+










-
+
-










-
+







    if (scalePtr->flags & REDRAW_OTHER) {
	/*
	 * Display the tick marks.
	 */

	if (tickInterval != 0) {
	    char valueString[TCL_DOUBLE_SPACE];
	    double ticks, maxTicks, tickValue;
	    double ticks, maxTicks;

	    /*
	     * Ensure that we will only draw enough of the tick values such
	     * that they don't overlap. We base this off the width that
	     * fromValue would take. Not exact, but better than no constraint.
	     */

	    ticks = fabs((scalePtr->toValue - scalePtr->fromValue)
		    / tickInterval);
	    if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->tickFormat,
		    scalePtr->fromValue) < 0) {
	    sprintf(valueString, scalePtr->format, scalePtr->fromValue);
		valueString[TCL_DOUBLE_SPACE - 1] = '\0';
	    }
	    maxTicks = (double) Tk_Width(tkwin)
		    / (double) Tk_TextWidth(scalePtr->tkfont, valueString, -1);
	    if (ticks > maxTicks) {
		tickInterval *= ticks / maxTicks;
		tickInterval *= (ticks / maxTicks);
	    }
	    tickValue = scalePtr->fromValue;
	    while (1) {
	    for (tickValue = scalePtr->fromValue; ;
		 tickValue += tickInterval) {
		/*
		 * The TkRoundValueToResolution call gets rid of accumulated
		 * The TkRoundToResolution call gets rid of accumulated
		 * round-off errors, if any.
		 */

		tickValue = TkRoundValueToResolution(scalePtr, tickValue);
		tickValue = TkRoundToResolution(scalePtr, tickValue);
		if (scalePtr->toValue >= scalePtr->fromValue) {
		    if (tickValue > scalePtr->toValue) {
			break;
		    }
		} else {
		    if (tickValue < scalePtr->toValue) {
			break;
		    }
		}
		DisplayHorizontalValue(scalePtr, drawable, tickValue,
			scalePtr->horizTickY, scalePtr->tickFormat);
			scalePtr->horizTickY);
		tickValue += tickInterval;
	    }
	}
    }

    /*
     * Display the value, if it is desired.
     */

    if (scalePtr->showValue) {
	DisplayHorizontalValue(scalePtr, drawable, scalePtr->value,
		scalePtr->horizValueY, scalePtr->valueFormat);
		scalePtr->horizValueY);
    }

    /*
     * Display the trough and the slider.
     */

    y = scalePtr->horizTroughY;
449
450
451
452
453
454
455
456
457


458
459
460
461
462
463
464
436
437
438
439
440
441
442


443
444
445
446
447
448
449
450
451







-
-
+
+








    if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) {
	Tk_FontMetrics fm;

	Tk_GetFontMetrics(scalePtr->tkfont, &fm);
	Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC,
		scalePtr->tkfont, scalePtr->label,
		scalePtr->labelLength, scalePtr->inset + fm.ascent/2,
		scalePtr->horizLabelY + fm.ascent);
                scalePtr->labelLength, scalePtr->inset + fm.ascent/2,
                scalePtr->horizLabelY + fm.ascent);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DisplayHorizontalValue --
475
476
477
478
479
480
481
482

483
484
485
486
487
488
489

490
491
492
493
494


495
496
497
498
499
500
501

502
503
504

505
506
507
508
509
510
511
512
513


514
515
516
517
518
519
520
462
463
464
465
466
467
468

469
470
471
472
473
474
475

476
477

478


479
480
481
482
483
484
485
486

487



488
489
490
491
492
493
494
495


496
497
498
499
500
501
502
503
504







-
+






-
+

-

-
-
+
+






-
+
-
-
-
+







-
-
+
+







 *	that corresponds to "value".
 *
 *----------------------------------------------------------------------
 */

static void
DisplayHorizontalValue(
    TkScale *scalePtr,	/* Information about widget in which to
    register TkScale *scalePtr,	/* Information about widget in which to
				 * display value. */
    Drawable drawable,		/* Pixmap or window in which to draw the
				 * value. */
    double value,		/* X-coordinate of number to display,
				 * specified in application coords, not in
				 * pixels (we'll compute pixels). */
    int top,			/* Y-coordinate of top edge of text, specified
    int top)			/* Y-coordinate of top edge of text, specified
				 * in pixels. */
    const char *format)		/* Format string to use for the value */
{
    Tk_Window tkwin = scalePtr->tkwin;
    int x, y, width;
    register Tk_Window tkwin = scalePtr->tkwin;
    int x, y, length, width;
    char valueString[TCL_DOUBLE_SPACE];
    Tk_FontMetrics fm;

    x = TkScaleValueToPixel(scalePtr, value);
    Tk_GetFontMetrics(scalePtr->tkfont, &fm);
    y = top + fm.ascent;
    if (snprintf(valueString, TCL_DOUBLE_SPACE, format, value) < 0) {
    sprintf(valueString, scalePtr->format, value);
	valueString[TCL_DOUBLE_SPACE - 1] = '\0';
    }
    Tcl_Size length = strlen(valueString);
    length = (int) strlen(valueString);
    width = Tk_TextWidth(scalePtr->tkfont, valueString, length);

    /*
     * Adjust the x-coordinate if necessary to keep the text entirely inside
     * the window.
     */

    x -= width / 2;
    if (x < scalePtr->inset + SPACING) {
    x -= (width)/2;
    if (x < (scalePtr->inset + SPACING)) {
	x = scalePtr->inset + SPACING;
    }

    /*
     * Check the right border so use starting point +text width for the check.
     */

540
541
542
543
544
545
546
547

548
549

550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578




579
580
581
582
583
584
585
524
525
526
527
528
529
530

531
532

533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553


554


555




556
557
558
559
560
561
562
563
564
565
566







-
+

-
+




















-
-
+
-
-

-
-
-
-
+
+
+
+







 *	The scale gets redisplayed.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayScale(
    void *clientData)	/* Widget record for scale. */
    ClientData clientData)	/* Widget record for scale. */
{
    TkScale *scalePtr = (TkScale *)clientData;
    TkScale *scalePtr = (TkScale *) clientData;
    Tk_Window tkwin = scalePtr->tkwin;
    Tcl_Interp *interp = scalePtr->interp;
    Pixmap pixmap;
    int result;
    char string[TCL_DOUBLE_SPACE];
    XRectangle drawnArea;
    Tcl_DString buf;

    scalePtr->flags &= ~REDRAW_PENDING;
    if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) {
	goto done;
    }

    /*
     * Invoke the scale's command if needed.
     */

    Tcl_Preserve(scalePtr);
    if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
	Tcl_Preserve(interp);
	if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat,
		scalePtr->value) < 0) {
	sprintf(string, scalePtr->format, scalePtr->value);
	    string[TCL_DOUBLE_SPACE - 1] = '\0';
	}
	Tcl_DStringInit(&buf);
	Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE);
	Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	Tcl_DStringAppend(&buf, scalePtr->command, -1);
	Tcl_DStringAppend(&buf, " ", -1);
	Tcl_DStringAppend(&buf, string, -1);
	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
	Tcl_DStringFree(&buf);
	if (result != TCL_OK) {
	    Tcl_AddErrorInfo(interp, "\n    (command executed by scale)");
	    Tcl_BackgroundException(interp, result);
	}
	Tcl_Release(interp);
    }
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
616
617
618
619
620
621
622

623
624
625
626
627
628
629
630







-
+







	if (scalePtr->highlightWidth != 0) {
	    GC gc;

	    if (scalePtr->flags & GOT_FOCUS) {
		gc = Tk_GCForColor(scalePtr->highlightColorPtr, pixmap);
	    } else {
		gc = Tk_GCForColor(
			Tk_3DBorderColor(scalePtr->highlightBorder), pixmap);
                        Tk_3DBorderColor(scalePtr->highlightBorder), pixmap);
	    }
	    Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, pixmap);
	}
    }

#ifndef TK_NO_DOUBLE_BUFFERING
    /*
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717







-
+



















-
+












	    return OTHER;
	}
	sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
		- scalePtr->sliderLength/2;
	if (y < sliderFirst) {
	    return TROUGH1;
	}
	if (y < sliderFirst + scalePtr->sliderLength) {
	if (y < (sliderFirst+scalePtr->sliderLength)) {
	    return SLIDER;
	}
	return TROUGH2;
    }

    if ((y < scalePtr->horizTroughY)
	    || (y >= (scalePtr->horizTroughY + 2*scalePtr->borderWidth +
	    scalePtr->width))) {
	return OTHER;
    }
    if ((x < scalePtr->inset)
	    || (x >= (Tk_Width(scalePtr->tkwin) - scalePtr->inset))) {
	return OTHER;
    }
    sliderFirst = TkScaleValueToPixel(scalePtr, scalePtr->value)
	    - scalePtr->sliderLength/2;
    if (x < sliderFirst) {
	return TROUGH1;
    }
    if (x < sliderFirst + scalePtr->sliderLength) {
    if (x < (sliderFirst+scalePtr->sliderLength)) {
	return SLIDER;
    }
    return TROUGH2;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixScrlbr.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkUnixScrollbar.c --
 *
 *	This file implements the Unix specific portion of the scrollbar
 *	widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkScrollbar.h"
59
60
61
62
63
64
65
66

67
68
69


70
71
72
73
74
75
76
59
60
61
62
63
64
65

66
67


68
69
70
71
72
73
74
75
76







-
+

-
-
+
+







 *----------------------------------------------------------------------
 */

TkScrollbar *
TkpCreateScrollbar(
    Tk_Window tkwin)
{
    UnixScrollbar *scrollPtr = (UnixScrollbar *)ckalloc(sizeof(UnixScrollbar));
    UnixScrollbar *scrollPtr = ckalloc(sizeof(UnixScrollbar));

    scrollPtr->troughGC = NULL;
    scrollPtr->copyGC = NULL;
    scrollPtr->troughGC = None;
    scrollPtr->copyGC = None;

    Tk_CreateEventHandler(tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask,
	    TkScrollbarEventProc, scrollPtr);

    return (TkScrollbar *) scrollPtr;
}
91
92
93
94
95
96
97
98

99
100
101


102
103
104
105
106
107
108
91
92
93
94
95
96
97

98
99


100
101
102
103
104
105
106
107
108







-
+

-
-
+
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

void
TkpDisplayScrollbar(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    TkScrollbar *scrollPtr = (TkScrollbar *)clientData;
    Tk_Window tkwin = scrollPtr->tkwin;
    register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
    register Tk_Window tkwin = scrollPtr->tkwin;
    XPoint points[7];
    Tk_3DBorder border;
    int relief, width, elementBorderWidth;
    Pixmap pixmap;

    if ((scrollPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	goto done;
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291





292
293
294
295
296
297
298







-
+











-
-
-
-
-







 *	The scrollbar will be displayed differently.
 *
 *----------------------------------------------------------------------
 */

extern void
TkpComputeScrollbarGeometry(
    TkScrollbar *scrollPtr)
    register TkScrollbar *scrollPtr)
				/* Scrollbar whose geometry may have
				 * changed. */
{
    int width, fieldLength;

    if (scrollPtr->highlightWidth < 0) {
	scrollPtr->highlightWidth = 0;
    }
    scrollPtr->inset = scrollPtr->highlightWidth + scrollPtr->borderWidth;
    width = (scrollPtr->vertical) ? Tk_Width(scrollPtr->tkwin)
	    : Tk_Height(scrollPtr->tkwin);

    /*
     * Next line assumes that the arrow area is a square.
     */

    scrollPtr->arrowLength = width - 2*scrollPtr->inset + 1;
    fieldLength = (scrollPtr->vertical ? Tk_Height(scrollPtr->tkwin)
	    : Tk_Width(scrollPtr->tkwin))
	    - 2*(scrollPtr->arrowLength + scrollPtr->inset);
    if (fieldLength < 0) {
	fieldLength = 0;
    }
362
363
364
365
366
367
368
369

370
371
372

373
374
375
376
377
378
379
357
358
359
360
361
362
363

364
365
366

367
368
369
370
371
372
373
374







-
+


-
+








void
TkpDestroyScrollbar(
    TkScrollbar *scrollPtr)
{
    UnixScrollbar *unixScrollPtr = (UnixScrollbar *)scrollPtr;

    if (unixScrollPtr->troughGC != NULL) {
    if (unixScrollPtr->troughGC != None) {
	Tk_FreeGC(scrollPtr->display, unixScrollPtr->troughGC);
    }
    if (unixScrollPtr->copyGC != NULL) {
    if (unixScrollPtr->copyGC != None) {
	Tk_FreeGC(scrollPtr->display, unixScrollPtr->copyGC);
    }
}

/*
 *----------------------------------------------------------------------
 *
390
391
392
393
394
395
396
397

398
399
400
401
402

403
404
405
406
407
408
409


410
411
412
413


414
415
416
417
418
419
420
385
386
387
388
389
390
391

392
393
394
395
396

397
398
399
400
401
402


403
404
405
406


407
408
409
410
411
412
413
414
415







-
+




-
+





-
-
+
+


-
-
+
+







 *	Configuration info may get changed.
 *
 *----------------------------------------------------------------------
 */

void
TkpConfigureScrollbar(
    TkScrollbar *scrollPtr)
    register TkScrollbar *scrollPtr)
				/* Information about widget; may or may not
				 * already have values for some fields. */
{
    XGCValues gcValues;
    GC newGC;
    GC new;
    UnixScrollbar *unixScrollPtr = (UnixScrollbar *) scrollPtr;

    Tk_SetBackgroundFromBorder(scrollPtr->tkwin, scrollPtr->bgBorder);

    gcValues.foreground = scrollPtr->troughColorPtr->pixel;
    newGC = Tk_GetGC(scrollPtr->tkwin, GCForeground, &gcValues);
    if (unixScrollPtr->troughGC != NULL) {
    new = Tk_GetGC(scrollPtr->tkwin, GCForeground, &gcValues);
    if (unixScrollPtr->troughGC != None) {
	Tk_FreeGC(scrollPtr->display, unixScrollPtr->troughGC);
    }
    unixScrollPtr->troughGC = newGC;
    if (unixScrollPtr->copyGC == NULL) {
    unixScrollPtr->troughGC = new;
    if (unixScrollPtr->copyGC == None) {
	gcValues.graphics_exposures = False;
	unixScrollPtr->copyGC = Tk_GetGC(scrollPtr->tkwin,
		GCGraphicsExposures, &gcValues);
    }
}

/*
433
434
435
436
437
438
439
440

441
442
443
444
445

446
447
448
449
450
451
452
428
429
430
431
432
433
434

435
436
437
438
439

440
441
442
443
444
445
446
447







-
+




-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkpScrollbarPosition(
    TkScrollbar *scrollPtr,
    register TkScrollbar *scrollPtr,
				/* Scrollbar widget record. */
    int x, int y)		/* Coordinates within scrollPtr's window. */
{
    int length, width, tmp;
    const int inset = scrollPtr->inset;
    register const int inset = scrollPtr->inset;

    if (scrollPtr->vertical) {
	length = Tk_Height(scrollPtr->tkwin);
	width = Tk_Width(scrollPtr->tkwin);
    } else {
	tmp = x;
	x = y;

Changes to unix/tkUnixSelect.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31





-
+

















-
+







/*
 * tkUnixSelect.c --
 *
 *	This file contains X specific routines for manipulating selections.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkInt.h"
#include "tkSelect.h"

typedef struct ConvertInfo {
    int offset;			/* The starting byte offset into the selection
				 * for the next chunk; -1 means all data has
				 * been transferred for this conversion. -2
				 * means only the final zero-length transfer
				 * still has to be done. Otherwise it is the
				 * offset of the next chunk of data to
				 * transfer. */
    Tcl_EncodingState state;	/* The encoding state needed across chunks. */
    char buffer[4];	/* A buffer to hold part of a UTF character
    char buffer[4];		/* A buffer to hold part of a UTF character
				 * that is split across chunks.*/
} ConvertInfo;

/*
 * When handling INCR-style selection retrievals, the selection owner uses the
 * following data structure to communicate between the ConvertSelection
 * function and TkSelPropProc.
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78







-
+







    Time time;			/* Timestamp corresponding to selection at
				 * beginning of request; used to abort
				 * transfer if selection changes. */
    struct IncrInfo *nextPtr;	/* Next in list of all INCR-style retrievals
				 * currently pending. */
} IncrInfo;

typedef struct {
typedef struct ThreadSpecificData {
    IncrInfo *pendingIncrs;	/* List of all incr structures currently
				 * active. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Largest property that we'll accept when sending or receiving the selection:
86
87
88
89
90
91
92
93
94


95
96

97
98
99

100
101

102
103

104
105
106
107
108
109
110
86
87
88
89
90
91
92


93
94
95

96
97
98

99
100

101
102

103
104
105
106
107
108
109
110







-
-
+
+

-
+


-
+

-
+

-
+








/*
 * Forward declarations for functions defined in this file:
 */

static void		ConvertSelection(TkWindow *winPtr,
			    XSelectionRequestEvent *eventPtr);
static void		IncrTimeoutProc(void *clientData);
static void		SelCvtFromX32(long *propPtr, unsigned long numValues, Atom type,
static void		IncrTimeoutProc(ClientData clientData);
static void		SelCvtFromX32(long *propPtr, int numValues, Atom type,
			    Tk_Window tkwin, Tcl_DString *dsPtr);
static void		SelCvtFromX8(char *propPtr, unsigned long numValues, Atom type,
static void		SelCvtFromX8(char *propPtr, int numValues, Atom type,
			    Tk_Window tkwin, Tcl_DString *dsPtr);
static long *		SelCvtToX(char *string, Atom type, Tk_Window tkwin,
			    Tcl_Size *numLongsPtr);
			    int *numLongsPtr);
static int		SelectionSize(TkSelHandler *selPtr);
static void		SelRcvIncrProc(void *clientData,
static void		SelRcvIncrProc(ClientData clientData,
			    XEvent *eventPtr);
static void		SelTimeoutProc(void *clientData);
static void		SelTimeoutProc(ClientData clientData);

/*
 *----------------------------------------------------------------------
 *
 * TkSelGetSelection --
 *
 *	Retrieve the specified selection from another process.
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141







-
+







				 * selection (determines display from which to
				 * retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection is to be
				 * returned. */
    Tk_GetSelProc *proc,	/* Function to call to process the selection,
				 * once it has been retrieved. */
    void *clientData)	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    TkSelRetrievalInfo retr;
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;

    /*
     * The selection is owned by some other process. To retrieve it, first
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
161
162
163
164
165
166
167







168
169
170
171
172
173
174







-
-
-
-
-
-
-







    retr.result = -1;
    retr.idleTime = 0;
    retr.encFlags = TCL_ENCODING_START;
    retr.nextPtr = pendingRetrievals;
    Tcl_DStringInit(&retr.buf);
    pendingRetrievals = &retr;

    /*
     * Delete the property to indicate that no parameters are supplied for
     * the conversion request.
     */

    XDeleteProperty(winPtr->display, retr.winPtr->window, retr.property);

    /*
     * Initiate the request for the selection. Note: can't use TkCurrentTime
     * for the time. If we do, and this application hasn't received any X
     * events in a long time, the current time will be way in the past and
     * could even predate the time when the selection was made; if this
     * happens, the request will be rejected.
     */
236
237
238
239
240
241
242
243

244
245
246
247



248
249
250
251
252
253
254

255
256
257
258
259
260
261
229
230
231
232
233
234
235

236
237



238
239
240

241
242
243
244
245

246
247
248
249
250
251
252
253







-
+

-
-
-
+
+
+
-





-
+







 *	until eventually there's no more selection to fetch.
 *
 *----------------------------------------------------------------------
 */

void
TkSelPropProc(
    XEvent *eventPtr)	/* X PropertyChange event. */
    register XEvent *eventPtr)	/* X PropertyChange event. */
{
    IncrInfo *incrPtr;
    TkSelHandler *selPtr;
    int length;
    register IncrInfo *incrPtr;
    register TkSelHandler *selPtr;
    int length, numItems;
    Tcl_Size numItems;
    unsigned long i;
    Atom target, formatType;
    long buffer[TK_SEL_WORDS_AT_ONCE];
    TkDisplay *dispPtr = TkGetDisplay(eventPtr->xany.display);
    Tk_ErrorHandler errorHandler;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * See if this event announces the deletion of a property being used for
     * an INCR transfer. If so, then add the next chunk of data to the
     * property.
     */
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+










-
+



















-
+







		if (ip.selPtr == NULL) {
		    /*
		     * The selection handler deleted itself.
		     */

		    return;
		}
		if (numItems == TCL_INDEX_NONE) {
		if (numItems < 0) {
		    numItems = 0;
		}
		numItems += length;
		if (numItems > TK_SEL_BYTES_AT_ONCE) {
		    Tcl_Panic("selection handler returned too many bytes");
		}
	    }
	    ((char *) buffer)[numItems] = 0;

	    errorHandler = Tk_CreateErrorHandler(eventPtr->xproperty.display,
		    -1, -1, -1, NULL, NULL);
		    -1, -1, -1, (int (*)()) NULL, NULL);

	    /*
	     * Encode the data using the proper format for each type.
	     */

	    if ((formatType == XA_STRING)
		    || (dispPtr && formatType==dispPtr->utf8Atom)
		    || (dispPtr && formatType==dispPtr->compoundTextAtom)) {
		Tcl_DString ds;
		int encodingCvtFlags;
		int srcLen, dstLen, result, srcRead, dstWrote, soFar;
		char *src, *dst;
		Tcl_Encoding encoding;

		/*
		 * Set up the encoding state based on the format and whether
		 * this is the first and/or last chunk.
		 */

		encodingCvtFlags = TCL_ENCODING_PROFILE_TCL8;
		encodingCvtFlags = 0;
		if (incrPtr->converts[i].offset == 0) {
		    encodingCvtFlags |= TCL_ENCODING_START;
		}
		if (numItems < TK_SEL_BYTES_AT_ONCE) {
		    encodingCvtFlags |= TCL_ENCODING_END;
		}
		if (formatType == XA_STRING) {
443
444
445
446
447
448
449
450

451
452
453

454
455
456
457
458
459
460
435
436
437
438
439
440
441

442
443
444

445
446
447
448
449
450
451
452







-
+


-
+







			(unsigned char *) Tcl_DStringValue(&ds),
			Tcl_DStringLength(&ds));

		/*
		 * Preserve any left-over bytes.
		 */

		if (srcLen > 3) {
		if (srcLen > 4) {
		    Tcl_Panic("selection conversion left too many bytes unconverted");
		}
		memcpy(incrPtr->converts[i].buffer, src, srcLen + 1);
		memcpy(incrPtr->converts[i].buffer, src, (size_t) srcLen+1);
		Tcl_DStringFree(&ds);
	    } else {
		/*
		 * Set the property to the encoded string value.
		 */

		char *propPtr = (char *) SelCvtToX((char *) buffer,
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482







-
+







	    /*
	     * Compute the next offset value. If this was the last chunk, then
	     * set the offset to -2. If this was an empty chunk, then set the
	     * offset to -1 to indicate we are done.
	     */

	    if (numItems < TK_SEL_BYTES_AT_ONCE) {
		if (numItems < 1) {
		if (numItems <= 0) {
		    incrPtr->converts[i].offset = -1;
		    incrPtr->numIncrs--;
		} else {
		    incrPtr->converts[i].offset = -2;
		}
	    } else {
		/*
516
517
518
519
520
521
522
523

524
525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

545
546
547
548

549
550
551
552
553
554
555
508
509
510
511
512
513
514

515
516
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
543
544
545
546
547
548







-
+


-
+

















-
+




+







 *
 *--------------------------------------------------------------
 */

void
TkSelEventProc(
    Tk_Window tkwin,		/* Window for which event was targeted. */
    XEvent *eventPtr)	/* X event: either SelectionClear,
    register XEvent *eventPtr)	/* X event: either SelectionClear,
				 * SelectionRequest, or SelectionNotify. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    Tcl_Interp *interp;

    /*
     * Case #1: SelectionClear events.
     */

    if (eventPtr->type == SelectionClear) {
	TkSelClearSelection(tkwin, eventPtr);
    }

    /*
     * Case #2: SelectionNotify events. Call the relevant function to handle
     * the incoming selection.
     */

    if (eventPtr->type == SelectionNotify) {
	TkSelRetrievalInfo *retrPtr;
	register TkSelRetrievalInfo *retrPtr;
	char *propInfo, **propInfoPtr = &propInfo;
	Atom type;
	int format, result;
	unsigned long numItems, bytesAfter;
	Tcl_DString ds;

	for (retrPtr = pendingRetrievals; ; retrPtr = retrPtr->nextPtr) {
	    if (retrPtr == NULL) {
		return;
	    }
	    if ((retrPtr->winPtr == winPtr)
		    && (retrPtr->selection == eventPtr->xselection.selection)
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
571
572
573
574
575
576
577

578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593







-
+








-







		&type, &format, &numItems, &bytesAfter,
		(unsigned char **) propInfoPtr);
	if ((result != Success) || (type == None)) {
	    return;
	}
	if (bytesAfter != 0) {
	    Tcl_SetObjResult(retrPtr->interp, Tcl_NewStringObj(
		    "selection property too large", TCL_INDEX_NONE));
		    "selection property too large", -1));
	    Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "SIZE",NULL);
	    retrPtr->result = TCL_ERROR;
	    XFree(propInfo);
	    return;
	}
	if ((type == XA_STRING) || (type == dispPtr->textAtom)
		|| (type == dispPtr->compoundTextAtom)) {
	    Tcl_Encoding encoding;
		Tcl_DString ds;

	    if (format != 8) {
		Tcl_SetObjResult(retrPtr->interp, Tcl_ObjPrintf(
			"bad format for string selection: wanted \"8\", got \"%d\"",
			format));
		Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "FORMAT",
			NULL);
617
618
619
620
621
622
623
624

625
626
627
628
629


630
631
632
633
634
635
636
609
610
611
612
613
614
615

616
617
618
619
620

621
622
623
624
625
626
627
628
629







-
+




-
+
+







	     */

	    if (type == dispPtr->compoundTextAtom) {
		encoding = Tcl_GetEncoding(NULL, "iso2022");
	    } else {
		encoding = Tcl_GetEncoding(NULL, "iso8859-1");
	    }
	    char *str = Tcl_ExternalToUtfDString(encoding, propInfo, numItems, &ds);
	    Tcl_ExternalToUtfDString(encoding, propInfo, (int)numItems, &ds);
	    if (encoding) {
		Tcl_FreeEncoding(encoding);
	    }

	    retrPtr->result = retrPtr->proc(retrPtr->clientData, interp, str);
	    retrPtr->result = retrPtr->proc(retrPtr->clientData, interp,
		    Tcl_DStringValue(&ds));
	    Tcl_DStringFree(&ds);
	    Tcl_Release(interp);
	} else if (type == dispPtr->utf8Atom) {
	    /*
	     * The X selection data is in UTF-8 format already. We can't
	     * guarantee that propInfo is NULL-terminated, so we might have to
	     * copy the string.
645
646
647
648
649
650
651
652

653
654
655
656
657
658
659
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652







-
+







		Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "FORMAT",
			NULL);
		retrPtr->result = TCL_ERROR;
		return;
	    }

	    if (propInfo[numItems] != '\0') {
		propData = (char *)ckalloc(numItems + 1);
		propData = ckalloc(numItems + 1);
		strcpy(propData, propInfo);
		propData[numItems] = '\0';
	    }
	    retrPtr->result = retrPtr->proc(retrPtr->clientData,
		    retrPtr->interp, propData);
	    if (propData != propInfo) {
		ckfree(propData);
686
687
688
689
690
691
692
693

694
695
696

697
698
699
700
701
702
703
679
680
681
682
683
684
685

686
687
688

689
690
691
692
693
694
695
696







-
+


-
+







		Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "FORMAT",
			NULL);
		retrPtr->result = TCL_ERROR;
		return;
	    }
	    Tcl_DStringInit(&ds);
	    if (format == 32) {
		SelCvtFromX32((long *) propInfo, numItems, type,
		SelCvtFromX32((long *) propInfo, (int) numItems, type,
			(Tk_Window) winPtr, &ds);
	    } else {
		SelCvtFromX8((char *) propInfo, numItems, type,
		SelCvtFromX8((char *) propInfo, (int) numItems, type,
			(Tk_Window) winPtr, &ds);
	    }
	    interp = retrPtr->interp;
	    Tcl_Preserve(interp);
	    retrPtr->result = retrPtr->proc(retrPtr->clientData,
		    interp, Tcl_DStringValue(&ds));
	    Tcl_Release(interp);
736
737
738
739
740
741
742
743

744
745

746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764

765
766
767
768
769

770
771
772
773
774
775
776
729
730
731
732
733
734
735

736
737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756

757
758
759
760
761

762
763
764
765
766
767
768
769







-
+

-
+


















-
+




-
+







 *	retrieval.
 *
 *----------------------------------------------------------------------
 */

static void
SelTimeoutProc(
    void *clientData)	/* Information about retrieval in progress. */
    ClientData clientData)	/* Information about retrieval in progress. */
{
    TkSelRetrievalInfo *retrPtr = (TkSelRetrievalInfo *)clientData;
    register TkSelRetrievalInfo *retrPtr = clientData;

    /*
     * Make sure that the retrieval is still in progress. Then see how long
     * it's been since any sort of response was received from the other side.
     */

    if (retrPtr->result != -1) {
	return;
    }
    retrPtr->idleTime++;
    if (retrPtr->idleTime >= 5) {
	/*
	 * Use a careful function to store the error message, because the
	 * result could already be partially filled in with a partial
	 * selection return.
	 */

	Tcl_SetObjResult(retrPtr->interp, Tcl_NewStringObj(
		"selection owner didn't respond", TCL_INDEX_NONE));
		"selection owner didn't respond", -1));
	Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "IGNORED", NULL);
	retrPtr->result = TCL_ERROR;
    } else {
	retrPtr->timeout = Tcl_CreateTimerHandler(1000, SelTimeoutProc,
		retrPtr);
		(ClientData) retrPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ConvertSelection --
792
793
794
795
796
797
798
799

800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

817
818
819
820


821
822
823
824
825
826
827
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808

809
810
811


812
813
814
815
816
817
818
819
820







-
+
















-
+


-
-
+
+








static void
ConvertSelection(
    TkWindow *winPtr,		/* Window that received the conversion
				 * request; may not be selection's current
				 * owner, be we set it to the current
				 * owner. */
    XSelectionRequestEvent *eventPtr)
    register XSelectionRequestEvent *eventPtr)
				/* Event describing request. */
{
	union {
		XSelectionEvent xsel;
		XEvent ev;
	} reply;	/* Used to notify requestor that selection
				 * info is ready. */
    int multiple;		/* Non-zero means a MULTIPLE request is being
				 * handled. */
    IncrInfo incr;		/* State of selection conversion. */
    Atom singleInfo[2];		/* incr.multAtoms points here except for
				 * multiple conversions. */
    unsigned long i;
    Tk_ErrorHandler errorHandler;
    TkSelectionInfo *infoPtr;
    TkSelInProgress ip;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    errorHandler = Tk_CreateErrorHandler(eventPtr->display, -1, -1,
	    -1, NULL, NULL);
    errorHandler = Tk_CreateErrorHandler(eventPtr->display, -1, -1,-1,
	    (int (*)()) NULL, NULL);

    /*
     * Initialize the reply event.
     */

    reply.xsel.type = SelectionNotify;
    reply.xsel.serial = 0;
868
869
870
871
872
873
874
875

876
877

878
879
880
881
882

883
884
885
886
887
888
889
890
891
892
893
894
895
896

897
898
899
900
901
902


903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923

924
925
926
927
928

929
930
931
932
933
934
935
936
937
938
939
940

941
942
943
944
945
946
947
861
862
863
864
865
866
867

868


869
870
871
872
873

874
875
876
877
878
879
880
881
882
883
884
885
886
887

888
889
890
891
892


893
894

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913

914
915
916
917
918

919
920
921
922
923
924
925
926
927
928
929
930

931
932
933
934
935
936
937
938







-
+
-
-
+




-
+













-
+




-
-
+
+
-



















-
+




-
+











-
+








	multiple = 1;
	incr.multAtoms = NULL;
	if (eventPtr->property == None) {
	    goto refuse;
	}
	result = XGetWindowProperty(eventPtr->display, eventPtr->requestor,
		eventPtr->property, 0, MAX_PROP_WORDS, False,
		eventPtr->property, 0, MAX_PROP_WORDS, False, XA_ATOM,
		winPtr->dispPtr->atomPairAtom, &type, &format,
		&incr.numConversions, &bytesAfter,
		&type, &format, &incr.numConversions, &bytesAfter,
		(unsigned char **) multAtomsPtr);
	if ((result != Success) || (bytesAfter != 0) || (format != 32)
		|| (type == None)) {
	    if (incr.multAtoms != NULL) {
		XFree(incr.multAtoms);
		XFree((char *) incr.multAtoms);
	    }
	    goto refuse;
	}
	incr.numConversions /= 2;	/* Two atoms per conversion. */
    }

    /*
     * Loop through all of the requested conversions, and either return the
     * entire converted selection, if it can be returned in a single bunch, or
     * return INCR information only (the actual selection will be returned
     * below).
     */

    incr.converts = (ConvertInfo *)ckalloc(incr.numConversions * sizeof(ConvertInfo));
    incr.converts = ckalloc(incr.numConversions * sizeof(ConvertInfo));
    incr.numIncrs = 0;
    for (i = 0; i < incr.numConversions; i++) {
	Atom target, property, type;
	long buffer[TK_SEL_WORDS_AT_ONCE];
	TkSelHandler *selPtr;
	Tcl_Size numItems;
	register TkSelHandler *selPtr;
	int numItems, format;
	int format;
	char *propPtr;

	target = incr.multAtoms[2*i];
	property = incr.multAtoms[2*i + 1];
	incr.converts[i].offset = -1;
	incr.converts[i].buffer[0] = '\0';

	for (selPtr = winPtr->selHandlerList; selPtr != NULL;
		selPtr = selPtr->nextPtr) {
	    if ((selPtr->target == target)
		    && (selPtr->selection == eventPtr->selection)) {
		break;
	    }
	}

	if (selPtr == NULL) {
	    /*
	     * Nobody seems to know about this kind of request. If it's of a
	     * sort that we can handle without any help, do it. Otherwise mark
	     * the request as an error.
	     * the request as an errror.
	     */

	    numItems = TkSelDefaultSelection(infoPtr, target, (char *) buffer,
		    TK_SEL_BYTES_AT_ONCE, &type);
	    if (numItems == TCL_INDEX_NONE) {
	    if (numItems < 0) {
		incr.multAtoms[2*i + 1] = None;
		continue;
	    }
	} else {
	    ip.selPtr = selPtr;
	    ip.nextPtr = TkSelGetInProgress();
	    TkSelSetInProgress(&ip);
	    type = selPtr->format;
	    numItems = selPtr->proc(selPtr->clientData, 0, (char *) buffer,
		    TK_SEL_BYTES_AT_ONCE);
	    TkSelSetInProgress(ip.nextPtr);
	    if ((ip.selPtr == NULL) || (numItems == TCL_INDEX_NONE)) {
	    if ((ip.selPtr == NULL) || (numItems < 0)) {
		incr.multAtoms[2*i + 1] = None;
		continue;
	    }
	    if (numItems > TK_SEL_BYTES_AT_ONCE) {
		Tcl_Panic("selection handler returned too many bytes");
	    }
	    ((char *) buffer)[numItems] = '\0';
992
993
994
995
996
997
998
999

1000
1001
1002


1003
1004
1005
1006
1007
1008
1009
983
984
985
986
987
988
989

990

991

992
993
994
995
996
997
998
999
1000







-
+
-

-
+
+







	     */

	    if (type == XA_STRING) {
		encoding = Tcl_GetEncoding(NULL, "iso8859-1");
	    } else {
		encoding = Tcl_GetEncoding(NULL, "iso2022");
	    }
	    unsigned char *str = (unsigned char *)Tcl_UtfToExternalDString(encoding,
	    Tcl_UtfToExternalDString(encoding, (char *) buffer, -1, &ds);
		    (char *) buffer, TCL_INDEX_NONE, &ds);
	    XChangeProperty(reply.xsel.display, reply.xsel.requestor,
		    property, type, 8, PropModeReplace, str,
		    property, type, 8, PropModeReplace,
		    (unsigned char *) Tcl_DStringValue(&ds),
		    Tcl_DStringLength(&ds));
	    if (encoding) {
		Tcl_FreeEncoding(encoding);
	    }
	    Tcl_DStringFree(&ds);
	} else {
	    propPtr = (char *) SelCvtToX((char *) buffer,
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042



1043
1044
1045
1046
1047
1048
1049
1024
1025
1026
1027
1028
1029
1030



1031
1032
1033
1034
1035
1036
1037
1038
1039
1040







-
-
-
+
+
+







	incr.reqWindow = reply.xsel.requestor;
	incr.time = infoPtr->time;
	incr.nextPtr = tsdPtr->pendingIncrs;
	tsdPtr->pendingIncrs = &incr;
    }
    if (multiple) {
	XChangeProperty(reply.xsel.display, reply.xsel.requestor,
		reply.xsel.property, winPtr->dispPtr->atomPairAtom,
		32, PropModeReplace, (unsigned char *) incr.multAtoms,
		incr.numConversions*2);
		reply.xsel.property, XA_ATOM, 32, PropModeReplace,
		(unsigned char *) incr.multAtoms,
		(int) incr.numConversions*2);
    } else {
	/*
	 * Not a MULTIPLE request. The first property in "multAtoms" got set
	 * to None if there was an error in conversion.
	 */

	reply.xsel.property = incr.multAtoms[1];
1061
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066







-
+







	IncrInfo *incrPtr2;

	while (incr.numIncrs > 0) {
	    Tcl_DoOneEvent(0);
	}
	Tcl_DeleteTimerHandler(incr.timeout);
	errorHandler = Tk_CreateErrorHandler(winPtr->display,
		-1, -1, -1, NULL, NULL);
		-1, -1, -1, (int (*)()) NULL, NULL);
	XSelectInput(reply.xsel.display, reply.xsel.requestor, 0L);
	Tk_DeleteErrorHandler(errorHandler);
	if (tsdPtr->pendingIncrs == &incr) {
	    tsdPtr->pendingIncrs = incr.nextPtr;
	} else {
	    for (incrPtr2 = tsdPtr->pendingIncrs; incrPtr2 != NULL;
		    incrPtr2 = incrPtr2->nextPtr) {
1083
1084
1085
1086
1087
1088
1089
1090

1091
1092
1093
1094
1095
1096
1097
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088







-
+








    /*
     * All done. Cleanup and return.
     */

    ckfree(incr.converts);
    if (multiple) {
	XFree(incr.multAtoms);
	XFree((char *) incr.multAtoms);
    }
    return;

    /*
     * An error occurred. Send back a refusal message.
     */

1120
1121
1122
1123
1124
1125
1126
1127
1128


1129
1130

1131
1132
1133
1134
1135
1136
1137
1111
1112
1113
1114
1115
1116
1117


1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128







-
-
+
+

-
+







 *	the higher-level function that initiated the selection retrieval.
 *
 *----------------------------------------------------------------------
 */

static void
SelRcvIncrProc(
    void *clientData,	/* Information about retrieval. */
    XEvent *eventPtr)	/* X PropertyChange event. */
    ClientData clientData,	/* Information about retrieval. */
    register XEvent *eventPtr)	/* X PropertyChange event. */
{
    TkSelRetrievalInfo *retrPtr = (TkSelRetrievalInfo *)clientData;
    register TkSelRetrievalInfo *retrPtr = clientData;
    char *propInfo, **propInfoPtr = &propInfo;
    Atom type;
    int format, result;
    unsigned long numItems, bytesAfter;
    Tcl_Interp *interp;

    if ((eventPtr->xproperty.atom != retrPtr->property)
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1136
1137
1138
1139
1140
1141
1142

1143
1144
1145
1146
1147
1148
1149
1150







-
+







	    True, (Atom) AnyPropertyType, &type, &format, &numItems,
	    &bytesAfter, (unsigned char **) propInfoPtr);
    if ((result != Success) || (type == None)) {
	return;
    }
    if (bytesAfter != 0) {
	Tcl_SetObjResult(retrPtr->interp, Tcl_NewStringObj(
		"selection property too large", TCL_INDEX_NONE));
		"selection property too large", -1));
	Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "SIZE", NULL);
	retrPtr->result = TCL_ERROR;
	goto done;
    }
    if ((type == XA_STRING)
	    || (type == retrPtr->winPtr->dispPtr->textAtom)
	    || (type == retrPtr->winPtr->dispPtr->utf8Atom)
1222
1223
1224
1225
1226
1227
1228
1229
1230


1231
1232
1233
1234
1235
1236
1237
1213
1214
1215
1216
1217
1218
1219


1220
1221
1222
1223
1224
1225
1226
1227
1228







-
-
+
+








	/*
	 * Now convert the data, growing the destination buffer as needed.
	 */

	while (1) {
	    result = Tcl_ExternalToUtf(NULL, encoding, src, srcLen,
		    TCL_ENCODING_PROFILE_TCL8|retrPtr->encFlags,
		    &retrPtr->encState, dst, dstLen, &srcRead, &dstWrote, NULL);
		    retrPtr->encFlags, &retrPtr->encState,
		    dst, dstLen, &srcRead, &dstWrote, NULL);
	    soFar = dst + dstWrote - Tcl_DStringValue(dstPtr);
	    retrPtr->encFlags &= ~TCL_ENCODING_START;
	    src += srcRead;
	    srcLen -= srcRead;
	    if (result != TCL_CONVERT_NOSPACE) {
		Tcl_DStringSetLength(dstPtr, soFar);
		break;
1276
1277
1278
1279
1280
1281
1282
1283

1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
1284







-
+


-
+







	    Tcl_SetErrorCode(retrPtr->interp, "TK", "SELECTION", "FORMAT",
		    NULL);
	    retrPtr->result = TCL_ERROR;
	    goto done;
	}
	Tcl_DStringInit(&ds);
	if (format == 32) {
	    SelCvtFromX32((long *) propInfo, numItems, type,
	    SelCvtFromX32((long *) propInfo, (int) numItems, type,
		    (Tk_Window) retrPtr->winPtr, &ds);
	} else {
	    SelCvtFromX8((char *) propInfo, numItems, type,
	    SelCvtFromX8((char *) propInfo, (int) numItems, type,
		    (Tk_Window) retrPtr->winPtr, &ds);
	}
	interp = retrPtr->interp;
	Tcl_Preserve(interp);
	result = retrPtr->proc(retrPtr->clientData, interp,
		Tcl_DStringValue(&ds));
	Tcl_Release(interp);
1367
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385
1358
1359
1360
1361
1362
1363
1364

1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376







-
+



-
+







 *	incrPtr is marked as "all done".
 *
 *----------------------------------------------------------------------
 */

static void
IncrTimeoutProc(
    void *clientData)	/* Information about INCR-mode selection
    ClientData clientData)	/* Information about INCR-mode selection
				 * retrieval for which we are selection
				 * owner. */
{
    IncrInfo *incrPtr = (IncrInfo *)clientData;
    register IncrInfo *incrPtr = clientData;

    incrPtr->idleTime++;
    if (incrPtr->idleTime >= 5) {
	incrPtr->numIncrs = 0;
    } else {
	incrPtr->timeout = Tcl_CreateTimerHandler(1000, IncrTimeoutProc,
		incrPtr);
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424

1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414

1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1437







-
+



-
+














-
+







SelCvtToX(
    char *string,		/* String representation of selection. */
    Atom type,			/* Atom specifying the X format that is
				 * desired for the selection. Should not be
				 * XA_STRING (if so, don't bother calling this
				 * function at all). */
    Tk_Window tkwin,		/* Window that governs atom conversion. */
    Tcl_Size *numLongsPtr)		/* Number of 32-bit words contained in the
    int *numLongsPtr)		/* Number of 32-bit words contained in the
				 * result. */
{
    const char **field;
    Tcl_Size numFields, i;
    int numFields, i;
    long *propPtr;

    /*
     * The string is assumed to consist of fields separated by spaces. The
     * property gets generated by converting each field to an integer number,
     * in one of two ways:
     * 1. If type is XA_ATOM, convert each field to its corresponding atom.
     * 2. If type is anything else, convert each field from an ASCII number to
     *    a 32-bit binary number.
     */

    if (Tcl_SplitList(NULL, string, &numFields, &field) != TCL_OK) {
	return NULL;
    }
    propPtr = (long *)ckalloc(numFields * sizeof(long));
    propPtr = ckalloc(numFields * sizeof(long));

    /*
     * Convert the fields one-by-one.
     */

    for (i=0 ; i<numFields ; i++) {
	if (type == XA_ATOM) {
1484
1485
1486
1487
1488
1489
1490
1491
1492


1493
1494
1495
1496
1497
1498
1499
1475
1476
1477
1478
1479
1480
1481


1482
1483
1484
1485
1486
1487
1488
1489
1490







-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
SelCvtFromX32(
    long *propPtr,	/* Property value from X. */
    unsigned long numValues,		/* Number of 32-bit values in property. */
    register long *propPtr,	/* Property value from X. */
    int numValues,		/* Number of 32-bit values in property. */
    Atom type,			/* Type of property Should not be XA_STRING
				 * (if so, don't bother calling this function
				 * at all). */
    Tk_Window tkwin,		/* Window to use for atom conversion. */
    Tcl_DString *dsPtr)		/* Where to store the converted string. */
{
    /*
1508
1509
1510
1511
1512
1513
1514
1515

1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526



1527
1528
1529

1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541

1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
1513
1514



1515
1516
1517
1518
1519

1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531

1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544







-
+








-
-
-
+
+
+


-
+











-
+












    for ( ; numValues > 0; propPtr++, numValues--) {
	if (type == XA_ATOM) {
	    Tcl_DStringAppendElement(dsPtr,
		    Tk_GetAtomName(tkwin, (Atom) *propPtr));
	} else {
	    char buf[12];

	    snprintf(buf, sizeof(buf), "0x%x", (unsigned int) *propPtr);
	    sprintf(buf, "0x%x", (unsigned int) *propPtr);
	    Tcl_DStringAppendElement(dsPtr, buf);
	}
    }
    Tcl_DStringAppend(dsPtr, " ", 1);
}

static void
SelCvtFromX8(
    char *propPtr,	/* Property value from X. */
    unsigned long numValues,		/* Number of 8-bit values in property. */
    TCL_UNUSED(Atom),			/* Type of property Should not be XA_STRING
    register char *propPtr,	/* Property value from X. */
    int numValues,		/* Number of 8-bit values in property. */
    Atom type,			/* Type of property Should not be XA_STRING
				 * (if so, don't bother calling this function
				 * at all). */
    TCL_UNUSED(Tk_Window),		/* Window to use for atom conversion. */
    Tk_Window tkwin,		/* Window to use for atom conversion. */
    Tcl_DString *dsPtr)		/* Where to store the converted string. */
{
    /*
     * Convert each long in the property to a string value, which is a
     * hexadecimal string. We build the list in a Tcl_DString because this is
     * easier than trying to get the quoting correct ourselves.
     */

    for ( ; numValues > 0; propPtr++, numValues--) {
	char buf[12];

	snprintf(buf, sizeof(buf), "0x%x", (unsigned char) *propPtr);
	sprintf(buf, "0x%x", (unsigned char) *propPtr);
	Tcl_DStringAppendElement(dsPtr, buf);
    }
    Tcl_DStringAppend(dsPtr, " ", 1);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to unix/tkUnixSend.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16






-
-
-
+
+
+







/*
 * tkUnixSend.c --
 *
 *	This file provides functions that implement the "send" command,
 *	allowing commands to be passed from interpreter to interpreter.
 *
 * Copyright © 1989-1994 The Regents of the University of California.
 * Copyright © 1994-1996 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1989-1994 The Regents of the University of California.
 * Copyright (c) 1994-1996 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkUnixInt.h"

93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107







-
+







    int gotResponse;		/* 1 means a response has been received, 0
				 * means the command is still outstanding. */
    struct PendingCommand *nextPtr;
				/* Next in list of all outstanding commands.
				 * NULL means end of list. */
} PendingCommand;

typedef struct {
typedef struct ThreadSpecificData {
    PendingCommand *pendingCommands;
				/* List of all commands currently being waited
				 * for. */
    RegisteredInterp *interpListPtr;
				/* List of all interpreters registered in the
				 * current process. */
} ThreadSpecificData;
199
200
201
202
203
204
205
206

207
208
209
210
211

212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
199
200
201
202
203
204
205

206
207
208
209
210

211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226







-
+




-
+







-
+








#define MAX_PROP_WORDS 100000

/*
 * Forward declarations for functions defined later in this file:
 */

static int		AppendErrorProc(void *clientData,
static int		AppendErrorProc(ClientData clientData,
			    XErrorEvent *errorPtr);
static void		AppendPropCarefully(Display *display,
			    Window window, Atom property, char *value,
			    int length, PendingCommand *pendingPtr);
static Tcl_CmdDeleteProc DeleteProc;
static void		DeleteProc(ClientData clientData);
static void		RegAddName(NameRegistry *regPtr,
			    const char *name, Window commWindow);
static void		RegClose(NameRegistry *regPtr);
static void		RegDeleteName(NameRegistry *regPtr, const char *name);
static Window		RegFindName(NameRegistry *regPtr, const char *name);
static NameRegistry *	RegOpen(Tcl_Interp *interp,
			    TkDisplay *dispPtr, int lock);
static void		SendEventProc(void *clientData, XEvent *eventPtr);
static void		SendEventProc(ClientData clientData, XEvent *eventPtr);
static int		SendInit(Tcl_Interp *interp, TkDisplay *dispPtr);
static Tk_RestrictProc SendRestrictProc;
static int		ServerSecure(TkDisplay *dispPtr);
static void		UpdateCommWindow(TkDisplay *dispPtr);
static int		ValidateName(TkDisplay *dispPtr, const char *name,
			    Window commWindow, int oldOK);

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
257
258
259
260
261
262
263

264
265
266
267
268



269
270
271
272
273
274
275
276







-





-
-
-
+







				 * use the registry until we close it. */
{
    NameRegistry *regPtr;
    int result, actualFormat;
    unsigned long bytesAfter;
    Atom actualType;
    char **propertyPtr;
    Tk_ErrorHandler handler;

    if (dispPtr->commTkwin == NULL) {
	SendInit(interp, dispPtr);
    }

    handler = Tk_CreateErrorHandler(dispPtr->display, -1, -1, -1, NULL, NULL);

    regPtr = (NameRegistry *)ckalloc(sizeof(NameRegistry));
    regPtr = ckalloc(sizeof(NameRegistry));
    regPtr->dispPtr = dispPtr;
    regPtr->locked = 0;
    regPtr->modified = 0;
    regPtr->allocedByX = 1;
    propertyPtr = &regPtr->property;

    if (lock && !localData.sendDebug) {
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
302
303
304
305
306
307
308

309
310


311
312
313
314
315
316
317







-


-
-







	    XFree(regPtr->property);
	    regPtr->propLength = 0;
	    regPtr->property = NULL;
	}
	XDeleteProperty(dispPtr->display,
		RootWindow(dispPtr->display, 0),
		dispPtr->registryProperty);
        XSync(dispPtr->display, False);
    }

    Tk_DeleteErrorHandler(handler);

    /*
     * Xlib placed an extra null byte after the end of the property, just to
     * make sure that it is always NULL-terminated. Be sure to include this
     * byte in our count if it's needed to ensure null termination (note: as
     * of 8/95 I'm no longer sure why this code is needed; seems like it
     * shouldn't be).
     */
472
473
474
475
476
477
478
479

480
481
482

483
484
485
486
487
488
489
466
467
468
469
470
471
472

473
474
475

476
477
478
479
480
481
482
483







-
+


-
+







				 * registered. */
    Window commWindow)		/* X identifier for comm. window of
				 * application. */
{
    char id[30], *newProp;
    int idLength, newBytes;

    snprintf(id, sizeof(id), "%x ", (unsigned) commWindow);
    sprintf(id, "%x ", (unsigned) commWindow);
    idLength = strlen(id);
    newBytes = idLength + strlen(name) + 1;
    newProp = (char *)ckalloc(regPtr->propLength + newBytes);
    newProp = ckalloc(regPtr->propLength + newBytes);
    strcpy(newProp, id);
    strcpy(newProp+idLength, name);
    if (regPtr->property != NULL) {
	memcpy(newProp + newBytes, regPtr->property, regPtr->propLength);
	if (regPtr->allocedByX) {
	    XFree(regPtr->property);
	} else {
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
510
511
512
513
514
515
516





517
518
519
520
521
522
523







-
-
-
-
-







 */

static void
RegClose(
    NameRegistry *regPtr)	/* Pointer to a registry opened with a
				 * previous call to RegOpen. */
{
    Tk_ErrorHandler handler;

    handler = Tk_CreateErrorHandler(regPtr->dispPtr->display, -1, -1, -1,
            NULL, NULL);

    if (regPtr->modified) {
	if (!regPtr->locked && !localData.sendDebug) {
	    Tcl_Panic("The name registry was modified without being locked!");
	}
	XChangeProperty(regPtr->dispPtr->display,
		RootWindow(regPtr->dispPtr->display, 0),
		regPtr->dispPtr->registryProperty, XA_STRING, 8,
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
536
537
538
539
540
541
542


543
544
545
546
547
548
549







-
-







     * as invoking a subprocess that needs to do I/O to the screen); if the
     * ungrab command is still sitting in our output buffer, we could
     * deadlock.
     */

    XFlush(regPtr->dispPtr->display);

    Tk_DeleteErrorHandler(handler);

    if (regPtr->property != NULL) {
	if (regPtr->allocedByX) {
	    XFree(regPtr->property);
	} else {
	    ckfree(regPtr->property);
	}
    }
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
576
577
578
579
580
581
582

583

584
585
586
587
588
589
590







-
+
-







    Window commWindow,		/* X identifier for the application's comm.
				 * window. */
    int oldOK)			/* Non-zero means that we should consider an
				 * application to be valid even if it looks
				 * like an old-style (pre-4.0) one; 0 means
				 * consider these invalid. */
{
    int result, actualFormat;
    int result, actualFormat, argc, i;
    Tcl_Size argc, i;
    unsigned long length, bytesAfter;
    Atom actualType;
    char *property, **propertyPtr = &property;
    Tk_ErrorHandler handler;
    const char **argv;

    property = NULL;
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
742
743
744
745
746
747
748

749
750
751
752
753
754
755
756







-
+







	 * the side of safety.
	 */

	secure = 0;
#endif /* FamilyServerInterpreted */
    }
    if (addrPtr != NULL) {
	XFree(addrPtr);
	XFree((char *) addrPtr);
    }
    return secure;
#endif /* TK_NO_SECURITY */
}

/*
 *----------------------------------------------------------------------
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
791
792
793
794
795
796
797

798
799
800
801
802
803
804
805







-
+







    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    NameRegistry *regPtr;
    Tcl_Interp *interp;
    const char *actualName;
    Tcl_DString dString;
    int offset, i;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    interp = winPtr->mainPtr->interp;
    if (dispPtr->commTkwin == NULL) {
	SendInit(interp, winPtr->dispPtr);
    }

827
828
829
830
831
832
833
834

835
836
837
838
839
840
841
813
814
815
816
817
818
819

820
821
822
823
824
825
826
827







-
+







	if (riPtr == NULL) {
	    /*
	     * This interpreter isn't currently registered; create the data
	     * structure that will be used to register it locally, plus add
	     * the "send" command to the interpreter.
	     */

	    riPtr = (RegisteredInterp *)ckalloc(sizeof(RegisteredInterp));
	    riPtr = ckalloc(sizeof(RegisteredInterp));
	    riPtr->interp = interp;
	    riPtr->dispPtr = winPtr->dispPtr;
	    riPtr->nextPtr = tsdPtr->interpListPtr;
	    tsdPtr->interpListPtr = riPtr;
	    riPtr->name = NULL;
	    Tcl_CreateObjCommand(interp, "send", Tk_SendObjCmd, riPtr, DeleteProc);
	    if (Tcl_IsSafe(interp)) {
866
867
868
869
870
871
872
873

874
875
876
877
878
879

880
881
882
883
884
885
886
852
853
854
855
856
857
858

859
860
861
862
863
864

865
866
867
868
869
870
871
872







-
+





-
+







    actualName = name;
    offset = 0;				/* Needed only to avoid "used before
					 * set" compiler warnings. */
    for (i = 1; ; i++) {
	if (i > 1) {
	    if (i == 2) {
		Tcl_DStringInit(&dString);
		Tcl_DStringAppend(&dString, name, TCL_INDEX_NONE);
		Tcl_DStringAppend(&dString, name, -1);
		Tcl_DStringAppend(&dString, " #", 2);
		offset = Tcl_DStringLength(&dString);
		Tcl_DStringSetLength(&dString, offset+TCL_INTEGER_SPACE);
		actualName = Tcl_DStringValue(&dString);
	    }
	    snprintf(Tcl_DStringValue(&dString) + offset, TCL_INTEGER_SPACE, "%d", i);
	    sprintf(Tcl_DStringValue(&dString) + offset, "%d", i);
	}
	w = RegFindName(regPtr, actualName);
	if (w == None) {
	    break;
	}

	/*
911
912
913
914
915
916
917
918

919
920
921
922
923
924
925
897
898
899
900
901
902
903

904
905
906
907
908
909
910
911







-
+







     * We've now got a name to use. Store it in the name registry and in the
     * local entry for this application, plus put it in a property on the
     * commWindow.
     */

    RegAddName(regPtr, actualName, Tk_WindowId(dispPtr->commTkwin));
    RegClose(regPtr);
    riPtr->name = (char *)ckalloc(strlen(actualName) + 1);
    riPtr->name = ckalloc(strlen(actualName) + 1);
    strcpy(riPtr->name, actualName);
    if (actualName != name) {
	Tcl_DStringFree(&dString);
    }
    UpdateCommWindow(dispPtr);

    return riPtr->name;
940
941
942
943
944
945
946
947

948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964



965
966

967
968
969
970
971

972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
















1009
1010
1011
1012


1013
1014

1015
1016
1017
1018
1019
1020
1021
926
927
928
929
930
931
932

933
934
935
936
937
938
939
940
941
942
943
944

945
946
947


948
949
950
951

952
953
954
955
956

957
958
959
960
961
962
963
964
965
966
967
968
969
970






971


















972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987




988
989


990
991
992
993
994
995
996
997







-
+











-



-
-
+
+
+

-
+




-
+













-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
-
-
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_SendObjCmd(
    TCL_UNUSED(void *),	/* Information about sender (only dispPtr
    ClientData clientData,	/* Information about sender (only dispPtr
				 * field is used). */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    enum {
	SEND_ASYNC, SEND_DISPLAYOF, SEND_LAST
    };
    static const char *const sendOptions[] = {
	"-async",   "-displayof",   "--",  NULL
    };
    const char *stringRep, *destName;
    TkWindow *winPtr;
    Window commWindow;
    PendingCommand pending;
    RegisteredInterp *riPtr;
    int result, async, i, firstArg, index;
    register RegisteredInterp *riPtr;
    const char *destName;
    int result, index, async, i, firstArg;
    Tk_RestrictProc *prevProc;
    void *prevArg;
    ClientData prevArg;
    TkDisplay *dispPtr;
    Tcl_Time timeout;
    NameRegistry *regPtr;
    Tcl_DString request;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_Interp *localInterp;	/* Used when the interpreter to send the
				 * command to is within the same process. */

    /*
     * Process options, if any.
     */

    async = 0;
    winPtr = (TkWindow *) Tk_MainWindow(interp);
    if (winPtr == NULL) {
	return TCL_ERROR;
    }

    /*
     * Process the command options.
     */

    for (i = 1; i < (objc - 1); i++) {
    for (i = 1; i < objc; i++) {
	stringRep = Tcl_GetString(objv[i]);
	if (stringRep[0] == '-') {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
		    sizeof(char *), "option", 0, &index) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (index == SEND_ASYNC) {
		++async;
	    } else if (index == SEND_DISPLAYOF) {
		winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[++i]),
			(Tk_Window) winPtr);
		if (winPtr == NULL) {
		    return TCL_ERROR;
		}
	    } else /* if (index == SEND_LAST) */ {
		i++;
		break;
	    }
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
		sizeof(char *), "option", 0, &index) != TCL_OK) {
	    break;
	}
	if (index == SEND_ASYNC) {
	    ++async;
	} else if (index == SEND_DISPLAYOF) {
	    winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[++i]),
		    (Tk_Window) winPtr);
	    if (winPtr == NULL) {
		return TCL_ERROR;
	    }
	} else if (index == SEND_LAST) {
	    i++;
	    break;
	}
	} else {
	    break;
	}
    }
    }


    if (objc < (i + 2)) {
    if (objc < (i+2)) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"?-option value ...? interpName arg ?arg ...?");
	return TCL_ERROR;
    }
    destName = Tcl_GetString(objv[i]);
    firstArg = i+1;

1037
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047

1048
1049
1050

1051
1052

1053
1054
1055
1056
1057
1058
1059
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022

1023
1024
1025

1026
1027

1028
1029
1030
1031
1032
1033
1034
1035







-
+


-
+


-
+

-
+







		|| (strcmp(riPtr->name, destName) != 0)) {
	    continue;
	}
	Tcl_Preserve(riPtr);
	localInterp = riPtr->interp;
	Tcl_Preserve(localInterp);
	if (firstArg == (objc-1)) {
	    result = Tcl_EvalEx(localInterp, Tcl_GetString(objv[firstArg]), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(localInterp, Tcl_GetString(objv[firstArg]), -1, TCL_EVAL_GLOBAL);
	} else {
	    Tcl_DStringInit(&request);
	    Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), TCL_INDEX_NONE);
	    Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), -1);
	    for (i = firstArg+1; i < objc; i++) {
		Tcl_DStringAppend(&request, " ", 1);
		Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), TCL_INDEX_NONE);
		Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), -1);
	    }
	    result = Tcl_EvalEx(localInterp, Tcl_DStringValue(&request), TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(localInterp, Tcl_DStringValue(&request), -1, TCL_EVAL_GLOBAL);
	    Tcl_DStringFree(&request);
	}
	if (interp != localInterp) {
	    if (result == TCL_ERROR) {
		Tcl_Obj *errorObjPtr;

		/*
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110

1111
1112
1113
1114

1115
1116
1117

1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159




















1160
1161
1162
1163
1164
1165
1166
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085

1086
1087
1088
1089

1090
1091
1092

1093
1094
1095

1096

























1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137







-
+



-
+



-
+


-
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







     * Send the command to the target interpreter by appending it to the comm
     * window in the communication window.
     */

    localData.sendSerial++;
    Tcl_DStringInit(&request);
    Tcl_DStringAppend(&request, "\0c\0-n ", 6);
    Tcl_DStringAppend(&request, destName, TCL_INDEX_NONE);
    Tcl_DStringAppend(&request, destName, -1);
    if (!async) {
	char buffer[TCL_INTEGER_SPACE * 2];

	snprintf(buffer, sizeof(buffer), "%x %d",
	sprintf(buffer, "%x %d",
		(unsigned) Tk_WindowId(dispPtr->commTkwin),
		localData.sendSerial);
	Tcl_DStringAppend(&request, "\0-r ", 4);
	Tcl_DStringAppend(&request, buffer, TCL_INDEX_NONE);
	Tcl_DStringAppend(&request, buffer, -1);
    }
    Tcl_DStringAppend(&request, "\0-s ", 4);
    Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), TCL_INDEX_NONE);
    Tcl_DStringAppend(&request, Tcl_GetString(objv[firstArg]), -1);
    for (i = firstArg+1; i < objc; i++) {
	Tcl_DStringAppend(&request, " ", 1);
	Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), TCL_INDEX_NONE);
	Tcl_DStringAppend(&request, Tcl_GetString(objv[i]), -1);
    }

    if (!async) {
	/*
	 * Register the fact that we're waiting for a command to complete
	 * (this is needed by SendEventProc and by AppendErrorProc to pass
	 * back the command's results). Set up a timeout handler so that
	 * we can check during long sends to make sure that the destination
	 * application is still alive.
	 *
	 * We prepare the pending struct here in order to catch potential
	 * early X errors from AppendPropCarefully() due to XSync().
	 */

	pending.serial = localData.sendSerial;
	pending.dispPtr = dispPtr;
	pending.target = destName;
	pending.commWindow = commWindow;
	pending.interp = interp;
	pending.result = NULL;
	pending.errorInfo = NULL;
	pending.errorCode = NULL;
	pending.gotResponse = 0;
	pending.nextPtr = tsdPtr->pendingCommands;
	tsdPtr->pendingCommands = &pending;
    }
    (void) AppendPropCarefully(dispPtr->display, commWindow,
	    dispPtr->commProperty, Tcl_DStringValue(&request),
	    Tcl_DStringLength(&request) + 1, (async ? NULL : &pending));
    Tcl_DStringFree(&request);
    if (async) {
	/*
	 * This is an asynchronous send: return immediately without waiting
	 * for a response.
	 */

	return TCL_OK;
    }

    /*
     * Register the fact that we're waiting for a command to complete (this is
     * needed by SendEventProc and by AppendErrorProc to pass back the
     * command's results). Set up a timeout handler so that we can check
     * during long sends to make sure that the destination application is
     * still alive.
     */

    pending.serial = localData.sendSerial;
    pending.dispPtr = dispPtr;
    pending.target = destName;
    pending.commWindow = commWindow;
    pending.interp = interp;
    pending.result = NULL;
    pending.errorInfo = NULL;
    pending.errorCode = NULL;
    pending.gotResponse = 0;
    pending.nextPtr = tsdPtr->pendingCommands;
    tsdPtr->pendingCommands = &pending;

    /*
     * Enter a loop processing X events until the result comes in or the
     * target is declared to be dead. While waiting for a result, look only at
     * send-related events so that the send is synchronous with respect to
     * other events in the application.
     */

1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167







-
+







		if (ValidateName(pending.dispPtr, pending.target,
			pending.commWindow, 1)) {
		    msg = "target application died or uses a Tk version before 4.0";
		} else {
		    msg = "target application died";
		}
		pending.code = TCL_ERROR;
		pending.result = (char *)ckalloc(strlen(msg) + 1);
		pending.result = ckalloc(strlen(msg) + 1);
		strcpy(pending.result, msg);
		pending.gotResponse = 1;
	    } else {
		Tcl_GetTime(&timeout);
		timeout.sec += 2;
	    }
	}
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203







-
+


-
+







	 */

	Tcl_ResetResult(interp);
	Tcl_AddErrorInfo(interp, pending.errorInfo);
	ckfree(pending.errorInfo);
    }
    if (pending.errorCode != NULL) {
	Tcl_SetObjErrorCode(interp, Tcl_NewStringObj(pending.errorCode, TCL_INDEX_NONE));
	Tcl_SetObjErrorCode(interp, Tcl_NewStringObj(pending.errorCode, -1));
	ckfree(pending.errorCode);
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(pending.result, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(pending.result, -1));
    ckfree(pending.result);
    return pending.code;
}

/*
 *----------------------------------------------------------------------
 *
1287
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298
1299
1300
1301
1258
1259
1260
1261
1262
1263
1264

1265
1266
1267
1268
1269
1270
1271
1272







-
+







	p++;
	if (ValidateName(winPtr->dispPtr, entryName, commWindow, 1)) {
	    /*
	     * The application still exists; add its name to the result.
	     */

	    Tcl_ListObjAppendElement(NULL, resultObj,
		    Tcl_NewStringObj(entryName, TCL_INDEX_NONE));
		    Tcl_NewStringObj(entryName, -1));
	} else {
	    int count;

	    /*
	     * This name is bogus (perhaps the application died without
	     * cleaning up its entry in the registry?). Delete the name.
	     */
1363
1364
1365
1366
1367
1368
1369
1370

1371
1372
1373
1374
1375
1376
1377
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345
1346
1347
1348







-
+







 *	Sets up various data structures and windows.
 *
 *--------------------------------------------------------------
 */

static int
SendInit(
    TCL_UNUSED(Tcl_Interp *),	/* Interpreter to use for error reporting (no
    Tcl_Interp *interp,		/* Interpreter to use for error reporting (no
				 * errors are ever returned, but the
				 * interpreter is needed anyway). */
    TkDisplay *dispPtr)		/* Display to initialize. */
{
    XSetWindowAttributes atts;

    /*
1423
1424
1425
1426
1427
1428
1429
1430

1431
1432
1433

1434
1435
1436
1437
1438
1439
1440

1441
1442
1443
1444
1445
1446
1447
1394
1395
1396
1397
1398
1399
1400

1401
1402
1403

1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417
1418







-
+


-
+






-
+







 *	the (ostensibly waiting) "send" commands. The property is deleted.
 *
 *--------------------------------------------------------------
 */

static void
SendEventProc(
    void *clientData,	/* Display information. */
    ClientData clientData,	/* Display information. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkDisplay *dispPtr = (TkDisplay *)clientData;
    TkDisplay *dispPtr = clientData;
    char *propInfo, **propInfoPtr = &propInfo;
    const char *p;
    int result, actualFormat;
    unsigned long numItems, bytesAfter;
    Atom actualType;
    Tcl_Interp *remoteInterp;	/* Interp in which to execute the command. */
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if ((eventPtr->xproperty.atom != dispPtr->commProperty)
	    || (eventPtr->xproperty.state != PropertyNewValue)) {
	return;
    }

1540
1541
1542
1543
1544
1545
1546
1547

1548
1549
1550
1551
1552
1553
1554
1555

1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570


1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634

1635
1636

1637
1638
1639
1640
1641
1642
1643
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539


1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560

1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606

1607
1608
1609
1610
1611
1612
1613
1614







-
+







-
+













-
-
+
+



















-
+


















-
+





-
+


















-
+

-
+







	     * Initialize the result property, so that we're ready at any time
	     * if we need to return an error.
	     */

	    if (commWindow != None) {
		Tcl_DStringInit(&reply);
		Tcl_DStringAppend(&reply, "\0r\0-s ", 6);
		Tcl_DStringAppend(&reply, serial, TCL_INDEX_NONE);
		Tcl_DStringAppend(&reply, serial, -1);
		Tcl_DStringAppend(&reply, "\0-r ", 4);
	    }

	    if (!ServerSecure(dispPtr)) {
		if (commWindow != None) {
		    Tcl_DStringAppend(&reply,
			    "X server insecure (must use xauth-style "
			    "authorization); command ignored", TCL_INDEX_NONE);
			    "authorization); command ignored", -1);
		}
		result = TCL_ERROR;
		goto returnResult;
	    }

	    /*
	     * Locate the application, then execute the script.
	     */

	    for (riPtr = tsdPtr->interpListPtr; ; riPtr = riPtr->nextPtr) {
		if (riPtr == NULL) {
		    if (commWindow != None) {
			Tcl_DStringAppend(&reply,
				"receiver never heard of interpreter \"", TCL_INDEX_NONE);
			Tcl_DStringAppend(&reply, interpName, TCL_INDEX_NONE);
				"receiver never heard of interpreter \"", -1);
			Tcl_DStringAppend(&reply, interpName, -1);
			Tcl_DStringAppend(&reply, "\"", 1);
		    }
		    result = TCL_ERROR;
		    goto returnResult;
		}
		if (strcmp(riPtr->name, interpName) == 0) {
		    break;
		}
	    }
	    Tcl_Preserve(riPtr);

	    /*
	     * We must protect the interpreter because the script may enter
	     * another event loop, which might call Tcl_DeleteInterp.
	     */

	    remoteInterp = riPtr->interp;
	    Tcl_Preserve(remoteInterp);

	    result = Tcl_EvalEx(remoteInterp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(remoteInterp, script, -1, TCL_EVAL_GLOBAL);

	    /*
	     * The call to Tcl_Release may have released the interpreter which
	     * will cause the "send" command for that interpreter to be
	     * deleted. The command deletion callback will set the
	     * riPtr->interp field to NULL, hence the check below for NULL.
	     */

	    if (commWindow != None) {
		Tcl_DStringAppend(&reply, Tcl_GetString(Tcl_GetObjResult(remoteInterp)),
			-1);
		if (result == TCL_ERROR) {
		    const char *varValue;

		    varValue = Tcl_GetVar2(remoteInterp, "errorInfo",
			    NULL, TCL_GLOBAL_ONLY);
		    if (varValue != NULL) {
			Tcl_DStringAppend(&reply, "\0-i ", 4);
			Tcl_DStringAppend(&reply, varValue, TCL_INDEX_NONE);
			Tcl_DStringAppend(&reply, varValue, -1);
		    }
		    varValue = Tcl_GetVar2(remoteInterp, "errorCode",
			    NULL, TCL_GLOBAL_ONLY);
		    if (varValue != NULL) {
			Tcl_DStringAppend(&reply, "\0-e ", 4);
			Tcl_DStringAppend(&reply, varValue, TCL_INDEX_NONE);
			Tcl_DStringAppend(&reply, varValue, -1);
		    }
		}
	    }
	    Tcl_Release(remoteInterp);
	    Tcl_Release(riPtr);

	    /*
	     * Return the result to the sender if a commWindow was specified
	     * (if none was specified then this is an asynchronous call).
	     * Right now reply has everything but the completion code, but it
	     * needs the NULL to terminate the current option.
	     */

	returnResult:
	    if (commWindow != None) {
		if (result != TCL_OK) {
		    char buffer[TCL_INTEGER_SPACE];

		    snprintf(buffer, sizeof(buffer), "%d", result);
		    sprintf(buffer, "%d", result);
		    Tcl_DStringAppend(&reply, "\0-c ", 4);
		    Tcl_DStringAppend(&reply, buffer, TCL_INDEX_NONE);
		    Tcl_DStringAppend(&reply, buffer, -1);
		}
		(void) AppendPropCarefully(dispPtr->display, commWindow,
			dispPtr->commProperty, Tcl_DStringValue(&reply),
			Tcl_DStringLength(&reply) + 1, NULL);
		XFlush(dispPtr->display);
		Tcl_DStringFree(&reply);
	    }
1705
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717

1718
1719
1720
1721

1722
1723
1724
1725
1726
1727
1728
1676
1677
1678
1679
1680
1681
1682

1683
1684
1685
1686
1687

1688
1689
1690
1691

1692
1693
1694
1695
1696
1697
1698
1699







-
+




-
+



-
+







	    for (pcPtr = tsdPtr->pendingCommands; pcPtr != NULL;
		    pcPtr = pcPtr->nextPtr) {
		if ((serial != pcPtr->serial) || (pcPtr->result != NULL)) {
		    continue;
		}
		pcPtr->code = code;
		if (resultString != NULL) {
		    pcPtr->result = (char *)ckalloc(strlen(resultString) + 1);
		    pcPtr->result = ckalloc(strlen(resultString) + 1);
		    strcpy(pcPtr->result, resultString);
		}
		if (code == TCL_ERROR) {
		    if (errorInfo != NULL) {
			pcPtr->errorInfo = (char *)ckalloc(strlen(errorInfo) + 1);
			pcPtr->errorInfo = ckalloc(strlen(errorInfo) + 1);
			strcpy(pcPtr->errorInfo, errorInfo);
		    }
		    if (errorCode != NULL) {
			pcPtr->errorCode = (char *)ckalloc(strlen(errorCode) + 1);
			pcPtr->errorCode = ckalloc(strlen(errorCode) + 1);
			strcpy(pcPtr->errorCode, errorCode);
		    }
		}
		pcPtr->gotResponse = 1;
		break;
	    }
	} else {
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
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







+


-
-
+
+

-
-
-
+
+
+













-
-
+
+







}

/*
 * The function below is invoked if an error occurs during the XChangeProperty
 * operation above.
 */

	/* ARGSUSED */
static int
AppendErrorProc(
    void *clientData,	/* Command to mark complete, or NULL. */
    TCL_UNUSED(XErrorEvent *))	/* Information about error. */
    ClientData clientData,	/* Command to mark complete, or NULL. */
    XErrorEvent *errorPtr)	/* Information about error. */
{
    PendingCommand *pendingPtr = (PendingCommand *)clientData;
    PendingCommand *pcPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    PendingCommand *pendingPtr = clientData;
    register PendingCommand *pcPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (pendingPtr == NULL) {
	return 0;
    }

    /*
     * Make sure this command is still pending.
     */

    for (pcPtr = tsdPtr->pendingCommands; pcPtr != NULL;
	    pcPtr = pcPtr->nextPtr) {
	if ((pcPtr == pendingPtr) && (pcPtr->result == NULL)) {
	    pcPtr->result = (char *)ckalloc(strlen(pcPtr->target) + 50);
	    snprintf(pcPtr->result, strlen(pcPtr->target) + 50, "no application named \"%s\"",
	    pcPtr->result = ckalloc(strlen(pcPtr->target) + 50);
	    sprintf(pcPtr->result, "no application named \"%s\"",
		    pcPtr->target);
	    pcPtr->code = TCL_ERROR;
	    pcPtr->gotResponse = 1;
	    break;
	}
    }
    return 0;
1832
1833
1834
1835
1836
1837
1838
1839


1840
1841
1842


1843
1844

1845
1846
1847
1848
1849
1850
1851
1804
1805
1806
1807
1808
1809
1810

1811
1812
1813


1814
1815
1816

1817
1818
1819
1820
1821
1822
1823
1824







-
+
+

-
-
+
+

-
+







 *	The interpreter given by riPtr is unregistered.
 *
 *--------------------------------------------------------------
 */

static void
DeleteProc(
    void *clientData)	/* Info about registration */
    ClientData clientData)	/* Info about registration, passed as
				 * ClientData. */
{
    RegisteredInterp *riPtr = (RegisteredInterp *)clientData;
    RegisteredInterp *riPtr2;
    RegisteredInterp *riPtr = clientData;
    register RegisteredInterp *riPtr2;
    NameRegistry *regPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    regPtr = RegOpen(riPtr->interp, riPtr->dispPtr, 1);
    RegDeleteName(regPtr, riPtr->name);
    RegClose(regPtr);

    if (tsdPtr->interpListPtr == riPtr) {
1879
1880
1881
1882
1883
1884
1885

1886
1887
1888
1889


1890
1891
1892
1893
1894
1895
1896
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861


1862
1863
1864
1865
1866
1867
1868
1869
1870







+


-
-
+
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

    /* ARGSUSED */
static Tk_RestrictAction
SendRestrictProc(
    TCL_UNUSED(void *),		/* Not used. */
    XEvent *eventPtr)		/* Event that just arrived. */
    ClientData clientData,		/* Not used. */
    register XEvent *eventPtr)		/* Event that just arrived. */
{
    TkDisplay *dispPtr;

    if (eventPtr->type != PropertyNotify) {
	return TK_DEFER_EVENT;
    }
    for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
1925
1926
1927
1928
1929
1930
1931
1932

1933
1934
1935
1936
1937
1938
1939
1899
1900
1901
1902
1903
1904
1905

1906
1907
1908
1909
1910
1911
1912
1913







-
+







static void
UpdateCommWindow(
    TkDisplay *dispPtr)		/* Display whose commWindow is to be
				 * updated. */
{
    Tcl_DString names;
    RegisteredInterp *riPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    Tcl_DStringInit(&names);
    for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
	    riPtr = riPtr->nextPtr) {
	Tcl_DStringAppendElement(&names, riPtr->name);
    }
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
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







+


-
+

-
+








-
+
-








-
+

-
-
-
+
+
+
-
-





-







 *
 * Side effects:
 *	Depends on option; see below.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
TkpTestsendCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    enum {
	TESTSEND_BOGUS, TESTSEND_PROP, TESTSEND_SERIAL
    };
    static const char *const testsendOptions[] = {
	"bogus",   "prop",   "serial",  NULL
    };
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *winPtr = clientData;
    Tk_ErrorHandler handler;
    int index;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"option ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], testsendOptions,
	if (Tcl_GetIndexFromObjStruct(interp, objv[1], testsendOptions,
		sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
    if (index == TESTSEND_BOGUS) {
	    return TCL_ERROR;
	}
	if (index == TESTSEND_BOGUS) {
        handler = Tk_CreateErrorHandler(winPtr->dispPtr->display, -1, -1, -1,
                NULL, NULL);
	XChangeProperty(winPtr->dispPtr->display,
		RootWindow(winPtr->dispPtr->display, 0),
		winPtr->dispPtr->registryProperty, XA_INTEGER, 32,
		PropModeReplace,
		(unsigned char *) "This is bogus information", 6);
        Tk_DeleteErrorHandler(handler);
    } else if (index == TESTSEND_PROP) {
	int result, actualFormat;
	unsigned long length, bytesAfter;
	Atom actualType, propName;
	char *property, **propertyPtr = &property, *p, *end;
	Window w;

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
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







-
+





-
-

-










-
+
-



-



-
+











	    if ((result == Success) && (actualType != None)
		    && (actualFormat == 8) && (actualType == XA_STRING)) {
		for (p = property; (unsigned long)(p-property) < length; p++) {
		    if (*p == 0) {
			*p = '\n';
		    }
		}
		Tcl_SetObjResult(interp, Tcl_NewStringObj(property, TCL_INDEX_NONE));
		Tcl_SetObjResult(interp, Tcl_NewStringObj(property, -1));
	    }
	    if (property != NULL) {
		XFree(property);
	    }
	} else if (Tcl_GetString(objv[4])[0] == 0) {
            handler = Tk_CreateErrorHandler(winPtr->dispPtr->display,
                    -1, -1, -1, NULL, NULL);
	    XDeleteProperty(winPtr->dispPtr->display, w, propName);
            Tk_DeleteErrorHandler(handler);
	} else {
	    Tcl_DString tmp;

	    Tcl_DStringInit(&tmp);
	    for (p = Tcl_DStringAppend(&tmp, Tcl_GetString(objv[4]),
		    (int) strlen(Tcl_GetString(objv[4]))); *p != 0; p++) {
		if (*p == '\n') {
		    *p = 0;
		}
	    }
            handler = Tk_CreateErrorHandler(winPtr->dispPtr->display,

                    -1, -1, -1, NULL, NULL);
	    XChangeProperty(winPtr->dispPtr->display, w, propName, XA_STRING,
		    8, PropModeReplace, (unsigned char*)Tcl_DStringValue(&tmp),
		    p-Tcl_DStringValue(&tmp));
            Tk_DeleteErrorHandler(handler);
	    Tcl_DStringFree(&tmp);
	}
    } else if (index == TESTSEND_SERIAL) {
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(localData.sendSerial+1));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(localData.sendSerial+1));
    }
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted unix/tkUnixSysNotify.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233









































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkUnixSysNotify.c --
 *
 * 	tkUnixSysNotify.c implements a "sysnotify" Tcl command which
 * 	permits one to post system notifications based on the libnotify API.
 *
 * Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2020 Christian Werner for runtime linking
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkUnixInt.h"

/*
 * Runtime linking of libnotify.
 */

typedef int	(*fn_ln_init)(const char *);
typedef void	(*fn_ln_uninit)(void);
typedef void *	(*fn_ln_notification_new)(const char *, const char *,
			const char *, void *);
typedef int	(*fn_ln_notification_show)(void *, int *);

static struct {
    int				nopen;
    Tcl_LoadHandle		lib;
    fn_ln_init			init;
    fn_ln_uninit		uninit;
    fn_ln_notification_new	notification_new;
    fn_ln_notification_show	notification_show;
} ln_fns = {
    0, NULL, NULL, NULL, NULL, NULL
};

#define notify_init			ln_fns.init
#define notify_uninit			ln_fns.uninit
#define notify_notification_new		ln_fns.notification_new
#define notify_notification_show	ln_fns.notification_show

TCL_DECLARE_MUTEX(ln_mutex);

/*
 * Forward declarations for procedures defined in this file.
 */

static Tcl_CmdDeleteProc SysNotifyDeleteCmd;
static Tcl_ObjCmdProc SysNotifyCmd;

/*
 *----------------------------------------------------------------------
 *
 * SysNotifyDeleteCmd --
 *
 *      Delete notification and clean up.
 *
 * Results:
 *	Window destroyed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
SysNotifyDeleteCmd (
    TCL_UNUSED(void *))
{
    Tcl_MutexLock(&ln_mutex);
    if (--ln_fns.nopen == 0) {
	if (notify_uninit) {
	    notify_uninit();
	}
	if (ln_fns.lib != NULL) {
	    Tcl_FSUnloadFile(NULL, ln_fns.lib);
	}
	memset(&ln_fns, 0, sizeof(ln_fns));
    }
    Tcl_MutexUnlock(&ln_mutex);
}

/*
 *----------------------------------------------------------------------
 *
 * SysNotifyCreateCmd --
 *
 *      Create tray command and (unreal) window.
 *
 * Results:
 *	Icon tray and hidden window created.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
SysNotifyCmd(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const *objv)
{
    const char *title;
    const char *message;
    const char *icon;
    const char *appname = "Wish";
    void *notif;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "title message");
	return TCL_ERROR;
    }

    /*
     * Pass strings to notification, and use a sane platform-specific
     * icon in the alert.
     */

    title = Tcl_GetString(objv[1]);
    message = Tcl_GetString(objv[2]);
    icon = "dialog-information";


    /* Use the appname for libnotify initialization
     * See bug f63c37be3a for a discussion whether this should be
     * allowed at all on safe interpreters
     */
    if (!Tcl_IsSafe(interp)) {
	appname = ((TkWindow *)Tk_MainWindow(interp))->nameUid;
    }

    /*
     * Call to notify_init should go here to prevent test suite failure.
     */

    if (notify_init && notify_notification_new && notify_notification_show) {
	Tcl_Encoding enc;
	Tcl_DString dst, dsm;

	Tcl_DStringInit(&dst);
	Tcl_DStringInit(&dsm);
	enc = Tcl_GetEncoding(NULL, "utf-8");
	char *dstStr = Tcl_UtfToExternalDString(enc, title, TCL_INDEX_NONE, &dst);
	char *dsmStr = Tcl_UtfToExternalDString(enc, message, TCL_INDEX_NONE, &dsm);
	notify_init(appname);
	notif = notify_notification_new(dstStr, dsmStr, icon, NULL);
	notify_notification_show(notif, NULL);
	Tcl_DStringFree(&dsm);
	Tcl_DStringFree(&dst);
	Tcl_FreeEncoding(enc);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * SysNotify_Init --
 *
 *      Initialize the command.
 *
 * Results:
 *	Command initialized.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
SysNotify_Init(
    Tcl_Interp *interp)
{
    Tcl_MutexLock(&ln_mutex);
    if (ln_fns.nopen == 0) {
	int i = 0;
	Tcl_Obj *nameobj;
	static const char *lnlibs[] = {
	    "libnotify.so.4",
	    "libnotify.so.3",
	    "libnotify.so.2",
	    "libnotify.so.1",
	    "libnotify.so",
	    NULL
	};

	while (lnlibs[i] != NULL) {
	    Tcl_ResetResult(interp);
	    nameobj = Tcl_NewStringObj(lnlibs[i], TCL_INDEX_NONE);
	    Tcl_IncrRefCount(nameobj);
	    if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &ln_fns.lib)
		    == TCL_OK) {
		Tcl_DecrRefCount(nameobj);
		break;
	    }
	    Tcl_DecrRefCount(nameobj);
	    ++i;
	}
	if (ln_fns.lib != NULL) {
#define LN_SYM(name)							\
	    ln_fns.name = (fn_ln_ ## name)				\
		Tcl_FindSymbol(NULL, ln_fns.lib, "notify_" #name)
	    LN_SYM(init);
	    LN_SYM(uninit);
	    LN_SYM(notification_new);
	    LN_SYM(notification_show);
#undef LN_SYM
	}
    }
    ln_fns.nopen++;
    Tcl_MutexUnlock(&ln_mutex);
    if (!notify_init) return TCL_OK;

    Tcl_CreateObjCommand(interp, "::tk::sysnotify::_sysnotify", SysNotifyCmd,
	    interp, SysNotifyDeleteCmd);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * coding: utf-8
 * End:
 */

Deleted unix/tkUnixSysTray.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkUnixSysTray.c --
 *
 * 	tkUnixSysTray.c implements a "systray" Tcl command which permits to
 * 	change the system tray/taskbar icon of a Tk toplevel window and
 * 	to post system notifications.
 *
 * Copyright © 2005 Anton Kovalenko.
 * Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkUnixInt.h"

/*
 * Based extensively on the tktray extension package. Here we are removing
 * non-essential parts of tktray.
 */

#include <time.h>
#include <string.h>
#include <stdio.h>

#include <X11/X.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

/* XEmbed definitions
 * See http://www.freedesktop.org/wiki/Standards_2fxembed_2dspec
 * */
#define XEMBED_MAPPED           (1<<0)
/* System tray opcodes
 * See http://www.freedesktop.org/wiki/Standards_2fsystemtray_2dspec
 * */
#define SYSTEM_TRAY_REQUEST_DOCK    0
#define SYSTEM_TRAY_BEGIN_MESSAGE   1
#define SYSTEM_TRAY_CANCEL_MESSAGE  2

/* Flags of widget configuration options */
#define ICON_CONF_IMAGE         (1<<0)  /* Image changed */
#define ICON_CONF_REDISPLAY     (1<<1)  /* Redisplay required */
#define ICON_CONF_XEMBED        (1<<2)  /* Remapping or unmapping required */
#define ICON_CONF_CLASS         (1<<3)   /* TODO WM_CLASS update required */
#define ICON_CONF_FIRST_TIME    (1<<4)  /* For IconConfigureMethod invoked by the constructor */

/* Widget states */
#define ICON_FLAG_REDRAW_PENDING    (1<<0)
#define ICON_FLAG_ARGB32            (1<<1)
#define ICON_FLAG_DIRTY_EDGES       (1<<2)

#define TKU_NO_BAD_WINDOW_BEGIN(display) \
    { Tk_ErrorHandler error__handler = \
	    Tk_CreateErrorHandler(display, BadWindow, -1, -1, NULL, NULL);
#define TKU_NO_BAD_WINDOW_END Tk_DeleteErrorHandler(error__handler); }

/*Declaration for utility functions.*/
static void TKU_WmWithdraw(Tk_Window winPtr, Tcl_Interp* interp);
static Tk_Window TKU_GetWrapper(Tk_Window winPtr);
void TKU_AddInput(Display* dpy, Window win, long add_to_mask);
static Tk_Window TKU_Wrapper(Tk_Window w, Tcl_Interp* interp);
static Window TKU_XID(Tk_Window w);

/* Customized window withdraw */
static void
TKU_WmWithdraw(
    Tk_Window winPtr,
    TCL_UNUSED(Tcl_Interp *))
{
    TkpWmSetState((TkWindow*)winPtr, WithdrawnState);
}

/* The wrapper should exist */
static Tk_Window
TKU_GetWrapper(
    Tk_Window winPtr)
{
    return (Tk_Window)
	    TkpGetWrapperWindow((TkWindow*)winPtr);
}

/* Subscribe for extra X11 events (needed for MANAGER selection) */
void
TKU_AddInput(
    Display* dpy,
    Window win,
    long add_to_mask)
{
    XWindowAttributes xswa;
    TKU_NO_BAD_WINDOW_BEGIN(dpy)
        XGetWindowAttributes(dpy,win,&xswa);
        XSelectInput(dpy,win,xswa.your_event_mask|add_to_mask);
    TKU_NO_BAD_WINDOW_END
}

/* Get Tk Window wrapper (make it exist if ny) */
static Tk_Window
TKU_Wrapper(
    Tk_Window w,
    Tcl_Interp* interp)
{
    Tk_Window wrapper = TKU_GetWrapper(w);
    if (!wrapper) {
	Tk_MakeWindowExist(w);
	TKU_WmWithdraw(w, interp);
	Tk_MapWindow(w);
	wrapper = (Tk_Window) TKU_GetWrapper(w);
    }
    return wrapper;
}

/* Return X window id for Tk window (make it exist if ny) */
static Window
TKU_XID(
    Tk_Window w)
{
    Window xid = Tk_WindowId(w);
    if (xid == None) {
	Tk_MakeWindowExist(w);
	xid = Tk_WindowId(w);
    }
    return xid;
}

/* Data structure representing dock widget */
typedef struct {
    /* standard for widget */
    Tk_Window tkwin, drawingWin;
    Window wrapper;
    Window myManager;
    Window trayManager;

    Tk_OptionTable options;
    Tcl_Interp *interp;
    Tcl_Command widgetCmd;

    Tk_Image image; /* image to be drawn */

    /* Only one of imageVisualInstance and photo is needed for argb32
     * operations. Unless imageString changes, imageVisualInstance is
     * always valid for the same drawingWin instance, but photo is
     * invalidated by any "whole image" type change. */

    Tk_Image imageVisualInstance; /* image instance for use with argb32 */
    Tk_PhotoHandle photo;	  /* !null if it's really a photo */

    /* Offscreen pixmap is created for a given imageWidth,
     * imageHeight, drawingWin, and invalidated (and freed) on image
     * resize or drawingWin destruction.

     * Contents of this pixmap is synced on demand; when image changes
     * but is not resized, pixmap is marked as out-of-sync. Next time
     * when redisplay is needed, pixmap is updated before drawing
     * operation.
     */

    Pixmap offscreenPixmap;
    /* There is no need to recreate GC ever; it remains valid once
     * created */

    GC offscreenGC;

    /* XImage for drawing ARGB32 photo on offscreenPixmap.  Should be
     * freed and nullified each time when a pixmap is freed.  Needed
     * (and created) when redrawing an image being a photo on ARGB32
     * offscreen pixmap. */
    XImage *offscreenImage;	/* for photo (argb32) drawing code */

    Visual *bestVisual;		/* Visual, when it's specified by tray
				 * manager AND is guessed to be
				 * ARGB32 */
    Colormap bestColormap;	/* Colormap for bestVisual */

    Atom aMANAGER;
    Atom a_NET_SYSTEM_TRAY_Sn;
    Atom a_XEMBED_INFO;
    Atom a_NET_SYSTEM_TRAY_MESSAGE_DATA;
    Atom a_NET_SYSTEM_TRAY_OPCODE;
    Atom a_NET_SYSTEM_TRAY_ORIENTATION;
    Atom a_NET_SYSTEM_TRAY_VISUAL;

    int flags; /* ICON_FLAG_ - see defines above */
    int msgid; /* Last balloon message ID */
    int useShapeExt;

    int x,y,width,height;
    int imageWidth, imageHeight;
    int requestedWidth, requestedHeight;
    int visible; /* whether XEMBED_MAPPED should be set */
    int docked;	 /* whether an icon should be docked */
    char *imageString, /* option: -image as string */
	 *classString; /* option: -class as string */
} DockIcon;

/*
 * Forward declarations for procedures defined in this file.
 */

static Tcl_ObjCmdProc TrayIconCreateCmd;
static Tcl_ObjCmdProc TrayIconObjectCmd;
static int TrayIconConfigureMethod(DockIcon *icon, Tcl_Interp *interp,
	Tcl_Size objc, Tcl_Obj *const objv[], int addflags);
static int PostBalloon(DockIcon* icon, const char *utf8msg,
	long timeout);
static void CancelBalloon(DockIcon* icon, int msgid);
static int QueryTrayOrientation(DockIcon* icon);

static Tcl_CmdDeleteProc TrayIconDeleteProc;
static Atom DockSelectionAtomFor(Tk_Window tkwin);
static void DockToManager(DockIcon *icon);
static void CreateTrayIconWindow(DockIcon *icon);

static void TrayIconRequestSize(DockIcon* icon, int w, int h);
static void TrayIconForceImageChange(DockIcon* icon);
static void TrayIconUpdate(DockIcon* icon, int mask);

static void EventuallyRedrawIcon(DockIcon* icon);
static void DisplayIcon(void *cd);

static void RetargetEvent(DockIcon *icon, XEvent *ev);

static void TrayIconEvent(void *cd, XEvent* ev);
static void UserIconEvent(void *cd, XEvent* ev);
static void TrayIconWrapperEvent(void *cd, XEvent* ev);
static int IconGenericHandler(void *cd, XEvent *ev);

int Tktray_Init (Tcl_Interp* interp );

/*
 *----------------------------------------------------------------------
 *
 * TrayIconObjectCmd --
 *
 * 	Manage attributes of tray icon.
 *
 * Results:
 *	Various values of the tray icon are set and retrieved.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TrayIconObjectCmd(
    void *cd,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    DockIcon *icon = (DockIcon*)cd;
    int bbox[4] = {0,0,0,0};
    Tcl_Obj * bboxObj;
    int wcmd;
    int i;
    XWindowAttributes xwa;
    Window bogus;
    int msgid;

    enum {XWC_CONFIGURE = 0, XWC_CGET, XWC_BALLOON, XWC_CANCEL,
            XWC_BBOX, XWC_DOCKED, XWC_ORIENTATION};
    const char *st_wcmd[] = {"configure", "cget", "balloon", "cancel",
            "bbox", "docked", "orientation", NULL};

    long timeout = 0;
    Tcl_Obj* optionValue;

    if (objc<2) {
	Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
	return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObj(interp, objv[1], st_wcmd,
            "subcommand", TCL_EXACT, &wcmd) != TCL_OK) {
	return TCL_ERROR;
    }

    switch (wcmd) {
    case XWC_CONFIGURE:
	return TrayIconConfigureMethod(icon,interp,objc-2,objv+2,0);

    case XWC_CGET:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp,2,objv,"option");
	    return TCL_ERROR;
	}
	optionValue = Tk_GetOptionValue(interp,(char*)icon,
                icon->options,objv[2],icon->tkwin);
	if (optionValue) {
	    Tcl_SetObjResult(interp,optionValue);
	    return TCL_OK;
	} else {
	    return TCL_ERROR;
	}

    case XWC_BALLOON:
	if ((objc != 3) && (objc != 4)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "message ?timeout?");
	    return TCL_ERROR;
	}
	if (objc == 4) {
	    if (Tcl_GetLongFromObj(interp,objv[3],&timeout) != TCL_OK)
		return TCL_ERROR;
	}
	msgid = PostBalloon(icon,Tcl_GetString(objv[2]), timeout);
	Tcl_SetObjResult(interp,Tcl_NewIntObj(msgid));
	return TCL_OK;

    case XWC_CANCEL:
	if (objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "messageId");
	    return TCL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp,objv[2],&msgid) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (msgid)
	    CancelBalloon(icon,msgid);
	return TCL_OK;

    case XWC_BBOX:
	if (icon->drawingWin) {
	    XGetWindowAttributes(Tk_Display(icon->drawingWin),
                    TKU_XID(icon->drawingWin), &xwa);

	    XTranslateCoordinates(Tk_Display(icon->drawingWin),
                    TKU_XID(icon->drawingWin), xwa.root, 0,0,
                    &icon->x, &icon->y, &bogus);
	    bbox[0] = icon->x;
	    bbox[1] = icon->y;
	    bbox[2] = bbox[0] + icon->width - 1;
	    bbox[3] = bbox[1] + icon->height - 1;
	}
	bboxObj = Tcl_NewObj();
	for (i = 0; i < 4; ++i) {
	    Tcl_ListObjAppendElement(interp, bboxObj, Tcl_NewIntObj(bbox[i]));
	}
	Tcl_SetObjResult(interp, bboxObj);
	return TCL_OK;

    case XWC_DOCKED:
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(icon->myManager != None));
	return TCL_OK;

    case XWC_ORIENTATION:
	if (icon->myManager == None || icon->wrapper == None) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("none", TCL_INDEX_NONE));
	} else {
	    switch(QueryTrayOrientation(icon)) {
	    case 0:
		Tcl_SetObjResult(interp, Tcl_NewStringObj("horizontal", TCL_INDEX_NONE));
		break;
	    case 1:
		Tcl_SetObjResult(interp, Tcl_NewStringObj("vertical", TCL_INDEX_NONE));
		break;
	    default:
		Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown", TCL_INDEX_NONE));
		break;
	    }
	}
	return TCL_OK;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * QueryTrayOrientation --
 *
 * 	Obtain the orientation of the tray icon.
 *
 * Results:
 *	Orientation is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
QueryTrayOrientation(
    DockIcon* icon)
{
    Atom retType = None;
    int retFormat = 32;
    unsigned long retNitems, retBytesAfter;
    unsigned char *retProp = NULL;
    int result = -1;

    if (icon->wrapper != None && icon->myManager != None) {
	XGetWindowProperty(Tk_Display(icon->tkwin),
			   icon->myManager,
			   icon->a_NET_SYSTEM_TRAY_ORIENTATION,
			   /* offset */ 0,
			   /* length */ 1,
			   /* delete */ False,
			   /* type */ XA_CARDINAL,
			   &retType, &retFormat, &retNitems,
			   &retBytesAfter, &retProp);
	if (retType == XA_CARDINAL && retFormat == 32 && retNitems == 1) {
	    result = (int) *(long*)retProp;
	}
	if (retProp) {
	    XFree(retProp);
	}
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * DockSelectionAtomFor --
 *
 * 	Obtain the dock selection atom.
 *
 * Results:
 *	Selection returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Atom
DockSelectionAtomFor(
    Tk_Window tkwin)
{
    char buf[256];
    snprintf(buf,256,"_NET_SYSTEM_TRAY_S%d",Tk_ScreenNumber(tkwin));
    return Tk_InternAtom(tkwin,buf);
}

/*
 *----------------------------------------------------------------------
 *
 * XembedSetState --
 *
 * 	Set the xembed state.
 *
 * Results:
 *	Updates the xembed state.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
XembedSetState(
    DockIcon *icon,
    long xembedState)
{
    long info[] = { 0, 0 };
    info[1] = xembedState;
    if (icon->drawingWin) {
	XChangeProperty(Tk_Display(icon->drawingWin),
			icon->wrapper,
			icon->a_XEMBED_INFO,
			icon->a_XEMBED_INFO, 32,
			PropModeReplace, (unsigned char*)info, 2);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * XembedRequestDock --
 *
 * 	Obtain the docking window.
 *
 * Results:
 *	The dock window is requested.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
XembedRequestDock(
    DockIcon *icon)
{
    Tk_Window tkwin = icon->drawingWin;
    XEvent ev;
    Display *dpy = Tk_Display(tkwin);

    memset(&ev, 0, sizeof(ev));
    ev.xclient.type = ClientMessage;
    ev.xclient.window = icon->myManager;
    ev.xclient.message_type = icon->a_NET_SYSTEM_TRAY_OPCODE;
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = 0;
    ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
    ev.xclient.data.l[2] = icon->wrapper;
    ev.xclient.data.l[3] = 0;
    ev.xclient.data.l[4] = 0;
    XSendEvent(dpy, icon->myManager, True, StructureNotifyMask|SubstructureNotifyMask, &ev);
 }

/*
 *----------------------------------------------------------------------
 *
 * CheckArgbVisual --
 *
 * 	Find out if a visual is recommended and if it looks like argb32.
 *
 * Results:
 *	Render the visual as needed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
CheckArgbVisual(
    DockIcon *icon)
{
    /* Find out if a visual is recommended and if it looks like argb32.
     * For such visuals we should:
     * Recreate a window if it's created but the depth is wrong;
     * Don't use ParentRelative but blank background.
     * For photo images, draw into a window by XPutImage.
     */
    Atom retType = None;
    int retFormat = 32;
    unsigned long retNitems, retBytesAfter;
    unsigned char *retProp = NULL;
    Visual *match = NULL;
    int depth = 0;
    Colormap cmap = None;

    TKU_NO_BAD_WINDOW_BEGIN(Tk_Display(icon->tkwin))
        XGetWindowProperty(Tk_Display(icon->tkwin),
                icon->trayManager,
                icon->a_NET_SYSTEM_TRAY_VISUAL,
                /* offset */ 0,
                /* length */ 1,
                /* delete */ False,
                /* type */ XA_VISUALID,
                &retType, &retFormat, &retNitems,
                &retBytesAfter, &retProp);
    TKU_NO_BAD_WINDOW_END
    if (retType == XA_VISUALID &&
	    retNitems == 1 &&
	    retFormat == 32) {
	char numeric[256];
	snprintf(numeric,256,"%ld",*(long*)retProp);
	XFree(retProp);
	match = Tk_GetVisual(icon->interp, icon->tkwin,
                numeric, &depth, &cmap);
    }
    if (match&& depth == 32 &&
	    match->red_mask == 0xFF0000UL &&
	    match->green_mask == 0x00FF00UL &&
	    match->blue_mask == 0x0000FFUL) {
	icon->bestVisual = match;
	icon->bestColormap = cmap;
    } else {
	icon->bestVisual = NULL;
	icon->bestColormap = None;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * CreateTrayIconWindow --
 *
 * 	Create and configure the window for the icon tray.
 *
 * Results:
 *	The window is created and displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
CreateTrayIconWindow(
    DockIcon *icon)
{
    Tcl_InterpState saved;
    Tk_Window tkwin;
    Tk_Window wrapper;
    XSetWindowAttributes attr;

    saved = Tcl_SaveInterpState(icon->interp, TCL_OK);
    /* Use the same name (tail) as the widget name, to enable
     * name-based icon management for supporting trays, as promised by
     * the docs.
     */
    tkwin = icon->drawingWin = Tk_CreateWindow(icon->interp, icon->tkwin,
            Tk_Name(icon->tkwin), "");
    if (tkwin) {
	Tk_SetClass(icon->drawingWin,icon->classString);
	Tk_CreateEventHandler(icon->drawingWin,ExposureMask|StructureNotifyMask|
                ButtonPressMask|ButtonReleaseMask|
                EnterWindowMask|LeaveWindowMask|PointerMotionMask,
                TrayIconEvent, icon);
	if(icon->bestVisual) {
	    Tk_SetWindowVisual(icon->drawingWin,icon->bestVisual,
                    32,icon->bestColormap);
	    icon->flags |= ICON_FLAG_ARGB32;
	    Tk_SetWindowBackground(tkwin, 0);
	} else {
	    Tk_SetWindowBackgroundPixmap(tkwin, ParentRelative);
	    icon->flags &= ~ICON_FLAG_ARGB32;
	}
	Tk_MakeWindowExist(tkwin);
	TKU_WmWithdraw(tkwin,icon->interp);
	wrapper = TKU_Wrapper(tkwin,icon->interp);

	attr.override_redirect = True;
	Tk_ChangeWindowAttributes(wrapper,CWOverrideRedirect,&attr);
	Tk_CreateEventHandler(wrapper,StructureNotifyMask,TrayIconWrapperEvent, icon);
	if (!icon->bestVisual) {
	    Tk_SetWindowBackgroundPixmap(wrapper, ParentRelative);
	} else {
	    Tk_SetWindowBackground(tkwin, 0);
	}
	icon->wrapper = TKU_XID(wrapper);
	TrayIconForceImageChange(icon);
    } else {
	Tcl_BackgroundError(icon->interp);
    }
    Tcl_RestoreInterpState(icon->interp, saved);
}

/*
 *----------------------------------------------------------------------
 *
 * DockToManager --
 *
 * 	Helper function to manage icon in display.
 *
 * Results:
 *	Icon is created and displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
DockToManager(
    DockIcon *icon)
{
    icon->myManager = icon->trayManager;
    Tk_SendVirtualEvent(icon->tkwin,Tk_GetUid("IconCreate"), NULL);
    XembedSetState(icon, icon->visible ? XEMBED_MAPPED : 0);
    XembedRequestDock(icon);
}

static const
Tk_OptionSpec IconOptionSpec[] = {
    {TK_OPTION_STRING,"-image","image","Image",
	NULL, TCL_INDEX_NONE, offsetof(DockIcon, imageString),
	TK_OPTION_NULL_OK, NULL,
	ICON_CONF_IMAGE | ICON_CONF_REDISPLAY},
    {TK_OPTION_STRING,"-class","class","Class",
	"TrayIcon", TCL_INDEX_NONE, offsetof(DockIcon, classString),
	0, NULL, ICON_CONF_CLASS},
    {TK_OPTION_BOOLEAN,"-docked","docked","Docked",
	"1", TCL_INDEX_NONE, offsetof(DockIcon, docked), 0, NULL,
	ICON_CONF_XEMBED | ICON_CONF_REDISPLAY},
    {TK_OPTION_BOOLEAN,"-shape","shape","Shape",
	"0", TCL_INDEX_NONE, offsetof(DockIcon, useShapeExt), 0, NULL,
	ICON_CONF_IMAGE | ICON_CONF_REDISPLAY},
    {TK_OPTION_BOOLEAN,"-visible","visible","Visible",
	"1", TCL_INDEX_NONE, offsetof(DockIcon, visible), 0, NULL,
	ICON_CONF_XEMBED | ICON_CONF_REDISPLAY},
    {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};

/*
 *----------------------------------------------------------------------
 *
 * TrayIconRequestSize --
 *
 * 	Set icon size.
 *
 * Results:
 *	Icon size is obtained/set.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconRequestSize(
    DockIcon* icon,
    int w,
    int h)
{
    if (icon->drawingWin) {
	if (icon->requestedWidth != w ||
	        icon->requestedHeight != h) {
	    Tk_SetMinimumRequestSize(icon->drawingWin,w,h);
	    Tk_GeometryRequest(icon->drawingWin,w,h);
	    Tk_SetGrid(icon->drawingWin,1,1,w,h);
	    icon->requestedWidth = w;
	    icon->requestedHeight = h;
	}
    } else {
	/* Sign that no size is requested yet */
	icon->requestedWidth = 0;
	icon->requestedHeight = 0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconImageChanged --
 *
 * 	Fires when icon state changes.
 *
 * Results:
 *	Icon changes are rendered.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconImageChanged(
    void *cd,
    int x,
    int y,
    int w,
    int h,
    int imgw,
    int imgh)
{
    DockIcon *icon = (DockIcon*) cd;
    if (imgw != icon->imageWidth || imgh != icon->imageHeight) {
	if (icon->offscreenImage) {
	    XDestroyImage(icon->offscreenImage);
	    icon->offscreenImage = NULL;
	}
	if (icon->offscreenPixmap) {
	    /* its size is bad */
	    Tk_FreePixmap(Tk_Display(icon->tkwin), icon->offscreenPixmap);
	    icon->offscreenPixmap = None;
	}
	/* if some image dimension decreases,
	 * empty areas around the image should be cleared */
	if (imgw < icon->imageWidth || imgh < icon->imageHeight) {
	    icon->flags |= ICON_FLAG_DIRTY_EDGES;
	}
    }
    icon->imageWidth = imgw;
    icon->imageHeight = imgh;
    if (imgw == w && imgh == h && x == 0 && y == 0) {
	icon->photo = NULL;	/* invalidate */
    }
    TrayIconRequestSize(icon,imgw,imgh);
    EventuallyRedrawIcon(icon);
}

/*
 *----------------------------------------------------------------------
 *
 * IgnoreImageChange --
 *
 * 	Currently no-op.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
IgnoreImageChange(
    TCL_UNUSED(void *),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
}

/*
 *----------------------------------------------------------------------
 *
 * ForceImageChange --
 *
 * 	Push icon changes through.
 *
 * Results:
 *	Icon image is updated.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconForceImageChange(
    DockIcon* icon)
{
    if (icon->image) {
	int w,h;
	Tk_SizeOfImage(icon->image,&w,&h);
	TrayIconImageChanged(icon, 0, 0, w, h, w, h);
    }
}

/*
 *----------------------------------------------------------------------
 *
 *  EventuallyRedrawIcon --
 *
 * 	Update image icon.
 *
 * Results:
 *	Icon image is updated.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
EventuallyRedrawIcon(
    DockIcon* icon)
{
    if (icon->drawingWin && icon->myManager) {	/* don't redraw invisible icon */
	if (!(icon->flags & ICON_FLAG_REDRAW_PENDING)) { /* don't schedule multiple redraw ops */
	    icon->flags |= ICON_FLAG_REDRAW_PENDING;
	    Tcl_DoWhenIdle(DisplayIcon, icon);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 *  DisplayIcon --
 *
 * 	Main function for displaying icon.
 *
 * Results:
 *	Icon image is displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
DisplayIcon(
    void *cd)
{
    DockIcon *icon = (DockIcon*)cd;
    int w = icon->imageWidth, h = icon->imageHeight;
    int imgx, imgy, outx, outy, outw, outh;
    imgx = (icon->width >= w) ? 0 : -(icon->width - w)/2;
    imgy = (icon->height >= h) ? 0 : -(icon->height - h)/2;
    outx = (icon->width >= w) ? (icon->width - w)/2 : 0;
    outy = (icon->height >= h) ? (icon->height - h)/2 : 0;
    outw = (icon->width >= w) ? w : icon->width;
    outh = (icon->height >= h) ? h : icon->height;

    icon->flags &= (~ICON_FLAG_REDRAW_PENDING);

    if (icon->drawingWin && icon->docked) {
	if (icon->flags & ICON_FLAG_ARGB32) {
	    /* ARGB32 redraw: never use a ParentRelative method, and
	       no need to clear window except FIXME when its size changed.
	       Draw on the offscreen pixmap instead, then copy to the window.
	     */
	    if (icon->offscreenPixmap == None) {
		icon->offscreenPixmap = Tk_GetPixmap(Tk_Display(icon->drawingWin),
                        Tk_WindowId(icon->drawingWin), w, h, 32);
	    }
	    if (!icon->photo) {
		icon->photo = Tk_FindPhoto(icon->interp, icon->imageString);
	    }
	    if (!icon->photo && !icon->imageVisualInstance) {
		Tcl_InterpState saved
			= Tcl_SaveInterpState(icon->interp, TCL_OK);
		icon->imageVisualInstance = Tk_GetImage(icon->interp,icon->drawingWin,
                        icon->imageString, IgnoreImageChange, NULL);
		Tcl_RestoreInterpState(icon->interp,saved);
	    }
	    if (icon->photo && !icon->offscreenImage) {
		icon->offscreenImage = XGetImage(Tk_Display(icon->drawingWin),
                        icon->offscreenPixmap, 0, 0, w, h, AllPlanes, ZPixmap);
	    }
	    if (icon->offscreenGC == None) {
		XGCValues gcv;
		gcv.function = GXcopy;
		gcv.plane_mask = AllPlanes;
		gcv.foreground = 0;
		gcv.background = 0;
		icon->offscreenGC = Tk_GetGC(icon->drawingWin,
                        GCFunction|GCPlaneMask|GCForeground|GCBackground, &gcv);
	    }
	    if (icon->flags & ICON_FLAG_DIRTY_EDGES) {
		XClearWindow(Tk_Display(icon->drawingWin), TKU_XID(icon->drawingWin));
		icon->flags &= ~ICON_FLAG_DIRTY_EDGES;
	    }
	    if (icon->photo) {
		Tk_PhotoImageBlock pib;
		int cx,cy;
		XImage *xim = icon->offscreenImage;
		/* redraw photo using raw data */
		Tk_PhotoGetImage(icon->photo,&pib);
		for (cy = 0; cy < h; ++cy) {
		    for (cx = 0; cx < w; ++cx) {
			XPutPixel(xim,cx,cy,
				  (*(pib.pixelPtr +
				     pib.pixelSize*cx +
				     pib.pitch*cy +
				     pib.offset[0])<<16) |
				  (*(pib.pixelPtr +
				     pib.pixelSize*cx +
				     pib.pitch*cy +
				     pib.offset[1])<<8) |
				  (*(pib.pixelPtr +
				     pib.pixelSize*cx +
				     pib.pitch*cy +
				     pib.offset[2])) |
				  (pib.offset[3] ?
				   (*(pib.pixelPtr +
				      pib.pixelSize*cx +
				      pib.pitch*cy +
				      pib.offset[3])<<24) : 0));
		    }
		}
		XPutImage(Tk_Display(icon->drawingWin),
			icon->offscreenPixmap,
			icon->offscreenGC,
			icon->offscreenImage,
			0,0,0,0,w,h);
	    } else {
		XFillRectangle(Tk_Display(icon->drawingWin),
			icon->offscreenPixmap,
			icon->offscreenGC,
			0,0,w,h);
		if (icon->imageVisualInstance) {
		    Tk_RedrawImage(icon->imageVisualInstance,
                            0,0,w,h,
                            icon->offscreenPixmap,
                            0,0);
		}
	    }
	    XCopyArea(Tk_Display(icon->drawingWin),
                    icon->offscreenPixmap,
                    TKU_XID(icon->drawingWin),
                    icon->offscreenGC,
                    imgx,imgy,outw,outh,outx,outy);
	} else {
	    /* Non-argb redraw: clear window and draw an image over it.
	       For photos it gives a correct alpha blending with a parent
	       window background, even if it's a fancy pixmap (proved to
	       work with lxpanel fancy backgrounds).
	    */
	    XClearWindow(Tk_Display(icon->drawingWin),
                    TKU_XID(icon->drawingWin));
	    if (icon->image && icon->visible) {
		Tk_RedrawImage(icon->image,imgx,imgy,outw,outh,
                        TKU_XID(icon->drawingWin), outx, outy);
	    }
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 *  RetargetEvent --
 *
 * 	Redirect X events to widgets.
 *
 * Results:
 *	Icon image is displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
RetargetEvent(
    DockIcon *icon,
    XEvent *ev)
{
    int send = 0;
    Window* saveWin1 = NULL, *saveWin2 = NULL;
    if (!icon->visible)
	return;
    switch (ev->type) {
    case MotionNotify:
	send = 1;
	saveWin1 = &ev->xmotion.subwindow;
	saveWin2 = &ev->xmotion.window;
	break;
    case LeaveNotify:
    case EnterNotify:
	send = 1;
	saveWin1 = &ev->xcrossing.subwindow;
	saveWin2 = &ev->xcrossing.window;
	break;
    case ButtonPress:
    case ButtonRelease:
	send = 1;
	saveWin1 = &ev->xbutton.subwindow;
	saveWin2 = &ev->xbutton.window;
	break;
    case MappingNotify:
	send = 1;
	saveWin1 = &ev->xmapping.window;
    }
    if (saveWin1) {
	Tk_MakeWindowExist(icon->tkwin);
	*saveWin1 = Tk_WindowId(icon->tkwin);
	if (saveWin2) *saveWin2 = *saveWin1;
    }
    if (send) {
	ev->xany.send_event = 0x147321ac;
	Tk_HandleEvent(ev);
    }
}

/*
 *----------------------------------------------------------------------
 *
 *  TrayIconWrapperEvent --
 *
 * 	Ensure automapping in root window is done in withdrawn state.
 *
 * Results:
 *	Icon image is displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconWrapperEvent(
    void *cd,
    XEvent* ev)
{
  /* Some embedders, like Docker, add icon windows to save set
   * (XAddToSaveSet), so when they crash the icon is reparented to root.
   * We have to make sure that automatic mapping in root is done in
   * withdrawn state (no way to prevent it entirely)
   */
    DockIcon *icon = (DockIcon*)cd;
    XWindowAttributes attr;
    if (icon->drawingWin) {
	switch(ev->type) {
	case ReparentNotify:
	    /* With virtual roots and screen roots etc, the only way
	       to check for reparent-to-root is to ask for this root
	       first */
	    XGetWindowAttributes(ev->xreparent.display,
                    ev->xreparent.window, &attr);
	    if (attr.root == ev->xreparent.parent) {
		/* upon reparent to root, */
		if (icon->drawingWin) {
		    /* we were sent away to root */
		    TKU_WmWithdraw(icon->drawingWin,icon->interp);
		    if (icon->myManager)
			Tk_SendVirtualEvent(icon->tkwin,Tk_GetUid("IconDestroy"), NULL);
		    icon->myManager = None;
		}
	    } /* Reparenting into some other embedder is theoretically possible,
	       * and everything would just work in this case.
               */
	    break;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconEvent --
 *
 * 	Handle X events.
 *
 * Results:
 *	Events are handled and processed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconEvent(
    void *cd,
    XEvent* ev)
{
    DockIcon *icon = (DockIcon*)cd;

    switch (ev->type) {
    case Expose:
	if (!ev->xexpose.count)
	    EventuallyRedrawIcon(icon);
	break;

    case DestroyNotify:
	/* If anonymous window is destroyed first, then either
	 * something went wrong with a tray (if -visible) or we just
	 * reconfigured to invisibility: nothing to be done in both
	 * cases.
	 * If unreal window is destroyed first, freeing the data structures
	 * is the only thing to do.
	 */
	if (icon->myManager) {
	    Tk_SendVirtualEvent(icon->tkwin,Tk_GetUid("IconDestroy"), NULL);
	}
	Tcl_CancelIdleCall(DisplayIcon, icon);
	icon->flags &= ~ICON_FLAG_REDRAW_PENDING;
	icon->drawingWin = NULL;
	icon->requestedWidth = 0; /* trigger re-request on recreation */
	icon->requestedHeight = 0;
	icon->wrapper = None;
	icon->myManager = None;
	break;

    case ConfigureNotify:
	Tk_SendVirtualEvent(icon->tkwin,Tk_GetUid("IconConfigure"), NULL);
	if (icon->width != ev->xconfigure.width ||
	        icon->height != ev->xconfigure.height) {
	    icon->width = ev->xconfigure.width;
	    icon->height = ev->xconfigure.height;
	    icon->flags |= ICON_FLAG_DIRTY_EDGES;
	    EventuallyRedrawIcon(icon);
	}
	RetargetEvent(icon,ev);
	break;

    case MotionNotify:  /* fall through */
    case ButtonPress:   /* fall through */
    case ButtonRelease: /* fall through */
    case EnterNotify:   /* fall through */
    case LeaveNotify:
	RetargetEvent(icon,ev);
	break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * UserIconEvent --
 *
 * 	Handle user events.
 *
 * Results:
 *	Events are handled and processed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
UserIconEvent(
    void *cd,
    XEvent* ev)
{
    DockIcon *icon = (DockIcon*)cd;

    switch (ev->type) {

    case DestroyNotify:
	Tk_DeleteGenericHandler(IconGenericHandler, icon);
	if(icon->drawingWin) {
	    icon->visible = 0;
	    Tcl_CancelIdleCall(DisplayIcon, icon);
	    icon->flags &= ~ICON_FLAG_REDRAW_PENDING;
	    Tk_DestroyWindow(icon->drawingWin);
	}
	if(icon->imageVisualInstance) {
	    Tk_FreeImage(icon->imageVisualInstance);
	    icon->image = NULL;
	}
	if(icon->offscreenImage) {
	    XDestroyImage(icon->offscreenImage);
	    icon->offscreenImage = NULL;
	}
	if(icon->offscreenGC) {
	    Tk_FreeGC(Tk_Display(icon->tkwin),icon->offscreenGC);
	    icon->offscreenGC = NULL;
	}
	if(icon->offscreenPixmap) {
	    Tk_FreePixmap(Tk_Display(icon->tkwin),icon->offscreenPixmap);
	}
	if(icon->image) {
	    Tk_FreeImage(icon->image);
	    icon->image = NULL;
	}
	if(icon->widgetCmd)
	    Tcl_DeleteCommandFromToken(icon->interp,icon->widgetCmd);
	Tk_FreeConfigOptions((char*)icon, icon->options, icon->tkwin);
	break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PostBalloon --
 *
 * 	Display tooltip/balloon window over tray icon.
 *
 * Results:
 *	Window is displayed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
PostBalloon(
    DockIcon *icon,
    const char *utf8msg,
    long timeout)
{
    Tk_Window tkwin = icon -> tkwin;
    Display* dpy = Tk_Display(tkwin);
    int length = strlen(utf8msg);
    XEvent ev;

    if (!(icon->drawingWin) || (icon->myManager == None))
	return 0;

    /* overflow protection */
    if (icon->msgid < 0)
	icon->msgid = 0;

    memset(&ev, 0, sizeof(ev));
    ev.xclient.type = ClientMessage;
    ev.xclient.window = icon->wrapper;
    ev.xclient.message_type = icon->a_NET_SYSTEM_TRAY_OPCODE;
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = CurrentTime;
    ev.xclient.data.l[1] = SYSTEM_TRAY_BEGIN_MESSAGE;
    ev.xclient.data.l[2] = timeout;
    ev.xclient.data.l[3] = length;
    ev.xclient.data.l[4] = ++icon->msgid;
    TKU_NO_BAD_WINDOW_BEGIN(Tk_Display(icon->tkwin))
	XSendEvent(dpy, icon->myManager , True, StructureNotifyMask|SubstructureNotifyMask, &ev);
        XSync(dpy, False);

        /* Sending message elements */
        while (length>0) {
	    ev.type = ClientMessage;
	    ev.xclient.window = icon->wrapper;
	    ev.xclient.message_type = icon->a_NET_SYSTEM_TRAY_MESSAGE_DATA;
	    ev.xclient.format = 8;
	    memset(ev.xclient.data.b,0,20);
	    strncpy(ev.xclient.data.b,utf8msg,length<20?length:20);
	    XSendEvent(dpy, icon->myManager, True, StructureNotifyMask|SubstructureNotifyMask, &ev);
	    XSync(dpy,False);
	    utf8msg += 20;
	    length -= 20;
        }
    TKU_NO_BAD_WINDOW_END;
    return icon->msgid;
}

/*
 *----------------------------------------------------------------------
 *
 * CancelBalloon --
 *
 * 	Remove balloon from display over tray icon.
 *
 * Results:
 *	Window is destroyed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
CancelBalloon(
    DockIcon *icon,
    int msgid)
{
    Tk_Window tkwin = icon -> tkwin;
    Display* dpy = Tk_Display(tkwin);
    XEvent ev;

    if (!(icon->drawingWin) || (icon->myManager == None))
	return;
    /* overflow protection */
    if (icon->msgid < 0)
	icon->msgid = 0;

    memset(&ev, 0, sizeof(ev));
    ev.type = ClientMessage;
    ev.xclient.window = icon->wrapper;
    ev.xclient.message_type = icon->a_NET_SYSTEM_TRAY_OPCODE;
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = CurrentTime;
    ev.xclient.data.l[1] = SYSTEM_TRAY_CANCEL_MESSAGE;
    ev.xclient.data.l[2]  =msgid;
    TKU_NO_BAD_WINDOW_BEGIN(Tk_Display(icon->tkwin))
	XSendEvent(dpy, icon->myManager , True,
                StructureNotifyMask|SubstructureNotifyMask, &ev);
    TKU_NO_BAD_WINDOW_END
}

/*
 *----------------------------------------------------------------------
 *
 * IconGenericHandler --
 *
 * 	Process non-tk events.
 *
 * Results:
 *	Events are processed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
IconGenericHandler(
    void *cd,
    XEvent *ev)
{
    DockIcon *icon = (DockIcon*)cd;

    if ((ev->type == ClientMessage) &&
	    (ev->xclient.message_type == icon->aMANAGER) &&
	    ((Atom)ev->xclient.data.l[1] == icon->a_NET_SYSTEM_TRAY_Sn)) {
	icon->trayManager = (Window)ev->xclient.data.l[2];
	XSelectInput(ev->xclient.display,icon->trayManager,StructureNotifyMask);
	if (icon->myManager == None)
	    TrayIconUpdate(icon, ICON_CONF_XEMBED);
	return 1;
    }
    if (ev->type == DestroyNotify) {
	if (ev->xdestroywindow.window == icon->trayManager) {
	    icon->trayManager = None;
	}
	if (ev->xdestroywindow.window == icon->myManager) {
	    icon->myManager = None;
	    icon->wrapper = None;
	    if (icon->drawingWin) {
		Tk_DestroyWindow(icon->drawingWin);
		icon->drawingWin = NULL;
	    }
	}
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconUpdate --
 *
 * 	Get in touch with new options that are certainly valid.
 *
 * Results:
 *	Options updated.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconUpdate(
    DockIcon *icon,
    int mask)
{
    /* why should someone need this option?
     * anyway, let's handle it if we provide it.
     */
    if (mask & ICON_CONF_CLASS) {
	if (icon->drawingWin)
	    Tk_SetClass(icon->drawingWin,Tk_GetUid(icon->classString));
    }
    /*
     * First, ensure right icon visibility.
     * If should be visible and not yet managed,
     * we have to get the tray or wait for it.
     * If should be invisible and managed,
     * real-window is simply destroyed.
     * If should be invisible and not managed,
     * generic handler should be abandoned.
     */
    if (mask & ICON_CONF_XEMBED) {
	if (icon->myManager == None &&
	        icon->trayManager != None &&
	        icon->docked) {
	    CheckArgbVisual(icon);
	    if (icon->drawingWin &&
		    ((icon->bestVisual && !(icon->flags & ICON_FLAG_ARGB32)) ||
		     (!icon->bestVisual && (icon->flags & ICON_FLAG_ARGB32)))) {
		icon->myManager = None;
		icon->wrapper = None;
		icon->requestedWidth = icon->requestedHeight = 0;
		Tk_DestroyWindow(icon->drawingWin);
		icon->drawingWin = NULL;
	    }
	    if (!icon->drawingWin) {
		CreateTrayIconWindow(icon);
	    }
	    if (icon->drawingWin) {
		DockToManager(icon);
	    }
	}
	if (icon->myManager != None &&
	        icon->drawingWin != NULL &&
	        !icon->docked) {
	    Tk_DestroyWindow(icon->drawingWin);
	    icon->drawingWin = NULL;
	    icon->myManager = None;
	    icon->wrapper = None;
	}
	if (icon->drawingWin) {
	    XembedSetState(icon, icon->visible ? XEMBED_MAPPED : 0);
	}
    }
    if (mask & ICON_CONF_IMAGE) {
	TrayIconForceImageChange(icon);
    }
    if (mask & ICON_CONF_REDISPLAY) {
	EventuallyRedrawIcon(icon);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconConfigureMethod --
 *
 *      Returns TCL_ERROR if some option is invalid,
 *      or else retrieve resource references and free old resources.
 *
 * Results:
 *	Widget configured.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TrayIconConfigureMethod(
    DockIcon *icon,
    Tcl_Interp* interp,
    Tcl_Size objc,
    Tcl_Obj *const objv[],
    int addflags)
{
    Tk_SavedOptions saved;
    Tk_Image newImage = NULL;
    int mask = 0;

    if (objc <= 1 && !(addflags & ICON_CONF_FIRST_TIME)) {
	Tcl_Obj* info = Tk_GetOptionInfo(interp, (char*)icon, icon->options,
                objc? objv[0] : NULL, icon->tkwin);
	if (info) {
	    Tcl_SetObjResult(interp,info);
	    return TCL_OK;
	} else {
	    return TCL_ERROR; /* msg by Tk_GetOptionInfo */
	}
    }

    if (Tk_SetOptions(interp, icon,icon->options,objc,objv,
            icon->tkwin,&saved,&mask) != TCL_OK) {
	return TCL_ERROR; /* msg by Tk_SetOptions */
    }
    mask |= addflags;
    /* now check option validity */
    if (mask & ICON_CONF_IMAGE) {
	if (icon->imageString) {
	    newImage = Tk_GetImage(interp, icon->tkwin, icon->imageString,
                    TrayIconImageChanged, icon);
	    if (!newImage) {
		Tk_RestoreSavedOptions(&saved);
		return TCL_ERROR; /* msg by Tk_GetImage */
	    }
	}
	if (icon->image) {
	    Tk_FreeImage(icon->image);
	    icon->image = NULL;
	}
	if (icon->imageVisualInstance) {
	    Tk_FreeImage(icon->imageVisualInstance);
	    icon->imageVisualInstance = NULL;
	}
	icon->image = newImage; /* may be null, as intended */
	icon->photo = NULL; /* invalidate photo reference */
    }
    Tk_FreeSavedOptions(&saved);
    /* Now as we are reconfigured... */
    TrayIconUpdate(icon,mask);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconDeleteProc --
 *
 *      Delete tray window and clean up.
 *
 * Results:
 *	Window destroyed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TrayIconDeleteProc(
    void *cd )
{
    DockIcon *icon = (DockIcon *)cd;
    Tk_DestroyWindow(icon->tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * TrayIconCreateCmd --
 *
 *      Create tray command and (unreal) window.
 *
 * Results:
 *	Icon tray and hidden window created.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TrayIconCreateCmd(
    void *cd,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    Tk_Window mainWindow = (Tk_Window)cd;
    DockIcon *icon;

    icon = (DockIcon*)attemptckalloc(sizeof(DockIcon));
    if (!icon) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("running out of memory", TCL_INDEX_NONE));
	goto handleErrors;
    }
    memset(icon,0,sizeof(*icon));

    if (objc < 2||(objc%2)) {
	Tcl_WrongNumArgs(interp, 1, objv, "pathName ?option value ...?");
	goto handleErrors;
    }

    /* It's not a toplevel window by now. It really doesn't matter,
     * because it's not really shown.
     */
    icon->tkwin = Tk_CreateWindowFromPath(interp, mainWindow,
            Tcl_GetString(objv[1]),"");
    if (icon->tkwin == NULL) {
	goto handleErrors;
    }

    /* Subscribe to StructureNotify */
    TKU_AddInput(Tk_Display(icon->tkwin),
            RootWindowOfScreen(Tk_Screen(icon->tkwin)),StructureNotifyMask);
    TKU_AddInput(Tk_Display(icon->tkwin),
            RootWindow(Tk_Display(icon->tkwin),0),StructureNotifyMask);
    /* Spec says "screen 0" not "default", but... */
    TKU_AddInput(Tk_Display(icon->tkwin),
            DefaultRootWindow(Tk_Display(icon->tkwin)),StructureNotifyMask);

    /* Early tracking of DestroyNotify is essential */
    Tk_CreateEventHandler(icon->tkwin,StructureNotifyMask,
            UserIconEvent, icon);

    /* Now try setting options */
    icon->options = Tk_CreateOptionTable(interp,IconOptionSpec);
    /* Class name is used for retrieving defaults, so... */
    Tk_SetClass(icon->tkwin, Tk_GetUid("TrayIcon"));
    if (Tk_InitOptions(interp,(char*)icon,icon->options,icon->tkwin) != TCL_OK) {
	goto handleErrors;
    }

    icon->a_NET_SYSTEM_TRAY_Sn = DockSelectionAtomFor(icon->tkwin);
    icon->a_NET_SYSTEM_TRAY_OPCODE = Tk_InternAtom(icon->tkwin,"_NET_SYSTEM_TRAY_OPCODE");
    icon->a_NET_SYSTEM_TRAY_MESSAGE_DATA = Tk_InternAtom(icon->tkwin,"_NET_SYSTEM_TRAY_MESSAGE_DATA");
    icon->a_NET_SYSTEM_TRAY_ORIENTATION = Tk_InternAtom(icon->tkwin,"_NET_SYSTEM_TRAY_ORIENTATION");
    icon->a_NET_SYSTEM_TRAY_VISUAL = Tk_InternAtom(icon->tkwin,"_NET_SYSTEM_TRAY_VISUAL");
    icon->a_XEMBED_INFO = Tk_InternAtom(icon->tkwin,"_XEMBED_INFO");
    icon->aMANAGER = Tk_InternAtom(icon->tkwin,"MANAGER");

    icon->interp = interp;

    icon->trayManager = XGetSelectionOwner(Tk_Display(icon->tkwin), icon->a_NET_SYSTEM_TRAY_Sn);
    if (icon->trayManager) {
	XSelectInput(Tk_Display(icon->tkwin),icon->trayManager, StructureNotifyMask);
    }

    Tk_CreateGenericHandler(IconGenericHandler, icon);

    if (objc>3) {
	if (TrayIconConfigureMethod(icon, interp, objc-2, objv+2,
                ICON_CONF_XEMBED|ICON_CONF_IMAGE|ICON_CONF_FIRST_TIME) != TCL_OK) {
	    goto handleErrors;
	}
    }

    icon->widgetCmd = Tcl_CreateObjCommand(interp, Tcl_GetString(objv[1]),
            TrayIconObjectCmd, icon, TrayIconDeleteProc);

    /* Sometimes a command just can't be created... */
    if (!icon->widgetCmd) {
	goto handleErrors;
    }

    Tcl_SetObjResult(interp,objv[1]);
    return TCL_OK;

handleErrors:
    /* Rolling back */
    if (icon) {
	if (icon->options) {
	    Tk_DeleteOptionTable(icon->options);
	    icon->options = NULL;
	}
	if (icon->tkwin) {
	    /* Resources will be freed by DestroyNotify handler */
	    Tk_DestroyWindow(icon->tkwin);
	}
	ckfree(icon);
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * Tktray_Init --
 *
 *      Initialize the command.
 *
 * Results:
 *	Command initialized.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tktray_Init(
    Tcl_Interp *interp)
{
    Tcl_CreateObjCommand(interp, "::tk::systray::_systray",
            TrayIconCreateCmd, Tk_MainWindow(interp), NULL);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */

Changes to unix/tkUnixWm.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58
59


60
61
62
63
64
65
66
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56
57


58
59
60
61
62
63
64
65
66








-
-
+
+



















-
-
+
+







-
+













-
-
+
+



-
-
+
+







/*
 * tkUnixWm.c --
 *
 *	This module takes care of the interactions between a Tk-based
 *	application and the window manager. Among other things, it implements
 *	the "wm" command and passes geometry information to the window
 *	manager.
 *
 * Copyright © 1991-1994 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1991-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.
 */

#include "tkUnixInt.h"

/*
 * A data structure of the following type holds information for each window
 * manager protocol (such as WM_DELETE_WINDOW) for which a handler (i.e. a Tcl
 * command) has been defined for a particular top-level window.
 */

typedef struct ProtocolHandler {
    Atom protocol;		/* Identifies the protocol. */
    struct ProtocolHandler *nextPtr;
				/* Next in list of protocol handlers for the
				 * same top-level window, or NULL for end of
				 * list. */
    Tcl_Interp *interp;	/* Interpreter in which to invoke command. */
    char command[TKFLEXARRAY];	/* Tcl command to invoke when a client message
    Tcl_Interp *interp;		/* Interpreter in which to invoke command. */
    char command[1];		/* Tcl command to invoke when a client message
				 * for this protocol arrives. The actual size
				 * of the structure varies to accommodate the
				 * needs of the actual command. THIS MUST BE
				 * THE LAST FIELD OF THE STRUCTURE. */
} ProtocolHandler;

#define HANDLER_SIZE(cmdLength) \
    (offsetof(ProtocolHandler, command) + 1 + cmdLength)
    ((unsigned) ((Tk_Offset(ProtocolHandler, command) + 1) + cmdLength))

/*
 * Data for [wm attributes] command:
 */

typedef struct {
    double alpha;		/* Transparency; 0.0=transparent, 1.0=opaque */
    int topmost;		/* Flag: true=>stay-on-top */
    int zoomed;			/* Flag: true=>maximized */
    int fullscreen;		/* Flag: true=>fullscreen */
} WmAttributes;

typedef enum {
    WMATT_ALPHA, WMATT_FULLSCREEN, WMATT_TOPMOST, WMATT_TYPE,
    WMATT_ZOOMED, _WMATT_LAST_ATTRIBUTE
    WMATT_ALPHA, WMATT_TOPMOST, WMATT_ZOOMED, WMATT_FULLSCREEN,
    WMATT_TYPE, _WMATT_LAST_ATTRIBUTE
} WmAttribute;

static const char *const WmAttributeNames[] = {
    "-alpha", "-fullscreen", "-topmost", "-type",
    "-zoomed", NULL
    "-alpha", "-topmost", "-zoomed", "-fullscreen",
    "-type", NULL
};

/*
 * A data structure of the following type holds window-manager-related
 * information for each top-level window in an application.
 */

78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+







    char *iconName;		/* Name to display in icon. Malloced. */
    XWMHints hints;		/* Various pieces of information for window
				 * manager. */
    char *leaderName;		/* Path name of leader of window group
				 * (corresponds to hints.window_group).
				 * Malloc-ed. Note: this field doesn't get
				 * updated if leader is destroyed. */
    TkWindow *containerPtr;	/* Container window for TRANSIENT_FOR property,
    TkWindow *masterPtr;	/* Master window for TRANSIENT_FOR property,
				 * or NULL. */
    Tk_Window icon;		/* Window to use as icon for this window, or
				 * NULL. */
    Tk_Window iconFor;		/* Window for which this window is icon, or
				 * NULL if this isn't an icon for anyone. */
    int withdrawn;		/* Non-zero means window has been withdrawn. */

201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215







-
+







     * Miscellaneous information.
     */

    WmAttributes attributes;	/* Current state of [wm attributes] */
    WmAttributes reqState;	/* Requested state of [wm attributes] */
    ProtocolHandler *protPtr;	/* First in list of protocol handlers for this
				 * window (NULL means none). */
    Tcl_Size cmdArgc;		/* Number of elements in cmdArgv below. */
    int cmdArgc;		/* Number of elements in cmdArgv below. */
    const char **cmdArgv;	/* Array of strings to store in the WM_COMMAND
				 * property. NULL means nothing available. */
    char *clientMachine;	/* String to store in WM_CLIENT_MACHINE
				 * property, or NULL. */
    int flags;			/* Miscellaneous flags, defined below. */
    int numTransients;		/* number of transients on this window */
    int iconDataSize;		/* size of iconphoto image data */
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269







-
+







 *				allow the user to change the width of the
 *				window (controlled by "wm resizable" command).
 * WM_HEIGHT_NOT_RESIZABLE -	non-zero means that we're not supposed to
 *				allow the user to change the height of the
 *				window (controlled by "wm resizable" command).
 * WM_WITHDRAWN -		non-zero means that this window has explicitly
 *				been withdrawn. If it's a transient, it should
 *				not mirror state changes in the container.
 *				not mirror state changes in the master.
 */

#define WM_NEVER_MAPPED			1
#define WM_UPDATE_PENDING		2
#define WM_NEGATIVE_X			4
#define WM_NEGATIVE_Y			8
#define WM_UPDATE_SIZE_HINTS		0x10
300
301
302
303
304
305
306
307

308
309

310
311
312
313
314
315

316
317
318
319
320

321
322
323
324
325
326
327
300
301
302
303
304
305
306

307
308

309
310
311
312
313
314

315
316
317
318
319

320
321
322
323
324
325
326
327







-
+

-
+





-
+




-
+







 */

/*
 * The following structures are the official type records for geometry
 * management of top-level and menubar windows.
 */

static void		TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void		TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
static void		RemapWindows(TkWindow *winPtr, TkWindow *parentPtr);
static void		MenubarReqProc(void *clientData,
static void		MenubarReqProc(ClientData clientData,
			    Tk_Window tkwin);

static const Tk_GeomMgr wmMgrType = {
    "wm",			/* name */
    TopLevelReqProc,		/* requestProc */
    NULL,			/* lostContentProc */
    NULL,			/* lostSlaveProc */
};
static const Tk_GeomMgr menubarMgrType = {
    "menubar",			/* name */
    MenubarReqProc,		/* requestProc */
    NULL,			/* lostContentProc */
    NULL,			/* lostSlaveProc */
};

/*
 * Structures of the following type are used for communication between
 * WaitForEvent, WaitRestrictProc, and WaitTimeoutProc.
 */

340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355

356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377

378
379

380
381
382

383
384
385

386
387
388

389
390
391

392
393
394

395
396
397

398
399
400

401
402
403

404
405
406

407
408
409

410
411
412

413
414
415

416
417
418
419
420
421

422
423
424

425
426
427

428
429
430

431
432
433

434
435
436

437
438
439

440
441
442

443
444
445

446
447
448

449
450
451

452
453
454

455
456
457

458
459
460

461
462
463

464
465
466

467
468
469

470
471
472

473
474
475

476
477
478

479
480
481
482
483
484
485
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354

355
356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

377
378

379
380
381

382
383
384

385
386
387

388
389
390

391
392
393

394
395
396

397
398
399

400
401
402

403
404
405

406
407
408

409
410
411

412
413
414

415
416



417

418
419
420

421
422
423

424
425
426

427
428
429

430
431
432

433
434
435

436
437
438

439
440
441

442
443
444

445
446
447

448
449
450

451
452
453

454
455
456

457
458
459

460
461
462

463
464
465

466
467
468

469
470
471

472
473
474

475
476
477
478
479
480
481
482







-
+







-
+


-
+


















-
+

-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+

-
-
-

-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+








static int		ComputeReparentGeometry(WmInfo *wmPtr);
static void		ConfigureEvent(WmInfo *wmPtr,
			    XConfigureEvent *eventPtr);
static void		CreateWrapper(WmInfo *wmPtr);
static void		GetMaxSize(WmInfo *wmPtr, int *maxWidthPtr,
			    int *maxHeightPtr);
static void		MenubarDestroyProc(void *clientData,
static void		MenubarDestroyProc(ClientData clientData,
			    XEvent *eventPtr);
static int		ParseGeometry(Tcl_Interp *interp, const char *string,
			    TkWindow *winPtr);
static void		ReparentEvent(WmInfo *wmPtr, XReparentEvent *eventPtr);
static void		PropertyEvent(WmInfo *wmPtr, XPropertyEvent *eventPtr);
static void		TkWmStackorderToplevelWrapperMap(TkWindow *winPtr,
			    Display *display, Tcl_HashTable *reparentTable);
static void		TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void		TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
static void		RemapWindows(TkWindow *winPtr, TkWindow *parentPtr);
static void		UpdateCommand(TkWindow *winPtr);
static void		UpdateGeometryInfo(void *clientData);
static void		UpdateGeometryInfo(ClientData clientData);
static void		UpdateHints(TkWindow *winPtr);
static void		UpdateSizeHints(TkWindow *winPtr,
			    int newWidth, int newHeight);
static void		UpdateTitle(TkWindow *winPtr);
static void		UpdatePhotoIcon(TkWindow *winPtr);
static void		UpdateVRootGeometry(WmInfo *wmPtr);
static void		UpdateWmProtocols(WmInfo *wmPtr);
static int		SetNetWmType(TkWindow *winPtr, Tcl_Obj *typePtr);
static Tcl_Obj *	GetNetWmType(TkWindow *winPtr);
static void 		SetNetWmState(TkWindow*, const char *atomName, int on);
static void 		CheckNetWmState(WmInfo *, Atom *atoms, int numAtoms);
static void 		UpdateNetWmState(WmInfo *);
static void		WaitForConfigureNotify(TkWindow *winPtr,
			    unsigned long serial);
static int		WaitForEvent(Display *display,
			    WmInfo *wmInfoPtr, int type, XEvent *eventPtr);
static void		WaitForMapNotify(TkWindow *winPtr, int mapped);
static Tk_RestrictProc WaitRestrictProc;
static void		WrapperEventProc(void *clientData,
static void		WrapperEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		WmWaitMapProc(void *clientData,
static void		WmWaitMapProc(ClientData clientData,
			    XEvent *eventPtr);
static int		WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmClientCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmColormapwindowsCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGridCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbadgeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmManageCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmOverrideredirectCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStateCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr,
			    Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);

/*
 *--------------------------------------------------------------
 *
 * TkWmCleanup --
563
564
565
566
567
568
569
570

571
572
573

574
575
576
577

578
579
580
581
582
583
584
560
561
562
563
564
565
566

567
568
569

570
571
572
573

574
575
576
577
578
579
580
581







-
+


-
+



-
+







 *--------------------------------------------------------------
 */

void
TkWmNewWindow(
    TkWindow *winPtr)		/* Newly-created top-level window. */
{
    WmInfo *wmPtr;
    register WmInfo *wmPtr;
    TkDisplay *dispPtr = winPtr->dispPtr;

    wmPtr = (WmInfo *)ckalloc(sizeof(WmInfo));
    wmPtr = ckalloc(sizeof(WmInfo));
    memset(wmPtr, 0, sizeof(WmInfo));
    wmPtr->winPtr = winPtr;
    wmPtr->reparent = None;
    wmPtr->containerPtr = NULL;
    wmPtr->masterPtr = NULL;
    wmPtr->numTransients = 0;
    wmPtr->hints.flags = InputHint | StateHint;
    wmPtr->hints.input = True;
    wmPtr->hints.initial_state = NormalState;
    wmPtr->hints.icon_pixmap = None;
    wmPtr->hints.icon_window = None;
    wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
658
659
660
661
662
663
664
665

666
667
668
669
670
671
672
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669







-
+







 */

void
TkWmMapWindow(
    TkWindow *winPtr)		/* Top-level window that's about to be
				 * mapped. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    XTextProperty textProp;

    if (wmPtr->flags & WM_NEVER_MAPPED) {
	Tcl_DString ds;

	wmPtr->flags &= ~WM_NEVER_MAPPED;

683
684
685
686
687
688
689
690

691
692

693
694
695

696
697
698
699
700
701
702
703
704
705
706

707
708
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723

724
725
726
727
728
729
730
680
681
682
683
684
685
686

687
688

689
690
691

692
693
694
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
710
711
712

713
714
715
716
717
718
719

720
721
722
723
724
725
726
727







-
+

-
+


-
+










-
+









-
+






-
+







	 * Store all the window-manager-related information for the window.
	 */

	TkWmSetClass(winPtr);
	UpdateTitle(winPtr);
	UpdatePhotoIcon(winPtr);

	if (wmPtr->containerPtr != NULL) {
	if (wmPtr->masterPtr != NULL) {
	    /*
	     * Don't map a transient if the container is not mapped.
	     * Don't map a transient if the master is not mapped.
	     */

	    if (!Tk_IsMapped(wmPtr->containerPtr)) {
	    if (!Tk_IsMapped(wmPtr->masterPtr)) {
		wmPtr->withdrawn = 1;
		wmPtr->hints.initial_state = WithdrawnState;
	    }

	    /*
	     * Make sure that we actually set the transient-for property, even
	     * if we are withdrawn. [Bug 1163496]
	     */

	    XSetTransientForHint(winPtr->display, wmPtr->wrapperPtr->window,
		    wmPtr->containerPtr->wmInfoPtr->wrapperPtr->window);
		    wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
	}

	wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
	UpdateHints(winPtr);
	UpdateWmProtocols(wmPtr);
	if (wmPtr->cmdArgv != NULL) {
	    UpdateCommand(winPtr);
	}
	if (wmPtr->clientMachine != NULL) {
	    (void)Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, TCL_INDEX_NONE, &ds);
	    Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, -1, &ds);
	    if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
		    &textProp) != 0) {
		unsigned long pid = (unsigned long) getpid();

		XSetWMClientMachine(winPtr->display,
			wmPtr->wrapperPtr->window, &textProp);
		XFree(textProp.value);
		XFree((char *) textProp.value);

		/*
		 * Inform the server (and more particularly any session
		 * manager) what our process ID is. We only do this when the
		 * CLIENT_MACHINE property is set since the spec for
		 * _NET_WM_PID requires that to be set too.
		 */
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842

843
844
845
846
847
848
849
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845
846







-
+








-
+







 *--------------------------------------------------------------
 */

void
TkWmDeadWindow(
    TkWindow *winPtr)		/* Top-level window that's being deleted. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    WmInfo *wmPtr2;

    if (wmPtr == NULL) {
	return;
    }
    if ((WmInfo *) winPtr->dispPtr->firstWmPtr == wmPtr) {
	winPtr->dispPtr->firstWmPtr = wmPtr->nextPtr;
    } else {
	WmInfo *prevPtr;
	register WmInfo *prevPtr;

	for (prevPtr = (WmInfo *) winPtr->dispPtr->firstWmPtr; ;
		prevPtr = prevPtr->nextPtr) {
	    /* ASSERT: prevPtr != NULL [Bug 1789819] */
	    if (prevPtr->nextPtr == wmPtr) {
		prevPtr->nextPtr = wmPtr->nextPtr;
		break;
908
909
910
911
912
913
914
915

916
917
918
919
920

921
922

923
924

925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940


941
942
943

944
945
946
947
948
949

950
951

952
953
954
955
956
957
958
905
906
907
908
909
910
911

912
913
914
915
916

917
918

919
920

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935


936
937
938
939

940
941
942
943
944
945

946
947

948
949
950
951
952
953
954
955







-
+




-
+

-
+

-
+














-
-
+
+


-
+





-
+

-
+







	ckfree(wmPtr->clientMachine);
    }
    if (wmPtr->flags & WM_UPDATE_PENDING) {
	Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
    }

    /*
     * Reset all transient windows whose container is the dead window.
     * Reset all transient windows whose master is the dead window.
     */

    for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
	    wmPtr2 = wmPtr2->nextPtr) {
	if (wmPtr2->containerPtr == winPtr) {
	if (wmPtr2->masterPtr == winPtr) {
	    wmPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) wmPtr2->containerPtr,
	    Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
		    StructureNotifyMask, WmWaitMapProc, wmPtr2->winPtr);
	    wmPtr2->containerPtr = NULL;
	    wmPtr2->masterPtr = NULL;
	    if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
		XDeleteProperty(winPtr->display, wmPtr2->wrapperPtr->window,
			Tk_InternAtom((Tk_Window) winPtr, "WM_TRANSIENT_FOR"));

		/*
		 * FIXME: Need a call like Win32's UpdateWrapper() so we can
		 * recreate the wrapper and get rid of the transient window
		 * decorations.
		 */
	    }
	}
    }
    /* ASSERT: numTransients == 0 [Bug 1789819] */

    if (wmPtr->containerPtr != NULL) {
	wmPtr2 = wmPtr->containerPtr->wmInfoPtr;
    if (wmPtr->masterPtr != NULL) {
	wmPtr2 = wmPtr->masterPtr->wmInfoPtr;

	/*
	 * If we had a container, tell them that we aren't tied to them anymore
	 * If we had a master, tell them that we aren't tied to them anymore
	 */

	if (wmPtr2 != NULL) {
	    wmPtr2->numTransients--;
	}
	Tk_DeleteEventHandler((Tk_Window) wmPtr->containerPtr,
	Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
		StructureNotifyMask, WmWaitMapProc, winPtr);
	wmPtr->containerPtr = NULL;
	wmPtr->masterPtr = NULL;
    }
    ckfree(wmPtr);
    winPtr->wmInfoPtr = NULL;
}

/*
 *--------------------------------------------------------------
979
980
981
982
983
984
985
986

987
988
989


990
991
992

993
994
995

996
997

998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013

1014
1015
1016
1017
1018

1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
976
977
978
979
980
981
982

983
984


985
986
987
988

989
990
991

992
993

994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015

1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037







-
+

-
-
+
+


-
+


-
+

-
+













+


-
+




-
+



-
+









-
+







{
    if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
	return;
    }

    if (winPtr->classUid != NULL) {
	XClassHint *classPtr;
	Tcl_DString name, ds;
	Tcl_DString name, class;

	(void)Tcl_UtfToExternalDString(NULL, winPtr->nameUid, TCL_INDEX_NONE, &name);
	(void)Tcl_UtfToExternalDString(NULL, winPtr->classUid, TCL_INDEX_NONE, &ds);
	Tcl_UtfToExternalDString(NULL, winPtr->nameUid, -1, &name);
	Tcl_UtfToExternalDString(NULL, winPtr->classUid, -1, &class);
	classPtr = XAllocClassHint();
	classPtr->res_name = Tcl_DStringValue(&name);
	classPtr->res_class = Tcl_DStringValue(&ds);
	classPtr->res_class = Tcl_DStringValue(&class);
	XSetClassHint(winPtr->display, winPtr->wmInfoPtr->wrapperPtr->window,
		classPtr);
	XFree(classPtr);
	XFree((char *) classPtr);
	Tcl_DStringFree(&name);
	Tcl_DStringFree(&ds);
	Tcl_DStringFree(&class);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_WmObjCmd --
 *
 *	This function is invoked to process the "wm" Tcl command.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_WmObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    static const char *const optionStrings[] = {
	"aspect", "attributes", "client", "colormapwindows",
	"command", "deiconify", "focusmodel", "forget",
	"frame", "geometry", "grid", "group", "iconbadge", "iconbitmap",
	"frame", "geometry", "grid", "group", "iconbitmap",
	"iconify", "iconmask", "iconname", "iconphoto",
	"iconposition", "iconwindow", "manage", "maxsize",
	"minsize", "overrideredirect", "positionfrom",
	"protocol", "resizable", "sizefrom", "stackorder",
	"state", "title", "transient", "withdraw", NULL };
    enum options {
	WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
	WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FORGET,
	WMOPT_FRAME, WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP,
	WMOPT_ICONBADGE, WMOPT_ICONBITMAP,
	WMOPT_ICONBITMAP,
	WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME, WMOPT_ICONPHOTO,
	WMOPT_ICONPOSITION, WMOPT_ICONWINDOW, WMOPT_MANAGE, WMOPT_MAXSIZE,
	WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT, WMOPT_POSITIONFROM,
	WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM, WMOPT_STACKORDER,
	WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT, WMOPT_WITHDRAW };
    int index;
    const char *argv1;
1053
1054
1055
1056
1057
1058
1059
1060
1061


1062
1063
1064
1065
1066
1067
1068
1051
1052
1053
1054
1055
1056
1057


1058
1059
1060
1061
1062
1063
1064
1065
1066







-
-
+
+







	int wmTracing;

	if ((objc != 2) && (objc != 3)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
	    return TCL_ERROR;
	}
	if (objc == 2) {
	    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
		    (dispPtr->flags & TK_DISPLAY_WM_TRACING) != 0));
	    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
		    dispPtr->flags & TK_DISPLAY_WM_TRACING));
	    return TCL_OK;
	}
	if (Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (wmTracing) {
	    dispPtr->flags |= TK_DISPLAY_WM_TRACING;
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1113
1114
1115
1116
1117
1118
1119


1120
1121
1122
1123
1124
1125
1126







-
-







	return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GEOMETRY:
	return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GRID:
	return WmGridCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GROUP:
	return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBADGE:
	return WmIconbadgeCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBITMAP:
	return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONIFY:
	return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONMASK:
	return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONNAME:
1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192

1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210




1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1178
1179
1180
1181
1182
1183
1184

1185
1186
1187

1188
1189
1190

1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202




1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230







-
+


-
+


-
+











-
-
-
-
+
+
+
+
















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmAspectCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int numer1, denom1, numer2, denom2;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?minNumer minDenom maxNumer maxDenom?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PAspect) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewWideIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewWideIntObj(wmPtr->maxAspect.y);
	    results[0] = Tcl_NewIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewIntObj(wmPtr->maxAspect.y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~PAspect;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) {
	    return TCL_ERROR;
	}
	if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) ||
		(denom2 <= 0)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "aspect number can't be <= 0", TCL_INDEX_NONE));
		    "aspect number can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "ASPECT", NULL);
	    return TCL_ERROR;
	}
	wmPtr->minAspect.x = numer1;
	wmPtr->minAspect.y = denom1;
	wmPtr->maxAspect.x = numer2;
	wmPtr->maxAspect.y = denom2;
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321
1322
1323
1324
1325







-
+







	if (Tcl_GetBooleanFromObj(interp, value,
		&wmPtr->reqState.fullscreen) != TCL_OK) {
	    return TCL_ERROR;
	}
	SetNetWmState(winPtr, "_NET_WM_STATE_FULLSCREEN",
		wmPtr->reqState.fullscreen);
	break;
    case _WMATT_LAST_ATTRIBUTE:
    case _WMATT_LAST_ATTRIBUTE:	/* NOTREACHED */
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1352
1353
1354
1355
1356
1357
1358
1359

1360
1361

1362
1363
1364
1365
1366
1367
1368
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365







-
+


+







	return Tcl_NewBooleanObj(wmPtr->attributes.topmost);
    case WMATT_ZOOMED:
	return Tcl_NewBooleanObj(wmPtr->attributes.zoomed);
    case WMATT_FULLSCREEN:
	return Tcl_NewBooleanObj(wmPtr->attributes.fullscreen);
    case WMATT_TYPE:
	return GetNetWmType(winPtr);
    case _WMATT_LAST_ATTRIBUTE:
    case _WMATT_LAST_ATTRIBUTE:	/*NOTREACHED*/
	break;
    }
    /*NOTREACHED*/
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * WmAttributesCmd --
1384
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404

1405
1406

1407
1408
1409
1410
1411
1412
1413
1414
1415

1416
1417
1418

1419
1420
1421
1422
1423
1424
1425

1426
1427
1428
1429
1430
1431
1432
1381
1382
1383
1384
1385
1386
1387

1388
1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402

1403
1404
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414

1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429







-
+


-
+









-
+

-
+








-
+


-
+






-
+







 * See also: TIP#231, EWMH.
 *
 *----------------------------------------------------------------------
 */

static int
WmAttributesCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int attribute = 0;

    if (objc == 3) {		/* wm attributes $win */
	Tcl_Obj *result = Tcl_NewListObj(0,0);

	for (attribute = 0; attribute < _WMATT_LAST_ATTRIBUTE; ++attribute) {
	    Tcl_ListObjAppendElement(interp, result,
		    Tcl_NewStringObj(WmAttributeNames[attribute], TCL_INDEX_NONE));
		    Tcl_NewStringObj(WmAttributeNames[attribute], -1));
	    Tcl_ListObjAppendElement(interp, result,
		    WmGetAttribute(winPtr, (WmAttribute)attribute));
		    WmGetAttribute(winPtr, attribute));
	}
	Tcl_SetObjResult(interp, result);
	return TCL_OK;
    } else if (objc == 4) {	/* wm attributes $win -attribute */
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], WmAttributeNames,
		sizeof(char *), "attribute", 0, &attribute) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, WmGetAttribute(winPtr, (WmAttribute)attribute));
	Tcl_SetObjResult(interp, WmGetAttribute(winPtr, attribute));
	return TCL_OK;
    } else if ((objc - 3) % 2 == 0) {	/* wm attributes $win -att value... */
	Tcl_Size i;
	int i;

	for (i = 3; i < objc; i += 2) {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], WmAttributeNames,
		    sizeof(char *), "attribute", 0, &attribute) != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (WmSetAttribute(winPtr,interp,(WmAttribute)attribute,objv[i+1]) != TCL_OK) {
	    if (WmSetAttribute(winPtr,interp,attribute,objv[i+1]) != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	return TCL_OK;
    }

    Tcl_WrongNumArgs(interp, 2, objv, "window ?-attribute ?value ...??");
1448
1449
1450
1451
1452
1453
1454
1455

1456
1457
1458

1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502
1503
1504

1505
1506
1507
1508
1509
1510
1511
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454

1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487

1488
1489
1490
1491
1492
1493

1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508







-
+


-
+


-
+









-
+



















-
+





-
+






-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmClientCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->clientMachine != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(wmPtr->clientMachine, TCL_INDEX_NONE));
		    Tcl_NewStringObj(wmPtr->clientMachine, -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (argv3[0] == 0) {
	if (wmPtr->clientMachine != NULL) {
	    ckfree(wmPtr->clientMachine);
	    wmPtr->clientMachine = NULL;
	    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
		XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
			Tk_InternAtom((Tk_Window) winPtr,
				"WM_CLIENT_MACHINE"));
	    }
	}
	return TCL_OK;
    }
    if (wmPtr->clientMachine != NULL) {
	ckfree(wmPtr->clientMachine);
    }
    wmPtr->clientMachine = (char *)ckalloc(objv[3]->length + 1);
    wmPtr->clientMachine = ckalloc(objv[3]->length + 1);
    strcpy(wmPtr->clientMachine, argv3);
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	XTextProperty textProp;
	Tcl_DString ds;

	(void)Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, TCL_INDEX_NONE, &ds);
	Tcl_UtfToExternalDString(NULL, wmPtr->clientMachine, -1, &ds);
	if (XStringListToTextProperty(&(Tcl_DStringValue(&ds)), 1,
		&textProp) != 0) {
	    unsigned long pid = (unsigned long) getpid();

	    XSetWMClientMachine(winPtr->display, wmPtr->wrapperPtr->window,
		    &textProp);
	    XFree(textProp.value);
	    XFree((char *) textProp.value);

	    /*
	     * Inform the server (and more particularly any session manager)
	     * what our process ID is. We only do this when the CLIENT_MACHINE
	     * property is set since the spec for _NET_WM_PID requires that to
	     * be set too.
	     */
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546

1547
1548
1549

1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568


1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1533
1534
1535
1536
1537
1538
1539

1540
1541
1542

1543
1544
1545

1546

1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562


1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574

1575
1576
1577

1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593







-
+


-
+


-
+
-
















-
-
+
+










-
+


-
+







-
+







 */

static int
WmColormapwindowsCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Window *cmapList;
    TkWindow *winPtr2;
    Tcl_Size i, windowObjc;
    int count, i, windowObjc, gotToplevel;
    int count, gotToplevel;
    Tcl_Obj **windowObjv, *resultObj;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
	return TCL_ERROR;
    }
    Tk_MakeWindowExist((Tk_Window) winPtr);
    if (wmPtr->wrapperPtr == NULL) {
	CreateWrapper(wmPtr);
    }
    if (objc == 3) {
	if (XGetWMColormapWindows(winPtr->display,
		wmPtr->wrapperPtr->window, &cmapList, &count) == 0) {
	    return TCL_OK;
	}
	resultObj = Tcl_NewObj();
	for (i = 0; i < (Tcl_Size)count; i++) {
	    if ((i == ((Tcl_Size)count-1))
	for (i = 0; i < count; i++) {
	    if ((i == (count-1))
		    && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
		break;
	    }
	    winPtr2 = (TkWindow *)
		   Tk_IdToWindow(winPtr->display, cmapList[i]);
	    if (winPtr2 == NULL) {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tcl_ObjPrintf("0x%lx", cmapList[i]));
	    } else {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tcl_NewStringObj(winPtr2->pathName, TCL_INDEX_NONE));
			Tcl_NewStringObj(winPtr2->pathName, -1));
	    }
	}
	XFree(cmapList);
	XFree((char *) cmapList);
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
    }
    if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
	    != TCL_OK) {
	return TCL_ERROR;
    }
    cmapList = (Window *)ckalloc((windowObjc+1) * sizeof(Window));
    cmapList = ckalloc((windowObjc+1) * sizeof(Window));
    gotToplevel = 0;
    for (i = 0; i < windowObjc; i++) {
	Tk_Window mapWin;

	if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
		&mapWin) != TCL_OK) {
	    ckfree(cmapList);
1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645

1646
1647
1648

1649
1650

1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661

1662
1663
1664
1665
1666
1667
1668
1631
1632
1633
1634
1635
1636
1637

1638
1639
1640

1641
1642
1643

1644
1645

1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656

1657
1658
1659
1660
1661
1662
1663
1664







-
+


-
+


-
+

-
+










-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmCommandCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size cmdArgc;
    int cmdArgc;
    const char **cmdArgv;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->cmdArgv != NULL) {
	    char *arg = Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv);

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(arg, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(arg, -1));
	    ckfree(arg);
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (argv3[0] == 0) {
	if (wmPtr->cmdArgv != NULL) {
1704
1705
1706
1707
1708
1709
1710
1711

1712
1713
1714

1715
1716
1717

1718
1719
1720
1721
1722
1723
1724
1700
1701
1702
1703
1704
1705
1706

1707
1708
1709

1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
1720







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmDeiconifyCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
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
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







-
+


-
+


-
+












-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFocusmodelCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"active", "passive", NULL };
    enum options {
	OPT_ACTIVE, OPT_PASSIVE };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?active|passive?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		wmPtr->hints.input ? "passive" : "active", TCL_INDEX_NONE));
		wmPtr->hints.input ? "passive" : "active", -1));
	return TCL_OK;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
	    sizeof(char *), "argument", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }
1809
1810
1811
1812
1813
1814
1815
1816

1817
1818
1819
1820



1821
1822

1823
1824
1825
1826
1827
1828
1829
1805
1806
1807
1808
1809
1810
1811

1812
1813



1814
1815
1816
1817

1818
1819
1820
1821
1822
1823
1824
1825







-
+

-
-
-
+
+
+

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmForgetCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel or Frame to work with */
    TCL_UNUSED(Tcl_Interp *),		/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),			/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))	/* Argument objects. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window) winPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;

    if (Tk_IsTopLevel(frameWin)) {
	TkFocusJoin(winPtr);
	Tk_UnmapWindow(frameWin);
	TkWmDeadWindow(winPtr);
	winPtr->flags &=
		~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
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
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







-
+


-
+


-
+

-









-
-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFrameCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Window window;
    char buf[TCL_INTEGER_SPACE];

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    window = wmPtr->reparent;
    if (window == None) {
	window = Tk_WindowId((Tk_Window) winPtr);
    }
    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)window);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("0x%x", (unsigned) window));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmGeometryCmd --
1904
1905
1906
1907
1908
1909
1910
1911

1912
1913
1914

1915
1916
1917

1918
1919
1920
1921
1922
1923
1924
1898
1899
1900
1901
1902
1903
1904

1905
1906
1907

1908
1909
1910

1911
1912
1913
1914
1915
1916
1917
1918







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGeometryCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    char xSign, ySign;
    int width, height;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newGeometry?");
	return TCL_ERROR;
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
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







-
+


-
+


-
+











-
-
-
-
+
+
+
+










-
+

















-
+





-
+





-
+





-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGridCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int reqWidth, reqHeight, widthInc, heightInc;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?baseWidth baseHeight widthInc heightInc?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PBaseSize) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewWideIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewWideIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewWideIntObj(wmPtr->heightInc);
	    results[0] = Tcl_NewIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewIntObj(wmPtr->heightInc);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	/*
	 * Turn off gridding and reset the width and height to make sense as
	 * ungridded numbers.
	 */

	wmPtr->sizeHintsFlags &= ~PBaseSize;
	wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
	if (wmPtr->width != -1) {
	    wmPtr->width = winPtr->reqWidth + (wmPtr->width
		    - wmPtr->reqGridWidth)*wmPtr->widthInc;
	    wmPtr->height = winPtr->reqHeight + (wmPtr->height
		    - wmPtr->reqGridHeight)*wmPtr->heightInc;
	}
	wmPtr->widthInc = 1;
	wmPtr->heightInc = 1;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &heightInc) !=TCL_OK)) {
	    return TCL_ERROR;
	}
	if (reqWidth < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "baseWidth can't be < 0", TCL_INDEX_NONE));
		    "baseWidth can't be < 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (reqHeight < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "baseHeight can't be < 0", TCL_INDEX_NONE));
		    "baseHeight can't be < 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (widthInc <= 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "widthInc can't be <= 0", TCL_INDEX_NONE));
		    "widthInc can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (heightInc <= 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "heightInc can't be <= 0", TCL_INDEX_NONE));
		    "heightInc can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
		heightInc);
    }
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
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
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







-
+


-
+










-
+







 */

static int
WmGroupCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    WmInfo *wmPtr2;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & WindowGroupHint) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (*argv3 == '\0') {
	wmPtr->hints.flags &= ~WindowGroupHint;
	if (wmPtr->leaderName != NULL) {
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
2106
2107
2108
2109
2110
2111
2112

2113
2114
2115
2116










































2117
2118
2119
2120
2121
2122
2123







-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	    CreateWrapper(wmPtr2);
	}
	if (wmPtr->leaderName != NULL) {
	    ckfree(wmPtr->leaderName);
	}
	wmPtr->hints.window_group = Tk_WindowId(wmPtr2->wrapperPtr);
	wmPtr->hints.flags |= WindowGroupHint;
	wmPtr->leaderName = (char *)ckalloc(objv[3]->length + 1);
	wmPtr->leaderName = ckalloc(objv[3]->length + 1);
	strcpy(wmPtr->leaderName, argv3);
    }
    UpdateHints(winPtr);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconbadgeCmd --
 *
 *	This function is invoked to process the "wm iconbadge" Tcl command.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbadgeCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    TkWindow *tkWin,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    (void) tkWin;
    char cmd[4096];

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window badge");
	return TCL_ERROR;
    }

    snprintf(cmd, sizeof(cmd), "::tk::icons::IconBadge {%s} {%s}",
	    Tcl_GetString(objv[2]),
	    Tcl_GetString(objv[3]));
    if (Tcl_EvalEx(interp, cmd, TCL_INDEX_NONE, TCL_EVAL_DIRECT) != TCL_OK) {
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconbitmapCmd --
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
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







-
+


-
+


-
+











-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbitmapCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Pixmap pixmap;
    const char *argv3;

    if ((objc < 3) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & IconPixmapHint) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    Tk_NameOfBitmap(winPtr->display,
			    wmPtr->hints.icon_pixmap), TCL_INDEX_NONE));
			    wmPtr->hints.icon_pixmap), -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (*argv3 == '\0') {
	if (wmPtr->hints.icon_pixmap != None) {
	    Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
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
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







-
+


-
+


-
+













-
+








-
+






-
+






-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconifyCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": override-redirect flag is set",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "OVERRIDE_REDIRECT",
		NULL);
	return TCL_ERROR;
    }
    if (wmPtr->containerPtr != NULL) {
    if (wmPtr->masterPtr != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is a transient",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "TRANSIENT", NULL);
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is an icon for \"%s\"",
		"can't iconify %s: it is an icon for %s",
		winPtr->pathName, Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "ICON", NULL);
	return TCL_ERROR;
    }
    if (winPtr->flags & TK_EMBEDDED) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is an embedded window",
		"can't iconify %s: it is an embedded window",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "EMBEDDED", NULL);
	return TCL_ERROR;
    }
    if (TkpWmSetState(winPtr, IconicState) == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"couldn't send iconify message to window manager", TCL_INDEX_NONE));
		"couldn't send iconify message to window manager", -1));
	Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
2312
2313
2314
2315
2316
2317
2318
2319

2320
2321
2322

2323
2324
2325
2326
2327
2328
2329
2264
2265
2266
2267
2268
2269
2270

2271
2272
2273

2274
2275
2276
2277
2278
2279
2280
2281







-
+


-
+







 */

static int
WmIconmaskCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Pixmap pixmap;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
	return TCL_ERROR;
    }
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
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







-
+


-
+


-
+








-
+







-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconnameCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->iconName != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->iconName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->iconName, -1));
	}
	return TCL_OK;
    } else {
	if (wmPtr->iconName != NULL) {
	    ckfree(wmPtr->iconName);
	}
	argv3 = Tcl_GetString(objv[3]);
	wmPtr->iconName = (char *)ckalloc(objv[3]->length + 1);
	wmPtr->iconName = ckalloc(objv[3]->length + 1);
	strcpy(wmPtr->iconName, argv3);
	if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	    UpdateTitle(winPtr);
	}
    }
    return TCL_OK;
}
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
2371
2372
2373
2374
2375
2376
2377

2378
2379
2380

2381
2382
2383

2384
2385
2386


2387
2388
2389
2390
2391
2392
2393
2394







-
+


-
+


-
+


-
-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconphotoCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_PhotoHandle photo;
    Tk_PhotoImageBlock block;
    Tcl_Size i;
    int size = 0, width, height, index = 0, x, y, isDefault = 0;
    int i, size = 0, width, height, index = 0, x, y, isDefault = 0;
    unsigned long *iconPropertyData;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?-default? image1 ?image2 ...?");
	return TCL_ERROR;
    }
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
2428
2429
2430
2431
2432
2433
2434

2435
2436
2437
2438
2439
2440
2441
2442
2443

2444




2445
2446
2447
2448
2449
2450
2451







-
+








-
+
-
-
-
-







    /*
     * We have calculated the size of the data. Try to allocate the needed
     * memory space. This is an unsigned long array (despite this being twice
     * as much as is really needed on LP64 platforms) because that's what X
     * defines CARD32 arrays to use. [Bug 2902814]
     */

    iconPropertyData = (unsigned long *)attemptckalloc(sizeof(unsigned long) * size);
    iconPropertyData = attemptckalloc(sizeof(unsigned long) * size);
    if (iconPropertyData == NULL) {
	return TCL_ERROR;
    }
    memset(iconPropertyData, 0, sizeof(unsigned long) * size);

    for (i = 3 + isDefault; i < objc; i++) {
	photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
	if (photo == NULL) {
	    ckfree(iconPropertyData);
	    Tcl_Free((char *) iconPropertyData);
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	        "failed to create an iconphoto with image \"%s\"",
		Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL);
	    return TCL_ERROR;
	}
	Tk_PhotoGetSize(photo, &width, &height);
	Tk_PhotoGetImage(photo, &block);

	/*
	 * Each image data will be placed as an array of 32bit packed
2519
2520
2521
2522
2523
2524
2525
2526

2527
2528

2529
2530
2531
2532
2533
2534
2535
2466
2467
2468
2469
2470
2471
2472

2473
2474

2475
2476
2477
2478
2479
2480
2481
2482







-
+

-
+







	 * The image data will be encoded in the iconPropertyData array.
	 */

	iconPropertyData[index++] = (unsigned long) width;
	iconPropertyData[index++] = (unsigned long) height;
	for (y = 0; y < height; y++) {
	    for (x = 0; x < width; x++) {
		unsigned char *pixelPtr =
		register unsigned char *pixelPtr =
			block.pixelPtr + x*block.pixelSize + y*block.pitch;
		unsigned long R, G, B, A;
		register unsigned long R, G, B, A;

		R = pixelPtr[block.offset[0]];
		G = pixelPtr[block.offset[1]];
		B = pixelPtr[block.offset[2]];
		A = pixelPtr[block.offset[3]];
		iconPropertyData[index++] = A<<24 | R<<16 | G<<8 | B<<0;
	    }
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
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







-
+


-
+


-
+










-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconpositionCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?x y?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & IconPositionHint) {
	    Tcl_Obj *results[2];

	    results[0] = Tcl_NewWideIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->hints.icon_y);
	    results[0] = Tcl_NewIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewIntObj(wmPtr->hints.icon_y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	}
	return TCL_OK;
    }
    if (Tcl_GetString(objv[3])[0] == '\0') {
	wmPtr->hints.flags &= ~IconPositionHint;
    } else {
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
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







-
+


-
+










-
+







 */

static int
WmIconwindowCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    WmInfo *wmPtr2;
    XSetWindowAttributes atts;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->icon != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj(wmPtr->icon));
	    Tcl_SetObjResult(interp, TkNewWindowObj(wmPtr->icon));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->hints.flags &= ~IconWindowHint;
	if (wmPtr->icon != NULL) {
	    /*
2747
2748
2749
2750
2751
2752
2753
2754

2755
2756
2757
2758


2759
2760
2761


2762
2763
2764
2765
2766
2767
2768
2694
2695
2696
2697
2698
2699
2700

2701
2702
2703


2704
2705
2706


2707
2708
2709
2710
2711
2712
2713
2714
2715







-
+


-
-
+
+

-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmManageCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel or Frame to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),			/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))	/* Argument objects. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window) winPtr;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!Tk_IsTopLevel(frameWin)) {
	if (!Tk_IsManageable(frameWin)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" is not manageable: must be a frame,"
		    " labelframe or toplevel", Tk_PathName(frameWin)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "MANAGE", NULL);
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
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







-
+


-
+


-
+










-
-
+
+



-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmMaxsizeCmd(
    Tk_Window tkwin,	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_Obj *results[2];

	GetMaxSize(wmPtr, &width, &height);
	results[0] = Tcl_NewWideIntObj(width);
	results[1] = Tcl_NewWideIntObj(height);
	results[0] = Tcl_NewIntObj(width);
	results[1] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }
    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->maxWidth = width;
    wmPtr->maxHeight = height;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;

    if (width <= 0 && height <= 0) {
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
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







-
+


-
+


-
+









-
-
+
+



-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmMinsizeCmd(
    Tk_Window tkwin,	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_Obj *results[2];

	results[0] = Tcl_NewWideIntObj(wmPtr->minWidth);
	results[1] = Tcl_NewWideIntObj(wmPtr->minHeight);
	results[0] = Tcl_NewIntObj(wmPtr->minWidth);
	results[1] = Tcl_NewIntObj(wmPtr->minHeight);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }
    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->minWidth = width;
    wmPtr->minHeight = height;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;
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
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







-
+


-
+


-
+











-
+


-
+





-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmOverrideredirectCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Bool boolValue, curValue;
    int boolean, curValue;
    XSetWindowAttributes atts;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
	return TCL_ERROR;
    }
    curValue = Tk_Attributes((Tk_Window) winPtr)->override_redirect;
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(curValue));
	return TCL_OK;
    }
    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolValue) != TCL_OK) {
    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) {
	return TCL_ERROR;
    }
    if (curValue != boolValue) {
    if (curValue != boolean) {
	/*
	 * Only do this if we are really changing value, because it causes
	 * some funky stuff to occur
	 */

	atts.override_redirect = boolValue;
	atts.override_redirect = (boolean) ? True : False;
	Tk_ChangeWindowAttributes((Tk_Window) winPtr, CWOverrideRedirect,
		&atts);
	if (winPtr->wmInfoPtr->wrapperPtr != NULL) {
	    Tk_ChangeWindowAttributes(
		    (Tk_Window) winPtr->wmInfoPtr->wrapperPtr,
		    CWOverrideRedirect, &atts);
	}
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
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







-
+


-
+


-
+


















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmPositionfromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL };
    enum options {
	OPT_PROGRAM, OPT_USER };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user/program?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	const char *sourceStr = "";

	if (wmPtr->sizeHintsFlags & USPosition) {
	    sourceStr = "user";
	} else if (wmPtr->sizeHintsFlags & PPosition) {
	    sourceStr = "program";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, -1));
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USPosition|PPosition);
    } else {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
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
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







-
+


-
+


-
-
+
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmProtocolCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    ProtocolHandler *protPtr, *prevPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    register ProtocolHandler *protPtr, *prevPtr;
    Atom protocol;
    const char *cmd;
    Tcl_Size cmdLength;
    int cmdLength;

    if ((objc < 3) || (objc > 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name? ?command?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	/*
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
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







-
+












-
+







	 * Return the command to handle a given protocol.
	 */

	for (protPtr = wmPtr->protPtr; protPtr != NULL;
		protPtr = protPtr->nextPtr) {
	    if (protPtr->protocol == protocol) {
		Tcl_SetObjResult(interp,
			Tcl_NewStringObj(protPtr->command, TCL_INDEX_NONE));
			Tcl_NewStringObj(protPtr->command, -1));
		return TCL_OK;
	    }
	}
	return TCL_OK;
    }

    /*
     * Special case for _NET_WM_PING: that's always handled directly.
     */

    if (strcmp(Tcl_GetString(objv[3]), "_NET_WM_PING") == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"may not alter handling of that protocol", TCL_INDEX_NONE));
		"may not alter handling of that protocol", -1));
	Tcl_SetErrorCode(interp, "TK", "WM", "PROTOCOL", "RESERVED", NULL);
	return TCL_ERROR;
    }

    /*
     * Delete any current protocol handler, then create a new one with the
     * specified command, unless the command is empty.
3122
3123
3124
3125
3126
3127
3128
3129

3130
3131
3132
3133
3134
3135
3136
3069
3070
3071
3072
3073
3074
3075

3076
3077
3078
3079
3080
3081
3082
3083







-
+







	    }
	    Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
	    break;
	}
    }
    cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
    if (cmdLength > 0) {
	protPtr = (ProtocolHandler *)ckalloc(HANDLER_SIZE(cmdLength));
	protPtr = ckalloc(HANDLER_SIZE(cmdLength));
	protPtr->protocol = protocol;
	protPtr->nextPtr = wmPtr->protPtr;
	wmPtr->protPtr = protPtr;
	protPtr->interp = interp;
	memcpy(protPtr->command, cmd, cmdLength + 1);
    }
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
3154
3155
3156
3157
3158
3159
3160
3161

3162
3163
3164

3165
3166
3167

3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178


3179
3180
3181
3182
3183
3184
3185
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







-
+


-
+


-
+









-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmResizableCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_Obj *results[2];

	results[0] = Tcl_NewWideIntObj(!(wmPtr->flags&WM_WIDTH_NOT_RESIZABLE));
	results[1] = Tcl_NewWideIntObj(!(wmPtr->flags&WM_HEIGHT_NOT_RESIZABLE));
	results[0] = Tcl_NewBooleanObj(!(wmPtr->flags&WM_WIDTH_NOT_RESIZABLE));
	results[1] = Tcl_NewBooleanObj(!(wmPtr->flags&WM_HEIGHT_NOT_RESIZABLE));
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }
    if ((Tcl_GetBooleanFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetBooleanFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
3213
3214
3215
3216
3217
3218
3219
3220

3221
3222
3223

3224
3225
3226

3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245

3246
3247
3248
3249
3250
3251
3252
3160
3161
3162
3163
3164
3165
3166

3167
3168
3169

3170
3171
3172

3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191

3192
3193
3194
3195
3196
3197
3198
3199







-
+


-
+


-
+


















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmSizefromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL };
    enum options {
	OPT_PROGRAM, OPT_USER };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user|program?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	const char *sourceStr = "";

	if (wmPtr->sizeHintsFlags & USSize) {
	    sourceStr = "user";
	} else if (wmPtr->sizeHintsFlags & PSize) {
	    sourceStr = "program";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, -1));
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USSize|PSize);
    } else {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
3284
3285
3286
3287
3288
3289
3290
3291

3292
3293
3294
3295
3296
3297
3298
3231
3232
3233
3234
3235
3236
3237

3238
3239
3240
3241
3242
3243
3244
3245







-
+







 */

static int
WmStackorderCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkWindow **windows, **window_ptr;
    static const char *const optionStrings[] = {
	"isabove", "isbelow", NULL };
    enum options {
	OPT_ISABOVE, OPT_ISBELOW };
3307
3308
3309
3310
3311
3312
3313
3314

3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3254
3255
3256
3257
3258
3259
3260

3261
3262
3263
3264
3265


3266
3267
3268
3269
3270
3271
3272







-
+




-
-







	windows = TkWmStackorderToplevel(winPtr);
	if (windows != NULL) {
	    Tcl_Obj *resultObj = Tcl_NewObj();

	    /* ASSERT: true [Bug 1789819]*/
	    for (window_ptr = windows; *window_ptr ; window_ptr++) {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tcl_NewStringObj((*window_ptr)->pathName, TCL_INDEX_NONE));
			Tcl_NewStringObj((*window_ptr)->pathName, -1));
	    }
	    ckfree(windows);
	    Tcl_SetObjResult(interp, resultObj);
	    return TCL_OK;
	} else {
	    return TCL_ERROR;
	}
    } else {
	Tk_Window relWin;
	TkWindow *winPtr2;
	int index1=-1, index2=-1, result;

	if (TkGetWindowFromObj(interp, tkwin, objv[4], &relWin) != TCL_OK) {
3355
3356
3357
3358
3359
3360
3361
3362

3363
3364
3365
3366
3367
3368
3369
3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3314







-
+







	 * Lookup stacking order of all toplevels that are children of "." and
	 * find the position of winPtr and winPtr2 in the stacking order.
	 */

	windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
	if (windows == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "TkWmStackorderToplevel failed", TCL_INDEX_NONE));
		    "TkWmStackorderToplevel failed", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	    return TCL_ERROR;
	}

	for (window_ptr = windows; *window_ptr ; window_ptr++) {
	    if (*window_ptr == winPtr) {
		index1 = (window_ptr - windows);
3380
3381
3382
3383
3384
3385
3386
3387

3388
3389
3390
3391
3392
3393
3394
3325
3326
3327
3328
3329
3330
3331

3332
3333
3334
3335
3336
3337
3338
3339







-
+







	    return TCL_ERROR;
	}
	if (index == OPT_ISABOVE) {
	    result = index1 > index2;
	} else { /* OPT_ISBELOW */
	    result = index1 < index2;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(result));
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result));
	return TCL_OK;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
3405
3406
3407
3408
3409
3410
3411
3412

3413
3414
3415

3416
3417
3418

3419
3420

3421
3422

3423
3424
3425
3426
3427
3428
3429
3350
3351
3352
3353
3354
3355
3356

3357
3358
3359

3360
3361
3362

3363
3364

3365
3366

3367
3368
3369
3370
3371
3372
3373
3374







-
+


-
+


-
+

-
+

-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmStateCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"iconic", "normal", "withdrawn", NULL };
	"normal", "iconic", "withdrawn", NULL };
    enum options {
	OPT_ICONIC, OPT_NORMAL, OPT_WITHDRAWN };
	OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN };
    int index;

    if ((objc < 3) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?state?");
	return TCL_ERROR;
    }
    if (objc == 4) {
3448
3449
3450
3451
3452
3453
3454
3455

3456
3457
3458
3459
3460
3461
3462
3393
3394
3395
3396
3397
3398
3399

3400
3401
3402
3403
3404
3405
3406
3407







-
+







		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": override-redirect flag is set",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE",
			"OVERRIDE_REDIRECT", NULL);
		return TCL_ERROR;
	    }
	    if (wmPtr->containerPtr != NULL) {
	    if (wmPtr->masterPtr != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": it is a transient",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "TRANSIENT",
			NULL);
		return TCL_ERROR;
	    }
3487
3488
3489
3490
3491
3492
3493
3494

3495
3496
3497
3498
3499
3500
3501
3432
3433
3434
3435
3436
3437
3438

3439
3440
3441
3442
3443
3444
3445
3446







-
+







	} else if (Tk_IsMapped((Tk_Window) winPtr)
		|| ((wmPtr->flags & WM_NEVER_MAPPED)
			&& (wmPtr->hints.initial_state == NormalState))) {
	    state = "normal";
	} else {
	    state = "iconic";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(state, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(state, -1));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
3511
3512
3513
3514
3515
3516
3517
3518

3519
3520
3521

3522
3523
3524

3525
3526
3527
3528
3529
3530
3531
3532
3533

3534
3535

3536
3537
3538
3539
3540
3541
3542

3543
3544
3545
3546
3547
3548
3549
3456
3457
3458
3459
3460
3461
3462

3463
3464
3465

3466
3467
3468

3469
3470
3471
3472
3473
3474
3475
3476
3477

3478
3479

3480
3481
3482
3483
3484
3485
3486

3487
3488
3489
3490
3491
3492
3493
3494







-
+


-
+


-
+








-
+

-
+






-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmTitleCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newTitle?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->title) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->title, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->title, -1));
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->nameUid, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(winPtr->nameUid, -1));
	}
    } else {
	if (wmPtr->title != NULL) {
	    ckfree(wmPtr->title);
	}
	argv3 = Tcl_GetString(objv[3]);
	wmPtr->title = (char *)ckalloc(objv[3]->length + 1);
	wmPtr->title = ckalloc(objv[3]->length + 1);
	strcpy(wmPtr->title, argv3);

	if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	    UpdateTitle(winPtr);
	}
    }
    return TCL_OK;
3567
3568
3569
3570
3571
3572
3573
3574

3575
3576
3577
3578


3579
3580
3581
3582

3583
3584
3585
3586
3587


3588
3589
3590
3591
3592

3593
3594

3595
3596
3597
3598
3599


3600
3601
3602
3603
3604
3605
3606
3607
3608
3609

3610
3611

3612
3613

3614
3615
3616
3617


3618
3619

3620
3621
3622

3623
3624

3625
3626
3627
3628
3629
3630
3631
3632
3633
3634

3635
3636
3637
3638
3639
3640
3641

3642
3643
3644
3645
3646
3647
3648
3649
3650


3651
3652
3653
3654



3655
3656
3657
3658

3659
3660
3661
3662



3663
3664
3665
3666
3667



3668
3669
3670
3671
3672


3673
3674
3675

3676
3677
3678
3679

3680
3681
3682
3683
3684
3685
3686
3687
3688

3689
3690
3691

3692
3693
3694
3695
3696
3697
3698
3512
3513
3514
3515
3516
3517
3518

3519
3520
3521


3522
3523
3524
3525
3526

3527
3528
3529
3530


3531
3532
3533
3534
3535
3536

3537
3538

3539
3540
3541
3542


3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553

3554
3555

3556
3557

3558
3559
3560


3561
3562
3563

3564
3565
3566

3567
3568

3569
3570
3571
3572
3573
3574
3575
3576
3577
3578

3579
3580
3581
3582
3583
3584
3585

3586
3587
3588
3589
3590
3591




3592
3593




3594
3595
3596




3597
3598



3599
3600
3601
3602
3603



3604
3605
3606
3607
3608
3609


3610
3611
3612
3613

3614
3615
3616
3617

3618
3619
3620
3621
3622
3623
3624
3625
3626

3627
3628
3629

3630
3631
3632
3633
3634
3635
3636
3637







-
+


-
-
+
+



-
+



-
-
+
+




-
+

-
+



-
-
+
+









-
+

-
+

-
+


-
-
+
+

-
+


-
+

-
+









-
+






-
+





-
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
+

-
-
-
+
+
+


-
-
-
+
+
+



-
-
+
+


-
+



-
+








-
+


-
+







 */

static int
WmTransientCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow *containerPtr = wmPtr->containerPtr, *w;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow *masterPtr = wmPtr->masterPtr;
    WmInfo *wmPtr2;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?window?");
	Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (containerPtr != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window) containerPtr));
	if (masterPtr != NULL) {
	    Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window) masterPtr));
	}
	return TCL_OK;
    }
    if (Tcl_GetString(objv[3])[0] == '\0') {
	if (containerPtr != NULL) {
	if (masterPtr != NULL) {
	    /*
	     * If we had a container, tell them that we aren't tied to them
	     * If we had a master, tell them that we aren't tied to them
	     * anymore
	     */

	    containerPtr->wmInfoPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) containerPtr, StructureNotifyMask,
	    masterPtr->wmInfoPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) masterPtr, StructureNotifyMask,
		    WmWaitMapProc, winPtr);

	    /*
	     * FIXME: Need a call like Win32's UpdateWrapper() so we can
	     * recreate the wrapper and get rid of the transient window
	     * decorations.
	     */
	}

	wmPtr->containerPtr = NULL;
	wmPtr->masterPtr = NULL;
    } else {
	Tk_Window container;
	Tk_Window masterWin;

	if (TkGetWindowFromObj(interp, tkwin, objv[3], &container)!=TCL_OK) {
	if (TkGetWindowFromObj(interp, tkwin, objv[3], &masterWin)!=TCL_OK) {
	    return TCL_ERROR;
	}
	containerPtr = (TkWindow *) container;
	while (!Tk_TopWinHierarchy(containerPtr)) {
	masterPtr = (TkWindow *) masterWin;
	while (!Tk_TopWinHierarchy(masterPtr)) {
	    /*
	     * Ensure that the container window is actually a Tk toplevel.
	     * Ensure that the master window is actually a Tk toplevel.
	     */

	    containerPtr = containerPtr->parentPtr;
	    masterPtr = masterPtr->parentPtr;
	}
	Tk_MakeWindowExist((Tk_Window) containerPtr);
	Tk_MakeWindowExist((Tk_Window) masterPtr);

	if (wmPtr->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a transient: it is an icon for %s",
		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}

	wmPtr2 = containerPtr->wmInfoPtr;
	wmPtr2 = masterPtr->wmInfoPtr;
	if (wmPtr2->wrapperPtr == NULL) {
	    CreateWrapper(wmPtr2);
	}

	if (wmPtr2->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a container: it is an icon for %s",
		    "can't make \"%s\" a master: it is an icon for %s",
		    Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}

	for (w = containerPtr; w != NULL && w->wmInfoPtr != NULL;
	    w = (TkWindow *)w->wmInfoPtr->containerPtr) {
	    if (w == winPtr) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	if (masterPtr == winPtr) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't set \"%s\" as container: would cause management loop",
		    Tk_PathName(containerPtr)));
		Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
		return TCL_ERROR;
		    "can't make \"%s\" its own master", Tk_PathName(winPtr)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
	    return TCL_ERROR;
	    }
	}

	if (containerPtr != wmPtr->containerPtr) {
	} else if (masterPtr != wmPtr->masterPtr) {
	    /*
	     * Remove old container map/unmap binding before setting the new
	     * container. The event handler will ensure that transient states
	     * reflect the state of the container.
	     * Remove old master map/unmap binding before setting the new
	     * master. The event handler will ensure that transient states
	     * reflect the state of the master.
	     */

	    if (wmPtr->containerPtr != NULL) {
		wmPtr->containerPtr->wmInfoPtr->numTransients--;
		Tk_DeleteEventHandler((Tk_Window) wmPtr->containerPtr,
	    if (wmPtr->masterPtr != NULL) {
		wmPtr->masterPtr->wmInfoPtr->numTransients--;
		Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
			StructureNotifyMask, WmWaitMapProc, winPtr);
	    }

	    containerPtr->wmInfoPtr->numTransients++;
	    Tk_CreateEventHandler((Tk_Window) containerPtr,
	    masterPtr->wmInfoPtr->numTransients++;
	    Tk_CreateEventHandler((Tk_Window) masterPtr,
		    StructureNotifyMask, WmWaitMapProc, winPtr);

	    wmPtr->containerPtr = containerPtr;
	    wmPtr->masterPtr = masterPtr;
	}
    }
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	if (wmPtr->containerPtr != NULL && !Tk_IsMapped(wmPtr->containerPtr)) {
	if (wmPtr->masterPtr != NULL && !Tk_IsMapped(wmPtr->masterPtr)) {
	    if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"couldn't send withdraw message to window manager",
			-1));
		Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
		return TCL_ERROR;
	    }
	} else {
	    if (wmPtr->containerPtr != NULL) {
	    if (wmPtr->masterPtr != NULL) {
		XSetTransientForHint(winPtr->display,
			wmPtr->wrapperPtr->window,
			wmPtr->containerPtr->wmInfoPtr->wrapperPtr->window);
			wmPtr->masterPtr->wmInfoPtr->wrapperPtr->window);
	    } else {
		XDeleteProperty(winPtr->display, wmPtr->wrapperPtr->window,
			Tk_InternAtom((Tk_Window) winPtr,"WM_TRANSIENT_FOR"));
	    }
	}
    }
    return TCL_OK;
3713
3714
3715
3716
3717
3718
3719
3720

3721
3722
3723

3724
3725
3726

3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742

3743
3744
3745
3746
3747
3748
3749
3652
3653
3654
3655
3656
3657
3658

3659
3660
3661

3662
3663
3664

3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680

3681
3682
3683
3684
3685
3686
3687
3688







-
+


-
+


-
+















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmWithdrawCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't withdraw %s: it is an icon for %s",
		Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "WITHDRAW", "ICON", NULL);
	return TCL_ERROR;
    }
    wmPtr->flags |= WM_WITHDRAWN;
    if (TkpWmSetState(winPtr, WithdrawnState) == 0) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"couldn't send withdraw message to window manager", TCL_INDEX_NONE));
		"couldn't send withdraw message to window manager", -1));
	Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
3760
3761
3762
3763
3764
3765
3766
3767

3768
3769
3770
3771
3772

3773
3774
3775
3776


3777
3778

3779
3780
3781
3782
3783
3784
3785
3699
3700
3701
3702
3703
3704
3705

3706
3707
3708
3709
3710

3711
3712
3713


3714
3715
3716

3717
3718
3719
3720
3721
3722
3723
3724







-
+




-
+


-
-
+
+

-
+







	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
}

/*
 * Invoked when a MapNotify or UnmapNotify event is delivered for a toplevel
 * that is the container of a transient toplevel.
 * that is the master of a transient toplevel.
 */

static void
WmWaitMapProc(
    void *clientData,	/* Pointer to window. */
    ClientData clientData,	/* Pointer to window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *containerPtr = winPtr->wmInfoPtr->containerPtr;
    TkWindow *winPtr = clientData;
    TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;

    if (containerPtr == NULL) {
    if (masterPtr == NULL) {
	return;
    }

    if (eventPtr->type == MapNotify) {
	if (!(winPtr->wmInfoPtr->flags & WM_WITHDRAWN)) {
	    (void) TkpWmSetState(winPtr, NormalState);
	}
3819
3820
3821
3822
3823
3824
3825
3826

3827
3828
3829
3830
3831
3832
3833
3758
3759
3760
3761
3762
3763
3764

3765
3766
3767
3768
3769
3770
3771
3772







-
+







				 * requested geometry for tkwin. */
    int reqHeight,		/* Height (in grid units) corresponding to the
				 * requested geometry for tkwin. */
    int widthInc, int heightInc)/* Pixel increments corresponding to a change
				 * of one grid unit. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;
    register WmInfo *wmPtr;

    /*
     * Ensure widthInc and heightInc are greater than 0
     */

    if (widthInc <= 0) {
	widthInc = 1;
3860
3861
3862
3863
3864
3865
3866
3867


3868
3869
3870
3871
3872
3873
3874
3799
3800
3801
3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813
3814







-
+
+







	return;
    }

    if ((wmPtr->reqGridWidth == reqWidth)
	    && (wmPtr->reqGridHeight == reqHeight)
	    && (wmPtr->widthInc == widthInc)
	    && (wmPtr->heightInc == heightInc)
	    && ((wmPtr->sizeHintsFlags & PBaseSize) == PBaseSize)) {
	    && ((wmPtr->sizeHintsFlags & (PBaseSize|PResizeInc))
		    == (PBaseSize|PResizeInc))) {
	return;
    }

    /*
     * If gridding was previously off, then forget about any window size
     * requests made by the user or via "wm geometry": these are in pixel
     * units and there's no easy way to translate them to grid units since the
3891
3892
3893
3894
3895
3896
3897
3898

3899
3900
3901
3902
3903
3904
3905
3831
3832
3833
3834
3835
3836
3837

3838
3839
3840
3841
3842
3843
3844
3845







-
+







     */

    wmPtr->gridWin = tkwin;
    wmPtr->reqGridWidth = reqWidth;
    wmPtr->reqGridHeight = reqHeight;
    wmPtr->widthInc = widthInc;
    wmPtr->heightInc = heightInc;
    wmPtr->sizeHintsFlags |= PBaseSize;
    wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc;
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
}

3923
3924
3925
3926
3927
3928
3929
3930

3931
3932
3933
3934
3935
3936
3937
3863
3864
3865
3866
3867
3868
3869

3870
3871
3872
3873
3874
3875
3876
3877







-
+








void
Tk_UnsetGrid(
    Tk_Window tkwin)		/* Token for window that is currently
				 * controlling gridding. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;
    register WmInfo *wmPtr;

    /*
     * Find the top-level window for tkwin, plus the window manager
     * information.
     */

    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
3950
3951
3952
3953
3954
3955
3956
3957

3958
3959
3960
3961
3962
3963
3964
3890
3891
3892
3893
3894
3895
3896

3897
3898
3899
3900
3901
3902
3903
3904







-
+







    }

    if (tkwin != wmPtr->gridWin) {
	return;
    }

    wmPtr->gridWin = NULL;
    wmPtr->sizeHintsFlags &= ~PBaseSize;
    wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
    if (wmPtr->width != -1) {
	wmPtr->width = winPtr->reqWidth + (wmPtr->width
		- wmPtr->reqGridWidth)*wmPtr->widthInc;
	wmPtr->height = winPtr->reqHeight + (wmPtr->height
		- wmPtr->reqGridHeight)*wmPtr->heightInc;
    }
    wmPtr->widthInc = 1;
4218
4219
4220
4221
4222
4223
4224
4225

4226
4227
4228
4229
4230
4231
4232
4158
4159
4160
4161
4162
4163
4164

4165
4166
4167
4168
4169
4170
4171
4172







-
+







	if ((actualFormat == 32) && (numItems == 1)) {
	    vRoot = wmPtr->vRoot = *virtualRootPtr;
	} else if (dispPtr->flags & TK_DISPLAY_WM_TRACING) {
	    printf("%s format %d numItems %ld\n",
		    "ReparentEvent got bogus VROOT property:", actualFormat,
		    numItems);
	}
	XFree(virtualRootPtr);
	XFree((char *) virtualRootPtr);
    }
    Tk_DeleteErrorHandler(handler);

    if (dispPtr->flags & TK_DISPLAY_WM_TRACING) {
	printf("ReparentEvent: %s (%p) reparented to 0x%x, vRoot = 0x%x\n",
		wmPtr->winPtr->pathName, wmPtr->winPtr,
		(unsigned) reparentEventPtr->parent, (unsigned) vRoot);
4269
4270
4271
4272
4273
4274
4275
4276

4277
4278
4279
4280
4281
4282
4283
4209
4210
4211
4212
4213
4214
4215

4216
4217
4218
4219
4220
4221
4222
4223







-
+







    wmPtr->reparent = reparentEventPtr->parent;
    while (1) {
	if (XQueryTree(wrapperPtr->display, wmPtr->reparent, &dummy2,
		&ancestor, &children, &dummy) == 0) {
	    Tk_DeleteErrorHandler(handler);
	    goto noReparent;
	}
	XFree(children);
	XFree((char *) children);
	if ((ancestor == vRoot) ||
		(ancestor == RootWindow(wrapperPtr->display,
		wrapperPtr->screenNum))) {
	    break;
	}
	wmPtr->reparent = ancestor;
    }
4453
4454
4455
4456
4457
4458
4459
4460

4461
4462
4463

4464
4465
4466
4467
4468
4469
4470
4393
4394
4395
4396
4397
4398
4399

4400
4401
4402

4403
4404
4405
4406
4407
4408
4409
4410







-
+


-
+







 */

static const unsigned WrapperEventMask =
	(StructureNotifyMask | PropertyChangeMask);

static void
WrapperEventProc(
    void *clientData,	/* Information about toplevel window. */
    ClientData clientData,	/* Information about toplevel window. */
    XEvent *eventPtr)		/* Event that just happened. */
{
    WmInfo *wmPtr = (WmInfo *)clientData;
    WmInfo *wmPtr = clientData;
    XEvent mapEvent;
    TkDisplay *dispPtr = wmPtr->winPtr->dispPtr;

    wmPtr->flags |= WM_VROOT_OFFSET_STALE;
    if (eventPtr->type == DestroyNotify) {
	Tk_ErrorHandler handler;

4536
4537
4538
4539
4540
4541
4542

4543
4544
4545

4546
4547
4548
4549
4550
4551
4552
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485

4486
4487
4488
4489
4490
4491
4492
4493







+


-
+







 * Side effects:
 *	Arrange for the window to be resized to satisfy the request (this
 *	happens as a when-idle action).
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
TopLevelReqProc(
    TCL_UNUSED(void *),		/* Not used. */
    ClientData dummy,		/* Not used. */
    Tk_Window tkwin)		/* Information about window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (wmPtr == NULL) {
	return;
4603
4604
4605
4606
4607
4608
4609
4610

4611
4612
4613


4614
4615
4616
4617
4618
4619
4620
4544
4545
4546
4547
4548
4549
4550

4551
4552


4553
4554
4555
4556
4557
4558
4559
4560
4561







-
+

-
-
+
+







 *	change, unless the WM prevents that from happening.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateGeometryInfo(
    void *clientData)	/* Pointer to the window's record. */
    ClientData clientData)	/* Pointer to the window's record. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register TkWindow *winPtr = clientData;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y, width, height, min, max;
    unsigned long serial;

    wmPtr->flags &= ~WM_UPDATE_PENDING;

    /*
     * Compute the new size for the top-level window. See the user
4753
4754
4755
4756
4757
4758
4759
4760

4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774

4775
4776
4777
4778
4779
4780
4781
4694
4695
4696
4697
4698
4699
4700

4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714

4715
4716
4717
4718
4719
4720
4721
4722







-
+













-
+







     *	  of 4/24/91) where they don't interpret coordinates according to
     *	  ICCCM. Moving a window to its current location may cause it to shift
     *	  position on the screen.
     */

    if ((winPtr->flags & (TK_EMBEDDED|TK_BOTH_HALVES))
	    == (TK_EMBEDDED|TK_BOTH_HALVES)) {
	Tk_Window childPtr = Tk_GetOtherWindow((Tk_Window)winPtr);
	TkWindow *childPtr = TkpGetOtherWindow(winPtr);

	/*
	 * This window is embedded and the container is also in this process,
	 * so we don't need to do anything special about the geometry, except
	 * to make sure that the desired size is known by the container. Also,
	 * zero out any position information, since embedded windows are not
	 * allowed to move.
	 */

	wmPtr->x = wmPtr->y = 0;
	wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
	height += wmPtr->menuHeight;
	if (childPtr != NULL) {
	    Tk_GeometryRequest(childPtr, width, height);
	    Tk_GeometryRequest((Tk_Window) childPtr, width, height);
	}
	return;
    }
    serial = NextRequest(winPtr->display);
    height += wmPtr->menuHeight;
    if (wmPtr->flags & WM_MOVE_PENDING) {
	if ((x + wmPtr->xInParent == winPtr->changes.x) &&
4867
4868
4869
4870
4871
4872
4873
4874

4875
4876
4877
4878
4879
4880
4881
4808
4809
4810
4811
4812
4813
4814

4815
4816
4817
4818
4819
4820
4821
4822







-
+








static void
UpdateSizeHints(
    TkWindow *winPtr,
    int newWidth,
    int newHeight)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    XSizeHints *hintsPtr;
    int maxWidth, maxHeight;

    wmPtr->flags &= ~WM_UPDATE_SIZE_HINTS;

    hintsPtr = XAllocSizeHints();
    if (hintsPtr == NULL) {
4918
4919
4920
4921
4922
4923
4924
4925

4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944

4945
4946
4947
4948
4949
4950
4951
4859
4860
4861
4862
4863
4864
4865

4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884

4885
4886
4887
4888
4889
4890
4891
4892







-
+


















-
+







    hintsPtr->width_inc = wmPtr->widthInc;
    hintsPtr->height_inc = wmPtr->heightInc;
    hintsPtr->min_aspect.x = wmPtr->minAspect.x;
    hintsPtr->min_aspect.y = wmPtr->minAspect.y;
    hintsPtr->max_aspect.x = wmPtr->maxAspect.x;
    hintsPtr->max_aspect.y = wmPtr->maxAspect.y;
    hintsPtr->win_gravity = wmPtr->gravity;
    hintsPtr->flags = wmPtr->sizeHintsFlags | PMinSize | PResizeInc;
    hintsPtr->flags = wmPtr->sizeHintsFlags | PMinSize;

    /*
     * If the window isn't supposed to be resizable, then set the minimum and
     * maximum dimensions to be the same.
     */

    if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
	hintsPtr->max_width = hintsPtr->min_width = newWidth;
	hintsPtr->flags |= PMaxSize;
    }
    if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
	hintsPtr->max_height = hintsPtr->min_height =
		newHeight + wmPtr->menuHeight;
	hintsPtr->flags |= PMaxSize;
    }

    XSetWMNormalHints(winPtr->display, wmPtr->wrapperPtr->window, hintsPtr);

    XFree(hintsPtr);
    XFree((char *) hintsPtr);
}

/*
 *--------------------------------------------------------------
 *
 * UpdateTitle --
 *
4976
4977
4978
4979
4980
4981
4982
4983

4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996

4997
4998
4999
5000
5001
5002
5003
4917
4918
4919
4920
4921
4922
4923

4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936

4937
4938
4939
4940
4941
4942
4943
4944







-
+












-
+







    Tcl_DString ds;

    /*
     * Set window title:
     */

    string = (wmPtr->title != NULL) ? wmPtr->title : winPtr->nameUid;
    (void)Tcl_UtfToExternalDString(NULL, string, TCL_INDEX_NONE, &ds);
    Tcl_UtfToExternalDString(NULL, string, -1, &ds);
    XStoreName(winPtr->display, wmPtr->wrapperPtr->window,
	    Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);

    SetWindowProperty(wmPtr->wrapperPtr, "_NET_WM_NAME", XA_UTF8_STRING, 8,
	    string, strlen(string));

    /*
     * Set icon name:
     */

    if (wmPtr->iconName != NULL) {
	(void)Tcl_UtfToExternalDString(NULL, wmPtr->iconName, TCL_INDEX_NONE, &ds);
	Tcl_UtfToExternalDString(NULL, wmPtr->iconName, -1, &ds);
	XSetIconName(winPtr->display, wmPtr->wrapperPtr->window,
		Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);

	SetWindowProperty(wmPtr->wrapperPtr, "_NET_WM_ICON_NAME",
		XA_UTF8_STRING, 8, wmPtr->iconName, strlen(wmPtr->iconName));
    }
5287
5288
5289
5290
5291
5292
5293
5294

5295
5296
5297
5298
5299
5300
5301
5228
5229
5230
5231
5232
5233
5234

5235
5236
5237
5238
5239
5240
5241
5242







-
+







    Display *display,		/* Display event is coming from. */
    WmInfo *wmInfoPtr,		/* Window for which event is desired. */
    int type,			/* Type of event that is wanted. */
    XEvent *eventPtr)		/* Place to store event. */
{
    WaitRestrictInfo info;
    Tk_RestrictProc *prevProc;
    void *prevArg;
    ClientData prevArg;
    Tcl_Time timeout;

    /*
     * Set up an event filter to select just the events we want, and a timer
     * handler, then wait for events until we get the event we want or a
     * timeout happens.
     */
5341
5342
5343
5344
5345
5346
5347
5348

5349
5350
5351

5352
5353
5354
5355
5356
5357
5358
5282
5283
5284
5285
5286
5287
5288

5289
5290
5291

5292
5293
5294
5295
5296
5297
5298
5299







-
+


-
+







 *	WaitForEvent.
 *
 *----------------------------------------------------------------------
 */

static Tk_RestrictAction
WaitRestrictProc(
    void *clientData,	/* Pointer to WaitRestrictInfo structure. */
    ClientData clientData,	/* Pointer to WaitRestrictInfo structure. */
    XEvent *eventPtr)		/* Event that is about to be handled. */
{
    WaitRestrictInfo *infoPtr = (WaitRestrictInfo *)clientData;
    WaitRestrictInfo *infoPtr = clientData;

    if (eventPtr->type == ReparentNotify) {
	return TK_PROCESS_EVENT;
    }
    if (((eventPtr->xany.window != infoPtr->wmInfoPtr->wrapperPtr->window)
	    && (eventPtr->xany.window != infoPtr->wmInfoPtr->reparent))
	    || (eventPtr->xany.display != infoPtr->display)) {
5487
5488
5489
5490
5491
5492
5493
5494

5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507

5508
5509
5510
5511
5512

5513
5514
5515
5516

5517
5518
5519
5520
5521
5522
5523
5428
5429
5430
5431
5432
5433
5434

5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447

5448
5449
5450
5451
5452

5453
5454
5455
5456

5457
5458
5459
5460
5461
5462
5463
5464







-
+












-
+




-
+



-
+







SetNetWmType(
    TkWindow *winPtr,
    Tcl_Obj *typePtr)
{
    Atom *atoms = NULL;
    WmInfo *wmPtr;
    Tcl_Obj **objv;
    Tcl_Size objc, n;
    int objc, n;
    Tk_Window tkwin = (Tk_Window) winPtr;
    Tcl_Interp *interp = Tk_Interp(tkwin);

    if (TCL_OK != Tcl_ListObjGetElements(interp, typePtr, &objc, &objv)) {
	return TCL_ERROR;
    }

    if (!Tk_HasWrapper(tkwin)) {
	return TCL_OK; /* error?? */
    }

    if (objc > 0) {
	atoms = (Atom *)ckalloc(sizeof(Atom) * objc);
	atoms = ckalloc(sizeof(Atom) * objc);
    }

    for (n = 0; n < objc; ++n) {
	Tcl_DString ds, dsName;
	Tcl_Size len;
	int len;
	char *name = Tcl_GetStringFromObj(objv[n], &len);

	Tcl_UtfToUpper(name);
	(void)Tcl_UtfToExternalDString(NULL, name, len, &dsName);
	Tcl_UtfToExternalDString(NULL, name, len, &dsName);
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, "_NET_WM_WINDOW_TYPE_", 20);
	Tcl_DStringAppend(&ds, Tcl_DStringValue(&dsName),
		Tcl_DStringLength(&dsName));
	Tcl_DStringFree(&dsName);
	atoms[n] = Tk_InternAtom(tkwin, Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);
5573
5574
5575
5576
5577
5578
5579
5580

5581
5582
5583
5584
5585
5586
5587
5514
5515
5516
5517
5518
5519
5520

5521
5522
5523
5524
5525
5526
5527
5528







-
+







    if (GetWindowProperty(wrapperPtr, typeAtom, maxLength, XA_ATOM,
	    &actualType, &actualFormat, &count, &bytesAfter, &propertyValue)){
	atoms = (Atom *) propertyValue;
	for (n = 0; n < count; ++n) {
	    const char *name = Tk_GetAtomName(tkwin, atoms[n]);

	    if (strncmp("_NET_WM_WINDOW_TYPE_", name, 20) == 0) {
		(void)Tcl_ExternalToUtfDString(NULL, name+20, TCL_INDEX_NONE, &ds);
		Tcl_ExternalToUtfDString(NULL, name+20, -1, &ds);
		Tcl_UtfToLower(Tcl_DStringValue(&ds));
		Tcl_ListObjAppendElement(interp, typePtr,
			Tcl_NewStringObj(Tcl_DStringValue(&ds),
				Tcl_DStringLength(&ds)));
		Tcl_DStringFree(&ds);
	    }
	}
5613
5614
5615
5616
5617
5618
5619
5620

5621
5622
5623

5624
5625
5626
5627
5628
5629
5630
5554
5555
5556
5557
5558
5559
5560

5561
5562
5563

5564
5565
5566
5567
5568
5569
5570
5571







-
+


-
+







ParseGeometry(
    Tcl_Interp *interp,		/* Used for error reporting. */
    const char *string,		/* String containing new geometry. Has the
				 * standard form "=wxh+x+y". */
    TkWindow *winPtr)		/* Pointer to top-level window whose geometry
				 * is to be changed. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y, width, height, flags;
    char *end;
    const char *p = string;
    register const char *p = string;

    /*
     * The leading "=" is optional.
     */

    if (*p == '=') {
	p++;
5749
5750
5751
5752
5753
5754
5755
5756

5757
5758
5759
5760
5761
5762
5763
5690
5691
5692
5693
5694
5695
5696

5697
5698
5699
5700
5701
5702
5703
5704







-
+







void
Tk_GetRootCoords(
    Tk_Window tkwin,		/* Token for window. */
    int *xPtr,			/* Where to store x-displacement of (0,0). */
    int *yPtr)			/* Where to store y-displacement of (0,0). */
{
    int x, y;
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * Search back through this window's parents all the way to a top-level
     * window, combining the offsets of each window within its parent.
     */

    x = y = 0;
5773
5774
5775
5776
5777
5778
5779
5780

5781
5782
5783
5784
5785

5786
5787
5788
5789
5790
5791
5792
5714
5715
5716
5717
5718
5719
5720

5721
5722
5723
5724
5725

5726
5727
5728
5729
5730
5731
5732
5733







-
+




-
+







	     */

	    y -= winPtr->wmInfoPtr->menuHeight;
	    winPtr = winPtr->wmInfoPtr->winPtr;
	    continue;
	}
	if (winPtr->flags & TK_TOP_LEVEL) {
	    Tk_Window otherPtr;
	    TkWindow *otherPtr;

	    if (!(winPtr->flags & TK_EMBEDDED)) {
		break;
	    }
	    otherPtr = Tk_GetOtherWindow((Tk_Window)winPtr);
	    otherPtr = TkpGetOtherWindow(winPtr);
	    if (otherPtr == NULL) {
		/*
		 * The container window is not in the same application. Query
		 * the X server.
		 */

		Window root, dummyChild;
5803
5804
5805
5806
5807
5808
5809
5810

5811
5812
5813
5814
5815
5816
5817
5744
5745
5746
5747
5748
5749
5750

5751
5752
5753
5754
5755
5756
5757
5758







-
+







		break;
	    } else {
		/*
		 * The container window is in the same application. Let's
		 * query its coordinates.
		 */

		winPtr = (TkWindow *)otherPtr;
		winPtr = otherPtr;
		continue;
	    }
	}
	winPtr = winPtr->parentPtr;
	if (winPtr == NULL) {
	    break;
	}
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5777
5778
5779
5780
5781
5782
5783












5784
5785
5786
5787
5788
5789
5790







-
-
-
-
-
-
-
-
-
-
-
-







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int PointInWindow(
    int x,
    int y,
    WmInfo *wmPtr)
{
    XWindowChanges changes = wmPtr->winPtr->changes;
    return (x >= changes.x &&
            x < changes.x + changes.width &&
            y >= changes.y - wmPtr->menuHeight &&
            y < changes.y + changes.height);
}

Tk_Window
Tk_CoordsToWindow(
    int rootX, int rootY,	/* Coordinates of point in root window. If a
				 * virtual-root window manager is in use,
				 * these coordinates refer to the virtual
				 * root, not the real root. */
    Tk_Window tkwin)		/* Token for any window in application; used
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928

5929
5930

5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945

5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5847
5848
5849
5850
5851
5852
5853




5854


5855








5856
5857
5858
5859



5860











5861
5862
5863
5864
5865
5866
5867







-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-




-
-
-
+
-
-
-
-
-
-
-
-
-
-
-







	}
	if (child == None) {
	    Tk_DeleteErrorHandler(handler);
	    return NULL;
	}
	for (wmPtr = (WmInfo *) dispPtr->firstWmPtr; wmPtr != NULL;
		wmPtr = wmPtr->nextPtr) {
            if (wmPtr->winPtr->mainPtr == NULL) {
                continue;
            }
	    if (child == wmPtr->reparent) {
	    if (wmPtr->reparent == child) {
                if (PointInWindow(x, y, wmPtr)) {
                    goto gotToplevel;
		goto gotToplevel;
                } else {

                    /*
                     * Return NULL if the point is in the title bar or border.
                     */

                    return NULL;
                }
	    }
	    if (wmPtr->wrapperPtr != NULL) {
		if (child == wmPtr->wrapperPtr->window) {
		    goto gotToplevel;
		} else if (wmPtr->winPtr->flags & TK_EMBEDDED &&
                           Tk_GetOtherWindow((Tk_Window)wmPtr->winPtr) == NULL) {

		}
                    /*
                     * This toplevel is embedded in a window belonging to
                     * a different application.
                     */

                    int rx, ry;
                    Tk_GetRootCoords((Tk_Window) wmPtr->winPtr, &rx, &ry);
                    childX -= rx;
                    childY -= ry;
                    goto gotToplevel;
                }
	    } else if (child == wmPtr->winPtr->window) {
		goto gotToplevel;
	    }
	}
	x = childX;
	y = childY;
	parent = window;
5971
5972
5973
5974
5975
5976
5977



5978
5979
5980
5981
5982
5983
5984
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891







+
+
+







	 * or below
	 */

	Tk_DeleteErrorHandler(handler);
	handler = NULL;
    }
    winPtr = wmPtr->winPtr;
    if (winPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr) {
	return NULL;
    }

    /*
     * Step 3: at this point winPtr and wmPtr refer to the toplevel that
     * contains the given coordinates, and childX and childY give the
     * translated coordinates in the *parent* of the toplevel. Now decide
     * whether the coordinates are in the menubar or the actual toplevel, and
     * translate the coordinates into the coordinate system of that window.
6027
6028
6029
6030
6031
6032
6033

6034
6035
6036
6037




6038
6039
6040
6041
6042
6043
6044


6045
6046

6047
6048
6049
6050
6051
6052
6053
6054

6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
5934
5935
5936
5937
5938
5939
5940
5941




5942
5943
5944
5945
5946
5947
5948
5949
5950
5951

5952
5953
5954

5955
5956
5957
5958
5959
5960



5961



5962
5963
5964
5965
5966
5967
5968







+
-
-
-
-
+
+
+
+






-
+
+

-
+





-
-
-
+
-
-
-







		    && (tmpy < (childPtr->changes.height + bd))) {
		nextPtr = childPtr;
	    }
	}
	if (nextPtr == NULL) {
	    break;
	}
	winPtr = nextPtr;
	x -= nextPtr->changes.x;
	y -= nextPtr->changes.y;
	if ((nextPtr->flags & TK_CONTAINER)
		&& (nextPtr->flags & TK_BOTH_HALVES)) {
	x -= winPtr->changes.x;
	y -= winPtr->changes.y;
	if ((winPtr->flags & TK_CONTAINER)
		&& (winPtr->flags & TK_BOTH_HALVES)) {
	    /*
	     * The window containing the point is a container, and the
	     * embedded application is in this same process. Switch over to
	     * the toplevel for the embedded application and start processing
	     * that toplevel from scratch.
	     */
	    winPtr = (TkWindow *)Tk_GetOtherWindow((Tk_Window)nextPtr);

	    winPtr = TkpGetOtherWindow(winPtr);
	    if (winPtr == NULL) {
		return (Tk_Window) nextPtr;
		return NULL;
	    }
	    wmPtr = winPtr->wmInfoPtr;
	    childX = x;
	    childY = y;
	    goto gotToplevel;
	} else {
            winPtr = nextPtr;
        }
	}
    }
    if (winPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr) {
        return NULL;
    }
    return (Tk_Window) winPtr;
}

/*
 *----------------------------------------------------------------------
 *
6216
6217
6218
6219
6220
6221
6222
6223

6224
6225
6226
6227
6228
6229
6230
6120
6121
6122
6123
6124
6125
6126

6127
6128
6129
6130
6131
6132
6133
6134







-
+








void
Tk_MoveToplevelWindow(
    Tk_Window tkwin,		/* Window to move. */
    int x, int y)		/* New location for window (within parent). */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!(winPtr->flags & TK_TOP_LEVEL)) {
	Tcl_Panic("Tk_MoveToplevelWindow called with non-toplevel window");
    }
    wmPtr->x = x;
    wmPtr->y = y;
    wmPtr->flags |= WM_MOVE_PENDING;
6264
6265
6266
6267
6268
6269
6270
6271

6272
6273

6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290

6291
6292
6293
6294
6295
6296
6297
6168
6169
6170
6171
6172
6173
6174

6175
6176

6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193

6194
6195
6196
6197
6198
6199
6200
6201







-
+

-
+
















-
+







 *	The WM_PROTOCOLS property gets changed for wmPtr's window.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateWmProtocols(
    WmInfo *wmPtr)	/* Information about top-level window. */
    register WmInfo *wmPtr)	/* Information about top-level window. */
{
    ProtocolHandler *protPtr;
    register ProtocolHandler *protPtr;
    Atom deleteWindowAtom, pingAtom;
    int count;
    Atom *arrayPtr, *atomPtr;

    /*
     * There are only two tricky parts here. First, there could be any number
     * of atoms for the window, so count them and malloc an array to hold all
     * of their atoms. Second, we *always* want to respond to the
     * WM_DELETE_WINDOW and _NET_WM_PING protocols, even if no-one's
     * officially asked.
     */

    for (protPtr = wmPtr->protPtr, count = 2; protPtr != NULL;
	    protPtr = protPtr->nextPtr, count++) {
	/* Empty loop body; we're just counting the handlers. */
    }
    arrayPtr = (Atom *)ckalloc(count * sizeof(Atom));
    arrayPtr = ckalloc(count * sizeof(Atom));
    deleteWindowAtom = Tk_InternAtom((Tk_Window) wmPtr->winPtr,
	    "WM_DELETE_WINDOW");
    pingAtom = Tk_InternAtom((Tk_Window) wmPtr->winPtr, "_NET_WM_PING");
    arrayPtr[0] = deleteWindowAtom;
    arrayPtr[1] = pingAtom;
    for (protPtr = wmPtr->protPtr, atomPtr = &arrayPtr[1];
	    protPtr != NULL; protPtr = protPtr->nextPtr) {
6325
6326
6327
6328
6329
6330
6331
6332

6333
6334
6335
6336
6337
6338
6339
6229
6230
6231
6232
6233
6234
6235

6236
6237
6238
6239
6240
6241
6242
6243







-
+








void
TkWmProtocolEventProc(
    TkWindow *winPtr,		/* Window to which the event was sent. */
    XEvent *eventPtr)		/* X event. */
{
    WmInfo *wmPtr;
    ProtocolHandler *protPtr;
    register ProtocolHandler *protPtr;
    Atom protocol;
    int result;
    const char *protocolName;
    Tcl_Interp *interp;

    protocol = (Atom) eventPtr->xclient.data.l[0];

6368
6369
6370
6371
6372
6373
6374
6375

6376
6377
6378
6379
6380
6381
6382
6272
6273
6274
6275
6276
6277
6278

6279
6280
6281
6282
6283
6284
6285
6286







-
+







    protocolName = Tk_GetAtomName((Tk_Window) winPtr, protocol);
    for (protPtr = wmPtr->protPtr; protPtr != NULL;
	    protPtr = protPtr->nextPtr) {
	if (protocol == protPtr->protocol) {
	    Tcl_Preserve(protPtr);
	    interp = protPtr->interp;
	    Tcl_Preserve(interp);
	    result = Tcl_EvalEx(interp, protPtr->command, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(interp, protPtr->command, -1, TCL_EVAL_GLOBAL);
	    if (result != TCL_OK) {
		Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
			"\n    (command for \"%s\" window manager protocol)",
			protocolName));
		Tcl_BackgroundException(interp, result);
	    }
	    Tcl_Release(interp);
6474
6475
6476
6477
6478
6479
6480
6481

6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497

6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513

6514
6515

6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527

6528
6529
6530
6531
6532
6533
6534
6378
6379
6380
6381
6382
6383
6384

6385



6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397

6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413

6414
6415

6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427

6428
6429
6430
6431
6432
6433
6434
6435







-
+
-
-
-












-
+















-
+

-
+











-
+







    /*
     * Map X Window ids to a TkWindow of the wrapped toplevel.
     */

    Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
    TkWmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);

    window_ptr = windows = (TkWindow **)ckalloc((table.numEntries+1) * sizeof(TkWindow *));
    window_ptr = windows = ckalloc((table.numEntries+1) * sizeof(TkWindow *));
    if (windows == NULL) {
	return NULL;
    }

    /*
     * Special cases: If zero or one toplevels were mapped there is no need to
     * call XQueryTree.
     */

    switch (table.numEntries) {
    case 0:
	windows[0] = NULL;
	goto done;
    case 1:
	hPtr = Tcl_FirstHashEntry(&table, &search);
	windows[0] = (TkWindow *)Tcl_GetHashValue(hPtr);
	windows[0] = Tcl_GetHashValue(hPtr);
	windows[1] = NULL;
	goto done;
    }

    vRoot = parentPtr->wmInfoPtr->vRoot;
    if (vRoot == None) {
	vRoot = RootWindowOfScreen(Tk_Screen((Tk_Window) parentPtr));
    }

    if (XQueryTree(parentPtr->display, vRoot, &dummy1, &dummy2,
	    &children, &numChildren) == 0) {
	ckfree(windows);
	windows = NULL;
    } else {
	for (i = 0; i < numChildren; i++) {
	    hPtr = Tcl_FindHashEntry(&table, children[i]);
	    hPtr = Tcl_FindHashEntry(&table, (char *) children[i]);
	    if (hPtr != NULL) {
		childWinPtr = (TkWindow *)Tcl_GetHashValue(hPtr);
		childWinPtr = Tcl_GetHashValue(hPtr);
		*window_ptr++ = childWinPtr;
	    }
	}

	/*
	 * ASSERT: window_ptr - windows == table.numEntries
	 * (#matched toplevel windows == #children) [Bug 1789819]
	 */

	*window_ptr = NULL;
	if (numChildren) {
	    XFree(children);
	    XFree((char *) children);
	}
    }

  done:
    Tcl_DeleteHashTable(&table);
    return windows;
}
6681
6682
6683
6684
6685
6686
6687
6688

6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701

6702
6703
6704
6705
6706
6707
6708
6582
6583
6584
6585
6586
6587
6588

6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601

6602
6603
6604
6605
6606
6607
6608
6609







-
+












-
+







    }

    /*
     * Make a new bigger array and use it to reset the property. Automatically
     * add the toplevel itself as the last element of the list.
     */

    newPtr = (Window *)ckalloc((count+2) * sizeof(Window));
    newPtr = ckalloc((count+2) * sizeof(Window));
    for (i = 0; i < count; i++) {
	newPtr[i] = oldPtr[i];
    }
    if (count == 0) {
	count++;
    }
    newPtr[count-1] = winPtr->window;
    newPtr[count] = topPtr->window;
    XSetWMColormapWindows(topPtr->display, wrapperPtr->window, newPtr,
	    count+1);
    ckfree(newPtr);
    if (oldPtr != NULL) {
	XFree(oldPtr);
	XFree((char *) oldPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmRemoveFromColormapWindows --
6790
6791
6792
6793
6794
6795
6796
6797

6798
6799
6800
6801
6802
6803
6804
6691
6692
6693
6694
6695
6696
6697

6698
6699
6700
6701
6702
6703
6704
6705







-
+







		oldPtr[j] = oldPtr[j+1];
	    }
	    XSetWMColormapWindows(topPtr->display, wrapperPtr->window,
		    oldPtr, count-1);
	    break;
	}
    }
    XFree(oldPtr);
    XFree((char *) oldPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetPointerCoords --
 *
6916
6917
6918
6919
6920
6921
6922
6923

6924
6925
6926
6927
6928
6929
6930
6817
6818
6819
6820
6821
6822
6823

6824
6825
6826
6827
6828
6829
6830
6831







-
+







 *
 *----------------------------------------------------------------------
 */

static void
TkSetTransientFor(Tk_Window tkwin, Tk_Window parent)
{
    if (parent == NULL) {
    if (parent == None) {
	parent = Tk_Parent(tkwin);
	while (!Tk_IsTopLevel(parent))
	    parent = Tk_Parent(parent);
    }
    /*
     * Prevent crash due to incomplete initialization, or other problems.
     * [Bugs 3554026, 3561016]
6978
6979
6980
6981
6982
6983
6984
6985

6986
6987
6988
6989
6990
6991

6992
6993

6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
6879
6880
6881
6882
6883
6884
6885

6886
6887
6888
6889
6890
6891

6892
6893

6894
6895
6896

6897

6898
6899
6900
6901
6902
6903
6904







-
+





-
+

-
+


-

-







    if (wmPtr->wrapperPtr == NULL) {
	CreateWrapper(wmPtr);
    }
    wrapperPtr = wmPtr->wrapperPtr;
    if (typeFlag == TK_MAKE_MENU_TEAROFF) {
	atts.override_redirect = False;
	atts.save_under = False;
	typeObj = Tcl_NewStringObj("menu", TCL_INDEX_NONE);
	typeObj = Tcl_NewStringObj("menu", -1);
	TkSetTransientFor(tkwin, NULL);
    } else {
	atts.override_redirect = True;
	atts.save_under = True;
	if (typeFlag == TK_MAKE_MENU_DROPDOWN) {
	    typeObj = Tcl_NewStringObj("dropdown_menu", TCL_INDEX_NONE);
	    typeObj = Tcl_NewStringObj("dropdown_menu", -1);
	} else {
	    typeObj = Tcl_NewStringObj("popup_menu", TCL_INDEX_NONE);
	    typeObj = Tcl_NewStringObj("popup_menu", -1);
	}
    }
    Tcl_IncrRefCount(typeObj);
    SetNetWmType((TkWindow *)tkwin, typeObj);
    Tcl_DecrRefCount(typeObj);

    /*
     * The override-redirect and save-under bits must be set on the wrapper
     * window in order to have the desired effect. However, also set the
     * override-redirect bit on the window itself, so that the "wm
     * overrideredirect" command will see it.
     */
7036
7037
7038
7039
7040
7041
7042
7043

7044
7045
7046
7047
7048
7049
7050
7051
7052

7053
7054
7055
7056
7057
7058
7059
6935
6936
6937
6938
6939
6940
6941

6942
6943
6944
6945
6946
6947
6948
6949
6950

6951
6952
6953
6954
6955
6956
6957
6958







-
+








-
+







CreateWrapper(
    WmInfo *wmPtr)		/* Window manager information for the
				 * window. */
{
    TkWindow *winPtr, *wrapperPtr;
    Window parent;
    Tcl_HashEntry *hPtr;
    int isNew;
    int new;

    winPtr = wmPtr->winPtr;
    if (winPtr->window == None) {
	Tk_MakeWindowExist((Tk_Window) winPtr);
    }

    /*
     * The code below is copied from CreateTopLevelWindow, Tk_MakeWindowExist,
     * and Tk_MakeWindow. The idea is to create an "official" Tk window (so
     * and TkpMakeWindow. The idea is to create an "official" Tk window (so
     * that we can get events on it), but to hide the window outside the
     * official Tk hierarchy so that it isn't visible to the application. See
     * the comments for the other functions if you have questions about this
     * code.
     */

    wmPtr->wrapperPtr = wrapperPtr = TkAllocWindow(winPtr->dispPtr,
7080
7081
7082
7083
7084
7085
7086
7087

7088
7089
7090
7091
7092
7093
7094
6979
6980
6981
6982
6983
6984
6985

6986
6987
6988
6989
6990
6991
6992
6993







-
+







	    parent, wrapperPtr->changes.x, wrapperPtr->changes.y,
	    (unsigned) wrapperPtr->changes.width,
	    (unsigned) wrapperPtr->changes.height,
	    (unsigned) wrapperPtr->changes.border_width, wrapperPtr->depth,
	    InputOutput, wrapperPtr->visual,
	    wrapperPtr->dirtyAtts|CWOverrideRedirect, &wrapperPtr->atts);
    hPtr = Tcl_CreateHashEntry(&wrapperPtr->dispPtr->winTable,
	    (char *) wrapperPtr->window, &isNew);
	    (char *) wrapperPtr->window, &new);
    Tcl_SetHashValue(hPtr, wrapperPtr);
    wrapperPtr->mainPtr = winPtr->mainPtr;
    wrapperPtr->mainPtr->refCount++;
    wrapperPtr->dirtyAtts = 0;
    wrapperPtr->dirtyChanges = 0;
    wrapperPtr->wmInfoPtr = wmPtr;

7258
7259
7260
7261
7262
7263
7264
7265

7266
7267
7268
7269
7270
7271
7272
7157
7158
7159
7160
7161
7162
7163

7164
7165
7166
7167
7168
7169
7170
7171







-
+







 *	the window is no longer considered to be a menubar.
 *
 *----------------------------------------------------------------------
 */

static void
MenubarDestroyProc(
    void *clientData,	/* TkWindow pointer for menubar. */
    ClientData clientData,	/* TkWindow pointer for menubar. */
    XEvent *eventPtr)		/* Describes what just happened. */
{
    WmInfo *wmPtr;

    if (eventPtr->type != DestroyNotify) {
	return;
    }
7295
7296
7297
7298
7299
7300
7301
7302

7303
7304
7305
7306

7307
7308
7309
7310
7311
7312
7313
7194
7195
7196
7197
7198
7199
7200

7201
7202
7203
7204

7205
7206
7207
7208
7209
7210
7211
7212







-
+



-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
MenubarReqProc(
    void *clientData,	/* Pointer to the window manager information
    ClientData clientData,	/* Pointer to the window manager information
				 * for tkwin's toplevel. */
    Tk_Window tkwin)		/* Handle for menubar window. */
{
    WmInfo *wmPtr = (WmInfo *)clientData;
    WmInfo *wmPtr = clientData;

    wmPtr->menuHeight = Tk_ReqHeight(tkwin);
    if (wmPtr->menuHeight <= 0) {
	wmPtr->menuHeight = 1;
    }
    wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
7334
7335
7336
7337
7338
7339
7340
7341

7342
7343
7344
7345
7346
7347
7348
7233
7234
7235
7236
7237
7238
7239

7240
7241
7242
7243
7244
7245
7246
7247







-
+







 *----------------------------------------------------------------------
 */

TkWindow *
TkpGetWrapperWindow(
    TkWindow *winPtr)		/* A toplevel window pointer. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if ((winPtr == NULL) || (wmPtr == NULL)) {
	return NULL;
    }

    return wmPtr->wrapperPtr;
}
7364
7365
7366
7367
7368
7369
7370
7371

7372
7373
7374

7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390


7391
7392
7393

7394
7395
7396
7397
7398
7399
7400
7263
7264
7265
7266
7267
7268
7269

7270
7271


7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286


7287
7288
7289
7290

7291
7292
7293
7294
7295
7296
7297
7298







-
+

-
-
+














-
-
+
+


-
+







 *----------------------------------------------------------------------
 */

static void
UpdateCommand(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tcl_DString cmds, ds;
    Tcl_Size i;
    int *offsets;
    int i, *offsets;
    char **cmdArgv;

    /*
     * Translate the argv strings into the external encoding. To avoid
     * allocating lots of memory, the strings are appended to a buffer with
     * nulls between each string.
     *
     * This code is tricky because we need to pass and array of pointers to
     * XSetCommand. However, we can't compute the pointers as we go because
     * the DString buffer space could get reallocated. So, store offsets for
     * each element as we go, then compute pointers from the offsets once the
     * entire DString is done.
     */

    cmdArgv = (char **)ckalloc(sizeof(char *) * wmPtr->cmdArgc);
    offsets = (int *)ckalloc(sizeof(int) * wmPtr->cmdArgc);
    cmdArgv = ckalloc(sizeof(char *) * wmPtr->cmdArgc);
    offsets = ckalloc(sizeof(int) * wmPtr->cmdArgc);
    Tcl_DStringInit(&cmds);
    for (i = 0; i < wmPtr->cmdArgc; i++) {
	(void)Tcl_UtfToExternalDString(NULL, wmPtr->cmdArgv[i], TCL_INDEX_NONE, &ds);
	Tcl_UtfToExternalDString(NULL, wmPtr->cmdArgv[i], -1, &ds);
	offsets[i] = Tcl_DStringLength(&cmds);
	Tcl_DStringAppend(&cmds, Tcl_DStringValue(&ds),
		Tcl_DStringLength(&ds)+1);
	Tcl_DStringFree(&ds);
    }
    cmdArgv[0] = Tcl_DStringValue(&cmds);
    for (i = 1; i < wmPtr->cmdArgc; i++) {

Changes to unix/tkUnixXId.c.

1
2
3
4
5


6
7
8
9
10
11
12
1
2
3


4
5
6
7
8
9
10
11
12



-
-
+
+







/*
 * tkUnixXId.c --
 *
 * Copyright © 1993 The Regents of the University of California.
 * Copyright © 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1993 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.
 */

#include "tkUnixInt.h"

Changes to win/Makefile.in.

1
2
3
4
5





6
7
8
9
10
11
12
13
14
15
16






17
18
19
20
21





22
23
24
25
26
27
28
29
30
31
32
33
34
35
36






37
38
39
40
41




42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65

66
67
68
69

70
71
72



73



74
75

76
77
78
79
80
81
82





1
2
3
4
5
6
7
8
9
10
11





12
13
14
15
16
17
18




19
20
21
22
23
24
25
26
27
28
29
30

31
32





33
34
35
36
37
38
39




40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66

67
68
69
70

71
72


73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
-
-
-
-
-
+
+
+
+
+






-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+
+







-


-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+



















-
+



-
+



-
+

-
-
+
+
+

+
+
+

-
+







#
# This file is a Makefile for Tk.  If it has the name "Makefile.in" then it
# is a template for a Makefile; to generate the actual Makefile, run
# "./configure", which is a configuration script generated by the "autoconf"
# program (constructs like "@foo@" will get replaced in the actual Makefile.
# This file is a Makefile for Tk.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.

TCLVERSION		= @TCL_VERSION@
TCLPATCHL		= @TCL_PATCH_LEVEL@
VERSION			= @TK_VERSION@
PATCH_LEVEL		= @TK_PATCH_LEVEL@

#--------------------------------------------------------------------------
# Things you can change to personalize the Makefile for your own site (you can
# make these changes in either Makefile.in or Makefile, but changes to
# Makefile will get lost if you re-run the configuration script).
#--------------------------------------------------------------------------
#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-specific
# files (exec_prefix) and machine-independent files such as scripts (prefix).
# The values specified here may be overridden at configure-time with the
# --exec-prefix and --prefix options to the "configure" script.
# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix			= @prefix@
exec_prefix		= @exec_prefix@
bindir			= @bindir@
libdir			= @libdir@
includedir		= @includedir@
datarootdir		= @datarootdir@
runstatedir		= @runstatedir@
mandir			= @mandir@

# The following definition can be set to non-null for special systems like AFS
# with replication. It allows the pathnames used for installation to be
# different than those used for actually reference files at run-time.
# INSTALL_ROOT is prepended to $prefix and $exec_prefix when installing files.
INSTALL_ROOT	=
# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT		=

# Directory from which applications will reference the library of Tk scripts
# (note: you can set the TK_LIBRARY environment variable at run-time to
# override this value):
TK_LIBRARY	= $(prefix)/lib/tk$(VERSION)
# Directory from which applications will reference the library of Tk
# scripts (note: you can set the TK_LIBRARY environment variable at
# run-time to override this value):
TK_LIBRARY		= $(prefix)/lib/tk$(VERSION)

# Path to use at runtime to refer to LIB_INSTALL_DIR:
LIB_RUNTIME_DIR		= $(libdir)

# Directory in which to install the program wish:
BIN_INSTALL_DIR		= $(INSTALL_ROOT)$(bindir)

# Directory in which to install the .a or .so binary for the Tk library:
LIB_INSTALL_DIR		= $(INSTALL_ROOT)$(libdir)

# Path name to use when installing library scripts:
SCRIPT_INSTALL_DIR	= $(INSTALL_ROOT)$(TK_LIBRARY)

# Directory in which to install the include file tk.h:
INCLUDE_INSTALL_DIR	= $(INSTALL_ROOT)$(includedir)

# Directory in which to (optionally) install the private tk headers:
PRIVATE_INCLUDE_INSTALL_DIR = $(INSTALL_ROOT)$(includedir)

# Top-level directory in which to install manual entries:
# Top-level directory for manual entries:
MAN_INSTALL_DIR		= $(INSTALL_ROOT)$(mandir)

# Directory in which to install manual entry for wish:
MAN1_INSTALL_DIR = $(MAN_INSTALL_DIR)/man1
MAN1_INSTALL_DIR	= $(MAN_INSTALL_DIR)/man1

# Directory in which to install manual entries for Tk's C library
# procedures:
MAN3_INSTALL_DIR = $(MAN_INSTALL_DIR)/man3
MAN3_INSTALL_DIR	= $(MAN_INSTALL_DIR)/man3

# Directory in which to install manual entries for the built-in Tk commands:
MANN_INSTALL_DIR = $(MAN_INSTALL_DIR)/mann
# Directory in which to install manual entries for the built-in
# Tk commands:
MANN_INSTALL_DIR	= $(MAN_INSTALL_DIR)/mann

# Libraries built with optimization switches have this additional extension
TK_DBGX			= @TK_DBGX@

# Directory in which to install the pkgIndex.tcl file for loadable Tk
PKG_INSTALL_DIR		= $(LIB_INSTALL_DIR)/tk$(VERSION)
PKG_INSTALL_DIR		= $(LIB_INSTALL_DIR)/tk$(VERSION)$(TK_DBGX)

# Package index file for loadable Tk
PKG_INDEX		= $(PKG_INSTALL_DIR)/pkgIndex.tcl

# The directory containing the Tcl source and header files.
TCL_SRC_DIR		= @TCL_SRC_DIR@

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115










116
117
118
119
120
121
122
123
124









125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151



152
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188

189
190
191
192

193
194
195
196
197
198


199
200
201
202
203
204
205


206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
97
98
99
100
101
102
103











104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120









121
122
123
124
125
126
127
128
129
130
131
132
133







134
135
136
137


138

139
140
141
142
143
144



145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209

210
211
212
213
214
215
216
217
218

219







































220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251







-
-
-
-
-
-
-
-
-
-
-







+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-
-
-
-
-
-
-




-
-

-
+





-
-
-
+
+
+







-
+

















-
+










-
+




+






+
+






-
+
+




-
+








-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+



















+








# The directory containing the platform specific Tcl sources and headers
# appropriate for this version of Tk:
TCL_PLATFORM_DIR	= @TCL_SRC_DIR@/win

TCL_TOOL_DIR		= @TCL_SRC_DIR@/tools

SRC_DIR			= @srcdir@
ROOT_DIR		= @srcdir@/..
TOP_DIR			= $(shell cd @srcdir@/..; pwd -W 2>/dev/null || pwd -P)
WIN_DIR			= $(TOP_DIR)/win
UNIX_DIR		= $(TOP_DIR)/unix
GENERIC_DIR		= $(TOP_DIR)/generic
TTK_DIR			= $(GENERIC_DIR)/ttk
BITMAP_DIR		= $(TOP_DIR)/bitmaps
XLIB_DIR		= $(TOP_DIR)/xlib
RC_DIR			= $(WIN_DIR)/rc

# Converts a POSIX path to a Windows native path.
CYGPATH			= @CYGPATH@

# The name of the Tcl library.
TCL_LIB_FILE	  = "$(shell $(CYGPATH) '@TCL_BIN_DIR@/@TCL_LIB_FILE@')"
TCL_STUB_LIB_FILE = "$(shell $(CYGPATH) '@TCL_BIN_DIR@/@TCL_STUB_LIB_FILE@')"

SRC_DIR			= @srcdir@
ROOT_DIR		= $(SRC_DIR)/..
WIN_DIR			= $(SRC_DIR)
UNIX_DIR		= $(SRC_DIR)/../unix
GENERIC_DIR		= $(SRC_DIR)/../generic
TTK_DIR			= $(GENERIC_DIR)/ttk
BITMAP_DIR		= $(ROOT_DIR)/bitmaps
XLIB_DIR		= $(ROOT_DIR)/xlib
RC_DIR			= $(WIN_DIR)/rc

ROOT_DIR_NATIVE		= $(shell $(CYGPATH) '$(ROOT_DIR)')
WIN_DIR_NATIVE		= $(shell $(CYGPATH) '$(WIN_DIR)')
GENERIC_DIR_NATIVE	= $(shell $(CYGPATH) '$(GENERIC_DIR)')
BITMAP_DIR_NATIVE	= $(shell $(CYGPATH) '$(ROOT_DIR)/bitmaps')
XLIB_DIR_NATIVE	= $(shell $(CYGPATH) '$(ROOT_DIR)/xlib')
RC_DIR_NATIVE	= $(shell $(CYGPATH) '$(ROOT_DIR)/rc')
TCL_GENERIC_NATIVE		= $(shell $(CYGPATH) '$(TCL_GENERIC_DIR)')
TCL_PLATFORM_NATIVE		= $(shell $(CYGPATH) '$(TCL_PLATFORM_DIR)')
TCL_SRC_DIR_NATIVE		= $(shell $(CYGPATH) '$(TCL_SRC_DIR)')
ROOT_DIR_NATIVE	   	= $(shell $(CYGPATH) '$(ROOT_DIR)' | sed 's!\\!/!g')
WIN_DIR_NATIVE	   	= $(shell $(CYGPATH) '$(WIN_DIR)' | sed 's!\\!/!g')
GENERIC_DIR_NATIVE 	= $(shell $(CYGPATH) '$(GENERIC_DIR)' | sed 's!\\!/!g')
BITMAP_DIR_NATIVE	= $(ROOT_DIR_NATIVE)/bitmaps
XLIB_DIR_NATIVE		= $(ROOT_DIR_NATIVE)/xlib
RC_DIR_NATIVE      	= $(WIN_DIR_NATIVE)/rc
TCL_GENERIC_NATIVE	= $(shell $(CYGPATH) '$(TCL_GENERIC_DIR)' | sed 's!\\!/!g')
TCL_PLATFORM_NATIVE	= $(shell $(CYGPATH) '$(TCL_PLATFORM_DIR)' | sed 's!\\!/!g')
TCL_SRC_DIR_NATIVE      = $(shell $(CYGPATH) '$(TCL_SRC_DIR)' | sed 's!\\!/!g')

DLLSUFFIX		= @DLLSUFFIX@
LIBSUFFIX		= @LIBSUFFIX@
EXESUFFIX		= @EXESUFFIX@
TCLVER			= @TCL_MAJOR_VERSION@@TCL_MINOR_VERSION@
VER			= @TK_MAJOR_VERSION@@TK_MINOR_VERSION@
DOTVER			= @TK_MAJOR_VERSION@.@TK_MINOR_VERSION@

TK_ZIP_FILE		= @TK_ZIP_FILE@
TK_VFS_PATH		= libtk.vfs/tk_library
TK_VFS_ROOT		= libtk.vfs

TK_STUB_LIB_FILE	= @TK_STUB_LIB_FILE@
TK_LIB_FILE		= @TK_LIB_FILE@
TK_DLL_FILE		= @TK_DLL_FILE@
TK_DLL_FILE_TCL8	= @TK_DLL_FILE_TCL8@
TK_DLL_FILE_TCL9	= @TK_DLL_FILE_TCL9@
TEST_DLL_FILE		= tktest$(VER)${DLLSUFFIX}
TEST_LIB_FILE		= @LIBPREFIX@tktest$(VER)${DLLSUFFIX}${LIBSUFFIX}
TEST_LIB_FILE		= @LIBPREFIX@tktest$(VER)${LIBSUFFIX}

SHARED_LIBRARIES 	= $(TK_DLL_FILE) $(TK_STUB_LIB_FILE)
STATIC_LIBRARIES	= $(TK_LIB_FILE)

WISH			= wish$(VER)${EXESUFFIX}
TKTEST			= tktest${EXESUFFIX}
CAT32			= cat32${EXESUFFIX}
MAN2TCL			= man2tcl${EXESUFFIX}
TKTEST			= tktest${EXEEXT}
CAT32			= cat32$(EXEEXT)
MAN2TCL			= man2tcl$(EXEEXT)

@SET_MAKE@

# Setting the VPATH variable to a list of paths will cause the
# makefile to look into these paths when resolving .c to .obj
# dependencies.

VPATH = $(GENERIC_DIR):$(TTK_DIR):$(WIN_DIR):$(XLIB_DIR):$(RC_DIR)
VPATH = $(GENERIC_DIR):$(TTK_DIR):$(WIN_DIR):$(UNIX_DIR):$(XLIB_DIR):$(RC_DIR)

# warning flags
CFLAGS_WARNING	= @CFLAGS_WARNING@

# The default switches for optimization or debugging
CFLAGS_DEBUG    = @CFLAGS_DEBUG@
CFLAGS_OPTIMIZE	= @CFLAGS_OPTIMIZE@

# The default switches for optimization or debugging
LDFLAGS_DEBUG    = @LDFLAGS_DEBUG@
LDFLAGS_OPTIMIZE = @LDFLAGS_OPTIMIZE@

# To change the compiler switches, for example to change from optimization to
# debugging symbols, change the following line:
#CFLAGS		= $(CFLAGS_DEBUG)
#CFLAGS		= $(CFLAGS_OPTIMIZE)
#CFLAGS		= $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE)
CFLAGS		= @CFLAGS@ @CFLAGS_DEFAULT@ -D_ATL_XP_TARGETING=1 -D__USE_MINGW_ANSI_STDIO=0
CFLAGS		= @CFLAGS@ @CFLAGS_DEFAULT@ -DUNICODE -D_UNICODE -D_ATL_XP_TARGETING

# Special compiler flags to use when building man2tcl on Windows.
MAN2TCLFLAGS	= @MAN2TCLFLAGS@

AR		= @AR@
RANLIB		= @RANLIB@
CC		= @CC@
RC		= @RC@
RES		= @RES@
TK_RES		= @TK_RES@
AC_FLAGS	= @EXTRA_CFLAGS@ @DEFS@
AC_FLAGS	= @EXTRA_CFLAGS@ @DEFS@ @TCL_DEFS@
CPPFLAGS	= @CPPFLAGS@
LDFLAGS		= @LDFLAGS@ @LDFLAGS_DEFAULT@
LDFLAGS_CONSOLE	= @LDFLAGS_CONSOLE@
LDFLAGS_WINDOW	= @LDFLAGS_WINDOW@
EXEEXT		= @EXEEXT@
OBJEXT		= @OBJEXT@
STLIB_LD	= @STLIB_LD@
SHLIB_LD	= @SHLIB_LD@
SHLIB_LD_LIBS	= @SHLIB_LD_LIBS@
SHLIB_CFLAGS	= @SHLIB_CFLAGS@
SHLIB_SUFFIX	= @SHLIB_SUFFIX@
VER		= @TK_MAJOR_VERSION@@TK_MINOR_VERSION@
DOTVER		= @TK_MAJOR_VERSION@.@TK_MINOR_VERSION@
LIBS		= $(TCL_STUB_LIB_FILE) @LIBS@ @LIBS_GUI@
RMDIR		= rm -rf
MKDIR		= mkdir -p
SHELL		= @SHELL@
RM		= rm -f
COPY		= cp
LN		= ln

BUILD_TCLSH	= @BUILD_TCLSH@

# Tk does not used deprecated Tcl constructs so it should
# compile fine with -DTCL_NO_DEPRECATED. To remove its own
# set of deprecated code uncomment the second line.
NO_DEPRECATED_FLAGS	=
NO_DEPRECATED_FLAGS	= -DTCL_NO_DEPRECATED
#NO_DEPRECATED_FLAGS	= -DTCL_NO_DEPRECATED -DTK_NO_DEPRECATED

# TCL_EXE is the name of a tclsh executable that is available *BEFORE*
# running make for the first time. Certain build targets (make genstubs)
# need it to be available on the PATH. This executable should *NOT* be
# required just to do a normal build although it can be required to run
# make dist.
TCL_EXE			= @TCLSH_PROG@
WINE    		= @WINE@

###
# Tip 430 - ZipFS Modifications
###

TK_ZIP_FILE		= @TK_ZIP_FILE@
TK_VFS_PATH		= libtk.vfs/tk_library
TK_VFS_ROOT		= libtk.vfs

HOST_CC		        = @CC_FOR_BUILD@
HOST_EXEEXT             = @EXEEXT_FOR_BUILD@
HOST_OBJEXT             = @OBJEXT_FOR_BUILD@
ZIPFS_BUILD	        = @ZIPFS_BUILD@
NATIVE_ZIP		= @ZIP_PROG@
ZIP_PROG_OPTIONS		= @ZIP_PROG_OPTIONS@
ZIP_PROG_VFSSEARCH  = @ZIP_PROG_VFSSEARCH@
SHARED_BUILD		= @SHARED_BUILD@
INSTALL_MSGS            = @INSTALL_MSGS@
INSTALL_LIBRARIES       = @INSTALL_LIBRARIES@

# Minizip
MINIZIP_OBJS = \
        adler32.$(HOST_OBJEXT) \
        compress.$(HOST_OBJEXT) \
        crc32.$(HOST_OBJEXT) \
        deflate.$(HOST_OBJEXT) \
        infback.$(HOST_OBJEXT) \
        inffast.$(HOST_OBJEXT) \
        inflate.$(HOST_OBJEXT) \
        inftrees.$(HOST_OBJEXT) \
        ioapi.$(HOST_OBJEXT) \
        iowin32.$(HOST_OBJEXT)  \
        trees.$(HOST_OBJEXT) \
        uncompr.$(HOST_OBJEXT) \
        zip.$(HOST_OBJEXT) \
        zutil.$(HOST_OBJEXT) \
        minizip.$(HOST_OBJEXT)

ZIP_INSTALL_OBJS =  @ZIP_INSTALL_OBJS@

CC_SWITCHES = ${CFLAGS} ${CFLAGS_WARNING} ${SHLIB_CFLAGS} \
-I"${GENERIC_DIR_NATIVE}" -I"${WIN_DIR_NATIVE}" \
-I"${XLIB_DIR_NATIVE}" -I"${BITMAP_DIR_NATIVE}" \
-I"${TCL_GENERIC_NATIVE}" -I"${TCL_PLATFORM_NATIVE}" \
${AC_FLAGS} $(NO_DEPRECATED_FLAGS) -DTCL_UTF_MAX=4 -DUSE_TCL_STUBS
${AC_FLAGS} $(NO_DEPRECATED_FLAGS) -DUSE_TCL_STUBS

CC_OBJNAME = @CC_OBJNAME@
CC_EXENAME = @CC_EXENAME@

# Tk used to let the configure script choose which program to use
# for installing, but there are just too many different versions of
# "install" around;  better to use the install-sh script that comes
# with the distribution, which is slower but guaranteed to work.

INSTALL		= cp
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA	= ${INSTALL}

WISH_OBJS = \
	winMain.$(OBJEXT)

TKTEST_OBJS = \
	tkSquare.$(OBJEXT) \
	tkTest.$(OBJEXT) \
	tkOldTest.$(OBJEXT) \
	tkWinTest.$(OBJEXT)

XLIB_OBJS = \
	xcolors.$(OBJEXT) \
	xdraw.$(OBJEXT) \
	xgc.$(OBJEXT) \
	ximage.$(OBJEXT) \
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
263
264
265
266
267
268
269


270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286







-
-










-







	tkWinColor.$(OBJEXT) \
	tkWinConfig.$(OBJEXT) \
	tkWinCursor.$(OBJEXT) \
	tkWinDialog.$(OBJEXT) \
	tkWinDraw.$(OBJEXT) \
	tkWinEmbed.$(OBJEXT) \
	tkWinFont.$(OBJEXT) \
	tkWinGDI.$(OBJEXT) \
	tkWinIco.$(OBJEXT) \
	tkWinImage.$(OBJEXT) \
	tkWinInit.$(OBJEXT) \
	tkWinKey.$(OBJEXT) \
	tkWinMenu.$(OBJEXT) \
	tkWinPixmap.$(OBJEXT) \
	tkWinPointer.$(OBJEXT) \
	tkWinRegion.$(OBJEXT) \
	tkWinScrlbr.$(OBJEXT) \
	tkWinSend.$(OBJEXT) \
	tkWinSendCom.$(OBJEXT) \
	tkWinSysTray.$(OBJEXT) \
	tkWinWindow.$(OBJEXT) \
	tkWinWm.$(OBJEXT) \
	tkWinX.$(OBJEXT) \
	stubs.$(OBJEXT) \
	tk3d.$(OBJEXT) \
	tkArgv.$(OBJEXT) \
	tkAtom.$(OBJEXT) \
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
311
312
313
314
315
316
317

318
319
320
321
322
323

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346







-






-
















-







	tkFont.$(OBJEXT) \
	tkFrame.$(OBJEXT) \
	tkGC.$(OBJEXT) \
	tkGeometry.$(OBJEXT) \
	tkGet.$(OBJEXT) \
	tkGrab.$(OBJEXT) \
	tkGrid.$(OBJEXT) \
	tkIcu.$(OBJEXT) \
	tkImage.$(OBJEXT) \
	tkImgBmap.$(OBJEXT) \
	tkImgListFormat.$(OBJEXT) \
	tkImgGIF.$(OBJEXT) \
	tkImgPNG.$(OBJEXT) \
	tkImgPPM.$(OBJEXT) \
	tkImgSVGnano.$(OBJEXT) \
	tkImgPhoto.$(OBJEXT) \
	tkImgPhInstance.$(OBJEXT) \
	tkImgUtil.$(OBJEXT) \
	tkListbox.$(OBJEXT) \
	tkMacWinMenu.$(OBJEXT) \
	tkMain.$(OBJEXT) \
	tkMain2.$(OBJEXT) \
	tkMenu.$(OBJEXT) \
	tkMenubutton.$(OBJEXT) \
	tkMenuDraw.$(OBJEXT) \
	tkMessage.$(OBJEXT) \
	tkPanedWindow.$(OBJEXT) \
	tkObj.$(OBJEXT) \
	tkOldConfig.$(OBJEXT) \
	tkOption.$(OBJEXT) \
	tkPack.$(OBJEXT) \
	tkPkgConfig.$(OBJEXT) \
	tkPlace.$(OBJEXT) \
	tkPointer.$(OBJEXT) \
	tkRectOval.$(OBJEXT) \
	tkScale.$(OBJEXT) \
	tkScrollbar.$(OBJEXT) \
	tkSelect.$(OBJEXT) \
	tkStyle.$(OBJEXT) \
481
482
483
484
485
486
487
488
489


490
491
492
493


494
495
496

497
498
499
500
501

502
503
504

505
506
507
508
509
510
511
436
437
438
439
440
441
442


443
444
445
446


447
448
449
450

451
452
453
454
455

456
457
458

459
460
461
462
463
464
465
466







-
-
+
+


-
-
+
+


-
+




-
+


-
+







# Specifying TESTFLAGS on the command line is the standard way to pass
# args to tcltest, ie:
#	% make test TESTFLAGS="-verbose bps -file fileName.test"

test: test-classic test-ttk

test-classic: binaries $(TKTEST) $(TEST_DLL_FILE) $(CAT32)
	$(SHELL_ENV) $(WINE) ./$(TKTEST) "$(ROOT_DIR_NATIVE)/tests/all.tcl" \
	$(TESTFLAGS) | $(WINE) ./$(CAT32)
	$(SHELL_ENV) ./$(TKTEST) "$(ROOT_DIR_NATIVE)/tests/all.tcl" \
	$(TESTFLAGS) | ./$(CAT32)

test-ttk: binaries $(TKTEST) $(TEST_DLL_FILE) $(CAT32)
	$(SHELL_ENV) $(WINE) ./$(TKTEST) "$(ROOT_DIR_NATIVE)/tests/ttk/all.tcl" \
	$(TESTFLAGS) | $(WINE) ./$(CAT32)
	$(SHELL_ENV) ./$(TKTEST) "$(ROOT_DIR_NATIVE)/tests/ttk/all.tcl" \
	$(TESTFLAGS) | ./$(CAT32)

runtest: binaries $(TKTEST) $(TEST_DLL_FILE)
	$(SHELL_ENV) $(WINE) ./$(TKTEST) $(TESTFLAGS) $(SCRIPT)
	$(SHELL_ENV) ./$(TKTEST) $(TESTFLAGS) $(SCRIPT)

# This target can be used to run wish from the build directory
# via `make shell` or `make shell SCRIPT=foo.tcl`
shell: binaries
	$(SHELL_ENV) $(WINE) ./$(WISH) $(SCRIPT)
	$(SHELL_ENV) ./$(WISH) $(SCRIPT)

demo: $(WISH)
	$(SHELL_ENV) $(WINE) ./$(WISH) $(ROOT_DIR)/library/demos/widget
	$(SHELL_ENV) ./$(WISH) $(ROOT_DIR)/library/demos/widget

# This target can be used to run wish inside either gdb or insight
gdb: binaries
	@echo "set env TCL_LIBRARY=$(TCL_SRC_DIR_NATIVE)/library" > gdb.run
	@echo "set env TK_LIBRARY=$(ROOT_DIR_NATIVE)/library" >> gdb.run
	PATH="$(TCL_BIN_DIR):$(PATH)"; export PATH; \
	gdb ./$(WISH) --command=gdb.run
529
530
531
532
533
534
535
536

537
538
539
540
541
542

543
544
545
546

547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565




566
567
568
569
570
571
572
573
574
575
576


577
578
579
580
581
582
583
484
485
486
487
488
489
490

491
492
493




494

495


496



497

498
499
500
501
502
503
504
505
506
507




508
509
510
511
512
513
514
515
516
517
518
519
520


521
522
523
524
525
526
527
528
529







-
+


-
-
-
-
+
-

-
-
+
-
-
-

-










-
-
-
-
+
+
+
+









-
-
+
+







		echo "Installing $$i to $(BIN_INSTALL_DIR)/"; \
		$(COPY) $$i "$(BIN_INSTALL_DIR)"; \
	    fi; \
	    done
	@echo "Creating package index $(PKG_INDEX)";
	@$(RM) $(PKG_INDEX);
	@(\
	echo "if {![package vsatisfies [package provide Tcl] 8.7-]} return";\
	echo "if {[catch {package present Tcl 8.6-}]} return";\
	echo "if {(\$$::tcl_platform(platform) eq \"unix\") && ([info exists ::env(DISPLAY)]";\
	echo "	|| ([info exists ::argv] && (\"-display\" in \$$::argv)))} {";\
	echo "    if {[package vsatisfies [package provide Tcl] 9.0]} {";\
	echo "	package ifneeded tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin libtcl9tk$(VERSION).dll]]]";\
	echo "    } else {";\
	echo "	package ifneeded tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin libtk$(VERSION).dll]]]";\
	echo "    package ifneeded Tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin libtk$(VERSION).dll]] Tk]";\
	echo "    }";\
	echo "} else {";\
	echo "    if {[package vsatisfies [package provide Tcl] 9.0]} {";\
	echo "	package ifneeded tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin $(TK_DLL_FILE_TCL9)]]]";\
	echo "    package ifneeded Tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin $(TK_DLL_FILE)]] Tk]";\
	echo "    } else {";\
	echo "	package ifneeded tk $(VERSION)$(PATCH_LEVEL) [list load [file normalize [file join \$$dir .. .. bin $(TK_DLL_FILE_TCL8)]]]";\
	echo "    }";\
	echo "}";\
	echo "package ifneeded Tk $(VERSION)$(PATCH_LEVEL) [list package require -exact tk $(VERSION)$(PATCH_LEVEL)]";\
	) > $(PKG_INDEX);
	@for i in tkConfig.sh $(TK_LIB_FILE) $(TK_STUB_LIB_FILE); \
	    do \
	    if [ -f $$i ]; then \
		echo "Installing $$i to $(LIB_INSTALL_DIR)/"; \
		$(COPY) $$i "$(LIB_INSTALL_DIR)"; \
	    fi; \
	    done

install-libraries: libraries
	@for i in "$$($(CYGPATH) $(prefix)/lib)" \
		"$(INCLUDE_INSTALL_DIR)" "$(INCLUDE_INSTALL_DIR)/X11" \
		"$(SCRIPT_INSTALL_DIR)" "$(SCRIPT_INSTALL_DIR)/images" \
		"$(SCRIPT_INSTALL_DIR)/msgs" "$(SCRIPT_INSTALL_DIR)/ttk"; \
	@for i in $(INSTALL_ROOT)$(prefix)/lib \
		$(INCLUDE_INSTALL_DIR) $(INCLUDE_INSTALL_DIR)/X11 \
		$(SCRIPT_INSTALL_DIR) $(SCRIPT_INSTALL_DIR)/images \
		$(SCRIPT_INSTALL_DIR)/msgs $(SCRIPT_INSTALL_DIR)/ttk; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		$(MKDIR) $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing header files to $(INCLUDE_INSTALL_DIR)/";
	@for i in "$(GENERIC_DIR)/tk.h" "$(GENERIC_DIR)/tkPlatDecls.h" \
		"$(GENERIC_DIR)/tkIntXlibDecls.h" "$(GENERIC_DIR)/tkDecls.h" ; \
	@for i in $(GENERIC_DIR)/tk.h $(GENERIC_DIR)/tkPlatDecls.h \
		$(GENERIC_DIR)/tkIntXlibDecls.h $(GENERIC_DIR)/tkDecls.h ; \
	    do \
	    $(INSTALL_DATA) $$i $(INCLUDE_INSTALL_DIR); \
	    done;
	@for i in $(XLIB_DIR)/X11/*.h; \
	    do \
	    $(INSTALL_DATA) $$i $(INCLUDE_INSTALL_DIR)/X11; \
	    done;
655
656
657
658
659
660
661
662
663
664



665
666
667
668
669

670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

760
761
762

763
764
765
766



767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783

784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800

801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820

821
822
823
824
825

826
827
828
829
830

831
832
833
834
835
836
837
601
602
603
604
605
606
607



608
609
610
611
612
613
614

615
616
617
618
619





620
621
622
623
624
625
626
627
628
629
630
631









632
633
634
635

636
637
638
639
























640
641
642
643
644
645
646
647
648

649
650
651
652





653
654
655
656
657
658
659
660
661

662
663
664

665
666
667
668
669
670
671
672
673
674
675
676
677
678






679




680












681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708
709

710

711
712
713

714
715
716
717
718
719
720
721







-
-
-
+
+
+




-
+




-
-
-
-
-












-
-
-
-
-
-
-
-
-




-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









-
+



-
-
-
-
-









-
+


-
+




+
+
+






-
-
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-




-
+



















-
+




-
+
-



-
+







		echo "Making directory $$i"; \
		$(MKDIR) $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing private header files to $(PRIVATE_INCLUDE_INSTALL_DIR)/";
	@for i in "$(GENERIC_DIR)/tkInt.h" "$(GENERIC_DIR)/tkIntDecls.h" \
		"$(GENERIC_DIR)/tkIntPlatDecls.h" "$(GENERIC_DIR)/tkPort.h" \
		"$(WIN_DIR)/tkWinPort.h" "$(WIN_DIR)/tkWinInt.h" "$(WIN_DIR)/tkWin.h"; \
	@for i in $(GENERIC_DIR)/tkInt.h $(GENERIC_DIR)/tkIntDecls.h \
		$(GENERIC_DIR)/tkIntPlatDecls.h $(GENERIC_DIR)/tkPort.h \
		$(WIN_DIR)/tkWinPort.h $(WIN_DIR)/tkWinInt.h $(WIN_DIR)/tkWin.h; \
	    do \
	    $(INSTALL_DATA) $$i $(PRIVATE_INCLUDE_INSTALL_DIR); \
	    done;

$(WISH): $(WISH_OBJS) @LIBRARIES@ $(TK_STUB_LIB_FILE) wish.$(RES) ${TK_ZIP_FILE}
$(WISH): $(WISH_OBJS) @LIBRARIES@ $(TK_STUB_LIB_FILE) wish.$(RES)
	$(CC) $(CFLAGS) $(WISH_OBJS) $(TK_LIB_FILE) \
	$(TK_STUB_LIB_FILE) $(TCL_LIB_FILE) $(LIBS) \
	wish.$(RES) $(CC_EXENAME) $(LDFLAGS_WINDOW)
	@VC_MANIFEST_EMBED_EXE@
	@if test "${ZIPFS_BUILD}" = "2" ; then \
		cat ${TK_ZIP_FILE} >> ${WISH}; \
		${NATIVE_ZIP} -A ${WISH} \
		  || echo 'ignore zip-error by adjust sfx process (not executable?)'; \
	fi

tktest: $(TKTEST)

$(TKTEST): testMain.$(OBJEXT) $(TEST_DLL_FILE) @LIBRARIES@ $(TK_STUB_LIB_FILE) wish.$(RES)
	$(CC) $(CFLAGS) testMain.$(OBJEXT) $(TEST_LIB_FILE) $(TK_LIB_FILE) \
	$(TK_STUB_LIB_FILE) $(TCL_LIB_FILE) $(LIBS) \
	wish.$(RES) $(CC_EXENAME) $(LDFLAGS_WINDOW)
	@VC_MANIFEST_EMBED_EXE@

${TEST_DLL_FILE}: ${TKTEST_OBJS} ${TK_STUB_LIB_FILE}
	@MAKE_DLL@ ${TKTEST_OBJS} $(TK_STUB_LIB_FILE) $(SHLIB_LD_LIBS)

$(TOP_DIR)/manifest.uuid:
	printf "git-" >$(TOP_DIR)/manifest.uuid
	(cd $(TOP_DIR); git rev-parse HEAD >>$(TOP_DIR)/manifest.uuid || printf "unknown" >$(TOP_DIR)/manifest.uuid)

tkUuid.h:	$(TOP_DIR)/manifest.uuid
	echo "#define TK_VERSION_UUID \\" >$@
	cat $(TOP_DIR)/manifest.uuid >>$@
	echo "" >>$@

# Msys make requires this next rule for some reason.
$(TCL_SRC_DIR)/win/cat.c:

cat32.${OBJEXT}: $(TCL_SRC_DIR)/win/cat.c
	$(CC) -c $(CC_SWITCHES) -DUNICODE -D_UNICODE "$(TCL_SRC_DIR)/win/cat.c" $(CC_OBJNAME)
	$(CC) -c $(CC_SWITCHES) "$(TCL_SRC_DIR)/win/cat.c" $(CC_OBJNAME)

$(CAT32): cat32.${OBJEXT}
	$(CC) $(CFLAGS) cat32.$(OBJEXT) $(CC_EXENAME) $(LIBS) $(LDFLAGS_CONSOLE)

tkzipfile: ${TK_ZIP_FILE}

${TK_ZIP_FILE}:  ${ZIP_INSTALL_OBJS}
	@$(RMDIR) ${TK_VFS_ROOT}
	@mkdir -p ${TK_VFS_PATH}
	@echo "creating ${TK_VFS_PATH} (prepare compression)"
	@( \
	  $(COPY) -a $(TOP_DIR)/library/* ${TK_VFS_PATH}; \
	)
	@$(RMDIR) $(TK_VFS_PATH)/demos
	-@if test "${ZIPFS_BUILD}" = "2" ; then \
	    cp ${TCL_BIN_DIR}/tclsh${TCLVER}s.exe ${TK_VFS_ROOT}/../${TK_ZIP_FILE} || cp ${TCL_BIN_DIR}/../bin/tclsh${TCLVER}s.exe ${TK_VFS_ROOT}/../${TK_ZIP_FILE}; \
	    (zip=`(realpath '${NATIVE_ZIP}' || readlink -m '${NATIVE_ZIP}') 2>/dev/null || \
		(echo '${NATIVE_ZIP}' | sed "s?^\./?$$(pwd)/?")`; \
		cd ${TK_VFS_ROOT} && $$zip -J ../${TK_ZIP_FILE}) \
	fi
	(zip=`(realpath '${NATIVE_ZIP}' || readlink -m '${NATIVE_ZIP}') 2>/dev/null || \
	  (echo '${NATIVE_ZIP}' | sed "s?^\./?$$(pwd)/?")`; \
	  cd ${TK_VFS_ROOT} && \
	  $$zip ${ZIP_PROG_OPTIONS} ../${TK_ZIP_FILE} ${ZIP_PROG_VFSSEARCH} >/dev/null && \
	  echo "${TK_ZIP_FILE} successful created with $$zip" && \
	  cd ..)


# The following targets are configured by autoconf to generate either
# a shared library or static library

${TK_STUB_LIB_FILE}: ${STUB_OBJS}
	@$(RM) ${TK_STUB_LIB_FILE}
	@MAKE_STUB_LIB@ ${STUB_OBJS}
	@POST_MAKE_LIB@

${TK_DLL_FILE}: ${TK_OBJS} $(TK_RES) ${TK_ZIP_FILE}
${TK_DLL_FILE}: ${TK_OBJS} $(TK_RES)
	@$(RM) ${TK_DLL_FILE}
	@MAKE_DLL@ ${TK_OBJS} $(TK_RES) $(SHLIB_LD_LIBS)
	@VC_MANIFEST_EMBED_DLL@
	@if test "${ZIPFS_BUILD}" = "1" ; then \
		cat ${TK_ZIP_FILE} >> ${TK_DLL_FILE}; \
		${NATIVE_ZIP} -A ${TK_DLL_FILE} \
		  || echo 'ignore zip-error by adjust sfx process (not executable?)'; \
	fi

${TK_LIB_FILE}: ${TK_OBJS}
	@$(RM) ${TK_LIB_FILE}
	@MAKE_LIB@ ${TK_OBJS}
	@POST_MAKE_LIB@

# Special case object file targets

winMain.$(OBJEXT): winMain.c
	$(CC) -c $(CC_SWITCHES) -DUNICODE=1 -D_UNICODE=1 @DEPARG@ $(CC_OBJNAME)
	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)

testMain.$(OBJEXT): winMain.c
	$(CC) -c $(CC_SWITCHES) -DTK_TEST -DUNICODE=1 -D_UNICODE=1 @DEPARG@ $(CC_OBJNAME)
	$(CC) -c $(CC_SWITCHES) @DEPARG@ -DTK_TEST $(CC_OBJNAME)

tkTest.$(OBJEXT): tkTest.c
	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)

tkOldTest.$(OBJEXT): tkOldTest.c
	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)

tkWinTest.$(OBJEXT): tkWinTest.c
	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)

tkSquare.$(OBJEXT): tkSquare.c
	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)

tkStubLib.$(OBJEXT): tkStubLib.c
	$(CC) -c $(CC_SWITCHES) @CFLAGS_NOLTO@ @DEPARG@ $(CC_OBJNAME)

ttkStubLib.$(OBJEXT): ${TTK_DIR}/ttkStubLib.c
	$(CC) -c $(CC_SWITCHES) @CFLAGS_NOLTO@ @DEPARG@ $(CC_OBJNAME)

tkMain2.$(OBJEXT): tkMain.c
	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DUNICODE=1 -D_UNICODE=1 @DEPARG@ $(CC_OBJNAME)

tkUnixMenubu.$(OBJEXT): ${UNIX_DIR}/tkUnixMenubu.c
	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DBUILD_ttk @DEPARG@ $(CC_OBJNAME)
	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DTK_ASCII_MAIN @DEPARG@ $(CC_OBJNAME)

tkUnixScale.$(OBJEXT): ${UNIX_DIR}/tkUnixScale.c
	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DBUILD_ttk @DEPARG@ $(CC_OBJNAME)

tkPkgConfig.$(OBJEXT): $(GENERIC_DIR)/tkPkgConfig.c
	$(CC) -c $(CC_SWITCHES)	 -DBUILD_tk -DBUILD_ttk		\
		-DCFG_RUNTIME_DLLFILE="\"$(TK_DLL_FILE)\"" \
		@DEPARG@ $(CC_OBJNAME)


tkWindow.$(OBJEXT): ${GENERIC_DIR}/tkWindow.c configure Makefile tkUuid.h
	$(CC) -c $(CC_SWITCHES) -I. -DBUILD_tk @DEPARG@ $(CC_OBJNAME)

# Extra dependency info
tkConsole.$(OBJEXT): configure Makefile
tkMain.$(OBJEXT): configure Makefile
tkMain2.$(OBJEXT): configure Makefile
tkWindow.$(OBJEXT): configure Makefile

# Add the object extension to the implicit rules.  By default .obj is not
# automatically added.

.SUFFIXES: .${OBJEXT}
.SUFFIXES: .$(RES)
.SUFFIXES: .rc

# Implicit rule for all object files that will end up in the Tk library

%.$(OBJEXT): %.c
	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DBUILD_ttk @DEPARG@ $(CC_OBJNAME)

.rc.$(RES):
	$(RC) @RC_OUT@ $@ @RC_TYPE@ @RC_DEFINES@ @RC_INCLUDE@ "$(GENERIC_DIR_NATIVE)" @RC_INCLUDE@ "$(TCL_GENERIC_NATIVE)" @RC_INCLUDE@ "$(RC_DIR_NATIVE)" @DEPARG@

depend:

cleanhelp:
	$(RM) *.hlp *.cnt *.hpj *.GID *.rtf man2tcl.exe
	$(RM) *.hlp *.cnt *.hpj *.GID *.rtf man2tcl${EXEEXT}

clean: cleanhelp
	$(RM) *.lib *.a *.exp *.dll *.res *.${OBJEXT} *~ \#* TAGS a.out
	$(RM) $(WISH) $(TKTEST) $(CAT32)
	$(RM) *.pch *.ilk *.pdb *.zip
	$(RM) *.pch *.ilk *.pdb
	$(RMDIR) *.vfs

distclean: clean
	$(RM) Makefile config.status config.cache config.log tkConfig.sh \
		wish.exe.manifest tkUuid.h
		wish.exe.manifest

Makefile: $(SRC_DIR)/Makefile.in
	./config.status

#
# Regenerate the stubs files.
#

Changes to win/README.

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
-
+



















-
+
Tk 9.0 for Windows
Tk 8.7 for Windows

Originally by Scott Stanton while at Sun Microsystems Labs

This is the directory where you configure and compile the Windows
version of Tk.  This directory also contains source files for Tk
that are specific to Microsoft Windows.  The rest of this file
contains information specific to the Windows version of Tk.

Please see the README and win/README files that come with the
associated Tcl release for an extensive set of pointers to
documentation.  You will need to obtain and compile the
Tcl release before using the Tk source distrition.

If you install the Tk sources next to the Tcl sources, then
the Tk Makefiles (e.g., makefile.vc for VC++) will properly
locate the necessary Tcl files.  Otherwise you may need to
edit makefile.vc and adjust the path to Tcl accordingly.

Information about compiling for windows is maintained at:
    https://www.tcl-lang.org/doc/howto/compile.html
    http://www.tcl.tk/doc/howto/compile.html

Changes to win/configure.

1
2
3

4
5
6

7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47








48
49
50
51
52
53




















54
55
56

57
58
59




60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76

77
78
79
80
81
82
83
84







85
86
87
88
89
90
91
92
93
94

95
96
97
98

99
100
101
102
103
104

105
106
107
108
109
110

111
112
113




















114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136



137
138
139
140
141

142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174


175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190


191
192
193

194
195
196
197


198
199
200
201
202
203

204
205
206
207
208
209
210
211
212

213
214

215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


233
234
235
236
237


238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259


260
261
262
263

264
265
266
267
268
269





270
271

272
273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
1
2

3
4
5

6

7
8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23


24
25
26
27
28
29

30
31
32
33








34
35
36
37
38
39
40
41
42
43
44






45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64



65



66
67
68
69










70




71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96


97




98
99
100
101
102
103

104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153



154
155
156
157
158
159
160

161

162
163
164
165
166
167


168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187

188

189


190
191

192
193


194
195
196
197
198
199

200

201


202
203

204

205

206


207
208
209
210
211
212


213



214
215
216
217
218

219
220

221

222

223

224
225
226
227
228
229
230







231
232

233



234
235
236
237

238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254


255
256
257
258
259

260






261
262
263
264
265
266

267
268
269
270
271
272

273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299


-
+


-
+
-










-
+
-






-
-
+
+




-




-
-
-
-
-
-
-
-



+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-


-
+








+
+
+
+
+
+
+








-
-
+
-
-
-
-
+





-
+





-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
-
-
+
+
+




-
+
-






-
-
+
+




-














-
+
-

-
-
+
+
-


-
-






-
+
-

-
-
+
+
-

-
+
-

-
-
+
+




-
-
+
-
-
-





-
+

-
+
-

-
+
-







-
-
-
-
-
-
-
+
+
-

-
-
-
+
+


-
+
-
















-
-
+
+



-
+
-
-
-
-
-
-
+
+
+
+
+

-
+





-
+
-



















-







#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.72 for tk 9.0.
# Generated by GNU Autoconf 2.69.
#
#
# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation,
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
# Inc.
#
#
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
else
  case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
IFS=" ""	$as_nl"

PS1='$ '
PS2='> '
PS4='+ '

  as_echo='print -r --'
  as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    export as_echo_n_body
LANGUAGE=C
export LANGUAGE

    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

fi
# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if ${PATH_SEPARATOR+false} :; then
if test "${PATH_SEPARATOR+set}" != set; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

# Use a proper internal environment variable to ensure we don't fall
  # into an infinite loop, continuously re-executing ourselves.
  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
    _as_can_reexec=no; export _as_can_reexec;
    # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
as_fn_exit 255
  fi
  # We don't want this to propagate to other subprocesses.
          { _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
  as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '\${1+\"\$@\"}'='\"\$@\"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case \`(set -o) 2>/dev/null\` in #(
else
  case \`(set -o) 2>/dev/null\` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi
"
  as_required="as_fn_return () { (exit \$1); }
as_fn_success () { as_fn_return 0; }
as_fn_failure () { as_fn_return 1; }
as_fn_ret_success () { return 0; }
as_fn_ret_failure () { return 1; }

exitcode=0
as_fn_success || { exitcode=1; echo as_fn_success failed.; }
as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
if ( set x; as_fn_ret_success y && test x = \"\$1\" )
if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
then :

else case e in #(
  e) exitcode=1; echo positional parameters were not saved. ;;
else
  exitcode=1; echo positional parameters were not saved.
esac
fi
test x\$exitcode = x0 || exit 1
blah=\$(echo \$(echo blah))
test x\"\$blah\" = xblah || exit 1
test -x / || exit 1"
  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
test \$(( 1 + 1 )) = 2 || exit 1"
  if (eval "$as_required") 2>/dev/null
  if (eval "$as_required") 2>/dev/null; then :
then :
  as_have_required=yes
else case e in #(
  e) as_have_required=no ;;
else
  as_have_required=no
esac
fi
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
then :

else case e in #(
  e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
else
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
as_found=false
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
  as_found=:
  case $as_dir in #(
	 /*)
	   for as_base in sh bash ksh sh5; do
	     # Try only shells that exist, to save several forks.
	     as_shell=$as_dir$as_base
	     as_shell=$as_dir/$as_base
	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
		    as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null
		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
then :
  CONFIG_SHELL=$as_shell as_have_required=yes
		   if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null
		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
then :
  break 2
fi
fi
	   done;;
       esac
  as_found=false
done
IFS=$as_save_IFS
if $as_found
then :

else case e in #(
  e) if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null
$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
then :
  CONFIG_SHELL=$SHELL as_have_required=yes
fi ;;
esac
fi
fi; }
IFS=$as_save_IFS


      if test "x$CONFIG_SHELL" != x
      if test "x$CONFIG_SHELL" != x; then :
then :
  export CONFIG_SHELL
             # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
fi

    if test x$as_have_required = xno
    if test x$as_have_required = xno; then :
then :
  printf "%s\n" "$0: This script requires a shell more modern than all"
  printf "%s\n" "$0: the shells that I found on your system."
  if test ${ZSH_VERSION+y} ; then
    printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later."
  $as_echo "$0: This script requires a shell more modern than all"
  $as_echo "$0: the shells that I found on your system."
  if test x${ZSH_VERSION+set} = xset ; then
    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
  else
    printf "%s\n" "$0: Please tell [email protected] about your system,
    $as_echo "$0: Please tell [email protected] about your system,
$0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run
$0: the script under such a shell if you do have one."
  fi
  exit 1
fi ;;
fi
esac
fi
fi
SHELL=${CONFIG_SHELL-/bin/sh}
export SHELL
# Unset more variables known to interfere with behavior of common tools.
CLICOLOR_FORCE= GREP_OPTIONS=
unset CLICOLOR_FORCE GREP_OPTIONS

## --------------------- ##
## M4sh Shell Functions. ##
## --------------------- ##
# as_fn_unset VAR
# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
  return $1
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_dir" |
$as_echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
372
373
374
375
376
377
378
379

380
381
382
383
384
385
386


387
388
389
390

391
392
393
394
395
396
397
398

399
400
401
402
403
404
405


406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423

424
425

426
427
428
429
430
431
432
366
367
368
369
370
371
372

373

374
375
376
377


378
379
380
381


382
383
384
385
386
387
388
389

390

391
392
393
394


395
396
397
398


399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414

415
416
417
418
419
420
421
422







-
+
-




-
-
+
+


-
-
+







-
+
-




-
-
+
+


-
-
+













-
+

-
+







} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else case e in #(
  e) as_fn_append ()
else
  as_fn_append ()
  {
    eval $1=\$$1\$2
  } ;;
esac
  }
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else case e in #(
  e) as_fn_arith ()
else
  as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  } ;;
esac
  }
fi # as_fn_arith


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  printf "%s\n" "$as_me: error: $2" >&2
  $as_echo "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error

if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X/"$0" |
$as_echo X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548



549
550
551
552
553
554
555
468
469
470
471
472
473
474


475
476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499




500
501
502
503
504
505
506
507
508
509
510
511
512






513
514
515
516
517
518
519
520
521
522
523



524
525
526
527
528
529
530
531
532
533







-
-











-
+













-
-
-
-













-
-
-
-
-
-











-
-
-
+
+
+







  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
  sed -n '
    p
    /[$]LINENO/=
  ' <$as_myself |
    sed '
      t clear
      :clear
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
    ' >$as_me.lineno &&
  chmod +x "$as_me.lineno" ||
    { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }

  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
  # already done that, so ensure we don't try to do so again and fall
  # in an infinite loop.  This has already happened in practice.
  _as_can_reexec=no; export _as_can_reexec
  # Don't try to exec as it changes $[0], causing all sort of problems
  # (the dirname of $[0] is not the place where we might find the
  # original and so on.  Autoconf is especially sensitive to this).
  . "./$as_me.lineno"
  # Exit status is that of the last command.
  exit
}


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
566
567
568
569
570
571
572
573

574
575
576
577

578
579
580
581
582
583
584
585
544
545
546
547
548
549
550

551

552
553

554

555
556
557
558
559
560
561







-
+
-


-
+
-







  as_mkdir_p=false
fi

as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


test -n "$DJDIR" || exec 7<&0 </dev/null
exec 6>&1

# Name of the host.
# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
595
596
597
598
599
600
601
602
603
604
605
606
607






608
609
610
611
612
613
614



615
616




617





618
619



620



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
571
572
573
574
575
576
577






578
579
580
581
582
583
584
585
586
587



588
589
590
591

592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617









618
619
620
621

622
623
624
625
626
627
628







-
-
-
-
-
-
+
+
+
+
+
+




-
-
-
+
+
+

-
+
+
+
+

+
+
+
+
+


+
+
+

+
+
+







-
-
-
-
-
-
-
-
-




-







LIBOBJS=
cross_compiling=no
subdirs=
MFLAGS=
MAKEFLAGS=

# Identity of this package.
PACKAGE_NAME='tk'
PACKAGE_TARNAME='tk'
PACKAGE_VERSION='9.0'
PACKAGE_STRING='tk 9.0'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
PACKAGE_NAME=
PACKAGE_TARNAME=
PACKAGE_VERSION=
PACKAGE_STRING=
PACKAGE_BUGREPORT=
PACKAGE_URL=

ac_unique_file="../generic/tk.h"
# Factoring default headers for most tests.
ac_includes_default="\
#include <stddef.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_STDLIB_H
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif"

ac_header_c_list=
ac_subst_vars='LTLIBOBJS
LIBOBJS
RES
RC_DEFINES
RC_DEFINE
RC_INCLUDE
RC_TYPE
677
678
679
680
681
682
683

684
685

686
687
688
689
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737
738
739

740
741
742
743



744
745
746
747
748
749
750
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675


676
677
678
679
680
681
682
683
684










685
686
687
688

689
690
691

692
693
694
695

696
697
698
699
700
701
702
703
704
705
706
707

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722







+


+








-
-


+






-
-
-
-
-
-
-
-
-
-




-



-




-
+











-
+




+
+
+







LDFLAGS_CONSOLE
LDFLAGS_OPTIMIZE
LDFLAGS_DEBUG
CC_EXENAME
CC_OBJNAME
DEPARG
EXTRA_CFLAGS
CFG_TK_EXPORT_FILE_SUFFIX
CFG_TK_UNSHARED_LIB_SUFFIX
CFG_TK_SHARED_LIB_SUFFIX
TCL_DBGX
TCL_PATCH_LEVEL
TCL_MINOR_VERSION
TCL_MAJOR_VERSION
TK_BIN_DIR
TK_SRC_DIR
TK_BUILD_STUB_LIB_SPEC
TK_STUB_LIB_FLAG
TK_STUB_LIB_FILE
TK_DLL_FILE_TCL9
TK_DLL_FILE_TCL8
TK_DLL_FILE
TK_LIB_FILE
TK_DBGX
TK_PATCH_LEVEL
TK_MINOR_VERSION
TK_MAJOR_VERSION
TK_VERSION
MACHINE
TK_WIN_VERSION
INSTALL_MSGS
INSTALL_LIBRARIES
TK_ZIP_FILE
ZIPFS_BUILD
ZIP_INSTALL_OBJS
ZIP_PROG_VFSSEARCH
ZIP_PROG_OPTIONS
ZIP_PROG
EXEEXT_FOR_BUILD
CC_FOR_BUILD
TCLSH_PROG
BUILD_TCLSH
VC_MANIFEST_EMBED_EXE
VC_MANIFEST_EMBED_DLL
CPP
LDFLAGS_DEFAULT
CFLAGS_DEFAULT
MAN2TCLFLAGS
CFLAGS_NOLTO
CFLAGS_WARNING
CFLAGS_OPTIMIZE
CFLAGS_DEBUG
DL_LIBS
WINE
CELIB_DIR
CYGPATH
TCL_DEFS
TCL_STUB_LIB_SPEC
TCL_STUB_LIB_FLAG
TCL_STUB_LIB_FILE
TCL_LIB_SPEC
TCL_LIB_FLAG
TCL_LIB_FILE
TCL_SRC_DIR
TCL_BIN_DIR
TCL_VERSION
SHARED_BUILD
TCL_THREADS
SET_MAKE
RC
RANLIB
AR
EGREP
GREP
CPP
OBJEXT
EXEEXT
ac_ct_CC
CPPFLAGS
LDFLAGS
CFLAGS
CC
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791
792
793

794
795
796


797
798
799
800
801
802
803
804
805
806
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759

760

761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778







-


















-
+
-



+



+
+


-







pdfdir
dvidir
htmldir
infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
datadir
datarootdir
libexecdir
sbindir
bindir
program_transform_name
prefix
exec_prefix
PACKAGE_URL
PACKAGE_BUGREPORT
PACKAGE_STRING
PACKAGE_VERSION
PACKAGE_TARNAME
PACKAGE_NAME
PATH_SEPARATOR
SHELL
SHELL'
OBJEXT_FOR_BUILD'
ac_subst_files=''
ac_user_opts='
enable_option_checking
enable_threads
enable_shared
with_tcl
enable_64bit
enable_wince
with_celib
enable_symbols
enable_embedded_manifest
enable_zipfs
'
      ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
841
842
843
844
845
846
847
848
849
850
851

852
853
854
855
856
857
858
813
814
815
816
817
818
819

820
821

822
823
824
825
826
827
828
829







-


-
+







sbindir='${exec_prefix}/sbin'
libexecdir='${exec_prefix}/libexec'
datarootdir='${prefix}/share'
datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
docdir='${datarootdir}/doc/${PACKAGE}'
infodir='${datarootdir}/info'
htmldir='${docdir}'
dvidir='${docdir}'
pdfdir='${docdir}'
psdir='${docdir}'
libdir='${exec_prefix}/lib'
localedir='${datarootdir}/locale'
870
871
872
873
874
875
876


877
878
879
880
881
882
883
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856







+
+







  fi

  case $ac_option in
  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
  *=)   ac_optarg= ;;
  *)    ac_optarg=yes ;;
  esac

  # Accept the important Cygnus configure options, so we can diagnose typos.

  case $ac_dashdash$ac_option in
  --)
    ac_dashdash=yes ;;

  -bindir | --bindir | --bindi | --bind | --bin | --bi)
    ac_prev=bindir ;;
911
912
913
914
915
916
917
918

919
920

921
922
923
924
925
926
927
884
885
886
887
888
889
890

891
892

893
894
895
896
897
898
899
900







-
+

-
+







  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
    datarootdir=$ac_optarg ;;

  -disable-* | --disable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: '$ac_useropt'"
      as_fn_error $? "invalid feature name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
937
938
939
940
941
942
943
944

945
946

947
948
949
950
951
952
953
910
911
912
913
914
915
916

917
918

919
920
921
922
923
924
925
926







-
+

-
+







  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
    dvidir=$ac_optarg ;;

  -enable-* | --enable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: '$ac_useropt'"
      as_fn_error $? "invalid feature name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1065
1066
1067
1068
1069
1070
1071









1072
1073
1074
1075
1076
1077
1078







-
-
-
-
-
-
-
-
-







  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
    psdir=$ac_optarg ;;

  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil)
    silent=yes ;;

  -runstatedir | --runstatedir | --runstatedi | --runstated \
  | --runstate | --runstat | --runsta | --runst | --runs \
  | --run | --ru | --r)
    ac_prev=runstatedir ;;
  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
  | --run=* | --ru=* | --r=*)
    runstatedir=$ac_optarg ;;

  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
    ac_prev=sbindir ;;
  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
  | --sbi=* | --sb=*)
    sbindir=$ac_optarg ;;

  -sharedstatedir | --sharedstatedir | --sharedstatedi \
1150
1151
1152
1153
1154
1155
1156
1157

1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173

1174
1175

1176
1177
1178
1179
1180
1181
1182
1114
1115
1116
1117
1118
1119
1120

1121
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136

1137
1138

1139
1140
1141
1142
1143
1144
1145
1146







-
+

-
+













-
+

-
+







  -version | --version | --versio | --versi | --vers | -V)
    ac_init_version=: ;;

  -with-* | --with-*)
    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: '$ac_useropt'"
      as_fn_error $? "invalid package name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
    eval with_$ac_useropt=\$ac_optarg ;;

  -without-* | --without-*)
    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: '$ac_useropt'"
      as_fn_error $? "invalid package name: $ac_useropt"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1196
1197
1198
1199
1200
1201
1202
1203
1204


1205
1206
1207
1208
1209
1210
1211
1212

1213
1214
1215
1216
1217
1218
1219

1220
1221

1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262

1263
1264
1265
1266
1267
1268
1269
1160
1161
1162
1163
1164
1165
1166


1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182

1183
1184

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233







-
-
+
+







-
+






-
+

-
+















-
+







-
+
















-
+







  -x-libraries | --x-libraries | --x-librarie | --x-librari \
  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
    ac_prev=x_libraries ;;
  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
    x_libraries=$ac_optarg ;;

  -*) as_fn_error $? "unrecognized option: '$ac_option'
Try '$0 --help' for more information"
  -*) as_fn_error $? "unrecognized option: \`$ac_option'
Try \`$0 --help' for more information"
    ;;

  *=*)
    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
    # Reject names that are not valid shell variable names.
    case $ac_envvar in #(
      '' | [0-9]* | *[!_$as_cr_alnum]* )
      as_fn_error $? "invalid variable name: '$ac_envvar'" ;;
      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
    esac
    eval $ac_envvar=\$ac_optarg
    export $ac_envvar ;;

  *)
    # FIXME: should be removed in autoconf 3.0.
    printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2
    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
      printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2
      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
    ;;

  esac
done

if test -n "$ac_prev"; then
  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
  as_fn_error $? "missing argument to $ac_option"
fi

if test -n "$ac_unrecognized_opts"; then
  case $enable_option_checking in
    no) ;;
    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
    *)     printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
  esac
fi

# Check all directory arguments for consistency.
for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
		datadir sysconfdir sharedstatedir localstatedir includedir \
		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
		libdir localedir mandir runstatedir
		libdir localedir mandir
do
  eval ac_val=\$$ac_var
  # Remove trailing slashes.
  case $ac_val in
    */ )
      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
      eval $ac_var=\$ac_val;;
  esac
  # Be sure to have absolute directory names.
  case $ac_val in
    [\\/$]* | ?:[\\/]* )  continue;;
    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
  esac
  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
done

# There might be people who depend on the old broken behavior: '$host'
# There might be people who depend on the old broken behavior: `$host'
# used to hold the argument of --host etc.
# FIXME: To remove some day.
build=$build_alias
host=$host_alias
target=$target_alias

# FIXME: To remove some day.
1294
1295
1296
1297
1298
1299
1300
1301

1302
1303
1304
1305
1306
1307
1308
1258
1259
1260
1261
1262
1263
1264

1265
1266
1267
1268
1269
1270
1271
1272







-
+







  ac_srcdir_defaulted=yes
  # Try the directory containing this script, then the parent directory.
  ac_confdir=`$as_dirname -- "$as_myself" ||
$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_myself" : 'X\(//\)[^/]' \| \
	 X"$as_myself" : 'X\(//\)$' \| \
	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_myself" |
$as_echo X"$as_myself" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
1323
1324
1325
1326
1327
1328
1329
1330

1331
1332
1333
1334
1335
1336
1337
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300
1301







-
+







else
  ac_srcdir_defaulted=no
fi
if test ! -r "$srcdir/$ac_unique_file"; then
  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
fi
ac_msg="sources are in $srcdir, but 'cd $srcdir' does not work"
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_abs_confdir=`(
	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
	pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
  srcdir=.
fi
1351
1352
1353
1354
1355
1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372

1373
1374

1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387




1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1427

1428
1429

1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470

1471
1472

1473
1474
1475
1476
1477
1478
1479
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335

1336
1337

1338
1339

1340
1341
1342
1343
1344
1345
1346
1347




1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361

1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381

1382


1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395

1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432

1433
1434

1435
1436
1437
1438
1439
1440
1441
1442







-
+













-
+

-
+

-
+







-
-
-
-
+
+
+
+










-








-
+











-
+
-
-






+


+



-






+











-
+


















-
+

-
+







#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
'configure' configures tk 9.0 to adapt to many kinds of systems.
\`configure' configures this package to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print 'checking ...' messages
  -q, --quiet, --silent   do not print \`checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for '--cache-file=config.cache'
  -C, --config-cache      alias for \`--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or '..']
      --srcdir=DIR        find the sources in DIR [configure dir or \`..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [$ac_default_prefix]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, 'make install' will install all the files in
'$ac_default_prefix/bin', '$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than '$ac_default_prefix' using '--prefix',
for instance '--prefix=\$HOME'.
By default, \`make install' will install all the files in
\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than \`$ac_default_prefix' using \`--prefix',
for instance \`--prefix=\$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/tk]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]
_ACEOF

  cat <<\_ACEOF
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in

     short | recursive ) echo "Configuration of tk 9.0:";;
   esac
  cat <<\_ACEOF

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-threads        build with threads (default: on)
  --enable-shared         build and link with shared libraries (default: on)
  --enable-64bit          enable 64bit support (where applicable)
  --enable-wince          enable Win/CE support (where applicable)
  --enable-symbols        build with debugging symbols (default: off)
  --enable-embedded-manifest
                          embed manifest if possible (default: yes)
  --enable-zipfs          build with Zipfs support (default: on)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-tcl              directory containing tcl configuration
                          (tclConfig.sh)
  --with-celib=DIR        use Windows/CE support library from DIR

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by 'configure' or to help
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.
_ACEOF
ac_status=$?
fi

if test "$ac_init_help" = "recursive"; then
  # If there are subdirs, report their specific --help.
  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
    test -d "$ac_dir" ||
      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
      continue
    ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
1493
1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519


1520
1521

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538

1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556
1557

1558
1559
1560
1561


1562
1563
1564

1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
1456
1457
1458
1459
1460
1461
1462

1463

1464
1465
1466
1467
1468
1469
1470

1471
1472
1473
1474
1475
1476
1477
1478
1479


1480
1481
1482

1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499

1500
1501
1502
1503
1504
1505
1506

1507
1508
1509
1510
1511
1512
1513
1514

1515
1516
1517
1518

1519

1520


1521
1522
1523
1524

1525

1526
1527
1528
1529
1530
1531






























































































1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551

1552
1553
1554
1555


1556
1557


1558
1559
1560
1561

1562

1563
1564
1565
1566
1567









1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
+
-







-
+








-
-
+
+

-
+
















-
+






-
+







-
+



-
+
-

-
-
+
+


-
+
-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+







-
+



-
-
+

-
-
+
+


-
+
-





-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+

+




-
-
+
+

-
+







    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
    ac_top_srcdir=$ac_top_build_prefix$srcdir
    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix

    cd "$ac_dir" || { ac_status=$?; continue; }
    # Check for configure.gnu first; this name is used for a wrapper for
    # Check for guested configure.
    # Metaconfig's "Configure" on case-insensitive file systems.
    if test -f "$ac_srcdir/configure.gnu"; then
      echo &&
      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
    elif test -f "$ac_srcdir/configure"; then
      echo &&
      $SHELL "$ac_srcdir/configure" --help=recursive
    else
      printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2
      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
    fi || ac_status=$?
    cd "$ac_pwd" || { ac_status=$?; break; }
  done
fi

test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
  cat <<\_ACEOF
tk configure 9.0
generated by GNU Autoconf 2.72
configure
generated by GNU Autoconf 2.69

Copyright (C) 2023 Free Software Foundation, Inc.
Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit
fi

## ------------------------ ##
## Autoconf initialization. ##
## ------------------------ ##

# ac_fn_c_try_compile LINENO
# --------------------------
# Try to compile conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest.beam
  rm -f conftest.$ac_objext
  if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest.$ac_objext
       } && test -s conftest.$ac_objext; then :
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1 ;;
	ac_retval=1
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_compile

# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  eval "$3=yes"
else case e in #(
  e) eval "$3=no" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_compile

# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
# variable VAR accordingly.
ac_fn_c_check_type ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) eval "$3=no"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
int
main (void)
{
if (sizeof ($2))
	 return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
int
main (void)
{
if (sizeof (($2)))
	    return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :

else case e in #(
  e) eval "$3=yes" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_type

# ac_fn_c_try_cpp LINENO
# ----------------------
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_cpp ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_cpp conftest.$ac_ext"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } > conftest.i && {
	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
	 test ! -s conftest.err
       }
then :
       }; then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

    ac_retval=1 ;;
    ac_retval=1
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_cpp
ac_configure_args_raw=
for ac_arg
do
  case $ac_arg in
  *\'*)
    ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
  esac
  as_fn_append ac_configure_args_raw " '$ac_arg'"
done

# ac_fn_c_try_run LINENO
# ----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_c_try_run ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then :
  ac_retval=0
else
  $as_echo "$as_me: program exited with status $ac_status" >&5
       $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

       ac_retval=$ac_status
fi
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_run

# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
# ---------------------------------------------
# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
# accordingly.
ac_fn_c_check_decl ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  as_decl_name=`echo $2|sed 's/ *(.*//'`
  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
int
main ()
{
#ifndef $as_decl_name
#ifdef __cplusplus
  (void) $as_decl_use;
#else
  (void) $as_decl_name;
#endif
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  eval "$3=yes"
else
  eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_decl

# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  eval "$3=yes"
else
  eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_compile
case $ac_configure_args_raw in
  *$as_nl*)
    ac_safe_unquote= ;;

# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
# the include files in INCLUDES and setting the cache variable VAR
# accordingly.
ac_fn_c_check_header_mongrel ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if eval \${$3+:} false; then :
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
fi
eval ac_res=\$$3
  *)
    ac_unsafe_z='|&;<>()$`\\"*?[ ''	' # This string ends in space, tab.
    ac_unsafe_a="$ac_unsafe_z#~"
    ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g"
    ac_configure_args_raw=`      printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;;
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
else
  # Is the header compilable?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
$as_echo_n "checking $2 usability... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_header_compiler=yes
else
  ac_header_compiler=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
$as_echo "$ac_header_compiler" >&6; }

# Is the header present?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
$as_echo_n "checking $2 presence... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <$2>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  ac_header_preproc=yes
else
  ac_header_preproc=no
fi
rm -f conftest.err conftest.i conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
$as_echo "$ac_header_preproc" >&6; }

# So?  What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
  yes:no: )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
  no:yes:* )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
esac
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  eval "$3=\$ac_header_compiler"
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_mongrel
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by tk $as_me 9.0, which was
generated by GNU Autoconf 2.72.  Invocation command line was
It was created by $as_me, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ $0$ac_configure_args_raw
  $ $0 $@

_ACEOF
exec 5>>config.log
{
cat <<_ASUNAME
## --------- ##
## Platform. ##
1757
1758
1759
1760
1761
1762
1763
1764
1765

1766
1767
1768
1769

1770
1771
1772
1773
1774
1775
1776
1807
1808
1809
1810
1811
1812
1813


1814




1815
1816
1817
1818
1819
1820
1821
1822







-
-
+
-
-
-
-
+








_ASUNAME

as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    printf "%s\n" "PATH: $as_dir"
    $as_echo "PATH: $as_dir"
  done
IFS=$as_save_IFS

} >&5

cat >&5 <<_ACEOF

1797
1798
1799
1800
1801
1802
1803
1804

1805
1806
1807
1808
1809
1810
1811
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
1857







-
+







  do
    case $ac_arg in
    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
    | -silent | --silent | --silen | --sile | --sil)
      continue ;;
    *\'*)
      ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
    esac
    case $ac_pass in
    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
    2)
      as_fn_append ac_configure_args1 " '$ac_arg'"
      if test $ac_must_keep_next = true; then
	ac_must_keep_next=false # Got value, back to normal.
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
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







-
-




-
+










-
-
+
+








# When interrupted or exit'd, cleanup temporary files, and complete
# config.log.  We remove comments because anyway the quotes in there
# would cause problems or look ugly.
# WARNING: Use '\'' to represent an apostrophe within the trap.
# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
trap 'exit_status=$?
  # Sanitize IFS.
  IFS=" ""	$as_nl"
  # Save into config.log some information that might help in debugging.
  {
    echo

    printf "%s\n" "## ---------------- ##
    $as_echo "## ---------------- ##
## Cache variables. ##
## ---------------- ##"
    echo
    # The following way of writing the cache mishandles newlines in values,
(
  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
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
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







-
+







-
+

-
+




-
+







-
+

-
+





-
+







-
-
+
+













-
+



+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+

+
-
+
+




+
+

+
-
+
+
+
+
+

-
+
+

-
+
+

-
-
+

-
+
-
-
-
-
-
-
-
-
+
+
+


-
-
+
+

-
+







-
-
+
+






-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
+
+


-
-
+
+








-
-
+
+


-
-
+
+


-
-
-
-
+
+
+
+





-
+









-
-
-
-
+
+
+
+
-
-
+














-





-
-
-
-
+
+
+
+







      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
)
    echo

    printf "%s\n" "## ----------------- ##
    $as_echo "## ----------------- ##
## Output variables. ##
## ----------------- ##"
    echo
    for ac_var in $ac_subst_vars
    do
      eval ac_val=\$$ac_var
      case $ac_val in
      *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      esac
      printf "%s\n" "$ac_var='\''$ac_val'\''"
      $as_echo "$ac_var='\''$ac_val'\''"
    done | sort
    echo

    if test -n "$ac_subst_files"; then
      printf "%s\n" "## ------------------- ##
      $as_echo "## ------------------- ##
## File substitutions. ##
## ------------------- ##"
      echo
      for ac_var in $ac_subst_files
      do
	eval ac_val=\$$ac_var
	case $ac_val in
	*\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	esac
	printf "%s\n" "$ac_var='\''$ac_val'\''"
	$as_echo "$ac_var='\''$ac_val'\''"
      done | sort
      echo
    fi

    if test -s confdefs.h; then
      printf "%s\n" "## ----------- ##
      $as_echo "## ----------- ##
## confdefs.h. ##
## ----------- ##"
      echo
      cat confdefs.h
      echo
    fi
    test "$ac_signal" != 0 &&
      printf "%s\n" "$as_me: caught signal $ac_signal"
    printf "%s\n" "$as_me: exit $exit_status"
      $as_echo "$as_me: caught signal $ac_signal"
    $as_echo "$as_me: exit $exit_status"
  } >&5
  rm -f core *.core core.conftest.* &&
    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
    exit $exit_status
' 0
for ac_signal in 1 2 13 15; do
  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
done
ac_signal=0

# confdefs.h avoids OS command line length limits that DEFS can exceed.
rm -f -r conftest* confdefs.h

printf "%s\n" "/* confdefs.h */" > confdefs.h
$as_echo "/* confdefs.h */" > confdefs.h

# Predefined preprocessor variables.

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h
#define PACKAGE_NAME "$PACKAGE_NAME"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h
#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h
#define PACKAGE_VERSION "$PACKAGE_VERSION"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h
#define PACKAGE_STRING "$PACKAGE_STRING"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
_ACEOF

cat >>confdefs.h <<_ACEOF
printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h
#define PACKAGE_URL "$PACKAGE_URL"
_ACEOF


# Let the site file select an alternate cache file if it wants to.
# Prefer an explicitly selected file to automatically selected ones.
ac_site_file1=NONE
ac_site_file2=NONE
if test -n "$CONFIG_SITE"; then
  # We do not want a PATH search for config.site.
  ac_site_files="$CONFIG_SITE"
  case $CONFIG_SITE in #((
    -*)  ac_site_file1=./$CONFIG_SITE;;
    */*) ac_site_file1=$CONFIG_SITE;;
    *)   ac_site_file1=./$CONFIG_SITE;;
  esac
elif test "x$prefix" != xNONE; then
  ac_site_files="$prefix/share/config.site $prefix/etc/config.site"
  ac_site_file1=$prefix/share/config.site
  ac_site_file2=$prefix/etc/config.site
else
  ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
  ac_site_file1=$ac_default_prefix/share/config.site
  ac_site_file2=$ac_default_prefix/etc/config.site
fi

for ac_site_file in $ac_site_files
for ac_site_file in "$ac_site_file1" "$ac_site_file2"
do
  case $ac_site_file in #(
  test "x$ac_site_file" = xNONE && continue
  */*) :
     ;; #(
  *) :
    ac_site_file=./$ac_site_file ;;
esac
  if test -f "$ac_site_file" && test -r "$ac_site_file"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;}
  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
$as_echo "$as_me: loading site script $ac_site_file" >&6;}
    sed 's/^/| /' "$ac_site_file" >&5
    . "$ac_site_file" \
      || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "failed to load site script $ac_site_file
See 'config.log' for more details" "$LINENO" 5; }
See \`config.log' for more details" "$LINENO" 5; }
  fi
done

if test -r "$cache_file"; then
  # Some versions of bash will fail to source /dev/null (special files
  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
printf "%s\n" "$as_me: loading cache $cache_file" >&6;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
$as_echo "$as_me: loading cache $cache_file" >&6;}
    case $cache_file in
      [\\/]* | ?:[\\/]* ) . "$cache_file";;
      *)                      . "./$cache_file";;
    esac
  fi
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
printf "%s\n" "$as_me: creating cache $cache_file" >&6;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
$as_echo "$as_me: creating cache $cache_file" >&6;}
  >$cache_file
fi

# Test code for whether the C compiler supports C89 (global declarations)
ac_c_conftest_c89_globals='
/* Does the compiler advertise C89 conformance?
   Do not test the value of __STDC__, because some compilers set it to 0
   while being otherwise adequately conformant. */
#if !defined __STDC__
# error "Compiler does not advertise C89 conformance"
#endif

#include <stddef.h>
#include <stdarg.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7 src/conf.sh.  */
struct buf { int x; };
struct buf * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (char **p, int i)
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;
}

/* C89 style stringification. */
#define noexpand_stringify(a) #a
const char *stringified = noexpand_stringify(arbitrary+token=sequence);

/* C89 style token pasting.  Exercises some of the corner cases that
   e.g. old MSVC gets wrong, but not very hard. */
#define noexpand_concat(a,b) a##b
#define expand_concat(a,b) noexpand_concat(a,b)
extern int vA;
extern int vbee;
#define aye A
#define bee B
int *pvA = &expand_concat(v,aye);
int *pvbee = &noexpand_concat(v,bee);

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not \xHH hex character constants.
   These do not provoke an error unfortunately, instead are silently treated
   as an "x".  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously \x00 != x always comes out true, for an
   array size at least.  It is necessary to write \x00 == 0 to get something
   that is true only with -std.  */
int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) '\''x'\''
int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
               int, int);'

# Test code for whether the C compiler supports C89 (body of main).
ac_c_conftest_c89_main='
ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]);
'

# Test code for whether the C compiler supports C99 (global declarations)
ac_c_conftest_c99_globals='
/* Does the compiler advertise C99 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# error "Compiler does not advertise C99 conformance"
#endif

// See if C++-style comments work.

#include <stdbool.h>
extern int puts (const char *);
extern int printf (const char *, ...);
extern int dprintf (int, const char *, ...);
extern void *malloc (size_t);
extern void free (void *);

// Check varargs macros.  These examples are taken from C99 6.10.3.5.
// dprintf is used instead of fprintf to avoid needing to declare
// FILE and stderr.
#define debug(...) dprintf (2, __VA_ARGS__)
#define showlist(...) puts (#__VA_ARGS__)
#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
static void
test_varargs_macros (void)
{
  int x = 1234;
  int y = 5678;
  debug ("Flag");
  debug ("X = %d\n", x);
  showlist (The first, second, and third items.);
  report (x>y, "x is %d but y is %d", x, y);
}

// Check long long types.
#define BIG64 18446744073709551615ull
#define BIG32 4294967295ul
#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
#if !BIG_OK
  #error "your preprocessor is broken"
#endif
#if BIG_OK
#else
  #error "your preprocessor is broken"
#endif
static long long int bignum = -9223372036854775807LL;
static unsigned long long int ubignum = BIG64;

struct incomplete_array
{
  int datasize;
  double data[];
};

struct named_init {
  int number;
  const wchar_t *name;
  double average;
};

typedef const char *ccp;

static inline int
test_restrict (ccp restrict text)
{
  // Iterate through items via the restricted pointer.
  // Also check for declarations in for loops.
  for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
    continue;
  return 0;
}

// Check varargs and va_copy.
static bool
test_varargs (const char *format, ...)
{
  va_list args;
  va_start (args, format);
  va_list args_copy;
  va_copy (args_copy, args);

  const char *str = "";
  int number = 0;
  float fnumber = 0;

  while (*format)
    {
      switch (*format++)
	{
	case '\''s'\'': // string
	  str = va_arg (args_copy, const char *);
	  break;
	case '\''d'\'': // int
	  number = va_arg (args_copy, int);
	  break;
	case '\''f'\'': // float
	  fnumber = va_arg (args_copy, double);
	  break;
	default:
	  break;
	}
    }
  va_end (args_copy);
  va_end (args);

  return *str && number && fnumber;
}
'

# Test code for whether the C compiler supports C99 (body of main).
ac_c_conftest_c99_main='
  // Check bool.
  _Bool success = false;
  success |= (argc != 0);

  // Check restrict.
  if (test_restrict ("String literal") == 0)
    success = true;
  char *restrict newvar = "Another string";

  // Check varargs.
  success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
  test_varargs_macros ();

  // Check flexible array members.
  struct incomplete_array *ia =
    malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
  ia->datasize = 10;
  for (int i = 0; i < ia->datasize; ++i)
    ia->data[i] = i * 1.234;
  // Work around memory leak warnings.
  free (ia);

  // Check named initializers.
  struct named_init ni = {
    .number = 34,
    .name = L"Test wide string",
    .average = 543.34343,
  };

  ni.number = 58;

  int dynamic_array[ni.number];
  dynamic_array[0] = argv[0][0];
  dynamic_array[ni.number - 1] = 543;

  // work around unused variable warnings
  ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\''
	 || dynamic_array[ni.number - 1] != 543);
'

# Test code for whether the C compiler supports C11 (global declarations)
ac_c_conftest_c11_globals='
/* Does the compiler advertise C11 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
# error "Compiler does not advertise C11 conformance"
#endif

// Check _Alignas.
char _Alignas (double) aligned_as_double;
char _Alignas (0) no_special_alignment;
extern char aligned_as_int;
char _Alignas (0) _Alignas (int) aligned_as_int;

// Check _Alignof.
enum
{
  int_alignment = _Alignof (int),
  int_array_alignment = _Alignof (int[100]),
  char_alignment = _Alignof (char)
};
_Static_assert (0 < -_Alignof (int), "_Alignof is signed");

// Check _Noreturn.
int _Noreturn does_not_return (void) { for (;;) continue; }

// Check _Static_assert.
struct test_static_assert
{
  int x;
  _Static_assert (sizeof (int) <= sizeof (long int),
                  "_Static_assert does not work in struct");
  long int y;
};

// Check UTF-8 literals.
#define u8 syntax error!
char const utf8_literal[] = u8"happens to be ASCII" "another string";

// Check duplicate typedefs.
typedef long *long_ptr;
typedef long int *long_ptr;
typedef long_ptr long_ptr;

// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
struct anonymous
{
  union {
    struct { int i; int j; };
    struct { int k; long int l; } w;
  };
  int m;
} v1;
'

# Test code for whether the C compiler supports C11 (body of main).
ac_c_conftest_c11_main='
  _Static_assert ((offsetof (struct anonymous, i)
		   == offsetof (struct anonymous, w.k)),
		  "Anonymous union alignment botch");
  v1.i = 2;
  v1.w.k = 5;
  ok |= v1.i != 5;
'

# Test code for whether the C compiler supports C11 (complete).
ac_c_conftest_c11_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}
${ac_c_conftest_c11_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  ${ac_c_conftest_c11_main}
  return ok;
}
"

# Test code for whether the C compiler supports C99 (complete).
ac_c_conftest_c99_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  return ok;
}
"

# Test code for whether the C compiler supports C89 (complete).
ac_c_conftest_c89_program="${ac_c_conftest_c89_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  return ok;
}
"

as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H"
as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H"
as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H"
as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H"
as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H"
as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H"
as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H"
as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H"
as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H"
# Check that the precious variables saved in the cache have kept the same
# value.
ac_cache_corrupted=false
for ac_var in $ac_precious_vars; do
  eval ac_old_set=\$ac_cv_env_${ac_var}_set
  eval ac_new_set=\$ac_env_${ac_var}_set
  eval ac_old_val=\$ac_cv_env_${ac_var}_value
  eval ac_new_val=\$ac_env_${ac_var}_value
  case $ac_old_set,$ac_new_set in
    set,)
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&2;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,set)
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was not set in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was not set in the previous run" >&2;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,);;
    *)
      if test "x$ac_old_val" != "x$ac_new_val"; then
	# differences in whitespace do not lead to failure.
	ac_old_val_w=`echo x $ac_old_val`
	ac_new_val_w=`echo x $ac_new_val`
	if test "$ac_old_val_w" != "$ac_new_val_w"; then
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' has changed since the previous run:" >&5
printf "%s\n" "$as_me: error: '$ac_var' has changed since the previous run:" >&2;}
	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
	  ac_cache_corrupted=:
	else
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&5
printf "%s\n" "$as_me: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&2;}
	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
	  eval $ac_var=\$ac_old_val
	fi
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   former value:  '$ac_old_val'" >&5
printf "%s\n" "$as_me:   former value:  '$ac_old_val'" >&2;}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   current value: '$ac_new_val'" >&5
printf "%s\n" "$as_me:   current value: '$ac_new_val'" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
      fi;;
  esac
  # Pass precious variables to config.status.
  if test "$ac_new_set" = set; then
    case $ac_new_val in
    *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *) ac_arg=$ac_var=$ac_new_val ;;
    esac
    case " $ac_configure_args " in
      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
    esac
  fi
done
if $ac_cache_corrupted; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
  as_fn_error $? "run '${MAKE-make} distclean' and/or 'rm $cache_file'
	    and start over" "$LINENO" 5
  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
fi
## -------------------- ##
## Main body of script. ##
## -------------------- ##

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu





# The following define is needed when building with Cygwin since newer
# versions of autoconf incorrectly set SHELL to /bin/bash instead of
# /bin/sh. The bash shell seems to suffer from some strange failures.
SHELL=/bin/sh

TK_VERSION=9.0
TK_MAJOR_VERSION=9
TK_MINOR_VERSION=0
TK_PATCH_LEVEL="b2"
TK_VERSION=8.7
TK_MAJOR_VERSION=8
TK_MINOR_VERSION=7
TK_PATCH_LEVEL="a0"
VER=$TK_MAJOR_VERSION$TK_MINOR_VERSION

#------------------------------------------------------------------------
# Handle the --prefix=... option
#------------------------------------------------------------------------

if test "${prefix}" = "NONE"; then
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
3171

3172
3173
3174

3175
3176
3177
3178


3179
3180
3181
3182
3183



3184
3185
3186
3187



3188
3189
3190
3191

3192
3193
3194
3195
3196
3197
3198
3199
3200
3201

3202
3203
3204
3205


3206
3207
3208

3209
3210

3211
3212
3213
3214


3215
3216
3217
3218
3219
3220
3221
3222

3223
3224
3225
3226



3227
3228
3229
3230



3231
3232
3233
3234
3235
3236
3237
3238

3239
3240
3241
3242
3243
3244
3245

3246
3247
3248
3249


3250
3251
3252
3253
3254

3255
3256
3257
3258
3259
3260
3261

3262
3263
3264
3265


3266
3267
3268
3269
3270
3271

3272
3273
3274
3275
3276
3277
3278

3279
3280
3281
3282

3283
3284
3285

3286
3287
3288
3289


3290
3291
3292
3293
3294



3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314



3315
3316
3317
3318



3319
3320
3321
3322
3323
3324
3325


3326
3327
3328

3329
3330
3331
3332
3333
3334




3335
3336
3337
3338
3339
3340












3341
3342
3343

3344
3345
3346
3347
3348
3349
3350
3351
3352









3353
3354
3355
3356
3357
3358
3359








3360
3361
3362
3363



3364
3365
3366



3367
3368

3369
3370


3371



3372
3373


3374
3375
3376

3377
3378

3379
3380
3381


3382
3383
3384

3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419

3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440








3441
3442


3443
3444
3445
3446
3447
3448


3449
3450
3451
3452
3453


3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467



3468
3469
3470
3471



3472
3473
3474
3475
3476
3477
3478


3479
3480
3481
3482

3483
3484
3485
3486

3487
3488
3489

3490
3491
3492
3493


3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509





































3510
3511










































3512












3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523



























3524



3525






3526





3527
3528












































3529











3530




3531




























































3532


































3533
3534









3535







































































3536

3537
3538

3539
3540
3541
3542
3543
3544
3545



3546
3547
3548
3549



3550
3551
3552
3553
3554
3555
3556
3557

3558
3559
3560
3561
3562

3563
3564

3565
3566
3567
3568
3569
3570
3571

3572
3573
3574
3575
3576
3577


3578
3579
3580


3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591



3592
3593
3594
3595



3596
3597
3598
3599
3600
3601
3602
3603

3604
3605
3606
3607
3608

3609
3610

3611
3612
3613
3614
3615
3616
3617

3618
3619
3620
3621
3622
3623


3624
3625
3626


3627
3628
3629
3630
3631
3632
3633
3634
3635


3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649



3650
3651
3652
3653



3654
3655
3656
3657
3658
3659
3660
3661

3662
3663
3664
3665
3666

3667
3668

3669
3670
3671
3672
3673
3674
3675

3676
3677
3678
3679
3680
3681


3682
3683
3684


3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695



3696
3697
3698
3699



3700
3701
3702
3703
3704
3705
3706
3707

3708
3709
3710
3711
3712

3713
3714

3715
3716
3717
3718
3719
3720
3721

3722
3723
3724
3725
3726
3727


3728
3729
3730


3731
3732
3733
3734
3735
3736
3737
3738
3739


3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753



3754
3755
3756
3757



3758
3759
3760
3761
3762
3763
3764
3765

3766
3767
3768
3769
3770

3771
3772

3773
3774
3775
3776
3777
3778
3779

3780
3781
3782
3783
3784
3785


3786
3787
3788


3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799



3800
3801
3802
3803



3804
3805
3806
3807
3808
3809
3810
3811

3812
3813
3814
3815
3816

3817
3818

3819
3820
3821
3822
3823
3824
3825

3826
3827
3828
3829
3830
3831


3832
3833
3834


3835
3836
3837
3838
3839
3840
3841
3842
3843


3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858


3859
3860
3861


3862
3863
3864
3865



3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877

3878
3879
3880
3881
3882


3883
3884
3885
3886


3887
3888
3889
3890
3891
3892
3893
3894
3895
3896

































3897
3898
3899
3900
3901
3902
3903
3904
3905


3906
3907

3908
3909
3910
3911
3912
3913











3914
3915
3916
3917


3918
3919
3920
3921


3922
3923
3924

3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946

3947
3948
3949
3950
3951
3952
3953



3954
3955
3956
3957



3958
3959
3960
3961
3962
3963
3964
3965


3966
3967
3968
3969
3970
3971
3972
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288


3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369

3370
3371
3372
3373
3374
3375
3376
3377



3378
3379
3380




3381
3382
3383
3384
3385
3386
3387
3388
3389


3390



3391

3392
3393

3394
3395
3396
3397
3398
3399
3400

3401

3402
3403
3404


3405
3406
3407


3408
3409
3410
3411
3412
3413
3414
3415
3416
3417



3418
3419
3420




3421
3422
3423
3424
3425
3426
3427
3428
3429


3430



3431

3432
3433

3434
3435
3436
3437
3438
3439
3440

3441

3442
3443
3444


3445
3446
3447


3448
3449
3450
3451
3452
3453
3454
3455
3456


3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469



3470
3471
3472




3473
3474
3475
3476
3477
3478
3479
3480
3481


3482



3483

3484
3485

3486
3487
3488
3489
3490
3491
3492

3493

3494
3495
3496


3497
3498
3499


3500
3501
3502
3503
3504
3505
3506
3507
3508
3509



3510
3511
3512




3513
3514
3515
3516
3517
3518
3519
3520
3521


3522



3523

3524
3525

3526
3527
3528
3529
3530
3531
3532

3533

3534
3535
3536


3537
3538
3539


3540
3541
3542
3543
3544
3545
3546
3547
3548


3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561



3562
3563
3564




3565
3566
3567
3568
3569
3570
3571
3572
3573


3574



3575

3576
3577

3578
3579
3580
3581
3582
3583
3584

3585

3586
3587
3588


3589
3590
3591


3592
3593
3594
3595
3596
3597
3598
3599
3600
3601



3602
3603
3604




3605
3606
3607
3608
3609
3610
3611
3612
3613


3614



3615

3616
3617

3618
3619
3620
3621
3622
3623
3624

3625

3626
3627
3628


3629
3630
3631


3632
3633
3634
3635
3636
3637
3638
3639
3640


3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655


3656
3657
3658


3659
3660




3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674

3675

3676
3677


3678
3679
3680
3681


3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733


3734
3735
3736

3737

3738




3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751


3752
3753
3754
3755


3756
3757
3758
3759

3760
3761
3762

3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780

3781

3782
3783
3784



3785
3786
3787




3788
3789
3790
3791
3792
3793
3794
3795
3796


3797
3798
3799
3800
3801
3802
3803
3804
3805







-
-
-
-
-
-
-
-
-








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+












-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+







-
-
+
-
-
-

-
-
+
+




-
+















-
+


-
+
-



-
-
+
+

-
-
+
+










-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+












-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+











-
-
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
+


-
+


-
+






-
+









-
+







-
+











-
-
-
+
+
+




















-
+


-
-
+
+
-
-
-
+
+














-
+




-
+










-
-
+
+
-

-
+
-
-
-
-
+
+
+


-
-
+
+

-
-
-
-
+
+
+
+
-

-
-
-
-
+
+
+
+




-
-
+
+






-
+


-
-
+
+
-
-
-
-
-
+
+
+
+









-
-
-
+
+
+

-
+
-


-
-
+
+








-
+


-
-









-
-
+
+







-
+


-
+







-
+


-
+






-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+
-

-
-
-
+
+
+
-
-
-
-
+
+
+



-
+













-
+


-
-
+
+
-








-
-
+
+


-
-
+
+

-
+
-

-
+
-

-
-
+
+


-
-
-
+
+
+
-
-
-
-
+
+
+



-
+









-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
+
+
-
-





-
+

-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+




-
+






-
+
-

-
-
+
+





-
+






-
+
-


-
+
-

-
+
-

-
-
+
+
-

-
-
-
+
+
+














-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+



-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
-
-
+
+
-
+
+
+

-
+
+


-
+
-
-
+

-
-
+
+


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
-

-
-
-
+
+
-
-









-
-
-
+
+
+
-
-
-
-
+
+
+





-
-
+
+



-
+
-


-
+


-
+
-

-
-
+
+
















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+

+
+
+
+
+
+

+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+

+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+


+




-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+











-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+











-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+








-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+






-
+
-



-
-
+
+

-
-
+
+







-
-
+
+













-
-
+
+

-
-
+
+
-
-
-
-
+
+
+











-
+
-


-
-
+
+


-
-
+
+










+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
+
+

-
+
-

-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+


-
-
+
+


-
+


-


















-
+
-



-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
+








# If the user did not set CFLAGS, set it now to keep
# the AC_PROG_CC macro from adding "-g -O2".
if test "${CFLAGS+set}" != "set" ; then
    CFLAGS=""
fi










ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}gcc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="gcc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

if test -z "$CC"; then
          if test -n "$ac_tool_prefix"; then
    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
set dummy ${ac_tool_prefix}cc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}cc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


  fi
fi
if test -z "$CC"; then
  # Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
  ac_prog_rejected=no
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
       ac_prog_rejected=yes
       continue
     fi
    ac_cv_prog_CC="cc"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

if test $ac_prog_rejected = yes; then
  # We found a bogon in the path, so make sure we never use it.
  set dummy $ac_cv_prog_CC
  shift
  if test $# != 0; then
    # We chose a different compiler from the bogus one.
    # However, it has the same basename, so the bogon will be chosen
    # first if we set CC to just the basename; use the full file name.
    shift
    ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@"
    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
  fi
fi
fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  for ac_prog in cl.exe
  do
    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


    test -n "$CC" && break
  done
fi
if test -z "$CC"; then
  ac_ct_CC=$CC
  for ac_prog in cl.exe
do
  # Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="$ac_prog"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


  test -n "$ac_ct_CC" && break
done

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
fi

fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args.
set dummy ${ac_tool_prefix}clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "clang", so it can be a program name with args.
set dummy clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

fi


test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "no acceptable C compiler found in \$PATH
See 'config.log' for more details" "$LINENO" 5; }
See \`config.log' for more details" "$LINENO" 5; }

# Provide some information about the compiler.
printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion -version; do
for ac_option in --version -v -V -qversion; do
  { { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    sed '10a\
... rest of stderr output deleted ...
         10q' conftest.err >conftest.er1
    cat conftest.er1 >&5
  fi
  rm -f conftest.er1 conftest.err
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
done

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
# Try to create an executable without -o first, disregard a.out.
# It will help us diagnose broken compilers, and finding out an intuition
# of exeext.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
printf %s "checking whether the C compiler works... " >&6; }
ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
$as_echo_n "checking whether the C compiler works... " >&6; }
ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`

# The possible output files:
ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"

ac_rmfiles=
for ac_file in $ac_files
do
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
  esac
done
rm -f $ac_rmfiles

if { { ac_try="$ac_link_default"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link_default") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'.
# So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no'
  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
# in a Makefile.  We should not override ac_cv_exeext if it was cached,
# so that the user can short-circuit this test for compilers unknown to
# Autoconf.
for ac_file in $ac_files ''
do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
	;;
    [ab].out )
	# We found the default executable, but exeext='' is most
	# certainly right.
	break;;
    *.* )
	if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no;
	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
	then :; else
	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	fi
	# We set ac_cv_exeext here because the later test for it is not
	# safe: cross compilers may not add the suffix if given an '-o'
	# safe: cross compilers may not add the suffix if given an `-o'
	# argument, so we may need to know it at that point already.
	# Even if this section looks crufty: it has the advantage of
	# actually working.
	break;;
    * )
	break;;
  esac
done
test "$ac_cv_exeext" = no && ac_cv_exeext=

else case e in #(
  e) ac_file='' ;;
else
  ac_file=''
esac
fi
if test -z "$ac_file"
if test -z "$ac_file"; then :
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
printf "%s\n" "$as_me: failed program was:" >&5
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "C compiler cannot create executables
See 'config.log' for more details" "$LINENO" 5; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; } ;;
See \`config.log' for more details" "$LINENO" 5; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
printf %s "checking for C compiler default output file name... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
printf "%s\n" "$ac_file" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
$as_echo_n "checking for C compiler default output file name... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
$as_echo "$ac_file" >&6; }
ac_exeext=$ac_cv_exeext

rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
ac_clean_files=$ac_clean_files_save
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
printf %s "checking for suffix of executables... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
$as_echo_n "checking for suffix of executables... " >&6; }
if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  # If both 'conftest.exe' and 'conftest' are 'present' (well, observable)
# catch 'conftest.exe'.  For instance with Cygwin, 'ls conftest' will
# work properly (i.e., refer to 'conftest.exe'), while it won't with
# 'rm'.
  # If both `conftest.exe' and `conftest' are `present' (well, observable)
# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
# work properly (i.e., refer to `conftest.exe'), while it won't with
# `rm'.
for ac_file in conftest.exe conftest conftest.*; do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	  break;;
    * ) break;;
  esac
done
else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of executables: cannot compile and link
See 'config.log' for more details" "$LINENO" 5; } ;;
See \`config.log' for more details" "$LINENO" 5; }
esac
fi
rm -f conftest conftest$ac_cv_exeext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
printf "%s\n" "$ac_cv_exeext" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
$as_echo "$ac_cv_exeext" >&6; }

rm -f conftest.$ac_ext
EXEEXT=$ac_cv_exeext
ac_exeext=$EXEEXT
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdio.h>
int
main (void)
main ()
{
FILE *f = fopen ("conftest.out", "w");
 if (!f)
  return 1;
 return ferror (f) || fclose (f) != 0;

  ;
  return 0;
}
_ACEOF
ac_clean_files="$ac_clean_files conftest.out"
# Check that the compiler produces executables we can run.  If not, either
# the compiler is broken, or we cross compile.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
printf %s "checking whether we are cross compiling... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
$as_echo_n "checking whether we are cross compiling... " >&6; }
if test "$cross_compiling" != yes; then
  { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  if { ac_try='./conftest$ac_cv_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then
    cross_compiling=no
  else
    if test "$cross_compiling" = maybe; then
	cross_compiling=yes
    else
	{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error 77 "cannot run C compiled programs.
If you meant to cross compile, use '--host'.
See 'config.log' for more details" "$LINENO" 5; }
	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run C compiled programs.
If you meant to cross compile, use \`--host'.
See \`config.log' for more details" "$LINENO" 5; }
    fi
  fi
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
printf "%s\n" "$cross_compiling" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
$as_echo "$cross_compiling" >&6; }

rm -f conftest.$ac_ext conftest$ac_cv_exeext \
rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
  conftest.o conftest.obj conftest.out
ac_clean_files=$ac_clean_files_save
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
printf %s "checking for suffix of object files... " >&6; }
if test ${ac_cv_objext+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
$as_echo_n "checking for suffix of object files... " >&6; }
if ${ac_cv_objext+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
rm -f conftest.o conftest.obj
if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
then :
  for ac_file in conftest.o conftest.obj conftest.*; do
  test -f "$ac_file" || continue;
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
       break;;
  esac
done
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of object files: cannot compile
See 'config.log' for more details" "$LINENO" 5; } ;;
See \`config.log' for more details" "$LINENO" 5; }
esac
fi
rm -f conftest.$ac_cv_objext conftest.$ac_ext ;;
rm -f conftest.$ac_cv_objext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
printf "%s\n" "$ac_cv_objext" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
$as_echo "$ac_cv_objext" >&6; }
OBJEXT=$ac_cv_objext
ac_objext=$OBJEXT
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5
printf %s "checking whether the compiler supports GNU C... " >&6; }
if test ${ac_cv_c_compiler_gnu+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
if ${ac_cv_c_compiler_gnu+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{
#ifndef __GNUC__
       choke me
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_compiler_gnu=yes
else case e in #(
  e) ac_compiler_gnu=no ;;
else
  ac_compiler_gnu=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_cv_c_compiler_gnu=$ac_compiler_gnu
 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
$as_echo "$ac_cv_c_compiler_gnu" >&6; }
ac_compiler_gnu=$ac_cv_c_compiler_gnu

if test $ac_compiler_gnu = yes; then
  GCC=yes
else
  GCC=
fi
ac_test_CFLAGS=${CFLAGS+y}
ac_test_CFLAGS=${CFLAGS+set}
ac_save_CFLAGS=$CFLAGS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
printf %s "checking whether $CC accepts -g... " >&6; }
if test ${ac_cv_prog_cc_g+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
$as_echo_n "checking whether $CC accepts -g... " >&6; }
if ${ac_cv_prog_cc_g+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_save_c_werror_flag=$ac_c_werror_flag
  $as_echo_n "(cached) " >&6
else
  ac_save_c_werror_flag=$ac_c_werror_flag
   ac_c_werror_flag=yes
   ac_cv_prog_cc_g=no
   CFLAGS="-g"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_g=yes
else case e in #(
  e) CFLAGS=""
else
  CFLAGS=""
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :

else case e in #(
  e) ac_c_werror_flag=$ac_save_c_werror_flag
else
  ac_c_werror_flag=$ac_save_c_werror_flag
	 CFLAGS="-g"
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_g=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
printf "%s\n" "$ac_cv_prog_cc_g" >&6; }
if test $ac_test_CFLAGS; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
$as_echo "$ac_cv_prog_cc_g" >&6; }
if test "$ac_test_CFLAGS" = set; then
  CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
  if test "$GCC" = yes; then
    CFLAGS="-g -O2"
  else
    CFLAGS="-g"
  fi
else
  if test "$GCC" = yes; then
    CFLAGS="-O2"
  else
    CFLAGS=
  fi
fi
ac_prog_cc_stdc=no
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5
printf %s "checking for $CC option to enable C11 features... " >&6; }
if test ${ac_cv_prog_cc_c11+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
if ${ac_cv_prog_cc_c89+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c11=no
  $as_echo_n "(cached) " >&6
else
  ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c11_program
_ACEOF
for ac_arg in '' -std=gnu11
do
#include <stdarg.h>
#include <stdio.h>
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
struct stat;
  ac_cv_prog_cc_c11=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c11" != "xno" && break
done
rm -f conftest.$ac_ext
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c11" = xno
then :
     char **p;
     int i;
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  return s;
  e) if test "x$ac_cv_prog_cc_c11" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5
printf "%s\n" "$ac_cv_prog_cc_c11" >&6; }
     CC="$CC $ac_cv_prog_cc_c11" ;;
esac
}

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not '\xHH' hex character constants.
   These don't provoke an error unfortunately, instead are silently treated
   as 'x'.  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
   array size at least.  It's necessary to write '\x00'==0 to get something
   that's true only with -std.  */
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11
  ac_prog_cc_stdc=c11 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
int osf4_cc_array ['\x00' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];

int test (int i, double x);
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5
printf %s "checking for $CC option to enable C99 features... " >&6; }
if test ${ac_cv_prog_cc_c99+y}
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
then :
  printf %s "(cached) " >&6
else case e in #(
int argc;
char **argv;
int
  e) ac_cv_prog_cc_c99=no
ac_save_CC=$CC
main ()
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
{
return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
$ac_c_conftest_c99_program
  ;
  return 0;
}
_ACEOF
for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99=
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
  if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_prog_cc_c99=$ac_arg
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c99" != "xno" && break
rm -f core conftest.err conftest.$ac_objext
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
CC=$ac_save_CC
esac
fi

if test "x$ac_cv_prog_cc_c99" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c99" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5
printf "%s\n" "$ac_cv_prog_cc_c99" >&6; }
     CC="$CC $ac_cv_prog_cc_c99" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99
  ac_prog_cc_stdc=c99 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5
printf %s "checking for $CC option to enable C89 features... " >&6; }
if test ${ac_cv_prog_cc_c89+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

$ac_c_conftest_c89_program
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c89" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
# AC_CACHE_VAL
case "x$ac_cv_prog_cc_c89" in
  x)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
$as_echo "none needed" >&6; } ;;
  xno)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
$as_echo "unsupported" >&6; } ;;
else case e in #(
  e) if test "x$ac_cv_prog_cc_c89" = x
  *)
    CC="$CC $ac_cv_prog_cc_c89"
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
printf "%s\n" "$ac_cv_prog_cc_c89" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
     CC="$CC $ac_cv_prog_cc_c89" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89
  ac_prog_cc_stdc=c89 ;;
if test "x$ac_cv_prog_cc_c89" != xno; then :

esac
fi
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
printf %s "checking for inline... " >&6; }
if test ${ac_cv_c_inline+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5
$as_echo_n "checking for inline... " >&6; }
if ${ac_cv_c_inline+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_c_inline=no
  $as_echo_n "(cached) " >&6
else
  ac_cv_c_inline=no
for ac_kw in inline __inline__ __inline; do
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifndef __cplusplus
typedef int foo_t;
static $ac_kw foo_t static_foo (void) {return 0; }
$ac_kw foo_t foo (void) {return 0; }
static $ac_kw foo_t static_foo () {return 0; }
$ac_kw foo_t foo () {return 0; }
#endif

_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_c_inline=$ac_kw
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  test "$ac_cv_c_inline" != no && break
done
 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
printf "%s\n" "$ac_cv_c_inline" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5
$as_echo "$ac_cv_c_inline" >&6; }

case $ac_cv_c_inline in
  inline | yes) ;;
  *)
    case $ac_cv_c_inline in
      no) ac_val=;;
      *) ac_val=$ac_cv_c_inline;;
    esac
    cat >>confdefs.h <<_ACEOF
#ifndef __cplusplus
#define inline $ac_val
#endif
_ACEOF
    ;;
esac

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
$as_echo_n "checking how to run the C preprocessor... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
  CPP=
fi
if test -z "$CPP"; then
  if ${ac_cv_prog_CPP+:} false; then :
  $as_echo_n "(cached) " >&6
else
      # Double quotes because CPP needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
    do
      ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
ac_header= ac_cache=
for ac_item in $ac_header_c_list

else
  # Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
  break
fi

    done
    ac_cv_prog_CPP=$CPP

fi
  CPP=$ac_cv_prog_CPP
else
  ac_cv_prog_CPP=$CPP
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
$as_echo "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
  if test $ac_cache; then
    ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default"
    if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then
      printf "%s\n" "#define $ac_item 1" >> confdefs.h
    fi
    ac_header= ac_cache=
  elif test $ac_header; then
    ac_cache=$ac_item
  else
    ac_header=$ac_item
  fi
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :

else
  # Broken: fails on valid input.
continue
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
ac_preproc_ok=:
break
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :

else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See \`config.log' for more details" "$LINENO" 5; }
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
if ${ac_cv_path_GREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -z "$GREP"; then
  ac_path_GREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in grep ggrep; do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
  # Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
*GNU*)
  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'GREP' >> "conftest.nl"
    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_GREP_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_GREP="$ac_path_GREP"
      ac_path_GREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_GREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_GREP"; then
    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_GREP=$GREP
fi

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
$as_echo "$ac_cv_path_GREP" >&6; }
 GREP="$ac_cv_path_GREP"


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
$as_echo_n "checking for egrep... " >&6; }
if ${ac_cv_path_EGREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
   then ac_cv_path_EGREP="$GREP -E"
   else
     if test -z "$EGREP"; then
  ac_path_EGREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in egrep; do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
  # Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
*GNU*)
  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'EGREP' >> "conftest.nl"
    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP="$ac_path_EGREP"
      ac_path_EGREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP"; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_EGREP=$EGREP
fi

   fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
$as_echo "$ac_cv_path_EGREP" >&6; }
 EGREP="$ac_cv_path_EGREP"


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>

int
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_cv_header_stdc=yes
else
  ac_cv_header_stdc=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes
then :
if test $ac_cv_header_stdc = yes; then
  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <string.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "memchr" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "free" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  if test "$cross_compiling" = yes; then :
  :
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ctype.h>
#include <stdlib.h>
#if ((' ' & 0x0FF) == 0x020)
# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
#else
# define ISLOWER(c) \
		   (('a' <= (c) && (c) <= 'i') \
		     || ('j' <= (c) && (c) <= 'r') \
		     || ('s' <= (c) && (c) <= 'z'))
# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
#endif

#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
int
main ()
{
  int i;
  for (i = 0; i < 256; i++)
    if (XOR (islower (i), ISLOWER (i))
	|| toupper (i) != TOUPPER (i))
      return 2;
  return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :

else
  ac_cv_header_stdc=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
$as_echo "$ac_cv_header_stdc" >&6; }
if test $ac_cv_header_stdc = yes; then

printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h
$as_echo "#define STDC_HEADERS 1" >>confdefs.h

fi


if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
set dummy ${ac_tool_prefix}ar; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_AR+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_AR+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$AR"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$AR"; then
  ac_cv_prog_AR="$AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_AR="${ac_tool_prefix}ar"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
AR=$ac_cv_prog_AR
if test -n "$AR"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
printf "%s\n" "$AR" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
$as_echo "$AR" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_AR"; then
  ac_ct_AR=$AR
  # Extract the first word of "ar", so it can be a program name with args.
set dummy ar; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_AR+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_AR+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_AR"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_AR"; then
  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_AR="ar"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_AR=$ac_cv_prog_ac_ct_AR
if test -n "$ac_ct_AR"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
printf "%s\n" "$ac_ct_AR" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
$as_echo "$ac_ct_AR" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_AR" = x; then
    AR=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    AR=$ac_ct_AR
  fi
else
  AR="$ac_cv_prog_AR"
fi

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RANLIB+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RANLIB+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RANLIB"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
printf "%s\n" "$RANLIB" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
$as_echo "$RANLIB" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RANLIB+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RANLIB"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
printf "%s\n" "$ac_ct_RANLIB" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
$as_echo "$ac_ct_RANLIB" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_RANLIB" = x; then
    RANLIB=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RANLIB=$ac_ct_RANLIB
  fi
else
  RANLIB="$ac_cv_prog_RANLIB"
fi

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args.
set dummy ${ac_tool_prefix}windres; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$RC"; then
  ac_cv_prog_RC="$RC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_RC="${ac_tool_prefix}windres"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
RC=$ac_cv_prog_RC
if test -n "$RC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RC" >&5
printf "%s\n" "$RC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RC" >&5
$as_echo "$RC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RC"; then
  ac_ct_RC=$RC
  # Extract the first word of "windres", so it can be a program name with args.
set dummy windres; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RC+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RC+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RC"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RC"; then
  ac_cv_prog_ac_ct_RC="$ac_ct_RC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RC="windres"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
fi
esac
fi
ac_ct_RC=$ac_cv_prog_ac_ct_RC
if test -n "$ac_ct_RC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5
printf "%s\n" "$ac_ct_RC" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5
$as_echo "$ac_ct_RC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi

  if test "x$ac_ct_RC" = x; then
    RC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RC=$ac_ct_RC
  fi
else
  RC="$ac_cv_prog_RC"
fi


#--------------------------------------------------------------------
# Checks to see if the make program sets the $MAKE variable.
#--------------------------------------------------------------------

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
set x ${MAKE-make}
ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
if eval test \${ac_cv_prog_make_${ac_make}_set+y}
ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat >conftest.make <<\_ACEOF
  $as_echo_n "(cached) " >&6
else
  cat >conftest.make <<\_ACEOF
SHELL = /bin/sh
all:
	@echo '@@@%%%=$(MAKE)=@@@%%%'
_ACEOF
# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
case `${MAKE-make} -f conftest.make 2>/dev/null` in
  *@@@%%%=?*=@@@%%%*)
    eval ac_cv_prog_make_${ac_make}_set=yes;;
  *)
    eval ac_cv_prog_make_${ac_make}_set=no;;
esac
rm -f conftest.make ;;
rm -f conftest.make
esac
fi
if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
  SET_MAKE=
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  SET_MAKE="MAKE=${MAKE-make}"
fi


#--------------------------------------------------------------------
# Determines the correct binary file extension (.o, .obj, .exe etc.)
#--------------------------------------------------------------------




#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
#--------------------------------------------------------------------


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for building with threads" >&5
$as_echo_n "checking for building with threads... " >&6; }
    # Check whether --enable-threads was given.
if test "${enable_threads+set}" = set; then :
  enableval=$enable_threads; tcl_ok=$enableval
else
  tcl_ok=yes
fi


    if test "$tcl_ok" = "yes"; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (default)" >&5
$as_echo "yes (default)" >&6; }
	TCL_THREADS=1
	$as_echo "#define TCL_THREADS 1" >>confdefs.h

	# USE_THREAD_ALLOC tells us to try the special thread-based
	# allocator that significantly reduces lock contention
	$as_echo "#define USE_THREAD_ALLOC 1" >>confdefs.h

    else
	TCL_THREADS=0
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
    fi



#--------------------------------------------------------------------
# The statements below define a collection of symbols related to
# building libtk as a shared library instead of a static library.
#--------------------------------------------------------------------


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
printf %s "checking how to build libraries... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
$as_echo_n "checking how to build libraries... " >&6; }
    # Check whether --enable-shared was given.
if test ${enable_shared+y}
if test "${enable_shared+set}" = set; then :
then :
  enableval=$enable_shared; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
esac
fi
else
  tcl_ok=yes
fi


    if test "${enable_shared+set}" = set; then
	enableval="$enable_shared"
	tcl_ok=$enableval
    else
	tcl_ok=yes
    fi

    if test "$tcl_ok" = "yes" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared" >&5
printf "%s\n" "shared" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: shared" >&5
$as_echo "shared" >&6; }
	SHARED_BUILD=1
    else
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5
printf "%s\n" "static" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: static" >&5
$as_echo "static" >&6; }
	SHARED_BUILD=0

printf "%s\n" "#define STATIC_BUILD 1" >>confdefs.h
$as_echo "#define STATIC_BUILD 1" >>confdefs.h

    fi



#--------------------------------------------------------------------
# Locate and source the tclConfig.sh file.
#--------------------------------------------------------------------


    #
    # Ok, lets find the tcl configuration
    # First, look for one uninstalled.
    # the alternative search directory is invoked by --with-tcl
    #

    if test x"${no_tcl}" = x ; then
	# we reset no_tcl in case something fails here
	no_tcl=true

# Check whether --with-tcl was given.
if test ${with_tcl+y}
if test "${with_tcl+set}" = set; then :
then :
  withval=$with_tcl; with_tclconfig="${withval}"
fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
printf %s "checking for Tcl configuration... " >&6; }
	if test ${ac_cv_c_tclconfig+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
$as_echo_n "checking for Tcl configuration... " >&6; }
	if ${ac_cv_c_tclconfig+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else


	    # First check to see if --with-tcl was specified.
	    if test x"${with_tclconfig}" != x ; then
		case "${with_tclconfig}" in
		    */tclConfig.sh )
			if test -f "${with_tclconfig}"; then
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
printf "%s\n" "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
$as_echo "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    with_tclconfig="`echo "${with_tclconfig}" | sed 's!/tclConfig\.sh$!!'`"
			fi ;;
		esac
		if test -f "${with_tclconfig}/tclConfig.sh" ; then
		    ac_cv_c_tclconfig="`(cd "${with_tclconfig}"; pwd)`"
		else
		    as_fn_error $? "${with_tclconfig} directory doesn't contain tclConfig.sh" "$LINENO" 5
4023
4024
4025
4026
4027
4028
4029
4030

4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042


4043
4044
4045
4046
4047
4048


4049
4050
4051
4052


4053
4054
4055
4056


4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073








4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093

4094
4095
4096
4097


4098




4099
4100
4101
4102
4103
4104
4105
4106

















4107
4108
4109
4110
4111
4112


4113
4114

4115
4116
4117
4118


4119
4120
4121
4122
4123





























4124
4125
4126
4127
4128

4129
4130
4131
4132
4133
4134
4135



4136
4137
4138
4139



4140
4141
4142
4143
4144
4145
4146
4147

4148
4149
4150
4151
4152

4153
4154

4155
4156
4157
4158
4159
4160
4161
4162

4163
4164
4165
4166
4167
4168


4169
4170
4171


4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222

4223
4224
4225
4226
4227
4228
4229



4230
4231
4232
4233



4234
4235
4236
4237
4238
4239
4240
4241

4242
4243
4244
4245
4246
4247
4248

4249
4250
4251
4252


4253
4254
4255
4256


4257
4258
4259
4260


4261
4262
4263
4264
4265

4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279

4280
4281
4282
4283
4284
4285
4286
3856
3857
3858
3859
3860
3861
3862

3863

3864
3865
3866
3867
3868
3869
3870
3871
3872


3873
3874
3875
3876
3877
3878


3879
3880
3881
3882


3883
3884
3885
3886


3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932

3933

3934


3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970


3971
3972
3973

3974

3975


3976
3977

3978
3979


3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012

4013
4014
4015
4016
4017



4018
4019
4020




4021
4022
4023
4024
4025
4026
4027
4028
4029


4030



4031

4032
4033

4034
4035
4036
4037
4038
4039
4040
4041

4042

4043
4044
4045


4046
4047
4048


4049
4050











































4051
4052
4053
4054
4055
4056
4057

4058
4059
4060
4061
4062



4063
4064
4065




4066
4067
4068
4069
4070
4071
4072
4073
4074
4075

4076
4077
4078
4079
4080
4081
4082

4083

4084


4085
4086

4087


4088
4089

4090


4091
4092
4093
4094
4095
4096

4097
4098
4099
4100
4101
4102







4103

4104
4105
4106
4107
4108
4109
4110
4111







-
+
-









-
-
+
+




-
-
+
+


-
-
+
+


-
-
+
+

















+
+
+
+
+
+
+
+



















-
+
-

-
-
+
+

+
+
+
+








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
+

-
+
-

-
-
+
+
-


-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+




-
-
-
+
+
+
-
-
-
-
+
+
+






-
-
+
-
-
-

-
+

-
+







-
+
-



-
-
+
+

-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
+




-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+




-
+





-
-
-
-
-
-
-

-
+







			`ls -dr ${srcdir}/../tcl[8-9].[0-9]* 2>/dev/null` ; do
		    if test -f "$i/win/tclConfig.sh" ; then
		    ac_cv_c_tclconfig="`(cd $i/win; pwd)`"
		    break
		fi
		done
	    fi
	 ;;

esac
fi


	if test x"${ac_cv_c_tclconfig}" = x ; then
	    TCL_BIN_DIR="# no Tcl configs found"
	    as_fn_error $? "Can't find Tcl configuration definitions. Use --with-tcl to specify a directory containing tclConfig.sh" "$LINENO" 5
	else
	    no_tcl=
	    TCL_BIN_DIR="${ac_cv_c_tclconfig}"
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	fi
    fi


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf %s "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo_n "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }

    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: loading" >&5
printf "%s\n" "loading" >&6; }
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: loading" >&5
$as_echo "loading" >&6; }
	. "${TCL_BIN_DIR}/tclConfig.sh"
    else
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
    fi

    #
    # If the TCL_BIN_DIR is the build directory (not the install directory),
    # then set the common variable name to the value of the build variables.
    # For example, the variable TCL_LIB_SPEC will be set to the value
    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
    # installed and uninstalled version of Tcl.
    #

    if test -f $TCL_BIN_DIR/Makefile ; then
        TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
        TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
        TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
    fi

    #
    # eval is required to do the TCL_DBGX substitution
    #

    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""

    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
















if test "${TCL_MAJOR_VERSION}" -lt 9 ; then
if test "${TCL_MAJOR_VERSION}" != "${TK_MAJOR_VERSION}"; then
if test "${TCL_MINOR_VERSION}" -lt 7; then
    as_fn_error $? "${TCL_BIN_DIR}/tclConfig.sh is for Tcl ${TCL_VERSION}.
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.7+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.7 or better." "$LINENO" 5
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.6+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.6 or better." "$LINENO" 5
fi
if test "${TCL_MINOR_VERSION}" -lt 6; then
    as_fn_error $? "${TCL_BIN_DIR}/tclConfig.sh is for Tcl ${TCL_VERSION}.
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.6+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.6 or better." "$LINENO" 5
fi

#--------------------------------------------------------------------
# The statements below define a collection of compile flags.  This
# macro depends on the value of SHARED_BUILD, and should be called
# after SC_ENABLE_SHARED checks the configure switches.
#--------------------------------------------------------------------

# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
		  inttypes.h stdint.h unistd.h
do :
  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF

fi

done




    # Step 0: Enable 64 bit support?

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
printf %s "checking if 64bit support is requested... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
$as_echo_n "checking if 64bit support is requested... " >&6; }
    # Check whether --enable-64bit was given.
if test ${enable_64bit+y}
if test "${enable_64bit+set}" = set; then :
then :
  enableval=$enable_64bit; do64bit=$enableval
else case e in #(
  e) do64bit=no ;;
else
  do64bit=no
esac
fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
printf "%s\n" "$do64bit" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
$as_echo "$do64bit" >&6; }

    # Cross-compiling options for Windows/CE builds

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if Windows/CE build is requested" >&5
$as_echo_n "checking if Windows/CE build is requested... " >&6; }
    # Check whether --enable-wince was given.
if test "${enable_wince+set}" = set; then :
  enableval=$enable_wince; doWince=$enableval
else
  doWince=no
fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doWince" >&5
$as_echo "$doWince" >&6; }

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Windows/CE celib directory" >&5
$as_echo_n "checking for Windows/CE celib directory... " >&6; }

# Check whether --with-celib was given.
if test "${with_celib+set}" = set; then :
  withval=$with_celib; CELIB_DIR=$withval
else
  CELIB_DIR=NO_CELIB
fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CELIB_DIR" >&5
$as_echo "$CELIB_DIR" >&6; }

    # Set some defaults (may get changed below)
    EXTRA_CFLAGS=""

printf "%s\n" "#define MODULE_SCOPE extern" >>confdefs.h
$as_echo "#define MODULE_SCOPE extern" >>confdefs.h


    # Extract the first word of "cygpath", so it can be a program name with args.
set dummy cygpath; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CYGPATH+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CYGPATH+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CYGPATH"; then
  $as_echo_n "(cached) " >&6
else
  if test -n "$CYGPATH"; then
  ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_CYGPATH="cygpath -m"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

  test -z "$ac_cv_prog_CYGPATH" && ac_cv_prog_CYGPATH="echo"
fi ;;
fi
esac
fi
CYGPATH=$ac_cv_prog_CYGPATH
if test -n "$CYGPATH"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
printf "%s\n" "$CYGPATH" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
$as_echo "$CYGPATH" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


    # Extract the first word of "wine", so it can be a program name with args.
set dummy wine; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_WINE+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$WINE"; then
  ac_cv_prog_WINE="$WINE" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_WINE="wine"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
WINE=$ac_cv_prog_WINE
if test -n "$WINE"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $WINE" >&5
printf "%s\n" "$WINE" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi



    SHLIB_SUFFIX=".dll"

    # MACHINE is IX86 for LINK, but this is used by the manifest,
    # which requires x86|amd64|arm64|ia64.
    # which requires x86|amd64|ia64.
    MACHINE="X86"

    if test "$GCC" = "yes"; then

      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cross-compile version of gcc" >&5
printf %s "checking for cross-compile version of gcc... " >&6; }
if test ${ac_cv_cross+y}
      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cross-compile version of gcc" >&5
$as_echo_n "checking for cross-compile version of gcc... " >&6; }
if ${ac_cv_cross+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	    #ifndef _WIN32
		#error cross-compiler
	    #endif

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_cross=no
else case e in #(
  e) ac_cv_cross=yes ;;
else
  ac_cv_cross=yes
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
       ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5
printf "%s\n" "$ac_cv_cross" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5
$as_echo "$ac_cv_cross" >&6; }

      if test "$ac_cv_cross" = "yes"; then
	case "$do64bit" in
	    amd64|x64|yes)
		CC="x86_64-w64-mingw32-${CC}"
		CC="x86_64-w64-mingw32-gcc"
		LD="x86_64-w64-mingw32-ld"
		AR="x86_64-w64-mingw32-ar"
		RANLIB="x86_64-w64-mingw32-ranlib"
		RC="x86_64-w64-mingw32-windres"
	    ;;
	    arm64|aarch64)
		CC="aarch64-w64-mingw32-${CC}"
		LD="aarch64-w64-mingw32-ld"
		AR="aarch64-w64-mingw32-ar"
		RANLIB="aarch64-w64-mingw32-ranlib"
		RC="aarch64-w64-mingw32-windres"
	    ;;
	    *)
		CC="i686-w64-mingw32-${CC}"
		CC="i686-w64-mingw32-gcc"
		LD="i686-w64-mingw32-ld"
		AR="i686-w64-mingw32-ar"
		RANLIB="i686-w64-mingw32-ranlib"
		RC="i686-w64-mingw32-windres"
	    ;;
	esac
      fi
4295
4296
4297
4298
4299
4300
4301
4302
4303


4304
4305
4306
4307
4308
4309

4310
4311
4312


4313
4314
4315


4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335



4336
4337
4338
4339



4340
4341
4342
4343
4344
4345
4346
4347

4348
4349
4350
4351
4352
4353
4354

4355
4356
4357
4358


4359
4360
4361
4362


4363
4364
4365
4366


4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377



4378
4379
4380
4381



4382
4383
4384
4385
4386
4387
4388

4389
4390
4391
4392
4393
4394
4395

4396
4397
4398
4399
4400
4401
4402
4403

4404
4405
4406
4407
4408
4409
4410
4411

4412
4413
4414


4415
4416
4417

4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436

4437
4438
4439
4440
4441
4442
4443

4444
4445
4446
4447


4448
4449
4450

4451
4452

4453
4454
4455
4456


4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487

4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574


4575
4576
4577
4578
4579
4580

4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596


4597
4598
4599

4600
4601
4602
4603


4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614

4615
4616
4617
4618
4619
4620
4621
4622

4623
4624
4625
4626
4627



4628
4629
4630
4631
4632
4633
4634

4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4120
4121
4122
4123
4124
4125
4126


4127
4128
4129
4130
4131
4132
4133

4134
4135


4136
4137
4138


4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157



4158
4159
4160




4161
4162
4163
4164
4165
4166
4167
4168
4169
4170

4171
4172
4173
4174
4175
4176
4177

4178

4179


4180
4181

4182


4183
4184

4185


4186
4187
4188
4189
4190



4191
4192



4193
4194
4195




4196
4197
4198
4199
4200
4201
4202
4203
4204

4205
4206
4207
4208
4209
4210
4211

4212
4213
4214
4215
4216
4217
4218
4219

4220
4221
4222
4223
4224
4225
4226


4227
4228


4229
4230
4231
4232

4233

4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250

4251
4252
4253
4254
4255
4256
4257

4258

4259


4260
4261

4262

4263
4264

4265

4266


4267
4268
4269
4270
4271
4272
4273
4274

























4275






















4276
































































4277
4278
4279
4280
4281
4282
4283

4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298


4299
4300
4301
4302

4303
4304
4305


4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317

4318
4319
4320
4321
4322
4323
4324
4325

4326
4327
4328



4329
4330
4331
4332
4333
4334
4335
4336
4337

4338
4339
4340
4341









4342
4343
4344
4345
4346
4347
4348







-
-
+
+





-
+

-
-
+
+

-
-
+
+

















-
-
-
+
+
+
-
-
-
-
+
+
+







-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+



-
-
-


-
-
-
+
+
+
-
-
-
-
+
+
+






-
+






-
+







-
+






-
-
+

-
-
+
+


-
+
-

















-
+






-
+
-

-
-
+
+
-

-
+

-
+
-

-
-
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+





-
+














-
-
+
+


-
+


-
-
+
+










-
+







-
+


-
-
-
+
+
+






-
+



-
-
-
-
-
-
-
-
-








    if test "$GCC" = "yes" && test "$CYGPATH" != "echo" ; then
	conftest=/tmp/conftest.rc
	echo "STRINGTABLE BEGIN" > $conftest
	echo "101 \"name\"" >> $conftest
	echo "END" >> $conftest

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Windows native path bug in windres" >&5
printf %s "checking for Windows native path bug in windres... " >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Windows native path bug in windres" >&5
$as_echo_n "checking for Windows native path bug in windres... " >&6; }
	cyg_conftest=`$CYGPATH $conftest`
	if { ac_try='$RC -o conftest.res.o $cyg_conftest'
  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
  (eval $ac_try) 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; } ; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
	else
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	    CYGPATH=echo
	fi
	conftest=
	cyg_conftest=
    fi

    if test "$CYGPATH" = "echo"; then
        DEPARG='"$<"'
    else
        DEPARG='"$(shell $(CYGPATH) $<)"'
    fi

    # set various compiler flags depending on whether we are using gcc or cl

    if test "${GCC}" = "yes" ; then
	extra_cflags="-pipe"
	extra_ldflags="-pipe -static-libgcc"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for mingw32 version of gcc" >&5
printf %s "checking for mingw32 version of gcc... " >&6; }
if test ${ac_cv_win32+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mingw32 version of gcc" >&5
$as_echo_n "checking for mingw32 version of gcc... " >&6; }
if ${ac_cv_win32+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		#ifdef _WIN32
		    #error win32
		#endif

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  ac_cv_win32=no
else case e in #(
  e) ac_cv_win32=yes ;;
else
  ac_cv_win32=yes
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_win32" >&5
printf "%s\n" "$ac_cv_win32" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_win32" >&5
$as_echo "$ac_cv_win32" >&6; }
	if test "$ac_cv_win32" != "yes"; then
	    as_fn_error $? "${CC} cannot produce win32 executables." "$LINENO" 5
	fi
	if test "$do64bit" != "arm64"; then
	    extra_cflags="$extra_cflags -DHAVE_CPUID=1"
	fi

	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -mwindows -municode -Dmain=xxmain"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working -municode linker flag" >&5
printf %s "checking for working -municode linker flag... " >&6; }
if test ${ac_cv_municode+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working -municode linker flag" >&5
$as_echo_n "checking for working -municode linker flag... " >&6; }
if ${ac_cv_municode+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext
  rm -f conftest.$ac_objext conftest$ac_exeext
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest$ac_exeext && {
	 test "$cross_compiling" = yes ||
	 test -x conftest$ac_exeext
       }
then :
       }; then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1 ;;
	ac_retval=1
esac
fi
  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  # interfere with the next link command; also delete a directory that is
  # left behind by Apple's compiler.  We do this before executing the actions.
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_link
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	#include <windows.h>
	int APIENTRY wWinMain(HINSTANCE a, HINSTANCE b, LPWSTR c, int d) {return 0;}

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  ac_cv_municode=yes
else case e in #(
  e) ac_cv_municode=no ;;
else
  ac_cv_municode=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
	 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_municode" >&5
printf "%s\n" "$ac_cv_municode" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_municode" >&5
$as_echo "$ac_cv_municode" >&6; }
	CFLAGS=$hold_cflags
	if test "$ac_cv_municode" = "yes" ; then
	    extra_ldflags="$extra_ldflags -municode"
	else
	    extra_cflags="$extra_cflags -DTCL_BROKEN_MAINARGS"
	fi
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fno-lto"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working -fno-lto" >&5
printf %s "checking for working -fno-lto... " >&6; }
if test ${ac_cv_nolto+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_nolto=yes
else case e in #(
  e) ac_cv_nolto=no ;;
esac
fi
    fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_nolto" >&5
printf "%s\n" "$ac_cv_nolto" >&6; }
	CFLAGS=$hold_cflags
	if test "$ac_cv_nolto" = "yes" ; then
	    CFLAGS_NOLTO="-fno-lto"
	else
	    CFLAGS_NOLTO=""
	fi
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -finput-charset" >&5
printf %s "checking if the compiler understands -finput-charset... " >&6; }
if test ${tcl_cv_cc_input_charset+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -finput-charset=UTF-8"
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_cc_input_charset=yes
else case e in #(
  e) tcl_cv_cc_input_charset=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	    CFLAGS=$hold_cflags ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_input_charset" >&5
printf "%s\n" "$tcl_cv_cc_input_charset" >&6; }
	if test $tcl_cv_cc_input_charset = yes; then
	    extra_cflags="$extra_cflags -finput-charset=UTF-8"
	fi
    fi

    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Wl,--enable-auto-image-base"
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working --enable-auto-image-base" >&5
printf %s "checking for working --enable-auto-image-base... " >&6; }
if test ${ac_cv_enable_auto_image_base+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_enable_auto_image_base=yes
else case e in #(
  e) ac_cv_enable_auto_image_base=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
     ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_enable_auto_image_base" >&5
printf "%s\n" "$ac_cv_enable_auto_image_base" >&6; }
    CFLAGS=$hold_cflags
    if test "$ac_cv_enable_auto_image_base" == "yes" ; then
	extra_ldflags="$extra_ldflags -Wl,--enable-auto-image-base"
    fi

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking compiler flags" >&5
printf %s "checking compiler flags... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler flags" >&5
$as_echo_n "checking compiler flags... " >&6; }
    if test "${GCC}" = "yes" ; then
	SHLIB_LD=""
	SHLIB_LD_LIBS='${LIBS}'
	LIBS="-lnetapi32 -lkernel32 -luser32 -ladvapi32 -luserenv -lws2_32"
	# mingw needs to link ole32 and oleaut32 for [send], but MSVC doesn't
	LIBS_GUI="-lgdi32 -lcomdlg32 -limm32 -lcomctl32 -lshell32 -luuid -lole32 -loleaut32 -lwinspool"
	LIBS_GUI="-lgdi32 -lcomdlg32 -limm32 -lcomctl32 -lshell32 -luuid -lole32 -loleaut32"
	STLIB_LD='${AR} cr'
	RC_OUT=-o
	RC_TYPE=
	RC_INCLUDE=--include
	RC_DEFINE=--define
	RES=res.o
	MAKE_LIB="\${STLIB_LD} \$@"
	MAKE_STUB_LIB="\${STLIB_LD} \$@"
	POST_MAKE_LIB="\${RANLIB} \$@"
	MAKE_EXE="\${CC} -o \$@"
	LIBPREFIX="lib"

	if test "${SHARED_BUILD}" = "0" ; then
	    # static
            { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: using static flags" >&5
printf "%s\n" "using static flags" >&6; }
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: using static flags" >&5
$as_echo "using static flags" >&6; }
	    runtime=
	    LIBRARIES="\${STATIC_LIBRARIES}"
	    EXESUFFIX="s.exe"
	    EXESUFFIX="s\${DBGX}.exe"
	else
	    # dynamic
            { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: using shared flags" >&5
printf "%s\n" "using shared flags" >&6; }
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: using shared flags" >&5
$as_echo "using shared flags" >&6; }

	    # ad-hoc check to see if CC supports -shared.
	    if "${CC}" -shared 2>&1 | egrep ': -shared not supported' >/dev/null; then
		as_fn_error $? "${CC} does not support the -shared option.
                You will need to upgrade to a newer version of the toolchain." "$LINENO" 5
	    fi

	    runtime=
	    # Add SHLIB_LD_LIBS to the Make rule, not here.

	    EXESUFFIX=".exe"
	    EXESUFFIX="\${DBGX}.exe"
	    LIBRARIES="\${SHARED_LIBRARIES}"
	fi
	# Link with gcc since ld does not link to default libs like
	# -luser32 and -lmsvcrt by default.
	SHLIB_LD='${CC} -shared'
	SHLIB_LD_LIBS='${LIBS}'
	MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -o \$@ ${extra_ldflags} \
	    -Wl,--out-implib,\$(patsubst %.dll,lib%.dll.a,\$@)"
	    -Wl,--out-implib,\$(patsubst %.dll,lib%.a,\$@)"
	# DLLSUFFIX is separate because it is the building block for
	# users of tclConfig.sh that may build shared or static.
	DLLSUFFIX=".dll"
	LIBSUFFIX=".a"
	LIBFLAGSUFFIX=""
	DLLSUFFIX="\${DBGX}.dll"
	LIBSUFFIX="\${DBGX}.a"
	LIBFLAGSUFFIX="\${DBGX}"
	SHLIB_SUFFIX=.dll

	EXTRA_CFLAGS="${extra_cflags}"

	CFLAGS_DEBUG=-g
	CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
	CFLAGS_WARNING="-Wall -Wextra -Wshadow -Wundef -Wwrite-strings -Wpointer-arith"
	CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement"
	LDFLAGS_DEBUG=
	LDFLAGS_OPTIMIZE=

	case "${CC}" in
	    *++)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wno-format"
		;;
	    *)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wc++-compat -fextended-identifiers"
		;;
	esac

	# Specify the CC output file names based on the target name
	CC_OBJNAME="-o \$@"
	CC_EXENAME="-o \$@"

	# Specify linker flags depending on the type of app being
	# built -- Console vs. Window.
	#
4664
4665
4666
4667
4668
4669
4670
4671
4672


4673
4674
4675
4676
4677
4678
4679
4680
4681
4682


4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693

4694
4695
4696
4697
4698
4699
4700

4701
4702
4703
4704
4705



4706
4707
4708

4709
4710
4711
4712
4713




4714
4715
4716
4717
4718
4719
4720
4721


4722
4723
4724

4725
4726
4727
4728


4729
4730
4731
4732

4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746



4747



4748





4749
4750
4751
4752
4753
4754

4755
4756
4757

4758
4759




4760
4761


4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774







4775








4776

4777
4778
4779



4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793



































































































4794


4795
4796
4797
4798
4799
4800
4801
4359
4360
4361
4362
4363
4364
4365


4366
4367





4368
4369
4370


4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382

4383
4384
4385
4386
4387
4388
4389

4390

4391



4392
4393
4394

4395

4396
4397




4398
4399
4400
4401
4402
4403
4404
4405
4406
4407


4408
4409
4410
4411

4412
4413
4414


4415
4416
4417
4418
4419

4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431



4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447



4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458


4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480

4481
4482
4483
4484
4485
4486
4487
4488
4489
4490



4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606

4607
4608
4609
4610
4611
4612
4613
4614
4615







-
-
+
+
-
-
-
-
-



-
-
+
+










-
+






-
+
-

-
-
-
+
+
+
-

-
+

-
-
-
-
+
+
+
+






-
-
+
+


-
+


-
-
+
+



-
+











-
-
-
+
+
+

+
+
+

+
+
+
+
+



-
-
-
+



+


+
+
+
+
-
-
+
+













+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+

+
-
-
-
+
+
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+







	#LDFLAGS_WINDOW="-mwindows -e _WinMain@16 ${extra_ldflags}"
	LDFLAGS_CONSOLE="-mconsole ${extra_ldflags}"
	LDFLAGS_WINDOW="-mwindows ${extra_ldflags}"

	case "$do64bit" in
	    amd64|x64|yes)
		MACHINE="AMD64" ; # assume AMD64 as default 64-bit build
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
printf "%s\n" "   Using 64-bit $MACHINE mode" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
$as_echo "   Using 64-bit $MACHINE mode" >&6; }
		;;
	    arm64|aarch64)
		MACHINE="ARM64"
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:    Using ARM64 $MACHINE mode" >&5
printf "%s\n" "   Using ARM64 $MACHINE mode" >&6; }
		;;
	    ia64)
		MACHINE="IA64"
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:    Using IA64 $MACHINE mode" >&5
printf "%s\n" "   Using IA64 $MACHINE mode" >&6; }
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
$as_echo "   Using 64-bit $MACHINE mode" >&6; }
		;;
	    *)
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		    #ifndef _WIN64
			#error 32-bit
		    #endif

int
main (void)
main ()
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_win_64bit=yes
else case e in #(
  e) tcl_win_64bit=no
		 ;;
else
  tcl_win_64bit=no

esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
		if test "$tcl_win_64bit" = "yes" ; then
		    do64bit=amd64
		    MACHINE="AMD64"
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
printf "%s\n" "   Using 64-bit $MACHINE mode" >&6; }
			do64bit=amd64
			MACHINE="AMD64"
			{ $as_echo "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
$as_echo "   Using 64-bit $MACHINE mode" >&6; }
		fi
		;;
	esac
    else
	if test "${SHARED_BUILD}" = "0" ; then
	    # static
            { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: using static flags" >&5
printf "%s\n" "using static flags" >&6; }
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: using static flags" >&5
$as_echo "using static flags" >&6; }
	    runtime=-MT
	    LIBRARIES="\${STATIC_LIBRARIES}"
	    EXESUFFIX="s.exe"
	    EXESUFFIX="s\${DBGX}.exe"
	else
	    # dynamic
            { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: using shared flags" >&5
printf "%s\n" "using shared flags" >&6; }
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: using shared flags" >&5
$as_echo "using shared flags" >&6; }
	    runtime=-MD
	    # Add SHLIB_LD_LIBS to the Make rule, not here.
	    LIBRARIES="\${SHARED_LIBRARIES}"
	    EXESUFFIX=".exe"
	    EXESUFFIX="\${DBGX}.exe"
	    case "x`echo \${VisualStudioVersion}`" in
		x1[4-9]*)
		    lflags="${lflags} -nodefaultlib:libucrt.lib"
		    ;;
		*)
		    ;;
	    esac
	fi
	MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -out:\$@"
	# DLLSUFFIX is separate because it is the building block for
	# users of tclConfig.sh that may build shared or static.
	DLLSUFFIX=".dll"
	LIBSUFFIX=".lib"
	LIBFLAGSUFFIX=""
	DLLSUFFIX="\${DBGX}.dll"
	LIBSUFFIX="\${DBGX}.lib"
	LIBFLAGSUFFIX="\${DBGX}"

	# This is a 2-stage check to make sure we have the 64-bit SDK
	# We have to know where the SDK is installed.
	# This magic is based on MS Platform SDK for Win2003 SP1 - hobbs
	if test "$do64bit" != "no" ; then
	    if test "x${MSSDK}x" = "xx" ; then
		MSSDK="C:/Progra~1/Microsoft Platform SDK"
	    fi
	    MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'`
	    PATH64=""
	    case "$do64bit" in
		amd64|x64|yes)
		    MACHINE="AMD64" ; # assume AMD64 as default 64-bit build
		    ;;
		arm64|aarch64)
		    MACHINE="ARM64"
		    PATH64="${MSSDK}/Bin/Win64/x86/AMD64"
		    ;;
		ia64)
		    MACHINE="IA64"
		    PATH64="${MSSDK}/Bin/Win64"
		    ;;
	    esac
	    if test ! -d "${PATH64}" ; then
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find 64-bit $MACHINE SDK" >&5
$as_echo "$as_me: WARNING: Could not find 64-bit $MACHINE SDK" >&2;}
	    fi
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
printf "%s\n" "   Using 64-bit $MACHINE mode" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result:    Using 64-bit $MACHINE mode" >&5
$as_echo "   Using 64-bit $MACHINE mode" >&6; }
	fi

	LIBS="netapi32.lib kernel32.lib user32.lib advapi32.lib userenv.lib ws2_32.lib"

	case "x`echo \${VisualStudioVersion}`" in
		x1[4-9]*)
		    LIBS="$LIBS ucrt.lib"
		    ;;
		*)
		    ;;
	esac

	if test "$do64bit" != "no" ; then
	    # The space-based-path will work for the Makefile, but will
	    # not work if AC_TRY_COMPILE is called.  TEA has the
	    # TEA_PATH_NOSPACE to avoid this issue.
	    # Check if _WIN64 is already recognized, and if so we don't
	    # need to modify CC.
	    ac_fn_c_check_decl "$LINENO" "_WIN64" "ac_cv_have_decl__WIN64" "$ac_includes_default"
if test "x$ac_cv_have_decl__WIN64" = xyes; then :
	    RC="rc"

else
  CC="\"${PATH64}/cl.exe\" -I\"${MSSDK}/Include\" \
			 -I\"${MSSDK}/Include/crt\" \
			 -I\"${MSSDK}/Include/crt/sys\""
fi

	    RC="\"${MSSDK}/bin/rc.exe\""
	    CFLAGS_DEBUG="-nologo -Zi -Od ${runtime}d"
	    # Do not use -O2 for Win64 - this has proved buggy in code gen.
	    CFLAGS_OPTIMIZE="-nologo -O2 ${runtime}"
	    lflags="${lflags} -nologo -MACHINE:${MACHINE}"
	    LINKBIN="link"
	    CFLAGS_OPTIMIZE="-nologo -O1 ${runtime}"
	    lflags="${lflags} -nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\""
	    LINKBIN="\"${PATH64}/link.exe\""
	    # Avoid 'unresolved external symbol __security_cookie' errors.
	    # c.f. http://support.microsoft.com/?id=894573
	    LIBS="$LIBS bufferoverflowU.lib"
	else
	    RC="rc"
	    # -Od - no optimization
	    # -WX - warnings as errors
	    CFLAGS_DEBUG="-nologo -Z7 -Od -WX ${runtime}d"
	    # -O2 - create fast code (/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy)
	    CFLAGS_OPTIMIZE="-nologo -O2 ${runtime}"
	    lflags="${lflags} -nologo"
	    LINKBIN="link"
	fi

	if test "$doWince" != "no" ; then
	    # Set defaults for common evc4/PPC2003 setup
	    # Currently Tcl requires 300+, possibly 420+ for sockets
	    CEVERSION=420; 		# could be 211 300 301 400 420 ...
	    TARGETCPU=ARMV4;	# could be ARMV4 ARM MIPS SH3 X86 ...
	    ARCH=ARM;		# could be ARM MIPS X86EM ...
	    PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002"
	    if test "$doWince" != "yes"; then
		# If !yes then the user specified something
		# Reset ARCH to allow user to skip specifying it
		ARCH=
		eval `echo $doWince | awk -F "," '{ \
	if (length($1)) { printf "CEVERSION=\"%s\"\n", $1; \
	if ($1 < 400)	  { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \
	if (length($2)) { printf "TARGETCPU=\"%s\"\n", toupper($2) }; \
	if (length($3)) { printf "ARCH=\"%s\"\n", toupper($3) }; \
	if (length($4)) { printf "PLATFORM=\"%s\"\n", $4 }; \
		}'`
		if test "x${ARCH}" = "x" ; then
		    ARCH=$TARGETCPU;
		fi
	    fi
	    OSVERSION=WCE$CEVERSION;
	    if test "x${WCEROOT}" = "x" ; then
		WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0"
		if test ! -d "${WCEROOT}" ; then
		    WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
		fi
	    fi
	    if test "x${SDKROOT}" = "x" ; then
		SDKROOT="C:/Program Files/Windows CE Tools"
		if test ! -d "${SDKROOT}" ; then
		    SDKROOT="C:/Windows CE Tools"
		fi
	    fi
	    # The space-based-path will work for the Makefile, but will
	    # not work if AC_TRY_COMPILE is called.
	    WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'`
	    SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'`
	    CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'`
	    if test ! -d "${CELIB_DIR}/inc"; then
		as_fn_error $? "Invalid celib directory \"${CELIB_DIR}\"" "$LINENO" 5
	    fi
	    if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"\
		-o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
		as_fn_error $? "could not find PocketPC SDK or target compiler to enable WinCE mode $CEVERSION,$TARGETCPU,$ARCH,$PLATFORM" "$LINENO" 5
	    else
		CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include"
		if test -d "${CEINCLUDE}/${TARGETCPU}" ; then
		    CEINCLUDE="${CEINCLUDE}/${TARGETCPU}"
		fi
		CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"
	    fi
	fi

	if test "$doWince" != "no" ; then
	    CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin"
	    if test "${TARGETCPU}" = "X86"; then
		CC="${CEBINROOT}/cl.exe"
	    else
		CC="${CEBINROOT}/cl${ARCH}.exe"
	    fi
	    CC="\"${CC}\" -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
	    RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\""
	    arch=`echo ${ARCH} | awk '{print tolower($0)}'`
	    defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _DLL _WINDOWS"
	    for i in $defs ; do
		cat >>confdefs.h <<_ACEOF
#define $i 1
_ACEOF

	    done
#	    if test "${ARCH}" = "X86EM"; then
#		AC_DEFINE_UNQUOTED(_WIN32_WCE_EMULATION)
#	    fi
	    cat >>confdefs.h <<_ACEOF
#define _WIN32_WCE $CEVERSION
_ACEOF

	    cat >>confdefs.h <<_ACEOF
#define UNDER_CE $CEVERSION
_ACEOF

	    CFLAGS_DEBUG="-nologo -Zi -Od"
	    CFLAGS_OPTIMIZE="-nologo -O2"
	    lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'`
	    lflags="-nodefaultlib -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo"
	    LINKBIN="\"${CEBINROOT}/link.exe\""

	    if test "${CEVERSION}" -lt 400 ; then
		LIBS="coredll.lib corelibc.lib winsock.lib"
	    else
		LIBS="coredll.lib corelibc.lib ws2.lib"
	    fi
	    # celib currently stuck at wce300 status
	    #LIBS="$LIBS \${CELIB_DIR}/wince-${ARCH}-pocket-${OSVERSION}-release/celib.lib"
	    LIBS="$LIBS \"\${CELIB_DIR}/wince-${ARCH}-pocket-wce300-release/celib.lib\""
	    LIBS_GUI="commctrl.lib commdlg.lib"
	else
	LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib uuid.lib winspool.lib"
	    LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib uuid.lib"
	fi

	SHLIB_LD="${LINKBIN} -dll -incremental:no ${lflags}"
	SHLIB_LD_LIBS='${LIBS}'
	# link -lib only works when -lib is the first arg
	STLIB_LD="${LINKBIN} -lib ${lflags}"
	RC_OUT=-fo
	RC_TYPE=-r
4818
4819
4820
4821
4822
4823
4824
4825

4826
4827
4828
4829
4830
4831
4832
4833
4834
4835

4836
4837
4838
4839
4840
4841
4842



4843
4844
4845
4846



4847
4848
4849

4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894

4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913

4914
4915
4916
4917


4918
4919
4920
4921

4922
4923
4924
4925

4926
4927
4928
4929


4930
4931
4932

4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944



4945
4946
4947
4948



4949
4950
4951
4952
4953
4954
4955
4956

4957
4958
4959
4960
4961
4962
4963
4964
4965

4966
4967
4968
4969


4970
4971
4972
4973


4974
4975
4976
4977


4978
4979
4980

4981
4982
4983



4984
4985
4986
4987
4988





















4989








4990

4991








4992
4993
4994
4995
4996
4997
4998
4999



5000
5001
5002
5003



5004
5005
5006
5007

5008
5009
5010
5011
5012
5013
5014
5015
5016
5017

5018
5019
5020
5021


5022
5023
5024
5025


5026
5027
5028
5029


5030
5031
5032

5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074


5075
5076
5077
5078


5079
5080

5081
5082
5083
5084
5085
5086
5087
5088
5089
5090



5091
5092
5093
5094



5095
5096
5097
5098
5099

5100
5101
5102
5103
5104
5105
5106

5107
5108
5109
5110


5111
5112
5113
5114


5115
5116
5117
5118


5119
5120
5121

5122
5123
5124
5125
5126
5127
5128



5129
5130
5131


5132
5133
5134
5135
5136
5137

5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153


5154
5155
5156
5157
5158
5159
5160

5161
5162
5163
5164
5165
5166
5167
5168
5169

5170
5171
5172

5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184

5185
5186


5187
5188
5189
5190
5191
5192

5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209


5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245


5246
5247

5248
5249
5250
5251


5252
5253
5254
5255
5256
5257
5258

5259
5260

5261
5262
5263


5264
5265

5266
5267
5268
5269

5270
5271
5272


5273
5274
5275
5276
5277
5278
5279
5280

5281
5282
5283
5284
5285
5286

5287
5288
5289

5290
5291
5292
5293
5294
5295
5296


5297
5298
5299


5300
5301
5302


5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583


5584
5585

5586
5587
5588
5589


5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609

5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626

5627
5628
5629
5630


5631
5632
5633
5634
5635
5636
5637
5638
5639
5640





5641
5642
5643
5644
5645


5646
5647

5648
5649
5650
5651



5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664

5665
5666
5667
5668
5669
5670
5671
5672


5673
5674
5675
5676
5677


5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866

5867
5868

5869
5870
5871
5872
5873
5874
5875

5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888

5889
5890
5891
5892
5893
5894
5895
5896

5897
5898

5899
5900
5901
5902
5903

5904
5905

5906
5907
5908
5909

5910
5911
5912
5913
5914
5915
5916
5917

5918
5919
5920
5921
5922
5923
5924
5925






5926
5927



5928


5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942

5943
5944
5945
5946
5947
5948
5949
4632
4633
4634
4635
4636
4637
4638

4639
4640
4641
4642
4643
4644
4645
4646
4647
4648

4649
4650
4651
4652
4653



4654
4655
4656




4657
4658
4659

4660

4661













































4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680

4681

4682


4683
4684

4685
4686

4687

4688
4689

4690

4691


4692
4693
4694
4695

4696
4697
4698
4699
4700
4701
4702
4703
4704
4705



4706
4707
4708




4709
4710
4711
4712
4713
4714
4715
4716
4717
4718

4719
4720
4721
4722
4723
4724
4725
4726
4727

4728

4729


4730
4731

4732


4733
4734

4735


4736
4737
4738
4739

4740
4741
4742
4743
4744
4745
4746





4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792



4793
4794
4795




4796
4797
4798
4799
4800
4801

4802
4803
4804
4805
4806
4807
4808
4809
4810
4811

4812

4813


4814
4815

4816


4817
4818

4819


4820
4821
4822
4823

4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835

























4836
4837
4838
4839


4840
4841

4842


4843
4844

4845
4846
4847
4848
4849
4850
4851
4852
4853



4854
4855
4856




4857
4858
4859
4860
4861
4862
4863

4864
4865
4866
4867
4868
4869
4870

4871

4872


4873
4874

4875


4876
4877

4878


4879
4880
4881
4882

4883
4884
4885
4886




4887
4888
4889
4890


4891
4892






4893
















4894
4895







4896









4897



4898





4899
4900



4901

4902


4903
4904






4905

















4906
4907









4908








4909






4910
4911
4912
4913
4914
4915
4916
4917
4918


4919
4920
4921

4922

4923


4924
4925

4926
4927
4928
4929
4930
4931
4932
4933

4934
4935


4936
4937
4938

4939
4940
4941
4942
4943
4944
4945


4946
4947
4948
4949
4950
4951
4952
4953
4954

4955
4956
4957
4958
4959
4960

4961
4962
4963

4964
4965
4966
4967
4968
4969


4970
4971
4972


4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984

































4985


















































































































































































































































4986
4987
4988

4989

4990


4991
4992

4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010

5011

5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026

5027
5028
5029


5030
5031
5032
5033
5034
5035
5036





5037
5038
5039
5040
5041
5042
5043
5044


5045
5046
5047

5048




5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063

5064

5065
5066
5067
5068
5069


5070
5071
5072
5073
5074


5075
5076
5077













































































































































































5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094

5095
5096



5097


5098











5099

5100
5101
5102
5103





5104
5105

5106
5107




5108


5109
5110
5111
5112

5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128


5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139

5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163







-
+









-
+




-
-
-
+
+
+
-
-
-
-
+
+
+
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+


















-
+
-

-
-
+
+
-


-
+
-


-
+
-

-
-
+
+


-
+









-
-
-
+
+
+
-
-
-
-
+
+
+







-
+








-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+


-
+



+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+

+
+
+
+
+
+
+
+





-
-
-
+
+
+
-
-
-
-
+
+
+



-
+









-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+


-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
+
+
-

-
-
+
+
-

+







-
-
-
+
+
+
-
-
-
-
+
+
+




-
+






-
+
-

-
-
+
+
-

-
-
+
+
-

-
-
+
+


-
+



-
-
-
-
+
+
+

-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-


-
-
-

-
+
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-

-
-
-
-
-
-









-
-
+
+

-
+
-

-
-
+
+
-






+

-
+

-
-
+
+

-
+




+

-
-
+
+







-
+





-
+


-
+





-
-
+
+

-
-
+
+



+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+

-
+
-

-
-
+
+
-


















-
+
-















-
+


-
-
+
+





-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+
-
-
-
-
+
+
+












-
+
-





-
-
+
+



-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















+

-
+

-
-
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-

-
+



-
-
-
-
-
+

-
+

-
-
-
-
+
-
-
+



-
+








+






-
-
+
+
+
+
+
+


+
+
+
-
+
+














+








	# Specify the CC output file names based on the target name
	CC_OBJNAME="-Fo\$@"
	CC_EXENAME="-Fe\"\$(shell \$(CYGPATH) '\$@')\""

	# Specify linker flags depending on the type of app being
	# built -- Console vs. Window.
	if test "${TARGETCPU}" != "X86"; then
	if test "$doWince" != "no" -a "${TARGETCPU}" != "X86"; then
	    LDFLAGS_CONSOLE="-link ${lflags}"
	    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
	else
	    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
	    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
	fi
    fi

    if test "$do64bit" != "no" ; then
	printf "%s\n" "#define TCL_CFG_DO64BIT 1" >>confdefs.h
	$as_echo "#define TCL_CFG_DO64BIT 1" >>confdefs.h

    fi

    if test "${GCC}" = "yes" ; then
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SEH support in compiler" >&5
printf %s "checking for SEH support in compiler... " >&6; }
if test ${tcl_cv_seh+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SEH support in compiler" >&5
$as_echo_n "checking for SEH support in compiler... " >&6; }
if ${tcl_cv_seh+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test "$cross_compiling" = yes
  $as_echo_n "(cached) " >&6
else
  if test "$cross_compiling" = yes; then :
then :
  tcl_cv_seh=no
else case e in #(
else
  e)
# ac_fn_c_try_run LINENO
# ----------------------
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
# executables *can* be run.
ac_fn_c_try_run ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: program exited with status $ac_status" >&5
       printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

       ac_retval=$ac_status ;;
esac
fi
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_run
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	    #define WIN32_LEAN_AND_MEAN
	    #include <windows.h>
	    #undef WIN32_LEAN_AND_MEAN

	    int main(int argc, char** argv) {
		int a, b = 0;
		__try {
		    a = 666 / b;
		}
		__except (EXCEPTION_EXECUTE_HANDLER) {
		    return 0;
		}
		return 1;
	    }

_ACEOF
if ac_fn_c_try_run "$LINENO"
if ac_fn_c_try_run "$LINENO"; then :
then :
  tcl_cv_seh=yes
else case e in #(
  e) tcl_cv_seh=no ;;
else
  tcl_cv_seh=no
esac
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
  conftest.$ac_objext conftest.beam conftest.$ac_ext
esac
fi

	 ;;

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_seh" >&5
printf "%s\n" "$tcl_cv_seh" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_seh" >&5
$as_echo "$tcl_cv_seh" >&6; }
	if test "$tcl_cv_seh" = "no" ; then

printf "%s\n" "#define HAVE_NO_SEH 1" >>confdefs.h
$as_echo "#define HAVE_NO_SEH 1" >>confdefs.h

	fi

	#
	# Check to see if the excpt.h include file provided contains the
	# definition for EXCEPTION_DISPOSITION; if not, which is the case
	# with Cygwin's version as of 2002-04-10, define it to be int,
	# sufficient for getting the current code to work.
	#
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for EXCEPTION_DISPOSITION support in include files" >&5
printf %s "checking for EXCEPTION_DISPOSITION support in include files... " >&6; }
if test ${tcl_cv_eh_disposition+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for EXCEPTION_DISPOSITION support in include files" >&5
$as_echo_n "checking for EXCEPTION_DISPOSITION support in include files... " >&6; }
if ${tcl_cv_eh_disposition+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#	    define WIN32_LEAN_AND_MEAN
#	    include <windows.h>
#	    undef WIN32_LEAN_AND_MEAN

int
main (void)
main ()
{

		EXCEPTION_DISPOSITION x;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_eh_disposition=yes
else case e in #(
  e) tcl_cv_eh_disposition=no ;;
else
  tcl_cv_eh_disposition=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_eh_disposition" >&5
printf "%s\n" "$tcl_cv_eh_disposition" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_eh_disposition" >&5
$as_echo "$tcl_cv_eh_disposition" >&6; }
	if test "$tcl_cv_eh_disposition" = "no" ; then

printf "%s\n" "#define EXCEPTION_DISPOSITION int" >>confdefs.h
$as_echo "#define EXCEPTION_DISPOSITION int" >>confdefs.h

	fi

	# Check to see if winnt.h defines CHAR, SHORT, and LONG
	# even if VOID has already been #defined. The win32api
	# used by mingw and cygwin is known to do this.
	ac_fn_c_check_header_compile "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default"
if test "x$ac_cv_header_stdbool_h" = xyes
then :

printf "%s\n" "#define HAVE_STDBOOL_H 1" >>confdefs.h

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for winnt.h that ignores VOID define" >&5
$as_echo_n "checking for winnt.h that ignores VOID define... " >&6; }
if ${tcl_cv_winnt_ignore_void+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

		#define VOID void
		#define WIN32_LEAN_AND_MEAN
		#include <windows.h>
		#undef WIN32_LEAN_AND_MEAN

int
main ()
{

		CHAR c;
		SHORT s;
		LONG l;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_winnt_ignore_void=yes
else
  tcl_cv_winnt_ignore_void=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_winnt_ignore_void" >&5
$as_echo "$tcl_cv_winnt_ignore_void" >&6; }
	if test "$tcl_cv_winnt_ignore_void" = "yes" ; then

$as_echo "#define HAVE_WINNT_IGNORE_VOID 1" >>confdefs.h

	fi

	# See if the compiler supports casting to a union type.
	# This is used to stop gcc from printing a compiler
	# warning when initializing a union member.

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
printf %s "checking for cast to union support... " >&6; }
if test ${tcl_cv_cast_to_union+y}
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
$as_echo_n "checking for cast to union support... " >&6; }
if ${tcl_cv_cast_to_union+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main (void)
main ()
{

		  union foo { int i; double d; };
		  union foo f = (union foo) (int) 0;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
if ac_fn_c_try_compile "$LINENO"; then :
then :
  tcl_cv_cast_to_union=yes
else case e in #(
  e) tcl_cv_cast_to_union=no ;;
else
  tcl_cv_cast_to_union=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
printf "%s\n" "$tcl_cv_cast_to_union" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
$as_echo "$tcl_cv_cast_to_union" >&6; }
	if test "$tcl_cv_cast_to_union" = "yes"; then

printf "%s\n" "#define HAVE_CAST_TO_UNION 1" >>confdefs.h
$as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h

	fi
    fi

    # DL_LIBS is empty, but then we match the Unix version







ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "
#include <stdint.h>

"
if test "x$ac_cv_type_intptr_t" = xyes
then :

printf "%s\n" "#define HAVE_INTPTR_T 1" >>confdefs.h


fi
ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "
#include <stdint.h>

"
if test "x$ac_cv_type_uintptr_t" = xyes
then :

printf "%s\n" "#define HAVE_UINTPTR_T 1" >>confdefs.h


fi


#--------------------------------------------------------------------
# man2tcl needs this so that it can use errno.h
#--------------------------------------------------------------------

ac_fn_c_check_header_compile "$LINENO" "errno.h" "ac_cv_header_errno_h" "$ac_includes_default"
if test "x$ac_cv_header_errno_h" = xyes
ac_fn_c_check_header_mongrel "$LINENO" "errno.h" "ac_cv_header_errno_h" "$ac_includes_default"
if test "x$ac_cv_header_errno_h" = xyes; then :
then :

else case e in #(
  e) MAN2TCLFLAGS="-DNO_ERRNO_H" ;;
else
  MAN2TCLFLAGS="-DNO_ERRNO_H"
esac
fi




#-------------------------------------------
#     Check for _strtoi64
#-------------------------------------------

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking availability of _strtoi64" >&5
printf %s "checking availability of _strtoi64... " >&6; }
if test ${tcl_cv_strtoi64+y}
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking availability of _strtoi64" >&5
$as_echo_n "checking availability of _strtoi64... " >&6; }
if ${tcl_cv_strtoi64+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
int
main (void)
main ()
{
_strtoi64(0,0,0)
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"
if ac_fn_c_try_link "$LINENO"; then :
then :
  tcl_cv_strtoi64=yes
else case e in #(
  e) tcl_cv_strtoi64=no ;;
else
  tcl_cv_strtoi64=no
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext ;;
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_strtoi64" >&5
printf "%s\n" "$tcl_cv_strtoi64" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_strtoi64" >&5
$as_echo "$tcl_cv_strtoi64" >&6; }
if test $tcl_cv_strtoi64 = no; then

printf "%s\n" "#define NO_STRTOI64 1" >>confdefs.h
$as_echo "#define NO_STRTOI64 1" >>confdefs.h

fi

ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "$ac_includes_default"
if test "x$ac_cv_type_intptr_t" = xyes
then :

#--------------------------------------------------------------------
# Windows XP theme engine header for Ttk
#--------------------------------------------------------------------

printf "%s\n" "#define HAVE_INTPTR_T 1" >>confdefs.h

ac_fn_c_check_header_compile "$LINENO" "uxtheme.h" "ac_cv_header_uxtheme_h" "#include <windows.h>
"
else case e in #(
  e)
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pointer-size signed integer type" >&5
printf %s "checking for pointer-size signed integer type... " >&6; }
if test ${tcl_cv_intptr_t+y}
then :
if test "x$ac_cv_header_uxtheme_h" = xyes; then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    for tcl_cv_intptr_t in "int" "long" "__int64" none; do
	if test "$tcl_cv_intptr_t" != none; then
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main (void)
{
static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($tcl_cv_intptr_t))];
test_array [0] = 0;
return test_array [0];

  ;
  $as_echo "#define HAVE_UXTHEME_H 1" >>confdefs.h

  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_ok=yes
else case e in #(
else
  e) tcl_ok=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	    test "$tcl_ok" = yes && break; fi
    done ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_intptr_t" >&5
  { $as_echo "$as_me:${as_lineno-$LINENO}: xpnative theme will be unavailable" >&5
printf "%s\n" "$tcl_cv_intptr_t" >&6; }
    if test "$tcl_cv_intptr_t" != none; then

$as_echo "$as_me: xpnative theme will be unavailable" >&6;}
printf "%s\n" "#define intptr_t $tcl_cv_intptr_t" >>confdefs.h

    fi
 ;;
esac
fi

ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default"
if test "x$ac_cv_type_uintptr_t" = xyes
then :


ac_fn_c_check_header_compile "$LINENO" "vssym32.h" "ac_cv_header_vssym32_h" "#include <windows.h>
printf "%s\n" "#define HAVE_UINTPTR_T 1" >>confdefs.h

#include <uxtheme.h>
"
else case e in #(
  e)
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pointer-size unsigned integer type" >&5
printf %s "checking for pointer-size unsigned integer type... " >&6; }
if test ${tcl_cv_uintptr_t+y}
then :
if test "x$ac_cv_header_vssym32_h" = xyes; then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned __int64" \
	    none; do
	if test "$tcl_cv_uintptr_t" != none; then
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main (void)
{
static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($tcl_cv_uintptr_t))];
test_array [0] = 0;
return test_array [0];

  ;
  $as_echo "#define HAVE_VSSYM32_H 1" >>confdefs.h

  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_ok=yes
else case e in #(
  e) tcl_ok=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	    test "$tcl_ok" = yes && break; fi
    done ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_uintptr_t" >&5
printf "%s\n" "$tcl_cv_uintptr_t" >&6; }
    if test "$tcl_cv_uintptr_t" != none; then

printf "%s\n" "#define uintptr_t $tcl_cv_uintptr_t" >>confdefs.h

    fi
 ;;
esac
fi


#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
printf %s "checking for build with symbols... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
$as_echo_n "checking for build with symbols... " >&6; }
    # Check whether --enable-symbols was given.
if test ${enable_symbols+y}
if test "${enable_symbols+set}" = set; then :
then :
  enableval=$enable_symbols; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=no ;;
else
  tcl_ok=no
esac
fi

# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
    if test "$tcl_ok" = "no"; then
	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'
	DBGX=""

printf "%s\n" "#define NDEBUG 1" >>confdefs.h
$as_echo "#define NDEBUG 1" >>confdefs.h

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }

	printf "%s\n" "#define TCL_CFG_OPTIMIZED 1" >>confdefs.h
	$as_echo "#define TCL_CFG_OPTIMIZED 1" >>confdefs.h

    else
	CFLAGS_DEFAULT='$(CFLAGS_DEBUG)'
	LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)'
	DBGX=g
	if test "$tcl_ok" = "yes"; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
printf "%s\n" "yes (standard debugging)" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
$as_echo "yes (standard debugging)" >&6; }
	fi
    fi



    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then

printf "%s\n" "#define TCL_MEM_DEBUG 1" >>confdefs.h
$as_echo "#define TCL_MEM_DEBUG 1" >>confdefs.h

    fi

    if test "$tcl_ok" = "compile" -o "$tcl_ok" = "all"; then

printf "%s\n" "#define TCL_COMPILE_DEBUG 1" >>confdefs.h
$as_echo "#define TCL_COMPILE_DEBUG 1" >>confdefs.h


printf "%s\n" "#define TCL_COMPILE_STATS 1" >>confdefs.h
$as_echo "#define TCL_COMPILE_STATS 1" >>confdefs.h

    fi

    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
	if test "$tcl_ok" = "all"; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem compile debugging" >&5
printf "%s\n" "enabled symbols mem compile debugging" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem compile debugging" >&5
$as_echo "enabled symbols mem compile debugging" >&6; }
	else
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
printf "%s\n" "enabled $tcl_ok debugging" >&6; }
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
$as_echo "enabled $tcl_ok debugging" >&6; }
	fi
    fi


TK_DBGX=${DBGX}

#--------------------------------------------------------------------
# Embed the manifest if we can determine how
#--------------------------------------------------------------------

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
printf %s "checking how to run the C preprocessor... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
  CPP=
fi
if test -z "$CPP"; then
  if test ${ac_cv_prog_CPP+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)     # Double quotes because $CC needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
    do
      ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :

else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok
then :
  break
fi

    done
    ac_cv_prog_CPP=$CPP
   ;;
esac
fi
  CPP=$ac_cv_prog_CPP
else
  ac_cv_prog_CPP=$CPP
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
printf "%s\n" "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :

else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok
then :

else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See 'config.log' for more details" "$LINENO" 5; } ;;
esac
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep -e" >&5
printf %s "checking for egrep -e... " >&6; }
if test ${ac_cv_path_EGREP_TRADITIONAL+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in grep ggrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" -E 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    :
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi

    if test "$ac_cv_path_EGREP_TRADITIONAL"
then :
  ac_cv_path_EGREP_TRADITIONAL="$ac_cv_path_EGREP_TRADITIONAL -E"
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in egrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi
 ;;
esac
fi ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP_TRADITIONAL" >&5
printf "%s\n" "$ac_cv_path_EGREP_TRADITIONAL" >&6; }
 EGREP_TRADITIONAL=$ac_cv_path_EGREP_TRADITIONAL


    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to embed manifest" >&5
printf %s "checking whether to embed manifest... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to embed manifest" >&5
$as_echo_n "checking whether to embed manifest... " >&6; }
    # Check whether --enable-embedded-manifest was given.
if test ${enable_embedded_manifest+y}
if test "${enable_embedded_manifest+set}" = set; then :
then :
  enableval=$enable_embedded_manifest; embed_ok=$enableval
else case e in #(
  e) embed_ok=yes ;;
else
  embed_ok=yes
esac
fi


    VC_MANIFEST_EMBED_DLL=
    VC_MANIFEST_EMBED_EXE=
    result=no
    if test "$embed_ok" = "yes" -a "${SHARED_BUILD}" = "1" \
       -a "$GCC" != "yes" ; then
	# Add the magic to embed the manifest into the dll/exe
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#if defined(_MSC_VER) && _MSC_VER >= 1400
print("manifest needed")
#endif

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP_TRADITIONAL "manifest needed" >/dev/null 2>&1
  $EGREP "manifest needed" >/dev/null 2>&1; then :
then :

	# Could do a CHECK_PROG for mt, but should always be with MSVC8+
	# Could add 'if test -f' check, but manifest should be created
	# in this compiler case
	# Add in a manifest argument that may be specified
	# XXX Needs improvement so that the test for existence accounts
	# XXX for a provided (known) manifest
	VC_MANIFEST_EMBED_DLL="if test -f \[email protected] ; then mt.exe -nologo -manifest \[email protected] wish.exe.manifest -outputresource:\$@\;2 ; fi"
	VC_MANIFEST_EMBED_EXE="if test -f \[email protected] ; then mt.exe -nologo -manifest \[email protected] wish.exe.manifest -outputresource:\$@\;1 ; fi"
	result=yes
	if test "xwish.exe.manifest" != x ; then
	    result="yes (wish.exe.manifest)"
	fi

fi
rm -rf conftest*
rm -f conftest*

    fi
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $result" >&5
printf "%s\n" "$result" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $result" >&5
$as_echo "$result" >&6; }





    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tclsh in Tcl build directory" >&5
printf %s "checking for tclsh in Tcl build directory... " >&6; }
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}\${EXESUFFIX}
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $BUILD_TCLSH" >&5
printf "%s\n" "$BUILD_TCLSH" >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh in Tcl build directory" >&5
$as_echo_n "checking for tclsh in Tcl build directory... " >&6; }
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BUILD_TCLSH" >&5
$as_echo "$BUILD_TCLSH" >&6; }



    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
printf %s "checking for tclsh... " >&6; }
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
$as_echo_n "checking for tclsh... " >&6; }

    if test ${ac_cv_path_tclsh+y}
    if ${ac_cv_path_tclsh+:} false; then :
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
  $as_echo_n "(cached) " >&6
else

	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do
	    for j in `ls -r $dir/tclsh[8-9]*.exe 2> /dev/null` \
		    `ls -r $dir/tclsh* 2> /dev/null` ; do
		if test x"$ac_cv_path_tclsh" = x ; then
		    if test -f "$j" ; then
			ac_cv_path_tclsh=$j
			break
		    fi
		fi
	    done
	done
     ;;

esac
fi


    if test -f "$ac_cv_path_tclsh" ; then
	TCLSH_PROG="$ac_cv_path_tclsh"
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $TCLSH_PROG" >&5
printf "%s\n" "$TCLSH_PROG" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $TCLSH_PROG" >&5
$as_echo "$TCLSH_PROG" >&6; }
    else
	# It is not an error if an installed version of Tcl can't be located.
	TCLSH_PROG=""
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: No tclsh found on PATH" >&5
printf "%s\n" "No tclsh found on PATH" >&6; }
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: No tclsh found on PATH" >&5
$as_echo "No tclsh found on PATH" >&6; }
    fi



#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
# Check whether --enable-zipfs was given.
if test ${enable_zipfs+y}
then :
  enableval=$enable_zipfs; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
esac
fi

if test "$tcl_ok" = "yes" ; then
    #
    # Find a native compiler
    #
    # Put a plausible default for CC_FOR_BUILD in Makefile.
if test -z "$CC_FOR_BUILD"; then
  if test "x$cross_compiling" = "xno"; then
    CC_FOR_BUILD='$(CC)'
  else
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gcc" >&5
printf %s "checking for gcc... " >&6; }
    if test ${ac_cv_path_cc+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do
	    for j in `ls -r $dir/gcc 2> /dev/null` \
		    `ls -r $dir/gcc 2> /dev/null` ; do
		if test x"$ac_cv_path_cc" = x ; then
		    if test -f "$j" ; then
			ac_cv_path_cc=$j
			break
		    fi
		fi
	    done
	done
     ;;
esac
fi

  fi
fi

# Also set EXEEXT_FOR_BUILD.
if test "x$cross_compiling" = "xno"; then
  EXEEXT_FOR_BUILD='$(EXEEXT)'
  OBJEXT_FOR_BUILD='$(OBJEXT)'
else
  OBJEXT_FOR_BUILD='.no'
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build system executable suffix" >&5
printf %s "checking for build system executable suffix... " >&6; }
if test ${bfd_cv_build_exeext+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) rm -f conftest*
     echo 'int main () { return 0; }' > conftest.c
     bfd_cv_build_exeext=
     ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
     for file in conftest.*; do
       case $file in
       *.c | *.o | *.obj | *.ilk | *.pdb) ;;
       *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
       esac
     done
     rm -f conftest*
     test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bfd_cv_build_exeext" >&5
printf "%s\n" "$bfd_cv_build_exeext" >&6; }
  EXEEXT_FOR_BUILD=""
  test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
fi

    #
    # Find a native zip implementation
    #

    ZIP_PROG=""
    ZIP_PROG_OPTIONS=""
    ZIP_PROG_VFSSEARCH=""
    ZIP_INSTALL_OBJS=""

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for zip" >&5
printf %s "checking for zip... " >&6; }
    if test ${ac_cv_path_zip+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/zip 2> /dev/null` \
            `ls -r $dir/zip 2> /dev/null` ; do
        if test x"$ac_cv_path_zip" = x ; then
            if test -f "$j" ; then
            ac_cv_path_zip=$j
            break
            fi
        fi
        done
    done
     ;;
esac
fi

    if test -f "$ac_cv_path_zip" ; then
        ZIP_PROG="$ac_cv_path_zip"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ZIP_PROG" >&5
printf "%s\n" "$ZIP_PROG" >&6; }
        ZIP_PROG_OPTIONS="-rq"
        ZIP_PROG_VFSSEARCH="*"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Found INFO Zip in environment" >&5
printf "%s\n" "Found INFO Zip in environment" >&6; }
        # Use standard arguments for zip
    else
        # It is not an error if an installed version of Zip can't be located.
        # We can use the locally distributed minizip instead
        ZIP_PROG="./minizip${EXEEXT_FOR_BUILD}"
        ZIP_PROG_OPTIONS="-o -r"
        ZIP_PROG_VFSSEARCH="*"
        ZIP_INSTALL_OBJS="minizip${EXEEXT_FOR_BUILD}"
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: No zip found on PATH building minizip" >&5
printf "%s\n" "No zip found on PATH building minizip" >&6; }
    fi





	ZIPFS_BUILD=1
	TK_ZIP_FILE=libtk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${TK_PATCH_LEVEL}.zip
else
	ZIPFS_BUILD=0
	TCL_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for building with zipfs" >&5
printf %s "checking for building with zipfs... " >&6; }
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;

printf "%s\n" "#define ZIPFS_BUILD 2" >>confdefs.h

       INSTALL_LIBRARIES=install-libraries-zipfs-static
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
     else

printf "%s\n" "#define ZIPFS_BUILD 1" >>confdefs.h
\
       INSTALL_LIBRARIES=install-libraries-zipfs-shared
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
    fi
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi






#------------------------------------------------------------------------
# tkConfig.sh refers to this by a different name
#------------------------------------------------------------------------

TK_SHARED_BUILD=${SHARED_BUILD}

#--------------------------------------------------------------------
# Perform final evaluations of variables with possible substitutions.
#--------------------------------------------------------------------

TK_SHARED_LIB_SUFFIX="\${NODOT_VERSION}${DLLSUFFIX}"
TK_UNSHARED_LIB_SUFFIX="\${NODOT_VERSION}${LIBSUFFIX}"
TK_EXPORT_FILE_SUFFIX="\${NODOT_VERSION}${LIBSUFFIX}"

eval "TK_SRC_DIR=\"`cd $srcdir/..; $CYGPATH $(pwd)`\""
eval "TK_SRC_DIR=\"`cd $srcdir/..; pwd`\""

eval "TK_DLL_FILE_TCL8=tk$VER${DLLSUFFIX}"
eval "TK_DLL_FILE_TCL9=tcl9tk$VER${DLLSUFFIX}"
if test ${TCL_MAJOR_VERSION} = 8 ; then
eval "TK_DLL_FILE=tk$VER${DLLSUFFIX}"
if test ${SHARED_BUILD} = 0 -o "$GCC" != "yes" ; then
 eval "TK_LIB_FILE=${LIBPREFIX}tk${VER}${LIBSUFFIX}"
eval "TK_LIB_FILE=${LIBPREFIX}tk$VER${LIBSUFFIX}"
else
 eval "TK_LIB_FILE=${LIBPREFIX}tk${VER}${DLLSUFFIX}.a"
fi
else
eval "TK_DLL_FILE=tcl9tk$VER${DLLSUFFIX}"
if test ${SHARED_BUILD} = 0 -o "$GCC" != "yes" ; then
 eval "TK_LIB_FILE=${LIBPREFIX}tcl9tk${VER}${LIBSUFFIX}"
else
 eval "TK_LIB_FILE=${LIBPREFIX}tcl9tk${VER}${DLLSUFFIX}.a"
fi
fi

eval "TK_STUB_LIB_FILE=${LIBPREFIX}tkstub${LIBSUFFIX}" ;
eval "TK_STUB_LIB_FILE=${LIBPREFIX}tkstub${VER}${LIBSUFFIX}"
# FIXME: All of this var junk needs to be done in tcl.m4 !!!!
# I left out the other vars that also need to get defined here.
# we also need to double check about spaces in path names
TK_LIB_FLAG="-l"
if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
    TK_LIB_FLAG="${TK_LIB_FLAG}tcl9"
fi
eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}${VER}${LIBFLAGSUFFIX}\""
eval "TK_LIB_FLAG=\"-ltk${VER}${LIBFLAGSUFFIX}\""
TK_LIB_SPEC="-L${libdir} ${TK_LIB_FLAG}"
eval "TK_BUILD_LIB_SPEC=\"-L`$CYGPATH $(pwd)` ${TK_LIB_FLAG}\""
TK_BUILD_LIB_SPEC="-L`pwd` ${TK_LIB_FLAG}"

if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
    eval "TK_STUB_LIB_FLAG=\"-ltkstub${LIBFLAGSUFFIX}\""
else
    eval "TK_STUB_LIB_FLAG=\"-ltkstub${VER}${LIBFLAGSUFFIX}\""
eval "TK_STUB_LIB_FLAG=\"-ltkstub${VER}${LIBFLAGSUFFIX}\""
fi
eval "TK_BUILD_STUB_LIB_SPEC=\"-L`$CYGPATH $(pwd)` ${TK_STUB_LIB_FLAG}\""
TK_BUILD_STUB_LIB_SPEC="-L`pwd` ${TK_STUB_LIB_FLAG}"

TK_STUB_LIB_SPEC="-L${libdir} ${TK_STUB_LIB_FLAG}"
TK_STUB_LIB_PATH="${libdir}/${TK_STUB_LIB_FILE}"
eval "TK_BUILD_STUB_LIB_PATH=\"`$CYGPATH $(pwd)`/${TK_STUB_LIB_FILE}\""
TK_BUILD_STUB_LIB_PATH="`pwd`/${TK_STUB_LIB_FILE}"

eval "DLLSUFFIX=${DLLSUFFIX}"
eval "LIBPREFIX=${LIBPREFIX}"
eval "LIBSUFFIX=${LIBSUFFIX}"
eval "EXESUFFIX=${EXESUFFIX}"

CFG_TK_SHARED_LIB_SUFFIX=${TK_SHARED_LIB_SUFFIX}
CFG_TK_UNSHARED_LIB_SUFFIX=${TK_UNSHARED_LIB_SUFFIX}
CFG_TK_EXPORT_FILE_SUFFIX=${TK_EXPORT_FILE_SUFFIX}

#--------------------------------------------------------------------
# Adjust the defines for how the resources are built depending
# on symbols and static vs. shared.
#--------------------------------------------------------------------

if test ${SHARED_BUILD} = 0; then
    RC_DEFINES="${RC_DEFINE} STATIC_BUILD"
if test ${SHARED_BUILD} = 0 -o "$TCL_NEEDS_EXP_FILE" = 0; then
    if test "${DBGX}" = "d"; then
        RC_DEFINES="${RC_DEFINE} STATIC_BUILD ${RC_DEFINE} DEBUG"
    else
        RC_DEFINES="${RC_DEFINE} STATIC_BUILD"
    fi
    TK_RES=""
else
    if test "${DBGX}" = "d"; then
        RC_DEFINES="${RC_DEFINE} DEBUG"
    else
    RC_DEFINES=""
        RC_DEFINES=""
    fi
    TK_RES='tk.$(RES)'
fi

# The wish.exe.manifest requires these
# TK_WIN_VERSION is the 4 dotted pair Windows version format which needs
# the release level, and must account for interim release versioning
case "$TK_PATCH_LEVEL" in
     *a*) TK_RELEASE_LEVEL=0 ;;
     *b*) TK_RELEASE_LEVEL=1 ;;
     *)   TK_RELEASE_LEVEL=2 ;;
esac
TK_WIN_VERSION="$TK_VERSION.$TK_RELEASE_LEVEL.`echo $TK_PATCH_LEVEL | tr -d ab.`"

# X86|AMD64|IA64 for manifest








6030
6031
6032
6033
6034
6035
6036
6037
6038


6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055


6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068

6069
6070
6071
6072
6073
6074
6075

6076
6077
6078
6079
6080
6081
6082
6083
6084
6085

6086
6087
6088
6089
6090
6091
6092
6093


6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108


6109
6110
6111
6112
6113
6114
6115
5244
5245
5246
5247
5248
5249
5250


5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267


5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281

5282
5283
5284
5285
5286
5287
5288

5289
5290
5291
5292
5293
5294
5295
5296
5297
5298

5299
5300
5301
5302
5303
5304
5305


5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320


5321
5322
5323
5324
5325
5326
5327
5328
5329







-
-
+
+















-
-
+
+












-
+






-
+









-
+






-
-
+
+













-
-
+
+







# scripts and configure runs, see configure's option --config-cache.
# It is not useful on other systems.  If it contains results you don't
# want to keep, you may remove or edit it.
#
# config.status only pays attention to the cache file if you give it
# the --recheck option to rerun configure.
#
# 'ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* 'ac_cv_foo' will be assigned the
# `ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* `ac_cv_foo' will be assigned the
# following values.

_ACEOF

# The following way of writing the cache mishandles newlines in values,
# but we know of no workaround that is simple, portable, and efficient.
# So, we kill variables containing newlines.
# Ultrix sh set writes to stderr and can't be redirected directly,
# and sets the high bit in the cache file unless we assign to the vars.
(
  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
  done

  (set) 2>&1 |
    case $as_nl`(ac_space=' '; set) 2>&1` in #(
    *${as_nl}ac_space=\ *)
      # 'set' does not quote correctly, so add quotes: double-quote
      # `set' does not quote correctly, so add quotes: double-quote
      # substitution turns \\\\ into \\, and sed turns \\ into \.
      sed -n \
	"s/'/'\\\\''/g;
	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
      ;; #(
    *)
      # 'set' quotes correctly as required by POSIX, so do not add quotes.
      # `set' quotes correctly as required by POSIX, so do not add quotes.
      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
) |
  sed '
     /^ac_cv_env_/b end
     t clear
     :clear
     s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/
     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
     t end
     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
     :end' >>confcache
if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
  if test -w "$cache_file"; then
    if test "x$cache_file" != "x/dev/null"; then
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
printf "%s\n" "$as_me: updating cache $cache_file" >&6;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
$as_echo "$as_me: updating cache $cache_file" >&6;}
      if test ! -f "$cache_file" || test -h "$cache_file"; then
	cat confcache >"$cache_file"
      else
        case $cache_file in #(
        */* | ?:*)
	  mv -f confcache "$cache_file"$$ &&
	  mv -f "$cache_file"$$ "$cache_file" ;; #(
        *)
	  mv -f confcache "$cache_file" ;;
	esac
      fi
    fi
  else
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
  fi
fi
rm -f confcache

test "x$prefix" = xNONE && prefix=$ac_default_prefix
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
6132
6133
6134
6135
6136
6137
6138
6139



6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159

6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176


6177
6178
6179
6180
6181
6182
6183
5346
5347
5348
5349
5350
5351
5352

5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374

5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390


5391
5392
5393
5394
5395
5396
5397
5398
5399







-
+
+
+



















-
+















-
-
+
+







:clear
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\)/-D\1=\2/g
t quote
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)/-D\1=\2/g
t quote
b any
:quote
s/[][	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/[	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/\[/\\&/g
s/\]/\\&/g
s/\$/$$/g
H
:any
${
	g
	s/^\n//
	s/\n/ /g
	p
}
'
DEFS=`sed -n "$ac_script" confdefs.h`


ac_libobjs=
ac_ltlibobjs=
U=
for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
  # 1. Remove the extension, and $U if already installed.
  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
  ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"`
  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
  #    will be set to the directory where LIBOBJS objects are built.
  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
done
LIBOBJS=$ac_libobjs

LTLIBOBJS=$ac_ltlibobjs



: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files $CONFIG_STATUS"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
as_write_fail=0
cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
#! $SHELL
# Generated by $as_me.
# Run this file to recreate the current configuration.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
6192
6193
6194
6195
6196
6197
6198
6199

6200
6201
6202
6203
6204
6205
6206
6207
6208


6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228








6229
6230
6231
6232
6233
6234




















6235
6236
6237

6238
6239
6240




6241
6242
6243
6244
6245
6246
6247
6248
6249
6250

6251
6252
6253
6254
6255
6256
6257

6258
6259
6260
6261
6262
6263
6264
6265







6266
6267
6268
6269
6270
6271
6272
6273
6274
6275

6276
6277
6278
6279

6280
6281
6282
6283
6284
6285

6286
6287
6288
6289
6290
6291

6292
6293
6294




















6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307

6308
6309

6310
6311
6312
6313
6314
6315
6316
5408
5409
5410
5411
5412
5413
5414

5415

5416
5417
5418
5419
5420
5421


5422
5423
5424
5425
5426
5427

5428
5429
5430
5431








5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442






5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462



5463



5464
5465
5466
5467










5468




5469
5470

5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494


5495




5496
5497
5498
5499
5500
5501

5502
5503
5504
5505
5506
5507

5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543

5544
5545

5546
5547
5548
5549
5550
5551
5552
5553







-
+
-






-
-
+
+




-




-
-
-
-
-
-
-
-



+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-


-
+








+
+
+
+
+
+
+








-
-
+
-
-
-
-
+





-
+





-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












-
+

-
+







cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
else
  case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
IFS=" ""	$as_nl"

PS1='$ '
PS2='> '
PS4='+ '

  as_echo='print -r --'
  as_echo_n='print -rn --'
elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    export as_echo_n_body
LANGUAGE=C
export LANGUAGE

    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

fi
# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if ${PATH_SEPARATOR+false} :; then
if test "${PATH_SEPARATOR+set}" != set; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
  test -z "$as_dir" && as_dir=.
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  printf "%s\n" "$as_me: error: $2" >&2
  $as_echo "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347

6348
6349
6350
6351
6352
6353
6354


6355
6356
6357
6358

6359
6360
6361
6362
6363
6364
6365
6366

6367
6368
6369
6370
6371
6372
6373


6374
6375
6376
6377

6378
6379
6380
6381
6382
6383
6384
5570
5571
5572
5573
5574
5575
5576

5577
5578
5579
5580
5581
5582

5583

5584
5585
5586
5587


5588
5589
5590
5591


5592
5593
5594
5595
5596
5597
5598
5599

5600

5601
5602
5603
5604


5605
5606
5607
5608


5609
5610
5611
5612
5613
5614
5615
5616







-






-
+
-




-
-
+
+


-
-
+







-
+
-




-
-
+
+


-
-
+







# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset

# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else case e in #(
  e) as_fn_append ()
else
  as_fn_append ()
  {
    eval $1=\$$1\$2
  } ;;
esac
  }
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else case e in #(
  e) as_fn_arith ()
else
  as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  } ;;
esac
  }
fi # as_fn_arith


if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
6397
6398
6399
6400
6401
6402
6403
6404

6405
6406
6407
6408
6409
6410
6411
5629
5630
5631
5632
5633
5634
5635

5636
5637
5638
5639
5640
5641
5642
5643







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X/"$0" |
$as_echo X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462



6463
6464
6465
6466
6467
6468
6469
5651
5652
5653
5654
5655
5656
5657




5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670






5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681



5682
5683
5684
5685
5686
5687
5688
5689
5690
5691







-
-
-
-













-
-
-
-
-
-











-
-
-
+
+
+







# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
6483
6484
6485
6486
6487
6488
6489
6490

6491
6492
6493
6494
6495
6496
6497
6498
6499

6500
6501
6502
6503
6504
6505
6506
5705
5706
5707
5708
5709
5710
5711

5712
5713
5714
5715
5716
5717
5718
5719
5720

5721
5722
5723
5724
5725
5726
5727
5728







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$as_dir" |
$as_echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
6536
6537
6538
6539
6540
6541
6542
6543

6544
6545
6546
6547

6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564


6565
6566
6567
6568
6569
6570
6571
5758
5759
5760
5761
5762
5763
5764

5765

5766
5767

5768

5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782


5783
5784
5785
5786
5787
5788
5789
5790
5791







-
+
-


-
+
-














-
-
+
+







{
  test -f "$1" && test -x "$1"
} # as_fn_executable_p
as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


exec 6>&1
## ----------------------------------- ##
## Main body of $CONFIG_STATUS script. ##
## ----------------------------------- ##
_ASEOF
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by tk $as_me 9.0, which was
generated by GNU Autoconf 2.72.  Invocation command line was
This file was extended by $as_me, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@

6584
6585
6586
6587
6588
6589
6590
6591

6592
6593
6594
6595
6596
6597
6598
5804
5805
5806
5807
5808
5809
5810

5811
5812
5813
5814
5815
5816
5817
5818







-
+







# Files that config.status was made for.
config_files="$ac_config_files"

_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
ac_cs_usage="\
'$as_me' instantiates files and other configuration actions
\`$as_me' instantiates files and other configuration actions
from templates according to the current configuration.  Unless the files
and actions are specified as TAGs, all are instantiated by default.

Usage: $0 [OPTION]... [TAG]...

  -h, --help       print this help, then exit
  -V, --version    print version number and configuration settings, then exit
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616

6617
6618
6619


6620
6621
6622

6623
6624
6625
6626
6627
6628
6629
5826
5827
5828
5829
5830
5831
5832


5833

5834
5835


5836
5837
5838
5839

5840
5841
5842
5843
5844
5845
5846
5847







-
-

-
+

-
-
+
+


-
+








Configuration files:
$config_files

Report bugs to the package provider."

_ACEOF
ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"`
ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"`
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
tk config.status 9.0
configured by $0, generated by GNU Autoconf 2.72,
config.status
configured by $0, generated by GNU Autoconf 2.69,
  with options \\"\$ac_cs_config\\"

Copyright (C) 2023 Free Software Foundation, Inc.
Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."

ac_pwd='$ac_pwd'
srcdir='$srcdir'
test -n "\$AWK" || AWK=awk
_ACEOF
6652
6653
6654
6655
6656
6657
6658
6659

6660
6661

6662
6663
6664
6665
6666
6667

6668
6669
6670
6671
6672
6673

6674
6675
6676
6677
6678
6679
6680


6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701

6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715

6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732

6733
6734
6735
6736
6737
6738
6739
6740
6741
6742

6743
6744
6745
6746
6747
6748
6749
6750

6751
6752
6753
6754
6755
6756
6757
5870
5871
5872
5873
5874
5875
5876

5877
5878

5879
5880
5881
5882
5883
5884

5885
5886
5887
5888
5889
5890

5891
5892
5893
5894
5895
5896


5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918

5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932

5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949

5950
5951
5952
5953
5954
5955
5956
5957
5958
5959

5960
5961
5962
5963
5964
5965
5966
5967

5968
5969
5970
5971
5972
5973
5974
5975







-
+

-
+





-
+





-
+





-
-
+
+




















-
+













-
+
















-
+









-
+







-
+







  esac

  case $ac_option in
  # Handling of the options.
  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
    ac_cs_recheck=: ;;
  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
    printf "%s\n" "$ac_cs_version"; exit ;;
    $as_echo "$ac_cs_version"; exit ;;
  --config | --confi | --conf | --con | --co | --c )
    printf "%s\n" "$ac_cs_config"; exit ;;
    $as_echo "$ac_cs_config"; exit ;;
  --debug | --debu | --deb | --de | --d | -d )
    debug=: ;;
  --file | --fil | --fi | --f )
    $ac_shift
    case $ac_optarg in
    *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    '') as_fn_error $? "missing file argument" ;;
    esac
    as_fn_append CONFIG_FILES " '$ac_optarg'"
    ac_need_defaults=false;;
  --he | --h |  --help | --hel | -h )
    printf "%s\n" "$ac_cs_usage"; exit ;;
    $as_echo "$ac_cs_usage"; exit ;;
  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil | --si | --s)
    ac_cs_silent=: ;;

  # This is an error.
  -*) as_fn_error $? "unrecognized option: '$1'
Try '$0 --help' for more information." ;;
  -*) as_fn_error $? "unrecognized option: \`$1'
Try \`$0 --help' for more information." ;;

  *) as_fn_append ac_config_targets " $1"
     ac_need_defaults=false ;;

  esac
  shift
done

ac_configure_extra_args=

if $ac_cs_silent; then
  exec 6>/dev/null
  ac_configure_extra_args="$ac_configure_extra_args --silent"
fi

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
  shift
  \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6
  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
  CONFIG_SHELL='$SHELL'
  export CONFIG_SHELL
  exec "\$@"
fi

_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
  printf "%s\n" "$ac_log"
  $as_echo "$ac_log"
} >&5

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1

# Handling of arguments.
for ac_config_target in $ac_config_targets
do
  case $ac_config_target in
    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
    "tkConfig.sh") CONFIG_FILES="$CONFIG_FILES tkConfig.sh" ;;
    "wish.exe.manifest") CONFIG_FILES="$CONFIG_FILES wish.exe.manifest" ;;

  *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;;
  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
  esac
done


# If the user did not use the arguments to specify the items to instantiate,
# then the envvar interface is used.  Set only those that are not.
# We use the long form for the default assignment because of an extremely
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
  test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files
  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
fi

# Have a temporary directory for convenience.  Make it in the build tree
# simply because there is no reason against having it here, and in addition,
# creating and moving files from /tmp can sometimes cause problems.
# Hook for its removal unless debugging.
# Note that there is a small window in which the directory will not be cleaned:
# after its creation but before its name has been assigned to '$tmp'.
# after its creation but before its name has been assigned to `$tmp'.
$debug ||
{
  tmp= ac_tmp=
  trap 'exit_status=$?
  : "${ac_tmp:=$tmp}"
  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
' 0
6767
6768
6769
6770
6771
6772
6773
6774

6775
6776
6777
6778
6779
6780
6781
5985
5986
5987
5988
5989
5990
5991

5992
5993
5994
5995
5996
5997
5998
5999







-
+







  tmp=./conf$$-$RANDOM
  (umask 077 && mkdir "$tmp")
} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
ac_tmp=$tmp

# Set up the scripts for CONFIG_FILES section.
# No need to generate them if there are no CONFIG_FILES.
# This happens for instance with './config.status config.h'.
# This happens for instance with `./config.status config.h'.
if test -n "$CONFIG_FILES"; then


ac_cr=`echo X | tr X '\015'`
# On cygwin, bash can eat \r inside `` if the user requested igncr.
# But we know of no other shell where ac_cr would be empty at this
# point, so we can use a bashism as a fallback.
6933
6934
6935
6936
6937
6938
6939
6940

6941
6942
6943
6944
6945
6946
6947
6151
6152
6153
6154
6155
6156
6157

6158
6159
6160
6161
6162
6163
6164
6165







-
+







for ac_tag
do
  case $ac_tag in
  :[FHLC]) ac_mode=$ac_tag; continue;;
  esac
  case $ac_mode$ac_tag in
  :[FHL]*:*);;
  :L* | :C*:*) as_fn_error $? "invalid tag '$ac_tag'" "$LINENO" 5;;
  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
  :[FH]-) ac_tag=-:-;;
  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
  esac
  ac_save_IFS=$IFS
  IFS=:
  set x $ac_tag
  IFS=$ac_save_IFS
6955
6956
6957
6958
6959
6960
6961
6962

6963
6964
6965
6966
6967
6968

6969
6970

6971
6972
6973
6974

6975
6976
6977
6978

6979
6980
6981
6982
6983


6984
6985
6986
6987
6988

6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005

7006
7007
7008
7009
7010
7011
7012
6173
6174
6175
6176
6177
6178
6179

6180
6181
6182
6183
6184
6185

6186
6187

6188
6189
6190
6191

6192
6193
6194
6195

6196
6197
6198
6199


6200
6201
6202
6203
6204
6205

6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222

6223
6224
6225
6226
6227
6228
6229
6230







-
+





-
+

-
+



-
+



-
+



-
-
+
+




-
+
















-
+







    ac_file_inputs=
    for ac_f
    do
      case $ac_f in
      -) ac_f="$ac_tmp/stdin";;
      *) # Look for the file first in the build tree, then in the source tree
	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
	 # because $ac_f cannot contain ':'.
	 # because $ac_f cannot contain `:'.
	 test -f "$ac_f" ||
	   case $ac_f in
	   [\\/$]*) false;;
	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
	   esac ||
	   as_fn_error 1 "cannot find input file: '$ac_f'" "$LINENO" 5;;
	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
      esac
      case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      as_fn_append ac_file_inputs " '$ac_f'"
    done

    # Let's still pretend it is 'configure' which instantiates (i.e., don't
    # Let's still pretend it is `configure' which instantiates (i.e., don't
    # use $as_me), people would be surprised to read:
    #    /* config.h.  Generated by config.status.  */
    configure_input='Generated from '`
	  printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	`' by configure.'
    if test x"$ac_file" != x-; then
      configure_input="$ac_file.  $configure_input"
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
printf "%s\n" "$as_me: creating $ac_file" >&6;}
      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
$as_echo "$as_me: creating $ac_file" >&6;}
    fi
    # Neutralize special characters interpreted by sed in replacement strings.
    case $configure_input in #(
    *\&* | *\|* | *\\* )
       ac_sed_conf_input=`printf "%s\n" "$configure_input" |
       ac_sed_conf_input=`$as_echo "$configure_input" |
       sed 's/[\\\\&|]/\\\\&/g'`;; #(
    *) ac_sed_conf_input=$configure_input;;
    esac

    case $ac_tag in
    *:-:* | *:-) cat >"$ac_tmp/stdin" \
      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
    esac
    ;;
  esac

  ac_dir=`$as_dirname -- "$ac_file" ||
$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$ac_file" : 'X\(//\)[^/]' \| \
	 X"$ac_file" : 'X\(//\)$' \| \
	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
printf "%s\n" X"$ac_file" |
$as_echo X"$ac_file" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
7022
7023
7024
7025
7026
7027
7028
7029

7030
7031

7032
7033
7034
7035
7036
7037
7038
6240
6241
6242
6243
6244
6245
6246

6247
6248

6249
6250
6251
6252
6253
6254
6255
6256







-
+

-
+







	  s/.*/./; q'`
  as_dir="$ac_dir"; as_fn_mkdir_p
  ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
7077
7078
7079
7080
7081
7082
7083
7084
7085


7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098

7099
7100
7101
7102
7103
7104
7105
6295
6296
6297
6298
6299
6300
6301


6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315

6316
6317
6318
6319
6320
6321
6322
6323







-
-
+
+












-
+







/@docdir@/p
/@infodir@/p
/@localedir@/p
/@mandir@/p'
case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
*datarootdir*) ac_datarootdir_seen=yes;;
*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
  ac_datarootdir_hack='
  s&@datadir@&$datadir&g
  s&@docdir@&$docdir&g
  s&@infodir@&$infodir&g
  s&@localedir@&$localedir&g
  s&@mandir@&$mandir&g
  s&\\\${datarootdir}&$datarootdir&g' ;;
esac
_ACEOF

# Neutralize VPATH when '$srcdir' = '.'.
# Neutralize VPATH when `$srcdir' = `.'.
# Shell code in configure.ac might set extrasub.
# FIXME: do we really want to maintain this feature?
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_sed_extra="$ac_vpsub
$extrasub
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
7120
7121
7122
7123
7124
7125
7126
7127

7128
7129

7130
7131
7132
7133
7134
7135
7136
6338
6339
6340
6341
6342
6343
6344

6345
6346

6347
6348
6349
6350
6351
6352
6353
6354







-
+

-
+







eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5

test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
      "$ac_tmp/out"`; test -z "$ac_out"; } &&
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable 'datarootdir'
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined.  Please make sure it is defined" >&5
printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable 'datarootdir'
$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
which seems to be undefined.  Please make sure it is defined" >&2;}

  rm -f "$ac_tmp/stdin"
  case $ac_file in
  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
  esac \
7169
7170
7171
7172
7173
7174
7175
7176
7177


7178
7179
7180
7181
6387
6388
6389
6390
6391
6392
6393


6394
6395
6396
6397
6398








-
-
+
+



-
  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
  exec 5>>config.log
  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
  # would make configure fail if this is the last instruction.
  $ac_cs_success || as_fn_exit 1
fi
if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
fi



Changes to win/configure.ac.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18




19
20
21
22
23
24
25
1
2
3
4
5



6
7
8
9
10
11
12
13




14
15
16
17
18
19
20
21
22
23
24





-
-
-
+
+






-
-
-
-
+
+
+
+







#! /bin/bash -norc
# This file is an input file used by the GNU "autoconf" program to
# generate the file "configure", which is run during Tk installation
# to configure the system for the local environment.

AC_INIT([tk],[9.0])
AC_CONFIG_SRCDIR([../generic/tk.h])
AC_PREREQ([2.69])
AC_INIT(../generic/tk.h)
AC_PREREQ(2.69)

# The following define is needed when building with Cygwin since newer
# versions of autoconf incorrectly set SHELL to /bin/bash instead of
# /bin/sh. The bash shell seems to suffer from some strange failures.
SHELL=/bin/sh

TK_VERSION=9.0
TK_MAJOR_VERSION=9
TK_MINOR_VERSION=0
TK_PATCH_LEVEL="b2"
TK_VERSION=8.7
TK_MAJOR_VERSION=8
TK_MINOR_VERSION=7
TK_PATCH_LEVEL="a0"
VER=$TK_MAJOR_VERSION$TK_MINOR_VERSION

#------------------------------------------------------------------------
# Handle the --prefix=... option
#------------------------------------------------------------------------

if test "${prefix}" = "NONE"; then
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63






64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83


84




85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112



113
114
115
116
117
118
119
120




121
122
123
124

125
126

127
128
129
130
131
132


133
134
135
136
137
138
139
140
141
142

143
144
145
146
147

148
149
150
151
152
153
154
155


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225

226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253

254
255

256
257
258
259
260

261
262

263
264
265
266

267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282






283
284



285


286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308



309
310
311
312
313
314
315
316
317
318
319
320
321
322

323
324

325
326
327
328
329
330
331
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84

85


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102




103
104
105
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121




122
123
124
125




126


127






128
129










130





131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150














































151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167



168


169











170

171
172
173
174





175
176

177
178




179


180
181
182
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199


200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232



233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259







-
+

















+
+
+
+
+
+















-
+
-

-
-
+
+

+
+
+
+










-
-
-
-












-
-
+
+
+




-
-
-
-
+
+
+
+
-
-
-
-
+
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+








+
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













+

-
+

-
-
-

-
-
+
-
-
-
-
-
-
-
-
-
-
-

-
+



-
-
-
-
-
+

-
+

-
-
-
-
+
-
-
+



-
+








+






-
-
+
+
+
+
+
+


+
+
+
-
+
+




















-
-
-
+
+
+
-













+


+







# the AC_PROG_CC macro from adding "-g -O2".
if test "${CFLAGS+set}" != "set" ; then
    CFLAGS=""
fi

AC_PROG_CC
AC_C_INLINE
AC_CHECK_INCLUDES_DEFAULT
AC_HEADER_STDC

AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib)
AC_CHECK_TOOL(RC, windres)

#--------------------------------------------------------------------
# Checks to see if the make program sets the $MAKE variable.
#--------------------------------------------------------------------

AC_PROG_MAKE_SET

#--------------------------------------------------------------------
# Determines the correct binary file extension (.o, .obj, .exe etc.)
#--------------------------------------------------------------------

AC_OBJEXT
AC_EXEEXT

#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
#--------------------------------------------------------------------

SC_ENABLE_THREADS

#--------------------------------------------------------------------
# The statements below define a collection of symbols related to
# building libtk as a shared library instead of a static library.
#--------------------------------------------------------------------

SC_ENABLE_SHARED

#--------------------------------------------------------------------
# Locate and source the tclConfig.sh file.
#--------------------------------------------------------------------

SC_PATH_TCLCONFIG($TK_PATCH_LEVEL)
SC_LOAD_TCLCONFIG

if test "${TCL_MAJOR_VERSION}" -lt 9 ; then
if test "${TCL_MAJOR_VERSION}" != "${TK_MAJOR_VERSION}"; then
if test "${TCL_MINOR_VERSION}" -lt 7; then
    AC_MSG_ERROR([${TCL_BIN_DIR}/tclConfig.sh is for Tcl ${TCL_VERSION}.
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.7+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.7 or better.])
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.6+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.6 or better.])
fi
if test "${TCL_MINOR_VERSION}" -lt 6; then
    AC_MSG_ERROR([${TCL_BIN_DIR}/tclConfig.sh is for Tcl ${TCL_VERSION}.
Tk ${TK_VERSION}${TK_PATCH_LEVEL} needs Tcl 8.6+.
Use --with-tcl= option to indicate location of tclConfig.sh file for Tcl 8.6 or better.])
fi

#--------------------------------------------------------------------
# The statements below define a collection of compile flags.  This
# macro depends on the value of SHARED_BUILD, and should be called
# after SC_ENABLE_SHARED checks the configure switches.
#--------------------------------------------------------------------

SC_CONFIG_CFLAGS

AC_CHECK_TYPES([intptr_t, uintptr_t],,,[[
#include <stdint.h>
]])

#--------------------------------------------------------------------
# man2tcl needs this so that it can use errno.h
#--------------------------------------------------------------------

AC_CHECK_HEADER(errno.h, , MAN2TCLFLAGS="-DNO_ERRNO_H")
AC_SUBST(MAN2TCLFLAGS)

#-------------------------------------------
#     Check for _strtoi64
#-------------------------------------------

AC_CACHE_CHECK([availability of _strtoi64], tcl_cv_strtoi64, [
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
    [[_strtoi64(0,0,0)]])],[tcl_cv_strtoi64=yes],[tcl_cv_strtoi64=no])])
    AC_TRY_LINK([#include <stdlib.h>],
	    [_strtoi64(0,0,0)],
	    tcl_cv_strtoi64=yes, tcl_cv_strtoi64=no)])
if test $tcl_cv_strtoi64 = no; then
    AC_DEFINE(NO_STRTOI64, 1, [Is _strtoi64 function available?])
fi

AC_CHECK_TYPE([intptr_t], [
    AC_DEFINE([HAVE_INTPTR_T], 1, [Do we have the intptr_t type?])], [
    AC_CACHE_CHECK([for pointer-size signed integer type], tcl_cv_intptr_t, [
    for tcl_cv_intptr_t in "int" "long" "__int64" none; do
#--------------------------------------------------------------------
# Windows XP theme engine header for Ttk
#--------------------------------------------------------------------

	if test "$tcl_cv_intptr_t" != none; then
	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
		    [[sizeof (void *) <= sizeof ($tcl_cv_intptr_t)]])],
		[tcl_ok=yes], [tcl_ok=no])
AC_CHECK_HEADER([uxtheme.h], [AC_DEFINE(HAVE_UXTHEME_H)],
	    test "$tcl_ok" = yes && break; fi
    done])
	[AC_MSG_NOTICE([xpnative theme will be unavailable])],
    if test "$tcl_cv_intptr_t" != none; then
	AC_DEFINE_UNQUOTED([intptr_t], [$tcl_cv_intptr_t], [Signed integer
	   type wide enough to hold a pointer.])
    fi
])
AC_CHECK_TYPE([uintptr_t], [
	[#include <windows.h>])
AC_CHECK_HEADER([vssym32.h], [AC_DEFINE(HAVE_VSSYM32_H)], [],
    AC_DEFINE([HAVE_UINTPTR_T], 1, [Do we have the uintptr_t type?])], [
    AC_CACHE_CHECK([for pointer-size unsigned integer type], tcl_cv_uintptr_t, [
    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned __int64" \
	    none; do
	if test "$tcl_cv_uintptr_t" != none; then
	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
		    [[sizeof (void *) <= sizeof ($tcl_cv_uintptr_t)]])],
		[tcl_ok=yes], [tcl_ok=no])
	    test "$tcl_ok" = yes && break; fi
    done])
	[#include <windows.h>
    if test "$tcl_cv_uintptr_t" != none; then
	AC_DEFINE_UNQUOTED([uintptr_t], [$tcl_cv_uintptr_t], [Unsigned integer
	   type wide enough to hold a pointer.])
    fi
])
#include <uxtheme.h>])

#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------

SC_ENABLE_SYMBOLS

TK_DBGX=${DBGX}

#--------------------------------------------------------------------
# Embed the manifest if we can determine how
#--------------------------------------------------------------------

SC_EMBED_MANIFEST(wish.exe.manifest)

SC_BUILD_TCLSH
SC_PROG_TCLSH

#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
AC_ARG_ENABLE(zipfs,
    AS_HELP_STRING([--enable-zipfs],
	[build with Zipfs support (default: on)]),
    [tcl_ok=$enableval], [tcl_ok=yes])
if test "$tcl_ok" = "yes" ; then
    #
    # Find a native compiler
    #
    AX_CC_FOR_BUILD
    #
    # Find a native zip implementation
    #
    SC_ZIPFS_SUPPORT
	ZIPFS_BUILD=1
	TK_ZIP_FILE=libtk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${TK_PATCH_LEVEL}.zip
else
	ZIPFS_BUILD=0
	TCL_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
AC_MSG_CHECKING([for building with zipfs])
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;
       AC_DEFINE(ZIPFS_BUILD, 2, [Are we building with zipfs enabled?])
       INSTALL_LIBRARIES=install-libraries-zipfs-static
       AC_MSG_RESULT([yes])
     else
       AC_DEFINE(ZIPFS_BUILD, 1, [Are we building with zipfs enabled?])\
       INSTALL_LIBRARIES=install-libraries-zipfs-shared
       AC_MSG_RESULT([yes])
    fi
else
AC_MSG_RESULT([no])
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi
AC_SUBST(ZIPFS_BUILD)
AC_SUBST(TK_ZIP_FILE)
AC_SUBST(INSTALL_LIBRARIES)
AC_SUBST(INSTALL_MSGS)


#------------------------------------------------------------------------
# tkConfig.sh refers to this by a different name
#------------------------------------------------------------------------

TK_SHARED_BUILD=${SHARED_BUILD}

#--------------------------------------------------------------------
# Perform final evaluations of variables with possible substitutions.
#--------------------------------------------------------------------

TK_SHARED_LIB_SUFFIX="\${NODOT_VERSION}${DLLSUFFIX}"
TK_UNSHARED_LIB_SUFFIX="\${NODOT_VERSION}${LIBSUFFIX}"
TK_EXPORT_FILE_SUFFIX="\${NODOT_VERSION}${LIBSUFFIX}"

eval "TK_SRC_DIR=\"`cd $srcdir/..; $CYGPATH $(pwd)`\""
eval "TK_SRC_DIR=\"`cd $srcdir/..; pwd`\""

eval "TK_DLL_FILE_TCL8=tk$VER${DLLSUFFIX}"
eval "TK_DLL_FILE_TCL9=tcl9tk$VER${DLLSUFFIX}"
if test ${TCL_MAJOR_VERSION} = 8 ; then
eval "TK_DLL_FILE=tk$VER${DLLSUFFIX}"
if test ${SHARED_BUILD} = 0 -o "$GCC" != "yes" ; then
 eval "TK_LIB_FILE=${LIBPREFIX}tk${VER}${LIBSUFFIX}"
eval "TK_LIB_FILE=${LIBPREFIX}tk$VER${LIBSUFFIX}"
else
 eval "TK_LIB_FILE=${LIBPREFIX}tk${VER}${DLLSUFFIX}.a"
fi
else
eval "TK_DLL_FILE=tcl9tk$VER${DLLSUFFIX}"
if test ${SHARED_BUILD} = 0 -o "$GCC" != "yes" ; then
 eval "TK_LIB_FILE=${LIBPREFIX}tcl9tk${VER}${LIBSUFFIX}"
else
 eval "TK_LIB_FILE=${LIBPREFIX}tcl9tk${VER}${DLLSUFFIX}.a"
fi
fi

eval "TK_STUB_LIB_FILE=${LIBPREFIX}tkstub${LIBSUFFIX}" ;
eval "TK_STUB_LIB_FILE=${LIBPREFIX}tkstub${VER}${LIBSUFFIX}"
# FIXME: All of this var junk needs to be done in tcl.m4 !!!!
# I left out the other vars that also need to get defined here.
# we also need to double check about spaces in path names
TK_LIB_FLAG="-l"
if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
    TK_LIB_FLAG="${TK_LIB_FLAG}tcl9"
fi
eval "TK_LIB_FLAG=\"${TK_LIB_FLAG}${VER}${LIBFLAGSUFFIX}\""
eval "TK_LIB_FLAG=\"-ltk${VER}${LIBFLAGSUFFIX}\""
TK_LIB_SPEC="-L${libdir} ${TK_LIB_FLAG}"
eval "TK_BUILD_LIB_SPEC=\"-L`$CYGPATH $(pwd)` ${TK_LIB_FLAG}\""
TK_BUILD_LIB_SPEC="-L`pwd` ${TK_LIB_FLAG}"

if test "${TCL_MAJOR_VERSION}" -gt 8 ; then
    eval "TK_STUB_LIB_FLAG=\"-ltkstub${LIBFLAGSUFFIX}\""
else
    eval "TK_STUB_LIB_FLAG=\"-ltkstub${VER}${LIBFLAGSUFFIX}\""
eval "TK_STUB_LIB_FLAG=\"-ltkstub${VER}${LIBFLAGSUFFIX}\""
fi
eval "TK_BUILD_STUB_LIB_SPEC=\"-L`$CYGPATH $(pwd)` ${TK_STUB_LIB_FLAG}\""
TK_BUILD_STUB_LIB_SPEC="-L`pwd` ${TK_STUB_LIB_FLAG}"

TK_STUB_LIB_SPEC="-L${libdir} ${TK_STUB_LIB_FLAG}"
TK_STUB_LIB_PATH="${libdir}/${TK_STUB_LIB_FILE}"
eval "TK_BUILD_STUB_LIB_PATH=\"`$CYGPATH $(pwd)`/${TK_STUB_LIB_FILE}\""
TK_BUILD_STUB_LIB_PATH="`pwd`/${TK_STUB_LIB_FILE}"

eval "DLLSUFFIX=${DLLSUFFIX}"
eval "LIBPREFIX=${LIBPREFIX}"
eval "LIBSUFFIX=${LIBSUFFIX}"
eval "EXESUFFIX=${EXESUFFIX}"

CFG_TK_SHARED_LIB_SUFFIX=${TK_SHARED_LIB_SUFFIX}
CFG_TK_UNSHARED_LIB_SUFFIX=${TK_UNSHARED_LIB_SUFFIX}
CFG_TK_EXPORT_FILE_SUFFIX=${TK_EXPORT_FILE_SUFFIX}

#--------------------------------------------------------------------
# Adjust the defines for how the resources are built depending
# on symbols and static vs. shared.
#--------------------------------------------------------------------

if test ${SHARED_BUILD} = 0; then
    RC_DEFINES="${RC_DEFINE} STATIC_BUILD"
if test ${SHARED_BUILD} = 0 -o "$TCL_NEEDS_EXP_FILE" = 0; then
    if test "${DBGX}" = "d"; then
        RC_DEFINES="${RC_DEFINE} STATIC_BUILD ${RC_DEFINE} DEBUG"
    else
        RC_DEFINES="${RC_DEFINE} STATIC_BUILD"
    fi
    TK_RES=""
else
    if test "${DBGX}" = "d"; then
        RC_DEFINES="${RC_DEFINE} DEBUG"
    else
    RC_DEFINES=""
        RC_DEFINES=""
    fi
    TK_RES='tk.$(RES)'
fi

# The wish.exe.manifest requires these
# TK_WIN_VERSION is the 4 dotted pair Windows version format which needs
# the release level, and must account for interim release versioning
case "$TK_PATCH_LEVEL" in
     *a*) TK_RELEASE_LEVEL=0 ;;
     *b*) TK_RELEASE_LEVEL=1 ;;
     *)   TK_RELEASE_LEVEL=2 ;;
esac
TK_WIN_VERSION="$TK_VERSION.$TK_RELEASE_LEVEL.`echo $TK_PATCH_LEVEL | tr -d ab.`"
AC_SUBST(TK_WIN_VERSION)
# X86|AMD64|IA64 for manifest
AC_SUBST(MACHINE)

AC_SUBST(TK_VERSION)
AC_SUBST(TK_MAJOR_VERSION)
AC_SUBST(TK_MINOR_VERSION)
AC_SUBST(TK_PATCH_LEVEL)
AC_SUBST(TK_LIB_FILE)
AC_SUBST(TK_DLL_FILE)
AC_SUBST(TK_DLL_FILE_TCL8)
AC_SUBST(TK_DBGX)
AC_SUBST(TK_LIB_FILE)
AC_SUBST(TK_DLL_FILE)
AC_SUBST(TK_DLL_FILE_TCL9)
AC_SUBST(TK_STUB_LIB_FILE)
AC_SUBST(TK_STUB_LIB_FLAG)
AC_SUBST(TK_BUILD_STUB_LIB_SPEC)
AC_SUBST(TK_SRC_DIR)
AC_SUBST(TK_BIN_DIR)

AC_SUBST(TCL_VERSION)
AC_SUBST(TCL_MAJOR_VERSION)
AC_SUBST(TCL_MINOR_VERSION)
AC_SUBST(TCL_PATCH_LEVEL)

AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TCL_BIN_DIR)
AC_SUBST(TCL_DBGX)
AC_SUBST(CFG_TK_SHARED_LIB_SUFFIX)
AC_SUBST(CFG_TK_UNSHARED_LIB_SUFFIX)
AC_SUBST(CFG_TK_EXPORT_FILE_SUFFIX)

AC_SUBST(CFLAGS_DEFAULT)
AC_SUBST(EXTRA_CFLAGS)
AC_SUBST(CYGPATH)
AC_SUBST(DEPARG)
AC_SUBST(CC_OBJNAME)
AC_SUBST(CC_EXENAME)
375
376
377
378
379
380
381
382

383
384
385
386

387
303
304
305
306
307
308
309

310

311
312

313
314







-
+
-


-
+

AC_SUBST(RC_OUT)
AC_SUBST(RC_TYPE)
AC_SUBST(RC_INCLUDE)
AC_SUBST(RC_DEFINE)
AC_SUBST(RC_DEFINES)
AC_SUBST(RES)

AC_CONFIG_FILES([Makefile tkConfig.sh wish.exe.manifest])
AC_OUTPUT(Makefile tkConfig.sh wish.exe.manifest)
AC_OUTPUT

dnl Local Variables:
dnl mode: autoconf
dnl mode: autoconf;
dnl End:

Deleted win/gitmanifest.in.

1

-
git-

Changes to win/makefile.vc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16








17
18




19
20
21
22
23
24
25
26














27
28

29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48


49
50
51
52
53
54






55
56
57
58








59
60











61
62
63
64
65
66
67
68
69
70
71
72





























73


74
75
76







77
78











79
80

81
82
83
84









85
86
87
88
89
90


















91



92
93
94






95
96
97

98
99


100
101
102
103
104
105
106

107

108



109

110


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128





129
130
131
132






133
134
135


136

137

138
139

140
141






142
143
144

145
146
147
148
149
150
151
152
153
154
155


156
157
158
159
160
161
162
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23


24
25
26
27
28







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67





68
69
70
71
72
73
74



75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94












95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126


127
128
129
130
131
132
133


134
135
136
137
138
139
140
141
142
143
144


145




146
147
148
149
150
151
152
153
154






155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176



177
178
179
180
181
182

183
184
185


186
187
188
189
190
191
192
193

194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210






211

212



213
214
215
216
217
218



219
220
221
222
223
224



225
226
227
228

229
230

231
232
233
234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251


252
253
254
255
256
257
258
259
260













-


+
+
+
+
+
+
+
+
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+






-
+













+
+

-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
-

+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+

-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
-
-
-
+
+
+
+
+
+
-


+
-
-
+
+






-
+

+

+
+
+
-
+

+
+






-
-
-
-
-
-

-

-
-
-
+
+
+
+
+

-
-
-
+
+
+
+
+
+
-
-
-
+
+

+
-
+

-
+


+
+
+
+
+
+


-
+









-
-
+
+







#------------------------------------------------------------- -*- makefile -*-
# makefile.vc --
#
#	Microsoft Visual C++ makefile for use with nmake.exe v1.62+ (VC++ 5.0+)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Ajuba Solutions.
# Copyright (c) 2001-2005 ActiveState Corporation.
# Copyright (c) 2001-2004 David Gravereaux.
# Copyright (c) 2003-2008 Pat Thoyts.
# Copyright (c) 2017 Ashok P. Nadkarni
#------------------------------------------------------------------------------

# Check to see we are configured to build with MSVC (MSDEVDIR, MSVCDIR or
# VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir)
!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(VCINSTALLDIR) && !defined(MSSDK) && !defined(WINDOWSSDKDIR)
MSG = ^
You need to run vcvars32.bat from Developer Studio or setenv.bat from the^
Platform SDK first to setup the environment.  Jump to this line to read^
the build instructions.
!error $(MSG)
# General usage:
#   nmake [-nologo] -f makefile.vc [TARGET|MACRODEF [TARGET|MACRODEF] [...]]
!endif

#------------------------------------------------------------------------------
# HOW TO USE this makefile:
#
# For MACRODEF, see TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md)
# or examine Sections 7-9 in rules.vc. This makefile has the following
# values for the OPTS macro in addition to the ones described there.
#       noembed  = Embeds Tcl scripts into the wish executable. Currently only
#                  applicable for static builds. Non-static builds currently
#                  never embed.
#	square   = Include the demo square widget.
# 1)  It is now necessary to have MSVCDir, MSDevDir or MSSDK set in the
#     environment.  This is used as a check to see if vcvars32.bat had been
#     run prior to running nmake or during the installation of Microsoft
#     Visual C++, MSVCDir had been set globally and the PATH adjusted.
#     Either way is valid.
#
#     You'll need to run vcvars32.bat contained in the MsDev's vc(98)/bin
#     directory to setup the proper environment, if needed, for your
#     current setup.  This is a needed bootstrap requirement and allows the
#     swapping of different environments to be easier.
#
# 2)  To use the Platform SDK (not expressly needed), run setenv.bat after
#     vcvars32.bat according to the instructions for it.  This can also
#     turn on the 64-bit compiler, if your SDK has it.
#
# Possible values for TARGET are:
# 3)  Targets are:
#	release  -- Builds the core, the shell and the dlls. (default)
#	dlls     -- Just builds the windows extensions.
#	shell    -- Just builds the shell and the core.
#	core     -- Only builds the core [tkXX.(dll|lib)].
#	all      -- Builds everything.
#	test     -- Builds and runs the test suite.
#	tktest   -- Just builds the test shell.
#	tktest   -- Just builds the binaries for the test suite.
#	install  -- Installs the built binaries and libraries to $(INSTALLDIR)
#		    as the root of the install tree.
#	cwish    -- Builds a console version of wish.
#	tidy/clean/hose -- varying levels of cleaning.
#	genstubs -- Rebuilds the Stubs table and support files (dev only).
#	depend   -- Generates an accurate set of source dependancies for this
#		    makefile.  Helpful to avoid problems when the sources are
#		    refreshed and you rebuild, but can "overbuild" when common
#		    headers like tkInt.h just get small changes.
#	htmlhelp -- Builds a Windows .chm help file for Tcl and Tk from the
#		    troff manual pages found in $(ROOT)\doc. You need to
#		    have installed the HTML Help Compiler package from Microsoft
#		    to produce the .chm file.
#	winhelp  -- Builds the windows .hlp file for Tcl from the troff man
#		    files found in $(ROOT)\doc.
#
# The steps to setup a Visual C++ environment depend on which
# version of Visual Studio and/or the Windows SDK you are building
# against and are not described here. The simplest method is generally
# to start a command shell using one of the short cuts installed by
# Visual Studio/Windows SDK for the appropriate target architecture.
# 4)  Macros usable on the commandline:
#	TCLDIR=<path>
#		Sets the location for where to find the Tcl headers and
#		libraries.  The install point is assumed when not specified.
#		Tk does need the source directory, though.  Tk comes very close
#		to not needing the sources, but does, in fact, require them.
#
# NOTE: For older (Visual C++ 6 or the 2003 SDK), to use the Platform
# SDK (not expressly needed), run setenv.bat after vcvars32.bat
# according to the instructions for it.  This can also turn on the
#	INSTALLDIR=<path>
#		Sets where to install Tcl from the built binaries.
#		C:\Progra~1\Tcl is assumed when not specified.
#
#	OPTS=loimpact,msvcrt,nothreads,noxp,pdbs,profile,square,static,staticpkg,symbols,unchecked,none
#		Sets special options for the core.  The default is for none.
#		Any combination of the above may be used (comma separated).
#		'none' will over-ride everything to nothing.
# 64-bit compiler, if your SDK has it.
#
#		loimpact = Adds a flag for how NT treats the heap to keep memory
#			   in use, low.  This is said to impact alloc performance.
#		msvcrt   = Affects the static option only to switch it from
#			   using libcmt(d) as the C runtime [by default] to
#			   msvcrt(d). This is useful for static embedding
#			   support.
#		nothreads= Turns off full multithreading support.
#		noxp     = If you do not have the uxtheme.h header then you
#                          cannot include support for XP themeing.
#		square   = Include the demo square widget.
#		static   = Builds a static library of the core instead of a
# Examples:
# Assuming Tcl sources lie in ../../tcl
#       c:\tcl_src\win\>nmake -f makefile.vc release
# If Tcl sources are not in ../../tcl, use the TCLDIR macro to specify dir
#       c:\tcl_src\win\>nmake -f makefile.vc release TCLDIR=c:\src\tcl
# Run the test suite
#       c:\tcl_src\win\>nmake -f makefile.vc test
# Install Tk in location specified by INSTALLDIR macro
#       c:\tcl_src\win\>nmake -f makefile.vc install INSTALLDIR=c:\progra~1\tcl
# Build release with PDB files
#       c:\tcl_src\win\>nmake -f makefile.vc release OPTS=pdbs
# Build debug version
#			   dll.  The shell will be static (and large), as well.
#		staticpkg= Affects the static option only to switch wishXX.exe
#			   to have the dde and reg extension linked inside it.
#		pdbs     = Build detached symbols for release builds.
#		profile  = Adds profiling hooks.  Map file is assumed.
#		thrdalloc = Use the thread allocator (shared global free pool)
#			   This is the default on threaded builds.
#		tclalloc = Use the old non-thread allocator
#		symbols  = Debug build. Links to the debug C runtime, disables
#			   optimizations and creates pdb symbols files.
#		unchecked = Allows a symbols build to not use the debug
#			   enabled runtime (msvcrt.dll not msvcrtd.dll
#			   or libcmt.lib not libcmtd.lib).
#
#	STATS=compdbg,memdbg,none
#		Sets optional memory and bytecode compiler debugging code added
#		to the core.  The default is for none.  Any combination of the
#		above may be used (comma separated).  'none' will over-ride
#		everything to nothing.
#
#		compdbg  = Enables byte compilation logging.
#		memdbg   = Enables the debugging memory allocator.
#
#	CHECKS=64bit,fullwarn,nodep,none
#		Sets special macros for checking compatability.
#
#		64bit    = Enable 64bit portability warnings (if available)
#		fullwarn = Builds with full compiler and link warnings enabled.
#			    Very verbose.
#       c:\tcl_src\win\>nmake -f makefile.vc release OPTS=symbols
#		nodep	 = Turns off compatability macros to ensure the core
#			    isn't being built with deprecated functions.
#
###############################################################################

#	MACHINE=(ALPHA|AMD64|IA64|IX86)
#		Set the machine type used for the compiler, linker, and
#		resource compiler.  This hook is needed to tell the tools
#		when alternate platforms are requested.  IX86 is the default
#		when not specified. If the CPU environment variable has been
#		set (ie: recent Platform SDK) then MACHINE is set from CPU.
#
# The PROJECT macro is used by rules.vc for generating appropriate
# macros and rules.
#	TMP_DIR=<path>
#	OUT_DIR=<path>
#		Hooks to allow the intermediate and output directories to be
#		changed.  $(OUT_DIR) is assumed to be
#		$(BINROOT)\(Release|Debug) based on if symbols are requested.
#		$(TMP_DIR) will de $(OUT_DIR)\<buildtype> by default.
#
#	TESTPAT=<file>
#		Reads the tests requested to be run from this file.
#
# 5)  Examples:
PROJECT = tk

#
# Default target to build if no target is specified. If unspecified, the
# rules.vc file will set up "all" as the target.
DEFAULT_BUILD_TARGET = release

#	Basic syntax of calling nmake looks like this:
#	nmake [-nologo] -f makefile.vc [target|macrodef [target|macrodef] [...]]
#
#                        Standard (no frills)
#       c:\tk_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
#       Setting environment for using Microsoft Visual C++ tools.
#       c:\tk_src\win\>nmake -f makefile.vc release
#       c:\tk_src\win\>nmake -f makefile.vc install INSTALLDIR=c:\progra~1\tcl
#
# We have a custom resource file
RCFILE = tk.rc

# The rules.vc file does much of the hard work in terms of defining
# the build configuration, macros, output directories etc.
!include "rules-ext.vc"
#                         Building for Win64
#       c:\tk_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
#       Setting environment for using Microsoft Visual C++ tools.
#       c:\tk_src\win\>c:\progra~1\platfo~1\setenv.bat /pre64 /RETAIL
#       Targeting Windows pre64 RETAIL
#       c:\tk_src\win\>nmake -f makefile.vc MACHINE=IA64
#
#------------------------------------------------------------------------------
#==============================================================================
###############################################################################


#    //==================================================================\\
#   >>[               -> Do not modify below this line. <-               ]<<
#   >>[  Please, use the commandline macros to modify how Tcl is built.  ]<<
#   >>[  If you need more features, send us a patch for more macros.     ]<<
#    \\==================================================================//


###############################################################################
#==============================================================================
#------------------------------------------------------------------------------
!if ($(TCL_MAJOR_VERSION) > 8) || ($(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) > 6)
USING_PRE87_TCL = 0
!else

!if !exist("makefile.vc")
MSG = ^
You must run this makefile only from the directory it is in.^
Please `cd` to its location first.
!error $(MSG)
USING_PRE87_TCL = 1
!endif

PROJECT = tk
# TCLINSTALL is set to 1 by rules.vc to indicate we are building against
# an installed Tcl and 0 if building against Tcl source. Tk needs the latter.
!include "rules.vc"

!if $(TCLINSTALL)
!message *** Warning: Tk requires the source distribution of Tcl to build from,
!message ***    at this time, sorry.  Please set the TCLDIR macro to point to the
!message ***    Tcl sources.
!endif

# Extra makefile options processing for non-standard OPTS values ...
# Extra makefile options processing...
!if "$(OPTS)" == "" || [nmakehlp -f "$(OPTS)" "none"]
HAVE_UXTHEME_H    = 1
TTK_SQUARE_WIDGET = 0
!else
!if [nmakehlp -f $(OPTS) "noxp"]
!message *** Exclude support for XP theme
TK_EMBED_SCRIPTS  = 1
HAVE_UXTHEME_H  = 0
!else
HAVE_UXTHEME_H  = 1
!endif
!if [nmakehlp -f "$(OPTS)" "square"]
!message *** Include ttk square demo widget
TTK_SQUARE_WIDGET   = 1
!else
TTK_SQUARE_WIDGET   = 0
!endif
!if [nmakehlp -f $(OPTS) "noembed"]
!message *** Option noembed specified. Tk script library will not be appended to the binary.
TK_EMBED_SCRIPTS = 0
!else
!message *** Tk script library will be appended to the binary.
TK_EMBED_SCRIPTS = 1
!endif
!endif

!if $(USING_PRE87_TCL)
TK_EMBED_SCRIPTS = 0
!endif
STUBPREFIX = $(PROJECT)stub
WISHNAMEPREFIX = wish

BINROOT		= $(MAKEDIR)     # originally .
ROOT		= $(MAKEDIR)\..  # originally ..

TK_NO_DEPRECATED = 0
!if "$(CHECKS)" != "" && ![nmakehlp -f "$(CHECKS)" "none"]
!if [nmakehlp -f $(CHECKS) "nodep"]
TK_LIBRARY	= $(ROOT)\library

TKIMPLIB	= "$(OUT_DIR)\$(PROJECT)$(TK_VERSION)$(SUFX).lib"
TKLIBNAME	= $(PROJECT)$(TK_VERSION)$(SUFX).$(EXT)
TKLIB		= "$(OUT_DIR)\$(TKLIBNAME)"

TK_NO_DEPRECATED = 1
!endif
!endif
TKSTUBLIBNAME	= $(STUBPREFIX)$(TK_VERSION).lib
TKSTUBLIB	= "$(OUT_DIR)\$(TKSTUBLIBNAME)"

WISH 		= "$(OUT_DIR)\$(WISHNAMEPREFIX)$(TK_VERSION)$(SUFX).exe"
WISHC 		= "$(OUT_DIR)\$(WISHNAMEPREFIX)c$(VERSION)$(SUFX).exe"
WISHC 		= "$(OUT_DIR)\$(WISHNAMEPREFIX)c$(TK_VERSION)$(SUFX).exe"

TKTEST		= "$(OUT_DIR)\$(PROJECT)test$(VERSION)$(SUFX).exe"
TKTEST		= "$(OUT_DIR)\$(PROJECT)test.exe"
CAT32		= "$(OUT_DIR)\cat32.exe"

LIB_INSTALL_DIR		= $(_INSTALLDIR)\lib
BIN_INSTALL_DIR		= $(_INSTALLDIR)\bin
DOC_INSTALL_DIR		= $(_INSTALLDIR)\doc
SCRIPT_INSTALL_DIR	= $(_INSTALLDIR)\lib\$(PROJECT)$(TK_DOTVERSION)
INCLUDE_INSTALL_DIR	= $(_INSTALLDIR)\include

WISHOBJS = \
	$(TMP_DIR)\winMain.obj \
!if $(STATIC_BUILD) && !$(STATIC_BUILD)
!if $(TCL_USE_STATIC_PACKAGES)
	$(TCLDDELIB) \
	$(TCLREGLIB) \
!endif
	$(TMP_DIR)\wish.res

TKTESTOBJS = \
	$(TMP_DIR)\testMain.obj \
	$(TMP_DIR)\tkSquare.obj \
	$(TMP_DIR)\tkTest.obj \
	$(TMP_DIR)\tkWinTest.obj \
	$(TMP_DIR)\tktest.res
	$(TMP_DIR)\tkOldTest.obj \
	$(TMP_DIR)\tkWinTest.obj

XLIBOBJS = \
	$(TMP_DIR)\xcolors.obj \
	$(TMP_DIR)\xdraw.obj \
	$(TMP_DIR)\xgc.obj \
	$(TMP_DIR)\ximage.obj \
	$(TMP_DIR)\xutil.obj
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
271
272
273
274
275
276
277


278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294







-
-










-







	$(TMP_DIR)\tkWinColor.obj \
	$(TMP_DIR)\tkWinConfig.obj \
	$(TMP_DIR)\tkWinCursor.obj \
	$(TMP_DIR)\tkWinDialog.obj \
	$(TMP_DIR)\tkWinDraw.obj \
	$(TMP_DIR)\tkWinEmbed.obj \
	$(TMP_DIR)\tkWinFont.obj \
	$(TMP_DIR)\tkWinGDI.obj \
	$(TMP_DIR)\tkWinIco.obj \
	$(TMP_DIR)\tkWinImage.obj \
	$(TMP_DIR)\tkWinInit.obj \
	$(TMP_DIR)\tkWinKey.obj \
	$(TMP_DIR)\tkWinMenu.obj \
	$(TMP_DIR)\tkWinPixmap.obj \
	$(TMP_DIR)\tkWinPointer.obj \
	$(TMP_DIR)\tkWinRegion.obj \
	$(TMP_DIR)\tkWinScrlbr.obj \
	$(TMP_DIR)\tkWinSend.obj \
	$(TMP_DIR)\tkWinSendCom.obj \
	$(TMP_DIR)\tkWinSysTray.obj \
	$(TMP_DIR)\tkWinWindow.obj \
	$(TMP_DIR)\tkWinWm.obj \
	$(TMP_DIR)\tkWinX.obj \
	$(TMP_DIR)\stubs.obj \
	$(TMP_DIR)\tk3d.obj \
	$(TMP_DIR)\tkArgv.obj \
	$(TMP_DIR)\tkAtom.obj \
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
319
320
321
322
323
324
325

326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354







-






-
















-







	$(TMP_DIR)\tkFont.obj \
	$(TMP_DIR)\tkFrame.obj \
	$(TMP_DIR)\tkGC.obj \
	$(TMP_DIR)\tkGeometry.obj \
	$(TMP_DIR)\tkGet.obj \
	$(TMP_DIR)\tkGrab.obj \
	$(TMP_DIR)\tkGrid.obj \
	$(TMP_DIR)\tkIcu.obj \
	$(TMP_DIR)\tkImage.obj \
	$(TMP_DIR)\tkImgBmap.obj \
	$(TMP_DIR)\tkImgListFormat.obj \
	$(TMP_DIR)\tkImgGIF.obj \
	$(TMP_DIR)\tkImgPNG.obj \
	$(TMP_DIR)\tkImgPPM.obj \
	$(TMP_DIR)\tkImgSVGnano.obj \
	$(TMP_DIR)\tkImgPhoto.obj \
	$(TMP_DIR)\tkImgPhInstance.obj \
	$(TMP_DIR)\tkImgUtil.obj \
	$(TMP_DIR)\tkListbox.obj \
	$(TMP_DIR)\tkMacWinMenu.obj \
	$(TMP_DIR)\tkMain.obj \
	$(TMP_DIR)\tkMain2.obj \
	$(TMP_DIR)\tkMenu.obj \
	$(TMP_DIR)\tkMenubutton.obj \
	$(TMP_DIR)\tkMenuDraw.obj \
	$(TMP_DIR)\tkMessage.obj \
	$(TMP_DIR)\tkPanedWindow.obj \
	$(TMP_DIR)\tkObj.obj \
	$(TMP_DIR)\tkOldConfig.obj \
	$(TMP_DIR)\tkOption.obj \
	$(TMP_DIR)\tkPack.obj \
	$(TMP_DIR)\tkPkgConfig.obj \
	$(TMP_DIR)\tkPlace.obj \
	$(TMP_DIR)\tkPointer.obj \
	$(TMP_DIR)\tkRectOval.obj \
	$(TMP_DIR)\tkScale.obj \
	$(TMP_DIR)\tkScrollbar.obj \
	$(TMP_DIR)\tkSelect.obj \
	$(TMP_DIR)\tkStyle.obj \
314
315
316
317
318
319
320
321
322



323
324
325
326

327
328
329
330

331
332
333
334
335


336
337
338
339







340
341

342






















































343
344














345
346



347








348



349
350





















351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462




463



464
465
466


467
468
469
470
471

472
473

474
475
476
477
478


479
480
481
482
483
484

485
486
487
488

489
490
491
492
493

494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530


531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552

553
554
555


556
557
558

559
560
561
562
563
564
565
566
567

568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588


















589
590
591
592
593
594

























595



















596
597
598

























599

600
601
602
603
604
605
606
607
608



609
610
611

612
613
614

615
616
617
618
619


620
621
622


623
624
625

626
627
628
629
630



631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646
647
648
649

650
651
652
653
654

655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675


676
677
678
679
680
681
682
683
684
685

686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703



704



705
706
707
708



709



710
711
712
713
714

715
716







717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741

742
743
744
745
746
747
748
749
750
751
752
753
754




755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

776
777
778
779
780
781






782
783
784


785
786
787
788
789
790
791
792
793
794
795
796
797

798
799
800
801
802
803
804
805
806
807
808
809
810















811
812
813
814





406
407
408
409
410
411
412


413
414
415
416
417
418

419




420

421



422
423
424



425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488


489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
516
517
518
519


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555



556
557
558














559



560
561

562
563
564
565
566

567
568
569
570
571
572
573
574
575
576
577

578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618
619
620
621
622
623

624
625
626
627
628
629
630
631
632
633
634
635
636

637
638
639
640
641

642
643
644
645

646

647


648
649
650
651


652
653

654

655
656

657
658
659
660

661
662
663
664
665

666
667
668
669
670

671
672
673












674














675


676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

691
692
693
694
695
696
697

698



699
700
701
702

703
704
705
706
707
708
709
710
711

712
713
714
715
716
717
718

719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751






752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821

822
823
824
825
826
827




828
829
830
831
832

833



834


835


836
837
838


839
840
841
842

843
844




845
846
847
848
849
850


851







852
853
854
855
856
857

858
859


860

861
862
863

864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880


881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914

915
916
917
918
919
920
921
922
923
924

925
926
927
928
929
930
931

932
933
934
935
936
937
938
939
940
941
942
943
944

945
946
947
948
949
950
951
952
953
954
955
956

957
958
959
960
961
962
963
964

965
966
967











968
969
970
971


972
973
974
975
976
977
978
979
980
981
982
983
984




985

986
987





988
989
990
991
992
993



994
995

996
997
998
999
1000
1001
1002



1003

1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032



1033
1034
1035
1036
1037







-
-
+
+
+



-
+
-
-
-
-
+
-

-
-
-
+
+

-
-
-
+
+
+
+
+
+
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
-
+
+
+
+
+
+
+
+

+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








+






-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-


-





-
+










-
+










-
+










-
+










-
+












-
+








+
+
+
+
-
+
+
+


-
+
+


-

-
+
-
-
+



-
-
+
+
-

-


-
+



-
+




-
+




-
+


-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
+













-







-
+
-
-
-
+
+


-
+








-
+






-
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+





-
-
-
-
+
+
+


-
+
-
-
-
+
-
-

-
-
+
+

-
-
+
+


-
+

-
-
-
-
+
+
+



-
-
+
-
-
-
-
-
-
-






-
+

-
-

-
+


-
+
















-
-
+
+










+


















+
+
+
-
+
+
+




+
+
+
-
+
+
+




-
+


+
+
+
+
+
+
+



-












-
+







-
+


-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-













-
-
-
-

-
+

-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-







-
-
-

-
+












-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
        $(TMP_DIR)\ttkWidget.obj \
        $(TMP_DIR)\ttkStubInit.obj

TKSTUBOBJS = \
	$(TMP_DIR)\tkStubLib.obj \
	$(TMP_DIR)\ttkStubLib.obj

### The following paths CANNOT have spaces in them as they appear on
### the left side of implicit rules.

WINDIR          = $(ROOT)\win
GENERICDIR	= $(ROOT)\generic
XLIBDIR		= $(ROOT)\xlib
TTKDIR		= $(ROOT)\generic\ttk
BITMAPDIR	= $(ROOT)\bitmaps

DOCDIR		= $(ROOT)\doc
# Directories where to build TIP430 ZIP files
# One for Tk - always built, contains Tk scripts
# One for Wish - for static builds, contains Tcl+Tk scripts
LIBTKVFS = $(OUT_DIR)\libtk.vfs
RCDIR		= $(WINDIR)\rc
WISHSCRIPTZIP = $(OUT_DIR)\wish.zip

# Additional include and C macro definitions for the implicit rules
# defined in rules.vc
PRJ_INCLUDES	= -I"$(BITMAPDIR)" -I"$(XLIBDIR)"
TK_INCLUDES	= -I"$(WINDIR)" -I"$(GENERICDIR)" -I"$(BITMAPDIR)" -I"$(XLIBDIR)" \
			$(TCL_INCLUDES)

CONFIG_DEFS     =/DHAVE_SYS_TYPES_H=1 /DHAVE_SYS_STAT_H=1 \
		 /DHAVE_STRING_H=1 /DHAVE_MEMORY_H=1 \
		 /DHAVE_STRINGS_H=1 /DTCL_UTF_MAX=4 \
CONFIG_DEFS     =-DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 \
		 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 \
		 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 \
		 -DSUPPORT_CONFIG_EMBEDDED \
!if $(HAVE_UXTHEME_H)
		 -DHAVE_UXTHEME_H=1 \
!endif
!if $(TTK_SQUARE_WIDGET)
		 /DTTK_SQUARE_WIDGET=1 \
		 -DTTK_SQUARE_WIDGET=1 \
!endif

TK_DEFINES	=-DBUILD_ttk $(OPTDEFINES)  $(CONFIG_DEFS) -Dinline=__inline

#---------------------------------------------------------------------
# Compile flags
#---------------------------------------------------------------------

!if !$(DEBUG)
!if $(OPTIMIZING)
### This cranks the optimization level to maximize speed
###  We can't use -O2 because sometimes it causes problems.
cdebug	= $(OPTIMIZATIONS)
!else
cdebug	=
!endif
!if $(SYMBOLS)
cdebug	= $(cdebug) -Zi
!endif
!else if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
### Warnings are too many, can't support warnings into errors.
cdebug	= -Zi -Od $(DEBUGFLAGS)
!else
cdebug	= -Zi -WX $(DEBUGFLAGS)
!endif

### Declarations common to all compiler options
cwarn = $(WARNINGS) -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE
cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\

!if $(MSVCRT)
!if $(DEBUG) && !$(UNCHECKED)
crt = -MDd
!else
crt = -MD
!endif
!else
!if $(DEBUG) && !$(UNCHECKED)
crt = -MTd
!else
crt = -MT
!endif
!endif

BASE_CFLAGS	= $(cdebug) $(cflags) $(crt) $(TK_INCLUDES)
TK_CFLAGS	= $(BASE_CFLAGS) $(TK_DEFINES) -DUSE_TCL_STUBS
CON_CFLAGS	= $(cdebug) $(cflags) $(crt) -DCONSOLE
WISH_CFLAGS	= $(BASE_CFLAGS) $(TK_DEFINES)
STUB_CFLAGS     = $(cflags) $(cdebug) $(TK_DEFINES)


#---------------------------------------------------------------------
# Link flags
#---------------------------------------------------------------------

!if $(TK_NO_DEPRECATED)
		 /DTK_NO_DEPRECATED=1
!if $(DEBUG)
ldebug	= -debug -debugtype:cv
!else
ldebug	= -release -opt:ref -opt:icf,3
!if $(SYMBOLS)
ldebug	= $(ldebug) -debug -debugtype:cv
!endif
!endif

### Declarations common to all linker options
lflags	= -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug)

!if $(PROFILE)
lflags	= $(lflags) -profile
!endif

!if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900
lflags	= $(lflags) -nodefaultlib:libucrt.lib
!endif
PRJ_DEFINES	= /DBUILD_ttk $(CONFIG_DEFS) /Dinline=__inline /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE

!if $(ALIGN98_HACK) && !$(STATIC_BUILD)
### Align sections for PE size savings.
lflags	= $(lflags) -opt:nowin98
!else if !$(ALIGN98_HACK) && $(STATIC_BUILD)
### Align sections for speed in loading by choosing the virtual page size.
lflags	= $(lflags) -align:4096
!endif

!if $(LOIMPACT)
lflags	= $(lflags) -ws:aggressive
!endif
# Additional Link libraries needed beyond those in rules.vc
PRJ_LIBS   = netapi32.lib gdi32.lib user32.lib userenv.lib winspool.lib shell32.lib ole32.lib uuid.lib

dlllflags = $(lflags) -dll
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows

tcllibs    = $(TCLSTUBLIB) $(TCLIMPLIB)

baselibs   = netapi32.lib kernel32.lib user32.lib advapi32.lib userenv.lib ws2_32.lib
# Avoid 'unresolved external symbol __security_cookie' errors.
# c.f. http://support.microsoft.com/?id=894573
!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
!if $(VCVERSION) > 1399 && $(VCVERSION) < 1500
baselibs   = $(baselibs) bufferoverflowU.lib
!endif
!endif
!if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900
baselibs   = $(baselibs) ucrt.lib
!endif

guilibs	  = $(baselibs) gdi32.lib


#---------------------------------------------------------------------
# TkTest flags
#---------------------------------------------------------------------

!if "$(TESTPAT)" != ""
TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT)
!endif


#---------------------------------------------------------------------
# Project specific targets
#---------------------------------------------------------------------

release:  setup $(TKSTUBLIB) $(WISH)
!if !$(USING_PRE87_TCL)
release:  libtkzip embed
!endif
all:	  release $(CAT32)
core:	  setup $(TKSTUBLIB) $(TKLIB)
cwish:	  $(WISHC)
libtkzip: setup $(TKSCRIPTZIP)
!if $(TK_EMBED_SCRIPTS)
!if $(STATIC_BUILD)
embed:    setup $(WISH) $(WISHSCRIPTZIP)
	@copy /y /b "$(WISH)"+"$(WISHSCRIPTZIP)" "$(WISH)"
!else
embed:    setup $(TKLIB) $(TKSCRIPTZIP)
	@copy /y /b "$(TKLIB)"+"$(TKSCRIPTZIP)" "$(TKLIB)"
!endif
!else
# ! TK_EMBED_SCRIPTS - still need to build the zip even if not embedded
embed: $(TKSCRIPTZIP)
!endif

install:  install-binaries install-libraries install-docs
!if $(SYMBOLS)
install:    install-pdbs
!endif
tktest:	  setup $(TKTEST) $(CAT32)

setup: default-setup

test: test-classic test-ttk

test-classic: setup $(TKTEST) $(TKLIB) $(CAT32)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	$(DEBUGGER) $(TKTEST) "$(ROOT:\=/)/tests/all.tcl" $(TESTFLAGS) | $(CAT32)

test-ttk: setup $(TKTEST) $(TKLIB) $(CAT32)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	$(DEBUGGER) $(TKTEST) "$(ROOT:\=/)/tests/ttk/all.tcl" $(TESTFLAGS) | $(CAT32)

runtest: setup $(TKTEST) $(TKLIB) $(CAT32)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	$(DEBUGGER) $(TKTEST)

rundemo: setup $(TKTEST) $(TKLIB) $(CAT32)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	$(TKTEST) $(ROOT:\=/)\library\demos\widget

shell: setup $(WISH)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	$(DEBUGGER) $(WISH) <<
	console show
<<

dbgshell: setup $(WISH)
	@set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
	@set TK_LIBRARY=$(LIBDIR:\=/)
	@set TK_LIBRARY=$(TK_LIBRARY:\=/)
	@set TCLLIBPATH=
!if $(TCLINSTALL)
	@set PATH=$(_TCLDIR)\bin;$(PATH)
!else
	@set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
!endif
	windbg $(WISH)

setup:
	@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
	@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)

!if $(STATIC_BUILD)
!if !$(STATIC_BUILD)
$(TKIMPLIB): $(TKLIB)
!endif

$(TKLIB): $(TKOBJS)
	$(LIBCMD) @<<
!if $(STATIC_BUILD)
	$(lib32) -nologo -out:$@ @<<
$**
<<

!else

	$(link32) $(dlllflags) -base:@$(COFFBASE),tk -out:$@ $(guilibs) \
$(TKLIB): $(TKOBJS)
	$(DLLCMD) @<<
		$(TCLSTUBLIB) @<<
$**
<<
	$(_VC_MANIFEST_EMBED_DLL)
	@if exist $*.exp del $*.exp

	-@del $*.exp
!endif
$(TKIMPLIB): $(TKLIB)

!endif # $(STATIC_BUILD)

$(TKSTUBLIB): $(TKSTUBOBJS)
	$(LIBCMD) -nodefaultlib $**
	$(lib32) -nologo -nodefaultlib -out:$@ $**


$(WISH): $(WISHOBJS) $(TKSTUBLIB) $(TKIMPLIB)
	$(GUIEXECMD) -stack:2300000 $**
	$(link32) $(guilflags) -stack:2300000 -out:$@ $(guilibs) $(tcllibs) $**
	$(_VC_MANIFEST_EMBED_EXE)


$(WISHC): $(WISHOBJS) $(TKSTUBLIB) $(TKIMPLIB)
	$(CONEXECMD) -stack:2300000 $**
	$(link32) $(conlflags) -stack:2300000 -out:$@ $(guilibs) $(tcllibs) $**
	$(_VC_MANIFEST_EMBED_EXE)


$(TKTEST): $(TKTESTOBJS) $(TKSTUBLIB) $(TKIMPLIB)
	$(GUIEXECMD) -stack:2300000 $**
	$(link32) $(guilflags) -stack:2300000 -out:$@ $(guilibs) $(tcllibs) $**
	$(_VC_MANIFEST_EMBED_EXE)

TKSCRIPTZIPTOP = tk_library
#TKSCRIPTZIPTOP = "tk$(DOTVERSION)"
$(TKSCRIPTZIP): .PHONY
	@echo Building Tk library zip file
	@if not exist "$(LIBTKVFS)" $(MKDIR) "$(LIBTKVFS)"
	@if exist "$(LIBTKVFS)\$(TKSCRIPTZIPTOP)" $(RMDIR) "$(LIBTKVFS)\$(TKSCRIPTZIPTOP)"
	@$(CPYDIR) $(LIBDIR) "$(LIBTKVFS)\$(TKSCRIPTZIPTOP)"
	@$(TCLSH) <<
cd {$(OUT_DIR)}
file delete -force {$@}
zipfs mkzip {$@} {$(LIBTKVFS)} {$(LIBTKVFS)}
<<

!if $(STATIC_BUILD)
$(WISHSCRIPTZIP): $(TKSCRIPTZIP)
	@echo Building Wish Tcl+Tk library zip file
	@if exist "$(LIBTKVFS)\tcl_library" $(RMDIR) "$(LIBTKVFS)\tcl_library"
	@$(TCLSH) <<
cd {$(OUT_DIR)}
file delete -force {$@}
zipfs mount "$(TCLSCRIPTZIP:\=/)" mnt
file copy [file join [zipfs root] mnt tcl_library] "$(LIBTKVFS:\=/)"
zipfs mkzip {$@} {$(LIBTKVFS)} {$(LIBTKVFS)}
<<
!endif


$(CAT32): $(_TCLDIR)\win\cat.c
	$(cc32) $(cflags) $(crt) /D_CRT_NONSTDC_NO_DEPRECATE /DCONSOLE /DUNICODE /D_UNICODE -Fo$(TMP_DIR)\ $?
	$(CONEXECMD) -stack:16384 $(TMP_DIR)\cat.obj
	$(cc32) $(CON_CFLAGS) -Fo$(TMP_DIR)\ $?
	$(link32) $(conlflags) -out:$@ -stack:16384 $(TMP_DIR)\cat.obj $(baselibs)
	$(_VC_MANIFEST_EMBED_EXE)

#---------------------------------------------------------------------
# Regenerate the stubs files.  [Development use only]
#---------------------------------------------------------------------

genstubs:
!if !exist($(TCLSH))
	@echo Build tclsh first!
!else
	set TCL_LIBRARY=$(TCL_LIBRARY)
	$(TCLSH) $(_TCLDIR)\tools\genStubs.tcl $(GENERICDIR) \
		$(GENERICDIR)\$(PROJECT).decls $(GENERICDIR)\$(PROJECT)Int.decls
	$(TCLSH) $(_TCLDIR)\tools\genStubs.tcl $(GENERICDIR)\ttk $(GENERICDIR)\ttk\ttk.decls
!endif


#---------------------------------------------------------------------
# Build the Windows HTML help file.
#---------------------------------------------------------------------

!if defined(PROCESSOR_ARCHITECTURE) && "$(PROCESSOR_ARCHITECTURE)" == "AMD64"
# NOTE: you can define HHC on the command-line to override this
HHC="%ProgramFiles(x86)%\HTML Help Workshop\hhc.exe"
!else
HHC="%ProgramFiles%\HTML Help Workshop\hhc.exe"
!ifndef HHC
HHC=""%ProgramFiles%\HTML Help Workshop\hhc.exe""
!endif
HTMLDIR=$(ROOT)\html
HTMLBASE=TclTk$(TCL_VERSION)
HTMLBASE=TclTk$(VERSION)
HHPFILE=$(HTMLDIR)\$(HTMLBASE).hhp
CHMFILE=$(HTMLDIR)\$(HTMLBASE).chm

htmlhelp: chmsetup $(CHMFILE)

$(CHMFILE): $(DOCDIR)\*
	@$(TCLSH) $(TCLTOOLSDIR)\tcltk-man2html.tcl
	@echo Compiling HTML help project
	@"$(HHC)" <<$(HHPFILE) >NUL
	@$(HHC) <<$(HHPFILE) >NUL
[OPTIONS]
Compatibility=1.1 or later
Compiled file=$(HTMLBASE).chm
Display compile progress=no
Error log file=$(HTMLBASE).log
Language=0x409 English (United States)
Title=Tcl/Tk $(TCL_DOTVERSION) Help
Title=Tcl/Tk $(DOT_VERSION) Help
[FILES]
contents.htm
docs.css
Keywords
TclCmd
TclLib
TkCmd
TkLib
UserCmd
<<

chmsetup:
	@if not exist $(HTMLDIR)\nul mkdir $(HTMLDIR)

#-------------------------------------------------------------------------
# Build the old-style Windows .hlp file
#-------------------------------------------------------------------------

HLPBASE		= $(PROJECT)$(TK_VERSION)
HELPFILE	= $(OUT_DIR)\$(HLPBASE).hlp
HELPCNT		= $(OUT_DIR)\$(HLPBASE).cnt
DOCTMP_DIR	= $(OUT_DIR)\$(PROJECT)_docs
HELPRTF		= $(DOCTMP_DIR)\$(PROJECT).rtf
MAN2HELP	= $(DOCTMP_DIR)\man2help.tcl
MAN2HELP2	= $(DOCTMP_DIR)\man2help2.tcl
INDEX		= $(DOCTMP_DIR)\index.tcl
BMP		= $(DOCTMP_DIR)\lamp.bmp
BMP_NOPATH	= lamp.bmp
MAN2TCL		= $(DOCTMP_DIR)\man2tcl.exe

winhelp: docsetup $(HELPFILE)

install-docs:
!if exist("$(CHMFILE)")
	@echo Installing compiled HTML help
	@$(CPY) "$(CHMFILE)" "$(DOC_INSTALL_DIR)\"
!endif
# "emacs font-lock highlighting fix
docsetup:
	@if not exist $(DOCTMP_DIR)\nul mkdir $(DOCTMP_DIR)

$(MAN2HELP) $(MAN2HELP2) $(INDEX): $(TCLTOOLSDIR)\$$(@F)
	$(CPY) $(TCLTOOLSDIR)\$(@F) $(@D)

$(BMP):
	$(CPY) $(WINDIR)\rc\$(@F) $(@D)

$(HELPFILE): $(HELPRTF) $(BMP)
	cd $(DOCTMP_DIR)
	start /wait hcrtf.exe -x <<$(PROJECT).hpj
[OPTIONS]
COMPRESS=12 Hall Zeck
LCID=0x409 0x0 0x0 ; English (United States)
TITLE=Tk Reference Manual
BMROOT=.
CNT=$(@B).cnt
HLP=$(@B).hlp

[FILES]
$(PROJECT).rtf

[WINDOWS]
main="Tcl/Tk Reference Manual",,27648,(r15263976),(r4227327)

[CONFIG]
BrowseButtons()
CreateButton(1, "Web", ExecFile("http://www.tcl.tk"))
CreateButton(2, "SF", ExecFile("http://sf.net/projects/tcl"))
CreateButton(3, "Wiki", ExecFile("http://wiki.tcl.tk"))
CreateButton(4, "FAQ", ExecFile("http://www.purl.org/NET/Tcl-FAQ/"))
<<
	cd $(MAKEDIR)
	@$(CPY) "$(DOCTMP_DIR)\$(@B).hlp" "$(OUT_DIR)"
	@$(CPY) "$(DOCTMP_DIR)\$(@B).cnt" "$(OUT_DIR)"

$(MAN2TCL): $(TCLTOOLSDIR)\$$(@B).c
	$(cc32) $(TK_CFLAGS) -Fo$(@D)\ $(TCLTOOLSDIR)\$(@B).c
	$(link32) $(conlflags) -out:$@ -stack:16384 $(@D)\man2tcl.obj
	$(_VC_MANIFEST_EMBED_EXE)

$(HELPRTF): $(MAN2TCL) $(MAN2HELP) $(MAN2HELP2) $(INDEX)
	$(TCLSH) $(MAN2HELP) -bitmap $(BMP_NOPATH) $(PROJECT) $(TK_VERSION) $(DOCDIR:\=/)

install-pdbs:
	@echo Installing debug symbols
	@$(CPY) "$(OUT_DIR)\*.pdb" "$(BIN_INSTALL_DIR)\"
install-docs:
!if exist($(HELPFILE))
	$(CPY) "$(HELPFILE)" "$(DOC_INSTALL_DIR)\"
	$(CPY) "$(HELPCNT)" "$(DOC_INSTALL_DIR)\"
	$(TCLSH) <<
puts "Installing $(PROJECT)'s helpfile contents into Tcl's ..."
set f [open "$(DOC_INSTALL_DIR:\=/)/tcl$(TK_VERSION).cnt" r]
while {![eof $$f]} {
    if {[regexp {:Include $(PROJECT)([0-9]{2}).cnt} [gets $$f] dummy ver]} {
	if {$$ver == $(TK_VERSION)} {
	    puts "Already installed."
	    exit
	} else {
	    # do something here logical to remove (or replace) it.
	    puts "$$ver != $(TK_VERSION), unfinished code path, die, die!"
	    exit 1
	}
    }
}
close $$f
set f [open "$(DOC_INSTALL_DIR:\=/)/tcl$(TK_VERSION).cnt" a]
puts $$f {:Include $(HLPBASE).cnt}
close $$f
<<
	start /wait winhlp32 -g $(DOC_INSTALL_DIR)\tcl$(TK_VERSION).hlp
# "emacs font-lock highlighting fix
!endif

#---------------------------------------------------------------------
# Special case object file targets
#---------------------------------------------------------------------

# Note: Static builds now always mandate statically linking Tcl registry etc.
$(TMP_DIR)\testMain.obj: $(WIN_DIR)\winMain.c
	$(cc32) $(appcflags_nostubs) /DTK_TEST /DUNICODE /D_UNICODE \
	    /DTCL_USE_STATIC_PACKAGES=$(STATIC_BUILD) \
$(TMP_DIR)\testMain.obj: $(WINDIR)\winMain.c
	$(cc32) $(WISH_CFLAGS) -DTK_TEST \
	    -DTCL_USE_STATIC_PACKAGES=$(TCL_USE_STATIC_PACKAGES) \
	    -Fo$@ $?

$(ROOT)\manifest.uuid:
$(TMP_DIR)\tkTest.obj: $(GENERICDIR)\tkTest.c
   copy $(WIN_DIR)\gitmanifest.in $(ROOT)\manifest.uuid
   git rev-parse HEAD >>$(ROOT)\manifest.uuid

	$(cc32) $(WISH_CFLAGS) -Fo$@ $?
$(TMP_DIR)\tkUuid.h:	$(ROOT)\manifest.uuid
	copy $(WIN_DIR)\tkUuid.h.in+$(ROOT)\manifest.uuid $(TMP_DIR)\tkUuid.h

$(TMP_DIR)\tkTest.obj: $(GENERICDIR)\tkTest.c
	$(cc32) $(appcflags_nostubs) -Fo$@ $?
$(TMP_DIR)\tkOldTest.obj: $(GENERICDIR)\tkOldTest.c
	$(cc32) $(WISH_CFLAGS) -Fo$@ $?

$(TMP_DIR)\tkWinTest.obj: $(WIN_DIR)\tkWinTest.c
	$(cc32) $(appcflags_nostubs) -Fo$@ $?
$(TMP_DIR)\tkWinTest.obj: $(WINDIR)\tkWinTest.c
	$(cc32) $(WISH_CFLAGS) -Fo$@ $?

$(TMP_DIR)\tkSquare.obj: $(GENERICDIR)\tkSquare.c
	$(cc32) $(appcflags_nostubs) -Fo$@ $?
	$(cc32) $(WISH_CFLAGS) -Fo$@ $?

# Note: Static builds now always mandate statically linking Tcl registry etc.
$(TMP_DIR)\winMain.obj: $(WIN_DIR)\winMain.c
	$(cc32) $(appcflags_nostubs) /DUNICODE /D_UNICODE \
	    /DTCL_USE_STATIC_PACKAGES=$(STATIC_BUILD) \
$(TMP_DIR)\winMain.obj: $(WINDIR)\winMain.c
	$(cc32) $(WISH_CFLAGS) \
	    -DTCL_USE_STATIC_PACKAGES=$(TCL_USE_STATIC_PACKAGES) \
	    -Fo$@ $?

$(TMP_DIR)\tkMain2.obj: $(GENERICDIR)\tkMain.c
	$(cc32) $(pkgcflags) /DUNICODE /D_UNICODE -Fo$@ $?

	$(cc32) -DBUILD_tk $(TK_CFLAGS) -DTK_ASCII_MAIN -Fo$@ $?
$(TMP_DIR)\tkPkgConfig.obj: $(GENERICDIR)\tkPkgConfig.c
	$(cc32) $(pkgcflags) 		\
		-DCFG_RUNTIME_DLLFILE="\"$(TKLIBNAME)\"" \
		-Fo$@ $?

$(TMP_DIR)\tkWindow.obj: $(GENERICDIR)\tkWindow.c $(TMP_DIR)\tkUuid.h
	$(cc32) $(pkgcflags) -I$(TMP_DIR) -Fo$@ $?

# The following objects are part of the stub library and should not
# be built as DLL objects but none of the symbols should be exported
# and no reference made to a C runtime.

$(TMP_DIR)\tkStubLib.obj : $(GENERICDIR)\tkStubLib.c
	$(cc32) $(stubscflags) -Fo$@ $?
	$(cc32) $(STUB_CFLAGS) $(TK_INCLUDES) -Zl -DSTATIC_BUILD -Fo$@ $?

$(TMP_DIR)\ttkStubLib.obj : $(TTKDIR)\ttkStubLib.c
	$(cc32) $(stubscflags) -Fo$@ $?

$(TMP_DIR)\wish.exe.manifest: $(WIN_DIR)\wish.exe.manifest.in
$(TMP_DIR)\wish.exe.manifest: $(WINDIR)\wish.exe.manifest.in
	@nmakehlp -s << $** >$@
@MACHINE@	  $(MACHINE:IX86=X86)
@TK_WIN_VERSION@  $(DOTVERSION).0.0
@TK_WIN_VERSION@  $(TK_DOTVERSION).0.0
<<

#---------------------------------------------------------------------
# Generate the source dependencies.  Having dependency rules will
# improve incremental build accuracy without having to resort to a
# full rebuild just because some non-global header file like
# tclCompile.h was changed.  These rules aren't needed when building
# from scratch.
#---------------------------------------------------------------------

depend:
!if !exist($(TCLSH))
	@echo Build tclsh first!
!else
	set TCL_LIBRARY=$(TCL_LIBRARY)
	$(TCLSH) $(TCLTOOLSDIR:\=/)/mkdepend.tcl -vc32 -out:"$(OUT_DIR)\depend.mk" \
		-passthru:"/DBUILD_tk $(TK_INCLUDES)" $(GENERICDIR),$$(GENERICDIR) \
		$(WIN_DIR),$$(WIN_DIR) $(TTKDIR),$$(TTKDIR) $(XLIBDIR),$$(XLIBDIR) \
		-passthru:"-DBUILD_tk $(TK_INCLUDES)" $(GENERICDIR),$$(GENERICDIR) \
		$(WINDIR),$$(WINDIR) $(TTKDIR),$$(TTKDIR) $(XLIBDIR),$$(XLIBDIR) \
		$(BITMAPDIR),$$(BITMAPDIR) @<<
$(TKOBJS)
<<
!endif

#---------------------------------------------------------------------
# Dependency rules
#---------------------------------------------------------------------

$(TMP_DIR)\tk.res: \
    $(RCDIR)\buttons.bmp \
    $(RCDIR)\cursor*.cur \
    $(RCDIR)\tk.ico

!if exist("$(OUT_DIR)\depend.mk")
!include "$(OUT_DIR)\depend.mk"
!message *** Dependency rules in use.
!else
!message *** Dependency rules are not being used.
!endif

### add a spacer in the output
!message

#---------------------------------------------------------------------
# Implicit rules
#---------------------------------------------------------------------

{$(XLIBDIR)}.c{$(TMP_DIR)}.obj::
	$(cc32) -DBUILD_tk $(TK_CFLAGS) -Fo$(TMP_DIR)\ @<<
$<
<<
	$(CCPKGCMD) @<<

{$(GENERICDIR)}.c{$(TMP_DIR)}.obj::
	$(cc32) -DBUILD_tk $(TK_CFLAGS) -Fo$(TMP_DIR)\ @<<
$<
<<

{$(TTKDIR)}.c{$(TMP_DIR)}.obj::
	$(cc32) -DBUILD_tk $(TK_CFLAGS) -Fo$(TMP_DIR)\ @<<
$<
<<
	$(CCPKGCMD) @<<

{$(WINDIR)}.c{$(TMP_DIR)}.obj::
	$(cc32) -DBUILD_tk $(TK_CFLAGS) -Fo$(TMP_DIR)\ @<<
$<
<<

{$(ROOT)\unix}.c{$(TMP_DIR)}.obj::
	$(CCPKGCMD) @<<
	$(cc32) -DBUILD_tk $(TK_CFLAGS) -Fo$(TMP_DIR)\ @<<
$<
<<

{$(RCDIR)}.rc{$(TMP_DIR)}.res:
	$(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" $(TCL_INCLUDES) \
	    -d DEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \
	    -d TCL_THREADS=$(TCL_THREADS) \
	    -d STATIC_BUILD=$(STATIC_BUILD) \
	    $<

$(TMP_DIR)\tk.res: $(TMP_DIR)\wish.exe.manifest
$(TMP_DIR)\wish.res: $(TMP_DIR)\wish.exe.manifest
$(TMP_DIR)\tktest.res: $(TMP_DIR)\wish.exe.manifest

.SUFFIXES:
.SUFFIXES:.c .rc


#---------------------------------------------------------------------
# Installation.
#---------------------------------------------------------------------

install-binaries:
	@echo installing binaries
	@$(CPY) "$(WISH)" "$(BIN_INSTALL_DIR)\"
!if "$(TKLIB)" != "$(TKIMPLIB)"
!if $(TKLIB) != $(TKIMPLIB)
	@$(CPY) "$(TKLIB)" "$(BIN_INSTALL_DIR)\"
!endif
	@$(CPY) "$(TKIMPLIB)" "$(LIB_INSTALL_DIR)\"
	@$(CPY) "$(TKSTUBLIB)" "$(LIB_INSTALL_DIR)\"
!if !$(STATIC_BUILD)
	@echo creating package index
	@type << > $(OUT_DIR)\pkgIndex.tcl
if {![package vsatisfies [package provide Tcl] 8.7-]} return
if {[catch {package present Tcl 8.6-}]} { return }
if {($$::tcl_platform(platform) eq "unix") && ([info exists ::env(DISPLAY)]
	|| ([info exists ::argv] && ("-display" in $$::argv)))} {
    if {[package vsatisfies [package provide Tcl] 9.0]} {
	package ifneeded tk $(TK_PATCH_LEVEL) [list load [file normalize [file join $$dir .. .. bin libtcl9tk$(DOTVERSION).dll]]]
    } else {
	package ifneeded tk $(TK_PATCH_LEVEL) [list load [file normalize [file join $$dir .. .. bin libtk$(DOTVERSION).dll]]]
    }
} else {
    if {[package vsatisfies [package provide Tcl] 9.0]} {
	package ifneeded tk $(TK_PATCH_LEVEL) [list load [file normalize [file join $$dir .. .. bin $(TKLIBNAME9)]]]
    } else {
	package ifneeded tk $(TK_PATCH_LEVEL) [list load [file normalize [file join $$dir .. .. bin $(TKLIBNAME8)]]]
    }
    package ifneeded Tk $(TK_PATCH_LEVEL) [list load [file join $$dir .. .. bin libtk$(TK_DOTVERSION).dll] Tk]
} else {
    package ifneeded Tk $(TK_PATCH_LEVEL) [list load [file join $$dir .. .. bin $(TKLIBNAME)] Tk]
}
}
package ifneeded Tk $(TK_PATCH_LEVEL) [list package require -exact tk $(TK_PATCH_LEVEL)]
<<
	@$(CPY) $(OUT_DIR)\pkgIndex.tcl "$(SCRIPT_INSTALL_DIR)\"
!endif

#"

install-libraries:
	@echo installing Tk headers
	@$(CPY) "$(GENERICDIR)\tk.h" "$(INCLUDE_INSTALL_DIR)\"
	@$(CPY) "$(GENERICDIR)\tkDecls.h" "$(INCLUDE_INSTALL_DIR)\"
	@$(CPY) "$(GENERICDIR)\tkPlatDecls.h" "$(INCLUDE_INSTALL_DIR)\"
	@$(CPY) "$(GENERICDIR)\tkIntXlibDecls.h" "$(INCLUDE_INSTALL_DIR)\"
	@$(CPY) "$(XLIBDIR)\X11\*.h" "$(INCLUDE_INSTALL_DIR)\X11\"
!if !$(USING_PRE87_TCL)
	@$(CPY) "$(TKSCRIPTZIP)" "$(LIB_INSTALL_DIR)"
!endif
!if !$(TK_EMBED_SCRIPTS)
	@echo installing script library
	@$(CPY) "$(LIBDIR)\*" "$(SCRIPT_INSTALL_DIR)\"
	@$(CPY) "$(ROOT)\library\*" "$(SCRIPT_INSTALL_DIR)\"
	@echo installing theme library
	@$(CPY) "$(LIBDIR)\ttk\*" "$(SCRIPT_INSTALL_DIR)\ttk\"
	@echo installing images
	@$(CPY) "$(LIBDIR)\images\*" "$(SCRIPT_INSTALL_DIR)\images\"
	@echo installing language files
	@$(CPY) "$(LIBDIR)\msgs\*" "$(SCRIPT_INSTALL_DIR)\msgs\"
	@$(CPY) "$(ROOT)\library\ttk\*" "$(SCRIPT_INSTALL_DIR)\ttk\"
	@echo installing demos
	@$(CPY) "$(ROOT)\library\demos\*" "$(SCRIPT_INSTALL_DIR)\demos\"
	@$(CPY) "$(ROOT)\library\demos\images\*" "$(SCRIPT_INSTALL_DIR)\demos\images\"
	@echo installing images
	@$(CPY) "$(ROOT)\library\images\*" "$(SCRIPT_INSTALL_DIR)\images\"
!endif
	@echo installing demos
	@$(CPY) "$(DEMODIR)\*" "$(DEMO_INSTALL_DIR)\"
	@echo installing language files
	@$(CPY) "$(ROOT)\library\msgs\*" "$(SCRIPT_INSTALL_DIR)\msgs\"
	@$(CPY) "$(DEMODIR)\images\*" "$(DEMO_INSTALL_DIR)\images\"

#"

#---------------------------------------------------------------------
# Clean up
#---------------------------------------------------------------------

clean: default-clean
realclean: hose
hose: default-hose
tidy:
!if "$(TKLIB)" != "$(TKIMPLIB)"
!if $(TKLIB) != $(TKIMPLIB)
	@echo Removing $(TKLIB) ...
	@if exist $(TKLIB) del $(TKLIB)
!endif
	@echo Removing $(TKIMPLIB) ...
	@if exist $(TKIMPLIB) del $(TKIMPLIB)
	@echo Removing $(WISH) ...
	@if exist $(WISH) del $(WISH)
	@echo Removing $(TKTEST) ...
	@if exist $(TKTEST) del $(TKTEST)
	@echo Removing $(TKSTUBLIB) ...
	@if exist $(TKSTUBLIB) del $(TKSTUBLIB)

.PHONY:
clean:
	@echo Cleaning $(TMP_DIR)\* ...
	@if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
	@echo Cleaning $(WINDIR)\nmakehlp.obj ...
	@if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj
	@echo Cleaning $(WINDIR)\nmakehlp.exe ...
	@if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe
	@echo Cleaning $(WINDIR)\_junk.pch ...
	@if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch
	@echo Cleaning $(WINDIR)\vercl.x ...
	@if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x
	@echo Cleaning $(WINDIR)\vercl.i ...
	@if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i
	@echo Cleaning $(WINDIR)\versions.vc ...
	@if exist $(WINDIR)\versions.vc del $(WINDIR)\versions.vc

# Local Variables:
# mode: makefile
# End:
realclean: hose

hose:
	@echo Hosing $(OUT_DIR)\* ...
	@if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)

Changes to win/nmakehlp.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17




18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36

37
38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45

46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83






-
-
+
+








-
+
+
+
+


-
+













-
+


+





-
+



-












-
-
+
+













-







/*
 * ----------------------------------------------------------------------------
 * nmakehlp.c --
 *
 *	This is used to fix limitations within nmake and the environment.
 *
 * Copyright (c) 2002 David Gravereaux.
 * Copyright (c) 2006 Pat Thoyts
 * Copyright (c) 2002 by David Gravereaux.
 * Copyright (c) 2006 by Pat Thoyts
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * ----------------------------------------------------------------------------
 */

#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#ifdef _MSC_VER
#define NO_SHLWAPI_GDI
#define NO_SHLWAPI_STREAM
#define NO_SHLWAPI_REG
#include <shlwapi.h>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
#endif
#pragma comment (lib, "shlwapi.lib")
#include <stdio.h>
#include <math.h>

/*
 * This library is required for x64 builds with _some_ versions of MSVC
 */
#if defined(_M_IA64) || defined(_M_AMD64)
#if _MSC_VER >= 1400 && _MSC_VER < 1500
#pragma comment(lib, "bufferoverflowU")
#endif
#endif

/* ISO hack for dumb VC++ */
#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
#ifdef _MSC_VER
#define   snprintf	_snprintf
#endif



/* protos */

static int CheckForCompilerFeature(const char *option);
static int CheckForLinkerFeature(char **options, int count);
static int CheckForLinkerFeature(const char *option);
static int IsIn(const char *string, const char *substring);
static int SubstituteFile(const char *substs, const char *filename);
static int QualifyPath(const char *path);
static int LocateDependency(const char *keyfile);
static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
static DWORD WINAPI ReadFromPipe(LPVOID args);

/* globals */

#define CHUNK	25
#define STATICBUFFERSIZE    1000
typedef struct {
    HANDLE pipe;
    char buffer[STATICBUFFERSIZE];
} pipeinfo;

pipeinfo Out = {INVALID_HANDLE_VALUE, ""};
pipeinfo Err = {INVALID_HANDLE_VALUE, ""};
pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};

/*
 * exitcodes: 0 == no, 1 == yes, 2 == error
 */

int
main(
    int argc,
    char *argv[])
{
    char msg[300];
    DWORD dwWritten;
    int chars;
    const char *s;

    /*
     * Make sure children (cl.exe and link.exe) are kept quiet.
     */

    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);

96
97
98
99
100
101
102
103

104
105

106
107
108
109
110
111
112

113
114
115
116
117
118
119
98
99
100
101
102
103
104

105
106

107
108
109
110
111
112
113

114
115
116
117
118
119
120
121







-
+

-
+






-
+







			"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
			&dwWritten, NULL);
		return 2;
	    }
	    return CheckForCompilerFeature(argv[2]);
	case 'l':
	    if (argc < 3) {
	    if (argc != 3) {
		chars = snprintf(msg, sizeof(msg) - 1,
	       		"usage: %s -l <linker option> ?<mandatory option> ...?\n"
	       		"usage: %s -l <linker option>\n"
			"Tests for whether link.exe supports an option\n"
			"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
			&dwWritten, NULL);
		return 2;
	    }
	    return CheckForLinkerFeature(&argv[2], argc-2);
	    return CheckForLinkerFeature(argv[2]);
	case 'f':
	    if (argc == 2) {
		chars = snprintf(msg, sizeof(msg) - 1,
			"usage: %s -f <string> <substring>\n"
			"Find a substring within another\n"
			"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
147
148
149
150
151
152
153
154

155
156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
149
150
151
152
153
154
155

156



157



158
159
160
161
162
163
164
165
166
167
168












169
170
171
172
173
174
175







-
+
-
-
-
+
-
-
-











-
-
-
-
-
-
-
-
-
-
-
-







		    "Extract a version from a file:\n"
		    "eg: pkgIndex.tcl \"package ifneeded http\"",
		    argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
		    &dwWritten, NULL);
		return 0;
	    }
	    s = GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0');
	    printf("%s\n", GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0'));
	    if (s && *s) {
		printf("%s\n", s);
		return 0;
	    return 0;
	    } else
		return 1; /* Version not found. Return non-0 exit code */

	case 'Q':
	    if (argc != 3) {
		chars = snprintf(msg, sizeof(msg) - 1,
		    "usage: %s -Q path\n"
		    "Emit the fully qualified path\n"
		    "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
		    &dwWritten, NULL);
		return 2;
	    }
	    return QualifyPath(argv[2]);

	case 'L':
	    if (argc != 3) {
		chars = snprintf(msg, sizeof(msg) - 1,
		    "usage: %s -L keypath\n"
		    "Emit the fully qualified path of directory containing keypath\n"
		    "exitcodes: 0 == success, 1 == not found, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
		    &dwWritten, NULL);
		return 2;
	    }
	    return LocateDependency(argv[2]);
	}
    }
    chars = snprintf(msg, sizeof(msg) - 1,
	    "usage: %s -c|-f|-l|-Q|-s|-V ...\n"
	    "This is a little helper app to equalize shell differences between WinNT and\n"
	    "Win9x and get nmake.exe to accomplish its job.\n",
	    argv[0]);
203
204
205
206
207
208
209
210
211


212
213
214
215
216

217
218
219
220
221
222

223
224
225
226
227
228

229
230
231
232
233
234
235
188
189
190
191
192
193
194


195
196
197
198
199
200

201
202
203
204
205
206

207
208
209
210
211
212

213
214
215
216
217
218
219
220







-
-
+
+




-
+





-
+





-
+







    char msg[300];
    BOOL ok;
    HANDLE hProcess, h, pipeThreads[2];
    char cmdline[100];

    hProcess = GetCurrentProcess();

    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    memset(&si, 0, sizeof(STARTUPINFO));
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags   = STARTF_USESTDHANDLES;
    si.hStdInput = INVALID_HANDLE_VALUE;

    memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = FALSE;

    /*
     * Create a non-inheritable pipe.
     * Create a non-inheritible pipe.
     */

    CreatePipe(&Out.pipe, &h, &sa, 0);

    /*
     * Dupe the write side, make it inheritable, and close the original.
     * Dupe the write side, make it inheritible, and close the original.
     */

    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
	    DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);

    /*
     * Same as above, but for the error side.
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270







-
+








    if (!ok) {
	DWORD err = GetLastError();
	int chars = snprintf(msg, sizeof(msg) - 1,
		"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);

	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
		(300-chars), 0);
	WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
	return 2;
    }

    /*
     * Close our references to the write handles that have now been inherited.
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342

343
344
345
346
347


348
349
350
351
352

353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
309
310
311
312
313
314
315

316

317
318
319
320
321
322
323
324


325
326
327
328


329
330
331
332
333
334

335
336
337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354







-
+
-








-
-
+



-
-
+
+




-
+











-
+







             || strstr(Err.buffer, "D9002") != NULL
             || strstr(Out.buffer, "D2021") != NULL
             || strstr(Err.buffer, "D2021") != NULL);
}

static int
CheckForLinkerFeature(
    char **options,
    const char *option)
    int count)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    SECURITY_ATTRIBUTES sa;
    DWORD threadID;
    char msg[300];
    BOOL ok;
    HANDLE hProcess, h, pipeThreads[2];
    int i;
    char cmdline[255];
    char cmdline[100];

    hProcess = GetCurrentProcess();

    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    memset(&si, 0, sizeof(STARTUPINFO));
    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags   = STARTF_USESTDHANDLES;
    si.hStdInput = INVALID_HANDLE_VALUE;

    memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;

    /*
     * Create a non-inheritible pipe.
     */

    CreatePipe(&Out.pipe, &h, &sa, 0);

    /*
     * Dupe the write side, make it inheritable, and close the original.
     * Dupe the write side, make it inheritible, and close the original.
     */

    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
	    DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);

    /*
     * Same as above, but for the error side.
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
364
365
366
367
368
369
370


371



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398







-
-
+
-
-
-



















-
+








    lstrcpy(cmdline, "link.exe -nologo ");

    /*
     * Append our option for testing.
     */

    for (i = 0; i < count; i++) {
	lstrcat(cmdline, " \"");
    lstrcat(cmdline, option);
	lstrcat(cmdline, options[i]);
	lstrcat(cmdline, "\"");
    }

    ok = CreateProcess(
	    NULL,	    /* Module name. */
	    cmdline,	    /* Command line. */
	    NULL,	    /* Process handle not inheritable. */
	    NULL,	    /* Thread handle not inheritable. */
	    TRUE,	    /* yes, inherit handles. */
	    DETACHED_PROCESS, /* No console for you. */
	    NULL,	    /* Use parent's environment block. */
	    NULL,	    /* Use parent's starting directory. */
	    &si,	    /* Pointer to STARTUPINFO structure. */
	    &pi);	    /* Pointer to PROCESS_INFORMATION structure. */

    if (!ok) {
	DWORD err = GetLastError();
	int chars = snprintf(msg, sizeof(msg) - 1,
		"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);

	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
		(300-chars), 0);
	WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
	return 2;
    }

    /*
     * Close our references to the write handles that have now been inherited.
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
429
430
431
432
433
434
435

436


437
438
439
440
441
442
443







-
+
-
-







    /*
     * Look for the commandline warning code in the stderr stream.
     */

    return !(strstr(Out.buffer, "LNK1117") != NULL ||
	    strstr(Err.buffer, "LNK1117") != NULL ||
	    strstr(Out.buffer, "LNK4044") != NULL ||
	    strstr(Err.buffer, "LNK4044") != NULL ||
	    strstr(Err.buffer, "LNK4044") != NULL);
	    strstr(Out.buffer, "LNK4224") != NULL ||
	    strstr(Err.buffer, "LNK4224") != NULL);
}

static DWORD WINAPI
ReadFromPipe(
    LPVOID args)
{
    pipeinfo *pi = (pipeinfo *) args;
501
502
503
504
505
506
507

508
509
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537


538
539
540

541
542


543
544
545
546
547
548
549
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513


514
515
516
517
518
519


520
521
522
523
524
525
526
527
528







+









-
+









-
+








-
-
+
+



+
-
-
+
+








static const char *
GetVersionFromFile(
    const char *filename,
    const char *match,
    int numdots)
{
    size_t cbBuffer = 100;
    static char szBuffer[100];
    char *szResult = NULL;
    FILE *fp = fopen(filename, "rt");

    if (fp != NULL) {
	/*
	 * Read data until we see our match string.
	 */

	while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
	while (fgets(szBuffer, cbBuffer, fp) != NULL) {
	    LPSTR p, q;

	    p = strstr(szBuffer, match);
	    if (p != NULL) {
		/*
		 * Skip to first digit after the match.
		 */

		p += strlen(match);
		while (*p && !isdigit((unsigned char)*p)) {
		while (*p && !isdigit(*p)) {
		    ++p;
		}

		/*
		 * Find ending whitespace.
		 */

		q = p;
		while (*q && (strchr("0123456789.ab", *q)) && (((!strchr(".ab", *q)
			    && !strchr("ab", q[-1])) || --numdots))) {
		while (*q && (strchr("0123456789.ab", *q)) && ((!strchr(".ab", *q)
			    && (!strchr("ab", q[-1])) || --numdots))) {
		    ++q;
		}

		memcpy(szBuffer, p, q - p);
		*q = 0;
		szResult = p;
		szBuffer[q-p] = 0;
		szResult = szBuffer;
		break;
	    }
	}
	fclose(fp);
    }
    return szResult;
}
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
537
538
539
540
541
542
543

544
545
546
547
548
549
550
551







-
+







    char * value;
} list_item_t;

/* insert a list item into the list (list may be null) */
static list_item_t *
list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
{
    list_item_t *itemPtr = (list_item_t *)malloc(sizeof(list_item_t));
    list_item_t *itemPtr = malloc(sizeof(list_item_t));
    if (itemPtr) {
	itemPtr->key = strdup(key);
	itemPtr->value = strdup(value);
	itemPtr->nextPtr = NULL;

	while(*listPtrPtr) {
	    listPtrPtr = &(*listPtrPtr)->nextPtr;
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613

614

615
616
617
618
619
620
621
622

623
624
625
626
627

628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

726
727
728
729

730
731
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761
762
763
764
765
766

767
768
769
770
771

772
773
774
775
776
777
778
779

780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797

798
799
800
801
802


803
804
805
806
807
808
809
810
811
812
813
814
815
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663
664











665
666
667
668
669
670
671
672
673
674
675
676
677


















678




679









680













681















682





683








684


















685





686
687



688
689
690
691
692
693
694
695
696
697







-
+

















+

+







-
+




-
+
















-
+













-
+
















-
+








-
-
-
-
-
-
-
-
-
-
-













-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
-
-
-










    }
}

/*
 * SubstituteFile --
 *	As windows doesn't provide anything useful like sed and it's unreliable
 *	to use the tclsh you are building against (consider x-platform builds -
 *	e.g. compiling AMD64 target from IX86) we provide a simple substitution
 *	eg compiling AMD64 target from IX86) we provide a simple substitution
 *	option here to handle autoconf style substitutions.
 *	The substitution file is whitespace and line delimited. The file should
 *	consist of lines matching the regular expression:
 *	  \s*\S+\s+\S*$
 *
 *	Usage is something like:
 *	  nmakehlp -S << $** > $@
 *        @PACKAGE_NAME@ $(PACKAGE_NAME)
 *        @PACKAGE_VERSION@ $(PACKAGE_VERSION)
 *        <<
 */

static int
SubstituteFile(
    const char *substitutions,
    const char *filename)
{
    size_t cbBuffer = 1024;
    static char szBuffer[1024], szCopy[1024];
    char *szResult = NULL;
    list_item_t *substPtr = NULL;
    FILE *fp, *sp;

    fp = fopen(filename, "rt");
    if (fp != NULL) {

	/*
	 * Build a list of substitutions from the first filename
	 * Build a list of substutitions from the first filename
	 */

	sp = fopen(substitutions, "rt");
	if (sp != NULL) {
	    while (fgets(szBuffer, sizeof(szBuffer), sp) != NULL) {
	    while (fgets(szBuffer, cbBuffer, sp) != NULL) {
		unsigned char *ks, *ke, *vs, *ve;
		ks = (unsigned char*)szBuffer;
		while (ks && *ks && isspace(*ks)) ++ks;
		ke = ks;
		while (ke && *ke && !isspace(*ke)) ++ke;
		vs = ke;
		while (vs && *vs && isspace(*vs)) ++vs;
		ve = vs;
		while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
		*ke = 0, *ve = 0;
		list_insert(&substPtr, (char*)ks, (char*)vs);
	    }
	    fclose(sp);
	}

	/* debug: dump the list */
#ifndef NDEBUG
#ifdef _DEBUG
	{
	    int n = 0;
	    list_item_t *p = NULL;
	    for (p = substPtr; p != NULL; p = p->nextPtr, ++n) {
		fprintf(stderr, "% 3d '%s' => '%s'\n", n, p->key, p->value);
	    }
	}
#endif

	/*
	 * Run the substitutions over each line of the input
	 */

	while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
	while (fgets(szBuffer, cbBuffer, fp) != NULL) {
	    list_item_t *p = NULL;
	    for (p = substPtr; p != NULL; p = p->nextPtr) {
		char *m = strstr(szBuffer, p->key);
		if (m) {
		    char *cp, *op, *sp;
		    cp = szCopy;
		    op = szBuffer;
		    while (op != m) *cp++ = *op++;
		    sp = p->value;
		    while (sp && *sp) *cp++ = *sp++;
		    op += strlen(p->key);
		    while (*op) *cp++ = *op++;
		    *cp = 0;
		    memcpy(szBuffer, szCopy, sizeof(szCopy));
		}
	    }
	    printf("%s", szBuffer);
	    printf(szBuffer);
	}

	list_free(&substPtr);
    }
    fclose(fp);
    return 0;
}

BOOL FileExists(LPCTSTR szPath)
{
#ifndef INVALID_FILE_ATTRIBUTES
    #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif
    DWORD pathAttr = GetFileAttributes(szPath);
    return (pathAttr != INVALID_FILE_ATTRIBUTES &&
	    !(pathAttr & FILE_ATTRIBUTE_DIRECTORY));
}


/*
 * QualifyPath --
 *
 *	This composes the current working directory with a provided path
 *	and returns the fully qualified and normalized path.
 *	Mostly needed to setup paths for testing.
 */

static int
QualifyPath(
    const char *szPath)
{
    char szCwd[MAX_PATH + 1];

    GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
    printf("%s\n", szCwd);
    return 0;
}

/*
 * Implements LocateDependency for a single directory. See that command
 * for an explanation.
 * Returns 0 if found after printing the directory.
 * Returns 1 if not found but no errors.
 * Returns 2 on any kind of error
 * Basically, these are used as exit codes for the process.
 */
static int LocateDependencyHelper(const char *dir, const char *keypath)
{
    HANDLE hSearch;
    char path[MAX_PATH+1];
    char szTmp[MAX_PATH + 1];
    size_t dirlen;
    int keylen, ret;
    WIN32_FIND_DATA finfo;

    char *p;
    if (dir == NULL || keypath == NULL)
	return 2; /* Have no real error reporting mechanism into nmake */
    dirlen = strlen(dir);
    if ((dirlen + 3) > sizeof(path))
	return 2;
    strncpy(path, dir, dirlen);
    strncpy(path+dirlen, "\\*", 3);	/* Including terminating \0 */
    keylen = strlen(keypath);

    GetCurrentDirectory(MAX_PATH, szCwd);
#if 0 /* This function is not available in Visual C++ 6 */
    /*
     * Use numerics 0 -> FindExInfoStandard,
     * 1 -> FindExSearchLimitToDirectories,
     * as these are not defined in Visual C++ 6
     */
    hSearch = FindFirstFileEx(path, 0, &finfo, 1, NULL, 0);
#else
    hSearch = FindFirstFile(path, &finfo);
#endif
    if (hSearch == INVALID_HANDLE_VALUE)
	return 1; /* Not found */

    while ((p = strchr(szPath, '/')) && *p)
    /* Loop through all subdirs checking if the keypath is under there */
    ret = 1; /* Assume not found */
    do {
	int sublen;
	/*
	 * We need to check it is a directory despite the
	 * FindExSearchLimitToDirectories in the above call. See SDK docs
	 */
	if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
	    continue;
	sublen = strlen(finfo.cFileName);
	if ((dirlen+1+sublen+1+keylen+1) > sizeof(path))
	    continue;		/* Path does not fit, assume not matched */
	strncpy(path+dirlen+1, finfo.cFileName, sublen);
	path[dirlen+1+sublen] = '\\';
	*p = '\\';
	strncpy(path+dirlen+1+sublen+1, keypath, keylen+1);
	if (FileExists(path)) {
	    /* Found a match, print to stdout */
	    path[dirlen+1+sublen] = '\0';
	    QualifyPath(path);
    PathCombine(szTmp, szCwd, szPath);
	    ret = 0;
	    break;
	}
    } while (FindNextFile(hSearch, &finfo));
    FindClose(hSearch);
    return ret;
}

    PathCanonicalize(szCwd, szTmp);
/*
 * LocateDependency --
 *
 *	Locates a dependency for a package.
 *        keypath - a relative path within the package directory
 *          that is used to confirm it is the correct directory.
 *	The search path for the package directory is currently only
 *      the parent and grandparent of the current working directory.
 *      If found, the command prints
 *         name_DIRPATH=<full path of located directory>
 *      and returns 0. If not found, does not print anything and returns 1.
 */
static int LocateDependency(const char *keypath)
{
    size_t i;
    int ret;
    static const char *paths[] = {"..", "..\\..", "..\\..\\.."};

    printf("%s\n", szCwd);
    for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
	ret = LocateDependencyHelper(paths[i], keypath);
	if (ret == 0)
	    return ret;
    }
    return 0;
}
    return ret;
}


/*
 * Local variables:
 *   mode: c
 *   c-basic-offset: 4
 *   fill-column: 78
 *   indent-tabs-mode: t
 *   tab-width: 8
 * End:
 */

Added win/rc/buttons.bmp.

cannot compute difference between binary files

Added win/rc/lamp.bmp.

cannot compute difference between binary files

Changes to win/rc/tk.rc.

1
2
3
4
5
6
7
8
9
10






11
12
13
14
15
16
17

18
19
20
21
22
23
24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30










+
+
+
+
+
+






-
+







//
// Version Resource Script
//

#include <windows.h>
#include <tk.h>

//
// build-up the name suffix that defines the type of build this is.
//
#if TCL_THREADS
#define SUFFIX_THREADS	    "t"
#else
#define SUFFIX_THREADS	    ""
#endif

#if DEBUG && !UNCHECKED
#define SUFFIX_DEBUG	    "g"
#else
#define SUFFIX_DEBUG	    ""
#endif

#define SUFFIX		    SUFFIX_DEBUG
#define SUFFIX		    SUFFIX_THREADS SUFFIX_DEBUG


VS_VERSION_INFO	VERSIONINFO
 FILEVERSION	TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 PRODUCTVERSION	TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 FILEFLAGSMASK	0x3fL
#ifdef DEBUG
32
33
34
35
36
37
38

39
40

41
42
43
44
45
46
47
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54







+

-
+







BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription", "Tk DLL\0"
            VALUE "OriginalFilename", "tk" STRINGIFY(TK_MAJOR_VERSION) STRINGIFY(TK_MINOR_VERSION) SUFFIX ".dll\0"
            VALUE "CompanyName", "ActiveState Corporation\0"
            VALUE "FileVersion", TK_PATCH_LEVEL
            VALUE "LegalCopyright", "Copyright \251 1987-2022 Regents of the University of California and other parties\0"
            VALUE "LegalCopyright", "Copyright \251 2001 by ActiveState Corporation, et al\0"
            VALUE "ProductName", "Tk " TK_VERSION " for Windows\0"
            VALUE "ProductVersion", TK_PATCH_LEVEL
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200

Changes to win/rc/tk_base.rc.

45
46
47
48
49
50
51






52
53
54
55
56
57
58
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+
+
+
+
+
+







    COMBOBOX        cmb1,8,253,135,21,CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED |
                    CBS_AUTOHSCROLL | CBS_SORT | CBS_HASSTRINGS | WS_BORDER |
                    WS_VSCROLL

END


//
// Bitmaps
//

buttons			BITMAP  DISCARDABLE	"buttons.bmp"

//
// Cursors
//

X_cursor                CURSOR  DISCARDABLE     "cursor00.cur"
arrow                   CURSOR  DISCARDABLE     "cursor02.cur"
based_arrow_down        CURSOR  DISCARDABLE     "cursor04.cur"

Deleted win/rc/tktest.rc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
















































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
//
// Version Resource Script
//

#include <windows.h>
#include <tk.h>

//
// build-up the name suffix that defines the type of build this is.
//
#if STATIC_BUILD
#define SUFFIX_STATIC	    "s"
#else
#define SUFFIX_STATIC	    ""
#endif

#if DEBUG && !UNCHECKED
#define SUFFIX_DEBUG	    "g"
#else
#define SUFFIX_DEBUG	    ""
#endif

#define SUFFIX		    SUFFIX_STATIC SUFFIX_DEBUG


VS_VERSION_INFO VERSIONINFO
 FILEVERSION    TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 PRODUCTVERSION TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 FILEFLAGSMASK	0x3fL
#ifdef DEBUG
 FILEFLAGS	VS_FF_DEBUG
#else
 FILEFLAGS	0x0L
#endif
 FILEOS		VOS__WINDOWS32
 FILETYPE	VFT_APP
 FILESUBTYPE	0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription", "Tktest Application\0"
            VALUE "OriginalFilename", "tktest" STRINGIFY(TK_MAJOR_VERSION) STRINGIFY(TK_MINOR_VERSION) SUFFIX ".exe\0"
            VALUE "FileVersion", TK_PATCH_LEVEL
            VALUE "LegalCopyright", "Copyright \251 1987-2022 Regents of the University of California and other parties\0"
            VALUE "ProductName", "Tk " TK_VERSION " for Windows\0"
            VALUE "ProductVersion", TK_PATCH_LEVEL
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

//
// Icon
//
//   The icon whose name or resource ID is lexigraphically first, is used
//   as the application's icon.
//

app                      ICON    DISCARDABLE     "wish.ico"

#if STATIC_BUILD
#include "tk_base.rc"
#endif

//
// This enables themed scrollbars in XP by trying to use comctl32 v6.
//

#ifndef RT_MANIFEST
#define RT_MANIFEST     24
#endif
#ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
#endif
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "wish.exe.manifest"

Changes to win/rc/wish.rc.

1
2
3
4
5
6
7
8
9
10






11
12
13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36










+
+
+
+
+
+












-
+







//
// Version Resource Script
//

#include <windows.h>
#include <tk.h>

//
// build-up the name suffix that defines the type of build this is.
//
#if TCL_THREADS
#define SUFFIX_THREADS	    "t"
#else
#define SUFFIX_THREADS	    ""
#endif

#if STATIC_BUILD
#define SUFFIX_STATIC	    "s"
#else
#define SUFFIX_STATIC	    ""
#endif

#if DEBUG && !UNCHECKED
#define SUFFIX_DEBUG	    "g"
#else
#define SUFFIX_DEBUG	    ""
#endif

#define SUFFIX		    SUFFIX_STATIC SUFFIX_DEBUG
#define SUFFIX		    SUFFIX_THREADS SUFFIX_STATIC SUFFIX_DEBUG


VS_VERSION_INFO VERSIONINFO
 FILEVERSION    TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 PRODUCTVERSION TK_MAJOR_VERSION,TK_MINOR_VERSION,TK_RELEASE_LEVEL,TK_RELEASE_SERIAL
 FILEFLAGSMASK	0x3fL
#ifdef DEBUG
38
39
40
41
42
43
44

45
46

47
48
49
50
51
52
53
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60







+

-
+







BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription", "Wish Application\0"
            VALUE "OriginalFilename", "wish" STRINGIFY(TK_MAJOR_VERSION) STRINGIFY(TK_MINOR_VERSION) SUFFIX ".exe\0"
            VALUE "CompanyName", "ActiveState Corporation\0"
            VALUE "FileVersion", TK_PATCH_LEVEL
            VALUE "LegalCopyright", "Copyright \251 1987-2022 Regents of the University of California and other parties\0"
            VALUE "LegalCopyright", "Copyright \251 2000 by ActiveState Corporation, et al\0"
            VALUE "ProductName", "Tk " TK_VERSION " for Windows\0"
            VALUE "ProductVersion", TK_PATCH_LEVEL
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200

Deleted win/rules-ext.vc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123



























































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
# This file should only be included in makefiles for Tcl extensions,
# NOT in the makefile for Tcl itself.

!ifndef _RULES_EXT_VC

# We need to run from the directory the parent makefile is located in.
# nmake does not tell us what makefile was used to invoke it so parent
# makefile has to set the MAKEFILEVC macro or we just make a guess and
# warn if we think that is not the case.
!if "$(MAKEFILEVC)" == ""

!if exist("$(PROJECT).vc")
MAKEFILEVC = $(PROJECT).vc
!elseif exist("makefile.vc")
MAKEFILEVC = makefile.vc
!endif
!endif # "$(MAKEFILEVC)" == ""

!if !exist("$(MAKEFILEVC)")
MSG = ^
You must run nmake from the directory containing the project makefile.^
If you are doing that and getting this message, set the MAKEFILEVC^
macro to the name of the project makefile.
!message WARNING: $(MSG)
!endif

!if "$(PROJECT)" == "tcl"
!error The rules-ext.vc file is not intended for Tcl itself.
!endif

# We extract version numbers using the nmakehlp program. For now use
# the local copy of nmakehlp. Once we locate Tcl, we will use that
# one if it is newer.
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
!if [$(CC) -nologo -DNDEBUG "nmakehlp.c" -link -subsystem:console > nul]
!endif
!else
!if [copy x86_64-w64-mingw32-nmakehlp.exe nmakehlp.exe >NUL]
!endif
!endif

# First locate the Tcl directory that we are working with.
!if "$(TCLDIR)" != ""

_RULESDIR = $(TCLDIR:/=\)

!else

# If an installation path is specified, that is also the Tcl directory.
# Also Tk never builds against an installed Tcl, it needs Tcl sources
!if defined(INSTALLDIR) && "$(PROJECT)" != "tk"
_RULESDIR=$(INSTALLDIR:/=\)
!else
# Locate Tcl sources
!if [echo _RULESDIR = \> nmakehlp.out] \
   || [nmakehlp -L generic\tcl.h >> nmakehlp.out]
_RULESDIR = ..\..\tcl
!else
!include nmakehlp.out
!endif

!endif # defined(INSTALLDIR)....

!endif # ifndef TCLDIR

# Now look for the targets.vc file under the Tcl root. Note we check this
# file and not rules.vc because the latter also exists on older systems.
!if exist("$(_RULESDIR)\lib\nmake\targets.vc") # Building against installed Tcl
_RULESDIR = $(_RULESDIR)\lib\nmake
!elseif exist("$(_RULESDIR)\win\targets.vc")   # Building against Tcl sources
_RULESDIR = $(_RULESDIR)\win
!else
# If we have not located Tcl's targets file, most likely we are compiling
# against an older version of Tcl and so must use our own support files.
_RULESDIR = .
!endif

!if "$(_RULESDIR)" != "."
# Potentially using Tcl's support files. If this extension has its own
# nmake support files, need to compare the versions and pick newer.

!if exist("rules.vc") # The extension has its own copy

!if [echo TCL_RULES_MAJOR = \> versions.vc] \
   && [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MAJOR >> versions.vc]
!endif
!if [echo TCL_RULES_MINOR = \>> versions.vc] \
   && [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MINOR >> versions.vc]
!endif

!if [echo OUR_RULES_MAJOR = \>> versions.vc] \
   && [nmakehlp -V "rules.vc" RULES_VERSION_MAJOR >> versions.vc]
!endif
!if [echo OUR_RULES_MINOR = \>> versions.vc] \
   && [nmakehlp -V "rules.vc" RULES_VERSION_MINOR >> versions.vc]
!endif
!include versions.vc
# We have a newer version of the support files, use them
!if ($(TCL_RULES_MAJOR) != $(OUR_RULES_MAJOR)) || ($(TCL_RULES_MINOR) < $(OUR_RULES_MINOR))
_RULESDIR = .
!endif

!endif # if exist("rules.vc")

!endif # if $(_RULESDIR) != "."

# Let rules.vc know what copy of nmakehlp.c to use.
NMAKEHLPC = $(_RULESDIR)\nmakehlp.c

# Get rid of our internal defines before calling rules.vc
!undef TCL_RULES_MAJOR
!undef TCL_RULES_MINOR
!undef OUR_RULES_MAJOR
!undef OUR_RULES_MINOR

!if exist("$(_RULESDIR)\rules.vc")
!message *** Using $(_RULESDIR)\rules.vc
!include "$(_RULESDIR)\rules.vc"
!else
!error *** Could not locate rules.vc in $(_RULESDIR)
!endif

!endif # _RULES_EXT_VC

Changes to win/rules.vc.

1

2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33

34
35
36
37

38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101

102
103

104
105
106

107
108
109
110
111
112


113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144





145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515



516
517
518

519
520
521
522
523
524
525
526
527




528
529


530
531
532
533

534
535
536



537
538
539
540
541
542
543
544
545


546
547

548
549

550


551

552

553
554
555

556

557
558


559
560
561
562
563
564
565
566
567
568

569
570
571

572
573
574
575
576






577
578

579
580
581
582


583



584
585



586
587
588
























589
590
591
592
593
594
595

596
597
598
599
600
601
602
603
604
605
606
607
608
609

610
611
612


613
614


615
616
617

618
619
620
621
622
623
624
625
626
627
628
629



630
631


632
633
634
635
636
637
638

639
640

641
642
643
644
645
646
647
648

649
650
651

652
653
654
655
656
657
658
659
660
661
662
663
664
665
666


667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

750
751
752

753
754
755

756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850


851
852
853
854
855
856
857
858
859
860
861

862
863



864
865
866
867

868
869
870
871


872
873
874
875
876

877
878
879


880
881
882
883
884

885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926




927
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953

954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048












1049
1050
1051
1052

1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066

1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129

1130

1131
1132
1133


1134
1135
1136

1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1148

1149
1150
1151
1152
1153
1154
1155
1156

1157
1158

1159
1160

1161
1162
1163
1164
1165
1166


1167
1168
1169



1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210

1211
1212

1213
1214
1215

1216
1217
1218
1219
1220

1221
1222
1223
1224
1225


1226
1227
1228





1229
1230

1231
1232
1233
1234




1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249

1250
1251
1252
1253
1254
1255
1256
1257



1258
1259

1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280

1281
1282
1283


1284
1285
1286

1287
1288

1289
1290
1291
1292
1293




1294
1295
1296
1297
1298
1299

1300


1301

1302
1303
1304
1305
1306
1307
1308
1309
1310




1311
1312
1313


1314
1315
1316


1317
1318
1319


1320
1321

1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334



1335
1336
1337
1338
1339
1340

1341
1342
1343
1344
1345

1346
1347

1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360

1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386

1387
1388


1389
1390
1391
1392
1393
1394
1395


1396
1397
1398


1399
1400
1401


1402
1403
1404
1405
1406





1407
1408

1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444

1445

1446
1447
1448
1449

1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469


1470
1471
1472

1473
1474
1475
1476



1477
1478

1479
1480
1481

1482
1483
1484
1485
1486
1487










1488
1489

1490
1491


1492
1493
1494
1495


1496
1497
1498
1499

1500
1501
1502
1503
1504



1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515

1516
1517
1518
1519
1520

1521
1522
1523
1524
1525

1526
1527
1528

1529
1530

1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565

1566
1567
1568


1569
1570


1571
1572

1573

1574


1575
1576

1577
1578
1579

1580
1581
1582
1583
1584
1585





1586
1587
1588

1589
1590
1591
1592

1593
1594
1595
1596

1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610

1611
1612
1613
1614

1615
1616
1617

1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637
1638
1639
1640

1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658





1659
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


1
2
3


4
5





6
7
8
9
10
11

12
13
14
15
16






17





18




19









20


















































21





22


23



24






25
26






27




28













29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46




































47





































48











































































































































































































49



50
51
52
53
54
55
56
57
58
59


60

61
62

63
64
65
66




67



68
69
70








































71
72


73
74
75
76
77
78
79
80
81
82



83
84
85



86









87
88
89
90


91
92




93



94
95
96
97








98
99
100

101

102
103

104
105
106
107

108



109

110
111

112
113
114

115







116



117





118
119
120
121
122
123


124
125


126
127
128

129
130
131
132
133
134
135
136



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172









173



174
175


176
177
178


179

180




181
182




183
184
185


186
187
188






189


190






191

192



193







194
195
196
197




198
199
200















































































201


202



203



204

205



206






























































207
208
209
210
211
212
213
214
215
216
217



218









219
220
221


222
223



224

225
226
227
228
229
230
231
232

233
234
235
236
237
238

239

240
241
242
243
244
245

246
247

248
249


250
251





252




253




254
255
256
257
258
259

260
261
262
263
264
265

266
267
268
269
270
271

272
273
274
275
276
277
278
279
280

281

282
283
284
285
286


287
288
289
290

291
292
293
294

295
296
297
298
299
300





301
302


303






















































































304








305
306
307
308
309
310
311
312
313
314
315
316




317














318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370










371
372

373



374
375



376




377








378


379





380


381


382






383
384
385


386
387
388

389

390
391





392






393

394






















395


396



397


398


399





400
401
402


403
404
405
406
407
408

409




410
411
412
413








414


415

416
417

418








419
420
421


422












423


424






425



426
427



428


429





430
431
432
433






434
435
436
437

438
439






440

441
442
443
444
445


446
447



448
449


450
451
452
453

454













455
456
457






458

459



460


461







462

463




464
465
466





















467



468


469
470
471


472



473
474
475


476
477
478


479
480


481


482
483
484
485
486


487








488




489






490





491










492
493

494




495


496













497



498
499



500




501
502
503
504

505



506






507
508
509
510
511
512
513
514
515
516
517

518


519
520

521


522
523
524



525





526
527
528



529

530




531

532





533



534

535



536
537

538




539





540


















541







542



543
544


545
546


547

548
549
550
551
552

553



554
555





556
557
558
559
560

561

562




563




564


565
566




567



568


569




570



571



572













573

574




575


















576
577
578
579
580


581

582



583



584




585



586






587
588
589
590
591
592
593
594
595
596
597
598
599



600
601
602



603
604




605
606





607
608




609
610
611




612


613


614


615
616



617


618


619


620
621



622
623
624





625
626


627








628




629
630



631




632


633
634

635



636
637


638






639
640


641





642
643

644




645




646





647


648



649
650




651
652
653















654

655
656
657
658


659
660


661
662

663




664





665




666





667




668

669
670

671




672
673
674


675



676
677

678







679



680
681
682
683



684
685
686
687
688


689




690




691
692

693


694
695
696
697

698



699
700
701
702
703






704
705

706
707

708
709
710
711
712

713
-
+


-
-
+
+
-
-
-
-
-






-





-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-








+
+
+
+
+

-

+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-










-
-

-
+

-




-
-
-
-

-
-
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-










-
-
-
+
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
-
+
-
-
-
+
+
+

-
-
-
-
-
-
-
-
+
+

-
+
-

+
-
+
+

+
-
+
-
-
-
+
-
+

-
+
+

-

-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
-
-
+

-
-

+
+
-
+
+
+


+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+





-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
+
+

-
-
+
-

-
-
-
-


-
-
-
-
+
+
+
-
-
+
+

-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-

-
+
-
-
-
+
-
-
-
-
-
-
-




-
-
-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
-
-
-
+
-
-
-
+
-

-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







+



-
-
-

-
-
-
-
-
-
-
-
-



-
-
+
+
-
-
-

-






+

-
+
+
+



-
+
-



+
+

-


-
+

-
-
+
+
-
-
-
-
-
+
-
-
-
-

-
-
-
-






-






-






-









-

-
+
+
+
+

-
-




-

+


-






-
-
-
-
-


-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+















-
+














-
+





-
+















-
-
-
-
-
-
-
-
-
-

+
-
+
-
-
-
+
+
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-

-
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
+
+

-
-
+
+
+
-

-
+

-
-
-
-
-

-
-
-
-
-
-

-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-

-
-
+
-
-
-
-
-
+
+

-
-
+
+
+
+
+

-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-

-
-

-
+

-
+
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
+
-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+

+
+
-
+

-
-
-
-
-
-

-
+
+
+
+

-
-
+
+
-
-
-
+
+
-
-

+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
+
-

-
-
-
+
-
-
+
-
-
-
-
-
-
-

-
+
-
-
-
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
+

-
-

-
-
-
+
+

-
-
+
+

-
-
+
+
-
-

-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-

-
-
-
-
+
-
-
-
-
-
-

-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-

+
-
+
-
-
-
-
+
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
+
-
-
-
+
-
-
-
-
+
+
+

-
+
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+
-
-
+
+
-

-
-
+
+

-
-
-
+
-
-
-
-
-
+
+
+
-
-
-

-
+
-
-
-
-

-
+
-
-
-
-
-
+
-
-
-

-
+
-
-
-
+

-
+
-
-
-
-
+
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
+
+
-
-
+
-
+

+
+

-
+
-
-
-
+

-
-
-
-
-
+
+
+
+
+
-

-
+
-
-
-
-
+
-
-
-
-
+
-
-


-
-
-
-
+
-
-
-

-
-
+
-
-
-
-
+
-
-
-
+
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
-

-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-

-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-

-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
+
+
-
-
-
-
+

+
-
-
-
-

-
-
+
-
-
+
-
-
+

-
-
-
+
-
-
+
-
-
+
-
-
+

-
-
-
+
+
+
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
+
-
-
-
-
+
-
-
+

-
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
-
+

-
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+

+
+
-
-
+
+
-
-
+

-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-

-
-
-
-
-
+
-
-
-
-

-
+
+
-

-
-
-
-
+
+
+
-
-
+
-
-
-
+

-
+
-
-
-
-
-
-
-
+
-
-
-
+
+

+
-
-
-
+
+
+
+

-
-
+
-
-
-
-
+
-
-
-
-
+
+
-

-
-
+



-
+
-
-
-





-
-
-
-
-
-


-

+
-
+
+
+
+

-
+
#------------------------------------------------------------- -*- makefile -*-
#------------------------------------------------------------------------------
# rules.vc --
#
# Part of the nmake based build system for Tcl and its extensions.
# This file does all the hard work in terms of parsing build options,
#	Microsoft Visual C++ makefile include for decoding the commandline
#	macros.  This file does not need editing to build Tcl.
# compiler switches, defining common targets and macros. The Tcl makefile
# directly includes this. Extensions include it via "rules-ext.vc".
#
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for
# detailed documentation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Copyright (c) 2001-2003 David Gravereaux.
# Copyright (c) 2003-2008 Patrick Thoyts
# Copyright (c) 2017      Ashok P. Nadkarni
#------------------------------------------------------------------------------

!ifndef _RULES_VC
_RULES_VC = 1

# The following macros define the version of the rules.vc nmake build system
# For modifications that are not backward-compatible, you *must* change
# the major version.
RULES_VERSION_MAJOR = 1
RULES_VERSION_MINOR = 11

cc32		= $(CC)   # built-in default.
# The PROJECT macro must be defined by parent makefile.
!if "$(PROJECT)" == ""
!error *** Error: Macro PROJECT not defined! Please define it before including rules.vc
!endif

link32		= link
!if "$(PRJ_PACKAGE_TCLNAME)" == ""
PRJ_PACKAGE_TCLNAME = $(PROJECT)
!endif

lib32		= lib
# Also special case Tcl and Tk to save some typing later
DOING_TCL = 0
DOING_TK  = 0
!if "$(PROJECT)" == "tcl"
DOING_TCL = 1
!elseif "$(PROJECT)" == "tk"
DOING_TK = 1
!endif

rc32		= $(RC)   # built-in default.
!ifndef NEED_TK
# Backwards compatibility
!ifdef PROJECT_REQUIRES_TK
NEED_TK = $(PROJECT_REQUIRES_TK)
!else
NEED_TK = 0
!endif
!endif

!ifndef NEED_TCL_SOURCE
NEED_TCL_SOURCE = 0
!endif

!ifdef NEED_TK_SOURCE
!if $(NEED_TK_SOURCE)
NEED_TK = 1
!endif
!else
NEED_TK_SOURCE = 0
!endif

################################################################
# Nmake is a pretty weak environment in syntax and capabilities
# so this file is necessarily verbose. It's broken down into
# the following parts.
#
# 0. Sanity check that compiler environment is set up and initialize
#    any built-in settings from the parent makefile
# 1. First define the external tools used for compiling, copying etc.
#    as this is independent of everything else.
# 2. Figure out our build structure in terms of the directory, whether
#    we are building Tcl or an extension, etc.
# 3. Determine the compiler and linker versions
# 4. Build the nmakehlp helper application
# 5. Determine the supported compiler options and features
# 6. Extract Tcl, Tk, and possibly extensions, version numbers from the
#    headers
# 7. Parse the OPTS macro value for user-specified build configuration
# 8. Parse the STATS macro value for statistics instrumentation
# 9. Parse the CHECKS macro for additional compilation checks
# 10. Based on this selected configuration, construct the output
#     directory and file paths
# 11. Construct the paths where the package is to be installed
# 12. Set up the actual options passed to compiler and linker based
#     on the information gathered above.
# 13. Define some standard build targets and implicit rules. These may
#     be optionally disabled by the parent makefile.
# 14. (For extensions only.) Compare the configuration of the target
#     Tcl and the extensions and warn against discrepancies.
#

# One final note about the macro names used. They are as they are
# for historical reasons. We would like legacy extensions to
# continue to work with this make include file so be wary of
# changing them for consistency or clarity.

!ifndef INSTALLDIR
# 0. Sanity check compiler environment

### Assume the normal default.
# Check to see we are configured to build with MSVC (MSDEVDIR, MSVCDIR or
# VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir)

_INSTALLDIR	= C:\Program Files\Tcl
!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(VCINSTALLDIR) && !defined(MSSDK) && !defined(WINDOWSSDKDIR)
MSG = ^
Visual C++ compiler environment not initialized.
!error $(MSG)
!endif

!else
### Fix the path separators.
# We need to run from the directory the parent makefile is located in.
# nmake does not tell us what makefile was used to invoke it so parent
# makefile has to set the MAKEFILEVC macro or we just make a guess and
# warn if we think that is not the case.
!if "$(MAKEFILEVC)" == ""

_INSTALLDIR	= $(INSTALLDIR:/=\)
!if exist("$(PROJECT).vc")
MAKEFILEVC = $(PROJECT).vc
!elseif exist("makefile.vc")
MAKEFILEVC = makefile.vc
!endif
!endif # "$(MAKEFILEVC)" == ""

!if !exist("$(MAKEFILEVC)")
MSG = ^
You must run nmake from the directory containing the project makefile.^
If you are doing that and getting this message, set the MAKEFILEVC^
macro to the name of the project makefile.
!message WARNING: $(MSG)
!endif


################################################################
# 1. Define external programs being used

#----------------------------------------------------------
# Set the proper copy method to avoid overwrite questions
# to the user when copying files and selecting the right
# "delete all" method.
#----------------------------------------------------------

RMDIR	= rmdir /S /Q
ERRNULL  = 2>NUL
!if ![ver | find "4.0" > nul]
CPY	= echo y | xcopy /i >NUL
COPY	= copy >NUL
!else
CPY	= xcopy /i /y >NUL
CPYDIR  = xcopy /e /i /y >NUL
COPY	= copy /y >NUL
!endif
MKDIR   = mkdir

######################################################################
# 2. Figure out our build environment in terms of what we're building.
#
# (a) Tcl itself
# (b) Tk
# (c) a Tcl extension using libraries/includes from an *installed* Tcl
# (d) a Tcl extension using libraries/includes from Tcl source directory
#
# This last is needed because some extensions still need
# some Tcl interfaces that are not publicly exposed.
#
# The fragment will set the following macros:
# ROOT - root of this module sources
# COMPATDIR - source directory that holds compatibility sources
# DOCDIR - source directory containing documentation files
# GENERICDIR - platform-independent source directory
# WIN_DIR - Windows-specific source directory
# TESTDIR - directory containing test files
# TOOLSDIR - directory containing build tools
# _TCLDIR - root of the Tcl installation OR the Tcl sources. Not set
#    when building Tcl itself.
# _INSTALLDIR - native form of the installation path. For Tcl
#    this will be the root of the Tcl installation. For extensions
#    this will be the lib directory under the root.
# TCLINSTALL  - set to 1 if _TCLDIR refers to
#    headers and libraries from an installed Tcl, and 0 if built against
#    Tcl sources. Not set when building Tcl itself. Yes, not very well
#    named.
# _TCL_H - native path to the tcl.h file
#
# If Tk is involved, also sets the following
# _TKDIR - native form Tk installation OR Tk source. Not set if building
#    Tk itself.
# TKINSTALL - set 1 if _TKDIR refers to installed Tk and 0 if Tk sources
# _TK_H - native path to the tk.h file

#------------------------------------------------------------------------------
# Root directory for sources and assumed subdirectories
ROOT = $(MAKEDIR)\..
# The following paths CANNOT have spaces in them as they appear on the
# left side of implicit rules.
!ifndef COMPATDIR
COMPATDIR	= $(ROOT)\compat
!endif
!ifndef DOCDIR
DOCDIR		= $(ROOT)\doc
!endif
!ifndef GENERICDIR
GENERICDIR	= $(ROOT)\generic
!endif
!ifndef TOOLSDIR
TOOLSDIR	= $(ROOT)\tools
!endif
!ifndef TESTDIR
TESTDIR	= $(ROOT)\tests
!endif
!ifndef LIBDIR
!if exist("$(ROOT)\library")
LIBDIR          = $(ROOT)\library
!else
LIBDIR          = $(ROOT)\lib
!endif
!endif
!ifndef DEMODIR
!if exist("$(LIBDIR)\demos")
DEMODIR		= $(LIBDIR)\demos
!else
DEMODIR		= $(ROOT)\demos
!endif
!endif # ifndef DEMODIR
# Do NOT use WINDIR because it is Windows internal environment
# variable to point to c:\windows!
WIN_DIR		= $(ROOT)\win

# Determine the host and target architectures and compiler version.
!ifndef RCDIR
!if exist("$(WIN_DIR)\rc")
RCDIR           = $(WIN_DIR)\rc
!else
RCDIR           = $(WIN_DIR)
!endif
!endif
RCDIR = $(RCDIR:/=\)

# The target directory where the built packages and binaries will be installed.
# INSTALLDIR is the (optional) path specified by the user.
# _INSTALLDIR is INSTALLDIR using the backslash separator syntax
!ifdef INSTALLDIR
### Fix the path separators.
_INSTALLDIR	= $(INSTALLDIR:/=\)
!else
### Assume the normal default.
_INSTALLDIR	= $(HOMEDRIVE)\Tcl
!endif

!if $(DOING_TCL)

# BEGIN Case 2(a) - Building Tcl itself

# Only need to define _TCL_H
_TCL_H = ..\generic\tcl.h

# END Case 2(a) - Building Tcl itself

!elseif $(DOING_TK)

# BEGIN Case 2(b) - Building Tk

TCLINSTALL = 0 # Tk always builds against Tcl source, not an installed Tcl
!if "$(TCLDIR)" == ""
!if [echo TCLDIR = \> nmakehlp.out] \
   || [nmakehlp -L generic\tcl.h >> nmakehlp.out]
!error *** Could not locate Tcl source directory.
!endif
!include nmakehlp.out
!endif # TCLDIR == ""

_TCLDIR	= $(TCLDIR:/=\)
_TCL_H  = $(_TCLDIR)\generic\tcl.h
!if !exist("$(_TCL_H)")
!error Could not locate tcl.h. Please set the TCLDIR macro to point to the Tcl *source* directory.
!endif

_TK_H = ..\generic\tk.h

# END Case 2(b) - Building Tk

!else

# BEGIN Case 2(c) or (d) - Building an extension other than Tk

# If command line has specified Tcl location through TCLDIR, use it
# else default to the INSTALLDIR setting
!if "$(TCLDIR)" != ""

_TCLDIR	= $(TCLDIR:/=\)
!if exist("$(_TCLDIR)\include\tcl.h") # Case 2(c) with TCLDIR defined
TCLINSTALL	= 1
_TCL_H          = $(_TCLDIR)\include\tcl.h
!elseif exist("$(_TCLDIR)\generic\tcl.h") # Case 2(d) with TCLDIR defined
TCLINSTALL	= 0
_TCL_H          = $(_TCLDIR)\generic\tcl.h
!endif

!else  #  # Case 2(c) for extensions with TCLDIR undefined

# Need to locate Tcl depending on whether it needs Tcl source or not.
# If we don't, check the INSTALLDIR for an installed Tcl first

!if exist("$(_INSTALLDIR)\include\tcl.h") && !$(NEED_TCL_SOURCE)

TCLINSTALL	= 1
TCLDIR          = $(_INSTALLDIR)\..
# NOTE: we will be resetting _INSTALLDIR to _INSTALLDIR/lib for extensions
# later so the \.. accounts for the /lib
_TCLDIR		= $(_INSTALLDIR)\..
_TCL_H          = $(_TCLDIR)\include\tcl.h

!else # exist(...) && !$(NEED_TCL_SOURCE)

!if [echo _TCLDIR = \> nmakehlp.out] \
   || [nmakehlp -L generic\tcl.h >> nmakehlp.out]
!error *** Could not locate Tcl source directory.
!endif
!include nmakehlp.out
TCLINSTALL      = 0
TCLDIR         = $(_TCLDIR)
_TCL_H          = $(_TCLDIR)\generic\tcl.h

!endif # exist(...) && !$(NEED_TCL_SOURCE)

!endif # TCLDIR

!ifndef _TCL_H
MSG =^
Failed to find tcl.h. The TCLDIR macro is set incorrectly or is not set and default path does not contain tcl.h.
!error $(MSG)
!endif

# Now do the same to locate Tk headers and libs if project requires Tk
!if $(NEED_TK)

!if "$(TKDIR)" != ""

_TKDIR = $(TKDIR:/=\)
!if exist("$(_TKDIR)\include\tk.h")
TKINSTALL      = 1
_TK_H          = $(_TKDIR)\include\tk.h
!elseif exist("$(_TKDIR)\generic\tk.h")
TKINSTALL      = 0
_TK_H          = $(_TKDIR)\generic\tk.h
!endif

!else # TKDIR not defined

# Need to locate Tcl depending on whether it needs Tcl source or not.
# If we don't, check the INSTALLDIR for an installed Tcl first

!if exist("$(_INSTALLDIR)\include\tk.h") && !$(NEED_TK_SOURCE)

TKINSTALL      = 1
# NOTE: we will be resetting _INSTALLDIR to _INSTALLDIR/lib for extensions
# later so the \.. accounts for the /lib
_TKDIR         = $(_INSTALLDIR)\..
_TK_H          = $(_TKDIR)\include\tk.h
TKDIR          = $(_TKDIR)

!else # exist("$(_INSTALLDIR)\include\tk.h") && !$(NEED_TK_SOURCE)

!if [echo _TKDIR = \> nmakehlp.out] \
   || [nmakehlp -L generic\tk.h >> nmakehlp.out]
!error *** Could not locate Tk source directory.
!endif
!include nmakehlp.out
TKINSTALL      = 0
TKDIR          = $(_TKDIR)
_TK_H          = $(_TKDIR)\generic\tk.h

!endif # exist("$(_INSTALLDIR)\include\tk.h") && !$(NEED_TK_SOURCE)

!endif # TKDIR

!ifndef _TK_H
MSG =^
Failed to find tk.h. The TKDIR macro is set incorrectly or is not set and default path does not contain tk.h.
!error $(MSG)
!endif

!endif # NEED_TK

!if $(NEED_TCL_SOURCE) && $(TCLINSTALL)
MSG = ^
*** Warning: This extension requires the source distribution of Tcl.^
*** Please set the TCLDIR macro to point to the Tcl sources.
!error $(MSG)
!endif

!if $(NEED_TK_SOURCE)
!if $(TKINSTALL)
MSG = ^
*** Warning: This extension requires the source distribution of Tk.^
*** Please set the TKDIR macro to point to the Tk sources.
!error $(MSG)
!endif
!endif


# If INSTALLDIR set to Tcl installation root dir then reset to the
# lib dir for installing extensions
!if exist("$(_INSTALLDIR)\include\tcl.h")
_INSTALLDIR=$(_INSTALLDIR)\lib
!endif

# END Case 2(c) or (d) - Building an extension
!endif # if $(DOING_TCL)

################################################################
# 3. Determine compiler version and architecture
# In this section, we figure out the compiler version and the
# architecture for which we are building. This sets the
# following macros:
# VCVERSION - the internal compiler version as 1200, 1400, 1910 etc.
#     This is also printed by the compiler in dotted form 19.10 etc.
# VCVER - the "marketing version", for example Visual C++ 6 for internal
#     compiler version 1200. This is kept only for legacy reasons as it
#     does not make sense for recent Microsoft compilers. Only used for
#     output directory names.
# ARCH - set to IX86, ARM64 or AMD64 depending on 32- or 64-bit target
# NATIVE_ARCH - set to IX86, ARM64 or AMD64 for the host machine
# MACHINE - same as $(ARCH) - legacy
# _VC_MANIFEST_EMBED_{DLL,EXE} - commands for embedding a manifest if needed

cc32		= $(CC)   # built-in default.
link32		= link
lib32		= lib
rc32		= $(RC)   # built-in default.

#----------------------------------------------------------------
#------------------------------------------------------------------------------
# Figure out the compiler architecture and version by writing
# the C macros to a file, preprocessing them with the C
# preprocessor and reading back the created file

_HASH=^#
_VC_MANIFEST_EMBED_EXE=
_VC_MANIFEST_EMBED_DLL=
VCVER=0
!if ![echo VCVERSION=_MSC_VER > vercl.x] \
    && ![echo $(_HASH)if defined(_M_IX86) >> vercl.x] \
    && ![echo ARCH=IX86 >> vercl.x] \
    && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
    && ![echo ARCH=AMD64 >> vercl.x] \
    && ![echo $(_HASH)elif defined(_M_ARM64) >> vercl.x] \
    && ![echo ARCH=ARM64 >> vercl.x] \
    && ![echo $(_HASH)endif >> vercl.x] \
    && ![$(cc32) -nologo -TC -P vercl.x 2>NUL]
    && ![cl -nologo -TC -P vercl.x $(ERRNULL)]
!include vercl.i
!if $(VCVERSION) < 1900
!if ![echo VCVER= ^\> vercl.vc] \
    && ![set /a $(VCVERSION) / 100 - 6 >> vercl.vc]
!include vercl.vc
!endif
!else
# The simple calculation above does not apply to new Visual Studio releases
# Keep the compiler version in its native form.
VCVER = $(VCVERSION)
!endif
!endif

!if ![del 2>NUL /q/f vercl.x vercl.i vercl.vc]
!if ![del $(ERRNUL) /q/f vercl.x vercl.i vercl.vc]
!endif

#----------------------------------------------------------------
# The MACHINE macro is used by legacy makefiles so set it as well
!ifdef MACHINE
!if "$(MACHINE)" == "x86"
!undef MACHINE
MACHINE = IX86
!elseif "$(MACHINE)" == "arm64"
!undef MACHINE
MACHINE = ARM64
!elseif "$(MACHINE)" == "x64"
!undef MACHINE
MACHINE = AMD64
!endif
!if "$(MACHINE)" != "$(ARCH)"
!error Specified MACHINE macro $(MACHINE) does not match detected target architecture $(ARCH).
!endif
!else
MACHINE=$(ARCH)
!endif

#---------------------------------------------------------------
# The PLATFORM_IDENTIFY macro matches the values returned by
# the Tcl platform::identify command
!if "$(MACHINE)" == "AMD64"
PLATFORM_IDENTIFY = win32-x86_64
!elseif "$(MACHINE)" == "ARM64"
PLATFORM_IDENTIFY = win32-arm
!else
PLATFORM_IDENTIFY = win32-ix86
!endif

# The MULTIPLATFORM macro controls whether binary extensions are installed
# in platform-specific directories. Intended to be set/used by extensions.
!ifndef MULTIPLATFORM_INSTALL
MULTIPLATFORM_INSTALL = 0
!endif

#------------------------------------------------------------
# Figure out the *host* architecture by reading the registry

!if ![reg query HKLM\Hardware\Description\System\CentralProcessor\0 /v Identifier | findstr /i x86]
NATIVE_ARCH=IX86
!elseif ![reg query HKLM\Hardware\Description\System\CentralProcessor\0 /v Identifier | findstr /i ARM | findstr /i 64-bit]
NATIVE_ARCH=ARM64
!else
NATIVE_ARCH=AMD64
!endif

# Since MSVC8 we must deal with manifest resources.
!if $(VCVERSION) >= 1400
_VC_MANIFEST_EMBED_EXE=if exist [email protected] mt -nologo -manifest [email protected] -outputresource:$@;1
_VC_MANIFEST_EMBED_DLL=if exist [email protected] mt -nologo -manifest [email protected] -outputresource:$@;2
!endif

################################################################
# 4. Build the nmakehlp program
# This is a helper app we need to overcome nmake's limiting
!ifndef MACHINE
MACHINE=$(ARCH)
!endif
# environment. We will call out to it to get various bits of
# information about supported compiler options etc.
#

# Tcl itself will always use the nmakehlp.c program which is
# in its own source. It will be kept updated there.
#
# Extensions built against an installed Tcl will use the installed
# copy of Tcl's nmakehlp.c if there is one and their own version
# otherwise. In the latter case, they would also be using their own
# rules.vc. Note that older versions of Tcl do not install nmakehlp.c
# or rules.vc.
#
!ifndef CFG_ENCODING
CFG_ENCODING	= \"cp1252\"
!endif

# Extensions built against Tcl sources will use the one from the Tcl source.
#
!message ===============================================================================

# When building an extension using a sufficiently new version of Tcl,
# rules-ext.vc will define NMAKEHLPC appropriately to point to the
# copy of nmakehlp.c to be used.

#----------------------------------------------------------
!ifndef NMAKEHLPC
# Default to the one in the current directory (the extension's own nmakehlp.c)
NMAKEHLPC = nmakehlp.c
# build the helper app we need to overcome nmake's limiting
# environment.
#----------------------------------------------------------

!if !$(DOING_TCL)
!if $(TCLINSTALL)
!if exist("$(_TCLDIR)\lib\nmake\nmakehlp.c")
NMAKEHLPC = $(_TCLDIR)\lib\nmake\nmakehlp.c
!endif
!else # !$(TCLINSTALL)
!if exist("$(_TCLDIR)\win\nmakehlp.c")
NMAKEHLPC = $(_TCLDIR)\win\nmakehlp.c
!if !exist(nmakehlp.exe)
!if [$(cc32) -nologo nmakehlp.c -link -subsystem:console > nul]
!endif
!endif # $(TCLINSTALL)
!endif
!endif # !$(DOING_TCL)

#----------------------------------------------------------
!endif # NMAKEHLPC
# Test for compiler features
#----------------------------------------------------------

### test for optimizations
# We always build nmakehlp even if it exists since we do not know
!if [nmakehlp -c -Ot]
# what source it was built from.
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
!if [$(cc32) -nologo "$(NMAKEHLPC)" -link -subsystem:console > nul]
!message *** Compiler has 'Optimizations'
!endif
OPTIMIZING	= 1
!else
!if [copy $(NMAKEHLPC:nmakehlp.c=x86_64-w64-mingw32-nmakehlp.exe) nmakehlp.exe >NUL]
!message *** Compiler does not have 'Optimizations'
OPTIMIZING	= 0
!endif
!endif

################################################################
# 5. Test for compiler features
# Visual C++ compiler options have changed over the years. Check
# which options are supported by the compiler in use.
#
# The following macros are set:
# OPTIMIZATIONS - the compiler flags to be used for optimized builds
OPTIMIZATIONS   =
# DEBUGFLAGS - the compiler flags to be used for debug builds
# LINKERFLAGS - Flags passed to the linker
#

# Note that these are the compiler settings *available*, not those
# that will be *used*. The latter depends on the OPTS macro settings
# which we have not yet parsed.
#
# Also note that some of the flags in OPTIMIZATIONS are not really
!if [nmakehlp -c -Ot]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -Ot
!endif

!if [nmakehlp -c -Oi]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -Oi
# related to optimization. They are placed there only for legacy reasons
# as some extensions expect them to be included in that macro.
!endif

# -Op improves float consistency. Note only needed for older compilers
# Newer compilers do not need or support this option.
!if [nmakehlp -c -Op]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -Op
!endif
FPOPTS  = -Op

!if [nmakehlp -c -fp:strict]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -fp:strict
!endif

!if [nmakehlp -c -Gs]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -Gs
!endif
# Strict floating point semantics - present in newer compilers in lieu of -Op
!if [nmakehlp -c -fp:strict]
FPOPTS  = $(FPOPTS) -fp:strict

!if [nmakehlp -c -GS]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -GS
!endif

!if [nmakehlp -c -GL]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -GL
!endif

DEBUGFLAGS     =

!if [nmakehlp -c -RTC1]
DEBUGFLAGS     = $(DEBUGFLAGS) -RTC1
!elseif [nmakehlp -c -GZ]
DEBUGFLAGS     = $(DEBUGFLAGS) -GZ
!endif

COMPILERFLAGS  =-W3 /DUNICODE /D_UNICODE /D_ATL_XP_TARGETING

# In v13 -GL and -YX are incompatible.
!if [nmakehlp -c -YX]
!if ![nmakehlp -c -GL]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -YX
!endif
!endif

!if "$(MACHINE)" == "IX86"
### test for pentium errata
!if [nmakehlp -c -QI0f]
!message *** Compiler has 'Pentium 0x0f fix'
FPOPTS  = $(FPOPTS) -QI0f
COMPILERFLAGS  = $(COMPILERFLAGS) -QI0f
!else
!message *** Compiler does not have 'Pentium 0x0f fix'
!endif
!endif

### test for optimizations
# /O2 optimization includes /Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy as per
# documentation. Note we do NOT want /Gs as that inserts a _chkstk
# stack probe at *every* function entry, not just those with more than
# a page of stack allocation resulting in a performance hit.  However,
# /O2 documentation is misleading as its stack probes are simply the
# default page size locals allocation probes and not what is implied
# by an explicit /Gs option.

!if "$(MACHINE)" == "IA64"
OPTIMIZATIONS = $(FPOPTS)

!if [nmakehlp -c -O2]
### test for Itanium errata
!if [nmakehlp -c -QIA64_Bx]
OPTIMIZING = 1
OPTIMIZATIONS   = $(OPTIMIZATIONS) -O2
!message *** Compiler has 'B-stepping errata workarounds'
COMPILERFLAGS   = $(COMPILERFLAGS) -QIA64_Bx
!else
# Legacy, really. All modern compilers support this
!message *** Compiler does not have 'Optimizations'
!message *** Compiler does not have 'B-stepping errata workarounds'
OPTIMIZING = 0
!endif

# Checks for buffer overflows in local arrays
!if [nmakehlp -c -GS]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -GS
!endif

# Link time optimization. Note that this option (potentially) makes
# generated libraries only usable by the specific VC++ version that
# created it. Requires /LTCG linker option
!if [nmakehlp -c -GL]
!if "$(MACHINE)" == "IX86"
### test for -align:4096, when align:512 will do.
!if [nmakehlp -l -opt:nowin98]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -GL
CC_GL_OPT_ENABLED = 1
!message *** Linker has 'Win98 alignment problem'
ALIGN98_HACK	= 1
!else
# In newer compilers -GL and -YX are incompatible.
!if [nmakehlp -c -YX]
OPTIMIZATIONS  = $(OPTIMIZATIONS) -YX
!endif
!endif # [nmakehlp -c -GL]

!message *** Linker does not have 'Win98 alignment problem'
DEBUGFLAGS     = $(FPOPTS)

ALIGN98_HACK	= 0
# Run time error checks. Not available or valid in a release, non-debug build
# RTC is for modern compilers, -GZ is legacy
!if [nmakehlp -c -RTC1]
DEBUGFLAGS     = $(DEBUGFLAGS) -RTC1
!elseif [nmakehlp -c -GZ]
DEBUGFLAGS     = $(DEBUGFLAGS) -GZ
!endif

!else
#----------------------------------------------------------------
# Linker flags

ALIGN98_HACK	= 0
# LINKER_TESTFLAGS are for internal use when we call nmakehlp to test
# if the linker supports a specific option. Without these flags link will
# return "LNK1561: entry point must be defined" error compiling from VS-IDE:
# They are not passed through to the actual application / extension
# link rules.
!ifndef LINKER_TESTFLAGS
LINKER_TESTFLAGS = /DLL /NOENTRY /OUT:nmakehlp.out
!endif

LINKERFLAGS     =

# If compiler has enabled link time optimization, linker must too with -ltcg
!ifdef CC_GL_OPT_ENABLED
!if [nmakehlp -l -ltcg $(LINKER_TESTFLAGS)]
LINKERFLAGS     = $(LINKERFLAGS) -ltcg
!if [nmakehlp -l -ltcg]
LINKERFLAGS     =-ltcg
!endif
!endif


################################################################
# 6. Extract various version numbers from headers
# For Tcl and Tk, version numbers are extracted from tcl.h and tk.h
# respectively. For extensions, versions are extracted from the
# configure.in or configure.ac from the TEA configuration if it
# exists, and unset otherwise.
# Sets the following macros:
# TCL_MAJOR_VERSION
# TCL_MINOR_VERSION
# TCL_RELEASE_SERIAL
# TCL_PATCH_LEVEL
# TCL_PATCH_LETTER
# TCL_VERSION
# TK_MAJOR_VERSION
# TK_MINOR_VERSION
# TK_RELEASE_SERIAL
# TK_PATCH_LEVEL
# TK_PATCH_LETTER
# TK_VERSION
# DOTVERSION - set as (for example) 2.5
# VERSION - set as (for example 25)
#--------------------------------------------------------------

!if [echo REM = This file is generated from rules.vc > versions.vc]
!endif
!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" "define TCL_MAJOR_VERSION" >> versions.vc]
!endif
!if [echo TCL_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_MINOR_VERSION >> versions.vc]
!endif
!if [echo TCL_RELEASE_SERIAL = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_RELEASE_SERIAL >> versions.vc]
!endif
!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_PATCH_LEVEL >> versions.vc]
!endif

!if defined(_TK_H)
!if [echo TK_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) "define TK_MAJOR_VERSION" >> versions.vc]
!endif
!if [echo TK_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_MINOR_VERSION >> versions.vc]
!endif
!if [echo TK_RELEASE_SERIAL = \>> versions.vc] \
   && [nmakehlp -V "$(_TK_H)" TK_RELEASE_SERIAL >> versions.vc]
!endif
!if [echo TK_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_PATCH_LEVEL >> versions.vc]
!endif
!endif # _TK_H

!include versions.vc

TCL_VERSION	= $(TCL_MAJOR_VERSION)$(TCL_MINOR_VERSION)
TCL_DOTVERSION	= $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
!if [nmakehlp -f $(TCL_PATCH_LEVEL) "a"]
TCL_PATCH_LETTER = a
!elseif [nmakehlp -f $(TCL_PATCH_LEVEL) "b"]
TCL_PATCH_LETTER = b
!else
TCL_PATCH_LETTER = .
!endif

!if defined(_TK_H)

TK_VERSION	= $(TK_MAJOR_VERSION)$(TK_MINOR_VERSION)
TK_DOTVERSION	= $(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
!if [nmakehlp -f $(TK_PATCH_LEVEL) "a"]
TK_PATCH_LETTER = a
!elseif [nmakehlp -f $(TK_PATCH_LEVEL) "b"]
TK_PATCH_LETTER = b
!else
TK_PATCH_LETTER = .
!endif

!endif

#----------------------------------------------------------
# Set DOTVERSION and VERSION
!if $(DOING_TCL)

# Decode the options requested.
DOTVERSION = $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
VERSION = $(TCL_VERSION)

#----------------------------------------------------------
!elseif $(DOING_TK)

DOTVERSION = $(TK_DOTVERSION)
VERSION = $(TK_VERSION)

!if "$(OPTS)" == "" || [nmakehlp -f "$(OPTS)" "none"]
!else # Doing a non-Tk extension

# If parent makefile has not defined DOTVERSION, try to get it from TEA
# first from a configure.in file, and then from configure.ac
!ifndef DOTVERSION
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.in ^[$(PROJECT)^] >> versions.vc]
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.ac ^[$(PROJECT)^] >> versions.vc]
!error *** Could not figure out extension version. Please define DOTVERSION in parent makefile before including rules.vc.
!endif
!endif
!include versions.vc
!endif # DOTVERSION
VERSION         = $(DOTVERSION:.=)

!endif # $(DOING_TCL) ... etc.

# Windows RC files have 3 version components. Ensure this irrespective
# of how many components the package has specified. Basically, ensure
# minimum 4 components by appending 4 0's and then pick out the first 4.
# Also take care of the fact that DOTVERSION may have "a" or "b" instead
# of "." separating the version components.
DOTSEPARATED=$(DOTVERSION:a=.)
DOTSEPARATED=$(DOTSEPARATED:b=.)
!if [echo RCCOMMAVERSION = \> versions.vc] \
  || [for /f "tokens=1,2,3,4,5* delims=." %a in ("$(DOTSEPARATED).0.0.0.0") do echo %a,%b,%c,%d >> versions.vc]
!error *** Could not generate RCCOMMAVERSION ***
!endif
!include versions.vc

########################################################################
# 7. Parse the OPTS macro to work out the requested build configuration.
# Based on this, we will construct the actual switches to be passed to the
# compiler and linker using the macros defined in the previous section.
# The following macros are defined by this section based on OPTS
# STATIC_BUILD - 0 -> Tcl is to be built as a shared library
#                1 -> build as a static library and shell
# TCL_THREADS - legacy but always 1 on Windows since winsock requires it.
# DEBUG - 1 -> debug build, 0 -> release builds
# SYMBOLS - 1 -> generate PDB's, 0 -> no PDB's
# PROFILE - 1 -> generate profiling info, 0 -> no profiling
# PGO     - 1 -> profile based optimization, 0 -> no
# MSVCRT  - 1 -> link to dynamic C runtime even when building static Tcl build
#           0 -> link to static C runtime for static Tcl build.
#           Does not impact shared Tcl builds (STATIC_BUILD == 0)
#           Default: 1 for Tcl 8.7 and up, 0 otherwise.
# TCL_USE_STATIC_PACKAGES - 1 -> statically link the registry and dde extensions
#           in the Tcl and Wish shell. 0 -> keep them as shared libraries. Does
#           not impact shared Tcl builds. Implied by STATIC_BUILD since Tcl 8.7.
# USE_THREAD_ALLOC - 1 -> Use a shared global free pool for allocation.
#           0 -> Use the non-thread allocator.
# UNCHECKED - 1 -> when doing a debug build with symbols, use the release
#           C runtime, 0 -> use the debug C runtime.
# USE_STUBS - 1 -> compile to use stubs interfaces, 0 -> direct linking
# CONFIG_CHECK - 1 -> check current build configuration against Tcl
#           configuration (ignored for Tcl itself)
# _USE_64BIT_TIME_T - forces a build using 64-bit time_t for 32-bit build
#           (CRT library should support this, not needed for Tcl 9.x)
# Further, LINKERFLAGS are modified based on above.

# Default values for all the above
STATIC_BUILD	= 0
TCL_THREADS	= 1
DEBUG		= 0
SYMBOLS		= 0
PROFILE		= 0
PGO		= 0
MSVCRT		= 1
LOIMPACT	= 0
TCL_USE_STATIC_PACKAGES	= 0
USE_THREAD_ALLOC = 1
UNCHECKED	= 0
CONFIG_CHECK    = 1
!if $(DOING_TCL)
USE_STUBS       = 0
!else
USE_STUBS       = 1
!endif

# If OPTS is not empty AND does not contain "none" which turns off all OPTS
# set the above macros based on OPTS content
!if "$(OPTS)" != "" && ![nmakehlp -f "$(OPTS)" "none"]

# OPTS are specified, parse them

!if [nmakehlp -f $(OPTS) "static"]
!message *** Doing static
STATIC_BUILD	= 1
!endif

!else
STATIC_BUILD	= 0
!if [nmakehlp -f $(OPTS) "nostubs"]
!message *** Not using stubs
USE_STUBS	= 0
!endif

!if [nmakehlp -f $(OPTS) "nomsvcrt"]
!message *** Doing nomsvcrt
MSVCRT		= 0
!else
!if [nmakehlp -f $(OPTS) "msvcrt"]
!message *** Doing msvcrt
MSVCRT		= 1
!else
!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7 && $(STATIC_BUILD)
!if !$(STATIC_BUILD)
MSVCRT		= 1
!else
MSVCRT		= 0
!endif
!endif
!endif # [nmakehlp -f $(OPTS) "nomsvcrt"]
!endif

!if [nmakehlp -f $(OPTS) "staticpkg"] && $(STATIC_BUILD)
!message *** Doing staticpkg
TCL_USE_STATIC_PACKAGES	= 1
!else
TCL_USE_STATIC_PACKAGES	= 0
!endif

!if [nmakehlp -f $(OPTS) "nothreads"]
!message *** Compile explicitly for non-threaded tcl
TCL_THREADS = 0
TCL_THREADS	= 0
USE_THREAD_ALLOC= 0
!endif

!else
TCL_THREADS	= 1
!if [nmakehlp -f $(OPTS) "tcl8"]
!message *** Build for Tcl8
TCL_BUILD_FOR = 8
!endif

USE_THREAD_ALLOC= 1
!if $(TCL_MAJOR_VERSION) == 8
!if [nmakehlp -f $(OPTS) "time64bit"]
!message *** Force 64-bit time_t
_USE_64BIT_TIME_T = 1
!endif
!endif

# Yes, it's weird that the "symbols" option controls DEBUG and
# the "pdbs" option controls SYMBOLS. That's historical.
!if [nmakehlp -f $(OPTS) "symbols"]
!message *** Doing symbols
DEBUG		= 1
!else
DEBUG		= 0
!endif

!if [nmakehlp -f $(OPTS) "pdbs"]
!message *** Doing pdbs
SYMBOLS		= 1
!else
SYMBOLS		= 0
!endif

!if [nmakehlp -f $(OPTS) "profile"]
!message *** Doing profile
PROFILE		= 1
!else
PROFILE		= 0
!endif

!if [nmakehlp -f $(OPTS) "pgi"]
!message *** Doing profile guided optimization instrumentation
PGO		= 1
!elseif [nmakehlp -f $(OPTS) "pgo"]
!message *** Doing profile guided optimization
PGO		= 2
!else
PGO		= 0
!endif

!if [nmakehlp -f $(OPTS) "loimpact"]
!message *** Warning: ignoring option "loimpact" - deprecated on modern Windows.
!message *** Doing loimpact
LOIMPACT	= 1
!else
LOIMPACT	= 0
!endif

# TBD - should get rid of this option
!if [nmakehlp -f $(OPTS) "thrdalloc"]
!message *** Doing thrdalloc
USE_THREAD_ALLOC = 1
!endif

!if [nmakehlp -f $(OPTS) "tclalloc"]
!message *** Doing tclalloc
USE_THREAD_ALLOC = 0
!endif

!if [nmakehlp -f $(OPTS) "unchecked"]
!message *** Doing unchecked
UNCHECKED = 1
!else
UNCHECKED = 0
!endif

!if [nmakehlp -f $(OPTS) "noconfigcheck"]
CONFIG_CHECK = 1
!else
CONFIG_CHECK = 0
!endif

!endif # "$(OPTS)" != ""  && ... parsing of OPTS

#----------------------------------------------------------
# Set linker flags based on above

!if $(PGO) > 1
!if [nmakehlp -l -ltcg:pgoptimize $(LINKER_TESTFLAGS)]
LINKERFLAGS	= $(LINKERFLAGS:-ltcg=) -ltcg:pgoptimize
!else
MSG=^
This compiler does not support profile guided optimization.
!error $(MSG)
!endif
!elseif $(PGO) > 0
!if [nmakehlp -l -ltcg:pginstrument $(LINKER_TESTFLAGS)]
LINKERFLAGS	= $(LINKERFLAGS:-ltcg=) -ltcg:pginstrument
!else
MSG=^
This compiler does not support profile guided optimization.
!error $(MSG)
!endif
!endif

################################################################
# 8. Parse the STATS macro to configure code instrumentation
# The following macros are set by this section:
# TCL_MEM_DEBUG - 1 -> enables memory allocation instrumentation
#                 0 -> disables
# TCL_COMPILE_DEBUG - 1 -> enables byte compiler logging
#                     0 -> disables

# Default both are off
TCL_MEM_DEBUG	    = 0
TCL_COMPILE_DEBUG   = 0

!if "$(STATS)" != "" && ![nmakehlp -f "$(STATS)" "none"]

!if [nmakehlp -f $(STATS) "memdbg"]
!message *** Doing memdbg
TCL_MEM_DEBUG	    = 1
!else
TCL_MEM_DEBUG	    = 0
!endif

!if [nmakehlp -f $(STATS) "compdbg"]
!message *** Doing compdbg
TCL_COMPILE_DEBUG   = 1
!else
TCL_COMPILE_DEBUG   = 0
!endif

!endif

####################################################################
# 9. Parse the CHECKS macro to configure additional compiler checks
# The following macros are set by this section:
# WARNINGS - compiler switches that control the warnings level
# TCL_NO_DEPRECATED - 1 -> disable support for deprecated functions
#                     0 -> enable deprecated functions

# Defaults - Permit deprecated functions and warning level 3
TCL_NO_DEPRECATED	    = 0
WARNINGS		    = -W3

!if "$(CHECKS)" != "" && ![nmakehlp -f "$(CHECKS)" "none"]

!if [nmakehlp -f $(CHECKS) "nodep"]
!message *** Doing nodep check
TCL_NO_DEPRECATED	    = 1
!endif

!if [nmakehlp -f $(CHECKS) "fullwarn"]
!message *** Doing full warnings check
WARNINGS		    = -W4
!if [nmakehlp -l -warn:3 $(LINKER_TESTFLAGS)]
LINKERFLAGS		    = $(LINKERFLAGS) -warn:3
!endif
!endif

!if [nmakehlp -f $(CHECKS) "64bit"] && [nmakehlp -c -Wp64]
!message *** Doing 64bit portability warnings
WARNINGS		    = $(WARNINGS) -Wp64
!endif

!endif


################################################################
# 10. Construct output directory and file paths
# Figure-out how to name our intermediate and output directories.
# In order to avoid inadvertent mixing of object files built using
# different compilers, build configurations etc.,
#
# Naming convention (suffixes):
#   t = full thread support. (Not used for Tcl >= 8.7)
#   s = static library (as opposed to an import library)
#   g = linked to the debug enabled C run-time.
#   x = special static build when it links to the dynamic C run-time.
# We wouldn't want different builds to use the same .obj files
# by accident.
#----------------------------------------------------------

#----------------------------------------
# Naming convention:
#   t = full thread support.
#   s = static library (as opposed to an
#	import library)
#   g = linked to the debug enabled C
#	run-time.
#   x = special static build when it
#
# The following macros are set in this section:
# SUFX - the suffix to use for binaries based on above naming convention
# BUILDDIRTOP - the toplevel default output directory
#	links to the dynamic C run-time.
#      is of the form {Release,Debug}[_AMD64][_COMPILERVERSION]
# TMP_DIR - directory where object files are created
# OUT_DIR - directory where output executables are created
# Both TMP_DIR and OUT_DIR are defaulted only if not defined by the
# parent makefile (or command line). The default values are
# based on BUILDDIRTOP.
# STUBPREFIX - name of the stubs library for this project
# PRJIMPLIB - output path of the generated project import library
# PRJLIBNAME - name of generated project library
# PRJLIB     - output path of generated project library
# PRJSTUBLIBNAME - name of the generated project stubs library
# PRJSTUBLIB - output path of the generated project stubs library
# RESFILE - output resource file (only if not static build)

#----------------------------------------
SUFX	    = tsgx

!if $(DEBUG)
BUILDDIRTOP = Debug
!else
BUILDDIRTOP = Release
!endif

!if "$(MACHINE)" != "IX86"
BUILDDIRTOP =$(BUILDDIRTOP)_$(MACHINE)
!endif
!if $(VCVER) > 6
BUILDDIRTOP =$(BUILDDIRTOP)_VC$(VCVER)
!endif

!if !$(DEBUG) || $(TCL_VERSION) > 86 || $(DEBUG) && $(UNCHECKED)
!if !$(DEBUG) || $(DEBUG) && $(UNCHECKED)
SUFX	    = $(SUFX:g=)
!endif

TMP_DIRFULL = .\$(BUILDDIRTOP)\$(PROJECT)_ThreadedDynamicStaticX

!if !$(STATIC_BUILD)
TMP_DIRFULL = $(TMP_DIRFULL:Static=)
SUFX	    = $(SUFX:s=)
EXT	    = dll
TMP_DIRFULL = $(TMP_DIRFULL:X=)
SUFX	    = $(SUFX:x=)
!else
TMP_DIRFULL = $(TMP_DIRFULL:Dynamic=)
EXT	    = lib
!if $(MSVCRT) && $(TCL_VERSION) > 86 || !$(MSVCRT) && $(TCL_VERSION) < 87
!if !$(MSVCRT)
TMP_DIRFULL = $(TMP_DIRFULL:X=)
SUFX	    = $(SUFX:x=)
!endif
!endif

!if !$(TCL_THREADS) || $(TCL_VERSION) > 86
!if !$(TCL_THREADS)
TMP_DIRFULL = $(TMP_DIRFULL:Threaded=)
SUFX	    = $(SUFX:t=)
!endif

!ifndef TMP_DIR
TMP_DIR	    = $(TMP_DIRFULL)
!ifndef OUT_DIR
OUT_DIR	    = .\$(BUILDDIRTOP)
!endif
!else
!ifndef OUT_DIR
OUT_DIR	    = $(TMP_DIR)
!endif
!endif

# Relative paths -> absolute
!if [echo OUT_DIR = \> nmakehlp.out] \
   || [nmakehlp -Q "$(OUT_DIR)" >> nmakehlp.out]
!error *** Could not fully qualify path OUT_DIR=$(OUT_DIR)
!endif
!if [echo TMP_DIR = \>> nmakehlp.out] \
   || [nmakehlp -Q "$(TMP_DIR)" >> nmakehlp.out]
!error *** Could not fully qualify path TMP_DIR=$(TMP_DIR)
!endif
!include nmakehlp.out

#----------------------------------------------------------
# The name of the stubs library for the project being built
# Decode the statistics requested.
STUBPREFIX      = $(PROJECT)stub

#
#----------------------------------------------------------

# Set up paths to various Tcl executables and libraries needed by extensions
#

!if "$(STATS)" == "" || [nmakehlp -f "$(STATS)" "none"]
# TIP 430. Unused for 8.6 but no harm defining it to allow a common rules.vc
TCLSCRIPTZIPNAME = libtcl$(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)$(TCL_PATCH_LETTER)$(TCL_RELEASE_SERIAL).zip
TKSCRIPTZIPNAME = libtk$(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)$(TK_PATCH_LETTER)$(TK_RELEASE_SERIAL).zip

TCL_MEM_DEBUG	    = 0
!if $(DOING_TCL)
TCLSHNAME       = $(PROJECT)sh$(VERSION)$(SUFX).exe
TCLSH		= $(OUT_DIR)\$(TCLSHNAME)
TCLIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
TCLLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
TCLLIB		= $(OUT_DIR)\$(TCLLIBNAME)
TCLSCRIPTZIP    = $(OUT_DIR)\$(TCLSCRIPTZIPNAME)

TCL_COMPILE_DEBUG   = 0
!if $(TCL_MAJOR_VERSION) == 8
TCLSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
!else
TCLSTUBLIBNAME	= $(STUBPREFIX).lib
!endif
TCLSTUBLIB	= $(OUT_DIR)\$(TCLSTUBLIBNAME)
TCL_INCLUDES    = -I"$(WIN_DIR)" -I"$(GENERICDIR)"

!if [nmakehlp -f $(STATS) "memdbg"]
!else # !$(DOING_TCL)

!message *** Doing memdbg
!if $(TCLINSTALL) # Building against an installed Tcl

TCL_MEM_DEBUG	    = 1
# When building extensions, we need to locate tclsh. Depending on version
# of Tcl we are building against, this may or may not have a "t" suffix.
# Try various possibilities in turn.
TCLSH		= $(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX:t=).exe
!if !exist("$(TCLSH)")
TCLSH           = $(_TCLDIR)\bin\tclsh$(TCL_VERSION)t$(SUFX:t=).exe
!else
TCL_MEM_DEBUG	    = 0
!endif

!if $(TCL_MAJOR_VERSION) == 8
!if [nmakehlp -f $(STATS) "compdbg"]
!message *** Doing compdbg
TCL_COMPILE_DEBUG   = 1
TCLSTUBLIB	= $(_TCLDIR)\lib\tclstub$(TCL_VERSION).lib
!else
TCLSTUBLIB	= $(_TCLDIR)\lib\tclstub.lib
TCL_COMPILE_DEBUG   = 0
!endif
TCLIMPLIB	= $(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX:t=).lib
# When building extensions, may be linking against Tcl that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TCLIMPLIB)")
TCLIMPLIB	= $(_TCLDIR)\lib\tcl$(TCL_VERSION)t$(SUFX:t=).lib
!endif
TCL_LIBRARY	= $(_TCLDIR)\lib
TCLREGLIB	= $(_TCLDIR)\lib\tclreg13$(SUFX:t=).lib
TCLDDELIB	= $(_TCLDIR)\lib\tcldde14$(SUFX:t=).lib
TCLSCRIPTZIP	= $(_TCLDIR)\lib\$(TCLSCRIPTZIPNAME)
TCLTOOLSDIR	= \must\have\tcl\sources\to\build\this\target
TCL_INCLUDES    = -I"$(_TCLDIR)\include"

!else # Building against Tcl sources

TCLSH		= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX:t=).exe
!if !exist($(TCLSH))
TCLSH		= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)t$(SUFX:t=).exe
!endif
!if $(TCL_MAJOR_VERSION) == 8
TCLSTUBLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub$(TCL_VERSION).lib
!else
TCLSTUBLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub.lib
!endif
TCLIMPLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX:t=).lib
# When building extensions, may be linking against Tcl that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TCLIMPLIB)")
TCLIMPLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)t$(SUFX:t=).lib
!endif
TCL_LIBRARY	= $(_TCLDIR)\library
TCLREGLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclreg13$(SUFX:t=).lib
TCLDDELIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcldde14$(SUFX:t=).lib
TCLSCRIPTZIP	= $(_TCLDIR)\win\$(BUILDDIRTOP)\$(TCLSCRIPTZIPNAME)
TCLTOOLSDIR	= $(_TCLDIR)\tools
TCL_INCLUDES	= -I"$(_TCLDIR)\generic" -I"$(_TCLDIR)\win"

#----------------------------------------------------------
!endif # TCLINSTALL

# Decode the checks requested.
!if !$(STATIC_BUILD) && "$(TCL_BUILD_FOR)" == "8"
tcllibs = "$(TCLSTUBLIB)"
!else
#----------------------------------------------------------
tcllibs = "$(TCLSTUBLIB)" "$(TCLIMPLIB)"
!endif

!endif # $(DOING_TCL)

!if "$(CHECKS)" == "" || [nmakehlp -f "$(CHECKS)" "none"]
# We need a tclsh that will run on the host machine as part of the build.
# IX86 runs on all architectures.
!ifndef TCLSH_NATIVE
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
TCLSH_NATIVE	= $(TCLSH)
TK_NO_DEPRECATED	    = 0
WARNINGS		    = -W3
!else
!error You must explicitly set TCLSH_NATIVE for cross-compilation
!endif
!if [nmakehlp -f $(CHECKS) "nodep"]
!message *** Doing nodep check
TK_NO_DEPRECATED	    = 1
!else
TK_NO_DEPRECATED	    = 0
!endif

!if [nmakehlp -f $(CHECKS) "fullwarn"]
# Do the same for Tk and Tk extensions that require the Tk libraries
!if $(DOING_TK) || $(NEED_TK)
WISHNAMEPREFIX = wish
WISHNAME = $(WISHNAMEPREFIX)$(TK_VERSION)$(SUFX).exe
!message *** Doing full warnings check
WARNINGS		    = -W4
!if [nmakehlp -l -warn:3]
LINKERFLAGS		    = $(LINKERFLAGS) -warn:3
TKLIBNAME8	= tk$(TK_VERSION)$(SUFX).$(EXT)
TKLIBNAME9	= tcl9tk$(TK_VERSION)$(SUFX).$(EXT)
!if $(TCL_MAJOR_VERSION) == 8 || "$(TCL_BUILD_FOR)" == "8"
TKLIBNAME	= tk$(TK_VERSION)$(SUFX).$(EXT)
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX).lib
!else
TKLIBNAME	= tcl9tk$(TK_VERSION)$(SUFX).$(EXT)
TKIMPLIBNAME	= tcl9tk$(TK_VERSION)$(SUFX).lib
!endif
!if $(TK_MAJOR_VERSION) == 8
TKSTUBLIBNAME	= tkstub$(TK_VERSION).lib
!else
TKSTUBLIBNAME	= tkstub.lib
WARNINGS		    = -W3
!endif

!if [nmakehlp -f $(CHECKS) "64bit"] && [nmakehlp -c -Wp64]
!if $(DOING_TK)
WISH 		= $(OUT_DIR)\$(WISHNAME)
TKSTUBLIB	= $(OUT_DIR)\$(TKSTUBLIBNAME)
TKIMPLIB	= $(OUT_DIR)\$(TKIMPLIBNAME)
TKLIB		= $(OUT_DIR)\$(TKLIBNAME)
TK_INCLUDES     = -I"$(WIN_DIR)" -I"$(GENERICDIR)"
TKSCRIPTZIP     = $(OUT_DIR)\$(TKSCRIPTZIPNAME)

!message *** Doing 64bit portability warnings
WARNINGS		    = $(WARNINGS) -Wp64
!endif
!else # effectively NEED_TK

!endif
!if $(TKINSTALL) # Building against installed Tk
WISH		= $(_TKDIR)\bin\$(WISHNAME)
TKSTUBLIB	= $(_TKDIR)\lib\$(TKSTUBLIBNAME)
TKIMPLIB	= $(_TKDIR)\lib\$(TKIMPLIBNAME)
# When building extensions, may be linking against Tk that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TKIMPLIB)")
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX:t=).lib
TKIMPLIB	= $(_TKDIR)\lib\$(TKIMPLIBNAME)
!endif
TK_INCLUDES     = -I"$(_TKDIR)\include"
TKSCRIPTZIP     = $(_TKDIR)\lib\$(TKSCRIPTZIPNAME)

!else # Building against Tk sources

!if $(PGO) > 1
WISH		= $(_TKDIR)\win\$(BUILDDIRTOP)\$(WISHNAME)
TKSTUBLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKSTUBLIBNAME)
TKIMPLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKIMPLIBNAME)
# When building extensions, may be linking against Tk that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TKIMPLIB)")
!if [nmakehlp -l -ltcg:pgoptimize]
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX:t=).lib
TKIMPLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKIMPLIBNAME)
!endif
LINKERFLAGS	= $(LINKERFLAGS:-ltcg=) -ltcg:pgoptimize
!else
TK_INCLUDES     = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
TKSCRIPTZIP     = $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKSCRIPTZIPNAME)

MSG=^
!endif # TKINSTALL

This compiler does not support profile guided optimization.
tklibs = "$(TKSTUBLIB)" "$(TKIMPLIB)"

!endif # $(DOING_TK)
!endif # $(DOING_TK) || $(NEED_TK)

!error $(MSG)
!endif
!elseif $(PGO) > 0
!if [nmakehlp -l -ltcg:pginstrument]
# Various output paths
PRJIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
PRJLIBNAME8	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
PRJLIBNAME9	= tcl9$(PROJECT)$(VERSION)$(SUFX).$(EXT)
!if $(TCL_MAJOR_VERSION) == 8 || "$(TCL_BUILD_FOR)" == "8"
PRJLIBNAME	= $(PRJLIBNAME8)
LINKERFLAGS	= $(LINKERFLAGS:-ltcg=) -ltcg:pginstrument
!else
MSG=^
This compiler does not support profile guided optimization.
PRJLIBNAME	= $(PRJLIBNAME9)
!error $(MSG)
!endif
PRJLIB		= $(OUT_DIR)\$(PRJLIBNAME)

!if $(TCL_MAJOR_VERSION) == 8
PRJSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
!else
PRJSTUBLIBNAME	= $(STUBPREFIX).lib
!endif
PRJSTUBLIB	= $(OUT_DIR)\$(PRJSTUBLIBNAME)

#----------------------------------------------------------
# Set our defines now armed with our options.
#----------------------------------------------------------

# If extension parent makefile has not defined a resource definition file,
# we will generate one from standard template.
OPTDEFINES	= -DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) -DSTDC_HEADERS -DTCL_NO_DEPRECATED

!if !$(DOING_TCL) && !$(DOING_TK) && !$(STATIC_BUILD)
!ifdef RCFILE
RESFILE = $(TMP_DIR)\$(RCFILE:.rc=.res)
!if $(TCL_MEM_DEBUG)
OPTDEFINES	= $(OPTDEFINES) -DTCL_MEM_DEBUG
!else
RESFILE = $(TMP_DIR)\$(PROJECT).res
!endif
!if $(TCL_COMPILE_DEBUG)
OPTDEFINES	= $(OPTDEFINES) -DTCL_COMPILE_DEBUG -DTCL_COMPILE_STATS
!endif

!if $(TCL_THREADS)
###################################################################
# 11. Construct the paths for the installation directories
# The following macros get defined in this section:
# LIB_INSTALL_DIR - where libraries should be installed
# BIN_INSTALL_DIR - where the executables should be installed
# DOC_INSTALL_DIR - where documentation should be installed
# SCRIPT_INSTALL_DIR - where scripts should be installed
# INCLUDE_INSTALL_DIR - where C include files should be installed
# DEMO_INSTALL_DIR - where demos should be installed
# PRJ_INSTALL_DIR - where package will be installed (not set for Tcl and Tk)

!if $(DOING_TCL) || $(DOING_TK)
LIB_INSTALL_DIR		= $(_INSTALLDIR)\lib
OPTDEFINES	= $(OPTDEFINES) -DTCL_THREADS=1
!if $(USE_THREAD_ALLOC)
OPTDEFINES	= $(OPTDEFINES) -DUSE_THREAD_ALLOC=1
BIN_INSTALL_DIR		= $(_INSTALLDIR)\bin
DOC_INSTALL_DIR		= $(_INSTALLDIR)\doc
!if $(DOING_TCL)
SCRIPT_INSTALL_DIR	= $(_INSTALLDIR)\lib\$(PROJECT)$(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
MODULE_INSTALL_DIR	= $(_INSTALLDIR)\lib\tcl$(TCL_MAJOR_VERSION)
!else # DOING_TK
!endif
SCRIPT_INSTALL_DIR	= $(_INSTALLDIR)\lib\$(PROJECT)$(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
!endif
DEMO_INSTALL_DIR	= $(SCRIPT_INSTALL_DIR)\demos
INCLUDE_INSTALL_DIR	= $(_INSTALLDIR)\include

!if $(STATIC_BUILD)
!else # extension other than Tk

OPTDEFINES	= $(OPTDEFINES) -DSTATIC_BUILD
PRJ_INSTALL_DIR         = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION)
!if $(MULTIPLATFORM_INSTALL)
LIB_INSTALL_DIR		= $(PRJ_INSTALL_DIR)\$(PLATFORM_IDENTIFY)
BIN_INSTALL_DIR		= $(PRJ_INSTALL_DIR)\$(PLATFORM_IDENTIFY)
!else
LIB_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
BIN_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
!endif
DOC_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
!if $(TK_NO_DEPRECATED)
SCRIPT_INSTALL_DIR	= $(PRJ_INSTALL_DIR)
DEMO_INSTALL_DIR	= $(PRJ_INSTALL_DIR)\demos
INCLUDE_INSTALL_DIR	= $(_INSTALLDIR)\..\include

OPTDEFINES	= $(OPTDEFINES) -DTK_NO_DEPRECATED
!endif

###################################################################
# 12. Set up actual options to be passed to the compiler and linker
# Now we have all the information we need, set up the actual flags and
# options that we will pass to the compiler and linker. The main
# makefile should use these in combination with whatever other flags
# and switches are specific to it.
# The following macros are defined, names are for historical compatibility:
# OPTDEFINES - /Dxxx C macro flags based on user-specified OPTS
# COMPILERFLAGS - /Dxxx C macro flags independent of any configuration options
# crt - Compiler switch that selects the appropriate C runtime
# cdebug - Compiler switches related to debug AND optimizations
# cwarn - Compiler switches that set warning levels
# cflags - complete compiler switches (subsumes cdebug and cwarn)
# ldebug - Linker switches controlling debug information and optimization
# lflags - complete linker switches (subsumes ldebug) except subsystem type
# dlllflags - complete linker switches to build DLLs (subsumes lflags)
# conlflags - complete linker switches for console program (subsumes lflags)
# guilflags - complete linker switches for GUI program (subsumes lflags)
# baselibs - minimum Windows libraries required. Parent makefile can
#    define PRJ_LIBS before including rules.rc if additional libs are needed

!if !$(DEBUG)
OPTDEFINES	= /DSTDC_HEADERS /DUSE_NMAKE=1
!if $(VCVERSION) > 1600
OPTDEFINES	= $(OPTDEFINES) /DHAVE_STDINT_H=1
OPTDEFINES	= $(OPTDEFINES) -DNDEBUG
!else
OPTDEFINES	= $(OPTDEFINES) /DMP_NO_STDINT=1
!if $(OPTIMIZING)
OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_OPTIMIZED
!endif
!if $(VCVERSION) >= 1800
OPTDEFINES	= $(OPTDEFINES) /DHAVE_INTTYPES_H=1 /DHAVE_STDBOOL_H=1
!endif

!if $(TCL_MEM_DEBUG)
OPTDEFINES	= $(OPTDEFINES) /DTCL_MEM_DEBUG
!if $(PROFILE)
OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_PROFILED
!endif
!if $(TCL_COMPILE_DEBUG)
OPTDEFINES	= $(OPTDEFINES) /DTCL_COMPILE_DEBUG /DTCL_COMPILE_STATS
!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
OPTDEFINES	= $(OPTDEFINES) -DTCL_CFG_DO64BIT
!endif
!if $(TCL_THREADS) && $(TCL_VERSION) < 87
OPTDEFINES	= $(OPTDEFINES) /DTCL_THREADS=1
!if $(VCVERSION) < 1300
OPTDEFINES	= $(OPTDEFINES) -DNO_STRTOI64
!if $(USE_THREAD_ALLOC) && $(TCL_VERSION) < 87
OPTDEFINES	= $(OPTDEFINES) /DUSE_THREAD_ALLOC=1
!endif
!endif
!if $(STATIC_BUILD)

#----------------------------------------------------------
# Locate the Tcl headers to build against
#----------------------------------------------------------

OPTDEFINES	= $(OPTDEFINES) /DSTATIC_BUILD
!elseif $(TCL_VERSION) > 86
!if "$(PROJECT)" == "tcl"
OPTDEFINES	= $(OPTDEFINES) /DTCL_WITH_EXTERNAL_TOMMATH
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
OPTDEFINES	= $(OPTDEFINES) /DMP_64BIT
!endif
!endif
!if $(TCL_NO_DEPRECATED)
OPTDEFINES	= $(OPTDEFINES) /DTCL_NO_DEPRECATED
!endif

!if $(USE_STUBS)
# Note we do not define USE_TCL_STUBS even when building tk since some
# test targets in tk do not use stubs
!if !$(DOING_TCL)
_TCL_H          = ..\generic\tcl.h
USE_STUBS_DEFS  = /DUSE_TCL_STUBS /DUSE_TCLOO_STUBS
!if $(NEED_TK)
USE_STUBS_DEFS  = $(USE_STUBS_DEFS) /DUSE_TK_STUBS
!endif
!endif
!endif # USE_STUBS

!if !$(DEBUG)
OPTDEFINES	= $(OPTDEFINES) /DNDEBUG
!if $(OPTIMIZING)
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_OPTIMIZED
!endif
!else
!endif
!if $(PROFILE)
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_PROFILED
!endif
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_DO64BIT
!endif
!if $(VCVERSION) < 1300
OPTDEFINES	= $(OPTDEFINES) /DNO_STRTOI64=1
!endif

# If INSTALLDIR set to tcl root dir then reset to the lib dir.
!if $(TCL_MAJOR_VERSION) == 8
!if exist("$(_INSTALLDIR)\include\tcl.h")
!if "$(_USE_64BIT_TIME_T)" == "1"
OPTDEFINES	= $(OPTDEFINES) /D_USE_64BIT_TIME_T=1
!endif

_INSTALLDIR=$(_INSTALLDIR)\lib
# _ATL_XP_TARGETING - Newer SDK's need this to build for XP
COMPILERFLAGS  = /D_ATL_XP_TARGETING
!endif
!if "$(TCL_BUILD_FOR)" == "8"
OPTDEFINES	= $(OPTDEFINES) /DTCL_MAJOR_VERSION=8
!endif

# Like the TEA system only set this non empty for non-Tk extensions
# Note: some extensions use PACKAGE_NAME and others use PACKAGE_TCLNAME
# so we pass both
!if !$(DOING_TCL) && !$(DOING_TK)
PKGNAMEFLAGS = /DPACKAGE_NAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \
               /DPACKAGE_TCLNAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \
               /DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
               /DMODULE_SCOPE=extern
!endif

# crt picks the C run time based on selected OPTS
!if $(MSVCRT)
!if $(DEBUG) && !$(UNCHECKED)
!if !defined(TCLDIR)
!if exist("$(_INSTALLDIR)\..\include\tcl.h")
crt = -MDd
!else
crt = -MD
TCLINSTALL	= 1
!endif
!else
!if $(DEBUG) && !$(UNCHECKED)
crt = -MTd
_TCLDIR		= $(_INSTALLDIR)\..
_TCL_H          = $(_INSTALLDIR)\..\include\tcl.h
TCLDIR          = $(_INSTALLDIR)\..
!else
crt = -MT
MSG=^
!endif
!endif

Failed to find tcl.h.  Set the TCLDIR macro.
# cdebug includes compiler options for debugging as well as optimization.
!if $(DEBUG)

# In debugging mode, optimizations need to be disabled
cdebug = -Zi -Od $(DEBUGFLAGS)

!error $(MSG)
!endif
!else
_TCLDIR	= $(TCLDIR:/=\)
!if exist("$(_TCLDIR)\include\tcl.h")
TCLINSTALL	= 1
_TCL_H          = $(_TCLDIR)\include\tcl.h
!elseif exist("$(_TCLDIR)\generic\tcl.h")
TCLINSTALL	= 0
_TCL_H          = $(_TCLDIR)\generic\tcl.h
!else

MSG =^
cdebug = $(OPTIMIZATIONS)
!if $(SYMBOLS)
Failed to find tcl.h.  The TCLDIR macro does not appear correct.
!error $(MSG)
cdebug = $(cdebug) -Zi
!endif

!endif # $(DEBUG)
!endif
!endif

# cwarn includes default warning levels, also C4090 (buggy) and C4146 is useless.
cwarn = $(WARNINGS) -wd4090 -wd4146

#--------------------------------------------------------------
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
# Disable pointer<->int warnings related to cast between different sizes
# There are a gadzillion of these due to use of ClientData and
# clutter up compiler
# output increasing chance of a real warning getting lost. So disable them.
# Extract various version numbers from tcl headers
# The generated file is then included in the makefile.
#--------------------------------------------------------------
# Eventually some day, Tcl will be 64-bit clean.
cwarn = $(cwarn) -wd4311 -wd4312
!endif

### Common compiler options that are architecture specific
!if [echo REM = This file is generated from rules.vc > versions.vc]
!if "$(MACHINE)" == "ARM"
carch = /D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
!else
carch =
!endif

!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \
# cpuid is only available on intel machines
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "AMD64"
carch = $(carch) /DHAVE_CPUID=1
!endif

   && [nmakehlp -V "$(_TCL_H)" TCL_MAJOR_VERSION >> versions.vc]
!if $(DEBUG)
# Turn warnings into errors
cwarn = $(cwarn) -WX
!endif

!if [echo TCL_MINOR_VERSION = \>> versions.vc] \
INCLUDES = $(TCL_INCLUDES) $(TK_INCLUDES) $(PRJ_INCLUDES)
!if !$(DOING_TCL) && !$(DOING_TK)
INCLUDES = $(INCLUDES) -I"$(GENERICDIR)" -I"$(WIN_DIR)" -I"$(COMPATDIR)"
   && [nmakehlp -V "$(_TCL_H)" TCL_MINOR_VERSION >> versions.vc]
!endif

!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \
# These flags are defined roughly in the order of the pre-reform
# rules.vc/makefile.vc to help visually compare that the pre- and
# post-reform build logs

   && [nmakehlp -V "$(_TCL_H)" TCL_PATCH_LEVEL >> versions.vc]
# cflags contains generic flags used for building practically all object files
cflags = -nologo -c $(COMPILERFLAGS) $(carch) $(cwarn) -Fp$(TMP_DIR)^\ $(cdebug)

!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7
cflags = $(cflags) -DTcl_Size=int
!endif

# appcflags contains $(cflags) and flags for building the application
# object files (e.g. tclsh, or wish) pkgcflags contains $(cflags) plus
# flags used for building shared object files The two differ in the
# BUILD_$(PROJECT) macro which should be defined only for the shared
# library *implementation* and not for its caller interface

appcflags_nostubs = $(cflags) $(crt) $(INCLUDES) $(TCL_DEFINES) $(PRJ_DEFINES) $(OPTDEFINES)
appcflags = $(appcflags_nostubs) $(USE_STUBS_DEFS)
pkgcflags = $(appcflags) $(PKGNAMEFLAGS) /DBUILD_$(PROJECT)
pkgcflags_nostubs = $(appcflags_nostubs) $(PKGNAMEFLAGS) /DBUILD_$(PROJECT)

# stubscflags contains $(cflags) plus flags used for building a stubs
# library for the package.  Note: /DSTATIC_BUILD is defined in
# $(OPTDEFINES) only if the OPTS configuration indicates a static
# library. However the stubs library is ALWAYS static hence included
# here irrespective of the OPTS setting.
#

# TBD - tclvfs has a comment that stubs libs should not be compiled with -GL
# without stating why. Tcl itself compiled stubs libs with this flag.
# so we do not remove it from cflags. -GL may prevent extensions
# compiled with one VC version to fail to link against stubs library
# compiled with another VC version. Check for this and fix accordingly.
stubscflags = $(cflags) $(PKGNAMEFLAGS) $(PRJ_DEFINES) $(OPTDEFINES) /Zl /GL- /DSTATIC_BUILD $(INCLUDES) $(USE_STUBS_DEFS)

# If building the tcl core then we need additional package versions
# Link flags

!if $(DEBUG)
!if "$(PROJECT)" == "tcl"
!if [echo PKG_HTTP_VER = \>> versions.vc] \
ldebug	= -debug -debugtype:cv
!else
   && [nmakehlp -V ..\library\http\pkgIndex.tcl http >> versions.vc]
!endif
ldebug	= -release -opt:ref -opt:icf,3
!if $(SYMBOLS)
!if [echo PKG_TCLTEST_VER = \>> versions.vc] \
ldebug	= $(ldebug) -debug -debugtype:cv
   && [nmakehlp -V ..\library\tcltest\pkgIndex.tcl tcltest >> versions.vc]
!endif
!if [echo PKG_MSGCAT_VER = \>> versions.vc] \
   && [nmakehlp -V ..\library\msgcat\pkgIndex.tcl msgcat >> versions.vc]
!endif

!if [echo PKG_PLATFORM_VER = \>> versions.vc] \
# Note: Profiling is currently only possible with the Visual Studio Enterprise
!if $(PROFILE)
ldebug= $(ldebug) -profile
   && [nmakehlp -V ..\library\platform\pkgIndex.tcl "platform " >> versions.vc]
!endif

### Declarations common to all linker versions
lflags	= -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug)

!if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900
!if [echo PKG_SHELL_VER = \>> versions.vc] \
   && [nmakehlp -V ..\library\platform\pkgIndex.tcl "platform::shell" >> versions.vc]
!endif
!if [echo PKG_DDE_VER = \>> versions.vc] \
   && [nmakehlp -V ..\library\dde\pkgIndex.tcl "dde " >> versions.vc]
lflags	= $(lflags) -nodefaultlib:libucrt.lib
!endif

!if [echo PKG_REG_VER =\>> versions.vc] \
dlllflags = $(lflags) -dll
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows

   && [nmakehlp -V ..\library\reg\pkgIndex.tcl registry >> versions.vc]
# Libraries that are required for every image.
# Extensions should define any additional libraries with $(PRJ_LIBS)
winlibs   = kernel32.lib advapi32.lib

!endif
!if $(NEED_TK)
winlibs = $(winlibs) gdi32.lib user32.lib uxtheme.lib
!endif

# Avoid 'unresolved external symbol __security_cookie' errors.
# c.f. http://support.microsoft.com/?id=894573
!if "$(MACHINE)" == "AMD64"
!if $(VCVERSION) > 1399 && $(VCVERSION) < 1500
!include versions.vc
winlibs   = $(winlibs) bufferoverflowU.lib
!endif
!endif

baselibs = $(winlibs) $(PRJ_LIBS)

#--------------------------------------------------------------
!if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900
baselibs   = $(baselibs) ucrt.lib
!endif

# Setup tcl version dependent stuff headers
################################################################
# 13. Define standard commands, common make targets and implicit rules

#--------------------------------------------------------------
CCPKGCMD = $(cc32) $(pkgcflags) -Fo$(TMP_DIR)^\
CCAPPCMD = $(cc32) $(appcflags) -Fo$(TMP_DIR)^\
CCSTUBSCMD = $(cc32) $(stubscflags) -Fo$(TMP_DIR)^\

LIBCMD = $(lib32) -nologo $(LINKERFLAGS) -out:$@
DLLCMD = $(link32) $(dlllflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)

CONEXECMD = $(link32) $(conlflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)
GUIEXECMD = $(link32) $(guilflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)
RESCMD  = $(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" \
	    $(TCL_INCLUDES) /DSTATIC_BUILD=$(STATIC_BUILD) \
	    /DDEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \
	    /DCOMMAVERSION=$(RCCOMMAVERSION) \
	    /DDOTVERSION=\"$(DOTVERSION)\" \
	    /DVERSION=\"$(VERSION)\" \
	    /DSUFX=\"$(SUFX)\" \
	    /DPROJECT=\"$(PROJECT)\" \
!if "$(PROJECT)" != "tcl"
	    /DPRJLIBNAME=\"$(PRJLIBNAME)\"

!ifndef DEFAULT_BUILD_TARGET
DEFAULT_BUILD_TARGET = $(PROJECT)
!endif

TCL_VERSION	= $(TCL_MAJOR_VERSION)$(TCL_MINOR_VERSION)
default-target: $(DEFAULT_BUILD_TARGET)

!if $(MULTIPLATFORM_INSTALL)
default-pkgindex:
	@echo if {[package vsatisfies [package provide Tcl] 9.0-]} { > $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PLATFORM_IDENTIFY) $(PRJLIBNAME9)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } else { >> $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PLATFORM_IDENTIFY) $(PRJLIBNAME8)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } >> $(OUT_DIR)\pkgIndex.tcl
!else
default-pkgindex:
	@echo if {[package vsatisfies [package provide Tcl] 9.0-]} { > $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PRJLIBNAME9)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } else { >> $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \

!if $(TCLINSTALL)
TCLSH		= "$(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX).exe"
!if !exist($(TCLSH))
TCLSH           = "$(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX:x=).exe"
	    [list load [file join $$dir $(PRJLIBNAME8)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } >> $(OUT_DIR)\pkgIndex.tcl
!endif

TCLSTUBLIB	= "$(_TCLDIR)\lib\tclstub$(TCL_VERSION).lib"
default-pkgindex-tea:
	@if exist $(ROOT)\pkgIndex.tcl.in nmakehlp -s << $(ROOT)\pkgIndex.tcl.in > $(OUT_DIR)\pkgIndex.tcl
@PACKAGE_VERSION@    $(DOTVERSION)
TCLIMPLIB	= "$(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX).lib"
@PACKAGE_NAME@       $(PRJ_PACKAGE_TCLNAME)
@PACKAGE_TCLNAME@    $(PRJ_PACKAGE_TCLNAME)
@PKG_LIB_FILE@       $(PRJLIBNAME)
!if !exist($(TCLIMPLIB))
@PKG_LIB_FILE8@      $(PRJLIBNAME8)
@PKG_LIB_FILE9@      $(PRJLIBNAME9)
<<

TCLIMPLIB	= "$(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX:x=).lib"
default-install: default-install-binaries default-install-libraries
!if $(SYMBOLS)
default-install: default-install-pdbs
!endif

# Again to deal with historical brokenness, there is some confusion
# in terminlogy. For extensions, the "install-binaries" was used to
# locate target directory for *binary shared libraries* and thus
# the appropriate macro is LIB_INSTALL_DIR since BIN_INSTALL_DIR is
# for executables (exes). On the other hand the "install-libraries"
TCL_LIBRARY	= $(_TCLDIR)\lib
TCLREGLIB	= "$(_TCLDIR)\lib\tclreg13$(SUFX:t=).lib"
TCLDDELIB	= "$(_TCLDIR)\lib\tcldde14$(SUFX:t=).lib"
COFFBASE	= \must\have\tcl\sources\to\build\this\target
TCLTOOLSDIR	= \must\have\tcl\sources\to\build\this\target
TCL_INCLUDES    = -I"$(_TCLDIR)\include"
!else
TCLSH		= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX).exe"
!if !exist($(TCLSH))
TCLSH		= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX:x=).exe"
!endif
TCLSTUBLIB	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub$(TCL_VERSION).lib"
TCLIMPLIB	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX).lib"
# target is for *scripts* and should have been called "install-scripts".
default-install-binaries: $(PRJLIB)
	@echo Installing binaries to '$(LIB_INSTALL_DIR)'
!if !exist($(TCLIMPLIB))
TCLIMPLIB	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX:x=).lib"
!endif
	@if not exist "$(LIB_INSTALL_DIR)" mkdir "$(LIB_INSTALL_DIR)"
	@$(CPY) $(PRJLIB) "$(LIB_INSTALL_DIR)" >NUL

TCL_LIBRARY	= $(_TCLDIR)\library
TCLREGLIB	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclreg13$(SUFX:t=).lib"
# Alias for default-install-scripts
default-install-libraries: default-install-scripts

default-install-scripts: $(OUT_DIR)\pkgIndex.tcl
TCLDDELIB	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcldde14$(SUFX:t=).lib"
COFFBASE	= "$(_TCLDIR)\win\coffbase.txt"
	@echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
	@if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
	@echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
	@$(CPY) $(OUT_DIR)\pkgIndex.tcl $(SCRIPT_INSTALL_DIR)

TCLTOOLSDIR	= $(_TCLDIR)\tools
TCL_INCLUDES	= -I"$(_TCLDIR)\generic" -I"$(_TCLDIR)\win"
default-install-stubs:
	@echo Installing stubs library to '$(SCRIPT_INSTALL_DIR)'
	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
	@$(CPY) $(PRJSTUBLIB) "$(SCRIPT_INSTALL_DIR)" >NUL
!endif

!endif
default-install-pdbs:
	@echo Installing PDBs to '$(LIB_INSTALL_DIR)'
	@if not exist "$(LIB_INSTALL_DIR)" mkdir "$(LIB_INSTALL_DIR)"
	@$(CPY) "$(OUT_DIR)\*.pdb" "$(LIB_INSTALL_DIR)\"

# "emacs font-lock highlighting fix

#-------------------------------------------------------------------------
default-install-docs-html:
	@echo Installing documentation files to '$(DOC_INSTALL_DIR)'
# Locate the Tk headers to build against
	@if not exist "$(DOC_INSTALL_DIR)" mkdir "$(DOC_INSTALL_DIR)"
	@if exist $(DOCDIR) for %f in ("$(DOCDIR)\*.html" "$(DOCDIR)\*.css" "$(DOCDIR)\*.png") do @$(COPY) %f "$(DOC_INSTALL_DIR)"
#-------------------------------------------------------------------------

default-install-docs-n:
	@echo Installing documentation files to '$(DOC_INSTALL_DIR)'
	@if not exist "$(DOC_INSTALL_DIR)" mkdir "$(DOC_INSTALL_DIR)"
!if "$(PROJECT)" == "tk"
	@if exist $(DOCDIR) for %f in ("$(DOCDIR)\*.n") do @$(COPY) %f "$(DOC_INSTALL_DIR)"

_TK_H          = ..\generic\tk.h
default-install-demos:
	@echo Installing demos to '$(DEMO_INSTALL_DIR)'
_INSTALLDIR    = $(_INSTALLDIR)\..
	@if not exist "$(DEMO_INSTALL_DIR)" mkdir "$(DEMO_INSTALL_DIR)"
	@if exist $(DEMODIR) $(CPYDIR) "$(DEMODIR)" "$(DEMO_INSTALL_DIR)"
!endif

default-clean:
	@echo Cleaning $(TMP_DIR)\* ...
	@if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
!ifdef PROJECT_REQUIRES_TK
!if !defined(TKDIR)
!if exist("$(_INSTALLDIR)\..\include\tk.h")
	@echo Cleaning $(WIN_DIR)\nmakehlp.obj, nmakehlp.exe ...
	@if exist $(WIN_DIR)\nmakehlp.obj del $(WIN_DIR)\nmakehlp.obj
	@if exist $(WIN_DIR)\nmakehlp.exe del $(WIN_DIR)\nmakehlp.exe
	@if exist $(WIN_DIR)\nmakehlp.out del $(WIN_DIR)\nmakehlp.out
	@echo Cleaning $(WIN_DIR)\nmhlp-out.txt ...
TKINSTALL      = 1
_TKDIR         = $(_INSTALLDIR)\..
	@if exist $(WIN_DIR)\nmhlp-out.txt del $(WIN_DIR)\nmhlp-out.txt
	@echo Cleaning $(WIN_DIR)\_junk.pch ...
_TK_H          = $(_TKDIR)\include\tk.h
	@if exist $(WIN_DIR)\_junk.pch del $(WIN_DIR)\_junk.pch
	@echo Cleaning $(WIN_DIR)\vercl.x, vercl.i ...
	@if exist $(WIN_DIR)\vercl.x del $(WIN_DIR)\vercl.x
	@if exist $(WIN_DIR)\vercl.i del $(WIN_DIR)\vercl.i
	@echo Cleaning $(WIN_DIR)\versions.vc, version.vc ...
	@if exist $(WIN_DIR)\versions.vc del $(WIN_DIR)\versions.vc
	@if exist $(WIN_DIR)\version.vc del $(WIN_DIR)\version.vc

TKDIR          = $(_TKDIR)
default-hose: default-clean
	@echo Hosing $(OUT_DIR)\* ...
	@if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)

!elseif exist("$(_TCLDIR)\include\tk.h")
TKINSTALL      = 1
# Only for backward compatibility
default-distclean: default-hose

_TKDIR         = $(_TCLDIR)
default-setup:
	@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
	@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)

_TK_H          = $(_TKDIR)\include\tk.h
!if "$(TESTPAT)" != ""
TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT)
TKDIR          = $(_TKDIR)
!endif

!else
default-test: default-setup $(PROJECT)
	@set TCLLIBPATH=$(OUT_DIR:\=/)
	@if exist $(LIBDIR) for %f in ("$(LIBDIR)\*.tcl") do @$(COPY) %f "$(OUT_DIR)"
_TKDIR = $(TKDIR:/=\)
!if exist("$(_TKDIR)\include\tk.h")
	cd "$(TESTDIR)" && $(DEBUGGER) $(TCLSH) all.tcl $(TESTFLAGS)

TKINSTALL      = 1
default-shell: default-setup $(PROJECT)
	@set TCLLIBPATH=$(OUT_DIR:\=/)
	@if exist $(LIBDIR) for %f in ("$(LIBDIR)\*.tcl") do @$(COPY) %f "$(OUT_DIR)"
	$(DEBUGGER) $(TCLSH)

# Generation of Windows version resource
_TK_H          = $(_TKDIR)\include\tk.h
!elseif exist("$(_TKDIR)\generic\tk.h")
!ifdef RCFILE

TKINSTALL      = 0
# Note: don't use $** in below rule because there may be other dependencies
# and only the "main" rc must be passed to the resource compiler
$(TMP_DIR)\$(PROJECT).res: $(RCDIR)\$(PROJECT).rc
	$(RESCMD) $(RCDIR)\$(PROJECT).rc

_TK_H          = $(_TKDIR)\generic\tk.h
!else

MSG =^
# If parent makefile has not defined a resource definition file,
# we will generate one from standard template.
$(TMP_DIR)\$(PROJECT).res: $(TMP_DIR)\$(PROJECT).rc

Failed to find tk.h. The TKDIR macro does not appear correct.
$(TMP_DIR)\$(PROJECT).rc:
	@$(COPY) << $(TMP_DIR)\$(PROJECT).rc
#include <winver.h>

!error $(MSG)
VS_VERSION_INFO VERSIONINFO
 FILEVERSION	COMMAVERSION
 PRODUCTVERSION	COMMAVERSION
 FILEFLAGSMASK	0x3fL
#ifdef DEBUG
!endif
 FILEFLAGS	VS_FF_DEBUG
#else
!endif
 FILEFLAGS	0x0L
#endif
 FILEOS		VOS_NT_WINDOWS32
!endif

 FILETYPE	VFT_DLL
 FILESUBTYPE	0x0L
BEGIN
    BLOCK "StringFileInfo"
#-------------------------------------------------------------------------
# Extract Tk version numbers
#-------------------------------------------------------------------------
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription",  "Tcl extension " PROJECT
            VALUE "OriginalFilename", PRJLIBNAME
            VALUE "FileVersion",      DOTVERSION
            VALUE "ProductName",      "Package " PROJECT " for Tcl"
            VALUE "ProductVersion",   DOTVERSION
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

<<
!if defined(PROJECT_REQUIRES_TK) || "$(PROJECT)" == "tk"

!if [echo TK_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_MAJOR_VERSION >> versions.vc]
!endif # ifdef RCFILE

!endif
!if [echo TK_MINOR_VERSION = \>> versions.vc] \
!ifndef DISABLE_IMPLICIT_RULES
DISABLE_IMPLICIT_RULES = 0
   && [nmakehlp -V $(_TK_H) TK_MINOR_VERSION >> versions.vc]
!endif

!if [echo TK_PATCH_LEVEL = \>> versions.vc] \
!if !$(DISABLE_IMPLICIT_RULES)
# Implicit rule definitions - only for building library objects. For stubs and
# main application, the makefile should define explicit rules.

   && [nmakehlp -V $(_TK_H) TK_PATCH_LEVEL >> versions.vc]
{$(ROOT)}.c{$(TMP_DIR)}.obj::
	$(CCPKGCMD) @<<
$<
<<

!endif
{$(WIN_DIR)}.c{$(TMP_DIR)}.obj::
	$(CCPKGCMD) @<<
$<
<<

{$(GENERICDIR)}.c{$(TMP_DIR)}.obj::
	$(CCPKGCMD) @<<
$<
<<

!include versions.vc
{$(COMPATDIR)}.c{$(TMP_DIR)}.obj::
	$(CCPKGCMD) @<<
$<
<<

{$(RCDIR)}.rc{$(TMP_DIR)}.res:
TK_DOTVERSION	= $(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
TK_VERSION	= $(TK_MAJOR_VERSION)$(TK_MINOR_VERSION)
	$(RESCMD) $<

{$(WIN_DIR)}.rc{$(TMP_DIR)}.res:
	$(RESCMD) $<

{$(TMP_DIR)}.rc{$(TMP_DIR)}.res:
!if "$(PROJECT)" != "tk"
!if $(TKINSTALL)
WISH		= "$(_TKDIR)\bin\wish$(TK_VERSION)$(SUFX).exe"
	$(RESCMD) $<

!if !exist($(WISH))
.SUFFIXES:
.SUFFIXES:.c .rc

WISH		= "$(_TKDIR)\bin\wish$(TK_VERSION)$(SUFX:x=).exe"
!endif

TKSTUBLIB	= "$(_TKDIR)\lib\tkstub$(TK_VERSION).lib"
################################################################
# 14. Sanity check selected options against Tcl build options
# When building an extension, certain configuration options should
# match the ones used when Tcl was built. Here we check and
# warn on a mismatch.
!if !$(DOING_TCL)

TKIMPLIB	= "$(_TKDIR)\lib\tk$(TK_VERSION)$(SUFX).lib"
!if $(TCLINSTALL) # Building against an installed Tcl
!if exist("$(_TCLDIR)\lib\nmake\tcl.nmake")
TCLNMAKECONFIG = "$(_TCLDIR)\lib\nmake\tcl.nmake"
!if !exist($(TKIMPLIB))
TKIMPLIB	= "$(_TKDIR)\win\$(BUILDDIRTOP)\tk$(TCL_VERSION)$(SUFX:x=).lib"
!endif
TK_INCLUDES     = -I"$(_TKDIR)\include"
!else # !$(TCLINSTALL) - building against Tcl source
!if exist("$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl.nmake")
TCLNMAKECONFIG	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl.nmake"
!else
WISH		= "$(_TKDIR)\win\$(BUILDDIRTOP)\wish$(TCL_VERSION)$(SUFX).exe"
!if !exist($(WISH))
WISH		= "$(_TKDIR)\win\$(BUILDDIRTOP)\wish$(TCL_VERSION)$(SUFX:x=).exe"
!endif
!endif # TCLINSTALL

TKSTUBLIB	= "$(_TKDIR)\win\$(BUILDDIRTOP)\tkstub$(TCL_VERSION).lib"
!if $(CONFIG_CHECK)
!ifdef TCLNMAKECONFIG
!include $(TCLNMAKECONFIG)

TKIMPLIB	= "$(_TKDIR)\win\$(BUILDDIRTOP)\tk$(TCL_VERSION)$(SUFX).lib"
!if defined(CORE_MACHINE) && "$(CORE_MACHINE)" != "$(MACHINE)"
!error ERROR: Build target ($(MACHINE)) does not match the Tcl library architecture ($(CORE_MACHINE)).
!endif
!if $(TCL_VERSION) < 87 && defined(CORE_USE_THREAD_ALLOC) && $(CORE_USE_THREAD_ALLOC) != $(USE_THREAD_ALLOC)
!if !exist($(TKIMPLIB))
TKIMPLIB	= "$(_TKDIR)\win\$(BUILDDIRTOP)\tk$(TCL_VERSION)$(SUFX:x=).lib"
!message WARNING: Value of USE_THREAD_ALLOC ($(USE_THREAD_ALLOC)) does not match its Tcl core value ($(CORE_USE_THREAD_ALLOC)).
!endif
!if defined(CORE_DEBUG) && $(CORE_DEBUG) != $(DEBUG)
!message WARNING: Value of DEBUG ($(DEBUG)) does not match its Tcl library configuration ($(DEBUG)).
TK_INCLUDES     = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
!endif
!endif

!endif # TCLNMAKECONFIG
!endif

!endif # !$(DOING_TCL)


#----------------------------------------------------------
# Display stats being used.
#----------------------------------------------------------

!if !$(DOING_TCL)
!message *** Building against Tcl at '$(_TCLDIR)'
!endif
!if !$(DOING_TK) && $(NEED_TK)
!message *** Building against Tk at '$(_TKDIR)'
!endif
!message *** Intermediate directory will be '$(TMP_DIR)'
!message *** Output directory will be '$(OUT_DIR)'
!message *** Installation, if selected, will be in '$(_INSTALLDIR)'
!message *** Suffix for binaries will be '$(SUFX)'
!message *** Optional defines are '$(OPTDEFINES)'
!message *** Compiler version $(VCVER). Target $(MACHINE), host $(NATIVE_ARCH).
!message *** Compiler version $(VCVER). Target machine is $(MACHINE)
!message *** Host architecture is $(NATIVE_ARCH)
!message *** Compiler options '$(COMPILERFLAGS) $(OPTIMIZATIONS) $(DEBUGFLAGS) $(WARNINGS)'
!message *** Link options '$(LINKERFLAGS)'

!endif # ifdef _RULES_VC
!endif

Changes to win/stubs.c.

1

2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22



23
24
25
26
27
28
29
30



31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48








49
50
51
52













53
54

55
56
57













58
59
60
61
62
63



64
65
66






67
68
69
70
71


72
73
74
75
76
77
78
79


80
81
82
83
84
85
86
87


88
89
90
91
92
93
94

95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
110
111



112
113
114
115
116
117
118
119
120
121




122
123

124
125
126
127
128
129
130



131
132
133
134
135
136
137
138
139



140
141
142
143
144
145
146
147
148
149
150





151
152
153
154
155
156
157
158


159
160
161
162
163
164
165
166


167
168
169
170
171
172
173
174
175
176




177
178
179
180
181
182
183
184
185
186
187
188






189
190
191
192
193
194
195

196
197
198
199
200
201
202
203


204
205
206
207
208
209
210
211
212



213
214
215
216
217
218
219
220
221
222
223





224
225
226
227
228
229
230
231
232
233




234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249



250
251
252
253
254
255
256
257
258



259
260
261
262
263
264
265
266
267



268
269
270
271
272
273
274
275
276



277
278
279
280
281
282
283
284
285



286
287
288
289
290
291
292
293
294



295
296
297
298
299
300
301
302
303



304
305
306
307
308
309
310
311
312
313
314
315
316
317








318
319
320
321
322
323
324
325
326
327




328
329
330
331
332
333
334
335
336



337
338
339
340
341
342
343
344
345
346
347
348






349
350
351
352
353
354
355
356
357
358
359
360
361







362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389

390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414
415

416
417
418
419
420
421
422

423
424

425
426
427
428
429
430
431

432
433

434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19



20
21
22
23
24
25
26
27



28
29
30
31

32
33
34
35
36
37
38
39
40








41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101


102
103
104
105
106
107
108
109


110
111
112
113
114
115
116
117


118
119
120
121
122
123
124
125

126
127
128
129
130
131
132


133
134
135
136
137
138
139
140



141
142
143
144
145
146
147
148
149




150
151
152
153
154

155
156
157
158
159



160
161
162
163
164
165
166
167
168



169
170
171
172
173
174
175
176
177





178
179
180
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196


197
198
199
200
201
202
203
204




205
206
207
208
209
210
211
212
213
214






215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233


234
235
236
237
238
239
240
241



242
243
244
245
246
247
248
249
250





251
252
253
254
255
256
257
258
259
260
261




262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278



279
280
281
282
283
284
285
286
287



288
289
290
291
292
293
294
295
296



297
298
299
300
301
302
303
304
305



306
307
308
309
310
311
312
313
314



315
316
317
318
319
320
321
322
323



324
325
326
327
328
329
330
331
332



333
334
335
336
337
338
339
340
341








342
343
344
345
346
347
348
349
350
351
352
353
354
355




356
357
358
359
360
361
362
363
364
365



366
367
368
369
370
371
372
373
374






375
376
377
378
379
380
381
382
383
384
385
386







387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420

421
422
423
424
425
426
427

428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446

447
448
449
450
451
452
453

454
455

456
457
458
459
460
461
462

463
464

465
466
467
468
469
470
471
472
473
474









-
+







-
+










-
-
-
+
+
+





-
-
-
+
+
+

-
+








-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
+



+
+
+
+
+
+



-
-
+
+






-
-
+
+






-
-
+
+






-
+






-
-
+
+






-
-
-
+
+
+






-
-
-
-
+
+
+
+

-
+




-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
-
-
+
+
+
+
+






-
-
+
+






-
-
+
+






-
-
-
-
+
+
+
+






-
-
-
-
-
-
+
+
+
+
+
+






-
+






-
-
+
+






-
-
-
+
+
+






-
-
-
-
-
+
+
+
+
+






-
-
-
-
+
+
+
+






-
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
+
+
+






-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
-
-
-
+
+
+
+






-
-
-
+
+
+






-
-
-
-
-
-
+
+
+
+
+
+






-
-
-
-
-
-
-
+
+
+
+
+
+
+




















-
+






-
+






-
+








-
+









-
+






-
+

-
+






-
+

-
+









-
-
-
-
-
-
-
-
-
#include "tkInt.h"
#include "tk.h"

/*
 * Undocumented Xlib internal function
 */

int
_XInitImageFuncPtrs(
    TCL_UNUSED(XImage *))
    XImage *image)
{
    return Success;
}

/*
 * From Xutil.h
 */

void
XSetWMClientMachine(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(XTextProperty *))
    Display *display,
    Window w,
    XTextProperty *text_prop)
{
}

Status
XStringListToTextProperty(
    TCL_UNUSED(char **),
    TCL_UNUSED(int),
    TCL_UNUSED(XTextProperty *))
    char **list,
    int count,
    XTextProperty *text_prop_return)
{
    return Success;
    return (Status) 0;
}

/*
 * From Xlib.h
 */

int
XChangeProperty(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom),
    TCL_UNUSED(Atom),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(_Xconst unsigned char *),
    TCL_UNUSED(int))
    Display *display,
    Window w,
    Atom property,
    Atom type,
    int format,
    int mode,
    _Xconst unsigned char *data,
    int nelements)
{
    return Success;
}

Cursor
XCreateGlyphCursor(
    Display *display,
    Font source_font,
    Font mask_font,
    unsigned int source_char,
    unsigned int mask_char,
    XColor _Xconst *foreground_color,
    XColor _Xconst *background_color)
{
    return 1;
}

XIC
XCreateIC(TCL_UNUSED(XIM), ...)
XCreateIC(XIM xim, ...)
{
    return NULL;
}

Cursor
XCreatePixmapCursor(
    Display *display,
    Pixmap source,
    Pixmap mask,
    XColor *foreground_color,
    XColor *background_color,
    unsigned int x,
    unsigned int y)
{
    return (Cursor) NULL;
}

int
XDeleteProperty(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom))
    Display *display,
    Window w,
    Atom property)
{
    return Success;
}

void
XDestroyIC(
    XIC ic)
{
}

Bool
XFilterEvent(
    TCL_UNUSED(XEvent *),
    TCL_UNUSED(Window))
    XEvent *event,
    Window window)
{
    return 0;
}

int
XForceScreenSaver(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int))
    Display *display,
    int mode)
{
    return Success;
}

int
XFreeCursor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Cursor))
    Display *display,
    Cursor cursor)
{
    return Success;
}

GContext
XGContextFromGC(
    TCL_UNUSED(GC))
    GC gc)
{
    return (GContext) NULL;
}

char *
XGetAtomName(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Atom))
    Display *display,
    Atom atom)
{
    return NULL;
}

int
XGetWindowAttributes(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(XWindowAttributes *))
    Display *display,
    Window w,
    XWindowAttributes *window_attributes_return)
{
    return Success;
}

Status
XGetWMColormapWindows(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window **),
    TCL_UNUSED(int *))
    Display *display,
    Window w,
    Window **windows_return,
    int *count_return)
{
    return Success;
    return (Status) 0;
}

int
XIconifyWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int))
    Display *display,
    Window w,
    int screen_number)
{
    return Success;
}

XHostAddress *
XListHosts(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int *),
    TCL_UNUSED(Bool *))
    Display *display,
    int *nhosts_return,
    Bool *state_return)
{
    return NULL;
}

int
XLookupColor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    TCL_UNUSED(_Xconst char *),
    TCL_UNUSED(XColor *),
    TCL_UNUSED(XColor *))
    Display *display,
    Colormap colormap,
    _Xconst char *color_name,
    XColor *exact_def_return,
    XColor *screen_def_return)
{
    return Success;
}

int
XNextEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(XEvent *))
    Display *display,
    XEvent *event_return)
{
    return Success;
}

int
XPutBackEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(XEvent *))
    Display *display,
    XEvent *event)
{
    return Success;
}

int
XQueryColors(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    TCL_UNUSED(XColor *),
    TCL_UNUSED(int))
    Display *display,
    Colormap colormap,
    XColor *defs_in_out,
    int ncolors)
{
    return Success;
}

int
XQueryTree(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window **),
    TCL_UNUSED(unsigned int *))
    Display *display,
    Window w,
    Window *root_return,
    Window *parent_return,
    Window **children_return,
    unsigned int *nchildren_return)
{
    return Success;
}

int
XRefreshKeyboardMapping(
    TCL_UNUSED(XMappingEvent *))
    XMappingEvent *event_map)
{
    return Success;
}

Window
XRootWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int))
    Display *display,
    int screen_number)
{
    return (Window) NULL;
}

int
XSelectInput(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(long))
    Display *display,
    Window w,
    long event_mask)
{
    return Success;
}

int
XSendEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Bool),
    TCL_UNUSED(long),
    TCL_UNUSED(XEvent *))
    Display *display,
    Window w,
    Bool propagate,
    long event_mask,
    XEvent *event_send)
{
    return Success;
}

int
XSetCommand(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(char **),
    TCL_UNUSED(int))
    Display *display,
    Window w,
    char **argv,
    int argc)
{
    return Success;
}

XErrorHandler
XSetErrorHandler(
    TCL_UNUSED(XErrorHandler))
    XErrorHandler handler)
{
    return NULL;
}

int
XSetIconName(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(_Xconst char *))
    Display *display,
    Window w,
    _Xconst char *icon_name)
{
    return Success;
}

int
XSetWindowBackground(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned long))
    Display *display,
    Window w,
    unsigned long background_pixel)
{
    return Success;
}

int
XSetWindowBackgroundPixmap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Pixmap))
    Display *display,
    Window w,
    Pixmap background_pixmap)
{
    return Success;
}

int
XSetWindowBorder(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned long))
    Display *display,
    Window w,
    unsigned long border_pixel)
{
    return Success;
}

int
XSetWindowBorderPixmap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Pixmap))
    Display *display,
    Window w,
    Pixmap border_pixmap)
{
    return Success;
}

int
XSetWindowBorderWidth(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(unsigned int))
    Display *display,
    Window w,
    unsigned int width)
{
    return Success;
}

int
XSetWindowColormap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Colormap))
    Display *display,
    Window w,
    Colormap colormap)
{
    return Success;
}

Bool
XTranslateCoordinates(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    TCL_UNUSED(int),
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    TCL_UNUSED(Window *))
    Display *display,
    Window src_w,
    Window dest_w,
    int src_x,
    int src_y,
    int *dest_x_return,
    int *dest_y_return,
    Window *child_return)
{
    return 0;
}

int
XWindowEvent(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(long),
    TCL_UNUSED(XEvent *))
    Display *display,
    Window w,
    long event_mask,
    XEvent *event_return)
{
    return Success;
}

int
XWithdrawWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int))
    Display *display,
    Window w,
    int screen_number)
{
    return Success;
}

int
XmbLookupString(
    TCL_UNUSED(XIC),
    TCL_UNUSED(XKeyPressedEvent *),
    TCL_UNUSED(char *),
    TCL_UNUSED(int),
    TCL_UNUSED(KeySym *),
    TCL_UNUSED(Status *))
    XIC ic,
    XKeyPressedEvent *event,
    char *buffer_return,
    int bytes_buffer,
    KeySym *keysym_return,
    Status *status_return)
{
    return Success;
}

int
XGetWindowProperty(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Atom),
    TCL_UNUSED(long),
    TCL_UNUSED(long),
    TCL_UNUSED(Bool),
    TCL_UNUSED(Atom),
    Display *display,
    Window w,
    Atom property,
    long long_offset,
    long long_length,
    Bool delete,
    Atom req_type,
    Atom *actual_type_return,
    int *actual_format_return,
    unsigned long *nitems_return,
    unsigned long *bytes_after_return,
    unsigned char **prop_return)
{
    *actual_type_return = None;
    *actual_format_return = 0;
    *nitems_return = 0;
    *bytes_after_return = 0;
    *prop_return = NULL;
    return BadValue;
}

/*
 * The following functions were implemented as macros under Windows.
 */

int
XFlush(
    TCL_UNUSED(Display *))
    Display *display)
{
    return 0;
}

int
XGrabServer(
    TCL_UNUSED(Display *))
    Display *display)
{
    return 0;
}

int
XUngrabServer(
    TCL_UNUSED(Display *))
    Display *display)
{
    return 0;
}

int
XFree(
    void *data)
{
	if (data != NULL) {
	if ((data) != NULL) {
		ckfree(data);
	}
    return 0;
}

int
XNoOp(
    Display *display)
{
    LastKnownRequestProcessed(display)++;
	display->request++;
    return 0;
}

XAfterFunction
XSynchronize(
    Display *display,
    TCL_UNUSED(Bool))
    Bool bool)
{
    LastKnownRequestProcessed(display)++;
	display->request++;
    return NULL;
}

int
XSync(
    Display *display,
    TCL_UNUSED(Bool))
    Bool bool)
{
    LastKnownRequestProcessed(display)++;
	display->request++;
    return 0;
}

VisualID
XVisualIDFromVisual(
    Visual *visual)
{
    return visual->visualid;
}

int
XOffsetRegion(
    TCL_UNUSED(Region),
	TCL_UNUSED(int),
	TCL_UNUSED(int))
{
	return 0;
}

Deleted win/svnmanifest.in.

1

-
svn-r

Deleted win/targets.vc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#------------------------------------------------------------- -*- makefile -*-
# targets.vc --
#
# Part of the nmake based build system for Tcl and its extensions.
# This file defines some standard targets for the convenience of extensions
# and can be optionally included by the extension makefile.
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for docs.

$(PROJECT): setup pkgindex $(PRJLIB)

!ifdef PRJ_STUBOBJS
$(PROJECT): $(PRJSTUBLIB)
$(PRJSTUBLIB): $(PRJ_STUBOBJS)
	$(LIBCMD) $**

$(PRJ_STUBOBJS):
	$(CCSTUBSCMD) %s
!endif # PRJ_STUBOBJS

!ifdef PRJ_MANIFEST
$(PROJECT): $(PRJLIB).manifest
$(PRJLIB).manifest: $(PRJ_MANIFEST)
	@nmakehlp -s << $** >$@
@MACHINE@	  $(MACHINE:IX86=X86)
<<
!endif

!if "$(PROJECT)" != "tcl" && "$(PROJECT)" != "tk"
$(PRJLIB): $(PRJ_OBJS) $(RESFILE)
!if $(STATIC_BUILD)
       $(LIBCMD) $**
!else
       $(DLLCMD) $**
       $(_VC_MANIFEST_EMBED_DLL)
!endif
       -@del $*.exp
!endif

!if "$(PRJ_HEADERS)" != "" && "$(PRJ_OBJS)" != ""
$(PRJ_OBJS): $(PRJ_HEADERS)
!endif

# If parent makefile has defined stub objects, add their installation
# to the default install
!if "$(PRJ_STUBOBJS)" != ""
default-install: default-install-stubs
!endif

# Unlike the other default targets, these cannot be in rules.vc because
# the executed command depends on existence of macro PRJ_HEADERS_PUBLIC
# that the parent makefile will not define until after including rules-ext.vc
!if "$(PRJ_HEADERS_PUBLIC)" != ""
default-install: default-install-headers
default-install-headers:
	@echo Installing headers to '$(INCLUDE_INSTALL_DIR)'
	@for %f in ($(PRJ_HEADERS_PUBLIC)) do @$(COPY) %f "$(INCLUDE_INSTALL_DIR)"
!endif

!if "$(DISABLE_STANDARD_TARGETS)" == ""
DISABLE_STANDARD_TARGETS = 0
!endif

!if "$(DISABLE_TARGET_setup)" == ""
DISABLE_TARGET_setup = 0
!endif
!if "$(DISABLE_TARGET_install)" == ""
DISABLE_TARGET_install = 0
!endif
!if "$(DISABLE_TARGET_clean)" == ""
DISABLE_TARGET_clean = 0
!endif
!if "$(DISABLE_TARGET_test)" == ""
DISABLE_TARGET_test = 0
!endif
!if "$(DISABLE_TARGET_shell)" == ""
DISABLE_TARGET_shell = 0
!endif

!if !$(DISABLE_STANDARD_TARGETS)
!if !$(DISABLE_TARGET_setup)
setup: default-setup
!endif
!if !$(DISABLE_TARGET_install)
install: default-install
!endif
!if !$(DISABLE_TARGET_clean)
clean: default-clean
realclean: hose
hose: default-hose
distclean: realclean default-distclean
!endif
!if !$(DISABLE_TARGET_test)
test: default-test
!endif
!if !$(DISABLE_TARGET_shell)
shell: default-shell
!endif
!endif # DISABLE_STANDARD_TARGETS

Changes to win/tcl.m4.

24
25
26
27
28
29
30
31

32
33

34
35
36
37
38
39
40
24
25
26
27
28
29
30

31
32

33
34
35
36
37
38
39
40







-
+

-
+







    # the alternative search directory is invoked by --with-tcl
    #

    if test x"${no_tcl}" = x ; then
	# we reset no_tcl in case something fails here
	no_tcl=true
	AC_ARG_WITH(tcl,
	    AS_HELP_STRING([--with-tcl],
	    AC_HELP_STRING([--with-tcl],
		[directory containing tcl configuration (tclConfig.sh)]),
	    [with_tclconfig="${withval}"])
	    with_tclconfig="${withval}")
	AC_MSG_CHECKING([for Tcl configuration])
	AC_CACHE_VAL(ac_cv_c_tclconfig,[

	    # First check to see if --with-tcl was specified.
	    if test x"${with_tclconfig}" != x ; then
		case "${with_tclconfig}" in
		    */tclConfig.sh )
142
143
144
145
146
147
148
149

150
151

152
153
154
155
156
157
158
142
143
144
145
146
147
148

149
150

151
152
153
154
155
156
157
158







-
+

-
+







    # the alternative search directory is invoked by --with-tk
    #

    if test x"${no_tk}" = x ; then
	# we reset no_tk in case something fails here
	no_tk=true
	AC_ARG_WITH(tk,
	    AS_HELP_STRING([--with-tk],
	    AC_HELP_STRING([--with-tk],
		[directory containing tk configuration (tkConfig.sh)]),
	    [with_tkconfig="${withval}"])
	    with_tkconfig="${withval}")
	AC_MSG_CHECKING([for Tk configuration])
	AC_CACHE_VAL(ac_cv_c_tkconfig,[

	    # First check to see if --with-tkconfig was specified.
	    if test x"${with_tkconfig}" != x ; then
		case "${with_tkconfig}" in
		    */tkConfig.sh )
275
276
277
278
279
280
281








282
283
284
285
286
287
288
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296







+
+
+
+
+
+
+
+








    if test -f $TCL_BIN_DIR/Makefile ; then
        TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
        TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
        TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
    fi

    #
    # eval is required to do the TCL_DBGX substitution
    #

    eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
    eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
    eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""

    eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
    eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
    eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""

    AC_SUBST(TCL_VERSION)
    AC_SUBST(TCL_BIN_DIR)
    AC_SUBST(TCL_SRC_DIR)
352
353
354
355
356
357
358








359
360
361
362
363
364
365
366



































367

368
369
370
371
372
373
374
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425







+
+
+
+
+
+
+
+








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_SHARED], [
    AC_MSG_CHECKING([how to build libraries])
    AC_ARG_ENABLE(shared,
	[  --enable-shared         build and link with shared libraries (default: on)],
	[tcl_ok=$enableval], [tcl_ok=yes])

    if test "${enable_shared+set}" = set; then
	enableval="$enable_shared"
	tcl_ok=$enableval
    else
	tcl_ok=yes
    fi

    if test "$tcl_ok" = "yes" ; then
	AC_MSG_RESULT([shared])
	SHARED_BUILD=1
    else
	AC_MSG_RESULT([static])
	SHARED_BUILD=0
	AC_DEFINE(STATIC_BUILD, 1, [Is this a static build?])
    fi
])

#------------------------------------------------------------------------
# SC_ENABLE_THREADS --
#
#	Specify if thread support should be enabled
#
# Arguments:
#	none
#
# Results:
#
#	Adds the following arguments to configure:
#		--enable-threads=yes|no
#
#	Defines the following vars:
#		TCL_THREADS
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_THREADS], [
    AC_MSG_CHECKING(for building with threads)
    AC_ARG_ENABLE(threads, [  --enable-threads        build with threads (default: on)],
	[tcl_ok=$enableval], [tcl_ok=yes])

    if test "$tcl_ok" = "yes"; then
	AC_MSG_RESULT([yes (default)])
	TCL_THREADS=1
	AC_DEFINE(TCL_THREADS)
	# USE_THREAD_ALLOC tells us to try the special thread-based
	# allocator that significantly reduces lock contention
	AC_DEFINE(USE_THREAD_ALLOC)
    else
	TCL_THREADS=0
	AC_MSG_RESULT(no)
    fi
    AC_SUBST(SHARED_BUILD)
    AC_SUBST(TCL_THREADS)
])

#------------------------------------------------------------------------
# SC_ENABLE_SYMBOLS --
#
#	Specify if debugging symbols should be used.
#	Memory (TCL_MEM_DEBUG) and compile (TCL_COMPILE_DEBUG) debugging
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410

411
412
413
414
415
416
417
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471







+










+







+







#		--enable-symbols
#
#	Defines the following vars:
#		CFLAGS_DEFAULT	Sets to $(CFLAGS_DEBUG) if true
#				Sets to $(CFLAGS_OPTIMIZE) if false
#		LDFLAGS_DEFAULT	Sets to $(LDFLAGS_DEBUG) if true
#				Sets to $(LDFLAGS_OPTIMIZE) if false
#		DBGX		Debug library extension
#
#------------------------------------------------------------------------

AC_DEFUN([SC_ENABLE_SYMBOLS], [
    AC_MSG_CHECKING([for build with symbols])
    AC_ARG_ENABLE(symbols, [  --enable-symbols        build with debugging symbols (default: off)],    [tcl_ok=$enableval], [tcl_ok=no])
# FIXME: Currently, LDFLAGS_DEFAULT is not used, it should work like CFLAGS_DEFAULT.
    if test "$tcl_ok" = "no"; then
	CFLAGS_DEFAULT='$(CFLAGS_OPTIMIZE)'
	LDFLAGS_DEFAULT='$(LDFLAGS_OPTIMIZE)'
	DBGX=""
	AC_DEFINE(NDEBUG, 1, [Is no debugging enabled?])
	AC_MSG_RESULT([no])

	AC_DEFINE(TCL_CFG_OPTIMIZED)
    else
	CFLAGS_DEFAULT='$(CFLAGS_DEBUG)'
	LDFLAGS_DEFAULT='$(LDFLAGS_DEBUG)'
	DBGX=g
	if test "$tcl_ok" = "yes"; then
	    AC_MSG_RESULT([yes (standard debugging)])
	fi
    fi
    AC_SUBST(CFLAGS_DEFAULT)
    AC_SUBST(LDFLAGS_DEFAULT)

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
503
504
505
506
507
508
509

510
511
512
513
514
515
516







-







# Results:
#
#	Can the following vars:
#		EXTRA_CFLAGS
#		CFLAGS_DEBUG
#		CFLAGS_OPTIMIZE
#		CFLAGS_WARNING
#		CFLAGS_NOLTO
#		LDFLAGS_DEBUG
#		LDFLAGS_OPTIMIZE
#		LDFLAGS_CONSOLE
#		LDFLAGS_WINDOW
#		CC_OBJNAME
#		CC_EXENAME
#		CYGPATH
486
487
488
489
490
491
492











493
494
495
496
497
498
499
500
501
502
503
504

505
506
507
508
509
510
511

512
513
514
515
516
517



518
519
520
521
522
523

524
525
526
527
528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566

567
568
569
570
571
572
573

574
575
576
577



578
579
580
581
582
583
584
585

586
587
588
589
590
591







592

593
594
595
596
597
598
599
600







+
+
+
+
+
+
+
+
+
+
+






-




-
+






-
+



-
-
-
+
+
+





-
+





-
-
-
-
-
-
-

-
+







AC_DEFUN([SC_CONFIG_CFLAGS], [

    # Step 0: Enable 64 bit support?

    AC_MSG_CHECKING([if 64bit support is requested])
    AC_ARG_ENABLE(64bit,[  --enable-64bit          enable 64bit support (where applicable)], [do64bit=$enableval], [do64bit=no])
    AC_MSG_RESULT($do64bit)

    # Cross-compiling options for Windows/CE builds

    AC_MSG_CHECKING([if Windows/CE build is requested])
    AC_ARG_ENABLE(wince,[  --enable-wince          enable Win/CE support (where applicable)], [doWince=$enableval], [doWince=no])
    AC_MSG_RESULT($doWince)

    AC_MSG_CHECKING([for Windows/CE celib directory])
    AC_ARG_WITH(celib,[  --with-celib=DIR        use Windows/CE support library from DIR],
	    CELIB_DIR=$withval, CELIB_DIR=NO_CELIB)
    AC_MSG_RESULT([$CELIB_DIR])

    # Set some defaults (may get changed below)
    EXTRA_CFLAGS=""
	AC_DEFINE(MODULE_SCOPE, [extern], [No need to mark inidividual symbols as hidden])

    AC_CHECK_PROG(CYGPATH, cygpath, cygpath -m, echo)
    AC_CHECK_PROG(WINE, wine, wine,)

    SHLIB_SUFFIX=".dll"

    # MACHINE is IX86 for LINK, but this is used by the manifest,
    # which requires x86|amd64|arm64|ia64.
    # which requires x86|amd64|ia64.
    MACHINE="X86"

    if test "$GCC" = "yes"; then

      AC_CACHE_CHECK(for cross-compile version of gcc,
	ac_cv_cross,
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_COMPILE([
	    #ifndef _WIN32
		#error cross-compiler
	    #endif
	]], [[]])],
	[ac_cv_cross=no],
	[ac_cv_cross=yes])
	], [],
	ac_cv_cross=no,
	ac_cv_cross=yes)
      )

      if test "$ac_cv_cross" = "yes"; then
	case "$do64bit" in
	    amd64|x64|yes)
		CC="x86_64-w64-mingw32-${CC}"
		CC="x86_64-w64-mingw32-gcc"
		LD="x86_64-w64-mingw32-ld"
		AR="x86_64-w64-mingw32-ar"
		RANLIB="x86_64-w64-mingw32-ranlib"
		RC="x86_64-w64-mingw32-windres"
	    ;;
	    arm64|aarch64)
		CC="aarch64-w64-mingw32-${CC}"
		LD="aarch64-w64-mingw32-ld"
		AR="aarch64-w64-mingw32-ar"
		RANLIB="aarch64-w64-mingw32-ranlib"
		RC="aarch64-w64-mingw32-windres"
	    ;;
	    *)
		CC="i686-w64-mingw32-${CC}"
		CC="i686-w64-mingw32-gcc"
		LD="i686-w64-mingw32-ld"
		AR="i686-w64-mingw32-ar"
		RANLIB="i686-w64-mingw32-ranlib"
		RC="i686-w64-mingw32-windres"
	    ;;
	esac
      fi
578
579
580
581
582
583
584
585

586
587
588
589
590
591



592
593
594
595
596
597
598
599
600
601
602
603

604
605

606
607
608



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697

698
699
700
701
702



703
704
705
706
707
708
709

710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
634
635
636
637
638
639
640

641
642
643
644



645
646
647
648
649
650
651



652
653
654
655

656
657
658
659



660
661
662
663
664
665
666
667
668
669

































670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695

696
697
698
699
700
701
702
703
704
705
706
707
708
709

710
711
712
713
714
715
716
717

718
719
720



721
722
723
724
725
726
727
728
729

730
731
732
733









734
735
736
737
738
739
740







-
+



-
-
-
+
+
+




-
-
-




-
+


+
-
-
-
+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
+

















-
+













-
+







-
+


-
-
-
+
+
+






-
+



-
-
-
-
-
-
-
-
-







    # set various compiler flags depending on whether we are using gcc or cl

    if test "${GCC}" = "yes" ; then
	extra_cflags="-pipe"
	extra_ldflags="-pipe -static-libgcc"
	AC_CACHE_CHECK(for mingw32 version of gcc,
	    ac_cv_win32,
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	    AC_TRY_COMPILE([
		#ifdef _WIN32
		    #error win32
		#endif
	    ]], [[]])],
	    [ac_cv_win32=no],
	    [ac_cv_win32=yes])
	    ], [],
	    ac_cv_win32=no,
	    ac_cv_win32=yes)
	)
	if test "$ac_cv_win32" != "yes"; then
	    AC_MSG_ERROR([${CC} cannot produce win32 executables.])
	fi
	if test "$do64bit" != "arm64"; then
	    extra_cflags="$extra_cflags -DHAVE_CPUID=1"
	fi

	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -mwindows -municode -Dmain=xxmain"
	AC_CACHE_CHECK(for working -municode linker flag,
	    ac_cv_municode,
	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
	AC_TRY_LINK([
	#include <windows.h>
	int APIENTRY wWinMain(HINSTANCE a, HINSTANCE b, LPWSTR c, int d) {return 0;}
	],
	]], [[]])],
	    [ac_cv_municode=yes],
	    [ac_cv_municode=no])
	[],
	    ac_cv_municode=yes,
	    ac_cv_municode=no)
	)
	CFLAGS=$hold_cflags
	if test "$ac_cv_municode" = "yes" ; then
	    extra_ldflags="$extra_ldflags -municode"
	else
	    extra_cflags="$extra_cflags -DTCL_BROKEN_MAINARGS"
	fi
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -fno-lto"
	AC_CACHE_CHECK(for working -fno-lto,
	    ac_cv_nolto,
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
	    [ac_cv_nolto=yes],
	    [ac_cv_nolto=no])
	)
	CFLAGS=$hold_cflags
	if test "$ac_cv_nolto" = "yes" ; then
	    CFLAGS_NOLTO="-fno-lto"
	else
	    CFLAGS_NOLTO=""
	fi
	AC_CACHE_CHECK([if the compiler understands -finput-charset],
	    tcl_cv_cc_input_charset, [
	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -finput-charset=UTF-8"
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[tcl_cv_cc_input_charset=yes],[tcl_cv_cc_input_charset=no])
	    CFLAGS=$hold_cflags])
	if test $tcl_cv_cc_input_charset = yes; then
	    extra_cflags="$extra_cflags -finput-charset=UTF-8"
	fi
    fi

    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Wl,--enable-auto-image-base"
    AC_CACHE_CHECK(for working --enable-auto-image-base,
	ac_cv_enable_auto_image_base,
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
	[ac_cv_enable_auto_image_base=yes],
	[ac_cv_enable_auto_image_base=no])
    )
    CFLAGS=$hold_cflags
    if test "$ac_cv_enable_auto_image_base" == "yes" ; then
	extra_ldflags="$extra_ldflags -Wl,--enable-auto-image-base"
    fi

    AC_MSG_CHECKING([compiler flags])
    if test "${GCC}" = "yes" ; then
	SHLIB_LD=""
	SHLIB_LD_LIBS='${LIBS}'
	LIBS="-lnetapi32 -lkernel32 -luser32 -ladvapi32 -luserenv -lws2_32"
	# mingw needs to link ole32 and oleaut32 for [send], but MSVC doesn't
	LIBS_GUI="-lgdi32 -lcomdlg32 -limm32 -lcomctl32 -lshell32 -luuid -lole32 -loleaut32 -lwinspool"
	LIBS_GUI="-lgdi32 -lcomdlg32 -limm32 -lcomctl32 -lshell32 -luuid -lole32 -loleaut32"
	STLIB_LD='${AR} cr'
	RC_OUT=-o
	RC_TYPE=
	RC_INCLUDE=--include
	RC_DEFINE=--define
	RES=res.o
	MAKE_LIB="\${STLIB_LD} \[$]@"
	MAKE_STUB_LIB="\${STLIB_LD} \[$]@"
	POST_MAKE_LIB="\${RANLIB} \[$]@"
	MAKE_EXE="\${CC} -o \[$]@"
	LIBPREFIX="lib"

	if test "${SHARED_BUILD}" = "0" ; then
	    # static
            AC_MSG_RESULT([using static flags])
	    runtime=
	    LIBRARIES="\${STATIC_LIBRARIES}"
	    EXESUFFIX="s.exe"
	    EXESUFFIX="s\${DBGX}.exe"
	else
	    # dynamic
            AC_MSG_RESULT([using shared flags])

	    # ad-hoc check to see if CC supports -shared.
	    if "${CC}" -shared 2>&1 | egrep ': -shared not supported' >/dev/null; then
		AC_MSG_ERROR([${CC} does not support the -shared option.
                You will need to upgrade to a newer version of the toolchain.])
	    fi

	    runtime=
	    # Add SHLIB_LD_LIBS to the Make rule, not here.

	    EXESUFFIX=".exe"
	    EXESUFFIX="\${DBGX}.exe"
	    LIBRARIES="\${SHARED_LIBRARIES}"
	fi
	# Link with gcc since ld does not link to default libs like
	# -luser32 and -lmsvcrt by default.
	SHLIB_LD='${CC} -shared'
	SHLIB_LD_LIBS='${LIBS}'
	MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -o \[$]@ ${extra_ldflags} \
	    -Wl,--out-implib,\$(patsubst %.dll,lib%.dll.a,\[$]@)"
	    -Wl,--out-implib,\$(patsubst %.dll,lib%.a,\[$]@)"
	# DLLSUFFIX is separate because it is the building block for
	# users of tclConfig.sh that may build shared or static.
	DLLSUFFIX=".dll"
	LIBSUFFIX=".a"
	LIBFLAGSUFFIX=""
	DLLSUFFIX="\${DBGX}.dll"
	LIBSUFFIX="\${DBGX}.a"
	LIBFLAGSUFFIX="\${DBGX}"
	SHLIB_SUFFIX=.dll

	EXTRA_CFLAGS="${extra_cflags}"

	CFLAGS_DEBUG=-g
	CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
	CFLAGS_WARNING="-Wall -Wextra -Wshadow -Wundef -Wwrite-strings -Wpointer-arith"
	CFLAGS_WARNING="-Wall -Wwrite-strings -Wsign-compare -Wdeclaration-after-statement"
	LDFLAGS_DEBUG=
	LDFLAGS_OPTIMIZE=

	case "${CC}" in
	    *++)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wno-format"
		;;
	    *)
		CFLAGS_WARNING="${CFLAGS_WARNING} -Wc++-compat -fextended-identifiers"
		;;
	esac

	# Specify the CC output file names based on the target name
	CC_OBJNAME="-o \[$]@"
	CC_EXENAME="-o \[$]@"

	# Specify linker flags depending on the type of app being
	# built -- Console vs. Window.
	#
741
742
743
744
745
746
747
748
749
750
751
752
753
754

755
756
757

758
759
760
761
762
763



764
765
766
767
768



769
770
771
772
773
774
775
776
777
778

779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794
795
796
797
798
799



800



801





802
803
804
805
806
807

808
809
810

811
812



813
814
815
816
817
818
819
820
821
822
823
824
825
826









827

828

829
830
831



832
833
834
835
836
837
838
839
840
841
842
843
844
845


























































































846


847
848
849
850
851
852
853
753
754
755
756
757
758
759




760
761

762
763
764

765
766
767
768



769
770
771
772
773



774
775
776
777
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792

793
794
795
796
797
798
799
800
801
802
803
804



805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820



821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853

854
855
856



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
971
972







-
-
-
-


-
+


-
+



-
-
-
+
+
+


-
-
-
+
+
+









-
+






-
+











-
-
-
+
+
+

+
+
+

+
+
+
+
+



-
-
-
+



+


+
+
+














+
+
+
+
+
+
+
+
+
-
+

+
-
-
-
+
+
+














+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+







	LDFLAGS_WINDOW="-mwindows ${extra_ldflags}"

	case "$do64bit" in
	    amd64|x64|yes)
		MACHINE="AMD64" ; # assume AMD64 as default 64-bit build
		AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
		;;
	    arm64|aarch64)
		MACHINE="ARM64"
		AC_MSG_RESULT([   Using ARM64 $MACHINE mode])
		;;
	    ia64)
		MACHINE="IA64"
		AC_MSG_RESULT([   Using IA64 $MACHINE mode])
		AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
		;;
	    *)
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
		AC_TRY_COMPILE([
		    #ifndef _WIN64
			#error 32-bit
		    #endif
		]], [[]])],
			[tcl_win_64bit=yes],
			[tcl_win_64bit=no]
		], [],
			tcl_win_64bit=yes,
			tcl_win_64bit=no
		)
		if test "$tcl_win_64bit" = "yes" ; then
		    do64bit=amd64
		    MACHINE="AMD64"
		    AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
			do64bit=amd64
			MACHINE="AMD64"
			AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
		fi
		;;
	esac
    else
	if test "${SHARED_BUILD}" = "0" ; then
	    # static
            AC_MSG_RESULT([using static flags])
	    runtime=-MT
	    LIBRARIES="\${STATIC_LIBRARIES}"
	    EXESUFFIX="s.exe"
	    EXESUFFIX="s\${DBGX}.exe"
	else
	    # dynamic
            AC_MSG_RESULT([using shared flags])
	    runtime=-MD
	    # Add SHLIB_LD_LIBS to the Make rule, not here.
	    LIBRARIES="\${SHARED_LIBRARIES}"
	    EXESUFFIX=".exe"
	    EXESUFFIX="\${DBGX}.exe"
	    case "x`echo \${VisualStudioVersion}`" in
		x1[[4-9]]*)
		    lflags="${lflags} -nodefaultlib:libucrt.lib"
		    ;;
		*)
		    ;;
	    esac
	fi
	MAKE_DLL="\${SHLIB_LD} \$(LDFLAGS) -out:\[$]@"
	# DLLSUFFIX is separate because it is the building block for
	# users of tclConfig.sh that may build shared or static.
	DLLSUFFIX=".dll"
	LIBSUFFIX=".lib"
	LIBFLAGSUFFIX=""
	DLLSUFFIX="\${DBGX}.dll"
	LIBSUFFIX="\${DBGX}.lib"
	LIBFLAGSUFFIX="\${DBGX}"

	# This is a 2-stage check to make sure we have the 64-bit SDK
	# We have to know where the SDK is installed.
	# This magic is based on MS Platform SDK for Win2003 SP1 - hobbs
	if test "$do64bit" != "no" ; then
	    if test "x${MSSDK}x" = "xx" ; then
		MSSDK="C:/Progra~1/Microsoft Platform SDK"
	    fi
	    MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'`
	    PATH64=""
	    case "$do64bit" in
		amd64|x64|yes)
		    MACHINE="AMD64" ; # assume AMD64 as default 64-bit build
		    ;;
		arm64|aarch64)
		    MACHINE="ARM64"
		    PATH64="${MSSDK}/Bin/Win64/x86/AMD64"
		    ;;
		ia64)
		    MACHINE="IA64"
		    PATH64="${MSSDK}/Bin/Win64"
		    ;;
	    esac
	    if test ! -d "${PATH64}" ; then
		AC_MSG_WARN([Could not find 64-bit $MACHINE SDK])
	    fi
	    AC_MSG_RESULT([   Using 64-bit $MACHINE mode])
	fi

	LIBS="netapi32.lib kernel32.lib user32.lib advapi32.lib userenv.lib ws2_32.lib"

	case "x`echo \${VisualStudioVersion}`" in
		x1[[4-9]]*)
		    LIBS="$LIBS ucrt.lib"
		    ;;
		*)
		    ;;
	esac

	if test "$do64bit" != "no" ; then
	    # The space-based-path will work for the Makefile, but will
	    # not work if AC_TRY_COMPILE is called.  TEA has the
	    # TEA_PATH_NOSPACE to avoid this issue.
	    # Check if _WIN64 is already recognized, and if so we don't
	    # need to modify CC.
	    AC_CHECK_DECL([_WIN64], [],
			  [CC="\"${PATH64}/cl.exe\" -I\"${MSSDK}/Include\" \
			 -I\"${MSSDK}/Include/crt\" \
			 -I\"${MSSDK}/Include/crt/sys\""])
	    RC="rc"
	    RC="\"${MSSDK}/bin/rc.exe\""
	    CFLAGS_DEBUG="-nologo -Zi -Od ${runtime}d"
	    # Do not use -O2 for Win64 - this has proved buggy in code gen.
	    CFLAGS_OPTIMIZE="-nologo -O2 ${runtime}"
	    lflags="${lflags} -nologo -MACHINE:${MACHINE}"
	    LINKBIN="link"
	    CFLAGS_OPTIMIZE="-nologo -O1 ${runtime}"
	    lflags="${lflags} -nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\""
	    LINKBIN="\"${PATH64}/link.exe\""
	    # Avoid 'unresolved external symbol __security_cookie' errors.
	    # c.f. http://support.microsoft.com/?id=894573
	    LIBS="$LIBS bufferoverflowU.lib"
	else
	    RC="rc"
	    # -Od - no optimization
	    # -WX - warnings as errors
	    CFLAGS_DEBUG="-nologo -Z7 -Od -WX ${runtime}d"
	    # -O2 - create fast code (/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy)
	    CFLAGS_OPTIMIZE="-nologo -O2 ${runtime}"
	    lflags="${lflags} -nologo"
	    LINKBIN="link"
	fi

	if test "$doWince" != "no" ; then
	    # Set defaults for common evc4/PPC2003 setup
	    # Currently Tcl requires 300+, possibly 420+ for sockets
	    CEVERSION=420; 		# could be 211 300 301 400 420 ...
	    TARGETCPU=ARMV4;	# could be ARMV4 ARM MIPS SH3 X86 ...
	    ARCH=ARM;		# could be ARM MIPS X86EM ...
	    PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002"
	    if test "$doWince" != "yes"; then
		# If !yes then the user specified something
		# Reset ARCH to allow user to skip specifying it
		ARCH=
		eval `echo $doWince | awk -F "," '{ \
	if (length([$]1)) { printf "CEVERSION=\"%s\"\n", [$]1; \
	if ([$]1 < 400)	  { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \
	if (length([$]2)) { printf "TARGETCPU=\"%s\"\n", toupper([$]2) }; \
	if (length([$]3)) { printf "ARCH=\"%s\"\n", toupper([$]3) }; \
	if (length([$]4)) { printf "PLATFORM=\"%s\"\n", [$]4 }; \
		}'`
		if test "x${ARCH}" = "x" ; then
		    ARCH=$TARGETCPU;
		fi
	    fi
	    OSVERSION=WCE$CEVERSION;
	    if test "x${WCEROOT}" = "x" ; then
		WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0"
		if test ! -d "${WCEROOT}" ; then
		    WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
		fi
	    fi
	    if test "x${SDKROOT}" = "x" ; then
		SDKROOT="C:/Program Files/Windows CE Tools"
		if test ! -d "${SDKROOT}" ; then
		    SDKROOT="C:/Windows CE Tools"
		fi
	    fi
	    # The space-based-path will work for the Makefile, but will
	    # not work if AC_TRY_COMPILE is called.
	    WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'`
	    SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'`
	    CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'`
	    if test ! -d "${CELIB_DIR}/inc"; then
		AC_MSG_ERROR([Invalid celib directory "${CELIB_DIR}"])
	    fi
	    if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"\
		-o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
		AC_MSG_ERROR([could not find PocketPC SDK or target compiler to enable WinCE mode [$CEVERSION,$TARGETCPU,$ARCH,$PLATFORM]])
	    else
		CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include"
		if test -d "${CEINCLUDE}/${TARGETCPU}" ; then
		    CEINCLUDE="${CEINCLUDE}/${TARGETCPU}"
		fi
		CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"
	    fi
	fi

	if test "$doWince" != "no" ; then
	    CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin"
	    if test "${TARGETCPU}" = "X86"; then
		CC="${CEBINROOT}/cl.exe"
	    else
		CC="${CEBINROOT}/cl${ARCH}.exe"
	    fi
	    CC="\"${CC}\" -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
	    RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\""
	    arch=`echo ${ARCH} | awk '{print tolower([$]0)}'`
	    defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _DLL _WINDOWS"
	    for i in $defs ; do
		AC_DEFINE_UNQUOTED($i)
	    done
#	    if test "${ARCH}" = "X86EM"; then
#		AC_DEFINE_UNQUOTED(_WIN32_WCE_EMULATION)
#	    fi
	    AC_DEFINE_UNQUOTED(_WIN32_WCE, $CEVERSION)
	    AC_DEFINE_UNQUOTED(UNDER_CE, $CEVERSION)
	    CFLAGS_DEBUG="-nologo -Zi -Od"
	    CFLAGS_OPTIMIZE="-nologo -O2"
	    lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'`
	    lflags="-nodefaultlib -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo"
	    LINKBIN="\"${CEBINROOT}/link.exe\""
	    AC_SUBST(CELIB_DIR)
	    if test "${CEVERSION}" -lt 400 ; then
		LIBS="coredll.lib corelibc.lib winsock.lib"
	    else
		LIBS="coredll.lib corelibc.lib ws2.lib"
	    fi
	    # celib currently stuck at wce300 status
	    #LIBS="$LIBS \${CELIB_DIR}/wince-${ARCH}-pocket-${OSVERSION}-release/celib.lib"
	    LIBS="$LIBS \"\${CELIB_DIR}/wince-${ARCH}-pocket-wce300-release/celib.lib\""
	    LIBS_GUI="commctrl.lib commdlg.lib"
	else
	LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib uuid.lib winspool.lib"
	    LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib uuid.lib"
	fi

	SHLIB_LD="${LINKBIN} -dll -incremental:no ${lflags}"
	SHLIB_LD_LIBS='${LIBS}'
	# link -lib only works when -lib is the first arg
	STLIB_LD="${LINKBIN} -lib ${lflags}"
	RC_OUT=-fo
	RC_TYPE=-r
870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893

894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911




912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

927
928
929
930

931
932
933
934



935
936
937
938
939
940



941




















942
943
944
945
946
947
948
949


950
951
952
953
954



955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989


990
991

992
993
994

995
996
997
998
999
1000
1001
989
990
991
992
993
994
995

996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026




1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047
1048

1049
1050



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128


1129
1130
1131

1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
1142







-
+















-
+














-
-
-
-
+
+
+
+














-
+



-
+

-
-
-
+
+
+






+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+
+


-
-
-
+
+
+












-




















-
-
+
+

-
+


-
+








	# Specify the CC output file names based on the target name
	CC_OBJNAME="-Fo\[$]@"
	CC_EXENAME="-Fe\"\$(shell \$(CYGPATH) '\[$]@')\""

	# Specify linker flags depending on the type of app being
	# built -- Console vs. Window.
	if test "${TARGETCPU}" != "X86"; then
	if test "$doWince" != "no" -a "${TARGETCPU}" != "X86"; then
	    LDFLAGS_CONSOLE="-link ${lflags}"
	    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
	else
	    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
	    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
	fi
    fi

    if test "$do64bit" != "no" ; then
	AC_DEFINE(TCL_CFG_DO64BIT)
    fi

    if test "${GCC}" = "yes" ; then
	AC_CACHE_CHECK(for SEH support in compiler,
	    tcl_cv_seh,
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	AC_TRY_RUN([
	    #define WIN32_LEAN_AND_MEAN
	    #include <windows.h>
	    #undef WIN32_LEAN_AND_MEAN

	    int main(int argc, char** argv) {
		int a, b = 0;
		__try {
		    a = 666 / b;
		}
		__except (EXCEPTION_EXECUTE_HANDLER) {
		    return 0;
		}
		return 1;
	    }
	]])],
	    [tcl_cv_seh=yes],
	    [tcl_cv_seh=no],
	    [tcl_cv_seh=no])
	],
	    tcl_cv_seh=yes,
	    tcl_cv_seh=no,
	    tcl_cv_seh=no)
	)
	if test "$tcl_cv_seh" = "no" ; then
	    AC_DEFINE(HAVE_NO_SEH, 1,
		    [Defined when mingw does not support SEH])
	fi

	#
	# Check to see if the excpt.h include file provided contains the
	# definition for EXCEPTION_DISPOSITION; if not, which is the case
	# with Cygwin's version as of 2002-04-10, define it to be int,
	# sufficient for getting the current code to work.
	#
	AC_CACHE_CHECK(for EXCEPTION_DISPOSITION support in include files,
	    tcl_cv_eh_disposition,
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	    AC_TRY_COMPILE([
#	    define WIN32_LEAN_AND_MEAN
#	    include <windows.h>
#	    undef WIN32_LEAN_AND_MEAN
	    ]], [[
	    ],[
		EXCEPTION_DISPOSITION x;
	    ]])],
		[tcl_cv_eh_disposition=yes],
		[tcl_cv_eh_disposition=no])
	    ],
		tcl_cv_eh_disposition=yes,
		tcl_cv_eh_disposition=no)
	)
	if test "$tcl_cv_eh_disposition" = "no" ; then
	AC_DEFINE(EXCEPTION_DISPOSITION, int,
		[Defined when cygwin/mingw does not support EXCEPTION DISPOSITION])
	fi

	# Check to see if winnt.h defines CHAR, SHORT, and LONG
	# even if VOID has already been #defined. The win32api
	# used by mingw and cygwin is known to do this.
	AC_CHECK_HEADER(stdbool.h, [AC_DEFINE(HAVE_STDBOOL_H, 1, [Do we have <stdbool.h>?])],)

	AC_CACHE_CHECK(for winnt.h that ignores VOID define,
	    tcl_cv_winnt_ignore_void,
	    AC_TRY_COMPILE([
		#define VOID void
		#define WIN32_LEAN_AND_MEAN
		#include <windows.h>
		#undef WIN32_LEAN_AND_MEAN
	    ], [
		CHAR c;
		SHORT s;
		LONG l;
	    ],
        tcl_cv_winnt_ignore_void=yes,
        tcl_cv_winnt_ignore_void=no)
	)
	if test "$tcl_cv_winnt_ignore_void" = "yes" ; then
	    AC_DEFINE(HAVE_WINNT_IGNORE_VOID, 1,
		    [Defined when cygwin/mingw ignores VOID define in winnt.h])
	fi

	# See if the compiler supports casting to a union type.
	# This is used to stop gcc from printing a compiler
	# warning when initializing a union member.

	AC_CACHE_CHECK(for cast to union support,
	    tcl_cv_cast_to_union,
	    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
	    AC_TRY_COMPILE([],
	    [
		  union foo { int i; double d; };
		  union foo f = (union foo) (int) 0;
	    ]])],
	    [tcl_cv_cast_to_union=yes],
	    [tcl_cv_cast_to_union=no])
	    ],
	    tcl_cv_cast_to_union=yes,
	    tcl_cv_cast_to_union=no)
	)
	if test "$tcl_cv_cast_to_union" = "yes"; then
	    AC_DEFINE(HAVE_CAST_TO_UNION, 1,
		    [Defined when compiler supports casting to union type.])
	fi
    fi

    # DL_LIBS is empty, but then we match the Unix version
    AC_SUBST(DL_LIBS)
    AC_SUBST(CFLAGS_DEBUG)
    AC_SUBST(CFLAGS_OPTIMIZE)
    AC_SUBST(CFLAGS_WARNING)
    AC_SUBST(CFLAGS_NOLTO)
])

#------------------------------------------------------------------------
# SC_WITH_TCL --
#
#	Location of the Tcl build directory.
#
# Arguments:
#	none
#
# Results:
#
#	Adds the following arguments to configure:
#		--with-tcl=...
#
#	Defines the following vars:
#		TCL_BIN_DIR	Full path to the tcl build dir.
#------------------------------------------------------------------------

AC_DEFUN([SC_WITH_TCL], [
    if test -d ../../tcl9.0$1/win;  then
	TCL_BIN_DEFAULT=../../tcl9.0$1/win
    if test -d ../../tcl8.7$1/win;  then
	TCL_BIN_DEFAULT=../../tcl8.7$1/win
    else
	TCL_BIN_DEFAULT=../../tcl9.0/win
	TCL_BIN_DEFAULT=../../tcl8.7/win
    fi

    AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 9.0 binaries from DIR],
    AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.7 binaries from DIR],
	    TCL_BIN_DIR=$withval, TCL_BIN_DIR=`cd $TCL_BIN_DEFAULT; pwd`)
    if test ! -d $TCL_BIN_DIR; then
	AC_MSG_ERROR(Tcl directory $TCL_BIN_DIR does not exist)
    fi
    if test ! -f $TCL_BIN_DIR/Makefile; then
	AC_MSG_ERROR(There is no Makefile in $TCL_BIN_DIR:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?)
    else
1016
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167
1168
1169
1170
1171







-
+







#	extension can't assume that an executable Tcl shell exists at
#	build time.
#
# Arguments
#	none
#
# Results
#	Substitutes the following values:
#	Subst's the following values:
#		TCLSH_PROG
#------------------------------------------------------------------------

AC_DEFUN([SC_PROG_TCLSH], [
    AC_MSG_CHECKING([for tclsh])

    AC_CACHE_VAL(ac_cv_path_tclsh, [
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075

1076
1077
1078
1079
1080
1081
1082
1203
1204
1205
1206
1207
1208
1209

1210
1211
1212
1213
1214
1215

1216
1217
1218
1219
1220
1221
1222
1223







-
+





-
+







#	when running tests from an extension build directory. It is not
#	correct to use the TCLSH_PROG in cases like this.
#
# Arguments
#	none
#
# Results
#	Substitutes the following values:
#	Subst's the following values:
#		BUILD_TCLSH
#------------------------------------------------------------------------

AC_DEFUN([SC_BUILD_TCLSH], [
    AC_MSG_CHECKING([for tclsh in Tcl build directory])
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}\${EXESUFFIX}
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}
    AC_MSG_RESULT($BUILD_TCLSH)
    AC_SUBST(BUILD_TCLSH)
])

#--------------------------------------------------------------------
# SC_TCL_CFG_ENCODING	TIP #59
#
1096
1097
1098
1099
1100
1101
1102

1103

1104
1105
1106
1107
1108
1109
1110
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1252







+
-
+








AC_DEFUN([SC_TCL_CFG_ENCODING], [
    AC_ARG_WITH(encoding, [  --with-encoding         encoding for configuration values], with_tcencoding=${withval})

    if test x"${with_tcencoding}" != x ; then
	AC_DEFINE_UNQUOTED(TCL_CFGVAL_ENCODING,"${with_tcencoding}")
    else
	# Default encoding on windows is not "iso8859-1"
	AC_DEFINE(TCL_CFGVAL_ENCODING,"utf-8")
	AC_DEFINE(TCL_CFGVAL_ENCODING,"cp1252")
    fi
])

#--------------------------------------------------------------------
# SC_EMBED_MANIFEST
#
#	Figure out if we can embed the manifest where necessary
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129
1130
1131
1132
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274







-
+







#		VC_MANIFEST_EMBED_EXE
#
#--------------------------------------------------------------------

AC_DEFUN([SC_EMBED_MANIFEST], [
    AC_MSG_CHECKING(whether to embed manifest)
    AC_ARG_ENABLE(embedded-manifest,
	AS_HELP_STRING([--enable-embedded-manifest],
	AC_HELP_STRING([--enable-embedded-manifest],
		[embed manifest if possible (default: yes)]),
	[embed_ok=$enableval], [embed_ok=yes])

    VC_MANIFEST_EMBED_DLL=
    VC_MANIFEST_EMBED_EXE=
    result=no
    if test "$embed_ok" = "yes" -a "${SHARED_BUILD}" = "1" \
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1293
1294
1295
1296
1297
1298
1299


































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
	fi
	])
    fi
    AC_MSG_RESULT([$result])
    AC_SUBST(VC_MANIFEST_EMBED_DLL)
    AC_SUBST(VC_MANIFEST_EMBED_EXE)
])

#------------------------------------------------------------------------
# SC_CC_FOR_BUILD
#	For cross compiles, locate a C compiler that can generate native binaries.
#
# Arguments:
#	none
#
# Results:
#	Substitutes the following vars:
#		CC_FOR_BUILD
#		EXEEXT_FOR_BUILD
#------------------------------------------------------------------------

dnl Get a default for CC_FOR_BUILD to put into Makefile.
AC_DEFUN([AX_CC_FOR_BUILD],
[# Put a plausible default for CC_FOR_BUILD in Makefile.
if test -z "$CC_FOR_BUILD"; then
  if test "x$cross_compiling" = "xno"; then
    CC_FOR_BUILD='$(CC)'
  else
    AC_MSG_CHECKING([for gcc])
    AC_CACHE_VAL(ac_cv_path_cc, [
	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do
	    for j in `ls -r $dir/gcc 2> /dev/null` \
		    `ls -r $dir/gcc 2> /dev/null` ; do
		if test x"$ac_cv_path_cc" = x ; then
		    if test -f "$j" ; then
			ac_cv_path_cc=$j
			break
		    fi
		fi
	    done
	done
    ])
  fi
fi
AC_SUBST(CC_FOR_BUILD)
# Also set EXEEXT_FOR_BUILD.
if test "x$cross_compiling" = "xno"; then
  EXEEXT_FOR_BUILD='$(EXEEXT)'
  OBJEXT_FOR_BUILD='$(OBJEXT)'
else
  OBJEXT_FOR_BUILD='.no'
  AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext,
    [rm -f conftest*
     echo 'int main () { return 0; }' > conftest.c
     bfd_cv_build_exeext=
     ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5
     for file in conftest.*; do
       case $file in
       *.c | *.o | *.obj | *.ilk | *.pdb) ;;
       *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;;
       esac
     done
     rm -f conftest*
     test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no])
  EXEEXT_FOR_BUILD=""
  test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext}
fi
AC_SUBST(EXEEXT_FOR_BUILD)])dnl
AC_SUBST(OBJEXT_FOR_BUILD)])dnl



#------------------------------------------------------------------------
# SC_ZIPFS_SUPPORT
#	Locate a zip encoder installed on the system path, or none.
#
# Arguments:
#	none
#
# Results:
#	Substitutes the following vars:
#		ZIP_PROG
#       ZIP_PROG_OPTIONS
#       ZIP_PROG_VFSSEARCH
#       ZIP_INSTALL_OBJS
#------------------------------------------------------------------------

AC_DEFUN([SC_ZIPFS_SUPPORT], [
    ZIP_PROG=""
    ZIP_PROG_OPTIONS=""
    ZIP_PROG_VFSSEARCH=""
    ZIP_INSTALL_OBJS=""

    AC_MSG_CHECKING([for zip])
    AC_CACHE_VAL(ac_cv_path_zip, [
    search_path=`echo ${PATH} | sed -e 's/:/ /g'`
    for dir in $search_path ; do
        for j in `ls -r $dir/zip 2> /dev/null` \
            `ls -r $dir/zip 2> /dev/null` ; do
        if test x"$ac_cv_path_zip" = x ; then
            if test -f "$j" ; then
            ac_cv_path_zip=$j
            break
            fi
        fi
        done
    done
    ])
    if test -f "$ac_cv_path_zip" ; then
        ZIP_PROG="$ac_cv_path_zip"
        AC_MSG_RESULT([$ZIP_PROG])
        ZIP_PROG_OPTIONS="-rq"
        ZIP_PROG_VFSSEARCH="*"
        AC_MSG_RESULT([Found INFO Zip in environment])
        # Use standard arguments for zip
    else
        # It is not an error if an installed version of Zip can't be located.
        # We can use the locally distributed minizip instead
        ZIP_PROG="./minizip${EXEEXT_FOR_BUILD}"
        ZIP_PROG_OPTIONS="-o -r"
        ZIP_PROG_VFSSEARCH="*"
        ZIP_INSTALL_OBJS="minizip${EXEEXT_FOR_BUILD}"
        AC_MSG_RESULT([No zip found on PATH building minizip])
    fi
    AC_SUBST(ZIP_PROG)
    AC_SUBST(ZIP_PROG_OPTIONS)
    AC_SUBST(ZIP_PROG_VFSSEARCH)
    AC_SUBST(ZIP_INSTALL_OBJS)
])

Changes to win/tkConfig.sh.in.

21
22
23
24
25
26
27
28
29
30


31
32
33
34
35
36
37
38

39
40
41
42

43
44
45
46

47
48
49
50
51
52
53
21
22
23
24
25
26
27



28
29
30
31
32
33
34
35
36

37
38
39
40

41
42
43
44

45
46
47
48
49
50
51
52







-
-
-
+
+







-
+



-
+



-
+








# -D flags for use with the C compiler.
TK_DEFS='@DEFS@'

# Flag, 1: we built a shared lib, 0 we didn't
TK_SHARED_BUILD=@TK_SHARED_BUILD@

# TK_DBGX used to be used to distinguish debug vs. non-debug builds.
# This was a righteous pain so the core doesn't do that any more.
TK_DBGX=
# This indicates if Tk was build with debugging symbols
TK_DBGX=@TK_DBGX@

# The name of the Tk library (may be either a .a file or a shared library):
TK_LIB_FILE='@TK_LIB_FILE@'

# Additional libraries to use when linking Tk.
TK_LIBS='@LIBS@ @LIBS_GUI@'

# Top-level directory in which Tk's platform-independent files are
# Top-level directory in which Tcl's platform-independent files are
# installed.
TK_PREFIX='@prefix@'

# Top-level directory in which Tk's platform-specific files (e.g.
# Top-level directory in which Tcl's platform-specific files (e.g.
# executables) are installed.
TK_EXEC_PREFIX='@exec_prefix@'

# -l flag to pass to the linker to pick up the Tk library
# -l flag to pass to the linker to pick up the Tcl library
TK_LIB_FLAG='@TK_LIB_FLAG@'

# String to pass to linker to pick up the Tk library from its
# build directory.
TK_BUILD_LIB_SPEC='@TK_BUILD_LIB_SPEC@'

# String to pass to linker to pick up the Tk library from its

Deleted win/tkUuid.h.in.

1

-
#define TK_VERSION_UUID \

Changes to win/tkWin.h.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24



25
26

27
28
29

30
31
32

33
34
35
36
37
38
39
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20

21

22
23
24
25
26
27

28
29
30

31
32
33

34
35
36
37
38
39
40
41






-
+













-
+
-


+
+
+

-
+


-
+


-
+







/*
 * tkWin.h --
 *
 *	Declarations of public types and interfaces that are only
 *	available under Windows.
 *
 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKWIN
#define _TKWIN

/*
 * We must specify the lower version we intend to support. In particular
 * the SystemParametersInfo API doesn't like to receive structures that
 * are larger than it expects which affects the font assignments.
 *
 * WINVER = 0x0600 means Windows Vista and above. Even though we still
 * NTDDI_VERSION = 0x0600 means Windows Vista and above
 * support Windows XP, but the Vista-specifics are tested at runtime.
 */

#ifndef NTDDI_VERSION
#define NTDDI_VERSION 0x06000000
#endif
#ifndef WINVER
#   define WINVER 0x0601
#define WINVER 0x0600
#endif
#ifndef _WIN32_WINNT
#   define _WIN32_WINNT 0x0601
#define _WIN32_WINNT 0x0600
#endif
#ifndef _WIN32_IE
#   define _WIN32_IE 0x0800
#define _WIN32_IE 0x0600
#endif

#ifndef _TK
#include <tk.h>
#endif

#define WIN32_LEAN_AND_MEAN

Changes to win/tkWin32Dll.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkWin32Dll.c --
 *
 *	This file contains a stub dll entry point.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#ifndef STATIC_BUILD
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127

128
129
130
131
132
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
97
98
99
100
101
102
103

104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
125

126


127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160







-
+


-















-
+



-
+
-
-










-
+















-
+








BOOL APIENTRY
DllMain(
    HINSTANCE hInstance,
    DWORD reason,
    LPVOID reserved)
{
#if defined(HAVE_NO_SEH) && !defined(__aarch64__)
#ifdef HAVE_NO_SEH
    TCLEXCEPTION_REGISTRATION registration;
#endif
    (void)reserved;

    /*
     * If we are attaching to the DLL from a new process, tell Tk about the
     * hInstance to use.
     */

    switch (reason) {
    case DLL_PROCESS_ATTACH:
	DisableThreadLibraryCalls(hInstance);
	TkWinSetHINSTANCE(hInstance);
	break;

    case DLL_PROCESS_DETACH:
	/*
	 * Protect the call to TkFinalize in an SEH block. We can't be
	 * guaranteed Tk is always being unloaded from a stable condition.
	 * guarenteed Tk is always being unloaded from a stable condition.
	 */

#ifdef HAVE_NO_SEH
#   if defined(__aarch64__)
#   ifdef __WIN64
	/* Don't run TkFinalize(NULL) on mingw-w64 for ARM64, since we don't have corresponding assembler-code. */
#   elif defined(_WIN64)
	__asm__ __volatile__ (

	    /*
	     * Construct an TCLEXCEPTION_REGISTRATION to protect the call to
	     * TkFinalize
	     */

	    "leaq	%[registration], %%rdx"		"\n\t"
	    "movq	%%gs:0,		%%rax"		"\n\t"
	    "movq	%%rax,		0x0(%%rdx)"	"\n\t" /* link */
	    "leaq	1f(%%rip),	%%rax"		"\n\t"
	    "leaq	1f,		%%rax"		"\n\t"
	    "movq	%%rax,		0x8(%%rdx)"	"\n\t" /* handler */
	    "movq	%%rbp,		0x10(%%rdx)"	"\n\t" /* rbp */
	    "movq	%%rsp,		0x18(%%rdx)"	"\n\t" /* rsp */
	    "movl	%[error],	0x20(%%rdx)"	"\n\t" /* status */

	    /*
	     * Link the TCLEXCEPTION_REGISTRATION on the chain
	     */

	    "movq	%%rdx,		%%gs:0"		"\n\t"

	    /*
	     * Call TkFinalize
	     */

	    "movq	$0x0,		0x0(%%rsp)"		"\n\t"
	    "movq	$0x0,		0x0(%%esp)"		"\n\t"
	    "call	TkFinalize"			"\n\t"

	    /*
	     * Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION
	     * and store a TCL_OK status
	     */

Changes to win/tkWin3d.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkWin3d.c --
 *
 *	This file contains the platform specific routines for drawing 3D
 *	borders in the Windows 95 style.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "tk3d.h"
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







 *
 *----------------------------------------------------------------------
 */

TkBorder *
TkpGetBorder(void)
{
    WinBorder *borderPtr = (WinBorder *)ckalloc(sizeof(WinBorder));
    WinBorder *borderPtr = ckalloc(sizeof(WinBorder));

    borderPtr->light2ColorPtr = NULL;
    borderPtr->dark2ColorPtr = NULL;
    return (TkBorder *) borderPtr;
}

/*
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137







-
+







    TkBorder *borderPtr = (TkBorder *) border;
    int left, right;
    Display *display = Tk_Display(tkwin);
    TkWinDCState state;
    HDC dc = TkWinGetDrawableDC(display, drawable, &state);
    int half;

    if ((borderPtr->lightGC == NULL) && (relief != TK_RELIEF_FLAT)) {
    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    switch (relief) {
    case TK_RELIEF_RAISED:
	left = (leftBevel)
		? borderPtr->lightGC->foreground
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232







-
+







    TkBorder *borderPtr = (TkBorder *) border;
    Display *display = Tk_Display(tkwin);
    int bottom, halfway, x1, x2, x1Delta, x2Delta;
    TkWinDCState state;
    HDC dc = TkWinGetDrawableDC(display, drawable, &state);
    int topColor, bottomColor;

    if ((borderPtr->lightGC == NULL) && (relief != TK_RELIEF_FLAT)) {
    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    /*
     * Compute a GC for the top half of the bevel and a GC for the bottom half
     * (they're the same in many cases).
     */
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349







-
+







				 * drawing. */
{
    XColor lightColor, darkColor;
    int tmp1, tmp2;
    int r, g, b;
    XGCValues gcValues;

    if (borderPtr->lightGC != NULL) {
    if (borderPtr->lightGC != None) {
	return;
    }

    /*
     * Handle the special case of the default system colors.
     */

536
537
538
539
540
541
542
543

544
545
546
547
548
549
550
536
537
538
539
540
541
542

543
544
545
546
547
548
549
550







-
+







    Tk_Window tkwin,
    Tk_3DBorder border,
    int which)			/* One of TK_3D_FLAT_GC, TK_3D_LIGHT_GC,
				 * TK_3D_DARK_GC, TK_3D_LIGHT2, TK_3D_DARK2 */
{
    WinBorder *borderPtr = (WinBorder *) border;

    if (borderPtr->info.lightGC == NULL) {
    if (borderPtr->info.lightGC == None) {
	TkpGetShadows(&borderPtr->info, tkwin);
    }
    switch (which) {
    case TK_3D_FLAT_GC:
	return borderPtr->info.bgColorPtr->pixel;
    case TK_3D_LIGHT_GC:
	if (borderPtr->info.lightColorPtr == NULL) {

Changes to win/tkWinButton.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkWinButton.c --
 *
 *	This file implements the Windows specific portion of the button
 *	widgets.
 *
 * Copyright © 1996-1998 Sun Microsystems, Inc.
 * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#define OEMRESOURCE
#include "tkWinInt.h"
32
33
34
35
36
37
38






















39



40
41
42

43
44





45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140







141
142
143
144
145
146

147
148
149
150
151
152

153









154
155
156
157
158
159






























160
161
162
163
164
165
166
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65

66


67
68
69
70
71
72
73
74
75


























































76
77
78
79
80
81


82
83






84
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101


102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132




133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+


-
+
-
-
+
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
-
+
+
-
-
-
-
-
-









-
+








-
-
+
+
+
+
+
+
+





-
+





-
+

+
+
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    WNDPROC oldProc;		/* Old window procedure. */
    HWND hwnd;			/* Current window handle. */
    Pixmap pixmap;		/* Bitmap for rendering the button. */
    DWORD style;		/* Window style flags. */
} WinButton;

/*
 * The following macro reverses the order of RGB bytes to convert between
 * RGBQUAD and COLORREF values.
 */

#define FlipColor(rgb) (RGB(GetBValue(rgb),GetGValue(rgb),GetRValue(rgb)))

/*
 * The following enumeration defines the meaning of the palette entries in the
 * "buttons" image used to draw checkbox and radiobutton indicators.
 */

enum {
    PAL_CHECK = 0,
    PAL_TOP_OUTER = 1,
    PAL_BOTTOM_OUTER = 2,
    PAL_BOTTOM_INNER = 3,
    PAL_INTERIOR = 4,
    PAL_TOP_INNER = 5,
    PAL_BACKGROUND = 6
};

/*
 * Cached information about the checkbutton and radiobutton indicator boxes
 * Cached information about the boxes bitmap, and the default border width for
 * a button in string form for use in Tk_OptionSpec for the various button
 * widget classes.
 */

typedef struct {
typedef struct ThreadSpecificData {
    BOOLEAN initialized;
    int boxSize;		/* Width & height of the box. */
    BITMAPINFOHEADER *boxesPtr;	/* Information about the bitmap. */
    DWORD *boxesPalette;	/* Pointer to color palette. */
    LPSTR boxesBits;		/* Pointer to bitmap data. */
    DWORD boxHeight;		/* Height of each sub-image. */
    DWORD boxWidth;		/* Width of each sub-image. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Data of the SVG images used for drawing the indicators
 */

static const char checkbtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <path d='m0 0v15h1v-14h14v-1z' fill='#a0a0a0'/>\n\
     <path d='m1 1v13h1v-12h12v-1z' fill='#696969'/>\n\
     <path d='m14 1v13h-13v1h14v-14z' fill='#e3e3e3'/>\n\
     <path d='m15 0v15h-15v1h16v-16z' fill='#eeeeee'/>\n\
     <rect x='2' y='2' width='12' height='12' fill='#ffffff'/>\n\
    </svg>";

static const char checkbtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <path d='m0 0v15h1v-14h14v-1z' fill='#a0a0a0'/>\n\
     <path d='m1 1v13h1v-12h12v-1z' fill='#696969'/>\n\
     <path d='m14 1v13h-13v1h14v-14z' fill='#e3e3e3'/>\n\
     <path d='m15 0v15h-15v1h16v-16z' fill='#eeeeee'/>\n\
     <rect x='2' y='2' width='12' height='12' fill='#ffffff'/>\n\
     <path d='m4.5 8 3 3 4-6' fill='none' stroke='#000000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/>\n\
    </svg>";

static const char radiobtnOffData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradientOuter' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#a0a0a0' offset='0'/>\n\
       <stop stop-color='#eeeeee' offset='1'/>\n\
      </linearGradient>\n\
      <linearGradient id='linearGradientInner' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#696969' offset='0'/>\n\
       <stop stop-color='#e3e3e3' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradientOuter)'/>\n\
     <circle cx='8' cy='8' r='7' fill='url(#linearGradientInner)'/>\n\
     <circle cx='8' cy='8' r='6' fill='#ffffff'/>\n\
    </svg>";

static const char radiobtnOnData[] = "\
    <svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
     <defs>\n\
      <linearGradient id='linearGradientOuter' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#a0a0a0' offset='0'/>\n\
       <stop stop-color='#eeeeee' offset='1'/>\n\
      </linearGradient>\n\
      <linearGradient id='linearGradientInner' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
       <stop stop-color='#696969' offset='0'/>\n\
       <stop stop-color='#e3e3e3' offset='1'/>\n\
      </linearGradient>\n\
     </defs>\n\
     <circle cx='8' cy='8' r='8' fill='url(#linearGradientOuter)'/>\n\
     <circle cx='8' cy='8' r='7' fill='url(#linearGradientInner)'/>\n\
     <circle cx='8' cy='8' r='6' fill='#ffffff'/>\n\
     <circle cx='8' cy='8' r='3' fill='#000000'/>\n\
    </svg>";

/*
 * Declarations for functions defined in this file.
 */

static LRESULT CALLBACK	ButtonProc(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam);
static Window		CreateProc(Tk_Window tkwin, Window parent,
			    void *instanceData);
static void		InitBoxes(Tk_Window tkwin);
			    ClientData instanceData);
static void		InitBoxes(void);
static void		ColorToStr(COLORREF color, char *colorStr);
static void		ImageChanged(void *clientData,
			    int x, int y, int width, int height,
			    int imageWidth, int imageHeight);
static void		TkpDrawIndicator(TkButton *butPtr, Drawable d,
			    Tk_3DBorder border, GC gc, int dim, int x, int y);

/*
 * The class procedure table for the button widgets.
 */

const Tk_ClassProcs tkpButtonProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    TkButtonWorldChanged,	/* worldChangedProc */
    CreateProc,			/* createProc */
    NULL			/* modalProc */
    NULL					/* modalProc */
};


/*
 *----------------------------------------------------------------------
 *
 * InitBoxes --
 *
 *	This function computes the size of the checkbutton and radiobutton
 *	indicator boxes, according to the display's scaling percentage.
 *	This function load the Tk 3d button bitmap. "buttons" is a 16 color
 *	bitmap that is laid out such that the top row contains the 4 checkbox
 *	images, and the bottom row contains the radio button images. Note that
 *	the bitmap is stored in bottom-up format. Also, the first seven
 *	palette entries are used to identify the different parts of the
 *	bitmaps so we can do the appropriate color mappings based on the
 *	current button colors.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Populates the thread-private data.
 *	Loads the "buttons" resource.
 *
 *----------------------------------------------------------------------
 */

static void
InitBoxes(Tk_Window tkwin)
InitBoxes(void)
{
    /*
     * For DLLs like Tk, the HINSTANCE is the same as the HMODULE.
     */

    HMODULE module = (HINSTANCE) Tk_GetHINSTANCE();
    HRSRC hrsrc;
    HGLOBAL hblk;
    LPBITMAPINFOHEADER newBitmap;
    DWORD size;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    double scalingLevel = TkScalingLevel(tkwin);

    tsdPtr->boxSize = (int)(16.0 * scalingLevel);
    tsdPtr->initialized = TRUE;

    hrsrc = FindResource(module, TEXT("buttons"), RT_BITMAP);
    if (hrsrc == NULL) {
	Tcl_Panic("FindResource() failed for buttons bitmap resource, "
            "resources in tk_base.rc must be linked into Tk dll or static executable");
    } else {
	hblk = LoadResource(module, hrsrc);
	tsdPtr->boxesPtr = (LPBITMAPINFOHEADER)LockResource(hblk);
    }

    /*
     * Copy the DIBitmap into writable memory.
     */

    if (tsdPtr->boxesPtr != NULL && !(tsdPtr->boxesPtr->biWidth % 4)
	    && !(tsdPtr->boxesPtr->biHeight % 2)) {
	size = tsdPtr->boxesPtr->biSize + (1 << tsdPtr->boxesPtr->biBitCount)
		* sizeof(RGBQUAD) + tsdPtr->boxesPtr->biSizeImage;
	newBitmap = ckalloc(size);
	memcpy(newBitmap, tsdPtr->boxesPtr, size);
	tsdPtr->boxesPtr = newBitmap;
	tsdPtr->boxWidth = tsdPtr->boxesPtr->biWidth / 4;
	tsdPtr->boxHeight = tsdPtr->boxesPtr->biHeight / 2;
	tsdPtr->boxesPalette = (DWORD*) (((LPSTR) tsdPtr->boxesPtr)
		+ tsdPtr->boxesPtr->biSize);
	tsdPtr->boxesBits = ((LPSTR) tsdPtr->boxesPalette)
	    + ((1 << tsdPtr->boxesPtr->biBitCount) * sizeof(RGBQUAD));
    } else {
	tsdPtr->boxesPtr = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpButtonSetDefaults --
 *
174
175
176
177
178
179
180
181

182
183
184
185

186
187
188
189
190
191
192
177
178
179
180
181
182
183

184
185
186
187

188
189
190
191
192
193
194
195







-
+



-
+







 * Side effects:
 *	Updates some of.
 *
 *----------------------------------------------------------------------
 */

void
TkpButtonSetDefaults(void)
TkpButtonSetDefaults()
{
    int width = GetSystemMetrics(SM_CXEDGE);
	if (width > 0) {
	    snprintf(tkDefButtonBorderWidth, sizeof(tkDefButtonBorderWidth), "%d", width);
	    sprintf(tkDefButtonBorderWidth, "%d", width);
	}
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCreateButton --
200
201
202
203
204
205
206
207

208
209
210
211

212
213
214
215
216
217
218
203
204
205
206
207
208
209

210
211
212
213

214
215
216
217
218
219
220
221







-
+



-
+







 *	Registers an event handler for the widget.
 *
 *----------------------------------------------------------------------
 */

TkButton *
TkpCreateButton(
    TCL_UNUSED(Tk_Window))
    Tk_Window tkwin)
{
    WinButton *butPtr;

    butPtr = (WinButton *)ckalloc(sizeof(WinButton));
    butPtr = ckalloc(sizeof(WinButton));
    butPtr->hwnd = NULL;
    return (TkButton *) butPtr;
}

/*
 *----------------------------------------------------------------------
 *
230
231
232
233
234
235
236
237

238
239
240
241

242
243
244
245
246

247
248
249

250
251
252

253
254
255
256
257

258
259
260
261
262
263
264
233
234
235
236
237
238
239

240
241
242
243

244
245
246
247
248

249
250
251

252
253
254

255
256
257
258
259

260
261
262
263
264
265
266
267







-
+



-
+




-
+


-
+


-
+




-
+







 *----------------------------------------------------------------------
 */

static Window
CreateProc(
    Tk_Window tkwin,		/* Token for window. */
    Window parentWin,		/* Parent of new window. */
    void *instanceData)		/* Button instance data. */
    ClientData instanceData)	/* Button instance data. */
{
    Window window;
    HWND parent;
    LPCWSTR windowClass;
    const TCHAR *class;
    WinButton *butPtr = (WinButton *)instanceData;

    parent = Tk_GetHWND(parentWin);
    if (butPtr->info.type == TYPE_LABEL) {
	windowClass = L"STATIC";
	class = TEXT("STATIC");
	butPtr->style = SS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
    } else {
	windowClass = L"BUTTON";
	class = TEXT("BUTTON");
	butPtr->style = BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
    }
    butPtr->hwnd = CreateWindowW(windowClass, NULL, butPtr->style,
    butPtr->hwnd = CreateWindow(class, NULL, butPtr->style,
	    Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
	    parent, NULL, Tk_GetHINSTANCE(), NULL);
    SetWindowPos(butPtr->hwnd, HWND_TOP, 0, 0, 0, 0,
		    SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
    butPtr->oldProc = (WNDPROC)SetWindowLongPtrW(butPtr->hwnd, GWLP_WNDPROC,
    butPtr->oldProc = (WNDPROC)SetWindowLongPtr(butPtr->hwnd, GWLP_WNDPROC,
	    (LONG_PTR) ButtonProc);

    window = Tk_AttachHWND(tkwin, butPtr->hwnd);
    return window;
}

/*
281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
284
285
286
287
288
289
290

291
292






























































































































































































































293
294
295
296
297
298
299







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







TkpDestroyButton(
    TkButton *butPtr)
{
    WinButton *winButPtr = (WinButton *)butPtr;
    HWND hwnd = winButPtr->hwnd;

    if (hwnd) {
	SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR) winButPtr->oldProc);
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) winButPtr->oldProc);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ColorToStr --
 *
 *	Writes a given color to a string, in the format "RRGGBB".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes the content of the memory area pointed to by the 2nd argument.
 *
 *----------------------------------------------------------------------
 */

static void
ColorToStr(
    COLORREF color,	/* specifies a color */
    char *colorStr)	/* memory area to which the color is to be
			   output in the format "RRGGBB" */
{
    snprintf(colorStr, 7, "%02x%02x%02x",
	     GetRValue(color), GetGValue(color), GetBValue(color));
}

/*
 *----------------------------------------------------------------------
 *
 * ImageChanged --
 *
 *	Dummy function to be passed to Tk_GetImage().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
ImageChanged(
    void *clientData,
    int x, int y, int width, int height,
    int imageWidth, int imageHeight)
{
    (void)clientData;
    (void)x; (void)y; (void)width; (void)height;
    (void)imageWidth; (void)imageHeight;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDrawIndicator -
 *
 *      Draws the indicator image in the drawable at the (x,y) location.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      An image is drawn in the drawable at the given location.
 *
 *----------------------------------------------------------------------
 */

static void
TkpDrawIndicator(
    TkButton *butPtr,		/* checkbutton or radiobutton */
    Drawable d,			/* what to draw on */
    Tk_3DBorder border,		/* colors of the border */
    GC gc,			/* graphics context */
    int dim,			/* width & height of the indicator */
    int x, int y)		/* where to draw */
{
    Tk_Window tkwin = butPtr->tkwin;
    char topOuterColorStr[7], btmOuterColorStr[7], topInnerColorStr[7],
	 btmInnerColorStr[7], interiorColorStr[7], checkColorStr[7];
    Tcl_Interp *interp = Tk_Interp(tkwin);
    char imgName[80];
    Tk_Image img;
    const char *svgDataPtr;
    size_t svgDataLen;
    char *svgDataCopy;
    char *topOuterColorPtr, *btmOuterColorPtr, *topInnerColorPtr,
	 *btmInnerColorPtr, *interiorColorPtr, *checkColorPtr;
    const char *cmdFmt;
    size_t scriptSize;
    char *script;
    int code;

    /*
     * Construct the color strings topOuterColorStr, btmOuterColorStr,
     * topInnerColorStr, btmInnerColorStr, interiorColorStr, and checkColorStr
     */

    ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_DARK_GC),
	       topOuterColorStr);
    ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_LIGHT_GC),
	       btmOuterColorStr);
    ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_DARK2),
	       topInnerColorStr);
    ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_LIGHT2),
	       btmInnerColorStr);

    if (butPtr->state == STATE_ACTIVE) {
	ColorToStr(TkWinGetBorderPixels(tkwin, butPtr->activeBorder,
		   TK_3D_FLAT_GC), interiorColorStr);
    } else if (butPtr->state == STATE_DISABLED || (butPtr->flags & TRISTATED)) {
	ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_LIGHT2),
		   interiorColorStr);
    } else if (butPtr->selectBorder != NULL) {
	ColorToStr(TkWinGetBorderPixels(tkwin, butPtr->selectBorder,
		   TK_3D_FLAT_GC), interiorColorStr);
    } else {
	ColorToStr(GetSysColor(COLOR_WINDOW), interiorColorStr);
    }

    if (butPtr->state == STATE_DISABLED && butPtr->disabledFg == NULL) {
	ColorToStr(TkWinGetBorderPixels(tkwin, border, TK_3D_DARK_GC),
		   checkColorStr);
    } else {
	ColorToStr(gc->foreground, checkColorStr);
    }

    /*
    * Check whether there is an SVG image of this size for the indicator's
    * type (0 = checkbtn, 1 = radiobtn) and these color strings
    */

    snprintf(imgName, sizeof(imgName),
	     "::tk::icons::indicator%d_%d_%s_%s_%s_%s_%s_%s",
	     dim, butPtr->type == TYPE_RADIO_BUTTON,
	     topOuterColorStr, btmOuterColorStr, topInnerColorStr,
	     btmInnerColorStr, interiorColorStr,
	     (butPtr->flags & (SELECTED|TRISTATED)) ? checkColorStr : "XXXXXX");
    img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    if (img == NULL) {
	/*
	 * Determine the SVG data to use for the photo image
	 */

	if (butPtr->type == TYPE_CHECK_BUTTON) {
	    svgDataPtr = ((butPtr->flags & (SELECTED|TRISTATED)) ?
			  checkbtnOnData : checkbtnOffData);
	} else {
	    svgDataPtr = ((butPtr->flags & (SELECTED|TRISTATED)) ?
			  radiobtnOnData : radiobtnOffData);
	}

	/*
	 * Copy the string pointed to by svgDataPtr to
	 * a newly allocated memory area svgDataCopy
	 */

	svgDataLen = strlen(svgDataPtr);
	svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
	if (svgDataCopy == NULL) {
	    return;
	}
	memcpy(svgDataCopy, svgDataPtr, svgDataLen);
	svgDataCopy[svgDataLen] = '\0';

	/*
	 * Update the colors within svgDataCopy
	 */

	topOuterColorPtr = strstr(svgDataCopy, "a0a0a0");
	btmOuterColorPtr = strstr(svgDataCopy, "eeeeee");
	topInnerColorPtr = strstr(svgDataCopy, "696969");
	btmInnerColorPtr = strstr(svgDataCopy, "e3e3e3");
	interiorColorPtr = strstr(svgDataCopy, "ffffff");
	checkColorPtr =    strstr(svgDataCopy, "000000");

	assert(topOuterColorPtr);
	assert(btmOuterColorPtr);
	assert(topInnerColorPtr);
	assert(btmInnerColorPtr);
	assert(interiorColorPtr);

	memcpy(topOuterColorPtr, topOuterColorStr, 6);
	memcpy(btmOuterColorPtr, btmOuterColorStr, 6);
	memcpy(topInnerColorPtr, topInnerColorStr, 6);
	memcpy(btmInnerColorPtr, btmInnerColorStr, 6);
	memcpy(interiorColorPtr, interiorColorStr, 6);
	if (checkColorPtr != NULL) {
	    memcpy(checkColorPtr, checkColorStr, 6);
	}

	/*
	 * Create an SVG photo image from svgDataCopy
	 */

	cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
	scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
	script = (char *)attemptckalloc(scriptSize);
	if (script == NULL) {
	    ckfree(svgDataCopy);
	    return;
	}
	snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
	ckfree(svgDataCopy);
	code = Tcl_EvalEx(interp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	ckfree(script);
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	    return;
	}
	img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
    }

    /*
     * Display the image
     */

    Tk_RedrawImage(img, 0, 0, dim, dim, d, x, y);
    Tk_FreeImage(img);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDisplayButton --
 *
526
527
528
529
530
531
532
533

534
535
536
537

538
539
540
541
542
543
544

545
546
547
548
549
550
551
552
553
554
555
556
557
558

559
560
561
562

563
564
565
566
567
568
569
307
308
309
310
311
312
313

314
315
316
317

318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352







-
+



-
+






-
+














+




+







 *	Information appears on the screen. The REDRAW_PENDING flag is cleared.
 *
 *----------------------------------------------------------------------
 */

void
TkpDisplayButton(
    void *clientData)	/* Information about widget. */
    ClientData clientData)	/* Information about widget. */
{
    TkWinDCState state;
    HDC dc;
    TkButton *butPtr = (TkButton *)clientData;
    register TkButton *butPtr = (TkButton *) clientData;
    GC gc;
    Tk_3DBorder border;
    Pixmap pixmap;
    int x = 0;			/* Initialization only needed to stop compiler
				 * warning. */
    int y, relief;
    Tk_Window tkwin = butPtr->tkwin;
    register Tk_Window tkwin = butPtr->tkwin;
    int width = 0, height = 0, haveImage = 0, haveText = 0, drawRing = 0;
    RECT rect;
    int defaultWidth;		/* Width of default ring. */
    int offset;			/* 0 means this is a label widget. 1 means it
				 * is a flavor of button, so we offset the
				 * text to make the button appear to move up
				 * and down as the relief changes. */
    int textXOffset = 0, textYOffset = 0;
				/* Text offsets for use with compound buttons
				 * and focus ring. */
    int imageWidth, imageHeight;
    int imageXOffset = 0, imageYOffset = 0;
				/* Image information that will be used to
				 * restrict disabled pixmap as well. */
    DWORD *boxesPalette;

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

    boxesPalette= tsdPtr->boxesPalette;
    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
400
401
402
403
404
405
406

407



408
409
410
411
412
413
414







-
+
-
-
-







	}
    }

    /*
     * Compute width of default ring and offset for pushed buttons.
     */

    if (butPtr->type == TYPE_LABEL) {
    if (butPtr->type == TYPE_BUTTON) {
	defaultWidth = butPtr->highlightWidth;
        offset = 0;
    } else if (butPtr->type == TYPE_BUTTON) {
	defaultWidth = ((butPtr->defaultState == DEFAULT_ACTIVE)
		? butPtr->highlightWidth : 0);
	offset = 1;
    } else {
	defaultWidth = 0;
	if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
	    offset = 1;
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
429
430
431
432
433
434
435

436
437
438
439
440
441
442
443







-
+







    Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin),
	    Tk_Height(tkwin), 0, TK_RELIEF_FLAT);

    /*
     * Display image or bitmap or text for button.
     */

    if (butPtr->image != NULL) {
    if (butPtr->image != None) {
	Tk_SizeOfImage(butPtr->image, &width, &height);
	haveImage = 1;
    } else if (butPtr->bitmap != None) {
	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
	haveImage = 1;
    }
    imageWidth = width;
865
866
867
868
869
870
871
872
873


874
875
876
877



878
879
880





881











































882
883
884
885
886
887
888
645
646
647
648
649
650
651


652
653
654
655
656

657
658
659
660
661
662
663
664
665
666
667

668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717







-
-
+
+



-
+
+
+



+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	DrawFocusRect(dc, &rect);
	TkWinReleaseDrawableDC(pixmap, dc, &state);
    }

    y += height/2;

    /*
     * Draw the indicator for check buttons and radio buttons. At this point
     * x and y refer to the top-left corner of the text or image or bitmap.
     * Draw the indicator for check buttons and radio buttons. At this point x
     * and y refer to the top-left corner of the text or image or bitmap.
     */

    if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn
	    && tsdPtr->initialized) {
	    && tsdPtr->boxesPtr) {
	int xSrc, ySrc;

	x -= butPtr->indicatorSpace;
	y -= butPtr->indicatorDiameter / 2;

	xSrc = (butPtr->flags & (SELECTED|TRISTATED)) ? tsdPtr->boxWidth : 0;
	if (butPtr->state == STATE_ACTIVE) {
	    xSrc += tsdPtr->boxWidth*2;
	}
	ySrc = (butPtr->type == TYPE_RADIO_BUTTON) ? 0 : tsdPtr->boxHeight;
	TkpDrawIndicator(butPtr, pixmap, border, gc, tsdPtr->boxSize, x, y + 1);

	/*
	 * Update the palette in the boxes bitmap to reflect the current
	 * button colors. Note that this code relies on the layout of the
	 * bitmap's palette. Also, all of the colors used to draw the bitmap
	 * must be in the palette that is selected into the DC of the
	 * offscreen pixmap. This requires that the static colors be placed
	 * into the palette.
	 */

	if ((butPtr->state == STATE_DISABLED)
		&& (butPtr->disabledFg == NULL)) {
	    boxesPalette[PAL_CHECK] = FlipColor(TkWinGetBorderPixels(tkwin,
		    border, TK_3D_DARK_GC));
	} else {
	    boxesPalette[PAL_CHECK] = FlipColor(gc->foreground);
	}
	boxesPalette[PAL_TOP_OUTER] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_DARK_GC));
	boxesPalette[PAL_TOP_INNER] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_DARK2));
	boxesPalette[PAL_BOTTOM_INNER] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_LIGHT2));
	boxesPalette[PAL_BOTTOM_OUTER] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_LIGHT_GC));
	if ((butPtr->state == STATE_DISABLED) || (butPtr->flags & TRISTATED)) {
	    boxesPalette[PAL_INTERIOR] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_LIGHT2));
	} else if (butPtr->selectBorder != NULL) {
	    boxesPalette[PAL_INTERIOR] = FlipColor(TkWinGetBorderPixels(tkwin,
		    butPtr->selectBorder, TK_3D_FLAT_GC));
	} else {
	    boxesPalette[PAL_INTERIOR] = FlipColor(GetSysColor(COLOR_WINDOW));
	}
	boxesPalette[PAL_BACKGROUND] = FlipColor(TkWinGetBorderPixels(tkwin,
		border, TK_3D_FLAT_GC));

	dc = TkWinGetDrawableDC(butPtr->display, pixmap, &state);
	StretchDIBits(dc, x, y, (int)tsdPtr->boxWidth, (int)tsdPtr->boxHeight,
		xSrc, ySrc, (int)tsdPtr->boxWidth, (int)tsdPtr->boxHeight,
		tsdPtr->boxesBits, (LPBITMAPINFO) tsdPtr->boxesPtr,
		DIB_RGB_COLORS, SRCCOPY);
	TkWinReleaseDrawableDC(pixmap, dc, &state);
    }

    /*
     * If the button is disabled with a stipple rather than a special
     * foreground color, generate the stippled effect. If the widget is
     * selected and we use a different background color when selected, must
     * temporarily modify the GC so the stippling is the right color.
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

942
943

944
945
946

947
948
949

950
951
952
953
954
955
956
754
755
756
757
758
759
760


761





762

763
764

765
766
767

768
769
770

771
772
773
774
775
776
777
778







-
-

-
-
-
-
-

-
+

-
+


-
+


-
+







	Tk_Draw3DRectangle(tkwin, pixmap, border,
		defaultWidth, defaultWidth,
		Tk_Width(tkwin) - 2*defaultWidth,
		Tk_Height(tkwin) - 2*defaultWidth,
		butPtr->borderWidth, relief);
    }
    if (defaultWidth != 0) {
        int highlightColor;

	dc = TkWinGetDrawableDC(butPtr->display, pixmap, &state);
        if (butPtr->type == TYPE_LABEL) {
            highlightColor = (int) Tk_3DBorderColor(butPtr->highlightBorder)->pixel;
        } else {
            highlightColor = (int) butPtr->highlightColorPtr->pixel;
        }
	TkWinFillRect(dc, 0, 0, Tk_Width(tkwin), defaultWidth,
		highlightColor);
		(int) butPtr->highlightColorPtr->pixel);
	TkWinFillRect(dc, 0, 0, defaultWidth, Tk_Height(tkwin),
		highlightColor);
		(int) butPtr->highlightColorPtr->pixel);
	TkWinFillRect(dc, 0, Tk_Height(tkwin) - defaultWidth,
		Tk_Width(tkwin), defaultWidth,
		highlightColor);
		(int) butPtr->highlightColorPtr->pixel);
	TkWinFillRect(dc, Tk_Width(tkwin) - defaultWidth, 0,
		defaultWidth, Tk_Height(tkwin),
		highlightColor);
		(int) butPtr->highlightColorPtr->pixel);
	TkWinReleaseDrawableDC(pixmap, dc, &state);
    }

    if (butPtr->flags & GOT_FOCUS) {
	Tk_SetCaretPos(tkwin, x, y, 0 /* not used */);
    }

981
982
983
984
985
986
987
988

989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010


1011
1012
1013
1014
1015
1016
1017
803
804
805
806
807
808
809

810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830


831
832
833
834
835
836
837
838
839







-
+




















-
-
+
+







 *	The button's window may change size.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeButtonGeometry(
    TkButton *butPtr)	/* Button whose geometry may have changed. */
    register TkButton *butPtr)	/* Button whose geometry may have changed. */
{
    int txtWidth, txtHeight;	/* Width and height of text */
    int imgWidth, imgHeight;	/* Width and height of image */
    int width = 0, height = 0;	/* Width and height of button */
    int haveImage, haveText;
    int avgWidth;
    int minWidth;
    /* Vertical and horizontal dialog units size in pixels. */
    double vDLU, hDLU;
    Tk_FontMetrics fm;

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

    if (butPtr->highlightWidth < 0) {
	butPtr->highlightWidth = 0;
    }
    butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth;
    butPtr->indicatorSpace = 0;

    if (!tsdPtr->initialized) {
	InitBoxes(butPtr->tkwin);
    if (!tsdPtr->boxesPtr) {
	InitBoxes();
    }

    /*
     * Figure out image metrics.
     */

    if (butPtr->image != NULL) {
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
852
853
854
855
856
857
858

859
860
861
862
863
864
865
866







-
+







    /*
     * Figure out font metrics (even if we don't have text because we need
     * DLUs (based on font, not text) for some spacing calculations below).
     */

    Tk_FreeTextLayout(butPtr->textLayout);
    butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
	    Tcl_GetString(butPtr->textPtr), TCL_INDEX_NONE, butPtr->wrapLength,
	    Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
	    butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

    txtWidth = butPtr->textWidth;
    txtHeight = butPtr->textHeight;
    haveText = (*(Tcl_GetString(butPtr->textPtr)) != '\0');
    avgWidth = (Tk_TextWidth(butPtr->tkfont,
	    "abcdefghijklmnopqurstuvwzyABCDEFGHIJKLMNOPQURSTUVWZY",
1325
1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336
1337
1338
1339
1147
1148
1149
1150
1151
1152
1153

1154
1155
1156
1157
1158
1159
1160
1161







-
+







    /*
     * Fix up width and height for indicator sizing and spacing.
     */

    if (butPtr->type == TYPE_RADIO_BUTTON
	    || butPtr->type == TYPE_CHECK_BUTTON) {
	if (butPtr->indicatorOn) {
	    butPtr->indicatorDiameter = tsdPtr->boxSize;
	    butPtr->indicatorDiameter = tsdPtr->boxHeight;

	    /*
	     * Make sure we can see the whole indicator, even if the text or
	     * image is very small.
	     */

	    if (height < butPtr->indicatorDiameter) {
1365
1366
1367
1368
1369
1370
1371
1372
1373


1374
1375
1376
1377
1378
1379
1380
1187
1188
1189
1190
1191
1192
1193


1194
1195
1196
1197
1198
1199
1200
1201
1202







-
-
+
+







}

/*
 *----------------------------------------------------------------------
 *
 * ButtonProc --
 *
 *	This function is called by Windows whenever an event occurs on a
 *	button control created by Tk.
 *	This function is call by Windows whenever an event occurs on a button
 *	control created by Tk.
 *
 * Results:
 *	Standard Windows return value.
 *
 * Side effects:
 *	May generate events.
 *
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464

1465
1466
1467
1468
1469
1470

1471
1472

1473
1474
1475
1476

1477
1478
1479
1480
1481
1482
1483
1484
1485
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278

1279
1280
1281
1282
1283
1284
1285

1286
1287
1288
1289
1290
1291

1292
1293

1294
1295
1296
1297

1298
1299
1300
1301
1302
1303
1304
1305
1306
1307







-
+







-
+














-
+






-
+





-
+

-
+



-
+









    case WM_ENABLE:
	break;

    case WM_PAINT: {
	PAINTSTRUCT ps;
	BeginPaint(hwnd, &ps);
	EndPaint(hwnd, &ps);
	TkpDisplayButton(butPtr);
	TkpDisplayButton((ClientData)butPtr);

	/*
	 * Special note: must cancel any existing idle handler for
	 * TkpDisplayButton; it's no longer needed, and TkpDisplayButton
	 * cleared the REDRAW_PENDING flag.
	 */

	Tcl_CancelIdleCall(TkpDisplayButton, butPtr);
	Tcl_CancelIdleCall(TkpDisplayButton, (ClientData)butPtr);
	return 0;
    }
    case BN_CLICKED: {
	/*
	 * OOPS: chromium fires WM_NULL regularly to ping if plugin is still
	 * alive. When using an external window (i.e. via the tcl plugin), this
	 * causes all buttons to fire once a second, so we need to make sure
	 * that we are not dealing with the chromium life check.
	*/
        if (wParam != 0 || lParam != 0) {
	    int code;
	    Tcl_Interp *interp = butPtr->info.interp;

	    if (butPtr->info.state != STATE_DISABLED) {
		Tcl_Preserve(interp);
		Tcl_Preserve((ClientData)interp);
		code = TkInvokeButton((TkButton*)butPtr);
		if (code != TCL_OK && code != TCL_CONTINUE
			&& code != TCL_BREAK) {
		    Tcl_AddErrorInfo(interp, "\n    (button invoke)");
		    Tcl_BackgroundException(interp, code);
		}
		Tcl_Release(interp);
		Tcl_Release((ClientData)interp);
	    }
	    Tcl_ServiceAll();
	    return 0;
	}
    }
    /* FALLTHRU */

    default:
	if (TkTranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	if (Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	    return result;
	}
    }
    return DefWindowProcW(hwnd, message, wParam, lParam);
    return DefWindowProc(hwnd, message, wParam, lParam);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinClipboard.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkWinClipboard.c --
 *
 *	This file contains functions for managing the clipboard.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "tkSelect.h"
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160

161
162

163
164
165
166
167
168
169
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58

59
60
61
62






63
64
65
66
67
68
69
70
71
72
73
74
75

76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149

150
151
152
153
154

155
156

157
158
159
160
161
162
163
164







-
+








-
+
+


-
-
-
-
-
-













-
+

-
+
+



















-
-
+
+







-
-
+
+




















-
-
+
+

















-
+
-





-
+

-
+







				 * selection (determines display from which to
				 * retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection is to be
				 * returned. */
    Tk_GetSelProc *proc,	/* Procedure to call to process the selection,
				 * once it has been retrieved. */
    void *clientData)	/* Arbitrary value to pass to proc. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    char *data, *destPtr;
    Tcl_DString ds;
    HGLOBAL handle;
    Tcl_Encoding encoding;
    int result, locale, noBackslash = 0;

    if ((selection != Tk_InternAtom(tkwin, "CLIPBOARD"))
	    || (target != XA_STRING)) {
	    || (target != XA_STRING)
	    || !OpenClipboard(NULL)) {
	goto error;
    }
    if (!OpenClipboard(NULL)) {
        Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	        "clipboard cannot be opened, another application grabbed it"));
        Tcl_SetErrorCode(interp, "TK", "CLIPBOARD", "BUSY", NULL);
        return TCL_ERROR;
    }

    /*
     * Attempt to get the data in Unicode form if available as this is less
     * work that CF_TEXT.
     */

    result = TCL_ERROR;
    if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
	handle = GetClipboardData(CF_UNICODETEXT);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}
	data = (char *)GlobalLock(handle);
	data = GlobalLock(handle);
	Tcl_DStringInit(&ds);
	Tcl_WCharToUtfDString((WCHAR *)data, wcslen((WCHAR *)data), &ds);
	Tcl_UniCharToUtfDString((Tcl_UniChar *)data,
		Tcl_UniCharLen((Tcl_UniChar *)data), &ds);
	GlobalUnlock(handle);
    } else if (IsClipboardFormatAvailable(CF_TEXT)) {
	/*
	 * Determine the encoding to use to convert this text.
	 */

	if (IsClipboardFormatAvailable(CF_LOCALE)) {
	    handle = GetClipboardData(CF_LOCALE);
	    if (!handle) {
		CloseClipboard();
		goto error;
	    }

	    /*
	     * Get the locale identifier, determine the proper code page to
	     * use, and find the corresponding encoding.
	     */

	    Tcl_DStringInit(&ds);
	    Tcl_DStringAppend(&ds, "cp######", TCL_INDEX_NONE);
	    data = (char *)GlobalLock(handle);
	    Tcl_DStringAppend(&ds, "cp######", -1);
	    data = GlobalLock(handle);

	    /*
	     * Even though the documentation claims that GetLocaleInfo expects
	     * an LCID, on Windows 9x it really seems to expect a LanguageID.
	     */

	    locale = LANGIDFROMLCID(*((int*)data));
	    GetLocaleInfoA((ULONG)locale, LOCALE_IDEFAULTANSICODEPAGE,
		    Tcl_DStringValue(&ds)+2, (int)Tcl_DStringLength(&ds)-2);
	    GetLocaleInfoA(locale, LOCALE_IDEFAULTANSICODEPAGE,
		    Tcl_DStringValue(&ds)+2, Tcl_DStringLength(&ds)-2);
	    GlobalUnlock(handle);

	    encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds));
	    Tcl_DStringFree(&ds);
	} else {
	    encoding = NULL;
	}

	/*
	 * Fetch the text and convert it to UTF.
	 */

	handle = GetClipboardData(CF_TEXT);
	if (!handle) {
	    if (encoding) {
		Tcl_FreeEncoding(encoding);
	    }
	    CloseClipboard();
	    goto error;
	}
	data = (char *)GlobalLock(handle);
	(void)Tcl_ExternalToUtfDString(encoding, data, TCL_INDEX_NONE, &ds);
	data = GlobalLock(handle);
	Tcl_ExternalToUtfDString(encoding, data, -1, &ds);
	GlobalUnlock(handle);
	if (encoding) {
	    Tcl_FreeEncoding(encoding);
	}
    } else if (IsClipboardFormatAvailable(CF_HDROP)) {
	DROPFILES *drop;

	handle = GetClipboardData(CF_HDROP);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}
	Tcl_DStringInit(&ds);
	drop = (DROPFILES *) GlobalLock(handle);
	if (drop->fWide) {
	    WCHAR *fname = (WCHAR *) ((char *) drop + drop->pFiles);
	    Tcl_DString dsTmp;
	    int count = 0;
	    int count = 0, len;
	    size_t len;

	    while (*fname != 0) {
		if (count) {
		    Tcl_DStringAppend(&ds, "\n", 1);
		}
		len = wcslen(fname);
		len = Tcl_UniCharLen((Tcl_UniChar *) fname);
		Tcl_DStringInit(&dsTmp);
		Tcl_WCharToUtfDString(fname, len, &dsTmp);
		Tcl_UniCharToUtfDString((Tcl_UniChar *) fname, len, &dsTmp);
		Tcl_DStringAppend(&ds, Tcl_DStringValue(&dsTmp),
			Tcl_DStringLength(&dsTmp));
		Tcl_DStringFree(&dsTmp);
		fname += len + 1;
		count++;
	    }
	    noBackslash = (count > 0);
223
224
225
226
227
228
229
230

231
232
233

234
235
236
237
238
239
240
218
219
220
221
222
223
224

225
226
227

228
229
230
231
232
233
234
235







-
+


-
+







 *	Empties the system clipboard, and claims ownership.
 *
 *----------------------------------------------------------------------
 */

int
XSetSelectionOwner(
    TCL_UNUSED(Display *),
    Display *display,
    Atom selection,
    Window owner,
    TCL_UNUSED(Time))
    Time time)
{
    HWND hwnd = owner ? TkWinGetHWND(owner) : NULL;
    Tk_Window tkwin;

    /*
     * This is a gross hack because the Tk_InternAtom interface is broken. It
     * expects a Tk_Window, even though it only needs a Tk_Display.
271
272
273
274
275
276
277
278

279
280
281
282
283
284

285
286
287
288
289
290
291
266
267
268
269
270
271
272

273
274
275
276
277
278

279
280
281
282
283
284
285
286







-
+





-
+







 *
 *----------------------------------------------------------------------
 */

void
TkWinClipboardRender(
    TkDisplay *dispPtr,
    TCL_UNUSED(UINT))
    UINT format)
{
    TkClipboardTarget *targetPtr;
    TkClipboardBuffer *cbPtr;
    HGLOBAL handle;
    char *buffer, *p, *rawText, *endPtr;
    size_t length;
    int length;
    Tcl_DString ds;

    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
	    targetPtr = targetPtr->nextPtr) {
	if (targetPtr->type == XA_STRING) {
	    break;
	}
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331






332
333

334
335
336
















337
338
339
340
341

342
343

344
345
346


347
348
349
350
351
352
353
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

357
358

359
360
361

362
363
364
365
366
367
368
369
370







-
+














+
+
+
+
+
+

-
+


-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+

-
+


-
+
+







	}
    }

    /*
     * Copy the data and change EOL characters.
     */

    buffer = rawText = (char *)ckalloc(length + 1);
    buffer = rawText = ckalloc(length + 1);
    if (targetPtr != NULL) {
	for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
		cbPtr = cbPtr->nextPtr) {
	    for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
		    p < endPtr; p++) {
		if (*p == '\n') {
		    *buffer++ = '\r';
		}
		*buffer++ = *p;
	    }
	}
    }
    *buffer = '\0';

    /*
     * Depending on the platform, turn the data into Unicode or the system
     * encoding before placing it on the clipboard.
     */

#ifdef UNICODE
	Tcl_DStringInit(&ds);
	Tcl_UtfToWCharDString(rawText, TCL_INDEX_NONE, &ds);
	Tcl_WinUtfToTChar(rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		Tcl_DStringLength(&ds) + 2);
		(unsigned) Tcl_DStringLength(&ds) + 2);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds),
		(unsigned) Tcl_DStringLength(&ds) + 2);
	GlobalUnlock(handle);
	Tcl_DStringFree(&ds);
	SetClipboardData(CF_UNICODETEXT, handle);
#else
	Tcl_UtfToExternalDString(NULL, rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		(unsigned) Tcl_DStringLength(&ds) + 1);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = (char *)GlobalLock(handle);
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds),
		Tcl_DStringLength(&ds) + 2);
		(unsigned) Tcl_DStringLength(&ds) + 1);
	GlobalUnlock(handle);
	Tcl_DStringFree(&ds);
	SetClipboardData(CF_UNICODETEXT, handle);
	SetClipboardData(CF_TEXT, handle);
#endif
}

/*
 *----------------------------------------------------------------------
 *
 * TkSelUpdateClipboard --
 *
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
379
380
381
382
383
384
385

386
387
388

389
390
391
392
393
394
395







-
+


-







 *
 *----------------------------------------------------------------------
 */

void
TkSelUpdateClipboard(
    TkWindow *winPtr,
    TCL_UNUSED(TkClipboardTarget *))
    TkClipboardTarget *targetPtr)
{
    HWND hwnd = TkWinGetHWND(winPtr->window);

    UpdateClipboard(hwnd);
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateClipboard --
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
434
435
436
437
438
439
440

441
442
443
444
445
446
447
448







-
+







 *
 *--------------------------------------------------------------
 */

void
TkSelEventProc(
    Tk_Window tkwin,		/* Window for which event was targeted. */
    XEvent *eventPtr)	/* X event: either SelectionClear,
    register XEvent *eventPtr)	/* X event: either SelectionClear,
				 * SelectionRequest, or SelectionNotify. */
{
    if (eventPtr->type == SelectionClear) {
	TkSelClearSelection(tkwin, eventPtr);
    }
}

445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
461
462
463
464
465
466
467

468
469
470
471
472
473
474
475
476
477
478







-
+










 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelPropProc(
    TCL_UNUSED(XEvent *))	/* X PropertyChange event. */
    register XEvent *eventPtr)	/* X PropertyChange event. */
{
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinColor.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkWinColor.c --
 *
 *	Functions to map color names to system color values.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright © 1994 Software Research Associates, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 * Copyright (c) 1994 Software Research Associates, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "tkColor.h"
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
54
55
56
57
58
59
60

61
62
63
64
65
66
67







-







    {"InactiveBorder",		COLOR_INACTIVEBORDER},
    {"InactiveCaption",		COLOR_INACTIVECAPTION},
    {"InactiveCaptionText",	COLOR_INACTIVECAPTIONTEXT},
    {"InfoBackground",		COLOR_INFOBK},
    {"InfoText",		COLOR_INFOTEXT},
    {"Menu",			COLOR_MENU},
    {"MenuText",		COLOR_MENUTEXT},
    {"PlaceHolderText",		COLOR_GRAYTEXT},
    {"Scrollbar",		COLOR_SCROLLBAR},
    {"Window",			COLOR_WINDOW},
    {"WindowFrame",		COLOR_WINDOWFRAME},
    {"WindowText",		COLOR_WINDOWTEXT}
};

/*
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
169
170
171
172
173
174
175

176
177
178
179
180
181
182
183







-
+







     * color index.
     */

    if (((strncasecmp(name, "system", 6) == 0)
	    && FindSystemColor(name+6, &color, &index))
	    || TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), name,
		    &color)) {
	winColPtr = (WinColor *)ckalloc(sizeof(WinColor));
	winColPtr = ckalloc(sizeof(WinColor));
	winColPtr->info.color = color;
	winColPtr->index = index;

	XAllocColor(Tk_Display(tkwin), Tk_Colormap(tkwin),
		&winColPtr->info.color);
 	return (TkColor *) winColPtr;
    }
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+








TkColor *
TkpGetColorByValue(
    Tk_Window tkwin,		/* Window in which color will be used. */
    XColor *colorPtr)		/* Red, green, and blue fields indicate
				 * desired color. */
{
    WinColor *tkColPtr = (WinColor *)ckalloc(sizeof(WinColor));
    WinColor *tkColPtr = ckalloc(sizeof(WinColor));

    tkColPtr->info.color.red = colorPtr->red;
    tkColPtr->info.color.green = colorPtr->green;
    tkColPtr->info.color.blue = colorPtr->blue;
    tkColPtr->info.color.pixel = 0;
    tkColPtr->index = -1;
    XAllocColor(Tk_Display(tkwin), Tk_Colormap(tkwin), &tkColPtr->info.color);
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284







-
+







 *----------------------------------------------------------------------
 */

int
TkWinIndexOfColor(
    XColor *colorPtr)
{
    WinColor *winColPtr = (WinColor *) colorPtr;
    register WinColor *winColPtr = (WinColor *) colorPtr;
    if (winColPtr->info.magic == COLOR_MAGIC) {
	return winColPtr->index;
    }
    return -1;
}

/*
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314



315
316
317
318

319
320

321
322
323
324
325
326
327
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310



311
312
313
314
315
316

317
318

319
320
321
322
323
324
325
326







-
+







-
-
-
+
+
+



-
+

-
+







 *	Allocates a new color in the palette.
 *
 *----------------------------------------------------------------------
 */

int
XAllocColor(
    TCL_UNUSED(Display *),
    Display *display,
    Colormap colormap,
    XColor *color)
{
    TkWinColormap *cmap = (TkWinColormap *) colormap;
    PALETTEENTRY entry, closeEntry;
    HDC dc = GetDC(NULL);

    entry.peRed = (BYTE)((color->red) >> 8);
    entry.peGreen = (BYTE)((color->green) >> 8);
    entry.peBlue = (BYTE)((color->blue) >> 8);
    entry.peRed = (color->red) >> 8;
    entry.peGreen = (color->green) >> 8;
    entry.peBlue = (color->blue) >> 8;
    entry.peFlags = 0;

    if (GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) {
	unsigned long sizePalette = (unsigned long)GetDeviceCaps(dc, SIZEPALETTE);
	unsigned long sizePalette = GetDeviceCaps(dc, SIZEPALETTE);
	UINT newPixel, closePixel;
	int isNew;
	int new;
	size_t refCount;
	Tcl_HashEntry *entryPtr;
	UINT index;

	/*
	 * Find the nearest existing palette entry.
	 */
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363


364
365
366
367
368

369
370
371
372
373
374
375
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357
358
359
360


361
362
363
364
365
366

367
368
369
370
371
372
373
374







-
+










-
-
+
+




-
+







	if ((index >= cmap->size) || (newPixel != closePixel)) {
	    if (cmap->size == sizePalette) {
		color->red   = closeEntry.peRed * 257;
		color->green = closeEntry.peGreen * 257;
		color->blue  = closeEntry.peBlue * 257;
		entry = closeEntry;
		if (index >= cmap->size) {
		    OutputDebugStringW(L"XAllocColor: Colormap is bigger than we thought");
		    OutputDebugStringA("XAllocColor: Colormap is bigger than we thought");
		}
	    } else {
		cmap->size++;
		ResizePalette(cmap->palette, cmap->size);
		SetPaletteEntries(cmap->palette, cmap->size - 1, 1, &entry);
	    }
	}

	color->pixel = PALETTERGB(entry.peRed, entry.peGreen, entry.peBlue);
	entryPtr = Tcl_CreateHashEntry(&cmap->refCounts,
		INT2PTR(color->pixel), &isNew);
	if (isNew) {
		INT2PTR(color->pixel), &new);
	if (new) {
	    refCount = 1;
	} else {
	    refCount = (size_t)Tcl_GetHashValue(entryPtr) + 1;
	}
	Tcl_SetHashValue(entryPtr, INT2PTR(refCount));
	Tcl_SetHashValue(entryPtr, (void *)refCount);
    } else {
	/*
	 * Determine what color will actually be used on non-colormap systems.
	 */

	color->pixel = GetNearestColor(dc,
		RGB(entry.peRed, entry.peGreen, entry.peBlue));
397
398
399
400
401
402
403
404

405
406
407
408

409
410
411
412
413
414
415
396
397
398
399
400
401
402

403
404
405
406

407
408
409
410
411
412
413
414







-
+



-
+







 *	set.
 *
 *----------------------------------------------------------------------
 */

int
XFreeColors(
    TCL_UNUSED(Display *),
    Display *display,
    Colormap colormap,
    unsigned long *pixels,
    int npixels,
    TCL_UNUSED(unsigned long))
    unsigned long planes)
{
    TkWinColormap *cmap = (TkWinColormap *) colormap;
    COLORREF cref;
    UINT count, index;
    size_t refCount;
    int i;
    PALETTEENTRY entry, *entries;
433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448

449
450
451
452
453
454
455
456







-
+









-
+







	    refCount = (size_t)Tcl_GetHashValue(entryPtr) - 1;
	    if (refCount == 0) {
		cref = pixels[i] & 0x00ffffff;
		index = GetNearestPaletteIndex(cmap->palette, cref);
		GetPaletteEntries(cmap->palette, index, 1, &entry);
		if (cref == RGB(entry.peRed, entry.peGreen, entry.peBlue)) {
		    count = cmap->size - index;
		    entries = (PALETTEENTRY *)ckalloc(sizeof(PALETTEENTRY) * count);
		    entries = ckalloc(sizeof(PALETTEENTRY) * count);
		    GetPaletteEntries(cmap->palette, index+1, count, entries);
		    SetPaletteEntries(cmap->palette, index, count, entries);
		    ckfree(entries);
		    cmap->size--;
		} else {
		    Tcl_Panic("Tried to free a color that isn't allocated");
		}
		Tcl_DeleteHashEntry(entryPtr);
	    } else {
		Tcl_SetHashValue(entryPtr, INT2PTR(refCount));
		Tcl_SetHashValue(entryPtr, (size_t)refCount);
	    }
	}
    }
    ReleaseDC(NULL, dc);
    return Success;
}

469
470
471
472
473
474
475
476
477
478
479




480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511
512
513

514
515
516
517
518
519
520
468
469
470
471
472
473
474




475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519







-
-
-
-
+
+
+
+






-
+













-
+












-
+







 *	Allocates an empty palette and color list.
 *
 *----------------------------------------------------------------------
 */

Colormap
XCreateColormap(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Visual *),
    TCL_UNUSED(int))
    Display *display,
    Window w,
    Visual *visual,
    int alloc)
{
    char logPalBuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
    LOGPALETTE *logPalettePtr;
    PALETTEENTRY *entryPtr;
    TkWinColormap *cmap;
    Tcl_HashEntry *hashPtr;
    int isNew;
    int new;
    UINT i;
    HPALETTE sysPal;

    /*
     * Allocate a starting palette with all of the reserved colors.
     */

    logPalettePtr = (LOGPALETTE *) logPalBuf;
    logPalettePtr->palVersion = 0x300;
    sysPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
    logPalettePtr->palNumEntries = GetPaletteEntries(sysPal, 0, 256,
	    logPalettePtr->palPalEntry);

    cmap = (TkWinColormap *)ckalloc(sizeof(TkWinColormap));
    cmap = ckalloc(sizeof(TkWinColormap));
    cmap->size = logPalettePtr->palNumEntries;
    cmap->stale = 0;
    cmap->palette = CreatePalette(logPalettePtr);

    /*
     * Add hash entries for each of the static colors.
     */

    Tcl_InitHashTable(&cmap->refCounts, TCL_ONE_WORD_KEYS);
    for (i = 0; i < logPalettePtr->palNumEntries; i++) {
	entryPtr = logPalettePtr->palPalEntry + i;
	hashPtr = Tcl_CreateHashEntry(&cmap->refCounts, INT2PTR(PALETTERGB(
		entryPtr->peRed, entryPtr->peGreen, entryPtr->peBlue)), &isNew);
		entryPtr->peRed, entryPtr->peGreen, entryPtr->peBlue)), &new);
	Tcl_SetHashValue(hashPtr, INT2PTR(1));
    }

    return (Colormap)cmap;
}

/*
532
533
534
535
536
537
538
539

540
541
542
543
544
545
546
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545







-
+







 *	palette must not be selected into a device context when this occurs.
 *
 *----------------------------------------------------------------------
 */

int
XFreeColormap(
    TCL_UNUSED(Display *),
    Display *display,
    Colormap colormap)
{
    TkWinColormap *cmap = (TkWinColormap *) colormap;

    if (!DeleteObject(cmap->palette)) {
	Tcl_Panic("Unable to free colormap, palette is still selected");
    }

Changes to win/tkWinConfig.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43






-
+











-
+





-
+










-
+







/*
 * tkWinConfig.c --
 *
 *	This module implements the Windows system defaults for the
 *	configuration package.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright (c) 1997 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"


/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSystemDefault --
 * TkpGetSystemDefault --
 *
 *	Given a dbName and className for a configuration option, return a
 *	string representation of the option.
 *
 * Results:
 *	Returns a Tcl_Obj* with the string identifier that identifies this
 *	Returns a Tk_Uid that is the string identifier that identifies this
 *	option. Returns NULL if there are no system defaults that match this
 *	pair.
 *
 * Side effects:
 *	None, once the package is initialized.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
Tk_GetSystemDefault(
TkpGetSystemDefault(
    Tk_Window tkwin,		/* A window to use. */
    const char *dbName,		/* The option database name. */
    const char *className)	/* The name of the option class. */
{
    Tcl_Obj *valueObjPtr;
    Tk_Uid classUid;

Changes to win/tkWinCursor.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkWinCursor.c --
 *
 *	This file contains Win32 specific cursor related routines.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-
+







#endif

/*
 * The table below is used to map from the name of a predefined cursor to its
 * resource identifier.
 */

static const struct CursorName {
static struct CursorName {
    const char *name;
    LPCTSTR id;
} cursorNames[] = {
    {"starting",		IDC_APPSTARTING},
    {"arrow",			IDC_ARROW},
    {"ibeam",			IDC_IBEAM},
    {"icon",			IDC_ICON},
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







    {NULL,			0}
};

/*
 * The default cursor is used whenever no other cursor has been specified.
 */

#define TK_DEFAULT_CURSOR	(LPCWSTR)IDC_ARROW
#define TK_DEFAULT_CURSOR	IDC_ARROW

/*
 *----------------------------------------------------------------------
 *
 * TkGetCursorByName --
 *
 *	Retrieve a system cursor by name.
92
93
94
95
96
97
98
99

100
101

102
103
104
105
106
107

108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
92
93
94
95
96
97
98

99
100

101
102

103
104
105

106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155







-
+

-
+

-



-
+









-
+

















-
+













-
+







TkCursor *
TkGetCursorByName(
    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
    Tk_Window tkwin,		/* Window in which cursor will be used. */
    Tk_Uid string)		/* Description of cursor. See manual entry for
				 * details on legal syntax. */
{
    const struct CursorName *namePtr;
    struct CursorName *namePtr;
    TkWinCursor *cursorPtr;
    Tcl_Size argc;
    int argc;
    const char **argv = NULL;
    (void)tkwin;

    /*
     * All cursor names are valid lists of one element (for
     * Unix-compatibility), even unadorned system cursor names.
     * Unix-compatability), even unadorned system cursor names.
     */

    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
	return NULL;
    }
    if (argc == 0) {
	goto badCursorSpec;
    }

    cursorPtr = (TkWinCursor *)ckalloc(sizeof(TkWinCursor));
    cursorPtr = ckalloc(sizeof(TkWinCursor));
    cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
    cursorPtr->winCursor = NULL;
    cursorPtr->system = 0;

    if (argv[0][0] == '@') {
	/*
	 * Check for system cursor of type @<filename>, where only the name is
	 * allowed. This accepts any of:
	 *	-cursor @/winnt/cursors/globe.ani
	 *	-cursor @C:/Winnt/cursors/E_arrow.cur
	 *	-cursor {@C:/Program\ Files/Cursors/bart.ani}
	 *      -cursor {{@C:/Program Files/Cursors/bart.ani}}
	 *	-cursor [list @[file join "C:/Program Files" Cursors bart.ani]]
	 */

	if (Tcl_IsSafe(interp)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "can't get cursor from a file in a safe interpreter", TCL_INDEX_NONE));
		    "can't get cursor from a file in a safe interpreter",-1));
	    Tcl_SetErrorCode(interp, "TK", "SAFE", "CURSOR_FILE", NULL);
	    ckfree(argv);
	    ckfree(cursorPtr);
	    return NULL;
	}
	cursorPtr->winCursor = LoadCursorFromFileA(&(argv[0][1]));
    } else {
	/*
	 * Check for the cursor in the system cursor set.
	 */

	for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
	    if (strcmp(namePtr->name, argv[0]) == 0) {
		cursorPtr->winCursor = LoadCursorW(NULL, (LPCWSTR) namePtr->id);
		cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);
		break;
	    }
	}

	if (cursorPtr->winCursor == NULL) {
	    /*
	     * Hmm, it is not in the system cursor set. Check to see if it is
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
197
198
199
200
201
202
203










204
205
206
207
208
209
210







-
-
-
-
-
-
-
-
-
-







    const char *source,		/* Bitmap data for cursor shape. */
    const char *mask,		/* Bitmap data for cursor mask. */
    int width, int height,	/* Dimensions of cursor. */
    int xHot, int yHot,		/* Location of hot-spot in cursor. */
    XColor fgColor,		/* Foreground color for cursor. */
    XColor bgColor)		/* Background color for cursor. */
{
    (void)tkwin;
    (void)source;
    (void)mask;
    (void)width;
    (void)height;
    (void)xHot;
    (void)yHot;
    (void)fgColor;
    (void)bgColor;

    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpFreeCursor --
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
221
222
223
224
225
226
227


228
229
230
231
232
233
234







-
-







 *----------------------------------------------------------------------
 */

void
TkpFreeCursor(
    TkCursor *cursorPtr)
{
    (void)cursorPtr;

    /* TkWinCursor *winCursorPtr = (TkWinCursor *) cursorPtr; */
}

/*
 *----------------------------------------------------------------------
 *
 * TkpSetCursor --
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263







-
+







TkpSetCursor(
    TkpCursor cursor)
{
    HCURSOR hcursor;
    TkWinCursor *winCursor = (TkWinCursor *) cursor;

    if (winCursor == NULL || winCursor->winCursor == NULL) {
	hcursor = LoadCursorW(NULL, TK_DEFAULT_CURSOR);
	hcursor = LoadCursor(NULL, TK_DEFAULT_CURSOR);
    } else {
	hcursor = winCursor->winCursor;
    }

    if (hcursor != NULL) {
	SetCursor(hcursor);
    }

Changes to win/tkWinDefault.h.

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91

92
93
94

95
96
97
98
99
100
101
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89

90
91
92
93
94
95
96
97
98
99
100
101







-









-
+















-
+


-
+



+







#define DEF_BUTTON_BORDER_WIDTH	"2"
#define DEF_BUTTON_CURSOR		""
#define DEF_BUTTON_COMMAND		""
#define DEF_BUTTON_COMPOUND		"none"
#define DEF_BUTTON_DEFAULT		"disabled"
#define DEF_BUTTON_DISABLED_FG_COLOR	DISABLED
#define DEF_BUTTON_DISABLED_FG_MONO	""
#define DEF_LABEL_FG			NORMAL_FG
#define DEF_BUTTON_FG			NORMAL_FG
#define DEF_CHKRAD_FG			TEXT_FG
#define DEF_BUTTON_FONT			"TkDefaultFont"
#define DEF_BUTTON_HEIGHT		"0"
#define DEF_BUTTON_HIGHLIGHT_BG_COLOR	DEF_BUTTON_BG_COLOR
#define DEF_BUTTON_HIGHLIGHT_BG_MONO	DEF_BUTTON_BG_MONO
#define DEF_BUTTON_HIGHLIGHT		HIGHLIGHT
#define DEF_LABEL_HIGHLIGHT_WIDTH	"0"
#define DEF_BUTTON_HIGHLIGHT_WIDTH	"1"
#define DEF_BUTTON_IMAGE		NULL
#define DEF_BUTTON_IMAGE		((char *) NULL)
#define DEF_BUTTON_INDICATOR		"1"
#define DEF_BUTTON_JUSTIFY		"center"
#define DEF_BUTTON_OFF_VALUE		"0"
#define DEF_BUTTON_ON_VALUE		"1"
#define DEF_BUTTON_OVER_RELIEF		""
#define DEF_BUTTON_PADX			"1"
#define DEF_LABCHKRAD_PADX		"1"
#define DEF_BUTTON_PADY			"1"
#define DEF_LABCHKRAD_PADY		"1"
#define DEF_BUTTON_RELIEF		"raised"
#define DEF_LABCHKRAD_RELIEF		"flat"
#define DEF_BUTTON_REPEAT_DELAY		"0"
#define DEF_BUTTON_REPEAT_INTERVAL	"0"
#define DEF_BUTTON_SELECT_COLOR		INDICATOR
#define DEF_BUTTON_SELECT_MONO		BLACK
#define DEF_BUTTON_SELECT_IMAGE		NULL
#define DEF_BUTTON_SELECT_IMAGE		((char *) NULL)
#define DEF_BUTTON_STATE		"normal"
#define DEF_LABEL_TAKE_FOCUS		"0"
#define DEF_BUTTON_TAKE_FOCUS		NULL
#define DEF_BUTTON_TAKE_FOCUS		((char *) NULL)
#define DEF_BUTTON_TEXT			""
#define DEF_BUTTON_TEXT_VARIABLE	""
#define DEF_BUTTON_TRISTATE_VALUE	""
#define DEF_BUTTON_UNDERLINE		"-1"
#define DEF_BUTTON_VALUE		""
#define DEF_BUTTON_WIDTH		"0"
#define DEF_BUTTON_WRAP_LENGTH		"0"
#define DEF_RADIOBUTTON_VARIABLE	"selectedButton"
#define DEF_CHECKBUTTON_VARIABLE	""

/*
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
122
123
124
125
126
127
128

129
130
131
132
133
134
135
136







-
+







#define DEF_CANVAS_SCROLL_REGION	""
#define DEF_CANVAS_SELECT_COLOR		SELECT_BG
#define DEF_CANVAS_SELECT_MONO		BLACK
#define DEF_CANVAS_SELECT_BD_COLOR	"1"
#define DEF_CANVAS_SELECT_BD_MONO	"0"
#define DEF_CANVAS_SELECT_FG_COLOR	SELECT_FG
#define DEF_CANVAS_SELECT_FG_MONO	WHITE
#define DEF_CANVAS_TAKE_FOCUS		NULL
#define DEF_CANVAS_TAKE_FOCUS		((char *) NULL)
#define DEF_CANVAS_WIDTH		"10c"
#define DEF_CANVAS_X_SCROLL_CMD		""
#define DEF_CANVAS_X_SCROLL_INCREMENT	"0"
#define DEF_CANVAS_Y_SCROLL_CMD		""
#define DEF_CANVAS_Y_SCROLL_INCREMENT	"0"

/*
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
153
154
155
156
157
158
159


160
161
162
163
164
165
166
167
168
169

170
171

172
173
174
175
176
177
178
179
180

181

182
183
184
185
186
187
188







-
-










-
+

-
+








-

-







#define DEF_ENTRY_INSERT_BG		TEXT_FG
#define DEF_ENTRY_INSERT_BD_COLOR	"0"
#define DEF_ENTRY_INSERT_BD_MONO	"0"
#define DEF_ENTRY_INSERT_OFF_TIME	"300"
#define DEF_ENTRY_INSERT_ON_TIME	"600"
#define DEF_ENTRY_INSERT_WIDTH		"2"
#define DEF_ENTRY_JUSTIFY		"left"
#define DEF_ENTRY_PLACEHOLDER		""
#define DEF_ENTRY_PLACEHOLDERFG		"SystemPlaceHolderText"
#define DEF_ENTRY_READONLY_BG_COLOR	"SystemButtonFace"
#define DEF_ENTRY_READONLY_BG_MONO	WHITE
#define DEF_ENTRY_RELIEF		"sunken"
#define DEF_ENTRY_SCROLL_COMMAND	""
#define DEF_ENTRY_SELECT_COLOR		SELECT_BG
#define DEF_ENTRY_SELECT_MONO		BLACK
#define DEF_ENTRY_SELECT_BD_COLOR	"0"
#define DEF_ENTRY_SELECT_BD_MONO	"0"
#define DEF_ENTRY_SELECT_FG_COLOR	SELECT_FG
#define DEF_ENTRY_SELECT_FG_MONO	WHITE
#define DEF_ENTRY_SHOW			NULL
#define DEF_ENTRY_SHOW			((char *) NULL)
#define DEF_ENTRY_STATE			"normal"
#define DEF_ENTRY_TAKE_FOCUS		NULL
#define DEF_ENTRY_TAKE_FOCUS		((char *) NULL)
#define DEF_ENTRY_TEXT_VARIABLE		""
#define DEF_ENTRY_WIDTH			"20"

/*
 * Defaults for frames:
 */

#define DEF_FRAME_BG_COLOR		NORMAL_BG
#define DEF_FRAME_BG_IMAGE		NULL
#define DEF_FRAME_BG_MONO		WHITE
#define DEF_FRAME_BG_TILE		"0"
#define DEF_FRAME_BORDER_WIDTH		"0"
#define DEF_FRAME_CLASS			"Frame"
#define DEF_FRAME_COLORMAP		""
#define DEF_FRAME_CONTAINER		"0"
#define DEF_FRAME_CURSOR		""
#define DEF_FRAME_HEIGHT		"0"
#define DEF_FRAME_HIGHLIGHT_BG		NORMAL_BG
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254





255
256

257
258
259


260
261

262
263
264


265
266
267

268
269
270


271
272


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
232
233
234
235
236
237
238

239
240
241
242
243
244
245





246
247
248
249
250
251

252
253


254
255
256

257
258


259
260
261
262

263
264


265
266
267

268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292


293
294
295
296
297
298
299
300
301







-
+






-
-
-
-
-
+
+
+
+
+

-
+

-
-
+
+

-
+

-
-
+
+


-
+

-
-
+
+

-
+
+










-













-
-
+
+







#define DEF_LISTBOX_SELECT_MONO		BLACK
#define DEF_LISTBOX_SELECT_BD		"0"
#define DEF_LISTBOX_SELECT_FG_COLOR	SELECT_FG
#define DEF_LISTBOX_SELECT_FG_MONO	WHITE
#define DEF_LISTBOX_SELECT_MODE		"browse"
#define DEF_LISTBOX_SET_GRID		"0"
#define DEF_LISTBOX_STATE		"normal"
#define DEF_LISTBOX_TAKE_FOCUS		NULL
#define DEF_LISTBOX_TAKE_FOCUS		((char *) NULL)
#define DEF_LISTBOX_WIDTH		"20"

/*
 * Defaults for individual entries of menus:
 */

#define DEF_MENU_ENTRY_ACTIVE_BG	NULL
#define DEF_MENU_ENTRY_ACTIVE_FG	NULL
#define DEF_MENU_ENTRY_ACCELERATOR	NULL
#define DEF_MENU_ENTRY_BG		NULL
#define DEF_MENU_ENTRY_BITMAP		NULL
#define DEF_MENU_ENTRY_ACTIVE_BG	((char *) NULL)
#define DEF_MENU_ENTRY_ACTIVE_FG	((char *) NULL)
#define DEF_MENU_ENTRY_ACCELERATOR	((char *) NULL)
#define DEF_MENU_ENTRY_BG		((char *) NULL)
#define DEF_MENU_ENTRY_BITMAP		None
#define DEF_MENU_ENTRY_COLUMN_BREAK	"0"
#define DEF_MENU_ENTRY_COMMAND		NULL
#define DEF_MENU_ENTRY_COMMAND		((char *) NULL)
#define DEF_MENU_ENTRY_COMPOUND 	"none"
#define DEF_MENU_ENTRY_FG		NULL
#define DEF_MENU_ENTRY_FONT		NULL
#define DEF_MENU_ENTRY_FG		((char *) NULL)
#define DEF_MENU_ENTRY_FONT		((char *) NULL)
#define DEF_MENU_ENTRY_HIDE_MARGIN	"0"
#define DEF_MENU_ENTRY_IMAGE		NULL
#define DEF_MENU_ENTRY_IMAGE		((char *) NULL)
#define DEF_MENU_ENTRY_INDICATOR	"1"
#define DEF_MENU_ENTRY_LABEL		NULL
#define DEF_MENU_ENTRY_MENU		NULL
#define DEF_MENU_ENTRY_LABEL		((char *) NULL)
#define DEF_MENU_ENTRY_MENU		((char *) NULL)
#define DEF_MENU_ENTRY_OFF_VALUE	"0"
#define DEF_MENU_ENTRY_ON_VALUE		"1"
#define DEF_MENU_ENTRY_SELECT_IMAGE	NULL
#define DEF_MENU_ENTRY_SELECT_IMAGE	((char *) NULL)
#define DEF_MENU_ENTRY_STATE		"normal"
#define DEF_MENU_ENTRY_VALUE		NULL
#define DEF_MENU_ENTRY_CHECK_VARIABLE	NULL
#define DEF_MENU_ENTRY_VALUE		((char *) NULL)
#define DEF_MENU_ENTRY_CHECK_VARIABLE	((char *) NULL)
#define DEF_MENU_ENTRY_RADIO_VARIABLE	"selectedButton"
#define DEF_MENU_ENTRY_SELECT		NULL
#define DEF_MENU_ENTRY_SELECT		((char *) NULL)
#define DEF_MENU_ENTRY_UNDERLINE	"-1"

/*
 * Defaults for menus overall:
 */

#define DEF_MENU_ACTIVE_BG_COLOR	SELECT_BG
#define DEF_MENU_ACTIVE_BG_MONO		BLACK
#define DEF_MENU_ACTIVE_BORDER_WIDTH	"0"
#define DEF_MENU_ACTIVE_FG_COLOR	SELECT_FG
#define DEF_MENU_ACTIVE_FG_MONO		WHITE
#define DEF_MENU_ACTIVE_RELIEF		"flat"
#define DEF_MENU_BG_COLOR		MENU_BG
#define DEF_MENU_BG_MONO		WHITE
#define DEF_MENU_BORDER_WIDTH		"0"
#define DEF_MENU_CURSOR			"arrow"
#define DEF_MENU_DISABLED_FG_COLOR	DISABLED
#define DEF_MENU_DISABLED_FG_MONO	""
#define DEF_MENU_FONT			"TkMenuFont"
#define DEF_MENU_FG			MENU_FG
#define DEF_MENU_POST_COMMAND		""
#define DEF_MENU_RELIEF			"flat"
#define DEF_MENU_SELECT_COLOR		MENU_FG
#define DEF_MENU_SELECT_MONO		BLACK
#define DEF_MENU_TAKE_FOCUS		"0"
#define DEF_MENU_TEAROFF		"0"
#define DEF_MENU_TEAROFF_CMD		NULL
#define DEF_MENU_TEAROFF		"1"
#define DEF_MENU_TEAROFF_CMD		((char *) NULL)
#define DEF_MENU_TITLE			""
#define DEF_MENU_TYPE			"normal"

/*
 * Defaults for menubuttons:
 */

319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357


358
359
360
361
362
363
364
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352


353
354
355
356
357
358
359
360
361







-
+










+



















-
-
+
+







#define DEF_MENUBUTTON_FONT		"TkDefaultFont"
#define DEF_MENUBUTTON_FG		NORMAL_FG
#define DEF_MENUBUTTON_HEIGHT		"0"
#define DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR DEF_MENUBUTTON_BG_COLOR
#define DEF_MENUBUTTON_HIGHLIGHT_BG_MONO  DEF_MENUBUTTON_BG_MONO
#define DEF_MENUBUTTON_HIGHLIGHT	HIGHLIGHT
#define DEF_MENUBUTTON_HIGHLIGHT_WIDTH	"0"
#define DEF_MENUBUTTON_IMAGE		NULL
#define DEF_MENUBUTTON_IMAGE		((char *) NULL)
#define DEF_MENUBUTTON_INDICATOR	"0"
#define DEF_MENUBUTTON_JUSTIFY		"center"
#define DEF_MENUBUTTON_MENU		""
#define DEF_MENUBUTTON_PADX		"4p"
#define DEF_MENUBUTTON_PADY		"3p"
#define DEF_MENUBUTTON_RELIEF		"flat"
#define DEF_MENUBUTTON_STATE		"normal"
#define DEF_MENUBUTTON_TAKE_FOCUS	"0"
#define DEF_MENUBUTTON_TEXT		""
#define DEF_MENUBUTTON_TEXT_VARIABLE	""
#define DEF_MENUBUTTON_UNDERLINE	"-1"
#define DEF_MENUBUTTON_WIDTH		"0"
#define DEF_MENUBUTTON_WRAP_LENGTH	"0"

/*
 * Defaults for messages:
 */

#define DEF_MESSAGE_ANCHOR		"center"
#define DEF_MESSAGE_ASPECT		"150"
#define DEF_MESSAGE_BG_COLOR		NORMAL_BG
#define DEF_MESSAGE_BG_MONO		WHITE
#define DEF_MESSAGE_BORDER_WIDTH	"1"
#define DEF_MESSAGE_CURSOR		""
#define DEF_MESSAGE_FG			NORMAL_FG
#define DEF_MESSAGE_FONT		"TkDefaultFont"
#define DEF_MESSAGE_HIGHLIGHT_BG	NORMAL_BG
#define DEF_MESSAGE_HIGHLIGHT		HIGHLIGHT
#define DEF_MESSAGE_HIGHLIGHT_WIDTH	"0"
#define DEF_MESSAGE_JUSTIFY		"left"
#define DEF_MESSAGE_PADX		NULL
#define DEF_MESSAGE_PADY		NULL
#define DEF_MESSAGE_PADX		"-1"
#define DEF_MESSAGE_PADY		"-1"
#define DEF_MESSAGE_RELIEF		"flat"
#define DEF_MESSAGE_TAKE_FOCUS		"0"
#define DEF_MESSAGE_TEXT		""
#define DEF_MESSAGE_TEXT_VARIABLE	""
#define DEF_MESSAGE_WIDTH		"0"

/*
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437



438
439
440
441
442
443
444
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424

425
426
427
428
429
430
431



432
433
434
435
436
437
438
439
440
441







-
+







-
+










-
+






-
-
-
+
+
+







 * Defaults for scales:
 */

#define DEF_SCALE_ACTIVE_BG_COLOR	ACTIVE_BG
#define DEF_SCALE_ACTIVE_BG_MONO	BLACK
#define DEF_SCALE_BG_COLOR		NORMAL_BG
#define DEF_SCALE_BG_MONO		WHITE
#define DEF_SCALE_BIG_INCREMENT		"0.0"
#define DEF_SCALE_BIG_INCREMENT		"0"
#define DEF_SCALE_BORDER_WIDTH		"1"
#define DEF_SCALE_COMMAND		""
#define DEF_SCALE_CURSOR		""
#define DEF_SCALE_DIGITS		"0"
#define DEF_SCALE_FONT			"TkDefaultFont"
#define DEF_SCALE_FG_COLOR		NORMAL_FG
#define DEF_SCALE_FG_MONO		BLACK
#define DEF_SCALE_FROM			"0.0"
#define DEF_SCALE_FROM			"0"
#define DEF_SCALE_HIGHLIGHT_BG_COLOR	DEF_SCALE_BG_COLOR
#define DEF_SCALE_HIGHLIGHT_BG_MONO	DEF_SCALE_BG_MONO
#define DEF_SCALE_HIGHLIGHT		HIGHLIGHT
#define DEF_SCALE_HIGHLIGHT_WIDTH	"2"
#define DEF_SCALE_LABEL			""
#define DEF_SCALE_LENGTH		"100"
#define DEF_SCALE_ORIENT		"vertical"
#define DEF_SCALE_RELIEF		"flat"
#define DEF_SCALE_REPEAT_DELAY		"300"
#define DEF_SCALE_REPEAT_INTERVAL	"100"
#define DEF_SCALE_RESOLUTION		"1.0"
#define DEF_SCALE_RESOLUTION		"1"
#define DEF_SCALE_TROUGH_COLOR		TROUGH
#define DEF_SCALE_TROUGH_MONO		WHITE
#define DEF_SCALE_SHOW_VALUE		"1"
#define DEF_SCALE_SLIDER_LENGTH		"30"
#define DEF_SCALE_SLIDER_RELIEF		"raised"
#define DEF_SCALE_STATE			"normal"
#define DEF_SCALE_TAKE_FOCUS		NULL
#define DEF_SCALE_TICK_INTERVAL		"0.0"
#define DEF_SCALE_TO			"100.0"
#define DEF_SCALE_TAKE_FOCUS		((char *) NULL)
#define DEF_SCALE_TICK_INTERVAL		"0"
#define DEF_SCALE_TO			"100"
#define DEF_SCALE_VARIABLE		""
#define DEF_SCALE_WIDTH			"15"

/*
 * Defaults for scrollbars:
 */

455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466







-
+







#define DEF_SCROLLBAR_HIGHLIGHT	HIGHLIGHT
#define DEF_SCROLLBAR_HIGHLIGHT_WIDTH	"0"
#define DEF_SCROLLBAR_JUMP		"0"
#define DEF_SCROLLBAR_ORIENT		"vertical"
#define DEF_SCROLLBAR_RELIEF		"sunken"
#define DEF_SCROLLBAR_REPEAT_DELAY	"300"
#define DEF_SCROLLBAR_REPEAT_INTERVAL	"100"
#define DEF_SCROLLBAR_TAKE_FOCUS	NULL
#define DEF_SCROLLBAR_TAKE_FOCUS	((char *) NULL)
#define DEF_SCROLLBAR_TROUGH_COLOR	TROUGH
#define DEF_SCROLLBAR_TROUGH_MONO	WHITE
#define DEF_SCROLLBAR_WIDTH		"10"

/*
 * Defaults for texts:
 */
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519








520
521
522
523
524
525
526







-
+












-
-
-
-
-
-
-
-







#define DEF_TEXT_SET_GRID		"0"
#define DEF_TEXT_SPACING1		"0"
#define DEF_TEXT_SPACING2		"0"
#define DEF_TEXT_SPACING3		"0"
#define DEF_TEXT_STATE			"normal"
#define DEF_TEXT_TABS			""
#define DEF_TEXT_TABSTYLE		"tabular"
#define DEF_TEXT_TAKE_FOCUS		NULL
#define DEF_TEXT_TAKE_FOCUS		((char *) NULL)
#define DEF_TEXT_UNDO			"0"
#define DEF_TEXT_WIDTH			"80"
#define DEF_TEXT_WRAP			"char"
#define DEF_TEXT_XSCROLL_COMMAND	""
#define DEF_TEXT_YSCROLL_COMMAND	""

/*
 * Defaults for canvas text:
 */

#define DEF_CANVTEXT_FONT		"TkDefaultFont"

/*
 * Defaults for canvas items
 * (arcs, bitmaps, lines, polygons, rectangles, and ovals):
 */

#define DEF_CANVBMAP_FG			NORMAL_FG
#define DEF_CANVITEM_OUTLINE		NORMAL_FG

/*
 * Defaults for toplevels (most of the defaults for frames also apply
 * to toplevels):
 */

#define DEF_TOPLEVEL_CLASS		"Toplevel"
#define DEF_TOPLEVEL_MENU		""

Changes to win/tkWinDialog.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkWinDialog.c --
 *
 *	Contains the Windows implementation of the common dialog boxes.
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-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.
 */

#include "tkWinInt.h"
#include "tkFileFilter.h"
36
37
38
39
40
41
42
43
44
45







46
47

48
49
50
51
52
53
54
36
37
38
39
40
41
42



43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-
-
-
+
+
+
+
+
+
+

-
+







#endif

/* This "new" dialog style is now actually the "old" dialog style post-Vista */
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif

#ifndef BFFM_VALIDATEFAILEDW
#define BFFM_VALIDATEFAILEDW 4
#endif /* BFFM_VALIDATEFAILEDW */
#ifndef BFFM_VALIDATEFAILED
#ifdef UNICODE
#define BFFM_VALIDATEFAILED 4
#else
#define BFFM_VALIDATEFAILED 3
#endif
#endif /* BFFM_VALIDATEFAILED */

typedef struct {
typedef struct ThreadSpecificData {
    int debugFlag;		/* Flags whether we should output debugging
				 * information while displaying a builtin
				 * dialog. */
    Tcl_Interp *debugInterp;	/* Interpreter to used for debugging. */
    UINT WM_LBSELCHANGED;	/* Holds a registered windows event used for
				 * communicating between the Directory Chooser
				 * dialog and its hook proc. */
112
113
114
115
116
117
118
119

120
121

122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181



182
183
184
185
186
187
188
116
117
118
119
120
121
122

123
124

125
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195







-
+

-
+

-
+


















-
-
+
+
















-
+


















-
+


+
+
+







#define NUM_TYPES (sizeof(allowedTypes) / sizeof(allowedTypes[0]))

/*
 * Abstract trivial differences between Win32 and Win64.
 */

#define TkWinGetHInstance(from) \
	((HINSTANCE) GetWindowLongPtrW((from), GWLP_HINSTANCE))
	((HINSTANCE) GetWindowLongPtr((from), GWLP_HINSTANCE))
#define TkWinGetUserData(from) \
	GetWindowLongPtrW((from), GWLP_USERDATA)
	GetWindowLongPtr((from), GWLP_USERDATA)
#define TkWinSetUserData(to,what) \
	SetWindowLongPtrW((to), GWLP_USERDATA, (LPARAM)(what))
	SetWindowLongPtr((to), GWLP_USERDATA, (LPARAM)(what))

/*
 * The value of TK_MULTI_MAX_PATH dictates how many files can be retrieved
 * with tk_get*File -multiple 1. It must be allocated on the stack, so make it
 * large enough but not too large. - hobbs
 *
 * The data is stored as <dir>\0<file1>\0<file2>\0...<fileN>\0\0. Since
 * MAX_PATH == 260 on Win2K/NT, *40 is ~10Kbytes.
 */

#define TK_MULTI_MAX_PATH	(MAX_PATH*40)

/*
 * The following structure is used to pass information between the directory
 * chooser function, Tk_ChooseDirectoryObjCmd(), and its dialog hook proc.
 */

typedef struct {
   WCHAR initDir[MAX_PATH];	/* Initial folder to use */
   WCHAR retDir[MAX_PATH];	/* Returned folder to use */
   TCHAR initDir[MAX_PATH];	/* Initial folder to use */
   TCHAR retDir[MAX_PATH];	/* Returned folder to use */
   Tcl_Interp *interp;
   int mustExist;		/* True if file must exist to return from
				 * callback */
} ChooseDir;

/*
 * The following structure is used to pass information between GetFileName
 * function and OFN dialog hook procedures. [Bug 2896501, Patch 2898255]
 */

typedef struct OFNData {
    Tcl_Interp *interp;		/* Interp, used only if debug is turned on,
				 * for setting the "tk_dialog" variable. */
    int dynFileBufferSize;	/* Dynamic filename buffer size, stored to
				 * avoid shrinking and expanding the buffer
				 * when selection changes */
    WCHAR *dynFileBuffer;	/* Dynamic filename buffer */
    TCHAR *dynFileBuffer;	/* Dynamic filename buffer */
} OFNData;

/*
 * The following structure is used to gather options used by various
 * file dialogs
 */
typedef struct OFNOpts {
    Tk_Window tkwin;            /* Owner window for dialog */
    Tcl_Obj *extObj;            /* Default extension */
    Tcl_Obj *titleObj;          /* Title for dialog */
    Tcl_Obj *filterObj;         /* File type filter list */
    Tcl_Obj *typeVariableObj;   /* Variable in which to store type selected */
    Tcl_Obj *initialTypeObj;    /* Initial value of above, or NULL */
    Tcl_DString utfDirString;   /* Initial dir */
    int multi;                  /* Multiple selection enabled */
    int confirmOverwrite;       /* Confirm before overwriting */
    int mustExist;              /* Used only for  */
    int forceXPStyle;          /* XXX - Force XP style even on newer systems */
    WCHAR file[TK_MULTI_MAX_PATH]; /* File name
    TCHAR file[TK_MULTI_MAX_PATH]; /* File name
                                      XXX - fixed size because it was so
                                      historically. Why not malloc'ed ?
                                      XXX - also, TCHAR should really be WCHAR
                                      because TkWinGetUnicodeEncoding is always
                                      UCS2.
                                   */
} OFNOpts;

/* Define the operation for which option parsing is to be done. */
enum OFNOper {
    OFN_FILE_SAVE,              /* tk_getOpenFile */
    OFN_FILE_OPEN,              /* tk_getSaveFile */
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440







-
+








    HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
        IFileSaveDialog *, REFIID, void **);
    ULONG ( STDMETHODCALLTYPE *AddRef )( IFileSaveDialog *);
    ULONG ( STDMETHODCALLTYPE *Release )( IFileSaveDialog *);
    HRESULT ( STDMETHODCALLTYPE *Show )(
        IFileSaveDialog *, HWND);
    HRESULT ( STDMETHODCALLTYPE *SetFileTypes )( IFileSaveDialog *,
    HRESULT ( STDMETHODCALLTYPE *SetFileTypes )( IFileSaveDialog * this,
        UINT, const TCLCOMDLG_FILTERSPEC *);
    HRESULT ( STDMETHODCALLTYPE *SetFileTypeIndex )(
        IFileSaveDialog *, UINT);
    HRESULT ( STDMETHODCALLTYPE *GetFileTypeIndex )(
         IFileSaveDialog *, UINT *);
    /* Actually pfde is IFileSaveDialogEvents* */
    HRESULT ( STDMETHODCALLTYPE *Advise )(
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589
590
591
592




593



























































594
595
596
597
598
599
600
571
572
573
574
575
576
577

578
579
580
581
582
583
584

585
586
587
588
589
590
591
592
593
594
595
596
597


598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668







-
+






-
+












-
-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 */

static UINT APIENTRY	ChooseDirectoryValidateProc(HWND hdlg, UINT uMsg,
			    LPARAM wParam, LPARAM lParam);
static UINT CALLBACK	ColorDlgHookProc(HWND hDlg, UINT uMsg, WPARAM wParam,
			    LPARAM lParam);
static void             CleanupOFNOptions(OFNOpts *optsPtr);
static int              ParseOFNOptions(void *clientData,
static int              ParseOFNOptions(ClientData clientData,
                            Tcl_Interp *interp, int objc,
                            Tcl_Obj *const objv[], enum OFNOper oper, OFNOpts *optsPtr);
static int GetFileNameXP(Tcl_Interp *interp, OFNOpts *optsPtr,
                         enum OFNOper oper);
static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr,
                            enum OFNOper oper);
static int 		GetFileName(void *clientData,
static int 		GetFileName(ClientData clientData,
                                    Tcl_Interp *interp, int objc,
                                    Tcl_Obj *const objv[], enum OFNOper oper);
static int MakeFilterVista(Tcl_Interp *interp, OFNOpts *optsPtr,
               DWORD *countPtr, TCLCOMDLG_FILTERSPEC **dlgFilterPtrPtr,
               DWORD *defaultFilterIndexPtr);
static void FreeFilterVista(DWORD count, TCLCOMDLG_FILTERSPEC *dlgFilterPtr);
static int 		MakeFilter(Tcl_Interp *interp, Tcl_Obj *valuePtr,
			    Tcl_DString *dsPtr, Tcl_Obj *initialPtr,
			    int *indexPtr);
static UINT APIENTRY	OFNHookProc(HWND hdlg, UINT uMsg, WPARAM wParam,
			    LPARAM lParam);
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam);
static void		SetTkDialog(void *clientData);
static const char *ConvertExternalFilename(LPCWSTR, Tcl_DString *);
static void		SetTkDialog(ClientData clientData);
static const char *ConvertExternalFilename(TCHAR *filename,
			    Tcl_DString *dsPtr);
static void             LoadShellProcs(void);


/* Definitions of dynamically loaded Win32 calls */
typedef HRESULT (STDAPICALLTYPE SHCreateItemFromParsingNameProc)(
    PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv);
struct ShellProcPointers {
    SHCreateItemFromParsingNameProc *SHCreateItemFromParsingName;
} ShellProcs;


/*
 *-------------------------------------------------------------------------
 *
 * LoadShellProcs --
 *
 *     Some shell functions are not available on older versions of
 *     Windows. This function dynamically loads them and stores pointers
 *     to them in ShellProcs. Any function that is not available has
 *     the corresponding pointer set to NULL.
 *
 *     Note this call never fails. Unavailability of a function is not
 *     a reason for failure. Caller should check whether a particular
 *     function pointer is NULL or not. Once loaded a function stays
 *     forever loaded.
 *
 *     XXX - we load the function pointers into global memory. This implies
 *     there is a potential (however small) for race conditions between
 *     threads. However, Tk is in any case meant to be loaded in exactly
 *     one thread so this should not be an issue and saves us from
 *     unnecessary bookkeeping.
 *
 * Return value:
 *     None.
 *
 * Side effects:
 *     ShellProcs is populated.
 *-------------------------------------------------------------------------
 */
static void LoadShellProcs()
{
    static HMODULE shell32_handle = NULL;

    if (shell32_handle != NULL)
        return; /* We have already been through here. */

    /*
     * XXX - Note we never call FreeLibrary. There is no point because
     * shell32.dll is loaded at startup anyways and stays for the duration
     * of the process so why bother with keeping track of when to unload
     */
    shell32_handle = LoadLibrary(TEXT("shell32.dll"));
    if (shell32_handle == NULL) /* Should never happen but check anyways. */
        return;

    ShellProcs.SHCreateItemFromParsingName =
        (SHCreateItemFromParsingNameProc*) GetProcAddress(shell32_handle,
                                                         "SHCreateItemFromParsingName");
}


/*
 *-------------------------------------------------------------------------
 *
 * EatSpuriousMessageBugFix --
 *
 *	In the file open/save dialog, double clicking on a list item causes
 *	the dialog box to close, but an unwanted WM_LBUTTONUP message is sent
632
633
634
635
636
637
638
639

640
641
642
643
644
645
646
700
701
702
703
704
705
706

707
708
709
710
711
712
713
714







-
+







static void
EatSpuriousMessageBugFix(void)
{
    MSG msg;
    DWORD nTime = GetTickCount() + 250;

    while (GetTickCount() < nTime) {
	PeekMessageW(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
	PeekMessage(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
    }
}

/*
 *-------------------------------------------------------------------------
 *
 * TkWinDialogDebug --
659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741







-
+







 *-------------------------------------------------------------------------
 */

void
TkWinDialogDebug(
    int debug)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    tsdPtr->debugFlag = debug;
}

/*
 *-------------------------------------------------------------------------
686
687
688
689
690
691
692
693

694
695
696
697
698

699
700
701

702
703
704
705
706
707
708
754
755
756
757
758
759
760

761
762
763
764
765

766
767
768

769
770
771
772
773
774
775
776







-
+




-
+


-
+







 *	application invokes the "tk_chooseColor" command.
 *
 *-------------------------------------------------------------------------
 */

int
Tk_ChooseColorObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData, parent;
    Tk_Window tkwin = clientData, parent;
    HWND hWnd;
    int i, oldMode, winCode, result;
    CHOOSECOLORW chooseColor;
    CHOOSECOLOR chooseColor;
    static int inited = 0;
    static COLORREF dwCustColors[16];
    static long oldColor;		/* the color selected last time */
    static const char *const optionStrings[] = {
	"-initialcolor", "-parent", "-title", NULL
    };
    enum options {
722
723
724
725
726
727
728
729

730
731
732
733
734
735
736
737


738
739
740
741
742
743
744
745
746
747
748


749
750
751
752
753
754
755
790
791
792
793
794
795
796

797
798
799
800
801
802
803


804
805
806
807
808
809
810
811
812
813
814


815
816
817
818
819
820
821
822
823







-
+






-
-
+
+









-
-
+
+







	    dwCustColors[i] = RGB(255-i * 10, i, i * 10);
	}
	oldColor = RGB(0xa0, 0xa0, 0xa0);
	inited = 1;
    }

    parent			= tkwin;
    chooseColor.lStructSize	= sizeof(CHOOSECOLORW);
    chooseColor.lStructSize	= sizeof(CHOOSECOLOR);
    chooseColor.hwndOwner	= NULL;
    chooseColor.hInstance	= NULL;
    chooseColor.rgbResult	= oldColor;
    chooseColor.lpCustColors	= dwCustColors;
    chooseColor.Flags		= CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK;
    chooseColor.lCustData	= (LPARAM) NULL;
    chooseColor.lpfnHook	= (LPOFNHOOKPROC)(void *)ColorDlgHookProc;
    chooseColor.lpTemplateName	= (LPWSTR) interp;
    chooseColor.lpfnHook	= (LPOFNHOOKPROC) ColorDlgHookProc;
    chooseColor.lpTemplateName	= (LPTSTR) interp;

    for (i = 1; i < objc; i += 2) {
	int index;
	const char *string;
	Tcl_Obj *optionPtr, *valuePtr;

	optionPtr = objv[i];
	valuePtr = objv[i + 1];

	if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings,
		"option", TCL_EXACT, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, optionPtr, optionStrings,
		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (i + 1 == objc) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "value for \"%s\" missing", Tcl_GetString(optionPtr)));
	    Tcl_SetErrorCode(interp, "TK", "COLORDIALOG", "VALUE", NULL);
	    return TCL_ERROR;
782
783
784
785
786
787
788
789

790
791
792
793
794
795
796
850
851
852
853
854
855
856

857
858
859
860
861
862
863
864







-
+








    Tk_MakeWindowExist(parent);
    chooseColor.hwndOwner = NULL;
    hWnd = Tk_GetHWND(Tk_WindowId(parent));
    chooseColor.hwndOwner = hWnd;

    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
    winCode = ChooseColorW(&chooseColor);
    winCode = ChooseColor(&chooseColor);
    (void) Tcl_SetServiceMode(oldMode);

    /*
     * Ensure that hWnd is enabled, because it can happen that we have updated
     * the wrapper of the parent, which causes us to leave this child disabled
     * (Windows loses sync).
     */
842
843
844
845
846
847
848
849

850
851
852

853
854
855

856
857
858
859
860
861
862
863

864
865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880
881
882
883
884
885

886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901

902
903
904
905
906
907
908
909
910
911
912

913
914

915
916
917
918

919
920
921

922
923
924
925
926
927
928

929
930
931
932
933
934
935
910
911
912
913
914
915
916

917
918
919

920
921
922

923
924
925
926
927
928
929
930

931
932
933
934
935
936


937
938
939
940
941
942
943
944
945
946
947
948
949
950
951

952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967

968
969
970
971
972
973
974
975
976
977
978

979
980

981
982
983
984

985
986
987

988
989
990
991
992
993
994

995
996
997
998
999
1000
1001
1002







-
+


-
+


-
+







-
+





-
-
+














-
+















-
+










-
+

-
+



-
+


-
+






-
+







 *----------------------------------------------------------------------
 */

static UINT CALLBACK
ColorDlgHookProc(
    HWND hDlg,			/* Handle to the color dialog. */
    UINT uMsg,			/* Type of message. */
    TCL_UNUSED(WPARAM),	/* First message parameter. */
    WPARAM wParam,		/* First message parameter. */
    LPARAM lParam)		/* Second message parameter. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    const char *title;
    CHOOSECOLORW *ccPtr;
    CHOOSECOLOR *ccPtr;

    if (WM_INITDIALOG == uMsg) {

	/*
	 * Set the title string of the dialog.
	 */

	ccPtr = (CHOOSECOLORW *) lParam;
	ccPtr = (CHOOSECOLOR *) lParam;
	title = (const char *) ccPtr->lCustData;

	if ((title != NULL) && (title[0] != '\0')) {
	    Tcl_DString ds;

	    Tcl_DStringInit(&ds);
	    SetWindowTextW(hDlg, Tcl_UtfToWCharDString(title, TCL_INDEX_NONE, &ds));
	    SetWindowText(hDlg, Tcl_WinUtfToTChar(title,-1,&ds));
	    Tcl_DStringFree(&ds);
	}
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
	    Tcl_DoWhenIdle(SetTkDialog, hDlg);
	}
	return TRUE;
    }
    return FALSE;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOpenFileObjCmd --
 * Tk_GetOpenFileCmd --
 *
 *	This function implements the "open file" dialog box for the Windows
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	See user documentation.
 *
 * Side effects:
 *	A dialog window is created the first this function is called.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetOpenFileObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    return GetFileName(clientData, interp, objc, objv, OFN_FILE_OPEN);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetSaveFileObjCmd --
 * Tk_GetSaveFileCmd --
 *
 *	Same as Tk_GetOpenFileObjCmd but opens a "save file" dialog box
 *	Same as Tk_GetOpenFileCmd but opens a "save file" dialog box
 *	instead
 *
 * Results:
 *	Same as Tk_GetOpenFileObjCmd.
 *	Same as Tk_GetOpenFileCmd.
 *
 * Side effects:
 *	Same as Tk_GetOpenFileObjCmd.
 *	Same as Tk_GetOpenFileCmd.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetSaveFileObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    return GetFileName(clientData, interp, objc, objv, OFN_FILE_SAVE);
}

968
969
970
971
972
973
974
975

976
977
978
979
980
981
982
1035
1036
1037
1038
1039
1040
1041

1042
1043
1044
1045
1046
1047
1048
1049







-
+







 *	Returns option values in *optsPtr. Note these may include string
 *      pointers into objv[]
 *----------------------------------------------------------------------
 */

static int
ParseOFNOptions(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    enum OFNOper oper,			/* 1 for Open, 0 for Save */
    OFNOpts *optsPtr)           /* Output, uninitialized on entry */
{
    int i;
1010
1011
1012
1013
1014
1015
1016
1017

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052

1053
1054
1055
1056
1057
1058
1059
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097



1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1126







-
+













-
-
-
+
+
+


















-
+







	{"-parent",		FILE_PARENT},
	{"-title",		FILE_TITLE},
	{"-typevariable",	FILE_TYPEVARIABLE},
	{NULL,			FILE_DEFAULT/*ignored*/ }
    };
    static const struct Options dirOptions[] = {
	{"-initialdir", FILE_INITDIR},
	{"-mustexist",  FILE_MUSTEXIST},
        {"-mustexist",  FILE_MUSTEXIST},
	{"-parent",	FILE_PARENT},
	{"-title",	FILE_TITLE},
	{NULL,		FILE_DEFAULT/*ignored*/ }
    };

    const struct Options *options = NULL;

    switch (oper) {
    case OFN_FILE_SAVE: options = saveOptions; break;
    case OFN_DIR_CHOOSE: options = dirOptions; break;
    case OFN_FILE_OPEN: options = openOptions; break;
    }

    memset(optsPtr, 0, sizeof(*optsPtr));
    /* optsPtr->forceXPStyle = 1; */
    optsPtr->tkwin = (Tk_Window)clientData;
    ZeroMemory(optsPtr, sizeof(*optsPtr));
    // optsPtr->forceXPStyle = 1;
    optsPtr->tkwin = clientData;
    optsPtr->confirmOverwrite = 1; /* By default we ask for confirmation */
    Tcl_DStringInit(&optsPtr->utfDirString);
    optsPtr->file[0] = 0;

    for (i = 1; i < objc; i += 2) {
	int index;
	const char *string;
	Tcl_Obj *valuePtr;

	if (Tcl_GetIndexFromObjStruct(interp, objv[i], options,
		sizeof(struct Options), "option", 0, &index) != TCL_OK) {
            /*
             * XXX -xpstyle is explicitly checked for as it is undocumented
             * and we do not want it to show in option error messages.
             */
            if (strcmp(Tcl_GetString(objv[i]), "-xpstyle"))
                goto error_return;
            if (i + 1 == objc) {
                Tcl_SetObjResult(interp, Tcl_NewStringObj("value for \"-xpstyle\" missing", TCL_INDEX_NONE));
                Tcl_SetObjResult(interp, Tcl_NewStringObj("value for \"-xpstyle\" missing", -1));
                Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL);
                goto error_return;
            }
	    if (Tcl_GetBooleanFromObj(interp, objv[i+1],
                                      &optsPtr->forceXPStyle) != TCL_OK)
                goto error_return;

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090



1091
1092
1093
1094

1095
1096
1097
1098
1099
1100
1101
1148
1149
1150
1151
1152
1153
1154



1155
1156
1157
1158
1159
1160

1161
1162
1163
1164
1165
1166
1167
1168







-
-
-
+
+
+



-
+







                                      &optsPtr->utfDirString) == NULL)
		goto error_return;
	    break;
	case FILE_INITFILE:
	    if (Tcl_TranslateFileName(interp, string, &ds) == NULL)
		goto error_return;
	    Tcl_UtfToExternal(NULL, TkWinGetUnicodeEncoding(),
                              Tcl_DStringValue(&ds), Tcl_DStringLength(&ds),
                              TCL_ENCODING_PROFILE_TCL8, NULL, (char *)&optsPtr->file[0],
                              sizeof(optsPtr->file), NULL, NULL, NULL);
                              Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), 0, NULL,
                              (char *) &optsPtr->file[0], sizeof(optsPtr->file),
                              NULL, NULL, NULL);
	    Tcl_DStringFree(&ds);
	    break;
	case FILE_PARENT:
	    optsPtr->tkwin = Tk_NameToWindow(interp, string, (Tk_Window)clientData);
	    optsPtr->tkwin = Tk_NameToWindow(interp, string, clientData);
	    if (optsPtr->tkwin == NULL)
		goto error_return;
	    break;
	case FILE_TITLE:
	    optsPtr->titleObj = valuePtr;
	    break;
	case FILE_TYPEVARIABLE:
1142
1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153

1154
1155
1156
1157
1158
1159





1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170











1171
1172
1173
1174
1175
1176






1177
1178
1179
1180
1181
1182
1183
1209
1210
1211
1212
1213
1214
1215

1216
1217
1218
1219

1220
1221
1222
1223



1224
1225
1226
1227
1228
1229










1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241





1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254







-
+



-
+



-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+







 *      1 if new dialogs are available, 0 otherwise
 *
 * Side effects:
 *      Loads required procedures dynamically if available.
 *      If new dialogs are available, COM is also initialized.
 *----------------------------------------------------------------------
 */
static int VistaFileDialogsAvailable(void)
static int VistaFileDialogsAvailable()
{
    HRESULT hr;
    IFileDialog *fdlgPtr = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
        Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->newFileDialogsState == FDLG_STATE_INIT) {
	tsdPtr->newFileDialogsState = FDLG_STATE_USE_OLD;
	hr = CoInitialize(0);
	/* XXX - need we schedule CoUninitialize at thread shutdown ? */
        tsdPtr->newFileDialogsState = FDLG_STATE_USE_OLD;
        LoadShellProcs();
        if (ShellProcs.SHCreateItemFromParsingName != NULL) {
            hr = CoInitialize(0);
            /* XXX - need we schedule CoUninitialize at thread shutdown ? */

	/* Ensure all COM interfaces we use are available */
	if (SUCCEEDED(hr)) {
	    hr = CoCreateInstance(&ClsidFileOpenDialog, NULL,
		    CLSCTX_INPROC_SERVER, &IIDIFileOpenDialog, (void **) &fdlgPtr);
	    if (SUCCEEDED(hr)) {
		fdlgPtr->lpVtbl->Release(fdlgPtr);
		hr = CoCreateInstance(&ClsidFileSaveDialog, NULL,
			CLSCTX_INPROC_SERVER, &IIDIFileSaveDialog, (void **) &fdlgPtr);
		if (SUCCEEDED(hr)) {
		    fdlgPtr->lpVtbl->Release(fdlgPtr);
            /* Ensure all COM interfaces we use are available */
            if (SUCCEEDED(hr)) {
                hr = CoCreateInstance(&ClsidFileOpenDialog, NULL,
                                      CLSCTX_INPROC_SERVER, &IIDIFileOpenDialog, (void **) &fdlgPtr);
                if (SUCCEEDED(hr)) {
                    fdlgPtr->lpVtbl->Release(fdlgPtr);
                    hr = CoCreateInstance(&ClsidFileSaveDialog, NULL,
                             CLSCTX_INPROC_SERVER, &IIDIFileSaveDialog,
                                          (void **) &fdlgPtr);
                    if (SUCCEEDED(hr)) {
                        fdlgPtr->lpVtbl->Release(fdlgPtr);

		    /* Looks like we have all we need */
		    tsdPtr->newFileDialogsState = FDLG_STATE_USE_NEW;
		}
	    }
	}
                        /* Looks like we have all we need */
                        tsdPtr->newFileDialogsState = FDLG_STATE_USE_NEW;
                    }
                }
            }
        }
    }

    return (tsdPtr->newFileDialogsState == FDLG_STATE_USE_NEW);
}

/*
 *----------------------------------------------------------------------
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1275
1276
1277
1278
1279
1280
1281

1282
1283
1284
1285
1286
1287
1288
1289







-
+







    HWND hWnd;
    DWORD flags, nfilters, defaultFilterIndex;
    TCLCOMDLG_FILTERSPEC *filterPtr = NULL;
    IFileDialog *fdlgIf = NULL;
    IShellItem *dirIf = NULL;
    LPWSTR wstr;
    Tcl_Obj *resultObj = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    int oldMode;

    if (tsdPtr->newFileDialogsState != FDLG_STATE_USE_NEW) {
	Tcl_Panic("Internal error: GetFileNameVista: IFileDialog API not available");
	return TCL_ERROR;
    }
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317


1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331

1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348
1349
1350
1351

1352
1353

1354
1355

1356
1357
1358
1359
1360
1361
1362
1379
1380
1381
1382
1383
1384
1385



1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399


1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414

1415
1416
1417
1418
1419

1420
1421

1422
1423

1424
1425
1426
1427
1428
1429
1430
1431







-
-
-
+
+












-
-
+














-
+




-
+

-
+

-
+







        goto vamoose;

    if (optsPtr->extObj != NULL) {
        Tcl_DString ds;
        const char *src;

        src = Tcl_GetString(optsPtr->extObj);
        Tcl_DStringInit(&ds);
        wstr = Tcl_UtfToWCharDString(src, optsPtr->extObj->length, &ds);
        if (wstr[0] == '.')
        wstr = (LPWSTR) Tcl_WinUtfToTChar(src, optsPtr->extObj->length, &ds);
        if (wstr[0] == L'.')
            ++wstr;
        hr = fdlgIf->lpVtbl->SetDefaultExtension(fdlgIf, wstr);
        Tcl_DStringFree(&ds);
        if (FAILED(hr))
            goto vamoose;
    }

    if (optsPtr->titleObj != NULL) {
        Tcl_DString ds;
        const char *src;

        src = Tcl_GetString(optsPtr->titleObj);
        Tcl_DStringInit(&ds);
        wstr = Tcl_UtfToWCharDString(src, optsPtr->titleObj->length, &ds);
        wstr = (LPWSTR) Tcl_WinUtfToTChar(src, optsPtr->titleObj->length, &ds);
        hr = fdlgIf->lpVtbl->SetTitle(fdlgIf, wstr);
        Tcl_DStringFree(&ds);
        if (FAILED(hr))
            goto vamoose;
    }

    if (optsPtr->file[0]) {
        hr = fdlgIf->lpVtbl->SetFileName(fdlgIf, optsPtr->file);
        if (FAILED(hr))
            goto vamoose;
    }

    if (Tcl_DStringValue(&optsPtr->utfDirString)[0] != '\0') {
        Tcl_Obj *normPath, *iniDirPath;
        iniDirPath = Tcl_NewStringObj(Tcl_DStringValue(&optsPtr->utfDirString), TCL_INDEX_NONE);
        iniDirPath = Tcl_NewStringObj(Tcl_DStringValue(&optsPtr->utfDirString), -1);
        Tcl_IncrRefCount(iniDirPath);
        normPath = Tcl_FSGetNormalizedPath(interp, iniDirPath);
        /* XXX - Note on failures do not raise error, simply ignore ini dir */
        if (normPath) {
            LPCWSTR nativePath;
            const WCHAR *nativePath;
            Tcl_IncrRefCount(normPath);
            nativePath = (LPCWSTR)Tcl_FSGetNativePath(normPath); /* Points INTO normPath*/
            nativePath = Tcl_FSGetNativePath(normPath); /* Points INTO normPath*/
            if (nativePath) {
                hr = SHCreateItemFromParsingName(
                hr = ShellProcs.SHCreateItemFromParsingName(
                    nativePath, NULL,
                    &IIDIShellItem, (void **) &dirIf);
                if (SUCCEEDED(hr)) {
                    /* Note we use SetFolder, not SetDefaultFolder - see MSDN */
                    fdlgIf->lpVtbl->SetFolder(fdlgIf, dirIf); /* Ignore errors */
                }
            }
1377
1378
1379
1380
1381
1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460







-
+







     */

    if (hWnd)
        EnableWindow(hWnd, 1);

    /*
     * Clear interp result since it might have been set during the modal loop.
     * https://core.tcl-lang.org/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
     * http://core.tcl.tk/tk/tktview/4a0451f5291b3c9168cc560747dae9264e1d2ef6
     */
    Tcl_ResetResult(interp);

    if (SUCCEEDED(hr)) {
        if ((oper == OFN_FILE_OPEN) && optsPtr->multi) {
            IShellItemArray *multiIf;
            DWORD dw, count;
1450
1451
1452
1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1519
1520
1521
1522
1523
1524
1525


1526
1527
1528
1529
1530
1531
1532
1533







-
-
+







                hr = fdlgIf->lpVtbl->GetFileTypeIndex(fdlgIf, &ftix);
                if (SUCCEEDED(hr)) {
                    /* Note ftix is a 1-based index */
                    if (ftix > 0 && ftix <= nfilters) {
                        Tcl_DString ftds;
                        Tcl_Obj *ftobj;

                        Tcl_DStringInit(&ftds);
                        Tcl_WCharToUtfDString(filterPtr[ftix-1].pszName, wcslen(filterPtr[ftix-1].pszName), &ftds);
                        Tcl_WinTCharToUtf(filterPtr[ftix-1].pszName, -1, &ftds);
                        ftobj = Tcl_NewStringObj(Tcl_DStringValue(&ftds),
                                Tcl_DStringLength(&ftds));
                        Tcl_ObjSetVar2(interp, optsPtr->typeVariableObj, NULL,
                                ftobj, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
                        Tcl_DStringFree(&ftds);
                    }
                }
1505
1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545

1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565

1566
1567
1568
1569
1570
1571



1572
1573
1574


1575
1576
1577
1578

1579

1580
1581
1582
1583
1584

1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603
1604
1605
1606

1607
1608
1609
1610


1611
1612
1613
1614
1615
1616
1617
1618
1619

1620
1621

1622
1623
1624
1625
1626
1627
1628
1573
1574
1575
1576
1577
1578
1579

1580
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590

1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612

1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634
1635
1636



1637
1638
1639



1640
1641
1642
1643


1644
1645
1646
1647
1648
1649


1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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







-
+







-
+


-
+













-
+







-
+



















-
+



-
-
-
+
+
+
-
-
-
+
+


-
-
+

+



-
-
+















-
-
+




-
+


-
-
+
+








-
+

-
+







 *
 * Side effects:
 *      See user documentation.
 *----------------------------------------------------------------------
 */
static int GetFileNameXP(Tcl_Interp *interp, OFNOpts *optsPtr, enum OFNOper oper)
{
    OPENFILENAMEW ofn;
    OPENFILENAME ofn;
    OFNData ofnData;
    int cdlgerr;
    int filterIndex = 0, result = TCL_ERROR, winCode, oldMode;
    HWND hWnd;
    Tcl_DString utfFilterString, ds;
    Tcl_DString extString, filterString, dirString, titleString;
    const char *str;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
        Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    memset(&ofnData, 0, sizeof(OFNData));
    ZeroMemory(&ofnData, sizeof(OFNData));
    Tcl_DStringInit(&utfFilterString);
    Tcl_DStringInit(&dirString); /* XXX - original code was missing this
                                    leaving dirString uninitialized for
                                    the unlikely code path where cwd failed */

    if (MakeFilter(interp, optsPtr->filterObj, &utfFilterString,
                   optsPtr->initialTypeObj, &filterIndex) != TCL_OK) {
	goto end;
    }

    Tk_MakeWindowExist(optsPtr->tkwin);
    hWnd = Tk_GetHWND(Tk_WindowId(optsPtr->tkwin));

    memset(&ofn, 0, sizeof(OPENFILENAME));
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hWnd;
    ofn.hInstance = TkWinGetHInstance(ofn.hwndOwner);
    ofn.lpstrFile = optsPtr->file;
    ofn.nMaxFile = TK_MULTI_MAX_PATH;
    ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR
	    | OFN_EXPLORER| OFN_ENABLEHOOK| OFN_ENABLESIZING;
    ofn.lpfnHook = (LPOFNHOOKPROC)(void *)OFNHookProc;
    ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProc;
    ofn.lCustData = (LPARAM) &ofnData;

    if (oper != OFN_FILE_SAVE) {
	ofn.Flags |= OFN_FILEMUSTEXIST;
    } else if (optsPtr->confirmOverwrite) {
	ofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if (tsdPtr->debugFlag != 0) {
	ofnData.interp = interp;
    }
    if (optsPtr->multi != 0) {
	ofn.Flags |= OFN_ALLOWMULTISELECT;

	/*
	 * Starting buffer size. The buffer will be expanded by the OFN dialog
	 * procedure when necessary
	 */

	ofnData.dynFileBufferSize = 512;
	ofnData.dynFileBuffer = (WCHAR *)ckalloc(512 * sizeof(WCHAR));
	ofnData.dynFileBuffer = ckalloc(512 * sizeof(TCHAR));
    }

    if (optsPtr->extObj != NULL) {
	str = Tcl_GetString(optsPtr->extObj);
	if (str[0] == '.') {
	    ++str;
        str = Tcl_GetString(optsPtr->extObj);
        if (str[0] == '.')
            ++str;
	}
	Tcl_DStringInit(&extString);
	ofn.lpstrDefExt = Tcl_UtfToWCharDString(str, TCL_INDEX_NONE, &extString);
	Tcl_WinUtfToTChar(str, -1, &extString);
	ofn.lpstrDefExt = (TCHAR *) Tcl_DStringValue(&extString);
    }

    Tcl_DStringInit(&filterString);
    ofn.lpstrFilter = Tcl_UtfToWCharDString(Tcl_DStringValue(&utfFilterString),
    Tcl_WinUtfToTChar(Tcl_DStringValue(&utfFilterString),
	    Tcl_DStringLength(&utfFilterString), &filterString);
    ofn.lpstrFilter = (TCHAR *) Tcl_DStringValue(&filterString);
    ofn.nFilterIndex = filterIndex;

    if (Tcl_DStringValue(&optsPtr->utfDirString)[0] != '\0') {
	Tcl_DStringInit(&dirString);
	Tcl_UtfToWCharDString(Tcl_DStringValue(&optsPtr->utfDirString),
	Tcl_WinUtfToTChar(Tcl_DStringValue(&optsPtr->utfDirString),
		Tcl_DStringLength(&optsPtr->utfDirString), &dirString);
    } else {
	/*
	 * NT 5.0 changed the meaning of lpstrInitialDir, so we have to ensure
	 * that we set the [pwd] if the user didn't specify anything else.
	 */

	Tcl_DString cwd;

	Tcl_DStringFree(&optsPtr->utfDirString);
	if ((Tcl_GetCwd(interp, &optsPtr->utfDirString) == NULL) ||
		(Tcl_TranslateFileName(interp,
                     Tcl_DStringValue(&optsPtr->utfDirString), &cwd) == NULL)) {
	    Tcl_ResetResult(interp);
	} else {
		Tcl_DStringInit(&dirString);
		Tcl_UtfToWCharDString(Tcl_DStringValue(&cwd),
	    Tcl_WinUtfToTChar(Tcl_DStringValue(&cwd),
		    Tcl_DStringLength(&cwd), &dirString);
	}
	Tcl_DStringFree(&cwd);
    }
    ofn.lpstrInitialDir = (WCHAR *) Tcl_DStringValue(&dirString);
    ofn.lpstrInitialDir = (TCHAR *) Tcl_DStringValue(&dirString);

    if (optsPtr->titleObj != NULL) {
	Tcl_DStringInit(&titleString);
	ofn.lpstrTitle = Tcl_UtfToWCharDString(Tcl_GetString(optsPtr->titleObj), TCL_INDEX_NONE, &titleString);
	Tcl_WinUtfToTChar(Tcl_GetString(optsPtr->titleObj), -1, &titleString);
	ofn.lpstrTitle = (TCHAR *) Tcl_DStringValue(&titleString);
    }

    /*
     * Popup the dialog.
     */

    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
    if (oper != OFN_FILE_SAVE) {
	winCode = GetOpenFileNameW(&ofn);
	winCode = GetOpenFileName(&ofn);
    } else {
	winCode = GetSaveFileNameW(&ofn);
	winCode = GetSaveFileName(&ofn);
    }
    Tcl_SetServiceMode(oldMode);
    EatSpuriousMessageBugFix();

    /*
     * Ensure that hWnd is enabled, because it can happen that we have updated
     * the wrapper of the parent, which causes us to leave this child disabled
1650
1651
1652
1653
1654
1655
1656
1657

1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675

1676
1677
1678
1679
1680
1681
1682
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







-
+

















-
+







     */

    cdlgerr = CommDlgExtendedError();

    /*
     * We now allow FNERR_BUFFERTOOSMALL when multiselection is enabled. The
     * filename buffer has been dynamically allocated by the OFN dialog
     * procedure to accommodate all selected files.
     * procedure to accomodate all selected files.
     */

    if ((winCode != 0)
	    || ((cdlgerr == FNERR_BUFFERTOOSMALL)
		    && (ofn.Flags & OFN_ALLOWMULTISELECT))) {
	int gotFilename = 0;	/* Flag for tracking whether we have any
				 * filename at all. For details, see
				 * http://stackoverflow.com/q/9227859/301832
				 */

	if (ofn.Flags & OFN_ALLOWMULTISELECT) {
	    /*
	     * The result in dynFileBuffer contains many items, separated by
	     * NUL characters. It is terminated with two nulls in a row. The
	     * first element is the directory path.
	     */

	    WCHAR *files = ofnData.dynFileBuffer;
	    TCHAR *files = ofnData.dynFileBuffer;
	    Tcl_Obj *returnList = Tcl_NewObj();
	    int count = 0;

	    /*
	     * Get directory.
	     */

1692
1693
1694
1695
1696
1697
1698
1699

1700
1701
1702
1703
1704
1705
1706
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
1771







-
+







		    Tcl_DString filenameBuf;

		    count++;
		    ConvertExternalFilename(files, &filenameBuf);

		    fullnameObj = Tcl_NewStringObj(Tcl_DStringValue(&ds),
			    Tcl_DStringLength(&ds));
		    Tcl_AppendToObj(fullnameObj, "/", TCL_INDEX_NONE);
		    Tcl_AppendToObj(fullnameObj, "/", -1);
		    Tcl_AppendToObj(fullnameObj, Tcl_DStringValue(&filenameBuf),
			    Tcl_DStringLength(&filenameBuf));
		    gotFilename = 1;
		    Tcl_DStringFree(&filenameBuf);
		    Tcl_ListObjAppendElement(NULL, returnList, fullnameObj);
		}
	    }
1715
1716
1717
1718
1719
1720
1721
1722

1723
1724
1725
1726
1727
1728
1729

1730
1731
1732
1733
1734
1735
1736
1780
1781
1782
1783
1784
1785
1786

1787
1788
1789
1790
1791
1792
1793

1794
1795
1796
1797
1798
1799
1800
1801







-
+






-
+







				Tcl_DStringLength(&ds)));
		gotFilename |= (Tcl_DStringLength(&ds) > 0);
	    }
	    Tcl_SetObjResult(interp, returnList);
	    Tcl_DStringFree(&ds);
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    ConvertExternalFilename(ofn.lpstrFile, &ds), TCL_INDEX_NONE));
		    ConvertExternalFilename(ofn.lpstrFile, &ds), -1));
	    gotFilename = (Tcl_DStringLength(&ds) > 0);
	    Tcl_DStringFree(&ds);
	}
	result = TCL_OK;
	if ((ofn.nFilterIndex > 0) && gotFilename && optsPtr->typeVariableObj
		&& optsPtr->filterObj) {
	    Tcl_Size listObjc, count;
	    int listObjc, count;
	    Tcl_Obj **listObjv = NULL;
	    Tcl_Obj **typeInfo = NULL;

	    if (Tcl_ListObjGetElements(interp, optsPtr->filterObj,
		    &listObjc, &listObjv) != TCL_OK) {
		result = TCL_ERROR;
	    } else if (Tcl_ListObjGetElements(interp,
1806
1807
1808
1809
1810
1811
1812
1813

1814
1815
1816
1817
1818
1819
1820
1871
1872
1873
1874
1875
1876
1877

1878
1879
1880
1881
1882
1883
1884
1885







-
+







 *	See user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
GetFileName(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[],	/* Argument objects. */
    enum OFNOper oper)  	/* 1 to call GetOpenFileName(), 0 to call
				 * GetSaveFileName(). */
{
    OFNOpts ofnOpts;
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
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







-
+

















-
+


-
+









/*
 *-------------------------------------------------------------------------
 *
 * OFNHookProc --
 *
 *	Dialog box hook function. This is used to set the "tk_dialog"
 *	Dialog box hook function. This is used to sets the "tk_dialog"
 *	variable for test/debugging when the dialog is ready to receive
 *	messages. When multiple file selection is enabled this function
 *	is used to process the list of names.
 *
 * Results:
 *	Returns 0 to allow default processing of messages to occur.
 *
 * Side effects:
 *	None.
 *
 *-------------------------------------------------------------------------
 */

static UINT APIENTRY
OFNHookProc(
    HWND hdlg,			/* Handle to child dialog window. */
    UINT uMsg,			/* Message identifier */
    TCL_UNUSED(WPARAM),	/* Message parameter */
    WPARAM wParam,		/* Message parameter */
    LPARAM lParam)		/* Message parameter */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    OPENFILENAME *ofnPtr;
    OFNData *ofnData;

    if (uMsg == WM_INITDIALOG) {
	TkWinSetUserData(hdlg, lParam);
    } else if (uMsg == WM_NOTIFY) {
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
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







-
+












-
-
+
+









-
+




-
+


-
+








-
+







	 * operation so it should not incur any noticeable delay. See [Bug
	 * 2987995]
	 */

	if (notifyPtr->hdr.code == CDN_FILEOK ||
		notifyPtr->hdr.code == CDN_SELCHANGE) {
	    int dirsize, selsize;
	    WCHAR *buffer;
	    TCHAR *buffer;
	    int buffersize;

	    /*
	     * Change of selection. Unscramble the unholy mess that's in the
	     * selection buffer, resizing it if necessary.
	     */

	    ofnPtr = notifyPtr->lpOFN;
	    ofnData = (OFNData *) ofnPtr->lCustData;
	    buffer = ofnData->dynFileBuffer;
	    hdlg = GetParent(hdlg);

	    selsize = (int) SendMessageW(hdlg, CDM_GETSPEC, 0, 0);
	    dirsize = (int) SendMessageW(hdlg, CDM_GETFOLDERPATH, 0, 0);
	    selsize = (int) SendMessage(hdlg, CDM_GETSPEC, 0, 0);
	    dirsize = (int) SendMessage(hdlg, CDM_GETFOLDERPATH, 0, 0);
	    buffersize = (selsize + dirsize + 1);

	    /*
	     * Just empty the buffer if dirsize indicates an error. [Bug
	     * 3071836]
	     */

	    if ((selsize > 1) && (dirsize > 0)) {
		if (ofnData->dynFileBufferSize < buffersize) {
		    buffer = (WCHAR *)ckrealloc(buffer, buffersize * sizeof(WCHAR));
		    buffer = ckrealloc(buffer, buffersize * sizeof(TCHAR));
		    ofnData->dynFileBufferSize = buffersize;
		    ofnData->dynFileBuffer = buffer;
		}

		SendMessageW(hdlg, CDM_GETFOLDERPATH, dirsize, (LPARAM) buffer);
		SendMessage(hdlg, CDM_GETFOLDERPATH, dirsize, (LPARAM) buffer);
		buffer += dirsize;

		SendMessageW(hdlg, CDM_GETSPEC, selsize, (LPARAM) buffer);
		SendMessage(hdlg, CDM_GETSPEC, selsize, (LPARAM) buffer);

		/*
		 * If there are multiple files, delete the quotes and change
		 * every second quote to NULL terminator
		 */

		if (buffer[0] == '"') {
		    BOOL findquote = TRUE;
		    WCHAR *tmp = buffer;
		    TCHAR *tmp = buffer;

		    while (*buffer != '\0') {
			if (findquote) {
			    if (*buffer == '"') {
				findquote = FALSE;
			    }
			    buffer++;
1950
1951
1952
1953
1954
1955
1956
1957
1958


1959
1960
1961
1962
1963
1964
1965
2015
2016
2017
2018
2019
2020
2021


2022
2023
2024
2025
2026
2027
2028
2029
2030







-
-
+
+







		     */

		    Tcl_DString tmpfile;
		    ConvertExternalFilename(buffer, &tmpfile);
		    if (TCL_PATH_ABSOLUTE ==
			    Tcl_GetPathType(Tcl_DStringValue(&tmpfile))) {
			/* re-get the full path to the start of the buffer */
			buffer = ofnData->dynFileBuffer;
			SendMessageW(hdlg, CDM_GETSPEC, selsize, (LPARAM) buffer);
			buffer = (TCHAR *) ofnData->dynFileBuffer;
			SendMessage(hdlg, CDM_GETSPEC, selsize, (LPARAM) buffer);
		    } else {
			*(buffer-1) = '\\';
		    }
		    buffer[selsize] = '\0'; /* Second NULL terminator. */
		    Tcl_DStringFree(&tmpfile);
		}
	    } else {
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
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







-
+













-
+




-
+
+
















-
+








    if (flist.filters == NULL) {
	/*
	 * Use "All Files (*.*) as the default filter if none is specified
	 */
	const char *defaultFilter = "All Files (*.*)";

	p = filterStr = (char *)ckalloc(30);
	p = filterStr = ckalloc(30);

	strcpy(p, defaultFilter);
	p+= strlen(defaultFilter);

	*p++ = '\0';
	*p++ = '*';
	*p++ = '.';
	*p++ = '*';
	*p++ = '\0';
	*p++ = '\0';
	*p = '\0';

    } else {
	Tcl_Size len;
	size_t len;

	if (valuePtr == NULL) {
	    len = 0;
	} else {
	    (void) Tcl_GetStringFromObj(valuePtr, &len);
	    (void) Tcl_GetString(valuePtr);
	    len = valuePtr->length;
	}

	/*
	 * We format the filetype into a string understood by Windows: {"Text
	 * Documents" {.doc .txt} {TEXT}} becomes "Text Documents
	 * (*.doc,*.txt)\0*.doc;*.txt\0"
	 *
	 * See the Windows OPENFILENAME manual page for details on the filter
	 * string format.
	 */

	/*
	 * Since we may only add asterisks (*) to the filter, we need at most
	 * twice the size of the string to format the filter
	 */

	filterStr = (char *)ckalloc(len * 3);
	filterStr = ckalloc(len * 3);

	for (filterPtr = flist.filters, p = filterStr; filterPtr;
		filterPtr = filterPtr->next) {
	    const char *sep;
	    FileFilterClause *clausePtr;

	    /*
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
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







-
+




















-
+

-
+







	 * characters.
	 */

	*p++ = '\0';
	*p = '\0';
    }

    Tcl_DStringAppend(dsPtr, filterStr, p - filterStr);
    Tcl_DStringAppend(dsPtr, filterStr, (int) (p - filterStr));
    ckfree(filterStr);

    TkFreeFileFilters(&flist);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeFilterVista
 *
 *      Frees storage previously allocated by MakeFilterVista.
 *      count is the number of elements in dlgFilterPtr[]
 */
static void FreeFilterVista(DWORD count, TCLCOMDLG_FILTERSPEC *dlgFilterPtr)
{
    if (dlgFilterPtr != NULL) {
        DWORD dw;
        for (dw = 0; dw < count; ++dw) {
            if (dlgFilterPtr[dw].pszName != NULL)
                ckfree((void *)dlgFilterPtr[dw].pszName);
                ckfree(dlgFilterPtr[dw].pszName);
            if (dlgFilterPtr[dw].pszSpec != NULL)
                ckfree((void *)dlgFilterPtr[dw].pszSpec);
                ckfree(dlgFilterPtr[dw].pszSpec);
        }
        ckfree(dlgFilterPtr);
    }
}

/*
 *----------------------------------------------------------------------
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
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







-
+




-
-
-
+
+
+

-
-
+
+


-
+
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-

-
-
+
+
-







        *dlgFilterPtrPtr = NULL;
        *countPtr = 0;
        return TCL_OK;
    }

    Tcl_DStringInit(&ds);
    Tcl_DStringInit(&patterns);
    dlgFilterPtr = (TCLCOMDLG_FILTERSPEC *)ckalloc(flist.numFilters * sizeof(*dlgFilterPtr));
    dlgFilterPtr = ckalloc(flist.numFilters * sizeof(*dlgFilterPtr));

    for (i = 0, filterPtr = flist.filters;
         filterPtr;
         filterPtr = filterPtr->next, ++i) {
	const char *sep;
	FileFilterClause *clausePtr;
	size_t nbytes;
        const char *sep;
        FileFilterClause *clausePtr;
        int nbytes;

	/* Check if this entry should be shown as the default */
	if (initial && strcmp(initial, filterPtr->name) == 0)
        /* Check if this entry should be shown as the default */
        if (initial && strcmp(initial, filterPtr->name) == 0)
            initialIndex = i+1; /* Windows filter indices are 1-based */

	/* First stash away the text description of the pattern */
        /* First stash away the text description of the pattern */
        Tcl_DStringInit(&ds);
        Tcl_UtfToWCharDString(filterPtr->name, TCL_INDEX_NONE, &ds);
	nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
	nbytes += sizeof(WCHAR);         /* Terminating \0 */
	dlgFilterPtr[i].pszName = (LPCWSTR)ckalloc(nbytes);
	memmove((void *) dlgFilterPtr[i].pszName, Tcl_DStringValue(&ds), nbytes);
	Tcl_DStringFree(&ds);
	Tcl_WinUtfToTChar(filterPtr->name, -1, &ds);
        nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
        nbytes += sizeof(WCHAR);         /* Terminating \0 */
        dlgFilterPtr[i].pszName = ckalloc(nbytes);
        memmove((void *) dlgFilterPtr[i].pszName, Tcl_DStringValue(&ds), nbytes);
        Tcl_DStringFree(&ds);

	/*
	 * Loop through and join patterns with a ";" Each "clause"
	 * corresponds to a single textual description (called typename)
	 * in the tk_getOpenFile docs. Each such typename may occur
	 * multiple times and all these form a single filter entry
	 * with one clause per occurence. Further each clause may specify
	 * multiple patterns. Hence the nested loop here.
	 */
	sep = "";
	for (clausePtr=filterPtr->clauses ; clausePtr;
	     clausePtr=clausePtr->next) {
	    GlobPattern *globPtr;
	    for (globPtr = clausePtr->patterns; globPtr;
		    globPtr = globPtr->next) {
		Tcl_DStringAppend(&patterns, sep, TCL_INDEX_NONE);
		Tcl_DStringAppend(&patterns, globPtr->pattern, TCL_INDEX_NONE);
		sep = ";";
	    }
	}
        /*
         * Loop through and join patterns with a ";" Each "clause"
         * corresponds to a single textual description (called typename)
         * in the tk_getOpenFile docs. Each such typename may occur
         * multiple times and all these form a single filter entry
         * with one clause per occurence. Further each clause may specify
         * multiple patterns. Hence the nested loop here.
         */
        sep = "";
        for (clausePtr=filterPtr->clauses ; clausePtr;
             clausePtr=clausePtr->next) {
            GlobPattern *globPtr;
            for (globPtr = clausePtr->patterns; globPtr;
                 globPtr = globPtr->next) {
                Tcl_DStringAppend(&patterns, sep, -1);
                Tcl_DStringAppend(&patterns, globPtr->pattern, -1);
                sep = ";";
            }
        }

	/* Again we need a Unicode form of the string */
        /* Again we need a Unicode form of the string */
        Tcl_DStringInit(&ds);
        Tcl_UtfToWCharDString(Tcl_DStringValue(&patterns), TCL_INDEX_NONE, &ds);
	nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
	nbytes += sizeof(WCHAR);         /* Terminating \0 */
	dlgFilterPtr[i].pszSpec = (LPCWSTR)ckalloc(nbytes);
	memmove((void *)dlgFilterPtr[i].pszSpec, Tcl_DStringValue(&ds), nbytes);
	Tcl_DStringFree(&ds);
	Tcl_DStringSetLength(&patterns, 0);
	Tcl_WinUtfToTChar(Tcl_DStringValue(&patterns), -1, &ds);
        nbytes = Tcl_DStringLength(&ds); /* # bytes, not Unicode chars */
        nbytes += sizeof(WCHAR);         /* Terminating \0 */
        dlgFilterPtr[i].pszSpec = ckalloc(nbytes);
        memmove((void *)dlgFilterPtr[i].pszSpec, Tcl_DStringValue(&ds), nbytes);
        Tcl_DStringFree(&ds);
        Tcl_DStringFree(&patterns);
    }
    Tcl_DStringFree(&patterns);

    if (initialIndex == 0) {
	initialIndex = 1;       /* If no default, show first entry */
    if (initialIndex == 0)
        initialIndex = 1;       /* If no default, show first entry */
    }
    *initialIndexPtr = initialIndex;
    *dlgFilterPtrPtr = dlgFilterPtr;
    *countPtr = flist.numFilters;

    TkFreeFileFilters(&flist);
    return TCL_OK;
}
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
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







-
+




-
+


-
+



-
+







 * - -title is really -message.
 *
 *----------------------------------------------------------------------
 */

int
Tk_ChooseDirectoryObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WCHAR path[MAX_PATH];
    TCHAR path[MAX_PATH];
    int oldMode, result;
    LPCITEMIDLIST pidl;		/* Returned by browser */
    BROWSEINFOW bInfo;		/* Used by browser */
    BROWSEINFO bInfo;		/* Used by browser */
    ChooseDir cdCBData;	    /* Structure to pass back and forth */
    LPMALLOC pMalloc;		/* Used by shell */
    HWND hWnd;
    WCHAR saveDir[MAX_PATH];
    TCHAR saveDir[MAX_PATH];
    Tcl_DString titleString;	/* Title */
    Tcl_DString tempString;	/* temporary */
    Tcl_Obj *objPtr;
    OFNOpts ofnOpts;
    const char *utfDir;

    result = ParseOFNOptions(clientData, interp, objc, objv,
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
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







-
+





-
+

-
-
+

-
+



-
-
+
+


















-
-
+
+




-
-
+
+

-
+







        CleanupOFNOptions(&ofnOpts);
        return result;
    }

    /* Older dialogs */

    path[0] = '\0';
    memset(&cdCBData, 0, sizeof(ChooseDir));
    ZeroMemory(&cdCBData, sizeof(ChooseDir));
    cdCBData.interp = interp;
    cdCBData.mustExist = ofnOpts.mustExist;

    utfDir = Tcl_DStringValue(&ofnOpts.utfDirString);
    if (utfDir[0] != '\0') {
	LPCWSTR uniStr;
	const TCHAR *uniStr;

	Tcl_DStringInit(&tempString);
	Tcl_UtfToWCharDString(Tcl_DStringValue(&ofnOpts.utfDirString), TCL_INDEX_NONE,
        Tcl_WinUtfToTChar(Tcl_DStringValue(&ofnOpts.utfDirString), -1,
                          &tempString);
        uniStr = (WCHAR *) Tcl_DStringValue(&tempString);
        uniStr = (TCHAR *) Tcl_DStringValue(&tempString);

        /* Convert possible relative path to full path to keep dialog happy. */

        GetFullPathNameW(uniStr, MAX_PATH, saveDir, NULL);
        wcsncpy(cdCBData.initDir, saveDir, MAX_PATH);
        GetFullPathName(uniStr, MAX_PATH, saveDir, NULL);
        _tcsncpy(cdCBData.initDir, saveDir, MAX_PATH);
    }

    /* XXX - rest of this (original) code has no error checks at all. */

    /*
     * Get ready to call the browser
     */

    Tk_MakeWindowExist(ofnOpts.tkwin);
    hWnd = Tk_GetHWND(Tk_WindowId(ofnOpts.tkwin));

    /*
     * Setup the parameters used by SHBrowseForFolder
     */

    bInfo.hwndOwner = hWnd;
    bInfo.pszDisplayName = path;
    bInfo.pidlRoot = NULL;
    if (wcslen(cdCBData.initDir) == 0) {
	GetCurrentDirectoryW(MAX_PATH, cdCBData.initDir);
    if (_tcslen(cdCBData.initDir) == 0) {
	GetCurrentDirectory(MAX_PATH, cdCBData.initDir);
    }
    bInfo.lParam = (LPARAM) &cdCBData;

    if (ofnOpts.titleObj != NULL) {
	Tcl_DStringInit(&titleString);
	bInfo.lpszTitle = Tcl_UtfToWCharDString(Tcl_GetString(ofnOpts.titleObj), TCL_INDEX_NONE, &titleString);
	Tcl_WinUtfToTChar(Tcl_GetString(ofnOpts.titleObj), -1, &titleString);
	bInfo.lpszTitle = (LPTSTR) Tcl_DStringValue(&titleString);
    } else {
	bInfo.lpszTitle = L"Please choose a directory, then select OK.";
	bInfo.lpszTitle = TEXT("Please choose a directory, then select OK.");
    }

    /*
     * Set flags to add edit box, status text line and use the new ui. Allow
     * override with magic variable (ignore errors in retrieval). See
     * http://msdn.microsoft.com/en-us/library/bb773205(VS.85).aspx for
     * possible flag values.
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
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







-
+





-
+














-
+

-
+



-
-
+
+



-
+




















-
+







    /*
     * Display dialog in background and process result. We look to give the
     * user a chance to change their mind on an invalid folder if mustexist is
     * 0.
     */

    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
    GetCurrentDirectoryW(MAX_PATH, saveDir);
    GetCurrentDirectory(MAX_PATH, saveDir);
    if (SHGetMalloc(&pMalloc) == NOERROR) {
        /*
         * XXX - MSDN says CoInitialize must have been called before
         * SHBrowseForFolder can be used but don't see that called anywhere.
         */
	pidl = SHBrowseForFolderW(&bInfo);
	pidl = SHBrowseForFolder(&bInfo);

	/*
	 * This is a fix for Windows 2000, which seems to modify the folder
	 * name buffer even when the dialog is canceled (in this case the
	 * buffer contains garbage). See [Bug #3002230]
	 */

	path[0] = '\0';

	/*
	 * Null for cancel button or invalid dir, otherwise valid.
	 */

	if (pidl != NULL) {
	    if (!SHGetPathFromIDListW(pidl, path)) {
	    if (!SHGetPathFromIDList(pidl, path)) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"error: not a file system folder", TCL_INDEX_NONE));
			"error: not a file system folder", -1));
		Tcl_SetErrorCode(interp, "TK", "DIRDIALOG", "PSEUDO", NULL);
	    }
	    pMalloc->lpVtbl->Free(pMalloc, (void *) pidl);
	} else if (wcslen(cdCBData.retDir) > 0) {
	    wcscpy(path, cdCBData.retDir);
	} else if (_tcslen(cdCBData.retDir) > 0) {
	    _tcscpy(path, cdCBData.retDir);
	}
	pMalloc->lpVtbl->Release(pMalloc);
    }
    SetCurrentDirectoryW(saveDir);
    SetCurrentDirectory(saveDir);
    Tcl_SetServiceMode(oldMode);

    /*
     * Ensure that hWnd is enabled, because it can happen that we have updated
     * the wrapper of the parent, which causes us to leave this child disabled
     * (Windows loses sync).
     */

    EnableWindow(hWnd, 1);

    /*
     * Change the pathname to the Tcl "normalized" pathname, where back
     * slashes are used instead of forward slashes
     */

    Tcl_ResetResult(interp);
    if (*path) {
	Tcl_DString ds;

	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		ConvertExternalFilename(path, &ds), TCL_INDEX_NONE));
		ConvertExternalFilename(path, &ds), -1));
	Tcl_DStringFree(&ds);
    }

    CleanupOFNOptions(&ofnOpts);
    return TCL_OK;
}

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
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







-
+



-
-
+
+








-
+









-
+
-










-
-
+
+
+
+


-

-
+







-
+






-
-
+
+

-
+









-
+














-
-
-
-
+
+
+
+

-
-
+
+






-
+



-
+

-
+



-
+












-
-
+
+

-
+








-
+

-
+



















-
+







-
+




-
+













-
+


-
+

















-
-
+
+







static UINT APIENTRY
ChooseDirectoryValidateProc(
    HWND hwnd,
    UINT message,
    LPARAM lParam,
    LPARAM lpData)
{
    WCHAR selDir[MAX_PATH];
    TCHAR selDir[MAX_PATH];
    ChooseDir *chooseDirSharedData = (ChooseDir *) lpData;
    Tcl_DString tempString;
    Tcl_DString initDirString;
    WCHAR string[MAX_PATH];
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    TCHAR string[MAX_PATH];
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->debugFlag) {
	tsdPtr->debugInterp = (Tcl_Interp *) chooseDirSharedData->interp;
	Tcl_DoWhenIdle(SetTkDialog, hwnd);
    }
    chooseDirSharedData->retDir[0] = '\0';
    switch (message) {
    case BFFM_VALIDATEFAILEDW:
    case BFFM_VALIDATEFAILED:
	/*
	 * First save and check to see if it is a valid path name, if so then
	 * make that path the one shown in the window. Otherwise, it failed
	 * the check and should be treated as such. Use
	 * Set/GetCurrentDirectory which allows relative path names and names
	 * with forward slashes. Use Tcl_TranslateFileName to make sure names
	 * like ~ are converted correctly.
	 */

	Tcl_DStringInit(&initDirString);
	Tcl_WinTCharToUtf((TCHAR *) lParam, -1, &initDirString);
	Tcl_WCharToUtfDString((WCHAR *) lParam, wcslen((WCHAR *) lParam), &initDirString);
	if (Tcl_TranslateFileName(chooseDirSharedData->interp,
		Tcl_DStringValue(&initDirString), &tempString) == NULL) {
	    /*
	     * Should we expose the error (in the interp result) to the user
	     * at this point?
	     */

	    chooseDirSharedData->retDir[0] = '\0';
	    return 1;
	}
	Tcl_DStringSetLength(&initDirString, 0);
	wcsncpy(string, Tcl_UtfToWCharDString(Tcl_DStringValue(&tempString), TCL_INDEX_NONE, &initDirString),
	Tcl_DStringFree(&initDirString);
	Tcl_WinUtfToTChar(Tcl_DStringValue(&tempString), -1, &initDirString);
	Tcl_DStringFree(&tempString);
	_tcsncpy(string, (TCHAR *) Tcl_DStringValue(&initDirString),
		MAX_PATH);
	Tcl_DStringFree(&initDirString);
	Tcl_DStringFree(&tempString);

	if (SetCurrentDirectoryW(string) == 0) {
	if (SetCurrentDirectory(string) == 0) {

	    /*
	     * Get the full path name to the user entry, at this point it does
	     * not exist so see if it is supposed to. Otherwise just return
	     * it.
	     */

	    GetFullPathNameW(string, MAX_PATH,
	    GetFullPathName(string, MAX_PATH,
		    chooseDirSharedData->retDir, NULL);
	    if (chooseDirSharedData->mustExist) {
		/*
		 * User HAS to select a valid directory.
		 */

		wsprintfW(selDir, L"Directory '%s' does not exist,\n"
		        L"please select or enter an existing directory.",
		wsprintf(selDir, TEXT("Directory '%s' does not exist,\n")
		        TEXT("please select or enter an existing directory."),
			chooseDirSharedData->retDir);
		MessageBoxW(NULL, selDir, NULL, MB_ICONEXCLAMATION|MB_OK);
		MessageBox(NULL, selDir, NULL, MB_ICONEXCLAMATION|MB_OK);
		chooseDirSharedData->retDir[0] = '\0';
		return 1;
	    }
	} else {
	    /*
	     * Changed to new folder OK, return immediatly with the current
	     * directory in utfRetDir.
	     */

	    GetCurrentDirectoryW(MAX_PATH, chooseDirSharedData->retDir);
	    GetCurrentDirectory(MAX_PATH, chooseDirSharedData->retDir);
	    return 0;
	}
	return 0;

    case BFFM_SELCHANGED:
	/*
	 * Set the status window to the currently selected path and enable the
	 * OK button if a file system folder, otherwise disable the OK button
	 * for things like server names. Perhaps a new switch
	 * -enablenonfolders can be used to allow non folders to be selected.
	 *
	 * Not called when user changes edit box directly.
	 */

	if (SHGetPathFromIDListW((LPITEMIDLIST) lParam, selDir)) {
	    SendMessageW(hwnd, BFFM_SETSTATUSTEXTW, 0, (LPARAM) selDir);
	    /* enable the OK button */
	    SendMessageW(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
	if (SHGetPathFromIDList((LPITEMIDLIST) lParam, selDir)) {
	    SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) selDir);
	    // enable the OK button
	    SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
	} else {
	    /* disable the OK button */
	    SendMessageW(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 0);
	    // disable the OK button
	    SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 0);
	}
	UpdateWindow(hwnd);
	return 1;

    case BFFM_INITIALIZED: {
	/*
	 * Directory browser initializing - tell it where to start from, user
	 * Directory browser intializing - tell it where to start from, user
	 * specified parameter.
	 */

	WCHAR *initDir = chooseDirSharedData->initDir;
	TCHAR *initDir = chooseDirSharedData->initDir;

	SetCurrentDirectoryW(initDir);
	SetCurrentDirectory(initDir);

	if (*initDir == '\\') {
	    /*
	     * BFFM_SETSELECTIONW only understands UNC paths as pidls, so
	     * BFFM_SETSELECTION only understands UNC paths as pidls, so
	     * convert path to pidl using IShellFolder interface.
	     */

	    LPMALLOC pMalloc;
	    LPSHELLFOLDER psfFolder;

	    if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
		if (SUCCEEDED(SHGetDesktopFolder(&psfFolder))) {
		    LPITEMIDLIST pidlMain;
		    ULONG ulCount, ulAttr;

		    if (SUCCEEDED(psfFolder->lpVtbl->ParseDisplayName(
			    psfFolder, hwnd, NULL, initDir,
			    &ulCount,&pidlMain,&ulAttr))
			    psfFolder, hwnd, NULL, (TCHAR *)
			    initDir, &ulCount,&pidlMain,&ulAttr))
			    && (pidlMain != NULL)) {
			SendMessageW(hwnd, BFFM_SETSELECTIONW, FALSE,
			SendMessage(hwnd, BFFM_SETSELECTION, FALSE,
				(LPARAM) pidlMain);
			pMalloc->lpVtbl->Free(pMalloc, pidlMain);
		    }
		    psfFolder->lpVtbl->Release(psfFolder);
		}
		pMalloc->lpVtbl->Release(pMalloc);
	    }
	} else {
	    SendMessageW(hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) initDir);
	    SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM) initDir);
	}
	SendMessageW(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
	SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
	break;
    }

    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MessageBoxObjCmd --
 *
 *	This function implements the MessageBox window for the Windows
 *	platform. See the user documentation for details on what it does.
 *
 * Results:
 *	See user documentation.
 *
 * Side effects:
 *	None. The MessageBox window will be destroyed before this function
 *	None. The MessageBox window will be destroy before this function
 *	returns.
 *
 *----------------------------------------------------------------------
 */

int
Tk_MessageBoxObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData, parent;
    Tk_Window tkwin = clientData, parent;
    HWND hWnd;
    Tcl_Obj *messageObj, *titleObj, *detailObj, *tmpObj;
    int defaultBtn, icon, type;
    int i, oldMode, winCode;
    UINT flags;
    static const char *const optionStrings[] = {
	"-default",	"-detail",	"-icon",	"-message",
	"-parent",	"-title",	"-type",	NULL
    };
    enum options {
	MSG_DEFAULT,	MSG_DETAIL,	MSG_ICON,	MSG_MESSAGE,
	MSG_PARENT,	MSG_TITLE,	MSG_TYPE
    };
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_DString titleBuf, tmpBuf;
    LPCWSTR titlePtr, tmpPtr;
    const WCHAR *titlePtr, *tmpPtr;
    const char *src;

    defaultBtn = -1;
    detailObj = NULL;
    icon = MB_ICONINFORMATION;
    messageObj = NULL;
    parent = tkwin;
    titleObj = NULL;
    type = MB_OK;

    for (i = 1; i < objc; i += 2) {
	int index;
	Tcl_Obj *optionPtr, *valuePtr;

	optionPtr = objv[i];
	valuePtr = objv[i + 1];

	if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings,
		"option", TCL_EXACT, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, optionPtr, optionStrings,
		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (i + 1 == objc) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "value for \"%s\" missing", Tcl_GetString(optionPtr)));
	    Tcl_SetErrorCode(interp, "TK", "MSGBOX", "VALUE", NULL);
	    return TCL_ERROR;
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
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







-
+
+


+
-
+
+
















-
+


-
-
+


-
-
+




-
+















-
+









-
+
















-
+

-
+







	    }
	}
	flags = buttonFlagMap[defaultBtnIdx];
    }

    flags |= icon | type | MB_TASKMODAL | MB_SETFOREGROUND;

    tmpObj = messageObj ? Tcl_DuplicateObj(messageObj) : Tcl_NewObj();
    tmpObj = messageObj ? Tcl_DuplicateObj(messageObj)
	    : Tcl_NewUnicodeObj(NULL, 0);
    Tcl_IncrRefCount(tmpObj);
    if (detailObj) {
	const Tcl_UniChar twoNL[] = { '\n', '\n' };
	Tcl_AppendStringsToObj(tmpObj, "\n\n", NULL);

	Tcl_AppendUnicodeToObj(tmpObj, twoNL, 2);
	Tcl_AppendObjToObj(tmpObj, detailObj);
    }

    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);

    /*
     * MessageBoxW exists for all platforms. Use it to allow unicode error
     * message to be displayed correctly where possible by the OS.
     *
     * In order to have the parent window icon reflected in a MessageBox, we
     * have to create a hook that will trigger when the MessageBox is being
     * created.
     */

    tsdPtr->hSmallIcon = TkWinGetIcon(parent, ICON_SMALL);
    tsdPtr->hBigIcon   = TkWinGetIcon(parent, ICON_BIG);
    tsdPtr->hMsgBoxHook = SetWindowsHookExW(WH_CBT, MsgBoxCBTProc, NULL,
    tsdPtr->hMsgBoxHook = SetWindowsHookEx(WH_CBT, MsgBoxCBTProc, NULL,
	    GetCurrentThreadId());
    src = Tcl_GetString(tmpObj);
    Tcl_DStringInit(&tmpBuf);
    tmpPtr = Tcl_UtfToWCharDString(src, tmpObj->length, &tmpBuf);
    tmpPtr = Tcl_WinUtfToTChar(src, tmpObj->length, &tmpBuf);
    if (titleObj != NULL) {
	src = Tcl_GetString(titleObj);
	Tcl_DStringInit(&titleBuf);
	titlePtr = Tcl_UtfToWCharDString(src, titleObj->length, &titleBuf);
	titlePtr = Tcl_WinUtfToTChar(src, titleObj->length, &titleBuf);
    } else {
	titlePtr = L"";
	Tcl_DStringInit(&titleBuf);
    }
    winCode = MessageBoxW(hWnd, tmpPtr, titlePtr, flags);
    winCode = MessageBox(hWnd, tmpPtr, titlePtr, flags);
    Tcl_DStringFree(&titleBuf);
    Tcl_DStringFree(&tmpBuf);
    UnhookWindowsHookEx(tsdPtr->hMsgBoxHook);
    (void) Tcl_SetServiceMode(oldMode);

    /*
     * Ensure that hWnd is enabled, because it can happen that we have updated
     * the wrapper of the parent, which causes us to leave this child disabled
     * (Windows loses sync).
     */

    EnableWindow(hWnd, 1);

    Tcl_DecrRefCount(tmpObj);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    TkFindStateString(buttonMap, winCode), TCL_INDEX_NONE));
	    TkFindStateString(buttonMap, winCode), -1));
    return TCL_OK;
}

static LRESULT CALLBACK
MsgBoxCBTProc(
    int nCode,
    WPARAM wParam,
    LPARAM lParam)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (nCode == HCBT_CREATEWND) {
	/*
	 * Window owned by our task is being created. Since the hook is
	 * installed just before the MessageBox call and removed after the
	 * MessageBox call, the window being created is either the message box
	 * or one of its controls. Check that the class is WC_DIALOG to ensure
	 * that it's the one we want.
	 */

	LPCBT_CREATEWND lpcbtcreate = (LPCBT_CREATEWND) lParam;

	if (WC_DIALOG == lpcbtcreate->lpcs->lpszClass) {
	    HWND hwnd = (HWND) wParam;

	    SendMessageW(hwnd, WM_SETICON, ICON_SMALL,
	    SendMessage(hwnd, WM_SETICON, ICON_SMALL,
		    (LPARAM) tsdPtr->hSmallIcon);
	    SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM) tsdPtr->hBigIcon);
	    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) tsdPtr->hBigIcon);
	}
    }

    /*
     * Call the next hook proc, if there is one
     */

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
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







-
+

-
+



-
+









-
+




-
+
-







 *	the test command 'tkwinevent debug 1'.
 *
 * ----------------------------------------------------------------------
 */

static void
SetTkDialog(
    void *clientData)
    ClientData clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    char buf[32];

    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)clientData);
    sprintf(buf, "0x%p", (HWND) clientData);
    Tcl_SetVar2(tsdPtr->debugInterp, "tk_dialog", NULL, buf, TCL_GLOBAL_ONLY);
}

/*
 * Factored out a common pattern in use in this file.
 */

static const char *
ConvertExternalFilename(
    LPCWSTR  filename,
    TCHAR *filename,
    Tcl_DString *dsPtr)
{
    char *p;

    Tcl_DStringInit(dsPtr);
    Tcl_WinTCharToUtf(filename, -1, dsPtr);
    Tcl_WCharToUtfDString(filename, wcslen(filename), dsPtr);
    for (p = Tcl_DStringValue(dsPtr); *p != '\0'; p++) {
	/*
	 * Change the pathname to the Tcl "normalized" pathname, where back
	 * slashes are used instead of forward slashes
	 */

	if (*p == '\\') {
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
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







-
+






-
-
+

-
+


-
+

-
+



-
+



-
+



-
+









-
+

-
+



-
+







 *
 * ----------------------------------------------------------------------
 */

static Tcl_Obj *
GetFontObj(
    HDC hdc,
    LOGFONTW *plf)
    LOGFONT *plf)
{
    Tcl_DString ds;
    Tcl_Obj *resObj;
    int pt = 0;

    resObj = Tcl_NewListObj(0, NULL);
    Tcl_DStringInit(&ds);
    Tcl_WCharToUtfDString(plf->lfFaceName, wcslen(plf->lfFaceName), &ds);
    Tcl_WinTCharToUtf(plf->lfFaceName, -1, &ds);
    Tcl_ListObjAppendElement(NULL, resObj,
	    Tcl_NewStringObj(Tcl_DStringValue(&ds), TCL_INDEX_NONE));
	    Tcl_NewStringObj(Tcl_DStringValue(&ds), -1));
    Tcl_DStringFree(&ds);
    pt = -MulDiv(plf->lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));
    Tcl_ListObjAppendElement(NULL, resObj, Tcl_NewWideIntObj(pt));
    Tcl_ListObjAppendElement(NULL, resObj, Tcl_NewIntObj(pt));
    if (plf->lfWeight >= 700) {
	Tcl_ListObjAppendElement(NULL, resObj, Tcl_NewStringObj("bold", TCL_INDEX_NONE));
	Tcl_ListObjAppendElement(NULL, resObj, Tcl_NewStringObj("bold", -1));
    }
    if (plf->lfItalic) {
	Tcl_ListObjAppendElement(NULL, resObj,
		Tcl_NewStringObj("italic", TCL_INDEX_NONE));
		Tcl_NewStringObj("italic", -1));
    }
    if (plf->lfUnderline) {
	Tcl_ListObjAppendElement(NULL, resObj,
		Tcl_NewStringObj("underline", TCL_INDEX_NONE));
		Tcl_NewStringObj("underline", -1));
    }
    if (plf->lfStrikeOut) {
	Tcl_ListObjAppendElement(NULL, resObj,
		Tcl_NewStringObj("overstrike", TCL_INDEX_NONE));
		Tcl_NewStringObj("overstrike", -1));
    }
    return resObj;
}

static void
ApplyLogfont(
    Tcl_Interp *interp,
    Tcl_Obj *cmdObj,
    HDC hdc,
    LOGFONTW *logfontPtr)
    LOGFONT *logfontPtr)
{
    Tcl_Size objc;
    int objc;
    Tcl_Obj **objv, **tmpv;

    Tcl_ListObjGetElements(NULL, cmdObj, &objc, &objv);
    tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
    tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
    memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
    tmpv[objc] = GetFontObj(hdc, logfontPtr);
    TkBackgroundEvalObjv(interp, objc+1, tmpv, TCL_EVAL_GLOBAL);
    ckfree(tmpv);
}

/*
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
3171
3172
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186

3187
3188
3189
3190
3191
3192

3193
3194
3195
3196
3197
3198
3199
3200
3201
3202

3203
3204
3205

3206
3207
3208
3209
3210

3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223

3224
3225
3226
3227
3228
3229
3230
3231







-
+


-
+












-
-
+

-
+
















-
+





-
+









-
+


-
+




-
+












-
+







static UINT_PTR CALLBACK
HookProc(
    HWND hwndDlg,
    UINT msg,
    WPARAM wParam,
    LPARAM lParam)
{
    CHOOSEFONTW *pcf = (CHOOSEFONTW *) lParam;
    CHOOSEFONT *pcf = (CHOOSEFONT *) lParam;
    HWND hwndCtrl;
    static HookData *phd = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (WM_INITDIALOG == msg && lParam != 0) {
	phd = (HookData *) pcf->lCustData;
	phd->hwnd = hwndDlg;
	if (tsdPtr->debugFlag) {
	    tsdPtr->debugInterp = phd->interp;
	    Tcl_DoWhenIdle(SetTkDialog, hwndDlg);
	}
	if (phd->titleObj != NULL) {
	    Tcl_DString title;

	    Tcl_DStringInit(&title);
	    Tcl_UtfToWCharDString(Tcl_GetString(phd->titleObj), TCL_INDEX_NONE, &title);
	    Tcl_WinUtfToTChar(Tcl_GetString(phd->titleObj), -1, &title);
	    if (Tcl_DStringLength(&title) > 0) {
		SetWindowTextW(hwndDlg, (LPCWSTR) Tcl_DStringValue(&title));
		SetWindowText(hwndDlg, (LPCTSTR) Tcl_DStringValue(&title));
	    }
	    Tcl_DStringFree(&title);
	}

	/*
	 * Disable the colour combobox (0x473) and its label (0x443).
	 */

	hwndCtrl = GetDlgItem(hwndDlg, 0x443);
	if (IsWindow(hwndCtrl)) {
	    EnableWindow(hwndCtrl, FALSE);
	}
	hwndCtrl = GetDlgItem(hwndDlg, 0x473);
	if (IsWindow(hwndCtrl)) {
	    EnableWindow(hwndCtrl, FALSE);
	}
	Tk_SendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL);
	TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL);
	return 1; /* we handled the message */
    }

    if (WM_DESTROY == msg) {
	phd->hwnd = NULL;
	Tk_SendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL);
	TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL);
	return 0;
    }

    /*
     * Handle apply button by calling the provided command script as a
     * background evaluation (ie: errors dont come back here).
     */

    if (WM_COMMAND == msg && LOWORD(wParam) == 1026) {
	LOGFONTW lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}};
	LOGFONT lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}};
	HDC hdc = GetDC(hwndDlg);

	SendMessageW(hwndDlg, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM) &lf);
	SendMessage(hwndDlg, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM) &lf);
	if (phd && phd->cmdObj) {
	    ApplyLogfont(phd->interp, phd->cmdObj, hdc, &lf);
	}
	if (phd && phd->parent) {
	    Tk_SendVirtualEvent(phd->parent, "TkFontchooserFontChanged", NULL);
	    TkSendVirtualEvent(phd->parent, "TkFontchooserFontChanged", NULL);
	}
	return 1;
    }
    return 0; /* pass on for default processing */
}

/*
 * Helper for the FontchooserConfigure command to return the current value of
 * any of the options (which may be NULL in the structure)
 */

enum FontchooserOption {
    FontchooserCmd, FontchooserFont, FontchooserParent, FontchooserTitle,
    FontchooserParent, FontchooserTitle, FontchooserFont, FontchooserCmd,
    FontchooserVisible
};

static Tcl_Obj *
FontchooserCget(
    HookData *hdPtr,
    int optionIndex)
3199
3200
3201
3202
3203
3204
3205
3206

3207
3208
3209
3210
3211
3212
3213
3258
3259
3260
3261
3262
3263
3264

3265
3266
3267
3268
3269
3270
3271
3272







-
+







	if (hdPtr->cmdObj) {
	    resObj = hdPtr->cmdObj;
	} else {
	    resObj = Tcl_NewStringObj("", 0);
	}
	break;
    case FontchooserVisible:
	resObj = Tcl_NewBooleanObj((hdPtr->hwnd != NULL) && IsWindow(hdPtr->hwnd));
	resObj = Tcl_NewBooleanObj(hdPtr->hwnd && IsWindow(hdPtr->hwnd));
	break;
    default:
	resObj = Tcl_NewStringObj("", 0);
    }
    return resObj;
}

3226
3227
3228
3229
3230
3231
3232
3233

3234
3235

3236
3237
3238

3239
3240
3241

3242
3243

3244
3245
3246

3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257

3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271


3272
3273
3274
3275
3276
3277
3278
3285
3286
3287
3288
3289
3290
3291

3292
3293

3294
3295
3296

3297
3298


3299
3300

3301
3302
3303

3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314

3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327


3328
3329
3330
3331
3332
3333
3334
3335
3336







-
+

-
+


-
+

-
-
+

-
+


-
+










-
+












-
-
+
+







 *	Per-interp data structure may be modified
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserConfigureCmd(
    void *clientData,	/* Main window */
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    HookData *hdPtr = NULL;
    Tcl_Size i;
    int r = TCL_OK;
    int i, r = TCL_OK;
    static const char *const optionStrings[] = {
	"-command", "-font", "-parent", "-title", "-visible", NULL
	"-parent", "-title", "-font", "-command", "-visible", NULL
    };

    hdPtr = (HookData *)Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);
    hdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);

    /*
     * With no arguments we return all the options in a dict.
     */

    if (objc == 1) {
	Tcl_Obj *keyObj, *valueObj;
	Tcl_Obj *dictObj = Tcl_NewDictObj();

	for (i = 0; r == TCL_OK && optionStrings[i] != NULL; ++i) {
	    keyObj = Tcl_NewStringObj(optionStrings[i], TCL_INDEX_NONE);
	    keyObj = Tcl_NewStringObj(optionStrings[i], -1);
	    valueObj = FontchooserCget(hdPtr, i);
	    r = Tcl_DictObjPut(interp, dictObj, keyObj, valueObj);
	}
	if (r == TCL_OK) {
	    Tcl_SetObjResult(interp, dictObj);
	}
	return r;
    }

    for (i = 1; i < objc; i += 2) {
	int optionIndex;

	if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings,
		"option", 0, &optionIndex) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
		sizeof(char *),  "option", 0, &optionIndex) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (objc == 2) {
	    /*
	     * If one option and no arg - return the current value.
	     */

3286
3287
3288
3289
3290
3291
3292
3293

3294
3295
3296
3297
3298
3299
3300
3301

3302
3303
3304
3305
3306
3307
3308
3344
3345
3346
3347
3348
3349
3350

3351
3352
3353
3354
3355
3356
3357
3358

3359
3360
3361
3362
3363
3364
3365
3366







-
+







-
+







	    return TCL_ERROR;
	}
	switch (optionIndex) {
	case FontchooserVisible: {
	    static const char *msg = "cannot change read-only option "
		    "\"-visible\": use the show or hide command";

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
	    Tcl_SetErrorCode(interp, "TK", "FONTDIALOG", "READONLY", NULL);
	    return TCL_ERROR;
	}
	case FontchooserParent: {
	    Tk_Window parent = Tk_NameToWindow(interp,
		    Tcl_GetString(objv[i+1]), tkwin);

	    if (parent == NULL) {
	    if (parent == None) {
		return TCL_ERROR;
	    }
	    if (hdPtr->parentObj) {
		Tcl_DecrRefCount(hdPtr->parentObj);
	    }
	    hdPtr->parentObj = objv[i+1];
	    if (Tcl_IsShared(hdPtr->parentObj)) {
3321
3322
3323
3324
3325
3326
3327
3328

3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343

3344
3345
3346
3347
3348
3349
3350
3379
3380
3381
3382
3383
3384
3385

3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400

3401
3402
3403
3404
3405
3406
3407
3408







-
+














-
+







	    }
	    Tcl_IncrRefCount(hdPtr->titleObj);
	    break;
	case FontchooserFont:
	    if (hdPtr->fontObj) {
		Tcl_DecrRefCount(hdPtr->fontObj);
	    }
	    Tcl_GetString(objv[i+1]);
	    (void)Tcl_GetString(objv[i+1]);
	    if (objv[i+1]->length) {
		hdPtr->fontObj = objv[i+1];
		if (Tcl_IsShared(hdPtr->fontObj)) {
		    hdPtr->fontObj = Tcl_DuplicateObj(hdPtr->fontObj);
		}
		Tcl_IncrRefCount(hdPtr->fontObj);
	    } else {
		hdPtr->fontObj = NULL;
	    }
	    break;
	case FontchooserCmd:
	    if (hdPtr->cmdObj) {
		Tcl_DecrRefCount(hdPtr->cmdObj);
	    }
	    Tcl_GetString(objv[i+1]);
	    (void)Tcl_GetString(objv[i+1]);
	    if (objv[i+1]->length) {
		hdPtr->cmdObj = objv[i+1];
		if (Tcl_IsShared(hdPtr->cmdObj)) {
		    hdPtr->cmdObj = Tcl_DuplicateObj(hdPtr->cmdObj);
		}
		Tcl_IncrRefCount(hdPtr->cmdObj);
	    } else {
3370
3371
3372
3373
3374
3375
3376
3377

3378
3379
3380


3381
3382
3383
3384
3385



3386
3387
3388
3389
3390

3391
3392
3393
3394
3395
3396

3397
3398
3399
3400
3401
3402
3403
3404


3405
3406

3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428


3429
3430
3431
3432
3433
3434
3435
3428
3429
3430
3431
3432
3433
3434

3435
3436


3437
3438
3439
3440



3441
3442
3443
3444
3445
3446
3447

3448
3449
3450
3451
3452
3453

3454
3455
3456
3457
3458
3459
3460


3461
3462
3463

3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484


3485
3486
3487
3488
3489
3490
3491
3492
3493







-
+

-
-
+
+


-
-
-
+
+
+




-
+





-
+






-
-
+
+

-
+




















-
-
+
+







 *	additional state.
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserShowCmd(
    void *clientData,	/* Main window */
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    TCL_UNUSED(Tcl_Size),
    TCL_UNUSED(Tcl_Obj *const *))
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_DString ds;
    Tk_Window tkwin = (Tk_Window)clientData, parent;
    CHOOSEFONTW cf;
    LOGFONTW lf;
    Tk_Window tkwin = clientData, parent;
    CHOOSEFONT cf;
    LOGFONT lf;
    HDC hdc;
    HookData *hdPtr;
    int r = TCL_OK, oldMode = 0;

    hdPtr = (HookData *)Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);
    hdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);

    parent = tkwin;
    if (hdPtr->parentObj) {
	parent = Tk_NameToWindow(interp, Tcl_GetString(hdPtr->parentObj),
		tkwin);
	if (parent == NULL) {
	if (parent == None) {
	    return TCL_ERROR;
	}
    }

    Tk_MakeWindowExist(parent);

    memset(&cf, 0, sizeof(CHOOSEFONTW));
    memset(&lf, 0, sizeof(LOGFONTW));
    ZeroMemory(&cf, sizeof(CHOOSEFONT));
    ZeroMemory(&lf, sizeof(LOGFONT));
    lf.lfCharSet = DEFAULT_CHARSET;
    cf.lStructSize = sizeof(CHOOSEFONTW);
    cf.lStructSize = sizeof(CHOOSEFONT);
    cf.hwndOwner = Tk_GetHWND(Tk_WindowId(parent));
    cf.lpLogFont = &lf;
    cf.nFontType = SCREEN_FONTTYPE;
    cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK;
    cf.rgbColors = RGB(0,0,0);
    cf.lpfnHook = HookProc;
    cf.lCustData = (INT_PTR) hdPtr;
    hdPtr->interp = interp;
    hdPtr->parent = parent;
    hdc = GetDC(cf.hwndOwner);

    if (hdPtr->fontObj != NULL) {
	TkFont *fontPtr;
	Tk_Font f = Tk_AllocFontFromObj(interp, tkwin, hdPtr->fontObj);

	if (f == NULL) {
	    return TCL_ERROR;
	}
	fontPtr = (TkFont *) f;
	cf.Flags |= CF_INITTOLOGFONTSTRUCT;
	Tcl_DStringInit(&ds);
	wcsncpy(lf.lfFaceName, Tcl_UtfToWCharDString(fontPtr->fa.family, TCL_INDEX_NONE, &ds),
	Tcl_WinUtfToTChar(fontPtr->fa.family, -1, &ds);
	_tcsncpy(lf.lfFaceName, (TCHAR *)Tcl_DStringValue(&ds),
		LF_FACESIZE-1);
	Tcl_DStringFree(&ds);
	lf.lfFaceName[LF_FACESIZE-1] = 0;
	lf.lfHeight = -MulDiv((int)(TkFontGetPoints(tkwin, fontPtr->fa.size) + 0.5),
	    GetDeviceCaps(hdc, LOGPIXELSY), 72);
	if (fontPtr->fa.weight == TK_FW_BOLD) {
	    lf.lfWeight = FW_BOLD;
3443
3444
3445
3446
3447
3448
3449
3450

3451
3452
3453
3454
3455
3456
3457
3458
3459
3460

3461
3462
3463
3464
3465

3466
3467
3468
3469
3470
3471
3472
3501
3502
3503
3504
3505
3506
3507

3508
3509
3510
3511
3512
3513
3514
3515
3516
3517

3518
3519
3520
3521
3522

3523
3524
3525
3526
3527
3528
3529
3530







-
+









-
+




-
+







	if (fontPtr->fa.overstrike) {
	    lf.lfStrikeOut = TRUE;
	}
	Tk_FreeFont(f);
    }

    if (TCL_OK == r && hdPtr->cmdObj != NULL) {
	Tcl_Size len = 0;
	int len = 0;

	r = Tcl_ListObjLength(interp, hdPtr->cmdObj, &len);
	if (len > 0) {
	    cf.Flags |= CF_APPLY;
	}
    }

    if (TCL_OK == r) {
	oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	if (ChooseFontW(&cf)) {
	if (ChooseFont(&cf)) {
	    if (hdPtr->cmdObj) {
		ApplyLogfont(hdPtr->interp, hdPtr->cmdObj, hdc, &lf);
	    }
	    if (hdPtr->parent) {
		Tk_SendVirtualEvent(hdPtr->parent, "TkFontchooserFontChanged", NULL);
		TkSendVirtualEvent(hdPtr->parent, "TkFontchooserFontChanged", NULL);
	    }
	}
	Tcl_SetServiceMode(oldMode);
	EnableWindow(cf.hwndOwner, 1);
    }

    ReleaseDC(cf.hwndOwner, hdc);
3484
3485
3486
3487
3488
3489
3490
3491

3492
3493
3494


3495
3496

3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516

3517
3518
3519
3520

3521
3522
3523
3524
3525
3526
3527
3542
3543
3544
3545
3546
3547
3548

3549
3550


3551
3552
3553

3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573

3574


3575

3576
3577
3578
3579
3580
3581
3582
3583







-
+

-
-
+
+

-
+



















-
+
-
-

-
+







 *	destroy the dialog
 *
 * ----------------------------------------------------------------------
 */

static int
FontchooserHideCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Main window */
    Tcl_Interp *interp,
    TCL_UNUSED(Tcl_Size),
    TCL_UNUSED(Tcl_Obj *const *))
    int objc,
    Tcl_Obj *const objv[])
{
    HookData *hdPtr = (HookData *)Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);
    HookData *hdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser", NULL);

    if (hdPtr->hwnd && IsWindow(hdPtr->hwnd)) {
	EndDialog(hdPtr->hwnd, 0);
    }
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * DeleteHookData --
 *
 *	Clean up the font chooser configuration data when the interp is
 *	destroyed.
 *
 * ----------------------------------------------------------------------
 */

static void
DeleteHookData(
DeleteHookData(ClientData clientData, Tcl_Interp *interp)
    void *clientData,
    TCL_UNUSED(Tcl_Interp *))
{
    HookData *hdPtr = (HookData *)clientData;
    HookData *hdPtr = clientData;

    if (hdPtr->parentObj) {
	Tcl_DecrRefCount(hdPtr->parentObj);
    }
    if (hdPtr->fontObj) {
	Tcl_DecrRefCount(hdPtr->fontObj);
    }
3550
3551
3552
3553
3554
3555
3556
3557

3558
3559
3560
3561

3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3606
3607
3608
3609
3610
3611
3612

3613


3614

3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628







-
+
-
-

-
+













    { "configure", FontchooserConfigureCmd, NULL },
    { "show", FontchooserShowCmd, NULL },
    { "hide", FontchooserHideCmd, NULL },
    { NULL, NULL, NULL }
};

int
TkInitFontchooser(
TkInitFontchooser(Tcl_Interp *interp, ClientData clientData)
    Tcl_Interp *interp,
    TCL_UNUSED(void *))
{
    HookData *hdPtr = (HookData *)ckalloc(sizeof(HookData));
    HookData *hdPtr = ckalloc(sizeof(HookData));

    memset(hdPtr, 0, sizeof(HookData));
    Tcl_SetAssocData(interp, "::tk::fontchooser", DeleteHookData, hdPtr);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinDraw.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * tkWinDraw.c --
 *
 *	This file contains the Xlib emulation functions pertaining to actually
 *	drawing objects on a window.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright © 1994 Software Research Associates, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 * Copyright (c) 1994 Software Research Associates, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
+








/*
 * The followng typedef is used to pass Windows GDI drawing functions.
 */

typedef BOOL (CALLBACK *WinDrawFunc)(HDC dc, const POINT *points, int npoints);

typedef struct {
typedef struct ThreadSpecificData {
    POINT *winPoints;		/* Array of points that is reused. */
    int nWinPoints;		/* Current size of point array. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Forward declarations for functions defined in this file:
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254







-
+







     * the last array if it is large enough.
     */

    if (npoints > tsdPtr->nWinPoints) {
	if (tsdPtr->winPoints != NULL) {
	    ckfree(tsdPtr->winPoints);
	}
	tsdPtr->winPoints = (POINT *)ckalloc(sizeof(POINT) * (size_t)npoints);
	tsdPtr->winPoints = ckalloc(sizeof(POINT) * npoints);
	if (tsdPtr->winPoints == NULL) {
	    tsdPtr->nWinPoints = -1;
	    return NULL;
	}
	tsdPtr->nWinPoints = npoints;
    }

365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379







-
+







    unsigned long plane)
{
    HDC srcDC, destDC;
    TkWinDCState srcState, destState;
    HBRUSH bgBrush, fgBrush, oldBrush;
    TkpClipMask *clipPtr = (TkpClipMask*)gc->clip_mask;

    LastKnownRequestProcessed(display)++;
    display->request++;

    if (plane != 1) {
	Tcl_Panic("Unexpected plane specified for XCopyPlane");
    }

    srcDC = TkWinGetDrawableDC(display, src, &srcState);

408
409
410
411
412
413
414
415

416
417
418
419
420
421
422
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422







-
+







	    /*
	     * Case 2: transparent bitmaps are handled by setting the
	     * destination to the foreground color whenever the source pixel
	     * is set.
	     */

	    fgBrush = CreateSolidBrush(gc->foreground);
	    oldBrush = (HBRUSH)SelectObject(destDC, fgBrush);
	    oldBrush = SelectObject(destDC, fgBrush);
	    SetBkColor(destDC, RGB(255,255,255));
	    SetTextColor(destDC, RGB(0,0,0));
	    BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, srcDC,
		    src_x, src_y, MASKPAT);
	    SelectObject(destDC, oldBrush);
	    DeleteObject(fgBrush);
	} else {
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460







-
+







	     */

	    BitBlt(memDC, 0, 0, (int) width, (int) height, srcDC, src_x, src_y,
		    SRCCOPY);
	    BitBlt(memDC, 0, 0, (int) width, (int) height, maskDC,
		    dest_x - gc->clip_x_origin, dest_y - gc->clip_y_origin,
		    SRCAND);
	    oldBrush = (HBRUSH)SelectObject(destDC, fgBrush);
	    oldBrush = SelectObject(destDC, fgBrush);
	    BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, memDC,
		    0, 0, MASKPAT);

	    /*
	     * Set background bits. Same as foreground, except we use ((NOT
	     * source) AND mask) and the background brush.
	     */
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
484
485
486
487
488
489
490

491
492
493
494
495
496
497
498







-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkPutImage, XPutImage --
 *
 *	Copies a subimage from an in-memory image to a rectangle of the
 *	Copies a subimage from an in-memory image to a rectangle of of the
 *	specified drawable.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws the image on the specified drawable.
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







{
    HDC dc, dcMem;
    TkWinDCState state;
    BITMAPINFO *infoPtr;
    HBITMAP bitmap;
    char *data;

    LastKnownRequestProcessed(display)++;
    display->request++;

    dc = TkWinGetDrawableDC(display, d, &state);
    SetROP2(dc, tkpWinRopModes[gc->function]);
    dcMem = CreateCompatibleDC(dc);

    if (image->bits_per_pixel == 1) {
	/*
549
550
551
552
553
554
555
556
557


558
559

560
561
562
563
564
565
566

567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590

591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
549
550
551
552
553
554
555


556
557
558

559
560
561
562
563
564
565

566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590

591
592
593

594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609







-
-
+
+

-
+






-
+







-
+














+

-
+


-
+








-







	/*
	 * Do not use a palette for TrueColor images.
	 */

	usePalette = (image->bits_per_pixel < 16);

	if (usePalette) {
	    infoPtr = (BITMAPINFO *)ckalloc(sizeof(BITMAPINFOHEADER)
		    + sizeof(RGBQUAD)*(size_t)ncolors);
	    infoPtr = ckalloc(sizeof(BITMAPINFOHEADER)
		    + sizeof(RGBQUAD)*ncolors);
	} else {
	    infoPtr = (BITMAPINFO *)ckalloc(sizeof(BITMAPINFOHEADER));
	    infoPtr = ckalloc(sizeof(BITMAPINFOHEADER));
	}

	infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	infoPtr->bmiHeader.biWidth = image->width;
	infoPtr->bmiHeader.biHeight = -image->height; /* Top-down order */
	infoPtr->bmiHeader.biPlanes = 1;
	infoPtr->bmiHeader.biBitCount = (WORD)image->bits_per_pixel;
	infoPtr->bmiHeader.biBitCount = image->bits_per_pixel;
	infoPtr->bmiHeader.biCompression = BI_RGB;
	infoPtr->bmiHeader.biSizeImage = 0;
	infoPtr->bmiHeader.biXPelsPerMeter = 0;
	infoPtr->bmiHeader.biYPelsPerMeter = 0;
	infoPtr->bmiHeader.biClrImportant = 0;

	if (usePalette) {
	    infoPtr->bmiHeader.biClrUsed = (DWORD)ncolors;
	    infoPtr->bmiHeader.biClrUsed = ncolors;
	    for (i = 0; i < ncolors; i++) {
		infoPtr->bmiColors[i].rgbBlue = GetBValue(colors[i]);
		infoPtr->bmiColors[i].rgbGreen = GetGValue(colors[i]);
		infoPtr->bmiColors[i].rgbRed = GetRValue(colors[i]);
		infoPtr->bmiColors[i].rgbReserved = 0;
	    }
	} else {
	    infoPtr->bmiHeader.biClrUsed = 0;
	}
	bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, CBM_INIT,
		image->data, infoPtr, DIB_RGB_COLORS);
	ckfree(infoPtr);
    }
    if (!bitmap) {
	Tcl_Panic("Fail to allocate bitmap");
	DeleteDC(dcMem);
	TkWinReleaseDrawableDC(d, dc, &state);
    	TkWinReleaseDrawableDC(d, dc, &state);
	return BadValue;
    }
    bitmap = (HBITMAP)SelectObject(dcMem, bitmap);
    bitmap = SelectObject(dcMem, bitmap);
    BitBlt(dc, dest_x, dest_y, (int) width, (int) height, dcMem, src_x, src_y,
	    SRCCOPY);
    DeleteObject(SelectObject(dcMem, bitmap));
    DeleteDC(dcMem);
    TkWinReleaseDrawableDC(d, dc, &state);
    return Success;
}

#undef XPutImage
int
XPutImage(
    Display *display,
    Drawable d,			/* Destination drawable. */
    GC gc,
    XImage *image,		/* Source image. */
    int src_x, int src_y,	/* Offset of subimage. */
667
668
669
670
671
672
673
674

675
676
677
678
679
680
681
682
683
684
685
686

687
688
689
690
691
692
693
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681
682
683
684
685

686
687
688
689
690
691
692
693







-
+











-
+








	/*
	 * Select stipple pattern into destination dc.
	 */

	stipple = CreatePatternBrush(twdPtr->bitmap.handle);
	SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
	oldBrush = (HBRUSH)SelectObject(dc, stipple);
	oldBrush = SelectObject(dc, stipple);
	dcMem = CreateCompatibleDC(dc);

	/*
	 * For each rectangle, create a drawing surface which is the size of
	 * the rectangle and fill it with the background color. Then merge the
	 * result with the stipple pattern.
	 */

	while (nrectangles-- > 0) {
	    bitmap = CreateCompatibleBitmap(dc, rectangles[0].width,
		    rectangles[0].height);
	    oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap);
	    oldBitmap = SelectObject(dcMem, bitmap);
	    rect.left = 0;
	    rect.top = 0;
	    rect.right = rectangles[0].width;
	    rect.bottom = rectangles[0].height;
	    FillRect(dcMem, &rect, brush);
	    BitBlt(dc, rectangles[0].x, rectangles[0].y, rectangles[0].width,
		    rectangles[0].height, dcMem, 0, 0, COPYFG);
714
715
716
717
718
719
720
721
722


723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
714
715
716
717
718
719
720


721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739














































740
741
742
743
744
745
746







-
-
+
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		rect.top = rectangles[0].y;
		rect.bottom = rect.top + rectangles[0].height;
		FillRect(dc, &rect, brush);
		++rectangles;
	    }
	} else {
	    HPEN newPen = CreatePen(PS_NULL, 0, gc->foreground);
	    HPEN oldPen = (HPEN)SelectObject(dc, newPen);
	    oldBrush = (HBRUSH)SelectObject(dc, brush);
	    HPEN oldPen = SelectObject(dc, newPen);
	    oldBrush = SelectObject(dc, brush);

	    while (nrectangles-- > 0) {
		Rectangle(dc, rectangles[0].x, rectangles[0].y,
		    rectangles[0].x + rectangles[0].width + 1,
		    rectangles[0].y + rectangles[0].height + 1);
		++rectangles;
	    }

	    SelectObject(dc, oldBrush);
	    SelectObject(dc, oldPen);
	    DeleteObject(newPen);
	}
    }
    DeleteObject(brush);
    TkWinReleaseDrawableDC(d, dc, &state);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * MakeAndStrokePath --
 *
 *	This function draws a shape using a list of points, a stipple pattern,
 *	and the specified drawing function. It does it through creation of a
 *	so-called 'path' (see GDI documentation on MSDN).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
static void
MakeAndStrokePath(
    HDC dc,
    POINT *winPoints,
    int npoints,
    WinDrawFunc func)        /* Name of the Windows GDI drawing function:
                                this is either Polyline or Polygon. */
{
    BeginPath(dc);
    func(dc, winPoints, (int)npoints);
    /*
     * In the case of closed polylines, the first and last points
     * are the same. We want miter or bevel join be rendered also
     * at this point, this needs telling the Windows GDI that the
     * path is closed.
     */
    if (func == Polyline) {
        if ((winPoints[0].x == winPoints[npoints-1].x) &&
                (winPoints[0].y == winPoints[npoints-1].y)) {
            CloseFigure(dc);
        }
        EndPath(dc);
        StrokePath(dc);
    } else {
        EndPath(dc);
        StrokeAndFillPath(dc);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RenderObject --
 *
 *	This function draws a shape using a list of points, a stipple pattern,
844
845
846
847
848
849
850
851

852
853
854
855
856
857
858
859

860
861

862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882


883
884
885
886
887
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902
903
904
905


906
907
908
909
910

911
912
913
914
915
916
917
798
799
800
801
802
803
804

805
806
807
808
809
810
811
812

813
814

815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834


835
836
837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855
856
857


858
859
860
861
862
863

864
865
866
867
868
869
870
871







-
+







-
+

-
+



















-
-
+
+











-
+









-
-
+
+




-
+







	height = rect.bottom - rect.top;

	/*
	 * Select stipple pattern into destination dc.
	 */

	SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
	oldBrush = (HBRUSH)SelectObject(dc, CreatePatternBrush(twdPtr->bitmap.handle));
	oldBrush = SelectObject(dc, CreatePatternBrush(twdPtr->bitmap.handle));

	/*
	 * Create temporary drawing surface containing a copy of the
	 * destination equal in size to the bounding box of the object.
	 */

	dcMem = CreateCompatibleDC(dc);
	oldBitmap = (HBITMAP)SelectObject(dcMem, CreateCompatibleBitmap(dc, width,
	oldBitmap = SelectObject(dcMem, CreateCompatibleBitmap(dc, width,
		height));
	oldPen = (HPEN)SelectObject(dcMem, pen);
	oldPen = SelectObject(dcMem, pen);
	BitBlt(dcMem, 0, 0, width, height, dc, rect.left, rect.top, SRCCOPY);

	/*
	 * Translate the object for rendering in the temporary drawing
	 * surface.
	 */

	for (i = 0; i < npoints; i++) {
	    winPoints[i].x -= rect.left;
	    winPoints[i].y -= rect.top;
	}

	/*
	 * Draw the object in the foreground color and copy it to the
	 * destination wherever the pattern is set.
	 */

	SetPolyFillMode(dcMem, (gc->fill_rule == EvenOddRule) ? ALTERNATE
		: WINDING);
	oldMemBrush = (HBRUSH)SelectObject(dcMem, CreateSolidBrush(gc->foreground));
        MakeAndStrokePath(dcMem, winPoints, npoints, func);
	oldMemBrush = SelectObject(dcMem, CreateSolidBrush(gc->foreground));
	func(dcMem, winPoints, npoints);
	BitBlt(dc, rect.left, rect.top, width, height, dcMem, 0, 0, COPYFG);

	/*
	 * If we are rendering an opaque stipple, then draw the polygon in the
	 * background color and copy it to the destination wherever the
	 * pattern is clear.
	 */

	if (gc->fill_style == FillOpaqueStippled) {
	    DeleteObject(SelectObject(dcMem,
		    CreateSolidBrush(gc->background)));
            MakeAndStrokePath(dcMem, winPoints, npoints, func);
	    func(dcMem, winPoints, npoints);
	    BitBlt(dc, rect.left, rect.top, width, height, dcMem, 0, 0,
		    COPYBG);
	}

	SelectObject(dcMem, oldPen);
	DeleteObject(SelectObject(dcMem, oldMemBrush));
	DeleteObject(SelectObject(dcMem, oldBitmap));
	DeleteDC(dcMem);
    } else {
	oldPen = (HPEN)SelectObject(dc, pen);
	oldBrush = (HBRUSH)SelectObject(dc, CreateSolidBrush(gc->foreground));
	oldPen = SelectObject(dc, pen);
	oldBrush = SelectObject(dc, CreateSolidBrush(gc->foreground));
	SetROP2(dc, tkpWinRopModes[gc->function]);

	SetPolyFillMode(dc, (gc->fill_rule == EvenOddRule) ? ALTERNATE
		: WINDING);
        MakeAndStrokePath(dc, winPoints, npoints, func);
	func(dc, winPoints, npoints);
	SelectObject(dc, oldPen);
    }
    DeleteObject(SelectObject(dc, oldBrush));
}

/*
 *----------------------------------------------------------------------
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996

997
998
999
1000
1001
1002
1003
930
931
932
933
934
935
936

937
938
939
940
941
942
943
944
945
946
947
948
949

950
951
952
953
954
955
956
957







-
+












-
+







int
XFillPolygon(
    Display *display,
    Drawable d,
    GC gc,
    XPoint *points,
    int npoints,
    TCL_UNUSED(int),
    int shape,
    int mode)
{
    HPEN pen;
    TkWinDCState state;
    HDC dc;

    if (d == None) {
	return BadDrawable;
    }

    dc = TkWinGetDrawableDC(display, d, &state);

    pen = (HPEN)GetStockObject(NULL_PEN);
    pen = GetStockObject(NULL_PEN);
    RenderObject(dc, gc, points, npoints, mode, pen, Polygon);

    TkWinReleaseDrawableDC(d, dc, &state);
    return Success;
}

/*
1033
1034
1035
1036
1037
1038
1039
1040
1041


1042
1043
1044

1045
1046
1047
1048
1049
1050
1051
987
988
989
990
991
992
993


994
995
996
997

998
999
1000
1001
1002
1003
1004
1005







-
-
+
+


-
+







	return BadDrawable;
    }

    dc = TkWinGetDrawableDC(display, d, &state);

    pen = SetUpGraphicsPort(gc);
    SetBkMode(dc, TRANSPARENT);
    oldPen = (HPEN)SelectObject(dc, pen);
    oldBrush = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH));
    oldPen = SelectObject(dc, pen);
    oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));
    SetROP2(dc, tkpWinRopModes[gc->function]);

    Rectangle(dc, x, y, x + (int)width + 1, y + (int)height + 1);
    Rectangle(dc, x, y, (int) x+width+1, (int) y+height+1);

    DeleteObject(SelectObject(dc, oldPen));
    SelectObject(dc, oldBrush);
    TkWinReleaseDrawableDC(d, dc, &state);
    return Success;
}

1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115
1116
1117
1118
1119
1120
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066

1067
1068
1069
1070
1071
1072
1073
1074







-
+














-
+







    Display *display,
    Drawable d,
    GC gc,
    int x, int y,
    unsigned int width, unsigned int height,
    int start, int extent)
{
    LastKnownRequestProcessed(display)++;
    display->request++;

    return DrawOrFillArc(display, d, gc, x, y, width, height, start, extent, 0);
}

int
XDrawArcs(
    Display *display,
    Drawable d,
    GC gc,
    XArc *arcs,
    int narcs)
{
    int ret = Success;

    LastKnownRequestProcessed(display)++;
    display->request++;

    while (narcs-- > 0) {
	ret = DrawOrFillArc(display, d, gc, arcs[0].x, arcs[0].y,
		    arcs[0].width, arcs[0].height,
		    arcs[0].angle1, arcs[0].angle2, 0);
	if (ret != Success) {
	    break;
1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128







-
+














-
+







    Display *display,
    Drawable d,
    GC gc,
    int x, int y,
    unsigned int width, unsigned int height,
    int start, int extent)
{
    LastKnownRequestProcessed(display)++;
    display->request++;

    return DrawOrFillArc(display, d, gc, x, y, width, height, start, extent, 1);
}

int
XFillArcs(
    Display *display,
    Drawable d,
    GC gc,
    XArc *arcs,
    int narcs)
{
    int ret = Success;

    LastKnownRequestProcessed(display)++;
    display->request++;

    while (narcs-- > 0) {
	ret = DrawOrFillArc(display, d, gc, arcs[0].x, arcs[0].y,
		    arcs[0].width, arcs[0].height,
		    arcs[0].angle1, arcs[0].angle2, 1);
	if (ret != Success) {
	    break;
1259
1260
1261
1262
1263
1264
1265
1266

1267
1268
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279

1280
1281

1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232

1233
1234

1235
1236
1237

1238
1239
1240
1241
1242
1243
1244
1245







-
+








-
+



-
+

-
+


-
+







    /*
     * Now draw a filled or open figure. Note that we have to increase the
     * size of the bounding box by one to account for the difference in pixel
     * definitions between X and Windows.
     */

    pen = SetUpGraphicsPort(gc);
    oldPen = (HPEN)SelectObject(dc, pen);
    oldPen = SelectObject(dc, pen);
    if (!fill) {
	/*
	 * Note that this call will leave a gap of one pixel at the end of the
	 * arc for thin arcs. We can't use ArcTo because it's only supported
	 * under Windows NT.
	 */

	SetBkMode(dc, TRANSPARENT);
	Arc(dc, x, y,  x + (int)width + 1, y + (int)height + 1, xstart, ystart,
	Arc(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart,
		xend, yend);
    } else {
	brush = CreateSolidBrush(gc->foreground);
	oldBrush = (HBRUSH)SelectObject(dc, brush);
	oldBrush = SelectObject(dc, brush);
	if (gc->arc_mode == ArcChord) {
	    Chord(dc, x, y,  x + (int)width + 1, y + (int)height + 1,
	    Chord(dc, x, y, (int) (x+width+1), (int) (y+height+1),
		    xstart, ystart, xend, yend);
	} else if (gc->arc_mode == ArcPieSlice) {
	    Pie(dc, x, y,  x+(int)width+1, y + (int)height + 1,
	    Pie(dc, x, y, (int) (x+width+1), (int) (y+height+1),
		    xstart, ystart, xend, yend);
	}
	DeleteObject(SelectObject(dc, oldBrush));
    }
    DeleteObject(SelectObject(dc, oldPen));
    TkWinReleaseDrawableDC(d, dc, &state);
    return Success;
1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358

1359
1360
1361
1362
1363
1364
1365
1366







-
+



-
+







 *
 *----------------------------------------------------------------------
 */

int
TkScrollWindow(
    Tk_Window tkwin,		/* The window to be scrolled. */
    TCL_UNUSED(GC),			/* GC for window to be scrolled. */
    GC gc,			/* GC for window to be scrolled. */
    int x, int y, int width, int height,
				/* Position rectangle to be scrolled. */
    int dx, int dy,		/* Distance rectangle should be moved. */
    Region damageRgn)		/* Region to accumulate damage in. */
    TkRegion damageRgn)		/* Region to accumulate damage in. */
{
    HWND hwnd = TkWinGetHWND(Tk_WindowId(tkwin));
    RECT scrollRect;

    scrollRect.left = x;
    scrollRect.top = y;
    scrollRect.right = x + width;
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478

1479
1480
1481

1482
1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1398
1399
1400
1401
1402
1403
1404

1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458

1459
1460

1461
1462
1463
1464
1465

1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477







-
+






-
+



















-
+


-
+









-
+













-
+

-





-
+












    rect.left = x;
    rect.top = y;
    rect.right = x + width;
    rect.bottom = y + height;
    oldColor = SetBkColor(dc, (COLORREF)pixel);
    SetBkMode(dc, OPAQUE);
    ExtTextOutW(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
    ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
    SetBkColor(dc, oldColor);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DrawHighlightBorder --
 * TkpDrawHighlightBorder --
 *
 *	This function draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus.
 *
 *      On Windows, we just draw the simple inset ring. On other sytems, e.g.
 *      the Mac, the focus ring is a little more complicated, so we need this
 *      abstraction.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
 *	to the outer area of "tkwin".
 *
 *----------------------------------------------------------------------
 */

void
Tk_DrawHighlightBorder(
TkpDrawHighlightBorder(
    Tk_Window tkwin,
    GC fgGC,
    TCL_UNUSED(GC),
    GC bgGC,
    int highlightWidth,
    Drawable drawable)
{
    TkDrawInsetFocusHighlight(tkwin, fgGC, highlightWidth, drawable, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpDrawFrameEx --
 * TkpDrawFrame --
 *
 *	This function draws the rectangular frame area.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Draws inside the tkwin area.
 *
 *----------------------------------------------------------------------
 */

void
TkpDrawFrameEx(
TkpDrawFrame(
    Tk_Window tkwin,
    Drawable drawable,
    Tk_3DBorder border,
    int highlightWidth,
    int borderWidth,
    int relief)
{
    Tk_Fill3DRectangle(tkwin, drawable, border, highlightWidth,
    Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), border, highlightWidth,
	    highlightWidth, Tk_Width(tkwin) - 2 * highlightWidth,
	    Tk_Height(tkwin) - 2 * highlightWidth, borderWidth, relief);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinEmbed.c.

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 * tkWinEmbed.c --
 *
 *	This file contains platform specific procedures for Windows platforms
 *	to provide basic operations needed for application embedding (where
 *	one application can use as its main window an internal window from
 *	another application).
 *
 * Copyright © 1996-1997 Sun Microsystems, Inc.
 * Copyright (c) 1996-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.
 */

#include "tkWinInt.h"

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44

45
46
47
48
49
50
51
30
31
32
33
34
35
36

37
38
39
40
41
42
43

44
45
46
47
48
49
50
51







-
+






-
+







				 * or NULL if the embedded application isn't
				 * in this process. */
    HWND embeddedMenuHWnd;	/* Tk's embedded menu window handler. */
    struct Container *nextPtr;	/* Next in list of all containers in this
				 * process. */
} Container;

typedef struct {
typedef struct ThreadSpecificData {
    Container *firstContainerPtr;
				/* First in list of all containers managed by
				 * this process. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

static void		ContainerEventProc(void *clientData,
static void		ContainerEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		EmbedGeometryRequest(Container *containerPtr,
			    int width, int height);
static void		EmbedWindowDeleted(TkWindow *winPtr);
static void		Tk_MapEmbeddedWindow(TkWindow* winPtr);
HWND			Tk_GetEmbeddedHWnd(TkWindow* winPtr);

65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







 *----------------------------------------------------------------------
 */

void
TkWinCleanupContainerList(void)
{
    Container *nextPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (; tsdPtr->firstContainerPtr != NULL;
	    tsdPtr->firstContainerPtr = nextPtr) {
	nextPtr = tsdPtr->firstContainerPtr->nextPtr;
	ckfree(tsdPtr->firstContainerPtr);
    }
92
93
94
95
96
97
98

99
100
101

102
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
92
93
94
95
96
97
98
99
100
101

102
103

104
105
106





107
108
109
110
111
112
113







+


-
+

-
+


-
-
-
-
-







 *
 * Side effects:
 *	Currently it does not do anything.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
TkpTestembedCmd(
    void *dummy,
    ClientData clientData,
    Tcl_Interp *interp,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    (void)dummy;
    (void)interp;
    (void)objc;
    (void)objv;

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DetachEmbeddedWindow --
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180

181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175

176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+












-
+





-
+




















-
+







static
void Tk_MapEmbeddedWindow(
    TkWindow *winPtr)		/* Top-level window that's about to be
				 * mapped. */
{
    if(!(winPtr->flags & TK_ALREADY_DEAD)) {
	HWND hwnd = (HWND)winPtr->privatePtr;
	int state = SendMessageW(hwnd, TK_STATE, -1, (WPARAM)-1) - 1;
	int state = SendMessage(hwnd, TK_STATE, -1, -1) - 1;

	if (state < 0 || state > 3) {
	    state = NormalState;
	}

	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {
	    /* empty body */
	}

	TkpWmSetState(winPtr, state);
	TkWmMapWindow(winPtr);
    }
    Tcl_Release(winPtr);
    Tcl_Release((ClientData)winPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_UseWindow --
 * TkpUseWindow --
 *
 *	This procedure causes a Tk window to use a given Windows handle for a
 *	window as its underlying window, rather than a new Windows window
 *	being created automatically. It is invoked by an embedded application
 *	to specify the window in which the application is embedded.
 *
 *	This procedure uses a simple attachment protocol by sending TK_INFO
 *	messages to the window to use with two sub messages:
 *
 *	    TK_CONTAINER_VERIFY - if a window handles this message, it should
 *		return either a (long)hwnd for a container or a -(long)hwnd
 *		for a non-container.
 *
 *	    TK_CONTAINER_ISAVAILABLE - a container window should return either
 *		a TRUE (non-zero) if it is available for use or a FALSE (zero)
 *		othersize.
 *
 *	The TK_INFO messages are required in order to verify if the window to
 *	use is a valid container. Without an id verification, an invalid
 *	window attachment may cause unexpected crashes/panics (bug 1096074).
 *	Additional sub messages may be defined/used in future for other
 *	Additional sub messages may be definded/used in future for other
 *	needs.
 *
 *	We do not enforce the above protocol for the reason of backward
 *	compatibility. If the window to use is unable to handle TK_INFO
 *	messages (e.g., legacy Tk container applications before 8.5), a dialog
 *	box with a warning message pops up and the user is asked to confirm if
 *	the attachment should proceed. However, we may have to enforce it in
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254







-
+


















-
+







 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_UseWindow(
TkpUseWindow(
    Tcl_Interp *interp,		/* If not NULL, used for error reporting if
				 * string is bogus. */
    Tk_Window tkwin,		/* Tk window that does not yet have an
				 * associated X window. */
    const char *string)		/* String identifying an X window to use for
				 * tkwin; must be an integer value. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    int id;
    HWND hwnd;
/*
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
*/

/*
    if (winPtr->window != None) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"can't modify container after widget is created", TCL_INDEX_NONE));
		"can't modify container after widget is created", -1));
	Tcl_SetErrorCode(interp, "TK", "EMBED", "POST_CREATE", NULL);
	return TCL_ERROR;
    }
*/

    if (strcmp(string, "") == 0) {
	if (winPtr->flags & TK_EMBEDDED) {
283
284
285
286
287
288
289
290

291
292

293
294

295
296
297
298
299
300

301
302
303
304
305
306
307
308
309
310

311
312
313


314
315
316

317
318
319
320
321
322
323
279
280
281
282
283
284
285

286
287

288
289

290
291
292
293
294
295

296
297
298
299
300
301
302
303
304
305

306
307


308
309
310
311

312
313
314
315
316
317
318
319







-
+

-
+

-
+





-
+









-
+

-
-
+
+


-
+







	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" doesn't exist", string));
	    Tcl_SetErrorCode(interp, "TK", "EMBED", "EXIST", NULL);
	}
	return TCL_ERROR;
    }

    id = SendMessageW(hwnd, TK_INFO, TK_CONTAINER_VERIFY, 0);
    id = SendMessage(hwnd, TK_INFO, TK_CONTAINER_VERIFY, 0);
    if (id == PTR2INT(hwnd)) {
	if (!SendMessageW(hwnd, TK_INFO, TK_CONTAINER_ISAVAILABLE, 0)) {
	if (!SendMessage(hwnd, TK_INFO, TK_CONTAINER_ISAVAILABLE, 0)) {
    	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "The container is already in use", TCL_INDEX_NONE));
		    "The container is already in use", -1));
	    Tcl_SetErrorCode(interp, "TK", "EMBED", "IN_USE", NULL);
	    return TCL_ERROR;
	}
    } else if (id == -PTR2INT(hwnd)) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"the window to use is not a Tk container", TCL_INDEX_NONE));
		"the window to use is not a Tk container", -1));
	Tcl_SetErrorCode(interp, "TK", "EMBED", "CONTAINER", NULL);
	return TCL_ERROR;
    } else {
	/*
	 * Proceed if the user decide to do so because it can be a legacy
	 * container application. However we may have to return a TCL_ERROR in
	 * order to avoid bug 1096074 in future.
	 */

	WCHAR msg[256];
	char msg[256];

	wsprintfW(msg, L"Unable to get information of window \"%.40hs\".  Attach to this\nwindow may have unpredictable results if it is not a valid container.\n\nPress Ok to proceed or Cancel to abort attaching.", string);
	if (IDCANCEL == MessageBoxW(hwnd, msg, L"Tk Warning",
	sprintf(msg, "Unable to get information of window \"%.80s\".  Attach to this\nwindow may have unpredictable results if it is not a valid container.\n\nPress Ok to proceed or Cancel to abort attaching.", string);
	if (IDCANCEL == MessageBoxA(hwnd, msg, "Tk Warning",
		MB_OKCANCEL | MB_ICONWARNING)) {
    	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Operation has been canceled", TCL_INDEX_NONE));
		    "Operation has been canceled", -1));
	    Tcl_SetErrorCode(interp, "TK", "EMBED", "CANCEL", NULL);
	    return TCL_ERROR;
	}
    }

    Tk_DetachEmbeddedWindow(winPtr, FALSE);

331
332
333
334
335
336
337
338
339


340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
327
328
329
330
331
332
333


334
335
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402







-
-
+
+







-
+
















-
+













-
+




















-
+







    winPtr->flags &= ~(TK_MAPPED);

    /*
     * Preserve the winPtr and create an idle handler to map the embedded
     * window.
     */

    Tcl_Preserve(winPtr);
    Tcl_DoWhenIdle((Tcl_IdleProc*) Tk_MapEmbeddedWindow, winPtr);
    Tcl_Preserve((ClientData) winPtr);
    Tcl_DoWhenIdle((Tcl_IdleProc*) Tk_MapEmbeddedWindow, (ClientData) winPtr);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeContainer --
 * TkpMakeContainer --
 *
 *	This procedure is called to indicate that a particular window will be
 *	a container for an embedded application. This changes certain aspects
 *	of the window's behavior, such as whether it will receive events
 *	anymore.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
Tk_MakeContainer(
TkpMakeContainer(
    Tk_Window tkwin)
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Register the window as a container so that, for example, we can find
     * out later if the embedded app. is in the same process.
     */

    Tk_MakeWindowExist(tkwin);
    containerPtr = (Container *)ckalloc(sizeof(Container));
    containerPtr = ckalloc(sizeof(Container));
    containerPtr->parentPtr = winPtr;
    containerPtr->parentHWnd = Tk_GetHWND(Tk_WindowId(tkwin));
    containerPtr->embeddedHWnd = NULL;
    containerPtr->embeddedPtr = NULL;
    containerPtr->embeddedMenuHWnd = NULL;
    containerPtr->nextPtr = tsdPtr->firstContainerPtr;
    tsdPtr->firstContainerPtr = containerPtr;
    winPtr->flags |= TK_CONTAINER;

    /*
     * Unlike in tkUnixEmbed.c, we don't make any requests for events in the
     * embedded window here. Now we just allow the embedding of another TK
     * application into TK windows. When the embedded window makes a request,
     * that will be done by sending to the container window a WM_USER message,
     * which will be intercepted by TkWinContainerProc.
     *
     * We need to get structure events of the container itself, though.
     */

    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
	    ContainerEventProc, containerPtr);
	    ContainerEventProc, (ClientData) containerPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinEmbeddedEventProc --
 *
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892

893
894
895
896
897
898

899
900
901
902
903
904
905
906
907
908
909
910



911
912
913
914
915
916
917
918
919
920
921
922




923
924
925
926
927
928
929
845
846
847
848
849
850
851

852
853
854
855
856
857
858









859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878

879
880
881
882
883
884

885
886
887
888
889
890
891
892
893
894



895
896
897
898
899
900
901
902
903
904
905




906
907
908
909
910
911
912
913
914
915
916







-
+






-
-
-
-
-
-
-
-
-




















-
+





-
+









-
-
-
+
+
+








-
-
-
-
+
+
+
+







 *	geometry information gets set for the container window.
 *
 *----------------------------------------------------------------------
 */

static void
ContainerEventProc(
    void *clientData,	/* Token for container window. */
    ClientData clientData,	/* Token for container window. */
    XEvent *eventPtr)		/* ResizeRequest event. */
{
    Container *containerPtr = (Container *)clientData;
    Tk_Window tkwin = (Tk_Window)containerPtr->parentPtr;

    if (eventPtr->type == ConfigureNotify) {

	/*
         * Send a ConfigureNotify  to the embedded application.
         */

        if (containerPtr->embeddedPtr != NULL) {
            TkDoConfigureNotify(containerPtr->embeddedPtr);
        }

	/*
	 * Resize the embedded window, if there is any.
	 */

	if (containerPtr->embeddedHWnd) {
	    SetWindowPos(containerPtr->embeddedHWnd, NULL, 0, 0,
		    Tk_Width(tkwin), Tk_Height(tkwin), SWP_NOZORDER);
	}
    } else if (eventPtr->type == DestroyNotify) {
	/*
	 * The container is gone, remove it from the list.
	 */

	EmbedWindowDeleted(containerPtr->parentPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetOtherWindow --
 * TkpGetOtherWindow --
 *
 *	If both the container and embedded window are in the same process,
 *	this procedure will return either one, given the other.
 *
 * Results:
 *	If tkwin is a container, the return value is the token for the
 *	If winPtr is a container, the return value is the token for the
 *	embedded window, and vice versa. If the "other" window isn't in this
 *	process, NULL is returned.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_GetOtherWindow(
    Tk_Window tkwin)		/* Tk's structure for a container or embedded
TkWindow *
TkpGetOtherWindow(
    TkWindow *winPtr)		/* Tk's structure for a container or embedded
				 * window. */
{
    Container *containerPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (containerPtr = tsdPtr->firstContainerPtr; containerPtr != NULL;
	    containerPtr = containerPtr->nextPtr) {
	if ((Tk_Window)containerPtr->embeddedPtr == tkwin) {
	    return (Tk_Window)containerPtr->parentPtr;
	} else if ((Tk_Window)containerPtr->parentPtr == tkwin) {
	    return (Tk_Window)containerPtr->embeddedPtr;
	if (containerPtr->embeddedPtr == winPtr) {
	    return containerPtr->parentPtr;
	} else if (containerPtr->parentPtr == winPtr) {
	    return containerPtr->embeddedPtr;
	}
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019







-
+







    TkWindow *topLevelPtr,	/* Top-level window containing desired focus
				 * window; should be embedded. */
    int force)			/* One means that the container should claim
				 * the focus if it doesn't currently have
				 * it. */
{
    HWND hwnd = GetParent(Tk_GetHWND(topLevelPtr->window));
    SendMessageW(hwnd, TK_CLAIMFOCUS, (WPARAM) force, 0);
    SendMessage(hwnd, TK_CLAIMFOCUS, (WPARAM) force, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpRedirectKeyEvent --
 *
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1037
1038
1039
1040
1041
1042
1043


1044
1045
1046
1047
1048
1049
1050







-
-







void
TkpRedirectKeyEvent(
    TkWindow *winPtr,		/* Window to which the event was originally
				 * reported. */
    XEvent *eventPtr)		/* X event to redirect (should be KeyPress or
				 * KeyRelease). */
{
    (void)winPtr;
    (void)eventPtr;
    /* not implemented */
}

/*
 *----------------------------------------------------------------------
 *
 * EmbedWindowDeleted --
1090
1091
1092
1093
1094
1095
1096
1097
1098


1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1075
1076
1077
1078
1079
1080
1081


1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097







-
-
+
+






-
+







     * Find the Container structure for this window work. Delete the
     * information about the embedded application and free the container's
     * record. The main container may be null. [Bug #476176]
     */

    prevPtr = NULL;
    containerPtr = tsdPtr->firstContainerPtr;
    while (1) {
	if (containerPtr == NULL) return;
    if (containerPtr == NULL) return;
    while (1) {
	if (containerPtr->embeddedPtr == winPtr) {
	    containerPtr->embeddedHWnd = NULL;
	    containerPtr->embeddedPtr = NULL;
	    break;
	}
	if (containerPtr->parentPtr == winPtr) {
	    SendMessageW(containerPtr->embeddedHWnd, WM_CLOSE, 0, 0);
	    SendMessage(containerPtr->embeddedHWnd, WM_CLOSE, 0, 0);
	    containerPtr->parentPtr = NULL;
	    containerPtr->embeddedPtr = NULL;
	    break;
	}
	prevPtr = containerPtr;
	containerPtr = containerPtr->nextPtr;
	if (containerPtr == NULL) {

Changes to win/tkWinFont.c.

1
2
3
4

5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58

59
60
61
62
63
64
65
1
2
3

4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56

57
58
59
60
61
62
63
64



-
+


-
-
-
+
+
+



















-
+

+

-
-




















-
+



-
+







/*
 * tkWinFont.c --
 *
 *	Contains the Windows implementation of the platform-independent font
 *	Contains the Windows implementation of the platform-independant font
 *	package interface.
 *
 * Copyright © 1994 Software Research Associates, Inc.
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1994 Software Research Associates, Inc.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "tkFont.h"

/*
 * The following structure represents a font family. It is assumed that all
 * screen fonts constructed from the same "font family" share certain
 * properties; all screen fonts with the same "font family" point to a shared
 * instance of this structure. The most important shared property is the
 * character existence metrics, used to determine if a screen font can display
 * a given Unicode character.
 *
 * Under Windows, a "font family" is uniquely identified by its face name.
 */

#define FONTMAP_SHIFT	    10
#define FONTMAP_SHIFT	    12

#define FONTMAP_PAGES	    	(1 << (21 - FONTMAP_SHIFT))
#define FONTMAP_BITSPERPAGE	(1 << FONTMAP_SHIFT)
#define FONTMAP_NUMCHARS	0x40000
#define FONTMAP_PAGES		(FONTMAP_NUMCHARS / FONTMAP_BITSPERPAGE)

typedef struct FontFamily {
    struct FontFamily *nextPtr;	/* Next in list of all known font families. */
    size_t refCount;		/* How many SubFonts are referring to this
				 * FontFamily. When the refCount drops to
				 * zero, this FontFamily may be freed. */
    /*
     * Key.
     */

    Tk_Uid faceName;		/* Face name key for this FontFamily. */

    /*
     * Derived properties.
     */

    Tcl_Encoding encoding;	/* Encoding for this font family. */
    int isSymbolFont;		/* Non-zero if this is a symbol font. */
    int isWideFont;		/* 1 if this is a double-byte font, 0
				 * otherwise. */
    BOOL (WINAPI *textOutProc)(HDC hdc, int x, int y, WCHAR *str, int len);
    BOOL (WINAPI *textOutProc)(HDC hdc, int x, int y, TCHAR *str, int len);
				/* The procedure to use to draw text after it
				 * has been converted from UTF-8 to the
				 * encoding of this font. */
    BOOL (WINAPI *getTextExtentPoint32Proc)(HDC, WCHAR *, int, LPSIZE);
    BOOL (WINAPI *getTextExtentPoint32Proc)(HDC, TCHAR *, int, LPSIZE);
				/* The procedure to use to measure text after
				 * it has been converted from UTF-8 to the
				 * encoding of this font. */

    char *fontMap[FONTMAP_PAGES];
				/* Two-level sparse table used to determine
				 * quickly if the specified character exists.
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131







-
+







				/* Builtin space for a limited number of
				 * SubFonts. */
    int numSubFonts;		/* Length of following array. */
    SubFont *subFontArray;	/* Array of SubFonts that have been loaded in
				 * order to draw/measure all the characters
				 * encountered by this font so far. All fonts
				 * start off with one SubFont initialized by
				 * InitFont() from the original set of font
				 * AllocFont() from the original set of font
				 * attributes. Usually points to
				 * staticSubFonts, but may point to malloced
				 * space if there are lots of SubFonts. */
    HWND hwnd;			/* Toplevel window of application that owns
				 * this font, used for getting HDC for
				 * offscreen measurements. */
    int pixelSize;		/* Original pixel size used when font was
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181






182
183
184
185
186
187
188
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193







-
+









+
+
+
+
+
+







    {DEFAULT_GUI_FONT,	    "defaultgui"},
    {OEM_FIXED_FONT,	    "oemfixed"},
    {SYSTEM_FIXED_FONT,	    "systemfixed"},
    {SYSTEM_FONT,	    "system"},
    {-1,		    NULL}
};

typedef struct {
typedef struct ThreadSpecificData {
    FontFamily *fontFamilyList; /* The list of font families that are
				 * currently loaded. As screen fonts are
				 * loaded, this list grows to hold information
				 * about what characters exist in each font
				 * family. */
    Tcl_HashTable uidTable;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Information cached about the system at startup time.
 */

static Tcl_Encoding systemEncoding;

/*
 * Procedures used only in this file.
 */

static FontFamily *	AllocFontFamily(HDC hdc, HFONT hFont, int base);
static SubFont *	CanUseFallback(HDC hdc, WinFont *fontPtr,
			    const char *fallbackName, int ch,
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219


220
221
222
223
224
225
226
227

228
229
230

231
232
233

234
235
236
237
238
239
240
209
210
211
212
213
214
215

216
217
218
219
220
221
222


223
224
225
226
227
228
229
230
231

232
233
234

235
236
237

238
239
240
241
242
243
244
245







-
+






-
-
+
+







-
+


-
+


-
+







			    double angle);
static void		InitFont(Tk_Window tkwin, HFONT hFont,
			    int overstrike, WinFont *tkFontPtr);
static inline void	InitSubFont(HDC hdc, HFONT hFont, int base,
			    SubFont *subFontPtr);
static int		CreateNamedSystemLogFont(Tcl_Interp *interp,
			    Tk_Window tkwin, const char* name,
			    LOGFONTW* logFontPtr);
			    LOGFONT* logFontPtr);
static int		CreateNamedSystemFont(Tcl_Interp *interp,
			    Tk_Window tkwin, const char* name, HFONT hFont);
static int		LoadFontRanges(HDC hdc, HFONT hFont,
			    USHORT **startCount, USHORT **endCount,
			    int *symbolPtr);
static void		MultiFontTextOut(HDC hdc, WinFont *fontPtr,
			    const char *source, int numBytes,
			    double x, double y, double angle);
			    const char *source, int numBytes, int x, int y,
			    double angle);
static void		ReleaseFont(WinFont *fontPtr);
static inline void	ReleaseSubFont(SubFont *subFontPtr);
static int		SeenName(const char *name, Tcl_DString *dsPtr);
static inline HFONT	SelectFont(HDC hdc, WinFont *fontPtr,
			    SubFont *subFontPtr, double angle);
static inline void	SwapLong(PULONG p);
static inline void	SwapShort(USHORT *p);
static int CALLBACK	WinFontCanUseProc(ENUMLOGFONTW *lfPtr,
static int CALLBACK	WinFontCanUseProc(ENUMLOGFONT *lfPtr,
			    NEWTEXTMETRIC *tmPtr, int fontType,
			    LPARAM lParam);
static int CALLBACK	WinFontExistProc(ENUMLOGFONTW *lfPtr,
static int CALLBACK	WinFontExistProc(ENUMLOGFONT *lfPtr,
			    NEWTEXTMETRIC *tmPtr, int fontType,
			    LPARAM lParam);
static int CALLBACK	WinFontFamilyEnumProc(ENUMLOGFONTW *lfPtr,
static int CALLBACK	WinFontFamilyEnumProc(ENUMLOGFONT *lfPtr,
			    NEWTEXTMETRIC *tmPtr, int fontType,
			    LPARAM lParam);

/*
 *-------------------------------------------------------------------------
 *
 * TkpFontPkgInit --
253
254
255
256
257
258
259

260
261
262
263
264
265
266
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272







+







 *-------------------------------------------------------------------------
 */

void
TkpFontPkgInit(
    TkMainInfo *mainPtr)	/* The application being created. */
{
    systemEncoding = TkWinGetUnicodeEncoding();
    TkWinSetupSystemFonts(mainPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpGetNativeFont --
296
297
298
299
300
301
302
303
304


305
306
307
308
309
310
311
302
303
304
305
306
307
308


309
310
311
312
313
314
315
316
317







-
-
+
+








    object = TkFindStateNum(NULL, NULL, systemMap, name);
    if (object < 0) {
	return NULL;
    }

    tkwin = (Tk_Window) ((TkWindow *) tkwin)->mainPtr->winPtr;
    fontPtr = (WinFont *)ckalloc(sizeof(WinFont));
    InitFont(tkwin, (HFONT)GetStockObject(object), 0, fontPtr);
    fontPtr = ckalloc(sizeof(WinFont));
    InitFont(tkwin, GetStockObject(object), 0, fontPtr);

    return (TkFont *) fontPtr;
}

/*
 *---------------------------------------------------------------------------
 *
321
322
323
324
325
326
327
328

329
330
331
332
333

334
335
336
337
338
339
340
327
328
329
330
331
332
333

334
335
336
337
338

339
340
341
342
343
344
345
346







-
+




-
+







 */

static int
CreateNamedSystemLogFont(
    Tcl_Interp *interp,
    Tk_Window tkwin,
    const char* name,
    LOGFONTW* logFontPtr)
    LOGFONT* logFontPtr)
{
    HFONT hFont;
    int r;

    hFont = CreateFontIndirectW(logFontPtr);
    hFont = CreateFontIndirect(logFontPtr);
    r = CreateNamedSystemFont(interp, tkwin, name, hFont);
    DeleteObject((HGDIOBJ)hFont);
    return r;
}

/*
 *---------------------------------------------------------------------------
382
383
384
385
386
387
388
389
390


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408

409
410

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441

442
443

444
445
446
447
448
449
450
388
389
390
391
392
393
394


395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441
442
443
444
445
446

447
448

449
450
451
452
453
454
455
456







-
-
+
+

















-
+

-
+


















-
+











-
+

-
+







void
TkWinSetupSystemFonts(
    TkMainInfo *mainPtr)
{
    Tcl_Interp *interp;
    Tk_Window tkwin;
    const TkStateMap *mapPtr;
    NONCLIENTMETRICSW ncMetrics;
    ICONMETRICSW iconMetrics;
    NONCLIENTMETRICS ncMetrics;
    ICONMETRICS iconMetrics;
    HFONT hFont;

    interp = (Tcl_Interp *) mainPtr->interp;
    tkwin = (Tk_Window) mainPtr->winPtr;

    /* force this for now */
    if (((TkWindow *) tkwin)->mainPtr == NULL) {
	((TkWindow *) tkwin)->mainPtr = mainPtr;
    }

    /*
     * If this API call fails then we will fallback to setting these named
     * fonts from script in ttk/fonts.tcl. So far I've only seen it fail when
     * WINVER has been defined for a higher platform than we are running on.
     * (i.e. WINVER=0x0600 and running on XP).
     */

    memset(&ncMetrics, 0, sizeof(ncMetrics));
    ZeroMemory(&ncMetrics, sizeof(ncMetrics));
    ncMetrics.cbSize = sizeof(ncMetrics);
    if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
    if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
	    sizeof(ncMetrics), &ncMetrics, 0)) {
	CreateNamedSystemLogFont(interp, tkwin, "TkDefaultFont",
		&ncMetrics.lfMessageFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkHeadingFont",
		&ncMetrics.lfMessageFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkTextFont",
		&ncMetrics.lfMessageFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkMenuFont",
		&ncMetrics.lfMenuFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkTooltipFont",
		&ncMetrics.lfStatusFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkCaptionFont",
		&ncMetrics.lfCaptionFont);
	CreateNamedSystemLogFont(interp, tkwin, "TkSmallCaptionFont",
		&ncMetrics.lfSmCaptionFont);
    }

    iconMetrics.cbSize = sizeof(iconMetrics);
    if (SystemParametersInfoW(SPI_GETICONMETRICS, sizeof(iconMetrics),
    if (SystemParametersInfo(SPI_GETICONMETRICS, sizeof(iconMetrics),
	    &iconMetrics, 0)) {
	CreateNamedSystemLogFont(interp, tkwin, "TkIconFont",
		&iconMetrics.lfFont);
    }

    /*
     * Identify an available fixed font. Equivalent to ANSI_FIXED_FONT but
     * more reliable on Russian Windows.
     */

    {
	LOGFONTW lfFixed = {
	LOGFONT lfFixed = {
	    0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
	    0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, L""
	    0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, TEXT("")
	};
	long pointSize, dpi;
	HDC hdc = GetDC(NULL);
	dpi = GetDeviceCaps(hdc, LOGPIXELSY);
	pointSize = -MulDiv(ncMetrics.lfMessageFont.lfHeight, 72, dpi);
	lfFixed.lfHeight = -MulDiv(pointSize+1, dpi, 72);
	ReleaseDC(NULL, hdc);
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574







-
+








  found:
    ReleaseDC(hwnd, hdc);

    hFont = GetScreenFont(faPtr, faceName,
	    (int)(TkFontGetPixels(tkwin, faPtr->size) + 0.5), 0.0);
    if (tkFontPtr == NULL) {
	fontPtr = (WinFont *)ckalloc(sizeof(WinFont));
	fontPtr = ckalloc(sizeof(WinFont));
    } else {
	fontPtr = (WinFont *) tkFontPtr;
	ReleaseFont(fontPtr);
    }
    InitFont(tkwin, hFont, faPtr->overstrike, fontPtr);

    return (TkFont *) fontPtr;
641
642
643
644
645
646
647
648

649
650
651
652
653
654
655
656
657
658



659
660
661

662
663
664
665

666
667
668
669
670
671
672
673
647
648
649
650
651
652
653

654
655
656
657
658
659
660
661



662
663
664
665
666

667
668
669
670

671

672
673
674
675
676
677
678







-
+







-
-
-
+
+
+


-
+



-
+
-







     * are not allowed, so the ANSI version of EnumFontFamilies will work. On
     * an internationalized version of 95, there may be fonts with
     * international names; the ANSI version will work, fetching the name in
     * the system code page. Can't use the Unicode version of EnumFontFamilies
     * because it only exists under NT.
     */

    EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontFamilyEnumProc,
    EnumFontFamilies(hdc, NULL, (FONTENUMPROC) WinFontFamilyEnumProc,
	    (LPARAM) resultObj);
    ReleaseDC(hwnd, hdc);
    Tcl_SetObjResult(interp, resultObj);
}

static int CALLBACK
WinFontFamilyEnumProc(
    ENUMLOGFONTW *lfPtr,		/* Logical-font data. */
    TCL_UNUSED(NEWTEXTMETRIC *),	/* Physical-font data (not used). */
    TCL_UNUSED(int),		/* Type of font (not used). */
    ENUMLOGFONT *lfPtr,		/* Logical-font data. */
    NEWTEXTMETRIC *tmPtr,	/* Physical-font data (not used). */
    int fontType,		/* Type of font (not used). */
    LPARAM lParam)		/* Result object to hold result. */
{
    WCHAR *faceName = lfPtr->elfLogFont.lfFaceName;
    char *faceName = (char *) lfPtr->elfLogFont.lfFaceName;
    Tcl_Obj *resultObj = (Tcl_Obj *) lParam;
    Tcl_DString faceString;

    Tcl_DStringInit(&faceString);
    Tcl_ExternalToUtfDString(systemEncoding, faceName, -1, &faceString);
    Tcl_WCharToUtfDString(faceName, wcslen(faceName), &faceString);
    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
	    Tcl_DStringValue(&faceString), Tcl_DStringLength(&faceString)));
    Tcl_DStringFree(&faceString);
    return 1;
}

/*
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
703
704
705
706
707
708
709

710
711
712
713
714
715
716
717







-
+







    FontFamily *familyPtr;
    Tcl_Obj *resultPtr, *strPtr;

    resultPtr = Tcl_NewObj();
    fontPtr = (WinFont *) tkfont;
    for (i = 0; i < fontPtr->numSubFonts; i++) {
	familyPtr = fontPtr->subFontArray[i].familyPtr;
	strPtr = Tcl_NewStringObj(familyPtr->faceName, TCL_INDEX_NONE);
	strPtr = Tcl_NewStringObj(familyPtr->faceName, -1);
	Tcl_ListObjAppendElement(NULL, resultPtr, strPtr);
    }
    Tcl_SetObjResult(interp, resultPtr);
}

/*
 *----------------------------------------------------------------------
742
743
744
745
746
747
748
749

750
751
752
753
754
755
756


757
758
759
760
761
762
763
747
748
749
750
751
752
753

754
755
756
757
758
759


760
761
762
763
764
765
766
767
768







-
+





-
-
+
+







				 * memory allocation */
    SubFont *thisSubFontPtr =
	    FindSubFontForChar(fontPtr, c, &lastSubFontPtr);
				/* Pointer to the subfont to use for the given
				 * character */
    FontFamily *familyPtr = thisSubFontPtr->familyPtr;
    HFONT oldfont;		/* Saved font from the device context */
    TEXTMETRICW tm;		/* Font metrics of the selected subfont */
    TEXTMETRIC tm;		/* Font metrics of the selected subfont */

    /*
     * Get the font attributes.
     */

    oldfont = (HFONT)SelectObject(hdc, thisSubFontPtr->hFont0);
    GetTextMetricsW(hdc, &tm);
    oldfont = SelectObject(hdc, thisSubFontPtr->hFont0);
    GetTextMetrics(hdc, &tm);
    SelectObject(hdc, oldfont);
    ReleaseDC(fontPtr->hwnd, hdc);
    faPtr->family = familyPtr->faceName;
    faPtr->size = TkFontGetPoints(tkwin,
	    (double)(tm.tmInternalLeading - tm.tmHeight));
    faPtr->weight = (tm.tmWeight > FW_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
    faPtr->slant = tm.tmItalic ? TK_FS_ITALIC : TK_FS_ROMAN;
786
787
788
789
790
791
792
793

794
795

796
797
798
799
800
801
802
791
792
793
794
795
796
797

798
799

800
801
802
803
804
805
806
807







-
+

-
+







 */

int
Tk_MeasureChars(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    Tcl_Size numBytes,		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string. */
	int maxLength,		/* If >= 0, maxLength specifies the longest
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length in pixels; don't
				 * consider any character that would cross
				 * this x-position. If < 0, then line length
				 * is unbounded and the flags argument is
				 * ignored. */
    int flags,			/* Various flag bits OR-ed together:
				 * TK_PARTIAL_OK means include the last char
826
827
828
829
830
831
832
833

834
835
836
837
838
839
840
841
842
843
844
845
846
847
848

849
850
851
852
853


854
855


856
857
858
859
860
861
862
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845
846
847
848
849
850
851
852

853
854
855
856


857
858
859

860
861
862
863
864
865
866
867
868







-
+














-
+



-
-
+
+

-
+
+







	return 0;
    }

    fontPtr = (WinFont *) tkfont;

    hdc = GetDC(fontPtr->hwnd);
    lastSubFontPtr = &fontPtr->subFontArray[0];
    oldFont = (HFONT)SelectObject(hdc, lastSubFontPtr->hFont0);
    oldFont = SelectObject(hdc, lastSubFontPtr->hFont0);

    /*
     * A three step process:
     * 1. Find a contiguous range of characters that can all be represented by
     *    a single screen font.
     * 2. Convert those chars to the encoding of that font.
     * 3. Measure converted chars.
     */

    moretomeasure = 0;
    curX = 0;
    start = source;
    end = start + numBytes;
    for (p = start; p < end; ) {
	next = p + Tcl_UtfToUniChar(p, &ch);
	next = p + TkUtfToUniChar(p, &ch);
	thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);
	if (thisSubFontPtr != lastSubFontPtr) {
	    familyPtr = lastSubFontPtr->familyPtr;
	    WCHAR *wstr = (WCHAR *)Tcl_UtfToExternalDString(familyPtr->encoding, start,
		    p - start, &runString);
	    Tcl_UtfToExternalDString(familyPtr->encoding, start,
		    (int) (p - start), &runString);
	    size.cx = 0;
	    familyPtr->getTextExtentPoint32Proc(hdc, wstr,
	    familyPtr->getTextExtentPoint32Proc(hdc,
		    (TCHAR *)Tcl_DStringValue(&runString),
		    Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
		    &size);
	    Tcl_DStringFree(&runString);
	    if (maxLength >= 0 && (curX+size.cx) > maxLength) {
		moretomeasure = 1;
		break;
	    }
872
873
874
875
876
877
878
879
880


881
882

883
884
885
886
887
888
889
878
879
880
881
882
883
884


885
886
887

888
889
890
891
892
893
894
895







-
-
+
+

-
+







    if (!moretomeasure) {
	/*
	 * We get here if the previous loop was just finished normally,
	 * without a break. Just measure the last run and that's it.
	 */

	familyPtr = lastSubFontPtr->familyPtr;
	WCHAR *wstr = (WCHAR *)Tcl_UtfToExternalDString(familyPtr->encoding, start,
		p - start, &runString);
	Tcl_UtfToExternalDString(familyPtr->encoding, start,
		(int) (p - start), &runString);
	size.cx = 0;
	familyPtr->getTextExtentPoint32Proc(hdc, wstr,
	familyPtr->getTextExtentPoint32Proc(hdc, (TCHAR *) Tcl_DStringValue(&runString),
		Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
		&size);
	Tcl_DStringFree(&runString);
	if (maxLength >= 0 && (curX+size.cx) > maxLength) {
	    moretomeasure = 1;
	} else {
	    curX += size.cx;
902
903
904
905
906
907
908
909

910
911

912
913
914
915
916

917
918
919
920
921
922
923
908
909
910
911
912
913
914

915
916

917
918
919
920
921

922
923
924
925
926
927
928
929







-
+

-
+




-
+







	char buf[16];
	int dstWrote;
	int lastSize = 0;

	familyPtr = lastSubFontPtr->familyPtr;
	Tcl_DStringInit(&runString);
	for (p = start; p < end; ) {
	    next = p + Tcl_UtfToUniChar(p, &ch);
	    next = p + TkUtfToUniChar(p, &ch);
	    Tcl_UtfToExternal(NULL, familyPtr->encoding, p,
		    (int) (next - p), TCL_ENCODING_PROFILE_TCL8, NULL, buf, sizeof(buf), NULL,
		    (int) (next - p), 0, NULL, buf, sizeof(buf), NULL,
		    &dstWrote, NULL);
	    Tcl_DStringAppend(&runString,buf,dstWrote);
	    size.cx = 0;
	    familyPtr->getTextExtentPoint32Proc(hdc,
		    (WCHAR *) Tcl_DStringValue(&runString),
		    (TCHAR *) Tcl_DStringValue(&runString),
		    Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
		    &size);
	    if ((curX+size.cx) > maxLength) {
		break;
	    }
	    lastSize = size.cx;
	    p = next;
957
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
963
964
965
966
967
968
969

970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990

991
992
993
994
995
996
997
998







-
+




















-
+







	const char *lastWordBreak = NULL;
	int ch2;

	end = p;
	p = source;
	ch = ' ';
	while (p < end) {
	    next = p + Tcl_UtfToUniChar(p, &ch2);
	    next = p + TkUtfToUniChar(p, &ch2);
	    if ((ch != ' ') && (ch2 == ' ')) {
		lastWordBreak = p;
	    }
	    p = next;
	    ch = ch2;
	}

	if (lastWordBreak != NULL) {
	    return Tk_MeasureChars(tkfont, source, lastWordBreak-source,
		    -1, 0, lengthPtr);
	}
	if (flags & TK_AT_LEAST_ONE) {
	    p = end;
	} else {
	    p = source;
	    curX = 0;
	}
    }

    *lengthPtr = curX;
    return (int)(p - source);
    return p - source;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkpMeasureCharsInContext --
 *
1011
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021


1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1017
1018
1019
1020
1021
1022
1023

1024
1025


1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053







-
+

-
-
+
+


















+







 */

int
TkpMeasureCharsInContext(
    Tk_Font tkfont,		/* Font in which characters will be drawn. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. */
    TCL_UNUSED(Tcl_Size),		/* Maximum number of bytes to consider from
    int numBytes,		/* Maximum number of bytes to consider from
				 * source string in all. */
    Tcl_Size rangeStart,		/* Index of first byte to measure. */
    Tcl_Size rangeLength,		/* Length of range to measure in bytes. */
    int rangeStart,		/* Index of first byte to measure. */
    int rangeLength,		/* Length of range to measure in bytes. */
    int maxLength,		/* If >= 0, maxLength specifies the longest
				 * permissible line length; don't consider any
				 * character that would cross this x-position.
				 * If < 0, then line length is unbounded and
				 * the flags argument is ignored. */
    int flags,			/* Various flag bits OR-ed together:
				 * TK_PARTIAL_OK means include the last char
				 * which only partially fit on this line.
				 * TK_WHOLE_WORDS means stop on a word
				 * boundary, if possible. TK_AT_LEAST_ONE
				 * means return at least one character even if
				 * no characters fit. TK_ISOLATE_END means
				 * that the last character should not be
				 * considered in context with the rest of the
				 * string (used for breaking lines). */
    int *lengthPtr)		/* Filled with x-location just after the
				 * terminating character. */
{
    (void) numBytes; /*unused*/
    return Tk_MeasureChars(tkfont, source + rangeStart, rangeLength,
	    maxLength, flags, lengthPtr);
}

/*
 *---------------------------------------------------------------------------
 *
1058
1059
1060
1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074

1075
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097







-
+








-
+








-
+







 */

void
Tk_DrawChars(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    TCL_UNUSED(Tk_Font),	/* Font in which characters will be drawn;
    Tk_Font tkfont,		/* Font in which characters will be drawn;
				 * must be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    int x, int y)		/* Coordinates at which to place origin of
				 * string when drawing. */
{
    HDC dc;
    WinFont *fontPtr;
    TkWinDCState state;

    fontPtr = (WinFont *) gc->font;
    LastKnownRequestProcessed(display)++;
    display->request++;

    if (drawable == None) {
	return;
    }

    dc = TkWinGetDrawableDC(display, drawable, &state);

1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132

1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1105
1106
1107
1108
1109
1110
1111

1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138

1139
1140
1141

1142
1143
1144
1145
1146
1147
1148
1149







-
+














-
+











-
+


-
+







    if ((gc->fill_style == FillStippled
	    || gc->fill_style == FillOpaqueStippled)
	    && gc->stipple != None) {
	TkWinDrawable *twdPtr = (TkWinDrawable *) gc->stipple;
	HBRUSH oldBrush, stipple;
	HBITMAP oldBitmap, bitmap;
	HDC dcMem;
	TEXTMETRICW tm;
	TEXTMETRIC tm;
	SIZE size;

	if (twdPtr->type != TWD_BITMAP) {
	    Tcl_Panic("unexpected drawable type in stipple");
	}

	/*
	 * Select stipple pattern into destination dc.
	 */

	dcMem = CreateCompatibleDC(dc);

	stipple = CreatePatternBrush(twdPtr->bitmap.handle);
	SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
	oldBrush = (HBRUSH)SelectObject(dc, stipple);
	oldBrush = SelectObject(dc, stipple);

	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
	SetTextColor(dcMem, gc->foreground);
	SetBkMode(dcMem, TRANSPARENT);
	SetBkColor(dcMem, RGB(0, 0, 0));

	/*
	 * Compute the bounding box and create a compatible bitmap.
	 */

	GetTextExtentPointA(dcMem, source, numBytes, &size);
	GetTextMetricsW(dcMem, &tm);
	GetTextMetrics(dcMem, &tm);
	size.cx -= tm.tmOverhang;
	bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
	oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap);
	oldBitmap = SelectObject(dcMem, bitmap);

	/*
	 * The following code is tricky because fonts are rendered in multiple
	 * colors. First we draw onto a black background and copy the white
	 * bits. Then we draw onto a white background and copy the black bits.
	 * Both the foreground and background bits of the font are ANDed with
	 * the stipple pattern as they are copied.
1164
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186

1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203







-
+














-
+


-
+







	SetTextAlign(dc, TA_LEFT | TA_BASELINE);
	SetTextColor(dc, gc->foreground);
	SetBkMode(dc, TRANSPARENT);
	MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, 0.0);
    } else {
	HBITMAP oldBitmap, bitmap;
	HDC dcMem;
	TEXTMETRICW tm;
	TEXTMETRIC tm;
	SIZE size;

	dcMem = CreateCompatibleDC(dc);

	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
	SetTextColor(dcMem, gc->foreground);
	SetBkMode(dcMem, TRANSPARENT);
	SetBkColor(dcMem, RGB(0, 0, 0));

	/*
	 * Compute the bounding box and create a compatible bitmap.
	 */

	GetTextExtentPointA(dcMem, source, numBytes, &size);
	GetTextMetricsW(dcMem, &tm);
	GetTextMetrics(dcMem, &tm);
	size.cx -= tm.tmOverhang;
	bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
	oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap);
	oldBitmap = SelectObject(dcMem, bitmap);

	MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent,
		0.0);
	BitBlt(dc, x, y - tm.tmAscent, size.cx, size.cy, dcMem,
		0, 0, (DWORD) tkpWinBltModes[gc->function]);

	/*
1205
1206
1207
1208
1209
1210
1211
1212

1213
1214
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227
1228
1229
1230
1231

1232
1233
1234
1235
1236
1237
1238
1212
1213
1214
1215
1216
1217
1218

1219
1220
1221
1222
1223
1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238
1239
1240
1241
1242
1243
1244
1245







-
+








-
+









-
+







}

void
TkDrawAngledChars(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    TCL_UNUSED(Tk_Font),	/* Font in which characters will be drawn;
    Tk_Font tkfont,		/* Font in which characters will be drawn;
				 * must be the same as font used in GC. */
    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    Tcl_Size numBytes,		/* Number of bytes in string. */
    int numBytes,		/* Number of bytes in string. */
    double x, double y,		/* Coordinates at which to place origin of
				 * string when drawing. */
    double angle)
{
    HDC dc;
    WinFont *fontPtr;
    TkWinDCState state;

    fontPtr = (WinFont *) gc->font;
    LastKnownRequestProcessed(display)++;
    display->request++;

    if (drawable == None) {
	return;
    }

    dc = TkWinGetDrawableDC(display, drawable, &state);

1246
1247
1248
1249
1250
1251
1252
1253

1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268

1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280

1281
1282
1283

1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294

1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315

1316
1317
1318
1319

1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334

1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304

1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325

1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

1341
1342
1343

1344
1345
1346
1347
1348
1349
1350
1351







-
+














-
+











-
+


-
+










-
+



-
+
















-
+



-
+














-
+


-
+







    if ((gc->fill_style == FillStippled
	    || gc->fill_style == FillOpaqueStippled)
	    && gc->stipple != None) {
	TkWinDrawable *twdPtr = (TkWinDrawable *)gc->stipple;
	HBRUSH oldBrush, stipple;
	HBITMAP oldBitmap, bitmap;
	HDC dcMem;
	TEXTMETRICW tm;
	TEXTMETRIC tm;
	SIZE size;

	if (twdPtr->type != TWD_BITMAP) {
	    Tcl_Panic("unexpected drawable type in stipple");
	}

	/*
	 * Select stipple pattern into destination dc.
	 */

	dcMem = CreateCompatibleDC(dc);

	stipple = CreatePatternBrush(twdPtr->bitmap.handle);
	SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
	oldBrush = (HBRUSH)SelectObject(dc, stipple);
	oldBrush = SelectObject(dc, stipple);

	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
	SetTextColor(dcMem, gc->foreground);
	SetBkMode(dcMem, TRANSPARENT);
	SetBkColor(dcMem, RGB(0, 0, 0));

	/*
	 * Compute the bounding box and create a compatible bitmap.
	 */

	GetTextExtentPointA(dcMem, source, numBytes, &size);
	GetTextMetricsW(dcMem, &tm);
	GetTextMetrics(dcMem, &tm);
	size.cx -= tm.tmOverhang;
	bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
	oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap);
	oldBitmap = SelectObject(dcMem, bitmap);

	/*
	 * The following code is tricky because fonts are rendered in multiple
	 * colors. First we draw onto a black background and copy the white
	 * bits. Then we draw onto a white background and copy the black bits.
	 * Both the foreground and background bits of the font are ANDed with
	 * the stipple pattern as they are copied.
	 */

	PatBlt(dcMem, 0, 0, size.cx, size.cy, BLACKNESS);
	MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, angle);
	MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
	BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
		0, 0, 0xEA02E9);
	PatBlt(dcMem, 0, 0, size.cx, size.cy, WHITENESS);
	MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, angle);
	MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
	BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
		0, 0, 0x8A0E06);

	/*
	 * Destroy the temporary bitmap and restore the device context.
	 */

	SelectObject(dcMem, oldBitmap);
	DeleteObject(bitmap);
	DeleteDC(dcMem);
	SelectObject(dc, oldBrush);
	DeleteObject(stipple);
    } else if (gc->function == GXcopy) {
	SetTextAlign(dc, TA_LEFT | TA_BASELINE);
	SetTextColor(dc, gc->foreground);
	SetBkMode(dc, TRANSPARENT);
	MultiFontTextOut(dc, fontPtr, source, numBytes, x, y, angle);
	MultiFontTextOut(dc, fontPtr, source, numBytes, (int)x, (int)y, angle);
    } else {
	HBITMAP oldBitmap, bitmap;
	HDC dcMem;
	TEXTMETRICW tm;
	TEXTMETRIC tm;
	SIZE size;

	dcMem = CreateCompatibleDC(dc);

	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
	SetTextColor(dcMem, gc->foreground);
	SetBkMode(dcMem, TRANSPARENT);
	SetBkColor(dcMem, RGB(0, 0, 0));

	/*
	 * Compute the bounding box and create a compatible bitmap.
	 */

	GetTextExtentPointA(dcMem, source, numBytes, &size);
	GetTextMetricsW(dcMem, &tm);
	GetTextMetrics(dcMem, &tm);
	size.cx -= tm.tmOverhang;
	bitmap = CreateCompatibleBitmap(dc, size.cx, size.cy);
	oldBitmap = (HBITMAP)SelectObject(dcMem, bitmap);
	oldBitmap = SelectObject(dcMem, bitmap);

	MultiFontTextOut(dcMem, fontPtr, source, numBytes, 0, tm.tmAscent,
		angle);
	BitBlt(dc, (int)x, (int)y - tm.tmAscent, size.cx, size.cy, dcMem,
		0, 0, (DWORD) tkpWinBltModes[gc->function]);

	/*
1356
1357
1358
1359
1360
1361
1362
1363

1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1363
1364
1365
1366
1367
1368
1369

1370



1371
1372
1373
1374
1375
1376
1377







-
+
-
-
-







 *---------------------------------------------------------------------------
 *
 * TkpDrawCharsInContext --
 *
 *	Draw a string of characters on the screen like Tk_DrawChars(), but
 *	with access to all the characters on the line for context. On Windows
 *	this context isn't consulted, so we just call Tk_DrawChars().
  *
 *
 *      Note: TK_DRAW_IN_CONTEXT being currently defined only on macOS, this
 *            function is unused (and possibly unfinished). See [7655f65ae7].
*
 * Results:
 *	None.
 *
 * Side effects:
 *	Information gets drawn on the screen.
 *
 *---------------------------------------------------------------------------
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392



1393
1394
1395
1396
1397


1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1387
1388
1389
1390
1391
1392
1393



1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408






























1409
1410
1411
1412
1413
1414
1415







-
-
-
+
+
+





+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    const char *source,		/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that
				 * is passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    int numBytes,		/* Number of bytes in string. */
    int rangeStart,		/* Index of first byte to draw. */
    int rangeLength,		/* Length of range to draw in bytes. */
    int x, int y)		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
{
    int widthUntilStart;

    (void) numBytes; /*unused*/

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    Tk_DrawChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+widthUntilStart, y);
}

void
TkpDrawAngledCharsInContext(
    Display *display,		/* Display on which to draw. */
    Drawable drawable,		/* Window or pixmap in which to draw. */
    GC gc,			/* Graphics context for drawing characters. */
    Tk_Font tkfont,		/* Font in which characters will be drawn; must
				 * be the same as font used in GC. */
    const char * source,	/* UTF-8 string to be displayed. Need not be
				 * '\0' terminated. All Tk meta-characters
				 * (tabs, control characters, and newlines)
				 * should be stripped out of the string that is
				 * passed to this function. If they are not
				 * stripped out, they will be displayed as
				 * regular printing characters. */
    TCL_UNUSED(Tcl_Size),		/* Number of bytes in string. */
    Tcl_Size rangeStart,		/* Index of first byte to draw. */
    Tcl_Size rangeLength,		/* Length of range to draw in bytes. */
    double x, double y,		/* Coordinates at which to place origin of the
				 * whole (not just the range) string when
				 * drawing. */
    double angle)		/* What angle to put text at, in degrees. */
{
    int widthUntilStart;
    double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

    Tk_MeasureChars(tkfont, source, rangeStart, -1, 0, &widthUntilStart);
    TkDrawAngledChars(display, drawable, gc, tkfont, source + rangeStart,
	    rangeLength, x+cosA*widthUntilStart, y-sinA*widthUntilStart, angle);
}

/*
 *-------------------------------------------------------------------------
 *
 * MultiFontTextOut --
 *
 *	Helper function for Tk_DrawChars. Draws characters, using the various
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475
1476
1477

1478
1479
1480
1481

1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497





1498

1499

1500
1501

1502
1503
1504
1505
1506
1507
1508

1509
1510
1511
1512
1513
1514
1515
1516
1517





1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531

1532
1533

1534
1535
1536
1537
1538
1539
1540
1541

1542
1543
1544

1545
1546
1547
1548
1549
1550
1551
1430
1431
1432
1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448

1449
1450
1451

1452
1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468




1469
1470
1471
1472
1473
1474
1475

1476
1477

1478

1479
1480
1481
1482
1483

1484
1485
1486
1487
1488
1489




1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509

1510
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520

1521
1522
1523
1524
1525
1526
1527
1528







-
+










-
+
-



-
+



-
+












-
-
-
-
+
+
+
+
+

+
-
+

-
+
-





-
+





-
-
-
-
+
+
+
+
+













-
+

-
+







-
+


-
+







static void
MultiFontTextOut(
    HDC hdc,			/* HDC to draw into. */
    WinFont *fontPtr,		/* Contains set of fonts to use when drawing
				 * following string. */
    const char *source,		/* Potentially multilingual UTF-8 string. */
    int numBytes,		/* Length of string in bytes. */
    double x, double y,		/* Coordinates at which to place origin of
    int x, int y,		/* Coordinates at which to place origin of
				 * string when drawing. */
    double angle)
{
    int ch;
    SIZE size;
    HFONT oldFont;
    FontFamily *familyPtr;
    Tcl_DString runString;
    const char *p, *end, *next;
    SubFont *lastSubFontPtr, *thisSubFontPtr;
    TEXTMETRICW tm;
    TEXTMETRIC tm;
    double sinA = sin(angle * PI/180.0), cosA = cos(angle * PI/180.0);

    lastSubFontPtr = &fontPtr->subFontArray[0];
    oldFont = SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
    GetTextMetricsW(hdc, &tm);
    GetTextMetrics(hdc, &tm);

    end = source + numBytes;
    for (p = source; p < end; ) {
	next = p + Tcl_UtfToUniChar(p, &ch);
	next = p + TkUtfToUniChar(p, &ch);
	thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr);

	/*
	 * The drawing API has a limit of 32767 pixels in one go.
	 * To avoid spending time on a rare case we do not measure each char,
	 * instead we limit to drawing chunks of 200 bytes since that works
	 * well in practice.
	 */

	if ((thisSubFontPtr != lastSubFontPtr) || (p-source > 200)) {
	    if (p > source) {
		familyPtr = lastSubFontPtr->familyPtr;
		WCHAR *wstr = (WCHAR *)Tcl_UtfToExternalDString(familyPtr->encoding, source,
			p - source, &runString);
		familyPtr->textOutProc(hdc, (int)(x-(double)tm.tmOverhang/2.0), y,
			wstr, Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
 		Tcl_UtfToExternalDString(familyPtr->encoding, source,
			(int) (p - source), &runString);
		familyPtr->textOutProc(hdc, x-(tm.tmOverhang/2), y,
			(TCHAR *)Tcl_DStringValue(&runString),
			Tcl_DStringLength(&runString)>>familyPtr->isWideFont);
		familyPtr->getTextExtentPoint32Proc(hdc,
			(TCHAR *)Tcl_DStringValue(&runString),
			wstr, Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
			Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
			&size);
		x += cosA*size.cx;
		x += size.cx;
		y -= sinA*size.cx;
		Tcl_DStringFree(&runString);
	    }
	    lastSubFontPtr = thisSubFontPtr;
	    source = p;
	    SelectFont(hdc, fontPtr, lastSubFontPtr, angle);
	    GetTextMetricsW(hdc, &tm);
	    GetTextMetrics(hdc, &tm);
	}
	p = next;
    }
    if (p > source) {
	familyPtr = lastSubFontPtr->familyPtr;
	WCHAR *wstr = (WCHAR *)Tcl_UtfToExternalDString(familyPtr->encoding, source,
		p - source, &runString);
	familyPtr->textOutProc(hdc, (int)(x-(double)tm.tmOverhang/2.0), y,
		wstr, Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
 	Tcl_UtfToExternalDString(familyPtr->encoding, source,
		(int) (p - source), &runString);
	familyPtr->textOutProc(hdc, x-(tm.tmOverhang/2), y,
		(TCHAR *)Tcl_DStringValue(&runString),
		Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
	Tcl_DStringFree(&runString);
    }
    SelectObject(hdc, oldFont);
}

static inline HFONT
SelectFont(
    HDC hdc,
    WinFont *fontPtr,
    SubFont *subFontPtr,
    double angle)
{
    if (angle == 0.0) {
	return (HFONT)SelectObject(hdc, subFontPtr->hFont0);
	return SelectObject(hdc, subFontPtr->hFont0);
    } else if (angle == subFontPtr->angle) {
	return (HFONT)SelectObject(hdc, subFontPtr->hFontAngled);
	return SelectObject(hdc, subFontPtr->hFontAngled);
    } else {
	if (subFontPtr->hFontAngled) {
	    DeleteObject(subFontPtr->hFontAngled);
	}
	subFontPtr->hFontAngled = GetScreenFont(&fontPtr->font.fa,
		subFontPtr->familyPtr->faceName, fontPtr->pixelSize, angle);
	if (subFontPtr->hFontAngled == NULL) {
	    return (HFONT)SelectObject(hdc, subFontPtr->hFont0);
	    return SelectObject(hdc, subFontPtr->hFont0);
	}
	subFontPtr->angle = angle;
	return (HFONT)SelectObject(hdc, subFontPtr->hFontAngled);
	return SelectObject(hdc, subFontPtr->hFontAngled);
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * InitFont --
1570
1571
1572
1573
1574
1575
1576
1577

1578
1579
1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591

1592
1593
1594
1595
1596

1597
1598

1599















1600
1601


1602
1603
1604
1605
1606
1607
1608
1609
1547
1548
1549
1550
1551
1552
1553

1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567

1568
1569
1570
1571
1572

1573
1574

1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591


1592
1593

1594
1595
1596
1597
1598
1599
1600







-
+







-
+





-
+




-
+

-
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-







static void
InitFont(
    Tk_Window tkwin,		/* Main window of interp in which font will be
				 * used, for getting HDC. */
    HFONT hFont,		/* Windows token for font. */
    int overstrike,		/* The overstrike attribute of logfont used to
				 * allocate this font. For some reason, the
				 * TEXTMETRICWs may contain incorrect info in
				 * TEXTMETRICs may contain incorrect info in
				 * the tmStruckOut field. */
    WinFont *fontPtr)		/* Filled with information constructed from
				 * the above arguments. */
{
    HDC hdc;
    HWND hwnd;
    HFONT oldFont;
    TEXTMETRICW tm;
    TEXTMETRIC tm;
    Window window;
    TkFontMetrics *fmPtr;
    Tcl_Encoding encoding;
    Tcl_DString faceString;
    TkFontAttributes *faPtr;
    WCHAR buf[LF_FACESIZE];
    TCHAR buf[LF_FACESIZE];

    window = Tk_WindowId(tkwin);
    hwnd = (window == None) ? NULL : TkWinGetHWND(window);
    hdc = GetDC(hwnd);
    oldFont = (HFONT)SelectObject(hdc, hFont);
    oldFont = SelectObject(hdc, hFont);

    GetTextMetricsW(hdc, &tm);
    GetTextMetrics(hdc, &tm);

    /*
     * On any version NT, there may fonts with international names. Use the
     * NT-only Unicode version of GetTextFace to get the font's name. If we
     * used the ANSI version on a non-internationalized version of NT, we
     * would get a font name with '?' replacing all the international
     * characters.
     *
     * On a non-internationalized verson of 95, fonts with international names
     * are not allowed, so the ANSI version of GetTextFace will work. On an
     * internationalized version of 95, there may be fonts with international
     * names; the ANSI version will work, fetching the name in the
     * international system code page. Can't use the Unicode version of
     * GetTextFace because it only exists under NT.
     */

    GetTextFaceW(hdc, LF_FACESIZE, buf);
    Tcl_DStringInit(&faceString);
    GetTextFace(hdc, LF_FACESIZE, buf);
    Tcl_ExternalToUtfDString(systemEncoding, (char *) buf, -1, &faceString);
    Tcl_WCharToUtfDString(buf, wcslen(buf), &faceString);

    fontPtr->font.fid	= (Font) fontPtr;
    fontPtr->hwnd	= hwnd;
    fontPtr->pixelSize	= tm.tmHeight - tm.tmInternalLeading;

    faPtr		= &fontPtr->font.fa;
    faPtr->family	= Tk_GetUid(Tcl_DStringValue(&faceString));
1624
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634
1635
1636
1637
1638
1615
1616
1617
1618
1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
1629







-
+








    fontPtr->numSubFonts 	= 1;
    fontPtr->subFontArray	= fontPtr->staticSubFonts;
    InitSubFont(hdc, hFont, 1, &fontPtr->subFontArray[0]);

    encoding = fontPtr->subFontArray[0].familyPtr->encoding;
    if (encoding == TkWinGetUnicodeEncoding()) {
	GetCharWidthW(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
	GetCharWidth(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
    } else {
	GetCharWidthA(hdc, 0, BASE_CHARS - 1, fontPtr->widths);
    }
    Tcl_DStringFree(&faceString);

    SelectObject(hdc, oldFont);
    ReleaseDC(hwnd, hdc);
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
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







-
+






-
-
+
+


-
-
-
+
+
+
-


-
+









-
+







 */

static FontFamily *
AllocFontFamily(
    HDC hdc,			/* HDC in which font can be selected. */
    HFONT hFont,		/* Screen font whose FontFamily is to be
				 * returned. */
    TCL_UNUSED(int))			/* Non-zero if this font family is to be used
    int base)			/* Non-zero if this font family is to be used
				 * in the base font of a font object. */
{
    Tk_Uid faceName;
    FontFamily *familyPtr;
    Tcl_DString faceString;
    Tcl_Encoding encoding;
    WCHAR buf[LF_FACESIZE];
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    TCHAR buf[LF_FACESIZE];
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    hFont = (HFONT)SelectObject(hdc, hFont);
    GetTextFaceW(hdc, LF_FACESIZE, buf);
    Tcl_DStringInit(&faceString);
    hFont = SelectObject(hdc, hFont);
    GetTextFace(hdc, LF_FACESIZE, buf);
    Tcl_ExternalToUtfDString(systemEncoding, (char *) buf, -1, &faceString);
    Tcl_WCharToUtfDString(buf, wcslen(buf), &faceString);
    faceName = Tk_GetUid(Tcl_DStringValue(&faceString));
    Tcl_DStringFree(&faceString);
    hFont = (HFONT)SelectObject(hdc, hFont);
    hFont = SelectObject(hdc, hFont);

    familyPtr = tsdPtr->fontFamilyList;
    for ( ; familyPtr != NULL; familyPtr = familyPtr->nextPtr) {
	if (familyPtr->faceName == faceName) {
	    familyPtr->refCount++;
	    return familyPtr;
	}
    }

    familyPtr = (FontFamily *)ckalloc(sizeof(FontFamily));
    familyPtr = ckalloc(sizeof(FontFamily));
    memset(familyPtr, 0, sizeof(FontFamily));
    familyPtr->nextPtr = tsdPtr->fontFamilyList;
    tsdPtr->fontFamilyList = familyPtr;

    /*
     * Set key for this FontFamily.
     */
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
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







-
+



















-
+

-
+

-
+



-
+

-
+








    familyPtr->refCount = 2;

    familyPtr->segCount = LoadFontRanges(hdc, hFont, &familyPtr->startCount,
	    &familyPtr->endCount, &familyPtr->isSymbolFont);

    encoding = NULL;
    if (familyPtr->isSymbolFont) {
    if (familyPtr->isSymbolFont != 0) {
	/*
	 * Symbol fonts are handled specially. For instance, Unicode 0393
	 * (GREEK CAPITAL GAMMA) must be mapped to Symbol character 0047
	 * (GREEK CAPITAL GAMMA), because the Symbol font doesn't have a GREEK
	 * CAPITAL GAMMA at location 0393. If Tk interpreted the Symbol font
	 * using the Unicode encoding, it would decide that the Symbol font
	 * has no GREEK CAPITAL GAMMA, because the Symbol encoding (of course)
	 * reports that character 0393 doesn't exist.
	 *
	 * With non-symbol Windows fonts, such as Times New Roman, if the font
	 * has a GREEK CAPITAL GAMMA, it will be found in the correct Unicode
	 * location (0393); the GREEK CAPITAL GAMMA will not be off hiding at
	 * some other location.
	 */

	encoding = Tcl_GetEncoding(NULL, faceName);
    }

    if (encoding == NULL) {
	encoding = TkWinGetUnicodeEncoding();
	encoding = Tcl_GetEncoding(NULL, "unicode");
	familyPtr->textOutProc =
	    (BOOL (WINAPI *)(HDC, int, int, WCHAR *, int)) TextOutW;
	    (BOOL (WINAPI *)(HDC, int, int, TCHAR *, int)) TextOutW;
	familyPtr->getTextExtentPoint32Proc =
	    (BOOL (WINAPI *)(HDC, WCHAR *, int, LPSIZE)) GetTextExtentPoint32W;
	    (BOOL (WINAPI *)(HDC, TCHAR *, int, LPSIZE)) GetTextExtentPoint32W;
	familyPtr->isWideFont = 1;
    } else {
	familyPtr->textOutProc =
	    (BOOL (WINAPI *)(HDC, int, int, WCHAR *, int)) TextOutA;
	    (BOOL (WINAPI *)(HDC, int, int, TCHAR *, int)) TextOutA;
	familyPtr->getTextExtentPoint32Proc =
	    (BOOL (WINAPI *)(HDC, WCHAR *, int, LPSIZE)) GetTextExtentPoint32A;
	    (BOOL (WINAPI *)(HDC, TCHAR *, int, LPSIZE)) GetTextExtentPoint32A;
	familyPtr->isWideFont = 0;
    }

    familyPtr->encoding = encoding;

    return familyPtr;
}
1872
1873
1874
1875
1876
1877
1878
1879

1880
1881
1882
1883
1884
1885
1886
1862
1863
1864
1865
1866
1867
1868

1869
1870
1871
1872
1873
1874
1875
1876







-
+








static void
FreeFontFamily(
    FontFamily *familyPtr)	/* The FontFamily to delete. */
{
    int i;
    FontFamily **familyPtrPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (familyPtr == NULL) {
	return;
    }
    if (familyPtr->refCount-- > 1) {
    	return;
1949
1950
1951
1952
1953
1954
1955
1956

1957
1958
1959
1960
1961
1962
1963
1939
1940
1941
1942
1943
1944
1945

1946
1947
1948
1949
1950
1951
1952
1953







-
+







    const char *const *aliases;
    const char *const *anyFallbacks;
    const char *const *const *fontFallbacks;
    const char *fallbackName;
    SubFont *subFontPtr;
    Tcl_DString ds;

    if ((ch < BASE_CHARS) || (ch >= FONTMAP_NUMCHARS)) {
    if (ch < BASE_CHARS) {
	return &fontPtr->subFontArray[0];
    }

    for (i = 0; i < fontPtr->numSubFonts; i++) {
	if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
	    return &fontPtr->subFontArray[i];
	}
2034
2035
2036
2037
2038
2039
2040
2041

2042
2043
2044
2045
2046
2047
2048
2024
2025
2026
2027
2028
2029
2030

2031
2032
2033
2034
2035
2036
2037
2038







-
+








    canUse.hdc = hdc;
    canUse.fontPtr = fontPtr;
    canUse.nameTriedPtr = &ds;
    canUse.ch = ch;
    canUse.subFontPtr = NULL;
    canUse.subFontPtrPtr = subFontPtrPtr;
    EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontCanUseProc,
    EnumFontFamilies(hdc, NULL, (FONTENUMPROC) WinFontCanUseProc,
	    (LPARAM) &canUse);
    subFontPtr = canUse.subFontPtr;

  end:
    Tcl_DStringFree(&ds);

    if (subFontPtr == NULL) {
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
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







-
-
-
+
+
+


















-
+
-







    }
    ReleaseDC(fontPtr->hwnd, hdc);
    return subFontPtr;
}

static int CALLBACK
WinFontCanUseProc(
    ENUMLOGFONTW *lfPtr,		/* Logical-font data. */
    TCL_UNUSED(NEWTEXTMETRIC *),	/* Physical-font data (not used). */
    TCL_UNUSED(int),		/* Type of font (not used). */
    ENUMLOGFONT *lfPtr,		/* Logical-font data. */
    NEWTEXTMETRIC *tmPtr,	/* Physical-font data (not used). */
    int fontType,		/* Type of font (not used). */
    LPARAM lParam)		/* Result object to hold result. */
{
    int ch;
    HDC hdc;
    WinFont *fontPtr;
    CanUse *canUsePtr;
    char *fallbackName;
    SubFont *subFontPtr;
    Tcl_DString faceString;
    Tcl_DString *nameTriedPtr;

    canUsePtr	    = (CanUse *) lParam;
    ch		    = canUsePtr->ch;
    hdc		    = canUsePtr->hdc;
    fontPtr	    = canUsePtr->fontPtr;
    nameTriedPtr    = canUsePtr->nameTriedPtr;

    fallbackName = (char *) lfPtr->elfLogFont.lfFaceName;
    Tcl_DStringInit(&faceString);
    Tcl_ExternalToUtfDString(systemEncoding, fallbackName, -1, &faceString);
    Tcl_WCharToUtfDString((WCHAR *)fallbackName, wcslen((WCHAR *)fallbackName), &faceString);
    fallbackName = Tcl_DStringValue(&faceString);

    if (SeenName(fallbackName, nameTriedPtr) == 0) {
	subFontPtr = CanUseFallback(hdc, fontPtr, fallbackName, ch,
		canUsePtr->subFontPtrPtr);
	if (subFontPtr != NULL) {
	    canUsePtr->subFontPtr = subFontPtr;
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2111
2112
2113
2114
2115
2116
2117




2118
2119
2120
2121
2122
2123
2124







-
-
-
-







FontMapLookup(
    SubFont *subFontPtr,	/* Contains font mapping cache to be queried
				 * and possibly updated. */
    int ch)			/* Character to be tested. */
{
    int row, bitOffset;

    if (ch < 0 || ch >= FONTMAP_NUMCHARS) {
	return 0;
    }

    row = ch >> FONTMAP_SHIFT;
    if (subFontPtr->fontMap[row] == NULL) {
	FontMapLoadPage(subFontPtr, row);
    }
    bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
    return (subFontPtr->fontMap[row][bitOffset >> 3] >> (bitOffset & 7)) & 1;
}
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
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







-
-
-
-
-
-
-
+
+
+
+
+
+
-
















-
+













-
+

-
+

-
+







FontMapInsert(
    SubFont *subFontPtr,	/* Contains font mapping cache to be
				 * updated. */
    int ch)			/* Character to be added to cache. */
{
    int row, bitOffset;

    if (ch >= 0 && ch < FONTMAP_NUMCHARS) {
	row = ch >> FONTMAP_SHIFT;
	if (subFontPtr->fontMap[row] == NULL) {
	    FontMapLoadPage(subFontPtr, row);
	}
	bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
	subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
    row = ch >> FONTMAP_SHIFT;
    if (subFontPtr->fontMap[row] == NULL) {
	FontMapLoadPage(subFontPtr, row);
    }
    bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
    subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
    }
}

/*
 *-------------------------------------------------------------------------
 *
 * FontMapLoadPage --
 *
 *	Load information about all the characters on a given page. This
 *	information consists of one bit per character that indicates whether
 *	the associated HFONT can (1) or cannot (0) display the characters on
 *	the page.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory allocated.
 *	Mempry allocated.
 *
 *-------------------------------------------------------------------------
 */

static void
FontMapLoadPage(
    SubFont *subFontPtr,	/* Contains font mapping cache to be
				 * updated. */
    int row)			/* Index of the page to be loaded into the
				 * cache. */
{
    FontFamily *familyPtr;
    Tcl_Encoding encoding;
    int i, j, bitOffset, end, segCount;
    char src[XMaxTransChars], buf[16];
    USHORT *startCount, *endCount;
    char buf[16], src[6];
    int i, j, bitOffset, end, segCount;

    subFontPtr->fontMap[row] = (char *)ckalloc(FONTMAP_BITSPERPAGE / 8);
    subFontPtr->fontMap[row] = ckalloc(FONTMAP_BITSPERPAGE / 8);
    memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8);

    familyPtr = subFontPtr->familyPtr;
    encoding = familyPtr->encoding;

    if (familyPtr->encoding == TkWinGetUnicodeEncoding()) {
	/*
2257
2258
2259
2260
2261
2262
2263
2264

2265
2266
2267
2268
2269
2270
2271
2240
2241
2242
2243
2244
2245
2246

2247
2248
2249
2250
2251
2252
2253
2254







-
+







	 * we don't know the proper Unicode -> symbol font mapping, we can
	 * install the symbol font as the base font and access its glyphs.
	 */

	end = (row + 1) << FONTMAP_SHIFT;
	for (i = row << FONTMAP_SHIFT; i < end; i++) {
	    if (Tcl_UtfToExternal(NULL, encoding, src,
		    Tcl_UniCharToUtf(i, src), TCL_ENCODING_PROFILE_STRICT, NULL,
		    Tcl_UniCharToUtf(i, src), TCL_ENCODING_STOPONERROR, NULL,
		    buf, sizeof(buf), NULL, NULL, NULL) != TCL_OK) {
		continue;
	    }
	    bitOffset = i & (FONTMAP_BITSPERPAGE - 1);
	    subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
	}
    }
2439
2440
2441
2442
2443
2444
2445
2446

2447
2448
2449
2450
2451
2452
2453
2422
2423
2424
2425
2426
2427
2428

2429
2430
2431
2432
2433
2434
2435
2436







-
+







	ReleaseSubFont(&subFont);
	return NULL;
    }

    if (fontPtr->numSubFonts >= SUBFONT_SPACE) {
	SubFont *newPtr;

    	newPtr = (SubFont *)ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1));
    	newPtr = ckalloc(sizeof(SubFont) * (fontPtr->numSubFonts + 1));
	memcpy(newPtr, fontPtr->subFontArray,
		fontPtr->numSubFonts * sizeof(SubFont));
	if (fontPtr->subFontArray != fontPtr->staticSubFonts) {
	    ckfree(fontPtr->subFontArray);
	}

	/*
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
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







+

-
+
















-
+
+
+

-
+







    const char *faceName,	/* Overrides font family specified in font
				 * attributes. */
    int pixelSize,		/* Overrides size specified in font
				 * attributes. */
    double angle)		/* What is the desired orientation of the
				 * font. */
{
    Tcl_DString ds;
    HFONT hFont;
    LOGFONTW lf;
    LOGFONT lf;

    memset(&lf, 0, sizeof(lf));
    lf.lfHeight		= -pixelSize;
    lf.lfWidth		= 0;
    lf.lfEscapement	= ROUND16(angle * 10);
    lf.lfOrientation	= ROUND16(angle * 10);
    lf.lfWeight = (faPtr->weight == TK_FW_NORMAL) ? FW_NORMAL : FW_BOLD;
    lf.lfItalic		= faPtr->slant;
    lf.lfUnderline	= faPtr->underline;
    lf.lfStrikeOut	= faPtr->overstrike;
    lf.lfCharSet	= DEFAULT_CHARSET;
    lf.lfOutPrecision	= OUT_TT_PRECIS;
    lf.lfClipPrecision	= CLIP_DEFAULT_PRECIS;
    lf.lfQuality	= DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;

    MultiByteToWideChar(CP_UTF8, 0, faceName, -1, lf.lfFaceName, LF_FACESIZE);
    Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &ds);
    _tcsncpy(lf.lfFaceName, (TCHAR *)Tcl_DStringValue(&ds), LF_FACESIZE-1);
    Tcl_DStringFree(&ds);
    lf.lfFaceName[LF_FACESIZE-1] = 0;
    hFont = CreateFontIndirectW(&lf);
    hFont = CreateFontIndirect(&lf);
    return hFont;
}

/*
 *-------------------------------------------------------------------------
 *
 * FamilyExists, FamilyOrAliasExists, WinFontExistsProc --
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
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







-
+
-








-
-
+
+







FamilyExists(
    HDC hdc,			/* HDC in which font family will be used. */
    const char *faceName)	/* Font family to query. */
{
    int result;
    Tcl_DString faceString;

    Tcl_DStringInit(&faceString);
    Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &faceString);
    Tcl_UtfToWCharDString(faceName, TCL_INDEX_NONE, &faceString);

    /*
     * If the family exists, WinFontExistProc() will be called and
     * EnumFontFamilies() will return whatever WinFontExistProc() returns. If
     * the family doesn't exist, EnumFontFamilies() will just return a
     * non-zero value.
     */

    result = EnumFontFamiliesW(hdc, (WCHAR *)Tcl_DStringValue(&faceString),
	    (FONTENUMPROCW) WinFontExistProc, 0);
    result = EnumFontFamilies(hdc, (TCHAR*) Tcl_DStringValue(&faceString),
	    (FONTENUMPROC) WinFontExistProc, 0);
    Tcl_DStringFree(&faceString);
    return (result == 0);
}

static const char *
FamilyOrAliasExists(
    HDC hdc,
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588




2589
2590
2591
2592
2593
2594
2595
2563
2564
2565
2566
2567
2568
2569




2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580







-
-
-
-
+
+
+
+







	}
    }
    return NULL;
}

static int CALLBACK
WinFontExistProc(
    TCL_UNUSED(ENUMLOGFONTW *),		/* Logical-font data. */
    TCL_UNUSED(NEWTEXTMETRIC *),	/* Physical-font data (not used). */
    TCL_UNUSED(int),		/* Type of font (not used). */
    TCL_UNUSED(LPARAM))		/* EnumFontData to hold result. */
    ENUMLOGFONT *lfPtr,		/* Logical-font data. */
    NEWTEXTMETRIC *tmPtr,	/* Physical-font data (not used). */
    int fontType,		/* Type of font (not used). */
    LPARAM lParam)		/* EnumFontData to hold result. */
{
    return 0;
}

/*
 * The following data structures are used when querying a TrueType font file
 * to determine which characters the font supports.
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
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







-
+
-












-
+







    HFONT hFont,		/* HFONT to query. */
    USHORT **startCountPtr,	/* Filled with malloced pointer to character
				 * range information. */
    USHORT **endCountPtr,	/* Filled with malloced pointer to character
				 * range information. */
    int *symbolPtr)
 {
    int n, i, j, k, swapped, segCount;
    int n, i, swapped, offset, cbData, segCount;
    size_t cbData, offset;
    DWORD cmapKey;
    USHORT *startCount, *endCount;
    CMAPTABLE cmapTable;
    ENCODINGTABLE encTable;
    SUBTABLE subTable;
    char *s;

    segCount = 0;
    startCount = NULL;
    endCount = NULL;
    *symbolPtr = 0;

    hFont = (HFONT)SelectObject(hdc, hFont);
    hFont = SelectObject(hdc, hFont);

    i = 0;
    s = (char *) &i;
    *s = '\1';
    swapped = 0;

    if (i == 1) {
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
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







-
-
+
+






-
-
-
+
+
+















-
-
-
-
-
+
+
+
+
+













-
-
+
+







	    if (subTable.any.format == 4) {
		if (swapped) {
		    SwapShort(&subTable.segment.segCountX2);
		}
		segCount = subTable.segment.segCountX2 / 2;
		cbData = segCount * sizeof(USHORT);

		startCount = (USHORT *)ckalloc(cbData);
		endCount = (USHORT *)ckalloc(cbData);
		startCount = ckalloc(cbData);
		endCount = ckalloc(cbData);

		offset = encTable.offset + sizeof(subTable.segment);
		GetFontData(hdc, cmapKey, (DWORD) offset, endCount, cbData);
		offset += cbData + sizeof(USHORT);
		GetFontData(hdc, cmapKey, (DWORD) offset, startCount, cbData);
		if (swapped) {
		    for (j = 0; j < segCount; j++) {
			SwapShort(&endCount[j]);
			SwapShort(&startCount[j]);
		    for (i = 0; i < segCount; i++) {
			SwapShort(&endCount[i]);
			SwapShort(&startCount[i]);
		    }
		}
		if (*symbolPtr != 0) {
		    /*
		     * Empirically determined: When a symbol font is loaded,
		     * the character existence metrics obtained from the
		     * system are mildly wrong. If the real range of the
		     * symbol font is from 0020 to 00FE, then the metrics are
		     * reported as F020 to F0FE. When we load a symbol font,
		     * we must fix the character existence metrics.
		     *
		     * Symbol fonts should only use the symbol encoding for
		     * 8-bit characters [note Bug: 2406]
		     */

		    for (k = 0; k < segCount; k++) {
			if (((startCount[k] & 0xff00) == 0xf000)
				&& ((endCount[k] & 0xff00) == 0xf000)) {
			    startCount[k] &= 0xff;
			    endCount[k] &= 0xff;
		    for (i = 0; i < segCount; i++) {
			if (((startCount[i] & 0xff00) == 0xf000)
				&& ((endCount[i] & 0xff00) == 0xf000)) {
			    startCount[i] &= 0xff;
			    endCount[i] &= 0xff;
			}
		    }
		}
	    }
	}
    } else if (GetTextCharset(hdc) == ANSI_CHARSET) {
	/*
	 * Bitmap font. We should also support ranges for the other *_CHARSET
	 * values.
	 */

	segCount = 1;
	cbData = segCount * sizeof(USHORT);
	startCount = (USHORT *)ckalloc(cbData);
	endCount = (USHORT *)ckalloc(cbData);
	startCount = ckalloc(cbData);
	endCount = ckalloc(cbData);
	startCount[0] = 0x0000;
	endCount[0] = 0x00ff;
    }
    SelectObject(hdc, hFont);

    *startCountPtr = startCount;
    *endCountPtr = endCount;

Deleted win/tkWinGDI.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkWinGDI.c --
 *
 *      This module implements access to the Win32 GDI API.
 *
 * Copyright © 1991-2018 Microsoft Corp.
 * Copyright © 2009, Michael I. Schwartz.
 * Copyright © 1998-2019 Harald Oehlmann, Elmicron GmbH
 * Copyright © 2021 Kevin Walzer/WordTech Communications LLC.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */


#include <windows.h>
#include <math.h>
#include <wtypes.h>
#include <winspool.h>
#include <commdlg.h>
#include <wingdi.h>

#include <tcl.h>

#include "tkWinInt.h"

/*
 * Create a standard "DrawFunc" to make this more workable....
 */
#ifdef _MSC_VER
typedef BOOL (WINAPI *DrawFunc) (
	HDC, int, int, int, int, int, int, int, int); /* Arc, Chord, Pie. */
#else
typedef BOOL WINAPI (*DrawFunc) (
	HDC, int, int, int, int, int, int, int, int); /* Arc, Chord, Pie. */
#endif

/* Real functions. */
static Tcl_ObjCmdProc GdiArc;
static Tcl_ObjCmdProc GdiBitmap;
static Tcl_ObjCmdProc GdiCharWidths;
static Tcl_ObjCmdProc GdiImage;
static Tcl_ObjCmdProc GdiPhoto;
static Tcl_ObjCmdProc GdiLine;
static Tcl_ObjCmdProc GdiOval;
static Tcl_ObjCmdProc GdiPolygon;
static Tcl_ObjCmdProc GdiRectangle;
static Tcl_ObjCmdProc GdiText;
static Tcl_ObjCmdProc GdiMap;
static Tcl_ObjCmdProc GdiCopyBits;

/* Local copies of similar routines elsewhere in Tcl/Tk. */
static int		GdiGetColor(Tcl_Obj *nameObj, COLORREF *color);

/*
 * Helper functions.
 */
static int		GdiMakeLogFont(Tcl_Interp *interp, const char *str,
			    LOGFONTW *lf, HDC hDC);
static int		GdiMakePen(Tcl_Interp *interp, int width,
			    int dashstyle, const char *dashstyledata,
			    int capstyle, int joinstyle,
			    int stipplestyle, const char *stippledata,
			    unsigned long color, HDC hDC, HGDIOBJ *oldPen);
static int		GdiFreePen(Tcl_Interp *interp, HDC hDC, HGDIOBJ oldPen);
static int		GdiMakeBrush(unsigned long color, long hatch,
			    LOGBRUSH *lb, HDC hDC, HBRUSH *oldBrush);
static void		GdiFreeBrush(Tcl_Interp *interp, HDC hDC,
			    HGDIOBJ oldBrush);
static int		GdiGetHdcInfo(HDC hdc,
			    LPPOINT worigin, LPSIZE wextent,
			    LPPOINT vorigin, LPSIZE vextent);

/* Helper functions for printing the window client area. */
enum PrintType { PTWindow = 0, PTClient = 1, PTScreen = 2 };

static HANDLE		CopyToDIB(HWND wnd, enum PrintType type);
static HBITMAP		CopyScreenToBitmap(LPRECT lpRect);
static HANDLE		BitmapToDIB(HBITMAP hb, HPALETTE hp);
static HANDLE		CopyScreenToDIB(LPRECT lpRect);
static int		DIBNumColors(LPBITMAPINFOHEADER lpDIB);
static int		PalEntriesOnDevice(HDC hDC);
static HPALETTE		GetSystemPalette(void);
static void		GetDisplaySize(LONG *width, LONG *height);
static int		GdiWordToWeight(const char *str);
static int		GdiParseFontWords(Tcl_Interp *interp, LOGFONTW *lf,
			    const char *str[], int numargs);
static Tcl_ObjCmdProc PrintSelectPrinter;
static Tcl_ObjCmdProc PrintOpenPrinter;
static Tcl_ObjCmdProc PrintClosePrinter;
static Tcl_ObjCmdProc PrintOpenDoc;
static Tcl_ObjCmdProc PrintCloseDoc;
static Tcl_ObjCmdProc PrintOpenPage;
static Tcl_ObjCmdProc PrintClosePage;

/*
 * Global state.
 */

static PRINTDLGW pd;
static DOCINFOW di;
static WCHAR *localPrinterName = NULL;
static int copies, paper_width, paper_height, dpi_x, dpi_y;
static LPDEVNAMES devnames;
static HDC printDC;

/*
 * To make the "subcommands" follow a standard convention, add them to this
 * array. The first element is the subcommand name, and the second a standard
 * Tcl command handler.
 */

static const struct gdi_command {
    const char *command_string;
    Tcl_ObjCmdProc *command;
} gdi_commands[] = {
    { "arc",        GdiArc },
    { "bitmap",     GdiBitmap },
    { "characters", GdiCharWidths },
    { "image",      GdiImage },
    { "line",       GdiLine },
    { "map",        GdiMap },
    { "oval",       GdiOval },
    { "photo",      GdiPhoto },
    { "polygon",    GdiPolygon },
    { "rectangle",  GdiRectangle },
    { "text",       GdiText },
    { "copybits",   GdiCopyBits },
};

/*
 *----------------------------------------------------------------------
 *
 * GdiArc --
 *
 * 	Map canvas arcs to GDI context.
 *
 * Results:
 *	Renders arcs.
 *
 *----------------------------------------------------------------------
 */

static int GdiArc(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi arc hdc x1 y1 x2 y2 "
	"-extent angle -start angle -style arcstyle "
	"-fill color -outline color "
	"-width dimension -dash dashrule "
	"-outlinestipple ignored -stipple ignored\n" ;
    int x1, y1, x2, y2;
    int xr0, yr0, xr1, yr1;
    HDC hDC;
    double extent = 0.0, start = 0.0;
    DrawFunc drawfunc;
    int width = 0;
    HPEN hPen;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;
    int dodash = 0;
    const char *dashdata = 0;

    drawfunc = Pie;

    /* Verrrrrry simple for now.... */
    if (argc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }

    argc -= 6;
    objv += 6;
    while (argc >= 2) {
	if (strcmp(Tcl_GetString(objv[0]), "-extent") == 0) {
	    extent = atof(Tcl_GetString(objv[1]));
	} else if (strcmp(Tcl_GetString(objv[0]), "-start") == 0) {
	    start = atof(Tcl_GetString(objv[1]));
	} else if (strcmp(Tcl_GetString(objv[0]), "-style") == 0) {
	    if (strcmp(Tcl_GetString(objv[1]), "pieslice") == 0) {
		drawfunc = Pie;
	    } else if (strcmp(Tcl_GetString(objv[1]), "arc") == 0) {
		drawfunc = Arc;
	    } else if (strcmp(Tcl_GetString(objv[1]), "chord") == 0) {
		drawfunc = Chord;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    /* Handle all args, even if we don't use them yet. */
	    if (GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outlinestipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetIntFromObj(interp, objv[1], &width)) {
		return TCL_ERROR;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
	    }
	} else {
	    /* Don't know that option! */
	    Tcl_AppendResult(interp, usage_message, (char *)NULL);
	    return TCL_ERROR;
	}
	argc -= 2;
	objv += 2;
    }
    xr0 = xr1 = (x1 + x2) / 2;
    yr0 = yr1 = (y1 + y2) / 2;

    /*
     * The angle used by the arc must be "warped" by the eccentricity of the
     * ellipse.  Thanks to Nigel Dodd <[email protected]> for bringing a
     * nice example.
     */

    xr0 += (int)(100.0 * (x2 - x1) * cos((start * 2.0 * 3.14159265) / 360.0));
    yr0 -= (int)(100.0 * (y2 - y1) * sin((start * 2.0 * 3.14159265) / 360.0));
    xr1 += (int)(100.0 * (x2 - x1) * cos(((start+extent) * 2.0 * 3.14159265) / 360.0));
    yr1 -= (int)(100.0 * (y2 - y1) * sin(((start+extent) * 2.0 * 3.14159265) / 360.0));

    /*
     * Under Win95, SetArcDirection isn't implemented--so we have to assume
     * that arcs are drawn counterclockwise (e.g., positive extent) So if it's
     * negative, switch the coordinates!
     */

    if (extent < 0) {
	int xr2 = xr0;
	int yr2 = yr0;

	xr0 = xr1;
	xr1 = xr2;
	yr0 = yr1;
	yr1 = yr2;
    }

    if (dofillcolor) {
	GdiMakeBrush(fillcolor, 0, &lbrush, hDC, &hBrush);
    } else {
	oldobj = SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));
    }

    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata,
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }

    (*drawfunc)(hDC, x1, y1, x2, y2, xr0, yr0, xr1, yr1);

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
	SelectObject(hDC, oldobj);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiBitmap --
 *
 * 	Unimplemented for now. Should use the same techniques as
 * 	CanvasPsBitmap (tkCanvPs.c).
 *
 * Results:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int GdiBitmap(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    Tcl_Obj *const *objv)
{
    /*
     * Skip this for now. Should be based on common code with the copybits
     * command.
     */

    Tcl_WrongNumArgs(interp, 1, objv, "hdc x y "
	    "-anchor [center|n|e|s|w] -background color "
	    "-bitmap bitmap -foreground color\n"
	    "Not implemented yet. Sorry!");
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiImage --
 *
 *	Unimplemented for now. Unimplemented for now. Should switch on image
 *	type and call either GdiPhoto or GdiBitmap. This code is similar to
 *	that in tkWinImage.c.
 *
 * Results:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int GdiImage(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    Tcl_Obj *const *objv)
{
    /* Skip this for now..... */
    /* Should be based on common code with the copybits command. */

    Tcl_WrongNumArgs(interp, 1, objv, "hdc x y -anchor [center|n|e|s|w] -image name\n"
	    "Not implemented yet. Sorry!");
    /* Normally, usage results in TCL_ERROR--but wait til' it's implemented. */
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiPhoto --
 *
 *	Contributed by Lukas Rosenthaler <[email protected]>
 *
 *	Note: The canvas doesn't directly support photos (only as images), so
 *	this is the first ::tk::print::_gdi command without an equivalent
 *	canvas command.  This code may be modified to support photo images on
 *	the canvas.
 *
 * Results:
 *	Renders a photo.
 *
 *----------------------------------------------------------------------
 */

static int GdiPhoto(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi photo hdc [-destination x y [w [h]]] -photo name\n";
    HDC dst;
    int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0;
    int nx, ny, sll;
    const char *photoname = 0;	/* For some reason Tk_FindPhoto takes a char *. */
    Tk_PhotoHandle photo_handle;
    Tk_PhotoImageBlock img_block;
    BITMAPINFO bitmapinfo;	/* Since we don't need the bmiColors table,
				 * there is no need for dynamic allocation. */
    int oldmode;		/* For saving the old stretch mode. */
    POINT pt;			/* For saving the brush org. */
    char *pbuf = NULL;
    int i, j, k;
    int retval = TCL_OK;

    /*
     * Parse the arguments.
     */

    /* HDC is required. */
    if (argc < 2) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    dst = printDC;

    /*
     * Next, check to see if 'dst' can support BitBlt.
     * If not, raise an error.
     */

    if ((GetDeviceCaps(dst, RASTERCAPS) & RC_STRETCHDIB) == 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"::tk::print::_gdi photo not supported on device context (0x%s)",
		Tcl_GetString(objv[1])));
	return TCL_ERROR;
    }

    /* Parse the command line arguments. */
    for (j = 2; j < argc; j++) {
	if (strcmp(Tcl_GetString(objv[j]), "-destination") == 0) {
	    double x, y, w, h;
	    int count = 0;
	    char dummy;

	    if (j < argc) {
		count = sscanf(Tcl_GetString(objv[++j]), "%lf%lf%lf%lf%c",
			&x, &y, &w, &h, &dummy);
	    }

	    if (count < 2 || count > 4) {
		/* Destination must provide at least 2 arguments. */
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"-destination requires a list of 2 to 4 numbers\n%s",
			usage_message));
		return TCL_ERROR;
	    }

	    dst_x = (int) x;
	    dst_y = (int) y;
	    if (count == 3) {
		dst_w = (int) w;
		dst_h = -1;
	    } else if (count == 4) {
		dst_w = (int) w;
		dst_h = (int) h;
	    }
	} else if (strcmp(Tcl_GetString(objv[j]), "-photo") == 0) {
	    photoname = Tcl_GetString(objv[++j]);
	}
    }

    if (photoname == 0) {	/* No photo provided. */
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"No photo name provided to ::tk::print::_gdi photo\n%s",
		usage_message));
	return TCL_ERROR;
    }

    photo_handle = Tk_FindPhoto(interp, photoname);
    if (photo_handle == 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"::tk::print::_gdi photo: Photo name %s can't be located\n%s",
		photoname, usage_message));
	return TCL_ERROR;
    }
    Tk_PhotoGetImage(photo_handle, &img_block);

    nx  = img_block.width;
    ny  = img_block.height;
    sll = ((3*nx + 3) / 4)*4; /* Must be multiple of 4. */

    /*
     * Buffer is potentially large enough that failure to allocate might be
     * recoverable.
     */

    pbuf = (char *)attemptckalloc(sll * ny * sizeof(char));
    if (pbuf == 0) { /* Memory allocation failure. */
	Tcl_AppendResult(interp,
		"::tk::print::_gdi photo failed--out of memory", (char *)NULL);
	return TCL_ERROR;
    }

    /* After this, all returns must go through retval. */

    /* BITMAP expects BGR; photo provides RGB. */
    for (k = 0; k < ny; k++) {
	for (i = 0; i < nx; i++) {
	    pbuf[k*sll + 3*i] = img_block.pixelPtr[
		    k*img_block.pitch + i*img_block.pixelSize + img_block.offset[2]];
	    pbuf[k*sll + 3*i + 1] = img_block.pixelPtr[
		    k*img_block.pitch + i*img_block.pixelSize + img_block.offset[1]];
	    pbuf[k*sll + 3*i + 2] = img_block.pixelPtr[
		    k*img_block.pitch + i*img_block.pixelSize + img_block.offset[0]];
	}
    }

    memset(&bitmapinfo, 0L, sizeof(BITMAPINFO));

    bitmapinfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
    bitmapinfo.bmiHeader.biWidth         = nx;
    bitmapinfo.bmiHeader.biHeight        = -ny;
    bitmapinfo.bmiHeader.biPlanes        = 1;
    bitmapinfo.bmiHeader.biBitCount      = 24;
    bitmapinfo.bmiHeader.biCompression   = BI_RGB;
    bitmapinfo.bmiHeader.biSizeImage     = 0; /* sll*ny;. */
    bitmapinfo.bmiHeader.biXPelsPerMeter = 0;
    bitmapinfo.bmiHeader.biYPelsPerMeter = 0;
    bitmapinfo.bmiHeader.biClrUsed       = 0;
    bitmapinfo.bmiHeader.biClrImportant  = 0;

    oldmode = SetStretchBltMode(dst, HALFTONE);
    /*
     * According to the Win32 Programmer's Manual, we have to set the brush
     * org, now.
     */
    SetBrushOrgEx(dst, 0, 0, &pt);

    if (dst_w <= 0) {
	dst_w = nx;
	dst_h = ny;
    } else if (dst_h <= 0) {
	dst_h = ny*dst_w / nx;
    }

    if (StretchDIBits(dst, dst_x, dst_y, dst_w, dst_h, 0, 0, nx, ny,
	    pbuf, &bitmapinfo, DIB_RGB_COLORS, SRCCOPY) == (int)GDI_ERROR) {
	int errcode = GetLastError();

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"::tk::print::_gdi photo internal failure: "
		"StretchDIBits error code %d", errcode));
	retval = TCL_ERROR;
    }

    /* Clean up the hDC. */
    if (oldmode != 0) {
	SetStretchBltMode(dst, oldmode);
	SetBrushOrgEx(dst, pt.x, pt.y, &pt);
    }

    ckfree(pbuf);

    if (retval == TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"%d %d %d %d", dst_x, dst_y, dst_w, dst_h));
    }

    return retval;
}

/*
 *----------------------------------------------------------------------
 *
 * Bezierize --
 *
 *	Interface to Tk's line smoother, used for lines and pollies.
 *	Provided by Jasper Taylor <[email protected]>.
 *
 * Results:
 *	Smooths lines.
 *
 *----------------------------------------------------------------------
 */

static int Bezierize(
    POINT* polypoints,
    int npoly,
    int nStep,
    POINT* bpointptr)
{
    /* First, translate my points into a list of doubles. */
    double *inPointList, *outPointList;
    int n;
    int nbpoints = 0;
    POINT* bpoints;

    inPointList = (double *)attemptckalloc(2 * sizeof(double) * npoly);
    if (inPointList == 0) {
	/* TODO: unreachable */
        return nbpoints; /* 0. */
    }

    for (n=0; n<npoly; n++) {
        inPointList[2*n] = polypoints[n].x;
        inPointList[2*n + 1] = polypoints[n].y;
    }

    nbpoints = 1 + npoly * nStep; /* this is the upper limit. */
    outPointList = (double *)attemptckalloc(2 * sizeof(double) * nbpoints);
    if (outPointList == 0) {
	/* TODO: unreachable */
        ckfree(inPointList);
        return 0;
    }

    nbpoints = TkMakeBezierCurve(NULL, inPointList, npoly, nStep,
	    NULL, outPointList);

    ckfree(inPointList);
    bpoints = (POINT *)attemptckalloc(sizeof(POINT)*nbpoints);
    if (bpoints == 0) {
	/* TODO: unreachable */
        ckfree(outPointList);
        return 0;
    }

    for (n=0; n<nbpoints; n++) {
        bpoints[n].x = (long)outPointList[2*n];
        bpoints[n].y = (long)outPointList[2*n + 1];
    }
    ckfree(outPointList);
    *bpointptr = *bpoints;
    return nbpoints;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiLine --
 *
 *	Maps lines to GDI context.
 *
 * Results:
 *	Renders lines.
 *
 *----------------------------------------------------------------------
 */

static int GdiLine(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi line hdc x1 y1 ... xn yn "
	"-arrow [first|last|both|none] -arrowshape {d1 d2 d3} "
	"-dash dashlist "
	"-capstyle [butt|projecting|round] -fill color "
	"-joinstyle [bevel|miter|round] -smooth [true|false|bezier] "
	"-splinesteps number -stipple bitmap -width linewid";
    char *strend;
    POINT *polypoints;
    int npoly;
    int x, y;
    HDC hDC;
    HPEN hPen;

    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;

    int width          = 0;
    COLORREF linecolor = 0;
    int dolinecolor    = 0;
    int dosmooth       = 0;
    int doarrow        = 0; /* 0=none; 1=end; 2=start; 3=both. */
    int arrowshape[3];

    int nStep = 12;

    int dodash = 0;
    const char *dashdata = 0;

    arrowshape[0] = 8;
    arrowshape[1] = 10;
    arrowshape[2] = 3;

    /* Verrrrrry simple for now.... */
    if (argc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
	|| 	(Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
	|| 	(Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
	|| 	(Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)
    ) {
	return TCL_ERROR;
    }
    argc -= 6;
    objv += 6;
    npoly = 2;

    while (argc >= 2) {
	/* Check for a number. */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
	if (strend > Tcl_GetString(objv[0])) {
	    /* One number.... */
	    y = strtoul(Tcl_GetString(objv[1]), &strend, 0);
	    if (strend > Tcl_GetString(objv[1])) {
		/* TWO numbers!. */
		polypoints[npoly].x = x;
		polypoints[npoly].y = y;
		npoly++;
		argc -= 2;
		objv += 2;
	    } else {
		/* Only one number... Assume a usage error. */
		ckfree(polypoints);
		Tcl_AppendResult(interp, usage_message, (char *)NULL);
		return TCL_ERROR;
	    }
	} else {
	    if (strcmp(Tcl_GetString(*objv), "-arrow") == 0) {
		if (strcmp(Tcl_GetString(objv[1]), "none") == 0) {
		    doarrow = 0;
		} else if (strcmp(Tcl_GetString(objv[1]), "both") == 0) {
		    doarrow = 3;
		} else if (strcmp(Tcl_GetString(objv[1]), "first") == 0) {
		    doarrow = 2;
		} else if (strcmp(Tcl_GetString(objv[1]), "last") == 0) {
		    doarrow = 1;
		}
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-arrowshape") == 0) {
		/* List of 3 numbers--set arrowshape array. */
		int a1, a2, a3;
		char dummy;

		if (sscanf(Tcl_GetString(objv[1]), "%d%d%d%c", &a1, &a2, &a3, &dummy) == 3
			&& a1 > 0 && a2 > 0 && a3 > 0) {
		    arrowshape[0] = a1;
		    arrowshape[1] = a2;
		    arrowshape[2] = a3;
		}
		/* Else the argument was bad. */

		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-capstyle") == 0) {
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-fill") == 0) {
		if (GdiGetColor(objv[1], &linecolor)) {
		    dolinecolor = 1;
		}
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-joinstyle") == 0) {
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-smooth") == 0) {
		/* Argument is true/false or 1/0 or bezier. */
		if (Tcl_GetString(objv[1])) {
		    switch (Tcl_GetString(objv[1])[0]) {
		    case 't': case 'T':
		    case '1':
		    case 'b': case 'B': /* bezier. */
			dosmooth = 1;
			break;
		    default:
			dosmooth = 0;
			break;
		    }
		    objv += 2;
		    argc -= 2;
		}
	    } else if (strcmp(Tcl_GetString(*objv), "-splinesteps") == 0) {
		if (Tcl_GetIntFromObj(interp, objv[1], &nStep) != TCL_OK) {
		    return TCL_ERROR;
		}
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-dash") == 0) {
		if (Tcl_GetString(objv[1])) {
		    dodash = 1;
		    dashdata = Tcl_GetString(objv[1]);
		}
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-dashoffset") == 0) {
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-stipple") == 0) {
		objv += 2;
		argc -= 2;
	    } else if (strcmp(Tcl_GetString(*objv), "-width") == 0) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
		objv += 2;
		argc -= 2;
	    } else { /* It's an unknown argument!. */
		argc--;
		objv++;
	    }
	    /* Check for arguments
	     * Most of the arguments affect the "Pen"
	     */
	}
    }

    if (width || dolinecolor || dodash) {
	GdiMakePen(interp, width, dodash, dashdata,
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    if (doarrow != 0) {
	GdiMakeBrush(linecolor, 0, &lbrush, hDC, &hBrush);
    }

    if (dosmooth) { /* Use PolyBezier. */
	int nbpoints;
	POINT *bpoints = 0;

	nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
	if (nbpoints > 0) {
	    Polyline(hDC, bpoints, nbpoints);
	} else {
	    Polyline(hDC, polypoints, npoly); /* Out of memory? Just draw a regular line. */
	}
	if (bpoints != 0) {
	    ckfree(bpoints);
	}
    } else {
	Polyline(hDC, polypoints, npoly);
    }

    if (dodash && doarrow) {  /* Don't use dashed or thick pen for the arrows! */
	GdiFreePen(interp, hDC, hPen);
	GdiMakePen(interp, width, 0, 0, 0, 0, 0, 0,
		linecolor, hDC, (HGDIOBJ *)&hPen);
    }

    /* Now the arrowheads, if any. */
    if (doarrow & 1) {
	/* Arrowhead at end = polypoints[npoly-1].x, polypoints[npoly-1].y. */
	POINT ahead[6];
	double dx, dy, length;
	double sinTheta, cosTheta;
	double vertX, vertY, temp;
	double fracHeight;

	fracHeight = 2.0 / arrowshape[2];

	ahead[0].x = ahead[5].x = polypoints[npoly-1].x;
	ahead[0].y = ahead[5].y = polypoints[npoly-1].y;
	dx = ahead[0].x - polypoints[npoly-2].x;
	dy = ahead[0].y - polypoints[npoly-2].y;
	if ((length = hypot(dx, dy)) == 0) {
	    sinTheta = cosTheta = 0.0;
	} else {
	    sinTheta = dy / length;
	    cosTheta = dx / length;
	}
	vertX = ahead[0].x - arrowshape[0]*cosTheta;
	vertY = ahead[0].y - arrowshape[0]*sinTheta;
	temp = arrowshape[2]*sinTheta;
	ahead[1].x = (long)(ahead[0].x - arrowshape[1]*cosTheta + temp);
	ahead[4].x = (long)(ahead[1].x - 2 * temp);
	temp = arrowshape[2]*cosTheta;
	ahead[1].y = (long)(ahead[0].y - arrowshape[1]*sinTheta - temp);
	ahead[4].y = (long)(ahead[1].y + 2 * temp);
	ahead[2].x = (long)(ahead[1].x*fracHeight + vertX*(1.0-fracHeight));
	ahead[2].y = (long)(ahead[1].y*fracHeight + vertY*(1.0-fracHeight));
	ahead[3].x = (long)(ahead[4].x*fracHeight + vertX*(1.0-fracHeight));
	ahead[3].y = (long)(ahead[4].y*fracHeight + vertY*(1.0-fracHeight));

	Polygon(hDC, ahead, 6);
    }

    if (doarrow & 2) {
	/* Arrowhead at end = polypoints[0].x, polypoints[0].y. */
	POINT ahead[6];
	double dx, dy, length;
	double sinTheta, cosTheta;
	double vertX, vertY, temp;
	double fracHeight;

	fracHeight = 2.0 / arrowshape[2];

	ahead[0].x = ahead[5].x = polypoints[0].x;
	ahead[0].y = ahead[5].y = polypoints[0].y;
	dx = ahead[0].x - polypoints[1].x;
	dy = ahead[0].y - polypoints[1].y;
	if ((length = hypot(dx, dy)) == 0) {
	    sinTheta = cosTheta = 0.0;
	} else {
	    sinTheta = dy / length;
	    cosTheta = dx / length;
	}
	vertX = ahead[0].x - arrowshape[0]*cosTheta;
	vertY = ahead[0].y - arrowshape[0]*sinTheta;
	temp = arrowshape[2]*sinTheta;
	ahead[1].x = (long)(ahead[0].x - arrowshape[1]*cosTheta + temp);
	ahead[4].x = (long)(ahead[1].x - 2 * temp);
	temp = arrowshape[2]*cosTheta;
	ahead[1].y = (long)(ahead[0].y - arrowshape[1]*sinTheta - temp);
	ahead[4].y = (long)(ahead[1].y + 2 * temp);
	ahead[2].x = (long)(ahead[1].x*fracHeight + vertX*(1.0-fracHeight));
	ahead[2].y = (long)(ahead[1].y*fracHeight + vertY*(1.0-fracHeight));
	ahead[3].x = (long)(ahead[4].x*fracHeight + vertX*(1.0-fracHeight));
	ahead[3].y = (long)(ahead[4].y*fracHeight + vertY*(1.0-fracHeight));

	Polygon(hDC, ahead, 6);
    }

    if (width || dolinecolor || dodash) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    }

    ckfree(polypoints);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiOval --
 *
 *	Maps ovals to GDI context.
 *
 * Results:
 *	Renders ovals.
 *
 *----------------------------------------------------------------------
 */

static int GdiOval(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi oval hdc x1 y1 x2 y2 -fill color -outline color "
	"-stipple bitmap -width linewid";
    int x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = 0;
    int dolinecolor = 0, dofillcolor = 0;
    HBRUSH hBrush = NULL;
    LOGBRUSH lbrush;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (argc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[2], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	int x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	int y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    argc -= 6;
    objv += 6;

    while (argc > 0) {
	/* Now handle any other arguments that occur. */
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not actually implemented */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
	    }
	}
	objv += 2;
	argc -= 2;
    }

    if (dofillcolor) {
	GdiMakeBrush(fillcolor, 0, &lbrush, hDC, &hBrush);
    } else {
	oldobj = SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));
    }

    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata,
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to right
     * and lower bounds to get appropriate behavior.
     */
    Ellipse(hDC, x1, y1, x2+1, y2+1);

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
	SelectObject(hDC, oldobj);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiPolygon --
 *
 *	Maps polygons to GDI context.
 *
 * Results:
 *	Renders polygons.
 *
 *----------------------------------------------------------------------
 */

static int GdiPolygon(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi polygon hdc x1 y1 ... xn yn "
	"-fill color -outline color -smooth [true|false|bezier] "
	"-splinesteps number -stipple bitmap -width linewid";

    char *strend;
    POINT *polypoints;
    int npoly;
    int dosmooth = 0;
    int nStep = 12;
    int x, y;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (argc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
    if (polypoints == 0) {
	/* TODO: unreachable */
	Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
	return TCL_ERROR;
    }
    if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)) {
	return TCL_ERROR;
    }
    argc -= 6;
    objv += 6;
    npoly = 2;

    while (argc >= 2) {
	/* Check for a number */
	x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
	if (strend > Tcl_GetString(objv[0])) {
	    /* One number.... */
	    y = strtoul(Tcl_GetString(objv[1]), &strend, 0);
	    if (strend > Tcl_GetString(objv[1])) {
		/* TWO numbers!. */
		polypoints[npoly].x = x;
		polypoints[npoly].y = y;
		npoly++;
		argc -= 2;
		objv += 2;
	    } else {
		/* Only one number... Assume a usage error. */
		ckfree(polypoints);
		Tcl_AppendResult(interp, usage_message, (char *)NULL);
		return TCL_ERROR;
	    }
	} else {
	    /*
	     * Check for arguments.
	     * Most of the arguments affect the "Pen" and "Brush".
	     */
	    if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
		if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		    dofillcolor = 1;
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
		if (GdiGetColor(objv[1], &linecolor)) {
		    dolinecolor = 0;
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-smooth") == 0) {
		if (Tcl_GetString(objv[1])) {
		    switch (Tcl_GetString(objv[1])[0]) {
		    case 't': case 'T':
		    case '1':
		    case 'b': case 'B': /* bezier. */
			dosmooth = 1;
			break;
		    default:
			dosmooth = 0;
			break;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-splinesteps") == 0) {
		if (Tcl_GetString(objv[1])) {
		    if (Tcl_GetIntFromObj(interp, objv[1], &nStep) != TCL_OK) {
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
		/* Not supported */
	    } else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
		if (Tcl_GetString(objv[1])) {
		    if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
			return TCL_ERROR;
		    }
		}
	    } else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
		if (Tcl_GetString(objv[1])) {
		    dodash = 1;
		    dashdata = Tcl_GetString(objv[1]);
		}
	    }
	    argc -= 2;
	    objv += 2;
	}
    }

    if (dofillcolor) {
	GdiMakeBrush(fillcolor, 0, &lbrush, hDC, &hBrush);
    } else {
	oldobj = SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));
    }

    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata, 0, 0, 0, 0,
		linecolor, hDC, (HGDIOBJ *)&hPen);
    }

    if (dosmooth) {
	int nbpoints;
	POINT *bpoints = 0;
	nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
	if (nbpoints > 0) {
	    Polygon(hDC, bpoints, nbpoints);
	} else {
	    Polygon(hDC, polypoints, npoly);
	}
	if (bpoints != 0) {
	    ckfree(bpoints);
	}
    } else {
	Polygon(hDC, polypoints, npoly);
    }

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
	SelectObject(hDC, oldobj);
    }

    ckfree(polypoints);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiRectangle --
 *
 *	Maps rectangles to GDI context.
 *
 * Results:
 *	Renders rectangles.
 *
 *----------------------------------------------------------------------
 */

static int GdiRectangle(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi rectangle hdc x1 y1 x2 y2 "
	"-fill color -outline color "
	"-stipple bitmap -width linewid";

    int x1, y1, x2, y2;
    HDC hDC;
    HPEN hPen;
    int width = 0;
    COLORREF linecolor = 0, fillcolor = BS_NULL;
    int dolinecolor = 0, dofillcolor = 0;
    LOGBRUSH lbrush;
    HBRUSH hBrush = NULL;
    HGDIOBJ oldobj = NULL;

    int dodash = 0;
    const char *dashdata = 0;

    /* Verrrrrry simple for now.... */
    if (argc < 6) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
	return TCL_ERROR;
    }
    if (x1 > x2) {
	int x3 = x1;
	x1 = x2;
	x2 = x3;
    }
    if (y1 > y2) {
	int y3 = y1;
	y1 = y2;
	y2 = y3;
    }
    argc -= 6;
    objv += 6;

    /* Now handle any other arguments that occur. */
    while (argc > 1) {
	if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
		dofillcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-outline") == 0) {
	    if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &linecolor)) {
		dolinecolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    /* Not supported; ignored */
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    if (Tcl_GetString(objv[1])) {
		if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
	    if (Tcl_GetString(objv[1])) {
		dodash = 1;
		dashdata = Tcl_GetString(objv[1]);
	    }
	}

	argc -= 2;
	objv += 2;
    }

    /*
     * Note: If any fill is specified, the function must create a brush and
     * put the coordinates in a RECTANGLE structure, and call FillRect.
     * FillRect requires a BRUSH / color.
     * If not, the function Rectangle must be called.
     */
    if (dofillcolor) {
	GdiMakeBrush(fillcolor, 0, &lbrush, hDC, &hBrush);
    } else {
	oldobj = SelectObject(hDC, GetStockObject(HOLLOW_BRUSH));
    }

    if (width || dolinecolor) {
	GdiMakePen(interp, width, dodash, dashdata,
		0, 0, 0, 0, linecolor, hDC, (HGDIOBJ *)&hPen);
    }
    /*
     * Per Win32, Rectangle includes lower and right edges--per Tcl8.3.2 and
     * earlier documentation, canvas rectangle does not. Thus, add 1 to
     * right and lower bounds to get appropriate behavior.
     */
    Rectangle(hDC, x1, y1, x2+1, y2+1);

    if (width || dolinecolor) {
	GdiFreePen(interp, hDC, hPen);
    }
    if (hBrush) {
	GdiFreeBrush(interp, hDC, hBrush);
    } else {
	SelectObject(hDC, oldobj);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiCharWidths --
 *
 *	Computes /character widths. This is completely inadequate for
 *	typesetting, but should work for simple text manipulation.
 *
 * Results:
 *	Returns character width.
 *
 *----------------------------------------------------------------------
 */


static int GdiCharWidths(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi characters hdc [-font fontname] [-array ary]";
    /*
     * Returns widths of characters from font in an associative array.
     * Font is currently selected font for HDC if not specified.
     * Array name is GdiCharWidths if not specified.
     * Widths should be in the same measures as all other values (1/1000 inch).
     */

    HDC hDC;
    LOGFONTW lf;
    HFONT hfont;
    HGDIOBJ oldfont;
    int made_font = 0;
    const char *aryvarname = "GdiCharWidths";
    /* For now, assume 256 characters in the font.... */
    int widths[256];
    int retval;

    if (argc < 2) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hDC = printDC;

    argc -= 2;
    objv += 2;

    while (argc > 0) {
	if (strcmp(Tcl_GetString(objv[0]), "-font") == 0) {
	    argc--;
	    objv++;
	    if (GdiMakeLogFont(interp, Tcl_GetString(objv[0]), &lf, hDC)) {
		if ((hfont = CreateFontIndirectW(&lf)) != NULL) {
		    made_font = 1;
		    oldfont = SelectObject(hDC, hfont);
		}
	    }
	    /* Else leave the font alone!. */
	} else if (strcmp(Tcl_GetString(objv[0]), "-array") == 0) {
	    objv++;
	    argc--;
	    if (argc > 0) {
		aryvarname = Tcl_GetString(objv[0]);
	    }
	}
	objv++;
	argc--;
    }

    /* Now, get the widths using the correct function for font type. */
    if ((retval = GetCharWidth32W(hDC, 0, 255, widths)) == FALSE) {
	retval = GetCharWidthW(hDC, 0, 255, widths);
    }

    /*
     * Retval should be 1 (TRUE) if the function succeeded. If the function
     * fails, get the "extended" error code and return. Be sure to deallocate
     * the font if necessary.
     */
    if (retval == FALSE) {
	DWORD val = GetLastError();

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                "::tk::print::_gdi character failed with code %ld", val));
	if (made_font) {
	    SelectObject(hDC, oldfont);
	    DeleteObject(hfont);
	}
	return TCL_ERROR;
    }

    {
	int i;
	char ind[2];
	ind[1] = '\0';

	for (i = 0; i < 255; i++) {
	    /* TODO: use a bytearray for the index name so NUL works */
	    ind[0] = i;
	    Tcl_SetVar2Ex(interp, aryvarname, ind, Tcl_NewIntObj(widths[i]),
		    TCL_GLOBAL_ONLY);
	}
    }
    /* Now, remove the font if we created it only for this function. */
    if (made_font) {
	SelectObject(hDC, oldfont);
	DeleteObject(hfont);
    }

    /* The return value should be the array name(?). */
    Tcl_AppendResult(interp, aryvarname, (char *)NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiText --
 *
 *	Maps text to GDI context.
 *
 * Results:
 *	Renders text.
 *
 *----------------------------------------------------------------------
 */

int GdiText(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi text hdc x y -anchor [center|n|e|s|w] "
	"-fill color -font fontname "
	"-justify [left|right|center] "
	"-stipple bitmap -text string -width linelen "
	"-single -backfill";

    HDC hDC;
    int x, y;
    const char *string = 0;
    RECT sizerect;
    UINT format_flags = DT_EXPANDTABS|DT_NOPREFIX; /* Like the canvas. */
    Tk_Anchor anchor = TK_ANCHOR_N;
    LOGFONTW lf;
    HFONT hfont;
    HGDIOBJ oldfont;
    int made_font = 0;
    int retval;
    int dotextcolor = 0;
    int dobgmode = 0;
    int bgmode;
    COLORREF textcolor = 0;
    int usesingle = 0;
    WCHAR *wstring;
    Tcl_DString tds;

    if (argc < 4) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    /* Parse the command. */

    hDC = printDC;

    if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
	return TCL_ERROR;
    }
    argc -= 4;
    objv += 4;

    sizerect.left = sizerect.right = x;
    sizerect.top = sizerect.bottom = y;

    while (argc > 0) {
	if (strcmp(Tcl_GetString(objv[0]), "-anchor") == 0) {
	    argc--;
	    objv++;
	    if (argc > 0) {
		Tk_GetAnchor(interp, Tcl_GetString(objv[0]), &anchor);
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-justify") == 0) {
	    argc--;
	    objv++;
	    if (argc > 0) {
		if (strcmp(Tcl_GetString(objv[0]), "left") == 0) {
		    format_flags |= DT_LEFT;
		} else if (strcmp(Tcl_GetString(objv[0]), "center") == 0) {
		    format_flags |= DT_CENTER;
		} else if (strcmp(Tcl_GetString(objv[0]), "right") == 0) {
		    format_flags |= DT_RIGHT;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-text") == 0) {
	    argc--;
	    objv++;
	    if (argc > 0) {
		string = Tcl_GetString(objv[0]);
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-font") == 0) {
	    argc--;
	    objv++;
	    if (GdiMakeLogFont(interp, Tcl_GetString(objv[0]), &lf, hDC)) {
		if ((hfont = CreateFontIndirectW(&lf)) != NULL) {
		    made_font = 1;
		    oldfont = SelectObject(hDC, hfont);
		}
	    }
	    /* Else leave the font alone! */
	} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
	    argc--;
	    objv++;
	    /* Not implemented yet. */
	} else if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
	    argc--;
	    objv++;
	    /* Get text color. */
	    if (GdiGetColor(objv[0], &textcolor)) {
		dotextcolor = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
	    argc--;
	    objv++;
	    if (argc > 0) {
		int value;
		if (Tcl_GetIntFromObj(interp, objv[0], &value) != TCL_OK) {
		    return TCL_ERROR;
		}
		sizerect.right += value;
	    }
	    /* If a width is specified, break at words. */
	    format_flags |= DT_WORDBREAK;
	} else if (strcmp(Tcl_GetString(objv[0]), "-single") == 0) {
	    usesingle = 1;
	} else if (strcmp(Tcl_GetString(objv[0]), "-backfill") == 0) {
	    dobgmode = 1;
	}

	argc--;
	objv++;
    }

    if (string == 0) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    /* Set the format flags for -single: Overrides -width. */
    if (usesingle == 1) {
	format_flags |= DT_SINGLELINE;
	format_flags |= DT_NOCLIP;
	format_flags &= ~DT_WORDBREAK;
    }

    Tcl_DStringInit(&tds);
    /* Just for fun, let's try translating string to Unicode. */
    wstring = Tcl_UtfToWCharDString(string, TCL_INDEX_NONE, &tds);
    DrawTextW(hDC, wstring, Tcl_DStringLength(&tds)/2, &sizerect,
	    format_flags | DT_CALCRECT);

    /* Adjust the rectangle according to the anchor. */
    x = y = 0;
    switch (anchor) {
    case TK_ANCHOR_N:
	x = (sizerect.right - sizerect.left) / 2;
	break;
    case TK_ANCHOR_S:
	x = (sizerect.right - sizerect.left) / 2;
	y = (sizerect.bottom - sizerect.top);
	break;
    case TK_ANCHOR_E:
	x = (sizerect.right - sizerect.left);
	y = (sizerect.bottom - sizerect.top) / 2;
	break;
    case TK_ANCHOR_W:
	y = (sizerect.bottom - sizerect.top) / 2;
	break;
    case TK_ANCHOR_NE:
	x = (sizerect.right - sizerect.left);
	break;
    case TK_ANCHOR_NW:
	break;
    case TK_ANCHOR_SE:
	x = (sizerect.right - sizerect.left);
	y = (sizerect.bottom - sizerect.top);
	break;
    case TK_ANCHOR_SW:
	y = (sizerect.bottom - sizerect.top);
	break;
    default:
	x = (sizerect.right - sizerect.left) / 2;
	y = (sizerect.bottom - sizerect.top) / 2;
	break;
    }
    sizerect.right  -= x;
    sizerect.left   -= x;
    sizerect.top    -= y;
    sizerect.bottom -= y;

    /* Get the color right. */
    if (dotextcolor) {
	textcolor = SetTextColor(hDC, textcolor);
    }

    if (dobgmode) {
	bgmode = SetBkMode(hDC, OPAQUE);
    } else {
	bgmode = SetBkMode(hDC, TRANSPARENT);
    }

    /* Print the text. */
    retval = DrawTextW(hDC, wstring,
	    Tcl_DStringLength(&tds)/2, &sizerect, format_flags);
    Tcl_DStringFree(&tds);

    /* Get the color set back. */
    if (dotextcolor) {
	textcolor = SetTextColor(hDC, textcolor);
    }
    SetBkMode(hDC, bgmode);
    if (made_font) {
	SelectObject(hDC, oldfont);
	DeleteObject(hfont);
    }

    /* In this case, the return value is the height of the text. */
    Tcl_SetObjResult(interp, Tcl_NewIntObj(retval));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiGetHdcInfo --
 *
 *	Gets salient characteristics of the CTM.
 *
 * Results:
 *	The return value is 0 if any failure occurs--in which case none of the
 *	other values are meaningful.  Otherwise the return value is the
 *	current mapping mode.
 *
 *----------------------------------------------------------------------
 */

static int GdiGetHdcInfo(
    HDC hdc,
    LPPOINT worigin,
    LPSIZE wextent,
    LPPOINT vorigin,
    LPSIZE vextent)
{
    int mapmode;
    int retval;

    memset(worigin, 0, sizeof(POINT));
    memset(vorigin, 0, sizeof(POINT));
    memset(wextent, 0, sizeof(SIZE));
    memset(vextent, 0, sizeof(SIZE));

    if ((mapmode = GetMapMode(hdc)) == 0) {
	/* Failed! */
	retval = 0;
    } else {
	retval = mapmode;
    }

    if (GetWindowExtEx(hdc, wextent) == FALSE) {
	/* Failed! */
	retval = 0;
    }
    if (GetViewportExtEx(hdc, vextent) == FALSE) {
	/* Failed! */
	retval = 0;
    }
    if (GetWindowOrgEx(hdc, worigin) == FALSE) {
	/* Failed! */
	retval = 0;
    }
    if (GetViewportOrgEx(hdc, vorigin) == FALSE) {
	/* Failed! */
	retval = 0;
    }

    return retval;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiNameToMode --
 *
 *	Converts Windows mapping mode names.
 *
 * Results:
 *	Mapping modes are delineated.
 *
 *----------------------------------------------------------------------
 */

static int GdiNameToMode(
    const char *name)
{
    static const struct gdimodes {
	int mode;
	const char *name;
    } modes[] = {
	{ MM_ANISOTROPIC, "MM_ANISOTROPIC" },
	{ MM_HIENGLISH,   "MM_HIENGLISH" },
	{ MM_HIMETRIC,    "MM_HIMETRIC" },
	{ MM_ISOTROPIC,   "MM_ISOTROPIC" },
	{ MM_LOENGLISH,   "MM_LOENGLISH" },
	{ MM_LOMETRIC,    "MM_LOMETRIC" },
	{ MM_TEXT,        "MM_TEXT" },
	{ MM_TWIPS,       "MM_TWIPS" }
    };

    size_t i;
    for (i=0; i < sizeof(modes) / sizeof(struct gdimodes); i++) {
	if (strcmp(modes[i].name, name) == 0) {
	    return modes[i].mode;
	}
    }
    return atoi(name);
}

/*
 *----------------------------------------------------------------------
 *
 * GdiModeToName --
 *
 *	Converts the mode number to a printable form.
 *
 * Results:
 *	Mapping numbers are delineated.
 *
 *----------------------------------------------------------------------
 */

static const char *GdiModeToName(
    int mode)
{
    static const struct gdi_modes {
	int mode;
	const char *name;
    } modes[] = {
	{ MM_ANISOTROPIC, "Anisotropic" },
	{ MM_HIENGLISH,   "1/1000 inch" },
	{ MM_HIMETRIC,    "1/100 mm" },
	{ MM_ISOTROPIC,   "Isotropic" },
	{ MM_LOENGLISH,   "1/100 inch" },
	{ MM_LOMETRIC,    "1/10 mm" },
	{ MM_TEXT,        "1 to 1" },
	{ MM_TWIPS,       "1/1440 inch" }
    };

    size_t i;
    for (i=0; i < sizeof(modes) / sizeof(struct gdi_modes); i++) {
	if (modes[i].mode == mode) {
	    return modes[i].name;
	}
    }
    return "Unknown";
}

/*
 *----------------------------------------------------------------------
 *
 * GdiMap --
 *
 *	Sets mapping mode between logical and physical device space.
 *
 * Results:
 *	Bridges map modes.
 *
 *----------------------------------------------------------------------
 */

static int GdiMap(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    static const char usage_message[] =
	"::tk::print::_gdi map hdc "
	"[-logical x[y]] [-physical x[y]] "
	"[-offset {x y} ] [-default] [-mode mode]";
    HDC hdc;
    int mapmode;	/* Mapping mode. */
    SIZE wextent;	/* Device extent. */
    SIZE vextent;	/* Viewport extent. */
    POINT worigin;	/* Device origin. */
    POINT vorigin;	/* Viewport origin. */
    int argno;

    /* Keep track of what parts of the function need to be executed. */
    int need_usage   = 0;
    int use_logical  = 0;
    int use_physical = 0;
    int use_offset   = 0;
    int use_default  = 0;
    int use_mode     = 0;

    /* Required parameter: HDC for printer. */
    if (argc < 2) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    hdc = printDC;

    if ((mapmode = GdiGetHdcInfo(hdc, &worigin, &wextent, &vorigin, &vextent)) == 0) {
	/* Failed!. */
	Tcl_AppendResult(interp, "Cannot get current HDC info", (char *)NULL);
	return TCL_ERROR;
    }

    /* Parse remaining arguments. */
    for (argno = 2; argno < argc; argno++) {
	if (strcmp(Tcl_GetString(objv[argno]), "-default") == 0) {
	    vextent.cx = vextent.cy = wextent.cx = wextent.cy = 1;
	    vorigin.x = vorigin.y = worigin.x = worigin.y = 0;
	    mapmode = MM_TEXT;
	    use_default = 1;
	} else if (strcmp(Tcl_GetString(objv[argno]), "-mode") == 0) {
	    if (argno + 1 >= argc) {
		need_usage = 1;
	    } else {
		mapmode = GdiNameToMode(Tcl_GetString(objv[argno + 1]));
		use_mode = 1;
		argno++;
	    }
	} else if (strcmp(Tcl_GetString(objv[argno]), "-offset") == 0) {
	    if (argno + 1 >= argc) {
		need_usage = 1;
	    } else {
		/* It would be nice if this parsed units as well.... */
		if (sscanf(Tcl_GetString(objv[argno + 1]), "%ld%ld",
			&vorigin.x, &vorigin.y) == 2) {
		    use_offset = 1;
		} else {
		    need_usage = 1;
		}
		argno++;
	    }
	} else if (strcmp(Tcl_GetString(objv[argno]), "-logical") == 0) {
	    if (argno + 1 >= argc) {
		need_usage = 1;
	    } else {
		int count;

		argno++;
		/* In "real-life", this should parse units as well.. */
		if ((count = sscanf(Tcl_GetString(objv[argno]), "%ld%ld",
			&wextent.cx, &wextent.cy)) != 2) {
		    if (count == 1) {
			mapmode = MM_ISOTROPIC;
			use_logical = 1;
			wextent.cy = wextent.cx;  /* Make them the same. */
		    } else {
			need_usage = 1;
		    }
		} else {
		    mapmode = MM_ANISOTROPIC;
		    use_logical = 2;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[argno]), "-physical") == 0) {
	    if (argno + 1 >= argc) {
		need_usage = 1;
	    } else {
		int count;

		argno++;
		/* In "real-life", this should parse units as well.. */
		if ((count = sscanf(Tcl_GetString(objv[argno]), "%ld%ld",
			&vextent.cx, &vextent.cy)) != 2) {
		    if (count == 1) {
			mapmode = MM_ISOTROPIC;
			use_physical = 1;
			vextent.cy = vextent.cx;  /* Make them the same. */
		    } else {
			need_usage = 1;
		    }
		} else {
		    mapmode = MM_ANISOTROPIC;
		    use_physical = 2;
		}
	    }
	}
    }

    /* Check for any impossible combinations. */
    if (use_logical != use_physical) {
	need_usage = 1;
    }
    if (use_default && (use_logical || use_offset || use_mode)) {
	need_usage = 1;
    }
    if (use_mode && use_logical &&
	    (mapmode != MM_ISOTROPIC && mapmode != MM_ANISOTROPIC)) {
	need_usage = 1;
    }

    if (need_usage) {
	Tcl_AppendResult(interp, usage_message, NULL);
	return TCL_ERROR;
    }

    /* Call Windows CTM functions. */
    if (use_logical || use_default || use_mode) { /* Don't call for offset only. */
	SetMapMode(hdc, mapmode);
    }

    if (use_offset || use_default) {
	POINT oldorg;
	SetViewportOrgEx(hdc, vorigin.x, vorigin.y, &oldorg);
	SetWindowOrgEx(hdc, worigin.x, worigin.y, &oldorg);
    }

    if (use_logical) {  /* Same as use_physical. */
	SIZE oldsiz;
	SetWindowExtEx(hdc, wextent.cx, wextent.cy, &oldsiz);
	SetViewportExtEx(hdc, vextent.cx, vextent.cy, &oldsiz);
    }

    /*
     * Since we may not have set up every parameter, get them again for the
     * report.
     */
    mapmode = GdiGetHdcInfo(hdc, &worigin, &wextent, &vorigin, &vextent);

    /*
     * Output current CTM info.
     * Note: This should really be in terms that can be used in a
     * ::tk::print::_gdi map command!
     */
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "Transform: \"(%ld, %ld) -> (%ld, %ld)\" "
	    "Origin: \"(%ld, %ld)\" "
	    "MappingMode: \"%s\"",
	    vextent.cx, vextent.cy, wextent.cx, wextent.cy,
	    vorigin.x, vorigin.y,
	    GdiModeToName(mapmode)));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiCopyBits --
 *
 *	Copies window bits from source to destination.
 *
 * Results:
 *	Copies window bits.
 *
 *----------------------------------------------------------------------
 */

static int GdiCopyBits(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int argc,
    Tcl_Obj *const *objv)
{
    /* Goal: get the Tk_Window from the top-level
     * convert it to an HWND
     * get the HDC
     * Do a bitblt to the given hdc
     * Use an optional parameter to point to an arbitrary window instead of
     * the main
     * Use optional parameters to map to the width and height required for the
     * dest.
     */
    static const char usage_message[] =
	"::tk::print::_gdi copybits hdc [-window w|-screen] [-client] "
	"[-source \"a b c d\"] "
	"[-destination \"a b c d\"] [-scale number] [-calc]";

    Tk_Window mainWin;
    Tk_Window workwin;
    Window wnd;
    HDC src;
    HDC dst;
    HWND hwnd = 0;

    HANDLE hDib;    /* Handle for device-independent bitmap. */
    LPBITMAPINFOHEADER lpDIBHdr;
    LPSTR lpBits;
    enum PrintType wintype = PTWindow;

    int hgt, wid;
    char *strend;
    long errcode;
    int k;

    /* Variables to remember what we saw in the arguments. */
    int do_window = 0;
    int do_screen = 0;
    int do_scale = 0;
    int do_print = 1;

    /* Variables to remember the values in the arguments. */
    const char *window_spec;
    double scale = 1.0;
    int src_x = 0, src_y = 0, src_w = 0, src_h = 0;
    int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0;
    int is_toplevel = 0;

    /*
     * The following steps are peculiar to the top level window.
     * There is likely a clever way to do the mapping of a widget pathname to
     * the proper window, to support the idea of using a parameter for this
     * purpose.
     */
    if ((workwin = mainWin = Tk_MainWindow(interp)) == 0) {
	Tcl_AppendResult(interp, "Can't find main Tk window", (char *)NULL);
	return TCL_ERROR;
    }

    /*
     * Parse the arguments.
     */
    /* HDC is required. */
    if (argc < 2) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    dst = printDC;

    /*
     * Next, check to see if 'dst' can support BitBlt.  If not, raise an
     * error.
     */
    if ((GetDeviceCaps(dst, RASTERCAPS) & RC_BITBLT) == 0) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"Can't do bitmap operations on device context\n"));
	return TCL_ERROR;
    }

    /* Loop through the remaining arguments. */
    for (k=2; k<argc; k++) {
	if (strcmp(Tcl_GetString(objv[k]), "-window") == 0) {
	    if (Tcl_GetString(objv[k+1]) && Tcl_GetString(objv[k+1])[0] == '.') {
		do_window = 1;
		workwin = Tk_NameToWindow(interp, window_spec = Tcl_GetString(objv[++k]), mainWin);
		if (workwin == NULL) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "Can't find window %s in this application",
			    window_spec));
		    return TCL_ERROR;
		}
	    } else {
		/* Use strtoul() so octal or hex representations will be
		 * parsed. */
		hwnd = (HWND) INT2PTR(strtoul(Tcl_GetString(objv[++k]), &strend, 0));
		if (strend == 0 || strend == Tcl_GetString(objv[k])) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "Can't understand window id %s", Tcl_GetString(objv[k])));
		    return TCL_ERROR;
		}
	    }
	} else if (strcmp(Tcl_GetString(objv[k]), "-screen") == 0) {
	    do_screen = 1;
	    wintype = PTScreen;
	} else if (strcmp(Tcl_GetString(objv[k]), "-client") == 0) {
	    wintype = PTClient;
	} else if (strcmp(Tcl_GetString(objv[k]), "-source") == 0) {
	    float a, b, c, d;
	    int count = sscanf(Tcl_GetString(objv[++k]), "%f%f%f%f", &a, &b, &c, &d);

	    if (count < 2) { /* Can't make heads or tails of it.... */
		Tcl_AppendResult(interp, usage_message, (char *)NULL);
		return TCL_ERROR;
	    }
	    src_x = (int)a;
	    src_y = (int)b;
	    if (count == 4) {
		src_w = (int)c;
		src_h = (int)d;
	    }
	} else if (strcmp(Tcl_GetString(objv[k]), "-destination") == 0) {
	    float a, b, c, d;
	    int count;

	    count = sscanf(Tcl_GetString(objv[++k]), "%f%f%f%f", &a, &b, &c, &d);
	    if (count < 2) { /* Can't make heads or tails of it.... */
		Tcl_AppendResult(interp, usage_message, (char *)NULL);
		return TCL_ERROR;
	    }
	    dst_x = (int)a;
	    dst_y = (int)b;
	    if (count == 3) {
		dst_w = (int)c;
		dst_h = -1;
	    } else if (count == 4) {
		dst_w = (int)c;
		dst_h = (int)d;
	    }
	} else if (strcmp(Tcl_GetString(objv[k]), "-scale") == 0) {
	    if (Tcl_GetString(objv[++k])) {
		if (Tcl_GetDouble(interp, Tcl_GetString(objv[k]), &scale) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (scale <= 0.01 || scale >= 100.0) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			    "Unreasonable scale specification %s", Tcl_GetString(objv[k])));
		    return TCL_ERROR;
		}
		do_scale = 1;
	    }
	} else if (strcmp(Tcl_GetString(objv[k]), "-noprint") == 0
		|| strncmp(Tcl_GetString(objv[k]), "-calc", 5) == 0) {
	    /* This option suggested by Pascal Bouvier to get sizes without
	     * printing. */
	    do_print = 0;
	}
    }

    /*
     * Check to ensure no incompatible arguments were used.
     */
    if (do_window && do_screen) {
	Tcl_AppendResult(interp, usage_message, (char *)NULL);
	return TCL_ERROR;
    }

    /*
     * Get the MS Window we want to copy.  Given the HDC, we can get the
     * "Window".
     */
    if (hwnd == 0) {
	if (Tk_IsTopLevel(workwin)) {
	    is_toplevel = 1;
	}

	if ((wnd = Tk_WindowId(workwin)) == 0) {
	    Tcl_AppendResult(interp, "Can't get id for Tk window", (char *)NULL);
	    return TCL_ERROR;
	}

	/* Given the "Window" we can get a Microsoft Windows HWND. */

	if ((hwnd = Tk_GetHWND(wnd)) == 0) {
	    Tcl_AppendResult(interp, "Can't get Windows handle for Tk window",
		    (char *)NULL);
	    return TCL_ERROR;
	}

	/*
	 * If it's a toplevel, give it special treatment: Get the top-level
	 * window instead.  If the user only wanted the client, the -client
	 * flag will take care of it.  This uses "windows" tricks rather than
	 * Tk since the obvious method of getting the wrapper window didn't
	 * seem to work.
	 */
	if (is_toplevel) {
	    HWND tmpWnd = hwnd;
	    while ((tmpWnd = GetParent(tmpWnd)) != 0) {
		hwnd = tmpWnd;
	    }
	}
    }

    /* Given the HWND, we can get the window's device context. */
    if ((src = GetWindowDC(hwnd)) == 0) {
	Tcl_AppendResult(interp, "Can't get device context for Tk window", (char *)NULL);
	return TCL_ERROR;
    }

    if (do_screen) {
	LONG w, h;
	GetDisplaySize(&w, &h);
	wid = w;
	hgt = h;
    } else if (is_toplevel) {
	RECT tl;
	GetWindowRect(hwnd, &tl);
	wid = tl.right - tl.left;
	hgt = tl.bottom - tl.top;
    } else {
	if ((hgt = Tk_Height(workwin)) <= 0) {
	    Tcl_AppendResult(interp, "Can't get height of Tk window", (char *)NULL);
	    ReleaseDC(hwnd,src);
	    return TCL_ERROR;
	}

	if ((wid = Tk_Width(workwin)) <= 0) {
	    Tcl_AppendResult(interp, "Can't get width of Tk window", (char *)NULL);
	    ReleaseDC(hwnd,src);
	    return TCL_ERROR;
	}
    }

    /*
     * Ensure all the widths and heights are set up right
     * A: No dimensions are negative
     * B: No dimensions exceed the maximums
     * C: The dimensions don't lead to a 0 width or height image.
     */
    if (src_x < 0) {
	src_x = 0;
    }
    if (src_y < 0) {
	src_y = 0;
    }
    if (dst_x < 0) {
	dst_x = 0;
    }
    if (dst_y < 0) {
	dst_y = 0;
    }

    if (src_w > wid || src_w <= 0) {
	src_w = wid;
    }

    if (src_h > hgt || src_h <= 0) {
	src_h = hgt;
    }

    if (do_scale && dst_w == 0) {
	/* Calculate destination width and height based on scale. */
	dst_w = (int)(scale * src_w);
	dst_h = (int)(scale * src_h);
    }

    if (dst_h == -1) {
	dst_h = (int) (((long)src_h * dst_w) / (src_w + 1)) + 1;
    }

    if (dst_h == 0 || dst_w == 0) {
	dst_h = src_h;
	dst_w = src_w;
    }

    if (do_print) {
	/*
	 * Based on notes from Heiko Schock and Arndt Roger Schneider, create
	 * this as a DIBitmap, to allow output to a greater range of devices.
	 * This approach will also allow selection of
	 *   a) Whole screen
	 *   b) Whole window
	 *   c) Client window only
	 * for the "grab"
	 */
	hDib = CopyToDIB(hwnd, wintype);

	/* GdiFlush();. */

	if (!hDib) {
	    Tcl_AppendResult(interp, "Can't create DIB", (char *)NULL);
	    ReleaseDC(hwnd,src);
	    return TCL_ERROR;
	}

	lpDIBHdr = (LPBITMAPINFOHEADER) GlobalLock(hDib);
	if (!lpDIBHdr) {
	    Tcl_AppendResult(interp, "Can't get DIB header", (char *)NULL);
	    ReleaseDC(hwnd,src);
	    return TCL_ERROR;
	}

	lpBits = (LPSTR) lpDIBHdr + lpDIBHdr->biSize + DIBNumColors(lpDIBHdr) * sizeof(RGBQUAD);

	/* stretch the DIBbitmap directly in the target device. */

	if (StretchDIBits(dst,
		dst_x, dst_y, dst_w, dst_h,
		src_x, src_y, src_w, src_h,
		lpBits, (LPBITMAPINFO)lpDIBHdr, DIB_RGB_COLORS,
		SRCCOPY) == (int)GDI_ERROR) {
	    errcode = GetLastError();
	    GlobalUnlock(hDib);
	    GlobalFree(hDib);
	    ReleaseDC(hwnd,src);
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "StretchDIBits failed with code %ld", errcode));
	    return TCL_ERROR;
	}

	/* free allocated memory. */
	GlobalUnlock(hDib);
	GlobalFree(hDib);
    }

    ReleaseDC(hwnd,src);

    /*
     * The return value should relate to the size in the destination space.
     * At least the height should be returned (for page layout purposes).
     */
    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    "%d %d %d %d", dst_x, dst_y, dst_w, dst_h));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * DIBNumColors --
 *
 *	Computes the number of colors required for a DIB palette.
 *
 * Results:
 *	Returns number of colors.

 *
 *----------------------------------------------------------------------
 */

static int DIBNumColors(
    LPBITMAPINFOHEADER lpDIB)
{
    WORD wBitCount;	/* DIB bit count. */
    DWORD dwClrUsed;

    /*
     * If this is a Windows-style DIB, the number of colors in the color table
     * can be less than the number of bits per pixel allows for (i.e.
     * lpbi->biClrUsed can be set to some value).  If this is the case, return
     * the appropriate value..
     */

    dwClrUsed = lpDIB->biClrUsed;
    if (dwClrUsed) {
	return (WORD) dwClrUsed;
    }

    /*
     * Calculate the number of colors in the color table based on.
     * The number of bits per pixel for the DIB.
     */

    wBitCount = lpDIB->biBitCount;

    /* Return number of colors based on bits per pixel. */

    switch (wBitCount) {
    case 1:
	return 2;
    case 4:
	return 16;
    case 8:
	return 256;
    default:
	return 0;
    }
}

/*
 * Helper functions
 */

/*
 * ParseFontWords converts various keywords to modifyers of a
 * font specification.
 * For all words, later occurrences override earlier occurrences.
 * Overstrike and underline cannot be "undone" by other words
 */

/*
 *----------------------------------------------------------------------
 *
 * GdiParseFontWords --
 *
 *	Converts various keywords to modifiers of a font specification.  For
 *	all words, later occurrences override earlier occurrences.  Overstrike
 *	and underline cannot be "undone" by other words
 *
 * Results:
 *	 Keywords converted to modifiers.
 *
 *----------------------------------------------------------------------
 */

static int GdiParseFontWords(
    TCL_UNUSED(Tcl_Interp *),
    LOGFONTW *lf,
    const char *str[],
    int numargs)
{
    int i;
    int retval = 0; /* Number of words that could not be parsed. */

    for (i=0; i<numargs; i++) {
	if (str[i]) {
	    int wt;
	    if ((wt = GdiWordToWeight(str[i])) != -1) {
		lf->lfWeight = wt;
	    } else if (strcmp(str[i], "roman") == 0) {
		lf->lfItalic = FALSE;
	    } else if (strcmp(str[i], "italic") == 0) {
		lf->lfItalic = TRUE;
	    } else if (strcmp(str[i], "underline") == 0) {
		lf->lfUnderline = TRUE;
	    } else if (strcmp(str[i], "overstrike") == 0) {
		lf->lfStrikeOut = TRUE;
	    } else {
		retval++;
	    }
	}
    }
    return retval;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiWordToWeight --
 *
 *	Converts keywords to font weights.
 *
 * Results:
 *	Helps set the proper font for GDI rendering.
 *
 *----------------------------------------------------------------------
 */

static int GdiWordToWeight(
    const char *str)
{
    int retval = -1;
    size_t i;
    static const struct font_weight {
	const char *name;
	int weight;
    } font_weights[] = {
	{ "thin", FW_THIN },
	{ "extralight", FW_EXTRALIGHT },
	{ "ultralight", FW_EXTRALIGHT },
	{ "light", FW_LIGHT },
	{ "normal", FW_NORMAL },
	{ "regular", FW_NORMAL },
	{ "medium", FW_MEDIUM },
	{ "semibold", FW_SEMIBOLD },
	{ "demibold", FW_SEMIBOLD },
	{ "bold", FW_BOLD },
	{ "extrabold", FW_EXTRABOLD },
	{ "ultrabold", FW_EXTRABOLD },
	{ "heavy", FW_HEAVY },
	{ "black", FW_HEAVY },
    };

    if (str == 0) {
	return -1;
    }

    for (i=0; i<sizeof(font_weights) / sizeof(struct font_weight); i++) {
	if (strcmp(str, font_weights[i].name) == 0) {
	    retval = font_weights[i].weight;
	    break;
	}
    }

    return retval;
}

/*
 *----------------------------------------------------------------------
 *
 * MakeLogFont --
 *
 *	Takes the font description string and converts this into a logical
 *	font spec.
 *
 * Results:
 *	 Sets font weight.
 *
 *----------------------------------------------------------------------
 */

static int GdiMakeLogFont(
    Tcl_Interp *interp,
    const char *str,
    LOGFONTW *lf,
    HDC hDC)
{
    const char **list;
    Tcl_Size count;

    /* Set up defaults for logical font. */
    memset(lf, 0, sizeof(*lf));
    lf->lfWeight  = FW_NORMAL;
    lf->lfCharSet = DEFAULT_CHARSET;
    lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf->lfQuality = DEFAULT_QUALITY;
    lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;

    /* The cast to (char *) is silly, based on prototype of Tcl_SplitList. */
    if (Tcl_SplitList(interp, str, &count, &list) != TCL_OK) {
	return 0;
    }

    /* Now we have the font structure broken into name, size, weight. */
    if (count >= 1) {
	Tcl_DString ds;

	Tcl_DStringInit(&ds);
	wcsncpy(lf->lfFaceName, Tcl_UtfToWCharDString(list[0], TCL_INDEX_NONE, &ds),
		LF_FACESIZE-1);
	Tcl_DStringFree(&ds);
	lf->lfFaceName[LF_FACESIZE-1] = 0;
    } else {
	return 0;
    }

    if (count >= 2) {
	int siz;
	char *strend;
	siz = strtol(list[1], &strend, 0);

	/*
	 * Assumptions:
	 * 1) Like canvas, if a positive number is specified, it's in points.
	 * 2) Like canvas, if a negative number is specified, it's in pixels.
	 */
	if (strend > list[1]) { /* If it looks like a number, it is a number.... */
	    if (siz > 0) {  /* Size is in points. */
		SIZE wextent, vextent;
		POINT worigin, vorigin;
		double factor;

		switch (GdiGetHdcInfo(hDC, &worigin, &wextent, &vorigin, &vextent)) {
		case MM_ISOTROPIC:
		    if (vextent.cy < -1 || vextent.cy > 1) {
			factor = (double)wextent.cy / vextent.cy;
			if (factor < 0.0) {
			    factor = -factor;
			}
			lf->lfHeight = (int)(-siz * GetDeviceCaps(hDC, LOGPIXELSY) * factor / 72.0);
		    } else if (vextent.cx < -1 || vextent.cx > 1) {
			factor = (double)wextent.cx / vextent.cx;
			if (factor < 0.0) {
			    factor = -factor;
			}
			lf->lfHeight = (int)(-siz * GetDeviceCaps(hDC, LOGPIXELSY) * factor / 72.0);
		    } else {
			lf->lfHeight = -siz; /* This is bad news.... */
		    }
		    break;
		case MM_ANISOTROPIC:
		    if (vextent.cy != 0) {
			factor = (double)wextent.cy / vextent.cy;
			if (factor < 0.0) {
			    factor = -factor;
			}
			lf->lfHeight = (int)(-siz * GetDeviceCaps(hDC, LOGPIXELSY) * factor / 72.0);
		    } else {
			lf->lfHeight = -siz; /* This is bad news.... */
		    }
		    break;
		case MM_TEXT:
		default:
		    /* If mapping mode is MM_TEXT, use the documented
		     * formula. */
		    lf->lfHeight = -MulDiv(siz, GetDeviceCaps(hDC, LOGPIXELSY), 72);
		    break;
		case MM_HIENGLISH:
		    lf->lfHeight = -MulDiv(siz, 1000, 72);
		    break;
		case MM_LOENGLISH:
		    lf->lfHeight = -MulDiv(siz, 100, 72);
		    break;
		case MM_HIMETRIC:
		    lf->lfHeight = -MulDiv(siz, (int)(1000*2.54), 72);
		    break;
		case MM_LOMETRIC:
		    lf->lfHeight = -MulDiv(siz, (int)(100*2.54), 72);
		    break;
		case MM_TWIPS:
		    lf->lfHeight = -MulDiv(siz, 1440, 72);
		    break;
		}
	    } else if (siz == 0) {   /* Use default size of 12 points. */
		lf->lfHeight = -MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72);
	    } else {                 /* Use pixel size. */
		lf->lfHeight = siz;  /* Leave this negative. */
	    }
	} else {
	    GdiParseFontWords(interp, lf, list+1, count-1);
	}
    }

    if (count >= 3) {
	GdiParseFontWords(interp, lf, list+2, count-2);
    }

    ckfree(list);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiMakePen --
 *
 *	Creates a logical pen based on input parameters and selects it into
 *	the hDC.
 *
 * Results:
 *	Sets rendering pen.
 *
 *----------------------------------------------------------------------
 */

static int GdiMakePen(
    Tcl_Interp *interp,
    int width,
    int dashstyle,
    const char *dashstyledata,
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),		/* Ignored for now. */
    TCL_UNUSED(int),
    TCL_UNUSED(const char *),	/* Ignored for now. */
    unsigned long color,
    HDC hDC,
    HGDIOBJ *oldPen)
{
    /*
     * The LOGPEN structure takes the following dash options:
     * PS_SOLID: a solid pen
     * PS_DASH:  a dashed pen
     * PS_DOT:   a dotted pen
     * PS_DASHDOT: a pen with a dash followed by a dot
     * PS_DASHDOTDOT: a pen with a dash followed by 2 dots
     *
     * It seems that converting to ExtCreatePen may be more advantageous, as
     * it matches the Tk canvas pens much better--but not for Win95, which
     * does not support PS_USERSTYLE. An explicit test (or storage in a static
     * after first failure) may suffice for working around this. The
     * ExtCreatePen is not supported at all under Win32.
     */

    HPEN hPen;
    LOGBRUSH lBrush;
    DWORD pStyle = PS_SOLID;           /* -dash should override*/
    DWORD endStyle = PS_ENDCAP_ROUND;  /* -capstyle should override. */
    DWORD joinStyle = PS_JOIN_ROUND;   /* -joinstyle should override. */
    DWORD styleCount = 0;
    DWORD *styleArray = 0;

    /*
     * To limit the propagation of allocated memory, the dashes will have a
     * maximum here.  If one wishes to remove the static allocation, please be
     * sure to update GdiFreePen and ensure that the array is NOT freed if the
     * LOGPEN option is used.
     */
    static DWORD pStyleData[24];
    if (dashstyle != 0 && dashstyledata != 0) {
	const char *cp;
	size_t i;
	char *dup = (char *) ckalloc(strlen(dashstyledata) + 1);
	strcpy(dup, dashstyledata);
	/* DEBUG. */
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"DEBUG: Found a dash spec of |%s|\n",
		dashstyledata));

	/* Parse the dash spec. */
	if (isdigit(dashstyledata[0])) {
	    cp = strtok(dup, " \t,;");
	    for (i = 0; cp && i < sizeof(pStyleData) / sizeof(DWORD); i++) {
		pStyleData[styleCount++] = atoi(cp);
		cp = strtok(NULL, " \t,;");
	    }
	} else {
	    for (i=0; dashstyledata[i] != '\0' && i< sizeof(pStyleData) / sizeof(DWORD); i++) {
		switch (dashstyledata[i]) {
		case ' ':
		    pStyleData[styleCount++] = 8;
		    break;
		case ',':
		    pStyleData[styleCount++] = 4;
		    break;
		case '_':
		    pStyleData[styleCount++] = 6;
		    break;
		case '-':
		    pStyleData[styleCount++] = 4;
		    break;
		case '.':
		    pStyleData[styleCount++] = 2;
		    break;
		default:
		    break;
		}
	    }
	}
	if (styleCount > 0) {
	    styleArray = pStyleData;
	} else {
	    dashstyle = 0;
	}
	if (dup) {
	    ckfree(dup);
	}
    }

    if (dashstyle != 0) {
	pStyle = PS_USERSTYLE;
    }

    /* -stipple could affect this.... */
    lBrush.lbStyle = BS_SOLID;
    lBrush.lbColor = color;
    lBrush.lbHatch = 0;

    /* We only use geometric pens, even for 1-pixel drawing. */
    hPen = ExtCreatePen(PS_GEOMETRIC|pStyle|endStyle|joinStyle,
	    width, &lBrush, styleCount, styleArray);

    if (hPen == 0) { /* Failed for some reason...Fall back on CreatePenIndirect. */
	LOGPEN lf;
	lf.lopnWidth.x = width;
	lf.lopnWidth.y = 0;		/* Unused in LOGPEN. */
	if (dashstyle == 0) {
	    lf.lopnStyle = PS_SOLID;	/* For now...convert 'style' in the future. */
	} else {
	    lf.lopnStyle = PS_DASH;	/* REALLLLY simple for now. */
	}
	lf.lopnColor = color;		/* Assume we're getting a COLORREF. */
	/* Now we have a logical pen. Create the "real" pen and put it in the
	 * hDC. */
	hPen = CreatePenIndirect(&lf);
    }

    *oldPen = SelectObject(hDC, hPen);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiFreePen --
 *
 *	Wraps the protocol to delete a created pen.
 *
 * Results:
 *	Deletes pen.
 *
 *----------------------------------------------------------------------
 */

static int GdiFreePen(
    TCL_UNUSED(Tcl_Interp *),
    HDC hDC,
    HGDIOBJ oldPen)
{
    HGDIOBJ gonePen = SelectObject(hDC, oldPen);

    DeleteObject(gonePen);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiMakeBrush--
 *
 *	Creates a logical brush based on input parameters, and selects it into
 *	the hdc.
 *
 * Results:
 *	 Creates brush.
 *
 *----------------------------------------------------------------------
 */

static int GdiMakeBrush(
    unsigned long color,
    long hatch,
    LOGBRUSH *lb,
    HDC hDC,
	HBRUSH *oldBrush)
{
    HBRUSH hBrush;
    lb->lbStyle = BS_SOLID; /* Support other styles later. */
    lb->lbColor = color;    /* Assume this is a COLORREF. */
    lb->lbHatch = hatch;    /* Ignored for now, given BS_SOLID in the Style. */

    /* Now we have the logical brush. Create the "real" brush and put it in
     * the hDC. */
    hBrush = CreateBrushIndirect(lb);
    *oldBrush = (HBRUSH)SelectObject(hDC, hBrush);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GdiFreeBrush --
 *
 *	Wraps the protocol to delete a created brush.
 *
 * Results:
 *	 Deletes brush.
 *
 *----------------------------------------------------------------------
 */
static void GdiFreeBrush(
    TCL_UNUSED(Tcl_Interp *),
    HDC hDC,
    HGDIOBJ oldBrush)
{
    HGDIOBJ goneBrush;

    goneBrush = SelectObject(hDC, oldBrush);
    DeleteObject(goneBrush);
}

/*
 * Utility functions from elsewhere in Tcl.
 * Functions have removed reliance on X and Tk libraries, as well as removing
 * the need for TkWindows.
 * GdiGetColor is a copy of a TkpGetColor from tkWinColor.c
 */
typedef struct {
    const char *name;
    int index;
} SystemColorEntry;

static const SystemColorEntry sysColors[] = {
    {"3dDarkShadow",		COLOR_3DDKSHADOW},
    {"3dLight",			COLOR_3DLIGHT},
    {"ActiveBorder",		COLOR_ACTIVEBORDER},
    {"ActiveCaption",		COLOR_ACTIVECAPTION},
    {"AppWorkspace",		COLOR_APPWORKSPACE},
    {"Background",		COLOR_BACKGROUND},
    {"ButtonFace",		COLOR_BTNFACE},
    {"ButtonHighlight",		COLOR_BTNHIGHLIGHT},
    {"ButtonShadow",		COLOR_BTNSHADOW},
    {"ButtonText",		COLOR_BTNTEXT},
    {"CaptionText",		COLOR_CAPTIONTEXT},
    {"DisabledText",		COLOR_GRAYTEXT},
    {"GrayText",		COLOR_GRAYTEXT},
    {"Highlight",		COLOR_HIGHLIGHT},
    {"HighlightText",		COLOR_HIGHLIGHTTEXT},
    {"InactiveBorder",		COLOR_INACTIVEBORDER},
    {"InactiveCaption",		COLOR_INACTIVECAPTION},
    {"InactiveCaptionText",	COLOR_INACTIVECAPTIONTEXT},
    {"InfoBackground",		COLOR_INFOBK},
    {"InfoText",		COLOR_INFOTEXT},
    {"Menu",			COLOR_MENU},
    {"MenuText",		COLOR_MENUTEXT},
    {"Scrollbar",		COLOR_SCROLLBAR},
    {"Window",			COLOR_WINDOW},
    {"WindowFrame",		COLOR_WINDOWFRAME},
    {"WindowText",		COLOR_WINDOWTEXT}
};

static const size_t numsyscolors = sizeof(sysColors) / sizeof(SystemColorEntry);

/*
 *----------------------------------------------------------------------
 *
 * GdiGetColor --
 *
 *	Convert color name to color specification.
 *
 * Results:
 *	 Color name converted.
 *
 *----------------------------------------------------------------------
 */

static int GdiGetColor(
    Tcl_Obj *nameObj,
    COLORREF *color)
{
    const char *name = Tcl_GetString(nameObj);

    if (_strnicmp(name, "system", 6) == 0) {
	size_t i, l, u;
	int r;

	l = 0;
	u = numsyscolors;
	while (l <= u) {
	    i = (l + u) / 2;
	    if ((r = _strcmpi(name+6, sysColors[i].name)) == 0) {
		break;
	    }
	    if (r < 0) {
		u = i - 1;
	    } else {
		l = i + 1;
	    }
	}
	if (l > u) {
	    return 0;
	}
	*color = GetSysColor(sysColors[i].index);
	return 1;
    } else {
    int result;
    XColor xcolor;
	result = XParseColor(NULL, 0, name, &xcolor);
	*color = ((xcolor.red & 0xFF00)>>8) | (xcolor.green & 0xFF00)
		| ((xcolor.blue & 0xFF00)<<8);
    return result;
    }
}

/*
 * Beginning of functions for screen-to-dib translations.
 *
 * Several of these functions are based on those in the WINCAP32 program
 * provided as a sample by Microsoft on the VC++ 5.0 disk. The copyright on
 * these functions is retained, even for those with significant changes.
 */

/*
 *----------------------------------------------------------------------
 *
 * CopyToDIB --
 *
 *	Copy window bits to a DIB.
 *
 * Results:
 *	 Color specification converted.
 *
 *----------------------------------------------------------------------
 */

static HANDLE CopyToDIB(
    HWND hWnd,
    enum PrintType type)
{
    HANDLE hDIB;
    HBITMAP hBitmap;
    HPALETTE hPalette;

    /* Check for a valid window handle. */

    if (!hWnd) {
        return NULL;
    }

    switch (type) {
    case PTWindow: {	/* Copy entire window. */
	RECT rectWnd;

	/* Get the window rectangle. */

	GetWindowRect(hWnd, &rectWnd);

	/*
	 * Get the DIB of the window by calling CopyScreenToDIB and passing it
	 * the window rect.
	 */

	hDIB = CopyScreenToDIB(&rectWnd);
	break;
    }

    case PTClient: {	/* Copy client area. */
	RECT rectClient;
	POINT pt1, pt2;

	/* Get the client area dimensions. */

	GetClientRect(hWnd, &rectClient);

	/* Convert client coords to screen coords. */

	pt1.x = rectClient.left;
	pt1.y = rectClient.top;
	pt2.x = rectClient.right;
	pt2.y = rectClient.bottom;
	ClientToScreen(hWnd, &pt1);
	ClientToScreen(hWnd, &pt2);
	rectClient.left = pt1.x;
	rectClient.top = pt1.y;
	rectClient.right = pt2.x;
	rectClient.bottom = pt2.y;

	/*
	 * Get the DIB of the client area by calling CopyScreenToDIB and
	 * passing it the client rect.
	 */

	hDIB = CopyScreenToDIB(&rectClient);
	break;
    }

    case PTScreen: { /* Entire screen. */
	RECT Rect;

	/*
	 * Get the device-dependent bitmap in lpRect by calling
	 * CopyScreenToBitmap and passing it the rectangle to grab.
	 */
	Rect.top = Rect.left = 0;
	GetDisplaySize(&Rect.right, &Rect.bottom);

	hBitmap = CopyScreenToBitmap(&Rect);

	/* Check for a valid bitmap handle. */

	if (!hBitmap) {
	    return NULL;
	}

	/* Get the current palette. */

	hPalette = GetSystemPalette();

	/* Convert the bitmap to a DIB. */

	hDIB = BitmapToDIB(hBitmap, hPalette);

	/* Clean up. */

	DeleteObject(hPalette);
	DeleteObject(hBitmap);

	/* Return handle to the packed-DIB. */
	break;
    }
    default:	/* Invalid print area. */
	return NULL;
    }

    /* Return the handle to the DIB. */
    return hDIB;
}

/*
 *----------------------------------------------------------------------
 *
 * GetDisplaySize--
 *
 *	GetDisplaySize does just that.  There may be an easier way, but it is
 *	not apparent.
 *
 * Results:
 *	Returns display size.
 *
 *----------------------------------------------------------------------
 */

static void GetDisplaySize(
    LONG *width,
    LONG *height)
{
    HDC hDC;

    hDC = CreateDCW(L"DISPLAY", 0, 0, 0);
    *width = GetDeviceCaps(hDC, HORZRES);
    *height = GetDeviceCaps(hDC, VERTRES);
    DeleteDC(hDC);
}

/*
 *----------------------------------------------------------------------
 *
 * CopyScreenToBitmap--
 *
 *	Copies screen to bitmap.
 *
 * Results:
 *	Screen is copied.
 *
 *----------------------------------------------------------------------
 */

static HBITMAP CopyScreenToBitmap(
    LPRECT lpRect)
{
    HDC     hScrDC, hMemDC;	/* Screen DC and memory DC. */
    HGDIOBJ hBitmap, hOldBitmap; /* Handles to deice-dependent bitmaps. */
    int     nX, nY, nX2, nY2;	/* Coordinates of rectangle to grab. */
    int     nWidth, nHeight;	/* DIB width and height */
    int     xScrn, yScrn;	/* Screen resolution. */

    /* Check for an empty rectangle. */

    if (IsRectEmpty(lpRect)) {
	return NULL;
    }

    /*
     * Create a DC for the screen and create a memory DC compatible to screen
     * DC.
     */

    hScrDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
    hMemDC = CreateCompatibleDC(hScrDC);

    /* Get points of rectangle to grab. */

    nX = lpRect->left;
    nY = lpRect->top;
    nX2 = lpRect->right;
    nY2 = lpRect->bottom;

    /* Get screen resolution. */

    xScrn = GetDeviceCaps(hScrDC, HORZRES);
    yScrn = GetDeviceCaps(hScrDC, VERTRES);

    /* Make sure bitmap rectangle is visible. */

    if (nX < 0) {
        nX = 0;
    }
    if (nY < 0) {
        nY = 0;
    }
    if (nX2 > xScrn) {
        nX2 = xScrn;
    }
    if (nY2 > yScrn) {
        nY2 = yScrn;
    }

    nWidth = nX2 - nX;
    nHeight = nY2 - nY;

    /* Create a bitmap compatible with the screen DC. */
    hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);

    /* Select new bitmap into memory DC. */
    hOldBitmap = SelectObject(hMemDC, hBitmap);

    /* Bitblt screen DC to memory DC. */
    BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);

    /*
     * Select old bitmap back into memory DC and get handle to bitmap of the
     * screen.
     */

    hBitmap = SelectObject(hMemDC, hOldBitmap);

    /* Clean up. */

    DeleteDC(hScrDC);
    DeleteDC(hMemDC);

    /* Return handle to the bitmap. */

    return (HBITMAP)hBitmap;
}

/*
 *----------------------------------------------------------------------
 *
 * BitmapToDIB--
 *
 *	Converts bitmap to DIB.
 *
 * Results:
 *	Bitmap converted.
 *
 *----------------------------------------------------------------------
 */

static HANDLE BitmapToDIB(
    HBITMAP hBitmap,
    HPALETTE hPal)
{
    BITMAP              bm;
    BITMAPINFOHEADER    bi;
    LPBITMAPINFOHEADER  lpbi;
    DWORD               dwLen;
    HANDLE              hDIB;
    HANDLE              h;
    HDC                 hDC;
    WORD                biBits;

    /* Check if bitmap handle is valid. */

    if (!hBitmap) {
        return NULL;
    }

    /* Fill in BITMAP structure, return NULL if it didn't work. */

    if (!GetObjectW(hBitmap, sizeof(bm), (LPWSTR)&bm)) {
        return NULL;
    }

    /* Ff no palette is specified, use default palette. */

    if (hPal == NULL) {
        hPal = (HPALETTE)GetStockObject(DEFAULT_PALETTE);
    }

    /* Calculate bits per pixel. */

    biBits = bm.bmPlanes * bm.bmBitsPixel;

    /* Make sure bits per pixel is valid. */

    if (biBits <= 1) {
        biBits = 1;
    } else if (biBits <= 4) {
        biBits = 4;
    } else if (biBits <= 8) {
        biBits = 8;
    } else { /* If greater than 8-bit, force to 24-bit. */
        biBits = 24;
    }

    /* Initialize BITMAPINFOHEADER. */

    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = bm.bmWidth;
    bi.biHeight = bm.bmHeight;
    bi.biPlanes = 1;
    bi.biBitCount = biBits;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;

    /* Calculate size of memory block required to store BITMAPINFO. */

    dwLen = bi.biSize + DIBNumColors(&bi) * sizeof(RGBQUAD);

    /* Get a DC. */

    hDC = GetDC(NULL);

    /* Select and realize our palette. */

    hPal = SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);

    /* Alloc memory block to store our bitmap. */

    hDIB = GlobalAlloc(GHND, dwLen);

    /* If we couldn't get memory block. */

    if (!hDIB) {
	/* clean up and return NULL. */

	SelectPalette(hDC, hPal, TRUE);
	RealizePalette(hDC);
	ReleaseDC(NULL, hDC);
	return NULL;
    }

    /* Lock memory and get pointer to it. */

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);

    /* Use our bitmap info. to fill BITMAPINFOHEADER. */

    *lpbi = bi;

    /* Call GetDIBits with a NULL lpBits param, so it will calculate the
     * biSizeImage field for us
     */

    GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, NULL, (LPBITMAPINFO)lpbi,
	    DIB_RGB_COLORS);

    /* get the info. returned by GetDIBits and unlock memory block. */

    bi = *lpbi;
    GlobalUnlock(hDIB);

    /* If the driver did not fill in the biSizeImage field, make one up. */
    if (bi.biSizeImage == 0) {
        bi.biSizeImage = (((((DWORD)bm.bmWidth * biBits) + 31) / 32) * 4)
		* bm.bmHeight;
    }

    /* Realloc the buffer big enough to hold all the bits. */

    dwLen = bi.biSize + DIBNumColors(&bi) * sizeof(RGBQUAD) + bi.biSizeImage;

    if ((h = GlobalReAlloc(hDIB, dwLen, 0)) != 0) {
        hDIB = h;
    } else {
	/* Clean up and return NULL. */

	GlobalFree(hDIB);
	SelectPalette(hDC, hPal, TRUE);
	RealizePalette(hDC);
	ReleaseDC(NULL, hDC);
	return NULL;
    }

    /* Lock memory block and get pointer to it. */

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);

    /* Call GetDIBits with a NON-NULL lpBits param, and actualy get the
     * bits this time.
     */

    if (GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, (LPSTR)lpbi +
	    (WORD)lpbi->biSize + DIBNumColors(lpbi) * sizeof(RGBQUAD),
	    (LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0) {
	/* Clean up and return NULL. */

	GlobalUnlock(hDIB);
	SelectPalette(hDC, hPal, TRUE);
	RealizePalette(hDC);
	ReleaseDC(NULL, hDC);
	return NULL;
    }

    bi = *lpbi;

    /* Clean up. */
    GlobalUnlock(hDIB);
    SelectPalette(hDC, hPal, TRUE);
    RealizePalette(hDC);
    ReleaseDC(NULL, hDC);

    /* Return handle to the DIB. */
    return hDIB;
}

/*
 *----------------------------------------------------------------------
 *
 * CopyScreenToDIB--
 *
 *	Copies screen to DIB.
 *
 * Results:
 *	Screen copied.
 *
 *----------------------------------------------------------------------
 */

static HANDLE CopyScreenToDIB(
    LPRECT lpRect)
{
    HBITMAP     hBitmap;
    HPALETTE    hPalette;
    HANDLE      hDIB;

    /*
     * Get the device-dependent bitmap in lpRect by calling CopyScreenToBitmap
     * and passing it the rectangle to grab.
     */

    hBitmap = CopyScreenToBitmap(lpRect);

    /* Check for a valid bitmap handle. */

    if (!hBitmap) {
	return NULL;
    }

    /* Get the current palette. */

    hPalette = GetSystemPalette();

    /* convert the bitmap to a DIB. */

    hDIB = BitmapToDIB(hBitmap, hPalette);

    /* Clean up. */

    DeleteObject(hPalette);
    DeleteObject(hBitmap);

    /* Return handle to the packed-DIB. */
    return hDIB;
}

/*
 *----------------------------------------------------------------------
 *
 * GetSystemPalette--
 *
 *	Obtains the system palette.
 *
 * Results:
 *	Returns palette.
 *
 *----------------------------------------------------------------------
 */

static HPALETTE GetSystemPalette(void)
{
    HDC hDC;                /* Handle to a DC. */
    static HPALETTE hPal = NULL;   /* Handle to a palette. */
    HANDLE hLogPal;         /* Handle to a logical palette. */
    LPLOGPALETTE lpLogPal;  /* Pointer to a logical palette. */
    int nColors;            /* Number of colors. */

    /* Find out how many palette entries we want.. */

    hDC = GetDC(NULL);
    if (!hDC) {
        return NULL;
    }

    nColors = PalEntriesOnDevice(hDC);   /* Number of palette entries. */

    /* Allocate room for the palette and lock it.. */

    hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors *
	    sizeof(PALETTEENTRY));
    if (!hLogPal) {
	/* If we didn't get a logical palette, return NULL. */

        return NULL;
    }

    /* get a pointer to the logical palette. */

    lpLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);

    /* Set some important fields. */

    lpLogPal->palVersion = 0x300;
    lpLogPal->palNumEntries = nColors;

    /* Copy the current system palette into our logical palette. */

    GetSystemPaletteEntries(hDC, 0, nColors,
	    (LPPALETTEENTRY) lpLogPal->palPalEntry);

    /*
     * Go ahead and create the palette.  Once it's created, we no longer need
     * the LOGPALETTE, so free it.
     */

    hPal = CreatePalette(lpLogPal);

    /* Clean up. */

    GlobalUnlock(hLogPal);
    GlobalFree(hLogPal);
    ReleaseDC(NULL, hDC);

    return hPal;
}

/*
 *----------------------------------------------------------------------
 *
 * PalEntriesOnDevice--
 *
 *	Returns the palettes on the device.
 *
 * Results:
 *	Returns palettes.
 *
 *----------------------------------------------------------------------
 */

static int PalEntriesOnDevice(
    HDC hDC)
{
    return (1 << (GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES)));
}

/*
 * --------------------------------------------------------------------------
 *
 * Winprint_Init--
 *
 *	Initializes printing module on Windows.
 *
 * Results:
 *	Module initialized.
 *
 * -------------------------------------------------------------------------
 */

int Winprint_Init(
    Tcl_Interp * interp)
{
    size_t i;
    Tcl_Namespace *namespacePtr;
    static const char *gdiName = "::tk::print::_gdi";
    static const size_t numCommands =
	    sizeof(gdi_commands) / sizeof(struct gdi_command);

    /*
     * Set up the low-level [_gdi] command.
     */

    namespacePtr = Tcl_CreateNamespace(interp, gdiName,
	    NULL, (Tcl_NamespaceDeleteProc *) NULL);
    for (i=0; i<numCommands; i++) {
	char buffer[100];

	snprintf(buffer, sizeof(buffer), "%s::%s", gdiName, gdi_commands[i].command_string);
	Tcl_CreateObjCommand(interp, buffer, gdi_commands[i].command,
		NULL, (Tcl_CmdDeleteProc *) 0);
	Tcl_Export(interp, namespacePtr, gdi_commands[i].command_string, 0);
    }
    Tcl_CreateEnsemble(interp, gdiName, namespacePtr, 0);

    /*
     * The other printing-related commands.
     */

    Tcl_CreateObjCommand(interp, "::tk::print::_selectprinter",
	    PrintSelectPrinter, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_openprinter",
	    PrintOpenPrinter, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_closeprinter",
	    PrintClosePrinter, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_opendoc",
	    PrintOpenDoc, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_closedoc",
	    PrintCloseDoc, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_openpage",
	    PrintOpenPage, NULL, NULL);
    Tcl_CreateObjCommand(interp, "::tk::print::_closepage",
	    PrintClosePage, NULL, NULL);
    return TCL_OK;
}

/* Print API functions. */

/*----------------------------------------------------------------------
 *
 * PrintSelectPrinter--
 *
 *	Main dialog for selecting printer and initializing data for print job.
 *
 * Results:
 *	Printer selected.
 *
 *----------------------------------------------------------------------
 */

static int PrintSelectPrinter(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj* const*))
{
    LPCWSTR printerName = NULL;
    PDEVMODEW returnedDevmode = NULL;
    PDEVMODEW localDevmode = NULL;

    copies = 0;
    paper_width = 0;
    paper_height = 0;
    dpi_x = 0;
    dpi_y = 0;

    /* Set up print dialog and initalize property structure. */

    memset(&pd, 0, sizeof(pd));
    pd.lStructSize = sizeof(pd);
    pd.hwndOwner = GetDesktopWindow();
    pd.Flags = PD_HIDEPRINTTOFILE | PD_DISABLEPRINTTOFILE | PD_NOSELECTION;

    if (PrintDlgW(&pd) == TRUE) {

	/*Get document info.*/
	memset(&di, 0, sizeof(di));
	di.cbSize = sizeof(di);
	di.lpszDocName = L"Tk Print Output";

	/* Copy print attributes to local structure. */
	returnedDevmode = (PDEVMODEW) GlobalLock(pd.hDevMode);
	devnames = (LPDEVNAMES) GlobalLock(pd.hDevNames);
	printerName = (LPCWSTR) devnames + devnames->wDeviceOffset;
	localDevmode = (LPDEVMODEW) HeapAlloc(GetProcessHeap(),
		HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS,
		returnedDevmode->dmSize);

	if (localDevmode != NULL) {
	    memcpy((LPVOID)localDevmode, (LPVOID)returnedDevmode,
		    returnedDevmode->dmSize);

	    /* Get values from user-set and built-in properties. */
	    localPrinterName = localDevmode->dmDeviceName;
	    dpi_y = localDevmode->dmYResolution;
	    dpi_x = localDevmode->dmPrintQuality;
	    /* Convert height and width to logical points. */
	    paper_height = (int) localDevmode->dmPaperLength / 0.254;
	    paper_width = (int) localDevmode->dmPaperWidth / 0.254;
	    copies = pd.nCopies;
	    /* Set device context here for all GDI printing operations. */
	    printDC = CreateDCW(L"WINSPOOL", printerName, NULL, localDevmode);
	} else {
	    localDevmode = NULL;
	}
    }

    if (pd.hDevMode != NULL) {
	GlobalFree(pd.hDevMode);
    }

    /*
     * Store print properties and link variables so they can be accessed from
     * script level.
     */
    if (localPrinterName != NULL) {
        char* varlink1 = (char*)ckalloc(100 * sizeof(char));
        char** varlink2 = (char**)ckalloc(sizeof(char*));
        *varlink2 = varlink1;
        WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, varlink1, 0, NULL, NULL);

        Tcl_LinkVar(interp, "::tk::print::printer_name", varlink2,
            TCL_LINK_STRING | TCL_LINK_READ_ONLY);
        Tcl_LinkVar(interp, "::tk::print::copies", &copies,
            TCL_LINK_INT | TCL_LINK_READ_ONLY);
        Tcl_LinkVar(interp, "::tk::print::dpi_x", &dpi_x,
            TCL_LINK_INT | TCL_LINK_READ_ONLY);
        Tcl_LinkVar(interp, "::tk::print::dpi_y", &dpi_y,
            TCL_LINK_INT | TCL_LINK_READ_ONLY);
        Tcl_LinkVar(interp, "::tk::print::paper_width", &paper_width,
            TCL_LINK_INT | TCL_LINK_READ_ONLY);
        Tcl_LinkVar(interp, "::tk::print::paper_height", &paper_height,
            TCL_LINK_INT | TCL_LINK_READ_ONLY);
    }

    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintOpenPrinter--
 *
 *	Open the given printer.
 *
 * Results:
 *	Opens the selected printer.
 *
 * -------------------------------------------------------------------------
 */

int PrintOpenPrinter(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_DString ds;

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "printer");
	return TCL_ERROR;
    }

    /*Start an individual page.*/
    if (StartPage(printDC) <= 0) {
	return TCL_ERROR;
    }

    const char *printer = Tcl_GetString(objv[1]);

    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    Tcl_DStringInit(&ds);
    if ((OpenPrinterW(Tcl_UtfToWCharDString(printer, -1, &ds),
	    (LPHANDLE)&printDC, NULL)) == FALSE) {
	Tcl_AppendResult(interp, "unable to open printer", (char *)NULL);
	Tcl_DStringFree(&ds);
	return TCL_ERROR;
    }

    Tcl_DStringFree(&ds);
    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintClosePrinter--
 *
 *	Closes the given printer.
 *
 * Results:
 *	Printer closed.
 *
 * -------------------------------------------------------------------------
 */

int PrintClosePrinter(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    ClosePrinter(printDC);
    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintOpenDoc--
 *
 *     Opens the document for printing.
 *
 * Results:
 *      Opens the print document.
 *
 * -------------------------------------------------------------------------
 */

int PrintOpenDoc(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    int output = 0;

    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    /*
     * Start printing.
     */
    output = StartDocW(printDC, &di);
    if (output <= 0) {
	Tcl_AppendResult(interp, "unable to start document", (char *)NULL);
	return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintCloseDoc--
 *
 *	Closes the document for printing.
 *
 * Results:
 *	Closes the print document.
 *
 * -------------------------------------------------------------------------
 */

int PrintCloseDoc(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    if (EndDoc(printDC) <= 0) {
	Tcl_AppendResult(interp, "unable to establish close document", (char *)NULL);
	return TCL_ERROR;
    }
    DeleteDC(printDC);
    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintOpenPage--
 *
 *    Opens a page for printing.
 *
 * Results:
 *      Opens the print page.
 *
 * -------------------------------------------------------------------------
 */

int PrintOpenPage(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    /*Start an individual page.*/
    if (StartPage(printDC) <= 0) {
	Tcl_AppendResult(interp, "unable to start page", (char *)NULL);
	return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * PrintClosePage--
 *
 *	Closes the printed page.
 *
 * Results:
 *	Closes the page.
 *
 * -------------------------------------------------------------------------
 */

int PrintClosePage(
    TCL_UNUSED(void *),
    Tcl_Interp *interp,
    TCL_UNUSED(int),
    TCL_UNUSED(Tcl_Obj *const *))
{
    if (printDC == NULL) {
	Tcl_AppendResult(interp, "unable to establish device context", (char *)NULL);
	return TCL_ERROR;
    }

    if (EndPage(printDC) <= 0) {
	Tcl_AppendResult(interp, "unable to close page", (char *)NULL);
	return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted win/tkWinIco.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227



































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkWinIco.c --
 *
 *	This file contains functions for icon-manipulation routines
 *      in Windows.
 *
 * Copyright © 1995-1996 Microsoft Corp.
 * Copyright © 1998 Brueckner & Jarosch Ing.GmbH, Erfurt, Germany
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinIco.h"

/*
 *----------------------------------------------------------------------
 *
 * DIBNumColors --
 *
 *	Calculates the number of entries in the color table, given by LPSTR
 *	lpbi - pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	WORD - Number of entries in the color table.
 *
 *----------------------------------------------------------------------
 */

static WORD
DIBNumColors(
    LPSTR lpbi)
{
    WORD wBitCount;
    DWORD dwClrUsed;

    dwClrUsed = ((LPBITMAPINFOHEADER) lpbi)->biClrUsed;

    if (dwClrUsed) {
	return (WORD) dwClrUsed;
    }

    wBitCount = ((LPBITMAPINFOHEADER) lpbi)->biBitCount;

    switch (wBitCount) {
    case 1:
	return 2;
    case 4:
	return 16;
    case 8:
	return 256;
    default:
	return 0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PaletteSize --
 *
 *	Calculates the number of bytes in the color table, as given by LPSTR
 *	lpbi - pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	Number of bytes in the color table
 *
 *----------------------------------------------------------------------
 */
static WORD
PaletteSize(
    LPSTR lpbi)
{
    return (WORD) (DIBNumColors(lpbi) * sizeof(RGBQUAD));
}

/*
 *----------------------------------------------------------------------
 *
 * FindDIBits --
 *
 *	Locate the image bits in a CF_DIB format DIB, as given by LPSTR lpbi -
 *	pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	pointer to the image bits
 *
 * Side effects: None
 *
 *
 *----------------------------------------------------------------------
 */

LPSTR
FindDIBBits(
    LPSTR lpbi)
{
    return lpbi + *((LPDWORD) lpbi) + PaletteSize(lpbi);
}

/*
 *----------------------------------------------------------------------
 *
 * BytesPerLine --
 *
 *	Calculates the number of bytes in one scan line, as given by
 *	LPBITMAPINFOHEADER lpBMIH - pointer to the BITMAPINFOHEADER that
 *	begins the CF_DIB block. Used by titlebar icon code.
 *
 * Results:
 *	number of bytes in one scan line (DWORD aligned)
 *
 *----------------------------------------------------------------------
 */

DWORD
BytesPerLine(
    LPBITMAPINFOHEADER lpBMIH)
{
    return WIDTHBYTES(lpBMIH->biWidth * lpBMIH->biPlanes * lpBMIH->biBitCount);
}
/*
 *----------------------------------------------------------------------
 *
 * CreateIcoFromPhoto --
 *
 *	Create ico pointer from Tk photo block.
 *
 * Results:
 *	Icon image is created from a valid Tk photo image.
 *
 * Side effects:
 *	Icon is created.
 *
 *----------------------------------------------------------------------
 */

HICON
CreateIcoFromPhoto(
    int width,                  /* Width of image. */
    int height,                 /* Height of image. */
    Tk_PhotoImageBlock block)   /* Image block to convert. */
{
    int idx, bufferSize;
    union {unsigned char *ptr; void *voidPtr;} bgraPixel;
    union {unsigned char *ptr; void *voidPtr;} bgraMask;
    HICON hIcon;
    BITMAPINFO bmInfo;
    ICONINFO iconInfo;

    /*
     * Don't use CreateIcon to create the icon, as it requires color
     * bitmap data in device-dependent format. Instead we use
     * CreateIconIndirect which takes device-independent bitmaps and
     * converts them as required. Initialise icon info structure.
     */

    memset(&iconInfo, 0, sizeof(iconInfo));
    iconInfo.fIcon = TRUE;

    /*
     * Create device-independent color bitmap.
     */

    memset(&bmInfo, 0, sizeof bmInfo);
    bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmInfo.bmiHeader.biWidth = width;
    bmInfo.bmiHeader.biHeight = -height;
    bmInfo.bmiHeader.biPlanes = 1;
    bmInfo.bmiHeader.biBitCount = 32;
    bmInfo.bmiHeader.biCompression = BI_RGB;

    iconInfo.hbmColor = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS,
            &bgraPixel.voidPtr, NULL, 0);
    if (!iconInfo.hbmColor) {
        return NULL;
    }

    /*
     * Convert the photo image data into BGRA format (RGBQUAD).
     */

    bufferSize = height * width * 4;
    for (idx = 0 ; idx < bufferSize ; idx += 4) {
        bgraPixel.ptr[idx] = block.pixelPtr[idx+2];
        bgraPixel.ptr[idx+1] = block.pixelPtr[idx+1];
        bgraPixel.ptr[idx+2] = block.pixelPtr[idx+0];
        bgraPixel.ptr[idx+3] = block.pixelPtr[idx+3];
    }

    /*
     * Create a dummy mask bitmap. The contents of this don't appear to
     * matter, as CreateIconIndirect will setup the icon mask based on the
     * alpha channel in our color bitmap.
     */

    bmInfo.bmiHeader.biBitCount = 1;

    iconInfo.hbmMask = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS,
            &bgraMask.voidPtr, NULL, 0);
    if (!iconInfo.hbmMask) {
        DeleteObject(iconInfo.hbmColor);
        return NULL;
    }

    memset(bgraMask.ptr, 0, width*height/8);

    /*
     * Create an icon from the bitmaps.
     */

    hIcon = CreateIconIndirect(&iconInfo);
    DeleteObject(iconInfo.hbmColor);
    DeleteObject(iconInfo.hbmMask);
    if (hIcon == NULL) {
        return NULL;
    }

    return hIcon;
}
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Deleted win/tkWinIco.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102






































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkWinIco.h --
 *
 *	This file contains declarations for icon-manipulation routines
 *      in Windows.
 *
 * Copyright © 1995-1996 Microsoft Corp.
 * Copyright © 1998 Brueckner & Jarosch Ing.GmbH, Erfurt, Germany
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWin.h"
#include <windows.h>
#include <shellapi.h>

/*
 * These structures represent the contents of a icon, in terms of its image
 * or resource.
 */

typedef struct {
    UINT Width, Height, Colors;	/* Width, Height and bpp */
    LPBYTE lpBits;		/* Ptr to DIB bits */
    DWORD dwNumBytes;		/* How many bytes? */
    LPBITMAPINFO lpbi;		/* Ptr to header */
    LPBYTE lpXOR;		/* Ptr to XOR image bits */
    LPBYTE lpAND;		/* Ptr to AND image bits */
    HICON hIcon;		/* DAS ICON */
} ICONIMAGE, *LPICONIMAGE;

typedef struct {
    BOOL         bHasChanged;                     // Has image changed?
    TCHAR        szOriginalICOFileName[MAX_PATH]; // Original name
    TCHAR        szOriginalDLLFileName[MAX_PATH]; // Original name
    int          nNumImages;                      // How many images?
    ICONIMAGE    IconImages[1];                   // Image entries
} ICONRESOURCE, *LPICONRESOURCE;

/*
 * This structure is how we represent a block of the above items. We will
 * reallocate these structures according to how many images they need to
 * contain.
 */

typedef struct {
    int nNumImages;		/* How many images? */
    ICONIMAGE IconImages[1];	/* Image entries */
} BlockOfIconImages, *BlockOfIconImagesPtr;

/*
 * These two structures are used to read in icons from an 'icon directory'
 * (i.e. the contents of a .icr file, say). We only use these structures
 * temporarily, since we copy the information we want into a
 * BlockOfIconImages.
 */

typedef struct {
    BYTE bWidth;		/* Width of the image */
    BYTE bHeight;		/* Height of the image (times 2) */
    BYTE bColorCount;		/* Number of colors in image (0 if >=8bpp) */
    BYTE bReserved;		/* Reserved */
    WORD wPlanes;		/* Color Planes */
    WORD wBitCount;		/* Bits per pixel */
    DWORD dwBytesInRes;		/* How many bytes in this resource? */
    DWORD dwImageOffset;	/* Where in the file is this image */
} ICONDIRENTRY, *LPICONDIRENTRY;

typedef struct {
    WORD idReserved;		/* Reserved */
    WORD idType;		/* Resource type (1 for icons) */
    WORD idCount;		/* How many images? */
    ICONDIRENTRY idEntries[1];	/* The entries for each image */
} ICONDIR, *LPICONDIR;

/*
 * Used in BytesPerLine
 */

#define WIDTHBYTES(bits)	((((bits) + 31)>>5)<<2)

/*
 * The following are implemented in tkWinIco.c and also used in tkWinWm.c and tkWinSysTray.c.
 */

DWORD BytesPerLine(LPBITMAPINFOHEADER lpBMIH);
LPSTR FindDIBBits(LPSTR lpbi);
HICON CreateIcoFromPhoto(int width, int height,
                        Tk_PhotoImageBlock block);


/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */



Changes to win/tkWinImage.c.

1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







/*
 * tkWinImage.c --
 *
 *	This file contains routines for manipulation full-color images.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
122
123
124
125
126
127
128

129
130
131
132
133
134
135







-







    switch  (image->bits_per_pixel) {
    case 32:
	/*
	 * Pixel is DWORD: 0x00BBGGRR
	 */

	destPtr[3] = 0;
	/* FALLTHRU */
    case 24:
	/*
	 * Pixel is triplet: 0xBBGGRR.
	 */

	destPtr[0] = (unsigned char) GetBValue(pixel);
	destPtr[1] = (unsigned char) GetGValue(pixel);
197
198
199
200
201
202
203
204
205


206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
196
197
198
199
200
201
202


203
204
205
206
207
208
209
210
211
212
213

214

215
216
217
218
219
220
221







-
-
+
+









-
+
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

XImage *
XCreateImage(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Visual *),
    Display *display,
    Visual *visual,
    unsigned int depth,
    int format,
    int offset,
    char *data,
    unsigned int width,
    unsigned int height,
    int bitmap_pad,
    int bytes_per_line)
{
    XImage* imagePtr = (XImage*)ckalloc(sizeof(XImage));
    XImage* imagePtr = ckalloc(sizeof(XImage));

    imagePtr->width = width;
    imagePtr->height = height;
    imagePtr->xoffset = offset;
    imagePtr->format = format;
    imagePtr->data = data;
    imagePtr->byte_order = LSBFirst;
    imagePtr->bitmap_unit = 8;
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294







-
+










-
+







 *	Returns a newly allocated image containing the data from the given
 *	rectangle of the given drawable.
 *
 * Side effects:
 *	None.
 *
 * This procedure is adapted from the XGetImage implementation in TkNT. That
 * code is Copyright © 1994 Software Research Associates, Inc.
 * code is Copyright (c) 1994 Software Research Associates, Inc.
 *
 *----------------------------------------------------------------------
 */

static XImage *
XGetImageZPixmap(
    Display *display,
    Drawable d,
    int x, int y,
    unsigned int width, unsigned int height,
    TCL_UNUSED(unsigned long),
    unsigned long plane_mask,
    int	format)
{
    TkWinDrawable *twdPtr = (TkWinDrawable *)d;
    XImage *ret_image;
    HDC hdc, hdcMem;
    HBITMAP hbmp, hbmpPrev;
    BITMAPINFO *bmInfo = NULL;
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324







-
+








    /*
     * Need to do a Blt operation to copy into a new bitmap.
     */

    hbmp = CreateCompatibleBitmap(hdc, (int) width, (int) height);
    hdcMem = CreateCompatibleDC(hdc);
    hbmpPrev = (HBITMAP)SelectObject(hdcMem, hbmp);
    hbmpPrev = SelectObject(hdcMem, hbmp);
    hPal = state.palette;
    if (hPal) {
	hPalPrev1 = SelectPalette(hdcMem, hPal, FALSE);
	n = RealizePalette(hdcMem);
	if (n > 0) {
	    UpdateColors(hdcMem);
	}
345
346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
343
344
345
346
347
348
349

350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377







-
+

-
+

















-
+







	depth = Tk_Depth((Tk_Window) twdPtr->window.winPtr);
    } else {
	depth = twdPtr->bitmap.depth;
    }

    size = sizeof(BITMAPINFO);
    if (depth <= 8) {
	size += sizeof(unsigned short) << depth;
	size += sizeof(unsigned short) * (1 << depth);
    }
    bmInfo = (BITMAPINFO *)ckalloc(size);
    bmInfo = ckalloc(size);

    bmInfo->bmiHeader.biSize		= sizeof(BITMAPINFOHEADER);
    bmInfo->bmiHeader.biWidth		= width;
    bmInfo->bmiHeader.biHeight		= -(int) height;
    bmInfo->bmiHeader.biPlanes		= 1;
    bmInfo->bmiHeader.biBitCount	= depth;
    bmInfo->bmiHeader.biCompression	= BI_RGB;
    bmInfo->bmiHeader.biSizeImage	= 0;
    bmInfo->bmiHeader.biXPelsPerMeter	= 0;
    bmInfo->bmiHeader.biYPelsPerMeter	= 0;
    bmInfo->bmiHeader.biClrUsed		= 0;
    bmInfo->bmiHeader.biClrImportant	= 0;

    if (depth == 1) {
	unsigned char *p, *pend;

	GetDIBits(hdcMem, hbmp, 0, height, NULL, bmInfo, DIB_PAL_COLORS);
	data = (unsigned char *)ckalloc(bmInfo->bmiHeader.biSizeImage);
	data = ckalloc(bmInfo->bmiHeader.biSizeImage);
	if (!data) {
	    /* printf("Failed to allocate data area for XImage.\n"); */
	    ret_image = NULL;
	    goto cleanup;
	}
	ret_image = XCreateImage(display, NULL, depth, ZPixmap, 0, (char *) data,
		width, height, 32, (int) ((width + 31) >> 3) & ~1);
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413







-
+







	}
    } else if (depth == 8) {
	unsigned short *palette;
	unsigned int i;
	unsigned char *p;

	GetDIBits(hdcMem, hbmp, 0, height, NULL, bmInfo, DIB_PAL_COLORS);
	data = (unsigned char *)ckalloc(bmInfo->bmiHeader.biSizeImage);
	data = ckalloc(bmInfo->bmiHeader.biSizeImage);
	if (!data) {
	    /* printf("Failed to allocate data area for XImage.\n"); */
	    ret_image = NULL;
	    goto cleanup;
	}
	ret_image = XCreateImage(display, NULL, 8, ZPixmap, 0, (char *) data,
		width, height, 8, (int) width);
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444







-
+







	p = data;
	palette = (unsigned short *) bmInfo->bmiColors;
	for (i = 0; i < bmInfo->bmiHeader.biSizeImage; i++, p++) {
	    *p = (unsigned char) palette[*p];
	}
    } else if (depth == 16) {
	GetDIBits(hdcMem, hbmp, 0, height, NULL, bmInfo, DIB_RGB_COLORS);
	data = (unsigned char *)ckalloc(bmInfo->bmiHeader.biSizeImage);
	data = ckalloc(bmInfo->bmiHeader.biSizeImage);
	if (!data) {
	    /* printf("Failed to allocate data area for XImage.\n"); */
	    ret_image = NULL;
	    goto cleanup;
	}
	ret_image = XCreateImage(display, NULL, 16, ZPixmap, 0, (char *) data,
		width, height, 16, 0 /* will be calc'ed from bitmap_pad */);
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470







-
+







	    ckfree(ret_image->data);
	    ckfree(ret_image);
	    ret_image = NULL;
	    goto cleanup;
	}
    } else {
	GetDIBits(hdcMem, hbmp, 0, height, NULL, bmInfo, DIB_RGB_COLORS);
	data = (unsigned char *)ckalloc(width * height * 4);
	data = ckalloc(width * height * 4);
	if (!data) {
	    /* printf("Failed to allocate data area for XImage.\n"); */
	    ret_image = NULL;
	    goto cleanup;
	}
	ret_image = XCreateImage(display, NULL, 32, ZPixmap, 0, (char *) data,
		width, height, 0, (int) width * 4);
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493







-
+







	     * can likely be optimized for that. -- hobbs
	     */

	    unsigned char *smallBitData, *smallBitBase, *bigBitData;
	    unsigned int byte_width, h, w;

	    byte_width = ((width * 3 + 3) & ~(unsigned)3);
	    smallBitBase = (unsigned char *)ckalloc(byte_width * height);
	    smallBitBase = ckalloc(byte_width * height);
	    if (!smallBitBase) {
		ckfree(ret_image->data);
		ckfree(ret_image);
		ret_image = NULL;
		goto cleanup;
	    }
	    smallBitData = smallBitBase;
582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594







-
+







    unsigned long plane_mask,
    int	format)
{
    TkWinDrawable *twdPtr = (TkWinDrawable *)d;
    XImage *imagePtr;
    HDC dc;

    LastKnownRequestProcessed(display)++;
    display->request++;

    if (twdPtr == NULL) {
	/*
	 * Avoid unmapped windows or bad drawables
	 */

	return NULL;
611
612
613
614
615
616
617
618
619


620
621
622
623
624
625
626
609
610
611
612
613
614
615


616
617
618
619
620
621
622
623
624







-
-
+
+







	COLORREF pixel;

	dc = TkWinGetDrawableDC(display, d, &state);

	imagePtr = XCreateImage(display, NULL, 32, format, 0, NULL,
		width, height, 32, 0);
	size = imagePtr->bytes_per_line * imagePtr->height;
	imagePtr->data = (char *)ckalloc(size);
	memset(imagePtr->data, 0, size);
	imagePtr->data = ckalloc(size);
	ZeroMemory(imagePtr->data, size);

	for (yy = 0; yy < height; yy++) {
	    for (xx = 0; xx < width; xx++) {
		pixel = GetPixel(dc, x+(int)xx, y+(int)yy);
		if (pixel == CLR_INVALID) {
		    break;
		}
658
659
660
661
662
663
664
665

666
667
668
669
670
671
672
656
657
658
659
660
661
662

663
664
665
666
667
668
669
670







-
+








	    TkpDisplayWarning(errMsg, "XGetImage Failure");
	    return NULL;
	}

	imagePtr = XCreateImage(display, NULL, 1, XYBitmap, 0, NULL,
		width, height, 32, 0);
	imagePtr->data = (char *)ckalloc(imagePtr->bytes_per_line * imagePtr->height);
	imagePtr->data = ckalloc(imagePtr->bytes_per_line * imagePtr->height);

	dc = GetDC(NULL);

	GetDIBits(dc, twdPtr->bitmap.handle, 0, height, NULL,
		infoPtr, DIB_RGB_COLORS);

	infoPtr->bmiHeader.biSize		= sizeof(BITMAPINFOHEADER);

Changes to win/tkWinInit.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkWinInit.c --
 *
 *	This file contains Windows-specific interpreter initialization
 *	functions.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkWinInt.h"

33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
33
34
35
36
37
38
39

40

41
42


43

44
45
46
47
48
49
50







-
+
-


-
-

-








int
TkpInit(
    Tcl_Interp *interp)
{
    /*
     * This is necessary for static initialization, and is ok otherwise
     * because TkWinXInit flips a static bit to do its work just once. Also,
     * because TkWinXInit flips a static bit to do its work just once.
     * initialize printing and systray API's here.
     */

    WinIcoInit(interp);
    Winprint_Init(interp);
    TkWinXInit(Tk_GetHINSTANCE());
    Icu_Init(interp);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetAppName --
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







-
+







 */

void
TkpGetAppName(
    Tcl_Interp *interp,
    Tcl_DString *namePtr)	/* A previously initialized Tcl_DString. */
{
    Tcl_Size argc, namelength;
    int argc, namelength;
    const char **argv = NULL, *name, *p;

    name = Tcl_GetVar2(interp, "argv0", NULL, TCL_GLOBAL_ONLY);
    namelength = -1;
    if (name != NULL) {
	Tcl_SplitPath(name, &argc, &argv);
	if (argc > 0) {
123
124
125
126
127
128
129
130

131
132
133

134
135

136
137
138
139
140
141
142
143
144

145
146
147
148
149
150

151
152
153
154
155


156
157
158

159
160
161
162
163
164
165
119
120
121
122
123
124
125

126
127
128

129
130

131
132
133
134
135
136
137
138
139

140
141
142
143
144
145

146
147
148
149


150
151
152
153

154
155
156
157
158
159
160
161







-
+


-
+

-
+








-
+





-
+



-
-
+
+


-
+







#define TK_MAX_WARN_LEN 1024
    WCHAR titleString[TK_MAX_WARN_LEN];
    WCHAR *msgString; /* points to titleString, just after title, leaving space for ": " */
    int len; /* size of title, including terminating NULL */

    /* If running on Cygwin and we have a stderr channel, use it. */
#if !defined(STATIC_BUILD)
	if (tclStubsPtr->tcl_CreateFileHandler) {
	if (tclStubsPtr->reserved9) {
	Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
	if (errChannel) {
	    Tcl_WriteChars(errChannel, title, TCL_INDEX_NONE);
	    Tcl_WriteChars(errChannel, title, -1);
	    Tcl_WriteChars(errChannel, ": ", 2);
	    Tcl_WriteChars(errChannel, msg, TCL_INDEX_NONE);
	    Tcl_WriteChars(errChannel, msg, -1);
	    Tcl_WriteChars(errChannel, "\n", 1);
	    return;
	}
    }
#endif /* !STATIC_BUILD */

    len = MultiByteToWideChar(CP_UTF8, 0, title, -1, titleString, TK_MAX_WARN_LEN);
    msgString = &titleString[len + 1];
    titleString[TK_MAX_WARN_LEN - 1] = '\0';
    titleString[TK_MAX_WARN_LEN - 1] = L'\0';
    MultiByteToWideChar(CP_UTF8, 0, msg, -1, msgString, (TK_MAX_WARN_LEN - 1) - len);
    /*
     * Truncate MessageBox string if it is too long to not overflow the screen
     * and cause possible oversized window error.
     */
    if (titleString[TK_MAX_WARN_LEN - 1] != '\0') {
    if (titleString[TK_MAX_WARN_LEN - 1] != L'\0') {
	memcpy(titleString + (TK_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR));
    }
    if (IsDebuggerPresent()) {
	titleString[len - 1] = ':';
	titleString[len] = ' ';
	titleString[len - 1] = L':';
	titleString[len] = L' ';
	OutputDebugStringW(titleString);
    } else {
	titleString[len - 1] = '\0';
	titleString[len - 1] = L'\0';
	MessageBoxW(NULL, msgString, titleString,
		MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL
		| MB_SETFOREGROUND | MB_TOPMOST);
    }
}

/*
178
179
180
181
182
183
184
185
186


187

188

189
190

191
192

193
194
195
196

197
198
199
200


201
202
203
204


205
206



207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
174
175
176
177
178
179
180


181
182
183
184
185
186
187

188
189

190
191
192
193

194
195
196


197
198
199
200


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223







-
-
+
+

+

+

-
+

-
+



-
+


-
-
+
+


-
-
+
+


+
+
+







+








 * ----------------------------------------------------------------------
 */

Tcl_Obj*
TkWin32ErrorObj(
    HRESULT hrError)
{
    LPWSTR lpBuffer = NULL, p = NULL;
    WCHAR  sBuffer[30];
    LPTSTR lpBuffer = NULL, p = NULL;
    TCHAR  sBuffer[30];
    Tcl_Obj* errPtr = NULL;
#ifdef _UNICODE
    Tcl_DString ds;
#endif

    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
	    | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)hrError,
	    LANG_NEUTRAL, (LPWSTR)&lpBuffer, 0, NULL);
	    LANG_NEUTRAL, (LPTSTR)&lpBuffer, 0, NULL);

    if (lpBuffer == NULL) {
	lpBuffer = sBuffer;
	wsprintfW(sBuffer, L"Error Code: %08lX", hrError);
	wsprintf(sBuffer, TEXT("Error Code: %08lX"), hrError);
    }

    if ((p = wcsrchr(lpBuffer, '\r')) != NULL) {
	*p = '\0';
    if ((p = _tcsrchr(lpBuffer, TEXT('\r'))) != NULL) {
	*p = TEXT('\0');
    }

    Tcl_DStringInit(&ds);
    Tcl_WCharToUtfDString(lpBuffer, wcslen(lpBuffer), &ds);
#ifdef _UNICODE
    Tcl_WinTCharToUtf(lpBuffer, (int)wcslen(lpBuffer) * sizeof (WCHAR), &ds);
    errPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
    Tcl_DStringFree(&ds);
#else
    errPtr = Tcl_NewStringObj(lpBuffer, (int)strlen(lpBuffer));
#endif /* _UNICODE */

    if (lpBuffer != sBuffer) {
	LocalFree((HLOCAL)lpBuffer);
    }

    return errPtr;
}


/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinInt.h.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15







-
+







/*
 * tkWinInt.h --
 *
 *	This file contains declarations that are shared among the
 *	Windows-specific parts of Tk, but aren't used by the rest of Tk.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 Scriptics Corporation.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TKWININT
#define _TKWININT
113
114
115
116
117
118
119
120
121


122
123
124
125
126
127
128
113
114
115
116
117
118
119


120
121
122
123
124
125
126
127
128







-
-
+
+








#define TkWinGetPalette(colormap) (((TkWinColormap *) colormap)->palette)

/*
 * The following macros define the class names for Tk Window types.
 */

#define TK_WIN_TOPLEVEL_CLASS_NAME L"TkTopLevel"
#define TK_WIN_CHILD_CLASS_NAME L"TkChild"
#define TK_WIN_TOPLEVEL_CLASS_NAME TEXT("TkTopLevel")
#define TK_WIN_CHILD_CLASS_NAME TEXT("TkChild")

/*
 * The following variable is a translation table between X gc functions and
 * Win32 raster and BitBlt op modes.
 */

MODULE_SCOPE const int tkpWinRopModes[];
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
138
139
140
141
142
143
144



145
146
147
148
149
150
151







-
-
-








/*
 * Internal functions used by more than one source file.
 */

#include "tkIntPlatDecls.h"

#ifdef __cplusplus
extern "C" {
#endif
/*
 * Special proc needed as tsd accessor function between
 * tkWinX.c:GenerateXEvent and tkWinClipboard.c:UpdateClipboard
 */

MODULE_SCOPE void TkWinUpdatingClipboard(int mode);

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

248

249







250
251
252
253
254
255
256
257
258

259

260







261
262
263
264
265
266
267
268
269
270
271
272
273
274
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202




























203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255




256







-















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













+

+

+
+
+
+
+
+
+









+

+

+
+
+
+
+
+
+









-
-
-
-


/*
 * Values returned by TkWinGetPlatformTheme.
 */

#define TK_THEME_WIN_CLASSIC    1
#define TK_THEME_WIN_XP         2
#define TK_THEME_WIN_VISTA      3

/*
 * The following is implemented in tkWinWm and used by tkWinEmbed.c
 */

MODULE_SCOPE void		TkpWinToplevelWithDraw(TkWindow *winPtr);
MODULE_SCOPE void		TkpWinToplevelIconify(TkWindow *winPtr);
MODULE_SCOPE void		TkpWinToplevelDeiconify(TkWindow *winPtr);
MODULE_SCOPE long		TkpWinToplevelIsControlledByWm(TkWindow *winPtr);
MODULE_SCOPE long		TkpWinToplevelMove(TkWindow *winPtr, int x, int y);
MODULE_SCOPE long		TkpWinToplevelOverrideRedirect(TkWindow *winPtr,
			    int reqValue);
MODULE_SCOPE void		TkpWinToplevelDetachWindow(TkWindow *winPtr);
MODULE_SCOPE int		TkpWmGetState(TkWindow *winPtr);

MODULE_SCOPE int		TkTranslateWinEvent(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam, LRESULT *result);
MODULE_SCOPE void		TkWinPointerEvent(HWND hwnd, int x, int y);

/*
 * The following is implemented in tkWinPointer.c and also used in tkWinWindow.c
 */

MODULE_SCOPE void		TkSetCursorPos(int x, int y);

/*
 * The following is implemented in tkWinSysTray.c
 */

MODULE_SCOPE  int       WinIcoInit (Tcl_Interp* interp);

/*
 * The following is implemented in tkWinGDI.c
 */

MODULE_SCOPE  int       Winprint_Init(Tcl_Interp* interp);

/*
 * The following is implemented in tkWinSysTray.c
 */

MODULE_SCOPE  int       WinIcoInit (Tcl_Interp* interp);

/*
 * Common routines used in Windows implementation
 */
MODULE_SCOPE Tcl_Obj *	        TkWin32ErrorObj(HRESULT hrError);


/*
 * The following functions are not present in old versions of Windows
 * API headers but are used in the Tk source to ensure 64bit
 * compatibility.
 */

#ifndef GetClassLongPtr
#   define GetClassLongPtrA	GetClassLongA
#   define GetClassLongPtrW	GetClassLongW
#   define SetClassLongPtrA	SetClassLongA
#   define SetClassLongPtrW	SetClassLongW
#   ifdef UNICODE
#	define GetClassLongPtr	GetClassLongPtrW
#	define SetClassLongPtr	SetClassLongPtrW
#   else
#	define GetClassLongPtr	GetClassLongPtrA
#	define SetClassLongPtr	SetClassLongPtrA
#   endif /* !UNICODE */
#endif /* !GetClassLongPtr */
#ifndef GCLP_HICON
#   define GCLP_HICON		GCL_HICON
#endif /* !GCLP_HICON */
#ifndef GCLP_HICONSM
#   define GCLP_HICONSM		(-34)
#endif /* !GCLP_HICONSM */

#ifndef GetWindowLongPtr
#   define GetWindowLongPtrA	GetWindowLongA
#   define GetWindowLongPtrW	GetWindowLongW
#   define SetWindowLongPtrA	SetWindowLongA
#   define SetWindowLongPtrW	SetWindowLongW
#   ifdef UNICODE
#	define GetWindowLongPtr	GetWindowLongPtrW
#	define SetWindowLongPtr	SetWindowLongPtrW
#   else
#	define GetWindowLongPtr	GetWindowLongPtrW
#	define SetWindowLongPtr	SetWindowLongPtrW
#   endif /* !UNICODE */
#endif /* !GetWindowLongPtr */
#ifndef GWLP_WNDPROC
#define GWLP_WNDPROC		GWL_WNDPROC
#define GWLP_HINSTANCE		GWL_HINSTANCE
#define GWLP_HWNDPARENT		GWL_HWNDPARENT
#define GWLP_USERDATA		GWL_USERDATA
#define GWLP_ID			GWL_ID
#endif /* !GWLP_WNDPROC */

#ifdef __cplusplus
}
#endif

#endif /* _TKWININT */

Changes to win/tkWinKey.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58






























59
60
61
62
63
64





65
66
67
68
69
70
71
72
1
2
3
4
5
6

7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23

24
25
26
27






























28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58





59
60
61
62
63

64
65
66
67
68
69
70






-
+






-










-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
-







/*
 * tkWinKey.c --
 *
 *	This file contains X emulation routines for keyboard related
 *	functions.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "X11/XF86keysym.h"

/*
 * The keymap table holds mappings of Windows keycodes to X keysyms. If
 * Windows ever comes along and changes the value of their keycodes, this will
 * break all kinds of things. However, this table lookup is much faster than
 * the alternative, in which we walked a list of keycodes looking for a match.
 * Since this lookup is performed for every Windows keypress event, it seems
 * like a worthwhile improvement to use the table.
 */

#define MAX_KEYCODE 183 /* VK_LAUNCH_APP2 is the last entry in our table below */
#define MAX_KEYCODE 179 /* VK_MEDIA_PLAY_PAUSE is the last entry in our table below */
/* cf. https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx */

static const KeySym keymap[] = {
    NoSymbol, NoSymbol, NoSymbol, XK_Cancel, NoSymbol, /*0 0x0*/
    NoSymbol, NoSymbol, NoSymbol, XK_BackSpace, XK_Tab, /*5 0x5*/
    NoSymbol, NoSymbol, XK_Clear, XK_Return, NoSymbol, /*10 0xA*/
    NoSymbol, XK_Shift_L, XK_Control_L, XK_Alt_L, XK_Pause, /*15 0xE*/
    XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*20 0x14*/
    NoSymbol, NoSymbol, XK_Escape, NoSymbol, NoSymbol, /*25 0x19*/
    NoSymbol, NoSymbol, XK_space, XK_Prior, XK_Next, /*30 0x1E*/
    XK_End, XK_Home, XK_Left, XK_Up, XK_Right, /*35 0x23*/
    XK_Down, XK_Select, XK_Print, XK_Execute, NoSymbol, /*40 0x28*/
    XK_Insert, XK_Delete, XK_Help, NoSymbol, NoSymbol, /*45 0x2D*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*50 0x32*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*55 0x37*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*60 0x3C*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*65 0x41*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*70 0x46*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*75 0x4B*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*80 0x50*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*85 0x55*/
    NoSymbol, XK_Super_L, XK_Super_R, XK_Menu, NoSymbol, /*90 0x5A*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*95 0x5F*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*100 0x64*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*105 0x69*/
    NoSymbol, NoSymbol, XK_F1, XK_F2, XK_F3, /*110 0x6E*/
    XK_F4, XK_F5, XK_F6, XK_F7, XK_F8, /*115 0x73*/
    XK_F9, XK_F10, XK_F11, XK_F12, XK_F13, /*120 0x78*/
    XK_F14, XK_F15, XK_F16, XK_F17, XK_F18, /*125 0x7D*/
    XK_F19, XK_F20, XK_F21, XK_F22, XK_F23, /*130 0x82*/
    XK_F24, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*135 0x87*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, XK_Num_Lock, /*140 0x8C*/
    XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*145 0x91*/
    NoSymbol, NoSymbol, NoSymbol, XK_Cancel, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, XK_BackSpace, XK_Tab,
    NoSymbol, NoSymbol, XK_Clear, XK_Return, NoSymbol,
    NoSymbol, XK_Shift_L, XK_Control_L, XK_Alt_L, XK_Pause,
    XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, XK_Escape, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, XK_space, XK_Prior, XK_Next,
    XK_End, XK_Home, XK_Left, XK_Up, XK_Right,
    XK_Down, XK_Select, XK_Print, XK_Execute, NoSymbol,
    XK_Insert, XK_Delete, XK_Help, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, XK_Win_L, XK_Win_R, XK_App, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, XK_F1, XK_F2, XK_F3,
    XK_F4, XK_F5, XK_F6, XK_F7, XK_F8,
    XK_F9, XK_F10, XK_F11, XK_F12, XK_F13,
    XK_F14, XK_F15, XK_F16, XK_F17, XK_F18,
    XK_F19, XK_F20, XK_F21, XK_F22, XK_F23,
    XK_F24, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, XK_Num_Lock,
    XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol, NoSymbol,
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*150 0x96*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*155 0x9B*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*160 0xA0*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*165 0xA5*/
    NoSymbol, NoSymbol, NoSymbol, XF86XK_AudioMute, XF86XK_AudioLowerVolume, /*170 0xAA*/
    XF86XK_AudioRaiseVolume, XF86XK_AudioNext, XF86XK_AudioPrev, XF86XK_AudioStop, XF86XK_AudioPlay, /*175 0xAF*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*155 0x9b*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*160 0xa0*/
    NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, /*165 0xa5*/
    NoSymbol, NoSymbol, NoSymbol, XK_XF86AudioMute, XK_XF86AudioLowerVolume, /*170 0xaa*/
    XK_XF86AudioRaiseVolume, XK_XF86AudioNext, XK_XF86AudioPrev, XK_XF86AudioStop, XK_XF86AudioPlay  /*175 0xaf*/
    XF86XK_Mail, XF86XK_AudioMedia, XF86XK_Launch0, XF86XK_Launch1  /*180 0xB4*/
};

/*
 * Prototypes for local functions defined in this file:
 */

static KeySym		KeycodeToKeysym(unsigned int keycode,
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101

102
103
104
105
106
107
108



109
110
111
112
113

114
115
116

117
118
119
120
121
122
123
124
125
126
127
128

129
130
131
132
133
134
135
84
85
86
87
88
89
90

91
92
93
94
95
96
97

98
99
100
101
102




103
104
105
106
107
108
109

110
111
112

113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+






-

+



-
-
-
-
+
+
+




-
+


-
+











-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

const char *
TkpGetString(
    TCL_UNUSED(TkWindow *),		/* Window where event occurred: needed to get
    TkWindow *winPtr,		/* Window where event occurred: needed to get
				 * input context. */
    XEvent *eventPtr,		/* X keyboard event. */
    Tcl_DString *dsPtr)		/* Uninitialized or empty string to hold
				 * result. */
{
    XKeyEvent *keyEv = &eventPtr->xkey;
    int len;
    char buf[6];
    int len;

    Tcl_DStringInit(dsPtr);
    if (keyEv->send_event == -1) {
	TkKeyEvent *ev = (TkKeyEvent *)keyEv;
	if (ev->nbytes > 0) {
	    (void)Tcl_ExternalToUtfDString(TkWinGetKeyInputEncoding(),
		    ev->trans_chars, ev->nbytes, dsPtr);
	if (keyEv->nbytes > 0) {
	    Tcl_ExternalToUtfDString(TkWinGetKeyInputEncoding(),
		    keyEv->trans_chars, keyEv->nbytes, dsPtr);
	}
    } else if (keyEv->send_event == -3) {

	/*
	 * Special case for WM_UNICHAR and win2000 multilingual IME input
	 * Special case for WM_UNICHAR and win2000 multi-lingal IME input
	 */

	len = Tcl_UniCharToUtf(keyEv->keycode, buf);
	len = TkUniCharToUtf(keyEv->keycode, buf);
	Tcl_DStringAppend(dsPtr, buf, len);
    } else {
	/*
	 * This is an event generated from generic code. It has no nchars or
	 * trans_chars members.
	 */

	KeySym keysym = KeycodeToKeysym(keyEv->keycode, keyEv->state, 0);

	if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256))
		|| (keysym == XK_Return) || (keysym == XK_Tab)) {
	    len = Tcl_UniCharToUtf(keysym & 255, buf);
	    len = Tcl_UniCharToUtf((Tcl_UniChar) (keysym & 255), buf);
	    Tcl_DStringAppend(dsPtr, buf, len);
	}
    }
    return Tcl_DStringValue(dsPtr);
}

/*
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
144
145
146
147
148
149
150

151
152















153
154
155
156
157
158
159







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *	None.
 *
 *----------------------------------------------------------------------
 */

KeySym
XKeycodeToKeysym(
    TCL_UNUSED(Display *),
    Display *display,
    unsigned int keycode,
    int index)
{
    int state = 0;

    if (index & 0x01) {
	state |= ShiftMask;
    }
    return KeycodeToKeysym(keycode, state, 0);
}

KeySym
XkbKeycodeToKeysym(
    TCL_UNUSED(Display *),
    unsigned int keycode,
    TCL_UNUSED(int),
    int index)
{
    int state = 0;

    if (index & 0x01) {
	state |= ShiftMask;
    }
200
201
202
203
204
205
206
207
208


209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225

226
227
228
229
230
231
232
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206

207
208
209
210
211
212
213
214







-
-
+
+













-
+


-
+







KeycodeToKeysym(
    unsigned int keycode,
    int state,
    int noascii)
{
    BYTE keys[256];
    int result, deadkey, shift;
    WCHAR buf[4];
    unsigned int scancode = MapVirtualKeyW(keycode, 0);
    TCHAR buf[4];
    unsigned int scancode = MapVirtualKey(keycode, 0);

    /*
     * Do not run keycodes of lock keys through ToUnicode(). One of ToUnicode()'s
     * side effects is to handle the lights on the keyboard, and we don't want
     * to mess that up.
     */

    if (noascii || keycode == VK_CAPITAL || keycode == VK_SCROLL ||
	    keycode == VK_NUMLOCK) {
	goto skipToUnicode;
    }

    /*
     * Use MapVirtualKeyW() to detect some dead keys.
     * Use MapVirtualKey() to detect some dead keys.
     */

    if (MapVirtualKeyW(keycode, 2) > 0x7fffUL) {
    if (MapVirtualKey(keycode, 2) > 0x7fffUL) {
	return XK_Multi_key;
    }

    /*
     * Set up a keyboard with correct modifiers
     */

275
276
277
278
279
280
281
282

283
284
285

286
287
288
289
290
291
292
257
258
259
260
261
262
263

264
265
266

267
268
269
270
271
272
273
274







-
+


-
+







	 * This was a dead char, and there were one previously remembered by
	 * the keyboard. Call ToUnicode() again with proper parameters to
	 * restore it.
	 *
	 * Get information about the old char
	 */

	deadkey = VkKeyScanW(buf[0]);
	deadkey = VkKeyScan(buf[0]);
	shift = deadkey >> 8;
	deadkey &= 255;
	scancode = MapVirtualKeyW(deadkey, 0);
	scancode = MapVirtualKey(deadkey, 0);

	/*
	 * Set up a keyboard with proper modifier keys
	 */

	memset(keys, 0, 256);
	if (shift & 1) {
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
433
434
435
436
437
438
439

440

441
442
443
444
445
446
447







-
+
-







TkpInitKeymapInfo(
    TkDisplay *dispPtr)		/* Display for which to recompute keymap
				 * information. */
{
    XModifierKeymap *modMapPtr;
    KeyCode *codePtr;
    KeySym keysym;
    int count, i, max;
    int count, i, j, max, arraySize;
    Tcl_Size j, arraySize;
#define KEYCODE_ARRAY_SIZE 20

    dispPtr->bindInfoStale = 0;
    modMapPtr = XGetModifierMapping(dispPtr->display);

    /*
     * Check the keycodes associated with the Lock modifier. If any of them is
517
518
519
520
521
522
523
524

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

541
542
543
544
545
546
547
548


549
550
551

552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568

569
570
571
572
573
574
575
498
499
500
501
502
503
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527


528
529
530
531

532
533
534
535
536
537
538
539
540
541
542

543
544
545
546
547
548

549
550
551
552
553
554
555
556







-
+















-
+






-
-
+
+


-
+










-
+





-
+







     */

    if (dispPtr->modKeyCodes != NULL) {
	ckfree(dispPtr->modKeyCodes);
    }
    dispPtr->numModKeyCodes = 0;
    arraySize = KEYCODE_ARRAY_SIZE;
    dispPtr->modKeyCodes = (KeyCode *)ckalloc(KEYCODE_ARRAY_SIZE * sizeof(KeyCode));
    dispPtr->modKeyCodes = ckalloc(KEYCODE_ARRAY_SIZE * sizeof(KeyCode));
    for (i = 0, codePtr = modMapPtr->modifiermap; i < max; i++, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}

	/*
	 * Make sure that the keycode isn't already in the array.
	 */

	for (j = 0; j < dispPtr->numModKeyCodes; j++) {
	    if (dispPtr->modKeyCodes[j] == *codePtr) {
		goto nextModCode;
	    }
	}
	if (dispPtr->numModKeyCodes >= arraySize) {
	    KeyCode *newKey;
	    KeyCode *new;

	    /*
	     * Ran out of space in the array; grow it.
	     */

	    arraySize *= 2;
	    newKey = (KeyCode *)ckalloc(arraySize * sizeof(KeyCode));
	    memcpy(newKey, dispPtr->modKeyCodes,
	    new = ckalloc(arraySize * sizeof(KeyCode));
	    memcpy(new, dispPtr->modKeyCodes,
		    dispPtr->numModKeyCodes * sizeof(KeyCode));
	    ckfree(dispPtr->modKeyCodes);
	    dispPtr->modKeyCodes = newKey;
	    dispPtr->modKeyCodes = new;
	}
	dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr;
	dispPtr->numModKeyCodes++;
	nextModCode: continue;
    }
    XFreeModifiermap(modMapPtr);
}

/*
 * When mapping from a keysym to a keycode, need information about the
 * modifier state that should be used so that when they call XkbKeycodeToKeysym
 * modifier state that should be used so that when they call XKeycodeToKeysym
 * taking into account the xkey.state, they will get back the original keysym.
 */

void
TkpSetKeycodeAndState(
    TCL_UNUSED(Tk_Window),
    Tk_Window tkwin,
    KeySym keySym,
    XEvent *eventPtr)
{
    int i;
    SHORT result;
    int shift;

587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582







-
+







    for (i = 0; i <= MAX_KEYCODE; i++) {
	if (keymap[i] == keySym) {
	    eventPtr->xkey.keycode = i;
	    return;
	}
    }
    if (keySym >= 0x20) {
	result = VkKeyScanW((WCHAR) keySym);
	result = VkKeyScan((TCHAR) keySym);
	if (result != -1) {
	    shift = result >> 8;
	    if (shift & 1)
		eventPtr->xkey.state |= ShiftMask;
	    if (shift & 2)
		eventPtr->xkey.state |= ControlMask;
	    if (shift & 4)
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
635







-
+




















-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

KeyCode
XKeysymToKeycode(
    TCL_UNUSED(Display *),
    Display *display,
    KeySym keysym)
{
    int i;
    SHORT result;

    /*
     * We check our private map first for a virtual keycode, as VkKeyScan will
     * return values that don't map to X for the "extended" Syms. This may be
     * due to just casting problems below, but this works.
     */

    if (keysym == NoSymbol) {
	return 0;
    }
    for (i = 0; i <= MAX_KEYCODE; i++) {
	if (keymap[i] == keysym) {
	    return ((KeyCode) i);
	}
    }
    if (keysym >= 0x20) {
	result = VkKeyScanW((WCHAR) keysym);
	result = VkKeyScan((TCHAR) keysym);
	if (result != -1) {
	    return (KeyCode) (result & 0xff);
	}
    }

    return 0;
}
667
668
669
670
671
672
673
674

675
676

677
678
679

680
681
682
683
684
685
686
648
649
650
651
652
653
654

655
656

657
658
659

660
661
662
663
664
665
666
667







-
+

-
+


-
+







 *	Allocates a new modifier map data structure.
 *
 *----------------------------------------------------------------------
 */

XModifierKeymap	*
XGetModifierMapping(
    TCL_UNUSED(Display *))
    Display *display)
{
    XModifierKeymap *map = (XModifierKeymap *)ckalloc(sizeof(XModifierKeymap));
    XModifierKeymap *map = ckalloc(sizeof(XModifierKeymap));

    map->max_keypermod = 1;
    map->modifiermap = (KeyCode *)ckalloc(sizeof(KeyCode) * 8);
    map->modifiermap = ckalloc(sizeof(KeyCode) * 8);
    map->modifiermap[ShiftMapIndex] = VK_SHIFT;
    map->modifiermap[LockMapIndex] = VK_CAPITAL;
    map->modifiermap[ControlMapIndex] = VK_CONTROL;
    map->modifiermap[Mod1MapIndex] = VK_NUMLOCK;
    map->modifiermap[Mod2MapIndex] = VK_MENU;
    map->modifiermap[Mod3MapIndex] = VK_SCROLL;
    map->modifiermap[Mod4MapIndex] = 0;
728
729
730
731
732
733
734
735

736
737
738
739
740
741
742
709
710
711
712
713
714
715

716
717
718
719
720
721
722
723







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

KeySym
XStringToKeysym(
    TCL_UNUSED(_Xconst char *))
    _Xconst char *string)
{
    return NoSymbol;
}

/*
 *----------------------------------------------------------------------
 *
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767
768
769
732
733
734
735
736
737
738

739
740
741
742
743
744
745
746
747
748
749
750







-
+











 *	None.
 *
 *----------------------------------------------------------------------
 */

char *
XKeysymToString(
    TCL_UNUSED(KeySym))
    KeySym keysym)
{
    return NULL;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinMenu.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


22
23
24
25
26
27
28
29
30






-
-
+
+













-
-
+
+







/*
 * tkWinMenu.c --
 *
 *	This module implements the Windows platform-specific features of
 *	menus.
 *
 * Copyright © 1996-1998 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#define OEMRESOURCE
#include "tkWinInt.h"
#include "tkMenu.h"

/*
 * The class of the window for popup menus.
 */

#define MENU_CLASS_NAME			L"MenuWindowClass"
#define EMBEDDED_MENU_CLASS_NAME	L"EmbeddedMenuWindowClass"
#define MENU_CLASS_NAME			TEXT("MenuWindowClass")
#define EMBEDDED_MENU_CLASS_NAME	TEXT("EmbeddedMenuWindowClass")

/*
 * Used to align a windows bitmap inside a rectangle
 */

#define ALIGN_BITMAP_LEFT	0x00000001
#define ALIGN_BITMAP_RIGHT	0x00000002
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







static int indicatorDimensions[2];
				/* The dimensions of the indicator space in a
				 * menu entry. Calculated at init time to save
				 * time. */

static BOOL showMenuAccelerators;

typedef struct {
typedef struct ThreadSpecificData {
    int inPostMenu;		/* We cannot be re-entrant like X Windows. */
    WORD lastCommandID;		/* The last command ID we allocated. */
    HWND menuHWND;		/* A window to service popup-menu messages
				 * in. */
    HWND embeddedMenuHWND;	/* A window to service embedded menu
				 * messages */
    int oldServiceMode;		/* Used while processing a menu; we need to
172
173
174
175
176
177
178
179



180
181

182
183
184
185
186
187
188
172
173
174
175
176
177
178

179
180
181
182

183
184
185
186
187
188
189
190







-
+
+
+

-
+







			    const Tk_FontMetrics *fmPtr,
			    int *widthPtr, int *heightPtr);
static void		GetTearoffEntryGeometry(TkMenu *menuPtr,
			    TkMenuEntry *mePtr, Tk_Font tkfont,
			    const Tk_FontMetrics *fmPtr, int *widthPtr,
			    int *heightPtr);
static int		GetNewID(TkMenuEntry *mePtr, WORD *menuIDPtr);
static Tcl_ObjCmdProc TkWinMenuKeyObjCmd;
static int		TkWinMenuKeyObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		MenuSelectEvent(TkMenu *menuPtr);
static void		ReconfigureWindowsMenu(void *clientData);
static void		ReconfigureWindowsMenu(ClientData clientData);
static void		RecursivelyClearActiveMenu(TkMenu *menuPtr);
static void		SetDefaults(int firstTime);
static LRESULT CALLBACK	TkWinMenuProc(HWND hwnd, UINT message, WPARAM wParam,
			    LPARAM lParam);
static LRESULT CALLBACK	TkWinEmbeddedMenuProc(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam);

227
228
229
230
231
232
233
234

235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257


258
259
260
261
262
263
264
229
230
231
232
233
234
235

236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257


258
259
260
261
262
263
264
265
266







-
+





-
+















-
-
+
+







 */

static int
GetNewID(
    TkMenuEntry *mePtr,		/* The menu we are working with. */
    WORD *menuIDPtr)		/* The resulting id. */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    WORD curID = tsdPtr->lastCommandID;

    while (1) {
	Tcl_HashEntry *commandEntryPtr;
	int isNew;
	int new;

	/*
	 * Try the next ID number, taking care to wrap rather than stray
	 * into the system menu IDs.  [Bug 3235256]
	 */
	if (++curID >= 0xF000) {
	    curID = 1;
	}

	/* Return error when we've checked all IDs without success. */
	if (curID == tsdPtr->lastCommandID) {
	    return TCL_ERROR;
	}

	commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
		INT2PTR(curID), &isNew);
	if (isNew) {
		INT2PTR(curID), &new);
	if (new) {
	    Tcl_SetHashValue(commandEntryPtr, mePtr);
	    *menuIDPtr = curID;
	    tsdPtr->lastCommandID = curID;
	    return TCL_OK;
	}
    }
}
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295







-
+







 *----------------------------------------------------------------------
 */

static void
FreeID(
    WORD commandID)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * If the menuHWND is NULL, this table has been finalized already.
     */

    if (tsdPtr->menuHWND != NULL) {
322
323
324
325
326
327
328
329

330
331
332
333
334
335

336
337
338
339
340
341
342
324
325
326
327
328
329
330

331
332
333
334
335
336

337
338
339
340
341
342
343
344







-
+





-
+







TkpNewMenu(
    TkMenu *menuPtr)		/* The common structure we are making the
				 * platform structure for. */
{
    HMENU winMenuHdl;
    Tcl_HashEntry *hashEntryPtr;
    int newEntry;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    winMenuHdl = CreatePopupMenu();
    if (winMenuHdl == NULL) {
    	Tcl_SetObjResult(menuPtr->interp, Tcl_NewStringObj(
		"No more menus can be allocated.", TCL_INDEX_NONE));
		"No more menus can be allocated.", -1));
	Tcl_SetErrorCode(menuPtr->interp, "TK", "MENU", "SYSTEM_RESOURCES", NULL);
    	return TCL_ERROR;
    }

    /*
     * We hash all of the HMENU's so that we can get their menu ptrs back when
     * dispatch messages.
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
370
371
372
373
374
375
376

377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398







-
+













-
+








void
TkpDestroyMenu(
    TkMenu *menuPtr)		/* The common menu structure */
{
    HMENU winMenuHdl = (HMENU) menuPtr->platformData;
    const char *searchName;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (menuPtr->menuFlags & MENU_RECONFIGURE_PENDING) {
	Tcl_CancelIdleCall(ReconfigureWindowsMenu, menuPtr);
    }

    if (winMenuHdl == NULL) {
	return;
    }

    if (menuPtr->menuFlags & MENU_SYSTEM_MENU) {
	TkMenuEntry *searchEntryPtr;
	Tcl_HashTable *tablePtr = TkGetMenuHashTable(menuPtr->interp);
	char *menuName = (char *)Tcl_GetHashKey(tablePtr,
	char *menuName = Tcl_GetHashKey(tablePtr,
		menuPtr->menuRefPtr->hashEntryPtr);

	/*
	 * Search for the menu in the menubar, if it is present, get the
	 * wrapper window associated with the toplevel and reset its
	 * system menu to the default menu.
	 */
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430







-
+







	/*
	 * Remove the menu from the menu hash table, then destroy the handle.
	 * If the menuHWND is NULL, this table has been finalized already.
	 */

	if (tsdPtr->menuHWND != NULL) {
	    Tcl_HashEntry *hashEntryPtr =
		Tcl_FindHashEntry(&tsdPtr->winMenuTable, winMenuHdl);
		Tcl_FindHashEntry(&tsdPtr->winMenuTable, (char *) winMenuHdl);

	    if (hashEntryPtr != NULL) {
		Tcl_DeleteHashEntry(hashEntryPtr);
	    }
	}
 	DestroyMenu(winMenuHdl);
    }
486
487
488
489
490
491
492
493

494
495
496

497
498
499

500
501
502

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539

540
541
542
543
544

545
546
547
548
549
550
551
488
489
490
491
492
493
494

495
496
497

498
499
500

501
502
503

504
505
506
507
508
509
510
511
512
513

514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

530
531
532

533
534
535
536
537
538

539
540
541
542
543

544
545
546
547
548
549
550
551







-
+


-
+


-
+


-
+









-
















-
+


-






-
+




-
+







GetEntryText(
    TkMenu *menuPtr,		/* The menu considered. */
    TkMenuEntry *mePtr)		/* A pointer to the menu entry. */
{
    char *itemText;

    if (mePtr->type == TEAROFF_ENTRY) {
	itemText = (char *)ckalloc(sizeof("(Tear-off)"));
	itemText = ckalloc(sizeof("(Tear-off)"));
	strcpy(itemText, "(Tear-off)");
    } else if (mePtr->imagePtr != NULL) {
	itemText = (char *)ckalloc(sizeof("(Image)"));
	itemText = ckalloc(sizeof("(Image)"));
	strcpy(itemText, "(Image)");
    } else if (mePtr->bitmapPtr != NULL) {
	itemText = (char *)ckalloc(sizeof("(Pixmap)"));
	itemText = ckalloc(sizeof("(Pixmap)"));
	strcpy(itemText, "(Pixmap)");
    } else if (mePtr->labelPtr == NULL || mePtr->labelLength == 0) {
	itemText = (char *)ckalloc(sizeof("( )"));
	itemText = ckalloc(sizeof("( )"));
	strcpy(itemText, "( )");
    } else {
	int i;
	const char *label = (mePtr->labelPtr == NULL) ? ""
		: Tcl_GetString(mePtr->labelPtr);
	const char *accel = ((menuPtr->menuType == MENUBAR) || (mePtr->accelPtr == NULL)) ? ""
		: Tcl_GetString(mePtr->accelPtr);
	const char *p, *next;
	Tcl_DString itemString;
	Tcl_UniChar ch = 0;

	/*
	 * We have to construct the string with an ampersand preceeding the
	 * underline character, and a tab seperating the text and the accel
	 * text. We have to be careful with ampersands in the string.
	 */

	Tcl_DStringInit(&itemString);

	for (p = label, i = 0; *p != '\0'; i++, p = next) {
	    if (i == mePtr->underline) {
		Tcl_DStringAppend(&itemString, "&", 1);
	    }
	    if (*p == '&') {
		Tcl_DStringAppend(&itemString, "&", 1);
	    }
	    next = p + Tcl_UtfToUniChar(p, &ch);
	    next = Tcl_UtfNext(p);
	    Tcl_DStringAppend(&itemString, p, (int) (next - p));
	}
	ch = 0;
	if (mePtr->accelLength > 0) {
	    Tcl_DStringAppend(&itemString, "\t", 1);
	    for (p = accel, i = 0; *p != '\0'; i++, p = next) {
		if (*p == '&') {
		    Tcl_DStringAppend(&itemString, "&", 1);
		}
		next = p + Tcl_UtfToUniChar(p, &ch);
		next = Tcl_UtfNext(p);
		Tcl_DStringAppend(&itemString, p, (int) (next - p));
	    }
	}

	itemText = (char *)ckalloc(Tcl_DStringLength(&itemString) + 1);
	itemText = ckalloc(Tcl_DStringLength(&itemString) + 1);
	strcpy(itemText, Tcl_DStringValue(&itemString));
	Tcl_DStringFree(&itemString);
    }
    return itemText;
}

/*
563
564
565
566
567
568
569
570

571
572

573
574
575
576

577
578
579
580
581
582
583
563
564
565
566
567
568
569

570
571

572
573
574
575

576
577
578
579
580
581
582
583







-
+

-
+



-
+







 *	if any need it.
 *
 *----------------------------------------------------------------------
 */

static void
ReconfigureWindowsMenu(
    void *clientData)	/* The menu we are rebuilding */
    ClientData clientData)	/* The menu we are rebuilding */
{
    TkMenu *menuPtr = (TkMenu *)clientData;
    TkMenu *menuPtr = clientData;
    TkMenuEntry *mePtr;
    HMENU winMenuHdl = (HMENU) menuPtr->platformData;
    char *itemText = NULL;
    LPCWSTR lpNewItem;
    const TCHAR *lpNewItem;
    UINT flags;
    UINT itemID;
    int i, count, systemMenu = 0, base;
    Tcl_DString translatedText;

    if (NULL == winMenuHdl) {
    	return;
605
606
607
608
609
610
611
612

613
614

615
616
617

618
619
620
621
622
623
624
605
606
607
608
609
610
611

612


613
614
615

616
617
618
619
620
621
622
623







-
+
-
-
+


-
+







	if ((menuPtr->menuType == MENUBAR) && (mePtr->type == TEAROFF_ENTRY)) {
	    continue;
	}

	itemText = GetEntryText(menuPtr, mePtr);
	if ((menuPtr->menuType == MENUBAR)
		|| (menuPtr->menuFlags & MENU_SYSTEM_MENU)) {
		Tcl_DStringInit(&translatedText);
	    Tcl_WinUtfToTChar(itemText, -1, &translatedText);
		Tcl_UtfToWCharDString(itemText, TCL_INDEX_NONE, &translatedText);
	    lpNewItem = (LPCWSTR) Tcl_DStringValue(&translatedText);
	    lpNewItem = (const TCHAR *) Tcl_DStringValue(&translatedText);
	    flags |= MF_STRING;
	} else {
	    lpNewItem = (LPCWSTR) mePtr;
	    lpNewItem = (LPCTSTR) mePtr;
	    flags |= MF_OWNERDRAW;
	}

	/*
	 * Set enabling and disabling correctly.
	 */

680
681
682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
679
680
681
682
683
684
685

686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704







-
+










-
+







			    & MENU_SYSTEM_MENU)) {
		Tcl_DString ds;
		TkMenuReferences *menuRefPtr;
		TkMenu *systemMenuPtr = mePtr->childMenuRefPtr->menuPtr;

		Tcl_DStringInit(&ds);
		Tcl_DStringAppend(&ds,
			Tk_PathName(menuPtr->mainMenuPtr->tkwin), TCL_INDEX_NONE);
			Tk_PathName(menuPtr->masterMenuPtr->tkwin), -1);
		Tcl_DStringAppend(&ds, ".system", 7);

		menuRefPtr = TkFindMenuReferences(menuPtr->interp,
			Tcl_DStringValue(&ds));

		Tcl_DStringFree(&ds);

		if ((menuRefPtr != NULL)
			&& (menuRefPtr->menuPtr != NULL)
			&& (menuPtr->parentTopLevelPtr != NULL)
			&& (systemMenuPtr->mainMenuPtr
			&& (systemMenuPtr->masterMenuPtr
				== menuRefPtr->menuPtr)) {
		    HMENU systemMenuHdl = (HMENU) systemMenuPtr->platformData;
		    HWND wrapper = TkWinGetWrapperWindow(menuPtr
			    ->parentTopLevelPtr);

		    if (wrapper != NULL) {
			DestroyMenu(systemMenuHdl);
713
714
715
716
717
718
719
720

721
722
723
724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763

764
765

766
767
768
769
770
771
772
773

774
775
776

777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
712
713
714
715
716
717
718

719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738
739
740
741
742
743
744
745

746



747
748
749
750
751
752
753
754
755
756
757
758

759
760

761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778
779
780
781







782
783
784
785
786
787
788







-
+











-
+














-
+
-
-
-












-
+

-
+







-
+



+








-
-
-
-
-
-
-







	    }
	    if (mePtr->childMenuRefPtr->menuPtr->menuFlags
		    & MENU_SYSTEM_MENU) {
		systemMenu++;
	    }
	}
	if (!systemMenu) {
	    InsertMenuW(winMenuHdl, 0xFFFFFFFF, flags, itemID, lpNewItem);
	    InsertMenu(winMenuHdl, 0xFFFFFFFF, flags, itemID, lpNewItem);
	}
	Tcl_DStringFree(&translatedText);
	if (itemText != NULL) {
	    ckfree(itemText);
	    itemText = NULL;
	}
    }


    if ((menuPtr->menuType == MENUBAR)
	    && (menuPtr->parentTopLevelPtr != NULL)) {
	HWND bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);
	HANDLE bar = TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr);

	if (bar) {
	    DrawMenuBar(bar);
	}
    }

    menuPtr->menuFlags &= ~(MENU_RECONFIGURE_PENDING);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostMenu --
 *
 *	Posts a menu on the screen so that the top left corner of the
 *	Posts a menu on the screen
 *      specified entry is located at the point (x, y) in screen coordinates.
 *      If the entry parameter is negative, the upper left corner of the
 *      menu itself is placed at the point.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The menu is posted and handled.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostMenu(
    TCL_UNUSED(Tcl_Interp *),
    Tcl_Interp *interp,
    TkMenu *menuPtr,
    int x, int y, Tcl_Size index)
    int x, int y)
{
    HMENU winMenuHdl = (HMENU) menuPtr->platformData;
    int result, flags;
    RECT noGoawayRect;
    POINT point;
    Tk_Window parentWindow = Tk_Parent(menuPtr->tkwin);
    int oldServiceMode = Tcl_GetServiceMode();
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    tsdPtr->inPostMenu++;

    CallPendingReconfigureImmediately(menuPtr);

    result = TkPreprocessMenu(menuPtr);
    if (result != TCL_OK) {
	tsdPtr->inPostMenu--;
	return result;
    }

    if (index >= menuPtr->numEntries) {
	index = menuPtr->numEntries - 1;
    }
    if (index >= 0) {
	y -= menuPtr->entries[index]->y;
    }

    /*
     * The post commands could have deleted the menu, which means
     * we are dead and should go away.
     */

    if (menuPtr->tkwin == NULL) {
	tsdPtr->inPostMenu--;
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
826
827
828
829
830
831
832

833
834
835
836
837
838
839



































































































840
841
842
843
844
845
846







-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    }

    TrackPopupMenu(winMenuHdl, flags, x, y, 0,
	    tsdPtr->menuHWND, &noGoawayRect);
    Tcl_SetServiceMode(oldServiceMode);

    GetCursorPos(&point);
    TkWinPointerEvent(NULL, point.x, point.y);
    Tk_PointerEvent(NULL, point.x, point.y);

    if (tsdPtr->inPostMenu) {
	tsdPtr->inPostMenu = 0;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpPostTearoffMenu --
 *
 *	Posts a tearoff menu on the screen so that the top left corner of the
 *      specified entry is located at the point (x, y) in screen coordinates.
 *      If the index parameter is negative, the upper left corner of the menu
 *      itself is placed at the point.  Adjusts the menu's position so that it
 *      fits on the screen, and maps and raises the menu.
 *
 * Results:
 *	Returns a standard Tcl Error.
 *
 * Side effects:
 *	The menu is posted.
 *
 *----------------------------------------------------------------------
 */

int
TkpPostTearoffMenu(
    TCL_UNUSED(Tcl_Interp *),		/* The interpreter of the menu */
    TkMenu *menuPtr,		/* The menu we are posting */
    int x, int y, Tcl_Size index)	/* The root X,Y coordinates where we are
				 * posting */
{
    int vRootX, vRootY, vRootWidth, vRootHeight;
    int result;

    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
    TkRecomputeMenu(menuPtr);
    result = TkPostCommand(menuPtr);
    if (result != TCL_OK) {
    	return result;
    }

    /*
     * The post commands could have deleted the menu, which means we are dead
     * and should go away.
     */

    if (menuPtr->tkwin == NULL) {
    	return TCL_OK;
    }

     /*
     * Adjust the menu y position so that the specified entry will be located
     * at the given coordinates.
     */

    if (index >= menuPtr->numEntries) {
	index = menuPtr->numEntries - 1;
    }
    if (index >= 0) {
	y -= menuPtr->entries[index]->y;
    }

   /*
     * Adjust the position of the menu if necessary to keep it visible on the
     * screen. There are two special tricks to make this work right:
     *
     * 1. If a virtual root window manager is being used then the coordinates
     *    are in the virtual root window of menuPtr's parent; since the menu
     *    uses override-redirect mode it will be in the *real* root window for
     *    the screen, so we have to map the coordinates from the virtual root
     *    (if any) to the real root. Can't get the virtual root from the menu
     *    itself (it will never be seen by the wm) so use its parent instead
     *    (it would be better to have an an option that names a window to use
     *    for this...).
     * 2. The menu may not have been mapped yet, so its current size might be
     *    the default 1x1. To compute how much space it needs, use its
     *    requested size, not its actual size.
     */

    Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
	&vRootWidth, &vRootHeight);
    vRootWidth -= Tk_ReqWidth(menuPtr->tkwin);
    if (x > vRootX + vRootWidth) {
	x = vRootX + vRootWidth;
    }
    if (x < vRootX) {
	x = vRootX;
    }
    vRootHeight -= Tk_ReqHeight(menuPtr->tkwin);
    if (y > vRootY + vRootHeight) {
	y = vRootY + vRootHeight;
    }
    if (y < vRootY) {
	y = vRootY;
    }
    Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
    if (!Tk_IsMapped(menuPtr->tkwin)) {
	Tk_MapWindow(menuPtr->tkwin);
    }
    TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMenuNewEntry --
 *
 *	Adds a pointer to a new menu entry structure with the platform-
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
896
897
898
899
900
901
902

903
904
905
906
907
908
909
910







-
+







    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    LRESULT lResult;

    if (!TkWinHandleMenuEvent(&hwnd, &message, &wParam, &lParam, &lResult)) {
	lResult = DefWindowProcW(hwnd, message, wParam, lParam);
	lResult = DefWindowProc(hwnd, message, wParam, lParam);
    }
    return lResult;
}

/*
 *----------------------------------------------------------------------
 *
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
921
922
923
924
925
926
927

928
929
930
931
932
933
934
935







-
+







 *	Redraw the embedded menu window.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateEmbeddedMenu(
    void *clientData)
    ClientData clientData)
{
    RECT rc;
    HWND hMenuWnd = (HWND)clientData;

    GetClientRect(hMenuWnd, &rc);
    InvalidateRect(hMenuWnd, &rc, FALSE);
    UpdateWindow(hMenuWnd);
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
957
958
959
960
961
962
963

964
965
966
967
968
969
970
971

972
973
974
975
976
977
978
979







-
+







-
+







    HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    static int nIdles = 0;
    LRESULT lResult = 1;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    switch(message) {
    case WM_ENTERIDLE:
	if ((wParam == MSGF_MENU) && (nIdles < 1)
		&& (hwnd == tsdPtr->embeddedMenuHWND)) {
	    Tcl_CreateTimerHandler(200, UpdateEmbeddedMenu,
		    (void *) lParam);
		    (ClientData) lParam);
	    nIdles++;
	}
	break;

    case WM_INITMENUPOPUP:
	nIdles = 0;
	break;
1102
1103
1104
1105
1106
1107
1108
1109

1110
1111

1112
1113
1114
1115
1116
1117
1118
993
994
995
996
997
998
999

1000
1001

1002
1003
1004
1005
1006
1007
1008
1009







-
+

-
+







    case WM_DRAWITEM:
    case WM_MENUSELECT:
	lResult = TkWinHandleMenuEvent(&hwnd, &message, &wParam, &lParam,
		&lResult);
	if (lResult || (GetCapture() != hwnd)) {
	    break;
	}
	/* FALLTHRU */

    default:
	lResult = DefWindowProcW(hwnd, message, wParam, lParam);
	lResult = DefWindowProc(hwnd, message, wParam, lParam);
	break;
    }
    return lResult;
}

/*
 *----------------------------------------------------------------------
1132
1133
1134
1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155

1156
1157

1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169

1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208

1209
1210
1211
1212
1213
1214
1215
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043
1044
1045

1046
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106







-
+









-
+





-
+

-
+











-
+


-
+
















-
+


















-
+







 *	should be returned to windows from this message.
 *
 *----------------------------------------------------------------------
 */

int
TkWinHandleMenuEvent(
    TCL_UNUSED(HWND *),
    HWND *phwnd,
    UINT *pMessage,
    WPARAM *pwParam,
    LPARAM *plParam,
    LRESULT *plResult)
{
    Tcl_HashEntry *hashEntryPtr;
    int returnResult = 0;
    TkMenu *menuPtr;
    TkMenuEntry *mePtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    switch (*pMessage) {
    case WM_UNINITMENUPOPUP:
	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
		*pwParam);
		(char *) *pwParam);
	if (hashEntryPtr != NULL) {
	    menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
	    menuPtr = Tcl_GetHashValue(hashEntryPtr);
	    if ((menuPtr->menuRefPtr != NULL)
		    && (menuPtr->menuRefPtr->parentEntryPtr != NULL)) {
		TkPostSubmenu(menuPtr->interp,
			menuPtr->menuRefPtr->parentEntryPtr->menuPtr, NULL);
	    }
	}
	break;

    case WM_INITMENU:
	TkMenuInit();
	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
		*pwParam);
		(char *) *pwParam);
	if (hashEntryPtr != NULL) {
	    tsdPtr->oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	    menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
	    menuPtr = Tcl_GetHashValue(hashEntryPtr);
	    tsdPtr->modalMenuPtr = menuPtr;
	    CallPendingReconfigureImmediately(menuPtr);
	    RecursivelyClearActiveMenu(menuPtr);
	    if (!tsdPtr->inPostMenu) {
		Tcl_Interp *interp = menuPtr->interp;
		int code;

		Tcl_Preserve(interp);
		code = TkPreprocessMenu(menuPtr);
		if ((code != TCL_OK) && (code != TCL_CONTINUE)
			&& (code != TCL_BREAK)) {
		    Tcl_AddErrorInfo(interp, "\n    (menu preprocess)");
		    Tcl_BackgroundException(interp, code);
		}
		Tcl_Release(interp);
	    }
	    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
	    TkActivateMenuEntry(menuPtr, -1);
	    *plResult = 0;
	    returnResult = 1;
	} else {
	    tsdPtr->modalMenuPtr = NULL;
	}
	break;

    case WM_SYSCOMMAND:
    case WM_COMMAND:
	TkMenuInit();
	if (HIWORD(*pwParam) != 0) {
	    break;
	}
	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->commandTable,
		INT2PTR(LOWORD(*pwParam)));
	if (hashEntryPtr == NULL) {
	    break;
	}
	mePtr = (TkMenuEntry *)Tcl_GetHashValue(hashEntryPtr);
	mePtr = Tcl_GetHashValue(hashEntryPtr);
	if (mePtr != NULL) {
	    TkMenuReferences *menuRefPtr;
	    TkMenuEntry *parentEntryPtr;
	    Tcl_Interp *interp;
	    int code;

	    /*
1247
1248
1249
1250
1251
1252
1253
1254

1255
1256
1257

1258
1259
1260

1261
1262
1263
1264

1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1138
1139
1140
1141
1142
1143
1144

1145
1146


1147
1148


1149

1150
1151

1152
1153
1154
1155
1156

1157
1158

1159
1160
1161
1162
1163
1164
1165

1166




1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178
1179
1180
1181







-
+

-
-
+

-
-
+
-


-
+




-
+

-







-
+
-
-
-
-








-







	    *plResult = 0;
	    returnResult = 1;
	}
	break;

    case WM_MENUCHAR: {
	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
		*plParam);
		(char *) *plParam);
	if (hashEntryPtr != NULL) {
	    Tcl_Size i, len;
	    int underline;
	    int i, len, underline;
	    Tcl_Obj *labelPtr;
	    WCHAR *wlabel;
	    int menuChar;
	    Tcl_UniChar *wlabel, menuChar;
	    Tcl_DString ds;

	    *plResult = 0;
	    menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
	    menuPtr = Tcl_GetHashValue(hashEntryPtr);
	    /*
	     * Assume we have something directly convertable to Tcl_UniChar.
	     * True at least for wide systems.
	     */
	    menuChar = Tcl_UniCharToUpper(LOWORD(*pwParam));
	    menuChar = Tcl_UniCharToUpper((Tcl_UniChar) LOWORD(*pwParam));

	    Tcl_DStringInit(&ds);
	    for (i = 0; i < menuPtr->numEntries; i++) {
		underline = menuPtr->entries[i]->underline;
		labelPtr = menuPtr->entries[i]->labelPtr;
		if ((underline >= 0) && (labelPtr != NULL)) {
		    /*
		     * Ensure we don't exceed the label length, then check
		     */
		    const char *src = Tcl_GetStringFromObj(labelPtr, &len);
		    wlabel = Tcl_GetUnicodeFromObj(labelPtr, &len);

		    Tcl_DStringFree(&ds);
		    Tcl_DStringInit(&ds);
		    wlabel = Tcl_UtfToWCharDString(src, len, &ds);
		    if ((underline < len) && (menuChar ==
				Tcl_UniCharToUpper(wlabel[underline]))) {
			*plResult = (2 << 16) | i;
			returnResult = 1;
			break;
		    }
		}
	    }
	    Tcl_DStringFree(&ds);
	}
	break;
    }

    case WM_MEASUREITEM: {
	LPMEASUREITEMSTRUCT itemPtr = (LPMEASUREITEMSTRUCT) *plParam;

1329
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1211
1212
1213
1214
1215
1216
1217

1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233







-
+







-
+







	    Tk_Font tkfont;

	    if (itemPtr->itemState & ODS_NOACCEL && !showMenuAccelerators) {
		drawingParameters |= DRAW_MENU_ENTRY_NOUNDERLINE;
	    }
	    mePtr = (TkMenuEntry *) itemPtr->itemData;
	    menuPtr = mePtr->menuPtr;
	    twdPtr = (TkWinDrawable *)ckalloc(sizeof(TkWinDrawable));
	    twdPtr = ckalloc(sizeof(TkWinDrawable));
	    twdPtr->type = TWD_WINDC;
	    twdPtr->winDC.hdc = itemPtr->hDC;

	    if (mePtr->state != ENTRY_DISABLED) {
		if (itemPtr->itemState & ODS_SELECTED) {
		    TkActivateMenuEntry(menuPtr, mePtr->index);
		} else {
		    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
		    TkActivateMenuEntry(menuPtr, -1);
		}
	    } else {
		/*
		 * On windows, menu entries should highlight even if they are
		 * disabled. (I know this seems dumb, but it is the way native
		 * windows menus works so we ought to mimic it.) The
		 * ENTRY_PLATFORM_FLAG1 flag will indicate that the entry
1393
1394
1395
1396
1397
1398
1399
1400

1401
1402

1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415







1416
1417
1418
1419



1420
1421

1422
1423
1424
1425
1426
1427

1428
1429
1430
1431
1432
1433

1434
1435

1436
1437
1438
1439
1440
1441
1442
1275
1276
1277
1278
1279
1280
1281

1282
1283

1284
1285
1286
1287
1288

1289
1290







1291
1292
1293
1294
1295
1296
1297
1298



1299
1300
1301
1302

1303
1304
1305
1306
1307
1308

1309
1310
1311
1312
1313
1314

1315
1316

1317
1318
1319
1320
1321
1322
1323
1324







-
+

-
+




-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
+
+
+

-
+





-
+





-
+

-
+







		Tcl_SetServiceMode(tsdPtr->oldServiceMode);
		RecursivelyClearActiveMenu(tsdPtr->modalMenuPtr);
	    }
	} else {
	    menuPtr = NULL;
	    if (*plParam != 0) {
		hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
			*plParam);
			(char *) *plParam);
		if (hashEntryPtr != NULL) {
		    menuPtr = (TkMenu *)Tcl_GetHashValue(hashEntryPtr);
		    menuPtr = Tcl_GetHashValue(hashEntryPtr);
		}
	    }

	    if (menuPtr != NULL) {
		Tcl_Size entryIndex = LOWORD(*pwParam);
		long entryIndex = LOWORD(*pwParam);

		if ((menuPtr->menuType == MENUBAR) && menuPtr->tearoff) {
		    /*
		     * Windows passes the entry index starting at 0 for
		     * the first menu entry. However this entry #0 is the
		     * tearoff entry for Tk (the menu has -tearoff 1),
		     * which is ignored for MENUBAR menues on Windows.
		     */
                if ((menuPtr->menuType == MENUBAR) && menuPtr->tearoff) {
                    /*
                     * Windows passes the entry index starting at 0 for
                     * the first menu entry. However this entry #0 is the
                     * tearoff entry for Tk (the menu has -tearoff 1),
                     * which is ignored for MENUBAR menues on Windows.
                     */

			entryIndex++;
		}
		mePtr = NULL;
                    entryIndex++;
                }
                mePtr = NULL;
		if (flags != 0xFFFF) {
		    if ((flags&MF_POPUP) && (entryIndex < menuPtr->numEntries)) {
		    if ((flags&MF_POPUP) && (entryIndex<menuPtr->numEntries)) {
			mePtr = menuPtr->entries[entryIndex];
		    } else {
			hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->commandTable,
				INT2PTR(entryIndex));
			if (hashEntryPtr != NULL) {
			    mePtr = (TkMenuEntry *)Tcl_GetHashValue(hashEntryPtr);
			    mePtr = Tcl_GetHashValue(hashEntryPtr);
			}
		    }
		}

		if ((mePtr == NULL) || (mePtr->state == ENTRY_DISABLED)) {
		    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
		    TkActivateMenuEntry(menuPtr, -1);
		} else {
		    if (mePtr->index >= (int)menuPtr->numEntries) {
		    if (mePtr->index >= menuPtr->numEntries) {
			Tcl_Panic("Trying to activate an entry which doesn't exist");
		    }
		    TkActivateMenuEntry(menuPtr, mePtr->index);
		}
		MenuSelectEvent(menuPtr);
		Tcl_ServiceAll();
		*plResult = 0;
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475

1476
1477
1478
1479
1480
1481
1482
1347
1348
1349
1350
1351
1352
1353

1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1364







-
+


-
+







 *----------------------------------------------------------------------
 */

void
RecursivelyClearActiveMenu(
    TkMenu *menuPtr)		/* The menu to reset. */
{
    Tcl_Size i;
    int i;
    TkMenuEntry *mePtr;

    TkActivateMenuEntry(menuPtr, TCL_INDEX_NONE);
    TkActivateMenuEntry(menuPtr, -1);
    MenuSelectEvent(menuPtr);
    for (i = 0; i < menuPtr->numEntries; i++) {
    	mePtr = menuPtr->entries[i];
	if (mePtr->state == ENTRY_ACTIVE) {
	    mePtr->state = ENTRY_NORMAL;
	}
	mePtr->entryFlags &= ~ENTRY_PLATFORM_FLAG1;
1509
1510
1511
1512
1513
1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561




1562
1563
1564
1565
1566
1567
1568
1391
1392
1393
1394
1395
1396
1397

1398
1399
1400
1401
1402
1403
1404
1405
1406

1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424

1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439




1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450







-
+








-
+

















-
+














-
-
-
-
+
+
+
+







void
TkpSetWindowMenuBar(
    Tk_Window tkwin,		/* The window we are putting the menubar
				 * into.*/
    TkMenu *menuPtr)		/* The menu we are inserting */
{
    HMENU winMenuHdl;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (menuPtr != NULL) {
	Tcl_HashEntry *hashEntryPtr;
	int newEntry;

	winMenuHdl = (HMENU) menuPtr->platformData;
	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable,
		winMenuHdl);
		(char *) winMenuHdl);
	Tcl_DeleteHashEntry(hashEntryPtr);
	DestroyMenu(winMenuHdl);
	winMenuHdl = CreateMenu();
	hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->winMenuTable,
		(char *) winMenuHdl, &newEntry);
	Tcl_SetHashValue(hashEntryPtr, menuPtr);
	menuPtr->platformData = (TkMenuPlatformData) winMenuHdl;
	TkWinSetMenu(tkwin, winMenuHdl);
	ScheduleMenuReconfigure(menuPtr);
    } else {
	TkWinSetMenu(tkwin, NULL);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetMainMenubar --
 * TkpSetMainMenubar --
 *
 *	Puts the menu associated with a window into the menubar. Should only
 *	be called when the window is in front.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The menubar is changed.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetMainMenubar(
    TCL_UNUSED(Tcl_Interp *),		/* The interpreter of the application */
    TCL_UNUSED(Tk_Window),		/* The frame we are setting up */
    TCL_UNUSED(const char *))	/* The name of the menu to put in front. If
TkpSetMainMenubar(
    Tcl_Interp *interp,		/* The interpreter of the application */
    Tk_Window tkwin,		/* The frame we are setting up */
    const char *menuName)	/* The name of the menu to put in front. If
    				 * NULL, use the default menu bar. */
{
    /*
     * Nothing to do.
     */
}

1582
1583
1584
1585
1586
1587
1588
1589
1590


1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1464
1465
1466
1467
1468
1469
1470


1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484









1485
1486
1487
1488
1489
1490
1491







-
-
+
+












-
-
-
-
-
-
-
-
-







 *----------------------------------------------------------------------
 */

void
GetMenuIndicatorGeometry(
    TkMenu *menuPtr,		/* The menu we are measuring */
    TkMenuEntry *mePtr,		/* The entry we are measuring */
    TCL_UNUSED(Tk_Font),		/* Precalculated font */
    TCL_UNUSED(const Tk_FontMetrics *),/* Precalculated font metrics */
    Tk_Font tkfont,		/* Precalculated font */
    const Tk_FontMetrics *fmPtr,/* Precalculated font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    *heightPtr = indicatorDimensions[0];
    if (mePtr->hideMargin) {
	*widthPtr = 0;
    } else {
	int borderWidth;

	Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
		menuPtr->borderWidthPtr, &borderWidth);
	*widthPtr = indicatorDimensions[1] - borderWidth;

        /*
         * Quite dubious about the above (why would borderWidth play a role?)
         * and about how indicatorDimensions[1] is obtained in SetDefaults().
         * At least don't let the result be negative!
         */
        if (*widthPtr < 0) {
            *widthPtr = 0;
        }
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GetMenuAccelGeometry --
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
1508
1509
1510
1511
1512
1513
1514







1515
1516
1517
1518
1519
1520
1521
1522







-
-
-
-
-
-
-
+







    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    *heightPtr = fmPtr->linespace;
    if (mePtr->type == CASCADE_ENTRY) {
        /*
         * Cascade entries have no accelerator but do show an arrow. Set
         * this field width to the width of the OBM_MNARROW system bitmap
         * used to display the arrow. I couldn't find how to query the
         * system for this value, therefore I resort to hardcoding.
         */
	*widthPtr = CASCADE_ARROW_WIDTH;
	*widthPtr = 0;
    } else if ((menuPtr->menuType != MENUBAR) && (mePtr->accelPtr != NULL)) {
	const char *accel = Tcl_GetString(mePtr->accelPtr);

	*widthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
    } else {
    	*widthPtr = 0;
    }
1670
1671
1672
1673
1674
1675
1676
1677
1678


1679
1680
1681
1682
1683

1684
1685
1686
1687
1688
1689
1690
1537
1538
1539
1540
1541
1542
1543


1544
1545
1546
1547
1548
1549

1550
1551
1552
1553
1554
1555
1556
1557







-
-
+
+




-
+







 *
 *----------------------------------------------------------------------
 */

void
GetTearoffEntryGeometry(
    TkMenu *menuPtr,		/* The menu we are measuring */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are measuring */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    TkMenuEntry *mePtr,		/* The entry we are measuring */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    if (menuPtr->menuType != MAIN_MENU) {
    if (menuPtr->menuType != MASTER_MENU) {
	*heightPtr = 0;
    } else {
	*heightPtr = fmPtr->linespace;
    }
    *widthPtr = 0;
}

1702
1703
1704
1705
1706
1707
1708
1709
1710
1711



1712
1713
1714
1715
1716
1717
1718
1569
1570
1571
1572
1573
1574
1575



1576
1577
1578
1579
1580
1581
1582
1583
1584
1585







-
-
-
+
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
GetMenuSeparatorGeometry(
    TCL_UNUSED(TkMenu *),		/* The menu we are measuring */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are measuring */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    TkMenu *menuPtr,		/* The menu we are measuring */
    TkMenuEntry *mePtr,		/* The entry we are measuring */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalcualted font metrics */
    int *widthPtr,		/* The resulting width */
    int *heightPtr)		/* The resulting height */
{
    *widthPtr = 0;
    *heightPtr = fmPtr->linespace - (2 * fmPtr->descent);
}
1756
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
1623
1624
1625
1626
1627
1628
1629

1630
1631
1632
1633
1634
1635
1636
1637







-
+







    POINT ptOrg;
    int topOffset, leftOffset;

    SetBkColor(hdc, gc->background);
    SetTextColor(hdc, gc->foreground);

    scratchDC = CreateCompatibleDC(hdc);
    bitmap = LoadBitmapW(NULL, (LPCWSTR)MAKEINTRESOURCE(bitmapID));
    bitmap = LoadBitmap(NULL, MAKEINTRESOURCE(bitmapID));

    SelectObject(scratchDC, bitmap);
    SetMapMode(scratchDC, GetMapMode(hdc));
    GetObjectA(bitmap, sizeof(BITMAP), &bm);
    ptSize.x = bm.bmWidth;
    ptSize.y = bm.bmHeight;
    DPtoLP(scratchDC, &ptSize, 1);
1815
1816
1817
1818
1819
1820
1821
1822
1823


1824
1825
1826
1827


1828
1829
1830
1831
1832
1833
1834
1682
1683
1684
1685
1686
1687
1688


1689
1690
1691
1692


1693
1694
1695
1696
1697
1698
1699
1700
1701







-
-
+
+


-
-
+
+







void
DrawMenuEntryIndicator(
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    GC gc,			/* The gc we are drawing with */
    GC indicatorGC,		/* The gc for indicator objects */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    TCL_UNUSED(const Tk_FontMetrics *),/* The precalculated font metrics */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int x,			/* Left edge */
    int y,			/* Top edge */
    TCL_UNUSED(int),
    TCL_UNUSED(int))
    int width,
    int height)
{
    if ((mePtr->type == CHECK_BUTTON_ENTRY)
	    || (mePtr->type == RADIO_BUTTON_ENTRY)) {
    	if (mePtr->indicatorOn && (mePtr->entryFlags & ENTRY_SELECTED)) {
	    RECT rect;
	    GC whichGC;
	    int borderWidth, activeBorderWidth;
1893
1894
1895
1896
1897
1898
1899
1900

1901
1902
1903

1904
1905
1906
1907
1908
1909
1910
1760
1761
1762
1763
1764
1765
1766

1767
1768
1769

1770
1771
1772
1773
1774
1775
1776
1777







-
+


-
+







DrawMenuEntryAccelerator(
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    GC gc,			/* The gc we are drawing with */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    TCL_UNUSED(Tk_3DBorder),	/* The border when an item is active */
    Tk_3DBorder activeBorder,	/* The border when an item is active */
    int x,			/* left edge */
    int y,			/* top edge */
    TCL_UNUSED(int),			/* Width of menu entry */
    int width,			/* Width of menu entry */
    int height)			/* Height of menu entry */
{
    int baseline;
    int leftEdge = x + mePtr->indicatorSpace + mePtr->labelWidth;
    const char *accel;

    if (menuPtr->menuType == MENUBAR) {
1919
1920
1921
1922
1923
1924
1925
1926

1927
1928
1929
1930
1931
1932
1933
1786
1787
1788
1789
1790
1791
1792

1793
1794
1795
1796
1797
1798
1799
1800







-
+








    baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;

    /*
     * Draw disabled 3D text highlight only with the Win95/98 look.
     */

    if (TkWinGetPlatformTheme() != TK_THEME_WIN_XP) {
    if (TkWinGetPlatformTheme() == TK_THEME_WIN_CLASSIC) {
	if ((mePtr->state == ENTRY_DISABLED)
		&& (menuPtr->disabledFgPtr != NULL) && (accel != NULL)) {
	    COLORREF oldFgColor = gc->foreground;

	    gc->foreground = GetSysColor(COLOR_3DHILIGHT);
	    if (!(mePtr->entryFlags & ENTRY_PLATFORM_FLAG1)) {
		Tk_DrawChars(menuPtr->display, d, gc, tkfont, accel,
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
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







-
-
+
+
-
















-
+





-
+










-
-
-
-
-
-
-
-
-
-








/*
 *----------------------------------------------------------------------
 *
 * DrawMenuEntryArrow --
 *
 *	This function draws the arrow bitmap on the right side of a menu
 *	entry. This function is only used when drawing the arrow for:
 *	 - a disabled cascade item
 *	entry. This function is only used when drawing the arrow for a
 *	disabled cascade menu.
 *	 - a cascade item in any state in a torn-off menu
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
DrawMenuEntryArrow(
    TkMenu *menuPtr,		/* The menu we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    GC gc,			/* The gc we are drawing with */
    TCL_UNUSED(Tk_3DBorder),	/* The border when an item is active */
    Tk_3DBorder activeBorder,	/* The border when an item is active */
    int x,			/* left edge */
    int y,			/* top edge */
    int width,			/* Width of menu entry */
    int height,			/* Height of menu entry */
    int drawArrow)		/* For cascade menus, whether of not to draw
				 * the arrow. I cannot figure out Windows'
				 * the arraw. I cannot figure out Windows'
				 * algorithm for where to draw this. */
{
    COLORREF oldFgColor;
    COLORREF oldBgColor;
    RECT rect;

    if (!drawArrow || (mePtr->type != CASCADE_ENTRY)) {
	return;
    }

    /*
     * Don't draw the arrow if a submenu is not attached to this
     * cascade entry.
     */

    if ((mePtr->childMenuRefPtr == NULL)
           || (mePtr->childMenuRefPtr->menuPtr == NULL)) {
        return;
    }

    oldFgColor = gc->foreground;
    oldBgColor = gc->background;

    /*
     * Set bitmap bg to highlight color if the menu is highlighted.
     */

2044
2045
2046
2047
2048
2049
2050
2051

2052
2053
2054
2055



2056
2057
2058
2059
2060
2061
2062
1900
1901
1902
1903
1904
1905
1906

1907
1908



1909
1910
1911
1912
1913
1914
1915
1916
1917
1918







-
+

-
-
-
+
+
+







 *
 *----------------------------------------------------------------------
 */

void
DrawMenuSeparator(
    TkMenu *menuPtr,		/* The menu we are drawing */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    TCL_UNUSED(GC),			/* The gc we are drawing with */
    TCL_UNUSED(Tk_Font),		/* The precalculated font */
    TCL_UNUSED(const Tk_FontMetrics *),/* The precalculated font metrics */
    GC gc,			/* The gc we are drawing with */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int x,			/* left edge */
    int y,			/* top edge */
    int width,			/* width of item */
    int height)			/* height of item */
{
    XPoint points[2];
    Tk_3DBorder border;
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
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







-
+





+
-
+


-



-
+















-
+













-
+







    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* What we are drawing into */
    GC gc,			/* The gc to draw into */
    Tk_Font tkfont,		/* The precalculated font */
    const Tk_FontMetrics *fmPtr,/* The precalculated font metrics */
    int x,			/* Left Edge */
    int y,			/* Top Edge */
    TCL_UNUSED(int),			/* Width of entry */
    int width,			/* Width of entry */
    int height)			/* Height of entry */
{
    if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
	int len;

	/* do the unicode call just to prevent overruns */
	len = Tcl_GetCharLength(mePtr->labelPtr);
	Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
	if (mePtr->underline < len) {
	    const char *label, *start, *end;
	    int ch;

	    label = Tcl_GetString(mePtr->labelPtr);
	    start = Tcl_UtfAtIndex(label, mePtr->underline);
	    end = start + Tcl_UtfToUniChar(start, &ch);
	    end = Tcl_UtfNext(start);
	    Tk_UnderlineChars(menuPtr->display, d,
		    gc, tkfont, label, x + mePtr->indicatorSpace,
		    y + (height + fmPtr->ascent - fmPtr->descent) / 2,
		    (int) (start - label), (int) (end - label));
	}
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkWinMenuKeyObjCmd --
 *
 *	This function is invoked when keys related to pulling down menus is
 *	pressed. The corresponding Windows events are generated and passed to
 *	DefWindowProcW if appropriate. This cmd is registered as tk::WinMenuKey
 *	DefWindowProc if appropriate. This cmd is registered as tk::WinMenuKey
 *	in the interp.
 *
 * Results:
 *	Always returns TCL_OK.
 *
 * Side effects:
 *	The menu system may take over and process user events for menu input.
 *
 *--------------------------------------------------------------
 */

static int
TkWinMenuKeyObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Unused. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    UINT scanCode;
    UINT virtualKey;
    XEvent *eventPtr;
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
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







-
-
+
+




-
-
+
+




-
-
+
+




-
+

-
+
-
-
+


+
-
-
-
-
-
+
+
+
+
+
+






-
-
+
+




-
-
+
+

-
+


-
-
+
+





-
+

-
+







	return TCL_ERROR;
    }
    keySym = i;

    if (eventPtr->type == KeyPress) {
	switch (keySym) {
	case XK_Alt_L:
	    scanCode = MapVirtualKeyW(VK_LMENU, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_LMENU, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYDOWN, VK_MENU,
		    (int) (scanCode << 16) | (1 << 29));
	    break;
	case XK_Alt_R:
	    scanCode = MapVirtualKeyW(VK_RMENU, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_RMENU, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYDOWN, VK_MENU,
		    (int) (scanCode << 16) | (1 << 29) | (1 << 24));
	    break;
	case XK_F10:
	    scanCode = MapVirtualKeyW(VK_F10, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_F10, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYDOWN, VK_F10, (int) (scanCode << 16));
	    break;
	default:
	    virtualKey = XKeysymToKeycode(winPtr->display, keySym);
	    scanCode = MapVirtualKeyW(virtualKey, 0);
	    scanCode = MapVirtualKey(virtualKey, 0);
	    if (0 != scanCode) {
		TkKeyEvent xkey;
		XKeyEvent xkey = eventPtr->xkey;
		memcpy(&xkey, eventPtr, sizeof(xkey));
		CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
		CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
			WM_SYSKEYDOWN, virtualKey,
			(int) ((scanCode << 16) | (1 << 29)));
		if (xkey.nbytes > 0) {
		for (i = 0; i < xkey.nbytes; i++) {
		    CallWindowProcW(DefWindowProcW,
			    Tk_GetHWND(Tk_WindowId(tkwin)), WM_SYSCHAR,
			    xkey.trans_chars[i],
			    (int) ((scanCode << 16) | (1 << 29)));
		    for (i = 0; i < xkey.nbytes; i++) {
			CallWindowProc(DefWindowProc,
				Tk_GetHWND(Tk_WindowId(tkwin)), WM_SYSCHAR,
				xkey.trans_chars[i],
				(int) ((scanCode << 16) | (1 << 29)));
		    }
		}
	    }
	}
    } else if (eventPtr->type == KeyRelease) {
	switch (keySym) {
	case XK_Alt_L:
	    scanCode = MapVirtualKeyW(VK_LMENU, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_LMENU, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYUP, VK_MENU, (int) (scanCode << 16)
		    | (1 << 29) | (1 << 30) | (1 << 31));
	    break;
	case XK_Alt_R:
	    scanCode = MapVirtualKeyW(VK_RMENU, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_RMENU, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYUP, VK_MENU, (int) (scanCode << 16) | (1 << 24)
		    | (1 << 29) | (1 << 30) | (1 << 31));
		    | (0x111 << 29) | (1 << 30) | (1 << 31));
	    break;
	case XK_F10:
	    scanCode = MapVirtualKeyW(VK_F10, 0);
	    CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
	    scanCode = MapVirtualKey(VK_F10, 0);
	    CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
		    WM_SYSKEYUP, VK_F10,
		    (int) (scanCode << 16) | (1 << 30) | (1 << 31));
	    break;
	default:
	    virtualKey = XKeysymToKeycode(winPtr->display, keySym);
	    scanCode = MapVirtualKeyW(virtualKey, 0);
	    scanCode = MapVirtualKey(virtualKey, 0);
	    if (0 != scanCode) {
		CallWindowProcW(DefWindowProcW, Tk_GetHWND(Tk_WindowId(tkwin)),
		CallWindowProc(DefWindowProc, Tk_GetHWND(Tk_WindowId(tkwin)),
			WM_SYSKEYUP, virtualKey, (int) ((scanCode << 16)
			| (1 << 29) | (1 << 30) | (1 << 31)));
	    }
	}
    }
    return TCL_OK;
}
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
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







-
+
+

-
+


-
+


-
+


-
+


-
-
+
+

-
+


-
-
+
+

-
+







     * windows events, so we need to invoke C code to generate the
     * WM_SYSKEYDOWNS and WM_SYSKEYUPs appropriately. Trick is, we can't
     * create a C level binding directly since we may want to modify the
     * binding in Tcl code.
     */

    (void) Tcl_CreateObjCommand(interp, "tk::WinMenuKey",
	    TkWinMenuKeyObjCmd, Tk_MainWindow(interp), NULL);
	    TkWinMenuKeyObjCmd,
	    (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<Alt_L>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<KeyRelease-Alt_L>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<Alt_R>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<KeyRelease-Alt_R>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
	    "<Alt-Key>", "tk::WinMenuKey %W %N", 0);
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<Alt-KeyPress>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<Alt-KeyRelease>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
	    "<Key-F10>", "tk::WinMenuKey %W %N", 0);
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<KeyPress-F10>", "tk::WinMenuKey %W %N", 0);

    (void) Tk_CreateBinding(interp, bindingTable, (void *)uid,
    (void) Tk_CreateBinding(interp, bindingTable, (ClientData) uid,
	    "<KeyRelease-F10>", "tk::WinMenuKey %W %N", 0);
}

/*
 *----------------------------------------------------------------------
 *
 * DrawMenuEntryLabel --
2461
2462
2463
2464
2465
2466
2467
2468

2469
2470
2471
2472
2473
2474
2475
2319
2320
2321
2322
2323
2324
2325

2326
2327
2328
2329
2330
2331
2332
2333







-
+







		(int) (y + (mePtr->height - imageHeight)/2 + imageYOffset), 1);
    }
    if ((mePtr->compound != COMPOUND_NONE) || !haveImage) {
    	if (mePtr->labelLength > 0) {
	    int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
	    const char *label = Tcl_GetString(mePtr->labelPtr);

	    if (TkWinGetPlatformTheme() != TK_THEME_WIN_XP) {
	    if (TkWinGetPlatformTheme() == TK_THEME_WIN_CLASSIC) {
		/*
		 * Win 95/98 systems draw disabled menu text with a 3D
		 * highlight, unless the menu item is highlighted,
		 */

		if ((mePtr->state == ENTRY_DISABLED) &&
			!(mePtr->entryFlags & ENTRY_PLATFORM_FLAG1)) {
2493
2494
2495
2496
2497
2498
2499
2500

2501
2502
2503
2504
2505
2506
2507
2351
2352
2353
2354
2355
2356
2357

2358
2359
2360
2361
2362
2363
2364
2365







-
+







    }

    if (mePtr->state == ENTRY_DISABLED) {
	if (menuPtr->disabledFgPtr == NULL) {
	    XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,
		    (unsigned) width, (unsigned) height);
	} else if ((mePtr->image != NULL)
		&& menuPtr->disabledImageGC) {
		&& (menuPtr->disabledImageGC != None)) {
	    XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,
		    leftEdge + imageXOffset,
		    (int) (y + (mePtr->height - imageHeight)/2 + imageYOffset),
		    (unsigned) imageWidth, (unsigned) imageHeight);
	}
    }
}
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
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







-
+

-
-
-
+
+
+







-
+







-
+







 *
 *----------------------------------------------------------------------
 */

void
DrawTearoffEntry(
    TkMenu *menuPtr,		/* The menu we are drawing */
    TCL_UNUSED(TkMenuEntry *),		/* The entry we are drawing */
    TkMenuEntry *mePtr,		/* The entry we are drawing */
    Drawable d,			/* The drawable we are drawing into */
    TCL_UNUSED(GC),			/* The gc we are drawing with */
    TCL_UNUSED(Tk_Font),		/* The font we are drawing with */
    TCL_UNUSED(const Tk_FontMetrics *),/* The metrics we are drawing with */
    GC gc,			/* The gc we are drawing with */
    Tk_Font tkfont,		/* The font we are drawing with */
    const Tk_FontMetrics *fmPtr,/* The metrics we are drawing with */
    int x, int y,
    int width, int height)
{
    XPoint points[2];
    int segmentWidth, maxX;
    Tk_3DBorder border;

    if (menuPtr->menuType != MAIN_MENU) {
    if (menuPtr->menuType != MASTER_MENU) {
	return;
    }

    points[0].x = x;
    points[0].y = y + height/2;
    points[1].y = points[0].y;
    segmentWidth = 6;
    maxX = x + width - 1;
    maxX = width - 1;
    border = Tk_Get3DBorderFromObj(menuPtr->tkwin, menuPtr->borderPtr);

    while (points[0].x < maxX) {
	points[1].x = points[0].x + segmentWidth;
	if (points[1].x > maxX) {
	    points[1].x = maxX;
	}
2600
2601
2602
2603
2604
2605
2606
2607

2608
2609
2610
2611
2612
2613
2614
2458
2459
2460
2461
2462
2463
2464

2465
2466
2467
2468
2469
2470
2471
2472







-
+







 *	if any need it.
 *
 *----------------------------------------------------------------------
 */

int
TkpConfigureMenuEntry(
    TkMenuEntry *mePtr)/* Information about menu entry; may or may
    register TkMenuEntry *mePtr)/* Information about menu entry; may or may
				 * not already have values for some fields. */
{
    ScheduleMenuReconfigure(mePtr->menuPtr);
    return TCL_OK;
}

/*
2638
2639
2640
2641
2642
2643
2644
2645

2646
2647
2648
2649
2650
2651
2652
2496
2497
2498
2499
2500
2501
2502

2503
2504
2505
2506
2507
2508
2509
2510







-
+







    int x,			/* X-coordinate of topleft of entry */
    int y,			/* Y-coordinate of topleft of entry */
    int width,			/* Width of the entry rectangle */
    int height,			/* Height of the current rectangle */
    int strictMotif,		/* Boolean flag */
    int drawingParameters)	/* Whether or not to draw the cascade arrow
				 * for cascade items and accelerator
				 * cues. */
				 * cues. Only applies to Windows. */
{
    GC gc, indicatorGC;
    TkMenu *menuPtr = mePtr->menuPtr;
    Tk_3DBorder bgBorder, activeBorder;
    const Tk_FontMetrics *fmPtr;
    Tk_FontMetrics entryMetrics;
    int padY = (menuPtr->menuType == MENUBAR) ? 3 : 0;
2664
2665
2666
2667
2668
2669
2670
2671

2672
2673
2674
2675
2676
2677
2678
2522
2523
2524
2525
2526
2527
2528

2529
2530
2531
2532
2533
2534
2535
2536







-
+







     * animated menus.  [Bug 1329198]
     */

    if (mePtr->image != NULL) {
	menuDc = TkWinGetDrawableDC(menuPtr->display, menuDrawable, &dcState);

	memDc = CreateCompatibleDC(menuDc);
	oldBitmap = (HBITMAP)SelectObject(memDc,
	oldBitmap = SelectObject(memDc,
    			CreateCompatibleBitmap(menuDc, width, height) );

	memWinDraw.type = TWD_WINDC;
	memWinDraw.winDC.hdc = memDc;
	d = (Drawable)&memWinDraw;
	adjustedX = 0;
	adjustedY = padY;
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
2786
2787
2788
2789
2790
2791
2792



2793

2794














2795
2796

2797
2798
2799
2800
2801
2802
2803







-
-
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-







    int x,			/* left edge */
    int y,			/* top edge */
    int width,			/* width of rectangle to draw */
    int height)			/* height of rectangle to draw */
{
    if (mePtr->state == ENTRY_ACTIVE
		|| (mePtr->entryFlags & ENTRY_PLATFORM_FLAG1)!=0 ) {
	int relief;
	int activeBorderWidth;

	bgBorder = activeBorder;

    }
	if ((menuPtr->menuType == MENUBAR)
		&& ((menuPtr->postedCascade == NULL)
		|| (menuPtr->postedCascade != mePtr))) {
	    relief = TK_RELIEF_FLAT;
	} else {
	    Tk_GetReliefFromObj(NULL, menuPtr->activeReliefPtr, &relief);
	}
	Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
		menuPtr->activeBorderWidthPtr, &activeBorderWidth);
	Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height,
		activeBorderWidth, relief);
    } else {
        Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height, 0,
                TK_RELIEF_FLAT);
    Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder, x, y, width, height, 0,
	    TK_RELIEF_FLAT);
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkpComputeStandardMenuGeometry --
 *
2976
2977
2978
2979
2980
2981
2982
2983

2984
2985
2986
2987
2988
2989
2990
2818
2819
2820
2821
2822
2823
2824

2825
2826
2827
2828
2829
2830
2831
2832







-
+







TkpComputeStandardMenuGeometry(
    TkMenu *menuPtr)		/* Structure describing menu. */
{
    Tk_Font menuFont, tkfont;
    Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;
    int x, y, height, width, indicatorSpace, labelWidth, accelWidth;
    int windowWidth, windowHeight, accelSpace;
    Tcl_Size i, j, lastColumnBreak = 0;
    int i, j, lastColumnBreak = 0;
    int activeBorderWidth, borderWidth;

    if (menuPtr->tkwin == NULL) {
	return;
    }

    Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
3005
3006
3007
3008
3009
3010
3011
3012

3013
3014
3015
3016
3017
3018
3019
2847
2848
2849
2850
2851
2852
2853

2854
2855
2856
2857
2858
2859
2860
2861







-
+








    menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
    Tk_GetFontMetrics(menuFont, &menuMetrics);
    accelSpace = Tk_TextWidth(menuFont, "M", 1);
    Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
	    menuPtr->activeBorderWidthPtr, &activeBorderWidth);

    for (i = 0; i < (int)menuPtr->numEntries; i++) {
    for (i = 0; i < menuPtr->numEntries; i++) {
	if (menuPtr->entries[i]->fontPtr == NULL) {
	    tkfont = menuFont;
	    fmPtr = &menuMetrics;
	} else {
	    tkfont = Tk_GetFontFromObj(menuPtr->tkwin,
		    menuPtr->entries[i]->fontPtr);
    	    Tk_GetFontMetrics(tkfont, &entryMetrics);
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
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







-
+













+







		menuPtr->entries[j]->labelWidth = labelWidth;
		menuPtr->entries[j]->width = indicatorSpace + labelWidth
			+ accelWidth + 2 * activeBorderWidth;
		menuPtr->entries[j]->x = x;
		menuPtr->entries[j]->entryFlags &= ~ENTRY_LAST_COLUMN;
	    }
	    x += indicatorSpace + labelWidth + accelWidth
		    + 2 * activeBorderWidth;
		    + 2 * borderWidth;
	    indicatorSpace = labelWidth = accelWidth = 0;
	    lastColumnBreak = i;
	    y = borderWidth;
	}

	if (menuPtr->entries[i]->type == SEPARATOR_ENTRY) {
	    GetMenuSeparatorGeometry(menuPtr, menuPtr->entries[i], tkfont,
	    	    fmPtr, &width, &height);
	    menuPtr->entries[i]->height = height;
	} else if (menuPtr->entries[i]->type == TEAROFF_ENTRY) {
	    GetTearoffEntryGeometry(menuPtr, menuPtr->entries[i], tkfont,
	    	    fmPtr, &width, &height);
	    menuPtr->entries[i]->height = height;

	} else {
	    /*
	     * For each entry, compute the height required by that particular
	     * entry, plus three widths: the width of the label, the width to
	     * allow for an indicator to be displayed to the left of the label
	     * (if any), and the width of the accelerator to be displayed to
	     * the right of the label (if any). These sizes depend, of course,
3089
3090
3091
3092
3093
3094
3095
3096

3097
3098
3099
3100
3101
3102
3103
3104
3105




3106
3107
3108
3109
3110
3111
3112
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







-
+







-
-
+
+
+
+







	    windowHeight = y;
	}
    }

    if (accelWidth != 0) {
	labelWidth += accelSpace;
    }
    for (j = lastColumnBreak; j < (int)menuPtr->numEntries; j++) {
    for (j = lastColumnBreak; j < menuPtr->numEntries; j++) {
	menuPtr->entries[j]->indicatorSpace = indicatorSpace;
	menuPtr->entries[j]->labelWidth = labelWidth;
	menuPtr->entries[j]->width = indicatorSpace + labelWidth
		+ accelWidth + 2 * activeBorderWidth;
	menuPtr->entries[j]->x = x;
	menuPtr->entries[j]->entryFlags |= ENTRY_LAST_COLUMN;
    }
    windowWidth = x + indicatorSpace + labelWidth + accelWidth
	    + 2 * activeBorderWidth + borderWidth;
    windowWidth = x + indicatorSpace + labelWidth + accelWidth + accelSpace
	    + 2 * activeBorderWidth + 2 * borderWidth;


    windowHeight += borderWidth;

    /*
     * The X server doesn't like zero dimensions, so round up to at least 1 (a
     * zero-sized menu should never really occur, anyway).
     */

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
3171
3172
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







-
+


-
-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

static void
MenuSelectEvent(
    TkMenu *menuPtr)		/* the menu we have selected. */
{
    union {XEvent general; XVirtualEvent virt;} event;
    XVirtualEvent event;
    union {DWORD msgpos; POINTS point;} root;

    memset(&event, 0, sizeof(event));
    event.virt.type = VirtualEvent;
    event.virt.serial = LastKnownRequestProcessed(menuPtr->display);
    event.virt.send_event = 0;
    event.virt.display = menuPtr->display;
    event.type = VirtualEvent;
    event.serial = menuPtr->display->request;
    event.send_event = 0;
    event.display = menuPtr->display;
    Tk_MakeWindowExist(menuPtr->tkwin);
    event.virt.event = Tk_WindowId(menuPtr->tkwin);
    event.virt.root = XRootWindow(menuPtr->display, 0);
    event.virt.subwindow = None;
    event.virt.time = TkpGetMS();
    event.event = Tk_WindowId(menuPtr->tkwin);
    event.root = XRootWindow(menuPtr->display, 0);
    event.subwindow = None;
    event.time = TkpGetMS();

    root.msgpos = GetMessagePos();
    event.virt.x_root = root.point.x;
    event.virt.y_root = root.point.y;
    event.virt.state = TkWinGetModifierState();
    event.virt.same_screen = 1;
    event.virt.name = Tk_GetUid("MenuSelect");
    event.virt.user_data = NULL;
    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
    event.x_root = root.point.x;
    event.y_root = root.point.y;
    event.state = TkWinGetModifierState();
    event.same_screen = 1;
    event.name = Tk_GetUid("MenuSelect");
    event.user_data = NULL;
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMenuNotifyToplevelCreate --
 *
3190
3191
3192
3193
3194
3195
3196
3197

3198
3199
3200
3201
3202
3203
3204
3034
3035
3036
3037
3038
3039
3040

3041
3042
3043
3044
3045
3046
3047
3048







-
+







{
    TkMenuReferences *menuRefPtr;
    TkMenu *menuPtr;

    if ((menuName != NULL) && (menuName[0] != '\0')) {
	menuRefPtr = TkFindMenuReferences(interp, menuName);
	if ((menuRefPtr != NULL) && (menuRefPtr->menuPtr != NULL)) {
	    for (menuPtr = menuRefPtr->menuPtr->mainMenuPtr; menuPtr != NULL;
	    for (menuPtr = menuRefPtr->menuPtr->masterMenuPtr; menuPtr != NULL;
		    menuPtr = menuPtr->nextInstancePtr) {
		if (menuPtr->menuType == MENUBAR) {
		    ScheduleMenuReconfigure(menuPtr);
		}
	    }
	}
    }
3221
3222
3223
3224
3225
3226
3227
3228

3229
3230

3231
3232
3233
3234
3235
3236
3237
3065
3066
3067
3068
3069
3070
3071

3072
3073

3074
3075
3076
3077
3078
3079
3080
3081







-
+

-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

HWND
Tk_GetMenuHWND(
    TCL_UNUSED(Tk_Window))
    Tk_Window tkwin)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    TkMenuInit();
    return tsdPtr->embeddedMenuHWND;
}

/*
3248
3249
3250
3251
3252
3253
3254
3255

3256
3257
3258


3259
3260
3261
3262
3263
3264
3265
3092
3093
3094
3095
3096
3097
3098

3099
3100


3101
3102
3103
3104
3105
3106
3107
3108
3109







-
+

-
-
+
+







 *	Menus have to be reinitialized next time.
 *
 *----------------------------------------------------------------------
 */

static void
MenuExitHandler(
    TCL_UNUSED(void *))	    /* Not used */
    ClientData clientData)	    /* Not used */
{
    UnregisterClassW(MENU_CLASS_NAME, Tk_GetHINSTANCE());
    UnregisterClassW(EMBEDDED_MENU_CLASS_NAME, Tk_GetHINSTANCE());
    UnregisterClass(MENU_CLASS_NAME, Tk_GetHINSTANCE());
    UnregisterClass(EMBEDDED_MENU_CLASS_NAME, Tk_GetHINSTANCE());
}

/*
 *----------------------------------------------------------------------
 *
 * MenuExitHandler --
 *
3273
3274
3275
3276
3277
3278
3279
3280

3281
3282

3283
3284
3285
3286
3287
3288
3289
3117
3118
3119
3120
3121
3122
3123

3124
3125

3126
3127
3128
3129
3130
3131
3132
3133







-
+

-
+







 *	Menus have to be reinitialized next time.
 *
 *----------------------------------------------------------------------
 */

static void
MenuThreadExitHandler(
    TCL_UNUSED(void *))
    ClientData clientData)	    /* Not used */
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    DestroyWindow(tsdPtr->menuHWND);
    DestroyWindow(tsdPtr->embeddedMenuHWND);
    tsdPtr->menuHWND = NULL;
    tsdPtr->embeddedMenuHWND = NULL;

3308
3309
3310
3311
3312
3313
3314
3315

3316
3317

3318
3319
3320
3321
3322
3323

3324
3325

3326
3327
3328
3329
3330
3331
3332
3152
3153
3154
3155
3156
3157
3158

3159
3160

3161
3162
3163
3164
3165
3166

3167
3168

3169
3170
3171
3172
3173
3174
3175
3176







-
+

-
+





-
+

-
+







 *	Storage is allocated.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
TkWinGetMenuSystemDefault(
    TCL_UNUSED(Tk_Window),		/* A window to use. */
    Tk_Window tkwin,		/* A window to use. */
    const char *dbName,		/* The option database name. */
    TCL_UNUSED(const char *))	/* The name of the option class. */
    const char *className)	/* The name of the option class. */
{
    Tcl_Obj *valuePtr = NULL;

    if ((strcmp(dbName, "activeBorderWidth") == 0) ||
	    (strcmp(dbName, "borderWidth") == 0)) {
	valuePtr = Tcl_NewWideIntObj(defaultBorderWidth);
	valuePtr = Tcl_NewIntObj(defaultBorderWidth);
    } else if (strcmp(dbName, "font") == 0) {
	valuePtr = Tcl_NewStringObj(Tcl_DStringValue(&menuFontDString), TCL_INDEX_NONE);
	valuePtr = Tcl_NewStringObj(Tcl_DStringValue(&menuFontDString), -1);
    }

    return valuePtr;
}

/*
 *----------------------------------------------------------------------
3351
3352
3353
3354
3355
3356
3357
3358

3359
3360
3361
3362


3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374

3375
3376
3377
3378
3379
3380
3381


3382

3383
3384
3385
3386

3387
3388

3389
3390

3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407

3408
3409
3410
3411
3412
3413
3414
3195
3196
3197
3198
3199
3200
3201

3202
3203
3204
3205

3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218

3219
3220
3221
3222
3223
3224
3225
3226
3227
3228

3229
3230
3231
3232

3233
3234

3235
3236

3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253

3254
3255
3256
3257
3258
3259
3260
3261







-
+



-
+
+











-
+







+
+
-
+



-
+

-
+

-
+
















-
+







				 * called? */
{
    char sizeString[TCL_INTEGER_SPACE];
    char faceName[LF_FACESIZE];
    HDC scratchDC;
    int bold = 0;
    int italic = 0;
    TEXTMETRICW tm;
    TEXTMETRIC tm;
    int pointSize;
    HFONT menuFont;
    /* See: [Bug #3239768] tk8.4.19 (and later) WIN32 menu font support */
    NONCLIENTMETRICSW metrics;
    NONCLIENTMETRICS metrics;
    OSVERSIONINFOW os;

    /*
     * Set all of the default options. The loop will terminate when we run out
     * of options via a break statement.
     */

    defaultBorderWidth = GetSystemMetrics(SM_CXBORDER);
    if (GetSystemMetrics(SM_CYBORDER) > defaultBorderWidth) {
	defaultBorderWidth = GetSystemMetrics(SM_CYBORDER);
    }

    scratchDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
    scratchDC = CreateDCA("DISPLAY", NULL, NULL, NULL);
    if (!firstTime) {
	Tcl_DStringFree(&menuFontDString);
    }
    Tcl_DStringInit(&menuFontDString);

    metrics.cbSize = sizeof(metrics);

    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
    GetVersionExW(&os);
    if (TkWinGetPlatformTheme() != TK_THEME_WIN_VISTA) {
    if (os.dwMajorVersion < 6) {
	metrics.cbSize -= sizeof(int);
    }

    SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, metrics.cbSize,
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize,
	    &metrics, 0);
    menuFont = CreateFontIndirectW(&metrics.lfMenuFont);
    menuFont = CreateFontIndirect(&metrics.lfMenuFont);
    SelectObject(scratchDC, menuFont);
    GetTextMetricsW(scratchDC, &tm);
    GetTextMetrics(scratchDC, &tm);
    GetTextFaceA(scratchDC, LF_FACESIZE, faceName);
    pointSize = MulDiv(tm.tmHeight - tm.tmInternalLeading,
	    72, GetDeviceCaps(scratchDC, LOGPIXELSY));
    if (tm.tmWeight >= 700) {
	bold = 1;
    }
    if (tm.tmItalic) {
	italic = 1;
    }

    SelectObject(scratchDC, GetStockObject(SYSTEM_FONT));
    DeleteDC(scratchDC);

    DeleteObject(menuFont);

    Tcl_DStringAppendElement(&menuFontDString, faceName);
    snprintf(sizeString, sizeof(sizeString), "%d", pointSize);
    sprintf(sizeString, "%d", pointSize);
    Tcl_DStringAppendElement(&menuFontDString, sizeString);

    if (bold || italic) {
	Tcl_DString boldItalicDString;

	Tcl_DStringInit(&boldItalicDString);
	if (bold) {
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447

3448
3449
3450
3451
3452
3453
3454
3272
3273
3274
3275
3276
3277
3278

3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292

3293
3294
3295
3296
3297
3298
3299
3300







-














-
+







    /*
     * Now we go ahead and get the dimensions of the check mark and the
     * appropriate margins. Since this is fairly hairy, we do it here to save
     * time when traversing large sets of menu items.
     *
     * The code below was given to me by Microsoft over the phone. It is the
     * only way to ensure menu items line up, and is not documented.
     * How strange the calculation of indicatorDimensions[1] is...!
     */

    indicatorDimensions[0] = GetSystemMetrics(SM_CYMENUCHECK);
    indicatorDimensions[1] = ((GetSystemMetrics(SM_CXFIXEDFRAME) +
	    GetSystemMetrics(SM_CXBORDER)
	    + GetSystemMetrics(SM_CXMENUCHECK) + 7) & 0xFFF8)
	    - GetSystemMetrics(SM_CXFIXEDFRAME);

    /*
     * Accelerators used to be always underlines until Win2K when a system
     * parameter was introduced to hide them unless Alt is pressed.
     */

    showMenuAccelerators = TRUE;
    SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &showMenuAccelerators, 0);
    SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &showMenuAccelerators, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMenuInit --
 *
3462
3463
3464
3465
3466
3467
3468
3469

3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481

3482
3483
3484
3485
3486
3487

3488
3489
3490
3491
3492
3493
3494
3308
3309
3310
3311
3312
3313
3314

3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326

3327
3328
3329
3330
3331
3332

3333
3334
3335
3336
3337
3338
3339
3340







-
+











-
+





-
+







 *
 *----------------------------------------------------------------------
 */

void
TkpMenuInit(void)
{
    WNDCLASSW wndClass;
    WNDCLASS wndClass;

    wndClass.style = CS_OWNDC;
    wndClass.lpfnWndProc = TkWinMenuProc;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hInstance = Tk_GetHINSTANCE();
    wndClass.hIcon = NULL;
    wndClass.hCursor = NULL;
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = MENU_CLASS_NAME;
    if (!RegisterClassW(&wndClass)) {
    if (!RegisterClass(&wndClass)) {
	Tcl_Panic("Failed to register menu window class");
    }

    wndClass.lpfnWndProc = TkWinEmbeddedMenuProc;
    wndClass.lpszClassName = EMBEDDED_MENU_CLASS_NAME;
    if (!RegisterClassW(&wndClass)) {
    if (!RegisterClass(&wndClass)) {
	Tcl_Panic("Failed to register embedded menu window class");
    }

    TkCreateExitHandler(MenuExitHandler, NULL);
    SetDefaults(1);
}

3508
3509
3510
3511
3512
3513
3514
3515

3516
3517
3518

3519
3520
3521
3522
3523
3524
3525
3526

3527
3528
3529
3530
3531
3532
3533
3354
3355
3356
3357
3358
3359
3360

3361
3362
3363

3364
3365
3366
3367
3368
3369
3370
3371

3372
3373
3374
3375
3376
3377
3378
3379







-
+


-
+







-
+







 *
 *----------------------------------------------------------------------
 */

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

    tsdPtr->menuHWND = CreateWindowW(MENU_CLASS_NAME, L"MenuWindow", WS_POPUP,
    tsdPtr->menuHWND = CreateWindow(MENU_CLASS_NAME, TEXT("MenuWindow"), WS_POPUP,
	    0, 0, 10, 10, NULL, NULL, Tk_GetHINSTANCE(), NULL);

    if (!tsdPtr->menuHWND) {
	Tcl_Panic("Failed to create the menu window");
    }

    tsdPtr->embeddedMenuHWND =
	    CreateWindowW(EMBEDDED_MENU_CLASS_NAME, L"EmbeddedMenuWindow",
	    CreateWindow(EMBEDDED_MENU_CLASS_NAME, TEXT("EmbeddedMenuWindow"),
	    WS_POPUP, 0, 0, 10, 10, NULL, NULL, Tk_GetHINSTANCE(), NULL);

    if (!tsdPtr->embeddedMenuHWND) {
	Tcl_Panic("Failed to create the embedded menu window");
    }

    Tcl_InitHashTable(&tsdPtr->winMenuTable, TCL_ONE_WORD_KEYS);

Changes to win/tkWinPixmap.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkWinPixmap.c --
 *
 *	This file contains the Xlib emulation functions pertaining to creating
 *	and destroying pixmaps.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

36
37
38
39
40
41
42
43

44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61

62
63
64
65
66
67
68
36
37
38
39
40
41
42

43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60

61
62
63
64
65
66
67
68







-
+

-
+













-
+

-
+







    int height,
    int depth)
{
    TkWinDrawable *newTwdPtr, *twdPtr;
    int planes;
    Screen *screen;

    LastKnownRequestProcessed(display)++;
    display->request++;

    newTwdPtr = (TkWinDrawable *)ckalloc(sizeof(TkWinDrawable));
    newTwdPtr = ckalloc(sizeof(TkWinDrawable));
    newTwdPtr->type = TWD_BITMAP;
    newTwdPtr->bitmap.depth = depth;
    twdPtr = (TkWinDrawable *) d;
    if (twdPtr->type != TWD_BITMAP) {
	if (twdPtr->window.winPtr == NULL) {
	    newTwdPtr->bitmap.colormap = DefaultColormap(display,
		    DefaultScreen(display));
	} else {
	    newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap;
	}
    } else {
	newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap;
    }
    screen = ScreenOfDisplay(display, 0);
    screen = &display->screens[0];
    planes = 1;
    if (depth == DefaultDepthOfScreen(screen)) {
    if (depth == screen->root_depth) {
	planes = PTR2INT(screen->ext_data);
	depth /= planes;
    }
    newTwdPtr->bitmap.handle =
	    CreateBitmap(width, height, (DWORD) planes, (DWORD) depth, NULL);

    /*
96
97
98
99
100
101
102
103

104
105
106
107
108
109



110
111
112
113
114
115
116
96
97
98
99
100
101
102

103
104
105
106



107
108
109
110
111
112
113
114
115
116







-
+



-
-
-
+
+
+







	 * people to report this as a bug...
	 */

	if (newTwdPtr->bitmap.handle == NULL && !repeatError) {
	    LPVOID lpMsgBuf;

	    repeatError = 1;
	    if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
	    if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
		    FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
		    NULL, GetLastError(),
		    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		    (LPWSTR)&lpMsgBuf, 0, NULL)) {
		MessageBoxW(NULL, (LPWSTR) lpMsgBuf,
			L"Tk_GetPixmap: Error from CreateDIBSection",
		    (LPSTR) &lpMsgBuf, 0, NULL)) {
		MessageBoxA(NULL, (LPCSTR) lpMsgBuf,
			"Tk_GetPixmap: Error from CreateDIBSection",
			MB_OK | MB_ICONINFORMATION);
		LocalFree(lpMsgBuf);
	    }
	}
    }

    if (newTwdPtr->bitmap.handle == NULL) {
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154







-
+







void
Tk_FreePixmap(
    Display *display,
    Pixmap pixmap)
{
    TkWinDrawable *twdPtr = (TkWinDrawable *) pixmap;

    LastKnownRequestProcessed(display)++;
    display->request++;
    if (twdPtr != NULL) {
	DeleteObject(twdPtr->bitmap.handle);
	ckfree(twdPtr);
    }
}

/*
193
194
195
196
197
198
199
200

201
202
203
204



205
206
207
208


209
210
211
212
213
214
215
193
194
195
196
197
198
199

200
201



202
203
204
205
206


207
208
209
210
211
212
213
214
215







-
+

-
-
-
+
+
+


-
-
+
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

int
XGetGeometry(
    TCL_UNUSED(Display *),
    Display *display,
    Drawable d,
    TCL_UNUSED(Window *),
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    Window *root_return,
    int *x_return,
    int *y_return,
    unsigned int *width_return,
    unsigned int *height_return,
    TCL_UNUSED(unsigned int *),
    TCL_UNUSED(unsigned int *))
    unsigned int *border_width_return,
    unsigned int *depth_return)
{
    TkWinDrawable *twdPtr = (TkWinDrawable *)d;

    if (twdPtr->type == TWD_BITMAP) {
	HDC dc;
	BITMAPINFO info;

Changes to win/tkWinPointer.c.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
1
2
3
4
5


6
7
8
9
10
11
12
13
14





-
-
+
+







/*
 * tkWinPointer.c --
 *
 *	Windows specific mouse tracking code.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 1998-1999 Scriptics Corporation.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-
+







static Tcl_TimerToken mouseTimer;	/* Handle to the latest mouse timer. */
static int mouseTimerSet = 0;		/* 1 if the mouse timer is active. */

/*
 * Forward declarations of procedures used in this file.
 */

static void		MouseTimerProc(void *clientData);
static void		MouseTimerProc(ClientData clientData);

/*
 *----------------------------------------------------------------------
 *
 * TkWinGetModifierState --
 *
 *	Return the modifier state as of the last message.
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
77
78
79
80
81
82
83






84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113







-
-
-
-
-
-






-
+















-
+







    }
    if (GetKeyState(VK_MBUTTON) & 0x8000) {
	state |= Button2Mask;
    }
    if (GetKeyState(VK_RBUTTON) & 0x8000) {
	state |= Button3Mask;
    }
    if (GetKeyState(VK_XBUTTON1) & 0x8000) {
	state |= Button4Mask;
    }
    if (GetKeyState(VK_XBUTTON2) & 0x8000) {
	state |= Button5Mask;
    }
    return state;
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinPointerEvent --
 * Tk_PointerEvent --
 *
 *	This procedure is called for each pointer-related event. It converts
 *	the position to root coords and updates the global pointer state
 *	machine. It also ensures that the mouse timer is scheduled.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May queue events and change the grab state.
 *
 *----------------------------------------------------------------------
 */

void
TkWinPointerEvent(
Tk_PointerEvent(
    HWND hwnd,			/* Window for coords, or NULL for the root
				 * window. */
    int x, int y)		/* Coords relative to hwnd, or screen if hwnd
				 * is NULL. */
{
    POINT pos;
    int state;
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
169
170
171
172
173
174
175






176
177
178
179
180
181
182







-
-
-
-
-
-







    Display *display,
    Window grab_window,
    Bool owner_events,
    int pointer_mode,
    int keyboard_mode,
    Time time)
{
    (void)display;
    (void)owner_events;
    (void)pointer_mode;
    (void)keyboard_mode;
    (void)time;

    keyboardWinPtr = TkWinGetWinPtr(grab_window);
    return GrabSuccess;
}

/*
 *----------------------------------------------------------------------
 *
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
194
195
196
197
198
199
200



201
202
203
204
205
206
207







-
-
-







 */

int
XUngrabKeyboard(
    Display *display,
    Time time)
{
    (void)display;
    (void)time;

    keyboardWinPtr = NULL;
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
231
232
233
234
235
236
237
238

239
240
241
242
243





244
245

246
247
248
249
250
251
252
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
242







-
+





+
+
+
+
+

-
+







 *	May schedule a new timer and/or generate enter/leave events.
 *
 *----------------------------------------------------------------------
 */

void
MouseTimerProc(
    TCL_UNUSED(void *))
    ClientData clientData)
{
    POINT pos;

    mouseTimerSet = 0;

    /*
     * Get the current mouse position and window. Don't do anything if the
     * mouse hasn't moved since the last time we looked.
     */

    GetCursorPos(&pos);
    TkWinPointerEvent(NULL, pos.x, pos.y);
    Tk_PointerEvent(NULL, pos.x, pos.y);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinCancelMouseTimer --
 *
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
280
281
282
283
284
285
286

287
288
289
290
291
292
293







-







void
TkGetPointerCoords(
    Tk_Window tkwin,		/* Window that identifies screen on which
				 * lookup is to be done. */
    int *xPtr, int *yPtr)	/* Store pointer coordinates here. */
{
    POINT point;
    (void)tkwin;

    GetCursorPos(&point);
    *xPtr = point.x;
    *yPtr = point.y;
}

/*
319
320
321
322
323
324
325
326
327
328



329
330
331
332


333
334
335

336
337
338
339
340
341
342
343
344

345
346
347


348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
437
438
439
440

441
442

443
444
445
446
447
448
449
308
309
310
311
312
313
314



315
316
317
318
319


320
321
322
323

324
325
326
327
328
329
330
331
332

333
334


335
336
337
338
339
340
341
342
343
344
345
346

















































347
348
349
350
351
352
353
354
355
356
357
358
359






360
361

362
363
364
365
366
367
368
369
370
371
372
373

374
375

376
377
378
379
380
381
382
383







-
-
-
+
+
+


-
-
+
+


-
+








-
+

-
-
+
+










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-













-
-
-
-
-
-


-
+











-
+

-
+







 *
 *----------------------------------------------------------------------
 */

Bool
XQueryPointer(
    Display *display,
    TCL_UNUSED(Window),
    TCL_UNUSED(Window *),
    TCL_UNUSED(Window *),
    Window w,
    Window *root_return,
    Window *child_return,
    int *root_x_return,
    int *root_y_return,
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    int *win_x_return,
    int *win_y_return,
    unsigned int *mask_return)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    TkGetPointerCoords(NULL, root_x_return, root_y_return);
    *mask_return = TkWinGetModifierState();
    return True;
}

/*
 *----------------------------------------------------------------------
 *
 * XWarpPointer, TkpWarpPointer --
 * XWarpPointer --
 *
 *	Move pointer to new location. Note that implementation of XWarpPointer
 *	is incomplete.
 *	Move pointer to new location. This is not a complete implementation of
 *	this function.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Mouse pointer changes position on screen.
 *
 *----------------------------------------------------------------------
 */

/*
 * TkSetCursorPos is a helper function replacing SetCursorPos since this
 * latter Windows function appears to have been broken by Microsoft
 * since Win10 Falls Creator Update - See ticket [69b48f427e] along with
 * several other Internet reports about this breakage.
 */

void TkSetCursorPos(
    int x,
    int y)
{
    INPUT input;
    int xscreen = (int)(GetSystemMetrics(SM_CXSCREEN) - 1);
    int yscreen = (int)(GetSystemMetrics(SM_CYSCREEN) - 1);

    /*
     * A multi-screen system may have different logical pixels/inch, with
     * Windows applying behind-the-scenes scaling on secondary screens.
     * Don't try and emulate that, instead fall back to SetCursor if the
     * requested position is off the primary screen.
     */
    if ( x < 0 || x > xscreen || y < 0 || y > yscreen ) {
        SetCursorPos(x, y);
        return;
    }

    input.type = INPUT_MOUSE;
    input.mi.dx = (x * 65535 + xscreen/2) / xscreen;
    input.mi.dy = (y * 65535 + yscreen/2) / yscreen;

    /*
     * Horrible workaround here. There is a bug on Win 10: when warping to
     * pixel (x = 0, y = 0) the SendInput() below just does not move the
     * mouse pointer. However, as soon as dx or dy is non zero it moves as
     * expected. Given the scaling factor of 65535 (see above),
     * (dx = 1 , dy = 0) still means pixel (x = 0, y = 0).
     * See ticket [69b48f427e].
     */
    if (input.mi.dx == 0 && input.mi.dy == 0) {
        input.mi.dx = 1;
    }

    input.mi.mouseData = 0;
    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
    input.mi.time = 0;
    input.mi.dwExtraInfo = 0;
    SendInput(1, &input, sizeof(input));
}

int
XWarpPointer(
    Display *display,
    Window src_w,
    Window dest_w,
    int src_x,
    int src_y,
    unsigned int src_width,
    unsigned int src_height,
    int dest_x,
    int dest_y)
{
    RECT r;
    (void)display;
    (void)src_w;
    (void)src_x;
    (void)src_y;
    (void)src_width;
    (void)src_height;

    GetWindowRect(Tk_GetHWND(dest_w), &r);
    TkSetCursorPos(r.left+dest_x, r.top+dest_y);
    SetCursorPos(r.left+dest_x, r.top+dest_y);
    return Success;
}

void
TkpWarpPointer(
    TkDisplay *dispPtr)
{
    if (dispPtr->warpWindow) {
	RECT r;

	GetWindowRect(Tk_GetHWND(Tk_WindowId(dispPtr->warpWindow)), &r);
	TkSetCursorPos(r.left + dispPtr->warpX, r.top + dispPtr->warpY);
	SetCursorPos(r.left + dispPtr->warpX, r.top + dispPtr->warpY);
    } else {
	TkSetCursorPos(dispPtr->warpX, dispPtr->warpY);
	SetCursorPos(dispPtr->warpX, dispPtr->warpY);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * XGetInputFocus --
463
464
465
466
467
468
469
470

471
472

473
474
475
476
477
478
479
397
398
399
400
401
402
403

404
405

406
407
408
409
410
411
412
413







-
+

-
+







XGetInputFocus(
    Display *display,
    Window *focus_return,
    int *revert_to_return)
{
    Tk_Window tkwin = Tk_HWNDToWindow(GetFocus());

    *focus_return = tkwin ? Tk_WindowId(tkwin) : 0;
    *focus_return = tkwin ? Tk_WindowId(tkwin) : None;
    *revert_to_return = RevertToParent;
    LastKnownRequestProcessed(display)++;
    display->request++;
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XSetInputFocus --
490
491
492
493
494
495
496
497
498


499
500

501
502
503
504
505
506
507
424
425
426
427
428
429
430


431
432
433

434
435
436
437
438
439
440
441







-
-
+
+

-
+







 *----------------------------------------------------------------------
 */

int
XSetInputFocus(
    Display *display,
    Window focus,
    TCL_UNUSED(int),
    TCL_UNUSED(Time))
    int revert_to,
    Time time)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    if (focus != None) {
	SetFocus(Tk_GetHWND(focus));
    }
    return Success;
}

/*
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
532
533
534
535
536
537
538























539
540
541
542
543
544
545
546







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








	SetCapture(Tk_GetHWND(Tk_WindowId(winPtr)));
	captured = 1;
    } else {
	captured = 0;
	ReleaseCapture();
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetCapture --
 *
 *	This function requests which window is capturing the mouse.
 *
 * Results:
 *	The return value is a pointer to the capture window, if there is
 *      one, otherwise it is NULL.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
TkpGetCapture(void)
{
    return Tk_HWNDToWindow(GetCapture());
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinPort.h.

17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
17
18
19
20
21
22
23

24
25

26
27
28
29
30
31
32
33







-


-
+







/*
 *---------------------------------------------------------------------------
 * The following sets of #includes and #ifdefs are required to get Tcl to
 * compile under the windows compilers.
 *---------------------------------------------------------------------------
 */

#include <stdio.h>
#include <wchar.h>
#include <io.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <limits.h>
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
59
60
61
62
63
64
65



66
67
68
69
70
71
72







-
-
-







#   define _TCHAR_DEFINED
#endif
#if defined(_MSC_VER) && defined(__STDC__)
    /* VS2005 SP1 misses this. See [Bug #3110161] */
    typedef _TCHAR TCHAR;
#endif

#if defined(__GNUC__) && !defined(__cplusplus)
#   pragma GCC diagnostic ignored "-Wc++-compat"
#endif
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

#ifndef __GNUC__
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126









127
86
87
88
89
90
91
92






93



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123







-
-
-
-
-
-

-
-
-




















+
+
+
+
+
+
+
+
+


#define REDO_KEYSYM_LOOKUP

/*
 * See ticket [916c1095438eae56]: GetVersionExW triggers warnings
 */
#if defined(_MSC_VER)
#   pragma warning(disable:4090) /* see: https://developercommunity.visualstudio.com/t/c-compiler-incorrect-propagation-of-const-qualifie/390711 */
#   pragma warning(disable:4146)
#   pragma warning(disable:4267)
#   pragma warning(disable:4244)
#   pragma warning(disable:4311)
#   pragma warning(disable:4312)
#   pragma warning(disable:4996)
#if !defined(_WIN64)
#   pragma warning(disable:4305)
#endif
#endif

/*
 * The following macro checks to see whether there is buffered
 * input data available for a stdio FILE.
 */

#ifdef _MSC_VER
#    define TK_READ_DATA_PENDING(f) ((f)->_cnt > 0)
#else /* _MSC_VER */
#    define TK_READ_DATA_PENDING(f) ((f)->level > 0)
#endif /* _MSC_VER */

/*
 * The following Tk functions are implemented as macros under Windows.
 */

#define TkpGetPixel(p) (((((p)->red >> 8) & 0xff) \
	| ((p)->green & 0xff00) | (((p)->blue << 8) & 0xff0000)) | 0x20000000)

/*
 * These calls implement native bitmaps which are not currently
 * supported under Windows.  The macros eliminate the calls.
 */

#define TkpDefineNativeBitmaps()
#define TkpCreateNativeBitmap(display, source) None
#define TkpGetNativeAppBitmap(display, name, w, h) None

#endif /* _WINPORT */

Changes to win/tkWinRegion.c.

1
2
3
4
5
6

7
8
9
10
11
12
13







14
15
16
17
18
19
20
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27





-
+







+
+
+
+
+
+
+







/*
 * tkWinRegion.c --
 *
 *	Tk Region emulation code.
 *
 * Copyright © 1995 Sun Microsystems, Inc.
 * Copyright (c) 1995 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"

#undef TkCreateRegion
#undef TkDestroyRegion
#undef TkClipBox
#undef TkIntersectRegion
#undef TkUnionRectWithRegion
#undef TkRectInRegion
#undef TkSubtractRegion

/*
 *----------------------------------------------------------------------
 *
 * TkCreateRegion --
 *
 *	Construct an empty region.
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
55
56
57
58
59
60
61

62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158







-
+




-


















-
+











-


















-
+






-


















-
+











-







 *
 * Side effects:
 *	Frees the storage associated with the specified region.
 *
 *----------------------------------------------------------------------
 */

int
void
TkDestroyRegion(
    TkRegion r)
{
    DeleteObject((HRGN) r);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkClipBox --
 *
 *	Computes the bounding box of a region.
 *
 * Results:
 *	Sets rect_return to the bounding box of the region.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
TkClipBox(
    TkRegion r,
    XRectangle* rect_return)
{
    RECT rect;

    GetRgnBox((HRGN)r, &rect);
    rect_return->x = (short) rect.left;
    rect_return->y = (short) rect.top;
    rect_return->width = (short) (rect.right - rect.left);
    rect_return->height = (short) (rect.bottom - rect.top);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkIntersectRegion --
 *
 *	Compute the intersection of two regions.
 *
 * Results:
 *	Returns the result in the dr_return region.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
TkIntersectRegion(
    TkRegion sra,
    TkRegion srb,
    TkRegion dr_return)
{
    CombineRgn((HRGN) dr_return, (HRGN) sra, (HRGN) srb, RGN_AND);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkUnionRectWithRegion --
 *
 *	Create the union of a source region and a rectangle.
 *
 * Results:
 *	Returns the result in the dr_return region.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
TkUnionRectWithRegion(
    XRectangle *rectangle,
    TkRegion src_region,
    TkRegion dest_region_return)
{
    HRGN rectRgn = CreateRectRgn(rectangle->x, rectangle->y,
	    rectangle->x + rectangle->width, rectangle->y + rectangle->height);

    CombineRgn((HRGN) dest_region_return, (HRGN) src_region,
	    (HRGN) rectRgn, RGN_OR);
    DeleteObject(rectRgn);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpBuildRegionFromAlphaData --
 *
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
266
267
268
269
270
271
272

273
274
275
276
277
278
279

























280
281
282
283
284
285
286
287
288







-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
void
TkSubtractRegion(
    TkRegion sra,
    TkRegion srb,
    TkRegion dr_return)
{
    CombineRgn((HRGN) dr_return, (HRGN) sra, (HRGN) srb, RGN_DIFF);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCopyRegion --
 *
 *  Makes the destination region a copy of the source region.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpCopyRegion(
    TkRegion dst,
    TkRegion src)
{
    CombineRgn((HRGN)dst, (HRGN)src, NULL, RGN_COPY);
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinScrlbr.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * tkWinScrollbar.c --
 *
 *	This file implements the Windows specific portion of the scrollbar
 *	widget.
 *
 * Copyright © 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include "tkScrollbar.h"
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85

86
87
88
89
90
91
92
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84

85
86
87
88
89
90
91
92







-
+


















-
+

-
+







TCL_DECLARE_MUTEX(winScrlbrMutex)

/*
 * Declarations for functions defined in this file.
 */

static Window		CreateProc(Tk_Window tkwin, Window parent,
			    void *instanceData);
			    ClientData instanceData);
static void		ModalLoop(WinScrollbar *, XEvent *eventPtr);
static LRESULT CALLBACK	ScrollbarProc(HWND hwnd, UINT message, WPARAM wParam,
			    LPARAM lParam);
static void		UpdateScrollbar(WinScrollbar *scrollPtr);
static void		UpdateScrollbarMetrics(void);

/*
 * The class procedure table for the scrollbar widget.
 */

const Tk_ClassProcs tkpScrollbarProcs = {
    sizeof(Tk_ClassProcs),	/* size */
    NULL,			/* worldChangedProc */
    CreateProc,			/* createProc */
    NULL 			/* modalProc */
};

static void
WinScrollbarEventProc(void *clientData, XEvent *eventPtr)
WinScrollbarEventProc(ClientData clientData, XEvent *eventPtr)
{
    WinScrollbar *scrollPtr = (WinScrollbar *)clientData;
    WinScrollbar *scrollPtr = clientData;

    if (eventPtr->type == ButtonPress) {
	ModalLoop(scrollPtr, eventPtr);
    } else {
	TkScrollbarEventProc(clientData, eventPtr);
    }
}
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131







-
+







    if (!initialized) {
	Tcl_MutexLock(&winScrlbrMutex);
	UpdateScrollbarMetrics();
	initialized = 1;
	Tcl_MutexUnlock(&winScrlbrMutex);
    }

    scrollPtr = (WinScrollbar *)ckalloc(sizeof(WinScrollbar));
    scrollPtr = ckalloc(sizeof(WinScrollbar));
    scrollPtr->winFlags = 0;
    scrollPtr->hwnd = NULL;

    Tk_CreateEventHandler(tkwin,
	    ExposureMask|StructureNotifyMask|FocusChangeMask|ButtonPressMask,
	    WinScrollbarEventProc, scrollPtr);

201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233







-
+

















-
+







 *----------------------------------------------------------------------
 */

static Window
CreateProc(
    Tk_Window tkwin,		/* Token for window. */
    Window parentWin,		/* Parent of new window. */
    void *instanceData)	/* Scrollbar instance data. */
    ClientData instanceData)	/* Scrollbar instance data. */
{
    DWORD style;
    Window window;
    HWND parent;
    TkWindow *winPtr;
    WinScrollbar *scrollPtr = (WinScrollbar *)instanceData;

    parent = Tk_GetHWND(parentWin);

    if (scrollPtr->info.vertical) {
	style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS
		| SBS_VERT;
    } else {
	style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS
		| SBS_HORZ;
    }

    scrollPtr->hwnd = CreateWindowW(L"SCROLLBAR", NULL, style,
    scrollPtr->hwnd = CreateWindow(TEXT("SCROLLBAR"), NULL, style,
	    Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
	    parent, NULL, Tk_GetHINSTANCE(), NULL);

    /*
     * Ensure new window is inserted into the stacking order at the correct
     * place.
     */
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255







-
+







	    TkWinSetWindowPos(scrollPtr->hwnd, Tk_GetHWND(winPtr->window),
		    Below);
	    break;
	}
    }

    scrollPtr->lastVertical = scrollPtr->info.vertical;
    scrollPtr->oldProc = (WNDPROC)SetWindowLongPtrW(scrollPtr->hwnd,
    scrollPtr->oldProc = (WNDPROC)SetWindowLongPtr(scrollPtr->hwnd,
	    GWLP_WNDPROC, (LONG_PTR) ScrollbarProc);
    window = Tk_AttachHWND(tkwin, scrollPtr->hwnd);

    UpdateScrollbar(scrollPtr);
    return window;
}

269
270
271
272
273
274
275
276

277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

295
296
297
298

299
300
301
302
303
304
305
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297

298
299
300
301
302
303
304
305







-
+

-
+















-
+



-
+







 *	Information appears on the screen.
 *
 *--------------------------------------------------------------
 */

void
TkpDisplayScrollbar(
    void *clientData)	/* Information about window. */
    ClientData clientData)	/* Information about window. */
{
    WinScrollbar *scrollPtr = (WinScrollbar *)clientData;
    WinScrollbar *scrollPtr = (WinScrollbar *) clientData;
    Tk_Window tkwin = scrollPtr->info.tkwin;

    scrollPtr->info.flags &= ~REDRAW_PENDING;
    if ((tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }

    /*
     * Destroy and recreate the scrollbar control if the orientation has
     * changed.
     */

    if (scrollPtr->lastVertical != scrollPtr->info.vertical) {
	HWND hwnd = Tk_GetHWND(Tk_WindowId(tkwin));

	SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR) scrollPtr->oldProc);
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) scrollPtr->oldProc);
	DestroyWindow(hwnd);

	CreateProc(tkwin, Tk_WindowId(Tk_Parent(tkwin)),
		scrollPtr);
		(ClientData) scrollPtr);
    } else {
	UpdateScrollbar(scrollPtr);
    }
}

/*
 *----------------------------------------------------------------------
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335







-
+







TkpDestroyScrollbar(
    TkScrollbar *scrollPtr)
{
    WinScrollbar *winScrollPtr = (WinScrollbar *)scrollPtr;
    HWND hwnd = winScrollPtr->hwnd;

    if (hwnd) {
	SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (INT_PTR) winScrollPtr->oldProc);
	SetWindowLongPtr(hwnd, GWLP_WNDPROC, (INT_PTR) winScrollPtr->oldProc);
	if (winScrollPtr->winFlags & IN_MODAL_LOOP) {
	    ((TkWindow *)scrollPtr->tkwin)->flags |= TK_DONT_DESTROY_WINDOW;
	    SetParent(hwnd, NULL);
	}
    }
    winScrollPtr->winFlags |= ALREADY_DEAD;
}
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370







-
+







    int arrowWidth = GetSystemMetrics(SM_CXVSCROLL);

    hArrowWidth = GetSystemMetrics(SM_CXHSCROLL);
    hThumb = GetSystemMetrics(SM_CXHTHUMB);
    vArrowHeight = GetSystemMetrics(SM_CYVSCROLL);
    vThumb = GetSystemMetrics(SM_CYVTHUMB);

    snprintf(tkDefScrollbarWidth, sizeof(tkDefScrollbarWidth), "%d", arrowWidth);
    sprintf(tkDefScrollbarWidth, "%d", arrowWidth);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpComputeScrollbarGeometry --
 *
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
379
380
381
382
383
384
385

386
387
388
389
390
391
392
393







-
+







 *	The scrollbar will be displayed differently.
 *
 *----------------------------------------------------------------------
 */

void
TkpComputeScrollbarGeometry(
    TkScrollbar *scrollPtr)
    register TkScrollbar *scrollPtr)
				/* Scrollbar whose geometry may have
				 * changed. */
{
    int fieldLength, minThumbSize;

    /*
     * Windows doesn't use focus rings on scrollbars, but we still perform
493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507







-
+







    case WM_VSCROLL: {
	Tcl_Interp *interp;
	Tcl_DString cmdString;
	int command = LOWORD(wParam);
	int code;

	GetCursorPos(&point);
	TkTranslateWinEvent(NULL, WM_MOUSEMOVE, 0,
	Tk_TranslateWinEvent(NULL, WM_MOUSEMOVE, 0,
		MAKELPARAM(point.x, point.y), &result);

	if (command == SB_ENDSCROLL) {
	    return 0;
	}

	/*
548
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563
564
565
566
567

568
569
570
571

572
573
574
575
576
577
578
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570

571
572
573
574
575
576
577
578







-
+











-
+



-
+








	    Tcl_PrintDouble(NULL, pos, valueString);
	    Tcl_DStringAppendElement(&cmdString, "moveto");
	    Tcl_DStringAppendElement(&cmdString, valueString);
	}

	interp = scrollPtr->info.interp;
	code = Tcl_EvalEx(interp, cmdString.string, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	code = Tcl_EvalEx(interp, cmdString.string, -1, TCL_EVAL_GLOBAL);
	if (code != TCL_OK && code != TCL_CONTINUE && code != TCL_BREAK) {
	    Tcl_AddErrorInfo(interp, "\n    (scrollbar command)");
	    Tcl_BackgroundException(interp, code);
	}
	Tcl_DStringFree(&cmdString);

	Tcl_ServiceAll();
	return 0;
    }

    default:
	if (TkTranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	if (Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	    return result;
	}
    }
    return CallWindowProcW(scrollPtr->oldProc, hwnd, message, wParam, lParam);
    return CallWindowProc(scrollPtr->oldProc, hwnd, message, wParam, lParam);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpConfigureScrollbar --
 *
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpConfigureScrollbar(
    TCL_UNUSED(TkScrollbar *))
    register TkScrollbar *scrollPtr)
				/* Information about widget; may or may not
				 * already have values for some fields. */
{
}

/*
 *----------------------------------------------------------------------
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629

630
631
632
633
634
635
636
613
614
615
616
617
618
619

620
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
636







-
+








-
+







ModalLoop(
    WinScrollbar *scrollPtr,
    XEvent *eventPtr)
{
    int oldMode;

    if (scrollPtr->hwnd) {
	Tcl_Preserve(scrollPtr);
	Tcl_Preserve((ClientData)scrollPtr);
	scrollPtr->winFlags |= IN_MODAL_LOOP;
	oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	TkWinResendEvent(scrollPtr->oldProc, scrollPtr->hwnd, eventPtr);
	(void) Tcl_SetServiceMode(oldMode);
	scrollPtr->winFlags &= ~IN_MODAL_LOOP;
	if (scrollPtr->hwnd && scrollPtr->winFlags & ALREADY_DEAD) {
	    DestroyWindow(scrollPtr->hwnd);
	}
	Tcl_Release(scrollPtr);
	Tcl_Release((ClientData)scrollPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkpScrollbarPosition --
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
646
647
648
649
650
651
652

653
654
655
656
657
658
659
660







-
+







 *	None.
 *
 *--------------------------------------------------------------
 */

int
TkpScrollbarPosition(
    TkScrollbar *scrollPtr,
    register TkScrollbar *scrollPtr,
				/* Scrollbar widget record. */
    int x, int y)		/* Coordinates within scrollPtr's window. */
{
    int length, width, tmp;

    if (scrollPtr->vertical) {
	length = Tk_Height(scrollPtr->tkwin);

Changes to win/tkWinSend.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22






-
-
+
+







-







/*
 * tkWinSend.c --
 *
 *	This file provides functions that implement the "send" command,
 *	allowing commands to be passed from interpreter to interpreter.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright © 2003 Pat Thoyts <[email protected]>
 * Copyright (c) 1997 by Sun Microsystems, Inc.
 * Copyright (c) 2003 Pat Thoyts <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkWinSendCom.h"
#include "tkWinInt.h"

/*
 * Should be defined in WTypes.h but mingw 1.0 is missing them.
 */

#ifndef _ROTFLAGS_DEFINED
#define _ROTFLAGS_DEFINED
59
60
61
62
63
64
65
66



67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+
+
+










-
+







#endif /* TK_SEND_ENABLED_ON_WINDOWS */

/*
 * Functions internal to this file.
 */

#ifdef TK_SEND_ENABLED_ON_WINDOWS
static Tcl_CmdDeleteProc CmdDeleteProc;
static void		CmdDeleteProc(ClientData clientData);
static void		InterpDeleteProc(ClientData clientData,
			    Tcl_Interp *interp);
static void		RevokeObjectRegistration(RegisteredInterp *riPtr);
#endif /* TK_SEND_ENABLED_ON_WINDOWS */
static HRESULT		BuildMoniker(const char *name, LPMONIKER *pmk);
#ifdef TK_SEND_ENABLED_ON_WINDOWS
static HRESULT		RegisterInterp(const char *name,
			    RegisteredInterp *riPtr);
#endif /* TK_SEND_ENABLED_ON_WINDOWS */
static int		FindInterpreterObject(Tcl_Interp *interp,
			    const char *name, LPDISPATCH *ppdisp);
static int		Send(LPDISPATCH pdispInterp, Tcl_Interp *interp,
			    int async, void *clientData, Tcl_Size objc,
			    int async, ClientData clientData, int objc,
			    Tcl_Obj *const objv[]);
static void		SendTrace(const char *format, ...);
static Tcl_EventProc	SendEventProc;

#if defined(DEBUG) || defined(_DEBUG)
#define TRACE SendTrace
#else
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
117
118
119
120
121
122
123


124
125
126
127
128
129
130







-
-







				 * be named: it is just used to identify the
				 * application and the display.  */
    const char *name)		/* The name that will be used to refer to the
				 * interpreter in later "send" commands. Must
				 * be globally unique. */
{
#ifndef TK_SEND_ENABLED_ON_WINDOWS
    (void)tkwin;

    /*
     * Temporarily disabled for bug #858822
     */

    return name;
#else /* TK_SEND_ENABLED_ON_WINDOWS */

142
143
144
145
146
147
148
149

150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
141
142
143
144
145
146
147

148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173







-
+




-
+












-
+







     * Initialise the COM library for this interpreter just once.
     */

    if (tsdPtr->initialized == 0) {
	hr = CoInitialize(0);
	if (FAILED(hr)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "failed to initialize the COM library", TCL_INDEX_NONE));
		    "failed to initialize the COM library", -1));
	    Tcl_SetErrorCode(interp, "TK", "SEND", "COM", NULL);
	    return "";
	}
	tsdPtr->initialized = 1;
	TRACE("Initialized COM library for interp 0x%" TCL_Z_MODIFIER "x\n", (size_t)interp);
	TRACE("Initialized COM library for interp 0x%08X\n", (long)interp);
    }

    /*
     * If the interp hasn't been registered before then we need to create the
     * registration structure and the COM object. If it has been registered
     * already then we can reuse all and just register the new name.
     */

    riPtr = Tcl_GetAssocData(interp, "tkWinSend::ri", NULL);
    if (riPtr == NULL) {
	LPUNKNOWN *objPtr;

	riPtr = (RegisteredInterp *)ckalloc(sizeof(RegisteredInterp));
	riPtr = ckalloc(sizeof(RegisteredInterp));
	memset(riPtr, 0, sizeof(RegisteredInterp));
	riPtr->interp = interp;

	objPtr = &riPtr->obj;
	hr = TkWinSendCom_CreateInstance(interp, &IID_IUnknown,
		(void **) objPtr);

206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
205
206
207
208
209
210
211

212
213
214
215

216
217
218
219
220
221
222







-
+



-







 *
 *----------------------------------------------------------------------
 */

int
TkGetInterpNames(
    Tcl_Interp *interp,		/* Interpreter for returning a result. */
    TCL_UNUSED(Tk_Window))	/* Window whose display is to be used for the
    Tk_Window tkwin)		/* Window whose display is to be used for the
				 * lookup. */
{
#ifndef TK_SEND_ENABLED_ON_WINDOWS
    (void)interp;
    /*
     * Temporarily disabled for bug #858822
     */

    return TCL_OK;
#else /* TK_SEND_ENABLED_ON_WINDOWS */

252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
250
251
252
253
254
255
256


257
258
259
260
261
262
263
264







-
-
+







			if (wcsncmp(olestr, oleszStub,
				wcslen(oleszStub)) == 0) {
			    LPOLESTR p = olestr + wcslen(oleszStub);

			    if (*p) {
				Tcl_DString ds;

				Tcl_DStringInit(&ds);
				Tcl_WCharToUtfDString(p + 1, wcslen(p + 1), &ds);
				Tcl_WinTCharToUtf(p + 1, -1, &ds);
				result = Tcl_ListObjAppendElement(interp,
					objList,
					Tcl_NewStringObj(Tcl_DStringValue(&ds),
						Tcl_DStringLength(&ds)));
				Tcl_DStringFree(&ds);
			    }
			}
316
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
332
333
334
335
336
337


338
339
340
341
342
343

344
345
346
347
348
349
350
351
352
353
354
355










356
357
358
359
360
361
362
363
364
365
366
367

368
369
370
371












372
373
374
375
376
377
378
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331

332

333
334
335
336
337
338
339

340












341
342
343
344
345
346
347
348
349
350



351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382







-
+











-

-
+
+





-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-








-
+




+
+
+
+
+
+
+
+
+
+
+
+







 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

int
Tk_SendObjCmd(
    void *clientData,	/* Information about sender (only dispPtr
    ClientData clientData,	/* Information about sender (only dispPtr
				 * field is used). */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument strings. */
{
    enum {
	SEND_ASYNC, SEND_DISPLAYOF, SEND_LAST
    };
    static const char *const sendOptions[] = {
	"-async",   "-displayof",   "--",  NULL
    };
    const char *stringRep;
    int result = TCL_OK;
    int i, async = 0, index;
    int i, optind, async = 0;
    Tcl_Obj *displayPtr = NULL;

    /*
     * Process the command options.
     */

    for (i = 1; i < (objc - 1); i++) {
    for (i = 1; i < objc; i++) {
	stringRep = Tcl_GetString(objv[i]);
	if (stringRep[0] == '-') {
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
		    sizeof(char *), "option", 0, &index) != TCL_OK) {
		break;
	    }
	    if (index == SEND_ASYNC) {
		async = 1;
	    } else if (index == SEND_DISPLAYOF) {
		i++;
	    } else /* if (index == SEND_LAST) */ {
		i++;
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], sendOptions,
		sizeof(char *), "option", 0, &optind) != TCL_OK) {
	    break;
	}
	if (optind == SEND_ASYNC) {
	    ++async;
	} else if (optind == SEND_DISPLAYOF) {
	    displayPtr = objv[++i];
	} else if (optind == SEND_LAST) {
	    i++;
		break;
	    }
	} else {
	    break;
	}
    }

    /*
     * Ensure we still have a valid command.
     */

    if (objc < (i + 2)) {
    if ((objc - i) < 2) {
	Tcl_WrongNumArgs(interp, 1, objv,
		"?-async? ?-displayof? ?--? interpName arg ?arg ...?");
	result = TCL_ERROR;
    }

    /*
     * We don't support displayPtr. See TIP #150.
     */

    if (displayPtr) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"option not implemented: \"displayof\" is not available"
		" for this platform.", -1));
	Tcl_SetErrorCode(interp, "TK", "SEND", "DISPLAYOF_WIN", NULL);
	result = TCL_ERROR;
    }

    /*
     * Send the arguments to the foreign interp.
     */
    /* FIX ME: we need to check for local interp */
    if (result == TCL_OK) {
	LPDISPATCH pdisp;
475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493







-
+







 *
 *--------------------------------------------------------------
 */

#ifdef TK_SEND_ENABLED_ON_WINDOWS
static void
CmdDeleteProc(
    void *clientData)
    ClientData clientData)
{
    RegisteredInterp *riPtr = (RegisteredInterp *)clientData;

    /*
     * Lock the package structure in memory.
     */

557
558
559
560
561
562
563



























564
565
566
567
568
569
570
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    }
}
#endif /* TK_SEND_ENABLED_ON_WINDOWS */

/*
 * ----------------------------------------------------------------------
 *
 * InterpDeleteProc --
 *
 *	This is called when the interpreter is deleted and used to unregister
 *	the COM libraries.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 * ----------------------------------------------------------------------
 */

#ifdef TK_SEND_ENABLED_ON_WINDOWS
static void
InterpDeleteProc(
    ClientData clientData,
    Tcl_Interp *interp)
{
    CoUninitialize();
}
#endif /* TK_SEND_ENABLED_ON_WINDOWS */

/*
 * ----------------------------------------------------------------------
 *
 * BuildMoniker --
 *
 *	Construct a moniker from the given name. This ensures that all our
 *	monikers have the same prefix.
 *
 * Results:
 *	S_OK. If the name cannot be turned into a moniker then a COM error
584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
599
615
616
617
618
619
620
621

622

623
624
625
626
627
628
629







-
+
-







    LPMONIKER pmkClass = NULL;
    HRESULT hr = CreateFileMoniker(TKWINSEND_REGISTRATION_BASE, &pmkClass);

    if (SUCCEEDED(hr)) {
	LPMONIKER pmkItem = NULL;
	Tcl_DString dString;

	Tcl_DStringInit(&dString);
	Tcl_WinUtfToTChar(name, -1, &dString);
	Tcl_UtfToWCharDString(name, TCL_INDEX_NONE, &dString);
	hr = CreateFileMoniker((LPOLESTR)Tcl_DStringValue(&dString), &pmkItem);
	Tcl_DStringFree(&dString);
	if (SUCCEEDED(hr)) {
	    hr = pmkClass->lpVtbl->ComposeWith(pmkClass, pmkItem, FALSE, ppmk);
	    pmkItem->lpVtbl->Release(pmkItem);
	}
	pmkClass->lpVtbl->Release(pmkClass);
637
638
639
640
641
642
643
644

645
646
647

648
649
650

651
652
653
654
655
656
657
667
668
669
670
671
672
673

674
675
676

677
678
679

680
681
682
683
684
685
686
687







-
+


-
+


-
+







    hr = GetRunningObjectTable(0, &pROT);
    if (SUCCEEDED(hr)) {
	offset = 0;
	for (i = 1; SUCCEEDED(hr); i++) {
	    if (i > 1) {
		if (i == 2) {
		    Tcl_DStringInit(&dString);
		    Tcl_DStringAppend(&dString, name, TCL_INDEX_NONE);
		    Tcl_DStringAppend(&dString, name, -1);
		    Tcl_DStringAppend(&dString, " #", 2);
		    offset = Tcl_DStringLength(&dString);
		    Tcl_DStringSetLength(&dString, offset + TCL_INTEGER_SPACE);
		    Tcl_DStringSetLength(&dString, offset+TCL_INTEGER_SPACE);
		    actualName = Tcl_DStringValue(&dString);
		}
		snprintf(Tcl_DStringValue(&dString) + offset, TCL_INTEGER_SPACE, "%d", i);
		sprintf(Tcl_DStringValue(&dString) + offset, "%d", i);
	    }

	    hr = BuildMoniker(actualName, &pmk);
	    if (SUCCEEDED(hr)) {

		hr = pROT->lpVtbl->Register(pROT,
		    ROTFLAGS_REGISTRATIONKEEPSALIVE,
699
700
701
702
703
704
705

706
707


708
709
710
711
712
713
714
729
730
731
732
733
734
735
736


737
738
739
740
741
742
743
744
745







+
-
-
+
+








static int
Send(
    LPDISPATCH pdispInterp,	/* Pointer to the remote interp's COM
				 * object. */
    Tcl_Interp *interp,		/* The local interpreter. */
    int async,			/* Flag for the calling style. */
    ClientData clientData,	/* The RegisteredInterp structure for this
    TCL_UNUSED(void *),
    Tcl_Size objc,			/* Number of arguments to be sent. */
				 * interp. */
    int objc,			/* Number of arguments to be sent. */
    Tcl_Obj *const objv[])	/* The arguments to be sent. */
{
    VARIANT vCmd, vResult;
    DISPPARAMS dp;
    EXCEPINFO ei;
    UINT uiErr = 0;
    HRESULT hr = S_OK, ehr = S_OK;
726
727
728
729
730
731
732
733
734


735
736
737
738
739
740
741
757
758
759
760
761
762
763


764
765
766
767
768
769
770
771
772







-
-
+
+







    VariantInit(&vCmd);
    VariantInit(&vResult);
    memset(&dp, 0, sizeof(dp));
    memset(&ei, 0, sizeof(ei));

    vCmd.vt = VT_BSTR;
    src = Tcl_GetString(cmd);
    Tcl_DStringInit(&ds);
    vCmd.bstrVal = SysAllocString(Tcl_UtfToWCharDString(src, cmd->length, &ds));
    Tcl_WinUtfToTChar(src, cmd->length, &ds);
    vCmd.bstrVal = SysAllocString((WCHAR *) Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);

    dp.cArgs = 1;
    dp.rgvarg = &vCmd;

    /*
     * Select the method to use based upon the async flag and call the method.
749
750
751
752
753
754
755
756
757


758
759
760
761
762
763
764
765
766
767
768
769
770


771
772
773
774
775
776
777
778
780
781
782
783
784
785
786


787
788
789
790
791
792
793
794
795
796
797
798
799


800
801

802
803
804
805
806
807
808







-
-
+
+











-
-
+
+
-








    /*
     * Convert the result into a string and place in the interps result.
     */

    ehr = VariantChangeType(&vResult, &vResult, 0, VT_BSTR);
    if (SUCCEEDED(ehr)) {
	Tcl_DStringInit(&ds);
	Tcl_WCharToUtfDString(vResult.bstrVal, SysStringLen(vResult.bstrVal), &ds);
	Tcl_WinTCharToUtf(vResult.bstrVal, (int) SysStringLen(vResult.bstrVal) *
		sizeof (WCHAR), &ds);
	Tcl_DStringResult(interp, &ds);
    }

    /*
     * Errors are returned as dispatch exceptions. If an error code was
     * returned then we decode the exception and setup the Tcl error
     * variables.
     */

    if (hr == DISP_E_EXCEPTION && ei.bstrSource != NULL) {
	Tcl_Obj *opError, *opErrorCode, *opErrorInfo;

	Tcl_DStringInit(&ds);
	Tcl_WinTCharToUtf(ei.bstrSource, (int) SysStringLen(ei.bstrSource) *
		sizeof (WCHAR), &ds);
	Tcl_WCharToUtfDString(ei.bstrSource, SysStringLen(ei.bstrSource), &ds);
	opError = Tcl_NewStringObj(Tcl_DStringValue(&ds),
		Tcl_DStringLength(&ds));
	Tcl_DStringFree(&ds);
	Tcl_ListObjIndex(interp, opError, 0, &opErrorCode);
	Tcl_SetObjErrorCode(interp, opErrorCode);
	Tcl_ListObjIndex(interp, opError, 1, &opErrorInfo);
	Tcl_AppendObjToErrorInfo(interp, opErrorInfo);
835
836
837
838
839
840
841
842

843
844

845
846
847

848
849

850
851
852
853
854
855
856
865
866
867
868
869
870
871

872
873

874
875
876

877
878

879
880
881
882
883
884
885
886







-
+

-
+


-
+

-
+








    opErrorCode = Tcl_DuplicateObj(opErrorCode);
    Tcl_IncrRefCount(opErrorCode);
    Tcl_ListObjAppendElement(interp, opErrorCode, opErrorInfo);
    /* TODO: Handle failure to append */

    src = Tcl_GetString(opError);
    Tcl_DStringInit(&ds);
    Tcl_WinUtfToTChar(src, opError->length, &ds);
    pExcepInfo->bstrDescription =
	    SysAllocString(Tcl_UtfToWCharDString(src, opError->length, &ds));
	    SysAllocString((WCHAR *) Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);
    src = Tcl_GetString(opErrorCode);
    Tcl_DStringInit(&ds);
    Tcl_WinUtfToTChar(src, opErrorCode->length, &ds);
    pExcepInfo->bstrSource =
	    SysAllocString(Tcl_UtfToWCharDString(src, opErrorCode->length, &ds));
	    SysAllocString((WCHAR *) Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);
    Tcl_DecrRefCount(opErrorCode);
    pExcepInfo->scode = E_FAIL;

    hr = CreateErrorInfo(&pCEI);
    if (!SUCCEEDED(hr)) {
	return;
889
890
891
892
893
894
895
896

897
898
899
900
901
902
903
919
920
921
922
923
924
925

926
927
928
929
930
931
932
933







-
+







    Tcl_Interp *interp,
    Tcl_Obj *cmdPtr)
{
    SendEvent *evPtr;

    TRACE("SendQueueCommand()\n");

    evPtr = (SendEvent *)ckalloc(sizeof(SendEvent));
    evPtr = ckalloc(sizeof(SendEvent));
    evPtr->header.proc = SendEventProc;
    evPtr->header.nextPtr = NULL;
    evPtr->interp = interp;
    Tcl_Preserve(evPtr->interp);

    if (Tcl_IsShared(cmdPtr)) {
	evPtr->cmdPtr = Tcl_DuplicateObj(cmdPtr);
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972







-
+







 *
 * ----------------------------------------------------------------------
 */

static int
SendEventProc(
    Tcl_Event *eventPtr,
    TCL_UNUSED(int))
    int flags)
{
    SendEvent *evPtr = (SendEvent *)eventPtr;

    TRACE("SendEventProc\n");

    Tcl_EvalObjEx(evPtr->interp, evPtr->cmdPtr,
	    TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);

Changes to win/tkWinSendCom.c.

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23







-
+







 * We implement a COM class for use in registering Tcl interpreters with the
 * system's Running Object Table. This class implements an IDispatch interface
 * with the following method:
 *	Send(String cmd) As String
 * In other words the Send methods takes a string and evaluates this in the
 * Tcl interpreter. The result is returned as another string.
 *
 * Copyright © 2002 Pat Thoyts <[email protected]>
 * Copyright (C) 2002 Pat Thoyts <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include "tkWinSendCom.h"
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154







-
+







 *
 * ----------------------------------------------------------------------
 */
static void
TkWinSendCom_Destroy(
    LPDISPATCH pdisp)
{
    CoTaskMemFree(pdisp);
    CoTaskMemFree((void *) pdisp);
}

/*
 * ----------------------------------------------------------------------
 *
 * IDispatch --
 *
162
163
164
165
166
167
168
169

170
171
172
173
174
175


176
177
178
179


180
181
182
183
184
185
186
187
188
189

190
191

192
193
194
195
196
197
198
199

200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
162
163
164
165
166
167
168

169
170
171
172
173


174
175
176
177


178
179
180
181
182
183
184
185
186
187
188

189
190

191
192
193
194
195
196
197
198

199
200

201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246




247
248
249
250
251
252
253







-
+




-
-
+
+


-
-
+
+









-
+

-
+







-
+

-
+











-
















-
-
-


















-
-
-
-







static STDMETHODIMP
WinSendCom_QueryInterface(
    IDispatch *This,
    REFIID riid,
    void **ppvObject)
{
    HRESULT hr = E_NOINTERFACE;
    TkWinSendCom *sendCom = (TkWinSendCom *) This;
    TkWinSendCom *this = (TkWinSendCom *) This;
    *ppvObject = NULL;

    if (memcmp(riid, &IID_IUnknown, sizeof(IID)) == 0
	    || memcmp(riid, &IID_IDispatch, sizeof(IID)) == 0) {
	*ppvObject = (void **) sendCom;
	sendCom->lpVtbl->AddRef(This);
	*ppvObject = (void **) this;
	this->lpVtbl->AddRef(This);
	hr = S_OK;
    } else if (memcmp(riid, &IID_ISupportErrorInfo, sizeof(IID)) == 0) {
	*ppvObject = (void **) (sendCom + 1);
	sendCom->lpVtbl2->AddRef((ISupportErrorInfo *) (sendCom + 1));
	*ppvObject = (void **) (this + 1);
	this->lpVtbl2->AddRef((ISupportErrorInfo *) (this + 1));
	hr = S_OK;
    }
    return hr;
}

static STDMETHODIMP_(ULONG)
WinSendCom_AddRef(
    IDispatch *This)
{
    TkWinSendCom *sendCom = (TkWinSendCom*)This;
    TkWinSendCom *this = (TkWinSendCom*)This;

    return InterlockedIncrement(&sendCom->refcount);
    return InterlockedIncrement(&this->refcount);
}

static STDMETHODIMP_(ULONG)
WinSendCom_Release(
    IDispatch *This)
{
    long r = 0;
    TkWinSendCom *sendCom = (TkWinSendCom*)This;
    TkWinSendCom *this = (TkWinSendCom*)This;

    if ((r = InterlockedDecrement(&sendCom->refcount)) == 0) {
    if ((r = InterlockedDecrement(&this->refcount)) == 0) {
	TkWinSendCom_Destroy(This);
    }
    return r;
}

static STDMETHODIMP
WinSendCom_GetTypeInfoCount(
    IDispatch *This,
    UINT *pctinfo)
{
    HRESULT hr = E_POINTER;
    (void)This;

    if (pctinfo != NULL) {
	*pctinfo = 0;
	hr = S_OK;
    }
    return hr;
}

static STDMETHODIMP
WinSendCom_GetTypeInfo(
    IDispatch *This,
    UINT iTInfo,
    LCID lcid,
    ITypeInfo **ppTI)
{
    HRESULT hr = E_POINTER;
    (void)This;
    (void)iTInfo;
    (void)lcid;

    if (ppTI) {
	*ppTI = NULL;
	hr = E_NOTIMPL;
    }
    return hr;
}

static STDMETHODIMP
WinSendCom_GetIDsOfNames(
    IDispatch *This,
    REFIID riid,
    LPOLESTR *rgszNames,
    UINT cNames,
    LCID lcid,
    DISPID *rgDispId)
{
    HRESULT hr = E_POINTER;
    (void)This;
    (void)riid;
    (void)cNames;
    (void)lcid;

    if (rgDispId) {
	hr = DISP_E_UNKNOWNNAME;
	if (_wcsicmp(*rgszNames, L"Send") == 0) {
	    *rgDispId = TKWINSENDCOM_DISPID_SEND, hr = S_OK;
	} else if (_wcsicmp(*rgszNames, L"Async") == 0) {
	    *rgDispId = TKWINSENDCOM_DISPID_ASYNC, hr = S_OK;
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
265
266
267
268
269
270
271

272


273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298







-
+
-
-







-
+










-
+







    WORD wFlags,
    DISPPARAMS *pDispParams,
    VARIANT *pvarResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr)
{
    HRESULT hr = DISP_E_MEMBERNOTFOUND;
    TkWinSendCom *sendCom = (TkWinSendCom*)This;
    TkWinSendCom *this = (TkWinSendCom*)This;
    (void)riid;
    (void)lcid;

    switch (dispidMember) {
    case TKWINSENDCOM_DISPID_SEND:
	if (wFlags | DISPATCH_METHOD) {
	    if (pDispParams->cArgs != 1) {
		hr = DISP_E_BADPARAMCOUNT;
	    } else {
		hr = Send(sendCom, pDispParams->rgvarg[0], pvarResult,
		hr = Send(this, pDispParams->rgvarg[0], pvarResult,
			pExcepInfo, puArgErr);
	    }
	}
	break;

    case TKWINSENDCOM_DISPID_ASYNC:
	if (wFlags | DISPATCH_METHOD) {
	    if (pDispParams->cArgs != 1) {
		hr = DISP_E_BADPARAMCOUNT;
	    } else {
		hr = Async(sendCom, pDispParams->rgvarg[0], pExcepInfo, puArgErr);
		hr = Async(this, pDispParams->rgvarg[0], pExcepInfo, puArgErr);
	    }
	}
	break;
    }
    return hr;
}

319
320
321
322
323
324
325
326

327
328

329
330
331
332
333
334
335

336
337

338
339
340
341
342
343
344

345
346

347
348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
309
310
311
312
313
314
315

316
317

318
319
320
321
322
323
324

325
326

327
328
329
330
331
332
333

334
335

336
337
338
339
340
341
342
343




344
345
346
347
348
349
350
351







-
+

-
+






-
+

-
+






-
+

-
+







-
-
-
-
+








static STDMETHODIMP
ISupportErrorInfo_QueryInterface(
    ISupportErrorInfo *This,
    REFIID riid,
    void **ppvObject)
{
    TkWinSendCom *sendCom = (TkWinSendCom *)(This - 1);
    TkWinSendCom *this = (TkWinSendCom *)(This - 1);

    return sendCom->lpVtbl->QueryInterface((IDispatch *) sendCom, riid, ppvObject);
    return this->lpVtbl->QueryInterface((IDispatch *) this, riid, ppvObject);
}

static STDMETHODIMP_(ULONG)
ISupportErrorInfo_AddRef(
    ISupportErrorInfo *This)
{
    TkWinSendCom *sendCom = (TkWinSendCom *)(This - 1);
    TkWinSendCom *this = (TkWinSendCom *)(This - 1);

    return InterlockedIncrement(&sendCom->refcount);
    return InterlockedIncrement(&this->refcount);
}

static STDMETHODIMP_(ULONG)
ISupportErrorInfo_Release(
    ISupportErrorInfo *This)
{
    TkWinSendCom *sendCom = (TkWinSendCom *)(This - 1);
    TkWinSendCom *this = (TkWinSendCom *)(This - 1);

    return sendCom->lpVtbl->Release((IDispatch *) sendCom);
    return this->lpVtbl->Release((IDispatch *) this);
}

static STDMETHODIMP
ISupportErrorInfo_InterfaceSupportsErrorInfo(
    ISupportErrorInfo *This,
    REFIID riid)
{
    (void)This;
    (void)riid;

    /*TkWinSendCom *sendCom = (TkWinSendCom*)(This - 1);*/
    /*TkWinSendCom *this = (TkWinSendCom*)(This - 1);*/
    return S_OK; /* or S_FALSE */
}

/*
 * ----------------------------------------------------------------------
 *
 * Async --
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403


404
405
406
407
408
409
410
367
368
369
370
371
372
373

374
375
376
377
378
379

380
381
382
383
384
385
386
387


388
389
390
391
392
393
394
395
396







-






-
+







-
-
+
+







    VARIANT Cmd,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr)
{
    HRESULT hr = S_OK;
    VARIANT vCmd;
    Tcl_DString ds;
    (void)puArgErr;

    VariantInit(&vCmd);

    hr = VariantChangeType(&vCmd, &Cmd, 0, VT_BSTR);
    if (FAILED(hr)) {
	Tcl_SetObjResult(obj->interp, Tcl_NewStringObj(
		"invalid args: Async(command)", TCL_INDEX_NONE));
		"invalid args: Async(command)", -1));
	TkWinSend_SetExcepInfo(obj->interp, pExcepInfo);
	hr = DISP_E_EXCEPTION;
    }

    if (SUCCEEDED(hr) && obj->interp) {
	Tcl_Obj *scriptPtr;

	Tcl_DStringInit(&ds);
	Tcl_WCharToUtfDString(vCmd.bstrVal, SysStringLen(vCmd.bstrVal), &ds);
	Tcl_WinTCharToUtf(vCmd.bstrVal, (int) SysStringLen(vCmd.bstrVal) *
		sizeof (WCHAR), &ds);
	scriptPtr =
		Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
	Tcl_DStringFree(&ds);
	TkWinSend_QueueCommand(obj->interp, scriptPtr);
    }

    VariantClear(&vCmd);
428
429
430
431
432
433
434
435

436
437
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459


460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476


477
478
479
480
481
482
483
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428
429

430
431
432

433
434
435
436
437
438
439
440
441
442


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459


460
461
462
463
464
465
466
467
468







-
+








-
+


-










-
-
+
+















-
-
+
+







 *	The interpreters state and result will be modified.
 *
 * ----------------------------------------------------------------------
 */

static HRESULT
Send(
    TkWinSendCom *comobj,
    TkWinSendCom *obj,
    VARIANT vCmd,
    VARIANT *pvResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr)
{
    HRESULT hr = S_OK;
    int result = TCL_OK;
    VARIANT v;
    Tcl_Interp *interp = comobj->interp;
    register Tcl_Interp *interp = obj->interp;
    Tcl_Obj *scriptPtr;
    Tcl_DString ds;
    (void)puArgErr;

    if (interp == NULL) {
	return S_OK;
    }
    VariantInit(&v);
    hr = VariantChangeType(&v, &vCmd, 0, VT_BSTR);
    if (!SUCCEEDED(hr)) {
	return hr;
    }

    Tcl_DStringInit(&ds);
    Tcl_WCharToUtfDString(v.bstrVal, SysStringLen(v.bstrVal), &ds);
    Tcl_WinTCharToUtf(v.bstrVal, (int) SysStringLen(v.bstrVal) *
	    sizeof (WCHAR), &ds);
    scriptPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
    Tcl_DStringFree(&ds);
    Tcl_Preserve(interp);
    Tcl_IncrRefCount(scriptPtr);
    result = Tcl_EvalObjEx(interp, scriptPtr,
	    TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);
    Tcl_DecrRefCount(scriptPtr);
    if (pvResult != NULL) {
	Tcl_Obj *obj;
	const char *src;

	VariantInit(pvResult);
	pvResult->vt = VT_BSTR;
	obj = Tcl_GetObjResult(interp);
	src = Tcl_GetString(obj);
	Tcl_DStringInit(&ds);
	pvResult->bstrVal = SysAllocString(Tcl_UtfToWCharDString(src, obj->length, &ds));
	Tcl_WinUtfToTChar(src, obj->length, &ds);
	pvResult->bstrVal = SysAllocString((WCHAR *) Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);
    }
    if (result == TCL_ERROR) {
	hr = DISP_E_EXCEPTION;
	TkWinSend_SetExcepInfo(interp, pExcepInfo);
    }
    Tcl_Release(interp);

Changes to win/tkWinSendCom.h.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15







-
+







/*
 * tkWinSendCom.h --
 *
 *	This file provides procedures that implement the Windows "send"
 *	command, allowing commands to be passed from interpreter to
 *	interpreter.
 *
 * Copyright © 2002 Pat Thoyts <[email protected]>
 * Copyright (C) 2002 Pat Thoyts <[email protected]>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _tkWinSendCom_h_INCLUDE
#define _tkWinSendCom_h_INCLUDE

Deleted win/tkWinSysTray.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * tkWinSysTray.c --
 *
 * 	tkWinSysTray.c implements a "systray" Tcl command which permits to
 * 	change the system tray/taskbar icon of a Tk toplevel window and
 * 	a "sysnotify" command to post system notifications.
 *
 * Copyright © 1995-1996 Microsoft Corp.
 * Copyright © 1998 Brueckner & Jarosch Ing.GmbH, Erfurt, Germany
 * Copyright © 2020 Kevin Walzer/WordTech Communications LLC.
 * Copyright © 2020 Eric Boudaillier.
 * Copyright © 2020 Francois Vogel.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"
#include <windows.h>
#include <shellapi.h>
#include "tkWin.h"
#include "tkWinInt.h"
#include "tkWinIco.h"

/*
 * Based extensively on the winico extension and sample code from Microsoft.
 * Some of the code was adapted into tkWinWM.c to implement the "wm iconphoto"
 * command (TIP 159), and here we are borrowing that code to use Tk images
 * to create system tray icons instead of ico files. Additionally, we are
 * removing obsolete parts of the winico extension, and implementing
 * more of the Shell_Notification API to add balloon/system notifications.
 */

#define GETHINSTANCE Tk_GetHINSTANCE()

typedef struct IcoInfo {
    HICON hIcon;                /* icon handle returned by LoadIcon. */
    unsigned id;                /* Identifier for command;  used to
                                 * cancel it. */
    Tcl_Obj *taskbar_txt;       /* text to display in the taskbar */
    Tcl_Interp *interp;         /* interp which created the icon */
    Tcl_Obj *taskbar_command;   /* command to eval if events in the taskbar
                                 * arrive */
    int taskbar_flags;          /* taskbar related flags*/
    HWND hwndFocus;
    struct IcoInfo *nextPtr;
} IcoInfo;

/* Per-interp struture */
typedef struct IcoInterpInfo {
    HWND hwnd;                  /* Handler window */
    int counter;                /* Counter for IcoInfo id generation */
    IcoInfo *firstIcoPtr;       /* List of created IcoInfo */
    struct IcoInterpInfo *nextPtr;
} IcoInterpInfo;

#define TASKBAR_ICON 1
#define ICON_MESSAGE WM_USER + 1234

#define HANDLER_CLASS "Wtk_TaskbarHandler"
static HWND CreateTaskbarHandlerWindow(void);

static IcoInterpInfo *firstIcoInterpPtr = NULL;
static Tk_EventProc WinIcoDestroy;

/*
 * If someone wants to see the several masks somewhere on the screen...
 * set the ICO_DRAW define and feel free to make some Tcl commands
 * for accessing it.  The normal drawing of an Icon to a DC is really easy:
 * DrawIcon(hdc,x,y,hIcon) or , more complicated
 * DrawIconEx32PlusMoreParameters ...
 */

/* #define ICO_DRAW */
#ifdef ICO_DRAW
#define RectWidth(r)((r).right - (r).left + 1)
#define RectHeight(r)((r).bottom - (r).top + 1)

/*
 *----------------------------------------------------------------------
 *
 * DrawXORMask --
 *
 * 	Using DIB functions, draw XOR mask on hDC in Rect.
 *
 * Results:
 *	Icon is rendered.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static BOOL
DrawXORMask(
    HDC hDC,
    RECT Rect,
    LPLPICONIMAGE lpIcon)
{
    int x, y;

    /* Sanity checks */
    if (lpIcon == NULL)
        return FALSE;
    if (lpIcon->lpBits == NULL)
        return FALSE;

    /* Account for height*2 thing */
    lpIcon->lpbi->bmiHeader.biHeight /= 2;

    /* Locate it */
    x = Rect.left + ((RectWidth(Rect) - lpIcon->lpbi->bmiHeader.biWidth) / 2);
    y = Rect.top + ((RectHeight(Rect) - lpIcon->lpbi->bmiHeader.biHeight) / 2);

    /* Blast it to the screen */
    SetDIBitsToDevice(hDC, x, y,
            lpIcon->lpbi->bmiHeader.biWidth,
            lpIcon->lpbi->bmiHeader.biHeight,
            0, 0, 0, lpIcon->lpbi->bmiHeader.biHeight,
            lpIcon->lpXOR, lpIcon->lpbi, DIB_RGB_COLORS);

    /* UnAccount for height*2 thing */
    lpIcon->lpbi->bmiHeader.biHeight *= 2;

    return TRUE;
}

/*
 *----------------------------------------------------------------------
 *
 * DrawANDMask --
 *
 * 	Using DIB functions, draw AND mask on hDC in Rect.
 *
 * Results:
 *	Icon is rendered.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

BOOL
DrawANDMask(
    HDC hDC,
    RECT Rect,
    LPLPICONIMAGE lpIcon)
{
    LPBITMAPINFO lpbi;
    int x, y;

    /* Sanity checks */
    if (lpIcon == NULL)
        return FALSE;
    if (lpIcon->lpBits == NULL)
        return FALSE;

    /* Need a bitmap header for the mono mask */
    lpbi = ckalloc(sizeof(BITMAPINFO) + (2 * sizeof(RGBQUAD)));
    lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    lpbi->bmiHeader.biWidth = lpIcon->lpbi->bmiHeader.biWidth;
    lpbi->bmiHeader.biHeight = lpIcon->lpbi->bmiHeader.biHeight / 2;
    lpbi->bmiHeader.biPlanes = 1;
    lpbi->bmiHeader.biBitCount = 1;
    lpbi->bmiHeader.biCompression = BI_RGB;
    lpbi->miHeader.biSizeImage = 0;
    lpbi->bmiHeader.biXPelsPerMeter = 0;
    lpbi->bmiHeader.biYPelsPerMeter = 0;
    lpbi->bmiHeader.biClrUsed = 0;
    lpbi->bmiHeader.biClrImportant = 0;
    lpbi->bmiColors[0].rgbRed = 0;
    lpbi->bmiColors[0].rgbGreen = 0;
    lpbi->bmiColors[0].rgbBlue = 0;
    lpbi->bmiColors[0].rgbReserved = 0;
    lpbi->bmiColors[1].rgbRed = 255;
    lpbi->bmiColors[1].rgbGreen = 255;
    lpbi->bmiColors[1].rgbBlue = 255;
    lpbi->bmiColors[1].rgbReserved = 0;

    /* Locate it */
    x = Rect.left + ((RectWidth(Rect) - lpbi->bmiHeader.biWidth) / 2);
    y = Rect.top + ((RectHeight(Rect) - lpbi->bmiHeader.biHeight) / 2);

    /* Blast it to the screen */
    SetDIBitsToDevice(hDC, x, y,
            lpbi->bmiHeader.biWidth,
            lpbi->bmiHeader.biHeight,
            0, 0, 0, lpbi->bmiHeader.biHeight,
            lpIcon->lpAND, lpbi, DIB_RGB_COLORS);

    /* clean up */
    ckfree(lpbi);

    return TRUE;
}
#endif /* ICO_DRAW */

/*
 *----------------------------------------------------------------------
 *
 * TaskbarOperation --
 *
 * 	Management of icon display.
 *
 * Results:
 *	Icon is displayed or deleted.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TaskbarOperation(
    IcoInterpInfo *icoInterpPtr,
    IcoInfo *icoPtr,
    int oper)
{
    NOTIFYICONDATAW ni;
    WCHAR *str;

    ni.cbSize = sizeof(NOTIFYICONDATAW);
    ni.hWnd = icoInterpPtr->hwnd;
    ni.uID = icoPtr->id;
    ni.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
    ni.uCallbackMessage = ICON_MESSAGE;
    ni.hIcon = icoPtr->hIcon;

    if (icoPtr->taskbar_txt != NULL) {
        Tcl_DString dst;
        Tcl_DStringInit(&dst);
        str = (WCHAR *)Tcl_UtfToWCharDString(Tcl_GetString(icoPtr->taskbar_txt), TCL_INDEX_NONE, &dst);
        wcsncpy(ni.szTip, str, (Tcl_DStringLength(&dst) + 2) / 2);
        Tcl_DStringFree(&dst);
    } else {
        ni.szTip[0] = 0;
    }

    if (Shell_NotifyIconW(oper, &ni) == 1) {
        if (oper == NIM_ADD || oper == NIM_MODIFY) {
            icoPtr->taskbar_flags |= TASKBAR_ICON;
        }
        if (oper == NIM_DELETE) {
            icoPtr->taskbar_flags &= ~TASKBAR_ICON;
        }
    }
    /* Silently ignore error? */
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * NewIcon --
 *
 * 	Create icon for display in system tray.
 *
 * Results:
 *	Icon is created for display.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static IcoInfo *
NewIcon(
    Tcl_Interp *interp,
    IcoInterpInfo *icoInterpPtr,
    HICON hIcon)
{
    IcoInfo *icoPtr;

    icoPtr = (IcoInfo *)ckalloc(sizeof(IcoInfo));
    memset(icoPtr, 0, sizeof(IcoInfo));
    icoPtr->id = ++icoInterpPtr->counter;
    icoPtr->hIcon = hIcon;
    icoPtr->taskbar_txt = NULL;
    icoPtr->interp = interp;
    icoPtr->taskbar_command = NULL;
    icoPtr->taskbar_flags = 0;
    icoPtr->hwndFocus = NULL;
    icoPtr->nextPtr = icoInterpPtr->firstIcoPtr;
    icoInterpPtr->firstIcoPtr = icoPtr;
    return icoPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeIcoPtr --
 *
 * 	Delete icon and free memory.
 *
 * Results:
 *	Icon is removed from display.
 *
 * Side effects:
 *	Memory/resources freed.
 *
 *----------------------------------------------------------------------
 */

static void
FreeIcoPtr(
    IcoInterpInfo *icoInterpPtr,
    IcoInfo *icoPtr)
{
    IcoInfo *prevPtr;
    if (icoInterpPtr->firstIcoPtr == icoPtr) {
        icoInterpPtr->firstIcoPtr = icoPtr->nextPtr;
    } else {
        for (prevPtr = icoInterpPtr->firstIcoPtr; prevPtr->nextPtr != icoPtr;
                prevPtr = prevPtr->nextPtr) {
            /* Empty loop body. */
        }
        prevPtr->nextPtr = icoPtr->nextPtr;
    }
    if (icoPtr->taskbar_flags & TASKBAR_ICON) {
        TaskbarOperation(icoInterpPtr, icoPtr, NIM_DELETE);
    }
    if (icoPtr->taskbar_txt != NULL) {
        Tcl_DecrRefCount(icoPtr->taskbar_txt);
    }
    if (icoPtr->taskbar_command != NULL) {
        Tcl_DecrRefCount(icoPtr->taskbar_command);
    }
    ckfree(icoPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * GetIcoPtr --
 *
 * 	Get pointer to icon for display.
 *
 * Results:
 *	Icon is obtained for display.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static IcoInfo *
GetIcoPtr(
    Tcl_Interp *interp,
    IcoInterpInfo *icoInterpPtr,
    const char *string)
{
    IcoInfo *icoPtr;
    unsigned id;
    const char *start;
    char *end;

    if (strncmp(string, "ico#", 4) != 0) {
        goto notfound;
    }
    start = string + 4;
    id = strtoul(start, &end, 10);
    if ((end == start) || (*end != 0)) {
        goto notfound;
    }
    for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
        if (icoPtr->id == id) {
            return icoPtr;
        }
    }

notfound:
    Tcl_AppendResult(interp, "icon \"", string,
        "\" doesn't exist", NULL);
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * GetInt --
 *
 * Utility function for calculating buffer length.
 *
 * Results:
 *	Length.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
GetInt(
    long theint,
    char *buffer,
    size_t len)
{
    snprintf(buffer, len, "0x%lx", theint);
    buffer[len - 1] = 0;
    return (int) strlen(buffer);
}

/*
 *----------------------------------------------------------------------
 *
 * GetIntDec --
 *
 * Utility function for calculating buffer length.
 *
 * Results:
 *	Length.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
GetIntDec(
    long theint,
    char *buffer,
    size_t len)
{
    snprintf(buffer, len - 1, "%ld", theint);
    buffer[len - 1] = 0;
    return (int) strlen(buffer);
}

/*
 *----------------------------------------------------------------------
 *
 * TaskbarExpandPercents --
 *
 * Parse strings in taskbar display.
 *
 * Results:
 *	Strings.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static char*
TaskbarExpandPercents(
    IcoInfo *icoPtr,
    const char *msgstring,
    WPARAM wParam,
    LPARAM lParam,
    char *before,
    char *after,
    int *aftersize)
{
#define SPACELEFT (*aftersize-(dst-after)-1)
#define AFTERLEN ((*aftersize>0)?(*aftersize*2):1024)
#define ALLOCLEN ((len>AFTERLEN)?(len*2):AFTERLEN)
    char buffer[TCL_INTEGER_SPACE + 5];
    char* dst;
    dst = after;
    while (*before) {
        const char *ptr = before;
        int len = 1;
        if(*before == '%') {
            switch(before[1]){
                case 'M':
                case 'm': {
                    before++;
                    len = strlen(msgstring);
                    ptr = msgstring;
                    break;
                }
                /* case 'W': {
                   before++;
                   len = (int)strlen(winstring);
                   ptr = winstring;
                   break;
                   }
                */
                case 'i': {
                    before++;
                    snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
                    len = strlen(buffer);
                    ptr = buffer;
                    break;
                }
                case 'w': {
                    before++;
                    len = GetInt((long)wParam,buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'l': {
                    before++;
                    len = GetInt((long)lParam,buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 't': {
                    before++;
                    len = GetInt((long)GetTickCount(), buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'x': {
                    POINT pt;
                    GetCursorPos(&pt);
                    before++;
                    len = GetIntDec((long)pt.x, buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'y': {
                    POINT pt;
                    GetCursorPos(&pt);
                    before++;
                    len = GetIntDec((long)pt.y,buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'X': {
                    DWORD dw;
                    dw = GetMessagePos();
                    before++;
                    len = GetIntDec((long)LOWORD(dw),buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'Y': {
                    DWORD dw;
                    dw = GetMessagePos();
                    before++;
                    len = GetIntDec((long)HIWORD(dw),buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case 'H': {
                    before++;
                    len = GetInt(PTR2INT(icoPtr->hwndFocus), buffer, sizeof(buffer));
                    ptr = buffer;
                    break;
                }
                case '%': {
                    before++;
                    len = 1;
                    ptr = "%";
                    break;
                }
            }
        }
        if (SPACELEFT < len) {
            char *newspace;
            ptrdiff_t dist = dst - after;
            int alloclen = ALLOCLEN;
            newspace = (char *)ckalloc(alloclen);
            if (dist>0)
                memcpy(newspace, after, dist);
            if (after && *aftersize) {
                ckfree(after);
            }
            *aftersize =alloclen;
            after = newspace;
            dst = after + dist;
        }
        if (len > 0) {
            memcpy(dst, ptr, len);
        }
        dst += len;
        if ((dst-after)>(*aftersize-1)) {
            printf("oops\n");
        }
        before++;
    }
    *dst = 0;
    return after;
}

/*
 *----------------------------------------------------------------------
 *
 * TaskbarEval --
 *
 * Parse mouse and keyboard events over taskbar.
 *
 * Results:
 *	Event processing.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
TaskbarEval(
    IcoInfo *icoPtr,
    WPARAM wParam,
    LPARAM lParam)
{
    const char *msgstring = "none";
    char evalspace[200];
    int evalsize = 200;
    char *expanded;
    int fixup = 0;

    switch (lParam) {
    case WM_MOUSEMOVE:
        msgstring = "WM_MOUSEMOVE";
        icoPtr->hwndFocus = GetFocus();
        break;
    case WM_LBUTTONDOWN:
        msgstring = "WM_LBUTTONDOWN";
        fixup = 1;
        break;
    case WM_LBUTTONUP:
        msgstring = "WM_LBUTTONUP";
        fixup = 1;
        break;
    case WM_LBUTTONDBLCLK:
        msgstring = "WM_LBUTTONDBLCLK";
        fixup = 1;
        break;
    case WM_RBUTTONDOWN:
        msgstring = "WM_RBUTTONDOWN";
        fixup = 1;
        break;
    case WM_RBUTTONUP:
        msgstring = "WM_RBUTTONUP";
        fixup = 1;
        break;
    case WM_RBUTTONDBLCLK:
        msgstring = "WM_RBUTTONDBLCLK";
        fixup = 1;
        break;
    case WM_MBUTTONDOWN:
        msgstring = "WM_MBUTTONDOWN";
        fixup = 1;
        break;
    case WM_MBUTTONUP:
        msgstring = "WM_MBUTTONUP";
        fixup = 1;
        break;
    case WM_MBUTTONDBLCLK:
        msgstring = "WM_MBUTTONDBLCLK";
        fixup = 1;
        break;
    default:
        msgstring = "WM_NULL";
        fixup = 0;
    }
    expanded = TaskbarExpandPercents(icoPtr, msgstring, wParam, lParam,
            Tcl_GetString(icoPtr->taskbar_command), evalspace, &evalsize);
    if (icoPtr->interp != NULL) {
        int result;
        HWND hwnd = NULL;

        /* See http://support.microsoft.com/kb/q135788/
         * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
        if (fixup) {
            if (icoPtr->hwndFocus != NULL && IsWindow(icoPtr->hwndFocus)) {
                hwnd = icoPtr->hwndFocus;
            } else {
                Tk_Window tkwin = Tk_MainWindow(icoPtr->interp);
                if (tkwin != NULL) {
                    hwnd = Tk_GetHWND(Tk_WindowId(tkwin));
                }
            }
            if (hwnd != NULL) {
                SetForegroundWindow(hwnd);
            }
        }

        result = Tcl_GlobalEval(icoPtr->interp, expanded);

        if (hwnd != NULL) {
            /* See http://support.microsoft.com/kb/q135788/
             * Seems to have moved to https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/135788 */
            PostMessageW(hwnd, WM_NULL, 0, 0);
        }
        if (result != TCL_OK) {
            char buffer[100];
            snprintf(buffer, 100, "\n  (command bound to taskbar-icon ico#%d)", icoPtr->id);
            Tcl_AddErrorInfo(icoPtr->interp, buffer);
            Tcl_BackgroundError(icoPtr->interp);
        }
    }
    if (expanded != evalspace) {
        ckfree(expanded);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TaskbarHandlerProc --
 *
 * 	Windows callback procedure, if ICON_MESSAGE arrives, try to execute
 * 	the taskbar_command.
 *
 * Results:
 *	Command execution.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static LRESULT CALLBACK
TaskbarHandlerProc(
    HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    static UINT msgTaskbarCreated = 0;
    IcoInterpInfo *icoInterpPtr;
    IcoInfo *icoPtr;

    switch (message) {
    case WM_CREATE:
        msgTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
        break;

    case ICON_MESSAGE:
        for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
            if (icoInterpPtr->hwnd == hwnd) {
                for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
                    if (icoPtr->id == wParam) {
                        if (icoPtr->taskbar_command != NULL) {
                            TaskbarEval(icoPtr, wParam, lParam);
                        }
                        break;
                    }
                }
                break;
            }
        }
        break;

    default:
        /*
         * Check to see if explorer has been restarted and we need to
         * re-add our icons.
         */
        if (message == msgTaskbarCreated) {
            for (icoInterpPtr = firstIcoInterpPtr; icoInterpPtr != NULL; icoInterpPtr = icoInterpPtr->nextPtr) {
                if (icoInterpPtr->hwnd == hwnd) {
                    for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = icoPtr->nextPtr) {
                        if (icoPtr->taskbar_flags & TASKBAR_ICON) {
                            TaskbarOperation(icoInterpPtr, icoPtr, NIM_ADD);
                        }
                    }
                    break;
                }
            }
        }
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * RegisterHandlerClass --
 *
 * 	Registers the handler window class.
 *
 * Results:
 *	Handler class registered.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
RegisterHandlerClass(
    HINSTANCE hInstance)
{
    WNDCLASS wndclass;
    memset(&wndclass, 0, sizeof(WNDCLASS));
    wndclass.style = 0;
    wndclass.lpfnWndProc = TaskbarHandlerProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = HANDLER_CLASS;
    return RegisterClass(&wndclass);
}

/*
 *----------------------------------------------------------------------
 *
 * CreateTaskbarHandlerWindow --
 *
 * 	Creates a hidden window to handle taskbar messages.
 *
 * Results:
 *	Hidden window created.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static HWND
CreateTaskbarHandlerWindow(void) {
    static int registered = 0;
    HINSTANCE hInstance = GETHINSTANCE;
    if (!registered) {
        if (!RegisterHandlerClass(hInstance))
            return 0;
        registered = 1;
    }
    return CreateWindow(HANDLER_CLASS, "", WS_OVERLAPPED, 0, 0,
            CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * WinIcoDestroy --
 *
 *	Event handler to delete systray icons when interp main window
 *	is deleted, either by destroy, interp deletion or application
 *	exit.
 *
 * Results:
 *	Icon/window removed and memory freed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
WinIcoDestroy(
    void *clientData,
    XEvent *eventPtr)
{
    IcoInterpInfo *icoInterpPtr = (IcoInterpInfo*) clientData;
    IcoInterpInfo *prevIcoInterpPtr;
    IcoInfo *icoPtr;
    IcoInfo *nextPtr;

    if (eventPtr->type != DestroyNotify) {
        return;
    }

    if (firstIcoInterpPtr == icoInterpPtr) {
        firstIcoInterpPtr = icoInterpPtr->nextPtr;
    } else {
        for (prevIcoInterpPtr = firstIcoInterpPtr; prevIcoInterpPtr->nextPtr != icoInterpPtr;
                prevIcoInterpPtr = prevIcoInterpPtr->nextPtr) {
            /* Empty loop body. */
        }
        prevIcoInterpPtr->nextPtr = icoInterpPtr->nextPtr;
    }

    DestroyWindow(icoInterpPtr->hwnd);
    for (icoPtr = icoInterpPtr->firstIcoPtr; icoPtr != NULL; icoPtr = nextPtr) {
            nextPtr = icoPtr->nextPtr;
        FreeIcoPtr(icoInterpPtr, icoPtr);
    }
    ckfree(icoInterpPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * WinSystrayCmd --
 *
 * 	Main command for creating, displaying, and removing icons from taskbar.
 *
 * Results:
 *	Management of icon display in taskbar/system tray.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
WinSystrayCmd(
    void *clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    static const char *const cmdStrings[] = {
        "add", "delete", "modify", NULL
    };
    enum { CMD_ADD, CMD_DELETE, CMD_MODIFY };
    static const char *const optStrings[] = {
        "-callback", "-image", "-text", NULL
    };
    enum { OPT_CALLBACK, OPT_IMAGE, OPT_TEXT };
    int cmd, opt;

    HICON hIcon;
    int i;
    IcoInterpInfo *icoInterpPtr = (IcoInterpInfo*) clientData;
    IcoInfo *icoPtr = NULL;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "command ...");
        return TCL_ERROR;
    }
    if (Tcl_GetIndexFromObj(interp, objv[1], cmdStrings, "command",
            0, &cmd) == TCL_ERROR) {
        return TCL_ERROR;
    }
    switch (cmd) {
        case CMD_ADD:
        case CMD_MODIFY: {
            Tcl_Obj *imageObj = NULL, *textObj = NULL, *callbackObj = NULL;
            int optStart;
            int oper;
            if (cmd == CMD_ADD) {
                optStart = 2;
                oper = NIM_ADD;
            } else {
                optStart = 3;
                oper = NIM_MODIFY;
                if (objc != 5) {
                    Tcl_WrongNumArgs(interp, 2, objv, "id option value");
                    return TCL_ERROR;
                }
                icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
                if (icoPtr == NULL) {
                    return TCL_ERROR;
                }
            }
            for (i = optStart; i < objc; i += 2) {
                if (Tcl_GetIndexFromObj(interp, objv[i], optStrings, "option",
                        0, &opt) == TCL_ERROR) {
                    return TCL_ERROR;
                }
                if (i+1 >= objc) {
                    Tcl_AppendResult(interp,
                            "missing value for option \"", Tcl_GetString(objv[i]),
                            "\"", NULL);
                    return TCL_ERROR;
                }
                switch (opt) {
                    case OPT_IMAGE:
                        imageObj = objv[i+1];
                        break;
                    case OPT_TEXT:
                        textObj = objv[i+1];
                        break;
                    case OPT_CALLBACK:
                        callbackObj = objv[i+1];
                        break;
                }
            }
            if (cmd == CMD_ADD && imageObj == NULL) {
                Tcl_SetObjResult(interp, Tcl_NewStringObj("missing required option \"-image\"", TCL_INDEX_NONE));
                return TCL_ERROR;
            }
            if (imageObj != NULL) {
                Tk_PhotoHandle photo;
                int width, height;
                Tk_PhotoImageBlock block;

                photo = Tk_FindPhoto(interp, Tcl_GetString(imageObj));
                if (photo == NULL) {
                    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                            "image \"%s\" doesn't exist", Tcl_GetString(imageObj)));
                    return TCL_ERROR;
                }
                Tk_PhotoGetSize(photo, &width, &height);
                Tk_PhotoGetImage(photo, &block);
                hIcon = CreateIcoFromPhoto(width, height, block);
                if (hIcon == NULL) {
                    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
                            "failed to create an iconphoto with image \"%s\"", Tcl_GetString(imageObj)));
                    return TCL_ERROR;
                }
            }
            if (cmd == CMD_ADD) {
                icoPtr = NewIcon(interp, icoInterpPtr, hIcon);
            } else {
                if (imageObj != NULL) {
                    DestroyIcon(icoPtr->hIcon);
                    icoPtr->hIcon = hIcon;
                }
            }
            if (callbackObj != NULL) {
                if (icoPtr->taskbar_command != NULL) {
                    Tcl_DecrRefCount(icoPtr->taskbar_command);
                }
                icoPtr->taskbar_command = callbackObj;
                Tcl_IncrRefCount(icoPtr->taskbar_command);
            }
            if (textObj != NULL) {
                if (icoPtr->taskbar_txt != NULL) {
                    Tcl_DecrRefCount(icoPtr->taskbar_txt);
                }
                icoPtr->taskbar_txt = textObj;
                Tcl_IncrRefCount(icoPtr->taskbar_txt);
            }
            TaskbarOperation(icoInterpPtr, icoPtr, oper);
            if (cmd == CMD_ADD) {
                char buffer[5 + TCL_INTEGER_SPACE];
                int n;
                n = snprintf(buffer, sizeof(buffer) - 1, "ico#%d", icoPtr->id);
                buffer[n] = 0;
                Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, n));
            }
            return TCL_OK;
        }
        case CMD_DELETE:
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "id");
                return TCL_ERROR;
            }
            icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
            if (icoPtr == NULL) {
                return TCL_ERROR;
            }
            FreeIcoPtr(icoInterpPtr, icoPtr);
            return TCL_OK;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WinSysNotifyCmd --
 *
 * 	Main command for creating and displaying notifications/balloons from system tray.
 *
 * Results:
 *	Display of notifications.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
WinSysNotifyCmd(
    void *clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    IcoInterpInfo *icoInterpPtr = (IcoInterpInfo*) clientData;
    IcoInfo *icoPtr;
    Tcl_DString infodst;
    Tcl_DString titledst;
    NOTIFYICONDATAW ni;
    char *msgtitle;
    char *msginfo;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "command ...");
        return TCL_ERROR;
    }
    if (strcmp(Tcl_GetString(objv[1]), "notify") != 0) {
        Tcl_AppendResult(interp, "unknown subcommand \"", Tcl_GetString(objv[1]),
                "\": must be notify", NULL);
        return TCL_ERROR;
    }
    if (objc != 5) {
        Tcl_WrongNumArgs(interp, 2, objv, "id title detail");
        return TCL_ERROR;
    }

    icoPtr = GetIcoPtr(interp, icoInterpPtr, Tcl_GetString(objv[2]));
    if (icoPtr == NULL) {
        return TCL_ERROR;
    }

    ni.cbSize = sizeof(NOTIFYICONDATAW);
    ni.hWnd = icoInterpPtr->hwnd;
    ni.uID = icoPtr->id;
    ni.uFlags = NIF_INFO;
    ni.uCallbackMessage = ICON_MESSAGE;
    ni.hIcon = icoPtr->hIcon;
    ni.dwInfoFlags = NIIF_INFO; /* Use a sane platform-specific icon here.*/

    msgtitle = Tcl_GetString(objv[3]);
    msginfo = Tcl_GetString(objv[4]);

    /* Balloon notification for system tray icon. */
    if (msgtitle != NULL) {
        WCHAR *title;
        Tcl_DStringInit(&titledst);
        title = Tcl_UtfToWCharDString(msgtitle, TCL_INDEX_NONE, &titledst);
        wcsncpy(ni.szInfoTitle, title, (Tcl_DStringLength(&titledst) + 2) / 2);
        Tcl_DStringFree(&titledst);
    }
    if (msginfo != NULL) {
        WCHAR *info;
        Tcl_DStringInit(&infodst);
        info = Tcl_UtfToWCharDString(msginfo, TCL_INDEX_NONE, &infodst);
        wcsncpy(ni.szInfo, info, (Tcl_DStringLength(&infodst) + 2) / 2);
        Tcl_DStringFree(&infodst);
    }

    Shell_NotifyIconW(NIM_MODIFY, &ni);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WinIcoInit --
 *
 * 	Initialize this package and create script-level commands.
 *
 * Results:
 *	Initialization of code.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
WinIcoInit(
    Tcl_Interp *interp)
{
    IcoInterpInfo *icoInterpPtr;
    Tk_Window mainWindow;

    mainWindow = Tk_MainWindow(interp);
    if (mainWindow == NULL) {
        Tcl_SetObjResult(interp, Tcl_NewStringObj("main window has been destroyed", TCL_INDEX_NONE));
        return TCL_ERROR;
    }

    icoInterpPtr = (IcoInterpInfo*) ckalloc(sizeof(IcoInterpInfo));
    icoInterpPtr->counter = 0;
    icoInterpPtr->firstIcoPtr = NULL;
    icoInterpPtr->hwnd = CreateTaskbarHandlerWindow();
    icoInterpPtr->nextPtr = firstIcoInterpPtr;
    firstIcoInterpPtr = icoInterpPtr;
    Tcl_CreateObjCommand(interp, "::tk::systray::_systray", WinSystrayCmd,
            icoInterpPtr, NULL);
    Tcl_CreateObjCommand(interp, "::tk::sysnotify::_sysnotify", WinSysNotifyCmd,
            icoInterpPtr, NULL);

    Tk_CreateEventHandler(mainWindow, StructureNotifyMask,
            WinIcoDestroy, icoInterpPtr);

    return TCL_OK;
}

/*
 * Local variables:
 * mode: c
 * indent-tabs-mode: nil
 * End:
 */

Changes to win/tkWinTest.c.

1
2
3
4
5
6
7
8
9



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
















35
36
37
38
39
40
41
1
2
3
4
5
6



7
8
9
10
11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26






27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49






-
-
-
+
+
+










-
-







-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







/*
 * tkWinTest.c --
 *
 *	Contains commands for platform specific tests for the Windows
 *	platform.
 *
 * Copyright © 1997 Sun Microsystems, Inc.
 * Copyright © 2000 Scriptics Corporation.
 * Copyright © 2001 ActiveState Corporation.
 * Copyright (c) 1997 Sun Microsystems, Inc.
 * Copyright (c) 2000 by Scriptics Corporation.
 * Copyright (c) 2001 by ActiveState Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#undef USE_TCL_STUBS
#define USE_TCL_STUBS
#undef USE_TK_STUBS
#define USE_TK_STUBS
#include "tkWinInt.h"
#undef TCLBOOLWARNING
#define TCLBOOLWARNING(boolPtr) /* needed here because we compile with -Wc++-compat */

HWND tkWinCurrentDialog;

/*
 * Forward declarations of functions defined later in this file:
 */

static Tcl_ObjCmdProc TestclipboardObjCmd;
static Tcl_ObjCmdProc TestwineventObjCmd;
static Tcl_ObjCmdProc TestfindwindowObjCmd;
static Tcl_ObjCmdProc TestgetwindowinfoObjCmd;
static Tcl_ObjCmdProc TestwinlocaleObjCmd;
static Tk_GetSelProc SetSelectionResult;
static int		TestclipboardObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		TestwineventObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		TestfindwindowObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		TestgetwindowinfoObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		TestwinlocaleObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static Tk_GetSelProc		SetSelectionResult;

/*
 *----------------------------------------------------------------------
 *
 * TkplatformtestInit --
 *
 *	Defines commands that test platform specific functionality for Windows
55
56
57
58
59
60
61
62

63
64

65
66

67
68

69
70

71
72
73
74
75
76
77
63
64
65
66
67
68
69

70
71

72
73

74
75

76
77

78
79
80
81
82
83
84
85







-
+

-
+

-
+

-
+

-
+







    Tcl_Interp *interp)		/* Interpreter to add commands to. */
{
    /*
     * Add commands for platform specific tests on MacOS here.
     */

    Tcl_CreateObjCommand(interp, "testclipboard", TestclipboardObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testwinevent", TestwineventObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testfindwindow", TestfindwindowObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testgetwindowinfo", TestgetwindowinfoObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    Tcl_CreateObjCommand(interp, "testwinlocale", TestwinlocaleObjCmd,
	    Tk_MainWindow(interp), NULL);
	    (ClientData) Tk_MainWindow(interp), NULL);
    return TCL_OK;
}

struct TestFindControlState {
    int  id;
    HWND control;
};
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157







-
+







    char id[TCL_INTEGER_SPACE], msgBuf[24 + TCL_INTEGER_SPACE];
    Tcl_DString ds;
    Tcl_Obj *resultPtr = Tcl_GetObjResult(interp);

    if (Tcl_IsShared(resultPtr)) {
	resultPtr = Tcl_DuplicateObj(resultPtr);
    }
    length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
    length = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
	    | FORMAT_MESSAGE_IGNORE_INSERTS
	    | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error,
	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (WCHAR *) wMsgPtrPtr,
	    0, NULL);
    if (length == 0) {
	char *msgPtr;

159
160
161
162
163
164
165
166

167
168
169

170
171
172
173



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
167
168
169
170
171
172
173

174
175
176
177
178
179
180


181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210







-
+



+


-
-
+
+
+



















-
+







	    LocalFree(msgPtr);
	}
    }
    if (length == 0) {
	if (error == ERROR_CALL_NOT_IMPLEMENTED) {
	    strcpy(msgBuf, "function not supported under Win32s");
	} else {
	    snprintf(msgBuf, sizeof(msgBuf), "unknown error: %ld", error);
	    sprintf(msgBuf, "unknown error: %ld", error);
	}
	msg = msgBuf;
    } else {
	Tcl_Encoding encoding;
	char *msgPtr;

	Tcl_DStringInit(&ds);
	Tcl_WCharToUtfDString(wMsgPtr, wcslen(wMsgPtr), &ds);
	encoding = Tcl_GetEncoding(NULL, "unicode");
	Tcl_ExternalToUtfDString(encoding, (char *) wMsgPtr, -1, &ds);
	Tcl_FreeEncoding(encoding);
	LocalFree(wMsgPtr);

	msgPtr = Tcl_DStringValue(&ds);
	length = Tcl_DStringLength(&ds);

	/*
	 * Trim the trailing CR/LF from the system message.
	 */

	if (msgPtr[length-1] == '\n') {
	    --length;
	}
	if (msgPtr[length-1] == '\r') {
	    --length;
	}
	msgPtr[length] = 0;
	msg = msgPtr;
    }

    snprintf(id, sizeof(id), "%ld", error);
    sprintf(id, "%ld", error);
    Tcl_SetErrorCode(interp, "WINDOWS", id, msg, NULL);
    Tcl_AppendToObj(resultPtr, msg, length);
    Tcl_SetObjResult(interp, resultPtr);

    if (length != 0) {
	Tcl_DStringFree(&ds);
    }
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232

233
234
235
236
237

238
239
240
241
242
243
244
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241

242
243
244
245
246

247
248
249
250
251
252
253
254







-
+









-
+




-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
SetSelectionResult(
    TCL_UNUSED(void *),
    ClientData dummy,
    Tcl_Interp *interp,
    const char *selection)
{
    Tcl_AppendResult(interp, selection, NULL);
    return TCL_OK;
}

static int
TestclipboardObjCmd(
    void *clientData,	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = (Tk_Window) clientData;

    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
    return TkSelGetSelection(interp, tkwin, Tk_InternAtom(tkwin, "CLIPBOARD"),
	    XA_STRING, SetSelectionResult, NULL);
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311
312
313
314

315
316
317
318

319
320
321
322
323
324
325
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292










293
294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310
311
312
313

314
315
316
317

318
319
320
321
322
323
324
325







-
+
















-
-
-
-
-
-
-
-
-
-










-
+










-
+



-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
TestwineventObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])		/* Argument strings. */
{
    HWND hwnd = 0;
    HWND child = 0;
    HWND control;
    int id;
    char *rest;
    UINT message;
    WPARAM wParam;
    LPARAM lParam;
    LRESULT result;
    static const TkStateMap messageMap[] = {
	{WM_LBUTTONDOWN,	"WM_LBUTTONDOWN"},
	{WM_LBUTTONUP,		"WM_LBUTTONUP"},
	{WM_LBUTTONDBLCLK,		"WM_LBUTTONDBLCLK"},
	{WM_MBUTTONDOWN,	"WM_MBUTTONDOWN"},
	{WM_MBUTTONUP,		"WM_MBUTTONUP"},
	{WM_MBUTTONDBLCLK,		"WM_MBUTTONDBLCLK"},
	{WM_RBUTTONDOWN,	"WM_RBUTTONDOWN"},
	{WM_RBUTTONUP,		"WM_RBUTTONUP"},
	{WM_RBUTTONDBLCLK,		"WM_RBUTTONDBLCLK"},
	{WM_XBUTTONDOWN,	"WM_XBUTTONDOWN"},
	{WM_XBUTTONUP,		"WM_XBUTTONUP"},
	{WM_XBUTTONDBLCLK,		"WM_XBUTTONDBLCLK"},
	{WM_CHAR,		"WM_CHAR"},
	{WM_GETTEXT,		"WM_GETTEXT"},
	{WM_SETTEXT,		"WM_SETTEXT"},
	{WM_COMMAND,            "WM_COMMAND"},
	{-1,			NULL}
    };

    if ((objc == 3) && (strcmp(Tcl_GetString(objv[1]), "debug") == 0)) {
	int b;

	if (Tcl_GetBooleanFromObj(interp, objv[2], &b) != TCL_OK) {
	if (Tcl_GetBoolean(interp, Tcl_GetString(objv[2]), &b) != TCL_OK) {
	    return TCL_ERROR;
	}
	TkWinDialogDebug(b);
	return TCL_OK;
    }

    if (objc < 4) {
	return TCL_ERROR;
    }

    hwnd = (HWND)INT2PTR(strtol(Tcl_GetString(objv[1]), &rest, 0));
    hwnd = INT2PTR(strtol(Tcl_GetString(objv[1]), &rest, 0));
    if (rest == Tcl_GetString(objv[1])) {
	hwnd = FindWindowA(NULL, Tcl_GetString(objv[1]));
	if (hwnd == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("no such window", TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("no such window", -1));
	    return TCL_ERROR;
	}
    }
    UpdateWindow(hwnd);

    id = strtol(Tcl_GetString(objv[2]), &rest, 0);
    if (rest == Tcl_GetString(objv[2])) {
366
367
368
369
370
371
372

373

374
375
376
377
378
379
380
381
382
383
384
385






386
387
388



389
390
391
392
393



394
395
396
397
398
399
400
401
402
403
404


405
406
407
408
409
410

411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

433
434
435
436
437

438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

453
454
455

456
457
458



459
460
461
462
463
464

465
466
467
468
469
470
471
472
473
474
475
476


477
478

479
480
481
482

483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

499
500
501
502
503
504

505
506
507
508
509
510
511
512

513
514
515
516
517
518
519
520
521
522
523
524

525
526

527
528
529
530
531


532
533
534
535
536
537
538
539
540
541

542
543

544
545
546
547
548
549

550
551
552
553

554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570

571
572
573
574
575
576
577
578
579
580
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380






381
382
383
384
385
386



387
388
389
390
391



392
393
394
395
396
397
398
399
400
401
402
403


404
405
406
407
408
409
410

411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

433
434
435
436
437

438
439
440
441
442
443
444
445
446
447
448
449
450
451


452
453


454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

482
483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507

508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523
524
525
526
527

528
529

530
531
532
533


534
535
536
537
538
539
540
541
542
543
544

545


546
547
548
549
550
551

552
553
554
555

556
557
558
559
560
561
562
563

564
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582
583







+
-
+






-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+


-
-
-
+
+
+









-
-
+
+





-
+

-
+



















-
+




-
+













-
-
+

-
-
+



+
+
+





-
+












+
+

-
+



-
+















-
+





-
+







-
+











-
+

-
+



-
-
+
+









-
+
-
-
+





-
+



-
+







-
+








-
+










                             Tcl_ObjPrintf("Could not find control with id %d", id));
            return TCL_ERROR;
        }
        buf[0] = 0;
        SendMessageA(control, WM_GETTEXT, (WPARAM)sizeof(buf),
                     (LPARAM) buf);
#endif
	Tcl_ExternalToUtfDString(NULL, buf, -1, &ds);
	Tcl_AppendResult(interp, Tcl_ExternalToUtfDString(NULL, buf, TCL_INDEX_NONE, &ds), NULL);
	Tcl_AppendResult(interp, Tcl_DStringValue(&ds), NULL);
	Tcl_DStringFree(&ds);
	break;
    }
    case WM_SETTEXT: {
	Tcl_DString ds;

	control = TestFindControl(hwnd, id);
	if (control == NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_ObjPrintf("Could not find control with id %d", id));
	    return TCL_ERROR;
	}
        control = TestFindControl(hwnd, id);
        if (control == NULL) {
            Tcl_SetObjResult(interp,
                             Tcl_ObjPrintf("Could not find control with id %d", id));
            return TCL_ERROR;
        }
	Tcl_DStringInit(&ds);
	LPARAM lparam = (LPARAM)Tcl_UtfToExternalDString(NULL, Tcl_GetString(objv[4]), TCL_INDEX_NONE, &ds);
	result = SendMessageA(control, WM_SETTEXT, 0, lparam);
	Tcl_UtfToExternalDString(NULL, Tcl_GetString(objv[4]), -1, &ds);
        result = SendMessageA(control, WM_SETTEXT, 0,
                                  (LPARAM) Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);
	if (result == 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to send text to dialog: ", TCL_INDEX_NONE));
	    AppendSystemError(interp, GetLastError());
	    return TCL_ERROR;
            Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to send text to dialog: ", -1));
            AppendSystemError(interp, GetLastError());
            return TCL_ERROR;
	}
	break;
    }
    case WM_COMMAND: {
	char buf[TCL_INTEGER_SPACE];
	if (objc < 5) {
	    wParam = MAKEWPARAM(id, 0);
	    lParam = (LPARAM)child;
	}
	snprintf(buf, sizeof(buf), "%d", (int) SendMessageA(hwnd, message, wParam, lParam));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
	sprintf(buf, "%d", (int) SendMessageA(hwnd, message, wParam, lParam));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
	break;
    }
    default: {
	char buf[TCL_INTEGER_SPACE];

	snprintf(buf, sizeof(buf), "%d",
	sprintf(buf, "%d",
		(int) SendDlgItemMessageA(hwnd, id, message, wParam, lParam));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
	break;
    }
    }
    return TCL_OK;
}

/*
 *  testfindwindow title ?class?
 *	Find a Windows window using the FindWindow API call. This takes the window
 *	title and optionally the window class and if found returns the HWND and
 *	raises an error if the window is not found.
 *	eg: testfindwindow Console TkTopLevel
 *	    Can find the console window if it is visible.
 *	eg: testfindwindow "TkTest #10201" "#32770"
 *	    Can find a messagebox window with this title.
 */

static int
TestfindwindowObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
	LPCWSTR title = NULL, windowClass = NULL;
    const TCHAR  *title = NULL, *class = NULL;
    Tcl_DString titleString, classString;
    HWND hwnd = NULL;
    int r = TCL_OK;
    DWORD myPid;

    Tcl_DStringInit(&classString);
    Tcl_DStringInit(&titleString);

    if (objc < 2 || objc > 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "title ?class?");
        return TCL_ERROR;
    }

    Tcl_DStringInit(&titleString);
    title = Tcl_UtfToWCharDString(Tcl_GetString(objv[1]), TCL_INDEX_NONE, &titleString);
    title = Tcl_WinUtfToTChar(Tcl_GetString(objv[1]), -1, &titleString);
    if (objc == 3) {
	Tcl_DStringInit(&classString);
	windowClass = Tcl_UtfToWCharDString(Tcl_GetString(objv[2]), TCL_INDEX_NONE, &classString);
        class = Tcl_WinUtfToTChar(Tcl_GetString(objv[2]), -1, &classString);
    }
    if (title[0] == 0)
        title = NULL;
#if 0
    hwnd  = FindWindow(class, title);
#else
    /* We want find a window the belongs to us and not some other process */
    hwnd = NULL;
    myPid = GetCurrentProcessId();
    while (1) {
        DWORD pid, tid;
        hwnd = FindWindowExW(NULL, hwnd, windowClass, title);
        hwnd = FindWindowEx(NULL, hwnd, class, title);
        if (hwnd == NULL)
            break;
        tid = GetWindowThreadProcessId(hwnd, &pid);
        if (tid == 0) {
            /* Window has gone */
            hwnd = NULL;
            break;
        }
        if (pid == myPid)
            break;              /* Found it */
    }

#endif

    if (hwnd == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to find window: ", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to find window: ", -1));
	AppendSystemError(interp, GetLastError());
	r = TCL_ERROR;
    } else {
        Tcl_SetObjResult(interp, Tcl_NewWideIntObj(PTR2INT(hwnd)));
        Tcl_SetObjResult(interp, Tcl_NewWideIntObj((size_t)hwnd));
    }

    Tcl_DStringFree(&titleString);
    Tcl_DStringFree(&classString);
    return r;

}

static BOOL CALLBACK
EnumChildrenProc(
    HWND hwnd,
    LPARAM lParam)
{
    Tcl_Obj *listObj = (Tcl_Obj *) lParam;

    Tcl_ListObjAppendElement(NULL, listObj, Tcl_NewWideIntObj(PTR2INT(hwnd)));
    Tcl_ListObjAppendElement(NULL, listObj, Tcl_NewWideIntObj((size_t)hwnd));
    return TRUE;
}

static int
TestgetwindowinfoObjCmd(
    TCL_UNUSED(void *),
    ClientData clientData,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_WideInt hwnd;
    Tcl_Obj *dictObj = NULL, *classObj = NULL, *textObj = NULL;
    Tcl_Obj *childrenObj = NULL;
    WCHAR buf[512];
    TCHAR buf[512];
    int cch, cchBuf = 256;
    Tcl_DString ds;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "hwnd");
	return TCL_ERROR;
    }

    if (Tcl_GetWideIntFromObj(interp, objv[1], &hwnd) != TCL_OK)
	return TCL_ERROR;

    cch = GetClassNameW((HWND)INT2PTR(hwnd), buf, cchBuf);
    cch = GetClassName((HWND)(size_t)hwnd, buf, cchBuf);
    if (cch == 0) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to get class name: ", TCL_INDEX_NONE));
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("failed to get class name: ", -1));
    	AppendSystemError(interp, GetLastError());
    	return TCL_ERROR;
    } else {
	Tcl_DStringInit(&ds);
	Tcl_WCharToUtfDString(buf, wcslen(buf), &ds);
	Tcl_DString ds;
	Tcl_WinTCharToUtf(buf, -1, &ds);
	classObj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
	Tcl_DStringFree(&ds);
    }

    dictObj = Tcl_NewDictObj();
    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("class", 5), classObj);
    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("id", 2),
	Tcl_NewWideIntObj(GetWindowLongPtr((HWND)(size_t)hwnd, GWL_ID)));

    cch = GetWindowTextW((HWND)INT2PTR(hwnd), buf, cchBuf);
    cch = GetWindowText((HWND)(size_t)hwnd, (LPTSTR)buf, cchBuf);
	Tcl_DStringInit(&ds);
    Tcl_WCharToUtfDString(buf, cch, &ds);
    Tcl_WinTCharToUtf(buf, cch * sizeof (WCHAR), &ds);
    textObj = Tcl_NewStringObj(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
    Tcl_DStringFree(&ds);

    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("text", 4), textObj);
    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("parent", 6),
	Tcl_NewWideIntObj(PTR2INT(GetParent((HWND)(size_t)hwnd))));
	Tcl_NewWideIntObj((size_t)(GetParent((HWND)(size_t)hwnd))));

    childrenObj = Tcl_NewListObj(0, NULL);
    EnumChildWindows((HWND)(size_t)hwnd, EnumChildrenProc, (LPARAM)childrenObj);
    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("children", TCL_INDEX_NONE), childrenObj);
    Tcl_DictObjPut(interp, dictObj, Tcl_NewStringObj("children", -1), childrenObj);

    Tcl_SetObjResult(interp, dictObj);
    return TCL_OK;
}

static int
TestwinlocaleObjCmd(
    TCL_UNUSED(void *),	/* Main window for application. */
    ClientData clientData,	/* Main window for application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument values. */
{
    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetThreadLocale()));
    Tcl_SetObjResult(interp, Tcl_NewIntObj((int)GetThreadLocale()));
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to win/tkWinWindow.c.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
1
2
3
4
5
6

7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23






-
+








-
+







/*
 * tkWinWindow.c --
 *
 *	Xlib emulation routines for Windows related to creating, displaying
 *	and destroying windows.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-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.
 */

#include "tkWinInt.h"
#include "tkBusy.h"

typedef struct {
typedef struct ThreadSpecificData {
    int initialized;		/* 0 means table below needs initializing. */
    Tcl_HashTable windowTable;  /* The windowTable maps from HWND to Tk_Window
				 * handles. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74

75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73

74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90







-
+
















-
+




-
+








-
+







 */

Window
Tk_AttachHWND(
    Tk_Window tkwin,
    HWND hwnd)
{
    int isNew;
    int new;
    Tcl_HashEntry *entryPtr;
    TkWinDrawable *twdPtr = (TkWinDrawable *) Tk_WindowId(tkwin);
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	Tcl_InitHashTable(&tsdPtr->windowTable, TCL_ONE_WORD_KEYS);
	tsdPtr->initialized = 1;
    }

    /*
     * Allocate a new drawable if necessary. Otherwise, remove the previous
     * HWND from from the window table.
     */

    if (twdPtr == NULL) {
	twdPtr = (TkWinDrawable *)ckalloc(sizeof(TkWinDrawable));
	twdPtr = ckalloc(sizeof(TkWinDrawable));
	twdPtr->type = TWD_WINDOW;
	twdPtr->window.winPtr = (TkWindow *) tkwin;
    } else if (twdPtr->window.handle != NULL) {
	entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable,
		twdPtr->window.handle);
		(char *)twdPtr->window.handle);
	Tcl_DeleteHashEntry(entryPtr);
    }

    /*
     * Insert the new HWND into the window table.
     */

    twdPtr->window.handle = hwnd;
    entryPtr = Tcl_CreateHashEntry(&tsdPtr->windowTable, (char *)hwnd, &isNew);
    entryPtr = Tcl_CreateHashEntry(&tsdPtr->windowTable, (char *)hwnd, &new);
    Tcl_SetHashValue(entryPtr, tkwin);

    return (Window)twdPtr;
}

/*
 *----------------------------------------------------------------------
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125







-
+







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

    if (!tsdPtr->initialized) {
	Tcl_InitHashTable(&tsdPtr->windowTable, TCL_ONE_WORD_KEYS);
	tsdPtr->initialized = 1;
    }
    entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, hwnd);
    entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, (char *) hwnd);
    if (entryPtr != NULL) {
	return (Tk_Window) Tcl_GetHashValue(entryPtr);
    }
    return NULL;
}

/*
166
167
168
169
170
171
172





173





174
175
176
177
178
179
180
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189







+
+
+
+
+
-
+
+
+
+
+







TkpPrintWindowId(
    char *buf,			/* Pointer to string large enough to hold the
				 * hex representation of a pointer. */
    Window window)		/* Window to be printed into buffer. */
{
    HWND hwnd = (window) ? Tk_GetHWND(window) : 0;

    /*
     * Use pointer representation, because Win64 is P64 (*not* LP64). Windows
     * doesn't print the 0x for %p, so we do it.
     * Bug 2026405: cygwin does output 0x for %p so test and recover.
     */
    snprintf(buf, TCL_INTEGER_SPACE, "0x%" TCL_Z_MODIFIER "x", (size_t)hwnd);

    sprintf(buf, "0x%p", hwnd);
    if (buf[2] == '0' && buf[3] == 'x') {
	sprintf(buf, "%p", hwnd);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpScanWindowId --
 *
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255
256
257
258


259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287







-
+














-
-
+
+





-














-
+







    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MakeWindow --
 * TkpMakeWindow --
 *
 *	Creates a Windows window object based on the current attributes of the
 *	specified TkWindow.
 *
 * Results:
 *	Returns a pointer to a new TkWinDrawable cast to a Window.
 *
 * Side effects:
 *	Creates a new window.
 *
 *----------------------------------------------------------------------
 */

Window
Tk_MakeWindow(
    Tk_Window tkwin,
TkpMakeWindow(
    TkWindow *winPtr,
    Window parent)
{
    HWND parentWin;
    int style;
    HWND hwnd;
    TkWindow *winPtr = (TkWindow *)tkwin;

    if (parent != None) {
	parentWin = Tk_GetHWND(parent);
	style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
    } else {
	parentWin = NULL;
	style = WS_POPUP | WS_CLIPCHILDREN;
    }

    /*
     * Create the window, then ensure that it is at the top of the stacking
     * order.
     */

    hwnd = CreateWindowExW(WS_EX_NOPARENTNOTIFY, TK_WIN_CHILD_CLASS_NAME, NULL,
    hwnd = CreateWindowEx(WS_EX_NOPARENTNOTIFY, TK_WIN_CHILD_CLASS_NAME, NULL,
	    (DWORD) style, Tk_X(winPtr), Tk_Y(winPtr), Tk_Width(winPtr),
	    Tk_Height(winPtr), parentWin, NULL, Tk_GetHINSTANCE(), NULL);
    SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
	    SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
    return Tk_AttachHWND((Tk_Window)winPtr, hwnd);
}

302
303
304
305
306
307
308
309

310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333







-
+








-
+







    Tcl_HashEntry *entryPtr;
    TkWinDrawable *twdPtr = (TkWinDrawable *)w;
    TkWindow *winPtr = TkWinGetWinPtr(w);
    HWND hwnd = Tk_GetHWND(w);
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    LastKnownRequestProcessed(display)++;
    display->request++;

    /*
     * Remove references to the window in the pointer module then release the
     * drawable.
     */

    TkPointerDeadWindow(winPtr);

    entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, hwnd);
    entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, (char*)hwnd);
    if (entryPtr != NULL) {
	Tcl_DeleteHashEntry(entryPtr);
    }

    ckfree(twdPtr);

    /*
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364
365

366
367
368
369
370
371
372
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368





369
370
371
372
373
374
375
376







-
+














-
+

-
-
-
-
-
+







 *----------------------------------------------------------------------
 *
 * XMapWindow --
 *
 *	Cause the given window to become visible.
 *
 * Results:
 *	Always returns Success or BadWindow.
 *	None
 *
 * Side effects:
 *	Causes the window state to change, and generates a MapNotify event.
 *
 *----------------------------------------------------------------------
 */

int
XMapWindow(
    Display *display,
    Window w)
{
    XEvent event;
    TkWindow *parentPtr;
    TkWindow *winPtr;
    TkWindow *winPtr = TkWinGetWinPtr(w);

    if (!w) {
	return BadWindow;
    }
    winPtr = TkWinGetWinPtr(w);
    LastKnownRequestProcessed(display)++;
    display->request++;

    ShowWindow(Tk_GetHWND(w), SW_SHOWNORMAL);
    winPtr->flags |= TK_MAPPED;

    /*
     * Check to see if this window is visible now. If all of the parent
     * windows up to the first toplevel are mapped, then this window and its
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
385
386
387
388
389
390
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414







-
+














-
+







	    }
	    if (parentPtr->flags & TK_TOP_HIERARCHY) {
		break;
	    }
	}
    } else {
	event.type = MapNotify;
	event.xmap.serial = LastKnownRequestProcessed(display);
	event.xmap.serial = display->request;
	event.xmap.send_event = False;
	event.xmap.display = display;
	event.xmap.event = winPtr->window;
	event.xmap.window = winPtr->window;
	event.xmap.override_redirect = winPtr->atts.override_redirect;
	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    }

    /*
     * Generate VisibilityNotify events for this window and its mapped
     * children.
     */

    event.type = VisibilityNotify;
    event.xvisibility.serial = LastKnownRequestProcessed(display);
    event.xvisibility.serial = display->request;
    event.xvisibility.send_event = False;
    event.xvisibility.display = display;
    event.xvisibility.window = winPtr->window;
    event.xvisibility.state = VisibilityUnobscured;
    NotifyVisibility(&event, winPtr);
    return Success;
}
450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
454
455
456
457
458
459
460

461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476





477
478
479
480
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
496







-
+













-
+

-
-
-
-
-
+











-
+







 *----------------------------------------------------------------------
 *
 * XUnmapWindow --
 *
 *	Cause the given window to become invisible.
 *
 * Results:
 *	Always returns Success or BadWindow.
 *	None
 *
 * Side effects:
 *	Causes the window state to change, and generates an UnmapNotify event.
 *
 *----------------------------------------------------------------------
 */

int
XUnmapWindow(
    Display *display,
    Window w)
{
    XEvent event;
    TkWindow *winPtr;
    TkWindow *winPtr = TkWinGetWinPtr(w);

    if (!w) {
	return BadWindow;
    }
    winPtr = TkWinGetWinPtr(w);
    LastKnownRequestProcessed(display)++;
    display->request++;

    /*
     * Bug fix: Don't short circuit this routine based on TK_MAPPED because it
     * will be cleared before XUnmapWindow is called.
     */

    ShowWindow(Tk_GetHWND(w), SW_HIDE);
    winPtr->flags &= ~TK_MAPPED;

    if (winPtr->flags & TK_WIN_MANAGED) {
	event.type = UnmapNotify;
	event.xunmap.serial = LastKnownRequestProcessed(display);
	event.xunmap.serial = display->request;
	event.xunmap.send_event = False;
	event.xunmap.display = display;
	event.xunmap.event = winPtr->window;
	event.xunmap.window = winPtr->window;
	event.xunmap.from_configure = False;
	Tk_HandleEvent(&event);
    }
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







int
XMoveResizeWindow(
    Display *display,
    Window w,
    int x, int y,		/* Position relative to parent. */
    unsigned int width, unsigned int height)
{
    LastKnownRequestProcessed(display)++;
    display->request++;
    MoveWindow(Tk_GetHWND(w), x, y, (int) width, (int) height, TRUE);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559







-
+







XMoveWindow(
    Display *display,
    Window w,
    int x, int y)		/* Position relative to parent */
{
    TkWindow *winPtr = TkWinGetWinPtr(w);

    LastKnownRequestProcessed(display)++;
    display->request++;

    MoveWindow(Tk_GetHWND(w), x, y, winPtr->changes.width,
	    winPtr->changes.height, TRUE);
    return Success;
}

/*
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590







-
+







XResizeWindow(
    Display *display,
    Window w,
    unsigned int width, unsigned int height)
{
    TkWindow *winPtr = TkWinGetWinPtr(w);

    LastKnownRequestProcessed(display)++;
    display->request++;

    MoveWindow(Tk_GetHWND(w), winPtr->changes.x, winPtr->changes.y, (int)width,
	    (int)height, TRUE);
    return Success;
}

/*
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632







-
+











-
+







int
XRaiseWindow(
    Display *display,
    Window w)
{
    HWND window = Tk_GetHWND(w);

    LastKnownRequestProcessed(display)++;
    display->request++;
    SetWindowPos(window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    return Success;
}

int
XLowerWindow(
    Display *display,
    Window w)
{
    HWND window = Tk_GetHWND(w);

    LastKnownRequestProcessed(display)++;
    display->request++;
    SetWindowPos(window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666







-
+







    Window w,
    unsigned int valueMask,
    XWindowChanges *values)
{
    TkWindow *winPtr = TkWinGetWinPtr(w);
    HWND hwnd = Tk_GetHWND(w);

    LastKnownRequestProcessed(display)++;
    display->request++;

    /*
     * Change the shape and/or position of the window.
     */

    if (valueMask & (CWX|CWY|CWWidth|CWHeight)) {
	MoveWindow(hwnd, winPtr->changes.x, winPtr->changes.y,
708
709
710
711
712
713
714
715

716
717
718

719
720
721
722
723
724
725
708
709
710
711
712
713
714

715
716
717

718
719
720
721
722
723
724
725







-
+


-
+







    RECT rc;
    HBRUSH brush;
    HPALETTE oldPalette, palette;
    TkWindow *winPtr;
    HWND hwnd = Tk_GetHWND(w);
    HDC dc = GetDC(hwnd);

    palette = TkWinGetPalette(DefaultColormapOfScreen(ScreenOfDisplay(display, 0)));
    palette = TkWinGetPalette(display->screens[0].cmap);
    oldPalette = SelectPalette(dc, palette, FALSE);

    LastKnownRequestProcessed(display)++;
    display->request++;

    winPtr = TkWinGetWinPtr(w);
    brush = CreateSolidBrush(winPtr->atts.background_pixel);
    GetWindowRect(hwnd, &rc);
    rc.right = rc.right - rc.left;
    rc.bottom = rc.bottom - rc.top;
    rc.left = rc.top = 0;
757
758
759
760
761
762
763



























764
765
766
767
768
769
770
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    XSetWindowAttributes* attributes)
{
    if (valueMask & CWCursor) {
	XDefineCursor(display, w, attributes->cursor);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * XReparentWindow --
 *
 *	TODO: currently placeholder to satisfy Xlib stubs.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	TODO.
 *
 *----------------------------------------------------------------------
 */

int
XReparentWindow(
    Display *display,
    Window w,
    Window parent,
    int x,
    int y)
{
    return BadWindow;
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinSetWindowPos --
 *
 *	Adjust the stacking order of a window relative to a second window (or
836
837
838
839
840
841
842
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
858

859
860
861
862
863
864
865
863
864
865
866
867
868
869

870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

885
886
887
888
889
890
891
892







-
+














-
+







    Window window;

    if (busyPtr->tkBusy != NULL) {
	Tk_MapWindow(busyPtr->tkBusy);
	window = Tk_WindowId(busyPtr->tkBusy);
	display = Tk_Display(busyPtr->tkBusy);
	hWnd = Tk_GetHWND(window);
	LastKnownRequestProcessed(display)++;
	display->request++;
	SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    }

    /*
     * Under Win32, cursors aren't associated with windows. Tk fakes this by
     * watching Motion events on its windows. So Tk will automatically change
     * the cursor when the pointer enters the Busy window. But Windows does
     * not immediately change the cursor; it waits for the cursor position to
     * change or a system call. We need to change the cursor before the
     * application starts processing, so set the cursor position redundantly
     * back to the current position.
     */

    GetCursorPos(&point);
    TkSetCursorPos(point.x, point.y);
    SetCursorPos(point.x, point.y);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpHideBusyWindow --
 *
893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
920
921
922
923
924
925
926

927
928
929
930
931
932
933
934







-
+







     * not immediately change the cursor: it waits for the cursor position to
     * change or a system call. We need to change the cursor before the
     * application starts processing, so set the cursor position redundantly
     * back to the current position.
     */

    GetCursorPos(&point);
    TkSetCursorPos(point.x, point.y);
    SetCursorPos(point.x, point.y);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpMakeTransparentWindowExist --
 *
922
923
924
925
926
927
928
929

930
931
932
933
934
935
936
949
950
951
952
953
954
955

956
957
958
959
960
961
962
963







-
+







    Window parent)		/* Parent window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    HWND hParent = (HWND) parent, hWnd;
    int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
    DWORD exStyle = WS_EX_TRANSPARENT | WS_EX_TOPMOST;

    hWnd = CreateWindowExW(exStyle, TK_WIN_CHILD_CLASS_NAME, NULL, style,
    hWnd = CreateWindowEx(exStyle, TK_WIN_CHILD_CLASS_NAME, NULL, style,
	    Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
	    hParent, NULL, Tk_GetHINSTANCE(), NULL);
    winPtr->window = Tk_AttachHWND(tkwin, hWnd);
}

/*
 *----------------------------------------------------------------------

Changes to win/tkWinWm.c.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16




17

18
19
20
21
22
23
24
25








-
-
+
+






-
-
-
-

-
+







/*
 * tkWinWm.c --
 *
 *	This module takes care of the interactions between a Tk-based
 *	application and the window manager. Among other things, it implements
 *	the "wm" command and passes geometry information to the window
 *	manager.
 *
 * Copyright © 1995-1997 Sun Microsystems, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkWinInt.h"
#include <windows.h>
#include <wtypes.h>
#include <shobjidl.h>
#include <shlguid.h>
#include <shellapi.h>
#include "tkWinIco.h"

/*
 * These next two defines are only valid on Win2K/XP+.
 */

#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED	0x00080000
#endif
57
58
59
60
61
62
63
64
65


66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83






84










85




































86

87
88
89
90
91
92
93
53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141







-
-
+
+







-
+










+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+








typedef struct ProtocolHandler {
    Atom protocol;		/* Identifies the protocol. */
    struct ProtocolHandler *nextPtr;
				/* Next in list of protocol handlers for the
				 * same top-level window, or NULL for end of
				 * list. */
    Tcl_Interp *interp;	/* Interpreter in which to invoke command. */
    char command[TKFLEXARRAY];	/* Tcl command to invoke when a client message
    Tcl_Interp *interp;		/* Interpreter in which to invoke command. */
    char command[1];		/* Tcl command to invoke when a client message
				 * for this protocol arrives. The actual size
				 * of the structure varies to accommodate the
				 * needs of the actual command. THIS MUST BE
				 * THE LAST FIELD OF THE STRUCTURE. */
} ProtocolHandler;

#define HANDLER_SIZE(cmdLength) \
    (offsetof(ProtocolHandler, command) + 1 + cmdLength)
    ((unsigned) ((Tk_Offset(ProtocolHandler, command) + 1) + cmdLength))

/*
 * Helper type passed via lParam to TkWmStackorderToplevelEnumProc
 */

typedef struct TkWmStackorderToplevelPair {
    Tcl_HashTable *table;
    TkWindow **windowPtr;
} TkWmStackorderToplevelPair;

/*
 * This structure represents the contents of a icon, in terms of its image.
 * The HICON is an internal Windows format. Most of these icon-specific
 * structures originated with the Winico extension. We stripped out unused
 * parts of that code, and integrated the code more naturally with Tcl.
 */

typedef struct {
    UINT Width, Height, Colors;	/* Width, Height and bpp */
    LPBYTE lpBits;		/* Ptr to DIB bits */
    DWORD dwNumBytes;		/* How many bytes? */
    LPBITMAPINFO lpbi;		/* Ptr to header */
    LPBYTE lpXOR;		/* Ptr to XOR image bits */
    LPBYTE lpAND;		/* Ptr to AND image bits */
    HICON hIcon;		/* DAS ICON */
} ICONIMAGE, *LPICONIMAGE;

/*
 * This structure is how we represent a block of the above items. We will
 * reallocate these structures according to how many images they need to
 * contain.
 */

typedef struct {
    int nNumImages;		/* How many images? */
    ICONIMAGE IconImages[1];	/* Image entries */
} BlockOfIconImages, *BlockOfIconImagesPtr;

/*
 * These two structures are used to read in icons from an 'icon directory'
 * (i.e. the contents of a .icr file, say). We only use these structures
 * temporarily, since we copy the information we want into a
 * BlockOfIconImages.
 */

typedef struct {
    BYTE bWidth;		/* Width of the image */
    BYTE bHeight;		/* Height of the image (times 2) */
    BYTE bColorCount;		/* Number of colors in image (0 if >=8bpp) */
    BYTE bReserved;		/* Reserved */
    WORD wPlanes;		/* Color Planes */
    WORD wBitCount;		/* Bits per pixel */
    DWORD dwBytesInRes;		/* How many bytes in this resource? */
    DWORD dwImageOffset;	/* Where in the file is this image */
} ICONDIRENTRY, *LPICONDIRENTRY;

typedef struct {
    WORD idReserved;		/* Reserved */
    WORD idType;		/* Resource type (1 for icons) */
    WORD idCount;		/* How many images? */
    ICONDIRENTRY idEntries[1];	/* The entries for each image */
} ICONDIR, *LPICONDIR;

/*
 * A pointer to one of these structures is associated with each toplevel.
 * A pointer to one of these strucutures is associated with each toplevel.
 * This allows us to free up all memory associated with icon resources when a
 * window is deleted or if the window's icon is changed. They are simply
 * reference counted according to:
 *
 * (1) How many WmInfo structures point to this object
 * (2) Whether the ThreadSpecificData defined in this file contains a pointer
 *     to this object.
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187







-
+







    char *iconName;		/* Name to display in icon. Malloced. */
    XWMHints hints;		/* Various pieces of information for window
				 * manager. */
    char *leaderName;		/* Path name of leader of window group
				 * (corresponds to hints.window_group).
				 * Malloc-ed. Note: this field doesn't get
				 * updated if leader is destroyed. */
    TkWindow *containerPtr;	/* Container window for TRANSIENT_FOR property,
    TkWindow *masterPtr;	/* Master window for TRANSIENT_FOR property,
				 * or NULL. */
    Tk_Window icon;		/* Window to use as icon for this window, or
				 * NULL. */
    Tk_Window iconFor;		/* Window for which this window is icon, or
				 * NULL if this isn't an icon for anyone. */

    /*
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277







-
+







-
+







				 * transparent) .. 1.0 (opaque) */

    /*
     * List of children of the toplevel which have private colormaps.
     */

    TkWindow **cmapList;	/* Array of window with private colormaps. */
    Tcl_Size cmapCount;		/* Number of windows in array. */
    int cmapCount;		/* Number of windows in array. */

    /*
     * Miscellaneous information.
     */

    ProtocolHandler *protPtr;	/* First in list of protocol handlers for this
				 * window (NULL means none). */
    Tcl_Size cmdArgc;		/* Number of elements in cmdArgv below. */
    int cmdArgc;		/* Number of elements in cmdArgv below. */
    const char **cmdArgv;	/* Array of strings to store in the WM_COMMAND
				 * property. NULL means nothing available. */
    char *clientMachine;	/* String to store in WM_CLIENT_MACHINE
				 * property, or NULL. */
    int flags;			/* Miscellaneous flags, defined below. */
    int numTransients;		/* Number of transients on this window */
    WinIconPtr iconPtr;		/* Pointer to titlebar icon structure for this
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325







-
+







 *				allow the user to change the width of the
 *				window (controlled by "wm resizable" command).
 * WM_HEIGHT_NOT_RESIZABLE -	Non-zero means that we're not supposed to
 *				allow the user to change the height of the
 *				window (controlled by "wm resizable" command).
 * WM_WITHDRAWN -		Non-zero means that this window has explicitly
 *				been withdrawn. If it's a transient, it should
 *				not mirror state changes in the container.
 *				not mirror state changes in the master.
 * WM_FULLSCREEN -		Non-zero means that this window has been placed
 *				in the full screen mode. It should be mapped at
 *				0,0 and be the width and height of the screen.
 */

#define WM_NEVER_MAPPED			(1<<0)
#define WM_UPDATE_PENDING		(1<<1)
306
307
308
309
310
311
312
313

314
315
316
317
318
319

320
321
322

323
324
325
326
327
328
329
354
355
356
357
358
359
360

361
362
363
364
365
366

367
368
369

370
371
372
373
374
375
376
377







-
+





-
+


-
+







#define EX_TRANSIENT_STYLE (WS_EX_DLGMODALFRAME)

/*
 * The following structure is the official type record for geometry management
 * of top-level windows.
 */

static void		TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void		TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
static void		RemapWindows(TkWindow *winPtr, HWND parentHWND);

static const Tk_GeomMgr wmMgrType = {
    "wm",			/* name */
    TopLevelReqProc,		/* requestProc */
    NULL,			/* lostContentProc */
    NULL,			/* lostSlaveProc */
};

typedef struct {
typedef struct ThreadSpecificData {
    HPALETTE systemPalette;	/* System palette; refers to the currently
				 * installed foreground logical palette. */
    TkWindow *createWindow;	/* Window that is being constructed. This
				 * value is set immediately before a call to
				 * CreateWindowEx, and is used by SetLimits.
				 * This is a gross hack needed to work around
				 * Windows brain damage where it sends the
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
393
394
395
396
397
398
399










400
401
402
403
404
405
406







-
-
-
-
-
-
-
-
-
-







 */

static int initialized;		/* Flag indicating whether module has been
				 * initialized. */

TCL_DECLARE_MUTEX(winWmMutex)

/*
 * The following records the "TaskbarButtonCreated" message ID
 * for overlay icons.
 */

static UINT TaskbarButtonCreatedMessageId = WM_NULL;

/* Reference to taskbarlist API for overlay icons. */
ITaskbarList3 *ptbl;

/*
 * Forward declarations for functions defined in this file:
 */

static int		ActivateWindow(Tcl_Event *evPtr, int flags);
static void		ConfigureTopLevel(WINDOWPOS *pos);
static void		GenerateConfigureNotify(TkWindow *winPtr);
381
382
383
384
385
386
387
388

389
390
391


392
393
394
395

396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413

414
415
416

417
418
419

420
421
422

423
424
425

426
427
428

429
430
431

432
433
434

435
436
437

438
439
440

441
442
443

444
445
446

447
448
449
450
451
452

453
454
455

456
457
458

459
460
461

462
463
464

465
466
467

468
469
470

471
472
473

474
475
476

477
478
479

480
481
482

483
484
485

486
487
488

489
490
491

492
493
494

495
496
497

498
499
500

501
502
503

504
505
506

507
508
509

510
511





















































































































































































512
513
514
515
516
517
518
419
420
421
422
423
424
425

426
427


428
429
430
431
432

433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448
449
450

451
452
453

454
455
456

457
458
459

460
461
462

463
464
465

466
467
468

469
470
471

472
473
474

475
476
477

478
479
480

481
482
483

484
485



486

487
488
489

490
491
492

493
494
495

496
497
498

499
500
501

502
503
504

505
506
507

508
509
510

511
512
513

514
515
516

517
518
519

520
521
522

523
524
525

526
527
528

529
530
531

532
533
534

535
536
537

538
539
540

541
542
543

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734







-
+

-
-
+
+



-
+





-


+









-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+

-
-
-

-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			    TkWindow *winPtr);
static void		RefreshColormap(Colormap colormap, TkDisplay *dispPtr);
static void		SetLimits(HWND hwnd, MINMAXINFO *info);
static void		TkWmStackorderToplevelWrapperMap(TkWindow *winPtr,
			    Display *display, Tcl_HashTable *table);
static LRESULT CALLBACK	TopLevelProc(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam);
static void		TopLevelEventProc(void *clientData,
static void		TopLevelEventProc(ClientData clientData,
			    XEvent *eventPtr);
static void		TopLevelReqProc(void *dummy, Tk_Window tkwin);
static void		UpdateGeometryInfo(void *clientData);
static void		TopLevelReqProc(ClientData dummy, Tk_Window tkwin);
static void		UpdateGeometryInfo(ClientData clientData);
static void		UpdateWrapper(TkWindow *winPtr);
static LRESULT CALLBACK	WmProc(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam);
static void		WmWaitVisibilityOrMapProc(void *clientData,
static void		WmWaitVisibilityOrMapProc(ClientData clientData,
			    XEvent *eventPtr);
static BlockOfIconImagesPtr ReadIconOrCursorFromFile(Tcl_Interp *interp,
			    Tcl_Obj* fileName, BOOL isIcon);
static WinIconPtr	ReadIconFromFile(Tcl_Interp *interp,
			    Tcl_Obj *fileName);
static BOOL		AdjustIconImagePointers(LPICONIMAGE lpImage);
static WinIconPtr	GetIconFromPixmap(Display *dsPtr, Pixmap pixmap);
static int		ReadICOHeader(Tcl_Channel channel);
static BOOL		AdjustIconImagePointers(LPICONIMAGE lpImage);
static HICON		MakeIconOrCursorFromResource(LPICONIMAGE lpIcon,
			    BOOL isIcon);
static HICON		GetIcon(WinIconPtr titlebaricon, int icon_size);
static int		WinSetIcon(Tcl_Interp *interp,
			    WinIconPtr titlebaricon, Tk_Window tkw);
static void		FreeIconBlock(BlockOfIconImagesPtr lpIR);
static void		DecrIconRefCount(WinIconPtr titlebaricon);

static int		WmAspectCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmAttributesCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmClientCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmColormapwindowsCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmCommandCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmDeiconifyCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFocusmodelCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmForgetCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmFrameCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGeometryCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGridCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmGroupCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbadgeCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    Tcl_Obj *const objv[]);
static int		WmIconbitmapCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconifyCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconmaskCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconnameCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconphotoCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconpositionCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmIconwindowCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmManageCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMaxsizeCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmMinsizeCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmOverrideredirectCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmPositionfromCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmProtocolCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmResizableCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmSizefromCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStackorderCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmStateCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTitleCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmTransientCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		WmWithdrawCmd(Tk_Window tkwin,
			    TkWindow *winPtr, Tcl_Interp *interp, Tcl_Size objc,
			    TkWindow *winPtr, Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static void		WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);

/*
 * Used in BytesPerLine
 */

#define WIDTHBYTES(bits)	((((bits) + 31)>>5)<<2)

/*
 *----------------------------------------------------------------------
 *
 * DIBNumColors --
 *
 *	Calculates the number of entries in the color table, given by LPSTR
 *	lpbi - pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	WORD - Number of entries in the color table.
 *
 *----------------------------------------------------------------------
 */

static WORD
DIBNumColors(
    LPSTR lpbi)
{
    WORD wBitCount;
    DWORD dwClrUsed;

    dwClrUsed = ((LPBITMAPINFOHEADER) lpbi)->biClrUsed;

    if (dwClrUsed) {
	return (WORD) dwClrUsed;
    }

    wBitCount = ((LPBITMAPINFOHEADER) lpbi)->biBitCount;

    switch (wBitCount) {
    case 1:
	return 2;
    case 4:
	return 16;
    case 8:
	return 256;
    default:
	return 0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PaletteSize --
 *
 *	Calculates the number of bytes in the color table, as given by LPSTR
 *	lpbi - pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	Number of bytes in the color table
 *
 *----------------------------------------------------------------------
 */
static WORD
PaletteSize(
    LPSTR lpbi)
{
    return (WORD) (DIBNumColors(lpbi) * sizeof(RGBQUAD));
}

/*
 *----------------------------------------------------------------------
 *
 * FindDIBits --
 *
 *	Locate the image bits in a CF_DIB format DIB, as given by LPSTR lpbi -
 *	pointer to the CF_DIB memory block. Used by titlebar icon code.
 *
 * Results:
 *	pointer to the image bits
 *
 * Side effects: None
 *
 *
 *----------------------------------------------------------------------
 */

static LPSTR
FindDIBBits(
    LPSTR lpbi)
{
    return lpbi + *((LPDWORD) lpbi) + PaletteSize(lpbi);
}

/*
 *----------------------------------------------------------------------
 *
 * BytesPerLine --
 *
 *	Calculates the number of bytes in one scan line, as given by
 *	LPBITMAPINFOHEADER lpBMIH - pointer to the BITMAPINFOHEADER that
 *	begins the CF_DIB block. Used by titlebar icon code.
 *
 * Results:
 *	number of bytes in one scan line (DWORD aligned)
 *
 *----------------------------------------------------------------------
 */

static DWORD
BytesPerLine(
    LPBITMAPINFOHEADER lpBMIH)
{
    return WIDTHBYTES(lpBMIH->biWidth * lpBMIH->biPlanes * lpBMIH->biBitCount);
}

/*
 *----------------------------------------------------------------------
 *
 * AdjustIconImagePointers --
 *
 *	Adjusts internal pointers in icon resource struct, as given by
 *	LPICONIMAGE lpImage - the resource to handle. Used by titlebar icon
 *	code.
 *
 * Results:
 *	BOOL - TRUE for success, FALSE for failure
 *
 *----------------------------------------------------------------------
 */

static BOOL
AdjustIconImagePointers(
    LPICONIMAGE lpImage)
{
    /*
     * Sanity check.
     */

    if (lpImage == NULL) {
	return FALSE;
    }

    /*
     * BITMAPINFO is at beginning of bits.
     */

    lpImage->lpbi = (LPBITMAPINFO) lpImage->lpBits;

    /*
     * Width - simple enough.
     */

    lpImage->Width = lpImage->lpbi->bmiHeader.biWidth;

    /*
     * Icons are stored in funky format where height is doubled so account for
     * that.
     */

    lpImage->Height = (lpImage->lpbi->bmiHeader.biHeight)/2;

    /*
     * How many colors?
     */

    lpImage->Colors = lpImage->lpbi->bmiHeader.biPlanes
	    * lpImage->lpbi->bmiHeader.biBitCount;

    /*
     * XOR bits follow the header and color table.
     */

    lpImage->lpXOR = (LPBYTE) FindDIBBits((LPSTR) lpImage->lpbi);

    /*
     * AND bits follow the XOR bits.
     */

    lpImage->lpAND = lpImage->lpXOR +
	    lpImage->Height*BytesPerLine((LPBITMAPINFOHEADER) lpImage->lpbi);
    return TRUE;
}

/*
 *----------------------------------------------------------------------
 *
 * MakeIconOrCursorFromResource --
 *
 *	Construct an actual HICON structure from the information in a
636
637
638
639
640
641
642
643

644
645
646
647
648
649
650
651
652
653
654

655
656
657





658

659
660
661
662
663




664
665

666
667
668


669
670
671
672
673
674
675
676
677
678
679

680
681

682
683
684
685
686
687
688
852
853
854
855
856
857
858

859
860
861
862
863
864
865
866
867
868
869

870
871
872
873
874
875
876
877
878

879
880




881
882
883
884
885

886
887


888
889
890
891
892
893
894
895
896
897
898
899

900
901

902
903
904
905
906
907
908
909







-
+










-
+



+
+
+
+
+
-
+

-
-
-
-
+
+
+
+

-
+

-
-
+
+










-
+

-
+







 *----------------------------------------------------------------------
 */

static int
InitWindowClass(
    WinIconPtr titlebaricon)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;
	tsdPtr->firstWindow = 1;
	tsdPtr->iconPtr = NULL;
    }
    if (!initialized) {
	Tcl_MutexLock(&winWmMutex);
	if (!initialized) {
	    WNDCLASSW windowClass;
	    WNDCLASS class;

	    initialized = 1;

	    /*
	     * The only difference between WNDCLASSW and WNDCLASSA are in
	     * pointers, so we can use the generic structure WNDCLASS.
	     */

	    memset(&windowClass, 0, sizeof(WNDCLASSW));
	    ZeroMemory(&class, sizeof(WNDCLASS));

	    windowClass.style = CS_HREDRAW | CS_VREDRAW;
	    windowClass.hInstance = Tk_GetHINSTANCE();
	    windowClass.lpszClassName = TK_WIN_TOPLEVEL_CLASS_NAME;
	    windowClass.lpfnWndProc = WmProc;
	    class.style = CS_HREDRAW | CS_VREDRAW;
	    class.hInstance = Tk_GetHINSTANCE();
	    class.lpszClassName = TK_WIN_TOPLEVEL_CLASS_NAME;
	    class.lpfnWndProc = WmProc;
	    if (titlebaricon == NULL) {
		windowClass.hIcon = LoadIconW(Tk_GetHINSTANCE(), L"tk");
		class.hIcon = LoadIcon(Tk_GetHINSTANCE(), TEXT("tk"));
	    } else {
		windowClass.hIcon = GetIcon(titlebaricon, ICON_BIG);
		if (windowClass.hIcon == NULL) {
		class.hIcon = GetIcon(titlebaricon, ICON_BIG);
		if (class.hIcon == NULL) {
		    return TCL_ERROR;
		}

		/*
		 * Store pointer to default icon so we know when we need to
		 * free that information
		 */

		tsdPtr->iconPtr = titlebaricon;
	    }
	    windowClass.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
	    class.hCursor = LoadCursor(NULL, IDC_ARROW);

	    if (!RegisterClassW(&windowClass)) {
	    if (!RegisterClass(&class)) {
		Tcl_Panic("Unable to register TkTopLevel class");
	    }
	}
	Tcl_MutexUnlock(&winWmMutex);
    }
    return TCL_OK;
}
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799
800

801
802
803
804
805
806

807
808

809
810
811
812
813
814
815
1005
1006
1007
1008
1009
1010
1011

1012
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026

1027
1028

1029
1030
1031
1032
1033
1034
1035
1036







-
+








-
+





-
+

-
+







	 * icon. Otherwise our icon choice will be ignored moments later when
	 * Tk finishes initialising.
	 */

	if (!initialized) {
	    if (InitWindowClass(titlebaricon) != TCL_OK) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"Unable to set icon", TCL_INDEX_NONE));
			"Unable to set icon", -1));
		Tcl_SetErrorCode(interp, "TK", "WM", "ICON", "FAILED", NULL);
		return TCL_ERROR;
	    }
	} else {
	    ThreadSpecificData *tsdPtr;

	    /*
	     * Don't check return result of SetClassLong() or
	     * SetClassLongPtrW() since they return the previously set value
	     * SetClassLongPtr() since they return the previously set value
	     * which is zero on the initial call or in an error case. The MSDN
	     * documentation does not indicate that the result needs to be
	     * checked.
	     */

	    SetClassLongPtrW(hwnd, GCLP_HICONSM,
	    SetClassLongPtr(hwnd, GCLP_HICONSM,
		    (LPARAM) GetIcon(titlebaricon, ICON_SMALL));
	    SetClassLongPtrW(hwnd, GCLP_HICON,
	    SetClassLongPtr(hwnd, GCLP_HICON,
		    (LPARAM) GetIcon(titlebaricon, ICON_BIG));
	    tsdPtr = (ThreadSpecificData *)
		    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
	    if (tsdPtr->iconPtr != NULL) {
		DecrIconRefCount(tsdPtr->iconPtr);
	    }
	    tsdPtr->iconPtr = titlebaricon;
841
842
843
844
845
846
847
848

849
850
851
852
853

854
855

856
857
858
859
860
861
862
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073

1074
1075

1076
1077
1078
1079
1080
1081
1082
1083







-
+




-
+

-
+







	     */

	    UpdateWrapper(wmPtr->winPtr);
	    wmPtr = ((TkWindow *) tkw)->wmInfoPtr;
	    hwnd = wmPtr->wrapper;
	    if (hwnd == NULL) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"Can't set icon; window has no wrapper.", TCL_INDEX_NONE));
			"Can't set icon; window has no wrapper.", -1));
		Tcl_SetErrorCode(interp, "TK", "WM", "ICON", "WRAPPER", NULL);
		return TCL_ERROR;
	    }
	}
	SendMessageW(hwnd, WM_SETICON, ICON_SMALL,
	SendMessage(hwnd, WM_SETICON, ICON_SMALL,
		(LPARAM) GetIcon(titlebaricon, ICON_SMALL));
	SendMessageW(hwnd, WM_SETICON, ICON_BIG,
	SendMessage(hwnd, WM_SETICON, ICON_BIG,
		(LPARAM) GetIcon(titlebaricon, ICON_BIG));

	/*
	 * Update the iconPtr we keep for each WmInfo structure.
	 */

	if (wmPtr->iconPtr != NULL) {
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132







-
+







HICON
TkWinGetIcon(
    Tk_Window tkwin,
    DWORD iconsize)
{
    WmInfo *wmPtr;
    HICON icon;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->iconPtr != NULL) {
	/*
	 * return default toplevel icon
	 */

937
938
939
940
941
942
943
944

945
946
947

948
949
950
951
952
953
954
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167

1168
1169
1170
1171
1172
1173
1174
1175







-
+


-
+







    }

    /*
     * Find the icon otherwise associated with the toplevel, or finally with
     * the window class.
     */

    icon = (HICON) SendMessageW(wmPtr->wrapper, WM_GETICON, iconsize,
    icon = (HICON) SendMessage(wmPtr->wrapper, WM_GETICON, iconsize,
	    (LPARAM) NULL);
    if (icon == (HICON) NULL) {
	icon = (HICON) GetClassLongPtrW(wmPtr->wrapper,
	icon = (HICON) GetClassLongPtr(wmPtr->wrapper,
		(iconsize == ICON_BIG) ? GCLP_HICON : GCLP_HICONSM);
    }
    return icon;
}

/*
 *----------------------------------------------------------------------
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027

1028
1029


1030
1031
1032
1033
1034

1035
1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247
1248
1249


1250
1251
1252

1253
1254

1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267

1268
1269
1270
1271
1272
1273
1274
1275
1276

1277
1278
1279
1280
1281
1282
1283
1284







-
+








+
-
-
+
+

-


-
+



-
+








-
+








-
+







    /*
     * Then see if we can ask the shell for the icon for this file. We
     * want both the regular and small icons so that the Alt-Tab (task-
     * switching) display uses the right icon.
     */

    if (lpIR == NULL) {
	SHFILEINFOW sfiSM;
	SHFILEINFO sfiSM;
	Tcl_DString ds, ds2;
	DWORD *res;
	const char *file;

	file = Tcl_TranslateFileName(interp, Tcl_GetString(fileName), &ds);
	if (file == NULL) {
	    return NULL;
	}
	Tcl_WinUtfToTChar(file, -1, &ds2);
	Tcl_DStringInit(&ds2);
	res = (DWORD *)SHGetFileInfoW(Tcl_UtfToWCharDString(file, TCL_INDEX_NONE, &ds2), 0, &sfiSM,
	Tcl_DStringFree(&ds);
	res = (DWORD *)SHGetFileInfo((TCHAR *)Tcl_DStringValue(&ds2), 0, &sfiSM,
		sizeof(SHFILEINFO), SHGFI_SMALLICON|SHGFI_ICON);
	Tcl_DStringFree(&ds);

	if (res != 0) {
	    SHFILEINFOW sfi;
	    SHFILEINFO sfi;
	    unsigned size;

	    Tcl_ResetResult(interp);
	    res = (DWORD *)SHGetFileInfoW((WCHAR *)Tcl_DStringValue(&ds2), 0, &sfi,
	    res = (DWORD *)SHGetFileInfo((TCHAR *)Tcl_DStringValue(&ds2), 0, &sfi,
		    sizeof(SHFILEINFO), SHGFI_ICON);

	    /*
	     * Account for extra icon, if necessary.
	     */

	    size = sizeof(BlockOfIconImages)
		    + ((res != 0) ? sizeof(ICONIMAGE) : 0);
	    lpIR = (BlockOfIconImagesPtr)ckalloc(size);
	    lpIR = ckalloc(size);
	    if (lpIR == NULL) {
		if (res != 0) {
		    DestroyIcon(sfi.hIcon);
		}
		DestroyIcon(sfiSM.hIcon);
		Tcl_DStringFree(&ds2);
		return NULL;
	    }
	    memset(lpIR, 0, size);
	    ZeroMemory(lpIR, size);

	    lpIR->nNumImages		= ((res != 0) ? 2 : 1);
	    lpIR->IconImages[0].Width	= 16;
	    lpIR->IconImages[0].Height	= 16;
	    lpIR->IconImages[0].Colors	= 4;
	    lpIR->IconImages[0].hIcon	= sfiSM.hIcon;

1071
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305





































































1306
1307
1308
1309
1310
1311
1312







-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		lpIR->IconImages[1].Colors	= 4;
		lpIR->IconImages[1].hIcon	= sfi.hIcon;
	    }
	}
	Tcl_DStringFree(&ds2);
    }
    if (lpIR != NULL) {
	titlebaricon = (WinIconPtr)ckalloc(sizeof(WinIconInstance));
	titlebaricon = ckalloc(sizeof(WinIconInstance));
	titlebaricon->iconBlock = lpIR;
	titlebaricon->refCount = 1;
    }
    return titlebaricon;
}


/*
 *----------------------------------------------------------------------
 *
 * AdjustIconImagePointers --
 *
 *	Adjusts internal pointers in icon resource struct, as given by
 *	LPICONIMAGE lpImage - the resource to handle. Used by titlebar icon
 *	code.
 *
 * Results:
 *	BOOL - TRUE for success, FALSE for failure
 *
 *----------------------------------------------------------------------
 */

static BOOL
AdjustIconImagePointers(
    LPICONIMAGE lpImage)
{
    /*
     * Sanity check.
     */

    if (lpImage == NULL) {
	return FALSE;
    }

    /*
     * BITMAPINFO is at beginning of bits.
     */

    lpImage->lpbi = (LPBITMAPINFO) lpImage->lpBits;

    /*
     * Width - simple enough.
     */

    lpImage->Width = lpImage->lpbi->bmiHeader.biWidth;

    /*
     * Icons are stored in funky format where height is doubled so account for
     * that.
     */

    lpImage->Height = (lpImage->lpbi->bmiHeader.biHeight)/2;

    /*
     * How many colors?
     */

    lpImage->Colors = lpImage->lpbi->bmiHeader.biPlanes
	    * lpImage->lpbi->bmiHeader.biBitCount;

    /*
     * XOR bits follow the header and color table.
     */

    lpImage->lpXOR = (LPBYTE) FindDIBBits((LPSTR) lpImage->lpbi);

    /*
     * AND bits follow the XOR bits.
     */

    lpImage->lpAND = lpImage->lpXOR +
	    lpImage->Height*BytesPerLine((LPBITMAPINFOHEADER) lpImage->lpbi);
    return TRUE;
}

/*
 *----------------------------------------------------------------------
 *
 * GetIconFromPixmap --
 *
 *	Turn a Tk Pixmap (i.e. a bitmap) into an icon resource, if possible,
 *	otherwise NULL is returned.
1216
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395

1396
1397
1398
1399
1400
1401
1402
1403







-
+




















-
+







    icon.hbmColor = twdPtr->bitmap.handle;

    hIcon = CreateIconIndirect(&icon);
    if (hIcon == NULL) {
	return NULL;
    }

    lpIR = (BlockOfIconImagesPtr)ckalloc(sizeof(BlockOfIconImages));
    lpIR = ckalloc(sizeof(BlockOfIconImages));
    if (lpIR == NULL) {
	DestroyIcon(hIcon);
	return NULL;
    }

    lpIR->nNumImages = 1;
    lpIR->IconImages[0].Width = width;
    lpIR->IconImages[0].Height = height;
    lpIR->IconImages[0].Colors = 1 << twdPtr->bitmap.depth;
    lpIR->IconImages[0].hIcon = hIcon;

    /*
     * These fields are ignored.
     */

    lpIR->IconImages[0].lpBits = 0;
    lpIR->IconImages[0].dwNumBytes = 0;
    lpIR->IconImages[0].lpXOR = 0;
    lpIR->IconImages[0].lpAND = 0;

    titlebaricon = (WinIconPtr)ckalloc(sizeof(WinIconInstance));
    titlebaricon = ckalloc(sizeof(WinIconInstance));
    titlebaricon->iconBlock = lpIR;
    titlebaricon->refCount = 1;
    return titlebaricon;
}

/*
 *----------------------------------------------------------------------
1442
1443
1444
1445
1446
1447
1448
1449

1450
1451
1452
1453
1454
1455
1456
1457

1458
1459
1460
1461
1462
1463
1464
1465
1466
1467

1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1594
1595
1596
1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
1608

1609
1610
1611
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632
1633







-
+







-
+









-
+






-
+







	return NULL;
    }

    /*
     * Allocate memory for the resource structure
     */

    lpIR = (BlockOfIconImagesPtr)ckalloc(sizeof(BlockOfIconImages));
    lpIR = ckalloc(sizeof(BlockOfIconImages));

    /*
     * Read in the header
     */

    lpIR->nNumImages = ReadICOHeader(channel);
    if (lpIR->nNumImages == -1) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid file header", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid file header", -1));
	Tcl_Close(NULL, channel);
	ckfree(lpIR);
	return NULL;
    }

    /*
     * Adjust the size of the struct to account for the images.
     */

    lpIR = (BlockOfIconImagesPtr)ckrealloc(lpIR, sizeof(BlockOfIconImages)
    lpIR = ckrealloc(lpIR, sizeof(BlockOfIconImages)
	    + (lpIR->nNumImages - 1) * sizeof(ICONIMAGE));

    /*
     * Allocate enough memory for the icon directory entries.
     */

    lpIDE = (LPICONDIRENTRY)ckalloc(lpIR->nNumImages * sizeof(ICONDIRENTRY));
    lpIDE = ckalloc(lpIR->nNumImages * sizeof(ICONDIRENTRY));

    /*
     * Read in the icon directory entries.
     */

    dwBytesRead = Tcl_Read(channel, (char *) lpIDE,
	    (int) (lpIR->nNumImages * sizeof(ICONDIRENTRY)));
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546
1547
1654
1655
1656
1657
1658
1659
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







-
+

















-
+












-
+







     */

    for (i=0 ; i<lpIR->nNumImages ; i++) {
	/*
	 * Allocate memory for the resource.
	 */

	lpIR->IconImages[i].lpBits = (LPBYTE)ckalloc(lpIDE[i].dwBytesInRes);
	lpIR->IconImages[i].lpBits = ckalloc(lpIDE[i].dwBytesInRes);
	lpIR->IconImages[i].dwNumBytes = lpIDE[i].dwBytesInRes;

	/*
	 * Seek to beginning of this image.
	 */

	if (Tcl_Seek(channel, lpIDE[i].dwImageOffset, FILE_BEGIN) == -1) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error seeking in file: %s", Tcl_PosixError(interp)));
	    goto readError;
	}

	/*
	 * Read it in.
	 */

	dwBytesRead = Tcl_Read(channel, (char *)lpIR->IconImages[i].lpBits,
		lpIDE[i].dwBytesInRes);
		(int) lpIDE[i].dwBytesInRes);
	if (dwBytesRead != lpIDE[i].dwBytesInRes) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "error reading file: %s", Tcl_PosixError(interp)));
	    goto readError;
	}

	/*
	 * Set the internal pointers appropriately.
	 */

	if (!AdjustIconImagePointers(&lpIR->IconImages[i])) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Error converting to internal format", TCL_INDEX_NONE));
		    "Error converting to internal format", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICON", "FORMAT", NULL);
	    goto readError;
	}
	lpIR->IconImages[i].hIcon =
		MakeIconOrCursorFromResource(&lpIR->IconImages[i], isIcon);
    }

1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600

1601
1602
1603
1604
1605
1606
1607
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







-
+











-
+







 *----------------------------------------------------------------------
 */

static TkWindow *
GetTopLevel(
    HWND hwnd)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * If this function is called before the CreateWindowEx call has
     * completed, then the user data slot will not have been set yet, so we
     * use the global createWindow variable.
     */

    if (tsdPtr->createWindow) {
	return tsdPtr->createWindow;
    }
    return (TkWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
    return (TkWindow *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
}

/*
 *----------------------------------------------------------------------
 *
 * SetLimits --
 *
1618
1619
1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632
1770
1771
1772
1773
1774
1775
1776

1777
1778
1779
1780
1781
1782
1783
1784







-
+







 */

static void
SetLimits(
    HWND hwnd,
    MINMAXINFO *info)
{
    WmInfo *wmPtr;
    register WmInfo *wmPtr;
    int maxWidth, maxHeight;
    int minWidth, minHeight;
    int base;
    TkWindow *winPtr = GetTopLevel(hwnd);

    if (winPtr == NULL) {
	return;
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
1875
1876
1877
1878
1879
1880
1881

1882
1883
1884
1885
1886
1887
1888







1889
1890
1891
1892
1893
1894
1895
1896







-
+






-
-
-
-
-
-
-
+







#endif

    if (!initialized) {
	return;
    }
    initialized = 0;

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

    if (!tsdPtr->initialized) {
	return;
    }
    tsdPtr->initialized = 0;

    /*
     * COM library cleanup.
     */

    CoUninitialize();

    UnregisterClassW(TK_WIN_TOPLEVEL_CLASS_NAME, hInstance);
    UnregisterClass(TK_WIN_TOPLEVEL_CLASS_NAME, hInstance);
}

/*
 *--------------------------------------------------------------
 *
 * TkWmNewWindow --
 *
1760
1761
1762
1763
1764
1765
1766
1767

1768
1769
1770
1771
1772
1773

1774
1775
1776
1777
1778
1779
1780
1906
1907
1908
1909
1910
1911
1912

1913
1914
1915
1916
1917
1918

1919
1920
1921
1922
1923
1924
1925
1926







-
+





-
+







 *--------------------------------------------------------------
 */

void
TkWmNewWindow(
    TkWindow *winPtr)		/* Newly-created top-level window. */
{
    WmInfo *wmPtr = (WmInfo *)ckalloc(sizeof(WmInfo));
    register WmInfo *wmPtr = ckalloc(sizeof(WmInfo));

    /*
     * Initialize full structure, then set what isn't NULL
     */

    memset(wmPtr, 0, sizeof(WmInfo));
    ZeroMemory(wmPtr, sizeof(WmInfo));
    winPtr->wmInfoPtr = wmPtr;
    wmPtr->winPtr = winPtr;
    wmPtr->hints.flags = InputHint | StateHint;
    wmPtr->hints.input = True;
    wmPtr->hints.initial_state = NormalState;
    wmPtr->hints.icon_pixmap = None;
    wmPtr->hints.icon_window = None;
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
1991
1992
1993
1994
1995
1996
1997

1998
1999
2000
2001
2002
2003
2004

2005
2006

2007
2008
2009
2010
2011
2012
2013
2014







-
+






-


-
+







 *----------------------------------------------------------------------
 */

static void
UpdateWrapper(
    TkWindow *winPtr)		/* Top-level window to redecorate. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    HWND parentHWND, oldWrapper = wmPtr->wrapper;
    HWND child, nextHWND, focusHWND;
    int x, y, width, height, state;
    WINDOWPLACEMENT place;
    HICON hSmallIcon = NULL;
    HICON hBigIcon = NULL;
    HRESULT hr;
    Tcl_DString titleString;
    int *childStateInfo = NULL;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->window == None) {
	/*
	 * Ensure existence of the window to update the wrapper for.
	 */

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
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







-
+
















-
+







-
+


-
+







	    Tcl_Panic("UpdateWrapper: Container was destroyed");
	}
    } else {
	/*
	 * Pick the decorative frame style. Override redirect windows get
	 * created as undecorated popups if they have no transient parent,
	 * otherwise they are children. This allows splash screens to operate
	 * as an independent window, while having dropdowns (like for a
	 * as an independent window, while having dropdows (like for a
	 * combobox) not grab focus away from their parent. Transient windows
	 * get a modal dialog frame. Neither override, nor transient windows
	 * appear in the Windows taskbar. Note that a transient window does
	 * not resize by default, so we need to explicitly add the
	 * WS_THICKFRAME style if we want it to be resizeable.
	 */

	if (winPtr->atts.override_redirect) {
	    wmPtr->style = WM_OVERRIDE_STYLE;
	    wmPtr->exStyle = EX_OVERRIDE_STYLE;

	    /*
	     * Parent must be desktop even if we have a transient parent.
	     */

	    parentHWND = GetDesktopWindow();
	    if (wmPtr->containerPtr) {
	    if (wmPtr->masterPtr) {
		wmPtr->style |= WS_CHILD;
	    } else {
		wmPtr->style |= WS_POPUP;
	    }
	} else if (wmPtr->flags & WM_FULLSCREEN) {
	    wmPtr->style = WM_FULLSCREEN_STYLE;
	    wmPtr->exStyle = EX_FULLSCREEN_STYLE;
	} else if (wmPtr->containerPtr) {
	} else if (wmPtr->masterPtr) {
	    wmPtr->style = WM_TRANSIENT_STYLE;
	    wmPtr->exStyle = EX_TRANSIENT_STYLE;
	    parentHWND = Tk_GetHWND(Tk_WindowId(wmPtr->containerPtr));
	    parentHWND = Tk_GetHWND(Tk_WindowId(wmPtr->masterPtr));
	    if (! ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE)
		    && (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE))) {
		wmPtr->style |= WS_THICKFRAME;
	    }
	} else {
	    wmPtr->style = WM_TOPLEVEL_STYLE;
	    wmPtr->exStyle = EX_TOPLEVEL_STYLE;
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
2122
2123
2124
2125
2126
2127
2128



2129
2130
2131

2132
2133

2134
2135
2136
2137

2138
2139
2140
2141
2142
2143
2144
2145







-
-
-
+
+

-
+

-
+



-
+








	/*
	 * Create the containing window, and set the user data to point to the
	 * TkWindow.
	 */

	tsdPtr->createWindow = winPtr;
	Tcl_DStringInit(&titleString);
	Tcl_UtfToWCharDString(((wmPtr->title != NULL) ?
		wmPtr->title : winPtr->nameUid), TCL_INDEX_NONE, &titleString);
	Tcl_WinUtfToTChar(((wmPtr->title != NULL) ?
		wmPtr->title : winPtr->nameUid), -1, &titleString);

	wmPtr->wrapper = CreateWindowExW(wmPtr->exStyle,
	wmPtr->wrapper = CreateWindowEx(wmPtr->exStyle,
		TK_WIN_TOPLEVEL_CLASS_NAME,
		(LPCWSTR) Tcl_DStringValue(&titleString),
		(LPCTSTR) Tcl_DStringValue(&titleString),
		wmPtr->style, x, y, width, height,
		parentHWND, NULL, Tk_GetHINSTANCE(), NULL);
	Tcl_DStringFree(&titleString);
	SetWindowLongPtrW(wmPtr->wrapper, GWLP_USERDATA, (LONG_PTR) winPtr);
	SetWindowLongPtr(wmPtr->wrapper, GWLP_USERDATA, (LONG_PTR) winPtr);
	tsdPtr->createWindow = NULL;

	if (wmPtr->exStyleConfig & WS_EX_LAYERED) {
	    /*
	     * The user supplies a double from [0..1], but Windows wants an
	     * int (transparent) 0..255 (opaque), so do the translation. Add
	     * the 0.5 to round the value.
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
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







-
+



-
+





-
+

-
+




-
+




-
+




-
+



-
+


















-
-
+
+


-
+



















-
+



-
+











-
+



















-
+







-
+








    /*
     * Now we need to reparent the contained window and set its style
     * appropriately. Be sure to update the style first so that Windows
     * doesn't try to set the focus to the child window.
     */

    SetWindowLongPtrW(child, GWL_STYLE,
    SetWindowLongPtr(child, GWL_STYLE,
	    WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);

    if (winPtr->flags & TK_EMBEDDED) {
	SetWindowLongPtrW(child, GWLP_WNDPROC, (LONG_PTR) TopLevelProc);
	SetWindowLongPtr(child, GWLP_WNDPROC, (LONG_PTR) TopLevelProc);
    }

    SetParent(child, wmPtr->wrapper);
    if (oldWrapper) {
	hSmallIcon = (HICON)
		SendMessageW(oldWrapper, WM_GETICON, ICON_SMALL, (LPARAM)NULL);
		SendMessage(oldWrapper, WM_GETICON, ICON_SMALL, (LPARAM)NULL);
	hBigIcon = (HICON)
		SendMessageW(oldWrapper, WM_GETICON, ICON_BIG, (LPARAM) NULL);
		SendMessage(oldWrapper, WM_GETICON, ICON_BIG, (LPARAM) NULL);
    }

    if (oldWrapper && (oldWrapper != wmPtr->wrapper)
	    && (oldWrapper != GetDesktopWindow())) {
	SetWindowLongPtrW(oldWrapper, GWLP_USERDATA, (LONG_PTR) 0);
	SetWindowLongPtr(oldWrapper, GWLP_USERDATA, (LONG_PTR) 0);

	if (wmPtr->numTransients > 0) {
	    /*
	     * Unset the current wrapper as the parent for all transient
	     * children for whom this is the container
	     * children for whom this is the master
	     */

	    WmInfo *wmPtr2;

	    childStateInfo = (int *)ckalloc(wmPtr->numTransients * sizeof(int));
	    childStateInfo = ckalloc(wmPtr->numTransients * sizeof(int));
	    state = 0;
	    for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
		    wmPtr2 = wmPtr2->nextPtr) {
		if (wmPtr2->containerPtr == winPtr
		if (wmPtr2->masterPtr == winPtr
			&& !(wmPtr2->flags & WM_NEVER_MAPPED)) {
		    childStateInfo[state++] = wmPtr2->hints.initial_state;
		    SetParent(TkWinGetHWND(wmPtr2->winPtr->window), NULL);
		}
	    }
	}

	/*
	 * Remove the menubar before destroying the window so the menubar
	 * isn't destroyed.
	 */

	SetMenu(oldWrapper, NULL);
	DestroyWindow(oldWrapper);
    }

    wmPtr->flags &= ~WM_NEVER_MAPPED;
    if (winPtr->flags & TK_EMBEDDED &&
	    SendMessageW(wmPtr->wrapper, TK_ATTACHWINDOW, (WPARAM) child, 0)) {
	SendMessageW(wmPtr->wrapper, TK_GEOMETRYREQ,
	    SendMessage(wmPtr->wrapper, TK_ATTACHWINDOW, (WPARAM) child, 0)) {
	SendMessage(wmPtr->wrapper, TK_GEOMETRYREQ,
		Tk_ReqWidth((Tk_Window) winPtr),
		Tk_ReqHeight((Tk_Window) winPtr));
	SendMessageW(wmPtr->wrapper, TK_SETMENU, (WPARAM) wmPtr->hMenu,
	SendMessage(wmPtr->wrapper, TK_SETMENU, (WPARAM) wmPtr->hMenu,
		(LPARAM) Tk_GetMenuHWND((Tk_Window) winPtr));
    }

    /*
     * Force an initial transition from withdrawn to the real initial state.
     * Set the Z order based on previous wrapper before we set the state.
     */

    state = wmPtr->hints.initial_state;
    wmPtr->hints.initial_state = WithdrawnState;
    if (nextHWND) {
	SetWindowPos(wmPtr->wrapper, nextHWND, 0, 0, 0, 0,
		SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOSENDCHANGING
		|SWP_NOOWNERZORDER);
    }
    TkpWmSetState(winPtr, state);
    wmPtr->hints.initial_state = state;

    if (hSmallIcon != NULL) {
	SendMessageW(wmPtr->wrapper, WM_SETICON, ICON_SMALL,
	SendMessage(wmPtr->wrapper, WM_SETICON, ICON_SMALL,
		(LPARAM) hSmallIcon);
    }
    if (hBigIcon != NULL) {
	SendMessageW(wmPtr->wrapper, WM_SETICON, ICON_BIG, (LPARAM) hBigIcon);
	SendMessage(wmPtr->wrapper, WM_SETICON, ICON_BIG, (LPARAM) hBigIcon);
    }

    /*
     * If we are embedded then force a mapping of the window now, because we
     * do not necessarily own the wrapper and may not get another opportunity
     * to map ourselves. We should not be in either iconified or zoomed states
     * when we get here, so it is safe to just check for TK_EMBEDDED without
     * checking what state we are supposed to be in (default to NormalState).
     */

    if (winPtr->flags & TK_EMBEDDED) {
	if (state+1 != SendMessageW(wmPtr->wrapper, TK_STATE, state, 0)) {
	if (state+1 != SendMessage(wmPtr->wrapper, TK_STATE, state, 0)) {
	    TkpWmSetState(winPtr, NormalState);
	    wmPtr->hints.initial_state = NormalState;
	}
	XMapWindow(winPtr->display, winPtr->window);
    }

    /*
     * Set up menus on the wrapper if required.
     */

    if (wmPtr->hMenu != NULL) {
	wmPtr->flags |= WM_SYNC_PENDING;
	SetMenu(wmPtr->wrapper, wmPtr->hMenu);
	wmPtr->flags &= ~WM_SYNC_PENDING;
    }

    if (childStateInfo) {
	if (wmPtr->numTransients > 0) {
	    /*
	     * Reset all transient children for whom this is the container.
	     * Reset all transient children for whom this is the master.
	     */

	    WmInfo *wmPtr2;

	    state = 0;
	    for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
		    wmPtr2 = wmPtr2->nextPtr) {
		if (wmPtr2->containerPtr == winPtr
		if (wmPtr2->masterPtr == winPtr
			&& !(wmPtr2->flags & WM_NEVER_MAPPED)) {
		    UpdateWrapper(wmPtr2->winPtr);
		    TkpWmSetState(wmPtr2->winPtr, childStateInfo[state++]);
		}
	    }
	}

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
2324
2325
2326
2327
2328
2329
2330





























2331
2332
2333
2334
2335
2336
2337







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







     */

    if (tsdPtr->firstWindow) {
	tsdPtr->firstWindow = 0;
	SetActiveWindow(wmPtr->wrapper);
    } else if (focusHWND) {
	SetFocus(focusHWND);
    }

    /*
     * Initialize hooks for overlay icon.
     * Start with TaskbarButtonCreated message.
     */

    TaskbarButtonCreatedMessageId = RegisterWindowMessage(TEXT("TaskbarButtonCreated"));

    /*
     * In case the application is run elevated, allow the
     * TaskbarButtonCreated message through.
     */

    ChangeWindowMessageFilter(TaskbarButtonCreatedMessageId, MSGFLT_ADD);

    /*
     * Load COM library for icon overlay.
     */

    hr = CoInitialize(0);
    if (SUCCEEDED(hr)) {
	hr = CoCreateInstance(&CLSID_TaskbarList, NULL,
		CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void **) &ptbl);
	if (FAILED(hr)) {
	    printf("Unable to initialize ITaskbarList3 API");
	    ptbl->lpVtbl->Release(NULL);
	    ptbl = NULL;
	}
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkWmMapWindow --
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
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







-
-
+
+








-
+


-
+







 */

void
TkWmMapWindow(
    TkWindow *winPtr)		/* Top-level window that's about to be
				 * mapped. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	InitWm();
    }

    if (wmPtr->flags & WM_NEVER_MAPPED) {
	/*
	 * Don't map a transient if the container is not mapped.
	 * Don't map a transient if the master is not mapped.
	 */

	if (wmPtr->containerPtr != NULL && !Tk_IsMapped(wmPtr->containerPtr)) {
	if (wmPtr->masterPtr != NULL && !Tk_IsMapped(wmPtr->masterPtr)) {
	    wmPtr->hints.initial_state = WithdrawnState;
	    return;
	}
    } else {
	if (wmPtr->hints.initial_state == WithdrawnState) {
	    return;
	}
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
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







-
+













-
+














-
+




-
+

-
+


-
-
+
+







 *--------------------------------------------------------------
 */

void
TkWmDeadWindow(
    TkWindow *winPtr)		/* Top-level window that's being deleted. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    WmInfo *wmPtr2;

    if (wmPtr == NULL) {
	return;
    }

    /*
     * Clean up event related window info.
     */

    if (winPtr->dispPtr->firstWmPtr == wmPtr) {
	winPtr->dispPtr->firstWmPtr = wmPtr->nextPtr;
    } else {
	WmInfo *prevPtr;
	register WmInfo *prevPtr;

	for (prevPtr = winPtr->dispPtr->firstWmPtr; ;
		prevPtr = prevPtr->nextPtr) {
	    if (prevPtr == NULL) {
		Tcl_Panic("couldn't unlink window in TkWmDeadWindow");
	    }
	    if (prevPtr->nextPtr == wmPtr) {
		prevPtr->nextPtr = wmPtr->nextPtr;
		break;
	    }
	}
    }

    /*
     * Reset all transient windows whose container is the dead window.
     * Reset all transient windows whose master is the dead window.
     */

    for (wmPtr2 = winPtr->dispPtr->firstWmPtr; wmPtr2 != NULL;
	 wmPtr2 = wmPtr2->nextPtr) {
	if (wmPtr2->containerPtr == winPtr) {
	if (wmPtr2->masterPtr == winPtr) {
	    wmPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) wmPtr2->containerPtr,
	    Tk_DeleteEventHandler((Tk_Window) wmPtr2->masterPtr,
		    VisibilityChangeMask|StructureNotifyMask,
		    WmWaitVisibilityOrMapProc, wmPtr2->winPtr);
	    wmPtr2->containerPtr = NULL;
	    if ((wmPtr2->wrapper != NULL)
	    wmPtr2->masterPtr = NULL;
	    if ((wmPtr2->wrapper != None)
		    && !(wmPtr2->flags & (WM_NEVER_MAPPED))) {
		UpdateWrapper(wmPtr2->winPtr);
	    }
	}
    }
    if (wmPtr->numTransients != 0)
	Tcl_Panic("numTransients should be 0");
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
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







-
-
+
+


-
+





-
+


-
+


















-
+







    }
    if (wmPtr->clientMachine != NULL) {
	ckfree(wmPtr->clientMachine);
    }
    if (wmPtr->flags & WM_UPDATE_PENDING) {
	Tcl_CancelIdleCall(UpdateGeometryInfo, winPtr);
    }
    if (wmPtr->containerPtr != NULL) {
	wmPtr2 = wmPtr->containerPtr->wmInfoPtr;
    if (wmPtr->masterPtr != NULL) {
	wmPtr2 = wmPtr->masterPtr->wmInfoPtr;

	/*
	 * If we had a container, tell them that we aren't tied to them anymore.
	 * If we had a master, tell them that we aren't tied to them anymore.
	 */

	if (wmPtr2 != NULL) {
	    wmPtr2->numTransients--;
	}
	Tk_DeleteEventHandler((Tk_Window) wmPtr->containerPtr,
	Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
		VisibilityChangeMask|StructureNotifyMask,
		WmWaitVisibilityOrMapProc, winPtr);
	wmPtr->containerPtr = NULL;
	wmPtr->masterPtr = NULL;
    }
    if (wmPtr->crefObj != NULL) {
	Tcl_DecrRefCount(wmPtr->crefObj);
	wmPtr->crefObj = NULL;
    }

    /*
     * Destroy the decorative frame window.
     */

    if (!(winPtr->flags & TK_EMBEDDED)) {
	if (wmPtr->wrapper != NULL) {
	    DestroyWindow(wmPtr->wrapper);
	} else if (winPtr->window) {
	    DestroyWindow(Tk_GetHWND(winPtr->window));
	}
    } else {
	if (wmPtr->wrapper != NULL) {
	    SendMessageW(wmPtr->wrapper, TK_DETACHWINDOW, 0, 0);
	    SendMessage(wmPtr->wrapper, TK_DETACHWINDOW, 0, 0);
	}
    }
    if (wmPtr->iconPtr != NULL) {
	/*
	 * This may delete the icon resource data. I believe we should do this
	 * after destroying the decorative frame, because the decorative frame
	 * is using this icon.
2625
2626
2627
2628
2629
2630
2631
2632

2633
2634
2635
2636
2637
2638
2639
2740
2741
2742
2743
2744
2745
2746

2747
2748
2749
2750
2751
2752
2753
2754







-
+







 *	A window property may get updated.
 *
 *--------------------------------------------------------------
 */

void
TkWmSetClass(
    TCL_UNUSED(TkWindow *))	/* Newly-created top-level window. */
    TkWindow *winPtr)		/* Newly-created top-level window. */
{
    /* Do nothing */
    return;
}

/*
 *----------------------------------------------------------------------
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
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







+


-
+




-
+



-
+











-
+









-
+










-
+
+







 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
Tk_WmObjCmd(
    void *clientData,	/* Main window associated with interpreter. */
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = (Tk_Window)clientData;
    Tk_Window tkwin = clientData;
    static const char *const optionStrings[] = {
	"aspect", "attributes", "client", "colormapwindows",
	"command", "deiconify", "focusmodel", "forget", "frame",
	"geometry", "grid", "group", "iconbadge", "iconbitmap",
	"geometry", "grid", "group", "iconbitmap",
	"iconify", "iconmask", "iconname",
	"iconphoto", "iconposition",
	"iconwindow", "manage", "maxsize", "minsize", "overrideredirect",
	"positionfrom", "protocol", "resizable", "sizefrom",
	"stackorder", "state", "title", "transient",
	"withdraw", NULL
    };
    enum options {
	WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS,
	WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FORGET,
	WMOPT_FRAME,
	WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBADGE, WMOPT_ICONBITMAP,
	WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP,
	WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME,
	WMOPT_ICONPHOTO, WMOPT_ICONPOSITION,
	WMOPT_ICONWINDOW, WMOPT_MANAGE, WMOPT_MAXSIZE, WMOPT_MINSIZE,
	WMOPT_OVERRIDEREDIRECT,
	WMOPT_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM,
	WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT,
	WMOPT_WITHDRAW
    };
    int index;
    Tcl_Size length;
    size_t length;
    const char *argv1;
    TkWindow *winPtr, **winPtrPtr = &winPtr;
    TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;

    if (objc < 2) {
    wrongNumArgs:
	Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
	return TCL_ERROR;
    }

    argv1 = Tcl_GetStringFromObj(objv[1], &length);
    argv1 = Tcl_GetString(objv[1]);
    length = objv[1]->length;
    if ((argv1[0] == 't') && !strncmp(argv1, "tracing", length)
	    && (length >= 3)) {
	int wmTracing;

	if ((objc != 2) && (objc != 3)) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
	    return TCL_ERROR;
2717
2718
2719
2720
2721
2722
2723
2724
2725


2726
2727
2728
2729
2730
2731
2732
2834
2835
2836
2837
2838
2839
2840


2841
2842
2843
2844
2845
2846
2847
2848
2849







-
-
+
+







	    dispPtr->flags |= TK_DISPLAY_WM_TRACING;
	} else {
	    dispPtr->flags &= ~TK_DISPLAY_WM_TRACING;
	}
	return TCL_OK;
    }

    if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings,
	    "option", 0, &index) != TCL_OK) {
    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    if (objc < 3) {
	goto wrongNumArgs;
    }

2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2881
2882
2883
2884
2885
2886
2887


2888
2889
2890
2891
2892
2893
2894







-
-







	return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GEOMETRY:
	return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GRID:
	return WmGridCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_GROUP:
	return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBADGE:
	return WmIconbadgeCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONBITMAP:
	return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONIFY:
	return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONMASK:
	return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
    case WMOPT_ICONNAME:
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
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







-
+


-
+


-
+











-
-
-
-
+
+
+
+















-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmAspectCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int numer1, denom1, numer2, denom2;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?minNumer minDenom maxNumer maxDenom?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PAspect) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewWideIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewWideIntObj(wmPtr->maxAspect.y);
	    results[0] = Tcl_NewIntObj(wmPtr->minAspect.x);
	    results[1] = Tcl_NewIntObj(wmPtr->minAspect.y);
	    results[2] = Tcl_NewIntObj(wmPtr->maxAspect.x);
	    results[3] = Tcl_NewIntObj(wmPtr->maxAspect.y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~PAspect;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) {
	    return TCL_ERROR;
	}
	if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) || (denom2 <= 0)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "aspect number can't be <= 0", TCL_INDEX_NONE));
		    "aspect number can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "ASPECT", NULL);
	    return TCL_ERROR;
	}
	wmPtr->minAspect.x = numer1;
	wmPtr->minAspect.y = denom1;
	wmPtr->maxAspect.x = numer2;
	wmPtr->maxAspect.y = denom2;
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
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







-
+


-
+


-
-
+
+




















-
+


-
+



-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+




-
+
+
+
+
+







 */

static int
WmAttributesCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    LONG style, exStyle, styleBit, *stylePtr = NULL;
    const char *string;
    int boolValue;
    Tcl_Size i, length;
    int i, boolean;
    size_t length;
    int config_fullscreen = 0, updatewrapper = 0;
    int fullscreen_attr_changed = 0, fullscreen_attr = 0;

    if ((objc < 3) || ((objc > 5) && ((objc%2) == 0))) {
    configArgs:
	Tcl_WrongNumArgs(interp, 2, objv,
		"window"
		" ?-alpha ?double??"
		" ?-transparentcolor ?color??"
		" ?-disabled ?bool??"
		" ?-fullscreen ?bool??"
		" ?-toolwindow ?bool??"
		" ?-topmost ?bool??");
	return TCL_ERROR;
    }
    exStyle = wmPtr->exStyleConfig;
    style = wmPtr->styleConfig;
    if (objc == 3) {
	Tcl_Obj *objPtr = Tcl_NewObj();
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-alpha", TCL_INDEX_NONE));
		Tcl_NewStringObj("-alpha", -1));
	Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewDoubleObj(wmPtr->alpha));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-transparentcolor", TCL_INDEX_NONE));
		Tcl_NewStringObj("-transparentcolor", -1));
	Tcl_ListObjAppendElement(NULL, objPtr,
		wmPtr->crefObj ? wmPtr->crefObj : Tcl_NewObj());
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-disabled", TCL_INDEX_NONE));
		Tcl_NewStringObj("-disabled", -1));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewBooleanObj(style & WS_DISABLED));
		Tcl_NewBooleanObj((style & WS_DISABLED)));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-fullscreen", TCL_INDEX_NONE));
		Tcl_NewStringObj("-fullscreen", -1));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN));
		Tcl_NewBooleanObj((wmPtr->flags & WM_FULLSCREEN)));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-toolwindow", TCL_INDEX_NONE));
		Tcl_NewStringObj("-toolwindow", -1));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewBooleanObj(exStyle & WS_EX_TOOLWINDOW));
		Tcl_NewBooleanObj((exStyle & WS_EX_TOOLWINDOW)));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewStringObj("-topmost", TCL_INDEX_NONE));
		Tcl_NewStringObj("-topmost", -1));
	Tcl_ListObjAppendElement(NULL, objPtr,
		Tcl_NewBooleanObj(exStyle & WS_EX_TOPMOST));
		Tcl_NewBooleanObj((exStyle & WS_EX_TOPMOST)));
	Tcl_SetObjResult(interp, objPtr);
	return TCL_OK;
    }
    for (i = 3; i < objc; i += 2) {
	string = Tcl_GetStringFromObj(objv[i], &length);
	string = Tcl_GetString(objv[i]);
	length = objv[i]->length;
	if ((length < 2) || (string[0] != '-')) {
	    goto configArgs;
	}
	if (strncmp(string, "-disabled", length) == 0) {
	    stylePtr = &style;
	    styleBit = WS_DISABLED;
	} else if ((strncmp(string, "-alpha", length) == 0)
		|| ((length > 2) && (strncmp(string, "-transparentcolor",
			length) == 0))) {
	    stylePtr = &exStyle;
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3110
3111
3112
3113
3114
3115
3116






3117
3118
3119
3120
3121
3122
3123







-
-
-
-
-
-







	    if ((i < objc-1) && (winPtr->flags & TK_EMBEDDED)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't set topmost flag on %s: it is an embedded window",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "ATTR", "TOPMOST", NULL);
		return TCL_ERROR;
	    }
	} else if (i == 3) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "bad attribute \"%s\": must be -alpha, -disabled, -fullscreen, -toolwindow, -topmost, or -transparentcolor",
		    string));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ATTR", "UNRECOGNIZED", NULL);
	    return TCL_ERROR;
	} else {
	    goto configArgs;
	}
	if (styleBit == WS_EX_LAYERED) {
	    if (objc == 4) {
		if (string[1] == 'a') {		/* -alpha */
		    Tcl_SetObjResult(interp, Tcl_NewDoubleObj(wmPtr->alpha));
3029
3030
3031
3032
3033
3034
3035
3036

3037

3038
3039
3040
3041
3042
3043
3044
3142
3143
3144
3145
3146
3147
3148

3149
3150
3151
3152
3153
3154
3155
3156
3157
3158







-
+

+







		    if (dval < 0.0) {
			dval = 0;
		    } else if (dval > 1.0) {
			dval = 1;
		    }
		    wmPtr->alpha = dval;
		} else {			/* -transparentcolor */
		    const char *crefstr = Tcl_GetStringFromObj(objv[i+1], &length);
		    const char *crefstr = Tcl_GetString(objv[i+1]);

		    length = objv[i+1]->length;
		    if (length == 0) {
			/* reset to no transparent color */
			if (wmPtr->crefObj) {
			    Tcl_DecrRefCount(wmPtr->crefObj);
			    wmPtr->crefObj = NULL;
			}
		    } else {
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
3189
3190
3191
3192
3193
3194
3195

3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206

3207
3208
3209
3210
3211
3212


3213
3214
3215
3216

3217
3218
3219
3220
3221
3222

3223
3224
3225
3226
3227
3228
3229
3230







-
+










-
+





-
-
+
+


-
+





-
+







		     * Set the window directly regardless of UpdateWrapper.
		     * The user supplies a double from [0..1], but Windows
		     * wants an int (transparent) 0..255 (opaque), so do the
		     * translation. Add the 0.5 to round the value.
		     */

		    if (!(wmPtr->exStyleConfig & WS_EX_LAYERED)) {
			SetWindowLongPtrW(wmPtr->wrapper, GWL_EXSTYLE,
			SetWindowLongPtr(wmPtr->wrapper, GWL_EXSTYLE,
				*stylePtr);
		    }
		    SetLayeredWindowAttributes((HWND) wmPtr->wrapper,
			    wmPtr->colorref, (BYTE) (wmPtr->alpha * 255 + 0.5),
			    (unsigned) (LWA_ALPHA |
				    (wmPtr->crefObj ? LWA_COLORKEY : 0)));
		}
	    }
	} else {
	    if ((i < objc-1)
		    && Tcl_GetBooleanFromObj(interp, objv[i+1], &boolValue)
		    && Tcl_GetBooleanFromObj(interp, objv[i+1], &boolean)
			    != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (config_fullscreen) {
		if (objc == 4) {
		    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
			    (wmPtr->flags & WM_FULLSCREEN) != 0));
		    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
			    wmPtr->flags & WM_FULLSCREEN));
		} else {
		    fullscreen_attr_changed = 1;
		    fullscreen_attr = boolValue;
		    fullscreen_attr = boolean;
		}
		config_fullscreen = 0;
	    } else if (objc == 4) {
		Tcl_SetObjResult(interp,
			Tcl_NewBooleanObj(*stylePtr & styleBit));
	    } else if (boolValue) {
	    } else if (boolean) {
		*stylePtr |= styleBit;
	    } else {
		*stylePtr &= ~styleBit;
	    }
	}
	if ((styleBit == WS_EX_TOPMOST) && (wmPtr->wrapper != NULL)) {
	    /*
3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210

3211
3212
3213

3214
3215

3216
3217
3218
3219
3220
3221
3222
3223
3224

3225
3226
3227
3228


3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243

3244
3245
3246
3247
3248
3249
3250
3251
3252

3253
3254
3255
3256
3257
3258
3259
3314
3315
3316
3317
3318
3319
3320

3321
3322
3323

3324
3325
3326

3327
3328

3329
3330
3331
3332
3333
3334
3335
3336
3337

3338
3339
3340
3341

3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357

3358
3359
3360
3361
3362
3363
3364
3365
3366

3367
3368
3369
3370
3371
3372
3373
3374







-
+


-
+


-
+

-
+








-
+



-
+
+














-
+








-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmClientCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size length;
    size_t length;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->clientMachine != NULL) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj(wmPtr->clientMachine, TCL_INDEX_NONE));
		    Tcl_NewStringObj(wmPtr->clientMachine, -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    argv3 = Tcl_GetString(objv[3]);
    length = objv[3]->length;
    if (argv3[0] == 0) {
	if (wmPtr->clientMachine != NULL) {
	    ckfree(wmPtr->clientMachine);
	    wmPtr->clientMachine = NULL;
	    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
		XDeleteProperty(winPtr->display, winPtr->window,
			Tk_InternAtom((Tk_Window) winPtr,"WM_CLIENT_MACHINE"));
	    }
	}
	return TCL_OK;
    }
    if (wmPtr->clientMachine != NULL) {
	ckfree(wmPtr->clientMachine);
    }
    wmPtr->clientMachine = (char *)ckalloc(length + 1);
    wmPtr->clientMachine = ckalloc(length + 1);
    memcpy(wmPtr->clientMachine, argv3, length + 1);
    if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	XTextProperty textProp;

	if (XStringListToTextProperty(&wmPtr->clientMachine, 1, &textProp)
		!= 0) {
	    XSetWMClientMachine(winPtr->display, winPtr->window,
		    &textProp);
	    XFree(textProp.value);
	    XFree((char *) textProp.value);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
3273
3274
3275
3276
3277
3278
3279
3280

3281
3282
3283

3284
3285

3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302

3303
3304
3305
3306
3307
3308
3309
3310
3311

3312
3313
3314
3315
3316
3317
3318
3388
3389
3390
3391
3392
3393
3394

3395
3396
3397

3398
3399

3400

3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415

3416
3417
3418
3419
3420
3421
3422
3423
3424

3425
3426
3427
3428
3429
3430
3431
3432







-
+


-
+

-
+
-















-
+








-
+







 */

static int
WmColormapwindowsCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow **cmapList, *winPtr2, **winPtr2Ptr = &winPtr2;
    Tcl_Size i, windowObjc;
    int i, windowObjc, gotToplevel;
    int gotToplevel;
    Tcl_Obj **windowObjv, *resultObj;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tk_MakeWindowExist((Tk_Window) winPtr);
	resultObj = Tcl_NewObj();
	for (i = 0; i < wmPtr->cmapCount; i++) {
	    if ((i == (wmPtr->cmapCount-1))
		    && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
		break;
	    }
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    Tk_NewWindowObj((Tk_Window) wmPtr->cmapList[i]));
		    TkNewWindowObj((Tk_Window) wmPtr->cmapList[i]));
	}
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
    }
    if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
	    != TCL_OK) {
	return TCL_ERROR;
    }
    cmapList = (TkWindow**)ckalloc((windowObjc + 1) * sizeof(TkWindow*));
    cmapList = ckalloc((windowObjc + 1) * sizeof(TkWindow*));
    gotToplevel = 0;
    for (i = 0; i < windowObjc; i++) {
	if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
		(Tk_Window *) winPtr2Ptr) != TCL_OK) {
	    ckfree(cmapList);
	    return TCL_ERROR;
	}
3365
3366
3367
3368
3369
3370
3371
3372

3373
3374
3375

3376
3377
3378

3379
3380

3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391

3392
3393
3394
3395
3396
3397
3398
3479
3480
3481
3482
3483
3484
3485

3486
3487
3488

3489
3490
3491

3492
3493

3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504

3505
3506
3507
3508
3509
3510
3511
3512







-
+


-
+


-
+

-
+










-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmCommandCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size cmdArgc;
    int cmdArgc;
    const char **cmdArgv;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->cmdArgv != NULL) {
	    char *merged = Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv);

	    Tcl_SetObjResult(interp, Tcl_NewStringObj(merged, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(merged, -1));
	    ckfree(merged);
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetString(objv[3]);
    if (argv3[0] == 0) {
	if (wmPtr->cmdArgv != NULL) {
3434
3435
3436
3437
3438
3439
3440
3441

3442
3443
3444

3445
3446
3447

3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461

3462
3463
3464
3465
3466
3467
3468
3548
3549
3550
3551
3552
3553
3554

3555
3556
3557

3558
3559
3560

3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574

3575
3576
3577
3578
3579
3580
3581
3582







-
+


-
+


-
+













-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmDeiconifyCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't deiconify %s: it is an icon for %s",
		Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "DEICONIFY", "ICON", NULL);
	return TCL_ERROR;
    }
    if (winPtr->flags & TK_EMBEDDED) {
	if (!SendMessageW(wmPtr->wrapper, TK_DEICONIFY, 0, 0)) {
	if (!SendMessage(wmPtr->wrapper, TK_DEICONIFY, 0, 0)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't deiconify %s: the container does not support the request",
		    winPtr->pathName));
	    Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	    return TCL_ERROR;
	}
	return TCL_OK;
3486
3487
3488
3489
3490
3491
3492
3493

3494
3495
3496

3497
3498
3499

3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514

3515
3516
3517
3518
3519


3520
3521
3522
3523
3524
3525
3526
3600
3601
3602
3603
3604
3605
3606

3607
3608
3609

3610
3611
3612

3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627

3628
3629
3630
3631


3632
3633
3634
3635
3636
3637
3638
3639
3640







-
+


-
+


-
+














-
+



-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFocusmodelCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"active", "passive", NULL
    };
    enum options {
	OPT_ACTIVE, OPT_PASSIVE
    };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?active|passive?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		wmPtr->hints.input ? "passive" : "active", TCL_INDEX_NONE));
		wmPtr->hints.input ? "passive" : "active", -1));
	return TCL_OK;
    }

    if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings,
	    "argument", 0,&index) != TCL_OK) {
    if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
	    sizeof(char *), "argument", 0,&index) != TCL_OK) {
	return TCL_ERROR;
    }
    if (index == OPT_ACTIVE) {
	wmPtr->hints.input = False;
    } else { /* OPT_PASSIVE */
	wmPtr->hints.input = True;
    }
3542
3543
3544
3545
3546
3547
3548
3549

3550
3551
3552
3553



3554
3555

3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566




3567
3568
3569
3570
3571
3572
3573
3656
3657
3658
3659
3660
3661
3662

3663
3664



3665
3666
3667
3668

3669
3670
3671
3672
3673
3674
3675
3676




3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687







-
+

-
-
-
+
+
+

-
+







-
-
-
-
+
+
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmForgetCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel or Frame to work with */
    TCL_UNUSED(Tcl_Interp *),		/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),		/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *))	/* Argument objects. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window) winPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;

    if (Tk_IsTopLevel(frameWin)) {
	Tk_UnmapWindow(frameWin);
	winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
	Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);
	RemapWindows(winPtr, Tk_GetHWND(winPtr->parentPtr->window));

	/*
	 * Make sure wm no longer manages this window
	 */
	Tk_ManageGeometry(frameWin, NULL, NULL);
        /*
         * Make sure wm no longer manages this window
         */
        Tk_ManageGeometry(frameWin, NULL, NULL);

	TkWmDeadWindow(winPtr);
	/* flags (above) must be cleared before calling */
	/* TkMapTopFrame (below) */
	TkMapTopFrame(frameWin);
    } else {
	/* Already not managed by wm - ignore it */
3590
3591
3592
3593
3594
3595
3596
3597

3598
3599
3600

3601
3602
3603

3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619

3620
3621
3622
3623
3624
3625
3626
3704
3705
3706
3707
3708
3709
3710

3711
3712
3713

3714
3715
3716

3717
3718

3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730


3731
3732
3733
3734
3735
3736
3737
3738







-
+


-
+


-
+

-












-
-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmFrameCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    HWND hwnd;
    char buf[TCL_INTEGER_SPACE];

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (Tk_WindowId((Tk_Window) winPtr) == None) {
	Tk_MakeWindowExist((Tk_Window) winPtr);
    }
    hwnd = wmPtr->wrapper;
    if (hwnd == NULL) {
	hwnd = Tk_GetHWND(Tk_WindowId((Tk_Window) winPtr));
    }
    snprintf(buf, sizeof(buf), "0x%" TCL_Z_MODIFIER "x", (size_t)hwnd);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("0x%x", PTR2INT(hwnd)));
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmGeometryCmd --
3635
3636
3637
3638
3639
3640
3641
3642

3643
3644
3645

3646
3647
3648

3649
3650
3651
3652
3653
3654
3655
3747
3748
3749
3750
3751
3752
3753

3754
3755
3756

3757
3758
3759

3760
3761
3762
3763
3764
3765
3766
3767







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGeometryCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    char xSign, ySign;
    int width, height;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newGeometry?");
	return TCL_ERROR;
3664
3665
3666
3667
3668
3669
3670
3671

3672
3673
3674
3675
3676
3677
3678
3776
3777
3778
3779
3780
3781
3782

3783
3784
3785
3786
3787
3788
3789
3790







-
+







	    height = wmPtr->reqGridHeight + (winPtr->changes.height
		    - winPtr->reqHeight)/wmPtr->heightInc;
	} else {
	    width = winPtr->changes.width;
	    height = winPtr->changes.height;
	}
	if (winPtr->flags & TK_EMBEDDED) {
	    int result = SendMessageW(wmPtr->wrapper, TK_MOVEWINDOW, -1, -1);
	    int result = SendMessage(wmPtr->wrapper, TK_MOVEWINDOW, -1, -1);

	    wmPtr->x = result >> 16;
	    wmPtr->y = result & 0x0000ffff;
	}
	Tcl_SetObjResult(interp, Tcl_ObjPrintf("%dx%d%c%d%c%d",
		width, height, xSign, wmPtr->x, ySign, wmPtr->y));
	return TCL_OK;
3703
3704
3705
3706
3707
3708
3709
3710

3711
3712
3713

3714
3715
3716

3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731




3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742

3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760

3761
3762
3763
3764
3765
3766

3767
3768
3769
3770
3771
3772

3773
3774
3775
3776
3777
3778

3779
3780
3781
3782
3783
3784
3785
3815
3816
3817
3818
3819
3820
3821

3822
3823
3824

3825
3826
3827

3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839




3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853

3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871

3872
3873
3874
3875
3876
3877

3878
3879
3880
3881
3882
3883

3884
3885
3886
3887
3888
3889

3890
3891
3892
3893
3894
3895
3896
3897







-
+


-
+


-
+











-
-
-
-
+
+
+
+










-
+

















-
+





-
+





-
+





-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmGridCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int reqWidth, reqHeight, widthInc, heightInc;

    if ((objc != 3) && (objc != 7)) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?baseWidth baseHeight widthInc heightInc?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->sizeHintsFlags & PBaseSize) {
	    Tcl_Obj *results[4];

	    results[0] = Tcl_NewWideIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewWideIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewWideIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewWideIntObj(wmPtr->heightInc);
	    results[0] = Tcl_NewIntObj(wmPtr->reqGridWidth);
	    results[1] = Tcl_NewIntObj(wmPtr->reqGridHeight);
	    results[2] = Tcl_NewIntObj(wmPtr->widthInc);
	    results[3] = Tcl_NewIntObj(wmPtr->heightInc);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	/*
	 * Turn off gridding and reset the width and height to make sense as
	 * ungridded numbers.
	 */

	wmPtr->sizeHintsFlags &= ~PBaseSize;
	wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
	if (wmPtr->width != -1) {
	    wmPtr->width = winPtr->reqWidth + (wmPtr->width
		    - wmPtr->reqGridWidth)*wmPtr->widthInc;
	    wmPtr->height = winPtr->reqHeight + (wmPtr->height
		    - wmPtr->reqGridHeight)*wmPtr->heightInc;
	}
	wmPtr->widthInc = 1;
	wmPtr->heightInc = 1;
    } else {
	if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK)
		|| (Tcl_GetIntFromObj(interp, objv[6], &heightInc) != TCL_OK)) {
	    return TCL_ERROR;
	}
	if (reqWidth < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "baseWidth can't be < 0", TCL_INDEX_NONE));
		    "baseWidth can't be < 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (reqHeight < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "baseHeight can't be < 0", TCL_INDEX_NONE));
		    "baseHeight can't be < 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (widthInc <= 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "widthInc can't be <= 0", TCL_INDEX_NONE));
		    "widthInc can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	if (heightInc <= 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "heightInc can't be <= 0", TCL_INDEX_NONE));
		    "heightInc can't be <= 0", -1));
	    Tcl_SetErrorCode(interp, "TK", "VALUE", "GRID", NULL);
	    return TCL_ERROR;
	}
	Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
		heightInc);
    }
    WmUpdateGeom(wmPtr, winPtr);
3804
3805
3806
3807
3808
3809
3810
3811

3812
3813
3814

3815
3816
3817

3818
3819
3820
3821
3822
3823
3824
3825

3826
3827
3828
3829


3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846

3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3916
3917
3918
3919
3920
3921
3922

3923
3924
3925

3926
3927
3928

3929
3930
3931
3932
3933
3934
3935
3936

3937
3938
3939
3940

3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958

3959
3960
3961















































































































3962
3963
3964
3965
3966
3967
3968







-
+


-
+


-
+







-
+



-
+
+
















-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 */

static int
WmGroupCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    const char *argv3;
    Tcl_Size length;
    size_t length;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & WindowGroupHint) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, TCL_INDEX_NONE));
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, -1));
	}
	return TCL_OK;
    }
    argv3 = Tcl_GetStringFromObj(objv[3], &length);
    argv3 = Tcl_GetString(objv[3]);
    length = objv[3]->length;
    if (*argv3 == '\0') {
	wmPtr->hints.flags &= ~WindowGroupHint;
	if (wmPtr->leaderName != NULL) {
	    ckfree(wmPtr->leaderName);
	}
	wmPtr->leaderName = NULL;
    } else {
	if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
	    return TCL_ERROR;
	}
	Tk_MakeWindowExist(tkwin2);
	if (wmPtr->leaderName != NULL) {
	    ckfree(wmPtr->leaderName);
	}
	wmPtr->hints.window_group = Tk_WindowId(tkwin2);
	wmPtr->hints.flags |= WindowGroupHint;
	wmPtr->leaderName = (char *)ckalloc(length + 1);
	wmPtr->leaderName = ckalloc(length + 1);
	memcpy(wmPtr->leaderName, argv3, length + 1);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconbadgeCmd --
 *
 *	This function is invoked to process the "wm iconbadge" Tcl command.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbadgeCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TCL_UNUSED(TkWindow *),	/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    HWND hwnd;
    Tk_PhotoHandle photo;
    Tk_PhotoImageBlock block;
    int width, height;
    HICON overlayicon;
    int badgenumber;
    char *badgestring = NULL;
    char photoname[4096];
    LPCWSTR string;
    HRESULT hr;
    Tk_Window badgewindow;
    WmInfo *wmPtr;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window badge");
	return TCL_ERROR;
    }

    /*
     * Parse args, get native wrapper window, and determine image.
     */

    badgewindow = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin);
    wmPtr = ((TkWindow *) badgewindow)->wmInfoPtr;
    hwnd = wmPtr->wrapper;
    badgestring = Tcl_GetString(objv[3]);

    badgenumber = atoi(badgestring);
    if (badgenumber > 9) {
	strcpy(photoname, "::tk::icons::9plus-badge");
    } else {
	strcpy(photoname, "::tk::icons::");
	strcat(photoname, badgestring);
	strcat(photoname, "-badge");
    }

    /*
     * If badgestring is empty string, remove icon.
     */

    if (strcmp("", badgestring) == 0) {
	ptbl->lpVtbl->SetOverlayIcon(ptbl, hwnd, NULL, NULL);
	return TCL_OK;
    }

    /*
     * If photo does not exist, return error. This means we do not have
     * to test for decimal or negative values; no photo for such values
     * is present.
     */

    photo = Tk_FindPhoto(interp, photoname);
    if (photo == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't use \"%s\" as icon badge", badgestring));
	return TCL_ERROR;
    }

    /*
     * We have found the image. Convert to icon.
     */

    Tk_PhotoGetSize(photo, &width, &height);
    Tk_PhotoGetImage(photo, &block);

    overlayicon = CreateIcoFromPhoto(width, height, block);
    if (overlayicon == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("Failed to create badge icon", TCL_INDEX_NONE));
	return TCL_ERROR;
    }

    /*
     * Place overlay icon on taskbar icon.
     */

    string = L"Alert";
    hr = ptbl->lpVtbl->SetOverlayIcon(ptbl, hwnd, overlayicon, string);
    if (hr != S_OK) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("Failed to create badge icon", TCL_INDEX_NONE));
	return TCL_ERROR;
    }
    DestroyIcon(overlayicon);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WmIconbitmapCmd --
3975
3976
3977
3978
3979
3980
3981
3982

3983
3984
3985

3986
3987
3988

3989
3990
3991
3992
3993
3994
3995
3977
3978
3979
3980
3981
3982
3983

3984
3985
3986

3987
3988
3989

3990
3991
3992
3993
3994
3995
3996
3997







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconbitmapCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow *useWinPtr = winPtr; /* window to apply to (NULL if -default) */
    const char *string;

    if ((objc < 3) || (objc > 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?-default? ?image?");
	return TCL_ERROR;
    } else if (objc == 5) {
4111
4112
4113
4114
4115
4116
4117
4118

4119
4120
4121

4122
4123
4124

4125
4126
4127
4128
4129
4130
4131

4132
4133

4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147

4148
4149
4150
4151
4152
4153
4154
4155
4156

4157
4158
4159
4160
4161
4162
4163
4113
4114
4115
4116
4117
4118
4119

4120
4121
4122

4123
4124
4125

4126

4127
4128
4129
4130
4131

4132
4133

4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147

4148
4149
4150
4151
4152
4153
4154
4155
4156

4157
4158
4159
4160
4161
4162
4163
4164







-
+


-
+


-
+
-





-
+

-
+













-
+








-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconifyCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (winPtr->flags & TK_EMBEDDED) {
	if (!SendMessageW(wmPtr->wrapper, TK_ICONIFY, 0, 0)) {
	if (!SendMessage(wmPtr->wrapper, TK_ICONIFY, 0, 0)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't iconify \"%s\": the container does not support the request",
		    "can't iconify %s: the container does not support the request",
		    winPtr->pathName));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "EMBEDDED", NULL);
	    return TCL_ERROR;
	}
    }
    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": override-redirect flag is set",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "OVERRIDE_REDIRECT",
		NULL);
	return TCL_ERROR;
    }
    if (wmPtr->containerPtr != NULL) {
    if (wmPtr->masterPtr != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is a transient",
		winPtr->pathName));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "TRANSIENT", NULL);
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't iconify \"%s\": it is an icon for \"%s\"",
		"can't iconify %s: it is an icon for %s",
		winPtr->pathName, Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "ICON", NULL);
	return TCL_ERROR;
    }
    TkpWmSetState(winPtr, IconicState);
    return TCL_OK;
}
4180
4181
4182
4183
4184
4185
4186
4187

4188
4189
4190

4191
4192
4193
4194
4195
4196
4197
4181
4182
4183
4184
4185
4186
4187

4188
4189
4190

4191
4192
4193
4194
4195
4196
4197
4198







-
+


-
+







 */

static int
WmIconmaskCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Pixmap pixmap;
    const char *argv3;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
	return TCL_ERROR;
    }
4235
4236
4237
4238
4239
4240
4241
4242

4243
4244
4245

4246
4247
4248

4249
4250

4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265



4266
4267
4268
4269
4270
4271
4272
4236
4237
4238
4239
4240
4241
4242

4243
4244
4245

4246
4247
4248

4249
4250

4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264


4265
4266
4267
4268
4269
4270
4271
4272
4273
4274







-
+


-
+


-
+

-
+













-
-
+
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconnameCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size length;
    size_t length;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		(wmPtr->iconName ? wmPtr->iconName : ""), -1));
	return TCL_OK;
    } else {
	if (wmPtr->iconName != NULL) {
	    ckfree(wmPtr->iconName);
	}
	argv3 = Tcl_GetStringFromObj(objv[3], &length);
	wmPtr->iconName = (char *)ckalloc(length + 1);
	argv3 = Tcl_GetString(objv[3]);
	length = objv[3]->length;
	wmPtr->iconName = ckalloc(length + 1);
	memcpy(wmPtr->iconName, argv3, length + 1);
	if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
	    XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName);
	}
    }
    return TCL_OK;
}
4286
4287
4288
4289
4290
4291
4292
4293

4294
4295
4296

4297
4298
4299
4300
4301
4302
4303



4304
4305
4306
4307


4308
4309
4310
4311
4312
4313
4314
4288
4289
4290
4291
4292
4293
4294

4295
4296
4297

4298
4299
4300
4301
4302
4303


4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319







-
+


-
+





-
-
+
+
+




+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconphotoCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkWindow *useWinPtr = winPtr; /* window to apply to (NULL if -default) */
    Tk_PhotoHandle photo;
    Tk_PhotoImageBlock block;
    Tcl_Size i;
    int width, height, startObj = 3;
    int i, width, height, idx, bufferSize, startObj = 3;
    union {unsigned char *ptr; void *voidPtr;} bgraPixel;
    union {unsigned char *ptr; void *voidPtr;} bgraMask;
    BlockOfIconImagesPtr lpIR;
    WinIconPtr titlebaricon = NULL;
    HICON hIcon;
    unsigned size;
    BITMAPINFO bmInfo;
    ICONINFO iconInfo;

    if (objc < 4) {
	Tcl_WrongNumArgs(interp, 2, objv,
		"window ?-default? image1 ?image2 ...?");
	return TCL_ERROR;
    }

4338
4339
4340
4341
4342
4343
4344
4345

4346
4347
4348

4349


4350
4351
4352
4353
4354
4355







































































4356



4357




4358

4359
4360

4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372

4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407

4408
4409
4410

4411
4412
4413

4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425


4426
4427
4428
4429
4430
4431
4432
4343
4344
4345
4346
4347
4348
4349

4350
4351
4352
4353
4354

4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433

4434
4435
4436
4437
4438
4439
4440
4441

4442
4443

4444
4445
4446
4447
4448
4449
4450
4451
4452

4453
4454

4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468


4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487

4488
4489
4490

4491
4492
4493

4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504


4505
4506
4507
4508
4509
4510
4511
4512
4513







-
+



+
-
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+

+
+
+
+
-
+

-
+








-


-
+













-
-



















-
+


-
+


-
+










-
-
+
+








    /*
     * We have calculated the size of the data. Try to allocate the needed
     * memory space.
     */

    size = sizeof(BlockOfIconImages) + (sizeof(ICONIMAGE) * (objc-startObj-1));
    lpIR = (BlockOfIconImagesPtr)attemptckalloc(size);
    lpIR = attemptckalloc(size);
    if (lpIR == NULL) {
	return TCL_ERROR;
    }
    ZeroMemory(lpIR, size);
    memset(lpIR, 0, size);

    lpIR->nNumImages = objc - startObj;

    for (i = startObj; i < objc; i++) {
	photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
	Tk_PhotoGetSize(photo, &width, &height);
	Tk_PhotoGetImage(photo, &block);

	/*
	 * Don't use CreateIcon to create the icon, as it requires color
	 * bitmap data in device-dependent format. Instead we use
	 * CreateIconIndirect which takes device-independent bitmaps and
	 * converts them as required. Initialise icon info structure.
	 */

	ZeroMemory(&iconInfo, sizeof(iconInfo));
	iconInfo.fIcon = TRUE;

	/*
	 * Create device-independant color bitmap.
	 */

	ZeroMemory(&bmInfo, sizeof bmInfo);
	bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmInfo.bmiHeader.biWidth = width;
	bmInfo.bmiHeader.biHeight = -height;
	bmInfo.bmiHeader.biPlanes = 1;
	bmInfo.bmiHeader.biBitCount = 32;
	bmInfo.bmiHeader.biCompression = BI_RGB;

	iconInfo.hbmColor = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS,
		&bgraPixel.voidPtr, NULL, 0);
	if (!iconInfo.hbmColor) {
	    ckfree(lpIR);
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "failed to create color bitmap for \"%s\"",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "BITMAP", NULL);
	    return TCL_ERROR;
	}

	/*
	 * Convert the photo image data into BGRA format (RGBQUAD).
	 */

	bufferSize = height * width * 4;
	for (idx = 0 ; idx < bufferSize ; idx += 4) {
	    bgraPixel.ptr[idx] = block.pixelPtr[idx+2];
	    bgraPixel.ptr[idx+1] = block.pixelPtr[idx+1];
	    bgraPixel.ptr[idx+2] = block.pixelPtr[idx+0];
	    bgraPixel.ptr[idx+3] = block.pixelPtr[idx+3];
	}

	/*
	 * Create a dummy mask bitmap. The contents of this don't appear to
	 * matter, as CreateIconIndirect will setup the icon mask based on the
	 * alpha channel in our color bitmap.
	 */

	bmInfo.bmiHeader.biBitCount = 1;

	iconInfo.hbmMask = CreateDIBSection(NULL, &bmInfo, DIB_RGB_COLORS,
		&bgraMask.voidPtr, NULL, 0);
	if (!iconInfo.hbmMask) {
	    DeleteObject(iconInfo.hbmColor);
	    ckfree(lpIR);
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "failed to create mask bitmap for \"%s\"",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "MASK", NULL);
	    return TCL_ERROR;
	}

	ZeroMemory(bgraMask.ptr, width*height/8);

	/*
	 * Create an icon from the bitmaps.
	 */

	hIcon = CreateIcoFromPhoto(width, height, block);
	hIcon = CreateIconIndirect(&iconInfo);
	DeleteObject(iconInfo.hbmColor);
	DeleteObject(iconInfo.hbmMask);
	if (hIcon == NULL) {
	    /*
	     * XXX should free up created icons.
	     */

	    FreeIconBlock(lpIR);
	    ckfree(lpIR);
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "failed to create an iconphoto with image \"%s\"",
		    "failed to create icon for \"%s\"",
		    Tcl_GetString(objv[i])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "ICON", NULL);
	    return TCL_ERROR;
	}
	lpIR->IconImages[i-startObj].Width = width;
	lpIR->IconImages[i-startObj].Height = height;
	lpIR->IconImages[i-startObj].Colors = 4;
	lpIR->IconImages[i-startObj].hIcon = hIcon;
	lpIR->nNumImages++;
    }

    titlebaricon = (WinIconPtr)ckalloc(sizeof(WinIconInstance));
    titlebaricon = ckalloc(sizeof(WinIconInstance));
    titlebaricon->iconBlock = lpIR;
    titlebaricon->refCount = 1;
    if (WinSetIcon(interp, titlebaricon, (Tk_Window) useWinPtr) != TCL_OK) {
	/*
	 * We didn't use the titlebaricon after all.
	 */

	DecrIconRefCount(titlebaricon);
	return TCL_ERROR;
    }
    return TCL_OK;
}



/*
 *----------------------------------------------------------------------
 *
 * WmIconpositionCmd --
 *
 *	This function is invoked to process the "wm iconposition" Tcl command.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmIconpositionCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?x y?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->hints.flags & IconPositionHint) {
	    Tcl_Obj *results[2];

	    results[0] = Tcl_NewWideIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewWideIntObj(wmPtr->hints.icon_y);
	    results[0] = Tcl_NewIntObj(wmPtr->hints.icon_x);
	    results[1] = Tcl_NewIntObj(wmPtr->hints.icon_y);
	    Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->hints.flags &= ~IconPositionHint;
    } else {
4459
4460
4461
4462
4463
4464
4465
4466

4467
4468
4469

4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480

4481
4482
4483
4484
4485
4486
4487
4540
4541
4542
4543
4544
4545
4546

4547
4548
4549

4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560

4561
4562
4563
4564
4565
4566
4567
4568







-
+


-
+










-
+







 */

static int
WmIconwindowCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    Tk_Window tkwin2;
    WmInfo *wmPtr2;
    XSetWindowAttributes atts;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (wmPtr->icon != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj(wmPtr->icon));
	    Tcl_SetObjResult(interp, TkNewWindowObj(wmPtr->icon));
	}
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->hints.flags &= ~IconWindowHint;
	if (wmPtr->icon != NULL) {
	    /*
4566
4567
4568
4569
4570
4571
4572
4573

4574
4575
4576
4577


4578
4579
4580


4581
4582
4583
4584
4585
4586
4587
4647
4648
4649
4650
4651
4652
4653

4654
4655
4656


4657
4658
4659


4660
4661
4662
4663
4664
4665
4666
4667
4668







-
+


-
-
+
+

-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmManageCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel or Frame to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    TCL_UNUSED(Tcl_Size),		/* Number of arguments. */
    TCL_UNUSED(Tcl_Obj *const *)) /* Argument objects. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window frameWin = (Tk_Window) winPtr;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register Tk_Window frameWin = (Tk_Window) winPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!Tk_IsTopLevel(frameWin)) {
	if (!Tk_IsManageable(frameWin)) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "window \"%s\" is not manageable: must be a frame,"
		    " labelframe or toplevel", Tk_PathName(frameWin)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "MANAGE", NULL);
4620
4621
4622
4623
4624
4625
4626
4627

4628
4629
4630

4631
4632
4633

4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645


4646
4647
4648
4649
4650


4651
4652
4653
4654
4655
4656
4657
4701
4702
4703
4704
4705
4706
4707

4708
4709
4710

4711
4712
4713

4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724


4725
4726
4727
4728
4729


4730
4731
4732
4733
4734
4735
4736
4737
4738







-
+


-
+


-
+










-
-
+
+



-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmMaxsizeCmd(
    Tk_Window tkwin,	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_Obj *results[2];

	GetMaxSize(wmPtr, &width, &height);
	results[0] = Tcl_NewWideIntObj(width);
	results[1] = Tcl_NewWideIntObj(height);
	results[0] = Tcl_NewIntObj(width);
	results[1] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }
    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->maxWidth = width;
    wmPtr->maxHeight = height;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;
}
4671
4672
4673
4674
4675
4676
4677
4678

4679
4680
4681

4682
4683
4684

4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696


4697
4698
4699
4700
4701


4702
4703
4704
4705
4706
4707
4708
4752
4753
4754
4755
4756
4757
4758

4759
4760
4761

4762
4763
4764

4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775


4776
4777
4778
4779
4780


4781
4782
4783
4784
4785
4786
4787
4788
4789







-
+


-
+


-
+










-
-
+
+



-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmMinsizeCmd(
    Tk_Window tkwin,	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	Tcl_Obj *results[2];

	GetMinSize(wmPtr, &width, &height);
	results[0] = Tcl_NewWideIntObj(width);
	results[1] = Tcl_NewWideIntObj(height);
	results[0] = Tcl_NewIntObj(width);
	results[1] = Tcl_NewIntObj(height);
	Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
	return TCL_OK;
    }
    if ((Tk_GetPixelsFromObj(interp, tkwin, objv[3], &width) != TCL_OK)
	    || (Tk_GetPixelsFromObj(interp, tkwin, objv[4], &height) != TCL_OK)) {
    if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
	    || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
	return TCL_ERROR;
    }
    wmPtr->minWidth = width;
    wmPtr->minHeight = height;
    WmUpdateGeom(wmPtr, winPtr);
    return TCL_OK;
}
4722
4723
4724
4725
4726
4727
4728
4729

4730
4731
4732

4733
4734
4735
4736


4737
4738
4739
4740
4741
4742
4743
4744

4745
4746
4747

4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758

4759
4760
4761

4762
4763

4764
4765
4766
4767
4768
4769
4770

4771
4772
4773
4774
4775
4776
4777
4803
4804
4805
4806
4807
4808
4809

4810
4811
4812

4813
4814
4815


4816
4817
4818
4819
4820
4821
4822
4823
4824

4825
4826
4827

4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838

4839
4840
4841

4842
4843

4844
4845
4846
4847
4848
4849
4850

4851
4852
4853
4854
4855
4856
4857
4858







-
+


-
+


-
-
+
+







-
+


-
+










-
+


-
+

-
+






-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmOverrideredirectCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    Bool boolValue, curValue;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int boolean, curValue;
    XSetWindowAttributes atts;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
	return TCL_ERROR;
    }
    if (winPtr->flags & TK_EMBEDDED) {
	curValue = SendMessageW(wmPtr->wrapper, TK_OVERRIDEREDIRECT, -1, -1)-1;
	curValue = SendMessage(wmPtr->wrapper, TK_OVERRIDEREDIRECT, -1, -1)-1;
	if (curValue < 0) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "Container does not support overrideredirect", TCL_INDEX_NONE));
		    "Container does not support overrideredirect", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	    return TCL_ERROR;
	}
    } else {
	curValue = Tk_Attributes((Tk_Window) winPtr)->override_redirect;
    }
    if (objc == 3) {
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(curValue));
	return TCL_OK;
    }
    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolValue) != TCL_OK) {
    if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) {
	return TCL_ERROR;
    }
    if (curValue != boolValue) {
    if (curValue != boolean) {
	if (winPtr->flags & TK_EMBEDDED) {
	    SendMessageW(wmPtr->wrapper, TK_OVERRIDEREDIRECT, boolValue, 0);
	    SendMessage(wmPtr->wrapper, TK_OVERRIDEREDIRECT, boolean, 0);
	} else {
	    /*
	     * Only do this if we are really changing value, because it causes
	     * some funky stuff to occur.
	     */

	    atts.override_redirect = boolValue;
	    atts.override_redirect = (boolean) ? True : False;
	    Tk_ChangeWindowAttributes((Tk_Window) winPtr, CWOverrideRedirect,
		    &atts);
	    if (!(wmPtr->flags & (WM_NEVER_MAPPED))
		    && !(winPtr->flags & TK_EMBEDDED)) {
		UpdateWrapper(winPtr);
	    }
	}
4794
4795
4796
4797
4798
4799
4800
4801

4802
4803
4804

4805
4806
4807

4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828

4829
4830
4831
4832
4833
4834
4835


4836
4837
4838
4839
4840
4841
4842
4875
4876
4877
4878
4879
4880
4881

4882
4883
4884

4885
4886
4887

4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908

4909
4910
4911
4912
4913
4914


4915
4916
4917
4918
4919
4920
4921
4922
4923







-
+


-
+


-
+




















-
+





-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmPositionfromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL
    };
    enum options {
	OPT_PROGRAM, OPT_USER
    };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user/program?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	const char *sourceStr = "";

	if (wmPtr->sizeHintsFlags & USPosition) {
	    sourceStr = "user";
	} else if (wmPtr->sizeHintsFlags & PPosition) {
	    sourceStr = "program";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, -1));
	return TCL_OK;
    }
    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USPosition|PPosition);
    } else {
	if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings,
		"argument", 0, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (index == OPT_USER) {
	    wmPtr->sizeHintsFlags &= ~PPosition;
	    wmPtr->sizeHintsFlags |= USPosition;
	} else {
	    wmPtr->sizeHintsFlags &= ~USPosition;
4862
4863
4864
4865
4866
4867
4868
4869

4870
4871
4872

4873
4874
4875
4876


4877
4878
4879

4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895

4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910

4911
4912
4913
4914
4915
4916
4917
4943
4944
4945
4946
4947
4948
4949

4950
4951
4952

4953
4954
4955


4956
4957
4958
4959

4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975

4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990

4991
4992
4993
4994
4995
4996
4997
4998







-
+


-
+


-
-
+
+


-
+















-
+














-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmProtocolCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    ProtocolHandler *protPtr, *prevPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    register ProtocolHandler *protPtr, *prevPtr;
    Atom protocol;
    const char *cmd;
    Tcl_Size cmdLength;
    size_t cmdLength;
    Tcl_Obj *resultObj;

    if ((objc < 3) || (objc > 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?name? ?command?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	/*
	 * Return a list of all defined protocols for the window.
	 */

	resultObj = Tcl_NewObj();
	for (protPtr = wmPtr->protPtr; protPtr != NULL;
		protPtr = protPtr->nextPtr) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    Tk_GetAtomName((Tk_Window)winPtr, protPtr->protocol), TCL_INDEX_NONE));
		    Tk_GetAtomName((Tk_Window)winPtr, protPtr->protocol), -1));
	}
	Tcl_SetObjResult(interp, resultObj);
	return TCL_OK;
    }
    protocol = Tk_InternAtom((Tk_Window) winPtr, Tcl_GetString(objv[3]));
    if (objc == 4) {
	/*
	 * Return the command to handle a given protocol.
	 */

	for (protPtr = wmPtr->protPtr; protPtr != NULL;
		protPtr = protPtr->nextPtr) {
	    if (protPtr->protocol == protocol) {
		Tcl_SetObjResult(interp,
			Tcl_NewStringObj(protPtr->command, TCL_INDEX_NONE));
			Tcl_NewStringObj(protPtr->command, -1));
		return TCL_OK;
	    }
	}
	return TCL_OK;
    }

    /*
4927
4928
4929
4930
4931
4932
4933
4934


4935
4936

4937
4938
4939
4940
4941
4942
4943
5008
5009
5010
5011
5012
5013
5014

5015
5016
5017

5018
5019
5020
5021
5022
5023
5024
5025







-
+
+

-
+







	    } else {
		prevPtr->nextPtr = protPtr->nextPtr;
	    }
	    Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
	    break;
	}
    }
    cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
    cmd = Tcl_GetString(objv[4]);
    cmdLength = objv[4]->length;
    if (cmdLength > 0) {
	protPtr = (ProtocolHandler *)ckalloc(HANDLER_SIZE(cmdLength));
	protPtr = ckalloc(HANDLER_SIZE(cmdLength));
	protPtr->protocol = protocol;
	protPtr->nextPtr = wmPtr->protPtr;
	wmPtr->protPtr = protPtr;
	protPtr->interp = interp;
	memcpy(protPtr->command, cmd, cmdLength + 1);
    }
    return TCL_OK;
4958
4959
4960
4961
4962
4963
4964
4965

4966
4967
4968

4969
4970
4971

4972
4973
4974
4975
4976
4977
4978
5040
5041
5042
5043
5044
5045
5046

5047
5048
5049

5050
5051
5052

5053
5054
5055
5056
5057
5058
5059
5060







-
+


-
+


-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmResizableCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int width, height;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
	return TCL_ERROR;
    }
    if (objc == 3) {
5020
5021
5022
5023
5024
5025
5026
5027

5028
5029
5030

5031
5032
5033

5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054

5055
5056
5057
5058
5059
5060
5061
5062


5063
5064
5065
5066
5067
5068
5069
5102
5103
5104
5105
5106
5107
5108

5109
5110
5111

5112
5113
5114

5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135

5136
5137
5138
5139
5140
5141
5142


5143
5144
5145
5146
5147
5148
5149
5150
5151







-
+


-
+


-
+




















-
+






-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmSizefromCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"program", "user", NULL
    };
    enum options {
	OPT_PROGRAM, OPT_USER
    };
    int index;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?user|program?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	const char *sourceStr = "";

	if (wmPtr->sizeHintsFlags & USSize) {
	    sourceStr = "user";
	} else if (wmPtr->sizeHintsFlags & PSize) {
	    sourceStr = "program";
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(sourceStr, -1));
	return TCL_OK;
    }

    if (*Tcl_GetString(objv[3]) == '\0') {
	wmPtr->sizeHintsFlags &= ~(USSize|PSize);
    } else {
	if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings,
		"argument", 0, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (index == OPT_USER) {
	    wmPtr->sizeHintsFlags &= ~PSize;
	    wmPtr->sizeHintsFlags |= USSize;
	} else { /* OPT_PROGRAM */
	    wmPtr->sizeHintsFlags &= ~USSize;
5092
5093
5094
5095
5096
5097
5098
5099

5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127












5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5174
5175
5176
5177
5178
5179
5180

5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200









5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212



5213
5214
5215
5216
5217
5218
5219







-
+



















-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-







 */

static int
WmStackorderCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    TkWindow **windows, **windowPtr;
    static const char *const optionStrings[] = {
	"isabove", "isbelow", NULL
    };
    enum options {
	OPT_ISABOVE, OPT_ISBELOW
    };
    Tcl_Obj *resultObj;
    int index;

    if ((objc != 3) && (objc != 5)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?isabove|isbelow window?");
	return TCL_ERROR;
    }

    if (objc == 3) {
	windows = TkWmStackorderToplevel(winPtr);
	if (windows != NULL) {
	    resultObj = Tcl_NewObj();
	    for (windowPtr = windows; *windowPtr ; windowPtr++) {
		Tcl_ListObjAppendElement(NULL, resultObj,
			Tk_NewWindowObj((Tk_Window) *windowPtr));
	    }
	    Tcl_SetObjResult(interp, resultObj);
	    ckfree(windows);
	    return TCL_OK;
	if (windows == NULL) {
	    Tcl_Panic("TkWmStackorderToplevel failed");
	}

	resultObj = Tcl_NewObj();
	for (windowPtr = windows; *windowPtr ; windowPtr++) {
	    Tcl_ListObjAppendElement(NULL, resultObj,
		    TkNewWindowObj((Tk_Window) *windowPtr));
	}
	Tcl_SetObjResult(interp, resultObj);
	ckfree(windows);
	return TCL_OK;
	} else {
	    return TCL_ERROR;
	}
    } else {
	TkWindow *winPtr2, **winPtr2Ptr = &winPtr2;
	int index1 = -1, index2 = -1, result;

	if (TkGetWindowFromObj(interp, tkwin, objv[4],
		(Tk_Window *) winPtr2Ptr) != TCL_OK) {
	    return TCL_ERROR;
5163
5164
5165
5166
5167
5168
5169
5170

5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192


5193
5194
5195
5196
5197
5198
5199
5200

5201
5202
5203
5204
5205
5206
5207
5245
5246
5247
5248
5249
5250
5251

5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272


5273
5274
5275
5276
5277
5278
5279
5280
5281

5282
5283
5284
5285
5286
5287
5288
5289







-
+




















-
-
+
+







-
+







	 * Lookup stacking order of all toplevels that are children of "." and
	 * find the position of winPtr and winPtr2 in the stacking order.
	 */

	windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr);
	if (windows == NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "TkWmStackorderToplevel failed", TCL_INDEX_NONE));
		    "TkWmStackorderToplevel failed", -1));
	    Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	    return TCL_ERROR;
	}

	for (windowPtr = windows; *windowPtr ; windowPtr++) {
	    if (*windowPtr == winPtr) {
		index1 = (windowPtr - windows);
	    }
	    if (*windowPtr == winPtr2) {
		index2 = (windowPtr - windows);
	    }
	}
	if (index1 == -1) {
	    Tcl_Panic("winPtr window not found");
	} else if (index2 == -1) {
	    Tcl_Panic("winPtr2 window not found");
	}

	ckfree(windows);

	if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings,
		"argument", 0, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (index == OPT_ISABOVE) {
	    result = index1 > index2;
	} else { /* OPT_ISBELOW */
	    result = index1 < index2;
	}
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(result));
	Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result));
	return TCL_OK;
    }
}

/*
 *----------------------------------------------------------------------
 *
5217
5218
5219
5220
5221
5222
5223
5224

5225
5226
5227

5228
5229
5230

5231
5232

5233
5234
5235

5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252


5253
5254
5255
5256
5257
5258
5259
5299
5300
5301
5302
5303
5304
5305

5306
5307
5308

5309
5310
5311

5312
5313

5314
5315
5316

5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332


5333
5334
5335
5336
5337
5338
5339
5340
5341







-
+


-
+


-
+

-
+


-
+















-
-
+
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmStateCmd(
    TCL_UNUSED(Tk_Window),		/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    static const char *const optionStrings[] = {
	"iconic", "normal", "withdrawn", "zoomed", NULL
	"normal", "iconic", "withdrawn", "zoomed", NULL
    };
    enum options {
	OPT_ICONIC, OPT_NORMAL, OPT_WITHDRAWN, OPT_ZOOMED
	OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN, OPT_ZOOMED
    };
    int index;

    if ((objc < 3) || (objc > 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?state?");
	return TCL_ERROR;
    }
    if (objc == 4) {
	if (wmPtr->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't change state of %s: it is an icon for %s",
		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "ICON", NULL);
	    return TCL_ERROR;
	}
	if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings,
		"argument", 0, &index) != TCL_OK) {
	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
		sizeof(char *), "argument", 0, &index) != TCL_OK) {
	    return TCL_ERROR;
	}

	if (winPtr->flags & TK_EMBEDDED) {
	    int state = 0;

	    switch (index) {
5269
5270
5271
5272
5273
5274
5275
5276

5277
5278
5279
5280
5281
5282
5283
5351
5352
5353
5354
5355
5356
5357

5358
5359
5360
5361
5362
5363
5364
5365







-
+







	    case OPT_ZOOMED:
		state = ZoomState;
		break;
	    default:
		Tcl_Panic("unexpected index");
	    }

	    if (state+1 != SendMessageW(wmPtr->wrapper, TK_STATE, state, 0)) {
	    if (state+1 != SendMessage(wmPtr->wrapper, TK_STATE, state, 0)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't change state of %s: the container does not support the request",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
		return TCL_ERROR;
	    }
	    return TCL_OK;
5296
5297
5298
5299
5300
5301
5302
5303

5304
5305
5306
5307
5308
5309
5310
5378
5379
5380
5381
5382
5383
5384

5385
5386
5387
5388
5389
5390
5391
5392







-
+







		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": override-redirect flag is set",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE",
			"OVERRIDE_REDIRECT", NULL);
		return TCL_ERROR;
	    }
	    if (wmPtr->containerPtr != NULL) {
	    if (wmPtr->masterPtr != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"can't iconify \"%s\": it is a transient",
			winPtr->pathName));
		Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "TRANSIENT",
			NULL);
		return TCL_ERROR;
	    }
5322
5323
5324
5325
5326
5327
5328
5329

5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340

5341
5342
5343
5344
5345
5346
5347
5404
5405
5406
5407
5408
5409
5410

5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421

5422
5423
5424
5425
5426
5427
5428
5429







-
+










-
+








	if (wmPtr->iconFor != NULL) {
	    stateStr = "icon";
	} else {
	    int state;

	    if (winPtr->flags & TK_EMBEDDED) {
		state = SendMessageW(wmPtr->wrapper, TK_STATE, -1, -1) - 1;
		state = SendMessage(wmPtr->wrapper, TK_STATE, -1, -1) - 1;
	    } else {
		state = wmPtr->hints.initial_state;
	    }
	    switch (state) {
	    case NormalState:	stateStr = "normal";	break;
	    case IconicState:	stateStr = "iconic";	break;
	    case WithdrawnState: stateStr = "withdrawn"; break;
	    case ZoomState:	stateStr = "zoomed";	break;
	    }
	}
	Tcl_SetObjResult(interp, Tcl_NewStringObj(stateStr, TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj(stateStr, -1));
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
5357
5358
5359
5360
5361
5362
5363
5364

5365
5366
5367

5368
5369
5370

5371
5372

5373
5374
5375
5376
5377
5378
5379
5380
5381

5382
5383
5384
5385
5386
5387

5388
5389
5390
5391
5392


5393
5394
5395
5396
5397
5398
5399
5400

5401
5402
5403
5404
5405
5406
5407



5408
5409
5410
5411
5412
5413

5414
5415

5416
5417
5418
5419
5420
5421
5422
5439
5440
5441
5442
5443
5444
5445

5446
5447
5448

5449
5450
5451

5452
5453

5454
5455
5456
5457
5458
5459
5460
5461
5462

5463
5464
5465
5466
5467
5468

5469
5470
5471
5472


5473
5474

5475
5476
5477
5478
5479
5480

5481
5482
5483
5484
5485
5486


5487
5488
5489
5490
5491
5492
5493
5494

5495


5496
5497
5498
5499
5500
5501
5502
5503







-
+


-
+


-
+

-
+








-
+





-
+



-
-
+
+
-






-
+





-
-
+
+
+





-
+
-
-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmTitleCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    const char *argv3;
    Tcl_Size length;
    size_t length;
    HWND wrapper;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?newTitle?");
	return TCL_ERROR;
    }

    if (winPtr->flags & TK_EMBEDDED) {
	wrapper = (HWND) SendMessageW(wmPtr->wrapper, TK_GETFRAMEWID, 0, 0);
	wrapper = (HWND) SendMessage(wmPtr->wrapper, TK_GETFRAMEWID, 0, 0);
    } else {
	wrapper = wmPtr->wrapper;
    }
    if (objc == 3) {
	if (wrapper) {
	    WCHAR buf[256];
	    TCHAR buf[256];
	    Tcl_DString titleString;
	    int size = 256;

	    GetWindowTextW(wrapper, buf, size);
	    Tcl_DStringInit(&titleString);
	    GetWindowText(wrapper, buf, size);
	    Tcl_WinTCharToUtf(buf, -1, &titleString);
	    Tcl_WCharToUtfDString(buf, wcslen(buf), &titleString);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    Tcl_DStringValue(&titleString),
		    Tcl_DStringLength(&titleString)));
	    Tcl_DStringFree(&titleString);
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    (wmPtr->title ? wmPtr->title : winPtr->nameUid), TCL_INDEX_NONE));
		    (wmPtr->title ? wmPtr->title : winPtr->nameUid), -1));
	}
    } else {
	if (wmPtr->title != NULL) {
	    ckfree(wmPtr->title);
	}
	argv3 = Tcl_GetStringFromObj(objv[3], &length);
	wmPtr->title = (char *)ckalloc(length + 1);
	argv3 = Tcl_GetString(objv[3]);
	length = objv[3]->length;
	wmPtr->title = ckalloc(length + 1);
	memcpy(wmPtr->title, argv3, length + 1);

	if (!(wmPtr->flags & WM_NEVER_MAPPED) && wmPtr->wrapper != NULL) {
	    Tcl_DString titleString;

	    Tcl_DStringInit(&titleString);
	    Tcl_WinUtfToTChar(wmPtr->title, -1, &titleString);
	    Tcl_UtfToWCharDString(wmPtr->title, TCL_INDEX_NONE, &titleString);
	    SetWindowTextW(wrapper, (LPCWSTR) Tcl_DStringValue(&titleString));
	    SetWindowText(wrapper, (LPCTSTR) Tcl_DStringValue(&titleString));
	    Tcl_DStringFree(&titleString);
	}
    }
    return TCL_OK;
}

/*
5437
5438
5439
5440
5441
5442
5443
5444

5445
5446
5447
5448


5449
5450
5451
5452

5453
5454
5455
5456
5457


5458
5459
5460
5461
5462

5463
5464

5465
5466
5467
5468
5469


5470
5471
5472
5473
5474

5475
5476
5477

5478
5479
5480

5481
5482

5483
5484
5485

5486
5487

5488
5489
5490
5491
5492
5493
5494
5495
5496
5497

5498
5499
5500
5501

5502
5503
5504
5505
5506

5507
5508
5509


5510
5511
5512
5513



5514
5515
5516

5517
5518
5519
5520



5521
5522
5523
5524
5525



5526
5527
5528
5529
5530
5531


5532
5533
5534
5535

5536
5537
5538
5539
5540
5541


5542
5543
5544
5545
5546
5547
5548
5518
5519
5520
5521
5522
5523
5524

5525
5526
5527


5528
5529
5530
5531
5532

5533
5534
5535
5536


5537
5538
5539
5540
5541
5542

5543
5544

5545
5546
5547
5548


5549
5550
5551
5552
5553
5554

5555
5556
5557

5558
5559
5560

5561
5562

5563
5564
5565

5566
5567

5568
5569
5570
5571
5572
5573
5574
5575
5576
5577

5578
5579
5580
5581

5582
5583
5584
5585
5586

5587



5588
5589




5590
5591
5592



5593
5594



5595
5596
5597
5598
5599



5600
5601
5602
5603
5604
5605
5606


5607
5608
5609
5610
5611

5612
5613
5614
5615
5616


5617
5618
5619
5620
5621
5622
5623
5624
5625







-
+


-
-
+
+



-
+



-
-
+
+




-
+

-
+



-
-
+
+




-
+


-
+


-
+

-
+


-
+

-
+









-
+



-
+




-
+
-
-
-
+
+
-
-
-
-
+
+
+
-
-
-
+

-
-
-
+
+
+


-
-
-
+
+
+




-
-
+
+



-
+




-
-
+
+







 */

static int
WmTransientCmd(
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow *containerPtr = wmPtr->containerPtr, **containerPtrPtr = &containerPtr, *w;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    TkWindow *masterPtr = wmPtr->masterPtr, **masterPtrPtr = &masterPtr;
    WmInfo *wmPtr2;

    if ((objc != 3) && (objc != 4)) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?window?");
	Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
	return TCL_ERROR;
    }
    if (objc == 3) {
	if (containerPtr != NULL) {
	    Tcl_SetObjResult(interp, Tk_NewWindowObj((Tk_Window) containerPtr));
	if (masterPtr != NULL) {
	    Tcl_SetObjResult(interp, TkNewWindowObj((Tk_Window) masterPtr));
	}
	return TCL_OK;
    }
    if (Tcl_GetString(objv[3])[0] == '\0') {
	if (containerPtr != NULL) {
	if (masterPtr != NULL) {
	    /*
	     * If we had a container, tell them that we aren't tied to them
	     * If we had a master, tell them that we aren't tied to them
	     * anymore.
	     */

	    containerPtr->wmInfoPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) containerPtr,
	    masterPtr->wmInfoPtr->numTransients--;
	    Tk_DeleteEventHandler((Tk_Window) masterPtr,
		    VisibilityChangeMask|StructureNotifyMask,
		    WmWaitVisibilityOrMapProc, winPtr);
	}

	wmPtr->containerPtr = NULL;
	wmPtr->masterPtr = NULL;
    } else {
	if (TkGetWindowFromObj(interp, tkwin, objv[3],
		(Tk_Window *) containerPtrPtr) != TCL_OK) {
		(Tk_Window *) masterPtrPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
	while (!Tk_TopWinHierarchy(containerPtr)) {
	while (!Tk_TopWinHierarchy(masterPtr)) {
	    /*
	     * Ensure that the container window is actually a Tk toplevel.
	     * Ensure that the master window is actually a Tk toplevel.
	     */

	    containerPtr = containerPtr->parentPtr;
	    masterPtr = masterPtr->parentPtr;
	}
	Tk_MakeWindowExist((Tk_Window) containerPtr);
	Tk_MakeWindowExist((Tk_Window) masterPtr);

	if (wmPtr->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a transient: it is an icon for %s",
		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}

	wmPtr2 = containerPtr->wmInfoPtr;
	wmPtr2 = masterPtr->wmInfoPtr;

	if (wmPtr2->iconFor != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't make \"%s\" a container: it is an icon for %s",
		    "can't make \"%s\" a master: it is an icon for %s",
		    Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
	    return TCL_ERROR;
	}
	for (w = containerPtr; w != NULL && w->wmInfoPtr != NULL;

	    w = (TkWindow *)w->wmInfoPtr->containerPtr) {
	    if (w == winPtr) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	if (masterPtr == winPtr) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't set \"%s\" as container: would cause management loop",
		    Tk_PathName(containerPtr)));
		Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
		return TCL_ERROR;
		    "can't make \"%s\" its own master", Tk_PathName(winPtr)));
	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
	    return TCL_ERROR;
	    }
	}
	if (containerPtr != wmPtr->containerPtr) {
	} else if (masterPtr != wmPtr->masterPtr) {
	    /*
	     * Remove old container map/unmap binding before setting the new
	     * container. The event handler will ensure that transient states
	     * reflect the state of the container.
	     * Remove old master map/unmap binding before setting the new
	     * master. The event handler will ensure that transient states
	     * reflect the state of the master.
	     */

	    if (wmPtr->containerPtr != NULL) {
		wmPtr->containerPtr->wmInfoPtr->numTransients--;
		Tk_DeleteEventHandler((Tk_Window) wmPtr->containerPtr,
	    if (wmPtr->masterPtr != NULL) {
		wmPtr->masterPtr->wmInfoPtr->numTransients--;
		Tk_DeleteEventHandler((Tk_Window) wmPtr->masterPtr,
			VisibilityChangeMask|StructureNotifyMask,
			WmWaitVisibilityOrMapProc, winPtr);
	    }

	    containerPtr->wmInfoPtr->numTransients++;
	    Tk_CreateEventHandler((Tk_Window) containerPtr,
	    masterPtr->wmInfoPtr->numTransients++;
	    Tk_CreateEventHandler((Tk_Window) masterPtr,
		    VisibilityChangeMask|StructureNotifyMask,
		    WmWaitVisibilityOrMapProc, winPtr);

	    wmPtr->containerPtr = containerPtr;
	    wmPtr->masterPtr = masterPtr;
	}
    }
    if (!((wmPtr->flags & WM_NEVER_MAPPED)
	    && !(winPtr->flags & TK_EMBEDDED))) {
	if (wmPtr->containerPtr != NULL
		&& !Tk_IsMapped(wmPtr->containerPtr)) {
	if (wmPtr->masterPtr != NULL
		&& !Tk_IsMapped(wmPtr->masterPtr)) {
	    TkpWmSetState(winPtr, WithdrawnState);
	} else {
	    UpdateWrapper(winPtr);
	}
    }
    return TCL_OK;
}
5562
5563
5564
5565
5566
5567
5568
5569

5570
5571
5572

5573
5574
5575

5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590

5591
5592
5593
5594
5595
5596
5597
5639
5640
5641
5642
5643
5644
5645

5646
5647
5648

5649
5650
5651

5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666

5667
5668
5669
5670
5671
5672
5673
5674







-
+


-
+


-
+














-
+







 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
WmWithdrawCmd(
    TCL_UNUSED(Tk_Window),	/* Main window of the application. */
    Tk_Window tkwin,		/* Main window of the application. */
    TkWindow *winPtr,		/* Toplevel to work with */
    Tcl_Interp *interp,		/* Current interpreter. */
    Tcl_Size objc,			/* Number of arguments. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "window");
	return TCL_ERROR;
    }
    if (wmPtr->iconFor != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"can't withdraw %s: it is an icon for %s",
		Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
	Tcl_SetErrorCode(interp, "TK", "WM", "WITHDRAW", "ICON", NULL);
	return TCL_ERROR;
    }

    if (winPtr->flags & TK_EMBEDDED) {
	if (SendMessageW(wmPtr->wrapper, TK_WITHDRAW, 0, 0) < 0) {
	if (SendMessage(wmPtr->wrapper, TK_WITHDRAW, 0, 0) < 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "can't withdraw %s: the container does not support the request",
		    Tcl_GetString(objv[2])));
	    Tcl_SetErrorCode(interp, "TK", "WM", "COMMUNICATION", NULL);
	    return TCL_ERROR;
	}
    } else {
5613
5614
5615
5616
5617
5618
5619

5620
5621
5622

5623
5624
5625
5626


5627
5628

5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640

5641
5642
5643
5644
5645
5646
5647
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699

5700
5701
5702


5703
5704
5705

5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717

5718
5719
5720
5721
5722
5723
5724
5725







+


-
+


-
-
+
+

-
+











-
+







{
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
}

	/*ARGSUSED*/
static void
WmWaitVisibilityOrMapProc(
    void *clientData,	/* Pointer to window. */
    ClientData clientData,	/* Pointer to window. */
    XEvent *eventPtr)		/* Information about event. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    TkWindow *containerPtr = winPtr->wmInfoPtr->containerPtr;
    TkWindow *winPtr = clientData;
    TkWindow *masterPtr = winPtr->wmInfoPtr->masterPtr;

    if (containerPtr == NULL)
    if (masterPtr == NULL)
	return;

    if (eventPtr->type == MapNotify) {
	if (!(winPtr->wmInfoPtr->flags & WM_WITHDRAWN)) {
	    TkpWmSetState(winPtr, NormalState);
	}
    } else if (eventPtr->type == UnmapNotify) {
	TkpWmSetState(winPtr, WithdrawnState);
    }

    if (eventPtr->type == VisibilityNotify) {
	int state = containerPtr->wmInfoPtr->hints.initial_state;
	int state = masterPtr->wmInfoPtr->hints.initial_state;

	if ((state == NormalState) || (state == ZoomState)) {
	    state = winPtr->wmInfoPtr->hints.initial_state;
	    if ((state == NormalState) || (state == ZoomState)) {
		UpdateWrapper(winPtr);
	    }
	}
5679
5680
5681
5682
5683
5684
5685
5686

5687
5688
5689
5690
5691
5692
5693
5757
5758
5759
5760
5761
5762
5763

5764
5765
5766
5767
5768
5769
5770
5771







-
+







				 * requested geometry for tkwin. */
    int reqHeight,		/* Height (in grid units) corresponding to the
				 * requested geometry for tkwin. */
    int widthInc, int heightInc)/* Pixel increments corresponding to a change
				 * of one grid unit. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;
    register WmInfo *wmPtr;

    /*
     * Ensure widthInc and heightInc are greater than 0
     */

    if (widthInc <= 0) {
	widthInc = 1;
5713
5714
5715
5716
5717
5718
5719
5720


5721
5722
5723
5724
5725
5726
5727
5791
5792
5793
5794
5795
5796
5797

5798
5799
5800
5801
5802
5803
5804
5805
5806







-
+
+







	return;
    }

    if ((wmPtr->reqGridWidth == reqWidth)
	    && (wmPtr->reqGridHeight == reqHeight)
	    && (wmPtr->widthInc == widthInc)
	    && (wmPtr->heightInc == heightInc)
	    && ((wmPtr->sizeHintsFlags & PBaseSize) == PBaseSize)) {
	    && ((wmPtr->sizeHintsFlags & (PBaseSize|PResizeInc))
		    == (PBaseSize|PResizeInc))) {
	return;
    }

    /*
     * If gridding was previously off, then forget about any window size
     * requests made by the user or via "wm geometry": these are in pixel
     * units and there's no easy way to translate them to grid units since the
5744
5745
5746
5747
5748
5749
5750
5751

5752
5753
5754
5755
5756
5757
5758
5823
5824
5825
5826
5827
5828
5829

5830
5831
5832
5833
5834
5835
5836
5837







-
+







     */

    wmPtr->gridWin = tkwin;
    wmPtr->reqGridWidth = reqWidth;
    wmPtr->reqGridHeight = reqHeight;
    wmPtr->widthInc = widthInc;
    wmPtr->heightInc = heightInc;
    wmPtr->sizeHintsFlags |= PBaseSize;
    wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc;
    if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	wmPtr->flags |= WM_UPDATE_PENDING;
    }
}

/*
5775
5776
5777
5778
5779
5780
5781
5782

5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802

5803
5804
5805
5806
5807
5808
5809
5854
5855
5856
5857
5858
5859
5860

5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880

5881
5882
5883
5884
5885
5886
5887
5888







-
+



















-
+








void
Tk_UnsetGrid(
    Tk_Window tkwin)		/* Token for window that is currently
				 * controlling gridding. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;
    register WmInfo *wmPtr;

    /*
     * Find the top-level window for tkwin, plus the window manager
     * information.
     */

    while (!(winPtr->flags & TK_TOP_HIERARCHY)) {
	winPtr = winPtr->parentPtr;
    }
    wmPtr = winPtr->wmInfoPtr;
    if (wmPtr == NULL) {
	return;
    }

    if (tkwin != wmPtr->gridWin) {
	return;
    }

    wmPtr->gridWin = NULL;
    wmPtr->sizeHintsFlags &= ~PBaseSize;
    wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
    if (wmPtr->width != -1) {
	wmPtr->width = winPtr->reqWidth + (wmPtr->width
		- wmPtr->reqGridWidth)*wmPtr->widthInc;
	wmPtr->height = winPtr->reqHeight + (wmPtr->height
		- wmPtr->reqGridHeight)*wmPtr->heightInc;
    }
    wmPtr->widthInc = 1;
5831
5832
5833
5834
5835
5836
5837
5838

5839
5840
5841

5842
5843
5844
5845
5846
5847
5848
5910
5911
5912
5913
5914
5915
5916

5917
5918
5919

5920
5921
5922
5923
5924
5925
5926
5927







-
+


-
+







 *	the structural change.
 *
 *----------------------------------------------------------------------
 */

static void
TopLevelEventProc(
    void *clientData,	/* Window for which event occurred. */
    ClientData clientData,	/* Window for which event occurred. */
    XEvent *eventPtr)		/* Event that just happened. */
{
    TkWindow *winPtr = (TkWindow *)clientData;
    register TkWindow *winPtr = clientData;

    if (eventPtr->type == DestroyNotify) {
	Tk_ErrorHandler handler;

	if (!(winPtr->flags & TK_ALREADY_DEAD)) {
	    /*
	     * A top-level window was deleted externally (e.g., by the window
5874
5875
5876
5877
5878
5879
5880

5881
5882
5883

5884
5885
5886
5887
5888
5889
5890
5891
5892

5893
5894
5895
5896
5897
5898
5899
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962

5963
5964
5965
5966
5967
5968
5969
5970
5971

5972
5973
5974
5975
5976
5977
5978
5979







+


-
+








-
+







 * Side effects:
 *	Arrange for the window to be resized to satisfy the request (this
 *	happens as a when-idle action).
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
static void
TopLevelReqProc(
    TCL_UNUSED(void *),		/* Not used. */
    ClientData dummy,		/* Not used. */
    Tk_Window tkwin)		/* Information about window. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr;

    wmPtr = winPtr->wmInfoPtr;
    if (wmPtr) {
	if ((winPtr->flags & TK_EMBEDDED) && (wmPtr->wrapper != NULL)) {
	    SendMessageW(wmPtr->wrapper, TK_GEOMETRYREQ, Tk_ReqWidth(tkwin),
	    SendMessage(wmPtr->wrapper, TK_GEOMETRYREQ, Tk_ReqWidth(tkwin),
		Tk_ReqHeight(tkwin));
	}
	if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	    Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	    wmPtr->flags |= WM_UPDATE_PENDING;
	}
    }
5918
5919
5920
5921
5922
5923
5924
5925

5926
5927
5928
5929
5930
5931
5932


5933
5934
5935
5936
5937
5938
5939
5998
5999
6000
6001
6002
6003
6004

6005
6006
6007
6008
6009
6010


6011
6012
6013
6014
6015
6016
6017
6018
6019







-
+





-
-
+
+







 *	from happening.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateGeometryInfo(
    void *clientData)	/* Pointer to the window's record. */
    ClientData clientData)	/* Pointer to the window's record. */
{
    int x, y;			/* Position of border on desktop. */
    int width, height;		/* Size of client area. */
    int min, max;
    RECT rect;
    TkWindow *winPtr = (TkWindow *)clientData;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register TkWindow *winPtr = clientData;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    wmPtr->flags &= ~WM_UPDATE_PENDING;

    /*
     * If the window is minimized or maximized, we should not update our
     * geometry since it will end up with the wrong values. ConfigureToplevel
     * will reschedule UpdateGeometryInfo when the state of the window
6097
6098
6099
6100
6101
6102
6103
6104
6105


6106
6107
6108
6109
6110
6111
6112
6177
6178
6179
6180
6181
6182
6183


6184
6185
6186
6187
6188
6189
6190
6191
6192







-
-
+
+







	/*
	 * The wrapper window is in a different process, so we need to send it
	 * a geometry request. This protocol assumes that the other process
	 * understands this Tk message, otherwise our requested geometry will
	 * be ignored.
	 */

	SendMessageW(wmPtr->wrapper, TK_MOVEWINDOW, x, y);
	SendMessageW(wmPtr->wrapper, TK_GEOMETRYREQ, width, height);
	SendMessage(wmPtr->wrapper, TK_MOVEWINDOW, x, y);
	SendMessage(wmPtr->wrapper, TK_GEOMETRYREQ, width, height);
    } else {
	int reqHeight, reqWidth;
	RECT windowRect;
	int menuInc = GetSystemMetrics(SM_CYMENU);
	int newHeight;

	/*
6205
6206
6207
6208
6209
6210
6211
6212

6213
6214
6215

6216
6217
6218
6219
6220
6221
6222
6285
6286
6287
6288
6289
6290
6291

6292
6293
6294

6295
6296
6297
6298
6299
6300
6301
6302







-
+


-
+







ParseGeometry(
    Tcl_Interp *interp,		/* Used for error reporting. */
    const char *string,		/* String containing new geometry. Has the
				 * standard form "=wxh+x+y". */
    TkWindow *winPtr)		/* Pointer to top-level window whose geometry
				 * is to be changed. */
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;
    int x, y, width, height, flags;
    char *end;
    const char *p = string;
    register const char *p = string;

    /*
     * The leading "=" is optional.
     */

    if (*p == '=') {
	p++;
6337
6338
6339
6340
6341
6342
6343
6344

6345
6346
6347
6348
6349
6350
6351
6417
6418
6419
6420
6421
6422
6423

6424
6425
6426
6427
6428
6429
6430
6431







-
+








void
Tk_GetRootCoords(
    Tk_Window tkwin,		/* Token for window. */
    int *xPtr,			/* Where to store x-displacement of (0,0). */
    int *yPtr)			/* Where to store y-displacement of (0,0). */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    register TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * If the window is mapped, let Windows figure out the translation.
     */

    if (winPtr->window != None) {
	HWND hwnd = Tk_GetHWND(winPtr->window);
6427
6428
6429
6430
6431
6432
6433
6434

6435
6436
6437
6438
6439
6440
6441
6507
6508
6509
6510
6511
6512
6513

6514
6515
6516
6517
6518
6519
6520
6521







-
+







 *	Vroot window information is refreshed if it is out of date.
 *
 *----------------------------------------------------------------------
 */

void
Tk_GetVRootGeometry(
    TCL_UNUSED(Tk_Window),/* Window whose virtual root is to be
    Tk_Window tkwin,		/* Window whose virtual root is to be
				 * queried. */
    int *xPtr, int *yPtr,	/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr, int *heightPtr)
				/* Store dimensions of virtual root here. */
{
    *xPtr = GetSystemMetrics(SM_XVIRTUALSCREEN);
6466
6467
6468
6469
6470
6471
6472
6473

6474
6475
6476
6477
6478
6479
6480
6546
6547
6548
6549
6550
6551
6552

6553
6554
6555
6556
6557
6558
6559
6560







-
+








void
Tk_MoveToplevelWindow(
    Tk_Window tkwin,		/* Window to move. */
    int x, int y)		/* New location for window (within parent). */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!(winPtr->flags & TK_TOP_LEVEL)) {
	Tcl_Panic("Tk_MoveToplevelWindow called with non-toplevel window");
    }
    wmPtr->x = x;
    wmPtr->y = y;
    wmPtr->flags |= WM_MOVE_PENDING;
6517
6518
6519
6520
6521
6522
6523
6524

6525
6526
6527
6528
6529
6530
6531
6597
6598
6599
6600
6601
6602
6603

6604
6605
6606
6607
6608
6609
6610
6611







-
+








void
TkWmProtocolEventProc(
    TkWindow *winPtr,		/* Window to which the event was sent. */
    XEvent *eventPtr)		/* X event. */
{
    WmInfo *wmPtr;
    ProtocolHandler *protPtr;
    register ProtocolHandler *protPtr;
    Atom protocol;
    int result;
    Tcl_Interp *interp;

    wmPtr = winPtr->wmInfoPtr;
    if (wmPtr == NULL) {
	return;
6540
6541
6542
6543
6544
6545
6546
6547

6548
6549
6550
6551
6552
6553
6554
6620
6621
6622
6623
6624
6625
6626

6627
6628
6629
6630
6631
6632
6633
6634







-
+







	     */

	    const char *name = Tk_GetAtomName((Tk_Window) winPtr, protocol);

	    Tcl_Preserve(protPtr);
	    interp = protPtr->interp;
	    Tcl_Preserve(interp);
	    result = Tcl_EvalEx(interp, protPtr->command, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
	    result = Tcl_EvalEx(interp, protPtr->command, -1, TCL_EVAL_GLOBAL);
	    if (result != TCL_OK) {
		Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
			"\n    (command for \"%s\" window manager protocol)",
			name));
		Tcl_BackgroundException(interp, result);
	    }
	    Tcl_Release(interp);
6593
6594
6595
6596
6597
6598
6599
6600

6601
6602

6603
6604
6605
6606
6607
6608
6609
6673
6674
6675
6676
6677
6678
6679

6680
6681

6682
6683
6684
6685
6686
6687
6688
6689







-
+

-
+







    TkWindow *childWinPtr;

    TkWmStackorderToplevelPair *pair =
	    (TkWmStackorderToplevelPair *) lParam;

    /*fprintf(stderr, "Looking up HWND %d\n", hwnd);*/

    hPtr = Tcl_FindHashEntry(pair->table, hwnd);
    hPtr = Tcl_FindHashEntry(pair->table, (char *) hwnd);
    if (hPtr != NULL) {
	childWinPtr = (TkWindow *)Tcl_GetHashValue(hPtr);
	childWinPtr = Tcl_GetHashValue(hPtr);

	/*
	 * Double check that same HWND does not get passed twice.
	 */

	if (childWinPtr == NULL) {
	    Tcl_Panic("duplicate HWND in TkWmStackorderToplevelEnumProc");
6695
6696
6697
6698
6699
6700
6701
6702

6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715

6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733


6734
6735
6736
6737
6738
6739
6740
6775
6776
6777
6778
6779
6780
6781

6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794

6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822







-
+












-
+


















+
+







    /*
     * Map HWND ids to a TkWindow of the wrapped toplevel.
     */

    Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
    TkWmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);

    windows = (TkWindow **)ckalloc((table.numEntries+1) * sizeof(TkWindow *));
    windows = ckalloc((table.numEntries+1) * sizeof(TkWindow *));

    /*
     * Special cases: If zero or one toplevels were mapped there is no need to
     * call EnumWindows.
     */

    switch (table.numEntries) {
    case 0:
	windows[0] = NULL;
	goto done;
    case 1:
	hPtr = Tcl_FirstHashEntry(&table, &search);
	windows[0] = (TkWindow *)Tcl_GetHashValue(hPtr);
	windows[0] = Tcl_GetHashValue(hPtr);
	windows[1] = NULL;
	goto done;
    }

    /*
     * We will be inserting into the array starting at the end and working our
     * way to the beginning since EnumWindows returns windows in highest to
     * lowest order.
     */

    pair.table = &table;
    pair.windowPtr = windows + table.numEntries;
    *pair.windowPtr-- = NULL;

    if (EnumWindows((WNDENUMPROC) TkWmStackorderToplevelEnumProc,
	    (LPARAM) &pair) == 0) {
	ckfree(windows);
	windows = NULL;
    } else if (pair.windowPtr != (windows-1)) {
	Tcl_Panic("num matched toplevel windows does not equal num children");
    }

  done:
    Tcl_DeleteHashTable(&table);
    return windows;
}

6791
6792
6793
6794
6795
6796
6797
6798

6799
6800
6801
6802
6803
6804
6805
6873
6874
6875
6876
6877
6878
6879

6880
6881
6882
6883
6884
6885
6886
6887







-
+







	insertAfter = (otherPtr->wmInfoPtr->wrapper != NULL)
		? otherPtr->wmInfoPtr->wrapper : Tk_GetHWND(otherPtr->window);
    } else {
	insertAfter = NULL;
    }

    if (winPtr->flags & TK_EMBEDDED) {
	SendMessageW(winPtr->wmInfoPtr->wrapper, TK_RAISEWINDOW,
	SendMessage(winPtr->wmInfoPtr->wrapper, TK_RAISEWINDOW,
		(WPARAM) insertAfter, aboveBelow);
    } else {
	TkWinSetWindowPos(hwnd, insertAfter, aboveBelow);
    }
}

/*
6871
6872
6873
6874
6875
6876
6877
6878

6879
6880
6881
6882
6883
6884
6885
6953
6954
6955
6956
6957
6958
6959

6960
6961
6962
6963
6964
6965
6966
6967







-
+







    }

    /*
     * Make a new bigger array and use it to reset the property.
     * Automatically add the toplevel itself as the last element of the list.
     */

    newPtr = (TkWindow **)ckalloc((count+2) * sizeof(TkWindow *));
    newPtr = ckalloc((count+2) * sizeof(TkWindow *));
    if (count > 0) {
	memcpy(newPtr, oldPtr, count * sizeof(TkWindow*));
    }
    if (count == 0) {
	count++;
    }
    newPtr[count-1] = winPtr;
7017
7018
7019
7020
7021
7022
7023
7024

7025
7026
7027
7028
7029
7030
7031
7099
7100
7101
7102
7103
7104
7105

7106
7107
7108
7109
7110
7111
7112
7113







-
+







    }
    if (!(winPtr->flags & TK_EMBEDDED)) {
	if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
	    Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
	    wmPtr->flags |= WM_UPDATE_PENDING|WM_MOVE_PENDING;
	}
    } else {
	SendMessageW(wmPtr->wrapper, TK_SETMENU, (WPARAM) hMenu,
	SendMessage(wmPtr->wrapper, TK_SETMENU, (WPARAM) hMenu,
		(LPARAM) Tk_GetMenuHWND(tkwin));
    }
}

/*
 *----------------------------------------------------------------------
 *
7253
7254
7255
7256
7257
7258
7259
7260

7261
7262
7263
7264
7265
7266
7267
7335
7336
7337
7338
7339
7340
7341

7342
7343
7344
7345
7346
7347
7348
7349







-
+







    XEvent event;

    /*
     * Generate a ConfigureNotify event.
     */

    event.type = ConfigureNotify;
    event.xconfigure.serial = LastKnownRequestProcessed(winPtr->display);
    event.xconfigure.serial = winPtr->display->request;
    event.xconfigure.send_event = False;
    event.xconfigure.display = winPtr->display;
    event.xconfigure.event = winPtr->window;
    event.xconfigure.window = winPtr->window;
    event.xconfigure.border_width = winPtr->changes.border_width;
    event.xconfigure.override_redirect = winPtr->atts.override_redirect;
    event.xconfigure.x = winPtr->changes.x;
7293
7294
7295
7296
7297
7298
7299
7300

7301
7302
7303
7304
7305
7306
7307
7375
7376
7377
7378
7379
7380
7381

7382
7383
7384
7385
7386
7387
7388
7389







-
+







InstallColormaps(
    HWND hwnd,			/* Toplevel wrapper window whose colormaps
				 * should be installed. */
    int message,		/* Either WM_PALETTECHANGED or
				 * WM_QUERYNEWPALETTE */
    int isForemost)		/* 1 if window is foremost, else 0 */
{
    Tcl_Size i;
    int i;
    HDC dc;
    HPALETTE oldPalette;
    TkWindow *winPtr = GetTopLevel(hwnd);
    WmInfo *wmPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

7331
7332
7333
7334
7335
7336
7337
7338

7339
7340
7341
7342
7343
7344
7345
7413
7414
7415
7416
7417
7418
7419

7420
7421
7422
7423
7424
7425
7426
7427







-
+







	oldPalette = SelectPalette(dc, tsdPtr->systemPalette, FALSE);
	if (RealizePalette(dc)) {
	    RefreshColormap(winPtr->atts.colormap, winPtr->dispPtr);
	} else if (wmPtr->cmapCount > 1) {
	    SelectPalette(dc, oldPalette, TRUE);
	    RealizePalette(dc);
	    ReleaseDC(hwnd, dc);
	    SendMessageW(hwnd, WM_PALETTECHANGED, (WPARAM) hwnd, (LPARAM) NULL);
	    SendMessage(hwnd, WM_PALETTECHANGED, (WPARAM) hwnd, (LPARAM) NULL);
	    return TRUE;
	}
    } else {
	/*
	 * Window is being notified of a change in the system palette. If this
	 * window is the foreground window, then we should only install the
	 * secondary palettes, since the primary was installed in response to
7402
7403
7404
7405
7406
7407
7408
7409

7410
7411
7412
7413
7414
7415
7416
7484
7485
7486
7487
7488
7489
7490

7491
7492
7493
7494
7495
7496
7497
7498







-
+








static void
RefreshColormap(
    Colormap colormap,
    TkDisplay *dispPtr)
{
    WmInfo *wmPtr;
    Tcl_Size i;
    int i;

    for (wmPtr = dispPtr->firstWmPtr; wmPtr != NULL; wmPtr = wmPtr->nextPtr) {
	if (wmPtr->cmapCount > 0) {
	    for (i = 0; i < wmPtr->cmapCount; i++) {
		if ((wmPtr->cmapList[i]->atts.colormap == colormap)
			&& Tk_IsMapped(wmPtr->cmapList[i])) {
		    InvalidateSubTree(wmPtr->cmapList[i], colormap);
7727
7728
7729
7730
7731
7732
7733
7734

7735
7736
7737
7738
7739
7740
7741
7809
7810
7811
7812
7813
7814
7815

7816
7817
7818
7819
7820
7821
7822
7823







-
+







	 */

	if (!(pos->flags & SWP_NOSIZE)) {
	    winPtr->changes.width = pos->cx;
	    winPtr->changes.height = pos->cy;
	}
	if (!(pos->flags & SWP_NOMOVE)) {
	    long result = SendMessageW(winPtr->wmInfoPtr->wrapper,
	    long result = SendMessage(winPtr->wmInfoPtr->wrapper,
		    TK_MOVEWINDOW, -1, -1);
	    winPtr->wmInfoPtr->x = winPtr->changes.x = result >> 16;
	    winPtr->wmInfoPtr->y = winPtr->changes.y = result & 0xffff;
	}

	GenerateConfigureNotify(winPtr);

7829
7830
7831
7832
7833
7834
7835
7836

7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851



7852
7853

7854
7855
7856
7857
7858
7859
7860
7911
7912
7913
7914
7915
7916
7917

7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930



7931
7932
7933
7934

7935
7936
7937
7938
7939
7940
7941
7942







-
+












-
-
-
+
+
+

-
+







	/*
	 * Display and/or color resolution changed.
	 */

	winPtr = GetTopLevel(hwnd);
	if (winPtr) {
	    Screen *screen = Tk_Screen(winPtr);
	    if (DefaultDepthOfScreen(screen) != (int) wParam) {
	    if (screen->root_depth != (int) wParam) {
		/*
		 * Color resolution changed, so do extensive rebuild of
		 * display parameters. This will affect the display for all Tk
		 * windows. We will receive this event for each toplevel, but
		 * this check makes us update only once, for the first
		 * toplevel that receives the message.
		 */

		TkWinDisplayChanged(Tk_Display(winPtr));
	    } else {
		HDC dc = GetDC(NULL);

		WidthOfScreen(screen) = LOWORD(lParam);		/* horizontal res */
		HeightOfScreen(screen) = HIWORD(lParam);	/* vertical res */
		WidthMMOfScreen(screen) = MulDiv(WidthOfScreen(screen), 254,
		screen->width = LOWORD(lParam);		/* horizontal res */
		screen->height = HIWORD(lParam);	/* vertical res */
		screen->mwidth = MulDiv(screen->width, 254,
			GetDeviceCaps(dc, LOGPIXELSX) * 10);
		HeightMMOfScreen(screen) = MulDiv(HeightOfScreen(screen), 254,
		screen->mheight = MulDiv(screen->height, 254,
			GetDeviceCaps(dc, LOGPIXELSY) * 10);
		ReleaseDC(NULL, dc);
	    }
	    if (Tk_Depth(winPtr) != (int) wParam) {
		/*
		 * Defer the window depth check to here so that each toplevel
		 * will properly update depth info.
7897
7898
7899
7900
7901
7902
7903
7904

7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925

7926
7927
7928
7929
7930
7931
7932
7979
7980
7981
7982
7983
7984
7985

7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006

8007
8008
8009
8010
8011
8012
8013
8014







-
+




















-
+







	result = 0;
	goto done;

    case WM_NCHITTEST: {
	winPtr = GetTopLevel(hwnd);
	if (winPtr && (TkGrabState(winPtr) == TK_GRAB_EXCLUDED)) {
	    /*
	     * This window is outside the grab hierarchy, so don't let any of
	     * This window is outside the grab heirarchy, so don't let any of
	     * the normal non-client processing occur. Note that this
	     * implementation is not strictly correct because the grab might
	     * change between now and when the event would have been processed
	     * by Tk, but it's close enough.
	     */

	    result = HTCLIENT;
	    goto done;
	}
	break;
    }

    case WM_MOUSEACTIVATE: {
	winPtr = GetTopLevel((HWND) wParam);
	if (winPtr && (TkGrabState(winPtr) != TK_GRAB_EXCLUDED)) {
	    /*
	     * This allows us to pass the message onto the native menus [Bug:
	     * 2272]
	     */

	    result = DefWindowProcW(hwnd, message, wParam, lParam);
	    result = DefWindowProc(hwnd, message, wParam, lParam);
	    goto done;
	}

	/*
	 * Don't activate the window yet since there is a grab that takes
	 * precedence. Instead we need to queue an event so we can check the
	 * grab state right before we handle the mouse event.
7995
7996
7997
7998
7999
8000
8001
8002

8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019

8020
8021

8022
8023
8024

8025
8026
8027
8028
8029
8030
8031
8077
8078
8079
8080
8081
8082
8083

8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100

8101
8102

8103
8104
8105

8106
8107
8108
8109
8110
8111
8112
8113







-
+
















-
+

-
+


-
+







    case WM_MENUSELECT:
    case WM_ENTERIDLE:
    case WM_INITMENUPOPUP:
	if (winPtr) {
	    HWND hMenuHWnd = Tk_GetEmbeddedMenuHWND((Tk_Window) winPtr);

	    if (hMenuHWnd) {
		if (SendMessageW(hMenuHWnd, message, wParam, lParam)) {
		if (SendMessage(hMenuHWnd, message, wParam, lParam)) {
		    goto done;
		}
	    } else if (TkWinHandleMenuEvent(&hwnd, &message, &wParam, &lParam,
		    &result)) {
		goto done;
	    }
	}
	break;
    }

    if (winPtr && winPtr->window) {
	HWND child = Tk_GetHWND(winPtr->window);

	if (message == WM_SETFOCUS) {
	    SetFocus(child);
	    result = 0;
	} else if (!TkTranslateWinEvent(child, message, wParam, lParam,
	} else if (!Tk_TranslateWinEvent(child, message, wParam, lParam,
		&result)) {
	    result = DefWindowProcW(hwnd, message, wParam, lParam);
	    result = DefWindowProc(hwnd, message, wParam, lParam);
	}
    } else {
	result = DefWindowProcW(hwnd, message, wParam, lParam);
	result = DefWindowProc(hwnd, message, wParam, lParam);
    }

  done:
    Tcl_ServiceAll();
    return result;
}

8167
8168
8169
8170
8171
8172
8173
8174

8175
8176
8177
8178
8179
8180
8181
8249
8250
8251
8252
8253
8254
8255

8256
8257
8258
8259
8260
8261
8262
8263







-
+







 *
 *	This function is called to activate a Tk window.
 */

static void
GenerateActivateEvent(TkWindow * winPtr, const int *flagPtr)
{
    ActivateEvent *eventPtr = (ActivateEvent *)ckalloc(sizeof(ActivateEvent));
    ActivateEvent *eventPtr = ckalloc(sizeof(ActivateEvent));

    eventPtr->ev.proc = ActivateWindow;
    eventPtr->winPtr = winPtr;
    eventPtr->flagPtr = flagPtr;
    eventPtr->hwnd = Tk_GetHWND(winPtr->window);
    Tcl_QueueEvent((Tcl_Event *)eventPtr, TCL_QUEUE_TAIL);
}
8216
8217
8218
8219
8220
8221
8222
8223

8224
8225
8226
8227
8228
8229
8230
8298
8299
8300
8301
8302
8303
8304

8305
8306
8307
8308
8309
8310
8311
8312







-
+







    if (!IsWindow(eventPtr->hwnd)) {
	return 1;
    }

    /*
     * If the toplevel is in the middle of a move or size operation then
     * we must delay handling of this event to avoid stealing the focus
     * while the window manager is in control.
     * while the window manage is in control.
     */

    if (eventPtr->flagPtr && *eventPtr->flagPtr) {
	return 0;
    }

    /*
8270
8271
8272
8273
8274
8275
8276
8277

8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291

8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307

8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318

8319
8320
8321
8322
8323
8324
8325
8352
8353
8354
8355
8356
8357
8358

8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372

8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388

8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399

8400
8401
8402
8403
8404
8405
8406
8407







-
+













-
+















-
+










-
+







 *----------------------------------------------------------------------
 */

void
TkWinSetForegroundWindow(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (wmPtr->wrapper != NULL) {
	SetForegroundWindow(wmPtr->wrapper);
    } else {
	SetForegroundWindow(Tk_GetHWND(winPtr->window));
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpWinToplevelWithdraw --
 *
 *	This function is to be used by a window manager to withdraw a toplevel
 *	This function is to be used by a window manage to withdraw a toplevel
 *	window.
 *
 * Results:
 *	none
 *
 * Side effects:
 *	May withdraw the toplevel window.
 *
 *----------------------------------------------------------------------
 */

void
TkpWinToplevelWithDraw(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    wmPtr->flags |= WM_WITHDRAWN;
    TkpWmSetState(winPtr, WithdrawnState);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpWinToplevelIconify --
 *
 *	This function is to be used by a window manager to iconify a toplevel
 *	This function is to be used by a window manage to iconify a toplevel
 *	window.
 *
 * Results:
 *	none
 *
 * Side effects:
 *	May iconify the toplevel window.
8335
8336
8337
8338
8339
8340
8341
8342

8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358

8359
8360
8361
8362
8363
8364
8365
8417
8418
8419
8420
8421
8422
8423

8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439

8440
8441
8442
8443
8444
8445
8446
8447







-
+















-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkpWinToplevelDeiconify --
 *
 *	This function is to be used by a window manager to deiconify a toplevel
 *	This function is to be used by a window manage to deiconify a toplevel
 *	window.
 *
 * Results:
 *	none
 *
 * Side effects:
 *	May deiconify the toplevel window.
 *
 *----------------------------------------------------------------------
 */

void
TkpWinToplevelDeiconify(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    wmPtr->flags &= ~WM_WITHDRAWN;

    /*
     * If WM_UPDATE_PENDING is true, a pending UpdateGeometryInfo may need to
     * be called first to update a withdrawn toplevel's geometry before it is
     * deiconified by TkpWmSetState. Don't bother if we've never been mapped.
8402
8403
8404
8405
8406
8407
8408
8409

8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426

8427
8428
8429
8430
8431
8432
8433
8484
8485
8486
8487
8488
8489
8490

8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507

8508
8509
8510
8511
8512
8513
8514
8515







-
+
















-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkpWinGeometryIsControlledByWm --
 *
 *	This function is to be used by a window manager to see if wm has
 *	This function is to be used by a window manage to see if wm has
 *	canceled geometry control.
 *
 * Results:
 *	0 - if the window manager has canceled its control
 *	1 - if the window manager controls the geometry
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

long
TkpWinToplevelIsControlledByWm(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (!wmPtr) {
	return 0;
    }
    return ((wmPtr->width != -1) && (wmPtr->height != -1)) ? 1 : 0;
}

8449
8450
8451
8452
8453
8454
8455
8456

8457
8458
8459
8460
8461
8462
8463
8531
8532
8533
8534
8535
8536
8537

8538
8539
8540
8541
8542
8543
8544
8545







-
+







 */

long
TkpWinToplevelMove(
    TkWindow *winPtr,
    int x, int y)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (wmPtr && x >= 0 && y >= 0 && !TkpWinToplevelIsControlledByWm(winPtr)) {
	Tk_MoveToplevelWindow((Tk_Window) winPtr, x, y);
    }
    return ((winPtr->changes.x << 16) & 0xffff0000)
	    | (winPtr->changes.y & 0xffff);
}
8481
8482
8483
8484
8485
8486
8487
8488

8489
8490
8491
8492
8493
8494
8495
8563
8564
8565
8566
8567
8568
8569

8570
8571
8572
8573
8574
8575
8576
8577







-
+








long
TkpWinToplevelOverrideRedirect(
    TkWindow *winPtr,
    int reqValue)
{
    int curValue;
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    curValue = Tk_Attributes((Tk_Window) winPtr)->override_redirect;
    if (reqValue < 0) {
	return curValue;
    }

    if (curValue != reqValue) {
8512
8513
8514
8515
8516
8517
8518
8519

8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535

8536
8537
8538

8539
8540
8541


8542
8543
8544

8545
8546
8547
8548
8549
8550
8551
8594
8595
8596
8597
8598
8599
8600

8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616

8617
8618
8619

8620
8621


8622
8623
8624
8625

8626
8627
8628
8629
8630
8631
8632
8633







-
+















-
+


-
+

-
-
+
+


-
+







}

/*
 *----------------------------------------------------------------------
 *
 * TkpWinToplevelDetachWindow --
 *
 *	This function is to be used for changing a toplevel's wrapper or
 *	This function is to be usd for changing a toplevel's wrapper or
 *	container.
 *
 * Results:
 *	The window's wrapper/container is removed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkpWinToplevelDetachWindow(
    TkWindow *winPtr)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    register WmInfo *wmPtr = winPtr->wmInfoPtr;

    if (winPtr->flags & TK_EMBEDDED) {
	int state = SendMessageW(wmPtr->wrapper, TK_STATE, -1, -1) - 1;
	int state = SendMessage(wmPtr->wrapper, TK_STATE, -1, -1) - 1;

	SendMessageW(wmPtr->wrapper, TK_SETMENU, 0, 0);
	SendMessageW(wmPtr->wrapper, TK_DETACHWINDOW, 0, 0);
	SendMessage(wmPtr->wrapper, TK_SETMENU, 0, 0);
	SendMessage(wmPtr->wrapper, TK_DETACHWINDOW, 0, 0);
	winPtr->flags &= ~TK_EMBEDDED;
	winPtr->privatePtr = NULL;
	wmPtr->wrapper = NULL;
	wmPtr->wrapper = None;
	if (state >= 0 && state <= 3) {
	    wmPtr->hints.initial_state = state;
	}
    }
    if (winPtr->flags & TK_TOP_LEVEL) {
	TkpWinToplevelOverrideRedirect(winPtr, 1);
    }

Changes to win/tkWinX.c.

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
1
2
3
4
5



6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21

22
23
24
25
26
27


































28
29
30
31
32
33
34





-
-
-
+
+
+





-








-






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







/*
 * tkWinX.c --
 *
 *	This file contains Windows emulation procedures for X routines.
 *
 * Copyright © 1995-1996 Sun Microsystems, Inc.
 * Copyright © 1994 Software Research Associates, Inc.
 * Copyright © 1998-2000 Scriptics Corporation.
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright (c) 1994 Software Research Associates, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#define XLIB_ILLEGAL_ACCESS
#include "tkWinInt.h"

#include <commctrl.h>
#ifdef _MSC_VER
#   pragma comment (lib, "comctl32.lib")
#   pragma comment (lib, "advapi32.lib")
#endif


/*
 * The zmouse.h file includes the definition for WM_MOUSEWHEEL.
 */

#include <zmouse.h>

/*
 * WM_MOUSEHWHEEL is normally defined by Winuser.h for Vista/2008 or later,
 * but is also usable on 2000/XP if IntelliPoint drivers are installed.
 */

#ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x020E
#endif

/* A WM_MOUSEWHEEL message sent by a trackpad contains the number of pixels as
 * the delta value, while low precision scrollwheels always send an integer
 * multiple of WHEELDELTA (= 120) as the delta value.
 */

#define WHEELDELTA 120

/*
 * Our heuristic for deciding whether a WM_MOUSEWHEEL message
 * comes from a high resolution scrolling device is that we
 * assume it is high resolution unless there are two consecutive
 * delta values that are both multiples of 120.  This is static,
 * rather than thread-specific, since input devices are shared
 * by all threads.
 */

static int lastMod = 0;

/*
 * The serial field of TouchpadScroll events is a counter for
 * events of this type only.
 */

static unsigned long scrollCounter = 0;

/*
 * imm.h is needed by HandleIMEComposition
 */

#include <imm.h>
#ifdef _MSC_VER
#   pragma comment (lib, "imm32.lib")
82
83
84
85
86
87
88
89


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92







-
+
+















-
+














-
+







/*
 * Declarations of static variables used in this file.
 */

static const char winScreenName[] = ":0"; /* Default name of windows display. */
static HINSTANCE tkInstance = NULL;	/* Application instance handle. */
static int childClassInitialized;	/* Registered child class? */
static WNDCLASSW childClass;		/* Window class for child windows. */
static WNDCLASS childClass;		/* Window class for child windows. */
static int tkPlatformId = 0;		/* version of Windows platform */
static int tkWinTheme = 0;		/* See TkWinGetPlatformTheme */
static Tcl_Encoding keyInputEncoding = NULL;
					/* The current character encoding for
					 * keyboard input */
static int keyInputCharset = -1;	/* The Win32 CHARSET for the keyboard
					 * encoding */
static Tcl_Encoding unicodeEncoding = NULL;
					/* The UNICODE encoding */

/*
 * Thread local storage. Notice that now each thread must have its own
 * TkDisplay structure, since this structure contains most of the thread-
 * specific date for threads.
 */

typedef struct {
typedef struct ThreadSpecificData {
    TkDisplay *winDisplay;	/* TkDisplay structure that represents Windows
				 * screen. */
    int updatingClipboard;	/* If 1, we are updating the clipboard. */
    int surrogateBuffer;	/* Buffer for first of surrogate pair. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/*
 * Forward declarations of functions used in this file.
 */

static void		GenerateXEvent(HWND hwnd, UINT message,
			    WPARAM wParam, LPARAM lParam);
static unsigned int	GetState(UINT message, WPARAM wParam, LPARAM lParam);
static void 		GetTranslatedKey(TkKeyEvent *xkey, UINT type);
static void 		GetTranslatedKey(XKeyEvent *xkey, UINT type);
static void		UpdateInputLanguage(int charset);
static int		HandleIMEComposition(HWND hwnd, LPARAM lParam);

/*
 *----------------------------------------------------------------------
 *
 * TkGetServerInfo --
139
140
141
142
143
144
145
146

147
148
149
150
151
152





153


154
155

156
157
158
159
160
161
162
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122

123
124
125

126
127
128
129
130
131
132
133







-
+






+
+
+
+
+
-
+
+

-
+







 *----------------------------------------------------------------------
 */

void
TkGetServerInfo(
    Tcl_Interp *interp,		/* The server information is returned in this
				 * interpreter's result. */
    TCL_UNUSED(Tk_Window))		/* Token for window; this selects a particular
    Tk_Window tkwin)		/* Token for window; this selects a particular
				 * display and server. */
{
    static char buffer[32]; /* Empty string means not initialized yet. */
    OSVERSIONINFOW os;

    if (!buffer[0]) {
	HANDLE handle = GetModuleHandle(TEXT("NTDLL"));
	int(__stdcall *getversion)(void *) =
		(int(__stdcall *)(void *))GetProcAddress(handle, "RtlGetVersion");
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
	if (!getversion || getversion(&os)) {
	GetVersionExW(&os);
	    GetVersionExW(&os);
	}
	/* Write the first character last, preventing multi-thread issues. */
	snprintf(buffer+1, sizeof(buffer)-1, "indows %d.%d %d %s", (int)os.dwMajorVersion,
	sprintf(buffer+1, "indows %d.%d %d %s", (int)os.dwMajorVersion,
		(int)os.dwMinorVersion, (int)os.dwBuildNumber,
#ifdef _WIN64
		"Win64"
#else
		"Win32"
#endif
	);
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166







-
+







 *----------------------------------------------------------------------
 */

HINSTANCE
Tk_GetHINSTANCE(void)
{
    if (tkInstance == NULL) {
	tkInstance = GetModuleHandleW(NULL);
	tkInstance = GetModuleHandle(NULL);
    }
    return tkInstance;
}

/*
 *----------------------------------------------------------------------
 *
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276

277
278
279


280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310

311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

































































337
338
339
340
341
342
343
344
345



346
347
348
349
350
351
352
353
354
355

356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246

247
248


249
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

279
280

281
282
283
284
285
286
287
288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388
389
390



391



392


































393
394
395
396
397
398
399







-
+







-
+

-
-
+
+







-
+




















-
+

-
+







-
+


















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+
+
+







-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







     */

    childClass.lpszClassName = TK_WIN_CHILD_CLASS_NAME;
    childClass.lpfnWndProc = TkWinChildProc;
    childClass.hIcon = NULL;
    childClass.hCursor = NULL;

    if (!RegisterClassW(&childClass)) {
    if (!RegisterClass(&childClass)) {
	Tcl_Panic("Unable to register TkChild class");
    }

    /*
     * Initialize input language info
     */

    if (GetLocaleInfoW(LANGIDFROMLCID(PTR2INT(GetKeyboardLayout(0))),
    if (GetLocaleInfo(LANGIDFROMLCID(PTR2INT(GetKeyboardLayout(0))),
	       LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
	       (LPWSTR) &lpCP, sizeof(lpCP)/sizeof(WCHAR))
	    && TranslateCharsetInfo((DWORD *)INT2PTR(lpCP), &lpCs, TCI_SRCCODEPAGE)) {
	       (LPTSTR) &lpCP, sizeof(lpCP)/sizeof(TCHAR))
	    && TranslateCharsetInfo(INT2PTR(lpCP), &lpCs, TCI_SRCCODEPAGE)) {
	UpdateInputLanguage((int) lpCs.ciCharset);
    }

    /*
     * Make sure we cleanup on finalize.
     */

    TkCreateExitHandler(TkWinXCleanup, hInstance);
    TkCreateExitHandler(TkWinXCleanup, (ClientData) hInstance);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinXCleanup --
 *
 *	Removes the registered classes for Tk.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Removes window classes from the system.
 *
 *----------------------------------------------------------------------
 */

void
TkWinXCleanup(
    void *clientData)
    ClientData clientData)
{
    HINSTANCE hInstance = (HINSTANCE)clientData;
    HINSTANCE hInstance = (HINSTANCE) clientData;

    /*
     * Clean up our own class.
     */

    if (childClassInitialized) {
	childClassInitialized = 0;
	UnregisterClassW(TK_WIN_CHILD_CLASS_NAME, hInstance);
	UnregisterClass(TK_WIN_CHILD_CLASS_NAME, hInstance);
    }

    if (unicodeEncoding != NULL) {
	Tcl_FreeEncoding(unicodeEncoding);
	unicodeEncoding = NULL;
    }

    /*
     * And let the window manager clean up its own class(es).
     */

    TkWinWmCleanup(hInstance);
    TkWinCleanupContainerList();
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinGetPlatformId --
 *
 *	Determines whether running under NT, 95, or Win32s, to allow runtime
 *	conditional code. Win32s is no longer supported.
 *
 * Results:
 *	The return value is one of:
 *		VER_PLATFORM_WIN32s	   Win32s on Windows 3.1 (not supported)
 *		VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95, 98, ME (not supported)
 *		VER_PLATFORM_WIN32_NT	Win32 on Windows XP, Vista, Windows 7, Windows 8
 *		VER_PLATFORM_WIN32_CE	Win32 on Windows CE
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkWinGetPlatformId(void)
{
    if (tkPlatformId == 0) {
	OSVERSIONINFOW os;

	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
	GetVersionExW(&os);
	tkPlatformId = os.dwPlatformId;

	/*
	 * Set tkWinTheme to be TK_THEME_WIN_XP or TK_THEME_WIN_CLASSIC. The
	 * TK_THEME_WIN_CLASSIC could be set even when running under XP if the
	 * windows classic theme was selected.
	 */

	if ((os.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
		(os.dwMajorVersion == 5 && os.dwMinorVersion == 1)) {
	    HKEY hKey;
	    LPCTSTR szSubKey = TEXT("Control Panel\\Appearance");
	    LPCTSTR szCurrent = TEXT("Current");
	    DWORD dwSize = 200;
	    char pBuffer[200];

	    memset(pBuffer, 0, dwSize);
	    if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0L,
		    KEY_READ, &hKey) != ERROR_SUCCESS) {
		tkWinTheme = TK_THEME_WIN_XP;
	    } else {
		RegQueryValueEx(hKey, szCurrent, NULL, NULL, (LPBYTE) pBuffer, &dwSize);
		RegCloseKey(hKey);
		if (strcmp(pBuffer, "Windows Standard") == 0) {
		    tkWinTheme = TK_THEME_WIN_CLASSIC;
		} else {
		    tkWinTheme = TK_THEME_WIN_XP;
		}
	    }
	} else {
	    tkWinTheme = TK_THEME_WIN_CLASSIC;
	}
    }
    return tkPlatformId;
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinGetPlatformTheme --
 *
 *	Return the Windows drawing style we should be using.
 *
 * Results:
 *	The return value is one of:
 *	    TK_THEME_WIN_CLASSIC	95/98/NT or XP in classic mode
 *	    TK_THEME_WIN_XP		XP not in classic mode
 *	    TK_THEME_WIN_VISTA	Vista or higher
 *
 * Side effects:
 *	Could invoke TkWinGetPlatformId.
 *
 *----------------------------------------------------------------------
 */

int
TkWinGetPlatformTheme(void)
{
    if (tkWinTheme == 0) {
	OSVERSIONINFOW os;

    if (tkPlatformId == 0) {
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
	GetVersionExW(&os);

	TkWinGetPlatformId();
	if (os.dwPlatformId != VER_PLATFORM_WIN32_NT) {
	    Tcl_Panic("Windows NT is the only supported platform");
	}

	/*
	 * Set tkWinTheme to be TK_THEME_WIN_(CLASSIC|XP|VISTA). The
	 * TK_THEME_WIN_CLASSIC could be set even when running under XP if the
	 * windows classic theme was selected.
	 */
	if (os.dwMajorVersion == 5 && os.dwMinorVersion >= 1) {
	    HKEY hKey;
	    LPCWSTR szSubKey = L"Control Panel\\Appearance";
	    LPCWSTR szCurrent = L"Current";
	    DWORD dwSize = 200;
	    WCHAR pBuffer[200];

	    memset(pBuffer, 0, dwSize);
	    if (RegOpenKeyExW(HKEY_CURRENT_USER, szSubKey, 0L,
		    KEY_READ, &hKey) != ERROR_SUCCESS) {
		tkWinTheme = TK_THEME_WIN_XP;
	    } else {
		RegQueryValueExW(hKey, szCurrent, NULL, NULL, (LPBYTE) pBuffer, &dwSize);
		RegCloseKey(hKey);
		if (wcscmp(pBuffer, L"Windows Standard") == 0) {
		    tkWinTheme = TK_THEME_WIN_CLASSIC;
		} else {
		    tkWinTheme = TK_THEME_WIN_XP;
		}
	    }
	} else if (os.dwMajorVersion > 5) {
	    tkWinTheme = TK_THEME_WIN_VISTA;
	} else {
	    tkWinTheme = TK_THEME_WIN_CLASSIC;
	}
    }
    return tkWinTheme;
}

/*
 *----------------------------------------------------------------------
 *
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
409
410
411
412
413
414
415

416
417
418
419
420
421
422
423







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

const char *
TkGetDefaultScreenName(
    TCL_UNUSED(Tcl_Interp *),
    Tcl_Interp *interp,		/* Not used. */
    const char *screenName)	/* If NULL, use default string. */
{
    if ((screenName == NULL) || (screenName[0] == '\0')) {
	screenName = winScreenName;
    }
    return screenName;
}
442
443
444
445
446
447
448
449

450
451
452

453
454
455
456
457



458
459

460
461
462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508





























509
510

511
512
513
514


515
516

517
518
519
520
521
522
523

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540


541
542

543
544
545
546

547
548
549
550
551
552
553
554


555


556
557
558
559





560
561
562
563
564



565
566
567

568
569
570


571
572
573



574
575
576
577
578
579
580
581
582
583
584
585
586
587



588
589
590
591
592
593
594
595
596



597
598
599
600
601
602
603
604
605
606

607
608

609
610

611
612
613
614


615
616
617
618
619
620
621

622
623
624
625
626
627
628
442
443
444
445
446
447
448

449
450
451

452
453
454



455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476

477
478
479





























480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

510
511
512


513
514
515

516
517
518
519
520
521
522

523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

544
545
546
547

548
549
550
551
552
553
554


555
556
557
558
559




560
561
562
563
564
565




566
567
568
569
570

571
572

573
574
575



576
577
578














579
580
581

582
583
584
585
586



587
588
589
590
591
592
593
594





595
596

597


598




599
600





601

602
603
604
605
606
607
608
609







-
+


-
+


-
-
-
+
+
+

-
+











-
+





-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+

-
+






-
+

















+
+

-
+



-
+






-
-
+
+

+
+
-
-
-
-
+
+
+
+
+

-
-
-
-
+
+
+


-
+

-

+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-





-
-
-
+
+
+





-
-
-
-
-
+

-
+
-
-
+
-
-
-
-
+
+
-
-
-
-
-

-
+







void
TkWinDisplayChanged(
    Display *display)
{
    HDC dc;
    Screen *screen;

    if (display == NULL || (((_XPrivDisplay)(display))->screens) == NULL) {
    if (display == NULL || display->screens == NULL) {
	return;
    }
    screen = (((_XPrivDisplay)(display))->screens);
    screen = display->screens;

    dc = GetDC(NULL);
    WidthOfScreen(screen) = GetDeviceCaps(dc, HORZRES);
    HeightOfScreen(screen) = GetDeviceCaps(dc, VERTRES);
    WidthMMOfScreen(screen) = MulDiv(WidthOfScreen(screen), 254,
    screen->width = GetDeviceCaps(dc, HORZRES);
    screen->height = GetDeviceCaps(dc, VERTRES);
    screen->mwidth = MulDiv(screen->width, 254,
	    GetDeviceCaps(dc, LOGPIXELSX) * 10);
    HeightMMOfScreen(screen) = MulDiv(HeightOfScreen(screen), 254,
    screen->mheight = MulDiv(screen->height, 254,
	    GetDeviceCaps(dc, LOGPIXELSY) * 10);

    /*
     * On windows, when creating a color bitmap, need two pieces of
     * information: the number of color planes and the number of pixels per
     * plane. Need to remember both quantities so that when constructing an
     * HBITMAP for offscreen rendering, we can specify the correct value for
     * the number of planes. Otherwise the HBITMAP won't be compatible with
     * the HWND and we'll just get blank spots copied onto the screen.
     */

    screen->ext_data = (XExtData *)INT2PTR(GetDeviceCaps(dc, PLANES));
    screen->ext_data = INT2PTR(GetDeviceCaps(dc, PLANES));
    screen->root_depth = GetDeviceCaps(dc, BITSPIXEL) * PTR2INT(screen->ext_data);

    if (screen->root_visual != NULL) {
	ckfree(screen->root_visual);
    }
    screen->root_visual = (Visual *)ckalloc(sizeof(Visual));
    screen->root_visual = ckalloc(sizeof(Visual));
    screen->root_visual->visualid = 0;
    if (GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) {
	DefaultVisualOfScreen(screen)->map_entries = GetDeviceCaps(dc, SIZEPALETTE);
	DefaultVisualOfScreen(screen)->c_class = PseudoColor;
	DefaultVisualOfScreen(screen)->red_mask = 0x0;
	DefaultVisualOfScreen(screen)->green_mask = 0x0;
	DefaultVisualOfScreen(screen)->blue_mask = 0x0;
    } else if (DefaultDepthOfScreen(screen) == 4) {
	DefaultVisualOfScreen(screen)->c_class = StaticColor;
	DefaultVisualOfScreen(screen)->map_entries = 16;
    } else if (DefaultDepthOfScreen(screen) == 8) {
	DefaultVisualOfScreen(screen)->c_class = StaticColor;
	DefaultVisualOfScreen(screen)->map_entries = 256;
    } else if (DefaultDepthOfScreen(screen) == 12) {
	DefaultVisualOfScreen(screen)->c_class = TrueColor;
	DefaultVisualOfScreen(screen)->map_entries = 32;
	DefaultVisualOfScreen(screen)->red_mask = 0xf0;
	DefaultVisualOfScreen(screen)->green_mask = 0xf000;
	DefaultVisualOfScreen(screen)->blue_mask = 0xf00000;
    } else if (DefaultDepthOfScreen(screen) == 16) {
	DefaultVisualOfScreen(screen)->c_class = TrueColor;
	DefaultVisualOfScreen(screen)->map_entries = 64;
	DefaultVisualOfScreen(screen)->red_mask = 0xf8;
	DefaultVisualOfScreen(screen)->green_mask = 0xfc00;
	DefaultVisualOfScreen(screen)->blue_mask = 0xf80000;
    } else if (DefaultDepthOfScreen(screen) >= 24) {
	DefaultVisualOfScreen(screen)->c_class = TrueColor;
	DefaultVisualOfScreen(screen)->map_entries = 256;
	DefaultVisualOfScreen(screen)->red_mask = 0xff;
	DefaultVisualOfScreen(screen)->green_mask = 0xff00;
	DefaultVisualOfScreen(screen)->blue_mask = 0xff0000;
	screen->root_visual->map_entries = GetDeviceCaps(dc, SIZEPALETTE);
	screen->root_visual->class = PseudoColor;
	screen->root_visual->red_mask = 0x0;
	screen->root_visual->green_mask = 0x0;
	screen->root_visual->blue_mask = 0x0;
    } else if (screen->root_depth == 4) {
	screen->root_visual->class = StaticColor;
	screen->root_visual->map_entries = 16;
    } else if (screen->root_depth == 8) {
	screen->root_visual->class = StaticColor;
	screen->root_visual->map_entries = 256;
    } else if (screen->root_depth == 12) {
	screen->root_visual->class = TrueColor;
	screen->root_visual->map_entries = 32;
	screen->root_visual->red_mask = 0xf0;
	screen->root_visual->green_mask = 0xf000;
	screen->root_visual->blue_mask = 0xf00000;
    } else if (screen->root_depth == 16) {
	screen->root_visual->class = TrueColor;
	screen->root_visual->map_entries = 64;
	screen->root_visual->red_mask = 0xf8;
	screen->root_visual->green_mask = 0xfc00;
	screen->root_visual->blue_mask = 0xf80000;
    } else if (screen->root_depth >= 24) {
	screen->root_visual->class = TrueColor;
	screen->root_visual->map_entries = 256;
	screen->root_visual->red_mask = 0xff;
	screen->root_visual->green_mask = 0xff00;
	screen->root_visual->blue_mask = 0xff0000;
    }
    DefaultVisualOfScreen(screen)->bits_per_rgb = DefaultDepthOfScreen(screen);
    screen->root_visual->bits_per_rgb = screen->root_depth;
    ReleaseDC(NULL, dc);

    if (DefaultColormapOfScreen(screen) != None) {
	XFreeColormap(display, DefaultColormapOfScreen(screen));
    if (screen->cmap != None) {
	XFreeColormap(display, screen->cmap);
    }
    DefaultColormapOfScreen(screen) = XCreateColormap(display, None, DefaultVisualOfScreen(screen),
    screen->cmap = XCreateColormap(display, None, screen->root_visual,
	    AllocNone);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpOpenDisplay/XkbOpenDisplay --
 * TkpOpenDisplay --
 *
 *	Create the Display structure and fill it with device specific
 *	information.
 *
 * Results:
 *	Returns a TkDisplay structure on success or NULL on failure.
 *
 * Side effects:
 *	Allocates a new TkDisplay structure.
 *
 *----------------------------------------------------------------------
 */

TkDisplay *
TkpOpenDisplay(
    const char *display_name)
{
    Screen *screen;
    TkWinDrawable *twdPtr;
    Display *display;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->winDisplay != NULL) {
	if (!strcmp(DisplayString(tsdPtr->winDisplay->display), display_name)) {
	if (!strcmp(tsdPtr->winDisplay->display->display_name, display_name)) {
	    return tsdPtr->winDisplay;
	} else {
	    return NULL;
	}
    }

    display = XkbOpenDisplay(display_name, NULL, NULL, NULL, NULL, NULL);
    TkWinDisplayChanged(display);
    display = ckalloc(sizeof(Display));
    ZeroMemory(display, sizeof(Display));

    display->display_name = ckalloc(strlen(display_name) + 1);
    strcpy(display->display_name, display_name);
    tsdPtr->winDisplay =(TkDisplay *) ckalloc(sizeof(TkDisplay));
    memset(tsdPtr->winDisplay, 0, sizeof(TkDisplay));
    tsdPtr->winDisplay->display = display;
    tsdPtr->updatingClipboard = FALSE;

    display->cursor_font = 1;
    display->nscreens = 1;
    display->request = 1;
    display->qlen = 0;

    /*
     * Key map info must be available immediately, because of "send event".
     */
    TkpInitKeymapInfo(tsdPtr->winDisplay);
    screen = ckalloc(sizeof(Screen));
    ZeroMemory(screen, sizeof(Screen));
    screen->display = display;

    /*
     * Key map info must be available immediately, because of "send event".
     * Set up the root window.
     */
    TkpInitKeymapInfo(tsdPtr->winDisplay);

    twdPtr = ckalloc(sizeof(TkWinDrawable));
    if (twdPtr == NULL) {
    return tsdPtr->winDisplay;
}

	return None;
    }
    twdPtr->type = TWD_WINDOW;
Display *
XkbOpenDisplay(
	const char *name,
	int *ev_rtrn,
	int *err_rtrn,
	int *major_rtrn,
	int *minor_rtrn,
	int *reason)
{
    _XPrivDisplay display = (_XPrivDisplay)ckalloc(sizeof(Display));
    Screen *screen = (Screen *)ckalloc(sizeof(Screen));
    TkWinDrawable *twdPtr = (TkWinDrawable *)ckalloc(sizeof(TkWinDrawable));

    memset(screen, 0, sizeof(Screen));
    twdPtr->window.winPtr = NULL;
    twdPtr->window.handle = NULL;
    screen->root = (Window)twdPtr;
    memset(display, 0, sizeof(Display));

    /*
     * Note that these pixel values are not palette relative.
     */

    WhitePixelOfScreen(screen) = RGB(255, 255, 255);
    BlackPixelOfScreen(screen) = RGB(0, 0, 0);
    DefaultColormapOfScreen(screen) = None;
    screen->white_pixel = RGB(255, 255, 255);
    screen->black_pixel = RGB(0, 0, 0);
    screen->cmap = None;

    display->screens		= screen;
    display->nscreens		= 1;
    display->default_screen	= 0;

    twdPtr->type = TWD_WINDOW;
    twdPtr->window.winPtr = NULL;
    twdPtr->window.handle = NULL;
    screen->root = (Window)twdPtr;
    screen->display = (Display *)display;
    TkWinDisplayChanged(display);

    display->display_name = (char  *)ckalloc(strlen(name) + 1);
    tsdPtr->winDisplay = ckalloc(sizeof(TkDisplay));
    strcpy(display->display_name, name);

    ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
    display->nscreens = 1;
    display->request = 1;
    display->qlen = 0;

    tsdPtr->winDisplay->display = display;
    tsdPtr->updatingClipboard = FALSE;
    if (ev_rtrn) *ev_rtrn = 0;
    if (err_rtrn) *err_rtrn = 0;
    if (major_rtrn) *major_rtrn = 0;
    if (minor_rtrn) *minor_rtrn = 0;
    if (reason) *reason = 0;

    return (Display *)display;
    return tsdPtr->winDisplay;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCloseDisplay --
 *
638
639
640
641
642
643
644
645

646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661



662
663
664


665
666
667


668
669

670
671
672
673
674
675
676
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633
634
635
636
637
638
639



640
641
642
643


644
645
646


647
648
649

650
651
652
653
654
655
656
657







-
+













-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
+







 *----------------------------------------------------------------------
 */

void
TkpCloseDisplay(
    TkDisplay *dispPtr)
{
    _XPrivDisplay display = (_XPrivDisplay)dispPtr->display;
    Display *display = dispPtr->display;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (dispPtr != tsdPtr->winDisplay) {
	Tcl_Panic("TkpCloseDisplay: tried to call TkpCloseDisplay on another display");
	return; /* not reached */
    }

    tsdPtr->winDisplay = NULL;

    if (display->display_name != NULL) {
	ckfree(display->display_name);
    }
    if (ScreenOfDisplay(display, 0) != NULL) {
	if (DefaultVisualOfScreen(ScreenOfDisplay(display, 0)) != NULL) {
	    ckfree(DefaultVisualOfScreen(ScreenOfDisplay(display, 0)));
    if (display->screens != NULL) {
	if (display->screens->root_visual != NULL) {
	    ckfree(display->screens->root_visual);
	}
	if (RootWindowOfScreen(ScreenOfDisplay(display, 0)) != None) {
	    ckfree((void *)RootWindowOfScreen(ScreenOfDisplay(display, 0)));
	if (display->screens->root != None) {
	    ckfree(display->screens->root);
	}
	if (DefaultColormapOfScreen(ScreenOfDisplay(display, 0)) != None) {
	    XFreeColormap(display, DefaultColormapOfScreen(ScreenOfDisplay(display, 0)));
	if (display->screens->cmap != None) {
	    XFreeColormap(display, display->screens->cmap);
	}
	ckfree(ScreenOfDisplay(display, 0));
	ckfree(display->screens);
    }
    ckfree(display);
}

/*
 *----------------------------------------------------------------------
 *
697
698
699
700
701
702
703
704

705
706
707
708
709
710
711
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692







-
+







    if (dispPtr->clipWindow != NULL) {
	Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
		dispPtr->applicationAtom);
	Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
		dispPtr->windowAtom);

	Tk_DestroyWindow(dispPtr->clipWindow);
	Tcl_Release(dispPtr->clipWindow);
	Tcl_Release((ClientData) dispPtr->clipWindow);
	dispPtr->clipWindow = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
720
721
722
723
724
725
726
727
728


729
730
731
732
733
734
735
701
702
703
704
705
706
707


708
709
710
711
712
713
714
715
716







-
-
+
+







 *	Plays a sounds out the system speakers.
 *
 *----------------------------------------------------------------------
 */

int
XBell(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int))
    Display *display,
    int percent)
{
    MessageBeep(MB_OK);
    return Success;
}

/*
 *----------------------------------------------------------------------
761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795
742
743
744
745
746
747
748

749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768

769
770
771
772
773
774
775
776







-
+



















-
+







	UpdateInputLanguage((int) wParam);
	result = 1;
	break;

    case WM_IME_COMPOSITION:
	result = 0;
	if (HandleIMEComposition(hwnd, lParam) == 0) {
	    result = DefWindowProcW(hwnd, message, wParam, lParam);
	    result = DefWindowProc(hwnd, message, wParam, lParam);
	}
	break;

    case WM_SETCURSOR:
	/*
	 * Short circuit the WM_SETCURSOR message since we set the cursor
	 * elsewhere.
	 */

	result = TRUE;
	break;

    case WM_CREATE:
    case WM_ERASEBKGND:
	result = 0;
	break;

    case WM_PAINT:
	GenerateXEvent(hwnd, message, wParam, lParam);
	result = DefWindowProcW(hwnd, message, wParam, lParam);
	result = DefWindowProc(hwnd, message, wParam, lParam);
	break;

    case TK_CLAIMFOCUS:
    case TK_GEOMETRYREQ:
    case TK_ATTACHWINDOW:
    case TK_DETACHWINDOW:
    case TK_ICONIFY:
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825


826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

842
843
844
845
846
847
848
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863
789
790
791
792
793
794
795

796
797
798
799
800
801
802
803
804


805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836

837
838
839
840
841
842
843
844







-
+








-
-
+
+















-
+














-
+







    case WM_UNICHAR:
        if (wParam == UNICODE_NOCHAR) {
	    /* If wParam is UNICODE_NOCHAR and the application processes
	     * this message, then return TRUE. */
	    result = 1;
	} else {
	    /* If the event was translated, we must return 0 */
            if (TkTranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
            if (Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
                result = 0;
	    } else {
	        result = 1;
	    }
	}
	break;

    default:
	if (!TkTranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	    result = DefWindowProcW(hwnd, message, wParam, lParam);
	if (!Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) {
	    result = DefWindowProc(hwnd, message, wParam, lParam);
	}
	break;
    }

    /*
     * Handle any newly queued events before returning control to Windows.
     */

    Tcl_ServiceAll();
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkTranslateWinEvent --
 * Tk_TranslateWinEvent --
 *
 *	This function is called by widget window functions to handle the
 *	translation from Win32 events to Tk events.
 *
 * Results:
 *	Returns 1 if the event was handled, else 0.
 *
 * Side effects:
 *	Depends on the event.
 *
 *----------------------------------------------------------------------
 */

int
TkTranslateWinEvent(
Tk_TranslateWinEvent(
    HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam,
    LRESULT *resultPtr)
{
    *resultPtr = 0;
899
900
901
902
903
904
905
906

907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925

926
927
928
929
930
931
932
880
881
882
883
884
885
886

887
888
889
890
891
892
893
894
895
896
897
898


899
900
901

902

903
904
905
906
907
908
909
910







-
+











-
-



-

-
+







	 * or we will loop.
	 */

	HWND target = (message == WM_NOTIFY)
		? ((NMHDR*)lParam)->hwndFrom : (HWND) lParam;

	if (target && target != hwnd) {
	    *resultPtr = SendMessageW(target, message, wParam, lParam);
	    *resultPtr = SendMessage(target, message, wParam, lParam);
	    return 1;
	}
	break;
    }

    case WM_LBUTTONDOWN:
    case WM_LBUTTONDBLCLK:
    case WM_MBUTTONDOWN:
    case WM_MBUTTONDBLCLK:
    case WM_RBUTTONDOWN:
    case WM_RBUTTONDBLCLK:
    case WM_XBUTTONDOWN:
    case WM_XBUTTONDBLCLK:
    case WM_LBUTTONUP:
    case WM_MBUTTONUP:
    case WM_RBUTTONUP:
    case WM_XBUTTONUP:
    case WM_MOUSEMOVE:
	TkWinPointerEvent(hwnd, (short) LOWORD(lParam), (short) HIWORD(lParam));
	Tk_PointerEvent(hwnd, (short) LOWORD(lParam), (short) HIWORD(lParam));
	return 1;

    case WM_SYSKEYDOWN:
    case WM_KEYDOWN:
	if (wParam == VK_PACKET) {
	    /*
	     * This will trigger WM_CHAR event(s) with unicode data.
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
919
920
921
922
923
924
925

926
927
928
929
930
931
932







-







    case WM_KILLFOCUS:
    case WM_DESTROYCLIPBOARD:
    case WM_UNICHAR:
    case WM_CHAR:
    case WM_SYSKEYUP:
    case WM_KEYUP:
    case WM_MOUSEWHEEL:
    case WM_MOUSEHWHEEL:
	GenerateXEvent(hwnd, message, wParam, lParam);
	return 1;
    case WM_MENUCHAR:
	GenerateXEvent(hwnd, message, wParam, lParam);

	/*
	 * MNC_CLOSE is the only one that looks right. This is a hack.
981
982
983
984
985
986
987
988

989
990
991
992
993

994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018





1019
1020
1021
1022
1023
1024

1025
1026
1027
1028
1029




1030
1031

1032
1033
1034
1035
1036
1037


1038
1039
1040


1041
1042
1043
1044
1045
1046
1047
958
959
960
961
962
963
964

965
966
967
968
969

970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990





991
992
993
994
995
996
997
998
999
1000

1001
1002




1003
1004
1005
1006
1007

1008
1009
1010
1011
1012


1013
1014
1015


1016
1017
1018
1019
1020
1021
1022
1023
1024







-
+




-
+




















-
-
-
-
-
+
+
+
+
+





-
+

-
-
-
-
+
+
+
+

-
+




-
-
+
+

-
-
+
+







static void
GenerateXEvent(
    HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    union {XEvent x; TkKeyEvent key;} event;
    XEvent event;
    TkWindow *winPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if ((message == WM_MOUSEWHEEL) || (message == WM_MOUSEHWHEEL)) {
    if (message == WM_MOUSEWHEEL) {
	union {LPARAM lParam; POINTS point;} root;
	POINT pos;
	root.lParam = lParam;

	/*
	 * Redirect mousewheel events to the window containing the cursor.
	 * That feels much less strange to users, and is how all the other
	 * platforms work.
	 */

	pos.x = root.point.x;
	pos.y = root.point.y;
	hwnd = WindowFromPoint(pos);
    }

    winPtr = (TkWindow *) Tk_HWNDToWindow(hwnd);
    if (!winPtr || winPtr->window == None) {
	return;
    }

    memset(&event.x, 0, sizeof(XEvent));
    event.x.xany.serial = LastKnownRequestProcessed(winPtr->display)++;
    event.x.xany.send_event = False;
    event.x.xany.display = winPtr->display;
    event.x.xany.window = winPtr->window;
    memset(&event, 0, sizeof(XEvent));
    event.xany.serial = winPtr->display->request++;
    event.xany.send_event = False;
    event.xany.display = winPtr->display;
    event.xany.window = winPtr->window;

    switch (message) {
    case WM_PAINT: {
	PAINTSTRUCT ps;

	event.x.type = Expose;
	event.type = Expose;
	BeginPaint(hwnd, &ps);
	event.x.xexpose.x = ps.rcPaint.left;
	event.x.xexpose.y = ps.rcPaint.top;
	event.x.xexpose.width = ps.rcPaint.right - ps.rcPaint.left;
	event.x.xexpose.height = ps.rcPaint.bottom - ps.rcPaint.top;
	event.xexpose.x = ps.rcPaint.left;
	event.xexpose.y = ps.rcPaint.top;
	event.xexpose.width = ps.rcPaint.right - ps.rcPaint.left;
	event.xexpose.height = ps.rcPaint.bottom - ps.rcPaint.top;
	EndPaint(hwnd, &ps);
	event.x.xexpose.count = 0;
	event.xexpose.count = 0;
	break;
    }

    case WM_CLOSE:
	event.x.type = ClientMessage;
	event.x.xclient.message_type =
	event.type = ClientMessage;
	event.xclient.message_type =
		Tk_InternAtom((Tk_Window) winPtr, "WM_PROTOCOLS");
	event.x.xclient.format = 32;
	event.x.xclient.data.l[0] =
	event.xclient.format = 32;
	event.xclient.data.l[0] =
		Tk_InternAtom((Tk_Window) winPtr, "WM_DELETE_WINDOW");
	break;

    case WM_SETFOCUS:
    case WM_KILLFOCUS: {
	TkWindow *otherWinPtr = (TkWindow *) Tk_HWNDToWindow((HWND) wParam);

1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079




1080
1081
1082
1083
1084
1085
1086
1046
1047
1048
1049
1050
1051
1052




1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063







-
-
-
-
+
+
+
+







	    Tk_SetCaretPos((Tk_Window) winPtr, 0, 0, 0);
	}

	if (otherWinPtr == winPtr) {
	    return;
	}

	event.x.xany.window = winPtr->window;
	event.x.type = (message == WM_SETFOCUS) ? FocusIn : FocusOut;
	event.x.xfocus.mode = NotifyNormal;
	event.x.xfocus.detail = NotifyNonlinear;
	event.xany.window = winPtr->window;
	event.type = (message == WM_SETFOCUS) ? FocusIn : FocusOut;
	event.xfocus.mode = NotifyNormal;
	event.xfocus.detail = NotifyNonlinear;

	/*
	 * Destroy the caret if we own it. If we are moving to another Tk
	 * window, it will reclaim and reposition it with Tk_SetCaretPos.
	 */

	if (message == WM_KILLFOCUS) {
1094
1095
1096
1097
1098
1099
1100
1101
1102


1103
1104

1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1071
1072
1073
1074
1075
1076
1077


1078
1079
1080

1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091







-
-
+
+

-
+



-







	    /*
	     * We want to avoid this event if we are the ones that caused this
	     * event.
	     */

	    return;
	}
	event.x.type = SelectionClear;
	event.x.xselectionclear.selection =
	event.type = SelectionClear;
	event.xselectionclear.selection =
		Tk_InternAtom((Tk_Window)winPtr, "CLIPBOARD");
	event.x.xselectionclear.time = TkpGetMS();
	event.xselectionclear.time = TkpGetMS();
	break;

    case WM_MOUSEWHEEL:
    case WM_MOUSEHWHEEL:
    case WM_CHAR:
    case WM_UNICHAR:
    case WM_SYSKEYDOWN:
    case WM_SYSKEYUP:
    case WM_KEYDOWN:
    case WM_KEYUP: {
	unsigned int state = GetState(message, wParam, lParam);
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141









1142
1143
1144
1145
1146
1147
1148

1149
1150

1151

1152
1153
1154
1155


1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223




1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237



1238
1239
1240
1241
1242
1243
1244
1102
1103
1104
1105
1106
1107
1108









1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123

1124

1125
1126

1127




1128
1129
1130
1131
1132














1133
1134
1135


















1136

















1137

1138
1139
1140
1141
1142
1143
1144
1145
1146
1147




1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162



1163
1164
1165
1166
1167
1168
1169
1170
1171
1172







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+






-
+
-

+
-
+
-
-
-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-










-
-
-
-
+
+
+
+











-
-
-
+
+
+







	clientPoint.y = root.point.y;
	ScreenToClient(hwnd, &clientPoint);

	/*
	 * Set up the common event fields.
	 */

	event.x.xbutton.root = RootWindow(winPtr->display, winPtr->screenNum);
	event.x.xbutton.subwindow = None;
	event.x.xbutton.x = clientPoint.x;
	event.x.xbutton.y = clientPoint.y;
	event.x.xbutton.x_root = root.point.x;
	event.x.xbutton.y_root = root.point.y;
	event.x.xbutton.state = state;
	event.x.xbutton.time = time;
	event.x.xbutton.same_screen = True;
	event.xbutton.root = RootWindow(winPtr->display, winPtr->screenNum);
	event.xbutton.subwindow = None;
	event.xbutton.x = clientPoint.x;
	event.xbutton.y = clientPoint.y;
	event.xbutton.x_root = root.point.x;
	event.xbutton.y_root = root.point.y;
	event.xbutton.state = state;
	event.xbutton.time = time;
	event.xbutton.same_screen = True;

	/*
	 * Now set up event specific fields.
	 */

	switch (message) {
	case WM_MOUSEWHEEL: {
	case WM_MOUSEWHEEL:

	    /*
	     * We have invented a new X event type to handle this event. It
	     * Send an Xevent using a KeyPress struct, but with the type field
	     * still uses the KeyPress struct. However, the keycode field has
	     * set to MouseWheelEvent for low resolution scrolls and to
	     * TouchpadScroll for high resolution scroll events. The Y delta
	     * is stored in the low order 16 bits of the keycode field.  Set
	     * nbytes to 0 to prevent conversion of the keycode to a keysym in
	     * been overloaded to hold the zDelta of the wheel. Set nbytes to
	     * 0 to prevent conversion of the keycode to a keysym in
	     * TkpGetString. [Bug 1118340].
	     */

	    int delta = (short) HIWORD(wParam);
	    int mod = delta % WHEELDELTA;
	    if ( mod != 0 || lastMod != 0) {
		/* High resolution. */
		event.x.type = TouchpadScroll;
		event.x.xany.send_event = -1;
		event.key.nbytes = 0;
		event.x.xkey.state = state;
		event.x.xany.serial = scrollCounter++;
		event.x.xkey.keycode = (unsigned int) delta;
	    } else {
		event.x.type = MouseWheelEvent;
		event.x.xany.send_event = -1;
		event.key.nbytes = 0;
	    event.type = MouseWheelEvent;
	    event.xany.send_event = -1;
	    event.xkey.nbytes = 0;
		event.x.xkey.keycode = (unsigned int) delta;
	    }
	    lastMod = mod;
	    break;
	}
	case WM_MOUSEHWHEEL: {

	    /*
	     * Send an Xevent using a KeyPress struct, but with the type field
	     * set to MouseWheelEvent for low resolution scrolls and to
	     * TouchpadScroll for high resolution scroll events.  For low
	     * resolution scrolls the X delta is stored in the keycode field
	     * and For high resolution scrolls the X delta is in the high word
	     * of the keycode.  Set nbytes to 0 to prevent conversion of the
	     * keycode to a keysym in TkpGetString. [Bug 1118340].
	     */

	    int delta = (short) HIWORD(wParam);
	    event.xkey.keycode = (short) HIWORD(wParam);
	    int mod = delta % WHEELDELTA;
	    if ( mod != 0 || lastMod != 0) {
		/* High resolution. */
		event.x.type = TouchpadScroll;
		event.x.xany.send_event = -1;
		event.key.nbytes = 0;
		event.x.xkey.state = state;
		event.x.xany.serial = scrollCounter++;
		event.x.xkey.keycode = (unsigned int)(-(delta << 16));
	    } else {
		event.x.type = MouseWheelEvent;
		event.x.xany.send_event = -1;
		event.key.nbytes = 0;
		event.x.xkey.state |= ShiftMask;
		event.x.xkey.keycode = delta;
	    }
	    lastMod = mod;
	    break;
	}
	case WM_SYSKEYDOWN:
	case WM_KEYDOWN:
	    /*
	     * Check for translated characters in the event queue. Setting
	     * xany.send_event to -1 indicates to the Windows implementation
	     * of TkpGetString() that this event was generated by windows and
	     * that the Windows extension xkey.trans_chars is filled with the
	     * MBCS characters that came from the TranslateMessage call.
	     */

	    event.x.type = KeyPress;
	    event.x.xany.send_event = -1;
	    event.x.xkey.keycode = wParam;
	    GetTranslatedKey(&event.key, (message == WM_KEYDOWN) ? WM_CHAR :
	    event.type = KeyPress;
	    event.xany.send_event = -1;
	    event.xkey.keycode = wParam;
	    GetTranslatedKey(&event.xkey, (message == WM_KEYDOWN) ? WM_CHAR :
	            WM_SYSCHAR);
	    break;

	case WM_SYSKEYUP:
	case WM_KEYUP:
	    /*
	     * We don't check for translated characters on keyup because Tk
	     * won't know what to do with them. Instead, we wait for the
	     * WM_CHAR messages which will follow.
	     */

	    event.x.type = KeyRelease;
	    event.x.xkey.keycode = wParam;
	    event.key.nbytes = 0;
	    event.type = KeyRelease;
	    event.xkey.keycode = wParam;
	    event.xkey.nbytes = 0;
	    break;

	case WM_CHAR:
	    /*
	     * Synthesize both a KeyPress and a KeyRelease. Strings generated
	     * by Input Method Editor are handled in the following manner:
	     * 1. A series of WM_KEYDOWN & WM_KEYUP messages that cause
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273



1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288



1289
1290
1291


1292
1293
1294
1295
1296

1297
1298
1299
1300
1301



1302
1303
1304
1305
1306


1307
1308
1309
1310
1311
1312
1313
1314
1315






1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336

1337
1338
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350
1351
1352
1192
1193
1194
1195
1196
1197
1198



1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213



1214
1215
1216
1217


1218
1219
1220
1221
1222
1223

1224
1225
1226



1227
1228
1229
1230
1231
1232


1233
1234
1235
1236
1237






1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1280







-
-
-
+
+
+












-
-
-
+
+
+

-
-
+
+




-
+


-
-
-
+
+
+



-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+




















-
+








-
+







	     *	  event. It is the event-consumer's responsibility to convert
	     *	  the string returned from XLookupString from system encoding
	     *	  to UTF-8.
	     * 5. And finally we get the WM_KEYUP for the "confirm typing"
	     *    character.
	     */

	    event.x.type = KeyPress;
	    event.x.xany.send_event = -1;
	    event.x.xkey.keycode = 0;
	    event.type = KeyPress;
	    event.xany.send_event = -1;
	    event.xkey.keycode = 0;
	    if ((int)wParam & 0xff00) {
		int ch1 = wParam & 0xffff;

		if ((ch1 & 0xfc00) == 0xd800) {
		    tsdPtr->surrogateBuffer = ch1;
		    return;
		}
		if ((ch1 & 0xfc00) == 0xdc00) {
		    ch1 = ((tsdPtr->surrogateBuffer & 0x3ff) << 10) |
			    (ch1 & 0x3ff) | 0x10000;
		    tsdPtr->surrogateBuffer = 0;
		}
		event.x.xany.send_event = -3;
		event.key.nbytes = 0;
		event.x.xkey.keycode = ch1;
		event.xany.send_event = -3;
		event.xkey.nbytes = 0;
		event.xkey.keycode = ch1;
	    } else {
		event.key.nbytes = 1;
		event.key.trans_chars[0] = (char) wParam;
		event.xkey.nbytes = 1;
		event.xkey.trans_chars[0] = (char) wParam;

		if (IsDBCSLeadByte((BYTE) wParam)) {
		    MSG msg;

		    if ((PeekMessageW(&msg, NULL, WM_CHAR, WM_CHAR,
		    if ((PeekMessage(&msg, NULL, WM_CHAR, WM_CHAR,
		            PM_NOREMOVE) != 0)
			    && (msg.message == WM_CHAR)) {
			GetMessageW(&msg, NULL, WM_CHAR, WM_CHAR);
			event.key.nbytes = 2;
			event.key.trans_chars[1] = (char) msg.wParam;
			GetMessage(&msg, NULL, WM_CHAR, WM_CHAR);
			event.xkey.nbytes = 2;
			event.xkey.trans_chars[1] = (char) msg.wParam;
		   }
		}
	    }
	    Tk_QueueWindowEvent(&event.x, TCL_QUEUE_TAIL);
	    event.x.type = KeyRelease;
	    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
	    event.type = KeyRelease;
	    break;

	case WM_UNICHAR: {
	    event.x.type = KeyPress;
	    event.x.xany.send_event = -3;
	    event.x.xkey.keycode = wParam;
	    event.key.nbytes = 0;
	    Tk_QueueWindowEvent(&event.x, TCL_QUEUE_TAIL);
	    event.x.type = KeyRelease;
	    event.type = KeyPress;
	    event.xany.send_event = -3;
	    event.xkey.keycode = wParam;
	    event.xkey.nbytes = 0;
	    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
	    event.type = KeyRelease;
	    break;
	}

	}
	break;
    }

    default:
	/*
	 * Don't know how to translate this event, so ignore it. (It probably
	 * should not have got here, but ignoring it should be harmless.)
	 */

	return;
    }

    /*
     * Post the translated event to the main Tk event queue.
     */

    Tk_QueueWindowEvent(&event.x, TCL_QUEUE_TAIL);
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
}

/*
 *----------------------------------------------------------------------
 *
 * GetState --
 *
 *	This function constructs a state mask for the mouse buttons and
 *	modifier keys as they were before the event occurred.
 *	modifier keys as they were before the event occured.
 *
 * Results:
 *	Returns a composite value of all the modifier and button state flags
 *	that were set at the time the event occurred.
 *
 * Side effects:
 *	None.
1431
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

1462
1463


1464
1465
1466
1467
1468
1469
1470
1359
1360
1361
1362
1363
1364
1365

1366
1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388

1389
1390

1391
1392
1393
1394
1395
1396
1397
1398
1399







-
+






-
+















-
+

-
+
+







 *	queue.
 *
 *----------------------------------------------------------------------
 */

static void
GetTranslatedKey(
    TkKeyEvent *xkey,
    XKeyEvent *xkey,
    UINT type)
{
    MSG msg;

    xkey->nbytes = 0;

    while ((xkey->nbytes < sizeof(xkey->trans_chars))
    while ((xkey->nbytes < XMaxTransChars)
	    && (PeekMessageA(&msg, NULL, type, type, PM_NOREMOVE) != 0)) {
	if (msg.message != type) {
	    break;
	}

	GetMessageA(&msg, NULL, type, type);

	/*
	 * If this is a normal character message, we may need to strip off the
	 * Alt modifier (e.g. Alt-digits). Note that we don't want to do this
	 * for system messages, because those were presumably generated as an
	 * Alt-char sequence (e.g. accelerator keys).
	 */

	if ((msg.message == WM_CHAR) && (msg.lParam & 0x20000000)) {
	    xkey->keyEvent.state = 0;
	    xkey->state = 0;
	}
	xkey->trans_chars[xkey->nbytes++] = (char) msg.wParam;
	xkey->trans_chars[xkey->nbytes] = (char) msg.wParam;
	xkey->nbytes++;

	if (((unsigned short) msg.wParam) > ((unsigned short) 0xff)) {
	    /*
	     * Some "addon" input devices, such as the popular PenPower
	     * Chinese writing pad, generate 16 bit values in WM_CHAR messages
	     * (instead of passing them in two separate WM_CHAR messages
	     * containing two 8-bit values.
1504
1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527
1528
1529
1530
1531
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446
1447
1448




1449

1450
1451
1452
1453
1454
1455
1456







-
+








-
-
-
-
+
-







    CHARSETINFO charsetInfo;
    Tcl_Encoding encoding;
    char codepage[4 + TCL_INTEGER_SPACE];

    if (keyInputCharset == charset) {
	return;
    }
    if (TranslateCharsetInfo((DWORD*)INT2PTR(charset), &charsetInfo,
    if (TranslateCharsetInfo(INT2PTR(charset), &charsetInfo,
	    TCI_SRCCHARSET) == 0) {
	/*
	 * Some mysterious failure.
	 */

	return;
    }

    if (charsetInfo.ciACP == CP_UTF8) {
	strcpy(codepage, "utf-8");
    } else {
	snprintf(codepage, sizeof(codepage), "cp%d", charsetInfo.ciACP);
    wsprintfA(codepage, "cp%d", charsetInfo.ciACP);
    }

    if ((encoding = Tcl_GetEncoding(NULL, codepage)) == NULL) {
	/*
	 * The encoding is not supported by Tcl.
	 */

	return;
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1503
1504
1505
1506
1507
1508
1509



1510

1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533







-
-
-
+
-















-
+







 *----------------------------------------------------------------------
 */

Tcl_Encoding
TkWinGetUnicodeEncoding(void)
{
    if (unicodeEncoding == NULL) {
	unicodeEncoding = Tcl_GetEncoding(NULL, "utf-16");
	if (unicodeEncoding == NULL) {
	    unicodeEncoding = Tcl_GetEncoding(NULL, "unicode");
	unicodeEncoding = Tcl_GetEncoding(NULL, "unicode");
	}
    }
    return unicodeEncoding;
}

/*
 *----------------------------------------------------------------------
 *
 * HandleIMEComposition --
 *
 *	This function works around a deficiency in some versions of Windows
 *	2000 to make it possible to entry multi-lingual characters under all
 *	versions of Windows 2000.
 *
 *	When an Input Method Editor (IME) is ready to send input characters to
 *	an application, it sends a WM_IME_COMPOSITION message with the
 *	GCS_RESULTSTR. However, The DefWindowProcW() on English Windows 2000
 *	GCS_RESULTSTR. However, The DefWindowProc() on English Windows 2000
 *	arbitrarily converts all non-Latin-1 characters in the composition to
 *	"?".
 *
 *	This function correctly processes the composition data and sends the
 *	UNICODE values of the composed characters to TK's event queue.
 *
 * Results:
1636
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
1651

1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667

1668
1669
1670
1671
1672
1673
1674
1558
1559
1560
1561
1562
1563
1564

1565
1566
1567
1568
1569
1570
1571
1572

1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1596







-
+







-
+















-
+







    }

    hIMC = ImmGetContext(hwnd);
    if (!hIMC) {
	return 0;
    }

    n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
    n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0);

    if (n > 0) {
	WCHAR *buff = (WCHAR *) ckalloc(n);
	TkWindow *winPtr;
	XEvent event;
	int i;

	n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, (unsigned) n) / 2;
	n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, buff, (unsigned) n) / 2;

	/*
	 * Set up the fields pertinent to key event.
	 *
	 * We set send_event to the special value of -3, so that TkpGetString
	 * in tkWinKey.c knows that keycode already contains a UNICODE
	 * char and there's no need to do encoding conversion.
	 *
	 * Note that the event *must* be zeroed out first; Tk plays cunning
	 * games with the overalls structure. [Bug 2992129]
	 */

	winPtr = (TkWindow *) Tk_HWNDToWindow(hwnd);

	memset(&event, 0, sizeof(XEvent));
	event.xkey.serial = LastKnownRequestProcessed(winPtr->display)++;
	event.xkey.serial = winPtr->display->request++;
	event.xkey.send_event = -3;
	event.xkey.display = winPtr->display;
	event.xkey.window = winPtr->window;
	event.xkey.root = RootWindow(winPtr->display, winPtr->screenNum);
	event.xkey.subwindow = None;
	event.xkey.state = TkWinGetModifierState();
	event.xkey.time = TkpGetMS();
1705
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
1627
1628
1629
1630
1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641







-
+








/*
 *----------------------------------------------------------------------
 *
 * TkWinResendEvent --
 *
 *	This function converts an X event into a Windows event and invokes the
 *	specified window function.
 *	specified windo function.
 *
 * Results:
 *	A standard Windows result.
 *
 * Side effects:
 *	Invokes the window function
 *
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
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







-
-
-
-
-
-
-
-













-
-
-
-
-
-








-
+







	msg = WM_MBUTTONDOWN;
	wparam = MK_MBUTTON;
	break;
    case Button3:
	msg = WM_RBUTTONDOWN;
	wparam = MK_RBUTTON;
	break;
    case Button8:
	msg = WM_XBUTTONDOWN;
	wparam = MAKEWPARAM(MK_XBUTTON1, XBUTTON1);
	break;
    case Button9:
	msg = WM_XBUTTONDOWN;
	wparam = MAKEWPARAM(MK_XBUTTON2, XBUTTON2);
	break;
    default:
	return 0;
    }

    if (eventPtr->xbutton.state & Button1Mask) {
	wparam |= MK_LBUTTON;
    }
    if (eventPtr->xbutton.state & Button2Mask) {
	wparam |= MK_MBUTTON;
    }
    if (eventPtr->xbutton.state & Button3Mask) {
	wparam |= MK_RBUTTON;
    }
    if (eventPtr->xbutton.state & Button4Mask) {
	wparam |= MK_XBUTTON1;
    }
    if (eventPtr->xbutton.state & Button5Mask) {
	wparam |= MK_XBUTTON2;
    }
    if (eventPtr->xbutton.state & ShiftMask) {
	wparam |= MK_SHIFT;
    }
    if (eventPtr->xbutton.state & ControlMask) {
	wparam |= MK_CONTROL;
    }
    lparam = MAKELPARAM((short) eventPtr->xbutton.x,
	    (short) eventPtr->xbutton.y);
    return CallWindowProcW(wndproc, hwnd, msg, wparam, lparam);
    return CallWindowProc(wndproc, hwnd, msg, wparam, lparam);
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetMS --
 *
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
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







-
-
+
+









-
+




-
+







 *----------------------------------------------------------------------
 *
 * Tk_GetUserInactiveTime --
 *
 *	Return the number of milliseconds the user was inactive.
 *
 * Results:
 *	Milliseconds of user inactive time or -1 if GetLastInputInfo
 *	returns an error.
 *	Milliseconds of user inactive time or -1 if the user32.dll doesn't
 *	have the symbol GetLastInputInfo or GetLastInputInfo returns an error.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

long
Tk_GetUserInactiveTime(
     TCL_UNUSED(Display *))
     Display *dpy)		/* Ignored on Windows */
{
    LASTINPUTINFO li;

    li.cbSize = sizeof(li);
    if (!GetLastInputInfo(&li)) {
    if (!(BOOL)GetLastInputInfo(&li)) {
	return -1;
    }

    /*
     * Last input info is in milliseconds, since restart time.
     */

1977
1978
1979
1980
1981
1982
1983
1984

1985
1986
1987
1988
1989
1990
1991
1992

1993
1994
1995
1996
1997
1998
1999
1885
1886
1887
1888
1889
1890
1891

1892
1893
1894
1895
1896
1897
1898
1899

1900
1901
1902
1903
1904
1905
1906
1907







-
+







-
+







 *
 *	Reset the user inactivity timer
 *
 * Results:
 *	none
 *
 * Side effects:
 *	The user inactivity timer of the underlying windowing system is reset
 *	The user inactivity timer of the underlaying windowing system is reset
 *	to zero.
 *
 *----------------------------------------------------------------------
 */

void
Tk_ResetUserInactiveTime(
    TCL_UNUSED(Display *))
    Display *dpy)
{
    INPUT inp;

    inp.type = INPUT_MOUSE;
    inp.mi.dx = 0;
    inp.mi.dy = 0;
    inp.mi.mouseData = 0;

Changes to win/ttkWinMonitor.c.

1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32




-
+



















-
+







#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#endif

#include "tkWinInt.h"
#include <tkWinInt.h>
#include "ttk/ttkTheme.h"

#if !defined(WM_THEMECHANGED)
#define WM_THEMECHANGED 0x031A
#endif

static LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);

/*
 * RegisterSystemColors --
 *	Register all known Windows system colors (as per GetSysColor) as Tk
 *	named colors.
 */

typedef struct {
    const char *name;
    int index;
} SystemColorEntry;

static const SystemColorEntry sysColors[] = {
static SystemColorEntry sysColors[] = {
	{ "System3dDarkShadow",		COLOR_3DDKSHADOW },
	{ "System3dLight",		COLOR_3DLIGHT },
	{ "SystemActiveBorder",		COLOR_ACTIVEBORDER },
	{ "SystemActiveCaption",	COLOR_ACTIVECAPTION },
	{ "SystemAppWorkspace",		COLOR_APPWORKSPACE },
	{ "SystemBackground",		COLOR_BACKGROUND },
	{ "SystemButtonFace",		COLOR_BTNFACE },
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76


77
78

79
80
81
82
83
84
85
86



87
88
89
90
91
92


93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74


75
76
77

78
79
80
81
82
83



84
85
86
87
88
89
90


91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119







-
+














-
+

-
-
+
+

-
+





-
-
-
+
+
+




-
-
+
+


-
+
















-
+







	{ "SystemWindowText",		COLOR_WINDOWTEXT },
	{ NULL, 0 }
};

static void RegisterSystemColors(Tcl_Interp *interp)
{
    Ttk_ResourceCache cache = Ttk_GetResourceCache(interp);
    const SystemColorEntry *sysColor;
    SystemColorEntry *sysColor;

    for (sysColor = sysColors; sysColor->name; ++sysColor) {
	DWORD pixel = GetSysColor(sysColor->index);
	XColor colorSpec;
	colorSpec.red = GetRValue(pixel) * 257;
	colorSpec.green = GetGValue(pixel) * 257;
	colorSpec.blue = GetBValue(pixel) * 257;
	Ttk_RegisterNamedColor(cache, sysColor->name, &colorSpec);
    }
}

static HWND
CreateThemeMonitorWindow(HINSTANCE hinst, Tcl_Interp *interp)
{
    WNDCLASSEXW wc;
    WNDCLASSEX wc;
    HWND       hwnd = NULL;
    WCHAR      title[32] = L"TtkMonitorWindow";
    WCHAR      name[32] = L"TtkMonitorClass";
    TCHAR      title[32] = TEXT("TtkMonitorWindow");
    TCHAR      name[32] = TEXT("TtkMonitorClass");

    wc.cbSize        = sizeof(WNDCLASSEXW);
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hinst;
    wc.hIcon         = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
    wc.hIconSm       = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
    wc.hCursor       = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszMenuName  = name;
    wc.lpszClassName = name;

    if (RegisterClassExW(&wc)) {
	hwnd = CreateWindowW( name, title, WS_OVERLAPPEDWINDOW,
    if (RegisterClassEx(&wc)) {
	hwnd = CreateWindow( name, title, WS_OVERLAPPEDWINDOW,
	    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
	    NULL, NULL, hinst, NULL );
	SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) interp);
	SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) interp);
	ShowWindow(hwnd, SW_HIDE);
	UpdateWindow(hwnd);
    }
    return hwnd;
}

static void
DestroyThemeMonitorWindow(void *clientData)
{
    HWND hwnd = (HWND)clientData;
    DestroyWindow(hwnd);
}

static LRESULT WINAPI
WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
    Tcl_Interp *interp = (Tcl_Interp *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
    Tcl_Interp *interp = (Tcl_Interp *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
    Ttk_Theme theme;

    switch (msg) {
    case WM_DESTROY:
	break;

    case WM_SYSCOLORCHANGE:
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148

149
150
151
152
153
154

155
156
157
158
159
160
161







-
+








-






-
+






	theme = Ttk_GetCurrentTheme(interp);
	if (theme) {
	    Ttk_UseTheme(interp, theme);
	    /* @@@ What to do about errors here? */
	}
	break;
    }
    return DefWindowProcW(hwnd, msg, wp, lp);
    return DefWindowProc(hwnd, msg, wp, lp);
}

/*
 * Windows-specific platform initialization:
 */

MODULE_SCOPE int TtkWinTheme_Init(Tcl_Interp *, HWND hwnd);
MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *, HWND hwnd);
MODULE_SCOPE int Ttk_WinPlatformInit(Tcl_Interp *interp);

MODULE_SCOPE int Ttk_WinPlatformInit(Tcl_Interp *interp)
{
    HWND hwnd;

    hwnd = CreateThemeMonitorWindow(Tk_GetHINSTANCE(), interp);
    Ttk_RegisterCleanup(interp, hwnd, DestroyThemeMonitorWindow);
    Ttk_RegisterCleanup(interp, (ClientData)hwnd, DestroyThemeMonitorWindow);

    TtkWinTheme_Init(interp, hwnd);
    TtkXPTheme_Init(interp, hwnd);

    return TCL_OK;
}

Changes to win/ttkWinTheme.c.

1

2
3
4
5
6
7
8

9
10

11
12
13
14
15
16
17

1
2
3
4
5
6
7

8
9

10
11
12
13
14
15
16
17
-
+






-
+

-
+







/* winTheme.c - Copyright © 2004 Pat Thoyts <[email protected]>
/* winTheme.c - Copyright (C) 2004 Pat Thoyts <[email protected]>
 */

#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#endif

#include "tkWinInt.h"
#include <tkWinInt.h>

#ifndef DFCS_HOT	/* Windows 98/Me, Windows 2000/XP only */
#ifndef DFCS_HOT	/* Windows 98/Me, Windows 200/XP only */
#define DFCS_HOT 0
#endif

#include "ttk/ttkTheme.h"

/*
 * BoxToRect --
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101



102
103
104
105
106
107


108
109
110
111

112
113
114
115

116
117
118

119
120
121
122
123
124
125
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98



99
100
101
102
103
104



105
106
107
108
109

110
111
112
113

114
115
116

117
118
119
120
121
122
123
124







-
+




















-
+






-
+













-
-
-
+
+
+



-
-
-
+
+



-
+



-
+


-
+







    }
}

/*------------------------------------------------------------------------
 * +++ State tables for FrameControlElements.
 */

static const Ttk_StateTable checkbutton_statemap[] = { /* see also SF#1865898 */
static Ttk_StateTable checkbutton_statemap[] = { /* see also SF#1865898 */
    { DFCS_BUTTON3STATE|DFCS_CHECKED|DFCS_INACTIVE,
    	TTK_STATE_ALTERNATE|TTK_STATE_DISABLED, 0 },
    { DFCS_BUTTON3STATE|DFCS_CHECKED|DFCS_PUSHED,
    	TTK_STATE_ALTERNATE|TTK_STATE_PRESSED, 0 },
    { DFCS_BUTTON3STATE|DFCS_CHECKED|DFCS_HOT,
    	TTK_STATE_ALTERNATE|TTK_STATE_ACTIVE, 0 },
    { DFCS_BUTTON3STATE|DFCS_CHECKED,
    	TTK_STATE_ALTERNATE, 0 },

    { DFCS_CHECKED|DFCS_INACTIVE, TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0 },
    { DFCS_CHECKED|DFCS_PUSHED,   TTK_STATE_SELECTED|TTK_STATE_PRESSED, 0 },
    { DFCS_CHECKED|DFCS_HOT,      TTK_STATE_SELECTED|TTK_STATE_ACTIVE, 0 },
    { DFCS_CHECKED,	          TTK_STATE_SELECTED, 0 },

    { DFCS_INACTIVE, TTK_STATE_DISABLED, 0 },
    { DFCS_PUSHED,   TTK_STATE_PRESSED, 0 },
    { DFCS_HOT,      TTK_STATE_ACTIVE, 0 },
    { 0, 0, 0 },
};

static const Ttk_StateTable pushbutton_statemap[] = {
static Ttk_StateTable pushbutton_statemap[] = {
    { DFCS_INACTIVE,	  TTK_STATE_DISABLED, 0 },
    { DFCS_PUSHED,	  TTK_STATE_PRESSED, 0 },
    { DFCS_HOT,		  TTK_STATE_ACTIVE, 0 },
    { 0, 0, 0 }
};

static const Ttk_StateTable arrow_statemap[] = {
static Ttk_StateTable arrow_statemap[] = {
    { DFCS_INACTIVE,            TTK_STATE_DISABLED, 0 },
    { DFCS_PUSHED | DFCS_FLAT,  TTK_STATE_PRESSED,  0 },
    { 0, 0, 0 }
};

/*------------------------------------------------------------------------
 * +++ FrameControlElement --
 * 	General-purpose element for things drawn with DrawFrameControl
 */
typedef struct {
    const char *name;		/* element name */
    int classId;		/* class id for DrawFrameControl */
    int partId;			/* part id for DrawFrameControl  */
    unsigned cxId;		/* system metric ids for width/height... */
    unsigned cyId;		/* ... or size if FIXEDSIZE bit set */
    const Ttk_StateTable *stateMap;	/* map Tk states to Win32 flags */
    int cxId;			/* system metric ids for width/height... */
    int cyId;			/* ... or size if FIXEDSIZE bit set */
    Ttk_StateTable *stateMap;	/* map Tk states to Win32 flags */
    Ttk_Padding margins;	/* additional placement padding */
} FrameControlElementData;

#define BASE_DIM    16
#define _FIXEDSIZE  0x80000000UL
#define _HALFMETRIC 0x40000000UL
#define _FIXEDSIZE  0x80000000L
#define _HALFMETRIC 0x40000000L
#define FIXEDSIZE(id) (id|_FIXEDSIZE)
#define HALFMETRIC(id) (id|_HALFMETRIC)
#define GETMETRIC(m) \
    ((m) & _FIXEDSIZE ? (int)((m) & ~_FIXEDSIZE) : GetSystemMetrics((m)&0xFFFFFFF))
    ((m) & _FIXEDSIZE ? (int)((m) & ~_FIXEDSIZE) : GetSystemMetrics((m)&0x0fffffff))

static FrameControlElementData FrameControlElements[] = {
    { "Checkbutton.indicator",
	DFC_BUTTON, DFCS_BUTTONCHECK, FIXEDSIZE(BASE_DIM), FIXEDSIZE(BASE_DIM),
	DFC_BUTTON, DFCS_BUTTONCHECK, FIXEDSIZE(13), FIXEDSIZE(13),
	checkbutton_statemap, {0,0,4,0} },
    { "Radiobutton.indicator",
    	DFC_BUTTON, DFCS_BUTTONRADIO, FIXEDSIZE(BASE_DIM), FIXEDSIZE(BASE_DIM),
    	DFC_BUTTON, DFCS_BUTTONRADIO, FIXEDSIZE(13), FIXEDSIZE(13),
	checkbutton_statemap, {0,0,4,0} },
    { "uparrow",
    	DFC_SCROLL, DFCS_SCROLLUP, SM_CXVSCROLL, SM_CYVSCROLL,
	arrow_statemap, {0,0,0,0} },
    { "downarrow",
    	DFC_SCROLL, DFCS_SCROLLDOWN, SM_CXVSCROLL, SM_CYVSCROLL,
	arrow_statemap, {0,0,0,0} },
141
142
143
144
145
146
147
148

149
150
151

152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182

183
184
185
186

187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215



216
217
218
219
220
221

222
223
224

225
226
227
228
229
230
231
232

233
234

235
236
237
238

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274


275
276
277
278
279
280

281
282
283

284
285
286
287
288
289
290
291

292
293

294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332

333
334

335
336
337


338
339
340
341
342

343
344
345
346

347
348

349
350

351
352
353
354
355
356
357
140
141
142
143
144
145
146

147



148


149

150
151
152













153
154

155
156
157
158
159

160



161


162

163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189



190
191
192
193
194
195



196



197
198
199
200
201
202
203


204


205


206

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

240
241


242
243
244
245
246



247



248
249
250
251
252
253
254


255


256


257

258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

291
292

293
294

295
296


297
298
299
300
301


302




303
304

305
306

307
308
309
310
311
312
313
314







-
+
-
-
-
+
-
-

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-


-





-
+
-
-
-
+
-
-

-
+










-
+















-
-
-
+
+
+



-
-
-
+
-
-
-
+






-
-
+
-
-
+
-
-

-
+















-
+
















-
+

-
-
+
+



-
-
-
+
-
-
-
+






-
-
+
-
-
+
-
-

-
+













-
+


















-
+

-
+

-
+

-
-
+
+



-
-
+
-
-
-
-
+

-
+

-
+








    { 0,0,0,0,0,0, {0,0,0,0} }
};

/* ---------------------------------------------------------------------- */

static void FrameControlElementSize(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    FrameControlElementData *p = (FrameControlElementData *)clientData;
    FrameControlElementData *p = clientData;
    int cx = GETMETRIC(p->cxId);
    int cy = GETMETRIC(p->cyId);

    if ((p->cxId & _FIXEDSIZE) && cx == BASE_DIM) {
	double scalingLevel = TkScalingLevel(tkwin);
	cx *= scalingLevel;
	cy *= scalingLevel;

	/*
	 * Update the corresponding element of the array FrameControlElements
	 */
	p->cxId = FIXEDSIZE(cx);
	p->cyId = FIXEDSIZE(cy);
    }

    if (p->cxId & _HALFMETRIC) cx /= 2;
    if (p->cyId & _HALFMETRIC) cy /= 2;

    *widthPtr = cx + Ttk_PaddingWidth(p->margins);
    *heightPtr = cy + Ttk_PaddingHeight(p->margins);
}

static void FrameControlElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    FrameControlElementData *elementData = (FrameControlElementData *)clientData;
    FrameControlElementData *elementData = clientData;
    RECT rc = BoxToRect(Ttk_PadBox(b, elementData->margins));
    TkWinDCState dcState;
    HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);

    DrawFrameControl(hdc, &rc,
	elementData->classId,
	elementData->partId|Ttk_StateTableLookup(elementData->stateMap, state));
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec FrameControlElementSpec = {
static Ttk_ElementSpec FrameControlElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    FrameControlElementSize,
    FrameControlElementDraw
};

/*----------------------------------------------------------------------
 * +++ Border element implementation.
 */

typedef struct {
    Tcl_Obj	*reliefObj;
} BorderElement;

static const Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-relief",TK_OPTION_RELIEF, offsetof(BorderElement,reliefObj), "flat" },
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
static Ttk_ElementOptionSpec BorderElementOptions[] = {
    { "-relief",TK_OPTION_RELIEF,Tk_Offset(BorderElement,reliefObj), "flat" },
    {NULL, 0, 0, NULL}
};

static void BorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE);
    paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE);
}

static void BorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    BorderElement *border = (BorderElement *)elementRecord;
    BorderElement *border = elementRecord;
    RECT rc = BoxToRect(b);
    int relief = TK_RELIEF_FLAT;
    TkWinDCState dcState;
    HDC hdc;

    Tk_GetReliefFromObj(NULL, border->reliefObj, &relief);

    if (relief != TK_RELIEF_FLAT) {
	UINT xFlags = (relief == TK_RELIEF_SOLID) ? BF_FLAT : 0;
	hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
	DrawEdge(hdc, &rc, ReliefToEdge(relief), BF_RECT | xFlags);
	TkWinReleaseDrawableDC(d, hdc, &dcState);
    }
}

static const Ttk_ElementSpec BorderElementSpec = {
static Ttk_ElementSpec BorderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(BorderElement),
    BorderElementOptions,
    BorderElementSize,
    BorderElementDraw
};

/*
 * Entry field borders:
 * Sunken border; also fill with window color.
 */

typedef struct {
    Tcl_Obj	*backgroundObj;
} FieldElement;

static const Ttk_ElementOptionSpec FieldElementOptions[] = {
static Ttk_ElementOptionSpec FieldElementOptions[] = {
    { "-fieldbackground", TK_OPTION_BORDER,
    	offsetof(FieldElement,backgroundObj), "white" },
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
    	Tk_Offset(FieldElement,backgroundObj), "white" },
    { NULL, 0, 0, NULL }
};

static void FieldElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE);
    paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE);
}

static void FieldElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    FieldElement *field = (FieldElement *)elementRecord;
    FieldElement *field = elementRecord;
    Tk_3DBorder bg = Tk_Get3DBorderFromObj(tkwin, field->backgroundObj);
    RECT rc = BoxToRect(b);
    TkWinDCState dcState;
    HDC hdc;

    Tk_Fill3DRectangle(
	tkwin, d, bg, b.x, b.y, b.width, b.height, 0, TK_RELIEF_FLAT);

    hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT);
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec FieldElementSpec = {
static Ttk_ElementSpec FieldElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FieldElement),
    FieldElementOptions,
    FieldElementSize,
    FieldElementDraw
};

/*------------------------------------------------------------------------
 * +++ Button borders.
 *	Drawn with DrawFrameControl instead of DrawEdge;
 *	Also draw default indicator and focus ring.
 */
typedef struct {
    Tcl_Obj	*reliefObj;
    Tcl_Obj	*highlightColorObj;
    Tcl_Obj	*defaultStateObj;
} ButtonBorderElement;

static const Ttk_ElementOptionSpec ButtonBorderElementOptions[] = {
static Ttk_ElementOptionSpec ButtonBorderElementOptions[] = {
    { "-relief",TK_OPTION_RELIEF,
	offsetof(ButtonBorderElement,reliefObj), "flat" },
	Tk_Offset(ButtonBorderElement,reliefObj), "flat" },
    { "-highlightcolor",TK_OPTION_COLOR,
	offsetof(ButtonBorderElement,highlightColorObj), "black" },
	Tk_Offset(ButtonBorderElement,highlightColorObj), "black" },
    { "-default", TK_OPTION_ANY,
	offsetof(ButtonBorderElement,defaultStateObj), "disabled" },
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
	Tk_Offset(ButtonBorderElement,defaultStateObj), "disabled" },
    {NULL, 0, 0, NULL}
};

static void ButtonBorderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord;
    ButtonBorderElement *bd = elementRecord;
    int relief = TK_RELIEF_RAISED;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    short int cx, cy;

    Tk_GetReliefFromObj(NULL, bd->reliefObj, &relief);
    Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState);
    cx = GetSystemMetrics(SM_CXEDGE);
    cy = GetSystemMetrics(SM_CYEDGE);

366
367
368
369
370
371
372
373
374

375
376

377
378
379
380

381
382

383
384
385
386
387
388
389
323
324
325
326
327
328
329


330


331


332

333
334

335
336
337
338
339
340
341
342







-
-
+
-
-
+
-
-

-
+

-
+







    cx += 2;
    cy += 2;

    *paddingPtr = Ttk_MakePadding(cx,cy,cx,cy);
}

static void ButtonBorderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    ButtonBorderElement *bd = (ButtonBorderElement *)elementRecord;
    ButtonBorderElement *bd = elementRecord;
    int relief = TK_RELIEF_FLAT;
    Ttk_ButtonDefaultState defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    int defaultState = TTK_BUTTON_DEFAULT_DISABLED;
    TkWinDCState dcState;
    HDC hdc;
    RECT rc;

    Tk_GetReliefFromObj(NULL, bd->reliefObj, &relief);
    Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState);

410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433

434
435
436

437
438
439
440
441
442
443
444
445


446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476
477


478
479
480
481
482
483

484
485

486
487
488
489

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518

519
520
521
522
523
524
525
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382
383



384



385
386
387
388
389
390




391
392


393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

419
420


421
422
423
424
425
426


427


428


429

430

431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+













-
-
-
+
-
-
-
+





-
-
-
-
+
+
-
-










-
+















-
+

-
-
+
+




-
-
+
-
-
+
-
-

-
+
-




















-
+






-
+







	short int borderWidth = 3;	/* @@@ Use GetSystemMetrics?*/
	rc = BoxToRect(Ttk_PadBox(b, Ttk_UniformPadding(borderWidth)));
    	DrawFocusRect(hdc, &rc);
    }
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec ButtonBorderElementSpec = {
static Ttk_ElementSpec ButtonBorderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ButtonBorderElement),
    ButtonBorderElementOptions,
    ButtonBorderElementSize,
    ButtonBorderElementDraw
};

/*------------------------------------------------------------------------
 * +++ Focus element.
 * 	Draw dashed focus rectangle.
 */

static void FocusElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    *paddingPtr = Ttk_UniformPadding(1);
}

static void FocusElementDraw(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    if (state & TTK_STATE_FOCUS) {
	RECT rc = BoxToRect(b);
	TkWinDCState dcState;
	HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    	DrawFocusRect(hdc, &rc);
	TkWinReleaseDrawableDC(d, hdc, &dcState);
    }
}

static const Ttk_ElementSpec FocusElementSpec = {
static Ttk_ElementSpec FocusElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    FocusElementSize,
    FocusElementDraw
};

/* FillFocusElement --
 * 	Draws a focus ring filled with the selection color
 */

typedef struct {
    Tcl_Obj *fillColorObj;
} FillFocusElement;

static const Ttk_ElementOptionSpec FillFocusElementOptions[] = {
static Ttk_ElementOptionSpec FillFocusElementOptions[] = {
    { "-focusfill", TK_OPTION_COLOR,
	offsetof(FillFocusElement,fillColorObj), "white" },
    {NULL, TK_OPTION_BOOLEAN, 0, NULL}
	Tk_Offset(FillFocusElement,fillColorObj), "white" },
    {NULL, 0, 0, NULL}
};

	/* @@@ FIX THIS */
static void FillFocusElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    FillFocusElement *focus = (FillFocusElement *)elementRecord;
    FillFocusElement *focus = elementRecord;

    if (state & TTK_STATE_FOCUS) {
	RECT rc = BoxToRect(b);
	TkWinDCState dcState;
	XColor *fillColor = Tk_GetColorFromObj(tkwin, focus->fillColorObj);
	GC gc = Tk_GCForColor(fillColor, d);
	HDC hdc;

	XFillRectangle(Tk_Display(tkwin),d,gc, b.x,b.y,b.width,b.height);
	hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    	DrawFocusRect(hdc, &rc);
	TkWinReleaseDrawableDC(d, hdc, &dcState);
    }
}

/*
 * ComboboxFocusElement --
 * 	Read-only comboboxes have a filled focus ring, editable ones do not.
 */
static void ComboboxFocusElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned int state)
{
    if (state & TTK_STATE_READONLY) {
    	FillFocusElementDraw(clientData, elementRecord, tkwin, d, b, state);
    }
}

static const Ttk_ElementSpec ComboboxFocusElementSpec = {
static Ttk_ElementSpec ComboboxFocusElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(FillFocusElement),
    FillFocusElementOptions,
    FocusElementSize,
    ComboboxFocusElementDraw
};

538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561

562
563
564

565
566
567
568

569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610



611
612
613
614
615

616
617

618
619
620
621
622


623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673


674
675

676
677
678
679
680

681
682

683
684
685
686
687


688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703


704
705
706
707
708
709
710
711
712
713
714
715
716

717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901

902
903
904

905
906
907
908
909
910
911
912
913
914


915
916
917
918
919
920
921
922
923
924
925
926

927
928
929
930
931
932
933
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500

501



502


503

504
505
506
507
508
509

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543



544
545
546
547
548
549


550


551


552


553
554
555
556
557
558
559
560
561
562
563
564
565
566




567
568


569
570
571
572
573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599


600
601
602

603
604
605
606


607


608


609


610
611
612
613
614
615
616
617
618
619
620
621
622
623




624
625


626
627
628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644
645
646
647










































































































































































648



649



650
651
652
653
654
655
656




657
658


659
660
661
662

663
664
665
666

667
668
669
670
671
672
673
674







-
+







-
+







-
+
-
-
-
+
-
-

-
+





-
+

















-
+















-
-
-
+
+
+



-
-
+
-
-
+
-
-

-
-
+
+












-
-
-
-
+
+
-
-














-
+
















-
-
+
+

-
+



-
-
+
-
-
+
-
-

-
-
+
+












-
-
-
-
+
+
-
-










-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
-
-
-
+






-
-
-
-
+
+
-
-




-




-
+








static const WORD Pattern[] = {
    0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa
};

static void TroughClientDataDeleteProc(void *clientData)
{
    TroughClientData *cd = (TroughClientData *)clientData;
    TroughClientData *cd = clientData;
    DeleteObject(cd->PatternBrush);
    DeleteObject(cd->PatternBitmap);
    ckfree(clientData);
}

static TroughClientData *TroughClientDataInit(Tcl_Interp *interp)
{
    TroughClientData *cd = (TroughClientData *)ckalloc(sizeof(*cd));
    TroughClientData *cd = ckalloc(sizeof(*cd));
    cd->PatternBitmap = CreateBitmap(8, 8, 1, 1, Pattern);
    cd->PatternBrush  = CreatePatternBrush(cd->PatternBitmap);
    Ttk_RegisterCleanup(interp, cd, TroughClientDataDeleteProc);
    return cd;
}

static void TroughElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    TroughClientData *cd = (TroughClientData *)clientData;
    TroughClientData *cd = clientData;
    TkWinDCState dcState;
    HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    HBRUSH hbr;
    COLORREF bk, oldbk, oldtxt;

    hbr = (HBRUSH)SelectObject(hdc, GetSysColorBrush(COLOR_SCROLLBAR));
    hbr = SelectObject(hdc, GetSysColorBrush(COLOR_SCROLLBAR));
    bk = GetSysColor(COLOR_3DHIGHLIGHT);
    oldtxt = SetTextColor(hdc, GetSysColor(COLOR_3DFACE));
    oldbk = SetBkColor(hdc, bk);

    /* WAS: if (bk (COLOR_3DHIGHLIGHT) == GetSysColor(COLOR_WINDOW)) ... */
    if (GetSysColor(COLOR_SCROLLBAR) == GetSysColor(COLOR_BTNFACE)) {
	/* Draw using the pattern brush */
	SelectObject(hdc, cd->PatternBrush);
    }

    PatBlt(hdc, b.x, b.y, b.width, b.height, PATCOPY);
    SetBkColor(hdc, oldbk);
    SetTextColor(hdc, oldtxt);
    SelectObject(hdc, hbr);
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec TroughElementSpec = {
static Ttk_ElementSpec TroughElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TtkNullElementSize,
    TroughElementDraw
};

/*------------------------------------------------------------------------
 * +++ Thumb element.
 */

typedef struct {
    Tcl_Obj *orientObj;
} ThumbElement;

static const Ttk_ElementOptionSpec ThumbElementOptions[] = {
    { "-orient", TK_OPTION_ANY, offsetof(ThumbElement,orientObj),"horizontal"},
    { NULL, TK_OPTION_BOOLEAN, 0, NULL }
static Ttk_ElementOptionSpec ThumbElementOptions[] = {
    { "-orient", TK_OPTION_ANY,Tk_Offset(ThumbElement,orientObj),"horizontal"},
    { NULL, 0, 0, NULL }
};

static void ThumbElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    ThumbElement *thumbPtr = (ThumbElement *)elementRecord;
    Ttk_Orient orient;
    ThumbElement *thumbPtr = elementRecord;
    int orient;

    Ttk_GetOrientFromObj(NULL, thumbPtr->orientObj, &orient);
    if (orient == TTK_ORIENT_HORIZONTAL) {
	*widthPtr = GetSystemMetrics(SM_CXHTHUMB);
	*heightPtr = GetSystemMetrics(SM_CYHSCROLL);
    } else {
	*widthPtr = GetSystemMetrics(SM_CXVSCROLL);
	*heightPtr = GetSystemMetrics(SM_CYVTHUMB);
    }
}

static void ThumbElementDraw(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    RECT rc = BoxToRect(b);
    TkWinDCState dcState;
    HDC hdc;

    /* Windows doesn't show a thumb when the scrollbar is disabled */
    if (state & TTK_STATE_DISABLED)
	return;

    hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_MIDDLE);
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec ThumbElementSpec = {
static Ttk_ElementSpec ThumbElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(ThumbElement),
    ThumbElementOptions,
    ThumbElementSize,
    ThumbElementDraw
};

/* ----------------------------------------------------------------------
 * The slider element is the shaped thumb used in the slider widget.
 * Windows likes to call this a trackbar.
 */

typedef struct {
    Tcl_Obj *orientObj;  /* orientation of the slider widget */
} SliderElement;

static const Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-orient", TK_OPTION_ANY, offsetof(SliderElement,orientObj),
static Ttk_ElementOptionSpec SliderElementOptions[] = {
    { "-orient", TK_OPTION_ANY, Tk_Offset(SliderElement,orientObj),
      "horizontal" },
      { NULL, TK_OPTION_BOOLEAN, 0, NULL }
      { NULL, 0, 0, NULL }
};

static void SliderElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(Tk_Window),
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    TCL_UNUSED(Ttk_Padding *))
{
    SliderElement *slider = (SliderElement *)elementRecord;
    Ttk_Orient orient;
    SliderElement *slider = elementRecord;
    int orient;

    Ttk_GetOrientFromObj(NULL, slider->orientObj, &orient);
    if (orient == TTK_ORIENT_HORIZONTAL) {
	*widthPtr = (GetSystemMetrics(SM_CXHTHUMB) / 2) | 1;
	*heightPtr = GetSystemMetrics(SM_CYHSCROLL);
    } else {
	*widthPtr = GetSystemMetrics(SM_CXVSCROLL);
	*heightPtr = (GetSystemMetrics(SM_CYVTHUMB) / 2) | 1;
    }
}

static void SliderElementDraw(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    RECT rc = BoxToRect(b);
    TkWinDCState dcState;
    HDC hdc;

    hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);
    DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_MIDDLE);
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec SliderElementSpec = {
static Ttk_ElementSpec SliderElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(SliderElement),
    SliderElementOptions,
    SliderElementSize,
    SliderElementDraw
};

/*------------------------------------------------------------------------
 * +++ Notebook elements.
 */

typedef struct {
    Tcl_Obj *borderWidthObj;
    Tcl_Obj *backgroundObj;
} TabElement;

static const Ttk_ElementOptionSpec TabElementOptions[] = {
    { "-borderwidth", TK_OPTION_PIXELS,
	offsetof(TabElement,borderWidthObj), "1" },
    { "-background", TK_OPTION_BORDER,
	offsetof(TabElement,backgroundObj), DEFAULT_BACKGROUND },
    {0,TK_OPTION_BOOLEAN,0,0}
};

static void TabElementSize(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
{
    TabElement *tab = (TabElement *)elementRecord;
    int borderWidth = 1;
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

    Tk_GetPixelsFromObj(0, tkwin, tab->borderWidthObj, &borderWidth);
    *paddingPtr = Ttk_UniformPadding((short)borderWidth);

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_N:
	    paddingPtr->top = 0;
	    break;
	case TTK_STICK_E:
	    paddingPtr->right = 0;
	    break;
	case TTK_STICK_W:
	    paddingPtr->left = 0;
	    break;
    }
}

static void TabElementDraw(
    TCL_UNUSED(void *), /* clientData */
    void *elementRecord,
    Tk_Window tkwin,
    Drawable d,
    Ttk_Box b,
    Ttk_State state)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
    TabElement *tab = (TabElement *)elementRecord;
    Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj);
    XPoint pts[6];
    double scalingLevel = TkScalingLevel(tkwin);
    int cut = round(2 * scalingLevel);
    Display *disp = Tk_Display(tkwin);
    int borderWidth = 1;

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    if (state & TTK_STATE_SELECTED) {
	/*
	 * Draw slightly outside of the allocated parcel,
	 * to overwrite the client area border.
	 */
	switch (nbTabsStickBit) {
	    default:
	    case TTK_STICK_S:
		b.height += 2;
		break;
	    case TTK_STICK_N:
		b.height += 2; b.y -= 2;
		break;
	    case TTK_STICK_E:
		b.width += 2;
		break;
	    case TTK_STICK_W:
		b.width += 2; b.x -= 2;
		break;
	}
    }

    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    pts[0].x = b.x;  pts[0].y = b.y + b.height-1;
	    pts[1].x = b.x;  pts[1].y = b.y + cut;
	    pts[2].x = b.x + cut;  pts[2].y = b.y;
	    pts[3].x = b.x + b.width-1 - cut;  pts[3].y = b.y;
	    pts[4].x = b.x + b.width-1;  pts[4].y = b.y + cut;
	    pts[5].x = b.x + b.width-1;  pts[5].y = b.y + b.height;
	    break;
	case TTK_STICK_N:
	    pts[0].x = b.x;  pts[0].y = b.y;
	    pts[1].x = b.x;  pts[1].y = b.y + b.height-1 - cut;
	    pts[2].x = b.x + cut;  pts[2].y = b.y + b.height-1;
	    pts[3].x = b.x + b.width-1 - cut;  pts[3].y = b.y + b.height-1;
	    pts[4].x = b.x + b.width-1;  pts[4].y = b.y + b.height-1 - cut;
	    pts[5].x = b.x + b.width-1;  pts[5].y = b.y-1;
	    break;
	case TTK_STICK_E:
	    pts[0].x = b.x + b.width-1;  pts[0].y = b.y;
	    pts[1].x = b.x + cut;  pts[1].y = b.y;
	    pts[2].x = b.x;  pts[2].y = b.y + cut;
	    pts[3].x = b.x;  pts[3].y = b.y + b.height-1 - cut;
	    pts[4].x = b.x + cut;  pts[4].y = b.y + b.height-1;
	    pts[5].x = b.x + b.width;  pts[5].y = b.y + b.height-1;
	    break;
	case TTK_STICK_W:
	    pts[0].x = b.x;  pts[0].y = b.y;
	    pts[1].x = b.x + b.width-1 - cut;  pts[1].y = b.y;
	    pts[2].x = b.x + b.width-1;  pts[2].y = b.y + cut;
	    pts[3].x = b.x + b.width-1;  pts[3].y = b.y + b.height-1 - cut;
	    pts[4].x = b.x + b.width-1 - cut;  pts[4].y = b.y + b.height-1;
	    pts[5].x = b.x-1;  pts[5].y = b.y + b.height-1;
	    break;
    }

    XFillPolygon(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC),
	    pts, 6, Convex, CoordModeOrigin);

    Tcl_GetIntFromObj(NULL, tab->borderWidthObj, &borderWidth);
    while (borderWidth--) {
	XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
		pts, 4, CoordModeOrigin);
	XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
		pts+3, 3, CoordModeOrigin);

	switch (nbTabsStickBit) {
	    default:
	    case TTK_STICK_S:
		++pts[0].x;  ++pts[1].x;  ++pts[2].y;
		++pts[3].y;  --pts[4].x;  --pts[5].x;
		break;
	    case TTK_STICK_N:
		++pts[0].x;  ++pts[1].x;  --pts[2].y;
		--pts[3].y;  --pts[4].x;  --pts[5].x;
		break;
	    case TTK_STICK_E:
		++pts[0].y;  ++pts[1].y;  ++pts[2].x;
		++pts[3].x;  --pts[4].y;  --pts[5].y;
		break;
	    case TTK_STICK_W:
		++pts[0].y;  ++pts[1].y;  --pts[2].x;
		--pts[3].x;  --pts[4].y;  --pts[5].y;
		break;
	}
    }
}

static const Ttk_ElementSpec TabElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TabElement),
    TabElementOptions,
    TabElementSize,
    TabElementDraw
};

static void ClientElementSize(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    TCL_UNUSED(Tk_Window),
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(int *), /* widthPtr */
    TCL_UNUSED(int *), /* heightPtr */
    Ttk_Padding *paddingPtr)
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    paddingPtr->left = paddingPtr->right = GetSystemMetrics(SM_CXEDGE);
    paddingPtr->top = paddingPtr->bottom = GetSystemMetrics(SM_CYEDGE);
}

static void ClientElementDraw(
    TCL_UNUSED(void *), /* clientData */
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    TCL_UNUSED(Ttk_State))
{
    RECT rc = BoxToRect(b);
    TkWinDCState dcState;
    HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState);

    DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_SOFT);
    TkWinReleaseDrawableDC(d, hdc, &dcState);
}

static const Ttk_ElementSpec ClientElementSpec = {
static Ttk_ElementSpec ClientElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    ClientElementSize,
    ClientElementDraw
};

941
942
943
944
945
946
947
948
949


950
951
952
953
954
955
956
957

958
959
960

961
962
963
964
965
966
967

968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992

993
994
995
996
997
998
999
1000
682
683
684
685
686
687
688


689
690
691
692
693
694
695
696
697

698



699





700

701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720

721
722
723
724

725
726
727
728
729
730
731
732
733







-
-
+
+







-
+
-
-
-
+
-
-
-
-
-

-
+



















-




-
+








    TTK_GROUP("Button.border", TTK_FILL_BOTH,
	TTK_GROUP("Button.padding", TTK_FILL_BOTH,
	    TTK_NODE("Button.label", TTK_FILL_BOTH))))

TTK_LAYOUT("TCombobox",
    TTK_GROUP("Combobox.field", TTK_FILL_BOTH,
	TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y)
	TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
	    TTK_GROUP("Combobox.focus", TTK_FILL_BOTH,
	TTK_GROUP("Combobox.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_BOTH,
	    TTK_GROUP("Combobox.focus", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_BOTH,
		TTK_NODE("Combobox.textarea", TTK_FILL_BOTH)))))

TTK_END_LAYOUT_TABLE

/* ---------------------------------------------------------------------- */

MODULE_SCOPE
int TtkWinTheme_Init(
int TtkWinTheme_Init(Tcl_Interp *interp, HWND hwnd)
    Tcl_Interp *interp,
    TCL_UNUSED(HWND));

{
MODULE_SCOPE
int TtkWinTheme_Init(
    Tcl_Interp *interp,
    TCL_UNUSED(HWND))
{
    Ttk_Theme themePtr, parentPtr;
    const FrameControlElementData *fce = FrameControlElements;
    FrameControlElementData *fce = FrameControlElements;

    parentPtr = Ttk_GetTheme(interp, "alt");
    themePtr = Ttk_CreateTheme(interp, "winnative", parentPtr);
    if (!themePtr) {
        return TCL_ERROR;
    }

    Ttk_RegisterElementSpec(themePtr, "border", &BorderElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "Button.border",
	&ButtonBorderElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "field", &FieldElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "focus", &FocusElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "Combobox.focus",
    	&ComboboxFocusElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "thumb", &ThumbElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "slider", &SliderElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "Scrollbar.trough", &TroughElementSpec,
    	TroughClientDataInit(interp));

    Ttk_RegisterElementSpec(themePtr, "tab", &TabElementSpec, NULL);
    Ttk_RegisterElementSpec(themePtr, "client", &ClientElementSpec, NULL);

    for (fce = FrameControlElements; fce->name != 0; ++fce) {
	Ttk_RegisterElementSpec(themePtr, fce->name,
		&FrameControlElementSpec, (void *)fce);
		&FrameControlElementSpec, fce);
    }

    Ttk_RegisterLayouts(themePtr, LayoutTable);

    Tcl_PkgProvide(interp, "ttk::theme::winnative", TTK_VERSION);
    return TCL_OK;
}

Changes to win/ttkWinXPTheme.c.

1
2
3
4
5
6
7



8
9
10
11
12
13
14
15
16
17
18






19
20

21





22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
1
2
3
4



5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39




40
41
42
43
44
45
46




-
-
-
+
+
+










-
+
+
+
+
+
+


+
-
+
+
+
+
+








-
-
-
-







/*
 * Tk theme engine which uses the Windows XP "Visual Styles" API
 * Adapted from Georgios Petasis' XP theme patch.
 *
 * Copyright © 2003 Georgios Petasis, [email protected].
 * Copyright © 2003 Joe English
 * Copyright © 2003 Pat Thoyts
 * Copyright (c) 2003 by Georgios Petasis, [email protected].
 * Copyright (c) 2003 by Joe English
 * Copyright (c) 2003 by Pat Thoyts
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * See also:
 *
 * <URL: http://msdn.microsoft.com/library/en-us/
 *  	shellcc/platform/commctls/userex/refentry.asp >
 */

#include "tkWinInt.h"
#include <tkWinInt.h>
#ifndef HAVE_UXTHEME_H
/* Stub for platforms that lack the XP theme API headers: */
int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) { return TCL_OK; }
#else

#include <windows.h>
#include <uxtheme.h>
#if defined(HAVE_VSSYM32_H) || _MSC_VER > 1500
#include <vssym32.h>
#   include <vssym32.h>
#else
#   include <tmschema.h>
#endif

#include "ttk/ttkTheme.h"

typedef HTHEME  (STDAPICALLTYPE OpenThemeDataProc)(HWND hwnd,
		 LPCWSTR pszClassList);
typedef HRESULT (STDAPICALLTYPE CloseThemeDataProc)(HTHEME hTheme);
typedef HRESULT (STDAPICALLTYPE DrawThemeBackgroundProc)(HTHEME hTheme,
                 HDC hdc, int iPartId, int iStateId, const RECT *pRect,
                 OPTIONAL const RECT *pClipRect);
typedef HRESULT (STDAPICALLTYPE DrawThemeEdgeProc)(HTHEME hTheme,
		 HDC hdc, int iPartId, int iStateId, const RECT *pDestRect,
		 unsigned int uEdge, unsigned int uFlags,
		 OPTIONAL RECT *pContentRect);
typedef HRESULT	(STDAPICALLTYPE GetThemePartSizeProc)(HTHEME,HDC,
		 int iPartId, int iStateId,
		 RECT *prc, enum THEMESIZE eSize, SIZE *psz);
typedef int     (STDAPICALLTYPE GetThemeSysSizeProc)(HTHEME,int);
/* GetThemeTextExtent and DrawThemeText only used with BROKEN_TEXT_ELEMENT */
typedef HRESULT (STDAPICALLTYPE GetThemeTextExtentProc)(HTHEME hTheme, HDC hdc,
		 int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
54
55
56
57
58
59
60

61
62
63
64
65
66
67







-







typedef struct
{
    OpenThemeDataProc			*OpenThemeData;
    CloseThemeDataProc			*CloseThemeData;
    GetThemePartSizeProc		*GetThemePartSize;
    GetThemeSysSizeProc			*GetThemeSysSize;
    DrawThemeBackgroundProc		*DrawThemeBackground;
    DrawThemeEdgeProc			*DrawThemeEdge;
    DrawThemeTextProc		        *DrawThemeText;
    GetThemeTextExtentProc		*GetThemeTextExtent;
    IsThemeActiveProc			*IsThemeActive;
    IsAppThemedProc			*IsAppThemed;

    HWND                                stubWindow;
} XPThemeProcs;
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100

101
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
91
92
93
94
95
96
97

98
99
100
101
102
103
104

105
106

107
108
109
110
111
112
113

114
115
116
117
118
119
120







-
+






-
+

-
+






-







{
    /*
     * Load the library "uxtheme.dll", where the native widget
     * drawing routines are implemented.  This will only succeed
     * if we are running at least on Windows XP.
     */
    HINSTANCE handle;
    *phlib = handle = LoadLibraryW(L"uxtheme.dll");
    *phlib = handle = LoadLibrary(TEXT("uxtheme.dll"));
    if (handle != 0)
    {
	/*
	 * We have successfully loaded the library. Proceed in storing the
	 * addresses of the functions we want to use.
	 */
	XPThemeProcs *procs = (XPThemeProcs *)ckalloc(sizeof(XPThemeProcs));
	XPThemeProcs *procs = ckalloc(sizeof(XPThemeProcs));
#define LOADPROC(name) \
	(0 != (procs->name = (name ## Proc *)(void *)GetProcAddress(handle, #name) ))
	(0 != (procs->name = (name ## Proc *)GetProcAddress(handle, #name) ))

	if (   LOADPROC(OpenThemeData)
	    && LOADPROC(CloseThemeData)
	    && LOADPROC(GetThemePartSize)
	    && LOADPROC(GetThemeSysSize)
	    && LOADPROC(DrawThemeBackground)
	    && LOADPROC(DrawThemeEdge)
	    && LOADPROC(GetThemeTextExtent)
	    && LOADPROC(DrawThemeText)
	    && LOADPROC(IsThemeActive)
	    && LOADPROC(IsAppThemed)
	)
	{
	    return procs;
126
127
128
129
130
131
132
133

134
135
136
137
138
139

140
141
142
143

144
145
146
147
148
149
150
151
152
153
130
131
132
133
134
135
136

137
138
139
140
141
142

143


144

145
146
147

148
149
150
151
152
153
154







-
+





-
+
-
-

-
+


-







 *
 *      Release any theme allocated resources.
 */

static void
XPThemeDeleteProc(void *clientData)
{
    XPThemeData *themeData = (XPThemeData *)clientData;
    XPThemeData *themeData = clientData;
    FreeLibrary(themeData->hlibrary);
    ckfree(clientData);
}

static int
XPThemeEnabled(
XPThemeEnabled(Ttk_Theme theme, void *clientData)
    TCL_UNUSED(Ttk_Theme),
    void *clientData)
{
    XPThemeData *themeData = (XPThemeData *)clientData;
    XPThemeData *themeData = clientData;
    int active = themeData->procs->IsThemeActive();
    int themed = themeData->procs->IsAppThemed();

    return (active && themed);
}

/*
 * BoxToRect --
 * 	Helper routine.  Returns a RECT data structure.
 */
161
162
163
164
165
166
167
168

169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267

268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
162
163
164
165
166
167
168

169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267

268
269
270
271
272
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
295

296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347







-
+




-
+











-
+


















-
+
















-
+








-
+














-
+










-
+










-
+











-
+







-
+







-
+







-
+







-
+







-
+










-
+








-
+







    rc.right = b.x + b.width;
    return rc;
}

/*
 * Map Tk state bitmaps to XP style enumerated values.
 */
static const Ttk_StateTable null_statemap[] = { {0,0,0} };
static Ttk_StateTable null_statemap[] = { {0,0,0} };

/*
 * Pushbuttons (Tk: "Button")
 */
static const Ttk_StateTable pushbutton_statemap[] =
static Ttk_StateTable pushbutton_statemap[] =
{
    { PBS_DISABLED, 	TTK_STATE_DISABLED, 0 },
    { PBS_PRESSED, 	TTK_STATE_PRESSED, 0 },
    { PBS_HOT,		TTK_STATE_ACTIVE, 0 },
    { PBS_DEFAULTED,	TTK_STATE_ALTERNATE, 0 },
    { PBS_NORMAL, 	0, 0 }
};

/*
 * Checkboxes (Tk: "Checkbutton")
 */
static const Ttk_StateTable checkbox_statemap[] =
static Ttk_StateTable checkbox_statemap[] =
{
{CBS_MIXEDDISABLED, 	TTK_STATE_ALTERNATE|TTK_STATE_DISABLED, 0},
{CBS_MIXEDPRESSED, 	TTK_STATE_ALTERNATE|TTK_STATE_PRESSED, 0},
{CBS_MIXEDHOT,  	TTK_STATE_ALTERNATE|TTK_STATE_ACTIVE, 0},
{CBS_MIXEDNORMAL, 	TTK_STATE_ALTERNATE, 0},
{CBS_CHECKEDDISABLED,	TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0},
{CBS_CHECKEDPRESSED,	TTK_STATE_SELECTED|TTK_STATE_PRESSED, 0},
{CBS_CHECKEDHOT,	TTK_STATE_SELECTED|TTK_STATE_ACTIVE, 0},
{CBS_CHECKEDNORMAL,	TTK_STATE_SELECTED, 0},
{CBS_UNCHECKEDDISABLED,	TTK_STATE_DISABLED, 0},
{CBS_UNCHECKEDPRESSED,	TTK_STATE_PRESSED, 0},
{CBS_UNCHECKEDHOT,	TTK_STATE_ACTIVE, 0},
{CBS_UNCHECKEDNORMAL,	0,0 }
};

/*
 * Radiobuttons:
 */
static const Ttk_StateTable radiobutton_statemap[] =
static Ttk_StateTable radiobutton_statemap[] =
{
{RBS_UNCHECKEDDISABLED,	TTK_STATE_ALTERNATE|TTK_STATE_DISABLED, 0},
{RBS_UNCHECKEDNORMAL,	TTK_STATE_ALTERNATE, 0},
{RBS_CHECKEDDISABLED,	TTK_STATE_SELECTED|TTK_STATE_DISABLED, 0},
{RBS_CHECKEDPRESSED,	TTK_STATE_SELECTED|TTK_STATE_PRESSED, 0},
{RBS_CHECKEDHOT,	TTK_STATE_SELECTED|TTK_STATE_ACTIVE, 0},
{RBS_CHECKEDNORMAL,	TTK_STATE_SELECTED, 0},
{RBS_UNCHECKEDDISABLED,	TTK_STATE_DISABLED, 0},
{RBS_UNCHECKEDPRESSED,	TTK_STATE_PRESSED, 0},
{RBS_UNCHECKEDHOT,	TTK_STATE_ACTIVE, 0},
{RBS_UNCHECKEDNORMAL,	0,0 }
};

/*
 * Groupboxes (tk: "frame")
 */
static const Ttk_StateTable groupbox_statemap[] =
static Ttk_StateTable groupbox_statemap[] =
{
{GBS_DISABLED,	TTK_STATE_DISABLED, 0},
{GBS_NORMAL,	0,0 }
};

/*
 * Edit fields (tk: "entry")
 */
static const Ttk_StateTable edittext_statemap[] =
static Ttk_StateTable edittext_statemap[] =
{
    { ETS_DISABLED,	TTK_STATE_DISABLED, 0 },
    { ETS_READONLY,	TTK_STATE_READONLY, 0 },
    { ETS_FOCUSED,	TTK_STATE_FOCUS, 0 },
    { ETS_HOT,		TTK_STATE_ACTIVE, 0 },
    { ETS_NORMAL,	0, 0 }
/* NOT USED: ETS_ASSIST, ETS_SELECTED */
};

/*
 * Combobox text field statemap:
 * Same as edittext_statemap, but doesn't use ETS_READONLY
 * (fixes: #1032409)
 */
static const Ttk_StateTable combotext_statemap[] =
static Ttk_StateTable combotext_statemap[] =
{
    { ETS_DISABLED,	TTK_STATE_DISABLED, 0 },
    { ETS_FOCUSED,	TTK_STATE_FOCUS, 0 },
    { ETS_HOT,		TTK_STATE_ACTIVE, 0 },
    { ETS_NORMAL,	0, 0 }
};

/*
 * Combobox button: (CBP_DROPDOWNBUTTON)
 */
static const Ttk_StateTable combobox_statemap[] = {
static Ttk_StateTable combobox_statemap[] = {
    { CBXS_DISABLED,	TTK_STATE_DISABLED, 0 },
    { CBXS_PRESSED, 	TTK_STATE_PRESSED, 0 },
    { CBXS_HOT, 	TTK_STATE_ACTIVE, 0 },
    { CBXS_HOT, 	TTK_STATE_HOVER, 0 },
    { CBXS_NORMAL, 	0, 0 }
};

/*
 * Toolbar buttons (TP_BUTTON):
 */
static const Ttk_StateTable toolbutton_statemap[] =  {
static Ttk_StateTable toolbutton_statemap[] =  {
    { TS_DISABLED, 	TTK_STATE_DISABLED, 0 },
    { TS_PRESSED,	TTK_STATE_PRESSED, 0 },
    { TS_HOTCHECKED,	TTK_STATE_SELECTED|TTK_STATE_ACTIVE, 0 },
    { TS_CHECKED, 	TTK_STATE_SELECTED, 0 },
    { TS_HOT,  		TTK_STATE_ACTIVE, 0 },
    { TS_NORMAL, 	0,0 }
};

/*
 * Scrollbars (Tk: "Scrollbar.thumb")
 */
static const Ttk_StateTable scrollbar_statemap[] =
static Ttk_StateTable scrollbar_statemap[] =
{
    { SCRBS_DISABLED, 	TTK_STATE_DISABLED, 0 },
    { SCRBS_PRESSED, 	TTK_STATE_PRESSED, 0 },
    { SCRBS_HOT,	TTK_STATE_ACTIVE, 0 },
    { SCRBS_NORMAL, 	0, 0 }
};

static const Ttk_StateTable uparrow_statemap[] =
static Ttk_StateTable uparrow_statemap[] =
{
    { ABS_UPDISABLED,	TTK_STATE_DISABLED, 0 },
    { ABS_UPPRESSED, 	TTK_STATE_PRESSED, 0 },
    { ABS_UPHOT,	TTK_STATE_ACTIVE, 0 },
    { ABS_UPNORMAL, 	0, 0 }
};

static const Ttk_StateTable downarrow_statemap[] =
static Ttk_StateTable downarrow_statemap[] =
{
    { ABS_DOWNDISABLED,	TTK_STATE_DISABLED, 0 },
    { ABS_DOWNPRESSED, 	TTK_STATE_PRESSED, 0 },
    { ABS_DOWNHOT,	TTK_STATE_ACTIVE, 0 },
    { ABS_DOWNNORMAL, 	0, 0 }
};

static const Ttk_StateTable leftarrow_statemap[] =
static Ttk_StateTable leftarrow_statemap[] =
{
    { ABS_LEFTDISABLED,	TTK_STATE_DISABLED, 0 },
    { ABS_LEFTPRESSED, 	TTK_STATE_PRESSED, 0 },
    { ABS_LEFTHOT,	TTK_STATE_ACTIVE, 0 },
    { ABS_LEFTNORMAL, 	0, 0 }
};

static const Ttk_StateTable rightarrow_statemap[] =
static Ttk_StateTable rightarrow_statemap[] =
{
    { ABS_RIGHTDISABLED,TTK_STATE_DISABLED, 0 },
    { ABS_RIGHTPRESSED, TTK_STATE_PRESSED, 0 },
    { ABS_RIGHTHOT,	TTK_STATE_ACTIVE, 0 },
    { ABS_RIGHTNORMAL, 	0, 0 }
};

static const Ttk_StateTable spinbutton_statemap[] =
static Ttk_StateTable spinbutton_statemap[] =
{
    { DNS_DISABLED,	TTK_STATE_DISABLED, 0 },
    { DNS_PRESSED,	TTK_STATE_PRESSED,  0 },
    { DNS_HOT,		TTK_STATE_ACTIVE,   0 },
    { DNS_NORMAL,	0,		    0 },
};

/*
 * Trackbar thumb: (Tk: "scale slider")
 */
static const Ttk_StateTable scale_statemap[] =
static Ttk_StateTable scale_statemap[] =
{
    { TUS_DISABLED, 	TTK_STATE_DISABLED, 0 },
    { TUS_PRESSED, 	TTK_STATE_PRESSED, 0 },
    { TUS_FOCUSED, 	TTK_STATE_FOCUS, 0 },
    { TUS_HOT,		TTK_STATE_ACTIVE, 0 },
    { TUS_NORMAL, 	0, 0 }
};

static const Ttk_StateTable tabitem_statemap[] =
static Ttk_StateTable tabitem_statemap[] =
{
    { TIS_DISABLED,     TTK_STATE_DISABLED, 0 },
    { TIS_SELECTED,     TTK_STATE_SELECTED, 0 },
    { TIS_HOT,          TTK_STATE_ACTIVE,   0 },
    { TIS_FOCUSED,      TTK_STATE_FOCUS,    0 },
    { TIS_NORMAL,       0,                  0 },
};
367
368
369
370
371
372
373
374

375
376
377
378

379
380
381
382
383
384
385






386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429
430
431
432




433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
368
369
370
371
372
373
374

375
376
377
378

379
380






381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

428
429




430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461







-
+



-
+

-
-
-
-
-
-
+
+
+
+
+
+







-
+















-
+

-
+















-
+

-
-
-
-
+
+
+
+




















-
+







 *	This gives bogus metrics for some parts (in particular,
 *	BP_PUSHBUTTONS).  Set the IGNORE_THEMESIZE flag to skip this call.
 */

typedef struct 	/* XP element specifications */
{
    const char	*elementName;	/* Tk theme engine element name */
    const Ttk_ElementSpec *elementSpec;
    Ttk_ElementSpec *elementSpec;
    				/* Element spec (usually GenericElementSpec) */
    LPCWSTR	className;	/* Windows window class name */
    int 	partId;		/* BP_PUSHBUTTON, BP_CHECKBUTTON, etc. */
    const Ttk_StateTable *statemap;	/* Map Tk states to XP states */
    Ttk_StateTable *statemap;	/* Map Tk states to XP states */
    Ttk_Padding	padding;	/* See NOTE-GetThemeMargins */
    unsigned  	flags;
#   define 	IGNORE_THEMESIZE 0x80000000U /* See NOTE-GetThemePartSize */
#   define 	PAD_MARGINS	 0x40000000U /* See NOTE-GetThemeMargins */
#   define 	HEAP_ELEMENT	 0x20000000U /* ElementInfo is on heap */
#   define 	HALF_HEIGHT	 0x10000000U /* Used by GenericSizedElements */
#   define 	HALF_WIDTH	 0x08000000U /* Used by GenericSizedElements */
    int  	flags;
#   define 	IGNORE_THEMESIZE 0x80000000 /* See NOTE-GetThemePartSize */
#   define 	PAD_MARGINS	 0x40000000 /* See NOTE-GetThemeMargins */
#   define 	HEAP_ELEMENT	 0x20000000 /* ElementInfo is on heap */
#   define 	HALF_HEIGHT	 0x10000000 /* Used by GenericSizedElements */
#   define 	HALF_WIDTH	 0x08000000 /* Used by GenericSizedElements */
} ElementInfo;

typedef struct
{
    /*
     * Static data, initialized when element is registered:
     */
    const ElementInfo	*info;
    ElementInfo	*info;
    XPThemeProcs *procs;	/* Pointer to theme procedure table */

    /*
     * Dynamic data, allocated by InitElementData:
     */
    HTHEME	hTheme;
    HDC		hDC;
    HWND	hwnd;

    /* For TkWinDrawableReleaseDC: */
    Drawable	drawable;
    TkWinDCState dcState;
} ElementData;

static ElementData *
NewElementData(XPThemeProcs *procs, const ElementInfo *info)
NewElementData(XPThemeProcs *procs, ElementInfo *info)
{
    ElementData *elementData = (ElementData *)ckalloc(sizeof(ElementData));
    ElementData *elementData = ckalloc(sizeof(ElementData));

    elementData->procs = procs;
    elementData->info = info;
    elementData->hTheme = elementData->hDC = 0;

    return elementData;
}

/*
 * Destroy elements. If the element was created by the element factory
 * then the info member is dynamically allocated. Otherwise it was
 * static data from the C object and only the ElementData needs freeing.
 */
static void DestroyElementData(void *clientData)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    if (elementData->info->flags & HEAP_ELEMENT) {
	ckfree((void *)elementData->info->statemap);
	ckfree((void *)elementData->info->className);
	ckfree((void *)elementData->info->elementName);
	ckfree((void *)elementData->info);
	ckfree(elementData->info->statemap);
	ckfree(elementData->info->className);
	ckfree(elementData->info->elementName);
	ckfree(elementData->info);
    }
    ckfree(clientData);
}

/*
 * InitElementData --
 * 	Looks up theme handle.  If Drawable argument is non-NULL,
 * 	also initializes DC.
 *
 * Returns:
 * 	1 on success, 0 on error.
 * 	Caller must later call FreeElementData() so this element
 * 	can be reused.
 */

static int
InitElementData(ElementData *elementData, Tk_Window tkwin, Drawable d)
{
    Window win = Tk_WindowId(tkwin);

    if (win) {
    if (win != None) {
	elementData->hwnd = Tk_GetHWND(win);
    } else  {
	elementData->hwnd = elementData->procs->stubWindow;
    }

    elementData->hTheme = elementData->procs->OpenThemeData(
	elementData->hwnd, elementData->info->className);
485
486
487
488
489
490
491
492

493
494
495

496
497
498
499

500
501
502
503
504
505
506
507
508
509

510
511
512
513
514
515
516
486
487
488
489
490
491
492

493



494


495

496
497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
513







-
+
-
-
-
+
-
-

-
+









-
+







 * +++ Generic element implementation.
 *
 * Used for elements which are handled entirely by the XP Theme API,
 * such as radiobutton and checkbutton indicators, scrollbar arrows, etc.
 */

static void GenericElementSize(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    int *widthPtr,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
    int *heightPtr,
    Ttk_Padding *paddingPtr)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    HRESULT result;
    SIZE size;

    if (!InitElementData(elementData, tkwin, 0))
	return;

    if (!(elementData->info->flags & IGNORE_THEMESIZE)) {
	result = elementData->procs->GetThemePartSize(
	    elementData->hTheme,
	    NULL,
	    elementData->hDC,
	    elementData->info->partId,
	    Ttk_StateTableLookup(elementData->info->statemap, 0),
	    NULL /*RECT *prc*/,
	    TS_TRUE,
	    &size);

	if (SUCCEEDED(result)) {
525
526
527
528
529
530
531
532

533
534
535

536
537
538
539

540
541
542
543
544
545
546
522
523
524
525
526
527
528

529



530


531

532
533
534
535
536
537
538
539







-
+
-
-
-
+
-
-

-
+







    if (elementData->info->flags & PAD_MARGINS) {
	*widthPtr += Ttk_PaddingWidth(elementData->info->padding);
	*heightPtr += Ttk_PaddingHeight(elementData->info->padding);
    }
}

static void GenericElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    RECT rc;

    if (!InitElementData(elementData, tkwin, d)) {
	return;
    }

    if (elementData->info->flags & PAD_MARGINS) {
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562







-
+







	Ttk_StateTableLookup(elementData->info->statemap, state),
	&rc,
	NULL/*pContentRect*/);

    FreeElementData(elementData);
}

static const Ttk_ElementSpec GenericElementSpec =
static Ttk_ElementSpec GenericElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    GenericElementSize,
    GenericElementDraw
};
577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620

621
622
623
624
625
626
627
628
629
630
631
632

633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649

650
651
652
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710
711
712
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
635
636
637
638

639



640


641

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

681
682
683
684
685
686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701







-
+

















-
+

















-
+











-
+













-
+
-
-
-
+
-
-

-
+



















-
+


















-
+












-
+







 */

static void
GenericSizedElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;

    if (!InitElementData(elementData, tkwin, 0))
	return;

    GenericElementSize(clientData, elementRecord, tkwin,
	widthPtr, heightPtr, paddingPtr);

    *widthPtr = elementData->procs->GetThemeSysSize(NULL,
	(elementData->info->flags >> 8) & 0xff);
    *heightPtr = elementData->procs->GetThemeSysSize(NULL,
	elementData->info->flags & 0xff);
    if (elementData->info->flags & HALF_HEIGHT)
	*heightPtr /= 2;
    if (elementData->info->flags & HALF_WIDTH)
	*widthPtr /= 2;
}

static const Ttk_ElementSpec GenericSizedElementSpec = {
static Ttk_ElementSpec GenericSizedElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    GenericSizedElementSize,
    GenericElementDraw
};

/*----------------------------------------------------------------------
 * +++ Spinbox arrow element.
 *     These are half-height scrollbar buttons.
 */

static void
SpinboxArrowElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;

    if (!InitElementData(elementData, tkwin, 0))
	return;

    GenericSizedElementSize(clientData, elementRecord, tkwin,
	widthPtr, heightPtr, paddingPtr);

    /* force the arrow button height to half size */
    *heightPtr /= 2;
}

static const Ttk_ElementSpec SpinboxArrowElementSpec = {
static Ttk_ElementSpec SpinboxArrowElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    SpinboxArrowElementSize,
    GenericElementDraw
};

/*----------------------------------------------------------------------
 * +++ Scrollbar thumb element.
 *     Same as a GenericElement, but don't draw in the disabled state.
 */

static void ThumbElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    unsigned stateId = Ttk_StateTableLookup(elementData->info->statemap, state);
    RECT rc = BoxToRect(b);

    /*
     * Don't draw the thumb if we are disabled.
     */
    if (state & TTK_STATE_DISABLED)
	return;

    if (!InitElementData(elementData, tkwin, d))
	return;

    elementData->procs->DrawThemeBackground(elementData->hTheme,
	elementData->hDC, elementData->info->partId, stateId,
	&rc, NULL);

    FreeElementData(elementData);
}

static const Ttk_ElementSpec ThumbElementSpec =
static Ttk_ElementSpec ThumbElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    GenericElementSize,
    ThumbElementDraw
};

/*----------------------------------------------------------------------
 * +++ Progress bar element.
 *	Increases the requested length of PP_CHUNK and PP_CHUNKVERT parts
 *	so that indeterminate progress bars show 3 bars instead of 1.
 */

static void PbarElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    int nBars = 3;

    GenericElementSize(clientData, elementRecord, tkwin,
    	widthPtr, heightPtr, paddingPtr);

    if (elementData->info->partId == PP_CHUNK) {
    	*widthPtr *= nBars;
    } else if (elementData->info->partId == PP_CHUNKVERT) {
    	*heightPtr *= nBars;
    }
}

static const Ttk_ElementSpec PbarElementSpec =
static Ttk_ElementSpec PbarElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    PbarElementSize,
    GenericElementDraw
};
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766

767
768
769

770
771
772
773
774
775

776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809


810
811
812
813
814
815
816


817
818
819
820
821
822
823
824
825
826

827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854

855
856
857
858
859

860
861
862
863
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879

880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
895

896
897
898
899
900
901
902

903
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

931
932
933

934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961

962
963

964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980


981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000

1001
1002

1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
710
711
712
713
714
715
716





































717

718



719


720



721
722

























723
724
725
726




727
728







729
730










731
























732
733
734

735
736
737
738
739

740
741
742
743
744
745
746
747
748
749
750
751
752

753
754
755
756
757
758
759

760
761
762
763
764
765
766
767

768
769
770
771
772
773
774
775

776
777
778
779
780
781
782

783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810

811
812
813

814
815

816
817
818
819
820
821
822
823
824
825
826
827



828
829
830
831


832
833
834
835
836

837
838

839
840
841
842
843
844
845
846
847
848
849

850
851
852
853


854
855
856
857
858
859
860



861
862
863
864


865
866
867
868
869

870
871

872
873
874


875
876
877

878
879
880
881
882
883
884
885







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-
-
-
+
-
-

-
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+




-
+












-
+






-
+







-
+







-
+






-
+








-
+


















-
+


-
+

-
+











-
-
-




-
-





-
+

-
+










-




-
-
+
+





-
-
-




-
-





-
+

-
+


-
-



-
+







 *	tab is exactly at the right edge of the notebook, but
 *	not if it's simply the rightmost tab.  This information
 * 	is not available.
 *
 *	The TIS_* and TILES_* definitions are identical, so
 * 	we can use the same statemap no matter what the partId.
 */

static void TabElementSize(
    void *clientData,
    void *elementRecord,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr,
    Ttk_Padding *paddingPtr)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    GenericElementSize(clientData, elementRecord, tkwin,
    	widthPtr, heightPtr, paddingPtr);

    *paddingPtr = Ttk_UniformPadding(3);
    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    paddingPtr->bottom = 0;
	    break;
	case TTK_STICK_N:
	    paddingPtr->top = 0;
	    break;
	case TTK_STICK_E:
	    paddingPtr->right = 0;
	    break;
	case TTK_STICK_W:
	    paddingPtr->left = 0;
	    break;
    }
}

static void TabElementDraw(
    void *clientData,
    void *clientData, void *elementRecord, Tk_Window tkwin,
    TCL_UNUSED(void *), /* elementRecord */
    Tk_Window tkwin,
    Drawable d,
    Drawable d, Ttk_Box b, unsigned int state)
    Ttk_Box b,
    Ttk_State state)
{
    Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
    TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
    ElementData *elementData = (ElementData *)clientData;
    ElementData *elementData = clientData;
    int partId = elementData->info->partId;
    int isSelected = (state & TTK_STATE_SELECTED);
    int stateId = Ttk_StateTableLookup(elementData->info->statemap, state);

    if (mainInfoPtr != NULL) {
	nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
    }

    /*
     * Correct the members of b if needed
     */
    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    break;
	case TTK_STICK_N:
	    b.y -= isSelected ? 0 : 1; b.height -= isSelected ? 1 : 0;
	    break;
	case TTK_STICK_E:
	    b.width -= isSelected ? 1 : 0;
	    break;
	case TTK_STICK_W:
	    b.x -= isSelected ? 1 : 2; b.width -= isSelected ? 1 : 0;
	    break;
    }

    RECT rc = BoxToRect(b);

    if (!InitElementData(elementData, tkwin, d))
	return;

    if (nbTabsStickBit == TTK_STICK_S) {
	if (state & TTK_STATE_USER1) {
	    partId = TABP_TABITEMLEFTEDGE;
    if (state & TTK_STATE_USER1)
	partId = TABP_TABITEMLEFTEDGE;
	}

	/*
	 * Draw the border and fill into rc
	 */
	elementData->procs->DrawThemeBackground(
	    elementData->hTheme, elementData->hDC, partId, stateId, &rc, NULL);
    elementData->procs->DrawThemeBackground(
	elementData->hTheme, elementData->hDC, partId,
    } else {
	/*
	 * Draw the fill but no border into rc
	 */
	RECT rc2 = rc;
	--rc2.top; --rc2.left; ++rc2.bottom; ++rc2.right;
	elementData->procs->DrawThemeBackground(
	    elementData->hTheme, elementData->hDC, partId, stateId, &rc2, &rc);
    }

	Ttk_StateTableLookup(elementData->info->statemap, state), &rc, NULL);
    /*
     * Draw a flat border at 3 edges
     */
    switch (nbTabsStickBit) {
	default:
	case TTK_STICK_S:
	    break;
	case TTK_STICK_N:
	    elementData->procs->DrawThemeEdge(
		elementData->hTheme, elementData->hDC, partId, stateId, &rc,
		BDR_RAISEDINNER, BF_FLAT|BF_LEFT|BF_RIGHT|BF_BOTTOM, NULL);
	    break;
	case TTK_STICK_E:
	    elementData->procs->DrawThemeEdge(
		elementData->hTheme, elementData->hDC, partId, stateId, &rc,
		BDR_RAISEDINNER, BF_FLAT|BF_LEFT|BF_TOP|BF_BOTTOM, NULL);
	    break;
	case TTK_STICK_W:
	    elementData->procs->DrawThemeEdge(
		elementData->hTheme, elementData->hDC, partId, stateId, &rc,
		BDR_RAISEDINNER, BF_FLAT|BF_TOP|BF_RIGHT|BF_BOTTOM, NULL);
	    break;
    }

    FreeElementData(elementData);
}

static const Ttk_ElementSpec TabElementSpec =
static Ttk_ElementSpec TabElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    TabElementSize,
    GenericElementSize,
    TabElementDraw
};

/*----------------------------------------------------------------------
 * +++  Tree indicator element.
 *
 *	Generic element, but don't display at all if TTK_STATE_LEAF (=USER2) set
 */

#define TTK_STATE_OPEN TTK_STATE_USER1
#define TTK_STATE_LEAF TTK_STATE_USER2

static const Ttk_StateTable header_statemap[] =
static Ttk_StateTable header_statemap[] =
{
    { HIS_PRESSED, 	TTK_STATE_PRESSED, 0 },
    { HIS_HOT,  	TTK_STATE_ACTIVE, 0 },
    { HIS_NORMAL, 	0,0 },
};

static const Ttk_StateTable treeview_statemap[] =
static Ttk_StateTable treeview_statemap[] =
{
    { TREIS_DISABLED, 	TTK_STATE_DISABLED, 0 },
    { TREIS_SELECTED,	TTK_STATE_SELECTED, 0},
    { TREIS_HOT, 	TTK_STATE_ACTIVE, 0 },
    { TREIS_NORMAL, 	0,0 },
};

static const Ttk_StateTable tvpglyph_statemap[] =
static Ttk_StateTable tvpglyph_statemap[] =
{
    { GLPS_OPENED, 	TTK_STATE_OPEN, 0 },
    { GLPS_CLOSED, 	0,0 },
};

static void TreeIndicatorElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    Drawable d, Ttk_Box b, unsigned int state)
{
    if (!(state & TTK_STATE_LEAF)) {
        GenericElementDraw(clientData,elementRecord,tkwin,d,b,state);
    }
}

static const Ttk_ElementSpec TreeIndicatorElementSpec =
static Ttk_ElementSpec TreeIndicatorElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
    GenericElementSize,
    TreeIndicatorElementDraw
};

#ifdef BROKEN_TEXT_ELEMENT
#if BROKEN_TEXT_ELEMENT

/*
 *----------------------------------------------------------------------
 * Text element (does not work yet).
 *
 * According to "Using Windows XP Visual Styles",  we need to select
 * a font into the DC before calling DrawThemeText().
 * There's just no easy way to get an HFONT out of a Tk_Font.
 * Maybe GetThemeFont() would work?
 *
 */

typedef struct
{
    Tcl_Obj *textObj;
    Tcl_Obj *fontObj;
} TextElement;

static const Ttk_ElementOptionSpec TextElementOptions[] =
static Ttk_ElementOptionSpec TextElementOptions[] =
{
    { "-text", TK_OPTION_STRING,
	offsetof(TextElement,textObj), "" },
	Tk_Offset(TextElement,textObj), "" },
    { "-font", TK_OPTION_FONT,
	offsetof(TextElement,fontObj), DEFAULT_FONT },
	Tk_Offset(TextElement,fontObj), DEFAULT_FONT },
    { NULL }
};

static void TextElementSize(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TextElement *element = elementRecord;
    ElementData *elementData = clientData;
    RECT rc = {0, 0};
    HRESULT hr = S_OK;
    const char *src;
    Tcl_Size len;
    Tcl_DString ds;

    if (!InitElementData(elementData, tkwin, 0))
	return;

    src = Tcl_GetStringFromObj(element->textObj, &len);
    Tcl_DStringInit(&ds);
    hr = elementData->procs->GetThemeTextExtent(
	    elementData->hTheme,
	    elementData->hDC,
	    elementData->info->partId,
	    Ttk_StateTableLookup(elementData->info->statemap, 0),
	    Tcl_UtfToWCharDString(src, len, &ds),
	    Tcl_GetUnicode(element->textObj),
	    -1,
	    DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
	    DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
	    NULL,
	    &rc);

    if (SUCCEEDED(hr)) {
	*widthPtr = rc.right - rc.left;
	*heightPtr = rc.bottom - rc.top;
    }
    if (*widthPtr < 80) *widthPtr = 80;
    if (*heightPtr < 20) *heightPtr = 20;

    Tcl_DStringFree(&ds);
    FreeElementData(elementData);
}

static void TextElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
    ClientData clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, unsigned int state)
{
    TextElement *element = elementRecord;
    ElementData *elementData = clientData;
    RECT rc = BoxToRect(b);
    HRESULT hr = S_OK;
    const char *src;
    Tcl_Size len;
    Tcl_DString ds;

    if (!InitElementData(elementData, tkwin, d))
	return;

    src = Tcl_GetStringFromObj(element->textObj, &len);
    Tcl_DStringInit(&ds);
    hr = elementData->procs->DrawThemeText(
	    elementData->hTheme,
	    elementData->hDC,
	    elementData->info->partId,
	    Ttk_StateTableLookup(elementData->info->statemap, state),
	    Tcl_UtfToWCharDString(src, len, &ds),
	    Tcl_GetUnicode(element->textObj),
	    -1,
	    DT_LEFT /* | DT_BOTTOM | DT_NOPREFIX */,
	    DT_LEFT,// | DT_BOTTOM | DT_NOPREFIX,
	    (state & TTK_STATE_DISABLED) ? DTT_GRAYED : 0,
	    &rc);

    Tcl_DStringFree(&ds);
    FreeElementData(elementData);
}

static const Ttk_ElementSpec TextElementSpec =
static Ttk_ElementSpec TextElementSpec =
{
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    TextElementSize,
    TextElementDraw
};
1028
1029
1030
1031
1032
1033
1034
1035
1036


1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055


1056
1057
1058
1059
1060
1061


1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
896
897
898
899
900
901
902


903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921


922
923
924
925
926
927


928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949
950
951







-
-
+
+

















-
-
+
+




-
-
+
+














-
+







    TTK_GROUP("Button.button", TTK_FILL_BOTH,
	TTK_GROUP("Button.focus", TTK_FILL_BOTH,
	    TTK_GROUP("Button.padding", TTK_FILL_BOTH,
		TTK_NODE("Button.label", TTK_FILL_BOTH)))))

TTK_LAYOUT("TMenubutton",
    TTK_NODE("Menubutton.dropdown", TTK_PACK_RIGHT|TTK_FILL_Y)
    TTK_GROUP("Menubutton.button", TTK_FILL_BOTH,
	    TTK_GROUP("Menubutton.padding", TTK_FILL_X,
    TTK_GROUP("Menubutton.button", TTK_PACK_RIGHT|TTK_EXPAND|TTK_FILL_BOTH,
	    TTK_GROUP("Menubutton.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_X,
	        TTK_NODE("Menubutton.label", 0))))

TTK_LAYOUT("Horizontal.TScrollbar",
    TTK_GROUP("Horizontal.Scrollbar.trough", TTK_FILL_X,
	TTK_NODE("Horizontal.Scrollbar.leftarrow", TTK_PACK_LEFT)
	TTK_NODE("Horizontal.Scrollbar.rightarrow", TTK_PACK_RIGHT)
	TTK_GROUP("Horizontal.Scrollbar.thumb", TTK_FILL_BOTH|TTK_UNIT,
	    TTK_NODE("Horizontal.Scrollbar.grip", 0))))

TTK_LAYOUT("Vertical.TScrollbar",
    TTK_GROUP("Vertical.Scrollbar.trough", TTK_FILL_Y,
	TTK_NODE("Vertical.Scrollbar.uparrow", TTK_PACK_TOP)
	TTK_NODE("Vertical.Scrollbar.downarrow", TTK_PACK_BOTTOM)
	TTK_GROUP("Vertical.Scrollbar.thumb", TTK_FILL_BOTH|TTK_UNIT,
	    TTK_NODE("Vertical.Scrollbar.grip", 0))))

TTK_LAYOUT("Horizontal.TScale",
    TTK_GROUP("Scale.focus", TTK_FILL_BOTH,
	TTK_GROUP("Horizontal.Scale.trough", TTK_FILL_BOTH,
    TTK_GROUP("Scale.focus", TTK_EXPAND|TTK_FILL_BOTH,
	TTK_GROUP("Horizontal.Scale.trough", TTK_EXPAND|TTK_FILL_BOTH,
	    TTK_NODE("Horizontal.Scale.track", TTK_FILL_X)
	    TTK_NODE("Horizontal.Scale.slider", TTK_PACK_LEFT) )))

TTK_LAYOUT("Vertical.TScale",
    TTK_GROUP("Scale.focus", TTK_FILL_BOTH,
	TTK_GROUP("Vertical.Scale.trough", TTK_FILL_BOTH,
    TTK_GROUP("Scale.focus", TTK_EXPAND|TTK_FILL_BOTH,
	TTK_GROUP("Vertical.Scale.trough", TTK_EXPAND|TTK_FILL_BOTH,
	    TTK_NODE("Vertical.Scale.track", TTK_FILL_Y)
	    TTK_NODE("Vertical.Scale.slider", TTK_PACK_TOP) )))

TTK_END_LAYOUT_TABLE

/*----------------------------------------------------------------------
 * +++ XP element info table:
 */

#define PAD(l,t,r,b) {l,t,r,b}
#define NOPAD {0,0,0,0}

/* name spec className partId statemap padding flags */

static const ElementInfo ElementInfoTable[] = {
static ElementInfo ElementInfoTable[] = {
    { "Checkbutton.indicator", &GenericElementSpec, L"BUTTON",
    	BP_CHECKBOX, checkbox_statemap, PAD(0, 0, 4, 0), PAD_MARGINS },
    { "Radiobutton.indicator", &GenericElementSpec, L"BUTTON",
    	BP_RADIOBUTTON, radiobutton_statemap, PAD(0, 0, 4, 0), PAD_MARGINS },
    { "Button.button", &GenericElementSpec, L"BUTTON",
    	BP_PUSHBUTTON, pushbutton_statemap, PAD(3, 3, 3, 3), IGNORE_THEMESIZE },
    { "Labelframe.border", &GenericElementSpec, L"BUTTON",
1140
1141
1142
1143
1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161

1162

1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188

1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1008
1009
1010
1011
1012
1013
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043

1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

1058
1059
1060
1061
1062

1063
1064
1065
1066
1067
1068
1069
1070







-
+














+
-
+



+








-
+



-
+









-
+




-
+







    { "Toolbutton.border", &GenericElementSpec, L"TOOLBAR",
    	TP_BUTTON, toolbutton_statemap, NOPAD,0 },
    { "Menubutton.button", &GenericElementSpec, L"TOOLBAR",
    	TP_SPLITBUTTON,toolbutton_statemap, NOPAD,0 },
    { "Menubutton.dropdown", &GenericElementSpec, L"TOOLBAR",
    	TP_SPLITBUTTONDROPDOWN,toolbutton_statemap, NOPAD,0 },
    { "Treeview.field", &GenericElementSpec, L"TREEVIEW",
	TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), IGNORE_THEMESIZE },
	TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), 0 },
    { "Treeitem.indicator", &TreeIndicatorElementSpec, L"TREEVIEW",
    	TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS },
    { "Treeheading.border", &GenericElementSpec, L"HEADER",
    	HP_HEADERITEM, header_statemap, PAD(4,0,4,0),0 },
    { "sizegrip", &GenericElementSpec, L"STATUS",
    	SP_GRIPPER, null_statemap, NOPAD,0 },
    { "Spinbox.field", &GenericElementSpec, L"EDIT",
	EP_EDITTEXT, edittext_statemap, PAD(1, 1, 1, 1), 0 },
    { "Spinbox.uparrow", &SpinboxArrowElementSpec, L"SPIN",
	SPNP_UP, spinbutton_statemap, NOPAD,
	PAD_MARGINS | ((SM_CXVSCROLL << 8) | SM_CYVSCROLL) },
    { "Spinbox.downarrow", &SpinboxArrowElementSpec, L"SPIN",
	SPNP_DOWN, spinbutton_statemap, NOPAD,
	PAD_MARGINS | ((SM_CXVSCROLL << 8) | SM_CYVSCROLL) },

#ifdef BROKEN_TEXT_ELEMENT
#if BROKEN_TEXT_ELEMENT
    { "Labelframe.text", &TextElementSpec, L"BUTTON",
    	BP_GROUPBOX, groupbox_statemap, NOPAD,0 },
#endif

    { 0,0,0,0,0,NOPAD,0 }
};
#undef PAD


static int
GetSysFlagFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr)
{
    static const char *const names[] = {
    static const char *names[] = {
	"SM_CXBORDER", "SM_CYBORDER", "SM_CXVSCROLL", "SM_CYVSCROLL",
	"SM_CXHSCROLL", "SM_CYHSCROLL", "SM_CXMENUCHECK", "SM_CYMENUCHECK",
	"SM_CXMENUSIZE", "SM_CYMENUSIZE", "SM_CXSIZE", "SM_CYSIZE", "SM_CXSMSIZE",
	"SM_CYSMSIZE", NULL
	"SM_CYSMSIZE"
    };
    int flags[] = {
	SM_CXBORDER, SM_CYBORDER, SM_CXVSCROLL, SM_CYVSCROLL,
	SM_CXHSCROLL, SM_CYHSCROLL, SM_CXMENUCHECK, SM_CYMENUCHECK,
	SM_CXMENUSIZE, SM_CYMENUSIZE, SM_CXSIZE, SM_CYSIZE, SM_CXSMSIZE,
	SM_CYSMSIZE
    };

    Tcl_Obj **objv;
    Tcl_Size i, objc;
    int i, objc;

    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK)
	return TCL_ERROR;
    if (objc != 2) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args", TCL_INDEX_NONE));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args", -1));
	Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
	return TCL_ERROR;
    }
    for (i = 0; i < objc; ++i) {
	int option;
	if (Tcl_GetIndexFromObjStruct(interp, objv[i], names,
		sizeof(char *), "system constant", 0, &option) != TCL_OK)
1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228

1229
1230
1231


1232
1233
1234
1235
1236

1237
1238
1239

1240
1241
1242
1243
1244
1245
1246





1247
1248
1249
1250

1251
1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277



1278
1279
1280
1281

1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292

1293
1294
1295
1296
1297
1298
1299

1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333

1334
1335

1336
1337

1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355

1356
1357
1358
1359

1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402





1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422

1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435

1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462


1088
1089
1090
1091
1092
1093
1094

1095
1096
1097

1098
1099


1100
1101
1102
1103
1104
1105

1106
1107
1108

1109

1110





1111
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1126

1127


1128
1129
1130


1131
1132
1133
1134
1135
1136
1137
1138

1139
1140



1141
1142
1143
1144
1145
1146

1147
1148
1149
1150
1151

1152
1153
1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197


1198
1199

1200
1201

1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215

1216
1217
1218

1219
1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
1230

1231
1232
1233
1234
1235

1236
1237
1238
1239
1240
1241
1242
1243
1244

1245

1246




1247
1248
1249
1250
1251
1252


1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282

1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325







-
+


-
+

-
-
+
+




-
+


-
+
-

-
-
-
-
-
+
+
+
+
+



-
+







-
+
-
-



-
-
+







-
+

-
-
-
+
+
+



-
+




-
+





-
+






-
+






-
+






-
+






-
+











-
-
+

-
+

-
+













-



-
+



-
+







-
+




-
+








-
+
-

-
-
-
-






-
-






-
+
+
+
+
+



















-
+












-
+










-
+
















+
+

static int
Ttk_CreateVsapiElement(
    Tcl_Interp *interp,
    void *clientData,
    Ttk_Theme theme,
    const char *elementName,
    Tcl_Size objc,
    int objc,
    Tcl_Obj *const objv[])
{
    XPThemeData *themeData = (XPThemeData *)clientData;
    XPThemeData *themeData = clientData;
    ElementInfo *elementPtr = NULL;
    void *elementData;
    LPCWSTR className;
    ClientData elementData;
    Tcl_UniChar *className;
    int partId = 0;
    Ttk_StateTable *stateTable;
    Ttk_Padding pad = {0, 0, 0, 0};
    int flags = 0;
    Tcl_Size length = 0;
    int length = 0;
    char *name;
    LPWSTR wname;
    const Ttk_ElementSpec *elementSpec = &GenericElementSpec;
    Ttk_ElementSpec *elementSpec = &GenericElementSpec;
    Tcl_DString classBuf;

    static const char *const optionStrings[] =
	{ "-halfheight", "-halfwidth", "-height", "-margins", "-padding",
	  "-syssize", "-width", NULL };
    enum { O_HALFHEIGHT, O_HALFWIDTH, O_HEIGHT, O_MARGINS, O_PADDING,
	   O_SYSSIZE, O_WIDTH };
    static const char *optionStrings[] =
	{ "-padding","-width","-height","-margins", "-syssize",
	  "-halfheight", "-halfwidth", NULL };
    enum { O_PADDING, O_WIDTH, O_HEIGHT, O_MARGINS, O_SYSSIZE,
	   O_HALFHEIGHT, O_HALFWIDTH };

    if (objc < 2) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
	    "missing required arguments 'class' and/or 'partId'", TCL_INDEX_NONE));
	    "missing required arguments 'class' and/or 'partId'", -1));
	Tcl_SetErrorCode(interp, "TTK", "VSAPI", "REQUIRED", NULL);
	return TCL_ERROR;
    }

    if (Tcl_GetIntFromObj(interp, objv[1], &partId) != TCL_OK) {
	return TCL_ERROR;
    }
    name = Tcl_GetStringFromObj(objv[0], &length);
    className = Tcl_GetUnicodeFromObj(objv[0], &length);
    Tcl_DStringInit(&classBuf);
    className = Tcl_UtfToWCharDString(name, length, &classBuf);

    /* flags or padding */
    if (objc > 3) {
	Tcl_Size i = 3;
	int option = 0;
	int i = 3, option = 0;
	for (i = 3; i < objc; i += 2) {
	    int tmp = 0;
	    if (i == objc -1) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"Missing value for \"%s\".",
			Tcl_GetString(objv[i])));
		Tcl_SetErrorCode(interp, "TTK", "VSAPI", "MISSING", NULL);
		goto retErr;
		return TCL_ERROR;
	    }
	    if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings,
		    "option", 0, &option) != TCL_OK)
		goto retErr;
	    if (Tcl_GetIndexFromObjStruct(interp, objv[i], optionStrings,
		    sizeof(char *), "option", 0, &option) != TCL_OK)
		return TCL_ERROR;
	    switch (option) {
	    case O_PADDING:
		if (Ttk_GetBorderFromObj(interp, objv[i+1], &pad) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		break;
	    case O_MARGINS:
		if (Ttk_GetBorderFromObj(interp, objv[i+1], &pad) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		flags |= PAD_MARGINS;
		break;
	    case O_WIDTH:
		if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		pad.left = pad.right = tmp;
		flags |= IGNORE_THEMESIZE;
		break;
	    case O_HEIGHT:
		if (Tcl_GetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		pad.top = pad.bottom = tmp;
		flags |= IGNORE_THEMESIZE;
		break;
	    case O_SYSSIZE:
		if (GetSysFlagFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		elementSpec = &GenericSizedElementSpec;
		flags |= (tmp & 0xFFFF);
		break;
	    case O_HALFHEIGHT:
		if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		if (tmp)
		    flags |= HALF_HEIGHT;
		break;
	    case O_HALFWIDTH:
		if (Tcl_GetBooleanFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
		    goto retErr;
		    return TCL_ERROR;
		}
		if (tmp)
		    flags |= HALF_WIDTH;
		break;
	    }
	}
    }

    /* convert a statemap into a state table */
    if (objc > 2) {
	Tcl_Obj **specs;
	Tcl_Size n, j, count;
	int status = TCL_OK;
	int n,j,count, status = TCL_OK;
	if (Tcl_ListObjGetElements(interp, objv[2], &count, &specs) != TCL_OK)
	    goto retErr;
	    return TCL_ERROR;
	/* we over-allocate to ensure there is a terminating entry */
	stateTable = (Ttk_StateTable *)ckalloc(sizeof(Ttk_StateTable) * (count + 1));
	stateTable = ckalloc(sizeof(Ttk_StateTable) * (count + 1));
	memset(stateTable, 0, sizeof(Ttk_StateTable) * (count + 1));
	for (n = 0, j = 0; status == TCL_OK && n < count; n += 2, ++j) {
	    Ttk_StateSpec spec = {0,0};
	    status = Ttk_GetStateSpecFromObj(interp, specs[n], &spec);
	    if (status == TCL_OK) {
		stateTable[j].onBits = spec.onbits;
		stateTable[j].offBits = spec.offbits;
		status = Tcl_GetIntFromObj(interp, specs[n+1],
			&stateTable[j].index);
	    }
	}
	if (status != TCL_OK) {
	    ckfree(stateTable);
	    Tcl_DStringFree(&classBuf);
	    return status;
	}
    } else {
	stateTable = (Ttk_StateTable *)ckalloc(sizeof(Ttk_StateTable));
	stateTable = ckalloc(sizeof(Ttk_StateTable));
	memset(stateTable, 0, sizeof(Ttk_StateTable));
    }

    elementPtr = (ElementInfo *)ckalloc(sizeof(ElementInfo));
    elementPtr = ckalloc(sizeof(ElementInfo));
    elementPtr->elementSpec = elementSpec;
    elementPtr->partId = partId;
    elementPtr->statemap = stateTable;
    elementPtr->padding = pad;
    elementPtr->flags = HEAP_ELEMENT | flags;

    /* set the element name to an allocated copy */
    name = (char *)ckalloc(strlen(elementName) + 1);
    name = ckalloc(strlen(elementName) + 1);
    strcpy(name, elementName);
    elementPtr->elementName = name;

    /* set the class name to an allocated copy */
    wname = (LPWSTR)ckalloc(Tcl_DStringLength(&classBuf) + sizeof(WCHAR));
    wname = ckalloc(sizeof(WCHAR) * (length + 1));
    wcscpy(wname, className);
    elementPtr->className = wname;

    elementData = NewElementData(themeData->procs, elementPtr);
    Ttk_RegisterElementSpec(
	theme, elementName, elementPtr->elementSpec, elementData);

    Ttk_RegisterCleanup(interp, elementData, DestroyElementData);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(elementName, TCL_INDEX_NONE));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(elementName, -1));
    Tcl_DStringFree(&classBuf);
    return TCL_OK;

retErr:
    Tcl_DStringFree(&classBuf);
    return TCL_ERROR;
}

/*----------------------------------------------------------------------
 * +++ Initialization routine:
 */

MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd);

MODULE_SCOPE int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd)
{
    XPThemeData *themeData;
    XPThemeProcs *procs;
    HINSTANCE hlibrary;
    Ttk_Theme themePtr, parentPtr, vistaPtr;
    const ElementInfo *infoPtr;
    ElementInfo *infoPtr;
    OSVERSIONINFOW os;

    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
    GetVersionExW(&os);

    procs = LoadXPThemeProcs(&hlibrary);
    if (!procs)
	return TCL_ERROR;
    procs->stubWindow = hwnd;

    /*
     * Create the new style engine.
     */
    parentPtr = Ttk_GetTheme(interp, "winnative");
    themePtr = Ttk_CreateTheme(interp, "xpnative", parentPtr);

    if (!themePtr)
        return TCL_ERROR;

    /*
     * Set theme data and cleanup proc
     */

    themeData = (XPThemeData *)ckalloc(sizeof(XPThemeData));
    themeData = ckalloc(sizeof(XPThemeData));
    themeData->procs = procs;
    themeData->hlibrary = hlibrary;

    Ttk_SetThemeEnabledProc(themePtr, XPThemeEnabled, themeData);
    Ttk_RegisterCleanup(interp, themeData, XPThemeDeleteProc);
    Ttk_RegisterElementFactory(interp, "vsapi", Ttk_CreateVsapiElement, themeData);

    /*
     * Create the vista theme on suitable platform versions and set the theme
     * enable function. The theme itself is defined in script.
     */

    if (TkWinGetPlatformTheme() == TK_THEME_WIN_VISTA) {
    if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && os.dwMajorVersion > 5) {
	vistaPtr = Ttk_CreateTheme(interp, "vista", themePtr);
	if (vistaPtr) {
	    Ttk_SetThemeEnabledProc(vistaPtr, XPThemeEnabled, themeData);
	}
    }

    /*
     * New elements:
     */
    for (infoPtr = ElementInfoTable; infoPtr->elementName != 0; ++infoPtr) {
	void *clientData = NewElementData(procs, infoPtr);
	ClientData clientData = NewElementData(procs, infoPtr);
	Ttk_RegisterElementSpec(
	    themePtr, infoPtr->elementName, infoPtr->elementSpec, clientData);
	Ttk_RegisterCleanup(interp, clientData, DestroyElementData);
    }

    Ttk_RegisterElementSpec(themePtr, "Scale.trough", &ttkNullElementSpec, 0);

    /*
     * Layouts:
     */
    Ttk_RegisterLayouts(themePtr, LayoutTable);

    Tcl_PkgProvide(interp, "ttk::theme::xpnative", TTK_VERSION);

    return TCL_OK;
}

#endif /* HAVE_UXTHEME_H */

Changes to win/winMain.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
8
9
10
11
12
13
14



















15
16
17
18
19
20
21




22
23
24
25
26




27

28
29
30








31



32
33
34
35
36



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56




57

58
59
60
61
62
63
64







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
-





-
-
-
-

-
+


-
-
-
-
-
-
-
-

-
-
-
+
+
+


-
-
-




















-
-
-
-
+
-







 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * Explanation on following undef USE_TCL_STUBS by JN 2023-12-19 on the core list:
 * What's going on is related to TIP #596:
 *  Stubs support for Embedding Tcl in other applications
 *
 * If an application using Tcl_Main() is compiled with USE_TCL_STUBS,
 * Tcl_Main() will be replaced by a stub function, which loads
 * libtcl9.0.so/tcl90.dll and then calls its Tcl_MainEx(). If
 * libtcl9.0.so/tcl90.dll is not present (at runtime), a crash is what happens.
 *
 * So ... tkAppInit.c should not be compiled with USE_TCL_STUBS
 * (unless you want to use the TIP #596 functionality)
 *
 * The proper solution is to make sure that Makefile.in doesn't use
 * TCL_USE_STUBS when compiling tkAppInit.c. But that's a
 * quite big re-organization just before a b1 release. Simpler
 * is just to #undef'ine USE_TCL_STUBS, it has the same effect.
 */
#undef USE_TCL_STUBS
#include "tk.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <locale.h>
#include <stdlib.h>
#include <tchar.h>
#if TCL_MAJOR_VERSION < 9 && TCL_MINOR_VERSION < 7
#   define Tcl_LibraryInitProc Tcl_PackageInitProc
#   define Tcl_StaticLibrary Tcl_StaticPackage
#endif

#if defined(__GNUC__)
int _CRT_glob = 0;
#endif /* __GNUC__ */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef TK_TEST
extern Tcl_LibraryInitProc Tktest_Init;
extern Tcl_PackageInitProc Tktest_Init;
#endif /* TK_TEST */

#if !defined(TCL_USE_STATIC_PACKAGES)
#   if TCL_MAJOR_VERSION > 8 || TCL_MINOR_VERSION > 6
#	define TCL_USE_STATIC_PACKAGES 1
#   else
#	define TCL_USE_STATIC_PACKAGES 0
#   endif
#endif

#if defined(STATIC_BUILD) && TCL_USE_STATIC_PACKAGES
extern Tcl_LibraryInitProc Registry_Init;
extern Tcl_LibraryInitProc Dde_Init;
extern Tcl_LibraryInitProc Dde_SafeInit;
extern Tcl_PackageInitProc Registry_Init;
extern Tcl_PackageInitProc Dde_Init;
extern Tcl_PackageInitProc Dde_SafeInit;
#endif

#ifdef __cplusplus
}
#endif
#ifdef TCL_BROKEN_MAINARGS
static void setargv(int *argcPtr, TCHAR ***argvPtr);
#endif

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

static BOOL consoleRequired = TRUE;

/*
 * The following #if block allows you to change the AppInit function by using
 * a #define of TCL_LOCAL_APPINIT instead of rewriting this entire file. The
 * #if checks for that #define and uses Tcl_AppInit if it doesn't exist.
 */

#ifndef TK_LOCAL_APPINIT
#define TK_LOCAL_APPINIT Tcl_AppInit
#endif
#ifndef MODULE_SCOPE
#   ifdef __cplusplus
#	define MODULE_SCOPE extern "C"
#   else
#	define MODULE_SCOPE extern
#   define MODULE_SCOPE extern
#   endif
#endif
MODULE_SCOPE int TK_LOCAL_APPINIT(Tcl_Interp *interp);

/*
 * The following #if block allows you to change how Tcl finds the startup
 * script, prime the library or encoding paths, fiddle with the argv, etc.,
 * without needing to rewrite Tk_Main()
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
102
103
104
105
106
107
108




109
110
111
112
113
114
115







-
-
-
-







    LPTSTR lpszCmdLine,
    int nCmdShow)
#endif
{
    TCHAR **argv;
    int argc;
    TCHAR *p;
    (void)hInstance;
    (void)hPrevInstance;
    (void)lpszCmdLine;
    (void)nCmdShow;

    /*
     * Create the console channels and install them as the standard channels.
     * All I/O will be discarded until Tk_CreateConsoleWindow is called to
     * attach the console to a text widget.
     */

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
141
142
143
144
145
146
147



148
149
150
151
152
153
154







-
-
-







	if (*p == '\\') {
	    *p = '/';
	}
    }

#ifdef TK_LOCAL_MAIN_HOOK
    TK_LOCAL_MAIN_HOOK(&argc, &argv);
#elif defined(UNICODE) && ((TCL_MAJOR_VERSION > 8) || (TCL_MINOR_VERSION > 6))
    /* This doesn't work on Windows without UNICODE, neither does it work with Tcl 8.6 */
    TclZipfs_AppHook(&argc, &argv);
#endif

    Tk_Main(argc, argv, TK_LOCAL_APPINIT);
    return 0;			/* Needed only to prevent compiler warning. */
}

/*
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254












255
256
257
258
259

260
261
262
263
264
265
266
173
174
175
176
177
178
179











180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218







-
-
-
-
-
-
-
-
-
-
-



-
+











+
+
+
+
+
+
+
+
+
+
+
+




-
+







int
Tcl_AppInit(
    Tcl_Interp *interp)		/* Interpreter for application. */
{
    if ((Tcl_Init)(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
#if defined(STATIC_BUILD) && TCL_USE_STATIC_PACKAGES
    if (Registry_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Registry", Registry_Init, 0);

    if (Dde_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Dde", Dde_Init, Dde_SafeInit);
#endif
    if (Tk_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Tk", Tk_Init, Tk_SafeInit);
    Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);

    /*
     * Initialize the console only if we are running as an interactive
     * application.
     */

    if (consoleRequired) {
	if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    }
#if defined(STATIC_BUILD) && TCL_USE_STATIC_PACKAGES
    if (Registry_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticPackage(interp, "registry", Registry_Init, 0);

    if (Dde_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticPackage(interp, "dde", Dde_Init, Dde_SafeInit);
#endif

#ifdef TK_TEST
    if (Tktest_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticLibrary(interp, "Tktest", Tktest_Init, 0);
    Tcl_StaticPackage(interp, "Tktest", Tktest_Init, 0);
#endif /* TK_TEST */

    /*
     * Call the init procedures for included packages. Each call should look
     * like this:
     *
     * if (Mod_Init(interp) == TCL_ERROR) {
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
261
262
263
264
265
266
267

268
269
270
271
272
273
274







-







#ifdef TCL_BROKEN_MAINARGS
int
main(
    int argc,
    char **dummy)
{
    TCHAR **argv;
    (void)dummy;
#else
int
_tmain(
    int argc,
    TCHAR **argv)
{
#endif
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374







-
+







	}
    }

    /* Make sure we don't call ckalloc through the (not yet initialized) stub table */
    #undef Tcl_Alloc
    #undef Tcl_DbCkalloc

    argSpace = (TCHAR *)ckalloc(size * sizeof(char *)
    argSpace = ckalloc(size * sizeof(char *)
	    + (_tcslen(cmdLine) * sizeof(TCHAR)) + sizeof(TCHAR));
    argv = (TCHAR **) argSpace;
    argSpace += size * (sizeof(char *)/sizeof(TCHAR));
    size--;

    p = cmdLine;
    for (argc = 0; argc < size; argc++) {

Changes to win/wish.exe.manifest.in.

24
25
26
27
28
29
30


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39




40
41
42
43
44
45
46







+
+







-
-
-
-







	    <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
	    <!-- Windows 8.1 -->
	    <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
	    <!-- Windows 8 -->
	    <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
	    <!-- Windows 7 -->
	    <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
	    <!-- Windows Vista -->
	    <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
	</application>
    </compatibility>
    <asmv3:application>
	<asmv3:windowsSettings
		xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
	    <dpiAware>true</dpiAware>
	</asmv3:windowsSettings>
	<asmv3:windowsSettings
		xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
	    <activeCodePage>UTF-8</activeCodePage>
	</asmv3:windowsSettings>
    </asmv3:application>
    <dependency>
	<dependentAssembly>
	    <assemblyIdentity
		    type="win32"
		    name="Microsoft.Windows.Common-Controls"
		    version="6.0.0.0"

Deleted win/x86_64-w64-mingw32-nmakehlp.exe.

cannot compute difference between binary files

Deleted xlib/X11/DECkeysym.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/***********************************************************

Copyright 1988, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1988 by Digital Equipment Corporation, Maynard, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

/*
 * DEC private keysyms
 * (29th bit set)
 */

/* two-key compose sequence initiators, chosen to map to Latin1 characters */

#define DXK_ring_accent              0x1000feb0
#define DXK_circumflex_accent        0x1000fe5e
#define DXK_cedilla_accent           0x1000fe2c
#define DXK_acute_accent             0x1000fe27
#define DXK_grave_accent             0x1000fe60
#define DXK_tilde                    0x1000fe7e
#define DXK_diaeresis                0x1000fe22

/* special keysym for LK2** "Remove" key on editing keypad */

#define DXK_Remove                   0x1000ff00  /* Remove */

Deleted xlib/X11/HPkeysym.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164




































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*

Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.

Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Hewlett Packard
or Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD
TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  Hewlett-Packard shall not be liable for errors
contained herein or direct, indirect, special, incidental or
consequential damages in connection with the furnishing,
performance, or use of this material.

*/

#ifndef _HPKEYSYM_H

#define _HPKEYSYM_H

#define hpXK_ClearLine               0x1000ff6f
#define hpXK_InsertLine              0x1000ff70
#define hpXK_DeleteLine              0x1000ff71
#define hpXK_InsertChar              0x1000ff72
#define hpXK_DeleteChar              0x1000ff73
#define hpXK_BackTab                 0x1000ff74
#define hpXK_KP_BackTab              0x1000ff75
#define hpXK_Modelock1               0x1000ff48
#define hpXK_Modelock2               0x1000ff49
#define hpXK_Reset                   0x1000ff6c
#define hpXK_System                  0x1000ff6d
#define hpXK_User                    0x1000ff6e
#define hpXK_mute_acute              0x100000a8
#define hpXK_mute_grave              0x100000a9
#define hpXK_mute_asciicircum        0x100000aa
#define hpXK_mute_diaeresis          0x100000ab
#define hpXK_mute_asciitilde         0x100000ac
#define hpXK_lira                    0x100000af
#define hpXK_guilder                 0x100000be
#define hpXK_Ydiaeresis              0x100000ee
#define hpXK_IO                      0x100000ee  /* deprecated alias for hpYdiaeresis */
#define hpXK_longminus               0x100000f6
#define hpXK_block                   0x100000fc


#ifndef _OSF_Keysyms
#define _OSF_Keysyms

#define osfXK_Copy                   0x1004ff02
#define osfXK_Cut                    0x1004ff03
#define osfXK_Paste                  0x1004ff04
#define osfXK_BackTab                0x1004ff07
#define osfXK_BackSpace              0x1004ff08
#define osfXK_Clear                  0x1004ff0b
#define osfXK_Escape                 0x1004ff1b
#define osfXK_AddMode                0x1004ff31
#define osfXK_PrimaryPaste           0x1004ff32
#define osfXK_QuickPaste             0x1004ff33
#define osfXK_PageLeft               0x1004ff40
#define osfXK_PageUp                 0x1004ff41
#define osfXK_PageDown               0x1004ff42
#define osfXK_PageRight              0x1004ff43
#define osfXK_Activate               0x1004ff44
#define osfXK_MenuBar                0x1004ff45
#define osfXK_Left                   0x1004ff51
#define osfXK_Up                     0x1004ff52
#define osfXK_Right                  0x1004ff53
#define osfXK_Down                   0x1004ff54
#define osfXK_EndLine                0x1004ff57
#define osfXK_BeginLine              0x1004ff58
#define osfXK_EndData                0x1004ff59
#define osfXK_BeginData              0x1004ff5a
#define osfXK_PrevMenu               0x1004ff5b
#define osfXK_NextMenu               0x1004ff5c
#define osfXK_PrevField              0x1004ff5d
#define osfXK_NextField              0x1004ff5e
#define osfXK_Select                 0x1004ff60
#define osfXK_Insert                 0x1004ff63
#define osfXK_Undo                   0x1004ff65
#define osfXK_Menu                   0x1004ff67
#define osfXK_Cancel                 0x1004ff69
#define osfXK_Help                   0x1004ff6a
#define osfXK_SelectAll              0x1004ff71
#define osfXK_DeselectAll            0x1004ff72
#define osfXK_Reselect               0x1004ff73
#define osfXK_Extend                 0x1004ff74
#define osfXK_Restore                0x1004ff78
#define osfXK_Delete                 0x1004ffff

#endif /* _OSF_Keysyms */


/**************************************************************
 * The use of the following macros is deprecated.
 * They are listed below only for backwards compatibility.
 */
#define XK_Reset                     0x1000ff6c  /* deprecated alias for hpReset */
#define XK_System                    0x1000ff6d  /* deprecated alias for hpSystem */
#define XK_User                      0x1000ff6e  /* deprecated alias for hpUser */
#define XK_ClearLine                 0x1000ff6f  /* deprecated alias for hpClearLine */
#define XK_InsertLine                0x1000ff70  /* deprecated alias for hpInsertLine */
#define XK_DeleteLine                0x1000ff71  /* deprecated alias for hpDeleteLine */
#define XK_InsertChar                0x1000ff72  /* deprecated alias for hpInsertChar */
#define XK_DeleteChar                0x1000ff73  /* deprecated alias for hpDeleteChar */
#define XK_BackTab                   0x1000ff74  /* deprecated alias for hpBackTab */
#define XK_KP_BackTab                0x1000ff75  /* deprecated alias for hpKP_BackTab */
#define XK_Ext16bit_L                0x1000ff76  /* deprecated */
#define XK_Ext16bit_R                0x1000ff77  /* deprecated */
#define XK_mute_acute                0x100000a8  /* deprecated alias for hpmute_acute */
#define XK_mute_grave                0x100000a9  /* deprecated alias for hpmute_grave */
#define XK_mute_asciicircum          0x100000aa  /* deprecated alias for hpmute_asciicircum */
#define XK_mute_diaeresis            0x100000ab  /* deprecated alias for hpmute_diaeresis */
#define XK_mute_asciitilde           0x100000ac  /* deprecated alias for hpmute_asciitilde */
#define XK_lira                      0x100000af  /* deprecated alias for hplira */
#define XK_guilder                   0x100000be  /* deprecated alias for hpguilder */
#ifndef XK_Ydiaeresis
#define XK_Ydiaeresis                0x100000ee  /* deprecated */
#endif
#define XK_IO                        0x100000ee  /* deprecated alias for hpYdiaeresis */
#define XK_longminus                 0x100000f6  /* deprecated alias for hplongminus */
#define XK_block                     0x100000fc  /* deprecated alias for hpblock */

#endif /* _HPKEYSYM_H */

Deleted xlib/X11/Sunkeysym.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106










































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 1991, Oracle and/or its affiliates.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/************************************************************

Copyright 1991, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.

***********************************************************/

/*
 * Floating Accent
 */

#define SunXK_FA_Grave               0x1005ff00
#define SunXK_FA_Circum              0x1005ff01
#define SunXK_FA_Tilde               0x1005ff02
#define SunXK_FA_Acute               0x1005ff03
#define SunXK_FA_Diaeresis           0x1005ff04
#define SunXK_FA_Cedilla             0x1005ff05

/*
 * Miscellaneous Functions
 */

#define SunXK_F36                    0x1005ff10  /* Labeled F11 */
#define SunXK_F37                    0x1005ff11  /* Labeled F12 */

#define SunXK_Sys_Req                0x1005ff60
#define SunXK_Print_Screen           0x0000ff61  /* Same as XK_Print */

/*
 * International & Multi-Key Character Composition
 */

#define SunXK_Compose                0x0000ff20  /* Same as XK_Multi_key */
#define SunXK_AltGraph               0x0000ff7e  /* Same as XK_Mode_switch */

/*
 * Cursor Control
 */

#define SunXK_PageUp                 0x0000ff55  /* Same as XK_Prior */
#define SunXK_PageDown               0x0000ff56  /* Same as XK_Next */

/*
 * Open Look Functions
 */

#define SunXK_Undo                   0x0000ff65  /* Same as XK_Undo */
#define SunXK_Again                  0x0000ff66  /* Same as XK_Redo */
#define SunXK_Find                   0x0000ff68  /* Same as XK_Find */
#define SunXK_Stop                   0x0000ff69  /* Same as XK_Cancel */
#define SunXK_Props                  0x1005ff70
#define SunXK_Front                  0x1005ff71
#define SunXK_Copy                   0x1005ff72
#define SunXK_Open                   0x1005ff73
#define SunXK_Paste                  0x1005ff74
#define SunXK_Cut                    0x1005ff75

#define SunXK_PowerSwitch            0x1005ff76
#define SunXK_AudioLowerVolume       0x1005ff77
#define SunXK_AudioMute              0x1005ff78
#define SunXK_AudioRaiseVolume       0x1005ff79
#define SunXK_VideoDegauss           0x1005ff7a
#define SunXK_VideoLowerBrightness   0x1005ff7b
#define SunXK_VideoRaiseBrightness   0x1005ff7c
#define SunXK_PowerSwitchShift       0x1005ff7d

Changes to xlib/X11/X.h.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55





56
57
58
59
60
61
62
63
64
65
66
67
68



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111








112

113
114
115
116


117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
1
2
3
4
5
6
7
8
9
10

























11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42











43
44
45
46




























47
48
49
50


51

52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68


69
70
71
72
73
74
75



76

77
78
79
80
81
82
83
+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+







-
+












-



+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-

-






+
+
+
+
+
+
+
+
-
+


-
-
+
+





-
-
-
+
-







/*
 *	$XConsortium: X.h,v 1.66 88/09/06 15:55:56 jim Exp $
 */

/* Definitions for the X window system likely to be used by applications */

#ifndef X_H
#define X_H

/***********************************************************

Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

#define X_PROTOCOL	11		/* current protocol version */
#define X_PROTOCOL_REVISION 0		/* current minor version */

#if defined(MAC_OSX_TK)
#   define Cursor XCursor
#   define Region XRegion
#endif

/* Resources */

/*
 * _XSERVER64 must ONLY be defined when compiling X server sources on
 * systems where unsigned long is not 32 bits, must NOT be used in
 * client or library code.
 */
#ifndef _XSERVER64
#  ifndef _XTYPEDEF_XID
#    define _XTYPEDEF_XID
#    ifdef _WIN64
typedef unsigned long long XID;
#    else
#ifdef _WIN64
typedef __int64 XID;
#else
typedef unsigned long XID;
#    endif
#  endif
#  ifndef _XTYPEDEF_MASK
#    define _XTYPEDEF_MASK
typedef unsigned long Mask;
#  endif
#  ifndef _XTYPEDEF_ATOM
#    define _XTYPEDEF_ATOM
typedef unsigned long Atom;		/* Also in Xdefs.h */
#  endif
typedef unsigned long VisualID;
typedef unsigned long Time;
#else
#  include <X11/Xmd.h>
#  ifndef _XTYPEDEF_XID
#    define _XTYPEDEF_XID
typedef CARD32 XID;
#  endif
#  ifndef _XTYPEDEF_MASK
#    define _XTYPEDEF_MASK
typedef CARD32 Mask;
#  endif
#  ifndef _XTYPEDEF_ATOM
#    define _XTYPEDEF_ATOM
typedef CARD32 Atom;
#  endif
typedef CARD32 VisualID;
typedef CARD32 Time;
#endif

typedef XID Window;
typedef XID Drawable;
#ifndef _XTYPEDEF_FONT
#  define _XTYPEDEF_FONT
typedef XID Font;
#endif
typedef XID Pixmap;
typedef XID Cursor;
typedef XID Colormap;
typedef XID GContext;
typedef XID KeySym;

typedef unsigned long Mask;

typedef unsigned long Atom;

typedef unsigned long VisualID;

typedef unsigned long Time;

typedef unsigned int KeyCode;	/* In order to use IME, the Macintosh needs
typedef unsigned long KeyCode;	/* In order to use IME, the Macintosh needs
				 * to pack 3 bytes into the keyCode field in
				 * the XEvent.  In the real X.h, a KeyCode is
				 * defined as an unsigned char, which wouldn't
				 * be big enough. */
				 * defined as a short, which wouldn't be big
				 * enough. */

/*****************************************************************
 * RESERVED RESOURCE AND CONSTANT DEFINITIONS
 *****************************************************************/

#ifndef None
/* Perl-Tk expects None to be a macro. See ticket [593eb0227c] */
#define None                 None /* See bug [9e31fd9449] and below */
#define None                 0L	/* universal null resource or null atom */
#endif

#define ParentRelative       1L	/* background pixmap in CreateWindow
				    and ChangeWindowAttributes */

#define CopyFromParent       0L	/* border pixmap in CreateWindow
				       and ChangeWindowAttributes
				   special VisualID and special window
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
167
168
169
170
171
172
173


174
175
176
177
178
179
180
181


182
183
184
185
186
187
188



189
190
191
192
193
194
195







-
-
+







-
-
+






-
-
-







#define PropertyNotify		28
#define SelectionClear		29
#define SelectionRequest	30
#define SelectionNotify		31
#define ColormapNotify		32
#define ClientMessage		33
#define MappingNotify		34
#define GenericEvent		35
#define LASTEvent		36	/* must be bigger than any event # */
#define LASTEvent		35	/* must be bigger than any event # */


/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
   state in various key-, mouse-, and button-related events. */

#define ShiftMask		(1<<0)
#define LockMask		(1<<1)
/* Perl-Tk expects ControlMask to be a macro. See ticket [593eb0227c] */
#define ControlMask		ControlMask /* See bug [9e31fd9449] and below */
#define ControlMask		(1<<2)
#define Mod1Mask		(1<<3)
#define Mod2Mask		(1<<4)
#define Mod3Mask		(1<<5)
#define Mod4Mask		(1<<6)
#define Mod5Mask		(1<<7)

/* See bug [9e31fd9449], this way prevents conflicts with Win32 headers */
enum { None = 0, ControlMask = (1<<2) };

/* modifier names.  Used to build a SetModifierMapping request or
   to read a GetModifierMapping request.  These correspond to the
   masks defined above. */
#define ShiftMapIndex		0
#define LockMapIndex		1
#define ControlMapIndex		2
#define Mod1MapIndex		3
304
305
306
307
308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
250
251
252
253
254
255
256

257
258
259




260
261
262
263
264
265
266







-
+


-
-
-
-







/* Circulation request */

#define PlaceOnTop		0
#define PlaceOnBottom		1

/* protocol families */

#define FamilyInternet		0	/* IPv4 */
#define FamilyInternet		0
#define FamilyDECnet		1
#define FamilyChaos		2
#define FamilyInternet6		6	/* IPv6 */

/* authentication families not tied to a specific protocol */
#define FamilyServerInterpreted 5

/* Property notification */

#define PropertyNewValue	0
#define PropertyDelete		1

/* Color Map notification */
722
723
724
725
726
727
728
729





730
664
665
666
667
668
669
670
671
672
673
674
675
676
677








+
+
+
+
+

#define DirectColor		5


/* Byte order  used in imageByteOrder and bitmapBitOrder */

#define LSBFirst		0
#define MSBFirst		1

#if defined(MAC_OSX_TK)
#   undef Cursor
#   undef Region
#endif

#endif /* X_H */

Deleted xlib/X11/XF86keysym.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487







































































































































































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * XFree86 vendor specific keysyms.
 *
 * The XFree86 keysym range is 0x10080001 - 0x1008ffff.
 *
 * The XF86 set of keysyms is a catch-all set of defines for keysyms found
 * on various multimedia keyboards. Originally specific to XFree86 they have
 * been been adopted over time and are considered a "standard" part of X
 * keysym definitions.
 * XFree86 never properly commented these keysyms, so we have done our
 * best to explain the semantic meaning of these keys.
 *
 * XFree86 has removed their mail archives of the period, that might have
 * shed more light on some of these definitions. Until/unless we resurrect
 * these archives, these are from memory and usage.
 */

/*
 * ModeLock
 *
 * This one is old, and not really used any more since XKB offers this
 * functionality.
 */

#define XF86XK_ModeLock              0x1008ff01  /* Mode Switch Lock */

/* Backlight controls. */
#define XF86XK_MonBrightnessUp       0x1008ff02  /* Monitor/panel brightness */
#define XF86XK_MonBrightnessDown     0x1008ff03  /* Monitor/panel brightness */
#define XF86XK_KbdLightOnOff         0x1008ff04  /* Keyboards may be lit     */
#define XF86XK_KbdBrightnessUp       0x1008ff05  /* Keyboards may be lit     */
#define XF86XK_KbdBrightnessDown     0x1008ff06  /* Keyboards may be lit     */
#define XF86XK_MonBrightnessCycle    0x1008ff07  /* Monitor/panel brightness */

/*
 * Keys found on some "Internet" keyboards.
 */
#define XF86XK_Standby               0x1008ff10  /* System into standby mode   */
#define XF86XK_AudioLowerVolume      0x1008ff11  /* Volume control down        */
#define XF86XK_AudioMute             0x1008ff12  /* Mute sound from the system */
#define XF86XK_AudioRaiseVolume      0x1008ff13  /* Volume control up          */
#define XF86XK_AudioPlay             0x1008ff14  /* Start playing of audio >   */
#define XF86XK_AudioStop             0x1008ff15  /* Stop playing audio         */
#define XF86XK_AudioPrev             0x1008ff16  /* Previous track             */
#define XF86XK_AudioNext             0x1008ff17  /* Next track                 */
#define XF86XK_HomePage              0x1008ff18  /* Display user's home page   */
#define XF86XK_Mail                  0x1008ff19  /* Invoke user's mail program */
#define XF86XK_Start                 0x1008ff1a  /* Start application          */
#define XF86XK_Search                0x1008ff1b  /* Search                     */
#define XF86XK_AudioRecord           0x1008ff1c  /* Record audio application   */

/* These are sometimes found on PDA's (e.g. Palm, PocketPC or elsewhere)   */
#define XF86XK_Calculator            0x1008ff1d  /* Invoke calculator program  */
#define XF86XK_Memo                  0x1008ff1e  /* Invoke Memo taking program */
#define XF86XK_ToDoList              0x1008ff1f  /* Invoke To Do List program  */
#define XF86XK_Calendar              0x1008ff20  /* Invoke Calendar program    */
#define XF86XK_PowerDown             0x1008ff21  /* Deep sleep the system      */
#define XF86XK_ContrastAdjust        0x1008ff22  /* Adjust screen contrast     */
#define XF86XK_RockerUp              0x1008ff23  /* Rocker switches exist up   */
#define XF86XK_RockerDown            0x1008ff24  /* and down                   */
#define XF86XK_RockerEnter           0x1008ff25  /* and let you press them     */

/* Some more "Internet" keyboard symbols */
#define XF86XK_Back                  0x1008ff26  /* Like back on a browser     */
#define XF86XK_Forward               0x1008ff27  /* Like forward on a browser  */
#define XF86XK_Stop                  0x1008ff28  /* Stop current operation     */
#define XF86XK_Refresh               0x1008ff29  /* Refresh the page           */
#define XF86XK_PowerOff              0x1008ff2a  /* Power off system entirely  */
#define XF86XK_WakeUp                0x1008ff2b  /* Wake up system from sleep  */
#define XF86XK_Eject                 0x1008ff2c  /* Eject device (e.g. DVD)    */
#define XF86XK_ScreenSaver           0x1008ff2d  /* Invoke screensaver         */
#define XF86XK_WWW                   0x1008ff2e  /* Invoke web browser         */
#define XF86XK_Sleep                 0x1008ff2f  /* Put system to sleep        */
#define XF86XK_Favorites             0x1008ff30  /* Show favorite locations    */
#define XF86XK_AudioPause            0x1008ff31  /* Pause audio playing        */
#define XF86XK_AudioMedia            0x1008ff32  /* Launch media collection app */
#define XF86XK_MyComputer            0x1008ff33  /* Display "My Computer" window */
#define XF86XK_VendorHome            0x1008ff34  /* Display vendor home web site */
#define XF86XK_LightBulb             0x1008ff35  /* Light bulb keys exist       */
#define XF86XK_Shop                  0x1008ff36  /* Display shopping web site   */
#define XF86XK_History               0x1008ff37  /* Show history of web surfing */
#define XF86XK_OpenURL               0x1008ff38  /* Open selected URL           */
#define XF86XK_AddFavorite           0x1008ff39  /* Add URL to favorites list   */
#define XF86XK_HotLinks              0x1008ff3a  /* Show "hot" links            */
#define XF86XK_BrightnessAdjust      0x1008ff3b  /* Invoke brightness adj. UI   */
#define XF86XK_Finance               0x1008ff3c  /* Display financial site      */
#define XF86XK_Community             0x1008ff3d  /* Display user's community    */
#define XF86XK_AudioRewind           0x1008ff3e  /* "rewind" audio track        */
#define XF86XK_BackForward           0x1008ff3f  /* ??? */
#define XF86XK_Launch0               0x1008ff40  /* Launch Application          */
#define XF86XK_Launch1               0x1008ff41  /* Launch Application          */
#define XF86XK_Launch2               0x1008ff42  /* Launch Application          */
#define XF86XK_Launch3               0x1008ff43  /* Launch Application          */
#define XF86XK_Launch4               0x1008ff44  /* Launch Application          */
#define XF86XK_Launch5               0x1008ff45  /* Launch Application          */
#define XF86XK_Launch6               0x1008ff46  /* Launch Application          */
#define XF86XK_Launch7               0x1008ff47  /* Launch Application          */
#define XF86XK_Launch8               0x1008ff48  /* Launch Application          */
#define XF86XK_Launch9               0x1008ff49  /* Launch Application          */
#define XF86XK_LaunchA               0x1008ff4a  /* Launch Application          */
#define XF86XK_LaunchB               0x1008ff4b  /* Launch Application          */
#define XF86XK_LaunchC               0x1008ff4c  /* Launch Application          */
#define XF86XK_LaunchD               0x1008ff4d  /* Launch Application          */
#define XF86XK_LaunchE               0x1008ff4e  /* Launch Application          */
#define XF86XK_LaunchF               0x1008ff4f  /* Launch Application          */

#define XF86XK_ApplicationLeft       0x1008ff50  /* switch to application, left */
#define XF86XK_ApplicationRight      0x1008ff51  /* switch to application, right*/
#define XF86XK_Book                  0x1008ff52  /* Launch bookreader           */
#define XF86XK_CD                    0x1008ff53  /* Launch CD/DVD player        */
#define XF86XK_Calculater            0x1008ff54  /* Launch Calculater           */
#define XF86XK_Clear                 0x1008ff55  /* Clear window, screen        */
#define XF86XK_Close                 0x1008ff56  /* Close window                */
#define XF86XK_Copy                  0x1008ff57  /* Copy selection              */
#define XF86XK_Cut                   0x1008ff58  /* Cut selection               */
#define XF86XK_Display               0x1008ff59  /* Output switch key           */
#define XF86XK_DOS                   0x1008ff5a  /* Launch DOS (emulation)      */
#define XF86XK_Documents             0x1008ff5b  /* Open documents window       */
#define XF86XK_Excel                 0x1008ff5c  /* Launch spread sheet         */
#define XF86XK_Explorer              0x1008ff5d  /* Launch file explorer        */
#define XF86XK_Game                  0x1008ff5e  /* Launch game                 */
#define XF86XK_Go                    0x1008ff5f  /* Go to URL                   */
#define XF86XK_iTouch                0x1008ff60  /* Logitech iTouch- don't use  */
#define XF86XK_LogOff                0x1008ff61  /* Log off system              */
#define XF86XK_Market                0x1008ff62  /* ??                          */
#define XF86XK_Meeting               0x1008ff63  /* enter meeting in calendar   */
#define XF86XK_MenuKB                0x1008ff65  /* distinguish keyboard from PB */
#define XF86XK_MenuPB                0x1008ff66  /* distinguish PB from keyboard */
#define XF86XK_MySites               0x1008ff67  /* Favourites                  */
#define XF86XK_New                   0x1008ff68  /* New (folder, document...    */
#define XF86XK_News                  0x1008ff69  /* News                        */
#define XF86XK_OfficeHome            0x1008ff6a  /* Office home (old Staroffice)*/
#define XF86XK_Open                  0x1008ff6b  /* Open                        */
#define XF86XK_Option                0x1008ff6c  /* ?? */
#define XF86XK_Paste                 0x1008ff6d  /* Paste                       */
#define XF86XK_Phone                 0x1008ff6e  /* Launch phone; dial number   */
#define XF86XK_Q                     0x1008ff70  /* Compaq's Q - don't use      */
#define XF86XK_Reply                 0x1008ff72  /* Reply e.g., mail            */
#define XF86XK_Reload                0x1008ff73  /* Reload web page, file, etc. */
#define XF86XK_RotateWindows         0x1008ff74  /* Rotate windows e.g. xrandr  */
#define XF86XK_RotationPB            0x1008ff75  /* don't use                   */
#define XF86XK_RotationKB            0x1008ff76  /* don't use                   */
#define XF86XK_Save                  0x1008ff77  /* Save (file, document, state */
#define XF86XK_ScrollUp              0x1008ff78  /* Scroll window/contents up   */
#define XF86XK_ScrollDown            0x1008ff79  /* Scrool window/contentd down */
#define XF86XK_ScrollClick           0x1008ff7a  /* Use XKB mousekeys instead   */
#define XF86XK_Send                  0x1008ff7b  /* Send mail, file, object     */
#define XF86XK_Spell                 0x1008ff7c  /* Spell checker               */
#define XF86XK_SplitScreen           0x1008ff7d  /* Split window or screen      */
#define XF86XK_Support               0x1008ff7e  /* Get support (??)            */
#define XF86XK_TaskPane              0x1008ff7f  /* Show tasks */
#define XF86XK_Terminal              0x1008ff80  /* Launch terminal emulator    */
#define XF86XK_Tools                 0x1008ff81  /* toolbox of desktop/app.     */
#define XF86XK_Travel                0x1008ff82  /* ?? */
#define XF86XK_UserPB                0x1008ff84  /* ?? */
#define XF86XK_User1KB               0x1008ff85  /* ?? */
#define XF86XK_User2KB               0x1008ff86  /* ?? */
#define XF86XK_Video                 0x1008ff87  /* Launch video player       */
#define XF86XK_WheelButton           0x1008ff88  /* button from a mouse wheel */
#define XF86XK_Word                  0x1008ff89  /* Launch word processor     */
#define XF86XK_Xfer                  0x1008ff8a
#define XF86XK_ZoomIn                0x1008ff8b  /* zoom in view, map, etc.   */
#define XF86XK_ZoomOut               0x1008ff8c  /* zoom out view, map, etc.  */

#define XF86XK_Away                  0x1008ff8d  /* mark yourself as away     */
#define XF86XK_Messenger             0x1008ff8e  /* as in instant messaging   */
#define XF86XK_WebCam                0x1008ff8f  /* Launch web camera app.    */
#define XF86XK_MailForward           0x1008ff90  /* Forward in mail           */
#define XF86XK_Pictures              0x1008ff91  /* Show pictures             */
#define XF86XK_Music                 0x1008ff92  /* Launch music application  */

#define XF86XK_Battery               0x1008ff93  /* Display battery information */
#define XF86XK_Bluetooth             0x1008ff94  /* Enable/disable Bluetooth    */
#define XF86XK_WLAN                  0x1008ff95  /* Enable/disable WLAN         */
#define XF86XK_UWB                   0x1008ff96  /* Enable/disable UWB	    */

#define XF86XK_AudioForward          0x1008ff97  /* fast-forward audio track    */
#define XF86XK_AudioRepeat           0x1008ff98  /* toggle repeat mode          */
#define XF86XK_AudioRandomPlay       0x1008ff99  /* toggle shuffle mode         */
#define XF86XK_Subtitle              0x1008ff9a  /* cycle through subtitle      */
#define XF86XK_AudioCycleTrack       0x1008ff9b  /* cycle through audio tracks  */
#define XF86XK_CycleAngle            0x1008ff9c  /* cycle through angles        */
#define XF86XK_FrameBack             0x1008ff9d  /* video: go one frame back    */
#define XF86XK_FrameForward          0x1008ff9e  /* video: go one frame forward */
#define XF86XK_Time                  0x1008ff9f  /* display, or shows an entry for time seeking */
#define XF86XK_Select                0x1008ffa0  /* Select button on joypads and remotes */
#define XF86XK_View                  0x1008ffa1  /* Show a view options/properties */
#define XF86XK_TopMenu               0x1008ffa2  /* Go to a top-level menu in a video */

#define XF86XK_Red                   0x1008ffa3  /* Red button                  */
#define XF86XK_Green                 0x1008ffa4  /* Green button                */
#define XF86XK_Yellow                0x1008ffa5  /* Yellow button               */
#define XF86XK_Blue                  0x1008ffa6  /* Blue button                 */

#define XF86XK_Suspend               0x1008ffa7  /* Sleep to RAM                */
#define XF86XK_Hibernate             0x1008ffa8  /* Sleep to disk               */
#define XF86XK_TouchpadToggle        0x1008ffa9  /* Toggle between touchpad/trackstick */
#define XF86XK_TouchpadOn            0x1008ffb0  /* The touchpad got switched on */
#define XF86XK_TouchpadOff           0x1008ffb1  /* The touchpad got switched off */

#define XF86XK_AudioMicMute          0x1008ffb2  /* Mute the Mic from the system */

#define XF86XK_Keyboard              0x1008ffb3  /* User defined keyboard related action */

#define XF86XK_WWAN                  0x1008ffb4  /* Toggle WWAN (LTE, UMTS, etc.) radio */
#define XF86XK_RFKill                0x1008ffb5  /* Toggle radios on/off */

#define XF86XK_AudioPreset           0x1008ffb6  /* Select equalizer preset, e.g. theatre-mode */

#define XF86XK_RotationLockToggle    0x1008ffb7  /* Toggle screen rotation lock on/off */

#define XF86XK_FullScreen            0x1008ffb8  /* Toggle fullscreen */

/* Keys for special action keys (hot keys) */
/* Virtual terminals on some operating systems */
#define XF86XK_Switch_VT_1           0x1008fe01
#define XF86XK_Switch_VT_2           0x1008fe02
#define XF86XK_Switch_VT_3           0x1008fe03
#define XF86XK_Switch_VT_4           0x1008fe04
#define XF86XK_Switch_VT_5           0x1008fe05
#define XF86XK_Switch_VT_6           0x1008fe06
#define XF86XK_Switch_VT_7           0x1008fe07
#define XF86XK_Switch_VT_8           0x1008fe08
#define XF86XK_Switch_VT_9           0x1008fe09
#define XF86XK_Switch_VT_10          0x1008fe0a
#define XF86XK_Switch_VT_11          0x1008fe0b
#define XF86XK_Switch_VT_12          0x1008fe0c

#define XF86XK_Ungrab                0x1008fe20  /* force ungrab               */
#define XF86XK_ClearGrab             0x1008fe21  /* kill application with grab */
#define XF86XK_Next_VMode            0x1008fe22  /* next video mode available  */
#define XF86XK_Prev_VMode            0x1008fe23  /* prev. video mode available */
#define XF86XK_LogWindowTree         0x1008fe24  /* print window tree to log   */
#define XF86XK_LogGrabInfo           0x1008fe25  /* print all active grabs to log */


/*
 * Reserved range for evdev symbols: 0x10081000-0x10081FFF
 *
 * Key syms within this range must match the Linux kernel
 * input-event-codes.h file in the format:
 *     XF86XK_CamelCaseKernelName	_EVDEVK(kernel value)
 * For example, the kernel
 *   #define KEY_MACRO_RECORD_START	0x2b0
 * effectively ends up as:
 *   #define XF86XK_MacroRecordStart	0x100812b0
 *
 * For historical reasons, some keysyms within the reserved range will be
 * missing, most notably all "normal" keys that are mapped through default
 * XKB layouts (e.g. KEY_Q).
 *
 * CamelCasing is done with a human control as last authority, e.g. see VOD
 * instead of Vod for the Video on Demand key.
 *
 * The format for #defines is strict:
 *
 * #define XF86XK_FOO<tab...>_EVDEVK(0xABC)<tab><tab> |* kver KEY_FOO *|
 *
 * Where
 * - alignment by tabs
 * - the _EVDEVK macro must be used
 * - the hex code must be in uppercase hex
 * - the kernel version (kver) is in the form v5.10
 * - kver and key name are within a slash-star comment (a pipe is used in
 *   this example for technical reasons)
 * These #defines are parsed by scripts. Do not stray from the given format.
 *
 * Where the evdev keycode is mapped to a different symbol, please add a
 * comment line starting with Use: but otherwise the same format, e.g.
 *  Use: XF86XK_RotationLockToggle	_EVDEVK(0x231)		   v4.16 KEY_ROTATE_LOCK_TOGGLE
 *
 */
#define _EVDEVK(_v) (0x10081000 + _v)
/* Use: XF86XK_Eject                    _EVDEVK(0x0a2)             KEY_EJECTCLOSECD */
/* Use: XF86XK_New                      _EVDEVK(0x0b5)     v2.6.14 KEY_NEW */
/* Use: XK_Redo                         _EVDEVK(0x0b6)     v2.6.14 KEY_REDO */
/* KEY_DASHBOARD has been mapped to LaunchB in xkeyboard-config since 2011 */
/* Use: XF86XK_LaunchB                  _EVDEVK(0x0cc)     v2.6.28 KEY_DASHBOARD */
/* Use: XF86XK_Display                  _EVDEVK(0x0e3)     v2.6.12 KEY_SWITCHVIDEOMODE */
/* Use: XF86XK_KbdLightOnOff            _EVDEVK(0x0e4)     v2.6.12 KEY_KBDILLUMTOGGLE */
/* Use: XF86XK_KbdBrightnessDown        _EVDEVK(0x0e5)     v2.6.12 KEY_KBDILLUMDOWN */
/* Use: XF86XK_KbdBrightnessUp          _EVDEVK(0x0e6)     v2.6.12 KEY_KBDILLUMUP */
/* Use: XF86XK_Send                     _EVDEVK(0x0e7)     v2.6.14 KEY_SEND */
/* Use: XF86XK_Reply                    _EVDEVK(0x0e8)     v2.6.14 KEY_REPLY */
/* Use: XF86XK_MailForward              _EVDEVK(0x0e9)     v2.6.14 KEY_FORWARDMAIL */
/* Use: XF86XK_Save                     _EVDEVK(0x0ea)     v2.6.14 KEY_SAVE */
/* Use: XF86XK_Documents                _EVDEVK(0x0eb)     v2.6.14 KEY_DOCUMENTS */
/* Use: XF86XK_Battery                  _EVDEVK(0x0ec)     v2.6.17 KEY_BATTERY */
/* Use: XF86XK_Bluetooth                _EVDEVK(0x0ed)     v2.6.19 KEY_BLUETOOTH */
/* Use: XF86XK_WLAN                     _EVDEVK(0x0ee)     v2.6.19 KEY_WLAN */
/* Use: XF86XK_UWB                      _EVDEVK(0x0ef)     v2.6.24 KEY_UWB */
/* Use: XF86XK_Next_VMode               _EVDEVK(0x0f1)     v2.6.23 KEY_VIDEO_NEXT */
/* Use: XF86XK_Prev_VMode               _EVDEVK(0x0f2)     v2.6.23 KEY_VIDEO_PREV */
/* Use: XF86XK_MonBrightnessCycle       _EVDEVK(0x0f3)     v2.6.23 KEY_BRIGHTNESS_CYCLE */
#define XF86XK_BrightnessAuto           _EVDEVK(0x0f4)  /* v3.16   KEY_BRIGHTNESS_AUTO */
#define XF86XK_DisplayOff               _EVDEVK(0x0f5)  /* v2.6.23 KEY_DISPLAY_OFF */
/* Use: XF86XK_WWAN                     _EVDEVK(0x0f6)     v3.13   KEY_WWAN */
/* Use: XF86XK_RFKill                   _EVDEVK(0x0f7)     v2.6.33 KEY_RFKILL */
/* Use: XF86XK_AudioMicMute             _EVDEVK(0x0f8)     v3.1    KEY_MICMUTE */
#define XF86XK_Info                     _EVDEVK(0x166)  /*         KEY_INFO */
/* Use: XF86XK_CycleAngle               _EVDEVK(0x173)             KEY_ANGLE */
/* Use: XF86XK_FullScreen               _EVDEVK(0x174)     v5.1    KEY_FULL_SCREEN */
#define XF86XK_AspectRatio              _EVDEVK(0x177)  /* v5.1    KEY_ASPECT_RATIO */
#define XF86XK_DVD                      _EVDEVK(0x185)  /*         KEY_DVD */
#define XF86XK_Audio                    _EVDEVK(0x188)  /*         KEY_AUDIO */
/* Use: XF86XK_Video                    _EVDEVK(0x189)             KEY_VIDEO */
/* Use: XF86XK_Calendar                 _EVDEVK(0x18d)             KEY_CALENDAR */
#define XF86XK_ChannelUp                _EVDEVK(0x192)  /*         KEY_CHANNELUP */
#define XF86XK_ChannelDown              _EVDEVK(0x193)  /*         KEY_CHANNELDOWN */
/* Use: XF86XK_AudioRandomPlay          _EVDEVK(0x19a)             KEY_SHUFFLE */
#define XF86XK_Break                    _EVDEVK(0x19b)  /*         KEY_BREAK */
#define XF86XK_VideoPhone               _EVDEVK(0x1a0)  /* v2.6.20 KEY_VIDEOPHONE */
/* Use: XF86XK_Game                     _EVDEVK(0x1a1)     v2.6.20 KEY_GAMES */
/* Use: XF86XK_ZoomIn                   _EVDEVK(0x1a2)     v2.6.20 KEY_ZOOMIN */
/* Use: XF86XK_ZoomOut                  _EVDEVK(0x1a3)     v2.6.20 KEY_ZOOMOUT */
#define XF86XK_ZoomReset                _EVDEVK(0x1a4)  /* v2.6.20 KEY_ZOOMRESET */
/* Use: XF86XK_Word                     _EVDEVK(0x1a5)     v2.6.20 KEY_WORDPROCESSOR */
#define XF86XK_Editor                   _EVDEVK(0x1a6)  /* v2.6.20 KEY_EDITOR */
/* Use: XF86XK_Excel                    _EVDEVK(0x1a7)     v2.6.20 KEY_SPREADSHEET */
#define XF86XK_GraphicsEditor           _EVDEVK(0x1a8)  /* v2.6.20 KEY_GRAPHICSEDITOR */
#define XF86XK_Presentation             _EVDEVK(0x1a9)  /* v2.6.20 KEY_PRESENTATION */
#define XF86XK_Database                 _EVDEVK(0x1aa)  /* v2.6.20 KEY_DATABASE */
/* Use: XF86XK_News                     _EVDEVK(0x1ab)     v2.6.20 KEY_NEWS */
#define XF86XK_Voicemail                _EVDEVK(0x1ac)  /* v2.6.20 KEY_VOICEMAIL */
#define XF86XK_Addressbook              _EVDEVK(0x1ad)  /* v2.6.20 KEY_ADDRESSBOOK */
/* Use: XF86XK_Messenger                _EVDEVK(0x1ae)     v2.6.20 KEY_MESSENGER */
#define XF86XK_DisplayToggle            _EVDEVK(0x1af)  /* v2.6.20 KEY_DISPLAYTOGGLE */
#define XF86XK_SpellCheck               _EVDEVK(0x1b0)  /* v2.6.24 KEY_SPELLCHECK */
/* Use: XF86XK_LogOff                   _EVDEVK(0x1b1)     v2.6.24 KEY_LOGOFF */
/* Use: XK_dollar                       _EVDEVK(0x1b2)     v2.6.24 KEY_DOLLAR */
/* Use: XK_EuroSign                     _EVDEVK(0x1b3)     v2.6.24 KEY_EURO */
/* Use: XF86XK_FrameBack                _EVDEVK(0x1b4)     v2.6.24 KEY_FRAMEBACK */
/* Use: XF86XK_FrameForward             _EVDEVK(0x1b5)     v2.6.24 KEY_FRAMEFORWARD */
#define XF86XK_ContextMenu              _EVDEVK(0x1b6)  /* v2.6.24 KEY_CONTEXT_MENU */
#define XF86XK_MediaRepeat              _EVDEVK(0x1b7)  /* v2.6.26 KEY_MEDIA_REPEAT */
#define XF86XK_10ChannelsUp             _EVDEVK(0x1b8)  /* v2.6.38 KEY_10CHANNELSUP */
#define XF86XK_10ChannelsDown           _EVDEVK(0x1b9)  /* v2.6.38 KEY_10CHANNELSDOWN */
#define XF86XK_Images                   _EVDEVK(0x1ba)  /* v2.6.39 KEY_IMAGES */
#define XF86XK_NotificationCenter       _EVDEVK(0x1bc)  /* v5.10   KEY_NOTIFICATION_CENTER */
#define XF86XK_PickupPhone              _EVDEVK(0x1bd)  /* v5.10   KEY_PICKUP_PHONE */
#define XF86XK_HangupPhone              _EVDEVK(0x1be)  /* v5.10   KEY_HANGUP_PHONE */
#define XF86XK_Fn                       _EVDEVK(0x1d0)  /*         KEY_FN */
#define XF86XK_Fn_Esc                   _EVDEVK(0x1d1)  /*         KEY_FN_ESC */
#define XF86XK_FnRightShift             _EVDEVK(0x1e5)  /* v5.10   KEY_FN_RIGHT_SHIFT */
/* Use: XK_braille_dot_1                _EVDEVK(0x1f1)     v2.6.17 KEY_BRL_DOT1 */
/* Use: XK_braille_dot_2                _EVDEVK(0x1f2)     v2.6.17 KEY_BRL_DOT2 */
/* Use: XK_braille_dot_3                _EVDEVK(0x1f3)     v2.6.17 KEY_BRL_DOT3 */
/* Use: XK_braille_dot_4                _EVDEVK(0x1f4)     v2.6.17 KEY_BRL_DOT4 */
/* Use: XK_braille_dot_5                _EVDEVK(0x1f5)     v2.6.17 KEY_BRL_DOT5 */
/* Use: XK_braille_dot_6                _EVDEVK(0x1f6)     v2.6.17 KEY_BRL_DOT6 */
/* Use: XK_braille_dot_7                _EVDEVK(0x1f7)     v2.6.17 KEY_BRL_DOT7 */
/* Use: XK_braille_dot_8                _EVDEVK(0x1f8)     v2.6.17 KEY_BRL_DOT8 */
/* Use: XK_braille_dot_9                _EVDEVK(0x1f9)     v2.6.23 KEY_BRL_DOT9 */
/* Use: XK_braille_dot_1                _EVDEVK(0x1fa)     v2.6.23 KEY_BRL_DOT10 */
#define XF86XK_Numeric0                 _EVDEVK(0x200)  /* v2.6.28 KEY_NUMERIC_0 */
#define XF86XK_Numeric1                 _EVDEVK(0x201)  /* v2.6.28 KEY_NUMERIC_1 */
#define XF86XK_Numeric2                 _EVDEVK(0x202)  /* v2.6.28 KEY_NUMERIC_2 */
#define XF86XK_Numeric3                 _EVDEVK(0x203)  /* v2.6.28 KEY_NUMERIC_3 */
#define XF86XK_Numeric4                 _EVDEVK(0x204)  /* v2.6.28 KEY_NUMERIC_4 */
#define XF86XK_Numeric5                 _EVDEVK(0x205)  /* v2.6.28 KEY_NUMERIC_5 */
#define XF86XK_Numeric6                 _EVDEVK(0x206)  /* v2.6.28 KEY_NUMERIC_6 */
#define XF86XK_Numeric7                 _EVDEVK(0x207)  /* v2.6.28 KEY_NUMERIC_7 */
#define XF86XK_Numeric8                 _EVDEVK(0x208)  /* v2.6.28 KEY_NUMERIC_8 */
#define XF86XK_Numeric9                 _EVDEVK(0x209)  /* v2.6.28 KEY_NUMERIC_9 */
#define XF86XK_NumericStar              _EVDEVK(0x20a)  /* v2.6.28 KEY_NUMERIC_STAR */
#define XF86XK_NumericPound             _EVDEVK(0x20b)  /* v2.6.28 KEY_NUMERIC_POUND */
#define XF86XK_NumericA                 _EVDEVK(0x20c)  /* v4.1    KEY_NUMERIC_A */
#define XF86XK_NumericB                 _EVDEVK(0x20d)  /* v4.1    KEY_NUMERIC_B */
#define XF86XK_NumericC                 _EVDEVK(0x20e)  /* v4.1    KEY_NUMERIC_C */
#define XF86XK_NumericD                 _EVDEVK(0x20f)  /* v4.1    KEY_NUMERIC_D */
#define XF86XK_CameraFocus              _EVDEVK(0x210)  /* v2.6.33 KEY_CAMERA_FOCUS */
#define XF86XK_WPSButton                _EVDEVK(0x211)  /* v2.6.34 KEY_WPS_BUTTON */
/* Use: XF86XK_TouchpadToggle           _EVDEVK(0x212)     v2.6.37 KEY_TOUCHPAD_TOGGLE */
/* Use: XF86XK_TouchpadOn               _EVDEVK(0x213)     v2.6.37 KEY_TOUCHPAD_ON */
/* Use: XF86XK_TouchpadOff              _EVDEVK(0x214)     v2.6.37 KEY_TOUCHPAD_OFF */
#define XF86XK_CameraZoomIn             _EVDEVK(0x215)  /* v2.6.39 KEY_CAMERA_ZOOMIN */
#define XF86XK_CameraZoomOut            _EVDEVK(0x216)  /* v2.6.39 KEY_CAMERA_ZOOMOUT */
#define XF86XK_CameraUp                 _EVDEVK(0x217)  /* v2.6.39 KEY_CAMERA_UP */
#define XF86XK_CameraDown               _EVDEVK(0x218)  /* v2.6.39 KEY_CAMERA_DOWN */
#define XF86XK_CameraLeft               _EVDEVK(0x219)  /* v2.6.39 KEY_CAMERA_LEFT */
#define XF86XK_CameraRight              _EVDEVK(0x21a)  /* v2.6.39 KEY_CAMERA_RIGHT */
#define XF86XK_AttendantOn              _EVDEVK(0x21b)  /* v3.10   KEY_ATTENDANT_ON */
#define XF86XK_AttendantOff             _EVDEVK(0x21c)  /* v3.10   KEY_ATTENDANT_OFF */
#define XF86XK_AttendantToggle          _EVDEVK(0x21d)  /* v3.10   KEY_ATTENDANT_TOGGLE */
#define XF86XK_LightsToggle             _EVDEVK(0x21e)  /* v3.10   KEY_LIGHTS_TOGGLE */
#define XF86XK_ALSToggle                _EVDEVK(0x230)  /* v3.13   KEY_ALS_TOGGLE */
/* Use: XF86XK_RotationLockToggle       _EVDEVK(0x231)     v4.16   KEY_ROTATE_LOCK_TOGGLE */
#define XF86XK_Buttonconfig             _EVDEVK(0x240)  /* v3.16   KEY_BUTTONCONFIG */
#define XF86XK_Taskmanager              _EVDEVK(0x241)  /* v3.16   KEY_TASKMANAGER */
#define XF86XK_Journal                  _EVDEVK(0x242)  /* v3.16   KEY_JOURNAL */
#define XF86XK_ControlPanel             _EVDEVK(0x243)  /* v3.16   KEY_CONTROLPANEL */
#define XF86XK_AppSelect                _EVDEVK(0x244)  /* v3.16   KEY_APPSELECT */
#define XF86XK_Screensaver              _EVDEVK(0x245)  /* v3.16   KEY_SCREENSAVER */
#define XF86XK_VoiceCommand             _EVDEVK(0x246)  /* v3.16   KEY_VOICECOMMAND */
#define XF86XK_Assistant                _EVDEVK(0x247)  /* v4.13   KEY_ASSISTANT */
/* Use: XK_ISO_Next_Group               _EVDEVK(0x248)     v5.2    KEY_KBD_LAYOUT_NEXT */
#define XF86XK_EmojiPicker              _EVDEVK(0x249)  /* v5.13   KEY_EMOJI_PICKER */
#define XF86XK_Dictate                  _EVDEVK(0x24a)  /* v5.17   KEY_DICTATE */
#define XF86XK_CameraAccessEnable       _EVDEVK(0x24b)  /* v6.2    KEY_CAMERA_ACCESS_ENABLE */
#define XF86XK_CameraAccessDisable      _EVDEVK(0x24c)  /* v6.2    KEY_CAMERA_ACCESS_DISABLE */
#define XF86XK_CameraAccessToggle       _EVDEVK(0x24d)  /* v6.2    KEY_CAMERA_ACCESS_TOGGLE */
#define XF86XK_BrightnessMin            _EVDEVK(0x250)  /* v3.16   KEY_BRIGHTNESS_MIN */
#define XF86XK_BrightnessMax            _EVDEVK(0x251)  /* v3.16   KEY_BRIGHTNESS_MAX */
#define XF86XK_KbdInputAssistPrev       _EVDEVK(0x260)  /* v3.18   KEY_KBDINPUTASSIST_PREV */
#define XF86XK_KbdInputAssistNext       _EVDEVK(0x261)  /* v3.18   KEY_KBDINPUTASSIST_NEXT */
#define XF86XK_KbdInputAssistPrevgroup  _EVDEVK(0x262)  /* v3.18   KEY_KBDINPUTASSIST_PREVGROUP */
#define XF86XK_KbdInputAssistNextgroup  _EVDEVK(0x263)  /* v3.18   KEY_KBDINPUTASSIST_NEXTGROUP */
#define XF86XK_KbdInputAssistAccept     _EVDEVK(0x264)  /* v3.18   KEY_KBDINPUTASSIST_ACCEPT */
#define XF86XK_KbdInputAssistCancel     _EVDEVK(0x265)  /* v3.18   KEY_KBDINPUTASSIST_CANCEL */
#define XF86XK_RightUp                  _EVDEVK(0x266)  /* v4.7    KEY_RIGHT_UP */
#define XF86XK_RightDown                _EVDEVK(0x267)  /* v4.7    KEY_RIGHT_DOWN */
#define XF86XK_LeftUp                   _EVDEVK(0x268)  /* v4.7    KEY_LEFT_UP */
#define XF86XK_LeftDown                 _EVDEVK(0x269)  /* v4.7    KEY_LEFT_DOWN */
#define XF86XK_RootMenu                 _EVDEVK(0x26a)  /* v4.7    KEY_ROOT_MENU */
#define XF86XK_MediaTopMenu             _EVDEVK(0x26b)  /* v4.7    KEY_MEDIA_TOP_MENU */
#define XF86XK_Numeric11                _EVDEVK(0x26c)  /* v4.7    KEY_NUMERIC_11 */
#define XF86XK_Numeric12                _EVDEVK(0x26d)  /* v4.7    KEY_NUMERIC_12 */
#define XF86XK_AudioDesc                _EVDEVK(0x26e)  /* v4.7    KEY_AUDIO_DESC */
#define XF86XK_3DMode                   _EVDEVK(0x26f)  /* v4.7    KEY_3D_MODE */
#define XF86XK_NextFavorite             _EVDEVK(0x270)  /* v4.7    KEY_NEXT_FAVORITE */
#define XF86XK_StopRecord               _EVDEVK(0x271)  /* v4.7    KEY_STOP_RECORD */
#define XF86XK_PauseRecord              _EVDEVK(0x272)  /* v4.7    KEY_PAUSE_RECORD */
#define XF86XK_VOD                      _EVDEVK(0x273)  /* v4.7    KEY_VOD */
#define XF86XK_Unmute                   _EVDEVK(0x274)  /* v4.7    KEY_UNMUTE */
#define XF86XK_FastReverse              _EVDEVK(0x275)  /* v4.7    KEY_FASTREVERSE */
#define XF86XK_SlowReverse              _EVDEVK(0x276)  /* v4.7    KEY_SLOWREVERSE */
#define XF86XK_Data                     _EVDEVK(0x277)  /* v4.7    KEY_DATA */
#define XF86XK_OnScreenKeyboard         _EVDEVK(0x278)  /* v4.12   KEY_ONSCREEN_KEYBOARD */
#define XF86XK_PrivacyScreenToggle      _EVDEVK(0x279)  /* v5.5    KEY_PRIVACY_SCREEN_TOGGLE */
#define XF86XK_SelectiveScreenshot      _EVDEVK(0x27a)  /* v5.6    KEY_SELECTIVE_SCREENSHOT */
#define XF86XK_NextElement              _EVDEVK(0x27b)  /* v5.18   KEY_NEXT_ELEMENT */
#define XF86XK_PreviousElement          _EVDEVK(0x27c)  /* v5.18   KEY_PREVIOUS_ELEMENT */
#define XF86XK_AutopilotEngageToggle    _EVDEVK(0x27d)  /* v5.18   KEY_AUTOPILOT_ENGAGE_TOGGLE */
#define XF86XK_MarkWaypoint             _EVDEVK(0x27e)  /* v5.18   KEY_MARK_WAYPOINT */
#define XF86XK_Sos                      _EVDEVK(0x27f)  /* v5.18   KEY_SOS */
#define XF86XK_NavChart                 _EVDEVK(0x280)  /* v5.18   KEY_NAV_CHART */
#define XF86XK_FishingChart             _EVDEVK(0x281)  /* v5.18   KEY_FISHING_CHART */
#define XF86XK_SingleRangeRadar         _EVDEVK(0x282)  /* v5.18   KEY_SINGLE_RANGE_RADAR */
#define XF86XK_DualRangeRadar           _EVDEVK(0x283)  /* v5.18   KEY_DUAL_RANGE_RADAR */
#define XF86XK_RadarOverlay             _EVDEVK(0x284)  /* v5.18   KEY_RADAR_OVERLAY */
#define XF86XK_TraditionalSonar         _EVDEVK(0x285)  /* v5.18   KEY_TRADITIONAL_SONAR */
#define XF86XK_ClearvuSonar             _EVDEVK(0x286)  /* v5.18   KEY_CLEARVU_SONAR */
#define XF86XK_SidevuSonar              _EVDEVK(0x287)  /* v5.18   KEY_SIDEVU_SONAR */
#define XF86XK_NavInfo                  _EVDEVK(0x288)  /* v5.18   KEY_NAV_INFO */
/* Use: XF86XK_BrightnessAdjust         _EVDEVK(0x289)     v5.18   KEY_BRIGHTNESS_MENU */
#define XF86XK_Macro1                   _EVDEVK(0x290)  /* v5.5    KEY_MACRO1 */
#define XF86XK_Macro2                   _EVDEVK(0x291)  /* v5.5    KEY_MACRO2 */
#define XF86XK_Macro3                   _EVDEVK(0x292)  /* v5.5    KEY_MACRO3 */
#define XF86XK_Macro4                   _EVDEVK(0x293)  /* v5.5    KEY_MACRO4 */
#define XF86XK_Macro5                   _EVDEVK(0x294)  /* v5.5    KEY_MACRO5 */
#define XF86XK_Macro6                   _EVDEVK(0x295)  /* v5.5    KEY_MACRO6 */
#define XF86XK_Macro7                   _EVDEVK(0x296)  /* v5.5    KEY_MACRO7 */
#define XF86XK_Macro8                   _EVDEVK(0x297)  /* v5.5    KEY_MACRO8 */
#define XF86XK_Macro9                   _EVDEVK(0x298)  /* v5.5    KEY_MACRO9 */
#define XF86XK_Macro10                  _EVDEVK(0x299)  /* v5.5    KEY_MACRO10 */
#define XF86XK_Macro11                  _EVDEVK(0x29a)  /* v5.5    KEY_MACRO11 */
#define XF86XK_Macro12                  _EVDEVK(0x29b)  /* v5.5    KEY_MACRO12 */
#define XF86XK_Macro13                  _EVDEVK(0x29c)  /* v5.5    KEY_MACRO13 */
#define XF86XK_Macro14                  _EVDEVK(0x29d)  /* v5.5    KEY_MACRO14 */
#define XF86XK_Macro15                  _EVDEVK(0x29e)  /* v5.5    KEY_MACRO15 */
#define XF86XK_Macro16                  _EVDEVK(0x29f)  /* v5.5    KEY_MACRO16 */
#define XF86XK_Macro17                  _EVDEVK(0x2a0)  /* v5.5    KEY_MACRO17 */
#define XF86XK_Macro18                  _EVDEVK(0x2a1)  /* v5.5    KEY_MACRO18 */
#define XF86XK_Macro19                  _EVDEVK(0x2a2)  /* v5.5    KEY_MACRO19 */
#define XF86XK_Macro20                  _EVDEVK(0x2a3)  /* v5.5    KEY_MACRO20 */
#define XF86XK_Macro21                  _EVDEVK(0x2a4)  /* v5.5    KEY_MACRO21 */
#define XF86XK_Macro22                  _EVDEVK(0x2a5)  /* v5.5    KEY_MACRO22 */
#define XF86XK_Macro23                  _EVDEVK(0x2a6)  /* v5.5    KEY_MACRO23 */
#define XF86XK_Macro24                  _EVDEVK(0x2a7)  /* v5.5    KEY_MACRO24 */
#define XF86XK_Macro25                  _EVDEVK(0x2a8)  /* v5.5    KEY_MACRO25 */
#define XF86XK_Macro26                  _EVDEVK(0x2a9)  /* v5.5    KEY_MACRO26 */
#define XF86XK_Macro27                  _EVDEVK(0x2aa)  /* v5.5    KEY_MACRO27 */
#define XF86XK_Macro28                  _EVDEVK(0x2ab)  /* v5.5    KEY_MACRO28 */
#define XF86XK_Macro29                  _EVDEVK(0x2ac)  /* v5.5    KEY_MACRO29 */
#define XF86XK_Macro30                  _EVDEVK(0x2ad)  /* v5.5    KEY_MACRO30 */
#define XF86XK_MacroRecordStart         _EVDEVK(0x2b0)  /* v5.5    KEY_MACRO_RECORD_START */
#define XF86XK_MacroRecordStop          _EVDEVK(0x2b1)  /* v5.5    KEY_MACRO_RECORD_STOP */
#define XF86XK_MacroPresetCycle         _EVDEVK(0x2b2)  /* v5.5    KEY_MACRO_PRESET_CYCLE */
#define XF86XK_MacroPreset1             _EVDEVK(0x2b3)  /* v5.5    KEY_MACRO_PRESET1 */
#define XF86XK_MacroPreset2             _EVDEVK(0x2b4)  /* v5.5    KEY_MACRO_PRESET2 */
#define XF86XK_MacroPreset3             _EVDEVK(0x2b5)  /* v5.5    KEY_MACRO_PRESET3 */
#define XF86XK_KbdLcdMenu1              _EVDEVK(0x2b8)  /* v5.5    KEY_KBD_LCD_MENU1 */
#define XF86XK_KbdLcdMenu2              _EVDEVK(0x2b9)  /* v5.5    KEY_KBD_LCD_MENU2 */
#define XF86XK_KbdLcdMenu3              _EVDEVK(0x2ba)  /* v5.5    KEY_KBD_LCD_MENU3 */
#define XF86XK_KbdLcdMenu4              _EVDEVK(0x2bb)  /* v5.5    KEY_KBD_LCD_MENU4 */
#define XF86XK_KbdLcdMenu5              _EVDEVK(0x2bc)  /* v5.5    KEY_KBD_LCD_MENU5 */
#undef _EVDEVK

Changes to xlib/X11/Xfuncproto.h.


1
2
3
4
5
6
7
8
9
10








11
12
13

14
15
16
17
18
19
20

21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


72
73



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
1
2









3
4
5
6
7
8
9
10



11







12



13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39









40
41
42
43
44
45
46
47
48
49



50
51
52

53
54
55
56
57

58
59









































































































































60
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+













-
+












-
-
-
-
-
-
-
-
-










-
-
-
+
+

-
+
+
+


-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

/* $XConsortium: Xfuncproto.h,v 1.7 91/05/13 20:49:21 rws Exp $ */
/*
 *
Copyright 1989, 1991, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

 * Copyright 1989, 1991 by the Massachusetts Institute of Technology
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

 * written prior permission. M.I.T. makes no representations about the
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 * suitability of this software for any purpose.  It is provided "as is"
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
 * without express or implied warranty.
 *
 */

/* Definitions to make function prototypes manageable */

#ifndef _XFUNCPROTO_H_
#define _XFUNCPROTO_H_

#ifndef NeedFunctionPrototypes
#define NeedFunctionPrototypes 1
#endif /* NeedFunctionPrototypes */

#ifndef NeedVarargsPrototypes
#define NeedVarargsPrototypes 1
#define NeedVarargsPrototypes 0
#endif /* NeedVarargsPrototypes */

#if NeedFunctionPrototypes

#ifndef NeedNestedPrototypes
#define NeedNestedPrototypes 1
#endif /* NeedNestedPrototypes */

#ifndef _Xconst
#define _Xconst const
#endif /* _Xconst */

/* Function prototype configuration (see configure for more info) */
#if !defined(NARROWPROTO) && \
    (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__))
#define NARROWPROTO
#endif
#ifndef FUNCPROTO
#define FUNCPROTO 15
#endif

#ifndef NeedWidePrototypes
#ifdef NARROWPROTO
#define NeedWidePrototypes 0
#else
#define NeedWidePrototypes 1		/* default to make interropt. easier */
#endif
#endif /* NeedWidePrototypes */

#endif /* NeedFunctionPrototypes */

#ifndef _XFUNCPROTOBEGIN
#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
#define _XFUNCPROTOBEGIN extern "C" {	/* do not leave open across includes */
#ifdef __cplusplus
#define _XFUNCPROTOBEGIN extern "C" {
#define _XFUNCPROTOEND }
#else
#endif

#ifndef _XFUNCPROTOBEGIN
#define _XFUNCPROTOBEGIN
#define _XFUNCPROTOEND
#endif
#endif /* _XFUNCPROTOBEGIN */

/* http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute */
#ifndef __has_attribute
# define __has_attribute(x) 0  /* Compatibility with non-clang compilers. */
#endif
#ifndef __has_feature
# define __has_feature(x) 0    /* Compatibility with non-clang compilers. */
#endif
#ifndef __has_extension
# define __has_extension(x) 0  /* Compatibility with non-clang compilers. */
#endif

/* Added in X11R6.9, so available in any version of modular xproto */
#if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
# define _X_SENTINEL(x) __attribute__ ((__sentinel__(x)))
#else
# define _X_SENTINEL(x)
#endif /* GNUC >= 4 */

/* Added in X11R6.9, so available in any version of modular xproto */
#if (__has_attribute(visibility) || (defined(__GNUC__) && (__GNUC__ >= 4))) \
    && !defined(__CYGWIN__) && !defined(__MINGW32__)
# define _X_EXPORT      __attribute__((visibility("default")))
# define _X_HIDDEN      __attribute__((visibility("hidden")))
# define _X_INTERNAL    __attribute__((visibility("internal")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
# define _X_EXPORT      __global
# define _X_HIDDEN      __hidden
# define _X_INTERNAL    __hidden
#else /* not gcc >= 4 and not Sun Studio >= 8 */
# define _X_EXPORT
# define _X_HIDDEN
# define _X_INTERNAL
#endif /* GNUC >= 4 */

/* Branch prediction hints for individual conditionals */
/* requires xproto >= 7.0.9 */
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
# define _X_LIKELY(x)   __builtin_expect(!!(x), 1)
# define _X_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else /* not gcc >= 3.3 */
# define _X_LIKELY(x)   (x)
# define _X_UNLIKELY(x) (x)
#endif

/* Bulk branch prediction hints via marking error path functions as "cold" */
/* requires xproto >= 7.0.25 */
#if __has_attribute(__cold__) || \
    (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) /* 4.3+ */
# define _X_COLD __attribute__((__cold__))
#else
# define _X_COLD /* nothing */
#endif

/* Added in X11R6.9, so available in any version of modular xproto */
#if __has_attribute(deprecated) \
    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)) \
    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5130))
# define _X_DEPRECATED  __attribute__((deprecated))
#else /* not gcc >= 3.1 */
# define _X_DEPRECATED
#endif

/* requires xproto >= 7.0.30 */
#if __has_extension(attribute_deprecated_with_message) || \
                (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
# define _X_DEPRECATED_MSG(_msg) __attribute__((deprecated(_msg)))
#else
# define _X_DEPRECATED_MSG(_msg) _X_DEPRECATED
#endif

/* requires xproto >= 7.0.17 */
#if __has_attribute(noreturn) \
    || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
    || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
# define _X_NORETURN __attribute((noreturn))
#else
# define _X_NORETURN
#endif /* GNUC  */

/* Added in X11R6.9, so available in any version of modular xproto */
#if __has_attribute(__format__) \
    || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
# define _X_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
#else /* not gcc >= 2.3 */
# define _X_ATTRIBUTE_PRINTF(x,y)
#endif

/* requires xproto >= 7.0.22 */
#if __has_attribute(__unused__) \
    || defined(__GNUC__) &&  ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)
#define _X_UNUSED  __attribute__((__unused__))
#else
#define _X_UNUSED  /* */
#endif

/* C99 keyword "inline" or equivalent extensions in pre-C99 compilers */
/* requires xproto >= 7.0.9
   (introduced in 7.0.8 but didn't support all compilers until 7.0.9) */
#if defined(inline) /* assume autoconf set it correctly */ || \
   (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */ || \
   (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550))
# define _X_INLINE inline
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
# define _X_INLINE __inline__
#else
# define _X_INLINE
#endif

/* C99 keyword "restrict" or equivalent extensions in pre-C99 compilers */
/* requires xproto >= 7.0.21 */
#ifndef _X_RESTRICT_KYWD
# if defined(restrict) /* assume autoconf set it correctly */ || \
    (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */ \
     && !defined(__cplusplus)) /* Workaround g++ issue on Solaris */
#  define _X_RESTRICT_KYWD  restrict
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
#  define _X_RESTRICT_KYWD __restrict__
# else
#  define _X_RESTRICT_KYWD
# endif
#endif

/* requires xproto >= 7.0.30 */
#if __has_attribute(no_sanitize_thread)
# define _X_NOTSAN __attribute__((no_sanitize_thread))
#else
# define _X_NOTSAN
#endif

/* Mark a char array/pointer as not containing a NUL-terminated string */
/* requires xproto >= 7.0.33 */
#if __has_attribute(nonstring)
# define _X_NONSTRING __attribute__((nonstring))
#else
# define _X_NONSTRING
#endif

#endif /* _XFUNCPROTO_H_ */

Changes to xlib/X11/Xlib.h.


1
2
3
4
5
6
7
8
9
10
11
12
13











14
15
16
17
18
19
20

21
22
23
24
25



26
27
28
29
30
31
32
33
34


35
36

37
38
39

40
41

42
43
44





45
46
47






48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111








112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133





















134
135
136
137


138
139
140
141
142
143
144
1
2












3
4
5
6
7
8
9
10
11
12
13







14





15
16
17
18
19
20
21
22
23
24


25
26
27

28
29


30


31
32


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
































55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70








71
72
73
74
75
76
77
78
79





















80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
110
111
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+







-
-
+
+

-
+

-
-
+
-
-
+

-
-
+
+
+
+
+



+
+
+
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+







/* $XConsortium: Xlib.h,v 11.221 93/07/02 14:13:28 gildea Exp $ */
/*

Copyright 1985, 1986, 1987, 1991, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

 * Copyright 1985, 1986, 1987, 1991 by the Massachusetts Institute of Technology
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission. M.I.T. makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 *
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.

*/
 * X Window System is a Trademark of MIT.
 *
 */


/*
 *	Xlib.h - Header definition and support file for the C subroutine
 *	interface library (Xlib) to the X Window System Protocol (V11).
 *	Structures and symbols starting with "_" are private to the library.
 */
#ifndef _X11_XLIB_H_
#define _X11_XLIB_H_
#ifndef _XLIB_H_
#define _XLIB_H_

#define XlibSpecificationRelease 6
#define XlibSpecificationRelease 5

#include <sys/types.h>

#if !defined(MAC_OSX_TK)
#if defined(__SCO__) || defined(__UNIXWARE__)
#include <stdint.h>
#   include <X11/X.h>
#endif

#include <X11/X.h>
#ifdef MAC_OSX_TK
#   include <X11/X.h>
#   define Cursor XCursor
#   define Region XRegion
#endif

/* applications should not depend on these two headers being included! */
#include <X11/Xfuncproto.h>

#ifndef X_WCHAR
#ifdef X_NOT_STDC_ENV
#define X_WCHAR
#endif
#endif

#ifndef X_WCHAR
#include <stddef.h>
#else
/* replace this with #include or typedef appropriate for your system */
typedef unsigned long wchar_t;
#endif

#ifndef EXTERN
#   define EXTERN extern TCL_STORAGE_CLASS
#endif
#if defined(STATIC_BUILD) || !defined(_WIN32)
# ifndef TCL_STORAGE_CLASS
#   define TCL_STORAGE_CLASS
# endif
#elif defined(BUILD_tk)
# undef TCL_STORAGE_CLASS
# define TCL_STORAGE_CLASS __declspec(dllexport)
#elif !defined(TCL_STORAGE_CLASS)
# define TCL_STORAGE_CLASS __declspec(dllimport)
#endif

EXTERN int
_Xmblen(
    char *str,
    int len
    );

/* API mentioning "UTF8" or "utf8" is an XFree86 extension, introduced in
   November 2000. Its presence is indicated through the following macro. */
#define X_HAVE_UTF8_STRING 1

/* The Xlib structs are full of implicit padding to properly align members.
   We can't clean that up without breaking ABI, so tell clang not to bother
   complaining about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif

typedef char *XPointer;

#define Bool int
#if defined(MAC_OSX_TK)
/* Use define rather than typedef, since may need to undefine this later */
#define Status int
#else
typedef int Status;
#endif
#define True 1
#define False 0

#define QueuedAlready 0
#define QueuedAfterReading 1
#define QueuedAfterFlush 2

#define ConnectionNumber(dpy) 	(((_XPrivDisplay)(dpy))->fd)
#define RootWindow(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->root)
#define DefaultScreen(dpy) 	(((_XPrivDisplay)(dpy))->default_screen)
#define DefaultRootWindow(dpy) 	(ScreenOfDisplay(dpy,DefaultScreen(dpy))->root)
#define DefaultVisual(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_visual)
#define DefaultGC(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->default_gc)
#define BlackPixel(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->black_pixel)
#define WhitePixel(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->white_pixel)
#define ConnectionNumber(dpy) 	((dpy)->fd)
#define RootWindow(dpy, scr) 	(((dpy)->screens[(scr)]).root)
#define DefaultScreen(dpy) 	((dpy)->default_screen)
#define DefaultRootWindow(dpy) 	(((dpy)->screens[(dpy)->default_screen]).root)
#define DefaultVisual(dpy, scr) (((dpy)->screens[(scr)]).root_visual)
#define DefaultGC(dpy, scr) 	(((dpy)->screens[(scr)]).default_gc)
#define BlackPixel(dpy, scr) 	(((dpy)->screens[(scr)]).black_pixel)
#define WhitePixel(dpy, scr) 	(((dpy)->screens[(scr)]).white_pixel)
#define AllPlanes 		((unsigned long)~0L)
#define QLength(dpy) 		(((_XPrivDisplay)(dpy))->qlen)
#define DisplayWidth(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->width)
#define DisplayHeight(dpy, scr) (ScreenOfDisplay(dpy,scr)->height)
#define DisplayWidthMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mwidth)
#define DisplayHeightMM(dpy, scr)(ScreenOfDisplay(dpy,scr)->mheight)
#define DisplayPlanes(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_depth)
#define DisplayCells(dpy, scr) 	(DefaultVisual(dpy,scr)->map_entries)
#define ScreenCount(dpy) 	(((_XPrivDisplay)(dpy))->nscreens)
#define ServerVendor(dpy) 	(((_XPrivDisplay)(dpy))->vendor)
#define ProtocolVersion(dpy) 	(((_XPrivDisplay)(dpy))->proto_major_version)
#define ProtocolRevision(dpy) 	(((_XPrivDisplay)(dpy))->proto_minor_version)
#define VendorRelease(dpy) 	(((_XPrivDisplay)(dpy))->release)
#define DisplayString(dpy) 	(((_XPrivDisplay)(dpy))->display_name)
#define DefaultDepth(dpy, scr) 	(ScreenOfDisplay(dpy,scr)->root_depth)
#define DefaultColormap(dpy, scr)(ScreenOfDisplay(dpy,scr)->cmap)
#define BitmapUnit(dpy) 	(((_XPrivDisplay)(dpy))->bitmap_unit)
#define BitmapBitOrder(dpy) 	(((_XPrivDisplay)(dpy))->bitmap_bit_order)
#define BitmapPad(dpy) 		(((_XPrivDisplay)(dpy))->bitmap_pad)
#define ImageByteOrder(dpy) 	(((_XPrivDisplay)(dpy))->byte_order)
#define NextRequest(dpy)	(((_XPrivDisplay)(dpy))->request + 1)
#define LastKnownRequestProcessed(dpy)	(((_XPrivDisplay)(dpy))->request)
#define QLength(dpy) 		((dpy)->qlen)
#define DisplayWidth(dpy, scr) 	(((dpy)->screens[(scr)]).width)
#define DisplayHeight(dpy, scr) (((dpy)->screens[(scr)]).height)
#define DisplayWidthMM(dpy, scr)(((dpy)->screens[(scr)]).mwidth)
#define DisplayHeightMM(dpy, scr)(((dpy)->screens[(scr)]).mheight)
#define DisplayPlanes(dpy, scr) (((dpy)->screens[(scr)]).root_depth)
#define DisplayCells(dpy, scr) 	(DefaultVisual((dpy), (scr))->map_entries)
#define ScreenCount(dpy) 	((dpy)->nscreens)
#define ServerVendor(dpy) 	((dpy)->vendor)
#define ProtocolVersion(dpy) 	((dpy)->proto_major_version)
#define ProtocolRevision(dpy) 	((dpy)->proto_minor_version)
#define VendorRelease(dpy) 	((dpy)->release)
#define DisplayString(dpy) 	((dpy)->display_name)
#define DefaultDepth(dpy, scr) 	(((dpy)->screens[(scr)]).root_depth)
#define DefaultColormap(dpy, scr)(((dpy)->screens[(scr)]).cmap)
#define BitmapUnit(dpy) 	((dpy)->bitmap_unit)
#define BitmapBitOrder(dpy) 	((dpy)->bitmap_bit_order)
#define BitmapPad(dpy) 		((dpy)->bitmap_pad)
#define ImageByteOrder(dpy) 	((dpy)->byte_order)
#define NextRequest(dpy)	((dpy)->request + 1)
#define LastKnownRequestProcessed(dpy)	((dpy)->request)

/* macros for screen oriented applications (toolkit) */
#define ScreenOfDisplay(dpy, scr)(&((_XPrivDisplay)(dpy))->screens[scr])
#define DefaultScreenOfDisplay(dpy) ScreenOfDisplay(dpy,DefaultScreen(dpy))
#define ScreenOfDisplay(dpy, scr)(&((dpy)->screens[(scr)]))
#define DefaultScreenOfDisplay(dpy) (&((dpy)->screens[(dpy)->default_screen]))
#define DisplayOfScreen(s)	((s)->display)
#define RootWindowOfScreen(s)	((s)->root)
#define BlackPixelOfScreen(s)	((s)->black_pixel)
#define WhitePixelOfScreen(s)	((s)->white_pixel)
#define DefaultColormapOfScreen(s)((s)->cmap)
#define DefaultDepthOfScreen(s)	((s)->root_depth)
#define DefaultGCOfScreen(s)	((s)->default_gc)
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
124
125
126
127
128
129
130

131


132
133
134
135
136
137
138







-
+
-
-








/*
 * Extensions need a way to hang private data on some structures.
 */
typedef struct _XExtData {
	int number;		/* number returned by XRegisterExtension */
	struct _XExtData *next;	/* next item on list of data for structure */
	int (*free_private)(	/* called to free private storage */
	int (*free_private)();	/* called to free private storage */
	struct _XExtData *extension
	);
	XPointer private_data;	/* data private to this extension. */
} XExtData;

/*
 * This file contains structures used by the extension mechanism.
 */
typedef struct {		/* public to extension, cannot be changed */
198
199
200
201
202
203
204
205

206
207
208
209

210
211
212
213
214
215
216
163
164
165
166
167
168
169

170
171
172
173

174
175
176
177
178
179
180
181







-
+



-
+







	unsigned long background;/* background pixel */
	int line_width;		/* line width */
	int line_style;	 	/* LineSolid, LineOnOffDash, LineDoubleDash */
	int cap_style;	  	/* CapNotLast, CapButt,
				   CapRound, CapProjecting */
	int join_style;	 	/* JoinMiter, JoinRound, JoinBevel */
	int fill_style;	 	/* FillSolid, FillTiled,
				   FillStippled, FillOpaqueStippled */
				   FillStippled, FillOpaeueStippled */
	int fill_rule;	  	/* EvenOddRule, WindingRule */
	int arc_mode;		/* ArcChord, ArcPieSlice */
	Pixmap tile;		/* tile pixmap for tiling operations */
	Pixmap stipple;		/* stipple 1 plane pixmap for stippling */
	Pixmap stipple;		/* stipple 1 plane pixmap for stipping */
	int ts_x_origin;	/* offset for tile or stipple operations */
	int ts_y_origin;
        Font font;	        /* default text font for text operations */
	int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
	Bool graphics_exposures;/* boolean, should exposures be generated */
	int clip_x_origin;	/* origin for clipping */
	int clip_y_origin;
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
217
218
219
220
221
222
223



224
225
226
227
228
229
230







-
-
-







} Depth;

/*
 * Information about the screen.  The contents of this structure are
 * implementation dependent.  A Screen should be treated as opaque
 * by application code.
 */

struct _XDisplay;		/* Forward declare before use for C++ */

typedef struct {
	XExtData *ext_data;	/* hook for extension to hang data */
	struct _XDisplay *display;/* back pointer to display structure */
	Window root;		/* Root window id. */
	int width, height;	/* width and height of screen */
	int mwidth, mheight;	/* width and height of  in millimeters */
	int ndepths;		/* number of depths possible */
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272







-
+







    Pixmap background_pixmap;	/* background or None or ParentRelative */
    unsigned long background_pixel;	/* background pixel */
    Pixmap border_pixmap;	/* border of the window */
    unsigned long border_pixel;	/* border pixel value */
    int bit_gravity;		/* one of bit gravity values */
    int win_gravity;		/* one of the window gravity values */
    int backing_store;		/* NotUseful, WhenMapped, Always */
    unsigned long backing_planes;/* planes to be preserved if possible */
    unsigned long backing_planes;/* planes to be preseved if possible */
    unsigned long backing_pixel;/* value to use in restoring planes */
    Bool save_under;		/* should bits under be saved? (popups) */
    long event_mask;		/* set of events that should be saved */
    long do_not_propagate_mask;	/* set of events that should not propagate */
    Bool override_redirect;	/* boolean value for override-redirect */
    Colormap colormap;		/* color map to be associated with window */
    Cursor cursor;		/* cursor to be displayed (or None) */
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

376
377

378
379
380



381
382

383
384
385
386

387
388
389
390
391
392
393
394
395
396
397







398
399
400
401
402
403
404
307
308
309
310
311
312
313










314
315
316
317
318
319
320
321
322
323
324
325
326

327
328

329
330
331
332
333
334
335
336

337




338






339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357







-
-
-
-
-
-
-
-
-
-













-
+

-
+



+
+
+

-
+
-
-
-
-
+
-
-
-
-
-
-





+
+
+
+
+
+
+








typedef struct {
	int family;		/* for example FamilyInternet */
	int length;		/* length of address, in bytes */
	char *address;		/* pointer to where to find the bytes */
} XHostAddress;

/*
 * Data structure for ServerFamilyInterpreted addresses in host routines
 */
typedef struct {
	int typelength;		/* length of type string, in bytes */
	int valuelength;	/* length of value string, in bytes */
	char *type;		/* pointer to where to find the type string */
	char *value;		/* pointer to where to find the address */
} XServerInterpretedAddress;

/*
 * Data structure for "image" data, used by image manipulation routines.
 */
typedef struct _XImage {
    int width, height;		/* size of image */
    int xoffset;		/* number of pixels offset in X direction */
    int format;			/* XYBitmap, XYPixmap, ZPixmap */
    char *data;			/* pointer to image data */
    int byte_order;		/* data byte order, LSBFirst, MSBFirst */
    int bitmap_unit;		/* quant. of scanline 8, 16, 32 */
    int bitmap_bit_order;	/* LSBFirst, MSBFirst */
    int bitmap_pad;		/* 8, 16, 32 either XY or ZPixmap */
    int depth;			/* depth of image */
    int bytes_per_line;		/* accelerator to next line */
    int bytes_per_line;		/* accelarator to next line */
    int bits_per_pixel;		/* bits per pixel (ZPixmap) */
    unsigned long red_mask;	/* bits in z arrangement */
    unsigned long red_mask;	/* bits in z arrangment */
    unsigned long green_mask;
    unsigned long blue_mask;
    XPointer obdata;		/* hook for the object routines to hang on */
#if defined(MAC_OSX_TK)
    int pixelpower;		/* n such that pixels are 2^n x 2^n blocks*/
#endif
    struct funcs {		/* image manipulation routines */
	struct _XImage *(*create_image)(
	struct _XImage *(*create_image)();
		struct _XDisplay* /* display */,
		Visual*		/* visual */,
		unsigned int	/* depth */,
		int		/* format */,
#if NeedFunctionPrototypes
		int		/* offset */,
		char*		/* data */,
		unsigned int	/* width */,
		unsigned int	/* height */,
		int		/* bitmap_pad */,
		int		/* bytes_per_line */);
	int (*destroy_image)        (struct _XImage *);
	unsigned long (*get_pixel)  (struct _XImage *, int, int);
	int (*put_pixel)            (struct _XImage *, int, int, unsigned long);
	struct _XImage *(*sub_image)(struct _XImage *, int, int, unsigned int, unsigned int);
	int (*add_pixel)            (struct _XImage *, long);
#else
	int (*destroy_image)();
	unsigned long (*get_pixel)();
	int (*put_pixel)();
	struct _XImage *(*sub_image)();
	int (*add_pixel)();
#endif
	} f;
} XImage;

/*
 * Data structure for XReconfigureWindow
 */
typedef struct {
484
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501
502
503
504

505
506
507


508
509
510
511
512
513
514





515
516
517
518
519
520
521
522
523

524
525

526
527
528

529
530
531



532
533
534
535

536
537
538
539
540
541
542
543

544
545
546
547
548



549





























550
551






552
553





554
555
556

557

558



559
560
561
562
563
564
565
566
567
568

569
570
571
572
573
574
575



576
577
578
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621

622
623
624
625
626
627
628
437
438
439
440
441
442
443


444










445

446
447


448
449
450
451





452
453
454
455
456


457
458
459
460
461
462

463
464

465
466

467
468



469
470
471

472
473

474


475
476
477
478
479

480
481
482



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515


516
517
518
519
520
521


522
523
524
525
526


527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606
607







-
-
+
-
-
-
-
-
-
-
-
-
-

-
+

-
-
+
+


-
-
-
-
-
+
+
+
+
+
-
-






-
+

-
+

-

+
-
-
-
+
+
+
-


-
+
-
-





-
+


-
-
-
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
-
-

+

+

+
+
+









-
+







+
+
+










-
+

















-
+
















-
+









/*
 * Display datatype maintaining display specific data.
 * The contents of this structure are implementation dependent.
 * A Display should be treated as opaque by application code.
 */
#ifndef XLIB_ILLEGAL_ACCESS
typedef struct _XDisplay Display;
typedef struct _XDisplay {
#endif

struct _XPrivate;		/* Forward declare before use for C++ */
struct _XrmHashBucketRec;

typedef struct
#ifdef XLIB_ILLEGAL_ACCESS
_XDisplay
#endif
{
	XExtData *ext_data;	/* hook for extension to hang data */
	struct _XPrivate *private1;
	struct _XFreeFuncs *free_funcs; /* internal free functions */
	int fd;			/* Network socket. */
	int private2;
	int proto_major_version;/* major version of server's X protocol */
	int conn_checker;         /* ugly thing used by _XEventsQueued */
	int proto_major_version;/* maj. version of server's X protocol */
	int proto_minor_version;/* minor version of servers X protocol */
	char *vendor;		/* vendor of the server hardware */
        XID private3;
	XID private4;
	XID private5;
	int private6;
	XID (*resource_alloc)(	/* allocator function */
        XID resource_base;	/* resource ID base */
	XID resource_mask;	/* resource ID mask bits */
	XID resource_id;	/* allocator current ID */
	int resource_shift;	/* allocator shift to correct bits */
	XID (*resource_alloc)(); /* allocator function */
		struct _XDisplay*
	);
	int byte_order;		/* screen byte order, LSBFirst, MSBFirst */
	int bitmap_unit;	/* padding and data requirements */
	int bitmap_pad;		/* padding requirements on bitmaps */
	int bitmap_bit_order;	/* LeastSignificant or MostSignificant */
	int nformats;		/* number of pixmap formats in list */
	ScreenFormat *pixmap_format;	/* pixmap format list */
	int private8;
	int vnumber;		/* Xlib's X protocol version number. */
	int release;		/* release of the server */
	struct _XPrivate *private9, *private10;
	struct _XSQEvent *head, *tail;	/* Input event queue. */
	int qlen;		/* Length of input event queue */
	unsigned long last_request_read; /* seq number of last event read */
	unsigned long request;	/* sequence number of last request. */
	char *last_req;		/* beginning of last request, or dummy */
	XPointer private11;
	XPointer private12;
	XPointer private13;
	char *buffer;		/* Output buffer starting address. */
	char *bufptr;		/* Output buffer index pointer. */
	char *bufmax;		/* Output buffer maximum+1 address. */
	XPointer private14;
	unsigned max_request_size; /* maximum number 32 bit words in request*/
	struct _XrmHashBucketRec *db;
	int (*private15)(
	int (*synchandler)();	/* Synchronization handler */
		struct _XDisplay*
		);
	char *display_name;	/* "host:display" string used on this connect*/
	int default_screen;	/* default screen for operations */
	int nscreens;		/* number of screens on this server*/
	Screen *screens;	/* pointer to list of screens */
	unsigned long motion_buffer;	/* size of motion buffer */
	unsigned long private16;
	unsigned long flags;	/* internal connection flags */
	int min_keycode;	/* minimum defined keycode */
	int max_keycode;	/* maximum defined keycode */
	XPointer private17;
	XPointer private18;
	int private19;
	KeySym *keysyms;	/* This server's keysyms */
	XModifierKeymap *modifiermap;	/* This server's modifier keymap */
	int keysyms_per_keycode;/* number of rows */
	char *xdefaults;	/* contents of defaults from server */
	char *scratch_buffer;	/* place to hang scratch buffer */
	unsigned long scratch_length;	/* length of scratch buffer */
	int ext_number;		/* extension number on this display */
	struct _XExten *ext_procs; /* extensions initialized on this display */
	/*
	 * the following can be fixed size, as the protocol defines how
	 * much address space is available.
	 * While this could be done using the extension vector, there
	 * may be MANY events processed, so a search through the extension
	 * list to find the right procedure for each event might be
	 * expensive if many extensions are being used.
	 */
	Bool (*event_vec[128])();  /* vector for wire to event */
	Status (*wire_vec[128])(); /* vector for event to wire */
	KeySym lock_meaning;	   /* for XLookupString */
	struct _XLockInfo *lock;   /* multi-thread state, display lock */
	struct _XInternalAsync *async_handlers; /* for internal async */
	unsigned long bigreq_size; /* max size of big requests */
	struct _XLockPtrs *lock_fns; /* pointers to threads functions */
	/* things above this line should not move, for binary compatibility */
	struct _XKeytrans *key_bindings; /* for XLookupString */
	Font cursor_font;	   /* for XCreateFontCursor */
	struct _XDisplayAtoms *atoms; /* for XInternAtom */
	unsigned int mode_switch;  /* keyboard group modifiers */
	struct _XContextDB *context_db; /* context database */
	Bool (**error_vec)();      /* vector for wire to error */
	/*
	 * Xcms information
	 */
	/* there is more to this structure, but it is private to Xlib */
}
	struct {
	   XPointer defaultCCCs;  /* pointer to an array of default XcmsCCC */
	   XPointer clientCmaps;  /* pointer to linked list of XcmsCmapRec */
	   XPointer perVisualIntensityMaps;
				  /* linked list of XcmsIntensityMap */
	} cms;
#ifdef XLIB_ILLEGAL_ACCESS
Display,
	struct _XIMFilter *im_filters;
	struct _XSQEvent *qfree; /* unallocated event queue elements */
	unsigned long next_event_serial_num; /* inserted into next queue elt */
	int (*savedsynchandler)(); /* user synchandler when Xlib usurps */
} Display;
#endif
*_XPrivDisplay;

#if NeedFunctionPrototypes	/* prototypes require event type definitions */
#undef _XEVENT_
#endif
#ifndef _XEVENT_

#define XMaxTransChars 4

/*
 * Definitions of specific events.
 */
typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window it is reported relative to */
	Window root;	        /* root window that the event occurred on */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	unsigned int keycode;	/* detail */
	Bool same_screen;	/* same screen flag */
        char trans_chars[XMaxTransChars];
				/* translated characters */
	int nbytes;
} XKeyEvent;
typedef XKeyEvent XKeyPressedEvent;
typedef XKeyEvent XKeyReleasedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window it is reported relative to */
	Window root;	        /* root window that the event occurred on */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	unsigned int button;	/* detail */
	Bool same_screen;	/* same screen flag */
} XButtonEvent;
typedef XButtonEvent XButtonPressedEvent;
typedef XButtonEvent XButtonReleasedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window reported relative to */
	Window root;	        /* root window that the event occurred on */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	char is_hint;		/* detail */
	Bool same_screen;	/* same screen flag */
} XMotionEvent;
typedef XMotionEvent XPointerMovedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window reported relative to */
	Window root;	        /* root window that the event occurred on */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	int mode;		/* NotifyNormal, NotifyGrab, NotifyUngrab */
	int detail;
	/*
638
639
640
641
642
643
644
645

646
647
648
649
650
651
652
653
617
618
619
620
621
622
623

624

625
626
627
628
629
630
631







-
+
-








typedef struct {
	int type;		/* FocusIn or FocusOut */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;		/* window of event */
	int mode;		/* NotifyNormal, NotifyWhileGrabbed,
	int mode;		/* NotifyNormal, NotifyGrab, NotifyUngrab */
				   NotifyGrab, NotifyUngrab */
	int detail;
	/*
	 * NotifyAncestor, NotifyVirtual, NotifyInferior,
	 * NotifyNonlinear,NotifyNonlinearVirtual, NotifyPointer,
	 * NotifyPointerRoot, NotifyDetailNone
	 */
} XFocusChangeEvent;
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
918
919
920
921
922
923
924



























925
926
927
928
929
930
931







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;/* Display the event was read from */
	Window window;	/* window on which event was requested in event mask */
} XAnyEvent;


/***************************************************************
 *
 * GenericEvent.  This event is the standard event for all newer extensions.
 */

typedef struct
    {
    int            type;         /* of event. Always GenericEvent */
    unsigned long  serial;       /* # of last request processed */
    Bool           send_event;   /* true if from SendEvent request */
    Display        *display;     /* Display the event was read from */
    int            extension;    /* major opcode of extension that caused the event */
    int            evtype;       /* actual event type. */
    } XGenericEvent;

typedef struct {
    int            type;         /* of event. Always GenericEvent */
    unsigned long  serial;       /* # of last request processed */
    Bool           send_event;   /* true if from SendEvent request */
    Display        *display;     /* Display the event was read from */
    int            extension;    /* major opcode of extension that caused the event */
    int            evtype;       /* actual event type. */
    unsigned int   cookie;
    void           *data;
} XGenericEventCookie;

/*
 * this union is defined so Xlib can always use the same sized
 * event structure internally, to avoid memory fragmentation.
 */
typedef union _XEvent {
        int type;		/* must not be changed; first element */
	XAnyEvent xany;
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

1014
1015
1016
1017

1018
1019
1020
1021
1022
1023
1024
955
956
957
958
959
960
961



962
963
964
965

966
967
968
969
970
971
972
973







-
-
-
+



-
+







	XSelectionRequestEvent xselectionrequest;
	XSelectionEvent xselection;
	XColormapEvent xcolormap;
	XClientMessageEvent xclient;
	XMappingEvent xmapping;
	XErrorEvent xerror;
	XKeymapEvent xkeymap;
	XGenericEvent xgeneric;
	XGenericEventCookie xcookie;
	XID pad[24];
	long pad[24];
} XEvent;
#endif

#define XAllocID(dpy) ((*((_XPrivDisplay)(dpy))->resource_alloc)((dpy)))
#define XAllocID(dpy) ((*(dpy)->resource_alloc)((dpy)))

/*
 * per character font metric information.
 */
typedef struct {
    short	lbearing;	/* origin to left edge of raster */
    short	rbearing;	/* origin to right edge of raster */
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237

1238



1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257






1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296

1297
1298
1299
1300
1301
1302
1303
1304
1305

1306
1307

1308
1309

1310
1311
1312
1313
1314

1315
1316

1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1036
1037
1038
1039
1040
1041
1042





1043

1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

















1059






1060











1061
1062
1063


















1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087

1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109












1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126





1127
1128






1129
1130
1131
1132
1133
1134



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145

























1146









1147


1148


1149





1150


1151


1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162















1163
1164
1165
1166
1167
1168
1169







-
-
-
-
-
+
-















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


















-






-





-

















-
-
-
-
-
-
-
-
-
-
-
-






+

+
+
+






-
-
-
-
-


-
-
-
-
-
-
+
+
+
+
+
+
-
-
-











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
+
-
-
+
-
-











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		XFontStruct *font; } XEDataObject;

typedef struct {
    XRectangle      max_ink_extent;
    XRectangle      max_logical_extent;
} XFontSetExtents;

/* unused:
typedef void (*XOMProc)();
 */

typedef struct _XOM *XOM;
typedef struct _XFontSet *XFontSet;
typedef struct _XOC *XOC, *XFontSet;

typedef struct {
    char           *chars;
    int             nchars;
    int             delta;
    XFontSet        font_set;
} XmbTextItem;

typedef struct {
    wchar_t        *chars;
    int             nchars;
    int             delta;
    XFontSet        font_set;
} XwcTextItem;

#define XNRequiredCharSet "requiredCharSet"
#define XNQueryOrientation "queryOrientation"
#define XNBaseFontName "baseFontName"
#define XNOMAutomatic "omAutomatic"
#define XNMissingCharSet "missingCharSet"
#define XNDefaultString "defaultString"
#define XNOrientation "orientation"
#define XNDirectionalDependentDrawing "directionalDependentDrawing"
#define XNContextualDrawing "contextualDrawing"
#define XNFontInfo "fontInfo"

typedef struct {
    int charset_count;
    char **charset_list;
} XOMCharSetList;

typedef enum {
typedef void (*XIMProc)();
    XOMOrientation_LTR_TTB,
    XOMOrientation_RTL_TTB,
    XOMOrientation_TTB_LTR,
    XOMOrientation_TTB_RTL,
    XOMOrientation_Context
} XOrientation;

typedef struct {
    int num_orientation;
    XOrientation *orientation;	/* Input Text description */
} XOMOrientation;

typedef struct {
    int num_font;
    XFontStruct **font_struct_list;
    char **font_name_list;
} XOMFontInfo;

typedef struct _XIM *XIM;
typedef struct _XIC *XIC;

typedef void (*XIMProc)(
    XIM,
    XPointer,
    XPointer
);

typedef Bool (*XICProc)(
    XIC,
    XPointer,
    XPointer
);

typedef void (*XIDProc)(
    Display*,
    XPointer,
    XPointer
);

typedef unsigned long XIMStyle;

typedef struct {
    unsigned short count_styles;
    XIMStyle *supported_styles;
} XIMStyles;

#define XIMPreeditArea		0x0001L
#define XIMPreeditCallbacks	0x0002L
#define XIMPreeditPosition	0x0004L
#define XIMPreeditNothing	0x0008L
#define XIMPreeditNone		0x0010L
#define XIMStatusArea		0x0100L
#define XIMStatusCallbacks	0x0200L
#define XIMStatusNothing	0x0400L
#define XIMStatusNone		0x0800L

#define XNVaNestedList "XNVaNestedList"
#define XNQueryInputStyle "queryInputStyle"
#define XNClientWindow "clientWindow"
#define XNInputStyle "inputStyle"
#define XNFocusWindow "focusWindow"
#define XNResourceName "resourceName"
#define XNResourceClass "resourceClass"
#define XNGeometryCallback "geometryCallback"
#define XNDestroyCallback "destroyCallback"
#define XNFilterEvents "filterEvents"
#define XNPreeditStartCallback "preeditStartCallback"
#define XNPreeditDoneCallback "preeditDoneCallback"
#define XNPreeditDrawCallback "preeditDrawCallback"
#define XNPreeditCaretCallback "preeditCaretCallback"
#define XNPreeditStateNotifyCallback "preeditStateNotifyCallback"
#define XNPreeditAttributes "preeditAttributes"
#define XNStatusStartCallback "statusStartCallback"
#define XNStatusDoneCallback "statusDoneCallback"
#define XNStatusDrawCallback "statusDrawCallback"
#define XNStatusAttributes "statusAttributes"
#define XNArea "area"
#define XNAreaNeeded "areaNeeded"
#define XNSpotLocation "spotLocation"
#define XNColormap "colorMap"
#define XNStdColormap "stdColorMap"
#define XNForeground "foreground"
#define XNBackground "background"
#define XNBackgroundPixmap "backgroundPixmap"
#define XNFontSet "fontSet"
#define XNLineSpace "lineSpace"
#define XNCursor "cursor"

#define XNQueryIMValuesList "queryIMValuesList"
#define XNQueryICValuesList "queryICValuesList"
#define XNVisiblePosition "visiblePosition"
#define XNR6PreeditCallback "r6PreeditCallback"
#define XNStringConversionCallback "stringConversionCallback"
#define XNStringConversion "stringConversion"
#define XNResetState "resetState"
#define XNHotKey "hotKey"
#define XNHotKeyState "hotKeyState"
#define XNPreeditState "preeditState"
#define XNSeparatorofNestedList "separatorofNestedList"

#define XBufferOverflow		-1
#define XLookupNone		1
#define XLookupChars		2
#define XLookupKeySym		3
#define XLookupBoth		4

#if NeedFunctionPrototypes
typedef void *XVaNestedList;
#else
typedef XPointer XVaNestedList;
#endif

typedef struct {
    XPointer client_data;
    XIMProc callback;
} XIMCallback;

typedef struct {
    XPointer client_data;
    XICProc callback;
} XICCallback;

typedef unsigned long XIMFeedback;

#define XIMReverse		1L
#define XIMUnderline		(1L<<1)
#define XIMHighlight		(1L<<2)
#define XIMPrimary	 	(1L<<5)
#define XIMSecondary		(1L<<6)
#define XIMTertiary	 	(1L<<7)
#define XIMReverse	1
#define XIMUnderline	(1<<1)
#define XIMHighlight	(1<<2)
#define XIMPrimary 	(1<<5)
#define XIMSecondary	(1<<6)
#define XIMTertiary 	(1<<7)
#define XIMVisibleToForward 	(1L<<8)
#define XIMVisibleToBackword 	(1L<<9)
#define XIMVisibleToCenter 	(1L<<10)

typedef struct _XIMText {
    unsigned short length;
    XIMFeedback *feedback;
    Bool encoding_is_wchar;
    union {
	char *multi_byte;
	wchar_t *wide_char;
    } string;
} XIMText;

typedef	unsigned long	 XIMPreeditState;

#define	XIMPreeditUnKnown	0L
#define	XIMPreeditEnable	1L
#define	XIMPreeditDisable	(1L<<1)

typedef	struct	_XIMPreeditStateNotifyCallbackStruct {
    XIMPreeditState state;
} XIMPreeditStateNotifyCallbackStruct;

typedef	unsigned long	 XIMResetState;

#define	XIMInitialState		1L
#define	XIMPreserveState	(1L<<1)

typedef unsigned long XIMStringConversionFeedback;

#define	XIMStringConversionLeftEdge	(0x00000001)
#define	XIMStringConversionRightEdge	(0x00000002)
#define	XIMStringConversionTopEdge	(0x00000004)
#define	XIMStringConversionBottomEdge	(0x00000008)
#define	XIMStringConversionConcealed	(0x00000010)
#define	XIMStringConversionWrapped	(0x00000020)

typedef struct _XIMStringConversionText {
typedef struct _XIMPreeditDrawCallbackStruct {
    unsigned short length;
    XIMStringConversionFeedback *feedback;
    Bool encoding_is_wchar;
    union {
	char *mbs;
	wchar_t *wcs;
    } string;
} XIMStringConversionText;

    int caret;		/* Cursor offset within pre-edit string */
typedef	unsigned short	XIMStringConversionPosition;

    int chg_first;	/* Starting change position */
typedef	unsigned short	XIMStringConversionType;

    int chg_length;	/* Length of the change in character count */
#define	XIMStringConversionBuffer	(0x0001)
#define	XIMStringConversionLine		(0x0002)
#define	XIMStringConversionWord		(0x0003)
#define	XIMStringConversionChar		(0x0004)

    XIMText *text;
typedef	unsigned short	XIMStringConversionOperation;

} XIMPreeditDrawCallbackStruct;
#define	XIMStringConversionSubstitution	(0x0001)
#define	XIMStringConversionRetrieval	(0x0002)

typedef enum {
    XIMForwardChar, XIMBackwardChar,
    XIMForwardWord, XIMBackwardWord,
    XIMCaretUp, XIMCaretDown,
    XIMNextLine, XIMPreviousLine,
    XIMLineStart, XIMLineEnd,
    XIMAbsolutePosition,
    XIMDontChange
} XIMCaretDirection;

typedef struct _XIMStringConversionCallbackStruct {
    XIMStringConversionPosition position;
    XIMCaretDirection direction;
    XIMStringConversionOperation operation;
    unsigned short factor;
    XIMStringConversionText *text;
} XIMStringConversionCallbackStruct;

typedef struct _XIMPreeditDrawCallbackStruct {
    int caret;		/* Cursor offset within pre-edit string */
    int chg_first;	/* Starting change position */
    int chg_length;	/* Length of the change in character count */
    XIMText *text;
} XIMPreeditDrawCallbackStruct;

typedef enum {
    XIMIsInvisible,	/* Disable caret feedback */
    XIMIsPrimary,	/* UI defined caret feedback */
    XIMIsSecondary	/* UI defined caret feedback */
} XIMCaretStyle;

typedef struct _XIMPreeditCaretCallbackStruct {
1363
1364
1365
1366
1367
1368
1369
1370

1371
1372

1373
1374
1375

1376
1377
1378
1379
1380

1381
1382

1383
1384
1385

1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030





4031
4032
4033
4034
4035

1181
1182
1183
1184
1185
1186
1187

1188


1189



1190





1191


1192



1193




1194
1195
1196























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1197

















































































































































































































































































































































































































































































































































































































































































1198
1199
1200


1201
1202
1203
1204
1205
1206
1207



1208







-
+
-
-
+
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
+
+
+
+
+


-
-
-
+
    XIMStatusDataType type;
    union {
	XIMText *text;
	Pixmap  bitmap;
    } data;
} XIMStatusDrawCallbackStruct;

typedef struct _XIMHotKeyTrigger {
typedef int (*XErrorHandler) (	    /* WARNING, this type not in Xlib spec */
    KeySym	 keysym;
    int		 modifier;
#if NeedFunctionPrototypes
    int		 modifier_mask;
} XIMHotKeyTrigger;

    Display*		/* display */,
typedef struct _XIMHotKeyTriggers {
    int			 num_hot_key;
    XIMHotKeyTrigger	*key;
} XIMHotKeyTriggers;

    XErrorEvent*	/* error_event */
typedef	unsigned long	 XIMHotKeyState;

#endif
#define	XIMHotKeyStateON	(0x0001L)
#define	XIMHotKeyStateOFF	(0x0002L)

);
typedef struct {
    unsigned short count_values;
    char **supported_values;
} XIMValuesList;

_XFUNCPROTOBEGIN

#if defined(WIN32) && !defined(_XLIBINT_)
#define _Xdebug *_Xdebug_p
#endif

EXTERN int _Xdebug;

EXTERN XFontStruct *XLoadQueryFont(
    Display*		/* display */,
    _Xconst char*	/* name */
);

EXTERN XFontStruct *XQueryFont(
    Display*		/* display */,
    XID			/* font_ID */
);


EXTERN XTimeCoord *XGetMotionEvents(
    Display*		/* display */,
    Window		/* w */,
    Time		/* start */,
    Time		/* stop */,
    int*		/* nevents_return */
);

EXTERN XModifierKeymap *XDeleteModifiermapEntry(
    XModifierKeymap*	/* modmap */,
#if NeedWidePrototypes
    unsigned int	/* keycode_entry */,
#else
    KeyCode		/* keycode_entry */,
#endif
    int			/* modifier */
);

EXTERN XModifierKeymap	*XGetModifierMapping(
    Display*		/* display */
);

EXTERN XModifierKeymap	*XInsertModifiermapEntry(
    XModifierKeymap*	/* modmap */,
#if NeedWidePrototypes
    unsigned int	/* keycode_entry */,
#else
    KeyCode		/* keycode_entry */,
#endif
    int			/* modifier */
);

EXTERN XModifierKeymap *XNewModifiermap(
    int			/* max_keys_per_mod */
);

EXTERN XImage *XCreateImage(
    Display*		/* display */,
    Visual*		/* visual */,
    unsigned int	/* depth */,
    int			/* format */,
    int			/* offset */,
    char*		/* data */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* bitmap_pad */,
    int			/* bytes_per_line */
);
EXTERN Status XInitImage(
    XImage*		/* image */
);
EXTERN XImage *XGetImage(
    Display*		/* display */,
    Drawable		/* d */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned long	/* plane_mask */,
    int			/* format */
);
EXTERN XImage *XGetSubImage(
    Display*		/* display */,
    Drawable		/* d */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned long	/* plane_mask */,
    int			/* format */,
    XImage*		/* dest_image */,
    int			/* dest_x */,
    int			/* dest_y */
);

/*
 * X function declarations.
 */
EXTERN Display *XOpenDisplay(
    _Xconst char*	/* display_name */
);

EXTERN void XrmInitialize(
    void
);

EXTERN char *XFetchBytes(
    Display*		/* display */,
    int*		/* nbytes_return */
);
EXTERN char *XFetchBuffer(
    Display*		/* display */,
    int*		/* nbytes_return */,
    int			/* buffer */
);
EXTERN char *XGetAtomName(
    Display*		/* display */,
    Atom		/* atom */
);
EXTERN Status XGetAtomNames(
    Display*		/* dpy */,
    Atom*		/* atoms */,
    int			/* count */,
    char**		/* names_return */
);
EXTERN char *XGetDefault(
    Display*		/* display */,
    _Xconst char*	/* program */,
    _Xconst char*	/* option */
);
EXTERN char *XDisplayName(
    _Xconst char*	/* string */
);
EXTERN char *XKeysymToString(
    KeySym		/* keysym */
);

EXTERN int (*XSynchronize(
    Display*		/* display */,
    Bool		/* onoff */
))(
    Display*		/* display */
);
EXTERN int (*XSetAfterFunction(
    Display*		/* display */,
    int (*) (
	     Display*	/* display */
            )		/* procedure */
))(
    Display*		/* display */
);
EXTERN Atom XInternAtom(
    Display*		/* display */,
    _Xconst char*	/* atom_name */,
    Bool		/* only_if_exists */
);
EXTERN Status XInternAtoms(
    Display*		/* dpy */,
    char**		/* names */,
    int			/* count */,
    Bool		/* onlyIfExists */,
    Atom*		/* atoms_return */
);
EXTERN Colormap XCopyColormapAndFree(
    Display*		/* display */,
    Colormap		/* colormap */
);
EXTERN Colormap XCreateColormap(
    Display*		/* display */,
    Window		/* w */,
    Visual*		/* visual */,
    int			/* alloc */
);
EXTERN Cursor XCreatePixmapCursor(
    Display*		/* display */,
    Pixmap		/* source */,
    Pixmap		/* mask */,
    XColor*		/* foreground_color */,
    XColor*		/* background_color */,
    unsigned int	/* x */,
    unsigned int	/* y */
);
EXTERN Cursor XCreateGlyphCursor(
    Display*		/* display */,
    Font		/* source_font */,
    Font		/* mask_font */,
    unsigned int	/* source_char */,
    unsigned int	/* mask_char */,
    XColor _Xconst *	/* foreground_color */,
    XColor _Xconst *	/* background_color */
);
EXTERN Cursor XCreateFontCursor(
    Display*		/* display */,
    unsigned int	/* shape */
);
EXTERN Font XLoadFont(
    Display*		/* display */,
    _Xconst char*	/* name */
);
EXTERN GC XCreateGC(
    Display*		/* display */,
    Drawable		/* d */,
    unsigned long	/* valuemask */,
    XGCValues*		/* values */
);
EXTERN GContext XGContextFromGC(
    GC			/* gc */
);
EXTERN void XFlushGC(
    Display*		/* display */,
    GC			/* gc */
);
EXTERN Pixmap XCreatePixmap(
    Display*		/* display */,
    Drawable		/* d */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int	/* depth */
);
EXTERN Pixmap XCreateBitmapFromData(
    Display*		/* display */,
    Drawable		/* d */,
    _Xconst char*	/* data */,
    unsigned int	/* width */,
    unsigned int	/* height */
);
EXTERN Pixmap XCreatePixmapFromBitmapData(
    Display*		/* display */,
    Drawable		/* d */,
    char*		/* data */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned long	/* fg */,
    unsigned long	/* bg */,
    unsigned int	/* depth */
);
EXTERN Window XCreateSimpleWindow(
    Display*		/* display */,
    Window		/* parent */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int	/* border_width */,
    unsigned long	/* border */,
    unsigned long	/* background */
);
EXTERN Window XGetSelectionOwner(
    Display*		/* display */,
    Atom		/* selection */
);
EXTERN Window XCreateWindow(
    Display*		/* display */,
    Window		/* parent */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int	/* border_width */,
    int			/* depth */,
    unsigned int	/* class */,
    Visual*		/* visual */,
    unsigned long	/* valuemask */,
    XSetWindowAttributes*	/* attributes */
);
EXTERN Colormap *XListInstalledColormaps(
    Display*		/* display */,
    Window		/* w */,
    int*		/* num_return */
);
EXTERN char **XListFonts(
    Display*		/* display */,
    _Xconst char*	/* pattern */,
    int			/* maxnames */,
    int*		/* actual_count_return */
);
EXTERN char **XListFontsWithInfo(
    Display*		/* display */,
    _Xconst char*	/* pattern */,
    int			/* maxnames */,
    int*		/* count_return */,
    XFontStruct**	/* info_return */
);
EXTERN char **XGetFontPath(
    Display*		/* display */,
    int*		/* npaths_return */
);
EXTERN char **XListExtensions(
    Display*		/* display */,
    int*		/* nextensions_return */
);
EXTERN Atom *XListProperties(
    Display*		/* display */,
    Window		/* w */,
    int*		/* num_prop_return */
);
EXTERN XHostAddress *XListHosts(
    Display*		/* display */,
    int*		/* nhosts_return */,
    Bool*		/* state_return */
);
EXTERN _X_DEPRECATED KeySym XKeycodeToKeysym(
    Display*		/* display */,
#if NeedWidePrototypes
    unsigned int	/* keycode */,
#else
    KeyCode		/* keycode */,
#endif
    int			/* index */
);
EXTERN KeySym XLookupKeysym(
    XKeyEvent*		/* key_event */,
    int			/* index */
);
EXTERN KeySym *XGetKeyboardMapping(
    Display*		/* display */,
#if NeedWidePrototypes
    unsigned int	/* first_keycode */,
#else
    KeyCode		/* first_keycode */,
#endif
    int			/* keycode_count */,
    int*		/* keysyms_per_keycode_return */
);
EXTERN KeySym XStringToKeysym(
    _Xconst char*	/* string */
);
EXTERN long XMaxRequestSize(
    Display*		/* display */
);
EXTERN long XExtendedMaxRequestSize(
    Display*		/* display */
);
EXTERN char *XResourceManagerString(
    Display*		/* display */
);
EXTERN char *XScreenResourceString(
	Screen*		/* screen */
);
EXTERN unsigned long XDisplayMotionBufferSize(
    Display*		/* display */
);
EXTERN VisualID XVisualIDFromVisual(
    Visual*		/* visual */
);

/* multithread routines */

EXTERN Status XInitThreads(
    void
);

EXTERN Status XFreeThreads(
    void
);

EXTERN void XLockDisplay(
    Display*		/* display */
);

EXTERN void XUnlockDisplay(
    Display*		/* display */
);

/* routines for dealing with extensions */

EXTERN XExtCodes *XInitExtension(
    Display*		/* display */,
    _Xconst char*	/* name */
);

EXTERN XExtCodes *XAddExtension(
    Display*		/* display */
);
EXTERN XExtData *XFindOnExtensionList(
    XExtData**		/* structure */,
    int			/* number */
);
EXTERN XExtData **XEHeadOfExtensionList(
    XEDataObject	/* object */
);

/* these are routines for which there are also macros */
EXTERN Window XRootWindow(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN Window XDefaultRootWindow(
    Display*		/* display */
);
EXTERN Window XRootWindowOfScreen(
    Screen*		/* screen */
);
EXTERN Visual *XDefaultVisual(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN Visual *XDefaultVisualOfScreen(
    Screen*		/* screen */
);
EXTERN GC XDefaultGC(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN GC XDefaultGCOfScreen(
    Screen*		/* screen */
);
EXTERN unsigned long XBlackPixel(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN unsigned long XWhitePixel(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN unsigned long XAllPlanes(
    void
);
EXTERN unsigned long XBlackPixelOfScreen(
    Screen*		/* screen */
);
EXTERN unsigned long XWhitePixelOfScreen(
    Screen*		/* screen */
);
EXTERN unsigned long XNextRequest(
    Display*		/* display */
);
EXTERN unsigned long XLastKnownRequestProcessed(
    Display*		/* display */
);
EXTERN char *XServerVendor(
    Display*		/* display */
);
EXTERN char *XDisplayString(
    Display*		/* display */
);
EXTERN Colormap XDefaultColormap(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN Colormap XDefaultColormapOfScreen(
    Screen*		/* screen */
);
EXTERN Display *XDisplayOfScreen(
    Screen*		/* screen */
);
EXTERN Screen *XScreenOfDisplay(
    Display*		/* display */,
    int			/* screen_number */
);
EXTERN Screen *XDefaultScreenOfDisplay(
    Display*		/* display */
);
EXTERN long XEventMaskOfScreen(
    Screen*		/* screen */
);

EXTERN int XScreenNumberOfScreen(
    Screen*		/* screen */
);

typedef int (*XErrorHandler) (	    /* WARNING, this type not in Xlib spec */
    Display*		/* display */,
    XErrorEvent*	/* error_event */
);

EXTERN XErrorHandler XSetErrorHandler (
    XErrorHandler	/* handler */
);


typedef int (*XIOErrorHandler) (    /* WARNING, this type not in Xlib spec */
    Display*		/* display */
);

EXTERN XIOErrorHandler XSetIOErrorHandler (
    XIOErrorHandler	/* handler */
);

typedef void (*XIOErrorExitHandler) ( /* WARNING, this type not in Xlib spec */
    Display*,		/* display */
    void*		/* user_data */
);

EXTERN void XSetIOErrorExitHandler (
    Display*,			/* display */
    XIOErrorExitHandler,	/* handler */
    void*			/* user_data */
);

EXTERN XPixmapFormatValues *XListPixmapFormats(
    Display*		/* display */,
    int*		/* count_return */
);
EXTERN int *XListDepths(
    Display*		/* display */,
    int			/* screen_number */,
    int*		/* count_return */
);

/* ICCCM routines for things that don't require special include files; */
/* other declarations are given in Xutil.h                             */
EXTERN Status XReconfigureWMWindow(
    Display*		/* display */,
    Window		/* w */,
    int			/* screen_number */,
    unsigned int	/* mask */,
    XWindowChanges*	/* changes */
);

EXTERN Status XGetWMProtocols(
    Display*		/* display */,
    Window		/* w */,
    Atom**		/* protocols_return */,
    int*		/* count_return */
);
EXTERN Status XSetWMProtocols(
    Display*		/* display */,
    Window		/* w */,
    Atom*		/* protocols */,
    int			/* count */
);
EXTERN Status XIconifyWindow(
    Display*		/* display */,
    Window		/* w */,
    int			/* screen_number */
);
EXTERN Status XWithdrawWindow(
    Display*		/* display */,
    Window		/* w */,
    int			/* screen_number */
);
EXTERN Status XGetCommand(
    Display*		/* display */,
    Window		/* w */,
    char***		/* argv_return */,
    int*		/* argc_return */
);
EXTERN Status XGetWMColormapWindows(
    Display*		/* display */,
    Window		/* w */,
    Window**		/* windows_return */,
    int*		/* count_return */
);
EXTERN Status XSetWMColormapWindows(
    Display*		/* display */,
    Window		/* w */,
    Window*		/* colormap_windows */,
    int			/* count */
);
EXTERN void XFreeStringList(
    char**		/* list */
);
EXTERN int XSetTransientForHint(
    Display*		/* display */,
    Window		/* w */,
    Window		/* prop_window */
);

/* The following are given in alphabetical order */

EXTERN int XActivateScreenSaver(
    Display*		/* display */
);

EXTERN int XAddHost(
    Display*		/* display */,
    XHostAddress*	/* host */
);

EXTERN int XAddHosts(
    Display*		/* display */,
    XHostAddress*	/* hosts */,
    int			/* num_hosts */
);

EXTERN int XAddToExtensionList(
    struct _XExtData**	/* structure */,
    XExtData*		/* ext_data */
);

EXTERN int XAddToSaveSet(
    Display*		/* display */,
    Window		/* w */
);

EXTERN Status XAllocColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    XColor*		/* screen_in_out */
);

EXTERN Status XAllocColorCells(
    Display*		/* display */,
    Colormap		/* colormap */,
    Bool	        /* contig */,
    unsigned long*	/* plane_masks_return */,
    unsigned int	/* nplanes */,
    unsigned long*	/* pixels_return */,
    unsigned int 	/* npixels */
);

EXTERN Status XAllocColorPlanes(
    Display*		/* display */,
    Colormap		/* colormap */,
    Bool		/* contig */,
    unsigned long*	/* pixels_return */,
    int			/* ncolors */,
    int			/* nreds */,
    int			/* ngreens */,
    int			/* nblues */,
    unsigned long*	/* rmask_return */,
    unsigned long*	/* gmask_return */,
    unsigned long*	/* bmask_return */
);

EXTERN Status XAllocNamedColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    _Xconst char*	/* color_name */,
    XColor*		/* screen_def_return */,
    XColor*		/* exact_def_return */
);

EXTERN int XAllowEvents(
    Display*		/* display */,
    int			/* event_mode */,
    Time		/* time */
);

EXTERN int XAutoRepeatOff(
    Display*		/* display */
);

EXTERN int XAutoRepeatOn(
    Display*		/* display */
);

EXTERN int XBell(
    Display*		/* display */,
    int			/* percent */
);

EXTERN int XBitmapBitOrder(
    Display*		/* display */
);

EXTERN int XBitmapPad(
    Display*		/* display */
);

EXTERN int XBitmapUnit(
    Display*		/* display */
);

EXTERN int XCellsOfScreen(
    Screen*		/* screen */
);

EXTERN int XChangeActivePointerGrab(
    Display*		/* display */,
    unsigned int	/* event_mask */,
    Cursor		/* cursor */,
    Time		/* time */
);

EXTERN int XChangeGC(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long	/* valuemask */,
    XGCValues*		/* values */
);

EXTERN int XChangeKeyboardControl(
    Display*		/* display */,
    unsigned long	/* value_mask */,
    XKeyboardControl*	/* values */
);

EXTERN int XChangeKeyboardMapping(
    Display*		/* display */,
    int			/* first_keycode */,
    int			/* keysyms_per_keycode */,
    KeySym*		/* keysyms */,
    int			/* num_codes */
);

EXTERN int XChangePointerControl(
    Display*		/* display */,
    Bool		/* do_accel */,
    Bool		/* do_threshold */,
    int			/* accel_numerator */,
    int			/* accel_denominator */,
    int			/* threshold */
);

EXTERN int XChangeProperty(
    Display*		/* display */,
    Window		/* w */,
    Atom		/* property */,
    Atom		/* type */,
    int			/* format */,
    int			/* mode */,
    _Xconst unsigned char*	/* data */,
    int			/* nelements */
);

EXTERN int XChangeSaveSet(
    Display*		/* display */,
    Window		/* w */,
    int			/* change_mode */
);

EXTERN int XChangeWindowAttributes(
    Display*		/* display */,
    Window		/* w */,
    unsigned long	/* valuemask */,
    XSetWindowAttributes* /* attributes */
);

EXTERN Bool XCheckIfEvent(
    Display*		/* display */,
    XEvent*		/* event_return */,
    Bool (*) (
	       Display*			/* display */,
               XEvent*			/* event */,
               XPointer			/* arg */
             )		/* predicate */,
    XPointer		/* arg */
);

EXTERN Bool XCheckMaskEvent(
    Display*		/* display */,
    long		/* event_mask */,
    XEvent*		/* event_return */
);

EXTERN Bool XCheckTypedEvent(
    Display*		/* display */,
    int			/* event_type */,
    XEvent*		/* event_return */
);

EXTERN Bool XCheckTypedWindowEvent(
    Display*		/* display */,
    Window		/* w */,
    int			/* event_type */,
    XEvent*		/* event_return */
);

EXTERN Bool XCheckWindowEvent(
    Display*		/* display */,
    Window		/* w */,
    long		/* event_mask */,
    XEvent*		/* event_return */
);

EXTERN int XCirculateSubwindows(
    Display*		/* display */,
    Window		/* w */,
    int			/* direction */
);

EXTERN int XCirculateSubwindowsDown(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XCirculateSubwindowsUp(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XClearArea(
    Display*		/* display */,
    Window		/* w */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    Bool		/* exposures */
);

EXTERN int XClearWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XCloseDisplay(
    Display*		/* display */
);

EXTERN int XConfigureWindow(
    Display*		/* display */,
    Window		/* w */,
    unsigned int	/* value_mask */,
    XWindowChanges*	/* values */
);

EXTERN int XConnectionNumber(
    Display*		/* display */
);

EXTERN int XConvertSelection(
    Display*		/* display */,
    Atom		/* selection */,
    Atom 		/* target */,
    Atom		/* property */,
    Window		/* requestor */,
    Time		/* time */
);

EXTERN int XCopyArea(
    Display*		/* display */,
    Drawable		/* src */,
    Drawable		/* dest */,
    GC			/* gc */,
    int			/* src_x */,
    int			/* src_y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* dest_x */,
    int			/* dest_y */
);

EXTERN int XCopyGC(
    Display*		/* display */,
    GC			/* src */,
    unsigned long	/* valuemask */,
    GC			/* dest */
);

EXTERN int XCopyPlane(
    Display*		/* display */,
    Drawable		/* src */,
    Drawable		/* dest */,
    GC			/* gc */,
    int			/* src_x */,
    int			/* src_y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* dest_x */,
    int			/* dest_y */,
    unsigned long	/* plane */
);

EXTERN int XDefaultDepth(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDefaultDepthOfScreen(
    Screen*		/* screen */
);

EXTERN int XDefaultScreen(
    Display*		/* display */
);

EXTERN int XDefineCursor(
    Display*		/* display */,
    Window		/* w */,
    Cursor		/* cursor */
);

EXTERN int XDeleteProperty(
    Display*		/* display */,
    Window		/* w */,
    Atom		/* property */
);

EXTERN int XDestroyWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XDestroySubwindows(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XDoesBackingStore(
    Screen*		/* screen */
);

EXTERN Bool XDoesSaveUnders(
    Screen*		/* screen */
);

EXTERN int XDisableAccessControl(
    Display*		/* display */
);


EXTERN int XDisplayCells(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDisplayHeight(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDisplayHeightMM(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDisplayKeycodes(
    Display*		/* display */,
    int*		/* min_keycodes_return */,
    int*		/* max_keycodes_return */
);

EXTERN int XDisplayPlanes(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDisplayWidth(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDisplayWidthMM(
    Display*		/* display */,
    int			/* screen_number */
);

EXTERN int XDrawArc(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* angle1 */,
    int			/* angle2 */
);

EXTERN int XDrawArcs(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XArc*		/* arcs */,
    int			/* narcs */
);

EXTERN int XDrawImageString(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* string */,
    int			/* length */
);

EXTERN int XDrawImageString16(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst XChar2b*	/* string */,
    int			/* length */
);

EXTERN int XDrawLine(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x1 */,
    int			/* y1 */,
    int			/* x2 */,
    int			/* y2 */
);

EXTERN int XDrawLines(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XPoint*		/* points */,
    int			/* npoints */,
    int			/* mode */
);

EXTERN int XDrawPoint(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */
);

EXTERN int XDrawPoints(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XPoint*		/* points */,
    int			/* npoints */,
    int			/* mode */
);

EXTERN int XDrawRectangle(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */
);

EXTERN int XDrawRectangles(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XRectangle*		/* rectangles */,
    int			/* nrectangles */
);

EXTERN int XDrawSegments(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XSegment*		/* segments */,
    int			/* nsegments */
);

EXTERN int XDrawString(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* string */,
    int			/* length */
);

EXTERN int XDrawString16(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst XChar2b*	/* string */,
    int			/* length */
);

EXTERN int XDrawText(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    XTextItem*		/* items */,
    int			/* nitems */
);

EXTERN int XDrawText16(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    XTextItem16*	/* items */,
    int			/* nitems */
);

EXTERN int XEnableAccessControl(
    Display*		/* display */
);

EXTERN int XEventsQueued(
    Display*		/* display */,
    int			/* mode */
);

EXTERN Status XFetchName(
    Display*		/* display */,
    Window		/* w */,
    char**		/* window_name_return */
);

EXTERN int XFillArc(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* angle1 */,
    int			/* angle2 */
);

EXTERN int XFillArcs(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XArc*		/* arcs */,
    int			/* narcs */
);

EXTERN int XFillPolygon(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XPoint*		/* points */,
    int			/* npoints */,
    int			/* shape */,
    int			/* mode */
);

EXTERN int XFillRectangle(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */
);

EXTERN int XFillRectangles(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XRectangle*		/* rectangles */,
    int			/* nrectangles */
);

EXTERN int XFlush(
    Display*		/* display */
);

EXTERN int XForceScreenSaver(
    Display*		/* display */,
    int			/* mode */
);

EXTERN int XFree(
    void*		/* data */
);

EXTERN int XFreeColormap(
    Display*		/* display */,
    Colormap		/* colormap */
);

EXTERN int XFreeColors(
    Display*		/* display */,
    Colormap		/* colormap */,
    unsigned long*	/* pixels */,
    int			/* npixels */,
    unsigned long	/* planes */
);

EXTERN int XFreeCursor(
    Display*		/* display */,
    Cursor		/* cursor */
);

EXTERN int XFreeExtensionList(
    char**		/* list */
);

EXTERN int XFreeFont(
    Display*		/* display */,
    XFontStruct*	/* font_struct */
);

EXTERN int XFreeFontInfo(
    char**		/* names */,
    XFontStruct*	/* free_info */,
    int			/* actual_count */
);

EXTERN int XFreeFontNames(
    char**		/* list */
);

EXTERN int XFreeFontPath(
    char**		/* list */
);

EXTERN int XFreeGC(
    Display*		/* display */,
    GC			/* gc */
);

EXTERN int XFreeModifiermap(
    XModifierKeymap*	/* modmap */
);

EXTERN int XFreePixmap(
    Display*		/* display */,
    Pixmap		/* pixmap */
);

EXTERN int XGeometry(
    Display*		/* display */,
    int			/* screen */,
    _Xconst char*	/* position */,
    _Xconst char*	/* default_position */,
    unsigned int	/* bwidth */,
    unsigned int	/* fwidth */,
    unsigned int	/* fheight */,
    int			/* xadder */,
    int			/* yadder */,
    int*		/* x_return */,
    int*		/* y_return */,
    int*		/* width_return */,
    int*		/* height_return */
);

EXTERN int XGetErrorDatabaseText(
    Display*		/* display */,
    _Xconst char*	/* name */,
    _Xconst char*	/* message */,
    _Xconst char*	/* default_string */,
    char*		/* buffer_return */,
    int			/* length */
);

EXTERN int XGetErrorText(
    Display*		/* display */,
    int			/* code */,
    char*		/* buffer_return */,
    int			/* length */
);

EXTERN Bool XGetFontProperty(
    XFontStruct*	/* font_struct */,
    Atom		/* atom */,
    unsigned long*	/* value_return */
);

EXTERN Status XGetGCValues(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long	/* valuemask */,
    XGCValues*		/* values_return */
);

EXTERN Status XGetGeometry(
    Display*		/* display */,
    Drawable		/* d */,
    Window*		/* root_return */,
    int*		/* x_return */,
    int*		/* y_return */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */,
    unsigned int*	/* border_width_return */,
    unsigned int*	/* depth_return */
);

EXTERN Status XGetIconName(
    Display*		/* display */,
    Window		/* w */,
    char**		/* icon_name_return */
);

EXTERN int XGetInputFocus(
    Display*		/* display */,
    Window*		/* focus_return */,
    int*		/* revert_to_return */
);

EXTERN int XGetKeyboardControl(
    Display*		/* display */,
    XKeyboardState*	/* values_return */
);

EXTERN int XGetPointerControl(
    Display*		/* display */,
    int*		/* accel_numerator_return */,
    int*		/* accel_denominator_return */,
    int*		/* threshold_return */
);

EXTERN int XGetPointerMapping(
    Display*		/* display */,
    unsigned char*	/* map_return */,
    int			/* nmap */
);

EXTERN int XGetScreenSaver(
    Display*		/* display */,
    int*		/* timeout_return */,
    int*		/* interval_return */,
    int*		/* prefer_blanking_return */,
    int*		/* allow_exposures_return */
);

EXTERN Status XGetTransientForHint(
    Display*		/* display */,
    Window		/* w */,
    Window*		/* prop_window_return */
);

EXTERN int XGetWindowProperty(
    Display*		/* display */,
    Window		/* w */,
    Atom		/* property */,
    long		/* long_offset */,
    long		/* long_length */,
    Bool		/* delete */,
    Atom		/* req_type */,
    Atom*		/* actual_type_return */,
    int*		/* actual_format_return */,
    unsigned long*	/* nitems_return */,
    unsigned long*	/* bytes_after_return */,
    unsigned char**	/* prop_return */
);

EXTERN Status XGetWindowAttributes(
    Display*		/* display */,
    Window		/* w */,
    XWindowAttributes*	/* window_attributes_return */
);

EXTERN int XGrabButton(
    Display*		/* display */,
    unsigned int	/* button */,
    unsigned int	/* modifiers */,
    Window		/* grab_window */,
    Bool		/* owner_events */,
    unsigned int	/* event_mask */,
    int			/* pointer_mode */,
    int			/* keyboard_mode */,
    Window		/* confine_to */,
    Cursor		/* cursor */
);

EXTERN int XGrabKey(
    Display*		/* display */,
    int			/* keycode */,
    unsigned int	/* modifiers */,
    Window		/* grab_window */,
    Bool		/* owner_events */,
    int			/* pointer_mode */,
    int			/* keyboard_mode */
);

EXTERN int XGrabKeyboard(
    Display*		/* display */,
    Window		/* grab_window */,
    Bool		/* owner_events */,
    int			/* pointer_mode */,
    int			/* keyboard_mode */,
    Time		/* time */
);

EXTERN int XGrabPointer(
    Display*		/* display */,
    Window		/* grab_window */,
    Bool		/* owner_events */,
    unsigned int	/* event_mask */,
    int			/* pointer_mode */,
    int			/* keyboard_mode */,
    Window		/* confine_to */,
    Cursor		/* cursor */,
    Time		/* time */
);

EXTERN int XGrabServer(
    Display*		/* display */
);

EXTERN int XHeightMMOfScreen(
    Screen*		/* screen */
);

EXTERN int XHeightOfScreen(
    Screen*		/* screen */
);

EXTERN int XIfEvent(
    Display*		/* display */,
    XEvent*		/* event_return */,
    Bool (*) (
	       Display*			/* display */,
               XEvent*			/* event */,
               XPointer			/* arg */
             )		/* predicate */,
    XPointer		/* arg */
);

EXTERN int XImageByteOrder(
    Display*		/* display */
);

EXTERN int XInstallColormap(
    Display*		/* display */,
    Colormap		/* colormap */
);

EXTERN KeyCode XKeysymToKeycode(
    Display*		/* display */,
    KeySym		/* keysym */
);

EXTERN int XKillClient(
    Display*		/* display */,
    XID			/* resource */
);

EXTERN Status XLookupColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    _Xconst char*	/* color_name */,
    XColor*		/* exact_def_return */,
    XColor*		/* screen_def_return */
);

EXTERN int XLowerWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XMapRaised(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XMapSubwindows(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XMapWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XMaskEvent(
    Display*		/* display */,
    long		/* event_mask */,
    XEvent*		/* event_return */
);

EXTERN int XMaxCmapsOfScreen(
    Screen*		/* screen */
);

EXTERN int XMinCmapsOfScreen(
    Screen*		/* screen */
);

EXTERN int XMoveResizeWindow(
    Display*		/* display */,
    Window		/* w */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */
);

EXTERN int XMoveWindow(
    Display*		/* display */,
    Window		/* w */,
    int			/* x */,
    int			/* y */
);

EXTERN int XNextEvent(
    Display*		/* display */,
    XEvent*		/* event_return */
);

EXTERN int XNoOp(
    Display*		/* display */
);

EXTERN Status XParseColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    _Xconst char*	/* spec */,
    XColor*		/* exact_def_return */
);

EXTERN int XParseGeometry(
    _Xconst char*	/* parsestring */,
    int*		/* x_return */,
    int*		/* y_return */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */
);

EXTERN int XPeekEvent(
    Display*		/* display */,
    XEvent*		/* event_return */
);

EXTERN int XPeekIfEvent(
    Display*		/* display */,
    XEvent*		/* event_return */,
    Bool (*) (
	       Display*		/* display */,
               XEvent*		/* event */,
               XPointer		/* arg */
             )		/* predicate */,
    XPointer		/* arg */
);

EXTERN int XPending(
    Display*		/* display */
);

EXTERN int XPlanesOfScreen(
    Screen*		/* screen */
);

EXTERN int XProtocolRevision(
    Display*		/* display */
);

EXTERN int XProtocolVersion(
    Display*		/* display */
);


EXTERN int XPutBackEvent(
    Display*		/* display */,
    XEvent*		/* event */
);

EXTERN int XPutImage(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    XImage*		/* image */,
    int			/* src_x */,
    int			/* src_y */,
    int			/* dest_x */,
    int			/* dest_y */,
    unsigned int	/* width */,
    unsigned int	/* height */
);

EXTERN int XQLength(
    Display*		/* display */
);

EXTERN Status XQueryBestCursor(
    Display*		/* display */,
    Drawable		/* d */,
    unsigned int        /* width */,
    unsigned int	/* height */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */
);

EXTERN Status XQueryBestSize(
    Display*		/* display */,
    int			/* class */,
    Drawable		/* which_screen */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */
);

EXTERN Status XQueryBestStipple(
    Display*		/* display */,
    Drawable		/* which_screen */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */
);

EXTERN Status XQueryBestTile(
    Display*		/* display */,
    Drawable		/* which_screen */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */
);

EXTERN int XQueryColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    XColor*		/* def_in_out */
);

EXTERN int XQueryColors(
    Display*		/* display */,
    Colormap		/* colormap */,
    XColor*		/* defs_in_out */,
    int			/* ncolors */
);

EXTERN Bool XQueryExtension(
    Display*		/* display */,
    _Xconst char*	/* name */,
    int*		/* major_opcode_return */,
    int*		/* first_event_return */,
    int*		/* first_error_return */
);

EXTERN int XQueryKeymap(
    Display*		/* display */,
    char [32]		/* keys_return */
);

EXTERN Bool XQueryPointer(
    Display*		/* display */,
    Window		/* w */,
    Window*		/* root_return */,
    Window*		/* child_return */,
    int*		/* root_x_return */,
    int*		/* root_y_return */,
    int*		/* win_x_return */,
    int*		/* win_y_return */,
    unsigned int*       /* mask_return */
);

EXTERN int XQueryTextExtents(
    Display*		/* display */,
    XID			/* font_ID */,
    _Xconst char*	/* string */,
    int			/* nchars */,
    int*		/* direction_return */,
    int*		/* font_ascent_return */,
    int*		/* font_descent_return */,
    XCharStruct*	/* overall_return */
);

EXTERN int XQueryTextExtents16(
    Display*		/* display */,
    XID			/* font_ID */,
    _Xconst XChar2b*	/* string */,
    int			/* nchars */,
    int*		/* direction_return */,
    int*		/* font_ascent_return */,
    int*		/* font_descent_return */,
    XCharStruct*	/* overall_return */
);

EXTERN Status XQueryTree(
    Display*		/* display */,
    Window		/* w */,
    Window*		/* root_return */,
    Window*		/* parent_return */,
    Window**		/* children_return */,
    unsigned int*	/* nchildren_return */
);

EXTERN int XRaiseWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XReadBitmapFile(
    Display*		/* display */,
    Drawable 		/* d */,
    _Xconst char*	/* filename */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */,
    Pixmap*		/* bitmap_return */,
    int*		/* x_hot_return */,
    int*		/* y_hot_return */
);

EXTERN int XReadBitmapFileData(
    _Xconst char*	/* filename */,
    unsigned int*	/* width_return */,
    unsigned int*	/* height_return */,
    unsigned char**	/* data_return */,
    int*		/* x_hot_return */,
    int*		/* y_hot_return */
);

EXTERN int XRebindKeysym(
    Display*		/* display */,
    KeySym		/* keysym */,
    KeySym*		/* list */,
    int			/* mod_count */,
    _Xconst unsigned char*	/* string */,
    int			/* bytes_string */
);

EXTERN int XRecolorCursor(
    Display*		/* display */,
    Cursor		/* cursor */,
    XColor*		/* foreground_color */,
    XColor*		/* background_color */
);

EXTERN int XRefreshKeyboardMapping(
    XMappingEvent*	/* event_map */
);

EXTERN int XRemoveFromSaveSet(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XRemoveHost(
    Display*		/* display */,
    XHostAddress*	/* host */
);

EXTERN int XRemoveHosts(
    Display*		/* display */,
    XHostAddress*	/* hosts */,
    int			/* num_hosts */
);

EXTERN int XReparentWindow(
    Display*		/* display */,
    Window		/* w */,
    Window		/* parent */,
    int			/* x */,
    int			/* y */
);

EXTERN int XResetScreenSaver(
    Display*		/* display */
);

EXTERN int XResizeWindow(
    Display*		/* display */,
    Window		/* w */,
    unsigned int	/* width */,
    unsigned int	/* height */
);

EXTERN int XRestackWindows(
    Display*		/* display */,
    Window*		/* windows */,
    int			/* nwindows */
);

EXTERN int XRotateBuffers(
    Display*		/* display */,
    int			/* rotate */
);

EXTERN int XRotateWindowProperties(
    Display*		/* display */,
    Window		/* w */,
    Atom*		/* properties */,
    int			/* num_prop */,
    int			/* npositions */
);

EXTERN int XScreenCount(
    Display*		/* display */
);

EXTERN int XSelectInput(
    Display*		/* display */,
    Window		/* w */,
    long		/* event_mask */
);

EXTERN Status XSendEvent(
    Display*		/* display */,
    Window		/* w */,
    Bool		/* propagate */,
    long		/* event_mask */,
    XEvent*		/* event_send */
);

EXTERN int XSetAccessControl(
    Display*		/* display */,
    int			/* mode */
);

EXTERN int XSetArcMode(
    Display*		/* display */,
    GC			/* gc */,
    int			/* arc_mode */
);

EXTERN int XSetBackground(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long	/* background */
);

EXTERN int XSetClipMask(
    Display*		/* display */,
    GC			/* gc */,
    Pixmap		/* pixmap */
);

EXTERN int XSetClipOrigin(
    Display*		/* display */,
    GC			/* gc */,
    int			/* clip_x_origin */,
    int			/* clip_y_origin */
);

EXTERN int XSetClipRectangles(
    Display*		/* display */,
    GC			/* gc */,
    int			/* clip_x_origin */,
    int			/* clip_y_origin */,
    XRectangle*		/* rectangles */,
    int			/* n */,
    int			/* ordering */
);

EXTERN int XSetCloseDownMode(
    Display*		/* display */,
    int			/* close_mode */
);

EXTERN int XSetCommand(
    Display*		/* display */,
    Window		/* w */,
    char**		/* argv */,
    int			/* argc */
);

EXTERN int XSetDashes(
    Display*		/* display */,
    GC			/* gc */,
    int			/* dash_offset */,
    _Xconst char*	/* dash_list */,
    int			/* n */
);

EXTERN int XSetFillRule(
    Display*		/* display */,
    GC			/* gc */,
    int			/* fill_rule */
);

EXTERN int XSetFillStyle(
    Display*		/* display */,
    GC			/* gc */,
    int			/* fill_style */
);

EXTERN int XSetFont(
    Display*		/* display */,
    GC			/* gc */,
    Font		/* font */
);

EXTERN int XSetFontPath(
    Display*		/* display */,
    char**		/* directories */,
    int			/* ndirs */
);

EXTERN int XSetForeground(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long	/* foreground */
);

EXTERN int XSetFunction(
    Display*		/* display */,
    GC			/* gc */,
    int			/* function */
);

EXTERN int XSetGraphicsExposures(
    Display*		/* display */,
    GC			/* gc */,
    Bool		/* graphics_exposures */
);

EXTERN int XSetIconName(
    Display*		/* display */,
    Window		/* w */,
    _Xconst char*	/* icon_name */
);

EXTERN int XSetInputFocus(
    Display*		/* display */,
    Window		/* focus */,
    int			/* revert_to */,
    Time		/* time */
);

EXTERN int XSetLineAttributes(
    Display*		/* display */,
    GC			/* gc */,
    unsigned int	/* line_width */,
    int			/* line_style */,
    int			/* cap_style */,
    int			/* join_style */
);

EXTERN int XSetModifierMapping(
    Display*		/* display */,
    XModifierKeymap*	/* modmap */
);

EXTERN int XSetPlaneMask(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long	/* plane_mask */
);

EXTERN int XSetPointerMapping(
    Display*		/* display */,
    _Xconst unsigned char*	/* map */,
    int			/* nmap */
);

EXTERN int XSetScreenSaver(
    Display*		/* display */,
    int			/* timeout */,
    int			/* interval */,
    int			/* prefer_blanking */,
    int			/* allow_exposures */
);

EXTERN int XSetSelectionOwner(
    Display*		/* display */,
    Atom	        /* selection */,
    Window		/* owner */,
    Time		/* time */
);

EXTERN int XSetState(
    Display*		/* display */,
    GC			/* gc */,
    unsigned long 	/* foreground */,
    unsigned long	/* background */,
    int			/* function */,
    unsigned long	/* plane_mask */
);

EXTERN int XSetStipple(
    Display*		/* display */,
    GC			/* gc */,
    Pixmap		/* stipple */
);

EXTERN int XSetSubwindowMode(
    Display*		/* display */,
    GC			/* gc */,
    int			/* subwindow_mode */
);

EXTERN int XSetTSOrigin(
    Display*		/* display */,
    GC			/* gc */,
    int			/* ts_x_origin */,
    int			/* ts_y_origin */
);

EXTERN int XSetTile(
    Display*		/* display */,
    GC			/* gc */,
    Pixmap		/* tile */
);

EXTERN int XSetWindowBackground(
    Display*		/* display */,
    Window		/* w */,
    unsigned long	/* background_pixel */
);

EXTERN int XSetWindowBackgroundPixmap(
    Display*		/* display */,
    Window		/* w */,
    Pixmap		/* background_pixmap */
);

EXTERN int XSetWindowBorder(
    Display*		/* display */,
    Window		/* w */,
    unsigned long	/* border_pixel */
);

EXTERN int XSetWindowBorderPixmap(
    Display*		/* display */,
    Window		/* w */,
    Pixmap		/* border_pixmap */
);

EXTERN int XSetWindowBorderWidth(
    Display*		/* display */,
    Window		/* w */,
    unsigned int	/* width */
);

EXTERN int XSetWindowColormap(
    Display*		/* display */,
    Window		/* w */,
    Colormap		/* colormap */
);

EXTERN int XStoreBuffer(
    Display*		/* display */,
    _Xconst char*	/* bytes */,
    int			/* nbytes */,
    int			/* buffer */
);

EXTERN int XStoreBytes(
    Display*		/* display */,
    _Xconst char*	/* bytes */,
    int			/* nbytes */
);

EXTERN int XStoreColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    XColor*		/* color */
);

EXTERN int XStoreColors(
    Display*		/* display */,
    Colormap		/* colormap */,
    XColor*		/* color */,
    int			/* ncolors */
);

EXTERN int XStoreName(
    Display*		/* display */,
    Window		/* w */,
    _Xconst char*	/* window_name */
);

EXTERN int XStoreNamedColor(
    Display*		/* display */,
    Colormap		/* colormap */,
    _Xconst char*	/* color */,
    unsigned long	/* pixel */,
    int			/* flags */
);

EXTERN int XSync(
    Display*		/* display */,
    Bool		/* discard */
);

EXTERN int XTextExtents(
    XFontStruct*	/* font_struct */,
    _Xconst char*	/* string */,
    int			/* nchars */,
    int*		/* direction_return */,
    int*		/* font_ascent_return */,
    int*		/* font_descent_return */,
    XCharStruct*	/* overall_return */
);

EXTERN int XTextExtents16(
    XFontStruct*	/* font_struct */,
    _Xconst XChar2b*	/* string */,
    int			/* nchars */,
    int*		/* direction_return */,
    int*		/* font_ascent_return */,
    int*		/* font_descent_return */,
    XCharStruct*	/* overall_return */
);

EXTERN int XTextWidth(
    XFontStruct*	/* font_struct */,
    _Xconst char*	/* string */,
    int			/* count */
);

EXTERN int XTextWidth16(
    XFontStruct*	/* font_struct */,
    _Xconst XChar2b*	/* string */,
    int			/* count */
);

EXTERN Bool XTranslateCoordinates(
    Display*		/* display */,
    Window		/* src_w */,
    Window		/* dest_w */,
    int			/* src_x */,
    int			/* src_y */,
    int*		/* dest_x_return */,
    int*		/* dest_y_return */,
    Window*		/* child_return */
);

EXTERN int XUndefineCursor(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XUngrabButton(
    Display*		/* display */,
    unsigned int	/* button */,
    unsigned int	/* modifiers */,
    Window		/* grab_window */
);

EXTERN int XUngrabKey(
    Display*		/* display */,
    int			/* keycode */,
    unsigned int	/* modifiers */,
    Window		/* grab_window */
);

EXTERN int XUngrabKeyboard(
    Display*		/* display */,
    Time		/* time */
);

EXTERN int XUngrabPointer(
    Display*		/* display */,
    Time		/* time */
);

EXTERN int XUngrabServer(
    Display*		/* display */
);

EXTERN int XUninstallColormap(
    Display*		/* display */,
    Colormap		/* colormap */
);

EXTERN int XUnloadFont(
    Display*		/* display */,
    Font		/* font */
);

EXTERN int XUnmapSubwindows(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XUnmapWindow(
    Display*		/* display */,
    Window		/* w */
);

EXTERN int XVendorRelease(
    Display*		/* display */
);

EXTERN int XWarpPointer(
    Display*		/* display */,
    Window		/* src_w */,
    Window		/* dest_w */,
    int			/* src_x */,
    int			/* src_y */,
    unsigned int	/* src_width */,
    unsigned int	/* src_height */,
    int			/* dest_x */,
    int			/* dest_y */
);

EXTERN int XWidthMMOfScreen(
    Screen*		/* screen */
);

EXTERN int XWidthOfScreen(
    Screen*		/* screen */
);

EXTERN int XWindowEvent(
    Display*		/* display */,
    Window		/* w */,
    long		/* event_mask */,
    XEvent*		/* event_return */
);

EXTERN int XWriteBitmapFile(
    Display*		/* display */,
    _Xconst char*	/* filename */,
    Pixmap		/* bitmap */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    int			/* x_hot */,
    int			/* y_hot */
);

EXTERN Bool XSupportsLocale (void);

EXTERN char *XSetLocaleModifiers(
    const char*		/* modifier_list */
);

EXTERN XOM XOpenOM(
    Display*			/* display */,
    struct _XrmHashBucketRec*	/* rdb */,
    _Xconst char*		/* res_name */,
    _Xconst char*		/* res_class */
);

EXTERN Status XCloseOM(
    XOM			/* om */
);

EXTERN char *XSetOMValues(
    XOM			/* om */,
    ...
) _X_SENTINEL(0);

EXTERN char *XGetOMValues(
    XOM			/* om */,
    ...
) _X_SENTINEL(0);

EXTERN Display *XDisplayOfOM(
    XOM			/* om */
);

EXTERN char *XLocaleOfOM(
    XOM			/* om */
);

EXTERN XOC XCreateOC(
    XOM			/* om */,
    ...
) _X_SENTINEL(0);

EXTERN void XDestroyOC(
    XOC			/* oc */
);

EXTERN XOM XOMOfOC(
    XOC			/* oc */
);

EXTERN char *XSetOCValues(
    XOC			/* oc */,
    ...
) _X_SENTINEL(0);

EXTERN char *XGetOCValues(
    XOC			/* oc */,
    ...
) _X_SENTINEL(0);

EXTERN XFontSet XCreateFontSet(
    Display*		/* display */,
    _Xconst char*	/* base_font_name_list */,
    char***		/* missing_charset_list */,
    int*		/* missing_charset_count */,
    char**		/* def_string */
);

EXTERN void XFreeFontSet(
    Display*		/* display */,
    XFontSet		/* font_set */
);

EXTERN int XFontsOfFontSet(
    XFontSet		/* font_set */,
    XFontStruct***	/* font_struct_list */,
    char***		/* font_name_list */
);

EXTERN char *XBaseFontNameListOfFontSet(
    XFontSet		/* font_set */
);

EXTERN char *XLocaleOfFontSet(
    XFontSet		/* font_set */
);

EXTERN Bool XContextDependentDrawing(
    XFontSet		/* font_set */
);

EXTERN Bool XDirectionalDependentDrawing(
    XFontSet		/* font_set */
);

EXTERN Bool XContextualDrawing(
    XFontSet		/* font_set */
);

EXTERN XFontSetExtents *XExtentsOfFontSet(
    XFontSet		/* font_set */
);

EXTERN int XmbTextEscapement(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN int XwcTextEscapement(
    XFontSet		/* font_set */,
    _Xconst wchar_t*	/* text */,
    int			/* num_wchars */
);

EXTERN int Xutf8TextEscapement(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN int XmbTextExtents(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN int XwcTextExtents(
    XFontSet		/* font_set */,
    _Xconst wchar_t*	/* text */,
    int			/* num_wchars */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN int Xutf8TextExtents(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN Status XmbTextPerCharExtents(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */,
    XRectangle*		/* ink_extents_buffer */,
    XRectangle*		/* logical_extents_buffer */,
    int			/* buffer_size */,
    int*		/* num_chars */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN Status XwcTextPerCharExtents(
    XFontSet		/* font_set */,
    _Xconst wchar_t*	/* text */,
    int			/* num_wchars */,
    XRectangle*		/* ink_extents_buffer */,
    XRectangle*		/* logical_extents_buffer */,
    int			/* buffer_size */,
    int*		/* num_chars */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN Status Xutf8TextPerCharExtents(
    XFontSet		/* font_set */,
    _Xconst char*	/* text */,
    int			/* bytes_text */,
    XRectangle*		/* ink_extents_buffer */,
    XRectangle*		/* logical_extents_buffer */,
    int			/* buffer_size */,
    int*		/* num_chars */,
    XRectangle*		/* overall_ink_return */,
    XRectangle*		/* overall_logical_return */
);

EXTERN void XmbDrawText(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    XmbTextItem*	/* text_items */,
    int			/* nitems */
);

EXTERN void XwcDrawText(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    XwcTextItem*	/* text_items */,
    int			/* nitems */
);

EXTERN void Xutf8DrawText(
    Display*		/* display */,
    Drawable		/* d */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    XmbTextItem*	/* text_items */,
    int			/* nitems */
);

EXTERN void XmbDrawString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN void XwcDrawString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst wchar_t*	/* text */,
    int			/* num_wchars */
);

EXTERN void Xutf8DrawString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN void XmbDrawImageString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN void XwcDrawImageString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst wchar_t*	/* text */,
    int			/* num_wchars */
);

EXTERN void Xutf8DrawImageString(
    Display*		/* display */,
    Drawable		/* d */,
    XFontSet		/* font_set */,
    GC			/* gc */,
    int			/* x */,
    int			/* y */,
    _Xconst char*	/* text */,
    int			/* bytes_text */
);

EXTERN XIM XOpenIM(
    Display*			/* dpy */,
    struct _XrmHashBucketRec*	/* rdb */,
    char*			/* res_name */,
    char*			/* res_class */
);

EXTERN Status XCloseIM(
    XIM /* im */
);

EXTERN char *XGetIMValues(
    XIM /* im */, ...
) _X_SENTINEL(0);

EXTERN char *XSetIMValues(
    XIM /* im */, ...
) _X_SENTINEL(0);

EXTERN Display *XDisplayOfIM(
    XIM /* im */
);

EXTERN char *XLocaleOfIM(
    XIM /* im*/
);

EXTERN XIC XCreateIC(
    XIM /* im */, ...
) _X_SENTINEL(0);

EXTERN void XDestroyIC(
    XIC /* ic */
);

EXTERN void XSetICFocus(
    XIC /* ic */
);

EXTERN void XUnsetICFocus(
    XIC /* ic */
);

EXTERN wchar_t *XwcResetIC(
    XIC /* ic */
);

EXTERN char *XmbResetIC(
    XIC /* ic */
);

EXTERN char *Xutf8ResetIC(
    XIC /* ic */
);

EXTERN char *XSetICValues(
    XIC /* ic */, ...
) _X_SENTINEL(0);

EXTERN char *XGetICValues(
    XIC /* ic */, ...
) _X_SENTINEL(0);

EXTERN XIM XIMOfIC(
    XIC /* ic */
);

EXTERN Bool XFilterEvent(
    XEvent*	/* event */,
    Window	/* window */
);

EXTERN int XmbLookupString(
    XIC			/* ic */,
    XKeyPressedEvent*	/* event */,
    char*		/* buffer_return */,
    int			/* bytes_buffer */,
    KeySym*		/* keysym_return */,
    Status*		/* status_return */
);

EXTERN int XwcLookupString(
    XIC			/* ic */,
    XKeyPressedEvent*	/* event */,
    wchar_t*		/* buffer_return */,
    int			/* wchars_buffer */,
    KeySym*		/* keysym_return */,
    Status*		/* status_return */
);

EXTERN int Xutf8LookupString(
    XIC			/* ic */,
    XKeyPressedEvent*	/* event */,
    char*		/* buffer_return */,
    int			/* bytes_buffer */,
    KeySym*		/* keysym_return */,
    Status*		/* status_return */
);

EXTERN XVaNestedList XVaCreateNestedList(
    int /*unused*/, ...
) _X_SENTINEL(0);

/* internal connections for IMs */

EXTERN Bool XRegisterIMInstantiateCallback(
    Display*			/* dpy */,
    struct _XrmHashBucketRec*	/* rdb */,
    char*			/* res_name */,
    char*			/* res_class */,
    XIDProc			/* callback */,
    XPointer			/* client_data */
);

EXTERN Bool XUnregisterIMInstantiateCallback(
    Display*			/* dpy */,
    struct _XrmHashBucketRec*	/* rdb */,
    char*			/* res_name */,
    char*			/* res_class */,
    XIDProc			/* callback */,
    XPointer			/* client_data */
);

typedef void (*XConnectionWatchProc)(
    Display*			/* dpy */,
    XPointer			/* client_data */,
    int				/* fd */,
    Bool			/* opening */,	 /* open or close flag */
    XPointer*			/* watch_data */ /* open sets, close uses */
);


EXTERN Status XInternalConnectionNumbers(
    Display*			/* dpy */,
    int**			/* fd_return */,
    int*			/* count_return */
);

EXTERN void XProcessInternalConnection(
    Display*			/* dpy */,
    int				/* fd */
);

EXTERN Status XAddConnectionWatch(
    Display*			/* dpy */,
    XConnectionWatchProc	/* callback */,
    XPointer			/* client_data */
);

EXTERN void XRemoveConnectionWatch(
    Display*			/* dpy */,
    XConnectionWatchProc	/* callback */,
    XPointer			/* client_data */
);

EXTERN void XSetAuthorization(
    char *			/* name */,
    int				/* namelen */,
    char *			/* data */,
    int				/* datalen */
);

EXTERN int _Xmbtowc(
    wchar_t *			/* wstr */,
    char *			/* str */,
    int				/* len */
);

EXTERN int _Xwctomb(
    char *			/* str */,
    wchar_t			/* wc */
);

EXTERN Bool XGetEventData(
    Display*			/* dpy */,
    XGenericEventCookie*	/* cookie*/
);

EXTERN void XFreeEventData(
    Display*			/* dpy */,
    XGenericEventCookie*	/* cookie*/
);

#include "tkIntXlibDecls.h"

#ifdef __clang__
#pragma clang diagnostic pop
_XFUNCPROTOEND

#if defined(MAC_OSX_TK)
#   undef Cursor
#   undef Region
#endif

_XFUNCPROTOEND

#endif /* _X11_XLIB_H_ */
#endif /* _XLIB_H_ */

Changes to xlib/X11/Xutil.h.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


51
52
53
54
55
56
57
58
59

60
61

62
63
64
65
66
67
68
1
2
3

























4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26


27
28
29
30


31




32


33
34
35
36
37
38
39
40
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+







-
+













-
-
+
+


-
-

-
-
-
-
+
-
-
+







/* $XConsortium: Xutil.h,v 11.73 91/07/30 16:21:37 rws Exp $ */

/***********************************************************

Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

#ifndef _X11_XUTIL_H_
#define _X11_XUTIL_H_
#ifndef _XUTIL_H_
#define _XUTIL_H_

/* You must include <X11/Xlib.h> before including this file */
#include <X11/Xlib.h>
#include <X11/keysym.h>

/* The Xlib structs are full of implicit padding to properly align members.
   We can't clean that up without breaking ABI, so tell clang not to bother
   complaining about it. */
#ifdef __clang__
#if defined(MAC_OSX_TK)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#   define Region XRegion
#endif

/*
 * Bitmask returned by XParseGeometry().  Each bit tells if the corresponding
 * value (x, y, width, height) was found in the parsed string.
 */
#define NoValue		0x0000
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
108
109
110
111
112
113
114

115
116
117
118
119
120
121







-







#define IconPixmapHint		(1L << 2)
#define IconWindowHint		(1L << 3)
#define IconPositionHint 	(1L << 4)
#define IconMaskHint		(1L << 5)
#define WindowGroupHint		(1L << 6)
#define AllHints (InputHint|StateHint|IconPixmapHint|IconWindowHint| \
IconPositionHint|IconMaskHint|WindowGroupHint)
#define XUrgencyHint		(1L << 8)

/* definitions for initial window state */
#define WithdrawnState 0	/* for windows that are not mapped */
#define NormalState 1	/* most applications want to start this way */
#define IconicState 3	/* application wants to start as an icon */

/*
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260

261
262
263

264
265
266

267
268
269

270
271
272
273

274
275
276
277


278
279
280
281
282
283
284
285
286
287
288
289
290
142
143
144
145
146
147
148

149


150
151
152
153
154
155
156
157
158
159
160
161
162
































163
164
165
166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189

190
191



192

193
194
195

196
197
198

199
200
201

202
203

204

205




206
207






208
209
210
211
212
213
214







-
+
-
-













-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-














-













-
+

-
-
-

-
+


-
+


-
+


-
+

-

-
+
-
-
-
-
+
+
-
-
-
-
-
-







#define XLocaleNotSupported -2
#define XConverterNotFound -3

typedef enum {
    XStringStyle,		/* STRING */
    XCompoundTextStyle,		/* COMPOUND_TEXT */
    XTextStyle,			/* text in owner's encoding (current locale)*/
    XStdICCTextStyle,		/* STRING, else COMPOUND_TEXT */
    XStdICCTextStyle		/* STRING, else COMPOUND_TEXT */
    /* The following is an XFree86 extension, introduced in November 2000 */
    XUTF8StringStyle		/* UTF8_STRING */
} XICCEncodingStyle;

typedef struct {
	int min_width, min_height;
	int max_width, max_height;
	int width_inc, height_inc;
} XIconSize;

typedef struct {
	char *res_name;
	char *res_class;
} XClassHint;

#ifndef EXTERN
#   define EXTERN extern TCL_STORAGE_CLASS
#endif
#if defined(STATIC_BUILD) || !defined(_WIN32)
# ifndef TCL_STORAGE_CLASS
#   define TCL_STORAGE_CLASS
# endif
#elif defined(BUILD_tk)
# undef TCL_STORAGE_CLASS
# define TCL_STORAGE_CLASS __declspec(dllexport)
#elif !defined(TCL_STORAGE_CLASS)
# define TCL_STORAGE_CLASS __declspec(dllimport)
#endif

#ifdef XUTIL_DEFINE_FUNCTIONS
EXTERN int XDestroyImage(
        XImage *ximage);
EXTERN unsigned long XGetPixel(
        XImage *ximage,
        int x, int y);
EXTERN int XPutPixel(
        XImage *ximage,
        int x, int y,
        unsigned long pixel);
EXTERN XImage *XSubImage(
        XImage *ximage,
        int x, int y,
        unsigned int width, unsigned int height);
EXTERN int XAddPixel(
        XImage *ximage,
        long value);
#else
/*
 * These macros are used to give some sugar to the image routines so that
 * naive people are more comfortable with them.
 */
#define XDestroyImage(ximage) \
	((*((ximage)->f.destroy_image))((ximage)))
#define XGetPixel(ximage, x, y) \
	((*((ximage)->f.get_pixel))((ximage), (x), (y)))
#define XPutPixel(ximage, x, y, pixel) \
	((*((ximage)->f.put_pixel))((ximage), (x), (y), (pixel)))
#define XSubImage(ximage, x, y, width, height)  \
	((*((ximage)->f.sub_image))((ximage), (x), (y), (width), (height)))
#define XAddPixel(ximage, value) \
	((*((ximage)->f.add_pixel))((ximage), (value)))
#endif

/*
 * Compose sequence status structure, used in calling XLookupString.
 */
typedef struct _XComposeStatus {
    XPointer compose_ptr;	/* state table pointer */
    int chars_matched;		/* match state */
} XComposeStatus;

/*
 * Keysym macros, used on Keysyms to test for classes of symbols
 */
#define IsKeypadKey(keysym) \
  (((KeySym)(keysym) >= XK_KP_Space) && ((KeySym)(keysym) <= XK_KP_Equal))
  (((unsigned)(keysym) >= XK_KP_Space) && ((unsigned)(keysym) <= XK_KP_Equal))

#define IsPrivateKeypadKey(keysym) \
  (((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF))

#define IsCursorKey(keysym) \
  (((KeySym)(keysym) >= XK_Home)     && ((KeySym)(keysym) <  XK_Select))
  (((unsigned)(keysym) >= XK_Home)     && ((unsigned)(keysym) <  XK_Select))

#define IsPFKey(keysym) \
  (((KeySym)(keysym) >= XK_KP_F1)     && ((KeySym)(keysym) <= XK_KP_F4))
  (((unsigned)(keysym) >= XK_KP_F1)     && ((unsigned)(keysym) <= XK_KP_F4))

#define IsFunctionKey(keysym) \
  (((KeySym)(keysym) >= XK_F1)       && ((KeySym)(keysym) <= XK_F35))
  (((unsigned)(keysym) >= XK_F1)       && ((unsigned)(keysym) <= XK_F35))

#define IsMiscFunctionKey(keysym) \
  (((KeySym)(keysym) >= XK_Select)   && ((KeySym)(keysym) <= XK_Break))
  (((unsigned)(keysym) >= XK_Select)   && ((unsigned)(keysym) <= XK_Break))

#ifdef XK_XKB_KEYS
#define IsModifierKey(keysym) \
  ((((KeySym)(keysym) >= XK_Shift_L) && ((KeySym)(keysym) <= XK_Hyper_R)) \
  ((((unsigned)(keysym) >= XK_Shift_L) && ((unsigned)(keysym) <= XK_Hyper_R)) \
   || (((KeySym)(keysym) >= XK_ISO_Lock) && \
       ((KeySym)(keysym) <= XK_ISO_Level5_Lock)) \
   || ((KeySym)(keysym) == XK_Mode_switch) \
   || ((KeySym)(keysym) == XK_Num_Lock))
   || ((unsigned)(keysym) == XK_Mode_switch) \
   || ((unsigned)(keysym) == XK_Num_Lock))
#else
#define IsModifierKey(keysym) \
  ((((KeySym)(keysym) >= XK_Shift_L) && ((KeySym)(keysym) <= XK_Hyper_R)) \
   || ((KeySym)(keysym) == XK_Mode_switch) \
   || ((KeySym)(keysym) == XK_Num_Lock))
#endif
/*
 * opaque reference to Region data type
 */
typedef struct _XRegion *Region;

/* Return values from XRectInRegion() */

373
374
375
376
377
378
379
380


381

382
383
384


385

386
387
388


389

390
391
392


393

394
395
396


397

398
399
400


401
402

403
404
405








406

407
408
409
410
411


412
413
414

415
416
417


418

419
420
421


422

423
424
425


426
427

428
429
430


431
432
433
434

435
436
437


438
439
440

441
442
443


444
445
446
447

448
449
450


451
452
453

454
455
456


457
458
459
460
461

462
463
464


465
466
467
468

469
470
471


472
473
474
475

476
477
478


479
480
481
482

483
484
485
486
487
488
489
490
491
492


493
494
495

496
497
498


499
500

501
502
503


504
505
506

507
508
509


510
511
512

513
514
515


516
517
518
519

520
521
522


523
524
525
526
527

528
529
530


531
532
533

534
535
536


537
538
539
540
541

542
543
544
545
546
547
548


549
550
551
552
553

554
555
556


557
558
559
560
561

562
563
564


565
566
567

568
569
570


571
572
573

574
575
576


577
578
579

580
581
582


583
584
585
586
587

588
589
590


591
592
593
594

595
596
597


598
599
600

601
602
603


604
605
606
607

608
609
610


611
612
613

614
615
616


617
618
619
620
621

622
623
624


625
626
627
628

629
630
631


632
633
634
635
636
637
638
639

640
641
642


643
644
645
646
647
648

649
650
651
652
653
654
655


656
657
658

659
660
661


662
663
664

665
666
667


668
669
670

671
672
673


674
675
676

677
678
679


680
681
682
683
684
685
686
687
688

689
690
691

692
693
694
695
696
697
698
699
700
701
702

703
704
705
706
707
708
709
710
711
712

713
714
715


716
717
718
719

720
721
722


723
724
725

726
727
728


729
730
731
732

733
734
735


736
737
738

739
740
741


742
743
744
745
746

747
748
749
750
751
752
753


754
755
756

757
758
759
760
761
762
763
764








765
766
767
768
769
770
771
772







773
774

775
776
777
778
779
780
781
782
783
784




785
786
787











788
789
790
791
792

793
794
795
796
797
798
799
800
801
802
803
804






805
806

807
808
809
810
811
812
813
814


815
816
817

818
819
820


821
822
823

824
825
826


827
828
829
830
831
832
833
834
835
836
837

838
839
840


841
842
843
844
845
846
847
848

849
850
851




852

297
298
299
300
301
302
303

304
305
306
307
308
309

310
311
312
313
314
315

316
317
318
319
320
321

322
323
324
325
326
327

328
329
330
331
332
333

334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350
351
352



353
354
355
356
357
358
359
360

361
362
363
364
365
366

367
368
369
370
371
372

373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450






451

452
453
454
455
456
457
458
459

460
461
462
463
464
465
466

467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508
509

510
511
512
513
514


515




516
517

518
519
520
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605

606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633
634
635
636
637

638
639
640
641
642
643


644




645
646

647
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662

663
664
665
666
667
668
669
670

671
672
673
674
675
676
677
678

679
680
681
682
683
684
685
686
687
688
689
690
691
692

693











694

695
696
697
698
699
700
701
702
703
704
705
706

707
708
709
710
711
712
713
714
715

716
717
718
719
720
721
722
723

724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740

741
742
743
744
745


746




747
748

749
750
751
752
753
754
755
756






757
758
759
760
761
762
763
764
765
766






767
768
769
770
771
772
773


774






775
776


777
778
779
780
781
782

783
784
785
786
787
788
789
790
791
792
793
794
795
796


797





798
799





800
801
802
803
804
805


806





807
808

809
810
811
812
813
814
815
816

817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840

841
842
843
844
845




846
847
848
849
850
851
852
853
854

855







-
+
+

+


-
+
+

+


-
+
+

+


-
+
+

+


-
+
+

+


-
+
+


+


-
+
+
+
+
+
+
+
+

+


-
-
-
+
+



+


-
+
+

+


-
+
+

+


-
+
+


+


-
+
+




+


-
+
+



+


-
+
+




+


-
+
+



+


-
+
+





+


-
+
+




+


-
+
+




+


-
+
+




+


-
-
-
-
-
-

-
+
+



+


-
+
+


+


-
+
+



+


-
+
+



+


-
+
+




+


-
+
+





+


-
+
+



+


-
+
+



-
-
+
-
-
-
-


-
+
+





+


-
+
+





+


-
+
+



+


-
+
+



+


-
+
+



+


-
+
+





+


-
+
+




+


-
+
+



+


-
+
+




+


-
+
+



+


-
+
+





+


-
+
+




+


-
+
+








+


-
+
+




-
-
+
-
-
-
-


-
+
+



+


-
+
+



+


-
+
+



+


-
+
+



+


-
+
+









+


-
+
-
-
-
-
-
-
-
-
-
-
-
+
-









+


-
+
+




+


-
+
+



+


-
+
+




+


-
+
+



+


-
+
+



-
-
+
-
-
-
-


-
+
+



+


-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-


-
-
+
+
+
+


-
+
+
+
+
+
+
+
+
+
+
+



-
-
+
-
-
-
-
-


-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-


-
+
+



+


-
+
+



+


-
+
+











+


-
+
+



-
-
-
-

+



+
+
+
+
-
+
#define XUniqueContext()       ((XContext) XrmUniqueQuark())
#define XStringToContext(string)   ((XContext) XrmStringToQuark(string))

_XFUNCPROTOBEGIN

/* The following declarations are alphabetized. */

EXTERN XClassHint *XAllocClassHint (
extern XClassHint *XAllocClassHint (
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN XIconSize *XAllocIconSize (
extern XIconSize *XAllocIconSize (
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN XSizeHints *XAllocSizeHints (
extern XSizeHints *XAllocSizeHints (
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN XStandardColormap *XAllocStandardColormap (
extern XStandardColormap *XAllocStandardColormap (
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN XWMHints *XAllocWMHints (
extern XWMHints *XAllocWMHints (
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN int XClipBox(
extern void XClipBox(
#if NeedFunctionPrototypes
    Region		/* r */,
    XRectangle*		/* rect_return */
#endif
);

EXTERN Region XCreateRegion(
extern Region XCreateRegion(
#if NeedFunctionPrototypes
    void
#endif
);

extern char *XDefaultString(
#if NeedFunctionPrototypes
    void
#endif
);

EXTERN const char *XDefaultString (void);

EXTERN int XDeleteContext(
extern int XDeleteContext(
#if NeedFunctionPrototypes
    Display*		/* display */,
    XID			/* rid */,
    XContext		/* context */
#endif
);

EXTERN int XDestroyRegion(
extern void XDestroyRegion(
#if NeedFunctionPrototypes
    Region		/* r */
#endif
);

EXTERN Bool XEmptyRegion(
extern Bool XEmptyRegion(
#if NeedFunctionPrototypes
    Region		/* r */
#endif
);

EXTERN Bool XEqualRegion(
extern Bool XEqualRegion(
#if NeedFunctionPrototypes
    Region		/* r1 */,
    Region		/* r2 */
#endif
);

EXTERN int XFindContext(
extern int XFindContext(
#if NeedFunctionPrototypes
    Display*		/* display */,
    XID			/* rid */,
    XContext		/* context */,
    XPointer*		/* data_return */
#endif
);

EXTERN Status XGetClassHint(
extern Status XGetClassHint(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XClassHint*		/* class_hints_return */
#endif
);

EXTERN Status XGetIconSizes(
extern Status XGetIconSizes(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XIconSize**		/* size_list_return */,
    int*		/* count_return */
#endif
);

EXTERN Status XGetNormalHints(
extern Status XGetNormalHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints_return */
#endif
);

EXTERN Status XGetRGBColormaps(
extern Status XGetRGBColormaps(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XStandardColormap** /* stdcmap_return */,
    int*		/* count_return */,
    Atom		/* property */
#endif
);

EXTERN Status XGetSizeHints(
extern Status XGetSizeHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints_return */,
    Atom		/* property */
#endif
);

EXTERN Status XGetStandardColormap(
extern Status XGetStandardColormap(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XStandardColormap*	/* colormap_return */,
    Atom		/* property */
#endif
);

EXTERN Status XGetTextProperty(
extern Status XGetTextProperty(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* window */,
    XTextProperty*	/* text_prop_return */,
    Atom		/* property */
#endif
);

EXTERN XVisualInfo *XGetVisualInfo(
    Display*		/* display */,
    long		/* vinfo_mask */,
    XVisualInfo*	/* vinfo_template */,
    int*		/* nitems_return */
);

EXTERN Status XGetWMClientMachine(
extern Status XGetWMClientMachine(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop_return */
#endif
);

EXTERN XWMHints *XGetWMHints(
extern XWMHints *XGetWMHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */
#endif
);

EXTERN Status XGetWMIconName(
extern Status XGetWMIconName(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop_return */
#endif
);

EXTERN Status XGetWMName(
extern Status XGetWMName(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop_return */
#endif
);

EXTERN Status XGetWMNormalHints(
extern Status XGetWMNormalHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints_return */,
    long*		/* supplied_return */
#endif
);

EXTERN Status XGetWMSizeHints(
extern Status XGetWMSizeHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints_return */,
    long*		/* supplied_return */,
    Atom		/* property */
#endif
);

EXTERN Status XGetZoomHints(
extern Status XGetZoomHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* zhints_return */
#endif
);

EXTERN int XIntersectRegion(
extern void XIntersectRegion(
#if NeedFunctionPrototypes
    Region		/* sra */,
    Region		/* srb */,
    Region		/* dr_return */
);

#endif
EXTERN void XConvertCase(
    KeySym		/* sym */,
    KeySym*		/* lower */,
    KeySym*		/* upper */
);

EXTERN int XLookupString(
extern int XLookupString(
#if NeedFunctionPrototypes
    XKeyEvent*		/* event_struct */,
    char*		/* buffer_return */,
    int			/* bytes_buffer */,
    KeySym*		/* keysym_return */,
    XComposeStatus*	/* status_in_out */
#endif
);

EXTERN Status XMatchVisualInfo(
extern Status XMatchVisualInfo(
#if NeedFunctionPrototypes
    Display*		/* display */,
    int			/* screen */,
    int			/* depth */,
    int			/* class */,
    XVisualInfo*	/* vinfo_return */
#endif
);

EXTERN int XOffsetRegion(
extern int XOffsetRegion(
#if NeedFunctionPrototypes
    Region		/* r */,
    int			/* dx */,
    int			/* dy */
#endif
);

EXTERN Bool XPointInRegion(
extern Bool XPointInRegion(
#if NeedFunctionPrototypes
    Region		/* r */,
    int			/* x */,
    int			/* y */
#endif
);

EXTERN Region XPolygonRegion(
extern Region XPolygonRegion(
#if NeedFunctionPrototypes
    XPoint*		/* points */,
    int			/* n */,
    int			/* fill_rule */
#endif
);

EXTERN int XRectInRegion(
extern int XRectInRegion(
#if NeedFunctionPrototypes
    Region		/* r */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */
#endif
);

EXTERN int XSaveContext(
extern int XSaveContext(
#if NeedFunctionPrototypes
    Display*		/* display */,
    XID			/* rid */,
    XContext		/* context */,
    _Xconst char*	/* data */
#endif
);

EXTERN int XSetClassHint(
extern void XSetClassHint(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XClassHint*		/* class_hints */
#endif
);

EXTERN int XSetIconSizes(
extern void XSetIconSizes(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XIconSize*		/* size_list */,
    int			/* count */
#endif
);

EXTERN int XSetNormalHints(
extern void XSetNormalHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints */
#endif
);

EXTERN void XSetRGBColormaps(
extern void XSetRGBColormaps(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XStandardColormap*	/* stdcmaps */,
    int			/* count */,
    Atom		/* property */
#endif
);

EXTERN int XSetSizeHints(
extern void XSetSizeHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints */,
    Atom		/* property */
#endif
);

EXTERN int XSetStandardProperties(
extern void XSetStandardProperties(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    _Xconst char*	/* window_name */,
    _Xconst char*	/* icon_name */,
    Pixmap		/* icon_pixmap */,
    char**		/* argv */,
    int			/* argc */,
    XSizeHints*		/* hints */
#endif
);

EXTERN void XSetTextProperty(
extern void XSetTextProperty(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop */,
    Atom		/* property */
);

#endif
EXTERN void XSetWMClientMachine(
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop */
);

EXTERN int XSetWMHints(
extern void XSetWMHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XWMHints*		/* wm_hints */
#endif
);

EXTERN void XSetWMIconName(
extern void XSetWMIconName(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop */
#endif
);

EXTERN void XSetWMName(
extern void XSetWMName(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* text_prop */
#endif
);

EXTERN void XSetWMNormalHints(
extern void XSetWMNormalHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints */
#endif
);

EXTERN void XSetWMProperties(
extern void XSetWMProperties(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XTextProperty*	/* window_name */,
    XTextProperty*	/* icon_name */,
    char**		/* argv */,
    int			/* argc */,
    XSizeHints*		/* normal_hints */,
    XWMHints*		/* wm_hints */,
    XClassHint*		/* class_hints */
#endif
);

EXTERN void XmbSetWMProperties(
extern void XmbSetWMProperties(
    Display*		/* display */,
    Window		/* w */,
    _Xconst char*	/* window_name */,
    _Xconst char*	/* icon_name */,
    char**		/* argv */,
    int			/* argc */,
    XSizeHints*		/* normal_hints */,
    XWMHints*		/* wm_hints */,
    XClassHint*		/* class_hints */
);

#if NeedFunctionPrototypes
EXTERN void Xutf8SetWMProperties(
    Display*		/* display */,
    Window		/* w */,
    _Xconst char*	/* window_name */,
    _Xconst char*	/* icon_name */,
    char**		/* argv */,
    int			/* argc */,
    XSizeHints*		/* normal_hints */,
    XWMHints*		/* wm_hints */,
    XClassHint*		/* class_hints */
#endif
);

EXTERN void XSetWMSizeHints(
extern void XSetWMSizeHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* hints */,
    Atom		/* property */
#endif
);

EXTERN int XSetRegion(
extern void XSetRegion(
#if NeedFunctionPrototypes
    Display*		/* display */,
    GC			/* gc */,
    Region		/* r */
#endif
);

EXTERN void XSetStandardColormap(
extern void XSetStandardColormap(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XStandardColormap*	/* colormap */,
    Atom		/* property */
#endif
);

EXTERN int XSetZoomHints(
extern void XSetZoomHints(
#if NeedFunctionPrototypes
    Display*		/* display */,
    Window		/* w */,
    XSizeHints*		/* zhints */
#endif
);

EXTERN int XShrinkRegion(
extern void XShrinkRegion(
#if NeedFunctionPrototypes
    Region		/* r */,
    int			/* dx */,
    int			/* dy */
);

#endif
EXTERN Status XStringListToTextProperty(
    char**		/* list */,
    int			/* count */,
    XTextProperty*	/* text_prop_return */
);

EXTERN int XSubtractRegion(
extern void XSubtractRegion(
#if NeedFunctionPrototypes
    Region		/* sra */,
    Region		/* srb */,
    Region		/* dr_return */
#endif
);

EXTERN int XmbTextListToTextProperty(
    Display*		display,
    char**		list,
    int			count,
    XICCEncodingStyle	style,
    XTextProperty*	text_prop_return
extern int XmbTextListToTextProperty(
#if NeedFunctionPrototypes
    Display*		/* display */,
    char**		/* list */,
    int			/* count */,
    XICCEncodingStyle	/* style */,
    XTextProperty*	/* text_prop_return */
#endif
);

EXTERN int XwcTextListToTextProperty(
    Display*		display,
    wchar_t**		list,
    int			count,
    XICCEncodingStyle	style,
    XTextProperty*	text_prop_return
extern int XwcTextListToTextProperty(
#if NeedFunctionPrototypes
    Display*		/* display */,
    wchar_t**		/* list */,
    int			/* count */,
    XICCEncodingStyle	/* style */,
    XTextProperty*	/* text_prop_return */
);

#endif
EXTERN int Xutf8TextListToTextProperty(
    Display*		display,
    char**		list,
    int			count,
    XICCEncodingStyle	style,
    XTextProperty*	text_prop_return
);

EXTERN void XwcFreeStringList(
    wchar_t**		list
extern void XwcFreeStringList(
#if NeedFunctionPrototypes
    wchar_t**		/* list */
#endif
);

EXTERN Status XTextPropertyToStringList(
extern Status XTextPropertyToStringList(
#if NeedFunctionPrototypes
    XTextProperty*	/* text_prop */,
    char***		/* list_return */,
    int*		/* count_return */
#endif
);

extern int XmbTextPropertyToTextList(
#if NeedFunctionPrototypes
    Display*		/* display */,
    XTextProperty*	/* text_prop */,
    char***		/* list_return */,
    int*		/* count_return */
);

#endif
EXTERN int XmbTextPropertyToTextList(
    Display*		display,
    const XTextProperty* text_prop,
    char***		list_return,
    int*		count_return
);

EXTERN int XwcTextPropertyToTextList(
    Display*		display,
    const XTextProperty* text_prop,
    wchar_t***		list_return,
    int*		count_return
extern int XwcTextPropertyToTextList(
#if NeedFunctionPrototypes
    Display*		/* display */,
    XTextProperty*	/* text_prop */,
    wchar_t***		/* list_return */,
    int*		/* count_return */
);

#endif
EXTERN int Xutf8TextPropertyToTextList(
    Display*		display,
    const XTextProperty* text_prop,
    char***		list_return,
    int*		count_return
);

EXTERN int XUnionRectWithRegion(
extern void XUnionRectWithRegion(
#if NeedFunctionPrototypes
    XRectangle*		/* rectangle */,
    Region		/* src_region */,
    Region		/* dest_region_return */
#endif
);

EXTERN int XUnionRegion(
extern int XUnionRegion(
#if NeedFunctionPrototypes
    Region		/* sra */,
    Region		/* srb */,
    Region		/* dr_return */
#endif
);

EXTERN int XWMGeometry(
extern int XWMGeometry(
#if NeedFunctionPrototypes
    Display*		/* display */,
    int			/* screen_number */,
    _Xconst char*	/* user_geometry */,
    _Xconst char*	/* default_geometry */,
    unsigned int	/* border_width */,
    XSizeHints*		/* hints */,
    int*		/* x_return */,
    int*		/* y_return */,
    int*		/* width_return */,
    int*		/* height_return */,
    int*		/* gravity_return */
#endif
);

EXTERN int XXorRegion(
extern void XXorRegion(
#if NeedFunctionPrototypes
    Region		/* sra */,
    Region		/* srb */,
    Region		/* dr_return */
);

#ifdef __clang__
#pragma clang diagnostic pop
#endif
);

_XFUNCPROTOEND

#if defined(MAC_OSX_TK)
#   undef Region
#endif

#endif /* _X11_XUTIL_H_ */
#endif /* _XUTIL_H_ */

Deleted xlib/X11/ap_keysym.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51



















































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/******************************************************************
Copyright 1987 by Apollo Computer Inc., Chelmsford, Massachusetts.
Copyright 1989 by Hewlett-Packard Company.

                        All Rights Reserved

Permission to use, duplicate, change, and distribute this software and
its documentation for any purpose and without fee is granted, provided
that the above copyright notice appear in such copy and that this
copyright notice appear in all supporting documentation, and that the
names of Apollo Computer Inc., the Hewlett-Packard Company, or the X
Consortium not be used in advertising or publicity pertaining to
distribution of the software without written prior permission.

HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD
TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  Hewlett-Packard shall not be liable for errors
contained herein or direct, indirect, special, incidental or
consequential damages in connection with the furnishing,
performance, or use of this material.

This software is not subject to any license of the American
Telephone and Telegraph Company or of the Regents of the
University of California.
******************************************************************/

#define apXK_LineDel            0x1000FF00
#define apXK_CharDel            0x1000FF01
#define apXK_Copy               0x1000FF02
#define apXK_Cut                0x1000FF03
#define apXK_Paste              0x1000FF04
#define apXK_Move               0x1000FF05
#define apXK_Grow               0x1000FF06
#define apXK_Cmd                0x1000FF07
#define apXK_Shell              0x1000FF08
#define apXK_LeftBar            0x1000FF09
#define apXK_RightBar           0x1000FF0A
#define apXK_LeftBox            0x1000FF0B
#define apXK_RightBox           0x1000FF0C
#define apXK_UpBox              0x1000FF0D
#define apXK_DownBox            0x1000FF0E
#define apXK_Pop                0x1000FF0F
#define apXK_Read               0x1000FF10
#define apXK_Edit               0x1000FF11
#define apXK_Save               0x1000FF12
#define apXK_Exit               0x1000FF13
#define apXK_Repeat             0x1000FF14

#define apXK_KP_parenleft       0x1000FFA8
#define apXK_KP_parenright      0x1000FFA9

Changes to xlib/X11/cursorfont.h.

1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


1





























2
3
4
5
6
7
8
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







/*

/* $XConsortium: cursorfont.h,v 1.2 88/09/06 16:44:27 jim Exp $ */
Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.

*/

#ifndef _X11_CURSORFONT_H_
#define _X11_CURSORFONT_H_

#define XC_num_glyphs 154
#define XC_X_cursor 0
#define XC_arrow 2
#define XC_based_arrow_down 4
#define XC_based_arrow_up 6
#define XC_boat 8
#define XC_bogosity 10
103
104
105
106
107
108
109
110
111
73
74
75
76
77
78
79









-
-
#define XC_top_tee 140
#define XC_trek 142
#define XC_ul_angle 144
#define XC_umbrella 146
#define XC_ur_angle 148
#define XC_watch 150
#define XC_xterm 152

#endif /* _X11_CURSORFONT_H_ */

Changes to xlib/X11/keysym.h.

1
2

3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74


1

2






3
















4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32



33













34
35

-
-
+
-

-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+







-
+















-




-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-


-
/***********************************************************

/* $XConsortium: keysym.h,v 1.13 91/03/13 20:09:49 rws Exp $ */
Copyright 1987, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

/***********************************************************
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

/* default keysyms */
#define XK_MISCELLANY
#define XK_XKB_KEYS
#define XK_LATIN1
#define XK_LATIN2
#define XK_LATIN3
#define XK_LATIN4
#define XK_LATIN8
#define XK_LATIN9
#define XK_CAUCASUS
#define XK_GREEK
#define XK_KATAKANA
#define XK_ARABIC
#define XK_CYRILLIC
#define XK_HEBREW
#define XK_THAI
#define XK_KOREAN
#define XK_ARMENIAN
#define XK_GEORGIAN
#define XK_VIETNAMESE
#define XK_CURRENCY
#define XK_MATHEMATICAL
#define XK_BRAILLE
#define XK_SINHALA

#include <X11/keysymdef.h>

Changes to xlib/X11/keysymdef.h.

1
2
3

4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195

196
197

198
199
200
201
202
203
204
205
206
207
208
209










210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

















240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258











259

260




261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276














277
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306



























307
308
309
310
311
312
313
314
315
316
317










318
319
320
321
322
323


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387




























































388
389
390
391
392
393
394
395
396






397
398
399
400
401
402
403
404
405








406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

619
620

621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719

































































































720
721
722
723
724
725
726
727
728
729
730
731
732












733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748















749
750

751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780





























781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815


































816
817
818
819
820
821
822
823







824
825
826
827
828


829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885























































886
887
888


889
890
891
892
893


894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918






















919
920
921
922
923
924


925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945


















946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985











986
987
988
989
990



991
992
993
994
995
996
997

998
999
1000
1001
1002

1003
1004
1005


1006
1007

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084






































































1085
1086
1087
1088
1089


1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110

1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
















































1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240


















1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263






















1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331



































































1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344




1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415






































































1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473

















































1474
1475
1476
1477

1478
1479

1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
























1507
1508
1509
1510

1511
1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559











































1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600








































1601
1602
1603
1604
1605


1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627



















1628
1629
1630
1631
1632

1633
1634
1635
1636
1637
1638
1639
1640
1641






1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
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



1





2



3















4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26















































































































































27
28
29
30

31
32

33
34
35










36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51




52
53
54

















55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71





72
73
74











75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94














95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111



























112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139










140
141
142
143
144
145
146
147
148
149
150
151
152
153


154
155
156
157
158
159




























































160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222






223
224
225
226
227
228
229








230
231
232
233
234
235
236
237
238
239
240


















































































































































































































241


242
243
244

































































































245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342












343
344
345
346
347
348
349
350
351
352
353
354
















355
356
357
358
359
360
361
362
363
364
365
366
367
368
369


370






























371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399



































400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433








434
435
436
437
438
439
440
441
442
443


444
445
446
447
448






















































449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503



504
505
506
507
508


509
510
511
512
513






















514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539


540
541
542
543
544


















545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562








































563
564
565
566
567
568
569
570
571
572
573





574
575
576







577





578



579
580


581
582
583
584
585
586
587
588






































































589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661


662
663
664
665
666


















667



























































668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715














716
717
718
719
720
721
722
723


















































724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741























742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763




































































764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834

835
836
837
838




839
840
841
842







































































843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916

917
918
919
920

















































921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972

973


974
975
976
977
























978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004

1005



1006
1007
1008
1009











































1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052









































1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095


1096
1097
1098
1099
1100



















1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123

1124
1125
1126
1127






1128
1129
1130
1131
1132
1133
































































































































1134





1135


1136

















1137
































1138























1139





























1140









1141




1142





1143



1144


1145




1146























































































1147






1148




1149





















1150





















1151




1152
























1153




1154



































































































1155


1156







1157
1158




1159





1160





















1161















1162







1163
1164
1165
1166
1167
1168



















































































































1169
1170
1171
1172


















































































































































1173





1174








1175
1176
1177
1178
1179
1180
1181










































































-
-
-
+
-
-
-
-
-

-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+







-
+













-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+



-
+

-
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+





-
+
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

+

+
+
+
+
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+




-
-
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+



-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
+
+
-
-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-




-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+
-
-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+
-
-
-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+



-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/***********************************************************
Copyright 1987, 1994, 1998  The Open Group

/* $XConsortium: keysymdef.h,v 1.15 93/04/02 10:57:36 rws Exp $ */
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

/***********************************************************
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

/*
 * The "X11 Window System Protocol" standard defines in Appendix A the
 * keysym codes. These 29-bit integer values identify characters or
 * functions associated with each key (e.g., via the visible
 * engraving) of a keyboard layout. This file assigns mnemonic macro
 * names for these keysyms.
 *
 * This file is also compiled (by src/util/makekeys.c in libX11) into
 * hash tables that can be accessed with X11 library functions such as
 * XStringToKeysym() and XKeysymToString().
 *
 * Where a keysym corresponds one-to-one to an ISO 10646 / Unicode
 * character, this is noted in a comment that provides both the U+xxxx
 * Unicode position, as well as the official Unicode name of the
 * character.
 *
 * Some keysyms map to a character already mapped by another keysym,
 * with compatible but more precise semantics, such as the keypad-
 * related keysyms. In this case, none of the keysym are deprecated.
 * The most generic keysym is annotated as previously and more specific
 * keysyms have the same annotation between angle brackets:
 *
 *     #define XK_space                 0x0020  // U+0020 SPACE
 *     #define XK_KP_Space              0xff80  //<U+0020 SPACE>
 *
 * Where the correspondence is either not one-to-one or semantically
 * unclear, the Unicode position and name are enclosed in
 * parentheses. Such legacy keysyms should be considered deprecated
 * and are not recommended for use in future keyboard mappings.
 *
 * For any future extension of the keysyms with characters already
 * found in ISO 10646 / Unicode, the following algorithm shall be
 * used. The new keysym code position will simply be the character's
 * Unicode number plus 0x01000000. The keysym values in the range
 * 0x01000100 to 0x0110ffff are reserved to represent Unicode
 * characters in the range U+0100 to U+10FFFF.
 *
 * While most newer Unicode-based X11 clients do already accept
 * Unicode-mapped keysyms in the range 0x01000100 to 0x0110ffff, it
 * will remain necessary for clients -- in the interest of
 * compatibility with existing servers -- to also understand the
 * existing legacy keysym values in the range 0x0100 to 0x20ff.
 *
 * Where several mnemonic names are defined for the same keysym in this
 * file, the first one listed is considered the "canonical" name. This
 * is the name that should be used when retrieving a keysym name from
 * its code. The next names are considered "aliases" to the canonical
 * name.
 *
 * Aliases are made explicit by writing in their comment "alias for",
 * followed by the corresponding canonical name. Example:
 *
 *     #define XK_dead_tilde            0xfe53
 *     #define XK_dead_perispomeni      0xfe53 // alias for dead_tilde
 *
 * The rules to consider a keysym mnemonic name deprecated are:
 *
 *   1. A legacy keysym with its Unicode mapping in parentheses is
 *      deprecated (see above).
 *
 *   2. A keysym name is *explicitly* deprecated by starting its comment
 *      with "deprecated". Examples:
 *
 *        #define XK_L1           0xffc8  // deprecated alias for F11
 *        #define XK_quoteleft    0x0060  // deprecated
 *
 *   3. A keysym name is *explicitly* *not* deprecated by starting its
 *      comment with "non-deprecated alias". Examples:
 *
 *       #define XK_dead_tilde       0xfe53
 *       #define XK_dead_perispomeni 0xfe53 // non-deprecated alias for dead_tilde
 *
 *   4. If none of the previous rules apply, an alias is *implicitly*
 *      deprecated if there is at least one previous name for the
 *      corresponding keysym that is *not* explicitly deprecated.
 *
 *      Examples:
 *
 *        // SingleCandidate is the canonical name
 *        #define XK_SingleCandidate        0xff3c
 *        // Hangul_SingleCandidate is deprecated because it is an alias
 *        // and it does not start with "non-deprecated alias"
 *        #define XK_Hangul_SingleCandidate 0xff3c // Single candidate
 *
 *        // guillemotleft is the canonical name, but it is deprecated
 *        #define XK_guillemotleft  0x00ab // deprecated alias for guillemetleft (misspelling)
 *        // guillemetleft is not deprecated, because the keysym has no endorsed name before it.
 *        #define XK_guillemetleft  0x00ab // U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
 *        // The following hypothetical name is deprecated because guillemetleft come before.
 *        #define XK_guillemetleft2 0x00ab
 *
 * Mnemonic names for keysyms are defined in this file with lines
 * that match one of these Perl regular expressions:
 *
 *    /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-f]+)\s*\/\* U\+([0-9A-F]{4,6}) (.*) \*\/\s*$/
 *    /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-f]+)\s*\/\*<U\+([0-9A-F]{4,6}) (.*)>\*\/\s*$/
 *    /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-f]+)\s*\/\*\(U\+([0-9A-F]{4,6}) (.*)\)\*\/\s*$/
 *    /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-f]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/
 *
 * Before adding new keysyms, please do consider the following: In
 * addition to the keysym names defined in this file, the
 * XStringToKeysym() and XKeysymToString() functions will also handle
 * any keysym string of the form "U0020" to "U007E" and "U00A0" to
 * "U10FFFF" for all possible Unicode characters. In other words,
 * every possible Unicode character has already a keysym string
 * defined algorithmically, even if it is not listed here. Therefore,
 * defining an additional keysym macro is only necessary where a
 * non-hexadecimal mnemonic name is needed, or where the new keysym
 * does not represent any existing Unicode character.
 *
 * When adding new keysyms to this file, do not forget to also update the
 * following as needed:
 *
 *   - the mappings in src/KeyBind.c in the libX11 repo
 *     https://gitlab.freedesktop.org/xorg/lib/libx11
 *
 *   - the protocol specification in specs/keysyms.xml in this repo
 *     https://gitlab.freedesktop.org/xorg/proto/xorgproto
 *
 * Before removing or changing the order of the keysyms, please consider
 * the following: it is very difficult to know what keysyms are used and
 * how.
 *
 *   - A sandboxed application may have incompatibilities with the host
 *     system. For example, if new keysym name is introduced and is made
 *     the canonical name, then an application with an older keysym parser
 *     will not be able to parse the new name.
 *   - Customization of keyboard layout and Compose files are two popular
 *     use cases. Checking the standard keyboard layout database xkeyboard-config
 *     https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config
 *     and the standard Compose files in libx11
 *     https://gitlab.freedesktop.org/xorg/lib/libx11 is a mandatory
 *     step, but may *not* be enough for a proper impact assessment for
 *     e.g. keysyms removals.
 *
 * Therefore, it is advised to proceed to no removal and to make a new
 * name canonical only 10 years after its introduction. This means that
 * some keysyms may have their first listed name deprecated during the
 * period of transition. Once this period is over, the deprecated name
 * should be moved after the new canonical name.
 */

#define XK_VoidSymbol                  0xffffff  /* Void symbol */
#define XK_VoidSymbol		0xFFFFFF	/* void symbol */

#ifdef XK_MISCELLANY
/*
 * TTY function keys, cleverly chosen to map to ASCII, for convenience of
 * TTY Functions, cleverly chosen to map to ascii, for convenience of
 * programming, but could have been arbitrary (at the cost of lookup
 * tables in client code).
 * tables in client code.
 */

#define XK_BackSpace                     0xff08  /* U+0008 BACKSPACE */
#define XK_Tab                           0xff09  /* U+0009 CHARACTER TABULATION */
#define XK_Linefeed                      0xff0a  /* U+000A LINE FEED */
#define XK_Clear                         0xff0b  /* U+000B LINE TABULATION */
#define XK_Return                        0xff0d  /* U+000D CARRIAGE RETURN */
#define XK_Pause                         0xff13  /* Pause, hold */
#define XK_Scroll_Lock                   0xff14
#define XK_Sys_Req                       0xff15
#define XK_Escape                        0xff1b  /* U+001B ESCAPE */
#define XK_Delete                        0xffff  /* U+007F DELETE */
#define XK_BackSpace		0xFF08	/* back space, back char */
#define XK_Tab			0xFF09
#define XK_Linefeed		0xFF0A	/* Linefeed, LF */
#define XK_Clear		0xFF0B
#define XK_Return		0xFF0D	/* Return, enter */
#define XK_Pause		0xFF13	/* Pause, hold */
#define XK_Scroll_Lock		0xFF14
#define XK_Sys_Req		0xFF15
#define XK_Escape		0xFF1B
#define XK_Delete		0xFFFF	/* Delete, rubout */



/* International & multi-key character composition */

#define XK_Multi_key                     0xff20  /* Multi-key character compose */
#define XK_Multi_key		0xFF20  /* Multi-key character compose */
#define XK_Codeinput                     0xff37
#define XK_SingleCandidate               0xff3c
#define XK_MultipleCandidate             0xff3d
#define XK_PreviousCandidate             0xff3e

/* Japanese keyboard support */

#define XK_Kanji                         0xff21  /* Kanji, Kanji convert */
#define XK_Muhenkan                      0xff22  /* Cancel Conversion */
#define XK_Henkan_Mode                   0xff23  /* Start/Stop Conversion */
#define XK_Henkan                        0xff23  /* non-deprecated alias for Henkan_Mode */
#define XK_Romaji                        0xff24  /* to Romaji */
#define XK_Hiragana                      0xff25  /* to Hiragana */
#define XK_Katakana                      0xff26  /* to Katakana */
#define XK_Hiragana_Katakana             0xff27  /* Hiragana/Katakana toggle */
#define XK_Zenkaku                       0xff28  /* to Zenkaku */
#define XK_Hankaku                       0xff29  /* to Hankaku */
#define XK_Zenkaku_Hankaku               0xff2a  /* Zenkaku/Hankaku toggle */
#define XK_Touroku                       0xff2b  /* Add to Dictionary */
#define XK_Massyo                        0xff2c  /* Delete from Dictionary */
#define XK_Kana_Lock                     0xff2d  /* Kana Lock */
#define XK_Kana_Shift                    0xff2e  /* Kana Shift */
#define XK_Eisu_Shift                    0xff2f  /* Alphanumeric Shift */
#define XK_Eisu_toggle                   0xff30  /* Alphanumeric toggle */
#define XK_Kanji		0xFF21	/* Kanji, Kanji convert */
#define XK_Muhenkan		0xFF22  /* Cancel Conversion */
#define XK_Henkan_Mode		0xFF23  /* Start/Stop Conversion */
#define XK_Henkan		0xFF23  /* Alias for Henkan_Mode */
#define XK_Romaji		0xFF24  /* to Romaji */
#define XK_Hiragana		0xFF25  /* to Hiragana */
#define XK_Katakana		0xFF26  /* to Katakana */
#define XK_Hiragana_Katakana	0xFF27  /* Hiragana/Katakana toggle */
#define XK_Zenkaku		0xFF28  /* to Zenkaku */
#define XK_Hankaku		0xFF29  /* to Hankaku */
#define XK_Zenkaku_Hankaku	0xFF2A  /* Zenkaku/Hankaku toggle */
#define XK_Touroku		0xFF2B  /* Add to Dictionary */
#define XK_Massyo		0xFF2C  /* Delete from Dictionary */
#define XK_Kana_Lock		0xFF2D  /* Kana Lock */
#define XK_Kana_Shift		0xFF2E  /* Kana Shift */
#define XK_Eisu_Shift		0xFF2F  /* Alphanumeric Shift */
#define XK_Eisu_toggle		0xFF30  /* Alphanumeric toggle */
#define XK_Kanji_Bangou                  0xff37  /* Codeinput */
#define XK_Zen_Koho                      0xff3d  /* Multiple/All Candidate(s) */
#define XK_Mae_Koho                      0xff3e  /* Previous Candidate */

/* 0xff31 thru 0xff3f are under XK_KOREAN */

/* Cursor control & motion */

#define XK_Home                          0xff50
#define XK_Left                          0xff51  /* Move left, left arrow */
#define XK_Up                            0xff52  /* Move up, up arrow */
#define XK_Right                         0xff53  /* Move right, right arrow */
#define XK_Down                          0xff54  /* Move down, down arrow */
#define XK_Prior                         0xff55  /* Prior, previous */
#define XK_Page_Up                       0xff55  /* deprecated alias for Prior */
#define XK_Next                          0xff56  /* Next */
#define XK_Page_Down                     0xff56  /* deprecated alias for Next */
#define XK_End                           0xff57  /* EOL */
#define XK_Begin                         0xff58  /* BOL */
#define XK_Home			0xFF50
#define XK_Left			0xFF51	/* Move left, left arrow */
#define XK_Up			0xFF52	/* Move up, up arrow */
#define XK_Right		0xFF53	/* Move right, right arrow */
#define XK_Down			0xFF54	/* Move down, down arrow */
#define XK_Prior		0xFF55	/* Prior, previous */
#define XK_Page_Up		0xFF55
#define XK_Next			0xFF56	/* Next */
#define XK_Page_Down		0xFF56
#define XK_End			0xFF57	/* EOL */
#define XK_Begin		0xFF58	/* BOL */

/* Special Windows keyboard keys */

#define XK_Win_L		0xFF5B	/* Left-hand Windows */
#define XK_Win_R		0xFF5C	/* Right-hand Windows */
#define XK_App			0xFF5D	/* Menu key */

/* Misc functions */
/* Misc Functions */

#define XK_Select                        0xff60  /* Select, mark */
#define XK_Print                         0xff61
#define XK_Execute                       0xff62  /* Execute, run, do */
#define XK_Insert                        0xff63  /* Insert, insert here */
#define XK_Undo                          0xff65
#define XK_Redo                          0xff66  /* Redo, again */
#define XK_Menu                          0xff67
#define XK_Find                          0xff68  /* Find, search */
#define XK_Cancel                        0xff69  /* Cancel, stop, abort, exit */
#define XK_Help                          0xff6a  /* Help */
#define XK_Break                         0xff6b
#define XK_Mode_switch                   0xff7e  /* Character set switch */
#define XK_script_switch                 0xff7e  /* non-deprecated alias for Mode_switch */
#define XK_Num_Lock                      0xff7f
#define XK_Select		0xFF60	/* Select, mark */
#define XK_Print		0xFF61
#define XK_Execute		0xFF62	/* Execute, run, do */
#define XK_Insert		0xFF63	/* Insert, insert here */
#define XK_Undo			0xFF65	/* Undo, oops */
#define XK_Redo			0xFF66	/* redo, again */
#define XK_Menu			0xFF67
#define XK_Find			0xFF68	/* Find, search */
#define XK_Cancel		0xFF69	/* Cancel, stop, abort, exit */
#define XK_Help			0xFF6A	/* Help, ? */
#define XK_Break		0xFF6B
#define XK_Mode_switch		0xFF7E	/* Character set switch */
#define XK_script_switch        0xFF7E  /* Alias for mode_switch */
#define XK_Num_Lock		0xFF7F

/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */
/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */

#define XK_KP_Space                      0xff80  /*<U+0020 SPACE>*/
#define XK_KP_Tab                        0xff89  /*<U+0009 CHARACTER TABULATION>*/
#define XK_KP_Enter                      0xff8d  /*<U+000D CARRIAGE RETURN>*/
#define XK_KP_F1                         0xff91  /* PF1, KP_A, ... */
#define XK_KP_F2                         0xff92
#define XK_KP_F3                         0xff93
#define XK_KP_F4                         0xff94
#define XK_KP_Home                       0xff95
#define XK_KP_Left                       0xff96
#define XK_KP_Up                         0xff97
#define XK_KP_Right                      0xff98
#define XK_KP_Down                       0xff99
#define XK_KP_Prior                      0xff9a
#define XK_KP_Page_Up                    0xff9a  /* deprecated alias for KP_Prior */
#define XK_KP_Next                       0xff9b
#define XK_KP_Page_Down                  0xff9b  /* deprecated alias for KP_Next */
#define XK_KP_End                        0xff9c
#define XK_KP_Begin                      0xff9d
#define XK_KP_Insert                     0xff9e
#define XK_KP_Delete                     0xff9f
#define XK_KP_Equal                      0xffbd  /*<U+003D EQUALS SIGN>*/
#define XK_KP_Multiply                   0xffaa  /*<U+002A ASTERISK>*/
#define XK_KP_Add                        0xffab  /*<U+002B PLUS SIGN>*/
#define XK_KP_Separator                  0xffac  /*<U+002C COMMA>*/
#define XK_KP_Subtract                   0xffad  /*<U+002D HYPHEN-MINUS>*/
#define XK_KP_Decimal                    0xffae  /*<U+002E FULL STOP>*/
#define XK_KP_Divide                     0xffaf  /*<U+002F SOLIDUS>*/
#define XK_KP_Space		0xFF80	/* space */
#define XK_KP_Tab		0xFF89
#define XK_KP_Enter		0xFF8D	/* enter */
#define XK_KP_F1		0xFF91	/* PF1, KP_A, ... */
#define XK_KP_F2		0xFF92
#define XK_KP_F3		0xFF93
#define XK_KP_F4		0xFF94
#define XK_KP_Home		0xFF95
#define XK_KP_Left		0xFF96
#define XK_KP_Up		0xFF97
#define XK_KP_Right		0xFF98
#define XK_KP_Down		0xFF99
#define XK_KP_Prior		0xFF9A
#define XK_KP_Page_Up		0xFF9A
#define XK_KP_Next		0xFF9B
#define XK_KP_Page_Down		0xFF9B
#define XK_KP_End		0xFF9C
#define XK_KP_Begin		0xFF9D
#define XK_KP_Insert		0xFF9E
#define XK_KP_Delete		0xFF9F
#define XK_KP_Equal		0xFFBD	/* equals */
#define XK_KP_Multiply		0xFFAA
#define XK_KP_Add		0xFFAB
#define XK_KP_Separator		0xFFAC	/* separator, often comma */
#define XK_KP_Subtract		0xFFAD
#define XK_KP_Decimal		0xFFAE
#define XK_KP_Divide		0xFFAF

#define XK_KP_0                          0xffb0  /*<U+0030 DIGIT ZERO>*/
#define XK_KP_1                          0xffb1  /*<U+0031 DIGIT ONE>*/
#define XK_KP_2                          0xffb2  /*<U+0032 DIGIT TWO>*/
#define XK_KP_3                          0xffb3  /*<U+0033 DIGIT THREE>*/
#define XK_KP_4                          0xffb4  /*<U+0034 DIGIT FOUR>*/
#define XK_KP_5                          0xffb5  /*<U+0035 DIGIT FIVE>*/
#define XK_KP_6                          0xffb6  /*<U+0036 DIGIT SIX>*/
#define XK_KP_7                          0xffb7  /*<U+0037 DIGIT SEVEN>*/
#define XK_KP_8                          0xffb8  /*<U+0038 DIGIT EIGHT>*/
#define XK_KP_9                          0xffb9  /*<U+0039 DIGIT NINE>*/
#define XK_KP_0			0xFFB0
#define XK_KP_1			0xFFB1
#define XK_KP_2			0xFFB2
#define XK_KP_3			0xFFB3
#define XK_KP_4			0xFFB4
#define XK_KP_5			0xFFB5
#define XK_KP_6			0xFFB6
#define XK_KP_7			0xFFB7
#define XK_KP_8			0xFFB8
#define XK_KP_9			0xFFB9



/*
 * Auxiliary functions; note the duplicate definitions for left and right
 * function keys;  Sun keyboards and a few other manufacturers have such
 * Auxilliary Functions; note the duplicate definitions for left and right
 * function keys;  Sun keyboards and a few other manufactures have such
 * function key groups on the left and/or right sides of the keyboard.
 * We've not found a keyboard with more than 35 function keys total.
 */

#define XK_F1                            0xffbe
#define XK_F2                            0xffbf
#define XK_F3                            0xffc0
#define XK_F4                            0xffc1
#define XK_F5                            0xffc2
#define XK_F6                            0xffc3
#define XK_F7                            0xffc4
#define XK_F8                            0xffc5
#define XK_F9                            0xffc6
#define XK_F10                           0xffc7
#define XK_F11                           0xffc8
#define XK_L1                            0xffc8  /* deprecated alias for F11 */
#define XK_F12                           0xffc9
#define XK_L2                            0xffc9  /* deprecated alias for F12 */
#define XK_F13                           0xffca
#define XK_L3                            0xffca  /* deprecated alias for F13 */
#define XK_F14                           0xffcb
#define XK_L4                            0xffcb  /* deprecated alias for F14 */
#define XK_F15                           0xffcc
#define XK_L5                            0xffcc  /* deprecated alias for F15 */
#define XK_F16                           0xffcd
#define XK_L6                            0xffcd  /* deprecated alias for F16 */
#define XK_F17                           0xffce
#define XK_L7                            0xffce  /* deprecated alias for F17 */
#define XK_F18                           0xffcf
#define XK_L8                            0xffcf  /* deprecated alias for F18 */
#define XK_F19                           0xffd0
#define XK_L9                            0xffd0  /* deprecated alias for F19 */
#define XK_F20                           0xffd1
#define XK_L10                           0xffd1  /* deprecated alias for F20 */
#define XK_F21                           0xffd2
#define XK_R1                            0xffd2  /* deprecated alias for F21 */
#define XK_F22                           0xffd3
#define XK_R2                            0xffd3  /* deprecated alias for F22 */
#define XK_F23                           0xffd4
#define XK_R3                            0xffd4  /* deprecated alias for F23 */
#define XK_F24                           0xffd5
#define XK_R4                            0xffd5  /* deprecated alias for F24 */
#define XK_F25                           0xffd6
#define XK_R5                            0xffd6  /* deprecated alias for F25 */
#define XK_F26                           0xffd7
#define XK_R6                            0xffd7  /* deprecated alias for F26 */
#define XK_F27                           0xffd8
#define XK_R7                            0xffd8  /* deprecated alias for F27 */
#define XK_F28                           0xffd9
#define XK_R8                            0xffd9  /* deprecated alias for F28 */
#define XK_F29                           0xffda
#define XK_R9                            0xffda  /* deprecated alias for F29 */
#define XK_F30                           0xffdb
#define XK_R10                           0xffdb  /* deprecated alias for F30 */
#define XK_F31                           0xffdc
#define XK_R11                           0xffdc  /* deprecated alias for F31 */
#define XK_F32                           0xffdd
#define XK_R12                           0xffdd  /* deprecated alias for F32 */
#define XK_F33                           0xffde
#define XK_R13                           0xffde  /* deprecated alias for F33 */
#define XK_F34                           0xffdf
#define XK_R14                           0xffdf  /* deprecated alias for F34 */
#define XK_F35                           0xffe0
#define XK_R15                           0xffe0  /* deprecated alias for F35 */
#define XK_F1			0xFFBE
#define XK_F2			0xFFBF
#define XK_F3			0xFFC0
#define XK_F4			0xFFC1
#define XK_F5			0xFFC2
#define XK_F6			0xFFC3
#define XK_F7			0xFFC4
#define XK_F8			0xFFC5
#define XK_F9			0xFFC6
#define XK_F10			0xFFC7
#define XK_F11			0xFFC8
#define XK_L1			0xFFC8
#define XK_F12			0xFFC9
#define XK_L2			0xFFC9
#define XK_F13			0xFFCA
#define XK_L3			0xFFCA
#define XK_F14			0xFFCB
#define XK_L4			0xFFCB
#define XK_F15			0xFFCC
#define XK_L5			0xFFCC
#define XK_F16			0xFFCD
#define XK_L6			0xFFCD
#define XK_F17			0xFFCE
#define XK_L7			0xFFCE
#define XK_F18			0xFFCF
#define XK_L8			0xFFCF
#define XK_F19			0xFFD0
#define XK_L9			0xFFD0
#define XK_F20			0xFFD1
#define XK_L10			0xFFD1
#define XK_F21			0xFFD2
#define XK_R1			0xFFD2
#define XK_F22			0xFFD3
#define XK_R2			0xFFD3
#define XK_F23			0xFFD4
#define XK_R3			0xFFD4
#define XK_F24			0xFFD5
#define XK_R4			0xFFD5
#define XK_F25			0xFFD6
#define XK_R5			0xFFD6
#define XK_F26			0xFFD7
#define XK_R6			0xFFD7
#define XK_F27			0xFFD8
#define XK_R7			0xFFD8
#define XK_F28			0xFFD9
#define XK_R8			0xFFD9
#define XK_F29			0xFFDA
#define XK_R9			0xFFDA
#define XK_F30			0xFFDB
#define XK_R10			0xFFDB
#define XK_F31			0xFFDC
#define XK_R11			0xFFDC
#define XK_F32			0xFFDD
#define XK_R12			0xFFDD
#define XK_F33			0xFFDE
#define XK_R13			0xFFDE
#define XK_F34			0xFFDF
#define XK_R14			0xFFDF
#define XK_F35			0xFFE0
#define XK_R15			0xFFE0

/* Modifiers */

#define XK_Shift_L                       0xffe1  /* Left shift */
#define XK_Shift_R                       0xffe2  /* Right shift */
#define XK_Control_L                     0xffe3  /* Left control */
#define XK_Control_R                     0xffe4  /* Right control */
#define XK_Caps_Lock                     0xffe5  /* Caps lock */
#define XK_Shift_Lock                    0xffe6  /* Shift lock */
#define XK_Shift_L		0xFFE1	/* Left shift */
#define XK_Shift_R		0xFFE2	/* Right shift */
#define XK_Control_L		0xFFE3	/* Left control */
#define XK_Control_R		0xFFE4	/* Right control */
#define XK_Caps_Lock		0xFFE5	/* Caps lock */
#define XK_Shift_Lock		0xFFE6	/* Shift lock */

#define XK_Meta_L                        0xffe7  /* Left meta */
#define XK_Meta_R                        0xffe8  /* Right meta */
#define XK_Alt_L                         0xffe9  /* Left alt */
#define XK_Alt_R                         0xffea  /* Right alt */
#define XK_Super_L                       0xffeb  /* Left super */
#define XK_Super_R                       0xffec  /* Right super */
#define XK_Hyper_L                       0xffed  /* Left hyper */
#define XK_Hyper_R                       0xffee  /* Right hyper */
#define XK_Meta_L		0xFFE7	/* Left meta */
#define XK_Meta_R		0xFFE8	/* Right meta */
#define XK_Alt_L		0xFFE9	/* Left alt */
#define XK_Alt_R		0xFFEA	/* Right alt */
#define XK_Super_L		0xFFEB	/* Left super */
#define XK_Super_R		0xFFEC	/* Right super */
#define XK_Hyper_L		0xFFED	/* Left hyper */
#define XK_Hyper_R		0xFFEE	/* Right hyper */
#endif /* XK_MISCELLANY */

/*
 * Keyboard (XKB) Extension function and modifier keys
 * (from Appendix C of "The X Keyboard Extension: Protocol Specification")
 * Byte 3 = 0xfe
 */

#ifdef XK_XKB_KEYS
#define XK_ISO_Lock                      0xfe01
#define XK_ISO_Level2_Latch              0xfe02
#define XK_ISO_Level3_Shift              0xfe03
#define XK_ISO_Level3_Latch              0xfe04
#define XK_ISO_Level3_Lock               0xfe05
#define XK_ISO_Level5_Shift              0xfe11
#define XK_ISO_Level5_Latch              0xfe12
#define XK_ISO_Level5_Lock               0xfe13
#define XK_ISO_Group_Shift               0xff7e  /* non-deprecated alias for Mode_switch */
#define XK_ISO_Group_Latch               0xfe06
#define XK_ISO_Group_Lock                0xfe07
#define XK_ISO_Next_Group                0xfe08
#define XK_ISO_Next_Group_Lock           0xfe09
#define XK_ISO_Prev_Group                0xfe0a
#define XK_ISO_Prev_Group_Lock           0xfe0b
#define XK_ISO_First_Group               0xfe0c
#define XK_ISO_First_Group_Lock          0xfe0d
#define XK_ISO_Last_Group                0xfe0e
#define XK_ISO_Last_Group_Lock           0xfe0f

#define XK_ISO_Left_Tab                  0xfe20
#define XK_ISO_Move_Line_Up              0xfe21
#define XK_ISO_Move_Line_Down            0xfe22
#define XK_ISO_Partial_Line_Up           0xfe23
#define XK_ISO_Partial_Line_Down         0xfe24
#define XK_ISO_Partial_Space_Left        0xfe25
#define XK_ISO_Partial_Space_Right       0xfe26
#define XK_ISO_Set_Margin_Left           0xfe27
#define XK_ISO_Set_Margin_Right          0xfe28
#define XK_ISO_Release_Margin_Left       0xfe29
#define XK_ISO_Release_Margin_Right      0xfe2a
#define XK_ISO_Release_Both_Margins      0xfe2b
#define XK_ISO_Fast_Cursor_Left          0xfe2c
#define XK_ISO_Fast_Cursor_Right         0xfe2d
#define XK_ISO_Fast_Cursor_Up            0xfe2e
#define XK_ISO_Fast_Cursor_Down          0xfe2f
#define XK_ISO_Continuous_Underline      0xfe30
#define XK_ISO_Discontinuous_Underline   0xfe31
#define XK_ISO_Emphasize                 0xfe32
#define XK_ISO_Center_Object             0xfe33
#define XK_ISO_Enter                     0xfe34

#define XK_dead_grave                    0xfe50
#define XK_dead_acute                    0xfe51
#define XK_dead_circumflex               0xfe52
#define XK_dead_tilde                    0xfe53
#define XK_dead_perispomeni              0xfe53  /* non-deprecated alias for dead_tilde */
#define XK_dead_macron                   0xfe54
#define XK_dead_breve                    0xfe55
#define XK_dead_abovedot                 0xfe56
#define XK_dead_diaeresis                0xfe57
#define XK_dead_abovering                0xfe58
#define XK_dead_doubleacute              0xfe59
#define XK_dead_caron                    0xfe5a
#define XK_dead_cedilla                  0xfe5b
#define XK_dead_ogonek                   0xfe5c
#define XK_dead_iota                     0xfe5d
#define XK_dead_voiced_sound             0xfe5e
#define XK_dead_semivoiced_sound         0xfe5f
#define XK_dead_belowdot                 0xfe60
#define XK_dead_hook                     0xfe61
#define XK_dead_horn                     0xfe62
#define XK_dead_stroke                   0xfe63
#define XK_dead_abovecomma               0xfe64
#define XK_dead_psili                    0xfe64  /* non-deprecated alias for dead_abovecomma */
#define XK_dead_abovereversedcomma       0xfe65
#define XK_dead_dasia                    0xfe65  /* non-deprecated alias for dead_abovereversedcomma */
#define XK_dead_doublegrave              0xfe66
#define XK_dead_belowring                0xfe67
#define XK_dead_belowmacron              0xfe68
#define XK_dead_belowcircumflex          0xfe69
#define XK_dead_belowtilde               0xfe6a
#define XK_dead_belowbreve               0xfe6b
#define XK_dead_belowdiaeresis           0xfe6c
#define XK_dead_invertedbreve            0xfe6d
#define XK_dead_belowcomma               0xfe6e
#define XK_dead_currency                 0xfe6f

/* extra dead elements for German T3 layout */
#define XK_dead_lowline                  0xfe90
#define XK_dead_aboveverticalline        0xfe91
#define XK_dead_belowverticalline        0xfe92
#define XK_dead_longsolidusoverlay       0xfe93

/* dead vowels for universal syllable entry */
#define XK_dead_a                        0xfe80
#define XK_dead_A                        0xfe81
#define XK_dead_e                        0xfe82
#define XK_dead_E                        0xfe83
#define XK_dead_i                        0xfe84
#define XK_dead_I                        0xfe85
#define XK_dead_o                        0xfe86
#define XK_dead_O                        0xfe87
#define XK_dead_u                        0xfe88
#define XK_dead_U                        0xfe89
#define XK_dead_small_schwa              0xfe8a  /* deprecated alias for dead_schwa */
#define XK_dead_schwa                    0xfe8a
#define XK_dead_capital_schwa            0xfe8b  /* deprecated alias for dead_SCHWA */
#define XK_dead_SCHWA                    0xfe8b

#define XK_dead_greek                    0xfe8c
#define XK_dead_hamza                    0xfe8d

#define XK_First_Virtual_Screen          0xfed0
#define XK_Prev_Virtual_Screen           0xfed1
#define XK_Next_Virtual_Screen           0xfed2
#define XK_Last_Virtual_Screen           0xfed4
#define XK_Terminate_Server              0xfed5

#define XK_AccessX_Enable                0xfe70
#define XK_AccessX_Feedback_Enable       0xfe71
#define XK_RepeatKeys_Enable             0xfe72
#define XK_SlowKeys_Enable               0xfe73
#define XK_BounceKeys_Enable             0xfe74
#define XK_StickyKeys_Enable             0xfe75
#define XK_MouseKeys_Enable              0xfe76
#define XK_MouseKeys_Accel_Enable        0xfe77
#define XK_Overlay1_Enable               0xfe78
#define XK_Overlay2_Enable               0xfe79
#define XK_AudibleBell_Enable            0xfe7a

#define XK_Pointer_Left                  0xfee0
#define XK_Pointer_Right                 0xfee1
#define XK_Pointer_Up                    0xfee2
#define XK_Pointer_Down                  0xfee3
#define XK_Pointer_UpLeft                0xfee4
#define XK_Pointer_UpRight               0xfee5
#define XK_Pointer_DownLeft              0xfee6
#define XK_Pointer_DownRight             0xfee7
#define XK_Pointer_Button_Dflt           0xfee8
#define XK_Pointer_Button1               0xfee9
#define XK_Pointer_Button2               0xfeea
#define XK_Pointer_Button3               0xfeeb
#define XK_Pointer_Button4               0xfeec
#define XK_Pointer_Button5               0xfeed
#define XK_Pointer_DblClick_Dflt         0xfeee
#define XK_Pointer_DblClick1             0xfeef
#define XK_Pointer_DblClick2             0xfef0
#define XK_Pointer_DblClick3             0xfef1
#define XK_Pointer_DblClick4             0xfef2
#define XK_Pointer_DblClick5             0xfef3
#define XK_Pointer_Drag_Dflt             0xfef4
#define XK_Pointer_Drag1                 0xfef5
#define XK_Pointer_Drag2                 0xfef6
#define XK_Pointer_Drag3                 0xfef7
#define XK_Pointer_Drag4                 0xfef8
#define XK_Pointer_Drag5                 0xfefd

#define XK_Pointer_EnableKeys            0xfef9
#define XK_Pointer_Accelerate            0xfefa
#define XK_Pointer_DfltBtnNext           0xfefb
#define XK_Pointer_DfltBtnPrev           0xfefc

/* Single-Stroke Multiple-Character N-Graph Keysyms For The X Input Method */

#define XK_ch                            0xfea0
#define XK_Ch                            0xfea1
#define XK_CH                            0xfea2
#define XK_c_h                           0xfea3
#define XK_C_h                           0xfea4
#define XK_C_H                           0xfea5

#endif /* XK_XKB_KEYS */

/*
 * 3270 Terminal Keys
 * Byte 3 = 0xfd
 */

#ifdef XK_3270
#define XK_3270_Duplicate                0xfd01
#define XK_3270_FieldMark                0xfd02
#define XK_3270_Right2                   0xfd03
#define XK_3270_Left2                    0xfd04
#define XK_3270_BackTab                  0xfd05
#define XK_3270_EraseEOF                 0xfd06
#define XK_3270_EraseInput               0xfd07
#define XK_3270_Reset                    0xfd08
#define XK_3270_Quit                     0xfd09
#define XK_3270_PA1                      0xfd0a
#define XK_3270_PA2                      0xfd0b
#define XK_3270_PA3                      0xfd0c
#define XK_3270_Test                     0xfd0d
#define XK_3270_Attn                     0xfd0e
#define XK_3270_CursorBlink              0xfd0f
#define XK_3270_AltCursor                0xfd10
#define XK_3270_KeyClick                 0xfd11
#define XK_3270_Jump                     0xfd12
#define XK_3270_Ident                    0xfd13
#define XK_3270_Rule                     0xfd14
#define XK_3270_Copy                     0xfd15
#define XK_3270_Play                     0xfd16
#define XK_3270_Setup                    0xfd17
#define XK_3270_Record                   0xfd18
#define XK_3270_ChangeScreen             0xfd19
#define XK_3270_DeleteWord               0xfd1a
#define XK_3270_ExSelect                 0xfd1b
#define XK_3270_CursorSelect             0xfd1c
#define XK_3270_PrintScreen              0xfd1d
#define XK_3270_Enter                    0xfd1e
#endif /* XK_3270 */

/*
 * Latin 1
 *  Latin 1
 * (ISO/IEC 8859-1 = Unicode U+0020..U+00FF)
 * Byte 3 = 0
 *  Byte 3 = 0
 */
#ifdef XK_LATIN1
#define XK_space                         0x0020  /* U+0020 SPACE */
#define XK_exclam                        0x0021  /* U+0021 EXCLAMATION MARK */
#define XK_quotedbl                      0x0022  /* U+0022 QUOTATION MARK */
#define XK_numbersign                    0x0023  /* U+0023 NUMBER SIGN */
#define XK_dollar                        0x0024  /* U+0024 DOLLAR SIGN */
#define XK_percent                       0x0025  /* U+0025 PERCENT SIGN */
#define XK_ampersand                     0x0026  /* U+0026 AMPERSAND */
#define XK_apostrophe                    0x0027  /* U+0027 APOSTROPHE */
#define XK_quoteright                    0x0027  /* deprecated */
#define XK_parenleft                     0x0028  /* U+0028 LEFT PARENTHESIS */
#define XK_parenright                    0x0029  /* U+0029 RIGHT PARENTHESIS */
#define XK_asterisk                      0x002a  /* U+002A ASTERISK */
#define XK_plus                          0x002b  /* U+002B PLUS SIGN */
#define XK_comma                         0x002c  /* U+002C COMMA */
#define XK_minus                         0x002d  /* U+002D HYPHEN-MINUS */
#define XK_period                        0x002e  /* U+002E FULL STOP */
#define XK_slash                         0x002f  /* U+002F SOLIDUS */
#define XK_0                             0x0030  /* U+0030 DIGIT ZERO */
#define XK_1                             0x0031  /* U+0031 DIGIT ONE */
#define XK_2                             0x0032  /* U+0032 DIGIT TWO */
#define XK_3                             0x0033  /* U+0033 DIGIT THREE */
#define XK_4                             0x0034  /* U+0034 DIGIT FOUR */
#define XK_5                             0x0035  /* U+0035 DIGIT FIVE */
#define XK_6                             0x0036  /* U+0036 DIGIT SIX */
#define XK_7                             0x0037  /* U+0037 DIGIT SEVEN */
#define XK_8                             0x0038  /* U+0038 DIGIT EIGHT */
#define XK_9                             0x0039  /* U+0039 DIGIT NINE */
#define XK_colon                         0x003a  /* U+003A COLON */
#define XK_semicolon                     0x003b  /* U+003B SEMICOLON */
#define XK_less                          0x003c  /* U+003C LESS-THAN SIGN */
#define XK_equal                         0x003d  /* U+003D EQUALS SIGN */
#define XK_greater                       0x003e  /* U+003E GREATER-THAN SIGN */
#define XK_question                      0x003f  /* U+003F QUESTION MARK */
#define XK_at                            0x0040  /* U+0040 COMMERCIAL AT */
#define XK_A                             0x0041  /* U+0041 LATIN CAPITAL LETTER A */
#define XK_B                             0x0042  /* U+0042 LATIN CAPITAL LETTER B */
#define XK_C                             0x0043  /* U+0043 LATIN CAPITAL LETTER C */
#define XK_D                             0x0044  /* U+0044 LATIN CAPITAL LETTER D */
#define XK_E                             0x0045  /* U+0045 LATIN CAPITAL LETTER E */
#define XK_F                             0x0046  /* U+0046 LATIN CAPITAL LETTER F */
#define XK_G                             0x0047  /* U+0047 LATIN CAPITAL LETTER G */
#define XK_H                             0x0048  /* U+0048 LATIN CAPITAL LETTER H */
#define XK_I                             0x0049  /* U+0049 LATIN CAPITAL LETTER I */
#define XK_J                             0x004a  /* U+004A LATIN CAPITAL LETTER J */
#define XK_K                             0x004b  /* U+004B LATIN CAPITAL LETTER K */
#define XK_L                             0x004c  /* U+004C LATIN CAPITAL LETTER L */
#define XK_M                             0x004d  /* U+004D LATIN CAPITAL LETTER M */
#define XK_N                             0x004e  /* U+004E LATIN CAPITAL LETTER N */
#define XK_O                             0x004f  /* U+004F LATIN CAPITAL LETTER O */
#define XK_P                             0x0050  /* U+0050 LATIN CAPITAL LETTER P */
#define XK_Q                             0x0051  /* U+0051 LATIN CAPITAL LETTER Q */
#define XK_R                             0x0052  /* U+0052 LATIN CAPITAL LETTER R */
#define XK_S                             0x0053  /* U+0053 LATIN CAPITAL LETTER S */
#define XK_T                             0x0054  /* U+0054 LATIN CAPITAL LETTER T */
#define XK_U                             0x0055  /* U+0055 LATIN CAPITAL LETTER U */
#define XK_V                             0x0056  /* U+0056 LATIN CAPITAL LETTER V */
#define XK_W                             0x0057  /* U+0057 LATIN CAPITAL LETTER W */
#define XK_X                             0x0058  /* U+0058 LATIN CAPITAL LETTER X */
#define XK_Y                             0x0059  /* U+0059 LATIN CAPITAL LETTER Y */
#define XK_Z                             0x005a  /* U+005A LATIN CAPITAL LETTER Z */
#define XK_bracketleft                   0x005b  /* U+005B LEFT SQUARE BRACKET */
#define XK_backslash                     0x005c  /* U+005C REVERSE SOLIDUS */
#define XK_bracketright                  0x005d  /* U+005D RIGHT SQUARE BRACKET */
#define XK_asciicircum                   0x005e  /* U+005E CIRCUMFLEX ACCENT */
#define XK_underscore                    0x005f  /* U+005F LOW LINE */
#define XK_grave                         0x0060  /* U+0060 GRAVE ACCENT */
#define XK_quoteleft                     0x0060  /* deprecated */
#define XK_a                             0x0061  /* U+0061 LATIN SMALL LETTER A */
#define XK_b                             0x0062  /* U+0062 LATIN SMALL LETTER B */
#define XK_c                             0x0063  /* U+0063 LATIN SMALL LETTER C */
#define XK_d                             0x0064  /* U+0064 LATIN SMALL LETTER D */
#define XK_e                             0x0065  /* U+0065 LATIN SMALL LETTER E */
#define XK_f                             0x0066  /* U+0066 LATIN SMALL LETTER F */
#define XK_g                             0x0067  /* U+0067 LATIN SMALL LETTER G */
#define XK_h                             0x0068  /* U+0068 LATIN SMALL LETTER H */
#define XK_i                             0x0069  /* U+0069 LATIN SMALL LETTER I */
#define XK_j                             0x006a  /* U+006A LATIN SMALL LETTER J */
#define XK_k                             0x006b  /* U+006B LATIN SMALL LETTER K */
#define XK_l                             0x006c  /* U+006C LATIN SMALL LETTER L */
#define XK_m                             0x006d  /* U+006D LATIN SMALL LETTER M */
#define XK_n                             0x006e  /* U+006E LATIN SMALL LETTER N */
#define XK_o                             0x006f  /* U+006F LATIN SMALL LETTER O */
#define XK_p                             0x0070  /* U+0070 LATIN SMALL LETTER P */
#define XK_q                             0x0071  /* U+0071 LATIN SMALL LETTER Q */
#define XK_r                             0x0072  /* U+0072 LATIN SMALL LETTER R */
#define XK_s                             0x0073  /* U+0073 LATIN SMALL LETTER S */
#define XK_t                             0x0074  /* U+0074 LATIN SMALL LETTER T */
#define XK_u                             0x0075  /* U+0075 LATIN SMALL LETTER U */
#define XK_v                             0x0076  /* U+0076 LATIN SMALL LETTER V */
#define XK_w                             0x0077  /* U+0077 LATIN SMALL LETTER W */
#define XK_x                             0x0078  /* U+0078 LATIN SMALL LETTER X */
#define XK_y                             0x0079  /* U+0079 LATIN SMALL LETTER Y */
#define XK_z                             0x007a  /* U+007A LATIN SMALL LETTER Z */
#define XK_braceleft                     0x007b  /* U+007B LEFT CURLY BRACKET */
#define XK_bar                           0x007c  /* U+007C VERTICAL LINE */
#define XK_braceright                    0x007d  /* U+007D RIGHT CURLY BRACKET */
#define XK_asciitilde                    0x007e  /* U+007E TILDE */
#define XK_space               0x020
#define XK_exclam              0x021
#define XK_quotedbl            0x022
#define XK_numbersign          0x023
#define XK_dollar              0x024
#define XK_percent             0x025
#define XK_ampersand           0x026
#define XK_apostrophe          0x027
#define XK_quoteright          0x027	/* deprecated */
#define XK_parenleft           0x028
#define XK_parenright          0x029
#define XK_asterisk            0x02a
#define XK_plus                0x02b
#define XK_comma               0x02c
#define XK_minus               0x02d
#define XK_period              0x02e
#define XK_slash               0x02f
#define XK_0                   0x030
#define XK_1                   0x031
#define XK_2                   0x032
#define XK_3                   0x033
#define XK_4                   0x034
#define XK_5                   0x035
#define XK_6                   0x036
#define XK_7                   0x037
#define XK_8                   0x038
#define XK_9                   0x039
#define XK_colon               0x03a
#define XK_semicolon           0x03b
#define XK_less                0x03c
#define XK_equal               0x03d
#define XK_greater             0x03e
#define XK_question            0x03f
#define XK_at                  0x040
#define XK_A                   0x041
#define XK_B                   0x042
#define XK_C                   0x043
#define XK_D                   0x044
#define XK_E                   0x045
#define XK_F                   0x046
#define XK_G                   0x047
#define XK_H                   0x048
#define XK_I                   0x049
#define XK_J                   0x04a
#define XK_K                   0x04b
#define XK_L                   0x04c
#define XK_M                   0x04d
#define XK_N                   0x04e
#define XK_O                   0x04f
#define XK_P                   0x050
#define XK_Q                   0x051
#define XK_R                   0x052
#define XK_S                   0x053
#define XK_T                   0x054
#define XK_U                   0x055
#define XK_V                   0x056
#define XK_W                   0x057
#define XK_X                   0x058
#define XK_Y                   0x059
#define XK_Z                   0x05a
#define XK_bracketleft         0x05b
#define XK_backslash           0x05c
#define XK_bracketright        0x05d
#define XK_asciicircum         0x05e
#define XK_underscore          0x05f
#define XK_grave               0x060
#define XK_quoteleft           0x060	/* deprecated */
#define XK_a                   0x061
#define XK_b                   0x062
#define XK_c                   0x063
#define XK_d                   0x064
#define XK_e                   0x065
#define XK_f                   0x066
#define XK_g                   0x067
#define XK_h                   0x068
#define XK_i                   0x069
#define XK_j                   0x06a
#define XK_k                   0x06b
#define XK_l                   0x06c
#define XK_m                   0x06d
#define XK_n                   0x06e
#define XK_o                   0x06f
#define XK_p                   0x070
#define XK_q                   0x071
#define XK_r                   0x072
#define XK_s                   0x073
#define XK_t                   0x074
#define XK_u                   0x075
#define XK_v                   0x076
#define XK_w                   0x077
#define XK_x                   0x078
#define XK_y                   0x079
#define XK_z                   0x07a
#define XK_braceleft           0x07b
#define XK_bar                 0x07c
#define XK_braceright          0x07d
#define XK_asciitilde          0x07e

#define XK_nobreakspace                  0x00a0  /* U+00A0 NO-BREAK SPACE */
#define XK_exclamdown                    0x00a1  /* U+00A1 INVERTED EXCLAMATION MARK */
#define XK_cent                          0x00a2  /* U+00A2 CENT SIGN */
#define XK_sterling                      0x00a3  /* U+00A3 POUND SIGN */
#define XK_currency                      0x00a4  /* U+00A4 CURRENCY SIGN */
#define XK_yen                           0x00a5  /* U+00A5 YEN SIGN */
#define XK_brokenbar                     0x00a6  /* U+00A6 BROKEN BAR */
#define XK_section                       0x00a7  /* U+00A7 SECTION SIGN */
#define XK_diaeresis                     0x00a8  /* U+00A8 DIAERESIS */
#define XK_copyright                     0x00a9  /* U+00A9 COPYRIGHT SIGN */
#define XK_ordfeminine                   0x00aa  /* U+00AA FEMININE ORDINAL INDICATOR */
#define XK_guillemotleft                 0x00ab  /* deprecated alias for guillemetleft (misspelling) */
#define XK_nobreakspace        0x0a0
#define XK_exclamdown          0x0a1
#define XK_cent        	       0x0a2
#define XK_sterling            0x0a3
#define XK_currency            0x0a4
#define XK_yen                 0x0a5
#define XK_brokenbar           0x0a6
#define XK_section             0x0a7
#define XK_diaeresis           0x0a8
#define XK_copyright           0x0a9
#define XK_ordfeminine         0x0aa
#define XK_guillemotleft       0x0ab	/* left angle quotation mark */
#define XK_guillemetleft                 0x00ab  /* U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK */
#define XK_notsign                       0x00ac  /* U+00AC NOT SIGN */
#define XK_hyphen                        0x00ad  /* U+00AD SOFT HYPHEN */
#define XK_registered                    0x00ae  /* U+00AE REGISTERED SIGN */
#define XK_macron                        0x00af  /* U+00AF MACRON */
#define XK_degree                        0x00b0  /* U+00B0 DEGREE SIGN */
#define XK_plusminus                     0x00b1  /* U+00B1 PLUS-MINUS SIGN */
#define XK_twosuperior                   0x00b2  /* U+00B2 SUPERSCRIPT TWO */
#define XK_threesuperior                 0x00b3  /* U+00B3 SUPERSCRIPT THREE */
#define XK_acute                         0x00b4  /* U+00B4 ACUTE ACCENT */
#define XK_mu                            0x00b5  /* U+00B5 MICRO SIGN */
#define XK_paragraph                     0x00b6  /* U+00B6 PILCROW SIGN */
#define XK_periodcentered                0x00b7  /* U+00B7 MIDDLE DOT */
#define XK_cedilla                       0x00b8  /* U+00B8 CEDILLA */
#define XK_onesuperior                   0x00b9  /* U+00B9 SUPERSCRIPT ONE */
#define XK_masculine                     0x00ba  /* deprecated alias for ordmasculine (inconsistent name) */
#define XK_notsign             0x0ac
#define XK_hyphen              0x0ad
#define XK_registered          0x0ae
#define XK_macron              0x0af
#define XK_degree              0x0b0
#define XK_plusminus           0x0b1
#define XK_twosuperior         0x0b2
#define XK_threesuperior       0x0b3
#define XK_acute               0x0b4
#define XK_mu                  0x0b5
#define XK_paragraph           0x0b6
#define XK_periodcentered      0x0b7
#define XK_cedilla             0x0b8
#define XK_onesuperior         0x0b9
#define XK_masculine           0x0ba
#define XK_ordmasculine                  0x00ba  /* U+00BA MASCULINE ORDINAL INDICATOR */
#define XK_guillemotright                0x00bb  /* deprecated alias for guillemetright (misspelling) */
#define XK_guillemotright      0x0bb	/* right angle quotation mark */
#define XK_guillemetright                0x00bb  /* U+00BB RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK */
#define XK_onequarter                    0x00bc  /* U+00BC VULGAR FRACTION ONE QUARTER */
#define XK_onehalf                       0x00bd  /* U+00BD VULGAR FRACTION ONE HALF */
#define XK_threequarters                 0x00be  /* U+00BE VULGAR FRACTION THREE QUARTERS */
#define XK_questiondown                  0x00bf  /* U+00BF INVERTED QUESTION MARK */
#define XK_Agrave                        0x00c0  /* U+00C0 LATIN CAPITAL LETTER A WITH GRAVE */
#define XK_Aacute                        0x00c1  /* U+00C1 LATIN CAPITAL LETTER A WITH ACUTE */
#define XK_Acircumflex                   0x00c2  /* U+00C2 LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
#define XK_Atilde                        0x00c3  /* U+00C3 LATIN CAPITAL LETTER A WITH TILDE */
#define XK_Adiaeresis                    0x00c4  /* U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS */
#define XK_Aring                         0x00c5  /* U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE */
#define XK_AE                            0x00c6  /* U+00C6 LATIN CAPITAL LETTER AE */
#define XK_Ccedilla                      0x00c7  /* U+00C7 LATIN CAPITAL LETTER C WITH CEDILLA */
#define XK_Egrave                        0x00c8  /* U+00C8 LATIN CAPITAL LETTER E WITH GRAVE */
#define XK_Eacute                        0x00c9  /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
#define XK_Ecircumflex                   0x00ca  /* U+00CA LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
#define XK_Ediaeresis                    0x00cb  /* U+00CB LATIN CAPITAL LETTER E WITH DIAERESIS */
#define XK_Igrave                        0x00cc  /* U+00CC LATIN CAPITAL LETTER I WITH GRAVE */
#define XK_Iacute                        0x00cd  /* U+00CD LATIN CAPITAL LETTER I WITH ACUTE */
#define XK_Icircumflex                   0x00ce  /* U+00CE LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
#define XK_Idiaeresis                    0x00cf  /* U+00CF LATIN CAPITAL LETTER I WITH DIAERESIS */
#define XK_ETH                           0x00d0  /* U+00D0 LATIN CAPITAL LETTER ETH */
#define XK_Eth                           0x00d0  /* deprecated */
#define XK_Ntilde                        0x00d1  /* U+00D1 LATIN CAPITAL LETTER N WITH TILDE */
#define XK_Ograve                        0x00d2  /* U+00D2 LATIN CAPITAL LETTER O WITH GRAVE */
#define XK_Oacute                        0x00d3  /* U+00D3 LATIN CAPITAL LETTER O WITH ACUTE */
#define XK_Ocircumflex                   0x00d4  /* U+00D4 LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
#define XK_Otilde                        0x00d5  /* U+00D5 LATIN CAPITAL LETTER O WITH TILDE */
#define XK_Odiaeresis                    0x00d6  /* U+00D6 LATIN CAPITAL LETTER O WITH DIAERESIS */
#define XK_multiply                      0x00d7  /* U+00D7 MULTIPLICATION SIGN */
#define XK_onequarter          0x0bc
#define XK_onehalf             0x0bd
#define XK_threequarters       0x0be
#define XK_questiondown        0x0bf
#define XK_Agrave              0x0c0
#define XK_Aacute              0x0c1
#define XK_Acircumflex         0x0c2
#define XK_Atilde              0x0c3
#define XK_Adiaeresis          0x0c4
#define XK_Aring               0x0c5
#define XK_AE                  0x0c6
#define XK_Ccedilla            0x0c7
#define XK_Egrave              0x0c8
#define XK_Eacute              0x0c9
#define XK_Ecircumflex         0x0ca
#define XK_Ediaeresis          0x0cb
#define XK_Igrave              0x0cc
#define XK_Iacute              0x0cd
#define XK_Icircumflex         0x0ce
#define XK_Idiaeresis          0x0cf
#define XK_ETH                 0x0d0
#define XK_Eth                 0x0d0	/* deprecated */
#define XK_Ntilde              0x0d1
#define XK_Ograve              0x0d2
#define XK_Oacute              0x0d3
#define XK_Ocircumflex         0x0d4
#define XK_Otilde              0x0d5
#define XK_Odiaeresis          0x0d6
#define XK_multiply            0x0d7
#define XK_Oslash                        0x00d8  /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
#define XK_Ooblique                      0x00d8  /* deprecated alias for Oslash */
#define XK_Ugrave                        0x00d9  /* U+00D9 LATIN CAPITAL LETTER U WITH GRAVE */
#define XK_Uacute                        0x00da  /* U+00DA LATIN CAPITAL LETTER U WITH ACUTE */
#define XK_Ucircumflex                   0x00db  /* U+00DB LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
#define XK_Udiaeresis                    0x00dc  /* U+00DC LATIN CAPITAL LETTER U WITH DIAERESIS */
#define XK_Yacute                        0x00dd  /* U+00DD LATIN CAPITAL LETTER Y WITH ACUTE */
#define XK_THORN                         0x00de  /* U+00DE LATIN CAPITAL LETTER THORN */
#define XK_Thorn                         0x00de  /* deprecated */
#define XK_ssharp                        0x00df  /* U+00DF LATIN SMALL LETTER SHARP S */
#define XK_agrave                        0x00e0  /* U+00E0 LATIN SMALL LETTER A WITH GRAVE */
#define XK_aacute                        0x00e1  /* U+00E1 LATIN SMALL LETTER A WITH ACUTE */
#define XK_acircumflex                   0x00e2  /* U+00E2 LATIN SMALL LETTER A WITH CIRCUMFLEX */
#define XK_atilde                        0x00e3  /* U+00E3 LATIN SMALL LETTER A WITH TILDE */
#define XK_adiaeresis                    0x00e4  /* U+00E4 LATIN SMALL LETTER A WITH DIAERESIS */
#define XK_aring                         0x00e5  /* U+00E5 LATIN SMALL LETTER A WITH RING ABOVE */
#define XK_ae                            0x00e6  /* U+00E6 LATIN SMALL LETTER AE */
#define XK_ccedilla                      0x00e7  /* U+00E7 LATIN SMALL LETTER C WITH CEDILLA */
#define XK_egrave                        0x00e8  /* U+00E8 LATIN SMALL LETTER E WITH GRAVE */
#define XK_eacute                        0x00e9  /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
#define XK_ecircumflex                   0x00ea  /* U+00EA LATIN SMALL LETTER E WITH CIRCUMFLEX */
#define XK_ediaeresis                    0x00eb  /* U+00EB LATIN SMALL LETTER E WITH DIAERESIS */
#define XK_igrave                        0x00ec  /* U+00EC LATIN SMALL LETTER I WITH GRAVE */
#define XK_iacute                        0x00ed  /* U+00ED LATIN SMALL LETTER I WITH ACUTE */
#define XK_icircumflex                   0x00ee  /* U+00EE LATIN SMALL LETTER I WITH CIRCUMFLEX */
#define XK_idiaeresis                    0x00ef  /* U+00EF LATIN SMALL LETTER I WITH DIAERESIS */
#define XK_eth                           0x00f0  /* U+00F0 LATIN SMALL LETTER ETH */
#define XK_ntilde                        0x00f1  /* U+00F1 LATIN SMALL LETTER N WITH TILDE */
#define XK_ograve                        0x00f2  /* U+00F2 LATIN SMALL LETTER O WITH GRAVE */
#define XK_oacute                        0x00f3  /* U+00F3 LATIN SMALL LETTER O WITH ACUTE */
#define XK_ocircumflex                   0x00f4  /* U+00F4 LATIN SMALL LETTER O WITH CIRCUMFLEX */
#define XK_otilde                        0x00f5  /* U+00F5 LATIN SMALL LETTER O WITH TILDE */
#define XK_odiaeresis                    0x00f6  /* U+00F6 LATIN SMALL LETTER O WITH DIAERESIS */
#define XK_division                      0x00f7  /* U+00F7 DIVISION SIGN */
#define XK_oslash                        0x00f8  /* U+00F8 LATIN SMALL LETTER O WITH STROKE */
#define XK_Ooblique            0x0d8
#define XK_Ugrave              0x0d9
#define XK_Uacute              0x0da
#define XK_Ucircumflex         0x0db
#define XK_Udiaeresis          0x0dc
#define XK_Yacute              0x0dd
#define XK_THORN               0x0de
#define XK_Thorn               0x0de	/* deprecated */
#define XK_ssharp              0x0df
#define XK_agrave              0x0e0
#define XK_aacute              0x0e1
#define XK_acircumflex         0x0e2
#define XK_atilde              0x0e3
#define XK_adiaeresis          0x0e4
#define XK_aring               0x0e5
#define XK_ae                  0x0e6
#define XK_ccedilla            0x0e7
#define XK_egrave              0x0e8
#define XK_eacute              0x0e9
#define XK_ecircumflex         0x0ea
#define XK_ediaeresis          0x0eb
#define XK_igrave              0x0ec
#define XK_iacute              0x0ed
#define XK_icircumflex         0x0ee
#define XK_idiaeresis          0x0ef
#define XK_eth                 0x0f0
#define XK_ntilde              0x0f1
#define XK_ograve              0x0f2
#define XK_oacute              0x0f3
#define XK_ocircumflex         0x0f4
#define XK_otilde              0x0f5
#define XK_odiaeresis          0x0f6
#define XK_division            0x0f7
#define XK_oslash              0x0f8
#define XK_ooblique                      0x00f8  /* deprecated alias for oslash */
#define XK_ugrave                        0x00f9  /* U+00F9 LATIN SMALL LETTER U WITH GRAVE */
#define XK_uacute                        0x00fa  /* U+00FA LATIN SMALL LETTER U WITH ACUTE */
#define XK_ucircumflex                   0x00fb  /* U+00FB LATIN SMALL LETTER U WITH CIRCUMFLEX */
#define XK_udiaeresis                    0x00fc  /* U+00FC LATIN SMALL LETTER U WITH DIAERESIS */
#define XK_yacute                        0x00fd  /* U+00FD LATIN SMALL LETTER Y WITH ACUTE */
#define XK_thorn                         0x00fe  /* U+00FE LATIN SMALL LETTER THORN */
#define XK_ydiaeresis                    0x00ff  /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
#define XK_ugrave              0x0f9
#define XK_uacute              0x0fa
#define XK_ucircumflex         0x0fb
#define XK_udiaeresis          0x0fc
#define XK_yacute              0x0fd
#define XK_thorn               0x0fe
#define XK_ydiaeresis          0x0ff
#endif /* XK_LATIN1 */

/*
 * Latin 2
 * Byte 3 = 1
 *   Latin 2
 *   Byte 3 = 1
 */

#ifdef XK_LATIN2
#define XK_Aogonek                       0x01a1  /* U+0104 LATIN CAPITAL LETTER A WITH OGONEK */
#define XK_breve                         0x01a2  /* U+02D8 BREVE */
#define XK_Lstroke                       0x01a3  /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
#define XK_Lcaron                        0x01a5  /* U+013D LATIN CAPITAL LETTER L WITH CARON */
#define XK_Sacute                        0x01a6  /* U+015A LATIN CAPITAL LETTER S WITH ACUTE */
#define XK_Scaron                        0x01a9  /* U+0160 LATIN CAPITAL LETTER S WITH CARON */
#define XK_Scedilla                      0x01aa  /* U+015E LATIN CAPITAL LETTER S WITH CEDILLA */
#define XK_Tcaron                        0x01ab  /* U+0164 LATIN CAPITAL LETTER T WITH CARON */
#define XK_Zacute                        0x01ac  /* U+0179 LATIN CAPITAL LETTER Z WITH ACUTE */
#define XK_Zcaron                        0x01ae  /* U+017D LATIN CAPITAL LETTER Z WITH CARON */
#define XK_Zabovedot                     0x01af  /* U+017B LATIN CAPITAL LETTER Z WITH DOT ABOVE */
#define XK_aogonek                       0x01b1  /* U+0105 LATIN SMALL LETTER A WITH OGONEK */
#define XK_ogonek                        0x01b2  /* U+02DB OGONEK */
#define XK_lstroke                       0x01b3  /* U+0142 LATIN SMALL LETTER L WITH STROKE */
#define XK_lcaron                        0x01b5  /* U+013E LATIN SMALL LETTER L WITH CARON */
#define XK_sacute                        0x01b6  /* U+015B LATIN SMALL LETTER S WITH ACUTE */
#define XK_caron                         0x01b7  /* U+02C7 CARON */
#define XK_scaron                        0x01b9  /* U+0161 LATIN SMALL LETTER S WITH CARON */
#define XK_scedilla                      0x01ba  /* U+015F LATIN SMALL LETTER S WITH CEDILLA */
#define XK_tcaron                        0x01bb  /* U+0165 LATIN SMALL LETTER T WITH CARON */
#define XK_zacute                        0x01bc  /* U+017A LATIN SMALL LETTER Z WITH ACUTE */
#define XK_doubleacute                   0x01bd  /* U+02DD DOUBLE ACUTE ACCENT */
#define XK_zcaron                        0x01be  /* U+017E LATIN SMALL LETTER Z WITH CARON */
#define XK_zabovedot                     0x01bf  /* U+017C LATIN SMALL LETTER Z WITH DOT ABOVE */
#define XK_Racute                        0x01c0  /* U+0154 LATIN CAPITAL LETTER R WITH ACUTE */
#define XK_Abreve                        0x01c3  /* U+0102 LATIN CAPITAL LETTER A WITH BREVE */
#define XK_Lacute                        0x01c5  /* U+0139 LATIN CAPITAL LETTER L WITH ACUTE */
#define XK_Cacute                        0x01c6  /* U+0106 LATIN CAPITAL LETTER C WITH ACUTE */
#define XK_Ccaron                        0x01c8  /* U+010C LATIN CAPITAL LETTER C WITH CARON */
#define XK_Eogonek                       0x01ca  /* U+0118 LATIN CAPITAL LETTER E WITH OGONEK */
#define XK_Ecaron                        0x01cc  /* U+011A LATIN CAPITAL LETTER E WITH CARON */
#define XK_Dcaron                        0x01cf  /* U+010E LATIN CAPITAL LETTER D WITH CARON */
#define XK_Dstroke                       0x01d0  /* U+0110 LATIN CAPITAL LETTER D WITH STROKE */
#define XK_Nacute                        0x01d1  /* U+0143 LATIN CAPITAL LETTER N WITH ACUTE */
#define XK_Ncaron                        0x01d2  /* U+0147 LATIN CAPITAL LETTER N WITH CARON */
#define XK_Odoubleacute                  0x01d5  /* U+0150 LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */
#define XK_Rcaron                        0x01d8  /* U+0158 LATIN CAPITAL LETTER R WITH CARON */
#define XK_Uring                         0x01d9  /* U+016E LATIN CAPITAL LETTER U WITH RING ABOVE */
#define XK_Udoubleacute                  0x01db  /* U+0170 LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */
#define XK_Tcedilla                      0x01de  /* U+0162 LATIN CAPITAL LETTER T WITH CEDILLA */
#define XK_racute                        0x01e0  /* U+0155 LATIN SMALL LETTER R WITH ACUTE */
#define XK_abreve                        0x01e3  /* U+0103 LATIN SMALL LETTER A WITH BREVE */
#define XK_lacute                        0x01e5  /* U+013A LATIN SMALL LETTER L WITH ACUTE */
#define XK_cacute                        0x01e6  /* U+0107 LATIN SMALL LETTER C WITH ACUTE */
#define XK_ccaron                        0x01e8  /* U+010D LATIN SMALL LETTER C WITH CARON */
#define XK_eogonek                       0x01ea  /* U+0119 LATIN SMALL LETTER E WITH OGONEK */
#define XK_ecaron                        0x01ec  /* U+011B LATIN SMALL LETTER E WITH CARON */
#define XK_dcaron                        0x01ef  /* U+010F LATIN SMALL LETTER D WITH CARON */
#define XK_dstroke                       0x01f0  /* U+0111 LATIN SMALL LETTER D WITH STROKE */
#define XK_nacute                        0x01f1  /* U+0144 LATIN SMALL LETTER N WITH ACUTE */
#define XK_ncaron                        0x01f2  /* U+0148 LATIN SMALL LETTER N WITH CARON */
#define XK_odoubleacute                  0x01f5  /* U+0151 LATIN SMALL LETTER O WITH DOUBLE ACUTE */
#define XK_rcaron                        0x01f8  /* U+0159 LATIN SMALL LETTER R WITH CARON */
#define XK_uring                         0x01f9  /* U+016F LATIN SMALL LETTER U WITH RING ABOVE */
#define XK_Aogonek             0x1a1
#define XK_breve               0x1a2
#define XK_Lstroke             0x1a3
#define XK_Lcaron              0x1a5
#define XK_Sacute              0x1a6
#define XK_Scaron              0x1a9
#define XK_Scedilla            0x1aa
#define XK_Tcaron              0x1ab
#define XK_Zacute              0x1ac
#define XK_Zcaron              0x1ae
#define XK_Zabovedot           0x1af
#define XK_aogonek             0x1b1
#define XK_ogonek              0x1b2
#define XK_lstroke             0x1b3
#define XK_lcaron              0x1b5
#define XK_sacute              0x1b6
#define XK_caron               0x1b7
#define XK_scaron              0x1b9
#define XK_scedilla            0x1ba
#define XK_tcaron              0x1bb
#define XK_zacute              0x1bc
#define XK_doubleacute         0x1bd
#define XK_zcaron              0x1be
#define XK_zabovedot           0x1bf
#define XK_Racute              0x1c0
#define XK_Abreve              0x1c3
#define XK_Lacute              0x1c5
#define XK_Cacute              0x1c6
#define XK_Ccaron              0x1c8
#define XK_Eogonek             0x1ca
#define XK_Ecaron              0x1cc
#define XK_Dcaron              0x1cf
#define XK_Dstroke             0x1d0
#define XK_Nacute              0x1d1
#define XK_Ncaron              0x1d2
#define XK_Odoubleacute        0x1d5
#define XK_Rcaron              0x1d8
#define XK_Uring               0x1d9
#define XK_Udoubleacute        0x1db
#define XK_Tcedilla            0x1de
#define XK_racute              0x1e0
#define XK_abreve              0x1e3
#define XK_lacute              0x1e5
#define XK_cacute              0x1e6
#define XK_ccaron              0x1e8
#define XK_eogonek             0x1ea
#define XK_ecaron              0x1ec
#define XK_dcaron              0x1ef
#define XK_dstroke             0x1f0
#define XK_nacute              0x1f1
#define XK_ncaron              0x1f2
#define XK_odoubleacute        0x1f5
#define XK_udoubleacute        0x1fb
#define XK_rcaron              0x1f8
#define XK_uring               0x1f9
#define XK_udoubleacute                  0x01fb  /* U+0171 LATIN SMALL LETTER U WITH DOUBLE ACUTE */
#define XK_tcedilla                      0x01fe  /* U+0163 LATIN SMALL LETTER T WITH CEDILLA */
#define XK_abovedot                      0x01ff  /* U+02D9 DOT ABOVE */
#define XK_tcedilla            0x1fe
#define XK_abovedot            0x1ff
#endif /* XK_LATIN2 */

/*
 * Latin 3
 * Byte 3 = 2
 *   Latin 3
 *   Byte 3 = 2
 */

#ifdef XK_LATIN3
#define XK_Hstroke                       0x02a1  /* U+0126 LATIN CAPITAL LETTER H WITH STROKE */
#define XK_Hcircumflex                   0x02a6  /* U+0124 LATIN CAPITAL LETTER H WITH CIRCUMFLEX */
#define XK_Iabovedot                     0x02a9  /* U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE */
#define XK_Gbreve                        0x02ab  /* U+011E LATIN CAPITAL LETTER G WITH BREVE */
#define XK_Jcircumflex                   0x02ac  /* U+0134 LATIN CAPITAL LETTER J WITH CIRCUMFLEX */
#define XK_hstroke                       0x02b1  /* U+0127 LATIN SMALL LETTER H WITH STROKE */
#define XK_hcircumflex                   0x02b6  /* U+0125 LATIN SMALL LETTER H WITH CIRCUMFLEX */
#define XK_idotless                      0x02b9  /* U+0131 LATIN SMALL LETTER DOTLESS I */
#define XK_gbreve                        0x02bb  /* U+011F LATIN SMALL LETTER G WITH BREVE */
#define XK_jcircumflex                   0x02bc  /* U+0135 LATIN SMALL LETTER J WITH CIRCUMFLEX */
#define XK_Cabovedot                     0x02c5  /* U+010A LATIN CAPITAL LETTER C WITH DOT ABOVE */
#define XK_Ccircumflex                   0x02c6  /* U+0108 LATIN CAPITAL LETTER C WITH CIRCUMFLEX */
#define XK_Gabovedot                     0x02d5  /* U+0120 LATIN CAPITAL LETTER G WITH DOT ABOVE */
#define XK_Gcircumflex                   0x02d8  /* U+011C LATIN CAPITAL LETTER G WITH CIRCUMFLEX */
#define XK_Ubreve                        0x02dd  /* U+016C LATIN CAPITAL LETTER U WITH BREVE */
#define XK_Scircumflex                   0x02de  /* U+015C LATIN CAPITAL LETTER S WITH CIRCUMFLEX */
#define XK_cabovedot                     0x02e5  /* U+010B LATIN SMALL LETTER C WITH DOT ABOVE */
#define XK_ccircumflex                   0x02e6  /* U+0109 LATIN SMALL LETTER C WITH CIRCUMFLEX */
#define XK_gabovedot                     0x02f5  /* U+0121 LATIN SMALL LETTER G WITH DOT ABOVE */
#define XK_gcircumflex                   0x02f8  /* U+011D LATIN SMALL LETTER G WITH CIRCUMFLEX */
#define XK_ubreve                        0x02fd  /* U+016D LATIN SMALL LETTER U WITH BREVE */
#define XK_scircumflex                   0x02fe  /* U+015D LATIN SMALL LETTER S WITH CIRCUMFLEX */
#define XK_Hstroke             0x2a1
#define XK_Hcircumflex         0x2a6
#define XK_Iabovedot           0x2a9
#define XK_Gbreve              0x2ab
#define XK_Jcircumflex         0x2ac
#define XK_hstroke             0x2b1
#define XK_hcircumflex         0x2b6
#define XK_idotless            0x2b9
#define XK_gbreve              0x2bb
#define XK_jcircumflex         0x2bc
#define XK_Cabovedot           0x2c5
#define XK_Ccircumflex         0x2c6
#define XK_Gabovedot           0x2d5
#define XK_Gcircumflex         0x2d8
#define XK_Ubreve              0x2dd
#define XK_Scircumflex         0x2de
#define XK_cabovedot           0x2e5
#define XK_ccircumflex         0x2e6
#define XK_gabovedot           0x2f5
#define XK_gcircumflex         0x2f8
#define XK_ubreve              0x2fd
#define XK_scircumflex         0x2fe
#endif /* XK_LATIN3 */


/*
 * Latin 4
 * Byte 3 = 3
 *   Latin 4
 *   Byte 3 = 3
 */

#ifdef XK_LATIN4
#define XK_kra                           0x03a2  /* U+0138 LATIN SMALL LETTER KRA */
#define XK_kappa                         0x03a2  /* deprecated */
#define XK_Rcedilla                      0x03a3  /* U+0156 LATIN CAPITAL LETTER R WITH CEDILLA */
#define XK_Itilde                        0x03a5  /* U+0128 LATIN CAPITAL LETTER I WITH TILDE */
#define XK_Lcedilla                      0x03a6  /* U+013B LATIN CAPITAL LETTER L WITH CEDILLA */
#define XK_Emacron                       0x03aa  /* U+0112 LATIN CAPITAL LETTER E WITH MACRON */
#define XK_Gcedilla                      0x03ab  /* U+0122 LATIN CAPITAL LETTER G WITH CEDILLA */
#define XK_Tslash                        0x03ac  /* U+0166 LATIN CAPITAL LETTER T WITH STROKE */
#define XK_rcedilla                      0x03b3  /* U+0157 LATIN SMALL LETTER R WITH CEDILLA */
#define XK_itilde                        0x03b5  /* U+0129 LATIN SMALL LETTER I WITH TILDE */
#define XK_lcedilla                      0x03b6  /* U+013C LATIN SMALL LETTER L WITH CEDILLA */
#define XK_emacron                       0x03ba  /* U+0113 LATIN SMALL LETTER E WITH MACRON */
#define XK_gcedilla                      0x03bb  /* U+0123 LATIN SMALL LETTER G WITH CEDILLA */
#define XK_tslash                        0x03bc  /* U+0167 LATIN SMALL LETTER T WITH STROKE */
#define XK_ENG                           0x03bd  /* U+014A LATIN CAPITAL LETTER ENG */
#define XK_eng                           0x03bf  /* U+014B LATIN SMALL LETTER ENG */
#define XK_Amacron                       0x03c0  /* U+0100 LATIN CAPITAL LETTER A WITH MACRON */
#define XK_Iogonek                       0x03c7  /* U+012E LATIN CAPITAL LETTER I WITH OGONEK */
#define XK_kra                 0x3a2
#define XK_kappa               0x3a2	/* deprecated */
#define XK_Rcedilla            0x3a3
#define XK_Itilde              0x3a5
#define XK_Lcedilla            0x3a6
#define XK_Emacron             0x3aa
#define XK_Gcedilla            0x3ab
#define XK_Tslash              0x3ac
#define XK_rcedilla            0x3b3
#define XK_itilde              0x3b5
#define XK_lcedilla            0x3b6
#define XK_emacron             0x3ba
#define XK_gcedilla            0x3bb
#define XK_tslash              0x3bc
#define XK_ENG                 0x3bd
#define XK_eng                 0x3bf
#define XK_Amacron             0x3c0
#define XK_Iogonek             0x3c7
#define XK_Eabovedot                     0x03cc  /* U+0116 LATIN CAPITAL LETTER E WITH DOT ABOVE */
#define XK_Imacron                       0x03cf  /* U+012A LATIN CAPITAL LETTER I WITH MACRON */
#define XK_Ncedilla                      0x03d1  /* U+0145 LATIN CAPITAL LETTER N WITH CEDILLA */
#define XK_Omacron                       0x03d2  /* U+014C LATIN CAPITAL LETTER O WITH MACRON */
#define XK_Kcedilla                      0x03d3  /* U+0136 LATIN CAPITAL LETTER K WITH CEDILLA */
#define XK_Uogonek                       0x03d9  /* U+0172 LATIN CAPITAL LETTER U WITH OGONEK */
#define XK_Utilde                        0x03dd  /* U+0168 LATIN CAPITAL LETTER U WITH TILDE */
#define XK_Umacron                       0x03de  /* U+016A LATIN CAPITAL LETTER U WITH MACRON */
#define XK_amacron                       0x03e0  /* U+0101 LATIN SMALL LETTER A WITH MACRON */
#define XK_iogonek                       0x03e7  /* U+012F LATIN SMALL LETTER I WITH OGONEK */
#define XK_eabovedot                     0x03ec  /* U+0117 LATIN SMALL LETTER E WITH DOT ABOVE */
#define XK_imacron                       0x03ef  /* U+012B LATIN SMALL LETTER I WITH MACRON */
#define XK_ncedilla                      0x03f1  /* U+0146 LATIN SMALL LETTER N WITH CEDILLA */
#define XK_omacron                       0x03f2  /* U+014D LATIN SMALL LETTER O WITH MACRON */
#define XK_kcedilla                      0x03f3  /* U+0137 LATIN SMALL LETTER K WITH CEDILLA */
#define XK_uogonek                       0x03f9  /* U+0173 LATIN SMALL LETTER U WITH OGONEK */
#define XK_utilde                        0x03fd  /* U+0169 LATIN SMALL LETTER U WITH TILDE */
#define XK_umacron                       0x03fe  /* U+016B LATIN SMALL LETTER U WITH MACRON */
#endif /* XK_LATIN4 */

/*
 * Latin 8
 */
#ifdef XK_LATIN8
#define XK_Wcircumflex                0x1000174  /* U+0174 LATIN CAPITAL LETTER W WITH CIRCUMFLEX */
#define XK_wcircumflex                0x1000175  /* U+0175 LATIN SMALL LETTER W WITH CIRCUMFLEX */
#define XK_Ycircumflex                0x1000176  /* U+0176 LATIN CAPITAL LETTER Y WITH CIRCUMFLEX */
#define XK_ycircumflex                0x1000177  /* U+0177 LATIN SMALL LETTER Y WITH CIRCUMFLEX */
#define XK_Babovedot                  0x1001e02  /* U+1E02 LATIN CAPITAL LETTER B WITH DOT ABOVE */
#define XK_babovedot                  0x1001e03  /* U+1E03 LATIN SMALL LETTER B WITH DOT ABOVE */
#define XK_Dabovedot                  0x1001e0a  /* U+1E0A LATIN CAPITAL LETTER D WITH DOT ABOVE */
#define XK_dabovedot                  0x1001e0b  /* U+1E0B LATIN SMALL LETTER D WITH DOT ABOVE */
#define XK_Fabovedot                  0x1001e1e  /* U+1E1E LATIN CAPITAL LETTER F WITH DOT ABOVE */
#define XK_fabovedot                  0x1001e1f  /* U+1E1F LATIN SMALL LETTER F WITH DOT ABOVE */
#define XK_Mabovedot                  0x1001e40  /* U+1E40 LATIN CAPITAL LETTER M WITH DOT ABOVE */
#define XK_mabovedot                  0x1001e41  /* U+1E41 LATIN SMALL LETTER M WITH DOT ABOVE */
#define XK_Pabovedot                  0x1001e56  /* U+1E56 LATIN CAPITAL LETTER P WITH DOT ABOVE */
#define XK_pabovedot                  0x1001e57  /* U+1E57 LATIN SMALL LETTER P WITH DOT ABOVE */
#define XK_Sabovedot                  0x1001e60  /* U+1E60 LATIN CAPITAL LETTER S WITH DOT ABOVE */
#define XK_sabovedot                  0x1001e61  /* U+1E61 LATIN SMALL LETTER S WITH DOT ABOVE */
#define XK_Eabovedot           0x3cc
#define XK_Imacron             0x3cf
#define XK_Ncedilla            0x3d1
#define XK_Omacron             0x3d2
#define XK_Kcedilla            0x3d3
#define XK_Uogonek             0x3d9
#define XK_Utilde              0x3dd
#define XK_Umacron             0x3de
#define XK_amacron             0x3e0
#define XK_iogonek             0x3e7
#define XK_eabovedot           0x3ec
#define XK_Tabovedot                  0x1001e6a  /* U+1E6A LATIN CAPITAL LETTER T WITH DOT ABOVE */
#define XK_tabovedot                  0x1001e6b  /* U+1E6B LATIN SMALL LETTER T WITH DOT ABOVE */
#define XK_Wgrave                     0x1001e80  /* U+1E80 LATIN CAPITAL LETTER W WITH GRAVE */
#define XK_wgrave                     0x1001e81  /* U+1E81 LATIN SMALL LETTER W WITH GRAVE */
#define XK_Wacute                     0x1001e82  /* U+1E82 LATIN CAPITAL LETTER W WITH ACUTE */
#define XK_imacron             0x3ef
#define XK_ncedilla            0x3f1
#define XK_omacron             0x3f2
#define XK_wacute                     0x1001e83  /* U+1E83 LATIN SMALL LETTER W WITH ACUTE */
#define XK_Wdiaeresis                 0x1001e84  /* U+1E84 LATIN CAPITAL LETTER W WITH DIAERESIS */
#define XK_wdiaeresis                 0x1001e85  /* U+1E85 LATIN SMALL LETTER W WITH DIAERESIS */
#define XK_Ygrave                     0x1001ef2  /* U+1EF2 LATIN CAPITAL LETTER Y WITH GRAVE */
#define XK_ygrave                     0x1001ef3  /* U+1EF3 LATIN SMALL LETTER Y WITH GRAVE */
#endif /* XK_LATIN8 */

#define XK_kcedilla            0x3f3
/*
 * Latin 9
 * Byte 3 = 0x13
 */

#define XK_uogonek             0x3f9
#ifdef XK_LATIN9
#define XK_OE                            0x13bc  /* U+0152 LATIN CAPITAL LIGATURE OE */
#define XK_oe                            0x13bd  /* U+0153 LATIN SMALL LIGATURE OE */
#define XK_utilde              0x3fd
#define XK_umacron             0x3fe
#define XK_Ydiaeresis                    0x13be  /* U+0178 LATIN CAPITAL LETTER Y WITH DIAERESIS */
#endif /* XK_LATIN9 */
#endif /* XK_LATIN4 */

/*
 * Katakana
 * Byte 3 = 4
 */

#ifdef XK_KATAKANA
#define XK_overline                      0x047e  /* U+203E OVERLINE */
#define XK_kana_fullstop                 0x04a1  /* U+3002 IDEOGRAPHIC FULL STOP */
#define XK_kana_openingbracket           0x04a2  /* U+300C LEFT CORNER BRACKET */
#define XK_kana_closingbracket           0x04a3  /* U+300D RIGHT CORNER BRACKET */
#define XK_kana_comma                    0x04a4  /* U+3001 IDEOGRAPHIC COMMA */
#define XK_kana_conjunctive              0x04a5  /* U+30FB KATAKANA MIDDLE DOT */
#define XK_kana_middledot                0x04a5  /* deprecated */
#define XK_kana_WO                       0x04a6  /* U+30F2 KATAKANA LETTER WO */
#define XK_kana_a                        0x04a7  /* U+30A1 KATAKANA LETTER SMALL A */
#define XK_kana_i                        0x04a8  /* U+30A3 KATAKANA LETTER SMALL I */
#define XK_kana_u                        0x04a9  /* U+30A5 KATAKANA LETTER SMALL U */
#define XK_kana_e                        0x04aa  /* U+30A7 KATAKANA LETTER SMALL E */
#define XK_kana_o                        0x04ab  /* U+30A9 KATAKANA LETTER SMALL O */
#define XK_kana_ya                       0x04ac  /* U+30E3 KATAKANA LETTER SMALL YA */
#define XK_kana_yu                       0x04ad  /* U+30E5 KATAKANA LETTER SMALL YU */
#define XK_kana_yo                       0x04ae  /* U+30E7 KATAKANA LETTER SMALL YO */
#define XK_kana_tsu                      0x04af  /* U+30C3 KATAKANA LETTER SMALL TU */
#define XK_kana_tu                       0x04af  /* deprecated */
#define XK_prolongedsound                0x04b0  /* U+30FC KATAKANA-HIRAGANA PROLONGED SOUND MARK */
#define XK_kana_A                        0x04b1  /* U+30A2 KATAKANA LETTER A */
#define XK_kana_I                        0x04b2  /* U+30A4 KATAKANA LETTER I */
#define XK_kana_U                        0x04b3  /* U+30A6 KATAKANA LETTER U */
#define XK_kana_E                        0x04b4  /* U+30A8 KATAKANA LETTER E */
#define XK_kana_O                        0x04b5  /* U+30AA KATAKANA LETTER O */
#define XK_kana_KA                       0x04b6  /* U+30AB KATAKANA LETTER KA */
#define XK_kana_KI                       0x04b7  /* U+30AD KATAKANA LETTER KI */
#define XK_kana_KU                       0x04b8  /* U+30AF KATAKANA LETTER KU */
#define XK_kana_KE                       0x04b9  /* U+30B1 KATAKANA LETTER KE */
#define XK_kana_KO                       0x04ba  /* U+30B3 KATAKANA LETTER KO */
#define XK_kana_SA                       0x04bb  /* U+30B5 KATAKANA LETTER SA */
#define XK_kana_SHI                      0x04bc  /* U+30B7 KATAKANA LETTER SI */
#define XK_kana_SU                       0x04bd  /* U+30B9 KATAKANA LETTER SU */
#define XK_kana_SE                       0x04be  /* U+30BB KATAKANA LETTER SE */
#define XK_kana_SO                       0x04bf  /* U+30BD KATAKANA LETTER SO */
#define XK_kana_TA                       0x04c0  /* U+30BF KATAKANA LETTER TA */
#define XK_kana_CHI                      0x04c1  /* U+30C1 KATAKANA LETTER TI */
#define XK_kana_TI                       0x04c1  /* deprecated */
#define XK_kana_TSU                      0x04c2  /* U+30C4 KATAKANA LETTER TU */
#define XK_kana_TU                       0x04c2  /* deprecated */
#define XK_kana_TE                       0x04c3  /* U+30C6 KATAKANA LETTER TE */
#define XK_kana_TO                       0x04c4  /* U+30C8 KATAKANA LETTER TO */
#define XK_kana_NA                       0x04c5  /* U+30CA KATAKANA LETTER NA */
#define XK_kana_NI                       0x04c6  /* U+30CB KATAKANA LETTER NI */
#define XK_kana_NU                       0x04c7  /* U+30CC KATAKANA LETTER NU */
#define XK_kana_NE                       0x04c8  /* U+30CD KATAKANA LETTER NE */
#define XK_kana_NO                       0x04c9  /* U+30CE KATAKANA LETTER NO */
#define XK_kana_HA                       0x04ca  /* U+30CF KATAKANA LETTER HA */
#define XK_kana_HI                       0x04cb  /* U+30D2 KATAKANA LETTER HI */
#define XK_kana_FU                       0x04cc  /* U+30D5 KATAKANA LETTER HU */
#define XK_kana_HU                       0x04cc  /* deprecated */
#define XK_kana_HE                       0x04cd  /* U+30D8 KATAKANA LETTER HE */
#define XK_kana_HO                       0x04ce  /* U+30DB KATAKANA LETTER HO */
#define XK_kana_MA                       0x04cf  /* U+30DE KATAKANA LETTER MA */
#define XK_kana_MI                       0x04d0  /* U+30DF KATAKANA LETTER MI */
#define XK_kana_MU                       0x04d1  /* U+30E0 KATAKANA LETTER MU */
#define XK_kana_ME                       0x04d2  /* U+30E1 KATAKANA LETTER ME */
#define XK_kana_MO                       0x04d3  /* U+30E2 KATAKANA LETTER MO */
#define XK_kana_YA                       0x04d4  /* U+30E4 KATAKANA LETTER YA */
#define XK_kana_YU                       0x04d5  /* U+30E6 KATAKANA LETTER YU */
#define XK_kana_YO                       0x04d6  /* U+30E8 KATAKANA LETTER YO */
#define XK_kana_RA                       0x04d7  /* U+30E9 KATAKANA LETTER RA */
#define XK_kana_RI                       0x04d8  /* U+30EA KATAKANA LETTER RI */
#define XK_kana_RU                       0x04d9  /* U+30EB KATAKANA LETTER RU */
#define XK_kana_RE                       0x04da  /* U+30EC KATAKANA LETTER RE */
#define XK_kana_RO                       0x04db  /* U+30ED KATAKANA LETTER RO */
#define XK_kana_WA                       0x04dc  /* U+30EF KATAKANA LETTER WA */
#define XK_kana_N                        0x04dd  /* U+30F3 KATAKANA LETTER N */
#define XK_voicedsound                   0x04de  /* U+309B KATAKANA-HIRAGANA VOICED SOUND MARK */
#define XK_semivoicedsound               0x04df  /* U+309C KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK */
#define XK_kana_switch                   0xff7e  /* non-deprecated alias for Mode_switch */
#define XK_overline				       0x47e
#define XK_kana_fullstop                               0x4a1
#define XK_kana_openingbracket                         0x4a2
#define XK_kana_closingbracket                         0x4a3
#define XK_kana_comma                                  0x4a4
#define XK_kana_conjunctive                            0x4a5
#define XK_kana_middledot                              0x4a5  /* deprecated */
#define XK_kana_WO                                     0x4a6
#define XK_kana_a                                      0x4a7
#define XK_kana_i                                      0x4a8
#define XK_kana_u                                      0x4a9
#define XK_kana_e                                      0x4aa
#define XK_kana_o                                      0x4ab
#define XK_kana_ya                                     0x4ac
#define XK_kana_yu                                     0x4ad
#define XK_kana_yo                                     0x4ae
#define XK_kana_tsu                                    0x4af
#define XK_kana_tu                                     0x4af  /* deprecated */
#define XK_prolongedsound                              0x4b0
#define XK_kana_A                                      0x4b1
#define XK_kana_I                                      0x4b2
#define XK_kana_U                                      0x4b3
#define XK_kana_E                                      0x4b4
#define XK_kana_O                                      0x4b5
#define XK_kana_KA                                     0x4b6
#define XK_kana_KI                                     0x4b7
#define XK_kana_KU                                     0x4b8
#define XK_kana_KE                                     0x4b9
#define XK_kana_KO                                     0x4ba
#define XK_kana_SA                                     0x4bb
#define XK_kana_SHI                                    0x4bc
#define XK_kana_SU                                     0x4bd
#define XK_kana_SE                                     0x4be
#define XK_kana_SO                                     0x4bf
#define XK_kana_TA                                     0x4c0
#define XK_kana_CHI                                    0x4c1
#define XK_kana_TI                                     0x4c1  /* deprecated */
#define XK_kana_TSU                                    0x4c2
#define XK_kana_TU                                     0x4c2  /* deprecated */
#define XK_kana_TE                                     0x4c3
#define XK_kana_TO                                     0x4c4
#define XK_kana_NA                                     0x4c5
#define XK_kana_NI                                     0x4c6
#define XK_kana_NU                                     0x4c7
#define XK_kana_NE                                     0x4c8
#define XK_kana_NO                                     0x4c9
#define XK_kana_HA                                     0x4ca
#define XK_kana_HI                                     0x4cb
#define XK_kana_FU                                     0x4cc
#define XK_kana_HU                                     0x4cc  /* deprecated */
#define XK_kana_HE                                     0x4cd
#define XK_kana_HO                                     0x4ce
#define XK_kana_MA                                     0x4cf
#define XK_kana_MI                                     0x4d0
#define XK_kana_MU                                     0x4d1
#define XK_kana_ME                                     0x4d2
#define XK_kana_MO                                     0x4d3
#define XK_kana_YA                                     0x4d4
#define XK_kana_YU                                     0x4d5
#define XK_kana_YO                                     0x4d6
#define XK_kana_RA                                     0x4d7
#define XK_kana_RI                                     0x4d8
#define XK_kana_RU                                     0x4d9
#define XK_kana_RE                                     0x4da
#define XK_kana_RO                                     0x4db
#define XK_kana_WA                                     0x4dc
#define XK_kana_N                                      0x4dd
#define XK_voicedsound                                 0x4de
#define XK_semivoicedsound                             0x4df
#define XK_kana_switch          0xFF7E  /* Alias for mode_switch */
#endif /* XK_KATAKANA */

/*
 * Arabic
 * Byte 3 = 5
 *  Arabic
 *  Byte 3 = 5
 */

#ifdef XK_ARABIC
#define XK_Farsi_0                    0x10006f0  /* U+06F0 EXTENDED ARABIC-INDIC DIGIT ZERO */
#define XK_Farsi_1                    0x10006f1  /* U+06F1 EXTENDED ARABIC-INDIC DIGIT ONE */
#define XK_Farsi_2                    0x10006f2  /* U+06F2 EXTENDED ARABIC-INDIC DIGIT TWO */
#define XK_Farsi_3                    0x10006f3  /* U+06F3 EXTENDED ARABIC-INDIC DIGIT THREE */
#define XK_Farsi_4                    0x10006f4  /* U+06F4 EXTENDED ARABIC-INDIC DIGIT FOUR */
#define XK_Farsi_5                    0x10006f5  /* U+06F5 EXTENDED ARABIC-INDIC DIGIT FIVE */
#define XK_Farsi_6                    0x10006f6  /* U+06F6 EXTENDED ARABIC-INDIC DIGIT SIX */
#define XK_Farsi_7                    0x10006f7  /* U+06F7 EXTENDED ARABIC-INDIC DIGIT SEVEN */
#define XK_Farsi_8                    0x10006f8  /* U+06F8 EXTENDED ARABIC-INDIC DIGIT EIGHT */
#define XK_Farsi_9                    0x10006f9  /* U+06F9 EXTENDED ARABIC-INDIC DIGIT NINE */
#define XK_Arabic_percent             0x100066a  /* U+066A ARABIC PERCENT SIGN */
#define XK_Arabic_superscript_alef    0x1000670  /* U+0670 ARABIC LETTER SUPERSCRIPT ALEF */
#define XK_Arabic_tteh                0x1000679  /* U+0679 ARABIC LETTER TTEH */
#define XK_Arabic_peh                 0x100067e  /* U+067E ARABIC LETTER PEH */
#define XK_Arabic_tcheh               0x1000686  /* U+0686 ARABIC LETTER TCHEH */
#define XK_Arabic_ddal                0x1000688  /* U+0688 ARABIC LETTER DDAL */
#define XK_Arabic_rreh                0x1000691  /* U+0691 ARABIC LETTER RREH */
#define XK_Arabic_comma                  0x05ac  /* U+060C ARABIC COMMA */
#define XK_Arabic_comma                                0x5ac
#define XK_Arabic_fullstop            0x10006d4  /* U+06D4 ARABIC FULL STOP */
#define XK_Arabic_0                   0x1000660  /* U+0660 ARABIC-INDIC DIGIT ZERO */
#define XK_Arabic_1                   0x1000661  /* U+0661 ARABIC-INDIC DIGIT ONE */
#define XK_Arabic_2                   0x1000662  /* U+0662 ARABIC-INDIC DIGIT TWO */
#define XK_Arabic_3                   0x1000663  /* U+0663 ARABIC-INDIC DIGIT THREE */
#define XK_Arabic_4                   0x1000664  /* U+0664 ARABIC-INDIC DIGIT FOUR */
#define XK_Arabic_5                   0x1000665  /* U+0665 ARABIC-INDIC DIGIT FIVE */
#define XK_Arabic_6                   0x1000666  /* U+0666 ARABIC-INDIC DIGIT SIX */
#define XK_Arabic_7                   0x1000667  /* U+0667 ARABIC-INDIC DIGIT SEVEN */
#define XK_Arabic_8                   0x1000668  /* U+0668 ARABIC-INDIC DIGIT EIGHT */
#define XK_Arabic_9                   0x1000669  /* U+0669 ARABIC-INDIC DIGIT NINE */
#define XK_Arabic_semicolon              0x05bb  /* U+061B ARABIC SEMICOLON */
#define XK_Arabic_question_mark          0x05bf  /* U+061F ARABIC QUESTION MARK */
#define XK_Arabic_hamza                  0x05c1  /* U+0621 ARABIC LETTER HAMZA */
#define XK_Arabic_maddaonalef            0x05c2  /* U+0622 ARABIC LETTER ALEF WITH MADDA ABOVE */
#define XK_Arabic_hamzaonalef            0x05c3  /* U+0623 ARABIC LETTER ALEF WITH HAMZA ABOVE */
#define XK_Arabic_hamzaonwaw             0x05c4  /* U+0624 ARABIC LETTER WAW WITH HAMZA ABOVE */
#define XK_Arabic_hamzaunderalef         0x05c5  /* U+0625 ARABIC LETTER ALEF WITH HAMZA BELOW */
#define XK_Arabic_hamzaonyeh             0x05c6  /* U+0626 ARABIC LETTER YEH WITH HAMZA ABOVE */
#define XK_Arabic_alef                   0x05c7  /* U+0627 ARABIC LETTER ALEF */
#define XK_Arabic_beh                    0x05c8  /* U+0628 ARABIC LETTER BEH */
#define XK_Arabic_tehmarbuta             0x05c9  /* U+0629 ARABIC LETTER TEH MARBUTA */
#define XK_Arabic_teh                    0x05ca  /* U+062A ARABIC LETTER TEH */
#define XK_Arabic_theh                   0x05cb  /* U+062B ARABIC LETTER THEH */
#define XK_Arabic_jeem                   0x05cc  /* U+062C ARABIC LETTER JEEM */
#define XK_Arabic_hah                    0x05cd  /* U+062D ARABIC LETTER HAH */
#define XK_Arabic_khah                   0x05ce  /* U+062E ARABIC LETTER KHAH */
#define XK_Arabic_dal                    0x05cf  /* U+062F ARABIC LETTER DAL */
#define XK_Arabic_thal                   0x05d0  /* U+0630 ARABIC LETTER THAL */
#define XK_Arabic_ra                     0x05d1  /* U+0631 ARABIC LETTER REH */
#define XK_Arabic_zain                   0x05d2  /* U+0632 ARABIC LETTER ZAIN */
#define XK_Arabic_seen                   0x05d3  /* U+0633 ARABIC LETTER SEEN */
#define XK_Arabic_sheen                  0x05d4  /* U+0634 ARABIC LETTER SHEEN */
#define XK_Arabic_sad                    0x05d5  /* U+0635 ARABIC LETTER SAD */
#define XK_Arabic_dad                    0x05d6  /* U+0636 ARABIC LETTER DAD */
#define XK_Arabic_tah                    0x05d7  /* U+0637 ARABIC LETTER TAH */
#define XK_Arabic_zah                    0x05d8  /* U+0638 ARABIC LETTER ZAH */
#define XK_Arabic_ain                    0x05d9  /* U+0639 ARABIC LETTER AIN */
#define XK_Arabic_ghain                  0x05da  /* U+063A ARABIC LETTER GHAIN */
#define XK_Arabic_tatweel                0x05e0  /* U+0640 ARABIC TATWEEL */
#define XK_Arabic_feh                    0x05e1  /* U+0641 ARABIC LETTER FEH */
#define XK_Arabic_qaf                    0x05e2  /* U+0642 ARABIC LETTER QAF */
#define XK_Arabic_kaf                    0x05e3  /* U+0643 ARABIC LETTER KAF */
#define XK_Arabic_lam                    0x05e4  /* U+0644 ARABIC LETTER LAM */
#define XK_Arabic_meem                   0x05e5  /* U+0645 ARABIC LETTER MEEM */
#define XK_Arabic_noon                   0x05e6  /* U+0646 ARABIC LETTER NOON */
#define XK_Arabic_ha                     0x05e7  /* U+0647 ARABIC LETTER HEH */
#define XK_Arabic_heh                    0x05e7  /* deprecated */
#define XK_Arabic_waw                    0x05e8  /* U+0648 ARABIC LETTER WAW */
#define XK_Arabic_alefmaksura            0x05e9  /* U+0649 ARABIC LETTER ALEF MAKSURA */
#define XK_Arabic_yeh                    0x05ea  /* U+064A ARABIC LETTER YEH */
#define XK_Arabic_fathatan               0x05eb  /* U+064B ARABIC FATHATAN */
#define XK_Arabic_dammatan               0x05ec  /* U+064C ARABIC DAMMATAN */
#define XK_Arabic_kasratan               0x05ed  /* U+064D ARABIC KASRATAN */
#define XK_Arabic_fatha                  0x05ee  /* U+064E ARABIC FATHA */
#define XK_Arabic_damma                  0x05ef  /* U+064F ARABIC DAMMA */
#define XK_Arabic_kasra                  0x05f0  /* U+0650 ARABIC KASRA */
#define XK_Arabic_shadda                 0x05f1  /* U+0651 ARABIC SHADDA */
#define XK_Arabic_sukun                  0x05f2  /* U+0652 ARABIC SUKUN */
#define XK_Arabic_semicolon                            0x5bb
#define XK_Arabic_question_mark                        0x5bf
#define XK_Arabic_hamza                                0x5c1
#define XK_Arabic_maddaonalef                          0x5c2
#define XK_Arabic_hamzaonalef                          0x5c3
#define XK_Arabic_hamzaonwaw                           0x5c4
#define XK_Arabic_hamzaunderalef                       0x5c5
#define XK_Arabic_hamzaonyeh                           0x5c6
#define XK_Arabic_alef                                 0x5c7
#define XK_Arabic_beh                                  0x5c8
#define XK_Arabic_tehmarbuta                           0x5c9
#define XK_Arabic_teh                                  0x5ca
#define XK_Arabic_theh                                 0x5cb
#define XK_Arabic_jeem                                 0x5cc
#define XK_Arabic_hah                                  0x5cd
#define XK_Arabic_khah                                 0x5ce
#define XK_Arabic_dal                                  0x5cf
#define XK_Arabic_thal                                 0x5d0
#define XK_Arabic_ra                                   0x5d1
#define XK_Arabic_zain                                 0x5d2
#define XK_Arabic_seen                                 0x5d3
#define XK_Arabic_sheen                                0x5d4
#define XK_Arabic_sad                                  0x5d5
#define XK_Arabic_dad                                  0x5d6
#define XK_Arabic_tah                                  0x5d7
#define XK_Arabic_zah                                  0x5d8
#define XK_Arabic_ain                                  0x5d9
#define XK_Arabic_ghain                                0x5da
#define XK_Arabic_tatweel                              0x5e0
#define XK_Arabic_feh                                  0x5e1
#define XK_Arabic_qaf                                  0x5e2
#define XK_Arabic_kaf                                  0x5e3
#define XK_Arabic_lam                                  0x5e4
#define XK_Arabic_meem                                 0x5e5
#define XK_Arabic_noon                                 0x5e6
#define XK_Arabic_ha                                   0x5e7
#define XK_Arabic_heh                                  0x5e7  /* deprecated */
#define XK_Arabic_waw                                  0x5e8
#define XK_Arabic_alefmaksura                          0x5e9
#define XK_Arabic_yeh                                  0x5ea
#define XK_Arabic_fathatan                             0x5eb
#define XK_Arabic_dammatan                             0x5ec
#define XK_Arabic_kasratan                             0x5ed
#define XK_Arabic_fatha                                0x5ee
#define XK_Arabic_damma                                0x5ef
#define XK_Arabic_kasra                                0x5f0
#define XK_Arabic_shadda                               0x5f1
#define XK_Arabic_sukun                                0x5f2
#define XK_Arabic_madda_above         0x1000653  /* U+0653 ARABIC MADDAH ABOVE */
#define XK_Arabic_hamza_above         0x1000654  /* U+0654 ARABIC HAMZA ABOVE */
#define XK_Arabic_hamza_below         0x1000655  /* U+0655 ARABIC HAMZA BELOW */
#define XK_Arabic_jeh                 0x1000698  /* U+0698 ARABIC LETTER JEH */
#define XK_Arabic_veh                 0x10006a4  /* U+06A4 ARABIC LETTER VEH */
#define XK_Arabic_keheh               0x10006a9  /* U+06A9 ARABIC LETTER KEHEH */
#define XK_Arabic_gaf                 0x10006af  /* U+06AF ARABIC LETTER GAF */
#define XK_Arabic_noon_ghunna         0x10006ba  /* U+06BA ARABIC LETTER NOON GHUNNA */
#define XK_Arabic_heh_doachashmee     0x10006be  /* U+06BE ARABIC LETTER HEH DOACHASHMEE */
#define XK_Farsi_yeh                  0x10006cc  /* U+06CC ARABIC LETTER FARSI YEH */
#define XK_Arabic_farsi_yeh           0x10006cc  /* deprecated alias for Farsi_yeh */
#define XK_Arabic_yeh_baree           0x10006d2  /* U+06D2 ARABIC LETTER YEH BARREE */
#define XK_Arabic_heh_goal            0x10006c1  /* U+06C1 ARABIC LETTER HEH GOAL */
#define XK_Arabic_switch                 0xff7e  /* non-deprecated alias for Mode_switch */
#define XK_Arabic_switch        0xFF7E  /* Alias for mode_switch */
#endif /* XK_ARABIC */

/*
 * Cyrillic
 * Byte 3 = 6
 */
#ifdef XK_CYRILLIC
#define XK_Cyrillic_GHE_bar           0x1000492  /* U+0492 CYRILLIC CAPITAL LETTER GHE WITH STROKE */
#define XK_Cyrillic_ghe_bar           0x1000493  /* U+0493 CYRILLIC SMALL LETTER GHE WITH STROKE */
#define XK_Cyrillic_ZHE_descender     0x1000496  /* U+0496 CYRILLIC CAPITAL LETTER ZHE WITH DESCENDER */
#define XK_Cyrillic_zhe_descender     0x1000497  /* U+0497 CYRILLIC SMALL LETTER ZHE WITH DESCENDER */
#define XK_Cyrillic_KA_descender      0x100049a  /* U+049A CYRILLIC CAPITAL LETTER KA WITH DESCENDER */
#define XK_Cyrillic_ka_descender      0x100049b  /* U+049B CYRILLIC SMALL LETTER KA WITH DESCENDER */
#define XK_Cyrillic_KA_vertstroke     0x100049c  /* U+049C CYRILLIC CAPITAL LETTER KA WITH VERTICAL STROKE */
#define XK_Cyrillic_ka_vertstroke     0x100049d  /* U+049D CYRILLIC SMALL LETTER KA WITH VERTICAL STROKE */
#define XK_Cyrillic_EN_descender      0x10004a2  /* U+04A2 CYRILLIC CAPITAL LETTER EN WITH DESCENDER */
#define XK_Cyrillic_en_descender      0x10004a3  /* U+04A3 CYRILLIC SMALL LETTER EN WITH DESCENDER */
#define XK_Cyrillic_U_straight        0x10004ae  /* U+04AE CYRILLIC CAPITAL LETTER STRAIGHT U */
#define XK_Cyrillic_u_straight        0x10004af  /* U+04AF CYRILLIC SMALL LETTER STRAIGHT U */
#define XK_Cyrillic_U_straight_bar    0x10004b0  /* U+04B0 CYRILLIC CAPITAL LETTER STRAIGHT U WITH STROKE */
#define XK_Cyrillic_u_straight_bar    0x10004b1  /* U+04B1 CYRILLIC SMALL LETTER STRAIGHT U WITH STROKE */
#define XK_Cyrillic_HA_descender      0x10004b2  /* U+04B2 CYRILLIC CAPITAL LETTER HA WITH DESCENDER */
#define XK_Cyrillic_ha_descender      0x10004b3  /* U+04B3 CYRILLIC SMALL LETTER HA WITH DESCENDER */
#define XK_Cyrillic_CHE_descender     0x10004b6  /* U+04B6 CYRILLIC CAPITAL LETTER CHE WITH DESCENDER */
#define XK_Cyrillic_che_descender     0x10004b7  /* U+04B7 CYRILLIC SMALL LETTER CHE WITH DESCENDER */
#define XK_Cyrillic_CHE_vertstroke    0x10004b8  /* U+04B8 CYRILLIC CAPITAL LETTER CHE WITH VERTICAL STROKE */
#define XK_Cyrillic_che_vertstroke    0x10004b9  /* U+04B9 CYRILLIC SMALL LETTER CHE WITH VERTICAL STROKE */
#define XK_Cyrillic_SHHA              0x10004ba  /* U+04BA CYRILLIC CAPITAL LETTER SHHA */
#define XK_Cyrillic_shha              0x10004bb  /* U+04BB CYRILLIC SMALL LETTER SHHA */

#define XK_Cyrillic_SCHWA             0x10004d8  /* U+04D8 CYRILLIC CAPITAL LETTER SCHWA */
#define XK_Cyrillic_schwa             0x10004d9  /* U+04D9 CYRILLIC SMALL LETTER SCHWA */
#define XK_Cyrillic_I_macron          0x10004e2  /* U+04E2 CYRILLIC CAPITAL LETTER I WITH MACRON */
#define XK_Cyrillic_i_macron          0x10004e3  /* U+04E3 CYRILLIC SMALL LETTER I WITH MACRON */
#define XK_Cyrillic_O_bar             0x10004e8  /* U+04E8 CYRILLIC CAPITAL LETTER BARRED O */
#define XK_Cyrillic_o_bar             0x10004e9  /* U+04E9 CYRILLIC SMALL LETTER BARRED O */
#define XK_Cyrillic_U_macron          0x10004ee  /* U+04EE CYRILLIC CAPITAL LETTER U WITH MACRON */
#define XK_Cyrillic_u_macron          0x10004ef  /* U+04EF CYRILLIC SMALL LETTER U WITH MACRON */

#define XK_Serbian_dje                   0x06a1  /* U+0452 CYRILLIC SMALL LETTER DJE */
#define XK_Macedonia_gje                 0x06a2  /* U+0453 CYRILLIC SMALL LETTER GJE */
#define XK_Cyrillic_io                   0x06a3  /* U+0451 CYRILLIC SMALL LETTER IO */
#define XK_Ukrainian_ie                  0x06a4  /* U+0454 CYRILLIC SMALL LETTER UKRAINIAN IE */
#define XK_Ukranian_je                   0x06a4  /* deprecated */
#define XK_Macedonia_dse                 0x06a5  /* U+0455 CYRILLIC SMALL LETTER DZE */
#define XK_Ukrainian_i                   0x06a6  /* U+0456 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I */
#define XK_Ukranian_i                    0x06a6  /* deprecated */
#define XK_Ukrainian_yi                  0x06a7  /* U+0457 CYRILLIC SMALL LETTER YI */
#define XK_Ukranian_yi                   0x06a7  /* deprecated */
#define XK_Cyrillic_je                   0x06a8  /* U+0458 CYRILLIC SMALL LETTER JE */
#define XK_Serbian_je                    0x06a8  /* deprecated */
#define XK_Cyrillic_lje                  0x06a9  /* U+0459 CYRILLIC SMALL LETTER LJE */
#define XK_Serbian_lje                   0x06a9  /* deprecated */
#define XK_Cyrillic_nje                  0x06aa  /* U+045A CYRILLIC SMALL LETTER NJE */
#define XK_Serbian_nje                   0x06aa  /* deprecated */
#define XK_Serbian_tshe                  0x06ab  /* U+045B CYRILLIC SMALL LETTER TSHE */
#define XK_Macedonia_kje                 0x06ac  /* U+045C CYRILLIC SMALL LETTER KJE */
#define XK_Serbian_dje                                 0x6a1
#define XK_Macedonia_gje                               0x6a2
#define XK_Cyrillic_io                                 0x6a3
#define XK_Ukrainian_ie                                0x6a4
#define XK_Ukranian_je                                 0x6a4  /* deprecated */
#define XK_Macedonia_dse                               0x6a5
#define XK_Ukrainian_i                                 0x6a6
#define XK_Ukranian_i                                  0x6a6  /* deprecated */
#define XK_Ukrainian_yi                                0x6a7
#define XK_Ukranian_yi                                 0x6a7  /* deprecated */
#define XK_Cyrillic_je                                 0x6a8
#define XK_Serbian_je                                  0x6a8  /* deprecated */
#define XK_Cyrillic_lje                                0x6a9
#define XK_Serbian_lje                                 0x6a9  /* deprecated */
#define XK_Cyrillic_nje                                0x6aa
#define XK_Serbian_nje                                 0x6aa  /* deprecated */
#define XK_Serbian_tshe                                0x6ab
#define XK_Macedonia_kje                               0x6ac
#define XK_Ukrainian_ghe_with_upturn     0x06ad  /* U+0491 CYRILLIC SMALL LETTER GHE WITH UPTURN */
#define XK_Byelorussian_shortu           0x06ae  /* U+045E CYRILLIC SMALL LETTER SHORT U */
#define XK_Cyrillic_dzhe                 0x06af  /* U+045F CYRILLIC SMALL LETTER DZHE */
#define XK_Serbian_dze                   0x06af  /* deprecated */
#define XK_numerosign                    0x06b0  /* U+2116 NUMERO SIGN */
#define XK_Serbian_DJE                   0x06b1  /* U+0402 CYRILLIC CAPITAL LETTER DJE */
#define XK_Macedonia_GJE                 0x06b2  /* U+0403 CYRILLIC CAPITAL LETTER GJE */
#define XK_Cyrillic_IO                   0x06b3  /* U+0401 CYRILLIC CAPITAL LETTER IO */
#define XK_Ukrainian_IE                  0x06b4  /* U+0404 CYRILLIC CAPITAL LETTER UKRAINIAN IE */
#define XK_Ukranian_JE                   0x06b4  /* deprecated */
#define XK_Macedonia_DSE                 0x06b5  /* U+0405 CYRILLIC CAPITAL LETTER DZE */
#define XK_Ukrainian_I                   0x06b6  /* U+0406 CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I */
#define XK_Ukranian_I                    0x06b6  /* deprecated */
#define XK_Ukrainian_YI                  0x06b7  /* U+0407 CYRILLIC CAPITAL LETTER YI */
#define XK_Ukranian_YI                   0x06b7  /* deprecated */
#define XK_Cyrillic_JE                   0x06b8  /* U+0408 CYRILLIC CAPITAL LETTER JE */
#define XK_Serbian_JE                    0x06b8  /* deprecated */
#define XK_Cyrillic_LJE                  0x06b9  /* U+0409 CYRILLIC CAPITAL LETTER LJE */
#define XK_Serbian_LJE                   0x06b9  /* deprecated */
#define XK_Cyrillic_NJE                  0x06ba  /* U+040A CYRILLIC CAPITAL LETTER NJE */
#define XK_Serbian_NJE                   0x06ba  /* deprecated */
#define XK_Serbian_TSHE                  0x06bb  /* U+040B CYRILLIC CAPITAL LETTER TSHE */
#define XK_Macedonia_KJE                 0x06bc  /* U+040C CYRILLIC CAPITAL LETTER KJE */
#define XK_Byelorussian_shortu                         0x6ae
#define XK_Cyrillic_dzhe                               0x6af
#define XK_Serbian_dze                                 0x6af  /* deprecated */
#define XK_numerosign                                  0x6b0
#define XK_Serbian_DJE                                 0x6b1
#define XK_Macedonia_GJE                               0x6b2
#define XK_Cyrillic_IO                                 0x6b3
#define XK_Ukrainian_IE                                0x6b4
#define XK_Ukranian_JE                                 0x6b4  /* deprecated */
#define XK_Macedonia_DSE                               0x6b5
#define XK_Ukrainian_I                                 0x6b6
#define XK_Ukranian_I                                  0x6b6  /* deprecated */
#define XK_Ukrainian_YI                                0x6b7
#define XK_Ukranian_YI                                 0x6b7  /* deprecated */
#define XK_Cyrillic_JE                                 0x6b8
#define XK_Serbian_JE                                  0x6b8  /* deprecated */
#define XK_Cyrillic_LJE                                0x6b9
#define XK_Serbian_LJE                                 0x6b9  /* deprecated */
#define XK_Cyrillic_NJE                                0x6ba
#define XK_Serbian_NJE                                 0x6ba  /* deprecated */
#define XK_Serbian_TSHE                                0x6bb
#define XK_Macedonia_KJE                               0x6bc
#define XK_Ukrainian_GHE_WITH_UPTURN     0x06bd  /* U+0490 CYRILLIC CAPITAL LETTER GHE WITH UPTURN */
#define XK_Byelorussian_SHORTU           0x06be  /* U+040E CYRILLIC CAPITAL LETTER SHORT U */
#define XK_Cyrillic_DZHE                 0x06bf  /* U+040F CYRILLIC CAPITAL LETTER DZHE */
#define XK_Serbian_DZE                   0x06bf  /* deprecated */
#define XK_Cyrillic_yu                   0x06c0  /* U+044E CYRILLIC SMALL LETTER YU */
#define XK_Cyrillic_a                    0x06c1  /* U+0430 CYRILLIC SMALL LETTER A */
#define XK_Cyrillic_be                   0x06c2  /* U+0431 CYRILLIC SMALL LETTER BE */
#define XK_Cyrillic_tse                  0x06c3  /* U+0446 CYRILLIC SMALL LETTER TSE */
#define XK_Cyrillic_de                   0x06c4  /* U+0434 CYRILLIC SMALL LETTER DE */
#define XK_Cyrillic_ie                   0x06c5  /* U+0435 CYRILLIC SMALL LETTER IE */
#define XK_Cyrillic_ef                   0x06c6  /* U+0444 CYRILLIC SMALL LETTER EF */
#define XK_Cyrillic_ghe                  0x06c7  /* U+0433 CYRILLIC SMALL LETTER GHE */
#define XK_Cyrillic_ha                   0x06c8  /* U+0445 CYRILLIC SMALL LETTER HA */
#define XK_Cyrillic_i                    0x06c9  /* U+0438 CYRILLIC SMALL LETTER I */
#define XK_Cyrillic_shorti               0x06ca  /* U+0439 CYRILLIC SMALL LETTER SHORT I */
#define XK_Cyrillic_ka                   0x06cb  /* U+043A CYRILLIC SMALL LETTER KA */
#define XK_Cyrillic_el                   0x06cc  /* U+043B CYRILLIC SMALL LETTER EL */
#define XK_Cyrillic_em                   0x06cd  /* U+043C CYRILLIC SMALL LETTER EM */
#define XK_Cyrillic_en                   0x06ce  /* U+043D CYRILLIC SMALL LETTER EN */
#define XK_Cyrillic_o                    0x06cf  /* U+043E CYRILLIC SMALL LETTER O */
#define XK_Cyrillic_pe                   0x06d0  /* U+043F CYRILLIC SMALL LETTER PE */
#define XK_Cyrillic_ya                   0x06d1  /* U+044F CYRILLIC SMALL LETTER YA */
#define XK_Cyrillic_er                   0x06d2  /* U+0440 CYRILLIC SMALL LETTER ER */
#define XK_Cyrillic_es                   0x06d3  /* U+0441 CYRILLIC SMALL LETTER ES */
#define XK_Cyrillic_te                   0x06d4  /* U+0442 CYRILLIC SMALL LETTER TE */
#define XK_Cyrillic_u                    0x06d5  /* U+0443 CYRILLIC SMALL LETTER U */
#define XK_Cyrillic_zhe                  0x06d6  /* U+0436 CYRILLIC SMALL LETTER ZHE */
#define XK_Cyrillic_ve                   0x06d7  /* U+0432 CYRILLIC SMALL LETTER VE */
#define XK_Cyrillic_softsign             0x06d8  /* U+044C CYRILLIC SMALL LETTER SOFT SIGN */
#define XK_Cyrillic_yeru                 0x06d9  /* U+044B CYRILLIC SMALL LETTER YERU */
#define XK_Cyrillic_ze                   0x06da  /* U+0437 CYRILLIC SMALL LETTER ZE */
#define XK_Cyrillic_sha                  0x06db  /* U+0448 CYRILLIC SMALL LETTER SHA */
#define XK_Cyrillic_e                    0x06dc  /* U+044D CYRILLIC SMALL LETTER E */
#define XK_Cyrillic_shcha                0x06dd  /* U+0449 CYRILLIC SMALL LETTER SHCHA */
#define XK_Cyrillic_che                  0x06de  /* U+0447 CYRILLIC SMALL LETTER CHE */
#define XK_Cyrillic_hardsign             0x06df  /* U+044A CYRILLIC SMALL LETTER HARD SIGN */
#define XK_Cyrillic_YU                   0x06e0  /* U+042E CYRILLIC CAPITAL LETTER YU */
#define XK_Cyrillic_A                    0x06e1  /* U+0410 CYRILLIC CAPITAL LETTER A */
#define XK_Cyrillic_BE                   0x06e2  /* U+0411 CYRILLIC CAPITAL LETTER BE */
#define XK_Cyrillic_TSE                  0x06e3  /* U+0426 CYRILLIC CAPITAL LETTER TSE */
#define XK_Cyrillic_DE                   0x06e4  /* U+0414 CYRILLIC CAPITAL LETTER DE */
#define XK_Cyrillic_IE                   0x06e5  /* U+0415 CYRILLIC CAPITAL LETTER IE */
#define XK_Cyrillic_EF                   0x06e6  /* U+0424 CYRILLIC CAPITAL LETTER EF */
#define XK_Cyrillic_GHE                  0x06e7  /* U+0413 CYRILLIC CAPITAL LETTER GHE */
#define XK_Cyrillic_HA                   0x06e8  /* U+0425 CYRILLIC CAPITAL LETTER HA */
#define XK_Cyrillic_I                    0x06e9  /* U+0418 CYRILLIC CAPITAL LETTER I */
#define XK_Cyrillic_SHORTI               0x06ea  /* U+0419 CYRILLIC CAPITAL LETTER SHORT I */
#define XK_Cyrillic_KA                   0x06eb  /* U+041A CYRILLIC CAPITAL LETTER KA */
#define XK_Cyrillic_EL                   0x06ec  /* U+041B CYRILLIC CAPITAL LETTER EL */
#define XK_Cyrillic_EM                   0x06ed  /* U+041C CYRILLIC CAPITAL LETTER EM */
#define XK_Cyrillic_EN                   0x06ee  /* U+041D CYRILLIC CAPITAL LETTER EN */
#define XK_Cyrillic_O                    0x06ef  /* U+041E CYRILLIC CAPITAL LETTER O */
#define XK_Cyrillic_PE                   0x06f0  /* U+041F CYRILLIC CAPITAL LETTER PE */
#define XK_Cyrillic_YA                   0x06f1  /* U+042F CYRILLIC CAPITAL LETTER YA */
#define XK_Cyrillic_ER                   0x06f2  /* U+0420 CYRILLIC CAPITAL LETTER ER */
#define XK_Cyrillic_ES                   0x06f3  /* U+0421 CYRILLIC CAPITAL LETTER ES */
#define XK_Cyrillic_TE                   0x06f4  /* U+0422 CYRILLIC CAPITAL LETTER TE */
#define XK_Cyrillic_U                    0x06f5  /* U+0423 CYRILLIC CAPITAL LETTER U */
#define XK_Cyrillic_ZHE                  0x06f6  /* U+0416 CYRILLIC CAPITAL LETTER ZHE */
#define XK_Cyrillic_VE                   0x06f7  /* U+0412 CYRILLIC CAPITAL LETTER VE */
#define XK_Cyrillic_SOFTSIGN             0x06f8  /* U+042C CYRILLIC CAPITAL LETTER SOFT SIGN */
#define XK_Cyrillic_YERU                 0x06f9  /* U+042B CYRILLIC CAPITAL LETTER YERU */
#define XK_Cyrillic_ZE                   0x06fa  /* U+0417 CYRILLIC CAPITAL LETTER ZE */
#define XK_Cyrillic_SHA                  0x06fb  /* U+0428 CYRILLIC CAPITAL LETTER SHA */
#define XK_Cyrillic_E                    0x06fc  /* U+042D CYRILLIC CAPITAL LETTER E */
#define XK_Cyrillic_SHCHA                0x06fd  /* U+0429 CYRILLIC CAPITAL LETTER SHCHA */
#define XK_Cyrillic_CHE                  0x06fe  /* U+0427 CYRILLIC CAPITAL LETTER CHE */
#define XK_Cyrillic_HARDSIGN             0x06ff  /* U+042A CYRILLIC CAPITAL LETTER HARD SIGN */
#define XK_Byelorussian_SHORTU                         0x6be
#define XK_Cyrillic_DZHE                               0x6bf
#define XK_Serbian_DZE                                 0x6bf  /* deprecated */
#define XK_Cyrillic_yu                                 0x6c0
#define XK_Cyrillic_a                                  0x6c1
#define XK_Cyrillic_be                                 0x6c2
#define XK_Cyrillic_tse                                0x6c3
#define XK_Cyrillic_de                                 0x6c4
#define XK_Cyrillic_ie                                 0x6c5
#define XK_Cyrillic_ef                                 0x6c6
#define XK_Cyrillic_ghe                                0x6c7
#define XK_Cyrillic_ha                                 0x6c8
#define XK_Cyrillic_i                                  0x6c9
#define XK_Cyrillic_shorti                             0x6ca
#define XK_Cyrillic_ka                                 0x6cb
#define XK_Cyrillic_el                                 0x6cc
#define XK_Cyrillic_em                                 0x6cd
#define XK_Cyrillic_en                                 0x6ce
#define XK_Cyrillic_o                                  0x6cf
#define XK_Cyrillic_pe                                 0x6d0
#define XK_Cyrillic_ya                                 0x6d1
#define XK_Cyrillic_er                                 0x6d2
#define XK_Cyrillic_es                                 0x6d3
#define XK_Cyrillic_te                                 0x6d4
#define XK_Cyrillic_u                                  0x6d5
#define XK_Cyrillic_zhe                                0x6d6
#define XK_Cyrillic_ve                                 0x6d7
#define XK_Cyrillic_softsign                           0x6d8
#define XK_Cyrillic_yeru                               0x6d9
#define XK_Cyrillic_ze                                 0x6da
#define XK_Cyrillic_sha                                0x6db
#define XK_Cyrillic_e                                  0x6dc
#define XK_Cyrillic_shcha                              0x6dd
#define XK_Cyrillic_che                                0x6de
#define XK_Cyrillic_hardsign                           0x6df
#define XK_Cyrillic_YU                                 0x6e0
#define XK_Cyrillic_A                                  0x6e1
#define XK_Cyrillic_BE                                 0x6e2
#define XK_Cyrillic_TSE                                0x6e3
#define XK_Cyrillic_DE                                 0x6e4
#define XK_Cyrillic_IE                                 0x6e5
#define XK_Cyrillic_EF                                 0x6e6
#define XK_Cyrillic_GHE                                0x6e7
#define XK_Cyrillic_HA                                 0x6e8
#define XK_Cyrillic_I                                  0x6e9
#define XK_Cyrillic_SHORTI                             0x6ea
#define XK_Cyrillic_KA                                 0x6eb
#define XK_Cyrillic_EL                                 0x6ec
#define XK_Cyrillic_EM                                 0x6ed
#define XK_Cyrillic_EN                                 0x6ee
#define XK_Cyrillic_O                                  0x6ef
#define XK_Cyrillic_PE                                 0x6f0
#define XK_Cyrillic_YA                                 0x6f1
#define XK_Cyrillic_ER                                 0x6f2
#define XK_Cyrillic_ES                                 0x6f3
#define XK_Cyrillic_TE                                 0x6f4
#define XK_Cyrillic_U                                  0x6f5
#define XK_Cyrillic_ZHE                                0x6f6
#define XK_Cyrillic_VE                                 0x6f7
#define XK_Cyrillic_SOFTSIGN                           0x6f8
#define XK_Cyrillic_YERU                               0x6f9
#define XK_Cyrillic_ZE                                 0x6fa
#define XK_Cyrillic_SHA                                0x6fb
#define XK_Cyrillic_E                                  0x6fc
#define XK_Cyrillic_SHCHA                              0x6fd
#define XK_Cyrillic_CHE                                0x6fe
#define XK_Cyrillic_HARDSIGN                           0x6ff
#endif /* XK_CYRILLIC */

/*
 * Greek
 * (based on an early draft of, and not quite identical to, ISO/IEC 8859-7)
 * Byte 3 = 7
 */

#ifdef XK_GREEK
#define XK_Greek_ALPHAaccent             0x07a1  /* U+0386 GREEK CAPITAL LETTER ALPHA WITH TONOS */
#define XK_Greek_EPSILONaccent           0x07a2  /* U+0388 GREEK CAPITAL LETTER EPSILON WITH TONOS */
#define XK_Greek_ETAaccent               0x07a3  /* U+0389 GREEK CAPITAL LETTER ETA WITH TONOS */
#define XK_Greek_IOTAaccent              0x07a4  /* U+038A GREEK CAPITAL LETTER IOTA WITH TONOS */
#define XK_Greek_ALPHAaccent                           0x7a1
#define XK_Greek_EPSILONaccent                         0x7a2
#define XK_Greek_ETAaccent                             0x7a3
#define XK_Greek_IOTAaccent                            0x7a4
#define XK_Greek_IOTAdieresis            0x07a5  /* U+03AA GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
#define XK_Greek_IOTAdiaeresis           0x07a5  /* deprecated (old typo) */
#define XK_Greek_OMICRONaccent           0x07a7  /* U+038C GREEK CAPITAL LETTER OMICRON WITH TONOS */
#define XK_Greek_UPSILONaccent           0x07a8  /* U+038E GREEK CAPITAL LETTER UPSILON WITH TONOS */
#define XK_Greek_UPSILONdieresis         0x07a9  /* U+03AB GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA */
#define XK_Greek_OMEGAaccent             0x07ab  /* U+038F GREEK CAPITAL LETTER OMEGA WITH TONOS */
#define XK_Greek_accentdieresis          0x07ae  /* U+0385 GREEK DIALYTIKA TONOS */
#define XK_Greek_horizbar                0x07af  /* U+2015 HORIZONTAL BAR */
#define XK_Greek_alphaaccent             0x07b1  /* U+03AC GREEK SMALL LETTER ALPHA WITH TONOS */
#define XK_Greek_epsilonaccent           0x07b2  /* U+03AD GREEK SMALL LETTER EPSILON WITH TONOS */
#define XK_Greek_etaaccent               0x07b3  /* U+03AE GREEK SMALL LETTER ETA WITH TONOS */
#define XK_Greek_iotaaccent              0x07b4  /* U+03AF GREEK SMALL LETTER IOTA WITH TONOS */
#define XK_Greek_iotadieresis            0x07b5  /* U+03CA GREEK SMALL LETTER IOTA WITH DIALYTIKA */
#define XK_Greek_iotaaccentdieresis      0x07b6  /* U+0390 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS */
#define XK_Greek_omicronaccent           0x07b7  /* U+03CC GREEK SMALL LETTER OMICRON WITH TONOS */
#define XK_Greek_upsilonaccent           0x07b8  /* U+03CD GREEK SMALL LETTER UPSILON WITH TONOS */
#define XK_Greek_upsilondieresis         0x07b9  /* U+03CB GREEK SMALL LETTER UPSILON WITH DIALYTIKA */
#define XK_Greek_upsilonaccentdieresis   0x07ba  /* U+03B0 GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS */
#define XK_Greek_omegaaccent             0x07bb  /* U+03CE GREEK SMALL LETTER OMEGA WITH TONOS */
#define XK_Greek_ALPHA                   0x07c1  /* U+0391 GREEK CAPITAL LETTER ALPHA */
#define XK_Greek_BETA                    0x07c2  /* U+0392 GREEK CAPITAL LETTER BETA */
#define XK_Greek_GAMMA                   0x07c3  /* U+0393 GREEK CAPITAL LETTER GAMMA */
#define XK_Greek_DELTA                   0x07c4  /* U+0394 GREEK CAPITAL LETTER DELTA */
#define XK_Greek_EPSILON                 0x07c5  /* U+0395 GREEK CAPITAL LETTER EPSILON */
#define XK_Greek_ZETA                    0x07c6  /* U+0396 GREEK CAPITAL LETTER ZETA */
#define XK_Greek_ETA                     0x07c7  /* U+0397 GREEK CAPITAL LETTER ETA */
#define XK_Greek_THETA                   0x07c8  /* U+0398 GREEK CAPITAL LETTER THETA */
#define XK_Greek_IOTA                    0x07c9  /* U+0399 GREEK CAPITAL LETTER IOTA */
#define XK_Greek_KAPPA                   0x07ca  /* U+039A GREEK CAPITAL LETTER KAPPA */
#define XK_Greek_LAMDA                   0x07cb  /* U+039B GREEK CAPITAL LETTER LAMDA */
#define XK_Greek_LAMBDA                  0x07cb  /* non-deprecated alias for Greek_LAMDA */
#define XK_Greek_MU                      0x07cc  /* U+039C GREEK CAPITAL LETTER MU */
#define XK_Greek_NU                      0x07cd  /* U+039D GREEK CAPITAL LETTER NU */
#define XK_Greek_XI                      0x07ce  /* U+039E GREEK CAPITAL LETTER XI */
#define XK_Greek_OMICRON                 0x07cf  /* U+039F GREEK CAPITAL LETTER OMICRON */
#define XK_Greek_PI                      0x07d0  /* U+03A0 GREEK CAPITAL LETTER PI */
#define XK_Greek_RHO                     0x07d1  /* U+03A1 GREEK CAPITAL LETTER RHO */
#define XK_Greek_SIGMA                   0x07d2  /* U+03A3 GREEK CAPITAL LETTER SIGMA */
#define XK_Greek_TAU                     0x07d4  /* U+03A4 GREEK CAPITAL LETTER TAU */
#define XK_Greek_UPSILON                 0x07d5  /* U+03A5 GREEK CAPITAL LETTER UPSILON */
#define XK_Greek_PHI                     0x07d6  /* U+03A6 GREEK CAPITAL LETTER PHI */
#define XK_Greek_CHI                     0x07d7  /* U+03A7 GREEK CAPITAL LETTER CHI */
#define XK_Greek_PSI                     0x07d8  /* U+03A8 GREEK CAPITAL LETTER PSI */
#define XK_Greek_OMEGA                   0x07d9  /* U+03A9 GREEK CAPITAL LETTER OMEGA */
#define XK_Greek_alpha                   0x07e1  /* U+03B1 GREEK SMALL LETTER ALPHA */
#define XK_Greek_beta                    0x07e2  /* U+03B2 GREEK SMALL LETTER BETA */
#define XK_Greek_gamma                   0x07e3  /* U+03B3 GREEK SMALL LETTER GAMMA */
#define XK_Greek_delta                   0x07e4  /* U+03B4 GREEK SMALL LETTER DELTA */
#define XK_Greek_epsilon                 0x07e5  /* U+03B5 GREEK SMALL LETTER EPSILON */
#define XK_Greek_zeta                    0x07e6  /* U+03B6 GREEK SMALL LETTER ZETA */
#define XK_Greek_eta                     0x07e7  /* U+03B7 GREEK SMALL LETTER ETA */
#define XK_Greek_theta                   0x07e8  /* U+03B8 GREEK SMALL LETTER THETA */
#define XK_Greek_iota                    0x07e9  /* U+03B9 GREEK SMALL LETTER IOTA */
#define XK_Greek_kappa                   0x07ea  /* U+03BA GREEK SMALL LETTER KAPPA */
#define XK_Greek_lamda                   0x07eb  /* U+03BB GREEK SMALL LETTER LAMDA */
#define XK_Greek_lambda                  0x07eb  /* non-deprecated alias for Greek_lamda */
#define XK_Greek_mu                      0x07ec  /* U+03BC GREEK SMALL LETTER MU */
#define XK_Greek_nu                      0x07ed  /* U+03BD GREEK SMALL LETTER NU */
#define XK_Greek_xi                      0x07ee  /* U+03BE GREEK SMALL LETTER XI */
#define XK_Greek_omicron                 0x07ef  /* U+03BF GREEK SMALL LETTER OMICRON */
#define XK_Greek_pi                      0x07f0  /* U+03C0 GREEK SMALL LETTER PI */
#define XK_Greek_rho                     0x07f1  /* U+03C1 GREEK SMALL LETTER RHO */
#define XK_Greek_sigma                   0x07f2  /* U+03C3 GREEK SMALL LETTER SIGMA */
#define XK_Greek_finalsmallsigma         0x07f3  /* U+03C2 GREEK SMALL LETTER FINAL SIGMA */
#define XK_Greek_tau                     0x07f4  /* U+03C4 GREEK SMALL LETTER TAU */
#define XK_Greek_upsilon                 0x07f5  /* U+03C5 GREEK SMALL LETTER UPSILON */
#define XK_Greek_phi                     0x07f6  /* U+03C6 GREEK SMALL LETTER PHI */
#define XK_Greek_chi                     0x07f7  /* U+03C7 GREEK SMALL LETTER CHI */
#define XK_Greek_psi                     0x07f8  /* U+03C8 GREEK SMALL LETTER PSI */
#define XK_Greek_omega                   0x07f9  /* U+03C9 GREEK SMALL LETTER OMEGA */
#define XK_Greek_switch                  0xff7e  /* non-deprecated alias for Mode_switch */
#define XK_Greek_IOTAdiaeresis                         0x7a5
#define XK_Greek_OMICRONaccent                         0x7a7
#define XK_Greek_UPSILONaccent                         0x7a8
#define XK_Greek_UPSILONdieresis                       0x7a9
#define XK_Greek_OMEGAaccent                           0x7ab
#define XK_Greek_accentdieresis                        0x7ae
#define XK_Greek_horizbar                              0x7af
#define XK_Greek_alphaaccent                           0x7b1
#define XK_Greek_epsilonaccent                         0x7b2
#define XK_Greek_etaaccent                             0x7b3
#define XK_Greek_iotaaccent                            0x7b4
#define XK_Greek_iotadieresis                          0x7b5
#define XK_Greek_iotaaccentdieresis                    0x7b6
#define XK_Greek_omicronaccent                         0x7b7
#define XK_Greek_upsilonaccent                         0x7b8
#define XK_Greek_upsilondieresis                       0x7b9
#define XK_Greek_upsilonaccentdieresis                 0x7ba
#define XK_Greek_omegaaccent                           0x7bb
#define XK_Greek_ALPHA                                 0x7c1
#define XK_Greek_BETA                                  0x7c2
#define XK_Greek_GAMMA                                 0x7c3
#define XK_Greek_DELTA                                 0x7c4
#define XK_Greek_EPSILON                               0x7c5
#define XK_Greek_ZETA                                  0x7c6
#define XK_Greek_ETA                                   0x7c7
#define XK_Greek_THETA                                 0x7c8
#define XK_Greek_IOTA                                  0x7c9
#define XK_Greek_KAPPA                                 0x7ca
#define XK_Greek_LAMDA                                 0x7cb
#define XK_Greek_LAMBDA                                0x7cb
#define XK_Greek_MU                                    0x7cc
#define XK_Greek_NU                                    0x7cd
#define XK_Greek_XI                                    0x7ce
#define XK_Greek_OMICRON                               0x7cf
#define XK_Greek_PI                                    0x7d0
#define XK_Greek_RHO                                   0x7d1
#define XK_Greek_SIGMA                                 0x7d2
#define XK_Greek_TAU                                   0x7d4
#define XK_Greek_UPSILON                               0x7d5
#define XK_Greek_PHI                                   0x7d6
#define XK_Greek_CHI                                   0x7d7
#define XK_Greek_PSI                                   0x7d8
#define XK_Greek_OMEGA                                 0x7d9
#define XK_Greek_alpha                                 0x7e1
#define XK_Greek_beta                                  0x7e2
#define XK_Greek_gamma                                 0x7e3
#define XK_Greek_delta                                 0x7e4
#define XK_Greek_epsilon                               0x7e5
#define XK_Greek_zeta                                  0x7e6
#define XK_Greek_eta                                   0x7e7
#define XK_Greek_theta                                 0x7e8
#define XK_Greek_iota                                  0x7e9
#define XK_Greek_kappa                                 0x7ea
#define XK_Greek_lamda                                 0x7eb
#define XK_Greek_lambda                                0x7eb
#define XK_Greek_mu                                    0x7ec
#define XK_Greek_nu                                    0x7ed
#define XK_Greek_xi                                    0x7ee
#define XK_Greek_omicron                               0x7ef
#define XK_Greek_pi                                    0x7f0
#define XK_Greek_rho                                   0x7f1
#define XK_Greek_sigma                                 0x7f2
#define XK_Greek_finalsmallsigma                       0x7f3
#define XK_Greek_tau                                   0x7f4
#define XK_Greek_upsilon                               0x7f5
#define XK_Greek_phi                                   0x7f6
#define XK_Greek_chi                                   0x7f7
#define XK_Greek_psi                                   0x7f8
#define XK_Greek_omega                                 0x7f9
#define XK_Greek_switch         0xFF7E  /* Alias for mode_switch */
#endif /* XK_GREEK */

/*
 * Technical
 * (from the DEC VT330/VT420 Technical Character Set, http://vt100.net/charsets/technical.html)
 * Byte 3 = 8
 */

#ifdef XK_TECHNICAL
#define XK_leftradical                   0x08a1  /* U+23B7 RADICAL SYMBOL BOTTOM */
#define XK_topleftradical                0x08a2  /*(U+250C BOX DRAWINGS LIGHT DOWN AND RIGHT)*/
#define XK_horizconnector                0x08a3  /*(U+2500 BOX DRAWINGS LIGHT HORIZONTAL)*/
#define XK_topintegral                   0x08a4  /* U+2320 TOP HALF INTEGRAL */
#define XK_botintegral                   0x08a5  /* U+2321 BOTTOM HALF INTEGRAL */
#define XK_vertconnector                 0x08a6  /*(U+2502 BOX DRAWINGS LIGHT VERTICAL)*/
#define XK_topleftsqbracket              0x08a7  /* U+23A1 LEFT SQUARE BRACKET UPPER CORNER */
#define XK_botleftsqbracket              0x08a8  /* U+23A3 LEFT SQUARE BRACKET LOWER CORNER */
#define XK_toprightsqbracket             0x08a9  /* U+23A4 RIGHT SQUARE BRACKET UPPER CORNER */
#define XK_botrightsqbracket             0x08aa  /* U+23A6 RIGHT SQUARE BRACKET LOWER CORNER */
#define XK_topleftparens                 0x08ab  /* U+239B LEFT PARENTHESIS UPPER HOOK */
#define XK_botleftparens                 0x08ac  /* U+239D LEFT PARENTHESIS LOWER HOOK */
#define XK_toprightparens                0x08ad  /* U+239E RIGHT PARENTHESIS UPPER HOOK */
#define XK_botrightparens                0x08ae  /* U+23A0 RIGHT PARENTHESIS LOWER HOOK */
#define XK_leftmiddlecurlybrace          0x08af  /* U+23A8 LEFT CURLY BRACKET MIDDLE PIECE */
#define XK_rightmiddlecurlybrace         0x08b0  /* U+23AC RIGHT CURLY BRACKET MIDDLE PIECE */
#define XK_topleftsummation              0x08b1
#define XK_botleftsummation              0x08b2
#define XK_topvertsummationconnector     0x08b3
#define XK_botvertsummationconnector     0x08b4
#define XK_toprightsummation             0x08b5
#define XK_botrightsummation             0x08b6
#define XK_rightmiddlesummation          0x08b7
#define XK_lessthanequal                 0x08bc  /* U+2264 LESS-THAN OR EQUAL TO */
#define XK_notequal                      0x08bd  /* U+2260 NOT EQUAL TO */
#define XK_greaterthanequal              0x08be  /* U+2265 GREATER-THAN OR EQUAL TO */
#define XK_integral                      0x08bf  /* U+222B INTEGRAL */
#define XK_therefore                     0x08c0  /* U+2234 THEREFORE */
#define XK_variation                     0x08c1  /* U+221D PROPORTIONAL TO */
#define XK_infinity                      0x08c2  /* U+221E INFINITY */
#define XK_nabla                         0x08c5  /* U+2207 NABLA */
#define XK_approximate                   0x08c8  /* U+223C TILDE OPERATOR */
#define XK_similarequal                  0x08c9  /* U+2243 ASYMPTOTICALLY EQUAL TO */
#define XK_ifonlyif                      0x08cd  /* U+21D4 LEFT RIGHT DOUBLE ARROW */
#define XK_implies                       0x08ce  /* U+21D2 RIGHTWARDS DOUBLE ARROW */
#define XK_identical                     0x08cf  /* U+2261 IDENTICAL TO */
#define XK_radical                       0x08d6  /* U+221A SQUARE ROOT */
#define XK_includedin                    0x08da  /* U+2282 SUBSET OF */
#define XK_includes                      0x08db  /* U+2283 SUPERSET OF */
#define XK_intersection                  0x08dc  /* U+2229 INTERSECTION */
#define XK_union                         0x08dd  /* U+222A UNION */
#define XK_logicaland                    0x08de  /* U+2227 LOGICAL AND */
#define XK_logicalor                     0x08df  /* U+2228 LOGICAL OR */
#define XK_partialderivative             0x08ef  /* U+2202 PARTIAL DIFFERENTIAL */
#define XK_function                      0x08f6  /* U+0192 LATIN SMALL LETTER F WITH HOOK */
#define XK_leftarrow                     0x08fb  /* U+2190 LEFTWARDS ARROW */
#define XK_uparrow                       0x08fc  /* U+2191 UPWARDS ARROW */
#define XK_rightarrow                    0x08fd  /* U+2192 RIGHTWARDS ARROW */
#define XK_downarrow                     0x08fe  /* U+2193 DOWNWARDS ARROW */
#define XK_leftradical                                 0x8a1
#define XK_topleftradical                              0x8a2
#define XK_horizconnector                              0x8a3
#define XK_topintegral                                 0x8a4
#define XK_botintegral                                 0x8a5
#define XK_vertconnector                               0x8a6
#define XK_topleftsqbracket                            0x8a7
#define XK_botleftsqbracket                            0x8a8
#define XK_toprightsqbracket                           0x8a9
#define XK_botrightsqbracket                           0x8aa
#define XK_topleftparens                               0x8ab
#define XK_botleftparens                               0x8ac
#define XK_toprightparens                              0x8ad
#define XK_botrightparens                              0x8ae
#define XK_leftmiddlecurlybrace                        0x8af
#define XK_rightmiddlecurlybrace                       0x8b0
#define XK_topleftsummation                            0x8b1
#define XK_botleftsummation                            0x8b2
#define XK_topvertsummationconnector                   0x8b3
#define XK_botvertsummationconnector                   0x8b4
#define XK_toprightsummation                           0x8b5
#define XK_botrightsummation                           0x8b6
#define XK_rightmiddlesummation                        0x8b7
#define XK_lessthanequal                               0x8bc
#define XK_notequal                                    0x8bd
#define XK_greaterthanequal                            0x8be
#define XK_integral                                    0x8bf
#define XK_therefore                                   0x8c0
#define XK_variation                                   0x8c1
#define XK_infinity                                    0x8c2
#define XK_nabla                                       0x8c5
#define XK_approximate                                 0x8c8
#define XK_similarequal                                0x8c9
#define XK_ifonlyif                                    0x8cd
#define XK_implies                                     0x8ce
#define XK_identical                                   0x8cf
#define XK_radical                                     0x8d6
#define XK_includedin                                  0x8da
#define XK_includes                                    0x8db
#define XK_intersection                                0x8dc
#define XK_union                                       0x8dd
#define XK_logicaland                                  0x8de
#define XK_logicalor                                   0x8df
#define XK_partialderivative                           0x8ef
#define XK_function                                    0x8f6
#define XK_leftarrow                                   0x8fb
#define XK_uparrow                                     0x8fc
#define XK_rightarrow                                  0x8fd
#define XK_downarrow                                   0x8fe
#endif /* XK_TECHNICAL */

/*
 * Special
 *  Special
 * (from the DEC VT100 Special Graphics Character Set)
 * Byte 3 = 9
 *  Byte 3 = 9
 */

#ifdef XK_SPECIAL
#define XK_blank                         0x09df
#define XK_soliddiamond                  0x09e0  /* U+25C6 BLACK DIAMOND */
#define XK_checkerboard                  0x09e1  /* U+2592 MEDIUM SHADE */
#define XK_ht                            0x09e2  /* U+2409 SYMBOL FOR HORIZONTAL TABULATION */
#define XK_ff                            0x09e3  /* U+240C SYMBOL FOR FORM FEED */
#define XK_cr                            0x09e4  /* U+240D SYMBOL FOR CARRIAGE RETURN */
#define XK_lf                            0x09e5  /* U+240A SYMBOL FOR LINE FEED */
#define XK_nl                            0x09e8  /* U+2424 SYMBOL FOR NEWLINE */
#define XK_vt                            0x09e9  /* U+240B SYMBOL FOR VERTICAL TABULATION */
#define XK_lowrightcorner                0x09ea  /* U+2518 BOX DRAWINGS LIGHT UP AND LEFT */
#define XK_uprightcorner                 0x09eb  /* U+2510 BOX DRAWINGS LIGHT DOWN AND LEFT */
#define XK_upleftcorner                  0x09ec  /* U+250C BOX DRAWINGS LIGHT DOWN AND RIGHT */
#define XK_lowleftcorner                 0x09ed  /* U+2514 BOX DRAWINGS LIGHT UP AND RIGHT */
#define XK_crossinglines                 0x09ee  /* U+253C BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
#define XK_horizlinescan1                0x09ef  /* U+23BA HORIZONTAL SCAN LINE-1 */
#define XK_horizlinescan3                0x09f0  /* U+23BB HORIZONTAL SCAN LINE-3 */
#define XK_horizlinescan5                0x09f1  /* U+2500 BOX DRAWINGS LIGHT HORIZONTAL */
#define XK_horizlinescan7                0x09f2  /* U+23BC HORIZONTAL SCAN LINE-7 */
#define XK_horizlinescan9                0x09f3  /* U+23BD HORIZONTAL SCAN LINE-9 */
#define XK_leftt                         0x09f4  /* U+251C BOX DRAWINGS LIGHT VERTICAL AND RIGHT */
#define XK_rightt                        0x09f5  /* U+2524 BOX DRAWINGS LIGHT VERTICAL AND LEFT */
#define XK_bott                          0x09f6  /* U+2534 BOX DRAWINGS LIGHT UP AND HORIZONTAL */
#define XK_topt                          0x09f7  /* U+252C BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */
#define XK_vertbar                       0x09f8  /* U+2502 BOX DRAWINGS LIGHT VERTICAL */
#define XK_blank                                       0x9df
#define XK_soliddiamond                                0x9e0
#define XK_checkerboard                                0x9e1
#define XK_ht                                          0x9e2
#define XK_ff                                          0x9e3
#define XK_cr                                          0x9e4
#define XK_lf                                          0x9e5
#define XK_nl                                          0x9e8
#define XK_vt                                          0x9e9
#define XK_lowrightcorner                              0x9ea
#define XK_uprightcorner                               0x9eb
#define XK_upleftcorner                                0x9ec
#define XK_lowleftcorner                               0x9ed
#define XK_crossinglines                               0x9ee
#define XK_horizlinescan1                              0x9ef
#define XK_horizlinescan3                              0x9f0
#define XK_horizlinescan5                              0x9f1
#define XK_horizlinescan7                              0x9f2
#define XK_horizlinescan9                              0x9f3
#define XK_leftt                                       0x9f4
#define XK_rightt                                      0x9f5
#define XK_bott                                        0x9f6
#define XK_topt                                        0x9f7
#define XK_vertbar                                     0x9f8
#endif /* XK_SPECIAL */

/*
 * Publishing
 *  Publishing
 * (these are probably from a long forgotten DEC Publishing
 * font that once shipped with DECwrite)
 * Byte 3 = 0x0a
 *  Byte 3 = a
 */

#ifdef XK_PUBLISHING
#define XK_emspace                       0x0aa1  /* U+2003 EM SPACE */
#define XK_enspace                       0x0aa2  /* U+2002 EN SPACE */
#define XK_em3space                      0x0aa3  /* U+2004 THREE-PER-EM SPACE */
#define XK_em4space                      0x0aa4  /* U+2005 FOUR-PER-EM SPACE */
#define XK_digitspace                    0x0aa5  /* U+2007 FIGURE SPACE */
#define XK_punctspace                    0x0aa6  /* U+2008 PUNCTUATION SPACE */
#define XK_thinspace                     0x0aa7  /* U+2009 THIN SPACE */
#define XK_hairspace                     0x0aa8  /* U+200A HAIR SPACE */
#define XK_emdash                        0x0aa9  /* U+2014 EM DASH */
#define XK_endash                        0x0aaa  /* U+2013 EN DASH */
#define XK_signifblank                   0x0aac  /*(U+2423 OPEN BOX)*/
#define XK_ellipsis                      0x0aae  /* U+2026 HORIZONTAL ELLIPSIS */
#define XK_doubbaselinedot               0x0aaf  /* U+2025 TWO DOT LEADER */
#define XK_onethird                      0x0ab0  /* U+2153 VULGAR FRACTION ONE THIRD */
#define XK_twothirds                     0x0ab1  /* U+2154 VULGAR FRACTION TWO THIRDS */
#define XK_onefifth                      0x0ab2  /* U+2155 VULGAR FRACTION ONE FIFTH */
#define XK_twofifths                     0x0ab3  /* U+2156 VULGAR FRACTION TWO FIFTHS */
#define XK_threefifths                   0x0ab4  /* U+2157 VULGAR FRACTION THREE FIFTHS */
#define XK_fourfifths                    0x0ab5  /* U+2158 VULGAR FRACTION FOUR FIFTHS */
#define XK_onesixth                      0x0ab6  /* U+2159 VULGAR FRACTION ONE SIXTH */
#define XK_fivesixths                    0x0ab7  /* U+215A VULGAR FRACTION FIVE SIXTHS */
#define XK_careof                        0x0ab8  /* U+2105 CARE OF */
#define XK_figdash                       0x0abb  /* U+2012 FIGURE DASH */
#define XK_leftanglebracket              0x0abc  /*(U+2329 LEFT-POINTING ANGLE BRACKET)*/
#define XK_decimalpoint                  0x0abd  /*(U+002E FULL STOP)*/
#define XK_rightanglebracket             0x0abe  /*(U+232A RIGHT-POINTING ANGLE BRACKET)*/
#define XK_marker                        0x0abf
#define XK_oneeighth                     0x0ac3  /* U+215B VULGAR FRACTION ONE EIGHTH */
#define XK_threeeighths                  0x0ac4  /* U+215C VULGAR FRACTION THREE EIGHTHS */
#define XK_fiveeighths                   0x0ac5  /* U+215D VULGAR FRACTION FIVE EIGHTHS */
#define XK_seveneighths                  0x0ac6  /* U+215E VULGAR FRACTION SEVEN EIGHTHS */
#define XK_trademark                     0x0ac9  /* U+2122 TRADE MARK SIGN */
#define XK_signaturemark                 0x0aca  /*(U+2613 SALTIRE)*/
#define XK_trademarkincircle             0x0acb
#define XK_leftopentriangle              0x0acc  /*(U+25C1 WHITE LEFT-POINTING TRIANGLE)*/
#define XK_rightopentriangle             0x0acd  /*(U+25B7 WHITE RIGHT-POINTING TRIANGLE)*/
#define XK_emopencircle                  0x0ace  /*(U+25CB WHITE CIRCLE)*/
#define XK_emopenrectangle               0x0acf  /*(U+25AF WHITE VERTICAL RECTANGLE)*/
#define XK_leftsinglequotemark           0x0ad0  /* U+2018 LEFT SINGLE QUOTATION MARK */
#define XK_rightsinglequotemark          0x0ad1  /* U+2019 RIGHT SINGLE QUOTATION MARK */
#define XK_leftdoublequotemark           0x0ad2  /* U+201C LEFT DOUBLE QUOTATION MARK */
#define XK_rightdoublequotemark          0x0ad3  /* U+201D RIGHT DOUBLE QUOTATION MARK */
#define XK_prescription                  0x0ad4  /* U+211E PRESCRIPTION TAKE */
#define XK_emspace                                     0xaa1
#define XK_enspace                                     0xaa2
#define XK_em3space                                    0xaa3
#define XK_em4space                                    0xaa4
#define XK_digitspace                                  0xaa5
#define XK_punctspace                                  0xaa6
#define XK_thinspace                                   0xaa7
#define XK_hairspace                                   0xaa8
#define XK_emdash                                      0xaa9
#define XK_endash                                      0xaaa
#define XK_signifblank                                 0xaac
#define XK_ellipsis                                    0xaae
#define XK_doubbaselinedot                             0xaaf
#define XK_onethird                                    0xab0
#define XK_twothirds                                   0xab1
#define XK_onefifth                                    0xab2
#define XK_twofifths                                   0xab3
#define XK_threefifths                                 0xab4
#define XK_fourfifths                                  0xab5
#define XK_onesixth                                    0xab6
#define XK_fivesixths                                  0xab7
#define XK_careof                                      0xab8
#define XK_figdash                                     0xabb
#define XK_leftanglebracket                            0xabc
#define XK_decimalpoint                                0xabd
#define XK_rightanglebracket                           0xabe
#define XK_marker                                      0xabf
#define XK_oneeighth                                   0xac3
#define XK_threeeighths                                0xac4
#define XK_fiveeighths                                 0xac5
#define XK_seveneighths                                0xac6
#define XK_trademark                                   0xac9
#define XK_signaturemark                               0xaca
#define XK_trademarkincircle                           0xacb
#define XK_leftopentriangle                            0xacc
#define XK_rightopentriangle                           0xacd
#define XK_emopencircle                                0xace
#define XK_emopenrectangle                             0xacf
#define XK_leftsinglequotemark                         0xad0
#define XK_rightsinglequotemark                        0xad1
#define XK_leftdoublequotemark                         0xad2
#define XK_rightdoublequotemark                        0xad3
#define XK_prescription                                0xad4
#define XK_permille                      0x0ad5  /* U+2030 PER MILLE SIGN */
#define XK_minutes                       0x0ad6  /* U+2032 PRIME */
#define XK_seconds                       0x0ad7  /* U+2033 DOUBLE PRIME */
#define XK_latincross                    0x0ad9  /* U+271D LATIN CROSS */
#define XK_hexagram                      0x0ada
#define XK_filledrectbullet              0x0adb  /*(U+25AC BLACK RECTANGLE)*/
#define XK_filledlefttribullet           0x0adc  /*(U+25C0 BLACK LEFT-POINTING TRIANGLE)*/
#define XK_filledrighttribullet          0x0add  /*(U+25B6 BLACK RIGHT-POINTING TRIANGLE)*/
#define XK_emfilledcircle                0x0ade  /*(U+25CF BLACK CIRCLE)*/
#define XK_emfilledrect                  0x0adf  /*(U+25AE BLACK VERTICAL RECTANGLE)*/
#define XK_enopencircbullet              0x0ae0  /*(U+25E6 WHITE BULLET)*/
#define XK_enopensquarebullet            0x0ae1  /*(U+25AB WHITE SMALL SQUARE)*/
#define XK_openrectbullet                0x0ae2  /*(U+25AD WHITE RECTANGLE)*/
#define XK_opentribulletup               0x0ae3  /*(U+25B3 WHITE UP-POINTING TRIANGLE)*/
#define XK_opentribulletdown             0x0ae4  /*(U+25BD WHITE DOWN-POINTING TRIANGLE)*/
#define XK_openstar                      0x0ae5  /*(U+2606 WHITE STAR)*/
#define XK_enfilledcircbullet            0x0ae6  /*(U+2022 BULLET)*/
#define XK_enfilledsqbullet              0x0ae7  /*(U+25AA BLACK SMALL SQUARE)*/
#define XK_filledtribulletup             0x0ae8  /*(U+25B2 BLACK UP-POINTING TRIANGLE)*/
#define XK_filledtribulletdown           0x0ae9  /*(U+25BC BLACK DOWN-POINTING TRIANGLE)*/
#define XK_leftpointer                   0x0aea  /*(U+261C WHITE LEFT POINTING INDEX)*/
#define XK_rightpointer                  0x0aeb  /*(U+261E WHITE RIGHT POINTING INDEX)*/
#define XK_club                          0x0aec  /* U+2663 BLACK CLUB SUIT */
#define XK_diamond                       0x0aed  /* U+2666 BLACK DIAMOND SUIT */
#define XK_heart                         0x0aee  /* U+2665 BLACK HEART SUIT */
#define XK_maltesecross                  0x0af0  /* U+2720 MALTESE CROSS */
#define XK_dagger                        0x0af1  /* U+2020 DAGGER */
#define XK_doubledagger                  0x0af2  /* U+2021 DOUBLE DAGGER */
#define XK_checkmark                     0x0af3  /* U+2713 CHECK MARK */
#define XK_ballotcross                   0x0af4  /* U+2717 BALLOT X */
#define XK_musicalsharp                  0x0af5  /* U+266F MUSIC SHARP SIGN */
#define XK_musicalflat                   0x0af6  /* U+266D MUSIC FLAT SIGN */
#define XK_malesymbol                    0x0af7  /* U+2642 MALE SIGN */
#define XK_femalesymbol                  0x0af8  /* U+2640 FEMALE SIGN */
#define XK_telephone                     0x0af9  /* U+260E BLACK TELEPHONE */
#define XK_telephonerecorder             0x0afa  /* U+2315 TELEPHONE RECORDER */
#define XK_phonographcopyright           0x0afb  /* U+2117 SOUND RECORDING COPYRIGHT */
#define XK_caret                         0x0afc  /* U+2038 CARET */
#define XK_singlelowquotemark            0x0afd  /* U+201A SINGLE LOW-9 QUOTATION MARK */
#define XK_doublelowquotemark            0x0afe  /* U+201E DOUBLE LOW-9 QUOTATION MARK */
#define XK_cursor                        0x0aff
#define XK_minutes                                     0xad6
#define XK_seconds                                     0xad7
#define XK_latincross                                  0xad9
#define XK_hexagram                                    0xada
#define XK_filledrectbullet                            0xadb
#define XK_filledlefttribullet                         0xadc
#define XK_filledrighttribullet                        0xadd
#define XK_emfilledcircle                              0xade
#define XK_emfilledrect                                0xadf
#define XK_enopencircbullet                            0xae0
#define XK_enopensquarebullet                          0xae1
#define XK_openrectbullet                              0xae2
#define XK_opentribulletup                             0xae3
#define XK_opentribulletdown                           0xae4
#define XK_openstar                                    0xae5
#define XK_enfilledcircbullet                          0xae6
#define XK_enfilledsqbullet                            0xae7
#define XK_filledtribulletup                           0xae8
#define XK_filledtribulletdown                         0xae9
#define XK_leftpointer                                 0xaea
#define XK_rightpointer                                0xaeb
#define XK_club                                        0xaec
#define XK_diamond                                     0xaed
#define XK_heart                                       0xaee
#define XK_maltesecross                                0xaf0
#define XK_dagger                                      0xaf1
#define XK_doubledagger                                0xaf2
#define XK_checkmark                                   0xaf3
#define XK_ballotcross                                 0xaf4
#define XK_musicalsharp                                0xaf5
#define XK_musicalflat                                 0xaf6
#define XK_malesymbol                                  0xaf7
#define XK_femalesymbol                                0xaf8
#define XK_telephone                                   0xaf9
#define XK_telephonerecorder                           0xafa
#define XK_phonographcopyright                         0xafb
#define XK_caret                                       0xafc
#define XK_singlelowquotemark                          0xafd
#define XK_doublelowquotemark                          0xafe
#define XK_cursor                                      0xaff
#endif /* XK_PUBLISHING */

/*
 * APL
 * Byte 3 = 0x0b
 *  APL
 *  Byte 3 = b
 */

#ifdef XK_APL
#define XK_leftcaret                     0x0ba3  /*(U+003C LESS-THAN SIGN)*/
#define XK_rightcaret                    0x0ba6  /*(U+003E GREATER-THAN SIGN)*/
#define XK_downcaret                     0x0ba8  /*(U+2228 LOGICAL OR)*/
#define XK_upcaret                       0x0ba9  /*(U+2227 LOGICAL AND)*/
#define XK_overbar                       0x0bc0  /*(U+00AF MACRON)*/
#define XK_downtack                      0x0bc2  /* U+22A4 DOWN TACK */
#define XK_upshoe                        0x0bc3  /*(U+2229 INTERSECTION)*/
#define XK_downstile                     0x0bc4  /* U+230A LEFT FLOOR */
#define XK_underbar                      0x0bc6  /*(U+005F LOW LINE)*/
#define XK_jot                           0x0bca  /* U+2218 RING OPERATOR */
#define XK_quad                          0x0bcc  /* U+2395 APL FUNCTIONAL SYMBOL QUAD */
#define XK_uptack                        0x0bce  /* U+22A5 UP TACK */
#define XK_circle                        0x0bcf  /* U+25CB WHITE CIRCLE */
#define XK_upstile                       0x0bd3  /* U+2308 LEFT CEILING */
#define XK_downshoe                      0x0bd6  /*(U+222A UNION)*/
#define XK_rightshoe                     0x0bd8  /*(U+2283 SUPERSET OF)*/
#define XK_leftshoe                      0x0bda  /*(U+2282 SUBSET OF)*/
#define XK_lefttack                      0x0bdc  /* U+22A3 LEFT TACK */
#define XK_righttack                     0x0bfc  /* U+22A2 RIGHT TACK */
#define XK_leftcaret                                   0xba3
#define XK_rightcaret                                  0xba6
#define XK_downcaret                                   0xba8
#define XK_upcaret                                     0xba9
#define XK_overbar                                     0xbc0
#define XK_downtack                                    0xbc2
#define XK_upshoe                                      0xbc3
#define XK_downstile                                   0xbc4
#define XK_underbar                                    0xbc6
#define XK_jot                                         0xbca
#define XK_quad                                        0xbcc
#define XK_uptack                                      0xbce
#define XK_circle                                      0xbcf
#define XK_upstile                                     0xbd3
#define XK_downshoe                                    0xbd6
#define XK_rightshoe                                   0xbd8
#define XK_leftshoe                                    0xbda
#define XK_lefttack                                    0xbdc
#define XK_righttack                                   0xbfc
#endif /* XK_APL */

/*
 * Hebrew
 * Byte 3 = 0x0c
 * Byte 3 = c
 */

#ifdef XK_HEBREW
#define XK_hebrew_doublelowline          0x0cdf  /* U+2017 DOUBLE LOW LINE */
#define XK_hebrew_aleph                  0x0ce0  /* U+05D0 HEBREW LETTER ALEF */
#define XK_hebrew_bet                    0x0ce1  /* U+05D1 HEBREW LETTER BET */
#define XK_hebrew_beth                   0x0ce1  /* deprecated */
#define XK_hebrew_gimel                  0x0ce2  /* U+05D2 HEBREW LETTER GIMEL */
#define XK_hebrew_gimmel                 0x0ce2  /* deprecated */
#define XK_hebrew_doublelowline                        0xcdf
#define XK_hebrew_aleph                                0xce0
#define XK_hebrew_bet                                  0xce1
#define XK_hebrew_beth                                 0xce1  /* deprecated */
#define XK_hebrew_gimel                                0xce2
#define XK_hebrew_gimmel                               0xce2  /* deprecated */
#define XK_hebrew_dalet                  0x0ce3  /* U+05D3 HEBREW LETTER DALET */
#define XK_hebrew_daleth                 0x0ce3  /* deprecated */
#define XK_hebrew_he                     0x0ce4  /* U+05D4 HEBREW LETTER HE */
#define XK_hebrew_waw                    0x0ce5  /* U+05D5 HEBREW LETTER VAV */
#define XK_hebrew_zain                   0x0ce6  /* U+05D6 HEBREW LETTER ZAYIN */
#define XK_hebrew_zayin                  0x0ce6  /* deprecated */
#define XK_hebrew_chet                   0x0ce7  /* U+05D7 HEBREW LETTER HET */
#define XK_hebrew_het                    0x0ce7  /* deprecated */
#define XK_hebrew_tet                    0x0ce8  /* U+05D8 HEBREW LETTER TET */
#define XK_hebrew_teth                   0x0ce8  /* deprecated */
#define XK_hebrew_yod                    0x0ce9  /* U+05D9 HEBREW LETTER YOD */
#define XK_hebrew_finalkaph              0x0cea  /* U+05DA HEBREW LETTER FINAL KAF */
#define XK_hebrew_kaph                   0x0ceb  /* U+05DB HEBREW LETTER KAF */
#define XK_hebrew_lamed                  0x0cec  /* U+05DC HEBREW LETTER LAMED */
#define XK_hebrew_finalmem               0x0ced  /* U+05DD HEBREW LETTER FINAL MEM */
#define XK_hebrew_mem                    0x0cee  /* U+05DE HEBREW LETTER MEM */
#define XK_hebrew_finalnun               0x0cef  /* U+05DF HEBREW LETTER FINAL NUN */
#define XK_hebrew_nun                    0x0cf0  /* U+05E0 HEBREW LETTER NUN */
#define XK_hebrew_samech                 0x0cf1  /* U+05E1 HEBREW LETTER SAMEKH */
#define XK_hebrew_samekh                 0x0cf1  /* deprecated */
#define XK_hebrew_ayin                   0x0cf2  /* U+05E2 HEBREW LETTER AYIN */
#define XK_hebrew_finalpe                0x0cf3  /* U+05E3 HEBREW LETTER FINAL PE */
#define XK_hebrew_pe                     0x0cf4  /* U+05E4 HEBREW LETTER PE */
#define XK_hebrew_finalzade              0x0cf5  /* U+05E5 HEBREW LETTER FINAL TSADI */
#define XK_hebrew_finalzadi              0x0cf5  /* deprecated */
#define XK_hebrew_zade                   0x0cf6  /* U+05E6 HEBREW LETTER TSADI */
#define XK_hebrew_zadi                   0x0cf6  /* deprecated */
#define XK_hebrew_qoph                   0x0cf7  /* U+05E7 HEBREW LETTER QOF */
#define XK_hebrew_kuf                    0x0cf7  /* deprecated */
#define XK_hebrew_resh                   0x0cf8  /* U+05E8 HEBREW LETTER RESH */
#define XK_hebrew_shin                   0x0cf9  /* U+05E9 HEBREW LETTER SHIN */
#define XK_hebrew_taw                    0x0cfa  /* U+05EA HEBREW LETTER TAV */
#define XK_hebrew_taf                    0x0cfa  /* deprecated */
#define XK_Hebrew_switch                 0xff7e  /* non-deprecated alias for Mode_switch */
#endif /* XK_HEBREW */

/*
 * Thai
 * Byte 3 = 0x0d
 */

#ifdef XK_THAI
#define XK_Thai_kokai                    0x0da1  /* U+0E01 THAI CHARACTER KO KAI */
#define XK_Thai_khokhai                  0x0da2  /* U+0E02 THAI CHARACTER KHO KHAI */
#define XK_Thai_khokhuat                 0x0da3  /* U+0E03 THAI CHARACTER KHO KHUAT */
#define XK_Thai_khokhwai                 0x0da4  /* U+0E04 THAI CHARACTER KHO KHWAI */
#define XK_Thai_khokhon                  0x0da5  /* U+0E05 THAI CHARACTER KHO KHON */
#define XK_Thai_khorakhang               0x0da6  /* U+0E06 THAI CHARACTER KHO RAKHANG */
#define XK_Thai_ngongu                   0x0da7  /* U+0E07 THAI CHARACTER NGO NGU */
#define XK_Thai_chochan                  0x0da8  /* U+0E08 THAI CHARACTER CHO CHAN */
#define XK_Thai_choching                 0x0da9  /* U+0E09 THAI CHARACTER CHO CHING */
#define XK_Thai_chochang                 0x0daa  /* U+0E0A THAI CHARACTER CHO CHANG */
#define XK_Thai_soso                     0x0dab  /* U+0E0B THAI CHARACTER SO SO */
#define XK_Thai_chochoe                  0x0dac  /* U+0E0C THAI CHARACTER CHO CHOE */
#define XK_Thai_yoying                   0x0dad  /* U+0E0D THAI CHARACTER YO YING */
#define XK_Thai_dochada                  0x0dae  /* U+0E0E THAI CHARACTER DO CHADA */
#define XK_Thai_topatak                  0x0daf  /* U+0E0F THAI CHARACTER TO PATAK */
#define XK_Thai_thothan                  0x0db0  /* U+0E10 THAI CHARACTER THO THAN */
#define XK_Thai_thonangmontho            0x0db1  /* U+0E11 THAI CHARACTER THO NANGMONTHO */
#define XK_Thai_thophuthao               0x0db2  /* U+0E12 THAI CHARACTER THO PHUTHAO */
#define XK_Thai_nonen                    0x0db3  /* U+0E13 THAI CHARACTER NO NEN */
#define XK_Thai_dodek                    0x0db4  /* U+0E14 THAI CHARACTER DO DEK */
#define XK_Thai_totao                    0x0db5  /* U+0E15 THAI CHARACTER TO TAO */
#define XK_Thai_thothung                 0x0db6  /* U+0E16 THAI CHARACTER THO THUNG */
#define XK_Thai_thothahan                0x0db7  /* U+0E17 THAI CHARACTER THO THAHAN */
#define XK_Thai_thothong                 0x0db8  /* U+0E18 THAI CHARACTER THO THONG */
#define XK_Thai_nonu                     0x0db9  /* U+0E19 THAI CHARACTER NO NU */
#define XK_Thai_bobaimai                 0x0dba  /* U+0E1A THAI CHARACTER BO BAIMAI */
#define XK_Thai_popla                    0x0dbb  /* U+0E1B THAI CHARACTER PO PLA */
#define XK_Thai_phophung                 0x0dbc  /* U+0E1C THAI CHARACTER PHO PHUNG */
#define XK_Thai_fofa                     0x0dbd  /* U+0E1D THAI CHARACTER FO FA */
#define XK_Thai_phophan                  0x0dbe  /* U+0E1E THAI CHARACTER PHO PHAN */
#define XK_Thai_fofan                    0x0dbf  /* U+0E1F THAI CHARACTER FO FAN */
#define XK_Thai_phosamphao               0x0dc0  /* U+0E20 THAI CHARACTER PHO SAMPHAO */
#define XK_Thai_moma                     0x0dc1  /* U+0E21 THAI CHARACTER MO MA */
#define XK_Thai_yoyak                    0x0dc2  /* U+0E22 THAI CHARACTER YO YAK */
#define XK_Thai_rorua                    0x0dc3  /* U+0E23 THAI CHARACTER RO RUA */
#define XK_Thai_ru                       0x0dc4  /* U+0E24 THAI CHARACTER RU */
#define XK_Thai_loling                   0x0dc5  /* U+0E25 THAI CHARACTER LO LING */
#define XK_Thai_lu                       0x0dc6  /* U+0E26 THAI CHARACTER LU */
#define XK_Thai_wowaen                   0x0dc7  /* U+0E27 THAI CHARACTER WO WAEN */
#define XK_Thai_sosala                   0x0dc8  /* U+0E28 THAI CHARACTER SO SALA */
#define XK_Thai_sorusi                   0x0dc9  /* U+0E29 THAI CHARACTER SO RUSI */
#define XK_Thai_sosua                    0x0dca  /* U+0E2A THAI CHARACTER SO SUA */
#define XK_Thai_hohip                    0x0dcb  /* U+0E2B THAI CHARACTER HO HIP */
#define XK_Thai_lochula                  0x0dcc  /* U+0E2C THAI CHARACTER LO CHULA */
#define XK_Thai_oang                     0x0dcd  /* U+0E2D THAI CHARACTER O ANG */
#define XK_Thai_honokhuk                 0x0dce  /* U+0E2E THAI CHARACTER HO NOKHUK */
#define XK_Thai_paiyannoi                0x0dcf  /* U+0E2F THAI CHARACTER PAIYANNOI */
#define XK_Thai_saraa                    0x0dd0  /* U+0E30 THAI CHARACTER SARA A */
#define XK_Thai_maihanakat               0x0dd1  /* U+0E31 THAI CHARACTER MAI HAN-AKAT */
#define XK_Thai_saraaa                   0x0dd2  /* U+0E32 THAI CHARACTER SARA AA */
#define XK_Thai_saraam                   0x0dd3  /* U+0E33 THAI CHARACTER SARA AM */
#define XK_Thai_sarai                    0x0dd4  /* U+0E34 THAI CHARACTER SARA I */
#define XK_Thai_saraii                   0x0dd5  /* U+0E35 THAI CHARACTER SARA II */
#define XK_Thai_saraue                   0x0dd6  /* U+0E36 THAI CHARACTER SARA UE */
#define XK_Thai_sarauee                  0x0dd7  /* U+0E37 THAI CHARACTER SARA UEE */
#define XK_Thai_sarau                    0x0dd8  /* U+0E38 THAI CHARACTER SARA U */
#define XK_Thai_sarauu                   0x0dd9  /* U+0E39 THAI CHARACTER SARA UU */
#define XK_Thai_phinthu                  0x0dda  /* U+0E3A THAI CHARACTER PHINTHU */
#define XK_Thai_maihanakat_maitho        0x0dde  /*(U+0E3E Unassigned code point)*/
#define XK_Thai_baht                     0x0ddf  /* U+0E3F THAI CURRENCY SYMBOL BAHT */
#define XK_Thai_sarae                    0x0de0  /* U+0E40 THAI CHARACTER SARA E */
#define XK_Thai_saraae                   0x0de1  /* U+0E41 THAI CHARACTER SARA AE */
#define XK_Thai_sarao                    0x0de2  /* U+0E42 THAI CHARACTER SARA O */
#define XK_Thai_saraaimaimuan            0x0de3  /* U+0E43 THAI CHARACTER SARA AI MAIMUAN */
#define XK_Thai_saraaimaimalai           0x0de4  /* U+0E44 THAI CHARACTER SARA AI MAIMALAI */
#define XK_Thai_lakkhangyao              0x0de5  /* U+0E45 THAI CHARACTER LAKKHANGYAO */
#define XK_Thai_maiyamok                 0x0de6  /* U+0E46 THAI CHARACTER MAIYAMOK */
#define XK_Thai_maitaikhu                0x0de7  /* U+0E47 THAI CHARACTER MAITAIKHU */
#define XK_Thai_maiek                    0x0de8  /* U+0E48 THAI CHARACTER MAI EK */
#define XK_Thai_maitho                   0x0de9  /* U+0E49 THAI CHARACTER MAI THO */
#define XK_Thai_maitri                   0x0dea  /* U+0E4A THAI CHARACTER MAI TRI */
#define XK_Thai_maichattawa              0x0deb  /* U+0E4B THAI CHARACTER MAI CHATTAWA */
#define XK_Thai_thanthakhat              0x0dec  /* U+0E4C THAI CHARACTER THANTHAKHAT */
#define XK_Thai_nikhahit                 0x0ded  /* U+0E4D THAI CHARACTER NIKHAHIT */
#define XK_Thai_leksun                   0x0df0  /* U+0E50 THAI DIGIT ZERO */
#define XK_Thai_leknung                  0x0df1  /* U+0E51 THAI DIGIT ONE */
#define XK_Thai_leksong                  0x0df2  /* U+0E52 THAI DIGIT TWO */
#define XK_Thai_leksam                   0x0df3  /* U+0E53 THAI DIGIT THREE */
#define XK_Thai_leksi                    0x0df4  /* U+0E54 THAI DIGIT FOUR */
#define XK_Thai_lekha                    0x0df5  /* U+0E55 THAI DIGIT FIVE */
#define XK_Thai_lekhok                   0x0df6  /* U+0E56 THAI DIGIT SIX */
#define XK_Thai_lekchet                  0x0df7  /* U+0E57 THAI DIGIT SEVEN */
#define XK_Thai_lekpaet                  0x0df8  /* U+0E58 THAI DIGIT EIGHT */
#define XK_Thai_lekkao                   0x0df9  /* U+0E59 THAI DIGIT NINE */
#endif /* XK_THAI */

#define XK_hebrew_dalet                                0xce3
/*
 * Korean
 * Byte 3 = 0x0e
 */

#define XK_hebrew_daleth                               0xce3  /* deprecated */
#ifdef XK_KOREAN

#define XK_hebrew_he                                   0xce4
#define XK_Hangul                        0xff31  /* Hangul start/stop(toggle) */
#define XK_Hangul_Start                  0xff32  /* Hangul start */
#define XK_Hangul_End                    0xff33  /* Hangul end, English start */
#define XK_Hangul_Hanja                  0xff34  /* Start Hangul->Hanja Conversion */
#define XK_Hangul_Jamo                   0xff35  /* Hangul Jamo mode */
#define XK_Hangul_Romaja                 0xff36  /* Hangul Romaja mode */
#define XK_Hangul_Codeinput              0xff37  /* Hangul code input mode */
#define XK_Hangul_Jeonja                 0xff38  /* Jeonja mode */
#define XK_Hangul_Banja                  0xff39  /* Banja mode */
#define XK_Hangul_PreHanja               0xff3a  /* Pre Hanja conversion */
#define XK_Hangul_PostHanja              0xff3b  /* Post Hanja conversion */
#define XK_Hangul_SingleCandidate        0xff3c  /* Single candidate */
#define XK_Hangul_MultipleCandidate      0xff3d  /* Multiple candidate */
#define XK_Hangul_PreviousCandidate      0xff3e  /* Previous candidate */
#define XK_Hangul_Special                0xff3f  /* Special symbols */
#define XK_Hangul_switch                 0xff7e  /* non-deprecated alias for Mode_switch */

#define XK_hebrew_waw                                  0xce5
/* Hangul Consonant Characters */
#define XK_Hangul_Kiyeog                 0x0ea1  /* U+3131 HANGUL LETTER KIYEOK */
#define XK_Hangul_SsangKiyeog            0x0ea2  /* U+3132 HANGUL LETTER SSANGKIYEOK */
#define XK_Hangul_KiyeogSios             0x0ea3  /* U+3133 HANGUL LETTER KIYEOK-SIOS */
#define XK_Hangul_Nieun                  0x0ea4  /* U+3134 HANGUL LETTER NIEUN */
#define XK_Hangul_NieunJieuj             0x0ea5  /* U+3135 HANGUL LETTER NIEUN-CIEUC */
#define XK_Hangul_NieunHieuh             0x0ea6  /* U+3136 HANGUL LETTER NIEUN-HIEUH */
#define XK_Hangul_Dikeud                 0x0ea7  /* U+3137 HANGUL LETTER TIKEUT */
#define XK_Hangul_SsangDikeud            0x0ea8  /* U+3138 HANGUL LETTER SSANGTIKEUT */
#define XK_Hangul_Rieul                  0x0ea9  /* U+3139 HANGUL LETTER RIEUL */
#define XK_Hangul_RieulKiyeog            0x0eaa  /* U+313A HANGUL LETTER RIEUL-KIYEOK */
#define XK_Hangul_RieulMieum             0x0eab  /* U+313B HANGUL LETTER RIEUL-MIEUM */
#define XK_Hangul_RieulPieub             0x0eac  /* U+313C HANGUL LETTER RIEUL-PIEUP */
#define XK_Hangul_RieulSios              0x0ead  /* U+313D HANGUL LETTER RIEUL-SIOS */
#define XK_Hangul_RieulTieut             0x0eae  /* U+313E HANGUL LETTER RIEUL-THIEUTH */
#define XK_Hangul_RieulPhieuf            0x0eaf  /* U+313F HANGUL LETTER RIEUL-PHIEUPH */
#define XK_Hangul_RieulHieuh             0x0eb0  /* U+3140 HANGUL LETTER RIEUL-HIEUH */
#define XK_Hangul_Mieum                  0x0eb1  /* U+3141 HANGUL LETTER MIEUM */
#define XK_Hangul_Pieub                  0x0eb2  /* U+3142 HANGUL LETTER PIEUP */
#define XK_Hangul_SsangPieub             0x0eb3  /* U+3143 HANGUL LETTER SSANGPIEUP */
#define XK_Hangul_PieubSios              0x0eb4  /* U+3144 HANGUL LETTER PIEUP-SIOS */
#define XK_Hangul_Sios                   0x0eb5  /* U+3145 HANGUL LETTER SIOS */
#define XK_Hangul_SsangSios              0x0eb6  /* U+3146 HANGUL LETTER SSANGSIOS */
#define XK_Hangul_Ieung                  0x0eb7  /* U+3147 HANGUL LETTER IEUNG */
#define XK_Hangul_Jieuj                  0x0eb8  /* U+3148 HANGUL LETTER CIEUC */
#define XK_Hangul_SsangJieuj             0x0eb9  /* U+3149 HANGUL LETTER SSANGCIEUC */
#define XK_Hangul_Cieuc                  0x0eba  /* U+314A HANGUL LETTER CHIEUCH */
#define XK_Hangul_Khieuq                 0x0ebb  /* U+314B HANGUL LETTER KHIEUKH */
#define XK_Hangul_Tieut                  0x0ebc  /* U+314C HANGUL LETTER THIEUTH */
#define XK_Hangul_Phieuf                 0x0ebd  /* U+314D HANGUL LETTER PHIEUPH */
#define XK_Hangul_Hieuh                  0x0ebe  /* U+314E HANGUL LETTER HIEUH */

#define XK_hebrew_zain                                 0xce6
/* Hangul Vowel Characters */
#define XK_Hangul_A                      0x0ebf  /* U+314F HANGUL LETTER A */
#define XK_Hangul_AE                     0x0ec0  /* U+3150 HANGUL LETTER AE */
#define XK_Hangul_YA                     0x0ec1  /* U+3151 HANGUL LETTER YA */
#define XK_Hangul_YAE                    0x0ec2  /* U+3152 HANGUL LETTER YAE */
#define XK_Hangul_EO                     0x0ec3  /* U+3153 HANGUL LETTER EO */
#define XK_Hangul_E                      0x0ec4  /* U+3154 HANGUL LETTER E */
#define XK_Hangul_YEO                    0x0ec5  /* U+3155 HANGUL LETTER YEO */
#define XK_Hangul_YE                     0x0ec6  /* U+3156 HANGUL LETTER YE */
#define XK_Hangul_O                      0x0ec7  /* U+3157 HANGUL LETTER O */
#define XK_Hangul_WA                     0x0ec8  /* U+3158 HANGUL LETTER WA */
#define XK_Hangul_WAE                    0x0ec9  /* U+3159 HANGUL LETTER WAE */
#define XK_Hangul_OE                     0x0eca  /* U+315A HANGUL LETTER OE */
#define XK_Hangul_YO                     0x0ecb  /* U+315B HANGUL LETTER YO */
#define XK_Hangul_U                      0x0ecc  /* U+315C HANGUL LETTER U */
#define XK_Hangul_WEO                    0x0ecd  /* U+315D HANGUL LETTER WEO */
#define XK_Hangul_WE                     0x0ece  /* U+315E HANGUL LETTER WE */
#define XK_Hangul_WI                     0x0ecf  /* U+315F HANGUL LETTER WI */
#define XK_Hangul_YU                     0x0ed0  /* U+3160 HANGUL LETTER YU */
#define XK_Hangul_EU                     0x0ed1  /* U+3161 HANGUL LETTER EU */
#define XK_Hangul_YI                     0x0ed2  /* U+3162 HANGUL LETTER YI */
#define XK_Hangul_I                      0x0ed3  /* U+3163 HANGUL LETTER I */

#define XK_hebrew_zayin                                0xce6  /* deprecated */
/* Hangul syllable-final (JongSeong) Characters */
#define XK_Hangul_J_Kiyeog               0x0ed4  /* U+11A8 HANGUL JONGSEONG KIYEOK */
#define XK_Hangul_J_SsangKiyeog          0x0ed5  /* U+11A9 HANGUL JONGSEONG SSANGKIYEOK */
#define XK_Hangul_J_KiyeogSios           0x0ed6  /* U+11AA HANGUL JONGSEONG KIYEOK-SIOS */
#define XK_Hangul_J_Nieun                0x0ed7  /* U+11AB HANGUL JONGSEONG NIEUN */
#define XK_Hangul_J_NieunJieuj           0x0ed8  /* U+11AC HANGUL JONGSEONG NIEUN-CIEUC */
#define XK_Hangul_J_NieunHieuh           0x0ed9  /* U+11AD HANGUL JONGSEONG NIEUN-HIEUH */
#define XK_Hangul_J_Dikeud               0x0eda  /* U+11AE HANGUL JONGSEONG TIKEUT */
#define XK_Hangul_J_Rieul                0x0edb  /* U+11AF HANGUL JONGSEONG RIEUL */
#define XK_Hangul_J_RieulKiyeog          0x0edc  /* U+11B0 HANGUL JONGSEONG RIEUL-KIYEOK */
#define XK_Hangul_J_RieulMieum           0x0edd  /* U+11B1 HANGUL JONGSEONG RIEUL-MIEUM */
#define XK_Hangul_J_RieulPieub           0x0ede  /* U+11B2 HANGUL JONGSEONG RIEUL-PIEUP */
#define XK_Hangul_J_RieulSios            0x0edf  /* U+11B3 HANGUL JONGSEONG RIEUL-SIOS */
#define XK_Hangul_J_RieulTieut           0x0ee0  /* U+11B4 HANGUL JONGSEONG RIEUL-THIEUTH */
#define XK_Hangul_J_RieulPhieuf          0x0ee1  /* U+11B5 HANGUL JONGSEONG RIEUL-PHIEUPH */
#define XK_Hangul_J_RieulHieuh           0x0ee2  /* U+11B6 HANGUL JONGSEONG RIEUL-HIEUH */
#define XK_Hangul_J_Mieum                0x0ee3  /* U+11B7 HANGUL JONGSEONG MIEUM */
#define XK_Hangul_J_Pieub                0x0ee4  /* U+11B8 HANGUL JONGSEONG PIEUP */
#define XK_Hangul_J_PieubSios            0x0ee5  /* U+11B9 HANGUL JONGSEONG PIEUP-SIOS */
#define XK_Hangul_J_Sios                 0x0ee6  /* U+11BA HANGUL JONGSEONG SIOS */
#define XK_Hangul_J_SsangSios            0x0ee7  /* U+11BB HANGUL JONGSEONG SSANGSIOS */
#define XK_Hangul_J_Ieung                0x0ee8  /* U+11BC HANGUL JONGSEONG IEUNG */
#define XK_Hangul_J_Jieuj                0x0ee9  /* U+11BD HANGUL JONGSEONG CIEUC */
#define XK_Hangul_J_Cieuc                0x0eea  /* U+11BE HANGUL JONGSEONG CHIEUCH */
#define XK_Hangul_J_Khieuq               0x0eeb  /* U+11BF HANGUL JONGSEONG KHIEUKH */
#define XK_Hangul_J_Tieut                0x0eec  /* U+11C0 HANGUL JONGSEONG THIEUTH */
#define XK_Hangul_J_Phieuf               0x0eed  /* U+11C1 HANGUL JONGSEONG PHIEUPH */
#define XK_Hangul_J_Hieuh                0x0eee  /* U+11C2 HANGUL JONGSEONG HIEUH */

#define XK_hebrew_chet                                 0xce7
/* Ancient Hangul Consonant Characters */
#define XK_Hangul_RieulYeorinHieuh       0x0eef  /* U+316D HANGUL LETTER RIEUL-YEORINHIEUH */
#define XK_Hangul_SunkyeongeumMieum      0x0ef0  /* U+3171 HANGUL LETTER KAPYEOUNMIEUM */
#define XK_Hangul_SunkyeongeumPieub      0x0ef1  /* U+3178 HANGUL LETTER KAPYEOUNPIEUP */
#define XK_Hangul_PanSios                0x0ef2  /* U+317F HANGUL LETTER PANSIOS */
#define XK_Hangul_KkogjiDalrinIeung      0x0ef3  /* U+3181 HANGUL LETTER YESIEUNG */
#define XK_Hangul_SunkyeongeumPhieuf     0x0ef4  /* U+3184 HANGUL LETTER KAPYEOUNPHIEUPH */
#define XK_Hangul_YeorinHieuh            0x0ef5  /* U+3186 HANGUL LETTER YEORINHIEUH */

#define XK_hebrew_het                                  0xce7  /* deprecated */
/* Ancient Hangul Vowel Characters */
#define XK_Hangul_AraeA                  0x0ef6  /* U+318D HANGUL LETTER ARAEA */
#define XK_Hangul_AraeAE                 0x0ef7  /* U+318E HANGUL LETTER ARAEAE */

#define XK_hebrew_tet                                  0xce8
/* Ancient Hangul syllable-final (JongSeong) Characters */
#define XK_Hangul_J_PanSios              0x0ef8  /* U+11EB HANGUL JONGSEONG PANSIOS */
#define XK_Hangul_J_KkogjiDalrinIeung    0x0ef9  /* U+11F0 HANGUL JONGSEONG YESIEUNG */
#define XK_Hangul_J_YeorinHieuh          0x0efa  /* U+11F9 HANGUL JONGSEONG YEORINHIEUH */

#define XK_hebrew_teth                                 0xce8  /* deprecated */
/* Korean currency symbol */
#define XK_Korean_Won                    0x0eff  /*(U+20A9 WON SIGN)*/

#define XK_hebrew_yod                                  0xce9
#endif /* XK_KOREAN */

#define XK_hebrew_finalkaph                            0xcea
/*
 * Armenian
 */

#define XK_hebrew_kaph                                 0xceb
#ifdef XK_ARMENIAN
#define XK_Armenian_ligature_ew       0x1000587  /* U+0587 ARMENIAN SMALL LIGATURE ECH YIWN */
#define XK_Armenian_full_stop         0x1000589  /* U+0589 ARMENIAN FULL STOP */
#define XK_Armenian_verjaket          0x1000589  /* deprecated alias for Armenian_full_stop */
#define XK_Armenian_separation_mark   0x100055d  /* U+055D ARMENIAN COMMA */
#define XK_Armenian_but               0x100055d  /* deprecated alias for Armenian_separation_mark */
#define XK_Armenian_hyphen            0x100058a  /* U+058A ARMENIAN HYPHEN */
#define XK_Armenian_yentamna          0x100058a  /* deprecated alias for Armenian_hyphen */
#define XK_Armenian_exclam            0x100055c  /* U+055C ARMENIAN EXCLAMATION MARK */
#define XK_Armenian_amanak            0x100055c  /* deprecated alias for Armenian_exclam */
#define XK_Armenian_accent            0x100055b  /* U+055B ARMENIAN EMPHASIS MARK */
#define XK_Armenian_shesht            0x100055b  /* deprecated alias for Armenian_accent */
#define XK_Armenian_question          0x100055e  /* U+055E ARMENIAN QUESTION MARK */
#define XK_Armenian_paruyk            0x100055e  /* deprecated alias for Armenian_question */
#define XK_Armenian_AYB               0x1000531  /* U+0531 ARMENIAN CAPITAL LETTER AYB */
#define XK_Armenian_ayb               0x1000561  /* U+0561 ARMENIAN SMALL LETTER AYB */
#define XK_Armenian_BEN               0x1000532  /* U+0532 ARMENIAN CAPITAL LETTER BEN */
#define XK_Armenian_ben               0x1000562  /* U+0562 ARMENIAN SMALL LETTER BEN */
#define XK_Armenian_GIM               0x1000533  /* U+0533 ARMENIAN CAPITAL LETTER GIM */
#define XK_Armenian_gim               0x1000563  /* U+0563 ARMENIAN SMALL LETTER GIM */
#define XK_Armenian_DA                0x1000534  /* U+0534 ARMENIAN CAPITAL LETTER DA */
#define XK_Armenian_da                0x1000564  /* U+0564 ARMENIAN SMALL LETTER DA */
#define XK_Armenian_YECH              0x1000535  /* U+0535 ARMENIAN CAPITAL LETTER ECH */
#define XK_Armenian_yech              0x1000565  /* U+0565 ARMENIAN SMALL LETTER ECH */
#define XK_Armenian_ZA                0x1000536  /* U+0536 ARMENIAN CAPITAL LETTER ZA */
#define XK_Armenian_za                0x1000566  /* U+0566 ARMENIAN SMALL LETTER ZA */
#define XK_Armenian_E                 0x1000537  /* U+0537 ARMENIAN CAPITAL LETTER EH */
#define XK_Armenian_e                 0x1000567  /* U+0567 ARMENIAN SMALL LETTER EH */
#define XK_Armenian_AT                0x1000538  /* U+0538 ARMENIAN CAPITAL LETTER ET */
#define XK_Armenian_at                0x1000568  /* U+0568 ARMENIAN SMALL LETTER ET */
#define XK_Armenian_TO                0x1000539  /* U+0539 ARMENIAN CAPITAL LETTER TO */
#define XK_Armenian_to                0x1000569  /* U+0569 ARMENIAN SMALL LETTER TO */
#define XK_Armenian_ZHE               0x100053a  /* U+053A ARMENIAN CAPITAL LETTER ZHE */
#define XK_Armenian_zhe               0x100056a  /* U+056A ARMENIAN SMALL LETTER ZHE */
#define XK_Armenian_INI               0x100053b  /* U+053B ARMENIAN CAPITAL LETTER INI */
#define XK_Armenian_ini               0x100056b  /* U+056B ARMENIAN SMALL LETTER INI */
#define XK_Armenian_LYUN              0x100053c  /* U+053C ARMENIAN CAPITAL LETTER LIWN */
#define XK_Armenian_lyun              0x100056c  /* U+056C ARMENIAN SMALL LETTER LIWN */
#define XK_Armenian_KHE               0x100053d  /* U+053D ARMENIAN CAPITAL LETTER XEH */
#define XK_Armenian_khe               0x100056d  /* U+056D ARMENIAN SMALL LETTER XEH */
#define XK_Armenian_TSA               0x100053e  /* U+053E ARMENIAN CAPITAL LETTER CA */
#define XK_Armenian_tsa               0x100056e  /* U+056E ARMENIAN SMALL LETTER CA */
#define XK_Armenian_KEN               0x100053f  /* U+053F ARMENIAN CAPITAL LETTER KEN */
#define XK_Armenian_ken               0x100056f  /* U+056F ARMENIAN SMALL LETTER KEN */
#define XK_Armenian_HO                0x1000540  /* U+0540 ARMENIAN CAPITAL LETTER HO */
#define XK_Armenian_ho                0x1000570  /* U+0570 ARMENIAN SMALL LETTER HO */
#define XK_Armenian_DZA               0x1000541  /* U+0541 ARMENIAN CAPITAL LETTER JA */
#define XK_Armenian_dza               0x1000571  /* U+0571 ARMENIAN SMALL LETTER JA */
#define XK_Armenian_GHAT              0x1000542  /* U+0542 ARMENIAN CAPITAL LETTER GHAD */
#define XK_Armenian_ghat              0x1000572  /* U+0572 ARMENIAN SMALL LETTER GHAD */
#define XK_Armenian_TCHE              0x1000543  /* U+0543 ARMENIAN CAPITAL LETTER CHEH */
#define XK_Armenian_tche              0x1000573  /* U+0573 ARMENIAN SMALL LETTER CHEH */
#define XK_Armenian_MEN               0x1000544  /* U+0544 ARMENIAN CAPITAL LETTER MEN */
#define XK_Armenian_men               0x1000574  /* U+0574 ARMENIAN SMALL LETTER MEN */
#define XK_Armenian_HI                0x1000545  /* U+0545 ARMENIAN CAPITAL LETTER YI */
#define XK_Armenian_hi                0x1000575  /* U+0575 ARMENIAN SMALL LETTER YI */
#define XK_Armenian_NU                0x1000546  /* U+0546 ARMENIAN CAPITAL LETTER NOW */
#define XK_Armenian_nu                0x1000576  /* U+0576 ARMENIAN SMALL LETTER NOW */
#define XK_Armenian_SHA               0x1000547  /* U+0547 ARMENIAN CAPITAL LETTER SHA */
#define XK_Armenian_sha               0x1000577  /* U+0577 ARMENIAN SMALL LETTER SHA */
#define XK_Armenian_VO                0x1000548  /* U+0548 ARMENIAN CAPITAL LETTER VO */
#define XK_Armenian_vo                0x1000578  /* U+0578 ARMENIAN SMALL LETTER VO */
#define XK_Armenian_CHA               0x1000549  /* U+0549 ARMENIAN CAPITAL LETTER CHA */
#define XK_Armenian_cha               0x1000579  /* U+0579 ARMENIAN SMALL LETTER CHA */
#define XK_Armenian_PE                0x100054a  /* U+054A ARMENIAN CAPITAL LETTER PEH */
#define XK_Armenian_pe                0x100057a  /* U+057A ARMENIAN SMALL LETTER PEH */
#define XK_Armenian_JE                0x100054b  /* U+054B ARMENIAN CAPITAL LETTER JHEH */
#define XK_Armenian_je                0x100057b  /* U+057B ARMENIAN SMALL LETTER JHEH */
#define XK_Armenian_RA                0x100054c  /* U+054C ARMENIAN CAPITAL LETTER RA */
#define XK_Armenian_ra                0x100057c  /* U+057C ARMENIAN SMALL LETTER RA */
#define XK_Armenian_SE                0x100054d  /* U+054D ARMENIAN CAPITAL LETTER SEH */
#define XK_Armenian_se                0x100057d  /* U+057D ARMENIAN SMALL LETTER SEH */
#define XK_Armenian_VEV               0x100054e  /* U+054E ARMENIAN CAPITAL LETTER VEW */
#define XK_Armenian_vev               0x100057e  /* U+057E ARMENIAN SMALL LETTER VEW */
#define XK_Armenian_TYUN              0x100054f  /* U+054F ARMENIAN CAPITAL LETTER TIWN */
#define XK_Armenian_tyun              0x100057f  /* U+057F ARMENIAN SMALL LETTER TIWN */
#define XK_Armenian_RE                0x1000550  /* U+0550 ARMENIAN CAPITAL LETTER REH */
#define XK_Armenian_re                0x1000580  /* U+0580 ARMENIAN SMALL LETTER REH */
#define XK_Armenian_TSO               0x1000551  /* U+0551 ARMENIAN CAPITAL LETTER CO */
#define XK_Armenian_tso               0x1000581  /* U+0581 ARMENIAN SMALL LETTER CO */
#define XK_Armenian_VYUN              0x1000552  /* U+0552 ARMENIAN CAPITAL LETTER YIWN */
#define XK_Armenian_vyun              0x1000582  /* U+0582 ARMENIAN SMALL LETTER YIWN */
#define XK_Armenian_PYUR              0x1000553  /* U+0553 ARMENIAN CAPITAL LETTER PIWR */
#define XK_Armenian_pyur              0x1000583  /* U+0583 ARMENIAN SMALL LETTER PIWR */
#define XK_Armenian_KE                0x1000554  /* U+0554 ARMENIAN CAPITAL LETTER KEH */
#define XK_Armenian_ke                0x1000584  /* U+0584 ARMENIAN SMALL LETTER KEH */
#define XK_Armenian_O                 0x1000555  /* U+0555 ARMENIAN CAPITAL LETTER OH */
#define XK_hebrew_lamed                                0xcec
#define XK_Armenian_o                 0x1000585  /* U+0585 ARMENIAN SMALL LETTER OH */
#define XK_Armenian_FE                0x1000556  /* U+0556 ARMENIAN CAPITAL LETTER FEH */
#define XK_Armenian_fe                0x1000586  /* U+0586 ARMENIAN SMALL LETTER FEH */
#define XK_Armenian_apostrophe        0x100055a  /* U+055A ARMENIAN APOSTROPHE */
#endif /* XK_ARMENIAN */

#define XK_hebrew_finalmem                             0xced
/*
 * Georgian
 */

#define XK_hebrew_mem                                  0xcee
#ifdef XK_GEORGIAN
#define XK_Georgian_an                0x10010d0  /* U+10D0 GEORGIAN LETTER AN */
#define XK_Georgian_ban               0x10010d1  /* U+10D1 GEORGIAN LETTER BAN */
#define XK_Georgian_gan               0x10010d2  /* U+10D2 GEORGIAN LETTER GAN */
#define XK_Georgian_don               0x10010d3  /* U+10D3 GEORGIAN LETTER DON */
#define XK_Georgian_en                0x10010d4  /* U+10D4 GEORGIAN LETTER EN */
#define XK_Georgian_vin               0x10010d5  /* U+10D5 GEORGIAN LETTER VIN */
#define XK_Georgian_zen               0x10010d6  /* U+10D6 GEORGIAN LETTER ZEN */
#define XK_Georgian_tan               0x10010d7  /* U+10D7 GEORGIAN LETTER TAN */
#define XK_Georgian_in                0x10010d8  /* U+10D8 GEORGIAN LETTER IN */
#define XK_Georgian_kan               0x10010d9  /* U+10D9 GEORGIAN LETTER KAN */
#define XK_Georgian_las               0x10010da  /* U+10DA GEORGIAN LETTER LAS */
#define XK_Georgian_man               0x10010db  /* U+10DB GEORGIAN LETTER MAN */
#define XK_Georgian_nar               0x10010dc  /* U+10DC GEORGIAN LETTER NAR */
#define XK_Georgian_on                0x10010dd  /* U+10DD GEORGIAN LETTER ON */
#define XK_Georgian_par               0x10010de  /* U+10DE GEORGIAN LETTER PAR */
#define XK_Georgian_zhar              0x10010df  /* U+10DF GEORGIAN LETTER ZHAR */
#define XK_Georgian_rae               0x10010e0  /* U+10E0 GEORGIAN LETTER RAE */
#define XK_Georgian_san               0x10010e1  /* U+10E1 GEORGIAN LETTER SAN */
#define XK_Georgian_tar               0x10010e2  /* U+10E2 GEORGIAN LETTER TAR */
#define XK_Georgian_un                0x10010e3  /* U+10E3 GEORGIAN LETTER UN */
#define XK_hebrew_finalnun                             0xcef
#define XK_Georgian_phar              0x10010e4  /* U+10E4 GEORGIAN LETTER PHAR */
#define XK_Georgian_khar              0x10010e5  /* U+10E5 GEORGIAN LETTER KHAR */
#define XK_Georgian_ghan              0x10010e6  /* U+10E6 GEORGIAN LETTER GHAN */
#define XK_Georgian_qar               0x10010e7  /* U+10E7 GEORGIAN LETTER QAR */
#define XK_Georgian_shin              0x10010e8  /* U+10E8 GEORGIAN LETTER SHIN */
#define XK_Georgian_chin              0x10010e9  /* U+10E9 GEORGIAN LETTER CHIN */
#define XK_Georgian_can               0x10010ea  /* U+10EA GEORGIAN LETTER CAN */
#define XK_Georgian_jil               0x10010eb  /* U+10EB GEORGIAN LETTER JIL */
#define XK_Georgian_cil               0x10010ec  /* U+10EC GEORGIAN LETTER CIL */
#define XK_Georgian_char              0x10010ed  /* U+10ED GEORGIAN LETTER CHAR */
#define XK_Georgian_xan               0x10010ee  /* U+10EE GEORGIAN LETTER XAN */
#define XK_Georgian_jhan              0x10010ef  /* U+10EF GEORGIAN LETTER JHAN */
#define XK_Georgian_hae               0x10010f0  /* U+10F0 GEORGIAN LETTER HAE */
#define XK_Georgian_he                0x10010f1  /* U+10F1 GEORGIAN LETTER HE */
#define XK_Georgian_hie               0x10010f2  /* U+10F2 GEORGIAN LETTER HIE */
#define XK_Georgian_we                0x10010f3  /* U+10F3 GEORGIAN LETTER WE */
#define XK_Georgian_har               0x10010f4  /* U+10F4 GEORGIAN LETTER HAR */
#define XK_Georgian_hoe               0x10010f5  /* U+10F5 GEORGIAN LETTER HOE */
#define XK_Georgian_fi                0x10010f6  /* U+10F6 GEORGIAN LETTER FI */
#endif /* XK_GEORGIAN */

#define XK_hebrew_nun                                  0xcf0
/*
 * Azeri (and other Turkic or Caucasian languages)
 */

#define XK_hebrew_samech                               0xcf1
#ifdef XK_CAUCASUS
/* latin */
#define XK_Xabovedot                  0x1001e8a  /* U+1E8A LATIN CAPITAL LETTER X WITH DOT ABOVE */
#define XK_Ibreve                     0x100012c  /* U+012C LATIN CAPITAL LETTER I WITH BREVE */
#define XK_Zstroke                    0x10001b5  /* U+01B5 LATIN CAPITAL LETTER Z WITH STROKE */
#define XK_Gcaron                     0x10001e6  /* U+01E6 LATIN CAPITAL LETTER G WITH CARON */
#define XK_Ocaron                     0x10001d1  /* U+01D1 LATIN CAPITAL LETTER O WITH CARON */
#define XK_Obarred                    0x100019f  /* U+019F LATIN CAPITAL LETTER O WITH MIDDLE TILDE */
#define XK_xabovedot                  0x1001e8b  /* U+1E8B LATIN SMALL LETTER X WITH DOT ABOVE */
#define XK_ibreve                     0x100012d  /* U+012D LATIN SMALL LETTER I WITH BREVE */
#define XK_zstroke                    0x10001b6  /* U+01B6 LATIN SMALL LETTER Z WITH STROKE */
#define XK_gcaron                     0x10001e7  /* U+01E7 LATIN SMALL LETTER G WITH CARON */
#define XK_ocaron                     0x10001d2  /* U+01D2 LATIN SMALL LETTER O WITH CARON */
#define XK_obarred                    0x1000275  /* U+0275 LATIN SMALL LETTER BARRED O */
#define XK_SCHWA                      0x100018f  /* U+018F LATIN CAPITAL LETTER SCHWA */
#define XK_schwa                      0x1000259  /* U+0259 LATIN SMALL LETTER SCHWA */
#define XK_EZH                        0x10001b7  /* U+01B7 LATIN CAPITAL LETTER EZH */
#define XK_ezh                        0x1000292  /* U+0292 LATIN SMALL LETTER EZH */
/* those are not really Caucasus */
/* For Inupiak */
#define XK_Lbelowdot                  0x1001e36  /* U+1E36 LATIN CAPITAL LETTER L WITH DOT BELOW */
#define XK_lbelowdot                  0x1001e37  /* U+1E37 LATIN SMALL LETTER L WITH DOT BELOW */
#endif /* XK_CAUCASUS */

#define XK_hebrew_samekh                               0xcf1  /* deprecated */
/*
 * Vietnamese
 */

#define XK_hebrew_ayin                                 0xcf2
#ifdef XK_VIETNAMESE
#define XK_Abelowdot                  0x1001ea0  /* U+1EA0 LATIN CAPITAL LETTER A WITH DOT BELOW */
#define XK_abelowdot                  0x1001ea1  /* U+1EA1 LATIN SMALL LETTER A WITH DOT BELOW */
#define XK_Ahook                      0x1001ea2  /* U+1EA2 LATIN CAPITAL LETTER A WITH HOOK ABOVE */
#define XK_ahook                      0x1001ea3  /* U+1EA3 LATIN SMALL LETTER A WITH HOOK ABOVE */
#define XK_Acircumflexacute           0x1001ea4  /* U+1EA4 LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND ACUTE */
#define XK_acircumflexacute           0x1001ea5  /* U+1EA5 LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE */
#define XK_Acircumflexgrave           0x1001ea6  /* U+1EA6 LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND GRAVE */
#define XK_acircumflexgrave           0x1001ea7  /* U+1EA7 LATIN SMALL LETTER A WITH CIRCUMFLEX AND GRAVE */
#define XK_Acircumflexhook            0x1001ea8  /* U+1EA8 LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_acircumflexhook            0x1001ea9  /* U+1EA9 LATIN SMALL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_Acircumflextilde           0x1001eaa  /* U+1EAA LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND TILDE */
#define XK_acircumflextilde           0x1001eab  /* U+1EAB LATIN SMALL LETTER A WITH CIRCUMFLEX AND TILDE */
#define XK_Acircumflexbelowdot        0x1001eac  /* U+1EAC LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND DOT BELOW */
#define XK_acircumflexbelowdot        0x1001ead  /* U+1EAD LATIN SMALL LETTER A WITH CIRCUMFLEX AND DOT BELOW */
#define XK_Abreveacute                0x1001eae  /* U+1EAE LATIN CAPITAL LETTER A WITH BREVE AND ACUTE */
#define XK_abreveacute                0x1001eaf  /* U+1EAF LATIN SMALL LETTER A WITH BREVE AND ACUTE */
#define XK_Abrevegrave                0x1001eb0  /* U+1EB0 LATIN CAPITAL LETTER A WITH BREVE AND GRAVE */
#define XK_abrevegrave                0x1001eb1  /* U+1EB1 LATIN SMALL LETTER A WITH BREVE AND GRAVE */
#define XK_Abrevehook                 0x1001eb2  /* U+1EB2 LATIN CAPITAL LETTER A WITH BREVE AND HOOK ABOVE */
#define XK_abrevehook                 0x1001eb3  /* U+1EB3 LATIN SMALL LETTER A WITH BREVE AND HOOK ABOVE */
#define XK_Abrevetilde                0x1001eb4  /* U+1EB4 LATIN CAPITAL LETTER A WITH BREVE AND TILDE */
#define XK_abrevetilde                0x1001eb5  /* U+1EB5 LATIN SMALL LETTER A WITH BREVE AND TILDE */
#define XK_Abrevebelowdot             0x1001eb6  /* U+1EB6 LATIN CAPITAL LETTER A WITH BREVE AND DOT BELOW */
#define XK_abrevebelowdot             0x1001eb7  /* U+1EB7 LATIN SMALL LETTER A WITH BREVE AND DOT BELOW */
#define XK_Ebelowdot                  0x1001eb8  /* U+1EB8 LATIN CAPITAL LETTER E WITH DOT BELOW */
#define XK_ebelowdot                  0x1001eb9  /* U+1EB9 LATIN SMALL LETTER E WITH DOT BELOW */
#define XK_Ehook                      0x1001eba  /* U+1EBA LATIN CAPITAL LETTER E WITH HOOK ABOVE */
#define XK_ehook                      0x1001ebb  /* U+1EBB LATIN SMALL LETTER E WITH HOOK ABOVE */
#define XK_Etilde                     0x1001ebc  /* U+1EBC LATIN CAPITAL LETTER E WITH TILDE */
#define XK_etilde                     0x1001ebd  /* U+1EBD LATIN SMALL LETTER E WITH TILDE */
#define XK_Ecircumflexacute           0x1001ebe  /* U+1EBE LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE */
#define XK_ecircumflexacute           0x1001ebf  /* U+1EBF LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE */
#define XK_Ecircumflexgrave           0x1001ec0  /* U+1EC0 LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND GRAVE */
#define XK_ecircumflexgrave           0x1001ec1  /* U+1EC1 LATIN SMALL LETTER E WITH CIRCUMFLEX AND GRAVE */
#define XK_Ecircumflexhook            0x1001ec2  /* U+1EC2 LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_ecircumflexhook            0x1001ec3  /* U+1EC3 LATIN SMALL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_Ecircumflextilde           0x1001ec4  /* U+1EC4 LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND TILDE */
#define XK_ecircumflextilde           0x1001ec5  /* U+1EC5 LATIN SMALL LETTER E WITH CIRCUMFLEX AND TILDE */
#define XK_Ecircumflexbelowdot        0x1001ec6  /* U+1EC6 LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND DOT BELOW */
#define XK_ecircumflexbelowdot        0x1001ec7  /* U+1EC7 LATIN SMALL LETTER E WITH CIRCUMFLEX AND DOT BELOW */
#define XK_Ihook                      0x1001ec8  /* U+1EC8 LATIN CAPITAL LETTER I WITH HOOK ABOVE */
#define XK_ihook                      0x1001ec9  /* U+1EC9 LATIN SMALL LETTER I WITH HOOK ABOVE */
#define XK_Ibelowdot                  0x1001eca  /* U+1ECA LATIN CAPITAL LETTER I WITH DOT BELOW */
#define XK_ibelowdot                  0x1001ecb  /* U+1ECB LATIN SMALL LETTER I WITH DOT BELOW */
#define XK_Obelowdot                  0x1001ecc  /* U+1ECC LATIN CAPITAL LETTER O WITH DOT BELOW */
#define XK_obelowdot                  0x1001ecd  /* U+1ECD LATIN SMALL LETTER O WITH DOT BELOW */
#define XK_Ohook                      0x1001ece  /* U+1ECE LATIN CAPITAL LETTER O WITH HOOK ABOVE */
#define XK_ohook                      0x1001ecf  /* U+1ECF LATIN SMALL LETTER O WITH HOOK ABOVE */
#define XK_Ocircumflexacute           0x1001ed0  /* U+1ED0 LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND ACUTE */
#define XK_ocircumflexacute           0x1001ed1  /* U+1ED1 LATIN SMALL LETTER O WITH CIRCUMFLEX AND ACUTE */
#define XK_Ocircumflexgrave           0x1001ed2  /* U+1ED2 LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND GRAVE */
#define XK_ocircumflexgrave           0x1001ed3  /* U+1ED3 LATIN SMALL LETTER O WITH CIRCUMFLEX AND GRAVE */
#define XK_Ocircumflexhook            0x1001ed4  /* U+1ED4 LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_ocircumflexhook            0x1001ed5  /* U+1ED5 LATIN SMALL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE */
#define XK_Ocircumflextilde           0x1001ed6  /* U+1ED6 LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND TILDE */
#define XK_ocircumflextilde           0x1001ed7  /* U+1ED7 LATIN SMALL LETTER O WITH CIRCUMFLEX AND TILDE */
#define XK_Ocircumflexbelowdot        0x1001ed8  /* U+1ED8 LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND DOT BELOW */
#define XK_ocircumflexbelowdot        0x1001ed9  /* U+1ED9 LATIN SMALL LETTER O WITH CIRCUMFLEX AND DOT BELOW */
#define XK_Ohornacute                 0x1001eda  /* U+1EDA LATIN CAPITAL LETTER O WITH HORN AND ACUTE */
#define XK_ohornacute                 0x1001edb  /* U+1EDB LATIN SMALL LETTER O WITH HORN AND ACUTE */
#define XK_Ohorngrave                 0x1001edc  /* U+1EDC LATIN CAPITAL LETTER O WITH HORN AND GRAVE */
#define XK_ohorngrave                 0x1001edd  /* U+1EDD LATIN SMALL LETTER O WITH HORN AND GRAVE */
#define XK_Ohornhook                  0x1001ede  /* U+1EDE LATIN CAPITAL LETTER O WITH HORN AND HOOK ABOVE */
#define XK_ohornhook                  0x1001edf  /* U+1EDF LATIN SMALL LETTER O WITH HORN AND HOOK ABOVE */
#define XK_Ohorntilde                 0x1001ee0  /* U+1EE0 LATIN CAPITAL LETTER O WITH HORN AND TILDE */
#define XK_ohorntilde                 0x1001ee1  /* U+1EE1 LATIN SMALL LETTER O WITH HORN AND TILDE */
#define XK_Ohornbelowdot              0x1001ee2  /* U+1EE2 LATIN CAPITAL LETTER O WITH HORN AND DOT BELOW */
#define XK_ohornbelowdot              0x1001ee3  /* U+1EE3 LATIN SMALL LETTER O WITH HORN AND DOT BELOW */
#define XK_Ubelowdot                  0x1001ee4  /* U+1EE4 LATIN CAPITAL LETTER U WITH DOT BELOW */
#define XK_ubelowdot                  0x1001ee5  /* U+1EE5 LATIN SMALL LETTER U WITH DOT BELOW */
#define XK_Uhook                      0x1001ee6  /* U+1EE6 LATIN CAPITAL LETTER U WITH HOOK ABOVE */
#define XK_uhook                      0x1001ee7  /* U+1EE7 LATIN SMALL LETTER U WITH HOOK ABOVE */
#define XK_Uhornacute                 0x1001ee8  /* U+1EE8 LATIN CAPITAL LETTER U WITH HORN AND ACUTE */
#define XK_uhornacute                 0x1001ee9  /* U+1EE9 LATIN SMALL LETTER U WITH HORN AND ACUTE */
#define XK_Uhorngrave                 0x1001eea  /* U+1EEA LATIN CAPITAL LETTER U WITH HORN AND GRAVE */
#define XK_uhorngrave                 0x1001eeb  /* U+1EEB LATIN SMALL LETTER U WITH HORN AND GRAVE */
#define XK_Uhornhook                  0x1001eec  /* U+1EEC LATIN CAPITAL LETTER U WITH HORN AND HOOK ABOVE */
#define XK_uhornhook                  0x1001eed  /* U+1EED LATIN SMALL LETTER U WITH HORN AND HOOK ABOVE */
#define XK_Uhorntilde                 0x1001eee  /* U+1EEE LATIN CAPITAL LETTER U WITH HORN AND TILDE */
#define XK_uhorntilde                 0x1001eef  /* U+1EEF LATIN SMALL LETTER U WITH HORN AND TILDE */
#define XK_Uhornbelowdot              0x1001ef0  /* U+1EF0 LATIN CAPITAL LETTER U WITH HORN AND DOT BELOW */
#define XK_uhornbelowdot              0x1001ef1  /* U+1EF1 LATIN SMALL LETTER U WITH HORN AND DOT BELOW */
#define XK_Ybelowdot                  0x1001ef4  /* U+1EF4 LATIN CAPITAL LETTER Y WITH DOT BELOW */
#define XK_ybelowdot                  0x1001ef5  /* U+1EF5 LATIN SMALL LETTER Y WITH DOT BELOW */
#define XK_Yhook                      0x1001ef6  /* U+1EF6 LATIN CAPITAL LETTER Y WITH HOOK ABOVE */
#define XK_yhook                      0x1001ef7  /* U+1EF7 LATIN SMALL LETTER Y WITH HOOK ABOVE */
#define XK_Ytilde                     0x1001ef8  /* U+1EF8 LATIN CAPITAL LETTER Y WITH TILDE */
#define XK_ytilde                     0x1001ef9  /* U+1EF9 LATIN SMALL LETTER Y WITH TILDE */
#define XK_Ohorn                      0x10001a0  /* U+01A0 LATIN CAPITAL LETTER O WITH HORN */
#define XK_ohorn                      0x10001a1  /* U+01A1 LATIN SMALL LETTER O WITH HORN */
#define XK_Uhorn                      0x10001af  /* U+01AF LATIN CAPITAL LETTER U WITH HORN */
#define XK_uhorn                      0x10001b0  /* U+01B0 LATIN SMALL LETTER U WITH HORN */
#define XK_combining_tilde            0x1000303  /* U+0303 COMBINING TILDE */
#define XK_combining_grave            0x1000300  /* U+0300 COMBINING GRAVE ACCENT */
#define XK_combining_acute            0x1000301  /* U+0301 COMBINING ACUTE ACCENT */
#define XK_combining_hook             0x1000309  /* U+0309 COMBINING HOOK ABOVE */
#define XK_combining_belowdot         0x1000323  /* U+0323 COMBINING DOT BELOW */

#define XK_hebrew_finalpe                              0xcf3
#endif /* XK_VIETNAMESE */

#define XK_hebrew_pe                                   0xcf4
#ifdef XK_CURRENCY
#define XK_EcuSign                    0x10020a0  /* U+20A0 EURO-CURRENCY SIGN */
#define XK_ColonSign                  0x10020a1  /* U+20A1 COLON SIGN */
#define XK_CruzeiroSign               0x10020a2  /* U+20A2 CRUZEIRO SIGN */
#define XK_FFrancSign                 0x10020a3  /* U+20A3 FRENCH FRANC SIGN */
#define XK_LiraSign                   0x10020a4  /* U+20A4 LIRA SIGN */
#define XK_MillSign                   0x10020a5  /* U+20A5 MILL SIGN */
#define XK_hebrew_finalzade                            0xcf5
#define XK_hebrew_finalzadi                            0xcf5  /* deprecated */
#define XK_NairaSign                  0x10020a6  /* U+20A6 NAIRA SIGN */
#define XK_PesetaSign                 0x10020a7  /* U+20A7 PESETA SIGN */
#define XK_RupeeSign                  0x10020a8  /* U+20A8 RUPEE SIGN */
#define XK_WonSign                    0x10020a9  /* U+20A9 WON SIGN */
#define XK_hebrew_zade                                 0xcf6
#define XK_NewSheqelSign              0x10020aa  /* U+20AA NEW SHEQEL SIGN */
#define XK_DongSign                   0x10020ab  /* U+20AB DONG SIGN */
#define XK_EuroSign                      0x20ac  /* U+20AC EURO SIGN */
#endif /* XK_CURRENCY */

#define XK_hebrew_zadi                                 0xcf6  /* deprecated */
#ifdef XK_MATHEMATICAL
/* one, two and three are defined above. */
#define XK_zerosuperior               0x1002070  /* U+2070 SUPERSCRIPT ZERO */
#define XK_foursuperior               0x1002074  /* U+2074 SUPERSCRIPT FOUR */
#define XK_fivesuperior               0x1002075  /* U+2075 SUPERSCRIPT FIVE */
#define XK_sixsuperior                0x1002076  /* U+2076 SUPERSCRIPT SIX */
#define XK_sevensuperior              0x1002077  /* U+2077 SUPERSCRIPT SEVEN */
#define XK_eightsuperior              0x1002078  /* U+2078 SUPERSCRIPT EIGHT */
#define XK_ninesuperior               0x1002079  /* U+2079 SUPERSCRIPT NINE */
#define XK_zerosubscript              0x1002080  /* U+2080 SUBSCRIPT ZERO */
#define XK_onesubscript               0x1002081  /* U+2081 SUBSCRIPT ONE */
#define XK_twosubscript               0x1002082  /* U+2082 SUBSCRIPT TWO */
#define XK_threesubscript             0x1002083  /* U+2083 SUBSCRIPT THREE */
#define XK_foursubscript              0x1002084  /* U+2084 SUBSCRIPT FOUR */
#define XK_fivesubscript              0x1002085  /* U+2085 SUBSCRIPT FIVE */
#define XK_sixsubscript               0x1002086  /* U+2086 SUBSCRIPT SIX */
#define XK_sevensubscript             0x1002087  /* U+2087 SUBSCRIPT SEVEN */
#define XK_eightsubscript             0x1002088  /* U+2088 SUBSCRIPT EIGHT */
#define XK_ninesubscript              0x1002089  /* U+2089 SUBSCRIPT NINE */
#define XK_partdifferential           0x1002202  /* U+2202 PARTIAL DIFFERENTIAL */
#define XK_emptyset                   0x1002205  /* U+2205 EMPTY SET */
#define XK_hebrew_qoph                                 0xcf7
#define XK_elementof                  0x1002208  /* U+2208 ELEMENT OF */
#define XK_notelementof               0x1002209  /* U+2209 NOT AN ELEMENT OF */
#define XK_containsas                 0x100220b  /* U+220B CONTAINS AS MEMBER */
#define XK_squareroot                 0x100221a  /* U+221A SQUARE ROOT */
#define XK_cuberoot                   0x100221b  /* U+221B CUBE ROOT */
#define XK_fourthroot                 0x100221c  /* U+221C FOURTH ROOT */
#define XK_dintegral                  0x100222c  /* U+222C DOUBLE INTEGRAL */
#define XK_tintegral                  0x100222d  /* U+222D TRIPLE INTEGRAL */
#define XK_because                    0x1002235  /* U+2235 BECAUSE */
#define XK_approxeq                   0x1002248  /*(U+2248 ALMOST EQUAL TO)*/
#define XK_notapproxeq                0x1002247  /*(U+2247 NEITHER APPROXIMATELY NOR ACTUALLY EQUAL TO)*/
#define XK_notidentical               0x1002262  /* U+2262 NOT IDENTICAL TO */
#define XK_stricteq                   0x1002263  /* U+2263 STRICTLY EQUIVALENT TO */
#endif /* XK_MATHEMATICAL */

#define XK_hebrew_kuf                                  0xcf7  /* deprecated */
#ifdef XK_BRAILLE
#define XK_braille_dot_1                 0xfff1
#define XK_braille_dot_2                 0xfff2
#define XK_braille_dot_3                 0xfff3
#define XK_braille_dot_4                 0xfff4
#define XK_braille_dot_5                 0xfff5
#define XK_braille_dot_6                 0xfff6
#define XK_hebrew_resh                                 0xcf8
#define XK_hebrew_shin                                 0xcf9
#define XK_hebrew_taw                                  0xcfa
#define XK_hebrew_taf                                  0xcfa  /* deprecated */
#define XK_Hebrew_switch        0xFF7E  /* Alias for mode_switch */
#endif /* XK_HEBREW */
#define XK_braille_dot_7                 0xfff7
#define XK_braille_dot_8                 0xfff8
#define XK_braille_dot_9                 0xfff9
#define XK_braille_dot_10                0xfffa
#define XK_braille_blank              0x1002800  /* U+2800 BRAILLE PATTERN BLANK */
#define XK_braille_dots_1             0x1002801  /* U+2801 BRAILLE PATTERN DOTS-1 */
#define XK_braille_dots_2             0x1002802  /* U+2802 BRAILLE PATTERN DOTS-2 */
#define XK_braille_dots_12            0x1002803  /* U+2803 BRAILLE PATTERN DOTS-12 */
#define XK_braille_dots_3             0x1002804  /* U+2804 BRAILLE PATTERN DOTS-3 */
#define XK_braille_dots_13            0x1002805  /* U+2805 BRAILLE PATTERN DOTS-13 */
#define XK_braille_dots_23            0x1002806  /* U+2806 BRAILLE PATTERN DOTS-23 */
#define XK_braille_dots_123           0x1002807  /* U+2807 BRAILLE PATTERN DOTS-123 */
#define XK_braille_dots_4             0x1002808  /* U+2808 BRAILLE PATTERN DOTS-4 */
#define XK_braille_dots_14            0x1002809  /* U+2809 BRAILLE PATTERN DOTS-14 */
#define XK_braille_dots_24            0x100280a  /* U+280A BRAILLE PATTERN DOTS-24 */
#define XK_braille_dots_124           0x100280b  /* U+280B BRAILLE PATTERN DOTS-124 */
#define XK_braille_dots_34            0x100280c  /* U+280C BRAILLE PATTERN DOTS-34 */
#define XK_braille_dots_134           0x100280d  /* U+280D BRAILLE PATTERN DOTS-134 */
#define XK_braille_dots_234           0x100280e  /* U+280E BRAILLE PATTERN DOTS-234 */
#define XK_braille_dots_1234          0x100280f  /* U+280F BRAILLE PATTERN DOTS-1234 */
#define XK_braille_dots_5             0x1002810  /* U+2810 BRAILLE PATTERN DOTS-5 */
#define XK_braille_dots_15            0x1002811  /* U+2811 BRAILLE PATTERN DOTS-15 */
#define XK_braille_dots_25            0x1002812  /* U+2812 BRAILLE PATTERN DOTS-25 */
#define XK_braille_dots_125           0x1002813  /* U+2813 BRAILLE PATTERN DOTS-125 */
#define XK_braille_dots_35            0x1002814  /* U+2814 BRAILLE PATTERN DOTS-35 */
#define XK_braille_dots_135           0x1002815  /* U+2815 BRAILLE PATTERN DOTS-135 */
#define XK_braille_dots_235           0x1002816  /* U+2816 BRAILLE PATTERN DOTS-235 */
#define XK_braille_dots_1235          0x1002817  /* U+2817 BRAILLE PATTERN DOTS-1235 */
#define XK_braille_dots_45            0x1002818  /* U+2818 BRAILLE PATTERN DOTS-45 */
#define XK_braille_dots_145           0x1002819  /* U+2819 BRAILLE PATTERN DOTS-145 */
#define XK_braille_dots_245           0x100281a  /* U+281A BRAILLE PATTERN DOTS-245 */
#define XK_braille_dots_1245          0x100281b  /* U+281B BRAILLE PATTERN DOTS-1245 */
#define XK_braille_dots_345           0x100281c  /* U+281C BRAILLE PATTERN DOTS-345 */
#define XK_braille_dots_1345          0x100281d  /* U+281D BRAILLE PATTERN DOTS-1345 */
#define XK_braille_dots_2345          0x100281e  /* U+281E BRAILLE PATTERN DOTS-2345 */
#define XK_braille_dots_12345         0x100281f  /* U+281F BRAILLE PATTERN DOTS-12345 */
#define XK_braille_dots_6             0x1002820  /* U+2820 BRAILLE PATTERN DOTS-6 */
#define XK_braille_dots_16            0x1002821  /* U+2821 BRAILLE PATTERN DOTS-16 */
#define XK_braille_dots_26            0x1002822  /* U+2822 BRAILLE PATTERN DOTS-26 */
#define XK_braille_dots_126           0x1002823  /* U+2823 BRAILLE PATTERN DOTS-126 */
#define XK_braille_dots_36            0x1002824  /* U+2824 BRAILLE PATTERN DOTS-36 */
#define XK_braille_dots_136           0x1002825  /* U+2825 BRAILLE PATTERN DOTS-136 */
#define XK_braille_dots_236           0x1002826  /* U+2826 BRAILLE PATTERN DOTS-236 */
#define XK_braille_dots_1236          0x1002827  /* U+2827 BRAILLE PATTERN DOTS-1236 */
#define XK_braille_dots_46            0x1002828  /* U+2828 BRAILLE PATTERN DOTS-46 */
#define XK_braille_dots_146           0x1002829  /* U+2829 BRAILLE PATTERN DOTS-146 */
#define XK_braille_dots_246           0x100282a  /* U+282A BRAILLE PATTERN DOTS-246 */
#define XK_braille_dots_1246          0x100282b  /* U+282B BRAILLE PATTERN DOTS-1246 */
#define XK_braille_dots_346           0x100282c  /* U+282C BRAILLE PATTERN DOTS-346 */
#define XK_braille_dots_1346          0x100282d  /* U+282D BRAILLE PATTERN DOTS-1346 */
#define XK_braille_dots_2346          0x100282e  /* U+282E BRAILLE PATTERN DOTS-2346 */
#define XK_braille_dots_12346         0x100282f  /* U+282F BRAILLE PATTERN DOTS-12346 */
#define XK_braille_dots_56            0x1002830  /* U+2830 BRAILLE PATTERN DOTS-56 */
#define XK_braille_dots_156           0x1002831  /* U+2831 BRAILLE PATTERN DOTS-156 */
#define XK_braille_dots_256           0x1002832  /* U+2832 BRAILLE PATTERN DOTS-256 */
#define XK_braille_dots_1256          0x1002833  /* U+2833 BRAILLE PATTERN DOTS-1256 */
#define XK_braille_dots_356           0x1002834  /* U+2834 BRAILLE PATTERN DOTS-356 */
#define XK_braille_dots_1356          0x1002835  /* U+2835 BRAILLE PATTERN DOTS-1356 */
#define XK_braille_dots_2356          0x1002836  /* U+2836 BRAILLE PATTERN DOTS-2356 */
#define XK_braille_dots_12356         0x1002837  /* U+2837 BRAILLE PATTERN DOTS-12356 */
#define XK_braille_dots_456           0x1002838  /* U+2838 BRAILLE PATTERN DOTS-456 */
#define XK_braille_dots_1456          0x1002839  /* U+2839 BRAILLE PATTERN DOTS-1456 */
#define XK_braille_dots_2456          0x100283a  /* U+283A BRAILLE PATTERN DOTS-2456 */
#define XK_braille_dots_12456         0x100283b  /* U+283B BRAILLE PATTERN DOTS-12456 */
#define XK_braille_dots_3456          0x100283c  /* U+283C BRAILLE PATTERN DOTS-3456 */
#define XK_braille_dots_13456         0x100283d  /* U+283D BRAILLE PATTERN DOTS-13456 */
#define XK_braille_dots_23456         0x100283e  /* U+283E BRAILLE PATTERN DOTS-23456 */
#define XK_braille_dots_123456        0x100283f  /* U+283F BRAILLE PATTERN DOTS-123456 */
#define XK_braille_dots_7             0x1002840  /* U+2840 BRAILLE PATTERN DOTS-7 */
#define XK_braille_dots_17            0x1002841  /* U+2841 BRAILLE PATTERN DOTS-17 */
#define XK_braille_dots_27            0x1002842  /* U+2842 BRAILLE PATTERN DOTS-27 */
#define XK_braille_dots_127           0x1002843  /* U+2843 BRAILLE PATTERN DOTS-127 */
#define XK_braille_dots_37            0x1002844  /* U+2844 BRAILLE PATTERN DOTS-37 */
#define XK_braille_dots_137           0x1002845  /* U+2845 BRAILLE PATTERN DOTS-137 */
#define XK_braille_dots_237           0x1002846  /* U+2846 BRAILLE PATTERN DOTS-237 */
#define XK_braille_dots_1237          0x1002847  /* U+2847 BRAILLE PATTERN DOTS-1237 */
#define XK_braille_dots_47            0x1002848  /* U+2848 BRAILLE PATTERN DOTS-47 */
#define XK_braille_dots_147           0x1002849  /* U+2849 BRAILLE PATTERN DOTS-147 */
#define XK_braille_dots_247           0x100284a  /* U+284A BRAILLE PATTERN DOTS-247 */
#define XK_braille_dots_1247          0x100284b  /* U+284B BRAILLE PATTERN DOTS-1247 */
#define XK_braille_dots_347           0x100284c  /* U+284C BRAILLE PATTERN DOTS-347 */
#define XK_braille_dots_1347          0x100284d  /* U+284D BRAILLE PATTERN DOTS-1347 */
#define XK_braille_dots_2347          0x100284e  /* U+284E BRAILLE PATTERN DOTS-2347 */
#define XK_braille_dots_12347         0x100284f  /* U+284F BRAILLE PATTERN DOTS-12347 */
#define XK_braille_dots_57            0x1002850  /* U+2850 BRAILLE PATTERN DOTS-57 */
#define XK_braille_dots_157           0x1002851  /* U+2851 BRAILLE PATTERN DOTS-157 */
#define XK_braille_dots_257           0x1002852  /* U+2852 BRAILLE PATTERN DOTS-257 */
#define XK_braille_dots_1257          0x1002853  /* U+2853 BRAILLE PATTERN DOTS-1257 */
#define XK_braille_dots_357           0x1002854  /* U+2854 BRAILLE PATTERN DOTS-357 */
#define XK_braille_dots_1357          0x1002855  /* U+2855 BRAILLE PATTERN DOTS-1357 */
#define XK_braille_dots_2357          0x1002856  /* U+2856 BRAILLE PATTERN DOTS-2357 */
#define XK_braille_dots_12357         0x1002857  /* U+2857 BRAILLE PATTERN DOTS-12357 */
#define XK_braille_dots_457           0x1002858  /* U+2858 BRAILLE PATTERN DOTS-457 */
#define XK_braille_dots_1457          0x1002859  /* U+2859 BRAILLE PATTERN DOTS-1457 */
#define XK_braille_dots_2457          0x100285a  /* U+285A BRAILLE PATTERN DOTS-2457 */
#define XK_braille_dots_12457         0x100285b  /* U+285B BRAILLE PATTERN DOTS-12457 */
#define XK_braille_dots_3457          0x100285c  /* U+285C BRAILLE PATTERN DOTS-3457 */
#define XK_braille_dots_13457         0x100285d  /* U+285D BRAILLE PATTERN DOTS-13457 */
#define XK_braille_dots_23457         0x100285e  /* U+285E BRAILLE PATTERN DOTS-23457 */
#define XK_braille_dots_123457        0x100285f  /* U+285F BRAILLE PATTERN DOTS-123457 */
#define XK_braille_dots_67            0x1002860  /* U+2860 BRAILLE PATTERN DOTS-67 */
#define XK_braille_dots_167           0x1002861  /* U+2861 BRAILLE PATTERN DOTS-167 */
#define XK_braille_dots_267           0x1002862  /* U+2862 BRAILLE PATTERN DOTS-267 */
#define XK_braille_dots_1267          0x1002863  /* U+2863 BRAILLE PATTERN DOTS-1267 */
#define XK_braille_dots_367           0x1002864  /* U+2864 BRAILLE PATTERN DOTS-367 */
#define XK_braille_dots_1367          0x1002865  /* U+2865 BRAILLE PATTERN DOTS-1367 */
#define XK_braille_dots_2367          0x1002866  /* U+2866 BRAILLE PATTERN DOTS-2367 */
#define XK_braille_dots_12367         0x1002867  /* U+2867 BRAILLE PATTERN DOTS-12367 */
#define XK_braille_dots_467           0x1002868  /* U+2868 BRAILLE PATTERN DOTS-467 */
#define XK_braille_dots_1467          0x1002869  /* U+2869 BRAILLE PATTERN DOTS-1467 */
#define XK_braille_dots_2467          0x100286a  /* U+286A BRAILLE PATTERN DOTS-2467 */
#define XK_braille_dots_12467         0x100286b  /* U+286B BRAILLE PATTERN DOTS-12467 */
#define XK_braille_dots_3467          0x100286c  /* U+286C BRAILLE PATTERN DOTS-3467 */
#define XK_braille_dots_13467         0x100286d  /* U+286D BRAILLE PATTERN DOTS-13467 */
#define XK_braille_dots_23467         0x100286e  /* U+286E BRAILLE PATTERN DOTS-23467 */

/* Multimedia keys, defined same as on Linux
 * /usr/include/pkg/libxkbcommon/xkbcommon/xkbcommon-keysyms.h
 */
#define XK_braille_dots_123467        0x100286f  /* U+286F BRAILLE PATTERN DOTS-123467 */
#define XK_braille_dots_567           0x1002870  /* U+2870 BRAILLE PATTERN DOTS-567 */
#define XK_braille_dots_1567          0x1002871  /* U+2871 BRAILLE PATTERN DOTS-1567 */
#define XK_braille_dots_2567          0x1002872  /* U+2872 BRAILLE PATTERN DOTS-2567 */
#define XK_braille_dots_12567         0x1002873  /* U+2873 BRAILLE PATTERN DOTS-12567 */
#define XK_braille_dots_3567          0x1002874  /* U+2874 BRAILLE PATTERN DOTS-3567 */
#define XK_braille_dots_13567         0x1002875  /* U+2875 BRAILLE PATTERN DOTS-13567 */
#define XK_braille_dots_23567         0x1002876  /* U+2876 BRAILLE PATTERN DOTS-23567 */
#define XK_braille_dots_123567        0x1002877  /* U+2877 BRAILLE PATTERN DOTS-123567 */
#define XK_braille_dots_4567          0x1002878  /* U+2878 BRAILLE PATTERN DOTS-4567 */
#define XK_braille_dots_14567         0x1002879  /* U+2879 BRAILLE PATTERN DOTS-14567 */
#define XK_braille_dots_24567         0x100287a  /* U+287A BRAILLE PATTERN DOTS-24567 */
#define XK_braille_dots_124567        0x100287b  /* U+287B BRAILLE PATTERN DOTS-124567 */
#define XK_braille_dots_34567         0x100287c  /* U+287C BRAILLE PATTERN DOTS-34567 */
#define XK_braille_dots_134567        0x100287d  /* U+287D BRAILLE PATTERN DOTS-134567 */
#define XK_braille_dots_234567        0x100287e  /* U+287E BRAILLE PATTERN DOTS-234567 */
#define XK_braille_dots_1234567       0x100287f  /* U+287F BRAILLE PATTERN DOTS-1234567 */
#define XK_braille_dots_8             0x1002880  /* U+2880 BRAILLE PATTERN DOTS-8 */
#define XK_braille_dots_18            0x1002881  /* U+2881 BRAILLE PATTERN DOTS-18 */
#define XK_braille_dots_28            0x1002882  /* U+2882 BRAILLE PATTERN DOTS-28 */
#define XK_braille_dots_128           0x1002883  /* U+2883 BRAILLE PATTERN DOTS-128 */
#define XK_braille_dots_38            0x1002884  /* U+2884 BRAILLE PATTERN DOTS-38 */
#define XK_braille_dots_138           0x1002885  /* U+2885 BRAILLE PATTERN DOTS-138 */
#define XK_braille_dots_238           0x1002886  /* U+2886 BRAILLE PATTERN DOTS-238 */
#define XK_braille_dots_1238          0x1002887  /* U+2887 BRAILLE PATTERN DOTS-1238 */
#define XK_braille_dots_48            0x1002888  /* U+2888 BRAILLE PATTERN DOTS-48 */
#define XK_braille_dots_148           0x1002889  /* U+2889 BRAILLE PATTERN DOTS-148 */
#define XK_braille_dots_248           0x100288a  /* U+288A BRAILLE PATTERN DOTS-248 */
#define XK_braille_dots_1248          0x100288b  /* U+288B BRAILLE PATTERN DOTS-1248 */
#define XK_braille_dots_348           0x100288c  /* U+288C BRAILLE PATTERN DOTS-348 */
#define XK_braille_dots_1348          0x100288d  /* U+288D BRAILLE PATTERN DOTS-1348 */
#define XK_braille_dots_2348          0x100288e  /* U+288E BRAILLE PATTERN DOTS-2348 */
#define XK_braille_dots_12348         0x100288f  /* U+288F BRAILLE PATTERN DOTS-12348 */
#define XK_braille_dots_58            0x1002890  /* U+2890 BRAILLE PATTERN DOTS-58 */
#define XK_braille_dots_158           0x1002891  /* U+2891 BRAILLE PATTERN DOTS-158 */
#define XK_braille_dots_258           0x1002892  /* U+2892 BRAILLE PATTERN DOTS-258 */
#define XK_braille_dots_1258          0x1002893  /* U+2893 BRAILLE PATTERN DOTS-1258 */
#define XK_braille_dots_358           0x1002894  /* U+2894 BRAILLE PATTERN DOTS-358 */
#define XK_braille_dots_1358          0x1002895  /* U+2895 BRAILLE PATTERN DOTS-1358 */
#define XK_braille_dots_2358          0x1002896  /* U+2896 BRAILLE PATTERN DOTS-2358 */
#define XK_braille_dots_12358         0x1002897  /* U+2897 BRAILLE PATTERN DOTS-12358 */
#define XK_braille_dots_458           0x1002898  /* U+2898 BRAILLE PATTERN DOTS-458 */
#define XK_braille_dots_1458          0x1002899  /* U+2899 BRAILLE PATTERN DOTS-1458 */
#define XK_braille_dots_2458          0x100289a  /* U+289A BRAILLE PATTERN DOTS-2458 */
#define XK_braille_dots_12458         0x100289b  /* U+289B BRAILLE PATTERN DOTS-12458 */
#define XK_braille_dots_3458          0x100289c  /* U+289C BRAILLE PATTERN DOTS-3458 */
#define XK_braille_dots_13458         0x100289d  /* U+289D BRAILLE PATTERN DOTS-13458 */
#define XK_braille_dots_23458         0x100289e  /* U+289E BRAILLE PATTERN DOTS-23458 */
#define XK_braille_dots_123458        0x100289f  /* U+289F BRAILLE PATTERN DOTS-123458 */
#define XK_braille_dots_68            0x10028a0  /* U+28A0 BRAILLE PATTERN DOTS-68 */
#define XK_braille_dots_168           0x10028a1  /* U+28A1 BRAILLE PATTERN DOTS-168 */
#define XK_braille_dots_268           0x10028a2  /* U+28A2 BRAILLE PATTERN DOTS-268 */
#define XK_braille_dots_1268          0x10028a3  /* U+28A3 BRAILLE PATTERN DOTS-1268 */
#define XK_braille_dots_368           0x10028a4  /* U+28A4 BRAILLE PATTERN DOTS-368 */
#define XK_braille_dots_1368          0x10028a5  /* U+28A5 BRAILLE PATTERN DOTS-1368 */
#define XK_braille_dots_2368          0x10028a6  /* U+28A6 BRAILLE PATTERN DOTS-2368 */
#define XK_braille_dots_12368         0x10028a7  /* U+28A7 BRAILLE PATTERN DOTS-12368 */
#define XK_braille_dots_468           0x10028a8  /* U+28A8 BRAILLE PATTERN DOTS-468 */
#define XK_braille_dots_1468          0x10028a9  /* U+28A9 BRAILLE PATTERN DOTS-1468 */
#define XK_braille_dots_2468          0x10028aa  /* U+28AA BRAILLE PATTERN DOTS-2468 */
#define XK_braille_dots_12468         0x10028ab  /* U+28AB BRAILLE PATTERN DOTS-12468 */
#define XK_braille_dots_3468          0x10028ac  /* U+28AC BRAILLE PATTERN DOTS-3468 */
#define XK_braille_dots_13468         0x10028ad  /* U+28AD BRAILLE PATTERN DOTS-13468 */
#define XK_braille_dots_23468         0x10028ae  /* U+28AE BRAILLE PATTERN DOTS-23468 */
#define XK_braille_dots_123468        0x10028af  /* U+28AF BRAILLE PATTERN DOTS-123468 */
#define XK_braille_dots_568           0x10028b0  /* U+28B0 BRAILLE PATTERN DOTS-568 */
#define XK_braille_dots_1568          0x10028b1  /* U+28B1 BRAILLE PATTERN DOTS-1568 */
#define XK_braille_dots_2568          0x10028b2  /* U+28B2 BRAILLE PATTERN DOTS-2568 */
#define XK_braille_dots_12568         0x10028b3  /* U+28B3 BRAILLE PATTERN DOTS-12568 */
#define XK_braille_dots_3568          0x10028b4  /* U+28B4 BRAILLE PATTERN DOTS-3568 */
#define XK_braille_dots_13568         0x10028b5  /* U+28B5 BRAILLE PATTERN DOTS-13568 */
#define XK_braille_dots_23568         0x10028b6  /* U+28B6 BRAILLE PATTERN DOTS-23568 */
#define XK_braille_dots_123568        0x10028b7  /* U+28B7 BRAILLE PATTERN DOTS-123568 */
#define XK_braille_dots_4568          0x10028b8  /* U+28B8 BRAILLE PATTERN DOTS-4568 */
#define XK_braille_dots_14568         0x10028b9  /* U+28B9 BRAILLE PATTERN DOTS-14568 */
#define XK_braille_dots_24568         0x10028ba  /* U+28BA BRAILLE PATTERN DOTS-24568 */
#define XK_braille_dots_124568        0x10028bb  /* U+28BB BRAILLE PATTERN DOTS-124568 */
#define XK_braille_dots_34568         0x10028bc  /* U+28BC BRAILLE PATTERN DOTS-34568 */
#define XK_braille_dots_134568        0x10028bd  /* U+28BD BRAILLE PATTERN DOTS-134568 */
#define XK_braille_dots_234568        0x10028be  /* U+28BE BRAILLE PATTERN DOTS-234568 */
#define XK_braille_dots_1234568       0x10028bf  /* U+28BF BRAILLE PATTERN DOTS-1234568 */
#define XK_braille_dots_78            0x10028c0  /* U+28C0 BRAILLE PATTERN DOTS-78 */
#define XK_braille_dots_178           0x10028c1  /* U+28C1 BRAILLE PATTERN DOTS-178 */
#define XK_braille_dots_278           0x10028c2  /* U+28C2 BRAILLE PATTERN DOTS-278 */
#define XK_braille_dots_1278          0x10028c3  /* U+28C3 BRAILLE PATTERN DOTS-1278 */
#define XK_braille_dots_378           0x10028c4  /* U+28C4 BRAILLE PATTERN DOTS-378 */
#define XK_braille_dots_1378          0x10028c5  /* U+28C5 BRAILLE PATTERN DOTS-1378 */
#define XK_braille_dots_2378          0x10028c6  /* U+28C6 BRAILLE PATTERN DOTS-2378 */
#define XK_braille_dots_12378         0x10028c7  /* U+28C7 BRAILLE PATTERN DOTS-12378 */
#define XK_braille_dots_478           0x10028c8  /* U+28C8 BRAILLE PATTERN DOTS-478 */
#define XK_braille_dots_1478          0x10028c9  /* U+28C9 BRAILLE PATTERN DOTS-1478 */
#define XK_braille_dots_2478          0x10028ca  /* U+28CA BRAILLE PATTERN DOTS-2478 */
#define XK_braille_dots_12478         0x10028cb  /* U+28CB BRAILLE PATTERN DOTS-12478 */
#define XK_braille_dots_3478          0x10028cc  /* U+28CC BRAILLE PATTERN DOTS-3478 */
#define XK_braille_dots_13478         0x10028cd  /* U+28CD BRAILLE PATTERN DOTS-13478 */
#define XK_braille_dots_23478         0x10028ce  /* U+28CE BRAILLE PATTERN DOTS-23478 */
#define XK_braille_dots_123478        0x10028cf  /* U+28CF BRAILLE PATTERN DOTS-123478 */
#define XK_braille_dots_578           0x10028d0  /* U+28D0 BRAILLE PATTERN DOTS-578 */
#define XK_braille_dots_1578          0x10028d1  /* U+28D1 BRAILLE PATTERN DOTS-1578 */
#define XK_braille_dots_2578          0x10028d2  /* U+28D2 BRAILLE PATTERN DOTS-2578 */
#define XK_braille_dots_12578         0x10028d3  /* U+28D3 BRAILLE PATTERN DOTS-12578 */
#define XK_braille_dots_3578          0x10028d4  /* U+28D4 BRAILLE PATTERN DOTS-3578 */
#define XK_braille_dots_13578         0x10028d5  /* U+28D5 BRAILLE PATTERN DOTS-13578 */
#define XK_braille_dots_23578         0x10028d6  /* U+28D6 BRAILLE PATTERN DOTS-23578 */
#define XK_braille_dots_123578        0x10028d7  /* U+28D7 BRAILLE PATTERN DOTS-123578 */
#define XK_braille_dots_4578          0x10028d8  /* U+28D8 BRAILLE PATTERN DOTS-4578 */
#define XK_braille_dots_14578         0x10028d9  /* U+28D9 BRAILLE PATTERN DOTS-14578 */
#define XK_braille_dots_24578         0x10028da  /* U+28DA BRAILLE PATTERN DOTS-24578 */
#define XK_braille_dots_124578        0x10028db  /* U+28DB BRAILLE PATTERN DOTS-124578 */
#define XK_braille_dots_34578         0x10028dc  /* U+28DC BRAILLE PATTERN DOTS-34578 */
#define XK_braille_dots_134578        0x10028dd  /* U+28DD BRAILLE PATTERN DOTS-134578 */
#define XK_braille_dots_234578        0x10028de  /* U+28DE BRAILLE PATTERN DOTS-234578 */
#define XK_braille_dots_1234578       0x10028df  /* U+28DF BRAILLE PATTERN DOTS-1234578 */
#define XK_braille_dots_678           0x10028e0  /* U+28E0 BRAILLE PATTERN DOTS-678 */
#define XK_braille_dots_1678          0x10028e1  /* U+28E1 BRAILLE PATTERN DOTS-1678 */
#define XK_braille_dots_2678          0x10028e2  /* U+28E2 BRAILLE PATTERN DOTS-2678 */
#define XK_braille_dots_12678         0x10028e3  /* U+28E3 BRAILLE PATTERN DOTS-12678 */
#define XK_braille_dots_3678          0x10028e4  /* U+28E4 BRAILLE PATTERN DOTS-3678 */
#define XK_braille_dots_13678         0x10028e5  /* U+28E5 BRAILLE PATTERN DOTS-13678 */
#define XK_braille_dots_23678         0x10028e6  /* U+28E6 BRAILLE PATTERN DOTS-23678 */
#define XK_braille_dots_123678        0x10028e7  /* U+28E7 BRAILLE PATTERN DOTS-123678 */
#define XK_braille_dots_4678          0x10028e8  /* U+28E8 BRAILLE PATTERN DOTS-4678 */
#define XK_braille_dots_14678         0x10028e9  /* U+28E9 BRAILLE PATTERN DOTS-14678 */
#define XK_braille_dots_24678         0x10028ea  /* U+28EA BRAILLE PATTERN DOTS-24678 */
#define XK_braille_dots_124678        0x10028eb  /* U+28EB BRAILLE PATTERN DOTS-124678 */
#define XK_braille_dots_34678         0x10028ec  /* U+28EC BRAILLE PATTERN DOTS-34678 */
#define XK_braille_dots_134678        0x10028ed  /* U+28ED BRAILLE PATTERN DOTS-134678 */
#define XK_braille_dots_234678        0x10028ee  /* U+28EE BRAILLE PATTERN DOTS-234678 */
#define XK_braille_dots_1234678       0x10028ef  /* U+28EF BRAILLE PATTERN DOTS-1234678 */
#define XK_braille_dots_5678          0x10028f0  /* U+28F0 BRAILLE PATTERN DOTS-5678 */
#define XK_braille_dots_15678         0x10028f1  /* U+28F1 BRAILLE PATTERN DOTS-15678 */
#define XK_braille_dots_25678         0x10028f2  /* U+28F2 BRAILLE PATTERN DOTS-25678 */
#define XK_braille_dots_125678        0x10028f3  /* U+28F3 BRAILLE PATTERN DOTS-125678 */
#define XK_braille_dots_35678         0x10028f4  /* U+28F4 BRAILLE PATTERN DOTS-35678 */
#define XK_braille_dots_135678        0x10028f5  /* U+28F5 BRAILLE PATTERN DOTS-135678 */
#define XK_braille_dots_235678        0x10028f6  /* U+28F6 BRAILLE PATTERN DOTS-235678 */
#define XK_braille_dots_1235678       0x10028f7  /* U+28F7 BRAILLE PATTERN DOTS-1235678 */
#define XK_braille_dots_45678         0x10028f8  /* U+28F8 BRAILLE PATTERN DOTS-45678 */
#define XK_braille_dots_145678        0x10028f9  /* U+28F9 BRAILLE PATTERN DOTS-145678 */
#define XK_braille_dots_245678        0x10028fa  /* U+28FA BRAILLE PATTERN DOTS-245678 */
#define XK_braille_dots_1245678       0x10028fb  /* U+28FB BRAILLE PATTERN DOTS-1245678 */
#define XK_braille_dots_345678        0x10028fc  /* U+28FC BRAILLE PATTERN DOTS-345678 */
#define XK_braille_dots_1345678       0x10028fd  /* U+28FD BRAILLE PATTERN DOTS-1345678 */
#define XK_braille_dots_2345678       0x10028fe  /* U+28FE BRAILLE PATTERN DOTS-2345678 */
#define XK_braille_dots_12345678      0x10028ff  /* U+28FF BRAILLE PATTERN DOTS-12345678 */
#endif /* XK_BRAILLE */

/*
 * Sinhala (http://unicode.org/charts/PDF/U0D80.pdf)
 * http://www.nongnu.org/sinhala/doc/transliteration/sinhala-transliteration_6.html
 */

#define XK_XF86AudioLowerVolume	0x1008FF11   /* Volume control down        */
#ifdef XK_SINHALA
#define XK_Sinh_ng                    0x1000d82  /* U+0D82 SINHALA SIGN ANUSVARAYA */
#define XK_Sinh_h2                    0x1000d83  /* U+0D83 SINHALA SIGN VISARGAYA */
#define XK_Sinh_a                     0x1000d85  /* U+0D85 SINHALA LETTER AYANNA */
#define XK_Sinh_aa                    0x1000d86  /* U+0D86 SINHALA LETTER AAYANNA */
#define XK_Sinh_ae                    0x1000d87  /* U+0D87 SINHALA LETTER AEYANNA */
#define XK_Sinh_aee                   0x1000d88  /* U+0D88 SINHALA LETTER AEEYANNA */
#define XK_Sinh_i                     0x1000d89  /* U+0D89 SINHALA LETTER IYANNA */
#define XK_XF86AudioMute	0x1008FF12   /* Mute sound from the system */
#define XK_XF86AudioRaiseVolume	0x1008FF13   /* Volume control up          */
#define XK_XF86AudioPlay	0x1008FF14   /* Start playing of audio >   */
#define XK_XF86AudioStop	0x1008FF15   /* Stop playing audio         */
#define XK_XF86AudioPrev	0x1008FF16   /* Previous track             */
#define XK_XF86AudioNext	0x1008FF17   /* Next track                 */

#define XK_Sinh_ii                    0x1000d8a  /* U+0D8A SINHALA LETTER IIYANNA */
#define XK_Sinh_u                     0x1000d8b  /* U+0D8B SINHALA LETTER UYANNA */
#define XK_Sinh_uu                    0x1000d8c  /* U+0D8C SINHALA LETTER UUYANNA */
#define XK_Sinh_ri                    0x1000d8d  /* U+0D8D SINHALA LETTER IRUYANNA */
#define XK_Sinh_rii                   0x1000d8e  /* U+0D8E SINHALA LETTER IRUUYANNA */
#define XK_Sinh_lu                    0x1000d8f  /* U+0D8F SINHALA LETTER ILUYANNA */
#define XK_Sinh_luu                   0x1000d90  /* U+0D90 SINHALA LETTER ILUUYANNA */
#define XK_Sinh_e                     0x1000d91  /* U+0D91 SINHALA LETTER EYANNA */
#define XK_Sinh_ee                    0x1000d92  /* U+0D92 SINHALA LETTER EEYANNA */
#define XK_Sinh_ai                    0x1000d93  /* U+0D93 SINHALA LETTER AIYANNA */
#define XK_Sinh_o                     0x1000d94  /* U+0D94 SINHALA LETTER OYANNA */
#define XK_Sinh_oo                    0x1000d95  /* U+0D95 SINHALA LETTER OOYANNA */
#define XK_Sinh_au                    0x1000d96  /* U+0D96 SINHALA LETTER AUYANNA */
#define XK_Sinh_ka                    0x1000d9a  /* U+0D9A SINHALA LETTER ALPAPRAANA KAYANNA */
#define XK_Sinh_kha                   0x1000d9b  /* U+0D9B SINHALA LETTER MAHAAPRAANA KAYANNA */
#define XK_Sinh_ga                    0x1000d9c  /* U+0D9C SINHALA LETTER ALPAPRAANA GAYANNA */
#define XK_Sinh_gha                   0x1000d9d  /* U+0D9D SINHALA LETTER MAHAAPRAANA GAYANNA */
#define XK_Sinh_ng2                   0x1000d9e  /* U+0D9E SINHALA LETTER KANTAJA NAASIKYAYA */
#define XK_Sinh_nga                   0x1000d9f  /* U+0D9F SINHALA LETTER SANYAKA GAYANNA */
#define XK_Sinh_ca                    0x1000da0  /* U+0DA0 SINHALA LETTER ALPAPRAANA CAYANNA */
#define XK_Sinh_cha                   0x1000da1  /* U+0DA1 SINHALA LETTER MAHAAPRAANA CAYANNA */
#define XK_Sinh_ja                    0x1000da2  /* U+0DA2 SINHALA LETTER ALPAPRAANA JAYANNA */
#define XK_Sinh_jha                   0x1000da3  /* U+0DA3 SINHALA LETTER MAHAAPRAANA JAYANNA */
#define XK_Sinh_nya                   0x1000da4  /* U+0DA4 SINHALA LETTER TAALUJA NAASIKYAYA */
#define XK_Sinh_jnya                  0x1000da5  /* U+0DA5 SINHALA LETTER TAALUJA SANYOOGA NAAKSIKYAYA */
#define XK_Sinh_nja                   0x1000da6  /* U+0DA6 SINHALA LETTER SANYAKA JAYANNA */
#define XK_Sinh_tta                   0x1000da7  /* U+0DA7 SINHALA LETTER ALPAPRAANA TTAYANNA */
#define XK_Sinh_ttha                  0x1000da8  /* U+0DA8 SINHALA LETTER MAHAAPRAANA TTAYANNA */
#define XK_Sinh_dda                   0x1000da9  /* U+0DA9 SINHALA LETTER ALPAPRAANA DDAYANNA */
#define XK_Sinh_ddha                  0x1000daa  /* U+0DAA SINHALA LETTER MAHAAPRAANA DDAYANNA */
#define XK_Sinh_nna                   0x1000dab  /* U+0DAB SINHALA LETTER MUURDHAJA NAYANNA */
#define XK_Sinh_ndda                  0x1000dac  /* U+0DAC SINHALA LETTER SANYAKA DDAYANNA */
#define XK_Sinh_tha                   0x1000dad  /* U+0DAD SINHALA LETTER ALPAPRAANA TAYANNA */
#define XK_Sinh_thha                  0x1000dae  /* U+0DAE SINHALA LETTER MAHAAPRAANA TAYANNA */
#define XK_Sinh_dha                   0x1000daf  /* U+0DAF SINHALA LETTER ALPAPRAANA DAYANNA */
#define XK_Sinh_dhha                  0x1000db0  /* U+0DB0 SINHALA LETTER MAHAAPRAANA DAYANNA */
#define XK_Sinh_na                    0x1000db1  /* U+0DB1 SINHALA LETTER DANTAJA NAYANNA */
#define XK_Sinh_ndha                  0x1000db3  /* U+0DB3 SINHALA LETTER SANYAKA DAYANNA */
#define XK_Sinh_pa                    0x1000db4  /* U+0DB4 SINHALA LETTER ALPAPRAANA PAYANNA */
#define XK_Sinh_pha                   0x1000db5  /* U+0DB5 SINHALA LETTER MAHAAPRAANA PAYANNA */
#define XK_Sinh_ba                    0x1000db6  /* U+0DB6 SINHALA LETTER ALPAPRAANA BAYANNA */
#define XK_Sinh_bha                   0x1000db7  /* U+0DB7 SINHALA LETTER MAHAAPRAANA BAYANNA */
#define XK_Sinh_ma                    0x1000db8  /* U+0DB8 SINHALA LETTER MAYANNA */
#define XK_Sinh_mba                   0x1000db9  /* U+0DB9 SINHALA LETTER AMBA BAYANNA */
#define XK_Sinh_ya                    0x1000dba  /* U+0DBA SINHALA LETTER YAYANNA */
#define XK_Sinh_ra                    0x1000dbb  /* U+0DBB SINHALA LETTER RAYANNA */
#define XK_Sinh_la                    0x1000dbd  /* U+0DBD SINHALA LETTER DANTAJA LAYANNA */
#define XK_Sinh_va                    0x1000dc0  /* U+0DC0 SINHALA LETTER VAYANNA */
#define XK_Sinh_sha                   0x1000dc1  /* U+0DC1 SINHALA LETTER TAALUJA SAYANNA */
#define XK_Sinh_ssha                  0x1000dc2  /* U+0DC2 SINHALA LETTER MUURDHAJA SAYANNA */
#define XK_Sinh_sa                    0x1000dc3  /* U+0DC3 SINHALA LETTER DANTAJA SAYANNA */
#define XK_Sinh_ha                    0x1000dc4  /* U+0DC4 SINHALA LETTER HAYANNA */
#define XK_Sinh_lla                   0x1000dc5  /* U+0DC5 SINHALA LETTER MUURDHAJA LAYANNA */
#define XK_Sinh_fa                    0x1000dc6  /* U+0DC6 SINHALA LETTER FAYANNA */
#define XK_Sinh_al                    0x1000dca  /* U+0DCA SINHALA SIGN AL-LAKUNA */
#define XK_Sinh_aa2                   0x1000dcf  /* U+0DCF SINHALA VOWEL SIGN AELA-PILLA */
#define XK_Sinh_ae2                   0x1000dd0  /* U+0DD0 SINHALA VOWEL SIGN KETTI AEDA-PILLA */
#define XK_Sinh_aee2                  0x1000dd1  /* U+0DD1 SINHALA VOWEL SIGN DIGA AEDA-PILLA */
#define XK_Sinh_i2                    0x1000dd2  /* U+0DD2 SINHALA VOWEL SIGN KETTI IS-PILLA */
#define XK_Sinh_ii2                   0x1000dd3  /* U+0DD3 SINHALA VOWEL SIGN DIGA IS-PILLA */
#define XK_Sinh_u2                    0x1000dd4  /* U+0DD4 SINHALA VOWEL SIGN KETTI PAA-PILLA */
#define XK_Sinh_uu2                   0x1000dd6  /* U+0DD6 SINHALA VOWEL SIGN DIGA PAA-PILLA */
#define XK_Sinh_ru2                   0x1000dd8  /* U+0DD8 SINHALA VOWEL SIGN GAETTA-PILLA */
#define XK_Sinh_e2                    0x1000dd9  /* U+0DD9 SINHALA VOWEL SIGN KOMBUVA */
#define XK_Sinh_ee2                   0x1000dda  /* U+0DDA SINHALA VOWEL SIGN DIGA KOMBUVA */
#define XK_Sinh_ai2                   0x1000ddb  /* U+0DDB SINHALA VOWEL SIGN KOMBU DEKA */
#define XK_Sinh_o2                    0x1000ddc  /* U+0DDC SINHALA VOWEL SIGN KOMBUVA HAA AELA-PILLA */
#define XK_Sinh_oo2                   0x1000ddd  /* U+0DDD SINHALA VOWEL SIGN KOMBUVA HAA DIGA AELA-PILLA */
#define XK_Sinh_au2                   0x1000dde  /* U+0DDE SINHALA VOWEL SIGN KOMBUVA HAA GAYANUKITTA */
#define XK_Sinh_lu2                   0x1000ddf  /* U+0DDF SINHALA VOWEL SIGN GAYANUKITTA */
#define XK_Sinh_ruu2                  0x1000df2  /* U+0DF2 SINHALA VOWEL SIGN DIGA GAETTA-PILLA */
#define XK_Sinh_luu2                  0x1000df3  /* U+0DF3 SINHALA VOWEL SIGN DIGA GAYANUKITTA */
#define XK_Sinh_kunddaliya            0x1000df4  /* U+0DF4 SINHALA PUNCTUATION KUNDDALIYA */
#endif /* XK_SINHALA */

Changes to xlib/xcolors.c.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15






-
-
+
+







/*
 * xcolors.c --
 *
 *	This file contains the routines used to map from X color names to RGB
 *	and pixel values.
 *
 * Copyright (c) 1996 Sun Microsystems, Inc.
 * Copyright (c) 2012 Jan Nijtmans
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 * Copyright (c) 2012 by Jan Nijtmans
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

40
41
42
43
44
45
46
47

48
49

50
51
52
53

54
55
56


57
58

59
60
61
62
63
64
65
66

67
68

69
70
71
72


73
74
75
76
77
78





79
80
81
82
83


84
85

86
87
88
89



90
91
92
93


94
95
96

97
98
99
100
101



102
103
104


105
106
107
108
109

110
111

112
113
114

115
116
117
118
119
120

121
122
123

124
125
126
127

128
129

130
131
132

133
134
135
136
137
138




139
140
141

142
143
144
145



146
147
148
149
150



151
152
153
154
155


156
157
158
159
160
161
162
163
164







165
166

167
168
169
170


171
172
173


174
175
176
177
178
179

180
181
182
183

184
185

186
187
188

189
190
191

192
193
194
195
196
197

198
199

200
201
202
203

204
205
206
207

208
209
210
211
212
213

214
215
216
217
218

219
220

221
222
223
224
225


226
227

228
229
230
231
232
233
234
40
41
42
43
44
45
46

47
48

49
50
51
52

53
54


55
56
57

58
59
60
61
62
63
64
65

66
67

68
69
70


71
72
73





74
75
76
77
78
79
80
81


82
83
84

85
86



87
88
89
90
91


92
93
94
95

96
97
98



99
100
101
102


103
104
105
106
107
108

109
110

111
112
113

114
115
116
117
118
119

120
121
122

123
124
125
126

127
128

129
130
131

132
133
134




135
136
137
138
139
140

141
142



143
144
145
146
147



148
149
150
151
152
153


154
155
156
157







158
159
160
161
162
163
164
165

166
167
168


169
170
171


172
173
174
175
176
177
178

179
180
181
182

183
184

185
186
187

188
189
190

191
192
193
194
195
196

197
198

199
200
201
202

203
204
205
206

207
208
209
210
211
212

213
214
215
216
217

218
219

220
221
222
223


224
225
226

227
228
229
230
231
232
233
234







-
+

-
+



-
+

-
-
+
+

-
+







-
+

-
+


-
-
+
+

-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+

-
-
-
+
+
+


-
-
+
+


-
+


-
-
-
+
+
+

-
-
+
+




-
+

-
+


-
+





-
+


-
+



-
+

-
+


-
+


-
-
-
-
+
+
+
+


-
+

-
-
-
+
+
+


-
-
-
+
+
+



-
-
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+


-
-
+
+

-
-
+
+





-
+



-
+

-
+


-
+


-
+





-
+

-
+



-
+



-
+





-
+




-
+

-
+



-
-
+
+

-
+







 * are handled by this table, above that is handled especially.
 */

typedef char elem[32];

static const elem xColors[] = {
    /* Colors starting with 'a' */
    "liceBlue\0                   \360\370\377\0",
    "liceBlue\0                   \360\370\377",
    "ntiqueWhite\0    \213\203\170\315\300\260\356\337\314\377\357\333\372\353\327\4",
    "qua\0                        \000\377\377\0",
    "qua\0                        \000\377\377",
    "quamarine\0      \105\213\164\146\315\252\166\356\306\177\377\324\177\377\324\4",
    "zure\0           \203\213\213\301\315\315\340\356\356\360\377\377\360\377\377\4",
    /* Colors starting with 'b' */
    "eige\0                       \365\365\334\0",
    "eige\0                       \365\365\334",
    "isque\0          \213\175\153\315\267\236\356\325\267\377\344\304\377\344\304\4",
    "lack\0                       \000\000\000\0",
    "lanchedAlmond\0              \377\353\315\0",
    "lack\0                       \000\000\000",
    "lanchedAlmond\0              \377\353\315",
    "lue\0            \000\000\213\000\000\315\000\000\356\000\000\377\000\000\377\4",
    "lueViolet\0                  \212\053\342\0",
    "lueViolet\0                  \212\053\342",
    "rown\0           \213\043\043\315\063\063\356\073\073\377\100\100\245\052\052\4",
    "urlywood\0       \213\163\125\315\252\175\356\305\221\377\323\233\336\270\207\4",
    /* Colors starting with 'c' */
    "adetBlue\0       \123\206\213\172\305\315\216\345\356\230\365\377\137\236\240\4",
    "hartreuse\0      \105\213\000\146\315\000\166\356\000\177\377\000\177\377\000\4",
    "hocolate\0       \213\105\023\315\146\035\356\166\041\377\177\044\322\151\036\4",
    "oral\0           \213\076\057\315\133\105\356\152\120\377\162\126\377\177\120\4",
    "ornflowerBlue\0              \144\225\355\0",
    "ornflowerBlue\0              \144\225\355",
    "ornsilk\0        \213\210\170\315\310\261\356\350\315\377\370\334\377\370\334\4",
    "rimson\0                     \334\024\074\0",
    "rimson\0                     \334\024\074",
    "yan\0            \000\213\213\000\315\315\000\356\356\000\377\377\000\377\377\4",
    /* Colors starting with 'd' */
    "arkBlue\0                    \000\000\213\0",
    "arkCyan\0                    \000\213\213\0",
    "arkBlue\0                    \000\000\213",
    "arkCyan\0                    \000\213\213",
    "arkGoldenrod\0   \213\145\010\315\225\014\356\255\016\377\271\017\270\206\013\4",
    "arkGray\0                    \251\251\251\0",
    "arkGreen\0                   \000\144\000\0",
    "arkGrey\0                    \251\251\251\0",
    "arkKhaki\0                   \275\267\153\0",
    "arkMagenta\0                 \213\000\213\0",
    "arkGray\0                    \251\251\251",
    "arkGreen\0                   \000\144\000",
    "arkGrey\0                    \251\251\251",
    "arkKhaki\0                   \275\267\153",
    "arkMagenta\0                 \213\000\213",
    "arkOliveGreen\0  \156\213\075\242\315\132\274\356\150\312\377\160\125\153\057\4",
    "arkOrange\0      \213\105\000\315\146\000\356\166\000\377\177\000\377\214\000\4",
    "arkOrchid\0      \150\042\213\232\062\315\262\072\356\277\076\377\231\062\314\4",
    "arkRed\0                     \213\000\000\0",
    "arkSalmon\0                  \351\226\172\0",
    "arkRed\0                     \213\000\000",
    "arkSalmon\0                  \351\226\172",
    "arkSeaGreen\0    \151\213\151\233\315\233\264\356\264\301\377\301\217\274\217\4",
    "arkSlateBlue\0               \110\075\213\0",
    "arkSlateBlue\0               \110\075\213",
    "arkSlateGray\0   \122\213\213\171\315\315\215\356\356\227\377\377\057\117\117\4",
    "arkSlateGrey\0               \057\117\117\0",
    "arkTurquoise\0               \000\316\321\0",
    "arkViolet\0                  \224\000\323\0",
    "arkSlateGrey\0               \057\117\117",
    "arkTurquoise\0               \000\316\321",
    "arkViolet\0                  \224\000\323",
    "eepPink\0        \213\012\120\315\020\166\356\022\211\377\024\223\377\024\223\4",
    "eepSkyBlue\0     \000\150\213\000\232\315\000\262\356\000\277\377\000\277\377\4",
    "imGray\0                     \151\151\151\0",
    "imGrey\0                     \151\151\151\0",
    "imGray\0                     \151\151\151",
    "imGrey\0                     \151\151\151",
    "odgerBlue\0      \020\116\213\030\164\315\034\206\356\036\220\377\036\220\377\4",
    /* Colors starting with 'e' */
    "\377                              \0" /* placeholder */,
    "\377" /* placeholder */,
    /* Colors starting with 'f' */
    "irebrick\0       \213\032\032\315\046\046\356\054\054\377\060\060\262\042\042\4",
    "loralWhite\0                 \377\372\360\0",
    "orestGreen\0                 \042\213\042\0",
    "uchsia\0                     \377\000\377\0",
    "loralWhite\0                 \377\372\360",
    "orestGreen\0                 \042\213\042",
    "uchsia\0                     \377\000\377",
    /* Colors starting with 'g' */
    "ainsboro\0                   \334\334\334\0",
    "hostWhite\0                  \370\370\377\0",
    "ainsboro\0                   \334\334\334",
    "hostWhite\0                  \370\370\377",
    "old\0            \213\165\000\315\255\000\356\311\000\377\327\000\377\327\000\4",
    "oldenrod\0       \213\151\024\315\233\035\356\264\042\377\301\045\332\245\040\4",
    "ray\0\024\024\024\022\022\022\017\017\017\015\015\015\012\012\012"
	    "\010\010\010\005\005\005\003\003\003\200\200\200\10",
    "ray0\0                       \000\000\000\0",
    "ray0\0                       \000\000\000",
    "reen\0           \000\213\000\000\315\000\000\356\000\000\377\000\000\200\000\4",
    "reenYellow\0                 \255\377\057\0",
    "reenYellow\0                 \255\377\057",
    "rey\0\024\024\024\022\022\022\017\017\017\015\015\015\012\012\012"
	    "\010\010\010\005\005\005\003\003\003\200\200\200\10",
    "rey0\0                       \000\000\000\0",
    "rey0\0                       \000\000\000",
    /* Colors starting with 'h' */
    "oneydew\0        \203\213\203\301\315\301\340\356\340\360\377\360\360\377\360\4",
    "otPink\0         \213\072\142\315\140\220\356\152\247\377\156\264\377\151\264\4",
    /* Colors starting with 'i' */
    "ndianRed\0       \213\072\072\315\125\125\356\143\143\377\152\152\315\134\134\4",
    "ndigo\0                      \113\000\202\0",
    "ndigo\0                      \113\000\202",
    "vory\0           \213\213\203\315\315\301\356\356\340\377\377\360\377\377\360\4",
    /* Colors starting with 'j' */
    "\377                              \0" /* placeholder */,
    "\377" /* placeholder */,
    /* Colors starting with 'k' */
    "haki\0           \213\206\116\315\306\163\356\346\205\377\366\217\360\346\214\4",
    /* Colors starting with 'l' */
    "avender\0                    \346\346\372\0",
    "avender\0                    \346\346\372",
    "avenderBlush\0   \213\203\206\315\301\305\356\340\345\377\360\365\377\360\365\4",
    "awnGreen\0                   \174\374\000\0",
    "awnGreen\0                   \174\374\000",
    "emonChiffon\0    \213\211\160\315\311\245\356\351\277\377\372\315\377\372\315\4",
    "ightBlue\0       \150\203\213\232\300\315\262\337\356\277\357\377\255\330\346\4",
    "ightCoral\0                  \360\200\200\0",
    "ightCoral\0                  \360\200\200",
    "ightCyan\0       \172\213\213\264\315\315\321\356\356\340\377\377\340\377\377\4",
    "ightGoldenrod\0  \213\201\114\315\276\160\356\334\202\377\354\213\356\335\202\4",
    "ightGoldenrodYellow\0        \372\372\322\0",
    "ightGray\0                   \323\323\323\0",
    "ightGreen\0                  \220\356\220\0",
    "ightGrey\0                   \323\323\323\0",
    "ightGoldenrodYellow\0        \372\372\322",
    "ightGray\0                   \323\323\323",
    "ightGreen\0                  \220\356\220",
    "ightGrey\0                   \323\323\323",
    "ightPink\0       \213\137\145\315\214\225\356\242\255\377\256\271\377\266\301\4",
    "ightSalmon\0     \213\127\102\315\201\142\356\225\162\377\240\172\377\240\172\4",
    "ightSeaGreen\0               \040\262\252\0",
    "ightSeaGreen\0               \040\262\252",
    "ightSkyBlue\0    \140\173\213\215\266\315\244\323\356\260\342\377\207\316\372\4",
    "ightSlateBlue\0              \204\160\377\0",
    "ightSlateGray\0              \167\210\231\0",
    "ightSlateGrey\0              \167\210\231\0",
    "ightSlateBlue\0              \204\160\377",
    "ightSlateGray\0              \167\210\231",
    "ightSlateGrey\0              \167\210\231",
    "ightSteelBlue\0  \156\173\213\242\265\315\274\322\356\312\341\377\260\304\336\4",
    "ightYellow\0     \213\213\172\315\315\264\356\356\321\377\377\340\377\377\340\4",
    "ime\0                        \000\377\000\0",
    "imeGreen\0                   \062\315\062\0",
    "inen\0                       \372\360\346\0",
    "ime\0                        \000\377\000",
    "imeGreen\0                   \062\315\062",
    "inen\0                       \372\360\346",
    /* Colors starting with 'm' */
    "agenta\0         \213\000\213\315\000\315\356\000\356\377\000\377\377\000\377\4",
    "aroon\0          \213\034\142\315\051\220\356\060\247\377\064\263\200\000\000\4",
    "ediumAquamarine\0            \146\315\252\0",
    "ediumBlue\0                  \000\000\315\0",
    "ediumAquamarine\0            \146\315\252",
    "ediumBlue\0                  \000\000\315",
    "ediumOrchid\0    \172\067\213\264\122\315\321\137\356\340\146\377\272\125\323\4",
    "ediumPurple\0    \135\107\213\211\150\315\237\171\356\253\202\377\223\160\333\4",
    "ediumSeaGreen\0              \074\263\161\0",
    "ediumSlateBlue\0             \173\150\356\0",
    "ediumSpringGreen\0           \000\372\232\0",
    "ediumTurquoise\0             \110\321\314\0",
    "ediumVioletRed\0             \307\025\205\0",
    "idnightBlue\0                \031\031\160\0",
    "intCream\0                   \365\377\372\0",
    "ediumSeaGreen\0              \074\263\161",
    "ediumSlateBlue\0             \173\150\356",
    "ediumSpringGreen\0           \000\372\232",
    "ediumTurquoise\0             \110\321\314",
    "ediumVioletRed\0             \307\025\205",
    "idnightBlue\0                \031\031\160",
    "intCream\0                   \365\377\372",
    "istyRose\0       \213\175\173\315\267\265\356\325\322\377\344\341\377\344\341\4",
    "occasin\0                    \377\344\265\0",
    "occasin\0                    \377\344\265",
    /* Colors starting with 'n' */
    "avajoWhite\0     \213\171\136\315\263\213\356\317\241\377\336\255\377\336\255\4",
    "avy\0                        \000\000\200\0",
    "avyBlue\0                    \000\000\200\0",
    "avy\0                        \000\000\200",
    "avyBlue\0                    \000\000\200",
    /* Colors starting with 'o' */
    "ldLace\0                     \375\365\346\0",
    "live\0                       \200\200\000\0",
    "ldLace\0                     \375\365\346",
    "live\0                       \200\200\000",
    "liveDrab\0       \151\213\042\232\315\062\263\356\072\300\377\076\153\216\043\4",
    "range\0          \213\132\000\315\205\000\356\232\000\377\245\000\377\245\000\4",
    "rangeRed\0       \213\045\000\315\067\000\356\100\000\377\105\000\377\105\000\4",
    "rchid\0          \213\107\211\315\151\311\356\172\351\377\203\372\332\160\326\4",
    /* Colors starting with 'p' */
    "aleGoldenrod\0               \356\350\252\0",
    "aleGoldenrod\0               \356\350\252",
    "aleGreen\0       \124\213\124\174\315\174\220\356\220\232\377\232\230\373\230\4",
    "aleTurquoise\0   \146\213\213\226\315\315\256\356\356\273\377\377\257\356\356\4",
    "aleVioletRed\0   \213\107\135\315\150\211\356\171\237\377\202\253\333\160\223\4",
    "apayaWhip\0                  \377\357\325\0",
    "apayaWhip\0                  \377\357\325",
    "eachPuff\0       \213\167\145\315\257\225\356\313\255\377\332\271\377\332\271\4",
    "eru\0                        \315\205\077\0",
    "eru\0                        \315\205\077",
    "ink\0            \213\143\154\315\221\236\356\251\270\377\265\305\377\300\313\4",
    "lum\0            \213\146\213\315\226\315\356\256\356\377\273\377\335\240\335\4",
    "owderBlue\0                  \260\340\346\0",
    "owderBlue\0                  \260\340\346",
    "urple\0          \125\032\213\175\046\315\221\054\356\233\060\377\200\000\200\4",
    /* Colors starting with 'q' */
    "\377                              \0" /* placeholder */,
    "\377" /* placeholder */,
    /* Colors starting with 'r' */
    "ed\0             \213\000\000\315\000\000\356\000\000\377\000\000\377\000\000\4",
    "osyBrown\0       \213\151\151\315\233\233\356\264\264\377\301\301\274\217\217\4",
    "oyalBlue\0       \047\100\213\072\137\315\103\156\356\110\166\377\101\151\341\4",
    /* Colors starting with 's' */
    "addleBrown\0                 \213\105\023\0",
    "addleBrown\0                 \213\105\023",
    "almon\0          \213\114\071\315\160\124\356\202\142\377\214\151\372\200\162\4",
    "andyBrown\0                  \364\244\140\0",
    "andyBrown\0                  \364\244\140",
    "eaGreen\0        \056\213\127\103\315\200\116\356\224\124\377\237\056\213\127\4",
    "eashell\0        \213\206\202\315\305\277\356\345\336\377\365\356\377\365\356\4",
    "ienna\0          \213\107\046\315\150\071\356\171\102\377\202\107\240\122\055\4",
    "ilver\0                      \300\300\300\0",
    "ilver\0                      \300\300\300",
    "kyBlue\0         \112\160\213\154\246\315\176\300\356\207\316\377\207\316\353\4",
    "lateBlue\0       \107\074\213\151\131\315\172\147\356\203\157\377\152\132\315\4",
    "lateGray\0       \154\173\213\237\266\315\271\323\356\306\342\377\160\200\220\4",
    "lateGrey\0                   \160\200\220\0",
    "lateGrey\0                   \160\200\220",
    "now\0            \213\211\211\315\311\311\356\351\351\377\372\372\377\372\372\4",
    "pringGreen\0     \000\213\105\000\315\146\000\356\166\000\377\177\000\377\177\4",
    "teelBlue\0       \066\144\213\117\224\315\134\254\356\143\270\377\106\202\264\4",
    /* Colors starting with 't' */
    "an\0             \213\132\053\315\205\077\356\232\111\377\245\117\322\264\214\4",
    "eal\0                        \000\200\200\0",
    "eal\0                        \000\200\200",
    "histle\0         \213\173\213\315\265\315\356\322\356\377\341\377\330\277\330\4",
    "omato\0          \213\066\046\315\117\071\356\134\102\377\143\107\377\143\107\4",
    "urquoise\0       \000\206\213\000\305\315\000\345\356\000\365\377\100\340\320\4",
    /* Colors starting with 'u' */
    "\377                              \0" /* placeholder */,
    "\377" /* placeholder */,
    /* Colors starting with 'v' */
    "iolet\0                      \356\202\356\0",
    "iolet\0                      \356\202\356",
    "ioletRed\0       \213\042\122\315\062\170\356\072\214\377\076\226\320\040\220\4",
    /* Colors starting with 'w' */
    "heat\0           \213\176\146\315\272\226\356\330\256\377\347\272\365\336\263\4",
    "hite\0                       \377\377\377\0",
    "hiteSmoke\0                  \365\365\365\0",
    "hite\0                       \377\377\377",
    "hiteSmoke\0                  \365\365\365",
    /* Colors starting with 'x' */
    "\377                              \0" /* placeholder */,
    "\377" /* placeholder */,
    /* Colors starting with 'y' */
    "ellow\0          \213\213\000\315\315\000\356\356\000\377\377\000\377\377\000\4",
    "ellowGreen\0                 \232\315\062\0"
};

/*
 *----------------------------------------------------------------------
332
333
334
335
336
337
338
339
340


341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
332
333
334
335
336
337
338


339
340
341
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
357







-
-
+
+









-
+







#define RED(p)		((unsigned char) (p)[0])
#define GREEN(p)	((unsigned char) (p)[1])
#define BLUE(p)		((unsigned char) (p)[2])
#define US(expr)	((unsigned short) (expr))

Status
XParseColor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Colormap),
    Display *display,
    Colormap map,
    const char *spec,
    XColor *colorPtr)
{
    if (spec[0] == '#') {
	char *p;
	Tcl_WideInt value = parseHex64bit(++spec, &p);

	/*
	 * If *p does not point to the end of the string, there were invalid
	 * digits in the spec. Ergo, it is not a valid color string.
	 * digits in the spec. Ergo, it is not a vailid color string.
	 * (Bug f0188aca9e)
	 */

	if (*p != '\0') {
	    return 0;
	}

Changes to xlib/xgc.c.

9
10
11
12
13
14
15


16
17












18
19
20

21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


48

49
50


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75


76
77
78
79
80
81
82







83
84
85
86
87
88
89
9
10
11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26
27
28
29
30
31

32






33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


53
54
55
56
57

58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80


81
82







83
84
85
86
87
88
89
90
91
92
93
94
95
96







+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
+
-
-
-
-
-
-
+



















-
-
+
+

+

-
+
+

-
-




















-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+







 * Copyright 2008-2009, Apple Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

#if !defined(MAC_OSX_TK)
#include <X11/Xlib.h>
#if defined(MAC_OSX_TK)
#   include <X11/Xlib.h>
#   define gcCacheSize 0
#   define TkpInitGCCache(gc)
#   define TkpFreeGCCache(gc)
#   define TkpGetGCCache(gc)
#else
#   include <tkMacOSXInt.h>
#   include <X11/Xlib.h>
#   include <X11/X.h>
#   define Cursor XCursor
#   define Region XRegion
#   define gcCacheSize sizeof(TkpGCCache)
#endif


#undef TkSetRegion
#define MAX_DASH_LIST_SIZE 10
typedef struct {
    XGCValues gc;
    char dash[MAX_DASH_LIST_SIZE];
} XGCValuesWithDash;


/*
 *----------------------------------------------------------------------
 *
 * AllocClipMask --
 *
 *	Static helper proc to allocate new or clear existing TkpClipMask.
 *
 * Results:
 *	Returns ptr to the new/cleared TkpClipMask.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static TkpClipMask *AllocClipMask(GC gc) {
    TkpClipMask *clip_mask = (TkpClipMask*) gc->clip_mask;

    if (clip_mask == NULL) {
	clip_mask = (TkpClipMask *)ckalloc(sizeof(TkpClipMask));
    if (clip_mask == None) {
	clip_mask = ckalloc(sizeof(TkpClipMask));
	gc->clip_mask = (Pixmap) clip_mask;
#ifdef MAC_OSX_TK
    } else if (clip_mask->type == TKP_CLIP_REGION) {
	TkDestroyRegion(clip_mask->value.region);
	TkpReleaseRegion(clip_mask->value.region);
#endif
    }
    clip_mask->type = TKP_CLIP_PIXMAP;
    clip_mask->value.pixmap = None;
    return clip_mask;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeClipMask --
 *
 *	Static helper proc to free TkpClipMask.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void FreeClipMask(GC gc) {
    TkpClipMask * clip_mask = (TkpClipMask*)gc->clip_mask;
    if (clip_mask == NULL) {
    if (gc->clip_mask != None) {
#ifdef MAC_OSX_TK
	return;
    }
    if (clip_mask->type == TKP_CLIP_REGION) {
	TkDestroyRegion(clip_mask->value.region);
    }
    ckfree(clip_mask);
    gc->clip_mask = None;
	if (((TkpClipMask*) gc->clip_mask)->type == TKP_CLIP_REGION) {
	    TkpReleaseRegion(((TkpClipMask*) gc->clip_mask)->value.region);
	}
#endif
	ckfree(gc->clip_mask);
	gc->clip_mask = None;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * XCreateGC --
 *
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113

114
115
116


117




118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

134
135
136


137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154


155
156






















157
158
159
160
161
162
163
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119

120
121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146


147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199







-
+








-
+



+
+
-
+
+
+
+















-
+

-
-
+
+


-
+















+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *
 *----------------------------------------------------------------------
 */

GC
XCreateGC(
    Display *display,
    TCL_UNUSED(Drawable),
    Drawable d,
    unsigned long mask,
    XGCValues *values)
{
    GC gp;

    /*
     * In order to have room for a dash list, MAX_DASH_LIST_SIZE extra chars
     * are defined, which is invisible from the outside. The list is assumed
     * to end with a 0-char, so this must be set explicitly during
     * to end with a 0-char, so this must be set explicitely during
     * initialization.
     */

#define MAX_DASH_LIST_SIZE 10

    gp = (GC)ckalloc(sizeof(XGCValuesWithDash));
    gp = ckalloc(sizeof(XGCValues) + MAX_DASH_LIST_SIZE + gcCacheSize);
    if (!gp) {
	return None;
    }

#define InitField(name,maskbit,default) \
	(gp->name = (mask & (maskbit)) ? values->name : (default))

    InitField(function,		  GCFunction,		GXcopy);
    InitField(plane_mask,	  GCPlaneMask,		(unsigned long)(~0));
    InitField(foreground,	  GCForeground,
	    BlackPixelOfScreen(DefaultScreenOfDisplay(display)));
    InitField(background,	  GCBackground,
	    WhitePixelOfScreen(DefaultScreenOfDisplay(display)));
    InitField(line_width,	  GCLineWidth,		1);
    InitField(line_style,	  GCLineStyle,		LineSolid);
    InitField(cap_style,	  GCCapStyle,		0);
    InitField(join_style,	  GCJoinStyle,		0);
    InitField(fill_style,	  GCFillStyle,		FillSolid);
    InitField(fill_rule,	  GCFillRule,		EvenOddRule);
    InitField(fill_rule,	  GCFillRule,		WindingRule);
    InitField(arc_mode,		  GCArcMode,		ArcPieSlice);
    InitField(tile,		  GCTile,		0);
    InitField(stipple,		  GCStipple,		0);
    InitField(tile,		  GCTile,		None);
    InitField(stipple,		  GCStipple,		None);
    InitField(ts_x_origin,	  GCTileStipXOrigin,	0);
    InitField(ts_y_origin,	  GCTileStipYOrigin,	0);
    InitField(font,		  GCFont,		0);
    InitField(font,		  GCFont,		None);
    InitField(subwindow_mode,	  GCSubwindowMode,	ClipByChildren);
    InitField(graphics_exposures, GCGraphicsExposures,	True);
    InitField(clip_x_origin,	  GCClipXOrigin,	0);
    InitField(clip_y_origin,	  GCClipYOrigin,	0);
    InitField(dash_offset,	  GCDashOffset,		0);
    InitField(dashes,		  GCDashList,		4);
    (&(gp->dashes))[1] = 0;

    gp->clip_mask = None;
    if (mask & GCClipMask) {
	TkpClipMask *clip_mask = AllocClipMask(gp);

	clip_mask->type = TKP_CLIP_PIXMAP;
	clip_mask->value.pixmap = values->clip_mask;
    }
    TkpInitGCCache(gp);

    return gp;
}

#ifdef MAC_OSX_TK
/*
 *----------------------------------------------------------------------
 *
 * TkpGetGCCache --
 *
 * Results:
 *	Pointer to the TkpGCCache at the end of the GC.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

TkpGCCache*
TkpGetGCCache(GC gc) {
    return (gc ? (TkpGCCache*)(((char*) gc) + sizeof(XGCValues) +
	    MAX_DASH_LIST_SIZE) : NULL);
}
#endif

/*
 *----------------------------------------------------------------------
 *
 * XChangeGC --
 *
 *	Changes the GC components specified by valuemask for the specified GC.
225
226
227
228
229
230
231
232

233
234
235

236

237
238
239
240
241
242
243
261
262
263
264
265
266
267

268
269
270

271
272
273
274
275
276
277
278
279
280







-
+


-
+

+







 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int XFreeGC(
    TCL_UNUSED(Display *),
    Display *d,
    GC gc)
{
    if (gc != NULL) {
    if (gc != None) {
	FreeClipMask(gc);
	TkpFreeGCCache(gc);
	ckfree(gc);
    }
    return Success;
}

/*
 *----------------------------------------------------------------------
254
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281

282
283
284
285
286
287
288
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325







-
+









-
+









-
+







 *	Each function sets some slot in the GC.
 *
 *----------------------------------------------------------------------
 */

int
XSetForeground(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    unsigned long foreground)
{
    gc->foreground = foreground;
    return Success;
}

int
XSetBackground(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    unsigned long background)
{
    gc->background = background;
    return Success;
}

int
XSetDashes(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int dash_offset,
    _Xconst char *dash_list,
    int n)
{
    char *p = &(gc->dashes);

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336

337
338
339
340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
355
356
357

358
359
360
361
362
363
364
365
366
367

368
369
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411




412
413
414
415
416
417

418
419
420
421
422

423
424

425
426
427
428
429


430
431
432
433
434
435
436



437
438
439
440
441
442
443

444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
336
337
338
339
340
341
342

343
344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442

443
444
445
446


447
448
449
450
451
452
453
454
455

456
457
458
459
460

461
462

463
464
465
466


467
468
469
470
471
472
473


474
475
476
477

478
479
480
481

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496


























497
498
499
500
501
502
503







-
+









-
+









-
+









-
+










-
+









-
+









-
+









-
+















-
+












-
+



-
-
+
+
+
+





-
+




-
+

-
+



-
-
+
+





-
-
+
+
+

-




-
+














-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    }
    *p = 0;
    return Success;
}

int
XSetFunction(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int function)
{
    gc->function = function;
    return Success;
}

int
XSetFillRule(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int fill_rule)
{
    gc->fill_rule = fill_rule;
    return Success;
}

int
XSetFillStyle(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int fill_style)
{
    gc->fill_style = fill_style;
    return Success;
}

int
XSetTSOrigin(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int x, int y)
{
    gc->ts_x_origin = x;
    gc->ts_y_origin = y;
    return Success;
}

int
XSetFont(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    Font font)
{
    gc->font = font;
    return Success;
}

int
XSetArcMode(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int arc_mode)
{
    gc->arc_mode = arc_mode;
    return Success;
}

int
XSetStipple(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    Pixmap stipple)
{
    gc->stipple = stipple;
    return Success;
}

int
XSetLineAttributes(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    unsigned int line_width,
    int line_style,
    int cap_style,
    int join_style)
{
    gc->line_width = line_width;
    gc->line_style = line_style;
    gc->cap_style = cap_style;
    gc->join_style = join_style;
    return Success;
}

int
XSetClipOrigin(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    int clip_x_origin,
    int clip_y_origin)
{
    gc->clip_x_origin = clip_x_origin;
    gc->clip_y_origin = clip_y_origin;
    return Success;
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetRegion, XSetClipMask, XSetClipRectangles --
 * TkSetRegion, XSetClipMask --
 *
 *	Sets the clipping region/pixmap for a GC.
 *
 *	Like the Xlib equivalent, it is safe to delete the
 *	region after setting it into the GC.
 *	Note that unlike the Xlib equivalent, it is not safe to delete the
 *	region after setting it into the GC (except on Mac OS X). The only
 *	uses of TkSetRegion are currently in DisplayFrame and in
 *	ImgPhotoDisplay, which use the GC immediately.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates or deallocates a TkpClipMask.
 *	Allocates or dealloates a TkpClipMask.
 *
 *----------------------------------------------------------------------
 */

int
void
TkSetRegion(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    TkRegion r)
{
    if (r == NULL) {
	Tcl_Panic("must not pass NULL to TkSetRegion for compatibility with X11; use XSetClipMask instead");
    if (r == None) {
	Tcl_Panic("must not pass None to TkSetRegion for compatibility with X11; use XSetClipMask instead");
    } else {
	TkpClipMask *clip_mask = AllocClipMask(gc);

	clip_mask->type = TKP_CLIP_REGION;
	clip_mask->value.region = r;
	clip_mask->value.region = TkCreateRegion();
	TkpCopyRegion(clip_mask->value.region, r);
#ifdef MAC_OSX_TK
	TkpRetainRegion(r);
#endif
    }
    return Success;
}

int
XSetClipMask(
    TCL_UNUSED(Display *),
    Display *display,
    GC gc,
    Pixmap pixmap)
{
    if (pixmap == None) {
	FreeClipMask(gc);
    } else {
	TkpClipMask *clip_mask = AllocClipMask(gc);

	clip_mask->type = TKP_CLIP_PIXMAP;
	clip_mask->value.pixmap = pixmap;
    }
    return Success;
}

int
XSetClipRectangles(
    TCL_UNUSED(Display*),
    GC gc,
    int clip_x_origin,
    int clip_y_origin,
    XRectangle* rectangles,
    int n,
    TCL_UNUSED(int))
{
    TkRegion clipRgn = TkCreateRegion();
    TkpClipMask * clip_mask = AllocClipMask(gc);
    clip_mask->type = TKP_CLIP_REGION;
    clip_mask->value.region = clipRgn;

    while (n--) {
	XRectangle rect = *rectangles;

	rect.x += clip_x_origin;
	rect.y += clip_y_origin;
	TkUnionRectWithRegion(&rect, clipRgn, clipRgn);
	rectangles++;
    }
    return 1;
}

/*
 * Some additional dummy functions (hopefully implemented soon).
 */

#if 0
Cursor
XCreateFontCursor(
521
522
523
524
525
526
527
528

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548





549
550
551
552
553

554
555
556
557
558



559
560
561
562
563
564
565
566
567



568
569

570
571
572
573
574
575
576



577
578
579
580
581

582
583
584


585
586
587
588
589

590
591


592
593
594
595
596
597
598
599
600


601
602
603


604
605
606
607
608

609
610
611
612
613
614


615
616
617
618
619
620
621

622
623
624
625
626
627
628

629
630
631
632
633
634
635
636
637
638
639

640
641
642
643
644
645
646
647
648

649
650
651

652
653

654
655
656
657
658
659
660
661
662
663
664
665
666
667


668
669
670
671
672
673

674
675

676
677
678
679
680
681
682

683
684

685
686
687
688
689
690
691
692
693
694
695
696
697

698
699

700
701
702


703
704
705
706
707
708
709
710
711
712

713
714
715
716

717
718
719


720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739


740
741

742
743

744
745
746
747
748
749
750
751
752
753
754
755
756
757



758
759

760
761

762
763
764
765


766
767
768

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787

788
789


790
791
792
793

794
795
796

797
798
799
800
801
802
803

804
805
806
807
808
809
810
811
812
813
814
815
816
817
534
535
536
537
538
539
540

541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556





557
558
559
560
561
562
563
564
565
566
567
568
569



570
571
572
573
574
575
576
577
578



579
580
581
582

583
584
585
586
587



588
589
590
591
592
593
594

595
596


597
598
599

600
601

602


603
604









605
606



607
608





609






610
611







612







613



614

615





616



617





618



619


620














621
622






623


624







625


626





627

628





629


630



631
632










633




634



635
636


637

638
639











640


641
642


643


644




645









646
647
648


649


650




651
652



653










654
655







656


657
658




659



660





661

662






663
664
665
666
667
668
669
670







-
+















-
-
-
-
-
+
+
+
+
+





+


-
-
-
+
+
+






-
-
-
+
+
+

-
+




-
-
-
+
+
+




-
+

-
-
+
+

-


-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-

-

-
-
-
-
-
+
-
-
-

-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-

-

-
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-

-


-
-
-
-
-
-
-
-
-
-
-

-
-
+
+
-
-
+
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-

-
+
-
-
-
-
-
-








int
XDrawPoints(
    Display *display,
    Drawable d,
    GC gc,
    XPoint *points,
    int npoints,
    TCL_UNUSED(int))
    int mode)
{
    int res = Success;

    while (npoints-- > 0) {
	res = XDrawLine(display, d, gc,
		points[0].x, points[0].y, points[0].x, points[0].y);
	if (res != Success) break;
	++points;
    }
    return res;
}

#if !defined(MAC_OSX_TK)
int
XDrawSegments(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Drawable),
    TCL_UNUSED(GC),
    TCL_UNUSED(XSegment *),
    TCL_UNUSED(int))
    Display *display,
    Drawable d,
    GC gc,
    XSegment *segments,
    int nsegments)
{
    return BadDrawable;
}
#endif

#if 0
char *
XFetchBuffer(
    TCL_UNUSED(Display *),
    TCL_UNUSED(int *),
    TCL_UNUSED(int))
    Display *display,
    int *nbytes_return,
    int buffer)
{
    return (char *) 0;
}

Status
XFetchName(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(char **))
    Display *display,
    Window w,
    char **window_name_return)
{
    return Success;
    return (Status) 0;
}

Atom *
XListProperties(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(int *))
    Display* display,
    Window w,
    int *num_prop_return)
{
    return (Atom *) 0;
}

int
void
XMapRaised(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window))
    Display *display,
    Window w)
{
    return Success;
}

int
void
XQueryTextExtents(
    TCL_UNUSED(Display *),
XPutImage(
    Display *display,
    TCL_UNUSED(XID),
    TCL_UNUSED(_Xconst char *),
    TCL_UNUSED(int),
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    TCL_UNUSED(int *),
    TCL_UNUSED(XCharStruct *))
{
    return Success;
    Drawable d,
    GC gc,
}

int
    XImage *image,
    int src_x,
XReparentWindow(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window),
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    int src_y,
    TCL_UNUSED(int))
{
    return BadWindow;
}

int
    int dest_x,
    int dest_y,
XUndefineCursor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Window))
{
    return Success;
}

    unsigned int width,
XVaNestedList
XVaCreateNestedList(
    TCL_UNUSED(int), ...)
{
    return NULL;
}

    unsigned int height)
char *
XSetICValues(
    TCL_UNUSED(XIC), ...)
{
    return NULL;
}

char *
XGetICValues(
    TCL_UNUSED(XIC), ...)
{

    return NULL;
}

void
XSetICFocus(
    TCL_UNUSED(XIC))
{
}

XQueryTextExtents(
Window
XCreateWindow(
    TCL_UNUSED(Display *),
    Display *display,
    TCL_UNUSED(Window),
    TCL_UNUSED(int),
    XID font_ID,
    TCL_UNUSED(int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(int),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(Visual *),
    TCL_UNUSED(unsigned long),
    TCL_UNUSED(XSetWindowAttributes *))
{
	return 0;
}

int
    _Xconst char *string,
    int nchars,
XPointInRegion(
    TCL_UNUSED(Region),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
	return 0;
    int *direction_return,
}

    int *font_ascent_return,
int
XUnionRegion(
    TCL_UNUSED(Region),
    TCL_UNUSED(Region),
    TCL_UNUSED(Region))
{
	return 0;
    int *font_descent_return,
}

    XCharStruct *overall_return)
Region
XPolygonRegion(
    TCL_UNUSED(XPoint *),
    TCL_UNUSED(int),
    TCL_UNUSED(int))
{
    return 0;
}

void
XDestroyIC(
    TCL_UNUSED(XIC))
{

}

void
Cursor
XCreatePixmapCursor(
    TCL_UNUSED(Display *),
XReparentWindow(
    Display *display,
    TCL_UNUSED(Pixmap),
    TCL_UNUSED(Pixmap),
    TCL_UNUSED(XColor *),
    TCL_UNUSED(XColor *),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(unsigned int))
{
    return (Cursor) NULL;
}

    Window w,
Cursor
XCreateGlyphCursor(
    TCL_UNUSED(Display *),
    TCL_UNUSED(Font),
    Window parent,
    TCL_UNUSED(Font),
    TCL_UNUSED(unsigned int),
    TCL_UNUSED(unsigned int),
    int x,
    int y)
    TCL_UNUSED(XColor _Xconst *),
    TCL_UNUSED(XColor _Xconst *))
{
    return (Cursor) NULL;
}

XFontSet
XCreateFontSet(
    TCL_UNUSED(Display *)		/* display */,
    TCL_UNUSED(_Xconst char *)	/* base_font_name_list */,
    TCL_UNUSED(char ***)		/* missing_charset_list */,
    TCL_UNUSED(int *)		/* missing_charset_count */,
    TCL_UNUSED(char **)		/* def_string */
) {
    return (XFontSet)0;
}

void
XFreeFontSet(
    TCL_UNUSED(Display *),		/* display */
XRotateBuffers(
    Display *display,
    TCL_UNUSED(XFontSet)		/* font_set */
) {
    int rotate)
}

{
void
XFreeStringList(
    TCL_UNUSED(char **)		/* list */
) {
}

Status
XCloseIM(
    TCL_UNUSED(XIM) /* im */
) {
    return Success;
}

Bool

void
XStoreBuffer(
XRegisterIMInstantiateCallback(
    TCL_UNUSED(Display *)			/* dpy */,
    Display *display,
    TCL_UNUSED(struct _XrmHashBucketRec *)	/* rdb */,
    TCL_UNUSED(char *)			/* res_name */,
    _Xconst char *bytes,
    TCL_UNUSED(char *)			/* res_class */,
    TCL_UNUSED(XIDProc)			/* callback */,
    TCL_UNUSED(XPointer)			/* client_data */
) {
    int nbytes,
    int buffer)
    return False;
}

{
Bool
XUnregisterIMInstantiateCallback(
    TCL_UNUSED(Display *) 		/* dpy */,
    TCL_UNUSED(struct _XrmHashBucketRec *)	/* rdb */,
    TCL_UNUSED(char *)			/* res_name */,
    TCL_UNUSED(char *)			/* res_class */,
    TCL_UNUSED(XIDProc)			/* callback */,
    TCL_UNUSED(XPointer)			/* client_data */
) {
    return False;
}

char *
XSetLocaleModifiers(
    TCL_UNUSED(const char *)		/* modifier_list */
) {
    return NULL;
}

void
XIM XOpenIM(
    TCL_UNUSED(Display *)			/* dpy */,
XUndefineCursor(
    Display *display,
    TCL_UNUSED(struct _XrmHashBucketRec *)	/* rdb */,
    TCL_UNUSED(char *)			/* res_name */,
    TCL_UNUSED(char *)			/* res_class */
) {
    Window w)
    return NULL;
}

{
char *
XGetIMValues(
    TCL_UNUSED(XIM) /* im */, ...
) {
    return NULL;
}

#endif
char *
XSetIMValues(
    TCL_UNUSED(XIM) /* im */, ...
) {
    return NULL;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */

Changes to xlib/ximage.c.

47
48
49
50
51
52
53
54
55
56
57
58
59





60
61
62
63
64
65
66
67
47
48
49
50
51
52
53






54
55
56
57
58

59
60
61
62
63
64
65







-
-
-
-
-
-
+
+
+
+
+
-







    pix = Tk_GetPixmap(display, d, (int) width, (int) height, 1);
    gc = XCreateGC(display, pix, 0, NULL);
    if (gc == NULL) {
	return None;
    }
    ximage = XCreateImage(display, NULL, 1, XYBitmap, 0, (char*) data, width,
	    height, 8, (width + 7) / 8);
    if (ximage) {
	ximage->bitmap_bit_order = LSBFirst;
	_XInitImageFuncPtrs(ximage);
	TkPutImage(NULL, 0, display, pix, gc, ximage, 0, 0, 0, 0, width, height);
	ximage->data = NULL;
	XDestroyImage(ximage);
    ximage->bitmap_bit_order = LSBFirst;
    _XInitImageFuncPtrs(ximage);
    TkPutImage(NULL, 0, display, pix, gc, ximage, 0, 0, 0, 0, width, height);
    ximage->data = NULL;
    XDestroyImage(ximage);
    }
    XFreeGC(display, gc);
    return pix;
}

/*
 * Local Variables:
 * mode: c

Changes to xlib/xutil.c.

1
2
3
4
5
6
7
8
9
10
11

12





13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24











+
-
+
+
+
+
+







/*
 * xutil.c --
 *
 *	This function contains generic X emulation routines.
 *
 * 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.
 */

#include <stdlib.h>
#include "tkInt.h"
#include <tk.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

/*
 *----------------------------------------------------------------------
 *
 * XInternAtom --
 *
 *	This procedure simulates the XInternAtom function by calling Tk_Uid to
28
29
30
31
32
33
34
35
36


37
38
39
40

41
42
43
44
45
46
47
33
34
35
36
37
38
39


40
41
42
43
44

45
46
47
48
49
50
51
52







-
-
+
+



-
+







 *
 *----------------------------------------------------------------------
 */

Atom
XInternAtom(
    Display *display,
    TCL_UNUSED(_Xconst char *),
    TCL_UNUSED(Bool))
    _Xconst char *atom_name,
    Bool only_if_exists)
{
    static Atom atom = XA_LAST_PREDEFINED;

    LastKnownRequestProcessed(display)++;
    display->request++;
    return ++atom;
}

/*
 *----------------------------------------------------------------------
 *
 * XGetVisualInfo --
60
61
62
63
64
65
66
67

68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
65
66
67
68
69
70
71

72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99







-
+





-
+













-
+







XVisualInfo *
XGetVisualInfo(
    Display *display,
    long vinfo_mask,
    XVisualInfo *vinfo_template,
    int *nitems_return)
{
    XVisualInfo *info = (XVisualInfo *)ckalloc(sizeof(XVisualInfo));
    XVisualInfo *info = ckalloc(sizeof(XVisualInfo));

    info->visual = DefaultVisual(display, 0);
    info->visualid = info->visual->visualid;
    info->screen = 0;
    info->depth = info->visual->bits_per_rgb;
    info->c_class = info->visual->c_class;
    info->class = info->visual->class;
    info->colormap_size = info->visual->map_entries;
    info->bits_per_rgb = info->visual->bits_per_rgb;
    info->red_mask = info->visual->red_mask;
    info->green_mask = info->visual->green_mask;
    info->blue_mask = info->visual->blue_mask;

    if (((vinfo_mask & VisualIDMask)
	    && (vinfo_template->visualid != info->visualid))
	    || ((vinfo_mask & VisualScreenMask)
		    && (vinfo_template->screen != info->screen))
	    || ((vinfo_mask & VisualDepthMask)
		    && (vinfo_template->depth != info->depth))
	    || ((vinfo_mask & VisualClassMask)
		    && (vinfo_template->c_class != info->c_class))
		    && (vinfo_template->class != info->class))
	    || ((vinfo_mask & VisualColormapSizeMask)
		    && (vinfo_template->colormap_size != info->colormap_size))
	    || ((vinfo_mask & VisualBitsPerRGBMask)
		    && (vinfo_template->bits_per_rgb != info->bits_per_rgb))
	    || ((vinfo_mask & VisualRedMaskMask)
		    && (vinfo_template->red_mask != info->red_mask))
	    || ((vinfo_mask & VisualGreenMaskMask)